X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FConstructionPlugin%2FConstructionPlugin_Validators.cpp;h=2efb39af9e2ad0600cafdb6442489aa8ee68287a;hb=eed8986352c64d13fe05eed6c42c36902ddddf52;hp=146e3055af468545c0cf0ab585acd1b943e8ca28;hpb=dc75c390f0aa6108d6983a8618dc4b9a4cd5949e;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp index 146e3055a..2efb39af9 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -12,10 +12,9 @@ // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or -// email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "ConstructionPlugin_Validators.h" @@ -27,6 +26,7 @@ #include #include #include +#include #include #include @@ -35,6 +35,7 @@ #include static std::shared_ptr getEdge(const GeomShapePtr theShape); +static std::shared_ptr getFace(const GeomShapePtr theShape); static std::shared_ptr getLin(const GeomShapePtr theShape); static std::shared_ptr getPln(const GeomShapePtr theShape); static std::shared_ptr getPnt(const GeomShapePtr theShape); @@ -53,7 +54,7 @@ bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttr GeomShapePtr aLineShape1 = aLineAttribute1->value(); ResultPtr aContext1 = aLineAttribute1->context(); if(!aContext1.get()) { - theError = "One of the attribute not initialized."; + theError = "One of the attribute is not initialized."; return false; } if(!aLineShape1.get()) { @@ -83,6 +84,11 @@ bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttr std::shared_ptr aLine1 = aLineEdge1->line(); std::shared_ptr aLine2 = aLineEdge2->line(); + if (!aLine1.get() || !aLine2.get()) { + theError = "Selected edge is not a line."; + return false; + } + if(!aLine1->isCoplanar(aLine2)) { theError = "Selected lines not coplanar."; return false; @@ -109,12 +115,12 @@ bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid( AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front()); std::shared_ptr anEdge; - std::shared_ptr aPln; + std::shared_ptr aFace; GeomShapePtr aShape1 = anAttribute1->value(); ResultPtr aContext1 = anAttribute1->context(); if(!aContext1.get()) { - theError = "One of the attribute not initialized."; + theError = "One of the attribute is not initialized."; return false; } if(!aShape1.get()) { @@ -130,22 +136,19 @@ bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid( aShape2 = aContext2->shape(); } - bool isPlaneFirst = false; anEdge = getEdge(aShape1); - aPln = getPln(aShape2); - if(!anEdge.get() || !aPln.get()) { + aFace = getFace(aShape2); + if(!anEdge.get() || !aFace.get()) { anEdge = getEdge(aShape2); - aPln = getPln(aShape1); - isPlaneFirst = true; + aFace = getFace(aShape1); } - if(!anEdge.get() || !aPln.get()) { + if(!anEdge.get() || !aFace.get()) { theError = "Wrong shape types selected."; return false; } - std::shared_ptr aPlaneFace(new GeomAPI_Face(isPlaneFirst ? aShape1 : aShape2)); - if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aPlaneFace)) { + if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aFace)) { theError = "Plane and edge are parallel."; return false; } @@ -168,7 +171,7 @@ bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& t GeomShapePtr aPointShape1 = aPointAttribute1->value(); ResultPtr aContext1 = aPointAttribute1->context(); if(!aContext1.get()) { - theError = "One of the attribute not initialized."; + theError = "One of the attribute is not initialized."; return false; } if(!aPointShape1.get()) { @@ -246,7 +249,7 @@ bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid( GeomShapePtr aShape1 = anAttribute1->value(); ResultPtr aContext1 = anAttribute1->context(); if(!aContext1.get()) { - theError = "One of the attribute not initialized."; + theError = "One of the attribute is not initialized."; return false; } if(!aShape1.get()) { @@ -304,7 +307,7 @@ bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid( GeomShapePtr aShape1 = anAttribute1->value(); ResultPtr aContext1 = anAttribute1->context(); if(!aContext1.get()) { - theError = "One of the attribute not initialized."; + theError = "One of the attribute is not initialized."; return false; } if(!aShape1.get()) { @@ -357,7 +360,7 @@ bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid( GeomShapePtr aShape1 = anAttribute1->value(); ResultPtr aContext1 = anAttribute1->context(); if(!aContext1.get()) { - theError = "One of the attribute not initialized."; + theError = "One of the attribute is not initialized."; return false; } if(!aShape1.get()) { @@ -392,27 +395,151 @@ bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid( return true; } -std::shared_ptr getEdge(const GeomShapePtr theShape) +//================================================================================================== +bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid( + const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const { - if(!theShape->isEdge()) { - return std::shared_ptr(); + FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); + + AttributeSelectionPtr anAttribute1 = + std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front()); + AttributeSelectionPtr anAttribute3 = aFeature->selection(theArguments.back()); + + GeomShapePtr aShape1 = anAttribute1->value(); + ResultPtr aContext1 = anAttribute1->context(); + if (!aContext1.get()) { + theError = "One of the attribute is not initialized."; + return false; + } + if (!aShape1.get()) { + aShape1 = aContext1->shape(); } - std::shared_ptr anEdge(new GeomAPI_Edge(theShape)); + std::shared_ptr aPln1 = getPln(aShape1); + if (!aPln1.get()) { + theError = "Wrong shape types selected."; + return false; + } + std::shared_ptr aDir1 = aPln1->direction(); + + if (anAttribute2.get()) { + GeomShapePtr aShape2 = anAttribute2->value(); + ResultPtr aContext2 = anAttribute2->context(); + if (!aShape2.get() && aContext2.get()) { + aShape2 = aContext2->shape(); + } + + if (aShape2.get()) { + std::shared_ptr aPln2 = getPln(aShape2); + if (!aPln2.get()) { + theError = "Wrong shape types selected."; + return false; + } + std::shared_ptr aDir2 = aPln2->direction(); + if (aDir1->isParallel(aDir2)) { + theError = "Planes are parallel."; + return false; + } + } + } + + if (anAttribute3.get()) { + GeomShapePtr aShape3 = anAttribute3->value(); + ResultPtr aContext3 = anAttribute3->context(); + if (!aShape3.get() && aContext3.get()) { + aShape3 = aContext3->shape(); + } + + if (aShape3.get()) { + std::shared_ptr aPln3 = getPln(aShape3); + if (!aPln3.get()) { + theError = "Wrong shape types selected."; + return false; + } + std::shared_ptr aDir3 = aPln3->direction(); + if (aDir1->isParallel(aDir3)) { + theError = "Planes are parallel."; + return false; + } + } + } + + return true; +} + +//================================================================================================== +bool ConstructionPlugin_ValidatorNotFeature::isValid( + const AttributePtr& theAttribute, + const std::list& /*theArguments*/, + Events_InfoMessage& theError) const +{ + AttributeSelectionPtr aSelAttr = + std::dynamic_pointer_cast(theAttribute); + if (!aSelAttr) { + theError = "Wrong attribute"; + return false; + } + + FeaturePtr aContextFeature = aSelAttr->contextFeature(); + if (aContextFeature) { + theError = "Feature should not be selected"; + return false; + } + return true; +} + +//================================================================================================== + +std::shared_ptr getEdge(const GeomShapePtr theShape) +{ + GeomEdgePtr anEdge; + + if(theShape->isEdge()) { + anEdge = theShape->edge(); + } + else if (theShape->isCompound()) { + GeomAPI_ShapeIterator anIt(theShape); + anEdge = anIt.current()->edge(); + } return anEdge; } +GeomFacePtr getFace(const GeomShapePtr theShape) +{ + GeomFacePtr aFace; + + if (theShape->isFace()) { + aFace = theShape->face(); + } + else if (theShape->isCompound()) { + GeomAPI_ShapeIterator anIt(theShape); + aFace = anIt.current()->face(); + } + + return aFace; +} + std::shared_ptr getLin(const GeomShapePtr theShape) { std::shared_ptr aLin; - if(!theShape->isEdge()) { + GeomEdgePtr anEdge; + + if (theShape->isEdge()) { + anEdge = theShape->edge(); + } + else if (theShape->isCompound()) { + GeomAPI_ShapeIterator anIt(theShape); + anEdge = anIt.current()->edge(); + } + else { return aLin; } - std::shared_ptr anEdge(new GeomAPI_Edge(theShape)); - if(!anEdge->isLine()) { return aLin; } @@ -426,13 +553,20 @@ std::shared_ptr getPln(const GeomShapePtr theShape) { std::shared_ptr aPln; - if(!theShape->isFace()) { + GeomFacePtr aFace; + + if(theShape->isFace()) { + aFace = theShape->face(); + } + else if (theShape->isCompound()) { + GeomAPI_ShapeIterator anIt(theShape); + aFace = anIt.current()->face(); + } + else { return aPln; } - std::shared_ptr aFace(new GeomAPI_Face(theShape)); - - if(!aFace->isPlanar()) { + if(!aFace || !aFace->isPlanar()) { return aPln; }