1 // Copyright (C) 2019 EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "PyStudyJob.hxx"
20 #include <py2cpp/py2cpp.hxx>
24 PyStudyJob::PyStudyJob()
29 py2cpp::PyFunction objConstructor;
30 objConstructor.loadExp("pydefx", "PyStudy");
31 _pyStudy = objConstructor();
34 PyStudyJob::PyStudyJob(const std::string& pymodule_name, const std::string& pyclass_name)
39 py2cpp::PyFunction objConstructor;
40 objConstructor.loadExp(pymodule_name, pyclass_name);
41 _pyStudy = objConstructor();
44 PyStudyJob::PyStudyJob(py2cpp::PyPtr& pyStudyObj)
45 : _pyStudy(pyStudyObj)
51 PyStudyJob::~PyStudyJob()
55 std::string PyStudyJob::state()
61 py2cpp::PyFunction pyFn;
62 pyFn.loadExp(_pyStudy, "getJobState");
63 py2cpp::pyResult(result) = pyFn();
65 catch(std::exception& e)
67 _lastError = "An error occured while retrieving job's state.\n";
68 _lastError += e.what();
73 double PyStudyJob::progress()
76 py2cpp::PyFunction pyFn;
80 pyFn.loadExp(_pyStudy, "getProgress");
81 py2cpp::pyResult(result) = pyFn();
83 catch(std::exception& e)
85 _lastError = "An error occured while retrieving job's progress.\n";
86 _lastError += e.what();
91 std::string PyStudyJob::dump()
97 py2cpp::PyFunction pyFn;
98 pyFn.loadExp(_pyStudy, "dump");
99 py2cpp::pyResult(result) = pyFn();
101 catch(std::exception& e)
103 _lastError = "An error occured while dumping the job.\n";
104 _lastError += e.what();
109 bool PyStudyJob::launch()
114 py2cpp::PyFunction pyFn;
115 pyFn.loadExp(_pyStudy, "launch");
118 catch(std::exception& e)
120 _lastError = "An error occured while launching the job.\n";
121 _lastError += e.what();
123 return _lastError.empty();
126 const std::string& PyStudyJob::lastError()
131 bool PyStudyJob::wait()
136 py2cpp::PyFunction pyFn;
137 pyFn.loadExp(_pyStudy, "wait");
140 catch(std::exception& e)
142 _lastError = "An error occured while waiting the end of the job.\n";
143 _lastError += e.what();
145 return _lastError.empty();
148 void PyStudyJob::configureWaitDelay(int seconds)
150 _waitDelay = seconds;