TechDraw: Fix Coverity dynamic_cast warnings

This commit is contained in:
Ian Rees 2016-08-19 22:47:17 +12:00 committed by wmayer
parent 97f6aa86ba
commit 8cc3ee64e8
12 changed files with 84 additions and 74 deletions

View File

@ -367,7 +367,11 @@ double DrawViewDimension::getDimValue() const
} }
int idx0 = DrawUtil::getIndexFromName(subElements[0]); int idx0 = DrawUtil::getIndexFromName(subElements[0]);
int idx1 = DrawUtil::getIndexFromName(subElements[1]); int idx1 = DrawUtil::getIndexFromName(subElements[1]);
TechDraw::DrawViewPart *viewPart = dynamic_cast<TechDraw::DrawViewPart *>(objects[0]); auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(objects[0]) );
if( viewPart == nullptr ) {
Base::Console().Message("INFO - DVD::getDimValue - References2D not DrawViewPart\n");
return 0.0;
}
TechDrawGeometry::BaseGeom* edge0 = viewPart->getProjEdgeByIndex(idx0); TechDrawGeometry::BaseGeom* edge0 = viewPart->getProjEdgeByIndex(idx0);
TechDrawGeometry::BaseGeom* edge1 = viewPart->getProjEdgeByIndex(idx1); TechDrawGeometry::BaseGeom* edge1 = viewPart->getProjEdgeByIndex(idx1);

View File

@ -302,13 +302,13 @@ void CmdTechDrawNewView::activated(int iMsg)
std::string PageName = page->getNameInDocument(); std::string PageName = page->getNameInDocument();
Gui::WaitCursor wc; Gui::WaitCursor wc;
const std::vector<App::DocumentObject*> selectedProjections = getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()); const auto selectedProjections( getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()) );
float newScale = 1.0; float newScale = 1.0;
float newRotation = 0.0; float newRotation = 0.0;
Base::Vector3d newDirection(0.0, 0.0, 1.0); Base::Vector3d newDirection(0.0, 0.0, 1.0);
if (!selectedProjections.empty()) { if (!selectedProjections.empty()) {
const TechDraw::DrawView* const myView = dynamic_cast<TechDraw::DrawView*>(selectedProjections.front()); const auto myView( static_cast<TechDraw::DrawView*>(selectedProjections.front()) );
newScale = myView->Scale.getValue(); newScale = myView->Scale.getValue();
newRotation = myView->Rotation.getValue(); newRotation = myView->Rotation.getValue();
@ -435,7 +435,7 @@ void CmdTechDrawProjGroup::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",multiViewName.c_str(),SourceName.c_str()); doCommand(Doc,"App.activeDocument().%s.Source = App.activeDocument().%s",multiViewName.c_str(),SourceName.c_str());
App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str()); App::DocumentObject *docObj = getDocument()->getObject(multiViewName.c_str());
TechDraw::DrawProjGroup *multiView = dynamic_cast<TechDraw::DrawProjGroup *>(docObj); auto multiView( static_cast<TechDraw::DrawProjGroup *>(docObj) );
// set the anchor // set the anchor
std::string anchor = "Front"; std::string anchor = "Front";
@ -642,32 +642,31 @@ CmdTechDrawClipMinus::CmdTechDrawClipMinus()
void CmdTechDrawClipMinus::activated(int iMsg) void CmdTechDrawClipMinus::activated(int iMsg)
{ {
std::vector<App::DocumentObject*> dObj = getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()); auto dObj( getSelection().getObjectsOfType(TechDraw::DrawView::getClassTypeId()) );
if (dObj.empty()) { if (dObj.empty()) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QMessageBox::warning( Gui::getMainWindow(),
QObject::tr("Select exactly one Drawing View object.")); QObject::tr("Wrong selection"),
QObject::tr("Select exactly one Drawing View object.") );
return; return;
} }
TechDraw::DrawView* view = dynamic_cast<TechDraw::DrawView*>(dObj.front());
bool clipFound = false; auto view( static_cast<TechDraw::DrawView*>(dObj.front()) );
TechDraw::DrawPage* page = view->findParentPage(); TechDraw::DrawPage* page = view->findParentPage();
const std::vector<App::DocumentObject*> pViews = page->Views.getValues(); const std::vector<App::DocumentObject*> pViews = page->Views.getValues();
TechDraw::DrawViewClip* clip = 0; TechDraw::DrawViewClip *clip(nullptr);
for (auto& v:pViews) { for (auto &v : pViews) {
clip = nullptr; clip = dynamic_cast<TechDraw::DrawViewClip*>(v);
if (v->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) { if (clip && clip->isViewInClip(view)) {
clip = dynamic_cast<TechDraw::DrawViewClip*>(v); break;
if (clip->isViewInClip(view)) {
clipFound = true;
break;
}
} }
clip = nullptr;
} }
if (!clipFound) { if (!clip) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), QMessageBox::warning( Gui::getMainWindow(),
QObject::tr("View does not belong to a Clip")); QObject::tr("Wrong selection"),
QObject::tr("View does not belong to a Clip") );
return; return;
} }

