#include <GeomAPI_PlanarEdges.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
#include <GeomAlgoAPI_WireBuilder.h>
#include <GeomValidators_ShapeType.h>
{
// Get base objects list.
if(theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
- Events_Error::send("Validator does not support attribute type \"" + theAttribute->attributeType()
+ Events_Error::send("Error: BuildPlugin_ValidatorBaseForBuild does not support attribute type \"" + theAttribute->attributeType()
+ "\"\n Only \"" + ModelAPI_AttributeSelectionList::typeId() + "\" supported.");
return false;
}
}
//=================================================================================================
-bool BuildPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribute,
+bool BuildPlugin_ValidatorBaseForWire::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
const std::list<std::string>& theArguments,
std::string& theError) const
{
- // Get base objects list.
+ // Get attribute.
+ if(theArguments.size() != 1) {
+ Events_Error::send("Error: BuildPlugin_ValidatorBaseForWire should be used only with 1 parameter (ID of base objects list)");
+ return false;
+ }
+ AttributePtr anAttribute = theFeature->attribute(theArguments.front());
+
+ // Check base objects list.
BuildPlugin_ValidatorBaseForBuild aValidatorBaseForBuild;
- if(!aValidatorBaseForBuild.isValid(theAttribute, theArguments, theError)) {
+ std::list<std::string> anArguments;
+ anArguments.push_back("edge");
+ anArguments.push_back("wire");
+ if(!aValidatorBaseForBuild.isValid(anAttribute, anArguments, theError)) {
return false;
}
// Collect base shapes.
AttributeSelectionListPtr aSelectionList =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
ListOfShape aListOfShapes;
for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
- ResultPtr aContext = aSelection->context();
GeomShapePtr aShape = aSelection->value();
- GeomShapePtr aContextShape = aContext->shape();
if(!aShape.get()) {
aShape = aSelection->context()->shape();
}
return true;
}
+
+//=================================================================================================
+bool BuildPlugin_ValidatorBaseForWireisNotObligatory(std::string theFeature, std::string theAttribute)
+{
+ return false;
+}
+
+//=================================================================================================
+bool BuildPlugin_ValidatorBaseForFace::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
+{
+ // Get base objects list.
+ BuildPlugin_ValidatorBaseForBuild aValidatorBaseForBuild;
+ std::list<std::string> anArguments;
+ anArguments.push_back("edge");
+ anArguments.push_back("wire");
+ if(!aValidatorBaseForBuild.isValid(theAttribute, anArguments, theError)) {
+ return false;
+ }
+
+ // Collect base shapes.
+ AttributeSelectionListPtr aSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ ListOfShape aListOfShapes;
+ for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
+ GeomShapePtr aShape = aSelection->value();
+ if(!aShape.get()) {
+ aShape = aSelection->context()->shape();
+ }
+ aListOfShapes.push_back(aShape);
+ }
+
+ // Check that they are planar.
+ GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aListOfShapes);
+
+ return aCompound->isPlanar();
+}
/// \ingroup Validators
/// \brief A validator for selection base shapes for wire. Allows to select edges on sketch and
/// wires objects that are connected to already selected shapes.
-class BuildPlugin_ValidatorBaseForWire: public ModelAPI_AttributeValidator
+class BuildPlugin_ValidatorBaseForWire: public ModelAPI_FeatureValidator
+{
+public:
+ //! Returns true if attributes is ok.
+ //! \param theFeature the checked feature.
+ //! \param theArguments arguments of the feature.
+ //! \param theError error message.
+ 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
+ virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+};
+
+/// \class BuildPlugin_ValidatorBaseForFace
+/// \ingroup Validators
+/// \brief A validator for selection base shapes for face. Allows to select sketch edges, edges and
+/// wires objects that lie in the same plane.
+class BuildPlugin_ValidatorBaseForFace: public ModelAPI_AttributeValidator
{
public:
//! Returns true if attribute is ok.