Skip to content

Commit c748879

Browse files
pluAtAnsyspluStefanThoene
authored
add checking existing speos features when create (#422)
same name feature was allowed when committing. * this is not same behaviour in scdm speos. * as we reply on Find with name as searching method, it is better to avoid having features with the same name --------- Signed-off-by: plu <plu@ansys.com> Co-authored-by: plu <plu@ansys.com> Co-authored-by: Stefan Thöne <86405327+StefanThoene@users.noreply.github.com>
1 parent f0b25a0 commit c748879

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/ansys/speos/script/project.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def create_optical_property(self, name: str, description: str = "", metadata: Ma
9595
ansys.speos.script.opt_prop.OptProp
9696
OptProp feature.
9797
"""
98+
existing_features = self.find(name=name)
99+
if len(existing_features) != 0:
100+
msg = "Feature {}: {} has a conflict name with an existing feature.".format(opt_prop.OptProp, name)
101+
raise ValueError(msg)
98102
feature = opt_prop.OptProp(project=self, name=name, description=description, metadata=metadata)
99103
self._features.append(feature)
100104
return feature
@@ -130,6 +134,10 @@ def create_source(
130134
Union[ansys.speos.script.source.Surface, ansys.speos.script.source.RayFile, ansys.speos.script.source.Luminaire]
131135
Source class instance.
132136
"""
137+
existing_features = self.find(name=name)
138+
if len(existing_features) != 0:
139+
msg = "Feature {}: {} has a conflict name with an existing feature.".format(feature_type, name)
140+
raise ValueError(msg)
133141
feature = None
134142
if feature_type == source.Surface:
135143
feature = source.Surface(project=self, name=name, description=description, metadata=metadata)
@@ -171,6 +179,10 @@ def create_simulation(
171179
Union[ansys.speos.script.simulation.Direct, ansys.speos.script.simulation.Interactive, ansys.speos.script.simulation.Inverse]
172180
Simulation class instance
173181
"""
182+
existing_features = self.find(name=name)
183+
if len(existing_features) != 0:
184+
msg = "Feature {}: {} has a conflict name with an existing feature.".format(feature_type, name)
185+
raise ValueError(msg)
174186
feature = None
175187
if feature_type == simulation.Direct:
176188
feature = simulation.Direct(project=self, name=name, description=description, metadata=metadata)
@@ -212,6 +224,10 @@ def create_sensor(
212224
Union[ansys.speos.script.sensor.Camera, ansys.speos.script.sensor.Radiance, ansys.speos.script.sensor.Irradiance]
213225
Sensor class instance.
214226
"""
227+
existing_features = self.find(name=name)
228+
if len(existing_features) != 0:
229+
msg = "Feature {}: {} has a conflict name with an existing feature.".format(feature_type, name)
230+
raise ValueError(msg)
215231
feature = None
216232
if feature_type == sensor.Irradiance:
217233
feature = sensor.Irradiance(project=self, name=name, description=description, metadata=metadata)
@@ -538,8 +554,9 @@ def _fill_features(self):
538554
self._fill_bodies(body_guids=part_data.body_guids, feat_host=sp_feat)
539555

540556
for mat_inst in scene_data.materials:
541-
op_feature = self.create_optical_property(name=mat_inst.name)
542-
op_feature._fill(mat_inst=mat_inst)
557+
if len(self.find(name=mat_inst.name)) == 0:
558+
op_feature = self.create_optical_property(name=mat_inst.name)
559+
op_feature._fill(mat_inst=mat_inst)
543560

544561
for src_inst in scene_data.sources:
545562
if src_inst.HasField("rayfile_properties"):

tests/workflow_tests/test_combine_speos.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def test_insert_speos(speos: Speos):
123123
assert len(p.scene_link.get().sensors) == 1
124124
assert len(p.scene_link.get().sources) == 0
125125
assert len(p.scene_link.get().simulations) == 1
126+
assert len(p.find(name=".*", name_regex=True, feature_type=script.opt_prop.OptProp)) == 7
126127

127128
# Insert several speos files into the project - only geometries + materials are retrieved
128129
insert_speos(
@@ -143,6 +144,7 @@ def test_insert_speos(speos: Speos):
143144
assert len(p.scene_link.get().sensors) == 1
144145
assert len(p.scene_link.get().sources) == 0
145146
assert len(p.scene_link.get().simulations) == 1
147+
assert len(p.find(name=".*", name_regex=True, feature_type=script.opt_prop.OptProp)) == 12
146148

147149
# Check that the root part contains one part per speos to insert
148150
root_part = p.find(name="", feature_type=script.Part)[0]

0 commit comments

Comments
 (0)