MitjaNemec / Kicad_action_plugins

Kicad action plugins
414 stars 62 forks source link

save_restore_layout can't work in kicad6.0RC1 #142

Open HaydenHu opened 2 years ago

HaydenHu commented 2 years ago

KICAD6.0RC1 was released with the hope of fixing save_restore_layout plug-ins

It seems that the schematic API has been postponed to 7.0, I hope not to wait for the API, directly parse schematic bar, this plug-in is too useful.

MitjaNemec commented 2 years ago

Well, I plan to port most of my plugins to V6. But I'll start with the simplest ones as I also have to figure out how to integrate plugins in the "plugin and content manager". So my current plan is to start porting the simplest plugins (Length stats and Archive project). Then I'll continue with more difficult ones (Place footprints, Replicate layout) and the last come the plugins that deal with schematics (Save/Restore Layout, Swap pins and Swap units). But before I start with the last batch I'll have to check with KiCad core dev team what is the state of the new python API. If it will be nearly finished, I'll wait for it. Otherwise, I'll start porting. Especially Save/Restore Layout as it only reads the schematics.

roykrikke commented 2 years ago

May I ask what your progress is? Could you possibly use help with, for example, reviews?

perigoso commented 2 years ago

But before I start with the last batch I'll have to check with KiCad core dev team what is the state of the new python API. If it will be nearly finished, I'll wait for it. Otherwise, I'll start porting. @MitjaNemec

New API has been postponed to V7, V6 is released so all is stable to work on

MitjaNemec commented 2 years ago

Yeah, I am started porting the plugins, but it is a slow process as I am short on spare time lately. So it is going to be a slow haul.

And the Save/Restore will mos likely be the last plugin, as I'll have to study how to parse the schematic files (as there is no API available)

roykrikke commented 2 years ago

Can I be of any help?

MitjaNemec commented 2 years ago

Thanks for offering.

What is you background? Are you familiar with python? The major effort for Save/Restore layout plugin is to refactor SchData class. The class parses the main all schematics files to get the schematics file hierarchy, so that we have a dictionary mapping schematics filenames to schematics UUID. For parsing files we should use one of the available s-expressions parsers. It might be smart to check which one makes more sense. Additionally the get_sch_hash has to be refactored to calculate the hash of schematics files, but the parts that change when using the file in multiple projects should not be taken into account then calculating hash (L F0 F 0 AR Sheet LIBS and EELAYER records)

roykrikke commented 2 years ago

I know python a bit and have been committing some code to https://github.com/ivandokov/phockup I am certainly no expert. I'll have a look at the code and get back to you then. Can I reach you somewhere private? Discord for example?

MitjaNemec commented 2 years ago

Thanks for the offer.

Before you start coding, you should start with preparing two (or even better three) KiCad projects where you use the same file (or a copy of a file) as a hierarchical page. Make sure you annotate the schematics in all projects. Then take a look at how the specific hierarchical sheet schematics file looks like. What changes if you reannotate the project? What changes if you include this file into another project.

For observing changes, make a copy of the file in specific points in time. So you'll end up with the same file but at different points in time:

  1. file used only in not annotated original project
  2. file used only in annotated original project
  3. file used also in second project, second project not annotated
  4. file used also in second project, second project annotated
  5. file used also in second project, first project reannotated
  6. file used also in third project, third project not annotated

and then you can look at the differences with meld, or winmerge.

These observations will let you know what parts of the schematics file change. These parts will have to be ignored when calculating hash. If you write down your observations, and also keep and archive of all the projects at different points in time for sharing, this would also help me, if you are not able to proceed forward.

Before you start coding I'd first look for s-expressions parser, and evaluate different options. From my memory you have sexpdata and you could also use parsers by realthunder or qu1ck

And only then you can start coding.

HaydenHu commented 2 years ago

Hello, how is the fix? Can I refer to the parsing section of this plugin for kicad_sch? https://github.com/ian-ross/kicad-plugins @MitjaNemec

MitjaNemec commented 2 years ago

I've got the plugin backend working. It took a bit longer as I've found a couple of bugs in KiCad and some of them have been are fixed since 6.0.3, while for remaining there are workarounds. I've managed to get around the parsing of schematics files so you have no code to help you. Sorry.

I expect that GUI part of the plugin should be in place in two weeks. So the plugin should be in PCM in three weeks or so.

MitjaNemec commented 2 years ago

Current code is at: https://github.com/MitjaNemec/SaveRestoreLayout

MitjaNemec commented 2 years ago

Ok, the plugin is released and is available in KiCad's Plugin and content Manager (PCM). It works more or less as the 5.1.x version did. But it'll take some time to write the documentation. If anybody volunteers to write it I’ll really appreciate it.