Salome HOME
Adding a Node to viewport is unified: one common method addNode() is created in Servi...
authorasv <asv@opencascade.com>
Fri, 24 Dec 2004 12:55:06 +0000 (12:55 +0000)
committerasv <asv@opencascade.com>
Fri, 24 Dec 2004 12:55:06 +0000 (12:55 +0000)
Messages are modified as usual: new messages were added.

src/SUPERVGUI/SUPERVGUI_Service.cxx
src/SUPERVGUI/SUPERVGUI_Service.h
src/SUPERVGUI/SUPERV_msg_en.po

index fe85677f48894f33257617f04986f71c97a17321..0a92e1a37c3454b20f90618d5c17d1a27826b0bb 100644 (file)
@@ -28,6 +28,7 @@
 using namespace std;
 #include "SUPERVGUI_Service.h"
 #include "SUPERVGUI_Main.h"
+#include "SUPERVGUI_Library.h"
 #include "SUPERVGUI.h"
 #include "QAD_Tools.h"
 #include "QAD_FileDlg.h"
@@ -168,18 +169,18 @@ SUPERVGUI_Service::SUPERVGUI_Service(SALOME_NamingService* ns):
   myStackWidget = new QWidgetStack(aPythonPane);
 
   // other pane
-  myScriptPane = new SUPERVGUI_PythonEditPane(myStackWidget);
+  myScriptPane = new SUPERVGUI_PythonEditPane( myStackWidget, true );
   myOtherId = myStackWidget->addWidget(myScriptPane);
 
   // loop pane
   QTabWidget* aLoopTabPane = new QTabWidget(myStackWidget);
-  myInitPane = new SUPERVGUI_PythonEditPane(myStackWidget); 
+  myInitPane = new SUPERVGUI_PythonEditPane( myStackWidget, true ); 
   aLoopTabPane->addTab(myInitPane, "Init");
 
-  myMorePane = new SUPERVGUI_PythonEditPane(myStackWidget);
+  myMorePane = new SUPERVGUI_PythonEditPane( myStackWidget, true );
   aLoopTabPane->addTab(myMorePane, "More");
 
-  myNextPane = new SUPERVGUI_PythonEditPane(myStackWidget);
+  myNextPane = new SUPERVGUI_PythonEditPane( myStackWidget, true );
   aLoopTabPane->addTab(myNextPane, "Next");
   myLoopId = myStackWidget->addWidget(aLoopTabPane);
 
@@ -195,43 +196,42 @@ SUPERVGUI_Service::SUPERVGUI_Service(SALOME_NamingService* ns):
   myTabPane->addTab(aPythonPane, tr("INLINE_PANE"));
 
   // Create Tab for Macro node only if environmental variable ENABLE_MACRO_NODE is set
-       if ( getenv( "ENABLE_MACRO_NODE" ) != NULL )
-       {
-       QWidget* aMacroPane = new QWidget(myTabPane);
-       QVBoxLayout* aMacroLayout = new QVBoxLayout(aMacroPane, 0, 4);
-       aMacroLayout->setMargin(5);
-       aMacroLayout->setSpacing(10);
-
-       QHBoxLayout* aLoadLayout = new QHBoxLayout(aMacroPane); //!!
-       aLoadLayout->addStretch();
-
-       QPushButton* aLoadBtn = new QPushButton(tr("BUT_LOAD"), aMacroPane);
-       connect(aLoadBtn, SIGNAL(clicked()), this, SLOT(loadGraph()));
+  if ( getenv( "ENABLE_MACRO_NODE" ) != NULL ) {
+    QWidget* aMacroPane = new QWidget(myTabPane);
+    QVBoxLayout* aMacroLayout = new QVBoxLayout(aMacroPane, 0, 4);
+    aMacroLayout->setMargin(5);
+    aMacroLayout->setSpacing(10);
+    
+    QHBoxLayout* aLoadLayout = new QHBoxLayout(aMacroPane); //!!
+    aLoadLayout->addStretch();
+    
+    QPushButton* aLoadBtn = new QPushButton(tr("BUT_LOAD"), aMacroPane);
+    connect(aLoadBtn, SIGNAL(clicked()), this, SLOT(loadGraph()));
 
-       aLoadLayout->addWidget(aLoadBtn);
+    aLoadLayout->addWidget(aLoadBtn);
 
-       aMacroLayout->addLayout(aLoadLayout);
+    aMacroLayout->addLayout(aLoadLayout);
  
-       myMacroPane = new QListView(aMacroPane);
-       myMacroPane->addColumn(tr("COL_COMPONENTS"));
-       myMacroPane->addColumn(tr("COL_PORTTYPE"));
-       myMacroPane->addColumn(tr("COL_PORTWAY"));
-       myMacroPane->setColumnAlignment(1, AlignLeft);
-       myMacroPane->setColumnAlignment(2, AlignLeft);
-       myMacroPane->setColumnAlignment(3, AlignLeft);
-       myMacroPane->setSelectionMode(QListView::Extended);
-       myMacroPane->setRootIsDecorated(true);
-       aMacroLayout->addWidget(myMacroPane); //!!
-
-       QPushButton* aAddBtn = new QPushButton(tr("TIT_ADDFNODE"), aMacroPane);
-       connect(aAddBtn, SIGNAL(clicked()), this, SLOT(addMacroNode()));
-       aAddBtn->setDefault(true); 
-
-       aMacroLayout->addWidget(aAddBtn);
-
-       myTabPane->addTab(aMacroPane, tr("MACRO_PANE"));
-       }
+    myMacroPane = new QListView(aMacroPane);
+    myMacroPane->addColumn(tr("COL_COMPONENTS"));
+    myMacroPane->addColumn(tr("COL_PORTTYPE"));
+    myMacroPane->addColumn(tr("COL_PORTWAY"));
+    myMacroPane->setColumnAlignment(1, AlignLeft);
+    myMacroPane->setColumnAlignment(2, AlignLeft);
+    myMacroPane->setColumnAlignment(3, AlignLeft);
+    myMacroPane->setSelectionMode(QListView::Extended);
+    myMacroPane->setRootIsDecorated(true);
+    aMacroLayout->addWidget(myMacroPane); //!!
+    
+    QPushButton* aAddBtn = new QPushButton(tr("TIT_ADDFNODE"), aMacroPane);
+    connect(aAddBtn, SIGNAL(clicked()), this, SLOT(addMacroNode()));
+    aAddBtn->setDefault(true); 
+    
+    aMacroLayout->addWidget(aAddBtn);
 
+    myTabPane->addTab(aMacroPane, tr("MACRO_PANE"));
+  }
+  
   aMainLayout->addWidget(myTabPane);
 
   // Close button
@@ -384,33 +384,24 @@ void SUPERVGUI_Service::addComputeNode() {
          const char* interface = item->parent()->text(0).latin1();
          const char* component = item->parent()->parent()->text(0).latin1();
          SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(aDesktop->getComponentName(component));
-         if (myComponent==NULL) {
+         if ( myComponent == NULL ) {
            QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
-         } else {
+         } 
+         else {
            const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service);
-           b  = true;
-           
-           SUPERV_CNode node = aMain->getDataflow()->CNode(*myService);
-           if (CORBA::is_nil(node)) {
+           SUPERV_CNode aNode = aMain->getDataflow()->CNode(*myService);
+           if ( CORBA::is_nil( aNode ) ) {
              QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));    
              return;
            }
-           //to appear a new node in the top-left corner of the current viewport
-           int cx, cy;
-           //2.8 point of improvements: Adding node to graph window with taking into account zoom factor
-           QWMatrix aWM = aMain->getCanvasView()->worldMatrix();
-           aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
-           //2.8 point of improvements:
-           cx = (int)((double)cx/aWM.m11());
-           cy = (int)((double)cy/aWM.m22());
-           node->Coords(cx, cy);
-           myX += (int)(NODE_DX*aWM.m11());
-           myY += (int)(NODE_DY*aWM.m22());
-           aMain->addComputeNode(SUPERV::CNode::_narrow(node));
+
+           SUPERV::INode_var aDummyEndNode;
+           addNode( aNode, aDummyEndNode, myX, myY );
+           b = true; // at least one node was added
          }
        }
       }
-      if (!b) {
+      if ( !b ) {
        QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NONODE_TOADD"));
       }
     }
@@ -443,53 +434,31 @@ void SUPERVGUI_Service::addFactoryNode() {
          SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(component);
          if (myComponent==NULL) {
            QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
-         } else {
+         } 
+         else {
            const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service);
-           b  = true;
-           
-           MESSAGE ( " myService->TypeOfNode == " << myService->TypeOfNode ) 
-
-           int cx, cy;
-
-           //2.8 point of improvements: Adding node to graph window with taking into account zoom factor
-           QWMatrix aWM = aMain->getCanvasView()->worldMatrix();
-
+           SUPERV_CNode aNode;
            if ( myService->TypeOfNode == 0 ) { // ComputeNode
-             SUPERV_CNode node = aMain->getDataflow()->CNode(*myService);
-             if (CORBA::is_nil(node)) {
+             aNode = aMain->getDataflow()->CNode(*myService);
+             if (CORBA::is_nil( aNode ) ) {
                QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));          
                return;
              }
-             //to appear a new node in the top-left corner of the current viewport
-             aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
-             //2.8 point of improvements:
-             cx = (int)((double)cx/aWM.m11());
-             cy = (int)((double)cy/aWM.m22());
-             node->Coords(cx, cy);
-             myX += (int)(NODE_DX*aWM.m11());
-             myY += (int)(NODE_DY*aWM.m22());
-             aMain->addComputeNode(SUPERV::CNode::_narrow(node));
-           } else { // Factory Node
-             SUPERV_FNode node = aMain->getDataflow()->FNode(component, interface, *myService);
-             if (CORBA::is_nil(node)) {
+           } 
+           else { // Factory Node
+             aNode = aMain->getDataflow()->FNode(component, interface, *myService);
+             if ( CORBA::is_nil( aNode ) ) {
                QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));          
                return;
              }
-             //to appear a new node in the top-left corner of the current viewport
-             aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
-             //2.8 point of improvements:
-             cx = (int)((double)cx/aWM.m11());
-             cy = (int)((double)cy/aWM.m22());
-             node->Coords(cx, cy);
-             myX += (int)(NODE_DX*aWM.m11());
-             myY += (int)(NODE_DY*aWM.m22());
-             aMain->addComputeNode(SUPERV::CNode::_narrow(node));
-             
            }
+           SUPERV::INode_var aDummyEndNode;
+           addNode( aNode, aDummyEndNode, myX, myY );
+           b = true;
          }
        }
       }
-      if (!b) {
+      if ( !b ) {
        QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NONODE_TOADD"));
       }
     }
