]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Translation.cpp
Salome HOME
Dump names of features copied in Multi-Translation, Multi-Rotation and Mirror macro...
[modules/shaper.git] / src / SketchAPI / SketchAPI_Translation.cpp
1 // Name   : SketchAPI_Translation.cpp
2 // Purpose: 
3 //
4 // History:
5 // 16/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Translation.h"
9 #include <SketchAPI_SketchEntity.h>
10 //--------------------------------------------------------------------------------------
11 #include <ModelHighAPI_Dumper.h>
12 #include <ModelHighAPI_Tools.h>
13
14 #include <SketchPlugin_SketchEntity.h>
15 //--------------------------------------------------------------------------------------
16 SketchAPI_Translation::SketchAPI_Translation(
17     const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : ModelHighAPI_Interface(theFeature)
19 {
20   initialize();
21 }
22
23 SketchAPI_Translation::SketchAPI_Translation(
24     const std::shared_ptr<ModelAPI_Feature> & theFeature,
25     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
26     const ModelHighAPI_RefAttr & thePoint1,
27     const ModelHighAPI_RefAttr & thePoint2,
28     const ModelHighAPI_Integer & theNumberOfObjects,
29     bool theFullValue)
30 : ModelHighAPI_Interface(theFeature)
31 {
32   if (initialize()) {
33     fillAttribute(theObjects, translationList());
34     fillAttribute(thePoint1, startPoint());
35     fillAttribute(thePoint2, endPoint());
36     fillAttribute(theNumberOfObjects, numberOfObjects());
37     fillAttribute(theFullValue ? "FullValue" : "SingleValue", valueType());
38
39     execute(true);
40   }
41 }
42
43 SketchAPI_Translation::~SketchAPI_Translation()
44 {
45
46 }
47
48 std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Translation::translated() const
49 {
50   std::list<ObjectPtr> aList = translatedObjects()->list();
51   // remove all initial features
52   std::list<FeaturePtr> anIntermediate;
53   std::list<ObjectPtr>::const_iterator anIt = aList.begin();
54   for (; anIt != aList.end(); ++anIt) {
55     FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
56     AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
57     if (isCopy.get() && isCopy->value())
58       anIntermediate.push_back(aFeature);
59   }
60   return SketchAPI_SketchEntity::wrap(anIntermediate);
61 }
62
63 //--------------------------------------------------------------------------------------
64
65 void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
66 {
67   FeaturePtr aBase = feature();
68   const std::string& aSketchName = theDumper.parentName(aBase);
69
70   AttributeRefListPtr aTransObjects = translationList();
71   AttributeRefAttrPtr aStart = startPoint();
72   AttributeRefAttrPtr aEnd   = endPoint();
73   AttributeIntegerPtr aNbCopies = numberOfObjects();
74   bool isFullValue = valueType()->value() != "SingleValue";
75
76   theDumper << aBase << " = " << aSketchName << ".addTranslation("
77             << aTransObjects << ", " << aStart << ", " << aEnd << ", " << aNbCopies;
78   if (isFullValue)
79     theDumper << ", " << isFullValue;
80   theDumper << ")" << std::endl;
81
82   // Dump variables for a list of translated features
83   theDumper << "[";
84   std::list<std::shared_ptr<ModelHighAPI_Interface> > aList = translated();
85   std::list<std::shared_ptr<ModelHighAPI_Interface> >::const_iterator anIt = aList.begin();
86   for (; anIt != aList.end(); ++anIt) {
87     if (anIt != aList.begin())
88       theDumper << ", ";
89     theDumper << theDumper.name((*anIt)->feature(), false);
90   }
91   theDumper << "] = " << theDumper.name(aBase) << ".translated()" << std::endl;
92 }