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)
Exemple #2
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
 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)
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"
Exemple #5
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
Exemple #6
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()
Exemple #7
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() 
Exemple #8
0
    def testChamferCommand(self):
        """
            this function is usefoul for short test
            as soon it works copy the code into featureTest
        """
        newDoc = self.__pyCadApplication.newDocument()
        intPoint = Point(0.0, 0.0)

        s1 = Segment(intPoint, Point(10.0, 0.0))
        s2 = Segment(intPoint, Point(0.0, 10.0))

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

        cObject = self.__pyCadApplication.getCommand("CHAMFER")
        keys = list(cObject.keys())
        cObject[keys[0]] = ent1
        cObject[keys[1]] = ent2
        cObject[keys[2]] = 2
        cObject[keys[3]] = 2
        cObject[keys[4]] = None
        cObject[keys[5]] = None
        cObject.applyCommand()
Exemple #9
0
 def MassiveDelete(self):
     try:
         import time
         startTime = time.clock()
         newDoc = self.__pyCadApplication.ActiveDocument
         newDoc.startMassiveCreation()
         for i in range(1000):
             intPoint = Point(i, i)
             args = {"SEGMENT_0": intPoint, "SEGMENT_1": Point(10.0, 0.0)}
             s1 = Segment(args)
             newDoc.saveEntity(s1)
         else:
             newDoc.performCommit()
             newDoc.stopMassiveCreation()
             endTime = time.clock() - startTime
             print("Create 1000 entity in %s" % str(endTime))
     finally:
         ents = newDoc.getAllDrawingEntity()
         ids = [ent.getId() for ent in ents]
         startTime = time.clock()
         newDoc.massiveDelete(ids)
         endTime = time.clock() - startTime
         print("Delete 1000 entity in %s" % str(endTime))
Exemple #10
0
 def createArc(self, x, y, r, color=None, sa=None, ea=None):
     """
         Create a Arc entitys into the current drawing
     """
     _center = Point(x, y)
     if sa is None or ea is None:
         sa = ea = 0  #This is the case of circle
     else:
         sa = (sa * math.pi) / 180
         ea = (ea * math.pi) / 180
         ea = ea - sa
     args = {"ARC_0": _center, "ARC_1": r, "ARC_2": sa, "ARC_3": ea}
     _arc = Arc(args)
     self.__kernel.saveEntity(_arc)
Exemple #11
0
    def createPolyline(self, points, c):
        """
            Crate poliline into Pythoncad
        """
        pass  #TODO: must be implemented

        dPrint("Exec createPolyline")
        i = 0
        args = {}
        for _x, _y in points:
            _p = Point(_x, _y)
            args["POLYLINE_%s" % str(i, 'ASCII')] = _p
            i += 1
        pline = Polyline(args)
        self.__kernel.saveEntity(pline)
Exemple #12
0
def _xfrm_point(pt, objdict, cx, cy, ra):
    _layer = pt.getParent()
    _pid = id(pt)
    _np = None
    _x, _y = _calc_coords(pt, cx, cy, ra)
    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)
    return _np
Exemple #13
0
 def createText(self, x, y, h, t):
     """
         Create a Text entitys into the current drawing
     """
     try:
         _text = t.replace('\x00', '').decode('utf8',
                                              'ignore').encode('utf8')
     except:
         self.writeError("createText",
                         "Debug Error Converting in unicode [%s]" % t)
         _text = 'Unable to convert in unicode'
     _p = Point(x, y)
     args = {"TEXT_0": _p, "TEXT_1": _text, "TEXT_2": 0.0, "TEXT_3": ""}
     _tb = Text(args)
     self.__kernel.saveEntity(_tb)
Exemple #14
0
 def toGeometricalEntity(self):
     """
         Convert an entity into a geometrical entity
     """
     from Kernel.initsetting import DRAWIN_ENTITY
     geoEnt = None
     cObjecs = self.getConstructionElements()
     cType = self.getEntityType()
     for key in DRAWIN_ENTITY:
         if DRAWIN_ENTITY[key] == cType:
             if cType == "POINT":
                 geoEnt = Point(cObjecs["POINT_0"], cObjecs["POINT_1"])
             else:
                 geoEnt = key(cObjecs)
             break
     return geoEnt
