Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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   AttributeRefAttrPtr aMirrorLine = mirrorLine();
74   AttributeRefListPtr aMirrorObjects = mirrorList();
75   theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
76             << aMirrorObjects << ")" << std::endl;
77
78   // Dump variables for a list of mirrored features
79   theDumper << "[";
80   std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = mirrored();
81   std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
82   for (; anIt != aList.end(); ++anIt) {
83     if (anIt != aList.begin())
84       theDumper << ", ";
85     theDumper << (*anIt)->feature();
86   }
87   theDumper << "] = " << theDumper.name(aBase) << ".mirrored()" << std::endl;
88
89   // Set necessary "auxiliary" flag for mirrored features
90   // (flag is set if it differs to base entity)
91   std::list<ObjectPtr> aMirList = aMirrorObjects->list();
92   std::list<ObjectPtr>::const_iterator aMIt = aMirList.begin();
93   for (anIt = aList.begin(); aMIt != aMirList.end(); ++aMIt, ++anIt) {
94     FeaturePtr aFeature = ModelAPI_Feature::feature(*aMIt);
95     if (!aFeature)
96       continue;
97     bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
98
99     aFeature = (*anIt)->feature();
100     bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
101     if (aFeatAux != aBaseAux)
102       theDumper << theDumper.name((*anIt)->feature(), false)
103                 << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;
104   }
105 }