Salome HOME
Merge from V6_main_20120808 08Aug12
[samples/atomsolv.git] / src / ATOMSOLV / ATOMSOLV.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
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.
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 using namespace std;
21 #include "ATOMSOLV.hxx"
22 #include "utilities.h"
23
24 #include <string>
25
26
27 ATOMSOLV::ATOMSOLV(CORBA::ORB_ptr orb,
28         PortableServer::POA_ptr poa,
29         PortableServer::ObjectId * contId, 
30         const char *instanceName, 
31         const char *interfaceName) :
32   Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
33 {
34   MESSAGE("activate object");
35   _thisObj = this ;
36   _id = _poa->activate_object(_thisObj);
37 }
38
39 ATOMSOLV::~ATOMSOLV()
40 {
41 }
42
43 CORBA::Boolean ATOMSOLV::setData( CORBA::Long studyID, const ATOMSOLV_ORB::TMoleculeList& theData )
44 {
45   const int n = theData.length();
46   ATOMSOLV_ORB::TMoleculeList_var data = new ATOMSOLV_ORB::TMoleculeList();
47   data->length( n );
48   for ( int i = 0; i < n; i++ )
49     data[ i ] = theData[ i ];
50
51   //  printf( " -- ATOMSOLV::setData( %d ) length = %d\n", studyID, data->length() );
52   myData[ studyID ] = data._retn();
53
54   return (bool)n;
55 }
56
57 CORBA::Boolean ATOMSOLV::getData( CORBA::Long studyID, ATOMSOLV_ORB::TMoleculeList_out outData )
58 {
59   if ( myData.find( studyID ) != myData.end() ) {
60     ATOMSOLV_ORB::TMoleculeList* data = myData[ studyID ];
61
62     //    printf( " -- ATOMSOLV::getData( %d ) length = %d\n", studyID, data->length() );
63     const int n = data->length();
64     outData = new ATOMSOLV_ORB::TMoleculeList();
65     outData->length( n );
66
67     for ( int i = 0; i < n; i++ )
68       (*outData)[ i ] = (*data)[ i ];
69     
70     return true;
71   }
72   return false;
73 }
74
75 CORBA::Boolean ATOMSOLV::processData( CORBA::Long studyID )
76 {
77   if ( myData.find( studyID ) != myData.end() ) {
78     ATOMSOLV_ORB::TMoleculeList* data = myData[ studyID ];
79     for ( int i = 0, n = data->length(); i < n; i++ )
80       (*data)[i].temperature = rand();
81   }
82   return true;
83 }
84
85
86 extern "C"
87 {
88   PortableServer::ObjectId * ATOMSOLVEngine_factory(
89                                CORBA::ORB_ptr orb,
90                                PortableServer::POA_ptr poa, 
91                                PortableServer::ObjectId * contId,
92                                const char *instanceName, 
93                                const char *interfaceName)
94   {
95     MESSAGE("PortableServer::ObjectId * ATOMSOLVEngine_factory()");
96     SCRUTE(interfaceName);
97     ATOMSOLV * myATOMSOLV 
98       = new ATOMSOLV(orb, poa, contId, instanceName, interfaceName);
99     return myATOMSOLV->getId() ;
100   }
101 }