Back to index

salome-gui  6.5.0
VTKViewer_InteractorStyle.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME VTKViewer : build VTK viewer into Salome desktop
00024 //  File   : VTKViewer_InteractorStyle.cxx
00025 //  Author : Christophe ATTANASIO
00026 
00027 #include "VTKViewer_InteractorStyle.h"
00028 
00029 #include "VTKViewer_Actor.h"
00030 #include "VTKViewer_Utilities.h"
00031 #include "VTKViewer_Trihedron.h"
00032 #include "VTKViewer_ViewWindow.h"
00033 #include "VTKViewer_RenderWindow.h"
00034 #include "VTKViewer_RenderWindowInteractor.h"
00035 
00036 #include <vtkObjectFactory.h>
00037 #include <vtkMath.h>
00038 #include <vtkCommand.h>
00039 #include <vtkCamera.h>
00040 #include <vtkRenderer.h>
00041 #include <vtkPicker.h>
00042 #include <vtkPointPicker.h>
00043 #include <vtkCellPicker.h>
00044 #include <vtkLine.h> 
00045 #include <vtkMapper.h>
00046 #include <vtkDataSet.h>
00047 #include <vtkSmartPointer.h>
00048 #include <vtkProperty.h>
00049 
00050 #include <QApplication>
00051 #include <QRubberBand>
00052 
00053 #include <algorithm>
00054 
00055 /*
00056 static int GetEdgeId(vtkPicker *thePicker, SALOME_Actor *theActor, int theObjId){
00057   int anEdgeId = -1;
00058   if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
00059     float aPickPosition[3];
00060     thePicker->GetPickPosition(aPickPosition);
00061     float aMinDist = 1000000.0, aDist = 0;
00062     for (int i = 0, iEnd = aPickedCell->GetNumberOfEdges(); i < iEnd; i++){
00063       if(vtkLine* aLine = vtkLine::SafeDownCast(aPickedCell->GetEdge(i))){
00064         int subId;  float pcoords[3], closestPoint[3], weights[3];
00065         aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights);
00066         if (aDist < aMinDist) {
00067           aMinDist = aDist;
00068           anEdgeId = i;
00069         }
00070       }
00071     }
00072   }
00073   return anEdgeId;
00074 }
00075 */
00076 
00077 vtkStandardNewMacro(VTKViewer_InteractorStyle);
00078 
00079 
00081 VTKViewer_InteractorStyle::VTKViewer_InteractorStyle()
00082 {
00083   m_Trihedron = 0;
00084   this->MotionFactor = 10.0;
00085   this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
00086   this->RadianToDegree = 180.0 / vtkMath::Pi();
00087   this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
00088   loadCursors();
00089 
00090   myPreSelectionActor = VTKViewer_Actor::New();
00091   myPreSelectionActor->GetProperty()->SetColor(0,1,1);
00092   myPreSelectionActor->GetProperty()->SetLineWidth(5);
00093   myPreSelectionActor->GetProperty()->SetPointSize(5);
00094 
00095   myRectBand = 0;
00096 
00097   OnSelectionModeChanged();
00098 }
00099 
00100 
00102 VTKViewer_InteractorStyle::~VTKViewer_InteractorStyle() 
00103 {
00104   m_ViewWnd->RemoveActor(myPreSelectionActor);
00105   endDrawRect();
00106 }
00107 
00108 
00115 void VTKViewer_InteractorStyle::setPreselectionProp(const double& theRed, const double& theGreen, 
00116                                                           const double& theBlue, const int& theWidth) 
00117 {
00118   if ( myPreSelectionActor->GetProperty() == 0 )
00119     return;
00120   myPreSelectionActor->GetProperty()->SetColor(theRed, theGreen, theBlue);
00121   myPreSelectionActor->GetProperty()->SetLineWidth(theWidth);
00122   myPreSelectionActor->GetProperty()->SetPointSize(theWidth);
00123 }
00124 
00125 
00129 void VTKViewer_InteractorStyle::SetInteractor(vtkRenderWindowInteractor *theInteractor){
00130   m_Interactor = dynamic_cast<VTKViewer_RenderWindowInteractor*>(theInteractor);
00131   Superclass::SetInteractor(theInteractor);
00132 }
00133 
00134 
00138 void VTKViewer_InteractorStyle::setViewWnd(VTKViewer_ViewWindow* theViewWnd ){
00139   m_ViewWnd = theViewWnd;
00140   m_ViewWnd->AddActor(myPreSelectionActor);
00141   myPreSelectionActor->Delete();
00142 }
00143 
00144 
00148 void VTKViewer_InteractorStyle::setGUIWindow(QWidget* theWindow){
00149   myGUIWindow = theWindow;
00150 }
00151 
00152 
00156 void VTKViewer_InteractorStyle::setTriedron(VTKViewer_Trihedron* theTrihedron){
00157   m_Trihedron = theTrihedron;
00158 }
00159 
00164 void VTKViewer_InteractorStyle::RotateXY(int dx, int dy)
00165 {
00166   double rxf;
00167   double ryf;
00168   vtkCamera *cam;
00169   
00170   if (this->CurrentRenderer == NULL)
00171     {
00172       return;
00173     }
00174   
00175   int *size = this->CurrentRenderer->GetRenderWindow()->GetSize();
00176   this->DeltaElevation = -20.0 / size[1];
00177   this->DeltaAzimuth = -20.0 / size[0];
00178   
00179   rxf = (double)dx * this->DeltaAzimuth *  this->MotionFactor;
00180   ryf = (double)dy * this->DeltaElevation * this->MotionFactor;
00181   
00182   cam = this->CurrentRenderer->GetActiveCamera();
00183   cam->Azimuth(rxf);
00184   cam->Elevation(ryf);
00185   cam->OrthogonalizeViewUp();
00186   ::ResetCameraClippingRange(this->CurrentRenderer); 
00187   //this->Interactor->Render();
00188   myGUIWindow->update();
00189 }
00190 
00191 void VTKViewer_InteractorStyle::PanXY(int x, int y, int oldX, int oldY)
00192 {
00193   TranslateView(x, y, oldX, oldY);   
00194   //this->Interactor->Render();
00195   myGUIWindow->update();
00196 }
00197 
00198 
00200 void VTKViewer_InteractorStyle::DollyXY(int dx, int dy)
00201 {
00202   if (this->CurrentRenderer == NULL) return;
00203 
00204   double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
00205   double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
00206 
00207   double zoomFactor = pow((double)1.1, dxf + dyf);
00208   
00209   vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
00210   if (aCam->GetParallelProjection())
00211     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
00212   else{
00213     aCam->Dolly(zoomFactor);
00214     ::ResetCameraClippingRange(this->CurrentRenderer);
00215   }
00216 
00217   //this->Interactor->Render();
00218   myGUIWindow->update();
00219 }
00220 
00221 void VTKViewer_InteractorStyle::SpinXY(int x, int y, int oldX, int oldY)
00222 {
00223   vtkCamera *cam;
00224 
00225   if (this->CurrentRenderer == NULL)
00226     {
00227       return;
00228     }
00229 
00230   double newAngle = atan2((double)(y - this->CurrentRenderer->GetCenter()[1]),
00231                           (double)(x - this->CurrentRenderer->GetCenter()[0]));
00232   double oldAngle = atan2((double)(oldY -this->CurrentRenderer->GetCenter()[1]),
00233                           (double)(oldX - this->CurrentRenderer->GetCenter()[0]));
00234   
00235   newAngle *= this->RadianToDegree;
00236   oldAngle *= this->RadianToDegree;
00237 
00238   cam = this->CurrentRenderer->GetActiveCamera();
00239   cam->Roll(newAngle - oldAngle);
00240   cam->OrthogonalizeViewUp();
00241       
00242   //this->Interactor->Render();
00243   myGUIWindow->update();
00244 }
00245 
00246 
00253 void VTKViewer_InteractorStyle::OnMouseMove(int vtkNotUsed(ctrl), 
00254                                                   int shift,
00255                                                   int x, int y) 
00256 {
00257   myShiftState = shift;
00258   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
00259     onOperation(QPoint(x, y));
00260   else if (ForcedState == VTK_INTERACTOR_STYLE_CAMERA_NONE)
00261     onCursorMove(QPoint(x, y));
00262 }
00263 
00264 
00271 void VTKViewer_InteractorStyle::OnLeftButtonDown(int ctrl, int shift, 
00272                                                        int x, int y) 
00273 {
00274   if (this->HasObserver(vtkCommand::LeftButtonPressEvent)) {
00275     this->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
00276     return;
00277   }
00278   this->FindPokedRenderer(x, y);
00279   if (this->CurrentRenderer == NULL) {
00280     return;
00281   }
00282   myShiftState = shift;
00283   // finishing current viewer operation
00284   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00285     onFinishOperation();
00286     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00287   }
00288   myOtherPoint = myPoint = QPoint(x, y);
00289   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00290     startOperation(ForcedState);
00291   } else {
00292     if (ctrl)
00293       startOperation(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
00294     else
00295       startOperation(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
00296   }
00297   return;
00298 }
00299 
00300 
00307 void VTKViewer_InteractorStyle::OnLeftButtonUp(int vtkNotUsed(ctrl),
00308                                                      int shift, 
00309                                                      int vtkNotUsed(x),
00310                                                      int vtkNotUsed(y))
00311 {
00312   myShiftState = shift;
00313   // finishing current viewer operation
00314   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00315     onFinishOperation();
00316     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00317   }
00318 }
00319 
00320 
00327 void VTKViewer_InteractorStyle::OnMiddleButtonDown(int ctrl,
00328                                                          int shift, 
00329                                                          int x, int y) 
00330 {
00331   if (this->HasObserver(vtkCommand::MiddleButtonPressEvent)) 
00332     {
00333       this->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
00334       return;
00335     }
00336   this->FindPokedRenderer(x, y);
00337   if (this->CurrentRenderer == NULL)
00338     {
00339       return;
00340     }
00341   myShiftState = shift;
00342   // finishing current viewer operation
00343   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00344     onFinishOperation();
00345     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00346   }
00347   myOtherPoint = myPoint = QPoint(x, y);
00348   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00349     startOperation(ForcedState);
00350   }
00351   else {
00352     if (ctrl)
00353       startOperation(VTK_INTERACTOR_STYLE_CAMERA_PAN);
00354   }
00355 }
00356 
00357 
00364 void VTKViewer_InteractorStyle::OnMiddleButtonUp(int vtkNotUsed(ctrl),
00365                                                        int shift, 
00366                                                        int vtkNotUsed(x),
00367                                                        int vtkNotUsed(y))
00368 {
00369   myShiftState = shift;
00370   // finishing current viewer operation
00371   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00372     onFinishOperation();
00373     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00374   }
00375 }
00376 
00377 
00384 void VTKViewer_InteractorStyle::OnRightButtonDown(int ctrl,
00385                                                         int shift, 
00386                                                         int x, int y) 
00387 {
00388   if (this->HasObserver(vtkCommand::RightButtonPressEvent)) 
00389     {
00390       this->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
00391       return;
00392     }
00393   this->FindPokedRenderer(x, y);
00394   if (this->CurrentRenderer == NULL)
00395     {
00396       return;
00397     }
00398   myShiftState = shift;
00399   // finishing current viewer operation
00400   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00401     onFinishOperation();
00402     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00403   }
00404   myOtherPoint = myPoint = QPoint(x, y);
00405   if (ForcedState != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00406     startOperation(ForcedState);
00407   }
00408   else {
00409     if (ctrl)
00410       startOperation(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);  
00411   }
00412 }
00413 
00420 void VTKViewer_InteractorStyle::OnRightButtonUp(int vtkNotUsed(ctrl),
00421                                                       int shift, 
00422                                                       int vtkNotUsed(x),
00423                                                       int vtkNotUsed(y))
00424 {
00425   myShiftState = shift;
00426   // finishing current viewer operation
00427   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE) {
00428     onFinishOperation();
00429     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00430   }
00431 }
00432 
00436 const char* imageZoomCursor[] = { 
00437 "32 32 3 1",
00438 ". c None",
00439 "a c #000000",
00440 "# c #ffffff",
00441 "................................",
00442 "................................",
00443 ".#######........................",
00444 "..aaaaaaa.......................",
00445 "................................",
00446 ".............#####..............",
00447 "...........##.aaaa##............",
00448 "..........#.aa.....a#...........",
00449 ".........#.a.........#..........",
00450 ".........#a..........#a.........",
00451 "........#.a...........#.........",
00452 "........#a............#a........",
00453 "........#a............#a........",
00454 "........#a............#a........",
00455 "........#a............#a........",
00456 ".........#...........#.a........",
00457 ".........#a..........#a.........",
00458 ".........##.........#.a.........",
00459 "........#####.....##.a..........",
00460 ".......###aaa#####.aa...........",
00461 "......###aa...aaaaa.......#.....",
00462 ".....###aa................#a....",
00463 "....###aa.................#a....",
00464 "...###aa...............#######..",
00465 "....#aa.................aa#aaaa.",
00466 ".....a....................#a....",
00467 "..........................#a....",
00468 "...........................a....",
00469 "................................",
00470 "................................",
00471 "................................",
00472 "................................"};
00473 
00475 const char* imageRotateCursor[] = { 
00476 "32 32 3 1",
00477 ". c None",
00478 "a c #000000",
00479 "# c #ffffff",
00480 "................................",
00481 "................................",
00482 "................................",
00483 "................................",
00484 "........#.......................",
00485 ".......#.a......................",
00486 "......#######...................",
00487 ".......#aaaaa#####..............",
00488 "........#..##.a#aa##........##..",
00489 ".........a#.aa..#..a#.....##.aa.",
00490 ".........#.a.....#...#..##.aa...",
00491 ".........#a.......#..###.aa.....",
00492 "........#.a.......#a..#aa.......",
00493 "........#a.........#..#a........",
00494 "........#a.........#a.#a........",
00495 "........#a.........#a.#a........",
00496 "........#a.........#a.#a........",
00497 ".........#.........#a#.a........",
00498 "........##a........#a#a.........",
00499 "......##.a#.......#.#.a.........",
00500 "....##.aa..##.....##.a..........",
00501 "..##.aa.....a#####.aa...........",
00502 "...aa.........aaa#a.............",
00503 "................#.a.............",
00504 "...............#.a..............",
00505 "..............#.a...............",
00506 "...............a................",
00507 "................................",
00508 "................................",
00509 "................................",
00510 "................................",
00511 "................................"};
00513 
00515 void VTKViewer_InteractorStyle::loadCursors()
00516 {
00517   myDefCursor       = QCursor(Qt::ArrowCursor);
00518   myHandCursor      = QCursor(Qt::PointingHandCursor);
00519   myPanCursor       = QCursor(Qt::SizeAllCursor);
00520   myZoomCursor      = QCursor(QPixmap(imageZoomCursor));
00521   myRotateCursor    = QCursor(QPixmap(imageRotateCursor));
00522   mySpinCursor      = QCursor(QPixmap(imageRotateCursor)); // temporarly !!!!!!
00523   myGlobalPanCursor = QCursor(Qt::CrossCursor);
00524   myCursorState     = false;
00525 }
00526 
00527 
00529 bool VTKViewer_InteractorStyle::eventFilter(QObject* object, QEvent* event)
00530 {
00531   if (!myGUIWindow) return false;
00532   if ( (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::KeyPress) && object != myGUIWindow)
00533   {
00534     qApp->removeEventFilter(this);
00535     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00536   }
00537   return QObject::eventFilter(object, event);
00538 }
00539 
00540 
00542 void VTKViewer_InteractorStyle::startZoom()
00543 {
00544   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
00545   {
00546     onFinishOperation();
00547     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00548   }
00549   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ZOOM);
00550   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ZOOM;
00551   qApp->installEventFilter(this);
00552 }
00553 
00554 
00556 void VTKViewer_InteractorStyle::startPan()
00557 {
00558   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
00559   {
00560     onFinishOperation();
00561     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00562   }
00563   setCursor(VTK_INTERACTOR_STYLE_CAMERA_PAN);
00564   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_PAN;
00565   qApp->installEventFilter(this);
00566 }
00567 
00569 void VTKViewer_InteractorStyle::startRotate()
00570 {
00571   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
00572   {
00573     onFinishOperation();
00574     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00575   }
00576   setCursor(VTK_INTERACTOR_STYLE_CAMERA_ROTATE);
00577   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_ROTATE;
00578   qApp->installEventFilter(this);
00579 }
00580 
00581 
00583 void VTKViewer_InteractorStyle::startSpin()
00584 {
00585   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
00586   {
00587     onFinishOperation();
00588     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00589   }
00590   setCursor(VTK_INTERACTOR_STYLE_CAMERA_SPIN);
00591   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_SPIN;
00592   qApp->installEventFilter(this);
00593 }
00594 
00595 
00596 
00598 void VTKViewer_InteractorStyle::startFitArea()
00599 {
00600   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
00601   {
00602     onFinishOperation();
00603     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00604   }
00605   setCursor(VTK_INTERACTOR_STYLE_CAMERA_FIT);
00606   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_FIT;
00607   qApp->installEventFilter(this);
00608 }
00609 
00610 
00612 void  VTKViewer_InteractorStyle::ViewFitAll() {
00613   int aTriedronWasVisible = false;
00614   if(m_Trihedron){
00615     aTriedronWasVisible = m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
00616     if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
00617   }
00618 
00619   if(m_Trihedron->GetVisibleActorCount(CurrentRenderer)){
00620     m_Trihedron->VisibilityOff();
00621     ::ResetCamera(CurrentRenderer);
00622   }else{
00623     m_Trihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
00624     ::ResetCamera(CurrentRenderer,true);
00625   }
00626   if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
00627   else m_Trihedron->VisibilityOff();
00628   ::ResetCameraClippingRange(CurrentRenderer);
00629 }
00630 
00631 
00633 void VTKViewer_InteractorStyle::startGlobalPan()
00634 {
00635   if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
00636   {
00637     onFinishOperation();
00638     startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00639   }
00640   setCursor(VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN);
00641   ForcedState = VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN;
00642 
00643   // store current zoom scale
00644   vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
00645   myScale = cam->GetParallelScale();
00646 
00647   ViewFitAll();
00648 
00649   if (myGUIWindow) myGUIWindow->update();
00650   
00651   qApp->installEventFilter(this);
00652 }
00653 
00654 
00656 bool VTKViewer_InteractorStyle::needsRedrawing()
00657 {
00658   return State == VTK_INTERACTOR_STYLE_CAMERA_ZOOM   ||
00659          State == VTK_INTERACTOR_STYLE_CAMERA_PAN    ||
00660          State == VTK_INTERACTOR_STYLE_CAMERA_ROTATE ||
00661          State == VTK_INTERACTOR_STYLE_CAMERA_SPIN   ||
00662          State == VTK_INTERACTOR_STYLE_CAMERA_NONE;
00663 }
00664 
00665 
00672 void VTKViewer_InteractorStyle::fitRect(const int left, 
00673                                        const int top, 
00674                                        const int right, 
00675                                        const int bottom)
00676 {
00677   if (this->CurrentRenderer == NULL) return;
00678  
00679   // move camera
00680   int x = (left + right)/2;
00681   int y = (top + bottom)/2;
00682   int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
00683   int oldX = aSize[0]/2;
00684   int oldY = aSize[1]/2;
00685   TranslateView(oldX, oldY, x, y);
00686 
00687   // zoom camera
00688   double dxf = (double)(aSize[0]) / (double)(abs(right - left));
00689   double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
00690   double zoomFactor = (dxf + dyf)/2 ;
00691 
00692   vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
00693   if(aCam->GetParallelProjection())
00694     aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
00695   else{
00696     aCam->Dolly(zoomFactor);
00697     ::ResetCameraClippingRange(this->CurrentRenderer);
00698   }
00699   
00700   myGUIWindow->update();
00701 }
00702 
00703 
00705 void VTKViewer_InteractorStyle::startOperation(int operation)
00706 {
00707   switch(operation)
00708   { 
00709   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
00710   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
00711   case VTK_INTERACTOR_STYLE_CAMERA_PAN:
00712   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
00713   case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
00714   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
00715   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
00716     if (State != VTK_INTERACTOR_STYLE_CAMERA_NONE)
00717       startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00718     State = operation;
00719     if (State != VTK_INTERACTOR_STYLE_CAMERA_SELECT)
00720       setCursor(operation);
00721     onStartOperation();
00722     break;
00723   case VTK_INTERACTOR_STYLE_CAMERA_NONE:
00724   default:
00725     setCursor(VTK_INTERACTOR_STYLE_CAMERA_NONE);
00726     State = ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE;
00727     break;
00728   }
00729 }
00730 
00731 
00733 void VTKViewer_InteractorStyle::setCursor(const int operation)
00734 {
00735   if (!myGUIWindow) return;
00736   switch (operation)
00737   {
00738     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
00739       myGUIWindow->setCursor(myZoomCursor); 
00740       myCursorState = true;
00741       break;
00742     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
00743       myGUIWindow->setCursor(myPanCursor); 
00744       myCursorState = true;
00745       break;
00746     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
00747       myGUIWindow->setCursor(myRotateCursor); 
00748       myCursorState = true;
00749       break;
00750     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
00751       myGUIWindow->setCursor(mySpinCursor); 
00752       myCursorState = true;
00753       break;
00754     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
00755       myGUIWindow->setCursor(myGlobalPanCursor); 
00756       myCursorState = true;
00757       break;
00758     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
00759     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
00760       myGUIWindow->setCursor(myHandCursor); 
00761       myCursorState = true;
00762       break;
00763     case VTK_INTERACTOR_STYLE_CAMERA_NONE:
00764     default:
00765       myGUIWindow->setCursor(myDefCursor); 
00766       myCursorState = false;
00767       break;
00768   }
00769 }
00770 
00774 void VTKViewer_InteractorStyle::drawRect()
00775 {
00776   if ( !myRectBand ) {
00777     myRectBand = new QRubberBand( QRubberBand::Rectangle, myGUIWindow );
00778     QPalette palette;
00779     palette.setColor(myRectBand->foregroundRole(), Qt::white);
00780     myRectBand->setPalette(palette);
00781   }
00782   myRectBand->hide();
00783 
00784   QRect aRect(myPoint, myOtherPoint);
00785   myRectBand->setGeometry( aRect );
00786   myRectBand->setVisible( aRect.isValid() );
00787 }
00788 
00792 void VTKViewer_InteractorStyle::endDrawRect()
00793 {
00794   delete myRectBand;
00795   myRectBand = 0;
00796 }
00797 
00799 void VTKViewer_InteractorStyle::onStartOperation()
00800 {
00801   if (!myGUIWindow) return;
00802   // VSV: LOD actor activisation
00803   //  this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
00804   switch (State) {
00805     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
00806     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
00807     {
00808       drawRect();
00809       break;
00810     }
00811     case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
00812     case VTK_INTERACTOR_STYLE_CAMERA_PAN:
00813     case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
00814     case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN:
00815     case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
00816       break;
00817   }
00818 }
00819 
00820 
00822 void VTKViewer_InteractorStyle::onFinishOperation() 
00823 {
00824   if (!myGUIWindow) return;
00825 
00826 
00827 //  SUIT_Study* aActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
00828 //  SALOME_Selection* aSel    = SALOME_Selection::Selection( aActiveStudy->getSelection() );
00829 
00830   // VSV: LOD actor activisation
00831   //  rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
00832 
00833 //  Selection_Mode aSelectionMode = aSel->SelectionMode();
00834 //  bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
00835 
00836 /*  switch (State) {
00837     case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
00838     case VTK_INTERACTOR_STYLE_CAMERA_FIT:
00839     {
00840       QPainter p(myGUIWindow);
00841       p.setPen(Qt::lightGray);
00842       p.setRasterOp(Qt::XorROP);
00843       QRect rect(myPoint, myOtherPoint);
00844       p.drawRect(rect);
00845       rect = rect.normalize();
00846       if (State == VTK_INTERACTOR_STYLE_CAMERA_FIT) {
00847         // making fit rect opeation 
00848         int w, h;
00849         m_Interactor->GetSize(w, h);
00850         int x1, y1, x2, y2;
00851         x1 = rect.left(); 
00852         y1 = h - rect.top() - 1;
00853         x2 = rect.right(); 
00854         y2 = h - rect.bottom() - 1;
00855         fitRect(x1, y1, x2, y2);
00856       }
00857       else {
00858         if (myPoint == myOtherPoint) {
00859           // process point selection
00860           int w, h, x, y;
00861           m_Interactor->GetSize(w, h);
00862           x = myPoint.x(); 
00863           y = h - myPoint.y() - 1;
00864 
00865           this->FindPokedRenderer(x, y);
00866           m_Interactor->StartPickCallback();
00867 
00868           vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
00869           aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
00870     
00871           SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
00872 
00873           if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
00874             int aVtkId = picker->GetCellId();
00875             if ( aVtkId >= 0 && SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
00876               int anObjId = SActor->GetElemObjId(aVtkId);
00877               if(anObjId >= 0){
00878                 Handle(SALOME_InteractiveObject) IO = SActor->getIO();
00879                 if(aSelectionMode != EdgeOfCellSelection) {
00880                   if(CheckDimensionId(aSelectionMode,SActor,anObjId)){
00881                     if (IsSelected(IO,aSel)) {
00882                       // This IO is already in the selection
00883                       aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
00884                     } else {
00885                       if (!myShiftState) {
00886                         this->HighlightProp( NULL );
00887                         aSel->ClearIObjects();
00888                       }
00889                       aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
00890                       aSel->AddIObject( IO, false );
00891                     }
00892                   }
00893                 }else{
00894                   if (!myShiftState) {
00895                     this->HighlightProp( NULL );
00896                     aSel->ClearIObjects();
00897                   }
00898                   int anEdgeId = GetEdgeId(picker,SActor,anObjId);
00899                   if (anEdgeId >= 0) {
00900                     aSel->AddOrRemoveIndex( IO, anObjId, true, false);
00901                     aSel->AddOrRemoveIndex( IO, -anEdgeId-1, true, true );
00902                     aSel->AddIObject( IO, false );
00903                   } 
00904                 }
00905               }
00906             } else {
00907               this->HighlightProp( NULL );
00908               aSel->ClearIObjects();
00909             }
00910           } else if ( vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker) ) {
00911             int aVtkId = picker->GetPointId();
00912             if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
00913               if ( SActor && SActor->hasIO() ) {
00914                 int anObjId = SActor->GetNodeObjId(aVtkId);
00915                 if(anObjId >= 0){
00916                   Handle(SALOME_InteractiveObject) IO = SActor->getIO();
00917                   if(IsSelected(IO,aSel)) {
00918                     // This IO is already in the selection
00919                     aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
00920                   } else {
00921                     if(!myShiftState) {
00922                       this->HighlightProp( NULL );
00923                       aSel->ClearIObjects();
00924                     }
00925                     aSel->AddOrRemoveIndex( IO, anObjId, myShiftState, false );
00926                     aSel->AddIObject( IO, false );
00927                   }
00928                 }
00929               }
00930             } else {
00931               this->HighlightProp( NULL );
00932               aSel->ClearIObjects();
00933             } 
00934           } else {
00935             if ( SActor && SActor->hasIO() ) {
00936               this->PropPicked++;
00937               Handle(SALOME_InteractiveObject) IO = SActor->getIO();
00938               if(IsSelected(IO,aSel)) {
00939                 // This IO is already in the selection
00940                 if(myShiftState) {
00941                   aSel->RemoveIObject(IO);
00942                 }
00943               }
00944               else {
00945                 if(!myShiftState) {
00946                   this->HighlightProp( NULL );
00947                   aSel->ClearIObjects();
00948                 }
00949                 aSel->AddIObject( IO, false );
00950               }
00951             }else{
00952               // No selection clear all
00953               this->PropPicked = 0;
00954               this->HighlightProp( NULL );
00955               aSel->ClearIObjects();
00956             }
00957           }
00958           m_Interactor->EndPickCallback();
00959         } else {
00960           //processing rectangle selection
00961           QString aComponentDataType = SUIT_Application::getDesktop()->getComponentDataType();
00962           if(aSelActiveCompOnly && aComponentDataType.isEmpty()) return;
00963           m_Interactor->StartPickCallback();
00964 
00965           if (!myShiftState) {
00966             this->PropPicked = 0;
00967             this->HighlightProp( NULL );
00968             aSel->ClearIObjects();
00969           }
00970 
00971           // Compute bounds
00972           //      vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
00973           QRect rect(myPoint, myOtherPoint);
00974           rect = rect.normalize();
00975           int w, h;
00976           m_Interactor->GetSize(w, h);
00977           int x1, y1, x2, y2;
00978           x1 = rect.left(); 
00979           y1 = h - rect.top() - 1;
00980           x2 = rect.right(); 
00981           y2 = h - rect.bottom() - 1;
00982 
00983           switch (aSelectionMode) {
00984           case NodeSelection: {
00985             if ( vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(m_Interactor->GetPicker()) ) {
00986               vtkActorCollection* aListActors = this->CurrentRenderer->GetActors();
00987               aListActors->InitTraversal();
00988               while (vtkActor* aActor = aListActors->GetNextActor()) {
00989                 if (!aActor->GetVisibility()) 
00990                   continue;
00991                 if(SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aActor)) {
00992                   if (SActor->hasIO()) {
00993                     Handle(SALOME_InteractiveObject) IO = SActor->getIO();
00994                     if (IO.IsNull()) 
00995                       continue;
00996                     if (aSelActiveCompOnly && aComponentDataType != IO->getComponentDataType())
00997                       continue;
00998                     if (vtkDataSet* aDataSet = SActor->GetInput()) {
00999                       SALOME_Selection::TContainerOfId anIndices;
01000                       for(int i = 0; i < aDataSet->GetNumberOfPoints(); i++) {
01001                         float aPoint[3];
01002                         aDataSet->GetPoint(i,aPoint);
01003                         if (IsInRect(aPoint,x1,y1,x2,y2)){
01004                           float aDisp[3];
01005                           ComputeWorldToDisplay(aPoint[0],aPoint[1],aPoint[2],aDisp);
01006                           if(aPointPicker->Pick(aDisp[0],aDisp[1],0.0,CurrentRenderer)){
01007                             if(vtkActorCollection *anActorCollection = aPointPicker->GetActors()){
01008                               if(anActorCollection->IsItemPresent(SActor)){
01009                                 float aPickedPoint[3];
01010                                 aPointPicker->GetMapperPosition(aPickedPoint);
01011                                 vtkIdType aVtkId = aDataSet->FindPoint(aPickedPoint);
01012                                 if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ){
01013                                   int anObjId = SActor->GetNodeObjId(aVtkId);
01014                                   anIndices.insert(anObjId);
01015                                 }
01016                               }
01017                             }
01018                           }
01019                         }
01020                       }
01021                       if (!anIndices.empty()) {
01022                         aSel->AddOrRemoveIndex(IO, anIndices, true, false);
01023                         aSel->AddIObject(IO, false);
01024                         anIndices.clear();
01025                       }else{
01026                         aSel->RemoveIObject(IO, false);
01027                       }
01028                     }
01029                   }
01030                 }
01031               }
01032             }
01033             break;
01034           }
01035           case CellSelection:
01036           case EdgeOfCellSelection:
01037           case EdgeSelection:
01038           case FaceSelection:
01039           case VolumeSelection: 
01040             {
01041               vtkSmartPointer<VTKViewer_CellRectPicker> picker = VTKViewer_CellRectPicker::New();
01042               picker->SetTolerance(0.001);
01043               picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
01044               
01045               vtkActorCollection* aListActors = picker->GetActors();
01046               aListActors->InitTraversal();
01047               while(vtkActor* aActor = aListActors->GetNextActor()) {
01048                 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
01049                   if (aSActor->hasIO()) {
01050                     Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
01051                     if (aSelActiveCompOnly && aComponentDataType != aIO->getComponentDataType())
01052                       continue;
01053                     VTKViewer_CellDataSet cellList = picker->GetCellData(aActor);
01054                     if ( !cellList.empty() ) {
01055                       SALOME_Selection::TContainerOfId anIndexes;
01056                       VTKViewer_CellDataSet::iterator it;
01057                       for ( it = cellList.begin(); it != cellList.end(); ++it ) {
01058                         int aCellId = (*it).cellId;
01059                         
01060                         if ( !IsValid( aSActor, aCellId ) )
01061                           continue;
01062                         
01063                         int anObjId = aSActor->GetElemObjId(aCellId);
01064                         if (anObjId != -1){
01065                           if ( CheckDimensionId(aSelectionMode,aSActor,anObjId) ) {
01066                             anIndexes.insert(anObjId);
01067                           }
01068                         }
01069                       }
01070                       aSel->AddOrRemoveIndex(aIO, anIndexes, true, false);
01071                       aSel->AddIObject(aIO, false);
01072                     }
01073                   }
01074                 }
01075               }
01076             }
01077             break;          
01078           case ActorSelection: // objects selection
01079             {
01080               vtkSmartPointer<VTKViewer_RectPicker> picker = VTKViewer_RectPicker::New();
01081               picker->SetTolerance(0.001);
01082               picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer);
01083 
01084               vtkActorCollection* aListActors = picker->GetActors();
01085               SALOME_ListIO aListIO;
01086               aListActors->InitTraversal();
01087               while(vtkActor* aActor = aListActors->GetNextActor()) {
01088                 if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor)) {
01089                   if (aSActor->hasIO()) {
01090                     Handle(SALOME_InteractiveObject) aIO = aSActor->getIO();
01091                     if (!IsStored(aIO,aListIO))
01092                       aListIO.Append(aIO);
01093                   }
01094                 }
01095               }
01096               if (!aListIO.IsEmpty()) {
01097                 SALOME_ListIteratorOfListIO It(aListIO);
01098                 for(;It.More();It.Next()) {
01099                   Handle(SALOME_InteractiveObject) IOS = It.Value();
01100                   this->PropPicked++;
01101                   aSel->AddIObject( IOS, false );
01102                 }
01103               }
01104             } // end case 4
01105           } //end switch
01106           m_Interactor->EndPickCallback();
01107         }
01108         aActiveStudy->update3dViewers();
01109       } 
01110     } 
01111     break;
01112   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM:
01113   case VTK_INTERACTOR_STYLE_CAMERA_PAN:
01114   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE:
01115   case VTK_INTERACTOR_STYLE_CAMERA_SPIN:
01116     break;
01117   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: 
01118     {
01119       int w, h, x, y;
01120       m_Interactor->GetSize(w, h);
01121       x = myPoint.x(); 
01122       y = h - myPoint.y() - 1;
01123       Place(x, y);
01124     }
01125     break;
01126   }
01127   if (myGUIWindow) myGUIWindow->update();
01128 */
01129 }
01130 
01132 void VTKViewer_InteractorStyle::onOperation(QPoint mousePos) 
01133 {
01134   if (!myGUIWindow) return;
01135   int w, h;
01136   GetInteractor()->GetSize(w, h);
01137   switch (State) {
01138   case VTK_INTERACTOR_STYLE_CAMERA_PAN: 
01139     {
01140       // processing panning
01141       //this->FindPokedCamera(mousePos.x(), mousePos.y());
01142       this->PanXY(mousePos.x(), myPoint.y(), myPoint.x(), mousePos.y());
01143       myPoint = mousePos;
01144       break;
01145     }
01146   case VTK_INTERACTOR_STYLE_CAMERA_ZOOM: 
01147     {    
01148       // processing zooming
01149       //this->FindPokedCamera(mousePos.x(), mousePos.y());
01150       this->DollyXY(mousePos.x() - myPoint.x(), mousePos.y() - myPoint.y());
01151       myPoint = mousePos;
01152       break;
01153     }
01154   case VTK_INTERACTOR_STYLE_CAMERA_ROTATE: 
01155     {
01156       // processing rotation
01157       //this->FindPokedCamera(mousePos.x(), mousePos.y());
01158       this->RotateXY(mousePos.x() - myPoint.x(), myPoint.y() - mousePos.y());
01159       myPoint = mousePos;
01160       break;
01161     }
01162   case VTK_INTERACTOR_STYLE_CAMERA_SPIN: 
01163     {
01164       // processing spinning
01165       //this->FindPokedCamera(mousePos.x(), mousePos.y());
01166       this->SpinXY(mousePos.x(), mousePos.y(), myPoint.x(), myPoint.y());
01167       myPoint = mousePos;
01168       break;
01169     }
01170   case VTK_INTERACTOR_STYLE_CAMERA_GLOBAL_PAN: 
01171     {    
01172       break;
01173     }
01174   case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
01175     {
01176       if (!myCursorState)
01177         setCursor(VTK_INTERACTOR_STYLE_CAMERA_SELECT);
01178     }
01179   case VTK_INTERACTOR_STYLE_CAMERA_FIT:
01180     {
01181       myOtherPoint = mousePos;
01182       drawRect();
01183       break;
01184     }
01185   }
01186   this->LastPos[0] = mousePos.x();
01187   this->LastPos[1] = h - mousePos.y() - 1;
01188 }
01189 
01191 void VTKViewer_InteractorStyle::OnSelectionModeChanged()
01192 {
01193   
01194   myPreSelectionActor->SetVisibility(false);
01195   myElemId = myEdgeId = myNodeId = -1;
01196   mySelectedActor = NULL;
01197 }
01198 
01202 void VTKViewer_InteractorStyle::onCursorMove(QPoint mousePos) {
01203   // processing highlighting
01204 //  SUIT_Study* anActiveStudy = SUIT_Application::getDesktop()->getActiveStudy();
01205 //  SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() );
01206 //  Selection_Mode aSelectionMode = Sel->SelectionMode();
01207 
01208 /*  int w, h, x, y;
01209   m_Interactor->GetSize(w, h);
01210   x = mousePos.x(); y = h - mousePos.y() - 1;
01211 
01212   this->FindPokedRenderer(x,y);
01213   m_Interactor->StartPickCallback();
01214   myPreSelectionActor->SetVisibility(false);
01215 
01216   vtkPicker* aPicker = vtkPicker::SafeDownCast(m_Interactor->GetPicker());
01217   aPicker->Pick(x, y, 0.0, this->CurrentRenderer);
01218 
01219   SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aPicker->GetActor());
01220 
01221   if (vtkCellPicker* picker = vtkCellPicker::SafeDownCast(aPicker)) {
01222     int aVtkId = picker->GetCellId();
01223     if ( aVtkId >= 0 ) {
01224       int anObjId = SActor->GetElemObjId(aVtkId);
01225       if ( SActor && SActor->hasIO() && IsValid( SActor, aVtkId ) ) {
01226         bool anIsSameObjId = (mySelectedActor == SActor && myElemId == anObjId);
01227         bool aResult = anIsSameObjId;
01228         if(!anIsSameObjId) {
01229           if(aSelectionMode != EdgeOfCellSelection) {
01230             aResult = CheckDimensionId(aSelectionMode,SActor,anObjId);
01231             if(aResult){
01232               mySelectedActor = SActor;
01233               myElemId = anObjId;
01234               m_Interactor->setCellData(anObjId,SActor,myPreSelectionActor);
01235             }
01236           }
01237         }
01238         if(aSelectionMode == EdgeOfCellSelection){
01239           int anEdgeId = GetEdgeId(picker,SActor,anObjId);
01240           bool anIsSameEdgeId = (myEdgeId != anEdgeId) && anIsSameObjId;
01241           aResult = anIsSameEdgeId;
01242           if(!anIsSameEdgeId) {
01243             aResult = (anEdgeId >= 0);
01244             if (aResult) {
01245               mySelectedActor = SActor;
01246               myEdgeId = anEdgeId;
01247               myElemId = anObjId;
01248               m_Interactor->setEdgeData(anObjId,SActor,-anEdgeId-1,myPreSelectionActor);
01249             } 
01250           }
01251         }
01252         if(aResult) {
01253           myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
01254           myPreSelectionActor->SetVisibility(true);
01255         }
01256       }
01257     }
01258   }
01259   else if (vtkPointPicker* picker = vtkPointPicker::SafeDownCast(aPicker)) {
01260     int aVtkId = picker->GetPointId();
01261     if ( aVtkId >= 0 && IsValid( SActor, aVtkId, true ) ) {
01262       if ( SActor && SActor->hasIO() ) {
01263         int anObjId = SActor->GetNodeObjId(aVtkId);
01264         bool anIsSameObjId = (mySelectedActor == SActor && myNodeId == anObjId);
01265         if(!anIsSameObjId) {
01266           mySelectedActor = SActor;
01267           myNodeId = anObjId;
01268           m_Interactor->setPointData(anObjId,SActor,myPreSelectionActor);
01269         }
01270         myPreSelectionActor->GetProperty()->SetRepresentationToSurface();
01271         myPreSelectionActor->SetVisibility(true);
01272       }
01273     }
01274   }
01275   else if ( vtkPicker::SafeDownCast(aPicker) ) {
01276     if ( SActor ) {
01277       if ( myPreViewActor != SActor ) {
01278         if ( myPreViewActor != NULL ) {
01279           myPreViewActor->SetPreSelected( false );
01280         }
01281         myPreViewActor = SActor;
01282               
01283         if ( SActor->hasIO() ) {
01284           Handle( SALOME_InteractiveObject) IO = SActor->getIO();
01285           if ( !IsSelected(IO,Sel) ) {
01286             // Find All actors with same IO
01287             vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
01288             theActors->InitTraversal();
01289             while( vtkActor *ac = theActors->GetNextActor() ) {
01290               if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
01291                 if ( anActor->hasIO() ) {
01292                   Handle(SALOME_InteractiveObject) IOS = anActor->getIO();
01293                   if(IO->isSame(IOS)) {
01294                     anActor->SetPreSelected( true );
01295                   }
01296                 }
01297               }
01298             }
01299           }
01300         }
01301       }
01302     } else {
01303       myPreViewActor = NULL;
01304       vtkActorCollection* theActors = this->CurrentRenderer->GetActors();
01305       theActors->InitTraversal();
01306       while( vtkActor *ac = theActors->GetNextActor() ) {
01307         if ( SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ) ) {
01308           anActor->SetPreSelected( false );
01309         }
01310       }
01311     }
01312   }
01313   m_Interactor->EndPickCallback();
01314   //m_Interactor->Render();
01315   myGUIWindow->update();
01316   
01317   this->LastPos[0] = x;
01318   this->LastPos[1] = y;*/
01319 }
01320 
01322 void VTKViewer_InteractorStyle::Place(const int theX, const int theY) 
01323 {
01324   if (this->CurrentRenderer == NULL) {
01325     return;
01326   }
01327 
01328   //translate view
01329   int *aSize = this->CurrentRenderer->GetRenderWindow()->GetSize();
01330   int centerX = aSize[0]/2;
01331   int centerY = aSize[1]/2;
01332 
01333   TranslateView(centerX, centerY, theX, theY);
01334 
01335   // restore zoom scale
01336   vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
01337   cam->SetParallelScale(myScale);
01338   ::ResetCameraClippingRange(this->CurrentRenderer);
01339 
01340   if (myGUIWindow) myGUIWindow->update();
01341 
01342 }
01343 
01344 
01345 
01347 void VTKViewer_InteractorStyle::TranslateView(int toX, int toY, int fromX, int fromY)
01348 {
01349   vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
01350   vtkFloatingPointType viewFocus[4], focalDepth, viewPoint[3];
01351   vtkFloatingPointType newPickPoint[4], oldPickPoint[4], motionVector[3];
01352   cam->GetFocalPoint(viewFocus);
01353 
01354   this->ComputeWorldToDisplay(viewFocus[0], viewFocus[1],
01355                               viewFocus[2], viewFocus);
01356   focalDepth = viewFocus[2];
01357 
01358   this->ComputeDisplayToWorld(vtkFloatingPointType(toX), vtkFloatingPointType(toY),
01359                               focalDepth, newPickPoint);
01360   this->ComputeDisplayToWorld(vtkFloatingPointType(fromX),vtkFloatingPointType(fromY),
01361                               focalDepth, oldPickPoint);
01362   
01363   // camera motion is reversed
01364   motionVector[0] = oldPickPoint[0] - newPickPoint[0];
01365   motionVector[1] = oldPickPoint[1] - newPickPoint[1];
01366   motionVector[2] = oldPickPoint[2] - newPickPoint[2];
01367   
01368   cam->GetFocalPoint(viewFocus);
01369   cam->GetPosition(viewPoint);
01370   cam->SetFocalPoint(motionVector[0] + viewFocus[0],
01371                      motionVector[1] + viewFocus[1],
01372                      motionVector[2] + viewFocus[2]);
01373   cam->SetPosition(motionVector[0] + viewPoint[0],
01374                    motionVector[1] + viewPoint[1],
01375                    motionVector[2] + viewPoint[2]);
01376 }
01377 
01378 
01380 bool VTKViewer_InteractorStyle::IsInRect(vtkActor* theActor, 
01381                                                const int left, const int top, 
01382                                                const int right, const int bottom)
01383 {
01384   vtkFloatingPointType* aBounds = theActor->GetBounds();
01385   vtkFloatingPointType aMin[3], aMax[3];
01386   ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
01387   ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
01388   if (aMin[0] > aMax[0]) {
01389     vtkFloatingPointType aBuf = aMin[0];
01390     aMin[0] = aMax[0];
01391     aMax[0] = aBuf;
01392   }
01393   if (aMin[1] > aMax[1]) {
01394     vtkFloatingPointType aBuf = aMin[1];
01395     aMin[1] = aMax[1];
01396     aMax[1] = aBuf;    
01397   }
01398 
01399   return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
01400 }
01401 
01402 
01404 bool VTKViewer_InteractorStyle::IsInRect(vtkCell* theCell, 
01405                                                const int left, const int top, 
01406                                                const int right, const int bottom)
01407 {
01408   vtkFloatingPointType* aBounds = theCell->GetBounds();
01409   vtkFloatingPointType aMin[3], aMax[3];
01410   ComputeWorldToDisplay(aBounds[0], aBounds[2], aBounds[4], aMin);
01411   ComputeWorldToDisplay(aBounds[1], aBounds[3], aBounds[5], aMax);
01412   if (aMin[0] > aMax[0]) {
01413     vtkFloatingPointType aBuf = aMin[0];
01414     aMin[0] = aMax[0];
01415     aMax[0] = aBuf;
01416   }
01417   if (aMin[1] > aMax[1]) {
01418     vtkFloatingPointType aBuf = aMin[1];
01419     aMin[1] = aMax[1];
01420     aMax[1] = aBuf;    
01421   }
01422 
01423   return ((aMin[0]>left) && (aMax[0]<right) && (aMin[1]>bottom) && (aMax[1]<top));
01424 }
01425 
01427 bool VTKViewer_InteractorStyle::IsInRect(vtkFloatingPointType* thePoint, 
01428                                          const int left, const int top, 
01429                                          const int right, const int bottom)
01430 {
01431   vtkFloatingPointType aPnt[3];
01432   ComputeWorldToDisplay(thePoint[0], thePoint[1], thePoint[2], aPnt);
01433 
01434   return ((aPnt[0]>left) && (aPnt[0]<right) && (aPnt[1]>bottom) && (aPnt[1]<top));
01435 }
01436 
01438 void  VTKViewer_InteractorStyle::SetFilter( const Handle(VTKViewer_Filter)& theFilter )
01439 {
01440   myFilters[ theFilter->GetId() ] = theFilter;
01441 }
01442 
01446 bool  VTKViewer_InteractorStyle::IsFilterPresent( const int theId )
01447 {
01448   return myFilters.find( theId ) != myFilters.end();
01449 }
01450 
01454 void  VTKViewer_InteractorStyle::RemoveFilter( const int theId )
01455 {
01456   if ( IsFilterPresent( theId ) )
01457     myFilters.erase( theId );
01458 }
01459 
01465 bool VTKViewer_InteractorStyle::IsValid( VTKViewer_Actor* theActor,
01466                                                const int     theId,
01467                                                const bool    theIsNode )
01468 {
01469   std::map<int, Handle(VTKViewer_Filter)>::const_iterator anIter;
01470   for ( anIter = myFilters.begin(); anIter != myFilters.end(); ++anIter )
01471   {
01472     const Handle(VTKViewer_Filter)& aFilter = anIter->second;
01473     if ( theIsNode == aFilter->IsNodeFilter() &&
01474          !aFilter->IsValid( theActor, theId ) )
01475       return false;
01476   }
01477   return true;
01478 }
01479 
01481 Handle(VTKViewer_Filter) VTKViewer_InteractorStyle::GetFilter( const int theId )
01482 {
01483   return IsFilterPresent( theId ) ? myFilters[ theId ] : Handle(VTKViewer_Filter)();
01484 }
01485 
01490 void VTKViewer_InteractorStyle::IncrementalPan( const int incrX, const int incrY )
01491 {
01492   this->PanXY( incrX, incrY, 0, 0 );
01493 }
01494 
01498 void VTKViewer_InteractorStyle::IncrementalZoom( const int incr )
01499 {
01500   this->DollyXY( incr, incr );
01501 }
01502 
01507 void VTKViewer_InteractorStyle::IncrementalRotate( const int incrX, const int incrY )
01508 {
01509   this->RotateXY( incrX, -incrY );
01510 }
01511 
01512 
01513 
01514 
01515 
01516 
01517 
01518 
01519 
01520 
01521 
01522 
01523 
01524 
01525 
01526 
01527 
01528 
01529 
01530 
01531 
01532 
01533 
01534