QPointF RelationItem::calcEndPoint(const Uid &end, const QPointF &otherEndPos, int nearestIntermediatePointIndex) { QGraphicsItem *endItem = m_diagramSceneModel->graphicsItem(end); QMT_CHECK(endItem); IIntersectionable *endObjectItem = dynamic_cast<IIntersectionable *>(endItem); QPointF endPos; if (endObjectItem) { DObject *endObject = m_diagramSceneModel->diagramController()->findElement<DObject>(end, m_diagramSceneModel->diagram()); QMT_CHECK(endObject); bool preferAxis = false; QPointF otherPos; if (nearestIntermediatePointIndex >= 0 && nearestIntermediatePointIndex < m_relation->intermediatePoints().size()) { otherPos = m_relation->intermediatePoints().at(nearestIntermediatePointIndex).pos(); preferAxis = true; } else { otherPos = otherEndPos; } bool ok = false; QLineF directLine(endObject->pos(), otherPos); if (preferAxis) { { QPointF axisDirection = GeometryUtilities::calcPrimaryAxisDirection(directLine); QLineF axis(otherPos, otherPos + axisDirection); QPointF projection = GeometryUtilities::calcProjection(axis, endObject->pos()); QLineF projectedLine(projection, otherPos); ok = endObjectItem->intersectShapeWithLine(projectedLine, &endPos); } if (!ok) { QPointF axisDirection = GeometryUtilities::calcSecondaryAxisDirection(directLine); QLineF axis(otherPos, otherPos + axisDirection); QPointF projection = GeometryUtilities::calcProjection(axis, endObject->pos()); QLineF projectedLine(projection, otherPos); ok = endObjectItem->intersectShapeWithLine(projectedLine, &endPos); } } if (!ok) { ok = endObjectItem->intersectShapeWithLine(directLine, &endPos); } if (!ok) { endPos = endItem->pos(); } } else { endPos = endItem->pos(); } return endPos; }
QPointF RelationItem::calcEndPoint(const Uid &end, const Uid &otherEnd, int nearestIntermediatePointIndex) { QPointF otherEndPos; if (nearestIntermediatePointIndex >= 0 && nearestIntermediatePointIndex < m_relation->intermediatePoints().size()) { // otherEndPos will not be used } else { DObject *endOtherObject = m_diagramSceneModel->diagramController()->findElement<DObject>(otherEnd, m_diagramSceneModel->diagram()); QMT_CHECK(endOtherObject); otherEndPos = endOtherObject->pos(); } return calcEndPoint(end, otherEndPos, nearestIntermediatePointIndex); }