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());
85 theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
86 } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) {
87 AttributeSelectionPtr anAttrFirstPnt =
88 aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID());
89 AttributeSelectionPtr anAttrSecondPnt =
90 aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID());
92 theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt;
95 theDumper << ")" << std::endl;
98 //==================================================================================================
99 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
100 const ModelHighAPI_Double& theDx,
101 const ModelHighAPI_Double& theDy,
102 const ModelHighAPI_Double& theDz)
104 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
105 return BoxPtr(new PrimitivesAPI_Box(aFeature, theDx, theDy, theDz));
108 //==================================================================================================
109 BoxPtr addBox(const std::shared_ptr<ModelAPI_Document>& thePart,
110 const ModelHighAPI_Selection& theFirstPoint,
111 const ModelHighAPI_Selection& theSecondPoint)
113 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Box::ID());
114 return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint));