#include "VisuGUI.h"
#include "VisuGUI_Tools.h"
+#include <LightApp_Application.h>
#include <SUIT_Desktop.h>
+#include <SUIT_Session.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_ResourceMgr.h>
#include <QtxDoubleSpinBox.h>
#include <QVBoxLayout>
#include <QHBoxLayout>
-#include <QListView>
+#include <QListWidget>
#include <QLineEdit>
#include <QTabWidget>
#include <QWidget>
#include <QCheckBox>
#include <QPushButton>
+#include <vtkMath.h>
+
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);
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);
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);
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();
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 );
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"));
+ }
}
+