Type system class Many of the classes in the FreeCAD must have their type information registered before any instances are created (including, but not limited to: App::Feature, App::Property, Gui::ViewProvider ). More...
#include <Type.h>
Public Types | |
typedef void *(* | instantiationMethod )(void) |
Public Member Functions | |
void * | createInstance (void) |
creates a instance of this type | |
unsigned int | getKey (void) const |
const char * | getName (void) const |
const Type | getParent (void) const |
bool | isBad (void) const |
bool | isDerivedFrom (const Type type) const |
bool | operator!= (const Type type) const |
bool | operator< (const Type type) const |
bool | operator<= (const Type type) const |
void | operator= (const Type type) |
bool | operator== (const Type type) const |
bool | operator> (const Type type) const |
bool | operator>= (const Type type) const |
Type (void) | |
A constructor. | |
Type (const Type &type) | |
Construction. | |
virtual | ~Type () |
Destruction. | |
Static Public Member Functions | |
static Type | badType (void) |
static void * | createInstanceByName (const char *TypeName, bool bLoadModule=false) |
creates a instance of the named type | |
static const Type | createType (const Type parent, const char *name, instantiationMethod method=0) |
static void | destruct (void) |
static Type | fromName (const char *name) |
static int | getAllDerivedFrom (const Type type, std::vector< Type > &List) |
static int | getNumTypes (void) |
static void | init (void) |
Static Protected Member Functions | |
static std::string | getModuleName (const char *ClassName) |
Type system class Many of the classes in the FreeCAD must have their type information registered before any instances are created (including, but not limited to: App::Feature, App::Property, Gui::ViewProvider ).
The use of Type to store this information provides lots of various functionality for working with class hierarchies, comparing class types, instantiating objects from classnames, etc etc.
It is for instance possible to do things like this:
void getRightFeature(Base::Base * anode) { assert(anode->getTypeId().isDerivedFrom(App::Feature::getClassTypeId())); if (anode->getTypeId() == Mesh::MeshFeature::getClassTypeId()) { // do something.. } else if (anode->getTypeId() == Part::PartFeature::getClassTypeId()) { // do something.. } else { Base::Console().Warning("getRightFeature", "Unknown feature type %s!\n", anode->getTypeId().getName()); } }
A notable feature of the Type class is that it is only 16 bits long and therefore should be passed around by value for efficiency reasons.
One important note about the use of Type to register class information: super classes must be registered before any of their derived classes are.
Definition at line 77 of file Base/type.h.
typedef void*(* Base::Type::instantiationMethod)(void) |
Definition at line 91 of file Base/type.h.
Type::Type | ( | void | ) |
Type::~Type | ( | ) | [virtual] |
Type Type::badType | ( | void | ) | [static] |
Definition at line 134 of file Type.cpp.
Referenced by Gui::SelectionSingleton::countObjectsOfType(), createInstanceByName(), App::DocumentPy::findObjects(), fromName(), Gui::SelectionSingleton::getObjectsOfType(), Gui::SelectionSingleton::getSelectionEx(), Base::BaseClass::init(), Base::BaseClass::initSubclass(), isDerivedFrom(), and Base::BaseClassPy::isDerivedFrom().
void * Type::createInstance | ( | void | ) |
creates a instance of this type
Definition at line 85 of file Type.cpp.
Referenced by createInstanceByName(), Part::PropertyGeometryList::Restore(), Sandbox::DocumentObjectProtectorPy::setattr(), and Gui::View3DInventorViewer::setNavigationType().
void * Type::createInstanceByName | ( | const char * | TypeName, | |
bool | bLoadModule = false | |||
) | [static] |
creates a instance of the named type
Definition at line 91 of file Type.cpp.
References badType(), Base::Console(), createInstance(), fromName(), getModuleName(), Base::Interpreter(), Base::InterpreterSingleton::loadModule(), Base::ConsoleSingleton::Log(), RobotExample::pos, and RobotExample::t.
Referenced by App::DynamicProperty::addDynamicProperty(), App::Document::addObject(), MeshGui::DlgEvaluateMeshImp::addViewProvider(), Gui::PropertyEditor::PropertyModel::buildUp(), Gui::WorkbenchManager::createWorkbench(), Gui::FreeCADGui_subgraphFromObject(), and Gui::Document::slotNewObject().
const Type Type::createType | ( | const Type | parent, | |
const char * | name, | |||
instantiationMethod | method = 0 | |||
) | [static] |
Definition at line 142 of file Type.cpp.
References getKey().
Referenced by Base::BaseClass::init(), and Base::BaseClass::initSubclass().
Type Type::fromName | ( | const char * | name | ) | [static] |
Definition at line 176 of file Type.cpp.
References badType(), and RobotExample::pos.
Referenced by PartGui::Mirroring::accept(), CmdPartSimpleCopy::activated(), CmdPartShapeFromMesh::activated(), CmdRobotAddToolShape::activated(), CmdFemCreateFromShape::activated(), Gui::SelectionSingleton::countObjectsOfType(), createInstanceByName(), exporter(), App::DocumentPy::findObjects(), PartGui::ViewProviderBoolean::getIcon(), Gui::SelectionSingleton::getObjectsOfType(), Base::BaseClass::initSubclass(), CmdPartSimpleCopy::isActive(), CmdPartShapeFromMesh::isActive(), CmdFemCreateFromShape::isActive(), Base::BaseClassPy::isDerivedFrom(), Gui::Node_Object::Node_Object(), Gui::View3DInventor::OnChange(), Gui::NavigationStyle::openPopupMenu(), Gui::Dialog::find_geometry_data::operator()(), Gui::Dialog::find_placement::operator()(), Part::PropertyGeometryList::Restore(), Gui::TreeView::rowsInserted(), Gui::View3DInventorPy::setNavigationType(), InspectionGui::ViewProviderInspection::updateData(), and InspectionGui::VisualInspection::VisualInspection().
Definition at line 210 of file Type.cpp.
Referenced by Gui::View3DInventorPy::listNavigationTypes(), Gui::NavigationStyle::openPopupMenu(), and Gui::Dialog::DlgSettings3DViewImp::retranslate().
unsigned int Base::Type::getKey | ( | void | ) | const [inline] |
Definition at line 139 of file Base/type.h.
Referenced by createType(), operator!=(), operator<(), operator<=(), operator=(), operator==(), operator>(), and operator>=().
string Type::getModuleName | ( | const char * | ClassName | ) | [static, protected] |
Definition at line 123 of file Type.cpp.
References RobotExample::pos.
Referenced by createInstanceByName().
const char * Type::getName | ( | void | ) | const |
Definition at line 187 of file Type.cpp.
Referenced by App::Document::_copyObject(), StdCmdHideSelection::activated(), StdCmdShowSelection::activated(), StdCmdToggleSelectability::activated(), StdCmdToggleVisibility::activated(), App::DynamicProperty::addDynamicProperties(), Gui::SelectionSingleton::addSelection(), Gui::Document::exportObjects(), Gui::View3DInventorPy::getNavigationType(), Gui::Document::importObjects(), Mesh::MeshFeaturePy::representation(), App::PropertyContainer::Restore(), Part::Box::Restore(), App::DynamicProperty::Restore(), InspectionGui::ViewProviderInspection::setDistances(), Gui::SelectionSingleton::setSelection(), and Gui::Document::slotNewObject().
const Type Type::getParent | ( | void | ) | const |
Definition at line 192 of file Type.cpp.
Referenced by isDerivedFrom().
bool Base::Type::isBad | ( | void | ) | const [inline] |
Definition at line 187 of file Base/type.h.
Referenced by Gui::View3DInventorViewer::setNavigationType().
bool Type::isDerivedFrom | ( | const Type | type | ) | const |
Definition at line 197 of file Type.cpp.
References badType(), and getParent().
Referenced by CmdPointsPolyCut::activated(), CmdMeshPolySplit::activated(), CmdMeshPolyCut::activated(), CmdMeshAddFacet::activated(), CmdMeshPolySelect::activated(), CmdMeshPolySegm::activated(), App::DocumentObjectGroupPy::addObject(), MeshGui::DlgEvaluateMeshImp::addViewProvider(), Gui::SelectionSingleton::countObjectsOfType(), MeshGui::ViewProviderMeshCurvature::curvatureInfoCallback(), Gui::TreeWidget::dragMoveEvent(), Gui::TreeWidget::dropEvent(), Robot::TrajectoryDressUpObject::execute(), Sketcher::SketchObject::execute(), Raytracing::RayFeature::execute(), Part::RuledSurface::execute(), Inspection::Feature::execute(), Drawing::FeatureViewPart::execute(), PartDesign::Revolution::execute(), Part::Revolution::execute(), Drawing::FeatureProjection::execute(), PartDesign::Pocket::execute(), PartDesign::Pad::execute(), Part::Mirroring::execute(), PartDesign::Fillet::execute(), Part::Fillet::execute(), Part::Extrusion::execute(), Part::Chamfer::execute(), Robot::Edge2TracObject::execute(), exporter(), MeshGui::ViewProviderMesh::faceInfoCallback(), MeshGui::ViewProviderMesh::fillHoleCallback(), App::DocumentPy::findObjects(), InspectionGui::ViewProviderInspection::getIcon(), Gui::SelectionSingleton::getObjectsOfType(), App::PropertyPlacementLink::getPlacementObject(), App::PropertyLinkSub::getValue(), App::PropertyLink::getValue(), Gui::ViewProviderDocumentObjectGroup::getViewProviders(), Gui::ViewProviderDocumentObjectGroup::hide(), InspectionGui::ViewProviderInspection::inspectCallback(), InspectionGui::ViewProviderInspection::inspectDistance(), Base::BaseClass::isDerivedFrom(), Gui::SelectionObject::isObjectTypeOf(), Gui::Command::isViewOfType(), MeshGui::ViewProviderMesh::markPartCallback(), Gui::Dialog::DlgMaterialPropertiesImp::on_ambientColor_changed(), Gui::Dialog::DlgMaterialPropertiesImp::on_diffuseColor_changed(), Gui::Dialog::DlgMaterialPropertiesImp::on_emissiveColor_changed(), Gui::Dialog::DlgMaterialPropertiesImp::on_shininess_valueChanged(), Gui::Dialog::DlgMaterialPropertiesImp::on_specularColor_changed(), Gui::PropertyEditor::PropertyItem::pythonIdentifier(), Gui::Document::setHide(), Gui::Document::setShow(), Gui::Application::setupContextMenu(), Gui::Dialog::DlgMaterialPropertiesImp::setViewProviders(), PartGui::ViewProviderPartBase::shapeInfoCallback(), Gui::ViewProviderDocumentObjectGroup::show(), Gui::DocumentItem::slotChangeObject(), Gui::Document::slotDeletedObject(), Gui::TaskView::TaskSelectLinkProperty::TaskSelectLinkProperty(), Gui::SelectionFilter::test(), Gui::PropertyEditor::PropertyPlacementItem::toolTip(), Gui::ViewProviderGeometryObject::unsetEdit(), SketcherGui::ViewProviderCustom::updateData(), PartGui::ViewProviderCustom::updateData(), InspectionGui::ViewProviderInspection::updateData(), Gui::PropertyEditor::PropertyTransientFileItem::value(), Gui::PropertyEditor::PropertyPathItem::value(), Gui::PropertyEditor::PropertyFileItem::value(), Gui::PropertyEditor::PropertyColorItem::value(), Gui::PropertyEditor::PropertyStringListItem::value(), Gui::PropertyEditor::PropertyEnumItem::value(), Gui::PropertyEditor::PropertyPlacementItem::value(), Gui::PropertyEditor::PropertyVectorItem::value(), Gui::PropertyEditor::PropertyBoolItem::value(), Gui::PropertyEditor::PropertyFloatConstraintItem::value(), Gui::PropertyEditor::PropertyUnitItem::value(), Gui::PropertyEditor::PropertyFloatItem::value(), Gui::PropertyEditor::PropertyIntegerConstraintItem::value(), Gui::PropertyEditor::PropertyIntegerItem::value(), Gui::PropertyEditor::PropertyFontItem::value(), and Gui::PropertyEditor::PropertyStringItem::value().
bool Base::Type::operator!= | ( | const Type | type | ) | const [inline] |
Definition at line 145 of file Base/type.h.
References getKey().
bool Base::Type::operator< | ( | const Type | type | ) | const [inline] |
Definition at line 163 of file Base/type.h.
References getKey().
bool Base::Type::operator<= | ( | const Type | type | ) | const [inline] |
Definition at line 169 of file Base/type.h.
References getKey().
void Base::Type::operator= | ( | const Type | type | ) | [inline] |
Definition at line 151 of file Base/type.h.
References getKey().
bool Base::Type::operator== | ( | const Type | type | ) | const [inline] |
Definition at line 157 of file Base/type.h.
References getKey().
bool Base::Type::operator> | ( | const Type | type | ) | const [inline] |
Definition at line 181 of file Base/type.h.
References getKey().
bool Base::Type::operator>= | ( | const Type | type | ) | const [inline] |
Definition at line 175 of file Base/type.h.
References getKey().