コード例 #1
0
 def slotSavedDocument(self, doc): #emulated - called by polling timer when LastModifiedDate of document changes
     if activeContainer().isDerivedFrom("App::Document"):
         return
     from PartOMagic.Base.Compatibility import tempovis_is_stacky
     if tempovis_is_stacky():
         return
     from PySide import QtGui
     mb = QtGui.QMessageBox()
     mb.setIcon(mb.Icon.Warning)
     mb.setText("It looks like you've just saved your project, but didn't deactivate active container. \n\n"
                "As of now, Part-o-magic doesn't remember visibilities of features outside of active container through save-restore. So this may cause unexpected visibility behavior when you open the document later.\n\n"
                "It is suggested to deactivate active container before saving projects.\n\n"
                "If you click 'Fix and Resave' button, Part-o-magic will deactivate active container, resave the document, and activate the container back.")
     mb.setWindowTitle("Part-o-magic")
     btnClose = mb.addButton(QtGui.QMessageBox.Close)
     btnResave = mb.addButton("Fix and Resave", QtGui.QMessageBox.ButtonRole.ActionRole)
     mb.setDefaultButton(btnClose)
     mb.exec_()
     if mb.clickedButton() is btnResave:
         cnt = activeContainer()
         setActiveContainer(cnt.Document)
         self.poll() #explicit call to poller, to update all visibilities
         cnt.Document.save()
         self.lastMD[App.ActiveDocument.Name] = cnt.Document.LastModifiedDate #to avoid triggering this dialog again
         setActiveContainer(cnt)
コード例 #2
0
ファイル: Observer.py プロジェクト: DeepSOIC/Part-o-magic
 def slotDeletedObject(self, feature):
     print (u"deleted {feat}. container chain: {chain}"
             .format(feat= feature.Name, chain= ".".join([cnt.Name for cnt in GT.getContainerChain(feature)])))
     ac = activeContainer()
     if feature in GT.getContainerChain(ac)+[ac]:
         # active container was deleted. Need to leave it ASAP, as long as we can access the chain
         setActiveContainer(GT.getContainer(feature))
         self.poll()
コード例 #3
0
    def trackActiveContainer(self):
        #watch for changes in active object
        activeBody = Gui.ActiveDocument.ActiveView.getActiveObject("pdbody")
        activePart = Gui.ActiveDocument.ActiveView.getActiveObject("part")
        ac = activeContainer()
        if not App.ActiveDocument.Name in self.activeObjects:
            self.activeObjects[App.ActiveDocument.Name] = (None, None, None)
        last_ac, last_ap, last_ab = self.activeObjects[App.ActiveDocument.Name]
        if (ac, activePart, activeBody) != (
                last_ac, last_ap, last_ab
        ):  #we are tracking activeContainer() too, because it changes when documents are created and deleted
            new_ac = last_ac
            if activeBody != last_ab and activePart != last_ap:
                #both active container fields have changed. Set active whatever is not none, but body has priority
                if activeBody is not None:
                    new_ac = activeBody
                else:
                    new_ac = activePart
            elif activeBody != last_ab:
                #only body field changed
                new_ac = activeBody
            elif activePart != last_ap:
                #only part field changed
                new_ac = activePart
            if new_ac is None:
                new_ac = App.ActiveDocument
            if new_ac is not last_ac:  #unlikely it is false, since we have detected a change....
                if not hasattr(App, 'ActiveContainer'):
                    setActiveContainer(new_ac)
                ac = activeContainer()
                assert (ac is new_ac)

            ac = activeContainer()
            try:
                self.activeContainerChanged(last_ac, ac)
            finally:
                # re-query the ative containers, as they might have been altered by setActiveContainer.
                activeBody = Gui.ActiveDocument.ActiveView.getActiveObject(
                    "pdbody")
                activePart = Gui.ActiveDocument.ActiveView.getActiveObject(
                    "part")
                self.activeObjects[App.ActiveDocument.Name] = (ac, activePart,
                                                               activeBody)
コード例 #4
0
 def slotDeletedObject(self, feature):
     print(u"deleted {feat}. container chain: {chain}".format(
         feat=feature.Name,
         chain=".".join([cnt.Name
                         for cnt in GT.getContainerChain(feature)])))
     ac = activeContainer()
     if feature in GT.getContainerChain(ac) + [ac]:
         # active container was deleted. Need to leave it ASAP, as long as we can access the chain
         setActiveContainer(GT.getContainer(feature))
         self.poll()
コード例 #5
0
ファイル: Observer.py プロジェクト: luzpaz/Part-o-magic
 def slotCreatedObject(self, feature):
     ac = activeContainer()
     aw = Gui.activeWorkbench().GetClassName()
     #hack!! we delay call of addObject to fire from within onChanged, as doing it now
     #results in incorrect parenting of viewproviders. Yet it has to be done before recompute, o
     #therwise the recompute fails.
     #From there, another delayed call is registered - a call to advanceTip, which should be called after the new object is fully set up.
     self.addition_calls_queue.append(
         lambda self=self, feature=feature, ac=ac, aw=aw: self.
         appendToActiveContainer(feature, ac, aw))
コード例 #6
0
ファイル: Observer.py プロジェクト: DeepSOIC/Part-o-magic
 def slotCreatedObject(self, feature):
     print("created object")
     ac = activeContainer()
     aw = Gui.activeWorkbench().GetClassName()
     #hack!! we delay call of addObject to fire from within onChanged, as doing it now 
     #results in incorrect parenting of viewproviders. Yet it has to be done before recompute, o
     #therwise the recompute fails.
     #From there, another delayed call is registered - a call to advanceTip, which should be called after the new object is fully set up.
     self.addition_calls_queue.append(
       lambda self=self, feature=feature, ac=ac, aw=aw:
         self.appendToActiveContainer(feature, ac, aw)
       )
