Saving surface specular roughness values to IFC is now supported.

This commit is contained in:
Dion Moult
2022-02-02 15:09:37 +11:00
parent 77821caae4
commit 72397f3aff
3 changed files with 117 additions and 49 deletions
@@ -28,12 +28,19 @@ class Usecase:
for key, value in self.settings["attributes"].items():
if key == "SurfaceColour":
self.edit_surface_colour(value)
elif key == "SpecularHighlight":
self.edit_specular_highlight(value)
elif self.is_colour_or_factor(key):
self.edit_colour_or_factor(key, value)
else:
setattr(self.settings["style"], key, value)
def edit_surface_colour(self, value):
if not self.settings["style"].SurfaceColour:
self.settings["style"].SurfaceColour = self.file.createIfcColourRgb(
value.get("Name", None), value["Red"], value["Green"], value["Blue"]
)
self.settings["style"].SurfaceColour[0] = value.get("Name", None)
self.settings["style"].SurfaceColour[1] = value["Red"]
self.settings["style"].SurfaceColour[2] = value["Green"]
self.settings["style"].SurfaceColour[3] = value["Blue"]
@@ -62,3 +69,13 @@ class Usecase:
if existing_value and existing_value.id():
self.file.remove(existing_value)
setattr(self.settings["style"], name, self.file.createIfcNormalisedRatioMeasure(value))
def edit_specular_highlight(self, value):
if value is None:
self.settings["style"].SpecularHighlight = None
elif value.get("IfcSpecularExponent", None):
self.settings["style"].SpecularHighlight = self.file.createIfcSpecularExponent(value["IfcSpecularExponent"])
elif value.get("IfcSpecularRoughness", None):
self.settings["style"].SpecularHighlight = self.file.createIfcSpecularRoughness(
value["IfcSpecularRoughness"]
)
@@ -24,29 +24,33 @@ import ifcopenshell.api
class TestEditTaskTime(test.bootstrap.IFC4):
def test_editing_all_attributes(self):
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={
"Name": "Name",
"DataOrigin": "NOTDEFINED",
"UserDefinedDataOrigin": "UserDefinedDataOrigin",
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": "P1D",
"ScheduleStart": "2000-01-01T00:00:00",
"ScheduleFinish": "2000-01-02T00:00:00",
"EarlyStart": "2000-01-01T00:00:00",
"EarlyFinish": "2000-01-02T00:00:00",
"LateStart": "2000-01-01T00:00:00",
"LateFinish": "2000-01-02T00:00:00",
"FreeFloat": "P0D",
"TotalFloat": "P0D",
"IsCritical": True,
"StatusTime": "2000-01-01T00:00:00",
"ActualDuration": "P1D",
"ActualStart": "2000-01-01T00:00:00",
"ActualFinish": "2000-01-02T00:00:00",
"RemainingTime": "P1D",
"Completion": 0.5,
})
ifcopenshell.api.run(
"sequence.edit_task_time",
self.file,
task_time=task_time,
attributes={
"Name": "Name",
"DataOrigin": "NOTDEFINED",
"UserDefinedDataOrigin": "UserDefinedDataOrigin",
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": "P1D",
"ScheduleStart": "2000-01-01T00:00:00",
"ScheduleFinish": "2000-01-02T00:00:00",
"EarlyStart": "2000-01-01T00:00:00",
"EarlyFinish": "2000-01-02T00:00:00",
"LateStart": "2000-01-01T00:00:00",
"LateFinish": "2000-01-02T00:00:00",
"FreeFloat": "P0D",
"TotalFloat": "P0D",
"IsCritical": True,
"StatusTime": "2000-01-01T00:00:00",
"ActualDuration": "P1D",
"ActualStart": "2000-01-01T00:00:00",
"ActualFinish": "2000-01-02T00:00:00",
"RemainingTime": "P1D",
"Completion": 0.5,
},
)
assert task_time.Name == "Name"
assert task_time.DataOrigin == "NOTDEFINED"
assert task_time.UserDefinedDataOrigin == "UserDefinedDataOrigin"
@@ -70,11 +74,16 @@ class TestEditTaskTime(test.bootstrap.IFC4):
def test_schedule_finish_dates_are_auto_calculated_if_possible(self):
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": "P1D",
"ScheduleStart": "2000-01-01T00:00:00",
})
ifcopenshell.api.run(
"sequence.edit_task_time",
self.file,
task_time=task_time,
attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": "P1D",
"ScheduleStart": "2000-01-01T00:00:00",
},
)
assert task_time.DurationType == "ELAPSEDTIME"
assert task_time.ScheduleDuration == "P1D"
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
@@ -82,11 +91,16 @@ class TestEditTaskTime(test.bootstrap.IFC4):
def test_schedule_durations_are_auto_calculated_if_possible(self):
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleStart": "2000-01-01T00:00:00",
"ScheduleFinish": "2000-01-02T00:00:00",
})
ifcopenshell.api.run(
"sequence.edit_task_time",
self.file,
task_time=task_time,
attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleStart": "2000-01-01T00:00:00",
"ScheduleFinish": "2000-01-02T00:00:00",
},
)
assert task_time.DurationType == "ELAPSEDTIME"
assert task_time.ScheduleDuration == "P1D"
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
@@ -94,12 +108,17 @@ class TestEditTaskTime(test.bootstrap.IFC4):
def test_a_duration_takes_priority_over_start_and_finish_dates(self):
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": "P1D",
"ScheduleStart": "2000-01-01T00:00:00",
"ScheduleFinish": "2000-01-03T00:00:00",
})
ifcopenshell.api.run(
"sequence.edit_task_time",
self.file,
task_time=task_time,
attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": "P1D",
"ScheduleStart": "2000-01-01T00:00:00",
"ScheduleFinish": "2000-01-03T00:00:00",
},
)
assert task_time.DurationType == "ELAPSEDTIME"
assert task_time.ScheduleDuration == "P1D"
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
@@ -107,11 +126,16 @@ class TestEditTaskTime(test.bootstrap.IFC4):
def test_durations_can_be_specified_in_datetime_objects(self):
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": datetime.timedelta(days=1),
"ScheduleStart": "2000-01-01T00:00:00",
})
ifcopenshell.api.run(
"sequence.edit_task_time",
self.file,
task_time=task_time,
attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": datetime.timedelta(days=1),
"ScheduleStart": "2000-01-01T00:00:00",
},
)
assert task_time.DurationType == "ELAPSEDTIME"
assert task_time.ScheduleDuration == "P1D"
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
@@ -119,11 +143,16 @@ class TestEditTaskTime(test.bootstrap.IFC4):
def test_zero_durations_are_allowed(self):
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
ifcopenshell.api.run("sequence.edit_task_time", self.file, task_time=task_time, attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": datetime.timedelta(),
"ScheduleStart": "2000-01-01T00:00:00",
})
ifcopenshell.api.run(
"sequence.edit_task_time",
self.file,
task_time=task_time,
attributes={
"DurationType": "ELAPSEDTIME",
"ScheduleDuration": datetime.timedelta(),
"ScheduleStart": "2000-01-01T00:00:00",
},
)
assert task_time.DurationType == "ELAPSEDTIME"
assert task_time.ScheduleDuration == "P0D"
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
@@ -118,3 +118,25 @@ class TestEditSurfaceStyle(test.bootstrap.IFC4):
attributes={attribute: {"Red": 1, "Green": 1, "Blue": 1}},
)
assert list(getattr(style, attribute)) == [None, 1, 1, 1]
def test_editing_a_specular_highlight_as_an_exponent(self):
style = self.file.createIfcSurfaceStyleRendering(self.file.createIfcColourRgb(None, 0, 0, 0))
ifcopenshell.api.run(
"style.edit_surface_style",
self.file,
style=style,
attributes={"SpecularHighlight": {"IfcSpecularExponent": 2}},
)
assert style.SpecularHighlight.is_a("IfcSpecularExponent")
assert style.SpecularHighlight.wrappedValue == 2
def test_editing_a_specular_highlight_as_a_roughness(self):
style = self.file.createIfcSurfaceStyleRendering(self.file.createIfcColourRgb(None, 0, 0, 0))
ifcopenshell.api.run(
"style.edit_surface_style",
self.file,
style=style,
attributes={"SpecularHighlight": {"IfcSpecularRoughness": 0.5}},
)
assert style.SpecularHighlight.is_a("IfcSpecularRoughness")
assert style.SpecularHighlight.wrappedValue == 0.5