Salome HOME
Fix for selection by name with suffix
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Translation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Translation.cpp
4 // Created:     07 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesAPI_Translation.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 FeaturesAPI_Translation::FeaturesAPI_Translation(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
15 {
16   initialize();
17 }
18
19 //==================================================================================================
20 FeaturesAPI_Translation::FeaturesAPI_Translation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
21                                                  const std::list<ModelHighAPI_Selection>& theMainObjects,
22                                                  const ModelHighAPI_Selection& theAxisObject,
23                                                  const ModelHighAPI_Double& theDistance)
24 : ModelHighAPI_Interface(theFeature)
25 {
26   if(initialize()) {
27     fillAttribute(theMainObjects, mymainObjects);
28     fillAttribute(theAxisObject, myaxisObject);
29     setDistance(theDistance);
30   }
31 }
32
33 //==================================================================================================
34 FeaturesAPI_Translation::~FeaturesAPI_Translation()
35 {
36
37 }
38
39 //==================================================================================================
40 void FeaturesAPI_Translation::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
41 {
42   fillAttribute(theMainObjects, mymainObjects);
43
44   execute();
45 }
46
47 //==================================================================================================
48 void FeaturesAPI_Translation::setAxisObject(const ModelHighAPI_Selection& theAxisObject)
49 {
50   fillAttribute(theAxisObject, myaxisObject);
51
52   execute();
53 }
54
55 //==================================================================================================
56 void FeaturesAPI_Translation::setDistance(const ModelHighAPI_Double& theDistance)
57 {
58   fillAttribute(theDistance, mydistance);
59
60   execute();
61 }
62
63 //==================================================================================================
64 void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
65 {
66   FeaturePtr aBase = feature();
67   const std::string& aDocName = theDumper.name(aBase->document());
68
69   AttributeSelectionListPtr anAttrObjects = aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
70   AttributeSelectionPtr anAttrAxis = aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
71   AttributeDoublePtr anAttrDistance = aBase->real(FeaturesPlugin_Translation::DISTANCE_ID());
72
73   theDumper << aBase << " = model.addTranslation(" << aDocName << ", "
74             << anAttrObjects << ", " << anAttrAxis << ", " << anAttrDistance << ")" << std::endl;
75 }
76
77 //==================================================================================================
78 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
79                               const std::list<ModelHighAPI_Selection>& theMainObjects,
80                               const ModelHighAPI_Selection& theAxisObject,
81                               const ModelHighAPI_Double& theDistance)
82 {
83   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
84   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theAxisObject, theDistance));
85 }