]> AND Private Git Repository - blast.git/blobdiff - InterfaceItem.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
changes in output pattern comput
[blast.git] / InterfaceItem.cpp
index 552e15989b990aa9257d362333c66ccfe4cefc9e..10158d7bd7a97a78fb4b3ce1d8e06d6d4559fee6 100644 (file)
@@ -11,7 +11,7 @@ InterfaceItem::InterfaceItem(double _position,
                              int _orientation,
                              ConnectedInterface *_refInter,
                              AbstractBoxItem* _owner,
-                             Parameters* _params){
+                             Parameters* _params) {
   positionRatio = _position;
   orientation = _orientation;
   refInter = _refInter;
@@ -19,10 +19,9 @@ InterfaceItem::InterfaceItem(double _position,
   // CAUTION : the owner must add explicitely this item to its interface, calling addInterface()
   owner = _owner;
   params = _params;
-  selected = false;
-  name = refInter->getName();
+  selected = false;  
   QFontMetrics fmName(params->defaultIfaceFont);
-  nameWidth = fmName.width(name);
+  nameWidth = fmName.width(refInter->getName());
   nameHeight = fmName.height();
   // by default, only data interface are visible
   if (refInter->getPurpose() == AbstractInterface::Data) {
@@ -42,6 +41,18 @@ InterfaceItem::InterfaceItem(){
   this->id = counter++;
 }
 
+QString InterfaceItem::getName() {
+  return refInter->getName();
+}
+
+void InterfaceItem::updateName(QString name) {  
+  QFontMetrics fmName(params->defaultIfaceFont);
+  nameWidth = fmName.width(refInter->getName());
+  nameHeight = fmName.height();
+  updatePosition();
+}
+
+
 /* boundingRect() : give the bounding rect in the blockitem coord. system */
 QRectF InterfaceItem::boundingRect() const {
 
@@ -82,12 +93,14 @@ void InterfaceItem::paint(QPainter *painter) {
 
     if(selected) {
       painter->setPen(QPen(Qt::red,2));
-    }
-    else if(refInter->getLevel() == AbstractInterface::Basic) {
-      painter->setPen(QPen(Qt::darkCyan,1));
-    }
-    else if(refInter->getLevel() == AbstractInterface::Top) {
-      painter->setPen(QPen(Qt::black,1));
+    }    
+    else  {
+      if(owner->isBoxItem()) {
+        painter->setPen(QPen(Qt::black,1));
+      }
+      else if(owner->isSourceItem()) {
+        painter->setPen(QPen(Qt::darkCyan,1));
+      }
     }
 
     painter->translate(originPoint);
@@ -116,6 +129,12 @@ void InterfaceItem::paint(QPainter *painter) {
     }
 
     // draw names
+    if(selected) {
+      painter->setPen(QPen(Qt::red,2));
+    }    
+    else  {
+      painter->setPen(QPen(Qt::black,1));      
+    }
 
     // reset to normal if at west
     if(orientation == Parameters::West){
@@ -133,7 +152,7 @@ void InterfaceItem::paint(QPainter *painter) {
       if(owner->isGroupItem()){
         painter->drawText(-(w+params->arrowWidth+params->arrowLineLength),-h/2,w,h,Qt::AlignLeft | Qt::TextWordWrap, refInter->getName());
       }
-      else if(owner->isBoxItem()){
+      else if((owner->isBoxItem()) || (owner->isSourceItem())){
         painter->drawText(0,-h/2,w,h,Qt::AlignRight | Qt::TextWordWrap, refInter->getName());
       }
     }
@@ -142,7 +161,7 @@ void InterfaceItem::paint(QPainter *painter) {
       if(owner->isGroupItem()) {
         painter->drawText(params->arrowWidth+params->arrowLineLength,-h/2,w,h,Qt::AlignRight | Qt::TextWordWrap, refInter->getName());
       }
-      else if(owner->isBoxItem()) {
+      else if((owner->isBoxItem()) || (owner->isSourceItem())){     
         painter->drawText(-w,-h/2,w,h,Qt::AlignLeft | Qt::TextWordWrap, refInter->getName());
       }
     }    
@@ -151,33 +170,30 @@ void InterfaceItem::paint(QPainter *painter) {
   }
 }
 
-QPointF InterfaceItem::getEndPointInGroup() {
-  QPointF p;
+QPointF InterfaceItem::getStartPosition() {
+  QPointF p = originPoint;
+  QPointF ownerPos = owner->scenePos();  
+  p += ownerPos;
+  return p;
+}
 
-  if (owner->isGroupItem()) {
-    p = originPoint;
-  }
-  else {
-    double x = owner->x() + originPoint.x();
-    double y = owner->y() + originPoint.y();
-    switch(orientation){
-    case Parameters::East:
-      x += params->arrowWidth+params->arrowLineLength;
-      break;
-    case Parameters::North:
-      y -= params->arrowWidth+params->arrowLineLength;
-      break;
-    case Parameters::West:
-      x -= params->arrowWidth+params->arrowLineLength;
-      break;
-    case Parameters::South:
-      y += params->arrowWidth+params->arrowLineLength;
-      break;
-    }
-    p = QPointF(x,y);
+QPointF InterfaceItem::getEndPosition() {
+  QPointF p = getStartPosition();
+  
+  switch(orientation){
+  case Parameters::East:
+    p.setX(p.x()+params->arrowWidth+params->arrowLineLength);
+    break;
+  case Parameters::North:
+    p.setY(p.y() - params->arrowWidth-params->arrowLineLength);
+    break;
+  case Parameters::West:
+    p.setX(p.x() - params->arrowWidth-params->arrowLineLength);
+    break;
+  case Parameters::South:
+    p.setY(p.y() + params->arrowWidth+params->arrowLineLength);
+    break;
   }
-
-  //cout << "iface end point in group item: " << p.x() << "," << p.y() << endl;
   return p;
 }
 
@@ -227,157 +243,7 @@ int InterfaceItem::getIntOrientation(QString str) {
 }
 
 
-/* connectWith() :
-  - modify all necessary attributes in the model to create a connection
-  between current InterfaceItem and iface. Note that the source and destination
-  are deduced from the direction (In, Out) and the type of the owner (funcitonal, group)
-
-  CAUTION: No security checks are done. This method must be called only if canConnectWith has been called and returned true.
-
-  NOTE : conditions so that this InterfaceItem can be connected with inter.
-     (i.e. current one can connect to inter OR inter can connect to current)
-
-     Here are all the possible combinations, depending on the type of the
-     block/item and direction of the interface, which are :
-     GI/GB : a GroupItem referencing a GroupBlock (single solution for GI)
-     BI/FB : a BlockItem referencing a FunctionalBlock
-     BI/GB : a BlockItem referencing a GroupBlock
-
-     For GI/GB:
-     - Input can connect with BI/FB or BI/GB Input
-     - Output can connect with BI/FB or BI/GB Output
-
-     For BI/FB:
-     - Input can connect with:
-         GI/GB Input
-         BI/FB Output
-         BI/GB Output
-     - Output can connect with:
-         GI/GB Output
-         BI/FB Input
-         BI/GB Input
-
-     For BI/GB:
-     - Input can connect with:
-         GI/GB Input
-         BI/FB Output
-         BI/GB Output
-     - Output can connect with:
-         GI/GB Output
-         BI/FB Input
-         BI/GB Input
-
-    And whatever the case an InOut can only connect with an InOut
-    We note that:
-       - the IG does not allow the connect a GI/GB interface to an
-       interface of another GI/GB, thus the case is not considered above.
-       - BI/FB and BI/GB are the same.
-       - the cases where direction are the same only occur when
-       the 2 items are of different type (GI and BI)
-       - the cases where directions are different only occur when
-       the 2 are of both BlockItem
-
-*/
-bool InterfaceItem::connectWith(InterfaceItem *iface) {
-  ConnectedInterface* interThis = refInter; // the reference of this
-  ConnectedInterface* interOther = iface->refInter; // the reference of the other
-  ConnectedInterface* src = NULL, *dest = NULL;
-
-  if(interThis->getDirection() == AbstractInterface::InOut && interOther->getDirection() == AbstractInterface::InOut){
-    /* NOTE: InOut interfaces have both directions and thus are
-       connected from inter1 to inter2 AND inter2 to inter1
-       Another effect is that a InOut can be connected to/from a single
-       InOut.
-    */
-    if((interThis->getConnectedFrom() == NULL) && (interOther->getConnectedFrom() == NULL)) {
-
-      interOther->connectFrom(interThis);
-      interOther->getConnectedTo().append(interThis);
-      interThis->connectFrom(interOther);
-      interThis->getConnectedTo().append(interOther);
-
-      cout << "connecting 2 InOut"<< endl;
-      return true;
-    }
-    return false;
-  }
-  else if (interThis->getDirection() == interOther->getDirection()) {
-
-    // cannot connect  GI to GI or 2 BI of the same direction.
-    if ((getOwner()->isGroupItem()) && (iface->getOwner()->isGroupItem())) return false;
-    if ((getOwner()->isBoxItem()) && (iface->getOwner()->isBoxItem())) return false;
-
-    if (interThis->getDirection() == AbstractInterface::Input) { // both are inputs
-      cout << "connecting GI to BI" << endl;
-      if(getOwner()->isGroupItem()) {
-        src = interThis;
-        dest = interOther;
-      }
-      else {
-        src = interOther;
-        dest = interThis;
-      }
-    }
-    else { // both are outputs
-      cout << "connecting BO to GO" << endl;
-      if(getOwner()->isGroupItem()){
-        src = interOther;
-        dest = interThis;
-      }
-      else {
-        src = interThis;
-        dest = interOther;
-      }
-    }
-  }
-  else {
-    if ((getOwner()->isGroupItem()) || (iface->getOwner()->isGroupItem())) return false;
-
-    cout << "connecting BO to BI" << endl;
-    if(interOther->getDirection() == AbstractInterface::Output) {
-      src = interOther;
-      dest = interThis;
-    }
-    else {
-      src = interThis;
-      dest = interOther;
-    }
-  }
-
-  if(dest != NULL && src != NULL){
-    // cannot overrive existing connectionFrom
-    if(dest->getConnectedFrom() == NULL) {
-      dest->connectFrom(src);
-      src->connectTo(dest);
-      return true;
-    }
-    else {
-      return false;
-    }
-  }
-  return false;
-}
-
-void InterfaceItem::unconnectTo(InterfaceItem *iface)
-{
-  if(iface->refInter->getConnectedFrom() == refInter){
-    iface->refInter->connectFrom(NULL);
-  }
-  if(iface->refInter->getConnectedTo().contains(refInter)){
-    cout << "abnormal case while removing iface conn from " << qPrintable(name) << " to " << qPrintable(iface->name) << endl;
-    iface->refInter->removeConnectedTo(refInter);
-  }
-  if(refInter->getConnectedFrom() == iface->refInter) {
-    cout << "abnormal case while removing iface conn from " << qPrintable(name) << " to " << qPrintable(iface->name) << endl;
-    refInter->connectFrom(NULL);
-  }
-  if(refInter->getConnectedTo().contains(iface->refInter)){
-    refInter->removeConnectedTo(iface->refInter);
-  }
-}
-
-void InterfaceItem::updatePosition()
-{
+void InterfaceItem::updatePosition() {
   if(orientation == Parameters::North || orientation == Parameters::South){
     position = positionRatio * owner->getWidth();
   } else {
@@ -391,7 +257,7 @@ void InterfaceItem::addConnectionItem(ConnectionItem* item) {
 }
 
 void InterfaceItem::removeConnectionItem(ConnectionItem* item) {
-  connections.removeOne(item);
+  connections.removeAll(item);
 }
 
 QDataStream &operator <<(QDataStream &out, InterfaceItem *i) {