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 : StdMeshers_ImportSource2D_i.cxx
27 #include "StdMeshers_ImportSource2D_i.hxx"
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Group_i.hxx"
32 #include "SMESH_PythonDump.hxx"
33 #include "StdMeshers_ObjRefUlils.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "utilities.h"
38 #include <TCollection_AsciiString.hxx>
40 #include CORBA_SERVER_HEADER(SMESH_Group)
44 //=============================================================================
46 * StdMeshers_ImportSource2D_i::StdMeshers_ImportSource2D_i
50 //=============================================================================
52 StdMeshers_ImportSource2D_i::StdMeshers_ImportSource2D_i( PortableServer::POA_ptr thePOA,
54 ::SMESH_Gen* theGenImpl )
55 : SALOME::GenericObj_i( thePOA ),
56 SMESH_Hypothesis_i( thePOA )
58 MESSAGE( "StdMeshers_ImportSource2D_i::StdMeshers_ImportSource2D_i" );
59 myBaseImpl = new ::StdMeshers_ImportSource2D( theGenImpl->GetANewId(),
62 _groupEntries = new SMESH::string_array();
65 //=============================================================================
67 * StdMeshers_ImportSource2D_i::~StdMeshers_ImportSource2D_i
71 //=============================================================================
73 StdMeshers_ImportSource2D_i::~StdMeshers_ImportSource2D_i()
75 MESSAGE( "StdMeshers_ImportSource2D_i::~StdMeshers_ImportSource2D_i" );
78 //=============================================================================
82 //=============================================================================
84 void StdMeshers_ImportSource2D_i::SetSourceFaces(const SMESH::ListOfGroups& groups)
86 MESSAGE( "StdMeshers_ImportSource2D_i::SetSourceFaces" );
90 std::vector<SMESH_Group*> smesh_groups;
91 std::vector<string> entries;
92 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
93 for ( int i = 0; i < groups.length(); ++i )
94 if ( SMESH_GroupBase_i* gp_i = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i] ))
96 if ( gp_i->GetType() != SMESH::FACE )
97 THROW_SALOME_CORBA_EXCEPTION("Wrong group type", SALOME::BAD_PARAM);
98 smesh_groups.push_back( gp_i->GetSmeshGroup() );
100 SALOMEDS::SObject_var so = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject(study, groups[i]);
103 CORBA::String_var entry = so->GetID();
104 entries.push_back( entry.in() );
107 this->GetImpl()->SetGroups( smesh_groups );
109 _groupEntries = new SMESH::string_array;
110 _groupEntries->length( entries.size ());
111 for ( int i = 0; i < entries.size(); ++i )
112 _groupEntries[i] = entries[i].c_str();
114 catch ( SALOME_Exception& S_ex )
116 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
119 // Update Python script
120 SMESH::TPythonDump() << _this() << ".SetSourceFaces( " << groups << " )";
123 //=============================================================================
125 * Return entries of groups
127 //=============================================================================
129 SMESH::string_array* StdMeshers_ImportSource2D_i::GetSourceFaces()
131 MESSAGE( "StdMeshers_ImportSource2D_i::GetImportSource" );
132 SMESH::string_array_var res = new SMESH::string_array( _groupEntries );
136 //================================================================================
138 * \brief Set to copy mesh and groups
140 //================================================================================
142 void StdMeshers_ImportSource2D_i::SetCopySourceMesh(CORBA::Boolean toCopyMesh,
143 CORBA::Boolean toCopyGroups)
145 GetImpl()->SetCopySourceMesh(toCopyMesh,toCopyGroups);
146 SMESH::TPythonDump() << _this() << ".SetCopySourceMesh( "
147 << toCopyMesh << ", " << toCopyGroups << " )";
150 //================================================================================
152 * \brief Return "to copy mesh and groups"
154 //================================================================================
156 void StdMeshers_ImportSource2D_i::GetCopySourceMesh(CORBA::Boolean& toCopyMesh,
157 CORBA::Boolean& toCopyGroups)
159 GetImpl()->GetCopySourceMesh(toCopyMesh,toCopyGroups);
162 //================================================================================
164 * \brief Write parameters in a string
165 * \retval char* - resulting string
167 //================================================================================
169 char* StdMeshers_ImportSource2D_i::SaveTo()
171 std::ostringstream os;
172 os << " " << _groupEntries->length();
174 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
175 for ( int i = 0; i < _groupEntries->length(); ++i )
178 os << " " << _groupEntries[i];
181 SALOMEDS::SObject_var groupSO = study->FindObjectID( _groupEntries[i] );
182 CORBA::Object_var groupObj;
183 if ( !groupSO->_is_nil() )
184 groupObj = groupSO->GetObject();
185 StdMeshers_ObjRefUlils::SaveToStream( groupObj, os );
188 myBaseImpl->SaveTo( os );
190 return CORBA::string_dup( os.str().c_str() );
193 //================================================================================
195 * \brief Retrieve parameters from the string
196 * \param theStream - the input string
198 //================================================================================
200 void StdMeshers_ImportSource2D_i::LoadFrom( const char* theStream )
202 std::istringstream is( theStream );
207 _groupEntries = new SMESH::string_array;
208 _groupEntries->length( nbGroups );
209 std::string id, entry;
210 for ( int i = 0; i < _groupEntries->length(); ++i )
213 _groupEntries[i] = entry.c_str();
216 _groupEntries->length( i );
217 is.clear(ios::badbit | is.rdstate());
221 _groupIDs.push_back( id );
224 is.clear(ios::badbit | is.rdstate());
229 myBaseImpl->LoadFrom( is );
232 //================================================================================
234 * \brief Retrieve groups by their ids loaded by LoadFrom()
235 * This is possible only when all meshes are fully loaded
237 //================================================================================
239 void StdMeshers_ImportSource2D_i::UpdateAsMeshesRestored()
241 std::vector<SMESH_Group*> smesh_groups;
242 for ( unsigned i = 0; i < _groupIDs.size(); ++i )
244 std::istringstream is( _groupIDs[i].c_str() );
245 SMESH::SMESH_GroupBase_var group =
246 StdMeshers_ObjRefUlils::LoadObjectFromStream<SMESH::SMESH_GroupBase>( is );
247 if ( SMESH_GroupBase_i* gp_i = SMESH::DownCast<SMESH_GroupBase_i*>( group ))
248 smesh_groups.push_back( gp_i->GetSmeshGroup() );
250 GetImpl()->RestoreGroups(smesh_groups);
253 //=============================================================================
255 * StdMeshers_ImportSource2D_i::GetImpl
259 //=============================================================================
261 ::StdMeshers_ImportSource2D* StdMeshers_ImportSource2D_i::GetImpl()
263 MESSAGE( "StdMeshers_ImportSource2D_i::GetImpl" );
264 return ( ::StdMeshers_ImportSource2D* )myBaseImpl;
267 //================================================================================
269 * \brief Verify whether hypothesis supports given entity type
270 * \param type - dimension (see SMESH::Dimension enumeration)
271 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
273 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
275 //================================================================================
276 CORBA::Boolean StdMeshers_ImportSource2D_i::IsDimSupported( SMESH::Dimension type )
278 return type == SMESH::DIM_2D;