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"
16 #include "SUIT_Accel.h"
18 #include "SUIT_Tools.h"
19 #include "SUIT_ResourceMgr.h"
21 #include "VTKViewer_Transform.h"
22 #include "VTKViewer_Utilities.h"
24 #include "SVTK_Trihedron.h"
25 #include "SVTK_CubeAxesActor2D.h"
26 #include "SVTK_ViewWindow.h"
27 #include "SVTK_ViewModel.h"
28 #include "SVTK_RenderWindow.h"
29 #include "SVTK_RenderWindowInteractor.h"
30 #include "SVTK_InteractorStyle.h"
32 #include "SALOME_ListIteratorOfListIO.hxx"
34 #include "SVTK_SelectorDef.h"
36 #include "VTKViewer_Algorithm.h"
37 #include "SVTK_Functor.h"
39 //----------------------------------------------------------------------------
41 ::SVTK_ViewWindow( SUIT_Desktop* theDesktop,
42 SVTK_Viewer* theModel)
43 : SUIT_ViewWindow( theDesktop ),
44 myTrihedronSize( 100 )
47 mySelector = new SVTK_SelectorDef();
48 connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
50 myTransform = VTKViewer_Transform::New();
51 myTrihedron = SVTK_Trihedron::New();
52 myCubeAxes = SVTK_CubeAxesActor2D::New();
53 myRenderer = vtkRenderer::New() ;
55 myTrihedron->AddToRender( myRenderer );
56 myRenderer->AddProp(myCubeAxes);
58 myRenderWindow = new SVTK_RenderWindow( this, "RenderWindow" );
59 setCentralWidget(myRenderWindow);
60 myRenderWindow->setFocusPolicy( StrongFocus );
61 myRenderWindow->setFocus();
63 myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
65 myRenderer->GetActiveCamera()->ParallelProjectionOn();
66 myRenderer->LightFollowCameraOn();
67 myRenderer->TwoSidedLightingOn();
69 // Set BackgroundColor
70 QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
71 QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
72 QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
74 if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
75 myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
77 myRenderer->SetBackground( 0, 0, 0 );
79 // Create an interactor.
80 myRWInteractor = SVTK_RenderWindowInteractor::New();
81 myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
82 myRWInteractor->setViewWindow( this );
84 SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New();
85 RWS->setGUIWindow( myRenderWindow );
86 RWS->setViewWindow( this );
88 myRWInteractor->SetInteractorStyle( RWS );
89 myRWInteractor->Initialize();
91 //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron );
92 RWS->FindPokedRenderer( 0, 0 );
94 SetSelectionMode(ActorSelection);
96 vtkTextProperty* tprop = vtkTextProperty::New();
97 tprop->SetColor(1, 1, 1);
101 bnd[0] = bnd[2] = bnd[4] = 0;
102 bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize();
103 myCubeAxes->SetLabelFormat("%6.4g");
104 myCubeAxes->SetBounds(bnd);
105 myCubeAxes->SetCamera(myRenderer->GetActiveCamera());
106 myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
107 myCubeAxes->SetFontFactor(0.8);
108 myCubeAxes->SetAxisTitleTextProperty(tprop);
109 myCubeAxes->SetAxisLabelTextProperty(tprop);
110 myCubeAxes->SetCornerOffset(0);
111 myCubeAxes->SetScaling(0);
112 myCubeAxes->SetNumberOfLabels(5);
113 myCubeAxes->VisibilityOff();
114 myCubeAxes->SetTransform(myTransform);
117 setCentralWidget( myRenderWindow );
119 myToolBar = new QToolBar(this);
120 myToolBar->setCloseMode(QDockWindow::Undocked);
121 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
126 connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
127 this, SLOT(onKeyPressed( QKeyEvent* )) );
128 connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
129 this, SLOT(onKeyReleased( QKeyEvent* )) );
130 connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
131 this, SLOT(onMousePressed( QMouseEvent* )) );
132 connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
133 this, SLOT(onMouseReleased( QMouseEvent* )) );
134 connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
135 this, SLOT(onMouseDoubleClicked( QMouseEvent* )) );
136 connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
137 this, SLOT(onMouseMoving( QMouseEvent* )) );
139 connect( myRWInteractor, SIGNAL(RenderWindowModified()),
140 myRenderWindow, SLOT(update()) );
141 connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
142 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
147 //----------------------------------------------------------------------------
151 myTransform->Delete();
152 // In order to ensure that the interactor unregisters
153 // this RenderWindow, we assign a NULL RenderWindow to
154 // it before deleting it.
155 myRWInteractor->SetRenderWindow( NULL );
156 myRWInteractor->Delete();
159 myRenderer->RemoveAllProps();
160 //m_Renderer->Delete();
161 myTrihedron->Delete();
162 myCubeAxes->Delete();
165 //----------------------------------------------------------------------------
170 myRWInteractor->GetSInteractorStyle()->startZoom();
173 //----------------------------------------------------------------------------
178 myRWInteractor->GetSInteractorStyle()->startPan();
181 //----------------------------------------------------------------------------
186 myRWInteractor->GetSInteractorStyle()->startRotate();
189 //----------------------------------------------------------------------------
192 ::activateGlobalPanning()
194 if(myTrihedron->GetVisibleActorCount(myRenderer))
195 myRWInteractor->GetSInteractorStyle()->startGlobalPan();
198 //----------------------------------------------------------------------------
201 ::activateWindowFit()
203 myRWInteractor->GetSInteractorStyle()->startFitArea();
206 //----------------------------------------------------------------------------
207 #if defined(WIN32) && !defined(_DEBUG)
208 #pragma optimize( "", off )
214 if (!myActionsMap.isEmpty()) return;
216 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
221 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
222 tr( "MNU_DUMP_VIEW" ), 0, this);
223 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
224 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
225 myActionsMap[ DumpId ] = aAction;
228 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
229 tr( "MNU_FITALL" ), 0, this);
230 aAction->setStatusTip(tr("DSC_FITALL"));
231 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
232 myActionsMap[ FitAllId ] = aAction;
235 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
236 tr( "MNU_FITRECT" ), 0, this);
237 aAction->setStatusTip(tr("DSC_FITRECT"));
238 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
239 myActionsMap[ FitRectId ] = aAction;
242 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
243 tr( "MNU_ZOOM_VIEW" ), 0, this);
244 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
245 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
246 myActionsMap[ ZoomId ] = aAction;
249 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
250 tr( "MNU_PAN_VIEW" ), 0, this);
251 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
252 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
253 myActionsMap[ PanId ] = aAction;
256 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
257 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
258 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
259 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
260 myActionsMap[ GlobalPanId ] = aAction;
263 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
264 tr( "MNU_ROTATE_VIEW" ), 0, this);
265 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
266 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
267 myActionsMap[ RotationId ] = aAction;
270 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
271 tr( "MNU_FRONT_VIEW" ), 0, this);
272 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
273 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
274 myActionsMap[ FrontId ] = aAction;
276 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
277 tr( "MNU_BACK_VIEW" ), 0, this);
278 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
279 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
280 myActionsMap[ BackId ] = aAction;
282 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
283 tr( "MNU_TOP_VIEW" ), 0, this);
284 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
285 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
286 myActionsMap[ TopId ] = aAction;
288 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
289 tr( "MNU_BOTTOM_VIEW" ), 0, this);
290 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
291 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
292 myActionsMap[ BottomId ] = aAction;
294 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
295 tr( "MNU_LEFT_VIEW" ), 0, this);
296 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
297 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
298 myActionsMap[ LeftId ] = aAction;
300 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
301 tr( "MNU_RIGHT_VIEW" ), 0, this);
302 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
303 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
304 myActionsMap[ RightId ] = aAction;
307 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
308 tr( "MNU_RESET_VIEW" ), 0, this);
309 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
310 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
311 myActionsMap[ ResetId ] = aAction;
313 // onViewTrihedron: Shows - Hides Trihedron
314 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
315 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
316 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
317 connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
318 myActionsMap[ ViewTrihedronId ] = aAction;
320 #if defined(WIN32) && !defined(_DEBUG)
321 #pragma optimize( "", on )
324 //----------------------------------------------------------------------------
329 myActionsMap[DumpId]->addTo(myToolBar);
330 myActionsMap[ViewTrihedronId]->addTo(myToolBar);
332 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
333 aScaleBtn->AddAction(myActionsMap[FitAllId]);
334 aScaleBtn->AddAction(myActionsMap[FitRectId]);
335 aScaleBtn->AddAction(myActionsMap[ZoomId]);
337 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
338 aPanningBtn->AddAction(myActionsMap[PanId]);
339 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
341 myActionsMap[RotationId]->addTo(myToolBar);
343 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
344 aViewsBtn->AddAction(myActionsMap[FrontId]);
345 aViewsBtn->AddAction(myActionsMap[BackId]);
346 aViewsBtn->AddAction(myActionsMap[TopId]);
347 aViewsBtn->AddAction(myActionsMap[BottomId]);
348 aViewsBtn->AddAction(myActionsMap[LeftId]);
349 aViewsBtn->AddAction(myActionsMap[RightId]);
351 myActionsMap[ResetId]->addTo(myToolBar);
354 //----------------------------------------------------------------------------
359 vtkCamera* camera = myRenderer->GetActiveCamera();
360 camera->SetPosition(1,0,0);
361 camera->SetViewUp(0,0,1);
362 camera->SetFocalPoint(0,0,0);
366 //----------------------------------------------------------------------------
371 vtkCamera* camera = myRenderer->GetActiveCamera();
372 camera->SetPosition(-1,0,0);
373 camera->SetViewUp(0,0,1);
374 camera->SetFocalPoint(0,0,0);
378 //----------------------------------------------------------------------------
383 vtkCamera* camera = myRenderer->GetActiveCamera();
384 camera->SetPosition(0,0,1);
385 camera->SetViewUp(0,1,0);
386 camera->SetFocalPoint(0,0,0);
390 //----------------------------------------------------------------------------
395 vtkCamera* camera = myRenderer->GetActiveCamera();
396 camera->SetPosition(0,0,-1);
397 camera->SetViewUp(0,1,0);
398 camera->SetFocalPoint(0,0,0);
402 //----------------------------------------------------------------------------
407 vtkCamera* camera = myRenderer->GetActiveCamera();
408 camera->SetPosition(0,-1,0);
409 camera->SetViewUp(0,0,1);
410 camera->SetFocalPoint(0,0,0);
414 //----------------------------------------------------------------------------
419 vtkCamera* camera = myRenderer->GetActiveCamera();
420 camera->SetPosition(0,1,0);
421 camera->SetViewUp(0,0,1);
422 camera->SetFocalPoint(0,0,0);
426 //----------------------------------------------------------------------------
431 int aTrihedronIsVisible = isTrihedronDisplayed();
432 int aCubeAxesIsVisible = isCubeAxesDisplayed();
434 myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
435 myCubeAxes->SetVisibility(0);
437 ::ResetCamera(myRenderer,true);
438 vtkCamera* aCamera = myRenderer->GetActiveCamera();
439 aCamera->SetPosition(1,-1,1);
440 aCamera->SetViewUp(0,0,1);
441 ::ResetCamera(myRenderer,true);
443 if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
444 else myTrihedron->VisibilityOff();
446 if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
447 else myCubeAxes->VisibilityOff();
449 static float aCoeff = 3.0;
450 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
454 //----------------------------------------------------------------------------
459 int aTrihedronWasVisible = false;
460 int aCubeAxesWasVisible = false;
462 aTrihedronWasVisible = isTrihedronDisplayed();
463 if (aTrihedronWasVisible)
464 myTrihedron->VisibilityOff();
468 aCubeAxesWasVisible = isCubeAxesDisplayed();
469 if (aCubeAxesWasVisible)
470 myCubeAxes->VisibilityOff();
473 if (myTrihedron->GetVisibleActorCount(myRenderer)) {
474 myTrihedron->VisibilityOff();
475 myCubeAxes->VisibilityOff();
476 ::ResetCamera(myRenderer);
478 myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
479 myCubeAxes->SetVisibility(2);
480 ::ResetCamera(myRenderer,true);
483 if (aTrihedronWasVisible)
484 myTrihedron->VisibilityOn();
486 myTrihedron->VisibilityOff();
488 if (aCubeAxesWasVisible)
489 myCubeAxes->VisibilityOn();
491 myCubeAxes->VisibilityOff();
493 ::ResetCameraClippingRange(myRenderer);
498 //----------------------------------------------------------------
501 ::onSelectionChanged()
505 const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
506 SALOME_ListIteratorOfListIO anIter(aListIO);
507 for(; anIter.More(); anIter.Next()){
508 highlight(anIter.Value(),true,!anIter.More());
511 emit selectionChanged();
514 //----------------------------------------------------------------
517 ::SetSelectionMode(Selection_Mode theMode)
519 mySelector->SetSelectionMode(theMode);
520 myRWInteractor->SetSelectionMode(theMode);
523 //----------------------------------------------------------------
526 ::SelectionMode() const
528 return mySelector->SelectionMode();
531 //----------------------------------------------------------------
536 myRWInteractor->unHighlightAll();
539 //----------------------------------------------------------------
542 ::highlight( const Handle(SALOME_InteractiveObject)& theIO,
546 myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
548 if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
549 TColStd_IndexedMapOfInteger aMapIndex;
550 mySelector->GetIndex(theIO,aMapIndex);
552 const char* anEntry = theIO->getEntry();
553 vtkActorCollection* aCollection = myRenderer->GetActors();
554 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
555 switch (mySelector->SelectionMode()) {
557 myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
559 case EdgeOfCellSelection:
560 myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
565 case VolumeSelection:
566 myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
571 myRWInteractor->unHighlightSubSelection();
575 //----------------------------------------------------------------
578 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
580 return myRWInteractor->isInViewer( theIO );
583 //----------------------------------------------------------------
586 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
588 return myRWInteractor->isVisible( theIO );
591 //----------------------------------------------------------------------------
594 ::setBackgroundColor( const QColor& color )
597 myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
600 //----------------------------------------------------------------------------
603 ::backgroundColor() const
607 myRenderer->GetBackground( backint );
608 return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
610 return SUIT_ViewWindow::backgroundColor();
613 //----------------------------------------------------------------------------
616 ::Repaint(bool theUpdateTrihedron)
618 if (theUpdateTrihedron)
620 myRenderWindow->update();
623 //----------------------------------------------------------------------------
626 ::GetScale( double theScale[3] )
628 myTransform->GetMatrixScale( theScale );
631 //----------------------------------------------------------------------------
634 ::SetScale( double theScale[3] )
636 myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
637 myRWInteractor->Render();
641 //----------------------------------------------------------------------------
644 ::isTrihedronDisplayed()
646 return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
651 ::isCubeAxesDisplayed()
653 return myCubeAxes->GetVisibility() == 1;
656 //----------------------------------------------------------------------------
664 if(isTrihedronDisplayed())
665 myTrihedron->VisibilityOff();
667 myTrihedron->VisibilityOn();
679 if(isCubeAxesDisplayed())
680 myCubeAxes->VisibilityOff();
682 myCubeAxes->VisibilityOn();
687 //----------------------------------------------------------------------------
690 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
692 // calculating diagonal of visible props of the renderer
694 myTrihedron->VisibilityOff();
696 if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
697 aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
698 aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
701 myTrihedron->VisibilityOn();
703 static bool aCalcByDiag = false;
705 aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
706 ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
707 ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
709 aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
710 aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
711 aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
714 float aSizeInPercents = myTrihedronSize;
716 static float EPS_SIZE = 5.0E-3;
717 theSize = myTrihedron->GetSize();
718 theNewSize = aLength * aSizeInPercents / 100.0;
720 // if the new trihedron size have sufficient difference, then apply the value
721 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
722 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
725 //----------------------------------------------------------------------------
726 int SVTK_ViewWindow::GetTrihedronSize() const
728 return myTrihedronSize;
731 void SVTK_ViewWindow::SetTrihedronSize( const int sz )
733 if ( myTrihedronSize == sz )
736 myTrihedronSize = sz;
737 AdjustTrihedrons( true );
740 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
741 * trihedron and cube axes, even if trihedron and cube axes is invisible.
745 ::AdjustTrihedrons(const bool theIsForcedUpdate)
747 if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
752 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
753 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
755 myCubeAxes->GetBounds(bnd);
757 int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
758 //if (aVisibleNum || theIsForcedUpdate) {
760 // if the new trihedron size have sufficient difference, then apply the value
761 double aNewSize = 100, anOldSize=myTrihedron->GetSize();
762 bool aTDisplayed = isTrihedronDisplayed();
763 bool aCDisplayed = isCubeAxesDisplayed();
764 if(aTDisplayed) myTrihedron->VisibilityOff();
765 if(aCDisplayed) myCubeAxes->VisibilityOff();
767 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
768 QString aSetting = aResMgr->stringValue("Viewer", "TrihedronSize", "105");
769 static float aSizeInPercents = aSetting.toFloat();
771 //bool isComputeTrihedronSize =
772 ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents);
774 myTrihedron->SetSize( aNewSize );
776 // iterate through displayed objects and set size if necessary
777 vtkActorCollection* anActors = getRenderer()->GetActors();
778 anActors->InitTraversal();
779 while (vtkActor* anActor = anActors->GetNextActor())
781 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ))
783 if (aSActor->IsResizable())
784 aSActor->SetSize( 0.5 * aNewSize );
785 if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) {
786 float *abounds = aSActor->GetBounds();
787 if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
788 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
789 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
790 for (int i = 0; i < 5; i = i + 2) {
791 if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i];
792 if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1];
797 if (aTDisplayed) myTrihedron->VisibilityOn();
798 if (aCDisplayed) myCubeAxes->VisibilityOn();
801 double aSize = myTrihedron->GetSize();
802 newbnd[0] = newbnd[2] = newbnd[4] = 0;
803 newbnd[1] = newbnd[3] = newbnd[5] = aSize;
806 if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT &&
807 newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) {
808 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
809 myCubeAxes->SetBounds(bnd);
812 myCubeAxes->SetBounds(bnd);
814 ::ResetCameraClippingRange(myRenderer);
817 //----------------------------------------------------------------------------
820 ::onAdjustTrihedron()
822 AdjustTrihedrons( false );
829 AdjustTrihedrons(false);
832 #define INCREMENT_FOR_OP 10
834 //=======================================================================
836 // Purpose : Performs incremental panning to the left
837 //=======================================================================
842 myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
845 //=======================================================================
847 // Purpose : Performs incremental panning to the right
848 //=======================================================================
853 myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
856 //=======================================================================
858 // Purpose : Performs incremental panning to the top
859 //=======================================================================
864 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
867 //=======================================================================
869 // Purpose : Performs incremental panning to the bottom
870 //=======================================================================
875 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
878 //=======================================================================
880 // Purpose : Performs incremental zooming in
881 //=======================================================================
886 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
889 //=======================================================================
891 // Purpose : Performs incremental zooming out
892 //=======================================================================
897 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
900 //=======================================================================
901 // name : onRotateLeft
902 // Purpose : Performs incremental rotating to the left
903 //=======================================================================
908 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
911 //=======================================================================
912 // name : onRotateRight
913 // Purpose : Performs incremental rotating to the right
914 //=======================================================================
919 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
922 //=======================================================================
924 // Purpose : Performs incremental rotating to the top
925 //=======================================================================
930 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
933 //=======================================================================
936 ::onKeyPressed(QKeyEvent* event)
938 emit keyPressed( this, event );
941 //=======================================================================
944 ::onKeyReleased(QKeyEvent* event)
946 emit keyReleased( this, event );
949 //=======================================================================
952 ::onMousePressed(QMouseEvent* event)
954 emit mousePressed(this, event);
957 //=======================================================================
960 ::onMouseReleased(QMouseEvent* event)
962 emit mouseReleased( this, event );
965 //=======================================================================
968 ::onMouseMoving(QMouseEvent* event)
970 emit mouseMoving( this, event );
973 //=======================================================================
976 ::onMouseDoubleClicked( QMouseEvent* event )
978 emit mouseDoubleClicked( this, event );
981 //=======================================================================
982 // name : onRotateDown
983 // Purpose : Performs incremental rotating to the bottom
984 //=======================================================================
989 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
992 //----------------------------------------------------------------------------
995 ::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
997 theActor->AddToRender(myRenderer);
998 theActor->SetTransform(myTransform);
999 if(theMoveInternalActors)
1000 myRWInteractor->MoveInternalActors();
1003 //----------------------------------------------------------------------------
1006 ::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1008 InsertActor(theActor);
1013 //----------------------------------------------------------------------------
1016 ::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1018 theActor->RemoveFromRender(myRenderer);
1023 //----------------------------------------------------------------------------
1026 ::MoveActor( SALOME_Actor* theActor)
1028 RemoveActor(theActor);
1029 InsertActor(theActor,true);
1032 //----------------------------------------------------------------------------
1037 QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
1038 return px.convertToImage();
1041 //----------------------------------------------------------------------------
1044 ::action( const int theAction )
1046 switch ( theAction ) {
1047 case SUIT_Accel::PanLeft : onPanLeft(); break;
1048 case SUIT_Accel::PanRight : onPanRight(); break;
1049 case SUIT_Accel::PanUp : onPanUp(); break;
1050 case SUIT_Accel::PanDown : onPanDown(); break;
1051 case SUIT_Accel::ZoomIn : onZoomIn(); break;
1052 case SUIT_Accel::ZoomOut : onZoomOut(); break;
1053 case SUIT_Accel::ZoomFit : onFitAll(); break;
1054 case SUIT_Accel::RotateLeft : onRotateLeft(); break;
1055 case SUIT_Accel::RotateRight : onRotateRight(); break;
1056 case SUIT_Accel::RotateUp : onRotateUp(); break;
1057 case SUIT_Accel::RotateDown : onRotateDown(); break;