]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Translation.cpp
Salome HOME
Revert change for MacroArc attribute names
[modules/shaper.git] / src / SketchAPI / SketchAPI_Translation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : SketchAPI_Translation.cpp
3 // Purpose:
4 //
5 // History:
6 // 16/06/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Translation.h"
10 #include <SketchAPI_SketchEntity.h>
11 //--------------------------------------------------------------------------------------
12 #include <ModelHighAPI_Dumper.h>
13 #include <ModelHighAPI_Tools.h>
14
15 #include <SketchPlugin_SketchEntity.h>
16 //--------------------------------------------------------------------------------------
17 SketchAPI_Translation::SketchAPI_Translation(
18     const std::shared_ptr<ModelAPI_Feature> & theFeature)
19 : ModelHighAPI_Interface(theFeature)
20 {
21   initialize();
22 }
23
24 SketchAPI_Translation::SketchAPI_Translation(
25     const std::shared_ptr<ModelAPI_Feature> & theFeature,
26     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
27     const ModelHighAPI_RefAttr & thePoint1,
28     const ModelHighAPI_RefAttr & thePoint2,
29     const ModelHighAPI_Integer & theNumberOfObjects,
30     bool theFullValue)
31 : ModelHighAPI_Interface(theFeature)
32 {
33   if (initialize()) {
34     fillAttribute(theObjects, translationList());
35     fillAttribute(thePoint1, startPoint());
36     fillAttribute(thePoint2, endPoint());
37     fillAttribute(theNumberOfObjects, numberOfObjects());
38     fillAttribute(theFullValue ? "FullValue" : "SingleValue", valueType());
39
40     execute(true);
41   }
42 }
43
44 SketchAPI_Translation::~SketchAPI_Translation()
45 {
46
47 }
48
49 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Translation::translated() const
50 {
51   std::list<ObjectPtr> aList = translatedObjects()->list();
52   // remove all initial features
53   std::list<FeaturePtr> anIntermediate;
54   std::list<ObjectPtr>::const_iterator anIt = aList.begin();
55   for (; anIt != aList.end(); ++anIt) {
56     FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
57     AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
58     if (isCopy.get() && isCopy->value())
59       anIntermediate.push_back(aFeature);
60   }
61   return SketchAPI_SketchEntity::wrap(anIntermediate);
62 }
63
64 //--------------------------------------------------------------------------------------
65
66 void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
67 {
68   FeaturePtr aBase = feature();
69   const std::string& aSketchName = theDumper.parentName(aBase);
70
71   AttributeRefListPtr aTransObjects = translationList();
72   AttributeRefAttrPtr aStart = startPoint();
73   AttributeRefAttrPtr aEnd   = endPoint();
74   AttributeIntegerPtr aNbCopies = numberOfObjects();
75   bool isFullValue = valueType()->value() != "SingleValue";
76
77   theDumper << aBase << " = " << aSketchName << ".addTranslation("
78             << aTransObjects << ", " << aStart << ", " << aEnd << ", " << aNbCopies;
79   if (isFullValue)
80     theDumper << ", " << isFullValue;
81   theDumper << ")" << std::endl;
82
83   // Dump variables for a list of translated features
84   theDumper << "[";
85   std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = translated();
86   std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
87   for (; anIt != aList.end(); ++anIt) {
88     if (anIt != aList.begin())
89       theDumper << ", ";
90     theDumper << (*anIt)->feature();
91   }
92   theDumper << "] = " << theDumper.name(aBase) << ".translated()" << std::endl;
93
94   // Set necessary "auxiliary" flag for translated features
95   // (flag is set if it differs to base entity)
96   std::list<ObjectPtr> aTransList = aTransObjects->list();
97   std::list<ObjectPtr>::const_iterator aTrIt = aTransList.begin();
98   anIt = aList.begin();
99   for (; aTrIt != aTransList.end(); ++aTrIt) {
100     FeaturePtr aFeature = ModelAPI_Feature::feature(*aTrIt);
101     if (!aFeature)
102       continue;
103     bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
104
105     for (int i = 1; i < aNbCopies->value(); ++i, ++anIt) {
106       aFeature = (*anIt)->feature();
107       bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
108       if (aFeatAux != aBaseAux)
109         theDumper << theDumper.name((*anIt)->feature(), false)
110                   << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;
111     }
112   }
113 }