1 // Copyright (C) 2007-2012 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
28 #include "VisuGUI_CutPlanesDlg.h"
30 #include "VISU_ColoredPrs3dFactory.hh"
33 #include "VisuGUI_Tools.h"
34 #include "VisuGUI_ViewTools.h"
35 #include "VisuGUI_InputPane.h"
37 #include "VISU_ColoredPrs3dFactory.hh"
38 #include "VISU_CutPlanes_i.hh"
39 #include "VISU_Result_i.hh"
40 #include "VISU_CutPlanesPL.hxx"
42 //#include "OB_Browser.h"
44 #include "VISU_TableDlg.h"
46 #include "SVTK_ViewWindow.h"
48 #include "LightApp_Application.h"
50 #include <SalomeApp_IntSpinBox.h>
51 #include <SalomeApp_DoubleSpinBox.h>
53 #include "SUIT_Application.h"
54 #include "SUIT_Desktop.h"
55 #include "SUIT_ViewWindow.h"
56 #include "SUIT_ViewManager.h"
57 #include "SUIT_Session.h"
58 #include "SUIT_MessageBox.h"
59 #include "SUIT_ResourceMgr.h"
63 #include <QButtonGroup>
70 #include <QRadioButton>
71 #include <QTableWidget>
73 #include <QPushButton>
74 #include <QHeaderView>
77 #include <vtkRenderer.h>
78 #include <vtkPolyData.h>
79 #include <vtkAppendPolyData.h>
80 #include <vtkDataSetMapper.h>
81 #include <vtkDataSet.h>
87 //extern VisuGUI *visuGUI;
89 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent)
90 : QFrame(theParent), myPreviewActor(0)
92 QGridLayout* TopLayout = new QGridLayout( this );
93 TopLayout->setSpacing( 6 );
94 TopLayout->setMargin( 10 );
96 QButtonGroup* SelPlane = new QButtonGroup ( this );
97 QGroupBox* aGB = new QGroupBox( tr("TXT_ORIENTATION"), this );
98 //SelPlane->setTitle(tr("TXT_ORIENTATION"));
99 //SelPlane->setColumnLayout(0, Qt::Vertical);
100 //SelPlane->layout()->setSpacing( 0 );
101 //SelPlane->layout()->setMargin( 0 );
102 QGridLayout* SelPlaneLayout = new QGridLayout( aGB );
103 SelPlaneLayout->setAlignment( Qt::AlignTop );
104 SelPlaneLayout->setSpacing( 6 );
105 SelPlaneLayout->setMargin( 11 );
107 RBxy = new QRadioButton (tr("PARALLEL_XOY"), aGB);
108 RByz = new QRadioButton (tr("PARALLEL_YOZ"), aGB);
109 RBzx = new QRadioButton (tr("PARALLEL_ZOX"), aGB);
110 SelPlaneLayout->addWidget( RBxy, 0, 0 );
111 SelPlaneLayout->addWidget( RByz, 0, 1 );
112 SelPlaneLayout->addWidget( RBzx, 0, 2 );
113 SelPlane->addButton( RBxy );
114 SelPlane->addButton( RByz );
115 SelPlane->addButton( RBzx );
117 QLabel* LabelPosi_3 = new QLabel (tr("LBL_NB_PLANS"), this);
119 nbPlan = new SalomeApp_IntSpinBox( this );
120 nbPlan->setAcceptNames( false );
121 nbPlan->setMinimum( 1 );
122 nbPlan->setMaximum(100);
123 nbPlan->setSingleStep( 1 );
124 nbPlan->setValue( 1 );
125 nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
127 myPosTable = new QTableWidget (this);
128 myPosTable->setMaximumHeight( 227 );
129 myPosTable->setMinimumWidth( 294 );
130 myPosTable->setColumnCount(2);
131 myPosTable->setRowCount(0);
132 connect( myPosTable, SIGNAL(cellChanged(int, int)), this, SLOT(onValueChanged(int, int)) );
134 myPosTable->setItemDelegateForColumn( 0,
135 new NumDelegateItem( myPosTable, NumDelegateItem::NV_Real) );
137 myPosTable->setEditTriggers(
138 (QAbstractItemView::EditTriggers)(QAbstractItemView::AllEditTriggers &(~QAbstractItemView::CurrentChanged)));
141 aLabels.append( tr("Position") );
142 aLabels.append( tr("Set default") );
144 myPosTable->setHorizontalHeaderLabels( aLabels );
146 QGroupBox* GBrot = new QGroupBox (tr("LBL_ROTATION"), this);
147 //GBrot->setColumnLayout(0, Qt::Vertical);
148 //GBrot->layout()->setSpacing( 0 );
149 //GBrot->layout()->setMargin( 0 );
150 QGridLayout* GBrotLayout = new QGridLayout( GBrot );
151 GBrotLayout->setAlignment( Qt::AlignTop );
152 GBrotLayout->setSpacing( 6 );
153 GBrotLayout->setMargin( 11 );
155 LabelRot1 = new QLabel (tr("LBL_ROT_X"), GBrot );
156 GBrotLayout->addWidget( LabelRot1, 0, 0 );
158 Rot1 = new SalomeApp_DoubleSpinBox( GBrot );
159 VISU::initSpinBox( Rot1, -180., 180., 10., "angle_precision" );
161 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
162 connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
163 GBrotLayout->addWidget( Rot1, 0, 1 );
165 LabelRot2 = new QLabel (tr("LBL_ROT_Y"), GBrot );
166 GBrotLayout->addWidget( LabelRot2, 1, 0 );
168 Rot2 = new SalomeApp_DoubleSpinBox( GBrot );
169 VISU::initSpinBox( Rot2, -180., 180., 10., "angle_precision" );
171 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
172 connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
173 GBrotLayout->addWidget( Rot2, 1, 1 );
175 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
176 myPosSpn = new SalomeApp_DoubleSpinBox( this );
177 VISU::initSpinBox( myPosSpn, 0., 1., .1, "parametric_precision" );
179 GDeformation = new QGroupBox(tr("LBL_DEFORMATION"), this);
180 GDeformation->setCheckable(true);
181 GDeformation->setChecked(false);
182 QGridLayout* GDeformationLayout = new QGridLayout( GDeformation );
183 GDeformationLayout->setSpacing( 6 );
184 GDeformationLayout->setMargin( 11 );
185 connect(GDeformation, SIGNAL(toggled(bool)), this, SLOT(onDeformationCheck(bool)));
187 QLabel* LabelDeformation1 = new QLabel (tr("LBL_DEFROMATION_VECT"), GDeformation);
188 GDeformationLayout->addWidget( LabelDeformation1, 0, 0 );
190 myVectorialFieldCombo = new QComboBox (GDeformation);
191 GDeformationLayout->addWidget( myVectorialFieldCombo, 0, 1 );
193 QLabel* LabelDeformation2 = new QLabel (tr("LBL_DEFROMATION_SCALE"), GDeformation);
194 GDeformationLayout->addWidget( LabelDeformation2, 1, 0 );
195 myScaleSpn = new SalomeApp_DoubleSpinBox (GDeformation);
196 VISU::initSpinBox( myScaleSpn, 0., 1.0E+38, 0.1, "visual_data_precision" );
197 myScaleSpn->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
198 GDeformationLayout->addWidget( myScaleSpn, 1, 1 );
199 connect(myVectorialFieldCombo, SIGNAL(activated(int)), this, SLOT(onVectorialFieldChanged(int)));
200 connect(myScaleSpn, SIGNAL(valueChanged(double)), this, SLOT(onScaleFactorChanged(double)));
201 myScaleSpn->setValue(0.1);
203 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
204 myPreviewCheck->setChecked(false);
205 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
207 TopLayout->addWidget( aGB, 0, 0, 1, 2 );
208 TopLayout->addWidget( GBrot, 1, 0, 1, 2 );
209 TopLayout->addWidget( LabelPosi_3, 2, 0 );
210 TopLayout->addWidget( nbPlan, 2, 1 );
211 TopLayout->addWidget( myPosTable, 3, 0, 1, 2 );
212 TopLayout->setRowStretch ( 3, 3 );
213 TopLayout->addWidget(aPosLbl, 4, 0 );
214 TopLayout->addWidget(myPosSpn, 4, 1 );
215 TopLayout->addWidget( GDeformation, 5, 0, 1, 2 );
216 TopLayout->addWidget( myPreviewCheck, 6, 0, 1, 2 );
218 // signals and slots connections
219 connect( SelPlane, SIGNAL( buttonClicked( int )), this, SLOT( orientationChanged( int ) ) );
220 connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
221 connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
222 connect( myPosTable->horizontalHeader(), SIGNAL( sectionClicked(int)), this, SLOT( setDefault(int) ) );
229 RByz->setChecked( true );
231 } // End of Constructor
233 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
236 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
240 void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs)
242 setNbPlanes(thePrs->GetNbPlanes());
243 setRotation(thePrs->GetRotateX()*180./M_PI, thePrs->GetRotateY()*180./M_PI);
244 setPlanePos(thePrs->GetOrientationType());
245 myPosSpn->setValue(thePrs->GetDisplacement());
246 InitEntity2VectorialFieldsMap(thePrs);
247 InsertAllVectorialFields();
248 setScaleFactor(thePrs->GetScale());
249 if(myEntity2VectorialFields.size() < 1)
250 GDeformation->setDisabled(true);
252 if(thePrs->IsDeformed()){
253 GDeformation->setChecked(true);
254 int idx = myVectorialFieldCombo->findText(thePrs->GetVectorialFieldName());
256 myVectorialFieldCombo->setCurrentIndex(idx);
258 myVectorialFieldCombo->addItem(thePrs->GetVectorialFieldName());
259 myVectorialFieldCombo->setCurrentIndex(myVectorialFieldCombo->count()-1);
266 myCutPlanes = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
267 myCutPlanes->SameAs(thePrs);
271 if (myPreviewCheck->isChecked()) {
276 void VisuGUI_CutPlanesPane::InitEntity2VectorialFieldsMap(VISU::ColoredPrs3d_i* thePrs){
278 VISU::Result_var theResult = thePrs->GetResultObject();
279 VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>(GetServant(theResult).in());
280 VISU::Result::Entities_var aEntities = aResult->GetEntities(thePrs->GetMeshName());
281 VISU::Result::TimeStampNumbers_var aScalarTimeStamp = aResult->GetTimeStampNumbers(thePrs->GetMeshName(),
283 thePrs->GetFieldName());
284 CORBA::Long aTimeStampNumber = aScalarTimeStamp->length();
286 for(size_t iEntity = 0; iEntity < aEntities->length(); iEntity++){
287 VISU::Entity aEntity = aEntities[iEntity];
288 VISU::Result::EntityNames_var aFields = aResult->GetFields(thePrs->GetMeshName(),aEntity);
289 for(size_t iField = 0; iField < aFields->length(); iField++){
291 TVectorialFieldsList aVectorialFields;
292 VISU::Result::TimeStampNumbers_var aTimeStamps = aResult->GetTimeStampNumbers(thePrs->GetMeshName(),aEntity,aFields[iField] );
294 if((aResult->GetNumberOfComponents(thePrs->GetMeshName(),aEntity,aFields[iField] ) > 1) &&
295 (aTimeStamps->length() >= aTimeStampNumber)){
296 aVectorialFields.push_back(QString(aFields[iField].in()));
298 if(aVectorialFields.size() > 0){
299 myEntity2VectorialFields.insert(TEntVectPair(aEntity,aVectorialFields));
305 void VisuGUI_CutPlanesPane::InsertAllVectorialFields(){
306 TEntity2VectorialFields::const_iterator aFieldIter = myEntity2VectorialFields.begin();
307 for( ;aFieldIter != myEntity2VectorialFields.end();aFieldIter++ ){
308 TVectorialFieldsList aVectorialFields = aFieldIter->second;
309 for(size_t iField = 0;iField < aVectorialFields.size(); iField++)
310 myVectorialFieldCombo->addItem(aVectorialFields[iField]);
314 double VisuGUI_CutPlanesPane::getScaleFactor(){
315 return myScaleSpn->value();
318 void VisuGUI_CutPlanesPane::setScaleFactor(double theFactor)
321 if (fabs(theFactor) > std::numeric_limits<double>::epsilon()) {
322 int degree = int(log10(fabs(theFactor))) - 1;
323 if (fabs(theFactor) < 1) {
324 // as logarithm value is negative in this case
325 // and it is truncated to the bigger integer
328 step = pow(10., double(degree));
331 myScaleSpn->setSingleStep(step);
332 myScaleSpn->setValue(theFactor);
335 void VisuGUI_CutPlanesPane::createPlanes()
337 if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
338 if (!(bool)myCutPlanes) return;
339 if (myPreviewActor != 0) return;
341 vtkDataSet* aDataSet = myCutPlanes->GetSpecificPL()->GetWarpVectorOutput();
342 if (!aDataSet->GetNumberOfCells()) {
343 onPreviewCheck(false);
346 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
347 aPlaneMapper->SetInput(aDataSet);
348 aPlaneMapper->ScalarVisibilityOff();
350 myPreviewActor = SALOME_Actor::New();
351 myPreviewActor->PickableOff();
352 myPreviewActor->SetMapper(aPlaneMapper);
353 aPlaneMapper->Delete();
354 VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
357 int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs)
359 thePrs->SetOrientation(getOrientaion(), getRotation1()*M_PI/180., getRotation2()*M_PI/180.);
360 thePrs->SetNbPlanes(getNbPlanes());
361 thePrs->SetDisplacement(myPosSpn->value());
362 for (int i = 0; i < getNbPlanes(); ++i) {
363 QTableWidgetItem* anItem = myPosTable->item(i, 1);
366 if (anItem->checkState() != Qt::Checked )
367 thePrs->SetPlanePosition(i, myPosTable->item(i, 0)->text().toDouble());
369 thePrs->SetDefault(i);
372 thePrs->UseDeformation(GDeformation->isChecked());
374 if(GDeformation->isChecked()){
375 TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
376 VISU::Entity anEntity;
378 bool isInited = false;
379 for(;anIter != myEntity2VectorialFields.end();anIter++){
380 TVectorialFieldsList aFields = anIter->second;
381 for(int it = 0;it < aFields.size();it++)
382 if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){
383 anEntity = anIter->first;
384 aFieldName = aFields[it];
392 thePrs->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
394 thePrs->SetScale(myScaleSpn->value());
400 Called when orientation is changed
402 void VisuGUI_CutPlanesPane::orientationChanged (int Id)
404 if ( RBxy->isChecked() ) { // RBxy->isChecked()
405 LabelRot1->setText(tr("LBL_ROT_X"));
406 LabelRot2->setText(tr("LBL_ROT_Y"));
407 } else if ( RByz->isChecked() ) { // RByz->isChecked()
408 LabelRot1->setText(tr("LBL_ROT_Y"));
409 LabelRot2->setText(tr("LBL_ROT_Z"));
410 } else if ( RBzx->isChecked() ) {
411 LabelRot1->setText(tr("LBL_ROT_Z"));
412 LabelRot2->setText(tr("LBL_ROT_X"));
418 Sets planes orientation and position
420 void VisuGUI_CutPlanesPane::setPlanePos (const VISU::CutPlanes::Orientation orient)
422 if (orient == VISU::CutPlanes::XY) // xy
424 RBxy->setChecked( true );
425 orientationChanged( 0 );
427 else if (orient == VISU::CutPlanes::YZ) // yz
429 RByz->setChecked( true );
430 orientationChanged( 1 );
434 RBzx->setChecked( true );
435 orientationChanged( 2 );
441 Gets planes orientation
443 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
445 VISU::CutPlanes::Orientation orient;
446 if ( RBxy->isChecked() ) // xy
447 orient = VISU::CutPlanes::XY;
448 else if ( RByz->isChecked() ) // yz
449 orient = VISU::CutPlanes::YZ;
450 else if ( RBzx->isChecked() ) // zx
451 orient = VISU::CutPlanes::ZX;
458 void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2)
460 Rot1->setValue( r1 );
461 Rot2->setValue( r2 );
464 void VisuGUI_CutPlanesPane::onScaleFactorChanged(double theFactor){
468 void VisuGUI_CutPlanesPane::onVectorialFieldChanged(int pos){
469 InitVectorialField();
473 void VisuGUI_CutPlanesPane::onDeformationCheck(bool Flag){
474 if(!(bool)myCutPlanes || !hasInit) return;
475 myCutPlanes->UseDeformation(Flag);
476 InitVectorialField();
480 void VisuGUI_CutPlanesPane::InitVectorialField(){
481 if(myCutPlanes->IsDeformed()){
482 TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
483 VISU::Entity anEntity;
485 bool isInited = false;
486 for(;anIter != myEntity2VectorialFields.end();anIter++){
487 TVectorialFieldsList aFields = anIter->second;
488 for(int it = 0;it < aFields.size();it++)
489 if(!QString::compare(aFields[it], myVectorialFieldCombo->currentText ())){
490 anEntity = anIter->first;
491 aFieldName = aFields[it];
499 myCutPlanes->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
504 Draw the table of planes positions
506 void VisuGUI_CutPlanesPane::DrawTable()
508 if (!(bool)myCutPlanes) return;
509 if (!hasInit) return;
511 int aNbRows = myPosTable->rowCount();
512 int aNbPlanes = getNbPlanes();
514 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*M_PI/180.,getRotation2()*M_PI/180.);
515 myCutPlanes->SetNbPlanes(aNbPlanes);
516 myCutPlanes->SetDisplacement(myPosSpn->value());
517 myCutPlanes->SetScale(getScaleFactor());
519 for (int i = 0; i < aNbRows; ++i) {
520 QTableWidgetItem* aItem = myPosTable->item( i, 1 );
521 if (aItem == 0) break;
522 if (aItem->checkState() != Qt::Checked )
523 myCutPlanes->SetPlanePosition(i, myPosTable->item(i, 0)->text().toDouble());
526 if (aNbPlanes > aNbRows)
527 while( aNbPlanes > myPosTable->rowCount() )
528 myPosTable->insertRow( myPosTable->rowCount() );
529 else if (aNbPlanes < aNbRows)
530 myPosTable->setRowCount(aNbPlanes);
533 QString str(tr("PLANE_NUMBER"));
534 int aMin = (aNbRows < aNbPlanes)? aNbRows : aNbPlanes;
535 for (int i = 0; i<aMin; i++) {
536 myPosTable->item( i, 0 )->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
537 myPosTable->item( i, 1 )->setCheckState( myCutPlanes->IsDefault(i) ? Qt::Checked : Qt::Unchecked);
538 aLabels.append( str.arg(i+1) );
541 //QHeader *vh = myPosTable->verticalHeader();
542 for (int i=aMin; i<aNbPlanes; i++) {
543 QTableWidgetItem* aEditItem = new QTableWidgetItem();
544 aEditItem->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
545 //aEditItem->setReplaceable(false);
546 //aEditItem->setEnabled(!myCutPlanes->IsDefault(i));
547 Qt::ItemFlags aFlags = aEditItem->flags();
548 if ( myCutPlanes->IsDefault(i) )
549 aFlags |= Qt::ItemIsEnabled;
551 aFlags &= (~Qt::ItemIsEnabled);
552 myPosTable->setItem(i, 0, aEditItem);
554 /*QCheckTableItem* aCheck = new QCheckTableItem(myPosTable, 0);
555 aCheck->setChecked(myCutPlanes->IsDefault(i));
556 aCheck->setReplaceable(false);*/
557 QTableWidgetItem* aCheck = new QTableWidgetItem();
558 aFlags = aCheck->flags();
559 //aFlags |= Qt::ItemIsUserCheckable;
560 aFlags &= (~Qt::ItemIsEditable);
561 aCheck->setFlags( aFlags );
562 aCheck->setCheckState( myCutPlanes->IsDefault(i) ?
563 Qt::Checked : Qt::Unchecked );
564 myPosTable->setItem(i, 1, aCheck);
566 //vh->setLabel( i, str.arg(i+1) );
567 aLabels.append( str.arg(i+1) );
569 myPosTable->setVerticalHeaderLabels( aLabels );
572 if (myPreviewCheck->isChecked()) {
573 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
574 myCutPlanes->GetPipeLine()->Update();
582 void VisuGUI_CutPlanesPane::setDefault (int all)
584 myPosTable->setCurrentCell(-1, 1);
585 myPosTable->clearSelection();
586 if (all == 0) return;
588 for (int i = 0; i < getNbPlanes(); ++i)
589 myPosTable->item( i, 1 )->setCheckState(Qt::Checked);
590 //((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
592 for (int i = 0; i < getNbPlanes(); ++i) {
593 if ( myPosTable->item( i, 1 )->checkState() == Qt::Checked )
595 myCutPlanes->SetDefault(i);
596 myPosTable->item( i, 0)->setText( QString::number(myCutPlanes->GetPlanePosition(i)));
597 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() &(~Qt::ItemIsEnabled ) );
600 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() | Qt::ItemIsEnabled );
604 void VisuGUI_CutPlanesPane::onValueChanged (int theRow, int theCol)
606 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
610 if ( !myPosTable->item(theRow, 1) || !myPosTable->item(theRow, 0) )
615 QTableWidgetItem* anItem = myPosTable->item(theRow, theCol);
619 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
622 anIndex = aModel->index( theRow, 0 );
624 myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
627 if ( myPreviewCheck->isChecked() )
630 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
632 myCutPlanes->GetPipeLine()->Update();
641 anItem = myPosTable->item(theRow, 0);
642 Qt::ItemFlags flags = anItem->flags();
645 myCutPlanes->SetDefault(theRow);
646 anIndex = aModel->index( theRow, 0 );
647 aModel->setData( anIndex, myCutPlanes->GetPlanePosition(theRow), Qt::DisplayRole );
649 /*if ( myPreviewCheck->isChecked() )
651 //not needed update presentation, because item->setFlags generates signal cellChanged() again
653 flags &= (~Qt::ItemIsEnabled );
656 flags |= Qt::ItemIsEnabled;
658 anItem->setFlags( flags );
662 bool isChanged = !anIndex.data().isNull();
663 QTableWidgetItem* anItem = myPosTable->item(theRow, 1);
666 anItem = new QTableWidgetItem();
667 myPosTable->setItem( theRow, 1, anItem );
668 Qt::ItemFlags flags = anItem->flags();
669 //flags |= Qt::ItemIsUserCheckable;
670 flags &= (~Qt::ItemIsEditable);
671 anItem->setFlags( flags );
673 anItem->setCheckState(!isChanged ? Qt::Checked : Qt::Unchecked);
675 if (myPreviewCheck->isChecked()) {
677 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
678 myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
679 myCutPlanes->GetPipeLine()->Update();
686 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
687 QTableWidgetItem* anItem = myPosTable->item(theRow, 0);
690 anItem = new QTableWidgetItem();
691 myPosTable->setItem( theRow, 0, anItem );
695 myCutPlanes->SetDefault(theRow);
696 //myPosTable->setText(theRow, 0, QString::number(myCutPlanes->GetPlanePosition(theRow)));
697 anIndex = aModel->index( theRow, 0 );
698 aModel->setData( anIndex, myCutPlanes->GetPlanePosition(theRow), Qt::DisplayRole );
699 anItem->setFlags( anItem->flags() | Qt::ItemIsEnabled );
700 if (myPreviewCheck->isChecked()) {
701 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
703 myCutPlanes->GetPipeLine()->Update();
710 //myPosTable->item(theRow, 0)->setEnabled(!isDefault);
711 anItem->setFlags( anItem->flags() &(~Qt::ItemIsEnabled ) );
715 void VisuGUI_CutPlanesPane::deletePlanes()
717 if (myPreviewActor == 0) return;
718 vtkRenderer* aRend = myPreviewActor->GetRenderer();
719 vtkRenderWindow* aWnd = aRend->GetRenderWindow();
722 myPreviewActor->RemoveFromRender(aRend);
723 // Bug IPAL11962: preview is still in the viewer, if viewer not active.
724 // if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
725 // vf->RemoveActor(myPreviewActor);
726 myPreviewActor->Delete();
730 void VisuGUI_CutPlanesPane::onRotation (double theValue)
732 if (!(bool)myCutPlanes) return;
733 if (myPreviewCheck->isChecked()) {
734 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
735 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*M_PI/180.,getRotation2()*M_PI/180.);
736 myCutPlanes->GetPipeLine()->Update();
744 void VisuGUI_CutPlanesPane::onPreviewCheck (bool thePreview)
746 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
748 storeToPrsObject(myCutPlanes);
749 myCutPlanes->GetPipeLine()->Update();
751 if(VISU::GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false))
752 vf->onFitAll(); // Repaint() is called inside
762 //###################################################################
768 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg (SalomeApp_Module* theModule)
769 : VisuGUI_ScalarBarBaseDlg(theModule)
771 setWindowTitle(tr("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, tr("Cut Planes"));
782 myInputPane = new VisuGUI_InputPane(VISU::TCUTPLANES, theModule, this);
783 myTabBox->addTab(GetScalarPane(), tr("Scalar Bar"));
784 myTabBox->addTab(myInputPane, tr("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);