Пример #1
0
    def calculateNewVector(self):
        try:
            self.faceDir = faced.getDirectionAxis()  # face direction
            faces = faced.findFaceSHavingTheSameEdge()
            # TODO: SHOULD WE DO ANY CALCULATION TO FIND BETTER FACE?
            if type(faces) == list:
                face = faces[0]
            elif faces is not None:
                face = faces
            else:
                raise ValueError("Face returned was none")

            yL = face.CenterOfMass
            uv = face.Surface.parameter(yL)
            nv = face.normalAt(uv[0], uv[1])
            self.normalVector = nv
            # Setup calculation.
            if (face.Surface.Rotation is None):
                plr = plDirection = App.Placement()

                # section direction. When the face doesn't have a Rotation
                yL = face.CenterOfMass
                uv = face.Surface.parameter(yL)
                nv = face.normalAt(uv[0], uv[1])
                direction = yL.sub(nv + yL)
                r = App.Rotation(App.Vector(0, 0, 1), direction)
                plDirection.Base = yL
                plDirection.Rotation.Q = r.Q
                plr = plDirection
                rotation = (plr.Rotation.Axis.x, plr.Rotation.Axis.y,
                            plr.Rotation.Axis.z,
                            math.degrees(plr.Rotation.Angle))
            else:
                ang = face.Surface.Axis.getAngle(App.Vector(0, 0, 1))
                rotation = [0, 0, 1, ang]

            d = self.tweakLength

            self.FirstLocation = yL + d * nv  # the 3 arrows-disc

            if self.oldFaceVertexes[
                    0].Point.z > self.selectedObj.Shape.BoundBox.ZMin:
                self.FirstLocation.z = self.selectedObj.Shape.BoundBox.ZMax
            else:
                self.FirstLocation.z = self.selectedObj.Shape.BoundBox.ZMin

            return rotation

        except Exception as err:

            App.Console.PrintError("'Calculate new Vector. "
                                   "{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)
Пример #2
0
    def calculateNewVector(self):
        try:
            self.faceDir = faced.getDirectionAxis()  # face direction
            faces = faced.findFaceSHavingTheSameEdge()
            # TODO: SHOULD WE DO ANY CALCULATION TO FIND BETTER FACE?
            if type(faces) == list:
                face = faces[0]
            elif faces is not None:
                face = faces
            else:
                raise ValueError("Face returned was none")

            yL = face.CenterOfMass
            uv = face.Surface.parameter(yL)
            nv = face.normalAt(uv[0], uv[1])
            self.normalVector = nv
            # Setup calculation.
            if (face.Surface.Rotation is None):
                calAn = math.degrees(nv.getAngle(App.Vector(1, 1, 0)))
                rotation = [0, 1, 0, calAn]
            else:
                rotation = [
                    face.Surface.Rotation.Axis.x, face.Surface.Rotation.Axis.y,
                    face.Surface.Rotation.Axis.z,
                    math.degrees(face.Surface.Rotation.Angle)
                ]

            d = self.tweakLength

            self.FirstLocation = yL + d * nv  # the 3 arrows-discs
            if self.oldEdgeVertexes[
                    0].Point.z > self.selectedObj.Shape.BoundBox.ZMin:
                self.FirstLocation.z = self.selectedObj.Shape.BoundBox.ZMax + self.awayFromObj
            else:
                self.FirstLocation.z = self.selectedObj.Shape.BoundBox.ZMin - self.awayFromObj

            return rotation

        except Exception as err:
            App.Console.PrintError("'Calculate new Vector. "
                                   "{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)
Пример #3
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)
Пример #4
0
    def calculateRotatedNormal(self, Wheelaxis):
        """[calculate placement, angle of rotation, axis of rotation based on the]

        Args:
            Wheelaxis ([str]): [Direction of the wheel coin widget - Axis type ]

        Returns:
            [Base.placement]: [Placement, rotation angle and axis of rotation for face2]
        """
        if self.isItRotation is True:
            return  # We shouldn't be here.

        faceRotation = 0
        # TODO: Lets take only X axis first , then Y ..etc and so on.
        face1Obj = self.ExtractedFaces[0]
        pl = self.ExtractedFaces[0].Placement
        self.faceDir = faced.getDirectionAxis(self.selected)  # face direction

        # THIS PART WILL BE COMPLICATED AND MUST BE WELL WRITTEN.

        # Wheelaxis color: RED is X , GREEN is Y,  FR_BLUEVIOLET is 45 and ORANGE is 135
        s = self.ExtractedFaces[1]
        # Reset the placement of the object if was not correct
        s.Placement = self.ExtractedFaces[0].Placement
        ax = self.selectedObj.Object.Shape.CenterOfMass
        if self.faceDir == "+x" and Wheelaxis == "X":
            faced.RealRotateObjectToAnAxis(s, ax, 0, 90, 0)
            self.ExtractedFaces[1].Placement.Base.x = self.ExtractedFaces[1].Placement.Base.x + \
                self.ExtractedFaces[1].Shape.BoundBox.XLength
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-x" and Wheelaxis == "X":
            faced.RealRotateObjectToAnAxis(s, ax, 0, 90, 0)
            self.ExtractedFaces[1].Placement.Base.x = self.ExtractedFaces[1].Placement.Base.x - \
                self.ExtractedFaces[1].Shape.BoundBox.XLength
            pl = self.ExtractedFaces[1].Placement

        elif (self.faceDir == "+x"
              and Wheelaxis == "Y") or (self.faceDir == "-x"
                                        and Wheelaxis == "Y"):
            # We do nothing .. it is ok to not change
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "+y" and Wheelaxis == "X":
            faced.RealRotateObjectToAnAxis(s, ax, 0, 0, -90)
            self.ExtractedFaces[1].Placement.Base.y = self.ExtractedFaces[1].Placement.Base.y + \
                self.ExtractedFaces[1].Shape.BoundBox.YLength
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-y" and Wheelaxis == "X":
            faced.RealRotateObjectToAnAxis(s, ax, 0, 0, 90)
            self.ExtractedFaces[1].Placement.Base.y = self.ExtractedFaces[1].Placement.Base.y - \
                self.ExtractedFaces[1].Shape.BoundBox.YLength
            pl = self.ExtractedFaces[1].Placement

        elif (self.faceDir == "+y"
              and Wheelaxis == "Y") or (self.faceDir == "-y"
                                        and Wheelaxis == "Y"):
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-z" and Wheelaxis == "X" or (
                self.faceDir == "+z" and Wheelaxis == "X"):
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "+z" and Wheelaxis == "Y":
            faced.RealRotateObjectToAnAxis(s, ax, 0, 0, -90)
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-z" and Wheelaxis == "Y":
            faced.RealRotateObjectToAnAxis(s, ax, 0, 0, 90)
            pl = self.ExtractedFaces[1].Placement

        # Now we have 45Degrees :
        if self.faceDir == "+x" and Wheelaxis == "45":
            faced.RotateObjectToCenterPoint(s, 0, 45, 0)
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-x" and Wheelaxis == "45":
            faced.RotateObjectToCenterPoint(s, 0, 45, 0)
            pl = self.ExtractedFaces[1].Placement

        # Now we have 45 Degrees :
        if self.faceDir == "+y" and Wheelaxis == "45":
            faced.RotateObjectToCenterPoint(s, 0, 0, -45)
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-y" and Wheelaxis == "45":
            faced.RotateObjectToCenterPoint(s, 0, 0, -45)
            pl = self.ExtractedFaces[1].Placement

            # Now we have 45 and 135 Degrees :
        if self.faceDir == "+z" and Wheelaxis == "45":
            faced.RotateObjectToCenterPoint(s, 0, 0, 45)
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-z" and Wheelaxis == "45":
            faced.RotateObjectToCenterPoint(s, 0, 0, 45)
            pl = self.ExtractedFaces[1].Placement

        # Now we have 135 Degrees :
        if self.faceDir == "+x" and Wheelaxis == "135":
            faced.RotateObjectToCenterPoint(s, 0, 135, 0)
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-x" and Wheelaxis == "135":
            faced.RotateObjectToCenterPoint(s, 0, 135, 0)
            pl = self.ExtractedFaces[1].Placement

        if self.faceDir == "+y" and Wheelaxis == "135":
            faced.RotateObjectToCenterPoint(s, 0, 0, -135)
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-y" and Wheelaxis == "135":
            faced.RotateObjectToCenterPoint(s, 0, 0, -135)
            pl = self.ExtractedFaces[1].Placement

        if self.faceDir == "+z" and Wheelaxis == "135":
            faced.RotateObjectToCenterPoint(s, 0, 0, 135)
            pl = self.ExtractedFaces[1].Placement

        elif self.faceDir == "-z" and Wheelaxis == "135":
            faced.RotateObjectToCenterPoint(s, 0, 0, 135)
            pl = self.ExtractedFaces[1].Object.Placement

        return pl
