Skip to content

Commit

Permalink
FEAT: add export gds comps xml function (#881)
Browse files Browse the repository at this point in the history
* add zip support edd tests

* improving style

* improving style

* add unittest for export_gds_comp_xml

* MISC: Auto fixes from pre-commit.com hooks

For more information, see https://pre-commit.ci

* fix pre-commit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
felipeescastro and pre-commit-ci[bot] authored Nov 8, 2024
1 parent 98981e4 commit 9cfe330
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/pyedb/dotnet/edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
SiwaveDCSimulationSetup,
SiwaveSimulationSetup,
)
from pyedb.generic.constants import AEDT_UNITS, SolverType
from pyedb.generic.constants import AEDT_UNITS, SolverType, unit_converter
from pyedb.generic.general_methods import (
generate_unique_name,
get_string_version,
Expand Down Expand Up @@ -4598,3 +4598,45 @@ def definitions(self):
def workflow(self):
"""Workflow class."""
return Workflow(self)

def export_gds_comp_xml(self, comps_to_export, gds_comps_unit="mm", control_path=None):
"""Exports an XML file with selected components information for use in a GDS import.
Parameters
----------
comps_to_export : list
List of components whose information will be exported to xml file.
gds_comps_unit : str, optional
GDS_COMPONENTS section units. Default is ``"mm"``.
control_path : str, optional
Path for outputting the XML file.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
"""
from pyedb.generic.general_methods import ET

components = ET.Element("GDS_COMPONENTS")
components.set("LengthUnit", gds_comps_unit)
if not comps_to_export:
comps_to_export = self.components.components
for comp in comps_to_export:
ocomp = self.components.components[comp]
gds_component = ET.SubElement(components, "GDS_COMPONENT")
for pin_name, pin in ocomp.pins.items():
pins_position_unit = unit_converter(pin.position, output_units=gds_comps_unit)
gds_pin = ET.SubElement(gds_component, "GDS_PIN")
gds_pin.set("Name", pin_name)
gds_pin.set("x", str(pins_position_unit[0]))
gds_pin.set("y", str(pins_position_unit[1]))
gds_pin.set("Layer", pin.placement_layer)
component = ET.SubElement(gds_component, "Component")
component.set("RefDes", ocomp.refdes)
component.set("PartName", ocomp.partname)
component.set("PartType", ocomp.type)
tree = ET.ElementTree(components)
ET.indent(tree, space="\t", level=0)
tree.write(control_path)
return True if os.path.exists(control_path) else False
7 changes: 7 additions & 0 deletions tests/legacy/system/test_edb_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,10 @@ def test_properties(self, edb_examples):
}
edbapp.components["C378"].model_properties = pp
assert edbapp.components["C378"].model_properties == pp

def test_export_gds_comp_xml(self, edb_examples):
edbapp = edb_examples.get_si_verse()
xml_output = os.path.join(self.local_scratch.path, "test.xml")
assert edbapp.export_gds_comp_xml(["U1", "U2", "C2", "R1"], control_path=xml_output)
assert os.path.isfile(xml_output)
edbapp.close()

0 comments on commit 9cfe330

Please sign in to comment.