1 // Copyright (C) 2007-2012 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
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : SMESH_Hypothesis_i.cxx
25 // Author : Paul RASCLE, EDF
28 #include "SMESH_Hypothesis_i.hxx"
29 #include "SMESH_Gen_i.hxx"
31 #include <utilities.h>
32 #include <SALOMEDS_wrap.hxx>
39 //=============================================================================
41 * SMESH_Hypothesis_i::SMESH_Hypothesis_i
45 //=============================================================================
47 SMESH_Hypothesis_i::SMESH_Hypothesis_i( PortableServer::POA_ptr thePOA )
48 : SALOME::GenericObj_i( thePOA )
50 MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Début" );
53 MESSAGE( "SMESH_Hypothesis_i::SMESH_Hypothesis_i / Fin" );
56 //=============================================================================
58 * SMESH_Hypothesis_i::~SMESH_Hypothesis_i
62 //=============================================================================
64 SMESH_Hypothesis_i::~SMESH_Hypothesis_i()
66 MESSAGE( "SMESH_Hypothesis_i::~SMESH_Hypothesis_i" );
71 //=============================================================================
73 * SMESH_Hypothesis_i::GetName
75 * Get type name of hypothesis
77 //=============================================================================
79 char* SMESH_Hypothesis_i::GetName()
81 //MESSAGE( "SMESH_Hypothesis_i::GetName" );
82 return CORBA::string_dup( myBaseImpl->GetName() );
85 //=============================================================================
87 * SMESH_Hypothesis_i::GetLibName
89 * Get plugin library name of hypothesis (required by persistency mechanism)
91 //=============================================================================
93 char* SMESH_Hypothesis_i::GetLibName()
95 MESSAGE( "SMESH_Hypothesis_i::GetLibName" );
96 return CORBA::string_dup( myBaseImpl->GetLibName() );
99 //=============================================================================
101 * SMESH_Hypothesis_i::SetLibName
103 * Set plugin library name of hypothesis (required by persistency mechanism)
105 //=============================================================================
107 void SMESH_Hypothesis_i::SetLibName(const char* theLibName)
109 MESSAGE( "SMESH_Hypothesis_i::SetLibName" );
110 myBaseImpl->SetLibName( theLibName );
113 //=============================================================================
115 * SMESH_Hypothesis_i::GetId
117 * Get unique id of hypothesis
119 //=============================================================================
121 CORBA::Long SMESH_Hypothesis_i::GetId()
123 MESSAGE( "SMESH_Hypothesis_i::GetId" );
124 return myBaseImpl->GetID();
127 //=============================================================================
129 * SMESH_Hypothesis_i::IsPublished()
132 //=============================================================================
133 bool SMESH_Hypothesis_i::IsPublished()
136 if ( SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen())
138 SALOMEDS::Study_var study = gen->GetCurrentStudy();
139 SALOMEDS::SObject_wrap SO = SMESH_Gen_i::ObjectToSObject( study, _this());
140 res = !SO->_is_nil();
145 //================================================================================
147 * \brief Set the pramIndex-th parameter
149 //================================================================================
151 void SMESH_Hypothesis_i::SetVarParameter (const char* theParameter,
152 const char* theMethod)
154 if ( SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen() )
156 gen->UpdateParameters(theParameter);
158 const std::vector< std::string >& pars = gen->GetLastParameters();
160 myMethod2VarParams[ theMethod ] = pars[0];
164 //================================================================================
166 * \brief Return the pramIndex-th variable parameter used for Hypothesis creation
168 //================================================================================
170 char* SMESH_Hypothesis_i::GetVarParameter (const char* theMethod)
172 if ( myMethod2VarParams.count("needs update by old study"))
174 // restore myMethod2VarParams by old study
175 myMethod2VarParams.clear();
176 if ( SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen() )
178 CORBA::String_var oldparVar = gen->GetParameters( _this() );
179 setOldParameters( oldparVar.in() );
182 std::map< std::string, std::string >::iterator meth_param = myMethod2VarParams.find( theMethod );
183 if ( meth_param != myMethod2VarParams.end() )
184 return CORBA::string_dup( meth_param->second.c_str() );
186 return CORBA::string_dup("");
189 //================================================================================
191 * \brief Restore myMethod2VarParams by parameters stored in an old study
193 //================================================================================
195 void SMESH_Hypothesis_i::setOldParameters (const char* theParameters)
197 if ( SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen() )
199 TCollection_AsciiString aOldParameters(theParameters);
200 int pos = aOldParameters.SearchFromEnd("|");
201 if ( pos >= 0 ) aOldParameters = aOldParameters.Split(pos);
202 pos = aOldParameters.SearchFromEnd(";*=");
203 if ( pos >= 0 ) aOldParameters.Split(pos-1);
204 gen->UpdateParameters( aOldParameters.ToCString() );
206 myMethod2VarParams.clear();
207 const std::vector< std::string >& pars = gen->GetLastParameters();
208 for ( size_t i = 0; i < pars.size(); ++i )
210 std::string meth = getMethodOfParameter( i, pars.size() );
211 myMethod2VarParams[ meth ] = pars[i];
213 gen->UpdateParameters(""); // clear params
217 //=============================================================================
219 * SMESH_Hypothesis_i::GetImpl
223 //=============================================================================
225 ::SMESH_Hypothesis* SMESH_Hypothesis_i::GetImpl()
230 //=============================================================================
232 * SMESH_Hypothesis_i::SaveTo
234 * Persistence: Dumps parameters to the string stream
236 //=============================================================================
238 char* SMESH_Hypothesis_i::SaveTo()
240 std::ostringstream os;
242 // assure that parameters are loaded from an old study
243 CORBA::String_var p = GetVarParameter("");
245 os << "VARS " << myMethod2VarParams.size() << " ";
246 std::map< std::string, std::string >::iterator meth_param = myMethod2VarParams.begin();
247 for ( ; meth_param != myMethod2VarParams.end(); ++meth_param )
248 os << meth_param->first << " "
249 << meth_param->second.size() << " "
250 << meth_param->second << " ";
252 myBaseImpl->SaveTo( os );
253 return CORBA::string_dup( os.str().c_str() );
256 //=============================================================================
258 * SMESH_Hypothesis_i::LoadFrom
260 * Persistence: Restores parameters from string
262 //=============================================================================
264 void SMESH_Hypothesis_i::LoadFrom( const char* theStream )
266 std::istringstream is( theStream );
267 if ( strncmp( theStream, "VARS", 4 ) == 0 )
273 for ( int i = 0; i < nbVars; ++i )
278 is.get( str, len + 2 ); // 2 - to read at least 1 white space
280 myMethod2VarParams[ meth ] = std::string( str+1, len );
286 // we can't restore myMethod2VarParams by old study here because SObject
287 // isn't yet bound to _this()
288 myMethod2VarParams["needs update by old study"] = "yes";
291 myBaseImpl->LoadFrom( is );
293 // let listeners know about loading (issue 0020918)
294 myBaseImpl->NotifySubMeshesHypothesisModification();
297 //================================================================================
299 * \brief This mesthod is called after completion of loading a study
301 //================================================================================
303 void SMESH_Hypothesis_i::UpdateAsMeshesRestored()
305 // for hyps needing full data restored