pfalstad / circuitjs1

Electronic Circuit Simulator in the Browser
GNU General Public License v2.0
1.65k stars 280 forks source link

Feature: Initialize subcircuit pin positions from schematic #34

Closed fritzw closed 1 year ago

fritzw commented 1 year ago

This change initializes the pin positions in the "Create subcircuit" dialog from the location of the "Labeled Nodes" in the schematic. The rationale for this change is that this makes it easier to change an existing subcircuit.

Previously the pins were distributed more or less arbitrarily to the left and right side of the symbol. You can drag them to the desired position and save the subcircuit. But when you open a saved subcircuit and then click "Create subcircuit" again, your previous pin arrangement is lost.

With this pull request, the initial pin positions are instead determined from the labeled nodes in the schematic. Labels that "point upward" are placed on the north edge of the symbol, nodes that "point right" on the east edge, etc. Additionally, the pins are sorted on the symbol in the same order as they appear in the schematic, from top to bottom (for horizontal pins) or from left to right (for vertical pins). This means that you don't have to repeat the positioning of pins over and over again when iteratively changing a subcircuit, but you can do it once in the schematic and then the symbol is automatically created accordingly.

The symbol is automatically sized that all pins fit inside. Care is taken to ensure that the pin labels of vertical and horizontal pins do not overlap.

Here are some examples:

https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgpABZsKBTAWjDACg1y08Q8qxCVPrRAB1SB0jlsCFLyo0B8kQFEJAJxDdlMucP7w2QA

image image

https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgpABZsKBTAWjDACg1y09wNCRuAmlRogAypA6RyrFCDxVCohbRAB1SQCcB+eVVzKqVMPClddLfoKZLVAOS06elp3qjI4bbbLeCVx020-KkEwPncTTyA

image image

https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgpABZsKBTAWjDACg1y09wwVxCVVvxogA6u04hco7Pxkgmc2iABykyF3zhi-MIJ0jxKDppDcQeIQasqxkU1wSFp-FM8XLRqh1OwJ+Wxp9SypRAFFfMwsUFFELBVEAZSjyfzc46QDpSFFkkz9c80yFRJAk9gAncw9lC1sheDZq9OLZbIbkOGac+MyYzMbu6oswXXNtYSguhxaiutr+IYcgA

image image

https://www.falstad.com/circuit/circuitjs.html?ctz=CQAgjCAMB0l3BWcMBMcUHYMGZIA4UA2ATmIxAUgpABZsKBTAWjDACg1zcbwaexiKcCjy0QAdXacQ2bIRlDZ8ptiE8AclMjkaYeXqo08VA2ICiW8mlEChp62PEoO2kChQ9j4DPK89xkC5WGIpCKAjKRmLqgdJ0obRRKmog6s5xUV4IYHYi5rGuuvKYasTFHubprg7hxfgycmIAygVcCGEVJQ3yPE1VVniiHlTc3c3sAE5uIQpuFV4m8GxT8bNKs4twyzLtczxF00KbgVMiQzRUNRFQyFun9bYykPx8N2BLK3rghIaZVMdsIA

image image

pfalstad commented 1 year ago

When I try this I get: [ERROR] Line 6194: Lambda expressions are allowed only at source level 1.8 or above Maybe that's because I am on GWT 2.7.0. Maybe it's time to upgrade. Did you find any problems with GWT 2.10.0 other than the LabeledNodeElm thing?

actually I switched to 2.8.1 and got it to work.

pfalstad commented 1 year ago

Very nice addition, thank you!

fritzw commented 1 year ago

Thanks. I'm running 2.10 without any other problems, apart from the exceptions from substring() that are fixed in #33.