Salome HOME
Fix for bug IPAL9817 : SIGSEGV appears after "InLine" node function edition.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Service.cxx
index 9732c589fc9db5298ebd10b57c0d06b3578e35fd..3afcebbf2ff55fe2c6be16c0feac03eb04271a4e 100644 (file)
@@ -317,7 +317,7 @@ void SUPERVGUI_Service::initialise() {
        SALOME_ModuleCatalog::Service* Service = &(Interface->interfaceservicelist[k]);
        QListViewItem* myServiceItem = new QListViewItem(myInterfaceItem, (char*)Service->ServiceName);
        myServiceItem->setSelectable(true);
-       components->ensureItemVisible(myServiceItem);
+       //components->ensureItemVisible(myServiceItem);
        
        long nbPortsOut = Service->ServiceoutParameter.length();
        for (int m=0; m<nbPortsOut; m++) {
@@ -511,8 +511,9 @@ void SUPERVGUI_Service::addInlineNode() {
     switch (aSel) {
     case 0: // Computation
       {        
-       SUPERV_CNode aNode = aMain->getDataflow()->INode(myScriptPane->getFuncName().latin1(), 
-                                                        (myScriptPane->getFunction()).in());
+       SUPERV_CNode aNode = 
+         aMain->getDataflow()->INode(myScriptPane->getFuncName().isEmpty() ? "" : myScriptPane->getFuncName().latin1(), 
+                                     (myScriptPane->getFunction()).in());
        if (CORBA::is_nil(aNode)) {
          QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
          return;
@@ -525,9 +526,10 @@ void SUPERVGUI_Service::addInlineNode() {
     case 1: // Switch
       {
        SUPERV_INode aEndNode;
-       SUPERV_CNode aStartNode = aMain->getDataflow()->SNode(myScriptPane->getFuncName().latin1(),
-                                                             (myScriptPane->getFunction()).in(),
-                                                             aEndNode);
+       SUPERV_CNode aStartNode = 
+         aMain->getDataflow()->SNode(myScriptPane->getFuncName().isEmpty() ? "" : myScriptPane->getFuncName().latin1(),
+                                     (myScriptPane->getFunction()).in(),
+                                     aEndNode);
        if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
          QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
          return;
@@ -539,10 +541,14 @@ void SUPERVGUI_Service::addInlineNode() {
     case 2: // Loop
       {
        SUPERV_INode aEndNode;
-       SUPERV_CNode aStartNode = aMain->getDataflow()->LNode(myInitPane->getFuncName().latin1(), (myInitPane->getFunction()).in(),
-                                                             myMorePane->getFuncName().latin1(), (myMorePane->getFunction()).in(),
-                                                             myNextPane->getFuncName().latin1(), (myNextPane->getFunction()).in(),
-                                                             aEndNode);
+       SUPERV_CNode aStartNode = 
+         aMain->getDataflow()->LNode(myInitPane->getFuncName().isEmpty() ? "" : myInitPane->getFuncName().latin1(), 
+                                     (myInitPane->getFunction()).in(),
+                                     myMorePane->getFuncName().isEmpty() ? "" : myMorePane->getFuncName().latin1(), 
+                                     (myMorePane->getFunction()).in(),
+                                     myNextPane->getFuncName().isEmpty() ? "" : myNextPane->getFuncName().latin1(), 
+                                     (myNextPane->getFunction()).in(),
+                                     aEndNode);
        if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
          QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
          return;
@@ -898,21 +904,23 @@ void SUPERVGUI_PythonEditPane::autoIndentLine() {
 
     // get current cursor position and previous line (the one to be analized) 
     int pos, para, i;
+    QString spacesStr;
     myText->getCursorPosition( &para, &pos ); // pos==0, beginning of line
-    QString line = myText->text( para-1 ); // previous paragraph line
+    if ( myText->paragraphLength(para-1) > 0 ) { // mkr : IPAL9817
+      QString line = myText->text( para-1 ); // previous paragraph line
 
-    // construct a string containing all leading space characters of previous line (tabs, etc.)
-    QString spacesStr;
-    i = -1;
-    while ( line[++i].isSpace() ) // append all isSpace() characters at beginning of line to spacesStr
-      spacesStr += line[i];
-
-    // if ':' was found -- add more spaces to spacesStr
-    line = line.stripWhiteSpace();
-    if ( line[ line.length()-1 ] == ':' ) {
-      i = 0;
-      while ( i++ < N ) 
-       spacesStr += ' ';
+      // construct a string containing all leading space characters of previous line (tabs, etc.)
+      i = -1;
+      while ( line[++i].isSpace() ) // append all isSpace() characters at beginning of line to spacesStr
+       spacesStr += line[i];
+      
+      // if ':' was found -- add more spaces to spacesStr
+      line = line.stripWhiteSpace();
+      if ( line[ line.length()-1 ] == ':' ) {
+       i = 0;
+       while ( i++ < N ) 
+         spacesStr += ' ';
+      }
     }
 
     // ok, append spacesStr at the beginning of the current line = make indentation
@@ -969,7 +977,7 @@ SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg( bool isLoop )
   aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
   
   QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
-  connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
+  connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( clickOnOk() ) );
   aBtnLayout->addWidget( aOKBtn );
 
   aBtnLayout->addStretch();
@@ -981,6 +989,16 @@ SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg( bool isLoop )
   aMainLayout->addWidget(aBtnBox);
 }
 
+// mkr : IPAL9817 : to avoid a SIGSEGV when INode_Impl::SetPyFunction(...)
+//                  will call with null python function name
+void SUPERVGUI_EditPythonDlg::clickOnOk()
+{
+  if ( getFuncName().isEmpty() )
+    QMessageBox::warning( SUIT_Session::session()->activeApplication()->desktop(), tr( "ERROR" ), tr( "MSG_INCORRECT_INDENT" ) );
+  else  
+    accept();
+}
+
 /**
  * Do the following actions for newly created Engine's CNode:
  * 1. Create a presentation for it (CanvasNode)
@@ -1024,6 +1042,7 @@ void SUPERVGUI_Service::addNode( SUPERV::CNode_var theNode, SUPERV::INode_var th
       aMain->addControlNode( theNode, SUPERV::CNode::_narrow( theEndNode ), true );
     else
       aMain->addComputeNode( theNode );
+    aSupMod->nullifyInitialVF();
   }
 }