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/*, SUIT_ViewManager* theMgr*/)
66 : QFrame(theParent), myPreviewActor(0)//, myMgr(theMgr)
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()
171 myCutPlanes->Destroy();
172 if (SVTK_ViewWindow* vf = VISU::GetViewWindow())
176 void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs)
178 setNbPlanes(thePrs->GetNbPlanes());
179 setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
180 setPlanePos(thePrs->GetOrientationType());
181 myPosSpn->setValue(thePrs->GetDisplacement());
184 myCutPlanes = new VISU::CutPlanes_i(thePrs->GetResult(),false);
185 myCutPlanes->SameAs(thePrs);
189 if (myPreviewCheck->isChecked()) {
194 void VisuGUI_CutPlanesPane::createPlanes()
196 if (VISU::GetViewWindow() == NULL) return;
197 if (myCutPlanes == NULL) return;
198 if (myPreviewActor != 0) return;
200 vtkAppendPolyData* aPolyData = myCutPlanes->GetCutPlanesPL()->GetAppendPolyData();
201 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
202 if (!aPolyData->GetOutput()->GetNumberOfCells()) {
203 onPreviewCheck(false);
206 aPlaneMapper->SetInput(aPolyData->GetOutput());
207 aPlaneMapper->ScalarVisibilityOff();
209 myPreviewActor = SALOME_Actor::New();
210 myPreviewActor->PickableOff();
211 myPreviewActor->SetMapper(aPlaneMapper);
212 aPlaneMapper->Delete();
213 VISU::GetViewWindow()->AddActor(myPreviewActor);
216 int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs)
218 thePrs->SetOrientation(getOrientaion(), getRotation1()*PI/180., getRotation2()*PI/180.);
219 thePrs->SetNbPlanes(getNbPlanes());
220 thePrs->SetDisplacement(myPosSpn->value());
221 for (int i = 0; i < getNbPlanes(); ++i) {
222 QCheckTableItem* anItem = (QCheckTableItem*)myPosTable->item(i, 1);
225 if (!anItem->isChecked())
226 thePrs->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
228 thePrs->SetDefault(i);
234 Called when orientation is changed
236 void VisuGUI_CutPlanesPane::orientationChanged (int Id)
238 if (Id == 0) { // RBxy->isChecked()
239 LabelRot1->setText(tr("LBL_ROT_X"));
240 LabelRot2->setText(tr("LBL_ROT_Y"));
241 } else if (Id == 1) { // RByz->isChecked()
242 LabelRot1->setText(tr("LBL_ROT_Y"));
243 LabelRot2->setText(tr("LBL_ROT_Z"));
245 LabelRot1->setText(tr("LBL_ROT_Z"));
246 LabelRot2->setText(tr("LBL_ROT_X"));
252 Sets planes orientation and position
254 void VisuGUI_CutPlanesPane::setPlanePos (const VISU::CutPlanes::Orientation orient)
256 if (orient == VISU::CutPlanes::XY) // xy
258 RBxy->setChecked( true );
259 orientationChanged( 0 );
261 else if (orient == VISU::CutPlanes::YZ) // yz
263 RByz->setChecked( true );
264 orientationChanged( 1 );
268 RBzx->setChecked( true );
269 orientationChanged( 2 );
275 Gets planes orientation
277 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
279 VISU::CutPlanes::Orientation orient;
280 if ( RBxy->isChecked() ) // xy
281 orient = VISU::CutPlanes::XY;
282 else if ( RByz->isChecked() ) // yz
283 orient = VISU::CutPlanes::YZ;
284 else if ( RBzx->isChecked() ) // zx
285 orient = VISU::CutPlanes::ZX;
292 void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2)
294 Rot1->setValue( r1 );
295 Rot2->setValue( r2 );
299 Draw the table of planes positions
301 void VisuGUI_CutPlanesPane::DrawTable()
303 if (myCutPlanes == NULL) return;
304 if (!hasInit) return;
306 int aNbRows = myPosTable->numRows();
307 int aNbPlanes = getNbPlanes();
309 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
310 myCutPlanes->SetNbPlanes(aNbPlanes);
311 myCutPlanes->SetDisplacement(myPosSpn->value());
313 for (int i = 0; i < aNbRows; ++i) {
314 QCheckTableItem* aItem = (QCheckTableItem*)myPosTable->item( i, 1 );
315 if (aItem == 0) break;
316 if (!aItem->isChecked())
317 myCutPlanes->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
320 if (aNbPlanes > aNbRows)
321 myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
322 else if (aNbPlanes < aNbRows)
323 myPosTable->setNumRows(aNbPlanes);
325 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
326 for (int i = 0; i<aMin; i++) {
327 myPosTable->setText(i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
328 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(myCutPlanes->IsDefault(i));
331 QHeader *vh = myPosTable->verticalHeader();
332 QString str("Plane# %1");
333 for (int i=aMin; i<aNbPlanes; i++) {
334 VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem(myPosTable,
335 QTableItem::OnTyping,
336 QString::number(myCutPlanes->GetPlanePosition(i)));
337 aEditItem->setReplaceable(false);
338 aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
339 myPosTable->setItem(i, 0, aEditItem);
341 QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
342 aCheck->setChecked(myCutPlanes->IsDefault(i));
343 aCheck->setReplaceable(false);
344 myPosTable->setItem(i, 1, aCheck);
346 vh->setLabel( i, str.arg(i+1) );
350 if (myPreviewCheck->isChecked()) {
351 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
352 myCutPlanes->GetPL()->Update();
360 void VisuGUI_CutPlanesPane::setDefault (int all)
362 myPosTable->setCurrentCell(-1, 1);
363 myPosTable->clearSelection();
364 if (all == 0) return;
366 for (int i = 0; i < getNbPlanes(); ++i)
367 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
369 for (int i = 0; i < getNbPlanes(); ++i) {
370 if ( ((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked() ) {
371 myCutPlanes->SetDefault(i);
372 myPosTable->setText( i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
373 myPosTable->item( i, 0 )->setEnabled(false);
375 myPosTable->item( i, 0 )->setEnabled(true);
379 void VisuGUI_CutPlanesPane::onValueChanged (int theRow, int theCol)
382 QString aTxt = myPosTable->text(theRow, 0);
383 bool isChanged = !aTxt.isEmpty();
384 ((QCheckTableItem*)myPosTable->item(theRow, 1))->setChecked(!isChanged);
386 if (myPreviewCheck->isChecked()) {
388 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
389 myCutPlanes->SetPlanePosition( theRow, aTxt.toDouble());
390 myCutPlanes->GetPL()->Update();
397 bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked();
399 myCutPlanes->SetDefault(theRow);
400 myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
402 if (myPreviewCheck->isChecked()) {
403 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
405 myCutPlanes->GetPL()->Update();
412 myPosTable->item(theRow, 0)->setEnabled(!isDefault);
416 void VisuGUI_CutPlanesPane::deletePlanes()
418 if (myPreviewActor == 0) return;
419 if (SVTK_ViewWindow* vf = VISU::GetViewWindow())
420 vf->RemoveActor(myPreviewActor);
421 myPreviewActor->Delete();
425 void VisuGUI_CutPlanesPane::onRotation (double theValue)
427 if (myCutPlanes == NULL) return;
428 if (myPreviewCheck->isChecked()) {
429 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
430 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
431 myCutPlanes->GetPL()->Update();
439 void VisuGUI_CutPlanesPane::onPreviewCheck (bool thePreview)
441 if (SVTK_ViewWindow* vf = VISU::GetViewWindow()) {
443 storeToPrsObject(myCutPlanes);
444 myCutPlanes->GetPL()->Update();
454 //###################################################################
460 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg (QWidget* parent, bool theIsCreation, bool theIsModal)
461 : QDialog(parent, "VisuGUI_CutPlanesDlg", theIsModal, WStyle_Customize |
462 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
463 //,myMgr(VisuGUI::application()->activeViewManager())
465 //myStudyWnd = myMgr->getActiveView();
467 setWFlags(getWFlags() | WDestructiveClose);
469 setCaption("Cut Planes Definition");
470 setSizeGripEnabled(true);
471 myIsCreation = theIsCreation;
473 QVBoxLayout* TopLayout = new QVBoxLayout (this);
474 TopLayout->setSpacing(6);
475 TopLayout->setMargin(11);
478 QTabWidget* aTabBox = new QTabWidget(this);
479 myCutPane = new VisuGUI_CutPlanesPane(this/*, myMgr*/);
480 aTabBox->addTab(myCutPane, "Cut Planes");
481 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
482 myScalarPane->setMargin(5);
483 aTabBox->addTab(myScalarPane, "Scalar Bar");
485 TopLayout->addWidget(aTabBox);
487 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
488 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
489 GroupButtons->setTitle("");
490 GroupButtons->setColumnLayout(0, Qt::Vertical);
491 GroupButtons->layout()->setSpacing(0);
492 GroupButtons->layout()->setMargin(0);
493 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
494 GroupButtonsLayout->setAlignment(Qt::AlignTop);
495 GroupButtonsLayout->setSpacing(6);
496 GroupButtonsLayout->setMargin(11);
498 QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
499 buttonOk->setAutoDefault(TRUE);
500 buttonOk->setDefault(TRUE);
501 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
502 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
504 QPushButton* buttonCancel = new QPushButton(tr("&Cancel"), GroupButtons, "buttonCancel");
505 buttonCancel->setAutoDefault(TRUE);
506 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
508 TopLayout->addWidget(GroupButtons);
510 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
511 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
512 //connect(myMgr, SIGNAL(closeAllViews()), this, SLOT(reject()));
513 //connect(VisuGUI::application()->desktop(),
514 // SIGNAL(windowActivated(SUIT_ViewWindow*)),
515 // this, SLOT(onWindowActivated(SUIT_ViewWindow*)));
518 void VisuGUI_CutPlanesDlg::initFromPrsObject (VISU::CutPlanes_i* thePrs)
521 myScalarPane->initFromPrsObject(thePrs);
522 myCutPane->initFromPrsObject(thePrs);
525 int VisuGUI_CutPlanesDlg::storeToPrsObject (VISU::CutPlanes_i* thePrs)
527 return (myScalarPane->storeToPrsObject(thePrs) &&
528 myCutPane->storeToPrsObject(thePrs));
531 void VisuGUI_CutPlanesDlg::accept()
533 if (myScalarPane->check())
537 void VisuGUI_CutPlanesDlg::reject() {
541 //void VisuGUI_CutPlanesDlg::onWindowActivated (SUIT_ViewWindow* theWnd)
543 // if (theWnd != myStudyWnd)
547 //###################################################################
549 QWidget* VisuGUI_NumEditItem::createEditor() const
551 QLineEdit *editline = new QLineEdit(text(), table()->viewport());
552 QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
553 dvalidator->setDecimals(32);
554 editline->setValidator(dvalidator);