1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_InputPane.cxx
24 // Author : Oleg UVAROV
27 #include "VisuGUI_InputPane.h"
29 #include "VisuGUI_Prs3dDlg.h"
30 #include "VisuGUI_FieldFilter.h"
31 #include "VisuGUI_Tools.h"
33 #include "VISU_ColoredPrs3d_i.hh"
34 #include "VISU_ScalarMap_i.hh"
35 #include "VISU_Result_i.hh"
36 #include "VISU_Convertor.hxx"
38 #include "SUIT_ResourceMgr.h"
40 #include "SalomeApp_Module.h"
42 #include "LightApp_Application.h"
43 #include "LightApp_SelectionMgr.h"
45 #include "SALOME_ListIO.hxx"
47 #include "SALOMEDSClient_AttributeString.hxx"
48 #include "SALOMEDSClient_AttributeName.hxx"
50 //#include "QtxListBox.h"
54 #include <QToolButton>
59 #include <QListWidget>
62 //---------------------------------------------------------------
63 class VisuGUI_ListWidget: public QListWidget
66 VisuGUI_ListWidget( QWidget * parent = 0 ):
70 virtual QSize sizeHint() const
72 return minimumSizeHint(); }
77 //---------------------------------------------------------------
78 VisuGUI_InputPane::VisuGUI_InputPane( VISU::VISUType theType,
79 SalomeApp_Module* theModule,
80 VisuGUI_Prs3dDlg* theDialog ) :
81 QGroupBox( theDialog ),
82 myModule( theModule ),
83 myDialog( theDialog ),
85 isRestoreInitialSelection(true)
87 //setFrameStyle( QFrame::NoFrame );
89 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(theModule);
91 connect( aSelectionMgr, SIGNAL( selectionChanged() ), SLOT( onSelectionChanged() ) );
93 QGridLayout* aMainLayout = new QGridLayout( this );
94 aMainLayout->setMargin( 11 );
95 aMainLayout->setSpacing( 6 );
97 // Definition of data source
98 myDataSourceGroupBox = new QGroupBox( this );
99 aMainLayout->addWidget( myDataSourceGroupBox, 0, 0 );
100 myDataSourceGroupBox->setTitle( tr( "PRS_DATA_SOUIRCE" ) );
102 QGroupBox* aGroupBox = myDataSourceGroupBox;
103 //aGroupBox->setColumnLayout(0, Qt::Vertical );
104 //aGroupBox->layout()->setSpacing( 6 );
105 //aGroupBox->layout()->setMargin( 11 );
107 QGridLayout* aGroupBoxLayout = new QGridLayout( aGroupBox );
108 aGroupBoxLayout->setAlignment( Qt::AlignTop );
110 QLabel* aLabel = new QLabel( tr( "MED_FILE" ), aGroupBox );
111 aGroupBoxLayout->addWidget( aLabel, 0, 0 );
113 myMedFile = new QLineEdit( aGroupBox );
114 myMedFile->setReadOnly( true );
115 myMedFile->setEnabled( false );
116 QPalette aPal = myMedFile->palette();
117 aPal.setColor( myMedFile->backgroundRole(), Qt::black );
118 myMedFile->setPalette( aPal );
119 //myMedFile->setPaletteForegroundColor( Qt::black );
120 aGroupBoxLayout->addWidget( myMedFile, 0, 1 );
123 QLabel* aLabel = new QLabel( tr( "MESH" ), aGroupBox );
124 aGroupBoxLayout->addWidget( aLabel, 1, 0 );
126 myMeshName = new QLineEdit( aGroupBox );
127 myMeshName->setReadOnly( true );
128 myMeshName->setEnabled( false );
129 QPalette aPal = myMeshName->palette();
130 aPal.setColor( myMeshName->backgroundRole(), Qt::black );
131 myMeshName->setPalette( aPal );
132 //myMeshName->setPaletteForegroundColor( Qt::black );
133 aGroupBoxLayout->addWidget( myMeshName, 1, 1 );
136 QLabel* aLabel = new QLabel( tr( "ENTITY" ), aGroupBox );
137 aGroupBoxLayout->addWidget( aLabel, 2, 0 );
139 myEntityName = new QLineEdit( aGroupBox );
140 myEntityName->setReadOnly( true );
141 myEntityName->setEnabled( false );
142 QPalette aPal = myEntityName->palette();
143 aPal.setColor( myEntityName->backgroundRole(), Qt::black );
144 myEntityName->setPalette( aPal );
145 //myEntityName->setPaletteForegroundColor( Qt::black );
146 aGroupBoxLayout->addWidget( myEntityName, 2, 1 );
149 QLabel* aLabel = new QLabel( tr( "FIELD" ), aGroupBox );
150 aGroupBoxLayout->addWidget( aLabel, 3, 0 );
152 myFieldName = new QLineEdit( aGroupBox );
153 myFieldName->setReadOnly( true );
154 aGroupBoxLayout->addWidget( myFieldName, 3, 1 );
157 QLabel* aLabel = new QLabel( tr( "TIME_STAMP" ), aGroupBox );
158 aGroupBoxLayout->addWidget( aLabel, 4, 0 );
160 myTimeStamps = new QComboBox( aGroupBox );
161 aGroupBoxLayout->addWidget( myTimeStamps, 4, 1 );
164 myReInit = new QCheckBox( tr( "REINITIALIZE" ), aGroupBox );
165 myReInit->setChecked( true );
166 aGroupBoxLayout->addWidget( myReInit, 5, 1 );
169 // Definition of used groups
170 myUseGroupsGroupBox = new QGroupBox( this );
171 aMainLayout->addWidget( myUseGroupsGroupBox, 1, 0 );
172 myUseGroupsGroupBox->setTitle( tr( "PRS_ON_GROUPS" ) );
173 myUseGroupsGroupBox->setCheckable( TRUE );
175 QGroupBox* aGroupBox = myUseGroupsGroupBox;
176 //aGroupBox->setColumnLayout(0, Qt::Vertical );
177 //aGroupBox->layout()->setSpacing( 6 );
178 //aGroupBox->layout()->setMargin( 11 );
180 QGridLayout* aGroupBoxLayout = new QGridLayout( aGroupBox );
181 aGroupBoxLayout->setAlignment( Qt::AlignTop );
183 myAllGroups = new VisuGUI_ListWidget(aGroupBox);
184 myAllGroups->setSelectionMode(QAbstractItemView::ExtendedSelection);
185 aGroupBoxLayout->addWidget( myAllGroups, 0, 0, 4, 1 );
188 mySelectedGroups = new VisuGUI_ListWidget(aGroupBox );
189 mySelectedGroups->setSelectionMode(QAbstractItemView::ExtendedSelection);
190 mySelectedGroups->installEventFilter(this);
191 aGroupBoxLayout->addWidget( mySelectedGroups, 0, 2, 4, 1 );
194 myAddButton = new QToolButton(aGroupBox);
195 myAddButton->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr("ICON_ADD")) );
196 aGroupBoxLayout->addWidget( myAddButton, 1, 1 );
199 myRemoveButton = new QToolButton(aGroupBox);
200 myRemoveButton->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr("ICON_REMOVE")) );
201 aGroupBoxLayout->addWidget( myRemoveButton, 2, 1 );
204 QSpacerItem* aSpacer = new QSpacerItem( 20, 51, QSizePolicy::Minimum, QSizePolicy::Expanding );
205 aGroupBoxLayout->addItem( aSpacer, 0, 1 );
208 QSpacerItem* aSpacer = new QSpacerItem( 20, 61, QSizePolicy::Minimum, QSizePolicy::Expanding );
209 aGroupBoxLayout->addItem( aSpacer, 3, 1 );
213 connect( myTimeStamps, SIGNAL( activated( int ) ), this, SLOT( changeTimeStamp( int ) ) );
214 connect( myReInit, SIGNAL( toggled( bool ) ), SLOT( onReInitialize( bool ) ) );
216 connect( myUseGroupsGroupBox, SIGNAL( toggled( bool ) ), this, SLOT( onTypeChanged() ) );
217 connect( myAllGroups, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ), this, SLOT( onListDoubleClicked( QListWidgetItem* ) ) );
218 connect( mySelectedGroups, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ), this, SLOT( onListDoubleClicked( QListWidgetItem* ) ) );
219 connect( myAddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
220 connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
222 // Save current selection (to be restored in destructor)
223 aSelectionMgr->selectedObjects(mySavedSelection);
226 onSelectionChanged();
228 myFieldFilter = new VisuGUI_FieldFilter( theType );
234 //---------------------------------------------------------------
235 VisuGUI_InputPane::~VisuGUI_InputPane()
237 if ( myModule->getApp() ) {
238 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule);
242 aSelectionMgr->removeFilter(myFieldFilter);
243 delete myFieldFilter;
246 // Restore initial selection
247 if(isRestoreInitialSelection)
248 aSelectionMgr->setSelectedObjects(mySavedSelection);
252 void VisuGUI_InputPane::SetRestoreInitialSelection(bool on){
253 isRestoreInitialSelection = on;
256 bool VisuGUI_InputPane::GetRestoreInitialSelection(){
257 return isRestoreInitialSelection;
260 //---------------------------------------------------------------
264 bool VisuGUI_InputPane::eventFilter (QObject* object, QEvent* event)
266 if (event->type() == QEvent::KeyPress) {
267 QKeyEvent* aKeyEvent = (QKeyEvent*)event;
268 if (object == mySelectedGroups && aKeyEvent->key() == Qt::Key_Delete)
271 return QObject::eventFilter(object, event);
275 //---------------------------------------------------------------
277 Called when the checkbox is toggled
279 void VisuGUI_InputPane::onTypeChanged( )
281 bool toEnable = myUseGroupsGroupBox->isChecked();
284 myAllGroups->clearSelection();
285 mySelectedGroups->clearSelection();
287 myAllGroups->setEnabled( toEnable );
288 mySelectedGroups->setEnabled( toEnable );
289 myAddButton->setEnabled( toEnable );
290 myRemoveButton->setEnabled( toEnable );
294 //---------------------------------------------------------------
296 Called when add button is clicked, adds item to choosen groups
298 void VisuGUI_InputPane::onAdd()
302 //for (int i = 0; i < myAllGroups->count(); i++)
303 // if (myAllGroups->isSelected(i))
304 // aList.append(myAllGroups->text(i));
305 QList<QListWidgetItem*> aItemList = myAllGroups->selectedItems();
306 QList<QListWidgetItem*>::Iterator it = aItemList.begin();
307 for ( ; it != aItemList.end(); it++ )
308 aList.append( (*it)->text() );
310 for (int i = 0; i < mySelectedGroups->count(); i++)
311 aList.removeAll(mySelectedGroups->item(i)->text());
313 mySelectedGroups->insertItems( mySelectedGroups->count(), aList);
317 //---------------------------------------------------------------
319 Called when remove button is clicked, remove selected items from choosen
321 void VisuGUI_InputPane::onRemove()
323 QList<QListWidgetItem*> aList = mySelectedGroups->selectedItems();
325 //aList.setAutoDelete(false);
326 //for (int i = 0; i < mySelectedGroups->count(); i++)
327 // if (mySelectedGroups->isSelected(i))
328 // aList.append(mySelectedGroups->item(i));
330 for (int i = 0; i < aList.count(); i++)
335 //---------------------------------------------------------------
337 Called when an item of listbox is double-clicked
339 void VisuGUI_InputPane::onListDoubleClicked( QListWidgetItem* theItem )
341 QListWidget* aListWidget = theItem->listWidget();
343 if (aListWidget == myAllGroups)
345 QList<QListWidgetItem*> aList = mySelectedGroups->findItems( theItem->text(), Qt::MatchExactly );
346 if ( aList.isEmpty() )
347 mySelectedGroups->insertItem( mySelectedGroups->count(), theItem->text() );
349 else if (aListWidget == mySelectedGroups)
354 //---------------------------------------------------------------
355 bool VisuGUI_InputPane::check()
357 return myTimeStamps->count() != 0;
361 //---------------------------------------------------------------
362 void VisuGUI_InputPane::clear()
366 myEntityName->clear();
367 myFieldName->clear();
368 myTimeStamps->clear();
372 //---------------------------------------------------------------
373 void VisuGUI_InputPane::onSelectionChanged()
377 SALOME_ListIO aListIO;
378 VISU::GetSelectionMgr( myModule )->selectedObjects(aListIO);
380 if (aListIO.Extent() != 1)
383 const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
385 _PTR(Study) aCStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
386 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
390 VISU::VISUType aType = VISU::Storable::SObject2Type(aSObject);
391 if (aType == VISU::TFIELD)
393 _PTR(SObject) aMedObject = aSObject->GetFather()->GetFather()->GetFather();
397 myTimeStamps->clear();
399 QString anEntityName, aTimeStampName;
401 _PTR(StudyBuilder) aBuilder = aCStudy->NewBuilder();
402 _PTR(ChildIterator) aIter = aCStudy->NewChildIterator(aSObject);
403 for( ; aIter->More(); aIter->Next() )
405 _PTR(SObject) aChildObj = aIter->Value();
409 if( anEntityName.isNull() )
411 _PTR(SObject) aRefObj;
412 if( aChildObj->ReferencedObject( aRefObj ) )
413 anEntityName = aRefObj->GetName().c_str();
416 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aChildObj);
417 if( aRestoringMap["myComment"] == "TIMESTAMP" )
419 aTimeStampName = aChildObj->GetName().c_str();
420 myTimeStamps->addItem( aTimeStampName );
424 myResult = VISU::FindResult( VISU::GetSObject( aSObject ).in() );
426 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aSObject);
427 myEntity = aRestoringMap["myEntityId"].toInt();
429 QString aMedFile = aMedObject->GetName().c_str();
430 QString aMeshName = aRestoringMap["myMeshName"];
431 QString aFieldName = aRestoringMap["myName"];
433 myMedFile->setText( aMedFile );
434 myMeshName->setText( aMeshName );
435 myEntityName->setText( anEntityName );
436 myFieldName->setText( aFieldName );
437 myTimeStamps->setCurrentIndex( 0 );
439 if( myReInit->isChecked() && myPrs )
441 QApplication::setOverrideCursor(Qt::WaitCursor);
443 myPrs->SetResultObject( myResult );
444 myPrs->SetMeshName( aMeshName.toLatin1().data() );
445 myPrs->SetEntity( VISU::Entity( myEntity ) );
446 myPrs->SetFieldName( aFieldName.toLatin1().data() );
447 myPrs->SetTimeStampNumber( myPrs->GetTimeStampNumberByIndex( 0 ) );
448 myPrs->Apply( true );
450 myDialog->initFromPrsObject( myPrs, false );
452 QApplication::restoreOverrideCursor();
458 //---------------------------------------------------------------
459 void VisuGUI_InputPane::changeTimeStamp( int theTimeStamp )
461 QApplication::setOverrideCursor(Qt::WaitCursor);
463 myPrs->SetTimeStampNumber( myPrs->GetTimeStampNumberByIndex( theTimeStamp ) );
464 myPrs->Apply( true );
465 myDialog->initFromPrsObject( myPrs, false );
467 QApplication::restoreOverrideCursor();
471 //---------------------------------------------------------------
472 void VisuGUI_InputPane::onReInitialize( bool on )
475 onSelectionChanged();
479 //---------------------------------------------------------------
480 void VisuGUI_InputPane::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs )
482 if( myPrs == thePrs )
489 CORBA::Long aTimeStampNumber = thePrs->GetTimeStampNumber();
490 VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = thePrs->GetTimeStampsRange();
491 CORBA::Long aLength = aTimeStampsRange->length();
493 for( int index = 0; index < aLength; index++ )
495 VISU::ColoredPrs3dHolder::TimeStampInfo anInfo = aTimeStampsRange[ index ];
496 QString aTime = anInfo.myTime.in();
497 myTimeStamps->addItem( aTime );
500 myResult = thePrs->GetResultObject();
501 VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>(GetServant(myResult).in());
502 myMedFile->setText( aResult->GetName().c_str() );
504 myEntity = (int)thePrs->GetEntity();
506 QString anEntityName;
509 case VISU::NODE_ENTITY:
510 anEntityName = "onNodes";
512 case VISU::EDGE_ENTITY:
513 anEntityName = "onEdges";
515 case VISU::FACE_ENTITY:
516 anEntityName = "onFaces";
518 case VISU::CELL_ENTITY:
519 anEntityName = "onCells";
523 myEntityName->setText( anEntityName );
525 myMeshName->setText( thePrs->GetMeshName() );
526 myFieldName->setText( thePrs->GetFieldName() );
527 myTimeStamps->setCurrentIndex( thePrs->GetTimeStampIndexByNumber( aTimeStampNumber ) );
529 myFieldFilter->setPrs3dEntry( thePrs->GetHolderEntry().c_str() );
530 bool anIsTimeStampFixed = myPrs->IsTimeStampFixed();
531 myDataSourceGroupBox->setEnabled(!anIsTimeStampFixed);
532 if(!anIsTimeStampFixed)
533 VISU::GetSelectionMgr( myModule )->installFilter( myFieldFilter );
535 // type of presentation and groups
536 VISU::Result_i::PInput anInput = aResult->GetInput();
537 const VISU::TMeshMap& aMeshMap = anInput->GetMeshMap();
538 std::string aMeshName = thePrs->GetCMeshName();
539 VISU::TMeshMap::const_iterator aMeshIter = aMeshMap.find(aMeshName);
540 if(aMeshIter != aMeshMap.end()){
541 const VISU::PMesh& aMesh = aMeshIter->second;
542 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
543 VISU::TGroupMap::const_iterator aGroupIter = aGroupMap.begin();
544 for(; aGroupIter != aGroupMap.end(); aGroupIter++){
545 const std::string& aGroupName = aGroupIter->first;
546 myAllGroups->insertItem( myAllGroups->count(), aGroupName.c_str());
550 if(myAllGroups->count() < 1){
551 myAllGroups->insertItem( myAllGroups->count(), tr("NO_GROUPS") );
552 myUseGroupsGroupBox->setEnabled(false);
554 const VISU::ColoredPrs3d_i::TGroupNames& aGroupNames = thePrs->GetGroupNames();
555 VISU::ColoredPrs3d_i::TGroupNames::const_iterator anIter = aGroupNames.begin();
556 for(; anIter != aGroupNames.end(); anIter++){
557 const std::string aGroupName = *anIter;
558 mySelectedGroups->insertItem(mySelectedGroups->count(), aGroupName.c_str());
560 myUseGroupsGroupBox->setEnabled(true);
562 myUseGroupsGroupBox->setChecked(mySelectedGroups->count() > 0);
566 //---------------------------------------------------------------
567 int VisuGUI_InputPane::storeToPrsObject( VISU::ColoredPrs3d_i* thePrs )
569 if(myUseGroupsGroupBox->isChecked()){
570 thePrs->RemoveAllGeom();
571 for(int i = 0; i < mySelectedGroups->count(); i++)
572 thePrs->AddMeshOnGroup(mySelectedGroups->item(i)->text().toLatin1().data() );
574 thePrs->SetSourceGeometry();
576 thePrs->SetResultObject( myResult );
578 thePrs->SetMeshName( myMeshName->text().toLatin1().data() );
579 thePrs->SetEntity( VISU::Entity( myEntity ) );
580 thePrs->SetFieldName( myFieldName->text().toLatin1().data() );
581 thePrs->SetTimeStampNumber( thePrs->GetTimeStampNumberByIndex( myTimeStamps->currentIndex() ) );
582 return ( int )thePrs->Apply( false );
586 //---------------------------------------------------------------