Salome HOME
Fix incorrect naming of features and results when import (same name of feature and...
authorazv <azv@opencascade.com>
Mon, 18 Nov 2019 13:08:15 +0000 (16:08 +0300)
committerazv <azv@opencascade.com>
Mon, 18 Nov 2019 13:08:15 +0000 (16:08 +0300)
Avoid using temporary file storage in tests.

33 files changed:
src/ExchangePlugin/ExchangePlugin_ImportPart.cpp
src/ExchangePlugin/Test/TestExportPart_Failure_1.py
src/ExchangePlugin/Test/TestExportPart_Failure_2.py
src/ExchangePlugin/Test/TestExportPart_Failure_3.py
src/ExchangePlugin/Test/TestExportPart_FullPartSet.py
src/ExchangePlugin/Test/TestExportPart_FullPart_1.py
src/ExchangePlugin/Test/TestExportPart_FullPart_2.py
src/ExchangePlugin/Test/TestExportPart_PartSet.py
src/ExchangePlugin/Test/TestExportPart_Results_1.py
src/ExchangePlugin/Test/TestExportPart_Results_2.py
src/ExchangePlugin/Test/TestExportPart_Results_3.py
src/ExchangePlugin/Test/TestExportPart_Results_4.py
src/ExchangePlugin/Test/TestExportPart_Results_5.py
src/ExchangePlugin/Test/TestExportPart_Results_6.py
src/ExchangePlugin/Test/TestExportPart_Results_7.py
src/ExchangePlugin/Test/TestExportPart_Results_8.py
src/ExchangePlugin/Test/TestImportPart_AfterCurrent_1.py
src/ExchangePlugin/Test/TestImportPart_AfterCurrent_2.py
src/ExchangePlugin/Test/TestImportPart_AfterLast_1.py
src/ExchangePlugin/Test/TestImportPart_AfterLast_2.py
src/ExchangePlugin/Test/TestImportPart_AfterLast_3.py
src/ExchangePlugin/Test/TestImportPart_AfterLast_4.py
src/ExchangePlugin/Test/TestImportPart_AfterLast_5.py
src/ExchangePlugin/Test/TestImportPart_AfterLast_6.py
src/ExchangePlugin/Test/TestImportPart_Construction_1.py
src/ExchangePlugin/Test/TestImportPart_Construction_2.py
src/ExchangePlugin/Test/TestImportPart_Construction_3.py
src/ExchangePlugin/Test/TestImportPart_Construction_4.py
src/ExchangePlugin/Test/TestImportPart_Multiple.py
src/ExchangePlugin/Test/TestImportPart_ToEmptyPart.py
src/ExchangePlugin/Test/TestImportPart_ToEmptyPartSet.py
src/Model/Model_Document.cpp
src/PythonAPI/model/exchange/tools.py

index 5c2a9a3dd8986ae3f402b047212844c58e945a34..14f2c19511c78055003704b03e867956885461a7 100644 (file)
@@ -78,6 +78,8 @@ void ExchangePlugin_ImportPart::execute()
 
 // ================================     Auxiliary functions     ===================================
 
+typedef std::map<std::string, std::map<std::string, std::set<int> > > 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<std::string, std::set<int> >& 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<int>& anIndices = theIndexedNames[aName];
+  std::set<int>& 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<FeaturePtr>& theAvoided,
-                            std::map<std::string, std::set<int> >& theIndexedNames)
+                            ObjectNameMap& theIndexedNames)
 {
   std::list<FeaturePtr> anAllFeatures = theDocument->allFeatures();
   std::list<FeaturePtr>::iterator aFIt = anAllFeatures.begin();
@@ -123,26 +125,36 @@ static void collectOldNames(DocumentPtr theDocument, std::list<FeaturePtr>& theA
     }
 
     // store name of feature
-    addIndexedName((*aFIt)->data()->name(), theIndexedNames);
+    addIndexedName(*aFIt, theIndexedNames);
     // store names of results
     const std::list<ResultPtr>& aResults = (*aFIt)->results();
     for (std::list<ResultPtr>::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<std::string, std::set<int> >& 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<std::string, std::set<int> >::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<std::string, std::set<int> >::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<int>::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<FeaturePtr>& theImported)
 {
-  std::map<std::string, std::set<int> > aNames;
+  ObjectNameMap aNames;
   collectOldNames(theDocument, theImported, aNames);
 
   for (std::list<FeaturePtr>::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<ResultPtr>& aResults = (*anIt)->results();
     for (std::list<ResultPtr>::const_iterator aRIt = aResults.begin();
          aRIt != aResults.end(); ++aRIt) {
-      aNewName = uniqueName((*aRIt)->data()->name(), aNames);
+      aNewName = uniqueName(*aRIt, aNames);
       (*aRIt)->data()->setName(aNewName);
     }
   }
index 399ca21b9ba292cce879f18295bb35ce8e44044e..65ce8669bc28b2f3fab4a5b47ff6af4cd3e85c4f 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 model.begin()
index 0f11b3831d40301eefde285014926b2c27335768..ceca5f167e8d778eb92e0b6b8cf46782d7eaee08 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Box_1
index b5fc215dfac8d6e008183c5f74f43ae4d6232421..8f3e46703301dfb43fd5ca4735161710688f3a2e 100644 (file)
@@ -31,7 +31,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 model.begin()
index e42df1e89e4085f1460be863561d798ab6715d37..5e5f8acf3adc37257858c4d5c5e3dc7bbec9cb19 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 model.begin()
index ae5a2f3f864130da2739982fd57dd7978e1063d4..e0eeee3f055ade43b0895030bcd89da6a230541b 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 model.begin()
index 29db8702f56876c797e73c0c028ef7ae9d13f09b..6b741abbcc4fa0c43f070bea165634904918f189 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 model.begin()
index 1031a7949f8516b3d51ef8f8a8c52b4e326a3767..3c8b14257c1435d1009f20882214aea63473a2fd 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 model.begin()
index 002c09a39a5af8f3fe98d0393ca2a3e23194472a..6c4266ed728791702fd1d211eae6df1399f2010e 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Point_2
index 590da1f22156a4cdb389cd47e7251345934592ea..f2c9ac63e56ea050103ae3126469f9518404a118 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Axis_4
index 1dddcb26d711e937f941bd307df23dd155d25646..0b723a2312743677fd2117a4b87e368335e5c0b8 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Sketch_1
index 63ffb4312b5429a4a9847f5bb788fe45b32e2421..a02183e98747bc1443bbb225eb3b3919dbf6808d 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Extrusion_1
index 7d1929264882e9a331c0c6bbb1f75674b3651d01..b3753edc2e7688305dba6743d08a567f6fe2c826 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Sketch_2
index b4ca20e34ace22c77447050fc1cc7ca79af1bc9e..0afd739afbec9ec48086cff8e224dab64103b9e0 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Revolution_1
index 5d8e9cb37123e0dec14a6090d37f8355b2b8f142..6dc1b76e75f636c336d5e07e9cb09d9f3597907b 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Box_1
index 7381f5e0ffd200b770f96f68745e6ae1f114f78e..1a03585150a62209fd4cb14938f6da7144d82892 100644 (file)
@@ -63,7 +63,7 @@ model.end()
 
 import os
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Translation_1
index e633e8834d472169549b64ed74ededd2b4f1666d..0d104a8b07dacf0a7585523576410536afe20a42 100644 (file)
@@ -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
index e9692722885e99cf347dae2a1c9d00b027a91801..3f75cb3d9d65ea663ad986ab782ade18c5a3f845 100644 (file)
@@ -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
index 113e738bffe89c82a0663961d69b3cee85f6b51e..dd465a4db689073a6b45a9ecf7938a487b7ddca3 100644 (file)
@@ -64,7 +64,7 @@ model.do()
 
 model.end()
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 # store the reference data
index 7b89ef1b84780d0b3b39a7a078eefb2dcde299ba..218612e6c16d4b8f94f0151a7e830da3d04b6042 100644 (file)
@@ -65,7 +65,7 @@ model.do()
 
 model.end()
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Sketch_1
index 0f507487144414885b50edd5c40945ede8a746a0..f3f4c105ac2d6f3338e31a67e480e5542ca85166 100644 (file)
@@ -64,7 +64,7 @@ model.do()
 
 model.end()
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Box_1
index 2dc22241e21aaf3ce2c31619a4b180db78a95d18..21167333281b292d3045a8262aa740cbbfc2fb5d 100644 (file)
@@ -64,7 +64,7 @@ model.do()
 
 model.end()
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 featureToExport = Translation_1
index 294f48589f00a8c0948833defea83caec294cec3..1ad3b03c9ee13a1e4601f0efbb58b1bac28144a9 100644 (file)
@@ -65,7 +65,7 @@ model.do()
 
 model.end()
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 # store the reference data
index f812d071fc22b902764dafada8625df6893b6cb5..58dac780e6dfaef5fb2e177aa812284414b95de9 100644 (file)
@@ -65,7 +65,7 @@ model.do()
 
 model.end()
 
-filename = model.tempFileName()
+filename = 'check_export.shaperpart'
 model.removeFile(filename)
 
 # store the reference data
index 17b64d1b4865624de76bb000f449657bdf33486b..45b0529b6c0e472a3afb1d66150ded6539f16149 100644 (file)
@@ -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
index 5ece48cc80faf0a1cda7076cb2b646312fe4b2f6..bf0db67cd1569f458b378ea533f695fb3b2b41b3 100644 (file)
@@ -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
index a9e1236abb125a4e8148b091d964687165e103be..5a84bd996eeced0b358a79487100ded1b1306ab8 100644 (file)
@@ -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
index 441ae9a3fc70c01485000799be74701deaa04679..ae3fa13c9b8057dac44183ac390fd18060b68b21 100644 (file)
@@ -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
index 9d3ad6218b16976f0ef2294d8389e75fd4f12590..7fdbc7e7a7496e802c4326aeffd5f96ef5a20578 100644 (file)
@@ -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
index fd665598a4401ba1e944dcbead511cb24d6128be..2df7249109e01ab034e5de9f4aa9de6c27881f62 100644 (file)
@@ -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
index 670f11adf8ba9bcec4124b06f566f8d9c80bb3ce..0f0fee841969e2a4f916d0feabaef19f15c24272 100644 (file)
@@ -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
index 216acecd7a7a3e73fdaf670cf1cb24e95f3f3e27..2e01c4d9d8b78725ab7562da6c2e57235babe0cc 100644 (file)
@@ -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);
index f6b9c6a71f0bc5794a699bff30b233167beef7a7..a80db1b29ab66fd3a2ce516e943680f00dfe5daf 100644 (file)
 #
 
 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)