1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SUPERVGUI_Service.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGUI_Service.h"
30 #include "SUPERVGUI_Main.h"
31 #include "SUPERVGUI_Library.h"
32 #include "SUPERVGUI.h"
34 #include "CAM_Application.h"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_FileDlg.h"
37 #include "SUIT_Session.h"
38 #include "SUIT_Tools.h"
40 #include "SALOME_NamingService.hxx"
41 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
45 #include <qtextstream.h>
48 static const char * ComponentIcon[] = {
55 " .................. ",
64 " .................. ",
68 " .. .. .. .. .. .. ",
70 " .. .. .. .. .. .. ",
74 static const char * InterfaceIcon[] = {
102 SUPERVGUI_Service::SUPERVGUI_Service(SALOME_NamingService* ns):
103 QDialog(SUIT_Session::session()->activeApplication()->desktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
104 naming(ns), myMFile(0)
106 setSizeGripEnabled( true );
107 setCaption(tr("TIT_SERVICES"));
109 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4);
111 myTabPane = new QTabWidget(this);
112 connect(myTabPane, SIGNAL(currentChanged(QWidget *)), this, SLOT(tabChanged(QWidget *)));
114 // Create Tab for Corba services
115 QWidget* aCorbaPane = new QWidget(myTabPane);
116 QVBoxLayout* aBaseLayoutV= new QVBoxLayout(aCorbaPane, 0, 4);
117 aBaseLayoutV->setMargin(5);
118 aBaseLayoutV->setSpacing(10);
120 QHBoxLayout* aBaseLayout = new QHBoxLayout(aCorbaPane); //!!
122 components = new QListView(aCorbaPane);
123 components->addColumn(tr("COL_COMPONENTS"));
124 components->addColumn(tr("COL_PORTTYPE"));
125 components->addColumn(tr("COL_PORTWAY"));
126 components->setColumnAlignment(1, AlignLeft);
127 components->setColumnAlignment(2, AlignLeft);
128 components->setColumnAlignment(3, AlignLeft);
129 components->setSelectionMode(QListView::Extended);
130 components->setRootIsDecorated(true);
131 // aBaseLayout->addWidget(components);
132 aBaseLayoutV->addWidget(components); //!!
134 //QHGroupBox* aAddBox = new QHGroupBox(tr("TIT_ADDNODE"), aCorbaPane); //!!
135 //aAddBox->setInsideSpacing(20); //!!
137 //NRI QPushButton* aComputeCBtn = new QPushButton(tr("TIT_ADDCNODE"), aCorbaPane); //!!
138 //NRI connect(aComputeCBtn, SIGNAL(clicked()), this, SLOT(addComputeNode())); //!!
139 //NRI aComputeCBtn->setDefault(false);
141 QPushButton* aComputeBtn = new QPushButton(tr("TIT_ADDFNODE"), aCorbaPane);
142 connect(aComputeBtn, SIGNAL(clicked()), this, SLOT(addFactoryNode()));
143 aComputeBtn->setDefault(true);
145 aBaseLayout->addWidget(aComputeBtn);
146 //NRI aBaseLayout->addWidget(aComputeCBtn); //!!
148 aBaseLayoutV->insertLayout(-1, aBaseLayout);
149 myTabPane->addTab(aCorbaPane, tr("MODULES_PANE"));
152 // Create Tab for Python services
153 QWidget* aPythonPane = new QWidget(myTabPane);
154 QVBoxLayout* aPythonLayout = new QVBoxLayout(aPythonPane, 0, 4);
155 aPythonLayout->setMargin(5);
156 aPythonLayout->setSpacing(10);
159 QHGroupBox* aAddBox2 = new QHGroupBox(tr("TIT_ADDNODE"), aPythonPane);
160 aAddBox2->setInsideSpacing(20);
162 /*QLabel* aTypeLbl = */new QLabel(tr("LBL_NODETYPE"), aAddBox2);
164 myTypeCombo = new QComboBox(aAddBox2);
165 myTypeCombo->insertItem( tr( "INLINE_COMP" ) );
166 myTypeCombo->insertItem( tr( "INLINE_SWTC" ) );
167 myTypeCombo->insertItem( tr( "INLINE_LOOP" ) );
168 myTypeCombo->insertItem( tr( "INLINE_GOTO") );
169 connect(myTypeCombo, SIGNAL(activated(int)), this, SLOT(typeNodeSelected(int)));
171 aPythonLayout->addWidget(aAddBox2);
174 myStackWidget = new QWidgetStack(aPythonPane);
177 myScriptPane = new SUPERVGUI_PythonEditPane( myStackWidget, true, myX, myY );
178 myOtherId = myStackWidget->addWidget(myScriptPane);
181 QTabWidget* aLoopTabPane = new QTabWidget(myStackWidget);
182 myInitPane = new SUPERVGUI_PythonEditPane( myStackWidget, true, myX, myY );
183 aLoopTabPane->addTab(myInitPane, "Init");
185 myMorePane = new SUPERVGUI_PythonEditPane( myStackWidget, true, myX, myY );
186 aLoopTabPane->addTab(myMorePane, "More");
188 myNextPane = new SUPERVGUI_PythonEditPane( myStackWidget, true, myX, myY );
189 aLoopTabPane->addTab(myNextPane, "Next");
190 myLoopId = myStackWidget->addWidget(aLoopTabPane);
192 myStackWidget->raiseWidget(myOtherId);
194 aPythonLayout->addWidget(myStackWidget, 1);
197 QPushButton* aCreateBtn = new QPushButton(tr("TIT_ADDNODE"), aPythonPane);
198 connect(aCreateBtn, SIGNAL(clicked()), this, SLOT(addInlineNode()));
199 aPythonLayout->addWidget(aCreateBtn);
201 myTabPane->addTab(aPythonPane, tr("INLINE_PANE"));
203 // Create Tab for Macro node only if environmental variable ENABLE_MACRO_NODE is set
204 if ( getenv( "ENABLE_MACRO_NODE" ) != NULL ) {
205 QWidget* aMacroPane = new QWidget(myTabPane);
206 QVBoxLayout* aMacroLayout = new QVBoxLayout(aMacroPane, 0, 4);
207 aMacroLayout->setMargin(5);
208 aMacroLayout->setSpacing(10);
210 QHBoxLayout* aLoadLayout = new QHBoxLayout(aMacroPane); //!!
211 aLoadLayout->addStretch();
213 QPushButton* aLoadBtn = new QPushButton(tr("BUT_LOAD"), aMacroPane);
214 connect(aLoadBtn, SIGNAL(clicked()), this, SLOT(loadGraph()));
216 aLoadLayout->addWidget(aLoadBtn);
218 aMacroLayout->addLayout(aLoadLayout);
220 myMacroPane = new QListView(aMacroPane);
221 myMacroPane->addColumn(tr("COL_COMPONENTS"));
222 myMacroPane->addColumn(tr("COL_PORTTYPE"));
223 myMacroPane->addColumn(tr("COL_PORTWAY"));
224 myMacroPane->setColumnAlignment(1, AlignLeft);
225 myMacroPane->setColumnAlignment(2, AlignLeft);
226 myMacroPane->setColumnAlignment(3, AlignLeft);
227 myMacroPane->setSelectionMode(QListView::Extended);
228 myMacroPane->setRootIsDecorated(true);
229 aMacroLayout->addWidget(myMacroPane); //!!
231 QPushButton* aAddBtn = new QPushButton(tr("TIT_ADDFNODE"), aMacroPane);
232 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(addMacroNode()));
233 aAddBtn->setDefault(true);
235 aMacroLayout->addWidget(aAddBtn);
237 myTabPane->addTab(aMacroPane, tr("MACRO_PANE"));
240 aMainLayout->addWidget(myTabPane);
243 QHBox* aBtnBox = new QHBox(this);
244 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
245 aBtnLayout->addStretch();
247 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
248 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
250 aMainLayout->addWidget(aBtnBox);
259 char* getDataStreamParameterName(int aType)
277 void SUPERVGUI_Service::initialise() {
278 CORBA::Object_ptr obj = naming->Resolve("/Kernel/ModulCatalog");
279 SALOME_ModuleCatalog::ModuleCatalog_var *aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
280 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
281 if (CORBA::is_nil(*aModuleCatalog)) {
282 setCaption("Error in Connexion to omniNames with '/Kernel/ModulCatalog'");
286 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
288 SALOME_ModuleCatalog::ListOfComponents_var lComponents = (*aModuleCatalog)->GetComponentList();
289 long nbComp = lComponents->length();
290 for (int i=0; i<nbComp; i++) {
291 SALOME_ModuleCatalog::Acomponent_ptr C = (*aModuleCatalog)->GetComponent((char *)lComponents[i]);
292 QListViewItem* myComponentItem = new QListViewItem(components, (char*)C->componentusername());
293 myComponentItem->setSelectable(false);
294 QString aIconName = C->component_icone();
295 if (!aIconName.isEmpty()) {
296 QString resFilePath = aResMgr->path(aResMgr->resSection(), C->componentname(), aIconName) ;
298 QPixmap aIcone(resFilePath);
299 QIconSet aIconSet(aIcone);
300 myComponentItem->setPixmap(0, aIconSet.pixmap(QIconSet::Small, QIconSet::Normal));
302 myComponentItem->setPixmap(0, ComponentIcon);
305 myComponentItem->setPixmap(0, ComponentIcon);
307 SALOME_ModuleCatalog::ListOfInterfaces* lInterfaces = C->GetInterfaceList();
308 long nbInterf = lInterfaces->length();
309 for (int j=0; j<nbInterf; j++) {
310 SALOME_ModuleCatalog::DefinitionInterface* Interface = C->GetInterface((char*)(*lInterfaces)[j]);
311 QListViewItem* myInterfaceItem = new QListViewItem(myComponentItem, (char*)Interface->interfacename);
312 myInterfaceItem->setSelectable(false);
313 myInterfaceItem->setPixmap(0, InterfaceIcon);
315 long nbServices = Interface->interfaceservicelist.length();
316 for (int k=0; k<nbServices; k++) {
317 SALOME_ModuleCatalog::Service* Service = &(Interface->interfaceservicelist[k]);
318 QListViewItem* myServiceItem = new QListViewItem(myInterfaceItem, (char*)Service->ServiceName);
319 myServiceItem->setSelectable(true);
320 //components->ensureItemVisible(myServiceItem);
322 long nbPortsOut = Service->ServiceoutParameter.length();
323 for (int m=0; m<nbPortsOut; m++) {
324 SALOME_ModuleCatalog::ServicesParameter* PortOut = &(Service->ServiceoutParameter[m]);
325 QListViewItem* myPortOutItem =
326 new QListViewItem(myServiceItem, (char*)PortOut->Parametername, (char*)PortOut->Parametertype, "Out");
327 myPortOutItem->setSelectable(false);
330 long nbStreamPortsOut = Service->ServiceoutDataStreamParameter.length();
331 for (int m=0; m<nbStreamPortsOut; m++) {
332 SALOME_ModuleCatalog::ServicesDataStreamParameter* PortOut = &(Service->ServiceoutDataStreamParameter[m]);
333 QListViewItem* myPortOutItem =
334 new QListViewItem(myServiceItem, (char*)PortOut->Parametername,
335 getDataStreamParameterName(PortOut->Parametertype), "DataStream Out");
336 myPortOutItem->setSelectable(false);
339 long nbPortsIn = Service->ServiceinParameter.length();
340 for (int l=0; l<nbPortsIn; l++) {
341 SALOME_ModuleCatalog::ServicesParameter* PortIn = &(Service->ServiceinParameter[l]);
342 QListViewItem* myPortInItem =
343 new QListViewItem(myServiceItem, (char*)PortIn->Parametername, (char*)PortIn->Parametertype, "In");
344 myPortInItem->setSelectable(false);
347 long nbStreamPortsIn = Service->ServiceinDataStreamParameter.length();
348 for (int l=0; l<nbStreamPortsIn; l++) {
349 SALOME_ModuleCatalog::ServicesDataStreamParameter* PortIn = &(Service->ServiceinDataStreamParameter[l]);
350 QListViewItem* myPortInItem =
351 new QListViewItem(myServiceItem, (char*)PortIn->Parametername,
352 getDataStreamParameterName(PortIn->Parametertype), "DataStream In");
353 myPortInItem->setSelectable(false);
362 SUPERVGUI_Service::~SUPERVGUI_Service() {
363 Trace("SUPERVGUI_Service::~SUPERVGUI_Service")
364 if (myMFile) delete myMFile;
367 void SUPERVGUI_Service::addComputeNode() {
368 SUIT_Desktop* aDesktop = SUIT_Session::session()->activeApplication()->desktop();
369 CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
370 if ( !anApp ) return;
372 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
374 MESSAGE("NULL Supervision module!");
378 SUPERVGUI_Main* aMain = aSupMod->getMain();
380 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
381 } else if (!aMain->isEditable()) {
382 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
384 CORBA::Object_ptr obj = naming->Resolve("/Kernel/ModulCatalog");
385 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
386 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
387 if (CORBA::is_nil(*aModuleCatalog)) {
388 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
392 QListViewItemIterator i(components);
393 for (; i.current(); ++i) {
395 if (item->isSelected()) {
396 const char* service = item->text(0).latin1();
397 const char* interface = item->parent()->text(0).latin1();
398 const char* component = item->parent()->parent()->text(0).latin1();
399 SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(anApp->moduleName(component));
400 if ( myComponent == NULL ) {
401 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
404 const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service);
405 SUPERV_CNode aNode = aMain->getDataflow()->CNode(*myService);
406 if ( CORBA::is_nil( aNode ) ) {
407 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
411 SUPERV::INode_var aDummyEndNode;
412 addNode( aNode, aDummyEndNode, myX, myY );
413 b = true; // at least one node was added
418 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NONODE_TOADD"));
424 void SUPERVGUI_Service::addFactoryNode() {
425 SUIT_Desktop* aDesktop = SUIT_Session::session()->activeApplication()->desktop();
426 CAM_Application* anApp = ( CAM_Application* )(SUIT_Session::session()->activeApplication());
427 if ( !anApp ) return;
429 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
431 MESSAGE("NULL Supervision module!");
435 SUPERVGUI_Main* aMain = aSupMod->getMain();
437 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
438 } else if (!aMain->isEditable()) {
439 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
441 CORBA::Object_ptr obj = naming->Resolve("/Kernel/ModulCatalog");
442 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
443 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
444 if (CORBA::is_nil(*aModuleCatalog)) {
445 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
449 QListViewItemIterator i(components);
450 for (; i.current(); ++i) {
452 if (item->isSelected()) {
453 const char* service = item->text(0).latin1();
454 const char* interface = item->parent()->text(0).latin1();
455 //const char* component = anApp->moduleName(item->parent()->parent()->text(0).latin1());
456 if ( aSupMod->getInterfaceNameMap().contains(item->parent()->text(0)) ) {
457 const char* component = aSupMod->getInterfaceNameMap().find(item->parent()->text(0)).data();
459 SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(component);
460 if (myComponent==NULL) {
461 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
464 const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service);
466 if ( myService->TypeOfNode == 0 ) { // ComputeNode
467 aNode = aMain->getDataflow()->CNode(*myService);
468 if (CORBA::is_nil( aNode ) ) {
469 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
473 else { // Factory Node
474 aNode = aMain->getDataflow()->FNode(component, interface, *myService);
475 if ( CORBA::is_nil( aNode ) ) {
476 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
480 SUPERV::INode_var aDummyEndNode;
481 addNode( aNode, aDummyEndNode, myX, myY );
488 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NONODE_TOADD"));
495 void SUPERVGUI_Service::addInlineNode() {
496 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
498 MESSAGE("NULL Supervision module!");
502 SUPERVGUI_Main* aMain = aSupMod->getMain();
504 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
506 else if (!aMain->isEditable()) {
507 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
510 int aSel = myTypeCombo->currentItem();
512 case 0: // Computation
514 SUPERV_CNode aNode = aMain->getDataflow()->INode(myScriptPane->getFuncName().latin1(),
515 (myScriptPane->getFunction()).in());
516 if (CORBA::is_nil(aNode)) {
517 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
520 SUPERV::INode_var aDummyEndNode;
521 addNode( aNode, aDummyEndNode, myX, myY );
527 SUPERV_INode aEndNode;
528 SUPERV_CNode aStartNode = aMain->getDataflow()->SNode(myScriptPane->getFuncName().latin1(),
529 (myScriptPane->getFunction()).in(),
531 if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
532 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
535 addNode( aStartNode, aEndNode, myX, myY );
541 SUPERV_INode aEndNode;
542 SUPERV_CNode aStartNode = aMain->getDataflow()->LNode(myInitPane->getFuncName().latin1(), (myInitPane->getFunction()).in(),
543 myMorePane->getFuncName().latin1(), (myMorePane->getFunction()).in(),
544 myNextPane->getFuncName().latin1(), (myNextPane->getFunction()).in(),
546 if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
547 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
550 addNode( aStartNode, aEndNode, myX, myY );
556 SUPERV_CNode aGotoNode;
557 if (myScriptPane->isDefined())
558 aGotoNode = aMain->getDataflow()->GNode(myScriptPane->getFuncName().latin1(),
559 (myScriptPane->getFunction()).in(), "");
561 aGotoNode = aMain->getDataflow()->GNode("GoTo", (myScriptPane->getFunction()).in(), "");
562 if (CORBA::is_nil(aGotoNode)) {
563 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
566 SUPERV::INode_var aDummyEndNode;
567 addNode( aGotoNode, aDummyEndNode, myX, myY );
574 void SUPERVGUI_Service::addMacroNode() {
575 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
577 MESSAGE("NULL Supervision module!");
581 SUPERVGUI_Main* aMain = aSupMod->getMain();
583 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
585 else if (!aMain->isEditable()) {
586 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
591 if (aMain->getDataflow()->IsStreamGraph()) {
592 SUPERV_StreamGraph aSGraph = aMain->getDataflow()->ToStreamGraph();
593 if (!SUPERV_isNull(aSGraph))
594 aNode = aSGraph->StreamMNode(myMFile->name().latin1());
595 // TMP: while stream macro nodes doesn't impemented
596 if (CORBA::is_nil(aNode)) {
597 aNode = aSGraph->MNode(myMFile->name().latin1());
601 aNode = aMain->getDataflow()->MNode(myMFile->name().latin1());
602 if (CORBA::is_nil(aNode)) {
603 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
607 SUPERV::INode_var aDummyEndNode;
608 addNode( aNode, aDummyEndNode, myX, myY );
611 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WARNING"), tr("MSG_NONODE_TOADD"));
616 void SUPERVGUI_Service::loadGraph() {
617 if ( getenv( "ENABLE_MACRO_NODE" ) == NULL )
618 // error! if ENABLE_MACRO_NODE is set - we should NOT get here by any means..
620 //MESSAGE("Error: ENABLE_MACRO_NODE is not set, but loadGraph() was called!");
624 QString aFileName = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
627 tr("MSG_GRAPH_INSERT"),
629 if (aFileName.isEmpty()) return;
631 myMacroPane->clear();
633 myMFile = new QFile(aFileName);
634 if (!myMFile->open(IO_ReadOnly)) {
635 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"),
636 tr("MSG_CANT_LOADSCRIPT"));
637 delete myMFile; myMFile = 0;
641 QTextStream* aStream = new QTextStream(myMFile);
642 if (aStream->atEnd()) {
643 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"),
644 tr("MSG_EMTY_FILE"));
647 delete myMFile; myMFile = 0;
652 // temporary display only file name
653 QFileInfo anInfo(*myMFile);
654 QListViewItem* anItem = new QListViewItem(myMacroPane, anInfo.baseName());
655 anItem->setSelectable(true);
658 void SUPERVGUI_Service::typeNodeSelected(int theRow) {
660 myStackWidget->raiseWidget(myLoopId);
662 myStackWidget->raiseWidget(myOtherId);
667 void SUPERVGUI_Service::choose() {
668 Trace("SUPERVGUI_Service::choose")
674 void SUPERVGUI_Service::showEvent(QShowEvent* theEvent) {
675 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
677 MESSAGE("NULL Supervision module!");
681 SUPERVGUI_Main* aMain = aSupMod->getMain();
682 if (aMain && (!aMain->isArrayShown())) {
683 aMain->getArrayView()->viewportToContents(0, 0, myX, myY);
684 //aMain->getGraph()->viewportToContents(0, 0, myX, myY);
686 QDialog::showEvent(theEvent);
690 void SUPERVGUI_Service::tabChanged(QWidget* theWidget) {
691 myIsInline = (myTabPane->currentPageIndex() == 1);
696 //*****************************************************
697 // Pane for Python script editing
698 //*****************************************************
699 SUPERVGUI_PythonEditPane::SUPERVGUI_PythonEditPane( QWidget* theParent, const bool isNodeCreation, int& theX, int& theY )
700 : myIsWithLibrary( isNodeCreation ),
702 myX( theX ), myY( theY )
704 QGridLayout* aEditLayout = new QGridLayout( this, 2, 8, 0, 6 );
707 if ( myIsWithLibrary ) {
708 QPushButton* aLibBtn = new QPushButton(tr("BUT_LIBRARY"), this);
709 connect(aLibBtn, SIGNAL(clicked()), this, SLOT(library()));
710 aEditLayout->addMultiCellWidget( aLibBtn, 0, 0, 1, 2 );
713 QPushButton* aLoadBtn = new QPushButton(tr("BUT_LOAD"), this);
714 connect(aLoadBtn, SIGNAL(clicked()), this, SLOT(loadFile()));
716 aEditLayout->addMultiCellWidget( aLoadBtn, 0, 0, 3, 4 );
718 myFunctionsCombo = new QComboBox( this );
719 connect( myFunctionsCombo, SIGNAL( activated( int ) ), this, SLOT( readFunction( int ) ) );
721 aEditLayout->addMultiCellWidget( myFunctionsCombo, 0, 0, 5, 7 );
724 myText = new QTextEdit(this);
725 myText->setTextFormat( Qt::PlainText ); // NOT rich text, so text() returns plain text
726 myText->setWordWrap( QTextEdit::FixedColumnWidth );
727 myText->setWrapColumnOrWidth( 80 );
728 connect( myText, SIGNAL( returnPressed() ), this, SLOT( autoIndentLine() ) );
730 aEditLayout->addMultiCellWidget( myText, 1, 1, 0, 7 );
731 //aEditLayout->setColStretch( 3, 1 ); // to allow myFunctionsCombo be larger when needed
735 * Return a text between "def" and "("
736 * "def" must begin with position 0, which means that only global function definitions are possible
738 QString getFunctionName( const QString& aLine ) {
739 int aDefPos = aLine.find("def");
740 if ( aDefPos == 0 ) { // only global function definitions!
741 int aStart = aLine.find(" ", aDefPos);
742 int aEnd = aLine.find("(", aStart);
743 QString aName = aLine.mid(aStart, (aEnd-aStart));
744 return aName.stripWhiteSpace();
750 * Searches for text beginning with "def" and ending with any meanful character at
751 * beginning of line. Starts searching with current position of given stream.
752 * Fills the myPyFunctions with strings corresponding to found fucntions.
754 void SUPERVGUI_PythonEditPane::initPyFunctions( QTextStream& theStream ) {
756 if ( theStream.atEnd() )
760 QString aLine = theStream.readLine();
762 while ( !theStream.atEnd() ) { // not EOF
764 // asv : 23.11.04 : fix for PAL6870 : skip empty lines in the beginning or between functions
765 // find("def)==0 -> analizing only global function definitions which start with 0 indentation
766 while ( !aLine.isNull() && aLine.find( "def" ) != 0 )
767 aLine = theStream.readLine();
769 if ( !aLine.isNull() && aLine.find("def") == 0 ) {
770 myFunctionsCombo->insertItem( getFunctionName( aLine ) ); // aLine now == function name
772 aPyFunction += aLine;
775 // read function body
776 aLine = theStream.readLine();
777 // asv : 23.11.04 : added "|| aLine.isEmpty()" - fix for PAL6870. readLine() returns an empty
778 // string for "\n" string, it trails \n caracter. but we accept such lines..
779 // asv : 22.12.04 : aLine[0].isSpace() || aLine[0]=='#' -> line must begin with space or tab
780 // (a normal code with indentation) or comment sign.
781 while ( !aLine.isNull() && ( aLine.isEmpty() || aLine[0].isSpace() || aLine[0] == '#' ) ) {
782 aPyFunction += aLine;
784 aLine = theStream.readLine();
787 myPyFunctions << aPyFunction;
788 aPyFunction.setLength( 0 );
794 * Load existing Python script
796 void SUPERVGUI_PythonEditPane::loadFile() {
797 QString aFileName = SUIT_FileDlg::getFileName(SUIT_Session::session()->activeApplication()->desktop(),
800 tr("TIT_LOADSCRIPT"),
802 if (aFileName.isEmpty()) return;
804 QFile aFile( aFileName );
805 if (!aFile.open(IO_ReadOnly)) {
806 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"),
807 tr("MSG_CANT_LOADSCRIPT"));
811 myPyFunctions.clear();
812 myFunctionsCombo->clear();
815 QTextStream aFileReader(&aFile);
816 if ( aFileReader.atEnd() ) {
817 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_EMTY_FILE"));
822 initPyFunctions( aFileReader );
824 if ( myPyFunctions.size() )
829 * Finds and Reads a function from current position in the opened file
830 * asv : Comment above is old! Present model: just take an already read string = PyFunction
831 * from the list which is filled in loadFile().
833 void SUPERVGUI_PythonEditPane::readFunction( int i ) {
835 if ( i != -1 && myPyFunctions.size() && myPyFunctions.size() > i )
836 myText->append( myPyFunctions[ i ] );
838 // asv : 30.11.04 : 2.7 - Inline node function editor improvement
839 // 2.7.1 - set focus to editor widget on editor window opening
840 // 2.7.2 - scroll to the beginning of function on editor window opening
842 myText->ensureVisible( 0,0 );
846 * Returns the text after "def" and before "(" -- first defined function name
848 QString SUPERVGUI_PythonEditPane::getFuncName() {
849 for (int i=0; i < myText->paragraphs(); i++) {
850 QString aName = getFunctionName( myText->text(i) );
851 if ( !aName.isEmpty() )
858 * Returns the contents of the myText widget without trailing spacing
860 SUPERV_Strings SUPERVGUI_PythonEditPane::getFunction() {
861 SUPERV_Strings aStrings = new SUPERV::ListOfStrings();
862 aStrings->length(myText->paragraphs());
863 for (int i=0; i < myText->paragraphs(); i++) {
864 QString aLine = myText->text(i);
865 // asv : 30.11.04 - why do we have to remove trailing spaces??
866 // it's user's responsibility to enter correct Python code, we don't do anything with it.
867 // if (..) -- initial, while(..) -- my improvement, but also commented out -- needless.
868 //if (!aLine.right(1).compare(" ")) // replaced with the line below -- loop
869 //while (aLine.at(aLine.length()-1).isSpace()) // remove trailing spaces
870 // aLine = aLine.remove(aLine.length()-1,1);
871 aStrings[i] = CORBA::string_dup(aLine.latin1());
873 return aStrings._retn();
877 void SUPERVGUI_PythonEditPane::setFunction(SUPERV_Strings theStr) {
879 for ( int i=0, aLen = theStr->length(); i < aLen; i++ )
880 myText->append(QString(theStr[i]));
882 // asv : 30.11.04 : 2.7 - Inline node function editor improvement
883 // 2.7.1 - set focus to editor widget on editor window opening
884 // 2.7.2 - scroll to the beginning of function on editor window opening
886 myText->ensureVisible( 0,0 );
890 * Automatic indentation rule: if a previous line ended with
891 * ':', then add N additional spaces in the current line. If no ':' found, then
892 * the same amount of spaces as in the previous line is added. Connected to
893 * "returnPressed" signal of myText text edit.
895 void SUPERVGUI_PythonEditPane::autoIndentLine() {
896 const int N = 4; // width of indentation "tab"
897 if ( myText && myText->paragraphs() ) {
899 // get current cursor position and previous line (the one to be analized)
901 myText->getCursorPosition( ¶, &pos ); // pos==0, beginning of line
902 QString line = myText->text( para-1 ); // previous paragraph line
904 // construct a string containing all leading space characters of previous line (tabs, etc.)
907 while ( line[++i].isSpace() ) // append all isSpace() characters at beginning of line to spacesStr
908 spacesStr += line[i];
910 // if ':' was found -- add more spaces to spacesStr
911 line = line.stripWhiteSpace();
912 if ( line[ line.length()-1 ] == ':' ) {
918 // ok, append spacesStr at the beginning of the current line = make indentation
919 myText->insertAt( spacesStr, para, pos );
920 myText->setCursorPosition( para, pos+spacesStr.length() );
925 * Create a node by loading it from an external XML library file
926 * This slot opens a dialog box which then "lives" by itself..
928 void SUPERVGUI_PythonEditPane::library() {
929 // if CanImport() returns false, it displays an error message box, so there is no need to
930 // display such message here ("library file not found", etc.).
931 if ( SUPERVGUI_Library::getLibrary()->CanImport() ) {
932 SUPERVGUI_LibDlg* aDlg = new SUPERVGUI_LibDlg( this, myX, myY );
940 SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg( bool isLoop )
941 :QDialog(SUIT_Session::session()->activeApplication()->desktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
943 setSizeGripEnabled( true );
944 setCaption(tr("TIT_FUNC_PYTHON"));
946 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4);
947 int a,b; // dummies for PythonEditPane, not used, since library = false and myX, myY are not used in PythonEditPane
949 QTabWidget* aLoopTabPane = new QTabWidget(this);
950 myInitPane = new SUPERVGUI_PythonEditPane( this, false, a, b ); // library == false, since no creation of a node is needed here
951 aLoopTabPane->addTab(myInitPane, "Init");
953 myMorePane = new SUPERVGUI_PythonEditPane( this, false, a, b );
954 aLoopTabPane->addTab(myMorePane, "More");
956 myNextPane = new SUPERVGUI_PythonEditPane( this, false, a, b );
957 aLoopTabPane->addTab(myNextPane, "Next");
959 aMainLayout->addWidget(aLoopTabPane);
961 myEditPane = new SUPERVGUI_PythonEditPane( this, false, a, b );
962 aMainLayout->addWidget(myEditPane);
964 QGroupBox* aBtnBox = new QGroupBox( this );
965 aBtnBox->setColumnLayout( 0, Qt::Vertical );
966 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
967 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
968 aBtnLayout->setAlignment( Qt::AlignTop );
969 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
971 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
972 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
973 aBtnLayout->addWidget( aOKBtn );
975 aBtnLayout->addStretch();
977 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
978 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
979 aBtnLayout->addWidget( aCancelBtn );
981 aMainLayout->addWidget(aBtnBox);
985 * Do the following actions for newly created Engine's CNode:
986 * 1. Create a presentation for it (CanvasNode)
987 * 2. Place the CanvasNode to the current top-left corner or the current viewport
988 * 3. Increment the coordinates of the next CanvasNode (new nodes are "cascaded" when several of them are created at once)
989 * PS theEndNode is passed only for Loop and Switch nodes (EndLoop and EndSwitch)
991 void SUPERVGUI_Service::addNode( SUPERV::CNode_var theNode, SUPERV::INode_var theEndNode, int& theX, int& theY ) {
992 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
994 MESSAGE("NULL Supervision module!");
998 SUPERVGUI_Main* aMain = aSupMod->getMain();
1000 if ( !CORBA::is_nil( theNode ) && aMain ) {
1002 aMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag, why here? -> PAL7960
1004 int cx, cy; //to appear a new node in the top-left corner of the current viewport
1006 //2.8 point of improvements: Adding node to graph window with taking into account zoom factor
1007 QWMatrix aWM = aMain->getCanvasView()->worldMatrix();
1008 aMain->getCanvasView()->viewportToContents(theX, theY, cx, cy);
1010 //2.8 point of improvements:
1011 cx = (int)((double)cx/aWM.m11());
1012 cy = (int)((double)cy/aWM.m22());
1013 theNode->Coords(cx, cy);
1014 if ( !CORBA::is_nil( theEndNode ) )
1015 theEndNode->Coords(cx + LABEL_WIDTH*2, cy);
1016 theX += (int)(NODE_DX*aWM.m11());
1017 theY += (int)(NODE_DY*aWM.m22());
1019 if ( theNode->IsGOTO() )
1020 aMain->addGOTONode( theNode );
1021 else if ( theNode->IsMacro() )
1022 aMain->addMacroNode( theNode );
1023 else if ( theNode->IsLoop() || theNode->IsSwitch() )
1024 aMain->addControlNode( theNode, SUPERV::CNode::_narrow( theEndNode ), true );
1026 aMain->addComputeNode( theNode );
1027 aSupMod->nullifyInitialVF();