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 level = reference->getLevel();
\r
24 connectedFrom = NULL;
\r
27 bool FunctionalInterface::isFunctionalInterface() {
\r
31 int FunctionalInterface::getInterfaceMultiplicity() {
\r
35 FunctionalInterface* iface = NULL;
\r
37 if (direction == AbstractInterface::Input) {
\r
38 QList<AbstractInterface *> inputs = owner->getInputs();
\r
39 for(i=0;i<inputs.size();i++) {
\r
40 iface = AI_TO_FUN(inputs.at(i));
\r
41 if (iface->getReference() == reference) {
\r
46 else if (direction == AbstractInterface::Output) {
\r
47 QList<AbstractInterface *> outputs = owner->getOutputs();
\r
48 for(i=0;i<outputs.size();i++) {
\r
49 iface = AI_TO_FUN(outputs.at(i));
\r
50 if (iface->getReference() == reference) {
\r
55 else if (direction == AbstractInterface::InOut) {
\r
56 QList<AbstractInterface *> bidirs = owner->getBidirs();
\r
57 for(i=0;i<bidirs.size();i++) {
\r
58 iface = AI_TO_FUN(bidirs.at(i));
\r
59 if (iface->getReference() == reference) {
\r
64 if (ifaceCount == 0) {
\r
67 else if ( reference->getMultiplicity() == -1) {
\r
70 else if ( ifaceCount < reference->getMultiplicity()) {
\r
76 AbstractInterface *FunctionalInterface::clone() {
\r
77 int id = getInterfaceMultiplicity();
\r
78 if (id < 0) return NULL;
\r
79 FunctionalInterface *inter = new FunctionalInterface(owner, reference);
\r
80 inter->setWidth(width);
\r
81 inter->setDirection(direction);
\r
82 inter->setPurpose(purpose);
\r
83 inter->setLevel(level);
\r
84 inter->connectFrom(NULL);
\r
85 inter->setName(reference->getName()+"_"+QString::number(id+1));
\r
89 bool FunctionalInterface::canConnectTo(AbstractInterface *iface) {
\r
92 necessary conditions :
\r
93 - this is an output or in/out interface
\r
94 - iface type must be functional or group interface
\r
95 - iface->connectedFrom must be NULL
\r
98 1 - iface is owned by a block (group or func) that is within the same group as the block that own this
\r
99 1.1 - this is output and iface is input
\r
100 1.2 - both are inout
\r
101 2 - iface is owned by the parent group of the block that owns this
\r
102 2.1 - this is an output, iface is an output of the group
\r
103 2.2 - both are inout
\r
106 if (direction == Input) return false;
\r
107 if (iface->isReferenceInterface()) return false;
\r
108 if (iface->getConnectedFrom() != NULL) return false;
\r
110 if (getOwner()->getParent() == iface->getOwner()->getParent()) {
\r
112 if ((direction == Output) && (iface->getDirection() == Input)) return true;
\r
113 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
115 else if (getOwner()->getParent() == iface->getOwner()) {
\r
116 if ((direction == Output) && (iface->getDirection() == Output)) return true;
\r
117 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
124 bool FunctionalInterface::canConnectFrom(AbstractInterface *iface) {
\r
127 necessary conditions :
\r
128 - this is an input or in/out interface
\r
129 - iface type must be functional or group interface
\r
130 - this connectedFrom must be NULL
\r
133 1 - iface is owned by a block (group or func) that is within the same group as the block that own this
\r
134 1.1 - this is input and iface is output
\r
135 1.2 - both are inout
\r
136 2 - iface is owned by the parent group of the block that owns this
\r
137 2.1 - this is an input, iface is an input of the group
\r
138 2.2 - both are inout
\r
140 if (direction == Output) return false;
\r
141 if (iface->isReferenceInterface()) return false;
\r
142 if (connectedFrom != NULL) return false;
\r
144 if (getOwner()->getParent() == iface->getOwner()->getParent()) {
\r
146 if ((direction == Input) && (iface->getDirection() == Output)) return true;
\r
147 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
149 else if (getOwner()->getParent() == iface->getOwner()) {
\r
150 if ((direction == Input) && (iface->getDirection() == Input)) return true;
\r
151 if ((direction == InOut) && (iface->getDirection() == InOut)) return true;
\r
158 void FunctionalInterface::connectionsValidation(QStack<AbstractInterface *> *interfacetoValidate, QList<AbstractInterface *> *validatedInterfaces) throw(Exception) {
\r
161 //inputs interfaces
\r
162 double widthInput, widthOutput;
\r
163 if(getDirection() == AbstractInterface::Input){
\r
164 widthInput = getDoubleWidth();
\r
165 widthOutput = getConnectedFrom()->getDoubleWidth();
\r
166 if(widthInput != widthOutput){
\r
167 throw new Exception(WIDTHS_NOT_EQUALS);
\r
169 foreach(AbstractInterface *inter, getOwner()->getOutputs()){
\r
170 if(inter->isConnectedTo()){
\r
171 if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){
\r
172 interfacetoValidate->push(inter);
\r
177 //outputs interfaces
\r
178 else if(getDirection() == AbstractInterface::Output){
\r
179 widthOutput = getDoubleWidth();
\r
180 foreach(AbstractInterface *inter, getConnectedTo()){
\r
181 widthInput = inter->getDoubleWidth();
\r
182 if(widthInput != widthOutput){
\r
183 throw new Exception(WIDTHS_NOT_EQUALS);
\r
186 foreach(AbstractInterface *inter, getConnectedTo()){
\r
187 if((!interfacetoValidate->contains(inter)) && (!validatedInterfaces->contains(inter))){
\r
188 interfacetoValidate->push(inter);
\r
192 else if(getDirection() == AbstractInterface::InOut){
\r