From e4f0ddad84a0afbadfc5f64b730d27e8321a96a4 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 17 Aug 2016 10:43:58 +0200 Subject: [PATCH] Coverity issues: check return value of dynamic_cast or replace it with static_cast --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 2 +- src/Mod/Sketcher/Gui/TaskSketcherElements.cpp | 2 +- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 181 +++++++++--------- 3 files changed, 93 insertions(+), 92 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index b772baa0be84..63aeb720067a 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -1659,7 +1659,7 @@ void CmdSketcherConstrainPerpendicular::activated(int iMsg) const std::vector &SubNames = selection[0].getSubNames(); Sketcher::SketchObject* Obj = dynamic_cast(selection[0].getObject()); - if (SubNames.size() != 2 && SubNames.size() != 3) { + if (!Obj || (SubNames.size() != 2 && SubNames.size() != 3)) { strError = QObject::tr("Wrong number of selected objects!","perpendicular constraint"); if (!strError.isEmpty()) strError.append(QString::fromLatin1("\n\n")); QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index 07b692b3e542..f1331c9ba7c5 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -562,7 +562,7 @@ void TaskSketcherElements::on_listWidgetElements_itemSelectionChanged(void) void TaskSketcherElements::on_listWidgetElements_itemEntered(QListWidgetItem *item) { ElementItem *it = dynamic_cast(item); - if (!item) return; + if (!it) return; Gui::Selection().rmvPreselect(); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index abf06ae2c029..6002b71fdaf3 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -1200,7 +1200,7 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo p1 = getSketchObject()->getSolvedSketch().getPoint(Constr->First, Constr->FirstPos); const Part::Geometry *geo = GeoById(geomlist, Constr->Second); if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); + const Part::GeomLineSegment *lineSeg = static_cast(geo); Base::Vector3d l2p1 = lineSeg->getStartPoint(); Base::Vector3d l2p2 = lineSeg->getEndPoint(); // calculate the projection of p1 onto line2 @@ -1213,11 +1213,11 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo } else if (Constr->First != Constraint::GeoUndef) { const Part::Geometry *geo = GeoById(geomlist, Constr->First); if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); + const Part::GeomLineSegment *lineSeg = static_cast(geo); p1 = lineSeg->getStartPoint(); p2 = lineSeg->getEndPoint(); } else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = dynamic_cast(geo); + const Part::GeomArcOfCircle *arc = static_cast(geo); double radius = arc->getRadius(); p1 = arc->getCenter(); double angle = Constr->LabelPosition; @@ -1233,7 +1233,7 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo p2 = p1 + radius * Base::Vector3d(cos(angle),sin(angle),0.); } else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle = dynamic_cast(geo); + const Part::GeomCircle *circle = static_cast(geo); double radius = circle->getRadius(); p1 = circle->getCenter(); Base::Vector3d tmpDir = Base::Vector3d(toPos.fX, toPos.fY, 0) - p1; @@ -1279,8 +1279,8 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo if (geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId() || geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) return; - const Part::GeomLineSegment *lineSeg1 = dynamic_cast(geo1); - const Part::GeomLineSegment *lineSeg2 = dynamic_cast(geo2); + const Part::GeomLineSegment *lineSeg1 = static_cast(geo1); + const Part::GeomLineSegment *lineSeg2 = static_cast(geo2); bool flip1 = (Constr->FirstPos == end); bool flip2 = (Constr->SecondPos == end); @@ -1312,11 +1312,11 @@ void ViewProviderSketch::moveConstraint(int constNum, const Base::Vector2D &toPo } else if (Constr->First != Constraint::GeoUndef) { // line/arc angle const Part::Geometry *geo = GeoById(geomlist, Constr->First); if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); + const Part::GeomLineSegment *lineSeg = static_cast(geo); p0 = (lineSeg->getEndPoint()+lineSeg->getStartPoint())/2; } else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = dynamic_cast(geo); + const Part::GeomArcOfCircle *arc = static_cast(geo); p0 = arc->getCenter(); } else { @@ -1842,7 +1842,8 @@ void ViewProviderSketch::centerSelection() for (int i=0; i < edit->constrGroup->getNumChildren(); i++) { if (edit->SelConstraintSet.find(i) != edit->SelConstraintSet.end()) { SoSeparator *sep = dynamic_cast(edit->constrGroup->getChild(i)); - group->addChild(sep); + if (sep) + group->addChild(sep); } } @@ -1902,7 +1903,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & if ((*it)->getTypeId() == Part::GeomPoint::getClassTypeId()) { // ----- Check if single point lies inside box selection -----/ - const Part::GeomPoint *point = dynamic_cast(*it); + const Part::GeomPoint *point = static_cast(*it); Plm.multVec(point->getPoint(), pnt0); pnt0 = proj(pnt0); VertexId += 1; @@ -1915,7 +1916,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & } else if ((*it)->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { // ----- Check if line segment lies inside box selection -----/ - const Part::GeomLineSegment *lineSeg = dynamic_cast(*it); + const Part::GeomLineSegment *lineSeg = static_cast(*it); Plm.multVec(lineSeg->getStartPoint(), pnt1); Plm.multVec(lineSeg->getEndPoint(), pnt2); pnt1 = proj(pnt1); @@ -1944,7 +1945,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & } else if ((*it)->getTypeId() == Part::GeomCircle::getClassTypeId()) { // ----- Check if circle lies inside box selection -----/ - const Part::GeomCircle *circle = dynamic_cast(*it); + const Part::GeomCircle *circle = static_cast(*it); pnt0 = circle->getCenter(); VertexId += 1; @@ -1986,7 +1987,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & } } else if ((*it)->getTypeId() == Part::GeomEllipse::getClassTypeId()) { // ----- Check if circle lies inside box selection -----/ - const Part::GeomEllipse *ellipse = dynamic_cast(*it); + const Part::GeomEllipse *ellipse = static_cast(*it); pnt0 = ellipse->getCenter(); VertexId += 1; @@ -2030,7 +2031,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & } else if ((*it)->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { // Check if arc lies inside box selection - const Part::GeomArcOfCircle *aoc = dynamic_cast(*it); + const Part::GeomArcOfCircle *aoc = static_cast(*it); pnt0 = aoc->getStartPoint(/*emulateCCW=*/true); pnt1 = aoc->getEndPoint(/*emulateCCW=*/true); @@ -2101,7 +2102,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & } else if ((*it)->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { // Check if arc lies inside box selection - const Part::GeomArcOfEllipse *aoe = dynamic_cast(*it); + const Part::GeomArcOfEllipse *aoe = static_cast(*it); pnt0 = aoe->getStartPoint(/*emulateCCW=*/true); pnt1 = aoe->getEndPoint(/*emulateCCW=*/true); @@ -2172,7 +2173,7 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s &startPos, const SbVec2s & } } else if ((*it)->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { - const Part::GeomBSplineCurve *spline = dynamic_cast(*it); + const Part::GeomBSplineCurve *spline = static_cast(*it); std::vector poles = spline->getPoles(); VertexId += poles.size(); // TODO @@ -2308,7 +2309,7 @@ void ViewProviderSketch::updateColor(void) // colors of the constraints for (int i=0; i < edit->constrGroup->getNumChildren(); i++) { - SoSeparator *s = dynamic_cast(edit->constrGroup->getChild(i)); + SoSeparator *s = static_cast(edit->constrGroup->getChild(i)); // Check Constraint Type Sketcher::Constraint* constraint = getSketchObject()->Constraints.getValues()[i]; @@ -2326,12 +2327,12 @@ void ViewProviderSketch::updateColor(void) SoMaterial *m = 0; if (!hasDatumLabel && type != Sketcher::Coincident && type != Sketcher::InternalAlignment) { hasMaterial = true; - m = dynamic_cast(s->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); + m = static_cast(s->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); } if (edit->SelConstraintSet.find(i) != edit->SelConstraintSet.end()) { if (hasDatumLabel) { - SoDatumLabel *l = dynamic_cast(s->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); + SoDatumLabel *l = static_cast(s->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); l->textColor = SelectColor; } else if (hasMaterial) { m->diffuseColor = SelectColor; @@ -2371,7 +2372,7 @@ void ViewProviderSketch::updateColor(void) } } else if (edit->PreselectConstraintSet.count(i)) { if (hasDatumLabel) { - SoDatumLabel *l = dynamic_cast(s->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); + SoDatumLabel *l = static_cast(s->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); l->textColor = PreselectColor; } else if (hasMaterial) { m->diffuseColor = PreselectColor; @@ -2379,7 +2380,7 @@ void ViewProviderSketch::updateColor(void) } else { if (hasDatumLabel) { - SoDatumLabel *l = dynamic_cast(s->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); + SoDatumLabel *l = static_cast(s->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); l->textColor = constraint->isDriving?ConstrDimColor:NonDrivingConstrDimColor; } else if (hasMaterial) { m->diffuseColor = constraint->isDriving?ConstrDimColor:NonDrivingConstrDimColor; @@ -2986,11 +2987,11 @@ void ViewProviderSketch::draw(bool temp) if (GeoId >= intGeoCount) GeoId = -extGeoCount; if ((*it)->getTypeId() == Part::GeomPoint::getClassTypeId()) { // add a point - const Part::GeomPoint *point = dynamic_cast(*it); + const Part::GeomPoint *point = static_cast(*it); Points.push_back(point->getPoint()); } else if ((*it)->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { // add a line - const Part::GeomLineSegment *lineSeg = dynamic_cast(*it); + const Part::GeomLineSegment *lineSeg = static_cast(*it); // create the definition struct for that geom Coords.push_back(lineSeg->getStartPoint()); Coords.push_back(lineSeg->getEndPoint()); @@ -3000,7 +3001,7 @@ void ViewProviderSketch::draw(bool temp) edit->CurvIdToGeoId.push_back(GeoId); } else if ((*it)->getTypeId() == Part::GeomCircle::getClassTypeId()) { // add a circle - const Part::GeomCircle *circle = dynamic_cast(*it); + const Part::GeomCircle *circle = static_cast(*it); Handle_Geom_Circle curve = Handle_Geom_Circle::DownCast(circle->handle()); int countSegments = 50; @@ -3019,7 +3020,7 @@ void ViewProviderSketch::draw(bool temp) Points.push_back(center); } else if ((*it)->getTypeId() == Part::GeomEllipse::getClassTypeId()) { // add an ellipse - const Part::GeomEllipse *ellipse = dynamic_cast(*it); + const Part::GeomEllipse *ellipse = static_cast(*it); Handle_Geom_Ellipse curve = Handle_Geom_Ellipse::DownCast(ellipse->handle()); int countSegments = 50; @@ -3038,7 +3039,7 @@ void ViewProviderSketch::draw(bool temp) Points.push_back(center); } else if ((*it)->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { // add an arc - const Part::GeomArcOfCircle *arc = dynamic_cast(*it); + const Part::GeomArcOfCircle *arc = static_cast(*it); Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(arc->handle()); double startangle, endangle; @@ -3071,7 +3072,7 @@ void ViewProviderSketch::draw(bool temp) Points.push_back(center); } else if ((*it)->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { // add an arc - const Part::GeomArcOfEllipse *arc = dynamic_cast(*it); + const Part::GeomArcOfEllipse *arc = static_cast(*it); Handle_Geom_TrimmedCurve curve = Handle_Geom_TrimmedCurve::DownCast(arc->handle()); double startangle, endangle; @@ -3104,7 +3105,7 @@ void ViewProviderSketch::draw(bool temp) Points.push_back(center); } else if ((*it)->getTypeId() == Part::GeomBSplineCurve::getClassTypeId()) { // add a bspline - const Part::GeomBSplineCurve *spline = dynamic_cast(*it); + const Part::GeomBSplineCurve *spline = static_cast(*it); Handle_Geom_BSplineCurve curve = Handle_Geom_BSplineCurve::DownCast(spline->handle()); double first = curve->FirstParameter(); @@ -3210,7 +3211,7 @@ void ViewProviderSketch::draw(bool temp) } try{//because calculateNormalAtPoint, used in there, can throw // root separator for this constraint - SoSeparator *sep = dynamic_cast(edit->constrGroup->getChild(i)); + SoSeparator *sep = static_cast(edit->constrGroup->getChild(i)); const Constraint *Constr = *it; // distinquish different constraint types to build up @@ -3223,7 +3224,7 @@ void ViewProviderSketch::draw(bool temp) const Part::Geometry *geo = GeoById(*geomlist, Constr->First); // Vertical can only be a GeomLineSegment assert(geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()); - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); + const Part::GeomLineSegment *lineSeg = static_cast(geo); // calculate the half distance between the start and endpoint Base::Vector3d midpos = ((lineSeg->getEndPoint()+lineSeg->getStartPoint())/2); @@ -3234,10 +3235,10 @@ void ViewProviderSketch::draw(bool temp) Base::Vector3d relpos = seekConstraintPosition(midpos, norm, dir, 2.5, edit->constrGroup->getChild(i)); - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(midpos.x, midpos.y, zConstr); //Absolute Reference + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(midpos.x, midpos.y, zConstr); //Absolute Reference //Reference Position that is scaled according to zoom - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relpos.x, relpos.y, 0); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relpos.x, relpos.y, 0); } break; @@ -3283,12 +3284,12 @@ void ViewProviderSketch::draw(bool temp) } else if (Constr->FirstPos == Sketcher::none) { if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg1 = dynamic_cast(geo1); + const Part::GeomLineSegment *lineSeg1 = static_cast(geo1); midpos1 = ((lineSeg1->getEndPoint()+lineSeg1->getStartPoint())/2); dir1 = (lineSeg1->getEndPoint()-lineSeg1->getStartPoint()).Normalize(); norm1 = Base::Vector3d(-dir1.y,dir1.x,0.); } else if (geo1->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = dynamic_cast(geo1); + const Part::GeomArcOfCircle *arc = static_cast(geo1); double startangle, endangle, midangle; arc->getRange(startangle, endangle, /*emulateCCW=*/true); midangle = (startangle + endangle)/2; @@ -3296,7 +3297,7 @@ void ViewProviderSketch::draw(bool temp) dir1 = Base::Vector3d(-norm1.y,norm1.x,0); midpos1 = arc->getCenter() + arc->getRadius() * norm1; } else if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle = dynamic_cast(geo1); + const Part::GeomCircle *circle = static_cast(geo1); norm1 = Base::Vector3d(cos(M_PI/4),sin(M_PI/4),0); dir1 = Base::Vector3d(-norm1.y,norm1.x,0); midpos1 = circle->getCenter() + circle->getRadius() * norm1; @@ -3304,12 +3305,12 @@ void ViewProviderSketch::draw(bool temp) break; if (geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg2 = dynamic_cast(geo2); + const Part::GeomLineSegment *lineSeg2 = static_cast(geo2); midpos2 = ((lineSeg2->getEndPoint()+lineSeg2->getStartPoint())/2); dir2 = (lineSeg2->getEndPoint()-lineSeg2->getStartPoint()).Normalize(); norm2 = Base::Vector3d(-dir2.y,dir2.x,0.); } else if (geo2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = dynamic_cast(geo2); + const Part::GeomArcOfCircle *arc = static_cast(geo2); double startangle, endangle, midangle; arc->getRange(startangle, endangle, /*emulateCCW=*/true); midangle = (startangle + endangle)/2; @@ -3317,7 +3318,7 @@ void ViewProviderSketch::draw(bool temp) dir2 = Base::Vector3d(-norm2.y,norm2.x,0); midpos2 = arc->getCenter() + arc->getRadius() * norm2; } else if (geo2->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle = dynamic_cast(geo2); + const Part::GeomCircle *circle = static_cast(geo2); norm2 = Base::Vector3d(cos(M_PI/4),sin(M_PI/4),0); dir2 = Base::Vector3d(-norm2.y,norm2.x,0); midpos2 = circle->getCenter() + circle->getRadius() * norm2; @@ -3328,15 +3329,15 @@ void ViewProviderSketch::draw(bool temp) } Base::Vector3d relpos1 = seekConstraintPosition(midpos1, norm1, dir1, 2.5, edit->constrGroup->getChild(i)); - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(midpos1.x, midpos1.y, zConstr); - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relpos1.x, relpos1.y, 0); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(midpos1.x, midpos1.y, zConstr); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relpos1.x, relpos1.y, 0); if (twoIcons) { Base::Vector3d relpos2 = seekConstraintPosition(midpos2, norm2, dir2, 2.5, edit->constrGroup->getChild(i)); Base::Vector3d secondPos = midpos2 - midpos1; - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->abPos = SbVec3f(secondPos.x, secondPos.y, zConstr); - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->translation = SbVec3f(relpos2.x -relpos1.x, relpos2.y -relpos1.y, 0); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->abPos = SbVec3f(secondPos.x, secondPos.y, zConstr); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->translation = SbVec3f(relpos2.x -relpos1.x, relpos2.y -relpos1.y, 0); } } @@ -3358,19 +3359,19 @@ void ViewProviderSketch::draw(bool temp) double r1a=0,r1b=0,r2a=0,r2b=0; double angle1,angle1plus=0., angle2, angle2plus=0.;//angle1 = rotation of object as a whole; angle1plus = arc angle (t parameter for ellipses). if (geo1->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle = dynamic_cast(geo1); + const Part::GeomCircle *circle = static_cast(geo1); r1a = circle->getRadius(); angle1 = M_PI/4; midpos1 = circle->getCenter(); } else if (geo1->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = dynamic_cast(geo1); + const Part::GeomArcOfCircle *arc = static_cast(geo1); r1a = arc->getRadius(); double startangle, endangle; arc->getRange(startangle, endangle, /*emulateCCW=*/true); angle1 = (startangle + endangle)/2; midpos1 = arc->getCenter(); } else if (geo1->getTypeId() == Part::GeomEllipse::getClassTypeId()) { - const Part::GeomEllipse *ellipse = dynamic_cast(geo1); + const Part::GeomEllipse *ellipse = static_cast(geo1); r1a = ellipse->getMajorRadius(); r1b = ellipse->getMinorRadius(); Base::Vector3d majdir = ellipse->getMajorAxisDir(); @@ -3378,7 +3379,7 @@ void ViewProviderSketch::draw(bool temp) angle1plus = M_PI/4; midpos1 = ellipse->getCenter(); } else if (geo1->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { - const Part::GeomArcOfEllipse *aoe = dynamic_cast(geo1); + const Part::GeomArcOfEllipse *aoe = static_cast(geo1); r1a = aoe->getMajorRadius(); r1b = aoe->getMinorRadius(); double startangle, endangle; @@ -3391,19 +3392,19 @@ void ViewProviderSketch::draw(bool temp) break; if (geo2->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle = dynamic_cast(geo2); + const Part::GeomCircle *circle = static_cast(geo2); r2a = circle->getRadius(); angle2 = M_PI/4; midpos2 = circle->getCenter(); } else if (geo2->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = dynamic_cast(geo2); + const Part::GeomArcOfCircle *arc = static_cast(geo2); r2a = arc->getRadius(); double startangle, endangle; arc->getRange(startangle, endangle, /*emulateCCW=*/true); angle2 = (startangle + endangle)/2; midpos2 = arc->getCenter(); } else if (geo2->getTypeId() == Part::GeomEllipse::getClassTypeId()) { - const Part::GeomEllipse *ellipse = dynamic_cast(geo2); + const Part::GeomEllipse *ellipse = static_cast(geo2); r2a = ellipse->getMajorRadius(); r2b = ellipse->getMinorRadius(); Base::Vector3d majdir = ellipse->getMajorAxisDir(); @@ -3411,7 +3412,7 @@ void ViewProviderSketch::draw(bool temp) angle2plus = M_PI/4; midpos2 = ellipse->getCenter(); } else if (geo2->getTypeId() == Part::GeomArcOfEllipse::getClassTypeId()) { - const Part::GeomArcOfEllipse *aoe = dynamic_cast(geo2); + const Part::GeomArcOfEllipse *aoe = static_cast(geo2); r2a = aoe->getMajorRadius(); r2b = aoe->getMinorRadius(); double startangle, endangle; @@ -3463,8 +3464,8 @@ void ViewProviderSketch::draw(bool temp) } else // Parallel can only apply to a GeomLineSegment break; } else { - const Part::GeomLineSegment *lineSeg1 = dynamic_cast(geo1); - const Part::GeomLineSegment *lineSeg2 = dynamic_cast(geo2); + const Part::GeomLineSegment *lineSeg1 = static_cast(geo1); + const Part::GeomLineSegment *lineSeg2 = static_cast(geo2); // calculate the half distance between the start and endpoint midpos1 = ((lineSeg1->getEndPoint()+lineSeg1->getStartPoint())/2); @@ -3479,16 +3480,16 @@ void ViewProviderSketch::draw(bool temp) Base::Vector3d relpos1 = seekConstraintPosition(midpos1, norm1, dir1, 2.5, edit->constrGroup->getChild(i)); Base::Vector3d relpos2 = seekConstraintPosition(midpos2, norm2, dir2, 2.5, edit->constrGroup->getChild(i)); - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(midpos1.x, midpos1.y, zConstr); //Absolute Reference + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(midpos1.x, midpos1.y, zConstr); //Absolute Reference //Reference Position that is scaled according to zoom - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relpos1.x, relpos1.y, 0); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relpos1.x, relpos1.y, 0); Base::Vector3d secondPos = midpos2 - midpos1; - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->abPos = SbVec3f(secondPos.x, secondPos.y, zConstr); //Absolute Reference + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->abPos = SbVec3f(secondPos.x, secondPos.y, zConstr); //Absolute Reference //Reference Position that is scaled according to zoom - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->translation = SbVec3f(relpos2.x - relpos1.x, relpos2.y -relpos1.y, 0); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->translation = SbVec3f(relpos2.x - relpos1.x, relpos2.y -relpos1.y, 0); } break; @@ -3515,7 +3516,7 @@ void ViewProviderSketch::draw(bool temp) } const Part::Geometry *geo = GeoById(*geomlist, Constr->Second); if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); + const Part::GeomLineSegment *lineSeg = static_cast(geo); Base::Vector3d l2p1 = lineSeg->getStartPoint(); Base::Vector3d l2p2 = lineSeg->getEndPoint(); // calculate the projection of p1 onto line2 @@ -3532,7 +3533,7 @@ void ViewProviderSketch::draw(bool temp) } else if (Constr->First != Constraint::GeoUndef) { const Part::Geometry *geo = GeoById(*geomlist, Constr->First); if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); + const Part::GeomLineSegment *lineSeg = static_cast(geo); pnt1 = lineSeg->getStartPoint(); pnt2 = lineSeg->getEndPoint(); } else @@ -3540,7 +3541,7 @@ void ViewProviderSketch::draw(bool temp) } else break; - SoDatumLabel *asciiText = dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); + SoDatumLabel *asciiText = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); asciiText->string = SbString(Constr->getPresentationValue().getUserString().toUtf8().constData()); if (Constr->Type == Distance) @@ -3601,8 +3602,8 @@ void ViewProviderSketch::draw(bool temp) Base::Vector3d dir = norm; dir.RotateZ(-M_PI/2.0); relPos = seekConstraintPosition(pos, norm, dir, 2.5, edit->constrGroup->getChild(i)); - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(pos.x, pos.y, zConstr); //Absolute Reference - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relPos.x, relPos.y, 0); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(pos.x, pos.y, zConstr); //Absolute Reference + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relPos.x, relPos.y, 0); } else if (Constr->Type == Tangent) { // get the geometry @@ -3611,8 +3612,8 @@ void ViewProviderSketch::draw(bool temp) if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId() && geo2->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg1 = dynamic_cast(geo1); - const Part::GeomLineSegment *lineSeg2 = dynamic_cast(geo2); + const Part::GeomLineSegment *lineSeg1 = static_cast(geo1); + const Part::GeomLineSegment *lineSeg2 = static_cast(geo2); // tangency between two lines Base::Vector3d midpos1 = ((lineSeg1->getEndPoint()+lineSeg1->getStartPoint())/2); Base::Vector3d midpos2 = ((lineSeg2->getEndPoint()+lineSeg2->getStartPoint())/2); @@ -3624,16 +3625,16 @@ void ViewProviderSketch::draw(bool temp) Base::Vector3d relpos1 = seekConstraintPosition(midpos1, norm1, dir1, 2.5, edit->constrGroup->getChild(i)); Base::Vector3d relpos2 = seekConstraintPosition(midpos2, norm2, dir2, 2.5, edit->constrGroup->getChild(i)); - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(midpos1.x, midpos1.y, zConstr); //Absolute Reference + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(midpos1.x, midpos1.y, zConstr); //Absolute Reference //Reference Position that is scaled according to zoom - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relpos1.x, relpos1.y, 0); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relpos1.x, relpos1.y, 0); Base::Vector3d secondPos = midpos2 - midpos1; - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->abPos = SbVec3f(secondPos.x, secondPos.y, zConstr); //Absolute Reference + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->abPos = SbVec3f(secondPos.x, secondPos.y, zConstr); //Absolute Reference //Reference Position that is scaled according to zoom - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->translation = SbVec3f(relpos2.x -relpos1.x, relpos2.y -relpos1.y, 0); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_SECOND_TRANSLATION))->translation = SbVec3f(relpos2.x -relpos1.x, relpos2.y -relpos1.y, 0); break; } @@ -3642,11 +3643,11 @@ void ViewProviderSketch::draw(bool temp) } if (geo1->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo1); + const Part::GeomLineSegment *lineSeg = static_cast(geo1); Base::Vector3d dir = (lineSeg->getEndPoint() - lineSeg->getStartPoint()).Normalize(); Base::Vector3d norm(-dir.y, dir.x, 0); if (geo2->getTypeId()== Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle = dynamic_cast(geo2); + const Part::GeomCircle *circle = static_cast(geo2); // tangency between a line and a circle float length = (circle->getCenter() - lineSeg->getStartPoint())*dir; @@ -3658,10 +3659,10 @@ void ViewProviderSketch::draw(bool temp) Base::Vector3d center; if(geo2->getTypeId()== Part::GeomEllipse::getClassTypeId()){ - const Part::GeomEllipse *ellipse = dynamic_cast(geo2); + const Part::GeomEllipse *ellipse = static_cast(geo2); center=ellipse->getCenter(); } else { - const Part::GeomArcOfEllipse *aoc = dynamic_cast(geo2); + const Part::GeomArcOfEllipse *aoc = static_cast(geo2); center=aoc->getCenter(); } @@ -3672,7 +3673,7 @@ void ViewProviderSketch::draw(bool temp) relPos = norm * 1; } else if (geo2->getTypeId()== Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = dynamic_cast(geo2); + const Part::GeomArcOfCircle *arc = static_cast(geo2); // tangency between a line and an arc float length = (arc->getCenter() - lineSeg->getStartPoint())*dir; @@ -3683,8 +3684,8 @@ void ViewProviderSketch::draw(bool temp) if (geo1->getTypeId()== Part::GeomCircle::getClassTypeId() && geo2->getTypeId()== Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle1 = dynamic_cast(geo1); - const Part::GeomCircle *circle2 = dynamic_cast(geo2); + const Part::GeomCircle *circle1 = static_cast(geo1); + const Part::GeomCircle *circle2 = static_cast(geo2); // tangency between two cicles Base::Vector3d dir = (circle2->getCenter() - circle1->getCenter()).Normalize(); pos = circle1->getCenter() + dir * circle1->getRadius(); @@ -3696,8 +3697,8 @@ void ViewProviderSketch::draw(bool temp) if (geo1->getTypeId()== Part::GeomCircle::getClassTypeId() && geo2->getTypeId()== Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomCircle *circle = dynamic_cast(geo1); - const Part::GeomArcOfCircle *arc = dynamic_cast(geo2); + const Part::GeomCircle *circle = static_cast(geo1); + const Part::GeomArcOfCircle *arc = static_cast(geo2); // tangency between a circle and an arc Base::Vector3d dir = (arc->getCenter() - circle->getCenter()).Normalize(); pos = circle->getCenter() + dir * circle->getRadius(); @@ -3705,15 +3706,15 @@ void ViewProviderSketch::draw(bool temp) } else if (geo1->getTypeId()== Part::GeomArcOfCircle::getClassTypeId() && geo2->getTypeId()== Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc1 = dynamic_cast(geo1); - const Part::GeomArcOfCircle *arc2 = dynamic_cast(geo2); + const Part::GeomArcOfCircle *arc1 = static_cast(geo1); + const Part::GeomArcOfCircle *arc2 = static_cast(geo2); // tangency between two arcs Base::Vector3d dir = (arc2->getCenter() - arc1->getCenter()).Normalize(); pos = arc1->getCenter() + dir * arc1->getRadius(); relPos = dir * 1; } - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(pos.x, pos.y, zConstr); //Absolute Reference - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relPos.x, relPos.y, 0); + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->abPos = SbVec3f(pos.x, pos.y, zConstr); //Absolute Reference + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = SbVec3f(relPos.x, relPos.y, 0); } } break; @@ -3731,7 +3732,7 @@ void ViewProviderSketch::draw(bool temp) dir.normalize(); SbVec3f norm (-dir[1],dir[0],0); - SoDatumLabel *asciiText = dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); + SoDatumLabel *asciiText = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); asciiText->datumtype = SoDatumLabel::SYMMETRIC; asciiText->pnts.setNum(2); @@ -3742,7 +3743,7 @@ void ViewProviderSketch::draw(bool temp) asciiText->pnts.finishEditing(); - dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = (p1 + p2)/2; + static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_FIRST_TRANSLATION))->translation = (p1 + p2)/2; } break; case Angle: @@ -3761,8 +3762,8 @@ void ViewProviderSketch::draw(bool temp) if (geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId() || geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) break; - const Part::GeomLineSegment *lineSeg1 = dynamic_cast(geo1); - const Part::GeomLineSegment *lineSeg2 = dynamic_cast(geo2); + const Part::GeomLineSegment *lineSeg1 = static_cast(geo1); + const Part::GeomLineSegment *lineSeg2 = static_cast(geo2); bool flip1 = (Constr->FirstPos == end); bool flip2 = (Constr->SecondPos == end); @@ -3818,7 +3819,7 @@ void ViewProviderSketch::draw(bool temp) } else if (Constr->First != Constraint::GeoUndef) { const Part::Geometry *geo = GeoById(*geomlist, Constr->First); if (geo->getTypeId() == Part::GeomLineSegment::getClassTypeId()) { - const Part::GeomLineSegment *lineSeg = dynamic_cast(geo); + const Part::GeomLineSegment *lineSeg = static_cast(geo); p0 = Base::convertTo((lineSeg->getEndPoint()+lineSeg->getStartPoint())/2); Base::Vector3d dir = lineSeg->getEndPoint()-lineSeg->getStartPoint(); @@ -3827,7 +3828,7 @@ void ViewProviderSketch::draw(bool temp) endangle = startangle + range; } else if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = dynamic_cast(geo); + const Part::GeomArcOfCircle *arc = static_cast(geo); p0 = Base::convertTo(arc->getCenter()); arc->getRange(startangle, endangle,/*emulateCCWXY=*/true); @@ -3839,7 +3840,7 @@ void ViewProviderSketch::draw(bool temp) } else break; - SoDatumLabel *asciiText = dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); + SoDatumLabel *asciiText = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); asciiText->string = SbString(Constr->getPresentationValue().getUserString().toUtf8().constData()); asciiText->datumtype = SoDatumLabel::ANGLE; asciiText->param1 = Constr->LabelDistance; @@ -3864,7 +3865,7 @@ void ViewProviderSketch::draw(bool temp) const Part::Geometry *geo = GeoById(*geomlist, Constr->First); if (geo->getTypeId() == Part::GeomArcOfCircle::getClassTypeId()) { - const Part::GeomArcOfCircle *arc = dynamic_cast(geo); + const Part::GeomArcOfCircle *arc = static_cast(geo); double radius = arc->getRadius(); double angle = (double) Constr->LabelPosition; if (angle == 10) { @@ -3876,7 +3877,7 @@ void ViewProviderSketch::draw(bool temp) pnt2 = pnt1 + radius * Base::Vector3d(cos(angle),sin(angle),0.); } else if (geo->getTypeId() == Part::GeomCircle::getClassTypeId()) { - const Part::GeomCircle *circle = dynamic_cast(geo); + const Part::GeomCircle *circle = static_cast(geo); double radius = circle->getRadius(); double angle = (double) Constr->LabelPosition; if (angle == 10) { @@ -3893,7 +3894,7 @@ void ViewProviderSketch::draw(bool temp) SbVec3f p1(pnt1.x,pnt1.y,zConstr); SbVec3f p2(pnt2.x,pnt2.y,zConstr); - SoDatumLabel *asciiText = dynamic_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); + SoDatumLabel *asciiText = static_cast(sep->getChild(CONSTRAINT_SEPARATOR_INDEX_MATERIAL_OR_DATUMLABEL)); asciiText->string = SbString(Constr->getPresentationValue().getUserString().toUtf8().constData()); asciiText->datumtype = SoDatumLabel::RADIUS;