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

Private GIT Repository
started top group gen, added project subdirs
[blast.git] / InterfaceItem.cpp
index 0e87a1934d67e8fc30b604466cad3ca2fe7cf4f5..18397f33cd0564239b9003e980bbec8d47630b22 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;
@@ -45,6 +45,14 @@ 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 {
 
@@ -85,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);
@@ -108,17 +118,36 @@ void InterfaceItem::paint(QPainter *painter) {
     }
 
     // draw arrows
-    if(refInter->getDirection() == AbstractInterface::Input) {
-      painter->drawPath(params->inArrow);
+    if ( (refInter->getPurpose() == AbstractInterface::Clock) || (refInter->getPurpose() == AbstractInterface::Reset)) {
+      painter->drawPath(params->clkrstArrow);
+    }
+    else if(refInter->getDirection() == AbstractInterface::Input) {
+      painter->drawPath(params->dataArrowIn);
     }
     else if(refInter->getDirection() == AbstractInterface::Output) {
-      painter->drawPath(params->outArrow);
+      painter->drawPath(params->dataArrowOut);
     } else if(refInter->getDirection() == AbstractInterface::InOut) {
-      painter->drawPath(params->inArrow);
-      painter->drawPath(params->outArrow);
+      painter->drawPath(params->dataArrowIn);
+      painter->drawPath(params->dataArrowOut);
     }
 
+    // paint modifier box if needed
+    ConnectedInterface* connIface = AI_TO_CON(refInter->getAssociatedIface());
+    if ((connIface != NULL) && (connIface->getInputModifier() != NULL)) {
+      painter->save();
+      painter->translate(params->arrowWidth+params->arrowLineLength,0);
+      painter->drawRect(0,-5,10,10);
+      painter->restore();
+    }
+
+
     // 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){
@@ -136,7 +165,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());
       }
     }
@@ -145,42 +174,41 @@ 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());
       }
-    }    
+    }
+
+
 
     painter->restore();
   }
 }
 
-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;
 }
 
@@ -230,157 +258,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(refInter->getName()) << " to " << qPrintable(iface->refInter->getName()) << endl;
-    iface->refInter->removeConnectedTo(refInter);
-  }
-  if(refInter->getConnectedFrom() == iface->refInter) {
-    cout << "abnormal case while removing iface conn from " << qPrintable(refInter->getName()) << " to " << qPrintable(iface->refInter->getName()) << 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 {
@@ -394,7 +272,7 @@ void InterfaceItem::addConnectionItem(ConnectionItem* item) {
 }
 
 void InterfaceItem::removeConnectionItem(ConnectionItem* item) {
-  connections.removeOne(item);
+  connections.removeAll(item);
 }
 
 QDataStream &operator <<(QDataStream &out, InterfaceItem *i) {