diff --git a/src/Mod/TechDraw/Gui/Grabber3d.cpp b/src/Mod/TechDraw/Gui/Grabber3d.cpp
index 79d7aa2e31..2e0edb7b6e 100644
--- a/src/Mod/TechDraw/Gui/Grabber3d.cpp
+++ b/src/Mod/TechDraw/Gui/Grabber3d.cpp
@@ -30,6 +30,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -39,27 +40,37 @@
using namespace TechDrawGui;
using namespace Gui;
-void Grabber3d::quickView(App::Document* appDoc,
- const QColor bgColor,
+void Grabber3d::quickView(const QColor bgColor,
QImage &image)
{
-// Base::Console().Message("G3d::quickView() - %d x %d\n", outWidth, outHeight);
- //get the active view
- Gui::Document* guiDoc = Gui::Application::Instance->getDocument(appDoc);
- Gui::MDIView* mdiView = guiDoc->getActiveView();
- if (mdiView == nullptr) {
- Base::Console().Warning("G3d::quickView - no ActiveView - returning\n");
+// Base::Console().Message("G3d::quickView());
+ //get a 3d view
+ if (!Gui::getMainWindow()) {
+ Base::Console().Warning("G3d::quickView - no Main Window - returning\n");
return;
}
-
+ Gui::MainWindow* mainWindow = Gui::getMainWindow();
+ Gui::MDIView* mdiView = Gui::getMainWindow()->activeWindow();
View3DInventor* view3d = qobject_cast(mdiView);
- if (view3d == nullptr) {
- Base::Console().Warning("G3d::quickView - no viewer for ActiveView - returning\n");
+ if (!view3d) {
+ //the active window is not a 3D view, so try to find one
+ auto mdiWindows = mainWindow->windows();
+ for (auto& mdi : mdiWindows) {
+ auto mdiView = qobject_cast(mdi);
+ if (mdiView) {
+ view3d = mdiView;
+ break;
+ }
+ }
+ }
+
+ if (!view3d) {
+ Base::Console().Warning("G3d::quickView - no 3D view for ActiveView - returning\n");
return;
}
View3DInventorViewer* viewer = view3d->getViewer();
- if (viewer == nullptr) {
+ if (!viewer) {
Base::Console().Warning("G3d::quickView - could not create viewer - returning\n");
return;
}
diff --git a/src/Mod/TechDraw/Gui/Grabber3d.h b/src/Mod/TechDraw/Gui/Grabber3d.h
index 98372892e0..715a7d3016 100644
--- a/src/Mod/TechDraw/Gui/Grabber3d.h
+++ b/src/Mod/TechDraw/Gui/Grabber3d.h
@@ -38,8 +38,7 @@ namespace TechDrawGui
/// Utility functions for obtaining 3d window image
class TechDrawGuiExport Grabber3d {
public:
- static void quickView(App::Document* appDoc,
- const QColor bgColor,
+ static void quickView(const QColor bgColor,
QImage &image);
};
diff --git a/src/Mod/TechDraw/Gui/TaskActiveView.cpp b/src/Mod/TechDraw/Gui/TaskActiveView.cpp
index 3c3bec1e4e..faa3c73a90 100644
--- a/src/Mod/TechDraw/Gui/TaskActiveView.cpp
+++ b/src/Mod/TechDraw/Gui/TaskActiveView.cpp
@@ -26,10 +26,11 @@
#include
#include
#include
-#include
+#include
#include
#endif // #ifndef _PreComp_
+#include
#include
#include
@@ -46,6 +47,7 @@
#include
#include
#include
+#include
#include
#include
@@ -114,6 +116,30 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
{
// Base::Console().Message("TAV::createActiveView()\n");
+ //make sure there is an 3D MDI to grab!!
+ if (!Gui::getMainWindow()) {
+ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No Main Window"),
+ QObject::tr("Can not find the main window"));
+ return nullptr;
+ }
+ View3DInventor* view3d = qobject_cast(Gui::getMainWindow()->activeWindow());
+ if (!view3d) {
+ //the active window is not a 3D view, so try to find one
+ auto mdiWindows = Gui::getMainWindow()->windows();
+ for (auto& mdi : mdiWindows) {
+ auto mdiView = qobject_cast(mdi);
+ if (mdiView) {
+ view3d = mdiView;
+ break;
+ }
+ }
+ }
+ if (!view3d) {
+ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No 3D Viewer"),
+ QObject::tr("Can not find a 3D viewer"));
+ return nullptr;
+ }
+
std::string imageName = m_pageFeat->getDocument()->getUniqueObjectName("ActiveView");
std::string imageType = "TechDraw::DrawViewImage";
@@ -124,8 +150,6 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",
pageName.c_str(), imageName.c_str());
- App::Document* appDoc = m_pageFeat->getDocument();
-
App::Document* doc = m_pageFeat->getDocument();
std::string special = "/" + imageName + "image.png";
std::string dir = doc->TransientDir.getValue();
@@ -141,15 +165,16 @@ TechDraw::DrawViewImage* TaskActiveView::createActiveView()
QImage image(100, 100, QImage::Format_RGB32); //arbitrary initial image size. quickView will use
//MdiView size in pixels
image.fill(QColor(Qt::transparent));
- Grabber3d:: quickView(appDoc,
- bg,
- image);
+ Grabber3d:: quickView(bg, image);
bool success = image.save(Base::Tools::fromStdString(fileSpec));
if (!success) {
Base::Console().Error("ActiveView could not save file: %s\n", fileSpec.c_str());
}
- Command::doCommand(Command::Doc,"App.activeDocument().%s.ImageFile = '%s'",imageName.c_str(), fileSpec.c_str());
+ //backslashes in windows fileSpec upsets python
+ std::regex rxBackslash("\\\\");
+ std::string noBackslash = std::regex_replace(fileSpec, rxBackslash, "/");
+ Command::doCommand(Command::Doc,"App.activeDocument().%s.ImageFile = '%s'",imageName.c_str(), noBackslash.c_str());
Command::doCommand(Command::Doc,"App.activeDocument().%s.Width = %.5f",imageName.c_str(), ui->qsbWidth->rawValue());
Command::doCommand(Command::Doc,"App.activeDocument().%s.Height = %.5f",imageName.c_str(), ui->qsbHeight->rawValue());
@@ -197,7 +222,9 @@ bool TaskActiveView::accept()
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create ActiveView"));
m_imageFeat = createActiveView();
// m_imageFeat->requestPaint();
- m_imageFeat->recomputeFeature();
+ if (m_imageFeat) {
+ m_imageFeat->recomputeFeature();
+ }
Gui::Command::updateActive();
Gui::Command::commitCommand();