Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_CanvasNodePrs.cxx
index cda5aaf2762d5a9c2a1a7a0b7d841b54bb277b4f..c5d107df1af309255346fb8becba5789ed54c315 100644 (file)
@@ -1,16 +1,36 @@
 //  SUPERV SUPERVGUI : GUI for Supervisor component
 //
-//  Copyright (C) 2003  OPEN CASCADE
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //  File   : SUPERVGUI_GanvasNodePrs.cxx
 //  Author : Natalia KOPNOVA
 //  Module : SUPERV
 
-using namespace std;
 #include "SUPERVGUI_CanvasNodePrs.h"
 #include "SUPERVGUI_CanvasNode.h"
 #include "SUPERVGUI_CanvasPort.h"
 #include "SUPERVGUI_Canvas.h"
+#include "SUPERVGUI_CanvasCellNodePrs.h"
+#include "SUPERVGUI_Main.h"
+
+#include "SUIT_ResourceMgr.h"
 
 //#define CHECKTIME
 
@@ -18,7 +38,7 @@ using namespace std;
 #include <sys/timeb.h>
 #endif
 
-#define PORT_MARGIN 2
+//#define PORT_MARGIN 2
 #undef PORT_HEIGHT // to avoid warning message
 #define PORT_HEIGHT LABEL_HEIGHT
 #define TEXT_MARGIN 5
@@ -27,10 +47,12 @@ using namespace std;
 //=====================================================================
 // Node presentation
 //=====================================================================
-SUPERVGUI_CanvasNodePrs::SUPERVGUI_CanvasNodePrs(QCanvas* theCanvas, 
-                                                SUPERVGUI_CanvasNode* theNode):
+SUPERVGUI_CanvasNodePrs::SUPERVGUI_CanvasNodePrs( SUIT_ResourceMgr* mgr, QCanvas* theCanvas, 
+                                                 SUPERVGUI_CanvasNode* theNode,
+                                                 bool theCellPrs):
   QCanvasPolygonalItem(theCanvas),
-  myNode(theNode)
+  myNode(theNode),
+  myMgr( mgr )
 {
   Trace("SUPERVGUI_CanvasNodePrs::SUPERVGUI_CanvasNodePrs");
   myWidth = LABEL_WIDTH;
@@ -46,25 +68,34 @@ SUPERVGUI_CanvasNodePrs::SUPERVGUI_CanvasNodePrs(QCanvas* theCanvas,
 
   myLabelVisible = true;
   myPortVisible = true;
+  myCellPrs = theCellPrs;
 
-  myColor = MAIN_BACK;
+  myColor = mgr->colorValue( "SUPERVGraph", "NodeBody", DEF_MAIN_BACK );
 
-  // create in/out connection points prs
-  myPointIn = new SUPERVGUI_CanvasHookPrs(theCanvas, this, true);
-  myPointOut = new SUPERVGUI_CanvasHookPrs(theCanvas, this, false);
+  if (!myCellPrs) {
+    // create in/out connection points prs
+    myPointIn = new SUPERVGUI_CanvasHookPrs(theCanvas, this, true);
+    myPointOut = new SUPERVGUI_CanvasHookPrs(theCanvas, this, false);
 
-  setZ(0);
-  setState(myNode->getEngine()->State());
-  updatePorts();
+    setZ(0);
+    setState(myNode->getEngine()->State());
+    updatePorts();
+  }
 }
 
 
 SUPERVGUI_CanvasNodePrs::~SUPERVGUI_CanvasNodePrs() 
 {
-  Trace("SUPERVGUI_CanvasNodePrs::~SUPERVGUI_CanvasNodePrs");
-  if (myPointIn) delete myPointIn;
-  if (myPointOut) delete myPointOut;
-  hide();
+  if ( !myCellPrs ) {
+    if ( myPointIn ) {
+      delete myPointIn;
+      myPointIn = 0;
+    }
+    if ( myPointOut ) {
+      delete myPointOut;
+      myPointOut = 0;
+    }
+  }
 }
 
 int SUPERVGUI_CanvasNodePrs::rtti() const
@@ -199,8 +230,10 @@ void SUPERVGUI_CanvasNodePrs::moveBy(double dx, double dy)
     }
   }
 
