Salome HOME
Add COPYING license file
[tools/yacsgen.git] / Examples / cppgui1 / components.py
1 # Copyright (C) 2009-2024  EDF
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 #import context from ..
21 exec(compile(open("../context.py").read(), "../context.py", 'exec'))
22
23 import os
24 from module_generator import *
25
26 idldefs="""
27 #include "myinterface.idl"
28 """
29
30 compodefs=r"""
31
32
33 class A: public virtual POA_Idl_A
34 {
35 public:
36   void createObject(::SALOMEDS::Study_ptr theStudy, const char* name){};
37
38   // Driver interface
39   virtual SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile){return 0;};
40   virtual SALOMEDS::TMPFile* SaveASCII(SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile){return 0;};
41   virtual bool Load(SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream, const char* theURL, bool isMultiFile){return 0;};
42   virtual bool LoadASCII(SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream, const char* theURL, bool isMultiFile){return 0;};
43   virtual void Close(SALOMEDS::SComponent_ptr IORSComponent){};
44   virtual char* ComponentDataType(){return (char*)"cppcompos";};
45   virtual char* IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject, const char* IORString, CORBA::Boolean isMultiFile, CORBA::Boolean isASCII){return 0;};
46   virtual char* LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, const char* aLocalPersistentID, CORBA::Boolean isMultiFile,
47                                        CORBA::Boolean isASCII){return 0;};
48   virtual bool  CanPublishInStudy(CORBA::Object_ptr theIOR){return 0;};
49   virtual SALOMEDS::SObject_ptr PublishInStudy(SALOMEDS::SObject_ptr theSObject,CORBA::Object_ptr theObject,
50                                                const char* theName){return 0;};
51   virtual CORBA::Boolean CanCopy(SALOMEDS::SObject_ptr theObject){return 0;};
52   virtual SALOMEDS::TMPFile* CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID){return 0;};
53   virtual CORBA::Boolean CanPaste(const char* theComponentName, CORBA::Long theObjectID){return 0;};
54   virtual SALOMEDS::SObject_ptr PasteInto(const SALOMEDS::TMPFile& theStream, CORBA::Long theObjectID, SALOMEDS::SObject_ptr theObject){return 0;};
55 };
56
57 """
58
59 compomethods=r"""
60
61   Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
62                                CORBA::Boolean isPublished,
63                                CORBA::Boolean isMultiFile,
64                                CORBA::Boolean& isValidScript)
65   {
66     std::cerr << "je suis dans le dump:" << __LINE__ << std::endl;
67     SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
68     if(CORBA::is_nil(aStudy))
69       return new Engines::TMPFile(0);
70
71     SALOMEDS::SObject_var aSO = aStudy->FindComponent("cppcompos");
72     if(CORBA::is_nil(aSO))
73        return new Engines::TMPFile(0);
74
75     std::string Script = "import cppcompos_ORB\n";
76     Script += "import salome\n";
77     Script += "compo = salome.lcc.FindOrLoadComponent('FactoryServer','cppcompos')\n";
78     Script += "def RebuildData(theStudy):\n";
79     Script += "  compo.SetCurrentStudy(theStudy)\n";
80     const char* aScript=Script.c_str();
81
82     char* aBuffer = new char[strlen(aScript)+1];
83     strcpy(aBuffer, aScript);
84     CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
85     int aBufferSize = strlen(aBuffer)+1;
86     Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
87     isValidScript = true;
88     return aStreamFile._retn();
89   }
90
91
92 """
93
94 body="""
95 std::cerr << "a: " << a << std::endl;
96 std::cerr << "b: " << b << std::endl;
97 c=a+b;
98 std::cerr << "c: " << c << std::endl;
99 """
100 c1=CPPComponent("cppcompos",services=[
101           Service("s1",inport=[("a","double"),("b","double")],
102                        outport=[("c","double")],
103                        defs="//def1",body=body,
104                  ),
105           ],
106          idls=["*.idl"],
107          interfacedefs=idldefs,
108          inheritedinterface="Idl_A",
109          compodefs=compodefs,
110          inheritedclass="A",
111          addedmethods=compomethods,
112          )
113
114 modul=Module("cppcompos",components=[c1],prefix="./install",
115              doc=["*.rst",],
116              gui=["cppcomposGUI.cxx","cppcomposGUI.h","demo.ui","*.png"],
117             )
118
119 g=Generator(modul,context)
120 g.generate()
121 #g.configure("-DTBB_INCLUDE_DIR=/opt/tbb/2018.u6/include  -DTBB_ROOT=/opt/tbb/2018.u6/")
122 g.configure()
123 g.make()
124 g.install()
125 g.make_appli("appli", restrict=["KERNEL"], altmodules={"GUI":GUI_ROOT_DIR, "YACS":YACS_ROOT_DIR}, sys_modules=SYS_MODULES)
126