Beispiel #1
0
def updateSegment(objSegment, objPoint, objInterPoint):
    """
            Return a segment with trimed to the intersection point
        """
    from Kernel.GeoEntity.segment import Segment
    from Kernel.GeoEntity.point import Point
    from Kernel.GeoUtil.geolib import Vector

    objProjection = objSegment.getProjection(objPoint)
    _p1, _p2 = objSegment.getEndpoints()
    if not (_p1 == objInterPoint or _p2 == objInterPoint):
        pickIntVect = Vector(objInterPoint, objProjection).mag()
        p1IntVect = Vector(objInterPoint, _p1).mag()
        if (pickIntVect == p1IntVect):
            arg = {"SEGMENT_0": _p1, "SEGMENT_1": objInterPoint}
            return Segment(arg)
        p2IntVect = Vector(objInterPoint, _p2).mag()
        if (pickIntVect == p2IntVect):
            arg = {"SEGMENT_0": objInterPoint, "SEGMENT_1": _p2}
            return Segment(arg)
    ldist = objProjection.dist(_p1)
    if ldist > objProjection.dist(_p2):
        arg = {"SEGMENT_0": _p1, "SEGMENT_1": objInterPoint}
        return Segment(arg)
    else:
        arg = {"SEGMENT_0": objInterPoint, "SEGMENT_1": _p2}
        return Segment(arg)
Beispiel #2
0
 def getProjection(self,fromPoint):
     """
         get Projection of the point x,y in the line
     """
     p1=self.p1
     p2=self.p2
     v=Vector(p1,p2)
     v1=Vector(p1,fromPoint)
     pjPoint=v.map(v1.point).point
     return p1+pjPoint
 def getProjection(self, fromPoint):
     """
         get Projection of the point x,y in the line
     """
     p1 = self.p1
     p2 = self.p2
     v = Vector(p1, p2)
     v1 = Vector(p1, fromPoint)
     pjPoint = v.map(v1.point).point
     return p1 + pjPoint
Beispiel #4
0
 def rotate(self, rotationPoint, angle):
     """
         this method must be defined for rotation
     """
     from Kernel.GeoUtil.geolib import Vector
     from Kernel.GeoEntity.point import Point
     v=Vector(rotationPoint,self)
     v.rotate(angle)
     p=rotationPoint+v.point    
     self.__x=p.x
     self.__y=p.y
Beispiel #5
0
 def rotate(self, rotationPoint, angle):
     """
         this method must be defined for rotation
     """
     from Kernel.GeoUtil.geolib import Vector
     from Kernel.GeoEntity.point import Point
     v = Vector(rotationPoint, self)
     v.rotate(angle)
     p = rotationPoint + v.point
     self.__x = p.x
     self.__y = p.y
Beispiel #6
0
 def rotate(self, rotationPoint, angle):
     """
         this method must be defined for rotation
     """
     from Kernel.GeoUtil.geolib import Vector
     from Kernel.GeoEntity.point import Point
     
     for key in self:
         if isinstance(self[key] , Point):
             v=Vector(rotationPoint,self[key] )
             v.rotate(angle)
             self[key]=rotationPoint+v.point
Beispiel #7
0
 def calculateTextPoint(self):       # TODO : test if the position is ok
     """
         calculate the text position
     """
     t=self.getDimensioLines()
     p1, p2=t[0]
     p1=Point(p1.x(), p1.y())
     v=Vector(p1, Point(p2.x(), p2.y()))
     vm=v.mag()
     vm.mult(v.norm/2)
     pe=p1+vm.point
     return QtCore.QPointF(pe.x, pe.y)
