43 PATH_TO_ICONS = path.join(FreeCAD.getHomePath(),
"Mod",
"Animate",
"Resources",
89 if prop ==
"Placement":
91 if hasattr(fp,
"Group")
and len(fp.Group) != 0:
92 for child
in fp.Group:
93 child.ParentFramePlacement = fp.Placement
106 rotation = FreeCAD.Rotation(fp.AngleYaw, fp.AnglePitch, fp.AngleRoll)
107 rotation_center = FreeCAD.Vector(0, 0, 0)
108 position = FreeCAD.Vector(fp.PositionX, fp.PositionY, fp.PositionZ)
109 fp.Placement = FreeCAD.Placement(position, rotation, rotation_center)
122 fp.ViewObject.Proxy.setProperties(fp.ViewObject)
138 if not hasattr(fp,
"AllowServer"):
139 fp.addProperty(
"App::PropertyBool",
"AllowServer",
"General",
140 "Should this object allow a Server object to " 141 +
"change it.").AllowServer =
True 144 if not hasattr(fp,
"PositionX"):
145 fp.addProperty(
"App::PropertyFloat",
"PositionX",
"FramePlacement",
146 "X position of the world frame.").PositionX = 0
147 if not hasattr(fp,
"PositionY"):
148 fp.addProperty(
"App::PropertyFloat",
"PositionY",
"FramePlacement",
149 "Y position of the world frame.").PositionY = 0
150 if not hasattr(fp,
"PositionZ"):
151 fp.addProperty(
"App::PropertyFloat",
"PositionZ",
"FramePlacement",
152 "Z position of the world frame.").PositionZ = 0
153 if not hasattr(fp,
"AngleYaw"):
154 fp.addProperty(
"App::PropertyFloat",
"AngleYaw",
"FramePlacement",
155 "Yaw angle (rotation about Z axis) of the world" 156 +
" frame in degrees.").AngleYaw = 0
157 if not hasattr(fp,
"AnglePitch"):
158 fp.addProperty(
"App::PropertyFloat",
"AnglePitch",
159 "FramePlacement",
"Pitch angle (rotation about Y" 160 +
" axis) of the world frame in degrees." 162 if not hasattr(fp,
"AngleRoll"):
163 fp.addProperty(
"App::PropertyFloat",
"AngleRoll",
"FramePlacement",
164 "Roll angle (rotation about X axis) of the world" 165 +
" frame in degrees.").AngleRoll = 0
168 if not hasattr(fp,
"ShowFrame"):
169 fp.addProperty(
"App::PropertyBool",
"ShowFrame",
"Frame",
170 "Show a frame for current pose." 172 if not hasattr(fp,
"FrameTransparency"):
173 fp.addProperty(
"App::PropertyPercent",
"FrameTransparency",
174 "Frame",
"Transparency of the frame in percents." 175 ).FrameTransparency = 0
176 if not hasattr(fp,
"ShowFrameArrowheads"):
177 fp.addProperty(
"App::PropertyBool",
"ShowFrameArrowheads",
"Frame",
178 "Show arrowheads for frame axis arrow's." 179 ).ShowFrameArrowheads =
True 180 if not hasattr(fp,
"FrameArrowheadLength"):
181 fp.addProperty(
"App::PropertyFloatConstraint",
182 "FrameArrowheadLength",
"Frame",
183 "Frame axis arrow's arrowhead length.\n" 184 +
"Range is < 1.0 | 1e6 >." 185 ).FrameArrowheadLength = (10, 1.0, 1e6, 1)
187 fp.FrameArrowheadLength = (fp.FrameArrowheadLength, 1.0, 1e6, 1)
188 if not hasattr(fp,
"FrameArrowheadRadius"):
189 fp.addProperty(
"App::PropertyFloatConstraint",
190 "FrameArrowheadRadius",
"Frame",
191 "Frame axis arrow's arrowhead bottom radius.\n" 192 +
"Range is < 0.5 | 1e6 >." 193 ).FrameArrowheadRadius = (5, 0.5, 1e6, 0.5)
195 fp.FrameArrowheadRadius = (fp.FrameArrowheadRadius, 0.5, 1e6, 0.5)
196 if not hasattr(fp,
"ShaftLength"):
197 fp.addProperty(
"App::PropertyFloatConstraint",
"ShaftLength",
198 "Frame",
"Frame axis arrow's shaft length.\n" 199 +
"Range is < 1.0 | 1e6 >." 200 ).ShaftLength = (20, 1.0, 1e6, 1)
202 fp.ShaftLength = (fp.ShaftLength, 1.0, 1e6, 1)
203 if not hasattr(fp,
"ShaftWidth"):
204 fp.addProperty(
"App::PropertyFloatConstraint",
"ShaftWidth",
205 "Frame",
"Frame axis arrow's shaft width.\n" 206 +
"Range is < 1.0 | 64 >." 207 ).ShaftWidth = (4, 1.0, 64, 1)
209 fp.ShaftWidth = (fp.ShaftWidth, 1.0, 64, 1)
210 if not hasattr(fp,
"ShowFrameLabels"):
211 fp.addProperty(
"App::PropertyBool",
"ShowFrameLabels",
212 "Frame",
"Show label for frame axes." 213 ).ShowFrameLabels =
True 216 if not hasattr(fp,
"FontSize"):
217 fp.addProperty(
"App::PropertyIntegerConstraint",
"FontSize",
218 "Labels",
"Label font size.\n" 219 +
"Range is < 1 | 100 >." 220 ).FontSize = (10, 1, 100, 1)
222 fp.FontSize = (fp.FontSize, 1, 100, 1)
223 if not hasattr(fp,
"DistanceToAxis"):
224 fp.addProperty(
"App::PropertyFloatConstraint",
"DistanceToAxis",
225 "Labels",
"Distance from label to its axis.\n" 226 +
"Range is < 0.5 | 1e6 >." 227 ).DistanceToAxis = (5, 0.5, 1e6, 0.5)
229 fp.DistanceToAxis = (fp.DistanceToAxis, 0.5, 1e6, 0.5)
230 if not hasattr(fp,
"Subscription"):
231 fp.addProperty(
"App::PropertyString",
"Subscription",
"Labels",
232 "Subscription added to an axis name." 234 if not hasattr(fp,
"Superscription"):
235 fp.addProperty(
"App::PropertyString",
"Superscription",
"Labels",
236 "Superscription added to an axis name." 237 ).Superscription =
"" 238 if not hasattr(fp,
"FontFamily"):
239 fp.addProperty(
"App::PropertyEnumeration",
"FontFamily",
240 "Labels",
"Label font family." 241 ).FontFamily = [
"SERIF",
"SANS",
"TYPEWRITER"]
242 if not hasattr(fp,
"FontStyle"):
243 fp.addProperty(
"App::PropertyEnumeration",
"FontStyle",
244 "Labels",
"Label font style." 245 ).FontStyle = [
"NONE",
"BOLD",
"ITALIC",
249 if not hasattr(fp,
"Placement"):
250 fp.addProperty(
"App::PropertyPlacement",
"Placement",
"Base",
251 "Current placement for animated objects in " 255 fp.setEditorMode(
"Placement", 2)
257 import AnimateDocumentObserver
367 frame.insertChild(self.
font, 1)
369 self.
frame.addChild(frame)
376 vp.Object.Proxy.setProperties(vp.Object)
393 if prop ==
"Placement" and hasattr(fp,
"Placement"):
394 trans = fp.Placement.Base
395 rot = fp.Placement.Rotation
401 elif prop ==
"ShowFrame" and hasattr(fp,
"ShowFrame"):
403 self.
frame.whichChild.setValue(coin.SO_SWITCH_ALL)
405 self.
frame.whichChild.setValue(coin.SO_SWITCH_NONE)
407 elif prop ==
"FrameTransparency" and hasattr(fp,
"FrameTransparency"):
409 setValue(0xff0000ff - (0xff*fp.FrameTransparency)//100)
411 setValue(0x00ff00ff - (0xff*fp.FrameTransparency)//100)
413 setValue(0x0000ffff - (0xff*fp.FrameTransparency)//100)
415 elif prop ==
"ShaftLength" and hasattr(fp,
"ShaftLength"):
416 self.
frame_shaft.vertexProperty.getValue().vertex.\
417 set1Value(1, 0, fp.ShaftLength, 0)
418 if hasattr(fp,
"FrameArrowheadLength"):
420 0, fp.ShaftLength + fp.FrameArrowheadLength/2, 0)
421 if not fp.ShowFrameArrowheads
and hasattr(fp,
"DistanceToAxis"):
423 0, fp.ShaftLength + fp.DistanceToAxis, 0)
425 elif prop ==
"FrameArrowheadLength" and \
426 hasattr(fp,
"FrameArrowheadLength"):
428 if hasattr(fp,
"ShaftLength"):
430 0, fp.ShaftLength + fp.FrameArrowheadLength/2, 0)
431 if fp.ShowFrameArrowheads
and hasattr(fp,
"DistanceToAxis"):
433 0, fp.FrameArrowheadLength/2 + fp.DistanceToAxis, 0)
435 elif prop ==
"ShaftWidth" and hasattr(fp,
"ShaftWidth"):
438 elif prop ==
"FrameArrowheadRadius" and \
439 hasattr(fp,
"FrameArrowheadRadius"):
441 fp.FrameArrowheadRadius)
443 elif prop ==
"ShowFrameArrowheads" and \
444 hasattr(fp,
"ShowFrameArrowheads"):
445 if fp.ShowFrameArrowheads:
447 if hasattr(fp,
"FrameArrowheadLength")
and \
448 hasattr(fp,
"DistanceToAxis"):
450 0, fp.FrameArrowheadLength/2 + fp.DistanceToAxis, 0)
453 if hasattr(fp,
"ShaftLength")
and \
454 hasattr(fp,
"DistanceToAxis"):
456 0, fp.ShaftLength + fp.DistanceToAxis, 0)
458 elif prop ==
"ShowFrameLabels" and hasattr(fp,
"ShowFrameLabels"):
459 for label
in self.
labels[:3]:
460 if fp.ShowFrameLabels:
461 label.whichChild.setValue(coin.SO_SWITCH_ALL)
463 label.whichChild.setValue(coin.SO_SWITCH_NONE)
466 elif prop ==
"Subscription" and hasattr(fp,
"Subscription"):
468 l.string.setValues(2, 1, [fp.Subscription])
470 elif prop ==
"Superscription" and hasattr(fp,
"Superscription"):
472 l.string.setValues(0, 1, [fp.Superscription])
474 elif prop ==
"FontFamily" and hasattr(fp,
"FontFamily"):
475 if fp.FontFamily ==
"SERIF":
476 self.
font.family.setValue(self.
font.SERIF)
477 if fp.FontFamily ==
"SANS":
478 self.
font.family.setValue(self.
font.SANS)
479 if fp.FontFamily ==
"TYPEWRITER":
480 self.
font.family.setValue(self.
font.TYPEWRITER)
482 elif prop ==
"FontStyle" and hasattr(fp,
"FontStyle"):
483 if fp.FontStyle ==
"NONE":
484 self.
font.style.setValue(self.
font.NONE)
485 if fp.FontStyle ==
"BOLD":
486 self.
font.style.setValue(self.
font.BOLD)
487 if fp.FontStyle ==
"ITALIC":
488 self.
font.style.setValue(self.
font.ITALIC)
489 if fp.FontStyle ==
"BOLD ITALIC":
490 self.
font.style.setValue(self.
font.BOLD | self.
font.ITALIC)
492 elif prop ==
"FontSize" and hasattr(fp,
"FontSize"):
493 self.
font.size.setValue(fp.FontSize)
495 elif prop ==
"DistanceToAxis" and hasattr(fp,
"DistanceToAxis")
and \
496 hasattr(fp,
"ShowFrameArrowheads"):
497 if fp.ShowFrameArrowheads
and hasattr(fp,
"FrameArrowheadLength"):
499 0, fp.FrameArrowheadLength/2 + fp.DistanceToAxis, 0)
500 elif hasattr(fp,
"ShaftLength"):
502 0, fp.ShaftLength + fp.DistanceToAxis, 0)
515 if prop ==
"Visibility":
531 if hasattr(self,
"fp")
and self.
fp:
545 if hasattr(obj,
"Proxy")
and \
546 (obj.Proxy.__class__.__name__ ==
"RobRotationProxy" or 547 obj.Proxy.__class__.__name__ ==
"RobTranslationProxy"):
560 return path.join(PATH_TO_ICONS,
"RobWorld.png")
598 vp.setEditorMode(
"DisplayMode", 2)
639 label_strings = [
"X",
"Y",
"Z"]
640 colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF]
649 label_group = coin.SoSeparator()
651 frame_axis_color = coin.SoPackedColor()
652 frame_axis_color.orderedRGBA.setValue(colors[i])
653 label_group.addChild(frame_axis_color)
656 0, 3, [
"", label_strings[i],
""])
661 self.
labels.append(coin.SoSwitch())
662 self.
labels[i].addChild(label_group)
678 shaft_vertices = coin.SoVertexProperty()
679 shaft_vertices.vertex.setNum(2)
680 shaft_vertices.vertex.set1Value(0, 0, 0, 0)
682 self.
frame_shaft.vertexProperty.setValue(shaft_vertices)
696 rot_y2x = coin.SoRotation()
697 rot_y2x.rotation.setValue(coin.SbRotation(coin.SbVec3f(0, 1, 0),
698 coin.SbVec3f(1, 0, 0)))
699 rot_y2z = coin.SoRotation()
700 rot_y2z.rotation.setValue(coin.SbRotation(coin.SbVec3f(0, 1, 0),
701 coin.SbVec3f(0, 0, 1)))
709 x_arrow = coin.SoSeparator()
710 x_arrow.addChild(rot_y2x)
714 x_arrow.addChild(frame_labels[0])
715 y_arrow = coin.SoSeparator()
719 y_arrow.addChild(frame_labels[1])
720 z_arrow = coin.SoSeparator()
721 z_arrow.addChild(rot_y2z)
725 z_arrow.addChild(frame_labels[2])
731 separated_frame = coin.SoSeparator()
733 separated_frame.addChild(x_arrow)
734 separated_frame.addChild(y_arrow)
735 separated_frame.addChild(z_arrow)
737 return separated_frame
758 return {
'Pixmap': path.join(PATH_TO_ICONS,
"RobWorldCmd.png"),
759 'MenuText':
"RobWorld",
760 'ToolTip':
"Create RobWorld instance."}
771 doc = FreeCAD.ActiveDocument
772 a = doc.addObject(
"App::DocumentObjectGroupPython",
"RobWorld")
790 if FreeCAD.ActiveDocument
is None:
def __init__(self, fp)
Initialization method for RobWorldProxy.
Proxy class for a DocumentObjectGroupPython RobWorld instance.
def attach(self, vp)
Method called by FreeCAD after initialization to attach Coin3D constructs.
frame_color_x
A SoPackedColor red color for an X axis.
def Activated(self)
Method used as a callback when the toolbar button or the menu item is clicked.
def doubleClicked(self, vp)
Method called by FreeCAD when RobWorld is double-clicked in the Tree View.
def addObserver()
Adds an AnimateDocumentObserver between FreeCAD's document observers safely.
labels
A list of SoSwitches containing colored translated labels.
def onChanged(self, vp, prop)
Method called after RobWorld.ViewObject was changed.
def execute(self, fp)
Method called when recomputing a DocumentObjectGroupPython.
def __setstate__(self, state)
Necessary method to avoid errors when trying to restore unserializable objects.
Proxy class for Gui.ViewProviderDocumentObject RobWorld.ViewObject.
def makeFrame(self, frame_labels)
Method which makes a Coin3D frame to show a current pose in a RobWorld.
def onDocumentRestored(self, fp)
Method called when document is restored to make sure everything is as it was.
def makeLabels(self)
Method which makes Coin3D labels to be displayed in the FreeCAD View.
frame_color_y
A SoPackedColor green color for an Y axis.
visualisations
A SoSwitch with all visualisations (frame & rotation axis).
def onChanged(self, fp, prop)
Method called after DocumentObjectGroupPython RobWorld was changed.
label_texts
A list of SoText2s labels denoting all axes and an origin.
def __init__(self, vp)
Initialization method for ViewProviderRobWorldProxy.
tf_object2world
A SoTransform transformation from object to world frame.
def updateData(self, fp, prop)
Method called after DocumentObjectGroupPython RobWorld was changed.
def setProperties(self, fp)
Method to set properties during initialization or document restoration.
def getIcon(self)
Method called by FreeCAD to supply an icon for the Tree View.
def claimChildren(self)
Method called by FreeCAD to retrieve assigned children.
def __getstate__(self)
Necessary method to avoid errors when trying to save unserializable objects.
def canDropObject(self, obj)
Method called by FreeCAD to ask if an object obj can be dropped into a Group.
frame
A SoSeparator with a coordinate frame made from 3 RGB arrows.
def setupContextMenu(self, vp, menu)
Method called by the FreeCAD to customize a context menu for a RobWorld.
def GetResources(self)
Method used by FreeCAD to retrieve resources to use for this command.
def IsActive(self)
Method to specify when the toolbar button and the menu item are enabled.
frame_arrowhead_translation
A SoTranslation moving frame arrowheads.
Class specifying Animate workbench's RobWorld button/command.
frame_shaft
A SoLineSet shaft for frame axes.
frame_color_z
A SoPackedColor blue color for an Z axis.
frame_arrowhead_cone
A SoCone arrowhead cone for frame axes.
frame_arrowhead
A SoSwitch translated cone for frame axes.
label_translations
A list of SoTranslations moving labels.
frame_drawstyle
A SoDrawStyle controlling frame axes shaft line width.
def setProperties(self, vp)
Method to hide unused properties.
font
A SoFontStyle font for axes labels.