Salome HOME
Dump names of features copied in Multi-Translation, Multi-Rotation and Mirror macro...
[modules/shaper.git] / src / SketchAPI / SketchAPI_Rotation.cpp
1 // Name   : SketchAPI_Rotation.cpp
2 // Purpose: 
3 //
4 // History:
5 // 16/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Rotation.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_Rotation::SketchAPI_Rotation(
17     const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : ModelHighAPI_Interface(theFeature)
19 {
20   initialize();
21 }
22
23 SketchAPI_Rotation::SketchAPI_Rotation(
24     const std::shared_ptr<ModelAPI_Feature> & theFeature,
25     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects,
26     const ModelHighAPI_RefAttr & theCenter,
27     const ModelHighAPI_Double & theAngle,
28     const ModelHighAPI_Integer & theNumberOfObjects,
29     bool theFullValue)
30 : ModelHighAPI_Interface(theFeature)
31 {
32   if (initialize()) {
33     fillAttribute(theObjects, rotationList());
34     fillAttribute(theCenter, center());
35     fillAttribute(theAngle, angle());
36     fillAttribute(theNumberOfObjects, numberOfObjects());
37     fillAttribute(theFullValue ? "FullAngle" : "SingleAngle", valueType());
38
39     execute(true);
40   }
41 }
42
43 SketchAPI_Rotation::~SketchAPI_Rotation()
44 {
45
46 }
47
48 std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Rotation::rotated() const
49 {
50   std::list<ObjectPtr> aList = rotatedObjects()->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_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
66 {
67   FeaturePtr aBase = feature();
68   const std::string& aSketchName = theDumper.parentName(aBase);
69
70   AttributeRefListPtr aRotObjects = rotationList();
71   AttributeRefAttrPtr aCenter = center();
72   AttributeDoublePtr anAngle = angle();
73   AttributeIntegerPtr aNbCopies = numberOfObjects();
74   bool isFullValue = valueType()->value() != "SingleAngle";
75
76   theDumper << aBase << " = " << aSketchName << ".addRotation("
77             << aRotObjects << ", " << aCenter << ", " << anAngle << ", " << aNbCopies;
78   if (isFullValue)
79     theDumper << ", " << isFullValue;
80   theDumper << ")" << std::endl;
81
82   // Dump variables for a list of rotated features
83   theDumper << "[";
84   std::list<std::shared_ptr<ModelHighAPI_Interface> > aList = rotated();
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) << ".rotated()" << std::endl;
92 }