simplipfy.Svg package

Subpackages

Submodules

simplipfy.Svg.drawWithSchemdraw module

class simplipfy.Svg.drawWithSchemdraw.DrawWithSchemdraw(circuit: ~lcapyInskale.circuit.Circuit, langSymbols: <simplipfy.Helpers.langSymbols.LangSymbols object at 0x0000020444227E00>, fileName: str = 'circuit', removeDangling: bool = True)

Bases: object

Use the schemdrawInskale package to draw a netlist generated with lcapy

add_connection_dots(drawingElements: list[DrawingElement], addToList=True) list[DrawingElement]

finds positions that occur more than 2 times and adds a dot at this position :param drawingElements: the start and end positions of those elements are checked :param addToList: if True the dots extend the drawingElements list, if False a new list with the dots is returned :returns: None if addToList is True, else a list with the dots Is used to indicate that two overlapping wires are connected

draw(path='')

save the svg image as a svg-file name of the file will be self.fileName :param path: path to save the svg file

getElementPositionsFromNetlist(maxDrawingIterations: int = 100) list[DrawingElement]

get the positions required to draw a circuit from the netlist

getElementPositionsFromObjects() tuple[list[DrawingElement], dict[Any, list[Vector2D]]]

get the positions required to draw a cricuti from generalizeNetlistDrawing.elements.element

getImageData(maxDrawingIterations: int = 100) str
Returns:

svg image data as utf-8 string

getNetlistLines() list[NetlistLine]

retriev the netlist lines from the circut

latexStr(line: NetlistLine)

convert value of the NetlistLine to a latex string

legacy_add_connection_dots()

adds the dots that are on connections between two lines e.g. when a line splits up in two lines a dot is created at the split point :returns: does not return anything

simplipfy.Svg.drawingConfig module

class simplipfy.Svg.drawingConfig.DrawingConfig

Bases: object

Singleton class to manage drawing options for the schematic drawing.

Available options are:

  • –generalize-<value> -> sets generalize to <value> (true/false): draws a generalized schematic

  • –optimize-<value> -> sets optimize to <value> (mobile/desktop/none): draws a generalized schematic, and rotates it to fit eighter mobile or desktop screens better. If optimize is set to none, the schematic is not rotated.

Note

If you want to add an option:

  • Create a function named _<optionName> within the class.

    The function signature should be:

    def _option<Name>(self, option: Option):
    

    Inside this function, you should implement the logic:

    if option.name == "<optionName":
        if option.value == ...:
            DrawingConfig._showNodes = ...
        elif option.value == ...:
            DrawingConfig._showNodes = ...
        else:
            raise RuntimeError(f"Unknown <optionName> value: {option.value}, option not changed")
    
  • add _<optionName> to class variables

  • add getter function:

    @property
    def <optionName>(self) -> <type>:
        return self._<optionName>
    
  • add it to self._setOptionFns in self.__new__

  • add it to self.saveOptions()

  • add it to self.setToDefault()

property generalize: bool

True if generalize is set, else False

Generalizes the schematic drawing. This means that the drawing emphasizes to highlight series and parallel relations between components. No wires are needed in the netlist for this to work but won’t break if they are present.

Type:

returns

static isLocked() bool
Returns:

True if the drawing config is locked, else False

If the drawing config is locked, no changes can be made to the config. All calls to functions that would change the config will be ignored.

loadOptions(options: list[Option]) None
Options:

list of Options to load

Returns:

None

load options from a list of Options

lock(on: str = None)
Parameters:

on – Calls setOptions with on string to set options before locking the config

Returns:

None

Lock the drawing config. This prevents any changes to the config.

property optimize: Optimize

Optimize enum value currently set for self.optimize

Depends on self.generalize being set to True. Optimize is an enum with the following values:

  • Optimize.NONE: no optimization

  • Optimize.MOBILE: optimize for mobile -> rotates the schematic to fit mobile screens better

  • Optimize.DESKTOP: optimize for desktop -> rotates the schematic to fit desktop screens better

Type:

returns

static parseString(options: str, reset=True) list[Option]
Parameters:
  • reset – resets the options to its standard values

  • options – string, –<optionName>-<value>

Returns:

list of object Option with the parsed options

options string is not case sensitive

Note

The options string is parsed using regex. The format is:

  • –<optionName>-<value> -> value is set to <value>

  • –<optionName> -> value is set to true

  • –generalize -> sets generalize to True

  • –generalize-true -> sets generalize to True

  • –generalize-false -> sets generalize to False

  • –optimize-mobile -> sets optimize to Optimize.MOBILE and generalize to True

  • –optimize-desktop -> sets optimize to Optimize.DESKTOP and generalize to True

  • –optimize-none -> sets optimize to Optimize.NONE and does not change generalize

  • –generalize-false –optimize-none -> sets generalize to False and optimize to Optimize.NONE

static saveOptions() list[Option]
Returns:

list of all options and their values

The return value of this function can be loaded with self.loadOptions

