| 2302 | } |
| 2303 | |
| 2304 | MDIView* Document::createView(const Base::Type& typeId, CreateViewMode mode) |
| 2305 | { |
| 2306 | if (!typeId.isDerivedFrom(MDIView::getClassTypeId())) { |
| 2307 | return nullptr; |
| 2308 | } |
| 2309 | |
| 2310 | std::list<MDIView*> theViews = this->getMDIViewsOfType(typeId); |
| 2311 | if (typeId == View3DInventor::getClassTypeId()) { |
| 2312 | |
| 2313 | QOpenGLWidget* shareWidget = nullptr; |
| 2314 | // VBO rendering doesn't work correctly when we don't share the OpenGL widgets |
| 2315 | if (!theViews.empty()) { |
| 2316 | auto firstView = static_cast<View3DInventor*>(theViews.front()); |
| 2317 | shareWidget = qobject_cast<QOpenGLWidget*>(firstView->getViewer()->getGLWidget()); |
| 2318 | |
| 2319 | const std::string& camera = firstView->getCamera(); |
| 2320 | saveCameraSettings(camera.c_str()); |
| 2321 | } |
| 2322 | |
| 2323 | auto view3D = new View3DInventor(this, getMainWindow(), shareWidget); |
| 2324 | if (!theViews.empty()) { |
| 2325 | auto firstView = static_cast<View3DInventor*>(theViews.front()); |
| 2326 | std::string overrideMode = firstView->getViewer()->getOverrideMode(); |
| 2327 | view3D->getViewer()->setOverrideMode(overrideMode); |
| 2328 | } |
| 2329 | |
| 2330 | // attach the viewproviders. we need to make sure that we only attach the toplevel ones |
| 2331 | // and not viewproviders which are claimed by other providers. To ensure this we first |
| 2332 | // add all providers and then remove the ones already claimed |
| 2333 | |
| 2334 | std::vector<App::DocumentObject*> child_vps; |
| 2335 | for (const auto& vp : d->_ViewProviderMap) { |
| 2336 | view3D->getViewer()->addViewProvider(vp.second); |
| 2337 | std::vector<App::DocumentObject*> children = vp.second->claimChildren3D(); |
| 2338 | child_vps.insert(child_vps.end(), children.begin(), children.end()); |
| 2339 | } |
| 2340 | |
| 2341 | for (const auto& va : d->_ViewProviderMapAnnotation) { |
| 2342 | view3D->getViewer()->addViewProvider(va.second); |
| 2343 | std::vector<App::DocumentObject*> children = va.second->claimChildren3D(); |
| 2344 | child_vps.insert(child_vps.end(), children.begin(), children.end()); |
| 2345 | } |
| 2346 | |
| 2347 | for (App::DocumentObject* obj : child_vps) { |
| 2348 | view3D->getViewer()->removeViewProvider(getViewProvider(obj)); |
| 2349 | } |
| 2350 | |
| 2351 | // When cloning the view, don't increment the window counter as the old view will be deleted |
| 2352 | // shortly after. |
| 2353 | if (mode != CreateViewMode::Clone) { |
| 2354 | const char* name = getDocument()->Label.getValue(); |
| 2355 | QString title |
| 2356 | = QStringLiteral("%1 : %2[*]").arg(QString::fromUtf8(name)).arg(d->_iWinCount++); |
| 2357 | |
| 2358 | view3D->setWindowTitle(title); |
| 2359 | } |
| 2360 | |
| 2361 | view3D->setWindowModified(this->isModified()); |
no test coverage detected