Control.ViewProviderControlProxy Class Reference

Proxy class for Gui.ViewProviderDocumentObject Control.ViewObject. More...

Public Member Functions

def __init__ (self, vp)
 Initialization method for ViewProviderControlProxy. More...
 
def attach (self, vp)
 Method called by FreeCAD after initialization. More...
 
def claimChildren (self)
 Method called by FreeCAD to retrieve assigned children. More...
 
def canDropObject (self, obj)
 Method called by FreeCAD to ask if an object obj can be dropped into a Group. More...
 
def getIcon (self)
 Method called by FreeCAD to supply an icon for the Tree View. More...
 
def setProperties (self, vp)
 Method to hide unused properties. More...
 
def doubleClicked (self, vp)
 Method called by FreeCAD when Control is double-clicked in the Tree View. More...
 
def setupContextMenu (self, vp, menu)
 Method called by the FreeCAD to customize a context menu for a Control. More...
 
def __getstate__ (self)
 Necessary method to avoid errors when trying to save unserializable objects. More...
 
def __setstate__ (self, state)
 Necessary method to avoid errors when trying to restore unserializable objects. More...
 

Static Public Attributes

 panel = None
 A ControlPanel if one is active or None. More...
 
 fp = None
 A Control object. More...
 

Detailed Description

Proxy class for Gui.ViewProviderDocumentObject Control.ViewObject.

A ViewProviderControlProxy instance provides a Control's icon, double-click response and context menu with "Show control panel".

To connect this Proxy object to a Gui.ViewProviderDocumentObject Control.ViewObject do:

a = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroupPython",
"Control")
ViewProviderControlProxy(a.ViewObject)

Definition at line 1238 of file Control.py.

Constructor & Destructor Documentation

◆ __init__()

def Control.ViewProviderControlProxy.__init__ (   self,
  vp 
)

Initialization method for ViewProviderControlProxy.

A class instance is created and made a Proxy for a generic Gui.ViewProviderDocumentObject Control.ViewObject. During initialization number of properties are specified and preset.

Parameters
vpA barebone Gui.ViewProviderDocumentObject Control.ViewObject.

Definition at line 1258 of file Control.py.

1258  def __init__(self, vp):
1259  self.setProperties(vp)
1260  vp.Proxy = self
1261 

Member Function Documentation

◆ __getstate__()

def Control.ViewProviderControlProxy.__getstate__ (   self)

Necessary method to avoid errors when trying to save unserializable objects.

This method is used by JSON to serialize unserializable objects during autosave. Without this an Error would rise when JSON would try to do that itself.

We need this for unserializable fp attribute, but we don't serialize it, because it's enough to reset it when object is restored.

Returns
None, because we don't serialize anything.

Definition at line 1401 of file Control.py.

1401  def __getstate__(self):
1402  return None
1403 

◆ __setstate__()

def Control.ViewProviderControlProxy.__setstate__ (   self,
  state 
)

Necessary method to avoid errors when trying to restore unserializable objects.

This method is used during a document restoration. We need this for unserializable fp attribute, but we do not restore it, because it's enough to reset it.

Definition at line 1411 of file Control.py.

1411  def __setstate__(self, state):
1412  pass
1413 
1414 

◆ attach()

def Control.ViewProviderControlProxy.attach (   self,
  vp 
)

Method called by FreeCAD after initialization.

This method adds Control as the fp attribute.

Parameters
vpA Control.ViewObject after initialization.

Definition at line 1270 of file Control.py.

1270  def attach(self, vp):
1271  # Add feature python as it's necessary to claimChildren
1272  self.fp = vp.Object
1273 

◆ canDropObject()

def Control.ViewProviderControlProxy.canDropObject (   self,
  obj 
)

Method called by FreeCAD to ask if an object obj can be dropped into a Group.

FreeCAD objects of a Server, Trajectory and CollisionDetector type are allowed to drop inside a Control group.

Parameters
objA FreeCAD object hovering above a Control item in the Tree View.

Definition at line 1298 of file Control.py.

1298  def canDropObject(self, obj):
1299  # Allow only some objects to be dropped into the Control group
1300  if hasattr(obj, "Proxy") and \
1301  (obj.Proxy.__class__.__name__ == "ServerProxy" or
1302  obj.Proxy.__class__.__name__ == "TrajectoryProxy" or
1303  obj.Proxy.__class__.__name__ == "CollisionDetectorProxy" or
1304  obj.Proxy.__class__.__name__ == "RobWorldProxy" or
1305  obj.Proxy.__class__.__name__ == "RobRotationProxy" or
1306  obj.Proxy.__class__.__name__ == "RobTranslationProxy"):
1307  return True
1308  return False
1309 

