1 // Copyright (C) 2007-2022 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 classes
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,
54 ::SMESH_Gen* theGenImpl )
55 : SALOME::GenericObj_i( thePOA ),
56 SMESH_Hypothesis_i( thePOA )
58 myBaseImpl = new ::StdMeshers_ImportSource1D( theGenImpl->GetANewId(),
60 _groupEntries = new SMESH::string_array();
63 //=============================================================================
65 * StdMeshers_ImportSource1D_i::~StdMeshers_ImportSource1D_i
69 //=============================================================================
71 StdMeshers_ImportSource1D_i::~StdMeshers_ImportSource1D_i()
75 //=============================================================================
79 //=============================================================================
81 void StdMeshers_ImportSource1D_i::SetSourceEdges(const SMESH::ListOfGroups& groups)
86 std::vector<SMESH_Group*> smesh_groups;
87 std::vector<string> entries;
88 for ( CORBA::ULong i = 0; i < groups.length(); ++i )
89 if ( SMESH_GroupBase_i* gp_i = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i] ))
91 if ( gp_i->GetType() != SMESH::EDGE )
92 THROW_SALOME_CORBA_EXCEPTION("Wrong group type", SALOME::BAD_PARAM);
93 smesh_groups.push_back( gp_i->GetSmeshGroup() );
95 SALOMEDS::SObject_wrap so = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject(groups[i]);
98 CORBA::String_var entry = so->GetID();
99 entries.push_back( entry.in() );
102 this->GetImpl()->SetGroups( smesh_groups );
104 _groupEntries = new SMESH::string_array;
105 _groupEntries->length( entries.size ());
106 for ( size_t i = 0; i < entries.size(); ++i )
107 _groupEntries[i] = entries[i].c_str();
109 catch ( SALOME_Exception& S_ex )
111 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
114 // Update Python script
115 SMESH::TPythonDump() << _this() << ".SetSourceEdges( " << groups << " )";
118 //=============================================================================
120 * Return entries of groups
122 //=============================================================================
124 SMESH::string_array* StdMeshers_ImportSource1D_i::GetSourceEdges()
126 SMESH::string_array_var res = new SMESH::string_array( _groupEntries );
130 //================================================================================
132 * \brief Set to copy mesh and groups
134 //================================================================================
136 void StdMeshers_ImportSource1D_i::SetCopySourceMesh(CORBA::Boolean toCopyMesh,
137 CORBA::Boolean toCopyGroups)
139 GetImpl()->SetCopySourceMesh(toCopyMesh,toCopyGroups);
140 SMESH::TPythonDump() << _this() << ".SetCopySourceMesh( "
141 << toCopyMesh << ", " << toCopyGroups << " )";
144 //================================================================================
146 * \brief Return "to copy mesh and groups"
148 //================================================================================
150 void StdMeshers_ImportSource1D_i::GetCopySourceMesh(CORBA::Boolean& toCopyMesh,
151 CORBA::Boolean& toCopyGroups)
153 GetImpl()->GetCopySourceMesh(toCopyMesh,toCopyGroups);
156 //================================================================================
158 * \brief Write parameters in a string
159 * \retval char* - resulting string
161 //================================================================================
163 char* StdMeshers_ImportSource1D_i::SaveTo()
165 std::ostringstream os;
166 os << " " << _groupEntries->length();
168 for ( size_t i = 0; i < _groupEntries->length(); ++i )
171 os << " " << _groupEntries[i];
174 SALOMEDS::SObject_wrap groupSO = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( _groupEntries[i] );
175 CORBA::Object_var groupObj;
176 if ( !groupSO->_is_nil() )
177 groupObj = groupSO->GetObject();
178 StdMeshers_ObjRefUlils::SaveToStream( groupObj, os );
181 myBaseImpl->SaveTo( os );
183 return CORBA::string_dup( os.str().c_str() );
186 //================================================================================
188 * \brief Retrieve parameters from the string
189 * \param theStream - the input string
191 //================================================================================
193 void StdMeshers_ImportSource1D_i::LoadFrom( const char* theStream )
195 std::istringstream is( theStream );
200 _groupEntries = new SMESH::string_array;
201 _groupEntries->length( nbGroups );
202 std::string id, entry;
203 for ( size_t i = 0; i < _groupEntries->length(); ++i )
206 _groupEntries[i] = entry.c_str();
209 _groupEntries->length( i );
210 is.clear(ios::badbit | is.rdstate());
214 _groupIDs.push_back( id );
217 is.clear(ios::badbit | is.rdstate());
222 myBaseImpl->LoadFrom( is );
225 //================================================================================
227 * \brief Retrieve groups by their ids loaded by LoadFrom()
228 * This is possible only when all meshes are fully loaded
230 //================================================================================
232 void StdMeshers_ImportSource1D_i::UpdateAsMeshesRestored()
234 std::vector<SMESH_Group*> smesh_groups;
235 for ( unsigned i = 0; i < _groupIDs.size(); ++i )
237 std::istringstream is( _groupIDs[i].c_str() );
238 SMESH::SMESH_GroupBase_var group =
239 StdMeshers_ObjRefUlils::LoadObjectFromStream<SMESH::SMESH_GroupBase>( is );
240 if ( SMESH_GroupBase_i* gp_i = SMESH::DownCast<SMESH_GroupBase_i*>( group ))
241 smesh_groups.push_back( gp_i->GetSmeshGroup() );
243 GetImpl()->RestoreGroups(smesh_groups);
246 //=============================================================================
248 * StdMeshers_ImportSource1D_i::GetImpl
252 //=============================================================================
254 ::StdMeshers_ImportSource1D* StdMeshers_ImportSource1D_i::GetImpl()
256 return ( ::StdMeshers_ImportSource1D* )myBaseImpl;
259 //================================================================================
261 * \brief Verify whether hypothesis supports given entity type
262 * \param type - dimension (see SMESH::Dimension enumeration)
263 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
265 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
267 //================================================================================
268 CORBA::Boolean StdMeshers_ImportSource1D_i::IsDimSupported( SMESH::Dimension type )
270 return type == SMESH::DIM_1D;