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 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"
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
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)
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)
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 --"
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]
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 --"
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 --"
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 --"
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 --"
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 --"
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 PyCadWrongImputData( "BaseCommand : Wrong imput parameter for the command") finally: return exitValue
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
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)
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()
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
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)
def getRandomPoint(self): """ get e random point """ x = random() * 1000 y = random() * 1000 return Point(x, y)
def hanhlerDoubleClick(self): """ event add from the handler """ point = Point(self.posHandler.scenePos.x(), self.posHandler.scenePos.y() * -1.0) self.activeICommand.addMauseEvent(point = point, distance = posHandler.distance, angle = posHandler.angle) self.hideHandler()
def decodePoint(value, previusPoint=None): """ this static method decode an imput and return a point(mm,mm) """ value = str(value).lower() from Kernel.GeoEntity.point import Point x, y = str(value).split(',') return Point(convertLengh(x), convertLengh(y))
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)
def findSegmentExtendedIntersectionPoint(obja, objb): """ xtend the segment intersection on a cline intersection Return a [Point,Point,..] """ return [ Point(x, y) for x, y in findSegmentExtendedIntersection(obja, objb) ]
def convertToPoint(self, msg): """ ask at the user to imput a point """ if msg: coords = msg.split(',') x = float(coords[0]) y = float(coords[1]) return Point(x, y) return None
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")
def getEntsToSave(self): """ get all the segment of the rectangle """ objEnt = [] p1 = self.value[0] p2 = self.value[1] x1, y1 = p1.getCoords() x2, y2 = p2.getCoords() p3 = Point(x1, y2) p4 = Point(x2, y1) segArg = {"SEGMENT_0": p1, "SEGMENT_1": p4} objEnt.append(Segment(segArg)) segArg = {"SEGMENT_0": p4, "SEGMENT_1": p2} objEnt.append(Segment(segArg)) segArg = {"SEGMENT_0": p2, "SEGMENT_1": p3} objEnt.append(Segment(segArg)) segArg = {"SEGMENT_0": p3, "SEGMENT_1": p1} objEnt.append(Segment(segArg)) return objEnt
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 = list(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()
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 --"
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 --"
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