1 // Copyright (C) 2007-2013 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 // File : StdMeshers_LayerDistribution_i.cxx
24 // Author : Edward AGAPOV
27 #include "StdMeshers_LayerDistribution_i.hxx"
28 #include "SMESH_Gen_i.hxx"
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_PythonDump.hxx"
32 #include "Utils_CorbaException.hxx"
33 #include "utilities.h"
35 #include <TCollection_AsciiString.hxx>
39 //=============================================================================
41 * StdMeshers_LayerDistribution_i::StdMeshers_LayerDistribution_i
45 //=============================================================================
47 StdMeshers_LayerDistribution_i::StdMeshers_LayerDistribution_i( PortableServer::POA_ptr thePOA,
49 ::SMESH_Gen* theGenImpl )
50 : SALOME::GenericObj_i( thePOA ),
51 SMESH_Hypothesis_i( thePOA )
53 MESSAGE( "StdMeshers_LayerDistribution_i::StdMeshers_LayerDistribution_i" );
54 myBaseImpl = new ::StdMeshers_LayerDistribution( theGenImpl->GetANewId(),
59 //=============================================================================
61 * StdMeshers_LayerDistribution_i::~StdMeshers_LayerDistribution_i
65 //=============================================================================
67 StdMeshers_LayerDistribution_i::~StdMeshers_LayerDistribution_i()
69 MESSAGE( "StdMeshers_LayerDistribution_i::~StdMeshers_LayerDistribution_i" );
72 //=============================================================================
74 * StdMeshers_LayerDistribution_i::SetLayerDistribution
78 //=============================================================================
80 void StdMeshers_LayerDistribution_i::SetLayerDistribution(SMESH::SMESH_Hypothesis_ptr hyp1D)
81 throw ( SALOME::SALOME_Exception )
85 SMESH_Hypothesis_i * hyp_i = SMESH::DownCast< SMESH_Hypothesis_i*>( hyp1D );
86 bool isNewHyp = ( hyp_i->GetImpl() != this->GetImpl()->GetLayerDistribution() );
87 this->GetImpl()->SetLayerDistribution( hyp_i->GetImpl() );
88 myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp1D );
89 // Remove SO of 1D hypothesis if it was published
90 if (SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen())
92 SALOMEDS::Study_var study = gen->GetCurrentStudy();
93 SALOMEDS::SObject_var SO = gen->ObjectToSObject( study, hyp1D );
94 if ( ! SO->_is_nil() )
96 SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
97 builder->RemoveObjectWithChildren( SO );
101 // Update Python script: write creation of 1D hyp as it is not published and
102 // for this, SMESH_Gen does not write it's creation
104 SMESH::TPythonDump() << hyp1D << " = "
105 << SMESH_Gen_i::GetSMESHGen() << ".CreateHypothesis('"
106 << hyp_i->GetName() << "', '" << hyp_i->GetLibName() << "')";
108 catch ( SALOME_Exception& S_ex ) {
109 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
111 // Update Python script
112 SMESH::TPythonDump() << _this() << ".SetLayerDistribution( " << hyp1D << " )";
115 //=============================================================================
117 * StdMeshers_LayerDistribution_i::GetLayerDistribution
119 * Returns <number of layers> parameter value
121 //=============================================================================
123 SMESH::SMESH_Hypothesis_ptr StdMeshers_LayerDistribution_i::GetLayerDistribution()
125 SMESH::SMESH_Hypothesis_var hyp = myHyp;
129 //=============================================================================
131 * StdMeshers_LayerDistribution_i::GetImpl
135 //=============================================================================
137 ::StdMeshers_LayerDistribution* StdMeshers_LayerDistribution_i::GetImpl()
139 return ( ::StdMeshers_LayerDistribution* )myBaseImpl;
142 //================================================================================
144 * \brief Verify whether hypothesis supports given entity type
145 * \param type - dimension (see SMESH::Dimension enumeration)
146 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
148 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
150 //================================================================================
151 CORBA::Boolean StdMeshers_LayerDistribution_i::IsDimSupported( SMESH::Dimension type )
153 return type == SMESH::DIM_3D;
156 //================================================================================
158 * \brief Write parameters in a string
159 * \retval char* - resulting string
161 //================================================================================
163 char* StdMeshers_LayerDistribution_i::SaveTo()
165 ASSERT( myBaseImpl );
166 std::ostringstream os;
168 ::SMESH_Hypothesis* hyp1D = GetImpl()->GetLayerDistribution();
169 SMESH_Hypothesis_i* hyp1D_i = SMESH::DownCast< SMESH_Hypothesis_i*>( myHyp );
170 if ( !hyp1D || !hyp1D_i )
173 os << hyp1D->GetName() << " "
174 << hyp1D->GetLibName() << " "
175 << hyp1D_i->SaveTo() << " ";
177 os << SMESH_Hypothesis_i::SaveTo(); // to have a mark of storage version ("VARS...")
179 return CORBA::string_dup( os.str().c_str() );
182 //================================================================================
184 * \brief Retrieve parameters from the string
185 * \param theStream - the input string
187 //================================================================================
189 void StdMeshers_LayerDistribution_i::LoadFrom( const char* theStream )
191 ASSERT( myBaseImpl );
192 std::istringstream is( theStream );
194 string typeName, libName;
195 if ( is >> typeName &&
198 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
199 SALOMEDS::Study_var curStudy = gen->GetCurrentStudy();
200 gen->SetCurrentStudy( SALOMEDS::Study::_nil() ); // prevent hypo publishing
203 SMESH::SMESH_Hypothesis_var hyp1D =
204 gen->CreateHypothesis( typeName.c_str(), libName.c_str() );
205 SMESH_Hypothesis_i* hyp1D_i = SMESH::DownCast< SMESH_Hypothesis_i*>( hyp1D );
207 hyp1D_i->LoadFrom( & theStream[ (streamoff) is.tellg()+1 ]);
208 this->GetImpl()->SetLayerDistribution( hyp1D_i->GetImpl() );
211 SMESH::SMESH_Hypothesis_var me = _this();
212 hyp1D->SetHolderHypothesis( me );
213 // as hyp1D is not published, its ID changes
214 //SMESH::TPythonDump() << _this() << ".SetLayerDistribution( " << hyp1D << " )";
216 // restore a mark of storage version ("VARS...")
217 SMESH_Hypothesis_i::LoadFrom( & theStream[ (streamoff)is.tellg()+1 ]);
222 gen->SetCurrentStudy( curStudy ); // enable hypo publishing
226 //================================================================================
228 * \brief Restore myMethod2VarParams by parameters stored in an old study
230 //================================================================================
232 void StdMeshers_LayerDistribution_i::setOldParameters (const char* theParameters)
234 if ( SMESH_Hypothesis_i* hyp1D_i = SMESH::DownCast< SMESH_Hypothesis_i*>( myHyp ))
235 hyp1D_i->setOldParameters( theParameters );