1 // Copyright (C) 2007-2013 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 // File : EntityGUI_FieldDlg.cxx
24 #include "EntityGUI_FieldDlg.h"
28 #include <GEOMBase_Skeleton.h>
29 #include <GEOM_Displayer.h>
30 #include <GeometryGUI.h>
32 #include <SalomeApp_Application.h>
33 #include <SalomeApp_Study.h>
34 #include <SalomeApp_Tools.h>
35 #include <SalomeApp_IntSpinBox.h>
36 #include <SalomeApp_DoubleSpinBox.h>
38 #include <LightApp_SelectionMgr.h>
40 #include <OCCViewer_ViewModel.h>
41 #include <OCCViewer_ViewManager.h>
42 #include <SVTK_ViewModel.h>
43 #include <SALOME_Prs.h>
44 #include <SALOME_ListIteratorOfListIO.hxx>
46 #include <SUIT_Desktop.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_OverrideCursor.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_ViewWindow.h>
52 #include <SUIT_ViewManager.h>
55 #include <QGridLayout>
57 #include <QHeaderView>
60 #include <QPushButton>
61 #include <QTableWidget>
62 #include <QVBoxLayout>
64 #include <AIS_ListOfInteractive.hxx>
65 #include <AIS_ListIteratorOfListOfInteractive.hxx>
68 #include <TopExp_Explorer.hxx>
69 #include <TopTools_IndexedMapOfShape.hxx>
70 #include <TColStd_IndexedMapOfInteger.hxx>
71 #include <TColStd_MapOfInteger.hxx>
72 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
76 #include <SALOMEDS_wrap.hxx>
77 #include <GEOMImpl_Types.hxx>
84 const int theIntLimit = std::numeric_limits<int>::max() - 10;
87 Class : EntityGUI_FieldDlg::CheckItem
88 Description : Bool item.
90 class EntityGUI_FieldDlg::CheckItem : public QTableWidgetItem
95 CheckItem( bool = false );
98 void setValue( bool );
102 int EntityGUI_FieldDlg::CheckItem::Type()
104 return QTableWidgetItem::UserType + 2;
107 EntityGUI_FieldDlg::CheckItem::CheckItem( bool value )
108 : QTableWidgetItem( Type() )
110 Qt::ItemFlags f = flags();
111 f = f | Qt::ItemIsUserCheckable;
112 f = f & ~Qt::ItemIsTristate;
113 f = f & ~Qt::ItemIsEditable;
118 EntityGUI_FieldDlg::CheckItem::~CheckItem()
122 void EntityGUI_FieldDlg::CheckItem::setValue( bool value )
124 setCheckState( value ? Qt::Checked : Qt::Unchecked );
127 bool EntityGUI_FieldDlg::CheckItem::value() const
129 return checkState() == Qt::Checked;
133 Class : EntityGUI_FieldDlg::IntSpinItem
134 Description : Integer spin table item.
137 class EntityGUI_FieldDlg::IntSpinItem : public QTableWidgetItem
142 IntSpinItem( const int theValue );
145 void setValue( const int theValue );
150 int EntityGUI_FieldDlg::IntSpinItem::Type()
152 return QTableWidgetItem::UserType + 3;
155 EntityGUI_FieldDlg::IntSpinItem::IntSpinItem( const int theValue )
156 : QTableWidgetItem( Type() )
158 setValue( theValue );
161 int EntityGUI_FieldDlg::IntSpinItem::value() const
164 int value = data( Qt::UserRole ).toInt( &ok );
165 return ok ? value : 0;
168 void EntityGUI_FieldDlg::IntSpinItem::setValue( const int theValue )
170 setData( Qt::UserRole, theValue );
171 setText( QString::number( theValue ) );
174 void EntityGUI_FieldDlg::IntSpinItem::clear()
180 Class : EntityGUI_FieldDlg::DoubleSpinItem
181 Description : Double spin table item.
184 class EntityGUI_FieldDlg::DoubleSpinItem : public QTableWidgetItem
189 DoubleSpinItem( const double theValue, const int thePrecision=6 );
191 double value() const;
192 void setValue( const double theValue );
194 int precision() const;
195 void setPrecision( const int thePrecision );
200 int EntityGUI_FieldDlg::DoubleSpinItem::Type()
202 return QTableWidgetItem::UserType + 4;
205 EntityGUI_FieldDlg::DoubleSpinItem::DoubleSpinItem( const double theValue,
206 const int thePrecision)
207 : QTableWidgetItem( Type() )
209 setValue( theValue );
210 setPrecision( thePrecision );
213 double EntityGUI_FieldDlg::DoubleSpinItem::value() const
216 double value = data( Qt::UserRole ).toDouble( &ok );
217 return ok ? value : 0;
220 void EntityGUI_FieldDlg::DoubleSpinItem::setValue( const double theValue )
222 setData( Qt::UserRole, theValue );
223 setText( QString::number( theValue ) );
226 int EntityGUI_FieldDlg::DoubleSpinItem::precision() const
229 int precision = data( Qt::UserRole + 1 ).toInt( &ok );
230 return ok ? precision : 0;
233 void EntityGUI_FieldDlg::DoubleSpinItem::setPrecision( const int thePrecision )
235 setData( Qt::UserRole + 1, thePrecision );
238 void EntityGUI_FieldDlg::DoubleSpinItem::clear()
244 Class : EntityGUI_FieldDlg::ComboDelegate
245 Description : Table used by this widget
248 class EntityGUI_FieldDlg::Delegate : public QItemDelegate
251 Delegate( QObject* = 0 );
254 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
255 const QModelIndex& ) const;
257 void setEditorData( QWidget*, const QModelIndex& ) const;
258 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
260 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
261 const QModelIndex& ) const;
266 EntityGUI_FieldDlg::Delegate::Delegate( QObject* parent )
267 : QItemDelegate( parent ),
268 myTable( dynamic_cast<EntityGUI_FieldDlg::StepTable*>( parent ) )
272 EntityGUI_FieldDlg::Delegate::~Delegate()
276 QWidget* EntityGUI_FieldDlg::Delegate::createEditor( QWidget* parent,
277 const QStyleOptionViewItem& option,
278 const QModelIndex& index ) const
280 QVariant aData = index.data( Qt::UserRole );
281 QVariant::Type aDataType = aData.type();
282 if( aDataType == QVariant::Int ) {
284 int aValue = aData.toInt( &ok );
286 SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( -theIntLimit, theIntLimit, 1, parent, false, true );
287 intSpin->setFrame( false );
288 intSpin->setValue( aValue );
292 else if( aDataType == QVariant::Double ) {
294 double aValue = aData.toDouble( &ok );
296 int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
300 SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
301 dblSpin->setFrame( false );
302 dblSpin->setValue( aValue );
306 return QItemDelegate::createEditor( parent, option, index );
309 void EntityGUI_FieldDlg::Delegate::setEditorData( QWidget* editor,
310 const QModelIndex& index ) const
312 QVariant data = index.model()->data( index, Qt::DisplayRole );
313 QString value = data.toString();
315 if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
316 if( data.type() == QVariant::Double ) {
317 double valueDouble = data.toDouble( &bOk );
319 dblSpin->setValue( valueDouble );
322 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
325 void EntityGUI_FieldDlg::Delegate::setModelData( QWidget* editor,
326 QAbstractItemModel* model,
327 const QModelIndex& index) const
329 QString oldData = myTable->text( index.row(), index.column() );
331 if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
332 model->setData( index, intSpin->value(), Qt::DisplayRole );
333 else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
334 model->setData( index, dblSpin->value(), Qt::DisplayRole );
336 QItemDelegate::setModelData( editor, model, index );
338 QString newData = myTable->text( index.row(), index.column() );
339 if ( newData != oldData )
340 myTable->setIsChanged();
343 void EntityGUI_FieldDlg::Delegate::updateEditorGeometry( QWidget* editor,
344 const QStyleOptionViewItem& option,
345 const QModelIndex& index ) const
347 editor->setGeometry( option.rect );
350 //=======================================================================
351 // name : EntityGUI_FieldDlg::StepTable::Table
352 // Purpose : Constructor
353 //=======================================================================
354 EntityGUI_FieldDlg::StepTable::StepTable (int stepID, int dataType,
355 int nbRows, int nbComps,
356 QString shapeName, QStringList headers,
357 GEOM::GEOM_FieldStep_ptr stepVar,
359 : QTableWidget(0, nbComps+1, parent),
360 myDataType( dataType ),
363 myStep( GEOM::GEOM_FieldStep::_duplicate( stepVar )),
366 setDim( nbRows, shapeName, stepVar->_is_nil() );
368 setHorizontalHeaderLabels( headers );
369 verticalHeader()->hide();
371 // set custom item delegate
372 setItemDelegate( new Delegate(this) );
373 // set edit triggers by default
374 setReadOnly( false );
376 if ( stepVar->_is_nil() )
379 myStamp = stepVar->GetStamp();
381 const int nbColumns = nbComps + 1;
387 GEOM::GEOM_BoolFieldStep_var bs = GEOM::GEOM_BoolFieldStep::_narrow( stepVar );
388 if ( !bs->_is_nil() )
390 GEOM::short_array_var vals = bs->GetValues();
391 if ( vals->length() == nbRows * nbComps )
392 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
393 for ( int iC = 1; iC < nbColumns; ++iC )
394 setItem( iR, iC, new CheckItem( vals[ iV++ ]));
396 connect( this, SIGNAL( itemClicked(QTableWidgetItem *)), this, SLOT( setIsChanged() ));
401 GEOM::GEOM_IntFieldStep_var is = GEOM::GEOM_IntFieldStep::_narrow( stepVar );
402 if ( !is->_is_nil() )
404 GEOM::ListOfLong_var vals = is->GetValues();
405 if ( vals->length() == nbRows * nbComps )
406 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
407 for ( int iC = 1; iC < nbColumns; ++iC )
408 setItem( iR, iC, new IntSpinItem( vals[ iV++ ]));
414 GEOM::GEOM_DoubleFieldStep_var ds = GEOM::GEOM_DoubleFieldStep::_narrow( stepVar );
415 if ( !ds->_is_nil() )
417 GEOM::ListOfDouble_var vals = ds->GetValues();
418 if ( vals->length() == nbRows * nbComps )
419 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
420 for ( int iC = 1; iC < nbColumns; ++iC )
421 setItem( iR, iC, new DoubleSpinItem( vals[ iV++ ]));
426 GEOM::GEOM_StringFieldStep_var ss = GEOM::GEOM_StringFieldStep::_narrow( stepVar );
427 if ( !ss->_is_nil() )
429 GEOM::string_array_var vals = ss->GetValues();
430 if ( vals->length() == nbRows * nbComps )
431 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
432 for ( int iC = 1; iC < nbColumns; ++iC )
433 setItem( iR, iC, new QTableWidgetItem( vals[ iV++ ].in() ));
439 //=======================================================================
440 // name : EntityGUI_FieldDlg::StepTable::~StepTable
441 // Purpose : Destructor
442 //=======================================================================
443 EntityGUI_FieldDlg::StepTable::~StepTable()
447 //=======================================================================
448 // name : EntityGUI_FieldDlg::StepTable::minimumSizeHint
449 // Purpose : Get minimum size for the table
450 //=======================================================================
451 QSize EntityGUI_FieldDlg::StepTable::minimumSizeHint() const
453 QSize s = QTableWidget::minimumSizeHint();
454 QHeaderView* hv = horizontalHeader();
456 s.setWidth( qMax( s.width(), hv->length() ) );
460 //=======================================================================
461 // name : EntityGUI_FieldDlg::StepTable::setEditable
462 // Purpose : Set editable of specified cell
463 //=======================================================================
464 void EntityGUI_FieldDlg::StepTable::setEditable (bool isEditable,
467 QTableWidgetItem* anItem = item( row, col );
469 bool isSignalsBlocked = signalsBlocked();
470 blockSignals( true );
472 Qt::ItemFlags f = anItem->flags();
473 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
474 else f = f | Qt::ItemIsEditable;
475 anItem->setFlags( f );
477 blockSignals( isSignalsBlocked );
481 //=======================================================================
482 // name : EntityGUI_FieldDlg::StepTable::isEditable
483 // Purpose : Verify wheter cell is editable
484 //=======================================================================
485 bool EntityGUI_FieldDlg::StepTable::isEditable (int row, int col) const
487 QTableWidgetItem* anItem = item( row, col );
488 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
491 void EntityGUI_FieldDlg::StepTable::setReadOnly( bool on )
493 setEditTriggers( on ?
494 QAbstractItemView::NoEditTriggers :
495 QAbstractItemView::AllEditTriggers );
498 bool EntityGUI_FieldDlg::StepTable::isReadOnly() const
500 return editTriggers() == QAbstractItemView::NoEditTriggers;
503 //=======================================================================
504 // name : EntityGUI_FieldDlg::StepTable::insertRows
505 // Purpose : Insert rows (virtual redefined)
506 //=======================================================================
507 void EntityGUI_FieldDlg::StepTable::insertRows (int row, int count)
509 while ( count-- ) insertRow( row );
512 //=======================================================================
513 // name : EntityGUI_FieldDlg::StepTable::text
514 // Purpose : Get text from cell (virtual redefined)
515 //=======================================================================
516 QString EntityGUI_FieldDlg::StepTable::text (int row, int col)
518 closePersistentEditor( currentItem() );
519 QTableWidgetItem* anItem = item( row, col );
520 return anItem ? anItem->text() : QString();
523 QList<int> EntityGUI_FieldDlg::StepTable::selectedRows()
525 QList<QTableWidgetItem*> selItems = selectedItems();
526 QTableWidgetItem* anItem;
529 foreach( anItem, selItems ) {
530 int r = row( anItem );
531 if ( !rows.contains( r ) ) rows.append( r );
538 //=======================================================================
539 //function : selectRows
541 //=======================================================================
543 void EntityGUI_FieldDlg::StepTable::selectRows(const QList<int>& rows)
545 closePersistentEditor( currentItem() );
547 QList<QTableWidgetSelectionRange> ranges = selectedRanges();
548 for ( int i = 0; i < ranges.count(); ++i )
549 setRangeSelected( ranges[i], false );
551 QList<int>::const_iterator row = rows.begin();
552 for ( ; row != rows.end(); ++row )
553 // QTableWidgetSelectionRange ( int top, int left, int bottom, int right )
554 setRangeSelected ( QTableWidgetSelectionRange(*row,0,*row,0), true );
557 //=======================================================================
559 //purpose : change nb rows in the table
560 //=======================================================================
562 void EntityGUI_FieldDlg::StepTable::setDim( int nbRows, QString shapeName, bool setDefault )
564 closePersistentEditor( currentItem() );
565 int curNbRows = rowCount();
566 if ( nbRows < curNbRows )
568 while ( nbRows < curNbRows )
569 removeRow( --curNbRows );
571 else if ( nbRows > curNbRows )
573 int nbColumns = columnCount();
574 for ( ; nbRows > curNbRows; ++curNbRows )
576 insertRow( curNbRows );
578 for ( int iC = 1; iC < nbColumns; ++iC )
579 setItem( curNbRows, iC, newDefaultItem() );
583 int indexWidth = 1, maxNbR = 10;
584 while ( nbRows >= maxNbR )
585 ++indexWidth, maxNbR *= 10;
586 shapeName = shapeName.toLower() + "_%1";
587 for ( int iR = 0; iR < nbRows; ++iR )
589 setItem( iR, 0, new QTableWidgetItem( shapeName.arg( iR+1, indexWidth, 10, QChar('0') )));
590 setEditable( false, iR, 0 );
594 //=======================================================================
595 //function : setNbComps
597 //=======================================================================
599 void EntityGUI_FieldDlg::StepTable::setNbComps( int nbComps )
601 closePersistentEditor( currentItem() );
602 nbComps++; // add sub-shape column
603 int curNbCols = columnCount();
604 if ( nbComps < curNbCols )
606 while ( nbComps < curNbCols )
607 removeColumn( --curNbCols );
609 else if ( nbComps > curNbCols )
611 int nbRows = rowCount();
612 for ( ; nbComps > curNbCols; ++curNbCols )
614 insertColumn( curNbCols );
615 setHorizontalHeaderItem( curNbCols,
616 new QTableWidgetItem(QString("Comp %1").arg( curNbCols )));
617 for ( int iR = 0; iR < nbRows; ++iR )
618 setItem( iR, curNbCols, newDefaultItem() );
623 //=======================================================================
624 //function : setDataType
625 //purpose : change type of data
626 //=======================================================================
628 void EntityGUI_FieldDlg::StepTable::setDataType( int dataType )
630 myDataType = dataType;
632 int nbRows = rowCount();
633 int nbColumns = columnCount();
635 for ( int iR = 0; iR < nbRows; ++iR )
636 for ( int iC = 1; iC < nbColumns; ++iC )
637 setItem( iR, iC, newDefaultItem() );
640 //=======================================================================
641 //function : newDefaultItem
642 //purpose : creates a table item with a default value
643 //=======================================================================
645 QTableWidgetItem * EntityGUI_FieldDlg::StepTable::newDefaultItem()
647 switch( myDataType ) {
648 case 0: return new CheckItem(false);
649 case 1: return new IntSpinItem(0);
650 case 2: return new DoubleSpinItem(0);
653 return new QTableWidgetItem(""); // string
656 //=======================================================================
657 //function : getHeaders
659 //=======================================================================
661 QStringList EntityGUI_FieldDlg::StepTable::getHeaders()
664 int nbColumns = columnCount();
665 for ( int iC = 0; iC < nbColumns; ++iC )
666 headers << horizontalHeaderItem( iC )->text();
670 //=======================================================================
671 //function : setHeaders
673 //=======================================================================
675 void EntityGUI_FieldDlg::StepTable::setHeaders(const QStringList& headers)
677 setHorizontalHeaderLabels( headers );
680 //=======================================================================
681 //function : setValues
682 //purpose : store values from this table to a field step
683 //=======================================================================
685 void EntityGUI_FieldDlg::StepTable::setValues(GEOM::GEOM_FieldStep_var& step)
687 closePersistentEditor( currentItem() );
689 if ( step->GetStamp() != myStamp )
690 step->SetStamp( myStamp );
692 if ( step->_is_equivalent( myStep ) && !myIsChanged )
695 const int nbColumns = columnCount();
696 const int nbComps = nbColumns - 1;
697 const int nbRows = rowCount();
699 switch ( myDataType ) {
702 GEOM::GEOM_BoolFieldStep_var bs = GEOM::GEOM_BoolFieldStep::_narrow( step );
703 if ( !bs->_is_nil() )
705 GEOM::short_array_var vals = new GEOM::short_array();
706 vals->length( nbRows * nbComps );
707 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
708 for ( int iC = 1; iC < nbColumns; ++iC )
709 vals[ iV++ ] = ((CheckItem*)item( iR, iC ))->value();
710 bs->SetValues( vals );
716 GEOM::GEOM_IntFieldStep_var is = GEOM::GEOM_IntFieldStep::_narrow( step );
717 if ( !is->_is_nil() )
719 GEOM::ListOfLong_var vals = new GEOM::ListOfLong();
720 vals->length( nbRows * nbComps );
721 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
722 for ( int iC = 1; iC < nbColumns; ++iC )
723 vals[ iV++ ] = text( iR, iC ).toInt();
724 is->SetValues( vals );
730 GEOM::GEOM_DoubleFieldStep_var ds = GEOM::GEOM_DoubleFieldStep::_narrow( step );
731 if ( !ds->_is_nil() )
733 GEOM::ListOfDouble_var vals = new GEOM::ListOfDouble();
734 vals->length( nbRows * nbComps );
735 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
736 for ( int iC = 1; iC < nbColumns; ++iC )
737 vals[ iV++ ] = text( iR, iC ).toDouble();
738 ds->SetValues( vals );
744 GEOM::GEOM_StringFieldStep_var ss = GEOM::GEOM_StringFieldStep::_narrow( step );
745 if ( !ss->_is_nil() )
747 GEOM::string_array_var vals = new GEOM::string_array();
748 vals->length( nbRows * nbComps );
749 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
750 for ( int iC = 1; iC < nbColumns; ++iC )
751 vals[ iV++ ] = item( iR, iC )->text().toLatin1().constData();
752 ss->SetValues( vals );
761 //=======================================================================
762 //function : EntityGUI_FieldDlg
764 //=======================================================================
766 EntityGUI_FieldDlg::EntityGUI_FieldDlg (GeometryGUI* theGeometryGUI,
767 GEOM::GEOM_Field_ptr theField, int stepID,
769 bool modal, Qt::WindowFlags fl)
770 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
771 myIsCreation( CORBA::is_nil( theField )),
772 myField( GEOM::GEOM_Field::_duplicate( theField )),
773 myCurStepID( stepID ),
774 myCurStepTable( NULL ),
775 myIsHiddenMain( false )
777 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
778 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
780 setWindowTitle(myIsCreation ? tr("CREATE_FIELD_TITLE") : tr("EDIT_FIELD_TITLE"));
782 // Shape type button group
783 mainFrame()->GroupConstructors->hide();
786 mainFrame()->GroupBoxName->setTitle(tr("FIELD_NAME"));
790 QGroupBox* propGroup = new QGroupBox(tr("PROPERTIES"), centralWidget());
791 QGridLayout* propLayout = new QGridLayout(propGroup);
792 propLayout->setMargin(9);
793 propLayout->setSpacing(6);
796 QLabel* shapeLabel = new QLabel(tr("SHAPE"), propGroup);
797 myShapeSelBtn = new QPushButton(propGroup);
798 myShapeSelBtn->setIcon(iconSelect);
799 myShapeSelBtn->setEnabled( myIsCreation );
800 myShapeName = new QLineEdit(propGroup);
801 myShapeName->setReadOnly(true);
802 myShapeName->setEnabled( myIsCreation );
805 QLabel* typeLabel = new QLabel( tr("DATA_TYPE"), propGroup );
806 myTypeCombo = new QComboBox( propGroup );
807 myTypeCombo->insertItem( GEOM::FDT_Bool, tr("BOOL"));
808 myTypeCombo->insertItem( GEOM::FDT_Int, tr("INT"));
809 myTypeCombo->insertItem( GEOM::FDT_Double, tr("DOUBLE"));
810 myTypeCombo->insertItem( GEOM::FDT_String, tr("STRING"));
811 myTypeCombo->setCurrentIndex( GEOM::FDT_Double ); // double
814 QLabel* dimLabel = new QLabel( tr("SHAPE_TYPE"), propGroup );
815 myDimCombo = new QComboBox( propGroup );
818 QLabel* nbCompsLabel = new QLabel( tr("NB_COMPS"), propGroup );
819 myNbCompsSpin = new SalomeApp_IntSpinBox( 1, 1000, 1, propGroup, true, true );
820 myNbCompsSpin->setValue( 1 );
821 propLayout->addWidget(shapeLabel, 0, 0);
822 propLayout->addWidget(myShapeSelBtn, 0, 1);
823 propLayout->addWidget(myShapeName, 0, 2);
824 propLayout->addWidget(typeLabel, 1, 0, 1, 2);
825 propLayout->addWidget(myTypeCombo, 1, 2);
826 propLayout->addWidget(dimLabel, 2, 0, 1, 2);
827 propLayout->addWidget(myDimCombo, 2, 2);
828 propLayout->addWidget(nbCompsLabel, 3, 0, 1, 2);
829 propLayout->addWidget(myNbCompsSpin, 3, 2);
830 // propLayout->addWidget(shapeLabel, 0, 0);
831 // propLayout->addWidget(myShapeName, 0, 1);
832 // propLayout->addWidget(typeLabel, 1, 0);
833 // propLayout->addWidget(myTypeCombo, 1, 1);
834 // propLayout->addWidget(dimLabel, 2, 0);
835 // propLayout->addWidget(myDimCombo, 2, 1);
836 // propLayout->addWidget(nbCompsLabel, 3, 0);
837 // propLayout->addWidget(myNbCompsSpin, 3, 1);
839 propLayout->setColumnStretch(2, 5);
843 QGroupBox* valsGroup = new QGroupBox(tr("VALUES"), centralWidget());
844 QGridLayout* valsLayout = new QGridLayout(valsGroup);
845 valsLayout->setMargin(9);
846 valsLayout->setSpacing(6);
849 mySwitchTableWdg = new QWidget(valsGroup);
850 QVBoxLayout* switchTableGrpLayout = new QVBoxLayout(mySwitchTableWdg);
851 switchTableGrpLayout->setMargin(0);
852 switchTableGrpLayout->setSpacing(0);
854 // step browse controls
855 myPrevStepBtn = new QPushButton( tr("PREV_STEP"), valsGroup );
856 QLabel* curStepLbl = new QLabel(tr("STEP"), valsGroup );
857 myStepsCombo = new QComboBox(valsGroup);
858 myNextStepBtn = new QPushButton( tr("NEXT_STEP"), valsGroup );
860 // step add/rm controls
861 QPushButton* addStepBtn = new QPushButton( tr("ADD_STEP"), valsGroup );
862 QLabel* stampLbl = new QLabel(tr("STAMP"), valsGroup );
863 myStampSpin = new SalomeApp_IntSpinBox( -theIntLimit, theIntLimit, 1, valsGroup, true, true);
864 myRmStepBtn = new QPushButton( tr("REMOVE_STEP"), valsGroup );
866 valsLayout->addWidget(mySwitchTableWdg, 0, 0, 1, 4);
867 valsLayout->addWidget(myPrevStepBtn, 1, 0);
868 valsLayout->addWidget(curStepLbl, 1, 1);
869 valsLayout->addWidget(myStepsCombo, 1, 2);
870 valsLayout->addWidget(myNextStepBtn, 1, 3);
871 valsLayout->addWidget(addStepBtn, 2, 0);
872 valsLayout->addWidget(stampLbl, 2, 1);
873 valsLayout->addWidget(myStampSpin, 2, 2);
874 valsLayout->addWidget(myRmStepBtn, 2, 3);
876 valsLayout->setColumnStretch(2, 5);
877 valsLayout->setRowStretch (0, 5);
879 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
880 layout->setMargin(0); layout->setSpacing(6);
881 layout->addWidget(propGroup);
882 layout->addWidget(valsGroup);
884 setHelpFileName("geom_field_page.html");
886 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
887 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
889 connect(myPrevStepBtn, SIGNAL(clicked()), this, SLOT( onPrevStep() ));
890 connect(myNextStepBtn, SIGNAL(clicked()), this, SLOT( onNextStep() ));
891 connect(addStepBtn, SIGNAL(clicked()), this, SLOT( onAddStep() ));
892 connect(myRmStepBtn, SIGNAL(clicked()), this, SLOT( onRmStep() ));
893 connect(myStampSpin, SIGNAL(valueChanged(int)), this, SLOT( onStampChange() ));
894 connect(myStepsCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( showCurStep() ));
895 connect(myStepsCombo, SIGNAL(activated(int)), this, SLOT( showCurStep() ));
897 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
898 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
904 //=======================================================================
905 //function : ~EntityGUI_FieldDlg
907 //=======================================================================
909 EntityGUI_FieldDlg::~EntityGUI_FieldDlg()
911 GEOM_Displayer* aDisplayer = getDisplayer();
912 if (myIsHiddenMain) {
913 aDisplayer->Display(myShape);
914 myIsHiddenMain = false;
916 // if ( !myField->_is_nil())
917 // aDisplayer->Display(myField);
919 QListIterator<int> anIter( myHiddenFieldStepIds );
920 while( anIter.hasNext() )
922 const int aStepId = anIter.next();
923 GEOM::GEOM_FieldStep_var step = myField->GetStep( aStepId );
924 if( !step->_is_nil() )
925 aDisplayer->Display( step, false );
927 aDisplayer->UpdateViewer();
930 //=================================================================================
933 //=================================================================================
934 void EntityGUI_FieldDlg::Init()
937 myHiddenFieldStepIds.clear();
938 myStepsCombo->clear();
940 if ( myIsCreation || myField->_is_nil() )
943 myStepTables.clear();
944 if ( myCurStepTable )
945 myCurStepTable->hide();
946 myCurStepTable = NULL;
949 initName(tr("FIELD_PREFIX"));
950 myStampSpin->setValue(0);
952 SelectionIntoArgument();
956 connect(myShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
957 connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onTypeChange()));
958 connect(myDimCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onDimChange()));
959 connect(myNbCompsSpin, SIGNAL(valueChanged(int)), this, SLOT( onNbCompsChange()));
964 // 1) get and sort step IDs
965 // 2) hide all displayed field steps' presentations
966 GEOM_Displayer* aDisplayer = getDisplayer();
967 GEOM::ListOfLong_var stepIDs = myField->GetSteps();
969 QList< int > stepsList;
970 for ( i = 0; i < stepIDs->length(); ++i )
972 int aStepId = stepIDs[i];
973 stepsList.push_back( aStepId );
974 GEOM::GEOM_FieldStep_var step = myField->GetStep( aStepId );
975 if( !step->_is_nil() )
977 QString anEntry( step->GetStudyEntry() );
978 if( aDisplayer->IsDisplayed( anEntry ) )
980 aDisplayer->Erase( step, false, false );
981 myHiddenFieldStepIds << aStepId;
985 qSort( stepsList.begin(), stepsList.end() );
987 myIsCreation = false;
989 CORBA::String_var fName = myField->GetName();
990 myMainFrame->ResultName->setText( fName.in() );
992 myShape = myField->GetShape();
993 CORBA::String_var sName;
994 if ( !myShape->_is_nil() )
995 sName = myShape->GetName();
996 myShapeName->setText( sName.in() ? sName.in() : "");
998 myTypeCombo->setCurrentIndex( myField->GetDataType() );
1000 updateDims( myField->GetDimension() );
1003 GEOM::string_array_var compNames = myField->GetComponents();
1004 myNbCompsSpin->setValue( compNames->length() );
1006 myShapeSelBtn->setEnabled( false );
1007 myShapeName->setEnabled( false );
1008 myTypeCombo->setEnabled( false );
1009 myDimCombo->setEnabled( false );
1010 myNbCompsSpin->setEnabled( false );
1012 myStepsCombo->blockSignals( true );
1013 for ( i = 0; i < stepIDs->length(); ++i )
1015 myStepsCombo->insertItem( i, QString::number( stepsList[i] ));
1016 if ( myCurStepID == stepsList[i] )
1017 myStepsCombo->setCurrentIndex( i );
1019 // if ( myStepsCombo->count() == 0 )
1020 // myStepsCombo->insertItem( 0, QString::number( myCurStepID ));
1021 myStepsCombo->blockSignals( false );
1024 activateSelection();
1028 //=================================================================================
1029 // function : enterEvent()
1031 //=================================================================================
1032 void EntityGUI_FieldDlg::enterEvent(QEvent* e)
1034 if (!buttonCancel()->isEnabled())
1035 ActivateThisDialog();
1038 //=================================================================================
1039 // function : ClickOnOk()
1041 //=================================================================================
1042 void EntityGUI_FieldDlg::ClickOnOk()
1044 setIsApplyAndClose(true);
1047 setIsApplyAndClose(false);
1050 //=================================================================================
1051 // function : ClickOnApply()
1053 //=================================================================================
1054 bool EntityGUI_FieldDlg::ClickOnApply()
1056 if(!isApplyAndClose()) {
1057 setIsDisableBrowsing( true );
1058 setIsDisplayResult( false );
1062 if ( !isValid( msg ) ) {
1066 SUIT_OverrideCursor wc;
1067 SUIT_Session::session()->activeApplication()->putInfo( "" );
1070 if ( openCommand() )
1071 if (!execute (/*isApplyAndClose()*/))
1078 catch( const SALOME::SALOME_Exception& e ) {
1079 SalomeApp_Tools::QtCatchCorbaException( e );
1085 if(!isApplyAndClose()) {
1086 setIsDisableBrowsing( false );
1087 setIsDisplayResult( true );
1092 myField = GEOM::GEOM_Field::_nil();
1093 if ( !isApplyAndClose() )
1099 //=================================================================================
1100 // function : ActivateThisDialog()
1102 //=================================================================================
1103 void EntityGUI_FieldDlg::ActivateThisDialog()
1105 GEOMBase_Skeleton::ActivateThisDialog();
1107 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
1108 this, SLOT(SelectionIntoArgument()));
1110 activateSelection();
1113 //=================================================================================
1114 // function : SetEditCurrentArgument()
1116 //=================================================================================
1117 void EntityGUI_FieldDlg::SetEditCurrentArgument()
1119 myEditCurrentArgument = myShapeName;
1120 SelectionIntoArgument();
1123 //=================================================================================
1124 // function : SelectionIntoArgument()
1125 // purpose : Called when selection has changed
1126 //=================================================================================
1127 void EntityGUI_FieldDlg::SelectionIntoArgument()
1129 if (myEditCurrentArgument == myShapeName || // Selection of a shape is active
1132 myShapeName->setText("");
1133 myShape = GEOM::GEOM_Object::_nil();
1135 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
1136 SALOME_ListIO aSelList;
1137 aSelMgr->selectedObjects(aSelList);
1138 int nbSel = aSelList.Extent();
1141 GEOM::GEOM_Object_var anObj =
1142 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
1144 if ( GEOMBase::IsShape(anObj) && anObj->IsMainShape() ) {
1145 if (myIsHiddenMain) {
1146 GEOM_Displayer* aDisplayer = getDisplayer();
1147 aDisplayer->Display(myShape);
1148 myIsHiddenMain = false;
1150 myShapeName->setText(GEOMBase::GetName(anObj));
1152 if ( !anObj->_is_nil() && !anObj->IsSame( myShape ))
1156 myEditCurrentArgument = 0;
1158 // re-fill myDimCombo
1159 const int curDim = getDim();
1160 updateDims( curDim );
1168 if (myIsHiddenMain) {
1169 GEOM_Displayer* aDisplayer = getDisplayer();
1170 aDisplayer->Display(myShape);
1171 myIsHiddenMain = false;
1175 else // select rows of a table according to shape selection
1177 if ( !myCurStepTable )
1180 bool isSignalsBlocked = myCurStepTable->signalsBlocked();
1181 myCurStepTable->blockSignals(true);
1183 QList< int > rowsToSelect;
1184 TColStd_IndexedMapOfInteger aMapIndex;
1185 if ( getSelectedSubshapes(aMapIndex ))
1186 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
1187 const int shapeID = aMapIndex( ii );
1188 for (int row = 0, n = myShapeIDs.size(); row < n; row++)
1189 if ( myShapeIDs[row] == shapeID ) {
1190 rowsToSelect.push_back( row );
1194 myCurStepTable->selectRows( rowsToSelect );
1196 myCurStepTable->blockSignals(isSignalsBlocked);
1200 //=================================================================================
1201 // function : onDimChange()
1202 // purpose : update dialog at change of dimension
1203 //=================================================================================
1204 void EntityGUI_FieldDlg::onDimChange()
1206 // get order of sub-shapes - myShapeIDs
1209 // update size of tables
1210 const int nbRows = myShapeIDs.size();
1211 QString subName = ( getDim() == -1 ) ? tr("WHOLE_SHAPE_VHEADER") : myDimCombo->currentText();
1212 QMap< int, StepTable* >::iterator tblIt = myStepTables.begin();
1213 for ( ; tblIt != myStepTables.end(); ++tblIt )
1214 if ( tblIt.value() )
1215 tblIt.value()->setDim( nbRows, subName );
1217 activateSelection();
1220 //=======================================================================
1221 //function : onNbCompsChange
1223 //=======================================================================
1225 void EntityGUI_FieldDlg::onNbCompsChange()
1227 QMap< int, StepTable* >::iterator tblIt = myStepTables.begin();
1228 for ( ; tblIt != myStepTables.end(); ++tblIt )
1229 if ( tblIt.value() )
1230 tblIt.value()->setNbComps( getNbComps() );
1233 //=======================================================================
1234 //function : onTypeChange
1236 //=======================================================================
1238 void EntityGUI_FieldDlg::onTypeChange()
1240 QMap< int, StepTable* >::iterator tblIt = myStepTables.begin();
1241 for ( ; tblIt != myStepTables.end(); ++tblIt )
1242 if ( tblIt.value() )
1243 tblIt.value()->setDataType( myTypeCombo->currentIndex() );
1246 //=================================================================================
1247 // function : onPrevStep()
1249 //=================================================================================
1250 void EntityGUI_FieldDlg::onPrevStep()
1252 int i = myStepsCombo->currentIndex();
1255 myStepsCombo->setCurrentIndex( i-1 );
1260 //=================================================================================
1261 // function : onNextStep()
1263 //=================================================================================
1264 void EntityGUI_FieldDlg::onNextStep()
1266 int i = myStepsCombo->currentIndex();
1267 if ( i+1 < myStepsCombo->count() )
1269 myStepsCombo->setCurrentIndex( i+1 );
1274 //=======================================================================
1275 //function : onAddStep
1277 //=======================================================================
1278 void EntityGUI_FieldDlg::onAddStep()
1280 if ( myStepsCombo->count() > 0 )
1281 myCurStepID = myStepsCombo->itemText( myStepsCombo->count()-1 ).toInt() + 1;
1283 myStepsCombo->insertItem( myStepsCombo->count(), QString::number( myCurStepID ));
1284 myStepsCombo->setCurrentIndex( myStepsCombo->count() - 1 );
1285 myRemovedSteps.remove( getCurStepID() );
1289 //=======================================================================
1290 //function : onRmStep
1292 //=======================================================================
1294 void EntityGUI_FieldDlg::onRmStep()
1296 if ( myStepsCombo->count() > 1 )
1298 myStepTables.remove( getCurStepID() );
1299 myRemovedSteps.insert( getCurStepID() );
1300 if ( myCurStepTable )
1301 myCurStepTable->hide();
1302 myCurStepTable = NULL;
1303 myStepsCombo->removeItem( myStepsCombo->currentIndex() );
1308 //=======================================================================
1309 //function : onStampChange
1311 //=======================================================================
1313 void EntityGUI_FieldDlg::onStampChange()
1315 if ( myCurStepTable )
1316 myCurStepTable->setStamp( myStampSpin->value() );
1319 //=======================================================================
1320 //function : showCurStep
1322 //=======================================================================
1324 void EntityGUI_FieldDlg::showCurStep()
1326 myCurStepID = getCurStepID();
1328 QStringList headers;
1329 if ( myCurStepTable )
1331 if ( myCurStepTable->getStepID() == myCurStepID )
1333 myCurStepTable->show();
1338 myCurStepTable->hide();
1339 headers = myCurStepTable->getHeaders();
1340 myCurStepTable->getStamp();
1344 if ( myStepTables.count ( myCurStepID ))
1346 myCurStepTable = myStepTables[ myCurStepID ];
1347 myCurStepTable->setHeaders( headers );
1351 // if ( myStepsCombo->count() == 0 )
1352 // return; // edit a field with no steps
1355 GEOM::GEOM_FieldStep_var stepVar;
1356 if ( !myField->_is_nil() )
1357 stepVar = myField->GetStep( myCurStepID );
1359 int nbComps = getNbComps();
1360 if ( headers.count() == 0 )
1362 headers << tr("SUB_SHAPE_HEADER");
1363 if ( !myIsCreation && !myField->_is_nil() )
1365 GEOM::string_array_var compNames = myField->GetComponents();
1366 for ( int iC = 0; iC < compNames->length(); ++iC )
1367 headers << compNames[ iC ].in();
1371 for ( int iC = 0; iC < nbComps; ++iC )
1372 headers << QString("Comp %1").arg( iC + 1 );
1375 QString subName = ( getDim() == -1 ) ? tr("WHOLE_SHAPE_VHEADER") : myDimCombo->currentText();
1376 myCurStepTable = new StepTable( myCurStepID, getDataType(), myShapeIDs.size(),
1377 nbComps, subName, headers, stepVar, mySwitchTableWdg );
1378 myStepTables[ myCurStepID ] = myCurStepTable;
1379 mySwitchTableWdg->layout()->addWidget( myCurStepTable );
1381 myCurStepTable->show();
1382 myStampSpin->setValue( myCurStepTable->getStamp() );
1384 connect(myCurStepTable, SIGNAL(itemSelectionChanged()), this, SLOT( highlightSubShapes() ));
1386 myPrevStepBtn->setEnabled( myStepsCombo->currentIndex() > 0 );
1387 myNextStepBtn->setEnabled( myStepsCombo->currentIndex()+1 < myStepsCombo->count() );
1388 myRmStepBtn->setEnabled( myStepsCombo->count() > 1 );
1391 //=================================================================================
1392 // function : getSelectedSubshapes
1394 //=================================================================================
1395 int EntityGUI_FieldDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
1397 theMapIndex.Clear();
1399 SalomeApp_Application* app = myGeomGUI->getApp();
1400 if (!app || myShape->_is_nil())
1403 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1404 SALOME_ListIO aSelList;
1405 aSelMgr->selectedObjects(aSelList);
1407 // try to find out and process the global selection
1408 // (of not published objects and of published sub-shapes)
1410 SALOME_ListIteratorOfListIO anIter (aSelList);
1411 for (int i = 0; anIter.More(); anIter.Next(), i++)
1413 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
1414 QString anEntry = anIObj->getEntry();
1416 int index = anEntry.lastIndexOf(str);
1417 if (index > 0) // selection among special preview
1419 anEntry.remove(0, index+1);
1420 int anIndex = anEntry.toInt();
1422 theMapIndex.Add(anIndex);
1424 else // selection among published shapes
1426 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1427 if (!appStudy) return 0;
1428 _PTR(Study) aStudy = appStudy->studyDS();
1430 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toLatin1().constData()));
1431 GEOM::GEOM_Object_var aGeomObj =
1432 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
1433 TopoDS_Shape aShape;
1434 if (GEOMBase::GetShape(aGeomObj, aShape)) {
1435 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType())
1437 TopExp_Explorer anExp (aShape, getShapeType());
1438 for (; anExp.More(); anExp.Next()) {
1439 TopoDS_Shape aSubShape = anExp.Current();
1440 int anIndex = myShapeMap.FindIndex(aSubShape);
1442 SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"),
1443 tr("WRN_NOT_SUBSHAPE"));
1445 theMapIndex.Add(anIndex);
1453 return theMapIndex.Extent();
1456 //=================================================================================
1457 // function : getShapeType()
1459 //=================================================================================
1460 TopAbs_ShapeEnum EntityGUI_FieldDlg::getShapeType(int* dim) const
1463 switch ( dim ? *dim : getDim() )
1465 case 0: return TopAbs_VERTEX;
1466 case 1: return TopAbs_EDGE;
1467 case 2: return TopAbs_FACE;
1468 case 3: return TopAbs_SOLID;
1469 default: return TopAbs_SHAPE;
1473 //=======================================================================
1476 //=======================================================================
1478 int EntityGUI_FieldDlg::getDim() const
1480 int i = myDimCombo->currentIndex();
1481 return ( i < 0 ) ? -1 : myDimCombo->itemData( i ).toInt();
1484 //=======================================================================
1485 //function : getDataType
1487 //=======================================================================
1489 int EntityGUI_FieldDlg::getDataType() const
1491 return myTypeCombo->currentIndex();
1494 //=======================================================================
1495 //function : getCurStepID
1497 //=======================================================================
1499 int EntityGUI_FieldDlg::getCurStepID() const
1501 if ( myStepsCombo->count() > 0 )
1502 return myStepsCombo->currentText().toInt();
1506 //=======================================================================
1507 //function : getNbComps
1509 //=======================================================================
1511 int EntityGUI_FieldDlg::getNbComps() const
1513 return myNbCompsSpin->value();
1516 //=================================================================================
1517 // function : updateShapeIDs()
1518 // purpose : update myShapeIDs
1519 //=================================================================================
1520 void EntityGUI_FieldDlg::updateShapeIDs()
1523 //myShapeMap.Clear();
1524 if ( !myShape->_is_nil() )
1526 TopoDS_Shape aShape =
1527 GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myShape);
1528 if ( myShapeMap.IsEmpty() )
1529 TopExp::MapShapes(aShape, myShapeMap);
1530 TopAbs_ShapeEnum shapeType = getShapeType();
1531 if ( shapeType == TopAbs_SHAPE )
1533 myShapeIDs.push_back( 1 );
1537 TopTools_IndexedMapOfShape dimSubShapesMap;
1538 TopExp::MapShapes(aShape, shapeType, dimSubShapesMap);
1539 myShapeIDs.resize( dimSubShapesMap.Extent() );
1540 for ( int i = 1; i <= dimSubShapesMap.Extent(); ++i )
1541 myShapeIDs[i-1] = myShapeMap.FindIndex( dimSubShapesMap(i) );
1546 //=======================================================================
1547 //function : updateDims
1548 //purpose : update myDimCombo
1549 //=======================================================================
1551 void EntityGUI_FieldDlg::updateDims(int curDim)
1553 myDimCombo->blockSignals( true );
1554 myDimCombo->clear();
1555 TopoDS_Shape aShape =
1556 GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myShape);
1558 if ( !aShape.IsNull() )
1560 const char* subNames[4] = { "VERTEX","EDGE","FACE","SOLID" };
1561 TopExp_Explorer exp;
1562 for ( int dim = 0; dim < 4; ++dim )
1564 exp.Init( aShape, getShapeType(&dim));
1565 if ( exp.More() && !aShape.IsSame( exp.Current() ))
1567 myDimCombo->insertItem( dim, tr( subNames[dim] ), dim );
1568 if ( dim == curDim ) // restore current dim
1569 myDimCombo->setCurrentIndex( myDimCombo->count()-1 );
1572 myDimCombo->insertItem( 4, tr("WHOLE"), -1 );
1573 if ( getDim() != curDim )
1574 myDimCombo->setCurrentIndex( myDimCombo->count()-1 );
1576 myDimCombo->blockSignals( false );
1579 //=================================================================================
1580 // function : activateSelection
1581 // purpose : Activate local selection
1582 //=================================================================================
1583 void EntityGUI_FieldDlg::activateSelection()
1585 bool isApply = ((QPushButton*)sender() == buttonApply());
1586 if(!isApplyAndClose())
1587 erasePreview(false);
1590 if (!myShape->_is_nil() &&
1591 !myEditCurrentArgument &&
1592 myShapeIDs.size() > 1 ) // shape type is already choosen by user
1594 GEOM_Displayer* aDisplayer = getDisplayer();
1595 CORBA::String_var aMainEntry = myShape->GetStudyEntry();
1597 //display mode for main shape
1598 if ( myDmMode == -1 ) {
1599 SALOME_View* view = GEOM_Displayer::GetActiveView();
1601 Handle(SALOME_InteractiveObject) io =
1602 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
1603 if ( view->isVisible( io ) ) {
1604 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
1606 myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
1608 // Hide main shape, if explode on VERTEX
1609 if(getShapeType() != TopAbs_VERTEX) {
1610 aDisplayer->Erase(myShape, false, false);
1611 myIsHiddenMain = true;
1615 myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
1618 aDisplayer->SetDisplayMode(myDmMode);
1620 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
1621 if (getShapeType() == TopAbs_VERTEX) {
1623 aDisplayer->Display(myShape);
1625 //aDisplayer->Erase(myField, false, false); ------- NOR YET implemented
1627 QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editField_color" );
1628 Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name();
1630 if(!isApplyAndClose()) {
1631 SUIT_ViewWindow* aViewWindow = 0;
1632 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
1634 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1635 if (aViewWindow == 0) return;
1637 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1638 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1639 aViewManager->getType() != SVTK_Viewer::Type())
1642 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1643 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1644 if (aView == 0) return;
1646 TopoDS_Shape aMainShape = myShapeMap(1);
1647 for ( int i = 0; i < myShapeIDs.size(); ++i )
1649 int index = myShapeIDs[ i ];
1650 TopoDS_Shape aSubShape = myShapeMap( index );
1651 QString anEntry = QString( "TEMP_" ) + aMainEntry.in() + QString("_%1").arg(index);
1652 Handle(SALOME_InteractiveObject) io =
1653 new SALOME_InteractiveObject(anEntry.toAscii(), "GEOM", "TEMP_IO");
1654 aDisplayer->SetColor( aCol );
1655 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1657 displayPreview(aPrs, true, false); // append, do not update
1658 // TODO: map or delete Prs
1661 aDisplayer->UnsetDisplayMode();
1662 aDisplayer->UnsetColor();
1663 aDisplayer->UpdateViewer();
1667 globalSelection(GEOM_ALLSHAPES);
1669 SelectionIntoArgument();
1672 //=================================================================================
1673 // function : highlightSubShapes
1674 // purpose : select objects corresponding to selected table rows
1675 //=================================================================================
1676 void EntityGUI_FieldDlg::highlightSubShapes()
1678 if (CORBA::is_nil(myShape) || !myCurStepTable )
1681 TColStd_MapOfInteger anIds;
1682 QList<int> rows = myCurStepTable->selectedRows();
1683 int ii = 0, nn = rows.count();
1684 for (; ii < nn; ii++)
1686 int shapeNum = rows[ ii ];
1687 if ( shapeNum < myShapeIDs.size() )
1688 anIds.Add( myShapeIDs[ shapeNum ]);
1691 SalomeApp_Application* app = myGeomGUI->getApp();
1692 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1693 aSelMgr->clearSelected();
1694 if ( anIds.IsEmpty() )
1697 SUIT_ViewWindow* aViewWindow = 0;
1698 SUIT_Study* activeStudy = app->activeStudy();
1700 aViewWindow = app->desktop()->activeWindow();
1701 if (aViewWindow == 0) return;
1703 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1704 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1705 aViewManager->getType() != SVTK_Viewer::Type())
1708 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1709 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1710 if (aView == 0) return;
1712 // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
1714 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
1715 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1716 AIS_ListOfInteractive List;
1717 //ic->DisplayedObjects(List);
1718 ic->ObjectsInside(List); // Mantis issue 0021367
1720 SALOME_ListIO aSelList;
1722 // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1723 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations(getStudyId());
1724 QMap<int, QString> childsMap;
1725 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1727 _PTR(Study) aStudy = appStudy->studyDS();
1728 CORBA::String_var aMainEntry = myShape->GetStudyEntry();
1729 _PTR(SObject) aSObj = aStudy->FindObjectID( aMainEntry.in() );
1730 _PTR(ChildIterator) anIt = aStudy->NewChildIterator(aSObj);
1731 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1732 GEOM::GEOM_Object_var aChild =
1733 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1734 if (!CORBA::is_nil(aChild)) {
1735 int index = aLocOp->GetSubShapeIndex(myShape, aChild);
1736 if ( anIds.Contains( index )) {
1737 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1738 //childsMap.insert(index, aChildEntry.in());
1739 Handle(SALOME_InteractiveObject) tmpIO =
1740 new SALOME_InteractiveObject( aChildEntry.in(), "GEOM", "TEMP_IO");
1741 aSelList.Append(tmpIO);
1747 AIS_ListIteratorOfListOfInteractive ite (List);
1748 for (; ite.More(); ite.Next()) {
1749 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1750 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1752 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1753 QString anEntry = anIO->getEntry();
1754 int index = anEntry.lastIndexOf("_");
1755 anEntry.remove(0, index+1);
1756 int anIndex = anEntry.toInt();
1757 if (anIds.Contains(anIndex)) {
1758 aSelList.Append(anIO);
1759 // if (childsMap.contains (anIndex)) {
1760 // Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toLatin1().constData(), "GEOM", "TEMP_IO");
1761 // aSelList.Append(tmpIO);
1767 aSelMgr->setSelectedObjects(aSelList);
1770 //=================================================================================
1771 // function : createOperation
1773 //=================================================================================
1774 GEOM::GEOM_IOperations_ptr EntityGUI_FieldDlg::createOperation()
1776 return getGeomEngine()->GetIFieldOperations(getStudyId());
1779 #define RETURN_WITH_MSG(a, b) \
1781 theMessage += (b); \
1785 //=================================================================================
1786 // function : isValid()
1787 // purpose : Verify validity of input data
1788 //=================================================================================
1789 bool EntityGUI_FieldDlg::isValid(QString& theMessage)
1791 SalomeApp_Study* study = getStudy();
1792 RETURN_WITH_MSG (!study, tr("GEOM_NO_STUDY"))
1793 RETURN_WITH_MSG (study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1795 if ( myIsCreation ) {
1796 RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_SHAPE"))
1799 RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD"))
1802 QString aName = getNewObjectName().trimmed();
1803 RETURN_WITH_MSG (aName.isEmpty(), tr("EMPTY_NAME"))
1805 RETURN_WITH_MSG ( !myCurStepTable, tr("NO_VALUES"))
1809 //=================================================================================
1810 // function : execute
1812 //=================================================================================
1813 bool EntityGUI_FieldDlg::execute()
1815 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy( getStudy()->studyDS() );
1816 SALOMEDS::StudyBuilder_var aBuilder = aStudyDS->NewBuilder();
1818 QString aName = getNewObjectName().trimmed();
1819 QStringList anEntryList;
1821 if ( myField->_is_nil() ) // create field
1823 QStringList columnNames = myCurStepTable->getHeaders();
1824 int nbComps = columnNames.count() - 1;
1825 GEOM::string_array_var compNames = new GEOM::string_array();
1826 compNames->length( nbComps );
1827 for ( int iC = 0; iC < nbComps; ++iC )
1828 compNames[ iC ] = columnNames[ iC+1 ].toLatin1().constData();
1830 GEOM::GEOM_IFieldOperations_var anOper = GEOM::GEOM_IFieldOperations::_narrow(getOperation());
1831 myField = anOper->CreateField( myShape,
1832 aName.toLatin1().constData(),
1833 GEOM::field_data_type( getDataType() ),
1834 CORBA::Short( getDim() ),
1836 if ( myField->_is_nil() )
1839 SALOMEDS::SObject_wrap aSO =
1840 getGeomEngine()->AddInStudy( aStudyDS, myField, aName.toLatin1().constData(), myShape );
1841 if ( !aSO->_is_nil() ) {
1842 myField->UnRegister();
1843 CORBA::String_var entry = aSO->GetID();
1844 anEntryList << entry.in();
1847 else // update field name
1849 myField->SetName( aName.toLatin1().constData() );
1851 CORBA::String_var entry = myField->GetStudyEntry();
1853 SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() );
1854 if ( !SO->_is_nil() ) {
1855 aBuilder->SetName(SO, aName.toLatin1().constData());
1860 // create / update steps
1861 QMap< int, StepTable* >::iterator i_tbl = myStepTables.begin();
1862 for ( ; i_tbl != myStepTables.end(); ++i_tbl )
1864 StepTable* tbl = i_tbl.value();
1865 GEOM::GEOM_FieldStep_var step = tbl->getStep();
1866 if ( step->_is_nil() )
1868 step = myField->GetStep( tbl->getStepID() );
1869 if ( step->_is_nil() )
1871 step = myField->AddStep( tbl->getStepID(), tbl->getStamp() );
1873 QString stepName = (tr("STEP")+" %1 %2").arg( tbl->getStepID() ).arg( tbl->getStamp() );
1874 SALOMEDS::SObject_wrap aSO =
1875 getGeomEngine()->AddInStudy( aStudyDS, step, stepName.toLatin1().constData(), myField );
1876 if ( /*!myIsCreation &&*/ !aSO->_is_nil() ) {
1878 CORBA::String_var entry = aSO->GetID();
1879 anEntryList << entry.in();
1883 tbl->setValues( step );
1885 // update the presentation if it is displayed
1886 CORBA::String_var aStepEntry = step->GetStudyEntry();
1887 Handle(SALOME_InteractiveObject) aStepIO =
1888 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
1889 getDisplayer()->Redisplay( aStepIO, false, false );
1891 getDisplayer()->UpdateViewer();
1894 if ( !myIsCreation )
1896 QSet< int >::iterator stepID = myRemovedSteps.begin();
1897 for ( ; stepID != myRemovedSteps.end(); ++stepID )
1899 GEOM::GEOM_FieldStep_var step = myField->GetStep( *stepID );
1900 if ( !step->_is_nil() )
1902 CORBA::String_var entry = step->GetStudyEntry();
1903 myField->RemoveStep( *stepID );
1906 SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() );
1907 if ( !SO->_is_nil() )
1908 aBuilder->RemoveObjectWithChildren( SO );
1913 myRemovedSteps.clear();
1917 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
1918 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
1919 if( aLightApp && !isDisableBrowsing() && anEntryList.count() )
1921 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
1922 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );