#include <cpBaseQtApplication/MainWindow.h>
+#include <cpBaseQtApplication/Plugins/Navigator.h>
+#include <cpBaseQtApplication/Pipeline/Canvas.h>
+#include <cpExtensions/QT/ConfigurationChooser.h>
+#include <cpExtensions/QT/ActorsWidgetInterface.h>
-#include <cpExtensions/QT/SimpleMPRWidget.h>
-#include <cpBaseQtApplication/ActorPropertiesQDialog.h>
-#include <cpBaseQtApplication/Editor.h>
-#include <cpBaseQtApplication/PathsDialog.h>
-#include <vtkRenderer.h>
-#include <QApplication>
-#include <QColorDialog>
#include <QDir>
#include <QFileDialog>
-#include <QFileInfo>
-#include <QMessageBox>
-#include <QTreeWidget>
-
-// -------------------------------------------------------------------------
-bool cpBaseQtApplication::MainWindow::_TBlocker::
-eventFilter( QObject* obj, QEvent* event )
-{
- return( true ); // -> Block all events
- /* NOTE: this should be the correct implementation:
- switch( event->type( ) )
- {
- //list event you want to prevent here ...
- case QEvent::KeyPress:
- case QEvent::KeyRelease:
- case QEvent::MouseButtonRelease:
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonDblClick:
- //...
- return( true );
- } // hctiws
- return( this->QObject::eventFilter( obj, event ) );
- */
-}
+#include <QInputDialog>
// -------------------------------------------------------------------------
cpBaseQtApplication::MainWindow::
-MainWindow(
- int argc, char* argv[],
- QApplication* app,
- QWidget* parent
- )
+MainWindow( int argc, char* argv[], QWidget* parent )
: Superclass( parent ),
- m_Application( app ),
- m_PluginsPath( "." ),
- m_TreeWidget( NULL ),
- m_Editor( NULL ),
- m_MPR( NULL )
+ m_LastSaveFileName( "" ),
+ m_BaseWindowTitle( "cpBaseQtApplication" ),
+ m_Canvas( NULL ),
+ m_Navigator( NULL ),
+ m_Viewer( NULL )
{
- QFileInfo e_path( argv[ 0 ] );
- QDir r_path( "." );
- this->m_RunPath = r_path.canonicalPath( ).toStdString( );
- std::stringstream paths;
- paths
- << e_path.canonicalPath( ).toStdString( )
- << cpPlugins_SEPARATOR
- << this->m_RunPath;
-
- try { this->m_Interface.AddEnvironments( this->m_RunPath ); }
- catch( ... ) { }
- try { this->m_Interface.OpenEnvironments( this->m_RunPath ); }
- catch( ... ) { }
- try { this->m_Interface.SaveEnvironments( this->m_RunPath ); }
- catch( ... ) { }
- this->UpdateEnvironment( );
- this->m_Workspace.SetInterface( &( this->m_Interface ) );
+ this->m_RunPath = QDir( "." ).canonicalPath( ).toStdString( );
+ this->m_Loader.GuessEnvironment( this->m_RunPath );
+ this->m_Loader.SaveEnvironment( this->m_RunPath );
+ this->_clearWorkspace( );
}
// -------------------------------------------------------------------------
}
// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-UpdateEnvironment( )
+cpBaseQtApplication::MainWindow::
+TWorkspace* cpBaseQtApplication::MainWindow::
+workspace( )
{
- try
- {
- this->m_Interface.LoadEnvironments( );
- this->m_Interface.GuessPlugins( );
- }
- catch( std::exception& err )
- {
- QMessageBox::critical(
- this, "Error loading required libraries", err.what( )
- );
- return;
-
- } // yrt
+ return( this->m_Workspace );
}
// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_Configure(
- QTreeWidget* tree,
- cpExtensions::QT::SimpleMPRWidget* mpr,
- cpBaseQtApplication::Editor* editor
- )
+const cpBaseQtApplication::MainWindow::
+TWorkspace* cpBaseQtApplication::MainWindow::
+workspace( ) const
{
- this->m_TreeWidget = tree;
- this->_UpdateLoadedPlugins( );
- this->m_Editor = editor;
- this->m_MPR = mpr;
- if( this->m_Editor != NULL )
- {
- this->m_Editor->setWorkspace( &( this->m_Workspace ) );
-
- // Slots <-> signals
- this->connect(
- this->m_Editor,
- SIGNAL( execFilter( const std::string& ) ),
- this,
- SLOT( _ExecFilter( const std::string& ) )
- );
- this->connect(
- this->m_Editor,
- SIGNAL( showFilterOutput( const std::string&, const std::string& ) ),
- this,
- SLOT( _ShowData( const std::string&, const std::string& ) )
- );
- this->connect(
- this->m_Editor,
- SIGNAL( hideFilterOutput( const std::string&, const std::string& ) ),
- this,
- SLOT( _HideData( const std::string&, const std::string& ) )
- );
- this->connect(
- this->m_Editor,
- SIGNAL( visualPropertiesFilterOutput( const std::string&, const std::string& ) ),
- this,
- SLOT( _DataProperties( const std::string&, const std::string& ) )
- );
-
- } // fi
- if( this->m_MPR != NULL )
- this->m_Workspace.SetMPRViewer( this->m_MPR );
- this->_ClearWorkspace( );
+ return( this->m_Workspace );
}
// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_ClearWorkspace( )
+cpBaseQtApplication::Pipeline::Canvas*
+cpBaseQtApplication::MainWindow::
+canvas( )
{
- if( this->m_Editor != NULL )
- this->m_Editor->clear( );
- if( this->m_MPR != NULL )
- this->m_MPR->Clear( );
- this->m_Workspace.Clear( );
+ return( this->m_Canvas );
}
// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_AddEnvironments( const std::string& environments )
+const cpBaseQtApplication::Pipeline::Canvas*
+cpBaseQtApplication::MainWindow::
+canvas( ) const
{
- try { this->m_Interface.AddEnvironments( environments ); }
- catch( ... ) { }
- try { this->m_Interface.SaveEnvironments( this->m_RunPath ); }
- catch( ... ) { }
- this->UpdateEnvironment( );
+ return( this->m_Canvas );
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_LoadPlugins( const std::string& filename )
+setCanvas( cpBaseQtApplication::Pipeline::Canvas* c )
{
- try
- {
- this->m_Interface.LoadFile( filename );
- this->_UpdateLoadedPlugins( );
- }
- catch( std::exception& err )
- {
- QMessageBox::critical(
- this,
- "Error loading plugins path",
- err.what( )
- );
+ this->m_Canvas = c;
+ if( this->m_Canvas != NULL )
+ this->m_Canvas->setWorkspace( this->m_Workspace );
- } // yrt
}
// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_LoadPluginsFromPath( const std::string& path )
+cpBaseQtApplication::Plugins::Navigator*
+cpBaseQtApplication::MainWindow::
+navigator( )
{
- try
- {
- this->m_Interface.LoadDirectory( path );
- this->_UpdateLoadedPlugins( );
- }
- catch( std::exception& err )
- {
- QMessageBox::critical(
- this,
- "Error loading plugins path",
- err.what( )
- );
+ return( this->m_Navigator );
+}
- } // yrt
+// -------------------------------------------------------------------------
+const cpBaseQtApplication::Plugins::Navigator*
+cpBaseQtApplication::MainWindow::
+navigator( ) const
+{
+ return( this->m_Navigator );
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_UpdateLoadedPlugins( )
+setNavigator( cpBaseQtApplication::Plugins::Navigator* n )
{
- if( this->m_TreeWidget == NULL )
- return;
- this->_Block( );
- auto categories = this->m_Interface.GetCategories( );
- unsigned int filter_count = 0;
- for( auto cIt = categories.begin( ); cIt != categories.end( ); ++cIt )
- {
- // Create or get category
- QList< QTreeWidgetItem* > cat_items =
- this->m_TreeWidget->findItems(
- cIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
- );
- QTreeWidgetItem* cat = NULL;
- if( cat_items.size( ) == 0 )
- {
- cat = new QTreeWidgetItem(
- ( QTreeWidgetItem* )( NULL ), QStringList( cIt->c_str( ) )
- );
- this->m_TreeWidget->addTopLevelItem( cat );
- }
- else
- cat = cat_items[ 0 ];
-
- // Create filters
- auto filters = this->m_Interface.GetFilters( *cIt );
- filter_count += filters.size( );
- for( auto fIt = filters.begin( ); fIt != filters.end( ); ++fIt )
- {
- QList< QTreeWidgetItem* > filter_items =
- this->m_TreeWidget->findItems(
- fIt->c_str( ), Qt::MatchExactly | Qt::MatchRecursive
- );
- auto fiIt = filter_items.begin( );
- auto found_fiIt = filter_items.end( );
- for( ; fiIt != filter_items.end( ); ++fiIt )
- if( ( *fiIt )->parent( ) == cat )
- found_fiIt = fiIt;
-
- // Add filter
- if( found_fiIt == filter_items.end( ) )
- QTreeWidgetItem* filter = new QTreeWidgetItem(
- cat, QStringList( fIt->c_str( ) )
- );
-
- } // rof
-
- } // rof
- this->m_TreeWidget->expandAll( );
- this->_UnBlock( );
-
- if( filter_count == 0 )
- QMessageBox::critical(
- this,
- "Error loading default plugins",
- "No plugins loaded: remember to load some!!!"
- );
+ this->m_Navigator = n;
}
// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_Block( )
+cpExtensions::QT::ActorsWidgetInterface*
+cpBaseQtApplication::MainWindow::
+viewer( )
{
- this->m_Application->setOverrideCursor( Qt::WaitCursor );
- this->m_Application->installEventFilter( &( this->m_Blocker ) );
+ return( this->m_Viewer );
}
// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_UnBlock( )
+const cpExtensions::QT::ActorsWidgetInterface*
+cpBaseQtApplication::MainWindow::
+viewer( ) const
{
- while( this->m_Application->overrideCursor( ) )
- this->m_Application->restoreOverrideCursor( );
- this->m_Application->removeEventFilter( &( this->m_Blocker ) );
+ return( this->m_Viewer );
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_LoadWorkspace( const std::string& filename )
+setViewer( cpExtensions::QT::ActorsWidgetInterface* v )
{
- this->_ClearWorkspace( );
- std::string err = this->m_Workspace.LoadWorkspace( filename );
- if( err != "" )
+ this->m_Viewer = v;
+ if( this->m_Viewer != NULL )
{
- QMessageBox::critical(
- this,
- QMessageBox::tr( "Error loading workspace" ),
- QMessageBox::tr( err.c_str( ) )
- );
- }
- else
- {
- if( this->m_Editor != NULL )
- this->m_Editor->redrawWorkspace( );
+ auto interactors = this->m_Viewer->GetInteractors( );
+ for( auto i : interactors )
+ this->m_Workspace->AddInteractor( i );
} // fi
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_SaveWorkspace( const std::string& filename )
+_loadPlugins( const std::string& filename )
{
- std::string err = this->m_Workspace.SaveWorkspace( filename );
- if( err != "" )
+ try
+ {
+ this->m_Loader.Register( filename );
+ if( this->m_Navigator != NULL )
+ this->m_Navigator->Update( );
+ }
+ catch( std::exception& err )
+ {
QMessageBox::critical(
this,
- QMessageBox::tr( "Error saving workspace" ),
- QMessageBox::tr( err.c_str( ) )
+ "Error loading plugins path",
+ err.what( )
);
+
+ } // yrt
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_BackgroundProperties( unsigned int i )
+_loadPlugins( )
{
- if( this->m_MPR == NULL )
- return;
-
- QColor color =
- QColorDialog::getColor(
- QColor( 0, 0, 0 ),
- this,
- "Select Color",
- QColorDialog::DontUseNativeDialog
- );
- if( color.isValid( ) )
- {
- double r = double( color.red( ) ) / double( 255 );
- double g = double( color.green( ) ) / double( 255 );
- double b = double( color.blue( ) ) / double( 255 );
- if( i >= 4 )
- {
- unsigned int maxId = ( i == 4 )? 3: 4;
- for( unsigned int j = 0; j < maxId; ++j )
- {
- auto ren = this->m_MPR->GetRenderer( j );
- if( ren != NULL )
- {
- ren->SetBackground( r, g, b );
- ren->Render( );
-
- } // fi
-
- } // rof
- }
- else
- {
- auto ren = this->m_MPR->GetRenderer( i );
- if( ren != NULL )
- {
- ren->SetBackground( r, g, b );
- ren->Render( );
-
- } // fi
-
- } // fi
+ QFileDialog dlg( this );
+ dlg.setFileMode( QFileDialog::ExistingFiles );
- } // fi
+ std::stringstream filter;
+ std::string suffix = std::string( cpPlugins_LIB_EXT );
+ filter << "Plugins file (*" << cpPlugins_LIB_EXT << ");;All files (*)";
+ dlg.setNameFilter( filter.str( ).c_str( ) );
+ dlg.setDefaultSuffix( suffix.c_str( ) );
+ if( !( dlg.exec( ) ) )
+ return;
+ QStringList names = dlg.selectedFiles( );
+ for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt )
+ this->_loadPlugins( qIt->toStdString( ) );
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_ShowData( const std::string& filter_name, const std::string& output_name )
+_loadPluginsFromPath( const std::string& path )
{
- if( this->m_MPR == NULL )
- return;
-
- auto output = this->m_Workspace.GetOutput( filter_name, output_name );
- if( output != NULL )
+ try
{
- this->_Block( );
- auto actor = output->GetVTKActor( );
- if( actor != NULL )
- {
- this->m_MPR->AddActor(
- actor, output_name + std::string( "@" ) + filter_name
- );
- this->_UnBlock( );
- }
- else
- {
- this->_UnBlock( );
- QMessageBox::critical(
- this,
- QMessageBox::tr( "Error showing data" ),
- QMessageBox::tr( "Unknown VTK conversion." )
- );
-
- } // fi
+ this->m_Loader.RegisterFromDirectory( path );
+ this->m_Loader.SaveEnvironment( this->m_RunPath );
+ if( this->m_Navigator != NULL )
+ this->m_Navigator->Update( );
}
- else
+ catch( std::exception& err )
+ {
QMessageBox::critical(
this,
- QMessageBox::tr( "Error showing data" ),
- QMessageBox::tr( "Unknown port name." )
+ "Error loading plugins path",
+ err.what( )
);
-}
-// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_HideData( const std::string& filter, const std::string& output )
-{
- std::cout << "MainWindow::HideData" << std::endl;
- /* TODO
- */
+ } // yrt
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_DataProperties(
- const std::string& filter_name, const std::string& output_name
- )
+_loadPluginsFromPath( )
{
- if( this->m_MPR == NULL )
+ QFileDialog d( this );
+ d.setFileMode( QFileDialog::DirectoryOnly );
+ if( !( d.exec( ) ) )
return;
-
- auto output = this->m_Workspace.GetOutput( filter_name, output_name );
- if( output != NULL )
- {
- this->_Block( );
- auto actors = this->m_MPR->GetActors(
- output_name + std::string( "@" ) + filter_name
- );
- auto dlg = new ActorPropertiesQDialog( NULL );
- for( auto i = actors.begin( ); i != actors.end( ); ++i )
- dlg->addActor( *i );
- dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 0 ) );
- dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 1 ) );
- dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 2 ) );
- dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 3 ) );
- this->_UnBlock( );
- dlg->exec( );
- }
- else
- QMessageBox::critical(
- this,
- QMessageBox::tr( "Error showing data" ),
- QMessageBox::tr( "Unknown port name." )
- );
+ this->_loadPluginsFromPath( d.selectedFiles( ).begin( )->toStdString( ) );
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_InteractiveLoadPlugins( )
+_clearWorkspace( )
{
- QFileDialog dlg( this );
- dlg.setFileMode( QFileDialog::ExistingFiles );
- dlg.setDirectory( this->m_PluginsPath.c_str( ) );
+ this->setWindowTitle( this->m_BaseWindowTitle.c_str( ) );
+ this->m_Workspace = TWorkspace::New( );
+ if( this->m_Canvas != NULL )
+ {
+ this->m_Canvas->clear( );
+ this->m_Canvas->setWorkspace( this->m_Workspace );
- std::stringstream filter;
- std::string suffix = std::string( cpPlugins_LIB_EXT );
- filter << "Plugins file (*." << cpPlugins_LIB_EXT << ");;All files (*)";
- dlg.setNameFilter( filter.str( ).c_str( ) );
- dlg.setDefaultSuffix( suffix.c_str( ) );
- if( !( dlg.exec( ) ) )
- return;
- QStringList names = dlg.selectedFiles( );
- for( auto qIt = names.begin( ); qIt != names.end( ); ++qIt )
- this->_LoadPlugins( qIt->toStdString( ) );
+ } // fi
+ if( this->m_Viewer != NULL )
+ {
+ // TODO: this->m_Viewer->clear( );
+ auto interactors = this->m_Viewer->GetInteractors( );
+ for( auto i : interactors )
+ this->m_Workspace->AddInteractor( i );
+
+ } // fi
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_InteractiveLoadPluginsFromPath( )
+_saveWorkspace( const std::string& fname )
{
- QFileDialog d( this );
- d.setFileMode( QFileDialog::DirectoryOnly );
- d.setDirectory( this->m_PluginsPath.c_str( ) );
- if( !( d.exec( ) ) )
- return;
- this->_LoadPluginsFromPath( d.selectedFiles( ).begin( )->toStdString( ) );
+ this->m_LastSaveFileName = fname;
+ this->m_Workspace->Save( this->m_LastSaveFileName );
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_ShowPlugins( )
+_saveWorkspace( )
{
- auto paths = this->m_Interface.GetPaths( );
- auto plugins = this->m_Interface.GetPlugins( );
- std::stringstream info;
- info << "----- PATHS -----" << std::endl;
- for( auto i = paths.begin( ); i != paths.end( ); ++i )
- info << " " << *i << std::endl;
- info << std::endl << "----- PLUGINS -----" << std::endl;
- for( auto i = plugins.begin( ); i != plugins.end( ); ++i )
- info << " " << *i << std::endl;
- QMessageBox::information(
- this,
- "Loaded libraries and plugins information",
- info.str( ).c_str( )
- );
+ if( this->m_LastSaveFileName == "" )
+ {
+ QFileDialog dlg( this );
+ dlg.setFileMode( QFileDialog::AnyFile );
+ dlg.setDirectory( "." );
+ dlg.setAcceptMode( QFileDialog::AcceptSave );
+ dlg.setNameFilter(
+ QFileDialog::tr( "Workspace file (*.wxml);;All files (*)" )
+ );
+ dlg.setDefaultSuffix( QFileDialog::tr( "wxml" ) );
+ dlg.setWindowTitle( "Saving workspace" );
+ if( dlg.exec( ) )
+ this->_saveWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) );
+ }
+ else
+ this->_saveWorkspace( this->m_LastSaveFileName );
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_InteractiveLoadWorkspace( )
+_loadWorkspace( const std::string& fname )
{
- QFileDialog dlg( this );
- dlg.setFileMode( QFileDialog::ExistingFile );
- dlg.setDirectory( "." );
- dlg.setNameFilter(
- QFileDialog::tr( "Workspace file (*.wxml);;All files (*)" )
- );
- dlg.setDefaultSuffix( QFileDialog::tr( "wxml" ) );
- if( !( dlg.exec( ) ) )
- return;
- this->_LoadWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) );
+ try
+ {
+ this->_clearWorkspace( );
+ this->m_Workspace->Load( fname );
+ this->m_LastSaveFileName = "";
+ if( this->m_Canvas != NULL )
+ this->m_Canvas->setWorkspace( this->m_Workspace );
+ }
+ catch( std::exception& err )
+ {
+ QMessageBox::critical(
+ this,
+ QMessageBox::tr( "Error loading workspace" ),
+ QMessageBox::tr( err.what( ) )
+ );
+
+ } // yrt
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_InteractiveSaveWorkspace( )
+_loadWorkspace( )
{
QFileDialog dlg( this );
- dlg.setFileMode( QFileDialog::AnyFile );
+ dlg.setFileMode( QFileDialog::ExistingFile );
dlg.setDirectory( "." );
- dlg.setAcceptMode( QFileDialog::AcceptSave );
dlg.setNameFilter(
QFileDialog::tr( "Workspace file (*.wxml);;All files (*)" )
);
dlg.setDefaultSuffix( QFileDialog::tr( "wxml" ) );
if( !( dlg.exec( ) ) )
return;
- this->_SaveWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) );
+ this->_loadWorkspace( dlg.selectedFiles( ).begin( )->toStdString( ) );
}
// -------------------------------------------------------------------------
void cpBaseQtApplication::MainWindow::
-_InteractiveAddEnviromentPaths( )
+_actorsProperties( )
{
- PathsDialog dlg( this );
- dlg.addPaths( this->m_Interface.GetPaths( ) );
- if( dlg.exec( ) )
- {
- auto paths = dlg.getPaths( );
- std::stringstream envs;
- for( auto p = paths.begin( ); p != paths.end( ); ++p )
- envs << *p << cpPlugins_SEPARATOR;
- this->_AddEnvironments( envs.str( ) );
- this->UpdateEnvironment( );
-
- } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpBaseQtApplication::MainWindow::
-_ExecFilter( const std::string& filter_name )
-{
- this->_Block( );
- try
- {
- this->m_Workspace.Execute( filter_name );
- this->_UnBlock( );
- }
- catch( itk::ExceptionObject& err1 )
- {
- this->_UnBlock( );
- QMessageBox::critical(
- this,
- QMessageBox::tr( "Error executing filter" ),
- QMessageBox::tr( err1.GetDescription( ) )
+ auto data =
+ dynamic_cast< cpExtensions::QT::ActorsWidgetInterface* >(
+ this->m_Viewer
);
- }
- catch( std::exception& err2 )
- {
- this->_UnBlock( );
- QMessageBox::critical(
- this,
- QMessageBox::tr( "Error executing filter" ),
- QMessageBox::tr( err2.what( ) )
- );
- }
- catch( ... )
+ if( data != NULL )
{
- this->_UnBlock( );
- QMessageBox::critical(
- this,
- QMessageBox::tr( "Error executing filter" ),
- QMessageBox::tr( "Unknown error" )
- );
+ auto dlg = new cpExtensions::QT::ConfigurationChooser( this );
+ dlg->setData( data );
+ dlg->exec( );
- } // yrt
+ } // fi
}
// eof - $RCSfile$