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 //----------------------------------------------------------------------------
211 if (!myActionsMap.isEmpty()) return;
213 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
218 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
219 tr( "MNU_DUMP_VIEW" ), 0, this);
220 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
221 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
222 myActionsMap[ DumpId ] = aAction;
225 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
226 tr( "MNU_FITALL" ), 0, this);
227 aAction->setStatusTip(tr("DSC_FITALL"));
228 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
229 myActionsMap[ FitAllId ] = aAction;
232 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
233 tr( "MNU_FITRECT" ), 0, this);
234 aAction->setStatusTip(tr("DSC_FITRECT"));
235 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
236 myActionsMap[ FitRectId ] = aAction;
239 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
240 tr( "MNU_ZOOM_VIEW" ), 0, this);
241 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
242 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
243 myActionsMap[ ZoomId ] = aAction;
246 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
247 tr( "MNU_PAN_VIEW" ), 0, this);
248 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
249 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
250 myActionsMap[ PanId ] = aAction;
253 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
254 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
255 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
256 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
257 myActionsMap[ GlobalPanId ] = aAction;
260 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
261 tr( "MNU_ROTATE_VIEW" ), 0, this);
262 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
263 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
264 myActionsMap[ RotationId ] = aAction;
267 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
268 tr( "MNU_FRONT_VIEW" ), 0, this);
269 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
270 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
271 myActionsMap[ FrontId ] = aAction;
273 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
274 tr( "MNU_BACK_VIEW" ), 0, this);
275 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
276 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
277 myActionsMap[ BackId ] = aAction;
279 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
280 tr( "MNU_TOP_VIEW" ), 0, this);
281 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
282 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
283 myActionsMap[ TopId ] = aAction;
285 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
286 tr( "MNU_BOTTOM_VIEW" ), 0, this);
287 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
288 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
289 myActionsMap[ BottomId ] = aAction;
291 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
292 tr( "MNU_LEFT_VIEW" ), 0, this);
293 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
294 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
295 myActionsMap[ LeftId ] = aAction;
297 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
298 tr( "MNU_RIGHT_VIEW" ), 0, this);
299 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
300 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
301 myActionsMap[ RightId ] = aAction;
304 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
305 tr( "MNU_RESET_VIEW" ), 0, this);
306 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
307 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
308 myActionsMap[ ResetId ] = aAction;
310 // onViewTrihedron: Shows - Hides Trihedron
311 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
312 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
313 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
314 connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
315 myActionsMap[ ViewTrihedronId ] = aAction;
318 //----------------------------------------------------------------------------
323 myActionsMap[DumpId]->addTo(myToolBar);
324 myActionsMap[ViewTrihedronId]->addTo(myToolBar);
326 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
327 aScaleBtn->AddAction(myActionsMap[FitAllId]);
328 aScaleBtn->AddAction(myActionsMap[FitRectId]);
329 aScaleBtn->AddAction(myActionsMap[ZoomId]);
331 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
332 aPanningBtn->AddAction(myActionsMap[PanId]);
333 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
335 myActionsMap[RotationId]->addTo(myToolBar);
337 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
338 aViewsBtn->AddAction(myActionsMap[FrontId]);
339 aViewsBtn->AddAction(myActionsMap[BackId]);
340 aViewsBtn->AddAction(myActionsMap[TopId]);
341 aViewsBtn->AddAction(myActionsMap[BottomId]);
342 aViewsBtn->AddAction(myActionsMap[LeftId]);
343 aViewsBtn->AddAction(myActionsMap[RightId]);
345 myActionsMap[ResetId]->addTo(myToolBar);
348 //----------------------------------------------------------------------------
353 vtkCamera* camera = myRenderer->GetActiveCamera();
354 camera->SetPosition(1,0,0);
355 camera->SetViewUp(0,0,1);
356 camera->SetFocalPoint(0,0,0);
360 //----------------------------------------------------------------------------
365 vtkCamera* camera = myRenderer->GetActiveCamera();
366 camera->SetPosition(-1,0,0);
367 camera->SetViewUp(0,0,1);
368 camera->SetFocalPoint(0,0,0);
372 //----------------------------------------------------------------------------
377 vtkCamera* camera = myRenderer->GetActiveCamera();
378 camera->SetPosition(0,0,1);
379 camera->SetViewUp(0,1,0);
380 camera->SetFocalPoint(0,0,0);
384 //----------------------------------------------------------------------------
389 vtkCamera* camera = myRenderer->GetActiveCamera();
390 camera->SetPosition(0,0,-1);
391 camera->SetViewUp(0,1,0);
392 camera->SetFocalPoint(0,0,0);
396 //----------------------------------------------------------------------------
401 vtkCamera* camera = myRenderer->GetActiveCamera();
402 camera->SetPosition(0,-1,0);
403 camera->SetViewUp(0,0,1);
404 camera->SetFocalPoint(0,0,0);
408 //----------------------------------------------------------------------------
413 vtkCamera* camera = myRenderer->GetActiveCamera();
414 camera->SetPosition(0,1,0);
415 camera->SetViewUp(0,0,1);
416 camera->SetFocalPoint(0,0,0);
420 //----------------------------------------------------------------------------
425 int aTrihedronIsVisible = isTrihedronDisplayed();
426 int aCubeAxesIsVisible = isCubeAxesDisplayed();
428 myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
429 myCubeAxes->SetVisibility(0);
431 ::ResetCamera(myRenderer,true);
432 vtkCamera* aCamera = myRenderer->GetActiveCamera();
433 aCamera->SetPosition(1,-1,1);
434 aCamera->SetViewUp(0,0,1);
435 ::ResetCamera(myRenderer,true);
437 if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
438 else myTrihedron->VisibilityOff();
440 if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
441 else myCubeAxes->VisibilityOff();
443 static float aCoeff = 3.0;
444 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
448 //----------------------------------------------------------------------------
453 int aTrihedronWasVisible = false;
454 int aCubeAxesWasVisible = false;
456 aTrihedronWasVisible = isTrihedronDisplayed();
457 if (aTrihedronWasVisible)
458 myTrihedron->VisibilityOff();
462 aCubeAxesWasVisible = isCubeAxesDisplayed();
463 if (aCubeAxesWasVisible)
464 myCubeAxes->VisibilityOff();
467 if (myTrihedron->GetVisibleActorCount(myRenderer)) {
468 myTrihedron->VisibilityOff();
469 myCubeAxes->VisibilityOff();
470 ::ResetCamera(myRenderer);
472 myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
473 myCubeAxes->SetVisibility(2);
474 ::ResetCamera(myRenderer,true);
477 if (aTrihedronWasVisible)
478 myTrihedron->VisibilityOn();
480 myTrihedron->VisibilityOff();
482 if (aCubeAxesWasVisible)
483 myCubeAxes->VisibilityOn();
485 myCubeAxes->VisibilityOff();
487 ::ResetCameraClippingRange(myRenderer);
492 //----------------------------------------------------------------
495 ::onSelectionChanged()
499 const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
500 SALOME_ListIteratorOfListIO anIter(aListIO);
501 for(; anIter.More(); anIter.Next()){
502 highlight(anIter.Value(),true,!anIter.More());
505 emit selectionChanged();
508 //----------------------------------------------------------------
511 ::SetSelectionMode(Selection_Mode theMode)
513 mySelector->SetSelectionMode(theMode);
514 myRWInteractor->SetSelectionMode(theMode);
517 //----------------------------------------------------------------
520 ::SelectionMode() const
522 return mySelector->SelectionMode();
525 //----------------------------------------------------------------
530 myRWInteractor->unHighlightAll();
533 //----------------------------------------------------------------
536 ::highlight( const Handle(SALOME_InteractiveObject)& theIO,
540 myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
542 if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
543 TColStd_IndexedMapOfInteger aMapIndex;
544 mySelector->GetIndex(theIO,aMapIndex);
546 const char* anEntry = theIO->getEntry();
547 vtkActorCollection* aCollection = myRenderer->GetActors();
548 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
549 switch (mySelector->SelectionMode()) {
551 myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
553 case EdgeOfCellSelection:
554 myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
559 case VolumeSelection:
560 myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
565 myRWInteractor->unHighlightSubSelection();
569 //----------------------------------------------------------------
572 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
574 return myRWInteractor->isInViewer( theIO );
577 //----------------------------------------------------------------
580 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
582 return myRWInteractor->isVisible( theIO );
585 //----------------------------------------------------------------------------
588 ::setBackgroundColor( const QColor& color )
591 myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
594 //----------------------------------------------------------------------------
597 ::backgroundColor() const
601 myRenderer->GetBackground( backint );
602 return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
604 return SUIT_ViewWindow::backgroundColor();
607 //----------------------------------------------------------------------------
610 ::Repaint(bool theUpdateTrihedron)
612 if (theUpdateTrihedron)
614 myRenderWindow->update();
617 //----------------------------------------------------------------------------
620 ::GetScale( double theScale[3] )
622 myTransform->GetMatrixScale( theScale );
625 //----------------------------------------------------------------------------
628 ::SetScale( double theScale[3] )
630 myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
631 myRWInteractor->Render();
635 //----------------------------------------------------------------------------
638 ::isTrihedronDisplayed()
640 return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
645 ::isCubeAxesDisplayed()
647 return myCubeAxes->GetVisibility() == 1;
650 //----------------------------------------------------------------------------
658 if(isTrihedronDisplayed())
659 myTrihedron->VisibilityOff();
661 myTrihedron->VisibilityOn();
673 if(isCubeAxesDisplayed())
674 myCubeAxes->VisibilityOff();
676 myCubeAxes->VisibilityOn();
681 //----------------------------------------------------------------------------
684 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
686 // calculating diagonal of visible props of the renderer
688 myTrihedron->VisibilityOff();
690 if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
691 aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
692 aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
695 myTrihedron->VisibilityOn();
697 static bool aCalcByDiag = false;
699 aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
700 ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
701 ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
703 aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
704 aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
705 aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
708 float aSizeInPercents = myTrihedronSize;
710 static float EPS_SIZE = 5.0E-3;
711 theSize = myTrihedron->GetSize();
712 theNewSize = aLength * aSizeInPercents / 100.0;
714 // if the new trihedron size have sufficient difference, then apply the value
715 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
716 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
719 //----------------------------------------------------------------------------
720 int SVTK_ViewWindow::GetTrihedronSize() const
722 return myTrihedronSize;
725 void SVTK_ViewWindow::SetTrihedronSize( const int sz )
727 if ( myTrihedronSize == sz )
730 myTrihedronSize = sz;
731 AdjustTrihedrons( true );
734 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
735 * trihedron and cube axes, even if trihedron and cube axes is invisible.
739 ::AdjustTrihedrons(const bool theIsForcedUpdate)
741 if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
746 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
747 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
749 myCubeAxes->GetBounds(bnd);
751 int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
752 //if (aVisibleNum || theIsForcedUpdate) {
754 // if the new trihedron size have sufficient difference, then apply the value
755 double aNewSize = 100, anOldSize=myTrihedron->GetSize();
756 bool aTDisplayed = isTrihedronDisplayed();
757 bool aCDisplayed = isCubeAxesDisplayed();
758 if(aTDisplayed) myTrihedron->VisibilityOff();
759 if(aCDisplayed) myCubeAxes->VisibilityOff();
761 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
762 QString aSetting = aResMgr->stringValue("Viewer", "TrihedronSize", "105");
763 static float aSizeInPercents = aSetting.toFloat();
765 //bool isComputeTrihedronSize =
766 ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents);
768 myTrihedron->SetSize( aNewSize );
770 // iterate through displayed objects and set size if necessary
771 vtkActorCollection* anActors = getRenderer()->GetActors();
772 anActors->InitTraversal();
773 while (vtkActor* anActor = anActors->GetNextActor())
775 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ))
777 if (aSActor->IsResizable())
778 aSActor->SetSize( 0.5 * aNewSize );
779 if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) {
780 float *abounds = aSActor->GetBounds();
781 if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
782 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
783 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
784 for (int i = 0; i < 5; i = i + 2) {
785 if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i];
786 if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1];
791 if (aTDisplayed) myTrihedron->VisibilityOn();
792 if (aCDisplayed) myCubeAxes->VisibilityOn();
795 double aSize = myTrihedron->GetSize();
796 newbnd[0] = newbnd[2] = newbnd[4] = 0;
797 newbnd[1] = newbnd[3] = newbnd[5] = aSize;
800 if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT &&
801 newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) {
802 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
803 myCubeAxes->SetBounds(bnd);
806 myCubeAxes->SetBounds(bnd);
808 ::ResetCameraClippingRange(myRenderer);
811 //----------------------------------------------------------------------------
814 ::onAdjustTrihedron()
816 AdjustTrihedrons( false );
823 AdjustTrihedrons(false);
826 #define INCREMENT_FOR_OP 10
828 //=======================================================================
830 // Purpose : Performs incremental panning to the left
831 //=======================================================================
836 myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
839 //=======================================================================
841 // Purpose : Performs incremental panning to the right
842 //=======================================================================
847 myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
850 //=======================================================================
852 // Purpose : Performs incremental panning to the top
853 //=======================================================================
858 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
861 //=======================================================================
863 // Purpose : Performs incremental panning to the bottom
864 //=======================================================================
869 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
872 //=======================================================================
874 // Purpose : Performs incremental zooming in
875 //=======================================================================
880 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
883 //=======================================================================
885 // Purpose : Performs incremental zooming out
886 //=======================================================================
891 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
894 //=======================================================================
895 // name : onRotateLeft
896 // Purpose : Performs incremental rotating to the left
897 //=======================================================================
902 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
905 //=======================================================================
906 // name : onRotateRight
907 // Purpose : Performs incremental rotating to the right
908 //=======================================================================
913 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
916 //=======================================================================
918 // Purpose : Performs incremental rotating to the top
919 //=======================================================================
924 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
927 //=======================================================================
930 ::onKeyPressed(QKeyEvent* event)
932 emit keyPressed( this, event );
935 //=======================================================================
938 ::onKeyReleased(QKeyEvent* event)
940 emit keyReleased( this, event );
943 //=======================================================================
946 ::onMousePressed(QMouseEvent* event)
948 emit mousePressed(this, event);
951 //=======================================================================
954 ::onMouseReleased(QMouseEvent* event)
956 emit mouseReleased( this, event );
959 //=======================================================================
962 ::onMouseMoving(QMouseEvent* event)
964 emit mouseMoving( this, event );
967 //=======================================================================
970 ::onMouseDoubleClicked( QMouseEvent* event )
972 emit mouseDoubleClicked( this, event );
975 //=======================================================================
976 // name : onRotateDown
977 // Purpose : Performs incremental rotating to the bottom
978 //=======================================================================
983 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
986 //----------------------------------------------------------------------------
989 ::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
991 theActor->AddToRender(myRenderer);
992 theActor->SetTransform(myTransform);
993 if(theMoveInternalActors)
994 myRWInteractor->MoveInternalActors();
997 //----------------------------------------------------------------------------
1000 ::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1002 InsertActor(theActor);
1007 //----------------------------------------------------------------------------
1010 ::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1012 theActor->RemoveFromRender(myRenderer);
1017 //----------------------------------------------------------------------------
1020 ::MoveActor( SALOME_Actor* theActor)
1022 RemoveActor(theActor);
1023 InsertActor(theActor,true);
1026 //----------------------------------------------------------------------------
1031 QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
1032 return px.convertToImage();
1035 //----------------------------------------------------------------------------
1038 ::action( const int theAction )
1040 switch ( theAction ) {
1041 case SUIT_Accel::PanLeft : onPanLeft(); break;
1042 case SUIT_Accel::PanRight : onPanRight(); break;
1043 case SUIT_Accel::PanUp : onPanUp(); break;
1044 case SUIT_Accel::PanDown : onPanDown(); break;
1045 case SUIT_Accel::ZoomIn : onZoomIn(); break;
1046 case SUIT_Accel::ZoomOut : onZoomOut(); break;
1047 case SUIT_Accel::ZoomFit : onFitAll(); break;
1048 case SUIT_Accel::RotateLeft : onRotateLeft(); break;
1049 case SUIT_Accel::RotateRight : onRotateRight(); break;
1050 case SUIT_Accel::RotateUp : onRotateUp(); break;
1051 case SUIT_Accel::RotateDown : onRotateDown(); break;