static void buildWaypointList(WaypointClient* userdata) { WaypointClient* anInstance = (WaypointClient*) userdata; Fl_Input_Choice * fromWPChoice = anInstance->frWps; Fl_Input_Choice * toWPChoice = anInstance->toWps; fromWPChoice->clear(); toWPChoice->clear(); Json::Value waypointsArray = anInstance->getWaypoints().get("waypoints",0); if (waypointsArray.size() == 0) { fromWPChoice->add("EMPTY"); toWPChoice->add("EMPTY"); } else { for (Json::ValueIterator itr = waypointsArray.begin(); itr != waypointsArray.end(); itr++) { Json::Value waypoint = *itr; string name = waypoint["name"].asString(); fromWPChoice->add(name.c_str()); toWPChoice->add(name.c_str()); } } fromWPChoice->value(0); toWPChoice->value(0); SelectedFromWP(NULL, anInstance); }
WaypointGUI(const char * name = 0) : Fl_Window(520, 300, name) { begin(); frWps = new Fl_Input_Choice(40, 10, 200, 25, "from"); frWps->add("EMPTY"); frWps->value(0); toWps = new Fl_Input_Choice(40, 45, 200, 25, "to"); toWps->add("EMPTY"); toWps->value(0); latIn = new Fl_Input(270, 10, 230, 25, "lat"); lonIn = new Fl_Input(270, 45, 230, 25, "lon"); eleIn = new Fl_Input(270, 80, 230, 25, "ele"); nameIn = new Fl_Input(270, 115, 230, 25, "name"); addrIn = new Fl_Multiline_Input(270, 150, 230, 70, "addr"); distBearIn = new Fl_Input(225, 260, 255, 25); removeWPButt = new Fl_Button(55, 80, 130, 25, "Remove Waypoint"); addWPButt = new Fl_Button(55, 115, 130, 25, "Add Waypoint"); modWPButt = new Fl_Button(55, 150, 130, 25, "Modify Waypoint"); getAddrButt = new Fl_Button(20, 185, 180, 25, "Get Addr for lat/lon"); //importJSONButt = new Fl_Button(20, 220, 180, 25, "Import Json Library"); distBearButt = new Fl_Button(20, 260, 180, 25, "Distance and Bearing"); end(); show(); }
void onelabGroup::updateParameter(onelab::string &p) { Fl_Tree_Item *n = _tree->find_item(p.getName().c_str()); if(!n) { addParameter(p); return; } Fl_Group *grp = (Fl_Group *)n->widget(); // macro button if(p.getAttribute("Macro") == "Gmsh"){ return; } // non-editable value FIXME if(p.getReadOnly()){ Fl_Output *but = (Fl_Output *)grp->child(0); but->value(p.getValue().c_str()); return; } // simple string (no menu) if(p.getChoices().empty() && p.getKind() != "file"){ Fl_Input *but = (Fl_Input *)grp->child(0); but->value(p.getValue().c_str()); return; } // general string input TODO Fl_Input_Choice *but = (Fl_Input_Choice *)grp->child(0); but->value(p.getValue().c_str()); }
// callback for string static void onelab_string_input_choice_cb(Fl_Widget *w, void *data) { if(!data) return; std::string name((char*)data); std::vector<onelab::string> strings; OnelabDatabase::instance()->get(strings, name); if(strings.size()){ Fl_Input_Choice *o = (Fl_Input_Choice*)w; onelab::string old = strings[0]; strings[0].setValue(o->value()); std::string choices; for(int i = 0; i < o->menubutton()->menu()->size(); i++){ if(o->menubutton()->menu()[i].flags & FL_MENU_TOGGLE){ if(o->menubutton()->menu()[i].flags & FL_MENU_VALUE) choices += "1"; else choices += "0"; } } if(choices.size()) strings[0].setAttribute("MultipleSelection", choices); //setGmshOption(strings[0]); OnelabDatabase::instance()->set(strings[0], "localGUI"); autoCheck(old, strings[0]); } }
Scheme_Object* spark_fltk_input_choice::value(int argc, Scheme_Object** argv) { DEFAULT_RET_INIT; Fl_Input_Choice* ic = _get_fl_input_choice(argc, argv, 0); if (ic) { if (argc == 1) { const char* s = ic->value(); _ret_ = scheme_make_utf8_string(s); } else { long i = 0; if (spark::Utils::long_from_scheme_long(argv[1], i)) { ic->value(i); _ret_ = scheme_true; } else { if (SCHEME_CHAR_STRINGP(argv[1])) { Scheme_Object* str = scheme_char_string_to_byte_string(argv[1]); std::string s = SCHEME_BYTE_STR_VAL(str); ic->value(s.c_str()); } else { int i = 0; spark::Utils::int_from_scheme_long(argv[1], i); ic->value(i); } _ret_ = scheme_true; } } } DEFAULT_RET_FINISH; }
static void ClickedDistBear(Fl_Widget * w, void * userdata) { WaypointClient* anInstance = (WaypointClient*) userdata; Fl_Input_Choice * fromWPChoice = anInstance->frWps; Fl_Input_Choice * toWPChoice = anInstance->toWps; Fl_Input * distBearOutput = anInstance->distBearIn; double dist = anInstance->getDistanceGCTo(fromWPChoice->value(), toWPChoice->value()); double bear = anInstance->getBearingGCInitTo(fromWPChoice->value(), toWPChoice->value()); stringstream ss; ss.precision(5); ss << dist << "/" << bear; string result = ss.str(); distBearOutput->value(result.c_str()); cout << "Calculated distance/bearing: " << result << "; \n"<< endl; buildWaypointList(anInstance); }
static void ClickedRemoveWP(Fl_Widget* w, void* userdata) { WaypointClient* anInstance = (WaypointClient*) userdata; Fl_Input_Choice* fromWPChoice = anInstance->frWps; Fl_Input_Choice* toWPChoice = anInstance->toWps; string selected(fromWPChoice->value()); if (anInstance->removeWaypoint(selected) == true) { cout << "Removed: Waypoint(" << selected << "); \n" << endl; } else { cout << "Error: Waypoint(" << selected << ") did not exist! \n" << endl; } buildWaypointList(anInstance); }
static void SelectedToWP(Fl_Widget * w, void * userdata) { WaypointClient* anInstance = (WaypointClient*) userdata; Fl_Input_Choice* toWps = anInstance->toWps; string selected(toWps->value()); cout << "Selected: " << selected << ";" << endl; try { Json::Value result = anInstance->getWaypoint(selected); if (result["result"] == "ERROR") { cout << "Unsuccessful grab" << endl; anInstance->nameIn->value("ERROR"); anInstance->latIn->value("0"); anInstance->lonIn->value("0"); anInstance->eleIn->value("0"); } else { string lat = to_string(result["lat"].asDouble()); string lon = to_string(result["lon"].asDouble()); string ele = to_string(result["ele"].asDouble()); anInstance->nameIn->value(result["name"].asCString()); anInstance->latIn->value(lat.c_str()); anInstance->lonIn->value(lon.c_str()); anInstance->eleIn->value(ele.c_str()); cout << "Successful grab" << endl; } } catch (exception &e) { cout << e.what() << endl; } }
// add parameter string to tree Fl_Widget *onelabGroup::_addParameterWidget(onelab::string &p, int ww, int hh, Fl_Tree_Item *n, bool highlight, Fl_Color c) { char *path = strdup(getPath(n).c_str()); _treeStrings.push_back(path); // macro button if(p.getAttribute("Macro") == "Gmsh"){ Fl_Button *but = new Fl_Button(1, 1, ww / _widgetLabelRatio, hh); but->box(FL_FLAT_BOX); but->color(_tree->color()); but->selection_color(_tree->color()); but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); //TODO but->callback(onelab_string_button_cb, (void*)path); if(highlight) but->color(c); return but; } // non-editable value if(p.getReadOnly()){ Fl_Output *but = new Fl_Output(1, 1, ww, hh); but->value(p.getValue().c_str()); but->align(FL_ALIGN_RIGHT); if(highlight) but->color(c); return but; } // simple string (no menu) if(p.getChoices().empty() && p.getKind() != "file"){ Fl_Input *but = new Fl_Input(1, 1, ww, hh); but->value(p.getValue().c_str()); //TODO but->callback(onelab_string_input_cb, (void*)path); but->when(FL_WHEN_ENTER_KEY); but->align(FL_ALIGN_RIGHT); if(highlight) but->color(c); return but; } // general string input Fl_Input_Choice *but = new Fl_Input_Choice(1, 1, ww, hh); std::string multipleSelection = p.getAttribute("MultipleSelection"); if(multipleSelection.size()) ;//but->menubutton()->callback(multiple_selection_menu_cb, but); std::vector<Fl_Menu_Item> menu; for(unsigned int j = 0; j < p.getChoices().size(); j++){ char *str = strdup(p.getChoices()[j].c_str()); _treeStrings.push_back(str); bool divider = (p.getKind() == "file" && j == p.getChoices().size() - 1); int choice = multipleSelection.size() ? FL_MENU_TOGGLE : 0; if(multipleSelection.size() > j && multipleSelection[j] == '1') choice |= FL_MENU_VALUE; Fl_Menu_Item it = {str, 0, 0, 0, divider ? FL_MENU_DIVIDER : choice}; menu.push_back(it); } //if(p.getKind() == "file"){ // Fl_Menu_Item it = {"Choose...", 0, onelab_input_choice_file_chooser_cb, (void*)n}; // menu.push_back(it); // Fl_Menu_Item it2 = {"Edit...", 0, onelab_input_choice_file_edit_cb, (void*)n}; // menu.push_back(it2); // if(GuessFileFormatFromFileName(p.getValue()) >= 0){ // Fl_Menu_Item it3 = {"Merge...", 0, onelab_input_choice_file_merge_cb, (void*)n}; // menu.push_back(it3); // } //} Fl_Menu_Item it = {0}; menu.push_back(it); but->menubutton()->copy(&menu[0]); but->value(p.getValue().c_str()); but->callback(onelab_string_input_choice_cb, (void*)path); but->input()->when(FL_WHEN_ENTER_KEY); but->align(FL_ALIGN_RIGHT); if(highlight) but->input()->color(c); return but; }