IMP 001989: multi selection in "Import" dialog boxes

This commit is contained in:
vsr 2008-07-02 08:41:03 +00:00
parent dcb0b83441
commit 4324ec1b43
2 changed files with 93 additions and 62 deletions

View File

@ -169,93 +169,113 @@ using namespace std;
// Definitions // Definitions
//============================================================= //=============================================================
void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh, void ImportMeshesFromFile( SMESH::SMESH_Gen_ptr theComponentMesh,
int theCommandID) int theCommandID )
{ {
QStringList filter; QStringList filter;
string myExtension; string myExtension;
if(theCommandID == 113){ if ( theCommandID == 113 ) {
filter.append(QObject::tr("MED files (*.med)")); filter.append( QObject::tr( "MED files (*.med)" ) );
filter.append(QObject::tr("All files (*)")); filter.append( QObject::tr( "All files (*)" ) );
}else if (theCommandID == 112){ }
filter.append(QObject::tr("IDEAS files (*.unv)")); else if ( theCommandID == 112 ) {
}else if (theCommandID == 111){ filter.append( QObject::tr( "IDEAS files (*.unv)" ) );
filter.append(QObject::tr("DAT files (*.dat)")); }
else if ( theCommandID == 111 ) {
filter.append( QObject::tr( "DAT files (*.dat)" ) );
} }
QString anInitialPath = ""; QString anInitialPath = "";
if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() ) if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
anInitialPath = QDir::currentDirPath(); anInitialPath = QDir::currentDirPath();
QString filename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), QStringList filenames = SUIT_FileDlg::getOpenFileNames( SMESHGUI::desktop(),
anInitialPath, anInitialPath,
filter, filter,
QObject::tr("Import mesh"), QObject::tr( "SMESH_IMPORT_MESH" ) );
true); if ( filenames.count() > 0 ) {
if(!filename.isEmpty()) {
SUIT_OverrideCursor wc; SUIT_OverrideCursor wc;
_PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
try { QStringList errors;
bool isEmpty = false;
for ( QStringList::ConstIterator it = filenames.begin(); it != filenames.end(); ++it ) {
QString filename = *it;
SMESH::mesh_array_var aMeshes = new SMESH::mesh_array; SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
switch ( theCommandID ) { try {
case 112: switch ( theCommandID ) {
{ case 111:
aMeshes->length( 1 ); {
aMeshes[0] = theComponentMesh->CreateMeshesFromUNV(filename.latin1()); // DAT format (currently unsupported)
break; errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
} arg( QObject::tr( "SMESH_ERR_NOT_SUPPORTED_FORMAT" ) ) );
case 113: break;
{ }
SMESH::DriverMED_ReadStatus res; case 112:
aMeshes = theComponentMesh->CreateMeshesFromMED(filename.latin1(),res); {
if ( res != SMESH::DRS_OK ) { // UNV format
wc.suspend(); aMeshes->length( 1 );
SUIT_MessageBox::warn1(SMESHGUI::desktop(), aMeshes[0] = theComponentMesh->CreateMeshesFromUNV( filename.latin1() );
QObject::tr("SMESH_WRN_WARNING"), if ( aMeshes[0]->_is_nil() )
QObject::tr(QString("SMESH_DRS_%1").arg(res)), errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
QObject::tr("SMESH_BUT_OK")); arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
aMeshes->length( 0 ); break;
wc.resume(); }
case 113:
{
// MED format
SMESH::DriverMED_ReadStatus res;
aMeshes = theComponentMesh->CreateMeshesFromMED( filename.latin1(), res );
if ( res != SMESH::DRS_OK ) {
errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
arg( QObject::tr( QString( "SMESH_DRS_%1" ).arg( res ) ) ) );
}
break;
} }
break;
} }
} }
catch ( const SALOME::SALOME_Exception& S_ex ) {
errors.append( QString( "%1 :\n\t%2" ).arg( filename ).
arg( QObject::tr( "SMESH_ERR_UNKNOWN_IMPORT_ERROR" ) ) );
}
bool isEmpty = false;
for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) { for ( int i = 0, iEnd = aMeshes->length(); i < iEnd; i++ ) {
_PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] ); _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshes[i] );
if ( aMeshSO ) { if ( aMeshSO ) {
_PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
_PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" ); _PTR(AttributePixMap) aPixmap = aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" );
aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_IMPORTED"); aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import if ( theCommandID == 112 ) // mesh names aren't taken from the file for UNV import
SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() ); SMESH::SetName( aMeshSO, QFileInfo(filename).fileName() );
} else }
else {
isEmpty = true; isEmpty = true;
}
} }
if ( isEmpty ) {
wc.suspend();
SUIT_MessageBox::warn1(SMESHGUI::desktop(),
QObject::tr("SMESH_WRN_WARNING"),
QObject::tr("SMESH_DRS_EMPTY"),
QObject::tr("SMESH_BUT_OK"));
wc.resume();
}
SMESHGUI::GetSMESHGUI()->updateObjBrowser();
} }
catch (const SALOME::SALOME_Exception& S_ex){
wc.suspend(); // update Object browser
SalomeApp_Tools::QtCatchCorbaException(S_ex); SMESHGUI::GetSMESHGUI()->updateObjBrowser();
wc.resume();
// show Error message box if there were errors
if ( errors.count() > 0 ) {
SUIT_MessageBox::error1( SMESHGUI::desktop(),
QObject::tr( "SMESH_ERROR" ),
QObject::tr( "SMESH_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ),
QObject::tr( "SMESH_BUT_OK" ) );
}
// show warning message box, if some imported mesh is empty
if ( isEmpty ) {
SUIT_MessageBox::warn1( SMESHGUI::desktop(),
QObject::tr( "SMESH_WRN_WARNING" ),
QObject::tr( "SMESH_DRS_SOME_EMPTY" ),
QObject::tr( "SMESH_BUT_OK" ) );
} }
} }
} }
void ExportMeshToFile( int theCommandID ) void ExportMeshToFile( int theCommandID )
{ {
LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr(); LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();

View File

@ -1384,20 +1384,16 @@ msgid "SMESH_DRS_1"
msgstr "MED file contains no mesh with the given name" msgstr "MED file contains no mesh with the given name"
msgid "SMESH_DRS_2" msgid "SMESH_DRS_2"
msgstr "" msgstr "MED file has overlapped ranges of element numbers, the numbers from the file are ignored"
"MED file has overlapped ranges of element numbers,\n"
" the numbers from the file are ignored"
msgid "SMESH_DRS_3" msgid "SMESH_DRS_3"
msgstr "Some elements were skipped due to incorrect file data" msgstr "Some elements were skipped due to incorrect file data"
msgid "SMESH_DRS_4" msgid "SMESH_DRS_4"
msgstr " The file is incorrect,\n" msgstr "The file is incorrect, some data is missed"
"some information will be missed"
msgid "SMESH_DRS_EMPTY" msgid "SMESH_DRS_EMPTY"
msgstr " The file is empty,\n" msgstr "The file is empty, there is nothing to be published"
"there is nothing to be published"
msgid "SMESH_EXPORT_UNV" msgid "SMESH_EXPORT_UNV"
msgstr "During export mesh with name - \"%1\" to UNV\n" msgstr "During export mesh with name - \"%1\" to UNV\n"
@ -3568,3 +3564,18 @@ msgstr "File size (bytes)"
msgid "SMESHGUI_FileInfoDlg::MED_VERSION" msgid "SMESHGUI_FileInfoDlg::MED_VERSION"
msgstr "MED version" msgstr "MED version"
msgid "SMESH_IMPORT_MESH"
msgstr "Import mesh data from files"
msgid "SMESH_ERR_NOT_SUPPORTED_FORMAT"
msgstr "Unsupported file format"
msgid "SMESH_ERR_UNKNOWN_IMPORT_ERROR"
msgstr "Unknown error"
msgid "SMESH_IMPORT_ERRORS"
msgstr "Import operation has finished with errors:"
msgid "SMESH_DRS_SOME_EMPTY"
msgstr "One or more mesh files were empty, data has not been published"