示例#1
0
 def point2ObjectDistance(self, point):
     dist = 100
     geoCalc = geoMath.GeoMath()
     for pointOnLine in self.freeHandLine:
         pointDist = geoCalc.distBetweenPoints(point, pointOnLine)
         dist = min(dist, pointDist)
     return dist
示例#2
0
 def point2ObjectDistance(self, point):
     dist=100
     geoCalc = geoMath.GeoMath()
     for vertex in range(len(self.polygon)):
         dist2AnEdge = geoCalc.calcDist(point,QLine(self.polygon[vertex], self.polygon[(vertex + 1) % len(self.polygon)]))
         dist = min(dist, dist2AnEdge)
     return dist
示例#3
0
文件: main.py 项目: lhf2011/sketchpad
    def mouseDoubleClickEvent(self, event):
        # double click to cancel choose a group
        if self.shape == "Choose":
            pos = QPoint(event.pos().x(), event.pos().y())
            if self.startQPoint.x() < 0:
                self.startQPoint = pos
            self.endQPoint = pos

            if self.startQPoint.x() < 0:
                return
            for gp in self.groups:
                geoCalc = geoMath.GeoMath()
                dist = geoCalc.minDistOfPoint2RectEdge(self.startQPoint, gp.area)
                if dist < 49:
                    self.groups.remove(gp)
            self.startQPoint = QPoint(-1, -1)
            self.endQPoint = QPoint(-1, -1)
示例#4
0
 def point2ObjectDistance(self, point):
     geoCalc = geoMath.GeoMath()
     dist= geoCalc.distBetweenPoints(point, self.ellipse.center())
     return dist
示例#5
0
 def point2ObjectDistance(self, point):
     geoCalc = geoMath.GeoMath()
     dist = geoCalc.minDistOfPoint2SquareEdge(point, self.square)
     return dist
示例#6
0
 def point2ObjectDistance(self, point):
     geoCalc = geoMath.GeoMath()
     dist= geoCalc.minDistOfPoint2RectEdge(point,self.rectangle)
     return dist
示例#7
0
 def point2ObjectDistance(self, point):
     geoCalc = geoMath.GeoMath()
     dist = geoCalc.calcDist( point=point, line=self.straightLine)
     return dist
示例#8
0
 def point2ObjectDistance(self, point):
     geoCalc = geoMath.GeoMath()
     dist = abs(round(geoCalc.distBetweenPoints(self.circle.center(), point))-self.radius)
     return dist
示例#9
0
文件: main.py 项目: lhf2011/sketchpad
 def mouseReleaseEvent(self, event):
     if self.shape == "Line":
         self.objectIndex=self.objectIndex+1
         self.straightLines.append(
             objectCharacter.StraightLineCha(objIndex=self.objectIndex, objShape="Line", penColor=self.pen.color(),
                                             penWidth=self.pen.width(), penStyle=self.pen.style(),
                                             straightLine=QLine(self.startQPoint, self.endQPoint)))
         self.startQPoint = QPoint(-1, -1)
         self.endQPoint = QPoint(-1, -1)
     if self.shape == "FreeHandLine":
         self.objectIndex = self.objectIndex + 1
         self.freeHandLines.append(
             objectCharacter.FreeHandLineCha(objIndex=self.objectIndex, objShape="FreeHandLine",
                                             penColor=self.pen.color(), penWidth=self.pen.width(),
                                             penStyle=self.pen.style(), freeHandLine=self.freeHandLine))
         self.freeHandLine=[]
     if self.shape == "Rectangle":
         self.objectIndex = self.objectIndex + 1
         self.rects.append(
             objectCharacter.RectangleCha(objIndex=self.objectIndex, objShape="Rectangle", penColor=self.pen.color(),
                                          penWidth=self.pen.width(), penStyle=self.pen.style(),
                                          rectangle=QRect(self.startQPoint, self.endQPoint)))
         self.startQPoint = QPoint(-1, -1)
         self.endQPoint = QPoint(-1, -1)
     if self.shape == "Square":
         self.objectIndex = self.objectIndex + 1
         point1 = self.startQPoint
         point3 = self.endQPoint
         point2 = QPoint(round(((point1.x()+point3.x())+(point3.y()-point1.y()))/2), round(((point1.y()+point3.y())+(point1.x()-point3.x()))/2))
         point4 = QPoint(round(((point1.x()+point3.x())-(point3.y()-point1.y()))/2), round(((point1.y()+point3.y())-(point1.x()-point3.x()))/2))
         self.squares.append(
             objectCharacter.SquareCha(objIndex=self.objectIndex, objShape="Square", penColor=self.pen.color(),
                                       penWidth=self.pen.width(),
                                       penStyle=self.pen.style(), square=[point1, point2, point3, point4]))
         self.startQPoint = QPoint(-1, -1)
         self.endQPoint = QPoint(-1, -1)
     if self.shape == "Ellipse":
         self.objectIndex = self.objectIndex + 1
         self.ellipses.append(
             objectCharacter.EllipseCha(objIndex=self.objectIndex, objShape="Ellipse", penColor=self.pen.color(),
                                        penWidth=self.pen.width(), penStyle=self.pen.style(),
                                        ellipse=QRect(self.startQPoint, self.endQPoint)))
         self.startQPoint = QPoint(-1, -1)
         self.endQPoint = QPoint(-1, -1)
     if self.shape == "Circle":
         self.objectIndex = self.objectIndex + 1
         center=QPoint( round((self.startQPoint.x() + self.endQPoint.x()) / 2), round((self.startQPoint.y() + self.endQPoint.y()) / 2) )
         geoCalc=geoMath.GeoMath()
         squareRadius = round(geoCalc.distBetweenPoints(self.startQPoint, self.endQPoint) / 2)
         topLeftPoint = QPoint( center.x()-squareRadius , center.y()-squareRadius)
         bottomRightPoint = QPoint(center.x() + squareRadius, center.y() + squareRadius)
         boundingRect = QRect(topLeftPoint,bottomRightPoint)
         self.circles.append(
             objectCharacter.CircleCha(objIndex=self.objectIndex, objShape="Circle", penColor=self.pen.color(),
                                       penWidth=self.pen.width(),
                                       penStyle=self.pen.style(), circle=boundingRect,radius=squareRadius))
         self.startQPoint = QPoint(-1, -1)
         self.endQPoint = QPoint(-1, -1)
     if self.shape == "Polygon":
         if len(self.polygon)==0:
             if self.startQPoint.x() < 0 or self.endQPoint.x()<0:
                 return
             self.polygon.append(self.startQPoint)
             self.polygon.append(self.endQPoint)
             self.startQPoint = QPoint(-1, -1)
             self.endQPoint = QPoint(-1, -1)
         else:
             if self.startQPoint.x() < 0 or self.endQPoint.x() < 0:
                 return
             startPointOverlap= False
             endPointOverlap= False
             for polygonPoints in self.polygon:
                 geoCalc= geoMath.GeoMath()
                 startPointOverlap = startPointOverlap or geoCalc.twoPointClose(polygonPoints, self.startQPoint)
                 endPointOverlap = endPointOverlap or geoCalc.twoPointClose(polygonPoints, self.endQPoint)
             if startPointOverlap and endPointOverlap:
                 self.objectIndex = self.objectIndex + 1
                 self.polygons.append(objectCharacter.PolygonCha(objIndex=self.objectIndex, objShape="Polygon",
                                                                 penColor=self.pen.color(),
                                                                 penWidth=self.pen.width(),
                                                                 penStyle=self.pen.style(), polygon=self.polygon))
                 self.polygon = []
                 self.startQPoint = QPoint(-1, -1)
                 self.endQPoint = QPoint(-1, -1)
             elif startPointOverlap:
                 self.polygon.append(self.endQPoint)
                 self.startQPoint = QPoint(-1, -1)
                 self.endQPoint = QPoint(-1, -1)
             else:
                 self.polygon.append(self.startQPoint)
                 self.polygon.append(self.endQPoint)
                 self.startQPoint = QPoint(-1, -1)
                 self.endQPoint = QPoint(-1, -1)
     if self.shape == "Group":
         if self.startQPoint.x() < 0:
             return
         self.objectIndex = self.objectIndex + 1
         chooseArea = QRect(self.startQPoint, self.endQPoint)
         containIndex = [self.objectIndex]
         # loop ellipse
         for elps in self.ellipses:
             if chooseArea.contains(elps.ellipse.center()):
                 containIndex.append(elps.objIndex)
         # loop circle
         for circle in self.circles:
             if chooseArea.contains(circle.circle.center()):
                 containIndex.append(circle.objIndex)
         # loop rectangular
         for rect in self.rects:
             if chooseArea.contains(rect.rectangle.center()):
                 containIndex.append(rect.objIndex)
         # loop square
         for square in self.squares:
             if chooseArea.contains(square.square[0]) and chooseArea.contains(square.square[1]) and chooseArea.contains(square.square[2]) and chooseArea.contains(square.square[3]):
                 containIndex.append(square.objIndex)
         # loop straight line
         for sl in self.straightLines:
             if chooseArea.contains(sl.straightLine.p1()) or chooseArea.contains(sl.straightLine.p2()):
                 containIndex.append(sl.objIndex)
         # loop freehand line
         for fhl in self.freeHandLines:
             if chooseArea.contains(fhl.freeHandLine[0]) or chooseArea.contains(fhl.freeHandLine[-1]):
                 containIndex.append(fhl.objIndex)
         # loop freehand line
         for plg in self.polygons:
             allPointsIncluded = True
             for point in plg.polygon:
                 if not chooseArea.contains(point):
                     allPointsIncluded = False
                     break
             if allPointsIncluded:
                 containIndex.append(plg.objIndex)
         # build group
         self.groups.append(
             objectCharacter.GroupCha(objIndex=self.objectIndex, objShape="Group", penColor=self.pen.color(), penWidth=self.pen.width(),
                      penStyle=Qt.DashDotLine, area=chooseArea, memberIndexes=containIndex))
         self.startQPoint = QPoint(-1, -1)
         self.endQPoint = QPoint(-1, -1)
     if self.shape == "Choose":
         if self.startQPoint.x() < 0:
             return
         self.chooseAnObject(self.startQPoint)
         moveX = self.endQPoint.x() - self.startQPoint.x()
         moveY = self.endQPoint.y() - self.startQPoint.y()
         self.moveObjectMembers(self.chooseObjectIndex, moveX, moveY)
         self.startQPoint = QPoint(-1, -1)
         self.endQPoint = QPoint(-1, -1)