Fix bug where editing styles didn't work if factors were stored instead of RGB colours

This commit is contained in:
Dion Moult
2021-09-10 17:43:26 +10:00
parent 9b94c3ceca
commit d350a17ce5
7 changed files with 170 additions and 99 deletions
+1 -1
View File
@@ -172,6 +172,7 @@ class IfcExporter:
try:
# This will throw an exception if the Blender object no longer exists
foo = obj.name
foo
return False
except:
return True
@@ -199,7 +200,6 @@ class IfcExportSettings:
@staticmethod
def factory(context, output_file, logger):
scene_bim = context.scene.BIMProperties
settings = IfcExportSettings()
settings.output_file = output_file
settings.logger = logger
+17 -28
View File
@@ -16,31 +16,24 @@
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.geom
import ifcopenshell.util.geolocation
import ifcopenshell.util.selector
import ifcopenshell.util.element
import ifcopenshell.util.unit
import bpy
import bmesh
import os
import re
import shutil
import threading
import bpy
import json
import time
import bmesh
import shutil
import threading
import mathutils
import math
import multiprocessing
import zipfile
import tempfile
import numpy as np
from blenderbim.bim.module.drawing.prop import getDiagramScales
from pathlib import Path
from itertools import cycle
from datetime import datetime
import multiprocessing
import ifcopenshell
import ifcopenshell.geom
import ifcopenshell.util.unit
import ifcopenshell.util.element
import ifcopenshell.util.selector
import ifcopenshell.util.geolocation
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.drawing.prop import getDiagramScales
class FileCopy(threading.Thread):
@@ -407,7 +400,6 @@ class IfcImporter:
props.has_blender_offset = True
def get_offset_point(self):
offset_point = None
elements_checked = 0
# If more than these points aren't far away, the file probably isn't absolutely positioned
element_checking_threshold = 100
@@ -462,16 +454,14 @@ class IfcImporter:
return mathutils.Matrix(matrix.tolist())
def find_decomposed_ifc_class(self, element, ifc_class):
results = []
if element.is_a(ifc_class):
return element
rel_aggregates = element.IsDecomposedBy
if not rel_aggregates:
return results
for rel_aggregate in rel_aggregates:
for part in rel_aggregate.RelatedObjects:
if part.is_a(ifc_class):
results.append(part)
results.extend(self.find_decomposed_ifc_class(part, ifc_class))
return results
result = self.find_decomposed_ifc_class(part, ifc_class)
if result:
return result
def create_grids(self):
grids = self.file.by_type("IfcGrid")
@@ -1485,7 +1475,6 @@ class IfcImportSettings:
@staticmethod
def factory(context, input_file, logger):
scene_bim = context.scene.BIMProperties
scene_diff = context.scene.DiffProperties
settings = IfcImportSettings()
settings.input_file = input_file
@@ -52,8 +52,25 @@ class UpdateStyleColours(bpy.types.Operator):
self.file = IfcStore.get_file()
material = bpy.data.materials.get(self.material) if self.material else context.active_object.active_material
settings = get_colour_settings(material)
settings["style"] = self.file.by_id(material.BIMMaterialProperties.ifc_style_id)
ifcopenshell.api.run("style.edit_style_colours", self.file, **settings)
for style in self.file.by_id(material.BIMMaterialProperties.ifc_style_id).Styles:
if style.is_a("IfcSurfaceStyleRendering"):
ifcopenshell.api.run(
"style.edit_surface_style",
self.file,
style=style,
attributes={
"SurfaceColour": settings["surface_colour"],
"Transparency": settings["transparency"],
"DiffuseColour": settings["diffuse_colour"],
},
)
elif style.is_a("IfcSurfaceStyleShading"):
ifcopenshell.api.run(
"style.edit_surface_style",
self.file,
style=style,
attributes={"SurfaceColour": settings["surface_colour"], "Transparency": settings["transparency"]},
)
return {"FINISHED"}
@@ -167,7 +184,7 @@ class EditStyle(bpy.types.Operator):
attributes = blenderbim.bim.helper.export_attributes(props.attributes)
self.file = IfcStore.get_file()
style = self.file.by_id(material.BIMMaterialProperties.ifc_style_id)
ifcopenshell.api.run("style.edit_style", self.file, **{"style": style, "attributes": attributes})
ifcopenshell.api.run("style.edit_presentation_style", self.file, **{"style": style, "attributes": attributes})
Data.load(IfcStore.get_file(), material.BIMMaterialProperties.ifc_style_id)
bpy.ops.bim.disable_editing_style()
return {"FINISHED"}