forked from geosim/QAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qad_arc.py
751 lines (633 loc) · 30 KB
/
qad_arc.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
# -*- coding: utf-8 -*-
"""
/***************************************************************************
QAD Quantum Aided Design plugin
classe per la gestione degli archi
-------------------
begin : 2013-05-22
copyright : iiiii
email : hhhhh
developers : bbbbb aaaaa ggggg
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
import math
import qad_utils
from qad_circle import *
from qad_variables import *
#===============================================================================
# QadArc arc class
#===============================================================================
class QadArc():
def __init__(self, arc = None):
if arc is not None:
self.set(arc.center, arc.radius, arc.startAngle, arc.endAngle)
else:
self.center = None
self.radius = None
self.startAngle = None
self.endAngle = None
def whatIs(self):
return "ARC"
def set(self, center, radius, startAngle, endAngle):
self.center = QgsPoint(center)
self.radius = radius
self.startAngle = startAngle
self.endAngle = endAngle
def transform(self, coordTransform):
"""Transform this geometry as described by CoordinateTranasform ct."""
self.center = coordTransform.transform(self.center)
def transformFromCRSToCRS(self, sourceCRS, destCRS):
"""Transform this geometry as described by CRS."""
if (sourceCRS is not None) and (destCRS is not None) and sourceCRS != destCRS:
coordTransform = QgsCoordinateTransform(sourceCRS, destCRS) # trasformo le coord
self.center = coordTransform.transform(self.center)
def __eq__(self, arc):
"""self == other"""
if self.center != arc.center or self.radius != arc.radius or \
self.startAngle != arc.startAngle or self.endAngle != arc.endAngle:
return False
else:
return True
def __ne__(self, arc):
"""self != other"""
if self.center != arc.center or self.radius != arc.radius or \
self.startAngle != arc.startAngle or self.endAngle != arc.endAngle:
return True
else:
return False
def totalAngle(self):
if self.startAngle < self.endAngle:
return self.endAngle - self.startAngle
else:
return (2 * math.pi - self.startAngle) + self.endAngle
def length(self):
return self.radius * self.totalAngle()
def getStartPt(self):
return qad_utils.getPolarPointByPtAngle(self.center,
self.startAngle,
self.radius)
def setStartAngleByPt(self, pt):
# da usare per modificare un arco già efinito
angle = qad_utils.getAngleBy2Pts(self.center, pt)
if angle == self.endAngle:
return False
else:
self.startAngle = angle
return True
def getEndPt(self):
return qad_utils.getPolarPointByPtAngle(self.center,
self.endAngle,
self.radius)
def setEndAngleByPt(self, pt):
# da usare per modificare un arco già definito
angle = qad_utils.getAngleBy2Pts(self.center, pt)
if angle == self.startAngle:
return False
else:
self.endAngle = angle
return True
def isPtOnArc(self, point):
dist = qad_utils.getDistance(self.center, point)
if qad_utils.doubleNear(self.radius, dist):
angle = qad_utils.getAngleBy2Pts(self.center, point)
return qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle)
else:
return False
def inverse(self):
dummy = self.endAngle
self.endAngle = self.startAngle
self.startAngle = dummy
def getMiddlePt(self):
halfAngle = self.totalAngle() / 2
return qad_utils.getPolarPointByPtAngle(self.center,
self.startAngle + halfAngle,
self.radius)
def getQuadrantPoints(self):
result = []
angle = 0
if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
result.append(QgsPoint(self.center.x() + self.radius, self.center.y()))
angle = math.pi / 2
if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
result.append(QgsPoint(self.center.x(), self.center.y() + self.radius))
angle = math.pi
if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
result.append(QgsPoint(self.center.x() - self.radius, self.center.y()))
angle = math.pi * 3 / 2
if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
result.append(QgsPoint(self.center.x(), self.center.y() - self.radius))
return result
#============================================================================
# getTanPoints
#============================================================================
def getTanPoints(self, point):
result = []
circle = QadCircle()
circle.set(self.center, self.radius)
points = circle.getTanPoints(point)
tot = len(points)
for p in points:
angle = qad_utils.getAngleBy2Pts(self.center, p)
if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
result.append(p)
return result
#============================================================================
# getTanDirectionOnPt
#============================================================================
def getTanDirectionOnPt(self, pt):
angle = qad_utils.getAngleBy2Pts(self.center, pt)
return qad_utils.normalizeAngle(angle + math.pi / 2)
#============================================================================
# getTanDirectionOnStartPt
#============================================================================
def getTanDirectionOnStartPt(self):
return self.getTanDirectionOnPt(self.getStartPt())
#============================================================================
# getTanDirectionOnEndPt
#============================================================================
def getTanDirectionOnEndPt(self):
return self.getTanDirectionOnPt(self.getEndPt())
#============================================================================
# getPerpendicularPoints
#============================================================================
def getPerpendicularPoints(self, point):
result = []
angle = qad_utils.getAngleBy2Pts(self.center, point)
if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
result.append( qad_utils.getPolarPointByPtAngle(self.center,
angle,
self.radius))
angle = angle + math.pi
if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
result.append( qad_utils.getPolarPointByPtAngle(self.center,
angle,
self.radius))
return result
#============================================================================
# getIntersectionPointsWithInfinityLine
#============================================================================
def getIntersectionPointsWithInfinityLine(self, p1, p2):
result = []
circle = QadCircle()
circle.set(self.center, self.radius)
intPtList = circle.getIntersectionPointsWithInfinityLine(p1, p2)
for intPt in intPtList:
if self.isPtOnArc(intPt):
result.append(intPt)
return result
#============================================================================
# getIntersectionPointsWithSegment
#============================================================================
def getIntersectionPointsWithSegment(self, p1, p2):
result = []
intPtList = self.getIntersectionPointsWithInfinityLine(p1, p2)
for intPt in intPtList:
if qad_utils.isPtOnSegment(p1, p2, intPt):
result.append(intPt)
return result
#============================================================================
# getIntersectionPointsWithCircle
#============================================================================
def getIntersectionPointsWithCircle(self, circle):
result = []
circle1 = QadCircle()
circle1.set(self.center, self.radius)
intPtList = circle1.getIntersectionPointsWithCircle(circle)
for intPt in intPtList:
if self.isPtOnArc(intPt):
result.append(intPt)
return result
#============================================================================
# getIntersectionPointsWithArc
#============================================================================
def getIntersectionPointsWithArc(self, arc):
result = []
circle = QadCircle()
circle.set(arc.center, arc.radius)
intPtList = self.getIntersectionPointsWithCircle(circle)
for intPt in intPtList:
if arc.isPtOnArc(intPt):
result.append(intPt)
return result
#============================================================================
# asPolyline
#============================================================================
def asPolyline(self, tolerance2ApproxCurve = None, atLeastNSegment = None):
"""
ritorna una lista di punti che definisce l'arco
"""
if tolerance2ApproxCurve is None:
tolerance = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
else:
tolerance = tolerance2ApproxCurve
if atLeastNSegment is None:
_atLeastNSegment = QadVariables.get(QadMsg.translate("Environment variables", "ARCMINSEGMENTQTY"), 12)
else:
_atLeastNSegment = atLeastNSegment
# Calcolo la lunghezza del segmento con pitagora
dummy = self.radius - tolerance
if dummy <= 0: # se la tolleranza é troppo bassa rispetto al raggio
SegmentLen = self.radius
else:
dummy = (self.radius * self.radius) - (dummy * dummy)
SegmentLen = math.sqrt(dummy) # radice quadrata
SegmentLen = SegmentLen * 2
if SegmentLen == 0: # se la tolleranza é troppo bassa la lunghezza del segmento diventa zero
return None
# calcolo quanti segmenti ci vogliono (non meno di _atLeastNSegment)
SegmentTot = math.ceil(self.length() / SegmentLen)
if SegmentTot < _atLeastNSegment:
SegmentTot = _atLeastNSegment
points = []
# primo punto
pt = qad_utils.getPolarPointByPtAngle(self.center, self.startAngle, self.radius)
points.append(pt)
i = 1
angle = self.startAngle
offSetAngle = self.totalAngle() / SegmentTot
while i < SegmentTot:
angle = angle + offSetAngle
pt = qad_utils.getPolarPointByPtAngle(self.center, angle, self.radius)
points.append(pt)
i = i + 1
# ultimo punto
pt = qad_utils.getPolarPointByPtAngle(self.center, self.endAngle, self.radius)
points.append(pt)
return points
#============================================================================
# fromStartSecondEndPts
#============================================================================
def fromStartSecondEndPts(self, startPt, secondPt, endPt):
"""
setta le caratteristiche dell'arco attraverso:
punto iniziale
secondo punto (intermedio)
punto finale
"""
points = [startPt, secondPt, endPt]
# lista di punti, parte dal punto 0, almeno 2 segmenti
if self.fromPolyline(points, 0, 2) is None:
return False
else:
return True
#============================================================================
# fromStartCenterEndPts
#============================================================================
def fromStartCenterEndPts(self, startPt, centerPt, endPt):
"""
setta le caratteristiche dell'arco attraverso:
punto iniziale
centro
punto finale
"""
if startPt == centerPt or startPt == endPt or endPt == centerPt:
return False
self.center = centerPt
self.radius = qad_utils.getDistance(centerPt, startPt)
self.startAngle = qad_utils.getAngleBy2Pts(centerPt, startPt)
self.endAngle = qad_utils.getAngleBy2Pts(centerPt, endPt)
return True
#============================================================================
# fromStartCenterPtsAngle
#============================================================================
def fromStartCenterPtsAngle(self, startPt, centerPt, angle):
"""
setta le caratteristiche dell'arco attraverso:
punto iniziale
centro
angolo inscritto
"""
if startPt == centerPt or angle == 0:
return False
self.center = centerPt
self.radius = qad_utils.getDistance(centerPt, startPt)
self.startAngle = qad_utils.getAngleBy2Pts(centerPt, startPt)
self.endAngle = self.startAngle + angle
if self.endAngle > math.pi * 2:
self.endAngle = self.endAngle % (math.pi * 2) # modulo
return True
#============================================================================
# fromStartCenterPtsChord
#============================================================================
def fromStartCenterPtsChord(self, startPt, centerPt, chord):
"""
setta le caratteristiche dell'arco attraverso:
punto iniziale
centro
lunghezza dela corda tra punto iniziale e finale
"""
if startPt == centerPt or chord == 0:
return False
self.center = centerPt
self.radius = qad_utils.getDistance(centerPt, startPt)
if chord > 2 * self.radius:
return False
self.startAngle = qad_utils.getAngleBy2Pts(centerPt, startPt)
# Teorema della corda
angle = 2 * math.asin(chord / (2 * self.radius))
self.endAngle = self.startAngle + angle
return True
#============================================================================
# fromStartEndPtsAngle
#============================================================================
def fromStartEndPtsAngle(self, startPt, endPt, angle):
"""
setta le caratteristiche dell'arco attraverso:
punto iniziale
punto finale
angolo inscritto
"""
if startPt == endPt or angle == 0:
return False
chord = qad_utils.getDistance(startPt, endPt)
half_chord = chord / 2
# Teorema della corda
self.radius = half_chord / math.sin(angle / 2)
angleSegment = qad_utils.getAngleBy2Pts(startPt, endPt)
ptMiddle = qad_utils.getMiddlePoint(startPt, endPt)
# Pitagora
distFromCenter = math.sqrt((self.radius * self.radius) - (half_chord * half_chord))
if angle < math.pi: # se angolo < 180 gradi
# aggiungo 90 gradi per cercare il centro a sinistra del segmento
self.center = qad_utils.getPolarPointByPtAngle(ptMiddle,
angleSegment + (math.pi / 2),
distFromCenter)
else:
# sottraggo 90 gradi per cercare il centro a destra del segmento
self.center = qad_utils.getPolarPointByPtAngle(ptMiddle,
angleSegment - (math.pi / 2),
distFromCenter)
self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt)
self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt)
return True
#============================================================================
# fromStartEndPtsTan
#============================================================================
def fromStartEndPtsTan(self, startPt, endPt, tan):
"""
setta le caratteristiche dell'arco attraverso:
punto iniziale
punto finale
direzione della tangente sul punto iniziale
"""
if startPt == endPt:
return False
angleSegment = qad_utils.getAngleBy2Pts(startPt, endPt)
if tan == angleSegment or tan == angleSegment - math.pi:
return False
chord = qad_utils.getDistance(startPt, endPt)
half_chord = chord / 2
ptMiddle = qad_utils.getMiddlePoint(startPt, endPt)
angle = tan + (math.pi / 2)
angle = angleSegment - angle
distFromCenter = math.tan(angle) * half_chord
self.center = qad_utils.getPolarPointByPtAngle(ptMiddle,
angleSegment - (math.pi / 2),
distFromCenter)
pt = qad_utils.getPolarPointByPtAngle(startPt, tan, chord)
if qad_utils.leftOfLine(endPt, startPt, pt) < 0:
# arco si sviluppa a sinistra della tangente
self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt)
self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt)
else:
# arco si sviluppa a destra della tangente
self.startAngle = qad_utils.getAngleBy2Pts(self.center, endPt)
self.endAngle = qad_utils.getAngleBy2Pts(self.center, startPt)
self.radius = qad_utils.getDistance(startPt, self.center)
return True
#============================================================================
# fromStartEndPtsRadius
#============================================================================
def fromStartEndPtsRadius(self, startPt, endPt, radius):
"""
setta le caratteristiche dell'arco attraverso:
punto iniziale
punto finale
raggio
"""
if startPt == endPt or radius <= 0:
return False
chord = qad_utils.getDistance(startPt, endPt)
half_chord = chord / 2
if radius < half_chord:
return False
self.radius = radius
angleSegment = qad_utils.getAngleBy2Pts(startPt, endPt)
ptMiddle = qad_utils.getMiddlePoint(startPt, endPt)
# Pitagora
distFromCenter = math.sqrt((self.radius * self.radius) - (half_chord * half_chord))
# aggiungo 90 gradi
self.center = qad_utils.getPolarPointByPtAngle(ptMiddle,
angleSegment + (math.pi / 2),
distFromCenter)
self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt)
self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt)
return True
#============================================================================
# fromStartPtAngleRadiusChordDirection
#============================================================================
def fromStartPtAngleRadiusChordDirection(self, startPt, angle, radius, chordDirection):
"""
setta le caratteristiche dell'arco attraverso:
punto iniziale
angolo inscritto
raggio
direzione della corda
"""
if angle == 0 or angle == 2 * math.pi or radius <= 0:
return False
a = chordDirection + (math.pi / 2) - (angle / 2)
self.radius = radius
self.center = qad_utils.getPolarPointByPtAngle(startPt, a, radius)
endPt = qad_utils.getPolarPointByPtAngle(self.center, a + math.pi + angle, radius)
self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt)
self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt)
return True
#============================================================================
# fromPolyline
#============================================================================
def fromPolyline(self, points, startVertex, atLeastNSegment = None):
"""
setta le caratteristiche del primo arco incontrato nella lista di punti
partendo dalla posizione startVertex (0-indexed)
ritorna la posizione nella lista del punto iniziale e finale se é stato trovato un arco
altrimenti None
N.B. in punti NON devono essere in coordinate geografiche
"""
if atLeastNSegment is None:
_atLeastNSegment = QadVariables.get(QadMsg.translate("Environment variables", "ARCMINSEGMENTQTY"), 12)
else:
_atLeastNSegment = atLeastNSegment
totPoints = len(points)
# perché sia un arco ci vogliono almeno _atLeastNSegment segmenti
if (totPoints - 1) - startVertex < _atLeastNSegment or _atLeastNSegment < 2:
return None
# per problemi di approssimazione dei calcoli
epsilon = 1.e-4 # percentuale del raggio per ottenere max diff. di una distanza con il raggio
InfinityLinePerpOnMiddle1 = None
InfinityLinePerpOnMiddle2 = None
nSegment = 0
i = startVertex
while i < totPoints - 1:
if InfinityLinePerpOnMiddle1 is None:
InfinityLinePerpOnMiddle1 = qad_utils.getInfinityLinePerpOnMiddle(points[i], points[i + 1])
nStartVertex = i
nSegment = 1
i = i + 1
continue
elif InfinityLinePerpOnMiddle2 is None:
InfinityLinePerpOnMiddle2 = qad_utils.getInfinityLinePerpOnMiddle(points[i], points[i + 1])
if InfinityLinePerpOnMiddle2 is None:
InfinityLinePerpOnMiddle1 = None
nSegment = 0
else:
# calcolo il presunto centro con 2 segmenti
center = qad_utils.getIntersectionPointOn2InfinityLines(InfinityLinePerpOnMiddle1[0], \
InfinityLinePerpOnMiddle1[1], \
InfinityLinePerpOnMiddle2[0], \
InfinityLinePerpOnMiddle2[1])
if center is None: # linee parallele
InfinityLinePerpOnMiddle1 = InfinityLinePerpOnMiddle2
InfinityLinePerpOnMiddle2 = None
nStartVertex = i
nSegment = 1
else:
nSegment = nSegment + 1
radius = qad_utils.getDistance(center, points[i + 1]) # calcolo il presunto raggio
maxDifference = radius * epsilon
# calcolo il verso dell'arco e l'angolo dell'arco
# se un punto intermedio dell'arco è a sinistra del
# segmento che unisce i due punti allora il verso è antiorario
startClockWise = True if qad_utils.leftOfLine(points[i], points[i - 1], points[i + 1]) < 0 else False
angle = qad_utils.getAngleBy3Pts(points[i - 1], center, points[i + 1], startClockWise)
else: # e sono già stati valutati almeno 2 segmenti
# calcolo la distanza del punto dal presunto centro
dist = qad_utils.getDistance(center, points[i + 1])
# calcolo il verso dell'arco e l'angolo
clockWise = True if qad_utils.leftOfLine(points[i], points[i - 1], points[i + 1]) < 0 else False
angle = angle + qad_utils.getAngleBy3Pts(points[i], center, points[i + 1], startClockWise)
# se la distanza è così vicina a quella del raggio
# il verso dell'arco deve essere quello iniziale
# l'angolo dell'arco non può essere >= 360 gradi
if qad_utils.doubleNear(radius, dist, maxDifference) and \
startClockWise == clockWise and \
angle < 2 * math.pi:
nSegment = nSegment + 1 # anche questo segmento fa parte dell'arco
else: # questo segmento non fa parte del cerchio
# se sono stati trovati un numero sufficiente di segmenti successivi
if nSegment >= _atLeastNSegment:
# se é un angolo giro e il primo punto = ultimo punto allora points é un cerchio
if qad_utils.doubleNear(angle, 2 * math.pi) and points[0] == points[-1]:
return None
break
else:
i = i - 2
InfinityLinePerpOnMiddle1 = None
InfinityLinePerpOnMiddle2 = None
i = i + 1
# se sono stati trovati un numero sufficiente di segmenti successivi
if nSegment >= _atLeastNSegment:
nEndVertex = nStartVertex + nSegment
# se il punto iniziale e quello finale non coincidono é un arco
if points[nStartVertex] != points[nEndVertex]:
self.center = center
self.radius = radius
# se il verso é orario
if startClockWise:
# inverto l'angolo iniziale con quello finale
self.endAngle = qad_utils.getAngleBy2Pts(center, points[nStartVertex])
self.startAngle = qad_utils.getAngleBy2Pts(center, points[nEndVertex])
else:
self.startAngle = qad_utils.getAngleBy2Pts(center, points[nStartVertex])
self.endAngle = qad_utils.getAngleBy2Pts(center, points[nEndVertex])
return nStartVertex, nEndVertex
return None
#===============================================================================
# QadArcList lista di archi class
#===============================================================================
class QadArcList():
def __init__(self):
self.arcList = [] # lista di archi
self.startEndVerticesList = [] # lista degli estremi (posizioni dei vertici iniziali e finali)
def clear(self):
del self.arcList[:] # svuoto la lista
del self.startEndVerticesList[:] # svuoto la lista
#============================================================================
# fromPoints
#============================================================================
def fromPoints(self, points, atLeastNSegment = None):
"""
setta la lista degli archi e degli estremi leggendo una sequenza di punti
ritorna il numero di archi trovati
"""
if atLeastNSegment is None:
_atLeastNSegment = QadVariables.get(QadMsg.translate("Environment variables", "ARCMINSEGMENTQTY"), 12)
else:
_atLeastNSegment = atLeastNSegment
self.clear()
startVertex = 0
arc = QadArc()
startEndVertices = arc.fromPolyline(points, startVertex, _atLeastNSegment)
while startEndVertices is not None:
_arc = QadArc(arc) # ne faccio una copia
self.arcList.append(_arc)
self.startEndVerticesList.append(startEndVertices)
startVertex = startEndVertices[1] # l'ultimo punto dell'arco
startEndVertices = arc.fromPolyline(points, startVertex, _atLeastNSegment)
return len(self.arcList)
#============================================================================
# fromGeom
#============================================================================
def fromGeom(self, geom, atLeastNSegment = None):
"""
setta la lista degli archi e degli estremi leggendo una geometria
ritorna il numero di archi trovati
"""
if atLeastNSegment is None:
_atLeastNSegment = QadVariables.get(QadMsg.translate("Environment variables", "ARCMINSEGMENTQTY"), 12)
else:
_atLeastNSegment = atLeastNSegment
self.clear()
arc = QadArc()
incremental = 0
# riduco in polilinee
geoms = qad_utils.asPointOrPolyline(geom)
for g in geoms:
points = g.asPolyline() # vettore di punti
startVertex = 0
startEndVertices = arc.fromPolyline(points, startVertex, _atLeastNSegment)
while startEndVertices is not None:
_arc = QadArc(arc) # ne faccio una copia
self.arcList.append(_arc)
self.startEndVerticesList.append([startEndVertices[0] + incremental, startEndVertices[1] + incremental])
startVertex = startEndVertices[1] # l'ultimo punto dell'arco
startEndVertices = arc.fromPolyline(points, startVertex, _atLeastNSegment)
incremental = len(points) - 1
return len(self.arcList)
#============================================================================
# fromGeom
#============================================================================
def arcAt(self, afterVertex):
"""
cerca se esiste un arco al segmento il cui secondo vertice é <afterVertex>
restituisce una lista con <arco>, <lista con indice del punto iniziale e finale>
oppure None se arco non trovato
"""
i = 0
for startEndVertices in self.startEndVerticesList:
if afterVertex > startEndVertices[0] and afterVertex <= startEndVertices[1]:
return self.arcList[i], startEndVertices
i = i + 1
return None