1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "SALOME_Actor.h"
21 #include <qapplication.h>
24 #include <vtkTextProperty.h>
25 #include <vtkActorCollection.h>
26 #include <vtkRenderWindow.h>
27 #include <vtkRenderer.h>
28 #include <vtkCamera.h>
30 #include "QtxAction.h"
32 #include "SUIT_Session.h"
33 #include "SUIT_ToolButton.h"
34 #include "SUIT_MessageBox.h"
35 #include "SUIT_Accel.h"
37 #include "SUIT_Tools.h"
38 #include "SUIT_ResourceMgr.h"
40 #include "VTKViewer_Transform.h"
41 #include "VTKViewer_Utilities.h"
43 #include "SVTK_Trihedron.h"
44 #include "SVTK_CubeAxesActor2D.h"
45 #include "SVTK_ViewWindow.h"
46 #include "SVTK_ViewModel.h"
47 #include "SVTK_RenderWindow.h"
48 #include "SVTK_RenderWindowInteractor.h"
49 #include "SVTK_InteractorStyle.h"
51 #include "SALOME_ListIteratorOfListIO.hxx"
53 #include "SVTK_SelectorDef.h"
55 #include "VTKViewer_Algorithm.h"
56 #include "SVTK_Functor.h"
58 //----------------------------------------------------------------------------
60 ::SVTK_ViewWindow( SUIT_Desktop* theDesktop,
61 SVTK_Viewer* theModel)
62 : SUIT_ViewWindow( theDesktop ),
63 myTrihedronSize( 100 )
66 mySelector = new SVTK_SelectorDef();
67 connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
69 myTransform = VTKViewer_Transform::New();
70 myTrihedron = SVTK_Trihedron::New();
71 myCubeAxes = SVTK_CubeAxesActor2D::New();
72 myRenderer = vtkRenderer::New() ;
74 myTrihedron->AddToRender( myRenderer );
75 myRenderer->AddProp(myCubeAxes);
77 myRenderWindow = new SVTK_RenderWindow( this, "RenderWindow" );
78 setCentralWidget(myRenderWindow);
79 myRenderWindow->setFocusPolicy( StrongFocus );
80 myRenderWindow->setFocus();
82 myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
84 myRenderer->GetActiveCamera()->ParallelProjectionOn();
85 myRenderer->LightFollowCameraOn();
86 myRenderer->TwoSidedLightingOn();
88 // Set BackgroundColor
89 QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
90 QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
91 QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
93 if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
94 myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
96 myRenderer->SetBackground( 0, 0, 0 );
98 // Create an interactor.
99 myRWInteractor = SVTK_RenderWindowInteractor::New();
100 myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
101 myRWInteractor->setViewWindow( this );
103 SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New();
104 RWS->setGUIWindow( myRenderWindow );
105 RWS->setViewWindow( this );
107 myRWInteractor->SetInteractorStyle( RWS );
108 myRWInteractor->Initialize();
110 //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron );
111 RWS->FindPokedRenderer( 0, 0 );
113 SetSelectionMode(ActorSelection);
115 vtkTextProperty* tprop = vtkTextProperty::New();
116 tprop->SetColor(1, 1, 1);
120 bnd[0] = bnd[2] = bnd[4] = 0;
121 bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize();
122 myCubeAxes->SetLabelFormat("%6.4g");
123 myCubeAxes->SetBounds(bnd);
124 myCubeAxes->SetCamera(myRenderer->GetActiveCamera());
125 myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
126 myCubeAxes->SetFontFactor(0.8);
127 myCubeAxes->SetAxisTitleTextProperty(tprop);
128 myCubeAxes->SetAxisLabelTextProperty(tprop);
129 myCubeAxes->SetCornerOffset(0);
130 myCubeAxes->SetScaling(0);
131 myCubeAxes->SetNumberOfLabels(5);
132 myCubeAxes->VisibilityOff();
133 myCubeAxes->SetTransform(myTransform);
136 setCentralWidget( myRenderWindow );
138 myToolBar = new QToolBar(this);
139 myToolBar->setCloseMode(QDockWindow::Undocked);
140 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
145 connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
146 this, SLOT(onKeyPressed( QKeyEvent* )) );
147 connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
148 this, SLOT(onKeyReleased( QKeyEvent* )) );
149 connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
150 this, SLOT(onMousePressed( QMouseEvent* )) );
151 connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
152 this, SLOT(onMouseReleased( QMouseEvent* )) );
153 connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
154 this, SLOT(onMouseDoubleClicked( QMouseEvent* )) );
155 connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
156 this, SLOT(onMouseMoving( QMouseEvent* )) );
158 connect( myRWInteractor, SIGNAL(RenderWindowModified()),
159 myRenderWindow, SLOT(update()) );
160 connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
161 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
166 //----------------------------------------------------------------------------
170 myTransform->Delete();
171 // In order to ensure that the interactor unregisters
172 // this RenderWindow, we assign a NULL RenderWindow to
173 // it before deleting it.
174 myRWInteractor->SetRenderWindow( NULL );
175 myRWInteractor->Delete();
178 myRenderer->RemoveAllProps();
179 //m_Renderer->Delete();
180 myTrihedron->Delete();
181 myCubeAxes->Delete();
184 //----------------------------------------------------------------------------
189 myRWInteractor->GetSInteractorStyle()->startZoom();
192 //----------------------------------------------------------------------------
197 myRWInteractor->GetSInteractorStyle()->startPan();
200 //----------------------------------------------------------------------------
205 myRWInteractor->GetSInteractorStyle()->startRotate();
208 //----------------------------------------------------------------------------
211 ::activateGlobalPanning()
213 if(myTrihedron->GetVisibleActorCount(myRenderer))
214 myRWInteractor->GetSInteractorStyle()->startGlobalPan();
217 //----------------------------------------------------------------------------
220 ::activateWindowFit()
222 myRWInteractor->GetSInteractorStyle()->startFitArea();
225 //----------------------------------------------------------------------------
226 #if defined(WIN32) && !defined(_DEBUG)
227 #pragma optimize( "", off )
233 if (!myActionsMap.isEmpty()) return;
235 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
240 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
241 tr( "MNU_DUMP_VIEW" ), 0, this);
242 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
243 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
244 myActionsMap[ DumpId ] = aAction;
247 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
248 tr( "MNU_FITALL" ), 0, this);
249 aAction->setStatusTip(tr("DSC_FITALL"));
250 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
251 myActionsMap[ FitAllId ] = aAction;
254 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
255 tr( "MNU_FITRECT" ), 0, this);
256 aAction->setStatusTip(tr("DSC_FITRECT"));
257 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
258 myActionsMap[ FitRectId ] = aAction;
261 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
262 tr( "MNU_ZOOM_VIEW" ), 0, this);
263 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
264 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
265 myActionsMap[ ZoomId ] = aAction;
268 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
269 tr( "MNU_PAN_VIEW" ), 0, this);
270 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
271 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
272 myActionsMap[ PanId ] = aAction;
275 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
276 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
277 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
278 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
279 myActionsMap[ GlobalPanId ] = aAction;
282 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
283 tr( "MNU_ROTATE_VIEW" ), 0, this);
284 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
285 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
286 myActionsMap[ RotationId ] = aAction;
289 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
290 tr( "MNU_FRONT_VIEW" ), 0, this);
291 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
292 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
293 myActionsMap[ FrontId ] = aAction;
295 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
296 tr( "MNU_BACK_VIEW" ), 0, this);
297 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
298 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
299 myActionsMap[ BackId ] = aAction;
301 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
302 tr( "MNU_TOP_VIEW" ), 0, this);
303 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
304 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
305 myActionsMap[ TopId ] = aAction;
307 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
308 tr( "MNU_BOTTOM_VIEW" ), 0, this);
309 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
310 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
311 myActionsMap[ BottomId ] = aAction;
313 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
314 tr( "MNU_LEFT_VIEW" ), 0, this);
315 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
316 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
317 myActionsMap[ LeftId ] = aAction;
319 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
320 tr( "MNU_RIGHT_VIEW" ), 0, this);
321 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
322 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
323 myActionsMap[ RightId ] = aAction;
326 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
327 tr( "MNU_RESET_VIEW" ), 0, this);
328 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
329 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
330 myActionsMap[ ResetId ] = aAction;
332 // onViewTrihedron: Shows - Hides Trihedron
333 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
334 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
335 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
336 connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
337 myActionsMap[ ViewTrihedronId ] = aAction;
339 #if defined(WIN32) && !defined(_DEBUG)
340 #pragma optimize( "", on )
343 //----------------------------------------------------------------------------
348 myActionsMap[DumpId]->addTo(myToolBar);
349 myActionsMap[ViewTrihedronId]->addTo(myToolBar);
351 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
352 aScaleBtn->AddAction(myActionsMap[FitAllId]);
353 aScaleBtn->AddAction(myActionsMap[FitRectId]);
354 aScaleBtn->AddAction(myActionsMap[ZoomId]);
356 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
357 aPanningBtn->AddAction(myActionsMap[PanId]);
358 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
360 myActionsMap[RotationId]->addTo(myToolBar);
362 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
363 aViewsBtn->AddAction(myActionsMap[FrontId]);
364 aViewsBtn->AddAction(myActionsMap[BackId]);
365 aViewsBtn->AddAction(myActionsMap[TopId]);
366 aViewsBtn->AddAction(myActionsMap[BottomId]);
367 aViewsBtn->AddAction(myActionsMap[LeftId]);
368 aViewsBtn->AddAction(myActionsMap[RightId]);
370 myActionsMap[ResetId]->addTo(myToolBar);
373 //----------------------------------------------------------------------------
378 vtkCamera* camera = myRenderer->GetActiveCamera();
379 camera->SetPosition(1,0,0);
380 camera->SetViewUp(0,0,1);
381 camera->SetFocalPoint(0,0,0);
385 //----------------------------------------------------------------------------
390 vtkCamera* camera = myRenderer->GetActiveCamera();
391 camera->SetPosition(-1,0,0);
392 camera->SetViewUp(0,0,1);
393 camera->SetFocalPoint(0,0,0);
397 //----------------------------------------------------------------------------
402 vtkCamera* camera = myRenderer->GetActiveCamera();
403 camera->SetPosition(0,0,1);
404 camera->SetViewUp(0,1,0);
405 camera->SetFocalPoint(0,0,0);
409 //----------------------------------------------------------------------------
414 vtkCamera* camera = myRenderer->GetActiveCamera();
415 camera->SetPosition(0,0,-1);
416 camera->SetViewUp(0,1,0);
417 camera->SetFocalPoint(0,0,0);
421 //----------------------------------------------------------------------------
426 vtkCamera* camera = myRenderer->GetActiveCamera();
427 camera->SetPosition(0,-1,0);
428 camera->SetViewUp(0,0,1);
429 camera->SetFocalPoint(0,0,0);
433 //----------------------------------------------------------------------------
438 vtkCamera* camera = myRenderer->GetActiveCamera();
439 camera->SetPosition(0,1,0);
440 camera->SetViewUp(0,0,1);
441 camera->SetFocalPoint(0,0,0);
445 //----------------------------------------------------------------------------
450 int aTrihedronIsVisible = isTrihedronDisplayed();
451 int aCubeAxesIsVisible = isCubeAxesDisplayed();
453 myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
454 myCubeAxes->SetVisibility(0);
456 ::ResetCamera(myRenderer,true);
457 vtkCamera* aCamera = myRenderer->GetActiveCamera();
458 aCamera->SetPosition(1,-1,1);
459 aCamera->SetViewUp(0,0,1);
460 ::ResetCamera(myRenderer,true);
462 if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
463 else myTrihedron->VisibilityOff();
465 if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
466 else myCubeAxes->VisibilityOff();
468 static float aCoeff = 3.0;
469 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
473 //----------------------------------------------------------------------------
478 int aTrihedronWasVisible = false;
479 int aCubeAxesWasVisible = false;
481 aTrihedronWasVisible = isTrihedronDisplayed();
482 if (aTrihedronWasVisible)
483 myTrihedron->VisibilityOff();
487 aCubeAxesWasVisible = isCubeAxesDisplayed();
488 if (aCubeAxesWasVisible)
489 myCubeAxes->VisibilityOff();
492 if (myTrihedron->GetVisibleActorCount(myRenderer)) {
493 myTrihedron->VisibilityOff();
494 myCubeAxes->VisibilityOff();
495 ::ResetCamera(myRenderer);
497 myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
498 myCubeAxes->SetVisibility(2);
499 ::ResetCamera(myRenderer,true);
502 if (aTrihedronWasVisible)
503 myTrihedron->VisibilityOn();
505 myTrihedron->VisibilityOff();
507 if (aCubeAxesWasVisible)
508 myCubeAxes->VisibilityOn();
510 myCubeAxes->VisibilityOff();
512 ::ResetCameraClippingRange(myRenderer);
517 //----------------------------------------------------------------
520 ::onSelectionChanged()
524 const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
525 SALOME_ListIteratorOfListIO anIter(aListIO);
526 for(; anIter.More(); anIter.Next()){
527 highlight(anIter.Value(),true,!anIter.More());
530 emit selectionChanged();
533 //----------------------------------------------------------------
536 ::SetSelectionMode(Selection_Mode theMode)
538 mySelector->SetSelectionMode(theMode);
539 myRWInteractor->SetSelectionMode(theMode);
542 //----------------------------------------------------------------
545 ::SelectionMode() const
547 return mySelector->SelectionMode();
550 //----------------------------------------------------------------
555 myRWInteractor->unHighlightAll();
558 //----------------------------------------------------------------
561 ::highlight( const Handle(SALOME_InteractiveObject)& theIO,
565 myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
567 if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
568 TColStd_IndexedMapOfInteger aMapIndex;
569 mySelector->GetIndex(theIO,aMapIndex);
571 const char* anEntry = theIO->getEntry();
572 vtkActorCollection* aCollection = myRenderer->GetActors();
573 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
574 switch (mySelector->SelectionMode()) {
576 myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
578 case EdgeOfCellSelection:
579 myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
584 case VolumeSelection:
585 myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
590 myRWInteractor->unHighlightSubSelection();
594 //----------------------------------------------------------------
597 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
599 return myRWInteractor->isInViewer( theIO );
602 //----------------------------------------------------------------
605 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
607 return myRWInteractor->isVisible( theIO );
610 //----------------------------------------------------------------------------
613 ::setBackgroundColor( const QColor& color )
616 myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
619 //----------------------------------------------------------------------------
622 ::backgroundColor() const
626 myRenderer->GetBackground( backint );
627 return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
629 return SUIT_ViewWindow::backgroundColor();
632 //----------------------------------------------------------------------------
635 ::Repaint(bool theUpdateTrihedron)
637 if (theUpdateTrihedron)
639 myRenderWindow->update();
642 //----------------------------------------------------------------------------
645 ::GetScale( double theScale[3] )
647 myTransform->GetMatrixScale( theScale );
650 //----------------------------------------------------------------------------
653 ::SetScale( double theScale[3] )
655 myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
656 myRWInteractor->Render();
660 //----------------------------------------------------------------------------
663 ::isTrihedronDisplayed()
665 return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
670 ::isCubeAxesDisplayed()
672 return myCubeAxes->GetVisibility() == 1;
675 //----------------------------------------------------------------------------
683 if(isTrihedronDisplayed())
684 myTrihedron->VisibilityOff();
686 myTrihedron->VisibilityOn();
698 if(isCubeAxesDisplayed())
699 myCubeAxes->VisibilityOff();
701 myCubeAxes->VisibilityOn();
706 //----------------------------------------------------------------------------
709 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
711 // calculating diagonal of visible props of the renderer
713 myTrihedron->VisibilityOff();
715 if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
716 aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
717 aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
720 myTrihedron->VisibilityOn();
722 static bool aCalcByDiag = false;
724 aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
725 ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
726 ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
728 aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
729 aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
730 aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
733 float aSizeInPercents = myTrihedronSize;
735 static float EPS_SIZE = 5.0E-3;
736 theSize = myTrihedron->GetSize();
737 theNewSize = aLength * aSizeInPercents / 100.0;
739 // if the new trihedron size have sufficient difference, then apply the value
740 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
741 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
744 //----------------------------------------------------------------------------
745 int SVTK_ViewWindow::GetTrihedronSize() const
747 return myTrihedronSize;
750 void SVTK_ViewWindow::SetTrihedronSize( const int sz )
752 myTrihedronSize = sz;
753 AdjustTrihedrons( true );
756 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
757 * trihedron and cube axes, even if trihedron and cube axes is invisible.
761 ::AdjustTrihedrons(const bool theIsForcedUpdate)
763 if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
768 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
769 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
771 myCubeAxes->GetBounds(bnd);
773 int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
775 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
776 bool isRelativeSize = aResMgr->booleanValue( "VTKViewer", "relative_size", true );
778 //if (aVisibleNum || theIsForcedUpdate) {
779 if (aVisibleNum || !isRelativeSize) {
780 // if the new trihedron size have sufficient difference, then apply the value
781 double aNewSize = 100, anOldSize=myTrihedron->GetSize();
782 bool aTDisplayed = isTrihedronDisplayed();
783 bool aCDisplayed = isCubeAxesDisplayed();
784 if(aTDisplayed) myTrihedron->VisibilityOff();
785 if(aCDisplayed) myCubeAxes->VisibilityOff();
787 int aDefaultSize = 100;
788 if (isRelativeSize) aDefaultSize = 105;
789 int aSizeFromPreferences = aResMgr->integerValue( "VTKViewer", "trihedron_size", aDefaultSize );
791 //bool isComputeTrihedronSize =
793 ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, (float)aSizeFromPreferences);
795 aNewSize = (double)aSizeFromPreferences;
797 myTrihedron->SetSize( aNewSize );
799 // iterate through displayed objects and set size if necessary
800 vtkActorCollection* anActors = getRenderer()->GetActors();
801 anActors->InitTraversal();
802 while (vtkActor* anActor = anActors->GetNextActor())
804 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ))
806 if (aSActor->IsResizable())
807 aSActor->SetSize( 0.5 * aNewSize );
808 if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) {
809 float *abounds = aSActor->GetBounds();
810 if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
811 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
812 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
813 for (int i = 0; i < 5; i = i + 2) {
814 if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i];
815 if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1];
820 if (aTDisplayed) myTrihedron->VisibilityOn();
821 if (aCDisplayed) myCubeAxes->VisibilityOn();
824 double aSize = myTrihedron->GetSize();
825 newbnd[0] = newbnd[2] = newbnd[4] = 0;
826 newbnd[1] = newbnd[3] = newbnd[5] = aSize;
829 if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT &&
830 newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) {
831 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
832 myCubeAxes->SetBounds(bnd);
835 myCubeAxes->SetBounds(bnd);
837 ::ResetCameraClippingRange(myRenderer);
840 //----------------------------------------------------------------------------
843 ::onAdjustTrihedron()
845 AdjustTrihedrons( false );
852 AdjustTrihedrons(false);
855 #define INCREMENT_FOR_OP 10
857 //=======================================================================
859 // Purpose : Performs incremental panning to the left
860 //=======================================================================
865 myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
868 //=======================================================================
870 // Purpose : Performs incremental panning to the right
871 //=======================================================================
876 myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
879 //=======================================================================
881 // Purpose : Performs incremental panning to the top
882 //=======================================================================
887 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
890 //=======================================================================
892 // Purpose : Performs incremental panning to the bottom
893 //=======================================================================
898 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
901 //=======================================================================
903 // Purpose : Performs incremental zooming in
904 //=======================================================================
909 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
912 //=======================================================================
914 // Purpose : Performs incremental zooming out
915 //=======================================================================
920 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
923 //=======================================================================
924 // name : onRotateLeft
925 // Purpose : Performs incremental rotating to the left
926 //=======================================================================
931 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
934 //=======================================================================
935 // name : onRotateRight
936 // Purpose : Performs incremental rotating to the right
937 //=======================================================================
942 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
945 //=======================================================================
947 // Purpose : Performs incremental rotating to the top
948 //=======================================================================
953 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
956 //=======================================================================
959 ::onKeyPressed(QKeyEvent* event)
961 emit keyPressed( this, event );
964 //=======================================================================
967 ::onKeyReleased(QKeyEvent* event)
969 emit keyReleased( this, event );
972 //=======================================================================
975 ::onMousePressed(QMouseEvent* event)
977 emit mousePressed(this, event);
980 //=======================================================================
983 ::onMouseReleased(QMouseEvent* event)
985 emit mouseReleased( this, event );
988 //=======================================================================
991 ::onMouseMoving(QMouseEvent* event)
993 emit mouseMoving( this, event );
996 //=======================================================================
999 ::onMouseDoubleClicked( QMouseEvent* event )
1001 emit mouseDoubleClicked( this, event );
1004 //=======================================================================
1005 // name : onRotateDown
1006 // Purpose : Performs incremental rotating to the bottom
1007 //=======================================================================
1012 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
1015 //----------------------------------------------------------------------------
1018 ::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
1020 theActor->AddToRender(myRenderer);
1021 theActor->SetTransform(myTransform);
1022 if(theMoveInternalActors)
1023 myRWInteractor->MoveInternalActors();
1026 //----------------------------------------------------------------------------
1029 ::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1031 InsertActor(theActor);
1036 //----------------------------------------------------------------------------
1039 ::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1041 theActor->RemoveFromRender(myRenderer);
1046 //----------------------------------------------------------------------------
1049 ::MoveActor( SALOME_Actor* theActor)
1051 RemoveActor(theActor);
1052 InsertActor(theActor,true);
1055 //----------------------------------------------------------------------------
1060 QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
1061 return px.convertToImage();
1064 //----------------------------------------------------------------------------
1067 ::action( const int theAction )
1069 switch ( theAction ) {
1070 case SUIT_Accel::PanLeft : onPanLeft(); break;
1071 case SUIT_Accel::PanRight : onPanRight(); break;
1072 case SUIT_Accel::PanUp : onPanUp(); break;
1073 case SUIT_Accel::PanDown : onPanDown(); break;
1074 case SUIT_Accel::ZoomIn : onZoomIn(); break;
1075 case SUIT_Accel::ZoomOut : onZoomOut(); break;
1076 case SUIT_Accel::ZoomFit : onFitAll(); break;
1077 case SUIT_Accel::RotateLeft : onRotateLeft(); break;
1078 case SUIT_Accel::RotateRight : onRotateRight(); break;
1079 case SUIT_Accel::RotateUp : onRotateUp(); break;
1080 case SUIT_Accel::RotateDown : onRotateDown(); break;