Example #1
0
/**
 * @return Center of the measured dimension.
 */
RS_Vector RS_DimAngular::getCenter() {
    RS_ConstructionLine l1(NULL, RS_ConstructionLineData(edata.definitionPoint1,
                           edata.definitionPoint2));
    RS_ConstructionLine l2(NULL, RS_ConstructionLineData(edata.definitionPoint3,
                           data.definitionPoint));
    RS_VectorSolutions vs = RS_Information::getIntersection(&l1, &l2, false);

    return vs.get(0);
}
Example #2
0
/**
 * Creates an entity parallel to the given entity e through the given
 * 'coord'.
 *
 * @param coord Coordinate to define the distance / side (typically a
 *              mouse coordinate).
 * @param number Number of parallels.
 * @param e Original entity.
 *
 * @return Pointer to the first created parallel or nullptr if no
 *    parallel has been created.
 */
RS_Entity* RS_Creation::createParallelThrough(const RS_Vector& coord,
                                              int number,
                                              RS_Entity* e) {
	if (!e) {
		return nullptr;
    }

    double dist;

    if (e->rtti()==RS2::EntityLine) {
        RS_Line* l = (RS_Line*)e;
		RS_ConstructionLine cl(nullptr,
                               RS_ConstructionLineData(l->getStartpoint(),
                                                       l->getEndpoint()));
        dist = cl.getDistanceToPoint(coord);
    } else {
        dist = e->getDistanceToPoint(coord);
    }

    if (dist<RS_MAXDOUBLE) {
        return createParallel(coord, dist, number, e);
    } else {
		return nullptr;
    }
}
Example #3
0
/**
 * @return Automatically created label for the default
 * measurement of this dimension.
 */
