Skip to content

Commit 26d7fe1

Browse files
committed
[TD]add section line marks for simple section
1 parent 9313304 commit 26d7fe1

File tree

6 files changed

+96
-50
lines changed

6 files changed

+96
-50
lines changed

src/Mod/TechDraw/App/DrawComplexSection.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,6 @@ using namespace TechDraw;
123123
using namespace std;
124124
using DU = DrawUtil;
125125

126-
//class to store geometry of points where the section line changes direction
127-
ChangePoint::ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection)
128-
{
129-
m_location = location;
130-
m_preDirection = preDirection;
131-
m_postDirection = postDirection;
132-
}
133-
134-
ChangePoint::ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection)
135-
{
136-
m_location.setX(location.X());
137-
m_location.setY(location.Y());
138-
m_preDirection.setX(preDirection.X());
139-
m_preDirection.setY(preDirection.Y());
140-
m_postDirection.setX(postDirection.X());
141-
m_postDirection.setY(postDirection.Y());
142-
}
143-
144-
void ChangePoint::scale(double scaleFactor)
145-
{
146-
m_location = m_location * scaleFactor;
147-
m_preDirection = m_preDirection * scaleFactor;
148-
m_postDirection = m_postDirection * scaleFactor;
149-
}
150-
151126
//===========================================================================
152127
// DrawComplexSection
153128
//===========================================================================

src/Mod/TechDraw/App/DrawComplexSection.h

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,6 @@
3535
namespace TechDraw
3636
{
3737

38-
//changes in direction of complex section line
39-
class ChangePoint
40-
{
41-
public:
42-
ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection);
43-
ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection);
44-
~ChangePoint() = default;
45-
46-
QPointF getLocation() const { return m_location; }
47-
QPointF getPreDirection() const { return m_preDirection; }
48-
QPointF getPostDirection() const { return m_postDirection; }
49-
void scale(double scaleFactor);
50-
51-
private:
52-
QPointF m_location;
53-
QPointF m_preDirection;
54-
QPointF m_postDirection;
55-
};
56-
57-
using ChangePointVector = std::vector<ChangePoint>;
58-
5938
class TechDrawExport DrawComplexSection: public DrawViewSection
6039
{
6140
PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawComplexSection);
@@ -94,7 +73,7 @@ class TechDrawExport DrawComplexSection: public DrawViewSection
9473
std::pair<Base::Vector3d, Base::Vector3d> sectionArrowDirs();
9574
TopoDS_Wire makeSectionLineWire();
9675

97-
ChangePointVector getChangePointsFromSectionLine();
76+
ChangePointVector getChangePointsFromSectionLine() override;
9877

9978
bool validateProfilePosition(TopoDS_Wire profileWire, gp_Ax2 sectionCS,
10079
gp_Dir &gClosestBasis) const;

