Add validator for the Filling selection.
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultBody.h>
+#include <GeomAlgoAPI_Copy.h>
#include <GeomAlgoAPI_Filling.h>
#include <GeomAlgoAPI_ShapeTools.h>
GeomEdgePtr anEdge;
switch (theShape->shapeType()) {
case GeomAPI_Shape::EDGE:
- anEdge = GeomEdgePtr(new GeomAPI_Edge(theShape));
+ anEdge = GeomEdgePtr(new GeomAPI_Edge(GeomAlgoAPI_Copy(theShape).shape()));
break;
case GeomAPI_Shape::WIRE:
anEdge = GeomAlgoAPI_ShapeTools::wireToEdge(
// check the distance to previous edge boundaries, reverse edge if necessary
GeomPointPtr aStartPnt = anEdge->firstPoint();
GeomPointPtr aEndPnt = anEdge->lastPoint();
+ if (anEdge->orientation() == GeomAPI_Shape::REVERSED) {
+ aStartPnt = anEdge->lastPoint();
+ aEndPnt = anEdge->firstPoint();
+ }
bool isReverse = false;
if (myLastEdgeStartPoint) {
double d1 = myLastEdgeStartPoint->distance(aStartPnt)
new BuildPlugin_ValidatorBaseForFace());
aFactory->registerValidator("BuildPlugin_ValidatorSubShapesSelection",
new BuildPlugin_ValidatorSubShapesSelection());
+ aFactory->registerValidator("BuildPlugin_ValidatorFillingSelection",
+ new BuildPlugin_ValidatorFillingSelection());
// Register this plugin.
ModelAPI_Session::get()->registerPlugin(this);
return true;
}
+
+
+//=================================================================================================
+bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ // Get base objects list.
+ if (theAttribute->attributeType() != ModelAPI_AttributeSelectionList::typeId()) {
+ std::string aMsg =
+ "Error: BuildPlugin_ValidatorFillingSelection does not support attribute type \""
+ "%1\"\n Only \"%2\" supported.";
+ Events_InfoMessage("BuildPlugin_Validators", aMsg).
+ arg(theAttribute->attributeType()).arg(ModelAPI_AttributeSelectionList::typeId()).send();
+ return false;
+ }
+ AttributeSelectionListPtr aSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if (!aSelectionList.get()) {
+ theError = "Could not get selection list.";
+ return false;
+ }
+
+ FeaturePtr anOwner = ModelAPI_Feature::feature(theAttribute->owner());
+
+ // Check selected shapes.
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
+ AttributeSelectionPtr aSelectionAttrInList = aSelectionList->value(anIndex);
+ if (!aSelectionAttrInList.get()) {
+ theError = "Empty attribute in list.";
+ return false;
+ }
+
+ // Check shape exists.
+ GeomShapePtr aShapeInList = aSelectionAttrInList->value();
+ if (!aShapeInList.get()) {
+ theError = "Object has no shape";
+ return false;
+ }
+
+ // Check shape type.
+ GeomAPI_Shape::ShapeType aType = aShapeInList->shapeType();
+ if (aType != GeomAPI_Shape::EDGE && aType != GeomAPI_Shape::WIRE) {
+ theError = "Incorrect objects selected";
+ return false;
+ }
+ }
+
+ return true;
+}
Events_InfoMessage& theError) const;
};
+/// \class BuildPlugin_ValidatorFillingSelection
+/// \ingroup Validators
+/// \brief A validator for selection of Filling feature.
+class BuildPlugin_ValidatorFillingSelection: public ModelAPI_AttributeValidator
+{
+public:
+ //! Returns true if attribute is ok.
+ //! \param[in] theAttribute the checked attribute.
+ //! \param[in] theArguments arguments of the attribute.
+ //! \param[out] theError error message.
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const;
+};
+
#endif
type_choice="edges wires"
concealment="false">
<validator id="PartSet_DifferentObjects"/>
+ <validator id="BuildPlugin_ValidatorFillingSelection"/>
</multi_selector>
<optionalbox id="advanced_options" title="Advanced options">
<switch id="orientation" label="Orientation">