X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/43fd94117de66d533ef9e58b2de85daa244da309..1b7818e18ed7bcf3464e307b97c6e0e6d72cc69b:/FunctionalInterface.cpp?ds=sidebyside

diff --git a/FunctionalInterface.cpp b/FunctionalInterface.cpp
index 1b8ff07..eec7ea8 100644
--- a/FunctionalInterface.cpp
+++ b/FunctionalInterface.cpp
@@ -17,10 +17,12 @@ FunctionalInterface::FunctionalInterface(AbstractBlock* _owner, ReferenceInterfa
   reference = _reference;
 
   name = reference->getName();
-  width = reference->getWidth();
+  type = reference->getType();
+  endianess = reference->getEndianess();
+  width = reference->getWidthString();
   direction = reference->getDirection();
   purpose = reference->getPurpose();  
-  connectedFrom = NULL;
+  connectedFrom = NULL;  
 }
 
 bool FunctionalInterface::isFunctionalInterface() {
@@ -76,10 +78,7 @@ AbstractInterface *FunctionalInterface::clone() {
   int id = getInterfaceMultiplicity();
   if (id < 0) return NULL;
   FunctionalInterface *inter = new FunctionalInterface(owner, reference);
-  inter->setWidth(width);
-  inter->setDirection(direction);
-  inter->setPurpose(purpose);  
-  inter->connectFrom(NULL);
+  inter->setWidth(width);  
   inter->setName(reference->getName()+"_"+QString::number(id+1));
   return inter;
 }
@@ -99,20 +98,26 @@ bool FunctionalInterface::canConnectTo(AbstractInterface *iface) {
      2 - iface is owned by the parent group of the block that owns this
         2.1 - this is an output, iface is an output of the group
         2.2 - both are inout
+     3 - this is owned by a source block and iface is owned by the top group
 
   */
   if (direction == Input) return false;
   if (iface->isReferenceInterface()) return false;
-  if (iface->getConnectedFrom() != NULL) return false;
-
+  ConnectedInterface* connIface = AI_TO_CON(iface);
+  if (connIface->getConnectedFrom() != NULL) return false;
+  // first case: interface of blocks within the same group
   if (getOwner()->getParent() == iface->getOwner()->getParent()) {
 
-    if ((direction == Output) && (iface->getDirection() == Input)) return true;
-    if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
+    if ((direction == Output) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) return true;
+    if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
   }
+  // second case: iface = interface of the group that contains owner of this
   else if (getOwner()->getParent() == iface->getOwner()) {
-    if ((direction == Output) && (iface->getDirection() == Output)) return true;
-    if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
+    if ((direction == Output) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) return true;
+    if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
+  }
+  else if ((getOwner()->isSourceBlock()) && (iface->getOwner()->isTopGroupBlock())) {
+    if ((direction == Output) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) return true;
   }
 
   return false;
@@ -141,12 +146,12 @@ bool FunctionalInterface::canConnectFrom(AbstractInterface *iface) {
 
   if (getOwner()->getParent() == iface->getOwner()->getParent()) {
 
-    if ((direction == Input) && (iface->getDirection() == Output)) return true;
-    if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
+    if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) return true;
+    if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
   }
   else if (getOwner()->getParent() == iface->getOwner()) {
-    if ((direction == Input) && (iface->getDirection() == Input)) return true;
-    if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
+    if ((direction == Input) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) return true;
+    if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
   }
 
   return false;