コード例 #7
0
ファイル: Observer.py プロジェクト: DeepSOIC/Part-o-magic
 def slotSavedDocument(self, doc): #emulated - called by polling timer when LastModifiedDate of document changes
     if activeContainer().isDerivedFrom("App::Document"):
         return
     from PySide import QtGui
     mb = QtGui.QMessageBox()
     mb.setIcon(mb.Icon.Warning)
     mb.setText("It looks like you've just saved your project, but didn't deactivate active container. \n\n"
                "As of now, Part-o-magic doesn't remember visibilities of features outside of active container through save-restore. So this may cause unexpected visibility behavior when you open the document later.\n\n"
                "It is suggested to deactivate active container before saving projects.\n\n"
                "If you click 'Fix and Resave' button, Part-o-magic will deactivate active container, resave the document, and activate the container back.")
     mb.setWindowTitle("Part-o-magic")
     btnClose = mb.addButton(QtGui.QMessageBox.Close)
     btnResave = mb.addButton("Fix and Resave", QtGui.QMessageBox.ButtonRole.ActionRole)
     mb.setDefaultButton(btnClose)
     mb.exec_()
     if mb.clickedButton() is btnResave:
         cnt = activeContainer()
         setActiveContainer(cnt.Document)
         self.poll() #explicit call to poller, to update all visibilities
         cnt.Document.save()
         self.lastMD[App.ActiveDocument.Name] = cnt.Document.LastModifiedDate #to avoid triggering this dialog again
         setActiveContainer(cnt)
コード例 #8
0
ファイル: Observer.py プロジェクト: DeepSOIC/Part-o-magic
    def trackActiveContainer(self):
        #watch for changes in active object
        activeBody = Gui.ActiveDocument.ActiveView.getActiveObject("pdbody")
        activePart = Gui.ActiveDocument.ActiveView.getActiveObject("part")
        ac = activeContainer()
        if not App.ActiveDocument.Name in self.activeObjects:
            self.activeObjects[App.ActiveDocument.Name] = (None, None, None)
        last_ac, last_ap, last_ab = self.activeObjects[App.ActiveDocument.Name]
        if (ac, activePart, activeBody) != (last_ac, last_ap, last_ab): #we are tracking activeContainer() too, because it changes when documents are created and deleted
            new_ac = last_ac
            if activeBody != last_ab and activePart != last_ap:
                #both active container fields have changed. Set active whatever is not none, but body has priority
                if activeBody is not None:
                    new_ac = activeBody
                else:
                    new_ac = activePart
            elif activeBody != last_ab:
                #only body field changed
                new_ac = activeBody
            elif activePart != last_ap:
                #only part field changed
                new_ac = activePart
            if new_ac is None:
                new_ac = App.ActiveDocument
            if new_ac is not last_ac: #unlikely it is false, since we have detected a change....
                if not hasattr(App, 'ActiveContainer'):
                    setActiveContainer(new_ac)
                ac = activeContainer()
                assert(ac is new_ac)

            ac = activeContainer()
            try:
                self.activeContainerChanged(last_ac, ac)
            finally:
                # re-query the ative containers, as they might have been altered by setActiveContainer.
                activeBody = Gui.ActiveDocument.ActiveView.getActiveObject("pdbody")
                activePart = Gui.ActiveDocument.ActiveView.getActiveObject("part")
                self.activeObjects[App.ActiveDocument.Name] = (ac, activePart, activeBody)
コード例 #9
0
 def updateVPs(self):
     '''updates many viewprovider properties (except visibility, which is handled by TempoVis objects)'''
     ac = activeContainer()
     
     if ac.isDerivedFrom("App::Document"):
         objects_in = set(App.ActiveDocument.Objects)
     else:
         objects_in = set(  GT.getDirectChildren(ac)  )
     objects_out = set(App.ActiveDocument.Objects) - objects_in
     
     # make all object in context selectable. This is mainly to undo consequences of old behavior of making everything out-of-context non-selectable
     for o in objects_in:
         if hasattr(o.ViewObject, "Selectable"):
             o.ViewObject.Selectable = True
     
     for o in App.ActiveDocument.findObjects("App::Origin"):
         o.ViewObject.Visibility = GT.getContainer(o) is ac
コード例 #10
0
ファイル: Observer.py プロジェクト: DeepSOIC/Part-o-magic
 def updateVPs(self):
     '''updates many viewprovider properties (except visibility, which is handled by TempoVis objets)'''
     ac = activeContainer()
     
     if ac.isDerivedFrom("App::Document"):
         objects_in = set(App.ActiveDocument.Objects)
     else:
         objects_in = set(  GT.getDirectChildren(ac)  )
     objects_out = set(App.ActiveDocument.Objects) - objects_in
     
     # make all object in context selectable. This is mainly to undo consequences of old behavior of making everything out-of-context non-selectable
     for o in objects_in:
         if hasattr(o.ViewObject, "Selectable"):
             o.ViewObject.Selectable = True
     
     for o in App.ActiveDocument.findObjects("App::Origin"):
         o.ViewObject.Visibility = GT.getContainer(o) is ac
コード例 #11
0
 def slotDeletedObject(self, feature):
     ac = activeContainer()
     if feature in GT.getContainerChain(ac)+[ac]:
         # active container was deleted. Need to leave it ASAP, as long as we can access the chain
         setActiveContainer(GT.getContainer(feature))
         self.poll()