1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SUPERVGUI_BrowseNodeDlg.cxx
8 // Author : Vitaly SMETANNIKOV
12 #include "SUPERVGUI_BrowseNodeDlg.h"
13 #include "SUPERVGUI_Node.h"
14 #include "SUPERVGUI.h"
17 #include <qlineedit.h>
18 #include <qpushbutton.h>
20 #include <qgroupbox.h>
25 SUPERVGUI_PortField::SUPERVGUI_PortField( QWidget* theParent, SUPERV_Port thePort ) {
27 myIsEditable = myPort->IsInput() && ( !myPort->IsLinked() );
29 QString aLabelTxt(myPort->Name());
31 SUPERV_CNode aNode = myPort->Node();
32 SALOME_ModuleCatalog::Service* aService = aNode->Service();
33 SALOME_ModuleCatalog::ListOfServicesParameter aList;
34 aList = (myPort->IsInput())? aService->ServiceinParameter : aService->ServiceoutParameter;
35 for (int i = 0; i < aList.length(); i++) {
36 SALOME_ModuleCatalog::ServicesParameter* aParam = &(aList[i]);
37 if (aLabelTxt == aParam->Parametername) {
38 aLabelTxt += QString(" (") + QString(aParam->Parametertype) + QString(")");
43 aLabelTxt += QString(":");
44 myLabel = new QLabel(aLabelTxt, theParent );
46 myValue = new QLineEdit( theParent );
47 myLabel->setBuddy( myValue );
49 myValue->setReadOnly( !myIsEditable );
50 QPalette aPalette = myValue->palette();
51 aPalette.setInactive(aPalette.disabled());
52 aPalette.setActive(aPalette.disabled());
53 myValue->setPalette(aPalette);
55 myValue->installEventFilter( this );
59 * Sets value from text edit control to engine of port
61 bool SUPERVGUI_PortField::setNewValue() {
62 if ( !myIsEditable ) return false;
64 QString aTxt = myValue->text();
65 if ( aTxt.isNull() || aTxt.isEmpty() ) return false;
67 if ( aTxt.find( "Unknown" ) < 0 ) {
68 return myPort->Input( Supervision.getEngine()->StringValue( aTxt ) );
76 bool SUPERVGUI_PortField::eventFilter( QObject* o, QEvent* e )
79 if ( e->type() == QEvent::FocusIn ) {
83 return QObject::eventFilter( o, e );
90 SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_Node* theNode )
91 : QDialog( theNode, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
94 setSizeGripEnabled( true );
96 myPortsList.setAutoDelete( true );
98 SUPERV_CNode aEngine = myNode->getEngine();
99 mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
100 // mySelection->ClearIObjects();
102 setName( "SUPERVGUI_BrowseNodeDlg" );
103 setCaption( tr( "TIT_BROWSENODE" ) + aEngine->Name() );
105 QGridLayout* aBaseLayout = new QGridLayout( this );
106 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
108 QGroupBox* aInBox = new QGroupBox( 2, Qt::Horizontal, "Input", this );
109 aInBox->setMargin( 11 );
110 aBaseLayout->addWidget( aInBox, 0, 0 );
112 QGroupBox* aOutBox = new QGroupBox( 2, Qt::Horizontal, "Output", this);
113 aOutBox->setMargin( 11 );
114 aBaseLayout->addWidget( aOutBox, 0, 1 );
116 myIsEditable = false;
119 SUPERV_Ports ports = aEngine->Ports();
120 int n = ports->length();
122 for ( int i = 0; i < n; i++ ) {
123 if ( ports[i]->IsInput() ) {
124 if ( !ports[i]->IsGate() ) { // not a gate
125 SUPERVGUI_PortField* aField = new SUPERVGUI_PortField( aInBox, ports[i] );
126 if ( aField->isEditable() ) myIsEditable = true;
127 myPortsList.append( aField );
128 if ( !myActiveField )
129 myActiveField = aField;
130 connect( aField, SIGNAL( activated() ), this, SLOT( onFieldActivated() ) );
135 if ( !ports[i]->IsGate() ) { // not a gate
136 myPortsList.append( new SUPERVGUI_PortField( aOutBox, ports[i] ) );
142 QGroupBox* aBtnBox = new QGroupBox( this );
143 aBtnBox->setColumnLayout( 0, Qt::Vertical );
144 aBtnBox->layout()->setSpacing( 0 );
145 aBtnBox->layout()->setMargin( 0 );
147 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
148 aBtnLayout->setAlignment( Qt::AlignTop );
149 aBtnLayout->setSpacing( 6 );
150 aBtnLayout->setMargin( 11 );
152 if ( myIsEditable ) {
153 QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), this );
154 aBaseLayout->addMultiCellWidget( aInfoLab, 1, 1, 0, 1 );
156 QPushButton* aOkBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
157 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
158 aBtnLayout->addWidget( aOkBtn );
159 aBaseLayout->addMultiCellWidget( aBtnBox, 2, 2, 0, 1 );
161 aBaseLayout->addMultiCellWidget( aBtnBox, 1, 1, 0, 1 );
163 aBtnLayout->addStretch();
164 QPushButton* aCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
165 aBtnLayout->addWidget( aCancelBtn );
166 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
169 aBtnLayout->addStretch();
171 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
172 myNode->getMain()->lockedGraph(true);
178 SUPERVGUI_BrowseNodeDlg::~SUPERVGUI_BrowseNodeDlg() {
182 * Set current values of editable ports
184 void SUPERVGUI_BrowseNodeDlg::setValues() {
185 SUPERVGUI_PortField* aField;
186 for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
192 * Set inputed values of editable ports and then closes and destroys dialog
194 void SUPERVGUI_BrowseNodeDlg::accept() {
195 if ( myIsEditable ) {
196 SUPERVGUI_PortField* aField;
197 for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
198 aField->setNewValue();
202 myNode->getMain()->lockedGraph(false);
209 * Closes and destroys dialog
211 void SUPERVGUI_BrowseNodeDlg::reject() {
212 myNode->getMain()->lockedGraph(false);
218 * Update current values on show event
220 void SUPERVGUI_BrowseNodeDlg::showEvent( QShowEvent* theEvent ) {
222 QDialog::showEvent( theEvent );
226 * Slot, called when field is focused
228 void SUPERVGUI_BrowseNodeDlg::onFieldActivated()
230 SUPERVGUI_PortField* aField = (SUPERVGUI_PortField*)sender();
231 myActiveField = (aField->isEditable())? aField : 0;
237 * Slot, called when selection is changed
239 void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
241 if ( myActiveField ) {
242 if( mySelection->IObjectCount() == 1 ) {
243 Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
244 if ( anIO->hasEntry() ) {
245 SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
246 getStudyDocument()->FindObjectID( anIO->getEntry() );
248 SALOMEDS::GenericAttribute_var anAttr;
249 SALOMEDS::AttributeIOR_var anIOR;
250 Standard_CString ior = "";
252 if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
253 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
254 ior = anIOR->Value();
257 ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
259 myActiveField->setData( ior );
268 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortIn* thePort )
269 : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
272 setSizeGripEnabled( true );
276 mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
277 // mySelection->ClearIObjects();
279 setName( "SUPERVGUI_GetValueDlg" );
280 setCaption( tr( "TIT_SETVALUE_PORT" ) );
282 QGridLayout* aBaseLayout = new QGridLayout( this );
283 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
285 QGroupBox* aBox = new QGroupBox( this );
286 aBox->setColumnLayout( 0, Qt::Vertical );
287 aBox->layout()->setSpacing( 0 ); aBox->layout()->setMargin( 0 );
288 QGridLayout* aBoxLayout = new QGridLayout( aBox->layout() );
289 aBoxLayout->setAlignment( Qt::AlignTop );
290 aBoxLayout->setSpacing( 6 ); aBoxLayout->setMargin( 11 );
291 aBaseLayout->addWidget( aBox, 0, 0 );
292 aBox->setMinimumWidth( 200 );
294 QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), aBox );
295 QFont fnt = aInfoLab->font(); fnt.setBold( true ); aInfoLab->setFont( fnt );
296 aBoxLayout->addMultiCellWidget( aInfoLab, 0, 0, 0, 1 );
297 myField = new SUPERVGUI_PortField( aBox, myPort->getPort() );
298 bool myIsEditable = myField->isEditable();
299 aBoxLayout->addWidget( myField->myLabel, 1, 0 );
300 aBoxLayout->addWidget( myField->myValue, 1, 1 );
302 QGroupBox* aBtnBox = new QGroupBox( this );
303 aBtnBox->setColumnLayout( 0, Qt::Vertical );
304 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
305 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
306 aBtnLayout->setAlignment( Qt::AlignTop );
307 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
309 aBaseLayout->addWidget( aBtnBox, 1, 0 );
311 if ( myIsEditable ) {
312 myOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
313 connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
314 aBtnLayout->addWidget( myOKBtn );
317 aBtnLayout->addStretch();
318 myCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
319 aBtnLayout->addWidget( myCancelBtn );
320 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
323 aBtnLayout->addStretch();
325 myField->updateGUI();
326 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
327 myPort->getMain()->lockedGraph(true);
333 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortInESNode* thePort )
334 : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
337 setSizeGripEnabled( true );
339 myPortESNode = thePort;
341 mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
342 // mySelection->ClearIObjects();
344 setName( "SUPERVGUI_GetValueDlg" );
345 setCaption( tr( "TIT_SETVALUE_PORT" ) );
347 QGridLayout* aBaseLayout = new QGridLayout( this );
348 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
350 QGroupBox* aBox = new QGroupBox( this );
351 aBox->setColumnLayout( 0, Qt::Vertical );
352 aBox->layout()->setSpacing( 0 ); aBox->layout()->setMargin( 0 );
353 QGridLayout* aBoxLayout = new QGridLayout( aBox->layout() );
354 aBoxLayout->setAlignment( Qt::AlignTop );
355 aBoxLayout->setSpacing( 6 ); aBoxLayout->setMargin( 11 );
356 aBaseLayout->addWidget( aBox, 0, 0 );
357 aBox->setMinimumWidth( 200 );
359 QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), aBox );
360 QFont fnt = aInfoLab->font(); fnt.setBold( true ); aInfoLab->setFont( fnt );
361 aBoxLayout->addMultiCellWidget( aInfoLab, 0, 0, 0, 1 );
362 myField = new SUPERVGUI_PortField( aBox, myPortESNode->getPort() );
363 bool myIsEditable = myField->isEditable();
364 aBoxLayout->addWidget( myField->myLabel, 1, 0 );
365 aBoxLayout->addWidget( myField->myValue, 1, 1 );
367 QGroupBox* aBtnBox = new QGroupBox( this );
368 aBtnBox->setColumnLayout( 0, Qt::Vertical );
369 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
370 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
371 aBtnLayout->setAlignment( Qt::AlignTop );
372 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
374 aBaseLayout->addWidget( aBtnBox, 1, 0 );
376 if ( myIsEditable ) {
377 myOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
378 connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
379 aBtnLayout->addWidget( myOKBtn );
382 aBtnLayout->addStretch();
383 myCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
384 aBtnLayout->addWidget( myCancelBtn );
385 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
388 aBtnLayout->addStretch();
390 myField->updateGUI();
391 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
392 myPortESNode->getMain()->lockedGraph(true);
398 SUPERVGUI_GetValueDlg::~SUPERVGUI_GetValueDlg() {
402 * Set entered value into port and then closes and destroys dialog
404 void SUPERVGUI_GetValueDlg::accept() {
405 if ( myField->setNewValue() ) {
410 myPortESNode->sync();
413 if ( QMessageBox::warning( QAD_Application::getDesktop(),
414 tr( "ERROR" ), tr( "MSG_CANT_SETVAL" ),
415 QMessageBox::Retry, QMessageBox::Abort) == QMessageBox::Retry )
420 myPort->getMain()->lockedGraph(false);
422 myPortESNode->getMain()->lockedGraph(false);
428 * Closes and destroys dialog
430 void SUPERVGUI_GetValueDlg::reject() {
432 myPort->getMain()->lockedGraph(false);
434 myPortESNode->getMain()->lockedGraph(false);
440 * Slot, called when selection is changed
442 void SUPERVGUI_GetValueDlg::onSelectionChanged()
444 if( mySelection->IObjectCount() == 1 ) {
445 Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
446 if ( anIO->hasEntry() ) {
447 SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
448 getStudyDocument()->FindObjectID( anIO->getEntry() );
450 SALOMEDS::GenericAttribute_var anAttr;
451 SALOMEDS::AttributeIOR_var anIOR;
452 Standard_CString ior = "";
454 if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
455 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
456 ior = anIOR->Value();
459 ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
461 myField->setData( ior );