1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VTKViewer_ViewFrame.cxx
25 // Author : Nicolas REJNERI
29 #include "VTKViewer_ViewFrame.h"
30 #include "VTKViewer_Utilities.h"
31 #include "VTKViewer_Trihedron.h"
32 #include "SALOME_CubeAxesActor2D.h"
33 #include "VTKViewer_RenderWindow.h"
34 #include "VTKViewer_RenderWindowInteractor.h"
35 #include "VTKViewer_InteractorStyleSALOME.h"
36 #include "VTKViewer_Algorithm.h"
37 #include "VTKViewer_Functor.h"
38 #include "VTKViewer_Prs.h"
40 #include "SALOME_Actor.h"
41 #include "SALOME_Transform.h"
42 #include "SALOME_TransformFilter.h"
43 #include "SALOME_GeometryFilter.h"
44 #include "SALOMEGUI.h"
46 #include "QAD_Settings.h"
47 #include "QAD_Config.h"
48 #include "QAD_Application.h"
49 #include "QAD_Desktop.h"
50 #include "SALOME_Selection.h"
51 #include "SALOME_InteractiveObject.hxx"
53 #include "SALOMEDS_Tool.hxx"
55 #include "utilities.h"
59 #include <qcolordialog.h>
60 #include <qfiledialog.h>
61 #include <qapplication.h>
65 #include <vtkCamera.h>
66 #include <vtkRenderer.h>
67 #include <vtkTransform.h>
68 #include <vtkActorCollection.h>
69 #include <vtkTextProperty.h>
71 #include <TColStd_IndexedMapOfInteger.hxx>
74 static int MYDEBUG = 0;
76 static int MYDEBUG = 0;
84 VTKViewer_ViewFrame::VTKViewer_ViewFrame(QWidget* parent, const char* name)
85 : QAD_ViewFrame(parent, name)
87 m_ViewUp[0] = 0; m_ViewUp[1] = 0; m_ViewUp[2] = -1;
88 m_ViewNormal[0] = 0; m_ViewNormal[1] = 0; m_ViewNormal[2] = 1;
89 m_Triedron = VTKViewer_Trihedron::New();
90 m_CubeAxes = SALOME_CubeAxesActor2D::New();
91 m_Transform = SALOME_Transform::New();
92 //m_Renderer = VTKViewer_Renderer::New() ;
93 m_Renderer = vtkRenderer::New() ;
95 m_Triedron->AddToRender(m_Renderer);
96 m_Renderer->AddProp(m_CubeAxes);
100 void VTKViewer_ViewFrame::InitialSetup() {
101 m_RW = new VTKViewer_RenderWindow(this, "RenderWindow");
102 m_RW->getRenderWindow()->AddRenderer(m_Renderer);
104 m_Renderer->GetActiveCamera()->ParallelProjectionOn();
105 m_Renderer->LightFollowCameraOn();
106 m_Renderer->TwoSidedLightingOn();
108 // Set BackgroundColor
109 QString BgrColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
110 QString BgrColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
111 QString BgrColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
113 if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
114 m_Renderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
116 m_Renderer->SetBackground( 0, 0, 0 );
118 // Create an interactor.
119 m_RWInteractor = VTKViewer_RenderWindowInteractor::New();
120 m_RWInteractor->SetRenderWindow(m_RW->getRenderWindow());
122 VTKViewer_InteractorStyleSALOME* RWS = VTKViewer_InteractorStyleSALOME::New();
123 m_RWInteractor->SetInteractorStyle(RWS);
126 m_RWInteractor->setGUIWindow(m_RW);
127 RWS->setGUIWindow(m_RW);
129 m_RWInteractor->Initialize();
130 m_RWInteractor->setViewFrame(this);
132 RWS->setViewFrame(this);
133 //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
134 RWS->FindPokedRenderer(0, 0);
136 vtkTextProperty* tprop = vtkTextProperty::New();
137 tprop->SetColor(1, 1, 1);
141 bnd[0] = bnd[2] = bnd[4] = 0;
142 bnd[1] = bnd[3] = bnd[5] = m_Triedron->GetSize();
143 m_CubeAxes->SetLabelFormat("%6.4g");
144 m_CubeAxes->SetBounds(bnd);
145 m_CubeAxes->SetCamera(m_Renderer->GetActiveCamera());
146 m_CubeAxes->SetLabelFormat("%6.4g");
147 m_CubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
148 m_CubeAxes->SetFontFactor(0.8);
149 m_CubeAxes->SetAxisTitleTextProperty(tprop);
150 m_CubeAxes->SetAxisLabelTextProperty(tprop);
151 m_CubeAxes->SetCornerOffset(0.0);
152 m_CubeAxes->SetScaling(0);
153 m_CubeAxes->SetNumberOfLabels(10);
156 setCentralWidget( m_RW );
160 VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
161 // In order to ensure that the interactor unregisters
162 // this RenderWindow, we assign a NULL RenderWindow to
163 // it before deleting it.
164 m_RWInteractor->SetRenderWindow(NULL) ;
165 m_RWInteractor->Delete() ;
167 m_Transform->Delete() ;
169 m_Renderer->RemoveAllProps();
170 // NRI : BugID 1137: m_Renderer->Delete() ;
171 m_Triedron->Delete();
173 m_CubeAxes->Delete();
174 INFOS("VTKViewer_ViewFrame::~VTKViewer_ViewFrame()");
178 Returns widget containing 3D-Viewer
180 QWidget* VTKViewer_ViewFrame::getViewWidget(){
184 bool VTKViewer_ViewFrame::isTrihedronDisplayed(){
185 return m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
188 bool VTKViewer_ViewFrame::isCubeAxesDisplayed(){
189 return m_CubeAxes->GetVisibility() == 1;
192 bool VTKViewer_ViewFrame::ComputeTrihedronSize( double& theNewSize, double& theSize )
194 // calculating diagonal of visible props of the renderer
196 m_Triedron->VisibilityOff();
197 if ( ::ComputeVisiblePropBounds( m_Renderer, bnd ) == 0 )
199 bnd[ 1 ] = bnd[ 3 ] = bnd[ 5 ] = 100;
200 bnd[ 0 ] = bnd[ 2 ] = bnd[ 100 ] = 0;
202 m_Triedron->VisibilityOn();
204 static bool CalcByDiag = false;
207 aLength = sqrt( ( bnd[1]-bnd[0])*(bnd[1]-bnd[0] )+
208 ( bnd[3]-bnd[2])*(bnd[3]-bnd[2] )+
209 ( bnd[5]-bnd[4])*(bnd[5]-bnd[4] ) );
213 aLength = bnd[ 1 ]-bnd[ 0 ];
214 aLength = max( ( bnd[ 3 ] - bnd[ 2 ] ),aLength );
215 aLength = max( ( bnd[ 5 ] - bnd[ 4 ] ),aLength );
218 static float aSizeInPercents = 105;
219 QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
220 if ( !aSetting.isEmpty() )
221 aSizeInPercents = aSetting.toFloat();
223 static float EPS_SIZE = 5.0E-3;
224 theSize = m_Triedron->GetSize();
225 theNewSize = aLength * aSizeInPercents / 100.0;
227 // if the new trihedron size have sufficient difference, then apply the value
228 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
229 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
232 double VTKViewer_ViewFrame::GetTrihedronSize() const
234 return m_Triedron->GetSize();
237 void VTKViewer_ViewFrame::AdjustTrihedrons( const bool forcedUpdate )
240 if ( !isCubeAxesDisplayed() && !isTrihedronDisplayed() && !forcedUpdate )
245 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
246 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
248 m_CubeAxes->GetBounds(bnd);
250 cout << "Bounds: BEFORE\n"
251 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
252 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
253 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
255 int aVisibleNum = m_Triedron->GetVisibleActorCount( m_Renderer );
256 if ( aVisibleNum || forcedUpdate )
258 // if the new trihedron size have sufficient difference, then apply the value
259 double aNewSize = 100, anOldSize;
260 if ( ComputeTrihedronSize( aNewSize, anOldSize ) || forcedUpdate )
262 m_Triedron->SetSize( aNewSize );
263 // itearte throuh displayed objects and set size if necessary
265 vtkActorCollection* anActors = getRenderer()->GetActors();
266 anActors->InitTraversal();
267 while( vtkActor* anActor = anActors->GetNextActor() )
269 if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
271 if ( aSActor->IsResizable() )
272 aSActor->SetSize( 0.5 * aNewSize );
273 if( aSActor->GetVisibility()){
275 aSActor->GetBounds(abounds);
277 cout << "Bounds: Actor="<<aSActor<<"\n"
278 << "\txMin=" << abounds[ 0 ] << " xMax=" << abounds[ 1 ] << "\n"
279 << "\tyMin=" << abounds[ 2 ] << " yMax=" << abounds[ 3 ] << "\n"
280 << "\tzMin=" << abounds[ 4 ] << " zMax=" << abounds[ 5 ] << "\n";
281 if ( abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
282 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
283 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
284 for(int i=0;i<5;i=i+2){
285 if(abounds[i]<newbnd[i]) newbnd[i]=abounds[i];
286 if(abounds[i+1]>newbnd[i+1]) newbnd[i+1]=abounds[i+1];
294 if( newbnd[0]<VTK_LARGE_FLOAT && newbnd[2]<VTK_LARGE_FLOAT && newbnd[4]<VTK_LARGE_FLOAT &&
295 newbnd[1]>-VTK_LARGE_FLOAT && newbnd[3]>-VTK_LARGE_FLOAT && newbnd[5]>-VTK_LARGE_FLOAT){
296 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
297 m_CubeAxes->SetBounds(bnd);
300 cout << "Bounds AFTER: VisibleActors="<<aVisibleNum<<"\n"
301 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
302 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
303 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
305 m_CubeAxes->SetBounds(bnd);
307 ::ResetCameraClippingRange(m_Renderer);
310 void VTKViewer_ViewFrame::AdjustAxes( const bool forcedUpdate )
312 AdjustTrihedrons(forcedUpdate);
315 void VTKViewer_ViewFrame::onAdjustTrihedron()
317 AdjustTrihedrons( false );
320 void VTKViewer_ViewFrame::onAdjustAxes()
326 Display/hide Trihedron
328 void VTKViewer_ViewFrame::onViewTrihedron(){
329 if(!m_Triedron) return;
330 if(isTrihedronDisplayed()){
331 m_Triedron->VisibilityOff();
332 m_CubeAxes->VisibilityOff();
335 m_Triedron->VisibilityOn();
336 m_CubeAxes->VisibilityOn();
342 Provides top projection of the active view
344 void VTKViewer_ViewFrame::onViewTop(){
345 vtkCamera* camera = m_Renderer->GetActiveCamera();
346 camera->SetPosition(0,0,1);
347 camera->SetViewUp(0,1,0);
348 camera->SetFocalPoint(0,0,0);
353 Provides bottom projection of the active view
355 void VTKViewer_ViewFrame::onViewBottom(){
356 vtkCamera* camera = m_Renderer->GetActiveCamera();
357 camera->SetPosition(0,0,-1);
358 camera->SetViewUp(0,1,0);
359 camera->SetFocalPoint(0,0,0);
364 Provides left projection of the active view
366 void VTKViewer_ViewFrame::onViewLeft(){
367 vtkCamera* camera = m_Renderer->GetActiveCamera();
368 camera->SetPosition(0,-1,0);
369 camera->SetViewUp(0,0,1);
370 camera->SetFocalPoint(0,0,0);
375 Provides right projection of the active view
377 void VTKViewer_ViewFrame::onViewRight(){
378 vtkCamera* camera = m_Renderer->GetActiveCamera();
379 camera->SetPosition(0,1,0);
380 camera->SetViewUp(0,0,1);
381 camera->SetFocalPoint(0,0,0);
386 Provides back projection of the active view
388 void VTKViewer_ViewFrame::onViewBack(){
389 vtkCamera* camera = m_Renderer->GetActiveCamera();
390 camera->SetPosition(-1,0,0);
391 camera->SetViewUp(0,0,1);
392 camera->SetFocalPoint(0,0,0);
397 Provides front projection of the active view
399 void VTKViewer_ViewFrame::onViewFront(){
400 vtkCamera* camera = m_Renderer->GetActiveCamera();
401 camera->SetPosition(1,0,0);
402 camera->SetViewUp(0,0,1);
403 camera->SetFocalPoint(0,0,0);
408 Fits all objects in the active view
410 void VTKViewer_ViewFrame::onViewFitAll(){
412 int aTriedronWasVisible = false;
413 int aCubeAxesWasVisible = false;
415 aTriedronWasVisible = m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
416 if(aTriedronWasVisible) m_Triedron->VisibilityOff();
419 aCubeAxesWasVisible = m_CubeAxes->GetVisibility();
420 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff();
423 if(m_Triedron->GetVisibleActorCount(m_Renderer)){
424 m_Triedron->VisibilityOff();
425 m_CubeAxes->VisibilityOff();
426 ::ResetCamera(m_Renderer);
428 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
429 m_CubeAxes->SetVisibility(2);
430 ::ResetCamera(m_Renderer,true);
432 if(aTriedronWasVisible) m_Triedron->VisibilityOn();
433 else m_Triedron->VisibilityOff();
434 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOn();
435 else m_CubeAxes->VisibilityOff();
436 ::ResetCameraClippingRange(m_Renderer);
442 Reset the active view
444 void VTKViewer_ViewFrame::onViewReset(){
445 int aTriedronIsVisible = isTrihedronDisplayed();
446 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
447 m_CubeAxes->SetVisibility(2);
448 ::ResetCamera(m_Renderer,true);
449 vtkCamera* aCamera = m_Renderer->GetActiveCamera();
450 aCamera->SetPosition(1,-1,1);
451 aCamera->SetViewUp(0,0,1);
452 ::ResetCamera(m_Renderer,true);
453 if(aTriedronIsVisible){
454 m_Triedron->VisibilityOn();
455 m_CubeAxes->VisibilityOn();
458 m_Triedron->VisibilityOff();
459 m_CubeAxes->VisibilityOff();
461 static float aCoeff = 3.0;
462 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
467 Rotates the active view
469 void VTKViewer_ViewFrame::onViewRotate(){
470 m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
474 Sets a new center of the active view
476 void VTKViewer_ViewFrame::onViewGlobalPan(){
477 if(m_Triedron->GetVisibleActorCount(m_Renderer))
478 m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
482 Zooms the active view
484 void VTKViewer_ViewFrame::onViewZoom(){
485 m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
489 Moves the active view
491 void VTKViewer_ViewFrame::onViewPan(){
492 m_RWInteractor->GetInteractorStyleSALOME()->startPan();
496 Fits all obejcts within a rectangular area of the active view
498 void VTKViewer_ViewFrame::onViewFitArea(){
499 m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
503 Set background of the viewport
505 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
508 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
512 Returns background of the viewport
514 QColor VTKViewer_ViewFrame::backgroundColor() const
518 m_Renderer->GetBackground(backint);
519 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
521 return QMainWindow::backgroundColor();
525 void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
527 m_RWInteractor->SetSelectionMode( mode );
530 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
532 m_RWInteractor->rename(IObject, newName);
535 void VTKViewer_ViewFrame::unHighlightAll()
537 m_RWInteractor->unHighlightAll();
540 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
544 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
545 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
546 m_RWInteractor->highlight(IObject, highlight, update);
548 if(Sel->HasIndex(IObject) && IObject->hasEntry()){
549 TColStd_IndexedMapOfInteger MapIndex;
550 Sel->GetIndex(IObject,MapIndex);
551 using namespace SALOME::VTK;
552 const char* anEntry = IObject->getEntry();
553 vtkActorCollection* aCollection = getRenderer()->GetActors();
554 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
555 switch (Sel->SelectionMode()) {
557 m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
559 case EdgeOfCellSelection:
560 m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
565 case VolumeSelection:
566 m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
571 m_RWInteractor->unHighlightSubSelection();
575 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
577 return m_RWInteractor->isInViewer( IObject );
580 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
582 return m_RWInteractor->isVisible( IObject );
585 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
587 m_RW->setPopupServer( App );
591 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
593 using namespace SALOME::VTK;
594 SALOME_Actor* anActor =
595 Find<SALOME_Actor>(getRenderer()->GetActors(),
596 TIsSameEntry<SALOME_Actor>(theEntry));
598 return anActor->getIO();
600 return Handle(SALOME_InteractiveObject)();
604 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
606 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
607 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
608 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
610 m_RWInteractor->Display(theIObject,false);
611 ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
612 aSel->AddIObject(theIObject,false);
619 struct TDisplayAction{
620 SALOME_Selection* mySel;
621 Handle(SALOME_InteractiveObject) myIO;
622 TDisplayAction(SALOME_Selection* theSel,
623 Handle(SALOME_InteractiveObject) theIO):
624 mySel(theSel), myIO(theIO)
626 void operator()(SALOME_Actor* theActor){
627 theActor->SetVisibility(true);
628 mySel->AddIObject(myIO,false);
632 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
634 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
635 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
637 aSel->ClearIObjects();
638 //m_RWInteractor->EraseAll();
641 using namespace SALOME::VTK;
642 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
643 TIsSameIObject<SALOME_Actor>(theIObject),
644 TDisplayAction(aSel,theIObject));
646 ToolsGUI::SetVisibility(
647 aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
653 struct TEraseAction: TDisplayAction{
654 VTKViewer_RenderWindowInteractor* myRWInteractor;
655 TEraseAction(SALOME_Selection* theSel,
656 Handle(SALOME_InteractiveObject) theIO,
657 VTKViewer_RenderWindowInteractor* theRWInteractor):
658 TDisplayAction(theSel,theIO),
659 myRWInteractor(theRWInteractor)
661 void operator()(SALOME_Actor* theActor){
662 myRWInteractor->Erase(myIO,false);
663 mySel->RemoveIObject(myIO,false);
667 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
669 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
670 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
672 using namespace SALOME::VTK;
673 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
674 TIsSameIObject<SALOME_Actor>(theIObject),
675 TEraseAction(aSel,theIObject,m_RWInteractor));
677 ToolsGUI::SetVisibility(
678 aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
685 void VTKViewer_ViewFrame::DisplayAll()
687 m_RWInteractor->DisplayAll();
689 // update flag of visibility
690 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
691 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
692 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
693 const QString& aCompName = aDesktop->getComponentDataType();
694 SALOMEDS::SObject_var aComponent =
695 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
697 std::list<SALOMEDS::SObject_var> aList;
698 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
700 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
701 for ( ; anIter != aList.end(); ++anIter )
702 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
706 void VTKViewer_ViewFrame::EraseAll()
708 m_RWInteractor->EraseAll();
710 // update flag of visibility
711 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
712 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
713 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
714 const QString& aCompName = aDesktop->getComponentDataType();
715 SALOMEDS::SObject_var aComponent =
716 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
718 std::list<SALOMEDS::SObject_var> aList;
719 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
721 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
722 for ( ; anIter != aList.end(); ++anIter )
723 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
727 void VTKViewer_ViewFrame::Repaint(bool theUpdateAxes)
729 if (theUpdateAxes) onAdjustAxes();
733 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
734 m_Transform->GetScale(theScale);
737 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
738 m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
739 m_RWInteractor->Render();
743 void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
744 theActor->AddToRender(m_Renderer);
745 theActor->SetTransform(m_Transform);
746 if(theMoveInternalActors)
747 m_RWInteractor->MoveInternalActors();
750 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
751 InsertActor(theActor);
756 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
757 theActor->RemoveFromRender(m_Renderer);
762 void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
764 RemoveActor(theActor);
765 InsertActor(theActor,true);
768 //==========================================================
770 * VTKViewer_ViewFrame::Display
771 * Display presentation
773 //==========================================================
774 void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
776 // try do downcast object
777 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
778 if ( !aVTKPrs || aVTKPrs->IsNull() )
781 vtkActorCollection* actors = aVTKPrs->GetObjects();
785 actors->InitTraversal();
787 while( ( actor = actors->GetNextActor() ) )
789 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
792 // just display the object
793 m_RWInteractor->Display( salomeActor, false );
795 // Set visibility flag
796 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
797 if ( !anObj.IsNull() && anObj->hasEntry() )
799 SALOMEDS::Study_var aStudy =
800 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
801 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
804 if ( salomeActor->IsSetCamera() )
805 salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
810 //==========================================================
812 * VTKViewer_ViewFrame::Erase
815 //==========================================================
816 void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
818 // try do downcast object
819 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
820 if ( !aVTKPrs || aVTKPrs->IsNull() )
823 vtkActorCollection* actors = aVTKPrs->GetObjects();
827 SALOMEDS::Study_var aStudy =
828 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
830 actors->InitTraversal();
832 while( ( actor = actors->GetNextActor() ) ) {
833 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
835 // just erase the object
837 m_RWInteractor->Remove( salomeActor, false );
839 m_RWInteractor->Erase( salomeActor, forced );
841 // Set visibility flag if necessary
844 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
845 if ( !anObj.IsNull() && anObj->hasEntry() )
846 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
852 //==========================================================
854 * VTKViewer_ViewFrame::CreatePrs
855 * Create presentation by entry
857 //==========================================================
858 SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
860 VTKViewer_Prs* prs = new VTKViewer_Prs();
862 vtkActorCollection* theActors = m_Renderer->GetActors();
863 theActors->InitTraversal();
865 while( ( ac = theActors->GetNextActor() ) ) {
866 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
867 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
868 prs->AddObject( ac );
875 //==========================================================
877 * VTKViewer_ViewFrame::BeforeDisplay
878 * Axiluary method called before displaying of objects
880 //==========================================================
881 void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
883 d->BeforeDisplay( this, SALOME_VTKViewType() );
886 //==========================================================
888 * VTKViewer_ViewFrame::AfterDisplay
889 * Axiluary method called after displaying of objects
891 //==========================================================
892 void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
894 d->AfterDisplay( this, SALOME_VTKViewType() );
897 //==========================================================
899 * VTKViewer_ViewFrame::undo
900 * Redisplay all objects in viewer
902 //==========================================================
903 void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
905 redisplayAll( theQADStudy, true );
908 //==========================================================
910 * VTKViewer_ViewFrame::redo
911 * Redisplay all objects in viewer
913 //==========================================================
914 void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
916 redisplayAll( theQADStudy, true );
919 //==========================================================
921 * VTKViewer_ViewFrame::redisplayAll
922 * Redisplay all objects in viewer
924 //==========================================================
925 void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
927 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
928 SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
929 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
930 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
931 const QString& aCompName = aDesktop->getComponentDataType();
932 SALOMEDS::SObject_var aComponent =
933 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
935 if ( aComponent->_is_nil() )
938 // bool isTrhDisplayed = isTrihedronDisplayed();
939 // bool isCubeDisplayed = isCubeAxesDisplayed();
941 m_RWInteractor->RemoveAll( false );
942 //m_RWInteractor->EraseAll();
944 aSel->ClearIObjects();
947 // ENK commented, already added to renderer in
948 // VTKViewer_ViewFrame::VTKViewer_ViewFrame(...)
949 if ( isTrhDisplayed )
950 m_Triedron->AddToRender( m_Renderer );
953 std::list<SALOMEDS::SObject_var> aList;
954 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
956 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
957 for ( ; anIter != aList.end(); ++anIter )
959 SALOMEDS::SObject_var anObj = (*anIter);
960 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
962 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
963 anIObj->setEntry( anObj->GetID() );
964 aGUI->BuildPresentation( anIObj, this );
973 #define INCREMENT_FOR_OP 10
975 //=======================================================================
977 // Purpose : Performs incremental panning to the left
978 //=======================================================================
979 void VTKViewer_ViewFrame::onPanLeft()
981 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
984 //=======================================================================
986 // Purpose : Performs incremental panning to the right
987 //=======================================================================
988 void VTKViewer_ViewFrame::onPanRight()
990 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
993 //=======================================================================
995 // Purpose : Performs incremental panning to the top
996 //=======================================================================
997 void VTKViewer_ViewFrame::onPanUp()
999 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
1002 //=======================================================================
1004 // Purpose : Performs incremental panning to the bottom
1005 //=======================================================================
1006 void VTKViewer_ViewFrame::onPanDown()
1008 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
1011 //=======================================================================
1013 // Purpose : Performs incremental zooming in
1014 //=======================================================================
1015 void VTKViewer_ViewFrame::onZoomIn()
1017 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
1020 //=======================================================================
1022 // Purpose : Performs incremental zooming out
1023 //=======================================================================
1024 void VTKViewer_ViewFrame::onZoomOut()
1026 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
1029 //=======================================================================
1030 // name : onRotateLeft
1031 // Purpose : Performs incremental rotating to the left
1032 //=======================================================================
1033 void VTKViewer_ViewFrame::onRotateLeft()
1035 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
1038 //=======================================================================
1039 // name : onRotateRight
1040 // Purpose : Performs incremental rotating to the right
1041 //=======================================================================
1042 void VTKViewer_ViewFrame::onRotateRight()
1044 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
1047 //=======================================================================
1048 // name : onRotateUp
1049 // Purpose : Performs incremental rotating to the top
1050 //=======================================================================
1051 void VTKViewer_ViewFrame::onRotateUp()
1053 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
1056 //=======================================================================
1057 // name : onRotateDown
1058 // Purpose : Performs incremental rotating to the bottom
1059 //=======================================================================
1060 void VTKViewer_ViewFrame::onRotateDown()
1062 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );