Adding surface styles now respect mutually exclusive style types

This commit is contained in:
Dion Moult
2022-02-02 15:04:19 +11:00
parent 10138e28c9
commit 77821caae4
2 changed files with 125 additions and 11 deletions
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api
class Usecase:
def __init__(self, file, **settings):
@@ -25,22 +28,20 @@ class Usecase:
self.settings[key] = value
def execute(self):
for key, value in self.settings["attributes"].items():
if key == "SurfaceColour" and value:
self.settings["attributes"][key] = self.create_colour_rgb(value)
if key == "DiffuseColour" and isinstance(value, dict):
self.settings["attributes"][key] = self.create_colour_rgb(value)
style_item = self.file.create_entity(self.settings["ifc_class"], **self.settings["attributes"])
style_item = self.file.create_entity(self.settings["ifc_class"])
ifcopenshell.api.run(
"style.edit_surface_style", self.file, style=style_item, attributes=self.settings["attributes"]
)
styles = list(self.settings["style"].Styles or [])
duplicate_items = [s for s in styles if s.is_a(self.settings["ifc_class"])]
select_class = self.settings["ifc_class"]
if select_class == "IfcSurfaceStyleRendering":
select_class = "IfcSurfaceStyleShading"
duplicate_items = [s for s in styles if s.is_a(select_class)]
for duplicate_item in duplicate_items:
self.file.remove(duplicate_item)
styles = list(self.settings["style"].Styles or [])
styles.append(style_item)
self.settings["style"].Styles = styles
return style_item
def create_colour_rgb(self, value):
return self.file.createIfcColourRgb(value["Name"], value["Red"], value["Green"], value["Blue"])