1 // Copyright (C) 2006-2015 CEA/DEN, 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
20 %define PYPILOTDOCSTRING
21 "This module provides 2 classes PyObserver and PyCatalogLoader that can be subclassed in Python (uses director feature)"
24 %module(directors="1",docstring=PYPILOTDOCSTRING) pypilot
26 %feature("autodoc", "1");
28 %include "engtypemaps.i"
31 #include "Dispatcher.hxx"
32 #include "Catalog.hxx"
33 #include "TypeCode.hxx"
39 class PyObserver:public Observer
42 virtual void notifyObserver(Node* object,const std::string& event)
44 //YACS engine processing is pure C++ : need to take the GIL
45 PyGILState_STATE gstate = PyGILState_Ensure();
49 pynotify(object,event);
52 // print the exception and clear it
54 //do not propagate the python exception (ignore it)
59 //ignore this exception:probably Swig::DirectorException
63 PyGILState_Release(gstate);
65 virtual void pynotify(Node* object,const std::string& event)
67 //To inherit (Python class)
68 std::cerr << "pynotify " << event << object << std::endl;
72 class PyCatalogLoader:public CatalogLoader
75 virtual CatalogLoader* newLoader(const std::string& path) {return 0;}
86 PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
89 PyErr_SetString(PyExc_ImportError,(char*)"Cannot import _omnipy");
92 PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
93 api = (omniORBPYAPI*)PyCObject_AsVoidPtr(pyapi);
99 * Director section : classes that can be subclassed in python
101 %feature("director") YACS::ENGINE::PyObserver;
102 %feature("nodirector") YACS::ENGINE::PyObserver::notifyObserver;
103 %feature("director") YACS::ENGINE::PyCatalogLoader;
104 %feature("nodirector") YACS::ENGINE::PyCatalogLoader::newLoader;
107 %feature("director:except") {
108 if ($error != NULL) {
109 // print the exception and clear it
111 //do not propagate the python exception (ignore it)
112 //throw Swig::DirectorMethodException();
117 * End of Director section
120 %types(YACS::ENGINE::Node *,YACS::ENGINE::Proc *,YACS::ENGINE::ForLoop *,YACS::ENGINE::Bloc *, YACS::ENGINE::Switch *);
121 %types(YACS::ENGINE::WhileLoop *,YACS::ENGINE::ForEachLoop *,YACS::ENGINE::ComposedNode *,YACS::ENGINE::InlineNode *);
122 %types(YACS::ENGINE::InlineFuncNode *,YACS::ENGINE::ServiceInlineNode *,YACS::ENGINE::ServiceNode *);
123 %types(YACS::ENGINE::ElementaryNode *);
124 %types(YACS::ENGINE::Container *, YACS::ENGINE::HomogeneousPoolContainer *);
126 %types(YACS::ENGINE::InputPort *,YACS::ENGINE::OutputPort *,YACS::ENGINE::InPropertyPort *);
127 %types(YACS::ENGINE::InputDataStreamPort *,YACS::ENGINE::OutputDataStreamPort *);
128 %types(YACS::ENGINE::InGate *,YACS::ENGINE::OutGate *);
129 %types(YACS::ENGINE::InPort *,YACS::ENGINE::OutPort *,YACS::ENGINE::Port *);
131 %types(YACS::ENGINE::Observer *);
134 %import "Dispatcher.hxx"
135 %import "Catalog.hxx"
141 class PyObserver:public Observer
144 virtual void pynotify(Node* object,const std::string& event);
147 class PyCatalogLoader:public CatalogLoader
150 virtual CatalogLoader* newLoader(const std::string& path);