/** * Generate buildUserInterface C++ lines of code corresponding * to user interface element t */ void Compiler::generateUserInterfaceTree(Tree t) { Tree label, elements, varname, sig; if (isUiFolder(t, label, elements)) { const int orient = tree2int(left(label)); // Empty labels will be renamed with a 0xABCD (address) kind of name that is ignored and not displayed by UI architectures const char* str = tree2str(right(label)); const char* model; // extract metadata from group label str resulting in a simplifiedLabel // and metadata declarations for fictive zone at address 0 string simplifiedLabel; map<string, set<string> > metadata; extractMetadata(str, simplifiedLabel, 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\");", "0", wdel(key) ,wdel(*j))); fJSON.declare(NULL, wdel(key).c_str(), wdel(*j).c_str()); } } //----------------- switch (orient) { case 0 : model = "interface->openVerticalBox(\"$0\");"; fJSON.openVerticalBox(checkNullLabel(t, simplifiedLabel).c_str()); break; case 1 : model = "interface->openHorizontalBox(\"$0\");"; fJSON.openHorizontalBox(checkNullLabel(t, simplifiedLabel).c_str()); break; case 2 : model = "interface->openTabBox(\"$0\");"; fJSON.openTabBox(checkNullLabel(t, simplifiedLabel).c_str()); break; default : fprintf(stderr, "error in user interface generation 1\n"); exit(1); } fClass->addUICode(subst(model, checkNullLabel(t, simplifiedLabel))); generateUserInterfaceElements(elements); fClass->addUICode("interface->closeBox();"); fJSON.closeBox(); } else if (isUiWidget(t, label, varname, sig)) { generateWidgetCode(label, varname, sig); } else { fprintf(stderr, "error in user interface generation 2\n"); exit(1); } }
void Description::addGroup(int level, Tree t) { Tree label, elements, varname, sig; const char* groupnames[] = { "vgroup", "hgroup", "tgroup" }; if(isUiFolder(t, label, elements)) { const int orient = tree2int(left(label)); addLayoutLine(level, subst("<group type=\"$0\">", groupnames[orient])); addLayoutLine(level + 1, subst("<label>$0</label>", checkNullLabel(t, xmlize(tree2str(right(label))), false))); while(!isNil(elements)) { addGroup(level + 1, right(hd(elements))); elements = tl(elements); } addLayoutLine(level, "</group>"); } else if(isUiWidget(t, label, varname, sig)) { int w = addWidget(label, varname, sig); addLayoutLine(level, subst("<widgetref id=\"$0\" />", T(w))); } else { fprintf(stderr, "error in user interface generation 2\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); } }
int Description::addWidget(Tree label, Tree varname, Tree sig) { Tree path, c, x, y, z; // add an active widget description if(isSigButton(sig, path)) { fWidgetID++; fActiveWidgetCount++; addActiveLine(subst("<widget type=\"button\" id=\"$0\">", T(fWidgetID))); addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true))); addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname))); addActiveLine("</widget>"); } else if(isSigCheckbox(sig, path)) { fWidgetID++; fActiveWidgetCount++; addActiveLine(subst("<widget type=\"checkbox\" id=\"$0\">", T(fWidgetID))); addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true))); addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname))); addActiveLine("</widget>"); } else if(isSigVSlider(sig, path, c, x, y, z)) { fWidgetID++; fActiveWidgetCount++; addActiveLine(subst("<widget type=\"vslider\" id=\"$0\">", T(fWidgetID))); addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true))); addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname))); addActiveLine(subst("\t<init>$0</init>", T(tree2double(c)))); addActiveLine(subst("\t<min>$0</min>", T(tree2double(x)))); addActiveLine(subst("\t<max>$0</max>", T(tree2double(y)))); addActiveLine(subst("\t<step>$0</step>", T(tree2double(z)))); addActiveLine("</widget>"); } else if(isSigHSlider(sig, path, c, x, y, z)) { fWidgetID++; fActiveWidgetCount++; addActiveLine(subst("<widget type=\"hslider\" id=\"$0\">", T(fWidgetID))); addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true))); addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname))); addActiveLine(subst("\t<init>$0</init>", T(tree2double(c)))); addActiveLine(subst("\t<min>$0</min>", T(tree2double(x)))); addActiveLine(subst("\t<max>$0</max>", T(tree2double(y)))); addActiveLine(subst("\t<step>$0</step>", T(tree2double(z)))); addActiveLine("</widget>"); } else if(isSigNumEntry(sig, path, c, x, y, z)) { fWidgetID++; fActiveWidgetCount++; addActiveLine(subst("<widget type=\"nentry\" id=\"$0\">", T(fWidgetID))); addActiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true))); addActiveLine(subst("\t<varname>$0</varname>", tree2str(varname))); addActiveLine(subst("\t<init>$0</init>", T(tree2double(c)))); addActiveLine(subst("\t<min>$0</min>", T(tree2double(x)))); addActiveLine(subst("\t<max>$0</max>", T(tree2double(y)))); addActiveLine(subst("\t<step>$0</step>", T(tree2double(z)))); addActiveLine("</widget>"); // add a passive widget description } else if(isSigVBargraph(sig, path, x, y, z)) { fWidgetID++; fPassiveWidgetCount++; addPassiveLine(subst("<widget type=\"vbargraph\" id=\"$0\">", T(fWidgetID))); addPassiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true))); addPassiveLine(subst("\t<varname>$0</varname>", tree2str(varname))); addPassiveLine(subst("\t<min>$0</min>", T(tree2double(x)))); addPassiveLine(subst("\t<max>$0</max>", T(tree2double(y)))); addPassiveLine("</widget>"); } else if(isSigHBargraph(sig, path, x, y, z)) { fWidgetID++; fPassiveWidgetCount++; addPassiveLine(subst("<widget type=\"hbargraph\" id=\"$0\">", T(fWidgetID))); addPassiveLine(subst("\t<label>$0</label>", checkNullLabel(sig, xmlize(tree2str(label)), true))); addPassiveLine(subst("\t<varname>$0</varname>", tree2str(varname))); addPassiveLine(subst("\t<min>$0</min>", T(tree2double(x)))); addPassiveLine(subst("\t<max>$0</max>", T(tree2double(y)))); addPassiveLine("</widget>"); } else { fprintf(stderr, "Error describing widget : unrecognized expression\n"); exit(1); } return fWidgetID; }