From: azv Date: Mon, 18 Nov 2019 13:08:15 +0000 (+0300) Subject: Fix incorrect naming of features and results when import (same name of feature and... X-Git-Tag: V9_5_0a1~166^2~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=69192b1ac7fbfedef36d95068a9407581fd87ea2;p=modules%2Fshaper.git Fix incorrect naming of features and results when import (same name of feature and its result has be supported). Avoid using temporary file storage in tests. --- diff --git a/src/ExchangePlugin/ExchangePlugin_ImportPart.cpp b/src/ExchangePlugin/ExchangePlugin_ImportPart.cpp index 5c2a9a3dd..14f2c1951 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportPart.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportPart.cpp @@ -78,6 +78,8 @@ void ExchangePlugin_ImportPart::execute() // ================================ Auxiliary functions =================================== +typedef std::map > > ObjectNameMap; + bool splitName(std::string& theName, int& theIndex) { size_t aLastUndercore = theName.find_last_of('_'); @@ -93,13 +95,13 @@ bool splitName(std::string& theName, int& theIndex) return isOk; } -void addIndexedName(const std::string& theName, - std::map >& theIndexedNames) +void addIndexedName(const ObjectPtr& theObject, ObjectNameMap& theIndexedNames) { - std::string aName = theName; + std::string aName = theObject->data()->name(); + std::string aGroup = theObject->groupName(); int anIndex = 0; bool isIndexed = splitName(aName, anIndex); - std::set& anIndices = theIndexedNames[aName]; + std::set& anIndices = theIndexedNames[aGroup][aName]; if (isIndexed) anIndices.insert(anIndex); } @@ -110,7 +112,7 @@ void addIndexedName(const std::string& theName, // 'Point_1', 'Point_2' => {'Point', [1, 2]}. // Thus, the new point should have index 3 and therefore the name 'Point_3'. static void collectOldNames(DocumentPtr theDocument, std::list& theAvoided, - std::map >& theIndexedNames) + ObjectNameMap& theIndexedNames) { std::list anAllFeatures = theDocument->allFeatures(); std::list::iterator aFIt = anAllFeatures.begin(); @@ -123,26 +125,36 @@ static void collectOldNames(DocumentPtr theDocument, std::list& theA } // store name of feature - addIndexedName((*aFIt)->data()->name(), theIndexedNames); + addIndexedName(*aFIt, theIndexedNames); // store names of results const std::list& aResults = (*aFIt)->results(); for (std::list::const_iterator aRIt = aResults.begin(); aRIt != aResults.end(); ++aRIt) - addIndexedName((*aRIt)->data()->name(), theIndexedNames); + addIndexedName(*aRIt, theIndexedNames); } } -static std::string uniqueName(const std::string& theName, - std::map >& theExistingNames) +static std::string uniqueName(const ObjectPtr& theObject, ObjectNameMap& theExistingNames) { - std::string aName = theName; + std::string aName = theObject->data()->name(); + std::string aGroup = theObject->groupName(); int anIndex = 1; splitName(aName, anIndex); - std::map >::iterator aFound = theExistingNames.find(aName); - bool isUnique = false; - if (aFound == theExistingNames.end()) - isUnique = true; + ObjectNameMap::iterator aFoundGroup = theExistingNames.find(aGroup); + bool isUnique = aFoundGroup == theExistingNames.end(); + + std::map >::iterator aFound; + if (!isUnique) { + aFound = aFoundGroup->second.find(aName); + isUnique = aFound == aFoundGroup->second.end(); + } + + if (isUnique) { + // name is unique + aName = theObject->data()->name(); + addIndexedName(theObject, theExistingNames); + } else { // search the appropriate index std::set::iterator aFoundIndex = aFound->second.find(anIndex); @@ -157,29 +169,24 @@ static std::string uniqueName(const std::string& theName, aFound->second.insert(anIndex); } - if (isUnique) { - // name is unique - aName = theName; - addIndexedName(theName, theExistingNames); - } return aName; } void correntNonUniqueNames(DocumentPtr theDocument, std::list& theImported) { - std::map > aNames; + ObjectNameMap aNames; collectOldNames(theDocument, theImported, aNames); for (std::list::iterator anIt = theImported.begin(); anIt != theImported.end(); ++anIt) { // update name of feature - std::string aNewName = uniqueName((*anIt)->data()->name(), aNames); + std::string aNewName = uniqueName(*anIt, aNames); (*anIt)->data()->setName(aNewName); // update names of results const std::list& aResults = (*anIt)->results(); for (std::list::const_iterator aRIt = aResults.begin(); aRIt != aResults.end(); ++aRIt) { - aNewName = uniqueName((*aRIt)->data()->name(), aNames); + aNewName = uniqueName(*aRIt, aNames); (*aRIt)->data()->setName(aNewName); } } diff --git a/src/ExchangePlugin/Test/TestExportPart_Failure_1.py b/src/ExchangePlugin/Test/TestExportPart_Failure_1.py index 399ca21b9..65ce8669b 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Failure_1.py +++ b/src/ExchangePlugin/Test/TestExportPart_Failure_1.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) model.begin() diff --git a/src/ExchangePlugin/Test/TestExportPart_Failure_2.py b/src/ExchangePlugin/Test/TestExportPart_Failure_2.py index 0f11b3831..ceca5f167 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Failure_2.py +++ b/src/ExchangePlugin/Test/TestExportPart_Failure_2.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Box_1 diff --git a/src/ExchangePlugin/Test/TestExportPart_Failure_3.py b/src/ExchangePlugin/Test/TestExportPart_Failure_3.py index b5fc215df..8f3e46703 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Failure_3.py +++ b/src/ExchangePlugin/Test/TestExportPart_Failure_3.py @@ -31,7 +31,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) model.begin() diff --git a/src/ExchangePlugin/Test/TestExportPart_FullPartSet.py b/src/ExchangePlugin/Test/TestExportPart_FullPartSet.py index e42df1e89..5e5f8acf3 100644 --- a/src/ExchangePlugin/Test/TestExportPart_FullPartSet.py +++ b/src/ExchangePlugin/Test/TestExportPart_FullPartSet.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) model.begin() diff --git a/src/ExchangePlugin/Test/TestExportPart_FullPart_1.py b/src/ExchangePlugin/Test/TestExportPart_FullPart_1.py index ae5a2f3f8..e0eeee3f0 100644 --- a/src/ExchangePlugin/Test/TestExportPart_FullPart_1.py +++ b/src/ExchangePlugin/Test/TestExportPart_FullPart_1.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) model.begin() diff --git a/src/ExchangePlugin/Test/TestExportPart_FullPart_2.py b/src/ExchangePlugin/Test/TestExportPart_FullPart_2.py index 29db8702f..6b741abbc 100644 --- a/src/ExchangePlugin/Test/TestExportPart_FullPart_2.py +++ b/src/ExchangePlugin/Test/TestExportPart_FullPart_2.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) model.begin() diff --git a/src/ExchangePlugin/Test/TestExportPart_PartSet.py b/src/ExchangePlugin/Test/TestExportPart_PartSet.py index 1031a7949..3c8b14257 100644 --- a/src/ExchangePlugin/Test/TestExportPart_PartSet.py +++ b/src/ExchangePlugin/Test/TestExportPart_PartSet.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) model.begin() diff --git a/src/ExchangePlugin/Test/TestExportPart_Results_1.py b/src/ExchangePlugin/Test/TestExportPart_Results_1.py index 002c09a39..6c4266ed7 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Results_1.py +++ b/src/ExchangePlugin/Test/TestExportPart_Results_1.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Point_2 diff --git a/src/ExchangePlugin/Test/TestExportPart_Results_2.py b/src/ExchangePlugin/Test/TestExportPart_Results_2.py index 590da1f22..f2c9ac63e 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Results_2.py +++ b/src/ExchangePlugin/Test/TestExportPart_Results_2.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Axis_4 diff --git a/src/ExchangePlugin/Test/TestExportPart_Results_3.py b/src/ExchangePlugin/Test/TestExportPart_Results_3.py index 1dddcb26d..0b723a231 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Results_3.py +++ b/src/ExchangePlugin/Test/TestExportPart_Results_3.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Sketch_1 diff --git a/src/ExchangePlugin/Test/TestExportPart_Results_4.py b/src/ExchangePlugin/Test/TestExportPart_Results_4.py index 63ffb4312..a02183e98 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Results_4.py +++ b/src/ExchangePlugin/Test/TestExportPart_Results_4.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Extrusion_1 diff --git a/src/ExchangePlugin/Test/TestExportPart_Results_5.py b/src/ExchangePlugin/Test/TestExportPart_Results_5.py index 7d1929264..b3753edc2 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Results_5.py +++ b/src/ExchangePlugin/Test/TestExportPart_Results_5.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Sketch_2 diff --git a/src/ExchangePlugin/Test/TestExportPart_Results_6.py b/src/ExchangePlugin/Test/TestExportPart_Results_6.py index b4ca20e34..0afd739af 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Results_6.py +++ b/src/ExchangePlugin/Test/TestExportPart_Results_6.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Revolution_1 diff --git a/src/ExchangePlugin/Test/TestExportPart_Results_7.py b/src/ExchangePlugin/Test/TestExportPart_Results_7.py index 5d8e9cb37..6dc1b76e7 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Results_7.py +++ b/src/ExchangePlugin/Test/TestExportPart_Results_7.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Box_1 diff --git a/src/ExchangePlugin/Test/TestExportPart_Results_8.py b/src/ExchangePlugin/Test/TestExportPart_Results_8.py index 7381f5e0f..1a0358515 100644 --- a/src/ExchangePlugin/Test/TestExportPart_Results_8.py +++ b/src/ExchangePlugin/Test/TestExportPart_Results_8.py @@ -63,7 +63,7 @@ model.end() import os -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Translation_1 diff --git a/src/ExchangePlugin/Test/TestImportPart_AfterCurrent_1.py b/src/ExchangePlugin/Test/TestImportPart_AfterCurrent_1.py index e633e8834..0d104a8b0 100644 --- a/src/ExchangePlugin/Test/TestImportPart_AfterCurrent_1.py +++ b/src/ExchangePlugin/Test/TestImportPart_AfterCurrent_1.py @@ -34,7 +34,7 @@ Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/YOZ"), mod model.do() model.end() -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # store the reference data diff --git a/src/ExchangePlugin/Test/TestImportPart_AfterCurrent_2.py b/src/ExchangePlugin/Test/TestImportPart_AfterCurrent_2.py index e96927228..3f75cb3d9 100644 --- a/src/ExchangePlugin/Test/TestImportPart_AfterCurrent_2.py +++ b/src/ExchangePlugin/Test/TestImportPart_AfterCurrent_2.py @@ -34,7 +34,7 @@ Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/YOZ"), mod model.do() model.end() -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # store the reference data diff --git a/src/ExchangePlugin/Test/TestImportPart_AfterLast_1.py b/src/ExchangePlugin/Test/TestImportPart_AfterLast_1.py index 113e738bf..dd465a4db 100644 --- a/src/ExchangePlugin/Test/TestImportPart_AfterLast_1.py +++ b/src/ExchangePlugin/Test/TestImportPart_AfterLast_1.py @@ -64,7 +64,7 @@ model.do() model.end() -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # store the reference data diff --git a/src/ExchangePlugin/Test/TestImportPart_AfterLast_2.py b/src/ExchangePlugin/Test/TestImportPart_AfterLast_2.py index 7b89ef1b8..218612e6c 100644 --- a/src/ExchangePlugin/Test/TestImportPart_AfterLast_2.py +++ b/src/ExchangePlugin/Test/TestImportPart_AfterLast_2.py @@ -65,7 +65,7 @@ model.do() model.end() -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Sketch_1 diff --git a/src/ExchangePlugin/Test/TestImportPart_AfterLast_3.py b/src/ExchangePlugin/Test/TestImportPart_AfterLast_3.py index 0f5074871..f3f4c105a 100644 --- a/src/ExchangePlugin/Test/TestImportPart_AfterLast_3.py +++ b/src/ExchangePlugin/Test/TestImportPart_AfterLast_3.py @@ -64,7 +64,7 @@ model.do() model.end() -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Box_1 diff --git a/src/ExchangePlugin/Test/TestImportPart_AfterLast_4.py b/src/ExchangePlugin/Test/TestImportPart_AfterLast_4.py index 2dc22241e..211673332 100644 --- a/src/ExchangePlugin/Test/TestImportPart_AfterLast_4.py +++ b/src/ExchangePlugin/Test/TestImportPart_AfterLast_4.py @@ -64,7 +64,7 @@ model.do() model.end() -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) featureToExport = Translation_1 diff --git a/src/ExchangePlugin/Test/TestImportPart_AfterLast_5.py b/src/ExchangePlugin/Test/TestImportPart_AfterLast_5.py index 294f48589..1ad3b03c9 100644 --- a/src/ExchangePlugin/Test/TestImportPart_AfterLast_5.py +++ b/src/ExchangePlugin/Test/TestImportPart_AfterLast_5.py @@ -65,7 +65,7 @@ model.do() model.end() -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # store the reference data diff --git a/src/ExchangePlugin/Test/TestImportPart_AfterLast_6.py b/src/ExchangePlugin/Test/TestImportPart_AfterLast_6.py index f812d071f..58dac780e 100644 --- a/src/ExchangePlugin/Test/TestImportPart_AfterLast_6.py +++ b/src/ExchangePlugin/Test/TestImportPart_AfterLast_6.py @@ -65,7 +65,7 @@ model.do() model.end() -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # store the reference data diff --git a/src/ExchangePlugin/Test/TestImportPart_Construction_1.py b/src/ExchangePlugin/Test/TestImportPart_Construction_1.py index 17b64d1b4..45b0529b6 100644 --- a/src/ExchangePlugin/Test/TestImportPart_Construction_1.py +++ b/src/ExchangePlugin/Test/TestImportPart_Construction_1.py @@ -49,7 +49,7 @@ for feat in features: res.append(GeomAlgoAPI_ShapeTools.volume(r.shape())) refData.append( (feat.getKind(), res) ) -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # emport the document diff --git a/src/ExchangePlugin/Test/TestImportPart_Construction_2.py b/src/ExchangePlugin/Test/TestImportPart_Construction_2.py index 5ece48cc8..bf0db67cd 100644 --- a/src/ExchangePlugin/Test/TestImportPart_Construction_2.py +++ b/src/ExchangePlugin/Test/TestImportPart_Construction_2.py @@ -51,7 +51,7 @@ for feat in features: res.append(GeomAlgoAPI_ShapeTools.volume(r.shape())) refData.append( (feat.getKind(), res) ) -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # emport the document diff --git a/src/ExchangePlugin/Test/TestImportPart_Construction_3.py b/src/ExchangePlugin/Test/TestImportPart_Construction_3.py index a9e1236ab..5a84bd996 100644 --- a/src/ExchangePlugin/Test/TestImportPart_Construction_3.py +++ b/src/ExchangePlugin/Test/TestImportPart_Construction_3.py @@ -51,7 +51,7 @@ for feat in features: res.append(GeomAlgoAPI_ShapeTools.volume(r.shape())) refData.append( (feat.getKind(), res) ) -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # emport the document diff --git a/src/ExchangePlugin/Test/TestImportPart_Construction_4.py b/src/ExchangePlugin/Test/TestImportPart_Construction_4.py index 441ae9a3f..ae3fa13c9 100644 --- a/src/ExchangePlugin/Test/TestImportPart_Construction_4.py +++ b/src/ExchangePlugin/Test/TestImportPart_Construction_4.py @@ -51,7 +51,7 @@ for feat in features: res.append(GeomAlgoAPI_ShapeTools.volume(r.shape())) refData.append( (feat.getKind(), res) ) -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # emport the document diff --git a/src/ExchangePlugin/Test/TestImportPart_Multiple.py b/src/ExchangePlugin/Test/TestImportPart_Multiple.py index 9d3ad6218..7fdbc7e7a 100644 --- a/src/ExchangePlugin/Test/TestImportPart_Multiple.py +++ b/src/ExchangePlugin/Test/TestImportPart_Multiple.py @@ -36,7 +36,7 @@ Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/YOZ"), mod model.do() model.end() -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # export all features from Part_1 diff --git a/src/ExchangePlugin/Test/TestImportPart_ToEmptyPart.py b/src/ExchangePlugin/Test/TestImportPart_ToEmptyPart.py index fd665598a..2df724910 100644 --- a/src/ExchangePlugin/Test/TestImportPart_ToEmptyPart.py +++ b/src/ExchangePlugin/Test/TestImportPart_ToEmptyPart.py @@ -67,7 +67,7 @@ for feat in features: res.append(GeomAlgoAPI_ShapeTools.volume(r.shape())) refData.append( (feat.getKind(), res) ) -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # emport the document diff --git a/src/ExchangePlugin/Test/TestImportPart_ToEmptyPartSet.py b/src/ExchangePlugin/Test/TestImportPart_ToEmptyPartSet.py index 670f11adf..0f0fee841 100644 --- a/src/ExchangePlugin/Test/TestImportPart_ToEmptyPartSet.py +++ b/src/ExchangePlugin/Test/TestImportPart_ToEmptyPartSet.py @@ -67,7 +67,7 @@ for feat in features: res.append(GeomAlgoAPI_ShapeTools.volume(r.shape())) refData.append( (feat.getKind(), res) ) -filename = model.tempFileName() +filename = 'check_export.shaperpart' model.removeFile(filename) # emport the document diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 216acecd7..2e01c4d9d 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -437,7 +437,7 @@ static bool saveDocument(Handle(Model_Application) theApp, aPathToFile.SetName(""); aPathToFile.SetExtension(""); OSD_Directory aBaseDir(aPathToFile); - if (!aBaseDir.Exists()) + if (aPathToFile.TrekLength() != 0 && !aBaseDir.Exists()) aBaseDir.Build(OSD_Protection()); // save the document aStatus = theApp->SaveAs(theDoc, theFilename); diff --git a/src/PythonAPI/model/exchange/tools.py b/src/PythonAPI/model/exchange/tools.py index f6b9c6a71..a80db1b29 100644 --- a/src/PythonAPI/model/exchange/tools.py +++ b/src/PythonAPI/model/exchange/tools.py @@ -18,12 +18,6 @@ # import os -import tempfile - -# Generate temporary file name -def tempFileName(): - tempDir = tempfile.TemporaryDirectory() - return os.path.join(tempDir.name, "temp.shaperpart") def removeFile(theFilename): try: os.remove(theFilename)