]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Rotation.cpp
Salome HOME
Porting to SALOME_8.2.0 : Debug visualization selection for AIS_Trihedron axes.
[modules/shaper.git] / src / SketchAPI / SketchAPI_Rotation.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : SketchAPI_Rotation.cpp
3 // Purpose:
4 //
5 // History:
6 // 16/06/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Rotation.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_Rotation::SketchAPI_Rotation(
18     const std::shared_ptr<ModelAPI_Feature> & theFeature)
19 : ModelHighAPI_Interface(theFeature)
20 {
21   initialize();
22 }
23
24 SketchAPI_Rotation::SketchAPI_Rotation(
25     const std::shared_ptr<ModelAPI_Feature> & theFeature,
26     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
27     const ModelHighAPI_RefAttr & theCenter,
28     const ModelHighAPI_Double & theAngle,
29     const ModelHighAPI_Integer & theNumberOfObjects,
30     bool theFullValue)
31 : ModelHighAPI_Interface(theFeature)
32 {
33   if (initialize()) {
34     fillAttribute(theObjects, rotationList());
35     fillAttribute(theCenter, center());
36     fillAttribute(theAngle, angle());
37     fillAttribute(theNumberOfObjects, numberOfObjects());
38     fillAttribute(theFullValue ? "FullAngle" : "SingleAngle", valueType());
39
40     execute(true);
41   }
42 }
43
44 SketchAPI_Rotation::~SketchAPI_Rotation()
45 {
46
47 }
48
49 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rotation::rotated() const
50 {
51   std::list<ObjectPtr> aList = rotatedObjects()->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_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
67 {
68   FeaturePtr aBase = feature();
69   const std::string& aSketchName = theDumper.parentName(aBase);
70
71   AttributeRefListPtr aRotObjects = rotationList();
72   AttributeRefAttrPtr aCenter = center();
73   AttributeDoublePtr anAngle = angle();
74   AttributeIntegerPtr aNbCopies = numberOfObjects();
75   bool isFullValue = valueType()->value() != "SingleAngle";
76
77   theDumper << aBase << " = " << aSketchName << ".addRotation("
78             << aRotObjects << ", " << aCenter << ", " << anAngle << ", " << aNbCopies;
79   if (isFullValue)
80     theDumper << ", " << isFullValue;
81   theDumper << ")" << std::endl;
82
83   // Dump variables for a list of rotated features
84   theDumper << "[";
85   std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = rotated();
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 << theDumper.name((*anIt)->feature(), false);
91   }
92   theDumper << "] = " << theDumper.name(aBase) << ".rotated()" << std::endl;
93
94   // Set necessary "auxiliary" flag for rotated features
95   // (flag is set if it differs to base entity)
96   std::list<ObjectPtr> aRotList = aRotObjects->list();
97   std::list<ObjectPtr>::const_iterator aRIt = aRotList.begin();
98   anIt = aList.begin();
99   for (; aRIt != aRotList.end(); ++aRIt) {
100     FeaturePtr aFeature = ModelAPI_Feature::feature(*aRIt);
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 }