[TD]simplify ActiveView
- remove copyActiveViewToSvgFile - use bitmap image instead of Svg - upgrade Task with crop options
This commit is contained in:
committed by
WandererFan
parent
60f7514306
commit
0fd189a153
@@ -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();
|
||||
|
||||
@@ -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<App::DocumentPy*>(docObj)->getDocumentPtr();
|
||||
if (colorObj && PyTuple_Check(colorObj)) {
|
||||
App::Color c = TechDraw::DrawUtil::pyTupleToColor(colorObj);
|
||||
bgColor = c.asValue<QColor>();
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -23,329 +23,54 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#include <QScreen>
|
||||
#include <Inventor/SbColor.h>
|
||||
#include <Inventor/SbVec2s.h>
|
||||
#include <Inventor/SbViewportRegion.h>
|
||||
#include <Inventor/SoRenderManager.h>
|
||||
#include <Inventor/actions/SoWriteAction.h>
|
||||
#include <Inventor/annex/HardCopy/SoVectorizeAction.h>
|
||||
#include <Inventor/misc/SoChildList.h>
|
||||
#include <Inventor/nodes/SoCamera.h>
|
||||
#include <Inventor/nodes/SoDirectionalLight.h>
|
||||
#include <Inventor/nodes/SoNode.h>
|
||||
#include <Inventor/nodes/SoOrthographicCamera.h>
|
||||
#include <Inventor/nodes/SoPerspectiveCamera.h>
|
||||
#include <Inventor/nodes/SoSeparator.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/MDIView.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/View3DInventor.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
#include <Gui/SoFCVectorizeSVGAction.h>
|
||||
|
||||
#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<View3DInventor*>(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<SoOrthographicCamera*>(sourceCam);
|
||||
sourceHeight = oCam->height.getValue();
|
||||
} else if (sourceCam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) {
|
||||
pCam = static_cast<SoPerspectiveCamera*>(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<SoOrthographicCamera*>(svgCam);
|
||||
double newHeight = sourceHeight * zoomFactor;
|
||||
oSvgCam->height.setValue(newHeight);
|
||||
} else if (svgCam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) {
|
||||
SoPerspectiveCamera* vSvgCam = static_cast<SoPerspectiveCamera*>(svgCam);
|
||||
vSvgCam->heightAngle.setValue(sourceAngle);
|
||||
}
|
||||
|
||||
viewerSvg->redraw();
|
||||
|
||||
std::unique_ptr<SoVectorizeAction> va;
|
||||
va = std::unique_ptr<SoVectorizeAction>(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<SoFCVectorizeSVGAction*>(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;
|
||||
}
|
||||
|
||||
@@ -25,27 +25,11 @@
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
class SoSeparator;
|
||||
class SoCamera;
|
||||
class SoNode;
|
||||
class SbVec2s;
|
||||
class SbVec2f;
|
||||
class SbVec2d;
|
||||
class SoVectorizeAction;
|
||||
#include <QColor>
|
||||
#include <QImage>
|
||||
|
||||
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
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
|
||||
#include <App/Document.h>
|
||||
|
||||
#include <Base/FileInfo.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Command.h>
|
||||
@@ -51,14 +53,12 @@
|
||||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
#include <Mod/TechDraw/App/DrawView.h>
|
||||
#include <Mod/TechDraw/App/DrawViewSymbol.h>
|
||||
#include <Mod/TechDraw/App/DrawViewImage.h>
|
||||
|
||||
#include <Mod/TechDraw/Gui/ui_TaskActiveView.h>
|
||||
|
||||
#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<TechDraw::DrawViewSymbol*>(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<TechDraw::DrawViewImage*>(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<ViewProviderImage*>(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();
|
||||
|
||||
|
||||
@@ -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_TaskActiveView> ui;
|
||||
|
||||
TechDraw::DrawPage* m_pageFeat;
|
||||
TechDraw::DrawViewSymbol* m_symbolFeat;
|
||||
TechDraw::DrawViewImage* m_imageFeat;
|
||||
|
||||
QPushButton* m_btnOK;
|
||||
QPushButton* m_btnCancel;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>375</width>
|
||||
<height>176</height>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@@ -31,15 +31,8 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="1,0,1">
|
||||
<item row="1" column="2">
|
||||
<widget class="Gui::QuantitySpinBox" name="qsbWidth">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
@@ -48,7 +41,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Width of generated view</string>
|
||||
<string>If Crop Image is checked, crop captured image to this width.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@@ -60,19 +53,15 @@
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>297.000000000000000</double>
|
||||
<double>100.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Height</string>
|
||||
<item row="4" column="2">
|
||||
<widget class="Gui::ColorButton" name="ccBgColor">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="Gui::QuantitySpinBox" name="qsbHeight">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -80,63 +69,11 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Height of generated view</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>210.000000000000000</double>
|
||||
<string>Select a color for solid background</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Border</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="Gui::QuantitySpinBox" name="qsbBorder">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Minimal distance of the object from
|
||||
the top and left view border</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="cbbg">
|
||||
<property name="toolTip">
|
||||
<string>Paint background yes/no</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Background</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="4" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@@ -149,31 +86,25 @@ the top and left view border</string>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="Gui::ColorButton" name="ccBgColor">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Background color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Line Width</string>
|
||||
<string>Crop To Height</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="Gui::QuantitySpinBox" name="qsbWeight">
|
||||
<item row="5" column="0">
|
||||
<widget class="QCheckBox" name="cbUse3d">
|
||||
<property name="text">
|
||||
<string>Use 3d Background</string>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="Gui::QuantitySpinBox" name="qsbHeight">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
@@ -181,7 +112,7 @@ the top and left view border</string>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Width of lines in generated view</string>
|
||||
<string>If Crop Image is checked, crop captured image to this height.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@@ -192,56 +123,49 @@ the top and left view border</string>
|
||||
<property name="minimum">
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>0.500000000000000</double>
|
||||
<double>100.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Render Mode</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="2">
|
||||
<widget class="QComboBox" name="cbMode">
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="cbbg">
|
||||
<property name="toolTip">
|
||||
<string>Drawing style - see SoRenderManager</string>
|
||||
<string>Paint background yes/no</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Solid Background</string>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="cbNoBG">
|
||||
<property name="text">
|
||||
<string>No Background</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Crop To Width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="cbCrop">
|
||||
<property name="text">
|
||||
<string>Crop Image</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>As is</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Wireframe</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Points</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Wireframe overlay</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Hidden Line</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Bounding box</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
Reference in New Issue
Block a user