def append(self, objName, callerName, fn, data=None): #, events='all' ''' Run fn(data) whenever objName is deleted (by now) if no data, fs() is called if the object 'callerName' is deleted, this listener stop listening for it but it remains working for all other callers ''' # TODO: generate a list for each kind of event #events = events if type(events) is list else [events] if not objName in self.lines: self.lines[objName] = [] self.lines[objName].append((fn, data, callerName)) FreeCAD.addDocumentObserver(self)
def _resume(): """do not call! resume a suspend by calling .release method on keeper object returned by suspend.""" global suspend_counter if suspend_counter == 0: return suspend_counter -= 1 if suspend_counter == 0: App.addDocumentObserver(observerInstance)
def __init__(self, command, source_container): self.defineAttributes() self.command = command command.waiter = self self.source_container = source_container App.addDocumentObserver( self) #this will call slotCreatedObject, eventually...
def create(doc, callback): ''' Creation method for _Document class ''' if _saveObserver.instance() is None: App.addDocumentObserver(_saveObserver(doc)) else: _saveObserver.instance().set_document(doc)
def Activated(self): try: import WorkingPlane from plane import Grid as gr from plane import DocObserver if (self.myDocObserver is None): self.myDocObserver = DocObserver() self.myDocObserver.setLink(self) App.addDocumentObserver(self.myDocObserver) if not (App.ActiveDocument): App.newDocument() Gui.ActiveDocument.ActiveView.setCameraType("Perspective") # FROM DRAFT if hasattr(FreeCADGui, "draftToolBar"): Gui.draftToolBar.Activated() if hasattr(FreeCADGui, "Snapper"): Gui.Snapper.show() import draftutils.init_draft_statusbar as dsb dsb.show_draft_statusbar() # Fix the view of the grid make it as 123D Design App.DraftWorkingPlane.alignToPointAndAxis( App.Vector(0.0, 0.0, 0.0), App.Vector(0, 0, 1), 0.0) # Show the Grid always # g=gridTracker() v = Gui.ActiveDocument.ActiveView # New plane axis 2021-03-22 if (self.planeShow is None): self.planeShow = gr(v) self.planeShow.Activated() # g.ff() #draft Grid --> I will try to remove it in the future Mariwan 2021-03-22 # Show Top view - Isometric always if self.runOnce == True: Gui.ActiveDocument.activeView().viewTop() Gui.activeDocument().activeView().viewIsometric() # Gui.SendMsgToActiveView("ViewFit") for TT in range(1, 10): Gui.ActiveDocument.ActiveView.zoomOut() self.runOnce = False App.Console.PrintLog( "Draft workbench activated Inside Design456.\n") # Turn OFF grid #TODO:Make This permanent Gui.Snapper.grid.off() App.Console.PrintMessage('Design456 workbench loaded\n') return except Exception as err: App.Console.PrintError("'Error: Design456 activation' Failed.\n" "Design456 will not work as expected.\n " "{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)
def get(doc): ''' Factory method to create an observer attached to doc If already created, return it ''' if not doc in ProjectObserver.docs: print('building new observer') ProjectObserver.docs[doc] = ProjectObserver(doc) App.addDocumentObserver(ProjectObserver.docs[doc]) return ProjectObserver.docs[doc]
def start(): global observerInstance if observerInstance is not None: return observerInstance = Observer() App.addDocumentObserver(observerInstance) global timer from PySide import QtCore timer = QtCore.QTimer() timer.setInterval(300) timer.connect(QtCore.SIGNAL("timeout()"), observerInstance.poll)
def get(doc): """ Factory method to create an observer attached to doc If already created, return it """ if not doc in ProjectObserver.docs: ProjectObserver.docs[doc] = ProjectObserver(doc) App.addDocumentObserver(ProjectObserver.docs[doc]) return ProjectObserver.docs[doc]
def makeObject(doc, type_id, name): import FreeCAD obs = Observer(doc) FreeCAD.addDocumentObserver(obs) try: obj = doc.addObject(type_id, name) finally: FreeCAD.removeDocumentObserver(obs) #some objects add extra objects automatically (e.g. Part makes an Origin). Can't prevent their creation. But can delete. for n in obs.new_objects: if n != obj.Name: doc.removeObject(n) return obj
def addObserver(): """ Adds an `AnimateDocumentObserver` between FreeCAD's document observers safely. It's preferred to add an `AnimateDocumentObserver` using this method, because other ways could result in having multiple document observers added to FreeCAD. Having a lot of document observers slows down FreeCAD due to necessity to inform them all about imminent changes and so on. """ # Check FreeCAD doesn't have an AnimateDocumentObserver already assigned # and assign one if not hasattr(FreeCAD, "animate_observer"): FreeCAD.animate_observer = AnimateDocumentObserver() FreeCAD.addDocumentObserver(FreeCAD.animate_observer)
def onStart(): """Start the cube menu.""" start = False try: mw.mainWindowClosed start = True except AttributeError: pass if start: t.stop() t.deleteLater() accessoriesMenu() mw.mainWindowClosed.connect(onClose) observer = DocumentObserver() App.addDocumentObserver(observer)
def initialize(docManager): global __Observer #we only initialize ones if __Observer: return #add the freecad observer __observer = __DocumentObserver(docManager) __guiObserver = __GUIDocumentObserver(docManager) FreeCAD.addDocumentObserver(__observer) FreeCADGui.addDocumentObserver(__guiObserver) __Observer = __ObserverManager(__guiObserver, __observer)
def start(): global observerInstance if observerInstance is not None: return observerInstance = Observer() App.addDocumentObserver(observerInstance) global timer from PySide import QtCore timer = QtCore.QTimer() timer.setInterval(300) timer.connect(QtCore.SIGNAL("timeout()"), observerInstance.poll) timer.start() global suspend_counter suspend_counter = 0
def __init__(self): FreeCAD.addDocumentObserver(self)
def addObserver(): # Check FreeCAD doesn't have an AnimateDocumentObserver already assigned # and assign one if not hasattr(FreeCAD, "animate_observer"): FreeCAD.animate_observer = AnimateDocumentObserver() FreeCAD.addDocumentObserver(FreeCAD.animate_observer)
def Activated(self): FreeCAD.addDocumentObserver(self.docObserver) from .gui import AsmCmdManager for cmd in AsmCmdManager.getInfo().Types: cmd.workbenchActivated()
def attach(cls): if cls._instance is None: cls._instance = cls() App.addDocumentObserver(cls._instance)
def Activated(self): import a2p_observers FreeCAD.addDocumentObserver(a2p_observers.redoUndoObserver)
def Activated(self): "This function is executed when the workbench is activated" print("Activated") self.obs = self.MyObserver() FreeCAD.addDocumentObserver(self.obs) return
Since they have the same names nothing needs to be done. This method is optional""" return mode def __getstate__(self): """ When saving the document this object gets stored using Python's json module.\' Since we have some un-serializable parts here -- the Coin stuff -- we must define this method\' to return a tuple of all serializable objects or None.""" return None def __setstate__(self, state): """ When restoring the serialized object from document we have the chance to set some internals here.\' Since no data were serialized nothing needs to be done here.""" return None FreeCAD.addDocumentObserver(Parameter) def createParameter(): a = FreeCAD.ActiveDocument.addObject("App::FeaturePython", "Parameter") Parameter(a) ViewProviderParameter(a.ViewObject) return a def makeParameter(): FreeCAD.newDocument() FreeCADGui.activateWorkbench("PartWorkbench") FreeCAD.ActiveDocument.addObject("Part::Box", "Box") createParameter()
updateAllGhosts(feature.Document) elif prop_name == 'Placement': if not Containers.isContainer(feature): return if 'Restore' in feature.State: return onContainerPlacementChanged(feature) #stop old observer, if reloading this module if 'observer' in vars(): App.removeDocumentObserver(observer) observer = None #start obsrever observer = Observer() App.addDocumentObserver(observer) def updateAllGhosts(doc): for obj in doc.Objects: if not hasattr(obj, 'Proxy'): continue if hasattr(obj.Proxy, 'updateDeps'): try: obj.Proxy.updateDeps(obj) except Exception as err: App.Console.PrintError( u"Updating dependencies of ghost '{obj}' failed:\n {err}\n" .format(err=str(err), obj=obj.Label))
def __init__(self, command, source_container): self.defineAttributes() self.command = command command.waiter = self self.source_container = source_container App.addDocumentObserver(self) #this will call slotCreatedObject, eventually...
def StartKneeSimulation(): StopKneeSimulation() _calculateKnees() _calculateSwivels() FreeCAD.kneeObserver=KneeObserver() FreeCAD.addDocumentObserver(FreeCAD.kneeObserver)