anObjects.push_back(anObject);
}
}
+
+ if(anObjects.empty()) {
+ static const std::string aFeatureError = "Error: No objects for partition.";
+ setError(aFeatureError);
+ return;
+ }
+
std::list<std::shared_ptr<GeomAPI_Pnt> > aBoundingPoints = GeomAlgoAPI_ShapeTools::getBoundingBox(anObjects, 1.0);
// Resize planes.
concealment="true">
<validator id="FeaturesPlugin_ValidatorPartitionSelection" parameters="Plane"/>
</multi_selector>
+ <validator id="GeomValidators_MinObjectsSelected" parameters="base_objects,2"/>
</source>
GeomValidators_ZeroOffset.h
GeomValidators_Different.h
GeomValidators_IntersectionSelection.h
+ GeomValidators_MinObjectsSelected.h
)
SET(PROJECT_SOURCES
GeomValidators_ZeroOffset.cpp
GeomValidators_Different.cpp
GeomValidators_IntersectionSelection.cpp
+ GeomValidators_MinObjectsSelected.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_MinObjectsSelected.cpp
+// Created: 30 June 2015
+// Author: Dmitry Bobylev
+
+#include <GeomValidators_MinObjectsSelected.h>
+
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+//=================================================================================================
+bool GeomValidators_MinObjectsSelected::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
+{
+ if(theArguments.size() != 2) {
+ theError = "Error: Wrong number of arguments (expected 2): selection list id and min number of objects";
+ return false;
+ }
+
+ std::string aSelectionListId = theArguments.front();
+ AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(aSelectionListId);
+ if(!anAttrSelList.get()) {
+ theError = "Error: Could not get attribute \"" + aSelectionListId + "\".";
+ return false;
+ }
+ int anObjectsNb = anAttrSelList->size();
+
+ int aMinObjectsNb = atoi(theArguments.back().c_str());
+
+ if(anObjectsNb < aMinObjectsNb) {
+ theError = "Error: Attribute \"" + aSelectionListId + "\" should contain at least "
+ + theArguments.back() + " items.";
+ return false;
+ }
+
+ return true;
+}
+
+//=================================================================================================
+bool GeomValidators_MinObjectsSelected::isNotObligatory(std::string theFeature, std::string theAttribute)
+{
+ return false;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_MinObjectsSelected.h
+// Created: 30 June 2015
+// Author: Dmitry Bobylev
+
+#ifndef GeomValidators_MinObjectsSelected_H
+#define GeomValidators_MinObjectsSelected_H
+
+#include <GeomValidators.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_FeatureValidator.h>
+
+/// \class GeomValidators_MinObjectsSelected
+/// \ingroup Validators
+/// \brief Validates number of objects in selection list.
+class GeomValidators_MinObjectsSelected : public ModelAPI_FeatureValidator
+{
+public:
+ /// \return true if selection list has enough objects.
+ /// \param[in] theFeature the validated feature.
+ /// \param[in] theArguments the arguments in the configuration file for this validator.
+ /// \param[out] theError error message.
+ /// \returns true if feature is valid.
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
+
+ /// \return true if the attribute in feature is not obligatory for the feature execution.
+ GEOMVALIDATORS_EXPORT virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+};
+
+#endif
#include <GeomValidators_ZeroOffset.h>
#include <GeomValidators_IntersectionSelection.h>
#include <GeomValidators_FeatureKind.h>
+#include <GeomValidators_MinObjectsSelected.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
aFactory->registerValidator("GeomValidators_ZeroOffset", new GeomValidators_ZeroOffset);
aFactory->registerValidator("GeomValidators_IntersectionSelection", new GeomValidators_IntersectionSelection);
aFactory->registerValidator("GeomValidators_FeatureKind", new GeomValidators_FeatureKind);
+ aFactory->registerValidator("GeomValidators_MinObjectsSelected", new GeomValidators_MinObjectsSelected);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);