Exemple #15
0
    def testFillet2(self):
        newDoc = self.__pyCadApplication.ActiveDocument
        intPoint = Point(0, 0)
        args = {"SEGMENT_0": intPoint, "SEGMENT_1": Point(1000, 1000)}
        s1 = Segment(args)
        args = {"SEGMENT_0": intPoint, "SEGMENT_1": Point(1000, 0)}
        s2 = Segment(args)

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

        cObject = self.__pyCadApplication.getCommand("FILLET")
        keys = list(cObject.keys())
        cObject[keys[0]] = ent1
        cObject[keys[1]] = ent2
        cObject[keys[2]] = Point(101, 0)
        cObject[keys[3]] = Point(0, 103)
        cObject[keys[4]] = "NO_TRIM"
        cObject[keys[5]] = 20
        cObject.applyCommand()

        cObject = self.__pyCadApplication.getCommand("FILLET")
        keys = list(cObject.keys())
        cObject[keys[0]] = ent1
        cObject[keys[1]] = ent2
        cObject[keys[2]] = Point(101, 0)
        cObject[keys[3]] = Point(0, 103)
        cObject[keys[4]] = "NO_TRIM"
        cObject[keys[5]] = 100
        cObject.applyCommand()

        cObject = self.__pyCadApplication.getCommand("BISECTOR")
        keys = list(cObject.keys())
        cObject[keys[0]] = ent1
        cObject[keys[1]] = ent2
        cObject[keys[2]] = Point(101, 0)
        cObject[keys[3]] = Point(0, 103)
        cObject[keys[4]] = 1000
        cObject.applyCommand()
Exemple #16
0
 def correctPositionForcedDirection(self, point, force):
     """
         correct the point cords 
     """
     if point == None or force == None:
         return None
     x, y = point.getCoords()
     lastSnap = None
     lastSnap = self.getActiveSnapClick()
     if force and lastSnap != None:
         if abs(x - lastSnap.x) > abs(y - lastSnap.y):
             y = lastSnap.y
         else:
             x = lastSnap.x
         #elif self.forceDirection.find("F")>=0:
         #    angle=convertAngle(self.forceDirection.split("F")[1])
         #    if angle:
         #        x=self.lastSnap.x+x
         #        y=self.lastSnap.y+math.cos(angle)*x
     return Point(x, y)
 def getMiddlePoint(self):
     """
         Return the middle point of the segment
     """
     _p1, _p2 = self.getEndpoints()
     _x1 = get_float(_p1.x)
     _x2 = get_float(_p2.x)
     _y1 = get_float(_p1.y)
     _y2 = get_float(_p2.y)
     _deltax = abs(_x1 - _x2) / 2.0
     _deltay = abs(_y1 - _y2) / 2.0
     if (_x1 < _x2):
         retX = _x1 + _deltax
     else:
         retX = _x2 + _deltax
     if (_y1 < _y2):
         retY = _y1 + _deltay
     else:
         retY = _y2 + _deltay
     return Point(retX, retY)
Exemple #18
0
 def mouseMoveEvent(self, event):
     scenePos = event.scenePos()
     mouseOnSceneX = scenePos.x()
     mouseOnSceneY = scenePos.y() * -1.0
     self.geoMousePointOnScene = Point(mouseOnSceneX, mouseOnSceneY)
     #
     # This event manages middle mouse button PAN
     #
     if self.isInPan:
         self.firePan(None, event.scenePos())
     #
     #This event manages the status bar coordinates display (relative or absolute depending on self.fromPoint)
     #
     else:
         if self.fromPoint == None:
             self.fireCoords(mouseOnSceneX, mouseOnSceneY, "abs")
         else:
             x = mouseOnSceneX - self.fromPoint.getx()
             y = mouseOnSceneY - self.fromPoint.gety()
             self.fireCoords(x, y, "rel")
     #
     #This seems needed to preview commands
     #
     ps = self.geoMousePointOnScene
     if self.activeICommand:
         #SNAP PREVIEW
         if self.activeKernelCommand.activeException(
         ) == ExcPoint or self.activeKernelCommand.activeException(
         ) == ExcLenght:
             item = self.activeICommand.getEntity(ps)
             if item:
                 ps = self.snappingPoint.getSnapPoint(
                     self.geoMousePointOnScene, item)
                 if ps != self.geoMousePointOnScene:
                     self.endMark.move(ps.getx(), ps.gety() * -1.0)
             else:
                 self.hideSnapMarks()
         qtItem = [self.itemAt(scenePos)]
         self.activeICommand.updateMauseEvent(ps, qtItem)
     super(CadScene, self).mouseMoveEvent(event)
     return
