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
30 #include "VTKViewer_ViewFrame.h"
31 #include "VTKViewer_RenderWindow.h"
32 //#include "VTKViewer_InteractorStyleSALOME.h"
34 #include "QAD_Settings.h"
35 #include "QAD_Config.h"
36 #include "QAD_Application.h"
37 #include "QAD_Desktop.h"
38 #include "SALOME_Selection.h"
39 #include "SALOME_InteractiveObject.hxx"
40 #include "VTKViewer_InteractorStyleSALOME.h"
42 #include "utilities.h"
46 #include <qcolordialog.h>
47 #include <qfiledialog.h>
48 #include <qapplication.h>
52 #include <vtkRenderer.h>
53 #include <vtkTransform.h>
54 #include <vtkPolyDataMapper.h>
57 #include <vtkTextSource.h>
59 #include <vtkConeSource.h>
60 #include <vtkTextMapper.h>
61 #include <vtkMapper2D.h>
62 #include <vtkActor2D.h>
63 #include <vtkWindowToImageFilter.h>
64 #include <vtkTIFFWriter.h>
65 #include <vtkVectorText.h>
66 #include <vtkFollower.h>
71 VTKViewer_ViewFrame::VTKViewer_ViewFrame(QWidget* parent, const char* name)
72 : QAD_ViewFrame(parent, name)
74 m_ViewUp[0] = 0; m_ViewUp[1] = 0; m_ViewUp[2] = -1;
75 m_ViewNormal[0] = 0; m_ViewNormal[1] = 0; m_ViewNormal[2] = 1;
76 m_Transform = SALOME_Transform::New();
78 // m_InitialSetupDone = false ;
83 vtkFollower* CreateTextActor(char *text, float aSize) {
84 vtkVectorText* aTxt = vtkVectorText::New();
86 vtkPolyDataMapper* textMapper = vtkPolyDataMapper::New();
87 textMapper->SetInput(aTxt->GetOutput());
88 vtkFollower* textActor = vtkFollower::New();
89 textActor->SetMapper(textMapper);
90 float aScale = 6 * aSize/100;
91 textActor->SetScale(aScale, aScale, aScale);
95 void VTKViewer_ViewFrame::AddVector(float* o,float* p,vtkRenderer* renderer, float aSize) {
96 vtkPoints* myPoints = vtkPoints::New();
97 vtkLine* myLine = vtkLine::New();
99 myPoints->InsertNextPoint(o);
100 myPoints->InsertNextPoint(p);
102 (myLine->GetPointIds())->InsertNextId(0);
103 (myLine->GetPointIds())->InsertNextId(1);
105 vtkActor* lineActor = vtkActor::New();
107 vtkCellArray* cell = vtkCellArray::New();
109 cell->InsertNextCell(myLine);
111 vtkPolyData* output = vtkPolyData::New();
113 output->SetPoints(myPoints);
114 output->SetLines(cell);
116 vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
118 mapper->SetInput(output);
120 lineActor->SetMapper(mapper);
124 vtkConeSource* acone = vtkConeSource::New();
128 acone->SetResolution(2);
129 // acone->SetAngle(70);
130 acone->SetRadius(0.02*dim);
131 acone->SetHeight(0.08*dim);
133 vtkActor* coneActor = vtkActor::New();
135 vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New();
136 coneMapper->SetInput(acone->GetOutput());
138 coneActor->SetMapper(coneMapper);
140 rot[0]=0; rot[1]=0; rot[2]=0;
142 vtkFollower* aTextActor;
144 coneActor->AddPosition(p);
147 aTextActor = CreateTextActor("X", dim);
151 coneActor->AddOrientation(rot);
152 aTextActor = CreateTextActor("Y", dim);
156 coneActor->AddOrientation(rot);
157 aTextActor = CreateTextActor("Z", dim);
159 aTextActor->AddPosition(p);
160 aTextActor->SetCamera(renderer->GetActiveCamera());
162 coneActor->GetProperty()->SetInterpolation(1);
163 coneActor->GetProperty()->SetRepresentationToSurface();
164 coneActor->GetProperty()->SetAmbient(1);
165 coneActor->GetProperty()->SetAmbientColor(1,1,1);
166 coneActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
167 coneActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
169 lineActor->GetProperty()->SetInterpolation(1);
170 lineActor->GetProperty()->SetRepresentationToSurface();
171 lineActor->GetProperty()->SetAmbient(1);
172 lineActor->GetProperty()->SetAmbientColor(1,1,1);
173 lineActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
174 lineActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
176 aTextActor->GetProperty()->SetAmbient(1);
177 aTextActor->GetProperty()->SetAmbientColor(1,1,1);
178 aTextActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
179 aTextActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
181 coneActor->PickableOff();
182 lineActor->PickableOff();
183 aTextActor->PickableOff();
185 m_Triedron->AddItem(coneActor);
186 m_Triedron->AddItem(lineActor);
187 m_Triedron->AddItem(aTextActor);
189 renderer->AddActor(coneActor);
190 renderer->AddActor(lineActor);
191 renderer->AddActor(aTextActor);
194 bool VTKViewer_ViewFrame::isTrihedronDisplayed() {
195 m_Triedron->InitTraversal();
196 vtkActor *ac = m_Triedron->GetNextActor();
198 if(ac->GetVisibility()) return true;
199 ac = m_Triedron->GetNextActor();
204 void VTKViewer_ViewFrame::SetTrihedronSize(int size)
206 m_Triedron->InitTraversal();
207 vtkActor* anActor = m_Triedron->GetNextActor();
208 while(!(anActor==NULL)) {
209 m_Renderer->RemoveActor( anActor );
210 anActor = m_Triedron->GetNextActor();
213 m_Triedron->RemoveAllItems();
219 void VTKViewer_ViewFrame::AddAxis(vtkRenderer* renderer) {
226 QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
227 if( Size.isEmpty() ){
230 dim = Size.toFloat();
233 origine[0]=0; origine[1]=0; origine[2]=0;
234 X[0]=origine[0]+dim; X[1]=origine[0]; X[2]=origine[0];
235 Y[0]=origine[0]; Y[1]=origine[0]+dim; Y[2]=origine[0];
236 Z[0]=origine[0]; Z[1]=origine[0]; Z[2]=origine[0]+dim;
238 AddVector(origine,X,renderer, dim);
239 AddVector(origine,Y,renderer, dim);
240 AddVector(origine,Z,renderer, dim);
245 Returns widget containing 3D-Viewer
247 QWidget* VTKViewer_ViewFrame::getViewWidget()
253 void VTKViewer_ViewFrame::InitialSetup() {
254 m_Renderer = vtkRenderer::New() ;
256 m_RW = new VTKViewer_RenderWindow(this, "RenderWindow");
257 m_RW->getRenderWindow()->AddRenderer(m_Renderer);
259 m_Renderer->GetActiveCamera()->ParallelProjectionOn();
260 m_Renderer->LightFollowCameraOn();
262 // Set BackgroundColor
263 QString BgrColorRed = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
264 QString BgrColorGreen = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
265 QString BgrColorBlue = QAD_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
267 if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
268 m_Renderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
270 m_Renderer->SetBackground( 0, 0, 0 );
273 m_Triedron = vtkActorCollection::New();
276 // Create an interactor.
277 m_RWInteractor = VTKViewer_RenderWindowInteractor::New();
278 m_RWInteractor->setGUIWindow(m_RW);
279 m_RWInteractor->SetRenderWindow(m_RW->getRenderWindow());
281 VTKViewer_InteractorStyleSALOME* RWS = VTKViewer_InteractorStyleSALOME::New();
282 RWS->setGUIWindow(m_RW);
283 m_RWInteractor->SetInteractorStyle(RWS);
285 m_RWInteractor->Initialize();
286 RWS->setTriedron( m_Triedron );
287 //SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
288 RWS->FindPokedRenderer(0, 0);
290 setCentralWidget( m_RW );
294 VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
296 // In order to ensure that the interactor unregisters
297 // this RenderWindow, we assign a NULL RenderWindow to
298 // it before deleting it.
300 m_Transform->Delete() ;
302 m_RWInteractor->SetRenderWindow(NULL) ;
303 m_RWInteractor->Delete() ;
307 // NRI : BugID 1137: m_Renderer->Delete() ;
312 Display/hide Trihedron
314 void VTKViewer_ViewFrame::onViewTrihedron()
316 if (isTrihedronDisplayed()) {
317 m_Triedron->InitTraversal();
318 vtkActor *ac = m_Triedron->GetNextActor();
321 ac = m_Triedron->GetNextActor();
325 m_Triedron->InitTraversal();
326 vtkActor *ac = m_Triedron->GetNextActor();
329 ac = m_Triedron->GetNextActor();
331 m_TriedronVisible = true;
337 Provides top projection of the active view
339 void VTKViewer_ViewFrame::onViewTop() {
340 vtkCamera* camera = m_Renderer->GetActiveCamera();
341 camera->SetFocalPoint(0,0,0);
342 camera->SetPosition(0,0,1);
343 camera->SetViewUp(0,1,0);
344 m_Renderer->ResetCamera();
350 Provides bottom projection of the active view
352 void VTKViewer_ViewFrame::onViewBottom()
354 vtkCamera* camera = m_Renderer->GetActiveCamera();
355 camera->SetFocalPoint(0,0,0);
356 camera->SetPosition(0,0,-1);
357 camera->SetViewUp(0,1,0);
358 m_Renderer->ResetCamera();
364 Provides left projection of the active view
366 void VTKViewer_ViewFrame::onViewLeft()
368 vtkCamera* camera = m_Renderer->GetActiveCamera();
369 camera->SetFocalPoint(0,0,0);
370 camera->SetPosition(0,1,0);
371 camera->SetViewUp(0,0,1);
372 m_Renderer->ResetCamera();
378 Provides right projection of the active view
380 void VTKViewer_ViewFrame::onViewRight()
382 vtkCamera* camera = m_Renderer->GetActiveCamera();
383 camera->SetFocalPoint(0,0,0);
384 camera->SetPosition(0,-1,0);
385 camera->SetViewUp(0,0,1);
386 m_Renderer->ResetCamera();
392 Provides back projection of the active view
394 void VTKViewer_ViewFrame::onViewBack()
396 vtkCamera* camera = m_Renderer->GetActiveCamera();
397 camera->SetPosition(-1,0,0);
398 camera->SetFocalPoint(0,0,0);
399 camera->SetViewUp(0,0,1);
400 m_Renderer->ResetCamera();
406 Provides front projection of the active view
408 void VTKViewer_ViewFrame::onViewFront()
410 vtkCamera* camera = m_Renderer->GetActiveCamera();
411 camera->SetPosition(1,0,0);
412 camera->SetFocalPoint(0,0,0);
413 camera->SetViewUp(0,0,1);
414 m_Renderer->ResetCamera();
420 Reset the active view
422 void VTKViewer_ViewFrame::onViewReset()
424 vtkCamera* camera = m_Renderer->GetActiveCamera();
425 camera->SetPosition(1,-1,1);
426 camera->SetFocalPoint(0,0,0);
427 camera->SetViewUp(0,0,1);
428 m_Renderer->ResetCamera();
429 camera->SetParallelScale(500);
430 m_Renderer->ResetCameraClippingRange();
435 Rotates the active view
437 void VTKViewer_ViewFrame::onViewRotate()
439 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
445 Sets a new center of the active view
447 void VTKViewer_ViewFrame::onViewGlobalPan()
449 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
451 RWS->startGlobalPan();
455 Zooms the active view
457 void VTKViewer_ViewFrame::onViewZoom()
459 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
465 Moves the active view
467 void VTKViewer_ViewFrame::onViewPan()
469 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
475 Fits all obejcts within a rectangular area of the active view
477 void VTKViewer_ViewFrame::onViewFitArea()
479 VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
485 Fits all objects in the active view
487 // Reset the camera clipping range to include this entire bounding box
488 static void ResetCameraClippingRange(vtkRenderer* theRenderer, float bounds[6] )
490 //see vtkRenderer::ResetCameraClippingRange(float bounds[6]) method
491 double vn[3], position[3], a, b, c, d;
492 double range[2], dist;
498 vtkCamera* anActiveCamera = theRenderer->GetActiveCamera();
499 if ( anActiveCamera == NULL )
501 //vtkErrorMacro(<< "Trying to reset clipping range of non-existant camera");
505 // Find the plane equation for the camera view plane
506 anActiveCamera->GetViewPlaneNormal(vn);
507 anActiveCamera->GetPosition(position);
511 // d = -(a*position[0] + b*position[1] + c*position[2]);
513 // Set the max near clipping plane and the min far clipping plane
514 // range[0] = a*bounds[0] + b*bounds[2] + c*bounds[4] + d;
517 // Find the closest / farthest bounding box vertex
518 // for ( k = 0; k < 2; k++ )
520 // for ( j = 0; j < 2; j++ )
522 // for ( i = 0; i < 2; i++ )
524 // dist = a*bounds[i] + b*bounds[2+j] + c*bounds[4+k] + d;
525 // range[0] = (dist<range[0])?(dist):(range[0]);
526 // range[1] = (dist>range[1])?(dist):(range[1]);
531 center[0] = (bounds[0] + bounds[1])/2.0;
532 center[1] = (bounds[2] + bounds[3])/2.0;
533 center[2] = (bounds[4] + bounds[5])/2.0;
534 width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
535 (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
536 (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
537 distance = sqrt((position[0]-center[0])*(position[0]-center[0]) +
538 (position[1]-center[1])*(position[1]-center[1]) +
539 (position[2]-center[2])*(position[2]-center[2]));
540 range[0] = distance - width/2.0;
541 range[1] = distance + width/2.0;
543 // Give ourselves a little breathing room
544 range[0] = 0.99*range[0] - (range[1] - range[0])*0.5;
545 range[1] = 1.01*range[1] + (range[1] - range[0])*0.5;
547 // Make sure near is not bigger than far
548 range[0] = (range[0] >= range[1])?(0.01*range[1]):(range[0]);
550 // Make sure near is at least some fraction of far - this prevents near
551 // from being behind the camera or too close in front. How close is too
552 // close depends on the resolution of the depth buffer
553 int ZBufferDepth = 16;
554 vtkRenderWindow* aRenderWindow = theRenderer->GetRenderWindow();
557 ZBufferDepth = aRenderWindow->GetDepthBufferSize();
560 if ( ZBufferDepth <= 16 )
562 range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
564 else if ( ZBufferDepth <= 24 )
566 range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
570 range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
572 anActiveCamera->SetClippingRange( range );
575 static void ResetCamera(vtkRenderer* theRenderer){
576 //see vtkRenderer::ResetCamera(float bounds[6]) method
578 if(!theRenderer) return;
579 theRenderer->ComputeVisiblePropBounds( bounds );
586 if ( theRenderer->GetActiveCamera() != NULL )
588 theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn);
592 MESSAGE("Trying to reset non-existant camera");
596 center[0] = (bounds[0] + bounds[1])/2.0;
597 center[1] = (bounds[2] + bounds[3])/2.0;
598 center[2] = (bounds[4] + bounds[5])/2.0;
599 width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
600 (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
601 (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
602 double ang = theRenderer->GetActiveCamera()->GetViewAngle();
603 distance = 2.0*width/tan(ang*vtkMath::Pi()/360.0);
604 // check view-up vector against view plane normal
605 vup = theRenderer->GetActiveCamera()->GetViewUp();
606 if ( fabs(vtkMath::Dot(vup,vn)) > 0.999 )
608 MESSAGE("Resetting view-up since view plane normal is parallel");
609 theRenderer->GetActiveCamera()->SetViewUp(-vup[2], vup[0], vup[1]);
613 theRenderer->GetActiveCamera()->SetFocalPoint(center[0],center[1],center[2]);
614 theRenderer->GetActiveCamera()->SetPosition(center[0]+distance*vn[0],
615 center[1]+distance*vn[1],
616 center[2]+distance*vn[2]);
617 // setup default parallel scale
618 theRenderer->GetActiveCamera()->SetParallelScale(width/2.0);
620 //theRenderer->ResetCameraClippingRange(bounds);
621 ResetCameraClippingRange(theRenderer,bounds);
624 void VTKViewer_ViewFrame::onViewFitAll()
626 Standard_Boolean TriedronWasVisible = false;
627 if (isTrihedronDisplayed()) {
628 m_Triedron->InitTraversal();
629 vtkActor *ac = m_Triedron->GetNextActor();
632 ac = m_Triedron->GetNextActor();
634 TriedronWasVisible = true;
636 bool hasVisibleActors = m_Renderer->VisibleActorCount() > 0;
637 if ( hasVisibleActors ) // if there are visible actors, not to take into account Trihedron
638 ResetCamera(m_Renderer);
639 if(TriedronWasVisible) {
640 m_Triedron->InitTraversal();
641 vtkActor *ac = m_Triedron->GetNextActor();
644 ac = m_Triedron->GetNextActor();
646 if ( !hasVisibleActors ) // if there are NO visible actors, fit view to see only Trihedron
647 ResetCamera(m_Renderer);
649 //m_Renderer->ResetCameraClippingRange();
654 Set background of the viewport
656 void VTKViewer_ViewFrame::setBackgroundColor( const QColor& color)
659 m_Renderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
663 Returns background of the viewport
665 QColor VTKViewer_ViewFrame::backgroundColor() const
669 m_Renderer->GetBackground(backint);
670 return QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL );
672 return QMainWindow::backgroundColor();
676 void VTKViewer_ViewFrame::SetSelectionMode( int mode )
678 m_RWInteractor->SetSelectionMode( mode );
681 void VTKViewer_ViewFrame::rename( const Handle(SALOME_InteractiveObject)& IObject, QString newName )
683 m_RWInteractor->rename(IObject, newName);
686 void VTKViewer_ViewFrame::unHighlightAll()
688 m_RWInteractor->unHighlightAll();
691 void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IObject,
695 QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
696 SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() );
697 if ( Sel->SelectionMode() == 4 )
698 m_RWInteractor->highlight(IObject, highlight, update);
699 else if ( Sel->SelectionMode() == 3 ) {
700 m_RWInteractor->highlight(IObject, highlight, update);
701 if ( Sel->HasIndex( IObject ) ) {
702 TColStd_MapOfInteger MapIndex;
703 Sel->GetIndex( IObject, MapIndex );
704 m_RWInteractor->highlightCell(IObject, highlight, MapIndex, update);
707 else if ( Sel->SelectionMode() == 2 ) {
708 m_RWInteractor->highlight(IObject, highlight, update);
709 if ( Sel->HasIndex( IObject ) ) {
710 TColStd_MapOfInteger MapIndex;
711 Sel->GetIndex( IObject, MapIndex );
712 m_RWInteractor->highlightEdge(IObject, highlight, MapIndex, update);
715 else if ( Sel->SelectionMode() == 1 ) {
716 m_RWInteractor->highlight(IObject, highlight, update);
717 if ( Sel->HasIndex( IObject ) ) {
718 TColStd_MapOfInteger MapIndex;
719 Sel->GetIndex( IObject, MapIndex );
720 m_RWInteractor->highlightPoint(IObject, highlight, MapIndex, update);
725 bool VTKViewer_ViewFrame::isInViewer( const Handle(SALOME_InteractiveObject)& IObject )
727 return m_RWInteractor->isInViewer( IObject );
730 bool VTKViewer_ViewFrame::isVisible( const Handle(SALOME_InteractiveObject)& IObject )
732 return m_RWInteractor->isVisible( IObject );
735 void VTKViewer_ViewFrame::setPopupServer( QAD_Application* App )
737 m_RW->setPopupServer( App );
740 void VTKViewer_ViewFrame::undo(SALOMEDS::Study_var aStudy,
741 const char* StudyFrameEntry)
743 vtkActorCollection* theActors = m_Renderer->GetActors();
744 theActors->InitTraversal();
745 vtkActor *ac = theActors->GetNextActor();
747 if ( ac->IsA("SALOME_Actor") ) {
748 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
749 if ( anActor->hasIO() ) {
750 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
751 if ( IO->hasEntry() ) {
752 /*if (!QAD_ViewFrame::isInViewer(aStudy, IO->getEntry(), StudyFrameEntry)) {
753 m_RWInteractor->Erase(IO);
758 ac = theActors->GetNextActor();
762 void VTKViewer_ViewFrame::redo(SALOMEDS::Study_var aStudy,
763 const char* StudyFrameEntry)
765 SALOMEDS::SObject_var RefSO;
766 SALOMEDS::SObject_var SO = aStudy->FindObjectID( StudyFrameEntry );
767 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
768 for (; it->More();it->Next()){
769 SALOMEDS::SObject_var CSO= it->Value();
770 if (CSO->ReferencedObject(RefSO)) {
771 vtkActorCollection* theActors = m_Renderer->GetActors();
772 theActors->InitTraversal();
773 vtkActor *ac = theActors->GetNextActor();
775 if ( ac->IsA("SALOME_Actor") ) {
776 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
777 if ( anActor->hasIO() ) {
778 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
779 if ( IO->hasEntry() ) {
780 /*if ( strcmp(IO->getEntry(),RefSO->GetID()) == 0 )
781 m_RWInteractor->Display(IO);*/
785 ac = theActors->GetNextActor();
793 Handle(SALOME_InteractiveObject) VTKViewer_ViewFrame::FindIObject(const char* Entry)
795 Handle(SALOME_InteractiveObject) IO;
796 vtkActorCollection* theActors = m_Renderer->GetActors();
797 theActors->InitTraversal();
798 vtkActor *ac = theActors->GetNextActor();
800 if ( ac->IsA("SALOME_Actor") ) {
801 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
802 if ( anActor->hasIO() ) {
803 IO = anActor->getIO();
804 if ( IO->hasEntry() ) {
805 if ( strcmp( IO->getEntry(), Entry ) == 0 ) {
811 ac = theActors->GetNextActor();
817 void VTKViewer_ViewFrame::Display(const Handle(SALOME_InteractiveObject)& IObject, bool update)
819 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
820 SALOME_Selection* Sel
821 = SALOME_Selection::Selection( myStudy->getSelection() );
823 vtkActorCollection* theActors = m_Renderer->GetActors();
824 theActors->InitTraversal();
825 vtkActor *ac = theActors->GetNextActor();
828 if ( ac->IsA("SALOME_Actor") )
830 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
831 if ( anActor->hasIO() )
833 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
834 if ( IO->isSame(IObject) )
836 m_RWInteractor->Display(IO, false);
837 Sel->AddIObject(IO, false);
842 ac = theActors->GetNextActor();
849 void VTKViewer_ViewFrame::DisplayOnly(const Handle(SALOME_InteractiveObject)& IObject)
851 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
852 SALOME_Selection* Sel
853 = SALOME_Selection::Selection( myStudy->getSelection() );
855 vtkActorCollection* theActors = m_Renderer->GetActors();
856 theActors->InitTraversal();
857 vtkActor *ac = theActors->GetNextActor();
859 if ( ac->IsA("SALOME_Actor") ) {
860 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
861 if ( anActor->hasIO() ) {
862 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
863 if ( !IO->isSame(IObject) ) {
864 m_RWInteractor->Erase(IO, false);
865 Sel->RemoveIObject(IO, false);
867 anActor->SetVisibility(true);
868 Sel->AddIObject(IO, false);
872 ac = theActors->GetNextActor();
877 void VTKViewer_ViewFrame::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update)
879 QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
880 SALOME_Selection* Sel
881 = SALOME_Selection::Selection( myStudy->getSelection() );
883 vtkActorCollection* theActors = m_Renderer->GetActors();
884 theActors->InitTraversal();
885 vtkActor *ac = theActors->GetNextActor();
888 if ( ac->IsA("SALOME_Actor") )
890 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
891 if ( anActor->hasIO() )
893 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
894 if ( IO->isSame( IObject ) ) {
895 m_RWInteractor->Erase(IO, false);
896 Sel->RemoveIObject(IO, false);
901 ac = theActors->GetNextActor();
908 void VTKViewer_ViewFrame::DisplayAll()
910 m_RWInteractor->DisplayAll();
914 void VTKViewer_ViewFrame::EraseAll()
916 m_RWInteractor->EraseAll();
920 void VTKViewer_ViewFrame::Repaint()
922 // m_RWInteractor->Render();
926 void VTKViewer_ViewFrame::GetScale(double theScale[3]){
927 m_Transform->GetScale(theScale);
930 void VTKViewer_ViewFrame::SetScale(double theScale[3]){
931 m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
932 m_Transform->Modified();
936 void VTKViewer_ViewFrame::AddActor( SALOME_Actor* theActor, bool update /*=false*/ ){
937 theActor->SetVisibility(true);
938 theActor->AddToRender(m_Renderer);
939 theActor->SetTransform(m_Transform);
941 m_Renderer->ResetCameraClippingRange();
942 m_RWInteractor->Render();
946 void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool update /*=false*/ ){
947 theActor->RemoveFromRender(m_Renderer);
949 m_Renderer->ResetCameraClippingRange();
950 m_RWInteractor->Render();