Part: fix dangerous static_cast usage in view provider

Because Gui::ViewProviderLink can be used to override the view provider
of any object, it is not safe to assume view provider type without
explicit checking.
This commit is contained in:
Zheng, Lei
2020-09-06 16:01:16 +08:00
committed by wwmayer
parent 2d11f16e9d
commit 18c0d8ab12
3 changed files with 40 additions and 34 deletions

View File

@@ -111,15 +111,17 @@ void ViewProviderCompound::updateData(const App::Property* prop)
TopTools_IndexedMapOfShape baseMap;
TopExp::MapShapes(baseShape, TopAbs_FACE, baseMap);
Gui::ViewProvider* vpBase = Gui::Application::Instance->getViewProvider(objBase);
std::vector<App::Color> baseCol = static_cast<PartGui::ViewProviderPart*>(vpBase)->DiffuseColor.getValues();
applyTransparency(static_cast<PartGui::ViewProviderPart*>(vpBase)->Transparency.getValue(),baseCol);
if (static_cast<int>(baseCol.size()) == baseMap.Extent()) {
applyColor(hist[index], baseCol, compCol);
}
else if (!baseCol.empty() && baseCol[0] != this->ShapeColor.getValue()) {
baseCol.resize(baseMap.Extent(), baseCol[0]);
applyColor(hist[index], baseCol, compCol);
auto vpBase = dynamic_cast<PartGui::ViewProviderPart*>(Gui::Application::Instance->getViewProvider(objBase));
if (vpBase) {
std::vector<App::Color> baseCol = vpBase->DiffuseColor.getValues();
applyTransparency(vpBase->Transparency.getValue(),baseCol);
if (static_cast<int>(baseCol.size()) == baseMap.Extent()) {
applyColor(hist[index], baseCol, compCol);
}
else if (!baseCol.empty() && baseCol[0] != this->ShapeColor.getValue()) {
baseCol.resize(baseMap.Extent(), baseCol[0]);
applyColor(hist[index], baseCol, compCol);
}
}
}