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(5);
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 double VTKViewer_ViewFrame::GetTrihedronSize() const
194 return m_Triedron->GetSize();
197 void VTKViewer_ViewFrame::AdjustTrihedrons(const bool forced)
200 if ( (!isCubeAxesDisplayed() || !isTrihedronDisplayed()) && forced)
205 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
206 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
208 m_CubeAxes->GetBounds(bnd);
210 cout << "Bounds: BEFORE\n"
211 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
212 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
213 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
215 int aVisibleNum = m_Triedron->GetVisibleActorCount( m_Renderer );
218 // if the new trihedron size have sufficient difference, then apply the value
219 double aNewSize = 100, anOldSize=m_Triedron->GetSize();
220 bool aTDisplayed = isTrihedronDisplayed();
221 bool aCDisplayed = isCubeAxesDisplayed();
222 if(aTDisplayed) m_Triedron->VisibilityOff();
223 if(aCDisplayed) m_CubeAxes->VisibilityOff();
224 static float aSizeInPercents = 105;
225 QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
226 if ( !aSetting.isEmpty() )
227 aSizeInPercents = aSetting.toFloat();
228 bool isComputeTrihedronSize = ::ComputeTrihedronSize(m_Renderer, aNewSize, anOldSize, aSizeInPercents);
229 if(aTDisplayed) m_Triedron->VisibilityOn();
230 if(aCDisplayed) m_CubeAxes->VisibilityOn();
232 if ( isComputeTrihedronSize )
234 m_Triedron->SetSize( aNewSize );
235 // itearte throuh displayed objects and set size if necessary
237 vtkActorCollection* anActors = getRenderer()->GetActors();
238 anActors->InitTraversal();
239 while( vtkActor* anActor = anActors->GetNextActor() )
241 if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
243 if ( aSActor->IsResizable() )
244 aSActor->SetSize( 0.5 * aNewSize );
245 if( aSActor->GetVisibility()){
247 aSActor->GetBounds(abounds);
249 cout << "Bounds: Actor="<<aSActor<<"\n"
250 << "\txMin=" << abounds[ 0 ] << " xMax=" << abounds[ 1 ] << "\n"
251 << "\tyMin=" << abounds[ 2 ] << " yMax=" << abounds[ 3 ] << "\n"
252 << "\tzMin=" << abounds[ 4 ] << " zMax=" << abounds[ 5 ] << "\n";
253 if ( abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
254 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
255 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
256 for(int i=0;i<5;i=i+2){
257 if(abounds[i]<newbnd[i]) newbnd[i]=abounds[i];
258 if(abounds[i+1]>newbnd[i+1]) newbnd[i+1]=abounds[i+1];
266 if( newbnd[0]<VTK_LARGE_FLOAT && newbnd[2]<VTK_LARGE_FLOAT && newbnd[4]<VTK_LARGE_FLOAT &&
267 newbnd[1]>-VTK_LARGE_FLOAT && newbnd[3]>-VTK_LARGE_FLOAT && newbnd[5]>-VTK_LARGE_FLOAT){
268 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
269 m_CubeAxes->SetBounds(bnd);
272 cout << "Bounds AFTER: VisibleActors="<<aVisibleNum<<"\n"
273 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
274 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
275 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
277 m_CubeAxes->SetBounds(bnd);
279 ::ResetCameraClippingRange(m_Renderer);
282 void VTKViewer_ViewFrame::onAdjustTrihedron()
284 AdjustTrihedrons(false);
287 void VTKViewer_ViewFrame::onAdjustCubeAxes()
289 AdjustTrihedrons(false);
293 Display/hide Trihedron
295 void VTKViewer_ViewFrame::onViewTrihedron(){
297 if(!m_Triedron) return;
298 if(isTrihedronDisplayed()) m_Triedron->VisibilityOff();
299 else m_Triedron->VisibilityOn();
303 void VTKViewer_ViewFrame::onViewCubeAxes(){
304 if(!m_CubeAxes) return;
305 if(isCubeAxesDisplayed()) m_CubeAxes->VisibilityOff();
306 else m_CubeAxes->VisibilityOn();
312 Provides top projection of the active view
314 void VTKViewer_ViewFrame::onViewTop(){
315 vtkCamera* camera = m_Renderer->GetActiveCamera();
316 camera->SetPosition(0,0,1);
317 camera->SetViewUp(0,1,0);
318 camera->SetFocalPoint(0,0,0);
323 Provides bottom projection of the active view
325 void VTKViewer_ViewFrame::onViewBottom(){
326 vtkCamera* camera = m_Renderer->GetActiveCamera();
327 camera->SetPosition(0,0,-1);
328 camera->SetViewUp(0,1,0);
329 camera->SetFocalPoint(0,0,0);
334 Provides left projection of the active view
336 void VTKViewer_ViewFrame::onViewLeft(){
337 vtkCamera* camera = m_Renderer->GetActiveCamera();
338 camera->SetPosition(0,-1,0);
339 camera->SetViewUp(0,0,1);
340 camera->SetFocalPoint(0,0,0);
345 Provides right projection of the active view
347 void VTKViewer_ViewFrame::onViewRight(){
348 vtkCamera* camera = m_Renderer->GetActiveCamera();
349 camera->SetPosition(0,1,0);
350 camera->SetViewUp(0,0,1);
351 camera->SetFocalPoint(0,0,0);
356 Provides back projection of the active view
358 void VTKViewer_ViewFrame::onViewBack(){
359 vtkCamera* camera = m_Renderer->GetActiveCamera();
360 camera->SetPosition(-1,0,0);
361 camera->SetViewUp(0,0,1);
362 camera->SetFocalPoint(0,0,0);
367 Provides front projection of the active view
369 void VTKViewer_ViewFrame::onViewFront(){
370 vtkCamera* camera = m_Renderer->GetActiveCamera();
371 camera->SetPosition(1,0,0);
372 camera->SetViewUp(0,0,1);
373 camera->SetFocalPoint(0,0,0);
378 Fits all objects in the active view
380 void VTKViewer_ViewFrame::onViewFitAll(){
382 int aTriedronWasVisible = false;
383 int aCubeAxesWasVisible = false;
385 aTriedronWasVisible = isTrihedronDisplayed();
386 if(aTriedronWasVisible) m_Triedron->VisibilityOff();
389 aCubeAxesWasVisible = isCubeAxesDisplayed();
390 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff();
393 if(m_Triedron->GetVisibleActorCount(m_Renderer)){
394 m_Triedron->VisibilityOff();
395 m_CubeAxes->VisibilityOff();
396 ::ResetCamera(m_Renderer);
398 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
399 m_CubeAxes->SetVisibility(2);
400 ::ResetCamera(m_Renderer,true);
402 if(aTriedronWasVisible) m_Triedron->VisibilityOn();
403 else m_Triedron->VisibilityOff();
404 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOn();
405 else m_CubeAxes->VisibilityOff();
406 ::ResetCameraClippingRange(m_Renderer);
412 Reset the active view
414 void VTKViewer_ViewFrame::onViewReset(){
415 int aTriedronIsVisible = isTrihedronDisplayed();
416 int aCubeAxesIsVisible = isCubeAxesDisplayed();
418 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
419 m_CubeAxes->SetVisibility(0);
421 ::ResetCamera(m_Renderer,true);
422 vtkCamera* aCamera = m_Renderer->GetActiveCamera();
423 aCamera->SetPosition(1,-1,1);
424 aCamera->SetViewUp(0,0,1);
425 ::ResetCamera(m_Renderer,true);
427 if(aTriedronIsVisible) m_Triedron->VisibilityOn();
428 else m_Triedron->VisibilityOff();
430 if(aCubeAxesIsVisible) m_CubeAxes->VisibilityOn();
431 else m_CubeAxes->VisibilityOff();
433 static float aCoeff = 3.0;
434 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
439 Rotates the active view
441 void VTKViewer_ViewFrame::onViewRotate(){
442 m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
446 Sets a new center of the active view
448 void VTKViewer_ViewFrame::onViewGlobalPan(){
449 if(m_Triedron->GetVisibleActorCount(m_Renderer))
450 m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
454 Zooms the active view
456 void VTKViewer_ViewFrame::onViewZoom(){
457 m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
461 Moves the active view
463 void VTKViewer_ViewFrame::onViewPan(){
464 m_RWInteractor->GetInteractorStyleSALOME()->startPan();
468 Fits all obejcts within a rectangular area of the active view
470 void VTKViewer_ViewFrame::onViewFitArea(){
471 m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
475 Set background of the viewport
477 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
480 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
484 Returns background of the viewport
486 QColor VTKViewer_ViewFrame::backgroundColor() const
490 m_Renderer->GetBackground(backint);
491 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
493 return QMainWindow::backgroundColor();
497 void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
499 m_RWInteractor->SetSelectionMode( mode );
502 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
504 m_RWInteractor->rename(IObject, newName);
507 void VTKViewer_ViewFrame::unHighlightAll()
509 m_RWInteractor->unHighlightAll();
512 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
516 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
517 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
518 m_RWInteractor->highlight(IObject, highlight, update);
520 if(Sel->HasIndex(IObject) && IObject->hasEntry()){
521 TColStd_IndexedMapOfInteger MapIndex;
522 Sel->GetIndex(IObject,MapIndex);
523 using namespace SALOME::VTK;
524 const char* anEntry = IObject->getEntry();
525 vtkActorCollection* aCollection = getRenderer()->GetActors();
526 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
527 switch (Sel->SelectionMode()) {
529 m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
531 case EdgeOfCellSelection:
532 m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
537 case VolumeSelection:
538 m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
543 m_RWInteractor->unHighlightSubSelection();
547 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
549 return m_RWInteractor->isInViewer( IObject );
552 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
554 return m_RWInteractor->isVisible( IObject );
557 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
559 m_RW->setPopupServer( App );
563 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
565 using namespace SALOME::VTK;
566 SALOME_Actor* anActor =
567 Find<SALOME_Actor>(getRenderer()->GetActors(),
568 TIsSameEntry<SALOME_Actor>(theEntry));
570 return anActor->getIO();
572 return Handle(SALOME_InteractiveObject)();
576 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
578 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
579 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
580 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
582 m_RWInteractor->Display(theIObject,false);
583 ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
584 aSel->AddIObject(theIObject,false);
591 struct TDisplayAction{
592 SALOME_Selection* mySel;
593 Handle(SALOME_InteractiveObject) myIO;
594 TDisplayAction(SALOME_Selection* theSel,
595 Handle(SALOME_InteractiveObject) theIO):
596 mySel(theSel), myIO(theIO)
598 void operator()(SALOME_Actor* theActor){
599 theActor->SetVisibility(true);
600 mySel->AddIObject(myIO,false);
604 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
606 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
607 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
609 aSel->ClearIObjects();
610 //m_RWInteractor->EraseAll();
613 using namespace SALOME::VTK;
614 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
615 TIsSameIObject<SALOME_Actor>(theIObject),
616 TDisplayAction(aSel,theIObject));
618 ToolsGUI::SetVisibility(
619 aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
625 struct TEraseAction: TDisplayAction{
626 VTKViewer_RenderWindowInteractor* myRWInteractor;
627 TEraseAction(SALOME_Selection* theSel,
628 Handle(SALOME_InteractiveObject) theIO,
629 VTKViewer_RenderWindowInteractor* theRWInteractor):
630 TDisplayAction(theSel,theIO),
631 myRWInteractor(theRWInteractor)
633 void operator()(SALOME_Actor* theActor){
634 myRWInteractor->Erase(myIO,false);
635 mySel->RemoveIObject(myIO,false);
639 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
641 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
642 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
644 using namespace SALOME::VTK;
645 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
646 TIsSameIObject<SALOME_Actor>(theIObject),
647 TEraseAction(aSel,theIObject,m_RWInteractor));
649 ToolsGUI::SetVisibility(
650 aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
657 void VTKViewer_ViewFrame::DisplayAll()
659 m_RWInteractor->DisplayAll();
661 // update flag of visibility
662 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
663 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
664 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
665 const QString& aCompName = aDesktop->getComponentDataType();
666 SALOMEDS::SObject_var aComponent =
667 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
669 std::list<SALOMEDS::SObject_var> aList;
670 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
672 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
673 for ( ; anIter != aList.end(); ++anIter )
674 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
678 void VTKViewer_ViewFrame::EraseAll()
680 m_RWInteractor->EraseAll();
682 // update flag of visibility
683 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
684 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
685 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
686 const QString& aCompName = aDesktop->getComponentDataType();
687 SALOMEDS::SObject_var aComponent =
688 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
690 std::list<SALOMEDS::SObject_var> aList;
691 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
693 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
694 for ( ; anIter != aList.end(); ++anIter )
695 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
699 void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
701 if (theUpdateTrihedron) onAdjustTrihedron();
702 //if (theUpdateCubeAxes) onAdjustCubeAxes();
706 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
707 m_Transform->GetScale(theScale);
710 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
711 m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
712 m_RWInteractor->Render();
716 void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
717 theActor->AddToRender(m_Renderer);
718 theActor->SetTransform(m_Transform);
719 if(theMoveInternalActors)
720 m_RWInteractor->MoveInternalActors();
723 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
724 InsertActor(theActor);
729 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
730 theActor->RemoveFromRender(m_Renderer);
735 void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
737 RemoveActor(theActor);
738 InsertActor(theActor,true);
741 //==========================================================
743 * VTKViewer_ViewFrame::Display
744 * Display presentation
746 //==========================================================
747 void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
749 // try do downcast object
750 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
751 if ( !aVTKPrs || aVTKPrs->IsNull() )
754 vtkActorCollection* actors = aVTKPrs->GetObjects();
758 actors->InitTraversal();
760 while( ( actor = actors->GetNextActor() ) )
762 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
765 // just display the object
766 m_RWInteractor->Display( salomeActor, false );
768 // Set visibility flag
769 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
770 if ( !anObj.IsNull() && anObj->hasEntry() )
772 SALOMEDS::Study_var aStudy =
773 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
774 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
777 if ( salomeActor->IsSetCamera() )
778 salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
783 //==========================================================
785 * VTKViewer_ViewFrame::Erase
788 //==========================================================
789 void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
791 // try do downcast object
792 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
793 if ( !aVTKPrs || aVTKPrs->IsNull() )
796 vtkActorCollection* actors = aVTKPrs->GetObjects();
800 SALOMEDS::Study_var aStudy =
801 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
803 actors->InitTraversal();
805 while( ( actor = actors->GetNextActor() ) ) {
806 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
808 // just erase the object
810 m_RWInteractor->Remove( salomeActor, false );
812 m_RWInteractor->Erase( salomeActor, forced );
814 // Set visibility flag if necessary
817 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
818 if ( !anObj.IsNull() && anObj->hasEntry() )
819 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
825 //==========================================================
827 * VTKViewer_ViewFrame::CreatePrs
828 * Create presentation by entry
830 //==========================================================
831 SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
833 VTKViewer_Prs* prs = new VTKViewer_Prs();
835 vtkActorCollection* theActors = m_Renderer->GetActors();
836 theActors->InitTraversal();
838 while( ( ac = theActors->GetNextActor() ) ) {
839 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
840 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
841 prs->AddObject( ac );
848 //==========================================================
850 * VTKViewer_ViewFrame::BeforeDisplay
851 * Axiluary method called before displaying of objects
853 //==========================================================
854 void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
856 d->BeforeDisplay( this, SALOME_VTKViewType() );
859 //==========================================================
861 * VTKViewer_ViewFrame::AfterDisplay
862 * Axiluary method called after displaying of objects
864 //==========================================================
865 void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
867 d->AfterDisplay( this, SALOME_VTKViewType() );
870 //==========================================================
872 * VTKViewer_ViewFrame::undo
873 * Redisplay all objects in viewer
875 //==========================================================
876 void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
878 redisplayAll( theQADStudy, true );
881 //==========================================================
883 * VTKViewer_ViewFrame::redo
884 * Redisplay all objects in viewer
886 //==========================================================
887 void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
889 redisplayAll( theQADStudy, true );
892 //==========================================================
894 * VTKViewer_ViewFrame::redisplayAll
895 * Redisplay all objects in viewer
897 //==========================================================
898 void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
900 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
901 SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
902 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
903 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
904 const QString& aCompName = aDesktop->getComponentDataType();
905 SALOMEDS::SObject_var aComponent =
906 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
908 if ( aComponent->_is_nil() )
911 m_RWInteractor->RemoveAll( false );
912 //m_RWInteractor->EraseAll();
914 aSel->ClearIObjects();
917 // ENK commented, already added to renderer in
918 // VTKViewer_ViewFrame::VTKViewer_ViewFrame(...)
919 if ( isTrhDisplayed )
920 m_Triedron->AddToRender( m_Renderer );
923 std::list<SALOMEDS::SObject_var> aList;
924 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
926 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
927 for ( ; anIter != aList.end(); ++anIter )
929 SALOMEDS::SObject_var anObj = (*anIter);
930 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
932 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
933 anIObj->setEntry( anObj->GetID() );
934 aGUI->BuildPresentation( anIObj, this );
943 #define INCREMENT_FOR_OP 10
945 //=======================================================================
947 // Purpose : Performs incremental panning to the left
948 //=======================================================================
949 void VTKViewer_ViewFrame::onPanLeft()
951 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
954 //=======================================================================
956 // Purpose : Performs incremental panning to the right
957 //=======================================================================
958 void VTKViewer_ViewFrame::onPanRight()
960 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
963 //=======================================================================
965 // Purpose : Performs incremental panning to the top
966 //=======================================================================
967 void VTKViewer_ViewFrame::onPanUp()
969 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
972 //=======================================================================
974 // Purpose : Performs incremental panning to the bottom
975 //=======================================================================
976 void VTKViewer_ViewFrame::onPanDown()
978 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
981 //=======================================================================
983 // Purpose : Performs incremental zooming in
984 //=======================================================================
985 void VTKViewer_ViewFrame::onZoomIn()
987 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
990 //=======================================================================
992 // Purpose : Performs incremental zooming out
993 //=======================================================================
994 void VTKViewer_ViewFrame::onZoomOut()
996 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
999 //=======================================================================
1000 // name : onRotateLeft
1001 // Purpose : Performs incremental rotating to the left
1002 //=======================================================================
1003 void VTKViewer_ViewFrame::onRotateLeft()
1005 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
1008 //=======================================================================
1009 // name : onRotateRight
1010 // Purpose : Performs incremental rotating to the right
1011 //=======================================================================
1012 void VTKViewer_ViewFrame::onRotateRight()
1014 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
1017 //=======================================================================
1018 // name : onRotateUp
1019 // Purpose : Performs incremental rotating to the top
1020 //=======================================================================
1021 void VTKViewer_ViewFrame::onRotateUp()
1023 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
1026 //=======================================================================
1027 // name : onRotateDown
1028 // Purpose : Performs incremental rotating to the bottom
1029 //=======================================================================
1030 void VTKViewer_ViewFrame::onRotateDown()
1032 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );