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"
33 #include "VisuGUI_ViewTools.h"
35 #include "VISU_CutPlanes_i.hh"
36 #include "VISU_CutPlanesPL.hxx"
38 #include "OB_Browser.h"
40 #include "SVTK_ViewWindow.h"
42 #include "LightApp_Application.h"
44 #include "SUIT_Application.h"
45 #include "SUIT_Desktop.h"
46 #include "SUIT_ViewWindow.h"
47 #include "SUIT_ViewManager.h"
48 #include "SUIT_Session.h"
49 #include "SUIT_MessageBox.h"
50 #include "SUIT_ResourceMgr.h"
53 #include <qcheckbox.h>
56 #include <qvalidator.h>
57 #include <qlineedit.h>
58 #include <qtabwidget.h>
60 #include <vtkRenderer.h>
61 #include <vtkPolyData.h>
62 #include <vtkAppendPolyData.h>
63 #include <vtkDataSetMapper.h>
67 //extern VisuGUI *visuGUI;
69 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent)
70 : QFrame(theParent), myPreviewActor(0)
72 QGridLayout* TopLayout = new QGridLayout( this );
73 TopLayout->setSpacing( 6 );
74 TopLayout->setMargin( 10 );
76 QButtonGroup* SelPlane = new QButtonGroup (tr("TXT_ORIENTATION"), this, "SelPlane");
77 //SelPlane->setTitle(tr("TXT_ORIENTATION"));
78 SelPlane->setColumnLayout(0, Qt::Vertical);
79 SelPlane->layout()->setSpacing( 0 );
80 SelPlane->layout()->setMargin( 0 );
81 QGridLayout* SelPlaneLayout = new QGridLayout( SelPlane->layout() );
82 SelPlaneLayout->setAlignment( Qt::AlignTop );
83 SelPlaneLayout->setSpacing( 6 );
84 SelPlaneLayout->setMargin( 11 );
86 RBxy = new QRadioButton (tr("PARALLEL_XOY"), SelPlane, "RBxy");
87 RByz = new QRadioButton (tr("PARALLEL_YOZ"), SelPlane, "RByz");
88 RBzx = new QRadioButton (tr("PARALLEL_ZOX"), SelPlane, "RBzx");
89 SelPlaneLayout->addWidget( RBxy, 0, 0 );
90 SelPlaneLayout->addWidget( RByz, 0, 1 );
91 SelPlaneLayout->addWidget( RBzx, 0, 2 );
93 QLabel* LabelPosi_3 = new QLabel (tr("LBL_NB_PLANS"), this, "LabelPosi_3");
95 nbPlan = new QSpinBox( 1, 100, 1, this, "nbPlan" );
96 nbPlan->setValue( 1 );
97 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
99 myPosTable = new QTable (this, "Positions of planes");
100 myPosTable->setMaximumHeight( 227 );
101 myPosTable->setMinimumWidth( 294 );
102 myPosTable->setNumCols(2);
103 myPosTable->setNumRows(0);
104 connect( myPosTable, SIGNAL(valueChanged(int, int)), this, SLOT(onValueChanged(int, int)) );
106 QHeader *th = myPosTable->horizontalHeader();
107 th->setLabel( 0, "Position" );
108 th->setLabel( 1, "Set default" );
109 th->setStyle("QStyle::CE_PushButton");
111 QGroupBox* GBrot = new QGroupBox (tr("LBL_ROTATION"), this, "GBrot");
112 GBrot->setColumnLayout(0, Qt::Vertical);
113 GBrot->layout()->setSpacing( 0 );
114 GBrot->layout()->setMargin( 0 );
115 QGridLayout* GBrotLayout = new QGridLayout( GBrot->layout() );
116 GBrotLayout->setAlignment( Qt::AlignTop );
117 GBrotLayout->setSpacing( 6 );
118 GBrotLayout->setMargin( 11 );
120 LabelRot1 = new QLabel (tr("LBL_ROT_X"), GBrot, "LabelRot1");
121 GBrotLayout->addWidget( LabelRot1, 0, 0 );
123 Rot1 = new QtxDblSpinBox( -180, 180, 10, GBrot );
125 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
126 connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
127 GBrotLayout->addWidget( Rot1, 0, 1 );
129 LabelRot2 = new QLabel (tr("LBL_ROT_Y"), GBrot, "LabelRot2");
130 GBrotLayout->addWidget( LabelRot2, 1, 0 );
132 Rot2 = new QtxDblSpinBox( -180, 180, 10, GBrot );
134 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
135 connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
136 GBrotLayout->addWidget( Rot2, 1, 1 );
138 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
139 myPosSpn = new QtxDblSpinBox( 0, 1, 0.1, this );
141 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
142 myPreviewCheck->setChecked(false);
143 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
145 TopLayout->addMultiCellWidget( SelPlane, 0, 0, 0, 1 );
146 TopLayout->addMultiCellWidget( GBrot, 1, 1, 0, 1 );
147 TopLayout->addWidget( LabelPosi_3, 2, 0 );
148 TopLayout->addWidget( nbPlan, 2, 1 );
149 TopLayout->addMultiCellWidget( myPosTable, 3, 3, 0, 1 );
150 TopLayout->setRowStretch ( 3, 3 );
151 TopLayout->addWidget(aPosLbl, 4, 0 );
152 TopLayout->addWidget(myPosSpn, 4, 1 );
153 TopLayout->addMultiCellWidget( myPreviewCheck, 5, 5, 0, 1 );
155 // signals and slots connections
156 connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) );
157 connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
158 connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
159 connect( th, SIGNAL( clicked(int)), this, SLOT( setDefault(int) ) );
167 RByz->setChecked( true );
169 } // End of Constructor
171 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
175 myCutPlanes->Destroy();
176 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
180 void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs)
182 setNbPlanes(thePrs->GetNbPlanes());
183 setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
184 setPlanePos(thePrs->GetOrientationType());
185 myPosSpn->setValue(thePrs->GetDisplacement());
188 myCutPlanes = new VISU::CutPlanes_i(thePrs->GetResult(),false);
189 myCutPlanes->SameAs(thePrs);
193 if (myPreviewCheck->isChecked()) {
198 void VisuGUI_CutPlanesPane::createPlanes()
200 if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
201 if (myCutPlanes == NULL) return;
202 if (myPreviewActor != 0) return;
204 vtkAppendPolyData* aPolyData = myCutPlanes->GetCutPlanesPL()->GetAppendPolyData();
205 if (!aPolyData->GetOutput()->GetNumberOfCells()) {
206 onPreviewCheck(false);
209 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
210 aPlaneMapper->SetInput(aPolyData->GetOutput());
211 aPlaneMapper->ScalarVisibilityOff();
213 myPreviewActor = SALOME_Actor::New();
214 myPreviewActor->PickableOff();
215 myPreviewActor->SetMapper(aPlaneMapper);
216 aPlaneMapper->Delete();
217 VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
220 int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs)
222 thePrs->SetOrientation(getOrientaion(), getRotation1()*PI/180., getRotation2()*PI/180.);
223 thePrs->SetNbPlanes(getNbPlanes());
224 thePrs->SetDisplacement(myPosSpn->value());
225 for (int i = 0; i < getNbPlanes(); ++i) {
226 QCheckTableItem* anItem = (QCheckTableItem*)myPosTable->item(i, 1);
229 if (!anItem->isChecked())
230 thePrs->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
232 thePrs->SetDefault(i);
238 Called when orientation is changed
240 void VisuGUI_CutPlanesPane::orientationChanged (int Id)
242 if (Id == 0) { // RBxy->isChecked()
243 LabelRot1->setText(tr("LBL_ROT_X"));
244 LabelRot2->setText(tr("LBL_ROT_Y"));
245 } else if (Id == 1) { // RByz->isChecked()
246 LabelRot1->setText(tr("LBL_ROT_Y"));
247 LabelRot2->setText(tr("LBL_ROT_Z"));
249 LabelRot1->setText(tr("LBL_ROT_Z"));
250 LabelRot2->setText(tr("LBL_ROT_X"));
256 Sets planes orientation and position
258 void VisuGUI_CutPlanesPane::setPlanePos (const VISU::CutPlanes::Orientation orient)
260 if (orient == VISU::CutPlanes::XY) // xy
262 RBxy->setChecked( true );
263 orientationChanged( 0 );
265 else if (orient == VISU::CutPlanes::YZ) // yz
267 RByz->setChecked( true );
268 orientationChanged( 1 );
272 RBzx->setChecked( true );
273 orientationChanged( 2 );
279 Gets planes orientation
281 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
283 VISU::CutPlanes::Orientation orient;
284 if ( RBxy->isChecked() ) // xy
285 orient = VISU::CutPlanes::XY;
286 else if ( RByz->isChecked() ) // yz
287 orient = VISU::CutPlanes::YZ;
288 else if ( RBzx->isChecked() ) // zx
289 orient = VISU::CutPlanes::ZX;
296 void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2)
298 Rot1->setValue( r1 );
299 Rot2->setValue( r2 );
303 Draw the table of planes positions
305 void VisuGUI_CutPlanesPane::DrawTable()
307 if (myCutPlanes == NULL) return;
308 if (!hasInit) return;
310 int aNbRows = myPosTable->numRows();
311 int aNbPlanes = getNbPlanes();
313 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
314 myCutPlanes->SetNbPlanes(aNbPlanes);
315 myCutPlanes->SetDisplacement(myPosSpn->value());
317 for (int i = 0; i < aNbRows; ++i) {
318 QCheckTableItem* aItem = (QCheckTableItem*)myPosTable->item( i, 1 );
319 if (aItem == 0) break;
320 if (!aItem->isChecked())
321 myCutPlanes->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
324 if (aNbPlanes > aNbRows)
325 myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
326 else if (aNbPlanes < aNbRows)
327 myPosTable->setNumRows(aNbPlanes);
329 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
330 for (int i = 0; i<aMin; i++) {
331 myPosTable->setText(i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
332 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(myCutPlanes->IsDefault(i));
335 QHeader *vh = myPosTable->verticalHeader();
336 QString str("Plane# %1");
337 for (int i=aMin; i<aNbPlanes; i++) {
338 VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem(myPosTable,
339 QTableItem::OnTyping,
340 QString::number(myCutPlanes->GetPlanePosition(i)));
341 aEditItem->setReplaceable(false);
342 aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
343 myPosTable->setItem(i, 0, aEditItem);
345 QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
346 aCheck->setChecked(myCutPlanes->IsDefault(i));
347 aCheck->setReplaceable(false);
348 myPosTable->setItem(i, 1, aCheck);
350 vh->setLabel( i, str.arg(i+1) );
354 if (myPreviewCheck->isChecked()) {
355 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
356 myCutPlanes->GetPL()->Update();
364 void VisuGUI_CutPlanesPane::setDefault (int all)
366 myPosTable->setCurrentCell(-1, 1);
367 myPosTable->clearSelection();
368 if (all == 0) return;
370 for (int i = 0; i < getNbPlanes(); ++i)
371 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
373 for (int i = 0; i < getNbPlanes(); ++i) {
374 if ( ((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked() ) {
375 myCutPlanes->SetDefault(i);
376 myPosTable->setText( i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
377 myPosTable->item( i, 0 )->setEnabled(false);
379 myPosTable->item( i, 0 )->setEnabled(true);
383 void VisuGUI_CutPlanesPane::onValueChanged (int theRow, int theCol)
386 QString aTxt = myPosTable->text(theRow, 0);
387 bool isChanged = !aTxt.isEmpty();
388 ((QCheckTableItem*)myPosTable->item(theRow, 1))->setChecked(!isChanged);
390 if (myPreviewCheck->isChecked()) {
392 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
393 myCutPlanes->SetPlanePosition( theRow, aTxt.toDouble());
394 myCutPlanes->GetPL()->Update();
401 bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked();
403 myCutPlanes->SetDefault(theRow);
404 myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
406 if (myPreviewCheck->isChecked()) {
407 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
409 myCutPlanes->GetPL()->Update();
416 myPosTable->item(theRow, 0)->setEnabled(!isDefault);
420 void VisuGUI_CutPlanesPane::deletePlanes()
422 if (myPreviewActor == 0) return;
423 vtkRenderer* aRend = myPreviewActor->GetRenderer();
425 myPreviewActor->RemoveFromRender(aRend);
426 // Bug IPAL11962: preview is still in the viewer, if viewer not active.
427 // if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
428 // vf->RemoveActor(myPreviewActor);
429 myPreviewActor->Delete();
433 void VisuGUI_CutPlanesPane::onRotation (double theValue)
435 if (myCutPlanes == NULL) return;
436 if (myPreviewCheck->isChecked()) {
437 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
438 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
439 myCutPlanes->GetPL()->Update();
447 void VisuGUI_CutPlanesPane::onPreviewCheck (bool thePreview)
449 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
451 storeToPrsObject(myCutPlanes);
452 myCutPlanes->GetPL()->Update();
462 //###################################################################
468 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg (SalomeApp_Module* theModule)
469 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_CutPlanesDlg", false,
470 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
472 setCaption("Cut Planes Definition");
473 setSizeGripEnabled(true);
475 QVBoxLayout* TopLayout = new QVBoxLayout (this);
476 TopLayout->setSpacing(6);
477 TopLayout->setMargin(11);
480 QTabWidget* aTabBox = new QTabWidget(this);
481 myCutPane = new VisuGUI_CutPlanesPane(this/*, myMgr*/);
482 aTabBox->addTab(myCutPane, "Cut Planes");
483 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
484 myScalarPane->setMargin(5);
485 aTabBox->addTab(myScalarPane, "Scalar Bar");
487 TopLayout->addWidget(aTabBox);
489 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
490 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
491 GroupButtons->setTitle("");
492 GroupButtons->setColumnLayout(0, Qt::Vertical);
493 GroupButtons->layout()->setSpacing(0);
494 GroupButtons->layout()->setMargin(0);
495 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
496 GroupButtonsLayout->setAlignment(Qt::AlignTop);
497 GroupButtonsLayout->setSpacing(6);
498 GroupButtonsLayout->setMargin(11);
500 QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
501 buttonOk->setAutoDefault(TRUE);
502 buttonOk->setDefault(TRUE);
503 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
504 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
506 QPushButton* buttonCancel = new QPushButton(tr("&Cancel"), GroupButtons, "buttonCancel");
507 buttonCancel->setAutoDefault(TRUE);
508 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
510 QPushButton* buttonHelp = new QPushButton(tr("&Help"), GroupButtons, "buttonHelp");
511 buttonHelp->setAutoDefault(TRUE);
512 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
514 TopLayout->addWidget(GroupButtons);
516 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
517 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
518 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
519 //connect(myMgr, SIGNAL(closeAllViews()), this, SLOT(reject()));
520 //connect(VisuGUI::application()->desktop(),
521 // SIGNAL(windowActivated(SUIT_ViewWindow*)),
522 // this, SLOT(onWindowActivated(SUIT_ViewWindow*)));
525 void VisuGUI_CutPlanesDlg::initFromPrsObject (VISU::CutPlanes_i* thePrs)
528 myScalarPane->initFromPrsObject(thePrs);
529 myCutPane->initFromPrsObject(thePrs);
532 int VisuGUI_CutPlanesDlg::storeToPrsObject (VISU::CutPlanes_i* thePrs)
534 return (myScalarPane->storeToPrsObject(thePrs) &&
535 myCutPane->storeToPrsObject(thePrs));
538 void VisuGUI_CutPlanesDlg::accept()
540 //if ( !VisuGUI::CheckActiveStudyLock() ) {
544 if (myScalarPane->check())
546 myScalarPane->deletePreview();
551 void VisuGUI_CutPlanesDlg::reject() {
552 myScalarPane->deletePreview();
556 void VisuGUI_CutPlanesDlg::onHelp()
558 QString aHelpFileName = "/files/cut_lines_resentation.htm";
559 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
561 VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
562 app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
565 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
566 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
567 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
568 QObject::tr("BUT_OK"));
572 //void VisuGUI_CutPlanesDlg::onWindowActivated (SUIT_ViewWindow* theWnd)
574 // if (theWnd != myStudyWnd)
578 //###################################################################
580 QWidget* VisuGUI_NumEditItem::createEditor() const
582 QLineEdit *editline = new QLineEdit(text(), table()->viewport());
583 QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
584 dvalidator->setDecimals(32);
585 editline->setValidator(dvalidator);