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

FEAT: cfg modeler #875

Merged
merged 20 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/use_configuration/import_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@

port_4 = {
"name": "port_4",
"type": "circuit",
"positive_terminal": {"coordinates": {"layer": "1_Top", "point": ["104mm", "37mm"], "net": "AVCC_1V3"}},
"negative_terminal": {"coordinates": {"layer": "Inner6(GND2)", "point": ["104mm", "37mm"], "net": "GND"}},
}
Expand Down
20 changes: 20 additions & 0 deletions src/pyedb/configuration/cfg_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,23 @@ def set_attributes(self, pedb_object):
if attr not in dir(pedb_object):
raise AttributeError(f"Invalid attribute '{attr}' in '{pedb_object}'")
setattr(pedb_object, attr, value)


class CfgVar:
def __init__(self, **kwargs):
self.name = kwargs["name"]
self.value = kwargs["value"]
self.description = kwargs.get("description", "")


class CfgVariables:
def __init__(self, pedb, data):
self._pedb = pedb
self.variables = [CfgVar(**i) for i in data]

def apply(self):
for i in self.variables:
if i.name.startswith("$"):
self._pedb.add_project_variable(i.name, i.value)
else:
self._pedb.add_design_variable(i.name, i.value)
3 changes: 3 additions & 0 deletions src/pyedb/configuration/cfg_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def __init__(self, pedb, pedb_object, **kwargs):
self.reference_designator = kwargs.get("reference_designator", None)
self.definition = kwargs.get("definition", None)
self.type = kwargs["part_type"].lower() if kwargs.get("part_type") else None
self.placement_layer = kwargs.get("placement_layer", None)
self.pins = kwargs.get("pins", [])

self.port_properties = kwargs.get("port_properties", {})
self.solder_ball_properties = kwargs.get("solder_ball_properties", {})
self.ic_die_properties = kwargs.get("ic_die_properties", {})
Expand Down
6 changes: 6 additions & 0 deletions src/pyedb/configuration/cfg_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@


from pyedb.configuration.cfg_boundaries import CfgBoundaries
from pyedb.configuration.cfg_common import CfgVariables
from pyedb.configuration.cfg_components import CfgComponents
from pyedb.configuration.cfg_general import CfgGeneral
from pyedb.configuration.cfg_modeler import CfgModeler
from pyedb.configuration.cfg_nets import CfgNets
from pyedb.configuration.cfg_operations import CfgOperations
from pyedb.configuration.cfg_package_definition import CfgPackageDefinitions
Expand Down Expand Up @@ -72,3 +74,7 @@ def __init__(self, pedb, **kwargs):

self.package_definitions = CfgPackageDefinitions(self._pedb, data=kwargs.get("package_definitions", []))
self.operations = CfgOperations(self._pedb, data=kwargs.get("operations", []))

self.modeler = CfgModeler(self._pedb, data=kwargs.get("modeler", {}))

self.variables = CfgVariables(self._pedb, data=kwargs.get("variables", []))
128 changes: 128 additions & 0 deletions src/pyedb/configuration/cfg_modeler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pyedb.configuration.cfg_components import CfgComponent
from pyedb.configuration.cfg_padstacks import CfgPadstackDefinition, CfgPadstackInstance
from pyedb.dotnet.edb_core.edb_data.padstacks_data import EDBPadstack


class CfgTrace:
def __init__(self, **kwargs):
self.name = kwargs.get("name", "")
self.layer = kwargs["layer"]
self.path = kwargs["path"]
self.width = kwargs["width"]
self.net_name = kwargs.get("net_name", "")
self.start_cap_style = kwargs.get("start_cap_style", "round")
self.end_cap_style = kwargs.get("end_cap_style", "round")
self.corner_style = kwargs.get("corner_style", "sharp")


class CfgPlane:
def __init__(self, **kwargs):
self.name = kwargs.get("name", "")
self.layer = kwargs["layer"]
self.net_name = kwargs.get("net_name", "")
self.type = kwargs.get("type", "rectangle")
self.lower_left_point = kwargs["lower_left_point"]
self.upper_right_point = kwargs["upper_right_point"]
self.corner_radius = kwargs.get("corner_radius", 0)
self.rotation = kwargs.get("rotation", 0)
self.voids = kwargs.get("voids", [])


class CfgModeler:
"""Manage configuration general settings."""

def __init__(self, pedb, data):
self._pedb = pedb
self.traces = [CfgTrace(**i) for i in data.get("traces", [])]
self.padstack_defs = [
CfgPadstackDefinition(self._pedb, None, **i) for i in data.get("padstack_definitions", [])
]
self.padstack_instances = [
CfgPadstackInstance(self._pedb, None, **i) for i in data.get("padstack_instances", [])
]
self.planes = [CfgPlane(**i) for i in data.get("planes", [])]
self.components = [CfgComponent(self._pedb, None, **i) for i in data.get("components", [])]

def apply(self):
if self.traces:
for t in self.traces:
obj = self._pedb.modeler.create_trace(
path_list=t.path,
layer_name=t.layer,
net_name=t.net_name,
width=t.width,
start_cap_style=t.start_cap_style,
end_cap_style=t.end_cap_style,
corner_style=t.corner_style,
)
obj.aedt_name = t.name

