-// LIGHT : sample (no-corba-engine) SALOME module
+// PARAVIS : ParaView wrapper SALOME module
//
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
#include "PVGUI_Module.h"
+#include "PVGUI_Module_impl.h"
#include "PVGUI_ProcessModuleHelper.h"
#include "PVGUI_ViewModel.h"
#include "PVGUI_ViewManager.h"
+#include "PVGUI_ViewWindow.h"
-#include <SUIT_MessageBox.h>
#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ResourceMgr.h>
#include <SUIT_Session.h>
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
+#include <QtxActionToolMgr.h>
+#include <QAction>
#include <QApplication>
-#include <QInputDialog>
-#include <QStringList>
-#include <QMenu>
+#include <QCursor>
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
#include <QIcon>
+#include <QInputDialog>
+#include <QStatusBar>
#include <QString>
-
+#include <QStringList>
+#include <QTimer>
+#include <QToolBar>
+
+#include <pqApplicationCore.h>
+#include <pqActiveServer.h>
+#include <pqActiveView.h>
+#include <pqClientAboutDialog.h>
+#include <pqObjectBuilder.h>
#include <pqOptions.h>
+#include <pqRenderView.h>
+#include <pqRubberBandHelper.h>
+#include <pqServer.h>
+#include <pqServerManagerModel.h>
+#include <pqServerResource.h>
+#include <pqUndoStack.h>
+#include <pqVCRController.h>
+#include <pqViewManager.h>
#include <vtkPVMain.h>
#include <vtkProcessModule.h>
vtkXdmfCS_Initialize(pm->GetInterpreter());
}
-vtkPVMain* PVGUI_Module::myPVMain = 0;
-pqOptions* PVGUI_Module::myPVOptions = 0;
-PVGUI_ProcessModuleHelper* PVGUI_Module::myPVHelper = 0;
+vtkPVMain* PVGUI_Module::pqImplementation::myPVMain = 0;
+pqOptions* PVGUI_Module::pqImplementation::myPVOptions = 0;
+PVGUI_ProcessModuleHelper* PVGUI_Module::pqImplementation::myPVHelper = 0;
/*!
\class PVGUI_Module
\brief Constructor. Sets the default name for the module.
*/
PVGUI_Module::PVGUI_Module()
-: LightApp_Module( "PARAVIS" )
+ : LightApp_Module( "PARAVIS" ),
+ Implementation( 0 )
{
}
{
LightApp_Module::initialize( app );
- SUIT_Desktop* desk = application()->desktop();
-
/*
int i = 1;
while( i ){
}
*/
- if ( pvInit() ) {
- pvCreateActions();
- }
+ pvInit();
+
/*
createAction( lgLoadFile, tr( "TOP_LOAD_FILE" ), QIcon(), tr( "MEN_LOAD_FILE" ),
tr( "STB_LOAD_FILE" ), 0, desk, false, this, SLOT( onLoadFile() ) );
*/
bool PVGUI_Module::pvInit()
{
- if ( !myPVMain ){
+ if ( !pqImplementation::myPVMain ){
// Obtain command-line arguments
int argc = 0;
QStringList args = QApplication::arguments();
// TODO: Set plugin dir from preferences
//QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
- myPVMain = vtkPVMain::New();
- if ( !myPVOptions )
- myPVOptions = pqOptions::New();
- if ( !myPVHelper )
- myPVHelper = PVGUI_ProcessModuleHelper::New();
+ pqImplementation::myPVMain = vtkPVMain::New();
+ if ( !pqImplementation::myPVOptions )
+ pqImplementation::myPVOptions = pqOptions::New();
+ if ( !pqImplementation::myPVHelper )
+ pqImplementation::myPVHelper = PVGUI_ProcessModuleHelper::New();
- myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
+ pqImplementation::myPVOptions->SetProcessType(vtkPVOptions::PVCLIENT);
// This creates the Process Module and initializes it.
- int ret = myPVMain->Initialize(myPVOptions, myPVHelper, ParaViewInitializeInterpreter,
- argc, argv);
+ int ret = pqImplementation::myPVMain->Initialize(pqImplementation::myPVOptions,
+ pqImplementation::myPVHelper,
+ ParaViewInitializeInterpreter,
+ argc, argv);
if (!ret){
// Tell process module that we support Multiple connections.
// This must be set before starting the event loop.
vtkProcessModule::GetProcessModule()->SupportMultipleConnectionsOn();
- ret = myPVHelper->Run(myPVOptions);
+ ret = pqImplementation::myPVHelper->Run(pqImplementation::myPVOptions);
}
- //delete[] argv;
- cout << "*** ParaView client initalized!!!" << endl;
+ delete[] argv;
return !ret;
}
void PVGUI_Module::showView( bool toShow )
{
// TODO: check if ParaView view already exists
- LightApp_Application* anApp = getApp();
+ if ( !Implementation ){
+ LightApp_Application* anApp = getApp();
+ SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+ PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
+ anApp->addViewManager( viewMgr );
+ connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
+ anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
+ //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
+ //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) );
+ SUIT_ViewWindow* wnd = viewMgr->createViewWindow();
+
+ // Simulate ParaView client main window
+ Implementation = new pqImplementation( anApp->desktop() );
+ PVGUI_ViewWindow* pvWnd = dynamic_cast<PVGUI_ViewWindow*>( wnd );
+ pvWnd->setMultiViewManager( &Implementation->Core.multiViewManager() );
+
+ setupDockWidgets();
+
+ pvCreateActions();
+ pvCreateMenus();
+ pvCreateToolBars();
+
+ setupDockWidgetsContextMenu();
+
+ // Now that we're ready, initialize everything ...
+ Implementation->Core.initializeStates();
+ }
+}
+
+/*!
+ \brief Manage the label of Undo operation.
+*/
+void PVGUI_Module::onUndoLabel( const QString& label )
+{
+ action(UndoId)->setText(
+ label.isEmpty() ? tr("Can't Undo") : QString(tr("&Undo %1")).arg(label));
+ action(UndoId)->setStatusTip(
+ label.isEmpty() ? tr("Can't Undo") : QString(tr("Undo %1")).arg(label));
+}
+
+/*!
+ \brief Manage the label of Redo operation.
+*/
+void PVGUI_Module::onRedoLabel( const QString& label )
+{
+ action(RedoId)->setText(
+ label.isEmpty() ? tr("Can't Redo") : QString(tr("&Redo %1")).arg(label));
+ action(RedoId)->setStatusTip(
+ label.isEmpty() ? tr("Can't Redo") : QString(tr("Redo %1")).arg(label));
+}
+
+/*!
+ \brief Manage the label of Undo Camera operation.
+*/
+void PVGUI_Module::onCameraUndoLabel( const QString& label )
+{
+ action(CameraUndoId)->setText(
+ label.isEmpty() ? tr("Can't Undo Camera") : QString(tr("U&ndo %1")).arg(label));
+ action(CameraUndoId)->setStatusTip(
+ label.isEmpty() ? tr("Can't Undo Camera") : QString(tr("Undo %1")).arg(label));
+}
+
+/*!
+ \brief Manage the label of Redo Camera operation.
+*/
+void PVGUI_Module::onCameraRedoLabel( const QString& label )
+{
+ action(CameraRedoId)->setText(
+ label.isEmpty() ? tr("Can't Redo Camera") : QString(tr("R&edo %1")).arg(label));
+ action(CameraRedoId)->setStatusTip(
+ label.isEmpty() ? tr("Can't Redo Camera") : QString(tr("Redo %1")).arg(label));
+}
+
+/*!
+ \brief Slot to delete all objects.
+*/
+void PVGUI_Module::onDeleteAll()
+{
+ pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder();
+ Implementation->Core.getApplicationUndoStack()->beginUndoSet("Delete All");
+ builder->destroyPipelineProxies();
+ Implementation->Core.getApplicationUndoStack()->endUndoSet();
+}
+
+/*!
+ \brief Slot to check/uncheck the action for corresponding selection mode.
+*/
+void PVGUI_Module::onSelectionModeChanged( int mode )
+{
+ if( toolMgr()->toolBar( mySelectionControlsTb )->isEnabled() ) {
+ if(mode == pqRubberBandHelper::SELECT) //surface selection
+ action(SelectCellsOnId)->setChecked(true);
+ else if(mode == pqRubberBandHelper::SELECT_POINTS) //surface selection
+ action(SelectPointsOnId)->setChecked(true);
+ else if(mode == pqRubberBandHelper::FRUSTUM)
+ action(SelectCellsThroughId)->setChecked(true);
+ else if(mode == pqRubberBandHelper::FRUSTUM_POINTS)
+ action(SelectPointsThroughId)->setChecked(true);
+ else if (mode == pqRubberBandHelper::BLOCKS)
+ action(SelectBlockId)->setChecked(true);
+ else // INTERACT
+ action(InteractId)->setChecked(true);
+ }
+}
+
+/*!
+ \brief Slot to manage the change of axis center.
+*/
+void PVGUI_Module::onShowCenterAxisChanged( bool enabled )
+{
+ action(ShowCenterId)->setEnabled(enabled);
+ action(ShowCenterId)->blockSignals(true);
+ pqRenderView* renView = qobject_cast<pqRenderView*>(
+ pqActiveView::instance().current());
+ action(ShowCenterId)->setChecked( renView ? renView->getCenterAxesVisibility() : false);
+ action(ShowCenterId)->blockSignals(false);
+}
+
+/*!
+ \brief Slot to set tooltips for the first anf the last frames, i.e. a time range of animation.
+*/
+void PVGUI_Module::setTimeRanges( double start, double end )
+{
+ action(FirstFrameId)->setToolTip(QString("First Frame (%1)").arg(start, 0, 'g'));
+ action(LastFrameId)->setToolTip(QString("Last Frame (%1)").arg(end, 0, 'g'));
+}
+
+/*!
+ \brief Slot to manage the plaing process of animation.
+*/
+void PVGUI_Module::onPlaying( bool playing )
+{
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
- PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() );
- anApp->addViewManager( viewMgr );
- connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ),
- anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) );
- //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) );
- //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) );
- SUIT_ViewWindow* wnd = viewMgr->createViewWindow();
+ if(playing) {
+ disconnect( action(PlayId), SIGNAL( triggered() ),
+ &Implementation->Core.VCRController(), SLOT( onPlay() ) );
+ connect( action(PlayId), SIGNAL( triggered() ),
+ &Implementation->Core.VCRController(), SLOT( onPause() ) );
+ action(PlayId)->setIcon(QIcon(resMgr->loadPixmap("ParaView",tr("ICON_PAUSE"),false)));
+ action(PlayId)->setText("Pa&use");
+ }
+ else {
+ connect( action(PlayId), SIGNAL( triggered() ),
+ &Implementation->Core.VCRController(), SLOT( onPlay() ) );
+ disconnect( action(PlayId), SIGNAL( triggered() ),
+ &Implementation->Core.VCRController(), SLOT( onPause() ) );
+ action(PlayId)->setIcon(QIcon(resMgr->loadPixmap("ParaView",tr("ICON_PLAY"),false)));
+ action(PlayId)->setText("&Play");
+ }
+
+ Implementation->Core.setSelectiveEnabledState(!playing);
}
-
+
/*!
- \brief Create actions for ParaView GUI operations
- duplicating menus and toolbars in pqMainWindow ParaView class
+ \brief Slot to add camera link.
*/
-void PVGUI_Module::pvCreateActions()
+void PVGUI_Module::onAddCameraLink()
{
- // TODO...
+ pqView* vm = pqActiveView::instance().current();
+ pqRenderView* rm = qobject_cast<pqRenderView*>(vm);
+ if(rm) rm->linkToOtherView();
+ else SUIT_MessageBox::warning(getApp()->desktop(),
+ tr("WARNING"), tr("WRN_ADD_CAMERA_LINK"));
+}
+
+/*!
+ \brief Slot to show information about ParaView.
+*/
+void PVGUI_Module::onHelpAbout()
+{
+ pqClientAboutDialog* const dialog = new pqClientAboutDialog(getApp()->desktop());
+ dialog->setAttribute(Qt::WA_DeleteOnClose);
+ dialog->show();
+}
+
+/*!
+ \brief Slot to show help for proxy.
+*/
+void PVGUI_Module::showHelpForProxy( const QString& proxy )
+{
+ // make sure assistant is ready
+ this->makeAssistant();
+
+ if(this->Implementation->AssistantClient) {
+ this->Implementation->AssistantClient->openAssistant();
+ QString page("%1/Documentation/%2.html");
+ page = page.arg(this->Implementation->DocumentationDir);
+ page = page.arg(proxy);
+ this->Implementation->AssistantClient->showPage(page);
+ }
+}
+
+QString Locate( const QString& appName )
+{
+ QString app_dir = QCoreApplication::applicationDirPath();
+ const char* inst_dirs[] = {
+ "/./",
+ "/../bin/",
+ "/../../bin/",
+ 0
+ };
+ for (const char** dir = inst_dirs; *dir; ++dir) {
+ QString path = app_dir;
+ path += *dir;
+ path += appName;
+ //cout << "Checking : " << path.toAscii().data() << " ... ";
+ //cout.flush();
+ QFileInfo finfo (path);
+ if (finfo.exists()) {
+ //cout << " Success!" << endl;
+ return path;
+ }
+ //cout << " Failed" << endl;
+ }
+ return app_dir + QDir::separator() + appName;
+}
+
+/*!
+ \brief Initialized an assistant client.
+*/
+void PVGUI_Module::makeAssistant()
+{
+ if(this->Implementation->AssistantClient)
+ return;
+
+ QString assistantExe;
+ QString profileFile;
+
+ const char* assistantName = "assistant";
+#ifdef WNT
+ const char* extString = ".exe";
+ const char* binDir = "\\";
+ const char* binDir1 = "\\..\\";
+#else
+ const char* extString = "";
+ const char* binDir = "/";
+ const char* binDir1 = "/";
+#endif
+
+ QString assistantProgName;
+ assistantProgName = assistantProgName + assistantName + extString;
+
+ QString helper = QCoreApplication::applicationDirPath() + binDir + QString("pqClientDocFinder.txt");
+ if(!QFile::exists(helper))
+ helper = QCoreApplication::applicationDirPath() + binDir1 + QString("pqClientDocFinder.txt");
+ if(QFile::exists(helper)) {
+ QFile file(helper);
+ if(file.open(QIODevice::ReadOnly)) {
+ assistantExe = file.readLine().trimmed() + assistantProgName;
+ profileFile = file.readLine().trimmed();
+ }
+ }
+
+ if(assistantExe.isEmpty()) {
+ assistantExe = ::Locate(assistantProgName);
+ /*
+ QString assistant = QCoreApplication::applicationDirPath();
+ assistant += QDir::separator();
+ assistant += assistantName;
+ assistantExe = assistant;
+ */
+ }
+
+ this->Implementation->AssistantClient = new QAssistantClient(assistantExe, this);
+ QObject::connect(this->Implementation->AssistantClient, SIGNAL(error(const QString&)),
+ this, SLOT(assistantError(const QString&)));
+
+ QStringList args;
+ args.append(QString("-profile"));
+
+ if(profileFile.isEmpty()) {
+ // see if help is bundled up with the application
+ QString profile = ::Locate("pqClient.adp");
+ /*QCoreApplication::applicationDirPath() + QDir::separator()
+ + QString("pqClient.adp");*/
+
+ if(QFile::exists(profile))
+ profileFile = profile;
+ }
+
+ if(profileFile.isEmpty() && getenv("PARAVIEW_HELP")) {
+ // not bundled, ask for help
+ args.append(getenv("PARAVIEW_HELP"));
+ }
+ else if(profileFile.isEmpty()) {
+ // no help, error out
+ SUIT_MessageBox::critical(getApp()->desktop(),"Help error", "Couldn't find"
+ " pqClient.adp.\nTry setting the PARAVIEW_HELP environment variable which"
+ " points to that file");
+ delete this->Implementation->AssistantClient;
+ return;
+ }
+
+ QFileInfo fi(profileFile);
+ this->Implementation->DocumentationDir = fi.absolutePath();
+
+ args.append(profileFile);
+
+ this->Implementation->AssistantClient->setArguments(args);
+}
+
+/*!
+ \brief Slot to call the message handler with the critical message.
+*/
+void PVGUI_Module::assistantError( const QString& error )
+{
+ qCritical(error.toAscii().data());
+}
+
+/*!
+ \brief Slot to show the waiting state.
+*/
+void PVGUI_Module::onPreAccept()
+{
+ getApp()->desktop()->statusBar()->showMessage(tr("Updating..."));
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+}
+
+/*!
+ \brief Slot to show the ready state.
+*/
+void PVGUI_Module::onPostAccept()
+{
+ getApp()->desktop()->statusBar()->showMessage(tr("Ready"), 2000);
+ QTimer::singleShot(0, this, SLOT(endWaitCursor()));
+}
+
+/*!
+ \brief Slot to switch off wait cursor.
+*/
+void PVGUI_Module::endWaitCursor()
+{
+ QApplication::restoreOverrideCursor();
+}
+
+/*!
+ \brief Returns the ParaView multi-view manager.
+*/
+pqViewManager* PVGUI_Module::getMultiViewManager() const
+{
+ pqViewManager* aMVM = 0;
+ if ( Implementation )
+ aMVM = &Implementation->Core.multiViewManager();
+ return aMVM;
}
/*!
showView( true );
+ // Make default server connection
+ if ( Implementation )
+ Implementation->Core.makeDefaultConnectionIfNoneExists();
+
return isDone;
}
+
/*!
\brief Deactivate module.
\param study current study