1 // Copyright (C) 2014-2020 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 "FeaturesAPI_Placement.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 FeaturesAPI_Placement::FeaturesAPI_Placement(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
32 //==================================================================================================
33 FeaturesAPI_Placement::FeaturesAPI_Placement(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34 const std::list<ModelHighAPI_Selection>& theObjects,
35 const ModelHighAPI_Selection& theStartShape,
36 const ModelHighAPI_Selection& theEndShape,
37 const bool theReverseDirection,
38 const bool theCentering)
39 : ModelHighAPI_Interface(theFeature)
42 fillAttribute(theObjects, myobjects);
43 fillAttribute(theStartShape, mystartShape);
44 fillAttribute(theEndShape, myendShape);
45 fillAttribute(theReverseDirection, myreverseDirection);
46 setCentering(theCentering);
50 //==================================================================================================
51 FeaturesAPI_Placement::~FeaturesAPI_Placement()
56 //==================================================================================================
57 void FeaturesAPI_Placement::setObjects(const std::list<ModelHighAPI_Selection>& theObjects)
59 fillAttribute(theObjects, myobjects);
64 //==================================================================================================
65 void FeaturesAPI_Placement::setStartShape(const ModelHighAPI_Selection& theStartShape)
67 fillAttribute(theStartShape, mystartShape);
72 //==================================================================================================
73 void FeaturesAPI_Placement::setEndShape(const ModelHighAPI_Selection& theEndShape)
75 fillAttribute(theEndShape, myendShape);
80 //==================================================================================================
81 void FeaturesAPI_Placement::setReverseDirection(const bool theReverseDirection)
83 fillAttribute(theReverseDirection, myreverseDirection);
88 //==================================================================================================
89 void FeaturesAPI_Placement::setCentering(const bool theCentering)
91 fillAttribute(theCentering, mycentering);
96 //==================================================================================================
97 void FeaturesAPI_Placement::dump(ModelHighAPI_Dumper& theDumper) const
99 FeaturePtr aBase = feature();
100 const std::string& aDocName = theDumper.name(aBase->document());
102 AttributeSelectionListPtr anAttrObjects =
103 aBase->selectionList(FeaturesPlugin_Placement::OBJECTS_LIST_ID());
104 AttributeSelectionPtr anAttrStartShape =
105 aBase->selection(FeaturesPlugin_Placement::START_SHAPE_ID());
106 AttributeSelectionPtr anAttrEndShape = aBase->selection(FeaturesPlugin_Placement::END_SHAPE_ID());
107 AttributeBooleanPtr anAttrReverse = aBase->boolean(FeaturesPlugin_Placement::REVERSE_ID());
108 AttributeBooleanPtr anAttrCentering = aBase->boolean(FeaturesPlugin_Placement::CENTERING_ID());
110 theDumper << aBase << " = model.addPlacement(" << aDocName << ", "
111 << anAttrObjects << ", " << anAttrStartShape << ", " << anAttrEndShape;
113 if (anAttrReverse->value())
114 theDumper << ", reverse = " << anAttrReverse;
115 if (anAttrCentering->value())
116 theDumper << ", centering = " << anAttrCentering;
117 if (!aBase->data()->version().empty())
118 theDumper << ", keepSubResults = True";
120 theDumper << ")" << std::endl;
123 //==================================================================================================
124 PlacementPtr addPlacement(const std::shared_ptr<ModelAPI_Document>& thePart,
125 const std::list<ModelHighAPI_Selection>& theObjects,
126 const ModelHighAPI_Selection& theStartShape,
127 const ModelHighAPI_Selection& theEndShape,
128 const bool theReverseDirection,
129 const bool theCentering,
130 const bool keepSubResults)
132 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Placement::ID());
134 aFeature->data()->setVersion("");
135 return PlacementPtr(new FeaturesAPI_Placement(aFeature,