[TD]fix fail on missing base view (#7856)

This commit is contained in:
wandererfan
2022-11-22 16:46:13 -05:00
committed by WandererFan
parent 52398d8f58
commit cdda6f2c38
4 changed files with 46 additions and 3 deletions

View File

@@ -423,6 +423,39 @@ bool DrawProjGroup::hasProjection(const char *viewProjType) const
return false;
}
bool DrawProjGroup::canDelete(const char *viewProjType) const
{
// Base::Console().Message("DPG::canDelete(%s)\n", viewProjType);
TechDraw::DrawProjGroupItem* foundItem(nullptr);
for( const auto it : Views.getValues() ) {
auto view( dynamic_cast<TechDraw::DrawProjGroupItem *>(it) );
if (!view) {
//should never have a item in DPG that is not a DPGI.
Base::Console().Log("PROBLEM - DPG::hasProjection finds non-DPGI in Group %s / %s\n",
getNameInDocument(), viewProjType);
throw Base::TypeError("Error: projection in DPG list is not a DPGI!");
}
if (strcmp(viewProjType, view->Type.getValueAsString()) == 0 ) {
foundItem = view;
break;
}
}
if (foundItem) {
auto linkedItems = foundItem->getInList();
for (auto& item : linkedItems) {
if (item == this) {
continue;
}
if (item->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
return false;
}
}
}
return true;
}
App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType)
{
DrawProjGroupItem *view( nullptr );

View File

@@ -78,7 +78,8 @@ public:
/// Check if container has a view of a specific type
bool hasProjection(const char *viewProjType) const;
///check if it is safe to delete item
bool canDelete(const char *viewProjType) const;
App::DocumentObject * getProjObj(const char *viewProjType) const;
DrawProjGroupItem* getProjItem(const char *viewProjType) const;

View File

@@ -190,8 +190,10 @@ void TaskProjGroup::viewToggled(bool toggle)
multiView->getNameInDocument(), viewNameCStr);
changed = true;
} else if ( !toggle && multiView->hasProjection( viewNameCStr ) ) {
multiView->removeProjection( viewNameCStr );
changed = true;
if (multiView->canDelete(viewNameCStr)) {
multiView->removeProjection( viewNameCStr );
changed = true;
}
}
if (changed) {
if (multiView->ScaleType.isValue("Automatic")) {
@@ -473,6 +475,9 @@ void TaskProjGroup::setupViewCheckboxes(bool addConnections)
const char *viewStr = viewChkIndexToCStr(i);
if (viewStr && multiView->hasProjection(viewStr)) {
box->setCheckState(Qt::Checked);
if (!multiView->canDelete(viewStr)) {
box->setEnabled(false);
}
} else {
box->setCheckState(Qt::Unchecked);
}

View File

@@ -227,6 +227,10 @@ bool ViewProviderViewPart::setEdit(int ModNum)
TechDraw::DrawViewPart* dvp = getViewObject();
TechDraw::DrawViewDetail* dvd = dynamic_cast<TechDraw::DrawViewDetail*>(dvp);
if (dvd) {
if (!dvd->BaseView.getValue()) {
Base::Console().Error("DrawViewDetail - %s - has no BaseView!\n", dvd->getNameInDocument());
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
Gui::Control().showDialog(new TaskDlgDetail(dvd));