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);
154 m_CubeAxes->VisibilityOff();
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);
230 if(aTDisplayed) m_Triedron->VisibilityOn();
231 if(aCDisplayed) m_CubeAxes->VisibilityOn();
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];
264 if( newbnd[0]<VTK_LARGE_FLOAT && newbnd[2]<VTK_LARGE_FLOAT && newbnd[4]<VTK_LARGE_FLOAT &&
265 newbnd[1]>-VTK_LARGE_FLOAT && newbnd[3]>-VTK_LARGE_FLOAT && newbnd[5]>-VTK_LARGE_FLOAT){
266 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
267 m_CubeAxes->SetBounds(bnd);
270 cout << "Bounds AFTER: VisibleActors="<<aVisibleNum<<"\n"
271 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
272 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
273 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
275 m_CubeAxes->SetBounds(bnd);
277 ::ResetCameraClippingRange(m_Renderer);
280 void VTKViewer_ViewFrame::onAdjustTrihedron()
282 AdjustTrihedrons(false);
285 void VTKViewer_ViewFrame::onAdjustCubeAxes()
287 AdjustTrihedrons(false);
291 Display/hide Trihedron
293 void VTKViewer_ViewFrame::onViewTrihedron(){
294 if(!m_Triedron) return;
295 if(isTrihedronDisplayed()) m_Triedron->VisibilityOff();
296 else m_Triedron->VisibilityOn();
300 void VTKViewer_ViewFrame::onViewCubeAxes(){
301 if(!m_CubeAxes) return;
302 if(isCubeAxesDisplayed()) m_CubeAxes->VisibilityOff();
303 else m_CubeAxes->VisibilityOn();
309 Provides top projection of the active view
311 void VTKViewer_ViewFrame::onViewTop(){
312 vtkCamera* camera = m_Renderer->GetActiveCamera();
313 camera->SetPosition(0,0,1);
314 camera->SetViewUp(0,1,0);
315 camera->SetFocalPoint(0,0,0);
320 Provides bottom projection of the active view
322 void VTKViewer_ViewFrame::onViewBottom(){
323 vtkCamera* camera = m_Renderer->GetActiveCamera();
324 camera->SetPosition(0,0,-1);
325 camera->SetViewUp(0,1,0);
326 camera->SetFocalPoint(0,0,0);
331 Provides left projection of the active view
333 void VTKViewer_ViewFrame::onViewLeft(){
334 vtkCamera* camera = m_Renderer->GetActiveCamera();
335 camera->SetPosition(0,-1,0);
336 camera->SetViewUp(0,0,1);
337 camera->SetFocalPoint(0,0,0);
342 Provides right projection of the active view
344 void VTKViewer_ViewFrame::onViewRight(){
345 vtkCamera* camera = m_Renderer->GetActiveCamera();
346 camera->SetPosition(0,1,0);
347 camera->SetViewUp(0,0,1);
348 camera->SetFocalPoint(0,0,0);
353 Provides back projection of the active view
355 void VTKViewer_ViewFrame::onViewBack(){
356 vtkCamera* camera = m_Renderer->GetActiveCamera();
357 camera->SetPosition(-1,0,0);
358 camera->SetViewUp(0,0,1);
359 camera->SetFocalPoint(0,0,0);
364 Provides front projection of the active view
366 void VTKViewer_ViewFrame::onViewFront(){
367 vtkCamera* camera = m_Renderer->GetActiveCamera();
368 camera->SetPosition(1,0,0);
369 camera->SetViewUp(0,0,1);
370 camera->SetFocalPoint(0,0,0);
375 Fits all objects in the active view
377 void VTKViewer_ViewFrame::onViewFitAll(){
379 int aTriedronWasVisible = false;
380 int aCubeAxesWasVisible = false;
382 aTriedronWasVisible = isTrihedronDisplayed();
383 if(aTriedronWasVisible) m_Triedron->VisibilityOff();
386 aCubeAxesWasVisible = isCubeAxesDisplayed();
387 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff();
390 if(m_Triedron->GetVisibleActorCount(m_Renderer)){
391 m_Triedron->VisibilityOff();
392 m_CubeAxes->VisibilityOff();
393 ::ResetCamera(m_Renderer);
395 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
396 m_CubeAxes->SetVisibility(2);
397 ::ResetCamera(m_Renderer,true);
399 if(aTriedronWasVisible) m_Triedron->VisibilityOn();
400 else m_Triedron->VisibilityOff();
401 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOn();
402 else m_CubeAxes->VisibilityOff();
403 ::ResetCameraClippingRange(m_Renderer);
409 Reset the active view
411 void VTKViewer_ViewFrame::onViewReset(){
412 int aTriedronIsVisible = isTrihedronDisplayed();
413 int aCubeAxesIsVisible = isCubeAxesDisplayed();
415 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
416 m_CubeAxes->SetVisibility(0);
418 ::ResetCamera(m_Renderer,true);
419 vtkCamera* aCamera = m_Renderer->GetActiveCamera();
420 aCamera->SetPosition(1,-1,1);
421 aCamera->SetViewUp(0,0,1);
422 ::ResetCamera(m_Renderer,true);
424 if(aTriedronIsVisible) m_Triedron->VisibilityOn();
425 else m_Triedron->VisibilityOff();
427 if(aCubeAxesIsVisible) m_CubeAxes->VisibilityOn();
428 else m_CubeAxes->VisibilityOff();
430 static float aCoeff = 3.0;
431 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
436 Rotates the active view
438 void VTKViewer_ViewFrame::onViewRotate(){
439 m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
443 Sets a new center of the active view
445 void VTKViewer_ViewFrame::onViewGlobalPan(){
446 if(m_Triedron->GetVisibleActorCount(m_Renderer))
447 m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
451 Zooms the active view
453 void VTKViewer_ViewFrame::onViewZoom(){
454 m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
458 Moves the active view
460 void VTKViewer_ViewFrame::onViewPan(){
461 m_RWInteractor->GetInteractorStyleSALOME()->startPan();
465 Fits all obejcts within a rectangular area of the active view
467 void VTKViewer_ViewFrame::onViewFitArea(){
468 m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
472 Set background of the viewport
474 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
477 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
481 Returns background of the viewport
483 QColor VTKViewer_ViewFrame::backgroundColor() const
487 m_Renderer->GetBackground(backint);
488 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
490 return QMainWindow::backgroundColor();
494 void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
496 m_RWInteractor->SetSelectionMode( mode );
499 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
501 m_RWInteractor->rename(IObject, newName);
504 void VTKViewer_ViewFrame::unHighlightAll()
506 m_RWInteractor->unHighlightAll();
509 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
513 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
514 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
515 m_RWInteractor->highlight(IObject, highlight, update);
517 if(Sel->HasIndex(IObject) && IObject->hasEntry()){
518 TColStd_IndexedMapOfInteger MapIndex;
519 Sel->GetIndex(IObject,MapIndex);
520 using namespace SALOME::VTK;
521 const char* anEntry = IObject->getEntry();
522 vtkActorCollection* aCollection = getRenderer()->GetActors();
523 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
524 switch (Sel->SelectionMode()) {
526 m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
528 case EdgeOfCellSelection:
529 m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
534 case VolumeSelection:
535 m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
540 m_RWInteractor->unHighlightSubSelection();
544 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
546 return m_RWInteractor->isInViewer( IObject );
549 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
551 return m_RWInteractor->isVisible( IObject );
554 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
556 m_RW->setPopupServer( App );
560 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
562 using namespace SALOME::VTK;
563 SALOME_Actor* anActor =
564 Find<SALOME_Actor>(getRenderer()->GetActors(),
565 TIsSameEntry<SALOME_Actor>(theEntry));
567 return anActor->getIO();
569 return Handle(SALOME_InteractiveObject)();
573 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
575 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
576 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
577 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
579 m_RWInteractor->Display(theIObject,false);
580 ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
581 aSel->AddIObject(theIObject,false);
588 struct TDisplayAction{
589 SALOME_Selection* mySel;
590 Handle(SALOME_InteractiveObject) myIO;
591 TDisplayAction(SALOME_Selection* theSel,
592 Handle(SALOME_InteractiveObject) theIO):
593 mySel(theSel), myIO(theIO)
595 void operator()(SALOME_Actor* theActor){
596 theActor->SetVisibility(true);
597 mySel->AddIObject(myIO,false);
601 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
603 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
604 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
606 aSel->ClearIObjects();
607 //m_RWInteractor->EraseAll();
610 using namespace SALOME::VTK;
611 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
612 TIsSameIObject<SALOME_Actor>(theIObject),
613 TDisplayAction(aSel,theIObject));
615 ToolsGUI::SetVisibility(
616 aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
622 struct TEraseAction: TDisplayAction{
623 VTKViewer_RenderWindowInteractor* myRWInteractor;
624 TEraseAction(SALOME_Selection* theSel,
625 Handle(SALOME_InteractiveObject) theIO,
626 VTKViewer_RenderWindowInteractor* theRWInteractor):
627 TDisplayAction(theSel,theIO),
628 myRWInteractor(theRWInteractor)
630 void operator()(SALOME_Actor* theActor){
631 myRWInteractor->Erase(myIO,false);
632 mySel->RemoveIObject(myIO,false);
636 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
638 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
639 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
641 using namespace SALOME::VTK;
642 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
643 TIsSameIObject<SALOME_Actor>(theIObject),
644 TEraseAction(aSel,theIObject,m_RWInteractor));
646 ToolsGUI::SetVisibility(
647 aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
654 void VTKViewer_ViewFrame::DisplayAll()
656 m_RWInteractor->DisplayAll();
658 // update flag of visibility
659 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
660 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
661 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
662 const QString& aCompName = aDesktop->getComponentDataType();
663 SALOMEDS::SObject_var aComponent =
664 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
666 std::list<SALOMEDS::SObject_var> aList;
667 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
669 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
670 for ( ; anIter != aList.end(); ++anIter )
671 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
675 void VTKViewer_ViewFrame::EraseAll()
677 m_RWInteractor->EraseAll();
679 // update flag of visibility
680 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
681 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
682 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
683 const QString& aCompName = aDesktop->getComponentDataType();
684 SALOMEDS::SObject_var aComponent =
685 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
687 std::list<SALOMEDS::SObject_var> aList;
688 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
690 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
691 for ( ; anIter != aList.end(); ++anIter )
692 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
696 void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
698 if (theUpdateTrihedron) onAdjustTrihedron();
699 //if (theUpdateCubeAxes) onAdjustCubeAxes();
703 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
704 m_Transform->GetScale(theScale);
707 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
708 m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
709 m_RWInteractor->Render();
713 void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
714 theActor->AddToRender(m_Renderer);
715 theActor->SetTransform(m_Transform);
716 if(theMoveInternalActors)
717 m_RWInteractor->MoveInternalActors();
720 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
721 InsertActor(theActor);
726 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
727 theActor->RemoveFromRender(m_Renderer);
732 void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
734 RemoveActor(theActor);
735 InsertActor(theActor,true);
738 //==========================================================
740 * VTKViewer_ViewFrame::Display
741 * Display presentation
743 //==========================================================
744 void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
746 // try do downcast object
747 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
748 if ( !aVTKPrs || aVTKPrs->IsNull() )
751 vtkActorCollection* actors = aVTKPrs->GetObjects();
755 actors->InitTraversal();
757 while( ( actor = actors->GetNextActor() ) )
759 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
762 // just display the object
763 m_RWInteractor->Display( salomeActor, false );
765 // Set visibility flag
766 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
767 if ( !anObj.IsNull() && anObj->hasEntry() )
769 SALOMEDS::Study_var aStudy =
770 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
771 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
774 if ( salomeActor->IsSetCamera() )
775 salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
780 //==========================================================
782 * VTKViewer_ViewFrame::Erase
785 //==========================================================
786 void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
788 // try do downcast object
789 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
790 if ( !aVTKPrs || aVTKPrs->IsNull() )
793 vtkActorCollection* actors = aVTKPrs->GetObjects();
797 SALOMEDS::Study_var aStudy =
798 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
800 actors->InitTraversal();
802 while( ( actor = actors->GetNextActor() ) ) {
803 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
805 // just erase the object
807 m_RWInteractor->Remove( salomeActor, false );
809 m_RWInteractor->Erase( salomeActor, forced );
811 // Set visibility flag if necessary
814 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
815 if ( !anObj.IsNull() && anObj->hasEntry() )
816 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
822 //==========================================================
824 * VTKViewer_ViewFrame::CreatePrs
825 * Create presentation by entry
827 //==========================================================
828 SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
830 VTKViewer_Prs* prs = new VTKViewer_Prs();
832 vtkActorCollection* theActors = m_Renderer->GetActors();
833 theActors->InitTraversal();
835 while( ( ac = theActors->GetNextActor() ) ) {
836 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
837 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
838 prs->AddObject( ac );
845 //==========================================================
847 * VTKViewer_ViewFrame::BeforeDisplay
848 * Axiluary method called before displaying of objects
850 //==========================================================
851 void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
853 d->BeforeDisplay( this, SALOME_VTKViewType() );
856 //==========================================================
858 * VTKViewer_ViewFrame::AfterDisplay
859 * Axiluary method called after displaying of objects
861 //==========================================================
862 void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
864 d->AfterDisplay( this, SALOME_VTKViewType() );
867 //==========================================================
869 * VTKViewer_ViewFrame::undo
870 * Redisplay all objects in viewer
872 //==========================================================
873 void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
875 redisplayAll( theQADStudy, true );
878 //==========================================================
880 * VTKViewer_ViewFrame::redo
881 * Redisplay all objects in viewer
883 //==========================================================
884 void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
886 redisplayAll( theQADStudy, true );
889 //==========================================================
891 * VTKViewer_ViewFrame::redisplayAll
892 * Redisplay all objects in viewer
894 //==========================================================
895 void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
897 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
898 SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
899 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
900 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
901 const QString& aCompName = aDesktop->getComponentDataType();
902 SALOMEDS::SObject_var aComponent =
903 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
905 if ( aComponent->_is_nil() )
908 m_RWInteractor->RemoveAll( false );
909 //m_RWInteractor->EraseAll();
911 aSel->ClearIObjects();
914 // ENK commented, already added to renderer in
915 // VTKViewer_ViewFrame::VTKViewer_ViewFrame(...)
916 if ( isTrhDisplayed )
917 m_Triedron->AddToRender( m_Renderer );
920 std::list<SALOMEDS::SObject_var> aList;
921 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
923 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
924 for ( ; anIter != aList.end(); ++anIter )
926 SALOMEDS::SObject_var anObj = (*anIter);
927 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
929 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
930 anIObj->setEntry( anObj->GetID() );
931 aGUI->BuildPresentation( anIObj, this );
940 #define INCREMENT_FOR_OP 10
942 //=======================================================================
944 // Purpose : Performs incremental panning to the left
945 //=======================================================================
946 void VTKViewer_ViewFrame::onPanLeft()
948 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
951 //=======================================================================
953 // Purpose : Performs incremental panning to the right
954 //=======================================================================
955 void VTKViewer_ViewFrame::onPanRight()
957 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
960 //=======================================================================
962 // Purpose : Performs incremental panning to the top
963 //=======================================================================
964 void VTKViewer_ViewFrame::onPanUp()
966 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
969 //=======================================================================
971 // Purpose : Performs incremental panning to the bottom
972 //=======================================================================
973 void VTKViewer_ViewFrame::onPanDown()
975 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
978 //=======================================================================
980 // Purpose : Performs incremental zooming in
981 //=======================================================================
982 void VTKViewer_ViewFrame::onZoomIn()
984 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
987 //=======================================================================
989 // Purpose : Performs incremental zooming out
990 //=======================================================================
991 void VTKViewer_ViewFrame::onZoomOut()
993 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
996 //=======================================================================
997 // name : onRotateLeft
998 // Purpose : Performs incremental rotating to the left
999 //=======================================================================
1000 void VTKViewer_ViewFrame::onRotateLeft()
1002 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
1005 //=======================================================================
1006 // name : onRotateRight
1007 // Purpose : Performs incremental rotating to the right
1008 //=======================================================================
1009 void VTKViewer_ViewFrame::onRotateRight()
1011 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
1014 //=======================================================================
1015 // name : onRotateUp
1016 // Purpose : Performs incremental rotating to the top
1017 //=======================================================================
1018 void VTKViewer_ViewFrame::onRotateUp()
1020 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
1023 //=======================================================================
1024 // name : onRotateDown
1025 // Purpose : Performs incremental rotating to the bottom
1026 //=======================================================================
1027 void VTKViewer_ViewFrame::onRotateDown()
1029 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );