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);
131 RWS->setTriedron(m_Triedron);
132 RWS->setCubeAxes(m_CubeAxes);
134 RWS->setViewFrame(this);
135 //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
136 RWS->FindPokedRenderer(0, 0);
138 vtkTextProperty* tprop = vtkTextProperty::New();
139 tprop->SetColor(1, 1, 1);
143 bnd[0] = bnd[2] = bnd[4] = 0;
144 bnd[1] = bnd[3] = bnd[5] = m_Triedron->GetSize();
145 m_CubeAxes->SetLabelFormat("%6.4g");
146 m_CubeAxes->SetBounds(bnd);
147 m_CubeAxes->SetCamera(m_Renderer->GetActiveCamera());
148 m_CubeAxes->SetLabelFormat("%6.4g");
149 m_CubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee
150 m_CubeAxes->SetFontFactor(0.8);
151 m_CubeAxes->SetAxisTitleTextProperty(tprop);
152 m_CubeAxes->SetAxisLabelTextProperty(tprop);
153 m_CubeAxes->SetCornerOffset(0.0);
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 bool VTKViewer_ViewFrame::ComputeTrihedronSize( double& theNewSize, double& theSize )
194 // calculating diagonal of visible props of the renderer
196 m_Triedron->VisibilityOff();
197 if ( ::ComputeVisiblePropBounds( m_Renderer, bnd ) == 0 )
199 bnd[ 1 ] = bnd[ 3 ] = bnd[ 5 ] = 100;
200 bnd[ 0 ] = bnd[ 2 ] = bnd[ 100 ] = 0;
202 m_Triedron->VisibilityOn();
204 static bool CalcByDiag = false;
207 aLength = sqrt( ( bnd[1]-bnd[0])*(bnd[1]-bnd[0] )+
208 ( bnd[3]-bnd[2])*(bnd[3]-bnd[2] )+
209 ( bnd[5]-bnd[4])*(bnd[5]-bnd[4] ) );
213 aLength = bnd[ 1 ]-bnd[ 0 ];
214 aLength = max( ( bnd[ 3 ] - bnd[ 2 ] ),aLength );
215 aLength = max( ( bnd[ 5 ] - bnd[ 4 ] ),aLength );
218 static float aSizeInPercents = 105;
219 QString aSetting = QAD_CONFIG->getSetting( "Viewer:TrihedronSize" );
220 if ( !aSetting.isEmpty() )
221 aSizeInPercents = aSetting.toFloat();
223 static float EPS_SIZE = 5.0E-3;
224 theSize = m_Triedron->GetSize();
225 theNewSize = aLength * aSizeInPercents / 100.0;
227 // if the new trihedron size have sufficient difference, then apply the value
228 return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
229 fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
232 double VTKViewer_ViewFrame::GetTrihedronSize() const
234 return m_Triedron->GetSize();
237 void VTKViewer_ViewFrame::AdjustTrihedrons( const bool forcedUpdate )
240 if ( !isTrihedronDisplayed() && !forcedUpdate )
245 newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT;
246 newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT;
248 m_CubeAxes->GetBounds(bnd);
250 cout << "Bounds: BEFORE\n"
251 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
252 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
253 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
255 int aVisibleNum = m_Triedron->GetVisibleActorCount( m_Renderer );
256 if ( aVisibleNum || forcedUpdate )
258 // if the new trihedron size have sufficient difference, then apply the value
259 double aNewSize = 100, anOldSize;
260 if ( ComputeTrihedronSize( aNewSize, anOldSize ) || forcedUpdate )
262 m_Triedron->SetSize( aNewSize );
263 // itearte throuh displayed objects and set size if necessary
265 vtkActorCollection* anActors = getRenderer()->GetActors();
266 anActors->InitTraversal();
267 while( vtkActor* anActor = anActors->GetNextActor() )
269 if( SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor ) )
271 if ( aSActor->IsResizable() )
272 aSActor->SetSize( 0.5 * aNewSize );
273 if( aSActor->GetVisibility()){
275 aSActor->GetBounds(abounds);
277 cout << "Bounds: Actor="<<aSActor<<"\n"
278 << "\txMin=" << abounds[ 0 ] << " xMax=" << abounds[ 1 ] << "\n"
279 << "\tyMin=" << abounds[ 2 ] << " yMax=" << abounds[ 3 ] << "\n"
280 << "\tzMin=" << abounds[ 4 ] << " zMax=" << abounds[ 5 ] << "\n";
281 if ( abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT &&
282 abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT &&
283 abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT)
284 for(int i=0;i<5;i=i+2){
285 if(abounds[i]<newbnd[i]) newbnd[i]=abounds[i];
286 if(abounds[i+1]>newbnd[i+1]) newbnd[i+1]=abounds[i+1];
294 if( newbnd[0]<VTK_LARGE_FLOAT && newbnd[2]<VTK_LARGE_FLOAT && newbnd[4]<VTK_LARGE_FLOAT &&
295 newbnd[1]>-VTK_LARGE_FLOAT && newbnd[3]>-VTK_LARGE_FLOAT && newbnd[5]>-VTK_LARGE_FLOAT){
296 for(int i=0;i<6;i++) bnd[i] = newbnd[i];
297 m_CubeAxes->SetBounds(bnd);
300 cout << "Bounds AFTER: VisibleActors="<<aVisibleNum<<"\n"
301 << "\txMin=" << bnd[ 0 ] << " xMax=" << bnd[ 1 ] << "\n"
302 << "\tyMin=" << bnd[ 2 ] << " yMax=" << bnd[ 3 ] << "\n"
303 << "\tzMin=" << bnd[ 4 ] << " zMax=" << bnd[ 5 ] << "\n";
305 m_CubeAxes->SetBounds(bnd);
307 ::ResetCameraClippingRange(m_Renderer);
310 void VTKViewer_ViewFrame::onAdjustTrihedron()
312 AdjustTrihedrons( false );
316 Display/hide Trihedron
318 void VTKViewer_ViewFrame::onViewTrihedron(){
319 if(!m_Triedron) return;
320 if(isTrihedronDisplayed()){
321 m_Triedron->VisibilityOff();
322 m_CubeAxes->VisibilityOff();
325 m_Triedron->VisibilityOn();
326 m_CubeAxes->VisibilityOn();
332 Provides top projection of the active view
334 void VTKViewer_ViewFrame::onViewTop(){
335 vtkCamera* camera = m_Renderer->GetActiveCamera();
336 camera->SetPosition(0,0,1);
337 camera->SetViewUp(0,1,0);
338 camera->SetFocalPoint(0,0,0);
343 Provides bottom projection of the active view
345 void VTKViewer_ViewFrame::onViewBottom(){
346 vtkCamera* camera = m_Renderer->GetActiveCamera();
347 camera->SetPosition(0,0,-1);
348 camera->SetViewUp(0,1,0);
349 camera->SetFocalPoint(0,0,0);
354 Provides left projection of the active view
356 void VTKViewer_ViewFrame::onViewLeft(){
357 vtkCamera* camera = m_Renderer->GetActiveCamera();
358 camera->SetPosition(0,-1,0);
359 camera->SetViewUp(0,0,1);
360 camera->SetFocalPoint(0,0,0);
365 Provides right projection of the active view
367 void VTKViewer_ViewFrame::onViewRight(){
368 vtkCamera* camera = m_Renderer->GetActiveCamera();
369 camera->SetPosition(0,1,0);
370 camera->SetViewUp(0,0,1);
371 camera->SetFocalPoint(0,0,0);
376 Provides back projection of the active view
378 void VTKViewer_ViewFrame::onViewBack(){
379 vtkCamera* camera = m_Renderer->GetActiveCamera();
380 camera->SetPosition(-1,0,0);
381 camera->SetViewUp(0,0,1);
382 camera->SetFocalPoint(0,0,0);
387 Provides front projection of the active view
389 void VTKViewer_ViewFrame::onViewFront(){
390 vtkCamera* camera = m_Renderer->GetActiveCamera();
391 camera->SetPosition(1,0,0);
392 camera->SetViewUp(0,0,1);
393 camera->SetFocalPoint(0,0,0);
398 Fits all objects in the active view
400 void VTKViewer_ViewFrame::onViewFitAll(){
401 m_RWInteractor->GetInteractorStyleSALOME()->ViewFitAll();
406 Reset the active view
408 void VTKViewer_ViewFrame::onViewReset(){
409 int aTriedronIsVisible = isTrihedronDisplayed();
410 m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
411 m_CubeAxes->SetVisibility(2);
412 ::ResetCamera(m_Renderer,true);
413 vtkCamera* aCamera = m_Renderer->GetActiveCamera();
414 aCamera->SetPosition(1,-1,1);
415 aCamera->SetViewUp(0,0,1);
416 ::ResetCamera(m_Renderer,true);
417 if(aTriedronIsVisible){
418 m_Triedron->VisibilityOn();
419 m_CubeAxes->VisibilityOn();
422 m_Triedron->VisibilityOff();
423 m_CubeAxes->VisibilityOff();
425 static float aCoeff = 3.0;
426 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
431 Rotates the active view
433 void VTKViewer_ViewFrame::onViewRotate(){
434 m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
438 Sets a new center of the active view
440 void VTKViewer_ViewFrame::onViewGlobalPan(){
441 if(m_Triedron->GetVisibleActorCount(m_Renderer))
442 m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
446 Zooms the active view
448 void VTKViewer_ViewFrame::onViewZoom(){
449 m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
453 Moves the active view
455 void VTKViewer_ViewFrame::onViewPan(){
456 m_RWInteractor->GetInteractorStyleSALOME()->startPan();
460 Fits all obejcts within a rectangular area of the active view
462 void VTKViewer_ViewFrame::onViewFitArea(){
463 m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
467 Set background of the viewport
469 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
472 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
476 Returns background of the viewport
478 QColor VTKViewer_ViewFrame::backgroundColor() const
482 m_Renderer->GetBackground(backint);
483 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
485 return QMainWindow::backgroundColor();
489 void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode )
491 m_RWInteractor->SetSelectionMode( mode );
494 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
496 m_RWInteractor->rename(IObject, newName);
499 void VTKViewer_ViewFrame::unHighlightAll()
501 m_RWInteractor->unHighlightAll();
504 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
508 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
509 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
510 m_RWInteractor->highlight(IObject, highlight, update);
512 if(Sel->HasIndex(IObject) && IObject->hasEntry()){
513 TColStd_IndexedMapOfInteger MapIndex;
514 Sel->GetIndex(IObject,MapIndex);
515 using namespace SALOME::VTK;
516 const char* anEntry = IObject->getEntry();
517 vtkActorCollection* aCollection = getRenderer()->GetActors();
518 if(SALOME_Actor* anActor = Find<SALOME_Actor>(aCollection,TIsSameEntry<SALOME_Actor>(anEntry))){
519 switch (Sel->SelectionMode()) {
521 m_RWInteractor->highlightPoint(MapIndex,anActor,highlight,update);
523 case EdgeOfCellSelection:
524 m_RWInteractor->highlightEdge(MapIndex,anActor,highlight,update);
529 case VolumeSelection:
530 m_RWInteractor->highlightCell(MapIndex,anActor,highlight,update);
535 m_RWInteractor->unHighlightSubSelection();
539 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
541 return m_RWInteractor->isInViewer( IObject );
544 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
546 return m_RWInteractor->isVisible( IObject );
549 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
551 m_RW->setPopupServer( App );
555 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* theEntry)
557 using namespace SALOME::VTK;
558 SALOME_Actor* anActor =
559 Find<SALOME_Actor>(getRenderer()->GetActors(),
560 TIsSameEntry<SALOME_Actor>(theEntry));
562 return anActor->getIO();
564 return Handle(SALOME_InteractiveObject)();
568 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
570 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
571 SALOME_Selection* aSel = SALOME_Selection::Selection( aQADStudy->getSelection() );
572 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
574 m_RWInteractor->Display(theIObject,false);
575 ToolsGUI::SetVisibility( aStudy, theIObject->getEntry(), true, this );
576 aSel->AddIObject(theIObject,false);
583 struct TDisplayAction{
584 SALOME_Selection* mySel;
585 Handle(SALOME_InteractiveObject) myIO;
586 TDisplayAction(SALOME_Selection* theSel,
587 Handle(SALOME_InteractiveObject) theIO):
588 mySel(theSel), myIO(theIO)
590 void operator()(SALOME_Actor* theActor){
591 theActor->SetVisibility(true);
592 mySel->AddIObject(myIO,false);
596 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& theIObject)
598 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
599 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
601 aSel->ClearIObjects();
602 //m_RWInteractor->EraseAll();
605 using namespace SALOME::VTK;
606 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
607 TIsSameIObject<SALOME_Actor>(theIObject),
608 TDisplayAction(aSel,theIObject));
610 ToolsGUI::SetVisibility(
611 aStudy->getStudyDocument(), theIObject->getEntry(), true, this );
617 struct TEraseAction: TDisplayAction{
618 VTKViewer_RenderWindowInteractor* myRWInteractor;
619 TEraseAction(SALOME_Selection* theSel,
620 Handle(SALOME_InteractiveObject) theIO,
621 VTKViewer_RenderWindowInteractor* theRWInteractor):
622 TDisplayAction(theSel,theIO),
623 myRWInteractor(theRWInteractor)
625 void operator()(SALOME_Actor* theActor){
626 myRWInteractor->Erase(myIO,false);
627 mySel->RemoveIObject(myIO,false);
631 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& theIObject, bool update)
633 QAD_Study* aStudy = QAD_Application::getDesktop()->getActiveStudy();
634 SALOME_Selection* aSel = SALOME_Selection::Selection(aStudy->getSelection());
636 using namespace SALOME::VTK;
637 ForEachIf<SALOME_Actor>(getRenderer()->GetActors(),
638 TIsSameIObject<SALOME_Actor>(theIObject),
639 TEraseAction(aSel,theIObject,m_RWInteractor));
641 ToolsGUI::SetVisibility(
642 aStudy->getStudyDocument(), theIObject->getEntry(), false, this );
649 void VTKViewer_ViewFrame::DisplayAll()
651 m_RWInteractor->DisplayAll();
653 // update flag of visibility
654 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
655 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
656 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
657 const QString& aCompName = aDesktop->getComponentDataType();
658 SALOMEDS::SObject_var aComponent =
659 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
661 std::list<SALOMEDS::SObject_var> aList;
662 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
664 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
665 for ( ; anIter != aList.end(); ++anIter )
666 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), true, this );
670 void VTKViewer_ViewFrame::EraseAll()
672 m_RWInteractor->EraseAll();
674 // update flag of visibility
675 QAD_Study* aQADStudy = QAD_Application::getDesktop()->getActiveStudy();
676 SALOMEDS::Study_var aStudy = aQADStudy->getStudyDocument();
677 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
678 const QString& aCompName = aDesktop->getComponentDataType();
679 SALOMEDS::SObject_var aComponent =
680 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
682 std::list<SALOMEDS::SObject_var> aList;
683 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
685 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
686 for ( ; anIter != aList.end(); ++anIter )
687 ToolsGUI::SetVisibility( aStudy, (*anIter)->GetID(), false, this );
691 void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
693 if (theUpdateTrihedron) onAdjustTrihedron();
697 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
698 m_Transform->GetScale(theScale);
701 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
702 m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
703 m_RWInteractor->Render();
707 void VTKViewer_ViewFrame::InsertActor( SALOME_Actor* theActor, bool theMoveInternalActors ){
708 theActor->AddToRender(m_Renderer);
709 theActor->SetTransform(m_Transform);
710 if(theMoveInternalActors)
711 m_RWInteractor->MoveInternalActors();
714 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
715 InsertActor(theActor);
720 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool theUpdate /*=false*/ ){
721 theActor->RemoveFromRender(m_Renderer);
726 void VTKViewer_ViewFrame::MoveActor(SALOME_Actor* theActor)
728 RemoveActor(theActor);
729 InsertActor(theActor,true);
732 //==========================================================
734 * VTKViewer_ViewFrame::Display
735 * Display presentation
737 //==========================================================
738 void VTKViewer_ViewFrame::Display( const SALOME_VTKPrs* prs )
740 // try do downcast object
741 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
742 if ( !aVTKPrs || aVTKPrs->IsNull() )
745 vtkActorCollection* actors = aVTKPrs->GetObjects();
749 actors->InitTraversal();
751 while( ( actor = actors->GetNextActor() ) )
753 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
756 // just display the object
757 m_RWInteractor->Display( salomeActor, false );
759 // Set visibility flag
760 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
761 if ( !anObj.IsNull() && anObj->hasEntry() )
763 SALOMEDS::Study_var aStudy =
764 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
765 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
768 if ( salomeActor->IsSetCamera() )
769 salomeActor->SetCamera( getRenderer()->GetActiveCamera() );
774 //==========================================================
776 * VTKViewer_ViewFrame::Erase
779 //==========================================================
780 void VTKViewer_ViewFrame::Erase( const SALOME_VTKPrs* prs, const bool forced )
782 // try do downcast object
783 const VTKViewer_Prs* aVTKPrs = dynamic_cast<const VTKViewer_Prs*>( prs );
784 if ( !aVTKPrs || aVTKPrs->IsNull() )
787 vtkActorCollection* actors = aVTKPrs->GetObjects();
791 SALOMEDS::Study_var aStudy =
792 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
794 actors->InitTraversal();
796 while( ( actor = actors->GetNextActor() ) ) {
797 SALOME_Actor* salomeActor = SALOME_Actor::SafeDownCast( actor );
799 // just erase the object
801 m_RWInteractor->Remove( salomeActor, false );
803 m_RWInteractor->Erase( salomeActor, forced );
805 // Set visibility flag if necessary
808 Handle(SALOME_InteractiveObject) anObj = salomeActor->getIO();
809 if ( !anObj.IsNull() && anObj->hasEntry() )
810 ToolsGUI::SetVisibility( aStudy, anObj->getEntry(), true, this );
816 //==========================================================
818 * VTKViewer_ViewFrame::CreatePrs
819 * Create presentation by entry
821 //==========================================================
822 SALOME_Prs* VTKViewer_ViewFrame::CreatePrs( const char* entry )
824 VTKViewer_Prs* prs = new VTKViewer_Prs();
826 vtkActorCollection* theActors = m_Renderer->GetActors();
827 theActors->InitTraversal();
829 while( ( ac = theActors->GetNextActor() ) ) {
830 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
831 if ( anActor && anActor->hasIO() && !strcmp( anActor->getIO()->getEntry(), entry ) ) {
832 prs->AddObject( ac );
839 //==========================================================
841 * VTKViewer_ViewFrame::BeforeDisplay
842 * Axiluary method called before displaying of objects
844 //==========================================================
845 void VTKViewer_ViewFrame::BeforeDisplay( SALOME_Displayer* d )
847 d->BeforeDisplay( this, SALOME_VTKViewType() );
850 //==========================================================
852 * VTKViewer_ViewFrame::AfterDisplay
853 * Axiluary method called after displaying of objects
855 //==========================================================
856 void VTKViewer_ViewFrame::AfterDisplay( SALOME_Displayer* d )
858 d->AfterDisplay( this, SALOME_VTKViewType() );
861 //==========================================================
863 * VTKViewer_ViewFrame::undo
864 * Redisplay all objects in viewer
866 //==========================================================
867 void VTKViewer_ViewFrame::undo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
869 redisplayAll( theQADStudy, true );
872 //==========================================================
874 * VTKViewer_ViewFrame::redo
875 * Redisplay all objects in viewer
877 //==========================================================
878 void VTKViewer_ViewFrame::redo( QAD_Study* theQADStudy, const char* /*StudyFrameEntry*/ )
880 redisplayAll( theQADStudy, true );
883 //==========================================================
885 * VTKViewer_ViewFrame::redisplayAll
886 * Redisplay all objects in viewer
888 //==========================================================
889 void VTKViewer_ViewFrame::redisplayAll( QAD_Study* theQADStudy, const bool theToUpdate )
891 SALOMEDS::Study_var aStudy = theQADStudy->getStudyDocument();
892 SALOME_Selection* aSel = SALOME_Selection::Selection( theQADStudy->getSelection() );
893 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
894 SALOMEGUI* aGUI = aDesktop->getActiveGUI();
895 const QString& aCompName = aDesktop->getComponentDataType();
896 SALOMEDS::SObject_var aComponent =
897 SALOMEDS::SObject::_narrow( aStudy->FindComponent ( aCompName.latin1() ) );
899 if ( aComponent->_is_nil() )
902 bool isTrhDisplayed = isTrihedronDisplayed();
903 bool isCubeDisplayed = isCubeAxesDisplayed();
905 m_RWInteractor->RemoveAll( false );
906 //m_RWInteractor->EraseAll();
908 aSel->ClearIObjects();
911 // ENK commented, already added to renderer in
912 // VTKViewer_ViewFrame::VTKViewer_ViewFrame(...)
913 if ( isTrhDisplayed )
914 m_Triedron->AddToRender( m_Renderer );
917 std::list<SALOMEDS::SObject_var> aList;
918 SALOMEDS_Tool::GetAllChildren( aStudy, aComponent, aList );
920 std::list<SALOMEDS::SObject_var>::iterator anIter = aList.begin();
921 for ( ; anIter != aList.end(); ++anIter )
923 SALOMEDS::SObject_var anObj = (*anIter);
924 if ( ToolsGUI::GetVisibility( aStudy, anObj, this ) )
926 Handle(SALOME_InteractiveObject) anIObj = new SALOME_InteractiveObject();
927 anIObj->setEntry( anObj->GetID() );
928 aGUI->BuildPresentation( anIObj, this );
937 #define INCREMENT_FOR_OP 10
939 //=======================================================================
941 // Purpose : Performs incremental panning to the left
942 //=======================================================================
943 void VTKViewer_ViewFrame::onPanLeft()
945 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( -INCREMENT_FOR_OP, 0 );
948 //=======================================================================
950 // Purpose : Performs incremental panning to the right
951 //=======================================================================
952 void VTKViewer_ViewFrame::onPanRight()
954 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( INCREMENT_FOR_OP, 0 );
957 //=======================================================================
959 // Purpose : Performs incremental panning to the top
960 //=======================================================================
961 void VTKViewer_ViewFrame::onPanUp()
963 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, INCREMENT_FOR_OP );
966 //=======================================================================
968 // Purpose : Performs incremental panning to the bottom
969 //=======================================================================
970 void VTKViewer_ViewFrame::onPanDown()
972 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalPan( 0, -INCREMENT_FOR_OP );
975 //=======================================================================
977 // Purpose : Performs incremental zooming in
978 //=======================================================================
979 void VTKViewer_ViewFrame::onZoomIn()
981 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( INCREMENT_FOR_OP );
984 //=======================================================================
986 // Purpose : Performs incremental zooming out
987 //=======================================================================
988 void VTKViewer_ViewFrame::onZoomOut()
990 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalZoom( -INCREMENT_FOR_OP );
993 //=======================================================================
994 // name : onRotateLeft
995 // Purpose : Performs incremental rotating to the left
996 //=======================================================================
997 void VTKViewer_ViewFrame::onRotateLeft()
999 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( -INCREMENT_FOR_OP, 0 );
1002 //=======================================================================
1003 // name : onRotateRight
1004 // Purpose : Performs incremental rotating to the right
1005 //=======================================================================
1006 void VTKViewer_ViewFrame::onRotateRight()
1008 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( INCREMENT_FOR_OP, 0 );
1011 //=======================================================================
1012 // name : onRotateUp
1013 // Purpose : Performs incremental rotating to the top
1014 //=======================================================================
1015 void VTKViewer_ViewFrame::onRotateUp()
1017 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, -INCREMENT_FOR_OP );
1020 //=======================================================================
1021 // name : onRotateDown
1022 // Purpose : Performs incremental rotating to the bottom
1023 //=======================================================================
1024 void VTKViewer_ViewFrame::onRotateDown()
1026 m_RWInteractor->GetInteractorStyleSALOME()->IncrementalRotate( 0, INCREMENT_FOR_OP );