Example #1
0
void
BridgeItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
	pressPos_ = lastPos_ = event->scenePos();
    ODD::ToolId tool = signalEditor_->getCurrentTool(); // Editor Delete Bridge
    if (tool == ODD::TSG_DEL)
    {
        removeBridge();
    }
    else
    {
		doPan_ = true;

		if (copyPan_)
		{
			if (tunnel_)
			{
				Tunnel *newTunnel = tunnel_->getClone();
				AddBridgeCommand *command = new AddBridgeCommand(newTunnel, bridge_->getParentRoad(), NULL);
				getProjectGraph()->executeCommand(command);
			}
			else
			{
				Bridge *newBridge = bridge_->getClone();
				AddBridgeCommand * command = new AddBridgeCommand(newBridge, bridge_->getParentRoad(), NULL);
				getProjectGraph()->executeCommand(command);
			}
		}
        GraphElement::mousePressEvent(event); // pass to baseclass
    }
}
void
SuperelevationSectionPolynomialItem::splitSection()
{
    double s = 0.5 * (superelevationSection_->getSStart() + superelevationSection_->getSEnd());

    SplitSuperelevationSectionCommand *command = new SplitSuperelevationSectionCommand(superelevationSection_, s, NULL);
    getProjectGraph()->executeCommand(command);
}
Example #3
0
void
JunctionElementItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        ODD::ToolId tool = getJunctionEditor()->getCurrentTool();
        if (tool == ODD::TTE_ROAD_DELETE)
        {
            removeParentRoad();
            return;
        }
        else if (tool == ODD::TTE_DELETE)
        {
            removeSection();
            return;
        }
        else if (tool == ODD::TJE_SPLIT)
        {
            RSystemElementRoad *road = trackElement_->getParentRoad();
            double s = road->getSFromGlobalPoint(event->scenePos(), trackElement_->getSStart(), trackElement_->getSEnd());

            getProjectData()->getUndoStack()->beginMacro(QObject::tr("Split Track and Road"));

            // Split Track //
            //
            SplitTrackComponentCommand *splitTrackCommand = new SplitTrackComponentCommand(trackElement_, s, NULL);
            getProjectGraph()->executeCommand(splitTrackCommand);

            // Split Road //
            //
            SplitRoadCommand *splitRoadCommand = new SplitRoadCommand(road, s, NULL);
            getProjectGraph()->executeCommand(splitRoadCommand);

            getProjectData()->getUndoStack()->endMacro();
            return;
        }
        //		else if(tool == ODD::TTE_MOVE)
        //		{
        //			return; // does nothing
        //		}
    }

    // parent: selection //
    JunctionComponentItem::mouseReleaseEvent(event); // pass to baseclass
}
Example #4
0
void
BridgeItem::init()
{
    // Hover Events //
    //
    setAcceptHoverEvents(true);
    setSelectable();
	setFlag(ItemIsFocusable);

	// Save a tunnel 
	//
	tunnel_ = dynamic_cast<Tunnel *>(bridge_);
    // Signal Editor
    //
    signalEditor_ = dynamic_cast<SignalEditor *>(getProjectGraph()->getProjectWidget()->getProjectEditor());

	// Signal Manager
	//
	signalManager_ = getProjectData()->getProjectWidget()->getMainWindow()->getSignalManager();

	// Category Size
	//
	categorySize_ = signalManager_->getCategoriesSize();

    // Context Menu //
    //

    QAction *removeRoadAction = getRemoveMenu()->addAction(tr("Bridge"));
    connect(removeRoadAction, SIGNAL(triggered()), this, SLOT(removeBridge()));

    if (getTopviewGraph()) // not for profile graph
    {
        // Text //
        //
        bridgeTextItem_ = new BridgeTextItem(this, bridge_);
        bridgeTextItem_->setZValue(1.0); // stack before siblings
    }

	road_ = bridge_->getParentRoad(); 
	closestRoad_ = road_;
	pos_ = road_->getGlobalPoint(bridge_->getSStart());

    updateColor();
    updatePosition();
    createPath();

	doPan_ = false;
	copyPan_ = false;
}
Example #5
0
void
LaneRoadItem::init()
{
    // ElevationEditor //
    //
    laneEditor_ = dynamic_cast<LaneEditor *>(getProjectGraph()->getProjectWidget()->getProjectEditor());
    if (!laneEditor_)
    {
        qDebug("Warning 1006241105! ElevationRoadItem not created by an ElevationEditor");
    }
    // SectionItems //
    //
    foreach (LaneSection *section, getRoad()->getLaneSections())
    {
        new LaneSectionItem(laneEditor_, this, section);
    }
Example #6
0
void
SuperelevationRoadItem::init()
{
    // SuperelevationEditor //
    //
    superelevationEditor_ = dynamic_cast<SuperelevationEditor *>(getProjectGraph()->getProjectWidget()->getProjectEditor());
    if (!superelevationEditor_)
    {
        qDebug("Warning 1007141555! SuperelevationRoadItem not created by an SuperelevationEditor");
    }

    // SectionItems //
    //
    foreach (SuperelevationSection *section, getRoad()->getSuperelevationSections())
    {
        new SuperelevationSectionItem(superelevationEditor_, this, section);
    }
Example #7
0
void
JunctionRoadItem::init()
{
    // JunctionEditor //
    //
    junctionEditor_ = dynamic_cast<JunctionEditor *>(getProjectGraph()->getProjectWidget()->getProjectEditor());
    if (!junctionEditor_)
    {
        qDebug("Warning 1007041414! JunctionRoadItem not created by an JunctionEditor");
    }

    // Parent //
    //
    parentJunctionRoadSystemItem_->addRoadItem(this);

    // JunctionSection Items //
    //
    rebuildSections(true);
}
void
SuperelevationSectionPolynomialItem::createPath()
{
    // Initialization //
    //
    double sStart = superelevationSection_->getSStart();
    double sEnd = superelevationSection_->getSEnd();
    if (sEnd < sStart)
        sEnd = sStart;

    //	double pointsPerMeter = 2.0; // BAD: hard coded!
    double pointsPerMeter = getProjectGraph()->getProjectWidget()->getLODSettings()->HeightEditorPointsPerMeter;

    int pointCount = int(ceil((sEnd - sStart) * pointsPerMeter)); // TODO curvature...
    if (pointCount < 2)
    {
        pointCount = 2;
    }

    QVector<QPointF> points(pointCount);
    double segmentLength = (sEnd - sStart) / (pointCount - 1);

    // Points //
    //
    for (int i = 0; i < pointCount; ++i)
    {
        double s = sStart + i * segmentLength; // [sStart, sEnd]
        points[i] = QPointF(s, superelevationSection_->getSuperelevationDegrees(s));
    }

    // Psycho-Path //
    //
    QPainterPath path;
    path.addPolygon(QPolygonF(points));

    setPath(path);
}
Example #9
0
/*!
* Initializes the path (only once).
*/
void
OSCBridgeItem::createPath()
{
	if (path_)
	{
		delete path_;
	}

	path_ = new QPainterPath();

    setBrush(QBrush(outerColor_));
    setPen(QPen(outerColor_, 2.0));


    if (bridge_->getLength() > NUMERICAL_ZERO3) // Bridge is repeated
    {
        double totalLength = 0.0;
        double currentS = bridge_->getSStart();

        // Left and right side //
        //
        while ((totalLength < bridge_->getLength()) && (currentS < road_->getLength()))
        {
            LaneSection *laneSection = road_->getLaneSection(currentS);
            double t = laneSection->getLaneSpanWidth(0, laneSection->getRightmostLaneId() - 1, currentS);
            QPointF currentPos = road_->getGlobalPoint(currentS, t);

            if (totalLength == 0)
            {
                path_->moveTo(currentPos.x(), currentPos.y());
            }
            else
            {
                path_->lineTo(currentPos.x(), currentPos.y());
                path_->moveTo(currentPos.x(), currentPos.y());
            }

            //				double dist = 4; // TODO get configured tesselation length Jutta knows where to get this from
            double dist = 1 / getProjectGraph()->getProjectWidget()->getLODSettings()->TopViewEditorPointsPerMeter;

            if ((totalLength + dist) > bridge_->getLength())
            {
                QPointF currentPos = road_->getGlobalPoint(currentS + (bridge_->getLength() - totalLength), t);
                path_->lineTo(currentPos.x(), currentPos.y());
            }

            totalLength += dist;
            currentS += dist;
        }

        totalLength = 0.0;
        currentS = bridge_->getSStart();

        // Left and right side //
        //
        while ((totalLength < bridge_->getLength()) && (currentS < road_->getLength()))
        {
            LaneSection *laneSection = road_->getLaneSection(currentS);
            double t = -laneSection->getLaneSpanWidth(laneSection->getLeftmostLaneId(), 0, currentS);
            QPointF currentPos = road_->getGlobalPoint(currentS, t);

            if (totalLength == 0)
            {
                path_->moveTo(currentPos.x(), currentPos.y());
            }
            else
            {
                path_->lineTo(currentPos.x(), currentPos.y());
                path_->moveTo(currentPos.x(), currentPos.y());
            }

            //				double dist = 4; // TODO get configured tesselation length Jutta knows where to get this from
            double dist = 1 / getProjectGraph()->getProjectWidget()->getLODSettings()->TopViewEditorPointsPerMeter;

            if ((totalLength + dist) > bridge_->getLength())
            {
                QPointF currentPos = road_->getGlobalPoint(currentS + (bridge_->getLength() - totalLength), t);
                path_->lineTo(currentPos.x(), currentPos.y());
            }

            totalLength += dist;
            currentS += dist;
        }
    }

    setPath(*path_);
}
bool
SuperelevationSectionPolynomialItem::removeSection()
{
    RemoveSuperelevationSectionCommand *command = new RemoveSuperelevationSectionCommand(superelevationSection_, NULL);
    return getProjectGraph()->executeCommand(command);
}
Example #11
0
void
OSCItem::init()
{
	
    // Hover Events //
    //
    setAcceptHoverEvents(true);
//    setSelectable();
	setFlag(QGraphicsItem::ItemIsSelectable);
	setFlag(ItemIsFocusable);

    // OpenScenario Editor
    //
    oscEditor_ = dynamic_cast<OpenScenarioEditor *>(getProjectGraph()->getProjectWidget()->getProjectEditor());

    // Context Menu //
    //

    QAction *removeElementAction = getRemoveMenu()->addAction(tr("OpenScenario Object"));
    connect(removeElementAction, SIGNAL(triggered()), this, SLOT(removeElement()));

    if (getTopviewGraph()) // not for profile graph
    {
        // Text //
        //
        oscTextItem_ = new OSCTextItem(this, oscObject_, pos_);
        oscTextItem_->setZValue(1.0); // stack before siblings
    }

	road_ = getProjectGraph()->getProjectData()->getRoadSystem()->getRoad(roadID_);
	closestRoad_ = road_;
	roadSystemItem_ = oscBaseItem_->getRoadSystemItem();

	doPan_ = false;
	copyPan_ = false;

	// TODO: get type and object from catalog reference //
	//

	const std::string refId = oscObject_->catalogReference->catalogId.getValue();
	OpenScenario::oscEntity *entityObject = dynamic_cast<OpenScenario::oscEntity *>(entityCatalog_->getCatalogObject(stoi(refId)));

	OpenScenario::oscCatalog *catalog;
	int id = entityObject->objectChoice->vehicle->refId.getValue();

	if (id > 0)
	{
		createPath = createVehiclePath;
		catalog = oscEditor_->getCatalog("vehicleCatalog");
		catalog->setCatalogType("vehicle");
	}

	if (catalog->getObjectsMap().size() == 0)
	{
		//get all catalog object filenames
		std::vector<bf::path> filenames = catalog->getXoscFilesFromDirectory(catalog->directory->path.getValue());

		//parse all files
		//store object name and filename in map
		catalog->fastReadCatalogObjects(filenames);
	}

	selectedObject_ = catalog->getCatalogObject(id);
	if (!selectedObject_)
	{
		catalog->fullReadCatalogObjectWithName(id);
		selectedObject_ = catalog->getCatalogObject(id);
	}

	createPath(selectedObject_);

	updateColor("oscVehicle");
    updatePosition();
}
Example #12
0
bool
BridgeItem::removeBridge()
{
    RemoveBridgeCommand *command = new RemoveBridgeCommand(bridge_, road_);
    return getProjectGraph()->executeCommand(command);
}
Example #13
0
void
JunctionElementItem::createPath()
{
    RSystemElementRoad *road = trackElement_->getParentRoad();

    // Initialization //
    //
    double sStart = trackElement_->getSStart() + 0.001; // 1mm gap
    double sEnd = trackElement_->getSEnd() - 0.001; // 1mm gap
    if (sEnd < sStart)
        sEnd = sStart;

    //	double pointsPerMeter = 1.0; // BAD: hard coded!
    double pointsPerMeter = getProjectGraph()->getProjectWidget()->getLODSettings()->TopViewEditorPointsPerMeter;
    int pointCount = int(ceil((sEnd - sStart) * pointsPerMeter)); // TODO curvature...
    if (pointCount <= 1)
    {
        pointCount = 2; // should be at least 2 to get a quad
    }
    QVector<QPointF> points(2 * pointCount + 1);
    double segmentLength = (sEnd - sStart) / (pointCount - 1);

    // Right side //
    //
    for (int i = 0; i < pointCount; ++i)
    {
        double s = sStart + i * segmentLength; // [sStart, sEnd]
        if (road)
        {
            points[i] = trackElement_->getPoint(s, road->getMinWidth(s));
        }
        else
        {

            points[i] = trackElement_->getPoint(s, 0.0);
        }
        //		qDebug() << s << " " << points[i] << " " << road->getMinWidth(s);
        if (i > 0 && (points[i] - points[i - 1]).manhattanLength() > 30)
        {
            //			QPointF tmp = trackElement_->getPoint(s, road->getMinWidth(s));
            //			qDebug() << "*************";
        }
    }

    // Left side //
    //
    for (int i = 0; i < pointCount; ++i)
    {
        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] = trackElement_->getPoint(s, road->getMaxWidth(s));
    }

    // End point //
    //
    points[2 * pointCount] = trackElement_->getPoint(sStart, road->getMinWidth(sStart));

    // Psycho-Path //
    //
    QPainterPath path;
    path.addPolygon(QPolygonF(points));

    setPath(path);
}