Salome HOME
a65b84362c8aabfa89a20e6a9c2f66a3a9967679
[modules/smesh.git] / src / SMESH_I / SMESH_Hypothesis_i.cxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SMESH_Hypothesis_i.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #include <iostream>
30 #include <sstream>
31 #include "SMESH_Hypothesis_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "utilities.h"
34
35 using namespace std;
36
37 //=============================================================================
38 /*!
39  *  SMESH_Hypothesis_i::SMESH_Hypothesis_i
40  * 
41  *  Constructor
42  */
43 //=============================================================================
44
45 SMESH_Hypothesis_i::SMESH_Hypothesis_i( PortableServer::POA_ptr thePOA )
46      : SALOME::GenericObj_i( thePOA )
47 {
48   MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Début" );
49   myBaseImpl = 0;
50   
51   MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Fin" );
52 };
53
54 //=============================================================================
55 /*!
56  *  SMESH_Hypothesis_i::~SMESH_Hypothesis_i
57  *
58  *  Destructor
59  */
60 //=============================================================================
61
62 SMESH_Hypothesis_i::~SMESH_Hypothesis_i()
63 {
64   MESSAGE( "SMESH_Hypothesis_i::~SMESH_Hypothesis_i" );
65   if ( myBaseImpl )
66     delete myBaseImpl;
67 };
68
69 //=============================================================================
70 /*!
71  *  SMESH_Hypothesis_i::GetName
72  *
73  *  Get type name of hypothesis
74  */
75 //=============================================================================
76
77 char* SMESH_Hypothesis_i::GetName()
78 {
79   //MESSAGE( "SMESH_Hypothesis_i::GetName" );
80   return CORBA::string_dup( myBaseImpl->GetName() );
81 };
82
83 //=============================================================================
84 /*!
85  *  SMESH_Hypothesis_i::GetLibName
86  *
87  *  Get plugin library name of hypothesis (required by persistency mechanism)
88  */
89 //=============================================================================
90
91 char* SMESH_Hypothesis_i::GetLibName()
92 {
93   MESSAGE( "SMESH_Hypothesis_i::GetLibName" );
94   return CORBA::string_dup( myBaseImpl->GetLibName() );
95 };
96
97 //=============================================================================
98 /*!
99  *  SMESH_Hypothesis_i::SetLibName
100  *
101  *  Set plugin library name of hypothesis (required by persistency mechanism)
102  */
103 //=============================================================================
104
105 void SMESH_Hypothesis_i::SetLibName(const char* theLibName)
106 {
107   MESSAGE( "SMESH_Hypothesis_i::SetLibName" );
108   myBaseImpl->SetLibName( theLibName );
109 };
110
111 //=============================================================================
112 /*!
113  *  SMESH_Hypothesis_i::GetId
114  *
115  *  Get unique id of hypothesis
116  */
117 //=============================================================================
118
119 CORBA::Long SMESH_Hypothesis_i::GetId()
120 {
121   MESSAGE( "SMESH_Hypothesis_i::GetId" );
122   return myBaseImpl->GetID();
123 }
124
125 //=============================================================================
126 /*!
127  *  SMESH_Hypothesis_i::IsPublished()
128  *
129  */
130 //=============================================================================
131 bool SMESH_Hypothesis_i::IsPublished(){
132   bool res = false;
133   SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
134   if(gen){
135     SALOMEDS::SObject_var SO = 
136       SMESH_Gen_i::ObjectToSObject(gen->GetCurrentStudy() , SMESH::SMESH_Hypothesis::_narrow(_this()));
137     res = !SO->_is_nil();
138   }
139   return res;
140 }
141
142 //=============================================================================
143 /*!
144  *  SMESH_Hypothesis_i::SetParameters()
145  *
146  */
147 //=============================================================================
148 void SMESH_Hypothesis_i::SetParameters(const char* theParameters)
149 {
150   SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
151   char * aParameters = CORBA::string_dup(theParameters);
152   if(gen){
153     if(IsPublished()) {
154       SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Hypothesis::_narrow(_this()),aParameters);
155     }
156     else {
157       myBaseImpl->SetParameters(gen->ParseParameters(aParameters));
158     }
159   }
160 }
161
162 //=============================================================================
163 /*!
164  *  SMESH_Hypothesis_i::GetParameters()
165  *
166  */
167 //=============================================================================
168 char* SMESH_Hypothesis_i::GetParameters()
169 {
170   SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
171   char* aResult;
172   if(IsPublished()) {
173     MESSAGE("SMESH_Hypothesis_i::GetParameters() : Get Parameters from SObject");
174     aResult = gen->GetParameters(SMESH::SMESH_Hypothesis::_narrow(_this()));
175   }
176   else {
177     MESSAGE("SMESH_Hypothesis_i::GetParameters() : Get local parameters");
178     aResult = myBaseImpl->GetParameters(); 
179   }
180   return CORBA::string_dup(aResult);
181 }
182
183 //=============================================================================
184 /*!
185  *  SMESH_Hypothesis_i::GetLastParameters()
186  *
187  */
188 //=============================================================================
189 SMESH::ListOfParameters* SMESH_Hypothesis_i::GetLastParameters()
190 {
191   SMESH::ListOfParameters_var aResult = new SMESH::ListOfParameters();
192   SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
193   if(gen) {
194     char *aParameters = GetParameters();
195     SALOMEDS::Study_ptr aStudy = gen->GetCurrentStudy();
196     if(!aStudy->_is_nil()) {
197       SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters); 
198       if(aSections->length() > 0) {
199         SALOMEDS::ListOfStrings aVars = aSections[aSections->length()-1];
200         aResult->length(aVars.length());
201         for(int i = 0;i < aVars.length();i++)
202           aResult[i] = CORBA::string_dup( aVars[i]);
203       }
204     }
205   }
206   return aResult._retn();
207 }
208
209 //=============================================================================
210 /*!
211  *  SMESH_Hypothesis_i::GetImpl
212  *
213  *  Get implementation
214  */
215 //=============================================================================
216
217 ::SMESH_Hypothesis* SMESH_Hypothesis_i::GetImpl()
218 {
219   //MESSAGE( "SMESH_Hypothesis_i::GetImpl" );
220   return myBaseImpl;
221 }
222
223 //=============================================================================
224 /*!
225  *  SMESH_Hypothesis_i::SaveTo
226  *
227  *  Persistence: Dumps parameters to the string stream
228  */
229 //=============================================================================
230
231 char* SMESH_Hypothesis_i::SaveTo()
232 {
233   MESSAGE( "SMESH_Hypothesis_i::SaveTo" );
234   std::ostringstream os;
235   myBaseImpl->SaveTo( os );
236   return CORBA::string_dup( os.str().c_str() );
237 }
238
239 //=============================================================================
240 /*!
241 *  SMESH_Hypothesis_i::LoadFrom
242 *
243 *  Persistence: Restores parameters from string
244 */
245 //=============================================================================
246
247 void SMESH_Hypothesis_i::LoadFrom( const char* theStream )
248 {
249   MESSAGE( "SMESH_Hypothesis_i::LoadFrom" );
250   std::istringstream is( theStream );
251   myBaseImpl->LoadFrom( is );
252 }