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();
221 m_Triedron->VisibilityOff();
222 m_CubeAxes->VisibilityOff();
223 static float aSizeInPercents = 105;
224 QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
225 if ( !aSetting.isEmpty() )
226 aSizeInPercents = aSetting.toFloat();
227 bool isComputeTrihedronSize = ::ComputeTrihedronSize(m_Renderer, aNewSize, anOldSize, aSizeInPercents);
228 m_Triedron->VisibilityOn();
229 m_CubeAxes->VisibilityOn();
231 if ( isComputeTrihedronSize )
233 m_Triedron->SetSize( aNewSize );
234 // itearte throuh displayed objects and set size if necessary
236 vtkActorCollection* anActors = getRenderer()->GetActors();
237 anActors->InitTraversal();
238 while( vtkActor* anActor = anActors->GetNextActor() )
240 if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
242 if ( aSActor->IsResizable() )
243 aSActor->SetSize( 0.5 * aNewSize );
244 if( aSActor->GetVisibility()){
246 aSActor->GetBounds(abounds);
248 cout << "Bounds: Actor="<<aSActor<<"\n"
249 << "\txMin=" << abounds[ 0 ] << " xMax=" << abounds[ 1 ] << "\n"
250 << "\tyMin=" << abounds[ 2 ] << " yMax=" << abounds[ 3 ] << "\n"
251 << "\tzMin=" << abounds[ 4 ] << " zMax=" << abounds[ 5 ] << "\n";
252 if ( abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
253 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
254 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
255 for(int i=0;i<5;i=i+2){
256 if(abounds[i]<newbnd[i]) newbnd[i]=abounds[i];
257 if(abounds[i+1]>newbnd[i+1]) newbnd[i+1]=abounds[i+1];
265 if( newbnd[0]<VTK_LARGE_FLOAT && newbnd[2]<VTK_LARGE_FLOAT && newbnd[4]<VTK_LARGE_FLOAT &&
266 newbnd[1]>-VTK_LARGE_FLOAT && newbnd[3]>-VTK_LARGE_FLOAT && newbnd[5]>-VTK_LARGE_FLOAT){
267 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
268 m_CubeAxes->SetBounds(bnd);
271 cout << "Bounds AFTER: VisibleActors="<<aVisibleNum<<"\n"
272 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
273 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
274 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
276 m_CubeAxes->SetBounds(bnd);
278 ::ResetCameraClippingRange(m_Renderer);
281 void VTKViewer_ViewFrame::onAdjustTrihedron()
283 AdjustTrihedrons(false);
286 void VTKViewer_ViewFrame::onAdjustCubeAxes()
288 AdjustTrihedrons(false);
292 Display/hide Trihedron
294 void VTKViewer_ViewFrame::onViewTrihedron(){
296 if(!m_Triedron) return;
297 if(isTrihedronDisplayed()) m_Triedron->VisibilityOff();
298 else m_Triedron->VisibilityOn();
302 void VTKViewer_ViewFrame::onViewCubeAxes(){
303 if(!m_CubeAxes) return;
304 if(isCubeAxesDisplayed()) m_CubeAxes->VisibilityOff();
305 else m_CubeAxes->VisibilityOn();
311 Provides top projection of the active view
313 void VTKViewer_ViewFrame::onViewTop(){
314 vtkCamera* camera = m_Renderer->GetActiveCamera();
315 camera->SetPosition(0,0,1);
316 camera->SetViewUp(0,1,0);
317 camera->SetFocalPoint(0,0,0);
322 Provides bottom projection of the active view
324 void VTKViewer_ViewFrame::onViewBottom(){
325 vtkCamera* camera = m_Renderer->GetActiveCamera();
326 camera->SetPosition(0,0,-1);
327 camera->SetViewUp(0,1,0);
328 camera->SetFocalPoint(0,0,0);
333 Provides left projection of the active view
335 void VTKViewer_ViewFrame::onViewLeft(){
336 vtkCamera* camera = m_Renderer->GetActiveCamera();
337 camera->SetPosition(0,-1,0);
338 camera->SetViewUp(0,0,1);
339 camera->SetFocalPoint(0,0,0);
344 Provides right projection of the active view
346 void VTKViewer_ViewFrame::onViewRight(){
347 vtkCamera* camera = m_Renderer->GetActiveCamera();
348 camera->SetPosition(0,1,0);
349 camera->SetViewUp(0,0,1);
350 camera->SetFocalPoint(0,0,0);
355 Provides back projection of the active view
357 void VTKViewer_ViewFrame::onViewBack(){
358 vtkCamera* camera = m_Renderer->GetActiveCamera();
359 camera->SetPosition(-1,0,0);
360 camera->SetViewUp(0,0,1);
361 camera->SetFocalPoint(0,0,0);
366 Provides front projection of the active view
368 void VTKViewer_ViewFrame::onViewFront(){
369 vtkCamera* camera = m_Renderer->GetActiveCamera();
370 camera->SetPosition(1,0,0);
371 camera->SetViewUp(0,0,1);
372 camera->SetFocalPoint(0,0,0);
377 Fits all objects in the active view
379 void VTKViewer_ViewFrame::onViewFitAll(){
381 int aTriedronWasVisible = false;
382 int aCubeAxesWasVisible = false;
384 aTriedronWasVisible = isTrihedronDisplayed();
385 if(aTriedronWasVisible) m_Triedron->VisibilityOff();
388 aCubeAxesWasVisible = isCubeAxesDisplayed();
389 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff();
392 if(m_Triedron->GetVisibleActorCount(m_Renderer)){
393 m_Triedron->VisibilityOff();
394 m_CubeAxes->VisibilityOff();
395 ::ResetCamera(m_Renderer);
397 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
398 m_CubeAxes->SetVisibility(2);
399 ::ResetCamera(m_Renderer,true);
401 if(aTriedronWasVisible) m_Triedron->VisibilityOn();
402 else m_Triedron->VisibilityOff();
403 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOn();
404 else m_CubeAxes->VisibilityOff();
405 ::ResetCameraClippingRange(m_Renderer);
411 Reset the active view
413 void VTKViewer_ViewFrame::onViewReset(){
414 int aTriedronIsVisible = isTrihedronDisplayed();
415 int aCubeAxesIsVisible = isCubeAxesDisplayed();
417 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
418 m_CubeAxes->SetVisibility(0);
420 ::ResetCamera(m_Renderer,true);
421 vtkCamera* aCamera = m_Renderer->GetActiveCamera();
422 aCamera->SetPosition(1,-1,1);
423 aCamera->SetViewUp(0,0,1);
424 ::ResetCamera(m_Renderer,true);
426 if(aTriedronIsVisible) m_Triedron->VisibilityOn();
427 else m_Triedron->VisibilityOff();
429 if(aCubeAxesIsVisible) m_CubeAxes->VisibilityOn();
430 else m_CubeAxes->VisibilityOff();
432 static float aCoeff = 3.0;
433 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
438 Rotates the active view
440 void VTKViewer_ViewFrame::onViewRotate(){
441 m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
445 Sets a new center of the active view
447 void VTKViewer_ViewFrame::onViewGlobalPan(){
448 if(m_Triedron->GetVisibleActorCount(m_Renderer))
449 m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
453 Zooms the active view
455 void VTKViewer_ViewFrame::onViewZoom(){
456 m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
460 Moves the active view
462 void VTKViewer_ViewFrame::onViewPan(){
463 m_RWInteractor->GetInteractorStyleSALOME()->startPan();
467 Fits all obejcts within a rectangular area of the active view
469 void VTKViewer_ViewFrame::onViewFitArea(){
470 m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
474 Set background of the viewport
476 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
479 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
483 Returns background of the viewport
485 QColor VTKViewer_ViewFrame::backgroundColor() const
489 m_Renderer->GetBackground(backint);
490 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
492 return QMainWindow::backgroundColor();
496 void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
498 m_RWInteractor->SetSelectionMode( mode );
501 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
503 m_RWInteractor->rename(IObject, newName);
506 void VTKViewer_ViewFrame::unHighlightAll()
508 m_RWInteractor->unHighlightAll();
511 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
515 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
516 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
517 m_RWInteractor->highlight(IObject, highlight, update);
519 if(Sel->HasIndex(IObject) && IObject->hasEntry()){
520 TColStd_IndexedMapOfInteger MapIndex;
521 Sel->GetIndex(IObject,MapIndex);
522 using namespace SALOME::VTK;
523 const char* anEntry = IObject->getEntry();
524 vtkActorCollection* aCollection = getRenderer()->GetActors();
525 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
526 switch (Sel->SelectionMode()) {
528 m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
530 case EdgeOfCellSelection:
531 m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
536 case VolumeSelection:
537 m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
542 m_RWInteractor->unHighlightSubSelection();
546 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
548 return m_RWInteractor->isInViewer( IObject );
551 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
553 return m_RWInteractor->isVisible( IObject );
556 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
558 m_RW->setPopupServer( App );
562 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
564 using namespace SALOME::VTK;
565 SALOME_Actor* anActor =
566 Find<SALOME_Actor>(getRenderer()->GetActors(),
567 TIsSameEntry<SALOME_Actor>(theEntry));
569 return anActor->getIO();
571 return Handle(SALOME_InteractiveObject)();
575 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
577 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
578 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
579 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
581 m_RWInteractor->Display(theIObject,false);
582 ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
583 aSel->AddIObject(theIObject,false);
590 struct TDisplayAction{
591 SALOME_Selection* mySel;
592 Handle(SALOME_InteractiveObject) myIO;
593 TDisplayAction(SALOME_Selection* theSel,
594 Handle(SALOME_InteractiveObject) theIO):
595 mySel(theSel), myIO(theIO)
597 void operator()(SALOME_Actor* theActor){
598 theActor->SetVisibility(true);
599 mySel->AddIObject(myIO,false);
603 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
605 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
606 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
608 aSel->ClearIObjects();
609 //m_RWInteractor->EraseAll();
612 using namespace SALOME::VTK;
613 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
614 TIsSameIObject<SALOME_Actor>(theIObject),
615 TDisplayAction(aSel,theIObject));
617 ToolsGUI::SetVisibility(
618 aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
624 struct TEraseAction: TDisplayAction{
625 VTKViewer_RenderWindowInteractor* myRWInteractor;
626 TEraseAction(SALOME_Selection* theSel,
627 Handle(SALOME_InteractiveObject) theIO,
628 VTKViewer_RenderWindowInteractor* theRWInteractor):
629 TDisplayAction(theSel,theIO),
630 myRWInteractor(theRWInteractor)
632 void operator()(SALOME_Actor* theActor){
633 myRWInteractor->Erase(myIO,false);
634 mySel->RemoveIObject(myIO,false);
638 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
640 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
641 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
643 using namespace SALOME::VTK;
644 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
645 TIsSameIObject<SALOME_Actor>(theIObject),
646 TEraseAction(aSel,theIObject,m_RWInteractor));
648 ToolsGUI::SetVisibility(
649 aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
656 void VTKViewer_ViewFrame::DisplayAll()
658 m_RWInteractor->DisplayAll();
660 // update flag of visibility
661 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
662 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
663 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
664 const QString& aCompName = aDesktop->getComponentDataType();
665 SALOMEDS::SObject_var aComponent =
666 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
668 std::list<SALOMEDS::SObject_var> aList;
669 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
671 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
672 for ( ; anIter != aList.end(); ++anIter )
673 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
677 void VTKViewer_ViewFrame::EraseAll()
679 m_RWInteractor->EraseAll();
681 // update flag of visibility
682 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
683 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
684 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
685 const QString& aCompName = aDesktop->getComponentDataType();
686 SALOMEDS::SObject_var aComponent =
687 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
689 std::list<SALOMEDS::SObject_var> aList;
690 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
692 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
693 for ( ; anIter != aList.end(); ++anIter )
694 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
698 void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
700 if (theUpdateTrihedron) onAdjustTrihedron();
701 //if (theUpdateCubeAxes) onAdjustCubeAxes();
705 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
706 m_Transform->GetScale(theScale);
709 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
710 m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
711 m_RWInteractor->Render();
715 void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
716 theActor->AddToRender(m_Renderer);
717 theActor->SetTransform(m_Transform);
718 if(theMoveInternalActors)
719 m_RWInteractor->MoveInternalActors();
722 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
723 InsertActor(theActor);
728 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
729 theActor->RemoveFromRender(m_Renderer);
734 void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
736 RemoveActor(theActor);
737 InsertActor(theActor,true);
740 //==========================================================
742 * VTKViewer_ViewFrame::Display
743 * Display presentation
745 //==========================================================
746 void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
748 // try do downcast object
749 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
750 if ( !aVTKPrs || aVTKPrs->IsNull() )
753 vtkActorCollection* actors = aVTKPrs->GetObjects();
757 actors->InitTraversal();
759 while( ( actor = actors->GetNextActor() ) )
761 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
764 // just display the object
765 m_RWInteractor->Display( salomeActor, false );
767 // Set visibility flag
768 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
769 if ( !anObj.IsNull() && anObj->hasEntry() )
771 SALOMEDS::Study_var aStudy =
772 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
773 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
776 if ( salomeActor->IsSetCamera() )
777 salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
782 //==========================================================
784 * VTKViewer_ViewFrame::Erase
787 //==========================================================
788 void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
790 // try do downcast object
791 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
792 if ( !aVTKPrs || aVTKPrs->IsNull() )
795 vtkActorCollection* actors = aVTKPrs->GetObjects();
799 SALOMEDS::Study_var aStudy =
800 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
802 actors->InitTraversal();
804 while( ( actor = actors->GetNextActor() ) ) {
805 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
807 // just erase the object
809 m_RWInteractor->Remove( salomeActor, false );
811 m_RWInteractor->Erase( salomeActor, forced );
813 // Set visibility flag if necessary
816 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
817 if ( !anObj.IsNull() && anObj->hasEntry() )
818 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
824 //==========================================================
826 * VTKViewer_ViewFrame::CreatePrs
827 * Create presentation by entry
829 //==========================================================
830 SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
832 VTKViewer_Prs* prs = new VTKViewer_Prs();
834 vtkActorCollection* theActors = m_Renderer->GetActors();
835 theActors->InitTraversal();
837 while( ( ac = theActors->GetNextActor() ) ) {
838 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
839 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
840 prs->AddObject( ac );
847 //==========================================================
849 * VTKViewer_ViewFrame::BeforeDisplay
850 * Axiluary method called before displaying of objects
852 //==========================================================
853 void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
855 d->BeforeDisplay( this, SALOME_VTKViewType() );
858 //==========================================================
860 * VTKViewer_ViewFrame::AfterDisplay
861 * Axiluary method called after displaying of objects
863 //==========================================================
864 void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
866 d->AfterDisplay( this, SALOME_VTKViewType() );
869 //==========================================================
871 * VTKViewer_ViewFrame::undo
872 * Redisplay all objects in viewer
874 //==========================================================
875 void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
877 redisplayAll( theQADStudy, true );
880 //==========================================================
882 * VTKViewer_ViewFrame::redo
883 * Redisplay all objects in viewer
885 //==========================================================
886 void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
888 redisplayAll( theQADStudy, true );
891 //==========================================================
893 * VTKViewer_ViewFrame::redisplayAll
894 * Redisplay all objects in viewer
896 //==========================================================
897 void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
899 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
900 SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
901 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
902 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
903 const QString& aCompName = aDesktop->getComponentDataType();
904 SALOMEDS::SObject_var aComponent =
905 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
907 if ( aComponent->_is_nil() )
910 m_RWInteractor->RemoveAll( false );
911 //m_RWInteractor->EraseAll();
913 aSel->ClearIObjects();
916 // ENK commented, already added to renderer in
917 // VTKViewer_ViewFrame::VTKViewer_ViewFrame(...)
918 if ( isTrhDisplayed )
919 m_Triedron->AddToRender( m_Renderer );
922 std::list<SALOMEDS::SObject_var> aList;
923 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
925 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
926 for ( ; anIter != aList.end(); ++anIter )
928 SALOMEDS::SObject_var anObj = (*anIter);
929 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
931 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
932 anIObj->setEntry( anObj->GetID() );
933 aGUI->BuildPresentation( anIObj, this );
942 #define INCREMENT_FOR_OP 10
944 //=======================================================================
946 // Purpose : Performs incremental panning to the left
947 //=======================================================================
948 void VTKViewer_ViewFrame::onPanLeft()
950 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
953 //=======================================================================
955 // Purpose : Performs incremental panning to the right
956 //=======================================================================
957 void VTKViewer_ViewFrame::onPanRight()
959 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
962 //=======================================================================
964 // Purpose : Performs incremental panning to the top
965 //=======================================================================
966 void VTKViewer_ViewFrame::onPanUp()
968 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
971 //=======================================================================
973 // Purpose : Performs incremental panning to the bottom
974 //=======================================================================
975 void VTKViewer_ViewFrame::onPanDown()
977 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
980 //=======================================================================
982 // Purpose : Performs incremental zooming in
983 //=======================================================================
984 void VTKViewer_ViewFrame::onZoomIn()
986 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
989 //=======================================================================
991 // Purpose : Performs incremental zooming out
992 //=======================================================================
993 void VTKViewer_ViewFrame::onZoomOut()
995 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
998 //=======================================================================
999 // name : onRotateLeft
1000 // Purpose : Performs incremental rotating to the left
1001 //=======================================================================
1002 void VTKViewer_ViewFrame::onRotateLeft()
1004 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
1007 //=======================================================================
1008 // name : onRotateRight
1009 // Purpose : Performs incremental rotating to the right
1010 //=======================================================================
1011 void VTKViewer_ViewFrame::onRotateRight()
1013 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
1016 //=======================================================================
1017 // name : onRotateUp
1018 // Purpose : Performs incremental rotating to the top
1019 //=======================================================================
1020 void VTKViewer_ViewFrame::onRotateUp()
1022 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
1025 //=======================================================================
1026 // name : onRotateDown
1027 // Purpose : Performs incremental rotating to the bottom
1028 //=======================================================================
1029 void VTKViewer_ViewFrame::onRotateDown()
1031 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );