4 #include <qfiledialog.h>
5 #include <qapplication.h>
6 #include <qmessagebox.h>
12 #include "MDIWindow.h"
16 #include "ViewOperations.h"
18 #include "Application.h"
20 MDIWindow::MDIWindow( Document* aDocument, QWidget* parent, V3d_TypeOfView type )
21 : QMainWindow( parent )
24 QSplitter* central = new QSplitter(Qt::Vertical, this);
26 myDocument = aDocument;
27 Handle(AIS_InteractiveContext) cxt = myDocument->getContext();
28 cxt->CurrentViewer()->SetDefaultTypeOfView( type );
29 myView = new View( cxt, central, this );
\r
30 verify(connect(myView, SIGNAL(ViewInitialized()),
\r
31 Application::getApplication(), SLOT(updateViewDlg())));
33 // Graph initialization
34 myGraphView = new GraphSplitView(central);
35 GraphView* pGraph = myGraphView->getGraph();
36 GraphItem* pItem = new GraphItem(pGraph, tr("LEG_NONOPT_DISPLAY"));
37 pItem->setSorted(true);
38 pItem->setMarker(0, QColor( Qt::blue ), Qt::SolidLine);
40 pItem = new GraphItem(pGraph, tr("LEG_OPT_DISPLAY"));
41 pItem->setSorted(true);
42 pItem->setMarker(1, QColor( Qt::red ), Qt::SolidLine);
44 pItem = new GraphItem(pGraph, tr("LEG_NONOPT_UPDATE"));
45 pItem->setSorted(true);
46 pItem->setMarker(2, QColor( Qt::blue ), Qt::DotLine);
48 pItem = new GraphItem(pGraph, tr("LEG_OPT_UPDATE"));
49 pItem->setSorted(true);
50 pItem->setMarker(3, QColor( Qt::red ), Qt::DotLine);
52 pGraph->setXTitle(tr("LAB_TRIANGLES"));
53 pGraph->setYTitle(tr("LAB_SECONDS"));
54 pGraph->installEventFilter(this);
55 pGraph->setOperationEnabled(GraphView::voRect, true);
56 pGraph->setOperationEnabled(GraphView::voZoom, true);
\r
57 pGraph->setOperationEnabled(GraphView::voZoomX, true);
58 pGraph->setOperationEnabled(GraphView::voZoomY, true);
59 pGraph->setOperationEnabled(GraphView::voPan, true);
\r
60 pGraph->setOperationEnabled(GraphView::voPanX, true);
\r
61 pGraph->setOperationEnabled(GraphView::voPanY, true);
\r
63 central->setStretchFactor(0, 5);
\r
64 central->setStretchFactor(1, 1);
\r
65 setCentralWidget( central );
67 myGraphPopup = new QMenu(pGraph);
69 myOperations = new ViewOperations( myDocument->getContext() );
71 verify( connect( myView, SIGNAL( noActiveActions() ),
72 myOperations, SLOT( onNoActiveActions() ) ) );
73 verify( connect( myOperations, SIGNAL( setCursor( const QCursor& ) ),
74 SLOT( setCursor( const QCursor& ) ) ) );
76 createViewActions();
\r
77 createGraphActions();
\r
80 MDIWindow::~MDIWindow()
85 Document* MDIWindow::getDocument()
90 int MDIWindow::getDisplayMode()
92 return myOperations->getDisplayMode();
95 void MDIWindow::closeEvent(QCloseEvent* e)
97 emit sendCloseView( this );
100 void MDIWindow::createViewActions()
102 QToolBar* aToolBar = new QToolBar( tr( "View Operations" ), this );
\r
103 addToolBar( Qt::TopToolBarArea, aToolBar );
105 QList<QAction*> aList = myOperations->getToolActions();
107 QActionGroup* dModeGroup = new QActionGroup( aToolBar );
111 foreach( a, aList ) {
\r
112 aToolBar->addAction( a );
114 // aToolBar->addSeparator();
115 if ( i == ViewOperations::ToolWireframeId || i == ViewOperations::ToolShadingId ) {
116 dModeGroup->addAction( a );
120 aToolBar->addSeparator();
122 aList = myOperations->getViewActions();
\r
123 foreach( a, aList ) aToolBar->addAction( a );
126 void MDIWindow::setCursor(const QCursor& aCursor)
128 myView->setCursor(aCursor);
131 void MDIWindow::defineMagView()
133 myView->setCurrentAction();
136 Handle(V3d_View)& MDIWindow::getView()
138 return myView->getView();
141 void MDIWindow::activateAction( ViewOperations::Action action )
143 myView->startAction( action );
146 void MDIWindow::addResult(ResultType item, int x, double y)
148 if (item == Undefined) return;
150 GraphView* pGraph = myGraphView->getGraph();
151 pGraph->getItem((int)item)->addNode(x, y);
152 double xMin, xMax, yMin, yMax;
153 pGraph->getRange(xMin, yMin, xMax, yMax);
154 pGraph->fitData(0, xMax, 0, yMax);
157 bool MDIWindow::eventFilter(QObject* dstObj, QEvent* event)
159 if (event->type() == QEvent::MouseButtonPress)
161 QMouseEvent* mEvent = (QMouseEvent*)event;
162 if (mEvent->button() == Qt::RightButton &&
163 !(mEvent->modifiers() & (Qt::ControlModifier | Qt::AltModifier | Qt::ShiftModifier)))
164 graphPopup(mEvent->globalPos());
169 void MDIWindow::createGraphActions()
171 QAction* a = new QAction( tr( "MEN_GRAPH_FIT_ALL" ), this );
\r
172 a->setToolTip( tr( "TBR_GRAPH_FIT_ALL" ) );
173 verify( connect( a, SIGNAL( activated() ) , this, SLOT( onGraphFitAll() ) ) );
174 myGraphPopup->addAction( a );
176 myGraphPopup->addSeparator();
178 a = new QAction( tr( "MEN_GRAPH_CLEAR" ), this );
179 a->setToolTip( tr( "TBR_GRAPH_CLEAR" ) );
\r
180 verify( connect( a, SIGNAL( activated() ) , this, SLOT( onGraphClear() ) ) );
181 myGraphPopup->addAction( a );
\r
184 void MDIWindow::graphPopup(const QPoint& pos)
186 myGraphPopup->popup(pos);
189 void MDIWindow::onGraphClear()
191 GraphView* graph = myGraphView->getGraph();
192 for (int i = 0; i < graph->getNbItems(); i++)
194 graph->getItem(i)->clear();
195 graph->getItem(i)->addNode(0, 0);
200 void MDIWindow::onGraphFitAll()
202 GraphView* graph = myGraphView->getGraph();
203 double xMin, xMax, yMin, yMax;
204 graph->getRange(xMin, yMin, xMax, yMax);
205 graph->fitData(0, xMax, 0, yMax);