Пример #5
0
    def getArrowPosition(self):
        """"
         Find out the vector and rotation of the arrow to be drawn.
        """
        #      For now the arrow will be at the top
        rotation = [0.0, 0.0, 0.0, 0.0]
        self.direction = faced.getDirectionAxis()  # Must be getSelectionEx

        if (self.direction == "+x"):
            rotation = [0.0, -1.0, 0.0, 90.0]
        elif (self.direction == "-x"):
            rotation = [0.0, 1.0, 0.0, 90.0]
        elif (self.direction == "+y"):
            rotation = [1.0, 0.0, 0.0, 90.0]
        elif (self.direction == "-y"):
            rotation = [-1.0, 0.0, 0.0, 90.0]
        elif (self.direction == "+z"):
            rotation = [1.0, 0.0, 0.0, 180.0]
        elif (self.direction == "-z"):
            rotation = [1.0, 0.0, 0.0, 0.0]

        if self.objectType == 'Shape':
            # 'Shape'
            # The whole object is selected
            if (self.direction == "+x" or self.direction == "-x"):
                if (self.direction == "+x"):
                    self._vector.x = self.selectedObj[0].Object.Shape.BoundBox.XMax + \
                        self.AwayFrom3DObject
                else:  # (direction=="-x"):
                    self._vector.x = self.selectedObj[0].Object.Shape.BoundBox.XMax - \
                        self.AwayFrom3DObject

                self._vector.y = self.selectedObj[
                    0].Object.Shape.BoundBox.YMax / 2
                self._vector.z = self.selectedObj[
                    0].Object.Shape.BoundBox.ZMax / 2

            elif (self.direction == "+y" or self.direction == "-y"):
                if (self.direction == "+y"):
                    self._vector.y = self.selectedObj[0].Object.Shape.BoundBox.YMax + \
                        self.AwayFrom3DObject
                else:  # (direction=="-y"):
                    self._vector.y = self.selectedObj[0].Object.Shape.BoundBox.YMax - \
                        self.AwayFrom3DObject
                self._vector.x = self.selectedObj[
                    0].Object.Shape.BoundBox.XMax / 2
                self._vector.z = self.selectedObj[
                    0].Object.Shape.BoundBox.ZMax / 2

            elif (self.direction == "+z" or self.direction == "-z"):
                if (self.direction == "+z"):
                    self._vector.z = self.selectedObj[0].Object.Shape.BoundBox.ZMax + \
                        self.AwayFrom3DObject
                else:  # (direction=="-z"):
                    self._vector.z = self.selectedObj[0].Object.Shape.BoundBox.ZMax - \
                        self.AwayFrom3DObject
                    self._vector.x = self.selectedObj[
                        0].Object.Shape.BoundBox.XMax / 2
                    self._vector.y = self.selectedObj[
                        0].Object.Shape.BoundBox.YMax / 2
            return rotation

        vectors = self.selectedObj[0].SubObjects[0].Vertexes
        if self.objectType == 'Face':
            self._vector.z = vectors[0].Z
            for i in vectors:
                self._vector.x += i.X
                self._vector.y += i.Y
                self._vector.z += i.Z
            self._vector.x = self._vector.x / 4
            self._vector.y = self._vector.y / 4
            self._vector.z = self._vector.z / 4

        elif self.objectType == 'Edge':
            # One edge is selected
            self._vector.z = vectors[0].Z
            for i in vectors:
                self._vector.x += i.X
                self._vector.y += i.Y
                self._vector.z += i.Z
            self._vector.x = self._vector.x / 2
            self._vector.y = self._vector.y / 2
            self._vector.z = self._vector.z / 2

        if self.direction == "+x":
            self._vector.x = self._vector.x + self.AwayFrom3DObject
        elif self.direction == "-x":
            self._vector.x = self._vector.x - self.AwayFrom3DObject
        elif self.direction == "+y":
            self._vector.y = self._vector.y + self.AwayFrom3DObject
        elif self.direction == "-y":
            self._vector.y = self._vector.y - self.AwayFrom3DObject
        elif self.direction == "+z":
            self._vector.z = self._vector.z + self.AwayFrom3DObject
        elif self.direction == "-z":
            self._vector.z = self._vector.z - self.AwayFrom3DObject

        return rotation
