2 // File : SUPERVGUI_BrowseNodeDlg.cxx
3 // Created : 10 / 01 / 2003
4 // Author : Vitaly SMETANNIKOV
7 // Copyright : Open CASCADE
10 #include "SUPERVGUI_BrowseNodeDlg.h"
11 #include "SUPERVGUI_Node.h"
12 #include "SUPERVGUI.h"
15 #include <qlineedit.h>
16 #include <qpushbutton.h>
18 #include <qgroupbox.h>
23 SUPERVGUI_PortField::SUPERVGUI_PortField( QWidget* theParent, SUPERV_Port thePort ) {
25 myIsEditable = myPort->IsInput() && ( !myPort->IsLinked() );
27 QString aLabelTxt(myPort->Name());
29 SUPERV_CNode aNode = myPort->Node();
30 SALOME_ModuleCatalog::Service* aService = aNode->Service();
31 SALOME_ModuleCatalog::ListOfServicesParameter aList;
32 aList = (myPort->IsInput())? aService->ServiceinParameter : aService->ServiceoutParameter;
33 for (int i = 0; i < aList.length(); i++) {
34 SALOME_ModuleCatalog::ServicesParameter* aParam = &(aList[i]);
35 if (aLabelTxt == aParam->Parametername) {
36 aLabelTxt += QString(" (") + QString(aParam->Parametertype) + QString(")");
41 aLabelTxt += QString(":");
42 myLabel = new QLabel(aLabelTxt, theParent );
44 myValue = new QLineEdit( theParent );
45 myLabel->setBuddy( myValue );
47 myValue->setReadOnly( !myIsEditable );
48 QPalette aPalette = myValue->palette();
49 aPalette.setInactive(aPalette.disabled());
50 aPalette.setActive(aPalette.disabled());
51 myValue->setPalette(aPalette);
53 myValue->installEventFilter( this );
57 * Sets value from text edit control to engine of port
59 bool SUPERVGUI_PortField::setNewValue() {
60 if ( !myIsEditable ) return false;
62 QString aTxt = myValue->text();
63 if ( aTxt.isNull() || aTxt.isEmpty() ) return false;
65 if ( aTxt.find( "Unknown" ) < 0 ) {
66 return myPort->Input( ( *Supervision.getEngine() )->StringValue( aTxt ) );
74 bool SUPERVGUI_PortField::eventFilter( QObject* o, QEvent* e )
77 if ( e->type() == QEvent::FocusIn ) {
81 return QObject::eventFilter( o, e );
88 SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_Node* theNode )
89 : QDialog( theNode, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
92 setSizeGripEnabled( true );
94 myPortsList.setAutoDelete( true );
96 SUPERV_CNode aEngine = myNode->getEngine();
97 mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
98 // mySelection->ClearIObjects();
100 setName( "SUPERVGUI_BrowseNodeDlg" );
101 setCaption( tr( "TIT_BROWSENODE" ) + aEngine->Name() );
103 QGridLayout* aBaseLayout = new QGridLayout( this );
104 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
106 QGroupBox* aInBox = new QGroupBox( 2, Qt::Horizontal, "Input", this );
107 aInBox->setMargin( 11 );
108 aBaseLayout->addWidget( aInBox, 0, 0 );
110 QGroupBox* aOutBox = new QGroupBox( 2, Qt::Horizontal, "Output", this);
111 aOutBox->setMargin( 11 );
112 aBaseLayout->addWidget( aOutBox, 0, 1 );
114 myIsEditable = false;
117 SUPERV_Ports ports = aEngine->Ports();
118 int n = ports->length();
120 for ( int i = 0; i < n; i++ ) {
121 if ( ports[i]->IsInput() ) {
122 if ( !ports[i]->IsGate() ) { // not a gate
123 SUPERVGUI_PortField* aField = new SUPERVGUI_PortField( aInBox, ports[i] );
124 if ( aField->isEditable() ) myIsEditable = true;
125 myPortsList.append( aField );
126 if ( !myActiveField )
127 myActiveField = aField;
128 connect( aField, SIGNAL( activated() ), this, SLOT( onFieldActivated() ) );
133 if ( !ports[i]->IsGate() ) { // not a gate
134 myPortsList.append( new SUPERVGUI_PortField( aOutBox, ports[i] ) );
140 QGroupBox* aBtnBox = new QGroupBox( this );
141 aBtnBox->setColumnLayout( 0, Qt::Vertical );
142 aBtnBox->layout()->setSpacing( 0 );
143 aBtnBox->layout()->setMargin( 0 );
145 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
146 aBtnLayout->setAlignment( Qt::AlignTop );
147 aBtnLayout->setSpacing( 6 );
148 aBtnLayout->setMargin( 11 );
150 if ( myIsEditable ) {
151 QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), this );
152 aBaseLayout->addMultiCellWidget( aInfoLab, 1, 1, 0, 1 );
154 QPushButton* aOkBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
155 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
156 aBtnLayout->addWidget( aOkBtn );
157 aBaseLayout->addMultiCellWidget( aBtnBox, 2, 2, 0, 1 );
159 aBaseLayout->addMultiCellWidget( aBtnBox, 1, 1, 0, 1 );
161 aBtnLayout->addStretch();
162 QPushButton* aCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
163 aBtnLayout->addWidget( aCancelBtn );
164 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
167 aBtnLayout->addStretch();
169 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
170 myNode->getMain()->lockedGraph(true);
176 SUPERVGUI_BrowseNodeDlg::~SUPERVGUI_BrowseNodeDlg() {
180 * Set current values of editable ports
182 void SUPERVGUI_BrowseNodeDlg::setValues() {
183 SUPERVGUI_PortField* aField;
184 for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
190 * Set inputed values of editable ports and then closes and destroys dialog
192 void SUPERVGUI_BrowseNodeDlg::accept() {
193 if ( myIsEditable ) {
194 SUPERVGUI_PortField* aField;
195 for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
196 aField->setNewValue();
200 myNode->getMain()->lockedGraph(false);
207 * Closes and destroys dialog
209 void SUPERVGUI_BrowseNodeDlg::reject() {
210 myNode->getMain()->lockedGraph(false);
216 * Update current values on show event
218 void SUPERVGUI_BrowseNodeDlg::showEvent( QShowEvent* theEvent ) {
220 QDialog::showEvent( theEvent );
224 * Slot, called when field is focused
226 void SUPERVGUI_BrowseNodeDlg::onFieldActivated()
228 SUPERVGUI_PortField* aField = (SUPERVGUI_PortField*)sender();
229 myActiveField = (aField->isEditable())? aField : 0;
235 * Slot, called when selection is changed
237 void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
239 if ( myActiveField ) {
240 if( mySelection->IObjectCount() == 1 ) {
241 Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
242 if ( anIO->hasEntry() ) {
243 SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
244 getStudyDocument()->FindObjectID( anIO->getEntry() );
246 SALOMEDS::GenericAttribute_var anAttr;
247 SALOMEDS::AttributeIOR_var anIOR;
248 Standard_CString ior = "";
250 if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
251 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
252 ior = anIOR->Value();
253 myActiveField->setData( ior );
263 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortIn* thePort )
264 : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
267 setSizeGripEnabled( true );
271 mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
272 // mySelection->ClearIObjects();
274 setName( "SUPERVGUI_GetValueDlg" );
275 setCaption( tr( "TIT_SETVALUE_PORT" ) );
277 QGridLayout* aBaseLayout = new QGridLayout( this );
278 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
280 QGroupBox* aBox = new QGroupBox( this );
281 aBox->setColumnLayout( 0, Qt::Vertical );
282 aBox->layout()->setSpacing( 0 ); aBox->layout()->setMargin( 0 );
283 QGridLayout* aBoxLayout = new QGridLayout( aBox->layout() );
284 aBoxLayout->setAlignment( Qt::AlignTop );
285 aBoxLayout->setSpacing( 6 ); aBoxLayout->setMargin( 11 );
286 aBaseLayout->addWidget( aBox, 0, 0 );
287 aBox->setMinimumWidth( 200 );
289 QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), aBox );
290 QFont fnt = aInfoLab->font(); fnt.setBold( true ); aInfoLab->setFont( fnt );
291 aBoxLayout->addMultiCellWidget( aInfoLab, 0, 0, 0, 1 );
292 myField = new SUPERVGUI_PortField( aBox, myPort->getPort() );
293 bool myIsEditable = myField->isEditable();
294 aBoxLayout->addWidget( myField->myLabel, 1, 0 );
295 aBoxLayout->addWidget( myField->myValue, 1, 1 );
297 QGroupBox* aBtnBox = new QGroupBox( this );
298 aBtnBox->setColumnLayout( 0, Qt::Vertical );
299 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
300 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
301 aBtnLayout->setAlignment( Qt::AlignTop );
302 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
304 aBaseLayout->addWidget( aBtnBox, 1, 0 );
306 if ( myIsEditable ) {
307 myOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
308 connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
309 aBtnLayout->addWidget( myOKBtn );
312 aBtnLayout->addStretch();
313 myCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
314 aBtnLayout->addWidget( myCancelBtn );
315 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
318 aBtnLayout->addStretch();
320 myField->updateGUI();
321 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
322 myPort->getMain()->lockedGraph(true);
328 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_PortInESNode* thePort )
329 : QDialog( thePort, 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
332 setSizeGripEnabled( true );
334 myPortESNode = thePort;
336 mySelection = SALOME_Selection::Selection( Supervision.getActiveStudy()->getSelection() );
337 // mySelection->ClearIObjects();
339 setName( "SUPERVGUI_GetValueDlg" );
340 setCaption( tr( "TIT_SETVALUE_PORT" ) );
342 QGridLayout* aBaseLayout = new QGridLayout( this );
343 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
345 QGroupBox* aBox = new QGroupBox( this );
346 aBox->setColumnLayout( 0, Qt::Vertical );
347 aBox->layout()->setSpacing( 0 ); aBox->layout()->setMargin( 0 );
348 QGridLayout* aBoxLayout = new QGridLayout( aBox->layout() );
349 aBoxLayout->setAlignment( Qt::AlignTop );
350 aBoxLayout->setSpacing( 6 ); aBoxLayout->setMargin( 11 );
351 aBaseLayout->addWidget( aBox, 0, 0 );
352 aBox->setMinimumWidth( 200 );
354 QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), aBox );
355 QFont fnt = aInfoLab->font(); fnt.setBold( true ); aInfoLab->setFont( fnt );
356 aBoxLayout->addMultiCellWidget( aInfoLab, 0, 0, 0, 1 );
357 myField = new SUPERVGUI_PortField( aBox, myPortESNode->getPort() );
358 bool myIsEditable = myField->isEditable();
359 aBoxLayout->addWidget( myField->myLabel, 1, 0 );
360 aBoxLayout->addWidget( myField->myValue, 1, 1 );
362 QGroupBox* aBtnBox = new QGroupBox( this );
363 aBtnBox->setColumnLayout( 0, Qt::Vertical );
364 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
365 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
366 aBtnLayout->setAlignment( Qt::AlignTop );
367 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
369 aBaseLayout->addWidget( aBtnBox, 1, 0 );
371 if ( myIsEditable ) {
372 myOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
373 connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
374 aBtnLayout->addWidget( myOKBtn );
377 aBtnLayout->addStretch();
378 myCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
379 aBtnLayout->addWidget( myCancelBtn );
380 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
383 aBtnLayout->addStretch();
385 myField->updateGUI();
386 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
387 myPortESNode->getMain()->lockedGraph(true);
393 SUPERVGUI_GetValueDlg::~SUPERVGUI_GetValueDlg() {
397 * Set entered value into port and then closes and destroys dialog
399 void SUPERVGUI_GetValueDlg::accept() {
400 if ( myField->setNewValue() ) {
405 myPortESNode->sync();
408 if ( QMessageBox::warning( QAD_Application::getDesktop(),
409 tr( "ERROR" ), tr( "MSG_CANT_SETVAL" ),
410 QMessageBox::Retry, QMessageBox::Abort) == QMessageBox::Retry )
415 myPort->getMain()->lockedGraph(false);
417 myPortESNode->getMain()->lockedGraph(false);
423 * Closes and destroys dialog
425 void SUPERVGUI_GetValueDlg::reject() {
427 myPort->getMain()->lockedGraph(false);
429 myPortESNode->getMain()->lockedGraph(false);
435 * Slot, called when selection is changed
437 void SUPERVGUI_GetValueDlg::onSelectionChanged()
439 if( mySelection->IObjectCount() == 1 ) {
440 Handle( SALOME_InteractiveObject ) anIO = mySelection->firstIObject();
441 if ( anIO->hasEntry() ) {
442 SALOMEDS::SObject_var aObj = Supervision.getActiveStudy()->
443 getStudyDocument()->FindObjectID( anIO->getEntry() );
445 SALOMEDS::GenericAttribute_var anAttr;
446 SALOMEDS::AttributeIOR_var anIOR;
447 Standard_CString ior = "";
449 if (aObj->FindAttribute( anAttr, "AttributeIOR" ) ) {
450 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
451 ior = anIOR->Value();
452 myField->setData( ior );