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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_CutPlanesDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_CutPlanesDlg.h"
32 #include "VisuGUI_Tools.h"
34 #include "VISU_CutPlanes_i.hh"
35 #include "VISU_CutPlanesPL.hxx"
37 #include "OB_Browser.h"
39 #include "SVTK_ViewWindow.h"
41 #include "SalomeApp_Application.h"
43 #include "SUIT_Application.h"
44 #include "SUIT_Desktop.h"
45 #include "SUIT_ViewWindow.h"
46 #include "SUIT_ViewManager.h"
49 #include <qcheckbox.h>
52 #include <qvalidator.h>
53 #include <qlineedit.h>
54 #include <qtabwidget.h>
56 #include <vtkRenderer.h>
57 #include <vtkPolyData.h>
58 #include <vtkAppendPolyData.h>
59 #include <vtkDataSetMapper.h>
63 //extern VisuGUI *visuGUI;
65 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent)
66 : QFrame(theParent), myPreviewActor(0)
68 QGridLayout* TopLayout = new QGridLayout( this );
69 TopLayout->setSpacing( 6 );
70 TopLayout->setMargin( 10 );
72 QButtonGroup* SelPlane = new QButtonGroup (tr("TXT_ORIENTATION"), this, "SelPlane");
73 //SelPlane->setTitle(tr("TXT_ORIENTATION"));
74 SelPlane->setColumnLayout(0, Qt::Vertical);
75 SelPlane->layout()->setSpacing( 0 );
76 SelPlane->layout()->setMargin( 0 );
77 QGridLayout* SelPlaneLayout = new QGridLayout( SelPlane->layout() );
78 SelPlaneLayout->setAlignment( Qt::AlignTop );
79 SelPlaneLayout->setSpacing( 6 );
80 SelPlaneLayout->setMargin( 11 );
82 RBxy = new QRadioButton (tr("PARALLEL_XOY"), SelPlane, "RBxy");
83 RByz = new QRadioButton (tr("PARALLEL_YOZ"), SelPlane, "RByz");
84 RBzx = new QRadioButton (tr("PARALLEL_ZOX"), SelPlane, "RBzx");
85 SelPlaneLayout->addWidget( RBxy, 0, 0 );
86 SelPlaneLayout->addWidget( RByz, 0, 1 );
87 SelPlaneLayout->addWidget( RBzx, 0, 2 );
89 QLabel* LabelPosi_3 = new QLabel (tr("LBL_NB_PLANS"), this, "LabelPosi_3");
91 nbPlan = new QSpinBox( 1, 100, 1, this, "nbPlan" );
92 nbPlan->setValue( 1 );
93 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
95 myPosTable = new QTable (this, "Positions of planes");
96 myPosTable->setMaximumHeight( 227 );
97 myPosTable->setMinimumWidth( 294 );
98 myPosTable->setNumCols(2);
99 myPosTable->setNumRows(0);
100 connect( myPosTable, SIGNAL(valueChanged(int, int)), this, SLOT(onValueChanged(int, int)) );
102 QHeader *th = myPosTable->horizontalHeader();
103 th->setLabel( 0, "Position" );
104 th->setLabel( 1, "Set default" );
105 th->setStyle("QStyle::CE_PushButton");
107 QGroupBox* GBrot = new QGroupBox (tr("LBL_ROTATION"), this, "GBrot");
108 GBrot->setColumnLayout(0, Qt::Vertical);
109 GBrot->layout()->setSpacing( 0 );
110 GBrot->layout()->setMargin( 0 );
111 QGridLayout* GBrotLayout = new QGridLayout( GBrot->layout() );
112 GBrotLayout->setAlignment( Qt::AlignTop );
113 GBrotLayout->setSpacing( 6 );
114 GBrotLayout->setMargin( 11 );
116 LabelRot1 = new QLabel (tr("LBL_ROT_X"), GBrot, "LabelRot1");
117 GBrotLayout->addWidget( LabelRot1, 0, 0 );
119 Rot1 = new QtxDblSpinBox( -180, 180, 10, GBrot );
121 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
122 connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
123 GBrotLayout->addWidget( Rot1, 0, 1 );
125 LabelRot2 = new QLabel (tr("LBL_ROT_Y"), GBrot, "LabelRot2");
126 GBrotLayout->addWidget( LabelRot2, 1, 0 );
128 Rot2 = new QtxDblSpinBox( -180, 180, 10, GBrot );
130 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
131 connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
132 GBrotLayout->addWidget( Rot2, 1, 1 );
134 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
135 myPosSpn = new QtxDblSpinBox( 0, 1, 0.1, this );
137 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
138 myPreviewCheck->setChecked(false);
139 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
141 TopLayout->addMultiCellWidget( SelPlane, 0, 0, 0, 1 );
142 TopLayout->addMultiCellWidget( GBrot, 1, 1, 0, 1 );
143 TopLayout->addWidget( LabelPosi_3, 2, 0 );
144 TopLayout->addWidget( nbPlan, 2, 1 );
145 TopLayout->addMultiCellWidget( myPosTable, 3, 3, 0, 1 );
146 TopLayout->setRowStretch ( 3, 3 );
147 TopLayout->addWidget(aPosLbl, 4, 0 );
148 TopLayout->addWidget(myPosSpn, 4, 1 );
149 TopLayout->addMultiCellWidget( myPreviewCheck, 5, 5, 0, 1 );
151 // signals and slots connections
152 connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) );
153 connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
154 connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
155 connect( th, SIGNAL( clicked(int)), this, SLOT( setDefault(int) ) );
163 RByz->setChecked( true );
165 } // End of Constructor
167 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
169 cout<<"### VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane"<<endl;
172 myCutPlanes->Destroy();
173 if (SVTK_ViewWindow* vf = VISU::GetViewWindow())
177 void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs)
179 setNbPlanes(thePrs->GetNbPlanes());
180 setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
181 setPlanePos(thePrs->GetOrientationType());
182 myPosSpn->setValue(thePrs->GetDisplacement());
185 myCutPlanes = new VISU::CutPlanes_i(thePrs->GetResult(),false);
186 myCutPlanes->SameAs(thePrs);
190 if (myPreviewCheck->isChecked()) {
195 void VisuGUI_CutPlanesPane::createPlanes()
197 if (VISU::GetViewWindow() == NULL) return;
198 if (myCutPlanes == NULL) return;
199 if (myPreviewActor != 0) return;
201 vtkAppendPolyData* aPolyData = myCutPlanes->GetCutPlanesPL()->GetAppendPolyData();
202 if (!aPolyData->GetOutput()->GetNumberOfCells()) {
203 onPreviewCheck(false);
206 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
207 aPlaneMapper->SetInput(aPolyData->GetOutput());
208 aPlaneMapper->ScalarVisibilityOff();
210 myPreviewActor = SALOME_Actor::New();
211 myPreviewActor->PickableOff();
212 myPreviewActor->SetMapper(aPlaneMapper);
213 aPlaneMapper->Delete();
214 VISU::GetViewWindow()->AddActor(myPreviewActor);
217 int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs)
219 thePrs->SetOrientation(getOrientaion(), getRotation1()*PI/180., getRotation2()*PI/180.);
220 thePrs->SetNbPlanes(getNbPlanes());
221 thePrs->SetDisplacement(myPosSpn->value());
222 for (int i = 0; i < getNbPlanes(); ++i) {
223 QCheckTableItem* anItem = (QCheckTableItem*)myPosTable->item(i, 1);
226 if (!anItem->isChecked())
227 thePrs->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
229 thePrs->SetDefault(i);
235 Called when orientation is changed
237 void VisuGUI_CutPlanesPane::orientationChanged (int Id)
239 if (Id == 0) { // RBxy->isChecked()
240 LabelRot1->setText(tr("LBL_ROT_X"));
241 LabelRot2->setText(tr("LBL_ROT_Y"));
242 } else if (Id == 1) { // RByz->isChecked()
243 LabelRot1->setText(tr("LBL_ROT_Y"));
244 LabelRot2->setText(tr("LBL_ROT_Z"));
246 LabelRot1->setText(tr("LBL_ROT_Z"));
247 LabelRot2->setText(tr("LBL_ROT_X"));
253 Sets planes orientation and position
255 void VisuGUI_CutPlanesPane::setPlanePos (const VISU::CutPlanes::Orientation orient)
257 if (orient == VISU::CutPlanes::XY) // xy
259 RBxy->setChecked( true );
260 orientationChanged( 0 );
262 else if (orient == VISU::CutPlanes::YZ) // yz
264 RByz->setChecked( true );
265 orientationChanged( 1 );
269 RBzx->setChecked( true );
270 orientationChanged( 2 );
276 Gets planes orientation
278 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
280 VISU::CutPlanes::Orientation orient;
281 if ( RBxy->isChecked() ) // xy
282 orient = VISU::CutPlanes::XY;
283 else if ( RByz->isChecked() ) // yz
284 orient = VISU::CutPlanes::YZ;
285 else if ( RBzx->isChecked() ) // zx
286 orient = VISU::CutPlanes::ZX;
293 void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2)
295 Rot1->setValue( r1 );
296 Rot2->setValue( r2 );
300 Draw the table of planes positions
302 void VisuGUI_CutPlanesPane::DrawTable()
304 if (myCutPlanes == NULL) return;
305 if (!hasInit) return;
307 int aNbRows = myPosTable->numRows();
308 int aNbPlanes = getNbPlanes();
310 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
311 myCutPlanes->SetNbPlanes(aNbPlanes);
312 myCutPlanes->SetDisplacement(myPosSpn->value());
314 for (int i = 0; i < aNbRows; ++i) {
315 QCheckTableItem* aItem = (QCheckTableItem*)myPosTable->item( i, 1 );
316 if (aItem == 0) break;
317 if (!aItem->isChecked())
318 myCutPlanes->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
321 if (aNbPlanes > aNbRows)
322 myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
323 else if (aNbPlanes < aNbRows)
324 myPosTable->setNumRows(aNbPlanes);
326 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
327 for (int i = 0; i<aMin; i++) {
328 myPosTable->setText(i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
329 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(myCutPlanes->IsDefault(i));
332 QHeader *vh = myPosTable->verticalHeader();
333 QString str("Plane# %1");
334 for (int i=aMin; i<aNbPlanes; i++) {
335 VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem(myPosTable,
336 QTableItem::OnTyping,
337 QString::number(myCutPlanes->GetPlanePosition(i)));
338 aEditItem->setReplaceable(false);
339 aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
340 myPosTable->setItem(i, 0, aEditItem);
342 QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
343 aCheck->setChecked(myCutPlanes->IsDefault(i));
344 aCheck->setReplaceable(false);
345 myPosTable->setItem(i, 1, aCheck);
347 vh->setLabel( i, str.arg(i+1) );
351 if (myPreviewCheck->isChecked()) {
352 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
353 myCutPlanes->GetPL()->Update();
361 void VisuGUI_CutPlanesPane::setDefault (int all)
363 myPosTable->setCurrentCell(-1, 1);
364 myPosTable->clearSelection();
365 if (all == 0) return;
367 for (int i = 0; i < getNbPlanes(); ++i)
368 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
370 for (int i = 0; i < getNbPlanes(); ++i) {
371 if ( ((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked() ) {
372 myCutPlanes->SetDefault(i);
373 myPosTable->setText( i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
374 myPosTable->item( i, 0 )->setEnabled(false);
376 myPosTable->item( i, 0 )->setEnabled(true);
380 void VisuGUI_CutPlanesPane::onValueChanged (int theRow, int theCol)
383 QString aTxt = myPosTable->text(theRow, 0);
384 bool isChanged = !aTxt.isEmpty();
385 ((QCheckTableItem*)myPosTable->item(theRow, 1))->setChecked(!isChanged);
387 if (myPreviewCheck->isChecked()) {
389 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
390 myCutPlanes->SetPlanePosition( theRow, aTxt.toDouble());
391 myCutPlanes->GetPL()->Update();
398 bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked();
400 myCutPlanes->SetDefault(theRow);
401 myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
403 if (myPreviewCheck->isChecked()) {
404 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
406 myCutPlanes->GetPL()->Update();
413 myPosTable->item(theRow, 0)->setEnabled(!isDefault);
417 void VisuGUI_CutPlanesPane::deletePlanes()
419 if (myPreviewActor == 0) return;
420 if (SVTK_ViewWindow* vf = VISU::GetViewWindow())
421 vf->RemoveActor(myPreviewActor);
422 myPreviewActor->Delete();
426 void VisuGUI_CutPlanesPane::onRotation (double theValue)
428 if (myCutPlanes == NULL) return;
429 if (myPreviewCheck->isChecked()) {
430 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
431 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
432 myCutPlanes->GetPL()->Update();
440 void VisuGUI_CutPlanesPane::onPreviewCheck (bool thePreview)
442 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
444 storeToPrsObject(myCutPlanes);
445 myCutPlanes->GetPL()->Update();
455 //###################################################################
461 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg (SalomeApp_Module* theModule)
462 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_CutPlanesDlg", true,
463 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
465 setCaption("Cut Planes Definition");
466 setSizeGripEnabled(true);
468 QVBoxLayout* TopLayout = new QVBoxLayout (this);
469 TopLayout->setSpacing(6);
470 TopLayout->setMargin(11);
473 QTabWidget* aTabBox = new QTabWidget(this);
474 myCutPane = new VisuGUI_CutPlanesPane(this/*, myMgr*/);
475 aTabBox->addTab(myCutPane, "Cut Planes");
476 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
477 myScalarPane->setMargin(5);
478 aTabBox->addTab(myScalarPane, "Scalar Bar");
480 TopLayout->addWidget(aTabBox);
482 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
483 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
484 GroupButtons->setTitle("");
485 GroupButtons->setColumnLayout(0, Qt::Vertical);
486 GroupButtons->layout()->setSpacing(0);
487 GroupButtons->layout()->setMargin(0);
488 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
489 GroupButtonsLayout->setAlignment(Qt::AlignTop);
490 GroupButtonsLayout->setSpacing(6);
491 GroupButtonsLayout->setMargin(11);
493 QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
494 buttonOk->setAutoDefault(TRUE);
495 buttonOk->setDefault(TRUE);
496 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
497 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
499 QPushButton* buttonCancel = new QPushButton(tr("&Cancel"), GroupButtons, "buttonCancel");
500 buttonCancel->setAutoDefault(TRUE);
501 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
503 TopLayout->addWidget(GroupButtons);
505 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
506 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
507 //connect(myMgr, SIGNAL(closeAllViews()), this, SLOT(reject()));
508 //connect(VisuGUI::application()->desktop(),
509 // SIGNAL(windowActivated(SUIT_ViewWindow*)),
510 // this, SLOT(onWindowActivated(SUIT_ViewWindow*)));
513 void VisuGUI_CutPlanesDlg::initFromPrsObject (VISU::CutPlanes_i* thePrs)
516 myScalarPane->initFromPrsObject(thePrs);
517 myCutPane->initFromPrsObject(thePrs);
520 int VisuGUI_CutPlanesDlg::storeToPrsObject (VISU::CutPlanes_i* thePrs)
522 return (myScalarPane->storeToPrsObject(thePrs) &&
523 myCutPane->storeToPrsObject(thePrs));
526 void VisuGUI_CutPlanesDlg::accept()
528 //if ( !VisuGUI::CheckActiveStudyLock() ) {
532 if (myScalarPane->check())
536 void VisuGUI_CutPlanesDlg::reject() {
540 //void VisuGUI_CutPlanesDlg::onWindowActivated (SUIT_ViewWindow* theWnd)
542 // if (theWnd != myStudyWnd)
546 //###################################################################
548 QWidget* VisuGUI_NumEditItem::createEditor() const
550 QLineEdit *editline = new QLineEdit(text(), table()->viewport());
551 QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
552 dvalidator->setDecimals(32);
553 editline->setValidator(dvalidator);