Skip to content

Commit f5cb605

Browse files
committed
Fix bug on multi selection end command
1 parent 2725e4a commit f5cb605

File tree

6 files changed

+44
-35
lines changed

6 files changed

+44
-35
lines changed

PythonCAD/Generic/Kernel/Command/basecommand.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, document):
3939
self.index=0
4040
self.document=document
4141
self.automaticApply=True
42-
42+
self.autorestart=True
4343
def __iter__(self):
4444
return self
4545

@@ -153,7 +153,7 @@ def keys(self):
153153
@property
154154
def lenght(self):
155155
"""
156-
get the number of command imput value that the user have to provide
156+
get the number of command input value that the user have to provide
157157
"""
158158
return len(self.exception)
159159

PythonCAD/Generic/Kernel/Command/propertycommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class PropertyCommand(BaseCommand):
3131
"""
3232
def __init__(self, document):
3333
BaseCommand.__init__(self, document)
34+
self.autorestart=False
3435
self.exception=[ExcMultiEntity,ExcDicTuple]
3536
self.defaultValue=[None]
3637
self.message=["Select Entities: ",

PythonCAD/Generic/Kernel/GeoUtil/geolib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import math
2424

2525
from Kernel.GeoEntity.point import Point
26+
from Kernel.exception import EntityMissing
2627

2728
class Vector:
2829
"""
@@ -33,9 +34,9 @@ def __init__(self,p1,p2):
3334
Default Constructor
3435
"""
3536
if(not isinstance(p1,Point)):
36-
raise TypeError,"Invalid Argument p1: Point Required"
37+
raise EntityMissing("Invalid Argument p1: Point Required")
3738
if(not isinstance(p2,Point)):
38-
raise TypeError,"Invalid Argument p2: Point Required"
39+
raise EntityMissing("Invalid Argument p2: Point Required")
3940
x,y=p1.getCoords()
4041
x1,y1=p2.getCoords()
4142
self.X=x1-x

PythonCAD/Generic/Kernel/exception.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
#
2222
# This module Provide custom exception for the db module and kernel
2323
#
24+
class EntityMissing(Exception):
25+
"""
26+
Wrong entity provided
27+
"""
28+
def __init__(self, value):
29+
self.value = value
30+
def __str__(self):
31+
return repr(self.value)
32+
33+
2434
class NoDefaultValue(Exception):
2535
"""
2636
no default value provided by the command

PythonCAD/Interface/Command/icommand.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,10 @@
2323
#
2424
# How it works:
2525
#
26-
#
27-
#
28-
#Qt Import
29-
#
30-
from PyQt4 import QtCore, QtGui
31-
32-
import math, string
26+
import logging
3327
#
3428
#Kernel Import
3529
#
36-
from Kernel.initsetting import SNAP_POINT_ARRAY, ACTIVE_SNAP_POINT, ACTIVE_SNAP_LIST
37-
from Kernel.GeoEntity.point import Point
38-
from Kernel.GeoUtil.geolib import Vector
3930
from Kernel.GeoUtil.intersection import *
4031
from Kernel.pycadevent import *
4132
from Kernel.exception import *
@@ -44,7 +35,6 @@
4435
# Interface Import
4536
#
4637
from Interface.cadinitsetting import RESTART_COMMAND_OPTION
47-
from Interface.Entity.base import BaseEntity
4838
from Interface.Dialogs.property import Property
4939
from Interface.Preview.factory import *
5040
from Interface.DrawingHelper.snap import *
@@ -114,14 +104,16 @@ def addMauseEvent(self, point, entity,distance=None,angle=None , text=None, forc
114104
#
115105
# Compute snap distance and position force
116106
#
117-
#print "log: addMauseEvent", str(point), str(entity), str(distance), str(angle), str(text), str(force)
107+
logging.debug("log: addMauseEvent [%s][%s][%s][%s][%s][%s]"%( str(point), str(entity), str(distance), str(angle), str(text), str(force)))
118108
if correct!=None:
119109
snap=self.scene.snappingPoint.getSnapPoint(point,self.getEntity(point))
120110
snap=self.correctPositionForcedDirection(snap, self._scene.forceDirection)
121111
else:
122112
snap=point
113+
123114
if angle==None:
124115
angle=self.calculateAngle(snap)
116+
125117
if distance==None:
126118
distance=self.getDistance(snap)
127119
#
@@ -212,25 +204,28 @@ def applyCommand(self):
212204
self.scene.hideSnapMarks()
213205
try:
214206
self.kernelCommand.applyCommand()
215-
if RESTART_COMMAND_OPTION:
216-
self.restartCommand()
217-
self.updateInput(self.kernelCommand.activeMessage)
218-
self.scene.clearSelection()
219-
self.scene.fromPoint=None
220-
self.scene.isGuided=None
221-
self.scene.isGuideLocked=None
222-
self.scene.GuideHandler.reset()
207+
if RESTART_COMMAND_OPTION and self.kernelCommand.autorestart:
208+
self.restartCommand()
209+
self.updateInput(self.kernelCommand.activeMessage)
210+
self.scene.clearSelection()
211+
self.scene.fromPoint=None
212+
self.scene.isGuided=None
213+
self.scene.isGuideLocked=None
214+
self.scene.GuideHandler.reset()
223215
else:
224216
self.scene.cancelCommand()
225217
self.updateInput("Ready")
218+
self.scene.clearPreview()
219+
self.removePreviewItemToTheScene()
226220
self=None
221+
return
227222
self.scene.clearPreview()
223+
self.removePreviewItemToTheScene()
228224
except Exception as e:
229225
print type(e) # the exception instance
230226
print "ICommand applyCommand Errore ", str(e)
231227
self.restartCommand()
232-
self.removePreviewItemToTheScene()
233-
return
228+
234229

235230
def getEntity(self, position):
236231
"""
@@ -283,14 +278,16 @@ def calculateAngle(self, snap):
283278
"""
284279
if snap==None:
285280
return None
286-
287-
for snapPoint in self._snap:
288-
print "angle ",self._snap[snapPoint],snap
289-
v=Vector(self._snap[snapPoint],snap )
290-
return v.absAng
291-
else:
281+
try:
282+
for snapPoint in self._snap:
283+
print "angle ",self._snap[snapPoint],snap
284+
v=Vector(self._snap[snapPoint],snap )
285+
return v.absAng
286+
else:
287+
return None
288+
except EntityMissing:
292289
return None
293-
290+
294291
def decodeText(self, value):
295292
"""
296293
encode the text given from the user

PythonCAD/Interface/Dialogs/Widget/widgets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def penChanged(self):
8686
"""
8787
change event
8888
"""
89-
self.activeValue = QtCore.Qt.PenStyle(self.penStyleComboBox.itemData(
90-
self.penStyleComboBox.currentIndex(), IdRole))
89+
value=self.penStyleComboBox.currentIndex()
90+
self.activeValue = QtCore.Qt.PenStyle(self.penStyleComboBox.itemData(value, IdRole).toInt()[0])
9191
self.changed=True
9292

9393

0 commit comments

Comments
 (0)