1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <PythonNode.hxx>
24 #include <SALOME_ResourcesManager.hxx>
25 #include <SALOME_LifeCycleCORBA.hxx>
27 #include <YACSGui_InputPanel.h>
28 #include <YACSGui_Module.h>
29 #include <YACSGui_PlusMinusGrp.h>
30 #include <YACSGui_Table.h>
31 #include <YACSGui_Graph.h>
32 #include <YACSGui_Executor.h>
33 #include <YACSGui_TreeView.h>
34 #include <YACSGui_TreeViewItem.h>
35 #include <YACSGui_LogViewer.h>
37 #include <YACSPrs_ElementaryNode.h>
39 #include <QxGraph_Canvas.h>
41 #include <LightApp_Application.h>
42 #include <CAM_Application.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_Application.h>
45 #include <SUIT_MessageBox.h>
46 #include <LogWindow.h>
49 #include <OutPort.hxx>
50 #include <InputPort.hxx>
51 #include <OutputPort.hxx>
52 #include <CalStreamPort.hxx>
53 #include <ConditionInputPort.hxx>
54 #include <ForLoop.hxx>
55 #include <ForEachLoop.hxx>
56 #include <WhileLoop.hxx>
58 #include <CORBAPorts.hxx>
59 #include <PythonPorts.hxx>
60 #include <XMLPorts.hxx>
61 #include <InlineNode.hxx>
62 #include <ServiceNode.hxx>
63 #include <ServiceInlineNode.hxx>
64 #include <CORBANode.hxx>
65 #include <SalomePythonNode.hxx>
66 #include <CppNode.hxx>
67 #include <XMLNode.hxx>
68 #include <Exception.hxx>
69 #include <Catalog.hxx>
70 #include <ComponentDefinition.hxx>
71 #include <CORBAComponent.hxx>
72 #include <CppComponent.hxx>
73 #include <SalomeComponent.hxx>
74 #include <SalomePythonComponent.hxx>
75 #include <RuntimeSALOME.hxx>
77 #include <qwindowsstyle.h>
78 #include <qpushbutton.h>
82 #include <qlineedit.h>
83 #include <qbuttongroup.h>
84 #include <qradiobutton.h>
85 #include <qcombobox.h>
86 #include <qtextedit.h>
87 #include <qtoolbutton.h>
89 #include <qprogressbar.h>
90 #include <qobjectlist.h>
91 #include <qfiledialog.h>
92 #include <qcheckbox.h>
97 #include "YacsTrace.hxx"
102 using namespace YACS;
103 using namespace YACS::ENGINE;
104 using namespace YACS::HMI;
109 Class : YACSGui_ServiceNodePage
110 Description : Page for SALOME and CORBA service nodes properties
113 YACSGui_ServiceNodePage::YACSGui_ServiceNodePage( QWidget* theParent, const char* theName, WFlags theFlags )
114 : ServiceNodePage( theParent, theName, theFlags ),
119 // the possibility to search is hided according to the Num. 14 from NEWS file
123 //#undef HAVE_QEXTSCINTILLA_H
124 #ifdef HAVE_QEXTSCINTILLA_H
125 _myTextEdit = new QextScintilla( InPythonEditorGroupBox, "Python Editor" );
126 _myTextEdit->setMinimumHeight(150);
127 InPythonEditorGroupBoxLayout->insertWidget(InPythonEditorGroupBoxLayout->findWidget(myTextEdit),
129 InPythonEditorGroupBoxLayout->remove(myTextEdit);
131 _myTextEdit->setUtf8(1);
132 QextScintillaLexerPython *lex = new QextScintillaLexerPython(_myTextEdit);
133 _myTextEdit->setLexer(lex);
134 _myTextEdit->setBraceMatching(QextScintilla::SloppyBraceMatch);
135 _myTextEdit->setAutoIndent(1);
136 _myTextEdit->setIndentationWidth(4);
137 _myTextEdit->setIndentationGuides(1);
138 _myTextEdit->setIndentationsUseTabs(0);
139 _myTextEdit->setAutoCompletionThreshold(2);
142 if ( !myInputPortsGroupBox || !myOutputPortsGroupBox ) return;
144 QString aPortTypes = QString("Data Flow;Data Stream (BASIC);Data Stream (CALCIUM);Data Stream (PALM)");
145 QString aValueTypes = QString("Double;Int;String;Bool;Objref;Sequence;Array;Struct");
148 myInputPortsGroupBox->setTitle( tr("Input Ports") );
149 YACSGui_Table* aTable = myInputPortsGroupBox->Table();
150 //aTable->setFixedHeight( 100 );
151 aTable->setNumCols( 4 );
152 aTable->horizontalHeader()->setLabel( 0, tr( "Name" ) );
153 aTable->horizontalHeader()->setLabel( 1, tr( "Class" ) );
154 aTable->horizontalHeader()->setLabel( 2, tr( "Type" ) );
155 aTable->horizontalHeader()->setLabel( 3, tr( "Value" ) );
156 aTable->setColumnWidth(0,58);
157 aTable->setColumnWidth(1,84);
158 aTable->setColumnWidth(2,80);
159 aTable->setCellType( -1, 0, YACSGui_Table::String );
160 aTable->setCellType( -1, 1, YACSGui_Table::Combo );
161 aTable->setCellType( -1, 2, YACSGui_Table::Combo );
162 //aTable->setCellType( -1, 3, YACSGui_Table::??? ); depends on combo box item choosen in the "Value type" column
164 aTable->setParams( 0, 1, aPortTypes );
165 aTable->setParams( 0, 2, aValueTypes );
167 aTable->setEditorSync(true);
169 connect( aTable, SIGNAL(valueChanged( int, int )), this, SLOT(onValueChanged( int, int )) );
171 myInputPortsGroupBox->HideBtn( YACSGui_PlusMinusGrp::PlusBtn | YACSGui_PlusMinusGrp::MinusBtn |
172 YACSGui_PlusMinusGrp::InsertBtn | YACSGui_PlusMinusGrp::SelectBtn );
173 myInputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
174 myInputPortsGroupBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
176 // Output Ports table
177 myOutputPortsGroupBox->setTitle( tr("Output Ports") );
178 aTable = myOutputPortsGroupBox->Table();
179 //aTable->setFixedHeight( 100 );
180 aTable->setNumCols( 5 );
181 aTable->horizontalHeader()->setLabel( 0, tr( "Name" ) );
182 aTable->horizontalHeader()->setLabel( 1, tr( "Class" ) );
183 aTable->horizontalHeader()->setLabel( 2, tr( "Type" ) );
184 aTable->horizontalHeader()->setLabel( 3, tr( "Value" ) );
185 aTable->horizontalHeader()->setLabel( 4, tr( "Is in study" ) );
186 aTable->setColumnWidth(0,58);
187 aTable->setColumnWidth(1,84);
188 aTable->setColumnWidth(2,80);
190 aTable->setCellType( -1, 0, YACSGui_Table::String );
191 aTable->setCellType( -1, 1, YACSGui_Table::Combo );
192 aTable->setCellType( -1, 2, YACSGui_Table::Combo );
193 //aTable->setCellType( -1, 3, YACSGui_Table::??? ); depends on combo box item choosen in the "Value type" column
194 aTable->setCellType( -1, 4, YACSGui_Table::Combo );
196 aTable->setParams( 0, 1, aPortTypes );
197 aTable->setParams( 0, 2, aValueTypes );
198 aTable->setParams( 0, 4, QString("Yes;No") );
199 aTable->setDefValue( 0, 4, QString("Yes") );
201 aTable->setEditorSync(true);
206 connect( aTable, SIGNAL(valueChanged( int, int )), this, SLOT(onValueChanged( int, int )) );
208 myOutputPortsGroupBox->HideBtn( YACSGui_PlusMinusGrp::PlusBtn | YACSGui_PlusMinusGrp::MinusBtn |
209 YACSGui_PlusMinusGrp::InsertBtn | YACSGui_PlusMinusGrp::SelectBtn );
210 myOutputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
211 myOutputPortsGroupBox->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
214 myProcRadioButton->setEnabled(false);
216 connect( myNodeName, SIGNAL(textChanged( const QString& )), this, SLOT(onNodeNameChanged( const QString& )) );
217 connect( myInstanceName, SIGNAL(activated( const QString& )), this, SLOT(onInstanceNameChanged( const QString& ) ) );
218 connect( myBrowseButton, SIGNAL(clicked( )), this, SLOT(onBrowse( )) );
219 connect( this, SIGNAL( enableApply( bool ) ), getInputPanel(), SLOT( onApplyEnabled( bool ) ) );
220 connect( CatalogTree, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( onCatalogMethodClicked( QListViewItem* ) ) );
221 connect( mySessionRadioButton, SIGNAL( stateChanged( int ) ), this, SLOT( onCatalogChanged( int ) ) );
222 connect( myProcRadioButton, SIGNAL( stateChanged( int ) ), this, SLOT( onCatalogChanged( int ) ) );
224 //connect( this, SIGNAL(visibilityChanged( bool )), this, SLOT(onVisibilityChanged( bool )) );
227 YACSGui_ServiceNodePage::~YACSGui_ServiceNodePage()
229 if (getInputPanel()) getInputPanel()->removePage(this);
232 void YACSGui_ServiceNodePage::setSCNode( YACS::HMI::SubjectComposedNode* theSCNode )
234 DEBTRACE("YACSGui_ServiceNodePage::setSCNode");
235 if ( theSCNode && mySCNode != theSCNode )
236 mySCNode = theSCNode;
239 void YACSGui_ServiceNodePage::setSNode( YACS::HMI::SubjectNode* theSNode )
241 if ( !theSNode ) return;
243 if ( YACS::ENGINE::ServiceNode* aServiceNode = dynamic_cast<ServiceNode*>( theSNode->getNode() ) )
245 myComponentName = QString::null;
246 myComponent = aServiceNode->getComponent();
247 YACSGui_NodePage::setSNode( theSNode );
251 void YACSGui_ServiceNodePage::setComponent( YACS::ENGINE::ComponentInstance* theComponent )
253 DEBTRACE("YACSGui_ServiceNodePage::setComponent");
254 if (!theComponent) return;
255 ServiceNode* aServiceNode = dynamic_cast<ServiceNode*>(getNode());
256 if (!aServiceNode) return;
257 ComponentInstance* compo = aServiceNode->getComponent();
260 std::string currentInstName = compo->getInstanceName();
261 std::string anInstanceName = theComponent->getInstanceName();
263 if( currentInstName != anInstanceName )
265 myComponentName = theComponent->getCompoName();
266 myInstanceName->setCurrentText(theComponent->getInstanceName());
267 myComponent = theComponent;
270 YACSGui_ComponentPage* aCompPage =
271 dynamic_cast<YACSGui_ComponentPage*>( getInputPanel()->getPage( YACSGui_InputPanel::ComponentId ) );
273 aCompPage->setSComponent( GuiContext::getCurrent()->_mapOfSubjectComponent[theComponent], false );
277 void YACSGui_ServiceNodePage::setMode( const YACSGui_InputPanel::PageMode theMode )
279 DEBTRACE("YACSGui_ServiceNodePage::setMode");
280 YACSGui_NodePage::setMode(theMode);
282 if ( myMode == YACSGui_InputPanel::NewMode )
284 DEBTRACE("new mode");
285 CatalogGroupBox->show();
286 PortListGroupBox->hide();
287 InPythonEditorGroupBox->hide();
288 NameGroupBox->hide();
289 // ComponentDefinitionLabel->hide();
290 // myComponentDefinition->hide();
291 // MethodName->hide();
292 // myMethodName->hide();
293 ExecutionGroupBox->hide();
295 string aType = getInputPanel()->getModule()->getNodeType(SALOMENODE);
296 aName << aType << GuiContext::getCurrent()->getNewId(SALOMENODE);
297 myNodeName->setText(aName.str());
298 myNodeFullName->setText(aName.str());
299 getInputPanel()->onApplyEnabled(false);
305 DEBTRACE("not new mode");
306 CatalogGroupBox->hide();
307 PortListGroupBox->show();
308 NameGroupBox->show();
309 // ComponentDefinitionLabel->show();
310 // myComponentDefinition->show();
311 // MethodName->show();
312 // myMethodName->show();
313 getInputPanel()->onApplyEnabled(true);
316 myMethodName->setReadOnly(true);
318 if ( myMode == YACSGui_InputPanel::EditMode )
320 DEBTRACE("edit mode");
321 myNodeName->setReadOnly(false);
322 ExecutionGroupBox->hide();
324 myInputPortsGroupBox->ShowBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
325 myOutputPortsGroupBox->ShowBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
327 else if ( myMode == YACSGui_InputPanel::RunMode )
329 DEBTRACE("run mode");
330 myNodeName->setReadOnly(true);
331 ExecutionGroupBox->show();
333 myInputPortsGroupBox->HideBtn();
334 myOutputPortsGroupBox->HideBtn();
338 void YACSGui_ServiceNodePage::notifyNodeStatus( int theStatus )
342 myNodeState->setPaletteForegroundColor(getColor(theStatus));
343 myNodeState->setText(getText(theStatus));
347 void YACSGui_ServiceNodePage::notifyNodeProgress()
351 if (!getNode()) return;
352 Proc* aProc = dynamic_cast<Proc*>(getNode()->getRootNode());
353 if ( !aProc ) return;
355 YACSGui_Graph* aGraph = getInputPanel()->getModule()->getGraph( aProc );
356 if ( !aGraph ) return;
358 if ( YACSPrs_ElementaryNode* anItem = aGraph->getItem(getNode()) )
360 int aProgress = (int)( ( (anItem->getStoredPercentage() < 0) ? anItem->getPercentage() :
361 anItem->getStoredPercentage() ) );
362 myProgressBar->setProgress(aProgress);
367 void YACSGui_ServiceNodePage::notifyInPortValues( std::map<std::string,std::string> theInPortName2Value )
369 DEBTRACE("YACSGui_ServiceNodePage::notifyInPortValues");
372 QStringList aPortNames;
373 myInputPortsGroupBox->Table()->strings( 0, aPortNames );
375 for ( QStringList::Iterator it = aPortNames.begin(); it != aPortNames.end(); ++it )
377 if ( (*it).isEmpty() ) continue;
379 map<string,string>::iterator it1 = theInPortName2Value.find( (*it).latin1() );
380 if ( it1 != theInPortName2Value.end() )
381 aValues.append( QString((*it1).second.c_str()) );
384 if ( aPortNames.count() == aValues.count() )
385 myInputPortsGroupBox->Table()->setStrings( 3, aValues );
388 void YACSGui_ServiceNodePage::notifyOutPortValues( std::map<std::string,std::string> theOutPortName2Value )
390 DEBTRACE("YACSGui_ServiceNodePage::notifyOutPortValues");
393 QStringList aPortNames;
394 myOutputPortsGroupBox->Table()->strings( 0, aPortNames );
396 for ( QStringList::Iterator it = aPortNames.begin(); it != aPortNames.end(); ++it )
398 if ( (*it).isEmpty() ) continue;
400 map<string,string>::iterator it1 = theOutPortName2Value.find( (*it).latin1() );
401 if ( it1 != theOutPortName2Value.end() )
402 aValues.append( QString((*it1).second.c_str()) );
405 if ( aPortNames.count() == aValues.count() )
406 myOutputPortsGroupBox->Table()->setStrings( 3, aValues );
409 void YACSGui_ServiceNodePage::checkModifications( bool& theWarnToShow, bool& theToApply )
411 DEBTRACE("YACSGui_ServiceNodePage::checkModifications " << theWarnToShow <<","<<theToApply);
412 if ( !getNode() || !theWarnToShow && !theToApply ) return;
414 // 1) check if the content of the page is really modified (in compare with the content of engine object)
415 bool isModified = false;
416 ServiceNode* aServiceNode = dynamic_cast<ServiceNode*>( getNode() );
417 if ( !aServiceNode ) return;
419 if ( myNodeName->text().compare(getNodeName()) != 0) isModified = true;
423 if (aServiceNode->getComponent())
424 if(QString::compare(myInstanceName->currentText(),aServiceNode->getComponent()->getInstanceName()) != 0)
430 // read input data and input data stream ports values from the table
431 YACSGui_Table* aTable = myInputPortsGroupBox->Table();
432 aTable->stopEdit(true);
434 QStringList aPortNames;
437 aTable->strings( 0, aPortNames );
438 aTable->strings( 3, aValues );
441 for ( QStringList::Iterator it = aPortNames.begin(); it != aPortNames.end(); ++it )
443 InPort* anInPort = aServiceNode->getInPort(*it);
444 QString value=aValues[aRowId];
447 DEBTRACE(getPortValue( anInPort ) << "," <<value);
449 if ( anInPort && getPortValue( anInPort ).compare(value) != 0 )
459 // TODO: compare "Is in study" fields (not yet in use)
461 if ( !isModified && (myType == ServiceInline || myType == XMLNode) )
463 // check the code modifications in the built-in Python code editor
465 if ( ServiceInlineNode* aSIN = dynamic_cast<ServiceInlineNode*>( getNode() ) ) aScript = QString(aSIN->getScript());
466 else if ( XmlNode* aXN = dynamic_cast<XmlNode*>( getNode() ) ) aScript = QString(aXN->getScript());
468 #ifdef HAVE_QEXTSCINTILLA_H
469 QString theText = _myTextEdit->text();
471 QString theText = myTextEdit->text();
473 if ( theText.compare(aScript) != 0 ) isModified = true;
476 // 2) if yes, show a warning message: Apply or Cancel
480 theWarnToShow = false;
481 if ( SUIT_MessageBox::warn2(getInputPanel()->getModule()->getApp()->desktop(),
483 tr("APPLY_CANCEL_MODIFICATIONS"),
484 tr("BUT_YES"), tr("BUT_NO"), 0, 1, 0) == 0 )
488 if ( getInputPanel() ) getInputPanel()->emitApply(YACSGui_InputPanel::ServiceNodeId);
493 else if ( theToApply )
496 if ( getInputPanel() ) getInputPanel()->emitApply(YACSGui_InputPanel::ServiceNodeId);
500 void YACSGui_ServiceNodePage::onCatalogChanged( int )
502 DEBTRACE("YACSGui_ServiceNodePage::onCatalogChanged");
503 getInputPanel()->onApplyEnabled(false);
505 // generate name of node if session catalog is active one. Name for proc catalog
506 // is generated when node is selected in catalog view
507 /*if ( !myProcRadioButton->isChecked() )
510 string aType = getInputPanel()->getModule()->getNodeType( SALOMENODE );
511 aName << aType << GuiContext::getCurrent()->getNewId( SALOMENODE );
512 myNodeName->setText(aName.str());
518 void YACSGui_ServiceNodePage::onCatalogMethodClicked( QListViewItem* it )
522 if ( !myProcRadioButton->isChecked() )
524 // session catalog is used
525 std::pair<std::string, std::string> compoServ = myServiceMap[it];
526 getInputPanel()->onApplyEnabled(!compoServ.first.empty() && !compoServ.second.empty());
530 // This block of code is commented because service nodes can be creatwed here only
532 // proc catalog is used. Apply button should be enabled if selected item is not
533 // "Nodes" or "Composed nodes" one.
534 QListViewItem* aParent = it->parent();
535 getInputPanel()->onApplyEnabled( aParent != 0 );
537 // At the time service nodes can be created only so there is no point in
538 // regenerating default node name in accordance with its type
540 if ( myProcNodesMap.count( it ) )
542 YACS::ENGINE::Node* aNode = myProcNodesMap[ it ];
545 YACS::HMI::TypeOfElem aTypeId = ProcInvoc::getTypeOfNode( aNode );
547 string aType = getInputPanel()->getModule()->getNodeType( aTypeId );
548 aName << aType << GuiContext::getCurrent()->getNewId( aTypeId );
549 myNodeName->setText( aName.str() );
550 myNodeFullName->setText( aName.str() );
551 myNodeType->setText( aType.c_str() );
558 void YACSGui_ServiceNodePage::onBrowse()
560 DEBTRACE("YACSGui_ServiceNodePage::onBrowse");
561 QString fn = QFileDialog::getOpenFileName( QString::null,
562 tr( "XML-Files (*.xml);;All Files (*)" ),
564 "load YACS scheme file dialog as catalog",
565 "Choose a filename to load" );
569 myProcName = fn.latin1();
571 myProcRadioButton->setEnabled(true);
572 myProcRadioButton->setChecked(true);
574 getInputPanel()->onApplyEnabled(false);
578 void YACSGui_ServiceNodePage::onApply()
580 DEBTRACE("YACSGui_ServiceNodePage::onApply");
581 if ( myMode == YACSGui_InputPanel::NewMode )
583 // --- NewMode: import a node or composed node of any type from catalog ---------
585 GuiContext* aContext = GuiContext::getCurrent();
586 if ( !aContext ) return;
588 YACSGui_Module* aModule = getInputPanel()->getModule();
589 if ( !aModule ) return;
591 YACSGui_EditionTreeView * aETV = dynamic_cast<YACSGui_EditionTreeView*>(aModule->activeTreeView());
594 SubjectProc* aSchema = aContext->getSubjectProc();
595 DEBTRACE("YACSGui_ServiceNodePage::onApply: "<< aSchema);
597 YACS::ENGINE::Catalog* aCatalog = 0;
598 if ( myProcRadioButton->isChecked() )
600 aCatalog = YACS::ENGINE::getSALOMERuntime()->loadCatalog( "proc", myProcName.c_str() );
601 std::string errors=aCatalog->getErrors();
605 std::string msg="The imported file ";
606 msg=msg+myProcName+" has errors. Some nodes can be uncompletely built\n";
607 LogViewer* log=new LogViewer(msg+errors,getInputPanel()->getModule()->getApp()->desktop(),"dialog",WDestructiveClose);
609 getInputPanel()->getModule()->getApp()->logWindow()->putMessage(msg+errors );
613 aCatalog = aModule->getCatalog();
615 QListViewItem* anItem = CatalogTree->selectedItem();
617 SubjectServiceNode* aNewSNode = 0;
618 if ( aSchema && aCatalog && anItem && mySCNode )
622 YACS::HMI::TypeOfElem aTypeId = UNKNOWN;
623 if ( !myProcRadioButton->isChecked() )
625 if ( myServiceMap.find( anItem ) == myServiceMap.end() )
628 pair<string, string> compoServ = myServiceMap[anItem];
629 compo = compoServ.first;
630 service = compoServ.second;
631 aTypeId = SALOMENODE;
635 if ( anItem->text( 0 ).isNull() )
639 service = anItem->text( 0 ).latin1();
641 if ( !myProcNodesMap.count( anItem ) )
644 YACS::ENGINE::Node* aNode = myProcNodesMap[ anItem ];
646 // Add node in catalog map if necessary. In the other case it will not be
647 // found in CommandAddNodeFromCatalog method
648 if ( !aCatalog->_nodeMap.count( service ) &&
649 !aCatalog->_composednodeMap.count( service ) )
651 aCatalog->_nodeMap[ service ] = aNode;
654 YACS::ENGINE::ServiceNode* aServiceNode =
655 dynamic_cast< YACS::ENGINE::ServiceNode* >( aNode );
657 aServiceNode->setComponent( 0 );
659 aTypeId = ProcInvoc::getTypeOfNode( aNode );
662 myComponentName = compo;
663 myMethodName->setText( service );
665 Proc* aProc = aContext->getProc();
666 DEBTRACE("YACSGui_ServiceNodePage::onApply: " << aProc);
667 if ( !aProc ) return;
669 YACSGui_Graph* aGraph = aModule->getGraph( aProc );
670 if ( !aGraph ) return;
673 string aType = aModule->getNodeType( aTypeId );
674 aName << aType << aContext->getNewId( aTypeId );
676 // ---> block for correct node (engine - subject - presentation) creation
677 SubjectNode* aCreatedSNode = 0;
680 if ( SubjectSwitch* aSwitch = dynamic_cast<SubjectSwitch*>(mySCNode) )
682 map<int, SubjectNode*> bodyMap = aSwitch->getBodyMap();
684 if (bodyMap.empty()) aSwCase = 1;
687 map<int, SubjectNode*>::reverse_iterator rit = bodyMap.rbegin();
688 aSwCase = (*rit).first + 1;
690 aCreatedSNode = aSwitch->addNode( aCatalog, compo, service, aName.str(), aSwCase);
692 else if ( SubjectForLoop* aForLoop = dynamic_cast<SubjectForLoop*>(mySCNode) )
694 aCreatedSNode = aModule->createBody( SALOMENODE, mySCNode, aCatalog, compo, service );
696 else if ( SubjectForEachLoop* aForEachLoop = dynamic_cast<SubjectForEachLoop*>(mySCNode) )
698 aCreatedSNode = aModule->createBody( SALOMENODE, mySCNode, aCatalog, compo, service );
700 else if ( SubjectWhileLoop* aWhileLoop = dynamic_cast<SubjectWhileLoop*>(mySCNode) )
702 aCreatedSNode = aModule->createBody( SALOMENODE, mySCNode, aCatalog, compo, service );
704 else if ( SubjectProc* aSchema = dynamic_cast<SubjectProc*>(mySCNode) )
706 DEBTRACE("YACSGui_ServiceNodePage::onApply: " << aSchema);
707 aCreatedSNode = aSchema->addNode( aCatalog, compo, service, aName.str() );
709 else if ( SubjectBloc* aBloc = dynamic_cast<SubjectBloc*>(mySCNode) )
711 aCreatedSNode = aBloc->addNode( aCatalog, compo, service, aName.str() );
712 if( SubjectComposedNode* aParent = dynamic_cast<SubjectComposedNode*>(aBloc->getParent()) )
713 aGraph->update(aBloc->getNode(), aParent);
718 aCreatedSNode = aSchema->addNode( aCatalog, compo, service, aName.str() );
722 if ( SubjectBloc* aSB = dynamic_cast<SubjectBloc*>(mySCNode) )
723 aSB->update( EDIT, 0, aSB );
725 aNewSNode = dynamic_cast<SubjectServiceNode*>(aCreatedSNode);
726 ServiceNode* aNewNode =0;
728 aNewNode = dynamic_cast<ServiceNode*>(aNewSNode->getNode());
729 ComponentInstance* aComp = 0;
731 aComp = aNewNode->getComponent();
732 SubjectComponent* aSComp = 0;
733 if ( aComp ) // find the component subject in the current GuiContext
734 if ( aContext->_mapOfSubjectComponent.find(aComp) != aContext->_mapOfSubjectComponent.end() )
735 aSComp = aContext->_mapOfSubjectComponent[aComp];
739 SubjectContainer* aSCont = 0;
740 SalomeContainer* aCont = dynamic_cast<SalomeContainer*>(aComp->getContainer());
742 { // container is not found
743 // 1) try to find the first container with the suitable type (i.e. Salome container)
744 // in the current GuiContext
745 map<Container*, SubjectContainer*>::iterator itCont = aContext->_mapOfSubjectContainer.begin();
746 for ( ; itCont!=aContext->_mapOfSubjectContainer.end(); itCont++ )
748 SalomeContainer* aSalomeCont = dynamic_cast<SalomeContainer*>( (*itCont).first );
751 aSCont = (*itCont).second;
759 // 2) create a new default Salome container and subject for it
760 string aDefContainer = "DefaultContainer";
761 if ( !aProc->containerMap.count(aDefContainer) )
763 aSCont = aSchema->addContainer(aDefContainer);
764 aCont = dynamic_cast<SalomeContainer*>(aSCont->getContainer());
769 { //container is found => try to get its subject from the current GuiContext
770 if ( aContext->_mapOfSubjectContainer.find(aCont) != aContext->_mapOfSubjectContainer.end() )
771 aSCont = aContext->_mapOfSubjectContainer[aCont];
776 YACSGui_ContainerViewItem* aContainerItem = 0;
778 // get the "Containers" label view item
779 YACSGui_LabelViewItem* aContainersL =
780 dynamic_cast<YACSGui_LabelViewItem*>(aETV->firstChild()->firstChild()->nextSibling()->nextSibling()->nextSibling());
781 if ( !aContainersL || aContainersL->text(0).compare(QString("Containers")) ) return;
783 YACSGui_ContainerViewItem* anAfter = 0;
784 if ( QListViewItem* aChild = aContainersL->firstChild() )
788 if ( anAfter = dynamic_cast<YACSGui_ContainerViewItem*>(aChild) )
789 if ( anAfter->getContainer() == aCont )
791 aContainerItem = anAfter;
794 aChild = aChild->nextSibling();
798 if ( aContainerItem )
800 aContainerItem->addComponentItem(aSComp);
801 aSComp->associateToContainer( aSCont );
802 aNewSNode->associateToComponent(aSComp);
807 aModule->temporaryExport();
810 // --- commented to avoid to close the NewMode panel
811 // aModule->setGuiMode(YACSGui_Module::EditMode);
812 // setMode(YACSGui_InputPanel::EditMode);
813 if ( aNewSNode ) setSNode(aNewSNode);
815 if ( aModule->activeTreeView() )
816 aModule->activeTreeView()->syncPageTypeWithSelection();
821 // --- not NewMode: edition of an existing Service Node -----------
825 setNodeName( myNodeName->text() );
827 if ( ServiceNode* aServiceNode = dynamic_cast<ServiceNode*>( getNode() ) )
829 SubjectServiceNode* aSSNode = dynamic_cast<SubjectServiceNode*>(mySNode);
831 if (ComponentInstance* aPrevComponent = aServiceNode->getComponent())
833 SubjectComponent* aPrevSComponent = GuiContext::getCurrent()->_mapOfSubjectComponent[aPrevComponent];
835 if(QString::compare(myInstanceName->currentText(),aServiceNode->getComponent()->getInstanceName()) != 0)
837 ComponentInstance* compo = 0;
838 Proc* aProc = GuiContext::getCurrent()->getProc();
841 map<pair<string,int>,ComponentInstance*>::const_iterator it = aProc->componentInstanceMap.begin();
842 for(; it!=aProc->componentInstanceMap.end(); ++it)
844 ComponentInstance *inst=(*it).second;
845 if (! QString::compare(inst->getInstanceName(), myInstanceName->currentText())) // if same instance name
854 SubjectComponent* aSComp = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
855 if ( aSSNode && aSComp ) aSSNode->associateToComponent(aSComp);
862 SubjectComponent* aSComp = GuiContext::getCurrent()->_mapOfSubjectComponent[myComponent];
863 if ( aSSNode && aSComp ) aSSNode->associateToComponent(aSComp);
867 // Reset the list of input ports
870 // Reset the list of output ports
873 // Reset Python function/script
874 string aScript = scriptText().isEmpty() ? string("") : scriptText().latin1();
875 if ( ServiceInlineNode* aSIN = dynamic_cast<ServiceInlineNode*>( getNode() ) ) aSIN->setScript( aScript );
876 else if ( XmlNode* aXN = dynamic_cast<XmlNode*>( getNode() ) ) aXN->setScript( aScript );
881 void YACSGui_ServiceNodePage::buildTree( YACS::ENGINE::Node* theNode,
882 QListViewItem* nodeLabel,
883 QListViewItem* compoNodeLabel )
888 // --- Create item corresponding to the node
889 QString aName( theNode->getName().c_str() );
893 QListViewItem* theParent = nodeLabel;
894 if (YACS::ENGINE::ComposedNode* aCompNode = dynamic_cast<YACS::ENGINE::ComposedNode*>(theNode))
896 theParent = compoNodeLabel;
897 std::list<Node*> aNodes = aCompNode->edGetDirectDescendants();
898 std::list<Node*>::iterator anIter;
899 for ( anIter = aNodes.begin(); anIter != aNodes.end(); ++anIter )
900 buildTree( *anIter, nodeLabel, compoNodeLabel );
903 QListViewItem* anItem = new QListViewItem( theParent, aName );
904 anItem->setPixmap( 0, YACSGui_NodeViewItem::icon( theNode ) );
905 myProcNodesMap[ anItem ] = theNode;
909 void YACSGui_ServiceNodePage::updateState()
911 DEBTRACE("YACSGui_ServiceNodePage::updateState");
912 if ( myMode == YACSGui_InputPanel::NewMode )
914 //DEBTRACE("New mode");
915 //myNodeType->setText( tr( "SALOME_SERVICE_NODE" ) ); // SALOME service node
916 CatalogTree->clear();
917 CatalogTree->setRootIsDecorated( TRUE );
919 YACS::ENGINE::Catalog *_currentCatalog =0;
920 if ( myProcRadioButton->isChecked() )
922 _currentCatalog = YACS::ENGINE::getSALOMERuntime()->loadCatalog( "proc", myProcName.c_str() );
923 std::string errors=_currentCatalog->getErrors();
926 std::string msg="The imported file ";
927 msg=msg+myProcName+" has errors. Some nodes can be uncompletely built\n";
928 LogViewer* log=new LogViewer(msg+errors,getInputPanel()->getModule()->getApp()->desktop(),"dialog",WDestructiveClose);
930 getInputPanel()->getModule()->getApp()->logWindow()->putMessage(msg+errors );
934 _currentCatalog = getInputPanel()->getModule()->getCatalog();
936 if ( _currentCatalog )
938 myProcNodesMap.clear();
940 // --- nodes and composed nodes
941 std::map< std::string, Node* >& aNodeMap = _currentCatalog->_nodeMap;
942 std::map< std::string, ComposedNode* >& aCompMap = _currentCatalog->_composednodeMap;
943 QListViewItem* aNodeRoot = new QListViewItem( CatalogTree, tr( "NODES" ) );
944 QListViewItem* aCompRoot = new QListViewItem( CatalogTree, tr( "COMPOSED_NODES" ) );
946 if ( aCompMap.size() )
948 std::map< std::string, ComposedNode* >::iterator cIter;
949 for ( cIter = aCompMap.begin(); cIter != aCompMap.end(); ++cIter )
951 YACS::ENGINE::Node* aNode = cIter->second;
952 buildTree( aNode, aNodeRoot, aCompRoot );
955 if ( aNodeMap.size() )
957 std::map< std::string, Node* >::iterator nIter;
958 for ( nIter = aNodeMap.begin(); nIter != aNodeMap.end(); ++nIter )
960 YACS::ENGINE::Node* aNode = nIter->second;
961 buildTree( aNode, aNodeRoot, aCompRoot );
965 // --- composed nodes
967 // --- component and services
968 map<string, YACS::ENGINE::ComponentDefinition*>::const_iterator itComp;
969 for (itComp = _currentCatalog->_componentMap.begin();
970 itComp != _currentCatalog->_componentMap.end();
973 string compoName = (*itComp).first;
974 YACS::ENGINE::ComponentDefinition* compo = (*itComp).second;
975 QListViewItem *item = new QListViewItem(CatalogTree, compoName.c_str());
976 myServiceMap[item] = pair<string,string>(compoName,"");
977 map<string, YACS::ENGINE::ServiceNode*>::iterator itServ;
978 for (itServ = compo->_serviceMap.begin(); itServ != compo->_serviceMap.end(); ++itServ)
980 string serviceName = (*itServ).first;
981 YACS::ENGINE::ServiceNode* service = (*itServ).second;
982 QListViewItem *sitem = new QListViewItem(item, serviceName.c_str());
983 myServiceMap[sitem] = pair<string,string>(compoName,serviceName);
989 //DEBTRACE("not new mode");
991 if ( myType != SALOMEService )
993 //DEBTRACE("myType != SALOMEService");
994 myInputPortsGroupBox->ShowBtn( YACSGui_PlusMinusGrp::AllBtn );
995 myInputPortsGroupBox->HideBtn( YACSGui_PlusMinusGrp::SelectBtn );
996 myInputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn |
997 YACSGui_PlusMinusGrp::PlusBtn | YACSGui_PlusMinusGrp::MinusBtn |
998 YACSGui_PlusMinusGrp::InsertBtn );
1000 myOutputPortsGroupBox->ShowBtn( YACSGui_PlusMinusGrp::AllBtn );
1001 myOutputPortsGroupBox->HideBtn( YACSGui_PlusMinusGrp::SelectBtn );
1002 myOutputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn |
1003 YACSGui_PlusMinusGrp::PlusBtn | YACSGui_PlusMinusGrp::MinusBtn |
1004 YACSGui_PlusMinusGrp::InsertBtn );
1008 //DEBTRACE("myType == SALOMEService");
1009 myInputPortsGroupBox->HideBtn( YACSGui_PlusMinusGrp::PlusBtn | YACSGui_PlusMinusGrp::MinusBtn |
1010 YACSGui_PlusMinusGrp::InsertBtn | YACSGui_PlusMinusGrp::SelectBtn );
1011 myInputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
1013 myOutputPortsGroupBox->HideBtn( YACSGui_PlusMinusGrp::PlusBtn | YACSGui_PlusMinusGrp::MinusBtn |
1014 YACSGui_PlusMinusGrp::InsertBtn | YACSGui_PlusMinusGrp::SelectBtn );
1015 myOutputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
1018 if ( (myType == ServiceInline || myType == XMLNode) && InPythonEditorGroupBox )
1020 // show built-in Python code editor
1021 InPythonEditorGroupBox->show();
1022 connect( mySearch, SIGNAL(returnPressed()), this, SLOT(onSearch()) );
1024 else if ( InPythonEditorGroupBox )
1026 // hide built-in Python code editor
1027 InPythonEditorGroupBox->hide();
1028 disconnect( mySearch, SIGNAL(returnPressed()), this, SLOT(onSearch()) );
1031 // Clear input ports table and output ports tables, if they are not empty
1032 if ( myInputPortsGroupBox )
1034 myInputPortsGroupBox->Table()->setNumRows( 0 );
1035 myInputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
1037 if ( myOutputPortsGroupBox )
1039 myOutputPortsGroupBox->Table()->setNumRows( 0 );
1040 myOutputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
1044 if ( myNodeName ) myNodeName->setText( getNodeName() );
1046 // Set node full name (read only)
1047 if ( myNodeFullName )
1048 myNodeFullName->setText( getNode()->getRootNode()->getChildName(getNode()) );
1050 // Set node type: SALOME or CORBA service
1054 myNodeType->setText( tr( "SALOME_SERVICE_NODE" ) ); break;
1056 myNodeType->setText( tr( "CORBA_SERVICE_NODE" ) ); break;
1058 myNodeType->setText( tr( "CPP_NODE" ) ); break;
1060 myNodeType->setText( tr( "SERVICE_INLINE_NODE" ) ); break;
1062 myNodeType->setText( tr( "XML_NODE" ) ); break;
1066 // Set component instance and services
1067 if( myComponentDefinition && myMethodName )
1070 // --- always fill the table seems safer (salome nodes)
1071 // if ( myType == CORBAService || myType == CPPNode /*|| myType == ServiceInline || myType == XMLNode*/ )
1073 // Fill the table of input ports of the node
1074 fillInputPortsTable( getNode() );
1076 // Fill the table of output ports of the node
1077 fillOutputPortsTable( getNode() );
1081 void YACSGui_ServiceNodePage::onNodeNameChanged( const QString& theName )
1083 if ( myNodeFullName )
1085 QString anOldName = myNodeFullName->text();
1086 int aRDotId = anOldName.findRev('.');
1087 myNodeFullName->setText( anOldName.replace( aRDotId+1, anOldName.length()-(aRDotId+1), theName ) );
1091 void YACSGui_ServiceNodePage::onInstanceNameChanged( const QString& theInstanceName )
1093 Proc* aProc = GuiContext::getCurrent()->getProc();
1094 if ( !aProc ) return;
1096 ComponentInstance* compo = 0;
1097 map<pair<string,int>,ComponentInstance*>::const_iterator it = aProc->componentInstanceMap.begin();
1098 for(; it!=aProc->componentInstanceMap.end(); ++it)
1100 ComponentInstance *inst=(*it).second;
1101 if (! QString::compare(inst->getInstanceName(), theInstanceName)) // if same instance name
1109 YACSGui_ComponentPage* aCompPage =
1110 dynamic_cast<YACSGui_ComponentPage*>( getInputPanel()->getPage( YACSGui_InputPanel::ComponentId ) );
1112 aCompPage->setSComponent( GuiContext::getCurrent()->_mapOfSubjectComponent[compo], false );
1115 void YACSGui_ServiceNodePage::onValueChanged( int theRow, int theCol )
1117 DEBTRACE("YACSGui_ServiceNodePage::onValueChanged " << theRow << "," << theCol);
1118 if ( YACSGui_Table* aTable = ( YACSGui_Table* )sender() )
1119 if ( theCol == 2 ) // the value type of the port was changed
1120 setValueCellValidator( aTable, theRow );
1123 void YACSGui_ServiceNodePage::hideEvent( QHideEvent* )
1127 #ifdef HAVE_QEXTSCINTILLA_H
1128 // _myTextEdit->removeSelection(); // --- see if replacement ?
1130 myTextEdit->removeSelection();
1134 void YACSGui_ServiceNodePage::onSearch()
1136 #ifdef HAVE_QEXTSCINTILLA_H
1137 if ( _myTextEdit && mySearch )
1139 if ( _myTextEdit->findFirst( mySearch->text(), true, false, true, &myPara, &myIndex ) )
1141 _myTextEdit->setSelection( myPara, myIndex, myPara, myIndex + mySearch->text().length() );
1142 myIndex += mySearch->text().length();
1149 if ( myTextEdit && mySearch )
1151 if ( myTextEdit->find( mySearch->text(), true, false, true, &myPara, &myIndex ) )
1153 myTextEdit->setSelection( myPara, myIndex, myPara, myIndex + mySearch->text().length() );
1154 myIndex += mySearch->text().length();
1163 void YACSGui_ServiceNodePage::updateServices()
1167 if ( myComponentDefinition ) myComponentDefinition->clear();
1168 if ( myMethodName ) myMethodName->clear();
1172 YACS::ENGINE::ServiceNode* aServiceNode = dynamic_cast<ServiceNode*>( getNode() );
1173 if( !aServiceNode ) return;
1175 if( myComponentName.isNull() )
1176 myComponentName = aServiceNode->getComponent()->getCompoName();
1178 myComponentDefinition->setText( myComponentName );
1179 myMethodName->setText( aServiceNode->getMethod() );
1180 fillInstanceNames();
1181 myInstanceName->setCurrentText( aServiceNode->getComponent()->getInstanceName() );
1183 fillInputPortsTable( aServiceNode );
1184 fillOutputPortsTable( aServiceNode );
1187 void YACSGui_ServiceNodePage::fillInstanceNames()
1189 myInstanceName->clear();
1190 YACS::ENGINE::ServiceNode* aServiceNode = dynamic_cast<ServiceNode*>( getNode() );
1191 if( !aServiceNode ) return;
1192 ComponentInstance* compo = aServiceNode->getComponent();
1195 if (compo->getKind() == "Salome")
1196 myInstanceName->setEnabled(true);
1198 myInstanceName->setEnabled(false);
1200 Proc* aProc = GuiContext::getCurrent()->getProc();
1201 if ( !aProc ) return;
1203 map<pair<string,int>,ComponentInstance*>::const_iterator it = aProc->componentInstanceMap.begin();
1204 for(; it!=aProc->componentInstanceMap.end(); ++it)
1206 ComponentInstance *inst=(*it).second;
1207 QString aComponentName = inst->getCompoName();
1208 if (! QString::compare(compo->getCompoName(), aComponentName)) // if same component name
1209 myInstanceName->insertItem( QString(inst->getInstanceName()));
1213 void YACSGui_ServiceNodePage::fillInputPortsTable( YACS::ENGINE::Node* theNode )
1215 DEBTRACE("YACSGui_ServiceNodePage::fillInputPortsTable");
1219 QStringList aPortNames;
1220 QStringList aPortTypes;
1221 QStringList aValueTypes;
1222 QStringList aValues;
1224 QValueList<bool> aReadOnlyFlags;
1226 YACSGui_Table* aTable = myInputPortsGroupBox->Table();
1227 QStringList aPTCB = aTable->Params( 0, 1 );
1229 list<InPort*> anInPortsEngine = theNode->getSetOfInPort();
1230 list<InPort*>::iterator anInPortsIter = anInPortsEngine.begin();
1231 for( ;anInPortsIter!=anInPortsEngine.end();anInPortsIter++)
1233 InPort* anInPort = *anInPortsIter;
1235 // Collect port names in the list
1236 aPortNames.append( anInPort->getName() );
1239 if ( InputPort* anInputP = dynamic_cast<InputPort*>(anInPort) )
1241 aPortTypes.append( aPTCB[0] );
1243 int nbLinks = anInPort->edGetNumberOfLinks();
1244 aReadOnlyFlags.append( nbLinks > 0 );
1246 //else if ( InputBasicStreamPort* aBasicStreamP = dynamic_cast<InputBasicStreamPort*>(anInPort) )
1247 //{ // there is no possibility to identify BASIC data stream port in engine now => take default value from combo box
1248 // aPortTypes.append( aPTCB[1] );
1250 else if ( InputCalStreamPort* aCalStreamP = dynamic_cast<InputCalStreamPort*>(anInPort) )
1252 aPortTypes.append( aPTCB[2] );
1253 aReadOnlyFlags.append( true );
1255 //else if ( InputPalmStreamPort* aPalmStreamP = dynamic_cast<InputPalmStreamPort*>(anInPort) )
1256 //{ // there is no possibility to identify PALM data stream port in engine now => take default value from combo box
1257 // aPortTypes.append( aPTCB[3] );
1259 else if ( InputDataStreamPort* aCalStreamP = dynamic_cast<InputDataStreamPort*>(anInPort) )
1261 aPortTypes.append( aPTCB[2] );
1262 aReadOnlyFlags.append( true );
1265 { // take default value from combo box
1266 aPortTypes.append( aPTCB[0] );
1267 aReadOnlyFlags.append( true );
1271 aValueTypes.append( getPortType( anInPort ) );
1274 aValues.append( getPortValue( anInPort ) );
1277 // Fill "Port name" column
1278 aTable->setStrings( 0, aPortNames, true );
1280 // Fill "Port type" column
1281 aTable->setStrings( 1, aPortTypes, true );
1283 // Fill "Value type" column
1284 aTable->setStrings( 2, aValueTypes, true );
1286 if ( myType == SALOMEService )
1287 // Set the valid cell type for the input ports values
1288 for ( int i=0; i<aTable->numRows(); i++ )
1289 setValueCellValidator( aTable, i );
1291 // Fill "Value" column
1292 aTable->setStrings( 3, aValues, true );
1294 if ( myType == SALOMEService )
1296 // Set all columns read only (except "Value" column)
1297 aTable->setReadOnly( -1, 0, true );
1298 aTable->setReadOnly( -1, 1, true );
1299 aTable->setReadOnly( -1, 2, true );
1302 // Set "Value" column read only (for linked ports)
1303 for ( int i = 0, n = aTable->numRows(); i < n; i++ )
1305 aTable->setDefValue( i, 2, aValueTypes[i] );
1306 aTable->setReadOnly( i, 3, aReadOnlyFlags[ i ] );
1309 if ( aPortNames.count() > 1 )
1310 myInputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
1314 void YACSGui_ServiceNodePage::fillOutputPortsTable( YACS::ENGINE::Node* theNode )
1319 QStringList aPortNames;
1320 QStringList aPortTypes;
1321 QStringList aValueTypes;
1322 QStringList aValues;
1323 QStringList anIsInStudy;
1325 YACSGui_Table* aTable = myOutputPortsGroupBox->Table();
1326 QStringList aPTCB = aTable->Params( 0, 1 );
1328 list<OutPort*> anOutPortsEngine = theNode->getSetOfOutPort();
1329 list<OutPort*>::iterator anOutPortsIter = anOutPortsEngine.begin();
1330 for( ;anOutPortsIter!=anOutPortsEngine.end();anOutPortsIter++)
1332 OutPort* anOutPort = *anOutPortsIter;
1334 // Collect port names in the list
1335 aPortNames.append( anOutPort->getName() );
1338 if ( OutputPort* anOutputP = dynamic_cast<OutputPort*>(anOutPort) )
1340 aPortTypes.append( aPTCB[0] );
1342 //else if ( OutputBasicStreamPort* aBasicStreamP = dynamic_cast<OutputBasicStreamPort*>(anOutPort) )
1343 //{ // there is no possibility to identify BASIC data stream port in engine now => take default value from combo box
1344 // aPortTypes.append( aPTCB[1] );
1346 else if ( OutputCalStreamPort* aCalStreamP = dynamic_cast<OutputCalStreamPort*>(anOutPort) )
1348 aPortTypes.append( aPTCB[2] );
1350 //else if ( OutputPalmStreamPort* aPalmStreamP = dynamic_cast<OutputPalmStreamPort*>(anOutPort) )
1351 //{ // there is no possibility to identify PALM data stream port in engine now => take default value from combo box
1352 // aPortTypes.append( aPTCB[3] );
1354 else if ( OutputDataStreamPort* aCalStreamP = dynamic_cast<OutputDataStreamPort*>(anOutPort) )
1356 aPortTypes.append( aPTCB[2] );
1359 { // take default value from combo box
1360 aPortTypes.append( aPTCB[0] );
1364 aValueTypes.append( getPortType( anOutPort ) );
1367 aValues.append( getPortValue( anOutPort ) );
1370 // There is no a such parameter either in engine or GUI at the current moment.
1371 // TODO: we need to implement it at GUI side.
1372 // As a temporary solution we set the default value
1373 anIsInStudy.append( aTable->defValue( 0, 4 ) );
1376 // Fill "Port name" column
1377 aTable->setStrings( 0, aPortNames, true );
1379 // Fill "Port type" column
1380 aTable->setStrings( 1, aPortTypes, true );
1382 // Fill "Value type" column
1383 aTable->setStrings( 2, aValueTypes, true );
1385 // Fill "Value" column
1386 aTable->setStrings( 3, aValues, true );
1388 // Fill "Is in study" column
1389 aTable->setStrings( 4, anIsInStudy, true );
1391 if ( myType == SALOMEService )
1393 // Set all columns read only
1394 aTable->setReadOnly( -1, 0, true );
1395 aTable->setReadOnly( -1, 1, true );
1396 aTable->setReadOnly( -1, 2, true );
1397 aTable->setReadOnly( -1, 3, true );
1400 for ( int i = 0, n = aTable->numRows(); i < n; i++ )
1401 aTable->setDefValue( i, 2, aValueTypes[i] );
1403 if ( aPortNames.count() > 1 )
1404 myOutputPortsGroupBox->EnableBtn( YACSGui_PlusMinusGrp::UpBtn | YACSGui_PlusMinusGrp::DownBtn );
1407 QString YACSGui_ServiceNodePage::getPortType( YACS::ENGINE::Port* thePort ) const
1411 YACSGui_Table* aTable = 0;
1412 if ( dynamic_cast<InPort*>(thePort) )
1413 aTable = myInputPortsGroupBox->Table();
1414 else if ( dynamic_cast<OutPort*>(thePort) )
1415 aTable = myOutputPortsGroupBox->Table();
1417 if ( !aTable ) return aType;
1419 QStringList aVTCB = aTable->Params( 0, 2 );
1421 if ( DataPort* aDataPort = dynamic_cast<DataPort*>(thePort) )
1423 DynType aDType = aDataPort->edGetType()->kind();
1424 if ( aDType > NONE && aDType < Objref ) //if (aDType != NONE)
1425 aType = aVTCB[aDType-1];
1427 aType = QString(aDataPort->edGetType()->name());
1434 void YACSGui_ServiceNodePage::setInputPorts()
1436 DEBTRACE("YACSGui_ServiceNodePage::setInputPorts");
1437 if ( !myInputPortsGroupBox ) return;
1439 ServiceNode* aNode = dynamic_cast<ServiceNode*>( getNode() );
1440 if ( !aNode ) return;
1442 myInputPortsGroupBox->Table()->stopEdit(true);
1444 if ( myType != SALOMEService )
1447 list<InPort*> anInPortsEngine = aNode->getSetOfInPort();
1448 list<InPort*>::iterator anInPortsIter = anInPortsEngine.begin();
1449 for( ;anInPortsIter!=anInPortsEngine.end();anInPortsIter++)
1451 mySNode->update( REMOVE,
1452 ( dynamic_cast<InputPort*>(*anInPortsIter) ? INPUTPORT : INPUTDATASTREAMPORT ),
1453 GuiContext::getCurrent()->_mapOfSubjectDataPort[*anInPortsIter] );
1455 //aNode->edRemovePort(*anInPortsIter);
1456 // remove port subject (and all subject links connected to this port)
1457 mySNode->destroy( GuiContext::getCurrent()->_mapOfSubjectDataPort[*anInPortsIter] );
1460 // create a set of new input ports
1461 YACS::ENGINE::Catalog* aCatalog = getInputPanel()->getModule()->getCatalog();
1462 if ( aCatalog && aNode->getComponent()
1464 aCatalog->_componentMap.count(aNode->getComponent()->getCompoName()) )
1466 ComponentDefinition* aCompodef = aCatalog->_componentMap[aNode->getComponent()->getCompoName()];
1467 if ( aCompodef && aCompodef->_serviceMap.count(aNode->getMethod()) )
1468 if ( ServiceNode* aNodeToClone = aCompodef->_serviceMap[aNode->getMethod()] )
1470 list<InPort*> anInPortsClone = aNodeToClone->getSetOfInPort();
1471 list<InPort*>::iterator anInPortsIter = anInPortsClone.begin();
1472 for( ;anInPortsIter!=anInPortsClone.end();anInPortsIter++)
1473 if ( InputPort* anIP = dynamic_cast<InputPort*>(*anInPortsIter) ) // Data Flow port
1474 dynamic_cast<SubjectElementaryNode*>(mySNode)->addInputPort( aCatalog,
1475 portValueType(anIP->edGetType()),
1477 else if ( InputDataStreamPort* anIDSP = dynamic_cast<InputDataStreamPort*>(*anInPortsIter) ) // Data Stream port
1478 dynamic_cast<SubjectElementaryNode*>(mySNode)->addIDSPort( aCatalog,
1479 portValueType(anIDSP->edGetType()),
1480 anIDSP->getName() );
1485 // read input data and input data stream ports from the table
1486 YACSGui_Table* aTable = myInputPortsGroupBox->Table();
1488 QStringList aPortNames;
1489 QStringList aValues;
1491 aTable->strings( 0, aPortNames );
1492 aTable->strings( 3, aValues );
1494 // initialize created input ports with values
1496 for ( QStringList::Iterator it = aPortNames.begin(); it != aPortNames.end(); ++it,++aRowId )
1498 if ( (*it).isEmpty() ) continue;
1500 if ( aTable->intValueCombo( 1, aRowId ) == 0 ) // Data Flow port
1504 aIDP = aNode->getInputPort(*it);
1506 catch (YACS::Exception& ex) {
1512 TypeCode* aTC = aIDP->edGetType();
1517 if(!aValues[aRowId].isNull())
1518 std::cerr << aValues[aRowId] << std::endl;
1520 std::cerr << "Qnull" << std::endl;
1523 if( aValues[aRowId] == "< ? >")
1526 // initialize new created input data port
1529 switch ( aTC->kind() )
1532 d=aValues[aRowId].toDouble(&ok);
1537 aIDP->edInit( aValues[aRowId].toInt() );
1540 aIDP->edInit( aValues[aRowId].latin1() );
1543 aIDP->edInit( aValues[aRowId].compare( aTable->Params(aRowId,3)[0] ) ? false : true );
1546 //aIDP->edInit( "" ); // TODO : create an Any* with corresponding type and initialize with it
1549 //aIDP->edInit( "" ); // TODO : create an Any* (i.e. SequenceAny*) with corresponding type and initialize with it
1552 //aIDP->edInit( "" ); // TODO : create an Any* (i.e. ArrayAny*) with corresponding type and initialize with it
1555 //aIDP->edInit( "" ); // TODO : create an Any* with corresponding type and initialize with it
1561 mySNode->update( EDIT, INPUTPORT, GuiContext::getCurrent()->_mapOfSubjectDataPort[aIDP]);
1563 //else if ( aTable->intValueCombo( 1, aRowId ) == 1 ) // Data Stream (BASIC) port
1564 // // TODO : set value for input data stream port
1565 //else if ( aTable->intValueCombo( 1, aRowId ) == 2 ) // Data Stream (CALCIUM) port
1566 // // TODO : set value for input data stream port
1567 //else if ( aTable->intValueCombo( 1, aRowId ) == 3 ) // Data Stream (PALM) port
1568 // // TODO : set value for input data stream port
1573 void YACSGui_ServiceNodePage::setOutputPorts()
1575 DEBTRACE("YACSGui_ServiceNodePage::setOutputPorts");
1576 if ( !myOutputPortsGroupBox ) return;
1578 ServiceNode* aNode = dynamic_cast<ServiceNode*>( getNode() );
1579 if ( !aNode ) return;
1581 myOutputPortsGroupBox->Table()->stopEdit(true);
1583 if ( myType != SALOMEService )
1586 list<OutPort*> anOutPortsEngine = aNode->getSetOfOutPort();
1587 list<OutPort*>::iterator anOutPortsIter = anOutPortsEngine.begin();
1588 for( ;anOutPortsIter!=anOutPortsEngine.end();anOutPortsIter++)
1590 mySNode->update( REMOVE,
1591 ( dynamic_cast<OutputPort*>(*anOutPortsIter) ? OUTPUTPORT : OUTPUTDATASTREAMPORT ),
1592 GuiContext::getCurrent()->_mapOfSubjectDataPort[*anOutPortsIter] );
1594 //aNode->edRemovePort(*anOutPortsIter);
1595 // remove port subject (and all subject links connected to this port)
1596 mySNode->destroy( GuiContext::getCurrent()->_mapOfSubjectDataPort[*anOutPortsIter] );
1599 // create a set of new input ports
1600 YACS::ENGINE::Catalog* aCatalog = getInputPanel()->getModule()->getCatalog();
1601 if ( aCatalog && aNode->getComponent()
1603 aCatalog->_componentMap.count(aNode->getComponent()->getCompoName()) )
1605 ComponentDefinition* aCompodef = aCatalog->_componentMap[aNode->getComponent()->getCompoName()];
1606 if ( aCompodef && aCompodef->_serviceMap.count(aNode->getMethod()) )
1607 if ( ServiceNode* aNodeToClone = aCompodef->_serviceMap[aNode->getMethod()] )
1609 list<OutPort*> anOutPortsClone = aNodeToClone->getSetOfOutPort();
1610 list<OutPort*>::iterator anOutPortsIter = anOutPortsClone.begin();
1611 for( ;anOutPortsIter!=anOutPortsClone.end();anOutPortsIter++)
1612 if ( OutputPort* anOP = dynamic_cast<OutputPort*>(*anOutPortsIter) ) // Data Flow port
1613 dynamic_cast<SubjectElementaryNode*>(mySNode)->addOutputPort( aCatalog,
1614 portValueType(anOP->edGetType()),
1616 else if ( OutputDataStreamPort* anODSP = dynamic_cast<OutputDataStreamPort*>(*anOutPortsIter) ) // Data Stream port
1617 dynamic_cast<SubjectElementaryNode*>(mySNode)->addODSPort( aCatalog,
1618 portValueType(anODSP->edGetType()),
1619 anODSP->getName() );
1624 // read output data and output data stream ports from the table
1625 YACSGui_Table* aTable = myOutputPortsGroupBox->Table();
1627 QStringList aPortNames;
1628 aTable->strings( 0, aPortNames );
1631 for ( QStringList::Iterator it = aPortNames.begin(); it != aPortNames.end(); ++it )
1633 if ( (*it).isEmpty() ) continue;
1635 // TODO : Remember "Is in study" flag for output port
1642 YACS::ENGINE::TypeCode* YACSGui_ServiceNodePage::createTypeCode( YACS::ENGINE::DynType theType,
1643 YACSGui_Table* theTable,
1654 aTC = new TypeCode(theType);
1658 if ( theTable->intValueCombo( 1, theRowId ) == 2 ) // Data Stream (CALCIUM) port
1659 aTC = new TypeCodeObjref("CALCIUM","CALCIUM");
1660 else if ( theTable->intValueCombo( 1, theRowId ) == 1 ) // Data Stream (BASIC) port
1661 aTC = new TypeCodeObjref("BASIC","BASIC");
1662 else if ( theTable->intValueCombo( 1, theRowId ) == 3 ) // Data Stream (PALM) port
1663 aTC = new TypeCodeObjref("PALM","PALM");
1665 aTC = new TypeCodeObjref("","");
1669 aTC = new TypeCodeSeq("","",(new TypeCode(Double)));
1672 aTC = new TypeCodeArray("","",(new TypeCode(Double)),0);
1675 aTC = new TypeCodeStruct("","");
1684 QString YACSGui_ServiceNodePage::scriptText() const
1686 #ifdef HAVE_QEXTSCINTILLA_H
1687 return _myTextEdit->text();
1689 return myTextEdit->text();
1693 void YACSGui_ServiceNodePage::setScriptText( const QString& txt )
1695 #ifdef HAVE_QEXTSCINTILLA_H
1696 _myTextEdit->setText( txt );
1698 myTextEdit->setText( txt );