| 43 | } |
| 44 | |
| 45 | wxPGProperty *SDRDevicesDialog::addArgInfoProperty(wxPropertyGrid *pg, SoapySDR::ArgInfo arg) { |
| 46 | |
| 47 | wxPGProperty *prop = nullptr; |
| 48 | |
| 49 | int intVal; |
| 50 | double floatVal; |
| 51 | std::vector<std::string>::iterator stringIter; |
| 52 | |
| 53 | switch (arg.type) { |
| 54 | case SoapySDR::ArgInfo::INT: |
| 55 | try { |
| 56 | intVal = std::stoi(arg.value); |
| 57 | } catch (const std::invalid_argument &) { |
| 58 | intVal = 0; |
| 59 | } |
| 60 | prop = pg->Append( new wxIntProperty(arg.name, wxPG_LABEL, intVal) ); |
| 61 | if (arg.range.minimum() != arg.range.maximum()) { |
| 62 | pg->SetPropertyAttribute( prop, wxPG_ATTR_MIN, arg.range.minimum()); |
| 63 | pg->SetPropertyAttribute( prop, wxPG_ATTR_MAX, arg.range.maximum()); |
| 64 | } |
| 65 | break; |
| 66 | case SoapySDR::ArgInfo::FLOAT: |
| 67 | try { |
| 68 | floatVal = std::stod(arg.value); |
| 69 | } catch (const std::invalid_argument &) { |
| 70 | floatVal = 0; |
| 71 | } |
| 72 | prop = pg->Append( new wxFloatProperty(arg.name, wxPG_LABEL, floatVal) ); |
| 73 | if (arg.range.minimum() != arg.range.maximum()) { |
| 74 | pg->SetPropertyAttribute( prop, wxPG_ATTR_MIN, arg.range.minimum()); |
| 75 | pg->SetPropertyAttribute( prop, wxPG_ATTR_MAX, arg.range.maximum()); |
| 76 | } |
| 77 | break; |
| 78 | case SoapySDR::ArgInfo::BOOL: |
| 79 | prop = pg->Append( new wxBoolProperty(arg.name, wxPG_LABEL, (arg.value=="true")) ); |
| 80 | break; |
| 81 | case SoapySDR::ArgInfo::STRING: |
| 82 | if (!arg.options.empty()) { |
| 83 | intVal = 0; |
| 84 | prop = pg->Append( new wxEnumProperty(arg.name, wxPG_LABEL) ); |
| 85 | for (stringIter = arg.options.begin(); stringIter != arg.options.end(); stringIter++) { |
| 86 | std::string optName = (*stringIter); |
| 87 | std::string displayName = optName; |
| 88 | if (!arg.optionNames.empty()) { |
| 89 | displayName = arg.optionNames[intVal]; |
| 90 | } |
| 91 | |
| 92 | prop->AddChoice(displayName); |
| 93 | if ((*stringIter)==arg.value) { |
| 94 | prop->SetChoiceSelection(intVal); |
| 95 | } |
| 96 | |
| 97 | intVal++; |
| 98 | } |
| 99 | } else { |
| 100 | prop = pg->Append( new wxStringProperty(arg.name, wxPG_LABEL, arg.value) ); |
| 101 | } |
| 102 | break; |