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() && !aSActor->IsInfinitive()){
243 float *abounds = aSActor->GetBounds();
245 cout << "Bounds: Actor="<<aSActor<<"\n"
246 << "\txMin=" << abounds[ 0 ] << " xMax=" << abounds[ 1 ] << "\n"
247 << "\tyMin=" << abounds[ 2 ] << " yMax=" << abounds[ 3 ] << "\n"
248 << "\tzMin=" << abounds[ 4 ] << " zMax=" << abounds[ 5 ] << "\n";
249 if ( abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
250 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
251 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
252 for(int i=0;i<5;i=i+2){
253 if(abounds[i]<newbnd[i]) newbnd[i]=abounds[i];
254 if(abounds[i+1]>newbnd[i+1]) newbnd[i+1]=abounds[i+1];
260 if(aTDisplayed) m_Triedron->VisibilityOn();
261 if(aCDisplayed) m_CubeAxes->VisibilityOn();
264 double aSize = m_Triedron->GetSize();
265 newbnd[0] = newbnd[2] = newbnd[4] = 0;
266 newbnd[1] = newbnd[3] = newbnd[5] = aSize;
269 if( newbnd[0]<VTK_LARGE_FLOAT && newbnd[2]<VTK_LARGE_FLOAT && newbnd[4]<VTK_LARGE_FLOAT &&
270 newbnd[1]>-VTK_LARGE_FLOAT && newbnd[3]>-VTK_LARGE_FLOAT && newbnd[5]>-VTK_LARGE_FLOAT){
271 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
272 m_CubeAxes->SetBounds(bnd);
275 cout << "Bounds AFTER: VisibleActors="<<aVisibleNum<<"\n"
276 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
277 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
278 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
280 m_CubeAxes->SetBounds(bnd);
282 ::ResetCameraClippingRange(m_Renderer);
285 void VTKViewer_ViewFrame::onAdjustTrihedron()
287 AdjustTrihedrons(false);
290 void VTKViewer_ViewFrame::onAdjustCubeAxes()
292 AdjustTrihedrons(false);
296 Display/hide Trihedron
298 void VTKViewer_ViewFrame::onViewTrihedron(){
299 if(!m_Triedron) return;
300 if(isTrihedronDisplayed()) m_Triedron->VisibilityOff();
301 else m_Triedron->VisibilityOn();
305 void VTKViewer_ViewFrame::onViewCubeAxes(){
306 if(!m_CubeAxes) return;
307 if(isCubeAxesDisplayed()) m_CubeAxes->VisibilityOff();
308 else m_CubeAxes->VisibilityOn();
314 Provides top projection of the active view
316 void VTKViewer_ViewFrame::onViewTop(){
317 vtkCamera* camera = m_Renderer->GetActiveCamera();
318 camera->SetPosition(0,0,1);
319 camera->SetViewUp(0,1,0);
320 camera->SetFocalPoint(0,0,0);
325 Provides bottom projection of the active view
327 void VTKViewer_ViewFrame::onViewBottom(){
328 vtkCamera* camera = m_Renderer->GetActiveCamera();
329 camera->SetPosition(0,0,-1);
330 camera->SetViewUp(0,1,0);
331 camera->SetFocalPoint(0,0,0);
336 Provides left projection of the active view
338 void VTKViewer_ViewFrame::onViewLeft(){
339 vtkCamera* camera = m_Renderer->GetActiveCamera();
340 camera->SetPosition(0,-1,0);
341 camera->SetViewUp(0,0,1);
342 camera->SetFocalPoint(0,0,0);
347 Provides right projection of the active view
349 void VTKViewer_ViewFrame::onViewRight(){
350 vtkCamera* camera = m_Renderer->GetActiveCamera();
351 camera->SetPosition(0,1,0);
352 camera->SetViewUp(0,0,1);
353 camera->SetFocalPoint(0,0,0);
358 Provides back projection of the active view
360 void VTKViewer_ViewFrame::onViewBack(){
361 vtkCamera* camera = m_Renderer->GetActiveCamera();
362 camera->SetPosition(-1,0,0);
363 camera->SetViewUp(0,0,1);
364 camera->SetFocalPoint(0,0,0);
369 Provides front projection of the active view
371 void VTKViewer_ViewFrame::onViewFront(){
372 vtkCamera* camera = m_Renderer->GetActiveCamera();
373 camera->SetPosition(1,0,0);
374 camera->SetViewUp(0,0,1);
375 camera->SetFocalPoint(0,0,0);
380 Fits all objects in the active view
382 void VTKViewer_ViewFrame::onViewFitAll(){
384 int aTriedronWasVisible = false;
385 int aCubeAxesWasVisible = false;
387 aTriedronWasVisible = isTrihedronDisplayed();
388 if(aTriedronWasVisible) m_Triedron->VisibilityOff();
391 aCubeAxesWasVisible = isCubeAxesDisplayed();
392 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOff();
395 if(m_Triedron->GetVisibleActorCount(m_Renderer)){
396 m_Triedron->VisibilityOff();
397 m_CubeAxes->VisibilityOff();
398 ::ResetCamera(m_Renderer);
400 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
401 m_CubeAxes->SetVisibility(2);
402 ::ResetCamera(m_Renderer,true);
404 if(aTriedronWasVisible) m_Triedron->VisibilityOn();
405 else m_Triedron->VisibilityOff();
406 if(aCubeAxesWasVisible) m_CubeAxes->VisibilityOn();
407 else m_CubeAxes->VisibilityOff();
408 ::ResetCameraClippingRange(m_Renderer);
414 Reset the active view
416 void VTKViewer_ViewFrame::onViewReset(){
417 int aTriedronIsVisible = isTrihedronDisplayed();
418 int aCubeAxesIsVisible = isCubeAxesDisplayed();
420 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
421 m_CubeAxes->SetVisibility(0);
423 ::ResetCamera(m_Renderer,true);
424 vtkCamera* aCamera = m_Renderer->GetActiveCamera();
425 aCamera->SetPosition(1,-1,1);
426 aCamera->SetViewUp(0,0,1);
427 ::ResetCamera(m_Renderer,true);
429 if(aTriedronIsVisible) m_Triedron->VisibilityOn();
430 else m_Triedron->VisibilityOff();
432 if(aCubeAxesIsVisible) m_CubeAxes->VisibilityOn();
433 else m_CubeAxes->VisibilityOff();
435 static float aCoeff = 3.0;
436 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
441 Rotates the active view
443 void VTKViewer_ViewFrame::onViewRotate(){
444 m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
448 Sets a new center of the active view
450 void VTKViewer_ViewFrame::onViewGlobalPan(){
451 if(m_Triedron->GetVisibleActorCount(m_Renderer))
452 m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
456 Zooms the active view
458 void VTKViewer_ViewFrame::onViewZoom(){
459 m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
463 Moves the active view
465 void VTKViewer_ViewFrame::onViewPan(){
466 m_RWInteractor->GetInteractorStyleSALOME()->startPan();
470 Fits all obejcts within a rectangular area of the active view
472 void VTKViewer_ViewFrame::onViewFitArea(){
473 m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
477 Set background of the viewport
479 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
482 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
486 Returns background of the viewport
488 QColor VTKViewer_ViewFrame::backgroundColor() const
492 m_Renderer->GetBackground(backint);
493 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
495 return QMainWindow::backgroundColor();
499 void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
501 m_RWInteractor->SetSelectionMode( mode );
504 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
506 m_RWInteractor->rename(IObject, newName);
509 void VTKViewer_ViewFrame::unHighlightAll()
511 m_RWInteractor->unHighlightAll();
514 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
518 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
519 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
520 m_RWInteractor->highlight(IObject, highlight, update);
522 if(Sel->HasIndex(IObject) && IObject->hasEntry()){
523 TColStd_IndexedMapOfInteger MapIndex;
524 Sel->GetIndex(IObject,MapIndex);
525 using namespace SALOME::VTK;
526 const char* anEntry = IObject->getEntry();
527 vtkActorCollection* aCollection = getRenderer()->GetActors();
528 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
529 switch (Sel->SelectionMode()) {
531 m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
533 case EdgeOfCellSelection:
534 m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
539 case VolumeSelection:
540 m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
545 m_RWInteractor->unHighlightSubSelection();
549 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
551 return m_RWInteractor->isInViewer( IObject );
554 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
556 return m_RWInteractor->isVisible( IObject );
559 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
561 m_RW->setPopupServer( App );
565 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
567 using namespace SALOME::VTK;
568 SALOME_Actor* anActor =
569 Find<SALOME_Actor>(getRenderer()->GetActors(),
570 TIsSameEntry<SALOME_Actor>(theEntry));
572 return anActor->getIO();
574 return Handle(SALOME_InteractiveObject)();
578 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
580 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
581 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
582 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
584 m_RWInteractor->Display(theIObject,false);
585 ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
586 aSel->AddIObject(theIObject,false);
593 struct TDisplayAction{
594 SALOME_Selection* mySel;
595 Handle(SALOME_InteractiveObject) myIO;
596 TDisplayAction(SALOME_Selection* theSel,
597 Handle(SALOME_InteractiveObject) theIO):
598 mySel(theSel), myIO(theIO)
600 void operator()(SALOME_Actor* theActor){
601 theActor->SetVisibility(true);
602 mySel->AddIObject(myIO,false);
606 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
608 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
609 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
611 aSel->ClearIObjects();
612 //m_RWInteractor->EraseAll();
615 using namespace SALOME::VTK;
616 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
617 TIsSameIObject<SALOME_Actor>(theIObject),
618 TDisplayAction(aSel,theIObject));
620 ToolsGUI::SetVisibility(
621 aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
627 struct TEraseAction: TDisplayAction{
628 VTKViewer_RenderWindowInteractor* myRWInteractor;
629 TEraseAction(SALOME_Selection* theSel,
630 Handle(SALOME_InteractiveObject) theIO,
631 VTKViewer_RenderWindowInteractor* theRWInteractor):
632 TDisplayAction(theSel,theIO),
633 myRWInteractor(theRWInteractor)
635 void operator()(SALOME_Actor* theActor){
636 myRWInteractor->Erase(myIO,false);
637 mySel->RemoveIObject(myIO,false);
641 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
643 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
644 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
646 using namespace SALOME::VTK;
647 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
648 TIsSameIObject<SALOME_Actor>(theIObject),
649 TEraseAction(aSel,theIObject,m_RWInteractor));
651 ToolsGUI::SetVisibility(
652 aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
659 void VTKViewer_ViewFrame::DisplayAll()
661 m_RWInteractor->DisplayAll();
663 // update flag of visibility
664 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
665 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
666 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
667 const QString& aCompName = aDesktop->getComponentDataType();
668 SALOMEDS::SObject_var aComponent =
669 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
671 std::list<SALOMEDS::SObject_var> aList;
672 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
674 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
675 for ( ; anIter != aList.end(); ++anIter )
676 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
680 void VTKViewer_ViewFrame::EraseAll()
682 m_RWInteractor->EraseAll();
684 // update flag of visibility
685 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
686 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
687 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
688 const QString& aCompName = aDesktop->getComponentDataType();
689 SALOMEDS::SObject_var aComponent =
690 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
692 std::list<SALOMEDS::SObject_var> aList;
693 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
695 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
696 for ( ; anIter != aList.end(); ++anIter )
697 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
701 void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
703 if (theUpdateTrihedron) onAdjustTrihedron();
704 //if (theUpdateCubeAxes) onAdjustCubeAxes();
708 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
709 m_Transform->GetMatrixScale(theScale);
712 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
713 m_Transform->SetMatrixScale(theScale[0], theScale[1], theScale[2]);
714 m_RWInteractor->Render();
718 void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
719 theActor->AddToRender(m_Renderer);
720 theActor->SetTransform(m_Transform);
721 if(theMoveInternalActors)
722 m_RWInteractor->MoveInternalActors();
725 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
726 InsertActor(theActor);
731 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
732 theActor->RemoveFromRender(m_Renderer);
737 void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
739 RemoveActor(theActor);
740 InsertActor(theActor,true);
743 //==========================================================
745 * VTKViewer_ViewFrame::Display
746 * Display presentation
748 //==========================================================
749 void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
751 // try do downcast object
752 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
753 if ( !aVTKPrs || aVTKPrs->IsNull() )
756 vtkActorCollection* actors = aVTKPrs->GetObjects();
760 actors->InitTraversal();
762 while( ( actor = actors->GetNextActor() ) )
764 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
767 // just display the object
768 m_RWInteractor->Display( salomeActor, false );
770 // Set visibility flag
771 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
772 if ( !anObj.IsNull() && anObj->hasEntry() )
774 SALOMEDS::Study_var aStudy =
775 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
776 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
779 if ( salomeActor->IsSetCamera() )
780 salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
785 //==========================================================
787 * VTKViewer_ViewFrame::Erase
790 //==========================================================
791 void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
793 // try do downcast object
794 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
795 if ( !aVTKPrs || aVTKPrs->IsNull() )
798 vtkActorCollection* actors = aVTKPrs->GetObjects();
802 SALOMEDS::Study_var aStudy =
803 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
805 actors->InitTraversal();
807 while( ( actor = actors->GetNextActor() ) ) {
808 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
810 // just erase the object
812 m_RWInteractor->Remove( salomeActor, false );
814 m_RWInteractor->Erase( salomeActor, forced );
816 // Set visibility flag if necessary
819 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
820 if ( !anObj.IsNull() && anObj->hasEntry() )
821 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
827 //==========================================================
829 * VTKViewer_ViewFrame::CreatePrs
830 * Create presentation by entry
832 //==========================================================
833 SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
835 VTKViewer_Prs* prs = new VTKViewer_Prs();
837 vtkActorCollection* theActors = m_Renderer->GetActors();
838 theActors->InitTraversal();
840 while( ( ac = theActors->GetNextActor() ) ) {
841 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
842 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
843 prs->AddObject( ac );
850 //==========================================================
852 * VTKViewer_ViewFrame::BeforeDisplay
853 * Axiluary method called before displaying of objects
855 //==========================================================
856 void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
858 d->BeforeDisplay( this, SALOME_VTKViewType() );
861 //==========================================================
863 * VTKViewer_ViewFrame::AfterDisplay
864 * Axiluary method called after displaying of objects
866 //==========================================================
867 void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
869 d->AfterDisplay( this, SALOME_VTKViewType() );
872 //==========================================================
874 * VTKViewer_ViewFrame::undo
875 * Redisplay all objects in viewer
877 //==========================================================
878 void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
880 redisplayAll( theQADStudy, true );
883 //==========================================================
885 * VTKViewer_ViewFrame::redo
886 * Redisplay all objects in viewer
888 //==========================================================
889 void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
891 redisplayAll( theQADStudy, true );
894 //==========================================================
896 * VTKViewer_ViewFrame::redisplayAll
897 * Redisplay all objects in viewer
899 //==========================================================
900 void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
902 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
903 SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
904 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
905 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
906 const QString& aCompName = aDesktop->getComponentDataType();
907 SALOMEDS::SObject_var aComponent =
908 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
910 if ( aComponent->_is_nil() )
913 m_RWInteractor->RemoveAll( false );
914 //m_RWInteractor->EraseAll();
916 aSel->ClearIObjects();
919 // ENK commented, already added to renderer in
920 // VTKViewer_ViewFrame::VTKViewer_ViewFrame(...)
921 if ( isTrhDisplayed )
922 m_Triedron->AddToRender( m_Renderer );
925 std::list<SALOMEDS::SObject_var> aList;
926 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
928 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
929 for ( ; anIter != aList.end(); ++anIter )
931 SALOMEDS::SObject_var anObj = (*anIter);
932 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
934 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
935 anIObj->setEntry( anObj->GetID() );
936 aGUI->BuildPresentation( anIObj, this );
945 #define INCREMENT_FOR_OP 10
947 //=======================================================================
949 // Purpose : Performs incremental panning to the left
950 //=======================================================================
951 void VTKViewer_ViewFrame::onPanLeft()
953 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
956 //=======================================================================
958 // Purpose : Performs incremental panning to the right
959 //=======================================================================
960 void VTKViewer_ViewFrame::onPanRight()
962 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
965 //=======================================================================
967 // Purpose : Performs incremental panning to the top
968 //=======================================================================
969 void VTKViewer_ViewFrame::onPanUp()
971 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
974 //=======================================================================
976 // Purpose : Performs incremental panning to the bottom
977 //=======================================================================
978 void VTKViewer_ViewFrame::onPanDown()
980 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
983 //=======================================================================
985 // Purpose : Performs incremental zooming in
986 //=======================================================================
987 void VTKViewer_ViewFrame::onZoomIn()
989 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
992 //=======================================================================
994 // Purpose : Performs incremental zooming out
995 //=======================================================================
996 void VTKViewer_ViewFrame::onZoomOut()
998 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
1001 //=======================================================================
1002 // name : onRotateLeft
1003 // Purpose : Performs incremental rotating to the left
1004 //=======================================================================
1005 void VTKViewer_ViewFrame::onRotateLeft()
1007 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
1010 //=======================================================================
1011 // name : onRotateRight
1012 // Purpose : Performs incremental rotating to the right
1013 //=======================================================================
1014 void VTKViewer_ViewFrame::onRotateRight()
1016 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
1019 //=======================================================================
1020 // name : onRotateUp
1021 // Purpose : Performs incremental rotating to the top
1022 //=======================================================================
1023 void VTKViewer_ViewFrame::onRotateUp()
1025 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
1028 //=======================================================================
1029 // name : onRotateDown
1030 // Purpose : Performs incremental rotating to the bottom
1031 //=======================================================================
1032 void VTKViewer_ViewFrame::onRotateDown()
1034 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );