Skip to content

Commit 90d9e49

Browse files
committed
Improve snap performance by excluding intersection with non geoItems
Generic fix
1 parent 0b039f1 commit 90d9e49

File tree

8 files changed

+53
-46
lines changed

8 files changed

+53
-46
lines changed

PythonCAD/Generic/Kernel/GeoEntity/dimension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Copyright (c) 2002, 2003, 2004, 2005, 2006 Art Haas
33
#
4-
# Copyright (c) 2010 Matteo Boscolo
4+
# Copyright (c) 2010 - 2013 Matteo Boscolo
55
#
66
# This file is part of PythonCAD.
77
#

PythonCAD/Generic/Kernel/GeoEntity/geometricalentity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2010 Matteo Boscolo
2+
# Copyright (c) 2010 - 2013 Matteo Boscolo
33
#
44
# This file is part of PythonCAD.
55
#
@@ -132,7 +132,7 @@ class GeometricalEntityComposed(dict):
132132
like dimension labels ...
133133
"""
134134
def __init__(self, kw, argNameType):
135-
if kw is None and argNameType is none:
135+
if kw is None and argNameType is None:
136136
return
137137
if len(kw)!=len(argNameType):
138138
raise TypeError, "Wrong number of items "

PythonCAD/Generic/Kernel/GeoUtil/intersection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _pol_obj_intersection(ipts, pol, obj):
135135
"""
136136
for seg in pol.getSegments():
137137
tempIpts=[]
138-
_sympy_intersection(tempipts, seg, obj)
138+
_sympy_intersection(tempIpts, seg, obj)
139139
if len(tempIpts)>0:
140140
ipts=tempIpts
141141
break
@@ -149,7 +149,7 @@ def _pol_pol_intersection(ipts, pol1, pol2):
149149
for seg1 in pol1.getSegments():
150150
for seg2 in pol2.getSegments():
151151
tempIpts=[]
152-
_sympy_intersection(tempipts, seg1, seg2)
152+
_sympy_intersection(tempIpts, seg1, seg2)
153153
if len(tempIpts)>0:
154154
ipts=tempIpts
155155
break
@@ -173,7 +173,7 @@ def find_intersections(obja, objb):
173173
try:
174174
_sympy_intersection(_ipts, obja, objb)
175175
except:
176-
print "problem with sympy intersection"
176+
print "find_intersections: problem with sympy intersection",obja,objb
177177
return _ipts
178178

179179
def findSegmentExtendedIntersection(obja, objb):

PythonCAD/Generic/Kernel/exception.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,49 +188,49 @@ class ExcPoint(CommandException):
188188

189189
class ExcLenght(CommandException):
190190
"""
191-
when this exception is trown it means that the command need a lenght
191+
when this exception is thrown it means that the command need a lenght
192192
"""
193193
pass
194194

195195
class ExcAngle(CommandException):
196196
"""
197-
when this exception is trown it means that the command need a deg angle
197+
when this exception is thrown it means that the command need a deg angle
198198
"""
199199
pass
200200

201201
class ExcText(CommandException):
202202
"""
203-
when this exception is trown it means that the command need text
203+
when this exception is thrown it means that the command need text
204204
"""
205205
pass
206206

207207
class ExcInt(CommandException):
208208
"""
209-
when this exception is trown it means that the command need an Integer
209+
when this exception is thrown it means that the command need an Integer
210210
"""
211211
pass
212212

213213
class ExcBool(CommandException):
214214
"""
215-
when this exception is trown it means that the command need an Boolean
215+
when this exception is thrown it means that the command need n Boolean
216216
"""
217217
pass
218218

219219
class ExcEntity(CommandException):
220220
"""
221-
when this exception is trown it means that the command need an dbEnity
221+
when this exception is thrown it means that the command need n dbEnity
222222
"""
223223
pass
224224

225225
class ExcMultiEntity(CommandException):
226226
"""
227-
when this exception is trown it means that the command need an array of id
227+
when this exception is thrown it means that the command need an array of id
228228
"""
229229
pass
230230

231231
class ExcEntityPoint(CommandException):
232232
"""
233-
when this exception is trown it means that the command need an a string
233+
when this exception is thrown it means that the command need an a string
234234
like id@x,y
235235
"""
236236
pass

