1 // Copyright (C) 2007-2010 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
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_CutPlanesDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_CutPlanesDlg.h"
31 #include "VISU_ColoredPrs3dFactory.hh"
34 #include "VisuGUI_Tools.h"
35 #include "VisuGUI_ViewTools.h"
36 #include "VisuGUI_InputPane.h"
38 #include "VISU_ColoredPrs3dFactory.hh"
39 #include "VISU_CutPlanes_i.hh"
40 #include "VISU_Result_i.hh"
41 #include "VISU_CutPlanesPL.hxx"
43 //#include "OB_Browser.h"
45 #include "VISU_TableDlg.h"
47 #include "SVTK_ViewWindow.h"
49 #include "LightApp_Application.h"
51 #include <SalomeApp_IntSpinBox.h>
52 #include <SalomeApp_DoubleSpinBox.h>
54 #include "SUIT_Application.h"
55 #include "SUIT_Desktop.h"
56 #include "SUIT_ViewWindow.h"
57 #include "SUIT_ViewManager.h"
58 #include "SUIT_Session.h"
59 #include "SUIT_MessageBox.h"
60 #include "SUIT_ResourceMgr.h"
64 #include <QButtonGroup>
71 #include <QRadioButton>
72 #include <QTableWidget>
74 #include <QPushButton>
75 #include <QHeaderView>
78 #include <vtkRenderer.h>
79 #include <vtkPolyData.h>
80 #include <vtkAppendPolyData.h>
81 #include <vtkDataSetMapper.h>
82 #include <vtkDataSet.h>
88 //extern VisuGUI *visuGUI;
90 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent)
91 : QFrame(theParent), myPreviewActor(0)
93 QGridLayout* TopLayout = new QGridLayout( this );
94 TopLayout->setSpacing( 6 );
95 TopLayout->setMargin( 10 );
97 QButtonGroup* SelPlane = new QButtonGroup ( this );
98 QGroupBox* aGB = new QGroupBox( tr("TXT_ORIENTATION"), this );
99 //SelPlane->setTitle(tr("TXT_ORIENTATION"));
100 //SelPlane->setColumnLayout(0, Qt::Vertical);
101 //SelPlane->layout()->setSpacing( 0 );
102 //SelPlane->layout()->setMargin( 0 );
103 QGridLayout* SelPlaneLayout = new QGridLayout( aGB );
104 SelPlaneLayout->setAlignment( Qt::AlignTop );
105 SelPlaneLayout->setSpacing( 6 );
106 SelPlaneLayout->setMargin( 11 );
108 RBxy = new QRadioButton (tr("PARALLEL_XOY"), aGB);
109 RByz = new QRadioButton (tr("PARALLEL_YOZ"), aGB);
110 RBzx = new QRadioButton (tr("PARALLEL_ZOX"), aGB);
111 SelPlaneLayout->addWidget( RBxy, 0, 0 );
112 SelPlaneLayout->addWidget( RByz, 0, 1 );
113 SelPlaneLayout->addWidget( RBzx, 0, 2 );
114 SelPlane->addButton( RBxy );
115 SelPlane->addButton( RByz );
116 SelPlane->addButton( RBzx );
118 QLabel* LabelPosi_3 = new QLabel (tr("LBL_NB_PLANS"), this);
120 nbPlan = new SalomeApp_IntSpinBox( this );
121 nbPlan->setAcceptNames( false );
122 nbPlan->setMinimum( 1 );
123 nbPlan->setMaximum(100);
124 nbPlan->setSingleStep( 1 );
125 nbPlan->setValue( 1 );
126 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
128 myPosTable = new QTableWidget (this);
129 myPosTable->setMaximumHeight( 227 );
130 myPosTable->setMinimumWidth( 294 );
131 myPosTable->setColumnCount(2);
132 myPosTable->setRowCount(0);
133 connect( myPosTable, SIGNAL(cellChanged(int, int)), this, SLOT(onValueChanged(int, int)) );
135 myPosTable->setItemDelegateForColumn( 0,
136 new NumDelegateItem( myPosTable, NumDelegateItem::NV_Real) );
138 myPosTable->setEditTriggers(
139 (QAbstractItemView::EditTriggers)(QAbstractItemView::AllEditTriggers &(~QAbstractItemView::CurrentChanged)));
142 aLabels.append( "Position" );
143 aLabels.append( "Set default" );
145 myPosTable->setHorizontalHeaderLabels( aLabels );
147 QGroupBox* GBrot = new QGroupBox (tr("LBL_ROTATION"), this);
148 //GBrot->setColumnLayout(0, Qt::Vertical);
149 //GBrot->layout()->setSpacing( 0 );
150 //GBrot->layout()->setMargin( 0 );
151 QGridLayout* GBrotLayout = new QGridLayout( GBrot );
152 GBrotLayout->setAlignment( Qt::AlignTop );
153 GBrotLayout->setSpacing( 6 );
154 GBrotLayout->setMargin( 11 );
156 LabelRot1 = new QLabel (tr("LBL_ROT_X"), GBrot );
157 GBrotLayout->addWidget( LabelRot1, 0, 0 );
159 Rot1 = new SalomeApp_DoubleSpinBox( GBrot );
160 VISU::initSpinBox( Rot1, -180., 180., 10., "angle_precision" );
162 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
163 connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
164 GBrotLayout->addWidget( Rot1, 0, 1 );
166 LabelRot2 = new QLabel (tr("LBL_ROT_Y"), GBrot );
167 GBrotLayout->addWidget( LabelRot2, 1, 0 );
169 Rot2 = new SalomeApp_DoubleSpinBox( GBrot );
170 VISU::initSpinBox( Rot2, -180., 180., 10., "angle_precision" );
172 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
173 connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
174 GBrotLayout->addWidget( Rot2, 1, 1 );
176 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
177 myPosSpn = new SalomeApp_DoubleSpinBox( this );
178 VISU::initSpinBox( myPosSpn, 0., 1., .1, "parametric_precision" );
180 GDeformation = new QGroupBox(tr("LBL_DEFORMATION"), this);
181 GDeformation->setCheckable(true);
182 GDeformation->setChecked(false);
183 QGridLayout* GDeformationLayout = new QGridLayout( GDeformation );
184 GDeformationLayout->setSpacing( 6 );
185 GDeformationLayout->setMargin( 11 );
186 connect(GDeformation, SIGNAL(toggled(bool)), this, SLOT(onDeformationCheck(bool)));
188 QLabel* LabelDeformation1 = new QLabel (tr("LBL_DEFROMATION_VECT"), GDeformation);
189 GDeformationLayout->addWidget( LabelDeformation1, 0, 0 );
191 myVectorialFieldCombo = new QComboBox (GDeformation);
192 GDeformationLayout->addWidget( myVectorialFieldCombo, 0, 1 );
194 QLabel* LabelDeformation2 = new QLabel (tr("LBL_DEFROMATION_SCALE"), GDeformation);
195 GDeformationLayout->addWidget( LabelDeformation2, 1, 0 );
196 myScaleSpn = new SalomeApp_DoubleSpinBox (GDeformation);
197 VISU::initSpinBox( myScaleSpn, 0., 1.0E+38, 0.1, "visual_data_precision" );
198 myScaleSpn->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
199 GDeformationLayout->addWidget( myScaleSpn, 1, 1 );
200 connect(myVectorialFieldCombo, SIGNAL(activated(int)), this, SLOT(onVectorialFieldChanged(int)));
201 connect(myScaleSpn, SIGNAL(valueChanged(double)), this, SLOT(onScaleFactorChanged(double)));
202 myScaleSpn->setValue(0.1);
204 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
205 myPreviewCheck->setChecked(false);
206 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
208 TopLayout->addWidget( aGB, 0, 0, 1, 2 );
209 TopLayout->addWidget( GBrot, 1, 0, 1, 2 );
210 TopLayout->addWidget( LabelPosi_3, 2, 0 );
211 TopLayout->addWidget( nbPlan, 2, 1 );
212 TopLayout->addWidget( myPosTable, 3, 0, 1, 2 );
213 TopLayout->setRowStretch ( 3, 3 );
214 TopLayout->addWidget(aPosLbl, 4, 0 );
215 TopLayout->addWidget(myPosSpn, 4, 1 );
216 TopLayout->addWidget( GDeformation, 5, 0, 1, 2 );
217 TopLayout->addWidget( myPreviewCheck, 6, 0, 1, 2 );
219 // signals and slots connections
220 connect( SelPlane, SIGNAL( buttonClicked( int )), this, SLOT( orientationChanged( int ) ) );
221 connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
222 connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
223 connect( myPosTable->horizontalHeader(), SIGNAL( sectionClicked(int)), this, SLOT( setDefault(int) ) );
230 RByz->setChecked( true );
232 } // End of Constructor
234 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
237 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
241 void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs)
243 setNbPlanes(thePrs->GetNbPlanes());
244 setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
245 setPlanePos(thePrs->GetOrientationType());
246 myPosSpn->setValue(thePrs->GetDisplacement());
247 InitEntity2VectorialFieldsMap(thePrs);
248 InsertAllVectorialFields();
249 setScaleFactor(thePrs->GetScale());
250 if(myEntity2VectorialFields.size() < 1)
251 GDeformation->setDisabled(true);
253 if(thePrs->IsDeformed()){
254 GDeformation->setChecked(true);
255 int idx = myVectorialFieldCombo->findText(thePrs->GetVectorialFieldName());
257 myVectorialFieldCombo->setCurrentIndex(idx);
259 myVectorialFieldCombo->addItem(thePrs->GetVectorialFieldName());
260 myVectorialFieldCombo->setCurrentIndex(myVectorialFieldCombo->count()-1);
267 myCutPlanes = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
268 myCutPlanes->SameAs(thePrs);
272 if (myPreviewCheck->isChecked()) {
277 void VisuGUI_CutPlanesPane::InitEntity2VectorialFieldsMap(VISU::ColoredPrs3d_i* thePrs){
279 VISU::Result_var theResult = thePrs->GetResultObject();
280 VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>(GetServant(theResult).in());
281 VISU::Result::Entities_var aEntities = aResult->GetEntities(thePrs->GetMeshName());
282 VISU::Result::TimeStampNumbers_var aScalarTimeStamp = aResult->GetTimeStampNumbers(thePrs->GetMeshName(),
284 thePrs->GetFieldName());
285 CORBA::Long aTimeStampNumber = aScalarTimeStamp->length();
287 for(size_t iEntity = 0; iEntity < aEntities->length(); iEntity++){
288 VISU::Entity aEntity = aEntities[iEntity];
289 VISU::Result::EntityNames_var aFields = aResult->GetFields(thePrs->GetMeshName(),aEntity);
290 for(size_t iField = 0; iField < aFields->length(); iField++){
292 TVectorialFieldsList aVectorialFields;
293 VISU::Result::TimeStampNumbers_var aTimeStamps = aResult->GetTimeStampNumbers(thePrs->GetMeshName(),aEntity,aFields[iField] );
295 if((aResult->GetNumberOfComponents(thePrs->GetMeshName(),aEntity,aFields[iField] ) > 1) &&
296 (aTimeStamps->length() >= aTimeStampNumber)){
297 aVectorialFields.push_back(QString(aFields[iField].in()));
299 if(aVectorialFields.size() > 0){
300 myEntity2VectorialFields.insert(TEntVectPair(aEntity,aVectorialFields));
306 void VisuGUI_CutPlanesPane::InsertAllVectorialFields(){
307 TEntity2VectorialFields::const_iterator aFieldIter = myEntity2VectorialFields.begin();
308 for( ;aFieldIter != myEntity2VectorialFields.end();aFieldIter++ ){
309 TVectorialFieldsList aVectorialFields = aFieldIter->second;
310 for(size_t iField = 0;iField < aVectorialFields.size(); iField++)
311 myVectorialFieldCombo->addItem(aVectorialFields[iField]);
315 double VisuGUI_CutPlanesPane::getScaleFactor(){
316 return myScaleSpn->value();
319 void VisuGUI_CutPlanesPane::setScaleFactor(double theFactor)
322 if (fabs(theFactor) > std::numeric_limits<double>::epsilon()) {
323 int degree = int(log10(fabs(theFactor))) - 1;
324 if (fabs(theFactor) < 1) {
325 // as logarithm value is negative in this case
326 // and it is truncated to the bigger integer
329 step = pow(10., double(degree));
332 myScaleSpn->setSingleStep(step);
333 myScaleSpn->setValue(theFactor);
336 void VisuGUI_CutPlanesPane::createPlanes()
338 if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
339 if (!(bool)myCutPlanes) return;
340 if (myPreviewActor != 0) return;
342 vtkDataSet* aDataSet = myCutPlanes->GetSpecificPL()->GetWarpVectorOutput();
343 if (!aDataSet->GetNumberOfCells()) {
344 onPreviewCheck(false);
347 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
348 aPlaneMapper->SetInput(aDataSet);
349 aPlaneMapper->ScalarVisibilityOff();
351 myPreviewActor = SALOME_Actor::New();
352 myPreviewActor->PickableOff();
353 myPreviewActor->SetMapper(aPlaneMapper);
354 aPlaneMapper->Delete();
355 VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
358 int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs)
360 thePrs->SetOrientation(getOrientaion(), getRotation1()*PI/180., getRotation2()*PI/180.);
361 thePrs->SetNbPlanes(getNbPlanes());
362 thePrs->SetDisplacement(myPosSpn->value());
363 for (int i = 0; i < getNbPlanes(); ++i) {
364 QTableWidgetItem* anItem = myPosTable->item(i, 1);
367 if (anItem->checkState() != Qt::Checked )
368 thePrs->SetPlanePosition(i, myPosTable->item(i, 0)->text().toDouble());
370 thePrs->SetDefault(i);
373 thePrs->UseDeformation(GDeformation->isChecked());
375 if(GDeformation->isChecked()){
376 TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
377 VISU::Entity anEntity;
379 bool isInited = false;
380 for(;anIter != myEntity2VectorialFields.end();anIter++){
381 TVectorialFieldsList aFields = anIter->second;
382 for(int it = 0;it < aFields.size();it++)
383 if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){
384 anEntity = anIter->first;
385 aFieldName = aFields[it];
393 thePrs->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
395 thePrs->SetScale(myScaleSpn->value());
401 Called when orientation is changed
403 void VisuGUI_CutPlanesPane::orientationChanged (int Id)
405 if ( RBxy->isChecked() ) { // RBxy->isChecked()
406 LabelRot1->setText(tr("LBL_ROT_X"));
407 LabelRot2->setText(tr("LBL_ROT_Y"));
408 } else if ( RByz->isChecked() ) { // RByz->isChecked()
409 LabelRot1->setText(tr("LBL_ROT_Y"));
410 LabelRot2->setText(tr("LBL_ROT_Z"));
411 } else if ( RBzx->isChecked() ) {
412 LabelRot1->setText(tr("LBL_ROT_Z"));
413 LabelRot2->setText(tr("LBL_ROT_X"));
419 Sets planes orientation and position
421 void VisuGUI_CutPlanesPane::setPlanePos (const VISU::CutPlanes::Orientation orient)
423 if (orient == VISU::CutPlanes::XY) // xy
425 RBxy->setChecked( true );
426 orientationChanged( 0 );
428 else if (orient == VISU::CutPlanes::YZ) // yz
430 RByz->setChecked( true );
431 orientationChanged( 1 );
435 RBzx->setChecked( true );
436 orientationChanged( 2 );
442 Gets planes orientation
444 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
446 VISU::CutPlanes::Orientation orient;
447 if ( RBxy->isChecked() ) // xy
448 orient = VISU::CutPlanes::XY;
449 else if ( RByz->isChecked() ) // yz
450 orient = VISU::CutPlanes::YZ;
451 else if ( RBzx->isChecked() ) // zx
452 orient = VISU::CutPlanes::ZX;
459 void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2)
461 Rot1->setValue( r1 );
462 Rot2->setValue( r2 );
465 void VisuGUI_CutPlanesPane::onScaleFactorChanged(double theFactor){
469 void VisuGUI_CutPlanesPane::onVectorialFieldChanged(int pos){
470 InitVectorialField();
474 void VisuGUI_CutPlanesPane::onDeformationCheck(bool Flag){
475 if(!(bool)myCutPlanes || !hasInit) return;
476 myCutPlanes->UseDeformation(Flag);
477 InitVectorialField();
481 void VisuGUI_CutPlanesPane::InitVectorialField(){
482 if(myCutPlanes->IsDeformed()){
483 TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
484 VISU::Entity anEntity;
486 bool isInited = false;
487 for(;anIter != myEntity2VectorialFields.end();anIter++){
488 TVectorialFieldsList aFields = anIter->second;
489 for(int it = 0;it < aFields.size();it++)
490 if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){
491 anEntity = anIter->first;
492 aFieldName = aFields[it];
500 myCutPlanes->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
505 Draw the table of planes positions
507 void VisuGUI_CutPlanesPane::DrawTable()
509 if (!(bool)myCutPlanes) return;
510 if (!hasInit) return;
512 int aNbRows = myPosTable->rowCount();
513 int aNbPlanes = getNbPlanes();
515 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
516 myCutPlanes->SetNbPlanes(aNbPlanes);
517 myCutPlanes->SetDisplacement(myPosSpn->value());
518 myCutPlanes->SetScale(getScaleFactor());
520 for (int i = 0; i < aNbRows; ++i) {
521 QTableWidgetItem* aItem = myPosTable->item( i, 1 );
522 if (aItem == 0) break;
523 if (aItem->checkState() != Qt::Checked )
524 myCutPlanes->SetPlanePosition(i, myPosTable->item(i, 0)->text().toDouble());
527 if (aNbPlanes > aNbRows)
528 while( aNbPlanes > myPosTable->rowCount() )
529 myPosTable->insertRow( myPosTable->rowCount() );
530 else if (aNbPlanes < aNbRows)
531 myPosTable->setRowCount(aNbPlanes);
534 QString str("Plane# %1");
535 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
536 for (int i = 0; i<aMin; i++) {
537 myPosTable->item( i, 0 )->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
538 myPosTable->item( i, 1 )->setCheckState( myCutPlanes->IsDefault(i) ? Qt::Checked : Qt::Unchecked);
539 aLabels.append( str.arg(i+1) );
542 //QHeader *vh = myPosTable->verticalHeader();
543 for (int i=aMin; i<aNbPlanes; i++) {
544 QTableWidgetItem* aEditItem = new QTableWidgetItem();
545 aEditItem->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
546 //aEditItem->setReplaceable(false);
547 //aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
548 Qt::ItemFlags aFlags = aEditItem->flags();
549 if ( myCutPlanes->IsDefault(i) )
550 aFlags |= Qt::ItemIsEnabled;
552 aFlags &= (~Qt::ItemIsEnabled);
553 myPosTable->setItem(i, 0, aEditItem);
555 /*QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
556 aCheck->setChecked(myCutPlanes->IsDefault(i));
557 aCheck->setReplaceable(false);*/
558 QTableWidgetItem* aCheck = new QTableWidgetItem();
559 aFlags = aCheck->flags();
560 //aFlags |= Qt::ItemIsUserCheckable;
561 aFlags &= (~Qt::ItemIsEditable);
562 aCheck->setFlags( aFlags );
563 aCheck->setCheckState( myCutPlanes->IsDefault(i) ?
564 Qt::Checked : Qt::Unchecked );
565 myPosTable->setItem(i, 1, aCheck);
567 //vh->setLabel( i, str.arg(i+1) );
568 aLabels.append( str.arg(i+1) );
570 myPosTable->setVerticalHeaderLabels( aLabels );
573 if (myPreviewCheck->isChecked()) {
574 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
575 myCutPlanes->GetPipeLine()->Update();
583 void VisuGUI_CutPlanesPane::setDefault (int all)
585 myPosTable->setCurrentCell(-1, 1);
586 myPosTable->clearSelection();
587 if (all == 0) return;
589 for (int i = 0; i < getNbPlanes(); ++i)
590 myPosTable->item( i, 1 )->setCheckState(Qt::Checked);
591 //((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
593 for (int i = 0; i < getNbPlanes(); ++i) {
594 if ( myPosTable->item( i, 1 )->checkState() == Qt::Checked )
596 myCutPlanes->SetDefault(i);
597 myPosTable->item( i, 0)->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
598 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() &(~Qt::ItemIsEnabled ) );
601 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() | Qt::ItemIsEnabled );
605 void VisuGUI_CutPlanesPane::onValueChanged (int theRow, int theCol)
607 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
611 if ( !myPosTable->item(theRow, 1) || !myPosTable->item(theRow, 0) )
616 QTableWidgetItem* anItem = myPosTable->item(theRow, theCol);
620 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
623 anIndex = aModel->index( theRow, 0 );
625 myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
628 if ( myPreviewCheck->isChecked() )
631 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
633 myCutPlanes->GetPipeLine()->Update();
642 anItem = myPosTable->item(theRow, 0);
643 Qt::ItemFlags flags = anItem->flags();
646 myCutPlanes->SetDefault(theRow);
647 anIndex = aModel->index( theRow, 0 );
648 aModel->setData( anIndex, myCutPlanes->GetPlanePosition(theRow), Qt::DisplayRole );
650 /*if ( myPreviewCheck->isChecked() )
652 //not needed update presentation, because item->setFlags generates signal cellChanged() again
654 flags &= (~Qt::ItemIsEnabled );
657 flags |= Qt::ItemIsEnabled;
659 anItem->setFlags( flags );
663 bool isChanged = !anIndex.data().isNull();
664 QTableWidgetItem* anItem = myPosTable->item(theRow, 1);
667 anItem = new QTableWidgetItem();
668 myPosTable->setItem( theRow, 1, anItem );
669 Qt::ItemFlags flags = anItem->flags();
670 //flags |= Qt::ItemIsUserCheckable;
671 flags &= (~Qt::ItemIsEditable);
672 anItem->setFlags( flags );
674 anItem->setCheckState(!isChanged ? Qt::Checked : Qt::Unchecked);
676 if (myPreviewCheck->isChecked()) {
678 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
679 myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
680 myCutPlanes->GetPipeLine()->Update();
687 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
688 QTableWidgetItem* anItem = myPosTable->item(theRow, 0);
691 anItem = new QTableWidgetItem();
692 myPosTable->setItem( theRow, 0, anItem );
696 myCutPlanes->SetDefault(theRow);
697 //myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
698 anIndex = aModel->index( theRow, 0 );
699 aModel->setData( anIndex, myCutPlanes->GetPlanePosition(theRow), Qt::DisplayRole );
700 anItem->setFlags( anItem->flags() | Qt::ItemIsEnabled );
701 if (myPreviewCheck->isChecked()) {
702 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
704 myCutPlanes->GetPipeLine()->Update();
711 //myPosTable->item(theRow, 0)->setEnabled(!isDefault);
712 anItem->setFlags( anItem->flags() &(~Qt::ItemIsEnabled ) );
716 void VisuGUI_CutPlanesPane::deletePlanes()
718 if (myPreviewActor == 0) return;
719 vtkRenderer* aRend = myPreviewActor->GetRenderer();
720 vtkRenderWindow* aWnd = aRend->GetRenderWindow();
723 myPreviewActor->RemoveFromRender(aRend);
724 // Bug IPAL11962: preview is still in the viewer, if viewer not active.
725 // if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
726 // vf->RemoveActor(myPreviewActor);
727 myPreviewActor->Delete();
731 void VisuGUI_CutPlanesPane::onRotation (double theValue)
733 if (!(bool)myCutPlanes) return;
734 if (myPreviewCheck->isChecked()) {
735 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
736 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
737 myCutPlanes->GetPipeLine()->Update();
745 void VisuGUI_CutPlanesPane::onPreviewCheck (bool thePreview)
747 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
749 storeToPrsObject(myCutPlanes);
750 myCutPlanes->GetPipeLine()->Update();
752 if(VISU::GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)) {
762 //###################################################################
768 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg (SalomeApp_Module* theModule)
769 : VisuGUI_ScalarBarBaseDlg(theModule)
771 setWindowTitle("Cut Planes Definition");
772 setSizeGripEnabled(true);
774 QVBoxLayout* TopLayout = new QVBoxLayout (this);
775 TopLayout->setSpacing(6);
776 TopLayout->setMargin(11);
779 myTabBox = new QTabWidget(this);
780 myCutPane = new VisuGUI_CutPlanesPane(this/*, myMgr*/);
781 myTabBox->addTab(myCutPane, "Cut Planes");
782 myInputPane = new VisuGUI_InputPane(VISU::TCUTPLANES, theModule, this);
783 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
784 myTabBox->addTab(myInputPane, "Input");
786 TopLayout->addWidget(myTabBox);
788 QGroupBox* GroupButtons = new QGroupBox(this);
789 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
790 GroupButtons->setTitle("");
791 //GroupButtons->setColumnLayout(0, Qt::Vertical);
792 //GroupButtons->layout()->setSpacing(0);
793 //GroupButtons->layout()->setMargin(0);
794 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
795 GroupButtonsLayout->setAlignment(Qt::AlignTop);
796 GroupButtonsLayout->setSpacing(6);
797 GroupButtonsLayout->setMargin(11);
799 QPushButton* buttonOk = new QPushButton(tr("BUT_OK"), GroupButtons);
800 buttonOk->setAutoDefault(TRUE);
801 buttonOk->setDefault(TRUE);
802 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
803 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
805 QPushButton* buttonCancel = new QPushButton(tr("BUT_CANCEL"), GroupButtons);
806 buttonCancel->setAutoDefault(TRUE);
807 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
809 QPushButton* buttonHelp = new QPushButton(tr("BUT_HELP"), GroupButtons);
810 buttonHelp->setAutoDefault(TRUE);
811 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
813 TopLayout->addWidget(GroupButtons);
815 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
816 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
817 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
820 VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
823 void VisuGUI_CutPlanesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
827 myPrsCopy = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
829 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
831 myCutPane->initFromPrsObject(myPrsCopy);
836 myInputPane->initFromPrsObject( myPrsCopy );
837 myTabBox->setCurrentIndex( 0 );
840 int VisuGUI_CutPlanesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
842 if(!myInputPane->check() || !GetScalarPane()->check())
845 int anIsOk = myInputPane->storeToPrsObject(myPrsCopy);
846 anIsOk &= GetScalarPane()->storeToPrsObject(myPrsCopy);
847 anIsOk &= myCutPane->storeToPrsObject(myPrsCopy);
849 VISU::TSameAsFactory<VISU::TCUTPLANES>().Copy(myPrsCopy, thePrs);
854 void VisuGUI_CutPlanesDlg::accept()
856 VisuGUI_ScalarBarBaseDlg::accept();
859 void VisuGUI_CutPlanesDlg::reject() {
860 VisuGUI_ScalarBarBaseDlg::reject();
863 QString VisuGUI_CutPlanesDlg::GetContextHelpFilePath()
865 return "cut_planes_page.html";
868 //###################################################################
870 /*QWidget* VisuGUI_NumEditItem::createEditor() const
872 QLineEdit *editline = new QLineEdit(text(), table()->viewport());
873 QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
874 dvalidator->setDecimals(32);
875 editline->setValidator(dvalidator);