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

#include <Mod/Mesh/Gui/Selection.h>

Detailed Description

The Selection class The selection singleton keeps track of the selection state of the whole application. It gets messages from all entities which can alter the selection (e.g. tree view and 3D-view) and sends messages to entities which need to keep track on the selection state.

The selection consists mainly out of following information per selected object:

Also the preselection is managed. That means you can add a filter to prevent selection of unwanted objects or subelements.

Public Member Functions

bool addSelection (const char *pDocName, const char *pObjectName=0, const char *pSubName=0, float x=0, float y=0, float z=0)
 Add to selection.
 
bool addSelection (const char *pDocName, const char *pObjectName, const std::vector< std::string > &pSubNames)
 Add to selection with several sub-elements.
 
bool addSelection (const SelectionObject &)
 Add to selection.
 
void rmvSelection (const char *pDocName, const char *pObjectName=0, const char *pSubName=0)
 Remove from selection (for internal use)
 
void setSelection (const char *pDocName, const std::vector< App::DocumentObject * > &)
 Set the selection for a document.
 
void clearSelection (const char *pDocName=0)
 Clear the selection of document pDocName. If the document name is not given the selection of the active document is cleared.
 
void clearCompleteSelection ()
 Clear the selection of all documents.
 
bool isSelected (const char *pDocName, const char *pObjectName=0, const char *pSubName=0) const
 Check if selected.
 
bool isSelected (App::DocumentObject *, const char *pSubName=0) const
 Check if selected.
 
bool setPreselect (const char *pDocName, const char *pObjectName, const char *pSubName, float x=0, float y=0, float z=0)
 set the preselected object (mostly by the 3D view)
 
void rmvPreselect ()
 remove the present preselection
 
void setPreselectCoord (float x, float y, float z)
 sets different coords for the preselection
 
const SelectionChangesgetPreselection (void) const
 returns the present preselection
 
void addSelectionGate (Gui::SelectionGate *gate)
 add a SelectionGate to control what is selectable
 
void rmvSelectionGate (void)
 remove the active SelectionGate
 
unsigned int countObjectsOfType (const Base::Type &typeId, const char *pDocName=0) const
 
unsigned int countObjectsOfType (const char *typeName, const char *pDocName=0) const
 
std::vector< App::DocumentObject * > getObjectsOfType (const Base::Type &typeId, const char *pDocName=0) const
 
std::vector< App::DocumentObject * > getObjectsOfType (const char *typeName, const char *pDocName=0) const
 
template<typename T >
std::vector< T * > getObjectsOfType (const char *pDocName=0) const
 
std::vector< SelObj > getSelection (const char *pDocName=0) const
 
std::vector< Gui::SelectionObjectgetSelectionEx (const char *pDocName=0, Base::Type typeId=App::DocumentObject::getClassTypeId()) const
 
int getAsPropertyLinkSubList (App::PropertyLinkSubList &prop) const
 getAsPropertyLinkSubList fills PropertyLinkSubList with current selection. More...
 
std::vector< SelObj > getCompleteSelection () const
 
unsigned int size (void) const
 Size of selected entities for all documents.
 
- Public Member Functions inherited from Base::Subject< const SelectionChanges & >
 Subject ()
 
virtual ~Subject ()
 
void Attach (Observer< const SelectionChanges & > *ToObserv)
 
void Detach (Observer< const SelectionChanges & > *ToObserv)
 
void Notify (const SelectionChanges & rcReason)
 
Observer< const SelectionChanges & > * Get (const char *Name)
 
void ClearObserver ()
 

Public Attributes

boost::signals2::signal< void(const SelectionChanges &msg)> signalSelectionChanged
 signal on new object
 

Protected Member Functions

 SelectionSingleton ()
 Construction.
 
virtual ~SelectionSingleton ()
 Destruction.
 
void slotDeletedObject (const App::DocumentObject &)
 Observer message from the App doc.
 
App::DocumentgetDocument (const char *pDocName=0) const
 helper to retrieve document by name
 

Additional Inherited Members

- Protected Attributes inherited from Base::Subject< const SelectionChanges & >
std::set< Observer< const SelectionChanges & > * > _ObserverSet
 Vector of attached observers.
 

Member Function Documentation

◆ countObjectsOfType() [1/2]

unsigned int Gui::SelectionSingleton::countObjectsOfType ( const Base::Type typeId,
const char *  pDocName = 0 
) const

Returns the number of selected objects with a special object type It's the convenient way to check if the right objects are selected to perform an operation (GuiCommand). The check also detects base types. E.g. "Part" also fits on "PartImport" or "PartTransform types. If no document name is given the active document is assumed.

◆ countObjectsOfType() [2/2]

unsigned int Gui::SelectionSingleton::countObjectsOfType ( const char *  typeName,
const char *  pDocName = 0 
) const

Does basically the same as the method above unless that it accepts a string literal as first argument. typeName must be a registered type, otherwise 0 is returned.

◆ getAsPropertyLinkSubList()

int Gui::SelectionSingleton::getAsPropertyLinkSubList ( App::PropertyLinkSubList &  prop) const

getAsPropertyLinkSubList fills PropertyLinkSubList with current selection.

Parameters
prop(output). The property object to receive links
Returns
the number of items written to the link

◆ getCompleteSelection()

std::vector<SelObj> Gui::SelectionSingleton::getCompleteSelection ( ) const

Returns a vector of all selection objects of all documents.

◆ getObjectsOfType() [1/3]

std::vector<App::DocumentObject*> Gui::SelectionSingleton::getObjectsOfType ( const Base::Type typeId,
const char *  pDocName = 0 
) const

Returns a vector of objects of type TypeName selected for the given document name pDocName. If no document name is specified the objects from the active document are regarded. If no objects of this document are selected an empty vector is returned.

Note
The vector reflects the sequence of selection.

◆ getObjectsOfType() [2/3]

std::vector<App::DocumentObject*> Gui::SelectionSingleton::getObjectsOfType ( const char *  typeName,
const char *  pDocName = 0 
) const

Does basically the same as the method above unless that it accepts a string literal as first argument. typeName must be a registered type otherwise an empty array is returned.

◆ getObjectsOfType() [3/3]

template<typename T >
std::vector< T * > Gui::SelectionSingleton::getObjectsOfType ( const char *  pDocName = 0) const

A convenience template-based method that returns an array with the correct types already.

◆ getSelection()

std::vector<SelObj> Gui::SelectionSingleton::getSelection ( const char *  pDocName = 0) const

Returns a vector of selection objects If no document name is given the objects of the active are returned. If nothing for this Document is selected an empty vector is returned. The vector reflects the sequence of selection.

◆ getSelectionEx()

std::vector<Gui::SelectionObject> Gui::SelectionSingleton::getSelectionEx ( const char *  pDocName = 0,
Base::Type  typeId = App::DocumentObject::getClassTypeId() 
) const

Returns a vector of selection objects If no document name is given the objects of the active are returned. If nothing for this document is selected an empty vector is returned. The vector reflects the sequence of selection.