[TechDraw] CenterLine should use enums

This commit is contained in:
Benjamin Bræstrup Sayoc
2023-07-14 12:59:20 +02:00
committed by WandererFan
parent b892fee07f
commit 90f22b4eba
3 changed files with 32 additions and 32 deletions

View File

@@ -420,13 +420,13 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints(DrawViewPart
double Ymid = Ymin + Yspan;
Base::Vector3d p1, p2;
if (mode == 0) { //vertical
if (mode == CenterLine::VERTICAL) { //vertical
p1 = Base::Vector3d(Xmid, Ymax, 0.0);
p2 = Base::Vector3d(Xmid, Ymin, 0.0);
} else if (mode == 1) { //horizontal
} else if (mode == CenterLine::HORIZONTAL) { //horizontal
p1 = Base::Vector3d(Xmin, Ymid, 0.0);
p2 = Base::Vector3d(Xmax, Ymid, 0.0);
} else { //vert == 2 //aligned, but aligned doesn't make sense for face(s) bbox
} else { //vert == CenterLine::ALIGNED //aligned, but aligned doesn't make sense for face(s) bbox
Base::Console().Message("CL::calcEndPoints - aligned is not applicable to Face center lines\n");
p1 = Base::Vector3d(Xmid, Ymax, 0.0);
p2 = Base::Vector3d(Xmid, Ymin, 0.0);
@@ -538,13 +538,13 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Lines(DrawVi
}
//orientation
if (mode == 0 && !inhibitVertical) { //Vertical
if (mode == CenterLine::VERTICAL && !inhibitVertical) { //Vertical
p1.x = mid.x;
p2.x = mid.x;
} else if (mode == 1 && !inhibitHorizontal) { //Horizontal
} else if (mode == CenterLine::HORIZONTAL && !inhibitHorizontal) { //Horizontal
p1.y = mid.y;
p2.y = mid.y;
} else if (mode == 2) { //Aligned
} else if (mode == CenterLine::ALIGNED) { //Aligned
// no op
}
@@ -627,15 +627,15 @@ std::pair<Base::Vector3d, Base::Vector3d> CenterLine::calcEndPoints2Points(DrawV
inhibitVertical = true;
}
if (mode == 0 && !inhibitVertical) {
if (mode == CenterLine::VERTICAL && !inhibitVertical) {
//Vertical
v1.x = mid.x;
v2.x = mid.x;
} else if (mode == 1 && !inhibitHorizontal) {
} else if (mode == CenterLine::HORIZONTAL && !inhibitHorizontal) {
//Horizontal
v1.y = mid.y;
v2.y = mid.y;
} else if (mode == 2) { //Aligned
} else if (mode == CenterLine::ALIGNED) { //Aligned
// no op
}

View File

@@ -85,7 +85,7 @@ public:
static CenterLine* CenterLineBuilder(TechDraw::DrawViewPart* partFeat,
std::vector<std::string> subs,
int mode = 0,
int mode = CenterLine::VERTICAL,
bool flip = false);
TechDraw::BaseGeomPtr scaledGeometry(TechDraw::DrawViewPart* partFeat);
@@ -137,8 +137,8 @@ public:
std::vector<std::string> m_faces;
std::vector<std::string> m_edges;
std::vector<std::string> m_verts;
int m_type; // 0 - face, 1 - 2 line, 2 - 2 point
int m_mode; // 0 - vert/ 1 - horiz/ 2 - aligned
int m_type; // CLTYPE enum
int m_mode; // CLMODE enum
double m_hShift;
double m_vShift;
double m_rotate;

View File

@@ -61,8 +61,8 @@ TaskCenterLine::TaskCenterLine(TechDraw::DrawViewPart* partFeat,
m_btnOK(nullptr),
m_btnCancel(nullptr),
m_edgeName(edgeName),
m_type(0), // 0 - Face, 1 - Lines, 2 - Points
m_mode(0), // 0 - vertical, 1 - horizontal, 2 - aligned
m_type(CenterLine::FACE),
m_mode(CenterLine::VERTICAL),
m_editMode(editMode)
{
ui->setupUi(this);
@@ -97,8 +97,8 @@ TaskCenterLine::TaskCenterLine(TechDraw::DrawViewPart* partFeat,
m_subNames(subNames),
m_geomIndex(0),
m_cl(nullptr),
m_type(0), // 0 - Face, 1 - Lines, 2 - Points
m_mode(0), // 0 - vertical, 1 - horizontal, 2 - aligned
m_type(CenterLine::FACE),
m_mode(CenterLine::VERTICAL),
m_editMode(editMode)
{
//existence of page and feature are checked by isActive method of calling command
@@ -107,11 +107,11 @@ TaskCenterLine::TaskCenterLine(TechDraw::DrawViewPart* partFeat,
std::string check = subNames.front();
std::string geomType = TechDraw::DrawUtil::getGeomTypeFromName(check);
if (geomType == "Face") {
m_type = 0;
m_type = CenterLine::FACE;
} else if (geomType == "Edge") {
m_type = 1;
m_type = CenterLine::EDGE;
} else if (geomType == "Vertex") {
m_type = 2;
m_type = CenterLine::VERTEX;
} else {
Base::Console().Error("TaskCenterLine - unknown geometry type: %s. Can not proceed.\n", geomType.c_str());
return;
@@ -143,7 +143,7 @@ void TaskCenterLine::changeEvent(QEvent *event)
void TaskCenterLine::setUiConnect()
{
// first enabling/disabling
if (m_type == 0) // if face, then aligned is not possible
if (m_type == CenterLine::FACE) // if face, then aligned is not possible
ui->rbAligned->setEnabled(false);
else
ui->rbAligned->setEnabled(true);
@@ -192,11 +192,11 @@ void TaskCenterLine::setUiPrimary()
int precision = Base::UnitsApi::getDecimals();
ui->qsbRotate->setDecimals(precision);
if (m_type == 1) {
if (m_type == CenterLine::EDGE) {
int orientation = checkPathologicalEdges(m_mode);
setUiOrientation(orientation);
}
if (m_type == 2) {
if (m_type == CenterLine::VERTEX) {
int orientation = checkPathologicalVertices(m_mode);
setUiOrientation(orientation);
}
@@ -218,11 +218,11 @@ void TaskCenterLine::setUiEdit()
ui->rbVertical->setChecked(false);
ui->rbHorizontal->setChecked(false);
ui->rbAligned->setChecked(false);
if (m_cl->m_mode == 0)
if (m_cl->m_mode == CenterLine::VERTICAL)
ui->rbVertical->setChecked(true);
else if (m_cl->m_mode == 1)
else if (m_cl->m_mode == CenterLine::HORIZONTAL)
ui->rbHorizontal->setChecked(true);
else if (m_cl->m_mode ==2)
else if (m_cl->m_mode == CenterLine::ALIGNED)
ui->rbAligned->setChecked(true);
Base::Quantity qVal;
@@ -255,7 +255,7 @@ void TaskCenterLine::onOrientationChanged()
m_cl->m_mode = CenterLine::CLMODE::ALIGNED;
// for centerlines between 2 lines we cannot just recompute
// because the new orientation might lead to an invalid centerline
if (m_type == 1)
if (m_type == CenterLine::EDGE)
updateOrientation();
else
m_partFeat->recomputeFeature();
@@ -337,7 +337,7 @@ void TaskCenterLine::onStyleChanged()
// between 2 horizontal edges)
int TaskCenterLine::checkPathologicalEdges(int inMode)
{
if (m_type != 1) {
if (m_type != CenterLine::EDGE) {
// not an edge based centerline, this doesn't apply
return inMode;
}
@@ -367,7 +367,7 @@ int TaskCenterLine::checkPathologicalEdges(int inMode)
// between 2 vertices aligned vertically)
int TaskCenterLine::checkPathologicalVertices(int inMode)
{
if (m_type != 2) {
if (m_type != CenterLine::VERTEX) {
// not a vertex based centerline, this doesn't apply
return inMode;
}
@@ -397,10 +397,10 @@ void TaskCenterLine::createCenterLine()
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create CenterLine"));
// check for illogical parameters
if (m_type == 1) {
if (m_type == CenterLine::EDGE) {
// between lines
m_mode = checkPathologicalEdges(m_mode);
} else if (m_type == 2) {
} else if (m_type == CenterLine::VERTEX) {
// between points
m_mode = checkPathologicalVertices(m_mode);
}
@@ -448,14 +448,14 @@ void TaskCenterLine::updateOrientation()
// https://forum.freecad.org/viewtopic.php?f=35&t=44255&start=20#p503220
// The centerline creation can fail if m_type is edge and both selected edges are vertical or horizontal.
int orientation = m_cl->m_mode;
if (m_type == 1) {
if (m_type == CenterLine::EDGE) {
// between lines
if (!m_edgeName.empty() && !m_cl->m_edges.empty()) {
// we have an existing centerline, not a freshly created one, and it is a centerline between edges
m_subNames = m_cl->m_edges;
orientation = checkPathologicalEdges(orientation);
}
} else if (m_type == 2) {
} else if (m_type == CenterLine::VERTEX) {
// between points
if (!m_edgeName.empty() && !m_cl->m_verts.empty()) {
// we have an existing centerline, not a freshly created one, and it is a centerline between points