mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-11 22:31:55 +00:00
Fix bug where you couldn't edit the geometry of a grid axis
This commit is contained in:
@@ -10,6 +10,7 @@ import blenderbim.bim.module.geometry.assign_styles as assign_styles
|
|||||||
import blenderbim.bim.module.geometry.assign_representation as assign_representation
|
import blenderbim.bim.module.geometry.assign_representation as assign_representation
|
||||||
import blenderbim.bim.module.geometry.unassign_representation as unassign_representation
|
import blenderbim.bim.module.geometry.unassign_representation as unassign_representation
|
||||||
import blenderbim.bim.module.geometry.remove_representation as remove_representation
|
import blenderbim.bim.module.geometry.remove_representation as remove_representation
|
||||||
|
import blenderbim.bim.module.grid.create_axis_curve as create_axis_curve
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim import import_ifc
|
from blenderbim.bim import import_ifc
|
||||||
from blenderbim.bim.module.geometry.data import Data
|
from blenderbim.bim.module.geometry.data import Data
|
||||||
@@ -317,6 +318,11 @@ class UpdateMeshRepresentation(bpy.types.Operator):
|
|||||||
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
bpy.ops.bim.edit_object_placement(obj=obj.name)
|
||||||
|
|
||||||
product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
product = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||||
|
|
||||||
|
if product.is_a("IfcGridAxis"):
|
||||||
|
create_axis_curve.Usecase(self.file, {"AxisCurve": obj, "grid_axis": product}).execute()
|
||||||
|
continue
|
||||||
|
|
||||||
old_representation = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
old_representation = self.file.by_id(obj.data.BIMMeshProperties.ifc_definition_id)
|
||||||
context_of_items = old_representation.ContextOfItems
|
context_of_items = old_representation.ContextOfItems
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import ifcopenshell
|
||||||
|
import ifcopenshell.util.unit
|
||||||
|
import ifcopenshell.util.placement
|
||||||
|
from mathutils import Matrix # For now, we depend on Blender
|
||||||
|
|
||||||
|
|
||||||
|
class Usecase:
|
||||||
|
def __init__(self, file, settings=None):
|
||||||
|
self.file = file
|
||||||
|
self.settings = {
|
||||||
|
"AxisCurve": None, # A Blender object
|
||||||
|
"grid_axis": None,
|
||||||
|
}
|
||||||
|
for key, value in settings.items():
|
||||||
|
self.settings[key] = value
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
if self.settings["grid_axis"].AxisCurve:
|
||||||
|
ifcopenshell.util.element.remove_deep(self.file, self.settings["grid_axis"].AxisCurve)
|
||||||
|
|
||||||
|
self.settings["unit_scale"] = ifcopenshell.util.unit.calculate_unit_scale(self.file)
|
||||||
|
grid = [i for i in self.file.get_inverse(self.settings["grid_axis"]) if i.is_a("IfcGrid")][0]
|
||||||
|
points = [
|
||||||
|
Matrix(ifcopenshell.util.placement.get_local_placement(grid.ObjectPlacement)).inverted()
|
||||||
|
@ (self.settings["AxisCurve"].matrix_world @ v.co)
|
||||||
|
for v in self.settings["AxisCurve"].data.vertices[0:2]
|
||||||
|
]
|
||||||
|
self.settings["grid_axis"].AxisCurve = self.file.createIfcPolyline(
|
||||||
|
[
|
||||||
|
self.create_cartesian_point(points[0][0], points[0][1], points[0][2]),
|
||||||
|
self.create_cartesian_point(points[1][0], points[1][1], points[1][2]),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def create_cartesian_point(self, x, y, z=None):
|
||||||
|
x = self.convert_si_to_unit(x)
|
||||||
|
y = self.convert_si_to_unit(y)
|
||||||
|
if z is None:
|
||||||
|
return self.file.createIfcCartesianPoint((x, y))
|
||||||
|
z = self.convert_si_to_unit(z)
|
||||||
|
return self.file.createIfcCartesianPoint((x, y, z))
|
||||||
|
|
||||||
|
def convert_si_to_unit(self, co):
|
||||||
|
return co / self.settings["unit_scale"]
|
||||||
@@ -1,16 +1,8 @@
|
|||||||
import ifcopenshell
|
|
||||||
import ifcopenshell.util.unit
|
|
||||||
import ifcopenshell.util.placement
|
|
||||||
from mathutils import Matrix # For now, we depend on Blender
|
|
||||||
from blenderbim.bim.module.owner.api import create_owner_history
|
|
||||||
|
|
||||||
|
|
||||||
class Usecase:
|
class Usecase:
|
||||||
def __init__(self, file, settings=None):
|
def __init__(self, file, settings=None):
|
||||||
self.file = file
|
self.file = file
|
||||||
self.settings = {
|
self.settings = {
|
||||||
"AxisTag": "A",
|
"AxisTag": "A",
|
||||||
"AxisCurve": None, # A Blender object
|
|
||||||
"SameSense": True,
|
"SameSense": True,
|
||||||
"UVWAxes": "UAxes", # Choose which axes
|
"UVWAxes": "UAxes", # Choose which axes
|
||||||
"Grid": None,
|
"Grid": None,
|
||||||
@@ -19,35 +11,11 @@ class Usecase:
|
|||||||
self.settings[key] = value
|
self.settings[key] = value
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
self.settings["unit_scale"] = ifcopenshell.util.unit.calculate_unit_scale(self.file)
|
|
||||||
points = [
|
|
||||||
Matrix(ifcopenshell.util.placement.get_local_placement(self.settings["Grid"].ObjectPlacement)).inverted()
|
|
||||||
@ (self.settings["AxisCurve"].matrix_world @ v.co)
|
|
||||||
for v in self.settings["AxisCurve"].data.vertices[0:2]
|
|
||||||
]
|
|
||||||
self.settings["AxisCurve"] = self.file.createIfcPolyline(
|
|
||||||
[
|
|
||||||
self.create_cartesian_point(points[0][0], points[0][1], points[0][2]),
|
|
||||||
self.create_cartesian_point(points[1][0], points[1][1], points[1][2]),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
element = self.file.create_entity("IfcGridAxis", **{
|
element = self.file.create_entity("IfcGridAxis", **{
|
||||||
"AxisTag": self.settings["AxisTag"],
|
"AxisTag": self.settings["AxisTag"],
|
||||||
"AxisCurve": self.settings["AxisCurve"],
|
|
||||||
"SameSense": self.settings["SameSense"]
|
"SameSense": self.settings["SameSense"]
|
||||||
})
|
})
|
||||||
axes = list(getattr(self.settings["Grid"], self.settings["UVWAxes"]) or [])
|
axes = list(getattr(self.settings["Grid"], self.settings["UVWAxes"]) or [])
|
||||||
axes.append(element)
|
axes.append(element)
|
||||||
setattr(self.settings["Grid"], self.settings["UVWAxes"], axes)
|
setattr(self.settings["Grid"], self.settings["UVWAxes"], axes)
|
||||||
return element
|
return element
|
||||||
|
|
||||||
def create_cartesian_point(self, x, y, z=None):
|
|
||||||
x = self.convert_si_to_unit(x)
|
|
||||||
y = self.convert_si_to_unit(y)
|
|
||||||
if z is None:
|
|
||||||
return self.file.createIfcCartesianPoint((x, y))
|
|
||||||
z = self.convert_si_to_unit(z)
|
|
||||||
return self.file.createIfcCartesianPoint((x, y, z))
|
|
||||||
|
|
||||||
def convert_si_to_unit(self, co):
|
|
||||||
return co / self.settings["unit_scale"]
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import blenderbim.bim.module.grid.create_grid_axis as create_grid_axis
|
import blenderbim.bim.module.grid.create_grid_axis as create_grid_axis
|
||||||
|
import blenderbim.bim.module.grid.create_axis_curve as create_axis_curve
|
||||||
from bpy.types import Operator
|
from bpy.types import Operator
|
||||||
from bpy.props import FloatProperty, IntProperty
|
from bpy.props import FloatProperty, IntProperty
|
||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
@@ -52,6 +53,7 @@ def add_object(self, context):
|
|||||||
result = create_grid_axis.Usecase(
|
result = create_grid_axis.Usecase(
|
||||||
self.file, {"AxisTag": tag, "AxisCurve": obj, "UVWAxes": "UAxes", "Grid": grid}
|
self.file, {"AxisTag": tag, "AxisCurve": obj, "UVWAxes": "UAxes", "Grid": grid}
|
||||||
).execute()
|
).execute()
|
||||||
|
create_axis_curve.Usecase(self.file, {"AxisCurve": obj, "grid_axis": result}).execute()
|
||||||
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
||||||
|
|
||||||
axes_collection = bpy.data.collections.new("VAxes")
|
axes_collection = bpy.data.collections.new("VAxes")
|
||||||
@@ -74,6 +76,7 @@ def add_object(self, context):
|
|||||||
result = create_grid_axis.Usecase(
|
result = create_grid_axis.Usecase(
|
||||||
self.file, {"AxisTag": tag, "AxisCurve": obj, "UVWAxes": "VAxes", "Grid": grid}
|
self.file, {"AxisTag": tag, "AxisCurve": obj, "UVWAxes": "VAxes", "Grid": grid}
|
||||||
).execute()
|
).execute()
|
||||||
|
create_axis_curve.Usecase(self.file, {"AxisCurve": obj, "grid_axis": result}).execute()
|
||||||
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
obj.BIMObjectProperties.ifc_definition_id = result.id()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user