diff --git a/Gui/Resources/icons/Assembly_AxialMove.svg b/Gui/Resources/icons/Assembly_AxialMove.svg new file mode 100644 index 0000000..3ecad78 --- /dev/null +++ b/Gui/Resources/icons/Assembly_AxialMove.svg @@ -0,0 +1,241 @@ + + + + + + + + + + + + image/svg+xml + + + Path-Axis + 2015-07-04 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + FreeCAD/src/Mod/Path/Gui/Resources/icons/Path-Axis.svg + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + [agryson] Alexander Gryson + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Gui/Resources/icons/Assembly_Move.svg b/Gui/Resources/icons/Assembly_Move.svg index 6d85c93..7e54a3c 100644 --- a/Gui/Resources/icons/Assembly_Move.svg +++ b/Gui/Resources/icons/Assembly_Move.svg @@ -14,8 +14,8 @@ height="64px" id="svg2963" sodipodi:version="0.32" - inkscape:version="0.48.5 r10040" - sodipodi:docname="Draft_Move.svg" + inkscape:version="0.91 r13725" + sodipodi:docname="Assembly_BallMove.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape" version="1.1"> + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -327,7 +358,7 @@ image/svg+xml - Draft_Move + Mon Oct 10 13:44:52 2011 +0000 diff --git a/assembly.py b/assembly.py index 6019e66..8377469 100644 --- a/assembly.py +++ b/assembly.py @@ -321,8 +321,8 @@ class AsmElementLink(AsmBase): obj.addProperty("App::PropertyXLink","LinkedObject"," Link",'') super(AsmElementLink,self).attach(obj) - def execute(self,_obj): - self.getInfo(True) + def execute(self,obj): + obj.ViewObject.Proxy.onExecute(self.getInfo(True)) return False def getAssembly(self): @@ -549,7 +549,76 @@ def setPlacement(part,pla,undoDocs,undoName=None): class ViewProviderAsmElementLink(ViewProviderAsmBase): - pass + def __init__(self,vobj): + self._draggingPart = None + self._draggingOffset = None + self._draggingOffsetInv = None + self._draggingUndos = None + self._draggingPlacement = None + super(ViewProviderAsmElementLink,self).__init__(vobj) + + def doubleClicked(self, vobj): + return vobj.Document.setEdit(vobj,1) + + def onExecute(self,info): + if not getattr(self,'_draggingPart',None): + return + self._draggingPart = info.Part + self._draggingPlacement = info.Placement.multiply( + FreeCAD.Placement(self._draggingOffset)) + self.ViewObject.DraggingPlacement = self._draggingPlacement + + def initDraggingPlacement(self): + obj = self.ViewObject.Object + info = obj.Proxy.getInfo() + self._draggingPart = info.Part + rot = utils.getElementRotation(info.Shape) + if not rot: + # in case the shape has no normal, like a vertex, just use an empty + # rotation, which means having the same rotation has the owner part. + rot = FreeCAD.Rotation() + pla = FreeCAD.Placement(utils.getElementPos(info.Shape),rot) + self._draggingOffset = FreeCAD.Placement(pla.toMatrix()) + self._draggingOffsetInv = FreeCAD.Placement(pla.toMatrix().inverse()) + self._draggingPlacement = info.Placement.multiply(pla) + mat = FreeCADGui.editDocument().EditingTransform + return (mat,self._draggingPlacement,info.Shape.BoundBox) + + def onDragStart(self): + self._draggingUndos = set() + + def onDragMotion(self): + pla = self.ViewObject.DraggingPlacement.multiply( + self._draggingOffsetInv) + setPlacement(self._draggingPart,pla, + self._draggingUndos, 'Assembly drag') + + obj = self.ViewObject.Object + + from PySide import QtCore,QtGui + if QtGui.QApplication.keyboardModifiers() == QtCore.Qt.ControlModifier: + obj.getLinkedObject(False).recompute() + obj.recompute() + return + + try: + asm3.solver.solve(obj.Proxy.getAssembly().Object) + except RuntimeError as e: + logger.error(e) + return self._draggingPlacement + + def onDragEnd(self): + for doc in self._draggingUndos: + doc.commitTransaction() + self._draggingUndos.clear() + + def unsetEdit(self,_vobj,_mode): + self._draggingPart = None + self._draggingOffset = None + self._draggingOffsetInv = None + self._draggingUndos = None + self._draggingPlacement = None + return False class AsmConstraint(AsmGroup): diff --git a/gui.py b/gui.py index 0162d4e..54e69b4 100644 --- a/gui.py +++ b/gui.py @@ -1,7 +1,7 @@ from future.utils import with_metaclass import FreeCAD, FreeCADGui from asm3.utils import logger,objName,addIconToFCAD -from asm3.assembly import Assembly,AsmConstraint +from asm3.assembly import isTypeOf,Assembly,AsmConstraint,AsmElementLink from asm3.proxy import ProxyType class SelectionObserver: @@ -103,7 +103,34 @@ class AsmCmdMove(AsmCmdBase): _id = 2 _menuText = 'Move part' _iconName = 'Assembly_Move.svg' + _useCenterballDragger = True + + @classmethod + def getSelection(cls): + sels = FreeCADGui.Selection.getSelection() + if len(sels)==1 and isTypeOf(sels[0],AsmElementLink): + return sels[0].ViewObject def Activated(self): - pass + vobj = self.getSelection() + if vobj: + doc = FreeCADGui.editDocument() + if doc: + doc.resetEdit() + vobj.UseCenterballDragger = self._useCenterballDragger + vobj.doubleClicked() + + @classmethod + def checkActive(cls): + cls._active = True if cls.getSelection() else False + + @classmethod + def deactive(cls): + cls._active = False + +class AsmCmdAxialMove(AsmCmdMove): + _id = 3 + _menuText = 'Axial move part' + _iconName = 'Assembly_AxialMove.svg' + _useCenterballDragger = False