1 // Copyright (C) 2007-2008 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
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 "VisuGUI_TableDlg.h"
46 #include "SVTK_ViewWindow.h"
48 #include "LightApp_Application.h"
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"
60 #include <QButtonGroup>
68 #include <QRadioButton>
69 #include <QTableWidget>
71 #include <QPushButton>
72 #include <QHeaderView>
75 #include <vtkRenderer.h>
76 #include <vtkPolyData.h>
77 #include <vtkAppendPolyData.h>
78 #include <vtkDataSetMapper.h>
79 #include <vtkDataSet.h>
85 //extern VisuGUI *visuGUI;
87 VisuGUI_CutPlanesPane::VisuGUI_CutPlanesPane (QWidget* theParent)
88 : QFrame(theParent), myPreviewActor(0)
90 QGridLayout* TopLayout = new QGridLayout( this );
91 TopLayout->setSpacing( 6 );
92 TopLayout->setMargin( 10 );
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 );
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 );
115 QLabel* LabelPosi_3 = new QLabel (tr("LBL_NB_PLANS"), this);
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 ) );
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)) );
131 myPosTable->setItemDelegateForColumn( 0,
132 new NumDelegateItem( myPosTable, NumDelegateItem::NV_Real) );
134 myPosTable->setEditTriggers(
135 (QAbstractItemView::EditTriggers)(QAbstractItemView::AllEditTriggers &(~QAbstractItemView::CurrentChanged)));
138 aLabels.append( "Position" );
139 aLabels.append( "Set default" );
141 myPosTable->setHorizontalHeaderLabels( aLabels );
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 );
152 LabelRot1 = new QLabel (tr("LBL_ROT_X"), GBrot );
153 GBrotLayout->addWidget( LabelRot1, 0, 0 );
155 Rot1 = new QtxDoubleSpinBox( -180, 180, 10, GBrot );
157 Rot1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
158 connect( Rot1, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
159 GBrotLayout->addWidget( Rot1, 0, 1 );
161 LabelRot2 = new QLabel (tr("LBL_ROT_Y"), GBrot );
162 GBrotLayout->addWidget( LabelRot2, 1, 0 );
164 Rot2 = new QtxDoubleSpinBox( -180, 180, 10, GBrot );
166 Rot2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
167 connect( Rot2, SIGNAL( valueChanged( double )), this, SLOT( onRotation( double ) ) );
168 GBrotLayout->addWidget( Rot2, 1, 1 );
170 QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
171 myPosSpn = new QtxDoubleSpinBox( 0, 1, 0.1, this );
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)));
181 QLabel* LabelDeformation1 = new QLabel (tr("LBL_DEFROMATION_VECT"), GDeformation);
182 GDeformationLayout->addWidget( LabelDeformation1, 0, 0 );
184 myVectorialFieldCombo = new QComboBox (GDeformation);
185 GDeformationLayout->addWidget( myVectorialFieldCombo, 0, 1 );
187 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
188 int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
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);
199 myPreviewCheck = new QCheckBox(tr("LBL_SHOW_PREVIEW"), this);
200 myPreviewCheck->setChecked(false);
201 connect( myPreviewCheck, SIGNAL( toggled( bool )), this, SLOT( onPreviewCheck( bool ) ) );
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 );
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) ) );
225 RByz->setChecked( true );
227 } // End of Constructor
229 VisuGUI_CutPlanesPane::~VisuGUI_CutPlanesPane()
232 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
236 void VisuGUI_CutPlanesPane::initFromPrsObject (VISU::CutPlanes_i* thePrs)
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);
248 if(thePrs->IsDeformed()){
249 GDeformation->setChecked(true);
250 int idx = myVectorialFieldCombo->findText(thePrs->GetVectorialFieldName());
252 myVectorialFieldCombo->setCurrentIndex(idx);
254 myVectorialFieldCombo->addItem(thePrs->GetVectorialFieldName());
255 myVectorialFieldCombo->setCurrentIndex(myVectorialFieldCombo->count()-1);
262 myCutPlanes = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
263 myCutPlanes->SameAs(thePrs);
267 if (myPreviewCheck->isChecked()) {
272 void VisuGUI_CutPlanesPane::InitEntity2VectorialFieldsMap(VISU::ColoredPrs3d_i* thePrs){
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(),
279 thePrs->GetFieldName());
280 CORBA::Long aTimeStampNumber = aScalarTimeStamp->length();
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++){
287 TVectorialFieldsList aVectorialFields;
288 VISU::Result::TimeStampNumbers_var aTimeStamps = aResult->GetTimeStampNumbers(thePrs->GetMeshName(),aEntity,aFields[iField] );
290 if((aResult->GetNumberOfComponents(thePrs->GetMeshName(),aEntity,aFields[iField] ) > 1) &&
291 (aTimeStamps->length() >= aTimeStampNumber)){
292 aVectorialFields.push_back(QString(aFields[iField].in()));
294 if(aVectorialFields.size() > 0){
295 myEntity2VectorialFields.insert(TEntVectPair(aEntity,aVectorialFields));
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]);
310 double VisuGUI_CutPlanesPane::getScaleFactor(){
311 return myScaleSpn->value();
314 void VisuGUI_CutPlanesPane::setScaleFactor(double theFactor)
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
324 step = pow(10., double(degree));
327 myScaleSpn->setSingleStep(step);
328 myScaleSpn->setValue(theFactor);
331 void VisuGUI_CutPlanesPane::createPlanes()
333 if (VISU::GetActiveViewWindow<SVTK_ViewWindow>() == NULL) return;
334 if (!(bool)myCutPlanes) return;
335 if (myPreviewActor != 0) return;
337 vtkDataSet* aDataSet = myCutPlanes->GetSpecificPL()->GetWarpVectorOutput();
338 if (!aDataSet->GetNumberOfCells()) {
339 onPreviewCheck(false);
342 vtkDataSetMapper* aPlaneMapper = vtkDataSetMapper::New();
343 aPlaneMapper->SetInput(aDataSet);
344 aPlaneMapper->ScalarVisibilityOff();
346 myPreviewActor = SALOME_Actor::New();
347 myPreviewActor->PickableOff();
348 myPreviewActor->SetMapper(aPlaneMapper);
349 aPlaneMapper->Delete();
350 VISU::GetActiveViewWindow<SVTK_ViewWindow>()->AddActor(myPreviewActor);
353 int VisuGUI_CutPlanesPane::storeToPrsObject (VISU::CutPlanes_i* thePrs)
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);
362 if (anItem->checkState() != Qt::Checked )
363 thePrs->SetPlanePosition(i, myPosTable->item(i, 0)->text().toDouble());
365 thePrs->SetDefault(i);
368 thePrs->UseDeformation(GDeformation->isChecked());
370 if(GDeformation->isChecked()){
371 TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
372 VISU::Entity anEntity;
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];
388 thePrs->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
390 thePrs->SetScale(myScaleSpn->value());
396 Called when orientation is changed
398 void VisuGUI_CutPlanesPane::orientationChanged (int Id)
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"));
414 Sets planes orientation and position
416 void VisuGUI_CutPlanesPane::setPlanePos (const VISU::CutPlanes::Orientation orient)
418 if (orient == VISU::CutPlanes::XY) // xy
420 RBxy->setChecked( true );
421 orientationChanged( 0 );
423 else if (orient == VISU::CutPlanes::YZ) // yz
425 RByz->setChecked( true );
426 orientationChanged( 1 );
430 RBzx->setChecked( true );
431 orientationChanged( 2 );
437 Gets planes orientation
439 VISU::CutPlanes::Orientation VisuGUI_CutPlanesPane::getOrientaion()
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;
454 void VisuGUI_CutPlanesPane::setRotation (const double r1, const double r2)
456 Rot1->setValue( r1 );
457 Rot2->setValue( r2 );
460 void VisuGUI_CutPlanesPane::onScaleFactorChanged(double theFactor){
464 void VisuGUI_CutPlanesPane::onVectorialFieldChanged(int pos){
465 InitVectorialField();
469 void VisuGUI_CutPlanesPane::onDeformationCheck(bool Flag){
470 if(!(bool)myCutPlanes || !hasInit) return;
471 myCutPlanes->UseDeformation(Flag);
472 InitVectorialField();
476 void VisuGUI_CutPlanesPane::InitVectorialField(){
477 if(myCutPlanes->IsDeformed()){
478 TEntity2VectorialFields::const_iterator anIter = myEntity2VectorialFields.begin();
479 VISU::Entity anEntity;
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];
495 myCutPlanes->SetVectorialField(anEntity,aFieldName.toLatin1().constData());
500 Draw the table of planes positions
502 void VisuGUI_CutPlanesPane::DrawTable()
504 if (!(bool)myCutPlanes) return;
505 if (!hasInit) return;
507 int aNbRows = myPosTable->rowCount();
508 int aNbPlanes = getNbPlanes();
510 myCutPlanes->SetOrientation(getOrientaion(),getRotation1()*PI/180.,getRotation2()*PI/180.);
511 myCutPlanes->SetNbPlanes(aNbPlanes);
512 myCutPlanes->SetDisplacement(myPosSpn->value());
513 myCutPlanes->SetScale(getScaleFactor());
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());
522 if (aNbPlanes > aNbRows)
523 while( aNbPlanes > myPosTable->rowCount() )
524 myPosTable->insertRow( myPosTable->rowCount() );
525 else if (aNbPlanes < aNbRows)
526 myPosTable->setRowCount(aNbPlanes);
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) );
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;
547 aFlags &= (~Qt::ItemIsEnabled);
548 myPosTable->setItem(i, 0, aEditItem);
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);
562 //vh->setLabel( i, str.arg(i+1) );
563 aLabels.append( str.arg(i+1) );
565 myPosTable->setVerticalHeaderLabels( aLabels );
568 if (myPreviewCheck->isChecked()) {
569 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
570 myCutPlanes->GetPipeLine()->Update();
578 void VisuGUI_CutPlanesPane::setDefault (int all)
580 myPosTable->setCurrentCell(-1, 1);
581 myPosTable->clearSelection();
582 if (all == 0) return;
584 for (int i = 0; i < getNbPlanes(); ++i)
585 myPosTable->item( i, 1 )->setCheckState(Qt::Checked);
586 //((QCheckTableItem*)myPosTable->item( i, 1 ))->setChecked(true);
588 for (int i = 0; i < getNbPlanes(); ++i) {
589 if ( myPosTable->item( i, 1 )->checkState() == Qt::Checked )
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 ) );
596 myPosTable->item( i, 0 )->setFlags( myPosTable->item( i, 0 )->flags() | Qt::ItemIsEnabled );
600 void VisuGUI_CutPlanesPane::onValueChanged (int theRow, int theCol)
602 QAbstractTableModel* aModel = qobject_cast<QAbstractTableModel*>( myPosTable->model() );
606 if ( !myPosTable->item(theRow, 1) || !myPosTable->item(theRow, 0) )
611 QTableWidgetItem* anItem = myPosTable->item(theRow, theCol);
615 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
618 anIndex = aModel->index( theRow, 0 );
620 myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
623 if ( myPreviewCheck->isChecked() )
626 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>())
628 myCutPlanes->GetPipeLine()->Update();
637 anItem = myPosTable->item(theRow, 0);
638 Qt::ItemFlags flags = anItem->flags();
641 myCutPlanes->SetDefault(theRow);
642 anIndex = aModel->index( theRow, 0 );
643 aModel->setData( anIndex, myCutPlanes->GetPlanePosition(theRow), Qt::DisplayRole );
645 /*if ( myPreviewCheck->isChecked() )
647 //not needed update presentation, because item->setFlags generates signal cellChanged() again
649 flags &= (~Qt::ItemIsEnabled );
652 flags |= Qt::ItemIsEnabled;
654 anItem->setFlags( flags );
658 bool isChanged = !anIndex.data().isNull();
659 QTableWidgetItem* anItem = myPosTable->item(theRow, 1);
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 );
669 anItem->setCheckState(!isChanged ? Qt::Checked : Qt::Unchecked);
671 if (myPreviewCheck->isChecked()) {
673 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
674 myCutPlanes->SetPlanePosition( theRow, anIndex.data().toDouble());
675 myCutPlanes->GetPipeLine()->Update();
682 bool isDefault = myPosTable->item(theRow, 1)->checkState() == Qt::Checked;
683 QTableWidgetItem* anItem = myPosTable->item(theRow, 0);
686 anItem = new QTableWidgetItem();
687 myPosTable->setItem( theRow, 0, anItem );
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>()) {
699 myCutPlanes->GetPipeLine()->Update();
706 //myPosTable->item(theRow, 0)->setEnabled(!isDefault);
707 anItem->setFlags( anItem->flags() &(~Qt::ItemIsEnabled ) );
711 void VisuGUI_CutPlanesPane::deletePlanes()
713 if (myPreviewActor == 0) return;
714 vtkRenderer* aRend = myPreviewActor->GetRenderer();
715 vtkRenderWindow* aWnd = aRend->GetRenderWindow();
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();
726 void VisuGUI_CutPlanesPane::onRotation (double theValue)
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();
740 void VisuGUI_CutPlanesPane::onPreviewCheck (bool thePreview)
742 if (SVTK_ViewWindow* vf = VISU::GetActiveViewWindow<SVTK_ViewWindow>()) {
744 storeToPrsObject(myCutPlanes);
745 myCutPlanes->GetPipeLine()->Update();
747 if(VISU::GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)) {
757 //###################################################################
763 VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg (SalomeApp_Module* theModule)
764 : VisuGUI_ScalarBarBaseDlg(theModule)
766 setWindowTitle("Cut Planes Definition");
767 setSizeGripEnabled(true);
769 QVBoxLayout* TopLayout = new QVBoxLayout (this);
770 TopLayout->setSpacing(6);
771 TopLayout->setMargin(11);
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");
781 TopLayout->addWidget(myTabBox);
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);
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);
800 QPushButton* buttonCancel = new QPushButton(tr("BUT_CANCEL"), GroupButtons);
801 buttonCancel->setAutoDefault(TRUE);
802 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
804 QPushButton* buttonHelp = new QPushButton(tr("BUT_HELP"), GroupButtons);
805 buttonHelp->setAutoDefault(TRUE);
806 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
808 TopLayout->addWidget(GroupButtons);
810 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
811 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
812 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
815 VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
818 void VisuGUI_CutPlanesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
822 myPrsCopy = VISU::TSameAsFactory<VISU::TCUTPLANES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
824 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
826 myCutPane->initFromPrsObject(myPrsCopy);
831 myInputPane->initFromPrsObject( myPrsCopy );
832 myTabBox->setCurrentIndex( 0 );
835 int VisuGUI_CutPlanesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
837 if(!myInputPane->check() || !GetScalarPane()->check())
840 int anIsOk = myInputPane->storeToPrsObject(myPrsCopy);
841 anIsOk &= GetScalarPane()->storeToPrsObject(myPrsCopy);
842 anIsOk &= myCutPane->storeToPrsObject(myPrsCopy);
844 VISU::TSameAsFactory<VISU::TCUTPLANES>().Copy(myPrsCopy, thePrs);
849 void VisuGUI_CutPlanesDlg::accept()
851 VisuGUI_ScalarBarBaseDlg::accept();
854 void VisuGUI_CutPlanesDlg::reject() {
855 VisuGUI_ScalarBarBaseDlg::reject();
858 QString VisuGUI_CutPlanesDlg::GetContextHelpFilePath()
860 return "cut_planes_page.html";
863 //###################################################################
865 /*QWidget* VisuGUI_NumEditItem::createEditor() const
867 QLineEdit *editline = new QLineEdit(text(), table()->viewport());
868 QDoubleValidator *dvalidator = new QDoubleValidator(table()->viewport());
869 dvalidator->setDecimals(32);
870 editline->setValidator(dvalidator);