FreeCAD C++
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Gui::ViewProvider Class Reference

#include <Mod/Raytracing/Gui/ViewProvider.h>

Detailed Description

General interface for all visual stuff in FreeCAD This class is used to generate and handle all around visualizing and presenting objects from the FreeCAD App layer to the user. This class and its descendents have to be implemented for any object type in order to show them in the 3DView and TreeView.

Public Member Functions

 ViewProvider ()
 constructor.
 
virtual ~ViewProvider ()
 destructor.
 
virtual std::vector< App::DocumentObject * > claimChildren3D (void) const
 
void update (const App::Property *)
 
unsigned long getStatus () const
 return the status bits
 
virtual bool keyPressed (bool pressed, int key)
 is called when the provider is in edit and a key event occurs. Only ESC ends edit.
 
virtual bool doubleClicked (void)
 is called by the tree if the user double click on the object
 
virtual bool mouseMove (const SbVec2s &cursorPos, View3DInventorViewer *viewer)
 is called when the provider is in edit and the mouse is moved
 
virtual bool mouseButtonPressed (int button, bool pressed, const SbVec2s &cursorPos, const View3DInventorViewer *viewer)
 is called when the Provider is in edit and the mouse is clicked
 
virtual void setupContextMenu (QMenu *, QObject *, const char *)
 set up the context-menu with the supported edit modes
 
Selection handling

This group of methods do the selection handling. Here you can define how the selection for your ViewProfider works.

virtual bool useNewSelectionModel (void) const
 indicates if the ViewProvider use the new Selection model
 
virtual bool isSelectable (void) const
 indicates if the ViewProvider can be selected
 
virtual std::string getElement (const SoDetail *) const
 return a hit element to the selection path or 0
 
virtual SoDetail * getDetail (const char *) const
 
virtual std::vector< Base::Vector3dgetModelPoints (const SoPickedPoint *) const
 
virtual std::vector< Base::Vector3dgetSelectionShape (const char *Element) const
 return the highlight lines for a given element or the whole shape
 
virtual bool onDelete (const std::vector< std::string > &subNames)
 
virtual bool canDelete (App::DocumentObject *obj) const
 Asks the view provider if the given object that is part of its outlist can be removed from there without breaking it. More...
 
Methods used by the Tree

If you want to take control over the appearance of your object in the tree you can reimplemnt these methods.

virtual QIcon getIcon (void) const
 deliver the icon shown in the tree view
 
virtual std::vector< App::DocumentObject * > claimChildren (void) const
 
Drag and drop

To enable drag and drop you have to re-implement canDragObjects() and canDropObjects() to return true. For finer control you can also re-implement canDragObject() or canDropObject() to filter certain object types, by default these methods don't filter any types. To take action of drag and drop the method dragObject() and dropObject() must be re-implemented, too.

virtual bool canDragObjects () const
 
virtual bool canDragObject (App::DocumentObject *) const
 
virtual bool showInTree () const
 
virtual void dragObject (App::DocumentObject *)
 
virtual bool canDropObjects () const
 
virtual bool canDropObject (App::DocumentObject *) const
 
virtual void dropObject (App::DocumentObject *)
 
virtual void replaceObject (App::DocumentObject *, App::DocumentObject *)
 
Display mode methods
std::string getActiveDisplayMode (void) const
 
virtual void setDisplayMode (const char *ModeName)
 set the display mode
 
virtual const char * getDefaultDisplayMode () const
 get the default display mode
 
virtual std::vector< std::string > getDisplayModes (void) const
 returns a list of all possible display modes
 
virtual void hide (void)
 Hides the view provider.
 
virtual void show (void)
 Shows the view provider.
 
virtual bool isShow (void) const
 checks whether the view provider is visible or not
 
void setVisible (bool)
 
bool isVisible () const
 
virtual void setOverrideMode (const std::string &mode)
 Overrides the display mode with mode.
 
const std::string getOverrideMode ()
 
Task panel

With this interface the ViewProvider can steer the appearance of widgets in the task view

virtual void getTaskViewContent (std::vector< Gui::TaskView::TaskContent * > &) const
 get a list of TaskBoxes associated with this object
 
direct handling methods

This group of methods is to direct influence the appearance of the viewed content. It's only for fast interactions! If you want to set the visual parameters you have to do it on the object viewed by this provider!

virtual void setTransformation (const Base::Matrix4D &rcMatrix)
 set the viewing transformation of the provider
 
virtual void setTransformation (const SbMatrix &rcMatrix)
 
