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->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
147 m_CubeAxes->SetFontFactor(0.8);
148 m_CubeAxes->SetAxisTitleTextProperty(tprop);
149 m_CubeAxes->SetAxisLabelTextProperty(tprop);
150 m_CubeAxes->SetCornerOffset(0);
151 m_CubeAxes->SetScaling(0);
152 m_CubeAxes->SetNumberOfLabels(5);
153 m_CubeAxes->VisibilityOff();
154 m_CubeAxes->SetTransform(m_Transform);
157 setCentralWidget( m_RW );
161 VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
162 // In order to ensure that the interactor unregisters
163 // this RenderWindow, we assign a NULL RenderWindow to
164 // it before deleting it.
165 m_RWInteractor->SetRenderWindow(NULL) ;
166 m_RWInteractor->Delete() ;
168 m_Transform->Delete() ;
170 m_Renderer->RemoveAllProps();
171 // NRI : BugID 1137: m_Renderer->Delete() ;
172 m_Triedron->Delete();
174 m_CubeAxes->Delete();
175 INFOS("VTKViewer_ViewFrame::~VTKViewer_ViewFrame()");
179 Returns widget containing 3D-Viewer
181 QWidget* VTKViewer_ViewFrame::getViewWidget(){
185 bool VTKViewer_ViewFrame::isTrihedronDisplayed(){
186 return m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
189 bool VTKViewer_ViewFrame::isCubeAxesDisplayed(){
190 return m_CubeAxes->GetVisibility() == 1;
193 double VTKViewer_ViewFrame::GetTrihedronSize() const
195 return m_Triedron->GetSize();
198 void VTKViewer_ViewFrame::AdjustTrihedrons(const bool forced)
201 if ( (!isCubeAxesDisplayed() || !isTrihedronDisplayed()) && forced)
206 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
207 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
209 m_CubeAxes->GetBounds(bnd);
211 cout << "Bounds: BEFORE\n"
212 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
213 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
214 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
216 int aVisibleNum = m_Triedron->GetVisibleActorCount( m_Renderer );
219 // if the new trihedron size have sufficient difference, then apply the value
220 double aNewSize = 100, anOldSize=m_Triedron->GetSize();
221 bool aTDisplayed = isTrihedronDisplayed();
222 bool aCDisplayed = isCubeAxesDisplayed();
223 if(aTDisplayed) m_Triedron->VisibilityOff();
224 if(aCDisplayed) m_CubeAxes->VisibilityOff();
225 static float aSizeInPercents = 105;
226 QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
227 if ( !aSetting.isEmpty() )
228 aSizeInPercents = aSetting.toFloat();
229 bool isComputeTrihedronSize = ::ComputeTrihedronSize(m_Renderer, aNewSize, anOldSize, aSizeInPercents);
231 m_Triedron->SetSize( aNewSize );
232 // itearte throuh displayed objects and set size if necessary
234 vtkActorCollection* anActors = getRenderer()->GetActors();
235 anActors->InitTraversal();
236 while( vtkActor* anActor = anActors->GetNextActor() )
238 if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
240 if ( aSActor->IsResizable() )
241 aSActor->SetSize( 0.5 * aNewSize );
242 if( aSActor->GetVisibility()){
244 aSActor->GetBounds(abounds);
246 cout << "Bounds: Actor="<<aSActor<<"\n"
247 << "\txMin=" << abounds[ 0 ] << " xMax=" << abounds[ 1 ] << "\n"
248 << "\tyMin=" << abounds[ 2 ] << " yMax=" << abounds[ 3 ] << "\n"
249 << "\tzMin=" << abounds[ 4 ] << " zMax=" << abounds[ 5 ] << "\n";
250 if ( abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
251 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
252 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
253 for(int i=0;i<5;i=i+2){
254 if(abounds[i]<newbnd[i]) newbnd[i]=abounds[i];
255 if(abounds[i+1]>newbnd[i+1]) newbnd[i+1]=abounds[i+1];
261 if(aTDisplayed) m_Triedron->VisibilityOn();
262 if(aCDisplayed) m_CubeAxes->VisibilityOn();
265 double aSize = m_Triedron->GetSize();
266 newbnd[0] = newbnd[2] = newbnd[4] = 0;
267 newbnd[1] = newbnd[3] = newbnd[5] = aSize;
270 if( newbnd[0]<VTK_LARGE_FLOAT && newbnd[2]<VTK_LARGE_FLOAT && newbnd[4]<VTK_LARGE_FLOAT &&
271 newbnd[1]>-VTK_LARGE_FLOAT && newbnd[3]>-VTK_LARGE_FLOAT && newbnd[5]>-VTK_LARGE_FLOAT){
272 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
273 m_CubeAxes->SetBounds(bnd);
276 cout << "Bounds AFTER: VisibleActors="<<aVisibleNum<<"\n"
277 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
278 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
279 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
281 m_CubeAxes->SetBounds(bnd);
283 ::ResetCameraClippingRange(m_Renderer);
286 void VTKViewer_ViewFrame::onAdjustTrihedron()
288 AdjustTrihedrons(false);
291 void VTKViewer_ViewFrame::onAdjustCubeAxes()
293 AdjustTrihedrons(false);
297 Display/hide Trihedron
299 void VTKViewer_ViewFrame::onViewTrihedron(){
300 if(!m_Triedron) return;
301 if(isTrihedronDisplayed()) m_Triedron->VisibilityOff();
302 else m_Triedron->VisibilityOn();
306 void VTKViewer_ViewFrame::onViewCubeAxes(){
307 if(!m_CubeAxes) return;
308 if(isCubeAxesDisplayed()) m_CubeAxes->VisibilityOff();
309 else m_CubeAxes->VisibilityOn();
315 Provides top projection of the active view
317 void VTKViewer_ViewFrame::onViewTop(){
318 vtkCamera* camera = m_Renderer->GetActiveCamera();
319 camera->SetPosition(0,0,1);
320 camera->SetViewUp(0,1,0);
321 camera->SetFocalPoint(0,0,0);
326 Provides bottom projection of the active view
328 void VTKViewer_ViewFrame::onViewBottom(){
329 vtkCamera* camera = m_Renderer->GetActiveCamera();
330 camera->SetPosition(0,0,-1);
331 camera->SetViewUp(0,1,0);
332 camera->SetFocalPoint(0,0,0);
337 Provides left projection of the active view
339 void VTKViewer_ViewFrame::onViewLeft(){
340 vtkCamera* camera = m_Renderer->GetActiveCamera();
341 camera->SetPosition(0,-1,0);
342 camera->SetViewUp(0,0,1);
343 camera->SetFocalPoint(0,0,0);
348 Provides right projection of the active view
350 void VTKViewer_ViewFrame::onViewRight(){
351 vtkCamera* camera = m_Renderer->GetActiveCamera();
352 camera->SetPosition(0,1,0);
353 camera->SetViewUp(0,0,1);
354 camera->SetFocalPoint(0,0,0);
359 Provides back projection of the active view
361 void VTKViewer_ViewFrame::onViewBack(){
362 vtkCamera* camera = m_Renderer->GetActiveCamera();
363 camera->SetPosition(-1,0,0);
364 camera->SetViewUp(0,0,1);
365 camera->SetFocalPoint(0,0,0);
370 Provides front projection of the active view
372 void VTKViewer_ViewFrame::onViewFront(){
373 vtkCamera* camera = m_Renderer->GetActiveCamera();
374 camera->SetPosition(1,0,0);
375 camera->SetViewUp(0,0,1);
376 camera->SetFocalPoint(0,0,0);
381 Fits all objects in the active view
383 void VTKViewer_ViewFrame::onViewFitAll(){
385 int aTriedronWasVisible = false;
386 int aCubeAxesWasVisible = false;
388 aTriedronWasVisible = isTrihedronDisplayed();
389 if(aTriedronWasVisible) m_Triedron->VisibilityOff();
392 aCubeAxesWasVisible = isCubeAxesDisplayed();
393 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff();
396 if(m_Triedron->GetVisibleActorCount(m_Renderer)){
397 m_Triedron->VisibilityOff();
398 m_CubeAxes->VisibilityOff();
399 ::ResetCamera(m_Renderer);
401 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
402 m_CubeAxes->SetVisibility(2);
403 ::ResetCamera(m_Renderer,true);
405 if(aTriedronWasVisible) m_Triedron->VisibilityOn();
406 else m_Triedron->VisibilityOff();
407 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOn();
408 else m_CubeAxes->VisibilityOff();
409 ::ResetCameraClippingRange(m_Renderer);
415 Reset the active view
417 void VTKViewer_ViewFrame::onViewReset(){
418 int aTriedronIsVisible = isTrihedronDisplayed();
419 int aCubeAxesIsVisible = isCubeAxesDisplayed();
421 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
422 m_CubeAxes->SetVisibility(0);
424 ::ResetCamera(m_Renderer,true);
425 vtkCamera* aCamera = m_Renderer->GetActiveCamera();
426 aCamera->SetPosition(1,-1,1);
427 aCamera->SetViewUp(0,0,1);
428 ::ResetCamera(m_Renderer,true);
430 if(aTriedronIsVisible) m_Triedron->VisibilityOn();
431 else m_Triedron->VisibilityOff();
433 if(aCubeAxesIsVisible) m_CubeAxes->VisibilityOn();
434 else m_CubeAxes->VisibilityOff();
436 static float aCoeff = 3.0;
437 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
442 Rotates the active view
444 void VTKViewer_ViewFrame::onViewRotate(){
445 m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
449 Sets a new center of the active view
451 void VTKViewer_ViewFrame::onViewGlobalPan(){
452 if(m_Triedron->GetVisibleActorCount(m_Renderer))
453 m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
457 Zooms the active view
459 void VTKViewer_ViewFrame::onViewZoom(){
460 m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
464 Moves the active view
466 void VTKViewer_ViewFrame::onViewPan(){
467 m_RWInteractor->GetInteractorStyleSALOME()->startPan();
471 Fits all obejcts within a rectangular area of the active view
473 void VTKViewer_ViewFrame::onViewFitArea(){
474 m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
478 Set background of the viewport
480 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
483 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
487 Returns background of the viewport
489 QColor VTKViewer_ViewFrame::backgroundColor() const
493 m_Renderer->GetBackground(backint);
494 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
496 return QMainWindow::backgroundColor();
500 void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
502 m_RWInteractor->SetSelectionMode( mode );
505 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
507 m_RWInteractor->rename(IObject, newName);
510 void VTKViewer_ViewFrame::unHighlightAll()
512 m_RWInteractor->unHighlightAll();
515 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
519 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
520 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
521 m_RWInteractor->highlight(IObject, highlight, update);
523 if(Sel->HasIndex(IObject) && IObject->hasEntry()){
524 TColStd_IndexedMapOfInteger MapIndex;
525 Sel->GetIndex(IObject,MapIndex);
526 using namespace SALOME::VTK;
527 const char* anEntry = IObject->getEntry();
528 vtkActorCollection* aCollection = getRenderer()->GetActors();
529 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
530 switch (Sel->SelectionMode()) {
532 m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
534 case EdgeOfCellSelection:
535 m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
540 case VolumeSelection:
541 m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
546 m_RWInteractor->unHighlightSubSelection();
550 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
552 return m_RWInteractor->isInViewer( IObject );
555 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
557 return m_RWInteractor->isVisible( IObject );
560 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
562 m_RW->setPopupServer( App );
566 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
568 using namespace SALOME::VTK;
569 SALOME_Actor* anActor =
570 Find<SALOME_Actor>(getRenderer()->GetActors(),
571 TIsSameEntry<SALOME_Actor>(theEntry));
573 return anActor->getIO();
575 return Handle(SALOME_InteractiveObject)();
579 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
581 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
582 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
583 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
585 m_RWInteractor->Display(theIObject,false);
586 ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
587 aSel->AddIObject(theIObject,false);
594 struct TDisplayAction{
595 SALOME_Selection* mySel;
596 Handle(SALOME_InteractiveObject) myIO;
597 TDisplayAction(SALOME_Selection* theSel,
598 Handle(SALOME_InteractiveObject) theIO):
599 mySel(theSel), myIO(theIO)
601 void operator()(SALOME_Actor* theActor){
602 theActor->SetVisibility(true);
603 mySel->AddIObject(myIO,false);
607 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
609 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
610 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
612 aSel->ClearIObjects();
613 //m_RWInteractor->EraseAll();
616 using namespace SALOME::VTK;
617 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
618 TIsSameIObject<SALOME_Actor>(theIObject),
619 TDisplayAction(aSel,theIObject));
621 ToolsGUI::SetVisibility(
622 aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
628 struct TEraseAction: TDisplayAction{
629 VTKViewer_RenderWindowInteractor* myRWInteractor;
630 TEraseAction(SALOME_Selection* theSel,
631 Handle(SALOME_InteractiveObject) theIO,
632 VTKViewer_RenderWindowInteractor* theRWInteractor):
633 TDisplayAction(theSel,theIO),
634 myRWInteractor(theRWInteractor)
636 void operator()(SALOME_Actor* theActor){
637 myRWInteractor->Erase(myIO,false);
638 mySel->RemoveIObject(myIO,false);
642 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
644 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
645 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
647 using namespace SALOME::VTK;
648 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
649 TIsSameIObject<SALOME_Actor>(theIObject),
650 TEraseAction(aSel,theIObject,m_RWInteractor));
652 ToolsGUI::SetVisibility(
653 aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
660 void VTKViewer_ViewFrame::DisplayAll()
662 m_RWInteractor->DisplayAll();
664 // update flag of visibility
665 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
666 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
667 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
668 const QString& aCompName = aDesktop->getComponentDataType();
669 SALOMEDS::SObject_var aComponent =
670 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
672 std::list<SALOMEDS::SObject_var> aList;
673 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
675 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
676 for ( ; anIter != aList.end(); ++anIter )
677 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
681 void VTKViewer_ViewFrame::EraseAll()
683 m_RWInteractor->EraseAll();
685 // update flag of visibility
686 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
687 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
688 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
689 const QString& aCompName = aDesktop->getComponentDataType();
690 SALOMEDS::SObject_var aComponent =
691 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
693 std::list<SALOMEDS::SObject_var> aList;
694 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
696 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
697 for ( ; anIter != aList.end(); ++anIter )
698 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
702 void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
704 if (theUpdateTrihedron) onAdjustTrihedron();
705 //if (theUpdateCubeAxes) onAdjustCubeAxes();
709 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
710 m_Transform->GetMatrixScale(theScale);
713 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
714 m_Transform->SetMatrixScale(theScale[0], theScale[1], theScale[2]);
715 m_RWInteractor->Render();
719 void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
720 theActor->AddToRender(m_Renderer);
721 theActor->SetTransform(m_Transform);
722 if(theMoveInternalActors)
723 m_RWInteractor->MoveInternalActors();
726 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
727 InsertActor(theActor);
732 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
733 theActor->RemoveFromRender(m_Renderer);
738 void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
740 RemoveActor(theActor);
741 InsertActor(theActor,true);
744 //==========================================================
746 * VTKViewer_ViewFrame::Display
747 * Display presentation
749 //==========================================================
750 void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
752 // try do downcast object
753 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
754 if ( !aVTKPrs || aVTKPrs->IsNull() )
757 vtkActorCollection* actors = aVTKPrs->GetObjects();
761 actors->InitTraversal();
763 while( ( actor = actors->GetNextActor() ) )
765 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
768 // just display the object
769 m_RWInteractor->Display( salomeActor, false );
771 // Set visibility flag
772 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
773 if ( !anObj.IsNull() && anObj->hasEntry() )
775 SALOMEDS::Study_var aStudy =
776 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
777 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
780 if ( salomeActor->IsSetCamera() )
781 salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
786 //==========================================================
788 * VTKViewer_ViewFrame::Erase
791 //==========================================================
792 void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
794 // try do downcast object
795 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
796 if ( !aVTKPrs || aVTKPrs->IsNull() )
799 vtkActorCollection* actors = aVTKPrs->GetObjects();
803 SALOMEDS::Study_var aStudy =
804 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
806 actors->InitTraversal();
808 while( ( actor = actors->GetNextActor() ) ) {
809 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
811 // just erase the object
813 m_RWInteractor->Remove( salomeActor, false );
815 m_RWInteractor->Erase( salomeActor, forced );
817 // Set visibility flag if necessary
820 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
821 if ( !anObj.IsNull() && anObj->hasEntry() )
822 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
828 //==========================================================
830 * VTKViewer_ViewFrame::CreatePrs
831 * Create presentation by entry
833 //==========================================================
834 SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
836 VTKViewer_Prs* prs = new VTKViewer_Prs();
838 vtkActorCollection* theActors = m_Renderer->GetActors();
839 theActors->InitTraversal();
841 while( ( ac = theActors->GetNextActor() ) ) {
842 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
843 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
844 prs->AddObject( ac );
851 //==========================================================
853 * VTKViewer_ViewFrame::BeforeDisplay
854 * Axiluary method called before displaying of objects
856 //==========================================================
857 void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
859 d->BeforeDisplay( this, SALOME_VTKViewType() );
862 //==========================================================
864 * VTKViewer_ViewFrame::AfterDisplay
865 * Axiluary method called after displaying of objects
867 //==========================================================
868 void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
870 d->AfterDisplay( this, SALOME_VTKViewType() );
873 //==========================================================
875 * VTKViewer_ViewFrame::undo
876 * Redisplay all objects in viewer
878 //==========================================================
879 void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
881 redisplayAll( theQADStudy, true );
884 //==========================================================
886 * VTKViewer_ViewFrame::redo
887 * Redisplay all objects in viewer
889 //==========================================================
890 void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
892 redisplayAll( theQADStudy, true );
895 //==========================================================
897 * VTKViewer_ViewFrame::redisplayAll
898 * Redisplay all objects in viewer
900 //==========================================================
901 void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
903 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
904 SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
905 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
906 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
907 const QString& aCompName = aDesktop->getComponentDataType();
908 SALOMEDS::SObject_var aComponent =
909 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
911 if ( aComponent->_is_nil() )
914 m_RWInteractor->RemoveAll( false );
915 //m_RWInteractor->EraseAll();
917 aSel->ClearIObjects();
920 // ENK commented, already added to renderer in
921 // VTKViewer_ViewFrame::VTKViewer_ViewFrame(...)
922 if ( isTrhDisplayed )
923 m_Triedron->AddToRender( m_Renderer );
926 std::list<SALOMEDS::SObject_var> aList;
927 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
929 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
930 for ( ; anIter != aList.end(); ++anIter )
932 SALOMEDS::SObject_var anObj = (*anIter);
933 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
935 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
936 anIObj->setEntry( anObj->GetID() );
937 aGUI->BuildPresentation( anIObj, this );
946 #define INCREMENT_FOR_OP 10
948 //=======================================================================
950 // Purpose : Performs incremental panning to the left
951 //=======================================================================
952 void VTKViewer_ViewFrame::onPanLeft()
954 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
957 //=======================================================================
959 // Purpose : Performs incremental panning to the right
960 //=======================================================================
961 void VTKViewer_ViewFrame::onPanRight()
963 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
966 //=======================================================================
968 // Purpose : Performs incremental panning to the top
969 //=======================================================================
970 void VTKViewer_ViewFrame::onPanUp()
972 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
975 //=======================================================================
977 // Purpose : Performs incremental panning to the bottom
978 //=======================================================================
979 void VTKViewer_ViewFrame::onPanDown()
981 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
984 //=======================================================================
986 // Purpose : Performs incremental zooming in
987 //=======================================================================
988 void VTKViewer_ViewFrame::onZoomIn()
990 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
993 //=======================================================================
995 // Purpose : Performs incremental zooming out
996 //=======================================================================
997 void VTKViewer_ViewFrame::onZoomOut()
999 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
1002 //=======================================================================
1003 // name : onRotateLeft
1004 // Purpose : Performs incremental rotating to the left
1005 //=======================================================================
1006 void VTKViewer_ViewFrame::onRotateLeft()
1008 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
1011 //=======================================================================
1012 // name : onRotateRight
1013 // Purpose : Performs incremental rotating to the right
1014 //=======================================================================
1015 void VTKViewer_ViewFrame::onRotateRight()
1017 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
1020 //=======================================================================
1021 // name : onRotateUp
1022 // Purpose : Performs incremental rotating to the top
1023 //=======================================================================
1024 void VTKViewer_ViewFrame::onRotateUp()
1026 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
1029 //=======================================================================
1030 // name : onRotateDown
1031 // Purpose : Performs incremental rotating to the bottom
1032 //=======================================================================
1033 void VTKViewer_ViewFrame::onRotateDown()
1035 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );