From b97c93008ecdee4402025c4bc2f2b5b0a9ffafc9 Mon Sep 17 00:00:00 2001 From: Wanderer Fan Date: Thu, 23 Jun 2022 10:39:59 -0400 Subject: [PATCH] [TD]simplify ActiveView - remove copyActiveViewToSvgFile - use bitmap image instead of Svg - upgrade Task with crop options --- src/Mod/TechDraw/App/DrawViewImage.cpp | 14 +- src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp | 67 ----- src/Mod/TechDraw/Gui/Grabber3d.cpp | 321 ++-------------------- src/Mod/TechDraw/Gui/Grabber3d.h | 48 +--- src/Mod/TechDraw/Gui/TaskActiveView.cpp | 104 +++---- src/Mod/TechDraw/Gui/TaskActiveView.h | 6 +- src/Mod/TechDraw/Gui/TaskActiveView.ui | 204 +++++--------- 7 files changed, 163 insertions(+), 601 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewImage.cpp b/src/Mod/TechDraw/App/DrawViewImage.cpp index 1d3ff8457a..c1babd3647 100644 --- a/src/Mod/TechDraw/App/DrawViewImage.cpp +++ b/src/Mod/TechDraw/App/DrawViewImage.cpp @@ -59,7 +59,10 @@ DrawViewImage::DrawViewImage() "Embedded image file. System use only."); // n/a to end users ADD_PROPERTY_TYPE(Width ,(100), vgroup, App::Prop_None, "The width of cropped image"); ADD_PROPERTY_TYPE(Height ,(100), vgroup, App::Prop_None, "The height of cropped image"); + ScaleType.setValue("Custom"); + Scale.setStatus(App::Property::Hidden, false); + Scale.setStatus(App::Property::ReadOnly, false); std::string imgFilter("Image files (*.jpg *.jpeg *.png);;All files (*)"); ImageFile.setFilter(imgFilter); @@ -84,11 +87,12 @@ void DrawViewImage::onChanged(const App::Property* prop) short DrawViewImage::mustExecute() const { - if (!isRestoring()) { - if (Height.isTouched() || - Width.isTouched()) { - return true; - }; + if (isRestoring()) { + return App::DocumentObject::mustExecute(); + } + if (Height.isTouched() || + Width.isTouched()) { + return 1; } return App::DocumentObject::mustExecute(); diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp index 53014d0f74..1620040789 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp @@ -53,7 +53,6 @@ #include "QGIView.h" #include "ViewProviderPage.h" #include "ViewProviderDrawingView.h" -#include "Grabber3d.h" namespace TechDrawGui { @@ -71,9 +70,6 @@ public: add_varargs_method("exportPageAsSvg", &Module::exportPageAsSvg, "exportPageAsSvg(DrawPageObject, FilePath) -- print page as Svg to file." ); - add_varargs_method("copyActiveViewToSvgFile", &Module::copyActiveViewToSvgFile, - "copyActiveViewToSvgFile(DrawPageObject, FilePath) -- copy ActiveView to Svg file." - ); add_varargs_method("addQGIToView", &Module::addQGIToView, "addQGIToView(View, QGraphicsItem) -- insert graphics item into view's graphic." ); @@ -258,69 +254,6 @@ private: return Py::None(); } -//!copyActiveViewToSvgFile(document, fileSpec) - Py::Object copyActiveViewToSvgFile(const Py::Tuple& args) - { - double result = 1.0; - PyObject *docObj = nullptr; - PyObject *colorObj = nullptr; - PyObject *paintObj = Py_True; - char* name; - - App::Document* appDoc = nullptr; - std::string fileSpec; - double outWidth = 138.5; //TODO: change to A4 for release - double outHeight = 95.0; //ISO A5 defaults - bool paintBackground = true; - QColor bgColor = QColor(Qt::white); - double lineWidth = 1.0; //1 mm - double border = 0.0; //no border - int mode = 0; //SoRenderManager::RenderMode(0) - AS_IS - - if (!PyArg_ParseTuple(args.ptr(), "Oet|ddOOddi", - &docObj, "utf-8", &name, - &outWidth, &outHeight, - &paintObj, &colorObj, - &lineWidth, &border, - &mode)) { - throw Py::TypeError("expected (doc, file|, options)"); - } - - fileSpec = std::string(name); - PyMem_Free(name); - - if (paintObj == Py_True) { - paintBackground = true; - } else { - paintBackground = false; - } - - - try { - if (PyObject_TypeCheck(docObj, &(App::DocumentPy::Type))) { - appDoc = static_cast(docObj)->getDocumentPtr(); - if (colorObj && PyTuple_Check(colorObj)) { - App::Color c = TechDraw::DrawUtil::pyTupleToColor(colorObj); - bgColor = c.asValue(); - } - result = - Grabber3d::copyActiveViewToSvgFile(appDoc, fileSpec, - outWidth, outHeight, - paintBackground, bgColor, - lineWidth, border, - mode); //TODO: add svg scale factor? - } - } - catch (Base::Exception &e) { - e.setPyException(); - throw Py::Exception(); - } - - PyObject* pyResult = nullptr; - pyResult = PyFloat_FromDouble(result); - return Py::asObject(pyResult); - } - Py::Object addQGIToView(const Py::Tuple& args) { PyObject *viewPy = nullptr; diff --git a/src/Mod/TechDraw/Gui/Grabber3d.cpp b/src/Mod/TechDraw/Gui/Grabber3d.cpp index 436f4b3e3a..79d7aa2e31 100644 --- a/src/Mod/TechDraw/Gui/Grabber3d.cpp +++ b/src/Mod/TechDraw/Gui/Grabber3d.cpp @@ -23,329 +23,54 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + #endif +#include #include #include #include -#include #include -#include #include #include -#include #include "Grabber3d.h" - using namespace TechDrawGui; -using namespace TechDraw; using namespace Gui; - //notes for selection view - //SoSeparator* newSG; - //for obj in objList: - // vProv = obj.ViewObject - // sg = vProv.getSG(obj); - // for child in sg: - // newSG->addChild(); - // - -//creates Svg file and returns estimate of scale -double Grabber3d::copyActiveViewToSvgFile(App::Document* appDoc, - std::string fileSpec, - double outWidth, double outHeight, - bool paintBackground, const QColor& bgColor, - double lineWidth, double border, - int renderMode) +void Grabber3d::quickView(App::Document* appDoc, + const QColor bgColor, + QImage &image) { -// Base::Console().Message("G3d::copyActiveViewToSvgFile()\n"); - double result = 1.0; //best estimate of scale of result - +// 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) { - Base::Console().Warning("G3d::copyActiveViewToSvgFile - no ActiveView - returning\n"); - return result; + if (mdiView == nullptr) { + Base::Console().Warning("G3d::quickView - no ActiveView - returning\n"); + return; } View3DInventor* view3d = qobject_cast(mdiView); - if (!view3d) { - Base::Console().Warning("G3d::copyActiveViewToSvgFile - no viewer for ActiveView - returning\n"); - return result; + if (view3d == nullptr) { + Base::Console().Warning("G3d::quickView - no viewer for ActiveView - returning\n"); + return; } View3DInventorViewer* viewer = view3d->getViewer(); - if (!viewer) { - Base::Console().Warning("G3d::copyActiveViewToSvgFile - could not create viewer - returning\n"); - return result; + if (viewer == nullptr) { + Base::Console().Warning("G3d::quickView - could not create viewer - returning\n"); + return; } + //figure out the size of the active MdiView + SbViewportRegion vport(viewer->getSoRenderManager()->getViewportRegion()); + SbVec2s vpSize = vport.getViewportSizePixels(); + short width; + short height; + vpSize.getValue(width, height); - //save parameters of source view - double mdiWidth = view3d->width(); - double mdiHigh = view3d->height(); - - SbViewportRegion sourceVPRegion = viewer->getSoRenderManager()->getViewportRegion(); - SoCamera* sourceCam = viewer->getSoRenderManager()->getCamera(); - SbRotation sourceOrient = viewer->getCameraOrientation(); - SbVec3f sourcePos = viewer->getSoRenderManager()->getCamera()->position.getValue(); - double sourceNear = viewer->getSoRenderManager()->getCamera()->nearDistance.getValue(); - double sourceFar = viewer->getSoRenderManager()->getCamera()->farDistance.getValue(); - double sourceFocal = viewer->getSoRenderManager()->getCamera()->focalDistance.getValue(); - double sourceAspect = viewer->getSoRenderManager()->getCamera()->aspectRatio.getValue(); - SoOrthographicCamera* oCam = nullptr; - SoPerspectiveCamera* pCam = nullptr; - double sourceHeight = 0.0; - double sourceAngle = 45.0; - if (sourceCam->getTypeId() == SoOrthographicCamera::getClassTypeId()) { - oCam = static_cast(sourceCam); - sourceHeight = oCam->height.getValue(); - } else if (sourceCam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) { - pCam = static_cast(sourceCam); - sourceAngle = pCam->heightAngle.getValue(); - } - oCam = nullptr; - pCam = nullptr; - - //make a view for rendering Svg - View3DInventor* view3DI = new View3DInventor(nullptr, nullptr); //essentially an undisplayed mdi -// view3DI->setWindowTitle(QString::fromUtf8("SvgRenderViewer")); //fluff -// Gui::getMainWindow()->addWindow(view3DI); //just for debugging. comment for release. - - View3DInventorViewer* viewerSvg = view3DI->getViewer(); - viewerSvg->setBackgroundColor(QColor(Qt::white)); - - SoRenderManager* renderMgr = viewerSvg->getSoRenderManager(); - renderMgr->setRenderMode(SoRenderManager::RenderMode(renderMode)); - - SbViewportRegion targetVPRegion; - targetVPRegion.setWindowSize(mdiWidth, mdiHigh); - targetVPRegion.setPixelsPerInch(sourceVPRegion.getPixelsPerInch()); - renderMgr->setViewportRegion(targetVPRegion); - - auto sgOld = viewer->getSceneGraph(); - SoSeparator* sgNew = copySceneGraph(sgOld); - viewerSvg->setSceneGraph(sgNew); - - if (sourceCam->getTypeId() == SoOrthographicCamera::getClassTypeId()) { - viewerSvg->setCameraType(SoOrthographicCamera::getClassTypeId()); - } else if (sourceCam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) { - viewerSvg->setCameraType(SoPerspectiveCamera::getClassTypeId()); - } - -// SoWriteAction writeAction; //dump the IV (debugging) -// writeAction.apply(sgNew); - - //set Svg view params to match source - SoCamera* svgCam = viewerSvg->getSoRenderManager()->getCamera(); - double zoomFactor = 1.0; //not used - svgCam->orientation.setValue(sourceOrient); - svgCam->position.setValue(sourcePos); - svgCam->nearDistance.setValue(sourceNear); - svgCam->farDistance.setValue(sourceFar); - svgCam->focalDistance.setValue(sourceFocal); - svgCam->aspectRatio.setValue(sourceAspect); - if (svgCam->getTypeId() == SoOrthographicCamera::getClassTypeId()) { - SoOrthographicCamera* oSvgCam = static_cast(svgCam); - double newHeight = sourceHeight * zoomFactor; - oSvgCam->height.setValue(newHeight); - } else if (svgCam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) { - SoPerspectiveCamera* vSvgCam = static_cast(svgCam); - vSvgCam->heightAngle.setValue(sourceAngle); - } - - viewerSvg->redraw(); - - std::unique_ptr va; - va = std::unique_ptr(new SoFCVectorizeSVGAction()); - - SoVectorOutput* out = va->getOutput(); - if (!out || !out->openFile(fileSpec.c_str())) { - Base::Console().Error("G3D::copyActiveViewToSvgFile - can not open file - %s/n", fileSpec.c_str()); - return result; - } - execVectorizeAction(viewerSvg, - va.get(), - outWidth, outHeight, - paintBackground, bgColor, - lineWidth, border); - - out->closeFile(); - - result = getViewerScale(viewerSvg); //screen : world - - double pScale = getPaperScale(viewerSvg, outWidth, outHeight); - - //TODO: figure out net scaling world -> screen -> paper - Base::Console().Log( - "G3d::copyActiveViewToSvgFile - approx screen:world scale: 1:%.5f w/ort pixel size issues\n", - result); - Base::Console().Log( - "G3d::copyActiveViewToSvgFile - approx paper/screen scale: 1:%.5f w/ort pixel size issues\n", - pScale); - -// postProcessSvg(fileSpec); - - view3DI->close(); //comment out for debugging - - viewerSvg->setSceneGraph(nullptr); - sgNew->unref(); - sgNew = nullptr; - - return result; + int samples = 8; //magic number from Gui::View3DInventorViewer + viewer->savePicture(width, height, samples, bgColor, image); } -//============================================================================== - -SoSeparator* Grabber3d::copySceneGraph(SoNode* sgIn) -{ -// Base::Console().Message("G3d::copySceneGraph()\n"); - SoSeparator* result = new SoSeparator(); - - SoDirectionalLight* newLight = new SoDirectionalLight; - result->addChild(newLight); - - SoNodeList* sgChildren = sgIn->getChildren(); - int childSize = sgChildren->getLength(); - - //gather up the nodes to display - for (int i=0; i < childSize; i++) { - SoNode* c = (*sgChildren)[i]; - if (c->isOfType(SoGroup::getClassTypeId())) { - auto cCopy = c->copy(); - result->addChild(cCopy); - } - } - - result->ref(); - return result; -} - -//============================================================================== - -//loosely based on View3DInventorViewer::saveGraphic -void Grabber3d::execVectorizeAction(Gui::View3DInventorViewer* viewer, - SoVectorizeAction* va, - double width, double height, - bool paintBackground, const QColor& bgColor, - double lineWidth, double border) -{ -// Base::Console().Message("G3d::execVectorizeAction() - va: %X\n", va); - if (va->getTypeId() == SoFCVectorizeSVGAction::getClassTypeId()) { - SoFCVectorizeSVGAction* vaFC = static_cast(va); - vaFC->setBackgroundState(paintBackground); - vaFC->setLineWidth(lineWidth); - vaFC->setUseMM(true); - } - - if (paintBackground && bgColor.isValid()) { - va->setBackgroundColor(true, SbColor(bgColor.redF(), bgColor.greenF(), bgColor.blueF())); - } else { - va->setBackgroundColor(false); - } - va->setOrientation(SoVectorizeAction::PORTRAIT); //don't play with my w x h - - va->beginPage(SbVec2f(border, border), SbVec2f(width, height)); - va->beginViewport(); - va->calibrate(viewer->getSoRenderManager()->getViewportRegion()); - va->apply(viewer->getSoRenderManager()->getSceneGraph()); - va->endViewport(); - va->endPage(); -} - -//============================================================================== -//find scale factor screen:world -double Grabber3d::getViewerScale(Gui::View3DInventorViewer* viewer) -{ -// Base::Console().Message("G3d::getViewerScale()\n"); - - double result = 1; -// double printerpxmm = 3.94; //? 100 dpi? - double coinpxmm = 2.83; //72 dpi - - //accurate dpmm for screen is not easily acquired! -// double qtpxmm = 96; -// QScreen *screen = QGuiApplication::primaryScreen(); -// double qtppi = screen->physicalDotsPerInch(); //~111 dpi -// qtpxmm = qtppi / 25.4; - - SbViewportRegion vpRegion = viewer->getSoRenderManager()->getViewportRegion(); - SbVec2s winSizePx = vpRegion.getWindowSize(); //pixel coords - - Base::Vector3d p1v(0, 0,0); - Base::Vector3d p2v(winSizePx[0] - 1, winSizePx[1] - 1); - double screenLengthpx = (p2v - p1v).Length(); //length in pixels - double screenLengthmm = (screenLengthpx / coinpxmm); - - SbVec2s p1s(0, 0); - SbVec2s p2s(winSizePx[0] - 1, winSizePx[1] - 1); - SbVec3f p1w = viewer->getPointOnFocalPlane(p1s); - SbVec3f p2w = viewer->getPointOnFocalPlane(p2s); - double worldLengthmm = (p2w - p1w).length(); //mm - - result = worldLengthmm / screenLengthmm; - return result; -} -//============================================================================== - -//find scale factor screen:"paper" -double Grabber3d::getPaperScale(Gui::View3DInventorViewer* viewer, - double pWidth, double pHeight) -{ -// Base::Console().Message("G3d::getPaperScale()\n"); - - double result = 1; -// double printerpxmm = 3.94; //? 100 dpi? - double coinpxmm = 2.83; //72 dpi - - //accurate dpmm for screen is not easily acquired! -// double qtpxmm = 96; -// QScreen *screen = QGuiApplication::primaryScreen(); -// double qtppi = screen->physicalDotsPerInch(); //~111 dpi -// qtpxmm = qtppi / 25.4; - - SbViewportRegion vpRegion = viewer->getSoRenderManager()->getViewportRegion(); - SbVec2s winSizePx = vpRegion.getWindowSize(); //pixel coords - - Base::Vector3d p1v(0, 0,0); - Base::Vector3d p2v(winSizePx[0] - 1, winSizePx[1] - 1); - double screenLengthpx = (p2v - p1v).Length(); //length in pixels - -// double screenLengthmm = (screenLengthpx / qtpxmm); - double screenLengthmm = (screenLengthpx / coinpxmm); - - double paperLengthmm = sqrt( pow(pWidth, 2) + pow(pHeight, 2)); - - result = paperLengthmm / screenLengthmm; - - double paperLengthpx = sqrt( pow(pWidth*coinpxmm, 2) + pow(pHeight*coinpxmm, 2)); - double resultpx = paperLengthpx / screenLengthpx; - Base::Console().Log("G3d::getPaperScale - screenLenpx: %.3f paperLenpx: %.3f resultpx: %.3f\n", - screenLengthpx, paperLengthpx, resultpx); - - Base::Console().Log("G3d::getPaperScale - screenLen: %.3f paperLen: %.3f result: %.3f\n", - screenLengthmm, paperLengthmm, result); - return result; -} - -//============================================================================== - -void Grabber3d::postProcessSvg(std::string fileSpec) -{ - (void) fileSpec; -} diff --git a/src/Mod/TechDraw/Gui/Grabber3d.h b/src/Mod/TechDraw/Gui/Grabber3d.h index fdffa87216..98372892e0 100644 --- a/src/Mod/TechDraw/Gui/Grabber3d.h +++ b/src/Mod/TechDraw/Gui/Grabber3d.h @@ -25,27 +25,11 @@ #include -class SoSeparator; -class SoCamera; -class SoNode; -class SbVec2s; -class SbVec2f; -class SbVec2d; -class SoVectorizeAction; +#include +#include namespace App { class Document; -class DocumentObject; -class NavigationStyle; -} -namespace Gui { -class Document; -class View3DInventorViewer; -} - -#include "MDIViewPage.h" - -namespace TechDraw { } namespace TechDrawGui @@ -53,30 +37,10 @@ namespace TechDrawGui /// Utility functions for obtaining 3d window image class TechDrawGuiExport Grabber3d { - public: - static double copyActiveViewToSvgFile(App::Document* appDoc, - std::string fileSpec, - double outWidth = 138.5, //TODO: change to A4 for release - double outHeight = 95.0, //ISO A5 defaults - bool paintBackground = true, - const QColor& bgcolor = QColor(Qt::white), - double lineWidth = 1.0, //1 mm - double border = 0.0, //no border - int mode = 0); //SoRenderManager::RenderMode(0) - AS_IS - - static SoSeparator* copySceneGraph(SoNode* sgIn); - - static void execVectorizeAction(Gui::View3DInventorViewer* viewer, - SoVectorizeAction* va, - double width, double height, - bool paintBackground, const QColor& bgcolor, - double lineWidth, double border); - - static double getViewerScale(Gui::View3DInventorViewer* viewer); - static double getPaperScale(Gui::View3DInventorViewer* viewer, - double pWidth, double pHeight); - - static void postProcessSvg(std::string fileSpec); +public: + static void quickView(App::Document* appDoc, + const QColor bgColor, + QImage &image); }; } //end namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/TaskActiveView.cpp b/src/Mod/TechDraw/Gui/TaskActiveView.cpp index 41d2a41f6d..3c3bec1e4e 100644 --- a/src/Mod/TechDraw/Gui/TaskActiveView.cpp +++ b/src/Mod/TechDraw/Gui/TaskActiveView.cpp @@ -37,6 +37,8 @@ #include +#include + #include #include #include @@ -51,14 +53,12 @@ #include #include #include +#include #include -#include "QGVPage.h" -#include "QGIView.h" #include "Grabber3d.h" -#include "Rez.h" - +#include "ViewProviderImage.h" #include "TaskActiveView.h" using namespace Gui; @@ -69,7 +69,7 @@ using namespace TechDrawGui; TaskActiveView::TaskActiveView(TechDraw::DrawPage* pageFeat) : ui(new Ui_TaskActiveView), m_pageFeat(pageFeat), - m_symbolFeat(nullptr), + m_imageFeat(nullptr), m_btnOK(nullptr), m_btnCancel(nullptr) { @@ -77,7 +77,6 @@ TaskActiveView::TaskActiveView(TechDraw::DrawPage* pageFeat) : ui->qsbWidth->setUnit(Base::Unit::Length); ui->qsbHeight->setUnit(Base::Unit::Length); - ui->qsbBorder->setUnit(Base::Unit::Length); setUiPrimary(); } @@ -111,55 +110,68 @@ void TaskActiveView::blockButtons(bool b) Q_UNUSED(b); } -//****************************************************************************** -TechDraw::DrawViewSymbol* TaskActiveView::createActiveView() +TechDraw::DrawViewImage* TaskActiveView::createActiveView() { // Base::Console().Message("TAV::createActiveView()\n"); - std::string symbolName = m_pageFeat->getDocument()->getUniqueObjectName("ActiveView"); - std::string symbolType = "TechDraw::DrawViewSymbol"; + std::string imageName = m_pageFeat->getDocument()->getUniqueObjectName("ActiveView"); + std::string imageType = "TechDraw::DrawViewImage"; std::string pageName = m_pageFeat->getNameInDocument(); - Command::doCommand(Command::Doc, "App.activeDocument().addObject('%s', '%s')", - symbolType.c_str(), symbolName.c_str()); - Command::doCommand(Command::Doc, "App.activeDocument().%s.addView(App.activeDocument().%s)", - pageName.c_str(), symbolName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().addObject('%s','%s')", + imageType.c_str(),imageName.c_str()); + Command::doCommand(Command::Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)", + pageName.c_str(), imageName.c_str()); App::Document* appDoc = m_pageFeat->getDocument(); - QTemporaryFile tempFile; - if (!tempFile.open()) { //open() creates temp file - Base::Console().Error("TAV::createActiveView - could not open temp file\n"); - return nullptr; - } - tempFile.close(); - std::string fileSpec = Base::Tools::toStdString(tempFile.fileName()); - fileSpec = Base::Tools::escapeEncodeFilename(fileSpec); + App::Document* doc = m_pageFeat->getDocument(); + std::string special = "/" + imageName + "image.png"; + std::string dir = doc->TransientDir.getValue(); + std::string fileSpec = dir + special; - //double estScale = - Grabber3d::copyActiveViewToSvgFile(appDoc, fileSpec, - ui->qsbWidth->rawValue(), - ui->qsbHeight->rawValue(), - ui->cbbg->isChecked(), - ui->ccBgColor->color(), - ui->qsbWeight->rawValue(), - ui->qsbBorder->rawValue(), - ui->cbMode->currentIndex()); - Command::doCommand(Command::Doc, "f = open(\"%s\", 'r')", (const char*)fileSpec.c_str()); - Command::doCommand(Command::Doc, "svg = f.read()"); -// Command::doCommand(Command::Doc, "print('length of svg: {}'.format(len(svg)))"); - - Command::doCommand(Command::Doc, "f.close()"); - Command::doCommand(Command::Doc, "App.activeDocument().%s.Symbol = svg", symbolName.c_str()); - - App::DocumentObject* newObj = m_pageFeat->getDocument()->getObject(symbolName.c_str()); - TechDraw::DrawViewSymbol* newSym = dynamic_cast(newObj); - if (!newObj || !newSym) { - throw Base::RuntimeError("TaskActiveView - new symbol object not found"); + QColor bg = ui->ccBgColor->color(); + if (ui->cbUse3d->isChecked()) { + bg = QColor(); + } else if (ui->cbNoBG->isChecked()) { + bg = QColor(Qt::transparent); } - return newSym; + 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); + 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()); + 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()); + + App::DocumentObject* newObj = m_pageFeat->getDocument()->getObject(imageName.c_str()); + TechDraw::DrawViewImage* newImg = dynamic_cast(newObj); + if ( (newObj == nullptr) || + (newImg == nullptr) ) { + throw Base::RuntimeError("TaskActiveView - new image object not found"); + } + Gui::Document* guiDoc = Gui::Application::Instance->getDocument(newImg->getDocument()); + if (guiDoc) { + Gui::ViewProvider* vp = guiDoc->getViewProvider(newImg); + if (vp) { + auto vpImage = dynamic_cast(vp); + if (vpImage) { + vpImage->Crop.setValue(ui->cbCrop->isChecked()); + } + } + } + + + return newImg; } //****************************************************************************** @@ -183,9 +195,9 @@ bool TaskActiveView::accept() { // Base::Console().Message("TAV::accept()\n"); Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create ActiveView")); - m_symbolFeat = createActiveView(); -// m_symbolFeat->requestPaint(); - m_symbolFeat->recomputeFeature(); + m_imageFeat = createActiveView(); +// m_imageFeat->requestPaint(); + m_imageFeat->recomputeFeature(); Gui::Command::updateActive(); Gui::Command::commitCommand(); diff --git a/src/Mod/TechDraw/Gui/TaskActiveView.h b/src/Mod/TechDraw/Gui/TaskActiveView.h index 8c38c95a8e..266064812e 100644 --- a/src/Mod/TechDraw/Gui/TaskActiveView.h +++ b/src/Mod/TechDraw/Gui/TaskActiveView.h @@ -36,7 +36,7 @@ namespace TechDraw { class DrawPage; class DrawView; -class DrawViewSymbol; +class DrawViewImage; } namespace TechDrawGui @@ -70,13 +70,13 @@ protected: void blockButtons(bool b); void setUiPrimary(void); - TechDraw::DrawViewSymbol* createActiveView(void); + TechDraw::DrawViewImage* createActiveView(); private: std::unique_ptr ui; TechDraw::DrawPage* m_pageFeat; - TechDraw::DrawViewSymbol* m_symbolFeat; + TechDraw::DrawViewImage* m_imageFeat; QPushButton* m_btnOK; QPushButton* m_btnCancel; diff --git a/src/Mod/TechDraw/Gui/TaskActiveView.ui b/src/Mod/TechDraw/Gui/TaskActiveView.ui index ca22f4ae2c..ec806aa83d 100644 --- a/src/Mod/TechDraw/Gui/TaskActiveView.ui +++ b/src/Mod/TechDraw/Gui/TaskActiveView.ui @@ -7,7 +7,7 @@ 0 0 375 - 176 + 191 @@ -31,15 +31,8 @@ - - - - - Width - - - - + + @@ -48,7 +41,7 @@ - Width of generated view + If Crop Image is checked, crop captured image to this width. Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -60,19 +53,15 @@ 0.000000000000000 - 297.000000000000000 + 100.000000000000000 - - - - Height + + + + false - - - - 0 @@ -80,63 +69,11 @@ - Height of generated view - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 0.000000000000000 - - - 210.000000000000000 + Select a color for solid background - - - - Border - - - - - - - - 0 - 0 - - - - Minimal distance of the object from -the top and left view border - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 0.000000000000000 - - - - - - - Paint background yes/no - - - Background - - - - + Qt::Horizontal @@ -149,31 +86,25 @@ the top and left view border - - - - false - - - - 0 - 0 - - - - Background color - - - - - + + - Line Width + Crop To Height - - + + + + Use 3d Background + + + true + + + + + 0 @@ -181,7 +112,7 @@ the top and left view border - Width of lines in generated view + If Crop Image is checked, crop captured image to this height. Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -192,56 +123,49 @@ the top and left view border 0.000000000000000 - - 0.100000000000000 - - 0.500000000000000 + 100.000000000000000 - - - - Render Mode - - - - - + + - Drawing style - see SoRenderManager + Paint background yes/no + + + Solid Background + + + true + + + + + + + No Background + + + true + + + true + + + + + + + Crop To Width + + + + + + + Crop Image - - - As is - - - - - Wireframe - - - - - Points - - - - - Wireframe overlay - - - - - Hidden Line - - - - - Bounding box - -