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 removeCallbacks(self, abort=False): if not self.active: return self.view.removeEventCallback("SoLocation2Event", self.callbackMove) self.view.removeEventCallback("SoMouseButtonEvent", self.callbackClick) self.view.removeEventCallback("SoKeyboardEvent", self.callbackKey) FreeCAD.closeActiveTransaction(abort) self.active = False self.info = None self.view = None
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 removeCallbacks(self): try: print('Remove callback') self.view.removeEventCallback( "SoLocation2Event", self.callbackMove) self.view.removeEventCallback( "SoMouseButtonEvent", self.callbackClick) self.view.removeEventCallback("SoKeyboardEvent", self.callbackKey) App.closeActiveTransaction(True) self.active = False self.info = None self.view = None except Exception as err: App.Console.PrintError("'remove callback error' Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno) return
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