PythonCAD/Interface/Command/icommand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def correctPositionForcedDirection(self, point, force):
500500

501501
def getIntersection(self, entity, point):
502502
"""
503-
this fucnticion compute the snap intersection point
503+
this function compute the snap intersection point
504504
"""
505505
returnVal=None
506506
distance=None

PythonCAD/Interface/DrawingHelper/polarguides.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def __init__(self, parent, x, y, a):
5151

5252
self.addGuidesByIncrement(math.pi/6)
5353

54-
54+
def collidesWithItem(self,other,mode):
55+
return False
56+
5557
def setForceDirection(self, a):
5658
'''
5759
set scene.forceDirection to a angle
@@ -151,6 +153,8 @@ def __init__(self, parent=None, a=0.0):
151153

152154
self.setPen(self.hidePen)
153155
self.hide()
156+
def collidesWithItem(self,other,mode):
157+
return False
154158

155159
def hide(self):
156160
self.setPen(self.hidePen)

PythonCAD/Interface/DrawingHelper/snap.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,32 @@ def getSnapPoint(self, point, entity):
4343
fromPoint: [Geoent.Pointfloat]
4444
fromEnt: [GeoEnt.*]
4545
"""
46+
def pointReturn(pointCalculated,realPoint):
47+
if pointCalculated==None:
48+
return realPoint
49+
return pointCalculated
50+
4651
if self.activeSnap==SNAP_POINT_ARRAY["NONE"]:
4752
return point
4853
else:
4954
snapPoint=point
5055
if SNAP_POINT_ARRAY["MID"] == self.activeSnap:
51-
snapPoint = self.getSnapMiddlePoint(entity)
56+
return pointReturn(self.getSnapMiddlePoint(entity),point)
5257
elif SNAP_POINT_ARRAY["END"] == self.activeSnap:
53-
snapPoint =self.getSnapEndPoint(entity, point)
58+
return pointReturn(self.getSnapEndPoint(entity, point),point)
5459
elif SNAP_POINT_ARRAY["ORTHO"] == self.activeSnap:
55-
snapPoint =self.getSnapOrtoPoint(entity, point)
60+
return pointReturn(self.getSnapOrtoPoint(entity, point),point)
5661
elif SNAP_POINT_ARRAY["CENTER"]== self.activeSnap:
57-
snapPoint =self.getSnapCenterPoint(entity)
62+
return pointReturn(self.getSnapCenterPoint(entity),point)
5863
elif SNAP_POINT_ARRAY["QUADRANT"]== self.activeSnap:
59-
snapPoint =self.getSnapQuadrantPoint(entity, snapPoint)
64+
return pointReturn(self.getSnapQuadrantPoint(entity, snapPoint),point)
6065
elif SNAP_POINT_ARRAY["ORIG"]== self.activeSnap:
61-
snapPoint=Point(0.0, 0.0)
66+
return Point(0.0, 0.0)
6267
elif SNAP_POINT_ARRAY["INTERSECTION"]== self.activeSnap:
63-
snapPoint=self.getIntersection(entity,snapPoint )
68+
return pointReturn(self.getIntersection(entity,snapPoint ),point)
6469
elif SNAP_POINT_ARRAY["LIST"]== self.activeSnap:
65-
#this should be used when checklist of snap will be enabled
70+
#TODO: this should be used when checklist of snap will be enabled
6671
snapPoints=[]
67-
6872
if ACTIVE_SNAP_LIST.count(SNAP_POINT_ARRAY["MID"])>0:
6973
pnt=self.getSnapMiddlePoint(entity)
7074
if pnt!=None:
@@ -102,14 +106,12 @@ def getSnapPoint(self, point, entity):
102106
else:
103107
if outPoint[0]!=None:
104108
snapPoint=outPoint[0]
109+
return pointReturn(snapPoint,point)
105110

106-
if snapPoint==None:
107-
return point
108-
return snapPoint
109111

110112
def getSnapOrtoPoint(self, entity, point):
111113
"""
112-
this fucnticion compute the orto to point snap constraint
114+
this function compute the orto to point snap constraint
113115
"""
114116
# Now only works for segments and arcs. USES THE getPROJECTION METHOD
115117
if self._scene.fromPoint==None or entity == None:
@@ -125,7 +127,7 @@ def getSnapOrtoPoint(self, entity, point):
125127

126128
def getSnapTangentPoint(self, point):
127129
"""
128-
this fucnticion compute the Tangent to point snap constraint
130+
this function compute the Tangent to point snap constraint
129131
"""
130132
#TODO: getSnapTangentPoint
131133
returnVal=None
@@ -136,7 +138,7 @@ def getSnapTangentPoint(self, point):
136138

137139
def getSnapMiddlePoint(self, entity):
138140
"""
139-
this fucnticion compute midpoint snap constraint to the entity argument
141+
this function compute midpoint snap constraint to the entity argument
140142
"""
141143
returnVal=None
142144
if getattr(entity, 'geoItem', None):
@@ -146,7 +148,7 @@ def getSnapMiddlePoint(self, entity):
146148

147149
def getSnapEndPoint(self, entity, point):
148150
"""
149-
this fucnticion compute the snap endpoint
151+
this function compute the snap endpoint
150152
"""
151153
if point == None or entity == None:
152154
return None
@@ -166,7 +168,7 @@ def getSnapEndPoint(self, entity, point):
166168

167169
def getSnapCenterPoint(self, entity):
168170
"""
169-
this fucnticion compute the snap from the center of an entity
171+
this function compute the snap from the center of an entity
170172
"""
171173
returnVal=None
172174
if getattr(entity, 'geoItem', None):
@@ -179,22 +181,17 @@ def getSnapCenterPoint(self, entity):
179181

180182
def getIntersection(self, entity, point):
181183
"""
182-
this fucnticion compute the snap intersection point
184+
this function compute the snap intersection point
183185
"""
184186
returnVal=None
185187
distance=None
186188
if entity!=None:
187189
geoEntityFrom=entity.geoItem
188-
import time
189-
#startTime=time.clock()
190190
entityList=self._scene.collidingItems(entity)
191-
#endTime=time.clock()-startTime
192-
#print "getIntersection, collidingItems in %s"%str(endTime)
193-
#startTime=time.clock()
194191
for ent in entityList:
192+
if not isinstance(ent,BaseEntity):
193+
continue
195194
if isinstance(ent, BaseEntity):
196-
#print "geoitem", ent.geoItem
197-
#print "geoEntityFrom", geoEntityFrom
198195
intPoint=find_intersections(ent.geoItem,geoEntityFrom)
199196
for tp in intPoint:
200197
iPoint=Point(tp[0], tp[1])
@@ -206,13 +203,11 @@ def getIntersection(self, entity, point):
206203
if distance>spoolDist:
207204
distance=spoolDist
208205
returnVal=iPoint
209-
#endTime=time.clock()-startTime
210-
#print "find intersection in %s"%str(endTime)
211206
return returnVal
212207

213208
def getSnapQuadrantPoint(self, entity, point):
214209
"""
215-
this fucnticion compute the snap from the quadrant
210+
this function compute the snap from the quadrant
216211
"""
217212
returnVal=None
218213
if getattr(entity, 'geoItem', None):
@@ -244,7 +239,10 @@ def __init__(self):
244239
self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, False)
245240
self.setFlag(QtGui.QGraphicsItem.ItemIgnoresTransformations, True)
246241
self.hide()
247-
242+
243+
def collidesWithItem(self,other,mode):
244+
return False
245+
248246
def shape(self):
249247
"""
250248
overloading of the shape method
@@ -277,7 +275,11 @@ def __init__(self, x, y):
277275
self.setToolTip("EndPoint")
278276
self.x=x
279277
self.y=y
280-
278+
279+
def collidesWithItem(self,other,mode):
280+
print "collidesWithItem"
281+
return False
282+
281283
def definePath(self):
282284
rect=QtCore.QRectF(self.x-5.0, self.y-5.0, 10.0, 10.0)
283285
path=QtGui.QPainterPath()

PythonCAD/pythoncad_qt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from Interface.cadwindow import CadWindowMdi
2525
#
2626
def getPythonCAD():
27+
2728
app = QtGui.QApplication(sys.argv)
2829
# splashscreen
2930
splashPath=os.path.join(os.getcwd(), 'icons', 'splashScreen1.png')

0 commit comments

Comments
 (0)