Salome HOME
Split loadTemplate into 2 parts to ease overload of default visitor
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 26 Sep 2019 13:56:48 +0000 (15:56 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 26 Sep 2019 13:56:48 +0000 (15:56 +0200)
AdaoExchangeLayer.cxx
AdaoExchangeLayer.hxx
TestAdaoExchange.cxx

index 8e9e28087c4fb37e828299c6f88f8b8d5812c151..38b1ba3ff02fe8d75a6d70dc46caf8947470e281 100644 (file)
@@ -319,7 +319,7 @@ private:
   PyObject *_context = nullptr;
 };
 
-void AdaoExchangeLayer::loadTemplate(AdaoModel::MainModel *model)
+void AdaoExchangeLayer::setFunctionCallbackInModel(AdaoModel::MainModel *model)
 {
   AutoGIL agil;
   const char DECORATOR_FUNC[]="def DecoratorAdao(cppFunc):\n"
@@ -346,7 +346,11 @@ void AdaoExchangeLayer::loadTemplate(AdaoModel::MainModel *model)
   //
   Visitor1 visitor(this->_internal->_decorator_func,this->_internal->_context);
   model->visitPythonLeaves(&visitor);
-  //
+}
+
+void AdaoExchangeLayer::loadTemplate(AdaoModel::MainModel *model)
+{
+  AutoGIL agil;
   {
     std::string sciptPyOfModelMaker(model->pyStr());
     PyObjectRAII res(PyObjectRAII::FromNew(PyRun_String(sciptPyOfModelMaker.c_str(),Py_file_input,this->_internal->_context,this->_internal->_context)));
index 988e23cf742f919268707d96b0c561430089be14..c9f2257572c2ccf7ceff2008c00ea57d783b7a6d 100644 (file)
@@ -40,6 +40,7 @@ public:
   PyObject *getPythonContext() const;
   std::string printContext() const;
   void init();
+  void setFunctionCallbackInModel(AdaoModel::MainModel *model);
   void loadTemplate(AdaoModel::MainModel *model);
   void execute();
   bool next(PyObject *& inputRequested);
index 30d29490b85bec16256ccf92d56f8614c106d9da..668201f5e2ce9a6d2a1a6918db29291c6acdb8f2 100644 (file)
@@ -124,6 +124,7 @@ void AdaoExchangeTest::test3DVar()
   AdaoExchangeLayer adao;
   adao.init();
   // For bounds, Background/Vector, Observation/Vector
+  adao.setFunctionCallbackInModel(&mm);
   Visitor2 visitorPythonObj(adao.getPythonContext());
   {
     AutoGIL agil;
@@ -181,6 +182,7 @@ void AdaoExchangeTest::testBlue()
   AdaoExchangeLayer adao;
   adao.init();
   // For bounds, Background/Vector, Observation/Vector
+  adao.setFunctionCallbackInModel(&mm);
   Visitor2 visitorPythonObj(adao.getPythonContext());
   {
     AutoGIL agil;
@@ -237,6 +239,7 @@ void AdaoExchangeTest::testNonLinearLeastSquares()
   AdaoExchangeLayer adao;
   adao.init();
   // For bounds, Background/Vector, Observation/Vector
+  adao.setFunctionCallbackInModel(&mm);
   Visitor2 visitorPythonObj(adao.getPythonContext());
   {
     AutoGIL agil;
@@ -277,6 +280,7 @@ void AdaoExchangeTest::testCasCrue()
   AdaoExchangeLayer adao;
   adao.init();
   // For bounds, Background/Vector, Observation/Vector
+  adao.setFunctionCallbackInModel(&mm);
   VisitorCruePython visitorPythonObj(adao.getPythonContext());
   {
     AutoGIL agil;