mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-01-05 22:30:34 +05:00
IMP 001989: multi selection in "Import" dialog boxes
This commit is contained in:
parent
ed2699c47a
commit
a400bda077
@ -3343,9 +3343,14 @@ msgstr "Compound"
|
|||||||
msgid "MEN_ALL_SEL_ONLY"
|
msgid "MEN_ALL_SEL_ONLY"
|
||||||
msgstr "Select All"
|
msgstr "Select All"
|
||||||
|
|
||||||
|
msgid "GEOM_ALL_IMPORT_FILES"
|
||||||
|
msgstr "All supported formats ( %1 )"
|
||||||
|
|
||||||
|
msgid "GEOM_UNSUPPORTED_TYPE"
|
||||||
|
msgstr "Unsupported format for the file"
|
||||||
|
|
||||||
|
msgid "GEOM_UNKNOWN_IMPORT_ERROR"
|
||||||
|
msgstr "Unknown error"
|
||||||
|
|
||||||
|
msgid "GEOM_IMPORT_ERRORS"
|
||||||
|
msgstr "Import operation has finished with errors:"
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
// QT Includes
|
// QT Includes
|
||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
#include <qmap.h>
|
#include <qmap.h>
|
||||||
|
#include <qregexp.h>
|
||||||
|
|
||||||
// OCCT Includes
|
// OCCT Includes
|
||||||
#include <TCollection_AsciiString.hxx>
|
#include <TCollection_AsciiString.hxx>
|
||||||
@ -65,6 +66,7 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
typedef QMap<QString, QString> FilterMap;
|
typedef QMap<QString, QString> FilterMap;
|
||||||
|
static QString lastUsedFilter;
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
// function : getFileName
|
// function : getFileName
|
||||||
@ -80,7 +82,6 @@ static QString getFileName( QWidget* parent,
|
|||||||
QString& format,
|
QString& format,
|
||||||
bool showCurrentDirInitially = false)
|
bool showCurrentDirInitially = false)
|
||||||
{
|
{
|
||||||
static QString lastUsedFilter;
|
|
||||||
//QStringList filters;
|
//QStringList filters;
|
||||||
QString aBrepFilter;
|
QString aBrepFilter;
|
||||||
for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it ) {
|
for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it ) {
|
||||||
@ -120,6 +121,63 @@ static QString getFileName( QWidget* parent,
|
|||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
// function : getFileNames
|
||||||
|
// purpose : Select list of files for Import operation. Returns also
|
||||||
|
// the selected file type code through <format> argument.
|
||||||
|
//=======================================================================
|
||||||
|
static QStringList getFileNames( QWidget* parent,
|
||||||
|
const QString& initial,
|
||||||
|
const FilterMap& filterMap,
|
||||||
|
const QString& caption,
|
||||||
|
QString& format,
|
||||||
|
bool showCurrentDirInitially = false)
|
||||||
|
{
|
||||||
|
QString aBrepFilter;
|
||||||
|
QStringList allFilters;
|
||||||
|
QStringList filters;
|
||||||
|
QRegExp re( "\\((.*)\\)" );
|
||||||
|
re.setMinimal( true );
|
||||||
|
for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it ) {
|
||||||
|
if ( it.data().contains( "BREP", false ) && aBrepFilter.isEmpty() )
|
||||||
|
aBrepFilter = it.key();
|
||||||
|
filters.append( it.key() );
|
||||||
|
int pos = 0;
|
||||||
|
while ( re.search( it.key(), pos ) >= 0 ) {
|
||||||
|
QString f = re.cap(1);
|
||||||
|
pos = re.pos() + f.length() + 2;
|
||||||
|
allFilters.append( f.simplifyWhiteSpace() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filters.append( QObject::tr( "GEOM_ALL_IMPORT_FILES" ).arg( allFilters.join( " " ) ) );
|
||||||
|
|
||||||
|
SUIT_FileDlg fd( parent, true, true, true );
|
||||||
|
fd.setMode( SUIT_FileDlg::ExistingFiles );
|
||||||
|
if ( !caption.isEmpty() )
|
||||||
|
fd.setCaption( caption );
|
||||||
|
if ( !initial.isEmpty() )
|
||||||
|
fd.setSelection( initial );
|
||||||
|
|
||||||
|
if ( showCurrentDirInitially && SUIT_FileDlg::getLastVisitedPath().isEmpty() )
|
||||||
|
fd.setDir( QDir::currentDirPath() );
|
||||||
|
|
||||||
|
fd.setFilters( filters );
|
||||||
|
|
||||||
|
if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) )
|
||||||
|
fd.setSelectedFilter( lastUsedFilter );
|
||||||
|
else if ( !aBrepFilter.isEmpty() )
|
||||||
|
fd.setSelectedFilter( aBrepFilter );
|
||||||
|
|
||||||
|
QStringList filenames;
|
||||||
|
if ( fd.exec() ) {
|
||||||
|
filenames = fd.selectedFiles();
|
||||||
|
format = filterMap.contains( fd.selectedFilter() ) ? filterMap[ fd.selectedFilter() ] : QString();
|
||||||
|
lastUsedFilter = fd.selectedFilter();
|
||||||
|
}
|
||||||
|
qApp->processEvents();
|
||||||
|
return filenames;
|
||||||
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
// function : getParentComponent
|
// function : getParentComponent
|
||||||
// purpose : Get object's parent component entry
|
// purpose : Get object's parent component entry
|
||||||
@ -543,7 +601,6 @@ void GEOMToolsGUI::OnEditCopy()
|
|||||||
bool GEOMToolsGUI::Import()
|
bool GEOMToolsGUI::Import()
|
||||||
{
|
{
|
||||||
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( getGeometryGUI()->getApp() );
|
SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( getGeometryGUI()->getApp() );
|
||||||
//SUIT_Application* app = getGeometryGUI()->getApp();
|
|
||||||
if (! app) return false;
|
if (! app) return false;
|
||||||
|
|
||||||
SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
|
SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
|
||||||
@ -553,6 +610,7 @@ bool GEOMToolsGUI::Import()
|
|||||||
}
|
}
|
||||||
_PTR(Study) aStudy = stud->studyDS();
|
_PTR(Study) aStudy = stud->studyDS();
|
||||||
|
|
||||||
|
// check if study is locked
|
||||||
bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
|
bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
|
||||||
if ( aLocked ) {
|
if ( aLocked ) {
|
||||||
SUIT_MessageBox::warn1 ( app->desktop(),
|
SUIT_MessageBox::warn1 ( app->desktop(),
|
||||||
@ -562,6 +620,7 @@ bool GEOMToolsGUI::Import()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if GEOM engine is available
|
||||||
GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
|
GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
|
||||||
if ( CORBA::is_nil( eng ) ) {
|
if ( CORBA::is_nil( eng ) ) {
|
||||||
SUIT_MessageBox::error1( app->desktop(),
|
SUIT_MessageBox::error1( app->desktop(),
|
||||||
@ -575,48 +634,68 @@ bool GEOMToolsGUI::Import()
|
|||||||
if ( aInsOp->_is_nil() )
|
if ( aInsOp->_is_nil() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
GEOM::GEOM_Object_var anObj;
|
// obtain a list of available import formats
|
||||||
|
|
||||||
// Obtain a list of available import formats
|
|
||||||
FilterMap aMap;
|
FilterMap aMap;
|
||||||
QStringList filters;
|
|
||||||
GEOM::string_array_var aFormats, aPatterns;
|
GEOM::string_array_var aFormats, aPatterns;
|
||||||
aInsOp->ImportTranslators( aFormats, aPatterns );
|
aInsOp->ImportTranslators( aFormats, aPatterns );
|
||||||
|
|
||||||
for ( int i = 0, n = aFormats->length(); i < n; i++ ) {
|
for ( int i = 0, n = aFormats->length(); i < n; i++ )
|
||||||
aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
|
aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
|
||||||
filters.push_back( (char*)aPatterns[i] );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// select files to be imported
|
||||||
QString fileType;
|
QString fileType;
|
||||||
|
QStringList fileNames = getFileNames( app->desktop(), "", aMap,
|
||||||
|
tr( "GEOM_MEN_IMPORT" ), fileType, true );
|
||||||
|
|
||||||
QString fileName = getFileName(app->desktop(), "", aMap, filters,
|
// set Wait cursor
|
||||||
tr("GEOM_MEN_IMPORT"), true, fileType, true);
|
SUIT_OverrideCursor wc;
|
||||||
|
|
||||||
if (fileType.isEmpty() )
|
if ( fileNames.count() == 0 )
|
||||||
{
|
return false; // nothing selected, return
|
||||||
// Trying to detect file type
|
|
||||||
QFileInfo aFileInfo( fileName );
|
|
||||||
QString aPossibleType = (aFileInfo.extension(false)).upper() ;
|
|
||||||
|
|
||||||
if ( (aMap.values()).contains(aPossibleType) )
|
QStringList errors;
|
||||||
fileType = aPossibleType;
|
|
||||||
|
QValueList< GEOM::GEOM_Object_var > objsForDisplay;
|
||||||
|
|
||||||
|
// iterate through all selected files
|
||||||
|
for ( QStringList::ConstIterator it = fileNames.begin(); it != fileNames.end(); ++it ) {
|
||||||
|
QString fileName = *it;
|
||||||
|
|
||||||
|
if ( fileName.isEmpty() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QString aCurrentType;
|
||||||
|
if ( fileType.isEmpty() ) {
|
||||||
|
// file type is not defined, try to detect
|
||||||
|
QString ext = QFileInfo( fileName ).extension( false ).upper();
|
||||||
|
QRegExp re( "\\*\\.(\\w+)" );
|
||||||
|
for ( FilterMap::const_iterator it = aMap.begin();
|
||||||
|
it != aMap.end() && aCurrentType.isEmpty(); ++it ) {
|
||||||
|
int pos = 0;
|
||||||
|
while ( re.search( it.key(), pos ) >= 0 ) {
|
||||||
|
QString f = re.cap(1).stripWhiteSpace().upper();
|
||||||
|
if ( ext == f ) { aCurrentType = it.data(); break; }
|
||||||
|
pos = re.pos() + re.cap(1).length() + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
aCurrentType = fileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileName.isEmpty() || fileType.isEmpty())
|
if ( aCurrentType.isEmpty() ) {
|
||||||
return false;
|
errors.append( QString( "%1 : %2" ).arg( fileName ).arg( tr( "GEOM_UNSUPPORTED_TYPE" ) ) );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
|
GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
|
||||||
try {
|
try {
|
||||||
SUIT_OverrideCursor wc;
|
|
||||||
|
|
||||||
app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( fileName, /*withExten=*/true ) ) );
|
app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( fileName, /*withExten=*/true ) ) );
|
||||||
|
|
||||||
anOp->start();
|
anOp->start();
|
||||||
|
|
||||||
CORBA::String_var fileN = fileName.latin1();
|
CORBA::String_var fileN = fileName.latin1();
|
||||||
CORBA::String_var fileT = fileType.latin1();
|
CORBA::String_var fileT = aCurrentType.latin1();
|
||||||
anObj = aInsOp->Import(fileN, fileT);
|
GEOM::GEOM_Object_var anObj = aInsOp->Import( fileN, fileT );
|
||||||
|
|
||||||
if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
|
if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
|
||||||
QString aPublishObjName =
|
QString aPublishObjName =
|
||||||
@ -628,31 +707,38 @@ bool GEOMToolsGUI::Import()
|
|||||||
anObj,
|
anObj,
|
||||||
aPublishObjName );
|
aPublishObjName );
|
||||||
|
|
||||||
GEOM_Displayer( stud ).Display( anObj.in() );
|
objsForDisplay.append( anObj );
|
||||||
|
|
||||||
// update data model and object browser
|
|
||||||
getGeometryGUI()->updateObjBrowser( true );
|
|
||||||
|
|
||||||
anOp->commit();
|
anOp->commit();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
anOp->abort();
|
anOp->abort();
|
||||||
wc.suspend();
|
errors.append( QString( "%1 : %2" ).arg( fileName ).arg( aInsOp->GetErrorCode() ) );
|
||||||
SUIT_MessageBox::error1( app->desktop(),
|
|
||||||
QObject::tr( "GEOM_ERROR" ),
|
|
||||||
QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ),
|
|
||||||
QObject::tr("BUT_OK") );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( const SALOME::SALOME_Exception& S_ex ) {
|
catch( const SALOME::SALOME_Exception& S_ex ) {
|
||||||
//QtCatchCorbaException(S_ex);
|
|
||||||
anOp->abort();
|
anOp->abort();
|
||||||
return false;
|
errors.append( QString( "%1 : %2" ).arg( fileName ).arg( tr( "GEOM_UNKNOWN_IMPORT_ERROR" ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update object browser
|
||||||
|
getGeometryGUI()->updateObjBrowser( true );
|
||||||
|
|
||||||
|
// display imported model (if only one file is selected)
|
||||||
|
if ( objsForDisplay.count() == 1 )
|
||||||
|
GEOM_Displayer( stud ).Display( objsForDisplay[0].in() );
|
||||||
|
|
||||||
|
if ( errors.count() > 0 ) {
|
||||||
|
SUIT_MessageBox::error1( app->desktop(),
|
||||||
|
QObject::tr( "GEOM_ERROR" ),
|
||||||
|
QObject::tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ),
|
||||||
|
QObject::tr( "BUT_OK" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
app->updateActions(); //SRN: To update a Save button in the toolbar
|
app->updateActions(); //SRN: To update a Save button in the toolbar
|
||||||
|
|
||||||
return true;
|
return objsForDisplay.count() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user