52 void mvaddstr_eol(
int row,
int col,
const char *str,
bool reverse=
false)
54 int cols=getmaxx(stdscr);
65 if (reverse) attron(WA_REVERSE);
66 mvaddnstr(row, col, str, n);
67 if (reverse) attroff(WA_REVERSE);
87 int getMinValueColum();
88 void setValueColumn(
int column);
91 std::string getValue(
bool add_unit_range);
92 std::string getAllowedCharacters();
94 void printName(
int row);
95 void printValue(
int row,
bool reverse);
96 void printTooltip(
int row,
bool reverse);
98 int getOptions(std::vector<std::string> &option);
101 std::string setValue(
const std::string &value);
104 std::string execute();
107 int NodeParam::getMinValueColum()
109 return 2*level+
static_cast<int>(node->GetName().size())+1;
112 void NodeParam::setValueColumn(
int column)
117 int NodeParam::getValueColumn()
122 std::string NodeParam::getValue(
bool add_unit_range)
126 switch (node->GetPrincipalInterfaceType())
156 out <<
" " << p->GetUnit();
174 out << p->GetValue();
178 out <<
" " << p->GetUnit();
182 out <<
" [" << p->GetMin() <<
", " << p->GetMax() <<
"]";
195 out << p->GetValue();
208 out << p->GetCurrentEntry()->GetSymbolic();
215 out <<
"(execute)" << std::endl;
225 std::string NodeParam::getAllowedCharacters()
229 switch (node->GetPrincipalInterfaceType())
258 switch (p->GetRepresentation())
296 void NodeParam::printName(
int row)
298 mvaddstr_eol(row, 2*level, node->GetName().c_str());
301 void NodeParam::printValue(
int row,
bool reverse)
303 std::string value=getValue(
true);
305 if (value.size() > 0)
307 mvaddstr_eol(row, value_column, value.c_str(), reverse);
311 void NodeParam::printTooltip(
int row,
bool reverse)
313 mvaddstr_eol(row, 0, node->GetToolTip().c_str(), reverse);
316 int NodeParam::getOptions(std::vector<std::string> &option)
320 switch (node->GetPrincipalInterfaceType())
328 option.push_back(std::string(
"False"));
329 option.push_back(std::string(
"True"));
346 if (p->GetCurrentEntry() != 0)
348 value=p->GetCurrentEntry()->GetSymbolic().c_str();
352 p->GetSymbolics(list);
354 for (
size_t i=0; i<list.size(); i++)
356 std::string opt=list[i].c_str();
357 option.push_back(opt);
375 bool NodeParam::isWritable()
380 std::string NodeParam::setValue(
const std::string &value)
388 switch (node->GetPrincipalInterfaceType())
394 std::string v=std::string(value);
395 if (v ==
"true" || v ==
"True" || v ==
"TRUE")
399 else if (v ==
"false" || v ==
"False" || v ==
"FALSE")
405 p->SetValue(static_cast<bool>(std::stoi(v)));
414 switch (p->GetRepresentation())
417 p->SetValue(std::stoll(std::string(value), 0, 16));
424 std::stringstream in(value);
427 for (
int i=0; i<4; i++)
430 ip=(ip<<8)|(stoi(elem)&0xff);
441 std::stringstream in(value);
444 for (
int i=0; i<4; i++)
447 mac=(mac<<8)|(stoi(elem, 0, 16)&0xff);
455 p->SetValue(std::stoll(std::string(value)));
464 p->SetValue(std::stof(std::string(value)));
475 entry=p->GetEntryByName(value.c_str());
482 p->SetIntValue(entry->GetValue());
490 p->SetValue(value.c_str());
500 ret=
"Internal error: Node is not writable";
505 ret=std::string(
"Error: ")+ex.
what();
509 ret=
"Error: Unknown exception";
515 bool NodeParam::isExecutable()
520 std::string NodeParam::execute()
536 ret=
"Internal error: Feature not a command";
541 ret=
"Internal error: Node is not writable";
546 ret=std::string(
"Error: ")+ex.
what();
550 ret=
"Error: Unknown exception";
560 void addNodeToList(std::vector<NodeParam> &list,
GenApi::INode *node,
int level)
564 list.push_back(NodeParam(level, node));
572 GenApi::FeatureList_t feature;
573 root->GetFeatures(feature);
576 for (
size_t i=0; i<feature.size(); i++)
578 addNodeToList(list, feature[i]->
GetNode(), level);
589 void redraw_line(
int row, NodeParam &node_param,
bool focus,
bool clear_line=
false)
598 if (node_param.isWritable()) attrs|=A_BOLD;
599 if (focus) attrs|=WA_REVERSE;
602 node_param.printName(row);
605 node_param.printValue(row,
false);
613 void redraw(std::vector<NodeParam> &list,
int &top_row,
int focus_row,
const char *message=0)
615 int rows=getmaxy(stdscr);
625 if (focus_row < top_row) top_row=focus_row;
626 if (focus_row > top_row+rows-1) top_row=focus_row-rows+1;
630 for (
int i=0; i<rows; i++)
632 if (top_row+i < static_cast<int>(list.size()))
634 redraw_line(i, list[top_row+i], focus_row == top_row+i);
638 if (message && *message !=
'\0')
640 mvaddstr_eol(rows, 0, message,
true);
644 list[focus_row].printTooltip(rows,
true);
653 std::string editNodeExecute(std::vector<NodeParam> &list,
int &top_row,
int focus_row)
660 redraw_line(focus_row-top_row, list[focus_row],
false,
false);
662 list[focus_row].printValue(focus_row-top_row,
true);
669 redraw(list, top_row, focus_row);
675 ret=list[focus_row].execute();
678 ret=
"Command executed!";
701 std::string editNodeOption(std::vector<NodeParam> &list,
int &top_row,
int focus_row,
702 const std::vector<std::string> &option,
int current)
706 redraw_line(focus_row-top_row, list[focus_row],
false,
false);
711 move(focus_row-top_row, list[focus_row].getValueColumn());
714 mvaddstr_eol(focus_row-top_row, list[focus_row].getValueColumn(), option[current].c_str(),
true);
721 redraw(list, top_row, focus_row);
722 redraw_line(focus_row-top_row, list[focus_row],
false,
false);
733 if (current+1 < static_cast<int>(option.size()))
742 ret=list[focus_row].setValue(option[current]);
764 std::string editNodeString(std::vector<NodeParam> &list,
int &top_row,
int focus_row)
766 std::string allowed=list[focus_row].getAllowedCharacters();
767 std::string value=list[focus_row].getValue(
false);
768 std::string message=
"Current value: "+list[focus_row].getValue(
true);
773 int row=focus_row-top_row;
774 int cpos=
static_cast<int>(value.size());
775 int col0=list[focus_row].getValueColumn();
776 int cn=getmaxx(stdscr)-col0;
780 redraw_line(row, list[focus_row],
false,
false);
784 move(getmaxy(stdscr)-1, 0);
787 mvaddstr_eol(getmaxy(stdscr)-1, 0, message.c_str(),
true);
801 mvaddstr_eol(row, col0, value.c_str(),
true);
802 move(row, col0+cpos);
811 redraw(list, top_row, focus_row, message.c_str());
812 redraw_line(row, list[focus_row],
false,
false);
823 if (cpos < static_cast<int>(value.size()) && cpos+1 < cn)
833 value.erase(cpos, 1);
838 if (cpos < static_cast<int>(value.size()))
840 value.erase(cpos, 1);
847 ret=list[focus_row].setValue(value);
858 if (static_cast<int>(value.size()) < cn)
862 char cc=
static_cast<char>(c);
863 if (c < 256 && std::isprint(cc))
865 if (allowed.size() == 0 || allowed.find(cc) != std::string::npos)
867 value.insert(cpos, &cc, 1);
887 bool editNodemap(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char root[])
891 std::vector<NodeParam> list;
898 addNodeToList(list, node, 0);
905 if (list.size() > 0 && std::string(root) ==
"Root")
907 list.erase(list.begin());
916 for (
size_t i=0; i<list.size(); i++)
918 value_column=std::max(value_column, list[i].getMinValueColum());
921 for (
size_t i=0; i<list.size(); i++)
923 list[i].setValueColumn(value_column);
937 keypad(stdscr, TRUE);
942 redraw(list, top_row, focus_row);
955 redraw(list, top_row, focus_row);
961 int rows=getmaxy(stdscr);
966 top_row=std::max(0, top_row-rows);
967 focus_row=std::max(0, focus_row-rows);
970 redraw(list, top_row, focus_row);
975 if (focus_row+1 < static_cast<int>(list.size()))
977 int rows=getmaxy(stdscr);
982 top_row=std::min(top_row+rows, std::max(0, static_cast<int>(list.size())-rows));
983 focus_row=std::min(focus_row+rows, static_cast<int>(list.size())-1);
986 redraw(list, top_row, focus_row);
994 redraw(list, top_row, focus_row);
999 if (focus_row+1 < static_cast<int>(list.size()))
1002 redraw(list, top_row, focus_row);
1010 if (list[focus_row].isWritable())
1014 std::string message;
1016 if (list[focus_row].isExecutable())
1018 message=editNodeExecute(list, top_row, focus_row);
1022 std::vector<std::string> option;
1023 int current=list[focus_row].getOptions(option);
1025 if (option.size() > 0)
1027 message=editNodeOption(list, top_row, focus_row, option, current);
1031 message=editNodeString(list, top_row, focus_row);
1037 redraw(list, top_row, focus_row, message.c_str());
1069 bool editNodemap(
const std::shared_ptr<GenApi::CNodeMapRef> &nodemap,
const char root[])
1071 std::cerr <<
"Editing of nodemap is not implemented! Recompile with ncurses." << std::endl;
Hex number in an edit control.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IBoolean
Interface for Boolean properties.
GENICAM_INTERFACE IInteger
Interface for integer properties.
std::istream & getline(std::istream &is, GENICAM_NAMESPACE::gcstring &str)
STL getline.
virtual INode * GetNode(const GENICAM_NAMESPACE::gcstring &Name) const =0
Retrieves the node from the central map by Name.
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT ICommand
Interface for command like properties.
bool editNodemap(const std::shared_ptr< GenApi::CNodeMapRef > &nodemap, const char root[])
Shows nodemap in a curses gui in the terminal and allows editing of parameters.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumeration
Interface for enumeration properties.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT ICategory
Gives access to a category node.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IString
Interface for string properties.
bool IsWritable(EAccessMode AccessMode)
Tests if writable.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
GENICAM_INTERFACE INode
Interface common to all nodes.
GenICam's exception class.
std::string formatValue(GenApi::IInteger *node, int64_t value)
Takes an integer value and formats it according to the specification in the node. ...
GENICAM_NAMESPACE::gcstring_vector StringList_t
A list of strings.
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IEnumEntry
Interface of single enum value.
virtual const char * what() const
Get error description (overwrite from std:exception)