use_choice="false"
concealment="true">
<validator id="PartSet_DifferentObjects"/>
- <validator id="GeomValidators_ShapeType" parameters="edge,face,solid"/>
+ <validator id="GeomValidators_IntersectionSelection"/>
</multi_selector>
<multi_selector id="tool_objects"
label="Tool objects"
use_choice="false"
concealment="true">
<validator id="PartSet_DifferentObjects"/>
- <validator id="GeomValidators_ShapeType" parameters="edge,face,solid"/>
+ <validator id="GeomValidators_IntersectionSelection"/>
</multi_selector>
</source>
GeomValidators_ZeroOffset.h
GeomValidators_Different.h
GeomValidators_BooleanSelection.h
+ GeomValidators_IntersectionSelection.h
)
SET(PROJECT_SOURCES
GeomValidators_ZeroOffset.cpp
GeomValidators_Different.cpp
GeomValidators_BooleanSelection.cpp
+ GeomValidators_IntersectionSelection.cpp
)
SET(PROJECT_LIBRARIES
#ifndef GeomValidators_BodyShapes_H
#define GeomValidators_BodyShapes_H
-#include <ModelAPI.h>
+#include <GeomValidators.h>
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_Attribute.h>
/// \param[in] theAttribute an attribute to check
/// \param[in] theArguments a filter parameters
/// \param[out] theError error message.
- MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& theError) const;
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
};
#endif
#ifndef GeomValidators_BooleanSelection_H
#define GeomValidators_BooleanSelection_H
-#include <ModelAPI.h>
+#include <GeomValidators.h>
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_Attribute.h>
/// \param[in] theAttribute an attribute to check.
/// \param[in] theArguments a filter parameters.
/// \param[out] theError error message.
- MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& theError) const;
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
};
#endif
#ifndef GeomValidators_DifferentShapes_H
#define GeomValidators_DifferentShapes_H
-#include <ModelAPI.h>
+#include <GeomValidators.h>
#include <ModelAPI_AttributeValidator.h>
#include <ModelAPI_Attribute.h>
/// \param[in] theAttribute an attribute to check
/// \param[in] theArguments a filter parameters
/// \param[out] theError error message.
- MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments,
- std::string& theError) const;
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
};
#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_IntersectionSelection.cpp
+// Created: 16 Feb 2016
+// Author: Dmitry Bobylev
+
+#include "GeomValidators_IntersectionSelection.h"
+
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Feature.h>
+
+bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const
+{
+ if(!theAttribute.get()) {
+ theError = "Error: empty selection.";
+ return false;
+ }
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+ if(!anAttrSelection.get()) {
+ theError = "Error: empty attribute selection.";
+ return false;
+ }
+ ResultPtr aContext = anAttrSelection->context();
+ if(!aContext.get()) {
+ theError = "Error: empty selection context.";
+ return false;
+ }
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
+ if(!aFeature.get()) {
+ theError = "Error: empty feature.";
+ return false;
+ }
+ std::string aFeatureKind = aFeature->getKind();
+ if(aFeatureKind == "Sketch" ||
+ aFeatureKind == "Plane" ||
+ aFeatureKind == "Axis") {
+ theError = "Error: ";
+ theError += aFeatureKind;
+ theError += " shape is not allowed for selection.";
+ return false;
+ }
+ std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+ if(!aShape.get()) {
+ aShape = aContext->shape();
+ }
+ if(!aShape.get()) {
+ theError = "Error: empty shape.";
+ return false;
+ }
+ int aShapeType = aShape->shapeType();
+ // Allow to select edges, faces and solids.
+ if(aShapeType != GeomAPI_Shape::EDGE &&
+ aShapeType != GeomAPI_Shape::FACE &&
+ aShapeType != GeomAPI_Shape::SOLID &&
+ aShapeType != GeomAPI_Shape::COMPSOLID &&
+ aShapeType != GeomAPI_Shape::COMPOUND) {
+ theError = "Error: selected shape has the wrong type.";
+ return false;
+ }
+ }
+
+ return true;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomValidators_IntersectionSelection.h
+// Created: 16 Feb 2016
+// Author: Dmitry Bobylev
+
+#ifndef GeomValidators_IntersectionSelection_H
+#define GeomValidators_IntersectionSelection_H
+
+#include <GeomValidators.h>
+
+#include <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_Attribute.h>
+
+/// \class GeomValidators_ZeroOffset
+/// \ingroup Validators
+/// \brief Validates selection for boolean operation.
+class GeomValidators_IntersectionSelection: public ModelAPI_AttributeValidator
+{
+public:
+ /// \return True if the attribute is valid. It checks whether the selection
+ /// is acceptable for boolean operation.
+ /// \param[in] theAttribute an attribute to check.
+ /// \param[in] theArguments a filter parameters.
+ /// \param[out] theError error message.
+ GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ std::string& theError) const;
+};
+
+#endif
#include <GeomValidators_PartitionArguments.h>
#include <GeomValidators_ShapeType.h>
#include <GeomValidators_ZeroOffset.h>
+#include <GeomValidators_IntersectionSelection.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
aFactory->registerValidator("GeomValidators_ZeroOffset", new GeomValidators_ZeroOffset);
aFactory->registerValidator("GeomValidators_BooleanSelection", new GeomValidators_BooleanSelection);
+ aFactory->registerValidator("GeomValidators_IntersectionSelection", new GeomValidators_IntersectionSelection);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);