mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
Saving surface specular roughness values to IFC is now supported.
This commit is contained in:
@@ -28,12 +28,19 @@ class Usecase:
|
|||||||
for key, value in self.settings["attributes"].items():
|
for key, value in self.settings["attributes"].items():
|
||||||
if key == "SurfaceColour":
|
if key == "SurfaceColour":
|
||||||
self.edit_surface_colour(value)
|
self.edit_surface_colour(value)
|
||||||
|
elif key == "SpecularHighlight":
|
||||||
|
self.edit_specular_highlight(value)
|
||||||
elif self.is_colour_or_factor(key):
|
elif self.is_colour_or_factor(key):
|
||||||
self.edit_colour_or_factor(key, value)
|
self.edit_colour_or_factor(key, value)
|
||||||
else:
|
else:
|
||||||
setattr(self.settings["style"], key, value)
|
setattr(self.settings["style"], key, value)
|
||||||
|
|
||||||
def edit_surface_colour(self, 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[1] = value["Red"]
|
||||||
self.settings["style"].SurfaceColour[2] = value["Green"]
|
self.settings["style"].SurfaceColour[2] = value["Green"]
|
||||||
self.settings["style"].SurfaceColour[3] = value["Blue"]
|
self.settings["style"].SurfaceColour[3] = value["Blue"]
|
||||||
@@ -62,3 +69,13 @@ class Usecase:
|
|||||||
if existing_value and existing_value.id():
|
if existing_value and existing_value.id():
|
||||||
self.file.remove(existing_value)
|
self.file.remove(existing_value)
|
||||||
setattr(self.settings["style"], name, self.file.createIfcNormalisedRatioMeasure(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):
|
class TestEditTaskTime(test.bootstrap.IFC4):
|
||||||
def test_editing_all_attributes(self):
|
def test_editing_all_attributes(self):
|
||||||
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
|
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={
|
ifcopenshell.api.run(
|
||||||
"Name": "Name",
|
"sequence.edit_task_time",
|
||||||
"DataOrigin": "NOTDEFINED",
|
self.file,
|
||||||
"UserDefinedDataOrigin": "UserDefinedDataOrigin",
|
task_time=task_time,
|
||||||
"DurationType": "ELAPSEDTIME",
|
attributes={
|
||||||
"ScheduleDuration": "P1D",
|
"Name": "Name",
|
||||||
"ScheduleStart": "2000-01-01T00:00:00",
|
"DataOrigin": "NOTDEFINED",
|
||||||
"ScheduleFinish": "2000-01-02T00:00:00",
|
"UserDefinedDataOrigin": "UserDefinedDataOrigin",
|
||||||
"EarlyStart": "2000-01-01T00:00:00",
|
"DurationType": "ELAPSEDTIME",
|
||||||
"EarlyFinish": "2000-01-02T00:00:00",
|
"ScheduleDuration": "P1D",
|
||||||
"LateStart": "2000-01-01T00:00:00",
|
"ScheduleStart": "2000-01-01T00:00:00",
|
||||||
"LateFinish": "2000-01-02T00:00:00",
|
"ScheduleFinish": "2000-01-02T00:00:00",
|
||||||
"FreeFloat": "P0D",
|
"EarlyStart": "2000-01-01T00:00:00",
|
||||||
"TotalFloat": "P0D",
|
"EarlyFinish": "2000-01-02T00:00:00",
|
||||||
"IsCritical": True,
|
"LateStart": "2000-01-01T00:00:00",
|
||||||
"StatusTime": "2000-01-01T00:00:00",
|
"LateFinish": "2000-01-02T00:00:00",
|
||||||
"ActualDuration": "P1D",
|
"FreeFloat": "P0D",
|
||||||
"ActualStart": "2000-01-01T00:00:00",
|
"TotalFloat": "P0D",
|
||||||
"ActualFinish": "2000-01-02T00:00:00",
|
"IsCritical": True,
|
||||||
"RemainingTime": "P1D",
|
"StatusTime": "2000-01-01T00:00:00",
|
||||||
"Completion": 0.5,
|
"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.Name == "Name"
|
||||||
assert task_time.DataOrigin == "NOTDEFINED"
|
assert task_time.DataOrigin == "NOTDEFINED"
|
||||||
assert task_time.UserDefinedDataOrigin == "UserDefinedDataOrigin"
|
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):
|
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())
|
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={
|
ifcopenshell.api.run(
|
||||||
"DurationType": "ELAPSEDTIME",
|
"sequence.edit_task_time",
|
||||||
"ScheduleDuration": "P1D",
|
self.file,
|
||||||
"ScheduleStart": "2000-01-01T00:00:00",
|
task_time=task_time,
|
||||||
})
|
attributes={
|
||||||
|
"DurationType": "ELAPSEDTIME",
|
||||||
|
"ScheduleDuration": "P1D",
|
||||||
|
"ScheduleStart": "2000-01-01T00:00:00",
|
||||||
|
},
|
||||||
|
)
|
||||||
assert task_time.DurationType == "ELAPSEDTIME"
|
assert task_time.DurationType == "ELAPSEDTIME"
|
||||||
assert task_time.ScheduleDuration == "P1D"
|
assert task_time.ScheduleDuration == "P1D"
|
||||||
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
|
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):
|
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())
|
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={
|
ifcopenshell.api.run(
|
||||||
"DurationType": "ELAPSEDTIME",
|
"sequence.edit_task_time",
|
||||||
"ScheduleStart": "2000-01-01T00:00:00",
|
self.file,
|
||||||
"ScheduleFinish": "2000-01-02T00:00:00",
|
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.DurationType == "ELAPSEDTIME"
|
||||||
assert task_time.ScheduleDuration == "P1D"
|
assert task_time.ScheduleDuration == "P1D"
|
||||||
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
|
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):
|
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())
|
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={
|
ifcopenshell.api.run(
|
||||||
"DurationType": "ELAPSEDTIME",
|
"sequence.edit_task_time",
|
||||||
"ScheduleDuration": "P1D",
|
self.file,
|
||||||
"ScheduleStart": "2000-01-01T00:00:00",
|
task_time=task_time,
|
||||||
"ScheduleFinish": "2000-01-03T00:00:00",
|
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.DurationType == "ELAPSEDTIME"
|
||||||
assert task_time.ScheduleDuration == "P1D"
|
assert task_time.ScheduleDuration == "P1D"
|
||||||
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
|
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):
|
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())
|
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={
|
ifcopenshell.api.run(
|
||||||
"DurationType": "ELAPSEDTIME",
|
"sequence.edit_task_time",
|
||||||
"ScheduleDuration": datetime.timedelta(days=1),
|
self.file,
|
||||||
"ScheduleStart": "2000-01-01T00:00:00",
|
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.DurationType == "ELAPSEDTIME"
|
||||||
assert task_time.ScheduleDuration == "P1D"
|
assert task_time.ScheduleDuration == "P1D"
|
||||||
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
|
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):
|
def test_zero_durations_are_allowed(self):
|
||||||
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=self.file.createIfcTask())
|
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={
|
ifcopenshell.api.run(
|
||||||
"DurationType": "ELAPSEDTIME",
|
"sequence.edit_task_time",
|
||||||
"ScheduleDuration": datetime.timedelta(),
|
self.file,
|
||||||
"ScheduleStart": "2000-01-01T00:00:00",
|
task_time=task_time,
|
||||||
})
|
attributes={
|
||||||
|
"DurationType": "ELAPSEDTIME",
|
||||||
|
"ScheduleDuration": datetime.timedelta(),
|
||||||
|
"ScheduleStart": "2000-01-01T00:00:00",
|
||||||
|
},
|
||||||
|
)
|
||||||
assert task_time.DurationType == "ELAPSEDTIME"
|
assert task_time.DurationType == "ELAPSEDTIME"
|
||||||
assert task_time.ScheduleDuration == "P0D"
|
assert task_time.ScheduleDuration == "P0D"
|
||||||
assert task_time.ScheduleStart == "2000-01-01T00:00:00"
|
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}},
|
attributes={attribute: {"Red": 1, "Green": 1, "Blue": 1}},
|
||||||
)
|
)
|
||||||
assert list(getattr(style, attribute)) == [None, 1, 1, 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
|
||||||
|
|||||||
Reference in New Issue
Block a user