示例#1
0
    def alignToFace(self, shape, offset=0):
        """Align the plane to a face.

        It uses the center of mass of the face as `position`,
        and its normal in the center of the face as `axis`,
        then calls `alignToPointAndAxis(position, axis, offset)`.

        If the face is a quadrilateral, then it adjusts the position
        of the plane according to its reported X direction and Y direction.

        Also set `weak` to `False`.

        Parameter
        --------
        shape : Part.Face
            A shape of type `'Face'`.

        offset : float
            Defaults to zero. A value which will be used to offset
            the plane in the direction of its `axis`.

        Returns
        -------
        bool
            `True` if the operation was successful, and `False` if the shape
            is not a `'Face'`.

        See Also
        --------
        alignToPointAndAxis, DraftGeomUtils.getQuad
        """
        # Set face to the unique selected face, if found
        if shape.ShapeType == 'Face':
            self.alignToPointAndAxis(shape.Faces[0].CenterOfMass,
                                     shape.Faces[0].normalAt(0, 0),
                                     offset)
            import DraftGeomUtils
            q = DraftGeomUtils.getQuad(shape)
            if q:
                self.u = q[1]
                self.v = q[2]
                if not DraftVecUtils.equals(self.u.cross(self.v), self.axis):
                    self.u = q[2]
                    self.v = q[1]
                if DraftVecUtils.equals(self.u, Vector(0, 0, 1)):
                    # the X axis is vertical: rotate 90 degrees
                    self.u, self.v = self.v.negative(), self.u
                elif DraftVecUtils.equals(self.u, Vector(0, 0, -1)):
                    self.u, self.v = self.v, self.u.negative()

            self.weak = False
            return True
        else:
            return False
示例#2
0
 def alignToFace(self, shape, offset=0):
     # Set face to the unique selected face, if found
     if shape.ShapeType == 'Face':
         self.alignToPointAndAxis(shape.Faces[0].CenterOfMass, shape.Faces[0].normalAt(0,0), offset)
         import DraftGeomUtils
         q = DraftGeomUtils.getQuad(shape)
         if q:
             self.u = q[1]
             self.v = q[2]
             if not DraftVecUtils.equals(self.u.cross(self.v),self.axis):
                 self.u = q[2]
                 self.v = q[1]
         return True
     else:
         return False
示例#3
0
 def alignToFace(self, shape, offset=0):
     # Set face to the unique selected face, if found
     if shape.ShapeType == 'Face':
         self.alignToPointAndAxis(shape.Faces[0].CenterOfMass, shape.Faces[0].normalAt(0,0), offset)
         import DraftGeomUtils
         q = DraftGeomUtils.getQuad(shape)
         if q:
             self.u = q[1]
             self.v = q[2]
             if not DraftVecUtils.equals(self.u.cross(self.v),self.axis):
                 self.u = q[2]
                 self.v = q[1]
         self.weak = False
         return True
     else:
         return False
示例#4
0
 def alignToFace(self, shape, offset=0):
     # Set face to the unique selected face, if found
     if shape.ShapeType == 'Face':
         self.alignToPointAndAxis(shape.Faces[0].CenterOfMass, shape.Faces[0].normalAt(0,0), offset)
         import DraftGeomUtils
         q = DraftGeomUtils.getQuad(shape)
         if q:
             self.u = q[1]
             self.v = q[2]
             if not DraftVecUtils.equals(self.u.cross(self.v),self.axis):
                 self.u = q[2]
                 self.v = q[1]
             if DraftVecUtils.equals(self.u,Vector(0,0,1)):
                 # the X axis is vertical: rotate 90 degrees
                 self.u,self.v = self.v.negative(),self.u
                 
         self.weak = False
         return True
     else:
         return False
示例#5
0
 def alignToFace(self, shape, offset=0):
     # Set face to the unique selected face, if found
     if shape.ShapeType == 'Face':
         self.alignToPointAndAxis(shape.Faces[0].CenterOfMass, shape.Faces[0].normalAt(0,0), offset)
         import DraftGeomUtils
         q = DraftGeomUtils.getQuad(shape)
         if q:
             self.u = q[1]
             self.v = q[2]
             if not DraftVecUtils.equals(self.u.cross(self.v),self.axis):
                 self.u = q[2]
                 self.v = q[1]
             if DraftVecUtils.equals(self.u,Vector(0,0,1)):
                 # the X axis is vertical: rotate 90 degrees
                 self.u,self.v = self.v.negative(),self.u
             elif DraftVecUtils.equals(self.u,Vector(0,0,-1)):
                 self.u,self.v = self.v,self.u.negative()
                 
         self.weak = False
         return True
     else:
         return False
示例#6
0
    def alignToFace(self, shape, offset=0, parent=None):
        """Align the plane to a face.

        It uses the center of mass of the face as `position`,
        and its normal in the center of the face as `axis`,
        then calls `alignToPointAndAxis(position, axis, offset)`.

        If the face is a quadrilateral, then it adjusts the position
        of the plane according to its reported X direction and Y direction.

        Also set `weak` to `False`.

        Parameter
        --------
        shape : Part.Face
            A shape of type `'Face'`.

        offset : float
            Defaults to zero. A value which will be used to offset
            the plane in the direction of its `axis`.

        parent : object
            Defaults to None. The ParentGeoFeatureGroup of the object
            the face belongs to.

        Returns
        -------
        bool
            `True` if the operation was successful, and `False` if the shape
            is not a `'Face'`.

        See Also
        --------
        alignToPointAndAxis, DraftGeomUtils.getQuad
        """
        # Set face to the unique selected face, if found
        if shape.ShapeType == 'Face':
            if parent:
                place = parent.getGlobalPlacement()
            else:
                place = FreeCAD.Placement()
            cen = place.multVec(shape.Faces[0].CenterOfMass)
            place.Base = FreeCAD.Vector(
                0, 0, 0)  # Reset the Base for the conversion of the normal.
            nor = place.multVec(shape.Faces[0].normalAt(0, 0))
            self.alignToPointAndAxis(cen, nor, offset)
            import DraftGeomUtils
            q = DraftGeomUtils.getQuad(shape)
            if q:
                self.u = place.multVec(q[1])
                self.v = place.multVec(q[2])
                if not DraftVecUtils.equals(self.u.cross(self.v), self.axis):
                    self.u, self.v = self.v, self.u
                if DraftVecUtils.equals(self.u, Vector(0, 0, 1)):
                    # the X axis is vertical: rotate 90 degrees
                    self.u, self.v = self.v.negative(), self.u
                elif DraftVecUtils.equals(self.u, Vector(0, 0, -1)):
                    self.u, self.v = self.v, self.u.negative()

            self.weak = False
            return True
        else:
            return False