def __init__(self, info): self.info = info.ElementInfo idx = len(self.info.Subname) if idx: sub = info.SelSubname[:-idx] else: sub = info.SelSubname _, mat = info.SelObj.getSubObject(sub, 1, FreeCAD.Matrix()) pos = utils.getElementPos(self.info.Shape) if not pos: pos = self.info.Shape.BoundBox.Center pos = mat.multiply(pos) self.matrix = mat * self.info.Placement.inverse().toMatrix() base = self.matrix.multiply(self.info.Placement.Base) self.offset = pos - base self.matrix.invert() self.view = info.SelObj.ViewObject.Document.ActiveView self.callbackMove = self.view.addEventCallback("SoLocation2Event", self.moveMouse) self.callbackClick = self.view.addEventCallback( "SoMouseButtonEvent", self.clickMouse) self.callbackKey = self.view.addEventCallback("SoKeyboardEvent", self.keyboardEvent) FreeCAD.setActiveTransaction('Assembly quick move', True) self.active = True
def move(cls, step): ret = cls.getSelection() if not ret: return obj, parent, topParent, subname = ret children = parent.Group i = children.index(obj) j = i + step if j < 0: j = len(children) - 1 elif j >= len(children): j = 0 logger.debug('move {}:{} -> {}:{}'.format(i, objName(obj), j, objName(children[j]))) FreeCAD.setActiveTransaction(cls._menuText) readonly = 'Immutable' in parent.getPropertyStatus('Group') if readonly: parent.setPropertyStatus('Group', '-Immutable') parent.Group = {i: children[j], j: obj} if readonly: parent.setPropertyStatus('Group', 'Immutable') FreeCAD.closeActiveTransaction() # The tree view may deselect the item because of claimChildren changes, # so we restore the selection here FreeCADGui.Selection.addSelection(topParent, subname)
def Activated(cls): from . import solver FreeCAD.setActiveTransaction('Assembly solve') logger.report('command "{}" exception'.format(cls.getName()), solver.solve, reportFailed=True) FreeCAD.closeActiveTransaction()
def Activated(cls): from .assembly import isTypeOf, AsmConstraint FreeCAD.setActiveTransaction('Toggle constraints') try: for obj in FreeCADGui.Selection.getSelection('*'): if isTypeOf(obj, AsmConstraint): obj.Disabled = not obj.Disabled FreeCAD.closeActiveTransaction() except Exception: FreeCAD.closeActiveTransaction(True) raise
def move(cls, step): ret = cls.getSelection() if not ret: return obj, parent = ret children = parent.Group i = children.index(obj) j = i + step if j < 0: j = len(children) - 1 elif j >= len(children): j = 0 logger.debug('move {}:{} -> {}:{}', i, objName(obj), j, objName(children[j])) FreeCAD.setActiveTransaction(cls._menuText) children[i], children[j] = children[j], obj from .assembly import editGroup editGroup(parent, children) FreeCAD.closeActiveTransaction()
def Activated(cls, idx=0): _ = idx from .assembly import Assembly objs = [] for obj in FreeCADGui.Selection.getSelection(): if obj.isDerivedFrom('App::LinkGroup'): objs.append(obj) else: objs = None break filenames = None if not objs: filenames = QtGui.QFileDialog.getOpenFileNames( QtGui.QApplication.activeWindow(), 'Please select file', None, 'STEP (*.stp *.step);;All (*.*)')[0] if not filenames: return FreeCAD.setActiveTransaction('Assembly import') doc = FreeCAD.ActiveDocument if not doc: doc = FreeCAD.newDocument() if filenames: import ImportGui for name in filenames: obj = ImportGui.insert(name, doc.Name, merge=False, useLinkGroup=True, mode=cls.importMode()) if obj: objs.append(obj) for obj in objs: Assembly.fromLinkGroup(obj) FreeCAD.closeActiveTransaction() return