Merge pull request #19411 from benj5378/enums2

TechDraw: hard type enums, part 2
This commit is contained in:
Chris Hennes
2025-03-03 10:37:21 -06:00
committed by GitHub
36 changed files with 411 additions and 451 deletions

View File

@@ -34,14 +34,16 @@ namespace TechDraw
{
//common definitions for line ends / arrows
enum ArrowType { FILLED_ARROW = 0,
OPEN_ARROW,
TICK,
DOT,
OPEN_CIRCLE,
FORK,
FILLED_TRIANGLE,
NONE};
enum class ArrowType : int {
FILLED_ARROW = 0,
OPEN_ARROW,
TICK,
DOT,
OPEN_CIRCLE,
FORK,
FILLED_TRIANGLE,
NONE
};
class TechDrawExport ArrowPropEnum {
Q_DECLARE_TR_FUNCTIONS(TechDraw::ArrowPropEnum)

View File

@@ -33,14 +33,16 @@
namespace TechDraw
{
enum BalloonType { Circular = 0,
None,
Triangle,
Inspection,
Hexagon,
Square,
Rectangle,
Line};
enum class BalloonType {
Circular = 0,
None,
Triangle,
Inspection,
Hexagon,
Square,
Rectangle,
Line
};
class TechDrawExport BalloonPropEnum {
Q_DECLARE_TR_FUNCTIONS(TechDraw::BalloonPropEnum)

View File

@@ -561,12 +561,11 @@ int DrawProjGroup::purgeProjections()
std::pair<Base::Vector3d, Base::Vector3d> DrawProjGroup::getDirsFromFront(DrawProjGroupItem* view)
{
std::pair<Base::Vector3d, Base::Vector3d> result;
std::string viewType = view->Type.getValueAsString();
ProjDirection viewType = static_cast<ProjDirection>(view->Type.getValue());
return getDirsFromFront(viewType);
}
std::pair<Base::Vector3d, Base::Vector3d> DrawProjGroup::getDirsFromFront(std::string viewType)
std::pair<Base::Vector3d, Base::Vector3d> DrawProjGroup::getDirsFromFront(ProjDirection viewType)
{
// Base::Console().Message("DPG::getDirsFromFront(%s)\n", viewType.c_str());
std::pair<Base::Vector3d, Base::Vector3d> result;
@@ -1106,77 +1105,26 @@ void DrawProjGroup::updateSecondaryDirs()
Base::Vector3d anchDir = anchor->Direction.getValue();
Base::Vector3d anchRot = anchor->getXDirection();
std::map<std::string, std::pair<Base::Vector3d, Base::Vector3d>> saveVals;
std::string key;
std::map<ProjDirection, std::pair<Base::Vector3d, Base::Vector3d>> saveVals;
std::pair<Base::Vector3d, Base::Vector3d> data;
for (auto& docObj : Views.getValues()) {
std::pair<Base::Vector3d, Base::Vector3d> newDirs;
std::string pic;
DrawProjGroupItem* v = static_cast<DrawProjGroupItem*>(docObj);
ProjItemType t = static_cast<ProjItemType>(v->Type.getValue());
switch (t) {
case Front:
data.first = anchDir;
data.second = anchRot;
key = "Front";
saveVals[key] = data;
break;
case Rear:
key = "Rear";
newDirs = getDirsFromFront(key);
saveVals[key] = newDirs;
break;
case Left:
key = "Left";
newDirs = getDirsFromFront(key);
saveVals[key] = newDirs;
break;
case Right:
key = "Right";
newDirs = getDirsFromFront(key);
saveVals[key] = newDirs;
break;
case Top:
key = "Top";
newDirs = getDirsFromFront(key);
saveVals[key] = newDirs;
break;
case Bottom:
key = "Bottom";
newDirs = getDirsFromFront(key);
saveVals[key] = newDirs;
break;
case FrontTopLeft:
key = "FrontTopLeft";
newDirs = getDirsFromFront(key);
saveVals[key] = newDirs;
break;
case FrontTopRight:
key = "FrontTopRight";
newDirs = getDirsFromFront(key);
saveVals[key] = newDirs;
break;
case FrontBottomLeft:
key = "FrontBottomLeft";
newDirs = getDirsFromFront(key);
saveVals[key] = newDirs;
break;
case FrontBottomRight:
key = "FrontBottomRight";
newDirs = getDirsFromFront(key);
saveVals[key] = newDirs;
break;
default: {
//TARFU invalid secondary type
Base::Console().Message(
"ERROR - DPG::updateSecondaryDirs - invalid projection type\n");
}
ProjDirection t = static_cast<ProjDirection>(v->Type.getValue());
if (t == ProjDirection::Front) {
data.first = anchDir;
data.second = anchRot;
saveVals[ProjDirection::Front] = data;
}
else {
std::pair<Base::Vector3d, Base::Vector3d> newDirs = getDirsFromFront(t);
saveVals[t] = newDirs;
}
}
for (auto& docObj : Views.getValues()) {
DrawProjGroupItem* v = static_cast<DrawProjGroupItem*>(docObj);
std::string type = v->Type.getValueAsString();
ProjDirection type = static_cast<ProjDirection>(v->Type.getValue());
data = saveVals[type];
v->Direction.setValue(data.first);
v->Direction.purgeTouched();
@@ -1186,31 +1134,20 @@ void DrawProjGroup::updateSecondaryDirs()
recomputeChildren();
}
void DrawProjGroup::rotate(const std::string& rotationdirection)
void DrawProjGroup::rotate(const RotationMotion& motion)
{
std::pair<Base::Vector3d, Base::Vector3d> newDirs;
if (rotationdirection == "Right")
newDirs = getDirsFromFront("Left");// Front -> Right -> Rear -> Left -> Front
else if (rotationdirection == "Left")
newDirs = getDirsFromFront("Right");// Front -> Left -> Rear -> Right -> Front
else if (rotationdirection == "Up")
newDirs = getDirsFromFront("Bottom");// Front -> Top -> Rear -> Bottom -> Front
else if (rotationdirection == "Down")
newDirs = getDirsFromFront("Top");// Front -> Bottom -> Rear -> Top -> Front
DrawProjGroupItem* anchor = getAnchor();
anchor->Direction.setValue(newDirs.first);
anchor->XDirection.setValue(newDirs.second);
getAnchor()->rotate(motion);
updateSecondaryDirs();
}
void DrawProjGroup::spin(const std::string& spindirection)
// TODO: should these functions identical to those
// in DrawViewPart be moved to DrawView?
void DrawProjGroup::spin(const SpinDirection& spindirection)
{
double angle;
if (spindirection == "CW")
if (spindirection == SpinDirection::CW)
angle = M_PI / 2.0;// Top -> Right -> Bottom -> Left -> Top
if (spindirection == "CCW")
if (spindirection == SpinDirection::CCW)
angle = -M_PI / 2.0;// Top -> Left -> Bottom -> Right -> Top
spin(angle);

View File

@@ -43,6 +43,9 @@ namespace TechDraw
const int MAXPROJECTIONCOUNT = 10;
class DrawProjGroupItem;
enum class ProjDirection : int;
enum class SpinDirection : int;
enum class RotationMotion : int;
/**
* Class super-container for managing a collection of DrawProjGroupItem
@@ -123,12 +126,12 @@ public:
Base::Vector3d getAnchorDirection();
TechDraw::DrawProjGroupItem* getAnchor();
std::pair<Base::Vector3d, Base::Vector3d> getDirsFromFront(DrawProjGroupItem* view);
std::pair<Base::Vector3d, Base::Vector3d> getDirsFromFront(std::string viewType);
std::pair<Base::Vector3d, Base::Vector3d> getDirsFromFront(TechDraw::ProjDirection viewType);
void updateSecondaryDirs();
void rotate(const std::string &rotationdirection);
void spin(const std::string &spindirection);
void rotate(const TechDraw::RotationMotion& motion);
void spin(const TechDraw::SpinDirection& spindirection);
void spin(double angle);
void dumpISO(const char * title);

View File

@@ -35,17 +35,6 @@
namespace TechDraw
{
enum ProjItemType{ Front,
Left,
Right,
Rear,
Top,
Bottom,
FrontTopLeft,
FrontTopRight,
FrontBottomLeft,
FrontBottomRight };
class DrawProjGroup;
class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart

View File

@@ -70,7 +70,7 @@ DrawViewBalloon::DrawViewBalloon()
ADD_PROPERTY_TYPE(OriginY, (0), "", (App::PropertyType)(App::Prop_None), "Balloon origin y");
EndType.setEnums(ArrowPropEnum::ArrowTypeEnums);
ADD_PROPERTY_TYPE(EndType, (Preferences::balloonArrow()), "", (App::PropertyType)(App::Prop_None),
ADD_PROPERTY_TYPE(EndType, (static_cast<int>(Preferences::balloonArrow())), "", (App::PropertyType)(App::Prop_None),
"End symbol for the balloon line");
ADD_PROPERTY_TYPE(EndTypeScale, (1.0), "", (App::PropertyType)(App::Prop_None),

View File

@@ -51,7 +51,7 @@ public:
App::DocumentObjectExecReturn *execute() override;
int getRefType() const override { return extent; }
RefType getRefType() const override { return RefType::extent; }
PyObject *getPyObject() override;

View File

@@ -82,6 +82,7 @@
using namespace TechDraw;
using namespace Part;
using DU = DrawUtil;
using RefType = DrawViewDimension::RefType;
//===========================================================================
// DrawViewDimension
@@ -490,16 +491,16 @@ App::DocumentObjectExecReturn* DrawViewDimension::execute()
ReferenceVector references = getEffectiveReferences();
if (Type.isValue("Distance") || Type.isValue("DistanceX") || Type.isValue("DistanceY")) {
if (getRefType() == oneEdge) {
if (getRefType() == RefType::oneEdge) {
m_linearPoints = getPointsOneEdge(references);
}
else if (getRefType() == twoEdge) {
else if (getRefType() == RefType::twoEdge) {
m_linearPoints = getPointsTwoEdges(references);
}
else if (getRefType() == twoVertex) {
else if (getRefType() == RefType::twoVertex) {
m_linearPoints = getPointsTwoVerts(references);
}
else if (getRefType() == vertexEdge) {
else if (getRefType() == RefType::vertexEdge) {
m_linearPoints = getPointsEdgeVert(references);
}
m_hasGeometry = true;
@@ -510,21 +511,21 @@ App::DocumentObjectExecReturn* DrawViewDimension::execute()
m_hasGeometry = true;
}
else if (Type.isValue("Angle")) {
if (getRefType() != twoEdge) {
if (getRefType() != RefType::twoEdge) {
throw Base::RuntimeError("Angle dimension has non-edge references");
}
m_anglePoints = getAnglePointsTwoEdges(references);
m_hasGeometry = true;
}
else if (Type.isValue("Angle3Pt")) {
if (getRefType() != threeVertex) {
if (getRefType() != RefType::threeVertex) {
throw Base::RuntimeError("3 point angle dimension has non-vertex references");
}
m_anglePoints = getAnglePointsThreeVerts(references);
m_hasGeometry = true;
}
else if (Type.isValue("Area")) {
if (getRefType() != oneFace) {
if (getRefType() != RefType::oneFace) {
throw Base::RuntimeError("area dimension has non-face references");
}
m_areaPoint = getAreaParameters(references);
@@ -1512,7 +1513,7 @@ ReferenceVector DrawViewDimension::getEffectiveReferences() const
// what configuration of references do we have - Vertex-Vertex, Edge-Vertex, Edge, ...
int DrawViewDimension::getRefType() const
RefType DrawViewDimension::getRefType() const
{
if (isExtentDim()) {
return RefType::extent;
@@ -1534,7 +1535,7 @@ int DrawViewDimension::getRefType() const
// something went wrong, there were no subNames.
Base::Console().Message("DVD::getRefType - %s - there are no subNames.\n",
getNameInDocument());
return 0;
return RefType::invalidRef;
}
return getRefTypeSubElements(subNames);
@@ -1542,9 +1543,9 @@ int DrawViewDimension::getRefType() const
// TODO: Gui/DimensionValidators.cpp has almost the same code
// decide what the reference configuration is by examining the names of the sub elements
int DrawViewDimension::getRefTypeSubElements(const std::vector<std::string>& subElements)
RefType DrawViewDimension::getRefTypeSubElements(const std::vector<std::string>& subElements)
{
int refType{invalidRef};
RefType refType{RefType::invalidRef};
int refEdges{0};
int refVertices{0};
int refFaces{0};
@@ -1562,22 +1563,22 @@ int DrawViewDimension::getRefTypeSubElements(const std::vector<std::string>& sub
}
if (refEdges == 0 && refVertices == 2 && refFaces == 0) {
refType = twoVertex;
refType = RefType::twoVertex;
}
if (refEdges == 0 && refVertices == 3 && refFaces == 0) {
refType = threeVertex;
refType = RefType::threeVertex;
}
if (refEdges == 1 && refVertices == 0 && refFaces == 0) {
refType = oneEdge;
refType = RefType::oneEdge;
}
if (refEdges == 1 && refVertices == 1 && refFaces == 0) {
refType = vertexEdge;
refType = RefType::vertexEdge;
}
if (refEdges == 2 && refVertices == 0 && refFaces == 0) {
refType = twoEdge;
refType = RefType::twoEdge;
}
if (refEdges == 0 && refVertices == 0 && refFaces == 1) {
refType = oneFace;
refType = RefType::oneFace;
}
return refType;
@@ -1830,14 +1831,14 @@ bool DrawViewDimension::validateReferenceForm() const
}
if (Type.isValue("Distance") || Type.isValue("DistanceX") || Type.isValue("DistanceY")) {
if (getRefType() == oneEdge) {
if (getRefType() == RefType::oneEdge) {
if (references.size() != 1) {
return false;
}
std::string subGeom = DrawUtil::getGeomTypeFromName(references.front().getSubName());
return subGeom == "Edge";
}
if (getRefType() == twoEdge) {
if (getRefType() == RefType::twoEdge) {
if (references.size() != 2) {
return false;
}
@@ -1846,7 +1847,7 @@ bool DrawViewDimension::validateReferenceForm() const
return (subGeom0 == "Edge" && subGeom1 == "Edge");
}
if (getRefType() == twoVertex) {
if (getRefType() == RefType::twoVertex) {
if (references.size() != 2) {
return false;
}
@@ -1855,7 +1856,7 @@ bool DrawViewDimension::validateReferenceForm() const
return (subGeom0 == "Vertex" && subGeom1 == "Vertex");
}
if (getRefType() == vertexEdge) {
if (getRefType() == RefType::vertexEdge) {
if (references.size() != 2) {
return false;
}

View File

@@ -99,7 +99,7 @@ public:
App::PropertyBool ShowUnits;
enum RefType
enum class RefType
{
invalidRef,
oneEdge,
@@ -145,8 +145,8 @@ public:
{
return {0, 0, 1, 1};
} // pretend dimensions always fit!
virtual int getRefType() const; // Vertex-Vertex, Edge, Edge-Edge
static int
virtual RefType getRefType() const; // Vertex-Vertex, Edge, Edge-Edge
static RefType
getRefTypeSubElements(const std::vector<std::string>&); // Vertex-Vertex, Edge, Edge-Edge
void setReferences2d(const ReferenceVector& refs);

View File

@@ -1276,29 +1276,29 @@ Base::Vector3d DrawViewPart::getXDirection() const
}
void DrawViewPart::rotate(const std::string& rotationdirection)
void DrawViewPart::rotate(const RotationMotion& motion)
{
std::pair<Base::Vector3d, Base::Vector3d> newDirs;
if (rotationdirection == "Right")
newDirs = getDirsFromFront("Left");// Front -> Right -> Rear -> Left -> Front
else if (rotationdirection == "Left")
newDirs = getDirsFromFront("Right");// Front -> Left -> Rear -> Right -> Front
else if (rotationdirection == "Up")
newDirs = getDirsFromFront("Bottom");// Front -> Top -> Rear -> Bottom -> Front
else if (rotationdirection == "Down")
newDirs = getDirsFromFront("Top");// Front -> Bottom -> Rear -> Top -> Front
if (motion == RotationMotion::Right)
newDirs = getDirsFromFront(ProjDirection::Left);// Front -> Right -> Rear -> Left -> Front
else if (motion == RotationMotion::Left)
newDirs = getDirsFromFront(ProjDirection::Right);// Front -> Left -> Rear -> Right -> Front
else if (motion == RotationMotion::Up)
newDirs = getDirsFromFront(ProjDirection::Bottom);// Front -> Top -> Rear -> Bottom -> Front
else if (motion == RotationMotion::Down)
newDirs = getDirsFromFront(ProjDirection::Top);// Front -> Bottom -> Rear -> Top -> Front
Direction.setValue(newDirs.first);
XDirection.setValue(newDirs.second);
recompute();
}
void DrawViewPart::spin(const std::string& spindirection)
void DrawViewPart::spin(const SpinDirection& spindirection)
{
double angle;
if (spindirection == "CW")
if (spindirection == SpinDirection::CW)
angle = M_PI / 2.0;// Top -> Right -> Bottom -> Left -> Top
if (spindirection == "CCW")
if (spindirection == SpinDirection::CCW)
angle = -M_PI / 2.0;// Top -> Left -> Bottom -> Right -> Top
spin(angle);
@@ -1315,7 +1315,7 @@ void DrawViewPart::spin(double angle)
recompute();
}
std::pair<Base::Vector3d, Base::Vector3d> DrawViewPart::getDirsFromFront(std::string viewType)
std::pair<Base::Vector3d, Base::Vector3d> DrawViewPart::getDirsFromFront(ProjDirection viewType)
{
// Base::Console().Message("DVP::getDirsFromFront(%s)\n", viewType.c_str());
std::pair<Base::Vector3d, Base::Vector3d> result;
@@ -1335,60 +1335,52 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawViewPart::getDirsFromFront(std::st
double angle = M_PI / 2.0;//90*
if (viewType == "Right") {
if (viewType == ProjDirection::Right) {
newCS = anchorCS.Rotated(gUpAxis, angle);
projDir = dir2vec(newCS.Direction());
rotVec = dir2vec(newCS.XDirection());
}
else if (viewType == "Left") {
else if (viewType == ProjDirection::Left) {
newCS = anchorCS.Rotated(gUpAxis, -angle);
projDir = dir2vec(newCS.Direction());
rotVec = dir2vec(newCS.XDirection());
}
else if (viewType == "Top") {
else if (viewType == ProjDirection::Top) {
projDir = dir2vec(gYDir);
rotVec = dir2vec(gXDir);
}
else if (viewType == "Bottom") {
else if (viewType == ProjDirection::Bottom) {
projDir = dir2vec(gYDir.Reversed());
rotVec = dir2vec(gXDir);
}
else if (viewType == "Rear") {
else if (viewType == ProjDirection::Rear) {
projDir = dir2vec(gDir.Reversed());
rotVec = dir2vec(gXDir.Reversed());
}
else if (viewType == "FrontTopLeft") {
else if (viewType == ProjDirection::FrontTopLeft) {
gp_Dir newDir = gp_Dir(gp_Vec(gDir) - gp_Vec(gXDir) + gp_Vec(gYDir));
projDir = dir2vec(newDir);
gp_Dir newXDir = gp_Dir(gp_Vec(gXDir) + gp_Vec(gDir));
rotVec = dir2vec(newXDir);
}
else if (viewType == "FrontTopRight") {
else if (viewType == ProjDirection::FrontTopRight) {
gp_Dir newDir = gp_Dir(gp_Vec(gDir) + gp_Vec(gXDir) + gp_Vec(gYDir));
projDir = dir2vec(newDir);
gp_Dir newXDir = gp_Dir(gp_Vec(gXDir) - gp_Vec(gDir));
rotVec = dir2vec(newXDir);
}
else if (viewType == "FrontBottomLeft") {
else if (viewType == ProjDirection::FrontBottomLeft) {
gp_Dir newDir = gp_Dir(gp_Vec(gDir) - gp_Vec(gXDir) - gp_Vec(gYDir));
projDir = dir2vec(newDir);
gp_Dir newXDir = gp_Dir(gp_Vec(gXDir) + gp_Vec(gDir));
rotVec = dir2vec(newXDir);
}
else if (viewType == "FrontBottomRight") {
else if (viewType == ProjDirection::FrontBottomRight) {
gp_Dir newDir = gp_Dir(gp_Vec(gDir) + gp_Vec(gXDir) - gp_Vec(gYDir));
projDir = dir2vec(newDir);
gp_Dir newXDir = gp_Dir(gp_Vec(gXDir) - gp_Vec(gDir));
rotVec = dir2vec(newXDir);
}
else {
// not one of the standard view directions, so complain and use the values for "Front"
Base::Console().Error("DrawViewPart - %s unknown projection: %s\n", getNameInDocument(),
viewType.c_str());
Base::Vector3d dirAnch = Direction.getValue();
Base::Vector3d rotAnch = getXDirection();
return std::make_pair(dirAnch, rotAnch);
}
return std::make_pair(projDir, rotVec);
}

View File

@@ -77,9 +77,34 @@ class GeomFormat;
namespace TechDraw
{
class DrawViewSection;
enum class ProjDirection {
Front,
Left,
Right,
Rear,
Top,
Bottom,
FrontTopLeft,
FrontTopRight,
FrontBottomLeft,
FrontBottomRight
};
enum class RotationMotion {
Left,
Right,
Up,
Down
};
enum class SpinDirection {
CW,
CCW
};
class TechDrawExport DrawViewPart: public DrawView, public CosmeticExtension
{
PROPERTY_HEADER_WITH_EXTENSIONS(TechDraw::DrawViewPart);
@@ -172,10 +197,10 @@ public:
virtual Base::Vector3d getLegacyX(const Base::Vector3d& pt, const Base::Vector3d& axis,
const bool flip = true) const;
void rotate(const std::string& rotationdirection);
void spin(const std::string& spindirection);
void rotate(const RotationMotion& motion);
void spin(const SpinDirection& spindirection);
void spin(double val);
std::pair<Base::Vector3d, Base::Vector3d> getDirsFromFront(std::string viewType);
std::pair<Base::Vector3d, Base::Vector3d> getDirsFromFront(ProjDirection viewType);
Base::Vector3d dir2vec(gp_Dir d);
gp_Ax2 localVectorToCS(const Base::Vector3d localUnit) const;

View File

@@ -155,7 +155,7 @@ Base::Vector3d LandmarkDimension::projectPoint(const Base::Vector3d& pt, DrawVie
return DrawUtil::invertY(result);
}
int LandmarkDimension::getRefType() const
DrawViewDimension::RefType LandmarkDimension::getRefType() const
{
//TODO: need changes here when other reference dim types added
return DrawViewDimension::RefType::twoVertex;

View File

@@ -57,7 +57,7 @@ public:
return "TechDrawGui::ViewProviderDimension"; }
DrawViewPart* getViewPart() const override;
int getRefType() const override;
RefType getRefType() const override;
gp_Ax2 getProjAxis() const;

View File

@@ -176,9 +176,10 @@ int Preferences::lineGroup()
return getPreferenceGroup("Decorations")->GetInt("LineGroup", 3); // FC 0.70mm
}
int Preferences::balloonArrow()
ArrowType Preferences::balloonArrow()
{
return getPreferenceGroup("Decorations")->GetInt("BalloonArrow", 0);
int temp = getPreferenceGroup("Decorations")->GetInt("BalloonArrow", 0);
return static_cast<ArrowType>(temp);
}
double Preferences::balloonKinkLength()

View File

@@ -41,6 +41,7 @@ class Color;
namespace TechDraw
{
enum class ArrowType : int;
//getters for parameters used in multiple places.
class TechDrawExport Preferences
@@ -70,7 +71,7 @@ public:
static double groupSpaceX();
static double groupSpaceY();
static int balloonArrow();
static ArrowType balloonArrow();
static double balloonKinkLength();
static int balloonShape();