Salome HOME
6cabb4e4efa0d7a9e06e78031ae25b267097d986
[modules/gui.git] / src / SUPERVGraph / SUPERVGraph_ViewFrame.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 SUPERVGraph : build Supervisor viewer into desktop
23 //  File   : SUPERVGraph_ViewFrame.cxx
24 //  Author : Nicolas REJNERI
25 //  Module : SALOME
26 //  $Header$
27 //
28 #include "SUPERVGraph_ViewFrame.h"
29
30 #include <SUIT_ResourceMgr.h>
31 #include <SUIT_Session.h>
32
33 //QT Include
34 #include <QVBoxLayout>
35 #include <QToolBar>
36
37 using namespace std;
38
39
40 /*!
41   Constructor
42 */
43 SUPERVGraph_View::SUPERVGraph_View( QWidget* theParent ): QWidget( theParent )
44 {
45   init(theParent);
46 }
47
48 /*!
49   Constructor
50 */
51 SUPERVGraph_View::SUPERVGraph_View( SUPERVGraph_View* theParent ): QWidget( theParent )
52 {
53   init(theParent);
54 }
55
56 /*!
57   Builds popup for SUPERVGraph viewer
58 */
59 void SUPERVGraph_View::contextMenuPopup( QMenu* )
60 {
61   // to be implemented
62 }
63
64 /*!
65   Initialization
66 */
67 void SUPERVGraph_View::init( QWidget* theParent )
68 {
69   if ( theParent->inherits( "QMainWindow" ) ) {
70     ( ( QMainWindow* )theParent )->setCentralWidget( this );
71   }
72   else {
73     QBoxLayout* layout = new QVBoxLayout( theParent );
74     layout->addWidget( this );
75   }
76
77 }
78
79 /*!
80     Constructor
81 */
82 SUPERVGraph_ViewFrame::SUPERVGraph_ViewFrame( SUIT_Desktop* theDesktop ) 
83   : SUIT_ViewWindow( theDesktop )
84 {
85   myView = 0;
86
87   //myView = new SUPERVGraph_View(this); 
88   // Set BackgroundColor
89   /*
90   int R = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorRed").toInt();
91   int G = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorGreen").toInt();
92   int B = QAD_CONFIG->getSetting("SUPERVGraph:BackgroundColorBlue").toInt();
93   setBackgroundColor(QColor(R,G,B));*/
94
95   myToolBar = new QToolBar(this);
96   //myToolBar->setCloseMode(QDockWindow::Undocked);
97   myToolBar->setWindowTitle(tr("LBL_TOOLBAR_LABEL"));
98   createActions();
99   createToolBar();
100 }
101
102 /*!
103   Creates actions of SUPERVGraph view window
104 */
105 void SUPERVGraph_ViewFrame::createActions()
106 {
107   if (!myActionsMap.isEmpty()) return;
108   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
109   QtxAction* aAction;
110
111   // Panning
112   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "SUPERVGraph", tr( "ICON_SUPERVGraph_PAN" ) ),
113                           tr( "MNU_PAN_VIEW" ), 0, this);
114   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
115   connect(aAction, SIGNAL(activated()), this, SLOT(onViewPan()));
116   myActionsMap[ PanId ] = aAction;
117
118   // Reset
119   aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "SUPERVGraph", tr( "ICON_SUPERVGraph_RESET" ) ),
120                           tr( "MNU_RESET_VIEW" ), 0, this);
121   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
122   connect(aAction, SIGNAL(activated()), this, SLOT(onViewReset()));
123   myActionsMap[ ResetId ] = aAction;
124 }
125
126 /*!
127   Creates toolbar of SUPERVGraph view window
128 */
129 void SUPERVGraph_ViewFrame::createToolBar()
130 {
131   myToolBar->addAction( myActionsMap[PanId] );
132   myToolBar->addAction( myActionsMap[ResetId] );
133 }
134
135 /*!
136   Destructor
137 */
138 SUPERVGraph_ViewFrame::~SUPERVGraph_ViewFrame() {}
139
140 /*!
141   Returns widget containing 3D-Viewer
142 */
143 SUPERVGraph_View* SUPERVGraph_ViewFrame::getViewWidget()
144 {
145   return myView;
146 }
147
148
149 /*!
150   Sets new view widget
151   \param theView - new view widget
152 */
153 void SUPERVGraph_ViewFrame::setViewWidget( SUPERVGraph_View* theView )
154 {
155   myView = theView;
156 }
157
158
159 /*!
160   Display/hide Trihedron
161 */
162 void SUPERVGraph_ViewFrame::onViewTrihedron()
163 {
164 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewTrihedron" )
165 }
166
167 /*!
168   Provides top projection of the active view
169 */
170 void SUPERVGraph_ViewFrame::onViewTop()
171 {
172 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewTop" )
173 }
174
175 /*!
176   Provides bottom projection of the active view
177 */
178 void SUPERVGraph_ViewFrame::onViewBottom()
179 {
180 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewBottom" )
181 }
182
183 /*!
184   Provides left projection of the active view
185 */
186 void SUPERVGraph_ViewFrame::onViewLeft()    
187 {
188 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewLeft" )
189 }
190
191 /*!
192   Provides right projection of the active view
193 */
194 void SUPERVGraph_ViewFrame::onViewRight()
195 {
196 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewRight" )
197 }
198
199 /*!
200   Provides back projection of the active view
201 */
202 void SUPERVGraph_ViewFrame::onViewBack()
203 {
204 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewBack" )
205 }
206
207 /*!
208   Provides front projection of the active view
209 */
210 void SUPERVGraph_ViewFrame::onViewFront()
211 {
212 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewFront" )
213 }
214
215 /*!
216   Reset the active view
217 */
218 void SUPERVGraph_ViewFrame::onViewReset()    
219 {
220 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewReset" )
221     if (myView)
222       myView->ResetView();
223 }
224
225 /*!
226   Rotates the active view
227 */
228 void SUPERVGraph_ViewFrame::onViewRotate()
229 {
230 //   MESSAGE ( "SUPERVGraph_ViewFrame::onViewRotate" )
231 }
232
233 /*!
234   Sets a new center of the active view
235 */
236 void SUPERVGraph_ViewFrame::onViewGlobalPan()
237 {
238 //   MESSAGE ( "SUPERVGraph_ViewFrame::onViewGlobalPan" )
239 }
240
241 /*!
242   Zooms the active view
243 */
244 void SUPERVGraph_ViewFrame::onViewZoom()
245 {
246 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewZoom" )
247 }
248
249 /*!
250   Moves the active view
251 */
252 void SUPERVGraph_ViewFrame::onViewPan()
253 {
254 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewPan" )
255     if (myView != NULL)
256       myView->ActivatePanning();
257 }
258
259 /*!
260   Fits all obejcts within a rectangular area of the active view
261 */
262 void SUPERVGraph_ViewFrame::onViewFitArea()
263 {
264 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewFitArea" )
265 }
266
267 /*!
268   Fits all objects in the active view
269 */
270 void SUPERVGraph_ViewFrame::onViewFitAll()
271 {
272 //  MESSAGE ( "SUPERVGraph_ViewFrame::onViewFitAll" )
273 }
274
275 /*!
276     Set background of the viewport
277 */
278 void SUPERVGraph_ViewFrame::setBackgroundColor( const QColor& color )
279 {
280   if (myView) {
281     QPalette palette;
282     palette.setColor(myView->backgroundRole(), color);
283     myView->setPalette(palette);
284   }
285 }
286
287 /*!
288     Returns background of the viewport
289 */
290 QColor SUPERVGraph_ViewFrame::backgroundColor() const
291 {
292   if (myView)
293     return myView->palette().color( myView->backgroundRole() );
294   return palette().color( backgroundRole() );
295 }
296
297 /*!
298 */
299 void SUPERVGraph_ViewFrame::onAdjustTrihedron()
300 {
301 //  MESSAGE ( "SUPERVGraph_ViewFrame::onAdjustTrihedron" )  
302 }
303
304 /*!
305   Changes name of object
306   \param obj - object to be renamed
307   \param name - new name
308 */
309 void SUPERVGraph_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, 
310                                     QString newName )
311 {
312 //  MESSAGE ( "SUPERVGraph_ViewFrame::rename" )
313 }
314
315 /*!
316   Unhilights all object in viewer
317   \param updateviewer - update current viewer
318 */
319 void SUPERVGraph_ViewFrame::unHighlightAll() 
320 {
321 //  MESSAGE ( "SUPERVGraph_ViewFrame::unHighlightAll" )
322 }
323
324 /*!
325   Hilights/unhilights object in viewer
326   \param obj - object to be updated
327   \param hilight - if it is true, object will be hilighted, otherwise it will be unhilighted
328   \param update - update current viewer
329 */
330 void SUPERVGraph_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject, 
331                                        bool highlight, bool immediatly ) 
332 {
333 //  MESSAGE ( "SUPERVGraph_ViewFrame::highlight" )
334 }
335
336 /*!
337   \return true if object is in viewer or in collector
338   \param obj - object to be checked
339   \param onlyInViewer - search object only in viewer (so object must be displayed)
340 */
341 bool SUPERVGraph_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject ) 
342 {
343 //  MESSAGE ( "SUPERVGraph_ViewFrame::isInViewer" )
344   return false;
345 }
346
347 /*!
348   \return true if object is displayed in viewer
349   \param obj - object to be checked
350 */
351 bool SUPERVGraph_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject ) 
352 {
353 //  MESSAGE ( "SUPERVGraph_ViewFrame::isVisible" )
354   return false;
355 }
356
357 /*!
358   Custom resize event handler
359 */
360 void SUPERVGraph_ViewFrame::resizeEvent( QResizeEvent* theEvent )
361 {
362   QMainWindow::resizeEvent( theEvent );
363   if ( myView ) myView->resizeView( theEvent );
364 }