Example #1
0
    def _generateClippedCurve(self, r1, r2, length, min=0, max=0):
        if max == 0.0:
            max = self._length

        if r1 > r2:
            major = length - min
            minor = r1
            if min <= 0:
                theta1 = math.pi / 2
            else:
                theta1 = self._eTheta(major, minor, (r1 / min))
            theta2 = math.pi - self._eTheta(major, minor, (r2 / max))

            print("tan %f,%f compared to %f,%f" %
                  (theta1, theta2, math.pi / 2, math.pi))
            curve = Part.ArcOfEllipse(
                Part.Ellipse(FreeCAD.Vector(max, 0.0), major, minor), theta1,
                theta2)
            for vertex in Part.Wire(curve.toShape()).Vertexes:
                print(vertex.Point)

            return curve

        major = length - min
        minor = r2
        if min <= 0:
            theta2 = math.pi / 2
        else:
            theta2 = self._eTheta(major, minor, (r2 / min))
        theta1 = self._eTheta(major, minor, (r1 / max))
        curve = Part.ArcOfEllipse(
            Part.Ellipse(FreeCAD.Vector(min, 0.0), major, minor), theta1,
            theta2)

        return curve
Example #2
0
    def drawHollow(self):
        last = self._length - self._thickness

        outer_curve = Part.ArcOfEllipse(
            Part.Ellipse(FreeCAD.Vector(0, 0), self._length, self._radius),
            0.0, math.pi / 2)
        inner_curve = Part.ArcOfEllipse(
            Part.Ellipse(FreeCAD.Vector(0, 0), last,
                         self._radius - self._thickness), 0.0, math.pi / 2)

        edges = self.hollowLines(last, outer_curve, inner_curve)
        return edges
Example #3
0
    def drawCapped(self):
        last = self._length - self._thickness
        minor_y = self.innerMinor(last)

        outer_curve = Part.ArcOfEllipse(
            Part.Ellipse(FreeCAD.Vector(0, 0), self._length, self._radius),
            0.0, math.pi / 2)
        inner_curve = Part.ArcOfEllipse(
            Part.Ellipse(FreeCAD.Vector(self._thickness, 0),
                         last - self._thickness, minor_y), 0.0, math.pi / 2)

        edges = self.cappedLines(last, minor_y, outer_curve, inner_curve)
        return edges
Example #4
0
 def execute(self, obj):
     import Part
     plm = obj.Placement
     if obj.MajorRadius.Value < obj.MinorRadius.Value:
         _err = "Error: Major radius is smaller than the minor radius"
         App.Console.PrintMessage(QT_TRANSLATE_NOOP("Draft", _err))
         return
     if obj.MajorRadius.Value and obj.MinorRadius.Value:
         ell = Part.Ellipse(App.Vector(0, 0, 0),
                            obj.MajorRadius.Value,
                            obj.MinorRadius.Value)
         shape = ell.toShape()
         if hasattr(obj,"FirstAngle"):
             if obj.FirstAngle.Value != obj.LastAngle.Value:
                 a1 = obj.FirstAngle.getValueAs(App.Units.Radian)
                 a2 = obj.LastAngle.getValueAs(App.Units.Radian)
                 shape = Part.ArcOfEllipse(ell, a1, a2).toShape()
         shape = Part.Wire(shape)
         if shape.isClosed():
             if hasattr(obj,"MakeFace"):
                 if obj.MakeFace:
                     shape = Part.Face(shape)
             else:
                 shape = Part.Face(shape)
         obj.Shape = shape
         if hasattr(obj, "Area") and hasattr(shape, "Area"):
             obj.Area = shape.Area
         obj.Placement = plm
     obj.positionBySupport()
Example #5
0
    def drawSolidShoulder(self):
        outer_curve = Part.ArcOfEllipse(
            Part.Ellipse(FreeCAD.Vector(0, 0), self._length, self._radius),
            0.0, math.pi / 2)

        edges = self.solidShoulderLines(outer_curve)
        return edges
