1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : VisuGUI_CutPlanesDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_CutPlanesDlg.h"
31 #include "VISU_ColoredPrs3dFactory.hh"
34 #include "VisuGUI_Tools.h"
35 #include "VisuGUI_ViewTools.h"
36 #include "VisuGUI_InputPane.h"
38 #include "VISU_ColoredPrs3dFactory.hh"
39 #include "VISU_CutPlanes_i.hh"
40 #include "VISU_CutPlanesPL.hxx"
42 #include "OB_Browser.h"
44 #include "SVTK_ViewWindow.h"
46 #include "LightApp_Application.h"
48 #include "SUIT_Application.h"
49 #include "SUIT_Desktop.h"
50 #include "SUIT_ViewWindow.h"
51 #include "SUIT_ViewManager.h"
52 #include "SUIT_Session.h"
53 #include "SUIT_MessageBox.h"
54 #include "SUIT_ResourceMgr.h"
57 #include <qbuttongroup.h>
58 #include <qcheckbox.h>
61 #include <qvalidator.h>
62 #include <qlineedit.h>
63 #include <qtabwidget.h>
65 #include <qpushbutton.h>
67 #include <vtkRenderer.h>
68 #include <vtkPolyData.h>
69 #include <vtkAppendPolyData.h>
70 #include <vtkDataSetMapper.h>
74 //extern VisuGUI *visuGUI;
76 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent)
77 : QFrame(theParent), myPreviewActor(0)
79 QGridLayout* TopLayout = new QGridLayout(this);
80 TopLayout->setSpacing(6);
81 TopLayout->setMargin(10);
83 QButtonGroup* SelPlane = new QButtonGroup (tr("TXT_ORIENTATION"), this, "SelPlane");
84 //SelPlane->setTitle(tr("TXT_ORIENTATION"));
85 SelPlane->setColumnLayout(0, Qt::Vertical);
86 SelPlane->layout()->setSpacing( 0 );
87 SelPlane->layout()->setMargin( 0 );
88 QGridLayout* SelPlaneLayout = new QGridLayout( SelPlane->layout() );
89 SelPlaneLayout->setAlignment( Qt::AlignTop );
90 SelPlaneLayout->setSpacing( 6 );
91 SelPlaneLayout->setMargin( 11 );
93 RBxy = new QRadioButton (tr("PARALLEL_XOY"), SelPlane, "RBxy");
94 RByz = new QRadioButton (tr("PARALLEL_YOZ"), SelPlane, "RByz");
95 RBzx = new QRadioButton (tr("PARALLEL_ZOX"), SelPlane, "RBzx");
96 SelPlaneLayout->addWidget( RBxy, 0, 0 );
97 SelPlaneLayout->addWidget( RByz, 0, 1 );
98 SelPlaneLayout->addWidget( RBzx, 0, 2 );
100 QLabel* LabelPosi_3 = new QLabel (tr("LBL_NB_PLANS"), this, "LabelPosi_3");
102 nbPlan = new QSpinBox( 1, 100, 1, this, "nbPlan" );
103 nbPlan->setValue( 1 );
104 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
106 myPosTable = new QTable (this, "Positions of planes");
107 myPosTable->setMaximumHeight( 227 );
108 myPosTable->setMinimumWidth( 294 );
109 myPosTable->setNumCols(2);
110 myPosTable->setNumRows(0);
111 connect( myPosTable, SIGNAL(valueChanged(int, int)), this, SLOT(onValueChanged(int, int)) );
113 QHeader *th = myPosTable->horizontalHeader();
114 th->setLabel( 0, "Position" );
115 th->setLabel( 1, "Set default" );
116 th->setStyle("QStyle::CE_PushButton");
118 QGroupBox* GBrot = new QGroupBox (tr("LBL_ROTATION"), this, "GBrot");
119 GBrot->setColumnLayout(0, Qt::Vertical);
120 GBrot->layout()->setSpacing( 0 );
121 GBrot->layout()->setMargin( 0 );
122 QGridLayout* GBrotLayout = new QGridLayout( GBrot->layout() );
123 GBrotLayout->setAlignment( Qt::AlignTop );
124 GBrotLayout->setSpacing( 6 );
125 GBrotLayout->setMargin( 11 );
127 LabelRot1 = new QLabel (tr("LBL_ROT_X"), GBrot, "LabelRot1");
128 GBrotLayout->addWidget( LabelRot1, 0, 0 );
130 Rot1 = new QtxDblSpinBox( -180, 180, 10, GBrot );
132 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
133 connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
134 GBrotLayout->addWidget( Rot1, 0, 1 );
136 LabelRot2 = new QLabel (tr("LBL_ROT_Y"), GBrot, "LabelRot2");
137 GBrotLayout->addWidget( LabelRot2, 1, 0 );
139 Rot2 = new QtxDblSpinBox( -180, 180, 10, GBrot );
141 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
142 connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
143 GBrotLayout->addWidget( Rot2, 1, 1 );
145 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
146 myPosSpn = new QtxDblSpinBox( 0, 1, 0.1, this );
148 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
149 myPreviewCheck->setChecked(false);
150 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
152 TopLayout->addMultiCellWidget( SelPlane, 0, 0, 0, 1 );
153 TopLayout->addMultiCellWidget( GBrot, 1, 1, 0, 1 );
154 TopLayout->addWidget( LabelPosi_3, 2, 0 );
155 TopLayout->addWidget( nbPlan, 2, 1 );
156 TopLayout->addMultiCellWidget( myPosTable, 3, 3, 0, 1 );
157 TopLayout->setRowStretch ( 3, 3 );
158 TopLayout->addWidget(aPosLbl, 4, 0 );
159 TopLayout->addWidget(myPosSpn, 4, 1 );
160 TopLayout->addMultiCellWidget( myPreviewCheck, 5, 5, 0, 1 );
162 // signals and slots connections
163 connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) );
164 connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
165 connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
166 connect( th, SIGNAL( clicked(int)), this, SLOT( setDefault(int) ) );
173 RByz->setChecked( true );
175 } // End of Constructor
177 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
180 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
184 void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs)
186 setNbPlanes(thePrs->GetNbPlanes());
187 setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
188 setPlanePos(thePrs->GetOrientationType());
189 myPosSpn->setValue(thePrs->GetDisplacement());
192 myCutPlanes = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
193 myCutPlanes->SameAs(thePrs);
197 if (myPreviewCheck->isChecked()) {
202 void VisuGUI_CutPlanesPane::createPlanes()
204 if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
205 if (!myCutPlanes) return;
206 if (myPreviewActor != 0) return;
208 vtkAppendPolyData* aPolyData = myCutPlanes->GetSpecificPL()->GetAppendPolyData();
209 if (!aPolyData->GetOutput()->GetNumberOfCells()) {
210 onPreviewCheck(false);
213 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
214 aPlaneMapper->SetInput(aPolyData->GetOutput());
215 aPlaneMapper->ScalarVisibilityOff();
217 myPreviewActor = SALOME_Actor::New();
218 myPreviewActor->PickableOff();
219 myPreviewActor->SetMapper(aPlaneMapper);
220 aPlaneMapper->Delete();
221 VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
224 int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs)
226 thePrs->SetOrientation(getOrientaion(), getRotation1()*PI/180., getRotation2()*PI/180.);
227 thePrs->SetNbPlanes(getNbPlanes());
228 thePrs->SetDisplacement(myPosSpn->value());
229 for (int i = 0; i < getNbPlanes(); ++i) {
230 QCheckTableItem* anItem = (QCheckTableItem*)myPosTable->item(i, 1);
233 if (!anItem->isChecked())
234 thePrs->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
236 thePrs->SetDefault(i);
242 Called when orientation is changed
244 void VisuGUI_CutPlanesPane::orientationChanged (int Id)
246 if (Id == 0) { // RBxy->isChecked()
247 LabelRot1->setText(tr("LBL_ROT_X"));
248 LabelRot2->setText(tr("LBL_ROT_Y"));
249 } else if (Id == 1) { // RByz->isChecked()
250 LabelRot1->setText(tr("LBL_ROT_Y"));
251 LabelRot2->setText(tr("LBL_ROT_Z"));
253 LabelRot1->setText(tr("LBL_ROT_Z"));
254 LabelRot2->setText(tr("LBL_ROT_X"));
260 Sets planes orientation and position
262 void VisuGUI_CutPlanesPane::setPlanePos (const VISU::CutPlanes::Orientation orient)
264 if (orient == VISU::CutPlanes::XY) // xy
266 RBxy->setChecked( true );
267 orientationChanged( 0 );
269 else if (orient == VISU::CutPlanes::YZ) // yz
271 RByz->setChecked( true );
272 orientationChanged( 1 );
276 RBzx->setChecked( true );
277 orientationChanged( 2 );
283 Gets planes orientation
285 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
287 VISU::CutPlanes::Orientation orient;
288 if ( RBxy->isChecked() ) // xy
289 orient = VISU::CutPlanes::XY;
290 else if ( RByz->isChecked() ) // yz
291 orient = VISU::CutPlanes::YZ;
292 else if ( RBzx->isChecked() ) // zx
293 orient = VISU::CutPlanes::ZX;
300 void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2)
302 Rot1->setValue( r1 );
303 Rot2->setValue( r2 );
307 Draw the table of planes positions
309 void VisuGUI_CutPlanesPane::DrawTable()
311 if (!myCutPlanes) return;
312 if (!hasInit) return;
314 int aNbRows = myPosTable->numRows();
315 int aNbPlanes = getNbPlanes();
317 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
318 myCutPlanes->SetNbPlanes(aNbPlanes);
319 myCutPlanes->SetDisplacement(myPosSpn->value());
321 for (int i = 0; i < aNbRows; ++i) {
322 QCheckTableItem* aItem = (QCheckTableItem*)myPosTable->item( i, 1 );
323 if (aItem == 0) break;
324 if (!aItem->isChecked())
325 myCutPlanes->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
328 if (aNbPlanes > aNbRows)
329 myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
330 else if (aNbPlanes < aNbRows)
331 myPosTable->setNumRows(aNbPlanes);
333 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
334 for (int i = 0; i<aMin; i++) {
335 myPosTable->setText(i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
336 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(myCutPlanes->IsDefault(i));
339 QHeader *vh = myPosTable->verticalHeader();
340 QString str("Plane# %1");
341 for (int i=aMin; i<aNbPlanes; i++) {
342 VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem(myPosTable,
343 QTableItem::OnTyping,
344 QString::number(myCutPlanes->GetPlanePosition(i)));
345 aEditItem->setReplaceable(false);
346 aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
347 myPosTable->setItem(i, 0, aEditItem);
349 QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
350 aCheck->setChecked(myCutPlanes->IsDefault(i));
351 aCheck->setReplaceable(false);
352 myPosTable->setItem(i, 1, aCheck);
354 vh->setLabel( i, str.arg(i+1) );
358 if (myPreviewCheck->isChecked()) {
359 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
360 myCutPlanes->GetPipeLine()->Update();
368 void VisuGUI_CutPlanesPane::setDefault (int all)
370 myPosTable->setCurrentCell(-1, 1);
371 myPosTable->clearSelection();
372 if (all == 0) return;
374 for (int i = 0; i < getNbPlanes(); ++i)
375 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
377 for (int i = 0; i < getNbPlanes(); ++i) {
378 if ( ((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked() ) {
379 myCutPlanes->SetDefault(i);
380 myPosTable->setText( i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
381 myPosTable->item( i, 0 )->setEnabled(false);
383 myPosTable->item( i, 0 )->setEnabled(true);
387 void VisuGUI_CutPlanesPane::onValueChanged (int theRow, int theCol)
390 QString aTxt = myPosTable->text(theRow, 0);
391 bool isChanged = !aTxt.isEmpty();
392 ((QCheckTableItem*)myPosTable->item(theRow, 1))->setChecked(!isChanged);
394 if (myPreviewCheck->isChecked()) {
396 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
397 myCutPlanes->SetPlanePosition( theRow, aTxt.toDouble());
398 myCutPlanes->GetPipeLine()->Update();
405 bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked();
407 myCutPlanes->SetDefault(theRow);
408 myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
410 if (myPreviewCheck->isChecked()) {
411 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
413 myCutPlanes->GetPipeLine()->Update();
420 myPosTable->item(theRow, 0)->setEnabled(!isDefault);
424 void VisuGUI_CutPlanesPane::deletePlanes()
426 if (myPreviewActor == 0) return;
427 vtkRenderer* aRend = myPreviewActor->GetRenderer();
428 vtkRenderWindow* aWnd = aRend->GetRenderWindow();
431 myPreviewActor->RemoveFromRender(aRend);
432 // Bug IPAL11962: preview is still in the viewer, if viewer not active.
433 // if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
434 // vf->RemoveActor(myPreviewActor);
435 myPreviewActor->Delete();
439 void VisuGUI_CutPlanesPane::onRotation (double theValue)
441 if (!myCutPlanes) return;
442 if (myPreviewCheck->isChecked()) {
443 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
444 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
445 myCutPlanes->GetPipeLine()->Update();
453 void VisuGUI_CutPlanesPane::onPreviewCheck (bool thePreview)
455 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
457 storeToPrsObject(myCutPlanes);
458 myCutPlanes->GetPipeLine()->Update();
468 //###################################################################
474 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg (SalomeApp_Module* theModule)
475 : VisuGUI_ScalarBarBaseDlg(theModule)
477 setCaption("Cut Planes Definition");
478 setSizeGripEnabled(true);
480 QVBoxLayout* TopLayout = new QVBoxLayout (this);
481 TopLayout->setSpacing(6);
482 TopLayout->setMargin(11);
485 myTabBox = new QTabWidget(this);
486 myCutPane = new VisuGUI_CutPlanesPane(this/*, myMgr*/);
487 myTabBox->addTab(myCutPane, "Cut Planes");
488 myInputPane = new VisuGUI_InputPane(VISU::TCUTPLANES, theModule, this);
489 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
490 myTabBox->addTab(myInputPane, "Input");
492 TopLayout->addWidget(myTabBox);
494 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
495 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
496 GroupButtons->setTitle("");
497 GroupButtons->setColumnLayout(0, Qt::Vertical);
498 GroupButtons->layout()->setSpacing(0);
499 GroupButtons->layout()->setMargin(0);
500 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
501 GroupButtonsLayout->setAlignment(Qt::AlignTop);
502 GroupButtonsLayout->setSpacing(6);
503 GroupButtonsLayout->setMargin(11);
505 QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
506 buttonOk->setAutoDefault(TRUE);
507 buttonOk->setDefault(TRUE);
508 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
509 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
511 QPushButton* buttonCancel = new QPushButton(tr("&Cancel"), GroupButtons, "buttonCancel");
512 buttonCancel->setAutoDefault(TRUE);
513 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
515 QPushButton* buttonHelp = new QPushButton(tr("&Help"), GroupButtons, "buttonHelp");
516 buttonHelp->setAutoDefault(TRUE);
517 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
519 TopLayout->addWidget(GroupButtons);
521 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
522 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
523 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
526 VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
529 void VisuGUI_CutPlanesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
533 myPrsCopy = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
535 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
537 myCutPane->initFromPrsObject(myPrsCopy);
542 myInputPane->initFromPrsObject( myPrsCopy );
543 myTabBox->setCurrentPage( 0 );
546 int VisuGUI_CutPlanesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
548 if(!myInputPane->check() || !GetScalarPane()->check())
551 int anIsOk = myInputPane->storeToPrsObject(myPrsCopy);
552 anIsOk &= GetScalarPane()->storeToPrsObject(myPrsCopy);
553 anIsOk &= myCutPane->storeToPrsObject(myPrsCopy);
555 VISU::TSameAsFactory<VISU::TCUTPLANES>().Copy(myPrsCopy, thePrs);
560 void VisuGUI_CutPlanesDlg::accept()
562 VisuGUI_ScalarBarBaseDlg::accept();
565 void VisuGUI_CutPlanesDlg::reject()
567 VisuGUI_ScalarBarBaseDlg::reject();
570 QString VisuGUI_CutPlanesDlg::GetContextHelpFilePath()
572 return "cut_planes_page.html";
575 //###################################################################
577 QWidget* VisuGUI_NumEditItem::createEditor() const
579 QLineEdit *editline = new QLineEdit(text(), table()->viewport());
580 QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
581 dvalidator->setDecimals(32);
582 editline->setValidator(dvalidator);