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 //#pragma optimize( "", off )
212 if (!myActionsMap.isEmpty()) return;
214 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
219 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
220 tr( "MNU_DUMP_VIEW" ), 0, this);
221 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
222 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
223 myActionsMap[ DumpId ] = aAction;
226 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
227 tr( "MNU_FITALL" ), 0, this);
228 aAction->setStatusTip(tr("DSC_FITALL"));
229 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
230 myActionsMap[ FitAllId ] = aAction;
233 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
234 tr( "MNU_FITRECT" ), 0, this);
235 aAction->setStatusTip(tr("DSC_FITRECT"));
236 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
237 myActionsMap[ FitRectId ] = aAction;
240 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
241 tr( "MNU_ZOOM_VIEW" ), 0, this);
242 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
243 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
244 myActionsMap[ ZoomId ] = aAction;
247 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
248 tr( "MNU_PAN_VIEW" ), 0, this);
249 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
250 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
251 myActionsMap[ PanId ] = aAction;
254 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
255 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
256 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
257 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
258 myActionsMap[ GlobalPanId ] = aAction;
261 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
262 tr( "MNU_ROTATE_VIEW" ), 0, this);
263 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
264 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
265 myActionsMap[ RotationId ] = aAction;
268 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
269 tr( "MNU_FRONT_VIEW" ), 0, this);
270 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
271 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
272 myActionsMap[ FrontId ] = aAction;
274 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
275 tr( "MNU_BACK_VIEW" ), 0, this);
276 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
277 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
278 myActionsMap[ BackId ] = aAction;
280 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
281 tr( "MNU_TOP_VIEW" ), 0, this);
282 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
283 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
284 myActionsMap[ TopId ] = aAction;
286 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
287 tr( "MNU_BOTTOM_VIEW" ), 0, this);
288 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
289 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
290 myActionsMap[ BottomId ] = aAction;
292 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
293 tr( "MNU_LEFT_VIEW" ), 0, this);
294 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
295 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
296 myActionsMap[ LeftId ] = aAction;
298 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
299 tr( "MNU_RIGHT_VIEW" ), 0, this);
300 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
301 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
302 myActionsMap[ RightId ] = aAction;
305 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
306 tr( "MNU_RESET_VIEW" ), 0, this);
307 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
308 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
309 myActionsMap[ ResetId ] = aAction;
311 // onViewTrihedron: Shows - Hides Trihedron
312 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
313 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
314 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
315 connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
316 myActionsMap[ ViewTrihedronId ] = aAction;
318 #pragma optimize( "", on )
320 //----------------------------------------------------------------------------
325 myActionsMap[DumpId]->addTo(myToolBar);
326 myActionsMap[ViewTrihedronId]->addTo(myToolBar);
328 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
329 aScaleBtn->AddAction(myActionsMap[FitAllId]);
330 aScaleBtn->AddAction(myActionsMap[FitRectId]);
331 aScaleBtn->AddAction(myActionsMap[ZoomId]);
333 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
334 aPanningBtn->AddAction(myActionsMap[PanId]);
335 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
337 myActionsMap[RotationId]->addTo(myToolBar);
339 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
340 aViewsBtn->AddAction(myActionsMap[FrontId]);
341 aViewsBtn->AddAction(myActionsMap[BackId]);
342 aViewsBtn->AddAction(myActionsMap[TopId]);
343 aViewsBtn->AddAction(myActionsMap[BottomId]);
344 aViewsBtn->AddAction(myActionsMap[LeftId]);
345 aViewsBtn->AddAction(myActionsMap[RightId]);
347 myActionsMap[ResetId]->addTo(myToolBar);
350 //----------------------------------------------------------------------------
355 vtkCamera* camera = myRenderer->GetActiveCamera();
356 camera->SetPosition(1,0,0);
357 camera->SetViewUp(0,0,1);
358 camera->SetFocalPoint(0,0,0);
362 //----------------------------------------------------------------------------
367 vtkCamera* camera = myRenderer->GetActiveCamera();
368 camera->SetPosition(-1,0,0);
369 camera->SetViewUp(0,0,1);
370 camera->SetFocalPoint(0,0,0);
374 //----------------------------------------------------------------------------
379 vtkCamera* camera = myRenderer->GetActiveCamera();
380 camera->SetPosition(0,0,1);
381 camera->SetViewUp(0,1,0);
382 camera->SetFocalPoint(0,0,0);
386 //----------------------------------------------------------------------------
391 vtkCamera* camera = myRenderer->GetActiveCamera();
392 camera->SetPosition(0,0,-1);
393 camera->SetViewUp(0,1,0);
394 camera->SetFocalPoint(0,0,0);
398 //----------------------------------------------------------------------------
403 vtkCamera* camera = myRenderer->GetActiveCamera();
404 camera->SetPosition(0,-1,0);
405 camera->SetViewUp(0,0,1);
406 camera->SetFocalPoint(0,0,0);
410 //----------------------------------------------------------------------------
415 vtkCamera* camera = myRenderer->GetActiveCamera();
416 camera->SetPosition(0,1,0);
417 camera->SetViewUp(0,0,1);
418 camera->SetFocalPoint(0,0,0);
422 //----------------------------------------------------------------------------
427 int aTrihedronIsVisible = isTrihedronDisplayed();
428 int aCubeAxesIsVisible = isCubeAxesDisplayed();
430 myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
431 myCubeAxes->SetVisibility(0);
433 ::ResetCamera(myRenderer,true);
434 vtkCamera* aCamera = myRenderer->GetActiveCamera();
435 aCamera->SetPosition(1,-1,1);
436 aCamera->SetViewUp(0,0,1);
437 ::ResetCamera(myRenderer,true);
439 if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
440 else myTrihedron->VisibilityOff();
442 if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
443 else myCubeAxes->VisibilityOff();
445 static float aCoeff = 3.0;
446 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
450 //----------------------------------------------------------------------------
455 int aTrihedronWasVisible = false;
456 int aCubeAxesWasVisible = false;
458 aTrihedronWasVisible = isTrihedronDisplayed();
459 if (aTrihedronWasVisible)
460 myTrihedron->VisibilityOff();
464 aCubeAxesWasVisible = isCubeAxesDisplayed();
465 if (aCubeAxesWasVisible)
466 myCubeAxes->VisibilityOff();
469 if (myTrihedron->GetVisibleActorCount(myRenderer)) {
470 myTrihedron->VisibilityOff();
471 myCubeAxes->VisibilityOff();
472 ::ResetCamera(myRenderer);
474 myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
475 myCubeAxes->SetVisibility(2);
476 ::ResetCamera(myRenderer,true);
479 if (aTrihedronWasVisible)
480 myTrihedron->VisibilityOn();
482 myTrihedron->VisibilityOff();
484 if (aCubeAxesWasVisible)
485 myCubeAxes->VisibilityOn();
487 myCubeAxes->VisibilityOff();
489 ::ResetCameraClippingRange(myRenderer);
494 //----------------------------------------------------------------
497 ::onSelectionChanged()
501 const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
502 SALOME_ListIteratorOfListIO anIter(aListIO);
503 for(; anIter.More(); anIter.Next()){
504 highlight(anIter.Value(),true,!anIter.More());
507 emit selectionChanged();
510 //----------------------------------------------------------------
513 ::SetSelectionMode(Selection_Mode theMode)
515 mySelector->SetSelectionMode(theMode);
516 myRWInteractor->SetSelectionMode(theMode);
519 //----------------------------------------------------------------
522 ::SelectionMode() const
524 return mySelector->SelectionMode();
527 //----------------------------------------------------------------
532 myRWInteractor->unHighlightAll();
535 //----------------------------------------------------------------
538 ::highlight( const Handle(SALOME_InteractiveObject)& theIO,
542 myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
544 if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
545 TColStd_IndexedMapOfInteger aMapIndex;
546 mySelector->GetIndex(theIO,aMapIndex);
548 const char* anEntry = theIO->getEntry();
549 vtkActorCollection* aCollection = myRenderer->GetActors();
550 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
551 switch (mySelector->SelectionMode()) {
553 myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
555 case EdgeOfCellSelection:
556 myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
561 case VolumeSelection:
562 myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
567 myRWInteractor->unHighlightSubSelection();
571 //----------------------------------------------------------------
574 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
576 return myRWInteractor->isInViewer( theIO );
579 //----------------------------------------------------------------
582 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
584 return myRWInteractor->isVisible( theIO );
587 //----------------------------------------------------------------------------
590 ::setBackgroundColor( const QColor& color )
593 myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
596 //----------------------------------------------------------------------------
599 ::backgroundColor() const
603 myRenderer->GetBackground( backint );
604 return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
606 return SUIT_ViewWindow::backgroundColor();
609 //----------------------------------------------------------------------------
612 ::Repaint(bool theUpdateTrihedron)
614 if (theUpdateTrihedron)
616 myRenderWindow->update();
619 //----------------------------------------------------------------------------
622 ::GetScale( double theScale[3] )
624 myTransform->GetMatrixScale( theScale );
627 //----------------------------------------------------------------------------
630 ::SetScale( double theScale[3] )
632 myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
633 myRWInteractor->Render();
637 //----------------------------------------------------------------------------
640 ::isTrihedronDisplayed()
642 return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
647 ::isCubeAxesDisplayed()
649 return myCubeAxes->GetVisibility() == 1;
652 //----------------------------------------------------------------------------
660 if(isTrihedronDisplayed())
661 myTrihedron->VisibilityOff();
663 myTrihedron->VisibilityOn();
675 if(isCubeAxesDisplayed())
676 myCubeAxes->VisibilityOff();
678 myCubeAxes->VisibilityOn();
683 //----------------------------------------------------------------------------
686 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
688 // calculating diagonal of visible props of the renderer
690 myTrihedron->VisibilityOff();
692 if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
693 aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
694 aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
697 myTrihedron->VisibilityOn();
699 static bool aCalcByDiag = false;
701 aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
702 ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
703 ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
705 aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
706 aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
707 aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
710 float aSizeInPercents = myTrihedronSize;
712 static float EPS_SIZE = 5.0E-3;
713 theSize = myTrihedron->GetSize();
714 theNewSize = aLength * aSizeInPercents / 100.0;
716 // if the new trihedron size have sufficient difference, then apply the value
717 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
718 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
721 //----------------------------------------------------------------------------
722 int SVTK_ViewWindow::GetTrihedronSize() const
724 return myTrihedronSize;
727 void SVTK_ViewWindow::SetTrihedronSize( const int sz )
729 if ( myTrihedronSize == sz )
732 myTrihedronSize = sz;
733 AdjustTrihedrons( true );
736 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
737 * trihedron and cube axes, even if trihedron and cube axes is invisible.
741 ::AdjustTrihedrons(const bool theIsForcedUpdate)
743 if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
748 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
749 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
751 myCubeAxes->GetBounds(bnd);
753 int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
754 //if (aVisibleNum || theIsForcedUpdate) {
756 // if the new trihedron size have sufficient difference, then apply the value
757 double aNewSize = 100, anOldSize=myTrihedron->GetSize();
758 bool aTDisplayed = isTrihedronDisplayed();
759 bool aCDisplayed = isCubeAxesDisplayed();
760 if(aTDisplayed) myTrihedron->VisibilityOff();
761 if(aCDisplayed) myCubeAxes->VisibilityOff();
763 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
764 QString aSetting = aResMgr->stringValue("Viewer", "TrihedronSize", "105");
765 static float aSizeInPercents = aSetting.toFloat();
767 //bool isComputeTrihedronSize =
768 ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents);
770 myTrihedron->SetSize( aNewSize );
772 // iterate through displayed objects and set size if necessary
773 vtkActorCollection* anActors = getRenderer()->GetActors();
774 anActors->InitTraversal();
775 while (vtkActor* anActor = anActors->GetNextActor())
777 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ))
779 if (aSActor->IsResizable())
780 aSActor->SetSize( 0.5 * aNewSize );
781 if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) {
782 float *abounds = aSActor->GetBounds();
783 if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
784 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
785 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
786 for (int i = 0; i < 5; i = i + 2) {
787 if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i];
788 if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1];
793 if (aTDisplayed) myTrihedron->VisibilityOn();
794 if (aCDisplayed) myCubeAxes->VisibilityOn();
797 double aSize = myTrihedron->GetSize();
798 newbnd[0] = newbnd[2] = newbnd[4] = 0;
799 newbnd[1] = newbnd[3] = newbnd[5] = aSize;
802 if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT &&
803 newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) {
804 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
805 myCubeAxes->SetBounds(bnd);
808 myCubeAxes->SetBounds(bnd);
810 ::ResetCameraClippingRange(myRenderer);
813 //----------------------------------------------------------------------------
816 ::onAdjustTrihedron()
818 AdjustTrihedrons( false );
825 AdjustTrihedrons(false);
828 #define INCREMENT_FOR_OP 10
830 //=======================================================================
832 // Purpose : Performs incremental panning to the left
833 //=======================================================================
838 myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
841 //=======================================================================
843 // Purpose : Performs incremental panning to the right
844 //=======================================================================
849 myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
852 //=======================================================================
854 // Purpose : Performs incremental panning to the top
855 //=======================================================================
860 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
863 //=======================================================================
865 // Purpose : Performs incremental panning to the bottom
866 //=======================================================================
871 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
874 //=======================================================================
876 // Purpose : Performs incremental zooming in
877 //=======================================================================
882 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
885 //=======================================================================
887 // Purpose : Performs incremental zooming out
888 //=======================================================================
893 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
896 //=======================================================================
897 // name : onRotateLeft
898 // Purpose : Performs incremental rotating to the left
899 //=======================================================================
904 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
907 //=======================================================================
908 // name : onRotateRight
909 // Purpose : Performs incremental rotating to the right
910 //=======================================================================
915 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
918 //=======================================================================
920 // Purpose : Performs incremental rotating to the top
921 //=======================================================================
926 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
929 //=======================================================================
932 ::onKeyPressed(QKeyEvent* event)
934 emit keyPressed( this, event );
937 //=======================================================================
940 ::onKeyReleased(QKeyEvent* event)
942 emit keyReleased( this, event );
945 //=======================================================================
948 ::onMousePressed(QMouseEvent* event)
950 emit mousePressed(this, event);
953 //=======================================================================
956 ::onMouseReleased(QMouseEvent* event)
958 emit mouseReleased( this, event );
961 //=======================================================================
964 ::onMouseMoving(QMouseEvent* event)
966 emit mouseMoving( this, event );
969 //=======================================================================
972 ::onMouseDoubleClicked( QMouseEvent* event )
974 emit mouseDoubleClicked( this, event );
977 //=======================================================================
978 // name : onRotateDown
979 // Purpose : Performs incremental rotating to the bottom
980 //=======================================================================
985 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
988 //----------------------------------------------------------------------------
991 ::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
993 theActor->AddToRender(myRenderer);
994 theActor->SetTransform(myTransform);
995 if(theMoveInternalActors)
996 myRWInteractor->MoveInternalActors();
999 //----------------------------------------------------------------------------
1002 ::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1004 InsertActor(theActor);
1009 //----------------------------------------------------------------------------
1012 ::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1014 theActor->RemoveFromRender(myRenderer);
1019 //----------------------------------------------------------------------------
1022 ::MoveActor( SALOME_Actor* theActor)
1024 RemoveActor(theActor);
1025 InsertActor(theActor,true);
1028 //----------------------------------------------------------------------------
1033 QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
1034 return px.convertToImage();
1037 //----------------------------------------------------------------------------
1040 ::action( const int theAction )
1042 switch ( theAction ) {
1043 case SUIT_Accel::PanLeft : onPanLeft(); break;
1044 case SUIT_Accel::PanRight : onPanRight(); break;
1045 case SUIT_Accel::PanUp : onPanUp(); break;
1046 case SUIT_Accel::PanDown : onPanDown(); break;
1047 case SUIT_Accel::ZoomIn : onZoomIn(); break;
1048 case SUIT_Accel::ZoomOut : onZoomOut(); break;
1049 case SUIT_Accel::ZoomFit : onFitAll(); break;
1050 case SUIT_Accel::RotateLeft : onRotateLeft(); break;
1051 case SUIT_Accel::RotateRight : onRotateRight(); break;
1052 case SUIT_Accel::RotateUp : onRotateUp(); break;
1053 case SUIT_Accel::RotateDown : onRotateDown(); break;