53 void mvaddstr_eol(
int row,
int col,
const char *str,
bool reverse=
false)
55 int cols=getmaxx(stdscr);
66 if (reverse) attron(WA_REVERSE);
67 mvaddnstr(row, col, str, n);
68 if (reverse) attroff(WA_REVERSE);
88 int getMinValueColum();
89 void setValueColumn(
int column);
92 std::string getValue(
bool add_unit_range);
93 std::string getAllowedCharacters();
95 void printName(
int row);
96 void printValue(
int row,
bool reverse);
97 void printTooltip(
int row,
bool reverse);
99 int getOptions(std::vector<std::string> &option);
102 std::string setValue(
const std::string &value);
105 std::string execute();
108 int NodeParam::getMinValueColum()
110 return 2*level+
static_cast<int>(node->GetName().size())+1;
113 void NodeParam::setValueColumn(
int column)
118 int NodeParam::getValueColumn()
123 std::string NodeParam::getValue(
bool add_unit_range)
127 switch (node->GetPrincipalInterfaceType())
157 out <<
" " << p->GetUnit();
175 int len=
static_cast<int>(p->GetLength());
177 len=std::min(len, (getmaxx(stdscr)-value_column)/2-1);
178 len=std::min(len, 128);
184 for (
int i=0; i<len && i<len; i++)
186 out << std::setfill('0') << std::setw(2) << static_cast<int>(buffer[i]);
198 out << p->GetValue();
202 out <<
" " << p->GetUnit();
206 out <<
" [" << p->GetMin() <<
", " << p->GetMax() <<
"]";
219 out << p->GetValue();
232 out << p->GetCurrentEntry()->GetSymbolic();
239 out <<
"(execute)" << std::endl;
249 std::string NodeParam::getAllowedCharacters()
253 switch (node->GetPrincipalInterfaceType())
282 switch (p->GetRepresentation())
339 void NodeParam::printName(
int row)
341 mvaddstr_eol(row, 2*level, node->GetName().c_str());
344 void NodeParam::printValue(
int row,
bool reverse)
346 std::string value=getValue(
true);
348 if (value.size() > 0)
350 mvaddstr_eol(row, value_column, value.c_str(), reverse);
354 void NodeParam::printTooltip(
int row,
bool reverse)
356 mvaddstr_eol(row, 0, node->GetToolTip().c_str(), reverse);
359 int NodeParam::getOptions(std::vector<std::string> &option)
363 switch (node->GetPrincipalInterfaceType())
371 option.push_back(std::string(
"False"));
372 option.push_back(std::string(
"True"));
389 if (p->GetCurrentEntry() != 0)
391 value=p->GetCurrentEntry()->GetSymbolic().c_str();
395 p->GetSymbolics(list);
397 for (
size_t i=0; i<list.size(); i++)
399 std::string opt=list[i].c_str();
400 option.push_back(opt);
418 bool NodeParam::isWritable()
423 std::string NodeParam::setValue(
const std::string &value)
431 switch (node->GetPrincipalInterfaceType())
437 std::string v=std::string(value);
438 if (v ==
"true" || v ==
"True" || v ==
"TRUE")
442 else if (v ==
"false" || v ==
"False" || v ==
"FALSE")
448 p->SetValue(
static_cast<bool>(std::stoi(v)));
457 switch (p->GetRepresentation())
460 p->SetValue(std::stoll(std::string(value), 0, 16));
467 std::stringstream in(value);
470 for (
int i=0; i<4; i++)
473 ip=(ip<<8)|(stoi(elem)&0xff);
484 std::stringstream in(value);
487 for (
int i=0; i<4; i++)
490 mac=(mac<<8)|(stoi(elem, 0, 16)&0xff);
498 p->SetValue(std::stoll(std::string(value)));
508 std::vector<uint8_t> buffer;
509 for (
size_t i=0; i<value.size()-1; i+=2)
511 buffer.push_back(stoi(value.substr(i, 2), 0, 16));
514 p->Set(buffer.data(), buffer.size());
521 p->SetValue(std::stof(std::string(value)));
532 entry=p->GetEntryByName(value.c_str());
539 p->SetIntValue(entry->GetValue());
547 p->SetValue(value.c_str());
557 ret=
"Internal error: Node is not writable";
562 ret=std::string(
"Error: ")+ex.
what();
566 ret=
"Error: Unknown exception";
572 bool NodeParam::isExecutable()
577 std::string NodeParam::execute()
593 ret=
"Internal error: Feature not a command";
598 ret=
"Internal error: Node is not writable";
603 ret=std::string(
"Error: ")+ex.
what();
607 ret=
"Error: Unknown exception";
617 void addNodeToList(std::vector<NodeParam> &list,
GenApi::INode *node,
int level)
621 list.push_back(NodeParam(level, node));
629 GenApi::FeatureList_t feature;
630 root->GetFeatures(feature);
633 for (
size_t i=0; i<feature.size(); i++)
635 addNodeToList(list, feature[i]->
GetNode(), level);
646 void redraw_line(
int row, NodeParam &node_param,
bool focus,
bool clear_line=
false)
655 if (node_param.isWritable()) attrs|=A_BOLD;
656 if (focus) attrs|=WA_REVERSE;
659 node_param.printName(row);
662 node_param.printValue(row,
false);
670 void redraw(std::vector<NodeParam> &list,
int &top_row,
int focus_row,
const char *message=0)
672 int rows=getmaxy(stdscr);
682 if (focus_row < top_row) top_row=focus_row;
683 if (focus_row > top_row+rows-1) top_row=focus_row-rows+1;
687 for (
int i=0; i<rows; i++)
689 if (top_row+i <
static_cast<int>(list.size()))
691 redraw_line(i, list[top_row+i], focus_row == top_row+i);
695 if (message && *message !=
'\0')
697 mvaddstr_eol(rows, 0, message,
true);
701 list[focus_row].printTooltip(rows,
true);
710 std::string editNodeExecute(std::vector<NodeParam> &list,
int &top_row,
int focus_row)
717 redraw_line(focus_row-top_row, list[focus_row],
false,
false);
719 list[focus_row].printValue(focus_row-top_row,
true);
726 redraw(list, top_row, focus_row);
732 ret=list[focus_row].execute();
735 ret=
"Command executed!";
758 std::string editNodeOption(std::vector<NodeParam> &list,
int &top_row,
int focus_row,
759 const std::vector<std::string> &option,
int current)
763 redraw_line(focus_row-top_row, list[focus_row],
false,
false);
768 move(focus_row-top_row, list[focus_row].getValueColumn());
771 mvaddstr_eol(focus_row-top_row, list[focus_row].getValueColumn(), option[current].c_str(),
true);
778 redraw(list, top_row, focus_row);
779 redraw_line(focus_row-top_row, list[focus_row],
false,
false);
790 if (current+1 <
static_cast<int>(option.size()))
799 ret=list[focus_row].setValue(option[current]);
821 std::string editNodeString(std::vector<NodeParam> &list,
int &top_row,
int focus_row)
823 std::string allowed=list[focus_row].getAllowedCharacters();
824 std::string value=list[focus_row].getValue(
false);
825 std::string message=
"Current value: "+list[focus_row].getValue(
true);
830 int row=focus_row-top_row;
831 int cpos=
static_cast<int>(value.size());
832 int col0=list[focus_row].getValueColumn();
833 int cn=getmaxx(stdscr)-col0;
837 redraw_line(row, list[focus_row],
false,
false);
841 move(getmaxy(stdscr)-1, 0);
844 mvaddstr_eol(getmaxy(stdscr)-1, 0, message.c_str(),
true);
858 mvaddstr_eol(row, col0, value.c_str(),
true);
859 move(row, col0+cpos);
868 redraw(list, top_row, focus_row, message.c_str());
869 redraw_line(row, list[focus_row],
false,
false);
880 if (cpos <
static_cast<int>(value.size()) && cpos+1 < cn)
890 value.erase(cpos, 1);
895 if (cpos <
static_cast<int>(value.size()))
897 value.erase(cpos, 1);
904 ret=list[focus_row].setValue(value);
915 if (
static_cast<int>(value.size()) < cn)
919 char cc=
static_cast<char>(c);
920 if (c < 256 && std::isprint(cc))
922 if (allowed.size() == 0 || allowed.find(cc) != std::string::npos)
924 value.insert(cpos, &cc, 1);
944 bool editNodemap(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char root[])
948 std::vector<NodeParam> list;
955 addNodeToList(list, node, 0);
962 if (list.size() > 0 && std::string(root) ==
"Root")
964 list.erase(list.begin());
973 for (
size_t i=0; i<list.size(); i++)
975 value_column=std::max(value_column, list[i].getMinValueColum());
978 for (
size_t i=0; i<list.size(); i++)
980 list[i].setValueColumn(value_column);
994 keypad(stdscr, TRUE);
999 redraw(list, top_row, focus_row);
1012 redraw(list, top_row, focus_row);
1018 int rows=getmaxy(stdscr);
1023 top_row=std::max(0, top_row-rows);
1024 focus_row=std::max(0, focus_row-rows);
1027 redraw(list, top_row, focus_row);
1032 if (focus_row+1 <
static_cast<int>(list.size()))
1034 int rows=getmaxy(stdscr);
1039 top_row=std::min(top_row+rows, std::max(0,
static_cast<int>(list.size())-rows));
1040 focus_row=std::min(focus_row+rows,
static_cast<int>(list.size())-1);
1043 redraw(list, top_row, focus_row);
1051 redraw(list, top_row, focus_row);
1056 if (focus_row+1 <
static_cast<int>(list.size()))
1059 redraw(list, top_row, focus_row);
1067 if (list[focus_row].isWritable())
1071 std::string message;
1073 if (list[focus_row].isExecutable())
1075 message=editNodeExecute(list, top_row, focus_row);
1079 std::vector<std::string> option;
1080 int current=list[focus_row].getOptions(option);
1082 if (option.size() > 0)
1084 message=editNodeOption(list, top_row, focus_row, option, current);
1088 message=editNodeString(list, top_row, focus_row);
1094 redraw(list, top_row, focus_row, message.c_str());
1126 bool editNodemap(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char root[])
1128 std::cerr <<
"Editing of nodemap is not implemented! Recompile with ncurses." << std::endl;