Hi,

Always on my interactor pythonpart, I'm now regarding the modification mode.

I can put an object (cuboid in my example) with a starting palette, load another palette when modifying (for generate cylinder).

The preview works great but :

1) when I click, the pythonpart doesn't apply the new geometry (with clearing model_ele_list)
2) I'd like to close the script when the new object is placed.

Best

class MyInteractor():
    """
    Definition of class MyInteractor
    """

    def __init__(self,
                 coord_input              : Input.CoordinateInput,
                 pyp_path                 : str,
                 global_str_table_service : StringTableService,
                 build_ele_list           : List[BuildingElement],
                 build_ele_composite      : BuildingElementComposite,
                 control_props_list       : List[ControlProperties],
                 modify_uuid_list         : List[str]):

        """
        Initialization of class MyInteractor

        Args:
            coord_input              : coordinate input
            pyp_path                 : path of the pyp file
            global_str_table_service : global string table service
            build_ele_list           : building element list
            build_ele_composite      : building element composite
            control_props_list       : control properties list
            modify_uuid_list         : UUIDs of the existing elements in the modification mode
        """

        self.coord_input         = coord_input
        self.pyp_path            = pyp_path
        self.str_table_service   = global_str_table_service
        self.build_ele_list      = build_ele_list
        self.build_ele_composite = build_ele_composite
        self.control_props_list  = control_props_list
        self.modify_uuid_list    = modify_uuid_list
        self.build_ele_service   = BuildingElementService()
        self.modification_mode   = modify_uuid_list != [] and modify_uuid_list[0] != "00000000-0000-0000-0000-000000000000--0"

        self.build_ele      = self.build_ele_list[0]
        self.model_ele_list = []
        self.selected_pnts  = []
        self.placement_mat  = Geometry.Matrix3D() if not self.modification_mode else self.build_ele_list[0].get_insert_matrix()
        self.axis           = Geometry.AxisPlacement3D(Geometry.Point3D(),
                                                       Geometry.Vector3D(1, 0, 0),
                                                       Geometry.Vector3D(0, 0, 1)
                                                       )

        self.palette_service : BuildingElementPaletteService = Any

        self.geo      = None
        self.com_prop = BaseElements.CommonProperties()
        self.com_prop.GetGlobalProperties()

        if self.modification_mode:
            self.is_showing_palette = self.show_palette("ModifyTestInteractor.pal")
        else:
            self.is_showing_palette = self.show_palette("TestInteractor.pyp")

        if not self.is_showing_palette :
            return

        self.reset_pnts()

    def reset_pnts(self):
        """
        Reset the input points
        """

        self.selected_pnts.clear()
        self.coord_input.InitFirstElementInput(Input.InputStringConvert("Indiquez le point d'insertion"))


    def show_palette(self, palette_name):
        """
        Show the palette

        Args:
            page  : the page of the palette

        Returns:
            True/False for success.
        """

        result, self.build_ele_script, self.build_ele_list, self.control_props_list,    \
            self.build_ele_composite, part_name, self.file_name = \
            self.build_ele_service.read_data_from_pyp(f"{self.pyp_path}\\{palette_name}",
                                                      self.str_table_service.str_table,
                                                      False,
                                                      self.str_table_service.material_str_table
                                                      )

        if not result:
            return False

        self.palette_service = BuildingElementPaletteService(self.build_ele_list,
                                                             self.build_ele_composite,
                                                             self.build_ele_script,
                                                             self.control_props_list,
                                                             self.file_name
                                                             )

        self.palette_service.show_palette(part_name)

        return True


    def modify_element_property(self, page, name, value):
        """
        Modify property of element

        Args:
            page  : the page of the property
            name  : the name of the property
            value : new value for property.
        """

        pass


    def on_cancel_by_menu_function(self):
        """
        Check for input function cancel in case of a started menu function
        """
        if self.modification_mode:
            self.create_pythonpart()

        if self.is_showing_palette :
            self.palette_service.close_palette()


    def on_cancel_function(self):
        """
        Check for input function cancel in case of ESC

        Returns:
            True/False for success.
        """
        if self.modification_mode:
            self.create_pythonpart()

        if self.is_showing_palette :
            self.palette_service.close_palette()

        return True


    def on_control_event(self, event_id: int):
        """
        Handles on control event

        Args:
            event_id : event id of control.
        """

        pass


    def on_mouse_leave(self):
        """
        Handles the mouse leave event
        """

        if self.modification_mode:
            self.modify_geometry(True)
        else:
            self.create_geometry(True)


    def on_preview_draw(self):
        """
        Handles the preview draw event
        """

        self.create_geometry(True)


    def on_value_input_control_enter(self):
        """
        Handles the enter inside the value input control event

        Returns:
            True/False for success.
        """

        pass


    def process_mouse_msg(self, mouse_msg, pnt, msg_info):
        """
        Process the mouse message event

        Args:
            mouse_msg : the mouse message
            pnt       : the input point in view coordinates
            msg_info  : additional message info.

        Returns:
            True/False for success.
        """

        input_pnt = self.coord_input.GetInputPoint(mouse_msg, pnt, msg_info).GetPoint()
        self.placement_mat.SetTranslation(Geometry.Vector3D(input_pnt))
        if self.modification_mode:
            self.modify_geometry(True)
        else:
            self.create_geometry(True)

        if self.coord_input.IsMouseMove(mouse_msg):
            return True

        self.selected_pnts.append(input_pnt)

        if len(self.selected_pnts) == 1:
            if self.modification_mode:
                self.modify_geometry(False)
            else:
                self.create_geometry(False)
            self.reset_pnts()

        return True


    def create_geometry(self, is_preview):
        """
        Create the geometry

        Args:
            is_preview : True/False.
        """

        self.geo = Geometry.BRep3D.CreateCuboid(self.axis, 1000, 1000, 1000)
        self.model_ele_list.append(BasisElements.ModelElement3D(self.com_prop, self.geo))

        if is_preview:
            self.draw_element_preview()
        else:
            self.create_pythonpart()


    def modify_geometry(self, is_preview):
        """
        Modify the geometry

        Args:
            is_preview : True/False.
        """

        self.model_ele_list.clear()
        self.geo = Geometry.BRep3D.CreateCylinder(self.axis, 500, 1000, True, True)
        self.model_ele_list.append(BasisElements.ModelElement3D(self.com_prop, self.geo))

        if is_preview:
            self.draw_element_preview()
        else:
            self.create_pythonpart()


    def create_pythonpart(self):
        """
        Create the PythonPart
        """

        pyp_util = PythonPartUtil()
        pyp_util.add_pythonpart_view_2d3d(self.model_ele_list)
        pyp_transaction = PythonPartTransaction(self.coord_input.GetInputViewDocument())
        pyp_transaction.execute(self.placement_mat,
                                self.coord_input.GetViewWorldProjection(),
                                pyp_util.create_pythonpart(self.build_ele),
                                self.modify_uuid_list
                                )


    def draw_element_preview(self):
        """
        Draw the preview
        """

        BaseElements.DrawElementPreview(self.coord_input.GetInputViewDocument(),
                                        self.placement_mat,
                                        self.model_ele_list,
                                        True,
                                        None
                                        )

Anhänge (3)

Typ: image/jpeg
20-mal heruntergeladen
Größe: 115,47 KiB
Typ: image/jpeg
24-mal heruntergeladen
Größe: 145,42 KiB
Typ: image/jpeg
18-mal heruntergeladen
Größe: 21,11 KiB