def getXYZdimOfSelectedObject(self, selected):
        import ThreeDWidgets.fr_coinwindow as win
        try:
            (vectors, lengths) = self.returnVectorsFromBoundaryBox(selected)
            # Create the lines
            self.smartInd.clear()
            self.smartInd.append(
                smartLines(vectors[0], [
                    "{0:.2f}".format(lengths[0]),
                ], 5, self))
            self.smartInd.append(
                smartLines(vectors[1], [
                    "{0:.2f}".format(lengths[1]),
                ], 5, self))
            self.smartInd.append(
                smartLines(vectors[2], [
                    "{0:.2f}".format(lengths[2]),
                ], 5, self))
            for i in self.smartInd:
                i.set_target(selected)
                i.FontSize(4)
            # set selected object to each smartline
            if self._mywin is None:
                self._mywin = win.Fr_CoinWindow()
            self._mywin.addWidget(self.smartInd)
            self._mywin.show()

        except Exception as err:
            App.Console.PrintError("'Design456_SmartScale' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Esempio n. 2
0
    def Activated(self):
        import ThreeDWidgets.fr_coinwindow as win
        self.selectedObj.clear()
        sel = Gui.Selection.getSelectionEx()
        if len(sel) < 2:
            # An object must be selected
            errMessage = "Select at least two objects to Align them"
            faced.errorDialog(errMessage)
            return

        self.selectedObj = sel
        self.recreateAll()
        self.smartInd = Fr_Align_Widget(self.NewBoundary, ["Align Tool", ])

        self.smartInd.w_callback_ = callback_release
        self.smartInd.w_btnCallbacks_ = [callback_btn0,
                                callback_btn1,
                                callback_btn2,
                                callback_btn3,
                                callback_btn4,
                                callback_btn5,
                                callback_btn6,
                                callback_btn7,
                                callback_btn8]

        self.smartInd.w_userData.callerObject = self

        if self._mywin is None:
            self._mywin = win.Fr_CoinWindow()
        self._mywin.addWidget(self.smartInd)
        mw = self.getMainWindow()
        self._mywin.show()
Esempio n. 3
0
    def Activated(self):
        import ThreeDWidgets.fr_coinwindow as win
        self.selectedObj.clear()
        sel = Gui.Selection.getSelectionEx()
        if len(sel) == 0:
            # An object must be selected
            errMessage = "Select an object, one face or one edge to chamfer"
            faced.errorDialog(errMessage)
            return

        self.selectedObj.append(sel[0])
        self.Originalname = self.selectedObj[0].Object.Name

        # Find Out shapes type.
        self.registerShapeType()
        o = Gui.ActiveDocument.getObject(self.selectedObj[0].Object.Name)

        # Undo
        App.ActiveDocument.openTransaction(
            translate("Design456", "SmartFillet"))
        o.Transparency = 80
        self.reCreatechamferObject()

        # get rotation
        rotation = self.getArrowPosition()

        self.smartInd = Fr_Arrow_Widget(
            [self._vector, App.Vector(0.0, 0.0, 0.0)],  # w_vector
            [
                "Radius: 0.0",
            ],
            1,  # Label, linewidth
            FR_COLOR.FR_RED,
            FR_COLOR.FR_WHITE,  # color, lblcolor
            rotation,  # rotation
            [1.0, 1.0, 1.0],  # scale 
            0,  # type
            0.0)  # opacity
        self.smartInd.w_callback_ = callback_release
        self.smartInd.w_move_callback_ = callback_move
        self.smartInd.w_userData.callerObject = self
        self.saveFirstPostion = self._vector
        if self._mywin is None:
            self._mywin = win.Fr_CoinWindow()
        self._mywin.addWidget(self.smartInd)
        mw = self.getMainWindow()
        self._mywin.show()
Esempio n. 4
0
    def Activated(self):
        """[ Executes when the tool is used   ]
        """
        import ThreeDWidgets.fr_coinwindow as win
        try:

            print("Smart ExtrudeRotate")
            self.selected = Gui.Selection.getSelectionEx()
            if len(self.selected) == 0:
                # An object must be selected
                errMessage = "Select an object, one face to Extrude"
                faced.errorDialog(errMessage)
                return
            self.selectedObj = self.selected[0]
            faced.EnableAllToolbar(False)
            self.faceDir = faced.getDirectionAxis(
                self.selected)  # face direction

            # Undo
            App.ActiveDocument.openTransaction(
                translate("Design456", "SmartExtrudeRotate"))
            self.ExtractedFaces.clear()
            if self.isFaceOf3DObj(
            ):  # We must know if the selection is a 2D face or a face from a 3D object
                # We have a 3D Object. Extract a face and start to Extrude
                self.extractFaces()
            else:
                # We have a 2D Face - Extract it directly
                sh = self.selectedObj.Object.Shape.copy()
                o = App.ActiveDocument.addObject("Part::Feature",
                                                 "MovableFace")
                o.Shape = sh
                self.ExtractedFaces.append(self.selectedObj.Object)
                self.ExtractedFaces.append(App.ActiveDocument.getObject(
                    o.Name))
            facingdir = self.faceDir.upper()
            facingdir = facingdir[1:]
            print(facingdir, "facingdir")
            # Decide how the Degree Wheel be drawn
            self.setupRotation = self.calculateNewVector()
            if self.faceDir == "+z" or self.faceDir == "-z":
                self.wheelObj = Fr_DegreeWheel_Widget(
                    [self.FirstLocation,
                     App.Vector(0, 0, 0)],
                    str(round(self.w_rotation[3], 2)) + "°", 1,
                    FR_COLOR.FR_RED, [0, 0, 0, 0], self.setupRotation,
                    [2.0, 2.0, 2.0], 2, facingdir)
            else:
                self.wheelObj = Fr_DegreeWheel_Widget(
                    [self.FirstLocation,
                     App.Vector(0, 0, 0)],
                    str(round(self.w_rotation[3], 2)) + "°", 1,
                    FR_COLOR.FR_RED, [0, 0, 0, 0], self.setupRotation,
                    [2.0, 2.0, 2.0], 1, facingdir)

            # Define the callbacks. We have many callbacks here.
            # TODO: FIXME:

            # Different callbacks for each action.
            self.wheelObj.w_wheel_cb_ = callback_Rotate
            self.wheelObj.w_xAxis_cb_ = callback_moveX
            self.wheelObj.w_yAxis_cb_ = callback_moveY
            self.wheelObj.w_45Axis_cb_ = callback_move45
            self.wheelObj.w_135Axis_cb_ = callback_move135

            self.wheelObj.w_callback_ = callback_release
            self.wheelObj.w_userData.callerObject = self
            self.newObject = App.ActiveDocument.addObject(
                'Part::Loft', 'ExtendFace')
            self.newObject.Sections = self.ExtractedFaces
            self.newObject.Solid = True
            self.newObject.Ruled = False  # TODO: SHOULD THIS BE RULED?
            self.newObject.Closed = False  # TODO: SHOULD THIS BE CLOSED?
            self.ExtractedFaces[0].Visibility = False
            self.ExtractedFaces[1].Visibility = False
            if self._mywin is None:
                self._mywin = win.Fr_CoinWindow()

            self._mywin.addWidget(self.wheelObj)
            mw = self.getMainWindow()
            self._mywin.show()

            # TODO: FIXME:
            # loft will be used . make some experementations.
            # But when should we use sweep???? don't know now

            App.ActiveDocument.recompute()

        except Exception as err:
            faced.EnableAllToolbar(True)
            App.Console.PrintError(
                "'Design456_ExtrudeRotate' ExtractFace-Failed. "
                "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Esempio n. 5
0
    def Activated(self):
        """[Executes when the tool is used]
        """
        import ThreeDWidgets.fr_coinwindow as win
        try:
            print("Smart Extrusion")
            sel = Gui.Selection.getSelectionEx()
            if len(sel) == 0:
                # An object must be selected
                errMessage = "Select a face to Extrude"
                faced.errorDialog(errMessage)
                return
            self.selectedObj = sel[0]
            # Whole object is selected TODO: FIXME: Check if this works always.
            if len(self.selectedObj.SubObjects) == 0:
                errMessage = "Select a face to Extrude"
                faced.errorDialog(errMessage)
                return
            faced.EnableAllToolbar(False)
            # Undo
            App.ActiveDocument.openTransaction(
                translate("Design456", "SmartExtrude"))
            self.WasFaceFrom3DObject = self.isFaceOf3DObj()
            if self.WasFaceFrom3DObject is True:  # We must know if the selection is a 2D face or a face from a 3D object
                # We have a 3D Object. Extract a face and start to Extrude
                self.targetFace = self.extractFace()
            else:
                # We have a 2D Face - Extract it directly
                self.targetFace = self.selectedObj.Object

            rotation = self.getArrowPosition()
            self.smartInd = Fr_Arrow_Widget(self._vector, [
                "  Length 0.0",
            ], 1, FR_COLOR.FR_RED, FR_COLOR.FR_WHITE, rotation,
                                            [1.2, 1.2, 1.2], 3, 0.0)

            self.smartInd.w_callback_ = callback_release
            self.smartInd.w_move_callback_ = callback_move
            self.smartInd.w_userData.callerObject = self
            if self._mywin is None:
                self._mywin = win.Fr_CoinWindow()

            self._mywin.addWidget(self.smartInd)
            mw = self.getMainWindow()
            self._mywin.show()

            self.newObject = App.ActiveDocument.addObject(
                'Part::Extrusion', 'Extrude')
            self.newObject.Base = self.targetFace
            self.newObject.DirMode = "Normal"  # Don't use Custom as it causes a PROBLEM!
            # Above statement is not always correct. Some faces require 'custom'
            self.newObject.DirLink = None
            self.newObject.LengthFwd = self.extrudeLength  # Must be negative
            self.newObject.LengthRev = 0.0
            self.newObject.Solid = True
            self.newObject.Reversed = False
            self.newObject.Symmetric = False
            self.newObject.TaperAngle = 0.0
            self.newObject.TaperAngleRev = 0.0
            self.newObject.Dir = Gui.ActiveDocument.getObject(
                self.targetFace.Name).Object.Shape.Faces[0].normalAt(0, 0)
            if (self.newObject.Dir.x != 1 or self.newObject.Dir.y != 1
                    or self.newObject.Dir.z != 1):
                self.newObject.DirMode = "Custom"

            App.ActiveDocument.recompute()

        except Exception as err:
            faced.EnableAllToolbar(True)
            App.Console.PrintError("'Design456_Extrude' Activated-Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Esempio n. 6
0
    def Activated(self):
        """[ Executes when the tool is used   ]
        """
        import ThreeDWidgets.fr_coinwindow as win
        self.coinFaces = coin.SoSeparator()
        self.w_rotation = [0.0, 0.0, 0.0]  #
        self.setupRotation = [0, 0, 0, 0]
        self.counter = 0
        self.run_Once = False
        self.tweakLength = 0
        self.oldTweakLength = 0
        self.isItRotation = False
        self.newFaces = []
        self.savedVertices = [[]]
        self.tweakLength = 0
        self.oldTweakLength = 0

        try:
            self.view = Gui.ActiveDocument.ActiveView
            self.sg = self.view.getSceneGraph()
            sel = Gui.Selection.getSelectionEx()

            if len(sel) > 2:
                errMessage = "Please select only one edge and try again"
                faced.errorDialog(errMessage)

            App.ActiveDocument.openTransaction(
                translate("Design456", "ExtendEdge"))

            self.MoveMentDirection = 'A'

            self.selectedObj = sel[0].Object
            self.selectedObj.Visibility = False
            if (hasattr(sel[0], "SubObjects")):
                self.selectedEdge = sel[0].SubObjects[0]
            else:
                raise Exception("Not implemented")

            if (not hasattr(self.selectedEdge, "Curve")):
                errmsg = "Please select an edge "
                faced.errorDialog(errmsg)
                self.selectedObj.Visibility = True
                self.__del__()
                return

            # Register undo
            App.ActiveDocument.openTransaction(
                translate("Design456", "EdgeExtend"))

            # Recreate the object in separated shapes.
            self.saveVertices()

            if (hasattr(self.selectedEdge, "Vertexes")):
                self.oldEdgeVertexes = self.selectedEdge.Vertexes
            if not hasattr(self.selectedEdge, 'Edges'):
                raise Exception("Please select only one edge and try again")
            if not (type(self.selectedEdge.Curve) == _part.Line
                    or type(self.selectedEdge.Curve) == _part.BezierCurve):
                msg = "Curve edges are not supported yet"
                faced.errorDialog(msg)
                return

            self.setupRotation = self.calculateNewVector()

            self.ExtractTheEdge()
            self.newEdgeVertexes = self.newEdge.Shape.Vertexes
            App.ActiveDocument.removeObject(self.selectedObj.Name)

            # Undo
            App.ActiveDocument.openTransaction(
                translate("Design456", "ExtendEdge"))

            if self.oldEdgeVertexes[
                    0].Point.z < self.selectedObj.Shape.BoundBox.ZMin:
                self.FirstLocation.z = self.selectedObj.Shape.BoundBox.ZMin - self.awayFromObj

            # Decide how the Degree disc be drawn
            self.discObj = Fr_ThreeArrows_Widget(
                [self.FirstLocation, App.Vector(0, 0, 0)],  #
                # label
                (str(round(self.w_rotation[0], 2)) + "°" +
                 str(round(self.w_rotation[1], 2)) + "°" +
                 str(round(self.w_rotation[2], 2)) + "°"),
                FR_COLOR.FR_WHITE,  # lblcolor
                [FR_COLOR.FR_RED, FR_COLOR.FR_GREEN, FR_COLOR.FR_BLUE
                 ],  # arrows color
                # rotation
                [0.0, 0.0, 0.0, 0.0],
                self.setupRotation,  # setup rotation
                [15.0, 15.0, 15.0],  # scale
                0,  # type
                0,  # opacity
                10)  # distance between them

            # Different callbacks for each action.
            self.discObj.w_xAxis_cb_ = self.MouseMovement_cb
            self.discObj.w_yAxis_cb_ = self.MouseMovement_cb
            self.discObj.w_zAxis_cb_ = self.MouseMovement_cb

            self.discObj.w_discXAxis_cb_ = self.callback_Rotate
            self.discObj.w_discYAxis_cb_ = self.callback_Rotate
            self.discObj.w_discZAxis_cb_ = self.callback_Rotate

            self.discObj.w_callback_ = self.callback_release
            self.discObj.w_userData.callerObject = self

            self.COIN_recreateObject()

            if self._mywin is None:
                self._mywin = win.Fr_CoinWindow()

            self._mywin.addWidget(self.discObj)
            mw = self.getMainWindow()
            self._mywin.show()

            App.ActiveDocument.recompute()

        except Exception as err:

            App.Console.PrintError("'Activated' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)
Esempio n. 7
0
    def Activated(self):
        """[ Executes when the tool is used   ]
        """
        import ThreeDWidgets.fr_coinwindow as win
        self.coinFaces = coin.SoSeparator()
        self.w_rotation = [0.0, 0.0, 0.0]  # disc rotation
        self.setupRotation = [0, 0, 0, 0]  # Whole widget rotation
        self._Vector = App.Vector(0.0, 0.0, 0.0)  # disc POSITION
        self.counter = 0
        self.run_Once = False
        self.tweakLength = 0
        self.oldTweakLength = 0
        self.newFaces = []
        self.savedVertexes = [[]]
        self.tweakLength = 0

        try:
            self.view = Gui.ActiveDocument.ActiveView
            self.sg = self.view.getSceneGraph()
            sel = Gui.Selection.getSelectionEx()

            if len(sel) > 2:
                errMessage = "Please select only one face and try again"
                faced.errorDialog(errMessage)
                return
            # Register undo
            App.ActiveDocument.openTransaction(
                translate("Design456", "ExtendFace"))
            self.selectedObj = sel[0].Object
            self.selectedObj.Visibility = False
            if (hasattr(sel[0], "SubObjects")):
                self.selectedFace = sel[0].SubObjects[0]
            else:
                raise Exception("Not implemented")

            if self.selectedFace.ShapeType != 'Face':
                errMessage = "Please select only one face and try again, was: " + \
                    str(self.selectedFace.ShapeType)
                faced.errorDialog(errMessage)
                return

            # Recreate the object in separated shapes.
            self.saveVertexes()

            if (hasattr(self.selectedFace, "Vertexes")):
                #self.oldFaceVertexes = self.selectedFace.OuterWire.OrderedVertexes
                self.oldFaceVertexes = self.selectedFace.Vertexes
            if not hasattr(self.selectedFace, 'Faces'):
                raise Exception("Please select only one face and try again")
            # TODO: FIXME: WHAT SHOULD WE DO WHEN IT IS A CURVED FACE???
            # if not(type(self.selectedFace.Curve) == _part.Line or
            #       type(self.selectedFace.Curve) == _part.BezierCurve):
            #    msg = "Curve Faces are not supported yet"
            #    faced.errorDialog(msg)
            #    self.hide()

            self.setupRotation = self.calculateNewVector()

            self.ExtractFace()
            self.newFaceVertexes = self.newFace.Shape.Vertexes
            App.ActiveDocument.removeObject(self.selectedObj.Name)

            # Undo
            App.ActiveDocument.openTransaction(
                translate("Design456", "ExtendFace"))

            # Decide how the Degree pad be drawn
            self.discObj = Fr_ThreeArrows_Widget(
                [self.FirstLocation, App.Vector(0, 0, 0)],  #
                # label
                [
                    (str(round(self.w_rotation[0], 2)) + "°" +
                     str(round(self.w_rotation[1], 2)) + "°" +
                     str(round(self.w_rotation[2], 2)) + "°"),
                ],
                FR_COLOR.FR_WHITE,  # lblcolor
                [FR_COLOR.FR_RED, FR_COLOR.FR_GREEN, FR_COLOR.FR_BLUE
                 ],  # arrows color
                # rotation of the disc main
                [0, 0, 0, 0],
                self.setupRotation,  # setup rotation
                [30.0, 30.0, 30.0],  # scale
                1,  # type
                0,  # opacity
                10)  # distance between them
            self.discObj.enableDiscs()

            # Different callbacks for each action.
            self.discObj.w_xAxis_cb_ = self.MouseDragging_cb
            self.discObj.w_yAxis_cb_ = self.MouseDragging_cb
            self.discObj.w_zAxis_cb_ = self.MouseDragging_cb

            self.discObj.w_discXAxis_cb_ = self.RotatingFace_cb
            self.discObj.w_discYAxis_cb_ = self.RotatingFace_cb
            self.discObj.w_discZAxis_cb_ = self.RotatingFace_cb

            self.discObj.w_callback_ = self.callback_release
            self.discObj.w_userData.callerObject = self

            self.COIN_recreateObject()

            if self._mywin is None:
                self._mywin = win.Fr_CoinWindow()

            self._mywin.addWidget(self.discObj)
            mw = self.getMainWindow()
            self._mywin.show()

            App.ActiveDocument.recompute()

        except Exception as err:

            App.Console.PrintError("'Activated' Failed. "
                                   "{err}\n".format(err=str(err)))
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            print(exc_type, fname, exc_tb.tb_lineno)