36 from PySide2.QtWidgets
import QMessageBox
39 ANIMATE_OBJECT_GROUP_CLASSES = [
"TrajectoryProxy",
"ControlProxy",
40 "CollisionDetectorProxy",
"RobWorldProxy",
41 "RobRotationProxy",
"RobTranslationProxy"]
45 ANIMATE_CLASSES = [
"TrajectoryProxy",
"ControlProxy",
"ServerProxy",
46 "CollisionDetectorProxy",
"CollisionProxy",
"RobWorldProxy",
47 "RobRotationProxy",
"RobTranslationProxy"]
50 ALLOWED_IN_CONTROL = [
"TrajectoryProxy",
"ServerProxy",
51 "CollisionDetectorProxy",
"RobWorldProxy",
52 "RobRotationProxy",
"RobTranslationProxy"]
89 cls.
__instance = super(AnimateDocumentObserver,
90 cls).
__new__(cls, *args, **kwargs)
106 FreeCAD.ActiveDocument.openTransaction()
124 if prop ==
"Group" and len(obj.Group) > len(self.
group_before):
126 new_obj = obj.Group[-1]
131 None,
'Forbidden action detected',
132 "Group objects from Animate workbench can group\n" 133 +
"only selected objects from Animate workbench.\n" 134 +
"Check the user guide for more info.")
135 FreeCAD.ActiveDocument.undo()
137 FreeCAD.ActiveDocument.commitTransaction()
144 None,
'Forbidden action detected',
145 "Objects from Animate workbench can be grouped\n" 146 +
"only by selected objects from Animate " 147 +
"workbench.\nCheck the user guide " 149 FreeCAD.ActiveDocument.undo()
151 FreeCAD.ActiveDocument.commitTransaction()
154 elif prop ==
"Group" and len(obj.Group) < len(self.
group_before):
156 removed = set(self.
group_before).difference(set(obj.Group)).pop()
157 if removed.Proxy.__class__.__name__ ==
"CollisionProxy" and \
158 hasattr(obj,
"Proxy")
and not obj.Proxy.resetting
and \
159 not obj.Proxy.checking:
161 None,
'Forbidden action detected',
162 "Collision objects cannot be removed from\n" 163 +
"a CollisionDetector group.")
164 FreeCAD.ActiveDocument.undo()
166 FreeCAD.ActiveDocument.commitTransaction()
180 if not hasattr(obj,
"Proxy"):
183 if obj.Proxy.__class__.__name__ ==
"NoneType":
184 obj_type = obj.Name.rstrip(
'0123456789') +
"Proxy" 186 obj_type = obj.Proxy.__class__.__name__
189 if obj_type
not in ANIMATE_OBJECT_GROUP_CLASSES:
206 if not hasattr(obj,
"Proxy"):
209 if obj.Proxy.__class__.__name__ ==
"NoneType":
210 obj_type = obj.Name.rstrip(
'0123456789') +
"Proxy" 212 obj_type = obj.Proxy.__class__.__name__
215 if obj_type
not in ANIMATE_CLASSES:
236 if not hasattr(obj,
"Proxy"):
239 if obj.Proxy.__class__.__name__ ==
"NoneType":
240 obj_type = obj.Name.rstrip(
'0123456789') +
"Proxy" 242 obj_type = obj.Proxy.__class__.__name__
245 if group.Proxy.__class__.__name__ ==
"NoneType":
246 group_type = group.Name.rstrip(
'0123456789') +
"Proxy" 248 group_type = group.Proxy.__class__.__name__
251 if group_type ==
"TrajectoryProxy" and obj_type ==
"TrajectoryProxy":
255 elif group_type ==
"ControlProxy" and obj_type
in ALLOWED_IN_CONTROL:
258 elif group_type ==
"CollisionDetectorProxy" and \
259 obj.Name.find(
"Collision") != -1:
263 elif (group_type
in [
"RobWorldProxy",
"RobRotationProxy",
264 "RobTranslationProxy"])
and \
265 (obj_type
in [
"RobRotationProxy",
"RobTranslationProxy"]):
296 server_proxy.onDocumentClosed()
331 if not hasattr(FreeCAD,
"animate_observer"):
333 FreeCAD.addDocumentObserver(FreeCAD.animate_observer)
dictionary server_proxies
A dict of document names and ServerProxies in them.
def slotBeforeChangeObject(self, obj, prop)
Qt slot method called when an object in a surveyed document is about to change.
def addObserver()
Adds an AnimateDocumentObserver between FreeCAD's document observers safely.
def slotChangedObject(self, obj, prop)
Qt slot method called when an object in an observed document was changed.
def addServerToNotify(self, server_proxy, document_name)
Method to add a server which needs to be notified when its document is closing.
def isAnimateObject(self, obj)
Method to check whether an object comes from the Animate workbench.
Class that keeps Animate workbench objects in recommended structures.
def animateObjectInForeignGroup(self, obj, group)
Method testing whether an Animate object is in a foreign group object.
__instance
A reference to a singleton.
def isAnimateGroup(self, obj)
Method to check whether a group object comes from the Animate workbench.
def foreignObjectInAnimateGroup(self, obj, group)
Method testing whether a forbidden object is in an Animate group object.
def __new__(cls, *args, **kwargs)
Method creating an AnimateDocumentObserver singleton instance.
group_before
A list of objects inside a group object about to change.
def slotDeletedDocument(self, doc)
Qt slot method called if a document is about to be closed.