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