/** * @brief Prepare "intervallic" user interface elements (sliders, nentry). * * - Format a LaTeX output string as a supertabular row with 3 columns : * "\begin{supertabular}{lll}". @see Lateq::printHierarchy * - The UI range is an bounded interval : [tmin, tmax]. * - The UI current value is tcur. * * @param[in] name The LaTeX name of the UI signal (eg. "{u_s}_{i}(t)"). * @param[in] path The path tree to parse. * @param[in] tcur The current UI value tree to convert. * @param[in] tmin The minimum UI value tree to convert. * @param[in] tmax The maximum UI value tree to convert. * @return <string> The LaTeX output string. */ string DocCompiler::prepareIntervallicUI(const string& name, Tree path, Tree tcur, Tree tmin, Tree tmax) { string label, unit, cur, min, max; getUIDocInfos(path, label, unit); cur = docT(tree2float(tcur)); min = docT(tree2float(tmin)); max = docT(tree2float(tmax)); string s = ""; label = (label.size() > 0) ? ("\\textsf{\"" + label + "\"} ") : ""; unit = (unit.size() > 0) ? ("\\ (" + unit + ")") : ""; s += label + unit; s += " & $" + name + "$"; s += " $\\in$ $\\left[\\," + min + ", " + max + "\\,\\right]$"; s += " & $(\\mbox{" + gDocMathStringMap["defaultvalue"] + "} = " + cur + ")$\\\\"; return s; }
/** * Eval a block diagram to a double. * * Eval a block diagram that represent a double constant. This function first eval * a block diagram to its normal form, then check it represent a numerical value (a * block diagram of type : 0->1) then do a symbolic propagation and try to convert the * resulting signal to a double. * @param exp the expression to evaluate * @param globalDefEnv the global environment * @param visited list of visited definition to detect recursive definitions * @param localValEnv the local environment * @return a block diagram in normal form */ static double eval2double (Tree exp, Tree visited, Tree localValEnv) { Tree diagram = a2sb(eval(exp, visited, localValEnv)); // pour getBoxType int numInputs, numOutputs; getBoxType(diagram, &numInputs, &numOutputs); if ( (numInputs > 0) || (numOutputs != 1) ) { evalerror(yyfilename, yylineno, "not a constant expression of type : (0->1)", exp); return 1; } else { Tree lsignals = boxPropagateSig(gGlobal->nil, diagram , makeSigInputList(numInputs) ); Tree val = simplify(hd(lsignals)); return tree2float(val); } }
/** * Generate user interface macros corresponding * to a user interface widget */ void Compiler::generateWidgetMacro(const string& pathname, Tree fulllabel, Tree varname, Tree sig) { Tree path, c, x, y, z; string label; map<string, set<string> > metadata; extractMetadata(tree2str(fulllabel), label, metadata); //string pathlabel = pathname+unquote(label); string pathlabel = pathname+label; if ( isSigButton(sig, path) ) { fClass->addUIMacro(subst("FAUST_ADDBUTTON(\"$0\", $1);", pathlabel, tree2str(varname))); } else if ( isSigCheckbox(sig, path) ) { fClass->addUIMacro(subst("FAUST_ADDCHECKBOX(\"$0\", $1);", pathlabel, tree2str(varname))); } else if ( isSigVSlider(sig, path,c,x,y,z) ) { fClass->addUIMacro(subst("FAUST_ADDVERTICALSLIDER(\"$0\", $1, $2, $3, $4, $5);", pathlabel, tree2str(varname), T(tree2float(c)), T(tree2float(x)), T(tree2float(y)), T(tree2float(z)))); } else if ( isSigHSlider(sig, path,c,x,y,z) ) { fClass->addUIMacro(subst("FAUST_ADDHORIZONTALSLIDER(\"$0\", $1, $2, $3, $4, $5);", pathlabel, tree2str(varname), T(tree2float(c)), T(tree2float(x)), T(tree2float(y)), T(tree2float(z)))); } else if ( isSigNumEntry(sig, path,c,x,y,z) ) { fClass->addUIMacro(subst("FAUST_ADDNUMENTRY(\"$0\", $1, $2, $3, $4, $5);", pathlabel, tree2str(varname), T(tree2float(c)), T(tree2float(x)), T(tree2float(y)), T(tree2float(z)))); } else if ( isSigVBargraph(sig, path,x,y,z) ) { fClass->addUIMacro(subst("FAUST_ADDVERTICALBARGRAPH(\"$0\", $1, $2, $3);", pathlabel, tree2str(varname), T(tree2float(x)), T(tree2float(y)))); } else if ( isSigHBargraph(sig, path,x,y,z) ) { fClass->addUIMacro(subst("FAUST_ADDHORIZONTALBARGRAPH(\"$0\", $1, $2, $3);", pathlabel, tree2str(varname), T(tree2float(x)), T(tree2float(y)))); } else { fprintf(stderr, "Error in generating widget code\n"); exit(1); } }
/** * Generate buildUserInterface C++ lines of code corresponding * to user interface widget t */ void Compiler::generateWidgetCode(Tree fulllabel, Tree varname, Tree sig) { Tree path, c, x, y, z; string label; map<string, set<string> > metadata; extractMetadata(tree2str(fulllabel), label, metadata); // add metadata if any for (map<string, set<string> >::iterator i = metadata.begin(); i != metadata.end(); i++) { const string& key = i->first; const set<string>& values = i->second; for (set<string>::const_iterator j = values.begin(); j != values.end(); j++) { fClass->addUICode(subst("interface->declare(&$0, \"$1\", \"$2\");", tree2str(varname), wdel(key), wdel(*j))); fJSON.declare(NULL, wdel(key).c_str(), wdel(*j).c_str()); } } if ( isSigButton(sig, path) ) { fClass->incUIActiveCount(); fClass->addUICode(subst("interface->addButton(\"$0\", &$1);", checkNullLabel(varname, label), tree2str(varname))); fJSON.addButton(checkNullLabel(varname, label).c_str(), NULL); } else if ( isSigCheckbox(sig, path) ) { fClass->incUIActiveCount(); fClass->addUICode(subst("interface->addCheckButton(\"$0\", &$1);", checkNullLabel(varname, label), tree2str(varname))); fJSON.addCheckButton(checkNullLabel(varname, label).c_str(), NULL); } else if ( isSigVSlider(sig, path,c,x,y,z) ) { fClass->incUIActiveCount(); fClass->addUICode(subst("interface->addVerticalSlider(\"$0\", &$1, $2, $3, $4, $5);", checkNullLabel(varname, label), tree2str(varname), T(tree2float(c)), T(tree2float(x)), T(tree2float(y)), T(tree2float(z)))); fJSON.addVerticalSlider(checkNullLabel(varname, label).c_str(), NULL, tree2float(c), tree2float(x), tree2float(y), tree2float(z)); } else if ( isSigHSlider(sig, path,c,x,y,z) ) { fClass->incUIActiveCount(); fClass->addUICode(subst("interface->addHorizontalSlider(\"$0\", &$1, $2, $3, $4, $5);", checkNullLabel(varname, label), tree2str(varname), T(tree2float(c)), T(tree2float(x)), T(tree2float(y)), T(tree2float(z)))); fJSON.addHorizontalSlider(checkNullLabel(varname, label).c_str(), NULL, tree2float(c), tree2float(x), tree2float(y), tree2float(z)); } else if ( isSigNumEntry(sig, path,c,x,y,z) ) { fClass->incUIActiveCount(); fClass->addUICode(subst("interface->addNumEntry(\"$0\", &$1, $2, $3, $4, $5);", checkNullLabel(varname, label), tree2str(varname), T(tree2float(c)), T(tree2float(x)), T(tree2float(y)), T(tree2float(z)))); fJSON.addNumEntry(checkNullLabel(varname, label).c_str(), NULL, tree2float(c), tree2float(x), tree2float(y), tree2float(z)); } else if ( isSigVBargraph(sig, path,x,y,z) ) { fClass->incUIPassiveCount(); fClass->addUICode(subst("interface->addVerticalBargraph(\"$0\", &$1, $2, $3);", checkNullLabel(varname, label, true), tree2str(varname), T(tree2float(x)), T(tree2float(y)))); fJSON.addVerticalBargraph(checkNullLabel(varname, label).c_str(), NULL, tree2float(x), tree2float(y)); } else if ( isSigHBargraph(sig, path,x,y,z) ) { fClass->incUIPassiveCount(); fClass->addUICode(subst("interface->addHorizontalBargraph(\"$0\", &$1, $2, $3);", checkNullLabel(varname, label, true), tree2str(varname), T(tree2float(x)), T(tree2float(y)))); fJSON.addHorizontalBargraph(checkNullLabel(varname, label).c_str(), NULL, tree2float(x), tree2float(y)); } else { fprintf(stderr, "Error in generating widget code\n"); exit(1); } }