Skip to content

Commit

Permalink
[TD]Make TD View from ActiveView
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Aug 28, 2019
1 parent 2af8a32 commit 13676bf
Show file tree
Hide file tree
Showing 12 changed files with 1,340 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Gui/SoFCVectorizeSVGAction.cpp
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
65 changes: 61 additions & 4 deletions src/Mod/TechDraw/Gui/AppTechDrawGuiPy.cpp
Expand Up @@ -38,22 +38,22 @@
#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>


#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 {

Expand All @@ -71,6 +71,9 @@ class Module : public Py::ExtensionModule<Module>
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() {}
Expand Down Expand Up @@ -237,7 +240,61 @@ class Module : public Py::ExtensionModule<Module>

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()
Expand Down
8 changes: 8 additions & 0 deletions src/Mod/TechDraw/Gui/CMakeLists.txt
Expand Up @@ -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})
Expand Down Expand Up @@ -96,6 +97,7 @@ set(TechDrawGui_UIC_SRCS
TaskRestoreLines.ui
TaskWeldingSymbol.ui
SymbolChooser.ui
TaskActiveView.ui
)

if(BUILD_QT5)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -344,6 +351,7 @@ SET(TechDrawGuiTaskDlgs_SRCS
TaskCL2Lines.ui
TaskWeldingSymbol.ui
SymbolChooser.ui
TaskActiveView.ui
)
SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS})

Expand Down
36 changes: 36 additions & 0 deletions src/Mod/TechDraw/Gui/Command.cpp
Expand Up @@ -74,6 +74,7 @@
#include "MDIViewPage.h"
#include "TaskProjGroup.h"
#include "TaskSectionView.h"
#include "TaskActiveView.h"
#include "ViewProviderPage.h"

using namespace TechDrawGui;
Expand Down Expand Up @@ -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
//===========================================================================
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 13676bf

Please sign in to comment.