28 #include <boost/lexical_cast.hpp>
30 #include <QPainterPath>
33 #include <SimoxUtility/algorithm/string/string_tools.h>
59 return boost::lexical_cast<float>(graphvizNumber);
61 catch (boost::bad_lexical_cast&)
71 std::string graphvizNumber =
to_string(number);
79 return graphvizNumber;
85 auto pos = graphvizPoint.find(
'!');
86 if (pos != std::string::npos)
88 graphvizPoint.erase(pos, 1);
95 float y = boost::lexical_cast<float>(tokens.at(1));
96 return QPointF{boost::lexical_cast<float>(tokens.at(0)), y};
98 catch (boost::bad_lexical_cast&)
103 catch (
const std::invalid_argument& ia)
105 ARMARX_ERROR_S <<
"Invalid argument for float conversion: " << ia.what() <<
" "
106 << tokens.at(0) <<
", " << tokens.at(1);
108 catch (
const std::out_of_range& e)
113 return QPointF(0, 0);
119 std::string graphvizPoint =
to_string(point.x());
120 graphvizPoint +=
",";
142 return graphvizPoint;
153 float y = boost::lexical_cast<float>(tokens.at(1));
154 float y2 = boost::lexical_cast<float>(tokens.at(3));
155 return QRectF{boost::lexical_cast<float>(tokens.at(0)),
157 boost::lexical_cast<float>(tokens.at(2)),
160 catch (boost::bad_lexical_cast&)
165 catch (
const std::invalid_argument& ia)
167 ARMARX_ERROR_S <<
"Invalid argument for float conversion: " << ia.what() <<
" "
168 << tokens.at(0) <<
", " << tokens.at(1);
170 catch (
const std::out_of_range& e)
175 return QRectF(0, 0, 0, 0);
183 tokenVector splineStrings = splitBy(graphVizSplineType,
";");
186 for (
auto spline : splineStrings)
188 splines.push_back(tokenize(spline));
191 return mergeSplines(splines);
199 std::string graphvizSpline;
203 graphvizSpline +=
"e,";
204 graphvizSpline += convertFromPoint(*(spline.
endPoint));
205 graphvizSpline +=
" ";
210 graphvizSpline +=
"s,";
211 graphvizSpline += convertFromPoint(*(spline.
startPoint));
212 graphvizSpline +=
" ";
217 graphvizSpline += convertFromPoint(point);
218 graphvizSpline +=
" ";
222 simox::alg::trim(graphvizSpline);
224 return graphvizSpline;
228 armarx::GraphvizConverter::tokenize(std::string graphVizSpline)
236 for (
auto point : points)
240 if (tokens.size() == 3)
246 QPointF floatPoint{boost::lexical_cast<float>(tokens.at(1)),
247 boost::lexical_cast<float>(tokens.at(2))};
249 if (tokens.at(0) ==
"s")
251 spline.
startPoint = std::make_shared<QPointF>(floatPoint);
255 spline.
endPoint = std::make_shared<QPointF>(floatPoint);
258 catch (boost::bad_lexical_cast&)
260 ARMARX_WARNING_S <<
" bad lexical cast to pointlist - value:" << graphVizSpline;
263 catch (
const std::invalid_argument& ia)
265 ARMARX_ERROR_S <<
"Invalid argument for float conversion: " << ia.what();
267 catch (
const std::out_of_range& e)
272 else if (tokens.size() == 2)
276 QPointF p{boost::lexical_cast<float>(tokens.at(0)),
277 boost::lexical_cast<float>(tokens.at(1))};
280 catch (
const std::invalid_argument& ia)
282 ARMARX_ERROR_S <<
"Invalid argument for float conversion: " << ia.what() <<
" "
283 << tokens.at(0) <<
", " << tokens.at(1);
285 catch (
const std::out_of_range& e)
292 ARMARX_ERROR_S <<
"Not a valid string to represent a spline control point: " << point;
302 armarx::GraphvizConverter::splitBy(std::string toSplit, std::string divider)
305 size_t dividerPos = 0;
307 while (dividerPos != std::string::npos)
309 dividerPos = toSplit.find_first_of(divider);
310 std::string token = toSplit.substr(0, dividerPos);
311 toSplit = toSplit.substr(dividerPos + 1);
313 tokenVec.push_back(token);
322 if (toMerge.size() >= 1)
324 return toMerge.front();
326 SupportPoints merged;
327 merged.
startPoint = toMerge.front().startPoint;
328 merged.endPoint = toMerge.back().endPoint;
330 for (SupportPoints otherSpline : toMerge)
332 merged.controlPoints.append(otherSpline.controlPoints);
366 list.append(*startPoint.get());
369 list.append(controlPointList());
373 list.append(*endPoint.get());
384 for (QPointF point : controlPoints)
395 controlPoints.clear();
397 for (
auto point :
list)
399 controlPoints.push_back(point);
406 controlPoints.append(point);