ra3xdh / qucs_s

Qucs-S is a circuit simulation program with Qt-based GUI
https://ra3xdh.github.io/
GNU General Public License v2.0
853 stars 109 forks source link

Improve SpiceLibComp device #679

Closed ra3xdh closed 3 months ago

ra3xdh commented 6 months ago

SpiceLibComp device was intended for usage of the unmodified SPICE libraries with Qucs-S https://qucs-s-help.readthedocs.io/en/latest/SubLib.html#usage-of-unmodified-spice-libraries The current implementation has many issues that prevents its usage for circuit design. The following improvements must be done:

Help is appreciated here.

wawuwo commented 6 months ago

@ra3xdh I've made a small patch enabling Qucs-S to save only a subcircuit symbol of a schematic to a file and to load back symbols from such files. Patch reuses Schematic object and resulting "symbol files" are in effect stripped usual schematic files (no components, no properties etc.)

Workflow to create a symbol:

  1. Create new schematic
  2. Add the required number of ports
  3. Switch to symbol editing mode
  4. Draw symbol
  5. Save symbol by going to File->Save as and selecting "Symbol only" type of file

After that one can load this symbol back using usual "File->Open" dialog, where "Symbol only" type of file has to be selected.

Unfortunately with this patch symbols from share/qucs-s/symbols can't be loaded — they lack <Qucs Schematc … > tag on first line.

Please check out branch https://github.com/wawuwo/qucs_s/tree/feature-export-symbol in my repo if it sounds interesting, I think it's not worth of opening a PR yet.

wawuwo commented 6 months ago

I forgot to mention that SpiceLibComp can use symbol files made this way, but you have to manually put them into share/qucs-s/symbols

ra3xdh commented 6 months ago

I've made a small patch enabling Qucs-S to save only a subcircuit symbol of a schematic to a file

Yes, this may help to resolve #147 I was thinking about the similar way. The main problem was how to add/remove ports for symbol without schematic. I will try to evaluate your patch in the next week.

Unfortunately with this patch symbols from share/qucs-s/symbols can't be loaded

It is not a big problem, because only 4 symbols are shipped with Qucs-S now. These four symbols could be easily recreated using new format.

wawuwo commented 6 months ago

how to add/remove ports for symbol without schematic

Maybe a solution is to show "port" tool in paintings alongside with arrow, line, ellipse, etc. when in symbol editing mode, so a user would be able to go straight to symbol editing, skipping the "add required number of ports" part. I'll look into it

ra3xdh commented 5 months ago

@wawuwo

I've made a small patch enabling Qucs-S to save only a subcircuit symbol

I have tested your patch. I have found this a good solution for #145 The following things should be fixed if possible:

I propose the following logic of adding symbol ports. It could be done using the Add port button on the toolbar

I am not sure if proposed workflow could be implemented. Alternative solution is also welcome.

wawuwo commented 5 months ago

@ra3xdh

Ports are shown without numbers when opening *.sym files This makes difficult to identify ports

I need some clarification here… Where should these numbers come from? I see you've added the symbol to SpiceLibComp component and I guess then the port numbers should be the numbers from .SUBCKT entry? I mean, if it's .SUBCKT Thyristor 99 88 77, then you expect to see 99, 88 and 77 somewhere around the ports on schematic picture? Or do you mean something like 555 timer has? (I'm sorry if my questions sound stupid, I don't have a lot of experience with it) 2024-04-19 15 52 27

ra3xdh commented 5 months ago

Normally the port number comes from subcircuit ports (Port device inserted from button on the toolbar) property like Num=1. I am not sure how the application derives symbol port number from subcircuit port number. But if the symbol opened without attached schematic, the port is drawn without numbers.

wawuwo commented 5 months ago

Oh god, it clicked, I finally see what port numbers you mean. Will look into it; I guess that's because adjustPortNumbers applies some "magic" to symbols and it's not called for "*.sym" files

wawuwo commented 5 months ago

I've added a commit with patch to display port numbers, but unfortunately has huge disadvantage.

Symbol files store ports like this:

  <.PortSym -30 -30 1 0>
  <.PortSym 30 -30 2 0>
  <.PortSym -30 30 3 0>
  <.PortSym 30 30 4 0>

where numbers are: x coordinate, y coordinate, auto assigned index number, rotation angle. So for .sym files the only port label we can obtain is its index number plus some static string, there is no more info in file. In contrast, ports in subcircuit symbols (i.e. usual schematics, not .sym) derive their labels from names of corresponding ports on schematic, so their labels can be of any form.

The only way to circumvent this I think is to change the format in which symbols are stored, to put "freeform" port numbers into files too.

wawuwo commented 5 months ago

But to make "freeform" port numbers in symbol mode when there is no corresponding schematic ports it's required to allow somehow editing of port texts 🤔

ra3xdh commented 5 months ago

It would be sufficient to show the automatically assigned port index number. No need to change the port format.

wawuwo commented 5 months ago

@ra3xdh Please, try the same branch with recent commit. I was able to patch here and there to allow adding ports when in symbol edit mode.

"insert port" tool works in symbol edit mode for usual "subcircuit + subcircuit symbol" files too. But ports added this way are automatically removed when file is saved. In other words, if one adds ports in symbol edit mode and then saves the document as *.sym, the all ports end up in a file. But if the document is saved as *.sch, then only the ports with a corresponding port in schematic end up in the file, "dangling" ports are removed from symbol.

ra3xdh commented 5 months ago

@wawuwo

Please, try the same branch with recent commit.

Yes, the recent improvements on this branch makes the new feature acceptable. I have found two minor issues:

"insert port" tool works in symbol edit mode for usual "subcircuit + subcircuit symbol" files too. But ports added this way are automatically removed when file is saved.

This behavior is correct. The symbol ports and SCH ports must be synchronized. The manual ports edition should be allowed only for detached symbols (SYM). Furthermore the port add button may be disabled when SCH file enters symbol editing mode (F9).

ra3xdh commented 5 months ago

@wawuwo You may open a PR on symbol editor and link it to the #147

ra3xdh commented 5 months ago

The merging #700 makes possible converting subcircuit symbols to symbol patterns *.sym files. The next step is to implement a custom dialog window for SpiceLibComp device that will allow to assign symbol pin and device pin. The extension of SpiceLibComp will be required.

ra3xdh commented 4 months ago

I propose to implement a custom dialog for SpiceLibComp containing symbol pins assignment table like in KiCAD. It's need to add something like this for SpiceLibComp: image

ra3xdh commented 4 months ago

The #755 contains SpiceLibComp redesign.

ra3xdh commented 4 months ago

I have merged #755. It doesn't contain a fix for "nested subcircuit" warning. This will be a separate PR. The update of the symbol pack also will be a separate PR.

ra3xdh commented 4 months ago

The New symbol action has been implemented by #757. It contains some other improvements of the symbol editor.

ra3xdh commented 3 months ago

I have merged #757. Now it is possible to create a new symbol from the file menu. The #757 also fixes some issues of the symbol editor.

ra3xdh commented 3 months ago

See #775 for "nested subcircuit" warning fix.

ra3xdh commented 3 months ago

The extended symbols set has been added by #776. This PR finishes the works related to SpiceLibComp redesign. Closing as completed. I will open a separate PR if something will be required for new SpiceLibComp.