From 7a45cd34e3fd8fb2d8773808603fad7a7e2a5945 Mon Sep 17 00:00:00 2001 From: godardma Date: Wed, 12 Nov 2025 14:38:56 +0100 Subject: [PATCH 1/3] drawing engine after hull details in motor_boat --- viewer/vibesgraphicsitem.cpp | 44 ++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/viewer/vibesgraphicsitem.cpp b/viewer/vibesgraphicsitem.cpp index 2803cb0..6a82f5a 100644 --- a/viewer/vibesgraphicsitem.cpp +++ b/viewer/vibesgraphicsitem.cpp @@ -1542,7 +1542,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY) body << QPointF(120,-80) + centerPoint; body << QPointF(-72,-80) + centerPoint; - // Draw with the new properties QGraphicsPolygonItem *graphics_body = new QGraphicsPolygonItem(body); graphics_body->setPen(pen); graphics_body->setBrush(brush); @@ -1561,7 +1560,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY) left_prop << QPointF(-72,16) + centerPoint; left_prop << QPointF(-80,16) + centerPoint; - // Draw with the new properties QGraphicsPolygonItem *graphics_left_prop = new QGraphicsPolygonItem(left_prop); graphics_left_prop->setPen(pen); graphics_left_prop->setBrush(QBrush(pen.color())); @@ -1580,7 +1578,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY) right_prop << QPointF(-72,-48) + centerPoint; right_prop << QPointF(-80,-48) + centerPoint; - // Draw with the new properties QGraphicsPolygonItem *graphics_right_prop = new QGraphicsPolygonItem(right_prop); graphics_right_prop->setPen(pen); graphics_right_prop->setBrush(QBrush(pen.color())); @@ -1590,6 +1587,25 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY) graphics_right_prop->setScale(length/401.); this->addToGroup(graphics_right_prop); } + + // Hull details + { + QPainterPath hull_details; + hull_details.moveTo(120 + centerPoint.x(), 80 + centerPoint.y()); + hull_details.lineTo(104 + centerPoint.x(), 64 + centerPoint.y()); + hull_details.lineTo(-56 + centerPoint.x(), 64 + centerPoint.y()); + hull_details.lineTo(-56 + centerPoint.x(), -64 + centerPoint.y()); + hull_details.lineTo(104 + centerPoint.x(), -64 + centerPoint.y()); + hull_details.lineTo(120 + centerPoint.x(), -80 + centerPoint.y()); + + QGraphicsPathItem *graphics_hull_details = new QGraphicsPathItem(hull_details); + graphics_hull_details->setPen(pen); + graphics_hull_details->setTransformOriginPoint(centerPoint); + graphics_hull_details->setRotation(orientation); + + graphics_hull_details->setScale(length/401.); + this->addToGroup(graphics_hull_details); + } // Engine { @@ -1599,7 +1615,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY) engine << QPointF(30,-22.5) + centerPoint; engine << QPointF(-15,-22.5) + centerPoint; - // Draw with the new properties QGraphicsPolygonItem *graphics_engine = new QGraphicsPolygonItem(engine); graphics_engine->setPen(pen); graphics_engine->setBrush(QBrush(pen.color())); @@ -1612,7 +1627,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY) // Circle { - // Draw with the new properties QGraphicsEllipseItem *circle_item = new QGraphicsEllipseItem(centerPoint.x()-24+200, centerPoint.y()-24, 48, 48); circle_item->setPen(pen); circle_item->setTransformOriginPoint(centerPoint); @@ -1621,26 +1635,6 @@ bool VibesGraphicsVehicleMotorBoat::computeProjection(int dimX, int dimY) circle_item->setScale(length/401.); this->addToGroup(circle_item); } - - // Hull details - { - QPainterPath hull_details; - hull_details.moveTo(120 + centerPoint.x(), 80 + centerPoint.y()); - hull_details.lineTo(104 + centerPoint.x(), 64 + centerPoint.y()); - hull_details.lineTo(-56 + centerPoint.x(), 64 + centerPoint.y()); - hull_details.lineTo(-56 + centerPoint.x(), -64 + centerPoint.y()); - hull_details.lineTo(104 + centerPoint.x(), -64 + centerPoint.y()); - hull_details.lineTo(120 + centerPoint.x(), -80 + centerPoint.y()); - - // Draw with the new properties - QGraphicsPathItem *graphics_hull_details = new QGraphicsPathItem(hull_details); - graphics_hull_details->setPen(pen); - graphics_hull_details->setTransformOriginPoint(centerPoint); - graphics_hull_details->setRotation(orientation); - - graphics_hull_details->setScale(length/401.); - this->addToGroup(graphics_hull_details); - } } // Update successful From e75e6afbcea1a351ac248c071093e11b8e9016a4 Mon Sep 17 00:00:00 2001 From: godardma Date: Thu, 13 Nov 2025 15:06:25 +0100 Subject: [PATCH 2/3] minor fix for drawText --- client-api/C++/examples/all_commands.cpp | 4 ++-- viewer/vibesgraphicsitem.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client-api/C++/examples/all_commands.cpp b/client-api/C++/examples/all_commands.cpp index 38cbd02..f975eeb 100644 --- a/client-api/C++/examples/all_commands.cpp +++ b/client-api/C++/examples/all_commands.cpp @@ -307,9 +307,9 @@ int main() // Testing VIbes drawText function VIBES_TEST( vibes::newFigure("drawText") ); - VIBES_TEST( vibes::drawText(2,2,"My Text") ); + VIBES_TEST( vibes::drawText(2,-1,"My Text") ); VIBES_TEST( vibes::drawText(2,2,"My Text", 0.1 , "b[k]") ); - VIBES_TEST( vibes::drawText(2,6,"My Text",vibesParams("FaceColor","red","EdgeColor","black","fontSize",15,"fontName","Cursive","name","Text") ) ); + VIBES_TEST( vibes::drawText(3,6,"My Text",vibesParams("FaceColor","red","EdgeColor","black","fontSize",15,"fontName","Cursive","name","Text") ) ); diff --git a/viewer/vibesgraphicsitem.cpp b/viewer/vibesgraphicsitem.cpp index 6a82f5a..12bc09f 100644 --- a/viewer/vibesgraphicsitem.cpp +++ b/viewer/vibesgraphicsitem.cpp @@ -1068,7 +1068,7 @@ bool VibesGraphicsText::computeProjection(int dimX, int dimY) { QFont textFont(fontName, fontSize); this->setFont(textFont); - this->setTransform(QTransform(1, 0, 0, -1, pos[0].toDouble(),pos[1].toDouble())); + this->setTransform(QTransform(1, 0, 0, -1, pos[0].toDouble(), pos[1].toDouble() + scale)); this->setText(text); this->setPen(pen); this->setBrush(brush); From 088b88b67956028eacf874d3d390606f3bb06a68 Mon Sep 17 00:00:00 2001 From: godardma Date: Thu, 13 Nov 2025 16:29:53 +0100 Subject: [PATCH 3/3] fix for drawText to avoid double translation when in a group --- client-api/C++/examples/all_commands.cpp | 4 +++- viewer/vibesgraphicsitem.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client-api/C++/examples/all_commands.cpp b/client-api/C++/examples/all_commands.cpp index f975eeb..90ba502 100644 --- a/client-api/C++/examples/all_commands.cpp +++ b/client-api/C++/examples/all_commands.cpp @@ -307,7 +307,9 @@ int main() // Testing VIbes drawText function VIBES_TEST( vibes::newFigure("drawText") ); - VIBES_TEST( vibes::drawText(2,-1,"My Text") ); + VIBES_TEST( vibes::newGroup("group") ); + VIBES_TEST( vibes::drawText(2,-1,"My Text")); + VIBES_TEST( vibes::drawText(2,-2,"My Text",vibesParams("group","group"))) ; VIBES_TEST( vibes::drawText(2,2,"My Text", 0.1 , "b[k]") ); VIBES_TEST( vibes::drawText(3,6,"My Text",vibesParams("FaceColor","red","EdgeColor","black","fontSize",15,"fontName","Cursive","name","Text") ) ); diff --git a/viewer/vibesgraphicsitem.cpp b/viewer/vibesgraphicsitem.cpp index 12bc09f..d431399 100644 --- a/viewer/vibesgraphicsitem.cpp +++ b/viewer/vibesgraphicsitem.cpp @@ -1041,7 +1041,6 @@ bool VibesGraphicsText::parseJsonGraphics(const QJsonObject& json) // #define GET_WITH_DEFAULT(dict,key,type,default_value) \ // dict.contains[key] ? dict[key].type - bool VibesGraphicsText::computeProjection(int dimX, int dimY) { const QJsonObject & json = this->_json; @@ -1068,7 +1067,8 @@ bool VibesGraphicsText::computeProjection(int dimX, int dimY) { QFont textFont(fontName, fontSize); this->setFont(textFont); - this->setTransform(QTransform(1, 0, 0, -1, pos[0].toDouble(), pos[1].toDouble() + scale)); + this->setTransform(QTransform(1, 0, 0, -1, 0., 0.)); + this->setPos(pos[0].toDouble(), pos[1].toDouble() + scale); this->setText(text); this->setPen(pen); this->setBrush(brush);