Example #6
0
    def _halfEllipse(self, major, minor, thickness, midChord):
        if major > minor:
            ellipse = Part.Ellipse(
                FreeCAD.Vector(midChord, thickness, major),
                FreeCAD.Vector(midChord - minor, thickness, 0),
                FreeCAD.Vector(midChord, thickness, 0))
            arc = Part.ArcOfEllipse(ellipse, -math.pi / 2, math.pi / 2)
        else:
            print("half 1")
            ellipse = Part.Ellipse(
                FreeCAD.Vector(midChord - minor, thickness, 0),
                FreeCAD.Vector(midChord, thickness, major),
                FreeCAD.Vector(midChord, thickness, 0))
            arc = Part.ArcOfEllipse(ellipse, 0, math.pi)

        line = Part.makeLine((midChord + minor, thickness, 0),
                             (midChord - minor, thickness, 0))
        wire = Part.Wire([arc.toShape(), line])
        return wire
Example #7
0
    def _generateCurve(self, r1, r2, length, min=0, max=0):
        if self._clipped:
            return super()._generateCurve(r1, r2, length, min, max)

        if self._debugShape:
            print("r1 = %f, r2 = %f, min = %f, max = %f, length = %f" %
                  (r1, r2, min, max, length))
        if max == 0.0:
            max = length - min
        if r1 > r2:
            radius = r1 - r2
            curve = Part.ArcOfEllipse(
                Part.Ellipse(FreeCAD.Vector(max, r2), max - min, radius),
                math.pi / 2, math.pi)
            return curve

        radius = r2 - r1
        curve = Part.ArcOfEllipse(
            Part.Ellipse(FreeCAD.Vector(min, r1), max - min, radius), 0.0,
            math.pi / 2)
        return curve
    def makeGeom(self, curve, startParam, endParam):

        '''makeGeom(self, curve, startParam, endParam)'''

        # print('###### makeGeom')

        if isinstance(curve, (Part.LineSegment, Part.Line)):
            # print('1')
            geom = Part.LineSegment(curve, startParam, endParam)

        elif isinstance(curve, Part.ArcOfCircle):
            # print('2')
            angleXU = curve.AngleXU
            geom = Part.ArcOfCircle(curve.Circle, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.ArcOfEllipse):
            # print('3')
            angleXU = curve.AngleXU
            geom = Part.ArcOfEllipse(curve.Ellipse, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.ArcOfParabola):
            # print('4')
            angleXU = curve.AngleXU
            geom = Part.ArcOfParabola(curve.Parabola, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.ArcOfHyperbola):
            # print('5')
            angleXU = curve.AngleXU
            geom = Part.ArcOfHyperbola(curve.Hyperbola, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.Circle):
            # print('6')
            angleXU = curve.AngleXU
            geom = Part.ArcOfCircle(curve, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.Ellipse):
            # print('7')
            angleXU = curve.AngleXU
            geom = Part.ArcOfEllipse(curve, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.Parabola):
            # print('8')
            angleXU = curve.AngleXU
            geom = Part.ArcOfParabola(curve, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.Hyperbola):
            # print('9')
            angleXU = curve.AngleXU
            geom = Part.ArcOfHyperbola(curve, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.BSplineCurve):
            # print('10')
            pass

        # print('geom ', geom)

        return geom
    def objArc(self, d, cx, cy, rx, ry, st, en, closed, node, mat):
        """
    We ignore the path d, and produce a nice arc object.
    We distinguish two cases. If it looks like a circle, we produce ArcOfCircle,
    else we produce ArcOfEllipse.

    To find the arc end points, we use the value() property of the Circle and Ellipse
    objects. With Circle we have to take care of mirror and rotation ourselves.

    If closed, we connect the two ends to the center with lines. The connections
    are secured with constraints.
    Radii are currently not secured with constraints.
    """
        ### CAUTION: Keep in sync with objEllipse() above.
        # print("objArc: st,en,closed", st, en, closed)
        self._matrix_from_svg(mat)
        c = self._from_svg(cx, cy, bbox=False)
        ori = self._from_svg(0, 0, bbox=False)
        vrx = self._from_svg(rx, 0, bbox=False) - ori
        vry = self._from_svg(0, ry, bbox=False) - ori
        i = self.ske.GeometryCount
        (st_idx, en_idx) = (1, 2)
        majAxisIdx = None

        if abs(vrx.Length - vry.Length) < epsilon:
            # it is a circle.
            self.bbox.add(c + vrx + vry)
            self.bbox.add(c - vrx - vry)
            ce = Part.Circle(Center=c,
                             Normal=Base.Vector(0, 0, 1),
                             Radius=vrx.Length)

            # Circles are immune to rotation and mirorring. Apply this manually.
            if self.yflip:
                (st, en) = (-en, -st)  ## coord system is mirrored.
            else:
                (st, en) = (en, st)  ## hmm.
                print("FIXME: ArcOfCircle() with yflip=False needs debugging.")
            r = Base.Matrix()
            r.rotateZ(st)
            pst = r.multiply(vrx)
            st = pst.getAngle(Base.Vector(
                1, 0, 0))  # ce.rotateZ() is a strange beast.
            pst = pst + c
            r = Base.Matrix()
            r.rotateZ(en)
            pen = r.multiply(vrx)
            en = pen.getAngle(Base.Vector(
                1, 0, 0))  # ce.rotateZ() is a strange beast.
            pen = pen + c

            self.ske.addGeometry([Part.ArcOfCircle(ce, st, en)])
            self.stats['objArc'] += 1

        else:
            # major axis is defined by Center and S1,
            # major radius is the distance between Center and S1,
            # minor radius is the distance between S2 and the major axis.
            s1 = self._from_svg(cx + rx, cy, bbox=False)
            s2 = self._from_svg(cx, cy + ry, bbox=False)
            (V1, V2, V3, V4) = self._ellipse_vertices2d(c, s1, s2)
            self.bbox.add(V1)
            self.bbox.add(V2)
            self.bbox.add(V3)
            self.bbox.add(V4)
            i = int(self.ske.GeometryCount)
            ce = Part.Ellipse(S1=V1, S2=V2, Center=c)
            self.ske.addGeometry([Part.ArcOfEllipse(ce, st, en)])
            if self.expose_int: self.ske.exposeInternalGeometry(i)
            majAxisIdx = i + 1  # CAUTION: is that a safe assumption?
            self.stats['objArc'] += 1
            ## CAUTION: with yflip=True sketcher reverses the endpoints of
            ##          an ArcOfEllipse to: en=1, st=2
            ##          ArcOfCircle seems unaffected.
            if self.yflip: (st_idx, en_idx) = (2, 1)
            r = Base.Matrix()
            r.rotateZ(st)
            pst = r.multiply(vrx) + c
            r = Base.Matrix()
            r.rotateZ(en)
            pen = r.multiply(vrx) + c

        j = self.ske.GeometryCount
        if closed:
            self.ske.addGeometry([
                Part.LineSegment(ce.value(en), c),
                Part.LineSegment(c, ce.value(st))
            ])

            if True:  # when debugging deformations, switch off constriants first.
                self.ske.addConstraint([
                    Sketcher.Constraint('Coincident', i + 0, en_idx, j + 0,
                                        1),  # arc with line
                    Sketcher.Constraint('Coincident', j + 1, 2, i + 0,
                                        st_idx),  # line with arc
                    Sketcher.Constraint('Coincident', j + 0, 2, j + 1,
                                        1),  # line with line
                    Sketcher.Constraint('Coincident', j + 0, 2, i + 0, 3)
                ])  # line with center

        if False:  # some debugging circles.
            self.ske.addGeometry(
                [
                    # Part.Circle(Center=pst, Normal=Base.Vector(0,0,1), Radius=2),
                    # Part.Circle(Center=pen, Normal=Base.Vector(0,0,1), Radius=3),
                    # Part.Circle(Center=ce.value(st), Normal=Base.Vector(0,0,1), Radius=4),
                    Part.Circle(Center=ce.value(en),
                                Normal=Base.Vector(0, 0, 1),
                                Radius=5)
                ],
                True)

        # we return the start, end and center points, as triple (sketcher_index, sketcher_index_point, Vector)
        return ((i + 0, st_idx, ce.value(st)), (i + 0, en_idx, ce.value(en)),
                (i + 0, 3, c), majAxisIdx)
    def makeGeom(self, curve, startParam, endParam):

        '''makeGeom(self, curve, startParam, endParam)'''

        # print '###### makeGeom'

        if isinstance(curve, (Part.Line, Part.LineSegment)):
            # print '1'
            geom = Part.LineSegment(curve, startParam, endParam)

        elif isinstance(curve, Part.Circle):
            # print '2'
            angleXU = curve.AngleXU
            geom = Part.ArcOfCircle(curve, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.ArcOfCircle):
            # print '3'
            angleXU = curve.AngleXU
            geom = Part.ArcOfCircle(curve.Circle, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.Ellipse):
            # print '4'
            angleXU = curve.AngleXU
            geom = Part.ArcOfEllipse(curve, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.ArcOfEllipse):
            # print '5'
            angleXU = curve.AngleXU
            geom = Part.ArcOfEllipse(curve.Ellipse, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.Parabola):
            # print '6'
            angleXU = curve.AngleXU
            geom = Part.ArcOfParabola(curve, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.ArcOfParabola):
            # print '7'
            angleXU = curve.AngleXU
            geom = Part.ArcOfParabola(curve.Parabola, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.Hyperbola):
            # print '8'
            angleXU = curve.AngleXU
            geom = Part.ArcOfHyperbola(curve, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.ArcOfHyperbola):
            # print '9'
            angleXU = curve.AngleXU
            geom = Part.ArcOfHyperbola(curve.Hyperbola, startParam, endParam)
            geom.AngleXU = angleXU

        elif isinstance(curve, Part.BSplineCurve):
            # print '10'
            pass

        # print 'geom ', geom

        return geom
                Radius=2),
    # North: math.pi/2
    # SouthEast: -math.pi/4
    # West: math.pi, -math.pi
    # East: 0
    #Part.ArcOfCircle(Part.Circle(Base.Vector(4,7,0), Base.Vector(0,0,1), 1), math.pi/2, -math.pi)
    #
    #
    # Long axis SW: (N, -N, 0)
    # Short axis NE: (N, N, 0)
    # StartPoint North: 3/4 pi  (counted CCW from long axis)
    # EndPoint   NNE:   -9/8 pi (counted CW from long axis)
    # FIXME: the angles are distroted according to the tangents of the contact point.
    # North is more like 5/8 pi but a bit less.
    Part.ArcOfEllipse(
        Part.Ellipse(App.Vector(8, -8, 0), App.Vector(3, 3, 0),
                     App.Vector(0, 0, 0)), -math.pi * (8 + 1.) / 8,
        math.pi * (5. / 8))
    #
    # Part.Ellipse(App.Vector(8,-8,0),App.Vector(3,3,0),App.Vector(0,0,0))
]
ske.addGeometry(geo, False)  # False: normal, True: blue construction
ske.exposeInternalGeometry(i +
                           5)  # long and short axis, focal points of Ellipse

print("GeometryCount changed from %d to %d" % (i, int(ske.GeometryCount)))

con = [
    Sketcher.Constraint('Coincident', i + 0, 2, i + 1, 1),
    Sketcher.Constraint('Coincident', i + 1, 2, i + 2, 1),
    Sketcher.Constraint('Coincident', i + 2, 2, i + 3, 1),
    Sketcher.Constraint('Coincident', i + 3, 2, i + 5, 2),