Exemple #19
0
 def mouseReleaseEvent(self, event):
     if event.button() == QtCore.Qt.MidButton:
         self.isInPan = False
         self.firePan(False, None)
     if not self.isInPan:
         self.updateSelected()
         qtItems = [item for item in self.selectedItems() if isinstance(item, BaseEntity)]
         if self.activeICommand:
             if event.button() == QtCore.Qt.RightButton:
                 try:
                     self.activeICommand.applyCommand()
                 except PyCadWrongImputData:
                     self.fireWarning("Wrong input value")
                 super(CadScene, self).mouseReleaseEvent(event)
                 return
                 
             if event.button() == QtCore.Qt.LeftButton:
                 point = None
                 if self.showHandler:
                     if self.posHandler == None:
                         self.posHandler = PositionHandler(event.scenePos())
                         self.addItem(self.posHandler)
                         return
                     else:
                         self.posHandler.show()
                         return
                 if point == None:
                     point = Point(event.scenePos().x(), event.scenePos().y() * -1.0)
                 # fire the mouse to the ICommand class
                 self.activeICommand.addMauseEvent(point=point, entity=qtItems, force=self.forceDirection)
         else:
             self.hideHandler()
             
     if self._cmdZoomWindow:
         self.zoomWindows(self.selectionArea().boundingRect())
         self._cmdZoomWindow = None
         self.clearSelection()  # clear the selection after the window zoom, why? because zoom windows select entities_>that's bad
         
     super(CadScene, self).mouseReleaseEvent(event)
     return
Exemple #20
0
    def mouseMoveEvent(self, event):
        scenePos = event.scenePos()
        self.mouseOnSceneX = scenePos.x()
        self.mouseOnSceneY = scenePos.y() * -1.0
        #
        #This event manages middle mouse button PAN
        #
        if self.isInPan:
            self.firePan(None, event.scenePos())
        #
        #This event manages the status bar coordinates display (relative or absolute depending on self.fromPoint)
        #
        else:
            if self.fromPoint == None:
                self.fireCoords(scenePos.x(), (scenePos.y() * -1.0), "abs")
            else:
                x = scenePos.x() - self.fromPoint.getx()
                y = scenePos.y() * -1.0 - self.fromPoint.gety()
                self.fireCoords(x, y, "rel")
        #
        #This seems needed to preview commands
        #
            if self.activeICommand:
                # scenePos = event.scenePos()
                distance = None
                point = Point(scenePos.x(), scenePos.y() * -1.0)
                qtItem = [self.itemAt(scenePos, QtGui.QTransform())]
                if self.__oldClickPoint:
                    distance = self.getDistance(event)
                self.activeICommand.updateMauseEvent(point, distance, qtItem)

#            self.updatePreview(self,point, distance)
        #
#        path=QtGui.QPainterPath()
#        path.addRect(scenePos.x()-self.__grapWithd/2, scenePos.y()+self.__grapWithd/2, self.__grapWithd, self.__grapWithd)
#        self.setSelectionArea(path)
        #
        super(CadScene, self).mouseMoveEvent(event)
        return 
