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 if ( myIsEditable ) {
208 SUPERVGUI_PortField* aField;
209 for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
210 aField->setNewValue();
212 myNodeCanvas->sync();
213 myNodeCanvas->getMain()->getCanvas()->update();
215 myNodeCanvas->getMain()->lockedGraph(false);
222 * Closes and destroys dialog
224 void SUPERVGUI_BrowseNodeDlg::reject() {
225 myNodeCanvas->getMain()->lockedGraph(false);
231 * Update current values on show event
233 void SUPERVGUI_BrowseNodeDlg::showEvent( QShowEvent* theEvent ) {
235 QDialog::showEvent( theEvent );
239 * Slot, called when field is focused
241 void SUPERVGUI_BrowseNodeDlg::onFieldActivated()
243 SUPERVGUI_PortField* aField = (SUPERVGUI_PortField*)sender();
244 myActiveField = (aField->isEditable())? aField : 0;
250 * Slot, called when selection is changed
252 void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
254 if ( myActiveField ) {
255 if( mySelection->IObjectCount() == 1 ) {
256 Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
257 if ( anIO->hasEntry() ) {
258 SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
259 getStudyDocument()->FindObjectID( anIO->getEntry() );
261 SALOMEDS::GenericAttribute_var anAttr;
262 SALOMEDS::AttributeIOR_var anIOR;
263 Standard_CString ior = "";
265 if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
266 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
267 ior = anIOR->Value();
270 ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
272 myActiveField->setData( ior );
280 * Constructor (SUPERVGUI_CanvasPort)
282 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_CanvasPort* thePort )
283 : QDialog( QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
285 myPortCanvas = thePort;
290 void SUPERVGUI_GetValueDlg::init()
293 setSizeGripEnabled( true );
295 mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
296 // mySelection->ClearIObjects();
298 setName( "SUPERVGUI_GetValueDlg" );
299 setCaption( tr( "TIT_SETVALUE_PORT" ) );
301 QGridLayout* aBaseLayout = new QGridLayout( this );
302 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
304 QGroupBox* aBox = new QGroupBox( this );
305 aBox->setColumnLayout( 0, Qt::Vertical );
306 aBox->layout()->setSpacing( 0 ); aBox->layout()->setMargin( 0 );
307 QGridLayout* aBoxLayout = new QGridLayout( aBox->layout() );
308 aBoxLayout->setAlignment( Qt::AlignTop );
309 aBoxLayout->setSpacing( 6 ); aBoxLayout->setMargin( 11 );
310 aBaseLayout->addWidget( aBox, 0, 0 );
311 aBox->setMinimumWidth( 200 );
313 QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), aBox );
314 QFont fnt = aInfoLab->font(); fnt.setBold( true ); aInfoLab->setFont( fnt );
315 aBoxLayout->addMultiCellWidget( aInfoLab, 0, 0, 0, 1 );
316 SUPERV_Port aEngine = myPortCanvas->getEngine();
318 myField = new SUPERVGUI_PortField( aBox, aEngine );
319 bool myIsEditable = myField->isEditable();
320 aBoxLayout->addWidget( myField->myLabel, 1, 0 );
321 aBoxLayout->addWidget( myField->myValue, 1, 1 );
323 QGroupBox* aBtnBox = new QGroupBox( this );
324 aBtnBox->setColumnLayout( 0, Qt::Vertical );
325 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
326 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
327 aBtnLayout->setAlignment( Qt::AlignTop );
328 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
330 aBaseLayout->addWidget( aBtnBox, 1, 0 );
332 if ( myIsEditable ) {
333 myOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
334 connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
335 aBtnLayout->addWidget( myOKBtn );
338 aBtnLayout->addStretch();
339 myCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
340 aBtnLayout->addWidget( myCancelBtn );
341 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
344 aBtnLayout->addStretch();
346 myField->updateGUI();
347 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
349 myPortCanvas->getMain()->lockedGraph(true);
355 SUPERVGUI_GetValueDlg::~SUPERVGUI_GetValueDlg() {
359 * Set entered value into port and then closes and destroys dialog
361 void SUPERVGUI_GetValueDlg::accept() {
362 if ( myField->setNewValue() ) {
364 myPortCanvas->sync();
366 // asv : 19.11.04 : fix for 6170, last comment of it about BrowsePort - update node status
367 // asv : 13.12.04 : commented out sync() of Node. See 2.21.
368 //if ( myPortCanvas->parent() && myPortCanvas->parent()->inherits( "SUPERVGUI_CanvasNode" ) ) {
369 // SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*)myPortCanvas->parent();
373 myPortCanvas->getMain()->getCanvas()->update();
376 if ( QMessageBox::warning( QAD_Application::getDesktop(),
377 tr( "ERROR" ), tr( "MSG_CANT_SETVAL" ),
378 QMessageBox::Retry, QMessageBox::Abort) == QMessageBox::Retry )
382 myPortCanvas->getMain()->lockedGraph(false);
389 * Closes and destroys dialog
391 void SUPERVGUI_GetValueDlg::reject() {
392 myPortCanvas->getMain()->lockedGraph(false);
398 * Slot, called when selection is changed
400 void SUPERVGUI_GetValueDlg::onSelectionChanged()
402 if( mySelection->IObjectCount() == 1 ) {
403 Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
404 if ( anIO->hasEntry() ) {
405 SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
406 getStudyDocument()->FindObjectID( anIO->getEntry() );
408 SALOMEDS::GenericAttribute_var anAttr;
409 SALOMEDS::AttributeIOR_var anIOR;
410 Standard_CString ior = "";
412 if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
413 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
414 ior = anIOR->Value();
417 ior = aObj->GetStudy()->ConvertObjectToIOR( aObj );
419 myField->setData( ior );
426 // ----------------------------
428 // ----------------------------
430 SUPERVGUI_StreamInDlg::SUPERVGUI_StreamInDlg(SUPERVGUI_CanvasStreamPortIn* thePort)
431 :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
433 myPortCanvas = thePort;
437 void SUPERVGUI_StreamInDlg::init()
439 setSizeGripEnabled( true );
440 setCaption( tr( "MSG_STREAM_DLG_TIT" ) );
442 QVBoxLayout* TopLayout = new QVBoxLayout( this, 11, 6 );
444 QFrame* aCtrlPane = new QFrame(this);
445 QGridLayout* aCtrlLayout = new QGridLayout( aCtrlPane, 4, 10 );
448 QLabel* aSchemaLbl = new QLabel(tr("MSG_STREAM_SCHEMA"),aCtrlPane);
449 aCtrlLayout->addWidget(aSchemaLbl, 0, 0);
451 mySchemaCombo = new QComboBox(aCtrlPane, "SchemaBox" );
452 mySchemaCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
453 mySchemaCombo->insertItem("SCHENULL");
454 mySchemaCombo->insertItem("TI");
455 mySchemaCombo->insertItem("TF");
456 mySchemaCombo->insertItem("DELTA");
457 aCtrlLayout->addWidget(mySchemaCombo, 0, 1);
460 QLabel* aInterLbl = new QLabel(tr("MSG_STREAM_INTER"),aCtrlPane);
461 aCtrlLayout->addWidget(aInterLbl, 1, 0);
463 myInterCombo = new QComboBox(aCtrlPane, "InterBox" );
464 myInterCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
465 myInterCombo->insertItem("INTERNULL");
466 myInterCombo->insertItem("L0");
467 myInterCombo->insertItem("L1");
468 aCtrlLayout->addWidget(myInterCombo, 1, 1);
471 QLabel* aExtraLbl = new QLabel(tr("MSG_STREAM_EXTRA"),aCtrlPane);
472 aCtrlLayout->addWidget(aExtraLbl, 2, 0);
474 myExterCombo = new QComboBox(aCtrlPane, "ExtraBox" );
475 myExterCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
476 myExterCombo->insertItem("EXTRANULL");
477 myExterCombo->insertItem("E0");
478 myExterCombo->insertItem("E1");
479 aCtrlLayout->addWidget(myExterCombo, 2, 1);
481 TopLayout->addWidget( aCtrlPane );
484 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
485 GroupButtons->setColumnLayout(0, Qt::Vertical );
486 GroupButtons->layout()->setSpacing( 0 );
487 GroupButtons->layout()->setMargin( 0 );
488 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
489 GroupButtonsLayout->setAlignment( Qt::AlignTop );
490 GroupButtonsLayout->setSpacing( 5 );
491 GroupButtonsLayout->setMargin( 8 );
493 QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
494 QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
496 GroupButtonsLayout->addWidget( okB, 0, 0 );
497 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
498 GroupButtonsLayout->addWidget( cancelB, 0, 2 );
500 TopLayout->addWidget( GroupButtons );
502 connect( okB, SIGNAL( clicked() ), this, SLOT( accept() ) );
503 connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
507 void SUPERVGUI_StreamInDlg::setData() {
508 SUPERV::KindOfSchema aSchema;
509 SUPERV::KindOfInterpolation aInterpolat;
510 SUPERV::KindOfExtrapolation aExtrapolat;
512 myPortCanvas->getStreamEngine()->Params(aSchema, aInterpolat, aExtrapolat);
514 mySchemaCombo->setCurrentItem((int)aSchema);
515 myInterCombo->setCurrentItem((int)aInterpolat);
516 myExterCombo->setCurrentItem((int)aExtrapolat);
519 void SUPERVGUI_StreamInDlg::accept() {
520 myPortCanvas->getStreamEngine()->SetParams((SUPERV::KindOfSchema) mySchemaCombo->currentItem(),
521 (SUPERV::KindOfInterpolation) myInterCombo->currentItem(),
522 (SUPERV::KindOfExtrapolation) myExterCombo->currentItem());
527 //-------------------------------------------------------------------------
528 SUPERVGUI_StreamOutDlg::SUPERVGUI_StreamOutDlg(SUPERVGUI_CanvasStreamPortOut* thePort)
529 :QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
531 myPortCanvas = thePort;
535 void SUPERVGUI_StreamOutDlg::init()
537 setSizeGripEnabled( true );
538 setCaption( tr( "MSG_STREAM_DLG_TIT" ) );
540 QVBoxLayout* TopLayout = new QVBoxLayout( this, 11, 6 );
542 QFrame* aCtrlPane = new QFrame(this);
543 QGridLayout* aCtrlLayout = new QGridLayout( aCtrlPane, 4, 10 );
545 QLabel* aLbl = new QLabel(tr("MSG_STREAM_LEVEL"),aCtrlPane);
546 aCtrlLayout->addWidget(aLbl, 0, 0);
548 myValEdit = new QLineEdit( aCtrlPane, "ValEdit" );
549 myValEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
550 myValEdit->setValidator( new QIntValidator(this) );
551 SUPERV_StreamPort aEngine = myPortCanvas->getStreamEngine();
552 myValEdit->setText(QString("%1").arg(aEngine->NumberOfValues()));
553 aCtrlLayout->addWidget(myValEdit, 0, 1);
554 TopLayout->addWidget( aCtrlPane );
557 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
558 GroupButtons->setColumnLayout(0, Qt::Vertical );
559 GroupButtons->layout()->setSpacing( 0 );
560 GroupButtons->layout()->setMargin( 0 );
561 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
562 GroupButtonsLayout->setAlignment( Qt::AlignTop );
563 GroupButtonsLayout->setSpacing( 5 );
564 GroupButtonsLayout->setMargin( 8 );
566 QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
567 QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
569 GroupButtonsLayout->addWidget( okB, 0, 0 );
570 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
571 GroupButtonsLayout->addWidget( cancelB, 0, 2 );
573 TopLayout->addWidget( GroupButtons );
575 connect( okB, SIGNAL( clicked() ), this, SLOT( accept() ) );
576 connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
579 void SUPERVGUI_StreamOutDlg::accept() {
581 QString aStr = myValEdit->text();
583 aRes = aStr.toLong();
584 myPortCanvas->getStreamEngine()->SetNumberOfValues(aRes);