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 "VTKViewer_RenderWindow.h"
33 #include "VTKViewer_RenderWindowInteractor.h"
34 #include "VTKViewer_InteractorStyleSALOME.h"
35 #include "VTKViewer_Algorithm.h"
36 #include "VTKViewer_Functor.h"
37 #include "VTKViewer_Prs.h"
39 #include "SALOME_Actor.h"
40 #include "SALOME_Transform.h"
41 #include "SALOME_TransformFilter.h"
42 #include "SALOME_GeometryFilter.h"
43 #include "SALOMEGUI.h"
45 #include "QAD_Settings.h"
46 #include "QAD_Config.h"
47 #include "QAD_Application.h"
48 #include "QAD_Desktop.h"
49 #include "SALOME_Selection.h"
50 #include "SALOME_InteractiveObject.hxx"
52 #include "SALOMEDS_Tool.hxx"
54 #include "utilities.h"
58 #include <qcolordialog.h>
59 #include <qfiledialog.h>
60 #include <qapplication.h>
64 #include <vtkCamera.h>
65 #include <vtkRenderer.h>
66 #include <vtkTransform.h>
67 #include <vtkActorCollection.h>
69 #include <TColStd_IndexedMapOfInteger.hxx>
76 VTKViewer_ViewFrame::VTKViewer_ViewFrame(QWidget* parent, const char* name)
77 : QAD_ViewFrame(parent, name)
79 m_ViewUp[0] = 0; m_ViewUp[1] = 0; m_ViewUp[2] = -1;
80 m_ViewNormal[0] = 0; m_ViewNormal[1] = 0; m_ViewNormal[2] = 1;
81 m_Triedron = VTKViewer_Trihedron::New();
82 m_Transform = SALOME_Transform::New();
83 //m_Renderer = VTKViewer_Renderer::New() ;
84 m_Renderer = vtkRenderer::New() ;
86 m_Triedron->AddToRender(m_Renderer);
90 void VTKViewer_ViewFrame::InitialSetup() {
91 m_RW = new VTKViewer_RenderWindow(this, "RenderWindow");
92 m_RW->getRenderWindow()->AddRenderer(m_Renderer);
94 m_Renderer->GetActiveCamera()->ParallelProjectionOn();
95 m_Renderer->LightFollowCameraOn();
96 m_Renderer->TwoSidedLightingOn();
98 // Set BackgroundColor
99 QString BgrColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
100 QString BgrColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
101 QString BgrColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
103 if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
104 m_Renderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
106 m_Renderer->SetBackground( 0, 0, 0 );
108 // Create an interactor.
109 m_RWInteractor = VTKViewer_RenderWindowInteractor::New();
110 m_RWInteractor->SetRenderWindow(m_RW->getRenderWindow());
112 VTKViewer_InteractorStyleSALOME* RWS = VTKViewer_InteractorStyleSALOME::New();
113 m_RWInteractor->SetInteractorStyle(RWS);
116 m_RWInteractor->setGUIWindow(m_RW);
117 RWS->setGUIWindow(m_RW);
119 m_RWInteractor->Initialize();
120 m_RWInteractor->setViewFrame(this);
121 RWS->setTriedron(m_Triedron);
122 RWS->setViewFrame(this);
123 //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
124 RWS->FindPokedRenderer(0, 0);
126 setCentralWidget( m_RW );
130 VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
131 // In order to ensure that the interactor unregisters
132 // this RenderWindow, we assign a NULL RenderWindow to
133 // it before deleting it.
134 m_RWInteractor->SetRenderWindow(NULL) ;
135 m_RWInteractor->Delete() ;
137 m_Transform->Delete() ;
139 m_Renderer->RemoveAllProps();
140 // NRI : BugID 1137: m_Renderer->Delete() ;
141 m_Triedron->Delete();
142 INFOS("VTKViewer_ViewFrame::~VTKViewer_ViewFrame()");
146 Returns widget containing 3D-Viewer
148 QWidget* VTKViewer_ViewFrame::getViewWidget(){
152 bool VTKViewer_ViewFrame::isTrihedronDisplayed(){
153 return m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
156 bool VTKViewer_ViewFrame::ComputeTrihedronSize( double& theNewSize, double& theSize )
158 // calculating diagonal of visible props of the renderer
160 m_Triedron->VisibilityOff();
161 if ( ::ComputeVisiblePropBounds( m_Renderer, bnd ) == 0 )
163 bnd[ 1 ] = bnd[ 3 ] = bnd[ 5 ] = 100;
164 bnd[ 0 ] = bnd[ 2 ] = bnd[ 100 ] = 0;
166 m_Triedron->VisibilityOn();
168 static bool CalcByDiag = false;
171 aLength = sqrt( ( bnd[1]-bnd[0])*(bnd[1]-bnd[0] )+
172 ( bnd[3]-bnd[2])*(bnd[3]-bnd[2] )+
173 ( bnd[5]-bnd[4])*(bnd[5]-bnd[4] ) );
177 aLength = bnd[ 1 ]-bnd[ 0 ];
178 aLength = max( ( bnd[ 3 ] - bnd[ 2 ] ),aLength );
179 aLength = max( ( bnd[ 5 ] - bnd[ 4 ] ),aLength );
182 static float aSizeInPercents = 105;
183 QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
184 if ( !aSetting.isEmpty() )
185 aSizeInPercents = aSetting.toFloat();
187 static float EPS_SIZE = 5.0E-3;
188 theSize = m_Triedron->GetSize();
189 theNewSize = aLength * aSizeInPercents / 100.0;
191 // if the new trihedron size have sufficient difference, then apply the value
192 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
193 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
196 double VTKViewer_ViewFrame::GetTrihedronSize() const
198 return m_Triedron->GetSize();
201 void VTKViewer_ViewFrame::AdjustTrihedrons( const bool forcedUpdate )
203 if ( !isTrihedronDisplayed() && !forcedUpdate )
206 int aVisibleNum = m_Triedron->GetVisibleActorCount( m_Renderer );
207 if ( aVisibleNum || forcedUpdate )
209 // if the new trihedron size have sufficient difference, then apply the value
210 double aNewSize = 100, anOldSize;
211 if ( ComputeTrihedronSize( aNewSize, anOldSize ) || forcedUpdate )
213 m_Triedron->SetSize( aNewSize );
214 // itearte throuh displayed objects and set size if necessary
216 vtkActorCollection* anActors = getRenderer()->GetActors();
217 anActors->InitTraversal();
218 while( vtkActor* anActor = anActors->GetNextActor() )
220 if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
222 if ( aSActor->IsResizable() )
223 aSActor->SetSize( 0.5 * aNewSize );
229 ::ResetCameraClippingRange(m_Renderer);
232 void VTKViewer_ViewFrame::onAdjustTrihedron()
234 AdjustTrihedrons( false );
238 Display/hide Trihedron
240 void VTKViewer_ViewFrame::onViewTrihedron(){
241 if(!m_Triedron) return;
242 if(isTrihedronDisplayed())
243 m_Triedron->VisibilityOff();
245 m_Triedron->VisibilityOn();
251 Provides top projection of the active view
253 void VTKViewer_ViewFrame::onViewTop(){
254 vtkCamera* camera = m_Renderer->GetActiveCamera();
255 camera->SetPosition(0,0,1);
256 camera->SetViewUp(0,1,0);
257 camera->SetFocalPoint(0,0,0);
262 Provides bottom projection of the active view
264 void VTKViewer_ViewFrame::onViewBottom(){
265 vtkCamera* camera = m_Renderer->GetActiveCamera();
266 camera->SetPosition(0,0,-1);
267 camera->SetViewUp(0,1,0);
268 camera->SetFocalPoint(0,0,0);
273 Provides left projection of the active view
275 void VTKViewer_ViewFrame::onViewLeft(){
276 vtkCamera* camera = m_Renderer->GetActiveCamera();
277 camera->SetPosition(0,-1,0);
278 camera->SetViewUp(0,0,1);
279 camera->SetFocalPoint(0,0,0);
284 Provides right projection of the active view
286 void VTKViewer_ViewFrame::onViewRight(){
287 vtkCamera* camera = m_Renderer->GetActiveCamera();
288 camera->SetPosition(0,1,0);
289 camera->SetViewUp(0,0,1);
290 camera->SetFocalPoint(0,0,0);
295 Provides back projection of the active view
297 void VTKViewer_ViewFrame::onViewBack(){
298 vtkCamera* camera = m_Renderer->GetActiveCamera();
299 camera->SetPosition(-1,0,0);
300 camera->SetViewUp(0,0,1);
301 camera->SetFocalPoint(0,0,0);
306 Provides front projection of the active view
308 void VTKViewer_ViewFrame::onViewFront(){
309 vtkCamera* camera = m_Renderer->GetActiveCamera();
310 camera->SetPosition(1,0,0);
311 camera->SetViewUp(0,0,1);
312 camera->SetFocalPoint(0,0,0);
317 Fits all objects in the active view
319 void VTKViewer_ViewFrame::onViewFitAll(){
320 m_RWInteractor->GetInteractorStyleSALOME()->ViewFitAll();
325 Reset the active view
327 void VTKViewer_ViewFrame::onViewReset(){
328 int aTriedronIsVisible = isTrihedronDisplayed();
329 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
330 ::ResetCamera(m_Renderer,true);
331 vtkCamera* aCamera = m_Renderer->GetActiveCamera();
332 aCamera->SetPosition(1,-1,1);
333 aCamera->SetViewUp(0,0,1);
334 ::ResetCamera(m_Renderer,true);
335 if(aTriedronIsVisible) m_Triedron->VisibilityOn();
336 else m_Triedron->VisibilityOff();
337 static float aCoeff = 3.0;
338 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
343 Rotates the active view
345 void VTKViewer_ViewFrame::onViewRotate(){
346 m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
350 Sets a new center of the active view
352 void VTKViewer_ViewFrame::onViewGlobalPan(){
353 if(m_Triedron->GetVisibleActorCount(m_Renderer))
354 m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
358 Zooms the active view
360 void VTKViewer_ViewFrame::onViewZoom(){
361 m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
365 Moves the active view
367 void VTKViewer_ViewFrame::onViewPan(){
368 m_RWInteractor->GetInteractorStyleSALOME()->startPan();
372 Fits all obejcts within a rectangular area of the active view
374 void VTKViewer_ViewFrame::onViewFitArea(){
375 m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
379 Set background of the viewport
381 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
384 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
388 Returns background of the viewport
390 QColor VTKViewer_ViewFrame::backgroundColor() const
394 m_Renderer->GetBackground(backint);
395 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
397 return QMainWindow::backgroundColor();
401 void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
403 m_RWInteractor->SetSelectionMode( mode );
406 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
408 m_RWInteractor->rename(IObject, newName);
411 void VTKViewer_ViewFrame::unHighlightAll()
413 m_RWInteractor->unHighlightAll();
416 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
420 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
421 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
422 m_RWInteractor->highlight(IObject, highlight, update);
424 if(Sel->HasIndex(IObject) && IObject->hasEntry()){
425 TColStd_IndexedMapOfInteger MapIndex;
426 Sel->GetIndex(IObject,MapIndex);
427 using namespace SALOME::VTK;
428 const char* anEntry = IObject->getEntry();
429 vtkActorCollection* aCollection = getRenderer()->GetActors();
430 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
431 switch (Sel->SelectionMode()) {
433 m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
435 case EdgeOfCellSelection:
436 m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
441 case VolumeSelection:
442 m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
447 m_RWInteractor->unHighlightSubSelection();
451 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
453 return m_RWInteractor->isInViewer( IObject );
456 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
458 return m_RWInteractor->isVisible( IObject );
461 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
463 m_RW->setPopupServer( App );
467 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
469 using namespace SALOME::VTK;
470 SALOME_Actor* anActor =
471 Find<SALOME_Actor>(getRenderer()->GetActors(),
472 TIsSameEntry<SALOME_Actor>(theEntry));
474 return anActor->getIO();
476 return Handle(SALOME_InteractiveObject)();
480 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
482 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
483 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
484 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
486 m_RWInteractor->Display(theIObject,false);
487 ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
488 aSel->AddIObject(theIObject,false);
495 struct TDisplayAction{
496 SALOME_Selection* mySel;
497 Handle(SALOME_InteractiveObject) myIO;
498 TDisplayAction(SALOME_Selection* theSel,
499 Handle(SALOME_InteractiveObject) theIO):
500 mySel(theSel), myIO(theIO)
502 void operator()(SALOME_Actor* theActor){
503 theActor->SetVisibility(true);
504 mySel->AddIObject(myIO,false);
508 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
510 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
511 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
513 aSel->ClearIObjects();
514 //m_RWInteractor->EraseAll();
517 using namespace SALOME::VTK;
518 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
519 TIsSameIObject<SALOME_Actor>(theIObject),
520 TDisplayAction(aSel,theIObject));
522 ToolsGUI::SetVisibility(
523 aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
529 struct TEraseAction: TDisplayAction{
530 VTKViewer_RenderWindowInteractor* myRWInteractor;
531 TEraseAction(SALOME_Selection* theSel,
532 Handle(SALOME_InteractiveObject) theIO,
533 VTKViewer_RenderWindowInteractor* theRWInteractor):
534 TDisplayAction(theSel,theIO),
535 myRWInteractor(theRWInteractor)
537 void operator()(SALOME_Actor* theActor){
538 myRWInteractor->Erase(myIO,false);
539 mySel->RemoveIObject(myIO,false);
543 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
545 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
546 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
548 using namespace SALOME::VTK;
549 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
550 TIsSameIObject<SALOME_Actor>(theIObject),
551 TEraseAction(aSel,theIObject,m_RWInteractor));
553 ToolsGUI::SetVisibility(
554 aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
561 void VTKViewer_ViewFrame::DisplayAll()
563 m_RWInteractor->DisplayAll();
565 // update flag of visibility
566 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
567 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
568 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
569 const QString& aCompName = aDesktop->getComponentDataType();
570 SALOMEDS::SObject_var aComponent =
571 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
573 std::list<SALOMEDS::SObject_var> aList;
574 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
576 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
577 for ( ; anIter != aList.end(); ++anIter )
578 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
582 void VTKViewer_ViewFrame::EraseAll()
584 m_RWInteractor->EraseAll();
586 // update flag of visibility
587 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
588 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
589 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
590 const QString& aCompName = aDesktop->getComponentDataType();
591 SALOMEDS::SObject_var aComponent =
592 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
594 std::list<SALOMEDS::SObject_var> aList;
595 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
597 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
598 for ( ; anIter != aList.end(); ++anIter )
599 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
603 void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
605 if (theUpdateTrihedron) onAdjustTrihedron();
609 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
610 m_Transform->GetScale(theScale);
613 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
614 m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
615 m_RWInteractor->Render();
619 void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
620 theActor->AddToRender(m_Renderer);
621 theActor->SetTransform(m_Transform);
622 if(theMoveInternalActors)
623 m_RWInteractor->MoveInternalActors();
626 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
627 InsertActor(theActor);
632 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
633 theActor->RemoveFromRender(m_Renderer);
638 void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
640 RemoveActor(theActor);
641 InsertActor(theActor,true);
644 //==========================================================
646 * VTKViewer_ViewFrame::Display
647 * Display presentation
649 //==========================================================
650 void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
652 // try do downcast object
653 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
654 if ( !aVTKPrs || aVTKPrs->IsNull() )
657 vtkActorCollection* actors = aVTKPrs->GetObjects();
661 actors->InitTraversal();
663 while( ( actor = actors->GetNextActor() ) )
665 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
668 // just display the object
669 m_RWInteractor->Display( salomeActor, false );
671 // Set visibility flag
672 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
673 if ( !anObj.IsNull() && anObj->hasEntry() )
675 SALOMEDS::Study_var aStudy =
676 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
677 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
680 if ( salomeActor->IsSetCamera() )
681 salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
686 //==========================================================
688 * VTKViewer_ViewFrame::Erase
691 //==========================================================
692 void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
694 // try do downcast object
695 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
696 if ( !aVTKPrs || aVTKPrs->IsNull() )
699 vtkActorCollection* actors = aVTKPrs->GetObjects();
703 SALOMEDS::Study_var aStudy =
704 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
706 actors->InitTraversal();
708 while( ( actor = actors->GetNextActor() ) ) {
709 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
711 // just erase the object
713 m_RWInteractor->Remove( salomeActor, false );
715 m_RWInteractor->Erase( salomeActor, forced );
717 // Set visibility flag if necessary
720 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
721 if ( !anObj.IsNull() && anObj->hasEntry() )
722 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
728 //==========================================================
730 * VTKViewer_ViewFrame::CreatePrs
731 * Create presentation by entry
733 //==========================================================
734 SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
736 VTKViewer_Prs* prs = new VTKViewer_Prs();
738 vtkActorCollection* theActors = m_Renderer->GetActors();
739 theActors->InitTraversal();
741 while( ( ac = theActors->GetNextActor() ) ) {
742 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
743 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
744 prs->AddObject( ac );
751 //==========================================================
753 * VTKViewer_ViewFrame::BeforeDisplay
754 * Axiluary method called before displaying of objects
756 //==========================================================
757 void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
759 d->BeforeDisplay( this, SALOME_VTKViewType() );
762 //==========================================================
764 * VTKViewer_ViewFrame::AfterDisplay
765 * Axiluary method called after displaying of objects
767 //==========================================================
768 void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
770 d->AfterDisplay( this, SALOME_VTKViewType() );
773 //==========================================================
775 * VTKViewer_ViewFrame::undo
776 * Redisplay all objects in viewer
778 //==========================================================
779 void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
781 redisplayAll( theQADStudy, true );
784 //==========================================================
786 * VTKViewer_ViewFrame::redo
787 * Redisplay all objects in viewer
789 //==========================================================
790 void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
792 redisplayAll( theQADStudy, true );
795 //==========================================================
797 * VTKViewer_ViewFrame::redisplayAll
798 * Redisplay all objects in viewer
800 //==========================================================
801 void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
803 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
804 SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
805 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
806 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
807 const QString& aCompName = aDesktop->getComponentDataType();
808 SALOMEDS::SObject_var aComponent =
809 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
811 if ( aComponent->_is_nil() )
814 bool isTrhDisplayed = isTrihedronDisplayed();
816 m_RWInteractor->RemoveAll( false );
817 //m_RWInteractor->EraseAll();
819 aSel->ClearIObjects();
821 if ( isTrhDisplayed )
822 m_Triedron->AddToRender( m_Renderer );
824 std::list<SALOMEDS::SObject_var> aList;
825 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
827 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
828 for ( ; anIter != aList.end(); ++anIter )
830 SALOMEDS::SObject_var anObj = (*anIter);
831 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
833 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
834 anIObj->setEntry( anObj->GetID() );
835 aGUI->BuildPresentation( anIObj, this );
844 #define INCREMENT_FOR_OP 10
846 //=======================================================================
848 // Purpose : Performs incremental panning to the left
849 //=======================================================================
850 void VTKViewer_ViewFrame::onPanLeft()
852 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
855 //=======================================================================
857 // Purpose : Performs incremental panning to the right
858 //=======================================================================
859 void VTKViewer_ViewFrame::onPanRight()
861 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
864 //=======================================================================
866 // Purpose : Performs incremental panning to the top
867 //=======================================================================
868 void VTKViewer_ViewFrame::onPanUp()
870 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
873 //=======================================================================
875 // Purpose : Performs incremental panning to the bottom
876 //=======================================================================
877 void VTKViewer_ViewFrame::onPanDown()
879 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
882 //=======================================================================
884 // Purpose : Performs incremental zooming in
885 //=======================================================================
886 void VTKViewer_ViewFrame::onZoomIn()
888 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
891 //=======================================================================
893 // Purpose : Performs incremental zooming out
894 //=======================================================================
895 void VTKViewer_ViewFrame::onZoomOut()
897 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
900 //=======================================================================
901 // name : onRotateLeft
902 // Purpose : Performs incremental rotating to the left
903 //=======================================================================
904 void VTKViewer_ViewFrame::onRotateLeft()
906 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
909 //=======================================================================
910 // name : onRotateRight
911 // Purpose : Performs incremental rotating to the right
912 //=======================================================================
913 void VTKViewer_ViewFrame::onRotateRight()
915 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
918 //=======================================================================
920 // Purpose : Performs incremental rotating to the top
921 //=======================================================================
922 void VTKViewer_ViewFrame::onRotateUp()
924 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
927 //=======================================================================
928 // name : onRotateDown
929 // Purpose : Performs incremental rotating to the bottom
930 //=======================================================================
931 void VTKViewer_ViewFrame::onRotateDown()
933 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );