Exemplo n.º 1
0
    def testMirror(self):
        """
            perform a mirror operation of all the entity
        """
        #Arc mirror
        newDoc=self.__pyCadApplication.ActiveDocument
        centerPoint=Point(100, 100)
        arg={"ARC_0":centerPoint, "ARC_1":50, "ARC_2":0.78539816339500002,"ARC_3":1.5707963267948966}
        arc=Arc(arg)
        entArc=newDoc.saveEntity(arc)

        sArg={"SEGMENT_0":Point(-100, 0), "SEGMENT_1":Point(0, 100)}
        _s=Segment(sArg)

        mirrorSeg=newDoc.saveEntity(_s)
        arc.mirror(_s)
        entArc=newDoc.saveEntity(arc)
        #Point
        centerPoint=Point(100, 0)
        dbPointEnt=newDoc.saveEntity(centerPoint)
        newcenterPoint=centerPoint.clone()
        newcenterPoint.mirror(_s)
        dbPointEnt=newDoc.saveEntity(newcenterPoint)
        #Segment
        sArg={"SEGMENT_0":Point(100, 100), "SEGMENT_1":Point(150, 150)}
        _st=Segment(sArg)
        newSeg=newDoc.saveEntity(_st)
        _st.mirror(_s)
        newDoc.saveEntity(_st)
        #Ellipse
        eArg={"ELLIPSE_0":Point(100, 0), "ELLIPSE_1":100, "ELLIPSE_2":50}
        _e=Ellipse(eArg)
        newE=newDoc.saveEntity(_e)
        _e.mirror(_s)
        newDoc.saveEntity(_e)
Exemplo n.º 2
0
 def getIntersection(self, entity, point):
     """
         this function compute the  snap intersection point
     """
     returnVal = None
     distance = None
     if entity != None:
         geoEntityFrom = entity.geoItem
         entityList = self._scene.collidingItems(entity)
         for ent in entityList:
             if not isinstance(ent, BaseEntity):
                 continue
             if isinstance(ent, BaseEntity):
                 intPoint = find_intersections(ent.geoItem, geoEntityFrom)
                 for tp in intPoint:
                     iPoint = Point(tp[0], tp[1])
                     if distance == None:
                         distance = iPoint.dist(point)
                         returnVal = iPoint
                     else:
                         spoolDist = iPoint.dist(point)
                         if distance > spoolDist:
                             distance = spoolDist
                             returnVal = iPoint
     return returnVal
Exemplo n.º 3
0
 def createLine(self, x1, y1, x2, y2, c):
     """
       Create the line into the current drawing
     """
     args = {"SEGMENT_0": Point(x1, y1), "SEGMENT_1": Point(x2, y2)}
     _seg = Segment(args)
     self.__kernel.saveEntity(_seg)
Exemplo n.º 4
0
    def testMove(self):
        """
            perform a move operation
        """
        #Arc
        newDoc=self.__pyCadApplication.ActiveDocument
        centerPoint=Point(100, 100)
        arg={"ARC_0":centerPoint, "ARC_1":50, "ARC_2":0.78539816339500002,"ARC_3":1.5707963267948966}
        arc=Arc(arg)
        entArc=newDoc.saveEntity(arc)

        sp=Point(0, 0)
        ep=Point(100, 100)

        arc.move(sp, ep)
        entArc=newDoc.saveEntity(arc)
        #Point
        centerPoint=Point(100, 0)
        dbPointEnt=newDoc.saveEntity(centerPoint)
        centerPoint.move(sp, ep)
        dbPointEnt=newDoc.saveEntity(centerPoint)
        #Segment
        sArg={"SEGMENT_0":Point(100, 100), "SEGMENT_1":Point(150, 150)}
        _st=Segment(sArg)
        newSeg=newDoc.saveEntity(_st)
        _st.move(sp, ep)
        newDoc.saveEntity(_st)
        #Ellipse
        eArg={"ELLIPSE_0":Point(100, 0), "ELLIPSE_1":100, "ELLIPSE_2":50}
        _e=Ellipse(eArg)
        newE=newDoc.saveEntity(_e)
        _e.move(sp, ep)
        newDoc.saveEntity(_e)
Exemplo n.º 5
0
    def rotate(self):
        """
            perform a rotate operation
        """
        newDoc=self.__pyCadApplication.ActiveDocument
        ang=1.5707963267948966
        cp=Point(0, 0)
        newDoc.saveEntity(cp)
        #Point
        centerPoint=Point(100,100)
        dbPointEnt=newDoc.saveEntity(centerPoint)
        centerPoint.rotate(cp, ang)
        dbPointEnt=newDoc.saveEntity(centerPoint)

        #Arc
        centerPoint=Point(100, 100)
        arg={"ARC_0":centerPoint, "ARC_1":50, "ARC_2":0.78539816339500002,"ARC_3":1.5707963267948966}
        arc=Arc(arg)
        entArc=newDoc.saveEntity(arc)
        arc.rotate(cp,ang)
        entArc=newDoc.saveEntity(arc)

        #Segment
        sArg={"SEGMENT_0":Point(100, 100), "SEGMENT_1":Point(150, 150)}
        _st=Segment(sArg)
        newSeg=newDoc.saveEntity(_st)
        _st.rotate(cp, ang)
        newDoc.saveEntity(_st)
        #Ellipse
        eArg={"ELLIPSE_0":Point(100, 0), "ELLIPSE_1":100, "ELLIPSE_2":50}
        _e=Ellipse(eArg)
        newE=newDoc.saveEntity(_e)
        _e.rotate(cp, ang)
        newDoc.saveEntity(_e)
Exemplo n.º 6
0
 def polygonPoint(self):
     """
         get the poligon points
     """
     if self.side <= 0:
         self.side = 6
     deltaAngle = (math.pi * 2) / self.side
     cPoint = Point(self.center.x(), self.center.y())
     vPoint = Point(self.vertex.x(), self.vertex.y())
     vertexVector = Vector(cPoint, vPoint)
     radius = vertexVector.norm
     angle = vertexVector.absAng
     pol = QtGui.QPolygonF()
     pFirst = None
     for i in range(0, int(self.side)):
         angle = deltaAngle + angle
         xsP = cPoint.x + radius * math.cos(angle) * -1.0
         ysP = cPoint.y + radius * math.sin(angle) * -1.0
         p = QtCore.QPointF(xsP, ysP)
         pol.append(p)
         if not pFirst:
             pFirst = p
     if pFirst:
         pol.append(pFirst)
     return pol
Exemplo n.º 7
0
 def mag(self):
     """
         Get the versor
     """
     _a = self.absAng
     p1 = Point(0, 0)
     p2 = Point(math.cos(_a), math.sin(_a))
     return Vector(p1, p2)
Exemplo n.º 8
0
def segment_ellipse():
    print "++ segment_ellipse ++"
    p1 = Point(0, 0)
    arg = {"ELLIPSE_0": p1, "ELLIPSE_1": 300, "ELLIPSE_2": 100}
    eli = Ellipse(arg)
    p2 = Point(0, 0)
    p3 = Point(-1, 0)
    arg = {"CLINE_0": p2, "CLINE_1": p3}
    seg1 = CLine(arg)
    print find_intersections(eli, seg1)
    print "-- segment_ellipse --"
Exemplo n.º 9
0
def segment_circle():
    print "++ segment_circle ++"
    p1 = Point(0, 0)
    arg = {"ARC_0": p1, "ARC_1": 5, "ARC_2": 0, "ARC_3": 6.2831}
    arc = Arc(arg)
    p2 = Point(0, 0)
    p3 = Point(-1, 0)
    arg = {"CLINE_0": p2, "CLINE_1": p3}
    seg1 = CLine(arg)
    print find_intersections(arc, seg1)
    print "-- segment_circle --"
Exemplo n.º 10
0
 def getQuadrant(self):
     """
         Return the circle intersection with the line x,y passing through the
         center
     """
     x, y=self.center.getCoords()
     p1=Point(x, y+self.radius)
     p2=Point(x-self.radius, y)
     p3=Point(x, y-self.radius)
     p4=Point(x+self.radius, y)
     return [p1, p2, p3, p4]
Exemplo n.º 11
0
def segment_cline():
    print "++ segment_cline ++"
    p1 = Point(0, 0)
    p2 = Point(0, 1)
    arg = {"CLINE_0": p1, "CLINE_1": p2}
    seg1 = CLine(arg)
    p3 = Point(0, 0)
    p4 = Point(-1, 0)
    arg = {"SEGMENT_0": p3, "SEGMENT_1": p4}
    seg2 = Segment(arg)

    print find_intersections(seg1, seg2)
    print "-- segment_cline --"
Exemplo n.º 12
0
 def getProjection(self,fromPoint):
     """
         get Projection of the point x,y on the arc
     """
     c=self.center
     v=Vector(fromPoint,c)
     if  v.norm>self.radius:
         a=v.absAng
         pj1=Point((v.X+fromPoint.getx()-self.radius*math.cos(a)), (v.Y+fromPoint.gety()-self.radius*math.sin(a)))
         pj2=Point((v.X+fromPoint.getx()+self.radius*math.cos(a)), (v.Y+fromPoint.gety()+self.radius*math.sin(a)))
         return pj1 # ######################## adding return value for pj2
     else:
         return None
Exemplo n.º 13
0
def segment_segmet():
    print "++ segment_segmet ++"
    p1 = Point(0, 0)
    p2 = Point(0, 1)
    arg = {"SEGMENT_0": p1, "SEGMENT_1": p2}
    seg1 = Segment(arg)
    p3 = Point(0, 0)
    p4 = Point(-1, 0)
    arg = {"SEGMENT_0": p3, "SEGMENT_1": p4}
    seg2 = Segment(arg)

    print find_intersections(seg1, seg2)
    print "-- segment_segmet --"
Exemplo n.º 14
0
def testSympySegment():
    print "++ Sympy Segment ++"
    p1 = Point(0, 1)
    p2 = Point(10, 20)
    arg = {"SEGMENT_0": p1, "SEGMENT_1": p2}
    seg = Segment(arg)
    symSeg = seg.getSympy()
    print symSeg
    p3 = Point(30, 40)
    arg1 = {"SEGMENT_0": p1, "SEGMENT_1": p3}
    seg1 = Segment(arg1)
    seg1.setFromSympy(symSeg)
    print "Segment ", seg1
    print "-- Sympy Segment --"
Exemplo n.º 15
0
def getEntityEntity(sympyEntity):
    """
        convert sympy object into PyCAD object
    """
    if isinstance(sympyEntity, geoSympy.Circle):
        arg={"ARC_0":Point(0.0, 0.0),
             "ARC_1":1,
             "ARC_2":None,
             "ARC_3":None
             }
        arc=Arc(arg)
        arc.setFromSympy(sympyEntity)
        return arc
    elif isinstance(sympyEntity, geoSympy.Point):
        p=Point(0.0, 0.0)
        p.setFromSympy(sympyEntity)
        return p
    elif isinstance(sympyEntity, geoSympy.Segment):
        segArg={"SEGMENT_0":Point(0.0, 0.0), "SEGMENT_1":Point(1.0, 1.0)}
        seg=Segment(segArg)
        seg.setFromSympy(sympyEntity)
        return seg
    elif isinstance(sympyEntity, geoSympy.Ellipse):
        arg={"ELLIPSE_0":Point(0.0, 0.0), "ELLIPSE_1":1.0, "ELLIPSE_2":2.0}
        e=Ellipse(arg)
        e.setFromSympy(sympyEntity)
        return e
    else:
        raise "not supported entity"
Exemplo n.º 16
0
def testSympyCline():
    print "++ Sympy CLine ++"
    p1 = Point(0, 1)
    p2 = Point(10, 20)
    arg = {"CLINE_0": p1, "CLINE_1": p2}
    seg = CLine(arg)
    symSeg = seg.getSympy()
    print symSeg
    p3 = Point(30, 40)
    arg1 = {"CLINE_0": p1, "CLINE_1": p3}
    seg1 = CLine(arg1)
    seg1.setFromSympy(symSeg)
    print "CLine ", seg1
    print "-- Sympy CLine --"
Exemplo n.º 17
0
 def translateCmdValue(self, value):
     """
         translate the imput value based on exception
     """
     point, entitys, distance, angle, text = value
     exitValue = None
     try:
         raise self.activeException()(None)
     except ExcPoint:
         exitValue = point
     except ExcEntity:
         if entitys:
             exitValue = str(entitys[0].ID)
     except ExcMultiEntity:
         exitValue = self.getIdsString(entitys)
     except ExcEntityPoint:
         if entitys:
             exitValue = (str(entitys[0].ID), point)
     except (ExcLenght):
         if distance:
             exitValue = self.convertToFloat(distance)
     except (ExcAngle):
         if angle:
             exitValue = convertAngle(angle)
         elif distance:
             exitValue = distance
         else:
             p0 = Point(0.0, 0.0)
             x, y = point.getCoords()
             p1 = Point(x, y)
             exitValue = Vector(p0, p1).absAng
     except (ExcInt):
         exitValue = self.convertToInt(distance)
     except (ExcText):
         exitValue = text
         if text == None:
             exitValue = ""
     except (ExcBool):
         if text == "TRUE":
             exitValue = True
         else:
             exitValue = False
     except (ExcDicTuple):
         exitValue = text
     except:
         raise PyCadWrongInputData(
             "BaseCommand : Wrong input parameter for the command")
     finally:
         return exitValue
Exemplo n.º 18
0
 def GetRadiusPointFromExt(self, x, y):
     """
         get The intersecrion point from the line(x,y,cx,cy) and the circle
     """
     _cx, _cy = self.center.getCoords()
     _r = self.radius
     centerPoint = Point(_cx, _cy)
     outPoint = Point(x, y)
     vector = Vector(outPoint, centerPoint)
     vNorm = vector.Norm()
     newNorm = abs(vNorm - _r)
     magVector = vector.Mag()
     magVector.Mult(newNorm)
     newPoint = magVector.Point()
     intPoint = Point(outPoint + newPoint)
     return intPoint.getCoords()
Exemplo n.º 19
0
 def getRandomPoint(self):
     """
         get e random point
     """
     x=random()*1000
     y=random()*1000
     return Point(x, y)
Exemplo n.º 20
0
def _rotate_polyline(obj, objdict, cx, cy, ra):
    _pts = obj.getPoints()
    _layer = obj.getParent()
    if _layer is None:
        raise RuntimeError, "Polyline parent is None"
    _move = True
    for _pt in _pts:
        if _pt.getParent() is not _layer:
            raise RuntimeError, "Polyline/point parent object conflict!"
        _move = (_can_move(_pt, objdict) and
                 (objdict.get(id(_pt)) is not False))
        if not _move:
            break
    if _move:
        for _pt in _pts:
            _x, _y = _calc_coords(_pt, cx, cy, ra)
            _pt.setCoords(_x, _y)
            _pid = id(_pt)
            objdict[_pid] = False
    else:
        for _i in range(len(_pts)):
            _pt = _pts[_i]
            if objdict.get(_pid) is True:
                _x, _y = _calc_coords(_pt, cx, cy, ra)
                _pts = _layer.find('point', _x, _y)
                if len(_pts) == 0:
                    _np = Point(_x, _y)
                    _layer.addObject(_np)
                else:
                    _np = _most_used(_pts)
                obj.setPoint(_i, _np)
                objdict[_pid] = False
                _layer.delObject(_pt)
Exemplo n.º 21
0
 def location(self, x, y):
     """
         Store the spatial position of the Text.
     """
     _x = get_float(x)
     _y = get_float(y)
     self['TEXT_0'] = Point(_x, _y)
Exemplo n.º 22
0
 def GetRadiusPointFromExt(self,x,y):
     """
         get The intersecrion point from the line(x,y,cx,cy) and the circle
     """
     _cx, _cy = self.center.getCoords()
     _r = self.radius
     centerPoint=Point(_cx,_cy)
     outPoint=Point(x,y)
     vector=Vector(outPoint,centerPoint)
     vNorm=vector.norm()
     newNorm=abs(vNorm-_r)
     magVector=vector.mag()
     magVector.mult(newNorm)
     newPoint=magVector.point()
     intPoint=Point(outPoint+newPoint)
     return intPoint.getCoords()
