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 imported modules
258 for (ModulesSet::const_iterator aModIt = theUsedModules.begin();
259 aModIt != theUsedModules.end(); ++aModIt) {
260 aFile << "from " << *aModIt << " import *" << std::endl;
262 if (!theUsedModules.empty())
265 aFile << "from salome.shaper import model" << std::endl << std::endl;
266 aFile << "model.begin()" << std::endl;
268 // dump collected data
269 aFile << myFullDump.str();
270 aFile << myDumpBuffer.str();
273 aFile << "model.end()" << std::endl;
279 static void getShapeAndContext(const AttributeSelectionPtr& theAttrSelect,
280 GeomShapePtr& theShape, ResultPtr& theContext)
282 if (theAttrSelect->isInitialized()) {
283 theShape = theAttrSelect->value();
284 theContext = theAttrSelect->context();
286 theShape = theContext->shape();
288 if (theAttrSelect->isGeometricalSelection() &&
289 theShape.get() && theShape->shapeType() == GeomAPI_Shape::COMPOUND &&
290 theContext.get() && !theShape->isEqual(theContext->shape()) &&
291 theContext->groupName() != ModelAPI_ResultPart::group()) {
292 GeomAPI_ShapeIterator anIt(theShape);
293 theShape = anIt.current();
298 void ModelHighAPI_Dumper::DumpStorage::write(const AttributeSelectionPtr& theAttrSelect)
300 myDumpBuffer << "model.selection(";
304 getShapeAndContext(theAttrSelect, aShape, aContext);
307 myDumpBuffer << "\"" << aShape->shapeTypeStr() << "\", \""
308 << theAttrSelect->namingName() << "\"";
314 static int possibleSelectionsByPoint(const GeomPointPtr& thePoint,
315 const ResultPtr& theResult,
316 const GeomShapePtr& theShape,
317 const FeaturePtr& theStartFeature,
318 const FeaturePtr& theEndFeature)
320 DocumentPtr aDoc1 = theStartFeature->document();
321 DocumentPtr aDoc2 = theEndFeature->document();
323 std::list<FeaturePtr> aFeatures = aDoc1->allFeatures();
324 if (aDoc1 != aDoc2) {
325 std::list<FeaturePtr> anAdditionalFeatures = aDoc2->allFeatures();
326 aFeatures.insert(aFeatures.end(), anAdditionalFeatures.begin(), anAdditionalFeatures.end());
329 CompositeFeaturePtr aLastCompositeFeature;
331 std::list<FeaturePtr>::const_iterator aFIt = aFeatures.begin();
332 while (aFIt != aFeatures.end() && *aFIt != theStartFeature) {
333 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFIt);
335 aLastCompositeFeature = aCompFeat;
339 // collect the list of composite features, containing the last feature;
340 // these features should be excluded from searching,
341 // because the feature cannot select sub-shapes from its parent
342 std::set<FeaturePtr> aEndFeatureParents = ModelAPI_Tools::getParents(theEndFeature);
344 int aNbPossibleSelections = 0;
345 for (; aFIt != aFeatures.end() && *aFIt != theEndFeature; ++aFIt) {
346 bool isSkipFeature = false;
347 if (aLastCompositeFeature && aLastCompositeFeature->isSub(*aFIt))
348 isSkipFeature = true;
349 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFIt);
351 ResultPartPtr aPartRes =
352 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aCompFeat->firstResult());
354 aLastCompositeFeature = aCompFeat;
355 if (aEndFeatureParents.find(aCompFeat) != aEndFeatureParents.end()) {
356 // do not process the parent for the last feature,
357 // because it cannot select objects from its parent
358 isSkipFeature = true;
364 std::list<ModelGeomAlgo_Shape::SubshapeOfResult> anApproproate;
365 if (ModelGeomAlgo_Shape::findSubshapeByPoint(*aFIt, thePoint, theShape->shapeType(),
367 std::list<ModelGeomAlgo_Shape::SubshapeOfResult>::iterator anApIt = anApproproate.begin();
368 for (; anApIt != anApproproate.end(); ++anApIt) {
369 ++aNbPossibleSelections;
371 // stop if the target shape and result are found
372 GeomShapePtr aCurShape = anApIt->mySubshape;
374 aCurShape = anApIt->myResult->shape();
376 if (anApIt->myResult->isSame(theResult) && aCurShape->isSame(theShape))
381 return aNbPossibleSelections;
384 void ModelHighAPI_Dumper::DumpStorageGeom::write(const AttributeSelectionPtr& theAttrSelect)
388 getShapeAndContext(theAttrSelect, aShape, aContext);
390 // how to dump selection: construction features are dumped by name always
391 FeaturePtr aSelectedFeature;
392 FeaturePtr aFeature = theAttrSelect->contextFeature();
393 if (aShape && aContext && !aFeature)
394 aSelectedFeature = ModelAPI_Feature::feature(aContext->data()->owner());
395 bool isDumpByGeom = aSelectedFeature && aSelectedFeature->isInHistory();
398 myDumpBuffer << "model.selection(\"" << aShape->shapeTypeStr();
399 // check the selected item is a ResultPart;
400 // in this case it is necessary to get shape with full transformation
401 // for correct calculation of the middle point
402 ResultPartPtr aResPart =
403 std::dynamic_pointer_cast<ModelAPI_ResultPart>(theAttrSelect->context());
404 if (aResPart && aShape->shapeType() == GeomAPI_Shape::COMPOUND)
405 aShape = aResPart->shape();
406 GeomPointPtr aMiddlePoint = aShape->middlePoint();
407 // calculate number of features, which could be selected by the same point
408 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttrSelect->owner());
409 int aNbPossibleSelections = possibleSelectionsByPoint(aMiddlePoint,
410 theAttrSelect->context(), aShape, aSelectedFeature, anOwner);
412 // produce the index if the number of applicable features is greater than 1
414 if (aNbPossibleSelections > 1) {
415 std::ostringstream anOutput;
416 anOutput << "_" << aNbPossibleSelections;
417 anIndex = anOutput.str();
420 myDumpBuffer << std::setprecision(THE_DUMP_PRECISION)
421 << anIndex << "\", ("
422 << aMiddlePoint->x() << ", "
423 << aMiddlePoint->y() << ", "
424 << aMiddlePoint->z() << ")";
428 DumpStorage::write(theAttrSelect);
431 void ModelHighAPI_Dumper::DumpStorageWeak::write(const AttributeSelectionPtr& theAttrSelect)
435 getShapeAndContext(theAttrSelect, aShape, aContext);
437 bool aStandardDump = true;
438 if (aShape.get() && aContext.get() &&
439 aShape != aContext->shape()) { // weak naming for local selection only
440 GeomAlgoAPI_NExplode aNExplode(aContext->shape(), aShape->shapeType());
441 int anIndex = aNExplode.index(aShape);
442 if (anIndex != 0) { // found a week-naming index, so, export it
443 myDumpBuffer << "model.selection(\"" << aShape->shapeTypeStr() << "\", \""
444 << theAttrSelect->contextName(aContext) << "\", " << anIndex << ")";
445 aStandardDump = false;
449 DumpStorage::write(theAttrSelect);
451 // ======================================================================
454 static int gCompositeStackDepth = 0;
456 ModelHighAPI_Dumper* ModelHighAPI_Dumper::mySelf = 0;
458 ModelHighAPI_Dumper::ModelHighAPI_Dumper()
459 : myDumpStorage(new DumpStorageBuffer),
460 myDumpPostponedInProgress(false)
464 ModelHighAPI_Dumper::~ModelHighAPI_Dumper()
466 delete myDumpStorage;
469 void ModelHighAPI_Dumper::setInstance(ModelHighAPI_Dumper* theDumper)
475 ModelHighAPI_Dumper* ModelHighAPI_Dumper::getInstance()
480 void ModelHighAPI_Dumper::addCustomStorage(const ModelHighAPI_Dumper::DumpStoragePtr& theStorage)
482 myDumpStorage->addStorage(theStorage);
485 void ModelHighAPI_Dumper::clearCustomStorage()
487 myDumpStorage->clear();
491 myFeatureCount.clear();
493 while (!myEntitiesStack.empty())
494 myEntitiesStack.pop();
498 void ModelHighAPI_Dumper::clearNotDumped()
500 myNotDumpedEntities.clear();
503 // Convert string to integer. If the string is not a number, return -1
504 static int toInt(const std::string& theString)
506 std::string::const_iterator aChar = theString.begin();
507 for (; aChar != theString.end(); ++aChar)
508 if (!std::isdigit(*aChar))
510 if (aChar != theString.end())
511 return -1; // not a number
512 return std::stoi(theString);
515 const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity,
516 bool theSaveNotDumped,
517 bool theUseEntityName)
519 EntityNameMap::const_iterator aFound = myNames.find(theEntity);
520 if (aFound != myNames.end())
521 return aFound->second.myCurrentName;
523 // entity is not found, store it
524 std::string aName, aKind;
525 bool isDefaultName = false;
526 bool isSaveNotDumped = theSaveNotDumped;
527 std::ostringstream aDefaultName;
528 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theEntity);
530 aName = aFeature->name();
531 aKind = aFeature->getKind();
533 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(theEntity);
535 aName = aFolder->data()->name();
536 aKind = ModelAPI_Folder::ID();
537 isSaveNotDumped = false;
541 ObjectPtr anObject = std::dynamic_pointer_cast<ModelAPI_Object>(theEntity);
543 DocumentPtr aDoc = anObject->document();
544 std::pair<int, int>& aNbFeatures = myFeatureCount[aDoc][aKind];
545 aNbFeatures.first += 1;
547 size_t anIndex = aName.find(aKind);
548 if (anIndex == 0 && aName[aKind.length()] == '_') { // name starts with "FeatureKind_"
549 std::string anIdStr = aName.substr(aKind.length() + 1);
550 int anId = toInt(anIdStr);
552 // Check number of already registered objects of such kind. Index of current object
553 // should be the same to identify feature's name as automatically generated.
554 if (aNbFeatures.first == anId && aNbFeatures.second < anId) {
555 // name is not user-defined
556 isDefaultName = true;
558 // check there are postponed features of this kind,
559 // dump their names, because the sequence of features may be changed
560 for (std::list<EntityPtr>::const_iterator aPpIt = myPostponed.begin();
561 aPpIt != myPostponed.end(); ++aPpIt) {
562 FeaturePtr aCurFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aPpIt);
563 if (aCurFeature && aCurFeature->getKind() == aKind) {
564 myNames[*aPpIt].myIsDefault = false;
565 isDefaultName = false;
570 if (anId > aNbFeatures.second)
571 aNbFeatures.second = anId;
574 // obtain default name for the feature
575 if (theUseEntityName)
576 aDefaultName << aName;
579 NbFeaturesMap::const_iterator aFIt = myFeatureCount.begin();
580 for (; aFIt != myFeatureCount.end(); ++aFIt) {
581 std::map<std::string, std::pair<int, int> >::const_iterator aFound =
582 aFIt->second.find(aKind);
583 if (aFound != aFIt->second.end())
584 aFullIndex += aFound->second.first;
586 aDefaultName << aKind << "_" << aFullIndex;
590 myNames[theEntity] = EntityName(aDefaultName.str(), aName, isDefaultName);
592 myNotDumpedEntities.insert(theEntity);
594 // store names of results
596 saveResultNames(aFeature);
598 return myNames[theEntity].myCurrentName;
601 const std::string& ModelHighAPI_Dumper::parentName(const FeaturePtr& theEntity)
603 const std::set<AttributePtr>& aRefs = theEntity->data()->refsToMe();
604 std::set<AttributePtr>::const_iterator aRefIt = aRefs.begin();
605 for (; aRefIt != aRefs.end(); ++aRefIt) {
606 CompositeFeaturePtr anOwner = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(
607 ModelAPI_Feature::feature((*aRefIt)->owner()));
609 return name(anOwner);
612 static const std::string DUMMY;
616 void ModelHighAPI_Dumper::saveResultNames(const FeaturePtr& theFeature)
618 // Default name of the feature
619 bool isFeatureDefaultName = myNames[theFeature].myIsDefault;
621 // Save only names of results which is not correspond to default feature name
622 const std::list<ResultPtr>& aResults = theFeature->results();
623 std::list<ResultPtr> allRes;
624 ModelAPI_Tools::allResults(theFeature, allRes);
625 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
626 std::pair<std::string, bool> aName = ModelAPI_Tools::getDefaultName(*aRes);
627 std::string aDefaultName = aName.first;
628 std::string aResName = (*aRes)->data()->name();
629 bool isUserDefined = !(isFeatureDefaultName && aDefaultName == aResName);
631 EntityName(aResName, (isUserDefined ? aResName : std::string()), !isUserDefined);
635 bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theDoc,
636 const std::string& theFileName)
638 // dump top level document feature
639 static const std::string aDocName("partSet");
640 myNames[theDoc] = EntityName(aDocName, std::string(), true);
641 *this << aDocName << " = model.moduleDocument()" << std::endl;
643 // dump subfeatures and store result to file
644 bool isOk = process(theDoc) && myDumpStorage->exportTo(theFileName, myModules);
645 clearCustomStorage();
649 bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theDoc)
652 std::list<ObjectPtr> anObjects = theDoc->allObjects();
653 std::list<ObjectPtr>::const_iterator anObjIt = anObjects.begin();
654 // firstly, dump all parameters
655 for (; anObjIt != anObjects.end(); ++ anObjIt) {
656 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIt);
658 dumpParameter(aFeature);
660 // dump all other features
661 for (anObjIt = anObjects.begin(); anObjIt != anObjects.end(); ++anObjIt) {
662 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*anObjIt);
663 if (aCompFeat) // iteratively process composite features
664 isOk = process(aCompFeat) && isOk;
665 else if (!isDumped(EntityPtr(*anObjIt))) {
667 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(*anObjIt);
671 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anObjIt);
672 if (aFeature) // dump common feature
673 dumpFeature(aFeature);
677 // dump folders if any
682 bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
685 // increase composite features stack
686 ++gCompositeStackDepth;
687 // dump composite itself
688 if (!isDumped(EntityPtr(theComposite)) || isForce)
689 dumpFeature(FeaturePtr(theComposite), isForce);
691 // sub-part is processed independently, because it provides separate document
692 if (theComposite->getKind() == PartSetPlugin_Part::ID()) {
693 // dump name of the part if it is different from default
694 if (!myEntitiesStack.empty())
697 // decrease composite features stack because we run into separate document
698 --gCompositeStackDepth;
700 ResultPartPtr aPartResult =
701 std::dynamic_pointer_cast<ModelAPI_ResultPart>(theComposite->lastResult());
704 DocumentPtr aSubDoc = aPartResult->partDoc();
707 // set name of document
708 const std::string& aPartName = myNames[theComposite].myCurrentName;
709 std::string aDocName = aPartName + "_doc";
710 myNames[aSubDoc] = EntityName(aDocName, std::string(), true);
712 // dump document in a separate line
713 *this << aDocName << " = " << aPartName << ".document()" << std::endl;
714 // dump features in the document
715 bool aRes = process(aSubDoc);
716 *this << "model.do()" << std::endl;
721 bool isOk = processSubs(theComposite);
722 // decrease composite features stack
723 --gCompositeStackDepth;
728 bool ModelHighAPI_Dumper::processSubs(
729 const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite,
733 // dump all sub-features;
734 bool isSubDumped = false;
735 int aNbSubs = theComposite->numberOfSubs();
736 for (int anIndex = 0; anIndex < aNbSubs; ++anIndex) {
737 FeaturePtr aFeature = theComposite->subFeature(anIndex);
738 if (isDumped(EntityPtr(aFeature)))
742 CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
743 if (aCompFeat) // iteratively process composite features
744 isOk = process(aCompFeat) && isOk;
746 dumpFeature(aFeature, true);
749 bool isDumpSetName = !myEntitiesStack.empty() &&
750 myEntitiesStack.top().myEntity == EntityPtr(theComposite);
751 bool isForceModelDo = isSubDumped && isDumpSetName &&
752 (myEntitiesStack.top().myUserName || !myEntitiesStack.top().myResults.empty());
753 // It is necessary for the sketch to create its result when complete (command "model.do()").
754 // This option is set by flat theDumpModelDo.
755 // However, nested sketches are rebuilt by parent feature, so, they do not need
756 // explicit call of "model.do()". This will be controlled by the depth of the stack.
757 if (isForceModelDo || (theDumpModelDo && gCompositeStackDepth <= 1))
758 *this << "model.do()" << std::endl;
760 // dump "setName" for composite feature
766 void ModelHighAPI_Dumper::postpone(const EntityPtr& theEntity)
769 name(theEntity, false);
770 myPostponed.push_back(theEntity);
773 void ModelHighAPI_Dumper::dumpPostponed(bool theDumpFolders)
775 if (myDumpPostponedInProgress)
778 myDumpPostponedInProgress = true;
779 // make a copy of postponed entities, because the list will be updated
780 // if some features are not able to be dumped
781 std::list<EntityPtr> aPostponedCopy = myPostponed;
784 // iterate over postponed entities and try to dump them
785 std::list<EntityPtr>::const_iterator anIt = aPostponedCopy.begin();
786 for (; anIt != aPostponedCopy.end(); ++anIt) {
787 FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(*anIt);
792 myPostponed.push_back(*anIt);
795 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
797 dumpFeature(aFeature, true);
800 myDumpPostponedInProgress = false;
803 void ModelHighAPI_Dumper::dumpSubFeatureNameAndColor(const std::string theSubFeatureGet,
804 const FeaturePtr& theSubFeature)
806 name(theSubFeature, false);
807 myNames[theSubFeature] = EntityName(theSubFeatureGet, theSubFeature->name(), false);
809 // store results if they have user-defined names or colors
810 std::list<ResultPtr> aResultsWithNameOrColor;
811 const std::list<ResultPtr>& aResults = theSubFeature->results();
812 std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
813 for (; aResIt != aResults.end(); ++aResIt) {
814 std::string aResName = (*aResIt)->data()->name();
815 myNames[*aResIt] = EntityName(aResName, aResName, false);
816 aResultsWithNameOrColor.push_back(*aResIt);
819 // store just dumped entity to stack
820 myEntitiesStack.push(LastDumpedEntity(theSubFeature, true, aResultsWithNameOrColor));
825 void ModelHighAPI_Dumper::importModule(const std::string& theModuleName)
827 myModules.insert(theModuleName);
830 void ModelHighAPI_Dumper::dumpEntitySetName()
832 const LastDumpedEntity& aLastDumped = myEntitiesStack.top();
833 bool isBufferEmpty = myDumpStorage->isBufferEmpty();
835 // dump "setName" for the entity
836 if (aLastDumped.myUserName) {
837 EntityName& anEntityNames = myNames[aLastDumped.myEntity];
838 if (!anEntityNames.myIsDefault)
839 *myDumpStorage << anEntityNames.myCurrentName << ".setName(\""
840 << anEntityNames.myUserName << "\")\n";
841 // don't dump "setName" for the entity twice
842 anEntityNames.myUserName.clear();
843 anEntityNames.myIsDefault = true;
845 // dump "setName" for results
846 std::list<ResultPtr>::const_iterator aResIt = aLastDumped.myResults.begin();
847 std::list<ResultPtr>::const_iterator aResEnd = aLastDumped.myResults.end();
848 for (; aResIt != aResEnd; ++aResIt) {
850 EntityName& anEntityNames = myNames[*aResIt];
851 if (!anEntityNames.myIsDefault) {
853 *myDumpStorage << ".setName(\"" << anEntityNames.myUserName << "\")\n";
854 // don't dump "setName" for the entity twice
855 anEntityNames.myUserName.clear();
856 anEntityNames.myIsDefault = true;
859 if (!isDefaultColor(*aResIt)) {
860 AttributeIntArrayPtr aColor = (*aResIt)->data()->intArray(ModelAPI_Result::COLOR_ID());
861 if (aColor && aColor->isInitialized()) {
863 *myDumpStorage << ".setColor(" << aColor->value(0) << ", " << aColor->value(1)
864 << ", " << aColor->value(2) << ")\n";
867 // set result deflection
868 if (!isDefaultDeflection(*aResIt)) {
869 AttributeDoublePtr aDeflectionAttr =
870 (*aResIt)->data()->real(ModelAPI_Result::DEFLECTION_ID());
871 if(aDeflectionAttr.get() && aDeflectionAttr->isInitialized()) {
873 *myDumpStorage << ".setDeflection(" << aDeflectionAttr->value() << ")\n";
876 // set result transparency
877 if (!isDefaultTransparency(*aResIt)) {
878 AttributeDoublePtr aTransparencyAttr =
879 (*aResIt)->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
880 if(aTransparencyAttr.get() && aTransparencyAttr->isInitialized()) {
882 *myDumpStorage << ".setTransparency(" << aTransparencyAttr->value() << ")\n";
887 myNames[aLastDumped.myEntity].myIsDumped = true;
888 myEntitiesStack.pop();
890 // clean buffer if it was clear before
892 myDumpStorage->mergeBuffer();
895 bool ModelHighAPI_Dumper::isDumped(const EntityPtr& theEntity) const
897 EntityNameMap::const_iterator aFound = myNames.find(theEntity);
898 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theEntity);
899 return (aFound != myNames.end() && aFound->second.myIsDumped) ||
900 myFeaturesToSkip.find(aFeature) != myFeaturesToSkip.end();
903 bool ModelHighAPI_Dumper::isDumped(const AttributeRefAttrPtr& theRefAttr) const
906 if (theRefAttr->isObject())
907 aFeature = ModelAPI_Feature::feature(theRefAttr->object());
909 aFeature = ModelAPI_Feature::feature(theRefAttr->attr()->owner());
910 return aFeature && isDumped(EntityPtr(aFeature));
913 bool ModelHighAPI_Dumper::isDumped(const AttributeRefListPtr& theRefList) const
915 std::list<ObjectPtr> aRefs = theRefList->list();
916 std::list<ObjectPtr>::iterator anIt = aRefs.begin();
917 for (; anIt != aRefs.end(); ++anIt) {
918 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
919 if (aFeature && !isDumped(EntityPtr(aFeature)))
925 static bool isSketchSub(const FeaturePtr& theFeature)
927 static const std::string SKETCH("Sketch");
928 CompositeFeaturePtr anOwner = ModelAPI_Tools::compositeOwner(theFeature);
929 return anOwner && anOwner->getKind() == SKETCH;
932 bool ModelHighAPI_Dumper::isDefaultColor(const ResultPtr& theResult) const
934 AttributeIntArrayPtr aColor = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
935 if (!aColor || !aColor->isInitialized())
938 // check the result belongs to sketch entity, do not dump color in this way
939 ResultConstructionPtr aResConstr =
940 std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theResult);
942 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult->data()->owner());
943 if (isSketchSub(aFeature))
947 std::string aSection, aName, aDefault;
948 theResult->colorConfigInfo(aSection, aName, aDefault);
950 // dump current color
951 std::ostringstream aColorInfo;
952 aColorInfo << aColor->value(0) << "," << aColor->value(1) << "," << aColor->value(2);
954 return aDefault == aColorInfo.str();
957 bool ModelHighAPI_Dumper::isDefaultDeflection(const ResultPtr& theResult) const
959 AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID());
960 if(!aDeflectionAttr || !aDeflectionAttr->isInitialized()) {
964 double aCurrent = aDeflectionAttr->value();
965 double aDefault = -1;
967 bool isConstruction = false;
968 std::string aResultGroup = theResult->groupName();
969 if (aResultGroup == ModelAPI_ResultConstruction::group())
970 isConstruction = true;
971 else if (aResultGroup == ModelAPI_ResultBody::group()) {
972 GeomShapePtr aGeomShape = theResult->shape();
973 if (aGeomShape.get()) {
974 // if the shape could not be exploded on faces, it contains only wires, edges, and vertices
975 // correction of deviation for them should not influence to the application performance
976 GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE);
977 isConstruction = !anExp.more();
981 aDefault = Config_PropManager::real("Visualization", "construction_deflection");
983 aDefault = Config_PropManager::real("Visualization", "body_deflection");
985 return fabs(aCurrent - aDefault) < 1.e-12;
988 bool ModelHighAPI_Dumper::isDefaultTransparency(const ResultPtr& theResult) const
990 AttributeDoublePtr anAttribute = theResult->data()->real(ModelAPI_Result::TRANSPARENCY_ID());
991 if(!anAttribute || !anAttribute->isInitialized()) {
994 return fabs(anAttribute->value()) < 1.e-12;
997 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char theChar)
999 *myDumpStorage << theChar;
1003 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char* theString)
1005 *myDumpStorage << theString;
1009 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const std::string& theString)
1011 *myDumpStorage << theString;
1015 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const bool theValue)
1017 *myDumpStorage << (theValue ? "True" : "False");
1021 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const int theValue)
1023 *myDumpStorage << theValue;
1027 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const double theValue)
1029 *myDumpStorage << theValue;
1033 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const std::shared_ptr<GeomAPI_Pnt>& thePoint)
1035 importModule("GeomAPI");
1036 *myDumpStorage << "GeomAPI_Pnt(" << thePoint->x() << ", "
1037 << thePoint->y() << ", " << thePoint->z() << ")";
1041 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const std::shared_ptr<GeomAPI_Dir>& theDir)
1043 importModule("GeomAPI");
1044 *myDumpStorage << "GeomAPI_Dir(" << theDir->x() << ", "
1045 << theDir->y() << ", " << theDir->z() << ")";
1049 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1050 const std::shared_ptr<GeomDataAPI_Dir>& theDir)
1052 *myDumpStorage << theDir->x() << ", " << theDir->y() << ", " << theDir->z();
1056 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1057 const std::shared_ptr<GeomDataAPI_Point>& thePoint)
1059 static const int aSize = 3;
1060 double aValues[aSize] = {thePoint->x(), thePoint->y(), thePoint->z()};
1061 std::string aTexts[aSize] = {thePoint->textX(), thePoint->textY(), thePoint->textZ()};
1062 myDumpStorage->dumpArray(aSize, aValues, aTexts);
1066 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1067 const std::shared_ptr<GeomDataAPI_Point2D>& thePoint)
1069 static const int aSize = 2;
1070 double aValues[aSize] = {thePoint->x(), thePoint->y()};
1071 std::string aTexts[aSize] = {thePoint->textX(), thePoint->textY()};
1072 myDumpStorage->dumpArray(aSize, aValues, aTexts);
1076 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1077 const std::shared_ptr<ModelAPI_AttributeBoolean>& theAttrBool)
1079 *myDumpStorage << (theAttrBool->value() ? "True" : "False");
1083 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1084 const std::shared_ptr<ModelAPI_AttributeInteger>& theAttrInt)
1086 std::string aText = theAttrInt->text();
1088 *myDumpStorage << theAttrInt->value();
1090 *myDumpStorage << "\"" << aText << "\"";
1094 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1095 const std::shared_ptr<ModelAPI_AttributeDouble>& theAttrReal)
1097 std::string aText = theAttrReal->text();
1099 *myDumpStorage << theAttrReal->value();
1101 *myDumpStorage << "\"" << aText << "\"";
1105 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1106 const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr)
1108 *myDumpStorage << "\"" << theAttrStr->value() << "\"";
1112 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FolderPtr& theFolder)
1114 *myDumpStorage << name(theFolder);
1116 // add dumped folder to a stack
1117 if (!myNames[theFolder].myIsDumped &&
1118 (myEntitiesStack.empty() || myEntitiesStack.top().myEntity != theFolder))
1119 myEntitiesStack.push(LastDumpedEntity(theFolder, !myNames[theFolder].myIsDefault));
1124 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity)
1126 *myDumpStorage << name(theEntity);
1128 if (!myNames[theEntity].myIsDumped) {
1129 bool isUserDefinedName = !myNames[theEntity].myIsDefault;
1130 // store results if they have user-defined names or colors
1131 std::list<ResultPtr> aResultsWithNameOrColor;
1132 std::list<ResultPtr> allRes;
1133 ModelAPI_Tools::allResults(theEntity, allRes);
1134 for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
1135 if(!myNames[*aRes].myIsDefault || !isDefaultColor(*aRes) ||
1136 !isDefaultDeflection(*aRes) || !isDefaultTransparency(*aRes))
1137 aResultsWithNameOrColor.push_back(*aRes);
1139 // store just dumped entity to stack
1140 if (myEntitiesStack.empty() || myEntitiesStack.top().myEntity != theEntity)
1141 myEntitiesStack.push(
1142 LastDumpedEntity(theEntity, isUserDefinedName, aResultsWithNameOrColor));
1145 // remove entity from the list of not dumped items
1146 myNotDumpedEntities.erase(theEntity);
1150 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ResultPtr& theResult)
1152 // iterate in the structure of sub-results to the parent
1153 ResultPtr aCurRes = theResult;
1154 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
1155 std::list<int> anIndices; // indexes of results in the parent result, starting from topmost
1156 while(aCurRes.get()) {
1157 ResultBodyPtr aParent = ModelAPI_Tools::bodyOwner(aCurRes);
1159 anIndices.push_front(ModelAPI_Tools::bodyIndex(aCurRes));
1160 } else { // index of the result in the feature
1161 std::list<ResultPtr>::const_iterator aRes = aFeature->results().cbegin();
1162 for(int anIndex = 0; aRes != aFeature->results().cend(); aRes++, anIndex++) {
1163 if (*aRes == aCurRes) {
1164 anIndices.push_front(anIndex);
1172 *myDumpStorage << name(aFeature);
1173 for (std::list<int>::iterator anI = anIndices.begin(); anI != anIndices.end(); anI++) {
1174 if (anI == anIndices.begin()) {
1176 *myDumpStorage << ".result()";
1179 *myDumpStorage << ".results()[" << *anI << "]";
1182 *myDumpStorage << ".subResult(" << *anI << ")";
1189 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ObjectPtr& theObject)
1191 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
1192 if(aFeature.get()) {
1193 *myDumpStorage << name(aFeature);
1197 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
1206 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const AttributePtr& theAttr)
1208 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttr->owner());
1210 std::string aWrapperPrefix, aWrapperSuffix;
1211 // Check the attribute belongs to copied (in multi-translation or multi-rotation) feature.
1212 // In this case we need to cast explicitly feature to appropriate type.
1213 AttributeBooleanPtr isCopy = anOwner->boolean("Copy");
1214 if (isCopy.get() && isCopy->value()) {
1215 aWrapperPrefix = featureWrapper(anOwner) + "(";
1216 aWrapperSuffix = ")";
1217 importModule("SketchAPI");
1220 *myDumpStorage << aWrapperPrefix << name(anOwner) << aWrapperSuffix
1221 << "." << attributeGetter(anOwner, theAttr->id()) << "()";
1225 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1226 const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr)
1228 if (theRefAttr->isObject())
1229 *this << theRefAttr->object();
1231 *this << theRefAttr->attr();
1235 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1236 const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList)
1238 *myDumpStorage << "[";
1239 std::list<std::pair<ObjectPtr, AttributePtr> > aList = theRefAttrList->list();
1240 bool isAdded = false;
1241 std::list<std::pair<ObjectPtr, AttributePtr> >::const_iterator anIt = aList.begin();
1242 for (; anIt != aList.end(); ++anIt) {
1244 *myDumpStorage << ", ";
1248 *this << anIt->first;
1249 else if (anIt->second)
1250 * this << anIt->second;
1252 *myDumpStorage << "]";
1256 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1257 const std::shared_ptr<ModelAPI_AttributeReference>& theReference)
1259 *this << theReference->value();
1263 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1264 const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList)
1266 static const int aThreshold = 2;
1267 static bool aDumpAsIs = false;
1268 // if number of elements in the list if greater than a threshold,
1269 // dump it in a separate line with specific name
1270 if (aDumpAsIs || theRefList->size() <= aThreshold) {
1271 *myDumpStorage << "[";
1272 std::list<ObjectPtr> aList = theRefList->list();
1273 bool isAdded = false;
1274 std::list<ObjectPtr>::const_iterator anIt = aList.begin();
1275 for (; anIt != aList.end(); ++anIt) {
1277 *myDumpStorage << ", ";
1283 *myDumpStorage << "]";
1286 FeaturePtr anOwner = ModelAPI_Feature::feature(theRefList->owner());
1287 std::string aListName = name(anOwner) + "_objects";
1288 // reserve dumped buffer and store list "as is"
1289 myDumpStorage->reserveBuffer();
1291 *this << aListName << " = " << theRefList << "\n";
1293 // append reserved data to the end of the current buffer
1294 myDumpStorage->restoreReservedBuffer();
1295 *myDumpStorage << aListName;
1300 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1301 const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect)
1303 myDumpStorage->write(theAttrSelect);
1307 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1308 const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList)
1310 static const int aThreshold = 2;
1311 static bool aDumpAsIs = false;
1312 // if number of elements in the list if greater than a threshold,
1313 // dump it in a separate line with specific name
1314 if (aDumpAsIs || theAttrSelList->size() <= aThreshold) {
1315 *myDumpStorage << "[";
1317 GeomShapePtr aShape;
1318 std::string aShapeTypeStr;
1320 bool isAdded = false;
1322 for(int anIndex = 0; anIndex < theAttrSelList->size(); ++anIndex) {
1323 AttributeSelectionPtr anAttribute = theAttrSelList->value(anIndex);
1324 aShape = anAttribute->value();
1326 ResultPtr aContext = anAttribute->context();
1328 aShape = aContext->shape();
1336 *myDumpStorage << ", ";
1340 *this << anAttribute;
1343 *myDumpStorage << "]";
1345 // obtain name of list (the feature may contain several selection lists)
1346 FeaturePtr anOwner = ModelAPI_Feature::feature(theAttrSelList->owner());
1347 std::string aListName = name(anOwner) + "_objects";
1348 std::list<AttributePtr> aSelLists =
1349 anOwner->data()->attributes(ModelAPI_AttributeSelectionList::typeId());
1350 if (aSelLists.size() > 1) {
1352 for (std::list<AttributePtr>::iterator aSIt = aSelLists.begin();
1353 aSIt != aSelLists.end(); ++aSIt, ++anIndex)
1354 if ((*aSIt).get() == theAttrSelList.get())
1356 std::ostringstream aSStream;
1357 aSStream << aListName << "_" << anIndex;
1358 aListName = aSStream.str();
1360 // reserve dumped buffer and store list "as is"
1361 myDumpStorage->reserveBuffer();
1363 *this << aListName << " = " << theAttrSelList << "\n";
1365 // append reserved data to the end of the current buffer
1366 myDumpStorage->restoreReservedBuffer();
1367 *myDumpStorage << aListName;
1372 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
1373 const std::shared_ptr<ModelAPI_AttributeStringArray>& theArray)
1375 std::ostringstream aBuffer;
1377 for(int anIndex = 0; anIndex < theArray->size(); ++anIndex) {
1381 aBuffer << "\"" << theArray->value(anIndex) << "\"";
1385 myDumpStorage->write(aBuffer.str());
1390 ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
1391 std::basic_ostream<char>& (*theEndl)(std::basic_ostream<char>&))
1393 *theDumper.myDumpStorage << theEndl;
1395 if (!theDumper.myEntitiesStack.empty()) {
1397 // all copies have been stored into stack, pop them all
1400 // Name for composite feature is dumped when all sub-entities are dumped
1401 // (see method ModelHighAPI_Dumper::processSubs).
1402 const ModelHighAPI_Dumper::LastDumpedEntity& aLastDumped = theDumper.myEntitiesStack.top();
1403 CompositeFeaturePtr aComposite =
1404 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aLastDumped.myEntity);
1406 theDumper.dumpEntitySetName();
1407 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aLastDumped.myEntity);
1409 AttributeBooleanPtr aCopyAttr = aFeature->boolean("Copy");
1410 isCopy = aCopyAttr.get() && aCopyAttr->value();
1413 } while (isCopy && !theDumper.myEntitiesStack.empty());
1416 // store all not-dumped entities first
1417 std::set<EntityPtr> aNotDumped = theDumper.myNotDumpedEntities;
1418 theDumper.myDumpStorage->reserveBuffer();
1419 std::set<EntityPtr>::const_iterator anIt = aNotDumped.begin();
1420 for (; anIt != aNotDumped.end(); ++anIt) {
1421 // if the feature is composite, dump it with all subs
1422 CompositeFeaturePtr aCompFeat =
1423 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*anIt);
1425 theDumper.process(aCompFeat, true);
1427 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
1428 theDumper.dumpFeature(aFeature, true);
1429 // dump the Projection feature which produces this "Copy" entity
1430 AttributeBooleanPtr aCopyAttr = aFeature->boolean("Copy");
1431 if (aCopyAttr.get() && aCopyAttr->value())
1433 const std::set<AttributePtr>& aRefs = aFeature->data()->refsToMe();
1434 std::set<AttributePtr>::iterator aRefIt = aRefs.begin();
1435 for (; aRefIt != aRefs.end(); ++aRefIt)
1436 if ((*aRefIt)->id() == "ProjectedFeature")
1437 { // process projection only
1438 FeaturePtr anOwner = ModelAPI_Feature::feature((*aRefIt)->owner());
1439 if (anOwner && !theDumper.isDumped(EntityPtr(anOwner)))
1440 theDumper.dumpFeature(anOwner, true);
1446 // then store the reserved data
1447 theDumper.myDumpStorage->restoreReservedBuffer();
1448 theDumper.myDumpStorage->mergeBuffer();
1450 // now, store all postponed features
1451 theDumper.dumpPostponed();