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"
30 #include "VISU_CutPlanes_i.hh"
31 #include "VISU_CutPlanesPL.hxx"
34 #include "VTKViewer_ViewFrame.h"
36 #include "QAD_Application.h"
37 #include "QAD_Desktop.h"
38 #include "QAD_RightFrame.h"
41 #include <qcheckbox.h>
44 #include <qvalidator.h>
45 #include <qlineedit.h>
46 #include <qtabwidget.h>
48 #include <vtkRenderer.h>
49 #include <vtkAppendPolyData.h>
50 #include <vtkDataSetMapper.h>
53 #define GET_VTK_VIEWFRAME(aStudy) dynamic_cast<VTKViewer_ViewFrame*>(aStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())
57 extern VisuGUI *visuGUI;
59 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane(QWidget* theParent, QAD_Study* theStudy)
60 :QFrame(theParent), myPreviewActor(0),myStudy(theStudy)
62 QGridLayout* TopLayout = new QGridLayout( this );
63 TopLayout->setSpacing( 6 );
64 TopLayout->setMargin( 10 );
66 QButtonGroup* SelPlane = new QButtonGroup( tr( "Orientation" ), this, "SelPlane" );
67 SelPlane->setTitle( tr( "Orientation" ) );
68 SelPlane->setColumnLayout(0, Qt::Vertical );
69 SelPlane->layout()->setSpacing( 0 );
70 SelPlane->layout()->setMargin( 0 );
71 QGridLayout* SelPlaneLayout = new QGridLayout( SelPlane->layout() );
72 SelPlaneLayout->setAlignment( Qt::AlignTop );
73 SelPlaneLayout->setSpacing( 6 );
74 SelPlaneLayout->setMargin( 11 );
76 RBxy = new QRadioButton( tr( "// X-Y" ), SelPlane, "RBxy" );
77 RByz = new QRadioButton( tr( "// Y-Z" ), SelPlane, "RByz" );
78 RBzx = new QRadioButton( tr( "// Z-X" ), SelPlane, "RBzx" );
79 SelPlaneLayout->addWidget( RBxy, 0, 0 );
80 SelPlaneLayout->addWidget( RByz, 0, 1 );
81 SelPlaneLayout->addWidget( RBzx, 0, 2 );
83 QLabel* LabelPosi_3 = new QLabel( tr( "Number of planes:" ), this, "LabelPosi_3" );
85 nbPlan = new QSpinBox( 1, 100, 1, this, "nbPlan" );
86 nbPlan->setValue( 1 );
87 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
89 myPosTable = new QTable(this, "Positions of planes" );
90 myPosTable->setMaximumHeight( 227 );
91 myPosTable->setMinimumWidth( 294 );
92 myPosTable->setNumCols(2);
93 myPosTable->setNumRows(0);
94 connect( myPosTable, SIGNAL(valueChanged(int, int)), this, SLOT(onValueChanged(int, int)) );
96 QHeader *th = myPosTable->horizontalHeader();
97 th->setLabel( 0, "Position" );
98 th->setLabel( 1, "Set default" );
99 th->setStyle("QStyle::CE_PushButton");
101 QGroupBox* GBrot = new QGroupBox( tr( "Rotations" ), this, "GBrot" );
102 GBrot->setColumnLayout(0, Qt::Vertical );
103 GBrot->layout()->setSpacing( 0 );
104 GBrot->layout()->setMargin( 0 );
105 QGridLayout* GBrotLayout = new QGridLayout( GBrot->layout() );
106 GBrotLayout->setAlignment( Qt::AlignTop );
107 GBrotLayout->setSpacing( 6 );
108 GBrotLayout->setMargin( 11 );
110 LabelRot1 = new QLabel( tr( "Rotation around X (Y to Z):" ), GBrot, "LabelRot1" );
111 GBrotLayout->addWidget( LabelRot1, 0, 0 );
113 Rot1 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
115 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
116 connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
117 GBrotLayout->addWidget( Rot1, 0, 1 );
119 LabelRot2 = new QLabel( tr( "Rotation around Y (Z to X):" ), GBrot, "LabelRot2" );
120 GBrotLayout->addWidget( LabelRot2, 1, 0 );
122 Rot2 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
124 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
125 connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
126 GBrotLayout->addWidget( Rot2, 1, 1 );
128 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
129 myPosSpn = new QAD_SpinBoxDbl( this, 0, 1, 0.1 );
131 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
132 myPreviewCheck->setChecked(false);
133 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
135 TopLayout->addMultiCellWidget( SelPlane, 0, 0, 0, 1 );
136 TopLayout->addMultiCellWidget( GBrot, 1, 1, 0, 1 );
137 TopLayout->addWidget( LabelPosi_3, 2, 0 );
138 TopLayout->addWidget( nbPlan, 2, 1 );
139 TopLayout->addMultiCellWidget( myPosTable, 3, 3, 0, 1 );
140 TopLayout->setRowStretch ( 3, 3 );
141 TopLayout->addWidget(aPosLbl, 4, 0 );
142 TopLayout->addWidget(myPosSpn, 4, 1 );
143 TopLayout->addMultiCellWidget( myPreviewCheck, 5, 5, 0, 1 );
145 // signals and slots connections
146 connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) );
147 connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
148 connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
149 connect( th, SIGNAL( clicked(int)), this, SLOT( setDefault(int) ) );
157 RByz->setChecked( true );
159 } // End of Constructor
162 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
165 if(myCutPlanes) myCutPlanes->Destroy();
166 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy))
171 void VisuGUI_CutPlanesPane::initFromPrsObject(VISU::CutPlanes_i* thePrs) {
172 setNbPlanes(thePrs->GetNbPlanes());
173 setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
174 setPlanePos(thePrs->GetOrientationType());
175 myPosSpn->setValue(thePrs->GetDisplacement());
178 myCutPlanes = new VISU::CutPlanes_i(thePrs->GetResult(),false);
179 myCutPlanes->SameAs(thePrs);
183 if (myPreviewCheck->isChecked()) {
189 void VisuGUI_CutPlanesPane::createPlanes() {
190 if (myStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) return;
191 if (myCutPlanes == NULL) return;
192 if (myPreviewActor != 0) return;
194 vtkAppendPolyData* aPolyData = myCutPlanes->GetCutPlanesPL()->GetAppendPolyData();
195 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
196 if (!aPolyData->GetOutput()->GetNumberOfCells()) {
197 onPreviewCheck(false);
200 aPlaneMapper->SetInput(aPolyData->GetOutput());
201 aPlaneMapper->ScalarVisibilityOff();
203 myPreviewActor = SALOME_Actor::New();
204 myPreviewActor->PickableOff();
205 myPreviewActor->SetMapper(aPlaneMapper);
206 aPlaneMapper->Delete();
207 GET_VTK_VIEWFRAME(myStudy)->AddActor(myPreviewActor);
212 int VisuGUI_CutPlanesPane::storeToPrsObject(VISU::CutPlanes_i* thePrs) {
213 thePrs->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
214 thePrs->SetNbPlanes(getNbPlanes());
215 thePrs->SetDisplacement(myPosSpn->value());
216 for (int i = 0; i < getNbPlanes(); ++i)
218 if (!((QCheckTableItem*)myPosTable->item(i, 1))->isChecked())
219 thePrs->SetPlanePosition( i, myPosTable->text(i, 0).toDouble());
220 else thePrs->SetDefault(i);
227 Called when orientation is changed
229 void VisuGUI_CutPlanesPane::orientationChanged( int Id )
231 if ( Id == 0 ) { // RBxy->isChecked()
232 LabelRot1->setText( tr( "Rotation around X (Y to Z):" ) );
233 LabelRot2->setText( tr( "Rotation around Y (Z to X):" ) );
234 } else if ( Id == 1 ) { // RByz->isChecked()
235 LabelRot1->setText( tr( "Rotation around Y (Z to X):" ) );
236 LabelRot2->setText( tr( "Rotation around Z (X to Y):" ) );
238 LabelRot1->setText( tr( "Rotation around Z (X to Y):" ) );
239 LabelRot2->setText( tr( "Rotation around X (Y to Z):" ) );
248 Sets planes orientation and position
250 void VisuGUI_CutPlanesPane::setPlanePos( const VISU::CutPlanes::Orientation orient)
252 if ( orient == VISU::CutPlanes::XY ) // xy
254 RBxy->setChecked( true );
255 orientationChanged( 0 );
257 else if ( orient == VISU::CutPlanes::YZ ) // yz
259 RByz->setChecked( true );
260 orientationChanged( 1 );
264 RBzx->setChecked( true );
265 orientationChanged( 2 );
271 Gets planes orientation
273 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
275 VISU::CutPlanes::Orientation orient;
276 if ( RBxy->isChecked() ) // xy
277 orient = VISU::CutPlanes::XY;
278 else if ( RByz->isChecked() ) // yz
279 orient = VISU::CutPlanes::YZ;
280 else if ( RBzx->isChecked() ) // zx
281 orient = VISU::CutPlanes::ZX;
288 void VisuGUI_CutPlanesPane::setRotation( const double r1, const double r2 )
290 Rot1->setValue( r1 );
291 Rot2->setValue( r2 );
295 Draw the table of planes positions
298 void VisuGUI_CutPlanesPane::DrawTable()
300 if (myCutPlanes == NULL) return;
301 if (!hasInit) return;
303 int aNbRows = myPosTable->numRows();
304 int aNbPlanes = getNbPlanes();
306 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
307 myCutPlanes->SetNbPlanes(aNbPlanes);
308 myCutPlanes->SetDisplacement(myPosSpn->value());
310 for (int i = 0; i < aNbRows; ++i) {
311 QCheckTableItem* aItem = (QCheckTableItem*)myPosTable->item( i, 1 );
312 if (aItem == 0) break;
313 if (!aItem->isChecked())
314 myCutPlanes->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
317 if (aNbPlanes > aNbRows)
318 myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
319 else if (aNbPlanes < aNbRows)
320 myPosTable->setNumRows(aNbPlanes);
322 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
323 for (int i = 0; i<aMin; i++) {
324 myPosTable->setText(i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
325 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(myCutPlanes->IsDefault(i));
328 QHeader *vh = myPosTable->verticalHeader();
329 QString str("Plane# %1");
330 for (int i=aMin; i<aNbPlanes; i++) {
331 VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem(myPosTable,
332 QTableItem::OnTyping,
333 QString::number(myCutPlanes->GetPlanePosition(i)));
334 aEditItem->setReplaceable(false);
335 aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
336 myPosTable->setItem(i, 0, aEditItem);
338 QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
339 aCheck->setChecked(myCutPlanes->IsDefault(i));
340 aCheck->setReplaceable(false);
341 myPosTable->setItem(i, 1, aCheck);
343 vh->setLabel( i, str.arg(i+1) );
347 if (myPreviewCheck->isChecked()) {
348 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
349 myCutPlanes->GetPL()->Update();
357 void VisuGUI_CutPlanesPane::setDefault(int all)
359 myPosTable->setCurrentCell(-1, 1);
360 myPosTable->clearSelection();
361 if (all == 0) return;
363 for (int i = 0; i < getNbPlanes(); ++i)
364 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
366 for (int i = 0; i < getNbPlanes(); ++i) {
367 if ( ((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked() ) {
368 myCutPlanes->SetDefault(i);
369 myPosTable->setText( i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
370 myPosTable->item( i, 0 )->setEnabled(false);
372 myPosTable->item( i, 0 )->setEnabled(true);
376 void VisuGUI_CutPlanesPane::onValueChanged(int theRow, int theCol) {
378 QString aTxt = myPosTable->text(theRow, 0);
379 bool isChanged = !aTxt.isEmpty();
380 ((QCheckTableItem*)myPosTable->item(theRow, 1))->setChecked(!isChanged);
382 if (myPreviewCheck->isChecked()) {
384 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
385 myCutPlanes->SetPlanePosition( theRow, aTxt.toDouble());
386 myCutPlanes->GetPL()->Update();
393 bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked();
395 myCutPlanes->SetDefault(theRow);
396 myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
398 if (myPreviewCheck->isChecked()) {
399 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
401 myCutPlanes->GetPL()->Update();
408 myPosTable->item(theRow, 0)->setEnabled(!isDefault);
413 void VisuGUI_CutPlanesPane::deletePlanes() {
414 if (myPreviewActor == 0) return;
415 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy))
416 vf->RemoveActor(myPreviewActor);
417 myPreviewActor->Delete();
421 void VisuGUI_CutPlanesPane::onRotation(double theValue) {
422 if (myCutPlanes == NULL) return;
423 if (myPreviewCheck->isChecked()) {
424 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
425 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
426 myCutPlanes->GetPL()->Update();
435 void VisuGUI_CutPlanesPane::onPreviewCheck(bool thePreview) {
436 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
438 storeToPrsObject(myCutPlanes);
439 myCutPlanes->GetPL()->Update();
452 //###################################################################
459 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg(bool theIsCreation, bool theIsModal)
460 : QDialog( QAD_Application::getDesktop(), "VisuGUI_CutPlanesDlg", theIsModal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu/* | WDestructiveClose */),
461 myStudy(QAD_Application::getDesktop()->getActiveStudy())
463 myStudyFrame = myStudy -> getActiveStudyFrame();
465 setWFlags(getWFlags() | WDestructiveClose);
467 setCaption( tr( "Cut Planes Definition" ) );
468 setSizeGripEnabled( TRUE );
469 myIsCreation = theIsCreation;
471 QVBoxLayout* TopLayout = new QVBoxLayout( this );
472 TopLayout->setSpacing( 6 );
473 TopLayout->setMargin( 11 );
475 QTabWidget* aTabBox = new QTabWidget(this);
476 myCutPane = new VisuGUI_CutPlanesPane(this, myStudy);
477 aTabBox->addTab(myCutPane, "Cut Planes");
478 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
479 myScalarPane->setMargin( 5 );
480 aTabBox->addTab(myScalarPane, "Scalar Bar");
482 TopLayout->addWidget(aTabBox);
484 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
485 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
486 GroupButtons->setTitle( tr( "" ) );
487 GroupButtons->setColumnLayout(0, Qt::Vertical );
488 GroupButtons->layout()->setSpacing( 0 );
489 GroupButtons->layout()->setMargin( 0 );
490 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
491 GroupButtonsLayout->setAlignment( Qt::AlignTop );
492 GroupButtonsLayout->setSpacing( 6 );
493 GroupButtonsLayout->setMargin( 11 );
495 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
496 buttonOk->setAutoDefault( TRUE );
497 buttonOk->setDefault( TRUE );
498 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
499 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
501 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons, "buttonCancel" );
502 buttonCancel->setAutoDefault( TRUE );
503 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
505 TopLayout->addWidget(GroupButtons);
507 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
508 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
509 connect( myStudy, SIGNAL(closed()), this, SLOT( reject() ) );
510 connect( myStudyFrame, SIGNAL(sfStudyFrameActivated(QAD_StudyFrame*)), this, SLOT(onFrameActivated(QAD_StudyFrame*)));
514 void VisuGUI_CutPlanesDlg::accept() {
515 if (myScalarPane->check()) {
517 if (storeToPrsObject(myPrs)) {
519 if (myStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
521 visuGUI->CreateActor(myPrs);
527 GET_VTK_VIEWFRAME(myStudy)->onViewFitAll();
530 visuGUI->RecreateActor(myPrs);
531 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
532 if ( vf->getRenderer()->GetActors()->GetNumberOfItems () > 0 ) {
533 vf->getRenderer()->ResetCameraClippingRange();
540 visuGUI->DeletePresentation(myPrs);
548 void VisuGUI_CutPlanesDlg::reject() {
549 if (myIsCreation && (!isModal())) {
550 visuGUI->DeletePresentation(myPrs);
551 myStudy -> updateObjBrowser();
556 void VisuGUI_CutPlanesDlg::onFrameActivated( QAD_StudyFrame* theFrame) {
557 if (theFrame != myStudyFrame)
561 //###################################################################
565 QWidget* VisuGUI_NumEditItem::createEditor() const
567 QLineEdit *editline = new QLineEdit(text(), table()->viewport());
568 QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
569 dvalidator->setDecimals(32);
570 editline->setValidator(dvalidator);