@@ -501,63 +470,44 @@ void SUPERVGUI_Service::addInlineNode() {
   SUPERVGUI_Main* aMain = Supervision.getMain();
   if (aMain==0) {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
-  } else if (!aMain->isEditable()) {
+  } 
+  else if (!aMain->isEditable()) {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));        
-  } else {
+  } 
+  else {
     int aSel = myTypeCombo->currentItem();
-    int cx, cy;
-
-    //2.8 point of improvements: Adding node to graph window with taking into account zoom factor
-    QWMatrix aWM = aMain->getCanvasView()->worldMatrix();
-
     switch (aSel) {
     case 0: // Computation
       {        
-       SUPERV_INode aNode = aMain->getDataflow()->INode(myScriptPane->getFuncName().latin1(), 
+       SUPERV_CNode aNode = aMain->getDataflow()->INode(myScriptPane->getFuncName().latin1(), 
                                                         (myScriptPane->getFunction()).in());
        if (CORBA::is_nil(aNode)) {
          QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
          return;
        }
-       //to appear a new node in the top-left corner of the current viewport
-       aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
-       //2.8 point of improvements:
-       cx = (int)((double)cx/aWM.m11());
-       cy = (int)((double)cy/aWM.m22());
-       aNode->Coords(cx, cy);
-       myX += (int)(NODE_DX*aWM.m11());
-       myY += (int)(NODE_DY*aWM.m22());
-       aMain->addComputeNode(SUPERV::CNode::_narrow(aNode));
+       SUPERV::INode_var aDummyEndNode;
+       addNode( aNode, aDummyEndNode, myX, myY );
       }
       break;
       
     case 1: // Switch
       {
        SUPERV_INode aEndNode;
-       SUPERV_SNode aStartNode = aMain->getDataflow()->SNode(myScriptPane->getFuncName().latin1(),
+       SUPERV_CNode aStartNode = aMain->getDataflow()->SNode(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;
        }
-       //to appear a new node in the top-left corner of the current viewport
-       aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
-       //2.8 point of improvements:
-       cx = (int)((double)cx/aWM.m11());
-       cy = (int)((double)cy/aWM.m22());
-       aStartNode->Coords(cx, cy);
-       aEndNode->Coords(cx + LABEL_WIDTH*2, cy);
-       myX += (int)(NODE_DX*aWM.m11());
-       myY += (int)(NODE_DY*aWM.m22());
-       aMain->addControlNode(SUPERV::CNode::_narrow(aStartNode), SUPERV::CNode::_narrow(aEndNode), true);
+       addNode( aStartNode, aEndNode, myX, myY );
       }
       break;
       
     case 2: // Loop
       {
        SUPERV_INode aEndNode;
-       SUPERV_LNode aStartNode = aMain->getDataflow()->LNode(myInitPane->getFuncName().latin1(), (myInitPane->getFunction()).in(),
+       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);
@@ -565,22 +515,13 @@ void SUPERVGUI_Service::addInlineNode() {
          QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
          return;
        }
-       //to appear a new node in the top-left corner of the current viewport
-       aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
-       //2.8 point of improvements:
-       cx = (int)((double)cx/aWM.m11());
-       cy = (int)((double)cy/aWM.m22());
-       aStartNode->Coords(cx, cy);
-       aEndNode->Coords(cx + LABEL_WIDTH*2, cy);
-       myX += (int)(NODE_DX*aWM.m11());
-       myY += (int)(NODE_DY*aWM.m22());
-       aMain->addControlNode(SUPERV::CNode::_narrow(aStartNode), SUPERV::CNode::_narrow(aEndNode), true);
+       addNode( aStartNode, aEndNode, myX, myY );
       }
       break;
       
     case 3: // GoTo
       {
-       SUPERV_GNode aGotoNode;
+       SUPERV_CNode aGotoNode;
        if (myScriptPane->isDefined()) 
          aGotoNode = aMain->getDataflow()->GNode(myScriptPane->getFuncName().latin1(), 
                                                  (myScriptPane->getFunction()).in(), "");
@@ -590,15 +531,8 @@ void SUPERVGUI_Service::addInlineNode() {
          QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
          return;
        }
-       //to appear a new node in the top-left corner of the current viewport
-       aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
-       //2.8 point of improvements:
-       cx = (int)((double)cx/aWM.m11());
-       cy = (int)((double)cy/aWM.m22());
-       aGotoNode->Coords(cx, cy);
-       myX += (int)(NODE_DX*aWM.m11());
-       myY += (int)(NODE_DY*aWM.m22());
-       aMain->addGOTONode(SUPERV::GNode::_narrow(aGotoNode));
+       SUPERV::INode_var aDummyEndNode;
+       addNode( aGotoNode, aDummyEndNode, myX, myY );
       }
       break;
     }
@@ -609,11 +543,13 @@ void SUPERVGUI_Service::addMacroNode() {
   SUPERVGUI_Main* aMain = Supervision.getMain();
   if (aMain==0) {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
-  } else if (!aMain->isEditable()) {
+  } 
+  else if (!aMain->isEditable()) {
     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));        
-  } else {
-    if (myMFile) {
-      SUPERV_Graph aNode;
+  } 
+  else {
+    if ( myMFile ) {
+      SUPERV_CNode aNode;
       if (aMain->getDataflow()->IsStreamGraph()) {
        SUPERV_StreamGraph aSGraph = aMain->getDataflow()->ToStreamGraph();
        if (!SUPERV_isNull(aSGraph)) 
@@ -629,18 +565,9 @@ void SUPERVGUI_Service::addMacroNode() {
        QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));         
        return;
       }
-      //to appear a new node in the top-left corner of the current viewport
-      int cx, cy;
-      //2.8 point of improvements: Adding node to graph window with taking into account zoom factor
-      QWMatrix aWM = aMain->getCanvasView()->worldMatrix();
-      aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
-      //2.8 point of improvements:
-      cx = (int)((double)cx/aWM.m11());
-      cy = (int)((double)cy/aWM.m22());
-      aNode->Coords(cx, cy);
-      myX += (int)(NODE_DX*aWM.m11());
-      myY += (int)(NODE_DY*aWM.m22());
-      aMain->addMacroNode(SUPERV::CNode::_narrow(aNode));
+
+      SUPERV::INode_var aDummyEndNode;
+      addNode( aNode, aDummyEndNode, myX, myY );
     }
     else {
       QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NONODE_TOADD"));
@@ -725,30 +652,53 @@ void SUPERVGUI_Service::tabChanged(QWidget* theWidget) {
 //*****************************************************
 //  Pane for Python script editing
 //*****************************************************
-SUPERVGUI_PythonEditPane::SUPERVGUI_PythonEditPane(QWidget* theParent) 
-  : QFrame(theParent)
+SUPERVGUI_PythonEditPane::SUPERVGUI_PythonEditPane( QWidget* theParent, const bool isNodeCreation ) 
+  : myIsWithLibrary( isNodeCreation ), 
+    QFrame( theParent )
 {
-  QGridLayout* aEditLayout = new QGridLayout(this, 2, 4);
+  QGridLayout* aEditLayout = new QGridLayout( this, 2, 8, 0, 6 );
 
   // First row
+  if ( myIsWithLibrary ) {
+    QPushButton* aLibBtn = new QPushButton(tr("BUT_LIBRARY"), this);
+    connect(aLibBtn, SIGNAL(clicked()), this, SLOT(library()));
+    aEditLayout->addMultiCellWidget( aLibBtn, 0, 0, 1, 2 );
+  }
+
   QPushButton* aLoadBtn = new QPushButton(tr("BUT_LOAD"), this);
   connect(aLoadBtn, SIGNAL(clicked()), this, SLOT(loadFile()));
   
-  aEditLayout->addWidget(aLoadBtn, 0, 2);
+  aEditLayout->addMultiCellWidget( aLoadBtn, 0, 0, 3, 4 );
 
-  myNextBtn = new QPushButton(tr("BUT_NEXT"), this);
-  myNextBtn->setEnabled(false);
-  connect(myNextBtn, SIGNAL(clicked()), this, SLOT(readFunction()));
+  myFunctionsCombo = new QComboBox( this );
+  connect( myFunctionsCombo, SIGNAL( activated( int ) ), this, SLOT( readFunction( int ) ) );
   
-  aEditLayout->addWidget(myNextBtn, 0, 3);
+  aEditLayout->addMultiCellWidget( myFunctionsCombo, 0, 0, 5, 7 );
   
   //Second row
   myText = new QTextEdit(this);
-  myText->setWordWrap(QTextEdit::FixedColumnWidth);
-  myText->setWrapColumnOrWidth(80);
+  myText->setTextFormat( Qt::PlainText ); // NOT rich text, so text() returns plain text
+  myText->setWordWrap( QTextEdit::FixedColumnWidth );
+  myText->setWrapColumnOrWidth( 80 );
   connect( myText, SIGNAL( returnPressed() ), this, SLOT( autoIndentLine() ) );
 
-  aEditLayout->addMultiCellWidget(myText, 1, 1, 0, 3);
+  aEditLayout->addMultiCellWidget( myText, 1, 1, 0, 7 );
+  //aEditLayout->setColStretch( 3, 1 ); // to allow myFunctionsCombo be larger when needed
+}
+
+/**
+ * Return a text between "def" and "("
+ * "def" must begin with position 0, which means that only global function definitions are possible
+ */ 
+QString getFunctionName( const QString& aLine ) {
+  int aDefPos = aLine.find("def");
+  if ( aDefPos == 0 ) { // only global function definitions!
+    int aStart = aLine.find(" ", aDefPos);
+    int aEnd = aLine.find("(", aStart);
+    QString aName = aLine.mid(aStart, (aEnd-aStart));
+    return aName.stripWhiteSpace();
+  }
+  return QString();
 }
    
 /**
@@ -772,6 +722,8 @@ void SUPERVGUI_PythonEditPane::initPyFunctions( QTextStream& theStream ) {
       aLine = theStream.readLine();
     
     if ( !aLine.isNull() && aLine.find("def") == 0 ) { 
+      myFunctionsCombo->insertItem( getFunctionName( aLine ) ); // aLine now == function name 
+
       aPyFunction += aLine;
       aPyFunction += '\n'; 
 
@@ -779,7 +731,9 @@ void SUPERVGUI_PythonEditPane::initPyFunctions( QTextStream& theStream ) {
       aLine = theStream.readLine();
       // asv : 23.11.04 : added "|| aLine.isEmpty()" - fix for PAL6870. readLine() returns an empty
       //       string for "\n" string, it trails \n caracter.  but we accept such lines..
-      while ( !aLine.isNull() && ( aLine.isEmpty() || aLine[0].isSpace() ) ) {
+      // asv : 22.12.04 : aLine[0].isSpace() || aLine[0]=='#' -> line must begin with space or tab
+      //       (a normal code with indentation) or comment sign.
+      while ( !aLine.isNull() && ( aLine.isEmpty() || aLine[0].isSpace() || aLine[0] == '#' ) ) {
        aPyFunction += aLine;
        aPyFunction += '\n'; 
        aLine = theStream.readLine();
@@ -810,8 +764,7 @@ void SUPERVGUI_PythonEditPane::loadFile() {
   }
 
   myPyFunctions.clear();
-  myPyIndex = -1;
-  myNextBtn->setEnabled( false );
+  myFunctionsCombo->clear();
   myText->clear();
 
   QTextStream aFileReader(&aFile);
@@ -823,11 +776,8 @@ void SUPERVGUI_PythonEditPane::loadFile() {
 
   initPyFunctions( aFileReader );
 
-  if ( myPyFunctions.size() ) {
-    myNextBtn->setEnabled( true );
-    myPyIndex = 0;
-    readFunction();
-  }
+  if ( myPyFunctions.size() )
+    readFunction( 0 );
 }
   
 /**
@@ -835,30 +785,28 @@ void SUPERVGUI_PythonEditPane::loadFile() {
  * asv : Comment above is old! Present model: just take an already read string = PyFunction
  * from the list which is filled in loadFile().
  */
-void SUPERVGUI_PythonEditPane::readFunction() {
+void SUPERVGUI_PythonEditPane::readFunction( int i ) {
   myText->clear();
-  if ( myPyIndex != -1 && myPyFunctions.size() && myPyFunctions.size() > myPyIndex )
-    myText->append( myPyFunctions[ myPyIndex++ ] );
-  if ( myPyFunctions.size() <= myPyIndex ) // last index was reached
-    myNextBtn->setEnabled( false );
+  if ( i != -1 && myPyFunctions.size() && myPyFunctions.size() > i )
+    myText->append( myPyFunctions[ i ] );
+
+  // asv : 30.11.04 : 2.7 - Inline node function editor improvement
+  // 2.7.1 - set focus to editor widget on editor window opening
+  // 2.7.2 - scroll to the beginning of function on editor window opening
+  myText->setFocus();
+  myText->ensureVisible( 0,0 );
 }
 
 /**
  * Returns the text after "def" and before "(" -- first defined function name
  */
 QString SUPERVGUI_PythonEditPane::getFuncName() {
-  QString aName("");
   for (int i=0; i < myText->paragraphs(); i++) {
-    QString aLine = myText->text(i);
-    int aDefPos = aLine.find("def");
-    if (aDefPos == 0) {
-      int aStart = aLine.find(" ", aDefPos);
-      int aEnd = aLine.find("(", aStart);
-      QString aName = aLine.mid(aStart, (aEnd-aStart));
-      return aName.stripWhiteSpace();
-    }
+    QString aName = getFunctionName( myText->text(i) );
+    if ( !aName.isEmpty() )
+      return aName;
   }
-  return aName;
+  return QString();
 }
 
 /**
@@ -882,8 +830,8 @@ SUPERV_Strings SUPERVGUI_PythonEditPane::getFunction() {
 
 
 void SUPERVGUI_PythonEditPane::setFunction(SUPERV_Strings theStr) {
-  int aLen = theStr->length();
-  for (int i=0; i < aLen; i++)
+  myText->clear();
+  for ( int i=0, aLen = theStr->length(); i < aLen; i++ )
     myText->append(QString(theStr[i]));
 
   // asv : 30.11.04 : 2.7 - Inline node function editor improvement
@@ -928,12 +876,20 @@ void SUPERVGUI_PythonEditPane::autoIndentLine() {
   }
 }
 
+/**
+ * Create a node by loading it from an external XML library file
+ * This slot opens a dialog box which then "lives" by itself..
+ */
+void SUPERVGUI_PythonEditPane::library() {
+  SUPERVGUI_LibDlg* aDlg = new SUPERVGUI_LibDlg( this );
+  aDlg->exec();
+}
 
 /*!
  * Edit Python dialog
  */
-SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg(bool isLoop)
-  :QDialog(QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg( bool isLoop )
+  :QDialog(QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu) 
 {
   setSizeGripEnabled( true );
   setCaption(tr("TIT_FUNC_PYTHON"));
@@ -941,18 +897,18 @@ SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg(bool isLoop)
   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4);
   if (isLoop) {
     QTabWidget* aLoopTabPane = new QTabWidget(this);
-    myInitPane = new SUPERVGUI_PythonEditPane(this); 
+    myInitPane = new SUPERVGUI_PythonEditPane( this, false ); // library == false, since no creation of a node is needed here
     aLoopTabPane->addTab(myInitPane, "Init");
     
-    myMorePane = new SUPERVGUI_PythonEditPane(this);
+    myMorePane = new SUPERVGUI_PythonEditPane( this, false );
     aLoopTabPane->addTab(myMorePane, "More");
     
-    myNextPane = new SUPERVGUI_PythonEditPane(this);
+    myNextPane = new SUPERVGUI_PythonEditPane( this, false );
     aLoopTabPane->addTab(myNextPane, "Next");
 
     aMainLayout->addWidget(aLoopTabPane);    
   } else {
-    myEditPane = new SUPERVGUI_PythonEditPane(this);
+    myEditPane = new SUPERVGUI_PythonEditPane( this, false );
     aMainLayout->addWidget(myEditPane);
   }
   QGroupBox* aBtnBox = new QGroupBox( this );
@@ -974,3 +930,40 @@ SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg(bool isLoop)
 
   aMainLayout->addWidget(aBtnBox);
 }
+
+/**
+ * Do the following actions for newly created Engine's CNode:
+ * 1. Create a presentation for it (CanvasNode)
+ * 2. Place the CanvasNode to the current top-left corner or the current viewport
+ * 3. Increment the coordinates of the next CanvasNode (new nodes are "cascaded" when several of them are created at once)
+ * PS theEndNode is passed only for Loop and Switch nodes (EndLoop and EndSwitch)
+ */ 
+void SUPERVGUI_Service::addNode( SUPERV::CNode_var theNode, SUPERV::INode_var theEndNode, int& theX, int& theY )  {
+  if ( !CORBA::is_nil( theNode ) ) {
+    int cx, cy;   //to appear a new node in the top-left corner of the current viewport
+    SUPERVGUI_Main* aMain = Supervision.getMain();
+
+    //2.8 point of improvements: Adding node to graph window with taking into account zoom factor
+    QWMatrix aWM = aMain->getCanvasView()->worldMatrix();
+    aMain->getCanvasView()->viewportToContents(theX, theY, cx, cy);
+
+    //2.8 point of improvements:
+    cx = (int)((double)cx/aWM.m11());
+    cy = (int)((double)cy/aWM.m22());
+    theNode->Coords(cx, cy);
+    if ( !CORBA::is_nil( theEndNode ) )
+      theEndNode->Coords(cx + LABEL_WIDTH*2, cy);
+    theX += (int)(NODE_DX*aWM.m11());
+    theY += (int)(NODE_DY*aWM.m22());
+
+    if ( theNode->IsGOTO() )
+      aMain->addGOTONode( theNode );
+    else if ( theNode->IsMacro() )
+      aMain->addMacroNode( theNode );
+    else if ( theNode->IsLoop() || theNode->IsSwitch() )
+      aMain->addControlNode( theNode, SUPERV::CNode::_narrow( theEndNode ), true );
+    else
+      aMain->addComputeNode( theNode );
+  }  
+}
+
index bc3fabe781ca3a2467f5b8ec85fe4d09ac00f9fd..0bba98c93086cb36ab04c65160bc79edbc0d41c6 100644 (file)
@@ -34,15 +34,17 @@ using namespace std;
 #include <qhgroupbox.h>
 #include <qwidgetstack.h>
 
+class QListBox; 
 
-//*****************************************************
-//  Pane for Python script editing
-//*****************************************************
+/*!
+ * Pane for Python script editing
+ */
 class SUPERVGUI_PythonEditPane: public QFrame {
+
   Q_OBJECT
 
- public:
-  SUPERVGUI_PythonEditPane(QWidget* theParent);
+public:
+  SUPERVGUI_PythonEditPane( QWidget* theParent, const bool isNodeCreation );
   ~SUPERVGUI_PythonEditPane() {};
   
   QString getFuncName();
@@ -53,14 +55,23 @@ class SUPERVGUI_PythonEditPane: public QFrame {
   SUPERV_Strings getFunction();
   void setFunction(SUPERV_Strings theStr);
     
- public slots:
+public slots:
+  // load all functions from an XML file into internal structures 
   void loadFile();
-  void readFunction();
-  void autoIndentLine();
 
- private:
+  // when user presses "Enter" - automatically set indentation of next line
+  void autoIndentLine(); 
+
+  // when user select another function name in combo box - fill myText with its body
+  void readFunction( int i ); 
+
+  // when user presses "Library" button - open a "Create node from Library" dialog
+  void library();
+
+private:
+  bool         myIsWithLibrary;
   QTextEdit*   myText;
-  QPushButton* myNextBtn;
+  QComboBox*   myFunctionsCombo;
 
   // fills myPyFunctions list.  called from loadFile() after user selects a file.
   void         initPyFunctions( QTextStream& );
@@ -69,31 +80,37 @@ class SUPERVGUI_PythonEditPane: public QFrame {
   // in readFunction()
   QStringList  myPyFunctions; 
 
-  // index of currently displayed Python function
-  int          myPyIndex;
 };
 
-
-//*****************************************************
-//  Dialog box for node creation
-//*****************************************************
-
+/*!
+ * Dialog box for node creation
+ */
 class SUPERVGUI_Service: public QDialog {
+
   Q_OBJECT
 
-  public:
+public:
     SUPERVGUI_Service(SALOME_NamingService* ns);
     ~SUPERVGUI_Service();
 
     void choose();
 
- protected:
+    /*!
+     * Do the following actions for newly created Engine's CNode:
+     * 1. Create a presentation for it (CanvasNode)
+     * 2. Place the CanvasNode to the current top-left corner or the current viewport
+     * 3. Increment the coordinates of the next CanvasNode (new nodes are "cascaded" when several of them are created at once)
+     * PS theEndNode is passed only for Loop and Switch nodes (EndLoop and EndSwitch)
+     */ 
+    static void addNode( SUPERV::CNode_var theNode, SUPERV::INode_var theEndNode, int& theX, int& theY );
+
+protected:
     void showEvent(QShowEvent* theEvent);
 
-  private:
+private:
     void initialise();
 
-  private slots:
+private slots:
     void tabChanged(QWidget *);
     void addComputeNode();
     void addFactoryNode();
@@ -102,7 +119,7 @@ class SUPERVGUI_Service: public QDialog {
     void typeNodeSelected(int theRow);
     void loadGraph();
 
-  private:
+private:
     QListView*            components;
     SALOME_NamingService* naming;
     int myX, myY;
@@ -129,9 +146,10 @@ class SUPERVGUI_Service: public QDialog {
  * Edit Python dialog
  */
 class SUPERVGUI_EditPythonDlg: public QDialog {
+
   Q_OBJECT
     
- public:
+public:
   SUPERVGUI_EditPythonDlg(bool isLoop = false);
   ~SUPERVGUI_EditPythonDlg() {};
 
@@ -178,7 +196,7 @@ class SUPERVGUI_EditPythonDlg: public QDialog {
   void setNextFunction(SUPERV_Strings theStr)
     { myNextPane->setFunction(theStr); }
 
- private:
+private:
   SUPERVGUI_PythonEditPane* myEditPane;
   SUPERVGUI_PythonEditPane* myInitPane;
   SUPERVGUI_PythonEditPane* myMorePane;
index 703635d8fe266fc0197cbe690510413ce39d2da2..1557103ea5bf723ba8ae3d23be92ec51be495b48 100644 (file)
@@ -642,6 +642,9 @@ msgstr "EndOf"
 msgid "BUT_LOAD"
 msgstr "Load from file..."
 
+msgid "BUT_LIBRARY"
+msgstr "Library..."
+
 msgid "BUT_NEXT"
 msgstr "Next Function"
 
@@ -738,3 +741,39 @@ msgstr "Incompatible types"
 msgid "MSG_INVALID_LINK"
 msgstr "Warning: the link connect ports of incompatible types.\nYou may keep it and edit types of ports before execution\nor you may remove it now."
 
+msgid "BUT_REMOVE"
+msgstr "Remove"
+
+msgid "MNU_EXPORT"
+msgstr "Export to Library"
+
+msgid "MSG_BAD_INODE"
+msgstr "InLine node export error:\nThe selected node does not seem to be a valid InLine node."
+
+msgid "MSG_ERROR_LIB1"
+msgstr "Error creating a library file and opening for writing."
+
+msgid "MSG_ERROR_LIB_IS_RECREATE"
+msgstr "Library file is corrupt (bad XML structure).  Remove it and create a new one?"
+
+msgid "MSG_ERROR_LIB_IO"
+msgstr "Unknown I/O error occured creating new library file."
+
+msgid "MSG_ERROR_LIB_WRITE"
+msgstr "Error writing library file!"
+
+msgid "MSG_ERROR_LIB_NIL_NODE"
+msgstr "Error: the node to be exported is NULL"
+
+msgid "MSG_ERROR_LIB_NIL_COUPLED"
+msgstr "Error: the coupled node of the exported node is NULL"
+
+msgid "MSG_ERROR_LIB_NIL_COUPLED"
+msgstr "Error: the coupled node of the exported node is NULL"
+
+msgid "MSG_ERROR_LIB_BAD_LOOP"
+msgstr "Error: the Loop/EndLoop nodes pair is incorrect."
+
+msgid "MSG_ERROR_LIB_BAD_SWITCH"
+msgstr "Error: the Switch/EndSwitch nodes pair is incorrect."
+