diff --git a/cmake/version.cmake b/cmake/version.cmake index e6b3c37..c491e7e 100644 --- a/cmake/version.cmake +++ b/cmake/version.cmake @@ -3,7 +3,7 @@ # set (QT_VTK_MAJOR_VERSION "8") -set (QT_VTK_MINOR_VERSION "6") +set (QT_VTK_MINOR_VERSION "7") set (QT_VTK_RELEASE_VERSION "0") set (QT_VTK_VERSION ${QT_VTK_MAJOR_VERSION}.${QT_VTK_MINOR_VERSION}.${QT_VTK_RELEASE_VERSION}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e293ec..98d396f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,4 @@ add_subdirectory (QtVtk) +add_subdirectory (viewpoint) diff --git a/src/QtVtk/CMakeLists.txt b/src/QtVtk/CMakeLists.txt index 0f4cee2..87e07f5 100644 --- a/src/QtVtk/CMakeLists.txt +++ b/src/QtVtk/CMakeLists.txt @@ -10,20 +10,21 @@ include (${GUIToolkitsVariables_CMAKE_DIR}/workarounds.cmake) find_package (VtkContrib 5 REQUIRED) include (${CMAKE_SOURCE_DIR}/cmake/qtvtk_common.cmake) # Après VtkContrib qui positionne les variables VTK_7, VTK_8 et VTK_9 -find_package (QtUtil 6 REQUIRED) +find_package (PrefsQt 6 REQUIRED) find_package(Qt${QT_MAJOR}Core NO_CMAKE_SYSTEM_PATH) # In order to enable moc ... if (VTK_9) find_package (VTK COMPONENTS GUISupportQt IOExportGL2PS FiltersExtraction) endif (VTK_9) file (GLOB HEADERS public/${CURRENT_PACKAGE_NAME}/*.h) -file (GLOB CPP_SOURCES *.cpp) +file (GLOB CPP_SOURCES *.cpp *.qrc) # On ajoute les en-têtes aux sources. C'est utile pour cmake dans certains cas, # par exemple lorsqu'ils doivent être pré-processés (moc, ...). add_library (QtVtk ${CPP_SOURCES} ${HEADERS}) set (ALL_TARGETS QtVtk) set_property (TARGET QtVtk PROPERTY AUTOMOC ON) +set_property (TARGET QtVtk PROPERTY AUTORCC ON) set_property (TARGET QtVtk PROPERTY VERSION ${QT_VTK_VERSION}) set_property (TARGET QtVtk PROPERTY SOVERSION ${QT_VTK_MAJOR_VERSION}) # Rem : en Qt v 4.* on utilise -DUSE_QT_WEBKIT @@ -51,7 +52,7 @@ endif(VTK_9) target_compile_definitions (QtVtk PUBLIC ${QT_VTK_PUBLIC_FLAGS}) target_compile_definitions (QtVtk PRIVATE ${QT_VTK_PRIVATE_FLAGS} ${QT_VTK_PRIVATE_HELP_FLAGS}) target_compile_options (QtVtk PRIVATE ${SHARED_CFLAGS}) # Requested by Qt ... -target_link_libraries (QtVtk PUBLIC QtUtil::QtUtil VtkContrib::VtkContrib) +target_link_libraries (QtVtk PUBLIC PrefsQt::PrefsQt VtkContrib::VtkContrib) # Etre capable une fois installée de retrouver vtk*, ... : # (Rem : en son absence on a Set runtime path of "/tmp/pignerol/install/lib/libQtVtk.so.5.0.0" to "") ... diff --git a/src/QtVtk/QtVTKPrintHelper.cpp b/src/QtVtk/QtVTKPrintHelper.cpp index 5ea1bdf..7248cec 100644 --- a/src/QtVtk/QtVTKPrintHelper.cpp +++ b/src/QtVtk/QtVTKPrintHelper.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -142,47 +143,6 @@ QtVTKPrintHelper::PrinterStatus QtVTKPrintHelper::print (vtkRenderWindow& window } // QtVTKPrintHelper::print -/** - * @return La première extension du filtre Qt reçu en argument (format NOM (*.ext1 *.ext2 ... *.extn). - */ -static string getFirstExtension (const string& filter) // v 7.4.0 -{ - UTF8String prepared (filter); - prepared.replace (string ("("), string (" "), true); // => nom *.ext1) - prepared.replace (string ("*"), string (""), true); // => nom .ext1) - prepared.replace (string (")"), string (""), true); // => nom *.ext1 - istringstream stream (prepared.utf8 ( )); - string name, ext; - stream >> name >> ext; - - - if ((false == stream.fail ( )) && (false == stream.bad ( ))) - return ext; - - return string ( ); -} // getFirstExtension - - -/** - * @param Nom de fichier proposé - * @param Filtre Qt utilisé lors du choix du fichier - * @return Le nom de fichier avec extension. Si le nom proposé n'en n'a pas alors la première du filtre est ajoutée. - */ -static string completeFileName (const string& path, const string& filter) // v 7.4.0 -{ - File file (path); - if (0 != file.getExtension ( ).length ( )) - return path; - - // Le fichier n'a pas d'extension, on rajoute la première du filtre - const string ext = getFirstExtension (filter); - UTF8String newPath (charset); - newPath << path << ext; - - return newPath.utf8 ( ); -} // completeFileName - - QtVTKPrintHelper::PrinterStatus QtVTKPrintHelper::printToFile (vtkRenderWindow& window, QWidget* top) { QPrinter printer; @@ -219,8 +179,7 @@ QtVTKPrintHelper::PrinterStatus QtVTKPrintHelper::printToFile (vtkRenderWindow& if (1 != fileList.size ( )) throw Exception ("Erreur, la liste de fichiers d'impression ne contient pas qu'un fichier."); -// string fileName (fileList [0].toStdString ( )); - string fileName (completeFileName (fileList [0].toStdString ( ), dialog.selectedNameFilter ( ).toStdString ( ))); // v 7.4.0 + string fileName (QtFileDialogUtilities::completeFileName (fileList [0].toStdString ( ), dialog.selectedNameFilter ( ).toStdString ( ))); // v 7.4.0 File file (fileName); if (false == file.isWritable ( )) @@ -277,7 +236,7 @@ QtVTKPrintHelper::PrinterStatus QtVTKPrintHelper::printTo4kFile (vtkRenderWindow if (1 != fileList.size ( )) throw Exception ("Erreur, la liste de fichiers d'impression ne contient pas qu'un fichier."); - const string fileName (completeFileName (fileList [0].toStdString ( ), dialog.selectedNameFilter ( ).toStdString ( ))); + const string fileName (QtFileDialogUtilities::completeFileName (fileList [0].toStdString ( ), dialog.selectedNameFilter ( ).toStdString ( ))); File file (fileName); if (false == file.isWritable ( )) { diff --git a/src/QtVtk/QtVtk.qrc b/src/QtVtk/QtVtk.qrc new file mode 100644 index 0000000..e7edcdb --- /dev/null +++ b/src/QtVtk/QtVtk.qrc @@ -0,0 +1,29 @@ + + + images/add_viewpoint.png + images/remove_viewpoint.png + images/remove_viewpoints.png + images/export_viewpoints.png + images/import_viewpoints.png + images/viewpoint_01.png + images/viewpoint_02.png + images/viewpoint_03.png + images/viewpoint_04.png + images/viewpoint_05.png + images/viewpoint_06.png + images/viewpoint_07.png + images/viewpoint_08.png + images/viewpoint_09.png + images/viewpoint_10.png + images/viewpoint_11.png + images/viewpoint_12.png + images/viewpoint_13.png + images/viewpoint_14.png + images/viewpoint_15.png + images/viewpoint_16.png + images/viewpoint_17.png + images/viewpoint_18.png + images/viewpoint_19.png + images/viewpoint_20.png + + diff --git a/src/QtVtk/QtVtkViewDefinitionDialog.cpp b/src/QtVtk/QtVtkViewDefinitionDialog.cpp new file mode 100644 index 0000000..2b5d980 --- /dev/null +++ b/src/QtVtk/QtVtkViewDefinitionDialog.cpp @@ -0,0 +1,179 @@ +#include "QtVtk/QtVtkViewDefinitionDialog.h" +#include +#include +#include + +#include + +#include + +#include +#include + + +USING_STD +USING_UTIL + +static const Charset charset ("àéèùô"); +USE_ENCODING_AUTODETECTION + +/** + * Aide pour positionner un widget au centre de "son parent". + * Utile depuis le passage à Qt 5 : une boite de dialogue modale ayant un parent est positionnée au centre du parent, ce qui est très bien, mais si on la + * déplace le parent suit le mouvement ... Donc pas moyen de voir ce qu'il y a dessous la boite de dialogue. + * => créer la boite de dialogue sans parent, et utiliser cette macro juste au moment de l'afficher. + */ +#ifndef QTVTK_CENTER_DIALOG +#define LEM_CENTER_DIALOG(dlg,parent) \ +if ((0 != dlg) && (0 != parent)) \ +{ \ + QRect pfg = parent->frameGeometry ( ); \ + QSize sz = dlg->size ( ); \ + dlg->move (pfg.x ( ) + (pfg.width ( ) - sz.width ( )) / 2, \ + pfg.y ( ) + (pfg.height ( ) - sz.height ( )) / 2); \ +} +#endif // LEM_CENTER_DIALOG + + +QtVtkViewDefinitionDialog::QtVtkViewDefinitionDialog ( + QWidget* parent, const string& title, bool modal, const UTF8String& name, const UTF8String& comment, + double position [3], double focal [3], double viewUp [3], double roll, + vtkRenderer* renderer, const string& helpURL, const string& helpTag) + : QDialog (0, true == modal ? (Qt::WindowFlags)(QtConfiguration::modalDialogWFlags | Qt::WindowStaysOnTopHint) : (Qt::WindowFlags)(QtConfiguration::amodalDialogWFlags | Qt::WindowStaysOnTopHint)), _viewDefinitionPanel (0), _closurePanel (0) +{ + setModal (modal); + setWindowTitle (QSTR (title)); + + // Creation de l'ihm : + QVBoxLayout* layout = new QVBoxLayout (this); + layout->setMargin (QtConfiguration::margin); + layout->setSizeConstraint (QLayout::SetMinimumSize); + QtGroupBox* frame = new QtGroupBox (QSTR ("Paramètres de la vue"), this, "frame"); + QVBoxLayout* frameLayout = new QVBoxLayout (frame); + layout->addWidget (frame); + frame->setLayout (frameLayout); + frame->setMargin (QtConfiguration::margin); + frame->setSpacing (QtConfiguration::spacing); + _viewDefinitionPanel = new QtVtkViewDefinitionPanel (frame, title, name, comment, position, focal, viewUp, roll, renderer); + _viewDefinitionPanel->adjustSize ( ); + frameLayout->addWidget (_viewDefinitionPanel); + + layout->addWidget (new QLabel (" ", this)); + _closurePanel = new QtDlgClosurePanel (this, true, "Appliquer", "Fermer", "Annuler",helpURL, helpTag); + layout->addWidget (_closurePanel); + _closurePanel->setMinimumSize (_closurePanel->sizeHint ( )); + + // Par defaut le bouton OK est artificellement clique par QDialog quand l'utilisateur fait return dans un champ de texte => on inhibe ce comportement par defaut : + _closurePanel->getApplyButton ( )->setAutoDefault (false); + _closurePanel->getApplyButton ( )->setDefault (false); + _closurePanel->getCloseButton ( )->setAutoDefault (false); + _closurePanel->getCloseButton ( )->setDefault (false); + _closurePanel->getCancelButton ( )->setAutoDefault (false); + _closurePanel->getCancelButton ( )->setDefault (false); + connect (_closurePanel->getApplyButton ( ), SIGNAL(clicked ( )), this, SLOT(apply ( ))); + connect (_closurePanel->getCloseButton ( ), SIGNAL(clicked ( )), this, SLOT(close ( ))); + connect (_closurePanel->getCancelButton ( ), SIGNAL(clicked ( )), this, SLOT(reject ( ))); + + layout->activate ( ); + setMinimumSize (layout->sizeHint ( )); + LEM_CENTER_DIALOG (this, parent) +} // QtVtkViewDefinitionDialog::QtVtkViewDefinitionDialog + + +QtVtkViewDefinitionDialog::QtVtkViewDefinitionDialog (const QtVtkViewDefinitionDialog&) +{ + assert (0 && "QtVtkViewDefinitionDialog copy constructor is forbidden."); +} // QtVtkViewDefinitionDialog::QtVtkViewDefinitionDialog (const QtVtkViewDefinitionDialog&) + + +QtVtkViewDefinitionDialog& QtVtkViewDefinitionDialog::operator = (const QtVtkViewDefinitionDialog&) +{ + assert (0 && "QtVtkViewDefinitionDialog assignment operator is forbidden."); + return *this; +} // QtVtkViewDefinitionDialog::operator = + + +QtVtkViewDefinitionDialog::~QtVtkViewDefinitionDialog ( ) +{ +} // QtVtkViewDefinitionDialog::~QtVtkViewDefinitionDialog + + +UTF8String QtVtkViewDefinitionDialog::getName ( ) const +{ + assert ((0 != _viewDefinitionPanel) && "QtVtkViewDefinitionDialog::getName : null view definition panel."); + return _viewDefinitionPanel->getName ( ); +} // QtVtkViewDefinitionDialog::getName + + +UTF8String QtVtkViewDefinitionDialog::getComment ( ) const +{ + assert ((0 != _viewDefinitionPanel) && "QtVtkViewDefinitionDialog::getComment : null view definition panel."); + return _viewDefinitionPanel->getComment ( ); +} // QtVtkViewDefinitionDialog::getComment + + +void QtVtkViewDefinitionDialog::getPosition (double coords [3]) const +{ + assert ((0 != _viewDefinitionPanel) && "QtVtkViewDefinitionDialog::getPosition : null view definition panel."); + _viewDefinitionPanel->getPosition (coords); +} // QtVtkViewDefinitionDialog::getPosition + + +void QtVtkViewDefinitionDialog::getFocalPoint (double coords [3]) const +{ + assert ((0 != _viewDefinitionPanel) && "QtVtkViewDefinitionDialog::getFocalPoint : null view definition panel."); + _viewDefinitionPanel->getFocalPoint (coords); +} // QtVtkViewDefinitionDialog::getFocalPoint + + +void QtVtkViewDefinitionDialog::getViewUp (double direction [3]) const +{ + assert ((0 != _viewDefinitionPanel) && "QtVtkViewDefinitionDialog::getViewUp : null view definition panel."); + _viewDefinitionPanel->getViewUp (direction); +} // QtVtkViewDefinitionDialog::getViewUp + + +double QtVtkViewDefinitionDialog::getRoll ( ) const +{ + assert ((0 != _viewDefinitionPanel) && "QtVtkViewDefinitionDialog::getRoll : null view definition panel."); + return _viewDefinitionPanel->getRoll ( ); +} // QtVtkViewDefinitionDialog::getRoll + + +QPushButton* QtVtkViewDefinitionDialog::getApplyButton ( ) const +{ + assert ((0 != _closurePanel) && "QtVtkViewDefinitionDialog::getApplyButton : null closure panel."); + return _closurePanel->getApplyButton ( ); +} // QtVtkViewDefinitionDialog::getApplyButton + + +QPushButton* QtVtkViewDefinitionDialog::getCancelButton ( ) const +{ + assert ((0 != _closurePanel) && "QtVtkViewDefinitionDialog::getCancelButton : null closure panel."); + return _closurePanel->getCancelButton ( ); +} // QtVtkViewDefinitionDialog::getCancelButton + + +void QtVtkViewDefinitionDialog::apply ( ) +{ + assert ((0 != _viewDefinitionPanel) && "QtVtkViewDefinitionDialog::apply : null view definition panel."); + _viewDefinitionPanel->apply ( ); +} // QtVtkViewDefinitionDialog::apply + + +void QtVtkViewDefinitionDialog::close ( ) +{ + QDialog::accept ( ); + emit applied (this); +} // QtVtkViewDefinitionDialog::close + + +void QtVtkViewDefinitionDialog::reject ( ) +{ + assert ((0 != _viewDefinitionPanel) && "QtVtkViewDefinitionDialog::reject : null view definition panel."); + _viewDefinitionPanel->reset ( ); + QDialog::reject ( ); + emit canceled (this); +} // QtVtkViewDefinitionDialog::reject + + diff --git a/src/QtVtk/QtVtkViewDefinitionPanel.cpp b/src/QtVtk/QtVtkViewDefinitionPanel.cpp new file mode 100644 index 0000000..bec84f1 --- /dev/null +++ b/src/QtVtk/QtVtkViewDefinitionPanel.cpp @@ -0,0 +1,356 @@ +#include "QtVtk/QtVtkViewDefinitionPanel.h" + +#include +#include +#include +#include +#include + +#include +#include // FLT_MAX +#include // FLT_MAX sous Linux ... + +#include +#include +#include +#include +#include + +#include +#include + + +USING_STD +USING_UTIL + +static const Charset charset ("àéèùô"); +USE_ENCODING_AUTODETECTION + + +// =========================================================================== +// QtVtkViewDefinitionPanel +// =========================================================================== + + + +QtVtkViewDefinitionPanel::QtVtkViewDefinitionPanel (QWidget* parent, const string& appTitle, const UTF8String& name, const UTF8String& comment, + double position [3], double focal [3], double viewUp [3],double roll, vtkRenderer* renderer) + : QWidget (parent), _appTitle (appTitle), _positionPanel (0), _focalPanel (0), _rollTextField (0), _renderer (renderer), _modified (false), _updated (true) +{ + for (int i = 0; i < 3; i++) + { + _initialPosition [i] = _position [i] = position [i]; + _initialFocal [i] = _focal [i] = focal [i]; + _initialViewUp [i] = _viewUp [i] = viewUp [i]; + } // for (int i = 0; i < 3; i++) + _initialRoll = _roll = roll; + + // Creation de l'ihm : + QVBoxLayout* layout = new QVBoxLayout (this); + layout->setSpacing (QtConfiguration::spacing); + layout->setMargin (QtConfiguration::margin); + layout->setSizeConstraint (QLayout::SetMinimumSize); + + // Nom / Commentaire : + QtGroupBox* nameGroupBox = new QtGroupBox ("", this); + QGridLayout* nameLayout = new QGridLayout (nameGroupBox); + nameGroupBox->setLayout (nameLayout); + nameGroupBox->setSpacing (QtConfiguration::spacing); + nameGroupBox->setMargin (QtConfiguration::margin); + nameLayout->setSizeConstraint (QLayout::SetMinimumSize); + QLabel* label = new QLabel ("Nom :", nameGroupBox); + nameLayout->addWidget (label, 0, 0); + _nameTextField = new QtTextField (nameGroupBox); + _nameTextField->setText (UTF8TOQSTRING (name)); + connect (_nameTextField, SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_nameTextField, SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + nameLayout->addWidget (_nameTextField, 0, 1); + label = new QLabel ("Commentaire :", nameGroupBox); + nameLayout->addWidget (label, 1, 0); + _commentTextField = new QtTextField (nameGroupBox); + _commentTextField->setText (UTF8TOQSTRING (comment)); + connect (_commentTextField, SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_commentTextField, SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + nameLayout->addWidget (_commentTextField, 1, 1); + nameGroupBox->adjustSize ( ); + layout->addWidget (nameGroupBox); + + // Position : + _positionPanel = new Qt3DDataPanel (this, "Position", true, "x : ", "y : ", "z : ", position [0], -DBL_MAX, DBL_MAX, position [1], -DBL_MAX, DBL_MAX, position [2], -DBL_MAX, DBL_MAX, false); + connect (_positionPanel->getXTextField ( ), SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_positionPanel->getYTextField ( ), SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_positionPanel->getZTextField ( ), SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_positionPanel->getXTextField ( ), SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + connect (_positionPanel->getYTextField ( ), SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + connect (_positionPanel->getZTextField ( ), SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + layout->addWidget (_positionPanel); + + // Focale : + _focalPanel = new Qt3DDataPanel (this, "Focale", true, "x : ", "y : ", "z : ", focal [0], -DBL_MAX, DBL_MAX, focal [1], -DBL_MAX, DBL_MAX, focal [2], -DBL_MAX, DBL_MAX, false); + connect (_focalPanel->getXTextField ( ), SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_focalPanel->getYTextField ( ), SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_focalPanel->getZTextField ( ), SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_focalPanel->getXTextField ( ), SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + connect (_focalPanel->getYTextField ( ), SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + connect (_focalPanel->getZTextField ( ), SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + layout->addWidget (_focalPanel); + + // Haut : + _viewUpPanel = new Qt3DDataPanel (this, "Direction vers le haut", true, "dx : ", "dy : ", "dz : ", viewUp [0], -DBL_MAX, DBL_MAX, viewUp [1], -DBL_MAX, DBL_MAX, viewUp [2], -DBL_MAX, DBL_MAX, false); + connect (_viewUpPanel->getXTextField ( ), SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_viewUpPanel->getYTextField ( ), SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_viewUpPanel->getZTextField ( ), SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_viewUpPanel->getXTextField ( ), SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + connect (_viewUpPanel->getYTextField ( ), SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + connect (_viewUpPanel->getZTextField ( ), SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + layout->addWidget (_viewUpPanel); + + // Roulis : + QtGroupBox* rollGroupBox = new QtGroupBox ("Roulis", this); + QHBoxLayout* rollLayout = new QHBoxLayout (rollGroupBox); + rollGroupBox->setLayout (rollLayout); + rollGroupBox->setSpacing (QtConfiguration::spacing); + rollGroupBox->setMargin (QtConfiguration::margin); + rollLayout->setSizeConstraint (QLayout::SetMinimumSize); + label = new QLabel ("Angle :", rollGroupBox); + label->setFixedSize (label->sizeHint ( )); + rollLayout->addWidget (label); + _rollTextField = new QtTextField (rollGroupBox); + _rollTextField->setVisibleColumns (4); + _rollTextField->setMaxLength (4); + _rollTextField->setFixedSize (_rollTextField->sizeHint ( )); + _rollTextField->setMaximumSize (_rollTextField->sizeHint ( )); + _rollTextField->setText (QString::number (roll)); + _rollTextField->setValidator (new QDoubleValidator (-360., 360., 4, _rollTextField)); + connect (_rollTextField, SIGNAL (returnPressed ( )), this, SLOT (viewFieldValidatedCallback ( ))); + connect (_rollTextField, SIGNAL (textChanged (const QString&)), this, SLOT (viewFieldModifiedCallback (const QString&))); + rollLayout->addWidget (_rollTextField); + label = new QLabel (QSTR ("(Domaine : -360 à 360 degrés)"), rollGroupBox); + label->setMinimumSize (label->sizeHint ( )); + rollLayout->addWidget (label); + rollGroupBox->adjustSize ( ); + layout->addWidget (rollGroupBox); + + layout->activate ( ); + setMinimumSize (layout->sizeHint ( )); +} // QtVtkViewDefinitionPanel::QtVtkViewDefinitionPanel + + +QtVtkViewDefinitionPanel::QtVtkViewDefinitionPanel (const QtVtkViewDefinitionPanel&) +{ + assert (0 && "QtVtkViewDefinitionPanel copy constructor is forbidden."); +} // QtVtkViewDefinitionPanel::QtVtkViewDefinitionPanel (const QtVtkViewDefinitionPanel&) + + +QtVtkViewDefinitionPanel& QtVtkViewDefinitionPanel::operator = (const QtVtkViewDefinitionPanel&) +{ + assert (0 && "QtVtkViewDefinitionPanel assignment operator is forbidden."); + return *this; +} // QtVtkViewDefinitionPanel::operator = + + +QtVtkViewDefinitionPanel::~QtVtkViewDefinitionPanel ( ) +{ +} // QtVtkViewDefinitionPanel::~QtVtkViewDefinitionPanel + + +void QtVtkViewDefinitionPanel::setPosition (double coords [3]) +{ + assert ((0 != _positionPanel) && "QtVtkViewDefinitionPanel::setPosition : null position panel."); + _positionPanel->setX (coords [0]); + _positionPanel->setY (coords [1]); + _positionPanel->setZ (coords [2]); + _updated = false; +} // QtVtkViewDefinitionPanel::setPosition + + +void QtVtkViewDefinitionPanel::setFocalPoint (double coords [3]) +{ + assert ((0 != _focalPanel) && "QtVtkViewDefinitionPanel::setFocalPoint : null focal panel."); + _focalPanel->setX (coords [0]); + _focalPanel->setY (coords [1]); + _focalPanel->setZ (coords [2]); + _updated = false; +} // QtVtkViewDefinitionPanel::setFocalPoint + + +void QtVtkViewDefinitionPanel::setViewUp (double coords [3]) +{ + assert ((0 != _focalPanel) && "QtVtkViewDefinitionPanel::setViewUp : null view up panel."); + _viewUpPanel->setX (coords [0]); + _viewUpPanel->setY (coords [1]); + _viewUpPanel->setZ (coords [2]); + _updated = false; +} // QtVtkViewDefinitionPanel::setViewUp + + +void QtVtkViewDefinitionPanel::setRoll (double roll) +{ + assert ((0 != _rollTextField) && "QtVtkViewDefinitionPanel::setRoll : null roll text field."); + _rollTextField->setText (QString::number (roll)); + _updated = false; +} // QtVtkViewDefinitionPanel::setRoll + + +void QtVtkViewDefinitionPanel::updateData ( ) +{ + bool modified = false; + int i = 0; + + double param3D [3]; + getPosition (param3D); + for (i = 0; i < 3; i++) + { + if (param3D [i] != _position [i]) + { + _position [i] = param3D [i]; + modified = true; + } // if (param3D [i] != _position [i]) + } // for (i = 0; i < 3; i++) + + getFocalPoint (param3D); + for (i = 0; i < 3; i++) + { + if (param3D [i] != _focal [i]) + { + _focal [i] = param3D [i]; + modified = true; + } // if (param3D [i] != _focal [i]) + } // for (i = 0; i < 3; i++) + + getViewUp (param3D); + for (i = 0; i < 3; i++) + { + if (param3D [i] != _viewUp [i]) + { + _viewUp [i] = param3D [i]; + modified = true; + } // if (param3D [i] != _focal [i]) + } // for (i = 0; i < 3; i++) + + if (_roll != getRoll ( )) + { + _roll = getRoll ( ); + modified = true; + } // if (_roll != getRoll ( )) + + if (false == modified) + return; + + setModified (true); + setUpdated (false); +} // QtVtkViewDefinitionPanel::updateData + + +UTF8String QtVtkViewDefinitionPanel::getName ( ) const +{ + assert ((0 != _nameTextField) && "QtVtkViewDefinitionPanel::getName : null name textfield."); + return QtUnicodeHelper::qstringToUTF8String (_nameTextField->text ( )); +} // QtVtkViewDefinitionPanel::getName + + +UTF8String QtVtkViewDefinitionPanel::getComment ( ) const +{ + assert ((0 != _commentTextField) && "QtVtkViewDefinitionPanel::getComment : null comment textfield."); + return QtUnicodeHelper::qstringToUTF8String (_commentTextField->text ( )); +} // QtVtkViewDefinitionPanel::getComment + + +void QtVtkViewDefinitionPanel::getPosition (double coords [3]) const +{ + assert ((0 != _positionPanel) && "QtVtkViewDefinitionPanel::getPosition : null position panel."); + coords [0] = _positionPanel->getX ( ); + coords [1] = _positionPanel->getY ( ); + coords [2] = _positionPanel->getZ ( ); +} // QtVtkViewDefinitionPanel::getPosition + + +void QtVtkViewDefinitionPanel::getFocalPoint (double coords [3]) const +{ + assert ((0 != _focalPanel) && "QtVtkViewDefinitionPanel::getFocalPoint : null focal panel."); + coords [0] = _focalPanel->getX ( ); + coords [1] = _focalPanel->getY ( ); + coords [2] = _focalPanel->getZ ( ); +} // QtVtkViewDefinitionPanel::getFocalPoint + + +void QtVtkViewDefinitionPanel::getViewUp (double direction [3]) const +{ + assert ((0 != _viewUpPanel) && "QtVtkViewDefinitionPanel::getViewUp : null view up panel."); + direction [0] = _viewUpPanel->getX ( ); + direction [1] = _viewUpPanel->getY ( ); + direction [2] = _viewUpPanel->getZ ( ); +} // QtVtkViewDefinitionPanel::getViewUp + + +double QtVtkViewDefinitionPanel::getRoll ( ) const +{ + assert ((0 != _rollTextField) && "QtVtkViewDefinitionPanel::getRoll : null roll text field."); + bool ok = true; + return _rollTextField->text ( ).toDouble (&ok); +} // QtVtkViewDefinitionPanel::getRoll + + +void QtVtkViewDefinitionPanel::apply ( ) +{ + if (true == isUpdated ( )) + return; + QtAutoWaitingCursor waitingCursor (true); + updateData ( ); + + vtkCamera* camera = 0 == _renderer ? 0 : _renderer->GetActiveCamera ( ); + if ((0 == _renderer) || (0 == camera)) + return; + + double position [3] = { 0., 0., 0. }; + double focal [3] = { 0., 0., 0. }; + double viewUp [3] = { 0., 0., 0. }; + double roll = getRoll ( ); + getPosition (position); + getFocalPoint (focal); + getViewUp (viewUp); + camera->SetPosition (position); + camera->SetFocalPoint (focal); + camera->SetViewUp (viewUp); + camera->SetRoll (roll); + // ResetCameraClippingRange : en son absence il y a de bonnes chances + // que certains objets ne soient plus affiches bien qu'ils devraient etre + // visibles. + _renderer->ResetCameraClippingRange ( ); + if (0 != _renderer->GetRenderWindow ( )) + _renderer->GetRenderWindow ( )->Render ( ); + + setUpdated (true); +} // QtVtkViewDefinitionPanel::apply + + +void QtVtkViewDefinitionPanel::reset ( ) +{ + if (false == isModified ( )) + return; + + setPosition (_initialPosition); + setFocalPoint (_initialFocal); + setViewUp (_initialViewUp); + setRoll (_initialRoll); + apply ( ); + setModified (false); +} // QtVtkViewDefinitionPanel::reset + + +void QtVtkViewDefinitionPanel::viewFieldModifiedCallback (const QString&) +{ +// setModified (true); + setUpdated (false); +} // QtVtkViewDefinitionPanel::viewFieldModifiedCallback + + +void QtVtkViewDefinitionPanel::viewFieldValidatedCallback ( ) +{ + updateData ( ); + + if (false == isUpdated ( )) + apply ( ); +} // QtVtkViewDefinitionPanel::viewFieldModifiedCallback + + diff --git a/src/QtVtk/QtVtkViewPointToolBar.cpp b/src/QtVtk/QtVtkViewPointToolBar.cpp new file mode 100644 index 0000000..9898626 --- /dev/null +++ b/src/QtVtk/QtVtkViewPointToolBar.cpp @@ -0,0 +1,266 @@ +#include "QtVtk/QtVtkViewPointToolBar.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + + +using namespace std; +using namespace TkUtil; +using namespace Preferences; + +static const Charset charset ("àéèùô"); +USE_ENCODING_AUTODETECTION + + + + +QtVtkViewPointToolBar::QtVtkViewPointToolBar (QWidget* parent, vtkCamera& camera, vtkRenderer* renderer) + : QToolBar (parent), _viewPointButtons ( ), _nextButton (1), _camera (&camera), _renderer (renderer) +{ + _camera->Register (0); + if (0 != _renderer) + _renderer->Register (0); + + QAction* action = new QAction (QIcon(":/images/add_viewpoint.png"), "+", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (newViewPointCallback ( ))); + QToolButton* button = new QToolButton (this); + button->setText ("+"); + button->setDefaultAction (action); + addWidget (button); + action = new QAction (QIcon(":/images/remove_viewpoints.png"), "Réinitialiser", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (initializeCallback ( ))); + button = new QToolButton (this); + button->setDefaultAction (action); + addWidget (button); + action = new QAction (QIcon(":/images/export_viewpoints.png"), "Exporter ...", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (exportViewPointsCallback ( ))); + button = new QToolButton (this); + button->setDefaultAction (action); + addWidget (button); + action = new QAction (QIcon(":/images/import_viewpoints.png"), "Importer ...", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (importViewPointsCallback ( ))); + button = new QToolButton (this); + button->setDefaultAction (action); + addWidget (button); +} // QtVtkViewPointToolBar::QtVtkViewPointToolBar + + +QtVtkViewPointToolBar::QtVtkViewPointToolBar (const QtVtkViewPointToolBar& tb) + : QToolBar ( ), _camera (0), _renderer (0) +{ + assert (0 && "QtVtkViewPointToolBar copy constructor is not allowed."); +} // QtVtkViewPointToolBar::QtVtkViewPointToolBar + + +QtVtkViewPointToolBar& QtVtkViewPointToolBar::operator = (const QtVtkViewPointToolBar&) +{ + assert (0 && "QtVtkViewPointToolBar assignment operator is not allowed."); + return *this; +} // QtVtkViewPointToolBar::QtVtkViewPointToolBar + + +QtVtkViewPointToolBar::~QtVtkViewPointToolBar ( ) +{ + if (0 != _camera) + _camera->UnRegister (0); + _camera = 0; + if (0 != _renderer) + _renderer->UnRegister (0); + _renderer = 0; +} // QtVtkViewPointToolBar::~QtVtkViewPointToolBar + + +void QtVtkViewPointToolBar::addViewPoint (const QtVtkViewPointToolButton::VtkViewPoint& viewPoint) +{ + assert (0 != _camera); + UTF8String name (charset); + name << "Vue_" << _nextButton; + UTF8String icon (charset); + icon << ":/images/viewpoint_" << TkUtil::setw (2) << _nextButton << ".png"; + QtVtkViewPointToolButton* tb = new QtVtkViewPointToolButton (this, icon.utf8 ( ), viewPoint, *_camera, _renderer); + addWidget (tb); + _viewPointButtons.push_back (tb); + _nextButton++; +} // QtVtkViewPointToolBar::addViewPoint + + +void QtVtkViewPointToolBar::removeViewPoint (QtVtkViewPointToolButton& viewPointButton) +{ + for (vector::iterator ittb = _viewPointButtons.begin ( ); _viewPointButtons.end ( ) != ittb; ittb++) + { + if (&viewPointButton == *ittb) + { +// _nextButton--; // NON, tant qu'on ne supporte pas les trous dans la numérotation ! +if (2 == _nextButton) _nextButton--; // => En attendant ;) + _viewPointButtons.erase (ittb); + viewPointButton.deleteLater ( ); + return; + } // if (&viewPointButton == *ittb) + } // for (vector::iterator ittb = _viewPointButtons.begin ( ); _viewPointButtons.end ( ) != ittb; ittb++) + + UTF8String error (charset); + error << "La barre d'outils \"Points de vue\" ne contient pas le point de vue \"" << viewPointButton.getViewPoint ( ).name << "\" : impossibilité de l'enlever."; + throw Exception (error); +} // QtVtkViewPointToolBar::removeViewPoint + + +void QtVtkViewPointToolBar::newViewPointCallback ( ) +{ + assert (0 != _camera); + UTF8String name (charset); + name << "Vue_" << _nextButton; + UTF8String icon (charset); + icon << ":/images/viewpoint_" << TkUtil::setw (2) << _nextButton << ".png"; + QtVtkViewPointToolButton* tb = new QtVtkViewPointToolButton (this, icon.utf8 ( ), name.utf8 ( ), *_camera, _renderer); + addWidget (tb); + _viewPointButtons.push_back (tb); + _nextButton++; +} // QtVtkViewPointToolBar::newViewPointCallback + + +void QtVtkViewPointToolBar::initializeCallback ( ) +{ + vector buttons = _viewPointButtons; + _nextButton = 1; + _viewPointButtons.clear ( ); + for (vector::iterator ittb = buttons.begin ( ); buttons.end ( ) != ittb; ittb++) + (*ittb)->deleteLater ( ); +} // QtVtkViewPointToolBar::initializeCallback + + +void QtVtkViewPointToolBar::exportViewPointsCallback ( ) +{ + if (true == _viewPointButtons.empty ( )) + { + QtMessageBox::displayErrorMessage (this, "Exportation des points de vue", UTF8String ("Absence de point de vue à exporter.", charset)); + return; + } // if (true == _viewPointButtons.empty ( )) + + static QString lastDir (Process::getCurrentDirectory ( ).c_str ( )); + UTF8String formats (charset); + formats << "XML (*.xml);;"; + QFileDialog dialog (this, "Exporter les points de vue", lastDir, UTF8TOQSTRING (formats)); + dialog.setOption (QFileDialog::DontUseNativeDialog); + dialog.setFileMode (QFileDialog::AnyFile); + dialog.setAcceptMode (QFileDialog::AcceptSave); + + if (QDialog::Accepted == dialog.exec ( )) + { + QtAutoWaitingCursor cursor (true); + + QStringList fileList = dialog.selectedFiles ( ); + if (1 != fileList.size ( )) + throw Exception ("Erreur, la liste de fichiers d'exportation de points de vue ne contient pas qu'un fichier."); + + string fileName (QtFileDialogUtilities::completeFileName (fileList [0].toStdString ( ), dialog.selectedNameFilter ( ).toStdString ( ))); + File file (fileName); + + if (false == file.isWritable ( )) + { + cursor.hide ( ); + UTF8String message (charset); + message << "Exportation des points de vue impossible dans le fichier \n" << file.getFullFileName ( ) << " :" << "\n" + << " absence de droits en écriture."; + QtMessageBox::displayErrorMessage (this, "Exportation des points de vue", message); + return; + } // if (false == file.isWritable ( )) + + lastDir = file.getPath ( ).getFullFileName ( ).c_str ( ); + + try + { + unique_ptr
mainSection (new Section (UTF8String ("QtVtk", charset), UTF8String ("Définitions de points de vue pour applications 3D", charset))); + for (vector::const_iterator ittb = _viewPointButtons.begin ( ); _viewPointButtons.end ( ) != ittb; ittb++) + { + Section* viewPointSection = QtVtkViewPointToolButton::viewPointToSection ((*ittb)->getViewPoint ( )); + mainSection->addSection (viewPointSection); + } + XMLLoader::save (*mainSection, file.getFullFileName ( ).c_str ( )); + } + catch (const Exception& exc) + { + UTF8String message (charset); + message << "Exportation des points de vue impossible dans le fichier \n" << file.getFullFileName ( ) << " :" << "\n" << exc.getFullMessage ( ); + QtMessageBox::displayErrorMessage (this, "Exportation de points de vue", message); + } + catch (...) + { + UTF8String message (charset); + message << "Exportation des points de vue impossible dans le fichier \n" << file.getFullFileName ( ) << " :" << " erreur non documentée."; + QtMessageBox::displayErrorMessage (this, "Exportation de points de vue", message); + } + } // if (QDialog::Accepted == dialog.exec ( )) + +} // QtVtkViewPointToolBar::exportViewPointsCallback + + +void QtVtkViewPointToolBar::importViewPointsCallback ( ) +{ + static QString lastDir (Process::getCurrentDirectory ( ).c_str ( )); + UTF8String formats (charset); + formats << "XML (*.xml);;"; + QFileDialog dialog (this, "Importer des points de vue", lastDir, UTF8TOQSTRING (formats)); + dialog.setOption (QFileDialog::DontUseNativeDialog); + dialog.setFileMode (QFileDialog::ExistingFile); + dialog.setAcceptMode (QFileDialog::AcceptOpen); + + if (QDialog::Accepted == dialog.exec ( )) + { + QtAutoWaitingCursor cursor (true); + + QStringList fileList = dialog.selectedFiles ( ); + if (0 == fileList.size ( )) + throw Exception ("Erreur, la liste de fichiers importés de point de vue ne contient pas qu'un fichier."); + + string fileName (QtFileDialogUtilities::completeFileName (fileList [0].toStdString ( ), dialog.selectedNameFilter ( ).toStdString ( ))); + File file (fileName); + + if (false == file.isReadable ( )) + { + cursor.hide ( ); + UTF8String message (charset); + message << "Import de points de vue impossible depuis le fichier \n" << file.getFullFileName ( ) << " :" << "\n" + << " absence de droits en lecture."; + QtMessageBox::displayErrorMessage (this, "Import de points de vue", message); + return; + } // if (false == file.isReadable ( )) + + lastDir = file.getPath ( ).getFullFileName ( ).c_str ( ); + + try + { + unique_ptr
mainSection (new Section (UTF8String ("QtVtk", charset), UTF8String ("Définitions de points de vue pour applications 3D", charset))); + mainSection.reset (XMLLoader::load (file.getFullFileName ( ).c_str ( ))); + const vector viewPoints = mainSection->getSections ( ); + for (vector::const_iterator itvp = viewPoints.begin ( ); viewPoints.end ( ) != itvp; itvp++) + { + addViewPoint (QtVtkViewPointToolButton::sectionToViewPoint (**itvp)); + } // for (vector::const_iterator itvp = viewPoints.begin ( ); viewPoints.end ( ) != itvp; itvp++) + } + catch (const Exception& exc) + { + UTF8String message (charset); + message << "Importation de points de vue impossible depuis le fichier \n" << file.getFullFileName ( ) << " :" << "\n" << exc.getFullMessage ( ); + QtMessageBox::displayErrorMessage (this, "Importation de points de vue", message); + } + catch (...) + { + UTF8String message (charset); + message << "Importation de points de vue impossible depuis le fichier \n" << file.getFullFileName ( ) << " :" << " erreur non documentée."; + QtMessageBox::displayErrorMessage (this, "Importation de points de vue", message); + } + } // if (QDialog::Accepted == dialog.exec ( )) +} // QtVtkViewPointToolBar::importViewPointsCallback diff --git a/src/QtVtk/QtVtkViewPointToolButton.cpp b/src/QtVtk/QtVtkViewPointToolButton.cpp new file mode 100644 index 0000000..1ddd498 --- /dev/null +++ b/src/QtVtk/QtVtkViewPointToolButton.cpp @@ -0,0 +1,403 @@ +#include "QtVtk/QtVtkViewPointToolButton.h" +#include "QtVtk/QtVtkViewDefinitionDialog.h" +#include "QtVtk/QtVtkViewPointToolBar.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace TkUtil; +using namespace Preferences; +using namespace std; + +static const Charset charset ("àéèùô"); +USE_ENCODING_AUTODETECTION + + +// ====================================================================================================================================== +// LA STRUCTURE QtVtkViewPointToolButton::VtkViewPoint +// ====================================================================================================================================== + +QtVtkViewPointToolButton::VtkViewPoint::VtkViewPoint ( ) + : name ( ), comment ( ), roll (0.) +{ + memset (position, 0, 3 * sizeof (double)); + memset (focalPoint, 0, 3 * sizeof (double)); + memset (viewUp, 0, 3 * sizeof (double)); +} // VtkViewPoint::VtkViewPoint + + +QtVtkViewPointToolButton::VtkViewPoint::VtkViewPoint (const QtVtkViewPointToolButton::VtkViewPoint& vp) + : name (vp.name), comment (vp.comment), roll (vp.roll) +{ + memcpy (position, vp.position, 3 * sizeof (double)); + memcpy (focalPoint, vp.focalPoint, 3 * sizeof (double)); + memcpy (viewUp, vp.viewUp, 3 * sizeof (double)); +} // VtkViewPoint::VtkViewPoint + + +QtVtkViewPointToolButton::VtkViewPoint& QtVtkViewPointToolButton::VtkViewPoint::operator = (const QtVtkViewPointToolButton::VtkViewPoint& vp) +{ + name = vp.name; + comment = vp.comment; + roll = vp.roll; + memcpy (position, vp.position, 3 * sizeof (double)); + memcpy (focalPoint, vp.focalPoint, 3 * sizeof (double)); + memcpy (viewUp, vp.viewUp, 3 * sizeof (double)); + + return *this; +} // VtkViewPoint::operator = + + +QtVtkViewPointToolButton::VtkViewPoint& QtVtkViewPointToolButton::VtkViewPoint::operator = (const vtkCamera& camera) +{ + roll = ((vtkCamera&)camera).GetRoll ( ); + memcpy (position, ((vtkCamera&)camera).GetPosition ( ), 3 * sizeof (double)); + memcpy (focalPoint, ((vtkCamera&)camera).GetFocalPoint ( ), 3 * sizeof (double)); + memcpy (viewUp, ((vtkCamera&)camera).GetViewUp ( ), 3 * sizeof (double)); + + return *this; +} // VtkViewPoint::operator = + + +QtVtkViewPointToolButton::VtkViewPoint::~VtkViewPoint ( ) +{ +} // VtkViewPoint::~VtkViewPoint + + +// ====================================================================================================================================== +// LA CLASSE QtVtkViewPointToolButton +// ====================================================================================================================================== + +Section* QtVtkViewPointToolButton::viewPointToSection (const QtVtkViewPointToolButton::VtkViewPoint& vp) +{ + Section* section = new Section (vp.name, vp.comment); + DoubleTripletNamedValue* position = new DoubleTripletNamedValue (UTF8String ("position", charset), vp.position [0], vp.position [1], vp.position [2]); + DoubleTripletNamedValue* focalPoint = new DoubleTripletNamedValue (UTF8String ("focalPoint", charset), vp.focalPoint [0], vp.focalPoint [1], vp.focalPoint [2]); + DoubleTripletNamedValue* viewUp = new DoubleTripletNamedValue (UTF8String ("viewUp", charset), vp.viewUp [0], vp.viewUp [1], vp.viewUp [2]); + DoubleNamedValue* roll = new DoubleNamedValue (UTF8String ("roll", charset), vp.roll); + section->addNamedValue (position); + section->addNamedValue (focalPoint); + section->addNamedValue (viewUp); + section->addNamedValue (roll); + + return section; +} // QtVtkViewPointToolButton::viewPointToSection + + +QtVtkViewPointToolButton::VtkViewPoint QtVtkViewPointToolButton::sectionToViewPoint (const Section& section) +{ + QtVtkViewPointToolButton::VtkViewPoint vp; + + vp.name = section.getName ( ); + vp.comment = section.getComment ( ); + try + { + DoubleTripletNamedValue* pos = dynamic_cast(&(section.getNamedValue (UTF8String ("position", charset)))); + if (0 != pos) + { + vp.position [0] = pos->getX ( ); + vp.position [1] = pos->getY ( ); + vp.position [2] = pos->getZ ( ); + } // if (0 != pos) + } + catch (...) + { + } + + try + { + DoubleTripletNamedValue* fp = dynamic_cast(&(section.getNamedValue (UTF8String ("focalPoint", charset)))); + if (0 != fp) + { + vp.focalPoint [0] = fp->getX ( ); + vp.focalPoint [1] = fp->getY ( ); + vp.focalPoint [2] = fp->getZ ( ); + } // if (0 != fp) + } + catch (...) + { + } + + try + { + DoubleTripletNamedValue* vu = dynamic_cast(&(section.getNamedValue (UTF8String ("viewUp", charset)))); + if (0 != vu) + { + vp.viewUp [0] = vu->getX ( ); + vp.viewUp [1] = vu->getY ( ); + vp.viewUp [2] = vu->getZ ( ); + } // if (0 != vu) + } + catch (...) + { + } + + try + { + DoubleNamedValue* r = dynamic_cast(&(section.getNamedValue (UTF8String ("roll", charset)))); + if (0 != r) + vp.roll = r->getValue ( ); + } + catch (...) + { + } + + return vp; +} // QtVtkViewPointToolButton::sectionToViewPoint + + +QtVtkViewPointToolButton::QtVtkViewPointToolButton (QWidget* parent, const std::string& icon, const TkUtil::UTF8String& name, vtkCamera& camera, vtkRenderer* renderer) + : QToolButton (parent), _viewPoint ( ), _camera (&camera), _renderer (renderer) +{ + setText (UTF8TOQSTRING (name)); + setIcon (QIcon (icon.c_str ( ))); + _viewPoint.name = name; + _viewPoint = *_camera; + setToolButtonStyle (Qt::ToolButtonIconOnly); + setPopupMode (QToolButton::MenuButtonPopup); + _camera->Register (0); + if (0 != _renderer) + _renderer->Register (0); + + QMenu* menu = new QMenu (this); + QAction* action = new QAction ("Appliquer", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (applyViewPointCallback ( ))); + menu->addAction (action); + action = new QAction ("Modifier ...", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (editViewPointCallback ( ))); + menu->addAction (action); + action = new QAction ("Supprimer ...", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (removeViewPointCallback ( ))); + menu->addAction (action); + action = new QAction ("Exporter ...", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (exportViewPointCallback ( ))); + menu->addAction (action); + setMenu (menu); +} // QtVtkViewPointToolButton::QtVtkViewPointToolButton + + +QtVtkViewPointToolButton::QtVtkViewPointToolButton (QWidget* parent, const string& icon, const QtVtkViewPointToolButton::VtkViewPoint& viewPoint, vtkCamera& camera, vtkRenderer* renderer) + : QToolButton (parent), _viewPoint (viewPoint), _camera (&camera), _renderer (renderer) +{ + setText (UTF8TOQSTRING (_viewPoint.name)); + setToolTip (UTF8TOQSTRING (_viewPoint.comment)); + setIcon (QIcon (icon.c_str ( ))); + setToolButtonStyle (Qt::ToolButtonIconOnly); + setPopupMode (QToolButton::MenuButtonPopup); + _camera->Register (0); + if (0 != _renderer) + _renderer->Register (0); + + QMenu* menu = new QMenu (this); + QAction* action = new QAction ("Appliquer", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (applyViewPointCallback ( ))); + menu->addAction (action); + action = new QAction ("Modifier ...", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (editViewPointCallback ( ))); + menu->addAction (action); + action = new QAction ("Supprimer ...", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (removeViewPointCallback ( ))); + menu->addAction (action); + action = new QAction ("Exporter ...", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (exportViewPointCallback ( ))); + menu->addAction (action); + setMenu (menu); +} // QtVtkViewPointToolButton::QtVtkViewPointToolButton + + +QtVtkViewPointToolButton::QtVtkViewPointToolButton (const QtVtkViewPointToolButton& tb) + : QToolButton ( ), _viewPoint ( ), _camera (0), _renderer (0) +{ + assert (0 && "QtVtkViewPointToolButton copy constructor is not allowed."); +} // QtVtkViewPointToolButton::QtVtkViewPointToolButton + + +QtVtkViewPointToolButton& QtVtkViewPointToolButton::operator = (const QtVtkViewPointToolButton&) +{ + assert (0 && "QtVtkViewPointToolButton assignment operator is not allowed."); + return *this; +} // QtVtkViewPointToolButton::QtVtkViewPointToolButton + + +QtVtkViewPointToolButton::~QtVtkViewPointToolButton ( ) +{ + if (0 != _camera) + _camera->UnRegister (0); + _camera = 0; + if (0 != _renderer) + _renderer->UnRegister (0); + _renderer = 0; +} // QtVtkViewPointToolButton::~QtVtkViewPointToolButton + + +const QtVtkViewPointToolButton::VtkViewPoint& QtVtkViewPointToolButton::getViewPoint ( ) const +{ + return _viewPoint; +} // QtVtkViewPointToolButton::getViewPoint + + +void QtVtkViewPointToolButton::setViewPoint (const QtVtkViewPointToolButton::VtkViewPoint& vp) +{ + _viewPoint = vp; + setText (UTF8TOQSTRING (_viewPoint.name)); + setToolTip (UTF8TOQSTRING (_viewPoint.comment)); + applyViewPointCallback ( ); +} // QtVtkViewPointToolButton::setViewPoint + + +void QtVtkViewPointToolButton::applyViewPointCallback ( ) +{ + assert (0 != _camera && "QtVtkViewPointToolButton::applyViewPointCallback : null camera"); + _camera->SetPosition (_viewPoint.position); + _camera->SetFocalPoint (_viewPoint.focalPoint); + _camera->SetViewUp (_viewPoint.viewUp); + _camera->SetRoll (_viewPoint.roll); + + if (0 != _renderer) + { + _renderer->ResetCameraClippingRange ( ); + if (0 != _renderer->GetRenderWindow ( )) + _renderer->GetRenderWindow ( )->Render ( ); + } // if (0 != _renderer) +} // QtVtkViewPointToolButton::applyViewPointCallback + + +void QtVtkViewPointToolButton::editViewPointCallback ( ) +{ + assert (0 != _camera && "QtVtkViewPointToolButton::editViewPointCallback : null camera"); + + try + { + UTF8String dlgTitle (charset); + dlgTitle << "Paramètres de définition de la vue."; + + QtVtkViewPointToolButton::VtkViewPoint vp = getViewPoint ( ); + QtVtkViewDefinitionDialog viewDialog (this, dlgTitle.utf8 ( ).c_str ( ), true, vp.name, vp.comment, vp.position, vp.focalPoint, vp.viewUp, vp.roll, _renderer); + int retVal = viewDialog.exec ( ); + + if (0 == retVal) + { + applyViewPointCallback ( ); // Annule d'éventuelles modifications effectuées par la boite de dialogue. + return; + } + + vp.name = viewDialog.getName ( ); + vp.comment = viewDialog.getComment ( ); + viewDialog.getPosition (vp.position); + viewDialog.getFocalPoint (vp.focalPoint); + viewDialog.getViewUp (vp.viewUp); + vp.roll = viewDialog.getRoll ( ); + + UTF8String message (charset); + message << "Paramètres de la vues modifiés. " + << "Position de la caméra : " + << vp.position [0] << ", " << vp.position [1] << ", " << vp.position [2] + << ". Position de la focale : " + << vp.focalPoint [0] << ", " << vp.focalPoint [1] << ", " << vp.focalPoint [2] + << ". Direction vers le haut : " + << vp.viewUp [0] << ", " << vp.viewUp [1] << ", " << vp.viewUp [2] + << " Roulis : " << vp.roll << " degrés."; + cout << message << endl; + setViewPoint (vp); + } + catch (const Exception& exc) + { + UTF8String message (charset); + message << "Modification du point de vue impossible :" << "\n" << exc.getFullMessage ( ); + QtMessageBox::displayErrorMessage (this, "Modification de point de vue", message); + } + catch (...) + { + UTF8String message (charset); + message << "Modification du point de vue impossible : erreur non renseignée."; + QtMessageBox::displayErrorMessage (this, "Modification de point de vue", message); + } +} // QtVtkViewPointToolButton::editViewPointCallback + + +void QtVtkViewPointToolButton::removeViewPointCallback ( ) +{ + try + { + QtVtkViewPointToolBar* toolbar = dynamic_cast(parentWidget ( )); + if (0 != toolbar) + toolbar->removeViewPoint (*this); + else + deleteLater ( ); + } + catch (...) + { + } +} // QtVtkViewPointToolButton::removeViewPointCallback + + +void QtVtkViewPointToolButton::exportViewPointCallback ( ) +{ + static QString lastDir (Process::getCurrentDirectory ( ).c_str ( )); + UTF8String formats (charset); + formats << "XML (*.xml);;"; + QFileDialog dialog (this, "Exporter le point de vue", lastDir, UTF8TOQSTRING (formats)); + dialog.setOption (QFileDialog::DontUseNativeDialog); + dialog.setFileMode (QFileDialog::AnyFile); + dialog.setAcceptMode (QFileDialog::AcceptSave); + + if (QDialog::Accepted == dialog.exec ( )) + { + QtAutoWaitingCursor cursor (true); + + QStringList fileList = dialog.selectedFiles ( ); + if (1 != fileList.size ( )) + throw Exception ("Erreur, la liste de fichiers d'export de point de vue ne contient pas qu'un fichier."); + + string fileName (QtFileDialogUtilities::completeFileName (fileList [0].toStdString ( ), dialog.selectedNameFilter ( ).toStdString ( ))); + File file (fileName); + + if (false == file.isWritable ( )) + { + cursor.hide ( ); + UTF8String message (charset); + message << "Exportation du point de vue impossible dans le fichier \n" << file.getFullFileName ( ) << " :" << "\n" + << " absence de droits en écriture."; + QtMessageBox::displayErrorMessage (this, "Export de point de vue", message); + return; + } // if (false == file.isWritable ( )) + + lastDir = file.getPath ( ).getFullFileName ( ).c_str ( ); + + try + { + unique_ptr
mainSection (new Section (UTF8String ("QtVtk", charset), UTF8String ("Définitions de points de vue pour applications 3D", charset))); + Section* viewPointSection = QtVtkViewPointToolButton::viewPointToSection (getViewPoint ( )); + mainSection->addSection (viewPointSection); + XMLLoader::save (*mainSection, file.getFullFileName ( ).c_str ( )); + } + catch (const Exception& exc) + { + UTF8String message (charset); + message << "Exportation du point de vue impossible dans le fichier \n" << file.getFullFileName ( ) << " :" << "\n" << exc.getFullMessage ( ); + QtMessageBox::displayErrorMessage (this, "Exportation de point de vue", message); + } + catch (...) + { + UTF8String message (charset); + message << "Exportation du point de vue impossible dans le fichier \n" << file.getFullFileName ( ) << " :" << " erreur non documentée."; + QtMessageBox::displayErrorMessage (this, "Exportation de point de vue", message); + } + } // if (QDialog::Accepted == dialog.exec ( )) +} // QtVtkViewPointToolButton::exportViewPointCallback + + diff --git a/src/QtVtk/cmake/QtVtkConfig.cmake.in b/src/QtVtk/cmake/QtVtkConfig.cmake.in index 2c4dc79..473817e 100644 --- a/src/QtVtk/cmake/QtVtkConfig.cmake.in +++ b/src/QtVtk/cmake/QtVtkConfig.cmake.in @@ -1,6 +1,6 @@ include(CMakeFindDependencyMacro) find_dependency (VtkContrib) -find_dependency (QtUtil) +find_dependency (PrefsQt) @PACKAGE_INIT@ diff --git a/src/QtVtk/images/.viewpoint_15svg.svg b/src/QtVtk/images/.viewpoint_15svg.svg new file mode 100644 index 0000000..77a2970 --- /dev/null +++ b/src/QtVtk/images/.viewpoint_15svg.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 15 + + diff --git a/src/QtVtk/images/add_viewpoint.png b/src/QtVtk/images/add_viewpoint.png new file mode 100644 index 0000000..8818ba8 Binary files /dev/null and b/src/QtVtk/images/add_viewpoint.png differ diff --git a/src/QtVtk/images/add_viewpoint.svg b/src/QtVtk/images/add_viewpoint.svg new file mode 100644 index 0000000..46ede54 --- /dev/null +++ b/src/QtVtk/images/add_viewpoint.svg @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/QtVtk/images/export_viewpoints.png b/src/QtVtk/images/export_viewpoints.png new file mode 100644 index 0000000..7d2f07d Binary files /dev/null and b/src/QtVtk/images/export_viewpoints.png differ diff --git a/src/QtVtk/images/import_viewpoints.png b/src/QtVtk/images/import_viewpoints.png new file mode 100644 index 0000000..55bffa8 Binary files /dev/null and b/src/QtVtk/images/import_viewpoints.png differ diff --git a/src/QtVtk/images/remove_viewpoint.png b/src/QtVtk/images/remove_viewpoint.png new file mode 100644 index 0000000..0bd7b07 Binary files /dev/null and b/src/QtVtk/images/remove_viewpoint.png differ diff --git a/src/QtVtk/images/remove_viewpoint.svg b/src/QtVtk/images/remove_viewpoint.svg new file mode 100644 index 0000000..acd5c8c --- /dev/null +++ b/src/QtVtk/images/remove_viewpoint.svg @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/QtVtk/images/remove_viewpoints.png b/src/QtVtk/images/remove_viewpoints.png new file mode 100644 index 0000000..5647296 Binary files /dev/null and b/src/QtVtk/images/remove_viewpoints.png differ diff --git a/src/QtVtk/images/remove_viewpoints.svg b/src/QtVtk/images/remove_viewpoints.svg new file mode 100644 index 0000000..bc9286a --- /dev/null +++ b/src/QtVtk/images/remove_viewpoints.svg @@ -0,0 +1,177 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/QtVtk/images/viewpoint_01.png b/src/QtVtk/images/viewpoint_01.png new file mode 100644 index 0000000..79670ad Binary files /dev/null and b/src/QtVtk/images/viewpoint_01.png differ diff --git a/src/QtVtk/images/viewpoint_01.svg b/src/QtVtk/images/viewpoint_01.svg new file mode 100644 index 0000000..e9f117f --- /dev/null +++ b/src/QtVtk/images/viewpoint_01.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 1 + + diff --git a/src/QtVtk/images/viewpoint_02.png b/src/QtVtk/images/viewpoint_02.png new file mode 100644 index 0000000..aee9824 Binary files /dev/null and b/src/QtVtk/images/viewpoint_02.png differ diff --git a/src/QtVtk/images/viewpoint_02.svg b/src/QtVtk/images/viewpoint_02.svg new file mode 100644 index 0000000..16a82c8 --- /dev/null +++ b/src/QtVtk/images/viewpoint_02.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + 2 + + diff --git a/src/QtVtk/images/viewpoint_03.png b/src/QtVtk/images/viewpoint_03.png new file mode 100644 index 0000000..7150ed7 Binary files /dev/null and b/src/QtVtk/images/viewpoint_03.png differ diff --git a/src/QtVtk/images/viewpoint_03.svg b/src/QtVtk/images/viewpoint_03.svg new file mode 100644 index 0000000..4c8eb70 --- /dev/null +++ b/src/QtVtk/images/viewpoint_03.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + 3 + + diff --git a/src/QtVtk/images/viewpoint_04.png b/src/QtVtk/images/viewpoint_04.png new file mode 100644 index 0000000..ec35b43 Binary files /dev/null and b/src/QtVtk/images/viewpoint_04.png differ diff --git a/src/QtVtk/images/viewpoint_04.svg b/src/QtVtk/images/viewpoint_04.svg new file mode 100644 index 0000000..1f5ee6e --- /dev/null +++ b/src/QtVtk/images/viewpoint_04.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + 4 + + diff --git a/src/QtVtk/images/viewpoint_05.png b/src/QtVtk/images/viewpoint_05.png new file mode 100644 index 0000000..d7ad90c Binary files /dev/null and b/src/QtVtk/images/viewpoint_05.png differ diff --git a/src/QtVtk/images/viewpoint_05.svg b/src/QtVtk/images/viewpoint_05.svg new file mode 100644 index 0000000..e9d5849 --- /dev/null +++ b/src/QtVtk/images/viewpoint_05.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + 5 + + diff --git a/src/QtVtk/images/viewpoint_06.png b/src/QtVtk/images/viewpoint_06.png new file mode 100644 index 0000000..8ac38f1 Binary files /dev/null and b/src/QtVtk/images/viewpoint_06.png differ diff --git a/src/QtVtk/images/viewpoint_06.svg b/src/QtVtk/images/viewpoint_06.svg new file mode 100644 index 0000000..2532952 --- /dev/null +++ b/src/QtVtk/images/viewpoint_06.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + 6 + + diff --git a/src/QtVtk/images/viewpoint_07.png b/src/QtVtk/images/viewpoint_07.png new file mode 100644 index 0000000..aca24d7 Binary files /dev/null and b/src/QtVtk/images/viewpoint_07.png differ diff --git a/src/QtVtk/images/viewpoint_07.svg b/src/QtVtk/images/viewpoint_07.svg new file mode 100644 index 0000000..29aaef2 --- /dev/null +++ b/src/QtVtk/images/viewpoint_07.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + 7 + + diff --git a/src/QtVtk/images/viewpoint_08.png b/src/QtVtk/images/viewpoint_08.png new file mode 100644 index 0000000..3327ddf Binary files /dev/null and b/src/QtVtk/images/viewpoint_08.png differ diff --git a/src/QtVtk/images/viewpoint_08.svg b/src/QtVtk/images/viewpoint_08.svg new file mode 100644 index 0000000..d0d1f63 --- /dev/null +++ b/src/QtVtk/images/viewpoint_08.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + 8 + + diff --git a/src/QtVtk/images/viewpoint_09.png b/src/QtVtk/images/viewpoint_09.png new file mode 100644 index 0000000..0c96001 Binary files /dev/null and b/src/QtVtk/images/viewpoint_09.png differ diff --git a/src/QtVtk/images/viewpoint_09.svg b/src/QtVtk/images/viewpoint_09.svg new file mode 100644 index 0000000..56eb9ca --- /dev/null +++ b/src/QtVtk/images/viewpoint_09.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + 9 + + diff --git a/src/QtVtk/images/viewpoint_10.png b/src/QtVtk/images/viewpoint_10.png new file mode 100644 index 0000000..b43eef6 Binary files /dev/null and b/src/QtVtk/images/viewpoint_10.png differ diff --git a/src/QtVtk/images/viewpoint_10.svg b/src/QtVtk/images/viewpoint_10.svg new file mode 100644 index 0000000..58e99f6 --- /dev/null +++ b/src/QtVtk/images/viewpoint_10.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 10 + + diff --git a/src/QtVtk/images/viewpoint_11.png b/src/QtVtk/images/viewpoint_11.png new file mode 100644 index 0000000..dfbedc7 Binary files /dev/null and b/src/QtVtk/images/viewpoint_11.png differ diff --git a/src/QtVtk/images/viewpoint_11.svg b/src/QtVtk/images/viewpoint_11.svg new file mode 100644 index 0000000..b0d61fd --- /dev/null +++ b/src/QtVtk/images/viewpoint_11.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 11 + + diff --git a/src/QtVtk/images/viewpoint_12.png b/src/QtVtk/images/viewpoint_12.png new file mode 100644 index 0000000..c4f8814 Binary files /dev/null and b/src/QtVtk/images/viewpoint_12.png differ diff --git a/src/QtVtk/images/viewpoint_12.svg b/src/QtVtk/images/viewpoint_12.svg new file mode 100644 index 0000000..d73352e --- /dev/null +++ b/src/QtVtk/images/viewpoint_12.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 12 + + diff --git a/src/QtVtk/images/viewpoint_13.png b/src/QtVtk/images/viewpoint_13.png new file mode 100644 index 0000000..439b150 Binary files /dev/null and b/src/QtVtk/images/viewpoint_13.png differ diff --git a/src/QtVtk/images/viewpoint_13.svg b/src/QtVtk/images/viewpoint_13.svg new file mode 100644 index 0000000..b497233 --- /dev/null +++ b/src/QtVtk/images/viewpoint_13.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 13 + + diff --git a/src/QtVtk/images/viewpoint_14.png b/src/QtVtk/images/viewpoint_14.png new file mode 100644 index 0000000..2b3a419 Binary files /dev/null and b/src/QtVtk/images/viewpoint_14.png differ diff --git a/src/QtVtk/images/viewpoint_14.svg b/src/QtVtk/images/viewpoint_14.svg new file mode 100644 index 0000000..2585a5b --- /dev/null +++ b/src/QtVtk/images/viewpoint_14.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 14 + + diff --git a/src/QtVtk/images/viewpoint_15.png b/src/QtVtk/images/viewpoint_15.png new file mode 100644 index 0000000..1710c19 Binary files /dev/null and b/src/QtVtk/images/viewpoint_15.png differ diff --git a/src/QtVtk/images/viewpoint_15.svg b/src/QtVtk/images/viewpoint_15.svg new file mode 100644 index 0000000..2dc5ebd --- /dev/null +++ b/src/QtVtk/images/viewpoint_15.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 15 + + diff --git a/src/QtVtk/images/viewpoint_16.png b/src/QtVtk/images/viewpoint_16.png new file mode 100644 index 0000000..0151762 Binary files /dev/null and b/src/QtVtk/images/viewpoint_16.png differ diff --git a/src/QtVtk/images/viewpoint_16.svg b/src/QtVtk/images/viewpoint_16.svg new file mode 100644 index 0000000..f17f29b --- /dev/null +++ b/src/QtVtk/images/viewpoint_16.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 16 + + diff --git a/src/QtVtk/images/viewpoint_17.png b/src/QtVtk/images/viewpoint_17.png new file mode 100644 index 0000000..aa0615a Binary files /dev/null and b/src/QtVtk/images/viewpoint_17.png differ diff --git a/src/QtVtk/images/viewpoint_17.svg b/src/QtVtk/images/viewpoint_17.svg new file mode 100644 index 0000000..b3a9613 --- /dev/null +++ b/src/QtVtk/images/viewpoint_17.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 17 + + diff --git a/src/QtVtk/images/viewpoint_18.png b/src/QtVtk/images/viewpoint_18.png new file mode 100644 index 0000000..a7e6b1d Binary files /dev/null and b/src/QtVtk/images/viewpoint_18.png differ diff --git a/src/QtVtk/images/viewpoint_18.svg b/src/QtVtk/images/viewpoint_18.svg new file mode 100644 index 0000000..7b21e15 --- /dev/null +++ b/src/QtVtk/images/viewpoint_18.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 18 + + diff --git a/src/QtVtk/images/viewpoint_19.png b/src/QtVtk/images/viewpoint_19.png new file mode 100644 index 0000000..ece789e Binary files /dev/null and b/src/QtVtk/images/viewpoint_19.png differ diff --git a/src/QtVtk/images/viewpoint_19.svg b/src/QtVtk/images/viewpoint_19.svg new file mode 100644 index 0000000..0cacfef --- /dev/null +++ b/src/QtVtk/images/viewpoint_19.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 19 + + diff --git a/src/QtVtk/images/viewpoint_20.png b/src/QtVtk/images/viewpoint_20.png new file mode 100644 index 0000000..5448bae Binary files /dev/null and b/src/QtVtk/images/viewpoint_20.png differ diff --git a/src/QtVtk/images/viewpoint_20.svg b/src/QtVtk/images/viewpoint_20.svg new file mode 100644 index 0000000..cc5a34d --- /dev/null +++ b/src/QtVtk/images/viewpoint_20.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + 20 + + diff --git a/src/QtVtk/public/QtVtk/QtVtkViewDefinitionDialog.h b/src/QtVtk/public/QtVtk/QtVtkViewDefinitionDialog.h new file mode 100644 index 0000000..69ff397 --- /dev/null +++ b/src/QtVtk/public/QtVtk/QtVtkViewDefinitionDialog.h @@ -0,0 +1,121 @@ +#ifndef QT_VTK_VIEW_DEFINITION_DIALOG_H +#define QT_VTK_VIEW_DEFINITION_DIALOG_H + +#include "QtVtk/QtVtkViewDefinitionPanel.h" +#include + +#include + +#include + + +/** + * Boite de dialogue Qt permettant la saisie des paramètres de définition d'un point de vue. + * Cette boite de dialogue peut piloter, optionnellement, une caméra VTK. La caméra est mise à jour avec les derniers paramètres saisis lorsque + * l'utilisateur effectue un retour chariot dans un champ numérique. + */ +class QtVtkViewDefinitionDialog : public QDialog +{ + Q_OBJECT + + public : + + /** Constructeur. + * @param widget parent. Ne doit pas être nul. + * @param titre de la boite de dialogue. + * @param caractère modal de la boite de dialogue. + * @param Eventuel nom du point de vue + * @param Eventuel commentaire associé au point de vue + * @param position initiale (x, y, z) de la caméra. + * @param focale initiale (x, y, z) de la caméra. + * @param direction vers le haut de la caméra + * @param roulis (angle de la caméra par rapport à sa direction (axe position-focale)). En degrés. + * @param Renderer utilisant la caméra à piloter si non nul (GetActiveCamera sur le renderer est utilisé). + * @param URL de l'aide + * @param Balise de l'aide + */ + QtVtkViewDefinitionDialog (QWidget* parent, const IN_STD string& title, bool modal, const TkUtil::UTF8String& name, const TkUtil::UTF8String& comment, + double position [3], double focal [3], double viewUp [3], double roll, vtkRenderer* renderer, + const IN_STD string& helpURL ="", const IN_STD string& helpTag = ""); + + /** Destructeur. */ + virtual ~QtVtkViewDefinitionDialog ( ); + + /** @return l'éventuel nom du point de vue. */ + virtual TkUtil::UTF8String getName ( ) const; + + /** @return l'éventuel commentaire associé au point de vue. */ + virtual TkUtil::UTF8String getComment ( ) const; + + /** @param les coordonnées de la caméra, en retour. */ + virtual void getPosition (double coords [3]) const; + + /** @param la position de la focale la caméra, en retour. */ + virtual void getFocalPoint (double coords [3]) const; + + /** @param la direction vers le haut de la caméra, en retour. */ + virtual void getViewUp (double direction [3]) const; + + /** @return le roulis de la caméra. */ + virtual double getRoll ( ) const; + + /** @return le bouton "Appliquer" de la boite de dialogue. */ + virtual QPushButton* getApplyButton ( ) const; + + /** @return le bouton "Annuler" de la boite de dialogue. */ + virtual QPushButton* getCancelButton ( ) const; + + + public slots : + + /** Appelé quand l'utilisateur appuie sur le bouton "Appliquer". + */ + virtual void apply ( ); + + /** Appelé quand l'utilisateur appuie sur le bouton "Fermer". + * Invoque Dialog::accept. + * Envoie le signal "applied" avec en argument cette instance. + */ + virtual void close ( ); + + /** Appelé quand l'utilisateur appuie sur le bouton "Annuler". + * Invoque Dialog::reject. + * Envoie le signal "canceled" avec en argument cette instance. + */ + virtual void reject ( ); + + + signals : + + /** Envoyé lorsque le bouton "Appliquer" est cliqué. + * @param l'instance siège de l'évènement. + */ + void applied (QtVtkViewDefinitionDialog* dialog); + + /** Envoyé lorsque le bouton "Annuler" est cliqué. + * @param l'instance siège de l'évènement. + */ + void canceled (QtVtkViewDefinitionDialog* dialog); + + + protected : + + + private : + + /** Constructeur de copie. Interdit. */ + QtVtkViewDefinitionDialog (const QtVtkViewDefinitionDialog&); + + /** Opérateur de copie. Interdit. */ + QtVtkViewDefinitionDialog& operator = (const QtVtkViewDefinitionDialog&); + + /** Le panneau de paramétrage de l'opération d'extraction. */ + QtVtkViewDefinitionPanel* _viewDefinitionPanel; + + /** Le panneau proposant "Appliquer" et "Annuler". */ + QtDlgClosurePanel* _closurePanel; +}; // class QtVtkViewDefinitionDialog + + + +#endif // QT_VTK_VIEW_DEFINITION_DIALOG_H diff --git a/src/QtVtk/public/QtVtk/QtVtkViewDefinitionPanel.h b/src/QtVtk/public/QtVtk/QtVtkViewDefinitionPanel.h new file mode 100644 index 0000000..673d9ca --- /dev/null +++ b/src/QtVtk/public/QtVtk/QtVtkViewDefinitionPanel.h @@ -0,0 +1,199 @@ +#ifndef QT_VTK_VIEW_DEFINITION_PANEL_H +#define QT_VTK_VIEW_DEFINITION_PANEL_H + +#include +#include +#include +#include + +#include + +#include + +#include + + +/** + * Panneau Qt permettant de définir interactivement la vue d'un théâtre. Cette vue est définie par l'emplacement et la focale de la caméra. + * Ce panneau peut piloter, optionnellement, une caméra VTK. La caméra est mise à jour avec les derniers paramètres saisis lorsque + * l'utilisateur effectue un retour chariot dans un champ numérique. + */ +class QtVtkViewDefinitionPanel : public QWidget +{ + Q_OBJECT + + public : + + /** Constructeur. + * @param widget parent. Ne doit pas être nul. + * @param titre de l'application (pour les messages d'erreur). + * @param Eventuel nom du point de vue + * @param Eventuel commentaire associé au point de vue + * @param position initiale (x, y, z) de la caméra. + * @param focale initiale (x, y, z) de la caméra. + * @param direction vers le haut (dx, dy, dz) de la caméra. + * @param roulis (angle de la caméra par rapport à sa direction (axe position-focale)). En degrés. + * @param Renderer utilisant la caméra à piloter si non nul (GetActiveCamera sur le renderer est utilisé). + */ + QtVtkViewDefinitionPanel (QWidget* parent, const IN_STD string& appTitle, const TkUtil::UTF8String& name, const TkUtil::UTF8String& comment, + double position [3], double focal [3], double viewUp [3], double roll, vtkRenderer* renderer); + + /** Destructeur. */ + virtual ~QtVtkViewDefinitionPanel ( ); + + /** @return l'éventuel nom du point de vue. */ + virtual TkUtil::UTF8String getName ( ) const; + + /** @return l'éventuel commentaire associé au point de vue. */ + virtual TkUtil::UTF8String getComment ( ) const; + + /** @param les coordonnées de la caméra, en retour. */ + virtual void getPosition (double coords [3]) const; + + /** @param la position de la focale la caméra, en retour. */ + virtual void getFocalPoint (double coords [3]) const; + + /** @param direction vers le haut (dx, dy, dz) de la caméra, en retour. */ + virtual void getViewUp (double direction [3]) const; + + /** @return le roulis de la caméra. */ + virtual double getRoll ( ) const; + + /** Applique les modification à l'éventuelle caméra. Affecte true à _updated. */ + virtual void apply ( ); + + /** Restaure les paramètres initiaux, aussi bien au niveau du panneau qu'au niveau de la caméra éventuellement pilotée. + */ + virtual void reset ( ); + + /** @return true si les paramètres ont été modifiés depuis le constructeur, sinon retourne false. */ + virtual bool isModified ( ) const + { return _modified; } + + + protected : + + + /** + * @param Nouvelle coordonnées de la caméra. + */ + virtual void setPosition (double coords [3]); + + /** + * @param Nouvelle coordonnées de la focale de la caméra. + */ + virtual void setFocalPoint (double coords [3]); + + /** + * @param Nouvelle direction haute de la caméra. + */ + virtual void setViewUp (double direction [3]); + + /** + * @param Nouveau roulis de la caméra. + */ + virtual void setRoll (double roll); + + /** + * Affecte le caractère "modifié" (depuis sa construction) à cette instance. + */ + virtual void setModified (bool modified) + { _modified = modified; } + + /** @return true si les paramètres n'ont pas été modifiés depuis la dernière mise à jour de la caméra, sinon retourne false. */ + virtual bool isUpdated ( ) const + { return _updated; } + + /** + * @param Mise à jour du caractère "caméra mis à jour". + */ + virtual void setUpdated (bool updated) + { _updated = updated; } + + /** + * Met à jour les paramètres au regard des valeurs dans le panneau. + * Appelle setModified (true) et setUpdated (false) si l'un d'entre-eux est modifié. + */ + virtual void updateData ( ); + + + protected slots : + + /** Appelé quand l'utilisateur modifie un champ dans le panneau. + * @param Nouveau texte. + * Affecte setUpdated (false). + */ + virtual void viewFieldModifiedCallback (const QString&); + + /** Appelé quand l'utilisateur valide la saisie d'un champ dans le panneau. Appelle apply. + * Affecte true à _modified si un paramètre est changé. + */ + virtual void viewFieldValidatedCallback ( ); + + + private : + + /** Constructeur de copie. Interdit. */ + QtVtkViewDefinitionPanel (const QtVtkViewDefinitionPanel&); + + /** Opérateur de copie. Interdit. */ + QtVtkViewDefinitionPanel& operator = (const QtVtkViewDefinitionPanel&); + + /** Le titre de l'application. */ + IN_STD string _appTitle; + + /** Le champ de définition du nom. */ + QtTextField* _nameTextField; + + /** Le champ de définition du commentaire. */ + QtTextField* _commentTextField; + + /** La position de la caméra. */ + Qt3DDataPanel* _positionPanel; + + /** La position de la focale de la caméra. */ + Qt3DDataPanel* _focalPanel; + + /** La direction vers le haut de la caméra. */ + Qt3DDataPanel* _viewUpPanel; + + /** Le champ de définition du roulis. */ + QtTextField* _rollTextField; + + /** Le renderer utilisant la caméra pilotée. */ + vtkRenderer* _renderer; + + /** La position initiale. */ + double _initialPosition [3]; + + /** La position initiale de la focale. */ + double _initialFocal [3]; + + /** La direction vers le haut initiale. */ + double _initialViewUp [3]; + + /** La valeur initiale du roulis. */ + double _initialRoll; + + /** La dernière position. */ + double _position [3]; + + /** La dernière position de la focale. */ + double _focal [3]; + + /** La direction vers le haut. */ + double _viewUp [3]; + + /** La dernère valeur du roulis. */ + double _roll; + + /** Les paramètres ont ils été modifiés par l'utilisateur ? */ + bool _modified; + + /** La vue est-elle à jour par rapport aux paramètres ? */ + bool _updated; +}; // class QtVtkViewDefinitionPanel + + + +#endif // QT_VTK_VIEW_DEFINITION_PANEL_H diff --git a/src/QtVtk/public/QtVtk/QtVtkViewPointToolBar.h b/src/QtVtk/public/QtVtk/QtVtkViewPointToolBar.h new file mode 100644 index 0000000..04d7ee7 --- /dev/null +++ b/src/QtVtk/public/QtVtk/QtVtkViewPointToolBar.h @@ -0,0 +1,84 @@ +#ifndef QT_VTK_VIEWPOINT_TOOL_BAR_H +#define QT_VTK_VIEWPOINT_TOOL_BAR_H + +#include +#include + +#include + + +/** + * @brief Barre de boutons à menu permettant de gérer un point de vue dans une fenêtre VTK et d'assurer la persistance de ce point de vue. + * @since 8.7.0 + */ +class QtVtkViewPointToolBar : public QToolBar +{ + Q_OBJECT + + public : + + /** + * @param Parent + * @param Camera VTK associée aux points de vue + * @param Eventuel gestionnaire de rendu (pour forcer les opération d'actualisation de la vue). + */ + QtVtkViewPointToolBar (QWidget* parent, vtkCamera& camera, vtkRenderer* renderer); + + /** + * Destructeur. RAS. + */ + virtual ~QtVtkViewPointToolBar ( ); + + /** + * Ajoute le point de vue transmis en argument à la barre de boutons. + */ + virtual void addViewPoint (const QtVtkViewPointToolButton::VtkViewPoint& viewPoint); + + /** + * Enlève le point de vue dont une référence sur le bouton est transmise en argument. + */ + virtual void removeViewPoint (QtVtkViewPointToolButton& viewPointButton); + + + protected slots : + + /** + * Ajoute le point de vue aux points de vue existants. + */ + virtual void newViewPointCallback ( ); + + /** + * Réinitialise (supprime tous les points de vue. + */ + virtual void initializeCallback ( ); + + /** + * Exporte les points de vue dans un fichier. + */ + virtual void exportViewPointsCallback ( ); + + /** + * Importe les points de vue depusi un fichier. + */ + virtual void importViewPointsCallback ( ); + + + private : + + QtVtkViewPointToolBar (const QtVtkViewPointToolBar&); + QtVtkViewPointToolBar& operator = (const QtVtkViewPointToolBar&); + + /** Points de vue gérés. */ + std::vector _viewPointButtons; + + /** Indice du prochain bouton créé. */ + size_t _nextButton; + + /** Camera VTK associée. */ + vtkCamera* _camera; + + /** Gestionnaire de rendu (pour forcer les opération d'actualisation de la vue). */ + vtkRenderer* _renderer; +}; // class QtVtkViewPointToolBar + +#endif // QT_VTK_VIEWPOINT_TOOL_BAR_H diff --git a/src/QtVtk/public/QtVtk/QtVtkViewPointToolButton.h b/src/QtVtk/public/QtVtk/QtVtkViewPointToolButton.h new file mode 100644 index 0000000..8a8e224 --- /dev/null +++ b/src/QtVtk/public/QtVtk/QtVtkViewPointToolButton.h @@ -0,0 +1,124 @@ +#ifndef QT_VTK_VIEWPOINT_TOOL_BUTTON_H +#define QT_VTK_VIEWPOINT_TOOL_BUTTON_H + +#include +#include +#include +#include +#include + + +/** + * @brief Bouton à menu permettant de gérer un point de vue dans une fenêtre VTK et d'assurer la persistance de ce point de vue. + * @since 8.7.0 + */ +class QtVtkViewPointToolButton : public QToolButton +{ + Q_OBJECT + + public : + + /** + * La définition d'un point de vue. + */ + struct VtkViewPoint + { + VtkViewPoint ( ); + VtkViewPoint (const VtkViewPoint& vp); + VtkViewPoint& operator = (const VtkViewPoint& vp); + VtkViewPoint& operator = (const vtkCamera&); + ~VtkViewPoint ( ); + + /** Nom de la vue et commentaire associé. */ + TkUtil::UTF8String name, comment; + + /** Position de l'observateur. */ + double position [3]; + + /** Point focal. */ + double focalPoint [3]; + + /** Direction vers le haut. */ + double viewUp [3]; + + /** Roulis (rotation autour de l'axe de visée). */ + double roll; + }; // struct VtkViewPoint + + static Preferences::Section* viewPointToSection (const VtkViewPoint& viewpoint); + static VtkViewPoint sectionToViewPoint (const Preferences::Section& section); + + + /** + * @param Parent + * @param Icône du bouton + * @param Nom du point de vue + * @param Camera VTK associée au point de vue + * @param Eventuel gestionnaire de rendu (pour forcer les opération d'actualisation de la vue). + */ + QtVtkViewPointToolButton (QWidget* parent, const std::string& icon, const TkUtil::UTF8String& name, vtkCamera& camera, vtkRenderer* renderer); + + /** + * @param Parent + * @param Icône du bouton + * @param Définition du point de vue + * @param Camera VTK associée au point de vue + * @param Eventuel gestionnaire de rendu (pour forcer les opération d'actualisation de la vue). + */ + QtVtkViewPointToolButton (QWidget* parent, const std::string& icon, const VtkViewPoint& viewPoint, vtkCamera& camera, vtkRenderer* renderer); + + /** + * Destructeur. RAS. + */ + virtual ~QtVtkViewPointToolButton ( ); + + /** + * @return La description du point de vue + */ + virtual const VtkViewPoint& getViewPoint ( ) const; + + /** + * @param Nouveau point de vue. Modifie également la vue graphique. + */ + virtual void setViewPoint (const VtkViewPoint& vp); + + + protected slots : + + /** + * Modifie la vue conformément aux paramétrage de ce point de vue. + */ + virtual void applyViewPointCallback ( ); + + /** + * Affiche une boite de dialogue de modification du point de vue. + */ + virtual void editViewPointCallback ( ); + + /** + * Supprime la vue (et le bouton). + */ + virtual void removeViewPointCallback ( ); + + /** + * Exporte le point de vue dans un fichier. + */ + virtual void exportViewPointCallback ( ); + + + private : + + QtVtkViewPointToolButton (const QtVtkViewPointToolButton&); + QtVtkViewPointToolButton& operator = (const QtVtkViewPointToolButton&); + + /** Le point de vue. */ + VtkViewPoint _viewPoint; + + /** Camera VTK associée. */ + vtkCamera* _camera; + + /** Gestionnaire de rendu (pour forcer les opération d'actualisation de la vue). */ + vtkRenderer* _renderer; +}; // class QtVtkViewPointToolButton + +#endif // QT_VTK_VIEWPOINT_TOOL_BUTTON_H diff --git a/src/viewpoint/CMakeLists.txt b/src/viewpoint/CMakeLists.txt new file mode 100644 index 0000000..4fa2264 --- /dev/null +++ b/src/viewpoint/CMakeLists.txt @@ -0,0 +1,18 @@ +find_package (GUIToolkitsVariables) + +include (${CMAKE_SOURCE_DIR}/cmake/version.cmake) +include (${GUIToolkitsVariables_CMAKE_DIR}/common.cmake) +include (${GUIToolkitsVariables_CMAKE_DIR}/common_qt.cmake) +include (${GUIToolkitsVariables_CMAKE_DIR}/workarounds.cmake) + +add_executable (viewpoint viewpoint.cpp QtViewPointWindow.cpp) +set_property (TARGET viewpoint PROPERTY AUTOMOC ON) + +set (ALL_TARGETS viewpoint) + +foreach (exe ${ALL_TARGETS}) + target_include_directories (${exe} PRIVATE ../QtVtk/public ${CMAKE_CURRENT_SOURCE_DIR}) + target_compile_options (${exe} PRIVATE ${SHARED_CFLAGS}) + target_link_libraries (${exe} PRIVATE QtVtk) + set_target_properties (${exe} PROPERTIES INSTALL_RPATH_USE_LINK_PATH 1 INSTALL_RPATH ${CMAKE_PACKAGE_RPATH_DIR}) +endforeach ( ) diff --git a/src/viewpoint/QtViewPointWindow.cpp b/src/viewpoint/QtViewPointWindow.cpp new file mode 100644 index 0000000..28dbb85 --- /dev/null +++ b/src/viewpoint/QtViewPointWindow.cpp @@ -0,0 +1,289 @@ +#include "QtViewPointWindow.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace TkUtil; +using namespace std; + +static const TkUtil::Charset charset ("àéèùô"); + +USE_ENCODING_AUTODETECTION + + +QtViewPointWindow::QtViewPointWindow ( ) + : QMainWindow ( ), _graphicWindow (0), _renderer (0), _renderWindow (0), _actors ( ), _surfaces ( ) +{ + createGui ( ); + createMenu ( ); +} // QtViewPointWindow::QtViewPointWindow + + +void QtViewPointWindow::createGui ( ) +{ + _graphicWindow = new QtVtkGraphicWidget (this); + _graphicWindow->setAttribute (Qt::WA_TranslucentBackground, true); // Bonne gestion transparence + setCentralWidget (_graphicWindow); + _renderer = vtkRenderer::New ( ); + _renderWindow = vtkRenderWindow::New ( ); + _renderWindow->Render ( ); // Pour bonne gestion transparence + _renderWindow->SetAlphaBitPlanes (1); // Bonne gestion transparence + _renderWindow->SetMultiSamples (0); // Bonne gestion transparence + _renderer->SetUseDepthPeeling (true); // Bonne gestion transparence + _renderer->SetBackground (1., 1., 1.); // Blanc +//_renderer->SetBackground (0., 0., 0.); // Noir + _renderWindow->AddRenderer (_renderer); + vtkRenderer* trihedronRenderer = vtkRenderer::New ( ); + trihedronRenderer->InteractiveOff ( ); + trihedronRenderer->SetViewport (0, 0, 0.2, 0.2); + trihedronRenderer->SetLayer (1); + vtkTrihedronCommand* trihedronCommand = vtkTrihedronCommand::New ( ); + _renderer->AddObserver (vtkCommand::StartEvent, trihedronCommand); + trihedronCommand->SetRenderer (trihedronRenderer); + vtkTrihedron* trihedron = vtkTrihedron::New ( ); + trihedron->PickableOff ( ); + trihedronRenderer->AddActor (trihedron); + _renderWindow->SetNumberOfLayers (2); + _renderWindow->AddRenderer (trihedronRenderer); + _graphicWindow->SetRenderWindow (_renderWindow); + vtkInteractorStyleSwitch* interactorStyle = vtkInteractorStyleSwitch::New ( ); + _graphicWindow->GetInteractor ( )->SetInteractorStyle (interactorStyle); + _graphicWindow->GetInteractor ( )->SetRenderWindow (_renderWindow); + _graphicWindow->setMinimumSize (800, 600); + _graphicWindow->resize (800, 600); +} // QtViewPointWindow::createGui + + +void QtViewPointWindow::createMenu ( ) +{ + addToolBar (Qt::TopToolBarArea, new QtVtkViewPointToolBar (this, *_renderer->GetActiveCamera ( ), _renderer)); + QMenuBar* menubar = menuBar ( ); + + QMenu* fileMenu = new QMenu ("&Fichier", menubar); + menubar->addMenu (fileMenu); + fileMenu->setToolTipsVisible (true); + QAction* action = new QAction ("Im&primer ...", this); + connect (action, SIGNAL (triggered( )), this, SLOT(printCallback ( ))); + fileMenu->addAction (action); + action = new QAction ("Im&primer dans un fichier ...", this); + connect (action, SIGNAL (triggered( )), this, SLOT(printToFileCallback ( ))); + fileMenu->addAction (action); + fileMenu->addSeparator ( ); + action = new QAction ("&Quitter", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (quitCallback ( ))); + fileMenu->addAction (action); + + QMenu* objectMenu = new QMenu ("&Objets", menubar); + menubar->addMenu (objectMenu); + objectMenu->setToolTipsVisible (true); + action = new QAction ("S&upprimer", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (removeObjectsCallback ( ))); + objectMenu->addAction (action); + action = new QAction (QSTR ("Sp&hère ..."), this); + connect (action, SIGNAL (triggered ( )), this, SLOT (sphereCallback ( ))); + objectMenu->addAction (action); + action = new QAction ("C&ylindre ...", this); + connect (action, SIGNAL (triggered ( )), this, SLOT (cylinderCallback ( ))); + objectMenu->addAction (action); +} // QtViewPointWindow::createMenu + + +void QtViewPointWindow::printCallback ( ) +{ + try + { + raise ( ); // Eviter qu'une fenêtre recouvre celle-ci + CHECK_NULL_PTR_ERROR (_renderWindow) + QtVTKPrintHelper::PrinterStatus status = QtVTKPrintHelper::print (*_renderWindow, this); + } + catch (const Exception& e) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), e.getFullMessage ( )); + } + catch (...) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), "Erreur non documentée"); + } +} // QtViewPointWindow::printCallback + + +void QtViewPointWindow::printToFileCallback ( ) +{ + try + { + raise ( ); // Eviter qu'une fen^etre recouvre celle-ci + CHECK_NULL_PTR_ERROR (_renderWindow) + QtVTKPrintHelper::PrinterStatus status = QtVTKPrintHelper::printToFile (*_renderWindow, this); + } + catch (const Exception& e) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), e.getFullMessage ( )); + } + catch (...) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), "Erreur non documentée"); + } +} // QtViewPointWindow::printToFileCallback + + +void QtViewPointWindow::quitCallback ( ) +{ + QApplication::exit (0); +} // QtViewPointWindow::quitCallback + + +void QtViewPointWindow::removeObjectsCallback ( ) +{ + try + { + CHECK_NULL_PTR_ERROR (_renderer) + CHECK_NULL_PTR_ERROR (_renderWindow) + for (vector::iterator it = _actors.begin ( ); + _actors.end ( ) != it; it++) + { + _renderer->RemoveActor (*it); + (*it)->Delete ( ); + } + for (vector::iterator itpd = _surfaces.begin ( ); + _surfaces.end ( ) != itpd; itpd++) + (*itpd)->Delete ( ); + + _actors.clear ( ); + _surfaces.clear ( ); + } + catch (const Exception& e) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), e.getFullMessage ( )); + } + catch (...) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), "Erreur non documentée"); + } +} // QtViewPointWindow::removeObjectsCallback + + +void QtViewPointWindow::sphereCallback ( ) +{ + try + { + CHECK_NULL_PTR_ERROR (_renderer) + CHECK_NULL_PTR_ERROR (_renderWindow) + // Mériterait une boite de dialogue dédiée : + double x = 0., y = 0., z = 0., radius = 1.; + QtCoordinatesDialog coordsDialog (this, "Centre de la sphère", "X :", "Y :", "Z :", x, y, z, false, true, true, true); + if (QDialog::Rejected == coordsDialog.exec ( )) + return; + coordsDialog.getCoordinates (x, y, z); + bool ok = true; + radius = QInputDialog::getDouble (this, QSTR ("Rayon de la sphère"), "Rayon :", radius, 0., 9.99E9, 10, &ok); + if (false == ok) + return; + vtkSphereSource* sphere = vtkSphereSource::New ( ); + sphere->SetCenter (x, y, z); + sphere->SetThetaResolution (360 / 4); + sphere->SetPhiResolution (360 / 4); + sphere->SetRadius (radius); + vtkPolyDataMapper* mapper = vtkPolyDataMapper::New ( ); + vtkActor* actor = vtkActor::New ( ); + mapper->SetInputConnection (sphere->GetOutputPort ( )); + actor->SetMapper (mapper); + _renderer->AddActor (actor); + _renderer->ResetCamera ( ); + _renderWindow->Render ( ); + _actors.push_back (actor); + vtkPolyData* surface = sphere->GetOutput ( ); + sphere->Update ( ); + surface->Register (0); + _surfaces.push_back (surface); + mapper->Delete ( ); mapper = 0; + sphere->Delete ( ); sphere = 0; + } + catch (const Exception& e) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), e.getFullMessage ( )); + } + catch (...) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), "Erreur non documentée"); + } +} // QtViewPointWindow::sphereCallback + + +void QtViewPointWindow::cylinderCallback ( ) +{ + try + { + CHECK_NULL_PTR_ERROR (_renderer) + CHECK_NULL_PTR_ERROR (_renderWindow) + // Mériterait une boite de dialogue dédiée : + double x = 0., y = 0., z = 0., radius = 1., height = 1; + QtCoordinatesDialog coordsDialog (this, "Centre du cylindre", "X :", "Y :", "Z :", x, y, z, false, true, true, true); + if (QDialog::Rejected == coordsDialog.exec ( )) + return; + coordsDialog.getCoordinates (x, y, z); + bool ok = true; + height = QInputDialog::getDouble (this, "Hauteur du cylindre", "Hauteur :", height, 0., 9.99E9, 10, &ok); + if (false == ok) + return; + radius = QInputDialog::getDouble (this, "Rayon du cylindre", "Rayon :", radius, 0., 9.99E9, 10, &ok); + if (false == ok) + return; + vtkCylinderSource* cylinder = vtkCylinderSource::New ( ); + cylinder->SetCenter (x, y, z); + cylinder->SetResolution (360); + cylinder->SetHeight (height); + cylinder->SetRadius (radius); + cylinder->CappingOff ( ); + // Par défaut le cylindre est le long de l'axe des Y, on le veut le long des X : + vtkTransformFilter* filter = vtkTransformFilter::New ( ); + vtkTransform* transform = vtkTransform::New ( ); + transform->RotateZ (90.); + filter->SetTransform (transform); + filter->SetInputData (cylinder->GetOutput ( )); + cylinder->Update ( ); + vtkPolyDataMapper* mapper = vtkPolyDataMapper::New ( ); + vtkActor* actor = vtkActor::New ( ); + mapper->SetInputConnection (filter->GetOutputPort ( )); + actor->SetMapper (mapper); + _renderer->AddActor (actor); + _renderer->ResetCamera ( ); + _renderWindow->Render ( ); + _actors.push_back (actor); + vtkPolyData* surface = filter->GetPolyDataOutput ( ); + surface->Register (0); + _surfaces.push_back (surface); + mapper->Delete ( ); mapper = 0; + cylinder->Delete ( ); cylinder = 0; + } + catch (const Exception& e) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), e.getFullMessage ( )); + } + catch (...) + { + QtMessageBox::displayErrorMessage (this, windowTitle ( ).toStdString ( ), "Erreur non documentée"); + } +} // QtViewPointWindow::cylinderCallback diff --git a/src/viewpoint/QtViewPointWindow.h b/src/viewpoint/QtViewPointWindow.h new file mode 100644 index 0000000..fd3c459 --- /dev/null +++ b/src/viewpoint/QtViewPointWindow.h @@ -0,0 +1,58 @@ +#include + +#include +#include + +#include +#include +#include +#include + +#include + + +class QtViewPointWindow : public QMainWindow +{ + Q_OBJECT + + public : + + QtViewPointWindow ( ); + + ~QtViewPointWindow ( ) + { } + + + protected : + + void createGui ( ); + void createMenu ( ); + + + protected slots : + + + virtual void printCallback ( ); + virtual void printToFileCallback ( ); + virtual void quitCallback ( ); + virtual void removeObjectsCallback ( ); + virtual void sphereCallback ( ); + virtual void cylinderCallback ( ); + + + private : + + QtViewPointWindow (const QtViewPointWindow&) + : QMainWindow ( ) + { } + QtViewPointWindow& operator = (const QtViewPointWindow&) + { return *this; } + + QtVtkGraphicWidget* _graphicWindow; + vtkRenderer* _renderer; + vtkRenderWindow* _renderWindow; + std::vector _actors; + std::vector _surfaces; +}; // class QtViewPointWindow + + diff --git a/src/viewpoint/viewpoint.cpp b/src/viewpoint/viewpoint.cpp new file mode 100644 index 0000000..2237bdd --- /dev/null +++ b/src/viewpoint/viewpoint.cpp @@ -0,0 +1,40 @@ +/** + * Petite application test mettant en scène une chambre d'expérience avec des + * pointages laser. + */ +#include "QtViewPointWindow.h" +#include + +#include +#include + +#include + +#include + + +using namespace TkUtil; +using namespace std; + + +int main (int argc, char* argv[]) +{ + try + { + QApplication* application = new QApplication (argc, argv); + QtVtk::initialize ( ); + QtViewPointWindow* mainWindow = new QtViewPointWindow ( ); + mainWindow->show ( ); + return application->exec ( ); + } + catch (const Exception& e) + { + cerr << "ERREUR : " << e.getFullMessage ( ) << endl; + return -1; + } + catch (...) + { + cerr << "ERREUR non documentée." << endl; + return -2; + } +} // main diff --git a/versions.txt b/versions.txt index a9e821f..33dbacf 100644 --- a/versions.txt +++ b/versions.txt @@ -1,5 +1,12 @@ A FAIRE : tester le vtkIntersectionPolyDataFilter de VTK 7, voir si de base il propose les services attendus (Inner, ...). +Version 8.7.0 : 08/04/25 +=============== + +Classes QtVtkViewPointToolBar et QtVtkViewPointToolButton. +Ce projet dépend maintenant de PrefsQt v 6.x. + + Version 8.6.0 : 22/11/24 ===============