X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FConstructionPlugin%2FConstructionPlugin_Validators.cpp;h=a26f2f519bb7066b6d1cfb31d80e376bfb18389d;hb=ebce006a9ba80eab34d5b9e16fab6979fc091a02;hp=6fa9cbd240ac42b0f013398bcedaec07abed30a4;hpb=268d201ee47fc1896a1af0d59c5b3bf3844d3c9a;p=modules%2Fshaper.git diff --git a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp index 6fa9cbd24..a26f2f519 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Validators.cpp @@ -1,8 +1,21 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> - -// File: ConstructionPlugin_Validators.cpp -// Created: 04 July 2016 -// Author: Dmitry Bobylev +// Copyright (C) 2014-2019 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 +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// 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 +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "ConstructionPlugin_Validators.h" @@ -12,12 +25,17 @@ #include #include #include +#include +#include +#include #include #include #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); @@ -29,7 +47,8 @@ bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttr { FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); - AttributeSelectionPtr aLineAttribute1 = std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr aLineAttribute1 = + std::dynamic_pointer_cast(theAttribute); AttributeSelectionPtr aLineAttribute2 = aFeature->selection(theArguments.front()); GeomShapePtr aLineShape1 = aLineAttribute1->value(); @@ -65,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; @@ -79,18 +103,19 @@ bool ConstructionPlugin_ValidatorPointLines::isValid(const AttributePtr& theAttr } //================================================================================================== -bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid( +bool ConstructionPlugin_ValidatorPointEdgeAndPlaneNotParallel::isValid( const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const { FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); - AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anAttribute1 = + std::dynamic_pointer_cast(theAttribute); AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front()); - std::shared_ptr aLin; - std::shared_ptr aPln; + std::shared_ptr anEdge; + std::shared_ptr aFace; GeomShapePtr aShape1 = anAttribute1->value(); ResultPtr aContext1 = anAttribute1->context(); @@ -111,20 +136,23 @@ bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid( aShape2 = aContext2->shape(); } - aLin = getLin(aShape1); - aPln = getPln(aShape2); - if(!aLin.get() || !aPln.get()) { - aLin = getLin(aShape2); - aPln = getPln(aShape1); + bool isPlaneFirst = false; + anEdge = getEdge(aShape1); + + aFace = getFace(aShape2); + if(!anEdge.get() || !aFace.get()) { + anEdge = getEdge(aShape2); + aFace = getFace(aShape1); + isPlaneFirst = true; } - if(!aLin.get() || !aPln.get()) { + if(!anEdge.get() || !aFace.get()) { theError = "Wrong shape types selected."; return false; } - if(aPln->isParallel(aLin)) { - theError = "Plane and line are parallel."; + if(GeomAlgoAPI_ShapeTools::isParallel(anEdge, aFace)) { + theError = "Plane and edge are parallel."; return false; } @@ -133,12 +161,13 @@ bool ConstructionPlugin_ValidatorPointLineAndPlaneNotParallel::isValid( //================================================================================================== bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - Events_InfoMessage& theError) const + const std::list& theArguments, + Events_InfoMessage& theError) const { FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); - AttributeSelectionPtr aPointAttribute1 = std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr aPointAttribute1 = + std::dynamic_pointer_cast(theAttribute); AttributeSelectionPtr aPointAttribute2 = aFeature->selection(theArguments.front()); AttributeSelectionPtr aPointAttribute3 = aFeature->selection(theArguments.back()); @@ -190,6 +219,11 @@ bool ConstructionPlugin_ValidatorPlaneThreePoints::isValid(const AttributePtr& t std::shared_ptr aPnt2 = aVertex2->point(); std::shared_ptr aPnt3 = aVertex3->point(); + if (aPnt1->isEqual(aPnt2)) { + theError = "Selected points are equal"; + return false; + } + std::shared_ptr aLin(new GeomAPI_Lin(aPnt1, aPnt2)); if(aLin->contains(aPnt3)) { @@ -208,7 +242,8 @@ bool ConstructionPlugin_ValidatorPlaneLinePoint::isValid( { FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); - AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anAttribute1 = + std::dynamic_pointer_cast(theAttribute); AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front()); std::shared_ptr aLin; @@ -265,7 +300,8 @@ bool ConstructionPlugin_ValidatorPlaneTwoParallelPlanes::isValid( { FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); - AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anAttribute1 = + std::dynamic_pointer_cast(theAttribute); AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front()); std::shared_ptr aPln1; @@ -317,7 +353,8 @@ bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid( { FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner()); - AttributeSelectionPtr anAttribute1 = std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anAttribute1 = + std::dynamic_pointer_cast(theAttribute); AttributeSelectionPtr anAttribute2 = aFeature->selection(theArguments.front()); std::shared_ptr aPln1; @@ -361,16 +398,128 @@ bool ConstructionPlugin_ValidatorAxisTwoNotParallelPlanes::isValid( return true; } +//================================================================================================== +bool ConstructionPlugin_ValidatorPointThreeNonParallelPlanes::isValid( + const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + 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 not initialized."; + return false; + } + if (!aShape1.get()) { + aShape1 = aContext1->shape(); + } + + 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; +} + +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; } @@ -384,13 +533,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; }