Implement updating and exporting kicad_parse_gen Schematics for the evaluator#18
Conversation
|
|
||
| impl<'a, T: Default + PartialEq> OrDefault<'a, T> for T { | ||
| fn or_default(self, default: T) -> T { | ||
| if self == Default::default() { |
There was a problem hiding this comment.
What does this check do? Where is the default value defined and for what type?
There was a problem hiding this comment.
Yeah some documentation on trait would be great 👍
There was a problem hiding this comment.
Documented in 02921b0. Default is a built-in trait that enables fetching the type-specific "default" value, e.g. "" (empty string) for string-like types and 0 for number-like types. I'm using it here to make this generic without having to write an impl for each type comparing against its respective "zero value".
| let name = attribute.name.as_str().or_default("Value"); | ||
| c.update_field(name, &attribute.value.to_string()); | ||
| c.update_field( | ||
| &format!("{}{}", name, "_expr"), |
There was a problem hiding this comment.
Why do we write back the expression? Isn't the desired truth of that always set by the user in the kicad file?
There was a problem hiding this comment.
Indeed it is, but serialization of field values with quotes is broken in kicad_parse_gen (like the TODO I've added below that line states). This means that parsing and serializing back an Eeschema file with quotes while doing no modifications isn't reproducible in the first place, it will mess up escaping of the quotes. Since the whole file needs to be serialized at once (and not just some individual fields), I need to work around the bugs in serializing the expression as well, even though it is read-only internally.
Hardcoding _expr as the suffix isn't the most elegant solution, but it'll do for now IMO before I get around to fixing kicad_parse_gen. Then we can completely get rid of the escape and unescape functions here.
|
|
||
| impl<'a, T: Default + PartialEq> OrDefault<'a, T> for T { | ||
| fn or_default(self, default: T) -> T { | ||
| if self == Default::default() { |
There was a problem hiding this comment.
Yeah some documentation on trait would be great 👍
|
Thanks |
Bases on #17, crosses the last item off the list in #14. With this the
kicad_parse_gen::schematic::Schematicstructs are being properly kept track of and can finally be updated using the internalSchematicstructs as well as written back to their respective files. Designed so that it should be easy to adapt to the changes in #15 once it gets merged.kicad_parse_genhas a nasty bug with handling escaped strings, I've added theescape/unescapeworkaround just for the expression field for now, but since it is more widespread we might want to open an issue for it (and fix it) upstream.cc @luxas @chiplet