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 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule);
241 aSelectionMgr->removeFilter(myFieldFilter);
242 delete myFieldFilter;
245 // Restore initial selection
246 if(isRestoreInitialSelection)
247 aSelectionMgr->setSelectedObjects(mySavedSelection);
250 void VisuGUI_InputPane::SetRestoreInitialSelection(bool on){
251 isRestoreInitialSelection = on;
254 bool VisuGUI_InputPane::GetRestoreInitialSelection(){
255 return isRestoreInitialSelection;
258 //---------------------------------------------------------------
262 bool VisuGUI_InputPane::eventFilter (QObject* object, QEvent* event)
264 if (event->type() == QEvent::KeyPress) {
265 QKeyEvent* aKeyEvent = (QKeyEvent*)event;
266 if (object == mySelectedGroups && aKeyEvent->key() == Qt::Key_Delete)
269 return QObject::eventFilter(object, event);
273 //---------------------------------------------------------------
275 Called when the checkbox is toggled
277 void VisuGUI_InputPane::onTypeChanged( )
279 bool toEnable = myUseGroupsGroupBox->isChecked();
282 myAllGroups->clearSelection();
283 mySelectedGroups->clearSelection();
285 myAllGroups->setEnabled( toEnable );
286 mySelectedGroups->setEnabled( toEnable );
287 myAddButton->setEnabled( toEnable );
288 myRemoveButton->setEnabled( toEnable );
292 //---------------------------------------------------------------
294 Called when add button is clicked, adds item to choosen groups
296 void VisuGUI_InputPane::onAdd()
300 //for (int i = 0; i < myAllGroups->count(); i++)
301 // if (myAllGroups->isSelected(i))
302 // aList.append(myAllGroups->text(i));
303 QList<QListWidgetItem*> aItemList = myAllGroups->selectedItems();
304 QList<QListWidgetItem*>::Iterator it = aItemList.begin();
305 for ( ; it != aItemList.end(); it++ )
306 aList.append( (*it)->text() );
308 for (int i = 0; i < mySelectedGroups->count(); i++)
309 aList.removeAll(mySelectedGroups->item(i)->text());
311 mySelectedGroups->insertItems( mySelectedGroups->count(), aList);
315 //---------------------------------------------------------------
317 Called when remove button is clicked, remove selected items from choosen
319 void VisuGUI_InputPane::onRemove()
321 QList<QListWidgetItem*> aList = mySelectedGroups->selectedItems();
323 //aList.setAutoDelete(false);
324 //for (int i = 0; i < mySelectedGroups->count(); i++)
325 // if (mySelectedGroups->isSelected(i))
326 // aList.append(mySelectedGroups->item(i));
328 for (int i = 0; i < aList.count(); i++)
333 //---------------------------------------------------------------
335 Called when an item of listbox is double-clicked
337 void VisuGUI_InputPane::onListDoubleClicked( QListWidgetItem* theItem )
339 QListWidget* aListWidget = theItem->listWidget();
341 if (aListWidget == myAllGroups)
343 QList<QListWidgetItem*> aList = mySelectedGroups->findItems( theItem->text(), Qt::MatchExactly );
344 if ( aList.isEmpty() )
345 mySelectedGroups->insertItem( mySelectedGroups->count(), theItem->text() );
347 else if (aListWidget == mySelectedGroups)
352 //---------------------------------------------------------------
353 bool VisuGUI_InputPane::check()
355 return myTimeStamps->count() != 0;
359 //---------------------------------------------------------------
360 void VisuGUI_InputPane::clear()
364 myEntityName->clear();
365 myFieldName->clear();
366 myTimeStamps->clear();
370 //---------------------------------------------------------------
371 void VisuGUI_InputPane::onSelectionChanged()
375 SALOME_ListIO aListIO;
376 VISU::GetSelectionMgr( myModule )->selectedObjects(aListIO);
378 if (aListIO.Extent() != 1)
381 const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
383 _PTR(Study) aCStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
384 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
388 VISU::VISUType aType = VISU::Storable::SObject2Type(aSObject);
389 if (aType == VISU::TFIELD)
391 _PTR(SObject) aMedObject = aSObject->GetFather()->GetFather()->GetFather();
395 myTimeStamps->clear();
397 QString anEntityName, aTimeStampName;
399 _PTR(StudyBuilder) aBuilder = aCStudy->NewBuilder();
400 _PTR(ChildIterator) aIter = aCStudy->NewChildIterator(aSObject);
401 for( ; aIter->More(); aIter->Next() )
403 _PTR(SObject) aChildObj = aIter->Value();
407 if( anEntityName.isNull() )
409 _PTR(SObject) aRefObj;
410 if( aChildObj->ReferencedObject( aRefObj ) )
411 anEntityName = aRefObj->GetName().c_str();
414 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aChildObj);
415 if( aRestoringMap["myComment"] == "TIMESTAMP" )
417 aTimeStampName = aChildObj->GetName().c_str();
418 myTimeStamps->addItem( aTimeStampName );
422 myResult = VISU::FindResult( VISU::GetSObject( aSObject ).in() );
424 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aSObject);
425 myEntity = aRestoringMap["myEntityId"].toInt();
427 QString aMedFile = aMedObject->GetName().c_str();
428 QString aMeshName = aRestoringMap["myMeshName"];
429 QString aFieldName = aRestoringMap["myName"];
431 myMedFile->setText( aMedFile );
432 myMeshName->setText( aMeshName );
433 myEntityName->setText( anEntityName );
434 myFieldName->setText( aFieldName );
435 myTimeStamps->setCurrentIndex( 0 );
437 if( myReInit->isChecked() && myPrs )
439 QApplication::setOverrideCursor(Qt::WaitCursor);
441 myPrs->SetResultObject( myResult );
442 myPrs->SetMeshName( aMeshName.toLatin1().data() );
443 myPrs->SetEntity( VISU::Entity( myEntity ) );
444 myPrs->SetFieldName( aFieldName.toLatin1().data() );
445 myPrs->SetTimeStampNumber( myPrs->GetTimeStampNumberByIndex( 0 ) );
446 myPrs->Apply( true );
448 myDialog->initFromPrsObject( myPrs, false );
450 QApplication::restoreOverrideCursor();
456 //---------------------------------------------------------------
457 void VisuGUI_InputPane::changeTimeStamp( int theTimeStamp )
459 QApplication::setOverrideCursor(Qt::WaitCursor);
461 myPrs->SetTimeStampNumber( myPrs->GetTimeStampNumberByIndex( theTimeStamp ) );
462 myPrs->Apply( true );
463 myDialog->initFromPrsObject( myPrs, false );
465 QApplication::restoreOverrideCursor();
469 //---------------------------------------------------------------
470 void VisuGUI_InputPane::onReInitialize( bool on )
473 onSelectionChanged();
477 //---------------------------------------------------------------
478 void VisuGUI_InputPane::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs )
480 if( myPrs == thePrs )
487 CORBA::Long aTimeStampNumber = thePrs->GetTimeStampNumber();
488 VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = thePrs->GetTimeStampsRange();
489 CORBA::Long aLength = aTimeStampsRange->length();
491 for( int index = 0; index < aLength; index++ )
493 VISU::ColoredPrs3dHolder::TimeStampInfo anInfo = aTimeStampsRange[ index ];
494 QString aTime = anInfo.myTime.in();
495 myTimeStamps->addItem( aTime );
498 myResult = thePrs->GetResultObject();
499 VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>(GetServant(myResult).in());
500 myMedFile->setText( aResult->GetName().c_str() );
502 myEntity = (int)thePrs->GetEntity();
504 QString anEntityName;
507 case VISU::NODE_ENTITY:
508 anEntityName = "onNodes";
510 case VISU::EDGE_ENTITY:
511 anEntityName = "onEdges";
513 case VISU::FACE_ENTITY:
514 anEntityName = "onFaces";
516 case VISU::CELL_ENTITY:
517 anEntityName = "onCells";
521 myEntityName->setText( anEntityName );
523 myMeshName->setText( thePrs->GetMeshName() );
524 myFieldName->setText( thePrs->GetFieldName() );
525 myTimeStamps->setCurrentIndex( thePrs->GetTimeStampIndexByNumber( aTimeStampNumber ) );
527 myFieldFilter->setPrs3dEntry( thePrs->GetHolderEntry().c_str() );
528 bool anIsTimeStampFixed = myPrs->IsTimeStampFixed();
529 myDataSourceGroupBox->setEnabled(!anIsTimeStampFixed);
530 if(!anIsTimeStampFixed)
531 VISU::GetSelectionMgr( myModule )->installFilter( myFieldFilter );
533 // type of presentation and groups
534 VISU::Result_i::PInput anInput = aResult->GetInput();
535 const VISU::TMeshMap& aMeshMap = anInput->GetMeshMap();
536 std::string aMeshName = thePrs->GetCMeshName();
537 VISU::TMeshMap::const_iterator aMeshIter = aMeshMap.find(aMeshName);
538 if(aMeshIter != aMeshMap.end()){
539 const VISU::PMesh& aMesh = aMeshIter->second;
540 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
541 VISU::TGroupMap::const_iterator aGroupIter = aGroupMap.begin();
542 for(; aGroupIter != aGroupMap.end(); aGroupIter++){
543 const std::string& aGroupName = aGroupIter->first;
544 myAllGroups->insertItem( myAllGroups->count(), aGroupName.c_str());
548 if(myAllGroups->count() < 1){
549 myAllGroups->insertItem( myAllGroups->count(), tr("NO_GROUPS") );
550 myUseGroupsGroupBox->setEnabled(false);
552 const VISU::ColoredPrs3d_i::TGroupNames& aGroupNames = thePrs->GetGroupNames();
553 VISU::ColoredPrs3d_i::TGroupNames::const_iterator anIter = aGroupNames.begin();
554 for(; anIter != aGroupNames.end(); anIter++){
555 const std::string aGroupName = *anIter;
556 mySelectedGroups->insertItem(mySelectedGroups->count(), aGroupName.c_str());
559 myUseGroupsGroupBox->setChecked(mySelectedGroups->count() > 0);
560 myUseGroupsGroupBox->setEnabled(anIsTimeStampFixed);
564 //---------------------------------------------------------------
565 int VisuGUI_InputPane::storeToPrsObject( VISU::ColoredPrs3d_i* thePrs )
567 if(myUseGroupsGroupBox->isChecked()){
568 thePrs->RemoveAllGeom();
569 for(int i = 0; i < mySelectedGroups->count(); i++)
570 thePrs->AddMeshOnGroup(mySelectedGroups->item(i)->text().toLatin1().data() );
572 thePrs->SetSourceGeometry();
574 thePrs->SetResultObject( myResult );
576 thePrs->SetMeshName( myMeshName->text().toLatin1().data() );
577 thePrs->SetEntity( VISU::Entity( myEntity ) );
578 thePrs->SetFieldName( myFieldName->text().toLatin1().data() );
579 thePrs->SetTimeStampNumber( thePrs->GetTimeStampNumberByIndex( myTimeStamps->currentIndex() ) );
580 return ( int )thePrs->Apply( false );
584 //---------------------------------------------------------------