Skip to content

Commit

Permalink
few previous commits fix ENSTABretagneRobotics#64
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaje committed Oct 12, 2015
1 parent c593b92 commit bf00460
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 4 deletions.
40 changes: 39 additions & 1 deletion client-api/C++/examples/all_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,44 @@ int main()
VIBES_TEST( vibes::axisLabels(labels) );
}

cout << "plotting y=abs(cos(x)), y=abs(sin(x)), y=abs(sin(sin(x)))"<<endl;
{
const int nbPts = 1000;
const double xStep = 0.01;

std::vector< std::vector<double> > points;
std::vector<double> point(2);
std::vector< double > vect_x2;
std::vector< double > vect_y2;

std::vector< double > vect_x3;
std::vector< double > vect_y3;
for (int i=0; i<nbPts; ++i)
{
const double x = xStep * i;
point[0] = x;
point[1] = fabs(cos(x));
points.push_back(point);

vect_x2.push_back(x);
vect_y2.push_back(fabs(sin(x)));

vect_x3.push_back(x);
vect_y3.push_back(sin(sin(x)));
}
VIBES_TEST( vibes::newFigure("abs(cos), abs(sin), sin(sin)") );
VIBES_TEST( vibes::drawLine(points,"tomato-..") );
VIBES_TEST(vibes::drawLine(vect_x2,vect_y2,vibesParams("LineWidth",0.07,"LineStyle",":","EdgeColor",(vibes::RGBA){255,255,255,255})));
VIBES_TEST(vibes::drawLine(vect_x3,vect_y3,vibesParams("LineWidth",0.0042,"LineStyle","--","EdgeColor",(vibes::RGBA){0,128,128,108})));

VIBES_TEST( vibes::axisAuto() );

VIBES_TEST( vibes::setFigureProperties("abs(cos)",
vibesParams("x",0,"y",220,"width",450,"height",100)) );
std::vector<std::string> labels;
labels.push_back("x"); labels.push_back("abs cos x"); labels.push_back("abs sin x"); labels.push_back("sin sin x");
VIBES_TEST( vibes::axisLabels(labels) );
}

VIBES_TEST( vibes::newFigure("figureTest") );

Expand Down Expand Up @@ -182,7 +220,7 @@ int main()
x.push_back(2); y.push_back(7);
x.push_back(0.5); y.push_back(4);
x.push_back(-0.5); y.push_back(4);
VIBES_TEST( vibes::drawPolygon(x, y, "yellow[red]") );
VIBES_TEST( vibes::drawPolygon(x, y, "red--[yellowgreen]") );
}

cout << "drawVehicle" << std::endl;
Expand Down
34 changes: 31 additions & 3 deletions viewer/vibesgraphicsitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,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") );
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)
Expand All @@ -906,6 +906,19 @@ bool VibesGraphicsLine::computeProjection(int dimX, int dimY)
path.addPolygon(polygon);
this->setPath(path);
// Set graphics properties
// 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));
}
this->setPen(pen);
//this->setBrush(brush);

Expand Down Expand Up @@ -954,8 +967,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") );
const QPen & pen = vibesDefaults.pen( jsonValue("EdgeColor") );
QBrush brush = vibesDefaults.brush( jsonValue("FaceColor") );
QPen pen = vibesDefaults.pen( jsonValue("EdgeColor") );

Q_ASSERT(json.contains("type"));
Q_ASSERT(json["type"].toString() == "polygon");
Expand All @@ -970,6 +983,21 @@ bool VibesGraphicsPolygon::computeProjection(int dimX, int dimY)
this->setPolygon(polygon);

// Update polygon color

// Set graphics properties
// 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));
}
this->setPen(pen);
this->setBrush(brush);

Expand Down
11 changes: 11 additions & 0 deletions viewer/vibesgraphicsitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ class VibesDefaults {
name=value.toString();
}
}
QColor c(name.toLower());
if(c.isValid())
{
return QBrush(c);
}
return _brushes[name];
}

Expand All @@ -143,6 +148,12 @@ class VibesDefaults {
name=value.toString();
}
}
QColor c;
c.setNamedColor(name.toLower());
if(c.isValid())
{
return QPen(c,0);
}
return _pens[name];
}
private:
Expand Down

0 comments on commit bf00460

Please sign in to comment.