Salome HOME
Dump names of features copied in Multi-Translation, Multi-Rotation and Mirror macro...
[modules/shaper.git] / src / SketchAPI / SketchAPI_Mirror.cpp
1 // Name   : SketchAPI_Mirror.cpp
2 // Purpose: 
3 //
4 // History:
5 // 16/06/16 - Sergey POKHODENKO - Creation of the file
6
7 //--------------------------------------------------------------------------------------
8 #include "SketchAPI_Mirror.h"
9 #include <SketchAPI_SketchEntity.h>
10 //--------------------------------------------------------------------------------------
11 #include <ModelHighAPI_Dumper.h>
12 #include <ModelHighAPI_Selection.h>
13 #include <ModelHighAPI_Tools.h>
14 //--------------------------------------------------------------------------------------
15 SketchAPI_Mirror::SketchAPI_Mirror(
16     const std::shared_ptr<ModelAPI_Feature> & theFeature)
17 : ModelHighAPI_Interface(theFeature)
18 {
19   initialize();
20 }
21
22 SketchAPI_Mirror::SketchAPI_Mirror(
23     const std::shared_ptr<ModelAPI_Feature> & theFeature,
24     const ModelHighAPI_RefAttr & theMirrorLine,
25     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
26 : ModelHighAPI_Interface(theFeature)
27 {
28   if (initialize()) {
29     fillAttribute(theMirrorLine, mirrorLine());
30     fillAttribute(theObjects, mirrorList());
31
32     execute();
33   }
34 }
35
36 SketchAPI_Mirror::~SketchAPI_Mirror()
37 {
38
39 }
40
41 std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Mirror::mirrored() const
42 {
43   std::list<ObjectPtr> aList = mirroredObjects()->list();
44   std::list<FeaturePtr> anIntermediate;
45   std::list<ObjectPtr>::const_iterator anIt = aList.begin();
46   for (; anIt != aList.end(); ++anIt) {
47     FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
48     anIntermediate.push_back(aFeature);
49   }
50   return SketchAPI_SketchEntity::wrap(anIntermediate);
51 }
52
53 //--------------------------------------------------------------------------------------
54
55 void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const
56 {
57   FeaturePtr aBase = feature();
58   const std::string& aSketchName = theDumper.parentName(aBase);
59
60   AttributeRefAttrPtr aMirrorLine = mirrorLine();
61   AttributeRefListPtr aMirrorObjects = mirrorList();
62   theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
63             << aMirrorObjects << ")" << std::endl;
64
65   // Dump variables for a list of mirrored features
66   theDumper << "[";
67   std::list<std::shared_ptr<ModelHighAPI_Interface> > aList = mirrored();
68   std::list<std::shared_ptr<ModelHighAPI_Interface> >::const_iterator anIt = aList.begin();
69   for (; anIt != aList.end(); ++anIt) {
70     if (anIt != aList.begin())
71       theDumper << ", ";
72     theDumper << theDumper.name((*anIt)->feature(), false);
73   }
74   theDumper << "] = " << theDumper.name(aBase) << ".mirrored()" << std::endl;
75 }