Salome HOME
Update copyright information
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_BrowseNodeDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SUPERV SUPERVGUI : GUI for Supervisor component
23 //  File   : SUPERVGUI_BrowseNodeDlg.cxx
24 //  Author : Vitaly SMETANNIKOV
25 //  Module : SUPERV
26 //
27 #include "SALOMEDSClient.hxx"
28 #include "SALOMEDS_SObject.hxx"
29 #include "SALOMEDS_Study.hxx"
30
31 #include "SalomeApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33 #include "SalomeApp_Study.h"
34 #include "SUIT_Session.h"
35
36 #include "SALOME_ListIO.hxx"
37
38 #include "SUPERVGUI_BrowseNodeDlg.h"
39 #include "SUPERVGUI_CanvasNode.h"
40 #include "SUPERVGUI_CanvasPort.h"
41 #include "SUPERVGUI.h"
42
43 #include <qlayout.h>
44 #include <qlabel.h>
45 #include <qlineedit.h>
46 #include <qpushbutton.h>
47 #include <qhbox.h>
48 #include <qgroupbox.h>
49 #include <qvalidator.h>
50
51 #include <boost/shared_ptr.hpp>
52 using namespace boost;
53
54 /**
55  * Constructor
56  */
57 SUPERVGUI_PortField::SUPERVGUI_PortField( QWidget* theParent, SUPERV_Port thePort ) {
58   myPort = thePort;
59   myIsEditable = myPort->IsInput() && ( !myPort->IsLinked() );
60
61   QString aLabelTxt(myPort->Name());
62
63   /*SUPERV_CNode aNode = myPort->Node();
64   SALOME_ModuleCatalog::Service* aService = aNode->Service();
65   SALOME_ModuleCatalog::ListOfServicesParameter aList;
66   aList = (myPort->IsInput())? aService->ServiceinParameter : aService->ServiceoutParameter;
67   for (int i = 0; i < aList.length(); i++) {
68     SALOME_ModuleCatalog::ServicesParameter* aParam = &(aList[i]);
69     if (aLabelTxt == aParam->Parametername) {
70       aLabelTxt += QString(" (") + QString(aParam->Parametertype) + QString(")");
71       break;
72     }
73   }
74   aLabelTxt += QString(":");*/
75
76   // mkr : the following way is easyer to get ports' type than commented above
77   QString aPortType = QString(myPort->Type());
78   aLabelTxt += QString(" (") + aPortType + QString("):");
79
80   myLabel = new QLabel(aLabelTxt, theParent );
81
82   myValue = new QLineEdit( theParent );
83   myLabel->setBuddy( myValue );
84   if (!myIsEditable) {
85     myValue->setReadOnly( !myIsEditable );
86     QPalette aPalette = myValue->palette();
87     aPalette.setInactive(aPalette.disabled());
88     aPalette.setActive(aPalette.disabled());
89     myValue->setPalette(aPalette);
90   }
91   // mkr : PAL6276 -->
92   else {
93     if ( !aPortType.compare(QString("boolean")) )
94       myValue->setValidator( new QIntValidator( 0, 1, theParent ) );
95
96     if ( !aPortType.compare(QString("short")) || !aPortType.compare(QString("int")) || !aPortType.compare(QString("long")) )
97       myValue->setValidator( new QIntValidator( theParent ) );
98     
99     if ( !aPortType.compare(QString("float")) || !aPortType.compare(QString("double")) )
100       myValue->setValidator( new QDoubleValidator( theParent ) );
101
102     if ( !aPortType.compare(QString("char")) ) {
103       QRegExp aRX( "." );
104       myValue->setValidator( new QRegExpValidator( aRX, theParent ) );
105
106     }
107   }
108   // mkr : PAL6276 <--
109   myValue->installEventFilter( this );
110 }
111
112 /**
113  * Sets value from text edit control to engine of port
114  */
115 bool SUPERVGUI_PortField::setNewValue() {
116   if ( !myIsEditable ) return false;
117
118   QString aTxt = myValue->text();
119   //mkr : fix for bug IPAL9441
120   //if ( aTxt.isNull() || aTxt.isEmpty() ) return false;
121   
122   if ( aTxt.find( "Unknown" ) < 0 ) {
123     SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
124     if ( !aSupMod ) {
125       MESSAGE("NULL Supervision module!");
126       return false;
127     }
128     return myPort->Input( aSupMod->getEngine()->StringValue( aTxt ) );
129   }
130   return false;
131 }
132  
133 /** 
134  * Event filter
135  */ 
136 bool SUPERVGUI_PortField::eventFilter( QObject* o, QEvent* e )
137 {
138   if ( o == myValue ) {
139     if ( e->type() == QEvent::FocusIn ) {
140       emit activated();
141     }
142   }
143   return QObject::eventFilter( o, e );
144 }
145
146
147 /**
148  * Constructor (SUPERVGUI_CanvasNode)
149  */
150 SUPERVGUI_BrowseNodeDlg::SUPERVGUI_BrowseNodeDlg( SUPERVGUI_CanvasNode* theNode )
151   : QDialog( SUIT_Session::session()->activeApplication()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
152 {
153   myNodeCanvas = theNode;
154
155   init();
156 }
157
158 void SUPERVGUI_BrowseNodeDlg::init()
159 {
160   myActiveField = 0;
161   setSizeGripEnabled( true );
162   myPortsList.setAutoDelete( true );
163
164   SUPERV_CNode aEngine = myNodeCanvas->getEngine();
165   
166   setName( "SUPERVGUI_BrowseNodeDlg" );
167   setCaption( tr( "TIT_BROWSENODE" ) + aEngine->Name() );
168
169   QGridLayout* aBaseLayout = new QGridLayout( this );
170   aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
171
172   QGroupBox* aInBox = new QGroupBox( 2, Qt::Horizontal, "Input", this );
173   aInBox->setMargin( 11 );
174   aBaseLayout->addWidget( aInBox, 0, 0 );
175
176   QGroupBox* aOutBox = new QGroupBox( 2, Qt::Horizontal, "Output", this);
177   aOutBox->setMargin( 11 );
178   aBaseLayout->addWidget( aOutBox, 0, 1 );
179
180   myIsEditable = false;
181   int                aPIcount = 0;
182   int                aPOcount = 0;
183   SUPERV_Ports       ports = aEngine->Ports();
184   int                n     = ports->length();
185
186   for ( int i = 0; i < n; i++ ) {
187     if ( ports[i]->IsInput() ) {
188       if ( !ports[i]->IsGate() ) { // not a gate
189         SUPERVGUI_PortField* aField = new SUPERVGUI_PortField( aInBox, ports[i] );
190         if ( aField->isEditable() ) 
191           myIsEditable = true;
192         myPortsList.append( aField );
193         if ( !myActiveField )
194           myActiveField = aField;
195         connect( aField, SIGNAL( activated() ), this, SLOT( onFieldActivated() ) );
196       }
197       aPIcount++;
198     } 
199     else {
200       if ( !ports[i]->IsGate() ) { // not a gate
201         myPortsList.append( new SUPERVGUI_PortField( aOutBox, ports[i] ) );
202       }
203       aPOcount++;
204     }
205   }
206   
207   QGroupBox* aBtnBox = new QGroupBox( this );
208   aBtnBox->setColumnLayout( 0, Qt::Vertical );
209   aBtnBox->layout()->setSpacing( 0 ); 
210   aBtnBox->layout()->setMargin( 0 );
211   
212   QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
213   aBtnLayout->setAlignment( Qt::AlignTop );
214   aBtnLayout->setSpacing( 6 ); 
215   aBtnLayout->setMargin( 11 );
216
217   if ( myIsEditable ) {
218     QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), this );
219     aBaseLayout->addMultiCellWidget( aInfoLab, 1, 1, 0, 1 );
220
221     QPushButton* aOkBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
222     connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
223     aBtnLayout->addWidget( aOkBtn );
224     aBaseLayout->addMultiCellWidget( aBtnBox, 2, 2, 0, 1 );
225   } else
226     aBaseLayout->addMultiCellWidget( aBtnBox, 1, 1, 0, 1 );
227
228   aBtnLayout->addStretch();
229   QPushButton* aCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
230   aBtnLayout->addWidget( aCancelBtn );
231   connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
232   
233   if ( !myIsEditable )
234     aBtnLayout->addStretch();
235
236   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
237   if ( aSupMod ) connect( (( SalomeApp_Application* )(aSupMod->getActiveStudy()->application()))->selectionMgr(), 
238                           SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
239   else MESSAGE("NULL Supervision module!");
240   
241   myNodeCanvas->getMain()->lockedGraph(true);
242 }
243
244 /**
245  * Destructor
246  */
247 SUPERVGUI_BrowseNodeDlg::~SUPERVGUI_BrowseNodeDlg() {
248 }
249
250 /**
251  * Set current values of editable ports
252  */
253 void SUPERVGUI_BrowseNodeDlg::setValues() {
254   SUPERVGUI_PortField* aField;
255   for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
256     if ( aField->getData().isEmpty() || aField->getData().isNull() ) // mkr : PAL11406
257       aField->updateGUI();
258   }
259 }
260
261 /** 
262  * Set inputed values of editable ports and then closes and destroys dialog
263  */
264 void SUPERVGUI_BrowseNodeDlg::accept() {
265   myNodeCanvas->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
266   if ( myIsEditable ) {
267     SUPERVGUI_PortField* aField;
268     for ( aField = myPortsList.first(); aField; aField = myPortsList.next() ) {
269       aField->setNewValue();
270     }
271     myNodeCanvas->sync();
272     myNodeCanvas->getMain()->getCanvas()->update();
273   }
274   myNodeCanvas->getMain()->lockedGraph(false);
275   QDialog::accept();
276   close();
277 }
278
279
280 /** 
281  * Closes and destroys dialog
282  */
283 void SUPERVGUI_BrowseNodeDlg::reject() {
284   myNodeCanvas->getMain()->lockedGraph(false);
285   QDialog::reject();
286   close();
287 }
288
289 /**
290  * Update current values on show event
291  */
292 void SUPERVGUI_BrowseNodeDlg::showEvent( QShowEvent* theEvent ) {
293   setValues();
294   QDialog::showEvent( theEvent );
295 }
296
297 /**
298  * Slot, called when field is focused
299  */
300 void SUPERVGUI_BrowseNodeDlg::onFieldActivated()
301 {
302   SUPERVGUI_PortField* aField = (SUPERVGUI_PortField*)sender();
303   myActiveField = (aField->isEditable())? aField : 0;
304 }
305
306 namespace {
307
308   QString getIORfromIO (const Handle(SALOME_InteractiveObject)& theIO,
309                         SUPERVGUI * theModule)
310   {
311     QString ior ("");
312     if (!theIO->hasEntry()) return ior;
313
314     SalomeApp_Study* anAppStudy = dynamic_cast<SalomeApp_Study*>(theModule->getActiveStudy());
315     _PTR(SObject) aSObj (anAppStudy->studyDS()->FindObjectID(theIO->getEntry()));
316
317     _PTR(GenericAttribute) anAttr;
318     if (aSObj->FindAttribute(anAttr, "AttributeIOR")) {
319       _PTR(AttributeIOR) anIOR (anAttr);
320       ior = anIOR->Value().c_str();
321       return ior;
322     }
323
324     // old code, it is useless, because <aSSObj->GetObject()> here will be NULL
325     // (because it is retrieved from <aSSObj> by stored IOR)
326     /*
327       SALOMEDS_Study* aSStudy = dynamic_cast<SALOMEDS_Study*>( aSObj->GetStudy().get() );
328       SALOMEDS_SObject* aSSObj = dynamic_cast<SALOMEDS_SObject*>( aSObj.get() );
329       if ( aSStudy && aSSObj )
330       ior = aSStudy->ConvertObjectToIOR( aSSObj->GetObject() ).c_str();
331     //*/
332
333     // new code
334
335     // default value: null IOR (IOR:01000000010000000000...)
336     SalomeApp_Application* anApp = theModule->getApp();
337     CORBA::Object_var aNullObj;
338     ior = anApp->orb()->object_to_string(aNullObj);
339
340     // try to load a component data from an opened (presumably) study
341     _PTR(SComponent) aSComp = aSObj->GetFatherComponent();
342     std::string aCompIOR;
343     if (!aSComp->ComponentIOR(aCompIOR)) {
344       std::string aCompDataType = aSComp->ComponentDataType();
345
346       // obtain a driver by a component data type
347       // like it is done in SALOMEDS_DriverFactory_i::GetDriverByType
348       SALOMEDS::Driver_var anEngine = SALOMEDS::Driver::_nil();
349       SALOME_LifeCycleCORBA * LCC = anApp->lcc();
350       try {
351         CORBA::Object_var
352           anEngineObj = LCC->FindOrLoad_Component("FactoryServer", aCompDataType.c_str());
353         if (CORBA::is_nil(anEngineObj))
354           anEngineObj = LCC->FindOrLoad_Component("FactoryServerPy", aCompDataType.c_str());
355
356         if (!CORBA::is_nil(anEngineObj))
357           anEngine = SALOMEDS::Driver::_narrow(anEngineObj);
358       }
359       catch (...) {
360       }
361
362       if (!CORBA::is_nil(anEngine)) {
363         // try to load
364         _PTR(StudyBuilder) aStudyBuilder = aSObj->GetStudy()->NewBuilder();
365         bool isOk = true;
366         try {
367           CORBA::String_var aDriverIOR = anApp->orb()->object_to_string(anEngine);
368           aStudyBuilder->LoadWith(aSComp, aDriverIOR.in());
369         }
370         catch (...) {
371           isOk = false;
372         }
373
374         if (isOk) {
375           // now try to obtain the IOR once again (after successfull component data loading)
376           if (aSObj->FindAttribute( anAttr, "AttributeIOR" )) {
377             _PTR(AttributeIOR) anIOR ( anAttr );
378             ior = anIOR->Value().c_str();
379           }
380         }
381       } // if (!CORBA::is_nil(anEngine))
382     } // if (!aSComp->ComponentIOR(aCompIOR))
383
384     return ior;
385   }
386
387 } // no name namespace
388
389 /**
390  * Slot, called when selection is changed
391  */
392 void SUPERVGUI_BrowseNodeDlg::onSelectionChanged()
393 {
394   if ( myActiveField ) {
395
396     SALOME_ListIO aList;
397     aList.Clear();
398
399     SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
400     if ( !aSupMod ) {
401       MESSAGE("NULL Supervision module!");
402       return;
403     }
404
405     SalomeApp_Application* anApp = aSupMod->getApp();
406     anApp->selectionMgr()->selectedObjects( aList );
407
408     if ( aList.Extent() == 1 ) {
409       Handle( SALOME_InteractiveObject ) anIO = aList.First();
410       if ( anIO->hasEntry() ) {
411         QString ior = ::getIORfromIO(anIO, aSupMod);
412         myActiveField->setData( ior );
413       }
414     }
415   }
416 }
417
418
419 /**
420  * Constructor (SUPERVGUI_CanvasPort)
421  */
422 SUPERVGUI_GetValueDlg::SUPERVGUI_GetValueDlg( SUPERVGUI_CanvasPort* thePort )
423   : QDialog( SUIT_Session::session()->activeApplication()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose )
424 {
425   myPortCanvas = thePort;
426
427   init();
428 }
429
430 void SUPERVGUI_GetValueDlg::init()
431 {
432   myOKBtn = 0;
433   setSizeGripEnabled( true );
434
435   setName( "SUPERVGUI_GetValueDlg" );
436   setCaption( tr( "TIT_SETVALUE_PORT" ) );
437   
438   QGridLayout* aBaseLayout = new QGridLayout( this );
439   aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
440   
441   QGroupBox* aBox = new QGroupBox( this );
442   aBox->setColumnLayout( 0, Qt::Vertical );
443   aBox->layout()->setSpacing( 0 ); aBox->layout()->setMargin( 0 );
444   QGridLayout* aBoxLayout = new QGridLayout( aBox->layout() );
445   aBoxLayout->setAlignment( Qt::AlignTop );
446   aBoxLayout->setSpacing( 6 ); aBoxLayout->setMargin( 11 );
447   aBaseLayout->addWidget( aBox, 0, 0 );
448   aBox->setMinimumWidth( 200 );
449   
450   QLabel* aInfoLab = new QLabel( tr( "ENTER_OR_SELECT_LBL" ), aBox );
451   QFont fnt = aInfoLab->font(); fnt.setBold( true ); aInfoLab->setFont( fnt );
452   aBoxLayout->addMultiCellWidget( aInfoLab, 0, 0, 0, 1 );
453   SUPERV_Port aEngine = myPortCanvas->getEngine();
454
455   myField = new SUPERVGUI_PortField( aBox, aEngine );
456   bool myIsEditable = myField->isEditable();
457   aBoxLayout->addWidget( myField->myLabel, 1, 0 ); 
458   aBoxLayout->addWidget( myField->myValue, 1, 1 );
459   
460   QGroupBox* aBtnBox = new QGroupBox( this );
461   aBtnBox->setColumnLayout( 0, Qt::Vertical );
462   aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
463   QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
464   aBtnLayout->setAlignment( Qt::AlignTop );
465   aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
466
467   aBaseLayout->addWidget( aBtnBox, 1, 0 );
468
469   if ( myIsEditable ) {
470     myOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
471     connect( myOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
472     aBtnLayout->addWidget( myOKBtn );
473   }
474
475   aBtnLayout->addStretch();
476   myCancelBtn = new QPushButton( myIsEditable ? tr( "BUT_CANCEL" ) : tr( "BUT_CLOSE" ), aBtnBox );
477   aBtnLayout->addWidget( myCancelBtn );
478   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
479   
480   if ( !myIsEditable )
481     aBtnLayout->addStretch();
482
483   myField->updateGUI();
484   
485   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
486   if ( aSupMod ) connect( (( SalomeApp_Application* )(aSupMod->getActiveStudy()->application()))->selectionMgr(), 
487                           SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionChanged() ) );
488   else MESSAGE("NULL Supervision module!");
489  
490   myPortCanvas->getMain()->lockedGraph(true);
491 }
492
493 /**
494  * Destructor
495  */
496 SUPERVGUI_GetValueDlg::~SUPERVGUI_GetValueDlg() {
497 }
498
499 /** 
500  * Set entered value into port and then closes and destroys dialog
501  */
502 void SUPERVGUI_GetValueDlg::accept() {
503   myPortCanvas->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
504   if ( myField->setNewValue() ) {
505     
506     myPortCanvas->sync();
507
508     // asv : 19.11.04 : fix for 6170, last comment of it about BrowsePort - update node status
509     // asv : 13.12.04 : commented out sync() of Node.  See 2.21.
510     //if ( myPortCanvas->parent() && myPortCanvas->parent()->inherits( "SUPERVGUI_CanvasNode" ) ) {
511     //  SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*)myPortCanvas->parent();
512     //  aNode->sync();
513     //}
514
515     myPortCanvas->getMain()->getCanvas()->update();
516   }
517   else {
518     if ( QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), 
519                                tr( "ERROR" ), tr( "MSG_CANT_SETVAL" ),
520                                QMessageBox::Retry, QMessageBox::Abort) == QMessageBox::Retry )
521       return;
522   }
523
524   myPortCanvas->getMain()->lockedGraph(false);
525   
526   QDialog::accept();
527   close();
528 }
529
530 /** 
531  * Closes and destroys dialog
532  */
533 void SUPERVGUI_GetValueDlg::reject() {
534   myPortCanvas->getMain()->lockedGraph(false);
535   QDialog::reject();
536   close();
537 }
538
539 /**
540  * Slot, called when selection is changed
541  */
542 void SUPERVGUI_GetValueDlg::onSelectionChanged()
543 {
544   SALOME_ListIO aList;
545   aList.Clear();
546
547   SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
548   if ( !aSupMod ) {
549     MESSAGE("NULL Supervision module!");
550     return;
551   }
552
553   SalomeApp_Application* anApp = aSupMod->getApp();
554   anApp->selectionMgr()->selectedObjects( aList );
555
556   if ( aList.Extent() == 1 ) {
557     Handle( SALOME_InteractiveObject ) anIO = aList.First();
558     if ( anIO->hasEntry() ) {
559       QString ior = ::getIORfromIO(anIO, aSupMod);
560       myField->setData( ior );
561     }
562   }
563 }
564
565
566
567 // ----------------------------
568 // Stream Ports
569 // ----------------------------
570
571 SUPERVGUI_StreamInDlg::SUPERVGUI_StreamInDlg(SUPERVGUI_CanvasStreamPortIn* thePort)
572   :QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
573 {
574   myPortCanvas = thePort;
575   init();
576 }
577
578 void SUPERVGUI_StreamInDlg::init()
579 {
580   setSizeGripEnabled( true );
581   setCaption( tr( "MSG_STREAM_DLG_TIT" ) );
582
583   QVBoxLayout* TopLayout = new QVBoxLayout( this, 11, 6 );
584
585   QFrame* aCtrlPane = new QFrame(this);
586   QGridLayout* aCtrlLayout = new QGridLayout( aCtrlPane, 4, 10 );
587
588   // Schema
589   QLabel* aSchemaLbl = new QLabel(tr("MSG_STREAM_SCHEMA"),aCtrlPane);
590   aCtrlLayout->addWidget(aSchemaLbl, 0, 0);
591
592   mySchemaCombo = new QComboBox(aCtrlPane, "SchemaBox" );
593   mySchemaCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
594   mySchemaCombo->insertItem("SCHENULL"); 
595   mySchemaCombo->insertItem("TI");  
596   mySchemaCombo->insertItem("TF");
597   mySchemaCombo->insertItem("DELTA");
598   aCtrlLayout->addWidget(mySchemaCombo, 0, 1);
599
600   // Interpolation
601   QLabel* aInterLbl = new QLabel(tr("MSG_STREAM_INTER"),aCtrlPane);
602   aCtrlLayout->addWidget(aInterLbl, 1, 0);
603
604   myInterCombo = new QComboBox(aCtrlPane, "InterBox" );
605   myInterCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
606   myInterCombo->insertItem("INTERNULL"); 
607   myInterCombo->insertItem("L0"); 
608   myInterCombo->insertItem("L1");
609   aCtrlLayout->addWidget(myInterCombo, 1, 1);
610
611   // Extrapolation
612   QLabel* aExtraLbl = new QLabel(tr("MSG_STREAM_EXTRA"),aCtrlPane);
613   aCtrlLayout->addWidget(aExtraLbl, 2, 0);
614
615   myExterCombo = new QComboBox(aCtrlPane, "ExtraBox" );
616   myExterCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
617   myExterCombo->insertItem("EXTRANULL");  
618   myExterCombo->insertItem("E0");
619   myExterCombo->insertItem("E1");
620   aCtrlLayout->addWidget(myExterCombo, 2, 1);
621   
622   TopLayout->addWidget( aCtrlPane );
623
624   // Buttons
625   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
626   GroupButtons->setColumnLayout(0, Qt::Vertical );
627   GroupButtons->layout()->setSpacing( 0 );
628   GroupButtons->layout()->setMargin( 0 );
629   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
630   GroupButtonsLayout->setAlignment( Qt::AlignTop );
631   GroupButtonsLayout->setSpacing( 5 );
632   GroupButtonsLayout->setMargin( 8 );
633   
634   QPushButton* okB     = new QPushButton( tr( "BUT_OK" ),     GroupButtons );
635   QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
636
637   GroupButtonsLayout->addWidget( okB, 0, 0 );
638   GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
639   GroupButtonsLayout->addWidget( cancelB, 0, 2 );
640
641   TopLayout->addWidget( GroupButtons );
642
643   connect( okB,     SIGNAL( clicked() ), this, SLOT( accept() ) );
644   connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
645   setData();
646 }
647
648 void SUPERVGUI_StreamInDlg::setData() {
649   SUPERV::KindOfSchema aSchema;
650   SUPERV::KindOfInterpolation aInterpolat;
651   SUPERV::KindOfExtrapolation aExtrapolat;
652
653   myPortCanvas->getStreamEngine()->Params(aSchema, aInterpolat, aExtrapolat);
654
655   mySchemaCombo->setCurrentItem((int)aSchema);
656   myInterCombo->setCurrentItem((int)aInterpolat);
657   myExterCombo->setCurrentItem((int)aExtrapolat);
658 }
659
660 void SUPERVGUI_StreamInDlg::accept() {
661   myPortCanvas->getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag 
662   myPortCanvas->getStreamEngine()->SetParams((SUPERV::KindOfSchema) mySchemaCombo->currentItem(), 
663                                              (SUPERV::KindOfInterpolation) myInterCombo->currentItem(),
664                                              (SUPERV::KindOfExtrapolation) myExterCombo->currentItem());
665   QDialog::accept();
666 }
667
668
669 //-------------------------------------------------------------------------
670 SUPERVGUI_StreamOutDlg::SUPERVGUI_StreamOutDlg(SUPERVGUI_CanvasStreamPortOut* thePort)
671   :QDialog( SUIT_Session::session()->activeApplication()->desktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
672 {
673   myPortCanvas = thePort;
674   init();
675 }
676
677 void SUPERVGUI_StreamOutDlg::init()
678 {
679   setSizeGripEnabled( true );
680   setCaption( tr( "MSG_STREAM_DLG_TIT" ) );
681
682   QVBoxLayout* TopLayout = new QVBoxLayout( this, 11, 6 );
683
684   QFrame* aCtrlPane = new QFrame(this);
685   QGridLayout* aCtrlLayout = new QGridLayout( aCtrlPane, 4, 10 );
686
687   QLabel* aLbl = new QLabel(tr("MSG_STREAM_LEVEL"),aCtrlPane);
688   aCtrlLayout->addWidget(aLbl, 0, 0);
689
690   myValEdit = new QLineEdit( aCtrlPane, "ValEdit" );
691   myValEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
692   myValEdit->setValidator( new QIntValidator(this) );
693   SUPERV_StreamPort aEngine = myPortCanvas->getStreamEngine();
694   myValEdit->setText(QString("%1").arg(aEngine->NumberOfValues()));
695   aCtrlLayout->addWidget(myValEdit, 0, 1);
696   TopLayout->addWidget( aCtrlPane );
697   
698   // Buttons
699   QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
700   GroupButtons->setColumnLayout(0, Qt::Vertical );
701   GroupButtons->layout()->setSpacing( 0 );
702   GroupButtons->layout()->setMargin( 0 );
703   QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
704   GroupButtonsLayout->setAlignment( Qt::AlignTop );
705   GroupButtonsLayout->setSpacing( 5 );
706   GroupButtonsLayout->setMargin( 8 );
707   
708   QPushButton* okB     = new QPushButton( tr( "BUT_OK" ),     GroupButtons );
709   QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
710
711   GroupButtonsLayout->addWidget( okB, 0, 0 );
712   GroupButtonsLayout->addItem  ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
713   GroupButtonsLayout->addWidget( cancelB, 0, 2 );
714
715   TopLayout->addWidget( GroupButtons );
716
717   connect( okB,     SIGNAL( clicked() ), this, SLOT( accept() ) );
718   connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
719 }
720
721 void SUPERVGUI_StreamOutDlg::accept() {
722   int aRes = 0;
723   QString aStr = myValEdit->text();
724   if (!aStr.isEmpty())
725     aRes = aStr.toLong();
726   myPortCanvas->getStreamEngine()->SetNumberOfValues(aRes);
727   QDialog::accept();
728 }
729