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 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : StdMeshers_ImportSource1D_i.cxx
27 #include "StdMeshers_ImportSource1D_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>
37 #include <SALOMEDS_wrap.hxx>
39 #include <TCollection_AsciiString.hxx>
41 #include CORBA_SERVER_HEADER(SMESH_Group)
45 //=============================================================================
47 * StdMeshers_ImportSource1D_i::StdMeshers_ImportSource1D_i
51 //=============================================================================
53 StdMeshers_ImportSource1D_i::StdMeshers_ImportSource1D_i( PortableServer::POA_ptr thePOA,
55 ::SMESH_Gen* theGenImpl )
56 : SALOME::GenericObj_i( thePOA ),
57 SMESH_Hypothesis_i( thePOA )
59 MESSAGE( "StdMeshers_ImportSource1D_i::StdMeshers_ImportSource1D_i" );
60 myBaseImpl = new ::StdMeshers_ImportSource1D( theGenImpl->GetANewId(),
63 _groupEntries = new SMESH::string_array();
66 //=============================================================================
68 * StdMeshers_ImportSource1D_i::~StdMeshers_ImportSource1D_i
72 //=============================================================================
74 StdMeshers_ImportSource1D_i::~StdMeshers_ImportSource1D_i()
76 MESSAGE( "StdMeshers_ImportSource1D_i::~StdMeshers_ImportSource1D_i" );
79 //=============================================================================
83 //=============================================================================
85 void StdMeshers_ImportSource1D_i::SetSourceEdges(const SMESH::ListOfGroups& groups)
87 MESSAGE( "StdMeshers_ImportSource1D_i::SetSourceEdges" );
91 std::vector<SMESH_Group*> smesh_groups;
92 std::vector<string> entries;
93 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
94 for ( int i = 0; i < groups.length(); ++i )
95 if ( SMESH_GroupBase_i* gp_i = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i] ))
97 if ( gp_i->GetType() != SMESH::EDGE )
98 THROW_SALOME_CORBA_EXCEPTION("Wrong group type", SALOME::BAD_PARAM);
99 smesh_groups.push_back( gp_i->GetSmeshGroup() );
101 SALOMEDS::SObject_wrap so = SMESH_Gen_i::ObjectToSObject(study, groups[i]);
104 CORBA::String_var entry = so->GetID();
105 entries.push_back( entry.in() );
108 this->GetImpl()->SetGroups( smesh_groups );
110 _groupEntries = new SMESH::string_array;
111 _groupEntries->length( entries.size ());
112 for ( int i = 0; i < entries.size(); ++i )
113 _groupEntries[i] = entries[i].c_str();
115 catch ( SALOME_Exception& S_ex )
117 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
120 // Update Python script
121 SMESH::TPythonDump() << _this() << ".SetSourceEdges( " << groups << " )";
124 //=============================================================================
126 * Return entries of groups
128 //=============================================================================
130 SMESH::string_array* StdMeshers_ImportSource1D_i::GetSourceEdges()
132 MESSAGE( "StdMeshers_ImportSource1D_i::GetImportSource" );
133 SMESH::string_array_var res = new SMESH::string_array( _groupEntries );
137 //================================================================================
139 * \brief Set to copy mesh and groups
141 //================================================================================
143 void StdMeshers_ImportSource1D_i::SetCopySourceMesh(CORBA::Boolean toCopyMesh,
144 CORBA::Boolean toCopyGroups)
146 GetImpl()->SetCopySourceMesh(toCopyMesh,toCopyGroups);
147 SMESH::TPythonDump() << _this() << ".SetCopySourceMesh( "
148 << toCopyMesh << ", " << toCopyGroups << " )";
151 //================================================================================
153 * \brief Return "to copy mesh and groups"
155 //================================================================================
157 void StdMeshers_ImportSource1D_i::GetCopySourceMesh(CORBA::Boolean& toCopyMesh,
158 CORBA::Boolean& toCopyGroups)
160 GetImpl()->GetCopySourceMesh(toCopyMesh,toCopyGroups);
163 //================================================================================
165 * \brief Write parameters in a string
166 * \retval char* - resulting string
168 //================================================================================
170 char* StdMeshers_ImportSource1D_i::SaveTo()
172 std::ostringstream os;
173 os << " " << _groupEntries->length();
175 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
176 for ( int i = 0; i < _groupEntries->length(); ++i )
179 os << " " << _groupEntries[i];
182 SALOMEDS::SObject_wrap groupSO = study->FindObjectID( _groupEntries[i] );
183 CORBA::Object_var groupObj;
184 if ( !groupSO->_is_nil() )
185 groupObj = groupSO->GetObject();
186 StdMeshers_ObjRefUlils::SaveToStream( groupObj, os );
189 myBaseImpl->SaveTo( os );
191 return CORBA::string_dup( os.str().c_str() );
194 //================================================================================
196 * \brief Retrieve parameters from the string
197 * \param theStream - the input string
199 //================================================================================
201 void StdMeshers_ImportSource1D_i::LoadFrom( const char* theStream )
203 std::istringstream is( theStream );
208 _groupEntries = new SMESH::string_array;
209 _groupEntries->length( nbGroups );
210 std::string id, entry;
211 for ( int i = 0; i < _groupEntries->length(); ++i )
214 _groupEntries[i] = entry.c_str();
217 _groupEntries->length( i );
218 is.clear(ios::badbit | is.rdstate());
222 _groupIDs.push_back( id );
225 is.clear(ios::badbit | is.rdstate());
230 myBaseImpl->LoadFrom( is );
233 //================================================================================
235 * \brief Retrieve groups by their ids loaded by LoadFrom()
236 * This is possible only when all meshes are fully loaded
238 //================================================================================
240 void StdMeshers_ImportSource1D_i::UpdateAsMeshesRestored()
242 std::vector<SMESH_Group*> smesh_groups;
243 for ( unsigned i = 0; i < _groupIDs.size(); ++i )
245 std::istringstream is( _groupIDs[i].c_str() );
246 SMESH::SMESH_GroupBase_var group =
247 StdMeshers_ObjRefUlils::LoadObjectFromStream<SMESH::SMESH_GroupBase>( is );
248 if ( SMESH_GroupBase_i* gp_i = SMESH::DownCast<SMESH_GroupBase_i*>( group ))
249 smesh_groups.push_back( gp_i->GetSmeshGroup() );
251 GetImpl()->RestoreGroups(smesh_groups);
254 //=============================================================================
256 * StdMeshers_ImportSource1D_i::GetImpl
260 //=============================================================================
262 ::StdMeshers_ImportSource1D* StdMeshers_ImportSource1D_i::GetImpl()
264 MESSAGE( "StdMeshers_ImportSource1D_i::GetImpl" );
265 return ( ::StdMeshers_ImportSource1D* )myBaseImpl;
268 //================================================================================
270 * \brief Verify whether hypothesis supports given entity type
271 * \param type - dimension (see SMESH::Dimension enumeration)
272 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
274 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
276 //================================================================================
277 CORBA::Boolean StdMeshers_ImportSource1D_i::IsDimSupported( SMESH::Dimension type )
279 return type == SMESH::DIM_1D;