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);
93 connect(m_RW, SIGNAL(DumpView()), this, SLOT(onProcessViewDump()));
95 m_Renderer->GetActiveCamera()->ParallelProjectionOn();
96 m_Renderer->LightFollowCameraOn();
97 m_Renderer->TwoSidedLightingOn();
99 // Set BackgroundColor
100 QString BgrColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
101 QString BgrColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
102 QString BgrColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
104 if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
105 m_Renderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
107 m_Renderer->SetBackground( 0, 0, 0 );
109 // Create an interactor.
110 m_RWInteractor = VTKViewer_RenderWindowInteractor::New();
111 m_RWInteractor->SetRenderWindow(m_RW->getRenderWindow());
113 VTKViewer_InteractorStyleSALOME* RWS = VTKViewer_InteractorStyleSALOME::New();
114 m_RWInteractor->SetInteractorStyle(RWS);
117 m_RWInteractor->setGUIWindow(m_RW);
118 RWS->setGUIWindow(m_RW);
120 m_RWInteractor->Initialize();
121 m_RWInteractor->setViewFrame(this);
122 RWS->setTriedron(m_Triedron);
123 RWS->setViewFrame(this);
124 //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
125 RWS->FindPokedRenderer(0, 0);
127 setCentralWidget( m_RW );
131 VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
132 // In order to ensure that the interactor unregisters
133 // this RenderWindow, we assign a NULL RenderWindow to
134 // it before deleting it.
135 m_RWInteractor->SetRenderWindow(NULL) ;
136 m_RWInteractor->Delete() ;
138 m_Transform->Delete() ;
140 m_Renderer->RemoveAllProps();
141 // NRI : BugID 1137: m_Renderer->Delete() ;
142 m_Triedron->Delete();
143 INFOS("VTKViewer_ViewFrame::~VTKViewer_ViewFrame()");
147 Returns widget containing 3D-Viewer
149 QWidget* VTKViewer_ViewFrame::getViewWidget(){
153 bool VTKViewer_ViewFrame::isTrihedronDisplayed(){
154 return m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
157 bool VTKViewer_ViewFrame::ComputeTrihedronSize( double& theNewSize, double& theSize )
159 // calculating diagonal of visible props of the renderer
161 m_Triedron->VisibilityOff();
162 if ( ::ComputeVisiblePropBounds( m_Renderer, bnd ) == 0 )
164 bnd[ 1 ] = bnd[ 3 ] = bnd[ 5 ] = 100;
165 bnd[ 0 ] = bnd[ 2 ] = bnd[ 100 ] = 0;
167 m_Triedron->VisibilityOn();
169 static bool CalcByDiag = false;
172 aLength = sqrt( ( bnd[1]-bnd[0])*(bnd[1]-bnd[0] )+
173 ( bnd[3]-bnd[2])*(bnd[3]-bnd[2] )+
174 ( bnd[5]-bnd[4])*(bnd[5]-bnd[4] ) );
178 aLength = bnd[ 1 ]-bnd[ 0 ];
179 aLength = max( ( bnd[ 3 ] - bnd[ 2 ] ),aLength );
180 aLength = max( ( bnd[ 5 ] - bnd[ 4 ] ),aLength );
183 static float aSizeInPercents = 105;
184 QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
185 if ( !aSetting.isEmpty() )
186 aSizeInPercents = aSetting.toFloat();
188 static float EPS_SIZE = 5.0E-3;
189 theSize = m_Triedron->GetSize();
190 theNewSize = aLength * aSizeInPercents / 100.0;
192 // if the new trihedron size have sufficient difference, then apply the value
193 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
194 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
197 double VTKViewer_ViewFrame::GetTrihedronSize() const
199 return m_Triedron->GetSize();
202 void VTKViewer_ViewFrame::AdjustTrihedrons( const bool forcedUpdate )
204 if ( !isTrihedronDisplayed() && !forcedUpdate )
207 int aVisibleNum = m_Triedron->GetVisibleActorCount( m_Renderer );
208 if ( aVisibleNum || forcedUpdate )
210 // if the new trihedron size have sufficient difference, then apply the value
211 double aNewSize = 100, anOldSize;
212 if ( ComputeTrihedronSize( aNewSize, anOldSize ) || forcedUpdate )
214 m_Triedron->SetSize( aNewSize );
215 // itearte throuh displayed objects and set size if necessary
217 vtkActorCollection* anActors = getRenderer()->GetActors();
218 anActors->InitTraversal();
219 while( vtkActor* anActor = anActors->GetNextActor() )
221 if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
223 if ( aSActor->IsResizable() )
224 aSActor->SetSize( 0.5 * aNewSize );
230 ::ResetCameraClippingRange(m_Renderer);
233 void VTKViewer_ViewFrame::onAdjustTrihedron()
235 AdjustTrihedrons( false );
239 Display/hide Trihedron
241 void VTKViewer_ViewFrame::onViewTrihedron(){
242 if(!m_Triedron) return;
243 if(isTrihedronDisplayed())
244 m_Triedron->VisibilityOff();
246 m_Triedron->VisibilityOn();
252 Provides top projection of the active view
254 void VTKViewer_ViewFrame::onViewTop(){
255 vtkCamera* camera = m_Renderer->GetActiveCamera();
256 camera->SetPosition(0,0,1);
257 camera->SetViewUp(0,1,0);
258 camera->SetFocalPoint(0,0,0);
263 Provides bottom projection of the active view
265 void VTKViewer_ViewFrame::onViewBottom(){
266 vtkCamera* camera = m_Renderer->GetActiveCamera();
267 camera->SetPosition(0,0,-1);
268 camera->SetViewUp(0,1,0);
269 camera->SetFocalPoint(0,0,0);
274 Provides left projection of the active view
276 void VTKViewer_ViewFrame::onViewLeft(){
277 vtkCamera* camera = m_Renderer->GetActiveCamera();
278 camera->SetPosition(0,-1,0);
279 camera->SetViewUp(0,0,1);
280 camera->SetFocalPoint(0,0,0);
285 Provides right projection of the active view
287 void VTKViewer_ViewFrame::onViewRight(){
288 vtkCamera* camera = m_Renderer->GetActiveCamera();
289 camera->SetPosition(0,1,0);
290 camera->SetViewUp(0,0,1);
291 camera->SetFocalPoint(0,0,0);
296 Provides back projection of the active view
298 void VTKViewer_ViewFrame::onViewBack(){
299 vtkCamera* camera = m_Renderer->GetActiveCamera();
300 camera->SetPosition(-1,0,0);
301 camera->SetViewUp(0,0,1);
302 camera->SetFocalPoint(0,0,0);
307 Provides front projection of the active view
309 void VTKViewer_ViewFrame::onViewFront(){
310 vtkCamera* camera = m_Renderer->GetActiveCamera();
311 camera->SetPosition(1,0,0);
312 camera->SetViewUp(0,0,1);
313 camera->SetFocalPoint(0,0,0);
318 Fits all objects in the active view
320 void VTKViewer_ViewFrame::onViewFitAll(){
321 m_RWInteractor->GetInteractorStyleSALOME()->ViewFitAll();
326 Reset the active view
328 void VTKViewer_ViewFrame::onViewReset(){
329 int aTriedronIsVisible = isTrihedronDisplayed();
330 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
331 ::ResetCamera(m_Renderer,true);
332 vtkCamera* aCamera = m_Renderer->GetActiveCamera();
333 aCamera->SetPosition(1,-1,1);
334 aCamera->SetViewUp(0,0,1);
335 ::ResetCamera(m_Renderer,true);
336 if(aTriedronIsVisible) m_Triedron->VisibilityOn();
337 else m_Triedron->VisibilityOff();
338 static float aCoeff = 3.0;
339 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
344 Rotates the active view
346 void VTKViewer_ViewFrame::onViewRotate(){
347 m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
351 Sets a new center of the active view
353 void VTKViewer_ViewFrame::onViewGlobalPan(){
354 if(m_Triedron->GetVisibleActorCount(m_Renderer))
355 m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
359 Zooms the active view
361 void VTKViewer_ViewFrame::onViewZoom(){
362 m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
366 Moves the active view
368 void VTKViewer_ViewFrame::onViewPan(){
369 m_RWInteractor->GetInteractorStyleSALOME()->startPan();
373 Fits all obejcts within a rectangular area of the active view
375 void VTKViewer_ViewFrame::onViewFitArea(){
376 m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
380 Set background of the viewport
382 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
385 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
389 Returns background of the viewport
391 QColor VTKViewer_ViewFrame::backgroundColor() const
395 m_Renderer->GetBackground(backint);
396 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
398 return QMainWindow::backgroundColor();
402 void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
404 m_RWInteractor->SetSelectionMode( mode );
407 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
409 m_RWInteractor->rename(IObject, newName);
412 void VTKViewer_ViewFrame::unHighlightAll()
414 m_RWInteractor->unHighlightAll();
417 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
421 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
422 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
423 m_RWInteractor->highlight(IObject, highlight, update);
425 if(Sel->HasIndex(IObject) && IObject->hasEntry()){
426 TColStd_IndexedMapOfInteger MapIndex;
427 Sel->GetIndex(IObject,MapIndex);
428 using namespace SALOME::VTK;
429 const char* anEntry = IObject->getEntry();
430 vtkActorCollection* aCollection = getRenderer()->GetActors();
431 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
432 switch (Sel->SelectionMode()) {
434 m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
436 case EdgeOfCellSelection:
437 m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
442 case VolumeSelection:
443 m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
448 m_RWInteractor->unHighlightSubSelection();
452 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
454 return m_RWInteractor->isInViewer( IObject );
457 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
459 return m_RWInteractor->isVisible( IObject );
462 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
464 m_RW->setPopupServer( App );
468 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
470 using namespace SALOME::VTK;
471 SALOME_Actor* anActor =
472 Find<SALOME_Actor>(getRenderer()->GetActors(),
473 TIsSameEntry<SALOME_Actor>(theEntry));
475 return anActor->getIO();
477 return Handle(SALOME_InteractiveObject)();
481 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
483 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
484 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
485 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
487 m_RWInteractor->Display(theIObject,false);
488 ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
489 aSel->AddIObject(theIObject,false);
496 struct TDisplayAction{
497 SALOME_Selection* mySel;
498 Handle(SALOME_InteractiveObject) myIO;
499 TDisplayAction(SALOME_Selection* theSel,
500 Handle(SALOME_InteractiveObject) theIO):
501 mySel(theSel), myIO(theIO)
503 void operator()(SALOME_Actor* theActor){
504 theActor->SetVisibility(true);
505 mySel->AddIObject(myIO,false);
509 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
511 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
512 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
514 aSel->ClearIObjects();
515 //m_RWInteractor->EraseAll();
518 using namespace SALOME::VTK;
519 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
520 TIsSameIObject<SALOME_Actor>(theIObject),
521 TDisplayAction(aSel,theIObject));
523 ToolsGUI::SetVisibility(
524 aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
530 struct TEraseAction: TDisplayAction{
531 VTKViewer_RenderWindowInteractor* myRWInteractor;
532 TEraseAction(SALOME_Selection* theSel,
533 Handle(SALOME_InteractiveObject) theIO,
534 VTKViewer_RenderWindowInteractor* theRWInteractor):
535 TDisplayAction(theSel,theIO),
536 myRWInteractor(theRWInteractor)
538 void operator()(SALOME_Actor* theActor){
539 myRWInteractor->Erase(myIO,false);
540 mySel->RemoveIObject(myIO,false);
544 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
546 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
547 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
549 using namespace SALOME::VTK;
550 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
551 TIsSameIObject<SALOME_Actor>(theIObject),
552 TEraseAction(aSel,theIObject,m_RWInteractor));
554 ToolsGUI::SetVisibility(
555 aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
562 void VTKViewer_ViewFrame::DisplayAll()
564 m_RWInteractor->DisplayAll();
566 // update flag of visibility
567 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
568 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
569 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
570 const QString& aCompName = aDesktop->getComponentDataType();
571 SALOMEDS::SObject_var aComponent =
572 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
574 std::list<SALOMEDS::SObject_var> aList;
575 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
577 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
578 for ( ; anIter != aList.end(); ++anIter )
579 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
583 void VTKViewer_ViewFrame::EraseAll()
585 m_RWInteractor->EraseAll();
587 // update flag of visibility
588 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
589 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
590 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
591 const QString& aCompName = aDesktop->getComponentDataType();
592 SALOMEDS::SObject_var aComponent =
593 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
595 std::list<SALOMEDS::SObject_var> aList;
596 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
598 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
599 for ( ; anIter != aList.end(); ++anIter )
600 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
604 void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
606 if (theUpdateTrihedron) onAdjustTrihedron();
610 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
611 m_Transform->GetScale(theScale);
614 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
615 m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
616 m_RWInteractor->Render();
620 void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
621 theActor->AddToRender(m_Renderer);
622 theActor->SetTransform(m_Transform);
623 if(theMoveInternalActors)
624 m_RWInteractor->MoveInternalActors();
627 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
628 InsertActor(theActor);
633 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
634 theActor->RemoveFromRender(m_Renderer);
639 void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
641 RemoveActor(theActor);
642 InsertActor(theActor,true);
645 //==========================================================
647 * VTKViewer_ViewFrame::Display
648 * Display presentation
650 //==========================================================
651 void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
653 // try do downcast object
654 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
655 if ( !aVTKPrs || aVTKPrs->IsNull() )
658 vtkActorCollection* actors = aVTKPrs->GetObjects();
662 actors->InitTraversal();
664 while( ( actor = actors->GetNextActor() ) )
666 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
669 // just display the object
670 m_RWInteractor->Display( salomeActor, false );
672 // Set visibility flag
673 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
674 if ( !anObj.IsNull() && anObj->hasEntry() )
676 SALOMEDS::Study_var aStudy =
677 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
678 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
681 if ( salomeActor->IsSetCamera() )
682 salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
687 //==========================================================
689 * VTKViewer_ViewFrame::Erase
692 //==========================================================
693 void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
695 // try do downcast object
696 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
697 if ( !aVTKPrs || aVTKPrs->IsNull() )
700 vtkActorCollection* actors = aVTKPrs->GetObjects();
704 SALOMEDS::Study_var aStudy =
705 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
707 actors->InitTraversal();
709 while( ( actor = actors->GetNextActor() ) ) {
710 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
712 // just erase the object
714 m_RWInteractor->Remove( salomeActor, false );
716 m_RWInteractor->Erase( salomeActor, forced );
718 // Set visibility flag if necessary
721 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
722 if ( !anObj.IsNull() && anObj->hasEntry() )
723 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
729 //==========================================================
731 * VTKViewer_ViewFrame::CreatePrs
732 * Create presentation by entry
734 //==========================================================
735 SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
737 VTKViewer_Prs* prs = new VTKViewer_Prs();
739 vtkActorCollection* theActors = m_Renderer->GetActors();
740 theActors->InitTraversal();
742 while( ( ac = theActors->GetNextActor() ) ) {
743 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
744 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
745 prs->AddObject( ac );
752 //==========================================================
754 * VTKViewer_ViewFrame::BeforeDisplay
755 * Axiluary method called before displaying of objects
757 //==========================================================
758 void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
760 d->BeforeDisplay( this, SALOME_VTKViewType() );
763 //==========================================================
765 * VTKViewer_ViewFrame::AfterDisplay
766 * Axiluary method called after displaying of objects
768 //==========================================================
769 void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
771 d->AfterDisplay( this, SALOME_VTKViewType() );
774 //==========================================================
776 * VTKViewer_ViewFrame::undo
777 * Redisplay all objects in viewer
779 //==========================================================
780 void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
782 redisplayAll( theQADStudy, true );
785 //==========================================================
787 * VTKViewer_ViewFrame::redo
788 * Redisplay all objects in viewer
790 //==========================================================
791 void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
793 redisplayAll( theQADStudy, true );
796 //==========================================================
798 * VTKViewer_ViewFrame::redisplayAll
799 * Redisplay all objects in viewer
801 //==========================================================
802 void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
804 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
805 SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
806 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
807 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
808 const QString& aCompName = aDesktop->getComponentDataType();
809 SALOMEDS::SObject_var aComponent =
810 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
812 if ( aComponent->_is_nil() )
815 bool isTrhDisplayed = isTrihedronDisplayed();
817 m_RWInteractor->RemoveAll( false );
818 //m_RWInteractor->EraseAll();
820 aSel->ClearIObjects();
822 if ( isTrhDisplayed )
823 m_Triedron->AddToRender( m_Renderer );
825 std::list<SALOMEDS::SObject_var> aList;
826 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
828 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
829 for ( ; anIter != aList.end(); ++anIter )
831 SALOMEDS::SObject_var anObj = (*anIter);
832 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
834 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
835 anIObj->setEntry( anObj->GetID() );
836 aGUI->BuildPresentation( anIObj, this );
845 #define INCREMENT_FOR_OP 10
847 //=======================================================================
849 // Purpose : Performs incremental panning to the left
850 //=======================================================================
851 void VTKViewer_ViewFrame::onPanLeft()
853 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
856 //=======================================================================
858 // Purpose : Performs incremental panning to the right
859 //=======================================================================
860 void VTKViewer_ViewFrame::onPanRight()
862 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
865 //=======================================================================
867 // Purpose : Performs incremental panning to the top
868 //=======================================================================
869 void VTKViewer_ViewFrame::onPanUp()
871 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
874 //=======================================================================
876 // Purpose : Performs incremental panning to the bottom
877 //=======================================================================
878 void VTKViewer_ViewFrame::onPanDown()
880 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
883 //=======================================================================
885 // Purpose : Performs incremental zooming in
886 //=======================================================================
887 void VTKViewer_ViewFrame::onZoomIn()
889 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
892 //=======================================================================
894 // Purpose : Performs incremental zooming out
895 //=======================================================================
896 void VTKViewer_ViewFrame::onZoomOut()
898 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
901 //=======================================================================
902 // name : onRotateLeft
903 // Purpose : Performs incremental rotating to the left
904 //=======================================================================
905 void VTKViewer_ViewFrame::onRotateLeft()
907 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
910 //=======================================================================
911 // name : onRotateRight
912 // Purpose : Performs incremental rotating to the right
913 //=======================================================================
914 void VTKViewer_ViewFrame::onRotateRight()
916 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
919 //=======================================================================
921 // Purpose : Performs incremental rotating to the top
922 //=======================================================================
923 void VTKViewer_ViewFrame::onRotateUp()
925 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
928 //=======================================================================
929 // name : onRotateDown
930 // Purpose : Performs incremental rotating to the bottom
931 //=======================================================================
932 void VTKViewer_ViewFrame::onRotateDown()
934 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );