diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index bf5f491193..0ff8b8b3b2 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -42,6 +42,11 @@ #include "DrawViewBalloon.h" #include "DrawLeaderLine.h" #include "DrawRichAnno.h" +#include "Cosmetic.h" +#include "PropertyGeomFormatList.h" +#include "PropertyCenterLineList.h" +#include "PropertyCosmeticEdgeList.h" +#include "PropertyCosmeticVertexList.h" namespace TechDraw { extern PyObject* initModule(); @@ -83,7 +88,7 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawViewDetail ::init(); TechDraw::DrawViewBalloon ::init(); TechDraw::DrawLeaderLine ::init(); - TechDraw::DrawRichAnno ::init(); + TechDraw::DrawRichAnno ::init(); TechDraw::DrawTemplate ::init(); TechDraw::DrawParametricTemplate::init(); @@ -91,19 +96,28 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawViewClip ::init(); TechDraw::DrawHatch ::init(); - TechDraw::DrawGeomHatch ::init(); + TechDraw::DrawGeomHatch ::init(); TechDraw::DrawViewDraft ::init(); TechDraw::DrawViewArch ::init(); TechDraw::DrawViewImage ::init(); + TechDraw::PropertyGeomFormatList::init(); + TechDraw::GeomFormat ::init(); + TechDraw::PropertyCenterLineList::init(); + TechDraw::CenterLine ::init(); + TechDraw::PropertyCosmeticEdgeList::init(); + TechDraw::CosmeticEdge ::init(); + TechDraw::PropertyCosmeticVertexList::init(); + TechDraw::CosmeticVertex ::init(); + // Python Types TechDraw::DrawPagePython ::init(); TechDraw::DrawViewPython ::init(); TechDraw::DrawViewPartPython ::init(); - TechDraw::DrawViewMultiPython ::init(); + TechDraw::DrawViewMultiPython ::init(); TechDraw::DrawTemplatePython ::init(); TechDraw::DrawViewSymbolPython::init(); TechDraw::DrawLeaderLinePython::init(); - TechDraw::DrawRichAnnoPython::init(); + TechDraw::DrawRichAnnoPython ::init(); PyMOD_Return(mod); } diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 589bae478d..a6611d0e17 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -59,7 +59,10 @@ generate_from_xml(DrawProjGroupItemPy) generate_from_xml(DrawViewAnnotationPy) generate_from_xml(DrawLeaderLinePy) generate_from_xml(DrawRichAnnoPy) - +generate_from_xml(GeomFormatPy) +generate_from_xml(CenterLinePy) +generate_from_xml(CosmeticEdgePy) +generate_from_xml(CosmeticVertexPy) SET(Draw_SRCS DrawPage.cpp @@ -140,6 +143,14 @@ SET(Geometry_SRCS GeometryObject.h Cosmetic.cpp Cosmetic.h + PropertyGeomFormatList.cpp + PropertyGeomFormatList.h + PropertyCenterLineList.cpp + PropertyCenterLineList.h + PropertyCosmeticEdgeList.cpp + PropertyCosmeticEdgeList.h + PropertyCosmeticVertexList.cpp + PropertyCosmeticVertexList.h ) SET(Python_SRCS @@ -177,6 +188,14 @@ SET(Python_SRCS DrawLeaderLinePyImp.cpp DrawRichAnnoPy.xml DrawRichAnnoPyImp.cpp + GeomFormatPy.xml + GeomFormatPyImp.cpp + CenterLinePy.xml + CenterLinePyImp.cpp + CosmeticEdgePy.xml + CosmeticEdgePyImp.cpp + CosmeticVertexPy.xml + CosmeticVertexPyImp.cpp ) SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS}) diff --git a/src/Mod/TechDraw/App/CenterLinePy.xml b/src/Mod/TechDraw/App/CenterLinePy.xml new file mode 100644 index 0000000000..8d9c847898 --- /dev/null +++ b/src/Mod/TechDraw/App/CenterLinePy.xml @@ -0,0 +1,29 @@ + + + + + + CenterLine specifies appearance parameters for TechDraw Geometry objects + + + + Create a clone of this centerline + + + + + Create a copy of this centerline + + + + diff --git a/src/Mod/TechDraw/App/CenterLinePyImp.cpp b/src/Mod/TechDraw/App/CenterLinePyImp.cpp new file mode 100644 index 0000000000..6ba67416c5 --- /dev/null +++ b/src/Mod/TechDraw/App/CenterLinePyImp.cpp @@ -0,0 +1,118 @@ +/*************************************************************************** + * Copyright (c) 2008 Werner Mayer * + * * + * 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 "Cosmetic.h" +#include "CenterLinePy.h" +#include "CenterLinePy.cpp" + +using namespace TechDraw; + +// returns a string which represents the object e.g. when printed in python +std::string CenterLinePy::representation(void) const +{ + return ""; +} + +PyObject *CenterLinePy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper +{ + // never create such objects with the constructor + PyErr_SetString(PyExc_RuntimeError, + "You cannot create an instance of the abstract class 'CenterLine'."); + return 0; +} + +// constructor method +int CenterLinePy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/) +{ + return 0; +} + +PyObject* CenterLinePy::clone(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + TechDraw::CenterLine* geom = this->getCenterLinePtr(); + PyTypeObject* type = this->GetType(); + PyObject* cpy = 0; + // let the type object decide + if (type->tp_new) + cpy = type->tp_new(type, this, 0); + if (!cpy) { + PyErr_SetString(PyExc_TypeError, "failed to create clone of CenterLine"); + return 0; + } + + TechDraw::CenterLinePy* geompy = static_cast(cpy); + // the PyMake function must have created the corresponding instance of the 'CenterLine' subclass + // so delete it now to avoid a memory leak + if (geompy->_pcTwinPointer) { + TechDraw::CenterLine* clone = static_cast(geompy->_pcTwinPointer); + delete clone; + } + geompy->_pcTwinPointer = geom->clone(); + return cpy; +} + +PyObject* CenterLinePy::copy(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + TechDraw::CenterLine* geom = this->getCenterLinePtr(); + PyTypeObject* type = this->GetType(); + PyObject* cpy = 0; + // let the type object decide + if (type->tp_new) + cpy = type->tp_new(type, this, 0); + if (!cpy) { + PyErr_SetString(PyExc_TypeError, "failed to create copy of CenterLine"); + return 0; + } + + TechDraw::CenterLinePy* geompy = static_cast(cpy); + // the PyMake function must have created the corresponding instance of the 'CenterLine' subclass + // so delete it now to avoid a memory leak + if (geompy->_pcTwinPointer) { + TechDraw::CenterLine* copy = static_cast(geompy->_pcTwinPointer); + delete copy; + } + geompy->_pcTwinPointer = geom->copy(); + return cpy; +} + +PyObject *CenterLinePy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int CenterLinePy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index 6d8f2b2440..c26942fb0c 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -39,11 +39,19 @@ #include #include #include +#include +#include #include +#include #include #include +#include +#include +#include +#include + #include "DrawUtil.h" #include "GeometryObject.h" #include "Geometry.h" @@ -75,10 +83,10 @@ LineFormat::LineFormat(int style, void LineFormat::dump(char* title) { Base::Console().Message("LF::dump - %s \n",title); - Base::Console().Message("LF::dump - %s \n",toCSV().c_str()); + Base::Console().Message("LF::dump - %s \n",toString().c_str()); } -std::string LineFormat::toCSV(void) const +std::string LineFormat::toString(void) const { std::stringstream ss; ss << m_style << "," << @@ -88,24 +96,24 @@ std::string LineFormat::toCSV(void) const return ss.str(); } -bool LineFormat::fromCSV(std::string& lineSpec) -{ - unsigned int maxCells = 4; - if (lineSpec.length() == 0) { - Base::Console().Message( "LineFormat::fromCSV - lineSpec empty\n"); - return false; - } - std::vector values = DrawUtil::split(lineSpec); - if (values.size() < maxCells) { - Base::Console().Message( "LineFormat::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() ); - return false; - } - m_style = atoi(values[0].c_str()); - m_weight= atof(values[1].c_str()); - m_color.fromHexString(values[2]); - m_visible = atoi(values[3].c_str()); - return true; -} +//bool LineFormat::fromCSV(std::string& lineSpec) +//{ +// unsigned int maxCells = 4; +// if (lineSpec.length() == 0) { +// Base::Console().Message( "LineFormat::fromCSV - lineSpec empty\n"); +// return false; +// } +// std::vector values = DrawUtil::split(lineSpec); +// if (values.size() < maxCells) { +// Base::Console().Message( "LineFormat::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() ); +// return false; +// } +// m_style = atoi(values[0].c_str()); +// m_weight= atof(values[1].c_str()); +// m_color.fromHexString(values[2]); +// m_visible = atoi(values[3].c_str()); +// return true; +//} //static preference getters. double LineFormat::getDefEdgeWidth() @@ -139,6 +147,8 @@ int LineFormat::getDefEdgeStyle() //**************************************************************************************** +TYPESYSTEM_SOURCE(TechDraw::CosmeticVertex, Base::Persistence) + CosmeticVertex::CosmeticVertex() : TechDraw::Vertex() { point(Base::Vector3d(0.0, 0.0, 0.0)); @@ -154,6 +164,15 @@ CosmeticVertex::CosmeticVertex() : TechDraw::Vertex() visible = true; } +CosmeticVertex::CosmeticVertex(const TechDraw::CosmeticVertex* cv) : TechDraw::Vertex(cv) +{ + linkGeom = cv->linkGeom; + color = cv->color; + size = cv->size; + style = cv->style; + visible = cv->visible; +} + CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc) { Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> @@ -169,7 +188,7 @@ CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc) visible = true; } -std::string CosmeticVertex::toCSV(void) const +std::string CosmeticVertex::toString(void) const { std::stringstream ss; ss << point().x << "," << @@ -184,74 +203,144 @@ std::string CosmeticVertex::toCSV(void) const return ss.str(); } -bool CosmeticVertex::fromCSV(std::string& lineSpec) +//bool CosmeticVertex::fromCSV(std::string& lineSpec) +//{ +// unsigned int maxCells = 8; +// if (lineSpec.length() == 0) { +// Base::Console().Message( "CosmeticVertex::fromCSV - lineSpec empty\n"); +// return false; +// } +// std::vector values = DrawUtil::split(lineSpec); +// if (values.size() < maxCells) { +// Base::Console().Message( "CosmeticVertex::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() ); +// return false; +// } +// double x = atof(values[0].c_str()); +// double y = atof(values[1].c_str()); +// double z = atof(values[2].c_str()); +// point(Base::Vector3d (x,y,z)); +// linkGeom = atoi(values[3].c_str()); +// color.fromHexString(values[4]); +// size = atof(values[5].c_str()); +// style = atoi(values[6].c_str()); +// visible = atoi(values[7].c_str()); +// return true; +//} + +// Persistence implementers +unsigned int CosmeticVertex::getMemSize (void) const { - unsigned int maxCells = 8; - if (lineSpec.length() == 0) { - Base::Console().Message( "CosmeticVertex::fromCSV - lineSpec empty\n"); - return false; - } - std::vector values = DrawUtil::split(lineSpec); - if (values.size() < maxCells) { - Base::Console().Message( "CosmeticVertex::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() ); - return false; - } - double x = atof(values[0].c_str()); - double y = atof(values[1].c_str()); - double z = atof(values[2].c_str()); - point(Base::Vector3d (x,y,z)); - linkGeom = atoi(values[3].c_str()); - color.fromHexString(values[4]); - size = atof(values[5].c_str()); - style = atoi(values[6].c_str()); - visible = atoi(values[7].c_str()); - return true; + return 1; +} + +void CosmeticVertex::Save(Base::Writer &writer) const +{ + TechDraw::Vertex::Save(writer); + writer.Stream() << writer.ind() << "" << endl; + writer.Stream() << writer.ind() << "" << endl; + writer.Stream() << writer.ind() << "" << endl; + writer.Stream() << writer.ind() << "