1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Hypothesis_i.cxx
24 // Author : Paul RASCLE, EDF
30 #include "SMESH_Hypothesis_i.hxx"
31 #include "SMESH_Gen_i.hxx"
32 #include "utilities.h"
36 //=============================================================================
38 * SMESH_Hypothesis_i::SMESH_Hypothesis_i
42 //=============================================================================
44 SMESH_Hypothesis_i::SMESH_Hypothesis_i( PortableServer::POA_ptr thePOA )
45 : SALOME_ParameterizedObject()
47 MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Début" );
50 MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Fin" );
53 //=============================================================================
55 * SMESH_Hypothesis_i::~SMESH_Hypothesis_i
59 //=============================================================================
61 SMESH_Hypothesis_i::~SMESH_Hypothesis_i()
63 MESSAGE( "SMESH_Hypothesis_i::~SMESH_Hypothesis_i" );
68 //=============================================================================
70 * SMESH_Hypothesis_i::GetName
72 * Get type name of hypothesis
74 //=============================================================================
76 char* SMESH_Hypothesis_i::GetName()
78 //MESSAGE( "SMESH_Hypothesis_i::GetName" );
79 return CORBA::string_dup( myBaseImpl->GetName() );
82 //=============================================================================
84 * SMESH_Hypothesis_i::GetLibName
86 * Get plugin library name of hypothesis (required by persistency mechanism)
88 //=============================================================================
90 char* SMESH_Hypothesis_i::GetLibName()
92 MESSAGE( "SMESH_Hypothesis_i::GetLibName" );
93 return CORBA::string_dup( myBaseImpl->GetLibName() );
96 //=============================================================================
98 * SMESH_Hypothesis_i::SetLibName
100 * Set plugin library name of hypothesis (required by persistency mechanism)
102 //=============================================================================
104 void SMESH_Hypothesis_i::SetLibName(const char* theLibName)
106 MESSAGE( "SMESH_Hypothesis_i::SetLibName" );
107 myBaseImpl->SetLibName( theLibName );
110 //=============================================================================
112 * SMESH_Hypothesis_i::GetId
114 * Get unique id of hypothesis
116 //=============================================================================
118 CORBA::Long SMESH_Hypothesis_i::GetId()
120 MESSAGE( "SMESH_Hypothesis_i::GetId" );
121 return myBaseImpl->GetID();
124 //=============================================================================
126 * SMESH_Hypothesis_i::IsPublished()
129 //=============================================================================
130 bool SMESH_Hypothesis_i::IsPublished(){
132 SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen();
134 SALOMEDS::SObject_var SO =
135 SMESH_Gen_i::ObjectToSObject(gen->GetCurrentStudy() , SMESH::SMESH_Hypothesis::_narrow(_this()));
136 res = !SO->_is_nil();
141 //=============================================================================
143 * SMESH_Hypothesis_i::GetEntry()
145 //=============================================================================
146 char* SMESH_Hypothesis_i::GetEntry()
149 SALOME::Notebook_ptr aNotebook = GetNotebook();
150 if( !CORBA::is_nil( aNotebook ) )
152 SALOMEDS::Study_ptr aStudy = aNotebook->GetStudy();
153 if( SMESH_Gen_i* aGen = SMESH_Gen_i::GetSMESHGen() )
155 if( StudyContext* aStudyContext = aGen->GetStudyContext( aStudy->StudyId() ) )
157 CORBA::String_var anIOR = aGen->GetORB()->object_to_string( _this() );
158 anId = aStudyContext->findId( anIOR.in() );
164 sprintf( aBuf, "%i", anId );
165 return CORBA::string_dup( aBuf );
168 //=============================================================================
170 * SMESH_Hypothesis_i::GetComponent()
172 //=============================================================================
173 char* SMESH_Hypothesis_i::GetComponent()
175 return CORBA::string_dup( "SMESH" );
178 //=============================================================================
180 * SMESH_Hypothesis_i::IsValid()
182 //=============================================================================
183 CORBA::Boolean SMESH_Hypothesis_i::IsValid()
188 //=============================================================================
190 * SMESH_Hypothesis_i::SetParameters()
193 //=============================================================================
194 void SMESH_Hypothesis_i::SetParameters( SALOME::Notebook_ptr theNotebook, const SALOME::StringArray& theParameters )
196 theNotebook->ClearDependencies( _this(), SALOME::Parameters );
197 std::list<std::string> aParams;
198 int n = theParameters.length();
199 for( int i=0; i<n; i++ )
201 std::string aParam = CORBA::string_dup( theParameters[i] );
202 aParams.push_back( aParam );
204 SALOME::Parameter_ptr aParamPtr = theNotebook->GetParameter( aParam.c_str() );
205 if( !CORBA::is_nil( aParamPtr ) )
206 theNotebook->AddDependency( _this(), aParamPtr );
208 myBaseImpl->SetParameters( aParams );
210 UpdateStringAttribute();
213 //=============================================================================
215 * SMESH_Hypothesis_i::GetParameters()
218 //=============================================================================
219 SALOME::StringArray* SMESH_Hypothesis_i::GetParameters()
221 std::list<std::string> aParams = myBaseImpl->GetParameters();
222 SALOME::StringArray_var aRes = new SALOME::StringArray();
223 aRes->length( aParams.size() );
224 std::list<std::string>::const_iterator it = aParams.begin(), last = aParams.end();
225 for( int i=0; it!=last; it++, i++ )
226 aRes[i] = CORBA::string_dup( it->c_str() );
230 //=============================================================================
232 * SMESH_Hypothesis_i::Update()
235 //=============================================================================
236 void SMESH_Hypothesis_i::Update( SALOME::Notebook_ptr theNotebook )
240 //=============================================================================
242 * SMESH_Hypothesis_i::UpdateStringAttribute()
245 //=============================================================================
246 void SMESH_Hypothesis_i::UpdateStringAttribute()
248 // implementation of the method has been temporarily changed
249 // previous implementation can be found in revision 1.12.14.8
250 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
252 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
253 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
254 SALOMEDS::SObject_var aSObject = SMESH_Gen_i::ObjectToSObject( aStudy, SMESH::SMESH_Hypothesis::_narrow( _this() ) );
255 if( CORBA::is_nil( aSObject ) )
258 SALOME::StringArray* aParameters = GetParameters();
260 SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute( aSObject, "AttributeString" );
261 SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow( anAttr );
264 for( int i = 0, n = aParameters->length(); i < n; i++ ) {
265 std::string aParameter = aParameters->operator[](i).in();
266 aString += aParameter;
271 aStringAttrib->SetValue( aString.c_str() );
272 aStringAttrib->Destroy();
275 //=============================================================================
277 * SMESH_Hypothesis_i::GetImpl
281 //=============================================================================
283 ::SMESH_Hypothesis* SMESH_Hypothesis_i::GetImpl()
285 //MESSAGE( "SMESH_Hypothesis_i::GetImpl" );
289 //=============================================================================
291 * SMESH_Hypothesis_i::SaveTo
293 * Persistence: Dumps parameters to the string stream
295 //=============================================================================
297 char* SMESH_Hypothesis_i::SaveTo()
299 MESSAGE( "SMESH_Hypothesis_i::SaveTo" );
300 std::ostringstream os;
301 myBaseImpl->SaveTo( os );
302 return CORBA::string_dup( os.str().c_str() );
305 //=============================================================================
307 * SMESH_Hypothesis_i::LoadFrom
309 * Persistence: Restores parameters from string
311 //=============================================================================
313 void SMESH_Hypothesis_i::LoadFrom( const char* theStream )
315 MESSAGE( "SMESH_Hypothesis_i::LoadFrom" );
316 std::istringstream is( theStream );
317 myBaseImpl->LoadFrom( is );