1 // Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
20 #include "SketchAPI_Mirror.h"
21 #include <SketchAPI_SketchEntity.h>
22 //--------------------------------------------------------------------------------------
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Selection.h>
25 #include <ModelHighAPI_Tools.h>
26 //--------------------------------------------------------------------------------------
27 SketchAPI_Mirror::SketchAPI_Mirror(
28 const std::shared_ptr<ModelAPI_Feature> & theFeature)
29 : ModelHighAPI_Interface(theFeature)
34 SketchAPI_Mirror::SketchAPI_Mirror(
35 const std::shared_ptr<ModelAPI_Feature> & theFeature,
36 const ModelHighAPI_RefAttr & theMirrorLine,
37 const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
38 : ModelHighAPI_Interface(theFeature)
41 fillAttribute(theMirrorLine, mirrorLine());
42 setMirrorList(theObjects);
46 SketchAPI_Mirror::~SketchAPI_Mirror()
50 void SketchAPI_Mirror::setMirrorList(const std::list<std::shared_ptr<ModelAPI_Object> >& theObjects)
52 fillAttribute(theObjects, mirrorList());
56 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Mirror::mirrored() const
58 std::list<ObjectPtr> aList = mirroredObjects()->list();
59 std::list<FeaturePtr> anIntermediate;
60 std::list<ObjectPtr>::const_iterator anIt = aList.begin();
61 for (; anIt != aList.end(); ++anIt) {
62 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
63 anIntermediate.push_back(aFeature);
65 return SketchAPI_SketchEntity::wrap(anIntermediate);
68 //--------------------------------------------------------------------------------------
70 void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const
72 FeaturePtr aBase = feature();
73 const std::string& aSketchName = theDumper.parentName(aBase);
75 AttributeRefAttrPtr aMirrorLine = mirrorLine();
76 AttributeRefListPtr aMirrorObjects = mirrorList();
78 // Check all attributes are already dumped. If not, store the constraint as postponed.
79 size_t aFirstNotDumped = theDumper.indexOfFirstNotDumped(aMirrorObjects);
80 if (!theDumper.isDumped(aMirrorLine) || aFirstNotDumped == 0) {
81 theDumper.postpone(aBase);
86 // the number of dumped aMirrorObjects is not changed, no need to dump anything
87 static std::map<FeaturePtr, size_t> aNbDumpedArguments;
88 std::map<FeaturePtr, size_t>::iterator aFound = aNbDumpedArguments.find(aBase);
89 if (aFound != aNbDumpedArguments.end() && aFound->second == aFirstNotDumped) {
90 theDumper.postpone(aBase);
94 aNbDumpedArguments[aBase] = aFirstNotDumped;
96 if (theDumper.isDumped(aBase)) {
97 // the feature is already dumped, but it was postponed, because of some arguments
98 // were not dumped yet, thus, it is necessary to update the list of rotated objects
99 theDumper << "\n### Update " << aBase->getKind() << std::endl;
100 theDumper << aBase << ".setMirrorList(" << aMirrorObjects << ")" << std::endl;
103 // the feature is not dumped yet, make the full dump
104 theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
105 << aMirrorObjects << ")" << std::endl;
108 // Dump variables for a list of mirrored features
110 std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = mirrored();
111 std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
112 for (size_t anIndex = 0; anIndex < aFirstNotDumped; ++anIndex, ++anIt) {
113 if (anIt != aList.begin())
115 theDumper << (*anIt)->feature();
117 theDumper << "] = " << theDumper.name(aBase) << ".mirrored()" << std::endl;
119 if (theDumper.isDumped(aMirrorObjects)) {
120 aNbDumpedArguments.erase(aBase);
121 // Set necessary "auxiliary" flag for mirrored features
122 // (flag is set if it differs to base entity)
123 std::list<ObjectPtr> aMirList = aMirrorObjects->list();
124 std::list<ObjectPtr>::const_iterator aMIt = aMirList.begin();
125 for (anIt = aList.begin(); aMIt != aMirList.end(); ++aMIt, ++anIt) {
126 FeaturePtr aFeature = ModelAPI_Feature::feature(*aMIt);
129 bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
131 aFeature = (*anIt)->feature();
132 bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
133 if (aFeatAux != aBaseAux)
134 theDumper << theDumper.name((*anIt)->feature(), false)
135 << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;
139 // If all refereced objects are not dumped yet, mark the feature as postponed.
140 theDumper.postpone(aBase);