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>
23 #include <vtkTextProperty.h>
24 #include <vtkActorCollection.h>
25 #include <vtkRenderWindow.h>
26 #include <vtkRenderer.h>
27 #include <vtkCamera.h>
29 #include "QtxAction.h"
31 #include "SUIT_Session.h"
32 #include "SUIT_ToolButton.h"
33 #include "SUIT_MessageBox.h"
34 #include "SUIT_Accel.h"
36 #include "SUIT_Tools.h"
37 #include "SUIT_ResourceMgr.h"
39 #include "VTKViewer_Transform.h"
40 #include "VTKViewer_Utilities.h"
42 #include "SVTK_Trihedron.h"
43 #include "SVTK_CubeAxesActor2D.h"
44 #include "SVTK_ViewWindow.h"
45 #include "SVTK_ViewModel.h"
46 #include "SVTK_RenderWindow.h"
47 #include "SVTK_RenderWindowInteractor.h"
48 #include "SVTK_InteractorStyle.h"
50 #include "SALOME_ListIteratorOfListIO.hxx"
52 #include "SVTK_SelectorDef.h"
54 #include "VTKViewer_Algorithm.h"
55 #include "SVTK_Functor.h"
57 //----------------------------------------------------------------------------
59 ::SVTK_ViewWindow( SUIT_Desktop* theDesktop,
60 SVTK_Viewer* theModel)
61 : SUIT_ViewWindow( theDesktop ),
62 myTrihedronSize( 100 )
65 mySelector = new SVTK_SelectorDef();
66 connect(this,SIGNAL(selectionChanged()),theModel,SLOT(onSelectionChanged()));
68 myTransform = VTKViewer_Transform::New();
69 myTrihedron = SVTK_Trihedron::New();
70 myCubeAxes = SVTK_CubeAxesActor2D::New();
71 myRenderer = vtkRenderer::New() ;
73 myTrihedron->AddToRender( myRenderer );
74 myRenderer->AddProp(myCubeAxes);
76 myRenderWindow = new SVTK_RenderWindow( this, "RenderWindow" );
77 setCentralWidget(myRenderWindow);
78 myRenderWindow->setFocusPolicy( StrongFocus );
79 myRenderWindow->setFocus();
81 myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
83 myRenderer->GetActiveCamera()->ParallelProjectionOn();
84 myRenderer->LightFollowCameraOn();
85 myRenderer->TwoSidedLightingOn();
87 // Set BackgroundColor
88 QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
89 QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
90 QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
92 if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
93 myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
95 myRenderer->SetBackground( 0, 0, 0 );
97 // Create an interactor.
98 myRWInteractor = SVTK_RenderWindowInteractor::New();
99 myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
100 myRWInteractor->setViewWindow( this );
102 SVTK_InteractorStyle* RWS = SVTK_InteractorStyle::New();
103 RWS->setGUIWindow( myRenderWindow );
104 RWS->setViewWindow( this );
106 myRWInteractor->SetInteractorStyle( RWS );
107 myRWInteractor->Initialize();
109 //merge with V2_2_0_VISU_improvements:RWS->setTriedron( myTrihedron );
110 RWS->FindPokedRenderer( 0, 0 );
112 SetSelectionMode(ActorSelection);
114 vtkTextProperty* tprop = vtkTextProperty::New();
115 tprop->SetColor(1, 1, 1);
119 bnd[0] = bnd[2] = bnd[4] = 0;
120 bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize();
121 myCubeAxes->SetLabelFormat("%6.4g");
122 myCubeAxes->SetBounds(bnd);
123 myCubeAxes->SetCamera(myRenderer->GetActiveCamera());
124 myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
125 myCubeAxes->SetFontFactor(0.8);
126 myCubeAxes->SetAxisTitleTextProperty(tprop);
127 myCubeAxes->SetAxisLabelTextProperty(tprop);
128 myCubeAxes->SetCornerOffset(0);
129 myCubeAxes->SetScaling(0);
130 myCubeAxes->SetNumberOfLabels(5);
131 myCubeAxes->VisibilityOff();
132 myCubeAxes->SetTransform(myTransform);
135 setCentralWidget( myRenderWindow );
137 myToolBar = new QToolBar(this);
138 myToolBar->setCloseMode(QDockWindow::Undocked);
139 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
144 connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
145 this, SLOT(onKeyPressed( QKeyEvent* )) );
146 connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
147 this, SLOT(onKeyReleased( QKeyEvent* )) );
148 connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
149 this, SLOT(onMousePressed( QMouseEvent* )) );
150 connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
151 this, SLOT(onMouseReleased( QMouseEvent* )) );
152 connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
153 this, SLOT(onMouseDoubleClicked( QMouseEvent* )) );
154 connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
155 this, SLOT(onMouseMoving( QMouseEvent* )) );
157 connect( myRWInteractor, SIGNAL(RenderWindowModified()),
158 myRenderWindow, SLOT(update()) );
159 connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
160 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
165 //----------------------------------------------------------------------------
169 myTransform->Delete();
170 // In order to ensure that the interactor unregisters
171 // this RenderWindow, we assign a NULL RenderWindow to
172 // it before deleting it.
173 myRWInteractor->SetRenderWindow( NULL );
174 myRWInteractor->Delete();
177 myRenderer->RemoveAllProps();
178 //m_Renderer->Delete();
179 myTrihedron->Delete();
180 myCubeAxes->Delete();
183 //----------------------------------------------------------------------------
188 myRWInteractor->GetSInteractorStyle()->startZoom();
191 //----------------------------------------------------------------------------
196 myRWInteractor->GetSInteractorStyle()->startPan();
199 //----------------------------------------------------------------------------
204 myRWInteractor->GetSInteractorStyle()->startRotate();
207 //----------------------------------------------------------------------------
210 ::activateGlobalPanning()
212 if(myTrihedron->GetVisibleActorCount(myRenderer))
213 myRWInteractor->GetSInteractorStyle()->startGlobalPan();
216 //----------------------------------------------------------------------------
219 ::activateWindowFit()
221 myRWInteractor->GetSInteractorStyle()->startFitArea();
224 //----------------------------------------------------------------------------
225 #if defined(WIN32) && !defined(_DEBUG)
226 #pragma optimize( "", off )
232 if (!myActionsMap.isEmpty()) return;
234 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
239 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
240 tr( "MNU_DUMP_VIEW" ), 0, this);
241 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
242 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
243 myActionsMap[ DumpId ] = aAction;
246 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
247 tr( "MNU_FITALL" ), 0, this);
248 aAction->setStatusTip(tr("DSC_FITALL"));
249 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
250 myActionsMap[ FitAllId ] = aAction;
253 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
254 tr( "MNU_FITRECT" ), 0, this);
255 aAction->setStatusTip(tr("DSC_FITRECT"));
256 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
257 myActionsMap[ FitRectId ] = aAction;
260 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
261 tr( "MNU_ZOOM_VIEW" ), 0, this);
262 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
263 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
264 myActionsMap[ ZoomId ] = aAction;
267 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
268 tr( "MNU_PAN_VIEW" ), 0, this);
269 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
270 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
271 myActionsMap[ PanId ] = aAction;
274 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
275 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
276 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
277 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
278 myActionsMap[ GlobalPanId ] = aAction;
281 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
282 tr( "MNU_ROTATE_VIEW" ), 0, this);
283 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
284 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
285 myActionsMap[ RotationId ] = aAction;
288 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
289 tr( "MNU_FRONT_VIEW" ), 0, this);
290 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
291 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
292 myActionsMap[ FrontId ] = aAction;
294 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
295 tr( "MNU_BACK_VIEW" ), 0, this);
296 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
297 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
298 myActionsMap[ BackId ] = aAction;
300 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
301 tr( "MNU_TOP_VIEW" ), 0, this);
302 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
303 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
304 myActionsMap[ TopId ] = aAction;
306 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
307 tr( "MNU_BOTTOM_VIEW" ), 0, this);
308 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
309 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
310 myActionsMap[ BottomId ] = aAction;
312 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
313 tr( "MNU_LEFT_VIEW" ), 0, this);
314 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
315 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
316 myActionsMap[ LeftId ] = aAction;
318 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
319 tr( "MNU_RIGHT_VIEW" ), 0, this);
320 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
321 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
322 myActionsMap[ RightId ] = aAction;
325 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
326 tr( "MNU_RESET_VIEW" ), 0, this);
327 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
328 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
329 myActionsMap[ ResetId ] = aAction;
331 // onViewTrihedron: Shows - Hides Trihedron
332 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
333 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
334 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
335 connect(aAction, SIGNAL(activated()), this, SLOT(onViewTrihedron()));
336 myActionsMap[ ViewTrihedronId ] = aAction;
338 #if defined(WIN32) && !defined(_DEBUG)
339 #pragma optimize( "", on )
342 //----------------------------------------------------------------------------
347 myActionsMap[DumpId]->addTo(myToolBar);
348 myActionsMap[ViewTrihedronId]->addTo(myToolBar);
350 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
351 aScaleBtn->AddAction(myActionsMap[FitAllId]);
352 aScaleBtn->AddAction(myActionsMap[FitRectId]);
353 aScaleBtn->AddAction(myActionsMap[ZoomId]);
355 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
356 aPanningBtn->AddAction(myActionsMap[PanId]);
357 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
359 myActionsMap[RotationId]->addTo(myToolBar);
361 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
362 aViewsBtn->AddAction(myActionsMap[FrontId]);
363 aViewsBtn->AddAction(myActionsMap[BackId]);
364 aViewsBtn->AddAction(myActionsMap[TopId]);
365 aViewsBtn->AddAction(myActionsMap[BottomId]);
366 aViewsBtn->AddAction(myActionsMap[LeftId]);
367 aViewsBtn->AddAction(myActionsMap[RightId]);
369 myActionsMap[ResetId]->addTo(myToolBar);
372 //----------------------------------------------------------------------------
377 vtkCamera* camera = myRenderer->GetActiveCamera();
378 camera->SetPosition(1,0,0);
379 camera->SetViewUp(0,0,1);
380 camera->SetFocalPoint(0,0,0);
384 //----------------------------------------------------------------------------
389 vtkCamera* camera = myRenderer->GetActiveCamera();
390 camera->SetPosition(-1,0,0);
391 camera->SetViewUp(0,0,1);
392 camera->SetFocalPoint(0,0,0);
396 //----------------------------------------------------------------------------
401 vtkCamera* camera = myRenderer->GetActiveCamera();
402 camera->SetPosition(0,0,1);
403 camera->SetViewUp(0,1,0);
404 camera->SetFocalPoint(0,0,0);
408 //----------------------------------------------------------------------------
413 vtkCamera* camera = myRenderer->GetActiveCamera();
414 camera->SetPosition(0,0,-1);
415 camera->SetViewUp(0,1,0);
416 camera->SetFocalPoint(0,0,0);
420 //----------------------------------------------------------------------------
425 vtkCamera* camera = myRenderer->GetActiveCamera();
426 camera->SetPosition(0,-1,0);
427 camera->SetViewUp(0,0,1);
428 camera->SetFocalPoint(0,0,0);
432 //----------------------------------------------------------------------------
437 vtkCamera* camera = myRenderer->GetActiveCamera();
438 camera->SetPosition(0,1,0);
439 camera->SetViewUp(0,0,1);
440 camera->SetFocalPoint(0,0,0);
444 //----------------------------------------------------------------------------
449 int aTrihedronIsVisible = isTrihedronDisplayed();
450 int aCubeAxesIsVisible = isCubeAxesDisplayed();
452 myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
453 myCubeAxes->SetVisibility(0);
455 ::ResetCamera(myRenderer,true);
456 vtkCamera* aCamera = myRenderer->GetActiveCamera();
457 aCamera->SetPosition(1,-1,1);
458 aCamera->SetViewUp(0,0,1);
459 ::ResetCamera(myRenderer,true);
461 if (aTrihedronIsVisible) myTrihedron->VisibilityOn();
462 else myTrihedron->VisibilityOff();
464 if (aCubeAxesIsVisible) myCubeAxes->VisibilityOn();
465 else myCubeAxes->VisibilityOff();
467 static float aCoeff = 3.0;
468 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
472 //----------------------------------------------------------------------------
477 int aTrihedronWasVisible = false;
478 int aCubeAxesWasVisible = false;
480 aTrihedronWasVisible = isTrihedronDisplayed();
481 if (aTrihedronWasVisible)
482 myTrihedron->VisibilityOff();
486 aCubeAxesWasVisible = isCubeAxesDisplayed();
487 if (aCubeAxesWasVisible)
488 myCubeAxes->VisibilityOff();
491 if (myTrihedron->GetVisibleActorCount(myRenderer)) {
492 myTrihedron->VisibilityOff();
493 myCubeAxes->VisibilityOff();
494 ::ResetCamera(myRenderer);
496 myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
497 myCubeAxes->SetVisibility(2);
498 ::ResetCamera(myRenderer,true);
501 if (aTrihedronWasVisible)
502 myTrihedron->VisibilityOn();
504 myTrihedron->VisibilityOff();
506 if (aCubeAxesWasVisible)
507 myCubeAxes->VisibilityOn();
509 myCubeAxes->VisibilityOff();
511 ::ResetCameraClippingRange(myRenderer);
516 //----------------------------------------------------------------
519 ::onSelectionChanged()
523 const SALOME_ListIO& aListIO = mySelector->StoredIObjects();
524 SALOME_ListIteratorOfListIO anIter(aListIO);
525 for(; anIter.More(); anIter.Next()){
526 highlight(anIter.Value(),true,!anIter.More());
529 emit selectionChanged();
532 //----------------------------------------------------------------
535 ::SetSelectionMode(Selection_Mode theMode)
537 mySelector->SetSelectionMode(theMode);
538 myRWInteractor->SetSelectionMode(theMode);
541 //----------------------------------------------------------------
544 ::SelectionMode() const
546 return mySelector->SelectionMode();
549 //----------------------------------------------------------------
554 myRWInteractor->unHighlightAll();
557 //----------------------------------------------------------------
560 ::highlight( const Handle(SALOME_InteractiveObject)& theIO,
564 myRWInteractor->highlight(theIO, theIsHighlight, theIsUpdate);
566 if(mySelector->HasIndex(theIO) && theIO->hasEntry()){
567 TColStd_IndexedMapOfInteger aMapIndex;
568 mySelector->GetIndex(theIO,aMapIndex);
570 const char* anEntry = theIO->getEntry();
571 vtkActorCollection* aCollection = myRenderer->GetActors();
572 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
573 switch (mySelector->SelectionMode()) {
575 myRWInteractor->highlightPoint(aMapIndex,anActor,theIsHighlight,theIsUpdate);
577 case EdgeOfCellSelection:
578 myRWInteractor->highlightEdge(aMapIndex,anActor,theIsHighlight,theIsUpdate);
583 case VolumeSelection:
584 myRWInteractor->highlightCell(aMapIndex,anActor,theIsHighlight,theIsUpdate);
589 myRWInteractor->unHighlightSubSelection();
593 //----------------------------------------------------------------
596 ::isInViewer( const Handle(SALOME_InteractiveObject)& theIO )
598 return myRWInteractor->isInViewer( theIO );
601 //----------------------------------------------------------------
604 ::isVisible( const Handle(SALOME_InteractiveObject)& theIO )
606 return myRWInteractor->isVisible( theIO );
609 //----------------------------------------------------------------------------
612 ::setBackgroundColor( const QColor& color )
615 myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
618 //----------------------------------------------------------------------------
621 ::backgroundColor() const
625 myRenderer->GetBackground( backint );
626 return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
628 return SUIT_ViewWindow::backgroundColor();
631 //----------------------------------------------------------------------------
634 ::Repaint(bool theUpdateTrihedron)
636 if (theUpdateTrihedron)
638 myRenderWindow->update();
641 //----------------------------------------------------------------------------
644 ::GetScale( double theScale[3] )
646 myTransform->GetMatrixScale( theScale );
649 //----------------------------------------------------------------------------
652 ::SetScale( double theScale[3] )
654 myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
655 myRWInteractor->Render();
659 //----------------------------------------------------------------------------
662 ::isTrihedronDisplayed()
664 return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
669 ::isCubeAxesDisplayed()
671 return myCubeAxes->GetVisibility() == 1;
674 //----------------------------------------------------------------------------
682 if(isTrihedronDisplayed())
683 myTrihedron->VisibilityOff();
685 myTrihedron->VisibilityOn();
697 if(isCubeAxesDisplayed())
698 myCubeAxes->VisibilityOff();
700 myCubeAxes->VisibilityOn();
705 //----------------------------------------------------------------------------
708 ::ComputeTrihedronSize( double& theNewSize, double& theSize )
710 // calculating diagonal of visible props of the renderer
712 myTrihedron->VisibilityOff();
714 if ( ::ComputeVisiblePropBounds( myRenderer, aBndBox ) == 0 ) {
715 aBndBox[ 1 ] = aBndBox[ 3 ] = aBndBox[ 5 ] = 100;
716 aBndBox[ 0 ] = aBndBox[ 2 ] = aBndBox[ 4 ] = 0;
719 myTrihedron->VisibilityOn();
721 static bool aCalcByDiag = false;
723 aLength = sqrt( ( aBndBox[1]-aBndBox[0])*(aBndBox[1]-aBndBox[0] )+
724 ( aBndBox[3]-aBndBox[2])*(aBndBox[3]-aBndBox[2] )+
725 ( aBndBox[5]-aBndBox[4])*(aBndBox[5]-aBndBox[4] ) );
727 aLength = aBndBox[ 1 ]-aBndBox[ 0 ];
728 aLength = max( ( aBndBox[ 3 ] - aBndBox[ 2 ] ),aLength );
729 aLength = max( ( aBndBox[ 5 ] - aBndBox[ 4 ] ),aLength );
732 float aSizeInPercents = myTrihedronSize;
734 static float EPS_SIZE = 5.0E-3;
735 theSize = myTrihedron->GetSize();
736 theNewSize = aLength * aSizeInPercents / 100.0;
738 // if the new trihedron size have sufficient difference, then apply the value
739 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
740 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
743 //----------------------------------------------------------------------------
744 int SVTK_ViewWindow::GetTrihedronSize() const
746 return myTrihedronSize;
749 void SVTK_ViewWindow::SetTrihedronSize( const int sz )
751 if ( myTrihedronSize == sz )
754 myTrihedronSize = sz;
755 AdjustTrihedrons( true );
758 /*! If parameter theIsForcedUpdate is true, recalculate parameters for
759 * trihedron and cube axes, even if trihedron and cube axes is invisible.
763 ::AdjustTrihedrons(const bool theIsForcedUpdate)
765 if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate)
770 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
771 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
773 myCubeAxes->GetBounds(bnd);
775 int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer );
776 //if (aVisibleNum || theIsForcedUpdate) {
778 // if the new trihedron size have sufficient difference, then apply the value
779 double aNewSize = 100, anOldSize=myTrihedron->GetSize();
780 bool aTDisplayed = isTrihedronDisplayed();
781 bool aCDisplayed = isCubeAxesDisplayed();
782 if(aTDisplayed) myTrihedron->VisibilityOff();
783 if(aCDisplayed) myCubeAxes->VisibilityOff();
785 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
786 QString aSetting = aResMgr->stringValue("Viewer", "TrihedronSize", "105");
787 static float aSizeInPercents = aSetting.toFloat();
789 //bool isComputeTrihedronSize =
790 ::ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents);
792 myTrihedron->SetSize( aNewSize );
794 // iterate through displayed objects and set size if necessary
795 vtkActorCollection* anActors = getRenderer()->GetActors();
796 anActors->InitTraversal();
797 while (vtkActor* anActor = anActors->GetNextActor())
799 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ))
801 if (aSActor->IsResizable())
802 aSActor->SetSize( 0.5 * aNewSize );
803 if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) {
804 float *abounds = aSActor->GetBounds();
805 if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
806 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
807 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
808 for (int i = 0; i < 5; i = i + 2) {
809 if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i];
810 if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1];
815 if (aTDisplayed) myTrihedron->VisibilityOn();
816 if (aCDisplayed) myCubeAxes->VisibilityOn();
819 double aSize = myTrihedron->GetSize();
820 newbnd[0] = newbnd[2] = newbnd[4] = 0;
821 newbnd[1] = newbnd[3] = newbnd[5] = aSize;
824 if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT &&
825 newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) {
826 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
827 myCubeAxes->SetBounds(bnd);
830 myCubeAxes->SetBounds(bnd);
832 ::ResetCameraClippingRange(myRenderer);
835 //----------------------------------------------------------------------------
838 ::onAdjustTrihedron()
840 AdjustTrihedrons( false );
847 AdjustTrihedrons(false);
850 #define INCREMENT_FOR_OP 10
852 //=======================================================================
854 // Purpose : Performs incremental panning to the left
855 //=======================================================================
860 myRWInteractor->GetSInteractorStyle()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
863 //=======================================================================
865 // Purpose : Performs incremental panning to the right
866 //=======================================================================
871 myRWInteractor->GetSInteractorStyle()->IncrementalPan( INCREMENT_FOR_OP, 0 );
874 //=======================================================================
876 // Purpose : Performs incremental panning to the top
877 //=======================================================================
882 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, INCREMENT_FOR_OP );
885 //=======================================================================
887 // Purpose : Performs incremental panning to the bottom
888 //=======================================================================
893 myRWInteractor->GetSInteractorStyle()->IncrementalPan( 0, -INCREMENT_FOR_OP );
896 //=======================================================================
898 // Purpose : Performs incremental zooming in
899 //=======================================================================
904 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( INCREMENT_FOR_OP );
907 //=======================================================================
909 // Purpose : Performs incremental zooming out
910 //=======================================================================
915 myRWInteractor->GetSInteractorStyle()->IncrementalZoom( -INCREMENT_FOR_OP );
918 //=======================================================================
919 // name : onRotateLeft
920 // Purpose : Performs incremental rotating to the left
921 //=======================================================================
926 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
929 //=======================================================================
930 // name : onRotateRight
931 // Purpose : Performs incremental rotating to the right
932 //=======================================================================
937 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
940 //=======================================================================
942 // Purpose : Performs incremental rotating to the top
943 //=======================================================================
948 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
951 //=======================================================================
954 ::onKeyPressed(QKeyEvent* event)
956 emit keyPressed( this, event );
959 //=======================================================================
962 ::onKeyReleased(QKeyEvent* event)
964 emit keyReleased( this, event );
967 //=======================================================================
970 ::onMousePressed(QMouseEvent* event)
972 emit mousePressed(this, event);
975 //=======================================================================
978 ::onMouseReleased(QMouseEvent* event)
980 emit mouseReleased( this, event );
983 //=======================================================================
986 ::onMouseMoving(QMouseEvent* event)
988 emit mouseMoving( this, event );
991 //=======================================================================
994 ::onMouseDoubleClicked( QMouseEvent* event )
996 emit mouseDoubleClicked( this, event );
999 //=======================================================================
1000 // name : onRotateDown
1001 // Purpose : Performs incremental rotating to the bottom
1002 //=======================================================================
1007 myRWInteractor->GetSInteractorStyle()->IncrementalRotate( 0, INCREMENT_FOR_OP );
1010 //----------------------------------------------------------------------------
1013 ::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors )
1015 theActor->AddToRender(myRenderer);
1016 theActor->SetTransform(myTransform);
1017 if(theMoveInternalActors)
1018 myRWInteractor->MoveInternalActors();
1021 //----------------------------------------------------------------------------
1024 ::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1026 InsertActor(theActor);
1031 //----------------------------------------------------------------------------
1034 ::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ )
1036 theActor->RemoveFromRender(myRenderer);
1041 //----------------------------------------------------------------------------
1044 ::MoveActor( SALOME_Actor* theActor)
1046 RemoveActor(theActor);
1047 InsertActor(theActor,true);
1050 //----------------------------------------------------------------------------
1055 QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
1056 return px.convertToImage();
1059 //----------------------------------------------------------------------------
1062 ::action( const int theAction )
1064 switch ( theAction ) {
1065 case SUIT_Accel::PanLeft : onPanLeft(); break;
1066 case SUIT_Accel::PanRight : onPanRight(); break;
1067 case SUIT_Accel::PanUp : onPanUp(); break;
1068 case SUIT_Accel::PanDown : onPanDown(); break;
1069 case SUIT_Accel::ZoomIn : onZoomIn(); break;
1070 case SUIT_Accel::ZoomOut : onZoomOut(); break;
1071 case SUIT_Accel::ZoomFit : onFitAll(); break;
1072 case SUIT_Accel::RotateLeft : onRotateLeft(); break;
1073 case SUIT_Accel::RotateRight : onRotateRight(); break;
1074 case SUIT_Accel::RotateUp : onRotateUp(); break;
1075 case SUIT_Accel::RotateDown : onRotateDown(); break;