1 // Copyright (C) 2014-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 "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(const std::shared_ptr<ModelAPI_Feature>& theFeature,
55 const ModelHighAPI_Double& theOx,
56 const ModelHighAPI_Double& theOy,
57 const ModelHighAPI_Double& theOz,
58 const ModelHighAPI_Double& theHalfX,
59 const ModelHighAPI_Double& theHalfY,
60 const ModelHighAPI_Double& theHalfZ)
61 : ModelHighAPI_Interface(theFeature)
65 fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_ONE_POINT_AND_DIMS(), creationMethod());
66 fillAttribute(theOx, ox());
67 fillAttribute(theOy, oy());
68 fillAttribute(theOz, oz());
69 fillAttribute(theHalfX, halfdx());
70 fillAttribute(theHalfY, halfdy());
71 fillAttribute(theHalfZ, halfdz());
76 //==================================================================================================
77 PrimitivesAPI_Box::~PrimitivesAPI_Box()
82 //==================================================================================================
83 void PrimitivesAPI_Box::setDimensions(const ModelHighAPI_Double& theDx,
84 const ModelHighAPI_Double& theDy,
85 const ModelHighAPI_Double& theDz)
87 fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
88 fillAttribute(theDx, dx());
89 fillAttribute(theDy, dy());
90 fillAttribute(theDz, dz());
95 //==================================================================================================
96 void PrimitivesAPI_Box::setPoints(const ModelHighAPI_Selection& theFirstPoint,
97 const ModelHighAPI_Selection& theSecondPoint)
99 fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
100 fillAttribute(theFirstPoint, firstPoint());
101 fillAttribute(theSecondPoint, secondPoint());
106 //==================================================================================================
107 void PrimitivesAPI_Box::setOrigin(const ModelHighAPI_Double& theOx,
108 const ModelHighAPI_Double& theOy,
109 const ModelHighAPI_Double& theOz)
111 fillAttribute(theOx, ox());
112 fillAttribute(theOy, oy());
113 fillAttribute(theOz, oz());
118 //==================================================================================================
119 void PrimitivesAPI_Box::setHalfLengths(const ModelHighAPI_Double& theHalfLengthX,
120 const ModelHighAPI_Double& theHalfLengthY,
121 const ModelHighAPI_Double& theHalfLengthZ)
123 fillAttribute(theHalfLengthX, halfdx());
124 fillAttribute(theHalfLengthY, halfdy());
125 fillAttribute(theHalfLengthZ, halfdz());
130 //==================================================================================================
131 void PrimitivesAPI_Box::dump(ModelHighAPI_Dumper& theDumper) const
133 FeaturePtr aBase = feature();
134 const std::string& aDocName = theDumper.name(aBase->document());
136 theDumper << aBase << " = model.addBox(" << aDocName;
138 std::string aCreationMethod = aBase->string(PrimitivesPlugin_Box::CREATION_METHOD())->value();
140 if(aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS()) {
141 AttributeDoublePtr anAttrDx = aBase->real(PrimitivesPlugin_Box::DX_ID());
142 AttributeDoublePtr anAttrDy = aBase->real(PrimitivesPlugin_Box::DY_ID());
143 AttributeDoublePtr anAttrDz = aBase->real(PrimitivesPlugin_Box::DZ_ID());
144 theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
145 } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) {
146 AttributeSelectionPtr anAttrFirstPnt =
147 aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
148 AttributeSelectionPtr anAttrSecondPnt =
149 aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
150 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
151 } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_ONE_POINT_AND_DIMS()) {
152 AttributeDoublePtr anAttrOx = aBase->real(PrimitivesPlugin_Box::OX_ID());
153 AttributeDoublePtr anAttrOy = aBase->real(PrimitivesPlugin_Box::OY_ID());
154 AttributeDoublePtr anAttrOz = aBase->real(PrimitivesPlugin_Box::OZ_ID());
155 AttributeDoublePtr anAttrHalfLengthX = aBase->real(PrimitivesPlugin_Box::HALF_DX_ID());
156 AttributeDoublePtr anAttrHalfLengthY = aBase->real(PrimitivesPlugin_Box::HALF_DY_ID());
157 AttributeDoublePtr anAttrHalfLengthZ = aBase->real(PrimitivesPlugin_Box::HALF_DZ_ID());
158 theDumper << ", " << anAttrOx << ", " << anAttrOy << ", " << anAttrOz;
159 theDumper << ", " << anAttrHalfLengthX << ", " << anAttrHalfLengthY;
160 theDumper << ", " << anAttrHalfLengthZ;
163 theDumper << ")" << std::endl;
166 //==================================================================================================
167 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
168 const ModelHighAPI_Double& theDx,
169 const ModelHighAPI_Double& theDy,
170 const ModelHighAPI_Double& theDz)
172 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
173 return BoxPtr(new PrimitivesAPI_Box(aFeature, theDx, theDy, theDz));
176 //==================================================================================================
177 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
178 const ModelHighAPI_Selection& theFirstPoint,
179 const ModelHighAPI_Selection& theSecondPoint)
181 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
182 return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint));
185 //==================================================================================================
186 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
187 const ModelHighAPI_Double& theOx,
188 const ModelHighAPI_Double& theOy,
189 const ModelHighAPI_Double& theOz,
190 const ModelHighAPI_Double& theHalfLengthX,
191 const ModelHighAPI_Double& theHalfLengthY,
192 const ModelHighAPI_Double& theHalfLengthZ)
194 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
195 return BoxPtr(new PrimitivesAPI_Box(aFeature, theOx, theOy, theOz, theHalfLengthX,
196 theHalfLengthY, theHalfLengthZ));