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
13 #include "SUPERVGUI_BrowseNodeDlg.h"
14 #include "SUPERVGUI_CanvasNode.h"
15 #include "SUPERVGUI_CanvasPort.h"
16 #include "SUPERVGUI.h"
20 #include <qlineedit.h>
21 #include <qpushbutton.h>
23 #include <qgroupbox.h>
24 #include <qvalidator.h>
29 SUPERVGUI_PortField::SUPERVGUI_PortField( QWidget* theParent, SUPERV_Port thePort ) {
31 myIsEditable = myPort->IsInput() && ( !myPort->IsLinked() );
33 QString aLabelTxt(myPort->Name());
35 SUPERV_CNode aNode = myPort->Node();
36 SALOME_ModuleCatalog::Service* aService = aNode->Service();
37 SALOME_ModuleCatalog::ListOfServicesParameter aList;
38 aList = (myPort->IsInput())? aService->ServiceinParameter : aService->ServiceoutParameter;
39 for (int i = 0; i < aList.length(); i++) {
40 SALOME_ModuleCatalog::ServicesParameter* aParam = &(aList[i]);
41 if (aLabelTxt == aParam->Parametername) {
42 aLabelTxt += QString(" (") + QString(aParam->Parametertype) + QString(")");
47 aLabelTxt += QString(":");
48 myLabel = new QLabel(aLabelTxt, theParent );
50 myValue = new QLineEdit( theParent );
51 myLabel->setBuddy( myValue );
53 myValue->setReadOnly( !myIsEditable );
54 QPalette aPalette = myValue->palette();
55 aPalette.setInactive(aPalette.disabled());
56 aPalette.setActive(aPalette.disabled());
57 myValue->setPalette(aPalette);
59 myValue->installEventFilter( this );
63 * Sets value from text edit control to engine of port
65 bool SUPERVGUI_PortField::setNewValue() {
66 if ( !myIsEditable ) return false;
68 QString aTxt = myValue->text();
69 if ( aTxt.isNull() || aTxt.isEmpty() ) return false;
71 if ( aTxt.find( "Unknown" ) < 0 ) {
72 return myPort->Input( Supervision.getEngine()->StringValue( aTxt ) );
80 bool SUPERVGUI_PortField::eventFilter( QObject* o, QEvent* e )
83 if ( e->type() == QEvent::FocusIn ) {
87 return QObject::eventFilter( o, e );
92 * Constructor (SUPERVGUI_CanvasNode)
94 SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_CanvasNode* theNode )
95 : QDialog( QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
97 myNodeCanvas = theNode;
102 void SUPERVGUI_BrowseNodeDlg::init()
105 setSizeGripEnabled( true );
106 myPortsList.setAutoDelete( true );
108 SUPERV_CNode aEngine = myNodeCanvas->getEngine();
110 mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
111 // mySelection->ClearIObjects();
113 setName( "SUPERVGUI_BrowseNodeDlg" );
114 setCaption( tr( "TIT_BROWSENODE" ) + aEngine->Name() );
116 QGridLayout* aBaseLayout = new QGridLayout( this );
117 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
119 QGroupBox* aInBox = new QGroupBox( 2, Qt::Horizontal, "Input", this );
120 aInBox->setMargin( 11 );
121 aBaseLayout->addWidget( aInBox, 0, 0 );
123 QGroupBox* aOutBox = new QGroupBox( 2, Qt::Horizontal, "Output", this);
124 aOutBox->setMargin( 11 );
125 aBaseLayout->addWidget( aOutBox, 0, 1 );
127 myIsEditable = false;
130 SUPERV_Ports ports = aEngine->Ports();
131 int n = ports->length();
133 for ( int i = 0; i < n; i++ ) {
134 if ( ports[i]->IsInput() ) {
135 if ( !ports[i]->IsGate() ) { // not a gate
136 SUPERVGUI_PortField* aField = new SUPERVGUI_PortField( aInBox, ports[i] );
137 if ( aField->isEditable() )
139 myPortsList.append( aField );
140 if ( !myActiveField )
141 myActiveField = aField;
142 connect( aField, SIGNAL( activated() ), this, SLOT( onFieldActivated() ) );
147 if ( !ports[i]->IsGate() ) { // not a gate
148 myPortsList.append( new SUPERVGUI_PortField( aOutBox, ports[i] ) );
154 QGroupBox* aBtnBox = new QGroupBox( this );
155 aBtnBox->setColumnLayout( 0, Qt::Vertical );
156 aBtnBox->layout()->setSpacing( 0 );
157 aBtnBox->layout()->setMargin( 0 );
159 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
160 aBtnLayout->setAlignment( Qt::AlignTop );
161 aBtnLayout->setSpacing( 6 );
162 aBtnLayout->setMargin( 11 );
164 if ( myIsEditable ) {
165 QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), this );
166 aBaseLayout->addMultiCellWidget( aInfoLab, 1, 1, 0, 1 );
168 QPushButton* aOkBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
169 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
170 aBtnLayout->addWidget( aOkBtn );
171 aBaseLayout->addMultiCellWidget( aBtnBox, 2, 2, 0, 1 );
173 aBaseLayout->addMultiCellWidget( aBtnBox, 1, 1, 0, 1 );
175 aBtnLayout->addStretch();
176 QPushButton* aCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
177 aBtnLayout->addWidget( aCancelBtn );
178 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
181 aBtnLayout->addStretch();
183 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
184 myNodeCanvas->getMain()->lockedGraph(true);
190 SUPERVGUI_BrowseNodeDlg::~SUPERVGUI_BrowseNodeDlg() {
194 * Set current values of editable ports
196 void SUPERVGUI_BrowseNodeDlg::setValues() {
197 SUPERVGUI_PortField* aField;
198 for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
204 * Set inputed values of editable ports and then closes and destroys dialog
206 void SUPERVGUI_BrowseNodeDlg::accept() {
207 myNodeCanvas->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
208 if ( myIsEditable ) {
209 SUPERVGUI_PortField* aField;
210 for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
211 aField->setNewValue();
213 myNodeCanvas->sync();
214 myNodeCanvas->getMain()->getCanvas()->update();
216 myNodeCanvas->getMain()->lockedGraph(false);
223 * Closes and destroys dialog
225 void SUPERVGUI_BrowseNodeDlg::reject() {
226 myNodeCanvas->getMain()->lockedGraph(false);
232 * Update current values on show event
234 void SUPERVGUI_BrowseNodeDlg::showEvent( QShowEvent* theEvent ) {
236 QDialog::showEvent( theEvent );
240 * Slot, called when field is focused
242 void SUPERVGUI_BrowseNodeDlg::onFieldActivated()
244 SUPERVGUI_PortField* aField = (SUPERVGUI_PortField*)sender();
245 myActiveField = (aField->isEditable())? aField : 0;
251 * Slot, called when selection is changed
253 void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
255 if ( myActiveField ) {
256 if( mySelection->IObjectCount() == 1 ) {
257 Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
258 if ( anIO->hasEntry() ) {
259 SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
260 getStudyDocument()->FindObjectID( anIO->getEntry() );
262 SALOMEDS::GenericAttribute_var anAttr;
263 SALOMEDS::AttributeIOR_var anIOR;
264 Standard_CString ior = "";
266 if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
267 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
268 ior = anIOR->Value();
271 ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
273 myActiveField->setData( ior );
281 * Constructor (SUPERVGUI_CanvasPort)
283 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_CanvasPort* thePort )
284 : QDialog( QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
286 myPortCanvas = thePort;
291 void SUPERVGUI_GetValueDlg::init()
294 setSizeGripEnabled( true );
296 mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
297 // mySelection->ClearIObjects();
299 setName( "SUPERVGUI_GetValueDlg" );
300 setCaption( tr( "TIT_SETVALUE_PORT" ) );
302 QGridLayout* aBaseLayout = new QGridLayout( this );
303 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
305 QGroupBox* aBox = new QGroupBox( this );
306 aBox->setColumnLayout( 0, Qt::Vertical );
307 aBox->layout()->setSpacing( 0 ); aBox->layout()->setMargin( 0 );
308 QGridLayout* aBoxLayout = new QGridLayout( aBox->layout() );
309 aBoxLayout->setAlignment( Qt::AlignTop );
310 aBoxLayout->setSpacing( 6 ); aBoxLayout->setMargin( 11 );
311 aBaseLayout->addWidget( aBox, 0, 0 );
312 aBox->setMinimumWidth( 200 );
314 QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), aBox );
315 QFont fnt = aInfoLab->font(); fnt.setBold( true ); aInfoLab->setFont( fnt );
316 aBoxLayout->addMultiCellWidget( aInfoLab, 0, 0, 0, 1 );
317 SUPERV_Port aEngine = myPortCanvas->getEngine();
319 myField = new SUPERVGUI_PortField( aBox, aEngine );
320 bool myIsEditable = myField->isEditable();
321 aBoxLayout->addWidget( myField->myLabel, 1, 0 );
322 aBoxLayout->addWidget( myField->myValue, 1, 1 );
324 QGroupBox* aBtnBox = new QGroupBox( this );
325 aBtnBox->setColumnLayout( 0, Qt::Vertical );
326 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
327 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
328 aBtnLayout->setAlignment( Qt::AlignTop );
329 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
331 aBaseLayout->addWidget( aBtnBox, 1, 0 );
333 if ( myIsEditable ) {
334 myOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
335 connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
336 aBtnLayout->addWidget( myOKBtn );
339 aBtnLayout->addStretch();
340 myCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
341 aBtnLayout->addWidget( myCancelBtn );
342 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
345 aBtnLayout->addStretch();
347 myField->updateGUI();
348 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
350 myPortCanvas->getMain()->lockedGraph(true);
356 SUPERVGUI_GetValueDlg::~SUPERVGUI_GetValueDlg() {
360 * Set entered value into port and then closes and destroys dialog
362 void SUPERVGUI_GetValueDlg::accept() {
363 myPortCanvas->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
364 if ( myField->setNewValue() ) {
366 myPortCanvas->sync();
368 // asv : 19.11.04 : fix for 6170, last comment of it about BrowsePort - update node status
369 // asv : 13.12.04 : commented out sync() of Node. See 2.21.
370 //if ( myPortCanvas->parent() && myPortCanvas->parent()->inherits( "SUPERVGUI_CanvasNode" ) ) {
371 // SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*)myPortCanvas->parent();
375 myPortCanvas->getMain()->getCanvas()->update();
378 if ( QMessageBox::warning( QAD_Application::getDesktop(),
379 tr( "ERROR" ), tr( "MSG_CANT_SETVAL" ),
380 QMessageBox::Retry, QMessageBox::Abort) == QMessageBox::Retry )
384 myPortCanvas->getMain()->lockedGraph(false);
391 * Closes and destroys dialog
393 void SUPERVGUI_GetValueDlg::reject() {
394 myPortCanvas->getMain()->lockedGraph(false);
400 * Slot, called when selection is changed
402 void SUPERVGUI_GetValueDlg::onSelectionChanged()
404 if( mySelection->IObjectCount() == 1 ) {
405 Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
406 if ( anIO->hasEntry() ) {
407 SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
408 getStudyDocument()->FindObjectID( anIO->getEntry() );
410 SALOMEDS::GenericAttribute_var anAttr;
411 SALOMEDS::AttributeIOR_var anIOR;
412 Standard_CString ior = "";
414 if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
415 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
416 ior = anIOR->Value();
419 ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
421 myField->setData( ior );
428 // ----------------------------
430 // ----------------------------
432 SUPERVGUI_StreamInDlg::SUPERVGUI_StreamInDlg(SUPERVGUI_CanvasStreamPortIn* thePort)
433 :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
435 myPortCanvas = thePort;
439 void SUPERVGUI_StreamInDlg::init()
441 setSizeGripEnabled( true );
442 setCaption( tr( "MSG_STREAM_DLG_TIT" ) );
444 QVBoxLayout* TopLayout = new QVBoxLayout( this, 11, 6 );
446 QFrame* aCtrlPane = new QFrame(this);
447 QGridLayout* aCtrlLayout = new QGridLayout( aCtrlPane, 4, 10 );
450 QLabel* aSchemaLbl = new QLabel(tr("MSG_STREAM_SCHEMA"),aCtrlPane);
451 aCtrlLayout->addWidget(aSchemaLbl, 0, 0);
453 mySchemaCombo = new QComboBox(aCtrlPane, "SchemaBox" );
454 mySchemaCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
455 mySchemaCombo->insertItem("SCHENULL");
456 mySchemaCombo->insertItem("TI");
457 mySchemaCombo->insertItem("TF");
458 mySchemaCombo->insertItem("DELTA");
459 aCtrlLayout->addWidget(mySchemaCombo, 0, 1);
462 QLabel* aInterLbl = new QLabel(tr("MSG_STREAM_INTER"),aCtrlPane);
463 aCtrlLayout->addWidget(aInterLbl, 1, 0);
465 myInterCombo = new QComboBox(aCtrlPane, "InterBox" );
466 myInterCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
467 myInterCombo->insertItem("INTERNULL");
468 myInterCombo->insertItem("L0");
469 myInterCombo->insertItem("L1");
470 aCtrlLayout->addWidget(myInterCombo, 1, 1);
473 QLabel* aExtraLbl = new QLabel(tr("MSG_STREAM_EXTRA"),aCtrlPane);
474 aCtrlLayout->addWidget(aExtraLbl, 2, 0);
476 myExterCombo = new QComboBox(aCtrlPane, "ExtraBox" );
477 myExterCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
478 myExterCombo->insertItem("EXTRANULL");
479 myExterCombo->insertItem("E0");
480 myExterCombo->insertItem("E1");
481 aCtrlLayout->addWidget(myExterCombo, 2, 1);
483 TopLayout->addWidget( aCtrlPane );
486 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
487 GroupButtons->setColumnLayout(0, Qt::Vertical );
488 GroupButtons->layout()->setSpacing( 0 );
489 GroupButtons->layout()->setMargin( 0 );
490 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
491 GroupButtonsLayout->setAlignment( Qt::AlignTop );
492 GroupButtonsLayout->setSpacing( 5 );
493 GroupButtonsLayout->setMargin( 8 );
495 QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
496 QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
498 GroupButtonsLayout->addWidget( okB, 0, 0 );
499 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
500 GroupButtonsLayout->addWidget( cancelB, 0, 2 );
502 TopLayout->addWidget( GroupButtons );
504 connect( okB, SIGNAL( clicked() ), this, SLOT( accept() ) );
505 connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
509 void SUPERVGUI_StreamInDlg::setData() {
510 SUPERV::KindOfSchema aSchema;
511 SUPERV::KindOfInterpolation aInterpolat;
512 SUPERV::KindOfExtrapolation aExtrapolat;
514 myPortCanvas->getStreamEngine()->Params(aSchema, aInterpolat, aExtrapolat);
516 mySchemaCombo->setCurrentItem((int)aSchema);
517 myInterCombo->setCurrentItem((int)aInterpolat);
518 myExterCombo->setCurrentItem((int)aExtrapolat);
521 void SUPERVGUI_StreamInDlg::accept() {
522 myPortCanvas->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
523 myPortCanvas->getStreamEngine()->SetParams((SUPERV::KindOfSchema) mySchemaCombo->currentItem(),
524 (SUPERV::KindOfInterpolation) myInterCombo->currentItem(),
525 (SUPERV::KindOfExtrapolation) myExterCombo->currentItem());
530 //-------------------------------------------------------------------------
531 SUPERVGUI_StreamOutDlg::SUPERVGUI_StreamOutDlg(SUPERVGUI_CanvasStreamPortOut* thePort)
532 :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
534 myPortCanvas = thePort;
538 void SUPERVGUI_StreamOutDlg::init()
540 setSizeGripEnabled( true );
541 setCaption( tr( "MSG_STREAM_DLG_TIT" ) );
543 QVBoxLayout* TopLayout = new QVBoxLayout( this, 11, 6 );
545 QFrame* aCtrlPane = new QFrame(this);
546 QGridLayout* aCtrlLayout = new QGridLayout( aCtrlPane, 4, 10 );
548 QLabel* aLbl = new QLabel(tr("MSG_STREAM_LEVEL"),aCtrlPane);
549 aCtrlLayout->addWidget(aLbl, 0, 0);
551 myValEdit = new QLineEdit( aCtrlPane, "ValEdit" );
552 myValEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
553 myValEdit->setValidator( new QIntValidator(this) );
554 SUPERV_StreamPort aEngine = myPortCanvas->getStreamEngine();
555 myValEdit->setText(QString("%1").arg(aEngine->NumberOfValues()));
556 aCtrlLayout->addWidget(myValEdit, 0, 1);
557 TopLayout->addWidget( aCtrlPane );
560 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
561 GroupButtons->setColumnLayout(0, Qt::Vertical );
562 GroupButtons->layout()->setSpacing( 0 );
563 GroupButtons->layout()->setMargin( 0 );
564 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
565 GroupButtonsLayout->setAlignment( Qt::AlignTop );
566 GroupButtonsLayout->setSpacing( 5 );
567 GroupButtonsLayout->setMargin( 8 );
569 QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
570 QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
572 GroupButtonsLayout->addWidget( okB, 0, 0 );
573 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
574 GroupButtonsLayout->addWidget( cancelB, 0, 2 );
576 TopLayout->addWidget( GroupButtons );
578 connect( okB, SIGNAL( clicked() ), this, SLOT( accept() ) );
579 connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
582 void SUPERVGUI_StreamOutDlg::accept() {
584 QString aStr = myValEdit->text();
586 aRes = aStr.toLong();
587 myPortCanvas->getStreamEngine()->SetNumberOfValues(aRes);