◆ claimChildren()

def Control.ViewProviderControlProxy.claimChildren (   self)

Method called by FreeCAD to retrieve assigned children.

When a property of a Control is touched the Control and the FreeCAD ActiveDocument are notified. The FreeCAD ActiveDocument then emits a signal to inform all its observers e.g. the FreeCADGui ActiveDocument. The FreeCADGui document then emits a new signal to inform e.g. the tree view. The tree view then invokes claimChildren().

Definition at line 1283 of file Control.py.

1283  def claimChildren(self):
1284  if hasattr(self, "fp"):
1285  if self.fp:
1286  return self.fp.Group
1287  return []
1288 

◆ doubleClicked()

def Control.ViewProviderControlProxy.doubleClicked (   self,
  vp 
)

Method called by FreeCAD when Control is double-clicked in the Tree View.

If no dialog is opened in the Task View, a new ControlPanel is opened. If a ControlPanel is already opened, the Model tab on the Combo View is swapped for the Tasks tab so that the panel becomes visible. If another dialog is opened a warning is shown.

Parameters
vpA Gui.ViewProviderDocumentObject Control.ViewObject.

Definition at line 1345 of file Control.py.

1345  def doubleClicked(self, vp):
1346  # Switch to the Task View if a Control panel is already opened
1347  if self.panel:
1348  FreeCADGui.Control.showTaskView()
1349 
1350  # Try to open new Control panel
1351  else:
1352  # Load the QDialog from a file and name it after this object
1353  form = FreeCADGui.PySideUic.loadUi(
1354  path.join(PATH_TO_UI, "AnimationControl.ui"))
1355  form.setWindowTitle(vp.Object.Label)
1356 
1357  # Create a control panel and try to show it
1358  self.panel = ControlPanel(vp.Object, form)
1359  try:
1360  FreeCADGui.Control.showDialog(self.panel)
1361  except RuntimeError as e:
1362  self.panel = None
1363  if str(e) == "Active task dialog found":
1364  QMessageBox.warning(None,
1365  'Error while opening control panel',
1366  "A panel is already active on "
1367  + "the Tasks tab of the Combo View.")
1368  FreeCADGui.Control.showTaskView()
1369  return True
1370 

◆ getIcon()

def Control.ViewProviderControlProxy.getIcon (   self)

Method called by FreeCAD to supply an icon for the Tree View.

A full path to an icon is supplied for the FreeCADGui.

Returns
A str path to an icon.

Definition at line 1318 of file Control.py.

1318  def getIcon(self):
1319  return path.join(PATH_TO_ICONS, "Control.png")
1320 

◆ setProperties()

def Control.ViewProviderControlProxy.setProperties (   self,
  vp 
)

Method to hide unused properties.

Properties Display Mode, Visibility are set to be invisible as they are unused.

Parameters
vpA Gui.ViewProviderDocumentObject Control.ViewObject.

Definition at line 1329 of file Control.py.

1329  def setProperties(self, vp):
1330  # Hide unnecessary view properties
1331  vp.setEditorMode("DisplayMode", 2)
1332  vp.setEditorMode("Visibility", 2)
1333 

◆ setupContextMenu()

def Control.ViewProviderControlProxy.setupContextMenu (   self,
  vp,
  menu 
)

Method called by the FreeCAD to customize a context menu for a Control.

The Transform and Set colors... items are removed from the context menu shown upon right click on DocumentObjectGroupPython Control in the Tree View. The option to Show control panel is added instead.

Parameters
vpA right-clicked Gui.ViewProviderDocumentObject Control.ViewObject.
menuA Qt's QMenu to be edited.

Definition at line 1382 of file Control.py.

1382  def setupContextMenu(self, vp, menu):
1383  # Add an option to open the Control panel
1384  menu.clear()
1385  action = menu.addAction("Show control panel")
1386  action.triggered.connect(lambda f=self.doubleClicked, arg=vp: f(arg))
1387 

Member Data Documentation

◆ fp

Control.ViewProviderControlProxy.fp = None
static

A Control object.

Definition at line 1246 of file Control.py.

◆ panel

Control.ViewProviderControlProxy.panel = None
static

A ControlPanel if one is active or None.

Definition at line 1245 of file Control.py.


The documentation for this class was generated from the following file: