Skip to content

Commit

Permalink
[viewer] added LineStyle and LineWidth support]
Browse files Browse the repository at this point in the history
  • Loading branch information
godardma committed Oct 7, 2024
1 parent 8dc7a7b commit f1038c4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
3 changes: 3 additions & 0 deletions client-api/C++/examples/all_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ int main()
VIBES_TEST(vibes::drawPoint(17,17,"red[darkyellow]"));
VIBES_TEST(vibes::drawPoint(27,27,2,vibesParams("FaceColor","magenta","EdgeColor","none","Draggable",true,"FixedScale",false)));

VIBES_TEST(vibes::drawBox(10,20,10,16,vibesParams("FaceColor","red","EdgeColor","black","LineStyle","-..","LineWidth","0.3","name","custom_line")))
VIBES_TEST(vibes::drawTank(12,6,30,4,"black[red]",vibesParams("LineWidth","0.5")))

VIBES_TEST( vibes::axisAuto() );
// VIBES_TEST( vibes::axisLimits(-1,1, -3,2) );

Expand Down
4 changes: 2 additions & 2 deletions client-api/python/vibes/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +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.drawAUV(5,3, 1, 2, color='blue[yellow]',name='auv1',LineStyle="..",LineWidth="0.3")
vibes.drawBox(2,4,4,7,color='red[yellow]', figure='test', name='box1',LineStyle="-..",LineWidth="0.1")
vibes.drawArrow((0,0), (1,1), 0.1, color='[b]', name='arrow1')

vibes.newFigure("raster")
Expand Down
41 changes: 19 additions & 22 deletions viewer/vibesgraphicsitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <cmath>
using namespace std;


// The only instance of VibesDefaults
VibesDefaults VibesDefaults::_instance;

Expand Down Expand Up @@ -275,19 +274,7 @@ 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");
}
// LineStyle and LineWidth need no processing

// Process object specific JSON
return parseJsonGraphics(json);
Expand Down Expand Up @@ -369,6 +356,7 @@ bool VibesGraphicsGroup::parseJsonGraphics(const QJsonObject &json)
{
item->setJsonValue("LineWidth",json["LineWidth"]);
}
// Update item display
item->updateProj();
}

Expand Down Expand Up @@ -1048,7 +1036,8 @@ bool VibesGraphicsVehicle::computeProjection(int dimX, int dimY)
// Get center
const QPointF & centerPoint = QPointF(center[dimX].toDouble(), center[dimY].toDouble());

// update child items if they exist
// If the shape has already been drawn, it has at least one child
// Update child items if they exist
if (this->childItems().size() > 0)
{
foreach(QGraphicsItem * item, this->childItems())
Expand All @@ -1062,6 +1051,7 @@ bool VibesGraphicsVehicle::computeProjection(int dimX, int dimY)
graphics_polygon->setScale(length / 4.); // initial vehicle's length is 4
}
}
// Else draw the shape for the first time
else{

// Set polygon shape
Expand Down Expand Up @@ -1145,7 +1135,8 @@ bool VibesGraphicsVehicleAUV::computeProjection(int dimX, int dimY)

/* This shape is inspired by the MOOS middleware GUI (see pMarineViewer) */

// update child items if they exist
// If the shape has already been drawn, it has at least one child
// Update child items if they exist
if (this->childItems().size() > 0)
{
foreach(QGraphicsItem * item, this->childItems())
Expand All @@ -1159,7 +1150,7 @@ bool VibesGraphicsVehicleAUV::computeProjection(int dimX, int dimY)
graphics_polygon->setScale(length / 7.); // initial vehicle's length is 4
}
}

// Else draw the shape for the first time
else{
// Set body shape
{
Expand Down Expand Up @@ -1272,7 +1263,8 @@ bool VibesGraphicsVehicleTank::computeProjection(int dimX, int dimY)

/* This shape is inspired by Luc Jaulin */

// update child items if they exist
// If the shape has already been drawn, it has at least one child
// Update child items if they exist
if (this->childItems().size() > 0)
{
foreach(QGraphicsItem * item, this->childItems())
Expand All @@ -1286,6 +1278,7 @@ bool VibesGraphicsVehicleTank::computeProjection(int dimX, int dimY)
graphics_polygon->setScale(length / 4.); // initial vehicle's length is 4
}
}
// Else draw the shape for the first time
else{

// Set body shape
Expand Down Expand Up @@ -1383,20 +1376,20 @@ bool VibesGraphicsArrow::computeProjection(int dimX, int dimY)

double before_last_x = 0., before_last_y = 0., last_x = 0., last_y = 0.;


// update child items if they exist
// If the shape has already been drawn, it has at least one child
// Update child items if they exist
if (this->childItems().size() > 0)
{
// item type : 2 if path, 5 if polygon
foreach(QGraphicsItem * item, this->childItems())
{
if (item->type() == 2)
if (item->type() == QGraphicsPathItem::Type)
{
//to vibes graphics item
QGraphicsPathItem *graphics_path = qgraphicsitem_cast<QGraphicsPathItem *>(item);
graphics_path->setPen(pen);
}
else if (item->type() == 5)
else if (item->type() == QGraphicsPolygonItem::Type)
{
//to vibes graphics item
QGraphicsPolygonItem *graphics_tip = qgraphicsitem_cast<QGraphicsPolygonItem *>(item);
Expand All @@ -1405,6 +1398,7 @@ bool VibesGraphicsArrow::computeProjection(int dimX, int dimY)
}
}
}
// Else draw the shape for the first time
else{
// Body
{
Expand Down Expand Up @@ -1526,6 +1520,8 @@ bool VibesGraphicsPie::computeProjection(int dimX, int dimY)
Q_ASSERT(rho[0].toDouble() >= 0);
Q_ASSERT(rho[1].toDouble() >= rho[0].toDouble());

// If the shape has already been drawn, it has at least one child
// Update child items if they exist
if (this->childItems().size() > 0)
{
foreach(QGraphicsItem * item, this->childItems())
Expand All @@ -1536,6 +1532,7 @@ bool VibesGraphicsPie::computeProjection(int dimX, int dimY)
graphics_polygon->setBrush(brush);
}
}
// Else draw the shape for the first time
else{
// Body
{
Expand Down
2 changes: 2 additions & 0 deletions viewer/vibesgraphicsitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ class VibesDefaults {
if(style == QString("-.")) return Qt::DashDotLine;
if(style == QString("-..")) return Qt::DashDotDotLine;
if(style == QString("..")) return Qt::DotLine;
// by Default SolidLine
return Qt::SolidLine;
}
const qreal parsePenWidth(const QString& width){
// Pen cannot have negative width
return std::max(0.,width.toDouble());
}
const QBrush brush(const QString & name = QString()) {
Expand Down

0 comments on commit f1038c4

Please sign in to comment.