Exemplo n.º 23
0
 def GetTangentPoint(self,x,y,outx,outy):
     """
         Get the tangent from an axternal point
         args:
             x,y is a point near the circle
             xout,yout is a point far from the circle
         return:
             a tuple(x,y,x1,xy) that define the tangent line
     """
     firstPoint=Point(x,y)
     fromPoint=Point(outx,outy)
     twoPointDistance=self.center.Dist(fromPoint)
     if(twoPointDistance<self.radius):
         return None,None
     originPoint=Point(0.0,0.0)
     tanMod=math.sqrt(pow(twoPointDistance,2)-pow(self.radius,2))
     tgAngle=math.asin(self.radius/twoPointDistance)
     #Compute the x versor
     xPoint=point.Point(1.0,0.0)
     xVector=Vector(originPoint,xPoint)
     twoPointVector=Vector(fromPoint,self.center)
     rightAngle=twoPointVector.Ang(xVector)
     cx,cy=self.center.getCoords()
     if(outy>cy): #stupid situation
         rightAngle=-rightAngle
     posAngle=rightAngle+tgAngle
     negAngle=rightAngle-tgAngle
     #Compute the Positive Tangent
     xCord=math.cos(posAngle)
     yCord=math.sin(posAngle)
     dirPoint=Point(xCord,yCord)#Versor that point at the tangentPoint
     ver=Vector(originPoint,dirPoint)
     ver.Mult(tanMod)
     tangVectorPoint=ver.Point()
     posPoint=Point(tangVectorPoint+(outx,outy))
     #Compute the Negative Tangent
     xCord=math.cos(negAngle)
     yCord=math.sin(negAngle)
     dirPoint=Point(xCord,yCord)#Versor that point at the tangentPoint
     ver=Vector(originPoint,dirPoint)
     ver.Mult(tanMod)
     tangVectorPoint=ver.Point()
     negPoint=Point(tangVectorPoint+(outx,outy))
     if firstPoint.Dist(posPoint)<firstPoint.Dist(negPoint):
         return posPoint.getCoords()
     else:
         return negPoint.getCoords()
Exemplo n.º 24
0
    def getEndpoints(self):
        """
            Return where the two endpoints for the arc-segment lie.
            This function returns two Points, each containing the x-y coordinates
            of the arc endpoints. The first Point corresponds to the endpoint at
            the startAngle, the second to the endpoint at the endAngle.
        """
        _cx, _cy = self.center.getCoords()
        _r = self.radius
        _sa = self.startAngle
        _sax = _cx + _r * math.cos(_sa )
        _say = _cy + _r * math.sin(_sa)
        _ea = self.endAngle+_sa

        _eax = _cx + _r * math.cos(_ea )
        _eay = _cy + _r * math.sin(_ea )
        return Point(_sax, _say), Point(_eax, _eay)
Exemplo n.º 25
0
 def convertToPoint(self, msg):
     """
         ask at the user to input a point
     """
     if msg:
         coords=msg.split(',')
         x=float(coords[0])
         y=float(coords[1])
         return Point(x, y)
     return None
Exemplo n.º 26
0
 def hanhlerDoubleClick(self):
     """
         event add from the handler
     """
     point = Point(self.posHandler.scenePos.x(),
                   self.posHandler.scenePos.y() * -1.0)
     self.activeICommand.addMouseEvent(point=point,
                                       distance=self.posHandler.distance,
                                       angle=self.posHandler.angle)
     self.hideHandler()
Exemplo n.º 27
0
    def testGeoChamfer(self):
        self.outputMsg("Test Chamfer")
        p1=Point(0.0, 0.0)
        p2=Point(10.0, 0.0)
        p3=Point(0.0, 10.0)

        s1=Segment(p1, p2)
        s2=Segment(p1, p3)

        cmf=Chamfer(es1.getId(), s2, 2.0, 2.0)
        cl=cmf.getLength()
        self.outputMsg("Chamfer Lengh %s"%str(cl))
        s1, s2, s3=cmf.getReletedComponent()
        if s3:
            for p in s3.getEndpoints():
                x, y=p.getCoords()
                self.outputMsg("P1 Cords %s,%s"%(str(x), str(y)))
        else:
            self.outputMsg("Chamfer segment in None")
