Exemplo n.º 1
1
 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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 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...
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def create(doc, callback):
    '''
    Creation method for _Document class
    '''
    if _saveObserver.instance() is None:
        App.addDocumentObserver(_saveObserver(doc))
    else:
        _saveObserver.instance().set_document(doc)
Exemplo n.º 6
0
    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]
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
    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]
Exemplo n.º 10
0
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)
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
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
Exemplo n.º 15
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)
Exemplo n.º 17
0
 def Activated(self):
     FreeCAD.addDocumentObserver(self.docObserver)
     from .gui import AsmCmdManager
     for cmd in AsmCmdManager.getInfo().Types:
         cmd.workbenchActivated()
Exemplo n.º 18
0
 def attach(cls):
     if cls._instance is None:
         cls._instance = cls()
         App.addDocumentObserver(cls._instance)
Exemplo n.º 19
0
 def Activated(self):
     import a2p_observers
     FreeCAD.addDocumentObserver(a2p_observers.redoUndoObserver)
Exemplo n.º 20
0
 def Activated(self):
     "This function is executed when the workbench is activated"
     print("Activated")
     self.obs = self.MyObserver()
     FreeCAD.addDocumentObserver(self.obs)
     return
Exemplo n.º 21
0
        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()
Exemplo n.º 22
0
 def attach(cls):
     if cls._instance is None:
         cls._instance = cls()
         App.addDocumentObserver(cls._instance)
Exemplo n.º 23
0
                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))

Exemplo n.º 24
0
 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...
Exemplo n.º 25
0
def StartKneeSimulation():
	StopKneeSimulation()
	_calculateKnees()
	_calculateSwivels()
	FreeCAD.kneeObserver=KneeObserver()
	FreeCAD.addDocumentObserver(FreeCAD.kneeObserver)