assembly: fix trace command
This commit is contained in:
parent
92b42d2f71
commit
12f1670925
66
assembly.py
66
assembly.py
|
@ -1608,23 +1608,26 @@ class AsmMovingPart(object):
|
||||||
self.tracePoint = self.draggerPlacement.Base
|
self.tracePoint = self.draggerPlacement.Base
|
||||||
self.trace = None
|
self.trace = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def onRollback(cls):
|
||||||
|
doc = FreeCADGui.editDocument()
|
||||||
|
if not doc:
|
||||||
|
return
|
||||||
|
vobj = doc.getInEdit()
|
||||||
|
if vobj and isTypeOf(vobj,ViewProviderAssembly):
|
||||||
|
movingPart = getattr(vobj.Proxy,'_movingPart',None)
|
||||||
|
if movingPart:
|
||||||
|
vobj.Object.recompute(True)
|
||||||
|
movingPart.tracePoint = movingPart.draggerPlacement.Base
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
info = getPartInfo(self.parent,self.subname)
|
info = getPartInfo(self.parent,self.subname)
|
||||||
self.oldPlacement = info.Placement.copy()
|
self.oldPlacement = info.Placement.copy()
|
||||||
self.part = info.Part
|
self.part = info.Part
|
||||||
self.partName = info.PartName
|
self.partName = info.PartName
|
||||||
pla = info.Placement.multiply(FreeCAD.Placement(self.offset))
|
pla = info.Placement.multiply(self.offset)
|
||||||
logger.trace('part move update {}: {}'.format(objName(self.parent),pla))
|
logger.trace('part move update {}: {}'.format(objName(self.parent),pla))
|
||||||
self.draggerPlacement = pla
|
self.draggerPlacement = pla
|
||||||
if gui.AsmCmdManager.Trace and \
|
|
||||||
self.tracePoint.isEqual(pla.Base,1e5):
|
|
||||||
if not self.trace:
|
|
||||||
self.trace = FreeCAD.ActiveDocument.addObject(
|
|
||||||
'Part::Polygon','AsmTrace')
|
|
||||||
self.trace.Nodes = {-1:self.tracePoint}
|
|
||||||
self.tracePoint = pla.Base
|
|
||||||
self.trace.Nodes = {-1:pla.Base}
|
|
||||||
self.trace.recompute()
|
|
||||||
return pla
|
return pla
|
||||||
|
|
||||||
def move(self):
|
def move(self):
|
||||||
|
@ -1666,6 +1669,22 @@ class AsmMovingPart(object):
|
||||||
solver.solve, self.objs, dragPart=self.part, rollback=rollback):
|
solver.solve, self.objs, dragPart=self.part, rollback=rollback):
|
||||||
obj.recompute(True)
|
obj.recompute(True)
|
||||||
|
|
||||||
|
if gui.AsmCmdManager.Trace and \
|
||||||
|
not self.tracePoint.isEqual(self.draggerPlacement.Base,1e-5):
|
||||||
|
try:
|
||||||
|
# check if the object is deleted
|
||||||
|
self.trace.Name
|
||||||
|
except Exception:
|
||||||
|
self.trace = None
|
||||||
|
mat = FreeCADGui.editDocument().EditingTransform
|
||||||
|
if not self.trace:
|
||||||
|
self.trace = FreeCAD.ActiveDocument.addObject(
|
||||||
|
'Part::Polygon','AsmTrace')
|
||||||
|
self.trace.Nodes = {-1:mat.multiply(self.tracePoint)}
|
||||||
|
self.tracePoint = self.draggerPlacement.Base
|
||||||
|
self.trace.Nodes = {-1:mat.multiply(self.draggerPlacement.Base)}
|
||||||
|
self.trace.recompute()
|
||||||
|
|
||||||
# self.draggerPlacement, which holds the intended dragger placement, is
|
# self.draggerPlacement, which holds the intended dragger placement, is
|
||||||
# updated by the above solver call through the following chain,
|
# updated by the above solver call through the following chain,
|
||||||
# solver.solve() -> (triggers dependent objects recompute when done)
|
# solver.solve() -> (triggers dependent objects recompute when done)
|
||||||
|
@ -1747,19 +1766,11 @@ def movePart(useCenterballDragger=None):
|
||||||
return doc.setEdit(vobj,1)
|
return doc.setEdit(vobj,1)
|
||||||
|
|
||||||
class AsmDocumentObserver:
|
class AsmDocumentObserver:
|
||||||
def checkMovingPart(self):
|
|
||||||
doc = FreeCADGui.editDocument()
|
|
||||||
if not doc:
|
|
||||||
return
|
|
||||||
vobj = doc.getInEdit()
|
|
||||||
if vobj and isTypeOf(vobj.Object,Assembly):
|
|
||||||
vobj.Object.recompute(True)
|
|
||||||
|
|
||||||
def slotUndoDocument(self,_doc):
|
def slotUndoDocument(self,_doc):
|
||||||
self.checkMovingPart()
|
AsmMovingPart.onRollback()
|
||||||
|
|
||||||
def slotRedoDocument(self,_doc):
|
def slotRedoDocument(self,_doc):
|
||||||
self.checkMovingPart()
|
AsmMovingPart.onRollback()
|
||||||
|
|
||||||
def slotChangedObject(self,obj,prop):
|
def slotChangedObject(self,obj,prop):
|
||||||
Assembly.checkPartChange(obj,prop)
|
Assembly.checkPartChange(obj,prop)
|
||||||
|
@ -1811,10 +1822,17 @@ class ViewProviderAssembly(ViewProviderAsmGroup):
|
||||||
self._movingPart.update)
|
self._movingPart.update)
|
||||||
if pla:
|
if pla:
|
||||||
self.ViewObject.DraggingPlacement = pla
|
self.ViewObject.DraggingPlacement = pla
|
||||||
else:
|
return
|
||||||
doc = FreeCADGui.editDocument()
|
|
||||||
if doc:
|
# Must NOT call resetEdit() here. Because we are called through dragger
|
||||||
doc.resetEdit()
|
# callback, meaning that we are called during coin node traversal.
|
||||||
|
# resetEdit() will cause View3DInventorView to reset editing root node.
|
||||||
|
# And disaster will happen when modifying coin node tree while
|
||||||
|
# traversing.
|
||||||
|
#
|
||||||
|
# doc = FreeCADGui.editDocument()
|
||||||
|
# if doc:
|
||||||
|
# doc.resetEdit()
|
||||||
|
|
||||||
def initDraggingPlacement(self):
|
def initDraggingPlacement(self):
|
||||||
if not getattr(self,'_movingPart',None):
|
if not getattr(self,'_movingPart',None):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user