From: azv Date: Thu, 21 Dec 2017 10:17:54 +0000 (+0300) Subject: Improve the correcting orientation in the Filling feature. X-Git-Tag: V_2.10.1~27 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b3dc09454bb4a591e37841d8c15b4dcbe678a8e6;p=modules%2Fshaper.git Improve the correcting orientation in the Filling feature. Add validator for the Filling selection. --- diff --git a/src/BuildPlugin/BuildPlugin_Filling.cpp b/src/BuildPlugin/BuildPlugin_Filling.cpp index a5597f6e6..e9b376399 100644 --- a/src/BuildPlugin/BuildPlugin_Filling.cpp +++ b/src/BuildPlugin/BuildPlugin_Filling.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -167,7 +168,7 @@ GeomEdgePtr BuildPlugin_Filling::toEdge(const GeomShapePtr& theShape, const std: 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( @@ -189,6 +190,10 @@ GeomEdgePtr BuildPlugin_Filling::toEdge(const GeomShapePtr& theShape, const std: // 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) diff --git a/src/BuildPlugin/BuildPlugin_Plugin.cpp b/src/BuildPlugin/BuildPlugin_Plugin.cpp index fed1877f9..2042eb2f1 100644 --- a/src/BuildPlugin/BuildPlugin_Plugin.cpp +++ b/src/BuildPlugin/BuildPlugin_Plugin.cpp @@ -49,6 +49,8 @@ BuildPlugin_Plugin::BuildPlugin_Plugin() 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); diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index 244ddb6e4..e0268ef42 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -359,3 +359,53 @@ bool BuildPlugin_ValidatorSubShapesSelection::isValid(const AttributePtr& theAtt return true; } + + +//================================================================================================= +bool BuildPlugin_ValidatorFillingSelection::isValid(const AttributePtr& theAttribute, + const std::list& 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(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; +} diff --git a/src/BuildPlugin/BuildPlugin_Validators.h b/src/BuildPlugin/BuildPlugin_Validators.h index 522e3bb83..5f3be35da 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.h +++ b/src/BuildPlugin/BuildPlugin_Validators.h @@ -94,4 +94,19 @@ public: 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& theArguments, + Events_InfoMessage& theError) const; +}; + #endif diff --git a/src/BuildPlugin/filling_widget.xml b/src/BuildPlugin/filling_widget.xml index a9e393004..0ecb85877 100644 --- a/src/BuildPlugin/filling_widget.xml +++ b/src/BuildPlugin/filling_widget.xml @@ -26,6 +26,7 @@ email : webmaster.salome@opencascade.com +