setOptions(optionStr: str, reset=True) None
Parameters:
  • reset – resets all options before parsing the string

  • optionStr – see self.parseString for details

Returns:

None

Sets options parsed from a string using self.parseString

static setToDefault() None
Returns:

None

sets the following values:

  • generalize = False

  • optimize = Optimize.NONE

does not work when locked

property showNodes: bool

True if showNodes is set, else False

Show nodes adds each node that is in the netlist to the drawing with its node number.

Type:

returns

unlock(setTo: str = None)
Parameters:

setTo – Calls setOptions with set string to set options after unlocking the config

Returns:

None

Unlock the drawing config. Reverts self.lock().

class simplipfy.Svg.drawingConfig.Option(name: str, value: str)

Bases: object

Class to represent an option for the drawing config. Wrapper for the name and value of the option after parsing with DrawingConfig.parseString()

simplipfy.Svg.drawingElement module

class simplipfy.Svg.drawingElement.DrawingElement(vec: Vector2D, di: DrawingInfo, omega_0, multipleSources: bool, formatter: DictExportBase, ls: LangSymbols, scaling=3.0)

Bases: Element

Base class for drawing elements in schemdraw that handles the common case for creating labels, positions etc. Treat this class as an abstract class.

clOfst = {'down': (-0.15, 0.15), 'left': (-0.1, -0.05), 'right': (-0.1, 0.05), 'up': (0.15, -0.15)}
curLabel(drawing: Drawing, at: Element, ofst=0.7, ofstLabel=None, reverse=False, suffix=None)
elOfst = {'down': (-0.35, -0.1), 'left': (0, -0.25), 'right': (0, 0.25), 'up': (0.35, 0.1)}
labelOffset() tuple[float, float]
property negNodePos: Vector2D

position of the negative node as Vector2D object

Type:

Returns

property posNodePos: Vector2D

position of the positive node as Vector2D object

Type:

Returns

abstractmethod schemdrawElement() Element
static textToDirection(dirText) int
static textToDirectionVector(dirText) Vector2D
vaOfst = {'down': 0.15, 'left': 0.15, 'right': -0.65, 'up': -0.65}
value()
vlOfst = {'down': (0, -0.15), 'left': (0, -0.15), 'right': (0, 0.15), 'up': (0, 0.15)}
voltLabel(drawing: Drawing, at: Element, ofst=0.15, ofstLabel=None, reverse=False, suffix=None)

simplipfy.Svg.drawingElementFaktory module

class simplipfy.Svg.drawingElementFaktory.DrawingElementFaktory(ls: LangSymbols, omega_0, formatter: DictExportBase, multipleSources=False)

Bases: object

Class for creating drawingElements

make(di: ~simplipfy.Svg.drawingInfo.DrawingInfo, vec: <generalizeNetlistDrawing.vector2D.Vector2D object at 0x0000020444227CB0>, type, length=3) DrawingElement

all makeFrom* functions call this function to actually make a DrawingElement

makeDot(vec: Vector2D, label='') ConnectionDot

Creates a connection dot that indicates that two overlapping wires are connected

makeFromElement(elm: Element)

create a drawing element from generalize.netlistDrawing.elements.element

makeFromNetline(netLine: str, vec: <generalizeNetlistDrawing.vector2D.Vector2D object at 0x00000204447E8190>) DrawingElement

Create a drawing element from a netlist line e.g., lcapy.Circuit(<initialize>).netlist()[0] Determines the element type from the netlist line R1 5 6 {100}; down -> R type

type_map: dict[str, Type[DrawingElement]] = {'AM': <class 'simplipfy.Svg.Elements.meters.Ammeter'>, 'C': <class 'simplipfy.Svg.Elements.components.Capacitor'>, 'D': <class 'simplipfy.Svg.Elements.components.ConnectionDot'>, 'I': <class 'simplipfy.Svg.Elements.sources.SourceI'>, 'L': <class 'simplipfy.Svg.Elements.components.Inductor'>, 'R': <class 'simplipfy.Svg.Elements.components.Resistor'>, 'V': <class 'simplipfy.Svg.Elements.sources.SourceV'>, 'VM': <class 'simplipfy.Svg.Elements.meters.Voltmeter'>, 'W': <class 'simplipfy.Svg.Elements.components.Line'>, 'Z': <class 'simplipfy.Svg.Elements.components.Resistor'>}

simplipfy.Svg.drawingInfo module

class simplipfy.Svg.drawingInfo.DrawingInfo(drawParam: str, type: str, typeSuffix: str, value: any, ac_dc: str = None, rotation: int = None)

Bases: object

Wrapper for the infromtaon needed to create a DrawingElement

static fromNetline(nl: NetlistLine) DrawingInfo
property label
property name

Module contents

Module used to generate the svg files that are displayed in the frontend. The module uses a slighlingly modified version of schemDraw called schemdrawInskale. The changes to schemDraw add IDs and Classes to the elements in the svg file to allow component selection and manupulation in the frontend. The IDs are used for communication between frontend and backend.