1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
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)
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)
42 fillAttribute(theMirrorLine, mirrorLine());
43 fillAttribute(theObjects, mirrorList());
49 SketchAPI_Mirror::~SketchAPI_Mirror()
54 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Mirror::mirrored() const
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);
63 return SketchAPI_SketchEntity::wrap(anIntermediate);
66 //--------------------------------------------------------------------------------------
68 void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const
70 FeaturePtr aBase = feature();
71 const std::string& aSketchName = theDumper.parentName(aBase);
73 AttributeRefAttrPtr aMirrorLine = mirrorLine();
74 AttributeRefListPtr aMirrorObjects = mirrorList();
75 theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
76 << aMirrorObjects << ")" << std::endl;
78 // Dump variables for a list of mirrored features
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())
85 theDumper << (*anIt)->feature();
87 theDumper << "] = " << theDumper.name(aBase) << ".mirrored()" << std::endl;
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);
97 bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
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;