Exemple #1
0
 def _execute(self, context):
     if not context.active_object:
         return
     bm = bmesh.new()
     bm.from_mesh(context.active_object.data)
     geometric_context = tool.Root.get_representation_context(
         tool.Root.get_object_representation(context.active_object)
     )
     for obj in context.selected_objects:
         if obj == context.active_object:
             continue
         if obj.data:
             element = tool.Ifc.get_entity(obj)
             if not element:
                 continue
             bm.to_mesh(obj.data)
             old_rep = self.get_representation_by_context(element, geometric_context)
             if old_rep:
                 ifcopenshell.api.run(
                     "geometry.unassign_representation", tool.Ifc.get(), product=element, representation=old_rep
                 )
                 ifcopenshell.api.run("geometry.remove_representation", tool.Ifc.get(), representation=old_rep)
             core.add_representation(
                 tool.Ifc,
                 tool.Geometry,
                 tool.Style,
                 tool.Surveyor,
                 obj=obj,
                 context=geometric_context,
                 ifc_representation_class=None,
                 profile_set_usage=None,
             )
Exemple #2
0
 def _execute(self, context):
     ifc_context = self.context_id
     if not ifc_context and get_contexts(self, context):
         ifc_context = int(context.scene.BIMRootProperties.contexts or "0") or None
     if ifc_context:
         ifc_context = tool.Ifc.get().by_id(ifc_context)
     obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
     core.add_representation(
         tool.Ifc,
         tool.Geometry,
         tool.Style,
         tool.Surveyor,
         obj=obj,
         context=ifc_context,
         ifc_representation_class=self.ifc_representation_class,
         profile_set_usage=tool.Ifc.get().by_id(self.profile_set_usage) if self.profile_set_usage else None,
     )
Exemple #3
0
 def test_doing_nothing_if_not_an_ifc_element(self, ifc, geometry, style, surveyor):
     ifc.get_entity("obj").should_be_called().will_return(None)
     assert (
         subject.add_representation(
             ifc,
             geometry,
             style,
             surveyor,
             obj="obj",
             context="context",
             ifc_representation_class="ifc_representation_class",
             profile_set_usage="profile_set_usage",
         )
         is None
     )
Exemple #4
0
    def test_not_handling_styles_if_representation_has_no_faces(self, ifc, geometry, style, surveyor):
        TestEditObjectPlacement.predict(self, ifc, geometry, surveyor)

        # Add representation
        geometry.get_object_data("obj").should_be_called().will_return("data")
        geometry.get_cartesian_point_coordinate_offset("obj").should_be_called().will_return("coordinate_offset")
        geometry.get_total_representation_items("obj").should_be_called().will_return(1)
        geometry.should_force_faceted_brep().should_be_called().will_return(False)
        geometry.should_force_triangulation().should_be_called().will_return(True)
        ifc.run(
            "geometry.add_representation",
            context="context",
            blender_object="obj",
            geometry="data",
            coordinate_offset="coordinate_offset",
            total_items=1,
            should_force_faceted_brep=False,
            should_force_triangulation=True,
            ifc_representation_class="ifc_representation_class",
            profile_set_usage="profile_set_usage",
        ).should_be_called().will_return("representation")

        # Styles are relevant for meshes with faces only
        geometry.does_object_have_mesh_with_faces("obj").should_be_called().will_return(False)

        # Assign representation to product
        ifc.run("geometry.assign_representation", product="element", representation="representation").should_be_called()

        # Update mesh
        geometry.duplicate_object_data("obj").should_be_called().will_return("data")
        geometry.change_object_data("obj", "data", is_global=True).should_be_called()
        geometry.get_representation_name("representation").should_be_called().will_return("name")
        geometry.rename_object("data", "name").should_be_called()
        geometry.link("representation", "data").should_be_called()

        assert (
            subject.add_representation(
                ifc,
                geometry,
                style,
                surveyor,
                obj="obj",
                context="context",
                ifc_representation_class="ifc_representation_class",
                profile_set_usage="profile_set_usage",
            )
            == "representation"
        )
Exemple #5
0
    def test_only_updating_the_placement_if_there_is_no_object_data(self, ifc, geometry, style, surveyor):
        TestEditObjectPlacement.predict(self, ifc, geometry, surveyor)

        # Add representation
        geometry.get_object_data("obj").should_be_called().will_return(None)
        assert (
            subject.add_representation(
                ifc,
                geometry,
                style,
                surveyor,
                obj="obj",
                context="context",
                ifc_representation_class="ifc_representation_class",
                profile_set_usage="profile_set_usage",
            )
            is None
        )