[TD]Make TD View from ActiveView
This commit is contained in:
@@ -382,6 +382,7 @@ SoFCVectorizeSVGAction::SoFCVectorizeSVGAction() :
|
||||
m_lineWidth(1.0),
|
||||
m_usemm(false)
|
||||
{
|
||||
Base::Console().Message("SoFCVSA::SoFCVSA()\n");
|
||||
SO_ACTION_CONSTRUCTOR(SoFCVectorizeSVGAction);
|
||||
this->setOutput(new SoSVGVectorOutput);
|
||||
this->p = new SoFCVectorizeSVGActionP(this);
|
||||
@@ -400,6 +401,7 @@ SoFCVectorizeSVGAction::getSVGOutput(void) const
|
||||
|
||||
void SoFCVectorizeSVGAction::printHeader(void) const
|
||||
{
|
||||
Base::Console().Message("SoFCVSA::printHeader()\n");
|
||||
std::ostream& str = this->getSVGOutput()->getFileStream();
|
||||
str << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << std::endl;
|
||||
str << "<!-- Created with FreeCAD (http://www.freecadweb.org) -->" << std::endl;
|
||||
@@ -433,6 +435,8 @@ void SoFCVectorizeSVGAction::printViewport(void) const
|
||||
|
||||
void SoFCVectorizeSVGAction::printBackground(void) const
|
||||
{
|
||||
Base::Console().Message("SoFCVSA::printBackground()\n");
|
||||
|
||||
SbVec2f mul = getRotatedViewportSize();
|
||||
SbVec2f add = getRotatedViewportStartpos();
|
||||
|
||||
|
||||
@@ -38,8 +38,10 @@
|
||||
#include <Base/VectorPy.h>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentPy.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
#include <App/Material.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
@@ -47,13 +49,11 @@
|
||||
|
||||
#include <Mod/Part/App/OCCError.h>
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
|
||||
#include "MDIViewPage.h"
|
||||
#include "ViewProviderPage.h"
|
||||
|
||||
namespace TechDrawGui {
|
||||
//module level static C++ functions go here
|
||||
}
|
||||
#include "Grabber3d.h"
|
||||
|
||||
namespace TechDrawGui {
|
||||
|
||||
@@ -71,6 +71,9 @@ 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."
|
||||
);
|
||||
initialize("This is a module for displaying drawings"); // register with Python
|
||||
}
|
||||
virtual ~Module() {}
|
||||
@@ -237,7 +240,61 @@ private:
|
||||
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
//!copyActiveViewToSvgFile(document, fileSpec)
|
||||
Py::Object copyActiveViewToSvgFile(const Py::Tuple& args)
|
||||
{
|
||||
double result = 1.0;
|
||||
PyObject *docObj = nullptr;
|
||||
PyObject *colorObj = nullptr;
|
||||
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|ddpOddi",
|
||||
&docObj, "utf-8",&name,
|
||||
&outWidth, &outHeight,
|
||||
&paintBackground, &colorObj,
|
||||
&lineWidth, &border,
|
||||
&mode)) {
|
||||
throw Py::TypeError("expected (doc, file|,options)");
|
||||
}
|
||||
|
||||
fileSpec = std::string(name);
|
||||
PyMem_Free(name);
|
||||
|
||||
try {
|
||||
if (PyObject_TypeCheck(docObj, &(App::DocumentPy::Type))) {
|
||||
appDoc = static_cast<App::DocumentPy*>(docObj)->getDocumentPtr();
|
||||
if ( (colorObj != nullptr) &&
|
||||
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) {
|
||||
throw Py::Exception(Base::BaseExceptionFreeCADError, e.what());
|
||||
}
|
||||
|
||||
PyObject* pyResult = nullptr;
|
||||
pyResult = PyFloat_FromDouble(result);
|
||||
return Py::asObject(pyResult);
|
||||
}
|
||||
};
|
||||
|
||||
PyObject* initModule()
|
||||
|
||||
@@ -66,6 +66,7 @@ set(TechDrawGui_MOC_HDRS
|
||||
TaskBalloon.h
|
||||
QGIWeldSymbol.h
|
||||
SymbolChooser.h
|
||||
TaskActiveView.h
|
||||
)
|
||||
|
||||
fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS})
|
||||
@@ -96,6 +97,7 @@ set(TechDrawGui_UIC_SRCS
|
||||
TaskRestoreLines.ui
|
||||
TaskWeldingSymbol.ui
|
||||
SymbolChooser.ui
|
||||
TaskActiveView.ui
|
||||
)
|
||||
|
||||
if(BUILD_QT5)
|
||||
@@ -183,6 +185,11 @@ SET(TechDrawGui_SRCS
|
||||
SymbolChooser.ui
|
||||
SymbolChooser.cpp
|
||||
SymbolChooser.h
|
||||
TaskActiveView.ui
|
||||
TaskActiveView.cpp
|
||||
TaskActiveView.h
|
||||
Grabber3d.cpp
|
||||
Grabber3d.h
|
||||
)
|
||||
|
||||
SET(TechDrawGuiView_SRCS
|
||||
@@ -344,6 +351,7 @@ SET(TechDrawGuiTaskDlgs_SRCS
|
||||
TaskCL2Lines.ui
|
||||
TaskWeldingSymbol.ui
|
||||
SymbolChooser.ui
|
||||
TaskActiveView.ui
|
||||
)
|
||||
SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS})
|
||||
|
||||
|
||||
@@ -74,6 +74,7 @@
|
||||
#include "MDIViewPage.h"
|
||||
#include "TaskProjGroup.h"
|
||||
#include "TaskSectionView.h"
|
||||
#include "TaskActiveView.h"
|
||||
#include "ViewProviderPage.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
@@ -324,6 +325,40 @@ bool CmdTechDrawNewView::isActive(void)
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// TechDraw_NewActiveView
|
||||
//===========================================================================
|
||||
|
||||
DEF_STD_CMD_A(CmdTechDrawNewActiveView);
|
||||
|
||||
CmdTechDrawNewActiveView::CmdTechDrawNewActiveView()
|
||||
: Command("TechDraw_NewActiveView")
|
||||
{
|
||||
sAppModule = "TechDraw";
|
||||
sGroup = QT_TR_NOOP("TechDraw");
|
||||
sMenuText = QT_TR_NOOP("Insert ActiveView(3D) as View in Page");
|
||||
sToolTipText = sMenuText;
|
||||
sWhatsThis = "TechDraw_NewActiveView";
|
||||
sStatusTip = sToolTipText;
|
||||
sPixmap = "actions/techdraw-activeview";
|
||||
}
|
||||
|
||||
void CmdTechDrawNewActiveView::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
std::string PageName = page->getNameInDocument();
|
||||
Gui::Control().showDialog(new TaskDlgActiveView(page));
|
||||
}
|
||||
|
||||
bool CmdTechDrawNewActiveView::isActive(void)
|
||||
{
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
// TechDraw_NewViewSection
|
||||
//===========================================================================
|
||||
@@ -1222,6 +1257,7 @@ void CreateTechDrawCommands(void)
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewPageDef());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewPage());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewView());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewActiveView());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewViewSection());
|
||||
rcCmdMgr.addCommand(new CmdTechDrawNewViewDetail());
|
||||
// rcCmdMgr.addCommand(new CmdTechDrawNewMulti()); //deprecated
|
||||
|
||||
384
src/Mod/TechDraw/Gui/Grabber3d.cpp
Normal file
384
src/Mod/TechDraw/Gui/Grabber3d.cpp
Normal file
@@ -0,0 +1,384 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2019 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
|
||||
#endif
|
||||
#include <QGuiApplication>
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QBitmap>
|
||||
#include <QGraphicsView>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QFormLayout>
|
||||
#include <QGraphicsProxyWidget>
|
||||
#include <QScreen>
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/MDIView.h>
|
||||
#include <Gui/NavigationStyle.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
#include <Gui/View3DInventor.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
#include <Gui/SoFCVectorizeSVGAction.h>
|
||||
|
||||
#include <Inventor/SbBasic.h>
|
||||
#include <Inventor/SbBox3f.h>
|
||||
#include <Inventor/SbColor.h>
|
||||
#include <Inventor/SbVec3f.h>
|
||||
#include <Inventor/SbVec2s.h>
|
||||
#include <Inventor/SbVec2f.h>
|
||||
#include <Inventor/SbVec2d.h>
|
||||
#include <Inventor/SbViewportRegion.h>
|
||||
#include <Inventor/SoDB.h>
|
||||
#include <Inventor/SoRenderManager.h>
|
||||
#include <Inventor/SoEventManager.h>
|
||||
#include <Inventor/actions/SoGetBoundingBoxAction.h>
|
||||
#include <Inventor/actions/SoWriteAction.h>
|
||||
#include <Inventor/events/SoEvents.h>
|
||||
#include <Inventor/fields/SoSFVec3f.h>
|
||||
#include <Inventor/nodes/SoCamera.h>
|
||||
#include <Inventor/nodes/SoOrthographicCamera.h>
|
||||
#include <Inventor/nodes/SoPerspectiveCamera.h>
|
||||
#include <Inventor/nodes/SoDirectionalLight.h>
|
||||
#include <Inventor/nodes/SoMaterial.h>
|
||||
#include <Inventor/nodes/SoNode.h>
|
||||
#include <Inventor/nodes/SoSeparator.h>
|
||||
#include <Inventor/nodes/SoCone.h>
|
||||
#include <Inventor/nodes/SoDirectionalLight.h>
|
||||
#include <Inventor/nodes/SoDrawStyle.h>
|
||||
#include <Inventor/Qt/viewers/SoQtViewer.h>
|
||||
#include <Inventor/annex/HardCopy/SoVectorizeAction.h>
|
||||
|
||||
#include "Rez.h"
|
||||
#include "QGVPage.h"
|
||||
#include "MDIViewPage.h"
|
||||
#include "DrawGuiUtil.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)
|
||||
{
|
||||
// Base::Console().Message("G3d::copyActiveViewToSvgFile()\n");
|
||||
double result = 1.0; //best estimate of scale of result
|
||||
|
||||
//get the active view
|
||||
Gui::Document* guiDoc = Gui::Application::Instance->getDocument(appDoc);
|
||||
Gui::MDIView* mdiView = guiDoc->getActiveView();
|
||||
if (mdiView == nullptr) {
|
||||
Base::Console().Warning("G3d::copyActiveViewToSvgFile - no ActiveView - returning\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
View3DInventor* view3d = qobject_cast<View3DInventor*>(mdiView);
|
||||
if (view3d == nullptr) {
|
||||
Base::Console().Warning("G3d::copyActiveViewToSvgFile - no viewer for ActiveView - returning\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
View3DInventorViewer* viewer = view3d->getViewer();
|
||||
if (viewer == nullptr) {
|
||||
Base::Console().Warning("G3d::copyActiveViewToSvgFile - could not create viewer - returning\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
//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 = dynamic_cast<SoOrthographicCamera*>(sourceCam);
|
||||
sourceHeight = oCam->height.getValue();
|
||||
} else if (sourceCam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) {
|
||||
pCam = dynamic_cast<SoPerspectiveCamera*>(sourceCam);
|
||||
sourceAngle = pCam->heightAngle.getValue();
|
||||
}
|
||||
oCam = nullptr;
|
||||
pCam = nullptr;
|
||||
|
||||
//make a view for rendering Svg
|
||||
View3DInventor* view3DI = new View3DInventor(0, 0); //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 = dynamic_cast<SoOrthographicCamera*>(svgCam);
|
||||
double newHeight = sourceHeight * zoomFactor;
|
||||
oSvgCam->height.setValue(newHeight);
|
||||
} else if (svgCam->getTypeId() == SoPerspectiveCamera::getClassTypeId()) {
|
||||
SoPerspectiveCamera* vSvgCam = dynamic_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;
|
||||
}
|
||||
QColor dbColor(Qt::blue);
|
||||
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;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
||||
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
|
||||
// QScreen *screen = QGuiApplication::primaryScreen();
|
||||
// double qtppi = screen->physicalDotsPerInch(); //~111 dpi
|
||||
// double 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->getPointOnScreen(p1s);
|
||||
SbVec3f p2w = viewer->getPointOnScreen(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
|
||||
// QScreen *screen = QGuiApplication::primaryScreen();
|
||||
// double qtppi = screen->physicalDotsPerInch(); //~111 dpi
|
||||
// double 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;
|
||||
}
|
||||
82
src/Mod/TechDraw/Gui/Grabber3d.h
Normal file
82
src/Mod/TechDraw/Gui/Grabber3d.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2019 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _Grabber3d_h_
|
||||
#define _Grabber3d_h_
|
||||
|
||||
|
||||
class SoSeparator;
|
||||
class SoCamera;
|
||||
class SoNode;
|
||||
class SbVec2s;
|
||||
class SbVec2f;
|
||||
class SbVec2d;
|
||||
class SoVectorizeAction;
|
||||
|
||||
namespace App {
|
||||
class Document;
|
||||
class DocumentObject;
|
||||
class NavigationStyle;
|
||||
}
|
||||
namespace Gui {
|
||||
class Document;
|
||||
class View3DInventorViewer;
|
||||
}
|
||||
|
||||
#include "MDIViewPage.h"
|
||||
|
||||
namespace TechDraw {
|
||||
}
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
} //end namespace TechDrawGui
|
||||
#endif
|
||||
@@ -43,6 +43,7 @@
|
||||
<file>icons/actions/techdraw-new-default.svg</file>
|
||||
<file>icons/actions/techdraw-new-pick.svg</file>
|
||||
<file>icons/actions/techdraw-view.svg</file>
|
||||
<file>icons/actions/techdraw-activeview.svg</file>
|
||||
<file>icons/actions/techdraw-multiview.svg</file>
|
||||
<file>icons/actions/techdraw-annotation.svg</file>
|
||||
<file>icons/actions/techdraw-clip.svg</file>
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="64"
|
||||
height="64"
|
||||
viewBox="0 0 64 64"
|
||||
version="1.1"
|
||||
id="svg142"
|
||||
sodipodi:docname="techdraw-activeview.svg"
|
||||
style="fill:none;stroke:#000000;stroke-width:2;stroke-linecap:round;stroke-linejoin:round"
|
||||
inkscape:version="0.92.4 (unknown)">
|
||||
<metadata
|
||||
id="metadata148">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<defs
|
||||
id="defs146">
|
||||
<linearGradient
|
||||
id="linearGradient1328"
|
||||
inkscape:collect="always">
|
||||
<stop
|
||||
id="stop1324"
|
||||
offset="0"
|
||||
style="stop-color:#ffffff;stop-opacity:1" />
|
||||
<stop
|
||||
id="stop1326"
|
||||
offset="1"
|
||||
style="stop-color:#16d0d2;stop-opacity:0;" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient1310">
|
||||
<stop
|
||||
style="stop-color:#06989a;stop-opacity:1"
|
||||
offset="0"
|
||||
id="stop1306" />
|
||||
<stop
|
||||
style="stop-color:#34e0e2;stop-opacity:1"
|
||||
offset="1"
|
||||
id="stop1308" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient1310"
|
||||
id="linearGradient1312"
|
||||
x1="57.636765"
|
||||
y1="50.225197"
|
||||
x2="5.834971"
|
||||
y2="19.189537"
|
||||
gradientUnits="userSpaceOnUse" />
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient1328"
|
||||
id="radialGradient1322"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(0.71743104,0.00748738,-0.00738849,0.70797021,9.3050603,6.5739852)"
|
||||
cx="32"
|
||||
cy="35.575535"
|
||||
fx="32"
|
||||
fy="35.575535"
|
||||
r="16" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1"
|
||||
objecttolerance="10"
|
||||
gridtolerance="10"
|
||||
guidetolerance="10"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:window-width="1358"
|
||||
inkscape:window-height="703"
|
||||
id="namedview144"
|
||||
showgrid="false"
|
||||
inkscape:zoom="8.03125"
|
||||
inkscape:cx="23.961976"
|
||||
inkscape:cy="24.054581"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="26"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg142" />
|
||||
<circle
|
||||
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#06989a;stroke-width:2.61091852;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="path907"
|
||||
cx="-14.782197"
|
||||
cy="31.832508"
|
||||
rx="11.694541"
|
||||
ry="12.694541" />
|
||||
<g
|
||||
id="g1166">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
id="path138"
|
||||
d="m 60.689917,49.407377 a 5.2163485,4.9735365 0 0 1 -5.216349,4.973537 H 8.5264316 A 5.2163485,4.9735365 0 0 1 3.310083,49.407377 V 22.052926 A 5.2163485,4.9735365 0 0 1 8.5264316,17.079389 H 18.959129 l 5.216348,-7.4603035 h 15.649046 l 5.216348,7.4603035 h 10.432697 a 5.2163485,4.9735365 0 0 1 5.216349,4.973537 z"
|
||||
style="fill:url(#linearGradient1312);stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;fill-opacity:1" />
|
||||
<g
|
||||
transform="translate(0,4)"
|
||||
id="g1160">
|
||||
<circle
|
||||
cx="32"
|
||||
cy="32"
|
||||
id="circle140"
|
||||
style="fill:url(#radialGradient1322);fill-opacity:1;stroke:#000000;stroke-width:3;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
r="14" />
|
||||
<ellipse
|
||||
style="opacity:1;vector-effect:none;fill:none;fill-opacity:1;stroke:#06989a;stroke-width:1.78571427;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
|
||||
id="path351"
|
||||
cx="32"
|
||||
cy="32"
|
||||
rx="11.607143"
|
||||
ry="11.607142" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.4 KiB |
259
src/Mod/TechDraw/Gui/TaskActiveView.cpp
Normal file
259
src/Mod/TechDraw/Gui/TaskActiveView.cpp
Normal file
@@ -0,0 +1,259 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2019 Wandererfan <wandererfan@gmail.com *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
|
||||
#endif // #ifndef _PreComp_
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStatusBar>
|
||||
#include <QGraphicsScene>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/UnitsApi.h>
|
||||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/ViewProvider.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
#include <Mod/TechDraw/App/DrawView.h>
|
||||
#include <Mod/TechDraw/App/DrawViewSymbol.h>
|
||||
|
||||
#include <Mod/TechDraw/Gui/ui_TaskActiveView.h>
|
||||
|
||||
#include "DrawGuiStd.h"
|
||||
#include "QGVPage.h"
|
||||
#include "QGIView.h"
|
||||
#include "Grabber3d.h"
|
||||
#include "Rez.h"
|
||||
|
||||
#include "TaskActiveView.h"
|
||||
|
||||
using namespace Gui;
|
||||
using namespace TechDraw;
|
||||
using namespace TechDrawGui;
|
||||
|
||||
//ctor for creation
|
||||
TaskActiveView::TaskActiveView(TechDraw::DrawPage* pageFeat) :
|
||||
ui(new Ui_TaskActiveView),
|
||||
m_pageFeat(pageFeat),
|
||||
m_symbolFeat(nullptr)
|
||||
{
|
||||
// Base::Console().Message("TAV::TAV() - create mode\n");
|
||||
if (m_pageFeat == nullptr) {
|
||||
//should be caught in CMD caller
|
||||
Base::Console().Error("TaskActiveView - bad parameters. Can not proceed.\n");
|
||||
return;
|
||||
}
|
||||
ui->setupUi(this);
|
||||
|
||||
setUiPrimary();
|
||||
}
|
||||
|
||||
TaskActiveView::~TaskActiveView()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void TaskActiveView::updateTask()
|
||||
{
|
||||
// blockUpdate = true;
|
||||
|
||||
// blockUpdate = false;
|
||||
}
|
||||
|
||||
void TaskActiveView::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
}
|
||||
|
||||
void TaskActiveView::setUiPrimary()
|
||||
{
|
||||
// Base::Console().Message("TAV::setUiPrimary()\n");
|
||||
setWindowTitle(QObject::tr("ActiveView to TD View"));
|
||||
}
|
||||
|
||||
void TaskActiveView::blockButtons(bool b)
|
||||
{
|
||||
Q_UNUSED(b);
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
TechDraw::DrawViewSymbol* TaskActiveView::createActiveView(void)
|
||||
{
|
||||
// Base::Console().Message("TAV::createActiveView()\n");
|
||||
|
||||
std::string symbolName = m_pageFeat->getDocument()->getUniqueObjectName("DrawActiveView");
|
||||
std::string symbolType = "TechDraw::DrawViewSymbol";
|
||||
|
||||
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());
|
||||
|
||||
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());
|
||||
|
||||
//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());
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
Command::doCommand(Command::Doc,"f = open(unicode(\"%s\",'utf-8'),'r')",(const char*)fileSpec.c_str());
|
||||
#else
|
||||
Command::doCommand(Command::Doc,"f = open(\"%s\",'r')",(const char*)fileSpec.c_str());
|
||||
#endif
|
||||
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 == nullptr) ||
|
||||
(newSym == nullptr) ) {
|
||||
throw Base::RuntimeError("TaskActiveView - new symbol object not found");
|
||||
}
|
||||
|
||||
return newSym;
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
|
||||
void TaskActiveView::saveButtons(QPushButton* btnOK,
|
||||
QPushButton* btnCancel)
|
||||
{
|
||||
m_btnOK = btnOK;
|
||||
m_btnCancel = btnCancel;
|
||||
}
|
||||
|
||||
void TaskActiveView::enableTaskButtons(bool b)
|
||||
{
|
||||
m_btnOK->setEnabled(b);
|
||||
m_btnCancel->setEnabled(b);
|
||||
}
|
||||
|
||||
//******************************************************************************
|
||||
|
||||
bool TaskActiveView::accept()
|
||||
{
|
||||
// Base::Console().Message("TAV::accept()\n");
|
||||
Gui::Command::openCommand("Create ActiveView");
|
||||
m_symbolFeat = createActiveView();
|
||||
// m_symbolFeat->requestPaint();
|
||||
m_symbolFeat->recomputeFeature();
|
||||
Gui::Command::updateActive();
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TaskActiveView::reject()
|
||||
{
|
||||
// Base::Console().Message("TAV::reject()\n");
|
||||
//nothing to remove.
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()");
|
||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()");
|
||||
|
||||
return false;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
TaskDlgActiveView::TaskDlgActiveView(TechDraw::DrawPage* page)
|
||||
: TaskDialog()
|
||||
{
|
||||
widget = new TaskActiveView(page);
|
||||
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-activeview"),
|
||||
widget->windowTitle(), true, 0);
|
||||
taskbox->groupLayout()->addWidget(widget);
|
||||
Content.push_back(taskbox);
|
||||
}
|
||||
|
||||
TaskDlgActiveView::~TaskDlgActiveView()
|
||||
{
|
||||
}
|
||||
|
||||
void TaskDlgActiveView::update()
|
||||
{
|
||||
// widget->updateTask();
|
||||
}
|
||||
|
||||
void TaskDlgActiveView::modifyStandardButtons(QDialogButtonBox* box)
|
||||
{
|
||||
QPushButton* btnOK = box->button(QDialogButtonBox::Ok);
|
||||
QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel);
|
||||
widget->saveButtons(btnOK, btnCancel);
|
||||
}
|
||||
|
||||
//==== calls from the TaskView ===============================================================
|
||||
void TaskDlgActiveView::open()
|
||||
{
|
||||
}
|
||||
|
||||
void TaskDlgActiveView::clicked(int)
|
||||
{
|
||||
}
|
||||
|
||||
bool TaskDlgActiveView::accept()
|
||||
{
|
||||
widget->accept();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TaskDlgActiveView::reject()
|
||||
{
|
||||
widget->reject();
|
||||
return true;
|
||||
}
|
||||
|
||||
#include <Mod/TechDraw/Gui/moc_TaskActiveView.cpp>
|
||||
129
src/Mod/TechDraw/Gui/TaskActiveView.h
Normal file
129
src/Mod/TechDraw/Gui/TaskActiveView.h
Normal file
@@ -0,0 +1,129 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2019 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TECHDRAWGUI_TASKWELDINGSYMBOL_H
|
||||
#define TECHDRAWGUI_TASKWELDINGSYMBOL_H
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
#include <App/DocumentObject.h>
|
||||
#include <Base/Vector3D.h>
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
|
||||
#include <Mod/TechDraw/Gui/ui_TaskActiveView.h>
|
||||
|
||||
class Ui_TaskActiveView;
|
||||
|
||||
namespace App {
|
||||
class DocumentObject;
|
||||
}
|
||||
|
||||
namespace TechDraw
|
||||
{
|
||||
class DrawPage;
|
||||
class DrawView;
|
||||
class DrawViewSymbol;
|
||||
}
|
||||
|
||||
namespace TechDrawGui
|
||||
{
|
||||
class QGVPage;
|
||||
class QGIView;
|
||||
class MDIViewPage;
|
||||
|
||||
class TechDrawGuiExport TaskActiveView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskActiveView(TechDraw::DrawPage* pageFeat);
|
||||
~TaskActiveView();
|
||||
|
||||
public Q_SLOTS:
|
||||
|
||||
public:
|
||||
virtual bool accept();
|
||||
virtual bool reject();
|
||||
void updateTask();
|
||||
void saveButtons(QPushButton* btnOK,
|
||||
QPushButton* btnCancel);
|
||||
void enableTaskButtons(bool b);
|
||||
|
||||
protected Q_SLOTS:
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
|
||||
void blockButtons(bool b);
|
||||
void setUiPrimary(void);
|
||||
|
||||
TechDraw::DrawViewSymbol* createActiveView(void);
|
||||
|
||||
private:
|
||||
Ui_TaskActiveView* ui;
|
||||
|
||||
TechDraw::DrawPage* m_pageFeat;
|
||||
TechDraw::DrawViewSymbol* m_symbolFeat;
|
||||
|
||||
QPushButton* m_btnOK;
|
||||
QPushButton* m_btnCancel;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class TaskDlgActiveView : public Gui::TaskView::TaskDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskDlgActiveView(TechDraw::DrawPage* pageFeat);
|
||||
~TaskDlgActiveView();
|
||||
|
||||
public:
|
||||
/// is called the TaskView when the dialog is opened
|
||||
virtual void open();
|
||||
/// is called by the framework if an button is clicked which has no accept or reject role
|
||||
virtual void clicked(int);
|
||||
/// is called by the framework if the dialog is accepted (Ok)
|
||||
virtual bool accept();
|
||||
/// is called by the framework if the dialog is rejected (Cancel)
|
||||
virtual bool reject();
|
||||
/// is called by the framework if the user presses the help button
|
||||
virtual void helpRequested() { return;}
|
||||
virtual bool isAllowedAlterDocument(void) const
|
||||
{ return false; }
|
||||
void update();
|
||||
|
||||
void modifyStandardButtons(QDialogButtonBox* box);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
TaskActiveView* widget;
|
||||
Gui::TaskView::TaskBox* taskbox;
|
||||
|
||||
};
|
||||
|
||||
} //namespace TechDrawGui
|
||||
|
||||
#endif // #ifndef TECHDRAWGUI_TASKWELDINGSYMBOL_H
|
||||
243
src/Mod/TechDraw/Gui/TaskActiveView.ui
Normal file
243
src/Mod/TechDraw/Gui/TaskActiveView.ui
Normal file
@@ -0,0 +1,243 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TaskActiveView</class>
|
||||
<widget class="QWidget" name="TaskActiveView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>423</width>
|
||||
<height>317</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>ActiveView to TD View</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../../../../../Source/FreeCAD-src/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc">
|
||||
<normaloff>:/icons/actions/techdraw-activeview.svg</normaloff>:/icons/actions/techdraw-activeview.svg</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="qsbWidth">
|
||||
<property name="toolTip">
|
||||
<string>Width of generated view</string>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>297.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Height</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="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="qsbBorder">
|
||||
<property name="toolTip">
|
||||
<string>Unused area around view</string>
|
||||
</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">
|
||||
<widget class="Gui::ColorButton" name="ccBgColor">
|
||||
<property name="toolTip">
|
||||
<string>Background color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Line Width</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="qsbWeight">
|
||||
<property name="toolTip">
|
||||
<string>Width of lines in generated view.</string>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>0.500000000000000</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="1">
|
||||
<widget class="QComboBox" name="cbMode">
|
||||
<property name="toolTip">
|
||||
<string>Drawing style - see SoRenderManager</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>
|
||||
<item row="1" column="1">
|
||||
<widget class="Gui::QuantitySpinBox" name="qsbHeight">
|
||||
<property name="toolTip">
|
||||
<string>Height of generated view</string>
|
||||
</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>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Gui::QuantitySpinBox</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>Gui/QuantitySpinBox.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>Gui::ColorButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>Gui/Widgets.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../../../../Source/FreeCAD-src/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -55,6 +55,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
||||
*draw << "TechDraw_NewPage";
|
||||
*draw << "Separator";
|
||||
*draw << "TechDraw_NewView";
|
||||
*draw << "TechDraw_NewActiveView";
|
||||
// *draw << "TechDraw_NewMulti"; //deprecated
|
||||
*draw << "TechDraw_ProjGroup";
|
||||
*draw << "TechDraw_NewViewSection";
|
||||
@@ -115,6 +116,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
|
||||
Gui::ToolBarItem *views = new Gui::ToolBarItem(root);
|
||||
views->setCommand("TechDraw Views");
|
||||
*views << "TechDraw_NewView";
|
||||
*views << "TechDraw_NewActiveView";
|
||||
// *views << "TechDraw_NewMulti"; //deprecated
|
||||
*views << "TechDraw_ProjGroup";
|
||||
*views << "TechDraw_NewViewSection";
|
||||
@@ -184,6 +186,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const
|
||||
Gui::ToolBarItem *views = new Gui::ToolBarItem(root);
|
||||
views->setCommand("Views");
|
||||
*views << "TechDraw_NewView";
|
||||
*views << "TechDraw_NewActiveView";
|
||||
// *views << "TechDraw_NewMulti"; //deprecated
|
||||
*views << "TechDraw_ProjGroup";
|
||||
*views << "TechDraw_NewViewSection";
|
||||
|
||||
Reference in New Issue
Block a user