diff --git a/src/Mod/Drawing/App/AppDrawing.cpp b/src/Mod/Drawing/App/AppDrawing.cpp
index 016abf81b..f80d20f1c 100644
--- a/src/Mod/Drawing/App/AppDrawing.cpp
+++ b/src/Mod/Drawing/App/AppDrawing.cpp
@@ -21,6 +21,7 @@
#include "FeatureView.h"
#include "FeatureViewPart.h"
#include "FeatureViewAnnotation.h"
+#include "FeatureViewSymbol.h"
#include "FeatureProjection.h"
#include "FeatureClip.h"
#include "PageGroup.h"
@@ -60,6 +61,7 @@ void DrawingExport initDrawing()
Drawing::FeatureViewPartPython ::init();
Drawing::FeatureViewPython ::init();
Drawing::FeatureViewAnnotation ::init();
+ Drawing::FeatureViewSymbol ::init();
Drawing::FeatureClip ::init();
}
diff --git a/src/Mod/Drawing/App/AppDrawingPy.cpp b/src/Mod/Drawing/App/AppDrawingPy.cpp
index 77a1a5fdb..3e06c579f 100644
--- a/src/Mod/Drawing/App/AppDrawingPy.cpp
+++ b/src/Mod/Drawing/App/AppDrawingPy.cpp
@@ -30,10 +30,12 @@
#include "ProjectionAlgos.h"
#include
#include
+#include
using namespace Drawing;
using namespace Part;
+using namespace std;
static PyObject *
project(PyObject *self, PyObject *args)
@@ -158,6 +160,44 @@ projectToDXF(PyObject *self, PyObject *args)
} PY_CATCH;
}
+static PyObject *
+removeSvgTags(PyObject *self, PyObject *args)
+{
+ const char* svgcode;
+ if (!PyArg_ParseTuple(args, "s",&svgcode))
+ return NULL;
+
+ PY_TRY {
+ string svg(svgcode);
+ string empty = "";
+ string endline = "--endOfLine--";
+ string linebreak = "\\n";
+ // removing linebreaks for regex to work
+ boost::regex e1 ("\\n");
+ svg = boost::regex_replace(svg, e1, endline);
+ // removing starting xml definition
+ boost::regex e2 ("<\\?xml.*?\\?>");
+ svg = boost::regex_replace(svg, e2, empty);
+ // removing starting svg tag
+ boost::regex e3 ("");
+ svg = boost::regex_replace(svg, e3, empty);
+ // removing sodipodi tags -- DANGEROUS, some sodipodi tags are single, better leave it
+ //boost::regex e4 ("");
+ //svg = boost::regex_replace(svg, e4, empty);
+ // removing metadata tags
+ boost::regex e5 ("");
+ svg = boost::regex_replace(svg, e5, empty);
+ // removing closing svg tags
+ boost::regex e6 ("");
+ svg = boost::regex_replace(svg, e6, empty);
+ // restoring linebreaks
+ boost::regex e7 ("--endOfLine--");
+ svg = boost::regex_replace(svg, e7, linebreak);
+ Py::String result(svg);
+ return Py::new_reference_to(result);
+ } PY_CATCH;
+}
+
/* registration table */
@@ -170,5 +210,7 @@ struct PyMethodDef Drawing_methods[] = {
"string = projectToSVG(TopoShape[,App.Vector Direction, string type]) -- Project a shape and return the SVG representation as string."},
{"projectToDXF" ,projectToDXF ,METH_VARARGS,
"string = projectToDXF(TopoShape[,App.Vector Direction, string type]) -- Project a shape and return the DXF representation as string."},
+ {"removeSvgTags" ,removeSvgTags ,METH_VARARGS,
+ "string = removeSvgTags(string) -- Removes the opening and closing svg tags and other metatags from a svg code, making it embeddable"},
{NULL, NULL} /* end of table marker */
};
diff --git a/src/Mod/Drawing/App/CMakeLists.txt b/src/Mod/Drawing/App/CMakeLists.txt
index 06d6ca7d2..4b6a285ad 100644
--- a/src/Mod/Drawing/App/CMakeLists.txt
+++ b/src/Mod/Drawing/App/CMakeLists.txt
@@ -29,6 +29,8 @@ SET(Features_SRCS
FeatureViewPart.h
FeatureViewAnnotation.cpp
FeatureViewAnnotation.h
+ FeatureViewSymbol.cpp
+ FeatureViewSymbol.h
FeatureClip.cpp
FeatureClip.h
PageGroup.cpp
diff --git a/src/Mod/Drawing/App/FeatureViewSymbol.cpp b/src/Mod/Drawing/App/FeatureViewSymbol.cpp
new file mode 100644
index 000000000..36f5b25ab
--- /dev/null
+++ b/src/Mod/Drawing/App/FeatureViewSymbol.cpp
@@ -0,0 +1,87 @@
+/***************************************************************************
+ * Copyright (c) Yorik van Havre (yorik@uncreated.net) 2013 *
+ * *
+ * 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_
+# include
+#endif
+
+#include
+
+#include
+#include
+
+#include "FeatureViewSymbol.h"
+
+using namespace Drawing;
+using namespace std;
+
+
+//===========================================================================
+// FeatureViewSymbol
+//===========================================================================
+
+PROPERTY_SOURCE(Drawing::FeatureViewSymbol, Drawing::FeatureView)
+
+
+FeatureViewSymbol::FeatureViewSymbol(void)
+{
+ static const char *vgroup = "Drawing view";
+
+ ADD_PROPERTY_TYPE(Symbol,(""),vgroup,App::Prop_Hidden,"The SVG code defining this symbol");
+
+}
+
+FeatureViewSymbol::~FeatureViewSymbol()
+{
+}
+
+App::DocumentObjectExecReturn *FeatureViewSymbol::execute(void)
+{
+ std::stringstream result;
+ result << "" << endl
+ << Symbol.getValue() << endl
+ << "" << endl;
+
+ // Apply the resulting fragment
+ ViewResult.setValue(result.str().c_str());
+
+ return App::DocumentObject::StdReturn;
+}
+
+// Python Drawing feature ---------------------------------------------------------
+
+namespace App {
+/// @cond DOXERR
+PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewSymbolPython, Drawing::FeatureViewSymbol)
+template<> const char* Drawing::FeatureViewSymbolPython::getViewProviderName(void) const {
+ return "DrawingGui::ViewProviderDrawingView";
+}
+/// @endcond
+
+// explicit template instantiation
+template class DrawingExport FeaturePythonT;
+}
diff --git a/src/Mod/Drawing/App/FeatureViewSymbol.h b/src/Mod/Drawing/App/FeatureViewSymbol.h
new file mode 100644
index 000000000..36877b656
--- /dev/null
+++ b/src/Mod/Drawing/App/FeatureViewSymbol.h
@@ -0,0 +1,71 @@
+/***************************************************************************
+ * Copyright (c) Yorik van Havre (yorik@uncreated.net 2013) *
+ * *
+ * 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 _FeatureViewSymbol_h_
+#define _FeatureViewSymbol_h_
+
+
+#include
+#include
+#include "FeatureView.h"
+#include
+
+
+namespace Drawing
+{
+
+
+/** Base class of all View Features in the drawing module
+ */
+class DrawingExport FeatureViewSymbol : public FeatureView
+{
+ PROPERTY_HEADER(Drawing::FeatureView);
+
+public:
+ /// Constructor
+ FeatureViewSymbol(void);
+ virtual ~FeatureViewSymbol();
+
+ App::PropertyString Symbol;
+
+ /** @name methods overide Feature */
+ //@{
+ /// recalculate the Feature
+ virtual App::DocumentObjectExecReturn *execute(void);
+ //@}
+
+ /// returns the type name of the ViewProvider
+ virtual const char* getViewProviderName(void) const {
+ return "DrawingGui::ViewProviderDrawingView";
+ }
+};
+
+typedef App::FeaturePythonT FeatureViewSymbolPython;
+
+
+} //namespace Drawing
+
+
+#endif
diff --git a/src/Mod/Drawing/Gui/Command.cpp b/src/Mod/Drawing/Gui/Command.cpp
index 8a206d52d..8bfd684f2 100644
--- a/src/Mod/Drawing/Gui/Command.cpp
+++ b/src/Mod/Drawing/Gui/Command.cpp
@@ -438,6 +438,60 @@ bool CmdDrawingClip::isActive(void)
return (getActiveGuiDocument() ? true : false);
}
+
+//===========================================================================
+// Drawing_Symbol
+//===========================================================================
+
+DEF_STD_CMD_A(CmdDrawingSymbol);
+
+CmdDrawingSymbol::CmdDrawingSymbol()
+ : Command("Drawing_Symbol")
+{
+ // seting the
+ sGroup = QT_TR_NOOP("Drawing");
+ sMenuText = QT_TR_NOOP("&Symbol");
+ sToolTipText = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing");
+ sWhatsThis = "Drawing_Symbol";
+ sStatusTip = QT_TR_NOOP("Inserts a symbol from a svg file in the active drawing");
+ sPixmap = "actions/drawing-symbol";
+}
+
+void CmdDrawingSymbol::activated(int iMsg)
+{
+
+ std::vector pages = this->getDocument()->getObjectsOfType(Drawing::FeaturePage::getClassTypeId());
+ if (pages.empty()){
+ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page to insert"),
+ QObject::tr("Create a page to insert."));
+ return;
+ }
+ // Reading an image
+ QString filename = Gui::FileDialog::getOpenFileName(Gui::getMainWindow(), QObject::tr("Choose an SVG file to open"), QString::null,
+ QObject::tr("Scalable Vector Graphics (*.svg *.svgz)"));
+ if (!filename.isEmpty())
+ {
+ std::string PageName = pages.front()->getNameInDocument();
+ std::string FeatName = getUniqueObjectName("Symbol");
+ openCommand("Create Symbol");
+ doCommand(Doc,"import Drawing");
+ doCommand(Doc,"f = open(\"%s\",\"r\")",(const char*)filename.toUtf8());
+ doCommand(Doc,"svg = f.read()");
+ doCommand(Doc,"f.close()");
+ doCommand(Doc,"App.activeDocument().addObject('Drawing::FeatureViewSymbol','%s')",FeatName.c_str());
+ doCommand(Doc,"App.activeDocument().%s.Symbol = Drawing.removeSvgTags(svg)",FeatName.c_str());
+ doCommand(Doc,"App.activeDocument().%s.addObject(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str());
+ updateActive();
+ commitCommand();
+ }
+}
+
+bool CmdDrawingSymbol::isActive(void)
+{
+ return (getActiveGuiDocument() ? true : false);
+}
+
+
//===========================================================================
// Drawing_ExportPage
//===========================================================================
@@ -536,6 +590,7 @@ void CreateDrawingCommands(void)
rcCmdMgr.addCommand(new CmdDrawingOpenBrowserView());
rcCmdMgr.addCommand(new CmdDrawingAnnotation());
rcCmdMgr.addCommand(new CmdDrawingClip());
+ rcCmdMgr.addCommand(new CmdDrawingSymbol());
rcCmdMgr.addCommand(new CmdDrawingExportPage());
rcCmdMgr.addCommand(new CmdDrawingProjectShape());
}
diff --git a/src/Mod/Drawing/Gui/Resources/Drawing.qrc b/src/Mod/Drawing/Gui/Resources/Drawing.qrc
index be83b03fc..683575fb2 100644
--- a/src/Mod/Drawing/Gui/Resources/Drawing.qrc
+++ b/src/Mod/Drawing/Gui/Resources/Drawing.qrc
@@ -18,6 +18,7 @@
icons/actions/drawing-openbrowser.svg
icons/actions/drawing-annotation.svg
icons/actions/drawing-clip.svg
+ icons/actions/drawing-symbol.svg
translations/Drawing_af.qm
translations/Drawing_de.qm
translations/Drawing_fi.qm
diff --git a/src/Mod/Drawing/Gui/Resources/icons/actions/drawing-symbol.svg b/src/Mod/Drawing/Gui/Resources/icons/actions/drawing-symbol.svg
new file mode 100644
index 000000000..666155132
--- /dev/null
+++ b/src/Mod/Drawing/Gui/Resources/icons/actions/drawing-symbol.svg
@@ -0,0 +1,439 @@
+
+
+
+
diff --git a/src/Mod/Drawing/Gui/Workbench.cpp b/src/Mod/Drawing/Gui/Workbench.cpp
index 9e604bca7..c8a88c78b 100644
--- a/src/Mod/Drawing/Gui/Workbench.cpp
+++ b/src/Mod/Drawing/Gui/Workbench.cpp
@@ -64,6 +64,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
*part << "Drawing_OpenBrowserView";
*part << "Drawing_Annotation";
*part << "Drawing_Clip";
+ *part << "Drawing_Symbol";
*part << "Drawing_ExportPage";
*part << "Separator";
*part << "Drawing_ProjectShape";
@@ -84,6 +85,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
*part << "Drawing_OpenBrowserView";
*part << "Drawing_Annotation";
*part << "Drawing_Clip";
+ *part << "Drawing_Symbol";
*part << "Drawing_ExportPage";
return root;
}