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 <vtkPolyData.h>
50 #include <vtkAppendPolyData.h>
51 #include <vtkDataSetMapper.h>
54 #define GET_VTK_VIEWFRAME(aStudy) dynamic_cast<VTKViewer_ViewFrame*>(aStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())
58 extern VisuGUI *visuGUI;
60 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane(QWidget* theParent, QAD_Study* theStudy)
61 :QFrame(theParent), myPreviewActor(0),myStudy(theStudy)
63 QGridLayout* TopLayout = new QGridLayout( this );
64 TopLayout->setSpacing( 6 );
65 TopLayout->setMargin( 10 );
67 QButtonGroup* SelPlane = new QButtonGroup( tr( "Orientation" ), this, "SelPlane" );
68 SelPlane->setTitle( tr( "Orientation" ) );
69 SelPlane->setColumnLayout(0, Qt::Vertical );
70 SelPlane->layout()->setSpacing( 0 );
71 SelPlane->layout()->setMargin( 0 );
72 QGridLayout* SelPlaneLayout = new QGridLayout( SelPlane->layout() );
73 SelPlaneLayout->setAlignment( Qt::AlignTop );
74 SelPlaneLayout->setSpacing( 6 );
75 SelPlaneLayout->setMargin( 11 );
77 RBxy = new QRadioButton( tr( "// X-Y" ), SelPlane, "RBxy" );
78 RByz = new QRadioButton( tr( "// Y-Z" ), SelPlane, "RByz" );
79 RBzx = new QRadioButton( tr( "// Z-X" ), SelPlane, "RBzx" );
80 SelPlaneLayout->addWidget( RBxy, 0, 0 );
81 SelPlaneLayout->addWidget( RByz, 0, 1 );
82 SelPlaneLayout->addWidget( RBzx, 0, 2 );
84 QLabel* LabelPosi_3 = new QLabel( tr( "Number of planes:" ), this, "LabelPosi_3" );
86 nbPlan = new QSpinBox( 1, 100, 1, this, "nbPlan" );
87 nbPlan->setValue( 1 );
88 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
90 myPosTable = new QTable(this, "Positions of planes" );
91 myPosTable->setMaximumHeight( 227 );
92 myPosTable->setMinimumWidth( 294 );
93 myPosTable->setNumCols(2);
94 myPosTable->setNumRows(0);
95 connect( myPosTable, SIGNAL(valueChanged(int, int)), this, SLOT(onValueChanged(int, int)) );
97 QHeader *th = myPosTable->horizontalHeader();
98 th->setLabel( 0, "Position" );
99 th->setLabel( 1, "Set default" );
100 th->setStyle("QStyle::CE_PushButton");
102 QGroupBox* GBrot = new QGroupBox( tr( "Rotations" ), this, "GBrot" );
103 GBrot->setColumnLayout(0, Qt::Vertical );
104 GBrot->layout()->setSpacing( 0 );
105 GBrot->layout()->setMargin( 0 );
106 QGridLayout* GBrotLayout = new QGridLayout( GBrot->layout() );
107 GBrotLayout->setAlignment( Qt::AlignTop );
108 GBrotLayout->setSpacing( 6 );
109 GBrotLayout->setMargin( 11 );
111 LabelRot1 = new QLabel( tr( "Rotation around X (Y to Z):" ), GBrot, "LabelRot1" );
112 GBrotLayout->addWidget( LabelRot1, 0, 0 );
114 Rot1 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
116 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
117 connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
118 GBrotLayout->addWidget( Rot1, 0, 1 );
120 LabelRot2 = new QLabel( tr( "Rotation around Y (Z to X):" ), GBrot, "LabelRot2" );
121 GBrotLayout->addWidget( LabelRot2, 1, 0 );
123 Rot2 = new QAD_SpinBoxDbl( GBrot, -180, 180, 10 );
125 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
126 connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
127 GBrotLayout->addWidget( Rot2, 1, 1 );
129 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
130 myPosSpn = new QAD_SpinBoxDbl( this, 0, 1, 0.1 );
132 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
133 myPreviewCheck->setChecked(false);
134 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
136 TopLayout->addMultiCellWidget( SelPlane, 0, 0, 0, 1 );
137 TopLayout->addMultiCellWidget( GBrot, 1, 1, 0, 1 );
138 TopLayout->addWidget( LabelPosi_3, 2, 0 );
139 TopLayout->addWidget( nbPlan, 2, 1 );
140 TopLayout->addMultiCellWidget( myPosTable, 3, 3, 0, 1 );
141 TopLayout->setRowStretch ( 3, 3 );
142 TopLayout->addWidget(aPosLbl, 4, 0 );
143 TopLayout->addWidget(myPosSpn, 4, 1 );
144 TopLayout->addMultiCellWidget( myPreviewCheck, 5, 5, 0, 1 );
146 // signals and slots connections
147 connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) );
148 connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
149 connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
150 connect( th, SIGNAL( clicked(int)), this, SLOT( setDefault(int) ) );
158 RByz->setChecked( true );
160 } // End of Constructor
163 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
166 if(myCutPlanes) myCutPlanes->Destroy();
167 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy))
172 void VisuGUI_CutPlanesPane::initFromPrsObject(VISU::CutPlanes_i* thePrs) {
173 setNbPlanes(thePrs->GetNbPlanes());
174 setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
175 setPlanePos(thePrs->GetOrientationType());
176 myPosSpn->setValue(thePrs->GetDisplacement());
179 myCutPlanes = new VISU::CutPlanes_i(thePrs->GetResult(),false);
180 myCutPlanes->SameAs(thePrs);
184 if (myPreviewCheck->isChecked()) {
190 void VisuGUI_CutPlanesPane::createPlanes() {
191 if (myStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) return;
192 if (myCutPlanes == NULL) return;
193 if (myPreviewActor != 0) return;
195 vtkAppendPolyData* aPolyData = myCutPlanes->GetCutPlanesPL()->GetAppendPolyData();
196 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
197 if (!aPolyData->GetOutput()->GetNumberOfCells()) {
198 onPreviewCheck(false);
201 aPlaneMapper->SetInput(aPolyData->GetOutput());
202 aPlaneMapper->ScalarVisibilityOff();
204 myPreviewActor = SALOME_Actor::New();
205 myPreviewActor->PickableOff();
206 myPreviewActor->SetMapper(aPlaneMapper);
207 aPlaneMapper->Delete();
208 GET_VTK_VIEWFRAME(myStudy)->AddActor(myPreviewActor);
213 int VisuGUI_CutPlanesPane::storeToPrsObject(VISU::CutPlanes_i* thePrs) {
214 thePrs->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
215 thePrs->SetNbPlanes(getNbPlanes());
216 thePrs->SetDisplacement(myPosSpn->value());
217 for (int i = 0; i < getNbPlanes(); ++i)
219 if (!((QCheckTableItem*)myPosTable->item(i, 1))->isChecked())
220 thePrs->SetPlanePosition( i, myPosTable->text(i, 0).toDouble());
221 else thePrs->SetDefault(i);
228 Called when orientation is changed
230 void VisuGUI_CutPlanesPane::orientationChanged( int Id )
232 if ( Id == 0 ) { // RBxy->isChecked()
233 LabelRot1->setText( tr( "Rotation around X (Y to Z):" ) );
234 LabelRot2->setText( tr( "Rotation around Y (Z to X):" ) );
235 } else if ( Id == 1 ) { // RByz->isChecked()
236 LabelRot1->setText( tr( "Rotation around Y (Z to X):" ) );
237 LabelRot2->setText( tr( "Rotation around Z (X to Y):" ) );
239 LabelRot1->setText( tr( "Rotation around Z (X to Y):" ) );
240 LabelRot2->setText( tr( "Rotation around X (Y to Z):" ) );
249 Sets planes orientation and position
251 void VisuGUI_CutPlanesPane::setPlanePos( const VISU::CutPlanes::Orientation orient)
253 if ( orient == VISU::CutPlanes::XY ) // xy
255 RBxy->setChecked( true );
256 orientationChanged( 0 );
258 else if ( orient == VISU::CutPlanes::YZ ) // yz
260 RByz->setChecked( true );
261 orientationChanged( 1 );
265 RBzx->setChecked( true );
266 orientationChanged( 2 );
272 Gets planes orientation
274 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
276 VISU::CutPlanes::Orientation orient;
277 if ( RBxy->isChecked() ) // xy
278 orient = VISU::CutPlanes::XY;
279 else if ( RByz->isChecked() ) // yz
280 orient = VISU::CutPlanes::YZ;
281 else if ( RBzx->isChecked() ) // zx
282 orient = VISU::CutPlanes::ZX;
289 void VisuGUI_CutPlanesPane::setRotation( const double r1, const double r2 )
291 Rot1->setValue( r1 );
292 Rot2->setValue( r2 );
296 Draw the table of planes positions
299 void VisuGUI_CutPlanesPane::DrawTable()
301 if (myCutPlanes == NULL) return;
302 if (!hasInit) return;
304 int aNbRows = myPosTable->numRows();
305 int aNbPlanes = getNbPlanes();
307 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
308 myCutPlanes->SetNbPlanes(aNbPlanes);
309 myCutPlanes->SetDisplacement(myPosSpn->value());
311 for (int i = 0; i < aNbRows; ++i) {
312 QCheckTableItem* aItem = (QCheckTableItem*)myPosTable->item( i, 1 );
313 if (aItem == 0) break;
314 if (!aItem->isChecked())
315 myCutPlanes->SetPlanePosition(i, myPosTable->text(i, 0).toDouble());
318 if (aNbPlanes > aNbRows)
319 myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
320 else if (aNbPlanes < aNbRows)
321 myPosTable->setNumRows(aNbPlanes);
323 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
324 for (int i = 0; i<aMin; i++) {
325 myPosTable->setText(i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
326 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(myCutPlanes->IsDefault(i));
329 QHeader *vh = myPosTable->verticalHeader();
330 QString str("Plane# %1");
331 for (int i=aMin; i<aNbPlanes; i++) {
332 VisuGUI_NumEditItem* aEditItem = new VisuGUI_NumEditItem(myPosTable,
333 QTableItem::OnTyping,
334 QString::number(myCutPlanes->GetPlanePosition(i)));
335 aEditItem->setReplaceable(false);
336 aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
337 myPosTable->setItem(i, 0, aEditItem);
339 QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
340 aCheck->setChecked(myCutPlanes->IsDefault(i));
341 aCheck->setReplaceable(false);
342 myPosTable->setItem(i, 1, aCheck);
344 vh->setLabel( i, str.arg(i+1) );
348 if (myPreviewCheck->isChecked()) {
349 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
350 myCutPlanes->GetPL()->Update();
358 void VisuGUI_CutPlanesPane::setDefault(int all)
360 myPosTable->setCurrentCell(-1, 1);
361 myPosTable->clearSelection();
362 if (all == 0) return;
364 for (int i = 0; i < getNbPlanes(); ++i)
365 ((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
367 for (int i = 0; i < getNbPlanes(); ++i) {
368 if ( ((QCheckTableItem*)myPosTable->item( i, 1 ))->isChecked() ) {
369 myCutPlanes->SetDefault(i);
370 myPosTable->setText( i, 0, QString::number(myCutPlanes->GetPlanePosition(i)));
371 myPosTable->item( i, 0 )->setEnabled(false);
373 myPosTable->item( i, 0 )->setEnabled(true);
377 void VisuGUI_CutPlanesPane::onValueChanged(int theRow, int theCol) {
379 QString aTxt = myPosTable->text(theRow, 0);
380 bool isChanged = !aTxt.isEmpty();
381 ((QCheckTableItem*)myPosTable->item(theRow, 1))->setChecked(!isChanged);
383 if (myPreviewCheck->isChecked()) {
385 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
386 myCutPlanes->SetPlanePosition( theRow, aTxt.toDouble());
387 myCutPlanes->GetPL()->Update();
394 bool isDefault = ((QCheckTableItem*)myPosTable->item(theRow, theCol))->isChecked();
396 myCutPlanes->SetDefault(theRow);
397 myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
399 if (myPreviewCheck->isChecked()) {
400 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
402 myCutPlanes->GetPL()->Update();
409 myPosTable->item(theRow, 0)->setEnabled(!isDefault);
414 void VisuGUI_CutPlanesPane::deletePlanes() {
415 if (myPreviewActor == 0) return;
416 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy))
417 vf->RemoveActor(myPreviewActor);
418 myPreviewActor->Delete();
422 void VisuGUI_CutPlanesPane::onRotation(double theValue) {
423 if (myCutPlanes == NULL) return;
424 if (myPreviewCheck->isChecked()) {
425 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
426 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
427 myCutPlanes->GetPL()->Update();
436 void VisuGUI_CutPlanesPane::onPreviewCheck(bool thePreview) {
437 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
439 storeToPrsObject(myCutPlanes);
440 myCutPlanes->GetPL()->Update();
453 //###################################################################
460 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg(bool theIsCreation, bool theIsModal)
461 : QDialog( QAD_Application::getDesktop(), "VisuGUI_CutPlanesDlg", theIsModal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu/* | WDestructiveClose */),
462 myStudy(QAD_Application::getDesktop()->getActiveStudy())
464 myStudyFrame = myStudy -> getActiveStudyFrame();
466 setWFlags(getWFlags() | WDestructiveClose);
468 setCaption( tr( "Cut Planes Definition" ) );
469 setSizeGripEnabled( TRUE );
470 myIsCreation = theIsCreation;
472 QVBoxLayout* TopLayout = new QVBoxLayout( this );
473 TopLayout->setSpacing( 6 );
474 TopLayout->setMargin( 11 );
476 QTabWidget* aTabBox = new QTabWidget(this);
477 myCutPane = new VisuGUI_CutPlanesPane(this, myStudy);
478 aTabBox->addTab(myCutPane, "Cut Planes");
479 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
480 myScalarPane->setMargin( 5 );
481 aTabBox->addTab(myScalarPane, "Scalar Bar");
483 TopLayout->addWidget(aTabBox);
485 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
486 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
487 GroupButtons->setTitle( tr( "" ) );
488 GroupButtons->setColumnLayout(0, Qt::Vertical );
489 GroupButtons->layout()->setSpacing( 0 );
490 GroupButtons->layout()->setMargin( 0 );
491 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
492 GroupButtonsLayout->setAlignment( Qt::AlignTop );
493 GroupButtonsLayout->setSpacing( 6 );
494 GroupButtonsLayout->setMargin( 11 );
496 QPushButton* buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
497 buttonOk->setAutoDefault( TRUE );
498 buttonOk->setDefault( TRUE );
499 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
500 GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1 );
502 QPushButton* buttonCancel = new QPushButton( tr( "&Cancel" ), GroupButtons, "buttonCancel" );
503 buttonCancel->setAutoDefault( TRUE );
504 GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
506 TopLayout->addWidget(GroupButtons);
508 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
509 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
510 connect( myStudy, SIGNAL(closed()), this, SLOT( reject() ) );
511 connect( myStudyFrame, SIGNAL(sfStudyFrameActivated(QAD_StudyFrame*)), this, SLOT(onFrameActivated(QAD_StudyFrame*)));
515 void VisuGUI_CutPlanesDlg::accept() {
516 if (myScalarPane->check()) {
518 if (storeToPrsObject(myPrs)) {
520 if (myStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
522 visuGUI->CreateActor(myPrs);
528 GET_VTK_VIEWFRAME(myStudy)->onViewFitAll();
531 visuGUI->RecreateActor(myPrs);
532 if (VTKViewer_ViewFrame* vf = GET_VTK_VIEWFRAME(myStudy)) {
533 if ( vf->getRenderer()->GetActors()->GetNumberOfItems () > 0 ) {
534 vf->getRenderer()->ResetCameraClippingRange();
541 visuGUI->DeletePresentation(myPrs);
549 void VisuGUI_CutPlanesDlg::reject() {
550 if (myIsCreation && (!isModal())) {
551 visuGUI->DeletePresentation(myPrs);
552 myStudy -> updateObjBrowser();
557 void VisuGUI_CutPlanesDlg::onFrameActivated( QAD_StudyFrame* theFrame) {
558 if (theFrame != myStudyFrame)
562 //###################################################################
566 QWidget* VisuGUI_NumEditItem::createEditor() const
568 QLineEdit *editline = new QLineEdit(text(), table()->viewport());
569 QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
570 dvalidator->setDecimals(32);
571 editline->setValidator(dvalidator);