1 #include "SALOME_Actor.h"
3 #include <qapplication.h>
5 #include <vtkTextProperty.h>
6 #include <vtkActorCollection.h>
7 #include <vtkRenderWindow.h>
8 #include <vtkRenderer.h>
11 #include "QtxAction.h"
13 #include "SUIT_Session.h"
14 #include "SUIT_ToolButton.h"
15 #include "SUIT_MessageBox.h"
17 #include "SUIT_Tools.h"
18 #include "SUIT_ResourceMgr.h"
20 #include "VTKViewer_Transform.h"
21 #include "VTKViewer_Utilities.h"
23 #include "SVTK_Trihedron.h"
24 #include "SVTK_CubeAxesActor2D.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"
31 #include "SALOME_ListIteratorOfListIO.hxx"
33 #include "SVTK_SelectorDef.h"
35 #include "VTKViewer_Algorithm.h"
36 #include "SVTK_Functor.h"
38 //----------------------------------------------------------------------------
40 ::SVTK_ViewWindow( SUIT_Desktop* theDesktop,
41 SVTK_Viewer* theModel)
42 : SUIT_ViewWindow( theDesktop ),
43 myTrihedronSize( 100 )
46 mySelector = new SVTK_SelectorDef();
47 connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
49 myTransform = VTKViewer_Transform::New();
50 myTrihedron = SVTK_Trihedron::New();
51 myCubeAxes = SVTK_CubeAxesActor2D::New();
52 myRenderer = vtkRenderer::New() ;
54 myTrihedron->AddToRender( myRenderer );
55 myRenderer->AddProp(myCubeAxes);
57 myRenderWindow = new SVTK_RenderWindow( this, "RenderWindow" );
58 setCentralWidget(myRenderWindow);
59 myRenderWindow->setFocusPolicy( StrongFocus );
60 myRenderWindow->setFocus();
62 myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
64 myRenderer->GetActiveCamera()->ParallelProjectionOn();
65 myRenderer->LightFollowCameraOn();
66 myRenderer->TwoSidedLightingOn();
68 // Set BackgroundColor
69 QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
70 QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
71 QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
73 if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
74 myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
76 myRenderer->SetBackground( 0, 0, 0 );
78 // Create an interactor.
79 myRWInteractor = SVTK_RenderWindowInteractor::New();
80 myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
81 myRWInteractor->setViewWindow( this );
83 SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New();
84 RWS->setGUIWindow( myRenderWindow );
85 RWS->setViewWindow( this );
87 myRWInteractor->SetInteractorStyle( RWS );
88 myRWInteractor->Initialize();
90 //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron );
91 RWS->FindPokedRenderer( 0, 0 );
93 SetSelectionMode(ActorSelection);
95 vtkTextProperty* tprop = vtkTextProperty::New();
96 tprop->SetColor(1, 1, 1);
100 bnd[0] = bnd[2] = bnd[4] = 0;
101 bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize();
102 myCubeAxes->SetLabelFormat("%6.4g");
103 myCubeAxes->SetBounds(bnd);
104 myCubeAxes->SetCamera(myRenderer->GetActiveCamera());
105 myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
106 myCubeAxes->SetFontFactor(0.8);
107 myCubeAxes->SetAxisTitleTextProperty(tprop);
108 myCubeAxes->SetAxisLabelTextProperty(tprop);
109 myCubeAxes->SetCornerOffset(0);
110 myCubeAxes->SetScaling(0);
111 myCubeAxes->SetNumberOfLabels(5);
112 myCubeAxes->VisibilityOff();
113 myCubeAxes->SetTransform(myTransform);
116 setCentralWidget( myRenderWindow );
118 myToolBar = new QToolBar(this);
119 myToolBar->setCloseMode(QDockWindow::Undocked);
120 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
125 connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
126 this, SLOT(onKeyPressed( QKeyEvent* )) );
127 connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
128 this, SLOT(onKeyReleased( QKeyEvent* )) );
129 connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
130 this, SLOT(onMousePressed( QMouseEvent* )) );
131 connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
132 this, SLOT(onMouseReleased( QMouseEvent* )) );
133 connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
134 this, SLOT(onMouseDoubleClicked( QMouseEvent* )) );
135 connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
136 this, SLOT(onMouseMoving( QMouseEvent* )) );
138 connect( myRWInteractor, SIGNAL(RenderWindowModified()),
139 myRenderWindow, SLOT(update()) );
140 connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
141 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
146 //----------------------------------------------------------------------------
150 myTransform->Delete();
151 // In order to ensure that the interactor unregisters
152 // this RenderWindow, we assign a NULL RenderWindow to
153 // it before deleting it.
154 myRWInteractor->SetRenderWindow( NULL );
155 myRWInteractor->Delete();
158 myRenderer->RemoveAllProps();
159 //m_Renderer->Delete();
160 myTrihedron->Delete();
161 myCubeAxes->Delete();
164 //----------------------------------------------------------------------------
169 myRWInteractor->GetSInteractorStyle()->startZoom();
172 //----------------------------------------------------------------------------
177 myRWInteractor->GetSInteractorStyle()->startPan();
180 //----------------------------------------------------------------------------
185 myRWInteractor->GetSInteractorStyle()->startRotate();
188 //----------------------------------------------------------------------------
191 ::activateGlobalPanning()
193 if(myTrihedron->GetVisibleActorCount(myRenderer))
194 myRWInteractor->GetSInteractorStyle()->startGlobalPan();
197 //----------------------------------------------------------------------------
200 ::activateWindowFit()
202 myRWInteractor->GetSInteractorStyle()->startFitArea();
205 //----------------------------------------------------------------------------
210 if (!myActionsMap.isEmpty()) return;
212 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
217 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
218 tr( "MNU_DUMP_VIEW" ), 0, this);
219 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
220 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
221 myActionsMap[ DumpId ] = aAction;
224 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
225 tr( "MNU_FITALL" ), 0, this);
226 aAction->setStatusTip(tr("DSC_FITALL"));
227 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
228 myActionsMap[ FitAllId ] = aAction;
231 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
232 tr( "MNU_FITRECT" ), 0, this);
233 aAction->setStatusTip(tr("DSC_FITRECT"));
234 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
235 myActionsMap[ FitRectId ] = aAction;
238 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
239 tr( "MNU_ZOOM_VIEW" ), 0, this);
240 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
241 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
242 myActionsMap[ ZoomId ] = aAction;
245 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
246 tr( "MNU_PAN_VIEW" ), 0, this);
247 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
248 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
249 myActionsMap[ PanId ] = aAction;
252 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
253 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
254 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
255 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
256 myActionsMap[ GlobalPanId ] = aAction;
259 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
260 tr( "MNU_ROTATE_VIEW" ), 0, this);
261 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
262 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
263 myActionsMap[ RotationId ] = aAction;
266 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
267 tr( "MNU_FRONT_VIEW" ), 0, this);
268 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
269 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
270 myActionsMap[ FrontId ] = aAction;
272 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
273 tr( "MNU_BACK_VIEW" ), 0, this);
274 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
275 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
276 myActionsMap[ BackId ] = aAction;
278 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
279 tr( "MNU_TOP_VIEW" ), 0, this);
280 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
281 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
282 myActionsMap[ TopId ] = aAction;
284 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
285 tr( "MNU_BOTTOM_VIEW" ), 0, this);
286 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
287 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
288 myActionsMap[ BottomId ] = aAction;
290 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
291 tr( "MNU_LEFT_VIEW" ), 0, this);
292 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
293 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
294 myActionsMap[ LeftId ] = aAction;
296 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
297 tr( "MNU_RIGHT_VIEW" ), 0, this);
298 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
299 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
300 myActionsMap[ RightId ] = aAction;
303 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
304 tr( "MNU_RESET_VIEW" ), 0, this);
305 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
306 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
307 myActionsMap[ ResetId ] = aAction;
309 // onViewTrihedron: Shows - Hides Trihedron
310 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
311 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
312 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
313 connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
314 myActionsMap[ ViewTrihedronId ] = aAction;
317 //----------------------------------------------------------------------------
322 myActionsMap[DumpId]->addTo(myToolBar);
323 myActionsMap[ViewTrihedronId]->addTo(myToolBar);
325 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
326 aScaleBtn->AddAction(myActionsMap[FitAllId]);
327 aScaleBtn->AddAction(myActionsMap[FitRectId]);
328 aScaleBtn->AddAction(myActionsMap[ZoomId]);
330 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
331 aPanningBtn->AddAction(myActionsMap[PanId]);
332 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
334 myActionsMap[RotationId]->addTo(myToolBar);
336 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
337 aViewsBtn->AddAction(myActionsMap[FrontId]);
338 aViewsBtn->AddAction(myActionsMap[BackId]);
339 aViewsBtn->AddAction(myActionsMap[TopId]);
340 aViewsBtn->AddAction(myActionsMap[BottomId]);
341 aViewsBtn->AddAction(myActionsMap[LeftId]);
342 aViewsBtn->AddAction(myActionsMap[RightId]);
344 myActionsMap[ResetId]->addTo(myToolBar);
347 //----------------------------------------------------------------------------
352 vtkCamera* camera = myRenderer->GetActiveCamera();
353 camera->SetPosition(1,0,0);
354 camera->SetViewUp(0,0,1);
355 camera->SetFocalPoint(0,0,0);
359 //----------------------------------------------------------------------------
364 vtkCamera* camera = myRenderer->GetActiveCamera();
365 camera->SetPosition(-1,0,0);
366 camera->SetViewUp(0,0,1);
367 camera->SetFocalPoint(0,0,0);
371 //----------------------------------------------------------------------------
376 vtkCamera* camera = myRenderer->GetActiveCamera();
377 camera->SetPosition(0,0,1);
378 camera->SetViewUp(0,1,0);
379 camera->SetFocalPoint(0,0,0);
383 //----------------------------------------------------------------------------
388 vtkCamera* camera = myRenderer->GetActiveCamera();
389 camera->SetPosition(0,0,-1);
390 camera->SetViewUp(0,1,0);
391 camera->SetFocalPoint(0,0,0);
395 //----------------------------------------------------------------------------
400 vtkCamera* camera = myRenderer->GetActiveCamera();
401 camera->SetPosition(0,-1,0);
402 camera->SetViewUp(0,0,1);
403 camera->SetFocalPoint(0,0,0);
407 //----------------------------------------------------------------------------
412 vtkCamera* camera = myRenderer->GetActiveCamera();
413 camera->SetPosition(0,1,0);
414 camera->SetViewUp(0,0,1);
415 camera->SetFocalPoint(0,0,0);
419 //----------------------------------------------------------------------------
424 int aTrihedronIsVisible = isTrihedronDisplayed();
425 int aCubeAxesIsVisible = isCubeAxesDisplayed();
427 myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
428 myCubeAxes->SetVisibility(0);
430 ::ResetCamera(myRenderer,true);
431 vtkCamera* aCamera = myRenderer->GetActiveCamera();
432 aCamera->SetPosition(1,-1,1);
433 aCamera->SetViewUp(0,0,1);
434 ::ResetCamera(myRenderer,true);
436 if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
437 else myTrihedron->VisibilityOff();
439 if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
440 else myCubeAxes->VisibilityOff();
442 static float aCoeff = 3.0;
443 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
447 //----------------------------------------------------------------------------
452 int aTrihedronWasVisible = false;
453 int aCubeAxesWasVisible = false;
455 aTrihedronWasVisible = isTrihedronDisplayed();
456 if (aTrihedronWasVisible)
457 myTrihedron->VisibilityOff();
461 aCubeAxesWasVisible = isCubeAxesDisplayed();
462 if (aCubeAxesWasVisible)
463 myCubeAxes->VisibilityOff();
466 if (myTrihedron->GetVisibleActorCount(myRenderer)) {
467 myTrihedron->VisibilityOff();
468 myCubeAxes->VisibilityOff();
469 ::ResetCamera(myRenderer);
471 myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
472 myCubeAxes->SetVisibility(2);
473 ::ResetCamera(myRenderer,true);
476 if (aTrihedronWasVisible)
477 myTrihedron->VisibilityOn();
479 myTrihedron->VisibilityOff();
481 if (aCubeAxesWasVisible)
482 myCubeAxes->VisibilityOn();
484 myCubeAxes->VisibilityOff();
486 ::ResetCameraClippingRange(myRenderer);
491 //----------------------------------------------------------------
494 ::onSelectionChanged()
498 const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
499 SALOME_ListIteratorOfListIO anIter(aListIO);
500 for(; anIter.More(); anIter.Next()){
501 highlight(anIter.Value(),true,!anIter.More());
504 emit selectionChanged();
507 //----------------------------------------------------------------
510 ::SetSelectionMode(Selection_Mode theMode)
512 mySelector->SetSelectionMode(theMode);
513 myRWInteractor->SetSelectionMode(theMode);
516 //----------------------------------------------------------------
519 ::SelectionMode() const
521 return mySelector->SelectionMode();
524 //----------------------------------------------------------------
529 myRWInteractor->unHighlightAll();
532 //----------------------------------------------------------------
535 ::highlight( const Handle(SALOME_InteractiveObject)& theIO,
539 myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
541 if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
542 TColStd_IndexedMapOfInteger aMapIndex;
543 mySelector->GetIndex(theIO,aMapIndex);
545 const char* anEntry = theIO->getEntry();
546 vtkActorCollection* aCollection = myRenderer->GetActors();
547 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
548 switch (mySelector->SelectionMode()) {
550 myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
552 case EdgeOfCellSelection:
553 myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
558 case VolumeSelection:
559 myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
564 myRWInteractor->unHighlightSubSelection();
568 //----------------------------------------------------------------
571 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
573 return myRWInteractor->isInViewer( theIO );
576 //----------------------------------------------------------------
579 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
581 return myRWInteractor->isVisible( theIO );
584 //----------------------------------------------------------------------------
587 ::setBackgroundColor( const QColor& color )
590 myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
593 //----------------------------------------------------------------------------
596 ::backgroundColor() const
600 myRenderer->GetBackground( backint );
601 return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
603 return SUIT_ViewWindow::backgroundColor();
606 //----------------------------------------------------------------------------
609 ::Repaint(bool theUpdateTrihedron)
611 if (theUpdateTrihedron)
613 myRenderWindow->update();
616 //----------------------------------------------------------------------------
619 ::GetScale( double theScale[3] )
621 myTransform->GetMatrixScale( theScale );
624 //----------------------------------------------------------------------------
627 ::SetScale( double theScale[3] )
629 myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
630 myRWInteractor->Render();
634 //----------------------------------------------------------------------------
637 ::isTrihedronDisplayed()
639 return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
644 ::isCubeAxesDisplayed()
646 return myCubeAxes->GetVisibility() == 1;
649 //----------------------------------------------------------------------------
657 if(isTrihedronDisplayed())
658 myTrihedron->VisibilityOff();
660 myTrihedron->VisibilityOn();
672 if(isCubeAxesDisplayed())
673 myCubeAxes->VisibilityOff();
675 myCubeAxes->VisibilityOn();
680 //----------------------------------------------------------------------------
683 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
685 // calculating diagonal of visible props of the renderer
687 myTrihedron->VisibilityOff();
689 if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
690 aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
691 aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
694 myTrihedron->VisibilityOn();
696 static bool aCalcByDiag = false;
698 aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
699 ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
700 ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
702 aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
703 aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
704 aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
707 float aSizeInPercents = myTrihedronSize;
709 static float EPS_SIZE = 5.0E-3;
710 theSize = myTrihedron->GetSize();
711 theNewSize = aLength * aSizeInPercents / 100.0;
713 // if the new trihedron size have sufficient difference, then apply the value
714 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
715 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
718 //----------------------------------------------------------------------------
719 int SVTK_ViewWindow::GetTrihedronSize() const
721 return myTrihedronSize;
724 void SVTK_ViewWindow::SetTrihedronSize( const int sz )
726 if ( myTrihedronSize == sz )
729 myTrihedronSize = sz;
730 AdjustTrihedrons( true );
733 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
734 * trihedron and cube axes, even if trihedron and cube axes is invisible.
738 ::AdjustTrihedrons(const bool theIsForcedUpdate)
740 if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
745 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
746 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
748 myCubeAxes->GetBounds(bnd);
750 int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
751 //if (aVisibleNum || theIsForcedUpdate) {
753 // if the new trihedron size have sufficient difference, then apply the value
754 double aNewSize = 100, anOldSize=myTrihedron->GetSize();
755 bool aTDisplayed = isTrihedronDisplayed();
756 bool aCDisplayed = isCubeAxesDisplayed();
757 if(aTDisplayed) myTrihedron->VisibilityOff();
758 if(aCDisplayed) myCubeAxes->VisibilityOff();
760 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
761 QString aSetting = aResMgr->stringValue("Viewer", "TrihedronSize", "105");
762 static float aSizeInPercents = aSetting.toFloat();
764 //bool isComputeTrihedronSize =
765 ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents);
767 myTrihedron->SetSize( aNewSize );
769 // iterate through displayed objects and set size if necessary
770 vtkActorCollection* anActors = getRenderer()->GetActors();
771 anActors->InitTraversal();
772 while (vtkActor* anActor = anActors->GetNextActor())
774 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ))
776 if (aSActor->IsResizable())
777 aSActor->SetSize( 0.5 * aNewSize );
778 if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) {
779 float *abounds = aSActor->GetBounds();
780 if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
781 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
782 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
783 for (int i = 0; i < 5; i = i + 2) {
784 if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i];
785 if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1];
790 if (aTDisplayed) myTrihedron->VisibilityOn();
791 if (aCDisplayed) myCubeAxes->VisibilityOn();
794 double aSize = myTrihedron->GetSize();
795 newbnd[0] = newbnd[2] = newbnd[4] = 0;
796 newbnd[1] = newbnd[3] = newbnd[5] = aSize;
799 if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT &&
800 newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) {
801 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
802 myCubeAxes->SetBounds(bnd);
805 myCubeAxes->SetBounds(bnd);
807 ::ResetCameraClippingRange(myRenderer);
810 //----------------------------------------------------------------------------
813 ::onAdjustTrihedron()
815 AdjustTrihedrons( false );
822 AdjustTrihedrons(false);
825 #define INCREMENT_FOR_OP 10
827 //=======================================================================
829 // Purpose : Performs incremental panning to the left
830 //=======================================================================
835 myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
838 //=======================================================================
840 // Purpose : Performs incremental panning to the right
841 //=======================================================================
846 myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
849 //=======================================================================
851 // Purpose : Performs incremental panning to the top
852 //=======================================================================
857 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
860 //=======================================================================
862 // Purpose : Performs incremental panning to the bottom
863 //=======================================================================
868 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
871 //=======================================================================
873 // Purpose : Performs incremental zooming in
874 //=======================================================================
879 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
882 //=======================================================================
884 // Purpose : Performs incremental zooming out
885 //=======================================================================
890 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
893 //=======================================================================
894 // name : onRotateLeft
895 // Purpose : Performs incremental rotating to the left
896 //=======================================================================
901 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
904 //=======================================================================
905 // name : onRotateRight
906 // Purpose : Performs incremental rotating to the right
907 //=======================================================================
912 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
915 //=======================================================================
917 // Purpose : Performs incremental rotating to the top
918 //=======================================================================
923 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
926 //=======================================================================
929 ::onKeyPressed(QKeyEvent* event)
931 emit keyPressed( this, event );
934 //=======================================================================
937 ::onKeyReleased(QKeyEvent* event)
939 emit keyReleased( this, event );
942 //=======================================================================
945 ::onMousePressed(QMouseEvent* event)
947 emit mousePressed(this, event);
950 //=======================================================================
953 ::onMouseReleased(QMouseEvent* event)
955 emit mouseReleased( this, event );
958 //=======================================================================
961 ::onMouseMoving(QMouseEvent* event)
963 emit mouseMoving( this, event );
966 //=======================================================================
969 ::onMouseDoubleClicked( QMouseEvent* event )
971 emit mouseDoubleClicked( this, event );
974 //=======================================================================
975 // name : onRotateDown
976 // Purpose : Performs incremental rotating to the bottom
977 //=======================================================================
982 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
985 //----------------------------------------------------------------------------
988 ::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
990 theActor->AddToRender(myRenderer);
991 theActor->SetTransform(myTransform);
992 if(theMoveInternalActors)
993 myRWInteractor->MoveInternalActors();
996 //----------------------------------------------------------------------------
999 ::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1001 InsertActor(theActor);
1006 //----------------------------------------------------------------------------
1009 ::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1011 theActor->RemoveFromRender(myRenderer);
1016 //----------------------------------------------------------------------------
1019 ::MoveActor( SALOME_Actor* theActor)
1021 RemoveActor(theActor);
1022 InsertActor(theActor,true);
1025 //----------------------------------------------------------------------------
1030 QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
1031 return px.convertToImage();