1 #include "GroupInterface.h"
2 #include "FunctionalInterface.h"
3 #include "GroupBlock.h"
5 GroupInterface::GroupInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose) throw(Exception) : ConnectedInterface(_owner,_name,_direction,_purpose,"inherited","") {
6 if (! _owner->isGroupBlock()) throw(Exception(BLOCK_INVALID_TYPE));
9 // force clock and reset to boolean width type instead of inherited
10 if ((purpose == Clock) || (purpose == Reset)) {
15 bool GroupInterface::isGroupInterface() {
19 AbstractInterface *GroupInterface::clone() {
20 GroupInterface *inter = new GroupInterface(owner,name,direction, purpose);
21 inter->setWidth(width);
25 int GroupInterface::getWidth() {
32 if (type == Boolean) {
35 else if (type == Inherited) {
36 // must search from which iface it is connected.
37 ConnectedInterface* fromIface = connectedFrom;
38 while ((fromIface != NULL) && (fromIface->getType() == Inherited)) {
39 fromIface = fromIface->getConnectedFrom();
41 if (fromIface == NULL) return -1;
42 w = fromIface->getWidth();
47 bool GroupInterface::canConnectTo(AbstractInterface *iface) {
50 necessary conditions :
51 - iface type must be functional or group interface
52 - iface->connectedFrom must be NULL
55 1 - this is owned by the parent group of the block (group or func) that owns iface
56 1.1 - this is input and iface is input
58 2 - this is owned by a group that has the same parent as the block (group or func) that owns iface
59 2.1 - this is an output, iface is an input of the group
61 3 - this is owned by a group and iface by its parent group
62 2.1 - this is an output, iface is an output of the group
68 if (iface->isReferenceInterface()) return false;
69 ConnectedInterface* connIface = AI_TO_CON(iface);
70 if (connIface->getConnectedFrom() != NULL) return false;
72 if (this->getOwner() == iface->getOwner()->getParent()) {
73 if ((direction == Input) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) return true;
74 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
77 else if (this->getOwner()->getParent() == iface->getOwner()->getParent()) {
78 if ((direction == Output) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) return true;
79 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
81 else if (this->getOwner()->getParent() == iface->getOwner()) {
82 if ((direction == Output) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) return true;
83 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
90 bool GroupInterface::canConnectFrom(AbstractInterface *iface) {
93 necessary conditions :
94 - iface type must be functional or group interface
95 - this->connectedFrom must be NULL
98 1 - this is owned by the parent group of the block (group or func) that owns iface
99 1.1 - this is output and iface is output
101 2 - this is owned by a group that has the same parent as the block (group or func) that owns iface
102 2.1 - this is an input, iface is an output of the group
104 3 - this is owned by a group and iface by its parent group
105 2.1 - this is an input, iface is an input of the group
107 4 - this is owned by top group and iface is an output of a source block
109 if (iface->isReferenceInterface()) return false;
110 if (getConnectedFrom() != NULL) return false;
112 if (this->getOwner() == iface->getOwner()->getParent()) {
113 if ((direction == Output) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) return true;
114 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
117 else if (this->getOwner()->getParent() == iface->getOwner()->getParent()) {
118 if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) return true;
119 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
121 else if (this->getOwner()->getParent() == iface->getOwner()) {
122 if ((direction == Input) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) return true;
123 if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) return true;
125 else if ((getOwner()->isTopGroupBlock()) && (iface->getOwner()->isStimuliBlock())) {
126 if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) return true;
132 void GroupInterface::connectionsValidation(QStack<AbstractInterface*> *interfacetoValidate, QList<AbstractInterface*> *validatedInterfaces) throw(Exception) {
133 cout << "group interface connection validation" << endl;