MitjaNemec / SaveRestoreLayout

GNU General Public License v2.0
22 stars 5 forks source link

Hierarchical sheet file name needs to be exactly the same for Restore layout to work (And maybe an idea on how to fix it?) #19

Open Jaron123 opened 1 month ago

Jaron123 commented 1 month ago

I was having trouble getting the plugin to work and one of the problems is the sheet file name needs to be the same when referencing. The problem is that when you make a new sheet in the schematic editor it automatically references it to relative path name. So a file called Test.kicad_sch will have sheet file designator "Test.kicad_sch" because it is in the same folder. When I now want to use the sheet and layout in another project (Which for KiCad is always in another folder) the file designator will change to absolute path "C:/folder/folder/folder/Test.kicad_sch". If you now try to apply the layout in PCB editor you get the error:

LookupError: Destination hierarchy: ['Test.kicad_sch'] does not match source level: 'C:/folder/folder/folder/Test.kicad_sch'

The only way to resolve this is to copy and paste the Test.kicad_sch to the other project and also force it to reference it with relative path. Which defeats the purpose of checking if the destination hierarchy and stuff is the same.. Why is the name of the schematic even checked? If I want to change the name of Test.kicad_sch to Test2.kicad_sch it also doesn't work even though the schematic is the same.

Maybe an idea to not have to check if the Hierarchical sheet schematic and layout file are the same maybe make the layout file part of the Hierarchical sheet schematic file and not check the location etc.

Besides this it might be more user friendly to force users to make a group of the layout they made of a Hierarchical sheet and copy everything in the group over when the layout is restored. This way it is possible to copy over graphical designators etc which can be very useful.

Also once these changes are implemented it is not necessary to have a separate replicate and save and restore layout addon. The layout is part of the sub sheet and can hopefully work multiple times on the same PCB design file. Workflow would be to link the layout made for a hierarchical sheet to the hierarchical sheet in grouped form. Then in schematic editor copy and paste the hierarchical sheet. And in PCB editor the layout can be copied and will also be in grouped form.

Jaron123 commented 1 month ago

Another note, even when the Hierarchical sheet file name is exactly the same, file is in the same and everything. sometimes I got: ValueError: Source and destination schematics don't match! This error seems to come up because the checksum was not the same. It might be that when the sub-schematic is in the wrong place the checksum might not match. My problem was fixed simply by commenting out: if not saved_hash == hex_hash: raise ValueError("Source and destination schematics don't match!") in save_restore_layout.py

To maybe explain what I ultimately want to achieve. I would like to have a hirarchical/sub schematics and partial-layout "place" or database or folder I put it into. The way I am gonna try doing it now is in my root folder I have a folder C:\KiCad_Modules and there I put KiCad projects that are just Sub-schematics and layouts of them. When making the layout .pckl file it is referenced with absolute path. And when the "Source and destination schematics don't match!" is commented out I can link the schematic in a KiCad file somewhere else on my computer and the layout .pckl file works to load the layout.

Hope this helps if someone is trying to do the same

MitjaNemec commented 1 month ago

Thanks for reporting this.

You are correct, it makes no sense to check for the matching names if the plugin is already comparing contents of schematic files. This probably stayed in code before I introduced contents checking. I'll have to take a look into this how to fix/remove this.

As for your other ideas/requests/remarks:

Besides this it might be more user friendly to force users to make a group of the layout they made of a Hierarchical sheet and copy everything in the group over when the layout is restored. This way it is possible to copy over graphical designators etc which can be very useful.

Can you be a bit more verbose? I don't know exactly what you mean?

Also once these changes are implemented it is not necessary to have a separate replicate and save and restore layout addon. The layout is part of the sub sheet and can hopefully work multiple times on the same PCB design file.

Again, I don't know how the layout would be a part of the subsheet? KiCad works with files and I cannot store layout information within the schematic file?

While it is true that Replicate layout plugin is quite similar to Save/Restore layout plugin I really don't want to join them as that would make one big plugin which would cover two (different) functionalities. And both plugins are already quite complex and hard to maintain.

Additional reason is that KiCad V9 or V10 plans to remove the functionality to share schematics files between projects, which will affect Save/restore layout plugin.

Also using groups as a help to work with either of the plugins (either in the backend of the plugin or as an UI part) is quite awkward. The KiCad grouping feature was not made for this and it lacks some features (nested groups, members belonging to different groups, ...) While there is a bit of support for groups in Replicate layout plugin, it is not as robust as I'd like

This error seems to come up because the checksum was not the same.

Yeah I quite like this feature as it prevents user errors. But as KiCad file formats tend to change (even during stable release cycle, this results in checksum errors. I have a plan to open a UI dialog ans ask the user to proceed, which would override checksum check, but I haven't gotten around doing it as it requires architectural changes, which will probably be significant and I am short on time.

I would like to have a hierarchical/sub schematics and partial-layout "place" or database or folder I put it into.

This workflow was what the plugin was intended to support, but because not all of the underlying data is present in the layout the plugin has to get some data from schematics. Therefore the plugin makes sure that source and destination schematics match. And due to file format changes user can get an error even when there is no obvious reason for the error (from the user's perscpecive). I probably could improve the checksum algorithm to be a bit more robust, but I am an EE and writing and supporting these plugins is on the edge of my CS knowledge.