Refactor code in DrawViewDimension::getRefType() shorter and simpler. No functional change except subelement sizes > 3 are supported, even though they are not supposed to happen.

This commit is contained in:
Aapo
2020-11-18 21:54:52 +02:00
committed by wwmayer
parent bfdffb50be
commit 31d6c7528d
3 changed files with 16 additions and 61 deletions

View File

@@ -252,7 +252,7 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void)
Type.isValue("DistanceY") ) {
if (getRefType() == oneEdge) {
m_linearPoints = getPointsOneEdge();
}else if (getRefType() == twoEdge) {
} else if (getRefType() == twoEdge) {
m_linearPoints = getPointsTwoEdges();
} else if (getRefType() == twoVertex) {
m_linearPoints = getPointsTwoVerts();
@@ -916,64 +916,28 @@ DrawViewPart* DrawViewDimension::getViewPart() const
int DrawViewDimension::getRefType() const
{
int refType = invalidRef;
const std::vector<std::string> &subElements = References2D.getSubValues();
if (subElements.size() == 1) {
refType = getRefType1(subElements[0]);
} else if (subElements.size() == 2) {
refType = getRefType2(subElements[0],subElements[1]);
} else if (subElements.size() == 3) {
refType = getRefType3(subElements[0],subElements[1],subElements[2]);
}
return refType;
return getRefTypeSubElements(References2D.getSubValues());
}
//static
int DrawViewDimension::getRefType1(const std::string g1)
int DrawViewDimension::getRefTypeSubElements(const std::vector<std::string> &subElements)
{
int refType = invalidRef;
if (DrawUtil::getGeomTypeFromName(g1) == "Edge") {
refType = oneEdge;
}
return refType;
}
int refEdges = 0, refVertices = 0;
//static
int DrawViewDimension::getRefType2(const std::string g1, const std::string g2)
{
int refType = invalidRef;
if ((DrawUtil::getGeomTypeFromName(g1) == "Edge") &&
(DrawUtil::getGeomTypeFromName(g2) == "Edge")) {
refType = twoEdge;
} else if ((DrawUtil::getGeomTypeFromName(g1) == "Vertex") &&
(DrawUtil::getGeomTypeFromName(g2) == "Vertex")) {
refType = twoVertex;
} else if (((DrawUtil::getGeomTypeFromName(g1) == "Vertex") &&
(DrawUtil::getGeomTypeFromName(g2) == "Edge")) ||
((DrawUtil::getGeomTypeFromName(g1) == "Edge") &&
(DrawUtil::getGeomTypeFromName(g2) == "Vertex")) ) {
refType = vertexEdge;
for (const auto& se: subElements) {
if (DrawUtil::getGeomTypeFromName(se) == "Vertex") { refVertices++; }
if (DrawUtil::getGeomTypeFromName(se) == "Edge") { refEdges++; }
}
//} else add different types here - Vertex-Face, ...
if (refEdges == 0 && refVertices == 2) { refType = twoVertex; }
if (refEdges == 0 && refVertices == 3) { refType = threeVertex; }
if (refEdges == 1 && refVertices == 0) { refType = oneEdge; }
if (refEdges == 1 && refVertices == 1) { refType = vertexEdge; }
if (refEdges == 2 && refVertices == 0) { refType = twoEdge; }
return refType;
}
int DrawViewDimension::getRefType3(const std::string g1,
const std::string g2,
const std::string g3)
{
int refType = invalidRef;
if ((DrawUtil::getGeomTypeFromName(g1) == "Vertex") &&
(DrawUtil::getGeomTypeFromName(g2) == "Vertex") &&
(DrawUtil::getGeomTypeFromName(g3) == "Vertex") ) {
refType = threeVertex;
}
return refType;
}
//! validate 2D references - only checks if the target exists
bool DrawViewDimension::checkReferences2D() const
{