1 // Copyright (C) 2018-2022 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FeaturesPlugin_BoundingBoxBase.h"
22 #include <ModelAPI_AttributeDoubleArray.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_ResultBody.h>
26 #include <ModelAPI_Session.h>
27 #include <ModelAPI_Validator.h>
28 #include <GeomAPI_Vertex.h>
30 #include <GeomAlgoAPI_BoundingBox.h>
31 #include <GeomAlgoAPI_PointBuilder.h>
32 #include <GeomAlgoAPI_ShapeTools.h>
34 #include <Config_PropManager.h>
41 //=================================================================================================
42 void FeaturesPlugin_BoundingBoxBase::createBoxByTwoPoints()
44 AttributeDoubleArrayPtr aValues =
45 std::dynamic_pointer_cast<ModelAPI_AttributeDoubleArray>(attributResultValues());
47 SessionPtr aSession = ModelAPI_Session::get();
49 DocumentPtr aDoc = aSession->activeDocument();
51 GeomVertexPtr vertexFirst =
52 GeomAlgoAPI_PointBuilder::vertex(aValues->value(0),
56 GeomVertexPtr vertexSecond =
57 GeomAlgoAPI_PointBuilder::vertex(aValues->value(1),
62 std::shared_ptr<GeomAlgoAPI_Box> aBoxAlgo;
65 aBoxAlgo = std::shared_ptr<GeomAlgoAPI_Box>(
66 new GeomAlgoAPI_Box(vertexFirst->point(),vertexSecond->point()));
69 // These checks should be made to the GUI for the feature but
70 // the corresponding validator does not exist yet.
71 if (!aBoxAlgo->check()) {
72 setError(aBoxAlgo->getError());
79 // Check if the creation of the box
80 if (!aBoxAlgo->isDone()) {
81 // The error is not displayed in a popup window. It must be in the message console.
82 setError(aBoxAlgo->getError());
85 if (!aBoxAlgo->checkValid("Box builder with two points")) {
86 // The error is not displayed in a popup window. It must be in the message console.
87 setError(aBoxAlgo->getError());
92 ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
93 loadNamingDS(aBoxAlgo, aResultBox);
94 setResult(aResultBox, aResultIndex);
97 //=================================================================================================
98 void FeaturesPlugin_BoundingBoxBase::loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxAlgo,
99 std::shared_ptr<ModelAPI_ResultBody> theResultBox)
102 theResultBox->store(theBoxAlgo->shape());
104 // Prepare the naming
105 theBoxAlgo->prepareNamingFaces();
108 std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces =
109 theBoxAlgo->getCreatedFaces();
110 for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator it = listOfFaces.begin();
111 it != listOfFaces.end();
113 theResultBox->generated((*it).second, (*it).first);