]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_CutPlanesDlg.cxx
Salome HOME
5b48ab40fe390edbeb225477f19e0a84b24e94fc
[modules/visu.git] / src / VISUGUI / VisuGUI_CutPlanesDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_CutPlanesDlg.cxx
24 //  Author : Laurent CORNABE & Hubert ROLLAND
25 //  Module : VISU
26 //  $Header$
27 //
28 #include "VisuGUI_CutPlanesDlg.h"
29
30 #include "VISU_ColoredPrs3dFactory.hh"
31
32 #include "VisuGUI.h"
33 #include "VisuGUI_Tools.h"
34 #include "VisuGUI_ViewTools.h"
35 #include "VisuGUI_InputPane.h"
36
37 #include "VISU_ColoredPrs3dFactory.hh"
38 #include "VISU_CutPlanes_i.hh"
39 #include "VISU_Result_i.hh"
40 #include "VISU_CutPlanesPL.hxx"
41
42 //#include "OB_Browser.h"
43
44 #include "VisuGUI_TableDlg.h"
45
46 #include "SVTK_ViewWindow.h"
47
48 #include "LightApp_Application.h"
49
50 #include "SUIT_Application.h"
51 #include "SUIT_Desktop.h"
52 #include "SUIT_ViewWindow.h"
53 #include "SUIT_ViewManager.h"
54 #include "SUIT_Session.h"
55 #include "SUIT_MessageBox.h"
56 #include "SUIT_ResourceMgr.h"
57
58 #include <QLayout>
59 #include <QLabel>
60 #include <QButtonGroup>
61 #include <QCheckBox>
62 #include <QStyle>
63 #include <QValidator>
64 #include <QLineEdit>
65 #include <QTabWidget>
66 #include <QKeyEvent>
67 #include <QSpinBox>
68 #include <QRadioButton>
69 #include <QTableWidget>
70 #include <QGroupBox>
71 #include <QPushButton>
72 #include <QHeaderView>
73 #include <QComboBox>
74
75 #include <vtkRenderer.h>
76 #include <vtkPolyData.h>
77 #include <vtkAppendPolyData.h>
78 #include <vtkDataSetMapper.h>
79 #include <vtkDataSet.h>
80
81 #include <limits>
82
83 using namespace std;
84
85 //extern VisuGUI *visuGUI;
86
87 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent)
88      : QFrame(theParent), myPreviewActor(0)
89 {
90   QGridLayout* TopLayout = new QGridLayout( this );
91   TopLayout->setSpacing( 6 );
92   TopLayout->setMargin( 10 );
93
94   QButtonGroup* SelPlane = new QButtonGroup ( this );
95   QGroupBox* aGB = new QGroupBox( tr("TXT_ORIENTATION"), this );
96   //SelPlane->setTitle(tr("TXT_ORIENTATION"));
97   //SelPlane->setColumnLayout(0, Qt::Vertical);
98   //SelPlane->layout()->setSpacing( 0 );
99   //SelPlane->layout()->setMargin( 0 );
100   QGridLayout* SelPlaneLayout = new QGridLayout( aGB );
101   SelPlaneLayout->setAlignment( Qt::AlignTop );
102   SelPlaneLayout->setSpacing( 6 );
103   SelPlaneLayout->setMargin( 11 );
104
105   RBxy = new QRadioButton (tr("PARALLEL_XOY"), aGB);
106   RByz = new QRadioButton (tr("PARALLEL_YOZ"), aGB);
107   RBzx = new QRadioButton (tr("PARALLEL_ZOX"), aGB);
108   SelPlaneLayout->addWidget( RBxy, 0, 0 );
109   SelPlaneLayout->addWidget( RByz, 0, 1 );
110   SelPlaneLayout->addWidget( RBzx, 0, 2 );
111   SelPlane->addButton( RBxy );
112   SelPlane->addButton( RByz );
113   SelPlane->addButton( RBzx );
114
115   QLabel* LabelPosi_3 = new QLabel (tr("LBL_NB_PLANS"), this);
116
117   nbPlan = new QSpinBox( this );
118   nbPlan->setMinimum( 1 );
119   nbPlan->setMaximum(100);
120   nbPlan->setSingleStep( 1 );
121   nbPlan->setValue( 1 );
122   nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
123
124   myPosTable = new QTableWidget (this);
125   myPosTable->setMaximumHeight( 227 );
126   myPosTable->setMinimumWidth( 294 );
127   myPosTable->setColumnCount(2);
128   myPosTable->setRowCount(0);
129   connect( myPosTable, SIGNAL(cellChanged(int, int)), this, SLOT(onValueChanged(int, int)) );
130
131   myPosTable->setItemDelegateForColumn( 0,
132          new NumDelegateItem( myPosTable, NumDelegateItem::NV_Real) );
133
134   myPosTable->setEditTriggers(
135          (QAbstractItemView::EditTriggers)(QAbstractItemView::AllEditTriggers &(~QAbstractItemView::CurrentChanged)));
136
137   QStringList aLabels;
138   aLabels.append( "Position" );
139   aLabels.append( "Set default" );
140   
141   myPosTable->setHorizontalHeaderLabels( aLabels );
142
143   QGroupBox* GBrot = new QGroupBox (tr("LBL_ROTATION"), this);
144   //GBrot->setColumnLayout(0, Qt::Vertical);
145   //GBrot->layout()->setSpacing( 0 );
146   //GBrot->layout()->setMargin( 0 );
147   QGridLayout* GBrotLayout = new QGridLayout( GBrot );
148   GBrotLayout->setAlignment( Qt::AlignTop );
149   GBrotLayout->setSpacing( 6 );
150   GBrotLayout->setMargin( 11 );
151
152   LabelRot1 = new QLabel (tr("LBL_ROT_X"), GBrot );
153   GBrotLayout->addWidget( LabelRot1, 0, 0 );
154
155   Rot1 = new QtxDoubleSpinBox( -180, 180, 10, GBrot );
156   Rot1->setValue( 0 );
157   Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
158   connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
159   GBrotLayout->addWidget( Rot1, 0, 1 );
160
161   LabelRot2 = new QLabel (tr("LBL_ROT_Y"), GBrot );
162   GBrotLayout->addWidget( LabelRot2, 1, 0 );
163
164   Rot2 = new QtxDoubleSpinBox( -180, 180, 10, GBrot );
165   Rot2->setValue( 0 );
166   Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
167   connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
168   GBrotLayout->addWidget( Rot2, 1, 1 );
169
170   QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
171   myPosSpn = new QtxDoubleSpinBox( 0, 1, 0.1, this );
172
173   GDeformation = new QGroupBox(tr("LBL_DEFORMATION"), this);
174   GDeformation->setCheckable(true);
175   GDeformation->setChecked(false);
176   QGridLayout* GDeformationLayout = new QGridLayout( GDeformation );
177   GDeformationLayout->setSpacing( 6 );
178   GDeformationLayout->setMargin( 11 );
179   connect(GDeformation, SIGNAL(toggled(bool)), this, SLOT(onDeformationCheck(bool)));
180
181   QLabel* LabelDeformation1 = new QLabel (tr("LBL_DEFROMATION_VECT"), GDeformation);
182   GDeformationLayout->addWidget( LabelDeformation1, 0, 0 );
183
184   myVectorialFieldCombo = new QComboBox (GDeformation);
185   GDeformationLayout->addWidget( myVectorialFieldCombo, 0, 1 );
186
187   SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
188   int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
189   
190   QLabel* LabelDeformation2 = new QLabel (tr("LBL_DEFROMATION_SCALE"), GDeformation);
191   GDeformationLayout->addWidget( LabelDeformation2, 1, 0 );
192   myScaleSpn = new QtxDoubleSpinBox (0, 1.0E+38, 0.1, aPrecision*(-1), 38, GDeformation);
193   myScaleSpn->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
194   GDeformationLayout->addWidget( myScaleSpn, 1, 1 );
195   connect(myVectorialFieldCombo,     SIGNAL(activated(int)), this, SLOT(onVectorialFieldChanged(int)));
196   connect(myScaleSpn, SIGNAL(valueChanged(double)), this, SLOT(onScaleFactorChanged(double)));
197   myScaleSpn->setValue(0.1);
198
199   myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
200   myPreviewCheck->setChecked(false);
201   connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
202
203   TopLayout->addWidget( aGB, 0, 0, 1, 2 );
204   TopLayout->addWidget( GBrot, 1, 0, 1, 2 );
205   TopLayout->addWidget( LabelPosi_3,   2, 0 );
206   TopLayout->addWidget( nbPlan,        2, 1 );
207   TopLayout->addWidget( myPosTable, 3, 0, 1, 2 );
208   TopLayout->setRowStretch ( 3, 3 );
209   TopLayout->addWidget(aPosLbl, 4, 0 );
210   TopLayout->addWidget(myPosSpn, 4, 1 );
211   TopLayout->addWidget( GDeformation, 5, 0, 1, 2 );
212   TopLayout->addWidget( myPreviewCheck, 6, 0, 1, 2 );
213
214   // signals and slots connections
215   connect( SelPlane, SIGNAL( buttonClicked( int )), this, SLOT( orientationChanged( int ) ) );
216   connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
217   connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
218   connect( myPosTable->horizontalHeader(), SIGNAL( sectionClicked(int)), this, SLOT( setDefault(int) ) );
219
220   // default values
221   hasInit = false;
222   X1 = 0; X2 = 0;
223   Y1 = 0; Y2 = 0;
224   Z1 = 0; Z2 = 0;
225   RByz->setChecked( true );
226
227 } // End of Constructor
228
229 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
230 {
231   deletePlanes();
232   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
233     vf->Repaint();
234 }
235
236 void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs)
237 {
238   setNbPlanes(thePrs->GetNbPlanes());
239   setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
240   setPlanePos(thePrs->GetOrientationType());
241   myPosSpn->setValue(thePrs->GetDisplacement());
242   InitEntity2VectorialFieldsMap(thePrs);
243   InsertAllVectorialFields();
244   setScaleFactor(thePrs->GetScale());
245   if(myEntity2VectorialFields.size() < 1)
246     GDeformation->setDisabled(true);
247   else{
248     if(thePrs->IsDeformed()){
249       GDeformation->setChecked(true);
250       int idx = myVectorialFieldCombo->findText(thePrs->GetVectorialFieldName());
251       if (idx >= 0)
252         myVectorialFieldCombo->setCurrentIndex(idx);
253       else {
254         myVectorialFieldCombo->addItem(thePrs->GetVectorialFieldName());
255         myVectorialFieldCombo->setCurrentIndex(myVectorialFieldCombo->count()-1);
256       }
257     }
258   }
259     
260   hasInit = true;
261   // init table
262   myCutPlanes = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
263   myCutPlanes->SameAs(thePrs);
264   DrawTable();
265
266   // Draw Preview
267   if (myPreviewCheck->isChecked()) {
268     createPlanes();
269   }
270 }
271
272 void VisuGUI_CutPlanesPane::InitEntity2VectorialFieldsMap(VISU::ColoredPrs3d_i* thePrs){
273
274   VISU::Result_var theResult = thePrs->GetResultObject();
275   VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>(GetServant(theResult).in());
276   VISU::Result::Entities_var aEntities = aResult->GetEntities(thePrs->GetMeshName());
277   VISU::Result::TimeStampNumbers_var aScalarTimeStamp = aResult->GetTimeStampNumbers(thePrs->GetMeshName(),
278                                                                                      thePrs->GetEntity(),
279                                                                                      thePrs->GetFieldName());
280   CORBA::Long aTimeStampNumber = aScalarTimeStamp->length();
281   
282   for(size_t iEntity = 0; iEntity < aEntities->length(); iEntity++){
283     VISU::Entity aEntity = aEntities[iEntity];
284     VISU::Result::EntityNames_var aFields = aResult->GetFields(thePrs->GetMeshName(),aEntity);
285     for(size_t iField = 0; iField < aFields->length(); iField++){
286
287       TVectorialFieldsList aVectorialFields;
288       VISU::Result::TimeStampNumbers_var aTimeStamps =  aResult->GetTimeStampNumbers(thePrs->GetMeshName(),aEntity,aFields[iField] );
289       
290       if((aResult->GetNumberOfComponents(thePrs->GetMeshName(),aEntity,aFields[iField] ) > 1) &&
291          (aTimeStamps->length() >= aTimeStampNumber)){
292         aVectorialFields.push_back(QString(aFields[iField].in()));
293       }
294       if(aVectorialFields.size() > 0){
295         myEntity2VectorialFields.insert(TEntVectPair(aEntity,aVectorialFields));
296       }
297     }
298   }
299 }
300
301 void VisuGUI_CutPlanesPane::InsertAllVectorialFields(){
302   TEntity2VectorialFields::const_iterator aFieldIter = myEntity2VectorialFields.begin();
303   for( ;aFieldIter != myEntity2VectorialFields.end();aFieldIter++ ){
304     TVectorialFieldsList aVectorialFields = aFieldIter->second;
305     for(size_t iField = 0;iField < aVectorialFields.size(); iField++)
306       myVectorialFieldCombo->addItem(aVectorialFields[iField]);
307   }
308 }
309
310 double VisuGUI_CutPlanesPane::getScaleFactor(){
311   return myScaleSpn->value();
312 }
313
314 void VisuGUI_CutPlanesPane::setScaleFactor(double theFactor)
315 {
316   double step = 0.1;
317   if (fabs(theFactor) > std::numeric_limits<double>::epsilon()) {
318     int degree = int(log10(fabs(theFactor))) - 1;
319     if (fabs(theFactor) < 1) {
320       // as logarithm value is negative in this case
321       // and it is truncated to the bigger integer
322       degree -= 1;
323     }
324     step = pow(10., double(degree));
325   }
326
327   myScaleSpn->setSingleStep(step);
328   myScaleSpn->setValue(theFactor);
329 }
330
331 void VisuGUI_CutPlanesPane::createPlanes()
332 {
333   if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
334   if (!(bool)myCutPlanes) return;
335   if (myPreviewActor != 0) return;
336
337   vtkDataSet* aDataSet = myCutPlanes->GetSpecificPL()->GetWarpVectorOutput();
338   if (!aDataSet->GetNumberOfCells()) {
339     onPreviewCheck(false);
340     return;
341   }
342   vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
343   aPlaneMapper->SetInput(aDataSet);
344   aPlaneMapper->ScalarVisibilityOff();
345
346   myPreviewActor = SALOME_Actor::New();
347   myPreviewActor->PickableOff();
348   myPreviewActor->SetMapper(aPlaneMapper);
349   aPlaneMapper->Delete();
350   VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
351 }
352
353 int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs)
354 {
355   thePrs->SetOrientation(getOrientaion(), getRotation1()*PI/180., getRotation2()*PI/180.);
356   thePrs->SetNbPlanes(getNbPlanes());
357   thePrs->SetDisplacement(myPosSpn->value());
358   for (int i = 0; i < getNbPlanes(); ++i) {
359     QTableWidgetItem* anItem = myPosTable->item(i, 1);
360     if (!anItem)
361       break;
362     if (anItem->checkState() != Qt::Checked )
363       thePrs->SetPlanePosition(i, myPosTable->item(i, 0)->text().toDouble());
364     else
365       thePrs->SetDefault(i);
366   }
367
368   thePrs->UseDeformation(GDeformation->isChecked());
369   
370   if(GDeformation->isChecked()){
371     TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
372     VISU::Entity anEntity;
373     QString aFieldName;
374     bool isInited = false;
375     for(;anIter != myEntity2VectorialFields.end();anIter++){
376       TVectorialFieldsList aFields = anIter->second;
377       for(int it = 0;it < aFields.size();it++)
378         if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){
379           anEntity = anIter->first;
380           aFieldName = aFields[it];
381           isInited = true;
382           break;
383         }
384       if(isInited)
385         break;
386     }
387     if(isInited)
388       thePrs->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
389     
390     thePrs->SetScale(myScaleSpn->value());
391   }
392   return 1;
393 }
394
395 /*!
396   Called when orientation is changed
397 */
398 void VisuGUI_CutPlanesPane::orientationChanged (int Id)
399 {
400   if ( RBxy->isChecked() ) { // RBxy->isChecked()
401     LabelRot1->setText(tr("LBL_ROT_X"));
402     LabelRot2->setText(tr("LBL_ROT_Y"));
403   } else if ( RByz->isChecked() ) { // RByz->isChecked()
404     LabelRot1->setText(tr("LBL_ROT_Y"));
405     LabelRot2->setText(tr("LBL_ROT_Z"));
406   } else if ( RBzx->isChecked() ) {
407     LabelRot1->setText(tr("LBL_ROT_Z"));
408     LabelRot2->setText(tr("LBL_ROT_X"));
409   }
410   DrawTable();
411 }
412
413 /*!
414   Sets planes orientation and position
415 */
416 void VisuGUI_CutPlanesPane::setPlanePos (const VISU::CutPlanes::Orientation orient)
417 {
418   if (orient == VISU::CutPlanes::XY)           // xy
419     {
420       RBxy->setChecked( true );
421       orientationChanged( 0 );
422     }
423   else if (orient == VISU::CutPlanes::YZ)       // yz
424     {
425       RByz->setChecked( true );
426       orientationChanged( 1 );
427     }
428   else                         // zx
429    {
430      RBzx->setChecked( true );
431      orientationChanged( 2 );
432    }
433
434 }
435
436 /*!
437   Gets planes orientation
438 */
439 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
440 {
441   VISU::CutPlanes::Orientation orient;
442   if ( RBxy->isChecked() )     // xy
443     orient = VISU::CutPlanes::XY;
444   else if ( RByz->isChecked() )     // yz
445     orient = VISU::CutPlanes::YZ;
446   else if ( RBzx->isChecked() )     // zx
447     orient = VISU::CutPlanes::ZX;
448   return orient;
449 }
450
451 /*!
452   Sets planes rotation
453 */
454 void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2)
455 {
456   Rot1->setValue( r1 );
457   Rot2->setValue( r2 );
458 }
459
460 void VisuGUI_CutPlanesPane::onScaleFactorChanged(double theFactor){
461   DrawTable();
462 }
463
464 void VisuGUI_CutPlanesPane::onVectorialFieldChanged(int pos){
465   InitVectorialField();
466   DrawTable();
467 }
468
469 void VisuGUI_CutPlanesPane::onDeformationCheck(bool Flag){
470   if(!(bool)myCutPlanes || !hasInit) return;
471   myCutPlanes->UseDeformation(Flag);
472   InitVectorialField();
473   DrawTable();
474 }
475
476 void VisuGUI_CutPlanesPane::InitVectorialField(){
477   if(myCutPlanes->IsDeformed()){
478     TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
479     VISU::Entity anEntity;
480     QString aFieldName;
481     bool isInited = false;
482     for(;anIter != myEntity2VectorialFields.end();anIter++){
483       TVectorialFieldsList aFields = anIter->second;
484       for(int it = 0;it < aFields.size();it++)
485         if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){
486           anEntity = anIter->first;
487           aFieldName = aFields[it];
488           isInited = true;
489           break;
490         }
491       if(isInited)
492         break;
493     }
494     if(isInited)
495       myCutPlanes->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
496   }
497 }
498
499 /*!
500   Draw the table of planes positions
501 */
502 void VisuGUI_CutPlanesPane::DrawTable()
503 {
504   if (!(bool)myCutPlanes) return;
505   if (!hasInit) return;
506
507   int aNbRows = myPosTable->rowCount();
508   int aNbPlanes = getNbPlanes();
509
510   myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
511   myCutPlanes->SetNbPlanes(aNbPlanes);
512   myCutPlanes->SetDisplacement(myPosSpn->value());
513   myCutPlanes->SetScale(getScaleFactor());
514   if (aNbRows>0)
515     for (int i = 0; i < aNbRows; ++i) {
516       QTableWidgetItem* aItem = myPosTable->item( i, 1 );
517       if (aItem == 0) break;
518       if (aItem->checkState() != Qt::Checked )
519         myCutPlanes->SetPlanePosition(i, myPosTable->item(i, 0)->text().toDouble());
520     }
521
522   if (aNbPlanes > aNbRows)
523     while( aNbPlanes > myPosTable->rowCount() )
524       myPosTable->insertRow( myPosTable->rowCount() );
525   else if (aNbPlanes < aNbRows)
526     myPosTable->setRowCount(aNbPlanes);
527
528   QStringList aLabels;
529   QString str("Plane# %1");
530   int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
531   for (int i = 0; i<aMin; i++) {
532     myPosTable->item( i, 0 )->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
533     myPosTable->item( i, 1 )->setCheckState( myCutPlanes->IsDefault(i) ? Qt::Checked : Qt::Unchecked);
534     aLabels.append( str.arg(i+1) );
535   }
536
537   //QHeader *vh = myPosTable->verticalHeader();
538   for (int i=aMin; i<aNbPlanes; i++) {
539     QTableWidgetItem* aEditItem = new QTableWidgetItem();
540     aEditItem->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
541     //aEditItem->setReplaceable(false);
542     //aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
543     Qt::ItemFlags aFlags = aEditItem->flags();
544     if ( myCutPlanes->IsDefault(i) )
545       aFlags |= Qt::ItemIsEnabled;
546     else
547       aFlags &= (~Qt::ItemIsEnabled);
548     myPosTable->setItem(i, 0, aEditItem);
549
550     /*QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
551     aCheck->setChecked(myCutPlanes->IsDefault(i));
552     aCheck->setReplaceable(false);*/
553     QTableWidgetItem* aCheck = new QTableWidgetItem();
554     aFlags = aCheck->flags();
555     //aFlags |=  Qt::ItemIsUserCheckable;
556     aFlags &=  (~Qt::ItemIsEditable);
557     aCheck->setFlags( aFlags );
558     aCheck->setCheckState( myCutPlanes->IsDefault(i) ?
559                            Qt::Checked : Qt::Unchecked );
560     myPosTable->setItem(i, 1, aCheck);
561
562     //vh->setLabel( i, str.arg(i+1) );
563     aLabels.append( str.arg(i+1) );
564   }
565   myPosTable->setVerticalHeaderLabels( aLabels );
566
567   // Update preview
568   if (myPreviewCheck->isChecked()) {
569     if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
570       myCutPlanes->GetPipeLine()->Update();
571       deletePlanes();
572       createPlanes();
573       vf->Repaint();
574     }
575   }
576 }
577
578 void VisuGUI_CutPlanesPane::setDefault (int all)
579 {
580   myPosTable->setCurrentCell(-1, 1);
581   myPosTable->clearSelection();
582   if (all == 0) return;
583   if (all == 1)
584     for (int i = 0; i < getNbPlanes(); ++i)
585       myPosTable->item( i, 1 )->setCheckState(Qt::Checked);
586   //((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
587
588   for (int i = 0; i < getNbPlanes(); ++i) {
589     if ( myPosTable->item( i, 1 )->checkState() == Qt::Checked )
590     {
591       myCutPlanes->SetDefault(i);
592       myPosTable->item( i, 0)->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
593       myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() &(~Qt::ItemIsEnabled ) );
594     }
595     else
596       myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() | Qt::ItemIsEnabled );
597   }
598 }
599
600 void VisuGUI_CutPlanesPane::onValueChanged (int theRow, int theCol)
601 {
602   QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
603   if ( !aModel )
604     return;
605   
606   if ( !myPosTable->item(theRow, 1) || !myPosTable->item(theRow, 0) )
607     return;
608
609   QModelIndex anIndex;
610
611   QTableWidgetItem* anItem = myPosTable->item(theRow, theCol);
612   if (!anItem )
613     return;
614
615   bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
616   if (theCol == 0 )
617   {
618     anIndex = aModel->index( theRow, 0 );
619     if ( !isDefault)
620       myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
621           
622             
623     if ( myPreviewCheck->isChecked() )
624     {
625       //Update Preview
626       if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
627       {
628         myCutPlanes->GetPipeLine()->Update();
629         deletePlanes();
630         createPlanes();
631         vf->Repaint();
632       }
633     }
634   }
635   else
636   {
637     anItem = myPosTable->item(theRow, 0);
638     Qt::ItemFlags flags = anItem->flags();
639     if ( isDefault )
640     {
641       myCutPlanes->SetDefault(theRow);
642       anIndex = aModel->index( theRow, 0 );
643       aModel->setData( anIndex, myCutPlanes->GetPlanePosition(theRow), Qt::DisplayRole );
644
645       /*if ( myPreviewCheck->isChecked() )
646         {
647         //not needed update presentation, because item->setFlags generates signal cellChanged() again
648         }*/
649       flags &= (~Qt::ItemIsEnabled );
650     }
651     else
652       flags |=  Qt::ItemIsEnabled;
653    
654     anItem->setFlags( flags );
655   }
656   
657   /*if (theCol == 0) {
658     bool isChanged = !anIndex.data().isNull();
659     QTableWidgetItem* anItem = myPosTable->item(theRow, 1);
660     if ( !anItem  )
661     {
662       anItem = new QTableWidgetItem();
663       myPosTable->setItem( theRow, 1, anItem );
664       Qt::ItemFlags flags = anItem->flags();
665       //flags |=  Qt::ItemIsUserCheckable;
666       flags &=  (~Qt::ItemIsEditable);
667       anItem->setFlags( flags );
668     }
669     anItem->setCheckState(!isChanged ? Qt::Checked : Qt::Unchecked);
670
671     if (myPreviewCheck->isChecked()) {
672       //Update Preview
673       if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
674         myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
675         myCutPlanes->GetPipeLine()->Update();
676         deletePlanes();
677         createPlanes();
678         vf->Repaint();
679       }
680     }
681   } else {
682     bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
683     QTableWidgetItem* anItem = myPosTable->item(theRow, 0);
684     if ( !anItem  )
685     {
686       anItem = new QTableWidgetItem();
687       myPosTable->setItem( theRow, 0, anItem );
688     }
689       
690     if (isDefault) {
691       myCutPlanes->SetDefault(theRow);
692       //myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
693       anIndex = aModel->index( theRow, 0 );
694       aModel->setData( anIndex, myCutPlanes->GetPlanePosition(theRow), Qt::DisplayRole );
695       anItem->setFlags( anItem->flags() | Qt::ItemIsEnabled );
696       if (myPreviewCheck->isChecked()) {
697         if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
698           //Update Preview
699           myCutPlanes->GetPipeLine()->Update();
700           deletePlanes();
701           createPlanes();
702           vf->Repaint();
703         }
704       }
705     }
706     //myPosTable->item(theRow, 0)->setEnabled(!isDefault);
707     anItem->setFlags( anItem->flags() &(~Qt::ItemIsEnabled ) );
708     }*/
709 }
710
711 void VisuGUI_CutPlanesPane::deletePlanes()
712 {
713   if (myPreviewActor == 0) return;
714   vtkRenderer* aRend       = myPreviewActor->GetRenderer();
715   vtkRenderWindow* aWnd = aRend->GetRenderWindow();
716
717   if(aRend && aWnd)
718     myPreviewActor->RemoveFromRender(aRend);
719 //  Bug IPAL11962: preview is still in the viewer, if viewer not active.
720 //   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
721 //     vf->RemoveActor(myPreviewActor);
722   myPreviewActor->Delete();
723   myPreviewActor = 0;
724 }
725
726 void VisuGUI_CutPlanesPane::onRotation (double theValue)
727 {
728   if (!(bool)myCutPlanes) return;
729   if (myPreviewCheck->isChecked()) {
730     if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
731       myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
732       myCutPlanes->GetPipeLine()->Update();
733       deletePlanes();
734       createPlanes();
735       vf->Repaint();
736     }
737   }
738 }
739
740 void VisuGUI_CutPlanesPane::onPreviewCheck (bool thePreview)
741 {
742   if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
743     if (thePreview) {
744       storeToPrsObject(myCutPlanes);
745       myCutPlanes->GetPipeLine()->Update();
746       createPlanes();
747       if(VISU::GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)) {
748         vf->onFitAll();
749       }
750     } else {
751       deletePlanes();
752       vf->Repaint();
753     }
754   }
755 }
756
757 //###################################################################
758
759
760 /*!
761   Constructor
762 */
763 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg (SalomeApp_Module* theModule)
764   : VisuGUI_ScalarBarBaseDlg(theModule)
765 {
766   setWindowTitle("Cut Planes Definition");
767   setSizeGripEnabled(true);
768
769   QVBoxLayout* TopLayout = new QVBoxLayout (this);
770   TopLayout->setSpacing(6);
771   TopLayout->setMargin(11);
772
773   // Tab pane
774   myTabBox = new QTabWidget(this);
775   myCutPane = new VisuGUI_CutPlanesPane(this/*, myMgr*/);
776   myTabBox->addTab(myCutPane, "Cut Planes");
777   myInputPane = new VisuGUI_InputPane(VISU::TCUTPLANES, theModule, this);
778   myTabBox->addTab(GetScalarPane(), "Scalar Bar");
779   myTabBox->addTab(myInputPane, "Input");
780
781   TopLayout->addWidget(myTabBox);
782
783   QGroupBox* GroupButtons = new QGroupBox(this);
784   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
785   GroupButtons->setTitle("");
786   //GroupButtons->setColumnLayout(0, Qt::Vertical);
787   //GroupButtons->layout()->setSpacing(0);
788   //GroupButtons->layout()->setMargin(0);
789   QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
790   GroupButtonsLayout->setAlignment(Qt::AlignTop);
791   GroupButtonsLayout->setSpacing(6);
792   GroupButtonsLayout->setMargin(11);
793
794   QPushButton* buttonOk = new QPushButton(tr("BUT_OK"), GroupButtons);
795   buttonOk->setAutoDefault(TRUE);
796   buttonOk->setDefault(TRUE);
797   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
798   GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
799
800   QPushButton* buttonCancel = new QPushButton(tr("BUT_CANCEL"), GroupButtons);
801   buttonCancel->setAutoDefault(TRUE);
802   GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
803
804   QPushButton* buttonHelp = new QPushButton(tr("BUT_HELP"), GroupButtons);
805   buttonHelp->setAutoDefault(TRUE);
806   GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
807
808   TopLayout->addWidget(GroupButtons);
809
810   connect(buttonOk,     SIGNAL(clicked()), this, SLOT(accept()));
811   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
812   connect(buttonHelp,   SIGNAL(clicked()), this, SLOT(onHelp()));
813 }
814
815 VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
816 {}
817
818 void VisuGUI_CutPlanesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
819                                                bool theInit )
820 {
821   if( theInit )
822     myPrsCopy = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
823
824   VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
825
826   myCutPane->initFromPrsObject(myPrsCopy);
827
828   if( !theInit )
829     return;
830
831   myInputPane->initFromPrsObject( myPrsCopy );
832   myTabBox->setCurrentIndex( 0 );
833 }
834
835 int VisuGUI_CutPlanesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
836 {
837   if(!myInputPane->check() || !GetScalarPane()->check())
838     return 0;
839
840   int anIsOk = myInputPane->storeToPrsObject(myPrsCopy);
841   anIsOk &= GetScalarPane()->storeToPrsObject(myPrsCopy);
842   anIsOk &= myCutPane->storeToPrsObject(myPrsCopy);
843
844   VISU::TSameAsFactory<VISU::TCUTPLANES>().Copy(myPrsCopy, thePrs);
845
846   return anIsOk;
847 }
848
849 void VisuGUI_CutPlanesDlg::accept()
850 {
851   VisuGUI_ScalarBarBaseDlg::accept();
852 }
853
854 void VisuGUI_CutPlanesDlg::reject() {
855   VisuGUI_ScalarBarBaseDlg::reject();
856 }
857
858 QString VisuGUI_CutPlanesDlg::GetContextHelpFilePath()
859 {
860   return "cut_planes_page.html";
861 }
862
863 //###################################################################
864
865 /*QWidget* VisuGUI_NumEditItem::createEditor() const
866 {
867   QLineEdit *editline = new QLineEdit(text(), table()->viewport());
868   QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
869   dvalidator->setDecimals(32);
870   editline->setValidator(dvalidator);
871   return editline;
872 }*/