Skip to content

Commit

Permalink
[Sketcher] Use modernized geometry type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
AjinkyaDahale committed Aug 21, 2024
1 parent d0c84eb commit 503b324
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/Mod/Sketcher/Gui/CommandSketcherTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ void SketcherCopy::activate(SketcherCopy::Op op)
int GeoId;
Sketcher::PointPos PosId;
Obj->getGeoVertexIndex(VtId, GeoId, PosId);
if (Obj->getGeometry(GeoId)->getTypeId() != Part::GeomPoint::getClassTypeId()) {
if (!Obj->getGeometry(GeoId)->is<Part::GeomPoint>()) {
LastGeoId = GeoId;
LastPointPos = PosId;
}
Expand Down Expand Up @@ -1990,7 +1990,7 @@ void CmdSketcherRectangularArray::activated(int iMsg)
int GeoId;
Sketcher::PointPos PosId;
Obj->getGeoVertexIndex(VtId, GeoId, PosId);
if (Obj->getGeometry(GeoId)->getTypeId() != Part::GeomPoint::getClassTypeId()) {
if (!Obj->getGeometry(GeoId)->is<Part::GeomPoint>()) {
LastGeoId = GeoId;
LastPointPos = PosId;
}
Expand Down
26 changes: 11 additions & 15 deletions src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -774,21 +774,19 @@ class DrawSketchDefaultHandler: public DrawSketchHandler,

// ellipse tangency support using construction elements (lines)
if (geom1 && geom2
&& (geom1->getTypeId() == Part::GeomEllipse::getClassTypeId()
|| geom2->getTypeId() == Part::GeomEllipse::getClassTypeId())) {

if (geom1->getTypeId() != Part::GeomEllipse::getClassTypeId()) {
&& (geom1->is<Part::GeomEllipse>() || geom2->is<Part::GeomEllipse>())) {
if (!geom1->is<Part::GeomEllipse>()) {
std::swap(geoId1, geoId2);
}

// geoId1 is the ellipse
geom1 = Obj->getGeometry(geoId1);
geom2 = Obj->getGeometry(geoId2);

if (geom2->getTypeId() == Part::GeomEllipse::getClassTypeId()
|| geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()
|| geom2->getTypeId() == Part::GeomCircle::getClassTypeId()
|| geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) {
if (geom2->is<Part::GeomEllipse>()
|| geom2->is<Part::GeomArcOfEllipse>()
|| geom2->is<Part::GeomCircle>()
|| geom2->is<Part::GeomArcOfCircle>()) {
// in all these cases an intermediate element is needed
// makeTangentToEllipseviaNewPoint(
// Obj,
Expand All @@ -801,21 +799,19 @@ class DrawSketchDefaultHandler: public DrawSketchHandler,

// arc of ellipse tangency support using external elements
if (geom1 && geom2
&& (geom1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()
|| geom2->getTypeId()
== Part::GeomArcOfEllipse::getClassTypeId())) {
&& (geom1->is<Part::GeomArcOfEllipse>()
|| geom2->is<Part::GeomArcOfEllipse>())) {

if (geom1->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId()) {
if (!geom1->is<Part::GeomArcOfEllipse>()) {
std::swap(geoId1, geoId2);
}

// geoId1 is the arc of ellipse
geom1 = Obj->getGeometry(geoId1);
geom2 = Obj->getGeometry(geoId2);

if (geom2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()
|| geom2->getTypeId() == Part::GeomCircle::getClassTypeId()
|| geom2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) {
if (geom2->is<Part::GeomArcOfEllipse>() || geom2->is<Part::GeomCircle>()
|| geom2->is<Part::GeomArcOfCircle>()) {
// in all these cases an intermediate element is needed
// makeTangentToArcOfEllipseviaNewPoint(
// Obj,
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Sketcher/Gui/DrawSketchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ void DrawSketchHandler::createAutoConstraints(const std::vector<AutoConstraint>&
if (geom1 && geom2
&& (geom1->is<Part::GeomEllipse>() || geom2->is<Part::GeomEllipse>())) {

if (geom1->getTypeId() != Part::GeomEllipse::getClassTypeId()) {
if (!geom1->is<Part::GeomEllipse>()) {
std::swap(geoId1, geoId2);
}

Expand All @@ -849,7 +849,7 @@ void DrawSketchHandler::createAutoConstraints(const std::vector<AutoConstraint>&
&& (geom1->is<Part::GeomArcOfEllipse>()
|| geom2->is<Part::GeomArcOfEllipse>())) {

if (geom1->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId()) {
if (!geom1->is<Part::GeomArcOfEllipse>()) {
std::swap(geoId1, geoId2);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Mod/Sketcher/Gui/DrawSketchHandlerEllipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ class DrawSketchHandlerEllipse: public DrawSketchHandlerEllipseBase

// in the exceptional event that this may lead to a circle, do not
// exposeInternalGeometry
if (!ShapeGeometry.empty()
&& ShapeGeometry[0]->getTypeId() == Part::GeomEllipse::getClassTypeId()) {
if (!ShapeGeometry.empty() && ShapeGeometry[0]->is<Part::GeomEllipse>()) {
Gui::cmdAppObjectArgs(sketchgui->getObject(),
"exposeInternalGeometry(%d)",
ellipseGeoId);
Expand Down Expand Up @@ -713,8 +712,7 @@ void DSHEllipseController::addConstraints()

using namespace Sketcher;

if (!handler->ShapeGeometry.empty()
&& handler->ShapeGeometry[0]->getTypeId() == Part::GeomEllipse::getClassTypeId()) {
if (!handler->ShapeGeometry.empty() && handler->ShapeGeometry[0]->is<Part::GeomEllipse>()) {

int firstLine = firstCurve + 1; // this is always the major axis
int secondLine = firstCurve + 2; // this is always the minor axis
Expand Down
6 changes: 2 additions & 4 deletions src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,7 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol

Base::Vector3d midpos1, dir1, norm1;
Base::Vector3d midpos2, dir2, norm2;
if (geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId()
|| geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) {
if (!geo1->is<Part::GeomLineSegment>() || !geo2->is<Part::GeomLineSegment>()) {
if (Constr->Type == Equal) {
double r1a = 0, r1b = 0, r2a = 0, r2b = 0;
double angle1,
Expand Down Expand Up @@ -731,8 +730,7 @@ void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geol


if (geo2->is<Part::GeomEllipse>() || geo2->is<Part::GeomArcOfEllipse>()
|| geo2->getTypeId()
== Part::GeomArcOfHyperbola::getClassTypeId()) {
|| geo2->is<Part::GeomArcOfHyperbola>()) {

Base::Vector3d majDir, minDir, rvec;
majDir = Base::Vector3d(cos(angle2),
Expand Down

0 comments on commit 503b324

Please sign in to comment.