src/Mod/TechDraw/App/DrawUtil.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,17 @@ class TechDrawExport DrawUtil {
145145
Base::Vector3d p2, Base::Vector3d d2);
146146
static Base::Vector2d Intersect2d(Base::Vector2d p1, Base::Vector2d d1,
147147
Base::Vector2d p2, Base::Vector2d d2);
148+
148149
static Base::Vector3d toVector3d(const gp_Pnt gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
149150
static Base::Vector3d toVector3d(const gp_Dir gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
151+
static Base::Vector3d toVector3d(const gp_Vec gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
152+
static Base::Vector3d toVector3d(const QPointF gp) { return Base::Vector3d(gp.x(), gp.y(), 0.0); }
153+
150154
static gp_Pnt togp_Pnt(const Base::Vector3d v) { return gp_Pnt(v.x, v.y, v.z); }
151155
static gp_Dir togp_Dir(const Base::Vector3d v) { return gp_Dir(v.x, v.y, v.z); }
152156
static gp_Vec togp_Vec(const Base::Vector3d v) { return gp_Vec(v.x, v.y, v.z); }
157+
static QPointF toQPointF(const Base::Vector3d v) { return QPointF(v.x, v.y); }
158+
153159
static std::string shapeToString(TopoDS_Shape s);
154160
static TopoDS_Shape shapeFromString(std::string s);
155161
static Base::Vector3d invertY(Base::Vector3d v);

src/Mod/TechDraw/App/DrawViewSection.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,29 @@ using namespace TechDraw;
9595

9696
using DU = DrawUtil;
9797

98+
//class to store geometry of points where the section line changes direction
99+
ChangePoint::ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection)
100+
{
101+
m_location = location;
102+
m_preDirection = preDirection;
103+
m_postDirection = postDirection;
104+
}
105+
106+
ChangePoint::ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection)
107+
{
108+
m_location.setX(location.X());
109+
m_location.setY(location.Y());
110+
m_preDirection.setX(preDirection.X());
111+
m_preDirection.setY(preDirection.Y());
112+
m_postDirection.setX(postDirection.X());
113+
m_postDirection.setY(postDirection.Y());
114+
}
115+
116+
void ChangePoint::scale(double scaleFactor)
117+
{
118+
m_location = m_location * scaleFactor;
119+
}
120+
98121
const char* DrawViewSection::SectionDirEnums[]= {"Right",
99122
"Left",
100123
"Up",
@@ -726,6 +749,30 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawViewSection::sectionLineEnds()
726749
return result;
727750
}
728751

752+
//find the points and directions to make the change point marks.
753+
ChangePointVector DrawViewSection::getChangePointsFromSectionLine()
754+
{
755+
// Base::Console().Message("Dvs::getChangePointsFromSectionLine()\n");
756+
ChangePointVector result;
757+
std::vector<gp_Pnt> allPoints;
758+
DrawViewPart *baseDvp = dynamic_cast<DrawViewPart *>(BaseView.getValue());
759+
if (baseDvp) {
760+
std::pair<Base::Vector3d, Base::Vector3d> lineEnds = sectionLineEnds();
761+
//make start and end marks
762+
gp_Pnt location0 = DU::togp_Pnt(lineEnds.first);
763+
gp_Pnt location1 = DU::togp_Pnt(lineEnds.second);
764+
gp_Dir postDir = gp_Dir(location1.XYZ() - location0.XYZ());
765+
gp_Dir preDir = postDir.Reversed();
766+
ChangePoint startPoint(location0, preDir, postDir);
767+
result.push_back(startPoint);
768+
preDir = gp_Dir(location0.XYZ() - location1.XYZ());
769+
postDir = preDir.Reversed();
770+
ChangePoint endPoint(location1, preDir, postDir);
771+
result.push_back(endPoint);
772+
}
773+
return result;
774+
}
775+
729776
//this should really be in BoundBox.h
730777
//!check if point is in box or on boundary of box
731778
//!compare to isInBox which doesn't allow on boundary

src/Mod/TechDraw/App/DrawViewSection.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ class PATLineSpec;
5858
class LineSet;
5959
class DashSet;
6060

61+
//changes in direction of complex section line. also marks at arrow positions.
62+
class ChangePoint
63+
{
64+
public:
65+
ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection);
66+
ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection);
67+
~ChangePoint() = default;
68+
69+
QPointF getLocation() const { return m_location; }
70+
void setLocation(QPointF newLocation) { m_location = newLocation; }
71+
QPointF getPreDirection() const { return m_preDirection; }
72+
QPointF getPostDirection() const { return m_postDirection; }
73+
void scale(double scaleFactor);
74+
75+
private:
76+
QPointF m_location;
77+
QPointF m_preDirection;
78+
QPointF m_postDirection;
79+
};
80+
81+
using ChangePointVector = std::vector<ChangePoint>;
82+
6183
class TechDrawExport DrawViewSection : public DrawViewPart
6284
{
6385
PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawViewSection);
@@ -141,6 +163,7 @@ class TechDrawExport DrawViewSection : public DrawViewPart
141163
static const char* CutSurfaceEnums[];
142164

143165
virtual std::pair<Base::Vector3d, Base::Vector3d> sectionLineEnds();
166+
virtual ChangePointVector getChangePointsFromSectionLine();
144167

145168
bool showSectionEdges(void);
146169

src/Mod/TechDraw/Gui/QGIViewPart.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
using namespace TechDraw;
8787
using namespace TechDrawGui;
8888
using namespace std;
89+
using DU = DrawUtil;
8990

9091
#define GEOMETRYEDGE 0
9192
#define COSMETICEDGE 1
@@ -844,17 +845,32 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b
844845
Base::Vector3d l1 = Rez::guiX(sLineEnds.first) * scale;
845846
Base::Vector3d l2 = Rez::guiX(sLineEnds.second) * scale;
846847
//make the section line a little longer
847-
double fudge = Rez::guiX(2.0 * Preferences::dimFontSizeMM());
848+
double fudge = 2.0 * Preferences::dimFontSizeMM();
848849
Base::Vector3d lineDir = l2 - l1;
849850
lineDir.Normalize();
850-
sectionLine->setEnds(l1 - lineDir * fudge,
851-
l2 + lineDir * fudge);
851+
sectionLine->setEnds(l1 - lineDir * Rez::guiX(fudge),
852+
l2 + lineDir * Rez::guiX(fudge));
852853

853854
//which way do the arrows point?
854855
Base::Vector3d arrowDir = viewSection->SectionNormal.getValue();
855856
arrowDir = - viewPart->projectPoint(arrowDir); //arrows point reverse of sectionNormal
856857
sectionLine->setDirection(arrowDir.x, - arrowDir.y); //3d direction needs Y inversion
857858

859+
if (vp->SectionLineMarks.getValue()) {
860+
ChangePointVector points = viewSection->getChangePointsFromSectionLine();
861+
//extend the changePoint locations to match the fudged section line ends
862+
QPointF location0 = points.front().getLocation() * scale;
863+
location0 = location0 - DU::toQPointF(lineDir) * fudge;
864+
QPointF location1 = points.back().getLocation() * scale;
865+
location1 = location1 + DU::toQPointF(lineDir) * fudge;
866+
//change points have Rez::guiX applied in sectionLine
867+
points.front().setLocation(location0);
868+
points.back().setLocation(location1);
869+
sectionLine->setChangePoints(points);
870+
} else {
871+
sectionLine->clearChangePoints();
872+
}
873+
858874
//set the general parameters
859875
sectionLine->setPos(0.0, 0.0);
860876
sectionLine->setWidth(lineWidthThin);

0 commit comments

Comments
 (0)