1 // Copyright (C) 2014-2019 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 "ModelHighAPI_Dumper.h"
22 #include <Config_PropManager.h>
24 #include <GeomAPI_Pnt.h>
25 #include <GeomAPI_Dir.h>
26 #include <GeomAPI_ShapeExplorer.h>
27 #include <GeomAPI_ShapeIterator.h>
28 #include <GeomAlgoAPI_NExplode.h>
30 #include <GeomDataAPI_Dir.h>
31 #include <GeomDataAPI_Point.h>
32 #include <GeomDataAPI_Point2D.h>
34 #include <ModelAPI_AttributeBoolean.h>
35 #include <ModelAPI_AttributeDouble.h>
36 #include <ModelAPI_AttributeIntArray.h>
37 #include <ModelAPI_AttributeInteger.h>
38 #include <ModelAPI_AttributeRefAttr.h>
39 #include <ModelAPI_AttributeRefAttrList.h>
40 #include <ModelAPI_AttributeReference.h>
41 #include <ModelAPI_AttributeRefList.h>
42 #include <ModelAPI_AttributeSelection.h>
43 #include <ModelAPI_AttributeSelectionList.h>
44 #include <ModelAPI_AttributeString.h>
45 #include <ModelAPI_AttributeStringArray.h>
46 #include <ModelAPI_CompositeFeature.h>
47 #include <ModelAPI_Document.h>
48 #include <ModelAPI_Entity.h>
49 #include <ModelAPI_Feature.h>
50 #include <ModelAPI_Folder.h>
51 #include <ModelAPI_Result.h>
52 #include <ModelAPI_ResultBody.h>
53 #include <ModelAPI_ResultConstruction.h>
54 #include <ModelAPI_ResultPart.h>
55 #include <ModelAPI_Session.h>
56 #include <ModelAPI_Tools.h>
58 #include <ModelGeomAlgo_Shape.h>
60 #include <PartSetPlugin_Part.h>
62 #include <OSD_OpenFile.hxx>
66 // =========== Implementation of storage of dumped data ===========
67 static const int THE_DUMP_PRECISION = 16;
69 class ModelHighAPI_Dumper::DumpStorageBuffer : public ModelHighAPI_Dumper::DumpStorage
72 void addStorage(const ModelHighAPI_Dumper::DumpStoragePtr& theStorage)
73 { myStorageArray.push_back(theStorage); }
75 void clear() { myStorageArray.clear(); }
79 return myStorageArray.empty() || myStorageArray.front()->buffer().str().empty();
84 std::list<ModelHighAPI_Dumper::DumpStoragePtr>::iterator anIt = myStorageArray.begin();
85 for (; anIt != myStorageArray.end(); ++anIt) {
86 // avoid multiple empty lines
87 std::string aBuf = (*anIt)->buffer().str();
88 size_t anInd = std::string::npos;
89 while ((anInd = aBuf.find("\n\n\n")) != std::string::npos)
92 (*anIt)->fullDump() << aBuf;
93 (*anIt)->buffer().str("");
97 void write(const std::string& theValue)
99 if (myStorageArray.empty())
100 addStorage(DumpStoragePtr(new DumpStorage));
102 std::list<ModelHighAPI_Dumper::DumpStoragePtr>::iterator anIt = myStorageArray.begin();
103 for (; anIt != myStorageArray.end(); ++anIt)
104 (*anIt)->buffer() << theValue;
107 DumpStorageBuffer& operator<<(const char theChar)
109 std::ostringstream out;
115 DumpStorageBuffer& operator<<(const char* theString)
121 DumpStorageBuffer& operator<<(const std::string& theString)
127 DumpStorageBuffer& operator<<(const bool theValue)
129 std::ostringstream out;
135 DumpStorageBuffer& operator<<(const int theValue)
137 std::ostringstream out;
143 DumpStorageBuffer& operator<<(const double theValue)
145 std::ostringstream out;
146 out << std::setprecision(THE_DUMP_PRECISION) << theValue;
152 DumpStorageBuffer& operator<<(DumpStorageBuffer& theBuffer,
153 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&))
155 theBuffer.write("\n");
159 void dumpArray(int theSize, double* theValues, std::string* theTexts)
161 std::ostringstream anOutput;
162 anOutput << std::setprecision(THE_DUMP_PRECISION);
163 for (int i = 0; i < theSize; ++i) {
166 if (theTexts[i].empty())
167 anOutput << theValues[i];
169 anOutput << "\"" << theTexts[i] << "\"";
171 write(anOutput.str());
174 virtual void write(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect)
176 if (myStorageArray.empty())
177 addStorage(DumpStoragePtr(new DumpStorage));
179 std::list<ModelHighAPI_Dumper::DumpStoragePtr>::iterator anIt = myStorageArray.begin();
180 for (; anIt != myStorageArray.end(); ++anIt)
181 (*anIt)->write(theAttrSelect);
184 virtual void reserveBuffer()
186 std::list<ModelHighAPI_Dumper::DumpStoragePtr>::iterator anIt = myStorageArray.begin();
187 for (; anIt != myStorageArray.end(); ++anIt)
188 (*anIt)->reserveBuffer();
191 virtual void restoreReservedBuffer()
193 std::list<ModelHighAPI_Dumper::DumpStoragePtr>::iterator anIt = myStorageArray.begin();
194 for (; anIt != myStorageArray.end(); ++anIt)
195 (*anIt)->restoreReservedBuffer();
198 virtual bool exportTo(const std::string& theFilename, const ModulesSet& theUsedModules)
200 static const std::string THE_EXT = ".py";
201 std::string aFilenameBase = theFilename;
202 if (aFilenameBase.rfind(THE_EXT) == aFilenameBase.size() - THE_EXT.size())
203 aFilenameBase = aFilenameBase.substr(0, aFilenameBase.size() - THE_EXT.size());
206 std::list<ModelHighAPI_Dumper::DumpStoragePtr>::iterator anIt = myStorageArray.begin();
207 for (; anIt != myStorageArray.end(); ++anIt) {
208 std::string aFilename = aFilenameBase + (*anIt)->myFilenameSuffix + THE_EXT;
209 isOk = (*anIt)->exportTo(aFilename, theUsedModules) && isOk;
215 std::list<ModelHighAPI_Dumper::DumpStoragePtr> myStorageArray;
219 ModelHighAPI_Dumper::DumpStorage::DumpStorage(const DumpStorage& theOther)
220 : myFilenameSuffix(theOther.myFilenameSuffix),
221 myDumpBufferHideout(theOther.myDumpBufferHideout)
223 myFullDump.str(theOther.myFullDump.str());
224 myDumpBuffer.str(theOther.myDumpBuffer.str());
227 const ModelHighAPI_Dumper::DumpStorage&
228 ModelHighAPI_Dumper::DumpStorage::operator=(const ModelHighAPI_Dumper::DumpStorage& theOther)
230 myFilenameSuffix = theOther.myFilenameSuffix;
231 myFullDump.str(theOther.myFullDump.str());
232 myDumpBuffer.str(theOther.myDumpBuffer.str());
233 myDumpBufferHideout = theOther.myDumpBufferHideout;
237 void ModelHighAPI_Dumper::DumpStorage::reserveBuffer()
239 myDumpBufferHideout.push(myDumpBuffer.str());
240 myDumpBuffer.str("");
243 void ModelHighAPI_Dumper::DumpStorage::restoreReservedBuffer()
245 myDumpBuffer << myDumpBufferHideout.top();
246 myDumpBufferHideout.pop();
249 bool ModelHighAPI_Dumper::DumpStorage::exportTo(const std::string& theFilename,
250 const ModulesSet& theUsedModules)
253 OSD_OpenStream(aFile, theFilename.c_str(), std::ofstream::out);
254 if (!aFile.is_open())
257 // standard header (encoding + imported modules)
258 aFile << "# -*- coding: utf-8 -*-" << std::endl << std::endl;
259 for (ModulesSet::const_iterator aModIt = theUsedModules.begin();
260 aModIt != theUsedModules.end(); ++aModIt) {
261 aFile << "from " << *aModIt << " import *" << std::endl;
263 if (!theUsedModules.empty())
266 aFile << "from salome.shaper import model" << std::endl << std::endl;
267 aFile << "model.begin()" << std::endl;
269 // dump collected data
270 aFile << myFullDump.str();
271 aFile << myDumpBuffer.str();
274 aFile << "model.end()" << std::endl;
280 static void getShapeAndContext(const AttributeSelectionPtr& theAttrSelect,
281 GeomShapePtr& theShape, ResultPtr& theContext)
283 if (theAttrSelect->isInitialized()) {
284 theShape = theAttrSelect->value();
285 theContext = theAttrSelect->context();
287 theShape = theContext->shape();
289 if (theAttrSelect->isGeometricalSelection() &&
290 theShape.get() && theShape->shapeType() == GeomAPI_Shape::COMPOUND &&
291 theContext.get() && !theShape->isEqual(theContext->shape()) &&
292 theContext->groupName() != ModelAPI_ResultPart::group()) {
293 GeomAPI_ShapeIterator anIt(theShape);
294 theShape = anIt.current();
299 void ModelHighAPI_Dumper::DumpStorage::write(const AttributeSelectionPtr& theAttrSelect)
301 myDumpBuffer << "model.selection(";
305 getShapeAndContext(theAttrSelect, aShape, aContext);
308 myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", \""
309 << theAttrSelect->namingName() << "\"";
315 static int possibleSelectionsByPoint(const GeomPointPtr& thePoint,
316 const ResultPtr& theResult,
317 const GeomShapePtr& theShape,
318 const FeaturePtr& theStartFeature,
319 const FeaturePtr& theEndFeature)
321 DocumentPtr aDoc1 = theStartFeature->document();
322 DocumentPtr aDoc2 = theEndFeature->document();
324 std::list<FeaturePtr> aFeatures = aDoc1->allFeatures();
325 if (aDoc1 != aDoc2) {
326 std::list<FeaturePtr> anAdditionalFeatures = aDoc2->allFeatures();
327 aFeatures.insert(aFeatures.end(), anAdditionalFeatures.begin(), anAdditionalFeatures.end());
330 CompositeFeaturePtr aLastCompositeFeature;
332 std::list<FeaturePtr>::const_iterator aFIt = aFeatures.begin();
333 while (aFIt != aFeatures.end() && *aFIt != theStartFeature) {
334 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFIt);
336 aLastCompositeFeature = aCompFeat;
340 // collect the list of composite features, containing the last feature;
341 // these features should be excluded from searching,
342 // because the feature cannot select sub-shapes from its parent
343 std::set<FeaturePtr> aEndFeatureParents = ModelAPI_Tools::getParents(theEndFeature);
345 int aNbPossibleSelections = 0;
346 for (; aFIt != aFeatures.end() && *aFIt != theEndFeature; ++aFIt) {
347 bool isSkipFeature = false;
348 if (aLastCompositeFeature && aLastCompositeFeature->isSub(*aFIt))
349 isSkipFeature = true;
350 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFIt);
352 ResultPartPtr aPartRes =
353 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aCompFeat->firstResult());
355 aLastCompositeFeature = aCompFeat;
356 if (aEndFeatureParents.find(aCompFeat) != aEndFeatureParents.end()) {
357 // do not process the parent for the last feature,
358 // because it cannot select objects from its parent
359 isSkipFeature = true;
365 std::list<ModelGeomAlgo_Shape::SubshapeOfResult> anApproproate;
366 if (ModelGeomAlgo_Shape::findSubshapeByPoint(*aFIt, thePoint, theShape->shapeType(),
368 std::list<ModelGeomAlgo_Shape::SubshapeOfResult>::iterator anApIt = anApproproate.begin();
369 for (; anApIt != anApproproate.end(); ++anApIt) {
370 ++aNbPossibleSelections;
372 // stop if the target shape and result are found
373 GeomShapePtr aCurShape = anApIt->mySubshape;
375 aCurShape = anApIt->myResult->shape();
377 if (anApIt->myResult->isSame(theResult) && aCurShape->isSame(theShape))
382 return aNbPossibleSelections;
385 void ModelHighAPI_Dumper::DumpStorageGeom::write(const AttributeSelectionPtr& theAttrSelect)
389 getShapeAndContext(theAttrSelect, aShape, aContext);
391 // how to dump selection: construction features are dumped by name always
392 FeaturePtr aSelectedFeature;
393 FeaturePtr aFeature = theAttrSelect->contextFeature();
394 if (aShape && aContext && !aFeature)
395 aSelectedFeature = ModelAPI_Feature::feature(aContext->data()->owner());
396 bool isDumpByGeom = aSelectedFeature && aSelectedFeature->isInHistory();
399 myDumpBuffer << "model.selection(\"" << aShape->shapeTypeStr();
400 // check the selected item is a ResultPart;
401 // in this case it is necessary to get shape with full transformation
402 // for correct calculation of the middle point
403 ResultPartPtr aResPart =
404 std::dynamic_pointer_cast<ModelAPI_ResultPart>(theAttrSelect->context());
405 if (aResPart && aShape->shapeType() == GeomAPI_Shape::COMPOUND)
406 aShape = aResPart->shape();
407 GeomPointPtr aMiddlePoint = aShape->middlePoint();
408 // calculate number of features, which could be selected by the same point
409 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttrSelect->owner());
410 int aNbPossibleSelections = possibleSelectionsByPoint(aMiddlePoint,
411 theAttrSelect->context(), aShape, aSelectedFeature, anOwner);
413 // produce the index if the number of applicable features is greater than 1
415 if (aNbPossibleSelections > 1) {
416 std::ostringstream anOutput;
417 anOutput << "_" << aNbPossibleSelections;
418 anIndex = anOutput.str();
421 myDumpBuffer << std::setprecision(THE_DUMP_PRECISION)
422 << anIndex << "\", ("
423 << aMiddlePoint->x() << ", "
424 << aMiddlePoint->y() << ", "
425 << aMiddlePoint->z() << ")";
429 DumpStorage::write(theAttrSelect);
432 void ModelHighAPI_Dumper::DumpStorageWeak::write(const AttributeSelectionPtr& theAttrSelect)
436 getShapeAndContext(theAttrSelect, aShape, aContext);
438 bool aStandardDump = true;
439 if (aShape.get() && aContext.get() &&
440 aShape != aContext->shape()) { // weak naming for local selection only
441 GeomAlgoAPI_NExplode aNExplode(aContext->shape(), aShape->shapeType());
442 int anIndex = aNExplode.index(aShape);
443 if (anIndex != 0) { // found a week-naming index, so, export it
444 myDumpBuffer << "model.selection(\"" << aShape->shapeTypeStr() << "\", \""
445 << theAttrSelect->contextName(aContext) << "\", " << anIndex << ")";
446 aStandardDump = false;
450 DumpStorage::write(theAttrSelect);
452 // ======================================================================
455 static int gCompositeStackDepth = 0;
457 ModelHighAPI_Dumper* ModelHighAPI_Dumper::mySelf = 0;
459 ModelHighAPI_Dumper::ModelHighAPI_Dumper()
460 : myDumpStorage(new DumpStorageBuffer),
461 myDumpPostponedInProgress(false)
465 ModelHighAPI_Dumper::~ModelHighAPI_Dumper()
467 delete myDumpStorage;
470 void ModelHighAPI_Dumper::setInstance(ModelHighAPI_Dumper* theDumper)
476 ModelHighAPI_Dumper* ModelHighAPI_Dumper::getInstance()
481 void ModelHighAPI_Dumper::addCustomStorage(const ModelHighAPI_Dumper::DumpStoragePtr& theStorage)
483 myDumpStorage->addStorage(theStorage);
486 void ModelHighAPI_Dumper::clearCustomStorage()
488 myDumpStorage->clear();
492 myFeatureCount.clear();
494 while (!myEntitiesStack.empty())
495 myEntitiesStack.pop();
499 void ModelHighAPI_Dumper::clearNotDumped()
501 myNotDumpedEntities.clear();
504 // Convert string to integer. If the string is not a number, return -1
505 static int toInt(const std::string& theString)
507 std::string::const_iterator aChar = theString.begin();
508 for (; aChar != theString.end(); ++aChar)
509 if (!std::isdigit(*aChar))
511 if (aChar != theString.end())
512 return -1; // not a number
513 return std::stoi(theString);
516 const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity,
517 bool theSaveNotDumped,
518 bool theUseEntityName)
520 EntityNameMap::const_iterator aFound = myNames.find(theEntity);
521 if (aFound != myNames.end())
522 return aFound->second.myCurrentName;
524 // entity is not found, store it
525 std::string aName, aKind;
526 bool isDefaultName = false;
527 bool isSaveNotDumped = theSaveNotDumped;
528 std::ostringstream aDefaultName;
529 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theEntity);
531 aName = aFeature->name();
532 aKind = aFeature->getKind();
534 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(theEntity);
536 aName = aFolder->data()->name();
537 aKind = ModelAPI_Folder::ID();
538 isSaveNotDumped = false;
542 ObjectPtr anObject = std::dynamic_pointer_cast<ModelAPI_Object>(theEntity);
544 DocumentPtr aDoc = anObject->document();
545 std::pair<int, int>& aNbFeatures = myFeatureCount[aDoc][aKind];
546 aNbFeatures.first += 1;
548 size_t anIndex = aName.find(aKind);
549 if (anIndex == 0 && aName[aKind.length()] == '_') { // name starts with "FeatureKind_"
550 std::string anIdStr = aName.substr(aKind.length() + 1);
551 int anId = toInt(anIdStr);
553 // Check number of already registered objects of such kind. Index of current object
554 // should be the same to identify feature's name as automatically generated.
555 if (aNbFeatures.first == anId && aNbFeatures.second < anId) {
556 // name is not user-defined
557 isDefaultName = true;
559 // check there are postponed features of this kind,
560 // dump their names, because the sequence of features may be changed
561 for (std::list<EntityPtr>::const_iterator aPpIt = myPostponed.begin();
562 aPpIt != myPostponed.end(); ++aPpIt) {
563 FeaturePtr aCurFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aPpIt);
564 if (aCurFeature && aCurFeature->getKind() == aKind) {
565 myNames[*aPpIt].myIsDefault = false;
566 isDefaultName = false;
571 if (anId > aNbFeatures.second)
572 aNbFeatures.second = anId;
575 // obtain default name for the feature
576 if (theUseEntityName)
577 aDefaultName << aName;
580 NbFeaturesMap::const_iterator aFIt = myFeatureCount.begin();
581 for (; aFIt != myFeatureCount.end(); ++aFIt) {
582 std::map<std::string, std::pair<int, int> >::const_iterator aFound =
583 aFIt->second.find(aKind);
584 if (aFound != aFIt->second.end())
585 aFullIndex += aFound->second.first;
587 aDefaultName << aKind << "_" << aFullIndex;
591 myNames[theEntity] = EntityName(aDefaultName.str(), aName, isDefaultName);
593 myNotDumpedEntities.insert(theEntity);
595 // store names of results
597 saveResultNames(aFeature);
599 return myNames[theEntity].myCurrentName;
602 const std::string& ModelHighAPI_Dumper::parentName(const FeaturePtr& theEntity)
604 const std::set<AttributePtr>& aRefs = theEntity->data()->refsToMe();
605 std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin();
606 for (; aRefIt != aRefs.end(); ++aRefIt) {
607 CompositeFeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(
608 ModelAPI_Feature::feature((*aRefIt)->owner()));
610 return name(anOwner);
613 static const std::string DUMMY;
617 void ModelHighAPI_Dumper::saveResultNames(const FeaturePtr& theFeature)
619 // Default name of the feature
620 bool isFeatureDefaultName = myNames[theFeature].myIsDefault;
622 // Save only names of results which is not correspond to default feature name
623 const std::list<ResultPtr>& aResults = theFeature->results();
624 std::list<ResultPtr> allRes;
625 ModelAPI_Tools::allResults(theFeature, allRes);
626 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
627 std::pair<std::string, bool> aName = ModelAPI_Tools::getDefaultName(*aRes);
628 std::string aDefaultName = aName.first;
629 std::string aResName = (*aRes)->data()->name();
630 bool isUserDefined = !(isFeatureDefaultName && aDefaultName == aResName);
632 EntityName(aResName, (isUserDefined ? aResName : std::string()), !isUserDefined);
636 bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theDoc,
637 const std::string& theFileName)
639 // dump top level document feature
640 static const std::string aDocName("partSet");
641 myNames[theDoc] = EntityName(aDocName, std::string(), true);
642 *this << aDocName << " = model.moduleDocument()" << std::endl;
644 // dump subfeatures and store result to file
645 bool isOk = process(theDoc) && myDumpStorage->exportTo(theFileName, myModules);
646 clearCustomStorage();
650 bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theDoc)
653 std::list<ObjectPtr> anObjects = theDoc->allObjects();
654 std::list<ObjectPtr>::const_iterator anObjIt = anObjects.begin();
655 // firstly, dump all parameters
656 for (; anObjIt != anObjects.end(); ++ anObjIt) {
657 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIt);
659 dumpParameter(aFeature);
661 // dump all other features
662 for (anObjIt = anObjects.begin(); anObjIt != anObjects.end(); ++anObjIt) {
663 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*anObjIt);
664 if (aCompFeat) // iteratively process composite features
665 isOk = process(aCompFeat) && isOk;
666 else if (!isDumped(EntityPtr(*anObjIt))) {
668 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(*anObjIt);
672 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIt);
673 if (aFeature) // dump common feature
674 dumpFeature(aFeature);
678 // dump folders if any
683 bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
686 // increase composite features stack
687 ++gCompositeStackDepth;
688 // dump composite itself
689 if (!isDumped(EntityPtr(theComposite)) || isForce)
690 dumpFeature(FeaturePtr(theComposite), isForce);
692 // sub-part is processed independently, because it provides separate document
693 if (theComposite->getKind() == PartSetPlugin_Part::ID()) {
694 // dump name of the part if it is different from default
695 if (!myEntitiesStack.empty())
698 // decrease composite features stack because we run into separate document
699 --gCompositeStackDepth;
701 ResultPartPtr aPartResult =
702 std::dynamic_pointer_cast<ModelAPI_ResultPart>(theComposite->lastResult());
705 DocumentPtr aSubDoc = aPartResult->partDoc();
708 // set name of document
709 const std::string& aPartName = myNames[theComposite].myCurrentName;
710 std::string aDocName = aPartName + "_doc";
711 myNames[aSubDoc] = EntityName(aDocName, std::string(), true);
713 // dump document in a separate line
714 *this << aDocName << " = " << aPartName << ".document()" << std::endl;
715 // dump features in the document
716 bool aRes = process(aSubDoc);
717 *this << "model.do()" << std::endl;
722 bool isOk = processSubs(theComposite);
723 // decrease composite features stack
724 --gCompositeStackDepth;
729 bool ModelHighAPI_Dumper::processSubs(
730 const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
734 // dump all sub-features;
735 bool isSubDumped = false;
736 int aNbSubs = theComposite->numberOfSubs();
737 for (int anIndex = 0; anIndex < aNbSubs; ++anIndex) {
738 FeaturePtr aFeature = theComposite->subFeature(anIndex);
739 if (isDumped(EntityPtr(aFeature)))
743 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
744 if (aCompFeat) // iteratively process composite features
745 isOk = process(aCompFeat) && isOk;
747 dumpFeature(aFeature, true);
750 bool isDumpSetName = !myEntitiesStack.empty() &&
751 myEntitiesStack.top().myEntity == EntityPtr(theComposite);
752 bool isForceModelDo = isSubDumped && isDumpSetName &&
753 (myEntitiesStack.top().myUserName || !myEntitiesStack.top().myResults.empty());
754 // It is necessary for the sketch to create its result when complete (command "model.do()").
755 // This option is set by flat theDumpModelDo.
756 // However, nested sketches are rebuilt by parent feature, so, they do not need
757 // explicit call of "model.do()". This will be controlled by the depth of the stack.
758 if (isForceModelDo || (theDumpModelDo && gCompositeStackDepth <= 1))
759 *this << "model.do()" << std::endl;
761 // dump "setName" for composite feature
767 void ModelHighAPI_Dumper::postpone(const EntityPtr& theEntity)
770 name(theEntity, false);
771 myPostponed.push_back(theEntity);
774 void ModelHighAPI_Dumper::dumpPostponed(bool theDumpFolders)
776 if (myDumpPostponedInProgress)
779 myDumpPostponedInProgress = true;
780 // make a copy of postponed entities, because the list will be updated
781 // if some features are not able to be dumped
782 std::list<EntityPtr> aPostponedCopy = myPostponed;
785 // iterate over postponed entities and try to dump them
786 std::list<EntityPtr>::const_iterator anIt = aPostponedCopy.begin();
787 for (; anIt != aPostponedCopy.end(); ++anIt) {
788 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(*anIt);
793 myPostponed.push_back(*anIt);
796 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
798 dumpFeature(aFeature, true);
801 myDumpPostponedInProgress = false;
804 void ModelHighAPI_Dumper::dumpSubFeatureNameAndColor(const std::string theSubFeatureGet,
805 const FeaturePtr& theSubFeature)
807 name(theSubFeature, false);
808 myNames[theSubFeature] = EntityName(theSubFeatureGet, theSubFeature->name(), false);
810 // store results if they have user-defined names or colors
811 std::list<ResultPtr> aResultsWithNameOrColor;
812 const std::list<ResultPtr>& aResults = theSubFeature->results();
813 std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
814 for (; aResIt != aResults.end(); ++aResIt) {
815 std::string aResName = (*aResIt)->data()->name();
816 myNames[*aResIt] = EntityName(aResName, aResName, false);
817 aResultsWithNameOrColor.push_back(*aResIt);
820 // store just dumped entity to stack
821 myEntitiesStack.push(LastDumpedEntity(theSubFeature, true, aResultsWithNameOrColor));
826 void ModelHighAPI_Dumper::importModule(const std::string& theModuleName)
828 myModules.insert(theModuleName);
831 void ModelHighAPI_Dumper::dumpEntitySetName()
833 const LastDumpedEntity& aLastDumped = myEntitiesStack.top();
834 bool isBufferEmpty = myDumpStorage->isBufferEmpty();
836 // dump "setName" for the entity
837 if (aLastDumped.myUserName) {
838 EntityName& anEntityNames = myNames[aLastDumped.myEntity];
839 if (!anEntityNames.myIsDefault)
840 *myDumpStorage << anEntityNames.myCurrentName << ".setName(\""
841 << anEntityNames.myUserName << "\")\n";
842 // don't dump "setName" for the entity twice
843 anEntityNames.myUserName.clear();
844 anEntityNames.myIsDefault = true;
846 // dump "setName" for results
847 std::list<ResultPtr>::const_iterator aResIt = aLastDumped.myResults.begin();
848 std::list<ResultPtr>::const_iterator aResEnd = aLastDumped.myResults.end();
849 for (; aResIt != aResEnd; ++aResIt) {
851 EntityName& anEntityNames = myNames[*aResIt];
852 if (!anEntityNames.myIsDefault) {
854 *myDumpStorage << ".setName(\"" << anEntityNames.myUserName << "\")\n";
855 // don't dump "setName" for the entity twice
856 anEntityNames.myUserName.clear();
857 anEntityNames.myIsDefault = true;
860 if (!isDefaultColor(*aResIt)) {
861 AttributeIntArrayPtr aColor = (*aResIt)->data()->intArray(ModelAPI_Result::COLOR_ID());
862 if (aColor && aColor->isInitialized()) {
864 *myDumpStorage << ".setColor(" << aColor->value(0) << ", " << aColor->value(1)
865 << ", " << aColor->value(2) << ")\n";
868 // set result deflection
869 if (!isDefaultDeflection(*aResIt)) {
870 AttributeDoublePtr aDeflectionAttr =
871 (*aResIt)->data()->real(ModelAPI_Result::DEFLECTION_ID());
872 if(aDeflectionAttr.get() && aDeflectionAttr->isInitialized()) {
874 *myDumpStorage << ".setDeflection(" << aDeflectionAttr->value() << ")\n";
877 // set result transparency
878 if (!isDefaultTransparency(*aResIt)) {
879 AttributeDoublePtr aTransparencyAttr =
880 (*aResIt)->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
881 if(aTransparencyAttr.get() && aTransparencyAttr->isInitialized()) {
883 *myDumpStorage << ".setTransparency(" << aTransparencyAttr->value() << ")\n";
888 myNames[aLastDumped.myEntity].myIsDumped = true;
889 myEntitiesStack.pop();
891 // clean buffer if it was clear before
893 myDumpStorage->mergeBuffer();
896 bool ModelHighAPI_Dumper::isDumped(const EntityPtr& theEntity) const
898 EntityNameMap::const_iterator aFound = myNames.find(theEntity);
899 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theEntity);
900 return (aFound != myNames.end() && aFound->second.myIsDumped) ||
901 myFeaturesToSkip.find(aFeature) != myFeaturesToSkip.end();
904 bool ModelHighAPI_Dumper::isDumped(const AttributeRefAttrPtr& theRefAttr) const
907 if (theRefAttr->isObject())
908 aFeature = ModelAPI_Feature::feature(theRefAttr->object());
910 aFeature = ModelAPI_Feature::feature(theRefAttr->attr()->owner());
911 return aFeature && isDumped(EntityPtr(aFeature));
914 bool ModelHighAPI_Dumper::isDumped(const AttributeRefListPtr& theRefList) const
916 std::list<ObjectPtr> aRefs = theRefList->list();
917 std::list<ObjectPtr>::iterator anIt = aRefs.begin();
918 for (; anIt != aRefs.end(); ++anIt) {
919 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
920 if (aFeature && !isDumped(EntityPtr(aFeature)))
926 static bool isSketchSub(const FeaturePtr& theFeature)
928 static const std::string SKETCH("Sketch");
929 CompositeFeaturePtr anOwner = ModelAPI_Tools::compositeOwner(theFeature);
930 return anOwner && anOwner->getKind() == SKETCH;
933 bool ModelHighAPI_Dumper::isDefaultColor(const ResultPtr& theResult) const
935 AttributeIntArrayPtr aColor = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
936 if (!aColor || !aColor->isInitialized())
939 // check the result belongs to sketch entity, do not dump color in this way
940 ResultConstructionPtr aResConstr =
941 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult);
943 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult->data()->owner());
944 if (isSketchSub(aFeature))
948 std::string aSection, aName, aDefault;
949 theResult->colorConfigInfo(aSection, aName, aDefault);
951 // dump current color
952 std::ostringstream aColorInfo;
953 aColorInfo << aColor->value(0) << "," << aColor->value(1) << "," << aColor->value(2);
955 return aDefault == aColorInfo.str();
958 bool ModelHighAPI_Dumper::isDefaultDeflection(const ResultPtr& theResult) const
960 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
961 if(!aDeflectionAttr || !aDeflectionAttr->isInitialized()) {
965 double aCurrent = aDeflectionAttr->value();
966 double aDefault = -1;
968 bool isConstruction = false;
969 std::string aResultGroup = theResult->groupName();
970 if (aResultGroup == ModelAPI_ResultConstruction::group())
971 isConstruction = true;
972 else if (aResultGroup == ModelAPI_ResultBody::group()) {
973 GeomShapePtr aGeomShape = theResult->shape();
974 if (aGeomShape.get()) {
975 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
976 // correction of deviation for them should not influence to the application performance
977 GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
978 isConstruction = !anExp.more();
982 aDefault = Config_PropManager::real("Visualization", "construction_deflection");
984 aDefault = Config_PropManager::real("Visualization", "body_deflection");
986 return fabs(aCurrent - aDefault) < 1.e-12;
989 bool ModelHighAPI_Dumper::isDefaultTransparency(const ResultPtr& theResult) const
991 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
992 if(!anAttribute || !anAttribute->isInitialized()) {
995 return fabs(anAttribute->value()) < 1.e-12;
998 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char theChar)
1000 *myDumpStorage << theChar;
1004 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char* theString)
1006 *myDumpStorage << theString;
1010 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const std::string& theString)
1012 *myDumpStorage << theString;
1016 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const bool theValue)
1018 *myDumpStorage << (theValue ? "True" : "False");
1022 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const int theValue)
1024 *myDumpStorage << theValue;
1028 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const double theValue)
1030 *myDumpStorage << theValue;
1034 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1036 importModule("GeomAPI");
1037 *myDumpStorage << "GeomAPI_Pnt(" << thePoint->x() << ", "
1038 << thePoint->y() << ", " << thePoint->z() << ")";
1042 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir)
1044 importModule("GeomAPI");
1045 *myDumpStorage << "GeomAPI_Dir(" << theDir->x() << ", "
1046 << theDir->y() << ", " << theDir->z() << ")";
1050 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1051 const std::shared_ptr<GeomDataAPI_Dir>& theDir)
1053 *myDumpStorage << theDir->x() << ", " << theDir->y() << ", " << theDir->z();
1057 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1058 const std::shared_ptr<GeomDataAPI_Point>& thePoint)
1060 static const int aSize = 3;
1061 double aValues[aSize] = {thePoint->x(), thePoint->y(), thePoint->z()};
1062 std::string aTexts[aSize] = {thePoint->textX(), thePoint->textY(), thePoint->textZ()};
1063 myDumpStorage->dumpArray(aSize, aValues, aTexts);
1067 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1068 const std::shared_ptr<GeomDataAPI_Point2D>& thePoint)
1070 static const int aSize = 2;
1071 double aValues[aSize] = {thePoint->x(), thePoint->y()};
1072 std::string aTexts[aSize] = {thePoint->textX(), thePoint->textY()};
1073 myDumpStorage->dumpArray(aSize, aValues, aTexts);
1077 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1078 const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool)
1080 *myDumpStorage << (theAttrBool->value() ? "True" : "False");
1084 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1085 const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt)
1087 std::string aText = theAttrInt->text();
1089 *myDumpStorage << theAttrInt->value();
1091 *myDumpStorage << "\"" << aText << "\"";
1095 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1096 const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal)
1098 std::string aText = theAttrReal->text();
1100 *myDumpStorage << theAttrReal->value();
1102 *myDumpStorage << "\"" << aText << "\"";
1106 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1107 const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr)
1109 *myDumpStorage << "\"" << theAttrStr->value() << "\"";
1113 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FolderPtr& theFolder)
1115 *myDumpStorage << name(theFolder);
1117 // add dumped folder to a stack
1118 if (!myNames[theFolder].myIsDumped &&
1119 (myEntitiesStack.empty() || myEntitiesStack.top().myEntity != theFolder))
1120 myEntitiesStack.push(LastDumpedEntity(theFolder, !myNames[theFolder].myIsDefault));
1125 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity)
1127 *myDumpStorage << name(theEntity);
1129 if (!myNames[theEntity].myIsDumped) {
1130 bool isUserDefinedName = !myNames[theEntity].myIsDefault;
1131 // store results if they have user-defined names or colors
1132 std::list<ResultPtr> aResultsWithNameOrColor;
1133 std::list<ResultPtr> allRes;
1134 ModelAPI_Tools::allResults(theEntity, allRes);
1135 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
1136 if(!myNames[*aRes].myIsDefault || !isDefaultColor(*aRes) ||
1137 !isDefaultDeflection(*aRes) || !isDefaultTransparency(*aRes))
1138 aResultsWithNameOrColor.push_back(*aRes);
1140 // store just dumped entity to stack
1141 if (myEntitiesStack.empty() || myEntitiesStack.top().myEntity != theEntity)
1142 myEntitiesStack.push(
1143 LastDumpedEntity(theEntity, isUserDefinedName, aResultsWithNameOrColor));
1146 // remove entity from the list of not dumped items
1147 myNotDumpedEntities.erase(theEntity);
1151 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ResultPtr& theResult)
1153 // iterate in the structure of sub-results to the parent
1154 ResultPtr aCurRes = theResult;
1155 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
1156 std::list<int> anIndices; // indexes of results in the parent result, starting from topmost
1157 while(aCurRes.get()) {
1158 ResultBodyPtr aParent = ModelAPI_Tools::bodyOwner(aCurRes);
1160 anIndices.push_front(ModelAPI_Tools::bodyIndex(aCurRes));
1161 } else { // index of the result in the feature
1162 std::list<ResultPtr>::const_iterator aRes = aFeature->results().cbegin();
1163 for(int anIndex = 0; aRes != aFeature->results().cend(); aRes++, anIndex++) {
1164 if (*aRes == aCurRes) {
1165 anIndices.push_front(anIndex);
1173 *myDumpStorage << name(aFeature);
1174 for (std::list<int>::iterator anI = anIndices.begin(); anI != anIndices.end(); anI++) {
1175 if (anI == anIndices.begin()) {
1177 *myDumpStorage << ".result()";
1180 *myDumpStorage << ".results()[" << *anI << "]";
1183 *myDumpStorage << ".subResult(" << *anI << ")";
1190 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ObjectPtr& theObject)
1192 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1193 if(aFeature.get()) {
1194 *myDumpStorage << name(aFeature);
1198 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1207 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const AttributePtr& theAttr)
1209 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttr->owner());
1211 std::string aWrapperPrefix, aWrapperSuffix;
1212 // Check the attribute belongs to copied (in multi-translation or multi-rotation) feature.
1213 // In this case we need to cast explicitly feature to appropriate type.
1214 AttributeBooleanPtr isCopy = anOwner->boolean("Copy");
1215 if (isCopy.get() && isCopy->value()) {
1216 aWrapperPrefix = featureWrapper(anOwner) + "(";
1217 aWrapperSuffix = ")";
1218 importModule("SketchAPI");
1221 *myDumpStorage << aWrapperPrefix << name(anOwner) << aWrapperSuffix
1222 << "." << attributeGetter(anOwner, theAttr->id()) << "()";
1226 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1227 const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr)
1229 if (theRefAttr->isObject())
1230 *this << theRefAttr->object();
1232 *this << theRefAttr->attr();
1236 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1237 const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList)
1239 *myDumpStorage << "[";
1240 std::list<std::pair<ObjectPtr, AttributePtr> > aList = theRefAttrList->list();
1241 bool isAdded = false;
1242 std::list<std::pair<ObjectPtr, AttributePtr> >::const_iterator anIt = aList.begin();
1243 for (; anIt != aList.end(); ++anIt) {
1245 *myDumpStorage << ", ";
1249 *this << anIt->first;
1250 else if (anIt->second)
1251 * this << anIt->second;
1253 *myDumpStorage << "]";
1257 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1258 const std::shared_ptr<ModelAPI_AttributeReference>& theReference)
1260 *this << theReference->value();
1264 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1265 const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList)
1267 static const int aThreshold = 2;
1268 static bool aDumpAsIs = false;
1269 // if number of elements in the list if greater than a threshold,
1270 // dump it in a separate line with specific name
1271 if (aDumpAsIs || theRefList->size() <= aThreshold) {
1272 *myDumpStorage << "[";
1273 std::list<ObjectPtr> aList = theRefList->list();
1274 bool isAdded = false;
1275 std::list<ObjectPtr>::const_iterator anIt = aList.begin();
1276 for (; anIt != aList.end(); ++anIt) {
1278 *myDumpStorage << ", ";
1284 *myDumpStorage << "]";
1287 FeaturePtr anOwner = ModelAPI_Feature::feature(theRefList->owner());
1288 std::string aListName = name(anOwner) + "_objects";
1289 // reserve dumped buffer and store list "as is"
1290 myDumpStorage->reserveBuffer();
1292 *this << aListName << " = " << theRefList << "\n";
1294 // append reserved data to the end of the current buffer
1295 myDumpStorage->restoreReservedBuffer();
1296 *myDumpStorage << aListName;
1301 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1302 const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect)
1304 myDumpStorage->write(theAttrSelect);
1308 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1309 const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList)
1311 static const int aThreshold = 2;
1312 static bool aDumpAsIs = false;
1313 // if number of elements in the list if greater than a threshold,
1314 // dump it in a separate line with specific name
1315 if (aDumpAsIs || theAttrSelList->size() <= aThreshold) {
1316 *myDumpStorage << "[";
1318 GeomShapePtr aShape;
1319 std::string aShapeTypeStr;
1321 bool isAdded = false;
1323 for(int anIndex = 0; anIndex < theAttrSelList->size(); ++anIndex) {
1324 AttributeSelectionPtr anAttribute = theAttrSelList->value(anIndex);
1325 aShape = anAttribute->value();
1327 ResultPtr aContext = anAttribute->context();
1329 aShape = aContext->shape();
1337 *myDumpStorage << ", ";
1341 *this << anAttribute;
1344 *myDumpStorage << "]";
1346 // obtain name of list (the feature may contain several selection lists)
1347 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttrSelList->owner());
1348 std::string aListName = name(anOwner) + "_objects";
1349 std::list<AttributePtr> aSelLists =
1350 anOwner->data()->attributes(ModelAPI_AttributeSelectionList::typeId());
1351 if (aSelLists.size() > 1) {
1353 for (std::list<AttributePtr>::iterator aSIt = aSelLists.begin();
1354 aSIt != aSelLists.end(); ++aSIt, ++anIndex)
1355 if ((*aSIt).get() == theAttrSelList.get())
1357 std::ostringstream aSStream;
1358 aSStream << aListName << "_" << anIndex;
1359 aListName = aSStream.str();
1361 // reserve dumped buffer and store list "as is"
1362 myDumpStorage->reserveBuffer();
1364 *this << aListName << " = " << theAttrSelList << "\n";
1366 // append reserved data to the end of the current buffer
1367 myDumpStorage->restoreReservedBuffer();
1368 *myDumpStorage << aListName;
1373 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1374 const std::shared_ptr<ModelAPI_AttributeStringArray>& theArray)
1376 std::ostringstream aBuffer;
1378 for(int anIndex = 0; anIndex < theArray->size(); ++anIndex) {
1382 aBuffer << "\"" << theArray->value(anIndex) << "\"";
1386 myDumpStorage->write(aBuffer.str());
1391 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
1392 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&))
1394 *theDumper.myDumpStorage << theEndl;
1396 if (!theDumper.myEntitiesStack.empty()) {
1398 // all copies have been stored into stack, pop them all
1401 // Name for composite feature is dumped when all sub-entities are dumped
1402 // (see method ModelHighAPI_Dumper::processSubs).
1403 const ModelHighAPI_Dumper::LastDumpedEntity& aLastDumped = theDumper.myEntitiesStack.top();
1404 CompositeFeaturePtr aComposite =
1405 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aLastDumped.myEntity);
1407 theDumper.dumpEntitySetName();
1408 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aLastDumped.myEntity);
1410 AttributeBooleanPtr aCopyAttr = aFeature->boolean("Copy");
1411 isCopy = aCopyAttr.get() && aCopyAttr->value();
1414 } while (isCopy && !theDumper.myEntitiesStack.empty());
1417 // store all not-dumped entities first
1418 std::set<EntityPtr> aNotDumped = theDumper.myNotDumpedEntities;
1419 theDumper.myDumpStorage->reserveBuffer();
1420 std::set<EntityPtr>::const_iterator anIt = aNotDumped.begin();
1421 for (; anIt != aNotDumped.end(); ++anIt) {
1422 // if the feature is composite, dump it with all subs
1423 CompositeFeaturePtr aCompFeat =
1424 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*anIt);
1426 theDumper.process(aCompFeat, true);
1428 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
1429 theDumper.dumpFeature(aFeature, true);
1430 // dump the Projection feature which produces this "Copy" entity
1431 AttributeBooleanPtr aCopyAttr = aFeature->boolean("Copy");
1432 if (aCopyAttr.get() && aCopyAttr->value())
1434 const std::set<AttributePtr>& aRefs = aFeature->data()->refsToMe();
1435 std::set<AttributePtr>::iterator aRefIt = aRefs.begin();
1436 for (; aRefIt != aRefs.end(); ++aRefIt)
1437 if ((*aRefIt)->id() == "ProjectedFeature")
1438 { // process projection only
1439 FeaturePtr anOwner = ModelAPI_Feature::feature((*aRefIt)->owner());
1440 if (anOwner && !theDumper.isDumped(EntityPtr(anOwner)))
1441 theDumper.dumpFeature(anOwner, true);
1447 // then store the reserved data
1448 theDumper.myDumpStorage->restoreReservedBuffer();
1449 theDumper.myDumpStorage->mergeBuffer();
1451 // now, store all postponed features
1452 theDumper.dumpPostponed();