Skip to content

Commit

Permalink
[TechDraw] Return logic simplification (FreeCAD#16504)
Browse files Browse the repository at this point in the history
* [TechDraw] AppTechDrawPy.cpp return logic simplification

* [TechDraw] CosmeticExtension.cpp return logic simplification

* [TechDraw] DrawBrokenView.cpp return logic simplification

* [TechDraw] HatchLine.cpp return logic simplification

* [TechDraw] LineGenerator.cpp return logic simplification

* [TechDraw] Preferences.cpp return logic simplification

* [TechDraw] ShapeExtractor.cpp return logic simplification

* [TechDraw] MDIViewPage.cpp return logic simplification

* [TechDraw] QGILeaderLine.cpp return logic simplification

* [TechDraw] QGIRichAnno.cpp return logic simplification

* [TechDraw] QGTracker.cpp return logic simplification
  • Loading branch information
benj5378 authored Nov 18, 2024
1 parent f9ba94c commit cdb9276
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 64 deletions.
3 changes: 1 addition & 2 deletions src/Mod/TechDraw/App/AppTechDrawPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,7 @@ class Module : public Py::ExtensionModule<Module>
const TopoDS_Shape& shape = pShape->getTopoShapePtr()->getShape();
Base::Vector3d dir = static_cast<Base::VectorPy*>(pcObjDir)->value();
Base::Vector3d centroid = ShapeUtils::findCentroidVec(shape, dir);
PyObject* result = nullptr;
result = new Base::VectorPy(new Base::Vector3d(centroid));
PyObject* result = new Base::VectorPy(new Base::Vector3d(centroid));
return Py::asObject(result);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Mod/TechDraw/App/CosmeticExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ std::string CosmeticExtension::addCosmeticVertex(const Base::Vector3d& pos, bool
TechDraw::CosmeticVertex* cv = new TechDraw::CosmeticVertex(tempPos);
verts.push_back(cv);
CosmeticVertexes.setValues(verts);
std::string result = cv->getTagAsString();
return result;
return cv->getTagAsString();
}

/// retrieve a cosmetic vertex by unique id
Expand Down
5 changes: 1 addition & 4 deletions src/Mod/TechDraw/App/DrawBrokenView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,8 @@ TopoDS_Shape DrawBrokenView::apply1Break(const App::DocumentObject& breakObj, co
TopoDS_Shape DrawBrokenView::compressShape(const TopoDS_Shape& shapeToCompress) const
{
// Base::Console().Message("DBV::compressShape()\n");
TopoDS_Shape result;
TopoDS_Shape compressed = compressHorizontal(shapeToCompress);
result = compressVertical(compressed);

return result;
return compressVertical(compressed);
}

//! move the broken pieces in the input shape "right" to close up the removed areas.
Expand Down
16 changes: 6 additions & 10 deletions src/Mod/TechDraw/App/HatchLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,19 @@ bool LineSet::isDashed()
//! calculates the apparent start point (ie start of overlay line) for dashed lines
Base::Vector3d LineSet::calcApparentStart(TechDraw::BaseGeomPtr g)
{
Base::Vector3d result;
Base::Vector3d start(g->getStartPoint().x, g->getStartPoint().y, 0.0);
double angle = getPATLineSpec().getAngle();
if (angle == 0.0) { //horizontal
result = Base::Vector3d(getMinX(), start.y, 0.0);
return Base::Vector3d(getMinX(), start.y, 0.0);
} else if ((angle == 90.0) ||
(angle == -90.0)) { //vertical
result = Base::Vector3d(start.x, getMinY(), 0.0);
return Base::Vector3d(start.x, getMinY(), 0.0);
} else {
double slope = getPATLineSpec().getSlope();
double y = getMinY();
double x = ((y - start.y) / slope) + start.x;
result = Base::Vector3d(x, y,0);
return Base::Vector3d(x, y,0);
}
return result;
}

Base::Vector3d LineSet::getUnitDir()
Expand Down Expand Up @@ -132,20 +130,18 @@ Base::Vector3d LineSet::getUnitOrtho()

Base::Vector3d LineSet::findAtomStart()
{
Base::Vector3d result;
Base::Vector3d origin = getOrigin();
double angle = getAngle();
if (angle == 0.0) {
result = Base::Vector3d(getMinX(), origin.y, 0.0);
return Base::Vector3d(getMinX(), origin.y, 0.0);
} else if ( (angle == 90.0) ||
(angle == -90.0) ) {
result = Base::Vector3d(origin.x, getMinY(), 0.0);
return Base::Vector3d(origin.x, getMinY(), 0.0);
} else {
double minY = getMinY();
double x = origin.x - (origin.y - minY)/getSlope();
result = Base::Vector3d(x, minY, 0.0);
return Base::Vector3d(x, minY, 0.0);
}
return result;
}

Base::Vector3d LineSet::getPatternStartPoint(TechDraw::BaseGeomPtr g, double &offset, double scale)
Expand Down
22 changes: 7 additions & 15 deletions src/Mod/TechDraw/App/LineGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ int LineGenerator::fromQtStyle(Qt::PenStyle style)
{
// Base::Console().Message("DLG::fromQtStyle(%d)\n", style);

int result { 0 };
// the 4 standard Qt::PenStyles and ISO128 equivalents
int dashed = 2;
int dotted = 7;
Expand All @@ -199,29 +198,22 @@ int LineGenerator::fromQtStyle(Qt::PenStyle style)
switch (style) {
case Qt::NoPen:
case Qt::SolidLine:
result = 1;
break;
return 1;
case Qt::DashLine:
result = dashed;
break;
return dashed;
case Qt::DotLine:
result = dotted;
break;
return dotted;
case Qt::DashDotLine:
result = dashDot;
break;
return dashDot;
case Qt::DashDotDotLine:
result = dashDotDot;
break;
return dashDotDot;
case Qt::CustomDashLine:
// not sure what to do here. we would have to match the custom pattern
// to the patterns of the ISO lines and set the dash pattern accordingly.
result = 2;
break;
return 2;
default:
result = 0;
return 0;
}
return result;
}


Expand Down
15 changes: 5 additions & 10 deletions src/Mod/TechDraw/App/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,21 +549,16 @@ std::string Preferences::currentElementDefFile()
int Preferences::LineCapStyle()
{
int currentIndex = LineCapIndex();
int result{0x20};
switch (currentIndex) {
switch (currentIndex) {
case 0:
result = static_cast<Qt::PenCapStyle>(0x20); //round;
break;
return static_cast<Qt::PenCapStyle>(0x20); //round;
case 1:
result = static_cast<Qt::PenCapStyle>(0x10); //square;
break;
return static_cast<Qt::PenCapStyle>(0x10); //square;
case 2:
result = static_cast<Qt::PenCapStyle>(0x00); //flat
break;
return static_cast<Qt::PenCapStyle>(0x00); //flat
default:
result = static_cast<Qt::PenCapStyle>(0x20);
return static_cast<Qt::PenCapStyle>(0x20);
}
return result;
}

//! returns the line cap index without conversion to a Qt::PenCapStyle
Expand Down
11 changes: 5 additions & 6 deletions src/Mod/TechDraw/App/ShapeExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,18 +421,17 @@ bool ShapeExtractor::is2dObject(const App::DocumentObject* obj)
// just these for now
bool ShapeExtractor::isEdgeType(const App::DocumentObject* obj)
{
bool result = false;
Base::Type t = obj->getTypeId();
if (t.isDerivedFrom(Part::Line::getClassTypeId()) ) {
result = true;
return true;
} else if (t.isDerivedFrom(Part::Circle::getClassTypeId())) {
result = true;
return true;
} else if (t.isDerivedFrom(Part::Ellipse::getClassTypeId())) {
result = true;
return true;
} else if (t.isDerivedFrom(Part::RegularPolygon::getClassTypeId())) {
result = true;
return true;
}
return result;
return false;
}

bool ShapeExtractor::isPointType(const App::DocumentObject* obj)
Expand Down
4 changes: 1 addition & 3 deletions src/Mod/TechDraw/Gui/MDIViewPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,6 @@ void MDIViewPage::removeUnselectedTreeSelection(QList<QGraphicsItem*> sceneSelec
bool MDIViewPage::compareSelections(std::vector<Gui::SelectionObject> treeSel,
QList<QGraphicsItem*> sceneSel)
{
bool result = true;

if (treeSel.empty() && sceneSel.empty()) {
return true;
}
Expand Down Expand Up @@ -1141,7 +1139,7 @@ bool MDIViewPage::compareSelections(std::vector<Gui::SelectionObject> treeSel,
return false;
}

return result;
return true;
}

///////////////////end Selection Routines //////////////////////
Expand Down
8 changes: 3 additions & 5 deletions src/Mod/TechDraw/Gui/QGILeaderLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,7 @@ double QGILeaderLine::getLineWidth()

TechDraw::DrawLeaderLine* QGILeaderLine::getLeaderFeature()
{
TechDraw::DrawLeaderLine* result = static_cast<TechDraw::DrawLeaderLine*>(getViewObject());
return result;
return static_cast<TechDraw::DrawLeaderLine*>(getViewObject());
}

double QGILeaderLine::getEdgeFuzz() const
Expand Down Expand Up @@ -637,12 +636,11 @@ void QGILeaderLine::paint(QPainter* painter, const QStyleOptionGraphicsItem* opt

bool QGILeaderLine::useOldCoords() const
{
bool result = false;
auto vp = dynamic_cast<ViewProviderLeader*>(getViewProvider(getViewObject()));
if (vp) {
result = vp->UseOldCoords.getValue();
return vp->UseOldCoords.getValue();
}
return result;
return false;
}


Expand Down
4 changes: 1 addition & 3 deletions src/Mod/TechDraw/Gui/QGIRichAnno.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,7 @@ QString QGIRichAnno::convertTextSizes(const QString& inHtml) const

TechDraw::DrawRichAnno* QGIRichAnno::getFeature()
{
TechDraw::DrawRichAnno* result =
static_cast<TechDraw::DrawRichAnno*>(getViewObject());
return result;
return static_cast<TechDraw::DrawRichAnno*>(getViewObject());
}


Expand Down
5 changes: 1 addition & 4 deletions src/Mod/TechDraw/Gui/QGTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,7 @@ QColor QGTracker::getTrackerColor()

double QGTracker::getTrackerWeight()
{
double result = 1.0;
result = Preferences::getPreferenceGroup("Tracker")->GetFloat("TrackerWeight", 4.0);

return result;
return Preferences::getPreferenceGroup("Tracker")->GetFloat("TrackerWeight", 4.0);
}

#include <Mod/TechDraw/Gui/moc_QGTracker.cpp>

Check failure on line 489 in src/Mod/TechDraw/Gui/QGTracker.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

'Mod/TechDraw/Gui/moc_QGTracker.cpp' file not found [clang-diagnostic-error]

0 comments on commit cdb9276

Please sign in to comment.