Exemple #21
0
 def nearestSnapPoint(self,
                      qtPointEvent,
                      snapForceType=None,
                      fromEntity=None):
     """
         compute the nearest point and return a qtPoint
     """
     pClick = Point(qtPointEvent.x(), qtPointEvent.y() * -1.0)
     ePoint = None
     for p in self.geoItem.getUpdatedSnapPoints(snapForceType, pClick,
                                                fromEntity):
         distance = p.dist(pClick)
         if ePoint == None:
             oldDistance = distance
             ePoint = p
         else:
             if oldDistance > distance:
                 oldDistance = distance
                 ePoint = p
     if ePoint == None:
         return qtPointEvent
     return QtCore.QPointF(ePoint.x, ePoint.y * -1.0)
Exemple #22
0
    def trim(self):
        """
            test the trim command
        """
        newDoc = self.__pyCadApplication.ActiveDocument

        sArg1 = {"SEGMENT_0": Point(0, 0), "SEGMENT_1": Point(150, 0)}
        _st1 = Segment(sArg1)
        newSeg1 = newDoc.saveEntity(_st1)

        sArg2 = {"SEGMENT_0": Point(200, 0), "SEGMENT_1": Point(200, 150)}
        _st2 = Segment(sArg2)
        newSeg2 = newDoc.saveEntity(_st2)
        trimCmd = self.__pyCadApplication.getCommand('TRIM')

        keys = list(trimCmd.keys())
        trimCmd[keys[0]] = newSeg1.getId()
        trimCmd[keys[1]] = newSeg2.getId()
        trimCmd[keys[2]] = Point(140, 1)
        trimCmd[keys[3]] = Point(210, 1)
        trimCmd[keys[4]] = "B"
        trimCmd.applyCommand()
Exemple #23
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)
Exemple #24
0
 def point(self):
     """
           Return The Point 
     """
     return Point(self.X, self.Y)
Exemple #25
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()
Exemple #26
0
 def clone(self):
     """
         Create an identical copy of a Point.
     """
     return Point(self.__x, self.__y)
Exemple #27
0
    def decodeText(self, value):
        """
            encode the text given from the user
        """       
        point = None
        distance = None
        entitys = None
        text = None
        angle = None
        try:
            try:
                raise self.kernelCommand.activeException()(None)
            except ExcPoint:
                if value.find(',') > -1:  # ABSOLUTE CARTESIAN INPUT
                    x, y = value.split(',')
                    point = Point(float(x), float(y))
                elif value.find('*') > -1:    # RELATIVE CARTESIAN INPUT
                    x, y = value.split('*')
                    x = self.scene.fromPoint.getx() + float(x)
                    y = self.scene.fromPoint.gety() + float(y)
                    point = Point(x, y)
                    # implement here relative coordinates
                elif value.find('<') > -1:
                    pass
                    # implement here polar coordinates
                else:  # DISTANCE+ANGLE FROM SCENE set coordinate based on distance input and angle from mouse position on the scene
                    d = float(value)

                    pX = self.scene.mouseOnSceneX
                    pY = self.scene.mouseOnSceneY
                    
                    if self.scene.forceDirection is not None:
                        pc = Point(pX, pY)
                        pc = self.correctPositionForcedDirection(pc, self.scene.forceDirection)
                        pX, pY = pc.getCoords()
                        
                    # if frompoint is not none else exception
                    dx = pX - self.scene.fromPoint.getx()
                    dy = pY - self.scene.fromPoint.gety()

                    a = math.atan2(dy, dx)
                        
                    x = self.scene.fromPoint.getx() + d * math.cos(a)
                    y = self.scene.fromPoint.gety() + d * math.sin(a)
                            
                    point = Point(x, y)
                        
            except (ExcEntity, ExcMultiEntity):
                entitys = self.getIdsString(value)
            except ExcEntityPoint:
                #(4@10,20)
                id, p = value.split('@')
                x, y = p.split(',')
                point = Point(float(x), float(y))
                entitys = self.getIdsString(id)
                return
            except (ExcLenght, ExcInt, ExcBool):
                distance = value
            except(ExcAngle):
                angle = value
            except(ExcText):
                text = value
        except:
            raise PyCadWrongImputData("BaseCommand : Wrong imput parameter for the command")
        return (point,entitys, distance,angle, text)
