Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / QxScene / QxScene_ViewWindow.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SALOME QxScene : build Supervisor viewer into desktop
23 //
24 #include "QxScene_ViewWindow.h"
25 #include "QxScene_Def.h"
26
27 #include <SUIT_ResourceMgr.h>
28 #include <SUIT_Session.h>
29 #include <SUIT_Desktop.h>
30
31 #include <QtxAction.h>
32 #include <QtxMultiAction.h>
33 #include <QtxActionToolMgr.h>
34
35 //QT Include
36 #include <QToolBar>
37 #include <QGraphicsRectItem>
38
39 //#define _DEVDEBUG_
40 #include "DebTrace.hxx"
41
42 using namespace std;
43
44 /*!
45     Constructor
46 */
47 QxScene_ViewWindow::QxScene_ViewWindow( SUIT_Desktop* theDesktop, QxScene_Viewer* theModel)
48   : SUIT_ViewWindow( theDesktop )
49 {
50   DEBTRACE("Construct QxScene_ViewWindow");
51   myViewModel = theModel;
52   _scene = 0;
53   _sceneView = 0;
54 }
55
56 /*!
57   Initialization
58 */
59 void QxScene_ViewWindow::initLayout()
60 {
61   DEBTRACE("QxScene_ViewWindow::initLayout");
62   createActions();
63   createToolBar();
64   
65   // --- QGraphics test
66
67 //   _scene = new QGraphicsScene();
68 //   _sceneView = new QGraphicsView(this);
69 //   setCentralWidget(_sceneView);
70 //   _sceneView->setScene(_scene);
71 //   QGraphicsRectItem *rect = _scene->addRect(QRectF(0, 0, 100, 100));
72 //   _sceneView->show();
73 }
74
75 /*!
76   Creates actions of QxScene view window
77 */
78 void QxScene_ViewWindow::createActions()
79 {
80   DEBTRACE("QxScene_ViewWindow::createActions");
81   QtxActionToolMgr* mgr = toolMgr();
82   QtxAction* aAction;
83   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
84
85   // 2. Scaling operations
86
87   // 2.1. Fit All
88   aAction = new QtxAction( tr( "MNU_FITALL" ),
89                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_FITALL" ) ),
90                            tr( "MNU_FITALL" ),
91                            0, this);
92   aAction->setStatusTip( tr( "DSC_FITALL" ) );
93   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitAll() ) );
94   mgr->registerAction( aAction, FitAllId );
95
96   // 2.2. Fit Rect
97   aAction = new QtxAction( tr( "MNU_FITRECT" ),
98                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_FITAREA" ) ),
99                            tr( "MNU_FITRECT" ),
100                            0, this);
101   aAction->setStatusTip( tr( "DSC_FITRECT" ) );
102   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewFitArea() ) );
103   mgr->registerAction( aAction, FitRectId );
104
105   // 2.3. Zoom
106   aAction = new QtxAction( tr( "MNU_ZOOM_VIEW" ),
107                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_ZOOM" ) ),
108                            tr( "MNU_ZOOM_VIEW" ),
109                            0, this);
110   aAction->setStatusTip( tr( "DSC_ZOOM_VIEW" ) );
111   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewZoom() ) );
112   mgr->registerAction( aAction, ZoomId );
113
114   // 2.4. Create multi-action for scaling operations
115   QtxMultiAction* aScaleAction = new QtxMultiAction( this );
116   aScaleAction->insertAction( mgr->action( FitAllId  ) );
117   aScaleAction->insertAction( mgr->action( FitRectId ) );
118   aScaleAction->insertAction( mgr->action( ZoomId    ) );
119   mgr->registerAction( aScaleAction, ScaleOpId );
120
121   // 3. Moving operations
122
123   // 3.1. Panning
124   aAction = new QtxAction( tr( "MNU_PAN_VIEW" ),
125                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_PAN" ) ),
126                            tr( "MNU_PAN_VIEW" ), 
127                            0, this);
128   aAction->setStatusTip( tr( "DSC_PAN_VIEW" ) );
129   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewPan() ) );
130   mgr->registerAction( aAction, PanId );
131
132   // 3.2. Global Panning
133   aAction = new QtxAction( tr( "MNU_GLOBALPAN_VIEW" ),
134                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_GLOBALPAN" ) ),
135                            tr( "MNU_GLOBALPAN_VIEW" ),
136                            0, this);
137   aAction->setStatusTip( tr( "DSC_GLOBALPAN_VIEW" ) );
138   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewGlobalPan() ) );
139   mgr->registerAction( aAction, GlobalPanId );
140
141   // 3.3. Create multi-action for moving operations
142   QtxMultiAction* aPanAction = new QtxMultiAction( this );
143   aPanAction->insertAction( mgr->action( PanId ) );
144   aPanAction->insertAction( mgr->action( GlobalPanId ) );
145   mgr->registerAction( aPanAction, MoveOpId );
146
147   // reset
148   aAction = new QtxAction( tr( "MNU_RESET_VIEW" ),
149                            aResMgr->loadPixmap( "QxSceneViewer", tr( "ICON_QXSCENE_RESET" ) ),
150                            tr( "MNU_RESET_VIEW" ), 
151                            0, this);
152   aAction->setStatusTip( tr( "DSC_RESET_VIEW" ) );
153   connect( aAction, SIGNAL( triggered( bool ) ), this, SLOT( onViewReset() ) );
154   mgr->registerAction( aAction, ResetId );
155 }
156
157 /*!
158   Creates toolbar of QxScene view window
159 */
160 void QxScene_ViewWindow::createToolBar()
161 {
162   DEBTRACE("QxScene_ViewWindow::createToolBar");
163   QtxActionToolMgr* mgr = toolMgr();
164   myToolBar = mgr->createToolBar( tr( "LBL_TOOLBAR_LABEL" ) );
165   mgr->append( ScaleOpId, myToolBar );
166   mgr->append( MoveOpId, myToolBar );
167   mgr->append( ResetId, myToolBar );
168 }
169
170 /*!
171   \brief Get view window's toolbar.
172   \return toolbar
173 */
174 QToolBar* QxScene_ViewWindow::getToolBar()
175 {
176   DEBTRACE("QxScene_ViewWindow::getToolBar");
177   return toolMgr()->toolBar( myToolBar );
178 }
179
180 /*!
181   Destructor
182 */
183 QxScene_ViewWindow::~QxScene_ViewWindow()
184 {
185   DEBTRACE("destructor QxScene_ViewWindow");
186
187 }
188
189 /*!
190   Reset the active view
191 */
192 void QxScene_ViewWindow::onViewReset()    
193 {
194   DEBTRACE( "QxScene_ViewWindow::onViewReset" );
195 }
196
197 /*!
198   Sets a new center of the active view
199 */
200 void QxScene_ViewWindow::onViewGlobalPan()
201 {
202   DEBTRACE( "QxScene_ViewWindow::onViewGlobalPan" );
203 }
204
205 /*!
206   Zooms the active view
207 */
208 void QxScene_ViewWindow::onViewZoom()
209 {
210   DEBTRACE( "QxScene_ViewWindow::onViewZoom" );
211 }
212
213 /*!
214   Moves the active view
215 */
216 void QxScene_ViewWindow::onViewPan()
217 {
218   DEBTRACE( "QxScene_ViewWindow::onViewPan" );
219 }
220
221 /*!
222   Fits all obejcts within a rectangular area of the active view
223 */
224 void QxScene_ViewWindow::onViewFitArea()
225 {
226   DEBTRACE( "QxScene_ViewWindow::onViewFitArea" );
227 }
228
229 /*!
230   Fits all objects in the active view
231 */
232 void QxScene_ViewWindow::onViewFitAll()
233 {
234   DEBTRACE( "QxScene_ViewWindow::onViewFitAll" );
235 }
236
237 /*!
238     Set background of the viewport
239 */
240 void QxScene_ViewWindow::setBackgroundColor( const QColor& color )
241 {
242   DEBTRACE("QxScene_ViewWindow::setBackgroundColor");
243 }
244
245 /*!
246     Returns background of the viewport
247 */
248 QColor QxScene_ViewWindow::backgroundColor() const
249 {
250   DEBTRACE("QxScene_ViewWindow::backgroundColor");
251   QColor col;
252   return col;
253 }
254
255 /*!
256   Custom resize event handler
257 */
258 void QxScene_ViewWindow::resizeEvent( QResizeEvent* theEvent )
259 {
260   DEBTRACE("QxScene_ViewWindow::resizeEvent");
261 }
262
263 /*!
264   Get resource manager
265 */
266 SUIT_ResourceMgr* QxScene_ViewWindow::resMgr() const
267
268   DEBTRACE("QxScene_ViewWindow::resMgr");
269   return SUIT_Session::session()->resourceMgr(); 
270 }
271
272 /*!
273  *  emits a signal to ask to close the schema associated to the window.
274  *  A boolean in return indicates if it is OK to close.
275  */
276 bool QxScene_ViewWindow::closeRequested()
277 {
278   DEBTRACE("QxScene_ViewWindow::closeRequested");
279   bool isClosed = false;
280   emit tryClose(isClosed, this);
281   DEBTRACE("isClosed=" << isClosed);
282   return isClosed;
283 }