30 #include <SimoxUtility/algorithm/string/string_tools.h>
32 #include <QPainterPath>
35 #include <boost/lexical_cast.hpp>
58 return boost::lexical_cast<float>(graphvizNumber);
60 catch (boost::bad_lexical_cast&)
69 std::string graphvizNumber =
to_string(number);
77 return graphvizNumber;
82 auto pos = graphvizPoint.find(
'!');
83 if (pos != std::string::npos)
85 graphvizPoint.erase(pos, 1);
92 float y = boost::lexical_cast<float>(tokens.at(1));
93 return QPointF {boost::lexical_cast<float>(tokens.at(0)), y};
95 catch (boost::bad_lexical_cast&)
100 catch (
const std::invalid_argument& ia)
102 ARMARX_ERROR_S <<
"Invalid argument for float conversion: " << ia.what() <<
" " << tokens.at(0) <<
", " << tokens.at(1);
104 catch (
const std::out_of_range& e)
109 return QPointF(0, 0);
114 std::string graphvizPoint =
to_string(point.x());
115 graphvizPoint +=
",";
137 return graphvizPoint;
147 float y = boost::lexical_cast<float>(tokens.at(1));
148 float y2 = boost::lexical_cast<float>(tokens.at(3));
149 return QRectF {boost::lexical_cast<float>(tokens.at(0)), y,
150 boost::lexical_cast<float>(tokens.at(2)), y2
153 catch (boost::bad_lexical_cast&)
158 catch (
const std::invalid_argument& ia)
160 ARMARX_ERROR_S <<
"Invalid argument for float conversion: " << ia.what() <<
" " << tokens.at(0) <<
", " << tokens.at(1);
162 catch (
const std::out_of_range& e)
167 return QRectF(0, 0, 0, 0);
175 tokenVector splineStrings = splitBy(graphVizSplineType,
";");
178 for (
auto spline : splineStrings)
180 splines.push_back(tokenize(spline));
183 return mergeSplines(splines);
190 std::string graphvizSpline;
194 graphvizSpline +=
"e,";
195 graphvizSpline += convertFromPoint(*(spline.
endPoint));
196 graphvizSpline +=
" ";
201 graphvizSpline +=
"s,";
202 graphvizSpline += convertFromPoint(*(spline.
startPoint));
203 graphvizSpline +=
" ";
208 graphvizSpline += convertFromPoint(point);
209 graphvizSpline +=
" ";
213 simox::alg::trim(graphvizSpline);
215 return graphvizSpline;
227 for (
auto point : points)
231 if (tokens.size() == 3)
237 QPointF floatPoint {boost::lexical_cast<float>(tokens.at(1)), boost::lexical_cast<float>(tokens.at(2))};
239 if (tokens.at(0) ==
"s")
241 spline.
startPoint = std::make_shared<QPointF>(floatPoint);
245 spline.
endPoint = std::make_shared<QPointF>(floatPoint);
248 catch (boost::bad_lexical_cast&)
250 ARMARX_WARNING_S <<
" bad lexical cast to pointlist - value:" << graphVizSpline;
253 catch (
const std::invalid_argument& ia)
255 ARMARX_ERROR_S <<
"Invalid argument for float conversion: " << ia.what();
257 catch (
const std::out_of_range& e)
262 else if (tokens.size() == 2)
266 QPointF p {boost::lexical_cast<float>(tokens.at(0)), boost::lexical_cast<float>(tokens.at(1))};
269 catch (
const std::invalid_argument& ia)
271 ARMARX_ERROR_S <<
"Invalid argument for float conversion: " << ia.what() <<
" " << tokens.at(0) <<
", " << tokens.at(1);
273 catch (
const std::out_of_range& e)
280 ARMARX_ERROR_S <<
"Not a valid string to represent a spline control point: " << point;
289 armarx::tokenVector armarx::GraphvizConverter::splitBy(std::string toSplit, std::string divider)
292 size_t dividerPos = 0;
294 while (dividerPos != std::string::npos)
296 dividerPos = toSplit.find_first_of(divider);
297 std::string token = toSplit.substr(0, dividerPos);
298 toSplit = toSplit.substr(dividerPos + 1);
300 tokenVec.push_back(token);
308 if (toMerge.size() >= 1)
310 return toMerge.front();
312 SupportPoints merged;
313 merged.
startPoint = toMerge.front().startPoint;
314 merged.endPoint = toMerge.back().endPoint;
316 for (SupportPoints otherSpline : toMerge)
318 merged.controlPoints.append(otherSpline.controlPoints);
351 list.append(*startPoint.get());
354 list.append(controlPointList());
358 list.append(*endPoint.get());
368 for (QPointF point : controlPoints)
378 controlPoints.clear();
380 for (
auto point :
list)
382 controlPoints.push_back(point);
388 controlPoints.append(point);