+ // first clear if already exists\r
+ clearConsumptionPattern();\r
+\r
+ lengthCP = -1; \r
+ QHash<QString,QString> consPattern = implementation->getConsumptionPattern(); \r
+ \r
+ foreach(AbstractInterface* iface, getControlInputs()) { \r
+ FunctionalInterface* connIface = AI_TO_FUN(iface);\r
+ QString refName = connIface->getReference()->getName(); \r
+ if (! consPattern.contains(refName)) {\r
+ throw(Exception(NO_IFACE_CP,this));\r
+ cerr << "no consumption pattern for reference interface " << qPrintable(refName) << endl;\r
+ }\r
+ QList<char>* pattern = NULL;\r
+ try {\r
+ pattern = expandPattern(consPattern.value(refName));\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ consumptionPattern.insert(connIface,pattern);\r
+ if (lengthCP == -1) {\r
+ lengthCP = pattern->size();\r
+ }\r
+ else {\r
+ if (pattern->size() != lengthCP) {\r
+ throw(Exception(INVALID_IFACE_CP_LENGTH,this));\r
+ }\r
+ }\r
+ } \r
+}\r
+\r
+void FunctionalBlock::createProductionPattern() throw(Exception){ \r
+ static QString fctName = "FunctionalBlock::createProductionPattern()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+\r
+ // first clear if already exists\r
+ clearProductionPattern();\r
+ \r
+ lengthPP = -1; \r
+ QHash<QString,QString> prodPattern = implementation->getProductionPattern(); \r
+ \r
+ foreach(AbstractInterface* iface, getControlOutputs()) { \r
+ FunctionalInterface* connIface = AI_TO_FUN(iface);\r
+ QString refName = connIface->getReference()->getName(); \r
+ if (! prodPattern.contains(refName)) {\r
+ throw(Exception(NO_IFACE_PP,this));\r
+ }\r
+ QList<char>* pattern = NULL;\r
+ try {\r
+ pattern = expandPattern(prodPattern.value(refName));\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ productionPattern.insert(connIface,pattern);\r
+ if (lengthPP == -1) {\r
+ lengthPP = pattern->size();\r
+ }\r
+ else {\r
+ if (pattern->size() != lengthPP) {\r
+ throw(Exception(INVALID_IFACE_PP_LENGTH,this));\r
+ }\r
+ }\r
+ } \r
+}\r
+\r
+void FunctionalBlock::createProductionCounter() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::createProductionCounter()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+\r
+ // first clear if already exists\r
+ productionCounter.clear();\r
+\r
+ \r
+ QStringList counterParts = implementation->getProductionCounter().split(",");\r
+ foreach(QString s, counterParts) {\r
+ cout << "cont part = " << qPrintable(s) << endl;\r
+ bool ok;\r
+ double val = s.toDouble(&ok);\r
+ if (ok) {\r
+ productionCounter.append(val);\r
+ }\r
+ else if (s.at(0) == '{') {\r
+ s.remove(0,1);\r
+ s.chop(1);\r
+ QStringList gen = s.split(":");\r
+ if (gen.size() != 3) {\r
+ throw(Exception(INVALID_IFACE_PC,this));\r
+ }\r
+ int start = 0;\r
+ int nb = 0;\r
+ int step = 0;\r
+ for(int i=0;i<3;i++) { \r
+ double result = 0.0;\r
+ try {\r
+ result = evaluateExpression(gen.at(i));\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ if (i==0) start = result;\r
+ else if (i==1) nb = result;\r
+ else if (i==2) step = result;\r
+ }\r
+ for(int j=0;j<nb;j++) {\r
+ productionCounter.append(start+j*step);\r
+ }\r
+ }\r
+ else { \r
+ double result = 0.0;\r
+ try {\r
+ result = evaluateExpression(s);\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+ productionCounter.append(result); \r
+ }\r
+ }\r
+ foreach(int val, productionCounter) {\r
+ cout << val << ",";\r
+ }\r
+ cout << endl;\r
+}\r
+\r
+QList<char>* FunctionalBlock::expandPattern(const QString& patternIn) throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::expandPattern()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ /* expanding a pattern is done in two steps :\r
+ - 1 : finding all variables that correspond to an expression\r
+ and copy them in the pattern\r
+ - 2 : parsing the result\r
+\r
+ Note that the result MUST contain only variables that have a\r
+ integer/double value. Otherwise, expanding will fail.\r
+\r
+ */\r
+\r
+ // first step.\r
+\r
+ QString p = replaceExpressions(patternIn);\r
+\r
+ QList<char> lst; \r
+ p.append(')');\r
+ int offset = 0; \r
+ QList<char>* patternOut = new QList<char>();\r
+ try {\r
+ patternOut->append(expandPatternRecur(p,&offset));\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
+\r
+ return patternOut;\r
+}\r
+\r
+QString FunctionalBlock::replaceExpressions(const QString& patternIn) throw(Exception) {\r
+\r
+ QString res = patternIn;\r
+ bool stop = false;\r