View File

@ -926,10 +926,11 @@ bool _checkSelection(Gui::Command* cmd, unsigned maxObjs) {
bool _checkDrawViewPart(Gui::Command* cmd) { bool _checkDrawViewPart(Gui::Command* cmd) {
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx(); std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()); auto objFeat( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
if(!objFeat) { if( !objFeat ) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), QMessageBox::warning( Gui::getMainWindow(),
QObject::tr("No DrawViewPart in selection.")); QObject::tr("Incorrect selection"),
QObject::tr("No DrawViewPart in selection.") );
return false; return false;
} }
return true; return true;
@ -953,9 +954,14 @@ bool _checkPartFeature(Gui::Command* cmd) {
//! verify that Selection contains a valid Geometry for a single Edge Dimension //! verify that Selection contains a valid Geometry for a single Edge Dimension
int _isValidSingleEdge(Gui::Command* cmd) { int _isValidSingleEdge(Gui::Command* cmd) {
int edgeType = isInvalid; auto edgeType( isInvalid );
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx(); auto selection( cmd->getSelection().getSelectionEx() );
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
auto objFeat( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
if( objFeat == nullptr ) {
return isInvalid;
}
const std::vector<std::string> SubNames = selection[0].getSubNames(); const std::vector<std::string> SubNames = selection[0].getSubNames();
if (SubNames.size() == 1) { //only 1 subshape selected if (SubNames.size() == 1) { //only 1 subshape selected
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { //the Name starts with "Edge" if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { //the Name starts with "Edge"

View File

@ -129,12 +129,14 @@ void CmdTechDrawNewHatch::activated(int iMsg)
} }
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx(); std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()); auto objFeat( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
if( objFeat == nullptr ) {
return;
}
const std::vector<std::string> &subNames = selection[0].getSubNames(); const std::vector<std::string> &subNames = selection[0].getSubNames();
TechDraw::DrawPage* page = objFeat->findParentPage(); TechDraw::DrawPage* page = objFeat->findParentPage();
std::string PageName = page->getNameInDocument(); std::string PageName = page->getNameInDocument();
TechDraw::DrawHatch *hatch = 0;
std::string FeatName = getUniqueObjectName("Hatch"); std::string FeatName = getUniqueObjectName("Hatch");
std::stringstream featLabel; std::stringstream featLabel;
featLabel << FeatName << "F" << TechDraw::DrawUtil::getIndexFromName(subNames.at(0)); featLabel << FeatName << "F" << TechDraw::DrawUtil::getIndexFromName(subNames.at(0));
@ -143,7 +145,7 @@ void CmdTechDrawNewHatch::activated(int iMsg)
doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str()); doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawHatch','%s')",FeatName.c_str());
doCommand(Doc,"App.activeDocument().%s.Label = '%s'",FeatName.c_str(),featLabel.str().c_str()); doCommand(Doc,"App.activeDocument().%s.Label = '%s'",FeatName.c_str(),featLabel.str().c_str());
hatch = dynamic_cast<TechDraw::DrawHatch *>(getDocument()->getObject(FeatName.c_str())); auto hatch( static_cast<TechDraw::DrawHatch *>(getDocument()->getObject(FeatName.c_str())) );
hatch->Source.setValue(objFeat, subNames); hatch->Source.setValue(objFeat, subNames);
//should this be: doCommand(Doc,"App..Feat..Source = [(App...%s,%s),(App..%s,%s),...]",objs[0]->getNameInDocument(),subs[0],...); //should this be: doCommand(Doc,"App..Feat..Source = [(App...%s,%s),(App..%s,%s),...]",objs[0]->getNameInDocument(),subs[0],...);
//seems very unwieldy //seems very unwieldy

View File

@ -166,8 +166,8 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget*
setDimensionGroups(); setDimensionGroups();
App::DocumentObject *obj = pageGui->getPageObject()->Template.getValue(); App::DocumentObject *obj = pageGui->getPageObject()->Template.getValue();
if(obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) { auto pageTemplate( dynamic_cast<TechDraw::DrawTemplate *>(obj) );
TechDraw::DrawTemplate *pageTemplate = dynamic_cast<TechDraw::DrawTemplate *>(obj); if( pageTemplate ) {
attachTemplate(pageTemplate); attachTemplate(pageTemplate);
} }

View File

@ -196,7 +196,10 @@ QGIView * QGIProjGroup::getAnchorQItem() const
{ {
// Get the currently assigned anchor view // Get the currently assigned anchor view
App::DocumentObject *anchorObj = getDrawView()->Anchor.getValue(); App::DocumentObject *anchorObj = getDrawView()->Anchor.getValue();
TechDraw::DrawView *anchorView = dynamic_cast<TechDraw::DrawView *>(anchorObj); auto anchorView( dynamic_cast<TechDraw::DrawView *>(anchorObj) );
if( anchorView == nullptr ) {
return nullptr;
}
// Locate the anchor view's qgraphicsitemview // Locate the anchor view's qgraphicsitemview
QList<QGraphicsItem*> list = childItems(); QList<QGraphicsItem*> list = childItems();

View File

@ -86,11 +86,10 @@ void QGIViewAnnotation::setViewAnnoFeature(TechDraw::DrawViewAnnotation *obj)
void QGIViewAnnotation::updateView(bool update) void QGIViewAnnotation::updateView(bool update)
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) auto viewAnno( dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject()) );
if( viewAnno == nullptr)
return; return;
TechDraw::DrawViewAnnotation *viewAnno = dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject());
if (update || if (update ||
viewAnno->isTouched() || viewAnno->isTouched() ||
viewAnno->Text.isTouched() || viewAnno->Text.isTouched() ||
@ -118,10 +117,10 @@ void QGIViewAnnotation::draw()
void QGIViewAnnotation::drawAnnotation() void QGIViewAnnotation::drawAnnotation()
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId())) auto viewAnno( dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject()) );
if( viewAnno == nullptr ) {
return; return;
}
TechDraw::DrawViewAnnotation *viewAnno = dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject());
const std::vector<std::string>& annoText = viewAnno->Text.getValues(); const std::vector<std::string>& annoText = viewAnno->Text.getValues();