-  myPointIn->moveBy(dx, dy);
-  myPointOut->moveBy(dx, dy);
+  if (!myCellPrs) {
+    myPointIn->moveBy(dx, dy);
+    myPointOut->moveBy(dx, dy);
+  }
 }
 
 void SUPERVGUI_CanvasNodePrs::setZ(double z)
@@ -257,7 +290,7 @@ void SUPERVGUI_CanvasNodePrs::setLabelVisible(bool b)
 
   myLabelVisible = b;
   updatePorts();
-  if (!isPortVisible()) updatePoints();
+  if (!isPortVisible() && !myCellPrs) updatePoints();
 
   if (aDisp) {
     show();
@@ -272,16 +305,20 @@ void SUPERVGUI_CanvasNodePrs::setPortVisible(bool b)
 
   myPortVisible = b;
   if (b) {
-    myPointIn->hide();
-    myPointOut->hide();
+    if (!myCellPrs) {
+      myPointIn->hide();
+      myPointOut->hide();
+    }
 
     updateGates();
   }
   else {
-    updatePoints();
-
-    myPointIn->show();
-    myPointOut->show();
+    if (!myCellPrs) {
+      updatePoints();
+      
+      myPointIn->show();
+      myPointOut->show();
+    }
   }
 
   const QObjectList* list = myNode->children();
@@ -511,14 +548,38 @@ void drawText(QPainter& thePainter, const QString& theText,
   int flags = theHAlign | Qt::AlignVCenter;
   QRect r(theRect.x() + TEXT_MARGIN, theRect.y(), 
          theRect.width() - 2*TEXT_MARGIN, theRect.height());
-  thePainter.drawText(r, flags, theText);
+
+  QWMatrix aMat = thePainter.worldMatrix();
+  if (aMat.m11() != 1.0) { 
+    // for scaled picture only
+    QRect r1 = aMat.mapRect(r);
+    QFont saved = thePainter.font();
+    QFont f(saved);
+    if (f.pointSize() == -1) {
+      f.setPixelSize((int)(f.pixelSize()*aMat.m11()));
+    }
+    else {
+      f.setPointSize((int)(f.pointSize()*aMat.m11()));
+    }
+    thePainter.save();
+    QWMatrix m;
+    thePainter.setWorldMatrix(m);
+    thePainter.setFont(f);
+    thePainter.drawText(r1, flags, theText);
+    thePainter.setFont(saved);
+    thePainter.restore();
+  }
+  else {
+    thePainter.drawText(r, flags, theText);
+  }
 }
 
 void SUPERVGUI_CanvasNodePrs::draw(QPainter& thePainter) 
 {
   thePainter.setPen(pen());
   thePainter.setBrush(nodeColor());
-  drawShape(thePainter);
+  if ( !CORBA::is_nil( myNode->getMain()->getDataflow()->Node( myNode->name() ) ) ) // mkr : IPAL11360
+    drawShape(thePainter);
 }
 
 void SUPERVGUI_CanvasNodePrs::drawShape(QPainter& thePainter) 
@@ -555,7 +616,7 @@ void SUPERVGUI_CanvasNodePrs::drawFrame(QPainter& thePainter)
 void SUPERVGUI_CanvasNodePrs::drawTitle(QPainter& thePainter) 
 {
   QBrush saved = thePainter.brush();
-  QBrush br(MAIN_TITLE);
+  QBrush br( myMgr->colorValue( "SUPERVGraph", "Title", DEF_MAIN_TITLE ) );
   thePainter.setBrush(br);
   drawTitleShape(thePainter);
   thePainter.setBrush(saved);
@@ -628,7 +689,12 @@ void SUPERVGUI_CanvasNodePrs::drawPort(QPainter& thePainter)
       ++it;
       if (obj->inherits("SUPERVGUI_CanvasPort")) {
        aPort = (SUPERVGUI_CanvasPort*) obj;
-       if (!aPort->getEngine()->IsGate()) {
+
+       SUPERV_Port aPortEng = aPort->getEngine();
+       //      if ( CORBA::is_nil( aPortEng ) )
+       //        printf ( "---\n port engine IS NIL ---\n\n" );
+
+       if ( !CORBA::is_nil( aPortEng ) && !aPortEng->IsGate() ) {
          aPort->getPrs()->draw(thePainter);
        }
       }
@@ -644,7 +710,7 @@ void SUPERVGUI_CanvasNodePrs::drawGate(QPainter& thePainter)
   QRect r = getGateRect();
   //  r.setHeight(r.height()+1);
   thePainter.drawRect(r);
-  int x0 = (r.left() + r.right())/2;
+  //int x0 = (r.left() + r.right())/2;
   //  thePainter.drawLine(x0, r.top(), x0, r.bottom());
 
   const QObjectList* list = myNode->children();
@@ -700,13 +766,21 @@ void SUPERVGUI_CanvasNodePrs::setState(SUPERV::GraphState theState)
     myStatusColor = red;
     break;
 
+  case SUPERV::LoadingState:
+    myStatus = "Loading";
+    myStatusColor = QColor(56,255,56);
+    break;
+
   default:
     myStatus = "No Status";
-    myStatusColor = MAIN_BACK;
+    myStatusColor = myMgr->colorValue( "SUPERVGraph", "NodeBody", DEF_MAIN_BACK );
     break;
   }
 
-  long sec = myNode->getEngine()->CpuUsed();
+  long sec = 0;
+  // IPAL9273, 9369, 9731
+  if ( theState != SUPERV_Kill && myNode->getMain()->getDataflow()->State() != SUPERV_Kill )
+    sec = myNode->getEngine()->CpuUsed();
   char hms[9];
   long s = sec/3600;
   hms[0]=(char)(((s/10)%10)+48);
@@ -830,9 +904,23 @@ bool SUPERVGUI_CanvasPortPrs::isAlert() const
 QString SUPERVGUI_CanvasPortPrs::getText() const
 {
   SUPERV_Port aPort = myPort->getEngine();
-  QString aText = aPort->Name();
-  if (aPort->IsParam() || aPort->IsInLine() || myPort->isStream())
-    aText = aText + "=" + aPort->ToString();
+  QString aText;
+  if ( !CORBA::is_nil( aPort ) ) {
+    aText = aPort->Name();
+    if (aPort->IsParam() || aPort->IsInLine() || myPort->isStream()) {
+      // mkr : modifications to avoid displaying long IOR's values on nodes' ports,
+      //       display ports type from corresponding XML catalog instead.
+      QString aPortValue = aPort->ToString();
+      QString aPortType = aPort->Type();
+      if ( aPortType.compare("string") // not "string" type
+          &&
+          aPortValue.find("IOR:") >= 0 ) // has IOR:... in value
+       aText = aText + "=" + aPortType;
+      else
+       aText = aText + "=" + aPortValue;
+    }
+  }
+  //  printf( "--- return text of port : %s ---\n", aText.latin1() );
   return aText;
 }
 
@@ -931,7 +1019,7 @@ void SUPERVGUI_CanvasHookPrs::init(QCanvas* theCanvas)
 SUPERVGUI_CanvasHookPrs::~SUPERVGUI_CanvasHookPrs()
 {
   hide();
-  if (myLine) {
+  if ( myLine ) {
     delete myLine;
     myLine = 0;
   }
@@ -940,9 +1028,9 @@ SUPERVGUI_CanvasHookPrs::~SUPERVGUI_CanvasHookPrs()
 QObject* SUPERVGUI_CanvasHookPrs::getObject() const
 {
   QObject* anObj = 0;
-  if (myNodePrs)
+  if ( myNodePrs )
     anObj = myNodePrs->getNode();
-  else if (myPortPrs)
+  else if ( myPortPrs )
     anObj = myPortPrs->getPort();
   return anObj;
 }