Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "StdMeshers_ImportSource1D_i.hxx"
00028
00029 #include "SMESH_Gen.hxx"
00030 #include "SMESH_Gen_i.hxx"
00031 #include "SMESH_Group_i.hxx"
00032 #include "SMESH_PythonDump.hxx"
00033 #include "StdMeshers_ObjRefUlils.hxx"
00034
00035 #include "Utils_CorbaException.hxx"
00036 #include "utilities.h"
00037
00038 #include <TCollection_AsciiString.hxx>
00039
00040 #include CORBA_SERVER_HEADER(SMESH_Group)
00041
00042 using namespace std;
00043
00044
00050
00051
00052 StdMeshers_ImportSource1D_i::StdMeshers_ImportSource1D_i( PortableServer::POA_ptr thePOA,
00053 int theStudyId,
00054 ::SMESH_Gen* theGenImpl )
00055 : SALOME::GenericObj_i( thePOA ),
00056 SMESH_Hypothesis_i( thePOA )
00057 {
00058 MESSAGE( "StdMeshers_ImportSource1D_i::StdMeshers_ImportSource1D_i" );
00059 myBaseImpl = new ::StdMeshers_ImportSource1D( theGenImpl->GetANewId(),
00060 theStudyId,
00061 theGenImpl );
00062 _groupEntries = new SMESH::string_array();
00063 }
00064
00065
00071
00072
00073 StdMeshers_ImportSource1D_i::~StdMeshers_ImportSource1D_i()
00074 {
00075 MESSAGE( "StdMeshers_ImportSource1D_i::~StdMeshers_ImportSource1D_i" );
00076 }
00077
00078
00082
00083
00084 void StdMeshers_ImportSource1D_i::SetSourceEdges(const SMESH::ListOfGroups& groups)
00085 {
00086 MESSAGE( "StdMeshers_ImportSource1D_i::SetSourceEdges" );
00087 ASSERT( myBaseImpl );
00088 try
00089 {
00090 std::vector<SMESH_Group*> smesh_groups;
00091 std::vector<string> entries;
00092 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
00093 for ( int i = 0; i < groups.length(); ++i )
00094 if ( SMESH_GroupBase_i* gp_i = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i] ))
00095 {
00096 if ( gp_i->GetType() != SMESH::EDGE )
00097 THROW_SALOME_CORBA_EXCEPTION("Wrong group type", SALOME::BAD_PARAM);
00098 smesh_groups.push_back( gp_i->GetSmeshGroup() );
00099
00100 SALOMEDS::SObject_var so = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject(study, groups[i]);
00101 if ( !so->_is_nil())
00102 {
00103 CORBA::String_var entry = so->GetID();
00104 entries.push_back( entry.in() );
00105 }
00106 }
00107 this->GetImpl()->SetGroups( smesh_groups );
00108
00109 _groupEntries = new SMESH::string_array;
00110 _groupEntries->length( entries.size ());
00111 for ( int i = 0; i < entries.size(); ++i )
00112 _groupEntries[i] = entries[i].c_str();
00113 }
00114 catch ( SALOME_Exception& S_ex )
00115 {
00116 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00117 }
00118
00119
00120 SMESH::TPythonDump() << _this() << ".SetSourceEdges( " << groups << " )";
00121 }
00122
00123
00127
00128
00129 SMESH::string_array* StdMeshers_ImportSource1D_i::GetSourceEdges()
00130 {
00131 MESSAGE( "StdMeshers_ImportSource1D_i::GetImportSource" );
00132 SMESH::string_array_var res = new SMESH::string_array( _groupEntries );
00133 return res._retn();
00134 }
00135
00136
00140
00141
00142 void StdMeshers_ImportSource1D_i::SetCopySourceMesh(CORBA::Boolean toCopyMesh,
00143 CORBA::Boolean toCopyGroups)
00144 {
00145 GetImpl()->SetCopySourceMesh(toCopyMesh,toCopyGroups);
00146 SMESH::TPythonDump() << _this() << ".SetCopySourceMesh( "
00147 << toCopyMesh << ", " << toCopyGroups << " )";
00148 }
00149
00150
00154
00155
00156 void StdMeshers_ImportSource1D_i::GetCopySourceMesh(CORBA::Boolean& toCopyMesh,
00157 CORBA::Boolean& toCopyGroups)
00158 {
00159 GetImpl()->GetCopySourceMesh(toCopyMesh,toCopyGroups);
00160 }
00161
00162
00167
00168
00169 char* StdMeshers_ImportSource1D_i::SaveTo()
00170 {
00171 std::ostringstream os;
00172 os << " " << _groupEntries->length();
00173
00174 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
00175 for ( int i = 0; i < _groupEntries->length(); ++i )
00176 {
00177
00178 os << " " << _groupEntries[i];
00179
00180
00181 SALOMEDS::SObject_var groupSO = study->FindObjectID( _groupEntries[i] );
00182 CORBA::Object_var groupObj;
00183 if ( !groupSO->_is_nil() )
00184 groupObj = groupSO->GetObject();
00185 StdMeshers_ObjRefUlils::SaveToStream( groupObj, os );
00186 }
00187
00188 myBaseImpl->SaveTo( os );
00189
00190 return CORBA::string_dup( os.str().c_str() );
00191 }
00192
00193
00198
00199
00200 void StdMeshers_ImportSource1D_i::LoadFrom( const char* theStream )
00201 {
00202 std::istringstream is( theStream );
00203
00204 int nbGroups;
00205 is >> nbGroups;
00206
00207 _groupEntries = new SMESH::string_array;
00208 _groupEntries->length( nbGroups );
00209 std::string id, entry;
00210 for ( int i = 0; i < _groupEntries->length(); ++i )
00211 {
00212 if ( is >> entry )
00213 _groupEntries[i] = entry.c_str();
00214 else
00215 {
00216 _groupEntries->length( i );
00217 is.clear(ios::badbit | is.rdstate());
00218 break;
00219 }
00220 if ( is >> id )
00221 _groupIDs.push_back( id );
00222 else
00223 {
00224 is.clear(ios::badbit | is.rdstate());
00225 break;
00226 }
00227 }
00228
00229 myBaseImpl->LoadFrom( is );
00230 }
00231
00232
00237
00238
00239 void StdMeshers_ImportSource1D_i::UpdateAsMeshesRestored()
00240 {
00241 std::vector<SMESH_Group*> smesh_groups;
00242 for ( unsigned i = 0; i < _groupIDs.size(); ++i )
00243 {
00244 std::istringstream is( _groupIDs[i].c_str() );
00245 SMESH::SMESH_GroupBase_var group =
00246 StdMeshers_ObjRefUlils::LoadObjectFromStream<SMESH::SMESH_GroupBase>( is );
00247 if ( SMESH_GroupBase_i* gp_i = SMESH::DownCast<SMESH_GroupBase_i*>( group ))
00248 smesh_groups.push_back( gp_i->GetSmeshGroup() );
00249 }
00250 GetImpl()->RestoreGroups(smesh_groups);
00251 }
00252
00253
00259
00260
00261 ::StdMeshers_ImportSource1D* StdMeshers_ImportSource1D_i::GetImpl()
00262 {
00263 MESSAGE( "StdMeshers_ImportSource1D_i::GetImpl" );
00264 return ( ::StdMeshers_ImportSource1D* )myBaseImpl;
00265 }
00266
00267
00275
00276 CORBA::Boolean StdMeshers_ImportSource1D_i::IsDimSupported( SMESH::Dimension type )
00277 {
00278 return type == SMESH::DIM_1D;
00279 }
00280