TechDraw: Fix Coverity dynamic_cast warnings
This commit is contained in:
parent
97f6aa86ba
commit
8cc3ee64e8
|
@ -367,7 +367,11 @@ double DrawViewDimension::getDimValue() const
|
|||
}
|
||||
int idx0 = DrawUtil::getIndexFromName(subElements[0]);
|
||||
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* edge1 = viewPart->getProjEdgeByIndex(idx1);
|
||||
|
||||
|
|
|
@ -302,13 +302,13 @@ void CmdTechDrawNewView::activated(int iMsg)
|
|||
std::string PageName = page->getNameInDocument();
|
||||
|
||||
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 newRotation = 0.0;
|
||||
Base::Vector3d newDirection(0.0, 0.0, 1.0);
|
||||
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();
|
||||
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());
|
||||
|
||||
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
|
||||
std::string anchor = "Front";
|
||||
|
@ -642,32 +642,31 @@ CmdTechDrawClipMinus::CmdTechDrawClipMinus()
|
|||
|
||||
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()) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select exactly one Drawing View object."));
|
||||
QMessageBox::warning( Gui::getMainWindow(),
|
||||
QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select exactly one Drawing View object.") );
|
||||
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();
|
||||
const std::vector<App::DocumentObject*> pViews = page->Views.getValues();
|
||||
TechDraw::DrawViewClip* clip = 0;
|
||||
for (auto& v:pViews) {
|
||||
clip = nullptr;
|
||||
if (v->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId())) {
|
||||
clip = dynamic_cast<TechDraw::DrawViewClip*>(v);
|
||||
if (clip->isViewInClip(view)) {
|
||||
clipFound = true;
|
||||
break;
|
||||
}
|
||||
TechDraw::DrawViewClip *clip(nullptr);
|
||||
for (auto &v : pViews) {
|
||||
clip = dynamic_cast<TechDraw::DrawViewClip*>(v);
|
||||
if (clip && clip->isViewInClip(view)) {
|
||||
break;
|
||||
}
|
||||
clip = nullptr;
|
||||
}
|
||||
|
||||
if (!clipFound) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("View does not belong to a Clip"));
|
||||
if (!clip) {
|
||||
QMessageBox::warning( Gui::getMainWindow(),
|
||||
QObject::tr("Wrong selection"),
|
||||
QObject::tr("View does not belong to a Clip") );
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -926,10 +926,11 @@ bool _checkSelection(Gui::Command* cmd, unsigned maxObjs) {
|
|||
|
||||
bool _checkDrawViewPart(Gui::Command* cmd) {
|
||||
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
if(!objFeat) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
|
||||
QObject::tr("No DrawViewPart in selection."));
|
||||
auto objFeat( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
|
||||
if( !objFeat ) {
|
||||
QMessageBox::warning( Gui::getMainWindow(),
|
||||
QObject::tr("Incorrect selection"),
|
||||
QObject::tr("No DrawViewPart in selection.") );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -953,9 +954,14 @@ bool _checkPartFeature(Gui::Command* cmd) {
|
|||
|
||||
//! verify that Selection contains a valid Geometry for a single Edge Dimension
|
||||
int _isValidSingleEdge(Gui::Command* cmd) {
|
||||
int edgeType = isInvalid;
|
||||
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
auto edgeType( isInvalid );
|
||||
auto selection( cmd->getSelection().getSelectionEx() );
|
||||
|
||||
auto objFeat( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
|
||||
if( objFeat == nullptr ) {
|
||||
return isInvalid;
|
||||
}
|
||||
|
||||
const std::vector<std::string> SubNames = selection[0].getSubNames();
|
||||
if (SubNames.size() == 1) { //only 1 subshape selected
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { //the Name starts with "Edge"
|
||||
|
|
|
@ -129,12 +129,14 @@ void CmdTechDrawNewHatch::activated(int iMsg)
|
|||
}
|
||||
|
||||
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();
|
||||
TechDraw::DrawPage* page = objFeat->findParentPage();
|
||||
std::string PageName = page->getNameInDocument();
|
||||
|
||||
TechDraw::DrawHatch *hatch = 0;
|
||||
std::string FeatName = getUniqueObjectName("Hatch");
|
||||
std::stringstream featLabel;
|
||||
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().%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);
|
||||
//should this be: doCommand(Doc,"App..Feat..Source = [(App...%s,%s),(App..%s,%s),...]",objs[0]->getNameInDocument(),subs[0],...);
|
||||
//seems very unwieldy
|
||||
|
|
|
@ -166,8 +166,8 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget*
|
|||
setDimensionGroups();
|
||||
|
||||
App::DocumentObject *obj = pageGui->getPageObject()->Template.getValue();
|
||||
if(obj && obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
|
||||
TechDraw::DrawTemplate *pageTemplate = dynamic_cast<TechDraw::DrawTemplate *>(obj);
|
||||
auto pageTemplate( dynamic_cast<TechDraw::DrawTemplate *>(obj) );
|
||||
if( pageTemplate ) {
|
||||
attachTemplate(pageTemplate);
|
||||
}
|
||||
|
||||
|
|
|
@ -196,7 +196,10 @@ QGIView * QGIProjGroup::getAnchorQItem() const
|
|||
{
|
||||
// Get the currently assigned anchor view
|
||||
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
|
||||
QList<QGraphicsItem*> list = childItems();
|
||||
|
|
|
@ -86,11 +86,10 @@ void QGIViewAnnotation::setViewAnnoFeature(TechDraw::DrawViewAnnotation *obj)
|
|||
|
||||
void QGIViewAnnotation::updateView(bool update)
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId()))
|
||||
auto viewAnno( dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject()) );
|
||||
if( viewAnno == nullptr)
|
||||
return;
|
||||
|
||||
TechDraw::DrawViewAnnotation *viewAnno = dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject());
|
||||
|
||||
if (update ||
|
||||
viewAnno->isTouched() ||
|
||||
viewAnno->Text.isTouched() ||
|
||||
|
@ -118,10 +117,10 @@ void QGIViewAnnotation::draw()
|
|||
|
||||
void QGIViewAnnotation::drawAnnotation()
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId()))
|
||||
auto viewAnno( dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject()) );
|
||||
if( viewAnno == nullptr ) {
|
||||
return;
|
||||
|
||||
TechDraw::DrawViewAnnotation *viewAnno = dynamic_cast<TechDraw::DrawViewAnnotation *>(getViewObject());
|
||||
}
|
||||
|
||||
const std::vector<std::string>& annoText = viewAnno->Text.getValues();
|
||||
|
||||
|
|
|
@ -80,10 +80,10 @@ QVariant QGIViewClip::itemChange(GraphicsItemChange change, const QVariant &valu
|
|||
|
||||
void QGIViewClip::updateView(bool update)
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId()))
|
||||
auto viewClip( dynamic_cast<TechDraw::DrawViewClip *>(getViewObject()) );
|
||||
if( viewClip == nullptr ) {
|
||||
return;
|
||||
|
||||
TechDraw::DrawViewClip *viewClip = dynamic_cast<TechDraw::DrawViewClip *>(getViewObject());
|
||||
}
|
||||
|
||||
if (update ||
|
||||
viewClip->isTouched() ||
|
||||
|
@ -111,10 +111,11 @@ void QGIViewClip::draw()
|
|||
|
||||
void QGIViewClip::drawClip()
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId()))
|
||||
return;
|
||||
auto viewClip( dynamic_cast<TechDraw::DrawViewClip *>(getViewObject()) );
|
||||
|
||||
TechDraw::DrawViewClip *viewClip = dynamic_cast<TechDraw::DrawViewClip *>(getViewObject());
|
||||
if( viewClip == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
prepareGeometryChange();
|
||||
double h = viewClip->Height.getValue();
|
||||
|
|
|
@ -242,10 +242,11 @@ void QGIViewDimension::updateView(bool update)
|
|||
|
||||
void QGIViewDimension::updateDim()
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()))
|
||||
const auto dim( dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject()) );
|
||||
if( dim == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject());
|
||||
QString labelText = QString::fromUtf8(dim->getFormatedValue().data(),dim->getFormatedValue().size());
|
||||
QFont font = datumLabel->font();
|
||||
font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points
|
||||
|
@ -264,10 +265,11 @@ void QGIViewDimension::datumLabelDragged()
|
|||
|
||||
void QGIViewDimension::datumLabelDragFinished()
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()))
|
||||
return;
|
||||
auto dim( dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject()) );
|
||||
|
||||
TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject());
|
||||
if( dim == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
double x = datumLabel->X(),
|
||||
y = datumLabel->Y();
|
||||
|
|
|
@ -231,14 +231,13 @@ QPainterPath QGIViewPart::drawPainterPath(TechDrawGeometry::BaseGeom *baseGeom)
|
|||
|
||||
void QGIViewPart::updateView(bool update)
|
||||
{
|
||||
if (getViewObject() == 0 ||
|
||||
!getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
|
||||
auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) );
|
||||
if( viewPart == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
QGIView::updateView(update);
|
||||
|
||||
TechDraw::DrawViewPart *viewPart = dynamic_cast<TechDraw::DrawViewPart *>(getViewObject());
|
||||
|
||||
if (update ||
|
||||
viewPart->isTouched() ||
|
||||
|
@ -276,13 +275,11 @@ void QGIViewPart::draw() {
|
|||
|
||||
void QGIViewPart::drawViewPart()
|
||||
{
|
||||
if ( getViewObject() == 0 ||
|
||||
!getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
|
||||
auto viewPart( dynamic_cast<TechDraw::DrawViewPart *>(getViewObject()) );
|
||||
if ( viewPart == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
TechDraw::DrawViewPart *viewPart = dynamic_cast<TechDraw::DrawViewPart *>(getViewObject());
|
||||
|
||||
float lineWidth = viewPart->LineWidth.getValue() * lineScaleFactor;
|
||||
float lineWidthHid = viewPart->HiddenWidth.getValue() * lineScaleFactor;
|
||||
|
||||
|
|
|
@ -60,20 +60,16 @@ void QGIViewSection::draw()
|
|||
|
||||
void QGIViewSection::drawSectionFace()
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId()))
|
||||
return;
|
||||
|
||||
TechDraw::DrawViewSection *section = dynamic_cast<TechDraw::DrawViewSection *>(getViewObject());
|
||||
if (!section->hasGeometry()) {
|
||||
auto section( dynamic_cast<TechDraw::DrawViewSection *>(getViewObject()) );
|
||||
if( section == nullptr ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!section->ShowCutSurface.getValue()) {
|
||||
if ( !section->hasGeometry() || !section->ShowCutSurface.getValue() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<TechDrawGeometry::Face*> sectionFaces;
|
||||
sectionFaces = section->getFaceGeometry();
|
||||
auto sectionFaces( section->getFaceGeometry() );
|
||||
if (sectionFaces.empty()) {
|
||||
Base::Console().Log("INFO - QGIViewSection::drawSectionFace - No sectionFaces available. Check Section plane.\n");
|
||||
return;
|
||||
|
@ -92,10 +88,10 @@ void QGIViewSection::drawSectionFace()
|
|||
|
||||
void QGIViewSection::updateView(bool update)
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()))
|
||||
auto viewPart( dynamic_cast<TechDraw::DrawViewSection *>(getViewObject()) );
|
||||
if( viewPart == nullptr ) {
|
||||
return;
|
||||
|
||||
TechDraw::DrawViewSection *viewPart = dynamic_cast<TechDraw::DrawViewSection *>(getViewObject());
|
||||
}
|
||||
|
||||
if(update ||
|
||||
viewPart->SectionNormal.isTouched() ||
|
||||
|
|
|
@ -81,10 +81,10 @@ void QGIViewSymbol::setViewSymbolFeature(TechDraw::DrawViewSymbol *obj)
|
|||
|
||||
void QGIViewSymbol::updateView(bool update)
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId()))
|
||||
auto viewSymbol( dynamic_cast<TechDraw::DrawViewSymbol *>(getViewObject()) );
|
||||
if( viewSymbol == nullptr ) {
|
||||
return;
|
||||
|
||||
TechDraw::DrawViewSymbol *viewSymbol = dynamic_cast<TechDraw::DrawViewSymbol *>(getViewObject());
|
||||
}
|
||||
|
||||
if (update ||
|
||||
viewSymbol->isTouched() ||
|
||||
|
@ -113,10 +113,11 @@ void QGIViewSymbol::draw()
|
|||
|
||||
void QGIViewSymbol::drawSvg()
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId()))
|
||||
auto viewSymbol( dynamic_cast<TechDraw::DrawViewSymbol *>(getViewObject()) );
|
||||
if( viewSymbol == nullptr ) {
|
||||
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?)
|
||||
//due to 1 sceneUnit (1mm) = 1 pixel for some QtSvg functions
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user