QString RS_DimLinear::getMeasuredLabel() {
    // direction of dimension line
    RS_Vector dirDim;
    dirDim.setPolar(100.0, edata.angle);

    // construction line for dimension line
    RS_ConstructionLine dimLine(NULL,
                                RS_ConstructionLineData(data.definitionPoint,
                                                        data.definitionPoint + dirDim));

    RS_Vector dimP1 = dimLine.getNearestPointOnEntity(edata.extensionPoint1);
    RS_Vector dimP2 = dimLine.getNearestPointOnEntity(edata.extensionPoint2);

    // Definitive dimension line:
    double dist = dimP1.distanceTo(dimP2);

        RS_Graphic* graphic = getGraphic();

    QString ret;
        if (graphic!=NULL) {
                ret = RS_Units::formatLinear(dist, graphic->getUnit(),
                        graphic->getLinearFormat(), graphic->getLinearPrecision());
        }
        else {
        ret = QString("%1").arg(dist);
        }

    return ret;
}
void RS_DimAligned::updateDimPoint(){
    // temporary construction line
	RS_ConstructionLine tmpLine( nullptr,
        RS_ConstructionLineData(edata.extensionPoint1, edata.extensionPoint2));

	RS_Vector tmpP1 = tmpLine.getNearestPointOnEntity(data.definitionPoint);
	data.definitionPoint += edata.extensionPoint2 - tmpP1;
}
Example #5
0
void RS_ActionDimAligned::preparePreview() {
	RS_Vector dirV = RS_Vector::polar(100.,
				  edata->extensionPoint1.angleTo(
					  edata->extensionPoint2)
				  +M_PI_2);
	RS_ConstructionLine cl(nullptr,
                           RS_ConstructionLineData(
							   edata->extensionPoint2,
							   edata->extensionPoint2+dirV));

    data->definitionPoint =
        cl.getNearestPointOnEntity(data->definitionPoint);
}
void RS_ActionDimLinear::preparePreview() {
    RS_Vector dirV;
    dirV.setPolar(100.0, edata.angle+M_PI/2.0);

    RS_ConstructionLine cl(
        NULL,
        RS_ConstructionLineData(
            edata.extensionPoint2,
            edata.extensionPoint2+dirV));

    data.definitionPoint =
        cl.getNearestPointOnEntity(data.definitionPoint);

}
Example #7
0
void RS_DimAligned::moveRef(const RS_Vector& ref, const RS_Vector& offset) {

    if (ref.distanceTo(data.definitionPoint)<1.0e-4) {
                RS_ConstructionLine l(NULL,
                        RS_ConstructionLineData(edata.extensionPoint1,
                                edata.extensionPoint2));
                double d = l.getDistanceToPoint(data.definitionPoint+offset);
                double a = edata.extensionPoint2.angleTo(data.definitionPoint);
                double ad = RS_Math::getAngleDifference(a,
                        edata.extensionPoint2.angleTo(data.definitionPoint+offset));

                if (fabs(ad)>M_PI/2.0 && fabs(ad)<3.0/2.0*M_PI) {
                        a = RS_Math::correctAngle(a+M_PI);
                }

                RS_Vector v;
                v.setPolar(d, a);
        data.definitionPoint = edata.extensionPoint2 + v;
                update(true);
    }
        else if (ref.distanceTo(data.middleOfText)<1.0e-4) {
        data.middleOfText.move(offset);
                update(false);
    }
        else if (ref.distanceTo(edata.extensionPoint1)<1.0e-4) {
                double a1 = edata.extensionPoint2.angleTo(edata.extensionPoint1);
                double a2 = edata.extensionPoint2.angleTo(edata.extensionPoint1+offset);
                double d1 = edata.extensionPoint2.distanceTo(edata.extensionPoint1);
                double d2 = edata.extensionPoint2.distanceTo(edata.extensionPoint1+offset);
                rotate(edata.extensionPoint2, a2-a1);
                if (fabs(d1)>1.0e-4) {
                        scale(edata.extensionPoint2, RS_Vector(d2/d1, d2/d1));
                }
                update(true);
    }
        else if (ref.distanceTo(edata.extensionPoint2)<1.0e-4) {
                double a1 = edata.extensionPoint1.angleTo(edata.extensionPoint2);
                double a2 = edata.extensionPoint1.angleTo(edata.extensionPoint2+offset);
                double d1 = edata.extensionPoint1.distanceTo(edata.extensionPoint2);
                double d2 = edata.extensionPoint1.distanceTo(edata.extensionPoint2+offset);
                rotate(edata.extensionPoint1, a2-a1);
                if (fabs(d1)>1.0e-4) {
                        scale(edata.extensionPoint1, RS_Vector(d2/d1, d2/d1));
                }
                update(true);
    }
}
Example #8
0
/**
 * @return Automatically created label for the default
 * measurement of this dimension.
 */
QString RS_DimLinear::getMeasuredLabel() {
    // direction of dimension line
	RS_Vector dirDim = RS_Vector::polar(100.0, edata.angle);

    // construction line for dimension line
	RS_ConstructionLine dimLine(nullptr,
								RS_ConstructionLineData(data.definitionPoint,
														data.definitionPoint + dirDim));

    RS_Vector dimP1 = dimLine.getNearestPointOnEntity(edata.extensionPoint1);
    RS_Vector dimP2 = dimLine.getNearestPointOnEntity(edata.extensionPoint2);

    // Definitive dimension line:
    double dist = dimP1.distanceTo(dimP2) * getGeneralFactor();

        RS_Graphic* graphic = getGraphic();

    QString ret;
        if (graphic) {
            int dimlunit = getGraphicVariableInt("$DIMLUNIT", 2);
            int dimdec = getGraphicVariableInt("$DIMDEC", 4);
            int dimzin = getGraphicVariableInt("$DIMZIN", 1);
            RS2::LinearFormat format = graphic->getLinearFormat(dimlunit);
            ret = RS_Units::formatLinear(dist, RS2::None, format, dimdec);
            if (format == RS2::Decimal)
                ret = stripZerosLinear(ret, dimzin);
            //verify if units are decimal and comma separator
            if (format == RS2::Decimal || format == RS2::ArchitecturalMetric){
                if (getGraphicVariableInt("$DIMDSEP", 0) == 44)
                    ret.replace(QChar('.'), QChar(','));
            }
        }
        else {
        ret = QString("%1").arg(dist);
        }

    return ret;
}
Example #9
0
/**
 * Updates the sub entities of this dimension. Called when the
 * text or the position, alignment, .. changes.
 *
 * @param autoText Automatically reposition the text label
 */
void RS_DimLinear::update(bool autoText) {

    RS_DEBUG->print("RS_DimLinear::update");

    clear();

    if (isUndone()) {
        return;
    }

    // general scale (DIMSCALE)
    double dimscale = getGeneralScale();
    // distance from entities (DIMEXO)
    double dimexo = getExtensionLineOffset()*dimscale;
    // extension line extension (DIMEXE)
    double dimexe = getExtensionLineExtension()*dimscale;

    RS_LineData ld;
    double extAngle = edata.angle + (M_PI/2.0);

    // direction of dimension line
    RS_Vector dirDim;
    dirDim.setPolar(100.0, edata.angle);
    // direction of extension lines
    RS_Vector dirExt;
    dirExt.setPolar(100.0, extAngle);

    // construction line for dimension line
    RS_ConstructionLine dimLine(
        NULL,
        RS_ConstructionLineData(data.definitionPoint,
                                data.definitionPoint + dirDim));

    RS_Vector dimP1 = dimLine.getNearestPointOnEntity(edata.extensionPoint1);
    RS_Vector dimP2 = dimLine.getNearestPointOnEntity(edata.extensionPoint2);

    // Definitive dimension line:
    updateCreateDimensionLine(dimP1, dimP2, true, true, autoText);
    /*
    ld = RS_LineData(data.definitionPoint, dimP1);
    RS_Line* dimensionLine = new RS_Line(this, ld);
       addEntity(dimensionLine);
    */
    RS_Vector vDimexo1, vDimexe1, vDimexo2, vDimexe2;
    vDimexe1.setPolar(dimexe, edata.extensionPoint1.angleTo(dimP1));
    vDimexo1.setPolar(dimexo, edata.extensionPoint1.angleTo(dimP1));

    vDimexe2.setPolar(dimexe, edata.extensionPoint2.angleTo(dimP2));
    vDimexo2.setPolar(dimexo, edata.extensionPoint2.angleTo(dimP2));

    if ((edata.extensionPoint1-dimP1).magnitude()<1e-6) {
        vDimexe1.setPolar(dimexe,
                          data.definitionPoint.angleTo(dimP1)-M_PI/2.0);
        vDimexo1.setPolar(dimexo,
                          data.definitionPoint.angleTo(dimP1)-M_PI/2.0);
    }
    if ((edata.extensionPoint2-dimP2).magnitude()<1e-6) {
        vDimexe2.setPolar(dimexe,
                          data.definitionPoint.angleTo(dimP2)-M_PI/2.0);
        vDimexo2.setPolar(dimexo,
                          data.definitionPoint.angleTo(dimP2)-M_PI/2.0);
    }

    // extension lines:
    ld = RS_LineData(edata.extensionPoint1+vDimexo1,
                     dimP1+vDimexe1);
    RS_Line* line = new RS_Line(this, ld);
    line->setPen(RS_Pen(RS2::FlagInvalid));
    line->setLayer(NULL);
    addEntity(line);
    ld = RS_LineData(edata.extensionPoint2+vDimexo2,
                     dimP2+vDimexe2);
    //data.definitionPoint+vDimexe2);
    line = new RS_Line(this, ld);
    line->setPen(RS_Pen(RS2::FlagInvalid));
    line->setLayer(NULL);
    addEntity(line);

    calculateBorders();
}
Example #10
0
/**
 * Updates the sub entities of this dimension. Called when the
 * text or the position, alignment, .. changes.
 *
 * @param autoText Automatically reposition the text label
 */
