2 // File : VTKViewer_ViewFrame.cxx
3 // Created : Wed Mar 20 11:29:40 2002
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE 2002
10 #include "VTKViewer_ViewFrame.h"
11 #include "VTKViewer_RenderWindow.h"
12 #include "VTKViewer_InteractorStyleSALOME.h"
14 #include "QAD_Settings.h"
15 #include "QAD_Config.h"
16 #include "QAD_Application.h"
17 #include "QAD_Desktop.h"
18 #include "SALOME_Selection.h"
19 #include "SALOME_InteractiveObject.hxx"
21 #include "utilities.h"
25 #include <qcolordialog.h>
26 #include <qfiledialog.h>
27 #include <qapplication.h>
31 #include <vtkTextSource.h>
33 #include <vtkConeSource.h>
34 #include <vtkTextMapper.h>
35 #include <vtkMapper2D.h>
36 #include <vtkActor2D.h>
37 #include <vtkWindowToImageFilter.h>
38 #include <vtkTIFFWriter.h>
40 #include <vtkTransformPolyDataFilter.h>
41 #include <vtkDataSetMapper.h>
46 VTKViewer_ViewFrame::VTKViewer_ViewFrame(QWidget* parent, const char* name)
47 : QAD_ViewFrame(parent, name)
49 m_ViewUp[0] = 0; m_ViewUp[1] = 0; m_ViewUp[2] = -1;
50 m_ViewNormal[0] = 0; m_ViewNormal[1] = 0; m_ViewNormal[2] = 1;
52 // m_InitialSetupDone = false ;
55 m_NonIsometricTransform = NULL;
60 static vtkActor* CreateTextActor(char *text) {
62 vtkTextSource* XLabel = vtkTextSource::New();
63 XLabel->SetForegroundColor(1,1,1);
64 XLabel->SetBackgroundColor(0,0,0);
65 XLabel->SetText(text);
67 vtkActor* XLabelActor = vtkActor::New();
69 vtkPolyDataMapper* text1Mapper = vtkPolyDataMapper::New();
70 text1Mapper->SetInput(XLabel->GetOutput());
72 XLabelActor->SetMapper(text1Mapper);
73 XLabelActor->SetScale(1,1,1);
78 void VTKViewer_ViewFrame::AddVector(float* o,float* p,vtkRenderer* renderer) {
82 vtkPoints* myPoints = vtkPoints::New();
83 vtkLine* myLine = vtkLine::New();
85 myPoints->InsertNextPoint(o);
86 myPoints->InsertNextPoint(p);
88 (myLine->GetPointIds())->InsertNextId(0);
89 (myLine->GetPointIds())->InsertNextId(1);
91 vtkActor* lineActor = vtkActor::New();
93 vtkCellArray* cell = vtkCellArray::New();
95 cell->InsertNextCell(myLine);
97 vtkPolyData* output = vtkPolyData::New();
99 output->SetPoints(myPoints);
100 output->SetLines(cell);
102 vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
104 mapper->SetInput(output);
106 lineActor->SetMapper(mapper);
110 vtkConeSource* acone = vtkConeSource::New();
113 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
114 if( Size.isEmpty() ) {
117 dim = Size.toFloat();
120 acone->SetResolution(2);
121 // acone->SetAngle(70);
122 acone->SetRadius(0.02*dim);
123 acone->SetHeight(0.08*dim);
125 vtkActor* coneActor = vtkActor::New();
127 vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New();
128 coneMapper->SetInput(acone->GetOutput());
130 coneActor->SetMapper(coneMapper);
132 rot[0]=0; rot[1]=0; rot[2]=0;
136 coneActor->AddPosition(p);
141 coneActor->AddPosition(p);
143 coneActor->AddOrientation(rot);
148 coneActor->AddPosition(p);
150 coneActor->AddOrientation(rot);
157 coneActor->GetProperty()->SetInterpolation(1);
158 coneActor->GetProperty()->SetRepresentationToSurface();
159 coneActor->GetProperty()->SetAmbient(1);
160 coneActor->GetProperty()->SetAmbientColor(1,1,1);
161 coneActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
162 coneActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
164 lineActor->GetProperty()->SetInterpolation(1);
165 lineActor->GetProperty()->SetRepresentationToSurface();
166 lineActor->GetProperty()->SetAmbient(1);
167 lineActor->GetProperty()->SetAmbientColor(1,1,1);
168 lineActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
169 lineActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
171 coneActor->PickableOff();
172 lineActor->PickableOff();
174 m_Triedron->AddItem(coneActor);
175 m_Triedron->AddItem(lineActor);
177 renderer->AddActor(coneActor);
178 renderer->AddActor(lineActor);
181 bool VTKViewer_ViewFrame::isTrihedronDisplayed()
183 m_Triedron->InitTraversal();
184 vtkActor *ac = m_Triedron->GetNextActor();
186 if(ac->GetVisibility()) return true;
187 ac = m_Triedron->GetNextActor();
192 void VTKViewer_ViewFrame::SetTrihedronSize(int size)
194 m_Triedron->InitTraversal();
195 vtkActor* anActor = m_Triedron->GetNextActor();
196 while(!(anActor==NULL)) {
197 m_Renderer->RemoveActor( anActor );
198 anActor = m_Triedron->GetNextActor();
201 m_Triedron->RemoveAllItems();
207 void VTKViewer_ViewFrame::AddAxis(vtkRenderer* renderer) {
215 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
216 if( Size.isEmpty() ){
219 dim = Size.toFloat();
222 origine[0]=0; origine[1]=0; origine[2]=0;
223 X[0]=origine[0]+dim; X[1]=origine[0]; X[2]=origine[0];
224 Y[0]=origine[0]; Y[1]=origine[0]+dim; Y[2]=origine[0];
225 Z[0]=origine[0]; Z[1]=origine[0]; Z[2]=origine[0]+dim;
227 AddVector(origine,X,renderer);
228 AddVector(origine,Y,renderer);
229 AddVector(origine,Z,renderer);
234 Returns widget containing 3D-Viewer
236 QWidget* VTKViewer_ViewFrame::getViewWidget()
238 return (QWidget*)getRW();
242 void VTKViewer_ViewFrame::setRW(VTKViewer_RenderWindow* rw) {
247 void VTKViewer_ViewFrame::InitialSetup() {
249 // Create a render window.
251 m_RW = new VTKViewer_RenderWindow(this,"");
253 // Create a renderer for this widget.
255 m_Renderer = vtkRenderer::New() ;
256 m_RW->AddRenderer(m_Renderer) ;
259 vtkCamera* camera = vtkCamera::New();
260 camera->SetPosition(1,-1,1);
261 camera->SetParallelProjection(true);
262 camera->SetRoll(-60);
265 m_Triedron = vtkActorCollection::New();
268 // Set BackgroundColor
269 QString BackgroundColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
270 QString BackgroundColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
271 QString BackgroundColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
273 if( !BackgroundColorRed.isEmpty() && !BackgroundColorGreen.isEmpty() && !BackgroundColorBlue.isEmpty() )
274 m_Renderer->SetBackground( BackgroundColorRed.toInt()/255., BackgroundColorGreen.toInt()/255., BackgroundColorBlue.toInt()/255. );
276 m_Renderer->SetBackground( 0, 0 , 0 );
279 // Create an interactor.
281 m_RWInteractor = VTKViewer_RenderWindowInteractor::New() ;
282 m_RWInteractor->SetRenderWindow(m_RW) ;
284 // :TRICKY: Tue May 2 19:29:36 2000 Pagey
285 // The order of the next two statements is very
286 // important. The interactor must be initialized
289 m_RWInteractor->Initialize();
290 m_Renderer->Render() ;
291 m_Renderer->SetActiveCamera(camera);
292 m_Renderer->ResetCamera();
294 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
296 RWS->setTriedron( m_Triedron );
297 //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
298 RWS->FindPokedRenderer(0, 0);
303 setCentralWidget( m_RW );
306 VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
308 // In order to ensure that the interactor unregisters
309 // this RenderWindow, we assign a NULL RenderWindow to
310 // it before deleting it.
312 if ( m_NonIsometricTransform )
313 m_NonIsometricTransform->Delete() ;
315 m_RWInteractor->SetRenderWindow(NULL) ;
316 m_RWInteractor->Delete() ;
321 // m_Renderer->Delete() ;
326 Display/hide Trihedron
328 void VTKViewer_ViewFrame::onViewTrihedron()
330 if (isTrihedronDisplayed()) {
331 m_Triedron->InitTraversal();
332 vtkActor *ac = m_Triedron->GetNextActor();
335 ac = m_Triedron->GetNextActor();
339 m_Triedron->InitTraversal();
340 vtkActor *ac = m_Triedron->GetNextActor();
343 ac = m_Triedron->GetNextActor();
345 m_TriedronVisible = true;
351 Provides top projection of the active view
353 void VTKViewer_ViewFrame::onViewTop() {
354 vtkCamera* camera = vtkCamera::New();
355 camera->SetPosition(0,0,1);
356 camera->SetParallelProjection(true);
357 m_Renderer->SetActiveCamera(camera);
358 // m_Renderer->ResetCamera();
364 Provides bottom projection of the active view
366 void VTKViewer_ViewFrame::onViewBottom()
368 vtkCamera* camera = vtkCamera::New();
369 camera->SetPosition(0,0,-1);
370 camera->SetParallelProjection(true);
371 m_Renderer->SetActiveCamera(camera);
372 // m_Renderer->ResetCamera();
378 Provides left projection of the active view
380 void VTKViewer_ViewFrame::onViewLeft()
382 vtkCamera* camera = vtkCamera::New();
383 camera->SetPosition(0,1,0);
384 camera->SetParallelProjection(true);
385 m_Renderer->SetActiveCamera(camera);
386 // m_Renderer->ResetCamera();
392 Provides right projection of the active view
394 void VTKViewer_ViewFrame::onViewRight()
396 vtkCamera* camera = vtkCamera::New();
397 camera->SetPosition(0,-1,0);
398 camera->SetParallelProjection(true);
399 m_Renderer->SetActiveCamera(camera);
400 // m_Renderer->ResetCamera();
406 Provides back projection of the active view
408 void VTKViewer_ViewFrame::onViewBack()
410 vtkCamera* camera = vtkCamera::New();
411 camera->SetPosition(-1,0,0);
412 camera->SetParallelProjection(true);
413 m_Renderer->SetActiveCamera(camera);
414 // m_Renderer->ResetCamera();
420 Provides front projection of the active view
422 void VTKViewer_ViewFrame::onViewFront()
424 vtkCamera* camera = vtkCamera::New();
425 camera->SetPosition(1,0,0);
426 camera->SetParallelProjection(true);
427 m_Renderer->SetActiveCamera(camera);
428 // m_Renderer->ResetCamera();
434 Reset the active view
436 void VTKViewer_ViewFrame::onViewReset()
438 vtkCamera* camera = vtkCamera::New();
439 camera->SetPosition(1,-1,1);
440 camera->SetParallelProjection(true);
441 camera->SetRoll(-60);
442 m_Renderer->SetActiveCamera(camera);
443 m_Renderer->ResetCamera();
444 m_Renderer->ResetCameraClippingRange();
450 Rotates the active view
452 void VTKViewer_ViewFrame::onViewRotate()
454 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
460 Sets a new center of the active view
462 void VTKViewer_ViewFrame::onViewGlobalPan()
464 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
466 RWS->startGlobalPan();
470 Zooms the active view
472 void VTKViewer_ViewFrame::onViewZoom()
474 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
480 Moves the active view
482 void VTKViewer_ViewFrame::onViewPan()
484 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
490 Fits all obejcts within a rectangular area of the active view
492 void VTKViewer_ViewFrame::onViewFitArea()
495 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
501 Fits all objects in the active view
503 // Reset the camera clipping range to include this entire bounding box
504 static void ResetCameraClippingRange(vtkRenderer* theRenderer, float bounds[6] )
506 //see vtkRenderer::ResetCameraClippingRange(float bounds[6]) method
507 double vn[3], position[3], a, b, c, d;
508 double range[2], dist;
514 vtkCamera* anActiveCamera = theRenderer->GetActiveCamera();
515 if ( anActiveCamera == NULL )
517 //vtkErrorMacro(<< "Trying to reset clipping range of non-existant camera");
521 // Find the plane equation for the camera view plane
522 anActiveCamera->GetViewPlaneNormal(vn);
523 anActiveCamera->GetPosition(position);
527 // d = -(a*position[0] + b*position[1] + c*position[2]);
529 // Set the max near clipping plane and the min far clipping plane
530 // range[0] = a*bounds[0] + b*bounds[2] + c*bounds[4] + d;
533 // Find the closest / farthest bounding box vertex
534 // for ( k = 0; k < 2; k++ )
536 // for ( j = 0; j < 2; j++ )
538 // for ( i = 0; i < 2; i++ )
540 // dist = a*bounds[i] + b*bounds[2+j] + c*bounds[4+k] + d;
541 // range[0] = (dist<range[0])?(dist):(range[0]);
542 // range[1] = (dist>range[1])?(dist):(range[1]);
547 center[0] = (bounds[0] + bounds[1])/2.0;
548 center[1] = (bounds[2] + bounds[3])/2.0;
549 center[2] = (bounds[4] + bounds[5])/2.0;
550 width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
551 (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
552 (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
553 distance = sqrt((position[0]-center[0])*(position[0]-center[0]) +
554 (position[1]-center[1])*(position[1]-center[1]) +
555 (position[2]-center[2])*(position[2]-center[2]));
556 range[0] = distance - width/2.0;
557 range[1] = distance + width/2.0;
559 // Give ourselves a little breathing room
560 range[0] = 0.99*range[0] - (range[1] - range[0])*0.5;
561 range[1] = 1.01*range[1] + (range[1] - range[0])*0.5;
563 // Make sure near is not bigger than far
564 range[0] = (range[0] >= range[1])?(0.01*range[1]):(range[0]);
566 // Make sure near is at least some fraction of far - this prevents near
567 // from being behind the camera or too close in front. How close is too
568 // close depends on the resolution of the depth buffer
569 int ZBufferDepth = 16;
570 vtkRenderWindow* aRenderWindow = theRenderer->GetRenderWindow();
573 ZBufferDepth = aRenderWindow->GetDepthBufferSize();
576 if ( ZBufferDepth <= 16 )
578 range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
580 else if ( ZBufferDepth <= 24 )
582 range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
586 range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
588 anActiveCamera->SetClippingRange( range );
591 static void ResetCamera(vtkRenderer* theRenderer){
592 //see vtkRenderer::ResetCamera(float bounds[6]) method
594 if(!theRenderer) return;
595 theRenderer->ComputeVisiblePropBounds( bounds );
602 if ( theRenderer->GetActiveCamera() != NULL )
604 theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn);
608 MESSAGE("Trying to reset non-existant camera");
612 center[0] = (bounds[0] + bounds[1])/2.0;
613 center[1] = (bounds[2] + bounds[3])/2.0;
614 center[2] = (bounds[4] + bounds[5])/2.0;
615 width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
616 (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
617 (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
618 double ang = theRenderer->GetActiveCamera()->GetViewAngle();
619 distance = 2.0*width/tan(ang*vtkMath::Pi()/360.0);
620 // check view-up vector against view plane normal
621 vup = theRenderer->GetActiveCamera()->GetViewUp();
622 if ( fabs(vtkMath::Dot(vup,vn)) > 0.999 )
624 MESSAGE("Resetting view-up since view plane normal is parallel");
625 theRenderer->GetActiveCamera()->SetViewUp(-vup[2], vup[0], vup[1]);
629 theRenderer->GetActiveCamera()->SetFocalPoint(center[0],center[1],center[2]);
630 theRenderer->GetActiveCamera()->SetPosition(center[0]+distance*vn[0],
631 center[1]+distance*vn[1],
632 center[2]+distance*vn[2]);
633 // setup default parallel scale
634 theRenderer->GetActiveCamera()->SetParallelScale(width/2.0);
636 //theRenderer->ResetCameraClippingRange(bounds);
637 ResetCameraClippingRange(theRenderer,bounds);
640 void VTKViewer_ViewFrame::onViewFitAll()
642 Standard_Boolean TriedronWasVisible = false;
643 if (isTrihedronDisplayed()) {
644 m_Triedron->InitTraversal();
645 vtkActor *ac = m_Triedron->GetNextActor();
648 ac = m_Triedron->GetNextActor();
650 TriedronWasVisible = true;
652 bool hasVisibleActors = m_Renderer->VisibleActorCount() > 0;
653 if ( hasVisibleActors ) // if there are visible actors, not to take into account Trihedron
654 ResetCamera(m_Renderer);
655 if(TriedronWasVisible) {
656 m_Triedron->InitTraversal();
657 vtkActor *ac = m_Triedron->GetNextActor();
660 ac = m_Triedron->GetNextActor();
662 if ( !hasVisibleActors ) // if there are NO visible actors, fit view to see only Trihedron
663 ResetCamera(m_Renderer);
665 //m_Renderer->ResetCameraClippingRange();
670 Set background of the viewport
672 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
675 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
679 Returns background of the viewport
681 QColor VTKViewer_ViewFrame::backgroundColor() const
685 m_Renderer->GetBackground(backint);
686 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
688 return QMainWindow::backgroundColor();
692 void VTKViewer_ViewFrame::SetSelectionMode( int mode )
694 m_RWInteractor->SetSelectionMode( mode );
697 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
699 m_RWInteractor->rename(IObject, newName);
702 void VTKViewer_ViewFrame::unHighlightAll()
704 m_RWInteractor->unHighlightAll();
707 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
711 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
712 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
714 if ( Sel->SelectionMode() == 4 )
715 m_RWInteractor->highlight(IObject, highlight, update);
716 else if ( Sel->SelectionMode() == 3 ) {
717 m_RWInteractor->highlight(IObject, highlight, update);
718 if ( Sel->HasIndex( IObject ) ) {
719 TColStd_MapOfInteger MapIndex;
720 Sel->GetIndex( IObject, MapIndex );
721 m_RWInteractor->highlightCell(IObject, highlight, MapIndex, update);
724 else if ( Sel->SelectionMode() == 2 ) {
725 m_RWInteractor->highlight(IObject, highlight, update);
726 if ( Sel->HasIndex( IObject ) ) {
727 TColStd_MapOfInteger MapIndex;
728 Sel->GetIndex( IObject, MapIndex );
729 m_RWInteractor->highlightEdge(IObject, highlight, MapIndex, update);
732 else if ( Sel->SelectionMode() == 1 ) {
733 m_RWInteractor->highlight(IObject, highlight, update);
734 if ( Sel->HasIndex( IObject ) ) {
735 TColStd_MapOfInteger MapIndex;
736 Sel->GetIndex( IObject, MapIndex );
737 m_RWInteractor->highlightPoint(IObject, highlight, MapIndex, update);
742 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
744 return m_RWInteractor->isInViewer( IObject );
747 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
749 return m_RWInteractor->isVisible( IObject );
752 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
754 m_RW->setPopupServer( App );
757 void VTKViewer_ViewFrame::undo(SALOMEDS::Study_var aStudy,
758 const char* StudyFrameEntry)
760 vtkActorCollection* theActors = m_Renderer->GetActors();
761 theActors->InitTraversal();
762 vtkActor *ac = theActors->GetNextActor();
764 if ( ac->IsA("SALOME_Actor") ) {
765 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
766 if ( anActor->hasIO() ) {
767 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
768 if ( IO->hasEntry() ) {
769 if (!QAD_ViewFrame::isInViewer(aStudy, IO->getEntry(), StudyFrameEntry)) {
770 m_RWInteractor->Erase(IO);
775 ac = theActors->GetNextActor();
779 void VTKViewer_ViewFrame::redo(SALOMEDS::Study_var aStudy,
780 const char* StudyFrameEntry)
782 SALOMEDS::SObject_var RefSO;
783 SALOMEDS::SObject_var SO = aStudy->FindObjectID( StudyFrameEntry );
784 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
785 for (; it->More();it->Next()){
786 SALOMEDS::SObject_var CSO= it->Value();
787 if (CSO->ReferencedObject(RefSO)) {
788 vtkActorCollection* theActors = m_Renderer->GetActors();
789 theActors->InitTraversal();
790 vtkActor *ac = theActors->GetNextActor();
792 if ( ac->IsA("SALOME_Actor") ) {
793 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
794 if ( anActor->hasIO() ) {
795 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
796 if ( IO->hasEntry() ) {
797 if ( strcmp(IO->getEntry(),RefSO->GetID()) == 0 )
798 m_RWInteractor->Display(IO);
802 ac = theActors->GetNextActor();
810 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* Entry)
812 Handle(SALOME_InteractiveObject) IO;
813 vtkActorCollection* theActors = m_Renderer->GetActors();
814 theActors->InitTraversal();
815 vtkActor *ac = theActors->GetNextActor();
817 if ( ac->IsA("SALOME_Actor") ) {
818 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
819 if ( anActor->hasIO() ) {
820 IO = anActor->getIO();
821 if ( IO->hasEntry() ) {
822 if ( strcmp( IO->getEntry(), Entry ) == 0 ) {
828 ac = theActors->GetNextActor();
834 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
836 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
837 SALOME_Selection* Sel
838 = SALOME_Selection::Selection( myStudy->getSelection() );
840 vtkActorCollection* theActors = m_Renderer->GetActors();
841 theActors->InitTraversal();
842 vtkActor *ac = theActors->GetNextActor();
845 if ( ac->IsA("SALOME_Actor") )
847 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
848 if ( anActor->hasIO() )
850 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
851 if ( IO->isSame(IObject) )
853 m_RWInteractor->Display(IO, false);
854 Sel->AddIObject(IO, false);
859 ac = theActors->GetNextActor();
866 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject)
868 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
869 SALOME_Selection* Sel
870 = SALOME_Selection::Selection( myStudy->getSelection() );
872 vtkActorCollection* theActors = m_Renderer->GetActors();
873 theActors->InitTraversal();
874 vtkActor *ac = theActors->GetNextActor();
876 if ( ac->IsA("SALOME_Actor") ) {
877 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
878 if ( anActor->hasIO() ) {
879 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
880 if ( !IO->isSame(IObject) ) {
881 m_RWInteractor->Erase(IO, false);
882 Sel->RemoveIObject(IO, false);
884 anActor->SetVisibility(true);
885 Sel->AddIObject(IO, false);
889 ac = theActors->GetNextActor();
894 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
896 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
897 SALOME_Selection* Sel
898 = SALOME_Selection::Selection( myStudy->getSelection() );
900 vtkActorCollection* theActors = m_Renderer->GetActors();
901 theActors->InitTraversal();
902 vtkActor *ac = theActors->GetNextActor();
905 if ( ac->IsA("SALOME_Actor") )
907 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
908 if ( anActor->hasIO() )
910 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
911 if ( IO->isSame( IObject ) ) {
912 m_RWInteractor->Erase(IO, false);
913 Sel->RemoveIObject(IO, false);
918 ac = theActors->GetNextActor();
925 void VTKViewer_ViewFrame::DisplayAll()
927 m_RWInteractor->DisplayAll();
931 void VTKViewer_ViewFrame::EraseAll()
933 m_RWInteractor->EraseAll();
937 void VTKViewer_ViewFrame::Repaint()
939 m_RWInteractor->Render();
943 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool update /*=false*/ )
945 m_Renderer->AddActor( theActor );
946 if (m_NonIsometricTransform != NULL)
948 vtkPolyDataMapper* mapper = NULL;
949 vtkMapper* initialMapper = theActor->GetInitialMapper();
950 if ( initialMapper == NULL )
951 initialMapper = theActor->GetMapper();
952 if ( initialMapper->IsA("vtkDataSetMapper") )
954 mapper = vtkDataSetMapper::SafeDownCast( initialMapper )->GetPolyDataMapper ();
957 initialMapper->Render(m_Renderer,theActor);
958 mapper = vtkDataSetMapper::SafeDownCast( initialMapper )->GetPolyDataMapper ();
962 mapper = vtkPolyDataMapper::SafeDownCast( initialMapper );
966 vtkTransformPolyDataFilter *aTransformFilter = vtkTransformPolyDataFilter::New();
967 aTransformFilter->SetInput ( mapper->GetInput() );
968 aTransformFilter->SetTransform (m_NonIsometricTransform);
971 vtkPolyDataMapper *aMapper = vtkPolyDataMapper::New();
972 aMapper->SetInput (aTransformFilter->GetOutput());
973 aMapper->ShallowCopy ( theActor->GetMapper());
976 theActor->SetMapper (aMapper);
978 aTransformFilter->Delete();
982 theActor->SetVisibility( true );
985 m_RWInteractor->Render();