From 840251fc351ab8cedbb218636380846bd00e6c55 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 14 May 2008 15:09:04 +0000 Subject: [PATCH] *** empty log message *** --- src/VISUGUI/Makefile.am | 6 +- src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx | 326 ++++++++++++++++++++--- src/VISUGUI/VisuGUI_ClippingPlaneMgr.h | 68 ++++- src/VISUGUI/VisuGUI_SegmentationMgr.cxx | 70 +++++ src/VISUGUI/VisuGUI_SegmentationMgr.h | 71 +++++ src/VISUGUI/VisuGUI_ViewExtender.cxx | 44 ++- src/VISUGUI/VisuGUI_ViewExtender.h | 12 +- 7 files changed, 540 insertions(+), 57 deletions(-) create mode 100644 src/VISUGUI/VisuGUI_SegmentationMgr.cxx create mode 100644 src/VISUGUI/VisuGUI_SegmentationMgr.h diff --git a/src/VISUGUI/Makefile.am b/src/VISUGUI/Makefile.am index ec5bfe9d..aed0f567 100644 --- a/src/VISUGUI/Makefile.am +++ b/src/VISUGUI/Makefile.am @@ -76,7 +76,8 @@ dist_libVISU_la_SOURCES= \ VisuGUI_CacheDlg.cxx \ VisuGUI_FieldFilter.cxx \ VisuGUI_ViewExtender.cxx \ - VisuGUI_ClippingPlaneMgr.cxx + VisuGUI_ClippingPlaneMgr.cxx \ + VisuGUI_SegmentationMgr.cxx MOC_FILES= \ VisuGUI_moc.cxx \ @@ -111,7 +112,8 @@ MOC_FILES= \ VisuGUI_InputPane_moc.cxx \ VisuGUI_CacheDlg_moc.cxx \ VisuGUI_ViewExtender_moc.cxx \ - VisuGUI_ClippingPlaneMgr_moc.cxx + VisuGUI_ClippingPlaneMgr_moc.cxx \ + VisuGUI_SegmentationMgr_moc.cxx nodist_libVISU_la_SOURCES=$(MOC_FILES) diff --git a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx index f5578879..5643b5a8 100644 --- a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx +++ b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.cxx @@ -23,12 +23,16 @@ #include "VisuGUI.h" #include "VisuGUI_Tools.h" +#include #include +#include +#include +#include #include #include #include -#include +#include #include #include #include @@ -38,12 +42,23 @@ #include #include +#include + using namespace std; -VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule) + + + +//**************************************************************** +VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule, + SVTK_ViewWindow* theViewWindow, + const QListOfPlanes& thePlanes) : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ), - myModule(theModule) + myModule(theModule), + myPlanes(thePlanes), + myViewWindow(theViewWindow), + myCurrentPlane(-1) { setWindowTitle(tr("TITLE")); setSizeGripEnabled(true); @@ -56,15 +71,22 @@ VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule) QHBoxLayout* aPlanesBox = new QHBoxLayout(this); aPlanesBox->setMargin(6); + aPlanesBox->setSizeConstraint(QLayout::SetMinimumSize); aMainLayout->addLayout(aPlanesBox); - myPlanesList = new QListView(this); + myPlanesList = new QListWidget(this); + for (int i = 0; i < myPlanes.size(); i++) + myPlanesList->addItem(myPlanes.at(i).name); + + myPlanesList->setMaximumSize(160, 500); + myPlanesList->setSelectionMode(QAbstractItemView::SingleSelection); + connect(myPlanesList, SIGNAL(currentRowChanged(int)), this, SLOT(onPlaneSelection(int))); aPlanesBox->addWidget(myPlanesList); // Planes parameters box QFrame* aPlanesFrame = new QFrame(this); aPlanesFrame->setWindowTitle(tr("TITLE_PLANES")); - aPlanesBox->addWidget(aPlanesFrame); + aPlanesBox->addWidget(aPlanesFrame, 1); QVBoxLayout* aFrameLayout = new QVBoxLayout(aPlanesFrame); aFrameLayout->setSpacing(5); @@ -78,11 +100,12 @@ VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule) myNameEdt = new QLineEdit(aPlanesFrame); aNameBox->addWidget(myNameEdt); - myMethodTab = new QTabWidget(aPlanesFrame); + //myMethodTab = new QTabWidget(aPlanesFrame); + myMethodTab = createVectorTab(aPlanesFrame); aFrameLayout->addWidget(myMethodTab); - myMethodTab->addTab(createVectorTab(), tr("BYVECTOR_TITLE")); - myMethodTab->addTab(createPlanesTab(), tr("BYPLANE_TITLE")); + // myMethodTab->addTab(createVectorTab(), tr("BYVECTOR_TITLE")); + // myMethodTab->addTab(createPlanesTab(), tr("BYPLANE_TITLE")); myAutoApply = new QCheckBox(tr("CHK_AUTOAPPLY"), aPlanesFrame); aFrameLayout->addWidget(myAutoApply); @@ -93,9 +116,11 @@ VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule) aManageBox->setMargin(6); QPushButton* aNewBtn = new QPushButton(tr("BTN_NEW"), this); + connect(aNewBtn, SIGNAL(clicked()), this, SLOT(onNewPlane())); aManageBox->addWidget(aNewBtn); QPushButton* aDeleteBtn = new QPushButton(tr("BTN_DELETE"), this); + connect(aDeleteBtn, SIGNAL(clicked()), this, SLOT(onDeletePlane())); aManageBox->addWidget(aDeleteBtn); aManageBox->addStretch(); @@ -125,13 +150,24 @@ VisuGUI_ClippingPlaneMgr::VisuGUI_ClippingPlaneMgr(VisuGUI* theModule) QPushButton* aBtnHelp = new QPushButton(tr("BUT_HELP"), aGroupButtons); aButtonsLayout->addWidget(aBtnHelp); + + connect(aBtnOk , SIGNAL(clicked()), this, SLOT(onOk())); + connect(aBtnApply, SIGNAL(clicked()), this, SLOT(onApply())); + connect(aBtnClose, SIGNAL(clicked()), this, SLOT(onClose())); + connect(aBtnHelp , SIGNAL(clicked()), this, SLOT(onHelp())); + + if (myPlanes.size() == 0) + myMethodTab->setEnabled(false); + else { + myPlanesList->setCurrentRow(0); + } } //**************************************************************** -QWidget* VisuGUI_ClippingPlaneMgr::createVectorTab() +QWidget* VisuGUI_ClippingPlaneMgr::createVectorTab(QWidget* theParent) { - QWidget* aVectorTab = new QWidget(myMethodTab); + QWidget* aVectorTab = new QWidget(theParent); QVBoxLayout* aVectorTabLayout = new QVBoxLayout(aVectorTab); QGroupBox* aOriginGroup = new QGroupBox( tr( "ORIGIN_TITLE" ), aVectorTab ); @@ -172,50 +208,270 @@ QWidget* VisuGUI_ClippingPlaneMgr::createVectorTab() myZDir->setValue( 0.0 ); aDirLayout->addWidget( myZDir ); + connect(myXDir, SIGNAL(valueChanged(double)), this, SLOT(setPlaneFromVector())); + connect(myYDir, SIGNAL(valueChanged(double)), this, SLOT(setPlaneFromVector())); + connect(myZDir, SIGNAL(valueChanged(double)), this, SLOT(setPlaneFromVector())); + return aVectorTab; } //**************************************************************** -QWidget* VisuGUI_ClippingPlaneMgr::createPlanesTab() +// QWidget* VisuGUI_ClippingPlaneMgr::createPlanesTab() +// { +// QWidget* aPlanesTab = new QWidget(myMethodTab); +// QGridLayout* aVectorTabLayout = new QGridLayout(aPlanesTab); + +// aVectorTabLayout->addWidget(new QLabel(tr("LBL_ORIENTATION"), aPlanesTab), 0, 0); +// aVectorTabLayout->addWidget(new QLabel(tr("LBL_DISTANCE"), aPlanesTab), 1, 0); + +// myPlaneCombo = new QComboBox(aPlanesTab); +// myPlaneCombo->addItem("|| X-Y"); +// myPlaneCombo->addItem("|| Y-Z"); +// myPlaneCombo->addItem("|| Z-X"); +// connect(myPlaneCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onMainPlaneSelect(int))); +// aVectorTabLayout->addWidget(myPlaneCombo, 0, 1); + +// myDistance = new QtxDoubleSpinBox( -1000, 1000, 1, aPlanesTab ); +// myDistance->setValue( 0.0 ); +// aVectorTabLayout->addWidget( myDistance, 1, 1 ); + +// myRotationXLbl = new QLabel(tr("LBL_ROTATION").arg("X"), aPlanesTab); +// aVectorTabLayout->addWidget(myRotationXLbl, 0, 2); + +// myRotX = new QtxDoubleSpinBox( -180.0, 180.0, 1, aPlanesTab ); +// myRotX->setValue( 0.0 ); +// aVectorTabLayout->addWidget( myRotX, 0, 3 ); + +// myRotationYLbl = new QLabel(tr("LBL_ROTATION").arg("Y"), aPlanesTab); +// aVectorTabLayout->addWidget(myRotationYLbl, 1, 2); + +// myRotY = new QtxDoubleSpinBox( -180.0, 180.0, 1, aPlanesTab ); +// myRotY->setValue( 0.0 ); +// aVectorTabLayout->addWidget( myRotY, 1, 3 ); + + +// return aPlanesTab; +// } + + +//**************************************************************** +VisuGUI_ClippingPlaneMgr::~VisuGUI_ClippingPlaneMgr() +{ +} + +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::onOk() +{ + onApply(); + onClose(); +} + +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::onApply() +{ + savePlane(myCurrentPlane); + emit applyPlanes(); +} + +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::onClose() +{ + close(); +} + +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::onPlaneSelection(int theRow) +{ + if (myCurrentPlane != -1) + savePlane(myCurrentPlane); + showPlane(theRow); + myCurrentPlane = theRow; +} + +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::onNewPlane() { - QWidget* aPlanesTab = new QWidget(myMethodTab); - QGridLayout* aVectorTabLayout = new QGridLayout(aPlanesTab); + PlaneDef aPlane; + setEmptyPlane(aPlane); + myPlanes.append(aPlane); - aVectorTabLayout->addWidget(new QLabel(tr("LBL_ORIENTATION"), aPlanesTab), 0, 0); - aVectorTabLayout->addWidget(new QLabel(tr("LBL_DISTANCE"), aPlanesTab), 1, 0); + myPlanesList->addItem(aPlane.name); + myPlanesList->setCurrentRow(myPlanes.size() - 1); + myMethodTab->setEnabled(true); +} - myPlaneCombo = new QComboBox(aPlanesTab); - myPlaneCombo->addItem("|| X-Y"); - myPlaneCombo->addItem("|| Y-Z"); - myPlaneCombo->addItem("|| X-Z"); - aVectorTabLayout->addWidget(myPlaneCombo, 0, 1); +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::onDeletePlane() +{ + if (myCurrentPlane == -1) return; + disconnect(myPlanesList, SIGNAL(currentRowChanged(int)), this, SLOT(onPlaneSelection(int))); + myPlanes.removeAt(myCurrentPlane); + myPlanesList->takeItem(myCurrentPlane); + if (myPlanes.size() == 0) + myCurrentPlane = -1; + else { + if (myCurrentPlane >= myPlanes.size()) + myCurrentPlane = myPlanes.size() - 1; + } + showPlane(myCurrentPlane); + myPlanesList->setCurrentRow(myCurrentPlane); + connect(myPlanesList, SIGNAL(currentRowChanged(int)), this, SLOT(onPlaneSelection(int))); + myMethodTab->setEnabled(myPlanes.size() > 0); +} - myDistance = new QtxDoubleSpinBox( -1000, 1000, 1, aPlanesTab ); - myDistance->setValue( 0.0 ); - aVectorTabLayout->addWidget( myDistance, 1, 1 ); +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::savePlane(int thePlaneNb) +{ + if (thePlaneNb < 0) return; + if (myPlanes.size() <= thePlaneNb) return; + PlaneDef aPlane; + aPlane.name = myNameEdt->text(); + aPlane.origin[0] = myXOrigin->value(); + aPlane.origin[1] = myYOrigin->value(); + aPlane.origin[2] = myZOrigin->value(); + + aPlane.direction[0] = myXDir->value(); + aPlane.direction[1] = myYDir->value(); + aPlane.direction[2] = myZDir->value(); - myRotationXLbl = new QLabel(tr("LBL_ROTATION").arg("X"), aPlanesTab); - aVectorTabLayout->addWidget(myRotationXLbl, 0, 2); + aPlane.isAuto = (myAutoApply->checkState() == Qt::Checked); + myPlanesList->item(thePlaneNb)->setText(aPlane.name); + myPlanes.replace(thePlaneNb, aPlane); +} - myRotX = new QtxDoubleSpinBox( -180.0, 180.0, 1, aPlanesTab ); - myRotX->setValue( 0.0 ); - aVectorTabLayout->addWidget( myRotX, 0, 3 ); +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::showPlane(int thePlaneNb) const +{ + if (myPlanes.size() <= thePlaneNb) return; + + PlaneDef aNullPlane; + setEmptyPlane(aNullPlane); - myRotationYLbl = new QLabel(tr("LBL_ROTATION").arg("Y"), aPlanesTab); - aVectorTabLayout->addWidget(myRotationYLbl, 1, 2); + const PlaneDef& aPlane = (thePlaneNb < 0)? aNullPlane : myPlanes.at(thePlaneNb); + myNameEdt->setText(aPlane.name); + myXOrigin->setValue(aPlane.origin[0]); + myYOrigin->setValue(aPlane.origin[1]); + myZOrigin->setValue(aPlane.origin[2]); - myRotY = new QtxDoubleSpinBox( -180.0, 180.0, 1, aPlanesTab ); - myRotY->setValue( 0.0 ); - aVectorTabLayout->addWidget( myRotY, 1, 3 ); + myXDir->setValue(aPlane.direction[0]); + myYDir->setValue(aPlane.direction[1]); + myZDir->setValue(aPlane.direction[2]); + myAutoApply->setCheckState(aPlane.isAuto? Qt::Checked : Qt::Unchecked); +} - return aPlanesTab; +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::setEmptyPlane(PlaneDef& thePlane) const +{ + thePlane.name = QString("Plane %1").arg(myPlanes.size()); + thePlane.origin[0] = 0.; + thePlane.origin[1] = 0.; + thePlane.origin[2] = 0.; + thePlane.direction[0] = 0.; + thePlane.direction[1] = 0.; + thePlane.direction[2] = 1.; + thePlane.isAuto = false; } +//**************************************************************** +//! returns number of main plane in the list myPlaneCombo. +//! If values are not correct returns -1 +// int VisuGUI_ClippingPlaneMgr::getMainPlane() +// { +// double aDir[3] = { myXDir->value(), myYDir->value(), myZDir->value() }; +// int aMainPlane = -1; +// if (vtkMath::Normalize(aDir) == 0) +// return aMainPlane; + +// //printf("#### Res x=%f, y=%f, z=%f\n", aDir[0], aDir[1], aDir[2]); +// double aLimit = cos(vtkMath::DegreesToRadians()*45.); +// //printf("#### Limit = %f\n", aLimit); +// if (fabs(aDir[0]) > aLimit) // Plane is Y-Z +// aMainPlane = 1; +// else if (fabs(aDir[1]) > aLimit) // Plane is X-Z +// aMainPlane = 2; +// else if (fabs(aDir[2]) > aLimit) // Plane is X-Z +// aMainPlane = 0; + +// //printf("#### Plane = %i\n", aMainPlane); +// return aMainPlane; +// } //**************************************************************** -VisuGUI_ClippingPlaneMgr::~VisuGUI_ClippingPlaneMgr() +//! Compute parameters of main planes pane from vector pane +// void VisuGUI_ClippingPlaneMgr::setPlaneFromVector() +// { +// int aPlaneIndex = getMainPlane(); +// if (aPlaneIndex == -1) return; +// myPlaneCombo->setCurrentIndex(aPlaneIndex); + +// double aDir[3] = { myXDir->value(), myYDir->value(), myZDir->value() }; +// vtkMath::Normalize(aDir); +// printf("#### Res x=%f, y=%f, z=%f\n", aDir[0], aDir[1], aDir[2]); + +// double aCoef = vtkMath::RadiansToDegrees(); +// switch (aPlaneIndex) { +// case 0: // || X-Y +// myRotX->setValue(asin(myYDir->value()) * aCoef); +// myRotY->setValue(asin(myXDir->value()) * aCoef); +// break; +// case 1: // || Y-Z +// myRotX->setValue(asin(myZDir->value()) * aCoef); +// myRotY->setValue(asin(myYDir->value()) * aCoef); +// break; +// case 2: // || Z-X +// myRotX->setValue(asin(myXDir->value()) * aCoef); +// myRotY->setValue(asin(myZDir->value()) * aCoef); +// break; +// } +// double aOrigin[3] = { myXOrigin->value(), myYOrigin->value(), myZOrigin->value() }; +// } + +//**************************************************************** +//! Compute parameters of vector pane from main planes pane +// void VisuGUI_ClippingPlaneMgr::setPlaneFromMPlane() +// { +// } + +//**************************************************************** +// void VisuGUI_ClippingPlaneMgr::onMainPlaneSelect(int theIndex) +// { +// switch (theIndex) { +// case 0: // || X-Y +// myRotationXLbl->setText( tr("LBL_ROTATION").arg("X") ); +// myRotationXLbl->setText( tr("LBL_ROTATION").arg("Y") ); +// break; +// case 1: // || Y-Z +// myRotationXLbl->setText( tr("LBL_ROTATION").arg("Y") ); +// myRotationXLbl->setText( tr("LBL_ROTATION").arg("Z") ); +// break; +// case 2: // || Z-X +// myRotationXLbl->setText( tr("LBL_ROTATION").arg("Z") ); +// myRotationXLbl->setText( tr("LBL_ROTATION").arg("X") ); +// break; +// } +// } + +//**************************************************************** +void VisuGUI_ClippingPlaneMgr::onHelp() { + QString aHelpFileName = "clipping_planes_page.html"; + LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication()); + if (app) + app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName); + else { + QString platform; +#ifdef WIN32 + platform = "winapplication"; +#else + platform = "application"; +#endif + SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"), + QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). + arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName), + QObject::tr("BUT_OK")); + } } + diff --git a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h index dd898a33..319863cd 100644 --- a/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h +++ b/src/VISUGUI/VisuGUI_ClippingPlaneMgr.h @@ -20,10 +20,11 @@ #ifndef DIALOGBOX_CLIPPINGPLANEMGR_H #define DIALOGBOX_CLIPPINGPLANEMGR_H -#include + + class VisuGUI; -class QListView; +class QListWidget; class QLineEdit; class QtxDoubleSpinBox; class QTabWidget; @@ -31,22 +32,59 @@ class QLabel; class QComboBox; class QCheckBox; + +#include +#include + class VisuGUI_ClippingPlaneMgr : public QDialog { Q_OBJECT public: - VisuGUI_ClippingPlaneMgr(VisuGUI* theModule); + VisuGUI_ClippingPlaneMgr(VisuGUI* theModule, + SVTK_ViewWindow* theViewWindow, + const QListOfPlanes& thePlanes); ~VisuGUI_ClippingPlaneMgr(); + const QListOfPlanes& getPlanes() const { return myPlanes; } + SVTK_ViewWindow* getViewWindow() const { return myViewWindow; } + + signals: + void applyPlanes(); + +private slots: + void onOk(); + void onApply(); + void onClose(); + void onHelp(); + void onPlaneSelection(int theRow); + void onNewPlane(); + void onDeletePlane(); + //! Compute parameters of main planes pane from vector pane + //void setPlaneFromVector(); + //! Compute parameters of vector pane from main planes pane + //void setPlaneFromMPlane(); + + //void onMainPlaneSelect(int); + private: - QWidget* createVectorTab(); - QWidget* createPlanesTab(); + QWidget* createVectorTab(QWidget* theParent); + //QWidget* createPlanesTab(); + + void savePlane(int thePlaneNb); + void showPlane(int thePlaneNb) const; + void setEmptyPlane(PlaneDef& thePlane) const; - QListView* myPlanesList; + //! returns number of main plane in the list myPlaneCombo. + //! If values are not correct returns -1 + //int getMainPlane(); + + + QListWidget* myPlanesList; QLineEdit* myNameEdt; VisuGUI* myModule; - QTabWidget* myMethodTab; + //QTabWidget* myMethodTab; + QWidget* myMethodTab; QtxDoubleSpinBox* myXOrigin; QtxDoubleSpinBox* myYOrigin; @@ -56,16 +94,20 @@ public: QtxDoubleSpinBox* myYDir; QtxDoubleSpinBox* myZDir; - QLabel* myRotationXLbl; - QLabel* myRotationYLbl; + //QLabel* myRotationXLbl; + //QLabel* myRotationYLbl; - QComboBox* myPlaneCombo; - QtxDoubleSpinBox* myDistance; - QtxDoubleSpinBox* myRotX; - QtxDoubleSpinBox* myRotY; + //QComboBox* myPlaneCombo; + //QtxDoubleSpinBox* myDistance; + //QtxDoubleSpinBox* myRotX; + //QtxDoubleSpinBox* myRotY; QCheckBox* myAutoApply; QCheckBox* myShowPreview; + + QListOfPlanes myPlanes; + SVTK_ViewWindow* myViewWindow; + int myCurrentPlane; }; #endif diff --git a/src/VISUGUI/VisuGUI_SegmentationMgr.cxx b/src/VISUGUI/VisuGUI_SegmentationMgr.cxx new file mode 100644 index 00000000..aeb4db90 --- /dev/null +++ b/src/VISUGUI/VisuGUI_SegmentationMgr.cxx @@ -0,0 +1,70 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : VisuGUI_SegmentationMgr.cxx +// Author : Vitaly Smetannikov +// Module : VISU + + +#include "VisuGUI_SegmentationMgr.h" + +#include + +VisuGUI_SegmentationMgr::VisuGUI_SegmentationMgr(VisuGUI* theModule) +{ +} + +VisuGUI_SegmentationMgr::~VisuGUI_SegmentationMgr() +{ +} + +const QListOfPlanes& VisuGUI_SegmentationMgr::getPlanes(SVTK_ViewWindow* theWindow) +{ + if (!myViewPlanesMap.contains(theWindow)) { + QListOfPlanes aNewList; + myViewPlanesMap[theWindow] = aNewList; + } + return myViewPlanesMap[theWindow]; +} + +void VisuGUI_SegmentationMgr::setPlanes(SVTK_ViewWindow* theWindow, const QListOfPlanes& theNewPlanes) +{ + myViewPlanesMap[theWindow] = theNewPlanes; +} + +void VisuGUI_SegmentationMgr::onAddActor(SVTK_ViewWindow*, VTKViewer_Actor*) +{ + printf("#### onAddActor\n"); +} + + +void VisuGUI_SegmentationMgr::onViewDeleted(SUIT_ViewWindow* theWindow) +{ + printf("#### onViewDeleted\n"); + SVTK_ViewWindow* aWindow = dynamic_cast(theWindow); + if (aWindow) { + if (myViewPlanesMap.contains(aWindow)) + myViewPlanesMap.remove(aWindow); + } +} + diff --git a/src/VISUGUI/VisuGUI_SegmentationMgr.h b/src/VISUGUI/VisuGUI_SegmentationMgr.h new file mode 100644 index 00000000..2e34b516 --- /dev/null +++ b/src/VISUGUI/VisuGUI_SegmentationMgr.h @@ -0,0 +1,71 @@ +// VISU VISUGUI : GUI of VISU component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : VisuGUI_SegmentationMgr.h +// Author : Vitaly Smetannikov +// Module : VISU +#ifndef VisuGUI_SegmentationMgr_HeaderFile +#define VisuGUI_SegmentationMgr_HeaderFile + +#include "VisuGUI_ClippingDlg.h" + +#include +#include +#include +#include +#include + + +struct PlaneDef +{ + double origin[3]; + double direction[3]; + bool isAuto; + QString name; +}; + + +typedef QList QListOfPlanes; + + +class VisuGUI_SegmentationMgr: public QObject +{ + Q_OBJECT +public: + + VisuGUI_SegmentationMgr(VisuGUI* theModule); + ~VisuGUI_SegmentationMgr(); + + const QListOfPlanes& getPlanes(SVTK_ViewWindow* theWindow); + void setPlanes(SVTK_ViewWindow* theWindow, const QListOfPlanes& theNewPlanes); + +private slots: + void onAddActor(SVTK_ViewWindow*, VTKViewer_Actor*); + void onViewDeleted(SUIT_ViewWindow*); + + private: + + QMap myViewPlanesMap; +}; + +#endif diff --git a/src/VISUGUI/VisuGUI_ViewExtender.cxx b/src/VISUGUI/VisuGUI_ViewExtender.cxx index c3273b6e..67eb0d24 100644 --- a/src/VISUGUI/VisuGUI_ViewExtender.cxx +++ b/src/VISUGUI/VisuGUI_ViewExtender.cxx @@ -29,12 +29,15 @@ #include "VisuGUI_ViewExtender.h" -// #include #include "VisuGUI_ClippingPlaneMgr.h" #include "VisuGUI.h" +#include "VisuGUI_SegmentationMgr.h" +#include "VisuGUI_ViewTools.h" #include #include +#include +#include #include #include @@ -46,6 +49,9 @@ VisuGUI_ViewExtender::VisuGUI_ViewExtender(VisuGUI* theModule): myModule(theModule), myNonModalDlg(0) { + mySegmentationMgr = new VisuGUI_SegmentationMgr(theModule); + + QtxAction* aAction; SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr(); aAction = new QtxAction(tr("MNU_CLIPPING_PLANE_MGR"), @@ -60,11 +66,12 @@ VisuGUI_ViewExtender::VisuGUI_ViewExtender(VisuGUI* theModule): VisuGUI_ViewExtender::~VisuGUI_ViewExtender() { + delete mySegmentationMgr; } int VisuGUI_ViewExtender::createToolbar(QtxActionToolMgr* theMgr) { - int aToolBar = theMgr->createToolBar( QObject::tr("VISU_VIEW_TOOLBAR")); + int aToolBar = theMgr->createToolBar( tr("VISU_VIEW_TOOLBAR")); theMgr->append( myActionsMap[ClippingPlaneMgrId], aToolBar ); return aToolBar; } @@ -76,16 +83,37 @@ void VisuGUI_ViewExtender::contextMenuPopup(QMenu* theMenu) void VisuGUI_ViewExtender::onPlanesMgr() { - myNonModalDlg = new VisuGUI_ClippingPlaneMgr(myModule); + if (myNonModalDlg) return; + + SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow(myModule); + if (!aViewWindow) return; + + VisuGUI_ClippingPlaneMgr* aDlg = + new VisuGUI_ClippingPlaneMgr(myModule, aViewWindow, mySegmentationMgr->getPlanes(aViewWindow)); + connect(aDlg, SIGNAL(applyPlanes()), this, SLOT(onApplyPlanes())); + + myNonModalDlg = aDlg; connect(myNonModalDlg, SIGNAL( destroyed(QObject*) ), this, SLOT( onDialogDestroy() )); myNonModalDlg->show(); } -void VisuGUI_ViewExtender::activate() +void VisuGUI_ViewExtender::activate(SUIT_ViewModel* theViewer) { + // Connect to signal on destroy ViewWindow + SVTK_Viewer* aViewer = dynamic_cast(theViewer); + if (aViewer) { + if (!myViewers.contains(aViewer)) { + SUIT_ViewManager* aMgr = aViewer->getViewManager(); + connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)), + mySegmentationMgr, SLOT(onViewDeleted(SUIT_ViewWindow*))); + connect(aViewer, SIGNAL(actorAdded(SVTK_ViewWindow*, VTKViewer_Actor*)), + mySegmentationMgr, SLOT(onAddActor(SVTK_ViewWindow*, VTKViewer_Actor*))); + myViewers.append(aViewer); + } + } } -void VisuGUI_ViewExtender::deactivate() +void VisuGUI_ViewExtender::deactivate(SUIT_ViewModel*) { if (myNonModalDlg) { myNonModalDlg->close(); @@ -98,3 +126,9 @@ void VisuGUI_ViewExtender::onDialogDestroy() disconnect(myNonModalDlg, SIGNAL( destroyed(QObject*) ), this, SLOT( onDialogDestroy() )); myNonModalDlg = 0; } + +void VisuGUI_ViewExtender::onApplyPlanes() +{ + VisuGUI_ClippingPlaneMgr* aDlg = (VisuGUI_ClippingPlaneMgr*) myNonModalDlg; + mySegmentationMgr->setPlanes(aDlg->getViewWindow(), aDlg->getPlanes()); +} diff --git a/src/VISUGUI/VisuGUI_ViewExtender.h b/src/VISUGUI/VisuGUI_ViewExtender.h index fc608a3d..909c0f31 100644 --- a/src/VISUGUI/VisuGUI_ViewExtender.h +++ b/src/VISUGUI/VisuGUI_ViewExtender.h @@ -37,6 +37,9 @@ class VisuGUI; class QtxAction; class QDialog; +class VisuGUI_SegmentationMgr; +class SVTK_Viewer; + class VisuGUI_ViewExtender: public QObject, public CAM_ViewExtender { Q_OBJECT @@ -49,12 +52,13 @@ class VisuGUI_ViewExtender: public QObject, public CAM_ViewExtender virtual int createToolbar(QtxActionToolMgr* theMgr); virtual void contextMenuPopup(QMenu* theMenu); - virtual void activate(); - virtual void deactivate(); + virtual void activate(SUIT_ViewModel*); + virtual void deactivate(SUIT_ViewModel*); private slots: void onPlanesMgr(); void onDialogDestroy(); + void onApplyPlanes(); private: enum { ClippingPlaneMgrId }; @@ -63,6 +67,10 @@ private slots: VisuGUI* myModule; QDialog* myNonModalDlg; + + VisuGUI_SegmentationMgr* mySegmentationMgr; + + QList myViewers; }; -- 2.39.2