From cba055958b614e3a582ea7ea78f8067706e7367f Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 16 Aug 2018 07:48:09 +0300 Subject: [PATCH] Dump with geometrical selection Update checkPythonDump() command to execute dumping with naming and geometrical selection one by one. --- src/ModelHighAPI/ModelHighAPI_Tools.cpp | 94 +++++++++++++++++-------- 1 file changed, 64 insertions(+), 30 deletions(-) diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index 70995d6a7..996e17676 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -411,57 +411,57 @@ std::string storeFeatures(const std::string& theDocName, DocumentPtr theDoc, } //================================================================================================== -bool checkPythonDump() +typedef std::map > 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 "<error()<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 > 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< > 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; +} + //-------------------------------------------------------------------------------------- -- 2.39.2