Ejemplo n.º 1
0
/**
  * Return a number of snap points, grid will always return 1
  *
  */
std::vector<lc::EntityCoordinate> Grid::snapPoints(const lc::geo::Coordinate& coord,  const lc::SimpleSnapConstrain & constrain, double minDistanceToSnap, int maxNumberOfSnapPoints) const {
    std::vector<lc::EntityCoordinate> points;

    if (constrain.constrain() & lc::SimpleSnapConstrain::LOGICAL) {

        double mx = coord.x() * 1.0 * (1/_convUnit);
        double my = coord.y() * 1.0 * (1/_convUnit);
        double gs = this->_lastGridSize * 1.0 * (1/_convUnit);


        double x, y;

        if (mx < 0.0) {
            x = (mx - gs / 2 * (1/_convUnit)) - fmod(mx - gs / 2 * (1/_convUnit), -gs);
        } else {
            x = (mx + gs / 2 * (1/_convUnit)) - fmod(mx + gs / 2 * (1/_convUnit), gs);
        }

        if (my < 0.0) {
            y = (my - gs / 2 * (1/_convUnit)) - fmod(my - gs / 2 * (1/_convUnit), -gs);
        } else {
            y = (my + gs / 2 * (1/_convUnit)) - fmod(my + gs / 2 * (1/_convUnit), gs);
        }

        points.push_back(lc::EntityCoordinate(lc::geo::Coordinate(x, y), 0));
    }

    return points;
}
Ejemplo n.º 2
0
/**
  * Return a number of snap points, grid will always return 1
  *
  */
std::vector<lc::EntityCoordinate> MetricGrid::snapPoints(const lc::geo::Coordinate& coord, double minDistanceToSnap, int maxNumberOfSnapPoints) const {

    double mx = coord.x() * 1.0;
    double my = coord.y() * 1.0;
    double gs = this->_lastGridSize * 1.0;


    double x, y;

    if (mx < 0.0) {
        x = (mx - gs / 2) - fmod(mx - gs / 2, -gs);
    } else {
        x = (mx + gs / 2) - fmod(mx + gs / 2, gs);
    }

    if (my < 0.0) {
        y = (my - gs / 2) - fmod(my - gs / 2, -gs);
    } else {
        y = (my + gs / 2) - fmod(my + gs / 2, gs);
    }

    std::vector<lc::EntityCoordinate> points;
    points.push_back(lc::EntityCoordinate(lc::geo::Coordinate(x, y), (lc::geo::Coordinate(x, y) - coord).magnitude(), 0));
    return points;
}
Ejemplo n.º 3
0
QList<lc::EntityDistance> SelectionManagerImpl::getEntitiesNearCoordinate(const lc::geo::Coordinate& point, double distance) const {

    // This routine gives us a rought estimate of all items around the point
    // this is done by checking the bounding rect. It's also fast because it uses the BSD tree from the scene
    QList<QGraphicsItem*> items = _view->scene()->items(
                                      point.x() - distance,
                                      point.y() - distance,
                                      distance * 2.0,
                                      distance * 2.0,
                                      Qt::IntersectsItemBoundingRect,
                                      Qt::AscendingOrder);




    // Now calculate for each entity if we are near the entities path
    QList<lc::EntityDistance> entities;

    for (int i = 0; i < items.count(); i++) {
        LCGraphicsItem* item = dynamic_cast<LCGraphicsItem*>(items.at(i));

        // If item == NULL then this item was not  a type of LCGraphicsItem, so no bother to test it further
        if (item != NULL) {
            shared_ptr<const lc::Snapable> entity = dynamic_pointer_cast<const lc::Snapable>(item->entity());

            if (entity != NULL) { // Not all entities might be snapable, so we only test if this is possible.
                lc::geo::Coordinate eCoordinate = entity->nearestPointOnPath(point);
                lc::geo::Coordinate nearestCoord = eCoordinate - point;

                double cDistance = nearestCoord.magnitude();
                if (cDistance < distance) {
                    entities.append(lc::EntityDistance(item->entity(), cDistance));
                }
            }
        }
    }

    return entities;
}
Ejemplo n.º 4
0
QDebug operator << (QDebug dbg, const lc::geo::Coordinate& c) {
    dbg.nospace() << "(" << c.x() << "," << c.y() << "," << c.z() << ")";
    return dbg.space();
}