void RS_DimLinear::updateDim(bool autoText) {

    RS_DEBUG->print("RS_DimLinear::update");

    clear();

    if (isUndone()) {
        return;
    }

    // general scale (DIMSCALE)
    double dimscale = getGeneralScale();
    // distance from entities (DIMEXO)
    double dimexo = getExtensionLineOffset()*dimscale;
    // extension line extension (DIMEXE)
    double dimexe = getExtensionLineExtension()*dimscale;

    // direction of dimension line
	RS_Vector dirDim = RS_Vector::polar(100.0, edata.angle);

    // construction line for dimension line
    RS_ConstructionLine dimLine(
		nullptr,
		RS_ConstructionLineData(data.definitionPoint,
								data.definitionPoint + dirDim));

    RS_Vector dimP1 = dimLine.getNearestPointOnEntity(edata.extensionPoint1);
    RS_Vector dimP2 = dimLine.getNearestPointOnEntity(edata.extensionPoint2);

    // Definitive dimension line:
    updateCreateDimensionLine(dimP1, dimP2, true, true, autoText);
    /*
    ld = RS_LineData(data.definitionPoint, dimP1);
    RS_Line* dimensionLine = new RS_Line(this, ld);
       addEntity(dimensionLine);
    */

    double extAngle1, extAngle2;

    if ((edata.extensionPoint1-dimP1).magnitude()<1e-6) {
        if ((edata.extensionPoint2-dimP2).magnitude()<1e-6) {
            //boot extension points are in dimension line only rotate 90
			extAngle2 = edata.angle + (M_PI_2);
        } else {
            //first extension point are in dimension line use second
            extAngle2 = edata.extensionPoint2.angleTo(dimP2);
        }
            extAngle1 = extAngle2;
    } else {
        //first extension point not are in dimension line use it
        extAngle1 = edata.extensionPoint1.angleTo(dimP1);
        if ((edata.extensionPoint2-dimP2).magnitude()<1e-6)
            extAngle2 = extAngle1;
        else
            extAngle2 = edata.extensionPoint2.angleTo(dimP2);
    }

	RS_Vector vDimexe1 = RS_Vector::polar(dimexe, extAngle1);
	RS_Vector vDimexe2 = RS_Vector::polar(dimexe, extAngle2);

	RS_Vector vDimexo1, vDimexo2;
	if (getFixedLengthOn()){
        double dimfxl = getFixedLength();
        double extLength = (edata.extensionPoint1-dimP1).magnitude();
        if (extLength-dimexo > dimfxl)
            vDimexo1.setPolar(extLength - dimfxl, extAngle1);
        extLength = (edata.extensionPoint2-dimP2).magnitude();
        if (extLength-dimexo > dimfxl)
            vDimexo2.setPolar(extLength - dimfxl, extAngle2);
    } else {
        vDimexo1.setPolar(dimexo, extAngle1);
        vDimexo2.setPolar(dimexo, extAngle2);
    }

    RS_Pen pen(getExtensionLineColor(),
           getExtensionLineWidth(),
           RS2::LineByBlock);

    // extension lines:
	RS_Line* line = new RS_Line{this,
			edata.extensionPoint1+vDimexo1, dimP1+vDimexe1};
    line->setPen(pen);
//    line->setPen(RS_Pen(RS2::FlagInvalid));
	line->setLayer(nullptr);
    addEntity(line);
    //data.definitionPoint+vDimexe2);
	line = new RS_Line{this,
			edata.extensionPoint2+vDimexo2, dimP2+vDimexe2};
    line->setPen(pen);
//    line->setPen(RS_Pen(RS2::FlagInvalid));
	line->setLayer(nullptr);
    addEntity(line);

    calculateBorders();
}