Basic working HiResolution TD

This commit is contained in:
WandererFan
2016-12-04 18:52:42 -05:00
parent ddfaf61660
commit fbe97ec247
17 changed files with 516 additions and 211 deletions

View File

@@ -53,11 +53,13 @@
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/Geometry.h>
#include "Rez.h"
#include "ZVALUE.h"
#include "QGIArrow.h"
#include "QGIDimLines.h"
#include "QGIViewDimension.h"
using namespace TechDraw;
using namespace TechDrawGui;
enum SnapMode{
@@ -156,6 +158,7 @@ QGIViewDimension::QGIViewDimension() :
//centerMark = new QGICMark();
//addToGroup(centerMark);
// connecting the needed slots and signals
QObject::connect(
datumLabel, SIGNAL(dragging()),
@@ -187,12 +190,12 @@ void QGIViewDimension::setViewPartFeature(TechDraw::DrawViewDimension *obj)
setViewFeature(static_cast<TechDraw::DrawView *>(obj));
// Set the QGIGroup Properties based on the DrawView
float x = obj->X.getValue(); //(0,0)?
float y = obj->Y.getValue();
float x = Rez::guiX(obj->X.getValue());
float y = Rez::guiX(obj->Y.getValue());
datumLabel->setPosFromCenter(x, y);
m_lineWidth = obj->LineWidth.getValue();
m_lineWidth = Rez::guiX(obj->LineWidth.getValue());
updateDim();
draw();
@@ -221,7 +224,7 @@ void QGIViewDimension::updateView(bool update)
if(dim->Fontsize.isTouched() ||
dim->Font.isTouched()) {
QFont font = datumLabel->font();
font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points
font.setPointSizeF(Rez::guiX(dim->Fontsize.getValue()));
font.setFamily(QString::fromLatin1(dim->Font.getValue()));
datumLabel->setFont(font);
@@ -250,7 +253,7 @@ void QGIViewDimension::updateDim()
QString labelText = QString::fromUtf8(dim->getFormatedValue().data(),dim->getFormatedValue().size());
QFont font = datumLabel->font();
font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points
font.setPointSizeF(Rez::guiX(dim->Fontsize.getValue()));
font.setFamily(QString::fromUtf8(dim->Font.getValue()));
datumLabel->setFont(font);
@@ -272,8 +275,8 @@ void QGIViewDimension::datumLabelDragFinished()
return;
}
double x = datumLabel->X(),
y = datumLabel->Y();
double x = Rez::appX(datumLabel->X()),
y = Rez::appX(datumLabel->Y());
Gui::Command::openCommand("Drag Dimension");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f", dim->getNameInDocument(), x);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f", dim->getNameInDocument(), y);
@@ -299,7 +302,7 @@ void QGIViewDimension::draw()
return;
}
m_lineWidth = dim->LineWidth.getValue();
m_lineWidth = Rez::guiX(dim->LineWidth.getValue());
QString labelText = datumLabel->toPlainText();
Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(), 0);
@@ -327,7 +330,9 @@ void QGIViewDimension::draw()
Base::Vector2d pnt1 = gen->points.at(0);
Base::Vector2d pnt2 = gen->points.at(1);
distStart = Base::Vector3d(pnt1.x, pnt1.y, 0.);
distStart = Rez::guiX(distStart);
distEnd = Base::Vector3d(pnt2.x, pnt2.y, 0.);
distEnd = Rez::guiX(distEnd);
} else {
throw Base::Exception("QGIVD::draw - Original edge not found or is invalid type (1)");
}
@@ -345,7 +350,9 @@ void QGIViewDimension::draw()
return;
}
distStart = Base::Vector3d (v0->pnt.x, v0->pnt.y, 0.);
distStart = Rez::guiX(distStart);
distEnd = Base::Vector3d (v1->pnt.x, v1->pnt.y, 0.);
distEnd = Rez::guiX(distEnd);
} else if(dim->References2D.getValues().size() == 2 &&
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" &&
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") {
@@ -364,7 +371,9 @@ void QGIViewDimension::draw()
p1 = geom0->nearPoint(geom1);
p2 = geom1->nearPoint(geom0);
distStart = Base::Vector3d(p1.x,p1.y,0.0);
distStart = Rez::guiX(distStart);
distEnd = Base::Vector3d(p2.x,p2.y,0.0);
distEnd = Rez::guiX(distStart);
} else if ( (geom0->geomType == TechDrawGeometry::GENERIC) &&
(geom1->geomType == TechDrawGeometry::GENERIC) ){
TechDrawGeometry::Generic *gen0 = static_cast<TechDrawGeometry::Generic *>(geom0);
@@ -374,11 +383,15 @@ void QGIViewDimension::draw()
pnt1 = gen0->points.at(0);
pnt2 = gen0->points.at(1);
edge1Start = Base::Vector3d(pnt1.x, pnt1.y, 0);
edge1Start = Rez::guiX(edge1Start);
edge1End = Base::Vector3d(pnt2.x, pnt2.y, 0);
edge1End = Rez::guiX(edge1End);
pnt1 = gen1->points.at(0);
pnt2 = gen1->points.at(1);
edge2Start = Base::Vector3d(pnt1.x, pnt1.y, 0);
edge2Start = Rez::guiX(edge2Start);
edge2End = Base::Vector3d(pnt2.x, pnt2.y, 0);
edge2End = Rez::guiX(edge2End);
// figure out which end of each edge to use for drawing
Base::Vector3d lin1 = edge1End - edge1Start; //vector from edge1Start to edge2End
@@ -430,8 +443,8 @@ void QGIViewDimension::draw()
displace.ProjectToLine(pnt - edgeStart, edgeEnd - edgeStart);
Base::Vector3d ptOnLine = pnt + displace;
distStart = pnt;
distEnd = ptOnLine;
distStart = Rez::guiX(pnt);
distEnd = Rez::guiX(ptOnLine);
//need to figure out Distance? from slope of distEnd-distStart?
} else {
Base::Console().Message("TARFU - invalid references for Dimension!!");
@@ -443,7 +456,7 @@ void QGIViewDimension::draw()
// text to left of vertical dims
// text above horizontal dims
double offsetFudge = 2.0;
double textOffset = 0.75 * dim->Fontsize.getValue() + offsetFudge;
double textOffset = 0.75 * Rez::guiX(dim->Fontsize.getValue()) + offsetFudge;
Base::Vector3d dir, norm; //direction/normal vectors of distance line (not dimension Line)
if (strcmp(dimType, "Distance") == 0 ) {
dir = (distEnd-distStart);
@@ -509,7 +522,7 @@ void QGIViewDimension::draw()
Base::Vector3d fauxCenter = lblCenter + textOffset * textNorm;
Base::Vector3d vec = fauxCenter - distEnd; //endof dist line to center of dimline
float perpDistance = vec.x * norm.x + vec.y * norm.y; //dot(vec,norm) the perp distance between distance & dimension lines.
float margin = 2.f;
float margin = Rez::guiX(2.f);
float scaler = 1.;
float offset1 = (perpDistance + normproj12 < 0) ? -margin : margin;
@@ -589,8 +602,10 @@ void QGIViewDimension::draw()
double angleOption = 0.0; //put lblText angle adjustments here
datumLabel->setRotation((angle * 180 / M_PI) + angleOption);
aHead1->setStyle(QGIArrow::getPrefArrowStyle());
aHead1->draw();
aHead2->flip(true);
aHead2->setStyle(QGIArrow::getPrefArrowStyle());
aHead2->draw();
angle = atan2f(dir.y,dir.x);
float arrowAngle = angle * 180 / M_PI;
@@ -625,8 +640,9 @@ void QGIViewDimension::draw()
if( (geom->geomType == TechDrawGeometry::CIRCLE) ||
(geom->geomType == TechDrawGeometry::ARCOFCIRCLE) ) {
TechDrawGeometry::Circle *circ = static_cast<TechDrawGeometry::Circle *>(geom);
radius = circ->radius;
radius = Rez::guiX(circ->radius);
centre = Base::Vector3d (circ->center.x, circ->center.y, 0);
centre = Rez::guiX(centre);
} else {
throw Base::Exception("FVD::draw - Original edge not found or is invalid type (2)");
}
@@ -651,7 +667,7 @@ void QGIViewDimension::draw()
int w = fm.width(labelText);
//int h = fm.height();
float margin = 5.f;
float margin = Rez::guiX(5.f);
// Calculate the dimension line endpoints
// recalced for vert & horizontal snap & inner placement. not used for nosnap outer?
@@ -687,7 +703,7 @@ void QGIViewDimension::draw()
if(posMode == VerticalSnap) {
float tip = (lblCenter.y > centre.y) ? margin: -margin;
tip *= 0.5;
//tip *= 0.5;
arrow1Tip.x = centre.x - radius; //to left, on circle cl
arrow1Tip.y = lblCenter.y;
@@ -721,7 +737,7 @@ void QGIViewDimension::draw()
// Snapped Horizontally
float tip = (lblCenter.x > centre.x) ? margin: -margin;
tip *= 0.5;
//tip *= 0.5;
arrow1Tip.y = centre.y - radius;
arrow1Tip.x = lblCenter.x;
@@ -786,8 +802,10 @@ void QGIViewDimension::draw()
dimLines->setPath(path);
aHead1->setStyle(QGIArrow::getPrefArrowStyle());
aHead1->draw();
aHead2->flip(true);
aHead2->setStyle(QGIArrow::getPrefArrowStyle());
aHead2->draw();
float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI;
@@ -841,16 +859,20 @@ void QGIViewDimension::draw()
}
if (geom->geomType == TechDrawGeometry::CIRCLE) {
TechDrawGeometry::Circle *circ = static_cast<TechDrawGeometry::Circle *>(geom);
radius = circ->radius;
radius = Rez::guiX(circ->radius);
curveCenter = Base::Vector3d(circ->center.x,circ->center.y,0.0);
curveCenter = Rez::guiX(curveCenter);
pointOnCurve = Base::Vector3d(curveCenter.x + radius, curveCenter.y,0.0);
pointOnCurve = Rez::guiX(pointOnCurve);
} else if (geom->geomType == TechDrawGeometry::ARCOFCIRCLE) {
isArc = true;
TechDrawGeometry::AOC *circ = static_cast<TechDrawGeometry::AOC *>(geom);
geomArc = circ;
radius = circ->radius;
radius = Rez::guiX(circ->radius);
curveCenter = Base::Vector3d(circ->center.x,circ->center.y,0.0);
curveCenter = Rez::guiX(curveCenter);
pointOnCurve = Base::Vector3d(circ->midPnt.x, circ->midPnt.y,0.0);
pointOnCurve = Rez::guiX(pointOnCurve);
} else {
throw Base::Exception("FVD::draw - Original edge not found or is invalid type (3)");
}
@@ -880,8 +902,8 @@ void QGIViewDimension::draw()
Base::Vector3d dLineStart;
Base::Vector3d kinkPoint;
double margin = 5.f; //space around label
double kinkLength = 5.0; //sb % of horizontal dist(lblCenter,curveCenter)???
double margin = Rez::guiX(5.f); //space around label
double kinkLength = Rez::guiX(5.0); //sb % of horizontal dist(lblCenter,curveCenter)???
if (outerPlacement) {
float offset = (margin + w / 2);
offset = (lblCenter.x < curveCenter.x) ? offset : -offset; //if label on left then tip is +ve (ie to right)
@@ -944,6 +966,7 @@ void QGIViewDimension::draw()
dimLines->setPath(dLinePath);
aHead1->setStyle(QGIArrow::getPrefArrowStyle());
aHead1->draw();
Base::Vector3d ar1Pos = pointOnCurve;
@@ -978,6 +1001,7 @@ void QGIViewDimension::draw()
TechDrawGeometry::Generic *gen0 = static_cast<TechDrawGeometry::Generic *>(geom0);
TechDrawGeometry::Generic *gen1 = static_cast<TechDrawGeometry::Generic *>(geom1);
Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(), 0);
// Get Points for line
Base::Vector2d pnt1, pnt2;
Base::Vector3d p1S, p1E, p2S, p2E;
@@ -985,13 +1009,17 @@ void QGIViewDimension::draw()
pnt2 = gen0->points.at(1);
p1S = Base::Vector3d(pnt1.x, pnt1.y, 0);
p1S = Rez::guiX(p1S);
p1E = Base::Vector3d(pnt2.x, pnt2.y, 0);
p1E = Rez::guiX(p1E);
pnt1 = gen1->points.at(0);
pnt2 = gen1->points.at(1);
p2S = Base::Vector3d(pnt1.x, pnt1.y, 0);
p2S = Rez::guiX(p2S);
p2E = Base::Vector3d(pnt2.x, pnt2.y, 0);
p2E = Rez::guiX(p2E);
Base::Vector3d dir1 = p1E - p1S;
Base::Vector3d dir2 = p2E - p2S;
@@ -1018,15 +1046,14 @@ void QGIViewDimension::draw()
double labelangle = atan2(-labelVec.y, labelVec.x);
double startangle = atan2(dir1.y,dir1.x); //whichever edge was clicked first
double range = atan2(-dir1.y*dir2.x+dir1.x*dir2.y, //atan2(dir1.cross(dir2), dir1.dot(dir2)) =
dir1.x*dir2.x+dir1.y*dir2.y); // angle between dir1,dir2
double startangle = atan2(dir1.y,dir1.x);
double range = atan2(-dir1.y*dir2.x+dir1.x*dir2.y,
dir1.x*dir2.x+dir1.y*dir2.y);
double endangle = startangle + range;
// Obtain the Label Position
Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(), 0); //(0,0) at creation
// Obtain the Label Position and measure the length between intersection
// Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(), 0);
float bbX = datumLabel->boundingRect().width();
float bbY = datumLabel->boundingRect().height();
@@ -1043,58 +1070,9 @@ void QGIViewDimension::draw()
Base::Vector3d p2 = ((p2E - p0).Length() > (p2S - p0).Length()) ? p2E : p2S;
// add an offset from the ends (add 1mm from end)
p1 += (p1-p0).Normalize() * 5.;
p1 += (p1-p0).Normalize() * 5.; //apply Rez here??? unitVector * 5 = 1/mm?
p2 += (p2-p0).Normalize() * 5.;
double l = labelangle;
double s = startangle;
double e = endangle;
//map angles onto [0,2PI]
if (l < 0.0) {
l += 2.0 * M_PI;
}
if (s < 0.0) {
s += 2.0 * M_PI;
}
if (e < 0.0) {
e += 2.0 * M_PI;
}
double low = std::min(s,e);
double high = std::max(s,e);
double offset;
offset = -low; //rotate low number to 0*
//double offLow = low + offset; //sb always zero
double offHigh = high + offset;
double offLabel = l + offset;
if (offLabel < 0.0) { //make sure offLabel is [0,2PI]
offLabel += 2.0 * M_PI;
}
//where to draw the arc
double arcDir;
double arcRange;
if ((offLabel <= offHigh) &&
(offLabel >= 0.0)) {
arcRange = high - low;
arcDir = 1.0;
} else { //offhigh <= offLabel <= 2PI
arcRange = 2.0 * M_PI - (high - low);
arcDir = -1.0;
}
//flip the arrow heads?
bool isOutside = true;
if (offHigh <= M_PI) { // end is in top half
if (offLabel <= offHigh ) { //label between 0 and offhigh
isOutside = false;
}
} else { //offHigh > M_PI //en is in bottom half
if (offLabel >= offHigh) { //label between offHigh and 0/360
isOutside = false;
}
}
Base::Vector3d ar1Pos = p0;
Base::Vector3d ar2Pos = p0;
@@ -1107,23 +1085,87 @@ void QGIViewDimension::draw()
// Only draw extension lines if outside arc
if(length > (p1-p0).Length()) {
path.moveTo(p1.x, p1.y);
p1 = ar1Pos + (p1-p0).Normalize() * 5.;
p1 = ar1Pos + (p1-p0).Normalize() * Rez::guiX(5.); //a bit past arrow head on leg 1
path.lineTo(p1.x, p1.y);
}
if(length > (p2-p0).Length()) {
path.moveTo(p2.x, p2.y);
p2 = ar2Pos + (p2-p0).Normalize() * 5.;
p2 = ar2Pos + (p2-p0).Normalize() * Rez::guiX(5.); //a bit past leg 2 arrow head on leg 2
path.lineTo(p2.x, p2.y);
}
bool isOutside = true;
// TODO find a better solution for this. Addmitedely not tidy
// ###############
// Treat zero as positive to be consistent for horizontal lines
if(std::abs(startangle) < FLT_EPSILON)
startangle = 0;
if(std::abs(endangle) < FLT_EPSILON)
endangle = 0;
if(startangle >= 0 && endangle >= 0) { //Both are in positive side
double langle = labelangle;
if(labelangle < 0)
langle += M_PI * 2;
if(endangle - startangle > 0) {
if(langle > startangle && langle < endangle)
isOutside = false;
} else {
if(langle < startangle && langle > endangle)
isOutside = false;
}
} else if(startangle < 0 && endangle < 0) { //both are in negative side
double langle = labelangle;
if(labelangle > 0)
langle -= M_PI * 2;
if(endangle - startangle < 0) {
if(langle > endangle && langle < startangle) //clockwise
isOutside = false;
} else {
if(langle < endangle && langle > startangle) //anticlockwise
isOutside = false;
}
} else if(startangle >= 0 && endangle < 0) {
if(labelangle < startangle && labelangle > endangle) //clockwise
isOutside = false;
} else if(startangle < 0 && endangle >= 0) {
//Both are in positive side
if(labelangle > startangle && labelangle < endangle) //clockwise
isOutside = false;
}
QRectF arcRect(p0.x - length, p0.y - length, 2. * length, 2. * length);
path.arcMoveTo(arcRect, low * 180 / M_PI);
path.arcTo(arcRect, low * 180 / M_PI, arcDir * arcRange * 180 / M_PI);
path.arcMoveTo(arcRect, endangle * 180 / M_PI);
if(isOutside) {
if(labelangle > endangle)
{
path.arcTo(arcRect, endangle * 180 / M_PI, (labelangle - endangle) * 180 / M_PI); //CCW from endangle
path.arcMoveTo(arcRect,startangle * 180 / M_PI);
path.arcTo(arcRect, startangle * 180 / M_PI, -10); //cw10 from start
} else {
path.arcTo(arcRect, endangle * 180 / M_PI, 10); // chosen a nominal value for 10 degrees
path.arcMoveTo(arcRect,startangle * 180 / M_PI);
path.arcTo(arcRect, startangle * 180 / M_PI, (labelangle - startangle) * 180 / M_PI); //unknown dir
}
} else {
path.arcTo(arcRect, endangle * 180 / M_PI, -range * 180 / M_PI);
}
dimLines->setPath(path);
aHead1->flip(true);
aHead1->setStyle(QGIArrow::getPrefArrowStyle());
aHead1->draw();
aHead2->setStyle(QGIArrow::getPrefArrowStyle());
aHead2->draw();
Base::Vector3d norm1 = p1-p0; //(-dir1.y, dir1.x, 0.);
@@ -1137,7 +1179,7 @@ void QGIViewDimension::draw()
aHead1->setPos(ar1Pos.x,ar1Pos.y );
aHead2->setPos(ar2Pos.x,ar2Pos.y );
float ar1angle = atan2(-norm1.y, -norm1.x) * 180 / M_PI; //TODO: arrow dir sb tangent to arc.
float ar1angle = atan2(-norm1.y, -norm1.x) * 180 / M_PI;
float ar2angle = atan2(norm2.y, norm2.x) * 180 / M_PI;
if(isOutside) {
@@ -1148,18 +1190,21 @@ void QGIViewDimension::draw()
aHead2->setRotation(ar2angle);
}
// Set the angle of the datum text
// Set the angle of the dimension text
Base::Vector3d labelNorm(-labelVec.y, labelVec.x, 0.);
double angLabelNorm = atan2(labelNorm.y, labelNorm.x);
//if label moves above/below horizontal, flip it right side up
if (angLabelNorm > M_PI_2-M_PI/12) { // label norm angle > 90 - 15 = 85
angLabelNorm -= M_PI; // angLabelNorm - 180 Flip
} else if (angLabelNorm <= -M_PI_2-M_PI/12) { // < -90 - 15 = - 105
angLabelNorm += M_PI; // angLabelNorm + 180 Flip
double lAngle = atan2(labelNorm.y, labelNorm.x);
//if label is more/less vertical, make it vertical
if (lAngle > M_PI_2+M_PI/12) { // label norm angle > 90 + 15 = 105
lAngle -= M_PI; // lAngle - 180 Flip
} else if (lAngle <= -M_PI_2+M_PI/12) { // < -90 + 15 = - 85
lAngle += M_PI; // langle + 180 Flip
}
datumLabel->setTransformOriginPoint(bbX / 2., bbY /2.);
datumLabel->setRotation(angLabelNorm * 180 / M_PI);
datumLabel->setRotation(lAngle * 180 / M_PI);
} else {
throw Base::Exception("FVD::draw - Invalid reference for dimension type (4)");
@@ -1217,16 +1262,15 @@ void QGIViewDimension::paint ( QPainter * painter, const QStyleOptionGraphicsIte
QPaintDevice* hw = painter->device();
QSvgGenerator* svg = dynamic_cast<QSvgGenerator*>(hw);
double arrowSaveWidth = aHead1->getWidth();
setPens();
//double arrowSaveWidth = aHead1->getWidth();
if (svg) {
setSvgPens();
} else {
setPens();
}
QGIView::paint (painter, &myOption, widget);
aHead1->setWidth(arrowSaveWidth);
aHead2->setWidth(arrowSaveWidth);
dimLines->setWidth(m_lineWidth);
setPens();
}
void QGIViewDimension::setSvgPens(void)
@@ -1240,6 +1284,8 @@ void QGIViewDimension::setSvgPens(void)
void QGIViewDimension::setPens(void)
{
dimLines->setWidth(m_lineWidth);
aHead1->setWidth(m_lineWidth);
aHead2->setWidth(m_lineWidth);
}
QColor QGIViewDimension::getNormalColor()