diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index 86e7fdf0a4..8e48c4b326 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -1698,7 +1698,7 @@ bool StdCmdAlignment::isActive() { if (ManualAlignment::hasInstance()) return false; - return Gui::Selection().countObjectsOfType(App::GeoFeature::getClassTypeId()) == 2; + return Gui::Selection().countObjectsOfType() == 2; } //=========================================================================== diff --git a/src/Gui/Selection.h b/src/Gui/Selection.h index ff299b3c5e..2780914dec 100644 --- a/src/Gui/Selection.h +++ b/src/Gui/Selection.h @@ -392,6 +392,13 @@ public: unsigned int countObjectsOfType(const Base::Type& typeId=App::DocumentObject::getClassTypeId(), const char* pDocName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement) const; + /** + * A convenience template-based method that returns the number of objects of the given type. + * \a T must be based on Base::BaseClass, otherwise 0 is returned. + */ + template inline unsigned int countObjectsOfType( + const char* pDocName=nullptr, ResolveMode resolve = ResolveMode::OldStyleElement) const; + /** * Does basically the same as the method above unless that it accepts a string literal as first argument. * \a typeName must be a registered type, otherwise 0 is returned. @@ -724,6 +731,15 @@ protected: SelectionStyle selectionStyle; }; +/** + * A convenience template-based method that returns the number of objects of the given type. + */ +template +inline unsigned int SelectionSingleton::countObjectsOfType(const char* pDocName, ResolveMode resolve) const { + static_assert(std::is_base_of::value, "Template parameter T must be derived from App::DocumentObject"); + return this->countObjectsOfType(T::getClassTypeId(), pDocName, resolve); +} + /** * A convenience template-based method that returns an array with the correct types already. */ diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index 8ebe03072e..e0c8a65f05 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -594,7 +594,7 @@ void StdWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const << StdViews << "Separator" << "Std_ViewDockUndockFullscreen"; - if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0) { + if (Gui::Selection().countObjectsOfType() > 0) { *item << "Separator" << "Std_ToggleVisibility" << "Std_ToggleSelectability" << "Std_TreeSelection" << "Std_RandomColor" << "Std_ToggleTransparency" << "Separator" << "Std_Delete" @@ -603,7 +603,7 @@ void StdWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const } else if (strcmp(recipient,"Tree") == 0) { - if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0) { + if (Gui::Selection().countObjectsOfType() > 0) { *item << "Std_ToggleFreeze" << "Separator" << "Std_Placement" << "Std_ToggleVisibility" << "Std_ShowSelection" << "Std_HideSelection" << "Std_ToggleSelectability" << "Std_TreeSelectAllInstances" << "Separator" diff --git a/src/Mod/Drawing/Gui/Command.cpp b/src/Mod/Drawing/Gui/Command.cpp index a09c755a93..c3f3a8cdf4 100644 --- a/src/Mod/Drawing/Gui/Command.cpp +++ b/src/Mod/Drawing/Gui/Command.cpp @@ -479,7 +479,7 @@ CmdDrawingOpenBrowserView::CmdDrawingOpenBrowserView() void CmdDrawingOpenBrowserView::activated(int iMsg) { Q_UNUSED(iMsg); - unsigned int n = getSelection().countObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + unsigned int n = getSelection().countObjectsOfType(); if (n != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), @@ -691,7 +691,7 @@ CmdDrawingExportPage::CmdDrawingExportPage() void CmdDrawingExportPage::activated(int iMsg) { Q_UNUSED(iMsg); - unsigned int n = getSelection().countObjectsOfType(Drawing::FeaturePage::getClassTypeId()); + unsigned int n = getSelection().countObjectsOfType(); if (n != 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), @@ -757,7 +757,7 @@ void CmdDrawingProjectShape::activated(int iMsg) bool CmdDrawingProjectShape::isActive(void) { - int ct = Gui::Selection().countObjectsOfType(Part::Feature::getClassTypeId()); + int ct = Gui::Selection().countObjectsOfType(); return (ct > 0 && !Gui::Control().activeDialog()); } diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index 2ef4a338f1..b7b763d55e 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -223,8 +223,7 @@ bool CmdFemAddPart::isActive(void) { if (Gui::Control().activeDialog()) return false; - Base::Type type = Base::Type::fromName("Part::Feature"); - return Gui::Selection().countObjectsOfType(type) > 0; + return Gui::Selection().countObjectsOfType(type) > 0; } */ @@ -1165,7 +1164,7 @@ void CmdFemDefineNodesSet::activated(int) bool CmdFemDefineNodesSet::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Fem::FemMeshObject::getClassTypeId()) != 1) { + if (getSelection().countObjectsOfType() != 1) { return false; } @@ -1314,7 +1313,7 @@ void CmdFemDefineElementsSet::activated(int) bool CmdFemDefineElementsSet::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Fem::FemMeshObject::getClassTypeId()) != 1) { + if (getSelection().countObjectsOfType() != 1) { return false; } @@ -2028,25 +2027,25 @@ bool CmdFemPostClipFilter::isActive() return false; } // only activate if a result is either a post pipeline or a possible filter - if (getSelection().getObjectsOfType().size() == 1) { + if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } return false; @@ -2080,25 +2079,25 @@ bool CmdFemPostCutFilter::isActive() return false; } // only activate if a result is either a post pipeline or a possible filter - if (getSelection().getObjectsOfType().size() == 1) { + if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } return false; @@ -2132,22 +2131,22 @@ bool CmdFemPostDataAlongLineFilter::isActive() return false; } // only activate if a result is either a post pipeline or a possible filter - if (getSelection().getObjectsOfType().size() == 1) { + if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } return false; @@ -2182,22 +2181,22 @@ bool CmdFemPostDataAtPointFilter::isActive() return false; } // only activate if a result is either a post pipeline or a possible filter - if (getSelection().getObjectsOfType().size() == 1) { + if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } return false; @@ -2307,22 +2306,22 @@ bool CmdFemPostScalarClipFilter::isActive() return false; } // only activate if a result is either a post pipeline or a possible other filter - if (getSelection().getObjectsOfType().size() == 1) { + if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } return false; @@ -2356,22 +2355,22 @@ bool CmdFemPostWarpVectorFilter::isActive() return false; } // only activate if a result is either a post pipeline or a possible other filter - if (getSelection().getObjectsOfType().size() == 1) { + if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } return false; @@ -2405,22 +2404,22 @@ bool CmdFemPostContoursFilter::isActive() return false; } // only activate if a result is either a post pipeline or a possible other filter - if (getSelection().getObjectsOfType().size() == 1) { + if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } - else if (getSelection().getObjectsOfType().size() == 1) { + else if (getSelection().countObjectsOfType() == 1) { return true; } return false; diff --git a/src/Mod/Mesh/Gui/Command.cpp b/src/Mod/Mesh/Gui/Command.cpp index 19d9360d72..cad7e62f26 100644 --- a/src/Mod/Mesh/Gui/Command.cpp +++ b/src/Mod/Mesh/Gui/Command.cpp @@ -151,7 +151,7 @@ void CmdMeshUnion::activated(int) bool CmdMeshUnion::isActive() { - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 2; + return getSelection().countObjectsOfType() == 2; } //-------------------------------------------------------------------------------------- @@ -230,7 +230,7 @@ void CmdMeshDifference::activated(int) bool CmdMeshDifference::isActive() { - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 2; + return getSelection().countObjectsOfType() == 2; } //-------------------------------------------------------------------------------------- @@ -309,7 +309,7 @@ void CmdMeshIntersection::activated(int) bool CmdMeshIntersection::isActive() { - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 2; + return getSelection().countObjectsOfType() == 2; } //-------------------------------------------------------------------------------------- @@ -445,7 +445,7 @@ void CmdMeshExport::activated(int) bool CmdMeshExport::isActive() { - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; + return getSelection().countObjectsOfType() == 1; } //-------------------------------------------------------------------------------------- @@ -516,7 +516,7 @@ bool CmdMeshFromGeometry::isActive() if (!doc) { return false; } - return getSelection().countObjectsOfType(App::GeoFeature::getClassTypeId()) >= 1; + return getSelection().countObjectsOfType() >= 1; } //=========================================================================== @@ -598,7 +598,7 @@ void CmdMeshVertexCurvature::activated(int) bool CmdMeshVertexCurvature::isActive() { // Check for the selected mesh feature (all Mesh types) - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } //-------------------------------------------------------------------------------------- @@ -696,7 +696,7 @@ void CmdMeshPolySegm::activated(int) bool CmdMeshPolySegm::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { + if (getSelection().countObjectsOfType() == 0) { return false; } @@ -744,7 +744,7 @@ void CmdMeshAddFacet::activated(int) bool CmdMeshAddFacet::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) { + if (getSelection().countObjectsOfType() != 1) { return false; } @@ -809,7 +809,7 @@ void CmdMeshPolyCut::activated(int) bool CmdMeshPolyCut::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { + if (getSelection().countObjectsOfType() == 0) { return false; } @@ -874,7 +874,7 @@ void CmdMeshPolyTrim::activated(int) bool CmdMeshPolyTrim::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { + if (getSelection().countObjectsOfType() == 0) { return false; } @@ -913,11 +913,7 @@ void CmdMeshTrimByPlane::activated(int) bool CmdMeshTrimByPlane::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) { - return false; - } - - return true; + return getSelection().countObjectsOfType() == 1; } //-------------------------------------------------------------------------------------- @@ -946,11 +942,7 @@ void CmdMeshSectionByPlane::activated(int) bool CmdMeshSectionByPlane::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) { - return false; - } - - return true; + return getSelection().countObjectsOfType() == 1; } //-------------------------------------------------------------------------------------- @@ -978,7 +970,7 @@ void CmdMeshCrossSections::activated(int) bool CmdMeshCrossSections::isActive() { - return (Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0 + return (Gui::Selection().countObjectsOfType() > 0 && !Gui::Control().activeDialog()); } @@ -1026,7 +1018,7 @@ void CmdMeshPolySplit::activated(int) bool CmdMeshPolySplit::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 0) { + if (getSelection().countObjectsOfType() == 0) { return false; } @@ -1209,7 +1201,7 @@ void CmdMeshRemeshGmsh::activated(int) bool CmdMeshRemeshGmsh::isActive() { - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; + return getSelection().countObjectsOfType() == 1; } //-------------------------------------------------------------------------------------- @@ -1297,7 +1289,7 @@ void CmdMeshEvaluateSolid::activated(int) bool CmdMeshEvaluateSolid::isActive() { // Check for the selected mesh feature (all Mesh types) - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; + return getSelection().countObjectsOfType() == 1; } //-------------------------------------------------------------------------------------- @@ -1326,7 +1318,7 @@ bool CmdMeshSmoothing::isActive() if (Gui::Control().activeDialog()) { return false; } - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } //-------------------------------------------------------------------------------------- @@ -1358,7 +1350,7 @@ bool CmdMeshDecimating::isActive() } #endif // Check for the selected mesh feature (all Mesh types) - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } //-------------------------------------------------------------------------------------- @@ -1394,7 +1386,7 @@ void CmdMeshHarmonizeNormals::activated(int) bool CmdMeshHarmonizeNormals::isActive() { // Check for the selected mesh feature (all Mesh types) - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } //-------------------------------------------------------------------------------------- @@ -1430,7 +1422,7 @@ void CmdMeshFlipNormals::activated(int) bool CmdMeshFlipNormals::isActive() { // Check for the selected mesh feature (all Mesh types) - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } //-------------------------------------------------------------------------------------- @@ -1482,7 +1474,7 @@ void CmdMeshBoundingBox::activated(int) bool CmdMeshBoundingBox::isActive() { // Check for the selected mesh feature (all Mesh types) - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; + return getSelection().countObjectsOfType() == 1; } //-------------------------------------------------------------------------------------- @@ -1565,7 +1557,7 @@ void CmdMeshFillupHoles::activated(int) bool CmdMeshFillupHoles::isActive() { // Check for the selected mesh feature (all Mesh types) - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } //-------------------------------------------------------------------------------------- @@ -1648,7 +1640,7 @@ bool CmdMeshSegmentation::isActive() if (Gui::Control().activeDialog()) { return false; } - return Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; + return Gui::Selection().countObjectsOfType() == 1; } //-------------------------------------------------------------------------------------- @@ -1684,7 +1676,7 @@ bool CmdMeshSegmentationBestFit::isActive() if (Gui::Control().activeDialog()) { return false; } - return Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; + return Gui::Selection().countObjectsOfType() == 1; } //-------------------------------------------------------------------------------------- @@ -1730,7 +1722,7 @@ void CmdMeshMerge::activated(int) bool CmdMeshMerge::isActive() { - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) >= 2; + return getSelection().countObjectsOfType() >= 2; } //-------------------------------------------------------------------------------------- @@ -1779,7 +1771,7 @@ void CmdMeshSplitComponents::activated(int) bool CmdMeshSplitComponents::isActive() { - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; + return getSelection().countObjectsOfType() == 1; } //-------------------------------------------------------------------------------------- @@ -1837,7 +1829,7 @@ void CmdMeshScale::activated(int) bool CmdMeshScale::isActive() { - return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } diff --git a/src/Mod/Mesh/Gui/Workbench.cpp b/src/Mod/Mesh/Gui/Workbench.cpp index ac6a3912fd..69990caf5b 100644 --- a/src/Mod/Mesh/Gui/Workbench.cpp +++ b/src/Mod/Mesh/Gui/Workbench.cpp @@ -158,7 +158,7 @@ void Workbench::deactivated() void Workbench::setupContextMenu(const char* recipient, Gui::MenuItem* item) const { StdWorkbench::setupContextMenu(recipient, item); - if (Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0) { + if (Gui::Selection().countObjectsOfType() > 0) { *item << "Separator" << "Mesh_Import" << "Mesh_Export" diff --git a/src/Mod/MeshPart/Gui/Command.cpp b/src/Mod/MeshPart/Gui/Command.cpp index 1934ad5b25..bb96c50660 100644 --- a/src/Mod/MeshPart/Gui/Command.cpp +++ b/src/Mod/MeshPart/Gui/Command.cpp @@ -173,11 +173,7 @@ void CmdMeshPartTrimByPlane::activated(int) bool CmdMeshPartTrimByPlane::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) { - return false; - } - - return true; + return getSelection().countObjectsOfType() == 1; } //=========================================================================== @@ -262,11 +258,7 @@ void CmdMeshPartSection::activated(int) bool CmdMeshPartSection::isActive() { // Check for the selected mesh feature (all Mesh types) - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1) { - return false; - } - - return true; + return getSelection().countObjectsOfType() == 1; } //=========================================================================== @@ -304,7 +296,7 @@ void CmdMeshPartCrossSections::activated(int iMsg) bool CmdMeshPartCrossSections::isActive() { - return (Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0 + return (Gui::Selection().countObjectsOfType() > 0 && !Gui::Control().activeDialog()); } diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index 2baefb624f..32f359ce64 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -344,8 +344,7 @@ void CmdPartCut::activated(int iMsg) bool CmdPartCut::isActive() { - return getSelection().countObjectsOfType( - App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink)==2; + return getSelection().countObjectsOfType(nullptr, Gui::ResolveMode::FollowLink) == 2; } //=========================================================================== @@ -404,8 +403,7 @@ void CmdPartCommon::activated(int iMsg) bool CmdPartCommon::isActive() { - return getSelection().countObjectsOfType( - App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) >= 1; + return getSelection().countObjectsOfType(nullptr, Gui::ResolveMode::FollowLink) >= 1; } //=========================================================================== @@ -483,8 +481,7 @@ void CmdPartFuse::activated(int iMsg) bool CmdPartFuse::isActive() { - return getSelection().countObjectsOfType( - App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) >= 1; + return getSelection().countObjectsOfType(nullptr, Gui::ResolveMode::FollowLink) >= 1; } //=========================================================================== @@ -839,8 +836,7 @@ CmdPartCompound::CmdPartCompound() void CmdPartCompound::activated(int iMsg) { Q_UNUSED(iMsg); - unsigned int n = getSelection().countObjectsOfType( - App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink); + unsigned int n = getSelection().countObjectsOfType(nullptr, Gui::ResolveMode::FollowLink); if (n < 1) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QObject::tr("Select one shape or more, please.")); @@ -872,8 +868,7 @@ void CmdPartCompound::activated(int iMsg) bool CmdPartCompound::isActive() { - return getSelection().countObjectsOfType( - App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) >= 1; + return getSelection().countObjectsOfType(nullptr, Gui::ResolveMode::FollowLink) >= 1; } //=========================================================================== @@ -921,7 +916,7 @@ void CmdPartSection::activated(int iMsg) bool CmdPartSection::isActive() { - return getSelection().countObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) == 2; + return getSelection().countObjectsOfType(nullptr, Gui::ResolveMode::FollowLink) == 2; } //=========================================================================== @@ -1032,7 +1027,7 @@ void CmdPartExport::activated(int iMsg) bool CmdPartExport::isActive() { - return Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) > 0; + return Gui::Selection().countObjectsOfType(nullptr, Gui::ResolveMode::FollowLink) > 0; } //=========================================================================== @@ -1360,7 +1355,7 @@ void CmdPartMakeFace::activated(int iMsg) bool CmdPartMakeFace::isActive() { - return (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) > 0 && + return (Gui::Selection().countObjectsOfType(nullptr, Gui::ResolveMode::FollowLink) > 0 && !Gui::Control().activeDialog()); } diff --git a/src/Mod/Part/Gui/CommandSimple.cpp b/src/Mod/Part/Gui/CommandSimple.cpp index fb156b524d..6b744b40a9 100644 --- a/src/Mod/Part/Gui/CommandSimple.cpp +++ b/src/Mod/Part/Gui/CommandSimple.cpp @@ -119,8 +119,7 @@ void CmdPartShapeFromMesh::activated(int iMsg) bool CmdPartShapeFromMesh::isActive() { - Base::Type meshid = Base::Type::fromName("Mesh::Feature"); - return Gui::Selection().countObjectsOfType(meshid) > 0; + return Gui::Selection().countObjectsOfType("Mesh::Feature") > 0; } //=========================================================================== // Part_PointsFromMesh @@ -205,8 +204,7 @@ void CmdPartPointsFromMesh::activated(int iMsg) bool CmdPartPointsFromMesh::isActive() { - Base::Type meshid = Base::Type::fromName("App::GeoFeature"); - return Gui::Selection().countObjectsOfType(meshid) > 0; + return Gui::Selection().countObjectsOfType() > 0; } //=========================================================================== diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 6ee21fdd16..107a994b4c 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -486,7 +486,7 @@ void CmdPartDesignClone::activated(int iMsg) bool CmdPartDesignClone::isActive() { - return getSelection().countObjectsOfType(Part::Feature::getClassTypeId()) == 1; + return getSelection().countObjectsOfType() == 1; } //=========================================================================== diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index 4e3929e6b9..219296ba28 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -132,11 +132,11 @@ void Workbench::setupContextMenu(const char* recipient, Gui::MenuItem* item) con } } - if (Gui::Selection().countObjectsOfType(PartDesign::Transformed::getClassTypeId()) - - Gui::Selection().countObjectsOfType(PartDesign::MultiTransform::getClassTypeId()) == 1 ) + if (Gui::Selection().countObjectsOfType() - + Gui::Selection().countObjectsOfType() == 1 ) *item << "PartDesign_MultiTransform"; - if (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId()) > 0) { + if (Gui::Selection().countObjectsOfType() > 0) { *item << "Std_Placement" << "Std_ToggleVisibility" << "Std_ShowSelection" diff --git a/src/Mod/Points/Gui/Command.cpp b/src/Mod/Points/Gui/Command.cpp index 02f1597396..b448fe63d6 100644 --- a/src/Mod/Points/Gui/Command.cpp +++ b/src/Mod/Points/Gui/Command.cpp @@ -188,7 +188,7 @@ void CmdPointsExport::activated(int iMsg) bool CmdPointsExport::isActive() { - return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } DEF_STD_CMD_A(CmdPointsTransform) @@ -227,7 +227,7 @@ void CmdPointsTransform::activated(int iMsg) bool CmdPointsTransform::isActive() { - return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } DEF_STD_CMD_A(CmdPointsConvert) @@ -315,7 +315,7 @@ void CmdPointsConvert::activated(int iMsg) bool CmdPointsConvert::isActive() { - return getSelection().countObjectsOfType(Base::Type::fromName("App::GeoFeature")) > 0; + return getSelection().countObjectsOfType() > 0; } DEF_STD_CMD_A(CmdPointsPolyCut) @@ -363,7 +363,7 @@ void CmdPointsPolyCut::activated(int iMsg) bool CmdPointsPolyCut::isActive() { // Check for the selected mesh feature (all Mesh types) - return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 0; + return getSelection().countObjectsOfType() > 0; } DEF_STD_CMD_A(CmdPointsMerge) @@ -426,7 +426,7 @@ void CmdPointsMerge::activated(int iMsg) bool CmdPointsMerge::isActive() { - return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) > 1; + return getSelection().countObjectsOfType() > 1; } DEF_STD_CMD_A(CmdPointsStructure) @@ -537,7 +537,7 @@ void CmdPointsStructure::activated(int iMsg) bool CmdPointsStructure::isActive() { - return getSelection().countObjectsOfType(Points::Feature::getClassTypeId()) == 1; + return getSelection().countObjectsOfType() == 1; } void CreatePointsCommands() diff --git a/src/Mod/ReverseEngineering/Gui/Command.cpp b/src/Mod/ReverseEngineering/Gui/Command.cpp index ad3b390e68..c6b7fe7c76 100644 --- a/src/Mod/ReverseEngineering/Gui/Command.cpp +++ b/src/Mod/ReverseEngineering/Gui/Command.cpp @@ -233,7 +233,7 @@ void CmdApproxPlane::activated(int) bool CmdApproxPlane::isActive() { - if (getSelection().countObjectsOfType(App::GeoFeature::getClassTypeId()) > 0) { + if (getSelection().countObjectsOfType() > 0) { return true; } return false; @@ -301,7 +301,7 @@ void CmdApproxCylinder::activated(int) bool CmdApproxCylinder::isActive() { - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0) { + if (getSelection().countObjectsOfType() > 0) { return true; } return false; @@ -349,7 +349,7 @@ void CmdApproxSphere::activated(int) bool CmdApproxSphere::isActive() { - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0) { + if (getSelection().countObjectsOfType() > 0) { return true; } return false; @@ -407,7 +407,7 @@ void CmdApproxPolynomial::activated(int) bool CmdApproxPolynomial::isActive() { - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0) { + if (getSelection().countObjectsOfType() > 0) { return true; } return false; @@ -442,7 +442,7 @@ bool CmdSegmentation::isActive() if (Gui::Control().activeDialog()) { return false; } - return Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1; + return Gui::Selection().countObjectsOfType() == 1; } DEF_STD_CMD_A(CmdSegmentationManual) @@ -521,7 +521,7 @@ void CmdSegmentationFromComponents::activated(int) bool CmdSegmentationFromComponents::isActive() { - if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0) { + if (getSelection().countObjectsOfType() > 0) { return true; } return false; @@ -591,7 +591,7 @@ void CmdMeshBoundary::activated(int) bool CmdMeshBoundary::isActive() { - return Gui::Selection().countObjectsOfType(Mesh::Feature::getClassTypeId()) > 0; + return Gui::Selection().countObjectsOfType() > 0; } DEF_STD_CMD_A(CmdPoissonReconstruction) @@ -676,7 +676,7 @@ void CmdViewTriangulation::activated(int) bool CmdViewTriangulation::isActive() { - return (Gui::Selection().countObjectsOfType(Points::Structured::getClassTypeId()) > 0); + return (Gui::Selection().countObjectsOfType() > 0); } void CreateReverseEngineeringCommands() diff --git a/src/Mod/Robot/Gui/CommandExport.cpp b/src/Mod/Robot/Gui/CommandExport.cpp index 304d154f53..ec2c16a5f3 100644 --- a/src/Mod/Robot/Gui/CommandExport.cpp +++ b/src/Mod/Robot/Gui/CommandExport.cpp @@ -54,8 +54,8 @@ CmdRobotExportKukaCompact::CmdRobotExportKukaCompact() void CmdRobotExportKukaCompact::activated(int) { - unsigned int n1 = getSelection().countObjectsOfType(Robot::RobotObject::getClassTypeId()); - unsigned int n2 = getSelection().countObjectsOfType(Robot::TrajectoryObject::getClassTypeId()); + unsigned int n1 = getSelection().countObjectsOfType(); + unsigned int n2 = getSelection().countObjectsOfType(); if (n1 != 1 || n2 != 1) { QMessageBox::warning(Gui::getMainWindow(), @@ -129,8 +129,8 @@ CmdRobotExportKukaFull::CmdRobotExportKukaFull() void CmdRobotExportKukaFull::activated(int) { - unsigned int n1 = getSelection().countObjectsOfType(Robot::RobotObject::getClassTypeId()); - unsigned int n2 = getSelection().countObjectsOfType(Robot::TrajectoryObject::getClassTypeId()); + unsigned int n1 = getSelection().countObjectsOfType(); + unsigned int n2 = getSelection().countObjectsOfType(); if (n1 != 1 || n2 != 1) { QMessageBox::warning(Gui::getMainWindow(), diff --git a/src/Mod/Robot/Gui/CommandTrajectory.cpp b/src/Mod/Robot/Gui/CommandTrajectory.cpp index e55457e62a..cd232add47 100644 --- a/src/Mod/Robot/Gui/CommandTrajectory.cpp +++ b/src/Mod/Robot/Gui/CommandTrajectory.cpp @@ -98,8 +98,8 @@ CmdRobotInsertWaypoint::CmdRobotInsertWaypoint() void CmdRobotInsertWaypoint::activated(int) { - unsigned int n1 = getSelection().countObjectsOfType(Robot::RobotObject::getClassTypeId()); - unsigned int n2 = getSelection().countObjectsOfType(Robot::TrajectoryObject::getClassTypeId()); + unsigned int n1 = getSelection().countObjectsOfType(); + unsigned int n2 = getSelection().countObjectsOfType(); if (n1 != 1 || n2 != 1) { QMessageBox::warning(Gui::getMainWindow(), diff --git a/src/Mod/Sketcher/Gui/Command.cpp b/src/Mod/Sketcher/Gui/Command.cpp index 9e0e30e389..16e2888164 100644 --- a/src/Mod/Sketcher/Gui/Command.cpp +++ b/src/Mod/Sketcher/Gui/Command.cpp @@ -328,7 +328,7 @@ void CmdSketcherEditSketch::activated(int iMsg) bool CmdSketcherEditSketch::isActive() { - return Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) == 1; + return Gui::Selection().countObjectsOfType() == 1; } DEF_STD_CMD_A(CmdSketcherLeaveSketch) @@ -539,7 +539,7 @@ void CmdSketcherReorientSketch::activated(int iMsg) bool CmdSketcherReorientSketch::isActive() { - return Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) == 1; + return Gui::Selection().countObjectsOfType() == 1; } DEF_STD_CMD_A(CmdSketcherMapSketch) @@ -843,7 +843,7 @@ bool CmdSketcherValidateSketch::isActive() { if (Gui::Control().activeDialog()) return false; - return Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) == 1; + return Gui::Selection().countObjectsOfType() == 1; } DEF_STD_CMD_A(CmdSketcherMirrorSketch) @@ -970,7 +970,7 @@ void CmdSketcherMirrorSketch::activated(int iMsg) bool CmdSketcherMirrorSketch::isActive() { - return Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0; + return Gui::Selection().countObjectsOfType() > 0; } DEF_STD_CMD_A(CmdSketcherMergeSketches) @@ -1059,7 +1059,7 @@ void CmdSketcherMergeSketches::activated(int iMsg) bool CmdSketcherMergeSketches::isActive() { - return Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 1; + return Gui::Selection().countObjectsOfType() > 1; } // Acknowledgement of idea and original python macro goes to SpritKopf: diff --git a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp index 0cc93aea49..a5fda2974d 100644 --- a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp +++ b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp @@ -141,7 +141,7 @@ void CmdSketcherToggleConstruction::activated(int iMsg) { Q_UNUSED(iMsg); // Option A: nothing is selected change creation mode from/to construction - if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) == 0) { + if (Gui::Selection().countObjectsOfType() == 0) { Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index edaa9bec7e..82af650761 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -81,7 +81,7 @@ bool isCreateConstraintActive(Gui::Document* doc) && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { if (static_cast(doc->getInEdit())->getSketchMode() == ViewProviderSketch::STATUS_NONE) { - if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) + if (Gui::Selection().countObjectsOfType() > 0) { return true; } @@ -10013,7 +10013,7 @@ void CmdSketcherToggleDrivingConstraint::activated(int iMsg) std::vector selection; - if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) { + if (Gui::Selection().countObjectsOfType() > 0) { // Now we check whether we have a constraint selected or not. // get the selection @@ -10137,7 +10137,7 @@ void CmdSketcherToggleActiveConstraint::activated(int iMsg) std::vector selection; - if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) { + if (Gui::Selection().countObjectsOfType() > 0) { // Now we check whether we have a constraint selected or not. // get the selection diff --git a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp index 9907a4c090..0dff58da9d 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp @@ -61,9 +61,7 @@ bool isSketcherVirtualSpaceActive(Gui::Document* doc, bool actsOnSelection) if (!actsOnSelection) { return true; } - else if (Gui::Selection().countObjectsOfType( - Sketcher::SketchObject::getClassTypeId()) - > 0) { + else if (Gui::Selection().countObjectsOfType() > 0) { return true; } } @@ -111,7 +109,7 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg) std::vector selection; - if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) { + if (Gui::Selection().countObjectsOfType() > 0) { // Now we check whether we have a constraint selected or not. selection = getSelection().getSelectionEx(); diff --git a/src/Mod/Sketcher/Gui/Utils.cpp b/src/Mod/Sketcher/Gui/Utils.cpp index fd29f90d97..8ed9f24d35 100644 --- a/src/Mod/Sketcher/Gui/Utils.cpp +++ b/src/Mod/Sketcher/Gui/Utils.cpp @@ -510,10 +510,7 @@ bool SketcherGui::isCommandActive(Gui::Document* doc, bool actsOnSelection) if (!actsOnSelection) { return true; } - else if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) - > 0) { - return true; - } + return Gui::Selection().countObjectsOfType() > 0; } } @@ -531,11 +528,7 @@ bool SketcherGui::isSketcherBSplineActive(Gui::Document* doc, bool actsOnSelecti if (!actsOnSelection) { return true; } - else if (Gui::Selection().countObjectsOfType( - Sketcher::SketchObject::getClassTypeId()) - > 0) { - return true; - } + return Gui::Selection().countObjectsOfType() > 0; } } } diff --git a/src/Mod/Surface/Gui/Command.cpp b/src/Mod/Surface/Gui/Command.cpp index 17b170adf8..81dd63620d 100644 --- a/src/Mod/Surface/Gui/Command.cpp +++ b/src/Mod/Surface/Gui/Command.cpp @@ -317,7 +317,7 @@ void CmdSurfaceExtendFace::activated(int) bool CmdSurfaceExtendFace::isActive() { - return Gui::Selection().countObjectsOfType(Part::Feature::getClassTypeId()) == 1; + return Gui::Selection().countObjectsOfType() == 1; } DEF_STD_CMD_A(CmdSurfaceSections)