TechDraw: Fix some Coverity Unchecked dynamic_cast
CIDs from sasobadovinac-FreeCAD: 151684 151714 151715 151716 151718 151719 151720 151721 151722 151724 151725 151730 151749 151759 151771 151794
This commit is contained in:
parent
66bd0f6b90
commit
34583fad05
|
@ -217,15 +217,11 @@ void DrawProjGroup::moveToCentre(void)
|
|||
|
||||
App::DocumentObject * DrawProjGroup::getProjObj(const char *viewProjType) const
|
||||
{
|
||||
const std::vector<App::DocumentObject *> &views = Views.getValues();
|
||||
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
|
||||
DrawView *view = dynamic_cast<DrawView *>(*it);
|
||||
if(view->getTypeId() == DrawProjGroupItem::getClassTypeId()) {
|
||||
DrawProjGroupItem *projPtr = dynamic_cast<DrawProjGroupItem *>(*it);
|
||||
|
||||
if( strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 )
|
||||
return *it;
|
||||
for( auto it : Views.getValues() ) {
|
||||
auto projPtr( dynamic_cast<DrawProjGroupItem *>(it) );
|
||||
if( projPtr &&
|
||||
strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
|
||||
return it;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,17 +230,10 @@ App::DocumentObject * DrawProjGroup::getProjObj(const char *viewProjType) const
|
|||
|
||||
bool DrawProjGroup::hasProjection(const char *viewProjType) const
|
||||
{
|
||||
const std::vector<App::DocumentObject *> &views = Views.getValues();
|
||||
|
||||
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
|
||||
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
|
||||
if(view->getTypeId() == TechDraw::DrawProjGroupItem::getClassTypeId()) {
|
||||
TechDraw::DrawProjGroupItem *projPtr = dynamic_cast<TechDraw::DrawProjGroupItem *>(*it);
|
||||
|
||||
if( strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
for( const auto it : Views.getValues() ) {
|
||||
auto view( dynamic_cast<TechDraw::DrawProjGroupItem *>(it) );
|
||||
if( view && strcmp(viewProjType, view->Type.getValueAsString()) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -269,14 +258,14 @@ bool DrawProjGroup::checkViewProjType(const char *in)
|
|||
|
||||
App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
|
||||
{
|
||||
DrawProjGroupItem *view = NULL;
|
||||
DrawProjGroupItem *view( nullptr );
|
||||
|
||||
if ( checkViewProjType(viewProjType) && !hasProjection(viewProjType) ) {
|
||||
std::string FeatName = getDocument()->getUniqueObjectName("ProjItem");
|
||||
App::DocumentObject *docObj = getDocument()->addObject("TechDraw::DrawProjGroupItem",
|
||||
FeatName.c_str());
|
||||
auto docObj( getDocument()->addObject( "TechDraw::DrawProjGroupItem",
|
||||
FeatName.c_str() ) );
|
||||
|
||||
view = dynamic_cast<TechDraw::DrawProjGroupItem *>( docObj );
|
||||
view = static_cast<TechDraw::DrawProjGroupItem *>( docObj );
|
||||
view->Source.setValue( Source.getValue() );
|
||||
view->ScaleType.setValue( ScaleType.getValue() );
|
||||
view->Scale.setValue( Scale.getValue() );
|
||||
|
@ -351,23 +340,19 @@ void DrawProjGroup::setViewOrientation(DrawProjGroupItem *v, const char *projTyp
|
|||
int DrawProjGroup::removeProjection(const char *viewProjType)
|
||||
{
|
||||
if ( checkViewProjType(viewProjType) ) {
|
||||
if(!hasProjection(viewProjType)) {
|
||||
if( !hasProjection(viewProjType) ) {
|
||||
throw Base::Exception("The projection doesn't exist in the group");
|
||||
}
|
||||
|
||||
// Iterate through the child views and find the projection type
|
||||
const std::vector<App::DocumentObject *> &views = Views.getValues();
|
||||
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
|
||||
TechDraw::DrawView *view = dynamic_cast<TechDraw::DrawView *>(*it);
|
||||
if(view->getTypeId() == TechDraw::DrawProjGroupItem::getClassTypeId()) {
|
||||
TechDraw::DrawProjGroupItem *projPtr = dynamic_cast<TechDraw::DrawProjGroupItem *>(*it);
|
||||
|
||||
for( auto it : Views.getValues() ) {
|
||||
auto projPtr( dynamic_cast<TechDraw::DrawProjGroupItem *>(it) );
|
||||
if( projPtr ) {
|
||||
if ( strcmp(viewProjType, projPtr->Type.getValueAsString()) == 0 ) {
|
||||
// Remove from the document
|
||||
getDocument()->remObject((*it)->getNameInDocument());
|
||||
getDocument()->remObject( it->getNameInDocument() );
|
||||
moveToCentre();
|
||||
return views.size();
|
||||
return Views.getValues().size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -382,7 +367,7 @@ void DrawProjGroup::arrangeViewPointers(DrawProjGroupItem *viewPtrs[10]) const
|
|||
viewPtrs[i] = NULL;
|
||||
}
|
||||
|
||||
DrawProjGroupItem *anchorView = dynamic_cast<DrawProjGroupItem *>(Anchor.getValue());
|
||||
auto anchorView( dynamic_cast<DrawProjGroupItem *>(Anchor.getValue()) );
|
||||
|
||||
if (!anchorView) { //TODO: Consider not requiring an anchor view, or allowing ones other than "Front"
|
||||
throw Base::Exception("No anchor view set in DrawProjGroup::arrangeViewPointers()");
|
||||
|
@ -397,8 +382,6 @@ void DrawProjGroup::arrangeViewPointers(DrawProjGroupItem *viewPtrs[10]) const
|
|||
}
|
||||
|
||||
// Iterate through views and populate viewPtrs
|
||||
DrawProjGroupItem* oView;
|
||||
std::vector<App::DocumentObject *> views = Views.getValues();
|
||||
if ( strcmp(projType, "Third Angle") == 0 ||
|
||||
strcmp(projType, "First Angle") == 0 ) {
|
||||
// Third Angle: FTL T FTRight
|
||||
|
@ -409,10 +392,9 @@ void DrawProjGroup::arrangeViewPointers(DrawProjGroupItem *viewPtrs[10]) const
|
|||
// Right F L Rear
|
||||
// FTRight T FTL
|
||||
bool thirdAngle = (strcmp(projType, "Third Angle") == 0);
|
||||
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
if ((*it)->getTypeId().isDerivedFrom(DrawProjGroupItem::getClassTypeId())) {
|
||||
oView = dynamic_cast<DrawProjGroupItem *>(*it);
|
||||
|
||||
for (auto it : Views.getValues()) {
|
||||
auto oView( dynamic_cast<DrawProjGroupItem *>(it) );
|
||||
if (oView) {
|
||||
const char *viewTypeCStr = oView->Type.getValueAsString();
|
||||
if (strcmp(viewTypeCStr, "Front") == 0) {
|
||||
viewPtrs[thirdAngle ? 4 : 4] = oView;
|
||||
|
@ -535,10 +517,9 @@ bool DrawProjGroup::distributeProjections()
|
|||
//!allow child DPGI's to be automatically positioned
|
||||
void DrawProjGroup::resetPositions(void)
|
||||
{
|
||||
const std::vector<App::DocumentObject *> &views = Views.getValues();
|
||||
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
DrawView *view = dynamic_cast<DrawView *>(*it);
|
||||
if(view->getTypeId() == DrawProjGroupItem::getClassTypeId()) {
|
||||
for( auto it : Views.getValues() ) {
|
||||
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
|
||||
if( view ) {
|
||||
view->setAutoPos(true);
|
||||
//X,Y == 0??
|
||||
}
|
||||
|
@ -550,12 +531,11 @@ void DrawProjGroup::setFrontViewOrientation(const Base::Matrix4D &newMat)
|
|||
{
|
||||
viewOrientationMatrix.setValue(newMat);
|
||||
|
||||
DrawProjGroupItem *view;
|
||||
std::vector<App::DocumentObject *> views = Views.getValues();
|
||||
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
if ((*it)->getTypeId().isDerivedFrom(DrawProjGroupItem::getClassTypeId())) {
|
||||
view = dynamic_cast<DrawProjGroupItem *>(*it);
|
||||
for( auto it : Views.getValues() ) {
|
||||
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
|
||||
if( view ) {
|
||||
setViewOrientation(view, view->Type.getValueAsString());
|
||||
// TODO: Seems we should ensure that modifying the view triggers this automatically? IR
|
||||
view->touch();
|
||||
}
|
||||
}
|
||||
|
@ -573,11 +553,9 @@ App::DocumentObjectExecReturn *DrawProjGroup::execute(void)
|
|||
Scale.setValue(autoScale);
|
||||
|
||||
//Rebuild the DPGI's
|
||||
const std::vector<App::DocumentObject *> &views = Views.getValues();
|
||||
for(std::vector<App::DocumentObject *>::const_iterator it = views.begin(); it != views.end(); ++it) {
|
||||
App::DocumentObject *docObj = *it;
|
||||
if(docObj->getTypeId().isDerivedFrom(DrawProjGroupItem::getClassTypeId())) {
|
||||
DrawProjGroupItem *view = dynamic_cast<DrawProjGroupItem *>(*it);
|
||||
for( const auto it : Views.getValues() ) {
|
||||
auto view( dynamic_cast<DrawProjGroupItem *>(it) );
|
||||
if( view ) {
|
||||
view->ScaleType.setValue("Custom");
|
||||
view->Scale.setValue(autoScale);
|
||||
view->Scale.setStatus(App::Property::ReadOnly,true);
|
||||
|
|
|
@ -1012,10 +1012,16 @@ bool _isValidVertexes(Gui::Command* cmd) {
|
|||
//! verify that the Selection contains valid geometries for an Edge to Edge Dimension
|
||||
int _isValidEdgeToEdge(Gui::Command* cmd) {
|
||||
//TODO: can the edges be in 2 different features??
|
||||
int edgeType = isInvalid;
|
||||
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
|
||||
TechDraw::DrawViewPart* objFeat0 = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
//TechDraw::DrawViewPart* objFeat1 = dynamic_cast<TechDraw::DrawViewPart *>(selection[1].getObject());
|
||||
|
||||
auto objFeat0( dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject()) );
|
||||
// getObject() can return null pointer, or dynamic_cast can fail
|
||||
if ( !objFeat0 ) {
|
||||
Base::Console().Error("Logic error in _isValidEdgeToEdge()\n");
|
||||
return isInvalid;
|
||||
}
|
||||
|
||||
int edgeType = isInvalid;
|
||||
const std::vector<std::string> SubNames = selection[0].getSubNames();
|
||||
if(SubNames.size() == 2) { //there are 2
|
||||
if (TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge" && //they both start with "Edge"
|
||||
|
|
|
@ -264,50 +264,48 @@ void MDIViewPage::attachTemplate(TechDraw::DrawTemplate *obj)
|
|||
}
|
||||
|
||||
|
||||
int MDIViewPage::attachView(App::DocumentObject *obj)
|
||||
bool MDIViewPage::attachView(App::DocumentObject *obj)
|
||||
{
|
||||
auto typeId(obj->getTypeId());
|
||||
|
||||
QGIView *qview(nullptr);
|
||||
|
||||
if (typeId.isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId()) ) {
|
||||
qview = m_view->addViewSection( dynamic_cast<TechDraw::DrawViewSection *>(obj) );
|
||||
qview = m_view->addViewSection( static_cast<TechDraw::DrawViewSection *>(obj) );
|
||||
|
||||
} else if (typeId.isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()) ) {
|
||||
qview = m_view->addViewPart( dynamic_cast<TechDraw::DrawViewPart *>(obj) );
|
||||
qview = m_view->addViewPart( static_cast<TechDraw::DrawViewPart *>(obj) );
|
||||
|
||||
} else if (typeId.isDerivedFrom(TechDraw::DrawProjGroup::getClassTypeId()) ) {
|
||||
qview = m_view->addProjectionGroup( dynamic_cast<TechDraw::DrawProjGroup *>(obj) );
|
||||
qview = m_view->addProjectionGroup( static_cast<TechDraw::DrawProjGroup *>(obj) );
|
||||
|
||||
} else if (typeId.isDerivedFrom(TechDraw::DrawViewCollection::getClassTypeId()) ) {
|
||||
qview = m_view->addDrawView( dynamic_cast<TechDraw::DrawViewCollection *>(obj) );
|
||||
qview = m_view->addDrawView( static_cast<TechDraw::DrawViewCollection *>(obj) );
|
||||
|
||||
} else if (typeId.isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()) ) {
|
||||
qview = m_view->addViewDimension( dynamic_cast<TechDraw::DrawViewDimension *>(obj) );
|
||||
qview = m_view->addViewDimension( static_cast<TechDraw::DrawViewDimension *>(obj) );
|
||||
|
||||
} else if (typeId.isDerivedFrom(TechDraw::DrawViewAnnotation::getClassTypeId()) ) {
|
||||
qview = m_view->addDrawViewAnnotation( dynamic_cast<TechDraw::DrawViewAnnotation *>(obj) );
|
||||
qview = m_view->addDrawViewAnnotation( static_cast<TechDraw::DrawViewAnnotation *>(obj) );
|
||||
|
||||
} else if (typeId.isDerivedFrom(TechDraw::DrawViewSymbol::getClassTypeId()) ) {
|
||||
qview = m_view->addDrawViewSymbol( dynamic_cast<TechDraw::DrawViewSymbol *>(obj) );
|
||||
qview = m_view->addDrawViewSymbol( static_cast<TechDraw::DrawViewSymbol *>(obj) );
|
||||
|
||||
} else if (typeId.isDerivedFrom(TechDraw::DrawViewClip::getClassTypeId()) ) {
|
||||
qview = m_view->addDrawViewClip( dynamic_cast<TechDraw::DrawViewClip *>(obj) );
|
||||
qview = m_view->addDrawViewClip( static_cast<TechDraw::DrawViewClip *>(obj) );
|
||||
|
||||
} else if (typeId.isDerivedFrom(TechDraw::DrawViewSpreadsheet::getClassTypeId()) ) {
|
||||
qview = m_view->addDrawViewSpreadsheet( dynamic_cast<TechDraw::DrawViewSpreadsheet *>(obj) );
|
||||
qview = m_view->addDrawViewSpreadsheet( static_cast<TechDraw::DrawViewSpreadsheet *>(obj) );
|
||||
|
||||
} else if (typeId.isDerivedFrom(TechDraw::DrawHatch::getClassTypeId()) ) {
|
||||
//Hatch is not attached like other Views (since it isn't really a View)
|
||||
return true;
|
||||
|
||||
} else {
|
||||
Base::Console().Log("Logic Error - Unknown view type in MDIViewPage::attachView\n");
|
||||
}
|
||||
|
||||
if(!qview)
|
||||
return -1;
|
||||
else
|
||||
return m_view->getViews().size();
|
||||
return (qview != nullptr);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -92,7 +92,10 @@ protected:
|
|||
void findMissingViews( const std::vector<App::DocumentObject*> &list, std::vector<App::DocumentObject*> &missing);
|
||||
bool hasQView(App::DocumentObject *obj);
|
||||
bool orphanExists(const char *viewName, const std::vector<App::DocumentObject*> &list);
|
||||
int attachView(App::DocumentObject *obj);
|
||||
|
||||
/// Attaches view of obj to m_view. Returns true on success, false otherwise
|
||||
bool attachView(App::DocumentObject *obj);
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
void closeEvent(QCloseEvent*);
|
||||
QPrinter::PaperSize getPaperSize(int w, int h) const;
|
||||
|
|
|
@ -213,15 +213,19 @@ void QGIView::setPosition(qreal x, qreal y)
|
|||
|
||||
double QGIView::getYInClip(double y)
|
||||
{
|
||||
QGCustomClip* parentClip = dynamic_cast<QGCustomClip*>(parentItem());
|
||||
auto parentClip( dynamic_cast<QGCustomClip*>( parentItem() ) );
|
||||
if (parentClip) {
|
||||
QGIViewClip* parentView = dynamic_cast<QGIViewClip*>(parentClip->parentItem());
|
||||
TechDraw::DrawViewClip* parentFeat = dynamic_cast<TechDraw::DrawViewClip*>(parentView->getViewObject());
|
||||
double newY = parentFeat->Height.getValue() - y;
|
||||
return newY;
|
||||
} else {
|
||||
Base::Console().Log("Logic Error - getYInClip called for child (%s) not in Clip\n",getViewName());
|
||||
auto parentView( dynamic_cast<QGIViewClip*>( parentClip->parentItem() ) );
|
||||
if (parentView) {
|
||||
auto parentFeat( dynamic_cast<TechDraw::DrawViewClip*>(parentView->getViewObject()) );
|
||||
if (parentFeat) {
|
||||
return parentFeat->Height.getValue() - y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Base::Console().Log( "Logic Error - getYInClip called for child "
|
||||
"(%s) not in Clip\n", getViewName() );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -209,9 +209,9 @@ void QGIViewDimension::hover(bool state)
|
|||
|
||||
void QGIViewDimension::updateView(bool update)
|
||||
{
|
||||
if(getViewObject() == 0 || !getViewObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId()))
|
||||
auto dim( dynamic_cast<TechDraw::DrawViewDimension*>(getViewObject()) );
|
||||
if( dim == nullptr )
|
||||
return;
|
||||
TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension*>(getViewObject());
|
||||
|
||||
// Identify what changed to prevent complete redraw
|
||||
if(dim->Fontsize.isTouched() ||
|
||||
|
|
|
@ -464,8 +464,7 @@ void QGVPage::toggleHatch(bool enable)
|
|||
int faceItemType = QGraphicsItem::UserType + 104;
|
||||
for (auto& c:partChildren) {
|
||||
if (c->type() == faceItemType) {
|
||||
QGIFace* f = dynamic_cast<QGIFace*>(c);
|
||||
f->toggleSvg(enable);
|
||||
static_cast<QGIFace*>(c)->toggleSvg(enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user