Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symbol editor #700

Merged
merged 6 commits into from
May 3, 2024
Merged

Add symbol editor #700

merged 6 commits into from
May 3, 2024

Conversation

wawuwo
Copy link
Contributor

@wawuwo wawuwo commented Apr 22, 2024

Opening a PR following the discussion in #679

Recap:

  • Symbol editor based on usual schematic editor
  • Saving and opening detached symbols to and from *.sym files
  • To save and open detached symbols, "Symbol only" filter should be selected in "Open file" dialog
  • To start creating a symbol, switch to symbol editing mode
  • Ports can be added and removed in symbol editing mode. If the symbol is then saved as *.sym file then all manually inserted ports remain. If it is saved as usual *.sch file, then all ports without a corresponding port in schematic will be removed.

May close #147

"Schematic" object already can edit symbols, this commit makes
it able to save and load them.

Implementation is actually quite ugly in terms of code beauty
and industry standards, it's very "hacky". It consists of two
parts:
1. Teach "Save" and "Open" dialogs to deal with "*.sym" files
2. Modify "Schematic" object and some other parts of codebase
   so that when a schematic is saved and the filename ends with
   "*.sym", then only symbol parts are saved. And vice versa:
   when a file with a name ending in "*.sym" is opened, then
   skip the path for usual schematic, and load only symbol parts.

The "symbol file" is actually a stripped "schematic file" — no
properties, no components, etc.
- PortSymbol has two members: nameStr and numberStr.
- nameStr is usually empty and is set from Schematic::adjustPortNumber
  after performing some obscure checks.
- numberStr is usually contains a number
- PortSymbol::paint outputs 'nameStr' as ports "label"
- When editing a *.sym file, 'adjustPortNumber' is not called,
  nameStr remains empty

This patch makes PortSymbol use 'numberStr' as fallback value for
cases when 'nameStr' is empty. When editing a *.sym file one won't
see a port without label anymore.
"Insert port" tool is reused it. When in symbol editing mode,
left mouse button click with this tool activated spawns a dialog
asking for port name, then insert a port.

I hope there is no breaking changes and everything is backwards
compatible as I strived to add workarounds everywhere it's needed.

The sad part is that code is not elegant, it increases overall
codebase entropy, doesn't follow any general strategy. It's just
a set of patches.
Detached ports are ports which were inserted manually, i.e. they
don't have a corresponding port in schematic.

Inside Schematic::undo the Schematic::adjustPortNumbers is called.
The latter removes detached ports and because of that you lose
all of your ports if use "undo" once.

But Schematic::adjustPortNumbers is also called every time the
editing mode is switched and when the file is saved. So I think
it wouldn't be harm to not adjust port numbers every time you
undoing.
@ra3xdh ra3xdh added this to the 24.3.0 milestone Apr 25, 2024
@ra3xdh
Copy link
Owner

ra3xdh commented Apr 25, 2024

Thanks! I will merge this after #533

@ra3xdh ra3xdh merged commit ae63391 into ra3xdh:current May 3, 2024
2 checks passed
@ra3xdh
Copy link
Owner

ra3xdh commented May 3, 2024

Thanks for the contribution! Merged.

@wawuwo wawuwo deleted the feature-export-symbol branch May 3, 2024 12:48
@ra3xdh ra3xdh linked an issue Jun 15, 2024 that may be closed by this pull request
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve SpiceLibComp device Add editor for symbol *.sym files
2 participants