/** * \return true if this leader can have an arrow head (i.e. first * segment is >= DIMASZ * DIMSCALE * 2. */ bool RLeaderData::canHaveArrowHead() const { if (countSegments()==0) { return false; } QSharedPointer<RShape> firstSegment = getSegmentAt(0); if (firstSegment.isNull()) { return false; } if (firstSegment->getLength() < getDimasz() * 2) { return false; } return true; }
QList<QSharedPointer<RShape> > RDimensionData::getArrow( const RVector& position, double direction) const { QList<QSharedPointer<RShape> > ret; double arrowSize = getDimasz(); // architecture tick: if (useArchTick()) { RVector p1(arrowSize/2, arrowSize/2); RLine line(p1, -p1); line.rotate(direction, RVector(0,0)); line.move(position); ret.append(QSharedPointer<RLine>(new RLine(line))); } // standard arrow: else { RTriangle arrow = RTriangle::createArrow(position, direction, arrowSize); ret.append(QSharedPointer<RTriangle>(new RTriangle(arrow))); } return ret; }
/** * Creates a dimensioning line (line with one, two or no arrows). */ QList<QSharedPointer<RShape> > RDimensionData::getDimensionLineShapes( const RVector& p1, const RVector& p2, bool arrow1, bool arrow2) const { QList<QSharedPointer<RShape> > ret; // text height (DIMTXT) double dimtxt = getDimtxt(); // text distance to line (DIMGAP) double dimgap = getDimgap(); // length of dimension line: dimLineLength = p1.getDistanceTo(p2); // do we have to put the arrows outside of the line? bool outsideArrows = (dimLineLength < getDimasz()*2.5); // arrow angles: double arrowAngle1, arrowAngle2; // Create dimension line: RLine dimensionLine(p1, p2); if (outsideArrows==false) { arrowAngle1 = dimensionLine.getDirection2(); arrowAngle2 = RMath::getNormalizedAngle(arrowAngle1+M_PI); } else { arrowAngle1 = dimensionLine.getDirection1(); arrowAngle2 = RMath::getNormalizedAngle(arrowAngle1+M_PI); // extend dimension line outside arrows RVector dir; dir.setPolar(getDimasz()*2, arrowAngle2); dimensionLine.setStartPoint(p1 + dir); dimensionLine.setEndPoint(p2 - dir); } ret.append(QSharedPointer<RShape>(new RLine(dimensionLine))); if (arrow1) { QList<QSharedPointer<RShape> > arrow = getArrow(p1, arrowAngle1); ret.append(arrow); } if (arrow2) { QList<QSharedPointer<RShape> > arrow = getArrow(p2, arrowAngle2); ret.append(arrow); } double dimAngle1 = dimensionLine.getDirection1(); bool corrected=false; defaultAngle = RMath::makeAngleReadable(dimAngle1, true, &corrected); if (autoTextPos) { RVector newTextPos = dimensionLine.getMiddlePoint(); RVector distV; // rotate text so it's readable from the bottom or right (ISO) // quadrant 1 & 4 if (corrected) { distV.setPolar(dimgap + dimtxt/2.0, dimAngle1-M_PI/2.0); } else { distV.setPolar(dimgap + dimtxt/2.0, dimAngle1+M_PI/2.0); } // move text away from dimension line: newTextPos+=distV; textPositionCenter = newTextPos; } return ret; }
QList<QSharedPointer<RShape> > RDimAngularData::getShapes(const RBox& queryBox, bool ignoreComplex, bool segment) const { Q_UNUSED(queryBox) Q_UNUSED(ignoreComplex) Q_UNUSED(segment) QSharedPointer<RBlockReferenceEntity> dimBlockReference = getDimensionBlockReference(); if (!dimBlockReference.isNull()) { return dimBlockReference->getShapes(queryBox, ignoreComplex); } QList<QSharedPointer<RShape> > ret; double dimexo = getDimexo(); double dimexe = getDimexe(); double dimtxt = getDimtxt(); double dimgap = getDimgap(); double dimasz = getDimasz(); // find out center: RVector center = getCenter(); if (!center.isValid()) { return ret; } double ang1 = 0.0; double ang2 = 0.0; bool reversed = false; RVector p1; RVector p2; getAngles(ang1, ang2, reversed, p1, p2); double rad = dimArcPosition.getDistanceTo(center); RLine line; RVector dir; double len; double dist; // 1st extension line: dist = center.getDistanceTo2D(p1); len = rad - dist + dimexe; dir.setPolar(1.0, ang1); line = RLine(center + dir*dist + dir*dimexo, center + dir*dist + dir*len); ret.append(QSharedPointer<RShape>(new RLine(line))); // 2nd extension line: dist = center.getDistanceTo2D(p2); len = rad - dist + dimexe; dir.setPolar(1.0, ang2); line = RLine(center + dir*dist + dir*dimexo, center + dir*dist + dir*len); ret.append(QSharedPointer<RShape>(new RLine(line))); // Create dimension line (arc): RArc arc(center, rad, ang1, ang2, reversed); ret.append(QSharedPointer<RShape>(new RArc(arc))); // length of dimension arc: double distance = arc.getLength(); // do we have to put the arrows outside of the arc? bool outsideArrows = (distance<dimasz*2); // arrow angles: double arrowAngle1, arrowAngle2; double arrowAng; if (rad>1.0e-6) { arrowAng = getDimasz() / rad; } else { arrowAng = 0.0; } if (outsideArrows) { arrowAngle1 = arc.getDirection1(); arrowAngle2 = arc.getDirection2(); } else { RVector v1, v2; if (!arc.isReversed()) { v1.setPolar(rad, arc.getStartAngle()+arrowAng); } else { v1.setPolar(rad, arc.getStartAngle()-arrowAng); } v1+=arc.getCenter(); arrowAngle1 = arc.getStartPoint().getAngleTo(v1); if (!arc.isReversed()) { v2.setPolar(rad, arc.getEndAngle()-arrowAng); } else { v2.setPolar(rad, arc.getEndAngle()+arrowAng); } v2+=arc.getCenter(); arrowAngle2 = arc.getEndPoint().getAngleTo(v2); arrowAngle1 = arrowAngle1+M_PI; arrowAngle2 = arrowAngle2+M_PI; } // Arrows: //RTriangle arrow = RTriangle::createArrow(arc.getStartPoint(), arrowAngle1, dimasz); QList<QSharedPointer<RShape> > arrow = getArrow(arc.getStartPoint(), arrowAngle1); ret.append(arrow); //arrow = RTriangle::createArrow(arc.getEndPoint(), arrowAngle2, dimasz); arrow = getArrow(arc.getEndPoint(), arrowAngle2); ret.append(arrow); //ret.append(QSharedPointer<RShape>(new RTriangle(arrow))); //RVector oldMot = textPosition; //textPosition = RVector(0,0); //defaultAngle = 0.0; //dimLineLength = RNANDOUBLE; //getTextData(); //textPosition = oldMot; RVector textPos = arc.getMiddlePoint(); double dimAngle1 = textPos.getAngleTo(arc.getCenter())-M_PI/2.0; if (!autoTextPos) { dimAngle1 = textPositionCenter.getAngleTo(arc.getCenter())-M_PI/2.0; } RVector distV; double textAngle; // rotate text so it's readable from the bottom or right (ISO) // quadrant 1 & 4 if (dimAngle1>M_PI/2.0*3.0+0.001 || dimAngle1<M_PI/2.0+0.001) { distV.setPolar(dimgap + dimtxt/2, dimAngle1+M_PI/2.0); textAngle = dimAngle1; } // quadrant 2 & 3 else { distV.setPolar(dimgap + dimtxt/2, dimAngle1-M_PI/2.0); textAngle = dimAngle1+M_PI; } if (!autoTextPos) { textPos = textPositionCenter; } else { // move text away from dimension line: textPos+=distV; textPositionCenter = textPos; } defaultAngle = textAngle; //getTextData(); //textData.rotate(textAngle, RVector(0,0)); //textData.move(textPos); return ret; }