Skip to content

Commit

Permalink
[TD]add section line marks for simple section
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Nov 15, 2022
1 parent 9313304 commit 26d7fe1
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 50 deletions.
25 changes: 0 additions & 25 deletions src/Mod/TechDraw/App/DrawComplexSection.cpp
Expand Up @@ -123,31 +123,6 @@ using namespace TechDraw;
using namespace std;
using DU = DrawUtil;

//class to store geometry of points where the section line changes direction
ChangePoint::ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection)
{
m_location = location;
m_preDirection = preDirection;
m_postDirection = postDirection;
}

ChangePoint::ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection)
{
m_location.setX(location.X());
m_location.setY(location.Y());
m_preDirection.setX(preDirection.X());
m_preDirection.setY(preDirection.Y());
m_postDirection.setX(postDirection.X());
m_postDirection.setY(postDirection.Y());
}

void ChangePoint::scale(double scaleFactor)
{
m_location = m_location * scaleFactor;
m_preDirection = m_preDirection * scaleFactor;
m_postDirection = m_postDirection * scaleFactor;
}

//===========================================================================
// DrawComplexSection
//===========================================================================
Expand Down
23 changes: 1 addition & 22 deletions src/Mod/TechDraw/App/DrawComplexSection.h
Expand Up @@ -35,27 +35,6 @@
namespace TechDraw
{

//changes in direction of complex section line
class ChangePoint
{
public:
ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection);
ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection);
~ChangePoint() = default;

QPointF getLocation() const { return m_location; }
QPointF getPreDirection() const { return m_preDirection; }
QPointF getPostDirection() const { return m_postDirection; }
void scale(double scaleFactor);

private:
QPointF m_location;
QPointF m_preDirection;
QPointF m_postDirection;
};

using ChangePointVector = std::vector<ChangePoint>;

class TechDrawExport DrawComplexSection: public DrawViewSection
{
PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawComplexSection);
Expand Down Expand Up @@ -94,7 +73,7 @@ class TechDrawExport DrawComplexSection: public DrawViewSection
std::pair<Base::Vector3d, Base::Vector3d> sectionArrowDirs();
TopoDS_Wire makeSectionLineWire();

ChangePointVector getChangePointsFromSectionLine();
ChangePointVector getChangePointsFromSectionLine() override;

bool validateProfilePosition(TopoDS_Wire profileWire, gp_Ax2 sectionCS,
gp_Dir &gClosestBasis) const;
Expand Down
6 changes: 6 additions & 0 deletions src/Mod/TechDraw/App/DrawUtil.h
Expand Up @@ -145,11 +145,17 @@ class TechDrawExport DrawUtil {
Base::Vector3d p2, Base::Vector3d d2);
static Base::Vector2d Intersect2d(Base::Vector2d p1, Base::Vector2d d1,
Base::Vector2d p2, Base::Vector2d d2);

