1 // Copyright (C) 2014-2019 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 "PrimitivesAPI_Box.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
32 //==================================================================================================
33 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34 const ModelHighAPI_Double & theDx,
35 const ModelHighAPI_Double & theDy,
36 const ModelHighAPI_Double & theDz)
37 : ModelHighAPI_Interface(theFeature)
40 setDimensions(theDx, theDy, theDz);
43 //==================================================================================================
44 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45 const ModelHighAPI_Selection& theFirstPoint,
46 const ModelHighAPI_Selection& theSecondPoint)
47 : ModelHighAPI_Interface(theFeature)
50 setPoints(theFirstPoint, theSecondPoint);
53 //==================================================================================================
54 PrimitivesAPI_Box::~PrimitivesAPI_Box()
59 //==================================================================================================
60 void PrimitivesAPI_Box::setDimensions(const ModelHighAPI_Double& theDx,
61 const ModelHighAPI_Double& theDy,
62 const ModelHighAPI_Double& theDz)
64 fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
65 fillAttribute(theDx, dx());
66 fillAttribute(theDy, dy());
67 fillAttribute(theDz, dz());
72 //==================================================================================================
73 void PrimitivesAPI_Box::setPoints(const ModelHighAPI_Selection& theFirstPoint,
74 const ModelHighAPI_Selection& theSecondPoint)
76 fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
77 fillAttribute(theFirstPoint, firstPoint());
78 fillAttribute(theSecondPoint, secondPoint());
83 //==================================================================================================
84 void PrimitivesAPI_Box::dump(ModelHighAPI_Dumper& theDumper) const
86 FeaturePtr aBase = feature();
87 const std::string& aDocName = theDumper.name(aBase->document());
89 theDumper << aBase << " = model.addBox(" << aDocName;
91 std::string aCreationMethod = aBase->string(PrimitivesPlugin_Box::CREATION_METHOD())->value();
93 if(aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS()) {
94 AttributeDoublePtr anAttrDx = aBase->real(PrimitivesPlugin_Box::DX_ID());
95 AttributeDoublePtr anAttrDy = aBase->real(PrimitivesPlugin_Box::DY_ID());
96 AttributeDoublePtr anAttrDz = aBase->real(PrimitivesPlugin_Box::DZ_ID());
97 theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
98 } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) {
99 AttributeSelectionPtr anAttrFirstPnt =
100 aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
101 AttributeSelectionPtr anAttrSecondPnt =
102 aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
103 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
106 theDumper << ")" << std::endl;
109 //==================================================================================================
110 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
111 const ModelHighAPI_Double& theDx,
112 const ModelHighAPI_Double& theDy,
113 const ModelHighAPI_Double& theDz)
115 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
116 return BoxPtr(new PrimitivesAPI_Box(aFeature, theDx, theDy, theDz));
119 //==================================================================================================
120 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
121 const ModelHighAPI_Selection& theFirstPoint,
122 const ModelHighAPI_Selection& theSecondPoint)
124 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
125 return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint));