Example #1
0
void RPolylineEntity::setShape(const RPolyline& l) {
    data.setVertices(l.getVertices());
    data.setBulges(l.getBulges());
    data.setClosed(l.isClosed());
    data.setStartWidths(l.getStartWidths());
    data.setEndWidths(l.getEndWidths());
}
Example #2
0
RPolyline RPasteOperation::getBoundary(double unitFactor) {
    RBox box = sourceDocument.getBoundingBox();
    RPolyline polyline = box.getPolyline2d();
    polyline.scale(scale * unitFactor);
    polyline.rotate(rotation);
    polyline.move(offset);
    return polyline;
}
Example #3
0
bool RPolyline::simplify(double angleTolerance) {
    bool ret = false;
    RPolyline newPolyline;
    //ret.appendVertex(getStartPoint());

    RS::EntityType type = RS::EntityUnknown;
    double angle = RMAXDOUBLE;
    //double radius = 0;
    //RVector center;
    //RVector vertex;

    for (int i=0; i<countSegments(); i++) {
        QSharedPointer<RShape> seg = getSegmentAt(i);

        QSharedPointer<RLine> line = seg.dynamicCast<RLine>();
        if (!line.isNull()) {
            double angleDiff = qAbs(RMath::getAngleDifference180(line->getAngle(), angle));
//            qDebug() << "angle diff: " << angleDiff;
//            qDebug() << "tol: " << angleTolerance;
            if (type==RS::EntityLine && angleDiff<angleTolerance) {

                //vertex = line->getEndPoint();
                ret = true;
            }
            else {
                //qDebug() << "start: " << line->getStartPoint();
                newPolyline.appendVertex(line->getStartPoint());
                angle = line->getAngle();
                type = RS::EntityLine;
            }
        }

        QSharedPointer<RArc> arc = seg.dynamicCast<RArc>();
        if (!arc.isNull()) {
            // TODO
            newPolyline.appendVertex(arc->getStartPoint(), arc->getBulge());
        }
    }

    if (isClosed()) {
        newPolyline.setClosed(true);
    }
    else {
        newPolyline.appendVertex(getEndPoint());
    }

//    qDebug() << "old polyline: " << *this;
//    qDebug() << "new polyline: " << newPolyline;

    //*this = newPolyline;

    //clear();
    vertices = newPolyline.vertices;
    bulges = newPolyline.bulges;
    closed = newPolyline.closed;

    return ret;
}
Example #4
0
/**
 * Exports an ellipse with the current attributes.
 * \todo switch from line based interpolation to arcs.
 */
void RExporter::exportEllipse(const REllipse& ellipse, double offset) {
    if (ellipse.getMajorRadius()<RS::PointTolerance ||
            ellipse.getMinorRadius()<RS::PointTolerance) {
        return;
    }

    RPolyline polyline;

    RVector cp = ellipse.getCenter();
    double radius1 = ellipse.getMajorRadius();
    double radius2 = ellipse.getMinorRadius();
    double angle = ellipse.getAngle();
    double a1 = ellipse.getStartParam();
    double a2 = ellipse.getEndParam();
    bool reversed = ellipse.isReversed();

    double aStep;         // Angle Step (rad)
    double a;             // Current Angle (rad)

    aStep=0.05;
    RVector vp;
    RVector vc(cp.x, cp.y);
    vp.set(cp.x+cos(a1)*radius1,
           cp.y+sin(a1)*radius2);
    vp.rotate(angle, vc);
    polyline.appendVertex(vp);
    if (!reversed) {
        // Arc Counterclockwise:
        if (a1>a2-RS::AngleTolerance) {
            a2+=2*M_PI;
        }
        for(a=a1+aStep; a<=a2; a+=aStep) {
            vp.set(cp.x+cos(a)*radius1,
                   cp.y+sin(a)*radius2);
            vp.rotate(angle, vc);
            polyline.appendVertex(vp);
        }
    } else {
        // Arc Clockwise:
        if (a1<a2+RS::AngleTolerance) {
            a2-=2*M_PI;
        }
        for(a=a1-aStep; a>=a2; a-=aStep) {
            vp.set(cp.x+cos(a)*radius1,
                   cp.y+sin(a)*radius2);
            vp.rotate(angle, vc);
            polyline.appendVertex(vp);
        }
    }
    vp.set(cp.x+cos(a2)*radius1,
           cp.y+sin(a2)*radius2);
    vp.rotate(angle, vc);
    polyline.appendVertex(vp);

    exportPolyline(polyline, offset);
}
Example #5
0
bool RPolyline::reverse() {
    RPolyline nPolyline;
    QList<QSharedPointer<RShape> > segments = getExploded();
    for (int i=segments.count()-1; i>=0; i--) {
        QSharedPointer<RShape> seg = segments.at(i);
        QSharedPointer<RDirected> directed = seg.dynamicCast<RDirected>();
        directed->reverse();
        nPolyline.appendShape(*seg);
    }
    nPolyline.setClosed(closed);
    *this = nPolyline;
    return true;
}
Example #6
0
void RSolidEntity::exportEntity(RExporter& e, bool preview, bool forceSelected) const {
    Q_UNUSED(preview);
    Q_UNUSED(forceSelected);

    // note that order of fourth and third vertex is swapped:
    RPolyline pl;
    pl.appendVertex(data.getVertexAt(0));
    pl.appendVertex(data.getVertexAt(1));
    if (data.countVertices()>3) {
        pl.appendVertex(data.getVertexAt(3));
    }
    pl.appendVertex(data.getVertexAt(2));
    pl.setClosed(true);

    e.exportPolyline(pl);
}
Example #7
0
RPolyline RSpline::toPolyline(int segments) const {
    RPolyline ret;

    QList<QSharedPointer<RShape> > lineSegments = getExploded(segments);
    for (int k=0; k<lineSegments.size(); k++) {
        QSharedPointer<RDirected> dir = lineSegments[k].dynamicCast<RDirected>();
        if (dir.isNull()) {
            continue;
        }
        if (k==0) {
            ret.appendVertex(dir->getStartPoint());
        }
        ret.appendVertex(dir->getEndPoint());
    }
    return ret;
}
Example #8
0
bool RArc::stretch(const RPolyline& area, const RVector& offset) {
    bool ret = false;

    if (area.contains(getStartPoint()) && area.contains(getEndPoint())) {
        return move(offset);
    }

    if (area.contains(getStartPoint())) {
        moveStartPoint(getStartPoint() + offset);
        ret = true;
    }
    else if (area.contains(getEndPoint())) {
        moveEndPoint(getEndPoint() + offset);
        ret = true;
    }

    return ret;
}
Example #9
0
bool RRay::stretch(const RPolyline& area, const RVector& offset) {
    bool ret = false;

    if (area.contains(basePoint)) {
        basePoint += offset;
        ret = true;
    }

    return ret;
}
Example #10
0
bool RPolyline::reverse() {
    RPolyline nPolyline;
    QList<QSharedPointer<RShape> > segments = getExploded();

    // skip last segment if polyline is closed and add flag instead:
    int iLast = segments.count()-1;
    if (isClosed()) {
        iLast--;
    }

    for (int i=iLast; i>=0; i--) {
        QSharedPointer<RShape> seg = segments.at(i);
        QSharedPointer<RDirected> directed = seg.dynamicCast<RDirected>();
        directed->reverse();
        nPolyline.appendShape(*seg);
    }
    nPolyline.setClosed(closed);
    *this = nPolyline;
    return true;
}
Example #11
0
RPolyline RSpline::toPolyline(int segments) const {
    RPolyline ret;

    QList<QSharedPointer<RShape> > lineSegments = getExplodedBezier(segments);
    for (int k=0; k<lineSegments.size(); k++) {
        QSharedPointer<RShape> shape = lineSegments[k];
        if (shape.isNull() || !shape->isDirected()) {
            continue;
        }
        if (k==0) {
            ret.appendVertex(shape->getStartPoint());
        }
        ret.appendVertex(shape->getEndPoint());
    }
    if (isClosed()) {
        ret.setClosed(true);
    }

    return ret;
}
Example #12
0
RPolyline RArc::approximateWithLines(double segmentLength) {
    RPolyline polyline;

    // avoid a segment length of 0:
    if (segmentLength<1.0e-6) {
        segmentLength = 1.0e-6;
    }

    double a1 = getStartAngle();
    double a2 = getEndAngle();
    double aStep = segmentLength / radius;
    double a, cix, ciy;

    polyline.appendVertex(getStartPoint());
    if (!reversed) {
        // Arc Counterclockwise:
        if (a1>a2-1.0e-10) {
            a2+=2*M_PI;
        }
        for (a=a1+aStep; a<=a2; a+=aStep) {
            cix = center.x + cos(a) * radius;
            ciy = center.y + sin(a) * radius;
            polyline.appendVertex(RVector(cix, ciy));
        }
    } else {
        // Arc Clockwise:
        if (a1<a2+1.0e-10) {
            a2-=2*M_PI;
        }
        for (a=a1-aStep; a>=a2; a-=aStep) {
            cix = center.x + cos(a) * radius;
            ciy = center.y + sin(a) * radius;
            polyline.appendVertex(RVector(cix, ciy));
        }
    }
    polyline.appendVertex(getEndPoint());

    return polyline;
}
Example #13
0
/**
 * \param polylineGen True: use pattern along whole polyline, False: pattern per segment.
 */
void RExporter::exportPolyline(const RPolyline& polyline, bool polylineGen, double offset) {
    RLinetypePattern p = getLinetypePattern();

    bool continuous = false;
    if (getEntity() == NULL || !p.isValid() || p.getNumDashes() <= 1 || draftMode || screenBasedLinetypes || twoColorSelectedMode) {
        continuous = true;
    }

    if (!continuous) {
        p.scale(getLineTypePatternScale(p));

        if (RMath::isNaN(offset)) {
            double length = polyline.getLength();
            offset = p.getPatternOffset(length);
        }
    }

    if (polylineGen) {
        // pattern along whole polyline:
        exportExplodable(polyline, offset);
    }
    else {
        // pattern for each individual segment:
        for (int i=0; i<polyline.countSegments(); i++) {
            QSharedPointer<RShape> shape = polyline.getSegmentAt(i);
            QSharedPointer<RLine> line = shape.dynamicCast<RLine>();
            if (!line.isNull()) {
                RExporter::exportLine(*line);
            }
            QSharedPointer<RArc> arc = shape.dynamicCast<RArc>();
            if (!arc.isNull()) {
                RExporter::exportArc(*arc);
            }
        }
    }
}
Example #14
0
void RGraphicsSceneQt::exportPolylineFill(const RPolyline& polyline) {
    if (currentBrush!=Qt::NoBrush) {
        bool created = beginPath();

        // TODO: support arc segments for filling:
        QPolygonF qpolygon;
        QList<RVector> points = polyline.getVertices();
        for (int i = 0; i < points.size(); ++i) {
            RVector v = points.at(i);
            qpolygon << QPointF(v.x, v.y);
        }
        currentPainterPath.setBrush(currentBrush);
        currentPainterPath.addPolygon(qpolygon);

        if (created) {
            endPath();
        }
    }
}
Example #15
0
void RExporter::exportPolyline(const RPolyline& polyline, double offset) {
    RLinetypePattern p = getLinetypePattern();

    bool continuous = false;
    if (getEntity() == NULL || !p.isValid() || p.getNumDashes() == 1 || draftMode || screenBasedLinetypes) {
        continuous = true;
    }

    if (!continuous) {
        p.scale(getPatternFactor());

        if (RMath::isNaN(offset)) {
            double length = polyline.getLength();
            offset = getPatternOffset(length, p);
        }
    }

    exportExplodable(polyline, offset);
}
Example #16
0
RPolyline RPasteOperation::getBoundary(double unitFactor) {
    RBox box = sourceDocument.getBoundingBox();
    RPolyline polyline = box.getPolyline2d();
    if (flipHorizontal) {
        polyline.flipHorizontal();
    }
    if (flipVertical) {
        polyline.flipVertical();
    }
    polyline.scale(scale * unitFactor);
    polyline.rotate(getRotation());
    polyline.move(getOffset());
    return polyline;
}
Example #17
0
void REcmaHelper::fromScriptValue(QScriptEngine* engine, QScriptValue scriptValue, QList<QSharedPointer<RShape> >& cppValue) {
    QVariantList variantList = engine->fromScriptValue<QVariantList>(scriptValue);
    for (int i = 0; i < variantList.size(); ++i) {
        QVariant v = variantList.at(i);
        QSharedPointer<RShape> pShape = v.value<QSharedPointer<RShape> >();
        if (!pShape.isNull()) {
            cppValue.append(pShape);
        }
        else {
            RShape* shape = v.value<RShape*>();
            if (shape!=NULL) {
                QSharedPointer<RShape> pShape(shape->clone());
                cppValue.append(pShape);
            }

            else if (v.canConvert<RArc>()) {
                RArc obj = v.value<RArc>();
                QSharedPointer<RArc> p(obj.clone());
                cppValue.append(p);
            }

            else if (v.canConvert<RCircle>()) {
                RCircle obj = v.value<RCircle>();
                QSharedPointer<RCircle> p(obj.clone());
                cppValue.append(p);
            }

            else if (v.canConvert<RLine>()) {
                RLine obj = v.value<RLine>();
                QSharedPointer<RLine> p(obj.clone());
                cppValue.append(p);
            }

            else if (v.canConvert<RPoint>()) {
                RPoint obj = v.value<RPoint>();
                QSharedPointer<RPoint> p(obj.clone());
                cppValue.append(p);
            }

            else if (v.canConvert<RPolyline>()) {
                RPolyline obj = v.value<RPolyline>();
                QSharedPointer<RPolyline> p(obj.clone());
                cppValue.append(p);
            }

            else if (v.canConvert<RSpline>()) {
                RSpline obj = v.value<RSpline>();
                QSharedPointer<RSpline> p(obj.clone());
                cppValue.append(p);
            }

            else if (v.canConvert<RTextLabel>()) {
                RTextLabel obj = v.value<RTextLabel>();
                QSharedPointer<RTextLabel> p(obj.clone());
                cppValue.append(p);
            }

            else if (v.canConvert<RTriangle>()) {
                RTriangle obj = v.value<RTriangle>();
                QSharedPointer<RTriangle> p(obj.clone());
                cppValue.append(p);
            }
        }
    }
}
Example #18
0
/**
 * Moves this vector by offset if it is inside the given area.
 */
RVector RVector::stretch(const RPolyline& area, const RVector& offset) {
    if (area.contains(*this)) {
        return move(offset);
    }
    return *this;
}
Example #19
0
RS::Side RSpline::getSideOfPoint(const RVector& point) const {
    RPolyline pl = toPolyline(16);
    return pl.getSideOfPoint(point);
}