Exemplo n.º 28
0
    def testFillet1(self):
        newDoc=self.__pyCadApplication.ActiveDocument
        intPoint=Point(0.0, 0.0)
        args={"SEGMENT_0":intPoint, "SEGMENT_1":Point(10.0, 0.0)}
        s1=Segment(args)
        args={"SEGMENT_0":intPoint, "SEGMENT_1":Point(0.0, 10.0)}
        s2=Segment(args)

        ent1=newDoc.saveEntity(s1)
        ent2=newDoc.saveEntity(s2)

        cObject=self.__pyCadApplication.getCommand("FILLET")
        keys=cObject.keys()
        cObject[keys[0]]=ent1
        cObject[keys[1]]=ent2
        cObject[keys[2]]=Point(1, 0)
        cObject[keys[3]]=Point(0, 3)
        cObject[keys[4]]="BOTH"
        cObject[keys[5]]=4
        cObject.applyCommand()
Exemplo n.º 29
0
def testSympyCircle():
    print "++ Sympy Arc ++"
    p1 = Point(0, 1)
    arg = {"ARC_0": p1, "ARC_1": 5, "ARC_2": 0, "ARC_3": 6.2831}
    arc = Arc(arg)
    sympCircle = arc.getSympy()
    print "sympCircle", sympCircle
    sympCircel = geoSympy.Circle(geoSympy.Point(10, 10), 10)
    arc.setFromSympy(sympCircel)
    print "Pythonca Arc ", arc
    print "-- Sympy Arc --"
Exemplo n.º 30
0
def testSympyEllipse():
    print "++ Sympy Ellipse ++"
    p1 = Point(0, 1)
    arg = {"ELLIPSE_0": p1, "ELLIPSE_1": 100, "ELLIPSE_2": 50}
    eli = Ellipse(arg)
    sympEli = eli.getSympy()
    print "sympEllipse", sympEli
    sympEli1 = geoSympy.Ellipse(geoSympy.Point(10, 10), 300, 200)
    eli.setFromSympy(sympEli1)
    print "Pythonca Ellipse ", eli
    print "-- Sympy Ellipse --"
Exemplo n.º 31
0
 def map(self, pPro):
     """
         Get a vector for the mapping point
     """
     p0 = Point(0, 0)
     vProj = Vector(p0, pPro)
     ang = self.ang(vProj)
     vProjNorm = vProj.norm
     projectionUnitDistance = vProjNorm * math.cos(ang)
     vSelfMag = self.mag()
     vSelfMag.mult(projectionUnitDistance)
     return vSelfMag
Exemplo n.º 32
0
 def __add__(self,obj):
     """
         Add two Point
     """
     if not isinstance(obj, Point):
         if isinstance(obj, tuple):
             x, y = tuple_to_two_floats(obj)
         else:
             raise TypeError,"Invalid Argument obj: Point or tuple Required"
     else:
         x,y = obj.getCoords()
     return Point(self.__x+x, self.__y+y)
Exemplo n.º 33
0
def _adjust_endpoint(arc, pt, objdict, cx, cy, ra):
    _layer = arc.getParent()
    if pt.getParent() is not _layer:
        raise RuntimeError, "Arc/Endpoint parent object conflict!"
    _pid = id(pt)
    _users = []
    for _user in pt.getUsers():
        _users.append(_user)
    _np = None
    _x, _y = _calc_coords(pt, cx, cy, ra)
    if len(_users) == 1 and _users[0] is arc:
        if _can_move(pt, objdict) and objdict.get(_pid) is not False:
            pt.setCoords(_x, _y)
        else:
            _pts = _layer.find('point', _x, _y)
            if len(_pts) == 0:
                _np = Point(_x, _y)
                _layer.addObject(_np)
            else:
                _np = _most_used(_pts)
    else:
        pt.freeUser(arc)
        _pts = _layer.find('point', _x, _y)
        if len(_pts) == 0:
            _np = Point(_x, _y)
            _layer.addObject(_np)
        else:
            _np = _most_used(_pts)
    if _np is not None:
        _np.storeUser(arc)
        if _adjust_dimensions(pt, _np):
            _layer.delObject(pt)
    if objdict.get(_pid) is not False:
        objdict[_pid] = False