Skip to content

Commit

Permalink
enabled linestyle and linewidth from JSON (for APIs)
Browse files Browse the repository at this point in the history
  • Loading branch information
godardma committed Sep 7, 2024
1 parent c72a678 commit 8f83303
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
6 changes: 4 additions & 2 deletions client-api/python/vibes/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
vibes.drawBox(0,1,4,6,color='[#FF12FFA0]', figure='test')
vibes.drawText(12, 12, 'My Text', 0.1, 'b[r]')
vibes.axisAuto()
vibes.drawBox(0.5,2,4,7,color='[#00FFFF66]', figure='test')
vibes.drawBox(0.5,2,4,7,color='[#00FFFF66]', figure='test', name='box1')
vibes.drawBox(-1,0,-4,-6,color='r', figure='test')
vibes.drawLine([[0,0], [4,4]])
vibes.drawEllipse(3, 5, 1, 3, 45)
Expand All @@ -25,7 +25,7 @@
vibes.drawPie([0,0], [5,9], [-120, -40], group="Pie")
# vibes.drawPie([0,0], [5,9], [-120, -40], "[b]")

vibes.drawPie([5,2], [1,2], [160, 220]) #, 'g[y]')
vibes.drawPie([5,2], [1,2], [160, 220],name="pie alone") #, 'g[y]')

# vibes.clearGroup("Pie", figure="test")

Expand Down Expand Up @@ -57,6 +57,8 @@

vibes.drawPolygon([[1,1], [1,4], [5,2], [5, 1]])
vibes.setFigureProperties({'viewbox':'equal'})
vibes.drawAUV(5,3, 1, 2, color='b[yellow]',name='auv1',linestyle="..",linewidth="0.3")
vibes.drawBox(2,4,4,7,color='r[yellow]', figure='test', name='box1',linestyle="-..",linewidth="0.1")

vibes.newFigure("raster")
vibes.drawArrow((0,0), (1,1), 0.1)
Expand Down
37 changes: 20 additions & 17 deletions viewer/vibesgraphicsitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,7 @@ bool VibesGraphicsItem::parseJson(QJsonObject &json)
json["FaceColor"] = QJsonValue(format.mid(fcStart + 1, fcEnd - fcStart - 1).trimmed());
format.remove(fcStart, fcEnd - fcStart + 1);
}
// Extract LineStyle
const QStringList lineStyles = {"-", "--","-.","-..", ".."};

foreach(const QString ls, lineStyles)
{
fcStart = format.indexOf(ls);
if (fcStart >= 0)
{
json["LineStyle"] = QJsonValue(ls);
format.remove(fcStart, ls.size());
}
}

// Extract EdgeColor
format = format.trimmed();
if (!format.isEmpty())
Expand All @@ -285,6 +274,20 @@ bool VibesGraphicsItem::parseJson(QJsonObject &json)
this->setName(json["name"].toString());
}

// Process object linewidth
if (json.contains("linewidth") )
{
json["LineWidth"] = QJsonValue(json["linewidth"]);
json.remove("linewidth");
}

// Process object linestyle
if (json.contains("linestyle") )
{
json["LineStyle"] = QJsonValue(json["linestyle"]);
json.remove("linestyle");
}

// Process object specific JSON
return parseJsonGraphics(json);
}
Expand Down Expand Up @@ -489,7 +492,7 @@ bool VibesGraphicsBoxes::parseJsonGraphics(const QJsonObject &json)
{
QGraphicsRectItem * rect = qgraphicsitem_cast<QGraphicsRectItem *>(item);
if (!rect) continue;
rect->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString()));
rect->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString()));
rect->setBrush(vibesDefaults.brush(jsonValue("FaceColor").toString()));
}

Expand Down Expand Up @@ -614,7 +617,7 @@ bool VibesGraphicsBoxesUnion::parseJsonGraphics(const QJsonObject &json)
this->_nbDim = nbCols / 2;

// Set graphical properties
this->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString()));
this->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString()));
this->setBrush(vibesDefaults.brush(jsonValue("FaceColor").toString()));

// Update successful
Expand Down Expand Up @@ -716,7 +719,7 @@ bool VibesGraphicsEllipse::parseJsonGraphics(const QJsonObject &json)
this->_nbDim = center.size();

// Set graphical properties
this->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString()));
this->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString()));
this->setBrush(vibesDefaults.brush(jsonValue("FaceColor").toString()));

// Update successful
Expand Down Expand Up @@ -875,7 +878,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").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString()));

// Update successful
return true;
Expand Down Expand Up @@ -1663,7 +1666,7 @@ bool VibesGraphicsPoints::parseJsonGraphics(const QJsonObject& json)
{
QGraphicsEllipseItem * disk = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
if (!disk) continue;
disk->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString()));
disk->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString()));
disk->setBrush(vibesDefaults.brush(jsonValue("FaceColor").toString()));
}
// Update successful
Expand Down

0 comments on commit 8f83303

Please sign in to comment.