1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
3 // Copyright (C) 2003 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
24 // File : StdMeshers_LayerDistribution_i.cxx
25 // Author : Edward AGAPOV
30 #include "StdMeshers_LayerDistribution_i.hxx"
31 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_PythonDump.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "utilities.h"
38 #include <TCollection_AsciiString.hxx>
40 //=============================================================================
42 * StdMeshers_LayerDistribution_i::StdMeshers_LayerDistribution_i
46 //=============================================================================
48 StdMeshers_LayerDistribution_i::StdMeshers_LayerDistribution_i( PortableServer::POA_ptr thePOA,
50 ::SMESH_Gen* theGenImpl )
51 : SALOME::GenericObj_i( thePOA ),
52 SMESH_Hypothesis_i( thePOA )
54 MESSAGE( "StdMeshers_LayerDistribution_i::StdMeshers_LayerDistribution_i" );
55 myBaseImpl = new ::StdMeshers_LayerDistribution( theGenImpl->GetANewId(),
60 //=============================================================================
62 * StdMeshers_LayerDistribution_i::~StdMeshers_LayerDistribution_i
66 //=============================================================================
68 StdMeshers_LayerDistribution_i::~StdMeshers_LayerDistribution_i()
70 MESSAGE( "StdMeshers_LayerDistribution_i::~StdMeshers_LayerDistribution_i" );
73 //=============================================================================
75 * StdMeshers_LayerDistribution_i::SetLayerDistribution
79 //=============================================================================
81 void StdMeshers_LayerDistribution_i::SetLayerDistribution(SMESH::SMESH_Hypothesis_ptr hyp1D)
82 throw ( SALOME::SALOME_Exception )
86 SMESH_Hypothesis_i * hyp_i = SMESH::DownCast< SMESH_Hypothesis_i*>( hyp1D );
87 bool isNewHyp = ( hyp_i->GetImpl() != this->GetImpl()->GetLayerDistribution() );
88 this->GetImpl()->SetLayerDistribution( hyp_i->GetImpl() );
89 myHyp = SMESH::SMESH_Hypothesis::_duplicate( hyp1D );
90 // Remove SO of 1D hypothesis if it was published
91 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() )
95 study->NewBuilder()->RemoveObjectWithChildren( SO );
97 // Update Python script: write creation of 1D hyp as it is not published and
98 // for this, SMESH_Gen does not write it's creation
100 SMESH::TPythonDump() << hyp1D << " = "
101 << SMESH_Gen_i::GetSMESHGen() << ".CreateHypothesis('"
102 << hyp_i->GetName() << "', '" << hyp_i->GetLibName() << "')";
104 catch ( SALOME_Exception& S_ex ) {
105 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
107 // Update Python script
108 SMESH::TPythonDump() << _this() << ".SetLayerDistribution( " << hyp1D << " )";
111 //=============================================================================
113 * StdMeshers_LayerDistribution_i::GetLayerDistribution
115 * Returns <number of layers> parameter value
117 //=============================================================================
119 SMESH::SMESH_Hypothesis_ptr StdMeshers_LayerDistribution_i::GetLayerDistribution()
121 SMESH::SMESH_Hypothesis_var hyp = myHyp;
125 //=============================================================================
127 * StdMeshers_LayerDistribution_i::GetImpl
131 //=============================================================================
133 ::StdMeshers_LayerDistribution* StdMeshers_LayerDistribution_i::GetImpl()
135 return ( ::StdMeshers_LayerDistribution* )myBaseImpl;
138 //================================================================================
140 * \brief Verify whether hypothesis supports given entity type
141 * \param type - dimension (see SMESH::Dimension enumeration)
142 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
144 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
146 //================================================================================
147 CORBA::Boolean StdMeshers_LayerDistribution_i::IsDimSupported( SMESH::Dimension type )
149 return type == SMESH::DIM_3D;
152 //================================================================================
154 * \brief Write parameters in a string
155 * \retval char* - resulting string
157 //================================================================================
159 char* StdMeshers_LayerDistribution_i::SaveTo()
161 ASSERT( myBaseImpl );
162 std::ostringstream os;
164 ::SMESH_Hypothesis* hyp1D = GetImpl()->GetLayerDistribution();
165 SMESH_Hypothesis_i* hyp1D_i = SMESH::DownCast< SMESH_Hypothesis_i*>( myHyp );
166 if ( !hyp1D || !hyp1D_i )
169 os << hyp1D->GetName() << " "
170 << hyp1D->GetLibName() << " "
171 << hyp1D_i->SaveTo();
173 //myBaseImpl->SaveTo( os );
175 return CORBA::string_dup( os.str().c_str() );
178 //================================================================================
180 * \brief Retrieve parameters from the string
181 * \param theStream - the input string
183 //================================================================================
185 void StdMeshers_LayerDistribution_i::LoadFrom( const char* theStream )
187 ASSERT( myBaseImpl );
188 std::istringstream is( theStream );
190 string typeName, libName;
191 if ( is >> typeName &&
194 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
195 SALOMEDS::Study_var curStudy = gen->GetCurrentStudy();
196 gen->SetCurrentStudy( SALOMEDS::Study::_nil() ); // prevent hypo publishing
199 SMESH::SMESH_Hypothesis_var hyp1D =
200 gen->CreateHypothesis( typeName.c_str(), libName.c_str() );
201 SMESH_Hypothesis_i* hyp1D_i = SMESH::DownCast< SMESH_Hypothesis_i*>( hyp1D );
203 hyp1D_i->LoadFrom( & theStream[ is.tellg() ]);
204 this->GetImpl()->SetLayerDistribution( hyp1D_i->GetImpl() );
206 // as hyp1D is not published, its ID changes
207 //SMESH::TPythonDump() << _this() << ".SetLayerDistribution( " << hyp1D << " )";
212 gen->SetCurrentStudy( curStudy ); // enable hypo publishing