View File

@ -80,10 +80,10 @@ QVariant QGIViewClip::itemChange(GraphicsItemChange change, const QVariant &valu
void QGIViewClip::updateView(bool update) void QGIViewClip::updateView(bool update)
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) auto viewClip( dynamic_cast<TechDraw::DrawViewClip *>(getViewObject()) );
if( viewClip == nullptr ) {
return; return;
}
TechDraw::DrawViewClip *viewClip = dynamic_cast<TechDraw::DrawViewClip *>(getViewObject());
if (update || if (update ||
viewClip->isTouched() || viewClip->isTouched() ||
@ -111,10 +111,11 @@ void QGIViewClip::draw()
void QGIViewClip::drawClip() void QGIViewClip::drawClip()
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) auto viewClip( dynamic_cast<TechDraw::DrawViewClip *>(getViewObject()) );
return;
TechDraw::DrawViewClip *viewClip = dynamic_cast<TechDraw::DrawViewClip *>(getViewObject()); if( viewClip == nullptr ) {
return;
}
prepareGeometryChange(); prepareGeometryChange();
double h = viewClip->Height.getValue(); double h = viewClip->Height.getValue();

View File

@ -242,10 +242,11 @@ void QGIViewDimension::updateView(bool update)
void QGIViewDimension::updateDim() void QGIViewDimension::updateDim()
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) const auto dim( dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject()) );
if( dim == nullptr ) {
return; return;
}
const TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject());
QString labelText = QString::fromUtf8(dim->getFormatedValue().data(),dim->getFormatedValue().size()); QString labelText = QString::fromUtf8(dim->getFormatedValue().data(),dim->getFormatedValue().size());
QFont font = datumLabel->font(); QFont font = datumLabel->font();
font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points
@ -264,10 +265,11 @@ void QGIViewDimension::datumLabelDragged()
void QGIViewDimension::datumLabelDragFinished() void QGIViewDimension::datumLabelDragFinished()
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) auto dim( dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject()) );
return;
TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject()); if( dim == nullptr ) {
return;
}
double x = datumLabel->X(), double x = datumLabel->X(),
y = datumLabel->Y(); y = datumLabel->Y();

View File

