Пример #1
0
void
OSCItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{	
	if (doPan_)
	{

		QPointF newPos = event->scenePos();
		path_->translate(newPos-lastPos_);
		lastPos_ = newPos;
		setPath(*path_);

		QVector2D vec;

		RSystemElementRoad * nearestRoad = oscEditor_->findClosestRoad( newPos, s_, t_, vec);
		if (!nearestRoad)
		{
			nearestRoad = road_;
		}
		if (nearestRoad != closestRoad_)
		{
			RoadItem *nearestRoadItem = roadSystemItem_->getRoadItem(nearestRoad->getID());
			nearestRoadItem->setHighlighting(true);
			setZValue(nearestRoadItem->zValue() + 1);
			roadSystemItem_->getRoadItem(closestRoad_->getID())->setHighlighting(false);
			closestRoad_ = nearestRoad;
		}

		GraphElement::mouseMoveEvent(event);
	}
}
Пример #2
0
void
BridgeItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{	
	if (doPan_)
	{

		QPointF newPos = event->scenePos();
		path_->translate(newPos - lastPos_);
		lastPos_ = newPos;
		setPath(*path_);

		QPointF to = road_->getGlobalPoint(bridge_->getSStart()) + lastPos_ - pressPos_;

		double s;
		QVector2D vec;
		double dist;

		RSystemElementRoad * nearestRoad = signalEditor_->findClosestRoad( to, s, dist, vec);
		if (!nearestRoad)
		{
			nearestRoad = road_;
		}
		if (nearestRoad != closestRoad_)
		{
			RoadItem *nearestRoadItem = roadSystemItem_->getRoadItem(nearestRoad->getID());
			nearestRoadItem->setHighlighting(true);
			setZValue(nearestRoadItem->zValue() + 1);
			roadSystemItem_->getRoadItem(closestRoad_->getID())->setHighlighting(false);
			closestRoad_ = nearestRoad;
		}

		GraphElement::mouseMoveEvent(event);
	}
}
Пример #3
0
void
SignalHandle::updateTransform()
{
    bool tmp = moveItem_;
    moveItem_ = false; // set false so itemChange doesn't interrupt
    RSystemElementRoad *road = parentSignalRoadItem_->getRoad();
    setPos(road->getGlobalPoint(0.0));
    setRotation(road->getGlobalHeading(0.0));
    moveItem_ = tmp; // reset
}
Пример #4
0
/*! \brief Handles the item's position changes.
*/
QVariant
SignalHandle::itemChange(GraphicsItemChange change, const QVariant &value)
{
    // NOTE: position is relative to parent!!! //
    //

    // Mode 1 //
    //
    if (parentSignalRoadItem_)
    {
        if (change == QGraphicsItem::ItemPositionChange)
        {
            if (moveItem_)
            {
                RSystemElementRoad *road = parentSignalRoadItem_->getRoad();
                double s = road->getSFromGlobalPoint(value.toPointF(), -100.0, road->getLength());
                //				return parentSectionItem_->getRoadSection()->getParentRoad()->getGlobalPoint(s, 0.0);

                /*				MoveRoadSectionCommand * command = new MoveRoadSectionCommand(roadSection, s, parentSectionItem_->getRoadSectionType());
				if(command->isValid())
				{
					roadSection->getUndoStack()->push(command);
				}
				else
				{
					delete command;
				}*/

                return pos(); // no translation
            }
            else
            {
            }
        }
    }

    // Mode 2 //
    //
    //	else
    //	{
    //
    //	}

    return QGraphicsItem::itemChange(change, value);
}
Пример #5
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
}
Пример #6
0
void
ObjectSettings::onEditingFinished()
{
    if (valueChanged_)
    {
        QString filename = ui->nameBox->text();
        QString newId = object_->getId();
        RSystemElementRoad * road = object_->getParentRoad();
        if (filename != object_->getName())
        {
            QStringList parts = object_->getId().split("_");

            if (parts.size() > 2)
            {
                newId = QString("%1_%2_%3").arg(parts.at(0)).arg(parts.at(1)).arg(filename); 
            }
            else
            {
                newId = road->getRoadSystem()->getUniqueId(object_->getId(), filename);
            }
        }

        double repeatLength = ui->repeatLengthSpinBox->value();
        if (repeatLength > road->getLength() - ui->repeatSSpinBox->value())
        {
            repeatLength = road->getLength() - ui->repeatSSpinBox->value();
        }

        SetObjectPropertiesCommand *command = new SetObjectPropertiesCommand(object_, newId, filename, ui->typeBox->text(), ui->tSpinBox->value(), ui->zOffsetSpinBox->value(),
            ui->validLengthSpinBox->value(), (Object::ObjectOrientation)ui->orientationComboBox->currentIndex(), ui->lengthSpinBox->value(), ui->widthSpinBox->value(), ui->radiusSpinBox->value(), ui->heightSpinBox->value(), ui->hdgSpinBox->value(),
            ui->pitchSpinBox->value(), ui->rollSpinBox->value(), ui->poleCheckBox->isChecked(), ui->repeatSSpinBox->value(), repeatLength, ui->repeatDistanceSpinBox->value(), ui->textureLineEdit->text());
        getProjectSettings()->executeCommand(command);

        valueChanged_ = false;
        QWidget * focusWidget = QApplication::focusWidget();
        if (focusWidget)
        {
            focusWidget->clearFocus();
        }
    }
}
Пример #7
0
void
SignalHandle::updatePos(SignalRoadItem *signalRoadItem, const QPointF &position, double sStartHint, double sEndHint)
{
    RSystemElementRoad *road = signalRoadItem->getRoad();

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

    // Set Item Pose //
    //
    setPos(road->getGlobalPoint(s, 0.0));
    setRotation(road->getGlobalHeading(s));

    // Line that spans the whole road //
    //
    QPainterPath path;
    path.moveTo(0.0, road->getMinWidth(s));
    path.lineTo(0.0, road->getMaxWidth(s));
    path.addPath(*pathTemplate_);
    setPath(path);
}
Пример #8
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);
}