Beispiel #8
0
 def calculateTextPoint(self):  # TODO : test if the position is ok
     """
         calculate the text position
     """
     t = self.getDimensioLines()
     p1, p2 = t[0]
     p1 = Point(p1.x(), p1.y())
     v = Vector(p1, Point(p2.x(), p2.y()))
     vm = v.mag()
     vm.mult(v.norm / 2)
     pe = p1 + vm.point
     return QtCore.QPointF(pe.x, pe.y)
 def rotate(self, rotationPoint, angle):
     """
         this method must be defined for rotation
     """
     from Kernel.GeoUtil.geolib import Vector
     from Kernel.GeoEntity.point import Point
     
     for key in self:
         if isinstance(self[key], Point):
             v = Vector(rotationPoint, self[key])
             v.rotate(angle)
             self[key] = rotationPoint + v.point
Beispiel #10
0
 def mirror(self, mirrorRef):
     """
         perform the mirror of the line
     """
     if not isinstance(mirrorRef, (CLine, Segment)):
         raise TypeError, "mirrorObject must be Cline Segment or a tuple of points"
     #
     startPoint, endPoint = self.getEndpoints()
     self.center.mirror(mirrorRef)
     endMirror = mirrorRef.getProjection(endPoint)
     vEnd = Vector(endPoint, endMirror)
     newStart = endMirror + vEnd.point
     self.startAngle = Vector(self.center, newStart).absAng
Beispiel #11
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()
Beispiel #12
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
Beispiel #13
0
 def updatePreview(self, position, distance, kernelCommand):
     """
         update the data at the preview item
     """
     self.prepareGeometryChange()  #qtCommand for update the scene
     for i in range(0, len(kernelCommand.value)):
         self.value[i] = self.revertToQTObject(kernelCommand.value[i])
     # Assing Command Values
     index = kernelCommand.valueIndex
     try:
         raise kernelCommand.exception[index](None)
     except (ExcPoint):
         self.value[index] = self.revertToQTObject(position)
     except (ExcLenght, ExcInt):
         if not distance or distance != None:
             self.value[index] = distance
     except (ExcAngle):
         p1 = kernelCommand.value[0]
         p2 = GeoPoint(position.x, position.y)
         ang = Vector(p1, p2).absAng
         if index == 3:
             ang = ang - self.value[2]
         self.value[index] = ang
     except:
         print "updatePreview: Exception not managed"
         return
Beispiel #14
0
 def updatePreview(self, position, distance, kernelCommand):
     """
         update the data at the preview item
     """
     # Assing default values
     for i in range(0, len(kernelCommand.exception)):
         if len(self.value) > i:
             self.value[i] = self.convertToQTObject(
                 kernelCommand.defaultValue[i])
         else:
             self.value.append(
                 self.convertToQTObject(kernelCommand.defaultValue[i]))
     # Assing Command Values
     for i in range(0, len(kernelCommand.exception)):
         if (i < len(kernelCommand.value)):
             self.value[i] = self.convertToQTObject(kernelCommand.value[i])
     # Assing mouse keyboard values
     index = kernelCommand.valueIndex
     try:
         raise kernelCommand.exception[index](None)
     except (ExcPoint):
         self.value[index] = position
     except (ExcLenght, ExcInt):
         self.value[index] = distance
     except (ExcAngle):
         p1 = GeoPoint(0.0, 0.0)
         p2 = GeoPoint(position.x(), position.y() * -1.0)
         self.value[index] = Vector(p1, p2).absAng
     except:
         return
     self.update(self.boundingRect())
Beispiel #15
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()
Beispiel #16
0
 def getDimensioLines(self):
     """
         compute all the segment needed for the dimension
     """
     p1p2v = Vector(self.firstPoint, self.secondPoint)
     v = Vector(self.firstPoint, self.thirdPoint)
     pp = self.firstPoint + p1p2v.map(v.point).point
     p3ppv = Vector(pp, self.thirdPoint)
     #
     fp = self.firstPoint + p3ppv.point
     fp = QtCore.QPointF(fp.x, fp.y * -1.0)
     sp = self.secondPoint + p3ppv.point
     sp = QtCore.QPointF(sp.x, sp.y * -1.0)
     #
     fp1 = QtCore.QPointF(self.firstPoint.x, self.firstPoint.y * -1.0)
     sp1 = QtCore.QPointF(self.secondPoint.x, self.secondPoint.y * -1.0)
     #
     return [(fp, sp), (fp, fp1), (sp, sp1)]