Exemple #28
0
 def getClickedPoint(self, point, entity, force=None):
     """
         Get segment snapPoints
         Remarks:
         force:      [initsetting.SNAP_POINT_ARRAY element]
         fromPoint:  [Geoent.Pointfloat]
         fromEnt:    [GeoEnt.*]
     """
     snapPoint = point
     point = self.correctPositionForcedDirection(point, force)
     if point != None:
         snapPoint = point
     lastSnapType = self.getLastForceSnap()
     if SNAP_POINT_ARRAY["MID"] == self.activeSnap:
         snapPoint = self.getSnapMiddlePoint(entity)
         if lastSnapType:  # Calculete in case of before constraint
             if lastSnapType == SNAP_POINT_ARRAY["ORTO"]:
                 snapPoint = self.getSnapOrtoPoint(snapPoint)
             elif lastSnapType == SNAP_POINT_ARRAY["TANGENT"]:
                 snapPoint = self.getSnapTangentPoint(snapPoint)
     elif SNAP_POINT_ARRAY["END"] == self.activeSnap:
         snapPoint = self.getSnapEndPoint(entity, point)
         if lastSnapType:  # Calculete in case of before constraint
             if lastSnapType == SNAP_POINT_ARRAY["ORTO"]:
                 snapPoint = self.getSnapOrtoPoint(snapPoint)
             elif lastSnapType == SNAP_POINT_ARRAY["TANGENT"]:
                 snapPoint = self.getSnapTangentPoint(snapPoint)
     elif SNAP_POINT_ARRAY["ORTO"] == self.activeSnap:
         if lastSnapType:
             if lastSnapType == SNAP_POINT_ARRAY["TANGENT"]:
                 snapPoint = self.getTangentOrtoSnap(entity)
             else:
                 snapPoint = self.getPointOrtoSnap(entity)
     elif SNAP_POINT_ARRAY["CENTER"] == self.activeSnap:
         snapPoint = self.getSnapCenterPoint(entity)
         if lastSnapType:  # Calculete in case of before constraint
             if lastSnapType == SNAP_POINT_ARRAY["ORTO"]:
                 snapPoint = self.getSnapOrtoPoint(snapPoint)
             elif lastSnapType == SNAP_POINT_ARRAY["TANGENT"]:
                 snapPoint = self.getSnapTangentPoint(snapPoint)
     elif SNAP_POINT_ARRAY["QUADRANT"] == self.activeSnap:
         snapPoint = self.getSnapQuadrantPoint(entity, snapPoint)
         if lastSnapType:  #Calculete in case of before constraint
             if lastSnapType == SNAP_POINT_ARRAY["ORTO"]:
                 snapPoint = self.getSnapOrtoPoint(snapPoint)
             elif lastSnapType == SNAP_POINT_ARRAY["TANGENT"]:
                 snapPoint = self.getSnapTangentPoint(snapPoint)
     elif SNAP_POINT_ARRAY["ORIG"] == self.activeSnap:
         snapPoint = Point(0.0, 0.0)
     elif SNAP_POINT_ARRAY["INTERSECTION"] == self.activeSnap:
         snapPoint = self.getIntersection(entity, snapPoint)
     elif SNAP_POINT_ARRAY["ALL"] == self.activeSnap:
         snapPoints = []
         pnt = self.getSnapMiddlePoint(entity)
         if pnt != None:
             snapPoints.append(pnt)
         pnt = self.getSnapEndPoint(entity, snapPoint)
         if pnt != None:
             snapPoints.append(pnt)
         outPoint = (None, None)
         for p in snapPoints:
             if p != None:
                 distance = p.dist(snapPoint)
                 if outPoint[0] == None:
                     outPoint = (p, distance)
                 else:
                     if outPoint[1] > distance:
                         outPoint = (p, distance)
         else:
             if outPoint[0] != None:
                 snapPoint = outPoint[0]
     #
     # Reset to snap all
     #
     self.activeSnap = SNAP_POINT_ARRAY["ALL"]
     #
     if snapPoint == None:
         self.__scene.fromPoint = point
         return point
     self.__scene.fromPoint = snapPoint
     return snapPoint
