1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PrimitivesAPI_Box.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 //==================================================================================================
27 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
33 //==================================================================================================
34 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35 const ModelHighAPI_Double & theDx,
36 const ModelHighAPI_Double & theDy,
37 const ModelHighAPI_Double & theDz)
38 : ModelHighAPI_Interface(theFeature)
41 setDimensions(theDx, theDy, theDz);
44 //==================================================================================================
45 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
46 const ModelHighAPI_Selection& theFirstPoint,
47 const ModelHighAPI_Selection& theSecondPoint)
48 : ModelHighAPI_Interface(theFeature)
51 setPoints(theFirstPoint, theSecondPoint);
54 //==================================================================================================
55 PrimitivesAPI_Box::~PrimitivesAPI_Box()
60 //==================================================================================================
61 void PrimitivesAPI_Box::setDimensions(const ModelHighAPI_Double& theDx,
62 const ModelHighAPI_Double& theDy,
63 const ModelHighAPI_Double& theDz)
65 fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
66 fillAttribute(theDx, dx());
67 fillAttribute(theDy, dy());
68 fillAttribute(theDz, dz());
73 //==================================================================================================
74 void PrimitivesAPI_Box::setPoints(const ModelHighAPI_Selection& theFirstPoint,
75 const ModelHighAPI_Selection& theSecondPoint)
77 fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
78 fillAttribute(theFirstPoint, firstPoint());
79 fillAttribute(theSecondPoint, secondPoint());
84 //==================================================================================================
85 void PrimitivesAPI_Box::dump(ModelHighAPI_Dumper& theDumper) const
87 FeaturePtr aBase = feature();
88 const std::string& aDocName = theDumper.name(aBase->document());
90 theDumper << aBase << " = model.addBox(" << aDocName;
92 std::string aCreationMethod = aBase->string(PrimitivesPlugin_Box::CREATION_METHOD())->value();
94 if(aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS()) {
95 AttributeDoublePtr anAttrDx = aBase->real(PrimitivesPlugin_Box::DX_ID());
96 AttributeDoublePtr anAttrDy = aBase->real(PrimitivesPlugin_Box::DY_ID());
97 AttributeDoublePtr anAttrDz = aBase->real(PrimitivesPlugin_Box::DZ_ID());
98 theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
99 } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) {
100 AttributeSelectionPtr anAttrFirstPnt =
101 aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
102 AttributeSelectionPtr anAttrSecondPnt =
103 aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
104 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
107 theDumper << ")" << std::endl;
110 //==================================================================================================
111 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
112 const ModelHighAPI_Double& theDx,
113 const ModelHighAPI_Double& theDy,
114 const ModelHighAPI_Double& theDz)
116 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
117 return BoxPtr(new PrimitivesAPI_Box(aFeature, theDx, theDy, theDz));
120 //==================================================================================================
121 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
122 const ModelHighAPI_Selection& theFirstPoint,
123 const ModelHighAPI_Selection& theSecondPoint)
125 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
126 return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint));