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