]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Mirror.cpp
Salome HOME
Porting to SALOME_8.2.0 : Debug visualization selection for AIS_Trihedron axes.
[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<SketchAPI_SketchEntity> > 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<SketchAPI_SketchEntity> > aList = mirrored();
69   std::list<std::shared_ptr<SketchAPI_SketchEntity> >::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
77   // Set necessary "auxiliary" flag for mirrored features
78   // (flag is set if it differs to base entity)
79   std::list<ObjectPtr> aMirList = aMirrorObjects->list();
80   std::list<ObjectPtr>::const_iterator aMIt = aMirList.begin();
81   for (anIt = aList.begin(); aMIt != aMirList.end(); ++aMIt, ++anIt) {
82     FeaturePtr aFeature = ModelAPI_Feature::feature(*aMIt);
83     if (!aFeature)
84       continue;
85     bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
86
87     aFeature = (*anIt)->feature();
88     bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
89     if (aFeatAux != aBaseAux)
90       theDumper << theDumper.name((*anIt)->feature(), false)
91                 << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;
92   }
93 }