Commit 9a090659 authored by whitlocb's avatar whitlocb

I added a new multiwindow viewer example program.



git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@13137 18c085ea-50e0-402c-830e-de6fd14e8384
parent 059b82a6
......@@ -35,28 +35,41 @@
# DAMAGE.
#
# Modifications:
# Brad Whitlock, Tue Nov 30 11:32:08 PST 2010
# I added multiwindow example.
#
#****************************************************************************/
SET(SOURCES
SET(SOURCES1
CommandParser.C
SimpleVisApp.C
Synchronizer.C
main.C
)
SET(SOURCES2
MultiWindowVisApp.C
main.C
)
# If the viewer is static then we need some static symbol lookup functions
IF(VISIT_STATIC)
SET(STATIC_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../../viewer/main/ViewerStaticSymbolLocator.C)
ENDIF(VISIT_STATIC)
# The subset of the sources that have Q_OBJECT in their header.
SET(MOC_SOURCES
SET(MOC_SOURCES1
CommandParser.h
SimpleVisApp.h
Synchronizer.h
)
QT_WRAP_CPP(embedded SOURCES ${MOC_SOURCES})
QT_WRAP_CPP(embedded SOURCES1 ${MOC_SOURCES1})
# The subset of the sources that have Q_OBJECT in their header.
SET(MOC_SOURCES2
MultiWindowVisApp.h
)
QT_WRAP_CPP(multiwindow SOURCES2 ${MOC_SOURCES2})
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
......@@ -82,14 +95,15 @@ ${VTK_INCLUDE_DIRS}
LINK_DIRECTORIES(${LIBRARY_OUTPUT_DIRECTORY} ${QT_LIBRARY_DIR} ${MESA_LIBRARY_DIR} ${GLEW_LIBRARY_DIR} ${VTK_LIBRARY_DIRS})
IF(NOT APPLE)
ADD_EXECUTABLE(embedded ${SOURCES} ${STATIC_SOURCES})
ADD_EXECUTABLE(embedded ${SOURCES1} ${STATIC_SOURCES1})
ADD_EXECUTABLE(multiwindow ${SOURCES2} ${STATIC_SOURCES2})
ELSE(NOT APPLE)
SET(GUI_ICON_FILE VisItIcon.icns)
SET_SOURCE_FILES_PROPERTIES(${VISIT_SOURCE_DIR}/common/icons/${GUI_ICON_FILE} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources
)
ADD_EXECUTABLE(embedded MACOSX_BUNDLE ${SOURCES} ${STATIC_SOURCES} ${VISIT_SOURCE_DIR}/common/icons/${GUI_ICON_FILE})
ADD_EXECUTABLE(embedded MACOSX_BUNDLE ${SOURCES1} ${STATIC_SOURCES1} ${VISIT_SOURCE_DIR}/common/icons/${GUI_ICON_FILE})
SET(MACOSX_BUNDLE_BUNDLE_NAME "Embedded viewer example ${VISIT_VERSION}")
SET(MACOSX_BUNDLE_INFO_STRING "Embedded viewer example")
SET(MACOSX_BUNDLE_ICON_FILE ${GUI_ICON_FILE})
......@@ -98,6 +112,16 @@ ELSE(NOT APPLE)
SET(MACOSX_BUNDLE_SHORT_VERSION_STRING "Embedded viewer example ${VISIT_VERSION}")
SET(MACOSX_BUNDLE_BUNDLE_VERSION ${VISIT_VERSION})
SET(MACOSX_BUNDLE_COPYRIGHT "Copyright (c) 2000 - 2010, Lawrence Livermore National Security, LLC")
ADD_EXECUTABLE(multiwindow MACOSX_BUNDLE ${SOURCES2} ${STATIC_SOURCES2} ${VISIT_SOURCE_DIR}/common/icons/${GUI_ICON_FILE})
# SET(MACOSX_BUNDLE_BUNDLE_NAME "Multiwindow embedded viewer example ${VISIT_VERSION}")
# SET(MACOSX_BUNDLE_INFO_STRING "Multiwindow embedded viewer example")
# SET(MACOSX_BUNDLE_ICON_FILE ${GUI_ICON_FILE})
# SET(MACOSX_BUNDLE_GUI_IDENTIFIER VISI)
# SET(MACOSX_BUNDLE_LONG_VERSION_STRING "Multiwindow embedded viewer example version ${VISIT_VERSION}")
# SET(MACOSX_BUNDLE_SHORT_VERSION_STRING "Multiwindow embedded viewer example ${VISIT_VERSION}")
# SET(MACOSX_BUNDLE_BUNDLE_VERSION ${VISIT_VERSION})
# SET(MACOSX_BUNDLE_COPYRIGHT "Copyright (c) 2000 - 2010, Lawrence Livermore National Security, LLC")
ENDIF(NOT APPLE)
SET(VIEWER_QT_LIBS
......@@ -116,7 +140,7 @@ IF(VISIT_STATIC)
)
ENDIF(VISIT_STATIC)
TARGET_LINK_LIBRARIES(embedded
SET(EMBEDDED_VIEWER_LIBS
${viewer_exe_IOperator}
${viewer_exe_VOperator}
${viewer_exe_IPlot}
......@@ -148,11 +172,19 @@ vtkqt
${VIEWER_QT_LIBS}
)
TARGET_LINK_LIBRARIES(embedded ${EMBEDDED_VIEWER_LIBS})
TARGET_LINK_LIBRARIES(multiwindow ${EMBEDDED_VIEWER_LIBS})
IF(APPLE)
# Hey, do we need this on 10.6?
SET_TARGET_PROPERTIES(embedded
PROPERTIES
LINK_FLAGS "-framework Carbon"
)
SET_TARGET_PROPERTIES(multiwindow
PROPERTIES
LINK_FLAGS "-framework Carbon"
)
ENDIF(APPLE)
# If we're building statically then the viewer can't be linked until the plugin
......@@ -164,4 +196,11 @@ IF(VISIT_STATIC)
${viewer_exe_IPlot}
${viewer_exe_VPlot}
)
ADD_DEPENDENCIES(multiwindow
${viewer_exe_IOperator}
${viewer_exe_VOperator}
${viewer_exe_IPlot}
${viewer_exe_VPlot}
)
ENDIF(VISIT_STATIC)
#include <MultiWindowVisApp.h>
#include <VisItViewer.h>
#include <ViewerMethods.h>
#include <QButtonGroup>
#include <QDir>
#include <QFileDialog>
#include <QLabel>
#include <QLayout>
#include <QListWidget>
#include <QMenuBar>
#include <QMenu>
#include <QRadioButton>
#include <QSpinBox>
#include <QWidget>
// State objects that we use.
#include <avtDatabaseMetaData.h>
#include <PlotList.h>
// Include this last since something about it on X11 systems seems to
// interfere with some of our other enums. X11 headers must have some
// naughty #define directives.
#include <vtkQtRenderWindow.h>
QWidget *
create_application_main_window(VisItViewer *v)
{
return new MultiWindowVisApp(v);
}
void
show_application_main_window(QWidget *w)
{
// Do it like this since virtual show isn't working...
MultiWindowVisApp *app = (MultiWindowVisApp *)w;
app->show();
app->raise();
}
// Window creation callback. Returns the vis window pointers to VisIt.
vtkQtRenderWindow *
MultiWindowVisApp::ReturnVisWin(void *data)
{
MultiWindowVisApp *This = (MultiWindowVisApp *)data;
// Return vis window 1, 2, ...
int idx = ++This->currentWindow;
qDebug("Return window %d", idx);
return (idx <= 2) ? This->viswindows[idx] : NULL;
}
MultiWindowVisApp::MultiWindowVisApp(VisItViewer *v) : QMainWindow()
{
viewer = v;
windowsAdded = false;
currentWindow = 0;
for(int i = 0; i < NWINDOWS + 1; ++i)
viswindows[i] = 0;
setWindowTitle(tr("Multiwindow visualization"));
// Create the window.
QWidget *central = new QWidget(this);
setCentralWidget(central);
QHBoxLayout *hLayout = new QHBoxLayout(central);
hLayout->setMargin(10);
hLayout->setSpacing(10);
QVBoxLayout *leftLayout = new QVBoxLayout(0);
leftLayout->setSpacing(10);
hLayout->addLayout(leftLayout);
QLabel *scalarLabel = new QLabel(tr("Scalar variables"), central);
leftLayout->addWidget(scalarLabel);
variables = new QListWidget(central);
leftLayout->addWidget(variables);
connect(variables, SIGNAL(currentTextChanged(const QString &)),
this, SLOT(onSelectVariable(const QString &)));
// Create the visualization windows. Do an easy layout in this example.
QSplitter *splitter = new QSplitter(central);
splitter->setOrientation(Qt::Horizontal);
hLayout->addWidget(splitter, 100);
viswindows[PSEUDOCOLOR_WINDOW] = new vtkQtRenderWindow(splitter);
viswindows[PSEUDOCOLOR_WINDOW]->setMinimumSize(QSize(300,400));
viswindows[VOLUME_WINDOW] = new vtkQtRenderWindow(splitter);
viswindows[VOLUME_WINDOW]->setMinimumSize(QSize(300,400));
//
// Register a window creation function (before Setup) that will
// return the vtkQtRenderWindow objects that we've already
// parented into our interface.
//
viewer->SetWindowCreationCallback(ReturnVisWin, (void *)this);
// Create menus
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(tr("Open . . ."), this, SLOT(selectFile()));
fileMenu->addSeparator();
fileMenu->addAction(tr("Quit"), qApp, SLOT(quit()));
QMenu *controlsMenu = menuBar()->addMenu(tr("Controls"));
controlsMenu->addAction(tr("Open GUI"), this, SLOT(openGUI()));
}
MultiWindowVisApp::~MultiWindowVisApp()
{
}
void
MultiWindowVisApp::show()
{
qDebug("show");
// Tell the viewer to hide toolbars in all windows.
viewer->DelayedMethods()->HideToolbars(true);
if(!windowsAdded)
{
windowsAdded = true;
// Call AddWindow() N-1 times to make sure that VisIt calls the window
// creation callback the appropriate number of times.
viewer->DelayedMethods()->ToggleLockViewMode();
for(int i = 0; i < NWINDOWS-1; ++i)
{
viewer->DelayedMethods()->AddWindow();
viewer->DelayedMethods()->ToggleLockViewMode();
}
}
viewer->DelayedMethods()->ShowAllWindows();
QMainWindow::show();
}
// ****************************************************************************
// Method: MultiWindowVisApp::selectFile
//
// Programmer: Brad Whitlock
// Creation: Fri Nov 21 10:23:40 PST 2008
//
// Modifications:
//
// ****************************************************************************
void
MultiWindowVisApp::selectFile()
{
// Get a filename from the file dialog.
QString filename = QFileDialog::getOpenFileName(this,
tr("Open File"),
QDir::current().path(),
tr("Data files (*.silo *.vtk *.cgns *.nc *.h5 *.pdb *.visit)"));
filename = QDir::toNativeSeparators(filename);
openFile(filename);
}
void
MultiWindowVisApp::openFile(const QString &filename)
{
if(!filename.isEmpty())
{
activeFile = filename;
resetWindow();
// Get the file's metadata and populate the variable list.
const avtDatabaseMetaData *md = viewer->GetMetaData(filename.toStdString());
if(md != 0)
{
variables->blockSignals(true);
for(int i = 0; i < md->GetNumScalars(); ++i)
variables->addItem(md->GetScalar(i)->name.c_str());
variables->blockSignals(false);
variables->setEnabled(md->GetNumScalars() > 0);
}
}
}
void
MultiWindowVisApp::resetWindow()
{
variables->blockSignals(true);
variables->clear();
variables->blockSignals(false);
viewer->Methods()->SetActiveWindow(VOLUME_WINDOW);
viewer->Methods()->DeleteActivePlots();
viewer->Methods()->SetActiveWindow(PSEUDOCOLOR_WINDOW);
viewer->Methods()->DeleteActivePlots();
}
void
MultiWindowVisApp::onSelectVariable(const QString &var)
{
if(viewer->State()->GetPlotList()->GetNumPlots() == 1)
{
viewer->DelayedMethods()->SetActiveWindow(VOLUME_WINDOW);
viewer->DelayedMethods()->ChangeActivePlotsVar(var.toStdString());
viewer->DelayedMethods()->SetActiveWindow(PSEUDOCOLOR_WINDOW);
viewer->DelayedMethods()->ChangeActivePlotsVar(var.toStdString());
}
else
{
viewer->DelayedMethods()->SetActiveWindow(VOLUME_WINDOW);
viewer->DelayedMethods()->OpenDatabase(activeFile.toStdString());
viewer->DelayedMethods()->DeleteActivePlots();
viewer->DelayedMethods()->AddPlot(viewer->GetPlotIndex("Volume"),
var.toStdString());
viewer->DelayedMethods()->DrawPlots();
viewer->DelayedMethods()->SetActiveWindow(PSEUDOCOLOR_WINDOW);
viewer->DelayedMethods()->OpenDatabase(activeFile.toStdString());
viewer->DelayedMethods()->DeleteActivePlots();
viewer->DelayedMethods()->AddPlot(viewer->GetPlotIndex("Pseudocolor"),
var.toStdString());
viewer->DelayedMethods()->DrawPlots();
}
}
void
MultiWindowVisApp::openGUI()
{
stringVector args;
viewer->DelayedMethods()->OpenClient("GUI", viewer->GetVisItCommand(), args);
}
void
MultiWindowVisApp::showTheWindow()
{
show();
raise();
}
#ifndef MULTI_WINDOW_VIS_APP_H
#define MULTI_WINDOW_VIS_APP_H
#include <QMainWindow>
class VisItViewer;
class QListWidget;
class vtkQtRenderWindow;
#define NWINDOWS 2
#define PSEUDOCOLOR_WINDOW 1
#define VOLUME_WINDOW 2
class MultiWindowVisApp : public QMainWindow
{
Q_OBJECT
public:
MultiWindowVisApp(VisItViewer *v);
virtual ~MultiWindowVisApp();
// Window creation callback. Returns the vis window pointers to VisIt.
static vtkQtRenderWindow *ReturnVisWin(void *data);
public slots:
virtual void show();
private slots:
void selectFile();
void openFile(const QString &);
void onSelectVariable(const QString &var);
void resetWindow();
void openGUI();
void showTheWindow();
private:
bool windowsAdded;
QString activeFile;
VisItViewer *viewer;
QListWidget *variables;
int currentWindow;
vtkQtRenderWindow *viswindows[NWINDOWS + 1];
};
#endif
......@@ -25,6 +25,21 @@
#include "CommandParser.h"
QWidget *
create_application_main_window(VisItViewer *v)
{
return new SimpleVisApp(v);
}
void
show_application_main_window(QWidget *w)
{
// Do it like this since virtual show isn't working...
SimpleVisApp *app = (SimpleVisApp *)w;
app->show();
app->raise();
}
vtkQtRenderWindow *
SimpleVisApp::ReturnVisWin(void *data)
{
......@@ -156,10 +171,6 @@ SimpleVisApp::resetWindow()
viewer->Methods()->DeleteActivePlots();
}
//
// Qt slots
//
void
SimpleVisApp::show()
{
......@@ -173,6 +184,10 @@ SimpleVisApp::show()
QMainWindow::show();
}
//
// Qt slots
//
// ****************************************************************************
// Method: SimpleVisApp::selectFile
//
......
......@@ -37,6 +37,7 @@ public:
public slots:
virtual void show();
private slots:
void selectFile();
void openFile(const QString &);
......
......@@ -43,7 +43,10 @@
#include <VisItViewer.h>
#include <VisItException.h>
#include <SimpleVisApp.h>
#include <QWidget>
extern QWidget *create_application_main_window(VisItViewer *v);
extern void show_application_main_window(QWidget *w);
// ****************************************************************************
// Method: main
......@@ -64,6 +67,9 @@
// the executable gets placed in the VisIt build tree. I think it only works
// for UNIX in-source builds though. A real app would do something better.
//
// Brad Whitlock, Tue Nov 30 11:09:15 PST 2010
// Get the window from an external routine so we can reuse main.C
//
// ****************************************************************************
int
......@@ -116,7 +122,7 @@ main(int argc, char *argv[])
// Create our visualization app. We have to do it before the call to Setup()
// since we're embedding vis windows.
//
SimpleVisApp *visapp = new SimpleVisApp(&viewer);
QWidget *visapp = create_application_main_window(&viewer);
//
// Now that we've created the QApplication, let's call the viewer's
......@@ -127,8 +133,7 @@ main(int argc, char *argv[])
//
// Show our app's main window
//
visapp->show();
visapp->raise();
show_application_main_window(visapp);
//
// Execute the viewer.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment