Salome HOME
Merge remote-tracking branch 'origin/cbr/export_to_geom_via_xao'
[modules/shaper.git] / src / SketchAPI / SketchAPI_Mirror.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "SketchAPI_Mirror.h"
22 #include <SketchAPI_SketchEntity.h>
23 //--------------------------------------------------------------------------------------
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Selection.h>
26 #include <ModelHighAPI_Tools.h>
27 //--------------------------------------------------------------------------------------
28 SketchAPI_Mirror::SketchAPI_Mirror(
29     const std::shared_ptr<ModelAPI_Feature> & theFeature)
30 : ModelHighAPI_Interface(theFeature)
31 {
32   initialize();
33 }
34
35 SketchAPI_Mirror::SketchAPI_Mirror(
36     const std::shared_ptr<ModelAPI_Feature> & theFeature,
37     const ModelHighAPI_RefAttr & theMirrorLine,
38     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
39 : ModelHighAPI_Interface(theFeature)
40 {
41   if (initialize()) {
42     fillAttribute(theMirrorLine, mirrorLine());
43     fillAttribute(theObjects, mirrorList());
44
45     execute();
46   }
47 }
48
49 SketchAPI_Mirror::~SketchAPI_Mirror()
50 {
51
52 }
53
54 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Mirror::mirrored() const
55 {
56   std::list<ObjectPtr> aList = mirroredObjects()->list();
57   std::list<FeaturePtr> anIntermediate;
58   std::list<ObjectPtr>::const_iterator anIt = aList.begin();
59   for (; anIt != aList.end(); ++anIt) {
60     FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
61     anIntermediate.push_back(aFeature);
62   }
63   return SketchAPI_SketchEntity::wrap(anIntermediate);
64 }
65
66 //--------------------------------------------------------------------------------------
67
68 void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const
69 {
70   FeaturePtr aBase = feature();
71   const std::string& aSketchName = theDumper.parentName(aBase);
72
73
74   AttributeRefAttrPtr aMirrorLine = mirrorLine();
75   AttributeRefListPtr aMirrorObjects = mirrorList();
76
77   // Check all attributes are already dumped. If not, store the constraint as postponed.
78   if (!theDumper.isDumped(aMirrorLine) || !theDumper.isDumped(aMirrorObjects)) {
79     theDumper.postpone(aBase);
80     return;
81   }
82
83   theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
84             << aMirrorObjects << ")" << std::endl;
85
86   // Dump variables for a list of mirrored features
87   theDumper << "[";
88   std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = mirrored();
89   std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
90   for (; anIt != aList.end(); ++anIt) {
91     if (anIt != aList.begin())
92       theDumper << ", ";
93     theDumper << (*anIt)->feature();
94   }
95   theDumper << "] = " << theDumper.name(aBase) << ".mirrored()" << std::endl;
96
97   // Set necessary "auxiliary" flag for mirrored features
98   // (flag is set if it differs to base entity)
99   std::list<ObjectPtr> aMirList = aMirrorObjects->list();
100   std::list<ObjectPtr>::const_iterator aMIt = aMirList.begin();
101   for (anIt = aList.begin(); aMIt != aMirList.end(); ++aMIt, ++anIt) {
102     FeaturePtr aFeature = ModelAPI_Feature::feature(*aMIt);
103     if (!aFeature)
104       continue;
105     bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
106
107     aFeature = (*anIt)->feature();
108     bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
109     if (aFeatAux != aBaseAux)
110       theDumper << theDumper.name((*anIt)->feature(), false)
111                 << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;
112   }
113 }