Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #include "main_widget.h"
00020 #include "moc_main_widget.cpp"
00021 
00022 #include "graph/posegraph3d.h"
00023 
00024 #include <QFileDialog>
00025 
00026 #include <iostream>
00027 #include <fstream>
00028 using namespace std;
00029 using namespace AISNavigation;
00030 
00031 MainWidget::MainWidget(QWidget* parent, Qt::WindowFlags flags) :
00032   QMainWindow(parent, flags)
00033 {
00034   setupUi(this);
00035   setWindowTitle("GraphViewer");
00036 
00037   
00038   connect((const QObject*) actionLoad, SIGNAL( activated() ), 
00039           (const QObject*) this, SLOT( loadGraph() ) );
00040   connect((const QObject*) actionSave, SIGNAL( activated() ), 
00041           (const QObject*) this, SLOT( saveGraph() ) );
00042   connect((const QObject*) actionExit, SIGNAL( activated() ), 
00043           (const QObject*) this, SLOT( close() ) );
00044   connect((const QObject*) actionSave_VRML, SIGNAL( activated() ), 
00045           (const QObject*) this, SLOT( saveGraphVrml() ) );
00046 
00047   
00048   connect((const QObject*) actionGraph, SIGNAL( toggled(bool) ), 
00049           (const QObject*) this, SLOT( setDrawGraph(bool) ) );
00050   connect((const QObject*) actionHirarchy, SIGNAL( toggled(bool) ), 
00051           (const QObject*) this, SLOT( setDrawHirarchy(bool) ) );
00052 }
00053 
00054 MainWidget::~MainWidget()
00055 {
00056 }
00057 
00058 void MainWidget::loadGraph()
00059 {
00060   PoseGraph3D* graph = viewer->graph.getGraph();
00061   if (!graph) {
00062     cerr << "No graph available" << endl;
00063   }
00064   QString fileName = QFileDialog::getOpenFileName(this, tr("Open Graph File"), "", tr("Graph-Files (*.graph)"));
00065   if (!fileName.isEmpty()) {
00066     ifstream fin(fileName.toAscii());
00067     graph->clear();
00068     graph->load(fin);
00069     viewer->graph.setGraph(graph);
00070     viewer->updateGL();
00071   }
00072 }
00073 
00074 void MainWidget::saveGraph()
00075 {
00076   PoseGraph3D* graph = viewer->graph.getGraph();
00077   if (!graph) {
00078     cerr << "No graph available" << endl;
00079   }
00080   QString fileName = QFileDialog::getSaveFileName(this, tr("Save Graph File"), "", tr("Graph-Files (*.graph)"));
00081   if (!fileName.isEmpty()) {
00082     ofstream fout(fileName.toAscii());
00083     graph->save(fout);
00084   }
00085 }
00086 
00087 void MainWidget::saveGraphVrml()
00088 {
00089   PoseGraph3D* graph = viewer->graph.getGraph();
00090   if (!graph) {
00091     cerr << "No graph available" << endl;
00092   }
00093   QString fileName = QFileDialog::getSaveFileName(this, tr("Save Graph VRML-File"), "", tr("VRML-Files (*.wrl)"));
00094   if (!fileName.isEmpty()) {
00095     ofstream fout(fileName.toAscii());
00096     viewer->graph.writeVrml(fout);
00097   }
00098 }
00099 
00100 void MainWidget::setDrawGraph(bool b)
00101 {
00102   viewer->graph.setDrawGraph(b);
00103   viewer->updateGL();
00104 }
00105 
00106 void MainWidget::setDrawHirarchy(bool b)
00107 {
00108   viewer->graph.setDrawHirarchy(b);
00109   viewer->updateGL();
00110 }