SbMatrix convert (const Base::Matrix4D &rcMatrix) const
 
Display mask modes

Mainly controls an SoSwitch node which selects the display mask modes. The number of display mask modes doesn't necessarily match with the number of display modes. E.g. various display modes like Gaussian curvature, mean curvature or gray values are displayed by one display mask mode that handles color values.

void addDisplayMaskMode (SoNode *node, const char *type)
 Adds a new display mask mode.
 
void setDisplayMaskMode (const char *type)
 Activates the display mask mode type.
 
SoNode * getDisplayMaskMode (const char *type) const
 Get the node to the display mask mode type.
 
std::vector< std::string > getDisplayMaskModes () const
 Returns a list of added display mask modes.
 
void setDefaultMode (int)
 
- Public Member Functions inherited from App::TransactionalObject
 TransactionalObject (void)
 Constructor.
 
- Public Member Functions inherited from App::ExtensionContainer
virtual PropertygetPropertyByName (const char *name) const override
 find a property by its name
 
virtual const char * getPropertyName (const Property *prop) const override
 get the name of a property
 
virtual void getPropertyMap (std::map< std::string, Property * > &Map) const override
 get all properties of the class (including properties of the parent)
 
virtual void getPropertyList (std::vector< Property * > &List) const override
 get all properties of the class (including properties of the parent)
 
virtual short getPropertyType (const Property *prop) const override
 get the Type of a Property
 
virtual short getPropertyType (const char *name) const override
 get the Type of a named Property
 
virtual const char * getPropertyGroup (const Property *prop) const override
 get the Group of a Property
 
virtual const char * getPropertyGroup (const char *name) const override
 get the Group of a named Property
 
virtual const char * getPropertyDocumentation (const Property *prop) const override
 get the Group of a Property
 
virtual const char * getPropertyDocumentation (const char *name) const override
 get the Group of a named Property
 
- Public Member Functions inherited from App::PropertyContainer
 PropertyContainer ()
 
virtual ~PropertyContainer ()
 
void setPropertyStatus (unsigned char bit, bool value)
 set the Status bit of all properties at once
 
bool isReadOnly (const Property *prop) const
 check if the property is read-only
 
bool isReadOnly (const char *name) const
 check if the named property is read-only
 
bool isHidden (const Property *prop) const
 check if the property is hidden
 
bool isHidden (const char *name) const
 check if the named property is hidden
 
- Public Member Functions inherited from Base::Persistence
virtual void SaveDocFile (Writer &) const
 
virtual void RestoreDocFile (Reader &)
 
- Public Member Functions inherited from Base::BaseClass
 BaseClass ()
 Construction.
 
virtual ~BaseClass ()
 Destruction.
 

Public Attributes

Signals of the view provider
boost::signals2::signal< void()> signalChangeIcon
 signal on icon change
 
boost::signals2::signal< void(const QString &)> signalChangeToolTip
 signal on tooltip change
 
boost::signals2::signal< void(const QString &)> signalChangeStatusTip
 signal on status tip change
 

Protected Member Functions

bool checkRecursion (SoNode *)
 
SoPickedPoint * getPointOnRay (const SbVec2s &pos, const View3DInventorViewer *viewer) const
 
SoPickedPoint * getPointOnRay (const SbVec3f &pos, const SbVec3f &dir, const View3DInventorViewer *viewer) const
 
void onChanged (const App::Property *prop)
 Reimplemented from subclass.
 
- Protected Member Functions inherited from App::PropertyContainer
virtual void onBeforeChange (const Property *)
 get called before the value is changed
 

Protected Attributes

SoSeparator * pcRoot
 The root Separator of the ViewProvider.
 
SoTransform * pcTransform
 this is transformation for the provider
 
SoSwitch * pcModeSwitch
 this is the mode switch, all the different viewing modes are collected here
 
SoSeparator * pcAnnotation
 The root separator for annotations.
 

Edit methods

if the Viewprovider goes in edit mode you can handle most of the events in the viewer by yourself

enum  EditMode
 
bool startEditing (int ModNum=0)
 
bool isEditing () const
 
void finishEditing ()
 
virtual void setEditViewer (View3DInventorViewer *, int ModNum)
 adjust viewer settings when editing a view provider
 
virtual void unsetEditViewer (View3DInventorViewer *)
 restores viewer settings when leaving editing mode
 
virtual bool setEdit (int ModNum)
 is called by the document when the provider goes in edit mode
 
virtual void unsetEdit (int ModNum)
 is called when you lose the edit mode
 
int getEditingMode () const
 return the edit mode or -1 if nothing is being edited
 

Additional Inherited Members

- Static Public Member Functions inherited from Base::Persistence
static std::string encodeAttribute (const std::string &)
 Encodes an attribute upon saving.
 

Member Function Documentation

◆ canDelete()

virtual bool Gui::ViewProvider::canDelete ( App::DocumentObject obj) const
virtual

Asks the view provider if the given object that is part of its outlist can be removed from there without breaking it.

Parameters
objis part of the outlist of the object associated to the view provider
Returns
true if the removal is approved by the view provider.

◆ canDragObject()

virtual bool Gui::ViewProvider::canDragObject ( App::DocumentObject ) const
virtual

Check whether the object can be removed from the view provider by drag and drop

◆ canDragObjects()

virtual bool Gui::ViewProvider::canDragObjects ( ) const
virtual

Check whether children can be removed from the view provider by drag and drop

Reimplemented in PartGui::ViewProviderMultiCommon, and PartGui::ViewProviderMultiFuse.

◆ canDropObject()

virtual bool Gui::ViewProvider::canDropObject ( App::DocumentObject ) const
virtual

Check whether the object can be dropped to the view provider by drag and drop

Reimplemented in PartDesignGui::ViewProviderBody.

◆ canDropObjects()

virtual bool Gui::ViewProvider::canDropObjects ( ) const
virtual

Check whether objects can be added to the view provider by drag and drop

Reimplemented in PartDesignGui::ViewProviderBody.

◆ checkRecursion()

bool Gui::ViewProvider::checkRecursion ( SoNode *  )
protected

Helper method to check that the node is valid, i.e. it must not cause and infinite recursion.

◆ claimChildren()

virtual std::vector<App::DocumentObject*> Gui::ViewProvider::claimChildren ( void  ) const
virtual

deliver the children belonging to this object this method is used to deliver the objects to the tree framework which should be grouped under its label. Obvious is the usage in the group but it can be used for any kind of grouping needed for a special purpose.

Reimplemented in PartGui::ViewProviderMultiCommon, PartGui::ViewProviderMultiFuse, and PartDesignGui::ViewProviderSketchBased.

◆ claimChildren3D()

virtual std::vector<App::DocumentObject*> Gui::ViewProvider::claimChildren3D ( void  ) const
virtual

deliver the children belonging to this object this method is used to deliver the objects to the 3DView which should be grouped under its scene graph. This affects the visibility and the 3D position of the object.

◆ dragObject()

virtual void Gui::ViewProvider::dragObject ( App::DocumentObject )
virtual

Remove a child from the view provider by drag and drop

◆ dropObject()

virtual void Gui::ViewProvider::dropObject ( App::DocumentObject )
virtual

Add an object to the view provider by drag and drop

Reimplemented in PartDesignGui::ViewProviderBody.

◆ getPointOnRay() [1/2]

SoPickedPoint* Gui::ViewProvider::getPointOnRay ( const SbVec2s &  pos,
const View3DInventorViewer viewer 
) const
protected

Helper method to get picked entities while editing. It's in the responsibility of the caller to delete the returned instance.

◆ getPointOnRay() [2/2]

SoPickedPoint* Gui::ViewProvider::getPointOnRay ( const SbVec3f &  pos,
const SbVec3f &  dir,
const View3DInventorViewer viewer 
) const
protected

Helper method to get picked entities while editing. It's in the responsibility of the caller to delete the returned instance.

◆ onDelete()

virtual bool Gui::ViewProvider::onDelete ( const std::vector< std::string > &  subNames)
virtual

Get called if the object is about to get deleted. Here you can delete other objects, switch their visibility or prevent the deletion of the object.

Parameters
subNameslist of selected subelements
Returns
true if the deletion is approved by the view provider.

Reimplemented in SketcherGui::ViewProviderSketch.

◆ replaceObject()

virtual void Gui::ViewProvider::replaceObject ( App::DocumentObject ,
App::DocumentObject  
)
virtual

Replace an object to the view provider by drag and drop

Reimplemented in PartGui::ViewProviderMultiCommon, and PartGui::ViewProviderMultiFuse.

◆ showInTree()

virtual bool Gui::ViewProvider::showInTree ( ) const
virtual

Tell the tree view if this object should appear there

◆ update()

void Gui::ViewProvider::update ( const App::Property )

update the content of the ViewProvider this method have to implement the recalculation of the ViewProvider. There are different reasons to update. E.g. only the view attribute has changed, or the data has manipulated.