]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Dump with geometrical selection
authorazv <azv@opencascade.com>
Thu, 16 Aug 2018 04:48:09 +0000 (07:48 +0300)
committerazv <azv@opencascade.com>
Thu, 30 Aug 2018 08:39:15 +0000 (11:39 +0300)
Update checkPythonDump() command to execute dumping with naming and geometrical selection one by one.

src/ModelHighAPI/ModelHighAPI_Tools.cpp

index 70995d6a76f9616d0b1e0ae02629434a5aa57aff..996e176764f2b7d97fa2d78b077f05e562123c41 100644 (file)
@@ -411,57 +411,57 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc,
 }
 
 //==================================================================================================
-bool checkPythonDump()
+typedef std::map<std::string, std::map<std::string, ModelHighAPI_FeatureStore> > Storage;
+
+static bool dumpToPython(SessionPtr theSession,
+                         const char* theFilename,
+                         bool theDumpByGeom,
+                         const std::string& theErrorMsgContext)
 {
-  SessionPtr aSession = ModelAPI_Session::get();
   // 2431: set PartSet as a current document
-  aSession->setActiveDocument(aSession->moduleDocument(), true);
+  theSession->setActiveDocument(theSession->moduleDocument(), true);
   // dump all to the python file
-  aSession->startOperation("Check python dump");
-  FeaturePtr aDump = aSession->moduleDocument()->addFeature("Dump");
+  theSession->startOperation("Check python dump");
+  FeaturePtr aDump = theSession->moduleDocument()->addFeature("Dump");
   if (aDump.get()) {
-    aDump->string("file_path")->setValue("check_dump.py"); // to the current folder
-    aDump->string("file_format")->setValue("py"); // to the current folder
+    aDump->string("file_path")->setValue(theFilename);
+    aDump->string("file_format")->setValue("py");
+    aDump->boolean("geometric_dump")->setValue(theDumpByGeom);
     aDump->execute();
   }
   bool isProblem = !aDump.get() || !aDump->error().empty(); // after "finish" dump will be removed
   if (isProblem && aDump.get()) {
-    std::cout<<"Dump feature error "<<aDump->error()<<std::endl;
-    Events_InfoMessage anErrorMsg(std::string("checkPythonDump"), aDump->error());
+    std::cout << "Dump feature error " << aDump->error() << std::endl;
+    Events_InfoMessage anErrorMsg(theErrorMsgContext, aDump->error());
     anErrorMsg.send();
   }
-  aSession->finishOperation();
-  if (isProblem) {
-    return false; // something is wrong during dump
-  }
+  theSession->finishOperation();
+  return !isProblem;
+}
 
-  // map from document name to feature name to feature data
-  std::map<std::string, std::map<std::string, ModelHighAPI_FeatureStore> > aStore;
-  std::string anError = storeFeatures(
-    aSession->moduleDocument()->kind(), aSession->moduleDocument(), aStore, false);
-  if (!anError.empty()) {
-    Events_InfoMessage anErrorMsg(std::string("checkPythonDump"), anError);
-    anErrorMsg.send();
-    return false;
-  }
+static bool checkDump(SessionPtr theSession,
+                      char* theFilename,
+                      Storage& theStorage,
+                      const std::string& theErrorMsgContext)
+{
 
   // close all before importation of the script
-  aSession->closeAll();
+  theSession->closeAll();
+
 
   // execute the dumped
   PyGILState_STATE gstate = PyGILState_Ensure(); /* acquire python thread */
-  static char aDumpName[] = "./check_dump.py";
   static char aReadMode[] = "r";
-  FILE* aFile = _Py_fopen(aDumpName, aReadMode);
-  PyRun_SimpleFileEx(aFile, aDumpName, 1);
+  PyObject* PyFileObject = PyFile_FromString(theFilename, aReadMode);
+  PyRun_SimpleFileEx(PyFile_AsFile(PyFileObject), theFilename, 1);
   PyGILState_Release(gstate); /* release python thread */
 
   // compare with the stored data
-  anError = storeFeatures(
-    aSession->moduleDocument()->kind(), aSession->moduleDocument(), aStore, true);
+  std::string anError = storeFeatures(
+    theSession->moduleDocument()->kind(), theSession->moduleDocument(), theStorage, true);
   if (!anError.empty()) {
-    std::cout<<anError<<std::endl;
-    Events_InfoMessage anErrorMsg(std::string("checkPythonDump"), anError);
+    std::cout << anError << std::endl;
+    Events_InfoMessage anErrorMsg(theErrorMsgContext, anError);
     anErrorMsg.send();
     return false;
   }
@@ -469,4 +469,38 @@ bool checkPythonDump()
   return true;
 }
 
+bool checkPythonDump()
+{
+  static const std::string anErrorByNaming("checkPythonDump by naming");
+  static const std::string anErrorByGeometry("checkPythonDump by geometry");
+
+  static char aFileForNamingDump[] = "./check_dump_byname.py";
+  static char aFileForGeometryDump[] = "./check_dump_bygeom.py";
+
+  SessionPtr aSession = ModelAPI_Session::get();
+  // dump with the selection by names
+  if (!dumpToPython(aSession, aFileForNamingDump, false, anErrorByNaming))
+    return false;
+  // dump with the selection by geometry
+  if (!dumpToPython(aSession, aFileForGeometryDump, true, anErrorByGeometry))
+    return false;
+
+   // map from document name to feature name to feature data
+  std::map<std::string, std::map<std::string, ModelHighAPI_FeatureStore> > aStore;
+  std::string anError = storeFeatures(
+    aSession->moduleDocument()->kind(), aSession->moduleDocument(), aStore, false);
+  if (!anError.empty()) {
+    Events_InfoMessage anErrorMsg(std::string("checkPythonDump"), anError);
+    anErrorMsg.send();
+    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);
+
+  return isOk;
+}
+
 //--------------------------------------------------------------------------------------