@ -231,14 +231,13 @@ QPainterPath QGIViewPart::drawPainterPath(TechDrawGeometry::BaseGeom *baseGeom)
void QGIViewPart::updateView(bool update) void QGIViewPart::updateView(bool update)
{ {
if (getViewObject() == 0 || auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) );
!getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { if( viewPart == nullptr ) {
return; return;
} }
QGIView::updateView(update); QGIView::updateView(update);
TechDraw::DrawViewPart *viewPart = dynamic_cast<TechDraw::DrawViewPart *>(getViewObject());
if (update || if (update ||
viewPart->isTouched() || viewPart->isTouched() ||
@ -276,13 +275,11 @@ void QGIViewPart::draw() {
void QGIViewPart::drawViewPart() void QGIViewPart::drawViewPart()
{ {
if ( getViewObject() == 0 || auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) );
!getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { if ( viewPart == nullptr ) {
return; return;
} }
TechDraw::DrawViewPart *viewPart = dynamic_cast<TechDraw::DrawViewPart *>(getViewObject());
float lineWidth = viewPart->LineWidth.getValue() * lineScaleFactor; float lineWidth = viewPart->LineWidth.getValue() * lineScaleFactor;
float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor; float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor;

View File

@ -60,20 +60,16 @@ void QGIViewSection::draw()
void QGIViewSection::drawSectionFace() void QGIViewSection::drawSectionFace()
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId())) auto section( dynamic_cast<TechDraw::DrawViewSection *>(getViewObject()) );
return; if( section == nullptr ) {
TechDraw::DrawViewSection *section = dynamic_cast<TechDraw::DrawViewSection *>(getViewObject());
if (!section->hasGeometry()) {
return; return;
} }
if (!section->ShowCutSurface.getValue()) { if ( !section->hasGeometry() || !section->ShowCutSurface.getValue() ) {
return; return;
} }
std::vector<TechDrawGeometry::Face*> sectionFaces; auto sectionFaces( section->getFaceGeometry() );
sectionFaces = section->getFaceGeometry();
if (sectionFaces.empty()) { if (sectionFaces.empty()) {
Base::Console().Log("INFO - QGIViewSection::drawSectionFace - No sectionFaces available. Check Section plane.\n"); Base::Console().Log("INFO - QGIViewSection::drawSectionFace - No sectionFaces available. Check Section plane.\n");
return; return;
@ -92,10 +88,10 @@ void QGIViewSection::drawSectionFace()
void QGIViewSection::updateView(bool update) void QGIViewSection::updateView(bool update)
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) auto viewPart( dynamic_cast<TechDraw::DrawViewSection *>(getViewObject()) );
if( viewPart == nullptr ) {
return; return;
}
TechDraw::DrawViewSection *viewPart = dynamic_cast<TechDraw::DrawViewSection *>(getViewObject());
if(update || if(update ||
viewPart->SectionNormal.isTouched() || viewPart->SectionNormal.isTouched() ||

View File

@ -81,10 +81,10 @@ void QGIViewSymbol::setViewSymbolFeature(TechDraw::DrawViewSymbol *obj)
void QGIViewSymbol::updateView(bool update) void QGIViewSymbol::updateView(bool update)
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId())) auto viewSymbol( dynamic_cast<TechDraw::DrawViewSymbol *>(getViewObject()) );
if( viewSymbol == nullptr ) {
return; return;
}
TechDraw::DrawViewSymbol *viewSymbol = dynamic_cast<TechDraw::DrawViewSymbol *>(getViewObject());
if (update || if (update ||
viewSymbol->isTouched() || viewSymbol->isTouched() ||
@ -113,10 +113,11 @@ void QGIViewSymbol::draw()
void QGIViewSymbol::drawSvg() void QGIViewSymbol::drawSvg()
{ {
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId())) auto viewSymbol( dynamic_cast<TechDraw::DrawViewSymbol *>(getViewObject()) );
if( viewSymbol == nullptr ) {
return; return;
}
TechDraw::DrawViewSymbol *viewSymbol = dynamic_cast<TechDraw::DrawViewSymbol *>(getViewObject());
//note: svg's are overscaled by (72 pixels(pts actually) /in)*(1 in/25.4 mm) = 2.834645669 (could be 96/25.4(CSS)? 110/25.4?) //note: svg's are overscaled by (72 pixels(pts actually) /in)*(1 in/25.4 mm) = 2.834645669 (could be 96/25.4(CSS)? 110/25.4?)
//due to 1 sceneUnit (1mm) = 1 pixel for some QtSvg functions //due to 1 sceneUnit (1mm) = 1 pixel for some QtSvg functions