X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_Box.cpp;h=cbdb91239eadc27eb95c1e162a674e202c031396;hb=5c6be24fd6035f7a030e76b8a369ef57b81893ca;hp=ee03a2224f3323a8362afc5a5fcc00322a30446c;hpb=114b72cd99a3a4be9e851be1c4b271b554808897;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp index ee03a2224..cbdb91239 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp @@ -1,8 +1,22 @@ -// Copyright (C) 2014-2016 CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_Box.cpp -// Created: 10 Mar 2016 -// Author: Clarisse Genrault (CEA) +// Copyright (C) 2014-2017 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 @@ -20,19 +34,57 @@ GeomAlgoAPI_Box::GeomAlgoAPI_Box(const double theDx, const double theDy, const d myDx = theDx; myDy = theDy; myDz = theDz; + myMethodType = MethodType::BOX_DIM; +} + +//================================================================================================= +GeomAlgoAPI_Box::GeomAlgoAPI_Box(std::shared_ptr theFirstPoint, + std::shared_ptr theSecondPoint) +{ + myFirstPoint = theFirstPoint; + mySecondPoint = theSecondPoint; + myMethodType = MethodType::BOX_POINTS; } //================================================================================================= bool GeomAlgoAPI_Box::check() { - if (myDx < Precision::Confusion()) { - myError = "Box builder with dimensions :: Dx is null."; - return false; - } else if (myDy < Precision::Confusion()) { - myError = "Box builder with dimensions :: Dy is null."; - return false; - } else if (myDz < Precision::Confusion()) { - myError = "Box builder with dimensions :: Dz is null."; + if (myMethodType == MethodType::BOX_DIM) { + if (myDx < Precision::Confusion()) { + myError = "Box builder with dimensions :: Dx is null or negative."; + return false; + } else if (myDy < Precision::Confusion()) { + myError = "Box builder with dimensions :: Dy is null or negative."; + return false; + } else if (myDz < Precision::Confusion()) { + myError = "Box builder with dimensions :: Dz is null or negative."; + return false; + } + } else if (myMethodType == MethodType::BOX_POINTS) { + if (!myFirstPoint.get()) { + myError = "Box builder with points :: the first point is not valid."; + return false; + } + if (!mySecondPoint.get()) { + myError = "Box builder with points :: the second point is not valid."; + return false; + } + if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion()) { + myError = "Box builder with points :: the distance between the two points is null."; + return false; + } + double aDiffX = myFirstPoint->x() - mySecondPoint->x(); + double aDiffY = myFirstPoint->y() - mySecondPoint->y(); + double aDiffZ = myFirstPoint->z() - mySecondPoint->z(); + if (fabs(aDiffX) < Precision::Confusion() || + fabs(aDiffY) < Precision::Confusion() || + fabs(aDiffZ) < Precision::Confusion()) { + myError = + "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes."; + return false; + } + } else { + myError = "Box builder :: Method not implemented."; return false; } return true; @@ -40,32 +92,80 @@ bool GeomAlgoAPI_Box::check() //================================================================================================= void GeomAlgoAPI_Box::build() +{ + if (myMethodType == MethodType::BOX_DIM) { + buildWithDimensions(); + } else if (myMethodType == MethodType::BOX_POINTS) { + buildWithPoints(); + } else { + myError = "Box builder :: Method not implemented."; + return; + } +} + +//================================================================================================= +void GeomAlgoAPI_Box::buildWithDimensions() { myCreatedFaces.clear(); - + // Construct the box BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(myDx, myDy, myDz); aBoxMaker->Build(); - + // Test the algorithm if (!aBoxMaker->IsDone()) { myError = "Box builder with dimensions :: algorithm failed."; return; } - + TopoDS_Shape aResult = aBoxMaker->Shape(); std::shared_ptr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aResult)); setShape(aShape); - + // Test on the shapes if (!aShape.get() || aShape->isNull()) { myError = "Box builder with dimensions :: resulting shape is null."; return; } - + + setImpl(aBoxMaker); + + setDone(true); +} + +//================================================================================================= +void GeomAlgoAPI_Box::buildWithPoints() +{ + myCreatedFaces.clear(); + + const gp_Pnt& aFirstPoint = myFirstPoint->impl(); + const gp_Pnt& aSecondPoint = mySecondPoint->impl(); + + // Construct the box + BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(aFirstPoint, aSecondPoint); + aBoxMaker->Build(); + + // Test the algorithm + if(!aBoxMaker->IsDone()) { + myError = "Box builder with two points :: algorithm failed."; + return; + } + + TopoDS_Shape aResult = aBoxMaker->Shape(); + + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + setShape(aShape); + + // Tests on the shape + if (!aShape.get() || aShape->isNull()) { + myError = "Box builder with two points :: resulting shape is null."; + return; + } + setImpl(aBoxMaker); - + setDone(true); } @@ -79,16 +179,16 @@ void GeomAlgoAPI_Box::prepareNamingFaces() std::shared_ptr aShapeBack(new GeomAPI_Shape); aShapeBack->setImpl(new TopoDS_Shape(aBoxMaker.BackFace())); myCreatedFaces["Back"] = aShapeBack; - std::shared_ptr aShapeTop(new GeomAPI_Shape); + std::shared_ptr aShapeTop(new GeomAPI_Shape); aShapeTop->setImpl(new TopoDS_Shape(aBoxMaker.TopFace())); myCreatedFaces["Top"] = aShapeTop; - std::shared_ptr aShapeBottom(new GeomAPI_Shape); + std::shared_ptr aShapeBottom(new GeomAPI_Shape); aShapeBottom->setImpl(new TopoDS_Shape(aBoxMaker.BottomFace())); myCreatedFaces["Bottom"] = aShapeBottom; - std::shared_ptr aShapeLeft(new GeomAPI_Shape); + std::shared_ptr aShapeLeft(new GeomAPI_Shape); aShapeLeft->setImpl(new TopoDS_Shape(aBoxMaker.LeftFace())); myCreatedFaces["Left"] = aShapeLeft; - std::shared_ptr aShapeRight(new GeomAPI_Shape); + std::shared_ptr aShapeRight(new GeomAPI_Shape); aShapeRight->setImpl(new TopoDS_Shape(aBoxMaker.RightFace())); myCreatedFaces["Right"] = aShapeRight; }