1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 )
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 return CORBA::string_dup( myBaseImpl->GetName() );
81 //=============================================================================
83 * SMESH_Hypothesis_i::GetLibName
85 * Get plugin library name of hypothesis (required by persistency mechanism)
87 //=============================================================================
89 char* SMESH_Hypothesis_i::GetLibName()
91 return CORBA::string_dup( myBaseImpl->GetLibName() );
94 //=============================================================================
96 * SMESH_Hypothesis_i::SetLibName
98 * Set plugin library name of hypothesis (required by persistency mechanism)
100 //=============================================================================
102 void SMESH_Hypothesis_i::SetLibName(const char* theLibName)
104 myBaseImpl->SetLibName( theLibName );
107 //=============================================================================
109 * SMESH_Hypothesis_i::GetId
111 * Get unique id of hypothesis
113 //=============================================================================
115 CORBA::Long SMESH_Hypothesis_i::GetId()
117 return myBaseImpl->GetID();
120 //=============================================================================
122 * SMESH_Hypothesis_i::IsPublished()
125 //=============================================================================
126 bool SMESH_Hypothesis_i::IsPublished()
129 if ( SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen())
131 SALOMEDS::Study_var study = gen->GetCurrentStudy();
132 SALOMEDS::SObject_wrap SO = SMESH_Gen_i::ObjectToSObject( study, _this());
133 res = !SO->_is_nil();
138 //================================================================================
140 * \brief Set the pramIndex-th parameter
142 //================================================================================
144 void SMESH_Hypothesis_i::SetVarParameter (const char* theParameter,
145 const char* theMethod)
147 if ( SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen() )
149 SMESH::SMESH_Hypothesis_var varHolder;
150 if ( myHolder->_is_nil() ) varHolder = _this();
151 else varHolder = myHolder;
152 gen->UpdateParameters( varHolder, theParameter );
154 const std::vector< std::string >& pars = gen->GetLastParameters();
156 myMethod2VarParams[ theMethod ] = pars[0];
160 //================================================================================
162 * \brief Return the pramIndex-th variable parameter used for Hypothesis creation
164 //================================================================================
166 char* SMESH_Hypothesis_i::GetVarParameter (const char* theMethod)
168 if ( myMethod2VarParams.count("needs update by old study"))
170 // restore myMethod2VarParams by old study
171 myMethod2VarParams.clear();
172 if ( SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen() )
174 CORBA::String_var oldparVar = gen->GetParameters( _this() );
175 setOldParameters( oldparVar.in() );
178 std::map< std::string, std::string >::iterator meth_param = myMethod2VarParams.find( theMethod );
179 if ( meth_param != myMethod2VarParams.end() )
180 return CORBA::string_dup( meth_param->second.c_str() );
182 return CORBA::string_dup("");
185 //================================================================================
187 * \brief Store a hypothesis wrapping this not published one.
189 * This hyp, which has no own parameters but is published, is used to store variables
190 * defining parameters of this hypothesis.
192 //================================================================================
194 void SMESH_Hypothesis_i::SetHolderHypothesis(const SMESH::SMESH_Hypothesis_ptr hyp)
196 myHolder = SMESH::SMESH_Hypothesis::_duplicate( hyp );
199 //================================================================================
201 * \brief Restore myMethod2VarParams by parameters stored in an old study
203 //================================================================================
205 void SMESH_Hypothesis_i::setOldParameters (const char* theParameters)
207 if ( SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen() )
209 TCollection_AsciiString aOldParameters(theParameters);
210 int pos = aOldParameters.SearchFromEnd("|");
211 if ( pos >= 0 ) aOldParameters = aOldParameters.Split(pos);
212 pos = aOldParameters.SearchFromEnd(";*=");
213 if ( pos >= 0 ) aOldParameters.Split(pos-1);
214 gen->UpdateParameters( CORBA::Object_var( _this() ).in(), aOldParameters.ToCString() );
216 myMethod2VarParams.clear();
217 const std::vector< std::string >& pars = gen->GetLastParameters();
218 for ( size_t i = 0; i < pars.size(); ++i )
220 std::string meth = getMethodOfParameter( i, pars.size() );
221 myMethod2VarParams[ meth ] = pars[i];
223 gen->UpdateParameters( CORBA::Object_var( _this() ).in(), "" ); // clear params
227 //=============================================================================
229 * SMESH_Hypothesis_i::GetImpl
233 //=============================================================================
235 ::SMESH_Hypothesis* SMESH_Hypothesis_i::GetImpl()
240 //================================================================================
242 * \brief Return true if a hypothesis has parameters
244 //================================================================================
246 CORBA::Boolean SMESH_Hypothesis_i::HasParameters()
248 std::ostringstream os;
249 myBaseImpl->SaveTo( os );
250 return ( !os.str().empty() );
253 //=============================================================================
255 * SMESH_Hypothesis_i::SaveTo
257 * Persistence: Dumps parameters to the string stream
259 //=============================================================================
261 char* SMESH_Hypothesis_i::SaveTo()
263 std::ostringstream os;
265 // assure that parameters are loaded from an old study
266 CORBA::String_var p = GetVarParameter("");
268 os << "VARS " << myMethod2VarParams.size() << " ";
269 std::map< std::string, std::string >::iterator meth_param = myMethod2VarParams.begin();
270 for ( ; meth_param != myMethod2VarParams.end(); ++meth_param )
271 os << meth_param->first << " "
272 << meth_param->second.size() << " "
273 << meth_param->second << " ";
275 myBaseImpl->SaveTo( os );
276 return CORBA::string_dup( os.str().c_str() );
279 //=============================================================================
281 * SMESH_Hypothesis_i::LoadFrom
283 * Persistence: Restores parameters from string
285 //=============================================================================
287 void SMESH_Hypothesis_i::LoadFrom( const char* theStream )
289 std::istringstream is( theStream );
290 if ( strncmp( theStream, "VARS", 4 ) == 0 )
296 for ( int i = 0; i < nbVars; ++i )
301 is.get( str, len + 2 ); // 2 - to read at least 1 white space
303 myMethod2VarParams[ meth ] = std::string( str+1, len );
309 // we can't restore myMethod2VarParams by old study here because SObject
310 // isn't yet bound to _this()
311 myMethod2VarParams["needs update by old study"] = "yes";
314 myBaseImpl->LoadFrom( is );
316 // let listeners know about loading (issue 0020918)
317 myBaseImpl->NotifySubMeshesHypothesisModification();
320 //================================================================================
322 * \brief This mesthod is called after completion of loading a study
324 //================================================================================
326 void SMESH_Hypothesis_i::UpdateAsMeshesRestored()
328 // for hyps needing full data restored