1 // Copyright (C) 2007-2024 CEA, EDF, 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, or (at your option) any later version.
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 // File : EntityGUI_FieldDlg.cxx
25 #include "EntityGUI_FieldDlg.h"
29 #include <GEOMBase_Skeleton.h>
30 #include <GEOM_Displayer.h>
31 #include <GeometryGUI.h>
33 #include <SalomeApp_Application.h>
34 #include <SalomeApp_Study.h>
35 #include <SalomeApp_Tools.h>
36 #include <SalomeApp_IntSpinBox.h>
37 #include <SalomeApp_DoubleSpinBox.h>
39 #include <LightApp_SelectionMgr.h>
41 #include <OCCViewer_ViewModel.h>
42 #include <OCCViewer_ViewManager.h>
43 #include <SVTK_ViewModel.h>
44 #include <SALOME_Prs.h>
45 #include <SALOME_ListIO.hxx>
47 #include <SUIT_Desktop.h>
48 #include <SUIT_MessageBox.h>
49 #include <SUIT_OverrideCursor.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_ViewWindow.h>
53 #include <SUIT_ViewManager.h>
56 #include <QGridLayout>
58 #include <QHeaderView>
59 #include <QInputDialog>
62 #include <QPushButton>
63 #include <QTableWidget>
64 #include <QVBoxLayout>
66 #include <AIS_ListOfInteractive.hxx>
67 #include <AIS_ListIteratorOfListOfInteractive.hxx>
70 #include <TopExp_Explorer.hxx>
71 #include <TopTools_IndexedMapOfShape.hxx>
72 #include <TColStd_IndexedMapOfInteger.hxx>
73 #include <TColStd_MapOfInteger.hxx>
74 #include <TColStd_DataMapIteratorOfDataMapOfIntegerInteger.hxx>
78 #include <SALOMEDS_wrap.hxx>
79 #include <GEOMImpl_Types.hxx>
86 const int theIntLimit = std::numeric_limits<int>::max() - 10;
89 Class : EntityGUI_FieldDlg::CheckItem
90 Description : Bool item.
92 class EntityGUI_FieldDlg::CheckItem : public QTableWidgetItem
97 CheckItem( bool = false );
100 void setValue( bool );
104 int EntityGUI_FieldDlg::CheckItem::Type()
106 return QTableWidgetItem::UserType + 2;
109 EntityGUI_FieldDlg::CheckItem::CheckItem( bool value )
110 : QTableWidgetItem( Type() )
112 Qt::ItemFlags f = flags();
113 f = f | Qt::ItemIsUserCheckable;
114 f = f & ~Qt::ItemIsTristate;
115 f = f & ~Qt::ItemIsEditable;
120 EntityGUI_FieldDlg::CheckItem::~CheckItem()
124 void EntityGUI_FieldDlg::CheckItem::setValue( bool value )
126 setCheckState( value ? Qt::Checked : Qt::Unchecked );
129 bool EntityGUI_FieldDlg::CheckItem::value() const
131 return checkState() == Qt::Checked;
135 Class : EntityGUI_FieldDlg::IntSpinItem
136 Description : Integer spin table item.
139 class EntityGUI_FieldDlg::IntSpinItem : public QTableWidgetItem
144 IntSpinItem( const int theValue );
147 void setValue( const int theValue );
152 int EntityGUI_FieldDlg::IntSpinItem::Type()
154 return QTableWidgetItem::UserType + 3;
157 EntityGUI_FieldDlg::IntSpinItem::IntSpinItem( const int theValue )
158 : QTableWidgetItem( Type() )
160 setValue( theValue );
163 int EntityGUI_FieldDlg::IntSpinItem::value() const
166 int value = data( Qt::UserRole ).toInt( &ok );
167 return ok ? value : 0;
170 void EntityGUI_FieldDlg::IntSpinItem::setValue( const int theValue )
172 setData( Qt::UserRole, theValue );
173 setText( QString::number( theValue ) );
176 void EntityGUI_FieldDlg::IntSpinItem::clear()
182 Class : EntityGUI_FieldDlg::DoubleSpinItem
183 Description : Double spin table item.
186 class EntityGUI_FieldDlg::DoubleSpinItem : public QTableWidgetItem
191 DoubleSpinItem( const double theValue, const int thePrecision=6 );
193 double value() const;
194 void setValue( const double theValue );
196 int precision() const;
197 void setPrecision( const int thePrecision );
202 int EntityGUI_FieldDlg::DoubleSpinItem::Type()
204 return QTableWidgetItem::UserType + 4;
207 EntityGUI_FieldDlg::DoubleSpinItem::DoubleSpinItem( const double theValue,
208 const int thePrecision)
209 : QTableWidgetItem( Type() )
211 setValue( theValue );
212 setPrecision( thePrecision );
215 double EntityGUI_FieldDlg::DoubleSpinItem::value() const
218 double value = data( Qt::UserRole ).toDouble( &ok );
219 return ok ? value : 0;
222 void EntityGUI_FieldDlg::DoubleSpinItem::setValue( const double theValue )
224 setData( Qt::UserRole, theValue );
225 setText( QString::number( theValue ) );
228 int EntityGUI_FieldDlg::DoubleSpinItem::precision() const
231 int precision = data( Qt::UserRole + 1 ).toInt( &ok );
232 return ok ? precision : 0;
235 void EntityGUI_FieldDlg::DoubleSpinItem::setPrecision( const int thePrecision )
237 setData( Qt::UserRole + 1, thePrecision );
240 void EntityGUI_FieldDlg::DoubleSpinItem::clear()
246 Class : EntityGUI_FieldDlg::ComboDelegate
247 Description : Table used by this widget
250 class EntityGUI_FieldDlg::Delegate : public QItemDelegate
253 Delegate( QObject* = 0 );
256 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
257 const QModelIndex& ) const;
259 void setEditorData( QWidget*, const QModelIndex& ) const;
260 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
262 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
263 const QModelIndex& ) const;
268 EntityGUI_FieldDlg::Delegate::Delegate( QObject* parent )
269 : QItemDelegate( parent ),
270 myTable( dynamic_cast<EntityGUI_FieldDlg::StepTable*>( parent ) )
274 EntityGUI_FieldDlg::Delegate::~Delegate()
278 QWidget* EntityGUI_FieldDlg::Delegate::createEditor( QWidget* parent,
279 const QStyleOptionViewItem& option,
280 const QModelIndex& index ) const
282 QVariant aData = index.data( Qt::UserRole );
283 QVariant::Type aDataType = aData.type();
284 if( aDataType == QVariant::Int ) {
286 int aValue = aData.toInt( &ok );
288 SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( -theIntLimit, theIntLimit, 1, parent, false, true );
289 intSpin->setFrame( false );
290 intSpin->setValue( aValue );
294 else if( aDataType == QVariant::Double ) {
296 double aValue = aData.toDouble( &ok );
298 int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
302 SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
303 dblSpin->setFrame( false );
304 dblSpin->setValue( aValue );
308 return QItemDelegate::createEditor( parent, option, index );
311 void EntityGUI_FieldDlg::Delegate::setEditorData( QWidget* editor,
312 const QModelIndex& index ) const
314 QVariant data = index.model()->data( index, Qt::DisplayRole );
315 QString value = data.toString();
317 if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
318 if( data.type() == QVariant::Double ) {
319 double valueDouble = data.toDouble( &bOk );
321 dblSpin->setValue( valueDouble );
324 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
327 void EntityGUI_FieldDlg::Delegate::setModelData( QWidget* editor,
328 QAbstractItemModel* model,
329 const QModelIndex& index) const
331 QString oldData = myTable->text( index.row(), index.column() );
333 if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
334 model->setData( index, intSpin->value(), Qt::DisplayRole );
335 else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
336 model->setData( index, dblSpin->value(), Qt::DisplayRole );
338 QItemDelegate::setModelData( editor, model, index );
340 QString newData = myTable->text( index.row(), index.column() );
341 if ( newData != oldData )
342 myTable->setIsChanged();
345 void EntityGUI_FieldDlg::Delegate::updateEditorGeometry( QWidget* editor,
346 const QStyleOptionViewItem& option,
347 const QModelIndex& /*index*/ ) const
349 editor->setGeometry( option.rect );
352 //=======================================================================
353 // name : EntityGUI_FieldDlg::StepTable::Table
354 // Purpose : Constructor
355 //=======================================================================
356 EntityGUI_FieldDlg::StepTable::StepTable (int stepID, int dataType,
357 int nbRows, int nbComps,
358 QString shapeName, QStringList headers,
359 GEOM::GEOM_FieldStep_ptr stepVar,
361 : QTableWidget(0, nbComps+1, parent),
362 myDataType( dataType ),
365 myStep( GEOM::GEOM_FieldStep::_duplicate( stepVar )),
368 setDim( nbRows, shapeName, stepVar->_is_nil() );
370 setHorizontalHeaderLabels( headers );
371 verticalHeader()->hide();
373 // set custom item delegate
374 setItemDelegate( new Delegate(this) );
375 // set edit triggers by default
376 setReadOnly( false );
378 if ( stepVar->_is_nil() )
380 connect( horizontalHeader(), SIGNAL( sectionDoubleClicked( int ) ), this, SLOT( headerDblClicked( int ) ) );
384 myStamp = stepVar->GetStamp();
386 const int nbColumns = nbComps + 1;
392 GEOM::GEOM_BoolFieldStep_var bs = GEOM::GEOM_BoolFieldStep::_narrow( stepVar );
393 if ( !bs->_is_nil() )
395 GEOM::short_array_var vals = bs->GetValues();
396 if ( (int)vals->length() == nbRows * nbComps )
397 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
398 for ( int iC = 1; iC < nbColumns; ++iC )
399 setItem( iR, iC, new CheckItem( vals[ iV++ ]));
401 connect( this, SIGNAL( itemClicked(QTableWidgetItem *)), this, SLOT( setIsChanged() ));
406 GEOM::GEOM_IntFieldStep_var is = GEOM::GEOM_IntFieldStep::_narrow( stepVar );
407 if ( !is->_is_nil() )
409 GEOM::ListOfLong_var vals = is->GetValues();
410 if ( (int)vals->length() == nbRows * nbComps )
411 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
412 for ( int iC = 1; iC < nbColumns; ++iC )
413 setItem( iR, iC, new IntSpinItem( vals[ iV++ ]));
419 GEOM::GEOM_DoubleFieldStep_var ds = GEOM::GEOM_DoubleFieldStep::_narrow( stepVar );
420 if ( !ds->_is_nil() )
422 GEOM::ListOfDouble_var vals = ds->GetValues();
423 if ( (int)vals->length() == nbRows * nbComps )
424 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
425 for ( int iC = 1; iC < nbColumns; ++iC )
426 setItem( iR, iC, new DoubleSpinItem( vals[ iV++ ]));
431 GEOM::GEOM_StringFieldStep_var ss = GEOM::GEOM_StringFieldStep::_narrow( stepVar );
432 if ( !ss->_is_nil() )
434 GEOM::string_array_var vals = ss->GetValues();
435 if ( (int)vals->length() == nbRows * nbComps )
436 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
437 for ( int iC = 1; iC < nbColumns; ++iC )
438 setItem( iR, iC, new QTableWidgetItem( vals[ iV++ ].in() ));
444 //=======================================================================
445 // name : EntityGUI_FieldDlg::StepTable::~StepTable
446 // Purpose : Destructor
447 //=======================================================================
448 EntityGUI_FieldDlg::StepTable::~StepTable()
452 //=======================================================================
453 // name : EntityGUI_FieldDlg::StepTable::minimumSizeHint
454 // Purpose : Get minimum size for the table
455 //=======================================================================
456 QSize EntityGUI_FieldDlg::StepTable::minimumSizeHint() const
458 QSize s = QTableWidget::minimumSizeHint();
459 QHeaderView* hv = horizontalHeader();
461 s.setWidth( qMax( s.width(), hv->length() ) );
465 //=======================================================================
466 // name : EntityGUI_FieldDlg::StepTable::setEditable
467 // Purpose : Set editable of specified cell
468 //=======================================================================
469 void EntityGUI_FieldDlg::StepTable::setEditable (bool isEditable,
472 QTableWidgetItem* anItem = item( row, col );
474 bool isSignalsBlocked = signalsBlocked();
475 blockSignals( true );
477 Qt::ItemFlags f = anItem->flags();
478 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
479 else f = f | Qt::ItemIsEditable;
480 anItem->setFlags( f );
482 blockSignals( isSignalsBlocked );
486 //=======================================================================
487 // name : EntityGUI_FieldDlg::StepTable::isEditable
488 // Purpose : Verify whether cell is editable
489 //=======================================================================
490 bool EntityGUI_FieldDlg::StepTable::isEditable (int row, int col) const
492 QTableWidgetItem* anItem = item( row, col );
493 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
496 void EntityGUI_FieldDlg::StepTable::setReadOnly( bool on )
498 setEditTriggers( on ?
499 QAbstractItemView::NoEditTriggers :
500 QAbstractItemView::AllEditTriggers );
503 bool EntityGUI_FieldDlg::StepTable::isReadOnly() const
505 return editTriggers() == QAbstractItemView::NoEditTriggers;
508 //=======================================================================
509 // name : EntityGUI_FieldDlg::StepTable::insertRows
510 // Purpose : Insert rows (virtual redefined)
511 //=======================================================================
512 void EntityGUI_FieldDlg::StepTable::insertRows (int row, int count)
514 while ( count-- ) insertRow( row );
517 //=======================================================================
518 // name : EntityGUI_FieldDlg::StepTable::text
519 // Purpose : Get text from cell (virtual redefined)
520 //=======================================================================
521 QString EntityGUI_FieldDlg::StepTable::text (int row, int col)
523 closePersistentEditor( currentItem() );
524 QTableWidgetItem* anItem = item( row, col );
525 return anItem ? anItem->text() : QString();
528 QList<int> EntityGUI_FieldDlg::StepTable::selectedRows()
530 QList<QTableWidgetItem*> selItems = selectedItems();
531 QTableWidgetItem* anItem;
534 foreach( anItem, selItems ) {
535 int r = row( anItem );
536 if ( !rows.contains( r ) ) rows.append( r );
543 //=======================================================================
544 //function : selectRows
546 //=======================================================================
548 void EntityGUI_FieldDlg::StepTable::selectRows(const QList<int>& rows)
550 closePersistentEditor( currentItem() );
552 QList<QTableWidgetSelectionRange> ranges = selectedRanges();
553 for ( int i = 0; i < ranges.count(); ++i )
554 setRangeSelected( ranges[i], false );
556 QList<int>::const_iterator row = rows.begin();
557 for ( ; row != rows.end(); ++row )
558 // QTableWidgetSelectionRange ( int top, int left, int bottom, int right )
559 setRangeSelected ( QTableWidgetSelectionRange(*row,0,*row,0), true );
562 //=======================================================================
564 //purpose : change nb rows in the table
565 //=======================================================================
567 void EntityGUI_FieldDlg::StepTable::setDim( int nbRows, QString shapeName, bool setDefault )
569 closePersistentEditor( currentItem() );
570 int curNbRows = rowCount();
571 if ( nbRows < curNbRows )
573 while ( nbRows < curNbRows )
574 removeRow( --curNbRows );
576 else if ( nbRows > curNbRows )
578 int nbColumns = columnCount();
579 for ( ; nbRows > curNbRows; ++curNbRows )
581 insertRow( curNbRows );
583 for ( int iC = 1; iC < nbColumns; ++iC )
584 setItem( curNbRows, iC, newDefaultItem() );
588 int indexWidth = 1, maxNbR = 10;
589 while ( nbRows >= maxNbR )
590 ++indexWidth, maxNbR *= 10;
591 shapeName = shapeName.toLower() + "_%1";
592 for ( int iR = 0; iR < nbRows; ++iR )
594 setItem( iR, 0, new QTableWidgetItem( shapeName.arg( iR+1, indexWidth, 10, QChar('0') )));
595 setEditable( false, iR, 0 );
599 //=======================================================================
600 //function : setNbComps
602 //=======================================================================
604 void EntityGUI_FieldDlg::StepTable::setNbComps( int nbComps )
606 closePersistentEditor( currentItem() );
607 nbComps++; // add sub-shape column
608 int curNbCols = columnCount();
609 if ( nbComps < curNbCols )
611 while ( nbComps < curNbCols )
612 removeColumn( --curNbCols );
614 else if ( nbComps > curNbCols )
616 int nbRows = rowCount();
617 for ( ; nbComps > curNbCols; ++curNbCols )
619 insertColumn( curNbCols );
620 setHorizontalHeaderItem( curNbCols,
621 new QTableWidgetItem(QString("Comp %1").arg( curNbCols )));
622 for ( int iR = 0; iR < nbRows; ++iR )
623 setItem( iR, curNbCols, newDefaultItem() );
628 //=======================================================================
629 //function : setDataType
630 //purpose : change type of data
631 //=======================================================================
633 void EntityGUI_FieldDlg::StepTable::setDataType( int dataType )
635 myDataType = dataType;
637 int nbRows = rowCount();
638 int nbColumns = columnCount();
640 for ( int iR = 0; iR < nbRows; ++iR )
641 for ( int iC = 1; iC < nbColumns; ++iC )
642 setItem( iR, iC, newDefaultItem() );
645 //=======================================================================
646 //function : newDefaultItem
647 //purpose : creates a table item with a default value
648 //=======================================================================
650 QTableWidgetItem * EntityGUI_FieldDlg::StepTable::newDefaultItem()
652 switch( myDataType ) {
653 case 0: return new CheckItem(false);
654 case 1: return new IntSpinItem(0);
655 case 2: return new DoubleSpinItem(0);
658 return new QTableWidgetItem(""); // string
661 //=======================================================================
662 //function : getHeaders
664 //=======================================================================
666 QStringList EntityGUI_FieldDlg::StepTable::getHeaders()
669 int nbColumns = columnCount();
670 for ( int iC = 0; iC < nbColumns; ++iC )
671 headers << horizontalHeaderItem( iC )->text();
675 //=======================================================================
676 //function : setHeaders
678 //=======================================================================
680 void EntityGUI_FieldDlg::StepTable::setHeaders(const QStringList& headers)
682 setHorizontalHeaderLabels( headers );
685 //=======================================================================
686 //function : setValues
687 //purpose : store values from this table to a field step
688 //=======================================================================
690 void EntityGUI_FieldDlg::StepTable::setValues(GEOM::GEOM_FieldStep_var& step)
692 closePersistentEditor( currentItem() );
694 if ( step->GetStamp() != myStamp )
695 step->SetStamp( myStamp );
697 if ( step->_is_equivalent( myStep ) && !myIsChanged )
700 const int nbColumns = columnCount();
701 const int nbComps = nbColumns - 1;
702 const int nbRows = rowCount();
704 switch ( myDataType ) {
707 GEOM::GEOM_BoolFieldStep_var bs = GEOM::GEOM_BoolFieldStep::_narrow( step );
708 if ( !bs->_is_nil() )
710 GEOM::short_array_var vals = new GEOM::short_array();
711 vals->length( nbRows * nbComps );
712 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
713 for ( int iC = 1; iC < nbColumns; ++iC )
714 vals[ iV++ ] = ((CheckItem*)item( iR, iC ))->value();
715 bs->SetValues( vals );
721 GEOM::GEOM_IntFieldStep_var is = GEOM::GEOM_IntFieldStep::_narrow( step );
722 if ( !is->_is_nil() )
724 GEOM::ListOfLong_var vals = new GEOM::ListOfLong();
725 vals->length( nbRows * nbComps );
726 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
727 for ( int iC = 1; iC < nbColumns; ++iC )
728 vals[ iV++ ] = text( iR, iC ).toInt();
729 is->SetValues( vals );
735 GEOM::GEOM_DoubleFieldStep_var ds = GEOM::GEOM_DoubleFieldStep::_narrow( step );
736 if ( !ds->_is_nil() )
738 GEOM::ListOfDouble_var vals = new GEOM::ListOfDouble();
739 vals->length( nbRows * nbComps );
740 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
741 for ( int iC = 1; iC < nbColumns; ++iC )
742 vals[ iV++ ] = text( iR, iC ).toDouble();
743 ds->SetValues( vals );
749 GEOM::GEOM_StringFieldStep_var ss = GEOM::GEOM_StringFieldStep::_narrow( step );
750 if ( !ss->_is_nil() )
752 GEOM::string_array_var vals = new GEOM::string_array();
753 vals->length( nbRows * nbComps );
754 for ( int iV = 0, iR = 0; iR < nbRows; ++iR )
755 for ( int iC = 1; iC < nbColumns; ++iC )
756 vals[ iV++ ] = item( iR, iC )->text().toUtf8().constData();
757 ss->SetValues( vals );
766 //=======================================================================
767 //function : headerDblClicked
768 //purpose : rename column, called when used double-clicks on the header
769 //=======================================================================
771 void EntityGUI_FieldDlg::StepTable::headerDblClicked( int section )
775 QString label = QInputDialog::getText( this, EntityGUI_FieldDlg::tr( "RENAME_COMPONENT" ),
776 EntityGUI_FieldDlg::tr ( "COMPONENT_NAME" ), QLineEdit::Normal,
777 horizontalHeaderItem( section )->text(), &bOk );
778 if ( bOk && !label.isEmpty() )
779 horizontalHeaderItem( section )->setText( label );
783 //=======================================================================
784 //function : EntityGUI_FieldDlg
786 //=======================================================================
788 EntityGUI_FieldDlg::EntityGUI_FieldDlg (GeometryGUI* theGeometryGUI,
789 GEOM::GEOM_Field_ptr theField, int stepID,
791 bool modal, Qt::WindowFlags fl)
792 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
793 myIsCreation( CORBA::is_nil( theField )),
794 myField( GEOM::GEOM_Field::_duplicate( theField )),
795 myCurStepID( stepID ),
796 myCurStepTable( NULL ),
797 myIsHiddenMain( false )
799 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
800 QPixmap iconSelect (resMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
802 setWindowTitle(myIsCreation ? tr("CREATE_FIELD_TITLE") : tr("EDIT_FIELD_TITLE"));
804 // Shape type button group
805 mainFrame()->GroupConstructors->hide();
808 mainFrame()->GroupBoxName->setTitle(tr("FIELD_NAME"));
812 QGroupBox* propGroup = new QGroupBox(tr("PROPERTIES"), centralWidget());
813 QGridLayout* propLayout = new QGridLayout(propGroup);
814 propLayout->setMargin(9);
815 propLayout->setSpacing(6);
818 QLabel* shapeLabel = new QLabel(tr("SHAPE"), propGroup);
819 myShapeSelBtn = new QPushButton(propGroup);
820 myShapeSelBtn->setIcon(iconSelect);
821 myShapeSelBtn->setEnabled( myIsCreation );
822 myShapeName = new QLineEdit(propGroup);
823 myShapeName->setReadOnly(true);
824 myShapeName->setEnabled( myIsCreation );
827 QLabel* typeLabel = new QLabel( tr("DATA_TYPE"), propGroup );
828 myTypeCombo = new QComboBox( propGroup );
829 myTypeCombo->insertItem( GEOM::FDT_Bool, tr("BOOL"));
830 myTypeCombo->insertItem( GEOM::FDT_Int, tr("INT"));
831 myTypeCombo->insertItem( GEOM::FDT_Double, tr("DOUBLE"));
832 myTypeCombo->insertItem( GEOM::FDT_String, tr("STRING"));
833 myTypeCombo->setCurrentIndex( GEOM::FDT_Double ); // double
836 QLabel* dimLabel = new QLabel( tr("SHAPE_TYPE"), propGroup );
837 myDimCombo = new QComboBox( propGroup );
840 QLabel* nbCompsLabel = new QLabel( tr("NB_COMPS"), propGroup );
841 myNbCompsSpin = new SalomeApp_IntSpinBox( 1, 1000, 1, propGroup, true, true );
842 myNbCompsSpin->setValue( 1 );
843 propLayout->addWidget(shapeLabel, 0, 0);
844 propLayout->addWidget(myShapeSelBtn, 0, 1);
845 propLayout->addWidget(myShapeName, 0, 2);
846 propLayout->addWidget(typeLabel, 1, 0, 1, 2);
847 propLayout->addWidget(myTypeCombo, 1, 2);
848 propLayout->addWidget(dimLabel, 2, 0, 1, 2);
849 propLayout->addWidget(myDimCombo, 2, 2);
850 propLayout->addWidget(nbCompsLabel, 3, 0, 1, 2);
851 propLayout->addWidget(myNbCompsSpin, 3, 2);
852 // propLayout->addWidget(shapeLabel, 0, 0);
853 // propLayout->addWidget(myShapeName, 0, 1);
854 // propLayout->addWidget(typeLabel, 1, 0);
855 // propLayout->addWidget(myTypeCombo, 1, 1);
856 // propLayout->addWidget(dimLabel, 2, 0);
857 // propLayout->addWidget(myDimCombo, 2, 1);
858 // propLayout->addWidget(nbCompsLabel, 3, 0);
859 // propLayout->addWidget(myNbCompsSpin, 3, 1);
861 propLayout->setColumnStretch(2, 5);
865 QGroupBox* valsGroup = new QGroupBox(tr("VALUES"), centralWidget());
866 QGridLayout* valsLayout = new QGridLayout(valsGroup);
867 valsLayout->setMargin(9);
868 valsLayout->setSpacing(6);
871 mySwitchTableWdg = new QWidget(valsGroup);
872 QVBoxLayout* switchTableGrpLayout = new QVBoxLayout(mySwitchTableWdg);
873 switchTableGrpLayout->setMargin(0);
874 switchTableGrpLayout->setSpacing(0);
876 // step add/rm controls
877 QPushButton* addStepBtn = new QPushButton( tr("ADD_STEP"), valsGroup );
878 QLabel* curStepLbl = new QLabel(tr("STEP"), valsGroup );
879 myStepEdit = new QLineEdit( valsGroup );
880 myStepsCombo = new QComboBox(valsGroup);
881 myStepsCombo->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
882 myRmStepBtn = new QPushButton( tr("REMOVE_STEP"), valsGroup );
884 // step browse controls
885 myPrevStepBtn = new QPushButton( tr("PREV_STEP"), valsGroup );
886 QLabel* stampLbl = new QLabel(tr("STAMP"), valsGroup );
887 myStampSpin = new SalomeApp_IntSpinBox( -theIntLimit, theIntLimit, 1, valsGroup, true, true);
888 myNextStepBtn = new QPushButton( tr("NEXT_STEP"), valsGroup );
890 valsLayout->addWidget(mySwitchTableWdg, 0, 0, 1, 5);
891 valsLayout->addWidget(addStepBtn, 1, 0);
892 valsLayout->addWidget(curStepLbl, 1, 1);
893 valsLayout->addWidget(myStepEdit, 1, 2);
894 valsLayout->addWidget(myStepsCombo, 1, 3);
895 valsLayout->addWidget(myRmStepBtn, 1, 4);
896 valsLayout->addWidget(myPrevStepBtn, 2, 0);
897 valsLayout->addWidget(stampLbl, 2, 1);
898 valsLayout->addWidget(myStampSpin, 2, 2, 1, 2);
899 valsLayout->addWidget(myNextStepBtn, 2, 4);
901 valsLayout->setColumnStretch(3, 5);
902 valsLayout->setRowStretch (0, 5);
904 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
905 layout->setMargin(0); layout->setSpacing(6);
906 layout->addWidget(propGroup);
907 layout->addWidget(valsGroup);
909 setHelpFileName("geom_field_page.html");
911 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
912 connect(aSelMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
914 connect(myPrevStepBtn, SIGNAL(clicked()), this, SLOT( onPrevStep() ));
915 connect(myNextStepBtn, SIGNAL(clicked()), this, SLOT( onNextStep() ));
916 connect(addStepBtn, SIGNAL(clicked()), this, SLOT( onAddStep() ));
917 connect(myRmStepBtn, SIGNAL(clicked()), this, SLOT( onRmStep() ));
918 connect(myStampSpin, SIGNAL(valueChanged(int)), this, SLOT( onStampChange() ));
919 connect(myStepsCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( showCurStep() ));
920 connect(myStepsCombo, SIGNAL(activated(int)), this, SLOT( showCurStep() ));
922 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
923 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
929 //=======================================================================
930 //function : ~EntityGUI_FieldDlg
932 //=======================================================================
934 EntityGUI_FieldDlg::~EntityGUI_FieldDlg()
936 GEOM_Displayer* aDisplayer = getDisplayer();
937 if (myIsHiddenMain) {
938 aDisplayer->Display(myShape);
939 myIsHiddenMain = false;
941 // if ( !myField->_is_nil())
942 // aDisplayer->Display(myField);
944 QListIterator<int> anIter( myHiddenFieldStepIds );
945 while( anIter.hasNext() )
947 const int aStepId = anIter.next();
948 GEOM::GEOM_FieldStep_var step = myField->GetStep( aStepId );
949 if( !step->_is_nil() )
950 aDisplayer->Display( step, false );
952 aDisplayer->UpdateViewer();
955 //=================================================================================
958 //=================================================================================
959 void EntityGUI_FieldDlg::Init()
962 myHiddenFieldStepIds.clear();
963 myStepsCombo->clear();
965 if ( myIsCreation || myField->_is_nil() )
968 myStepTables.clear();
969 if ( myCurStepTable )
970 myCurStepTable->hide();
971 myCurStepTable = NULL;
974 initName(tr("FIELD_PREFIX"));
975 myStampSpin->setValue(0);
977 SelectionIntoArgument();
981 connect(myShapeSelBtn, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
982 connect(myTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onTypeChange()));
983 connect(myDimCombo, SIGNAL(currentIndexChanged(int)), this, SLOT( onDimChange()));
984 connect(myNbCompsSpin, SIGNAL(valueChanged(int)), this, SLOT( onNbCompsChange()));
989 // 1) get and sort step IDs
990 // 2) hide all displayed field steps' presentations
991 GEOM_Displayer* aDisplayer = getDisplayer();
992 GEOM::ListOfLong_var stepIDs = myField->GetSteps();
994 QList< int > stepsList;
995 for ( i = 0; i < stepIDs->length(); ++i )
997 int aStepId = stepIDs[i];
998 stepsList.push_back( aStepId );
999 GEOM::GEOM_FieldStep_var step = myField->GetStep( aStepId );
1000 if( !step->_is_nil() )
1002 QString anEntry( step->GetStudyEntry() );
1003 if( aDisplayer->IsDisplayed( anEntry ) )
1005 aDisplayer->Erase( step, false, false );
1006 myHiddenFieldStepIds << aStepId;
1010 qSort( stepsList.begin(), stepsList.end() );
1012 myIsCreation = false;
1014 CORBA::String_var fName = myField->GetName();
1015 myMainFrame->ResultName->setText( fName.in() );
1017 myShape = myField->GetShape();
1018 CORBA::String_var sName;
1019 if ( !myShape->_is_nil() )
1020 sName = myShape->GetName();
1021 myShapeName->setText( sName.in() ? sName.in() : "");
1023 myTypeCombo->setCurrentIndex( myField->GetDataType() );
1025 updateDims( myField->GetDimension() );
1028 GEOM::string_array_var compNames = myField->GetComponents();
1029 myNbCompsSpin->setValue( compNames->length() );
1031 myShapeSelBtn->setEnabled( false );
1032 myShapeName->setEnabled( false );
1033 myTypeCombo->setEnabled( false );
1034 myDimCombo->setEnabled( false );
1035 myNbCompsSpin->setEnabled( false );
1037 myStepsCombo->blockSignals( true );
1038 for ( i = 0; i < stepIDs->length(); ++i )
1040 myStepsCombo->insertItem( i, QString::number( stepsList[i] ));
1041 if ( myCurStepID == stepsList[i] )
1042 myStepsCombo->setCurrentIndex( i );
1044 // if ( myStepsCombo->count() == 0 )
1045 // myStepsCombo->insertItem( 0, QString::number( myCurStepID ));
1046 myStepsCombo->blockSignals( false );
1049 activateSelection();
1053 //=================================================================================
1054 // function : enterEvent()
1056 //=================================================================================
1057 void EntityGUI_FieldDlg::enterEvent(QEvent*)
1059 if (!buttonCancel()->isEnabled())
1060 ActivateThisDialog();
1063 //=================================================================================
1064 // function : ClickOnOk()
1066 //=================================================================================
1067 void EntityGUI_FieldDlg::ClickOnOk()
1069 setIsApplyAndClose(true);
1072 setIsApplyAndClose(false);
1075 //=================================================================================
1076 // function : ClickOnApply()
1078 //=================================================================================
1079 bool EntityGUI_FieldDlg::ClickOnApply()
1081 if(!isApplyAndClose()) {
1082 setIsDisableBrowsing( true );
1083 setIsDisplayResult( false );
1087 if ( !isValid( msg ) ) {
1091 SUIT_OverrideCursor wc;
1092 SUIT_Session::session()->activeApplication()->putInfo( "" );
1095 if ( openCommand() )
1096 if (!execute (/*isApplyAndClose()*/))
1103 catch( const SALOME::SALOME_Exception& e ) {
1104 SalomeApp_Tools::QtCatchCorbaException( e );
1110 if(!isApplyAndClose()) {
1111 setIsDisableBrowsing( false );
1112 setIsDisplayResult( true );
1117 myField = GEOM::GEOM_Field::_nil();
1118 if ( !isApplyAndClose() )
1124 //=================================================================================
1125 // function : ActivateThisDialog()
1127 //=================================================================================
1128 void EntityGUI_FieldDlg::ActivateThisDialog()
1130 GEOMBase_Skeleton::ActivateThisDialog();
1132 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
1133 this, SLOT(SelectionIntoArgument()));
1135 activateSelection();
1138 //=================================================================================
1139 // function : SetEditCurrentArgument()
1141 //=================================================================================
1142 void EntityGUI_FieldDlg::SetEditCurrentArgument()
1144 myEditCurrentArgument = myShapeName;
1145 SelectionIntoArgument();
1148 //=================================================================================
1149 // function : SelectionIntoArgument()
1150 // purpose : Called when selection has changed
1151 //=================================================================================
1152 void EntityGUI_FieldDlg::SelectionIntoArgument()
1154 if (myEditCurrentArgument == myShapeName || // Selection of a shape is active
1157 myShapeName->setText("");
1158 myShape = GEOM::GEOM_Object::_nil();
1160 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
1161 SALOME_ListIO aSelList;
1162 aSelMgr->selectedObjects(aSelList);
1163 int nbSel = aSelList.Extent();
1166 GEOM::GEOM_Object_var anObj =
1167 GEOMBase::ConvertIOinGEOMObject(aSelList.First());
1169 if ( GEOMBase::IsShape(anObj) && anObj->IsMainShape() ) {
1170 if (myIsHiddenMain) {
1171 GEOM_Displayer* aDisplayer = getDisplayer();
1172 aDisplayer->Display(myShape);
1173 myIsHiddenMain = false;
1175 myShapeName->setText(GEOMBase::GetName(anObj));
1177 if ( !anObj->_is_nil() && !anObj->IsSame( myShape ))
1181 myEditCurrentArgument = 0;
1183 // re-fill myDimCombo
1184 //const int curDim = getDim();
1193 if (myIsHiddenMain) {
1194 GEOM_Displayer* aDisplayer = getDisplayer();
1195 aDisplayer->Display(myShape);
1196 myIsHiddenMain = false;
1200 else // select rows of a table according to shape selection
1202 if ( !myCurStepTable )
1205 bool isSignalsBlocked = myCurStepTable->signalsBlocked();
1206 myCurStepTable->blockSignals(true);
1208 QList< int > rowsToSelect;
1209 TColStd_IndexedMapOfInteger aMapIndex;
1210 if ( getSelectedSubshapes(aMapIndex ))
1211 for (int ii = 1, nn = aMapIndex.Extent(); ii <= nn; ii++) {
1212 const int shapeID = aMapIndex( ii );
1213 for (int row = 0, n = myShapeIDs.size(); row < n; row++)
1214 if ( myShapeIDs[row] == shapeID ) {
1215 rowsToSelect.push_back( row );
1219 myCurStepTable->selectRows( rowsToSelect );
1221 myCurStepTable->blockSignals(isSignalsBlocked);
1225 //=================================================================================
1226 // function : onDimChange()
1227 // purpose : update dialog at change of dimension
1228 //=================================================================================
1229 void EntityGUI_FieldDlg::onDimChange()
1231 // get order of sub-shapes - myShapeIDs
1234 // update size of tables
1235 const int nbRows = myShapeIDs.size();
1236 QString subName = ( getDim() == -1 ) ? tr("WHOLE_SHAPE_VHEADER") : myDimCombo->currentText();
1237 QMap< int, StepTable* >::iterator tblIt = myStepTables.begin();
1238 for ( ; tblIt != myStepTables.end(); ++tblIt )
1239 if ( tblIt.value() )
1240 tblIt.value()->setDim( nbRows, subName );
1242 activateSelection();
1245 //=======================================================================
1246 //function : onNbCompsChange
1248 //=======================================================================
1250 void EntityGUI_FieldDlg::onNbCompsChange()
1252 QMap< int, StepTable* >::iterator tblIt = myStepTables.begin();
1253 for ( ; tblIt != myStepTables.end(); ++tblIt )
1254 if ( tblIt.value() )
1255 tblIt.value()->setNbComps( getNbComps() );
1258 //=======================================================================
1259 //function : onTypeChange
1261 //=======================================================================
1263 void EntityGUI_FieldDlg::onTypeChange()
1265 QMap< int, StepTable* >::iterator tblIt = myStepTables.begin();
1266 for ( ; tblIt != myStepTables.end(); ++tblIt )
1267 if ( tblIt.value() )
1268 tblIt.value()->setDataType( myTypeCombo->currentIndex() );
1271 //=================================================================================
1272 // function : onPrevStep()
1274 //=================================================================================
1275 void EntityGUI_FieldDlg::onPrevStep()
1277 int i = myStepsCombo->currentIndex();
1280 myStepsCombo->setCurrentIndex( i-1 );
1285 //=================================================================================
1286 // function : onNextStep()
1288 //=================================================================================
1289 void EntityGUI_FieldDlg::onNextStep()
1291 int i = myStepsCombo->currentIndex();
1292 if ( i+1 < myStepsCombo->count() )
1294 myStepsCombo->setCurrentIndex( i+1 );
1299 static int findInCombo( QComboBox* where, int what, bool& ok )
1304 for ( ; idx < where->count() && !ok; idx++ ) {
1305 int step = where->itemText( idx ).toInt();
1306 if ( step == what ) {
1309 else if ( step > what )
1316 //=======================================================================
1317 //function : onAddStep
1319 //=======================================================================
1320 void EntityGUI_FieldDlg::onAddStep()
1324 if ( !myStepEdit->text().isEmpty() )
1325 step = myStepEdit->text().toInt();
1327 int idx = findInCombo( myStepsCombo, step, ok );
1330 SUIT_MessageBox::critical(this, QObject::tr("ERR_ERROR"),
1331 tr("ERR_STEP_EXISTS"));
1335 myStepsCombo->insertItem( idx, QString::number( step ));
1336 myStepsCombo->setCurrentIndex( idx );
1337 myRemovedSteps.remove( getCurStepID() );
1341 //=======================================================================
1342 //function : onRmStep
1344 //=======================================================================
1345 void EntityGUI_FieldDlg::onRmStep()
1347 if ( myStepsCombo->count() > 1 )
1349 myStepTables.remove( getCurStepID() );
1350 myRemovedSteps.insert( getCurStepID() );
1351 if ( myCurStepTable )
1352 myCurStepTable->hide();
1353 myCurStepTable = NULL;
1354 myStepsCombo->removeItem( myStepsCombo->currentIndex() );
1359 //=======================================================================
1360 //function : onStampChange
1362 //=======================================================================
1363 void EntityGUI_FieldDlg::onStampChange()
1365 if ( myCurStepTable )
1366 myCurStepTable->setStamp( myStampSpin->value() );
1369 //=======================================================================
1370 //function : showCurStep
1372 //=======================================================================
1373 void EntityGUI_FieldDlg::showCurStep()
1375 myCurStepID = getCurStepID();
1376 myStepEdit->setText(QString::number( myCurStepID ));
1378 QStringList headers;
1379 if ( myCurStepTable )
1381 if ( myCurStepTable->getStepID() == myCurStepID )
1383 myCurStepTable->show();
1388 myCurStepTable->hide();
1389 headers = myCurStepTable->getHeaders();
1390 myCurStepTable->getStamp();
1394 if ( myStepTables.count ( myCurStepID ))
1396 myCurStepTable = myStepTables[ myCurStepID ];
1397 myCurStepTable->setHeaders( headers );
1401 // if ( myStepsCombo->count() == 0 )
1402 // return; // edit a field with no steps
1405 GEOM::GEOM_FieldStep_var stepVar;
1406 if ( !myField->_is_nil() )
1407 stepVar = myField->GetStep( myCurStepID );
1409 int nbComps = getNbComps();
1410 if ( headers.count() == 0 )
1412 headers << tr("SUB_SHAPE_HEADER");
1413 if ( !myIsCreation && !myField->_is_nil() )
1415 GEOM::string_array_var compNames = myField->GetComponents();
1416 for ( int iC = 0; iC < (int)compNames->length(); ++iC )
1417 headers << compNames[ iC ].in();
1421 for ( int iC = 0; iC < nbComps; ++iC )
1422 headers << QString("Comp %1").arg( iC + 1 );
1425 QString subName = ( getDim() == -1 ) ? tr("WHOLE_SHAPE_VHEADER") : myDimCombo->currentText();
1426 myCurStepTable = new StepTable( myCurStepID, getDataType(), myShapeIDs.size(),
1427 nbComps, subName, headers, stepVar, mySwitchTableWdg );
1428 myStepTables[ myCurStepID ] = myCurStepTable;
1429 mySwitchTableWdg->layout()->addWidget( myCurStepTable );
1431 myCurStepTable->show();
1432 myStampSpin->setValue( myCurStepTable->getStamp() );
1434 connect(myCurStepTable, SIGNAL(itemSelectionChanged()), this, SLOT( highlightSubShapes() ));
1436 myPrevStepBtn->setEnabled( myStepsCombo->currentIndex() > 0 );
1437 myNextStepBtn->setEnabled( myStepsCombo->currentIndex()+1 < myStepsCombo->count() );
1438 myRmStepBtn->setEnabled( myStepsCombo->count() > 1 );
1441 //=================================================================================
1442 // function : getSelectedSubshapes
1444 //=================================================================================
1445 int EntityGUI_FieldDlg::getSelectedSubshapes (TColStd_IndexedMapOfInteger& theMapIndex)
1447 theMapIndex.Clear();
1449 SalomeApp_Application* app = myGeomGUI->getApp();
1450 if (!app || myShape->_is_nil())
1453 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1454 SALOME_ListIO aSelList;
1455 aSelMgr->selectedObjects(aSelList);
1457 // try to find out and process the global selection
1458 // (of not published objects and of published sub-shapes)
1460 SALOME_ListIteratorOfListIO anIter (aSelList);
1461 for (int i = 0; anIter.More(); anIter.Next(), i++)
1463 Handle(SALOME_InteractiveObject) anIObj = anIter.Value();
1464 QString anEntry = anIObj->getEntry();
1466 int index = anEntry.lastIndexOf(str);
1467 if (index > 0) // selection among special preview
1469 anEntry.remove(0, index+1);
1470 int anIndex = anEntry.toInt();
1472 theMapIndex.Add(anIndex);
1474 else // selection among published shapes
1476 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1477 if (!appStudy) return 0;
1478 _PTR(Study) aStudy = appStudy->studyDS();
1480 _PTR(SObject) aSObj (aStudy->FindObjectID(anEntry.toUtf8().constData()));
1481 if ( ! GeometryGUI::IsInGeomComponent( aSObj )) continue;
1482 GEOM::GEOM_Object_var aGeomObj =
1483 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObj));
1484 TopoDS_Shape aShape;
1485 if (GEOMBase::GetShape(aGeomObj, aShape)) {
1486 if (aGeomObj->GetType() == GEOM_GROUP || aShape.ShapeType() == getShapeType())
1488 TopExp_Explorer anExp (aShape, getShapeType());
1489 for (; anExp.More(); anExp.Next()) {
1490 TopoDS_Shape aSubShape = anExp.Current();
1491 int anIndex = myShapeMap.FindIndex(aSubShape);
1493 SUIT_MessageBox::warning(app->desktop(), QObject::tr("WRN_WARNING"),
1494 tr("WRN_NOT_SUBSHAPE"));
1496 theMapIndex.Add(anIndex);
1504 return theMapIndex.Extent();
1507 //=================================================================================
1508 // function : getShapeType()
1510 //=================================================================================
1511 TopAbs_ShapeEnum EntityGUI_FieldDlg::getShapeType(int* dim) const
1514 switch ( dim ? *dim : getDim() )
1516 case 0: return TopAbs_VERTEX;
1517 case 1: return TopAbs_EDGE;
1518 case 2: return TopAbs_FACE;
1519 case 3: return TopAbs_SOLID;
1520 default: return TopAbs_SHAPE;
1524 //=======================================================================
1527 //=======================================================================
1528 int EntityGUI_FieldDlg::getDim() const
1530 int i = myDimCombo->currentIndex();
1531 return ( i < 0 ) ? -1 : myDimCombo->itemData( i ).toInt();
1534 //=======================================================================
1535 //function : getDataType
1537 //=======================================================================
1538 int EntityGUI_FieldDlg::getDataType() const
1540 return myTypeCombo->currentIndex();
1543 //=======================================================================
1544 //function : getCurStepID
1546 //=======================================================================
1547 int EntityGUI_FieldDlg::getCurStepID() const
1549 if ( myStepsCombo->count() > 0 )
1550 return myStepsCombo->currentText().toInt();
1554 //=======================================================================
1555 //function : getNbComps
1557 //=======================================================================
1558 int EntityGUI_FieldDlg::getNbComps() const
1560 return myNbCompsSpin->value();
1563 //=================================================================================
1564 // function : updateShapeIDs()
1565 // purpose : update myShapeIDs
1566 //=================================================================================
1567 void EntityGUI_FieldDlg::updateShapeIDs()
1570 //myShapeMap.Clear();
1571 if ( !myShape->_is_nil() )
1573 TopoDS_Shape aShape =
1574 GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myShape);
1575 if ( myShapeMap.IsEmpty() )
1576 TopExp::MapShapes(aShape, myShapeMap);
1577 TopAbs_ShapeEnum shapeType = getShapeType();
1578 if ( shapeType == TopAbs_SHAPE )
1580 myShapeIDs.push_back( 1 );
1584 TopTools_IndexedMapOfShape dimSubShapesMap;
1585 TopExp::MapShapes(aShape, shapeType, dimSubShapesMap);
1586 myShapeIDs.resize( dimSubShapesMap.Extent() );
1587 for ( int i = 1; i <= dimSubShapesMap.Extent(); ++i )
1588 myShapeIDs[i-1] = myShapeMap.FindIndex( dimSubShapesMap(i) );
1593 //=======================================================================
1594 //function : updateDims
1595 //purpose : update myDimCombo
1596 //=======================================================================
1597 void EntityGUI_FieldDlg::updateDims(int curDim)
1599 myDimCombo->blockSignals( true );
1600 myDimCombo->clear();
1601 TopoDS_Shape aShape =
1602 GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), myShape);
1604 if ( !aShape.IsNull() )
1606 const char* subNames[4] = { "VERTEX","EDGE","FACE","SOLID" };
1607 TopExp_Explorer exp;
1608 for ( int dim = 0; dim < 4; ++dim )
1610 exp.Init( aShape, getShapeType(&dim));
1611 if ( exp.More() && !aShape.IsSame( exp.Current() ))
1612 myDimCombo->insertItem( dim, tr( subNames[dim] ), dim );
1614 myDimCombo->insertItem( 4, tr("WHOLE"), -1 );
1616 int idx = myDimCombo->findData( curDim );
1618 myDimCombo->setCurrentIndex( idx );
1620 myDimCombo->setCurrentIndex( myDimCombo->count()-1-(myDimCombo->count()>1?1:0) );
1622 myDimCombo->blockSignals( false );
1625 //=================================================================================
1626 // function : activateSelection
1627 // purpose : Activate local selection
1628 //=================================================================================
1629 void EntityGUI_FieldDlg::activateSelection()
1631 //bool isApply = ((QPushButton*)sender() == buttonApply());
1632 if(!isApplyAndClose())
1633 erasePreview(false);
1636 if (!myShape->_is_nil() &&
1637 !myEditCurrentArgument &&
1638 myShapeIDs.size() > 1 ) // shape type is already chosen by user
1640 GEOM_Displayer* aDisplayer = getDisplayer();
1641 CORBA::String_var aMainEntry = myShape->GetStudyEntry();
1643 //display mode for main shape
1644 if ( myDmMode == -1 ) {
1645 SALOME_View* view = GEOM_Displayer::GetActiveView();
1647 Handle(SALOME_InteractiveObject) io =
1648 new SALOME_InteractiveObject (aMainEntry.in(), "GEOM", "TEMP_IO");
1649 if ( view->isVisible( io ) ) {
1650 Handle(GEOM_AISShape) aSh = GEOMBase::ConvertIOinGEOMAISShape( io, true );
1652 myDmMode = aSh->isTopLevel() ? aSh->prevDisplayMode() : aSh->DisplayMode();
1654 // Hide main shape, if explode on VERTEX
1655 if(getShapeType() != TopAbs_VERTEX) {
1656 aDisplayer->Erase(myShape, false, false);
1657 myIsHiddenMain = true;
1661 myDmMode = SUIT_Session::session()->resourceMgr()->integerValue( "Geometry", "display_mode" );
1664 aDisplayer->SetDisplayMode(myDmMode);
1666 // Mantis issue 0021421: do not hide main shape, if explode on VERTEX
1667 if (getShapeType() == TopAbs_VERTEX) {
1669 aDisplayer->Display(myShape);
1671 //aDisplayer->Erase(myField, false, false); ------- NOR YET implemented
1673 QColor aColor = SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", "editField_color" );
1674 Quantity_NameOfColor aCol = SalomeApp_Tools::color( aColor ).Name();
1676 if(!isApplyAndClose()) {
1677 SUIT_ViewWindow* aViewWindow = 0;
1678 SUIT_Study* activeStudy = SUIT_Session::session()->activeApplication()->activeStudy();
1680 aViewWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
1681 if (aViewWindow == 0) return;
1683 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1684 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1685 aViewManager->getType() != SVTK_Viewer::Type())
1688 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1689 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1690 if (aView == 0) return;
1692 TopoDS_Shape aMainShape = myShapeMap(1);
1693 for ( int i = 0; i < myShapeIDs.size(); ++i )
1695 int index = myShapeIDs[ i ];
1696 TopoDS_Shape aSubShape = myShapeMap( index );
1697 QString anEntry = QString( "TEMP_" ) + aMainEntry.in() + QString("_%1").arg(index);
1698 Handle(SALOME_InteractiveObject) io =
1699 new SALOME_InteractiveObject(anEntry.toUtf8(), "GEOM", "TEMP_IO");
1700 aDisplayer->SetColor( aCol );
1701 SALOME_Prs* aPrs = aDisplayer->buildSubshapePresentation(aSubShape, anEntry, aView);
1703 displayPreview(aPrs, true, false); // append, do not update
1704 // TODO: map or delete Prs
1707 aDisplayer->UnsetDisplayMode();
1708 aDisplayer->UnsetColor();
1709 aDisplayer->UpdateViewer();
1713 globalSelection(GEOM_ALLSHAPES);
1715 SelectionIntoArgument();
1718 //=================================================================================
1719 // function : highlightSubShapes
1720 // purpose : select objects corresponding to selected table rows
1721 //=================================================================================
1722 void EntityGUI_FieldDlg::highlightSubShapes()
1724 if (CORBA::is_nil(myShape) || !myCurStepTable )
1727 TColStd_MapOfInteger anIds;
1728 QList<int> rows = myCurStepTable->selectedRows();
1729 int ii = 0, nn = rows.count();
1730 for (; ii < nn; ii++)
1732 int shapeNum = rows[ ii ];
1733 if ( shapeNum < myShapeIDs.size() )
1734 anIds.Add( myShapeIDs[ shapeNum ]);
1737 SalomeApp_Application* app = myGeomGUI->getApp();
1738 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
1739 aSelMgr->clearSelected();
1740 if ( anIds.IsEmpty() )
1743 SUIT_ViewWindow* aViewWindow = 0;
1744 SUIT_Study* activeStudy = app->activeStudy();
1746 aViewWindow = app->desktop()->activeWindow();
1747 if (aViewWindow == 0) return;
1749 SUIT_ViewManager* aViewManager = aViewWindow->getViewManager();
1750 if (aViewManager->getType() != OCCViewer_Viewer::Type() &&
1751 aViewManager->getType() != SVTK_Viewer::Type())
1754 SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
1755 SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
1756 if (aView == 0) return;
1758 // TODO??: use here GEOMBase_Helper::myPreview instead of ic->DisplayedObjects()
1760 OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)aViewManager)->getOCCViewer();
1761 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
1762 AIS_ListOfInteractive List;
1763 //ic->DisplayedObjects(List);
1764 ic->ObjectsInside(List); // Mantis issue 0021367
1766 SALOME_ListIO aSelList;
1768 // To highlight the selected sub-shape in Object Browser, if it's already published under the main shape
1769 GEOM::GEOM_ILocalOperations_var aLocOp = getGeomEngine()->GetILocalOperations();
1770 QMap<int, QString> childsMap;
1771 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
1773 _PTR(Study) aStudy = appStudy->studyDS();
1774 CORBA::String_var aMainEntry = myShape->GetStudyEntry();
1775 _PTR(SObject) aSObj = aStudy->FindObjectID( aMainEntry.in() );
1776 _PTR(ChildIterator) anIt = aStudy->NewChildIterator(aSObj);
1777 if ( GeometryGUI::IsInGeomComponent( aSObj ))
1778 for (anIt->InitEx(true); anIt->More(); anIt->Next()) {
1779 GEOM::GEOM_Object_var aChild =
1780 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anIt->Value()));
1781 if (!CORBA::is_nil(aChild)) {
1782 int index = aLocOp->GetSubShapeIndex(myShape, aChild);
1783 if ( anIds.Contains( index )) {
1784 CORBA::String_var aChildEntry = aChild->GetStudyEntry();
1785 //childsMap.insert(index, aChildEntry.in());
1786 Handle(SALOME_InteractiveObject) tmpIO =
1787 new SALOME_InteractiveObject( aChildEntry.in(), "GEOM", "TEMP_IO");
1788 aSelList.Append(tmpIO);
1794 AIS_ListIteratorOfListOfInteractive ite (List);
1795 for (; ite.More(); ite.Next()) {
1796 if (ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
1797 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
1799 Handle(SALOME_InteractiveObject) anIO = aSh->getIO();
1800 QString anEntry = anIO->getEntry();
1801 int index = anEntry.lastIndexOf("_");
1802 anEntry.remove(0, index+1);
1803 int anIndex = anEntry.toInt();
1804 if (anIds.Contains(anIndex)) {
1805 aSelList.Append(anIO);
1806 // if (childsMap.contains (anIndex)) {
1807 // Handle(SALOME_InteractiveObject) tmpIO = new SALOME_InteractiveObject(childsMap.value(anIndex).toUtf8().constData(), "GEOM", "TEMP_IO");
1808 // aSelList.Append(tmpIO);
1814 aSelMgr->setSelectedObjects(aSelList);
1817 //=================================================================================
1818 // function : createOperation
1820 //=================================================================================
1821 GEOM::GEOM_IOperations_ptr EntityGUI_FieldDlg::createOperation()
1823 return getGeomEngine()->GetIFieldOperations();
1826 #define RETURN_WITH_MSG(a, b) \
1828 theMessage += (b); \
1832 //=================================================================================
1833 // function : isValid()
1834 // purpose : Verify validity of input data
1835 //=================================================================================
1836 bool EntityGUI_FieldDlg::isValid(QString& theMessage)
1838 SalomeApp_Study* study = getStudy();
1839 RETURN_WITH_MSG (!study, tr("GEOM_NO_STUDY"))
1840 RETURN_WITH_MSG (study->studyDS()->GetProperties()->IsLocked(), tr("GEOM_STUDY_LOCKED"))
1842 if ( myIsCreation ) {
1843 RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_SHAPE"))
1846 RETURN_WITH_MSG(CORBA::is_nil(myShape), tr("NO_FIELD"))
1849 QString aName = getNewObjectName().trimmed();
1850 RETURN_WITH_MSG (aName.isEmpty(), tr("EMPTY_NAME"))
1852 RETURN_WITH_MSG ( !myCurStepTable, tr("NO_VALUES"))
1856 //=================================================================================
1857 // function : execute
1859 //=================================================================================
1860 bool EntityGUI_FieldDlg::execute()
1862 SALOMEDS::Study_var aStudyDS = GeometryGUI::getStudyServant();
1863 SALOMEDS::StudyBuilder_var aBuilder = aStudyDS->NewBuilder();
1865 QString aName = getNewObjectName().trimmed();
1866 QStringList anEntryList;
1868 if ( myField->_is_nil() ) // create field
1870 QStringList columnNames = myCurStepTable->getHeaders();
1871 int nbComps = columnNames.count() - 1;
1872 GEOM::string_array_var compNames = new GEOM::string_array();
1873 compNames->length( nbComps );
1874 for ( int iC = 0; iC < nbComps; ++iC )
1875 compNames[ iC ] = columnNames[ iC+1 ].toUtf8().constData();
1877 GEOM::GEOM_IFieldOperations_var anOper = GEOM::GEOM_IFieldOperations::_narrow(getOperation());
1878 myField = anOper->CreateField( myShape,
1879 aName.toUtf8().constData(),
1880 GEOM::field_data_type( getDataType() ),
1881 CORBA::Short( getDim() ),
1883 if ( myField->_is_nil() )
1886 SALOMEDS::SObject_wrap aSO =
1887 getGeomEngine()->AddInStudy( myField, aName.toUtf8().constData(), myShape );
1888 if ( !aSO->_is_nil() ) {
1889 myField->UnRegister();
1890 CORBA::String_var entry = aSO->GetID();
1891 anEntryList << entry.in();
1894 else // update field name
1896 myField->SetName( aName.toUtf8().constData() );
1898 CORBA::String_var entry = myField->GetStudyEntry();
1900 SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() );
1901 if ( !SO->_is_nil() ) {
1902 aBuilder->SetName(SO, aName.toUtf8().constData());
1907 // create / update steps
1908 QMap< int, StepTable* >::iterator i_tbl = myStepTables.begin();
1909 for ( ; i_tbl != myStepTables.end(); ++i_tbl )
1911 StepTable* tbl = i_tbl.value();
1912 QString stepName = (tr("STEP")+" %1 %2").arg( tbl->getStepID() ).arg( tbl->getStamp() );
1914 GEOM::GEOM_FieldStep_var step = tbl->getStep();
1915 if ( step->_is_nil() )
1917 step = myField->GetStep( tbl->getStepID() );
1918 if ( step->_is_nil() )
1920 step = myField->AddStep( tbl->getStepID(), tbl->getStamp() );
1922 SALOMEDS::SObject_wrap aSO =
1923 getGeomEngine()->AddInStudy( step, stepName.toUtf8().constData(), myField );
1924 if ( /*!myIsCreation &&*/ !aSO->_is_nil() ) {
1926 CORBA::String_var entry = aSO->GetID();
1927 anEntryList << entry.in();
1931 else if ( step->GetStamp() != tbl->getStamp() )
1933 // update a stamp in the object browser
1934 CORBA::String_var entry = step->GetStudyEntry();
1936 SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() );
1937 if ( !SO->_is_nil() )
1938 aBuilder->SetName( SO, stepName.toUtf8().constData() );
1942 tbl->setValues( step );
1944 // update the presentation if it is displayed
1945 CORBA::String_var aStepEntry = step->GetStudyEntry();
1946 Handle(SALOME_InteractiveObject) aStepIO =
1947 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
1948 getDisplayer()->Redisplay( aStepIO, false, false );
1950 getDisplayer()->UpdateViewer();
1953 if ( !myIsCreation )
1955 QSet< int >::iterator stepID = myRemovedSteps.begin();
1956 for ( ; stepID != myRemovedSteps.end(); ++stepID )
1958 GEOM::GEOM_FieldStep_var step = myField->GetStep( *stepID );
1959 if ( !step->_is_nil() )
1961 CORBA::String_var entry = step->GetStudyEntry();
1962 myField->RemoveStep( *stepID );
1965 SALOMEDS::SObject_wrap SO = aStudyDS->FindObjectID( entry.in() );
1966 if ( !SO->_is_nil() )
1967 aBuilder->RemoveObjectWithChildren( SO );
1972 myRemovedSteps.clear();
1976 if( SUIT_Application* anApp = SUIT_Session::session()->activeApplication() ) {
1977 LightApp_Application* aLightApp = dynamic_cast<LightApp_Application*>( anApp );
1978 if( aLightApp && !isDisableBrowsing() && anEntryList.count() )
1980 aLightApp->browseObjects( anEntryList, isApplyAndClose(), isOptimizedBrowsing() );
1981 anApp->putInfo( QObject::tr("GEOM_PRP_DONE") );
1988 //=================================================================================
1989 // function : getSourceObjects
1990 // purpose : virtual method to get source objects
1991 //=================================================================================
1992 QList<GEOM::GeomObjPtr> EntityGUI_FieldDlg::getSourceObjects()
1994 QList<GEOM::GeomObjPtr> res;
1995 GEOM::GeomObjPtr aGeomObjPtr(myField->GetShape());