Implement new validator to select shape types specified by the Group feature.
FiltersPlugin_OppositeToEdge.h
FiltersPlugin_RelativeToSolid.h
FiltersPlugin_ExternalFaces.h
+ FiltersPlugin_Validators.h
)
SET(PROJECT_SOURCES
FiltersPlugin_OppositeToEdge.cpp
FiltersPlugin_RelativeToSolid.cpp
FiltersPlugin_ExternalFaces.cpp
+ FiltersPlugin_Validators.cpp
)
SET(PROJECT_LIBRARIES
Config
GeomAPI
GeomAlgoAPI
+ GeomValidators
)
SET(PROJECT_PYFILES
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
${PROJECT_SOURCE_DIR}/src/GeomDataAPI
+ ${PROJECT_SOURCE_DIR}/src/GeomValidators
+ ${PROJECT_SOURCE_DIR}/src/CollectionPlugin
)
INSTALL(TARGETS Filters DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES})
#include "FiltersPlugin_OppositeToEdge.h"
#include "FiltersPlugin_RelativeToSolid.h"
#include "FiltersPlugin_ExternalFaces.h"
+#include "FiltersPlugin_Validators.h"
#include <Config_ModuleReader.h>
FiltersPlugin_Plugin::FiltersPlugin_Plugin()
{
- // register validators
+ // register filters
SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_FiltersFactory* aFactory = aMgr->filters();
aFactory->registerFilter("HorizontalFaces", new FiltersPlugin_HorizontalFace);
Config_ModuleReader::loadScript("FiltersPlugin_TopoConnectedFaces");
+ // register validators
+ ModelAPI_ValidatorsFactory* aValidators = aMgr->validators();
+ aValidators->registerValidator("FiltersPlugin_ShapeType",
+ new FiltersPlugin_ShapeTypeValidator);
+
ModelAPI_Session::get()->registerPlugin(this);
}
--- /dev/null
+// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "FiltersPlugin_Validators.h"
+
+#include <CollectionPlugin_Group.h>
+
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Session.h>
+
+bool FiltersPlugin_ShapeTypeValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ if (!theAttribute)
+ return false;
+ FeaturePtr aFilterFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ if (!aFilterFeature)
+ return false;
+
+ // iterate on groups and find the one having the current filters feature
+ DocumentPtr aCurDoc = ModelAPI_Session::get()->activeDocument();
+ std::list<FeaturePtr> aFeatList = aCurDoc->allFeatures();
+ for (std::list<FeaturePtr>::iterator anIt = aFeatList.begin(); anIt != aFeatList.end(); ++anIt)
+ if ((*anIt)->getKind() == CollectionPlugin_Group::ID()) {
+ AttributeSelectionListPtr aSelList =
+ (*anIt)->selectionList(CollectionPlugin_Group::LIST_ID());
+ if (aSelList->filters() == aFilterFeature) {
+ TypeOfShape aType = shapeType(aSelList->selectionType());
+ if (isValidAttribute(theAttribute, aType, theError))
+ return true;
+ }
+ }
+
+ return false;
+}
--- /dev/null
+// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef FILTERSPLUGIN_VALIDATORS_H_
+#define FILTERSPLUGIN_VALIDATORS_H_
+
+#include "FiltersPlugin.h"
+
+#include <GeomValidators_ShapeType.h>
+
+/**
+ * Validates selection of "On geometry" filter to select only
+ * the shapes specified by the group type.
+ */
+class FiltersPlugin_ShapeTypeValidator : public GeomValidators_ShapeType
+{
+public:
+ /// \return True if the attribute is valid. It checks whether the shape is a
+ /// body subshape. Does not allow select construction shapes.
+ /// \param[in] theAttribute an attribute to check
+ /// \param[in] theArguments a filter parameters
+ /// \param[out] theError error message.
+ FILTERS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
+#endif
\ No newline at end of file
<filter id="OnGeometry">
<multi_selector id="OnGeometry__OnGeometry"
- label="Edges/faces:"
+ label="Shapes:"
tooltip="Select objects to limit selection."
type_choice="edges faces">
- <validator id="GeomValidators_ShapeType" parameters="edge,face"/>
+ <validator id="FiltersPlugin_ShapeType"/>
</multi_selector>
</filter>
#include <Events_InfoMessage.h>
+#include <algorithm>
#include <string>
#include <map>
if (MyShapeTypes.size() == 0) {
MyShapeTypes["empty"] = Empty;
MyShapeTypes["vertex"] = Vertex;
+ MyShapeTypes["vertices"] = Vertex;
MyShapeTypes["edge"] = Edge;
+ MyShapeTypes["edges"] = Edge;
MyShapeTypes["line"] = Line;
MyShapeTypes["circle"] = Circle;
MyShapeTypes["wire"] = Wire;
MyShapeTypes["face"] = Face;
+ MyShapeTypes["faces"] = Face;
MyShapeTypes["plane"] = Plane;
MyShapeTypes["shell"] = Shell;
MyShapeTypes["solid"] = Solid;
+ MyShapeTypes["solids"] = Solid;
MyShapeTypes["compsolid"] = CompSolid;
MyShapeTypes["compound"] = Compound;
}
std::string aType = std::string(theType.c_str());
+ std::transform(aType.begin(), aType.end(), aType.begin(), ::tolower);
if (MyShapeTypes.find(aType) != MyShapeTypes.end())
return MyShapeTypes[aType];
protected:
/// Convert string to TypeOfShape value
/// \param theType a string value
- static TypeOfShape shapeType(const std::string& theType);
+ GEOMVALIDATORS_EXPORT static TypeOfShape shapeType(const std::string& theType);
/// Returns true if the attibute's object type satisfies the argument value
/// \param[in] theAttribute a checked attribute
/// \param[in] theShapeType a type of shape
/// \param[out] theError error message.
+ GEOMVALIDATORS_EXPORT
bool isValidAttribute(const AttributePtr& theAttribute,
const TypeOfShape theShapeType,
Events_InfoMessage& theError) const;