1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
3 // File: PrimitivesAPI_Box.cpp
4 // Created: 28 June 2016
5 // Author: Clarisse Genrault
7 #include "PrimitivesAPI_Box.h"
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
12 //==================================================================================================
13 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
19 //==================================================================================================
20 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
21 const ModelHighAPI_Double & theDx,
22 const ModelHighAPI_Double & theDy,
23 const ModelHighAPI_Double & theDz)
24 : ModelHighAPI_Interface(theFeature)
27 setDimensions(theDx, theDy, theDz);
30 //==================================================================================================
31 PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr<ModelAPI_Feature>& theFeature,
32 const ModelHighAPI_Selection& theFirstPoint,
33 const ModelHighAPI_Selection& theSecondPoint)
34 : ModelHighAPI_Interface(theFeature)
37 setPoints(theFirstPoint, theSecondPoint);
40 //==================================================================================================
41 PrimitivesAPI_Box::~PrimitivesAPI_Box()
46 //==================================================================================================
47 void PrimitivesAPI_Box::setDimensions(const ModelHighAPI_Double& theDx,
48 const ModelHighAPI_Double& theDy,
49 const ModelHighAPI_Double& theDz)
51 fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
52 fillAttribute(theDx, dx());
53 fillAttribute(theDy, dy());
54 fillAttribute(theDz, dz());
59 //==================================================================================================
60 void PrimitivesAPI_Box::setPoints(const ModelHighAPI_Selection& theFirstPoint,
61 const ModelHighAPI_Selection& theSecondPoint)
63 fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS(), creationMethod());
64 fillAttribute(theFirstPoint, firstPoint());
65 fillAttribute(theSecondPoint, secondPoint());
70 //==================================================================================================
71 void PrimitivesAPI_Box::dump(ModelHighAPI_Dumper& theDumper) const
73 FeaturePtr aBase = feature();
74 const std::string& aDocName = theDumper.name(aBase->document());
76 theDumper << aBase << " = model.addBox(" << aDocName;
78 std::string aCreationMethod = aBase->string(PrimitivesPlugin_Box::CREATION_METHOD())->value();
80 if(aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS()) {
81 AttributeDoublePtr anAttrDx = aBase->real(PrimitivesPlugin_Box::DX_ID());
82 AttributeDoublePtr anAttrDy = aBase->real(PrimitivesPlugin_Box::DY_ID());
83 AttributeDoublePtr anAttrDz = aBase->real(PrimitivesPlugin_Box::DZ_ID());
84 theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
85 } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) {
86 AttributeSelectionPtr anAttrFirstPnt =
87 aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
88 AttributeSelectionPtr anAttrSecondPnt =
89 aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
90 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
93 theDumper << ")" << std::endl;
96 //==================================================================================================
97 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
98 const ModelHighAPI_Double& theDx,
99 const ModelHighAPI_Double& theDy,
100 const ModelHighAPI_Double& theDz)
102 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
103 return BoxPtr(new PrimitivesAPI_Box(aFeature, theDx, theDy, theDz));
106 //==================================================================================================
107 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
108 const ModelHighAPI_Selection& theFirstPoint,
109 const ModelHighAPI_Selection& theSecondPoint)
111 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
112 return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint));