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