1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_CutPlanesDlg.cxx
24 // Author : Laurent CORNABE & Hubert ROLLAND
27 #include "VisuGUI_CutPlanesDlg.h"
29 #include "VISU_ColoredPrs3dFactory.hh"
32 #include "VisuGUI_Tools.h"
33 #include "VisuGUI_ViewTools.h"
34 #include "VisuGUI_InputPane.h"
36 #include "VISU_ColoredPrs3dFactory.hh"
37 #include "VISU_CutPlanes_i.hh"
38 #include "VISU_Result_i.hh"
39 #include "VISU_CutPlanesPL.hxx"
41 //#include "OB_Browser.h"
43 #include "VISU_TableDlg.h"
45 #include "SVTK_ViewWindow.h"
47 #include "LightApp_Application.h"
49 #include <SalomeApp_IntSpinBox.h>
50 #include <SalomeApp_DoubleSpinBox.h>
52 #include "SUIT_Application.h"
53 #include "SUIT_Desktop.h"
54 #include "SUIT_ViewWindow.h"
55 #include "SUIT_ViewManager.h"
56 #include "SUIT_Session.h"
57 #include "SUIT_MessageBox.h"
58 #include "SUIT_ResourceMgr.h"
62 #include <QButtonGroup>
69 #include <QRadioButton>
70 #include <QTableWidget>
72 #include <QPushButton>
73 #include <QHeaderView>
76 #include <vtkRenderer.h>
77 #include <vtkPolyData.h>
78 #include <vtkAppendPolyData.h>
79 #include <vtkDataSetMapper.h>
80 #include <vtkDataSet.h>
86 //extern VisuGUI *visuGUI;
88 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent)
89 : QFrame(theParent), myPreviewActor(0)
91 QGridLayout* TopLayout = new QGridLayout( this );
92 TopLayout->setSpacing( 6 );
93 TopLayout->setMargin( 10 );
95 QButtonGroup* SelPlane = new QButtonGroup ( this );
96 QGroupBox* aGB = new QGroupBox( tr("TXT_ORIENTATION"), this );
97 //SelPlane->setTitle(tr("TXT_ORIENTATION"));
98 //SelPlane->setColumnLayout(0, Qt::Vertical);
99 //SelPlane->layout()->setSpacing( 0 );
100 //SelPlane->layout()->setMargin( 0 );
101 QGridLayout* SelPlaneLayout = new QGridLayout( aGB );
102 SelPlaneLayout->setAlignment( Qt::AlignTop );
103 SelPlaneLayout->setSpacing( 6 );
104 SelPlaneLayout->setMargin( 11 );
106 RBxy = new QRadioButton (tr("PARALLEL_XOY"), aGB);
107 RByz = new QRadioButton (tr("PARALLEL_YOZ"), aGB);
108 RBzx = new QRadioButton (tr("PARALLEL_ZOX"), aGB);
109 SelPlaneLayout->addWidget( RBxy, 0, 0 );
110 SelPlaneLayout->addWidget( RByz, 0, 1 );
111 SelPlaneLayout->addWidget( RBzx, 0, 2 );
112 SelPlane->addButton( RBxy );
113 SelPlane->addButton( RByz );
114 SelPlane->addButton( RBzx );
116 QLabel* LabelPosi_3 = new QLabel (tr("LBL_NB_PLANS"), this);
118 nbPlan = new SalomeApp_IntSpinBox( this );
119 nbPlan->setAcceptNames( false );
120 nbPlan->setMinimum( 1 );
121 nbPlan->setMaximum(100);
122 nbPlan->setSingleStep( 1 );
123 nbPlan->setValue( 1 );
124 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
126 myPosTable = new QTableWidget (this);
127 myPosTable->setMaximumHeight( 227 );
128 myPosTable->setMinimumWidth( 294 );
129 myPosTable->setColumnCount(2);
130 myPosTable->setRowCount(0);
131 connect( myPosTable, SIGNAL(cellChanged(int, int)), this, SLOT(onValueChanged(int, int)) );
133 myPosTable->setItemDelegateForColumn( 0,
134 new NumDelegateItem( myPosTable, NumDelegateItem::NV_Real) );
136 myPosTable->setEditTriggers(
137 (QAbstractItemView::EditTriggers)(QAbstractItemView::AllEditTriggers &(~QAbstractItemView::CurrentChanged)));
140 aLabels.append( "Position" );
141 aLabels.append( "Set default" );
143 myPosTable->setHorizontalHeaderLabels( aLabels );
145 QGroupBox* GBrot = new QGroupBox (tr("LBL_ROTATION"), this);
146 //GBrot->setColumnLayout(0, Qt::Vertical);
147 //GBrot->layout()->setSpacing( 0 );
148 //GBrot->layout()->setMargin( 0 );
149 QGridLayout* GBrotLayout = new QGridLayout( GBrot );
150 GBrotLayout->setAlignment( Qt::AlignTop );
151 GBrotLayout->setSpacing( 6 );
152 GBrotLayout->setMargin( 11 );
154 LabelRot1 = new QLabel (tr("LBL_ROT_X"), GBrot );
155 GBrotLayout->addWidget( LabelRot1, 0, 0 );
157 Rot1 = new SalomeApp_DoubleSpinBox( GBrot );
158 VISU::initSpinBox( Rot1, -180., 180., 10., "angle_precision" );
160 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
161 connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
162 GBrotLayout->addWidget( Rot1, 0, 1 );
164 LabelRot2 = new QLabel (tr("LBL_ROT_Y"), GBrot );
165 GBrotLayout->addWidget( LabelRot2, 1, 0 );
167 Rot2 = new SalomeApp_DoubleSpinBox( GBrot );
168 VISU::initSpinBox( Rot2, -180., 180., 10., "angle_precision" );
170 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
171 connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
172 GBrotLayout->addWidget( Rot2, 1, 1 );
174 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
175 myPosSpn = new SalomeApp_DoubleSpinBox( this );
176 VISU::initSpinBox( myPosSpn, 0., 1., .1, "parametric_precision" );
178 GDeformation = new QGroupBox(tr("LBL_DEFORMATION"), this);
179 GDeformation->setCheckable(true);
180 GDeformation->setChecked(false);
181 QGridLayout* GDeformationLayout = new QGridLayout( GDeformation );
182 GDeformationLayout->setSpacing( 6 );
183 GDeformationLayout->setMargin( 11 );
184 connect(GDeformation, SIGNAL(toggled(bool)), this, SLOT(onDeformationCheck(bool)));
186 QLabel* LabelDeformation1 = new QLabel (tr("LBL_DEFROMATION_VECT"), GDeformation);
187 GDeformationLayout->addWidget( LabelDeformation1, 0, 0 );
189 myVectorialFieldCombo = new QComboBox (GDeformation);
190 GDeformationLayout->addWidget( myVectorialFieldCombo, 0, 1 );
192 QLabel* LabelDeformation2 = new QLabel (tr("LBL_DEFROMATION_SCALE"), GDeformation);
193 GDeformationLayout->addWidget( LabelDeformation2, 1, 0 );
194 myScaleSpn = new SalomeApp_DoubleSpinBox (GDeformation);
195 VISU::initSpinBox( myScaleSpn, 0., 1.0E+38, 0.1, "visual_data_precision" );
196 myScaleSpn->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
197 GDeformationLayout->addWidget( myScaleSpn, 1, 1 );
198 connect(myVectorialFieldCombo, SIGNAL(activated(int)), this, SLOT(onVectorialFieldChanged(int)));
199 connect(myScaleSpn, SIGNAL(valueChanged(double)), this, SLOT(onScaleFactorChanged(double)));
200 myScaleSpn->setValue(0.1);
202 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
203 myPreviewCheck->setChecked(false);
204 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
206 TopLayout->addWidget( aGB, 0, 0, 1, 2 );
207 TopLayout->addWidget( GBrot, 1, 0, 1, 2 );
208 TopLayout->addWidget( LabelPosi_3, 2, 0 );
209 TopLayout->addWidget( nbPlan, 2, 1 );
210 TopLayout->addWidget( myPosTable, 3, 0, 1, 2 );
211 TopLayout->setRowStretch ( 3, 3 );
212 TopLayout->addWidget(aPosLbl, 4, 0 );
213 TopLayout->addWidget(myPosSpn, 4, 1 );
214 TopLayout->addWidget( GDeformation, 5, 0, 1, 2 );
215 TopLayout->addWidget( myPreviewCheck, 6, 0, 1, 2 );
217 // signals and slots connections
218 connect( SelPlane, SIGNAL( buttonClicked( int )), this, SLOT( orientationChanged( int ) ) );
219 connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
220 connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
221 connect( myPosTable->horizontalHeader(), SIGNAL( sectionClicked(int)), this, SLOT( setDefault(int) ) );
228 RByz->setChecked( true );
230 } // End of Constructor
232 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
235 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
239 void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs)
241 setNbPlanes(thePrs->GetNbPlanes());
242 setRotation(thePrs->GetRotateX()*180./M_PI, thePrs->GetRotateY()*180./M_PI);
243 setPlanePos(thePrs->GetOrientationType());
244 myPosSpn->setValue(thePrs->GetDisplacement());
245 InitEntity2VectorialFieldsMap(thePrs);
246 InsertAllVectorialFields();
247 setScaleFactor(thePrs->GetScale());
248 if(myEntity2VectorialFields.size() < 1)
249 GDeformation->setDisabled(true);
251 if(thePrs->IsDeformed()){
252 GDeformation->setChecked(true);
253 int idx = myVectorialFieldCombo->findText(thePrs->GetVectorialFieldName());
255 myVectorialFieldCombo->setCurrentIndex(idx);
257 myVectorialFieldCombo->addItem(thePrs->GetVectorialFieldName());
258 myVectorialFieldCombo->setCurrentIndex(myVectorialFieldCombo->count()-1);
265 myCutPlanes = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
266 myCutPlanes->SameAs(thePrs);
270 if (myPreviewCheck->isChecked()) {
275 void VisuGUI_CutPlanesPane::InitEntity2VectorialFieldsMap(VISU::ColoredPrs3d_i* thePrs){
277 VISU::Result_var theResult = thePrs->GetResultObject();
278 VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>(GetServant(theResult).in());
279 VISU::Result::Entities_var aEntities = aResult->GetEntities(thePrs->GetMeshName());
280 VISU::Result::TimeStampNumbers_var aScalarTimeStamp = aResult->GetTimeStampNumbers(thePrs->GetMeshName(),
282 thePrs->GetFieldName());
283 CORBA::Long aTimeStampNumber = aScalarTimeStamp->length();
285 for(size_t iEntity = 0; iEntity < aEntities->length(); iEntity++){
286 VISU::Entity aEntity = aEntities[iEntity];
287 VISU::Result::EntityNames_var aFields = aResult->GetFields(thePrs->GetMeshName(),aEntity);
288 for(size_t iField = 0; iField < aFields->length(); iField++){
290 TVectorialFieldsList aVectorialFields;
291 VISU::Result::TimeStampNumbers_var aTimeStamps = aResult->GetTimeStampNumbers(thePrs->GetMeshName(),aEntity,aFields[iField] );
293 if((aResult->GetNumberOfComponents(thePrs->GetMeshName(),aEntity,aFields[iField] ) > 1) &&
294 (aTimeStamps->length() >= aTimeStampNumber)){
295 aVectorialFields.push_back(QString(aFields[iField].in()));
297 if(aVectorialFields.size() > 0){
298 myEntity2VectorialFields.insert(TEntVectPair(aEntity,aVectorialFields));
304 void VisuGUI_CutPlanesPane::InsertAllVectorialFields(){
305 TEntity2VectorialFields::const_iterator aFieldIter = myEntity2VectorialFields.begin();
306 for( ;aFieldIter != myEntity2VectorialFields.end();aFieldIter++ ){
307 TVectorialFieldsList aVectorialFields = aFieldIter->second;
308 for(size_t iField = 0;iField < aVectorialFields.size(); iField++)
309 myVectorialFieldCombo->addItem(aVectorialFields[iField]);
313 double VisuGUI_CutPlanesPane::getScaleFactor(){
314 return myScaleSpn->value();
317 void VisuGUI_CutPlanesPane::setScaleFactor(double theFactor)
320 if (fabs(theFactor) > std::numeric_limits<double>::epsilon()) {
321 int degree = int(log10(fabs(theFactor))) - 1;
322 if (fabs(theFactor) < 1) {
323 // as logarithm value is negative in this case
324 // and it is truncated to the bigger integer
327 step = pow(10., double(degree));
330 myScaleSpn->setSingleStep(step);
331 myScaleSpn->setValue(theFactor);
334 void VisuGUI_CutPlanesPane::createPlanes()
336 if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
337 if (!(bool)myCutPlanes) return;
338 if (myPreviewActor != 0) return;
340 vtkDataSet* aDataSet = myCutPlanes->GetSpecificPL()->GetWarpVectorOutput();
341 if (!aDataSet->GetNumberOfCells()) {
342 onPreviewCheck(false);
345 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
346 aPlaneMapper->SetInput(aDataSet);
347 aPlaneMapper->ScalarVisibilityOff();
349 myPreviewActor = SALOME_Actor::New();
350 myPreviewActor->PickableOff();
351 myPreviewActor->SetMapper(aPlaneMapper);
352 aPlaneMapper->Delete();
353 VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
356 int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs)
358 thePrs->SetOrientation(getOrientaion(), getRotation1()*M_PI/180., getRotation2()*M_PI/180.);
359 thePrs->SetNbPlanes(getNbPlanes());
360 thePrs->SetDisplacement(myPosSpn->value());
361 for (int i = 0; i < getNbPlanes(); ++i) {
362 QTableWidgetItem* anItem = myPosTable->item(i, 1);
365 if (anItem->checkState() != Qt::Checked )
366 thePrs->SetPlanePosition(i, myPosTable->item(i, 0)->text().toDouble());
368 thePrs->SetDefault(i);
371 thePrs->UseDeformation(GDeformation->isChecked());
373 if(GDeformation->isChecked()){
374 TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
375 VISU::Entity anEntity;
377 bool isInited = false;
378 for(;anIter != myEntity2VectorialFields.end();anIter++){
379 TVectorialFieldsList aFields = anIter->second;
380 for(int it = 0;it < aFields.size();it++)
381 if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){
382 anEntity = anIter->first;
383 aFieldName = aFields[it];
391 thePrs->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
393 thePrs->SetScale(myScaleSpn->value());
399 Called when orientation is changed
401 void VisuGUI_CutPlanesPane::orientationChanged (int Id)
403 if ( RBxy->isChecked() ) { // RBxy->isChecked()
404 LabelRot1->setText(tr("LBL_ROT_X"));
405 LabelRot2->setText(tr("LBL_ROT_Y"));
406 } else if ( RByz->isChecked() ) { // RByz->isChecked()
407 LabelRot1->setText(tr("LBL_ROT_Y"));
408 LabelRot2->setText(tr("LBL_ROT_Z"));
409 } else if ( RBzx->isChecked() ) {
410 LabelRot1->setText(tr("LBL_ROT_Z"));
411 LabelRot2->setText(tr("LBL_ROT_X"));
417 Sets planes orientation and position
419 void VisuGUI_CutPlanesPane::setPlanePos (const VISU::CutPlanes::Orientation orient)
421 if (orient == VISU::CutPlanes::XY) // xy
423 RBxy->setChecked( true );
424 orientationChanged( 0 );
426 else if (orient == VISU::CutPlanes::YZ) // yz
428 RByz->setChecked( true );
429 orientationChanged( 1 );
433 RBzx->setChecked( true );
434 orientationChanged( 2 );
440 Gets planes orientation
442 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
444 VISU::CutPlanes::Orientation orient;
445 if ( RBxy->isChecked() ) // xy
446 orient = VISU::CutPlanes::XY;
447 else if ( RByz->isChecked() ) // yz
448 orient = VISU::CutPlanes::YZ;
449 else if ( RBzx->isChecked() ) // zx
450 orient = VISU::CutPlanes::ZX;
457 void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2)
459 Rot1->setValue( r1 );
460 Rot2->setValue( r2 );
463 void VisuGUI_CutPlanesPane::onScaleFactorChanged(double theFactor){
467 void VisuGUI_CutPlanesPane::onVectorialFieldChanged(int pos){
468 InitVectorialField();
472 void VisuGUI_CutPlanesPane::onDeformationCheck(bool Flag){
473 if(!(bool)myCutPlanes || !hasInit) return;
474 myCutPlanes->UseDeformation(Flag);
475 InitVectorialField();
479 void VisuGUI_CutPlanesPane::InitVectorialField(){
480 if(myCutPlanes->IsDeformed()){
481 TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
482 VISU::Entity anEntity;
484 bool isInited = false;
485 for(;anIter != myEntity2VectorialFields.end();anIter++){
486 TVectorialFieldsList aFields = anIter->second;
487 for(int it = 0;it < aFields.size();it++)
488 if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){
489 anEntity = anIter->first;
490 aFieldName = aFields[it];
498 myCutPlanes->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
503 Draw the table of planes positions
505 void VisuGUI_CutPlanesPane::DrawTable()
507 if (!(bool)myCutPlanes) return;
508 if (!hasInit) return;
510 int aNbRows = myPosTable->rowCount();
511 int aNbPlanes = getNbPlanes();
513 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*M_PI/180.,getRotation2()*M_PI/180.);
514 myCutPlanes->SetNbPlanes(aNbPlanes);
515 myCutPlanes->SetDisplacement(myPosSpn->value());
516 myCutPlanes->SetScale(getScaleFactor());
518 for (int i = 0; i < aNbRows; ++i) {
519 QTableWidgetItem* aItem = myPosTable->item( i, 1 );
520 if (aItem == 0) break;
521 if (aItem->checkState() != Qt::Checked )
522 myCutPlanes->SetPlanePosition(i, myPosTable->item(i, 0)->text().toDouble());
525 if (aNbPlanes > aNbRows)
526 while( aNbPlanes > myPosTable->rowCount() )
527 myPosTable->insertRow( myPosTable->rowCount() );
528 else if (aNbPlanes < aNbRows)
529 myPosTable->setRowCount(aNbPlanes);
532 QString str("Plane# %1");
533 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
534 for (int i = 0; i<aMin; i++) {
535 myPosTable->item( i, 0 )->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
536 myPosTable->item( i, 1 )->setCheckState( myCutPlanes->IsDefault(i) ? Qt::Checked : Qt::Unchecked);
537 aLabels.append( str.arg(i+1) );
540 //QHeader *vh = myPosTable->verticalHeader();
541 for (int i=aMin; i<aNbPlanes; i++) {
542 QTableWidgetItem* aEditItem = new QTableWidgetItem();
543 aEditItem->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
544 //aEditItem->setReplaceable(false);
545 //aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
546 Qt::ItemFlags aFlags = aEditItem->flags();
547 if ( myCutPlanes->IsDefault(i) )
548 aFlags |= Qt::ItemIsEnabled;
550 aFlags &= (~Qt::ItemIsEnabled);
551 myPosTable->setItem(i, 0, aEditItem);
553 /*QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
554 aCheck->setChecked(myCutPlanes->IsDefault(i));
555 aCheck->setReplaceable(false);*/
556 QTableWidgetItem* aCheck = new QTableWidgetItem();
557 aFlags = aCheck->flags();
558 //aFlags |= Qt::ItemIsUserCheckable;
559 aFlags &= (~Qt::ItemIsEditable);
560 aCheck->setFlags( aFlags );
561 aCheck->setCheckState( myCutPlanes->IsDefault(i) ?
562 Qt::Checked : Qt::Unchecked );
563 myPosTable->setItem(i, 1, aCheck);
565 //vh->setLabel( i, str.arg(i+1) );
566 aLabels.append( str.arg(i+1) );
568 myPosTable->setVerticalHeaderLabels( aLabels );
571 if (myPreviewCheck->isChecked()) {
572 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
573 myCutPlanes->GetPipeLine()->Update();
581 void VisuGUI_CutPlanesPane::setDefault (int all)
583 myPosTable->setCurrentCell(-1, 1);
584 myPosTable->clearSelection();
585 if (all == 0) return;
587 for (int i = 0; i < getNbPlanes(); ++i)
588 myPosTable->item( i, 1 )->setCheckState(Qt::Checked);
589 //((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
591 for (int i = 0; i < getNbPlanes(); ++i) {
592 if ( myPosTable->item( i, 1 )->checkState() == Qt::Checked )
594 myCutPlanes->SetDefault(i);
595 myPosTable->item( i, 0)->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
596 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() &(~Qt::ItemIsEnabled ) );
599 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() | Qt::ItemIsEnabled );
603 void VisuGUI_CutPlanesPane::onValueChanged (int theRow, int theCol)
605 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
609 if ( !myPosTable->item(theRow, 1) || !myPosTable->item(theRow, 0) )
614 QTableWidgetItem* anItem = myPosTable->item(theRow, theCol);
618 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
621 anIndex = aModel->index( theRow, 0 );
623 myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
626 if ( myPreviewCheck->isChecked() )
629 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
631 myCutPlanes->GetPipeLine()->Update();
640 anItem = myPosTable->item(theRow, 0);
641 Qt::ItemFlags flags = anItem->flags();
644 myCutPlanes->SetDefault(theRow);
645 anIndex = aModel->index( theRow, 0 );
646 aModel->setData( anIndex, myCutPlanes->GetPlanePosition(theRow), Qt::DisplayRole );
648 /*if ( myPreviewCheck->isChecked() )
650 //not needed update presentation, because item->setFlags generates signal cellChanged() again
652 flags &= (~Qt::ItemIsEnabled );
655 flags |= Qt::ItemIsEnabled;
657 anItem->setFlags( flags );
661 bool isChanged = !anIndex.data().isNull();
662 QTableWidgetItem* anItem = myPosTable->item(theRow, 1);
665 anItem = new QTableWidgetItem();
666 myPosTable->setItem( theRow, 1, anItem );
667 Qt::ItemFlags flags = anItem->flags();
668 //flags |= Qt::ItemIsUserCheckable;
669 flags &= (~Qt::ItemIsEditable);
670 anItem->setFlags( flags );
672 anItem->setCheckState(!isChanged ? Qt::Checked : Qt::Unchecked);
674 if (myPreviewCheck->isChecked()) {
676 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
677 myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
678 myCutPlanes->GetPipeLine()->Update();
685 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
686 QTableWidgetItem* anItem = myPosTable->item(theRow, 0);
689 anItem = new QTableWidgetItem();
690 myPosTable->setItem( theRow, 0, anItem );
694 myCutPlanes->SetDefault(theRow);
695 //myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
696 anIndex = aModel->index( theRow, 0 );
697 aModel->setData( anIndex, myCutPlanes->GetPlanePosition(theRow), Qt::DisplayRole );
698 anItem->setFlags( anItem->flags() | Qt::ItemIsEnabled );
699 if (myPreviewCheck->isChecked()) {
700 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
702 myCutPlanes->GetPipeLine()->Update();
709 //myPosTable->item(theRow, 0)->setEnabled(!isDefault);
710 anItem->setFlags( anItem->flags() &(~Qt::ItemIsEnabled ) );
714 void VisuGUI_CutPlanesPane::deletePlanes()
716 if (myPreviewActor == 0) return;
717 vtkRenderer* aRend = myPreviewActor->GetRenderer();
718 vtkRenderWindow* aWnd = aRend->GetRenderWindow();
721 myPreviewActor->RemoveFromRender(aRend);
722 // Bug IPAL11962: preview is still in the viewer, if viewer not active.
723 // if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
724 // vf->RemoveActor(myPreviewActor);
725 myPreviewActor->Delete();
729 void VisuGUI_CutPlanesPane::onRotation (double theValue)
731 if (!(bool)myCutPlanes) return;
732 if (myPreviewCheck->isChecked()) {
733 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
734 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*M_PI/180.,getRotation2()*M_PI/180.);
735 myCutPlanes->GetPipeLine()->Update();
743 void VisuGUI_CutPlanesPane::onPreviewCheck (bool thePreview)
745 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
747 storeToPrsObject(myCutPlanes);
748 myCutPlanes->GetPipeLine()->Update();
750 if(VISU::GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false))
751 vf->onFitAll(); // Repaint() is called inside
761 //###################################################################
767 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg (SalomeApp_Module* theModule)
768 : VisuGUI_ScalarBarBaseDlg(theModule)
770 setWindowTitle("Cut Planes Definition");
771 setSizeGripEnabled(true);
773 QVBoxLayout* TopLayout = new QVBoxLayout (this);
774 TopLayout->setSpacing(6);
775 TopLayout->setMargin(11);
778 myTabBox = new QTabWidget(this);
779 myCutPane = new VisuGUI_CutPlanesPane(this/*, myMgr*/);
780 myTabBox->addTab(myCutPane, "Cut Planes");
781 myInputPane = new VisuGUI_InputPane(VISU::TCUTPLANES, theModule, this);
782 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
783 myTabBox->addTab(myInputPane, "Input");
785 TopLayout->addWidget(myTabBox);
787 QGroupBox* GroupButtons = new QGroupBox(this);
788 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
789 GroupButtons->setTitle("");
790 //GroupButtons->setColumnLayout(0, Qt::Vertical);
791 //GroupButtons->layout()->setSpacing(0);
792 //GroupButtons->layout()->setMargin(0);
793 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
794 GroupButtonsLayout->setAlignment(Qt::AlignTop);
795 GroupButtonsLayout->setSpacing(6);
796 GroupButtonsLayout->setMargin(11);
798 QPushButton* buttonOk = new QPushButton(tr("BUT_OK"), GroupButtons);
799 buttonOk->setAutoDefault(TRUE);
800 buttonOk->setDefault(TRUE);
801 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
802 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
804 QPushButton* buttonCancel = new QPushButton(tr("BUT_CANCEL"), GroupButtons);
805 buttonCancel->setAutoDefault(TRUE);
806 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
808 QPushButton* buttonHelp = new QPushButton(tr("BUT_HELP"), GroupButtons);
809 buttonHelp->setAutoDefault(TRUE);
810 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
812 TopLayout->addWidget(GroupButtons);
814 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
815 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
816 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
819 VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
822 void VisuGUI_CutPlanesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
826 myPrsCopy = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
828 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
830 myCutPane->initFromPrsObject(myPrsCopy);
835 myInputPane->initFromPrsObject( myPrsCopy );
836 myTabBox->setCurrentIndex( 0 );
839 int VisuGUI_CutPlanesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
841 if(!myInputPane->check() || !GetScalarPane()->check())
844 int anIsOk = myInputPane->storeToPrsObject(myPrsCopy);
845 anIsOk &= GetScalarPane()->storeToPrsObject(myPrsCopy);
846 anIsOk &= myCutPane->storeToPrsObject(myPrsCopy);
848 VISU::TSameAsFactory<VISU::TCUTPLANES>().Copy(myPrsCopy, thePrs);
853 void VisuGUI_CutPlanesDlg::accept()
855 VisuGUI_ScalarBarBaseDlg::accept();
858 void VisuGUI_CutPlanesDlg::reject() {
859 VisuGUI_ScalarBarBaseDlg::reject();
862 QString VisuGUI_CutPlanesDlg::GetContextHelpFilePath()
864 return "cut_planes_page.html";
867 //###################################################################
869 /*QWidget* VisuGUI_NumEditItem::createEditor() const
871 QLineEdit *editline = new QLineEdit(text(), table()->viewport());
872 QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
873 dvalidator->setDecimals(32);
874 editline->setValidator(dvalidator);