if self.padstack_defs:
for p in self.padstack_defs:
pdata = self._pedb._edb.Definition.PadstackDefData.Create()
pdef = self._pedb._edb.Definition.PadstackDef.Create(self._pedb.active_db, p.name)
pdef.SetData(pdata)
pdef = EDBPadstack(pdef, self._pedb.padstacks)
p._pyedb_obj = pdef
p.set_parameters_to_edb()

if self.padstack_instances:
for p in self.padstack_instances:
p_inst = self._pedb.padstacks.place(
via_name=p.name,
position=p.position,
definition_name=p.definition,
)
p._pyedb_obj = p_inst
p.set_parameters_to_edb()

if self.planes:
for p in self.planes:
if p.type == "rectangle":
obj = self._pedb.modeler.create_rectangle(
layer_name=p.layer,
net_name=p.net_name,
lower_left_point=p.lower_left_point,
upper_right_point=p.upper_right_point,
corner_radius=p.corner_radius,
rotation=p.rotation,
)
obj.aedt_name = p.name
for v in p.voids:
for i in self._pedb.layout.primitives:
if i.aedt_name == v:
self._pedb.modeler.add_void(obj, i)

if self.components:
pedb_p_inst = self._pedb.padstacks.instances_by_name
for c in self.components:
obj = self._pedb.components.create(
[pedb_p_inst[i] for i in c.pins],
component_name=c.reference_designator,
placement_layer=c.placement_layer,
component_part_name=c.definition,
)
c._pyedb_obj = obj
c.set_parameters_to_edb()
28 changes: 18 additions & 10 deletions src/pyedb/configuration/cfg_padstacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def __init__(self, pedb, padstack_dict=None):
padstack_defs_layout = self._pedb.padstacks.definitions
for pdef in padstack_dict.get("definitions", []):
obj = padstack_defs_layout[pdef["name"]]
self.definitions.append(Definition(self._pedb, obj, **pdef))
self.definitions.append(CfgPadstackDefinition(self._pedb, obj, **pdef))

inst_from_layout = self._pedb.padstacks.instances_by_name
for inst in padstack_dict.get("instances", []):
obj = inst_from_layout[inst["name"]]
self.instances.append(Instance(self._pedb, obj, **inst))
self.instances.append(CfgPadstackInstance(self._pedb, obj, **inst))

def clean(self):
self.definitions = []
Expand All @@ -63,17 +63,17 @@ def apply(self):
def retrieve_parameters_from_edb(self):
self.clean()
for _, obj in self._pedb.padstacks.definitions.items():
pdef = Definition(self._pedb, obj)
pdef = CfgPadstackDefinition(self._pedb, obj)
pdef.retrieve_parameters_from_edb()
self.definitions.append(pdef)

for obj in self._pedb.layout.padstack_instances:
inst = Instance(self._pedb, obj)
inst = CfgPadstackInstance(self._pedb, obj)
inst.retrieve_parameters_from_edb()
self.instances.append(inst)


class Definition(CfgBase):
class CfgPadstackDefinition(CfgBase):
"""Padstack definition data class."""

PAD_SHAPE_PARAMETERS = {
Expand All @@ -98,16 +98,16 @@ def __init__(self, pedb, pedb_object, **kwargs):
self.hole_parameters = kwargs.get("hole_parameters", None)

def set_parameters_to_edb(self):
if self.hole_parameters:
self._set_hole_parameters_to_edb(self.hole_parameters)
if self.hole_range:
self._pyedb_obj.hole_range = self.hole_range
if self.hole_plating_thickness:
self._pyedb_obj.hole_plating_thickness = self.hole_plating_thickness
if self.material:
self._pyedb_obj.material = self.material
if self.hole_range:
self._pyedb_obj.hole_range = self.hole_range
if self.pad_parameters:
self._set_pad_parameters_to_edb(self.pad_parameters)
if self.hole_parameters:
self._set_hole_parameters_to_edb(self.hole_parameters)

def retrieve_parameters_from_edb(self):
self.name = self._pyedb_obj.name
Expand Down Expand Up @@ -282,13 +282,15 @@ def _set_hole_parameters_to_edb(self, params):
self._pyedb_obj._padstack_def_data = pdef_data


class Instance(CfgBase):
class CfgPadstackInstance(CfgBase):
"""Instance data class."""

def __init__(self, pedb, pyedb_obj, **kwargs):
self._pedb = pedb
self._pyedb_obj = pyedb_obj
self.name = kwargs.get("name", None)
self.net_name = kwargs.get("net_name", "")
self.layer_range = kwargs.get("layer_range", [None, None])
self.definition = kwargs.get("definition", None)
self.backdrill_parameters = kwargs.get("backdrill_parameters", None)
self._id = kwargs.get("id", None)
Expand All @@ -300,6 +302,12 @@ def __init__(self, pedb, pyedb_obj, **kwargs):
def set_parameters_to_edb(self):
if self.name is not None:
self._pyedb_obj.aedt_name = self.name
if self.net_name is not None:
self._pyedb_obj.net_name = self._pedb.nets.find_or_create_net(self.net_name).name
if self.layer_range[0] is not None:
self._pyedb_obj.start_layer = self.layer_range[0]
if self.layer_range[1] is not None:
self._pyedb_obj.stop_layer = self.layer_range[1]
if self.backdrill_parameters:
self._pyedb_obj.backdrill_parameters = self.backdrill_parameters

Expand Down
Loading
Loading