From: dbv Date: Wed, 2 Dec 2015 13:09:29 +0000 (+0300) Subject: Update validator X-Git-Tag: V_2.1.0~221 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a57ebcbce92f5113504466d88dc12cc722baeddb;p=modules%2Fshaper.git Update validator --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index c8ac130c4..3f7ed7efd 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -61,36 +61,26 @@ void FeaturesPlugin_Extrusion::execute() ListOfShape aFacesList; AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID()); for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) { - std::shared_ptr aFaceSel = aFacesSelectionList->value(anIndex); - ResultPtr aContext = aFaceSel->context(); - std::shared_ptr aContextShape = aContext->shape(); - if(!aContextShape.get()) { - static const std::string aContextError = "The selection context is bad"; - setError(aContextError); - break; - } - + AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex); std::shared_ptr aFaceShape = aFaceSel->value(); - int aFacesNum = -1; // this mean that "aFace" is used - ResultConstructionPtr aConstruction = - std::dynamic_pointer_cast(aContext); - if(!aFaceShape.get()) { // this may be the whole sketch result selected, check and get faces - if (aConstruction.get()) { - aFacesNum = aConstruction->facesNum(); - } else { + if(aFaceShape.get() && !aFaceShape->isNull()) { // Getting face. + aFacesList.push_back(aFaceShape); + } else { // This may be the whole sketch result selected, check and get faces. + ResultPtr aContext = aFaceSel->context(); + std::shared_ptr aContextShape = aContext->shape(); + if(!aContextShape.get()) { + static const std::string aContextError = "The selection context is bad"; + setError(aContextError); + return; + } + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aContext); + if(!aConstruction.get()) { static const std::string aFaceError = "Can not find basis for extrusion"; setError(aFaceError); - break; + return; } - } - for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { - std::shared_ptr aBaseShape; - if (aFacesNum == -1) { - if (!aFaceShape->isNull()) { - aFacesList.push_back(aFaceShape); - } - break; - } else { + int aFacesNum = aConstruction->facesNum(); + for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { aFaceShape = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); aFacesList.push_back(aFaceShape); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp index fd06b5f96..f37eac6c8 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp @@ -58,34 +58,26 @@ void FeaturesPlugin_Revolution::execute() ListOfShape aFacesList; AttributeSelectionListPtr aFacesSelectionList = selectionList(LIST_ID()); for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) { - std::shared_ptr aFaceSel = aFacesSelectionList->value(anIndex); - ResultPtr aContext = aFaceSel->context(); - std::shared_ptr aContextShape = aContext->shape(); - if(!aContextShape.get()) { - static const std::string aContextError = "The selection context is bad"; - setError(aContextError); - break; - } - + AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex); std::shared_ptr aFaceShape = aFaceSel->value(); - int aFacesNum = -1; // this mean that "aFace" is used - ResultConstructionPtr aConstruction = - std::dynamic_pointer_cast(aContext); - if(!aFaceShape.get()) { // this may be the whole sketch result selected, check and get faces - if (aConstruction.get()) { - aFacesNum = aConstruction->facesNum(); - } else { + if(aFaceShape.get() && !aFaceShape->isNull()) { // Getting face. + aFacesList.push_back(aFaceShape); + } else { // This may be the whole sketch result selected, check and get faces. + ResultPtr aContext = aFaceSel->context(); + std::shared_ptr aContextShape = aContext->shape(); + if(!aContextShape.get()) { + static const std::string aContextError = "The selection context is bad"; + setError(aContextError); + return; + } + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aContext); + if(!aConstruction.get()) { static const std::string aFaceError = "Can not find basis for revolution"; setError(aFaceError); - break; + return; } - } - for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { - std::shared_ptr aBaseShape; - if (aFacesNum == -1) { - aFacesList.push_back(aFaceShape); - break; - } else { + int aFacesNum = aConstruction->facesNum(); + for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { aFaceShape = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); aFacesList.push_back(aFaceShape); } diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index a2d10a699..90a7b7078 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -77,5 +77,5 @@ - + diff --git a/src/FeaturesPlugin/extrusioncut_widget.xml b/src/FeaturesPlugin/extrusioncut_widget.xml index a5bd0a91d..5a1c29076 100755 --- a/src/FeaturesPlugin/extrusioncut_widget.xml +++ b/src/FeaturesPlugin/extrusioncut_widget.xml @@ -72,5 +72,5 @@ concealment="true"> - + diff --git a/src/FeaturesPlugin/extrusionfuse_widget.xml b/src/FeaturesPlugin/extrusionfuse_widget.xml index eb9254066..fb06968e0 100644 --- a/src/FeaturesPlugin/extrusionfuse_widget.xml +++ b/src/FeaturesPlugin/extrusionfuse_widget.xml @@ -72,5 +72,5 @@ concealment="true"> - + diff --git a/src/FeaturesPlugin/extrusionsketch_widget.xml b/src/FeaturesPlugin/extrusionsketch_widget.xml index c136499f5..a5c74f6d0 100644 --- a/src/FeaturesPlugin/extrusionsketch_widget.xml +++ b/src/FeaturesPlugin/extrusionsketch_widget.xml @@ -65,5 +65,5 @@ - + diff --git a/src/FeaturesPlugin/revolution_widget.xml b/src/FeaturesPlugin/revolution_widget.xml index 19527f989..d64ceef23 100644 --- a/src/FeaturesPlugin/revolution_widget.xml +++ b/src/FeaturesPlugin/revolution_widget.xml @@ -93,5 +93,5 @@ - + \ No newline at end of file diff --git a/src/FeaturesPlugin/revolutioncut_widget.xml b/src/FeaturesPlugin/revolutioncut_widget.xml index dac018aaa..c90327b4c 100644 --- a/src/FeaturesPlugin/revolutioncut_widget.xml +++ b/src/FeaturesPlugin/revolutioncut_widget.xml @@ -88,5 +88,5 @@ concealment="true"> - + diff --git a/src/FeaturesPlugin/revolutionfuse_widget.xml b/src/FeaturesPlugin/revolutionfuse_widget.xml index b590bbfd6..79455e844 100644 --- a/src/FeaturesPlugin/revolutionfuse_widget.xml +++ b/src/FeaturesPlugin/revolutionfuse_widget.xml @@ -88,5 +88,5 @@ concealment="true"> - + diff --git a/src/FeaturesPlugin/revolutionsketch_widget.xml b/src/FeaturesPlugin/revolutionsketch_widget.xml index 460fd7a95..c72c0f220 100644 --- a/src/FeaturesPlugin/revolutionsketch_widget.xml +++ b/src/FeaturesPlugin/revolutionsketch_widget.xml @@ -81,5 +81,5 @@ - + diff --git a/src/GeomAPI/GeomAPI_Pln.cpp b/src/GeomAPI/GeomAPI_Pln.cpp index 4947170e9..dfb7e9bd7 100644 --- a/src/GeomAPI/GeomAPI_Pln.cpp +++ b/src/GeomAPI/GeomAPI_Pln.cpp @@ -45,3 +45,14 @@ void GeomAPI_Pln::coefficients(double& theA, double& theB, double& theC, double& { impl().Coefficients(theA, theB, theC, theD); } + +bool GeomAPI_Pln::isCoincident(const std::shared_ptr thePlane, const double theTolerance) +{ + if(!thePlane.get()) { + return false; + } + + const gp_Pln& aMyPln = impl(); + const gp_Pln& anOtherPln = thePlane->impl(); + return (aMyPln.Contains(anOtherPln.Location(), theTolerance) && aMyPln.Axis().IsParallel(anOtherPln.Axis(), theTolerance)); +} diff --git a/src/GeomAPI/GeomAPI_Pln.h b/src/GeomAPI/GeomAPI_Pln.h index 405cc7e98..e0564557e 100644 --- a/src/GeomAPI/GeomAPI_Pln.h +++ b/src/GeomAPI/GeomAPI_Pln.h @@ -46,6 +46,10 @@ class GeomAPI_Pln : public GeomAPI_Interface /// Returns the plane coefficients (Ax+By+Cz+D=0) GEOMAPI_EXPORT void coefficients(double& theA, double& theB, double& theC, double& theD); + + /// Returns true if planes are coincident. + GEOMAPI_EXPORT + bool isCoincident(const std::shared_ptr thePlane, const double theTolerance = 1.e-7); }; #endif diff --git a/src/GeomValidators/GeomValidators_ZeroOffset.cpp b/src/GeomValidators/GeomValidators_ZeroOffset.cpp index 9f0d5ede1..3d08e9fd9 100644 --- a/src/GeomValidators/GeomValidators_ZeroOffset.cpp +++ b/src/GeomValidators/GeomValidators_ZeroOffset.cpp @@ -6,18 +6,25 @@ #include -#include #include #include +#include #include +#include + +#include +#include +#include +#include +#include //================================================================================================= bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, std::string& theError) const { - if(theArguments.size() != 8) { - theError = "Wrong number of arguments (expected 8)."; + if(theArguments.size() != 9) { + theError = "Wrong number of validator arguments in xml(expected 9)."; return false; } @@ -30,7 +37,45 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& anIt++; std::string aCreationMethod = *anIt; anIt++; - + + ListOfShape aFacesList; + if(theFeature->selection(*anIt)) { + AttributeSelectionPtr aFaceSelection = theFeature->selection(*anIt); + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aFaceSelection->context()); + if(aConstruction.get()) { + int aSketchFacesNum = aConstruction->facesNum(); + for(int aFaceIndex = 0; aFaceIndex < aSketchFacesNum; aFaceIndex++) { + std::shared_ptr aFace = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); + aFacesList.push_back(aFace); + } + } + } else if(theFeature->selectionList(*anIt)) { + AttributeSelectionListPtr aFacesSelectionList = theFeature->selectionList(*anIt); + for(int anIndex = 0; anIndex < aFacesSelectionList->size(); anIndex++) { + AttributeSelectionPtr aFaceSel = aFacesSelectionList->value(anIndex); + std::shared_ptr aFaceShape = aFaceSel->value(); + if(aFaceShape.get() && !aFaceShape->isNull()) { // Getting face. + aFacesList.push_back(aFaceShape); + } else { // This may be the whole sketch result selected, check and get faces. + ResultPtr aContext = aFaceSel->context(); + std::shared_ptr aContextShape = aContext->shape(); + if(!aContextShape.get()) { + break; + } + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aContext); + if(!aConstruction.get()) { + break; + } + int aFacesNum = aConstruction->facesNum(); + for(int aFaceIndex = 0; aFaceIndex < aFacesNum || aFacesNum == -1; aFaceIndex++) { + aFaceShape = std::dynamic_pointer_cast(aConstruction->face(aFaceIndex)); + aFacesList.push_back(aFaceShape); + } + } + } + } + anIt++; + double aToSize = 0.0; double aFromSize = 0.0; @@ -84,9 +129,42 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& aFromSize = anAttrDouble->value(); } - if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape))) - && (aFromSize == -aToSize)) { - theError = "FromSize = -ToSize and bounding planes are equal."; + bool isPlanesCoincident = false; + if(!aFromShape.get() && !aToShape.get()) { + isPlanesCoincident = true; + } else if(aFromShape.get() && aToShape.get()) { + std::shared_ptr aFromFace(new GeomAPI_Face(aFromShape)); + std::shared_ptr aFromPln = aFromFace->getPlane(); + + std::shared_ptr aToFace(new GeomAPI_Face(aToShape)); + std::shared_ptr aToPln = aToFace->getPlane(); + + if(aFromPln.get()) { + isPlanesCoincident = aFromPln->isCoincident(aToPln); + } + } else { + std::shared_ptr aFace; + if(aFromShape.get()) { + aFace.reset(new GeomAPI_Face(aFromShape)); + } else { + aFace.reset(new GeomAPI_Face(aToShape)); + } + std::shared_ptr aPln = aFace->getPlane(); + if(aPln.get()) { + for(ListOfShape::const_iterator anIter = aFacesList.cbegin(); anIter != aFacesList.cend(); anIter++) { + std::shared_ptr aSketchShape = *anIter; + std::shared_ptr aSketchFace(new GeomAPI_Face(aSketchShape)); + std::shared_ptr aSketchPln = aSketchFace->getPlane(); + if(aPln->isCoincident(aSketchPln)) { + isPlanesCoincident = true; + break; + } + } + } + } + + if(isPlanesCoincident && aFromSize == -aToSize) { + theError = "FromSize = -ToSize and bounding planes are coincident."; return false; }