Back to index

salome-gui  6.5.0
SVTK_ViewParameterDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  SALOME VTKViewer : build VTK viewer into Salome desktop
00021 //  File   : 
00022 //  Author : 
00023 
00024 #include "SVTK_ViewParameterDlg.h"
00025 #include "SVTK_ViewWindow.h"
00026 #include "SVTK_RenderWindowInteractor.h"
00027 #include "SVTK_Event.h"
00028 #include "SVTK_InteractorStyle.h"
00029 
00030 #include "VTKViewer_Utilities.h"
00031 
00032 #include "QtxAction.h"
00033 
00034 #include <QLineEdit>
00035 #include <QGroupBox>
00036 #include <QLabel>
00037 #include <QPushButton>
00038 #include <QGridLayout>
00039 #include <QDoubleValidator>
00040 #include <QCheckBox>
00041 #include <QRadioButton>
00042 #include <QButtonGroup>
00043 
00044 #include <vtkCallbackCommand.h>
00045 #include <vtkRenderer.h>
00046 #include <vtkCamera.h>
00047 #include <vtkGenericRenderWindowInteractor.h>
00048 
00052 SVTK_ViewParameterDlg::SVTK_ViewParameterDlg(QtxAction* theAction,
00053                                              SVTK_ViewWindow* theParent,
00054                                              const char* theName):
00055   ViewerTools_DialogBase(theAction, theParent, theName),
00056   myMainWindow(theParent),
00057   myPriority(0.0),
00058   myEventCallbackCommand(vtkCallbackCommand::New()),
00059   myRWInteractor(theParent->GetInteractor())
00060 {
00061   setWindowTitle(tr("DLG_TITLE"));
00062   setSizeGripEnabled(TRUE);
00063 
00064   // Top layout
00065   QVBoxLayout* aTopLayout = new QVBoxLayout(this);
00066   aTopLayout->setSpacing(6);
00067   aTopLayout->setMargin(11);
00068 
00069   // Projection mode
00070   QGroupBox* aGroupBoxMode = new QGroupBox(tr("PROJECTION_MODE"), this);
00071   QHBoxLayout* aLayout1 = new QHBoxLayout(aGroupBoxMode);
00072 
00073   QRadioButton* aOrtho = new QRadioButton(tr("ORTHOGONAL_MODE"), aGroupBoxMode);
00074   QRadioButton* aPersp = new QRadioButton(tr("PERSPECTIVE_MODE"), aGroupBoxMode);
00075 
00076   aLayout1->addWidget(aOrtho);
00077   aLayout1->addWidget(aPersp);
00078 
00079   myProjectionMode = new QButtonGroup(aGroupBoxMode);
00080   myProjectionMode->addButton(aOrtho, 0);
00081   myProjectionMode->addButton(aPersp, 1);
00082   connect(myProjectionMode, SIGNAL(buttonClicked(int)), SLOT(onProjectionModeChanged(int)));
00083 
00084   // Focal point
00085   QGroupBox* aGroupBoxFocal = new QGroupBox(tr("FOCAL_POINT"), this);
00086   QVBoxLayout* aLayout2 = new QVBoxLayout(aGroupBoxFocal);
00087 
00088   myToBBCenter = new QPushButton(aGroupBoxFocal);
00089   myToBBCenter->setText(tr("LBL_TOBBCENTER"));
00090   aLayout2->addWidget(myToBBCenter);
00091   connect(myToBBCenter, SIGNAL(clicked()), this, SLOT(onToBBCenter()));
00092 
00093   myToOrigin = new QPushButton(aGroupBoxFocal);
00094   myToOrigin->setText(tr("LBL_TOORIGIN"));
00095   aLayout2->addWidget(myToOrigin);
00096   connect(myToOrigin, SIGNAL(clicked()), this, SLOT(onToOrigin()));
00097 
00098   mySelectPoint = new QPushButton(aGroupBoxFocal);
00099   mySelectPoint->setText(tr("LBL_SELECTPOINT"));
00100   mySelectPoint->setCheckable(true);
00101   aLayout2->addWidget(mySelectPoint);
00102   connect(mySelectPoint, SIGNAL(clicked()), this, SLOT(onSelectPoint()));
00103 
00104   // Focal point coordinates
00105   myFocalCoords = new QFrame(aGroupBoxFocal);
00106   myFocalCoords->setObjectName("FocalPointCoordinates");
00107 
00108   QHBoxLayout* aCoordLayout = new QHBoxLayout(myFocalCoords);
00109   aCoordLayout->setSpacing(6);
00110   aCoordLayout->setMargin(0);
00111   
00112   QLabel* aLabelX = new QLabel(tr("LBL_X"), myFocalCoords);
00113   aLabelX->setFixedWidth(25);
00114   myFocalX = new QLineEdit(myFocalCoords);
00115   myFocalX->setValidator(new QDoubleValidator(myFocalX));
00116   myFocalX->setText(QString::number(0.0));
00117   connect(myFocalX, SIGNAL(textChanged(const QString&)), SLOT(onFocalCoordChanged()));
00118   
00119   QLabel* aLabelY = new QLabel(tr("LBL_Y"), myFocalCoords);
00120   aLabelY->setFixedWidth(25);
00121   myFocalY = new QLineEdit(myFocalCoords);
00122   myFocalY->setValidator(new QDoubleValidator(myFocalY));
00123   myFocalY->setText(QString::number(0.0));
00124   connect(myFocalY, SIGNAL(textChanged(const QString&)), SLOT(onFocalCoordChanged()));
00125 
00126   QLabel* aLabelZ = new QLabel(tr("LBL_Z"), myFocalCoords);
00127   aLabelZ->setFixedWidth(25);
00128   myFocalZ = new QLineEdit(myFocalCoords);
00129   myFocalZ->setValidator(new QDoubleValidator(myFocalZ));
00130   myFocalZ->setText(QString::number(0.0));
00131   connect(myFocalZ, SIGNAL(textChanged(const QString&)), SLOT(onFocalCoordChanged()));
00132 
00133   aCoordLayout->addWidget(aLabelX);
00134   aCoordLayout->addWidget(myFocalX);
00135   aCoordLayout->addWidget(aLabelY);
00136   aCoordLayout->addWidget(myFocalY);
00137   aCoordLayout->addWidget(aLabelZ);
00138   aCoordLayout->addWidget(myFocalZ);
00139   aLayout2->addWidget(myFocalCoords);
00140 
00141   // Camera position
00142   QGroupBox* aGroupBoxCamera = new QGroupBox(tr("CAMERA_POSITION"), this);
00143   QVBoxLayout* aLayout3 = new QVBoxLayout(aGroupBoxCamera);
00144 
00145   QRadioButton* aWorld = new QRadioButton(tr("WORLD_COORDINATES"), aGroupBoxCamera);
00146   QRadioButton* aRelative = new QRadioButton(tr("FOCAL_RELATIVE"), aGroupBoxCamera);
00147 
00148   QHBoxLayout* aHLayout = new QHBoxLayout;
00149   aHLayout->addWidget(aWorld);
00150   aHLayout->addWidget(aRelative);
00151   aLayout3->addLayout(aHLayout);
00152 
00153   myCameraPositionMode = new QButtonGroup(aGroupBoxCamera);
00154   myCameraPositionMode->addButton(aWorld, 0);
00155   myCameraPositionMode->addButton(aRelative, 1);
00156   connect(myCameraPositionMode, SIGNAL(buttonClicked(int)), SLOT(onPositionModeChanged(int)));
00157 
00158   // Camera coordinates
00159   myCameraCoords = new QFrame(aGroupBoxCamera);
00160   myCameraCoords->setObjectName("CameraCoordinates");
00161 
00162   aCoordLayout = new QHBoxLayout(myCameraCoords);
00163   aCoordLayout->setSpacing(6);
00164   aCoordLayout->setMargin(0);
00165 
00166   aLabelX = new QLabel(tr("LBL_X"), myCameraCoords);
00167   aLabelX->setFixedWidth(25);
00168   myCameraX = new QLineEdit(myCameraCoords);
00169   myCameraX->setValidator(new QDoubleValidator(myCameraX));
00170   myCameraX->setText(QString::number(0.0));
00171   connect(myCameraX, SIGNAL(textChanged(const QString&)), SLOT(onCameraCoordChanged()));
00172 
00173   aLabelY = new QLabel(tr("LBL_Y"), myCameraCoords);
00174   aLabelY->setFixedWidth(25);
00175   myCameraY = new QLineEdit(myCameraCoords);
00176   myCameraY->setValidator(new QDoubleValidator(myCameraY));
00177   myCameraY->setText(QString::number(0.0));
00178   connect(myCameraY, SIGNAL(textChanged(const QString&)), SLOT(onCameraCoordChanged()));
00179 
00180   aLabelZ = new QLabel(tr("LBL_Z"), myCameraCoords);
00181   aLabelZ->setFixedWidth(25);
00182   myCameraZ = new QLineEdit(myCameraCoords);
00183   myCameraZ->setValidator(new QDoubleValidator(myCameraZ));
00184   myCameraZ->setText(QString::number(1.0));
00185   connect(myCameraZ, SIGNAL(textChanged(const QString&)), SLOT(onCameraCoordChanged()));
00186 
00187   aCoordLayout->addWidget(aLabelX);
00188   aCoordLayout->addWidget(myCameraX);
00189   aCoordLayout->addWidget(aLabelY);
00190   aCoordLayout->addWidget(myCameraY);
00191   aCoordLayout->addWidget(aLabelZ);
00192   aCoordLayout->addWidget(myCameraZ);
00193   aLayout3->addWidget(myCameraCoords);
00194 
00195   // Projection direction
00196   QFrame* line1 = new QFrame(aGroupBoxCamera);
00197   line1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
00198   aLayout3->addWidget(line1);
00199 
00200   QLabel* aLabel = new QLabel(tr("PROJECTION_DIRECTION"), aGroupBoxCamera);
00201   aLayout3->addWidget(aLabel);
00202 
00203   myProjDirection = new QFrame(aGroupBoxCamera);
00204   myProjDirection->setObjectName("ProjectionDirection");
00205 
00206   aCoordLayout = new QHBoxLayout(myProjDirection);
00207   aCoordLayout->setSpacing(6);
00208   aCoordLayout->setMargin(0);
00209 
00210   aLabelX = new QLabel(tr("LBL_DX"), myProjDirection);
00211   aLabelX->setFixedWidth(25);
00212   myProjDirX = new QLineEdit(myProjDirection);
00213   myProjDirX->setValidator(new QDoubleValidator(myProjDirX));
00214   myProjDirX->setText(QString::number(0.0));
00215   connect(myProjDirX, SIGNAL(textChanged(const QString&)), SLOT(onDirectionChanged()));
00216 
00217   aLabelY = new QLabel(tr("LBL_DY"), myProjDirection);
00218   aLabelY->setFixedWidth(25);
00219   myProjDirY = new QLineEdit(myProjDirection);
00220   myProjDirY->setValidator(new QDoubleValidator(myProjDirY));
00221   myProjDirY->setText(QString::number(0.0));
00222   connect(myProjDirY, SIGNAL(textChanged(const QString&)), SLOT(onDirectionChanged()));
00223 
00224   aLabelZ = new QLabel(tr("LBL_DZ"), myProjDirection);
00225   aLabelZ->setFixedWidth(25);
00226   myProjDirZ = new QLineEdit(myProjDirection);
00227   myProjDirZ->setValidator(new QDoubleValidator(myProjDirZ));
00228   myProjDirZ->setText(QString::number(-1.0));
00229   connect(myProjDirZ, SIGNAL(textChanged(const QString&)), SLOT(onDirectionChanged()));
00230 
00231   aCoordLayout->addWidget(aLabelX);
00232   aCoordLayout->addWidget(myProjDirX);
00233   aCoordLayout->addWidget(aLabelY);
00234   aCoordLayout->addWidget(myProjDirY);
00235   aCoordLayout->addWidget(aLabelZ);
00236   aCoordLayout->addWidget(myProjDirZ);
00237   aLayout3->addWidget(myProjDirection);
00238 
00239   // Distance to focal point
00240   QHBoxLayout* aHorLayout = new QHBoxLayout;
00241   aHorLayout->setSpacing(6);
00242 
00243   aLabel = new QLabel(tr("FOCAL_DISTANCE"), aGroupBoxCamera);
00244   myDistance = new QLineEdit(aGroupBoxCamera);
00245   QDoubleValidator* aVal = new QDoubleValidator(myDistance);
00246   aVal->setBottom(0.0002); // VTK minimal distance
00247   myDistance->setValidator(aVal);
00248   myDistance->setText(QString::number(1.0));
00249   connect(myDistance, SIGNAL(textChanged(const QString&)), SLOT(onDistanceChanged()));
00250   
00251   aHorLayout->addWidget(aLabel);
00252   aHorLayout->addWidget(myDistance);
00253   aLayout3->addLayout(aHorLayout);
00254 
00255   // View Up direction
00256   QFrame* line2 = new QFrame(aGroupBoxCamera);
00257   line2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
00258   aLayout3->addWidget(line2);
00259 
00260   aLabel = new QLabel(tr("VIEW_UP_DIRECTION"), aGroupBoxCamera);
00261   aLayout3->addWidget(aLabel);
00262 
00263   myViewDirection = new QFrame(aGroupBoxCamera);
00264   myViewDirection->setObjectName("ViewUpDirection");
00265   aLayout3->addWidget(myViewDirection);
00266 
00267   aCoordLayout = new QHBoxLayout(myViewDirection);
00268   aCoordLayout->setSpacing(6);
00269   aCoordLayout->setMargin(0);
00270 
00271   aLabelX = new QLabel(tr("LBL_DX"), myViewDirection);
00272   aLabelX->setFixedWidth(25);
00273   myViewDirX = new QLineEdit(myViewDirection);
00274   myViewDirX->setValidator(new QDoubleValidator(myViewDirX));
00275   myViewDirX->setText(QString::number(0.0));
00276   connect(myViewDirX, SIGNAL(textChanged(const QString&)), SLOT(onViewDirectionChanged()));
00277 
00278   aLabelY = new QLabel(tr("LBL_DY"), myViewDirection);
00279   aLabelY->setFixedWidth(25);
00280   myViewDirY = new QLineEdit(myViewDirection);
00281   myViewDirY->setValidator(new QDoubleValidator(myViewDirY));
00282   myViewDirY->setText(QString::number(1.0));
00283   connect(myViewDirY, SIGNAL(textChanged(const QString&)), SLOT(onViewDirectionChanged()));
00284 
00285   aLabelZ = new QLabel(tr("LBL_DZ"), myViewDirection);
00286   aLabelZ->setFixedWidth(25);
00287   myViewDirZ = new QLineEdit(myViewDirection);
00288   myViewDirZ->setValidator(new QDoubleValidator(myViewDirZ));
00289   myViewDirZ->setText(QString::number(0.0));
00290   connect(myViewDirZ, SIGNAL(textChanged(const QString&)), SLOT(onViewDirectionChanged()));
00291 
00292   aCoordLayout->addWidget(aLabelX);
00293   aCoordLayout->addWidget(myViewDirX);
00294   aCoordLayout->addWidget(aLabelY);
00295   aCoordLayout->addWidget(myViewDirY);
00296   aCoordLayout->addWidget(aLabelZ);
00297   aCoordLayout->addWidget(myViewDirZ);
00298 
00299   // Zooming
00300   QGroupBox* aGroupBoxZoom = new QGroupBox(tr("ZOOMING"), this);
00301   QVBoxLayout* aLayout4 = new QVBoxLayout(aGroupBoxZoom);
00302 
00303   // Parallel scale
00304   myScaleBox = new QFrame(aGroupBoxZoom);
00305   myScaleBox->setObjectName("ScaleValue");
00306 
00307   aHorLayout = new QHBoxLayout(myScaleBox);
00308   aHorLayout->setSpacing(6);
00309   aHorLayout->setMargin(0);
00310 
00311   aLabel = new QLabel(tr("LBL_SCALE"), myScaleBox);
00312   myScale = new QLineEdit(myScaleBox);
00313   QDoubleValidator* aVal2 = new QDoubleValidator(myScale);
00314   aVal2->setBottom(0.000001); // VTK minimal scale
00315   myScale->setValidator(aVal2);
00316   myScale->setText(QString::number(1.0));
00317   connect(myScale, SIGNAL(textChanged(const QString&)), SLOT(onZoomChanged()));
00318 
00319   aHorLayout->addWidget(aLabel);
00320   aHorLayout->addWidget(myScale);
00321   aLayout4->addWidget(myScaleBox);
00322 
00323   // View Angle
00324   myViewAngleBox = new QFrame(aGroupBoxZoom);
00325   myViewAngleBox->setObjectName("ViewAngle");
00326 
00327   aHorLayout = new QHBoxLayout(myViewAngleBox);
00328   aHorLayout->setSpacing(6);
00329   aHorLayout->setMargin(0);
00330 
00331   aLabel = new QLabel(tr("LBL_VIEW_ANGLE"), myViewAngleBox);
00332   myViewAngle = new QLineEdit(myViewAngleBox);
00333   QDoubleValidator* aVal3 = new QDoubleValidator(myViewAngle);
00334   aVal3->setBottom(0.000001); // VTK minimal scale
00335   aVal3->setTop(179); // VTK minimal scale
00336   myViewAngle->setValidator(aVal3);
00337   myViewAngle->setText(QString::number(30.0));
00338   connect(myViewAngle, SIGNAL(textChanged(const QString&)), SLOT(onZoomChanged()));
00339 
00340   aHorLayout->addWidget(aLabel);
00341   aHorLayout->addWidget(myViewAngle);
00342   aLayout4->addWidget(myViewAngleBox);
00343 
00344   // "Close" button
00345   QGroupBox* aGroupBox = new QGroupBox(this);
00346   QHBoxLayout* aHBoxLayout2 = new QHBoxLayout(aGroupBox);
00347   aHBoxLayout2->setMargin(11);
00348   aHBoxLayout2->setSpacing(6);
00349 
00350   QPushButton* m_bClose = new QPushButton(tr("&Close"), aGroupBox );
00351   m_bClose->setObjectName("m_bClose");
00352   m_bClose->setAutoDefault(TRUE);
00353   m_bClose->setFixedSize(m_bClose->sizeHint());
00354   connect(m_bClose, SIGNAL(clicked()), this, SLOT(onClickClose()));
00355 
00356   // Layout buttons
00357   aHBoxLayout2->addWidget(m_bClose);
00358 
00359   // Layout top level widgets
00360   aTopLayout->addWidget(aGroupBoxMode);
00361   aTopLayout->addWidget(aGroupBoxFocal);
00362   aTopLayout->addWidget(aGroupBoxCamera);
00363   aTopLayout->addWidget(aGroupBoxZoom);
00364   aTopLayout->addWidget(aGroupBox);
00365   aTopLayout->addStretch();
00366 
00367   // initial state
00368   myProjectionMode->button(0)->setChecked(true);
00369   myCameraPositionMode->button(0)->setChecked(true);
00370 
00371   setEnabled(myCameraCoords, myCameraPositionMode->checkedId() == 0);
00372 
00373   myScaleBox->setVisible(myProjectionMode->checkedId() == 0);
00374   myViewAngleBox->setVisible(myProjectionMode->checkedId() == 1);
00375 
00376   updateData();
00377 
00378   this->resize(400, this->sizeHint().height());
00379 
00380   myEventCallbackCommand->Delete();
00381   myEventCallbackCommand->SetClientData(this);
00382   myEventCallbackCommand->SetCallback(SVTK_ViewParameterDlg::ProcessEvents);
00383   myIsObserverAdded = false;
00384   myBusy = false;
00385 }
00386 
00387 /*
00388  *  Destroys the object and frees any allocated resources
00389  */
00390 SVTK_ViewParameterDlg::~SVTK_ViewParameterDlg()
00391 {
00392   // no need to delete child widgets, Qt does it all for us
00393 }
00394 
00395 void SVTK_ViewParameterDlg::addObserver()
00396 {
00397   if ( !myIsObserverAdded ) {
00398     vtkInteractorStyle* aIStyle = myRWInteractor->GetInteractorStyle();
00399     aIStyle->AddObserver(SVTK::FocalPointChanged, myEventCallbackCommand.GetPointer(), myPriority);
00400 
00401     vtkRenderer *aRenderer = myRWInteractor->getRenderer();
00402     aRenderer->AddObserver(vtkCommand::EndEvent, myEventCallbackCommand.GetPointer(), myPriority);
00403 
00404     myIsObserverAdded = true;
00405   }
00406 }
00407 
00411 void SVTK_ViewParameterDlg::ProcessEvents(vtkObject* vtkNotUsed(theObject), 
00412                                           unsigned long theEvent,
00413                                           void* theClientData, 
00414                                           void* theCallData)
00415 {
00416   SVTK_ViewParameterDlg* self = reinterpret_cast<SVTK_ViewParameterDlg*>(theClientData);
00417   vtkFloatingPointType* aCoord;
00418   switch ( theEvent ) {
00419   case SVTK::FocalPointChanged:
00420     if ( theCallData )
00421     {
00422       aCoord = (vtkFloatingPointType*)theCallData;
00423       self->myBusy = true;
00424       self->myFocalX->setText( QString::number(aCoord[0]) );
00425       self->myFocalY->setText( QString::number(aCoord[1]) );
00426       self->myFocalZ->setText( QString::number(aCoord[2]) );
00427       self->myBusy = false;
00428       self->onFocalCoordChanged();
00429     }
00430     break;
00431   case vtkCommand::EndEvent:
00432     if ( self->myRWInteractor->getRenderer()->GetActiveCamera()->GetMTime() > self->myCameraMTime )
00433       self->updateData();
00434     break;
00435   }
00436 }
00437 
00438 void SVTK_ViewParameterDlg::updateData()
00439 {
00440   myBusy = true;
00441   vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
00442 
00443   int aParallel = aCamera->GetParallelProjection();
00444   myProjectionMode->button(aParallel?0:1)->setChecked(true);
00445   onProjectionModeChanged( myProjectionMode->checkedId() );
00446 
00447   double focal[3], pos[3], vup[3], proj[3], dist, scale, angle;
00448 
00449   aCamera->GetFocalPoint(focal);
00450   myFocalX->setText(QString::number(focal[0]));
00451   myFocalY->setText(QString::number(focal[1]));
00452   myFocalZ->setText(QString::number(focal[2]));
00453 
00454   aCamera->GetPosition(pos);
00455   myCameraX->setText(QString::number(pos[0]));
00456   myCameraY->setText(QString::number(pos[1]));
00457   myCameraZ->setText(QString::number(pos[2]));
00458 
00459   aCamera->GetDirectionOfProjection(proj);
00460   myProjDirX->setText(QString::number(proj[0]));
00461   myProjDirY->setText(QString::number(proj[1]));
00462   myProjDirZ->setText(QString::number(proj[2]));
00463 
00464   aCamera->GetViewUp(vup);
00465   myViewDirX->setText(QString::number(vup[0]));
00466   myViewDirY->setText(QString::number(vup[1]));
00467   myViewDirZ->setText(QString::number(vup[2]));
00468 
00469   dist = aCamera->GetDistance();
00470   myDistance->setText(QString::number(dist));
00471 
00472   scale = aCamera->GetParallelScale();
00473   myScale->setText(QString::number(scale));
00474 
00475   angle = aCamera->GetViewAngle();
00476   myViewAngle->setText(QString::number(angle));
00477 
00478   myCameraMTime.Modified();
00479   myBusy = false;
00480 }
00481 
00482 void SVTK_ViewParameterDlg::setEnabled(QFrame* theWidget, const bool theState)
00483 {
00484   QObjectList aChildren(theWidget->children());
00485   QObject* anObj;
00486   for(int i = 0; i < aChildren.size(); i++)
00487   {
00488     anObj = aChildren.at(i);
00489     if (anObj !=0 && anObj->inherits("QLineEdit"))
00490       ((QLineEdit*)anObj)->setReadOnly(!theState);
00491     if (anObj !=0 && anObj->inherits("QPushButton"))
00492       ((QLineEdit*)anObj)->setEnabled(theState);
00493   }
00494   
00495 }
00496 
00497 void SVTK_ViewParameterDlg::onProjectionModeChanged(int mode)
00498 {
00499   int aBtn = myProjectionMode->checkedId();
00500 
00501   vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
00502   aCamera->SetParallelProjection(aBtn == 0);
00503 
00504   myMainWindow->activateProjectionMode(aBtn);
00505 
00506   // update view
00507   myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
00508 
00509   if ( aBtn == 0 ) {
00510     myViewAngleBox->setVisible(false);
00511     myScaleBox->setVisible(true);
00512   }
00513   else {
00514     myScaleBox->setVisible(false);
00515     myViewAngleBox->setVisible(true);
00516   }
00517 }
00518 
00519 void SVTK_ViewParameterDlg::onPositionModeChanged(int mode)
00520 {
00521   setEnabled(myCameraCoords, myCameraPositionMode->checkedId() == 0);
00522 }
00523 
00524 void SVTK_ViewParameterDlg::onToBBCenter()
00525 {
00526   if ( mySelectPoint->isChecked() )
00527     mySelectPoint->toggle();
00528 
00529   myMainWindow->activateSetFocalPointGravity();
00530 }
00531 
00532 void SVTK_ViewParameterDlg::onToOrigin()
00533 {
00534   if ( mySelectPoint->isChecked() )
00535     mySelectPoint->toggle();
00536 
00537   myBusy = true;
00538   myFocalX->setText(QString::number(0.0));
00539   myFocalY->setText(QString::number(0.0));
00540   myFocalZ->setText(QString::number(0.0));
00541   myBusy = false;
00542 
00543   onFocalCoordChanged();
00544 }
00545 
00546 void SVTK_ViewParameterDlg::onSelectPoint()
00547 {
00548   if ( mySelectPoint->isChecked() )
00549     myMainWindow->activateStartFocalPointSelection();
00550   else
00551     mySelectPoint->toggle();
00552 }
00553 
00554 void SVTK_ViewParameterDlg::onFocalCoordChanged()
00555 {
00556   if ( myBusy ) return;
00557 
00558   if ( mySelectPoint->isChecked() )
00559     mySelectPoint->toggle();
00560 
00561   vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
00562   aCamera->SetFocalPoint(myFocalX->text().toDouble(),
00563                          myFocalY->text().toDouble(),
00564                          myFocalZ->text().toDouble());
00565 
00566   aCamera->OrthogonalizeViewUp();
00567   myRWInteractor->getRenderer()->ResetCameraClippingRange();
00568 
00569   // update view
00570   myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
00571 
00572   myMainWindow->activateSetFocalPointSelected();
00573 
00574   //updateProjection();
00575 }
00576 
00577 void SVTK_ViewParameterDlg::onCameraCoordChanged()
00578 {
00579   if ( myBusy ) return;
00580 
00581   vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
00582   aCamera->SetPosition(myCameraX->text().toDouble(),
00583                        myCameraY->text().toDouble(),
00584                        myCameraZ->text().toDouble());
00585 
00586   aCamera->OrthogonalizeViewUp();
00587   myRWInteractor->getRenderer()->ResetCameraClippingRange();
00588 
00589   // update view
00590   myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
00591 
00592   //updateProjection();
00593 }
00594 
00595 void SVTK_ViewParameterDlg::onDirectionChanged()
00596 {
00597   if ( myBusy ) return;
00598 
00599   updateCoordinates();
00600 }
00601 
00602 void SVTK_ViewParameterDlg::onDistanceChanged()
00603 {
00604   if ( myBusy ) return;
00605 
00606   updateCoordinates();
00607 }
00608 
00609 void SVTK_ViewParameterDlg::onViewDirectionChanged()
00610 {
00611   if ( myBusy ) return;
00612 
00613   vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
00614   aCamera->SetViewUp(myViewDirX->text().toDouble(),
00615                      myViewDirY->text().toDouble(),
00616                      myViewDirZ->text().toDouble());
00617 
00618   // update view
00619   myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
00620 }
00621 
00622 void SVTK_ViewParameterDlg::onZoomChanged()
00623 {
00624   if ( myBusy ) return;
00625 
00626   vtkCamera* aCamera = myRWInteractor->getRenderer()->GetActiveCamera();
00627 
00628   switch( myProjectionMode->checkedId() ) {
00629   case 0:
00630     aCamera->SetParallelScale(myScale->text().toDouble());
00631     break;
00632   case 1:
00633     aCamera->SetViewAngle(myViewAngle->text().toDouble());
00634     break;
00635   }
00636 
00637   // update view
00638   myRWInteractor->GetDevice()->CreateTimer(VTKI_TIMER_FIRST);
00639 }
00640 
00641 void SVTK_ViewParameterDlg::onClickClose()
00642 {
00643   reject();
00644 }
00645 
00646 void SVTK_ViewParameterDlg::updateProjection()
00647 {
00648   double pnt[3], pos[3], dir[3], dist;
00649 
00650   pnt[0] = myFocalX->text().toDouble();
00651   pnt[1] = myFocalY->text().toDouble();
00652   pnt[2] = myFocalZ->text().toDouble();
00653 
00654   pos[0] = myCameraX->text().toDouble();
00655   pos[1] = myCameraY->text().toDouble();
00656   pos[2] = myCameraZ->text().toDouble();
00657 
00658   dir[0] = pnt[0] - pos[0];
00659   dir[1] = pnt[1] - pos[1];
00660   dir[2] = pnt[2] - pos[2];
00661 
00662   dist = sqrt( dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2] );
00663 
00664   if ( dist > 0.0002 ) {
00665     dir[0] = dir[0] / dist;
00666     dir[1] = dir[1] / dist;
00667     dir[2] = dir[2] / dist;
00668   }
00669 
00670   myBusy = true;
00671   myProjDirX->setText(QString::number(dir[0]));
00672   myProjDirY->setText(QString::number(dir[1]));
00673   myProjDirZ->setText(QString::number(dir[2]));
00674 
00675   myDistance->setText(QString::number(dist));
00676   myBusy = false;
00677 }
00678 
00679 void SVTK_ViewParameterDlg::updateCoordinates()
00680 {
00681   double pnt[3], pos[3], dir[3], dist;
00682 
00683   pnt[0] = myFocalX->text().toDouble();
00684   pnt[1] = myFocalY->text().toDouble();
00685   pnt[2] = myFocalZ->text().toDouble();
00686 
00687   pos[0] = myCameraX->text().toDouble();
00688   pos[1] = myCameraY->text().toDouble();
00689   pos[2] = myCameraZ->text().toDouble();
00690 
00691   dir[0] = myProjDirX->text().toDouble();
00692   dir[1] = myProjDirY->text().toDouble();
00693   dir[2] = myProjDirZ->text().toDouble();
00694 
00695   dist = myDistance->text().toDouble();
00696 
00697   if (myCameraPositionMode->checkedId() == 1) {
00698     // recompute camera position
00699     dir[0] = -dir[0]; dir[1] = -dir[1]; dir[2] = -dir[2];
00700     if (computePoint(pnt, dir, dist, pos)) {
00701       myBusy = true;
00702       myCameraX->setText(QString::number(pos[0]));
00703       myCameraY->setText(QString::number(pos[1]));
00704       myCameraZ->setText(QString::number(pos[2]));
00705       myBusy = false;
00706       onCameraCoordChanged();
00707     }
00708   }
00709   else {
00710     // recompute focal point
00711     if (computePoint(pos, dir, dist, pnt)) {
00712       if (mySelectPoint->isChecked())
00713         mySelectPoint->toggle();
00714       myBusy = true;
00715       myFocalX->setText(QString::number(pnt[0]));
00716       myFocalY->setText(QString::number(pnt[1]));
00717       myFocalZ->setText(QString::number(pnt[2]));
00718       myBusy = false;
00719       onFocalCoordChanged();
00720     }
00721   }
00722 }
00723 
00724 bool SVTK_ViewParameterDlg::computePoint(const double start[3], 
00725                                          const double dir[3], 
00726                                          const double dist, 
00727                                          double result[3])
00728 {
00729   double d = sqrt(dir[0]*dir[0]+dir[1]*dir[1]+dir[2]*dir[2]);
00730   if ( d < 0.0002 ) return false;
00731 
00732   for (int i = 0; i < 3; i++)
00733     result[i] = start[i] + dir[i] * dist / d;
00734 
00735   return true;
00736 }