mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
You can now copy a representation from one object to another
This commit is contained in:
@@ -20,13 +20,14 @@ import bpy
|
|||||||
from . import ui, prop, operator
|
from . import ui, prop, operator
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
operator.EditObjectPlacement,
|
|
||||||
operator.AddRepresentation,
|
operator.AddRepresentation,
|
||||||
operator.SwitchRepresentation,
|
operator.CopyRepresentation,
|
||||||
operator.RemoveRepresentation,
|
operator.EditObjectPlacement,
|
||||||
operator.UpdateRepresentation,
|
|
||||||
operator.UpdateParametricRepresentation,
|
|
||||||
operator.GetRepresentationIfcParameters,
|
operator.GetRepresentationIfcParameters,
|
||||||
|
operator.RemoveRepresentation,
|
||||||
|
operator.SwitchRepresentation,
|
||||||
|
operator.UpdateParametricRepresentation,
|
||||||
|
operator.UpdateRepresentation,
|
||||||
prop.BIMGeometryProperties,
|
prop.BIMGeometryProperties,
|
||||||
ui.BIM_PT_derived_placements,
|
ui.BIM_PT_derived_placements,
|
||||||
ui.BIM_PT_representations,
|
ui.BIM_PT_representations,
|
||||||
|
|||||||
@@ -17,16 +17,18 @@
|
|||||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
import bmesh
|
||||||
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.util.unit
|
import ifcopenshell.util.unit
|
||||||
import ifcopenshell.util.element
|
import ifcopenshell.util.element
|
||||||
import ifcopenshell.util.representation
|
import ifcopenshell.util.representation
|
||||||
import logging
|
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import blenderbim.core.geometry as core
|
import blenderbim.core.geometry as core
|
||||||
import blenderbim.core.style
|
import blenderbim.core.style
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
|
import blenderbim.bim.handler
|
||||||
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 ifcopenshell.api.geometry.data import Data
|
from ifcopenshell.api.geometry.data import Data
|
||||||
@@ -38,6 +40,7 @@ from mathutils import Vector
|
|||||||
class Operator:
|
class Operator:
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
IfcStore.execute_ifc_operator(self, context)
|
IfcStore.execute_ifc_operator(self, context)
|
||||||
|
blenderbim.bim.handler.refresh_ui_data()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -53,7 +56,7 @@ class EditObjectPlacement(bpy.types.Operator, Operator):
|
|||||||
core.edit_object_placement(tool.Ifc, tool.Surveyor, obj=obj)
|
core.edit_object_placement(tool.Ifc, tool.Surveyor, obj=obj)
|
||||||
|
|
||||||
|
|
||||||
class AddRepresentation(bpy.types.Operator):
|
class AddRepresentation(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.add_representation"
|
bl_idname = "bim.add_representation"
|
||||||
bl_label = "Add Representation"
|
bl_label = "Add Representation"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
@@ -62,9 +65,6 @@ class AddRepresentation(bpy.types.Operator):
|
|||||||
ifc_representation_class: bpy.props.StringProperty()
|
ifc_representation_class: bpy.props.StringProperty()
|
||||||
profile_set_usage: bpy.props.IntProperty()
|
profile_set_usage: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
@@ -232,16 +232,13 @@ class SwitchRepresentation(bpy.types.Operator):
|
|||||||
self.element_obj.modifiers.remove(modifier)
|
self.element_obj.modifiers.remove(modifier)
|
||||||
|
|
||||||
|
|
||||||
class RemoveRepresentation(bpy.types.Operator):
|
class RemoveRepresentation(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.remove_representation"
|
bl_idname = "bim.remove_representation"
|
||||||
bl_label = "Remove Representation"
|
bl_label = "Remove Representation"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
obj: bpy.props.StringProperty()
|
obj: bpy.props.StringProperty()
|
||||||
representation_id: bpy.props.IntProperty()
|
representation_id: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
self.file = IfcStore.get_file()
|
self.file = IfcStore.get_file()
|
||||||
representation = self.file.by_id(self.representation_id)
|
representation = self.file.by_id(self.representation_id)
|
||||||
@@ -415,3 +412,22 @@ class GetRepresentationIfcParameters(bpy.types.Operator):
|
|||||||
if element[i]:
|
if element[i]:
|
||||||
new.value = element[i]
|
new.value = element[i]
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class CopyRepresentation(bpy.types.Operator, Operator):
|
||||||
|
bl_idname = "bim.copy_representation"
|
||||||
|
bl_label = "Copy Representation"
|
||||||
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
obj: bpy.props.StringProperty()
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
if not context.active_object:
|
||||||
|
return
|
||||||
|
bm = bmesh.new()
|
||||||
|
bm.from_mesh(context.active_object.data)
|
||||||
|
for obj in context.selected_objects:
|
||||||
|
if obj == context.active_object:
|
||||||
|
continue
|
||||||
|
if obj.data:
|
||||||
|
bm.to_mesh(obj.data)
|
||||||
|
bpy.ops.bim.add_representation(obj=obj.name)
|
||||||
|
|||||||
@@ -102,6 +102,9 @@ class BIM_PT_mesh(Panel):
|
|||||||
op.ifc_definition_id = props.ifc_definition_id
|
op.ifc_definition_id = props.ifc_definition_id
|
||||||
op.disable_opening_subtractions = True
|
op.disable_opening_subtractions = True
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
|
row.operator("bim.copy_representation")
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("bim.update_representation")
|
row.operator("bim.update_representation")
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
@geometry
|
@geometry
|
||||||
Feature: Geometry
|
Feature: Geometry
|
||||||
Covers geometry and coordinate manipulation
|
|
||||||
|
|
||||||
Scenario: Edit object placement
|
Scenario: Edit object placement
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
@@ -11,3 +10,17 @@ Scenario: Edit object placement
|
|||||||
And the object "IfcWall/Cube" is selected
|
And the object "IfcWall/Cube" is selected
|
||||||
When I press "bim.edit_object_placement"
|
When I press "bim.edit_object_placement"
|
||||||
Then nothing happens
|
Then nothing happens
|
||||||
|
|
||||||
|
Scenario: Copy representation
|
||||||
|
Given an empty IFC project
|
||||||
|
And I add a cube
|
||||||
|
And the object "Cube" is selected
|
||||||
|
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
|
||||||
|
And I press "bim.assign_class"
|
||||||
|
And I add a cube
|
||||||
|
And the object "Cube" is selected
|
||||||
|
And I press "bim.assign_class"
|
||||||
|
And the object "IfcWall/Cube" is selected
|
||||||
|
And additionally the object "IfcWall/Cube.001" is selected
|
||||||
|
When I press "bim.copy_representation"
|
||||||
|
Then nothing happens
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ def the_object_name_is_selected(name):
|
|||||||
additionally_the_object_name_is_selected(name)
|
additionally_the_object_name_is_selected(name)
|
||||||
|
|
||||||
|
|
||||||
|
@given(parsers.parse('additionally the object "{name}" is selected'))
|
||||||
@when(parsers.parse('additionally the object "{name}" is selected'))
|
@when(parsers.parse('additionally the object "{name}" is selected'))
|
||||||
def additionally_the_object_name_is_selected(name):
|
def additionally_the_object_name_is_selected(name):
|
||||||
obj = bpy.context.scene.objects.get(name)
|
obj = bpy.context.scene.objects.get(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user