Salome HOME
Compile errors on Mandrake Linux were fixed
[modules/gui.git] / src / SVTK / SVTK_ViewWindow.cxx
1 #include "SALOME_Actor.h"
2
3 #include <qapplication.h>
4
5 #include <vtkActorCollection.h>
6 #include <vtkRenderWindow.h>
7 #include <vtkRenderer.h>
8 #include <vtkCamera.h>
9
10 #include "QtxAction.h"
11
12 #include "SUIT_Session.h"
13 #include "SUIT_ToolButton.h"
14 #include "SUIT_MessageBox.h"
15
16 #include "SUIT_Tools.h"
17 #include "SUIT_ResourceMgr.h"
18 #include "SUIT_FileDlg.h"
19
20 #include "VTKViewer_Transform.h"
21 #include "VTKViewer_Utilities.h"
22
23 #include "SVTK_Trihedron.h"
24 #include "SVTK_ViewWindow.h"
25 #include "SVTK_ViewModel.h"
26 #include "SVTK_RenderWindow.h"
27 #include "SVTK_RenderWindowInteractor.h"
28 #include "SVTK_InteractorStyle.h"
29
30 #include "SALOME_ListIteratorOfListIO.hxx"
31
32 #include "SVTK_SelectorDef.h"
33
34 #include "VTKViewer_Algorithm.h"
35 #include "SVTK_Functor.h"
36
37 //----------------------------------------------------------------------------
38 SVTK_ViewWindow
39 ::SVTK_ViewWindow( SUIT_Desktop* theDesktop, 
40                    SVTK_Viewer* theModel)
41   : SUIT_ViewWindow(theDesktop)
42 {
43   myModel = theModel;
44   mySelector = new SVTK_SelectorDef();
45   connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
46
47   myTransform = VTKViewer_Transform::New();
48   myTrihedron = SVTK_Trihedron::New();
49   myRenderer  = vtkRenderer::New() ;
50
51   myTrihedron->AddToRender( myRenderer );
52
53   myRenderWindow = new SVTK_RenderWindow( this, "RenderWindow" );
54   setCentralWidget(myRenderWindow);
55   myRenderWindow->setFocusPolicy( StrongFocus );
56   myRenderWindow->setFocus();
57
58   myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
59
60   myRenderer->GetActiveCamera()->ParallelProjectionOn();
61   myRenderer->LightFollowCameraOn();
62   myRenderer->TwoSidedLightingOn();
63
64   // Set BackgroundColor
65   QString BgrColorRed   = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
66   QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
67   QString BgrColorBlue  = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
68
69   if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() ) 
70     myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
71   else
72     myRenderer->SetBackground( 0, 0, 0 );
73   
74   // Create an interactor.
75   myRWInteractor = SVTK_RenderWindowInteractor::New();
76   myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
77   myRWInteractor->setViewWindow( this );
78
79   SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New();
80   RWS->setGUIWindow( myRenderWindow );
81   RWS->setViewWindow( this );
82
83   myRWInteractor->SetInteractorStyle( RWS ); 
84   myRWInteractor->Initialize();
85
86   RWS->setTriedron( myTrihedron );
87   RWS->FindPokedRenderer( 0, 0 );
88
89   SetSelectionMode(ActorSelection);
90
91   setCentralWidget( myRenderWindow );
92
93   myToolBar = new QToolBar(this);
94   myToolBar->setCloseMode(QDockWindow::Undocked);
95   myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
96
97   createActions();
98   createToolBar();
99
100   connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
101            this,           SLOT(onKeyPressed( QKeyEvent* )) );
102   connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
103            this,           SLOT(onKeyReleased( QKeyEvent* )) );
104   connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
105            this,           SLOT(onMousePressed( QMouseEvent* )) );
106   connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
107            this,           SLOT(onMouseReleased( QMouseEvent* )) );
108   connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
109            this,           SLOT(onMouseDoubleClicked( QMouseEvent* )) );
110   connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
111            this,           SLOT(onMouseMoving( QMouseEvent* )) );
112
113   connect( myRWInteractor, SIGNAL(RenderWindowModified()),
114            myRenderWindow, SLOT(update()) );
115   connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
116            this,           SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
117
118   onResetView();
119 }
120
121 //----------------------------------------------------------------------------
122 SVTK_ViewWindow
123 ::~SVTK_ViewWindow()
124 {
125   myTransform->Delete();
126   // In order to ensure that the interactor unregisters
127   // this RenderWindow, we assign a NULL RenderWindow to 
128   // it before deleting it.
129   myRWInteractor->SetRenderWindow( NULL );
130   myRWInteractor->Delete();
131   
132   //m_RW->Delete() ;
133   myRenderer->RemoveAllProps();
134   //m_Renderer->Delete() ;
135   myTrihedron->Delete();
136 }
137
138 //----------------------------------------------------------------------------
139 void
140 SVTK_ViewWindow
141 ::activateZoom()
142 {
143   myRWInteractor->GetSInteractorStyle()->startZoom();
144 }
145
146 //----------------------------------------------------------------------------
147 void
148 SVTK_ViewWindow
149 ::activatePanning()
150 {
151   myRWInteractor->GetSInteractorStyle()->startPan();
152 }
153
154 //----------------------------------------------------------------------------
155 void
156 SVTK_ViewWindow
157 ::activateRotation()
158 {
159   myRWInteractor->GetSInteractorStyle()->startRotate();
160 }
161
162 //----------------------------------------------------------------------------
163 void
164 SVTK_ViewWindow
165 ::activateGlobalPanning()
166 {
167   if(myTrihedron->GetVisibleActorCount(myRenderer))
168     myRWInteractor->GetSInteractorStyle()->startGlobalPan();
169 }
170
171 //----------------------------------------------------------------------------
172 void
173 SVTK_ViewWindow
174 ::activateWindowFit()
175 {
176   myRWInteractor->GetSInteractorStyle()->startFitArea();
177 }
178
179 //----------------------------------------------------------------------------
180 void
181 SVTK_ViewWindow
182 ::createActions()
183 {
184   if (!myActionsMap.isEmpty()) return;
185   
186   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
187   
188   QtxAction* aAction;
189
190   // Dump view
191   aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
192                            tr( "MNU_DUMP_VIEW" ), 0, this);
193   aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
194   connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
195   myActionsMap[ DumpId ] = aAction;
196
197   // FitAll
198   aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
199                            tr( "MNU_FITALL" ), 0, this);
200   aAction->setStatusTip(tr("DSC_FITALL"));
201   connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
202   myActionsMap[ FitAllId ] = aAction;
203
204   // FitRect
205   aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
206                            tr( "MNU_FITRECT" ), 0, this);
207   aAction->setStatusTip(tr("DSC_FITRECT"));
208   connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
209   myActionsMap[ FitRectId ] = aAction;
210
211   // Zoom
212   aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
213                            tr( "MNU_ZOOM_VIEW" ), 0, this);
214   aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
215   connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
216   myActionsMap[ ZoomId ] = aAction;
217
218   // Panning
219   aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
220                            tr( "MNU_PAN_VIEW" ), 0, this);
221   aAction->setStatusTip(tr("DSC_PAN_VIEW"));
222   connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
223   myActionsMap[ PanId ] = aAction;
224
225   // Global Panning
226   aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
227                            tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
228   aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
229   connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
230   myActionsMap[ GlobalPanId ] = aAction;
231
232   // Rotation
233   aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
234                            tr( "MNU_ROTATE_VIEW" ), 0, this);
235   aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
236   connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
237   myActionsMap[ RotationId ] = aAction;
238
239   // Projections
240   aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
241                            tr( "MNU_FRONT_VIEW" ), 0, this);
242   aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
243   connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
244   myActionsMap[ FrontId ] = aAction;
245
246   aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
247                            tr( "MNU_BACK_VIEW" ), 0, this);
248   aAction->setStatusTip(tr("DSC_BACK_VIEW"));
249   connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
250   myActionsMap[ BackId ] = aAction;
251
252   aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
253                            tr( "MNU_TOP_VIEW" ), 0, this);
254   aAction->setStatusTip(tr("DSC_TOP_VIEW"));
255   connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
256   myActionsMap[ TopId ] = aAction;
257
258   aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
259                            tr( "MNU_BOTTOM_VIEW" ), 0, this);
260   aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
261   connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
262   myActionsMap[ BottomId ] = aAction;
263
264   aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
265                            tr( "MNU_LEFT_VIEW" ), 0, this);
266   aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
267   connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
268   myActionsMap[ LeftId ] = aAction;
269
270   aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
271                            tr( "MNU_RIGHT_VIEW" ), 0, this);
272   aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
273   connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
274   myActionsMap[ RightId ] = aAction;
275
276   // Reset
277   aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
278                            tr( "MNU_RESET_VIEW" ), 0, this);
279   aAction->setStatusTip(tr("DSC_RESET_VIEW"));
280   connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
281   myActionsMap[ ResetId ] = aAction;
282 }
283
284 //----------------------------------------------------------------------------
285 void
286 SVTK_ViewWindow
287 ::createToolBar()
288 {
289   myActionsMap[DumpId]->addTo(myToolBar);
290
291   SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
292   aScaleBtn->AddAction(myActionsMap[FitAllId]);
293   aScaleBtn->AddAction(myActionsMap[FitRectId]);
294   aScaleBtn->AddAction(myActionsMap[ZoomId]);
295
296   SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
297   aPanningBtn->AddAction(myActionsMap[PanId]);
298   aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
299
300   myActionsMap[RotationId]->addTo(myToolBar);
301
302   SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
303   aViewsBtn->AddAction(myActionsMap[FrontId]);
304   aViewsBtn->AddAction(myActionsMap[BackId]);
305   aViewsBtn->AddAction(myActionsMap[TopId]);
306   aViewsBtn->AddAction(myActionsMap[BottomId]);
307   aViewsBtn->AddAction(myActionsMap[LeftId]);
308   aViewsBtn->AddAction(myActionsMap[RightId]);
309
310   myActionsMap[ResetId]->addTo(myToolBar);
311 }
312
313 //----------------------------------------------------------------------------
314 void
315 SVTK_ViewWindow
316 ::onFrontView()
317 {
318   vtkCamera* camera = myRenderer->GetActiveCamera();
319   camera->SetPosition(1,0,0);
320   camera->SetViewUp(0,0,1);
321   camera->SetFocalPoint(0,0,0);
322   onFitAll();
323 }
324
325 //----------------------------------------------------------------------------
326 void
327 SVTK_ViewWindow
328 ::onBackView()
329 {
330   vtkCamera* camera = myRenderer->GetActiveCamera();
331   camera->SetPosition(-1,0,0);
332   camera->SetViewUp(0,0,1);
333   camera->SetFocalPoint(0,0,0);
334   onFitAll();
335 }
336
337 //----------------------------------------------------------------------------
338 void
339 SVTK_ViewWindow
340 ::onTopView()
341 {
342   vtkCamera* camera = myRenderer->GetActiveCamera();
343   camera->SetPosition(0,0,1);
344   camera->SetViewUp(0,1,0);
345   camera->SetFocalPoint(0,0,0);
346   onFitAll();
347 }
348
349 //----------------------------------------------------------------------------
350 void
351 SVTK_ViewWindow
352 ::onBottomView()
353 {
354   vtkCamera* camera = myRenderer->GetActiveCamera();
355   camera->SetPosition(0,0,-1);
356   camera->SetViewUp(0,1,0);
357   camera->SetFocalPoint(0,0,0);
358   onFitAll();
359 }
360
361 //----------------------------------------------------------------------------
362 void
363 SVTK_ViewWindow
364 ::onLeftView()
365 {
366   vtkCamera* camera = myRenderer->GetActiveCamera(); 
367   camera->SetPosition(0,-1,0);
368   camera->SetViewUp(0,0,1);
369   camera->SetFocalPoint(0,0,0);
370   onFitAll();
371 }
372
373 //----------------------------------------------------------------------------
374 void
375 SVTK_ViewWindow
376 ::onRightView()
377 {
378   vtkCamera* camera = myRenderer->GetActiveCamera();
379   camera->SetPosition(0,1,0);
380   camera->SetViewUp(0,0,1);
381   camera->SetFocalPoint(0,0,0);
382   onFitAll();
383 }
384
385 //----------------------------------------------------------------------------
386 void
387 SVTK_ViewWindow
388 ::onResetView()
389 {
390   int aTrihedronIsVisible = isTrihedronDisplayed();
391   myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
392   ::ResetCamera(myRenderer,true);  
393   vtkCamera* aCamera = myRenderer->GetActiveCamera();
394   aCamera->SetPosition(1,-1,1);
395   aCamera->SetViewUp(0,0,1);
396   ::ResetCamera(myRenderer,true);  
397   if(aTrihedronIsVisible) myTrihedron->VisibilityOn();
398   else myTrihedron->VisibilityOff();
399   static float aCoeff = 3.0;
400   aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
401   Repaint();
402 }
403
404 //----------------------------------------------------------------------------
405 void
406 SVTK_ViewWindow
407 ::onFitAll()
408 {
409   myRWInteractor->GetSInteractorStyle()->ViewFitAll();
410   Repaint();
411 }
412
413 //----------------------------------------------------------------------------
414 void
415 SVTK_ViewWindow
416 ::onDumpView()
417 {
418   QApplication::setOverrideCursor( Qt::waitCursor );
419   QPixmap px = QPixmap::grabWindow(myRenderWindow->winId());
420   QApplication::restoreOverrideCursor();
421   
422   QString fileName = SUIT_FileDlg::getFileName(this,
423                                               QString::null,
424                                               tr("VTK_IMAGE_FILES"),
425                                               tr("INF_APP_DUMP_VIEW"),
426                                               false);
427   if (!fileName.isNull()) {
428     QApplication::setOverrideCursor( Qt::waitCursor );
429     QString fmt = SUIT_Tools::extension( fileName ).upper();
430     if (fmt.isEmpty())
431       fmt = QString("BMP"); // default format
432     if (fmt == "JPG")
433       fmt = "JPEG";
434     bool bOk = px.save(fileName, fmt.latin1());
435     QApplication::restoreOverrideCursor();
436     if (!bOk) {
437       SUIT_MessageBox::error1(this, tr("ERROR"), tr("ERR_DOC_CANT_SAVE_FILE"), tr("BUT_OK"));
438     }
439   }
440 }
441
442 //----------------------------------------------------------------
443 void
444 SVTK_ViewWindow
445 ::onSelectionChanged()
446 {
447   unHighlightAll();
448
449   const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
450   SALOME_ListIteratorOfListIO anIter(aListIO);
451   for(; anIter.More(); anIter.Next()){
452     highlight(anIter.Value(),true,!anIter.More());
453   }
454
455   emit selectionChanged();
456 }
457
458 //----------------------------------------------------------------
459 void
460 SVTK_ViewWindow
461 ::SetSelectionMode(Selection_Mode theMode)
462 {
463   mySelector->SetSelectionMode(theMode);
464   myRWInteractor->SetSelectionMode(theMode);
465 }
466
467 //----------------------------------------------------------------
468 Selection_Mode
469 SVTK_ViewWindow
470 ::SelectionMode() const
471 {
472   return mySelector->SelectionMode();
473 }
474
475 //----------------------------------------------------------------
476 void 
477 SVTK_ViewWindow
478 ::unHighlightAll() 
479 {
480   myRWInteractor->unHighlightAll();
481 }
482
483 //----------------------------------------------------------------
484 void
485 SVTK_ViewWindow
486 ::highlight( const Handle(SALOME_InteractiveObject)& theIO, 
487              bool theIsHighlight, 
488              bool theIsUpdate ) 
489 {
490   myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
491
492   if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
493     TColStd_IndexedMapOfInteger aMapIndex;
494     mySelector->GetIndex(theIO,aMapIndex);
495     using namespace VTK;
496     const char* anEntry = theIO->getEntry();
497     vtkActorCollection* aCollection = myRenderer->GetActors();
498     if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
499       switch (mySelector->SelectionMode()) {
500       case NodeSelection:
501         myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
502         break;
503       case EdgeOfCellSelection:
504         myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
505         break;
506       case CellSelection:
507       case EdgeSelection:
508       case FaceSelection:
509       case VolumeSelection:
510         myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
511         break;
512       }
513     }
514   }else{
515     myRWInteractor->unHighlightSubSelection();
516   }
517 }
518
519 //----------------------------------------------------------------
520 bool
521 SVTK_ViewWindow
522 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO ) 
523 {
524   return myRWInteractor->isInViewer( theIO );
525 }
526
527 //----------------------------------------------------------------
528 bool
529 SVTK_ViewWindow
530 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO ) 
531 {
532   return myRWInteractor->isVisible( theIO );
533 }
534
535 //----------------------------------------------------------------------------
536 void
537 SVTK_ViewWindow
538 ::setBackgroundColor( const QColor& color )
539 {
540   if ( myRenderer )
541     myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
542 }
543
544 //----------------------------------------------------------------------------
545 QColor
546 SVTK_ViewWindow
547 ::backgroundColor() const
548 {
549   float backint[3];
550   if ( myRenderer ) {
551     myRenderer->GetBackground( backint );
552     return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
553   }
554   return SUIT_ViewWindow::backgroundColor();
555 }
556
557 //----------------------------------------------------------------------------
558 void
559 SVTK_ViewWindow
560 ::Repaint(bool theUpdateTrihedron)
561 {
562   if (theUpdateTrihedron) 
563     onAdjustTrihedron();
564   myRenderWindow->update();
565 }
566
567 //----------------------------------------------------------------------------
568 void
569 SVTK_ViewWindow
570 ::GetScale( double theScale[3] ) 
571 {
572   myTransform->GetScale( theScale );
573 }
574
575 //----------------------------------------------------------------------------
576 void
577 SVTK_ViewWindow
578 ::SetScale( double theScale[3] ) 
579 {
580   myTransform->SetScale( theScale[0], theScale[1], theScale[2] );
581   myRWInteractor->Render();
582   Repaint();
583 }
584
585 //----------------------------------------------------------------------------
586 bool
587 SVTK_ViewWindow
588 ::isTrihedronDisplayed()
589 {
590   return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
591 }
592
593 //----------------------------------------------------------------------------
594 void 
595 SVTK_ViewWindow
596 ::onViewTrihedron()
597 {
598   if(!myTrihedron) 
599     return;
600
601   if(isTrihedronDisplayed())
602     myTrihedron->VisibilityOff();
603   else
604     myTrihedron->VisibilityOn();
605
606   Repaint();
607 }
608
609 //----------------------------------------------------------------------------
610 bool
611 SVTK_ViewWindow
612 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
613 {
614   // calculating diagonal of visible props of the renderer
615   float aBndBox[ 6 ];
616   myTrihedron->VisibilityOff();
617
618   if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
619     aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
620     aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
621   }
622
623   myTrihedron->VisibilityOn();
624   float aLength = 0;
625   static bool aCalcByDiag = false;
626   if ( aCalcByDiag ) {
627     aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
628                     ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
629                     ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
630   } else {
631     aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
632     aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
633     aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
634   }
635
636   static float aSizeInPercents = 105;
637   //QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
638   //if ( !aSetting.isEmpty() )
639   //  aSizeInPercents = aSetting.toFloat();
640
641   static float EPS_SIZE = 5.0E-3;
642   theSize = myTrihedron->GetSize();
643   theNewSize = aLength * aSizeInPercents / 100.0;
644
645   // if the new trihedron size have sufficient difference, then apply the value
646   return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
647          fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
648 }
649
650 //----------------------------------------------------------------------------
651 double
652 SVTK_ViewWindow
653 ::GetTrihedronSize() const
654 {
655   return myTrihedron->GetSize();
656 }
657
658 //----------------------------------------------------------------------------
659 void
660 SVTK_ViewWindow
661 ::AdjustTrihedrons( const bool theIsForcedUpdate )
662 {
663   if ( !isTrihedronDisplayed() && !theIsForcedUpdate )
664     return;
665
666   int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
667   if ( aVisibleNum || theIsForcedUpdate ) {
668     // if the new trihedron size have sufficient difference, then apply the value
669     double aNewSize = 100, anOldSize;
670     if ( ComputeTrihedronSize( aNewSize, anOldSize ) || theIsForcedUpdate ) {
671       myTrihedron->SetSize( aNewSize );
672       // itearte throuh displayed objects and set size if necessary
673       
674       vtkActorCollection* anActors = getRenderer()->GetActors();
675       anActors->InitTraversal();
676       while( vtkActor* anActor = anActors->GetNextActor() ) {
677         if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) ) {
678           if ( aSActor->IsResizable() )
679             aSActor->SetSize( 0.5 * aNewSize );
680         }
681       }
682     }
683   }
684
685   ::ResetCameraClippingRange(myRenderer);
686 }
687
688 //----------------------------------------------------------------------------
689 void
690 SVTK_ViewWindow
691 ::onAdjustTrihedron()
692 {   
693   AdjustTrihedrons( false );
694 }
695
696 #define INCREMENT_FOR_OP 10
697
698 //=======================================================================
699 // name    : onPanLeft
700 // Purpose : Performs incremental panning to the left
701 //=======================================================================
702 void
703 SVTK_ViewWindow
704 ::onPanLeft()
705 {
706   myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
707 }
708
709 //=======================================================================
710 // name    : onPanRight
711 // Purpose : Performs incremental panning to the right
712 //=======================================================================
713 void
714 SVTK_ViewWindow
715 ::onPanRight()
716 {
717   myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
718 }
719
720 //=======================================================================
721 // name    : onPanUp
722 // Purpose : Performs incremental panning to the top
723 //=======================================================================
724 void
725 SVTK_ViewWindow
726 ::onPanUp()
727 {
728   myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
729 }
730
731 //=======================================================================
732 // name    : onPanDown
733 // Purpose : Performs incremental panning to the bottom
734 //=======================================================================
735 void
736 SVTK_ViewWindow
737 ::onPanDown()
738 {
739   myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
740 }
741
742 //=======================================================================
743 // name    : onZoomIn
744 // Purpose : Performs incremental zooming in
745 //=======================================================================
746 void
747 SVTK_ViewWindow
748 ::onZoomIn()
749 {
750   myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
751 }
752
753 //=======================================================================
754 // name    : onZoomOut
755 // Purpose : Performs incremental zooming out
756 //=======================================================================
757 void
758 SVTK_ViewWindow
759 ::onZoomOut()
760 {
761   myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
762 }
763
764 //=======================================================================
765 // name    : onRotateLeft
766 // Purpose : Performs incremental rotating to the left
767 //=======================================================================
768 void
769 SVTK_ViewWindow
770 ::onRotateLeft()
771 {
772   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
773 }
774
775 //=======================================================================
776 // name    : onRotateRight
777 // Purpose : Performs incremental rotating to the right
778 //=======================================================================
779 void
780 SVTK_ViewWindow
781 ::onRotateRight()
782 {
783   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
784 }
785
786 //=======================================================================
787 // name    : onRotateUp
788 // Purpose : Performs incremental rotating to the top
789 //=======================================================================
790 void
791 SVTK_ViewWindow
792 ::onRotateUp()
793 {
794   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
795 }
796
797 //=======================================================================
798 void
799 SVTK_ViewWindow
800 ::onKeyPressed(QKeyEvent* event)
801 {
802   emit keyPressed( this, event );
803 }
804
805 //=======================================================================
806 void
807 SVTK_ViewWindow
808 ::onKeyReleased(QKeyEvent* event)
809 {
810   emit keyReleased( this, event );
811 }
812
813 //=======================================================================
814 void
815 SVTK_ViewWindow
816 ::onMousePressed(QMouseEvent* event)
817 {
818   emit mousePressed(this, event);
819 }
820
821 //=======================================================================
822 void
823 SVTK_ViewWindow
824 ::onMouseReleased(QMouseEvent* event)
825 {
826   emit mouseReleased( this, event );
827 }
828
829 //=======================================================================
830 void
831 SVTK_ViewWindow
832 ::onMouseMoving(QMouseEvent* event)
833 {
834   emit mouseMoving( this, event );
835 }
836
837 //=======================================================================
838 void
839 SVTK_ViewWindow
840 ::onMouseDoubleClicked( QMouseEvent* event )
841 {
842   emit mouseDoubleClicked( this, event );
843 }
844
845 //=======================================================================
846 // name    : onRotateDown
847 // Purpose : Performs incremental rotating to the bottom
848 //=======================================================================
849 void
850 SVTK_ViewWindow
851 ::onRotateDown()
852 {
853   myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
854 }
855
856 //----------------------------------------------------------------------------
857 void
858 SVTK_ViewWindow
859 ::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
860 {
861   theActor->AddToRender(myRenderer);
862   theActor->SetTransform(myTransform);
863   if(theMoveInternalActors) 
864     myRWInteractor->MoveInternalActors();
865 }
866
867 //----------------------------------------------------------------------------
868 void
869 SVTK_ViewWindow
870 ::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
871 {
872   InsertActor(theActor);
873   if(theUpdate) 
874     Repaint();
875 }
876
877 //----------------------------------------------------------------------------
878 void
879 SVTK_ViewWindow
880 ::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
881 {
882   theActor->RemoveFromRender(myRenderer);
883   if(theUpdate) 
884     Repaint();
885 }
886
887 //----------------------------------------------------------------------------
888 void
889 SVTK_ViewWindow
890 ::MoveActor( SALOME_Actor* theActor)
891 {
892   RemoveActor(theActor);
893   InsertActor(theActor,true);
894 }