Remove magic number and hard type enums in DrawViewDimension.h
- Remove currently present magic numbers - Hard type enums, so magic numbers can no longer be introduced. We don't want people to introduce magic numbers.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user