diff --git a/client-api/C++/examples/CMakeLists.txt b/client-api/C++/examples/CMakeLists.txt index a96232d..63878c4 100644 --- a/client-api/C++/examples/CMakeLists.txt +++ b/client-api/C++/examples/CMakeLists.txt @@ -17,6 +17,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_LIST_DIR}/../src/) ADD_EXECUTABLE(all_commands all_commands.cpp ${vibes_SOURCES}) +ADD_EXECUTABLE(newmain newmain.cpp ${vibes_SOURCES}) + INCLUDE_DIRECTORIES(interval) ADD_EXECUTABLE(sivia_simple sivia_simple.cpp ${interval_SOURCES} ${vibes_SOURCES}) diff --git a/viewer/vibesgraphicsitem.cpp b/viewer/vibesgraphicsitem.cpp index 497fde6..e9de77b 100644 --- a/viewer/vibesgraphicsitem.cpp +++ b/viewer/vibesgraphicsitem.cpp @@ -230,15 +230,24 @@ bool VibesGraphicsItem::parseJson(QJsonObject &json) format.remove(fcStart, fcEnd-fcStart+1); } // Extract LineStyle - const QStringList lineStyles = {"--","-.","-",":"}; + // ! styles with redundant parts must have their longest version + // placed at the end of the array + const QStringList lineStyles = {"-","--","-.","-..",":"}; + QStringList presentStyles; + vector fcStarts; foreach (const QString ls, lineStyles) { fcStart = format.indexOf(ls); if (fcStart >= 0) { - json["LineStyle"] = QJsonValue(ls); - format.remove(fcStart, ls.size()); + presentStyles.push_back(ls); + fcStarts.push_back(fcStart); } } + if(presentStyles.size()>0) + { + json["LineStyle"]=QJsonValue(presentStyles.back()); + format.remove(fcStarts.back(),presentStyles.back().size()); + } // Extract EdgeColor format = format.trimmed(); if (!format.isEmpty()) @@ -332,9 +341,7 @@ bool VibesGraphicsBox::parseJsonGraphics(const QJsonObject &json) // VibesGraphicsBox has JSON type "box" if (type == "box") { - cout << "type=box"<_nbDim = bounds.size() / 2; // Set graphical properties -// cout << "Avant setPen"<setPen( vibesDefaults.pen2( jsonValue("EdgeColor")) ); - //this->setPen( vibesDefaults.pen( jsonValue("EdgeColor").toString() ) ); -// cout << "Avant setBrush"<setBrush( vibesDefaults.brush( jsonValue("FaceColor").toString() ) ); + this->setPen( vibesDefaults.pen( jsonValue("EdgeColor") ) ); + this->setBrush( vibesDefaults.brush( jsonValue("FaceColor") ) ); // Update successful return true; @@ -367,10 +367,10 @@ bool VibesGraphicsBox::parseJsonGraphics(const QJsonObject &json) bool VibesGraphicsBox::computeProjection(int dimX, int dimY) { const QJsonObject & json = this->_json; - cout << "Compute Projection"<setRect(lb_x, lb_y, ub_x - lb_x, ub_y - lb_y); + // Handle lineStyle + if(json.contains("LineStyle")) + { + Q_ASSERT(json["LineStyle"].isString()); + string style=json["LineStyle"].toString().toStdString(); + pen.setStyle(vibesDefaults.styleToPenStyle(style)); + } + // Handle lineStyle + if(json.contains("LineWidth")) + { + Q_ASSERT(json["LineWidth"].isDouble()); + pen.setWidthF(std::fmax(json["LineWidth"].toDouble(0),0)); + } + // Update rectangle color this->setPen(pen); this->setBrush(brush); - + // Update successful return true; } @@ -438,8 +452,25 @@ bool VibesGraphicsBoxes::parseJsonGraphics(const QJsonObject &json) { QGraphicsRectItem * rect = qgraphicsitem_cast(item); if (!rect) continue; - rect->setPen( vibesDefaults.pen( jsonValue("EdgeColor").toString() ) ); - rect->setBrush( vibesDefaults.brush( jsonValue("FaceColor").toString() ) ); + + QPen pen=vibesDefaults.pen( jsonValue("EdgeColor") ) ; + QBrush brush=vibesDefaults.brush( jsonValue("EdgeColor") ) ; + // Handle lineStyle + if(json.contains("LineStyle")) + { + Q_ASSERT(json["LineStyle"].isString()); + string style=json["LineStyle"].toString().toStdString(); + pen.setStyle(vibesDefaults.styleToPenStyle(style)); + } + // Handle lineStyle + if(json.contains("LineWidth")) + { + Q_ASSERT(json["LineWidth"].isDouble()); + pen.setWidthF(std::fmax(json["LineWidth"].toDouble(0),0)); + } + + rect->setPen( pen); + rect->setBrush( brush ); } // Update successful @@ -456,8 +487,8 @@ bool VibesGraphicsBoxes::computeProjection(int dimX, int dimY) const QJsonObject & json = this->_json; // Get shape color (or default if not specified) - const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); - const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + QBrush brush = vibesDefaults.brush( jsonValue("FaceColor") ); + QPen pen = vibesDefaults.pen( jsonValue("EdgeColor") ); // Now process shape-specific properties // (we can only update properties of a shape, but mutation into another type is not supported) @@ -484,6 +515,21 @@ bool VibesGraphicsBoxes::computeProjection(int dimX, int dimY) double ub_y = box[2*dimY+1].toDouble(); // Create a new rect QGraphicsRectItem * rect = new QGraphicsRectItem(lb_x, lb_y, ub_x - lb_x, ub_y - lb_y); + + // Handle lineStyle + if(json.contains("LineStyle")) + { + Q_ASSERT(json["LineStyle"].isString()); + string style=json["LineStyle"].toString().toStdString(); + pen.setStyle(vibesDefaults.styleToPenStyle(style)); + } + // Handle lineStyle + if(json.contains("LineWidth")) + { + Q_ASSERT(json["LineWidth"].isDouble()); + pen.setWidthF(std::fmax(json["LineWidth"].toDouble(0),0)); + } + rect->setPen(pen); rect->setBrush(brush); // Add it to the group @@ -561,8 +607,8 @@ bool VibesGraphicsBoxesUnion::parseJsonGraphics(const QJsonObject &json) this->_nbDim = nbCols / 2; // Set graphical properties - this->setPen( vibesDefaults.pen( jsonValue("EdgeColor").toString() ) ); - this->setBrush( vibesDefaults.brush( jsonValue("FaceColor").toString() ) ); + this->setPen( vibesDefaults.pen( jsonValue("EdgeColor") ) ); + this->setBrush( vibesDefaults.brush( jsonValue("FaceColor") ) ); // Update successful return true; @@ -579,8 +625,8 @@ bool VibesGraphicsBoxesUnion::computeProjection(int dimX, int dimY) const QJsonObject & json = this->_json; // Get shape color (or default if not specified) - const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); - const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor") ); + const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor") ); // Now process shape-specific properties // (we can only update properties of a shape, but mutation into another type is not supported) @@ -661,8 +707,8 @@ bool VibesGraphicsEllipse::parseJsonGraphics(const QJsonObject &json) this->_nbDim = center.size(); // Set graphical properties - this->setPen( vibesDefaults.pen( jsonValue("EdgeColor").toString() ) ); - this->setBrush( vibesDefaults.brush( jsonValue("FaceColor").toString() ) ); + this->setPen( vibesDefaults.pen( jsonValue("EdgeColor") ) ); + this->setBrush( vibesDefaults.brush( jsonValue("FaceColor") ) ); // Update successful return true; @@ -679,8 +725,8 @@ bool VibesGraphicsEllipse::computeProjection(int dimX, int dimY) const QJsonObject & json = this->_json; // Get shape color (or default if not specified) - const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); - const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor") ); + const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor") ); Q_ASSERT (json.contains("type")); Q_ASSERT(json["type"].toString() == "ellipse"); @@ -820,7 +866,7 @@ bool VibesGraphicsLine::parseJsonGraphics(const QJsonObject &json) this->_nbDim = nbCols; // Set pen - this->setPen( vibesDefaults.pen( jsonValue("EdgeColor").toString() ) ); + this->setPen( vibesDefaults.pen( jsonValue("EdgeColor") ) ); // Update successful return true; @@ -838,7 +884,7 @@ bool VibesGraphicsLine::computeProjection(int dimX, int dimY) // Get line color (or default if not specified) //const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); - const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor") ); // Now process shape-specific properties // (we can only update properties of a shape, but mutation into another type is not supported) @@ -891,8 +937,8 @@ bool VibesGraphicsPolygon::parseJsonGraphics(const QJsonObject &json) this->_nbDim = nbCols; // Set pen - this->setPen( vibesDefaults.pen( jsonValue("EdgeColor").toString() ) ); - this->setBrush( vibesDefaults.brush( jsonValue("FaceColor").toString() ) ); + this->setPen( vibesDefaults.pen( jsonValue("EdgeColor") ) ); + this->setBrush( vibesDefaults.brush( jsonValue("FaceColor") ) ); // Update successful return true; @@ -908,8 +954,8 @@ bool VibesGraphicsPolygon::computeProjection(int dimX, int dimY) const QJsonObject & json = this->_json; // Get shape color (or default if not specified) - const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); - const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor") ); + const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor") ); Q_ASSERT(json.contains("type")); Q_ASSERT(json["type"].toString() == "polygon"); @@ -972,8 +1018,8 @@ bool VibesGraphicsVehicle::computeProjection(int dimX, int dimY) const QJsonObject & json = this->_json; // Get shape color (or default if not specified) - const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); - const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor") ); + const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor") ); Q_ASSERT(json.contains("type")); Q_ASSERT(json["type"].toString() == "vehicle"); @@ -1048,8 +1094,8 @@ bool VibesGraphicsVehicleAUV::computeProjection(int dimX, int dimY) const QJsonObject & json = this->_json; // Get shape color (or default if not specified) - const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); - const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor") ); + const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor") ); Q_ASSERT (json.contains("type")); Q_ASSERT(json["type"].toString() == "vehicle_auv"); @@ -1156,8 +1202,8 @@ bool VibesGraphicsArrow::computeProjection(int dimX, int dimY) const QJsonObject & json = this->_json; // Get arrow color (or default if not specified) - const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); - const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor") ); + const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor") ); // Now process shape-specific properties // (we can only update properties of a shape, but mutation into another type is not supported) @@ -1270,8 +1316,8 @@ bool VibesGraphicsPie::computeProjection(int dimX, int dimY) const QJsonObject & json = this->_json; // Get arrow color (or default if not specified) - const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor").toString() ); - const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor").toString() ); + const QBrush & brush = vibesDefaults.brush( jsonValue("FaceColor") ); + const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor") ); // Now process shape-specific properties // (we can only update properties of a shape, but mutation into another type is not supported) diff --git a/viewer/vibesgraphicsitem.h b/viewer/vibesgraphicsitem.h index 9bdc0df..9b7b11f 100644 --- a/viewer/vibesgraphicsitem.h +++ b/viewer/vibesgraphicsitem.h @@ -13,10 +13,7 @@ #include #include -#include -using namespace std; - -// Singleton class to hold Vibes defaults and constants +#// Singleton class to hold Vibes defaults and constants class VibesDefaults { QHash _brushes; QHash _pens; @@ -83,16 +80,35 @@ class VibesDefaults { return QColor(r,g,b,a); } - const QBrush brush(const QJsonValue &value) const { + static Qt::PenStyle styleToPenStyle(const std::string &style) + { + if(style=="--") + { + return Qt::DashLine; + } + if(style=="-.") + { + return Qt::DashDotLine; + } + if(style==":") + { + return Qt::DotLine; + } + if(style=="-..") + { + return Qt::DashDotDotLine; + } + return Qt::SolidLine; + } + + QBrush brush(const QJsonValue &value) const { QString name; if(value.isArray()) { - cout << "Brush isArray"<