1 // Copyright (C) 2007-2010 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
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_InputPane.cxx
25 // Author : Oleg UVAROV
28 #include "VisuGUI_InputPane.h"
30 #include "VisuGUI_Prs3dDlg.h"
31 #include "VisuGUI_FieldFilter.h"
32 #include "VisuGUI_Tools.h"
34 #include "VISU_ColoredPrs3d_i.hh"
35 #include "VISU_ScalarMap_i.hh"
36 #include "VISU_Result_i.hh"
37 #include "VISU_Convertor.hxx"
39 #include "SUIT_ResourceMgr.h"
41 #include "SalomeApp_Module.h"
43 #include "LightApp_Application.h"
44 #include "LightApp_SelectionMgr.h"
46 #include "SALOME_ListIO.hxx"
48 #include "SALOMEDSClient_AttributeString.hxx"
49 #include "SALOMEDSClient_AttributeName.hxx"
51 //#include "QtxListBox.h"
55 #include <QToolButton>
60 #include <QListWidget>
63 //---------------------------------------------------------------
64 class VisuGUI_ListWidget: public QListWidget
67 VisuGUI_ListWidget( QWidget * parent = 0 ):
71 virtual QSize sizeHint() const
73 return minimumSizeHint(); }
78 //---------------------------------------------------------------
79 VisuGUI_InputPane::VisuGUI_InputPane( VISU::VISUType theType,
80 SalomeApp_Module* theModule,
81 VisuGUI_Prs3dDlg* theDialog ) :
82 QGroupBox( theDialog ),
83 myModule( theModule ),
84 myDialog( theDialog ),
86 isRestoreInitialSelection(true)
88 //setFrameStyle( QFrame::NoFrame );
90 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(theModule);
92 connect( aSelectionMgr, SIGNAL( selectionChanged() ), SLOT( onSelectionChanged() ) );
94 QGridLayout* aMainLayout = new QGridLayout( this );
95 aMainLayout->setMargin( 11 );
96 aMainLayout->setSpacing( 6 );
98 // Definition of data source
99 myDataSourceGroupBox = new QGroupBox( this );
100 aMainLayout->addWidget( myDataSourceGroupBox, 0, 0 );
101 myDataSourceGroupBox->setTitle( tr( "PRS_DATA_SOUIRCE" ) );
103 QGroupBox* aGroupBox = myDataSourceGroupBox;
104 //aGroupBox->setColumnLayout(0, Qt::Vertical );
105 //aGroupBox->layout()->setSpacing( 6 );
106 //aGroupBox->layout()->setMargin( 11 );
108 QGridLayout* aGroupBoxLayout = new QGridLayout( aGroupBox );
109 aGroupBoxLayout->setAlignment( Qt::AlignTop );
111 QLabel* aLabel = new QLabel( tr( "MED_FILE" ), aGroupBox );
112 aGroupBoxLayout->addWidget( aLabel, 0, 0 );
114 myMedFile = new QLineEdit( aGroupBox );
115 myMedFile->setReadOnly( true );
116 myMedFile->setEnabled( false );
117 QPalette aPal = myMedFile->palette();
118 aPal.setColor( myMedFile->backgroundRole(), Qt::black );
119 myMedFile->setPalette( aPal );
120 //myMedFile->setPaletteForegroundColor( Qt::black );
121 aGroupBoxLayout->addWidget( myMedFile, 0, 1 );
124 QLabel* aLabel = new QLabel( tr( "MESH" ), aGroupBox );
125 aGroupBoxLayout->addWidget( aLabel, 1, 0 );
127 myMeshName = new QLineEdit( aGroupBox );
128 myMeshName->setReadOnly( true );
129 myMeshName->setEnabled( false );
130 QPalette aPal = myMeshName->palette();
131 aPal.setColor( myMeshName->backgroundRole(), Qt::black );
132 myMeshName->setPalette( aPal );
133 //myMeshName->setPaletteForegroundColor( Qt::black );
134 aGroupBoxLayout->addWidget( myMeshName, 1, 1 );
137 QLabel* aLabel = new QLabel( tr( "ENTITY" ), aGroupBox );
138 aGroupBoxLayout->addWidget( aLabel, 2, 0 );
140 myEntityName = new QLineEdit( aGroupBox );
141 myEntityName->setReadOnly( true );
142 myEntityName->setEnabled( false );
143 QPalette aPal = myEntityName->palette();
144 aPal.setColor( myEntityName->backgroundRole(), Qt::black );
145 myEntityName->setPalette( aPal );
146 //myEntityName->setPaletteForegroundColor( Qt::black );
147 aGroupBoxLayout->addWidget( myEntityName, 2, 1 );
150 QLabel* aLabel = new QLabel( tr( "FIELD" ), aGroupBox );
151 aGroupBoxLayout->addWidget( aLabel, 3, 0 );
153 myFieldName = new QLineEdit( aGroupBox );
154 myFieldName->setReadOnly( true );
155 aGroupBoxLayout->addWidget( myFieldName, 3, 1 );
158 QLabel* aLabel = new QLabel( tr( "TIME_STAMP" ), aGroupBox );
159 aGroupBoxLayout->addWidget( aLabel, 4, 0 );
161 myTimeStamps = new QComboBox( aGroupBox );
162 aGroupBoxLayout->addWidget( myTimeStamps, 4, 1 );
165 myReInit = new QCheckBox( tr( "REINITIALIZE" ), aGroupBox );
166 myReInit->setChecked( true );
167 aGroupBoxLayout->addWidget( myReInit, 5, 1 );
170 // Definition of used groups
171 myUseGroupsGroupBox = new QGroupBox( this );
172 aMainLayout->addWidget( myUseGroupsGroupBox, 1, 0 );
173 myUseGroupsGroupBox->setTitle( tr( "PRS_ON_GROUPS" ) );
174 myUseGroupsGroupBox->setCheckable( TRUE );
176 QGroupBox* aGroupBox = myUseGroupsGroupBox;
177 //aGroupBox->setColumnLayout(0, Qt::Vertical );
178 //aGroupBox->layout()->setSpacing( 6 );
179 //aGroupBox->layout()->setMargin( 11 );
181 QGridLayout* aGroupBoxLayout = new QGridLayout( aGroupBox );
182 aGroupBoxLayout->setAlignment( Qt::AlignTop );
184 myAllGroups = new VisuGUI_ListWidget(aGroupBox);
185 myAllGroups->setSelectionMode(QAbstractItemView::ExtendedSelection);
186 aGroupBoxLayout->addWidget( myAllGroups, 0, 0, 4, 1 );
189 mySelectedGroups = new VisuGUI_ListWidget(aGroupBox );
190 mySelectedGroups->setSelectionMode(QAbstractItemView::ExtendedSelection);
191 mySelectedGroups->installEventFilter(this);
192 aGroupBoxLayout->addWidget( mySelectedGroups, 0, 2, 4, 1 );
195 myAddButton = new QToolButton(aGroupBox);
196 myAddButton->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr("ICON_ADD")) );
197 aGroupBoxLayout->addWidget( myAddButton, 1, 1 );
200 myRemoveButton = new QToolButton(aGroupBox);
201 myRemoveButton->setIcon( VISU::GetResourceMgr()->loadPixmap("VISU", tr("ICON_REMOVE")) );
202 aGroupBoxLayout->addWidget( myRemoveButton, 2, 1 );
205 QSpacerItem* aSpacer = new QSpacerItem( 20, 51, QSizePolicy::Minimum, QSizePolicy::Expanding );
206 aGroupBoxLayout->addItem( aSpacer, 0, 1 );
209 QSpacerItem* aSpacer = new QSpacerItem( 20, 61, QSizePolicy::Minimum, QSizePolicy::Expanding );
210 aGroupBoxLayout->addItem( aSpacer, 3, 1 );
214 connect( myTimeStamps, SIGNAL( activated( int ) ), this, SLOT( changeTimeStamp( int ) ) );
215 connect( myReInit, SIGNAL( toggled( bool ) ), SLOT( onReInitialize( bool ) ) );
217 connect( myUseGroupsGroupBox, SIGNAL( toggled( bool ) ), this, SLOT( onTypeChanged() ) );
218 connect( myAllGroups, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ), this, SLOT( onListDoubleClicked( QListWidgetItem* ) ) );
219 connect( mySelectedGroups, SIGNAL( itemDoubleClicked( QListWidgetItem* ) ), this, SLOT( onListDoubleClicked( QListWidgetItem* ) ) );
220 connect( myAddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
221 connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
223 // Save current selection (to be restored in destructor)
224 aSelectionMgr->selectedObjects(mySavedSelection);
227 onSelectionChanged();
229 myFieldFilter = new VisuGUI_FieldFilter( theType );
235 //---------------------------------------------------------------
236 VisuGUI_InputPane::~VisuGUI_InputPane()
238 if ( myModule->getApp() ) {
239 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule);
243 aSelectionMgr->removeFilter(myFieldFilter);
244 delete myFieldFilter;
247 // Restore initial selection
248 if(isRestoreInitialSelection)
249 aSelectionMgr->setSelectedObjects(mySavedSelection);
253 void VisuGUI_InputPane::SetRestoreInitialSelection(bool on){
254 isRestoreInitialSelection = on;
257 bool VisuGUI_InputPane::GetRestoreInitialSelection(){
258 return isRestoreInitialSelection;
261 //---------------------------------------------------------------
265 bool VisuGUI_InputPane::eventFilter (QObject* object, QEvent* event)
267 if (event->type() == QEvent::KeyPress) {
268 QKeyEvent* aKeyEvent = (QKeyEvent*)event;
269 if (object == mySelectedGroups && aKeyEvent->key() == Qt::Key_Delete)
272 return QObject::eventFilter(object, event);
276 //---------------------------------------------------------------
278 Called when the checkbox is toggled
280 void VisuGUI_InputPane::onTypeChanged( )
282 bool toEnable = myUseGroupsGroupBox->isChecked();
285 myAllGroups->clearSelection();
286 mySelectedGroups->clearSelection();
288 myAllGroups->setEnabled( toEnable );
289 mySelectedGroups->setEnabled( toEnable );
290 myAddButton->setEnabled( toEnable );
291 myRemoveButton->setEnabled( toEnable );
295 //---------------------------------------------------------------
297 Called when add button is clicked, adds item to choosen groups
299 void VisuGUI_InputPane::onAdd()
303 //for (int i = 0; i < myAllGroups->count(); i++)
304 // if (myAllGroups->isSelected(i))
305 // aList.append(myAllGroups->text(i));
306 QList<QListWidgetItem*> aItemList = myAllGroups->selectedItems();
307 QList<QListWidgetItem*>::Iterator it = aItemList.begin();
308 for ( ; it != aItemList.end(); it++ )
309 aList.append( (*it)->text() );
311 for (int i = 0; i < mySelectedGroups->count(); i++)
312 aList.removeAll(mySelectedGroups->item(i)->text());
314 mySelectedGroups->insertItems( mySelectedGroups->count(), aList);
318 //---------------------------------------------------------------
320 Called when remove button is clicked, remove selected items from choosen
322 void VisuGUI_InputPane::onRemove()
324 QList<QListWidgetItem*> aList = mySelectedGroups->selectedItems();
326 //aList.setAutoDelete(false);
327 //for (int i = 0; i < mySelectedGroups->count(); i++)
328 // if (mySelectedGroups->isSelected(i))
329 // aList.append(mySelectedGroups->item(i));
331 for (int i = 0; i < aList.count(); i++)
336 //---------------------------------------------------------------
338 Called when an item of listbox is double-clicked
340 void VisuGUI_InputPane::onListDoubleClicked( QListWidgetItem* theItem )
342 QListWidget* aListWidget = theItem->listWidget();
344 if (aListWidget == myAllGroups)
346 QList<QListWidgetItem*> aList = mySelectedGroups->findItems( theItem->text(), Qt::MatchExactly );
347 if ( aList.isEmpty() )
348 mySelectedGroups->insertItem( mySelectedGroups->count(), theItem->text() );
350 else if (aListWidget == mySelectedGroups)
355 //---------------------------------------------------------------
356 bool VisuGUI_InputPane::check()
358 return myTimeStamps->count() != 0;
362 //---------------------------------------------------------------
363 void VisuGUI_InputPane::clear()
367 myEntityName->clear();
368 myFieldName->clear();
369 myTimeStamps->clear();
373 //---------------------------------------------------------------
374 void VisuGUI_InputPane::onSelectionChanged()
378 SALOME_ListIO aListIO;
379 VISU::GetSelectionMgr( myModule )->selectedObjects(aListIO);
381 if (aListIO.Extent() != 1)
384 const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
386 _PTR(Study) aCStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
387 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
391 VISU::VISUType aType = VISU::Storable::SObject2Type(aSObject);
392 if (aType == VISU::TFIELD)
394 _PTR(SObject) aMedObject = aSObject->GetFather()->GetFather()->GetFather();
398 myTimeStamps->clear();
400 QString anEntityName, aTimeStampName;
402 _PTR(StudyBuilder) aBuilder = aCStudy->NewBuilder();
403 _PTR(ChildIterator) aIter = aCStudy->NewChildIterator(aSObject);
404 for( ; aIter->More(); aIter->Next() )
406 _PTR(SObject) aChildObj = aIter->Value();
410 if( anEntityName.isNull() )
412 _PTR(SObject) aRefObj;
413 if( aChildObj->ReferencedObject( aRefObj ) )
414 anEntityName = aRefObj->GetName().c_str();
417 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aChildObj);
418 if( aRestoringMap["myComment"] == "TIMESTAMP" )
420 aTimeStampName = aChildObj->GetName().c_str();
421 myTimeStamps->addItem( aTimeStampName );
425 myResult = VISU::FindResult( VISU::GetSObject( aSObject ).in() );
427 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aSObject);
428 myEntity = aRestoringMap["myEntityId"].toInt();
430 QString aMedFile = aMedObject->GetName().c_str();
431 QString aMeshName = aRestoringMap["myMeshName"];
432 QString aFieldName = aRestoringMap["myName"];
434 myMedFile->setText( aMedFile );
435 myMeshName->setText( aMeshName );
436 myEntityName->setText( anEntityName );
437 myFieldName->setText( aFieldName );
438 myTimeStamps->setCurrentIndex( 0 );
440 if( myReInit->isChecked() && myPrs )
442 QApplication::setOverrideCursor(Qt::WaitCursor);
444 myPrs->SetResultObject( myResult );
445 myPrs->SetMeshName( aMeshName.toLatin1().data() );
446 myPrs->SetEntity( VISU::Entity( myEntity ) );
447 myPrs->SetFieldName( aFieldName.toLatin1().data() );
448 myPrs->SetTimeStampNumber( myPrs->GetTimeStampNumberByIndex( 0 ) );
449 myPrs->Apply( true );
451 myDialog->initFromPrsObject( myPrs, false );
453 QApplication::restoreOverrideCursor();
459 //---------------------------------------------------------------
460 void VisuGUI_InputPane::changeTimeStamp( int theTimeStamp )
462 QApplication::setOverrideCursor(Qt::WaitCursor);
464 myPrs->SetTimeStampNumber( myPrs->GetTimeStampNumberByIndex( theTimeStamp ) );
465 myPrs->Apply( true );
466 myDialog->initFromPrsObject( myPrs, false );
468 QApplication::restoreOverrideCursor();
472 //---------------------------------------------------------------
473 void VisuGUI_InputPane::onReInitialize( bool on )
476 onSelectionChanged();
480 //---------------------------------------------------------------
481 void VisuGUI_InputPane::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs )
483 if( myPrs == thePrs )
490 CORBA::Long aTimeStampNumber = thePrs->GetTimeStampNumber();
491 VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = thePrs->GetTimeStampsRange();
492 CORBA::Long aLength = aTimeStampsRange->length();
494 for( int index = 0; index < aLength; index++ )
496 VISU::ColoredPrs3dHolder::TimeStampInfo anInfo = aTimeStampsRange[ index ];
497 QString aTime = anInfo.myTime.in();
498 myTimeStamps->addItem( aTime );
501 myResult = thePrs->GetResultObject();
502 VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>(GetServant(myResult).in());
503 myMedFile->setText( aResult->GetName().c_str() );
505 myEntity = (int)thePrs->GetEntity();
507 QString anEntityName;
510 case VISU::NODE_ENTITY:
511 anEntityName = "onNodes";
513 case VISU::EDGE_ENTITY:
514 anEntityName = "onEdges";
516 case VISU::FACE_ENTITY:
517 anEntityName = "onFaces";
519 case VISU::CELL_ENTITY:
520 anEntityName = "onCells";
524 myEntityName->setText( anEntityName );
526 myMeshName->setText( thePrs->GetMeshName() );
527 myFieldName->setText( thePrs->GetFieldName() );
528 myTimeStamps->setCurrentIndex( thePrs->GetTimeStampIndexByNumber( aTimeStampNumber ) );
530 myFieldFilter->setPrs3dEntry( thePrs->GetHolderEntry().c_str() );
531 bool anIsTimeStampFixed = myPrs->IsTimeStampFixed();
532 myDataSourceGroupBox->setEnabled(!anIsTimeStampFixed);
533 if(!anIsTimeStampFixed)
534 VISU::GetSelectionMgr( myModule )->installFilter( myFieldFilter );
536 // type of presentation and groups
537 VISU::Result_i::PInput anInput = aResult->GetInput();
538 const VISU::TMeshMap& aMeshMap = anInput->GetMeshMap();
539 std::string aMeshName = thePrs->GetCMeshName();
540 VISU::TMeshMap::const_iterator aMeshIter = aMeshMap.find(aMeshName);
541 if(aMeshIter != aMeshMap.end()){
542 const VISU::PMesh& aMesh = aMeshIter->second;
543 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
544 VISU::TGroupMap::const_iterator aGroupIter = aGroupMap.begin();
545 for(; aGroupIter != aGroupMap.end(); aGroupIter++){
546 const std::string& aGroupName = aGroupIter->first;
547 myAllGroups->insertItem( myAllGroups->count(), aGroupName.c_str());
551 if(myAllGroups->count() < 1){
552 myAllGroups->insertItem( myAllGroups->count(), tr("NO_GROUPS") );
553 myUseGroupsGroupBox->setEnabled(false);
555 const VISU::ColoredPrs3d_i::TGroupNames& aGroupNames = thePrs->GetGroupNames();
556 VISU::ColoredPrs3d_i::TGroupNames::const_iterator anIter = aGroupNames.begin();
557 for(; anIter != aGroupNames.end(); anIter++){
558 const std::string aGroupName = *anIter;
559 mySelectedGroups->insertItem(mySelectedGroups->count(), aGroupName.c_str());
561 myUseGroupsGroupBox->setEnabled(true);
563 myUseGroupsGroupBox->setChecked(mySelectedGroups->count() > 0);
567 //---------------------------------------------------------------
568 int VisuGUI_InputPane::storeToPrsObject( VISU::ColoredPrs3d_i* thePrs )
570 if(myUseGroupsGroupBox->isChecked()){
571 thePrs->RemoveAllGeom();
572 for(int i = 0; i < mySelectedGroups->count(); i++)
573 thePrs->AddMeshOnGroup(mySelectedGroups->item(i)->text().toLatin1().data() );
575 thePrs->SetSourceGeometry();
577 thePrs->SetResultObject( myResult );
579 thePrs->SetMeshName( myMeshName->text().toLatin1().data() );
580 thePrs->SetEntity( VISU::Entity( myEntity ) );
581 thePrs->SetFieldName( myFieldName->text().toLatin1().data() );
582 thePrs->SetTimeStampNumber( thePrs->GetTimeStampNumberByIndex( myTimeStamps->currentIndex() ) );
583 return ( int )thePrs->Apply( false );
587 //---------------------------------------------------------------