1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 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
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"
53 #include <qcheckbox.h>
54 #include <qcombobox.h>
55 #include <qtoolbutton.h>
58 #include <qlineedit.h>
61 //---------------------------------------------------------------
62 class VisuGUI_ListBox: public QtxListBox
65 VisuGUI_ListBox( QWidget * parent = 0, const char * name = 0, WFlags f = 0 ):
66 QtxListBox(parent, name, f)
69 virtual QSize sizeHint() const
71 return minimumSizeHint(); }
76 //---------------------------------------------------------------
77 VisuGUI_InputPane::VisuGUI_InputPane( VISU::VISUType theType,
78 SalomeApp_Module* theModule,
79 VisuGUI_Prs3dDlg* theDialog ) :
80 QGroupBox( theDialog ),
81 myModule( theModule ),
82 myDialog( theDialog ),
85 setFrameStyle( QFrame::NoFrame );
87 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(theModule);
89 connect( aSelectionMgr, SIGNAL( selectionChanged() ), SLOT( onSelectionChanged() ) );
91 QGridLayout* aMainLayout = new QGridLayout( this, 1, 1, 11, 6 );
93 // Definition of data source
94 myDataSourceGroupBox = new QGroupBox( this );
95 aMainLayout->addWidget( myDataSourceGroupBox, 0, 0 );
96 myDataSourceGroupBox->setTitle( tr( "PRS_DATA_SOUIRCE" ) );
98 QGroupBox* aGroupBox = myDataSourceGroupBox;
99 aGroupBox->setColumnLayout(0, Qt::Vertical );
100 aGroupBox->layout()->setSpacing( 6 );
101 aGroupBox->layout()->setMargin( 11 );
103 QGridLayout* aGroupBoxLayout = new QGridLayout( aGroupBox->layout() );
104 aGroupBoxLayout->setAlignment( Qt::AlignTop );
106 QLabel* aLabel = new QLabel( tr( "MED_FILE" ), aGroupBox );
107 aGroupBoxLayout->addWidget( aLabel, 0, 0 );
109 myMedFile = new QLineEdit( aGroupBox );
110 myMedFile->setReadOnly( true );
111 myMedFile->setEnabled( false );
112 myMedFile->setPaletteForegroundColor( Qt::black );
113 aGroupBoxLayout->addWidget( myMedFile, 0, 1 );
116 QLabel* aLabel = new QLabel( tr( "MESH" ), aGroupBox );
117 aGroupBoxLayout->addWidget( aLabel, 1, 0 );
119 myMeshName = new QLineEdit( aGroupBox );
120 myMeshName->setReadOnly( true );
121 myMeshName->setEnabled( false );
122 myMeshName->setPaletteForegroundColor( Qt::black );
123 aGroupBoxLayout->addWidget( myMeshName, 1, 1 );
126 QLabel* aLabel = new QLabel( tr( "ENTITY" ), aGroupBox );
127 aGroupBoxLayout->addWidget( aLabel, 2, 0 );
129 myEntityName = new QLineEdit( aGroupBox );
130 myEntityName->setReadOnly( true );
131 myEntityName->setEnabled( false );
132 myEntityName->setPaletteForegroundColor( Qt::black );
133 aGroupBoxLayout->addWidget( myEntityName, 2, 1 );
136 QLabel* aLabel = new QLabel( tr( "FIELD" ), aGroupBox );
137 aGroupBoxLayout->addWidget( aLabel, 3, 0 );
139 myFieldName = new QLineEdit( aGroupBox );
140 myFieldName->setReadOnly( true );
141 aGroupBoxLayout->addWidget( myFieldName, 3, 1 );
144 QLabel* aLabel = new QLabel( tr( "TIME_STAMP" ), aGroupBox );
145 aGroupBoxLayout->addWidget( aLabel, 4, 0 );
147 myTimeStamps = new QComboBox( aGroupBox );
148 aGroupBoxLayout->addWidget( myTimeStamps, 4, 1 );
151 myReInit = new QCheckBox( tr( "REINITIALIZE" ), aGroupBox );
152 myReInit->setChecked( true );
153 aGroupBoxLayout->addWidget( myReInit, 5, 1 );
156 // Definition of used groups
157 myUseGroupsGroupBox = new QGroupBox( this );
158 aMainLayout->addWidget( myUseGroupsGroupBox, 1, 0 );
159 myUseGroupsGroupBox->setTitle( tr( "PRS_ON_GROUPS" ) );
160 myUseGroupsGroupBox->setCheckable( TRUE );
162 QGroupBox* aGroupBox = myUseGroupsGroupBox;
163 aGroupBox->setColumnLayout(0, Qt::Vertical );
164 aGroupBox->layout()->setSpacing( 6 );
165 aGroupBox->layout()->setMargin( 11 );
167 QGridLayout* aGroupBoxLayout = new QGridLayout( aGroupBox->layout() );
168 aGroupBoxLayout->setAlignment( Qt::AlignTop );
170 myAllGroups = new VisuGUI_ListBox(aGroupBox, "myAllGroups");
171 myAllGroups->setSelectionMode(QListBox::Extended);
172 aGroupBoxLayout->addMultiCellWidget( myAllGroups, 0, 3, 0, 0 );
175 mySelectedGroups = new VisuGUI_ListBox(aGroupBox, "mySelectedGroups");
176 mySelectedGroups->setSelectionMode(QListBox::Extended);
177 mySelectedGroups->installEventFilter(this);
178 aGroupBoxLayout->addMultiCellWidget( mySelectedGroups, 0, 3, 2, 2 );
181 myAddButton = new QToolButton(aGroupBox);
182 myAddButton->setPixmap( VISU::GetResourceMgr()->loadPixmap("VISU", tr("ICON_ADD")) );
183 aGroupBoxLayout->addWidget( myAddButton, 1, 1 );
186 myRemoveButton = new QToolButton(aGroupBox);
187 myRemoveButton->setPixmap( VISU::GetResourceMgr()->loadPixmap("VISU", tr("ICON_REMOVE")) );
188 aGroupBoxLayout->addWidget( myRemoveButton, 2, 1 );
191 QSpacerItem* aSpacer = new QSpacerItem( 20, 51, QSizePolicy::Minimum, QSizePolicy::Expanding );
192 aGroupBoxLayout->addItem( aSpacer, 0, 1 );
195 QSpacerItem* aSpacer = new QSpacerItem( 20, 61, QSizePolicy::Minimum, QSizePolicy::Expanding );
196 aGroupBoxLayout->addItem( aSpacer, 3, 1 );
200 connect( myTimeStamps, SIGNAL( activated( int ) ), this, SLOT( changeTimeStamp( int ) ) );
201 connect( myReInit, SIGNAL( toggled( bool ) ), SLOT( onReInitialize( bool ) ) );
203 connect( myUseGroupsGroupBox, SIGNAL( toggled( bool ) ), this, SLOT( onTypeChanged() ) );
204 connect( myAllGroups, SIGNAL( doubleClicked( QListBoxItem* ) ), this, SLOT( onListDoubleClicked( QListBoxItem* ) ) );
205 connect( mySelectedGroups, SIGNAL( doubleClicked( QListBoxItem* ) ), this, SLOT( onListDoubleClicked( QListBoxItem* ) ) );
206 connect( myAddButton, SIGNAL(clicked()), this, SLOT(onAdd()));
207 connect( myRemoveButton, SIGNAL(clicked()), this, SLOT(onRemove()));
209 // Save current selection (to be restored in destructor)
210 aSelectionMgr->selectedObjects(mySavedSelection);
213 onSelectionChanged();
215 myFieldFilter = new VisuGUI_FieldFilter( theType );
221 //---------------------------------------------------------------
222 VisuGUI_InputPane::~VisuGUI_InputPane()
224 LightApp_SelectionMgr* aSelectionMgr = VISU::GetSelectionMgr(myModule);
228 aSelectionMgr->removeFilter(myFieldFilter);
229 delete myFieldFilter;
232 // Restore initial selection
233 aSelectionMgr->setSelectedObjects(mySavedSelection);
237 //---------------------------------------------------------------
241 bool VisuGUI_InputPane::eventFilter (QObject* object, QEvent* event)
243 if (event->type() == QEvent::KeyPress) {
244 QKeyEvent* aKeyEvent = (QKeyEvent*)event;
245 if (object == mySelectedGroups && aKeyEvent->key() == Key_Delete)
248 return QObject::eventFilter(object, event);
252 //---------------------------------------------------------------
254 Called when the checkbox is toggled
256 void VisuGUI_InputPane::onTypeChanged( )
258 bool toEnable = myUseGroupsGroupBox->isChecked();
261 myAllGroups->clearSelection();
262 mySelectedGroups->clearSelection();
264 myAllGroups->setEnabled( toEnable );
265 mySelectedGroups->setEnabled( toEnable );
266 myAddButton->setEnabled( toEnable );
267 myRemoveButton->setEnabled( toEnable );
271 //---------------------------------------------------------------
273 Called when add button is clicked, adds item to choosen groups
275 void VisuGUI_InputPane::onAdd()
279 for (int i = 0; i < myAllGroups->count(); i++)
280 if (myAllGroups->isSelected(i))
281 aList.append(myAllGroups->text(i));
283 for (int i = 0; i < mySelectedGroups->count(); i++)
284 aList.remove(mySelectedGroups->text(i));
286 mySelectedGroups->insertStringList(aList);
290 //---------------------------------------------------------------
292 Called when remove button is clicked, remove selected items from choosen
294 void VisuGUI_InputPane::onRemove()
296 QPtrList<QListBoxItem> aList;
297 aList.setAutoDelete(false);
298 for (int i = 0; i < mySelectedGroups->count(); i++)
299 if (mySelectedGroups->isSelected(i))
300 aList.append(mySelectedGroups->item(i));
302 for (int i = 0; i < aList.count(); i++)
307 //---------------------------------------------------------------
309 Called when an item of listbox is double-clicked
311 void VisuGUI_InputPane::onListDoubleClicked( QListBoxItem* theItem )
313 QListBox* aListBox = theItem->listBox();
315 if (aListBox == myAllGroups)
317 if (!mySelectedGroups->findItem( theItem->text(), Qt::ExactMatch ))
318 mySelectedGroups->insertItem(theItem->text());
320 else if (aListBox == mySelectedGroups)
325 //---------------------------------------------------------------
326 bool VisuGUI_InputPane::check()
328 return myTimeStamps->count() != 0;
332 //---------------------------------------------------------------
333 void VisuGUI_InputPane::clear()
337 myEntityName->clear();
338 myFieldName->clear();
339 myTimeStamps->clear();
343 //---------------------------------------------------------------
344 void VisuGUI_InputPane::onSelectionChanged()
348 SALOME_ListIO aListIO;
349 VISU::GetSelectionMgr( myModule )->selectedObjects(aListIO);
351 if (aListIO.Extent() != 1)
354 const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
356 _PTR(Study) aCStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
357 _PTR(SObject) aSObject = aCStudy->FindObjectID(anIO->getEntry());
361 VISU::VISUType aType = VISU::Storable::SObject2Type(aSObject);
362 if (aType == VISU::TFIELD)
364 _PTR(SObject) aMedObject = aSObject->GetFather()->GetFather()->GetFather();
368 myTimeStamps->clear();
370 QString anEntityName, aTimeStampName;
372 _PTR(StudyBuilder) aBuilder = aCStudy->NewBuilder();
373 _PTR(ChildIterator) aIter = aCStudy->NewChildIterator(aSObject);
374 for( ; aIter->More(); aIter->Next() )
376 _PTR(SObject) aChildObj = aIter->Value();
380 if( anEntityName.isNull() )
382 _PTR(SObject) aRefObj;
383 if( aChildObj->ReferencedObject( aRefObj ) )
384 anEntityName = aRefObj->GetName().c_str();
387 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aChildObj);
388 if( aRestoringMap["myComment"] == "TIMESTAMP" )
390 aTimeStampName = aChildObj->GetName().c_str();
391 myTimeStamps->insertItem( aTimeStampName );
395 myResult = VISU::FindResult( VISU::GetSObject( aSObject ).in() );
397 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aSObject);
398 myEntity = aRestoringMap["myEntityId"].toInt();
400 QString aMedFile = aMedObject->GetName().c_str();
401 QString aMeshName = aRestoringMap["myMeshName"];
402 QString aFieldName = aRestoringMap["myName"];
404 myMedFile->setText( aMedFile );
405 myMeshName->setText( aMeshName );
406 myEntityName->setText( anEntityName );
407 myFieldName->setText( aFieldName );
408 myTimeStamps->setCurrentItem( 0 );
410 if( myReInit->isChecked() && myPrs )
412 QApplication::setOverrideCursor(Qt::waitCursor);
414 myPrs->SetResultObject( myResult );
415 myPrs->SetMeshName( aMeshName.latin1() );
416 myPrs->SetEntity( VISU::Entity( myEntity ) );
417 myPrs->SetFieldName( aFieldName.latin1() );
418 myPrs->SetTimeStampNumber( myPrs->GetTimeStampNumberByIndex( 0 ) );
419 myPrs->Apply( true );
421 myDialog->initFromPrsObject( myPrs, false );
423 QApplication::restoreOverrideCursor();
429 //---------------------------------------------------------------
430 void VisuGUI_InputPane::changeTimeStamp( int theTimeStamp )
432 QApplication::setOverrideCursor(Qt::waitCursor);
434 myPrs->SetTimeStampNumber( myPrs->GetTimeStampNumberByIndex( theTimeStamp ) );
435 myPrs->Apply( true );
436 myDialog->initFromPrsObject( myPrs, false );
438 QApplication::restoreOverrideCursor();
442 //---------------------------------------------------------------
443 void VisuGUI_InputPane::onReInitialize( bool on )
446 onSelectionChanged();
450 //---------------------------------------------------------------
451 void VisuGUI_InputPane::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs )
453 if( myPrs == thePrs )
460 CORBA::Long aTimeStampNumber = thePrs->GetTimeStampNumber();
461 VISU::ColoredPrs3dHolder::TimeStampsRange_var aTimeStampsRange = thePrs->GetTimeStampsRange();
462 CORBA::Long aLength = aTimeStampsRange->length();
464 for( int index = 0; index < aLength; index++ )
466 VISU::ColoredPrs3dHolder::TimeStampInfo anInfo = aTimeStampsRange[ index ];
467 QString aTime = anInfo.myTime.in();
468 myTimeStamps->insertItem( aTime );
471 myResult = thePrs->GetResultObject();
472 VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>(GetServant(myResult).in());
473 myMedFile->setText( aResult->GetName().c_str() );
475 myEntity = (int)thePrs->GetEntity();
477 QString anEntityName;
480 case VISU::NODE_ENTITY:
481 anEntityName = "onNodes";
483 case VISU::EDGE_ENTITY:
484 anEntityName = "onEdges";
486 case VISU::FACE_ENTITY:
487 anEntityName = "onFaces";
489 case VISU::CELL_ENTITY:
490 anEntityName = "onCells";
494 myEntityName->setText( anEntityName );
496 myMeshName->setText( thePrs->GetMeshName() );
497 myFieldName->setText( thePrs->GetFieldName() );
498 myTimeStamps->setCurrentItem( thePrs->GetTimeStampIndexByNumber( aTimeStampNumber ) );
500 myFieldFilter->setPrs3dEntry( thePrs->GetHolderEntry() );
501 bool anIsTimeStampFixed = myPrs->IsTimeStampFixed();
502 myDataSourceGroupBox->setEnabled(!anIsTimeStampFixed);
503 if(!anIsTimeStampFixed)
504 VISU::GetSelectionMgr( myModule )->installFilter( myFieldFilter );
506 // type of presentation and groups
507 VISU::Result_i::PInput anInput = aResult->GetInput();
508 const VISU::TMeshMap& aMeshMap = anInput->GetMeshMap();
509 std::string aMeshName = thePrs->GetCMeshName();
510 VISU::TMeshMap::const_iterator aMeshIter = aMeshMap.find(aMeshName);
511 if(aMeshIter != aMeshMap.end()){
512 const VISU::PMesh& aMesh = aMeshIter->second;
513 const VISU::TGroupMap& aGroupMap = aMesh->myGroupMap;
514 VISU::TGroupMap::const_iterator aGroupIter = aGroupMap.begin();
515 for(; aGroupIter != aGroupMap.end(); aGroupIter++){
516 const std::string& aGroupName = aGroupIter->first;
517 myAllGroups->insertItem(QString(aGroupName));
521 if(myAllGroups->count() < 1){
522 myAllGroups->insertItem( tr("NO_GROUPS") );
523 myUseGroupsGroupBox->setEnabled(false);
525 const VISU::ColoredPrs3d_i::TGroupNames& aGroupNames = thePrs->GetGroupNames();
526 VISU::ColoredPrs3d_i::TGroupNames::const_iterator anIter = aGroupNames.begin();
527 for(; anIter != aGroupNames.end(); anIter++){
528 const std::string aGroupName = *anIter;
529 mySelectedGroups->insertItem(QString(aGroupName));
532 myUseGroupsGroupBox->setChecked(mySelectedGroups->count() > 0);
533 myUseGroupsGroupBox->setEnabled(anIsTimeStampFixed);
537 //---------------------------------------------------------------
538 int VisuGUI_InputPane::storeToPrsObject( VISU::ColoredPrs3d_i* thePrs )
541 if(myUseGroupsGroupBox->isChecked()){
542 thePrs->RemoveAllGeom();
543 for(int i = 0; i < mySelectedGroups->count(); i++)
544 thePrs->AddMeshOnGroup(mySelectedGroups->text(i) );
546 thePrs->SetSourceGeometry();
548 thePrs->SetResultObject( myResult );
550 thePrs->SetMeshName( myMeshName->text().latin1() );
551 thePrs->SetEntity( VISU::Entity( myEntity ) );
552 thePrs->SetFieldName( myFieldName->text().latin1() );
553 thePrs->SetTimeStampNumber( thePrs->GetTimeStampNumberByIndex( myTimeStamps->currentItem() ) );
554 return ( int )thePrs->Apply( false );
558 //---------------------------------------------------------------