diff --git a/src/pyedb/configuration/cfg_data.py b/src/pyedb/configuration/cfg_data.py index 0f7c226b9b..e32acc13a8 100644 --- a/src/pyedb/configuration/cfg_data.py +++ b/src/pyedb/configuration/cfg_data.py @@ -48,11 +48,9 @@ def __init__(self, pedb, **kwargs): if kwargs.get("boundaries", None): self.boundaries = CfgBoundaries(self, kwargs.get("boundaries", None)) - self.nets = None - if kwargs.get("nets"): - self.nets = CfgNets( - self, kwargs.get("nets", {}).get("signal_nets", []), kwargs.get("nets", {}).get("power_ground_nets", []) - ) + self.nets = CfgNets( + self, kwargs.get("nets", {}).get("signal_nets", []), kwargs.get("nets", {}).get("power_ground_nets", []) + ) self.components = CfgComponents(self._pedb, components_data=kwargs.get("components", [])) diff --git a/src/pyedb/configuration/cfg_nets.py b/src/pyedb/configuration/cfg_nets.py index d959289663..660c710983 100644 --- a/src/pyedb/configuration/cfg_nets.py +++ b/src/pyedb/configuration/cfg_nets.py @@ -41,3 +41,17 @@ def apply(self): for power_net in self.power_nets: if power_net in self._pedb.nets: self._pedb.nets.nets[power_net].is_power_ground = True + + def _load_data_from_db(self): + self.signal_nets = [] + self.power_nets = [] + for net in self._pedb.nets.signal: + self.signal_nets.append(net) + for net in self._pedb.nets.power: + self.power_nets.append(net) + + def get_data_from_db(self): + """Get net information.""" + self._load_data_from_db() + data = {"signal_nets": self.signal_nets, "power_ground_nets": self.power_nets} + return data diff --git a/src/pyedb/configuration/configuration.py b/src/pyedb/configuration/configuration.py index 16a124694c..2e6cd41c2d 100644 --- a/src/pyedb/configuration/configuration.py +++ b/src/pyedb/configuration/configuration.py @@ -273,10 +273,11 @@ def get_data_from_db(self, **kwargs): data["setups"] = self.cfg_data.setups.get_data_from_db() if kwargs.get("components", False): data["components"] = self.cfg_data.components.get_data_from_db() - + if kwargs.get("nets", False): + data["nets"] = self.cfg_data.nets.get_data_from_db() return data - def export(self, file_path, stackup=True, package_definitions=True, setups=True): + def export(self, file_path, stackup=True, package_definitions=True, setups=True, nets=True): """Export the configuration data from layout to a file. Parameters @@ -292,7 +293,7 @@ def export(self, file_path, stackup=True, package_definitions=True, setups=True) """ file_path = file_path if isinstance(file_path, Path) else Path(file_path) file_path = file_path if file_path.suffix == ".json" else file_path.with_suffix(".json") - data = self.get_data_from_db(stackup=stackup, package_definitions=package_definitions, setups=setups) + data = self.get_data_from_db(stackup=stackup, package_definitions=package_definitions, setups=setups, nets=nets) with open(file_path, "w") as f: json.dump(data, f, ensure_ascii=False, indent=4) return True if os.path.isfile(file_path) else False diff --git a/tests/legacy/system/test_edb_configuration_2p0.py b/tests/legacy/system/test_edb_configuration_2p0.py index b0e8bb122a..ecd333dcff 100644 --- a/tests/legacy/system/test_edb_configuration_2p0.py +++ b/tests/legacy/system/test_edb_configuration_2p0.py @@ -793,3 +793,17 @@ def test_16_export_to_external_file(self, edb_examples): data_file_path = Path(edb_examples.test_folder) / "test.json" edbapp.configuration.export(data_file_path) assert data_file_path.is_file() + with open(data_file_path) as f: + data = json.load(f) + assert "stackup" in data + assert data["stackup"]["materials"] + assert data["stackup"]["materials"][0]["name"] == "copper" + assert data["stackup"]["materials"][0]["conductivity"] == 5.8e7 + assert data["stackup"]["layers"] + data["stackup"]["layers"][0]["name"] = "1_Top" + data["stackup"]["layers"][0]["type"] = "signal" + data["stackup"]["layers"][0]["material"] = "copper" + assert data["nets"] + assert len(data["nets"]["signal_nets"]) == 342 + assert len(data["nets"]["power_ground_nets"]) == 6 + edbapp.close()