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);
74 AttributeRefAttrPtr aMirrorLine = mirrorLine();
75 AttributeRefListPtr aMirrorObjects = mirrorList();
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);
83 theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
84 << aMirrorObjects << ")" << std::endl;
86 // Dump variables for a list of mirrored features
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())
93 theDumper << (*anIt)->feature();
95 theDumper << "] = " << theDumper.name(aBase) << ".mirrored()" << std::endl;
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);
105 bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
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;