Salome HOME
Update Python dump to write both standard naming and geometrical selection at once
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_Tools.cpp
index a140b1ec6717c4418db7005c7a417ab44655f28a..3aa3579ad19d4df58f63c5c2c0bdae55f275466d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ModelHighAPI_Tools.h"
@@ -346,6 +345,12 @@ GeomAPI_Shape::ShapeType getShapeType(const ModelHighAPI_Selection& theSelection
       aShapeType = shapeTypeByStr(aType);
       break;
     }
+    case ModelHighAPI_Selection::VT_WeakNamingPair: {
+      TypeWeakNamingPair aPair = theSelection.typeWeakNamingPair();
+      std::string aType = aPair.first;
+      aShapeType = shapeTypeByStr(aType);
+      break;
+    }
   }
 
   return aShapeType;
@@ -377,7 +382,7 @@ std::string strByValueType(const ModelAPI_AttributeTables::ValueType theType)
   return ""; // bad case
 }
 
-/// stores the features information, recoursively stores sub-documetns features
+/// stores the features information, recursively stores sub-documents features
 std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc,
   std::map<std::string, std::map<std::string, ModelHighAPI_FeatureStore> >& theStore,
   const bool theCompare) // if false => store
@@ -390,7 +395,7 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc,
      }
   }
   // store the model features information: iterate all features
-  int anObjectsCount = 0; // stores the number of compared features for this document to compate
+  int anObjectsCount = 0; // stores the number of compared features for this document to compare
   std::set<std::string> aProcessed; // processed features names (that are in the current document)
 
   // process all objects (features and folders)
@@ -422,7 +427,7 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc,
       ModelAPI_Tools::allResults(aFeature, allResults);
       std::list<ResultPtr>::iterator aRes = allResults.begin();
       for(; aRes != allResults.end(); aRes++) {
-        // recoursively store features of sub-documents
+        // recursively store features of sub-documents
         if ((*aRes)->groupName() == ModelAPI_ResultPart::group()) {
           DocumentPtr aDoc = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes)->partDoc();
           if (aDoc.get()) {
@@ -458,7 +463,7 @@ typedef std::map<std::string, std::map<std::string, ModelHighAPI_FeatureStore> >
 
 static bool dumpToPython(SessionPtr theSession,
                          const char* theFilename,
-                         const char* theSelectionType,
+                         const checkDumpType theSelectionType,
                          const std::string& theErrorMsgContext)
 {
   // 2431: set PartSet as a current document
@@ -469,8 +474,9 @@ static bool dumpToPython(SessionPtr theSession,
   if (aDump.get()) {
     aDump->string("file_path")->setValue(theFilename);
     aDump->string("file_format")->setValue("py");
-    aDump->string("selection_type")->setValue(theSelectionType);
-    aDump->execute();
+    aDump->boolean("topological_naming")->setValue(theSelectionType & CHECK_NAMING);
+    aDump->boolean("geometric_selection")->setValue(theSelectionType & CHECK_GEOMETRICAL);
+    aDump->boolean("weak_naming")->setValue(theSelectionType & CHECK_WEAK);
   }
   bool isProblem = !aDump.get() || !aDump->error().empty(); // after "finish" dump will be removed
   if (isProblem && aDump.get()) {
@@ -511,22 +517,21 @@ static bool checkDump(SessionPtr theSession,
   return true;
 }
 
-bool checkPythonDump()
+bool checkPythonDump(const checkDumpType theCheckType)
 {
-  return true;
-
   static const std::string anErrorByNaming("checkPythonDump by naming");
   static const std::string anErrorByGeometry("checkPythonDump by geometry");
+  static const std::string anErrorByWeak("checkPythonDump by weak naming");
 
-  static char aFileForNamingDump[] = "./check_dump_byname.py";
-  static char aFileForGeometryDump[] = "./check_dump_bygeom.py";
+  static char aFileForNamingDump[] = "./check_dump.py";
+  static char aFileForGeometryDump[] = "./check_dump_geo.py";
+  static char aFileForWeakDump[] = "./check_dump_weak.py";
 
   SessionPtr aSession = ModelAPI_Session::get();
-  // dump with the selection by names
-  if (!dumpToPython(aSession, aFileForNamingDump, "topological_naming", anErrorByNaming))
-    return false;
-  // dump with the selection by geometry
-  if (!dumpToPython(aSession, aFileForGeometryDump, "geometric_selection", anErrorByGeometry))
+  // dump with the specified types
+  char* aFileName = theCheckType == CHECK_GEOMETRICAL ? aFileForGeometryDump :
+                   (theCheckType == CHECK_WEAK ? aFileForWeakDump : aFileForNamingDump);
+  if (!dumpToPython(aSession, aFileName, theCheckType, anErrorByNaming))
     return false;
 
    // map from document name to feature name to feature data
@@ -539,10 +544,18 @@ bool checkPythonDump()
     return false;
   }
 
-  // check dump with the selection by names
-  bool isOk = checkDump(aSession, aFileForNamingDump, aStore, anErrorByNaming);
-  // check dump with the selection by geometry
-  isOk = isOk && checkDump(aSession, aFileForGeometryDump, aStore, anErrorByGeometry);
+  bool isOk = true;
+  if (theCheckType & CHECK_NAMING) {
+    // check dump with the selection by names
+    isOk = checkDump(aSession, aFileForNamingDump, aStore, anErrorByNaming);
+  }
+  if (theCheckType & CHECK_GEOMETRICAL) {
+    // check dump with the selection by geometry
+    isOk = isOk && checkDump(aSession, aFileForGeometryDump, aStore, anErrorByGeometry);
+  }
+  if (theCheckType & CHECK_WEAK) {
+    isOk = isOk && checkDump(aSession, aFileForWeakDump, aStore, anErrorByWeak);
+  }
 
   return isOk;
 }