Beispiel #17
0
 def move(self, fromPoint, toPoint):
     """
         perform the move operation
     """
     from Kernel.GeoUtil.geolib import Vector
     v = Vector(fromPoint, toPoint)
     p = self + v.point
     self.__x = p.x
     self.__x = p.y
Beispiel #18
0
 def getDimensioLines(self):
     """
         compute all the segment needed for the dimension
     """
     p1p2v=Vector(self.firstPoint, self.secondPoint)
     v=Vector(self.firstPoint,self.thirdPoint)
     pp=self.firstPoint+p1p2v.map(v.point).point
     p3ppv=Vector(pp, self.thirdPoint)
     #
     fp=self.firstPoint+p3ppv.point
     fp=QtCore.QPointF(fp.x, fp.y*-1.0)
     sp=self.secondPoint+p3ppv.point
     sp=QtCore.QPointF(sp.x, sp.y*-1.0)
     #
     fp1=QtCore.QPointF(self.firstPoint.x, self.firstPoint.y*-1.0)
     sp1=QtCore.QPointF(self.secondPoint.x, self.secondPoint.y*-1.0)
     #
     return [(fp, sp), (fp, fp1), (sp, sp1)]
Beispiel #19
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(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()
Beispiel #20
0
 def move(self, fromPoint, toPoint):
     """
         this method must be defined for moving operation
     """
     from Kernel.GeoUtil.geolib import Vector
     from Kernel.GeoEntity.point import Point
     v = Vector(fromPoint, toPoint)
     for key in self:
         if isinstance(self[key], Point):
             self[key] += v.point
     return v.point
Beispiel #21
0
    def calculateAngle(self, snap):
        """
            calculate the angle betwin the point clicked
        """
        if snap == None:
            return None

        for snapPoint in self.__snap:
            if snapPoint != None:
                v = Vector(snapPoint, snap)
                return v.absAng
        else:
            return None
Beispiel #22
0
 def mirror(self, mirrorRef):
     """
         perform the mirror of the line
     """
     from Kernel.GeoEntity.cline import CLine
     from Kernel.GeoEntity.segment import Segment
     from Kernel.GeoUtil.geolib import Vector
     if not isinstance(mirrorRef, (CLine, Segment)):
         raise TypeError, "mirrorObject must be Cline Segment or a tuple of points"
     #
     centerMirror = mirrorRef.getProjection(self)
     vCenter = Vector(self, centerMirror)
     p = centerMirror + vCenter.point
     self.__x, self.__y = p.getCoords()
Beispiel #23
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
Beispiel #24
0
 def getAngledVector(self, segment, point):
     """
         calculate the vector use
     """
     pi = self.intersection[0]
     p1, p2 = segment.getEndpoints()
     vs1 = Vector(pi, p1)
     vs2 = Vector(pi, p2)
     if abs(vs1.absAng - vs2.absAng) < 0.00001:
         if pi.dist(p1) > pi.dist(p2):
             return Vector(pi, p1)
         else:
             return Vector(pi, p2)
     else:
         jp = segment.getProjection(point)
         vj = Vector(pi, jp)
         if abs(vj.absAng - vs1.absAng) < 0.00001:
             return Vector(pi, p1)
         else:
             return Vector(pi, p2)
Beispiel #25
0
 def vector(self):
     """
         Get The vector of the Segment
     """
     return Vector(self.p1, self.p2)
Beispiel #26
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()
Beispiel #27
0
 def getAngle(self):
     """
         Calculate the angle based on the starting and ending point
     """
     v = Vector(self.value[0], self.value[1])
     return v.absAng
Beispiel #28
0
 def vector(self):
     """
         Get The vector of the CLine
     """
     return Vector(self.p1, self.p2)