1 #include "ArithmeticEvaluator.h"
\r
2 #include "FunctionalInterface.h"
\r
3 #include "ReferenceInterface.h"
\r
4 #include "GroupInterface.h"
\r
5 #include "FunctionalBlock.h"
\r
6 #include "GroupBlock.h"
\r
9 FunctionalInterface::FunctionalInterface(AbstractBlock* _owner, ReferenceInterface *_reference) throw(Exception) : ConnectedInterface(_owner) {
\r
11 if (_owner == NULL) throw(Exception(BLOCK_NULL));
\r
12 if (_reference == NULL) throw(Exception(IFACE_NULL));
\r
14 if (! _owner->isFunctionalBlock()) throw(Exception(BLOCK_INVALID_TYPE));
\r
15 if (! _reference->isReferenceInterface()) throw(Exception(IFACE_INVALID_TYPE));
\r
17 reference = _reference;
\r
19 name = reference->getName();
\r
20 width = reference->getWidth();
\r
21 direction = reference->getDirection();
\r
22 purpose = reference->getPurpose();
\r
23 connectedFrom = NULL;
\r
26 bool FunctionalInterface::isFunctionalInterface() {
\r
30 int FunctionalInterface::getInterfaceMultiplicity() {
\r
34 FunctionalInterface* iface = NULL;
\r
36 if (direction == AbstractInterface::Input) {
\r
37 QList<AbstractInterface *> inputs = owner->getInputs();
\r
38 for(i=0;i<inputs.size();i++) {
\r
39 iface = AI_TO_FUN(inputs.at(i));
\r
40 if (iface->getReference() == reference) {
\r
45 else if (direction == AbstractInterface::Output) {
\r
46 QList<AbstractInterface *> outputs = owner->getOutputs();
\r
47 for(i=0;i<outputs.size();i++) {
\r
48 iface = AI_TO_FUN(outputs.at(i));
\r
49 if (iface->getReference() == reference) {
\r
54 else if (direction == AbstractInterface::InOut) {
\r
55 QList<AbstractInterface *> bidirs = owner->getBidirs();
\r
56 for(i=0;i<bidirs.size();i++) {
\r
57 iface = AI_TO_FUN(bidirs.at(i));
\r
58 if (iface->getReference() == reference) {
\r
63 if (ifaceCount == 0) {
\r
66 else if ( reference->getMultiplicity() == -1) {
\r
69 else if ( ifaceCount < reference->getMultiplicity()) {
\r
75 AbstractInterface *FunctionalInterface::clone() {
\r
76 int id = getInterfaceMultiplicity();
\r
77 if (id < 0) return NULL;
\r
78 FunctionalInterface *inter = new FunctionalInterface(owner, reference);
\r
79 inter->setWidth(width);
\r
80 inter->setName(reference->getName()+"_"+QString::number(id+1));
\r
84 bool FunctionalInterface::canConnectTo(AbstractInterface *iface) {
\r
87 necessary conditions :
\r
88 - this is an output or in/out interface
\r
89 - iface type must be functional or group interface
\r
90 - iface->connectedFrom must be NULL
\r
93 1 - iface is owned by a block (group or func) that is within the same group as the block that own this
\r
94 1.1 - this is output and iface is input
\r
95 1.2 - both are inout
\r
96 2 - iface is owned by the parent group of the block that owns this
\r
97 2.1 - this is an output, iface is an output of the group
\r
98 2.2 - both are inout
\r
99 3 - this is owned by a source block and iface is owned by the top group
\r
102 if (direction == Input) return false;
\r
103 if (iface->isReferenceInterface()) return false;
\r
104 ConnectedInterface* connIface = AI_TO_CON(iface);
\r
105 if (connIface->getConnectedFrom() != NULL) return false;
\r
106 // first case: interface of blocks within the same group
\r
107 if (getOwner()->getParent() == iface->getOwner()->getParent()) {
\r
109 if ((direction == Output) && (iface->getDirection() == Input)) return true;
\r
110 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
112 // second case: iface = interface of the group that contains owner of this
\r
113 else if (getOwner()->getParent() == iface->getOwner()) {
\r
114 if ((direction == Output) && (iface->getDirection() == Output)) return true;
\r
115 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
117 else if ((getOwner()->isSourceBlock()) && (iface->getOwner()->isTopGroupBlock())) {
\r
118 if ((direction == Output) && (iface->getDirection() == Input)) return true;
\r
125 bool FunctionalInterface::canConnectFrom(AbstractInterface *iface) {
\r
128 necessary conditions :
\r
129 - this is an input or in/out interface
\r
130 - iface type must be functional or group interface
\r
131 - this connectedFrom must be NULL
\r
134 1 - iface is owned by a block (group or func) that is within the same group as the block that own this
\r
135 1.1 - this is input and iface is output
\r
136 1.2 - both are inout
\r
137 2 - iface is owned by the parent group of the block that owns this
\r
138 2.1 - this is an input, iface is an input of the group
\r
139 2.2 - both are inout
\r
141 if (direction == Output) return false;
\r
142 if (iface->isReferenceInterface()) return false;
\r
143 if (connectedFrom != NULL) return false;
\r
145 if (getOwner()->getParent() == iface->getOwner()->getParent()) {
\r
147 if ((direction == Input) && (iface->getDirection() == Output)) return true;
\r
148 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
150 else if (getOwner()->getParent() == iface->getOwner()) {
\r
151 if ((direction == Input) && (iface->getDirection() == Input)) return true;
\r
152 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
159 void FunctionalInterface::connectionsValidation(QStack<AbstractInterface *> *interfacetoValidate, QList<AbstractInterface *> *validatedInterfaces) throw(Exception) {
\r
162 //inputs interfaces
\r
163 double widthInput, widthOutput;
\r
164 if(getDirection() == AbstractInterface::Input){
\r
165 widthInput = getDoubleWidth();
\r
166 widthOutput = getConnectedFrom()->getDoubleWidth();
\r
167 if(widthInput != widthOutput){
\r
168 throw new Exception(WIDTHS_NOT_EQUALS);
\r
170 foreach(AbstractInterface *inter, getOwner()->getOutputs()){
\r
171 if(inter->isConnectedTo()){
\r
172 if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){
\r
173 interfacetoValidate->push(inter);
\r
178 //outputs interfaces
\r
179 else if(getDirection() == AbstractInterface::Output){
\r
180 widthOutput = getDoubleWidth();
\r
181 foreach(AbstractInterface *inter, getConnectedTo()){
\r
182 widthInput = inter->getDoubleWidth();
\r
183 if(widthInput != widthOutput){
\r
184 throw new Exception(WIDTHS_NOT_EQUALS);
\r
187 foreach(AbstractInterface *inter, getConnectedTo()){
\r
188 if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){
\r
189 interfacetoValidate->push(inter);
\r
193 else if(getDirection() == AbstractInterface::InOut){
\r