static Base::Vector3d toVector3d(const gp_Pnt gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
static Base::Vector3d toVector3d(const gp_Dir gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
static Base::Vector3d toVector3d(const gp_Vec gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
static Base::Vector3d toVector3d(const QPointF gp) { return Base::Vector3d(gp.x(), gp.y(), 0.0); }

static gp_Pnt togp_Pnt(const Base::Vector3d v) { return gp_Pnt(v.x, v.y, v.z); }
static gp_Dir togp_Dir(const Base::Vector3d v) { return gp_Dir(v.x, v.y, v.z); }
static gp_Vec togp_Vec(const Base::Vector3d v) { return gp_Vec(v.x, v.y, v.z); }
static QPointF toQPointF(const Base::Vector3d v) { return QPointF(v.x, v.y); }

static std::string shapeToString(TopoDS_Shape s);
static TopoDS_Shape shapeFromString(std::string s);
static Base::Vector3d invertY(Base::Vector3d v);
Expand Down
47 changes: 47 additions & 0 deletions src/Mod/TechDraw/App/DrawViewSection.cpp
Expand Up @@ -95,6 +95,29 @@ using namespace TechDraw;

using DU = DrawUtil;

//class to store geometry of points where the section line changes direction
ChangePoint::ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection)
{
m_location = location;
m_preDirection = preDirection;
m_postDirection = postDirection;
}

ChangePoint::ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection)
{
m_location.setX(location.X());
m_location.setY(location.Y());
m_preDirection.setX(preDirection.X());
m_preDirection.setY(preDirection.Y());
m_postDirection.setX(postDirection.X());
m_postDirection.setY(postDirection.Y());
}

void ChangePoint::scale(double scaleFactor)
{
m_location = m_location * scaleFactor;
}

const char* DrawViewSection::SectionDirEnums[]= {"Right",
"Left",
"Up",
Expand Down Expand Up @@ -726,6 +749,30 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawViewSection::sectionLineEnds()
return result;
}

//find the points and directions to make the change point marks.
ChangePointVector DrawViewSection::getChangePointsFromSectionLine()
{
// Base::Console().Message("Dvs::getChangePointsFromSectionLine()\n");
ChangePointVector result;
std::vector<gp_Pnt> allPoints;
DrawViewPart *baseDvp = dynamic_cast<DrawViewPart *>(BaseView.getValue());
if (baseDvp) {
std::pair<Base::Vector3d, Base::Vector3d> lineEnds = sectionLineEnds();
//make start and end marks
gp_Pnt location0 = DU::togp_Pnt(lineEnds.first);
gp_Pnt location1 = DU::togp_Pnt(lineEnds.second);
gp_Dir postDir = gp_Dir(location1.XYZ() - location0.XYZ());
gp_Dir preDir = postDir.Reversed();
ChangePoint startPoint(location0, preDir, postDir);
result.push_back(startPoint);
preDir = gp_Dir(location0.XYZ() - location1.XYZ());
postDir = preDir.Reversed();
ChangePoint endPoint(location1, preDir, postDir);
result.push_back(endPoint);
}
return result;
}

//this should really be in BoundBox.h
//!check if point is in box or on boundary of box
//!compare to isInBox which doesn't allow on boundary
Expand Down
23 changes: 23 additions & 0 deletions src/Mod/TechDraw/App/DrawViewSection.h
Expand Up @@ -58,6 +58,28 @@ class PATLineSpec;
class LineSet;
class DashSet;

//changes in direction of complex section line. also marks at arrow positions.
class ChangePoint
{
public:
ChangePoint(QPointF location, QPointF preDirection, QPointF postDirection);
ChangePoint(gp_Pnt location, gp_Dir preDirection, gp_Dir postDirection);
~ChangePoint() = default;

QPointF getLocation() const { return m_location; }
void setLocation(QPointF newLocation) { m_location = newLocation; }
QPointF getPreDirection() const { return m_preDirection; }
QPointF getPostDirection() const { return m_postDirection; }
void scale(double scaleFactor);

private:
QPointF m_location;
QPointF m_preDirection;
QPointF m_postDirection;
};

using ChangePointVector = std::vector<ChangePoint>;

class TechDrawExport DrawViewSection : public DrawViewPart
{
PROPERTY_HEADER_WITH_OVERRIDE(Part::DrawViewSection);
Expand Down Expand Up @@ -141,6 +163,7 @@ class TechDrawExport DrawViewSection : public DrawViewPart
static const char* CutSurfaceEnums[];

virtual std::pair<Base::Vector3d, Base::Vector3d> sectionLineEnds();
virtual ChangePointVector getChangePointsFromSectionLine();

bool showSectionEdges(void);

Expand Down
22 changes: 19 additions & 3 deletions src/Mod/TechDraw/Gui/QGIViewPart.cpp
Expand Up @@ -86,6 +86,7 @@
using namespace TechDraw;
using namespace TechDrawGui;
using namespace std;
using DU = DrawUtil;

#define GEOMETRYEDGE 0
#define COSMETICEDGE 1
Expand Down Expand Up @@ -844,17 +845,32 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b
Base::Vector3d l1 = Rez::guiX(sLineEnds.first) * scale;
Base::Vector3d l2 = Rez::guiX(sLineEnds.second) * scale;
//make the section line a little longer
double fudge = Rez::guiX(2.0 * Preferences::dimFontSizeMM());
double fudge = 2.0 * Preferences::dimFontSizeMM();
Base::Vector3d lineDir = l2 - l1;
lineDir.Normalize();
sectionLine->setEnds(l1 - lineDir * fudge,
l2 + lineDir * fudge);
sectionLine->setEnds(l1 - lineDir * Rez::guiX(fudge),
l2 + lineDir * Rez::guiX(fudge));

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

if (vp->SectionLineMarks.getValue()) {
ChangePointVector points = viewSection->getChangePointsFromSectionLine();
//extend the changePoint locations to match the fudged section line ends
QPointF location0 = points.front().getLocation() * scale;
location0 = location0 - DU::toQPointF(lineDir) * fudge;
QPointF location1 = points.back().getLocation() * scale;
location1 = location1 + DU::toQPointF(lineDir) * fudge;
//change points have Rez::guiX applied in sectionLine
points.front().setLocation(location0);
points.back().setLocation(location1);
sectionLine->setChangePoints(points);
} else {
sectionLine->clearChangePoints();
}

//set the general parameters
sectionLine->setPos(0.0, 0.0);
sectionLine->setWidth(lineWidthThin);
Expand Down

0 comments on commit 26d7fe1

Please sign in to comment.