X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/43fd94117de66d533ef9e58b2de85daa244da309..e5af659f87bcb199d6a5f10f09b311138351d0f3:/InterfaceItem.cpp?ds=sidebyside diff --git a/InterfaceItem.cpp b/InterfaceItem.cpp index 7c384d2..0047e16 100644 --- a/InterfaceItem.cpp +++ b/InterfaceItem.cpp @@ -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 { @@ -227,157 +235,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 {