Skip to content

Commit

Permalink
[TD]fix 4335 section line pos on rotated base
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Jun 15, 2020
1 parent 8a9ea0c commit b7a448d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
51 changes: 28 additions & 23 deletions src/Mod/TechDraw/App/DrawUtil.cpp
Expand Up @@ -296,36 +296,41 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawUtil::boxIntersect2d(Base::Vector3
dir.Normalize();
// y = mx + b
// m = (y1 - y0) / (x1 - x0)
if (DrawUtil::fpCompare(dir.x, 0.0) ) {
if (DrawUtil::fpCompare(dir.x, 0.0) ) { //vertical case
p1 = Base::Vector3d(point.x, - yRange / 2.0, 0.0);
p2 = Base::Vector3d(point.x, yRange / 2.0, 0.0);
} else {
double slope = dir.y / dir.x;
double left = -xRange / 2.0;
double right = xRange / 2.0;
double top = yRange / 2.0;
double bottom = -yRange / 2.0;
double yLeft = point.y - slope * (point.x - left) ;
double yRight = point.y - slope * (point.x - right);
double xTop = point.x - ( (point.y - top) / slope );
double xBottom = point.x - ( (point.y - bottom) / slope );

if ( (bottom < yLeft) &&
(top > yLeft) ) {
p1 = Base::Vector3d(left, yLeft);
} else if (yLeft <= bottom) {
p1 = Base::Vector3d(xBottom, bottom);
} else if (yLeft >= top) {
p1 = Base::Vector3d(xTop, top);
}
if (DrawUtil::fpCompare(slope, 0.0)) { //horizontal case
p1 = Base::Vector3d(left, point.y);
p2 = Base::Vector3d(right, point.y);
} else { //normal case
double top = yRange / 2.0;
double bottom = -yRange / 2.0;
double yLeft = point.y - slope * (point.x - left) ;
double yRight = point.y - slope * (point.x - right);
double xTop = point.x - ( (point.y - top) / slope );
double xBottom = point.x - ( (point.y - bottom) / slope );

if ( (bottom < yLeft) &&
(top > yLeft) ) {
p1 = Base::Vector3d(left, yLeft);
} else if (yLeft <= bottom) {
p1 = Base::Vector3d(xBottom, bottom);
} else if (yLeft >= top) {
p1 = Base::Vector3d(xTop, top);
}

if ( (bottom < yRight) &&
(top > yRight) ) {
p2 = Base::Vector3d(right, yRight);
} else if (yRight <= bottom) {
p2 = Base::Vector3d(xBottom, bottom);
} else if (yRight >= top) {
p2 = Base::Vector3d(xTop, top);
if ( (bottom < yRight) &&
(top > yRight) ) {
p2 = Base::Vector3d(right, yRight);
} else if (yRight <= bottom) {
p2 = Base::Vector3d(xBottom, bottom);
} else if (yRight >= top) {
p2 = Base::Vector3d(xTop, top);
}
}
}
result.first = p1;
Expand Down
10 changes: 10 additions & 0 deletions src/Mod/TechDraw/App/DrawViewSection.cpp
Expand Up @@ -585,6 +585,11 @@ TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shap
std::pair<Base::Vector3d, Base::Vector3d> DrawViewSection::sectionLineEnds(void)
{
std::pair<Base::Vector3d, Base::Vector3d> result;
Base::Vector3d stdZ(0.0, 0.0, 1.0);
double baseRotation = getBaseDVP()->Rotation.getValue(); //Qt degrees
Base::Rotation rotator(stdZ, baseRotation * M_PI / 180.0);
Base::Rotation unrotator(stdZ, - baseRotation * M_PI / 180.0);

auto sNorm = SectionNormal.getValue();
double angle = M_PI / 2.0;
auto axis = getBaseDVP()->Direction.getValue();
Expand All @@ -605,7 +610,12 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawViewSection::sectionLineEnds(void)
xRange /= getBaseDVP()->getScale();
double yRange = bbx.MaxY - bbx.MinY;
yRange /= getBaseDVP()->getScale();
sOrgOnBase = rotator.multVec(sOrgOnBase);
sLineOnBase = rotator.multVec(sLineOnBase);

result = DrawUtil::boxIntersect2d(sOrgOnBase, sLineOnBase, xRange, yRange); //unscaled
result.first = unrotator.multVec(result.first);
result.second = unrotator.multVec(result.second);

return result;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/TechDraw/Gui/QGIDecoration.cpp
Expand Up @@ -106,6 +106,12 @@ QColor QGIDecoration::prefSelectColor()
return PreferencesGui::selectQColor();
}

QRectF QGIDecoration::boundingRect() const
{
return childrenBoundingRect();
}


void QGIDecoration::makeMark(double x, double y)
{
QGICMark* cmItem = new QGICMark(-1);
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/QGIDecoration.h
Expand Up @@ -47,6 +47,7 @@ class TechDrawGuiExport QGIDecoration : public QGraphicsItemGroup
enum {Type = QGraphicsItem::UserType + 173};
int type() const { return Type;}

virtual QRectF boundingRect() const;
virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
virtual void draw();
void setWidth(double w);
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/QGIViewPart.cpp
Expand Up @@ -872,7 +872,7 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b
double fontSize = Preferences::dimFontSizeMM();
sectionLine->setFont(m_font, fontSize);
sectionLine->setZValue(ZVALUE::SECTIONLINE);
sectionLine->setRotation(viewPart->Rotation.getValue());
sectionLine->setRotation(- viewPart->Rotation.getValue());
sectionLine->draw();
}
}
Expand Down

0 comments on commit b7a448d

Please sign in to comment.