Exemple #29
0
    def getSnapPoint(self, point, entity):
        """
            Get snapPoints
            Remarks:
            force:      [initsetting.SNAP_POINT_ARRAY element]
            fromPoint:  [Geoent.Pointfloat]
            fromEnt:    [GeoEnt.*]
        """
        def pointReturn(pointCalculated, realPoint):
            if pointCalculated == None:
                return realPoint
            return pointCalculated

        if self.activeSnap == SNAP_POINT_ARRAY["NONE"]:
            return point
        else:
            snapPoint = point
            if SNAP_POINT_ARRAY["MID"] == self.activeSnap:
                return pointReturn(self.getSnapMiddlePoint(entity), point)
            elif SNAP_POINT_ARRAY["END"] == self.activeSnap:
                return pointReturn(self.getSnapEndPoint(entity, point), point)
            elif SNAP_POINT_ARRAY["ORTHO"] == self.activeSnap:
                return pointReturn(self.getSnapOrtoPoint(entity, point), point)
            elif SNAP_POINT_ARRAY["CENTER"] == self.activeSnap:
                return pointReturn(self.getSnapCenterPoint(entity), point)
            elif SNAP_POINT_ARRAY["QUADRANT"] == self.activeSnap:
                return pointReturn(
                    self.getSnapQuadrantPoint(entity, snapPoint), point)
            elif SNAP_POINT_ARRAY["ORIG"] == self.activeSnap:
                return Point(0.0, 0.0)
            elif SNAP_POINT_ARRAY["INTERSECTION"] == self.activeSnap:
                return pointReturn(self.getIntersection(entity, snapPoint),
                                   point)
            elif SNAP_POINT_ARRAY["LIST"] == self.activeSnap:
                #TODO: this should be used when checklist of snap will be enabled
                snapPoints = []
                if ACTIVE_SNAP_LIST.count(SNAP_POINT_ARRAY["MID"]) > 0:
                    pnt = self.getSnapMiddlePoint(entity)
                    if pnt != None:
                        snapPoints.append(pnt)

                if ACTIVE_SNAP_LIST.count(SNAP_POINT_ARRAY["END"]) > 0:
                    pnt = self.getSnapEndPoint(entity, snapPoint)
                    if pnt != None:
                        snapPoints.append(pnt)

                if ACTIVE_SNAP_LIST.count(SNAP_POINT_ARRAY["QUADRANT"]) > 0:
                    pnt = self.getSnapQuadrantPoint(entity, snapPoint)
                    if pnt != None:
                        snapPoints.append(pnt)

                if ACTIVE_SNAP_LIST.count(SNAP_POINT_ARRAY["ORTHO"]) > 0:
                    pnt = self.getSnapOrtoPoint(entity, snapPoint)
                    if pnt != None:
                        snapPoints.append(pnt)

                if ACTIVE_SNAP_LIST.count(
                        SNAP_POINT_ARRAY["INTERSECTION"]) > 0:
                    pnt = self.getIntersection(entity, snapPoint)
                    if pnt != None:
                        snapPoints.append(pnt)

                outPoint = (None, None)
                for p in snapPoints:
                    if p != None:
                        distance = p.dist(snapPoint)
                        if outPoint[0] == None:
                            outPoint = (p, distance)
                        else:
                            if outPoint[1] > distance:
                                outPoint = (p, distance)
                else:
                    if outPoint[0] != None:
                        snapPoint = outPoint[0]
            return pointReturn(snapPoint, point)
