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)
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()
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()
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)
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)
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)
def activateContainer(container): '''activateContainer(container): activates, and applies visibility automation immediately.''' setActiveContainer(container) if isRunning(): global observerInstance observerInstance.trackActiveContainer()
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()