-
Notifications
You must be signed in to change notification settings - Fork 0
/
geocollector.py
182 lines (149 loc) · 4.94 KB
/
geocollector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
from geometry.point import Point
from geometry.curves.line import Line
from geometry.curves.polyline import Polyline
from geometry.curves.cubicspline import CubicSpline
from geometry.curves.circle import Circle
from geometry.curves.circlearc import CircleArc
from geometry.curves.ellipse import Ellipse
from geometry.curves.ellipsearc import EllipseArc
import math
class GeoCollector:
def __init__(self):
self.geo = None
self.prevPt = None
self.tempPt = None
self.geoType = None # POINT, LINE, POLYLINE...
def __del__(self):
if self.geo is not None:
del self.geo
def setGeoType(self, _type):
self.geoType = _type
def getGeoType(self):
return self.geoType
def startGeoCollection(self):
if self.geo is not None:
del self.geo
if self.geoType == 'LINE':
self.geo = Line()
elif self.geoType == 'POLYLINE':
self.geo = Polyline()
elif self.geoType == 'CUBICSPLINE':
self.geo = CubicSpline()
elif self.geoType == 'CIRCLE':
self.geo = Circle()
elif self.geoType == 'CIRCLEARC':
self.geo = CircleArc()
elif self.geoType == 'ELLIPSE':
self.geo = Ellipse()
elif self.geoType == 'ELLIPSEARC':
self.geo = EllipseArc()
def endGeoCollection(self):
self.geo = None
self.tempPt = None
def isActive(self):
if self.geo is not None:
return True
return False
def isCollecting(self):
if self.geo is not None:
if self.geo.getNumberOfCtrlPoints() > 0:
return True
return False
def hasFinished(self):
if self.geo is not None:
if self.geo.isPossible():
return True
return False
def isUnlimited(self):
if self.geo is not None:
if self.geo.isUnlimited():
return True
return False
def insertPoint(self, _x, _y, _LenAndAng, _tol):
if self.isCollecting():
if self.prevPt is not None:
if (abs(_x - self.prevPt.getX()) <= _tol and
abs(_y - self.prevPt.getY()) <= _tol):
return 0
self.geo.buildCurve(_x, _y, _LenAndAng)
if self.prevPt is None:
self.prevPt = Point(_x, _y)
else:
self.prevPt.setCoords(_x, _y)
self.tempPt = None
return 1
def addTempPoint(self, _x, _y):
if self.tempPt is None:
self.tempPt = Point(_x, _y)
else:
self.tempPt.setCoords(_x, _y)
return 1
def getCollectedGeo(self):
return self.geo
def getDrawPoints(self):
if self.geo is None:
return []
if self.tempPt is None:
return []
return self.geo.getEquivPolylineCollecting(self.tempPt)
def getPoints(self):
if self.geo is None:
ctrlPts = []
else:
ctrlPts = self.geo.getCtrlPoints()
if ctrlPts == []:
pts = []
else:
pts = ctrlPts.copy()
if self.tempPt is not None:
pts.append(self.tempPt)
return pts
def getBoundBox(self):
if self.geo is None:
return
return self.geo.getBoundBox()
def reset(self):
self.geo = None
def kill(self):
if self.geo is not None:
del self.geo
del self
def SnaptoCurrentSegment(self, _x, _y, _tol):
if not self.geo.isUnlimited():
return False, _x, _y
pts = self.geo.getCtrlPoints()
if len(pts) < 3:
return False, _x, _y
snap = False
dmin = _tol
for i in range(0, len(pts)):
pt_x = pts[i].getX()
pt_y = pts[i].getY()
d = math.sqrt((_x-pt_x)*(_x-pt_x)+(_y-pt_y)*(_y-pt_y))
if d < dmin:
xmin = pt_x
ymin = pt_y
dmin = d
snap = True
if snap:
return True, xmin, ymin
else:
status, clstPt, dist, t, tangVec = self.geo.closestPoint(_x, _y)
if not status:
return False, _x, _y
if dist < dmin:
dmin = dist
xmin = clstPt.getX()
ymin = clstPt.getY()
return True, xmin, ymin
else:
return False, _x, _y
def CurrentNumberOfControlPoints(self):
try:
NumCtrlPts = self.geo.nPts
except:
NumCtrlPts = 0
return NumCtrlPts
def updateCollectingPntInfo(self, _x, _y, _LenAndAng):
refPtX, refPtY, v1, v2 = self.geo.updateCollectingPntInfo(_x, _y, _LenAndAng)
return refPtX, refPtY, v1, v2