1 // Copyright (C) 2019-2024 EDF
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 #ifndef YDEFX_TMONOPYJOB_HXX
20 #define YDEFX_TMONOPYJOB_HXX
21 #include "JobParametersProxy.hxx"
22 #include "MonoPyJob.hxx"
23 #include "SamplePyConversions.hxx"
24 #include "PyStudyFunction.hxx"
28 template <class ...Ts>
29 class TMonoPyJob : public MonoPyJob
33 TMonoPyJob(const PyStudyFunction& fnScript,
34 Sample<Ts...>& sample,
35 const JobParametersProxy& params)
39 if(_lastError.empty()) // no errors during parent construction
43 py2cpp::PyPtr pySample = fnScript.createEmptySample();
44 py2cpp::PyFunction setInputValues;
45 setInputValues.loadExp(pySample, "setInputValues");
46 setInputValues(inputToPy(_sample));
48 py2cpp::PyFunction pyFn;
49 pyFn.loadExp(_pyStudy, "createNewJob");
50 pyFn(fnScript, pySample, params);
52 catch(std::exception& e)
54 _lastError = "An error occured while creating the job.\n";
55 _lastError += e.what();
60 //! Connect to an existing job.
61 TMonoPyJob(const std::string& jobDump, Sample<Ts...>& sample)
65 if(_lastError.empty()) // no errors during parent construction
69 py2cpp::PyFunction pyFn;
70 pyFn.loadExp(_pyStudy, "loadFromString");
73 catch(std::exception& e)
75 _lastError = "An error occured while creating the job.\n";
76 _lastError += e.what();
81 virtual ~TMonoPyJob(){}
87 py2cpp::PyFunction pyFn;
88 pyFn.loadExp(_pyStudy, "getResult");
89 pyFn(); // python call: _pyStudy.getResult()
90 fetchResults(_pyStudy.getAttr("sample"), _sample);
92 catch(std::exception& e)
94 _lastError = "An error occured while fetching the results.\n";
95 _lastError += e.what();
97 return _lastError.empty();
100 const Sample<Ts...>& getSample()const{return _sample;}
103 Sample<Ts...>& _sample;
108 #endif //YDEFX_TMONOPYJOB_HXX