From: azv Date: Tue, 23 Aug 2016 14:19:44 +0000 (+0300) Subject: Allow dumper to set empty user-defined name for features X-Git-Tag: V_2.5.0~137^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=268de14fe8b857dd33fafb349386be6e3fb4caf5;p=modules%2Fshaper.git Allow dumper to set empty user-defined name for features --- diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 5ec70a34b..fe2875f8c 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -88,10 +88,11 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, { EntityNameMap::const_iterator aFound = myNames.find(theEntity); if (aFound != myNames.end()) - return aFound->second.first; + return aFound->second.myCurrentName; // entity is not found, store it std::string aName; + bool isDefaultName = false; std::ostringstream aDefaultName; FeaturePtr aFeature = std::dynamic_pointer_cast(theEntity); if (aFeature) { @@ -111,6 +112,7 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, if (aNbFeatures == anId) { // name is not user-defined aName.clear(); + isDefaultName = true; } } @@ -129,7 +131,7 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, } } - myNames[theEntity] = std::pair(aDefaultName.str(), aName); + myNames[theEntity] = EntityName(aDefaultName.str(), aName, isDefaultName); if (theSaveNotDumped) myNotDumpedEntities.insert(theEntity); @@ -137,7 +139,7 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, if (aFeature) saveResultNames(aFeature); - return myNames[theEntity].first; + return myNames[theEntity].myCurrentName; } const std::string& ModelHighAPI_Dumper::parentName(const FeaturePtr& theEntity) @@ -157,7 +159,7 @@ const std::string& ModelHighAPI_Dumper::parentName(const FeaturePtr& theEntity) void ModelHighAPI_Dumper::saveResultNames(const FeaturePtr& theFeature) { - const std::string& aFeatureName = myNames[theFeature].first; + const std::string& aFeatureName = myNames[theFeature].myCurrentName; const std::list& aResults = theFeature->results(); std::list::const_iterator aResIt = aResults.begin(); for (int i = 1; aResIt != aResults.end(); ++aResIt, ++i) { @@ -174,8 +176,8 @@ void ModelHighAPI_Dumper::saveResultNames(const FeaturePtr& theFeature) } } - myNames[*aResIt] = std::pair(aResName, - isUserDefined ? aResName : std::string()); + myNames[*aResIt] = EntityName(aResName, + (isUserDefined ? aResName : std::string()), !isUserDefined); } } @@ -184,7 +186,7 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr& theD { // dump top level document feature static const std::string aDocName("partSet"); - myNames[theDoc] = std::pair(aDocName, std::string()); + myNames[theDoc] = EntityName(aDocName, std::string(), true); *this << aDocName << " = model.moduleDocument()" << std::endl; // dump subfeatures and store result to file @@ -231,9 +233,9 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr(aDocName, std::string()); + myNames[aSubDoc] = EntityName(aDocName, std::string(), true); // dump document in a separate line *this << aDocName << " = " << aPartName << ".document()" << std::endl; @@ -290,7 +292,7 @@ void ModelHighAPI_Dumper::dumpSubFeatureNameAndColor(const std::string theSubFea const FeaturePtr& theSubFeature) { name(theSubFeature, false); - myNames[theSubFeature] = std::pair(theSubFeatureGet, theSubFeature->name()); + myNames[theSubFeature] = EntityName(theSubFeatureGet, theSubFeature->name(), false); // store results if they have user-defined names or colors std::list aResultsWithNameOrColor; @@ -298,7 +300,7 @@ void ModelHighAPI_Dumper::dumpSubFeatureNameAndColor(const std::string theSubFea std::list::const_iterator aResIt = aResults.begin(); for (; aResIt != aResults.end(); ++aResIt) { std::string aResName = (*aResIt)->data()->name(); - myNames[*aResIt] = std::pair(aResName, aResName); + myNames[*aResIt] = EntityName(aResName, aResName, false); aResultsWithNameOrColor.push_back(*aResIt); } @@ -362,21 +364,26 @@ void ModelHighAPI_Dumper::dumpEntitySetName() // dump "setName" for the entity if (aLastDumped.myUserName) { - std::pair anEntityNames = myNames[aLastDumped.myEntity]; - if (!anEntityNames.second.empty()) - myDumpBuffer << anEntityNames.first << ".setName(\"" << anEntityNames.second << "\")" << std::endl; - anEntityNames.second.clear(); // don't dump "setName" for the entity twice + EntityName& anEntityNames = myNames[aLastDumped.myEntity]; + if (!anEntityNames.myIsDefault) + myDumpBuffer << anEntityNames.myCurrentName << ".setName(\"" + << anEntityNames.myUserName << "\")" << std::endl; + // don't dump "setName" for the entity twice + anEntityNames.myUserName.clear(); + anEntityNames.myIsDefault = true; } // dump "setName" for results std::list::const_iterator aResIt = aLastDumped.myResults.begin(); std::list::const_iterator aResEnd = aLastDumped.myResults.end(); for (; aResIt != aResEnd; ++aResIt) { // set result name - std::pair anEntityNames = myNames[*aResIt]; - if (!anEntityNames.second.empty()) { + EntityName& anEntityNames = myNames[*aResIt]; + if (!anEntityNames.myIsDefault) { *this << *aResIt; - myDumpBuffer << ".setName(\"" << anEntityNames.second << "\")" << std::endl; - anEntityNames.second.clear(); // don't dump "setName" for the entity twice + myDumpBuffer << ".setName(\"" << anEntityNames.myUserName << "\")" << std::endl; + // don't dump "setName" for the entity twice + anEntityNames.myUserName.clear(); + anEntityNames.myIsDefault = true; } // set result color if (!isDefaultColor(*aResIt)) { @@ -546,13 +553,13 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity { myDumpBuffer << name(theEntity); - bool isUserDefinedName = !myNames[theEntity].second.empty(); + bool isUserDefinedName = !myNames[theEntity].myIsDefault; // store results if they have user-defined names or colors std::list aResultsWithNameOrColor; const std::list& aResults = theEntity->results(); std::list::const_iterator aResIt = aResults.begin(); for (; aResIt != aResults.end(); ++aResIt) - if (!myNames[*aResIt].second.empty() || !isDefaultColor(*aResIt)) + if (!myNames[*aResIt].myIsDefault || !isDefaultColor(*aResIt)) aResultsWithNameOrColor.push_back(*aResIt); // store just dumped entity to stack myEntitiesStack.push(LastDumpedEntity(theEntity, isUserDefinedName, aResultsWithNameOrColor)); diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 5231ffe73..026f955c0 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -244,9 +244,21 @@ private: bool isDefaultColor(const ResultPtr& theResult) const; private: - typedef std::map > EntityNameMap; - typedef std::map > ModulesMap; - typedef std::map > NbFeaturesMap; + struct EntityName { + std::string myCurrentName; ///< default name of current feature + std::string myUserName; ///< user-defined name + bool myIsDefault; ///< \c true if the name is default + + EntityName() {} + + EntityName(const std::string& theCurName, const std::string& theUserName, bool theDefault) + : myCurrentName(theCurName), myUserName(theUserName), myIsDefault(theDefault) + {} + }; + + typedef std::map EntityNameMap; + typedef std::map > ModulesMap; + typedef std::map > NbFeaturesMap; struct LastDumpedEntity { EntityPtr myEntity; ///< last dumped entity