Exemple #30
0
    def decodeText(self, value):
        """
            encode the text given from the user
        """
        point = None
        distance = None
        entitys = None
        text = None
        angle = None
        try:
            try:
                raise self.kernelCommand.activeException()(None)
            except ExcPoint:
                if value.find(',') > -1:  # ABSOLUTE CARTESIAN INPUT
                    x, y = value.split(',')
                    point = Point(float(x), float(y))
                elif value.find('*') > -1:  # RELATIVE CARTESIAN INPUT
                    x, y = value.split('*')
                    x = self.scene.fromPoint.getx() + float(x)
                    y = self.scene.fromPoint.gety() + float(y)
                    point = Point(x, y)
                    # implement here relative coordinates
                elif value.find('<') > -1:
                    pass
                    # implement here polar coordinates
                else:  # DISTANCE+ANGLE FROM SCENE set coordinate based on distance input and angle from mouse position on the scene
                    d = float(value)

                    pX = self.scene.mouseOnSceneX
                    pY = self.scene.mouseOnSceneY

                    if self.scene.forceDirection is not None:
                        pc = Point(pX, pY)
                        pc = self.correctPositionForcedDirection(
                            pc, self.scene.forceDirection)
                        pX, pY = pc.getCoords()

                    # if frompoint is not none else exception
                    dx = pX - self.scene.fromPoint.getx()
                    dy = pY - self.scene.fromPoint.gety()

                    a = math.atan2(dy, dx)

                    x = self.scene.fromPoint.getx() + d * math.cos(a)
                    y = self.scene.fromPoint.gety() + d * math.sin(a)

                    point = Point(x, y)

            except (ExcEntity, ExcMultiEntity):
                entitys = self.getIdsString(value)
            except ExcEntityPoint:
                #(4@10,20)
                id, p = value.split('@')
                x, y = p.split(',')
                point = Point(float(x), float(y))
                entitys = self.getIdsString(id)
                return
            except (ExcLenght, ExcInt, ExcBool):
                distance = value
            except (ExcAngle):
                angle = value
            except (ExcText):
                text = value
        except:
            raise PyCadWrongImputData(
                "BaseCommand : Wrong imput parameter for the command")
        return (point, entitys, distance, angle, text)
Exemple #31
0
 def applyCommand(self):
     if len(self.value)!=1:
         raise PyCadWrongImputData("Wrong number of input parameter")
     point=Point(self.value[0])
     self.document.saveEntity(point)
Exemple #32
0
    def multitest(self):
        p1 = Point(0, 0)
        p2 = Point(10, 0)
        p3 = Point(0, 10)
        pp1 = Point(1, 0)
        pp2 = Point(0, 3)
        self.testBisector(p1, p2, p3, pp1, pp2)
        self.testFillet(p1, p2, p3, pp1, pp2)

        p1 = Point(0, 0)
        p2 = Point(-10, 0)
        p3 = Point(0, 10)
        pp1 = Point(-1, 0)
        pp2 = Point(0, 3)
        self.testBisector(p1, p2, p3, pp1, pp2)
        self.testFillet(p1, p2, p3, pp1, pp2)

        p1 = Point(0, 0)
        p2 = Point(-10, 0)
        p3 = Point(0, -10)
        pp1 = Point(-1, 0)
        pp2 = Point(0, -3)
        self.testBisector(p1, p2, p3, pp1, pp2)
        self.testFillet(p1, p2, p3, pp1, pp2)

        p1 = Point(0, 0)
        p2 = Point(10, 0)
        p3 = Point(0, -10)
        pp1 = Point(1, 0)
        pp2 = Point(0, -3)
        self.testBisector(p1, p2, p3, pp1, pp2)
        self.testFillet(p1, p2, p3, pp1, pp2)

        p1 = Point(100, 0)
        p2 = Point(200, 0)
        p3 = Point(200, 100)
        pp1 = Point(110, -1)
        pp2 = Point(112, 30)
        self.testBisector(p1, p2, p3, pp1, pp2)
        self.testFillet(p1, p2, p3, pp1, pp2)

        p1 = Point(100, 100)
        p2 = Point(200, 0)
        p3 = Point(200, 100)
        pp1 = Point(110, -1)
        pp2 = Point(112, 30)
        self.testBisector(p1, p2, p3, pp1, pp2, 30)
        self.testFillet(p1, p2, p3, pp1, pp2, 30)