@@ -57,6 +57,7 @@ LaneEditor::LaneEditor(ProjectWidget *projectWidget, ProjectData *projectData, T
: ProjectEditor(projectWidget, projectData, topviewGraph)
, roadSystemItem_(NULL)
, insertSectionHandle_(NULL)
, pointHandle_(NULL)
{
}

@@ -86,6 +87,11 @@ LaneEditor::init()
//
insertSectionHandle_ = new SectionHandle(roadSystemItem_);
insertSectionHandle_->hide();

// Width Add Handle //
//
pointHandle_ = new PointHandle(roadSystemItem_);
pointHandle_->hide();
}
}

@@ -108,6 +114,16 @@ LaneEditor::getInsertSectionHandle() const
return insertSectionHandle_;
}

PointHandle *
LaneEditor::getAddWidthHandle() const
{
if (!pointHandle_)
{
qDebug("ERROR 1010151634! LaneEditor not yet initialized.");
}
return pointHandle_;
}

//################//
// TOOL //
//################//
@@ -25,6 +25,7 @@ class LaneRoadSystemItem;
class BaseLaneMoveHandle;

class SectionHandle;
class PointHandle;

class LaneEditor : public ProjectEditor
{
@@ -41,6 +42,7 @@ class LaneEditor : public ProjectEditor
// Handle //
//
SectionHandle *getInsertSectionHandle() const;
PointHandle *getAddWidthHandle() const;

// Tool //
//
@@ -79,9 +81,10 @@ public slots:
//
LaneRoadSystemItem *roadSystemItem_;

// Handle //
// Handles //
//
SectionHandle *insertSectionHandle_;
PointHandle *pointHandle_;

// Edit Mode (width or border) //
//
@@ -32,6 +32,7 @@
#include "lanelinkitem.hpp"
#include "src/graph/topviewgraph.hpp"
#include "src/graph/graphscene.hpp"
#include "src/graph/items/roadsystem/sections/sectionhandle.hpp"

// Editor //
//
@@ -234,7 +235,6 @@ LaneItem::updateColor()
void
LaneItem::createPath()
{
RSystemElementRoad *road = parentLaneSection_->getParentRoad();

// Initialization //
//
@@ -267,7 +267,7 @@ LaneItem::createPath()
for (int i = 0; i < pointCount; ++i)
{
double s = sStart + i * segmentLength; // [sStart, sEnd]
points[i] = road->getGlobalPoint(s, laneSide * parentLaneSection_->getLaneSpanWidth(0, lane_->getId() - laneSide, s) + road->getLaneOffset(s));
points[i] = grandparentRoad_->getGlobalPoint(s, laneSide * parentLaneSection_->getLaneSpanWidth(0, lane_->getId() - laneSide, s) + grandparentRoad_->getLaneOffset(s));
}

// Left side //
@@ -277,19 +277,19 @@ LaneItem::createPath()
double s = sEnd - i * segmentLength; // [sEnd, sStart]
if (s < 0.0)
s = 0.0; // can happen due to numerical inaccuracy (around -1.0e-15)
points[i + pointCount] = road->getGlobalPoint(s, laneSide * parentLaneSection_->getLaneSpanWidth(0, lane_->getId(), s) + road->getLaneOffset(s));
points[i + pointCount] = grandparentRoad_->getGlobalPoint(s, laneSide * parentLaneSection_->getLaneSpanWidth(0, lane_->getId(), s) + grandparentRoad_->getLaneOffset(s));
}

// End point //
//
points[2 * pointCount] = road->getGlobalPoint(sStart, laneSide * parentLaneSection_->getLaneSpanWidth(0, lane_->getId() - laneSide, sStart) + road->getLaneOffset(sStart));
points[2 * pointCount] = grandparentRoad_->getGlobalPoint(sStart, laneSide * parentLaneSection_->getLaneSpanWidth(0, lane_->getId() - laneSide, sStart) + grandparentRoad_->getLaneOffset(sStart));
}
else
{
for (int i = 0; i < pointCount; ++i)
{
double s = sStart + i * segmentLength; // [sStart, sEnd]
points[i] = road->getGlobalPoint(s, laneSide * parentLaneSection_->getLaneWidth(lane_->getId() - laneSide, s));
points[i] = grandparentRoad_->getGlobalPoint(s, laneSide * parentLaneSection_->getLaneWidth(lane_->getId() - laneSide, s));
}

// Left side //
@@ -299,12 +299,12 @@ LaneItem::createPath()
double s = sEnd - i * segmentLength; // [sEnd, sStart]
if (s < 0.0)
s = 0.0; // can happen due to numerical inaccuracy (around -1.0e-15)
points[i + pointCount] = road->getGlobalPoint(s, laneSide * parentLaneSection_->getLaneWidth(lane_->getId(), s));
points[i + pointCount] = grandparentRoad_->getGlobalPoint(s, laneSide * parentLaneSection_->getLaneWidth(lane_->getId(), s));
}

// End point //
//
points[2 * pointCount] = road->getGlobalPoint(sStart, laneSide * parentLaneSection_->getLaneWidth(lane_->getId() - laneSide, sStart));
points[2 * pointCount] = grandparentRoad_->getGlobalPoint(sStart, laneSide * parentLaneSection_->getLaneWidth(lane_->getId() - laneSide, sStart));
}


@@ -345,7 +345,7 @@ LaneItem::updateObserver()

// Road //
//
int roadChanges = parentLaneSection_->getParentRoad()->getRoadChanges();
int roadChanges = grandparentRoad_->getRoadChanges();
if ((roadChanges & RSystemElementRoad::CRD_TrackSectionChange)
|| (roadChanges & RSystemElementRoad::CRD_LaneSectionChange)
|| (roadChanges & RSystemElementRoad::CRD_ShapeChange))
@@ -371,8 +371,7 @@ LaneItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
ODD::ToolId tool = parentLaneSectionItem_->getLaneEditor()->getCurrentTool();
if ((tool == ODD::TLE_ADD_WIDTH) && (event->button() == Qt::LeftButton))
{
RSystemElementRoad *road = parentLaneSection_->getParentRoad();
double s = road->getSFromGlobalPoint(event->pos(), parentLaneSection_->getSStart(), parentLaneSection_->getSEnd()) - parentLaneSection_->getSStart();
double s = grandparentRoad_->getSFromGlobalPoint(event->pos(), parentLaneSection_->getSStart(), parentLaneSection_->getSEnd()) - parentLaneSection_->getSStart();

double startWidth = lane_->getWidth(s);
// double slope = lane_->getSlope(s);
@@ -405,6 +404,25 @@ LaneItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
void
LaneItem::hoverMoveEvent(QGraphicsSceneHoverEvent * event)
{
ODD::ToolId tool = parentLaneSectionItem_->getLaneEditor()->getCurrentTool();
if (tool == ODD::TLE_ADD_WIDTH)
{
setCursor(Qt::CrossCursor);

double s = grandparentRoad_->getSFromGlobalPoint(event->pos(), parentLaneSection_->getSStart(), parentLaneSection_->getSEnd()) - parentLaneSection_->getSStart();
double t;
if (lane_->getId() > 0)
{
t = parentLaneSection_->getLaneSpanWidth(0, lane_->getId() - 1, s) + lane_->getWidth(s) / 2;
}
else
{
t = -parentLaneSection_->getLaneSpanWidth(0, lane_->getId() + 1, s) - lane_->getWidth(s) / 2;
}

parentLaneSectionItem_->getLaneEditor()->getAddWidthHandle()->updatePos(parentLaneSectionItem_->getParentRoadItem(), grandparentRoad_->getGlobalPoint(s, t), parentLaneSection_->getSStart(), parentLaneSection_->getSEnd());
parentLaneSectionItem_->getLaneEditor()->getAddWidthHandle()->show();
}
parentLaneSectionItem_->hoverMoveEvent(event);
}

@@ -254,7 +254,7 @@ LaneSectionItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
setCursor(Qt::PointingHandCursor);
}
else if (tool == ODD::TLE_ADD || tool == ODD::TLE_ADD_WIDTH)
else if (tool == ODD::TLE_ADD)
{
setCursor(Qt::CrossCursor);
laneEditor_->getInsertSectionHandle()->updatePos(parentRoadItem_, event->scenePos(), laneSection_->getSStart(), laneSection_->getSEnd());
@@ -283,10 +283,14 @@ LaneSectionItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
// does nothing //
}
else if (tool == ODD::TLE_ADD || tool == ODD::TLE_ADD_WIDTH)
else if (tool == ODD::TLE_ADD)
{
laneEditor_->getInsertSectionHandle()->hide();
}
else if (tool == ODD::TLE_ADD_WIDTH)
{
laneEditor_->getAddWidthHandle()->hide();
}
else if (tool == ODD::TLE_DEL)
{
// does nothing //
@@ -311,10 +315,14 @@ LaneSectionItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
// does nothing //
}
else if (tool == ODD::TLE_ADD || tool == ODD::TLE_ADD_WIDTH)
else if (tool == ODD::TLE_ADD)
{
laneEditor_->getInsertSectionHandle()->updatePos(parentRoadItem_, event->scenePos(), laneSection_->getSStart(), laneSection_->getSEnd());
}
else if (tool == ODD::TLE_ADD_WIDTH)
{
laneEditor_->getAddWidthHandle()->updatePos(parentRoadItem_, event->scenePos(), laneSection_->getSStart(), laneSection_->getSEnd());
}
else if (tool == ODD::TLE_DEL)
{
// does nothing //
@@ -19,6 +19,7 @@
//
#include "src/data/roadsystem/rsystemelementroad.hpp"
#include "src/data/roadsystem/sections/roadsection.hpp"
#include "src/data/roadsystem/sections/lanesection.hpp"
#include "src/data/commands/roadsectioncommands.hpp"

// Graph //
@@ -235,3 +236,23 @@ SectionHandle::createPath()

SectionHandle::pathTemplate_ = &pathTemplate;
}

//##############################//
//
// PointHandle
//
//##############################//
void
PointHandle::updatePos(RoadItem *roadItem, const QPointF &position, double sStartHint, double sEndHint)
{
RSystemElementRoad *road = roadItem->getRoad();

// Calculate road coordinate //
//
double s = road->getSFromGlobalPoint(position, sStartHint, sEndHint);

// Set Item Pose //
//
setPos(position);
setRotation(road->getGlobalHeading(s));
}
@@ -39,7 +39,7 @@ class SectionHandle : public QGraphicsPathItem
}

void updateTransform();
void updatePos(RoadItem *roadItem, const QPointF &position, double sStartHint, double sEndHint);
virtual void updatePos(RoadItem *roadItem, const QPointF &position, double sStartHint, double sEndHint);

protected:
private:
@@ -81,4 +81,24 @@ class SectionHandle : public QGraphicsPathItem
static QPainterPath *pathTemplate_; // this path will be shared by all handles
};

class PointHandle : public SectionHandle
{
public:
explicit PointHandle(RoadSystemItem *parentRoadSystemItem)
: SectionHandle(parentRoadSystemItem)
{};

virtual ~PointHandle()
{ /* does nothing */
}

virtual void updatePos(RoadItem *roadItem, const QPointF &position, double sStartHint, double sEndHint);

protected:
private:
PointHandle(); /* not allowed */
PointHandle(const PointHandle &); /* not allowed */
PointHandle &operator=(const PointHandle &); /* not allowed */
};

#endif // SECTIONHANDLE_HPP