2 #include <RobotComponents/gui-plugins/RobotIKPlugin/ui_SetDesiredPoseDialog.h>
9 static std::vector<std::string> expectedKeys({
"agent",
"frame",
"qw",
"qx",
"qy",
"qz",
"x",
"y",
"z"});
17 connect(ui->pushButton_formatJSON, SIGNAL(clicked()),
this, SLOT(formatInput()));
18 connect(ui->plainTextEdit, SIGNAL(textChanged()),
this, SLOT(checkJSON()));
19 connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
this, SLOT(parseInputAndSetPose()));
34 void SetDesiredPoseDialog::checkJSON()
36 std::string text = ui->plainTextEdit->toPlainText().toUtf8().data();
42 std::string errorMsgPart;
46 std::vector<std::string> keys = json->getKeys();
47 for (std::string& k : expectedKeys)
49 if (std::find(keys.begin(), keys.end(), k) == keys.end())
58 for (std::string& k : expectedKeys)
64 if (errorMsgPart.size() >= 2)
66 errorMsgPart = errorMsgPart.substr(0, errorMsgPart.size() - 2);
70 if (!
parser.iserr() && errorMsgPart.empty())
72 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
73 ui->label_jsonValid->setStyleSheet(
"QLabel { color : green; }");
74 ui->label_jsonValid->setText(
"JSON-Format: valid");
78 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
79 ui->label_jsonValid->setStyleSheet(
"QLabel { color : red; }");
80 if (errorMsgPart.empty())
82 ui->label_jsonValid->setText(
"JSON-Format: not valid, Error at " + QString(
parser.getlongerrposstr().c_str()));
87 ui->label_jsonValid->setText(
"JSON-Format: not valid, Missing following keys: \n{ " + QString(errorMsgPart.c_str()) +
" }");
92 void SetDesiredPoseDialog::formatInput()
94 std::string text = ui->plainTextEdit->toPlainText().toUtf8().data();
100 if (stringToJSON(text, json))
102 std::vector<std::string> keys = json->getKeys();
103 for (std::string& k : expectedKeys)
105 if (std::find(keys.begin(), keys.end(), k) == keys.end())
107 if (k ==
"agent" || k ==
"frame")
117 ui->plainTextEdit->setPlainText(QString(json->toJsonString(2).c_str()));
122 msgBox.setText(
"Input cannot be parsed into json and therefore not formated.");
123 msgBox.setIcon(QMessageBox::Warning);
124 msgBox.setStandardButtons(QMessageBox::Ok);
125 msgBox.setDefaultButton(QMessageBox::Ok);
130 void SetDesiredPoseDialog::parseInputAndSetPose()
132 std::string text = ui->plainTextEdit->toPlainText().toUtf8().data();
136 float x =
armarx::toFloat((std::dynamic_pointer_cast<armarx::JsonValue>(json->get(
"x")))->rawValue());
137 float y =
armarx::toFloat((std::dynamic_pointer_cast<armarx::JsonValue>(json->get(
"y")))->rawValue());
138 float z =
armarx::toFloat((std::dynamic_pointer_cast<armarx::JsonValue>(json->get(
"z")))->rawValue());
139 float qw =
armarx::toFloat((std::dynamic_pointer_cast<armarx::JsonValue>(json->get(
"qw")))->rawValue());
140 float qx =
armarx::toFloat((std::dynamic_pointer_cast<armarx::JsonValue>(json->get(
"qx")))->rawValue());
141 float qy =
armarx::toFloat((std::dynamic_pointer_cast<armarx::JsonValue>(json->get(
"qy")))->rawValue());
142 float qz =
armarx::toFloat((std::dynamic_pointer_cast<armarx::JsonValue>(json->get(
"qz")))->rawValue());
143 std::string agent = (std::dynamic_pointer_cast<armarx::JsonValue>(json->get(
"agent")))->asString();
144 std::string frame = (std::dynamic_pointer_cast<armarx::JsonValue>(json->get(
"frame")))->asString();
161 result = std::dynamic_pointer_cast<armarx::JsonObject>(
parser.parsedJson);