[TD]fix active view on windows

This commit is contained in:
wandererfan
2022-09-12 09:16:24 -04:00
committed by WandererFan
parent 3ca81a7916
commit acac7decfa
3 changed files with 59 additions and 22 deletions

View File

@@ -30,6 +30,7 @@
#include <Base/Console.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/MDIView.h>
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
@@ -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<View3DInventor*>(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<View3DInventor*>(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;
}

View File

@@ -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);
};

View File

@@ -26,10 +26,11 @@
#include <QApplication>
#include <QPushButton>
#include <QStatusBar>
#include <QGraphicsScene>
#include <QMessageBox>
#include <QTemporaryFile>
#endif // #ifndef _PreComp_
#include <regex>
#include <Base/Console.h>
#include <Base/Tools.h>
@@ -46,6 +47,7 @@
#include <Gui/Document.h>
#include <Gui/MainWindow.h>
#include <Gui/Selection.h>
#include <Gui/View3DInventor.h>
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
@@ -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<View3DInventor*>(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<View3DInventor*>(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();