Пример #6
0
    def makeIt(self, commandType):
        try:
            nObjects = []
            newShape = None
            simpl_cpy = None
            self.commandType = commandType
            selection = Gui.Selection.getSelectionEx()
            # Two object must be selected
            if (len(selection) < 2 or len(selection) > 2):
                errMessage = "Select two objects to use Common 2D Tool"
                faced.getInfo(selection).errorDialog(errMessage)
                return None
            else:
                nObjects.clear()
                GlobalPlacement = App.ActiveDocument.getObject(
                    selection[0].Object.Name).Placement
                for a2dobj in selection:
                    m = App.ActiveDocument.getObject(a2dobj.Object.Name)
                    f = App.ActiveDocument.addObject('Part::Extrusion',
                                                     'ExtrudeOriginal')
                    f.Base = App.ActiveDocument.getObject(m.Name)
                    f.DirMode = "Normal"
                    f.DirLink = a2dobj.Object
                    if faced.getDirectionAxis() == "x":
                        f.Dir = (1, 0, 0)
                    elif faced.getDirectionAxis() == "y":
                        f.Dir = (0, 1, 0)
                    else:
                        f.Dir = (0, 0, 1)

                    f.LengthFwd = 1.00
                    f.LengthRev = 0.0
                    f.Solid = True
                    f.Reversed = False
                    f.Symmetric = False
                    f.TaperAngle = 0.0
                    f.TaperAngleRev = 0.0
                    App.ActiveDocument.recompute()

                    # Make a simple copy of the object
                    newShape = _part.getShape(f,
                                              '',
                                              needSubElement=False,
                                              refine=True)
                    newObj = App.ActiveDocument.addObject(
                        'Part::Feature', 'Extrude')
                    newObj.Shape = newShape
                    App.ActiveDocument.recompute()
                    App.ActiveDocument.ActiveObject.Label = f.Label
                    App.ActiveDocument.recompute()
                    App.ActiveDocument.removeObject(f.Name)
                    App.ActiveDocument.removeObject(m.Name)
                    App.ActiveDocument.recompute()
                    nObjects.append(newObj)

                tempResult = self.DoCommand(
                    self.commandType)  #Create the common 3D shape
                if (self.commandType == 1 or self.commandType == 3):
                    tempResult.Shapes = nObjects
                    tempResult.Refine = True
                elif (self.commandType == 2):
                    tempResult.Tool = nObjects[1]
                    tempResult.Base = nObjects[0]
                App.ActiveDocument.recompute()
                #Make a simple version
                newShape = _part.getShape(tempResult,
                                          '',
                                          needSubElement=False,
                                          refine=False)
                simpl_cpy = App.ActiveDocument.addObject(
                    'Part::Feature', 'Shape')
                simpl_cpy.Shape = newShape  #simple version of the 3D common
                App.ActiveDocument.recompute()
                for name in nObjects:
                    App.ActiveDocument.removeObject(name.Name)
                App.ActiveDocument.removeObject(tempResult.Name)
                App.ActiveDocument.recompute()
            # Extract the face
            sh = simpl_cpy.Shape.copy()
            #sh.Placement = GlobalPlacement  # Result.Placement
            sh.Placement.Base.z = -1

            Gui.Selection.clearSelection()
            App.ActiveDocument.recompute()
            Gui.Selection.addSelection(App.ActiveDocument.Name, simpl_cpy.Name)
            s = Gui.Selection.getSelectionEx()[0]
            faceName = faced.SelectTopFace(simpl_cpy).Activated()

            newobj = App.ActiveDocument.addObject("Part::Feature",
                                                  self.localShapeName)
            print(faceName)
            newobj.Shape = sh.getElement(faceName)
            App.ActiveDocument.removeObject(simpl_cpy.Name)
            del nObjects[:]
        except Exception as err:
            App.Console.PrintError("'makeIt' 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)