From f63cd9255ad1632064906619acb00fa1627c3838 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sun, 1 Dec 2019 09:18:24 -0500 Subject: [PATCH] [TD]Python routines & extension for CosmeticVertex --- src/Mod/TechDraw/App/AppTechDraw.cpp | 12 +- src/Mod/TechDraw/App/CMakeLists.txt | 5 + src/Mod/TechDraw/App/Cosmetic.cpp | 4 +- src/Mod/TechDraw/App/Cosmetic.h | 1 + src/Mod/TechDraw/App/CosmeticExtension.cpp | 192 +++++++++++++++ src/Mod/TechDraw/App/CosmeticExtension.h | 73 ++++++ src/Mod/TechDraw/App/CosmeticExtensionPy.xml | 17 ++ .../TechDraw/App/CosmeticExtensionPyImp.cpp | 54 +++++ src/Mod/TechDraw/App/CosmeticVertexPy.xml | 13 ++ src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp | 63 ++++- src/Mod/TechDraw/App/DrawDimHelper.cpp | 4 +- src/Mod/TechDraw/App/DrawViewPart.cpp | 220 +++--------------- src/Mod/TechDraw/App/DrawViewPart.h | 24 +- src/Mod/TechDraw/App/DrawViewPartPy.xml | 23 +- src/Mod/TechDraw/App/DrawViewPartPyImp.cpp | 189 ++++++++++++--- src/Mod/TechDraw/App/GeometryObject.cpp | 20 ++ src/Mod/TechDraw/App/GeometryObject.h | 7 +- src/Mod/TechDraw/Gui/AppTechDrawGui.cpp | 4 + src/Mod/TechDraw/Gui/CMakeLists.txt | 2 + src/Mod/TechDraw/Gui/QGIViewPart.cpp | 3 +- .../Gui/ViewProviderCosmeticExtension.cpp | 67 ++++++ .../Gui/ViewProviderCosmeticExtension.h | 52 +++++ 22 files changed, 800 insertions(+), 249 deletions(-) create mode 100644 src/Mod/TechDraw/App/CosmeticExtension.cpp create mode 100644 src/Mod/TechDraw/App/CosmeticExtension.h create mode 100644 src/Mod/TechDraw/App/CosmeticExtensionPy.xml create mode 100644 src/Mod/TechDraw/App/CosmeticExtensionPyImp.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp create mode 100644 src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.h diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index a7980c8486..7a1a1fc7c0 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -52,6 +52,8 @@ #include "PropertyCosmeticEdgeList.h" #include "PropertyCosmeticVertexList.h" +#include "CosmeticExtension.h" + namespace TechDraw { extern PyObject* initModule(); } @@ -71,11 +73,6 @@ PyMOD_INIT_FUNC(TechDraw) PyObject* mod = TechDraw::initModule(); Base::Console().Log("Loading TechDraw module... done\n"); - - // NOTE: To finish the initialization of our own type objects we must - // call PyType_Ready, otherwise we run into a segmentation fault, later on. - // This function is responsible for adding inherited slots from a type's base class. - TechDraw::DrawPage ::init(); TechDraw::DrawView ::init(); TechDraw::DrawViewCollection ::init(); @@ -118,6 +115,10 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::PropertyCosmeticVertexList::init(); TechDraw::CosmeticVertex ::init(); + TechDraw::CosmeticExtension ::init(); + TechDraw::CosmeticExtensionPython::init(); + + // are these python init calls required? some modules don't have them // Python Types TechDraw::DrawPagePython ::init(); TechDraw::DrawViewPython ::init(); @@ -130,5 +131,6 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawTilePython ::init(); TechDraw::DrawTileWeldPython ::init(); TechDraw::DrawWeldSymbolPython::init(); + PyMOD_Return(mod); } diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index d6fe80db2e..7f5ffdfb4a 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -67,6 +67,7 @@ generate_from_xml(CosmeticVertexPy) generate_from_xml(DrawTilePy) generate_from_xml(DrawTileWeldPy) generate_from_xml(DrawWeldSymbolPy) +generate_from_xml(CosmeticExtensionPy) SET(Draw_SRCS DrawPage.cpp @@ -167,6 +168,8 @@ SET(Geometry_SRCS PropertyCosmeticEdgeList.h PropertyCosmeticVertexList.cpp PropertyCosmeticVertexList.h + CosmeticExtension.cpp + CosmeticExtension.h ) SET(Python_SRCS @@ -220,6 +223,8 @@ SET(Python_SRCS DrawTileWeldPyImp.cpp DrawWeldSymbolPy.xml DrawWeldSymbolPyImp.cpp + CosmeticExtensionPy.xml + CosmeticExtensionPyImp.cpp ) SOURCE_GROUP("Mod" FILES ${TechDraw_SRCS}) diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index d6f170ead4..906c0de20a 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -323,7 +323,9 @@ CosmeticVertex* CosmeticVertex::clone(void) const PyObject* CosmeticVertex::getPyObject(void) { - return new CosmeticVertexPy(new CosmeticVertex(this->copy())); +// return new CosmeticVertexPy(new CosmeticVertex(this->copy())); //shouldn't this be clone? + PyObject* result = new CosmeticVertexPy(this->clone()); //shouldn't this be clone? + return result; } void CosmeticVertex::dump(const char* title) diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index 97b3eed4e5..804cd07aa1 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -91,6 +91,7 @@ public: Base::Vector3d permaPoint; //permanent, unscaled value int linkGeom; //connection to corresponding "geom" Vertex (fragile - index based!) + //better to do reverse search for CosmeticTag in vertex geometry App::Color color; double size; int style; diff --git a/src/Mod/TechDraw/App/CosmeticExtension.cpp b/src/Mod/TechDraw/App/CosmeticExtension.cpp new file mode 100644 index 0000000000..a8ccf1c11a --- /dev/null +++ b/src/Mod/TechDraw/App/CosmeticExtension.cpp @@ -0,0 +1,192 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * 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 "CosmeticExtension.h" + +#include + +#include +#include + +#include "CosmeticExtensionPy.h" + +#include "Cosmetic.h" +#include "DrawUtil.h" +#include "DrawViewPart.h" + +using namespace TechDraw; +using namespace std; + + +EXTENSION_PROPERTY_SOURCE(TechDraw::CosmeticExtension, App::DocumentObjectExtension) + +CosmeticExtension::CosmeticExtension() +{ + static const char *cgroup = "Cosmetics"; + + EXTENSION_ADD_PROPERTY_TYPE(CosmeticVertexes ,(0),cgroup,App::Prop_Output,"CosmeticVertex Save/Restore"); + + initExtensionType(CosmeticExtension::getExtensionClassTypeId()); +} + +CosmeticExtension::~CosmeticExtension() +{ +} + +//void CosmeticExtension::extHandleChangedPropertyName(Base::XMLReader &reader, +// const char* TypeName, +// const char* PropName) +//{ +//} + +//============================================================================== +//CosmeticVertex x,y are stored as unscaled, but mirrored (inverted Y) values. +//if you are creating a CV based on calculations of scaled geometry, you need to +//unscale x,y before creation. +//if you are creating a CV based on calculations of mirrored geometry, you need to +//mirror again before creation. + +//returns unique CV id +//only adds cv to cvlist property. does not add to display geometry until dvp executes. +std::string CosmeticExtension::addCosmeticVertex(Base::Vector3d pos) +{ +// Base::Console().Message("CEx::addCosmeticVertex(%s)\n", + // DrawUtil::formatVector(pos).c_str()); + std::vector verts = CosmeticVertexes.getValues(); + Base::Vector3d tempPos = DrawUtil::invertY(pos); + TechDraw::CosmeticVertex* cv = new TechDraw::CosmeticVertex(tempPos); + verts.push_back(cv); + CosmeticVertexes.setValues(verts); + std::string result = cv->getTagAsString(); + return result; +} + +//get CV by unique id +TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertex(std::string tagString) const +{ +// Base::Console().Message("CEx::getCosmeticVertex(%s)\n", tagString.c_str()); + CosmeticVertex* result = nullptr; + const std::vector verts = CosmeticVertexes.getValues(); + for (auto& cv: verts) { + std::string cvTag = cv->getTagAsString(); + if (cvTag == tagString) { + result = cv; + break; + } + } + return result; +} + +// find the cosmetic vertex corresponding to selection name (Vertex5) +// used when selecting +TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(std::string name) const +{ +// Base::Console().Message("CEx::getCVBySelection(%s)\n",name.c_str()); + CosmeticVertex* result = nullptr; + App::DocumentObject* extObj = const_cast (getExtendedObject()); + TechDraw::DrawViewPart* dvp = dynamic_cast(extObj); + if (dvp == nullptr) { + return result; + } + int idx = DrawUtil::getIndexFromName(name); + TechDraw::Vertex* v = dvp->getProjVertexByIndex(idx); + if (v == nullptr) { + return result; + } + if (!v->cosmeticTag.empty()) { + result = getCosmeticVertex(v->cosmeticTag); + } + return result; +} + +//overload for index only +TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(int i) const +{ +// Base::Console().Message("CEx::getCVBySelection(%d)\n", i); + std::stringstream ss; + ss << "Vertex" << i; + std::string vName = ss.str(); + return getCosmeticVertexBySelection(vName); +} + +void CosmeticExtension::removeCosmeticVertex(std::string delTag) +{ +// Base::Console().Message("DVP::removeCV(%s)\n", delTag.c_str()); + std::vector cVerts = CosmeticVertexes.getValues(); + std::vector newVerts; + for (auto& cv: cVerts) { + if (cv->getTagAsString() != delTag) { + newVerts.push_back(cv); + } + } + CosmeticVertexes.setValues(newVerts); +} + +void CosmeticExtension::removeCosmeticVertex(std::vector delTags) +{ + for (auto& t: delTags) { + removeCosmeticVertex(t); + } +} + +bool CosmeticExtension::replaceCosmeticVertex(CosmeticVertex* newCV) +{ +// Base::Console().Message("DVP::replaceCV(%s)\n", newCV->getTagAsString().c_str()); + bool result = false; + std::vector cVerts = CosmeticVertexes.getValues(); + std::vector newVerts; + std::string tag = newCV->getTagAsString(); + for (auto& cv: cVerts) { + if (cv->getTagAsString() == tag) { + newVerts.push_back(newCV); + result = true; + } else { + newVerts.push_back(cv); + } + } + CosmeticVertexes.setValues(newVerts); + return result; +} + +//================================================================================ +PyObject* CosmeticExtension::getExtensionPyObject(void) { + if (ExtensionPythonObject.is(Py::_None())){ + // ref counter is set to 1 + ExtensionPythonObject = Py::Object(new CosmeticExtensionPy(this),true); + } + return Py::new_reference_to(ExtensionPythonObject); +} + +namespace App { +/// @cond DOXERR + EXTENSION_PROPERTY_SOURCE_TEMPLATE(TechDraw::CosmeticExtensionPython, TechDraw::CosmeticExtension) +/// @endcond + +// explicit template instantiation + template class TechDrawExport ExtensionPythonT; +} + + diff --git a/src/Mod/TechDraw/App/CosmeticExtension.h b/src/Mod/TechDraw/App/CosmeticExtension.h new file mode 100644 index 0000000000..a6b47212d9 --- /dev/null +++ b/src/Mod/TechDraw/App/CosmeticExtension.h @@ -0,0 +1,73 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * 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 TECHDRAW_COSMETICEXTENSION_H +#define TECHDRAW_COSMETICEXTENSION_H + +#include +#include +#include +#include + +#include +#include + +#include "PropertyCosmeticVertexList.h" + + +namespace TechDraw { +class DrawViewPart; +class GeometryObject; + +class TechDrawExport CosmeticExtension : public App::DocumentObjectExtension { + EXTENSION_PROPERTY_HEADER(TechDraw::CosmeticObject); + +public: + CosmeticExtension(); + virtual ~CosmeticExtension(); + + TechDraw::PropertyCosmeticVertexList CosmeticVertexes; + + virtual std::string addCosmeticVertex(Base::Vector3d pos); + virtual CosmeticVertex* getCosmeticVertexBySelection(std::string name) const; + virtual CosmeticVertex* getCosmeticVertexBySelection(int i) const; + virtual CosmeticVertex* getCosmeticVertex(std::string id) const; + virtual bool replaceCosmeticVertex(CosmeticVertex* newVertex); + virtual void removeCosmeticVertex(std::string tag); + virtual void removeCosmeticVertex(std::vector delTags); + + PyObject* getExtensionPyObject(void); + +protected: +/* virtual void extHandleChangedPropertyName(Base::XMLReader &reader, */ +/* const char* TypeName, */ +/* const char* PropName);*/ + +private: + +}; + +typedef App::ExtensionPythonT CosmeticExtensionPython; + +} //end namespace TechDraw + +#endif //TECHDRAW_COSMETICEXTENSION_H diff --git a/src/Mod/TechDraw/App/CosmeticExtensionPy.xml b/src/Mod/TechDraw/App/CosmeticExtensionPy.xml new file mode 100644 index 0000000000..a233d1f833 --- /dev/null +++ b/src/Mod/TechDraw/App/CosmeticExtensionPy.xml @@ -0,0 +1,17 @@ + + + + + + This object represents cosmetic features for a DrawViewPart. + + + diff --git a/src/Mod/TechDraw/App/CosmeticExtensionPyImp.cpp b/src/Mod/TechDraw/App/CosmeticExtensionPyImp.cpp new file mode 100644 index 0000000000..d90b6a9f80 --- /dev/null +++ b/src/Mod/TechDraw/App/CosmeticExtensionPyImp.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * 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" + +#include +#include +#include +#include + +#include "Mod/TechDraw/App/CosmeticExtension.h" + +// inclusion of the generated files (generated out of CosmeticExtensionPy.xml) +#include "CosmeticExtensionPy.h" +#include "CosmeticExtensionPy.cpp" + +using namespace TechDraw; + +// returns a string which represents the object e.g. when printed in python +std::string CosmeticExtensionPy::representation(void) const +{ + return std::string(""); +} + +PyObject *CosmeticExtensionPy::getCustomAttributes(const char* /*attr*/) const +{ + return 0; +} + +int CosmeticExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +{ + return 0; +} + + diff --git a/src/Mod/TechDraw/App/CosmeticVertexPy.xml b/src/Mod/TechDraw/App/CosmeticVertexPy.xml index fb512c3db0..bccca58862 100644 --- a/src/Mod/TechDraw/App/CosmeticVertexPy.xml +++ b/src/Mod/TechDraw/App/CosmeticVertexPy.xml @@ -31,5 +31,18 @@ + + + Gives the position of this CosmeticVertex as vector. + + + + + + Show/hide the vertex. + + + + diff --git a/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp b/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp index 7bab6e50de..8955041ff8 100644 --- a/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp +++ b/src/Mod/TechDraw/App/CosmeticVertexPyImp.cpp @@ -27,10 +27,18 @@ # include #endif +#include +#include +#include +#include + + #include "Cosmetic.h" #include "CosmeticVertexPy.h" #include "CosmeticVertexPy.cpp" +#include "DrawUtil.h" + using namespace TechDraw; // returns a string which represents the object e.g. when printed in python @@ -59,7 +67,7 @@ PyObject* CosmeticVertexPy::clone(PyObject *args) return NULL; TechDraw::CosmeticVertex* geom = this->getCosmeticVertexPtr(); - geom->dump("CEPYI::clone"); +// geom->dump("CEPYI::clone"); PyTypeObject* type = this->GetType(); PyObject* cpy = 0; // let the type object decide @@ -87,7 +95,7 @@ PyObject* CosmeticVertexPy::copy(PyObject *args) return NULL; TechDraw::CosmeticVertex* geom = this->getCosmeticVertexPtr(); - geom->dump("CEPYI::copy"); +// geom->dump("CEPYI::copy"); PyTypeObject* type = this->GetType(); PyObject* cpy = 0; // let the type object decide @@ -115,6 +123,57 @@ Py::String CosmeticVertexPy::getTag(void) const return Py::String(tmp); } +Py::Object CosmeticVertexPy::getPoint(void) const +{ + Base::Vector3d point = getCosmeticVertexPtr()->permaPoint; + point = DrawUtil::invertY(point); + return Py::asObject(new Base::VectorPy(point)); +} + +void CosmeticVertexPy::setPoint(Py::Object arg) +{ + PyObject* p = arg.ptr(); + if (PyObject_TypeCheck(p, &(Base::VectorPy::Type))) { + Base::Vector3d point = static_cast(p)->value(); + getCosmeticVertexPtr()->permaPoint = + DrawUtil::invertY(point); + } + else if (PyObject_TypeCheck(p, &PyTuple_Type)) { + Base::Vector3d point = Base::getVectorFromTuple(p); + getCosmeticVertexPtr()->permaPoint = + DrawUtil::invertY(point); + } + else { + std::string error = std::string("type must be 'Vector', not "); + error += p->ob_type->tp_name; + throw Py::TypeError(error); + } +} + +Py::Boolean CosmeticVertexPy::getShow(void) const +{ + bool show = getCosmeticVertexPtr()->visible; + if (show) { + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } +// return Py::asObject(); +} + +void CosmeticVertexPy::setShow(Py::Boolean arg) +{ + PyObject* p = arg.ptr(); + if (PyBool_Check(p)) { + if (p == Py_True) { + getCosmeticVertexPtr()->visible = true; + } else { + getCosmeticVertexPtr()->visible = false; + } + } +} + + PyObject *CosmeticVertexPy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/TechDraw/App/DrawDimHelper.cpp b/src/Mod/TechDraw/App/DrawDimHelper.cpp index 17021f2606..4cddb7fbd2 100644 --- a/src/Mod/TechDraw/App/DrawDimHelper.cpp +++ b/src/Mod/TechDraw/App/DrawDimHelper.cpp @@ -350,10 +350,10 @@ DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp, //regular dims will have trouble with geom indexes! Base::Vector3d cleanMin = DrawUtil::invertY(inMin) / scale; - std::string tag1 = dvp->addCosmeticVertexSS(cleanMin); + std::string tag1 = dvp->addCosmeticVertex(cleanMin); int iGV1 = dvp->add1CVToGV(tag1); Base::Vector3d cleanMax = DrawUtil::invertY(inMax) / scale; - std::string tag2 = dvp->addCosmeticVertexSS(cleanMax); + std::string tag2 = dvp->addCosmeticVertex(cleanMax); int iGV2 = dvp->add1CVToGV(tag2); std::vector objs; diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index eab1132a04..103d164e05 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -118,7 +118,9 @@ using namespace std; //=========================================================================== -PROPERTY_SOURCE(TechDraw::DrawViewPart, TechDraw::DrawView) +//PROPERTY_SOURCE(TechDraw::DrawViewPart, TechDraw::DrawView) +PROPERTY_SOURCE_WITH_EXTENSIONS(TechDraw::DrawViewPart, + TechDraw::DrawView) DrawViewPart::DrawViewPart(void) : geometryObject(0) @@ -127,8 +129,11 @@ DrawViewPart::DrawViewPart(void) : static const char *sgroup = "HLR Parameters"; nowUnsetting = false; - Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> - GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); + CosmeticExtension::initExtension(this); + + Base::Reference hGrp = App::GetApplication(). + GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/General"); double defDist = hGrp->GetFloat("FocusDistance",100.0); //properties that affect Geometry @@ -155,7 +160,7 @@ DrawViewPart::DrawViewPart(void) : ADD_PROPERTY_TYPE(IsoHidden ,(false),sgroup,App::Prop_None,"Hidden Iso u,v lines on/off"); ADD_PROPERTY_TYPE(IsoCount ,(0),sgroup,App::Prop_None,"Number of isoparameters"); - ADD_PROPERTY_TYPE(CosmeticVertexes ,(0),sgroup,App::Prop_Output,"CosmeticVertex Save/Restore"); +// ADD_PROPERTY_TYPE(CosmeticVertexes ,(0),sgroup,App::Prop_Output,"CosmeticVertex Save/Restore"); ADD_PROPERTY_TYPE(CosmeticEdges ,(0),sgroup,App::Prop_Output,"CosmeticEdge Save/Restore"); ADD_PROPERTY_TYPE(CenterLines ,(0),sgroup,App::Prop_Output,"Geometry format Save/Restore"); ADD_PROPERTY_TYPE(GeomFormats ,(0),sgroup,App::Prop_Output,"Geometry format Save/Restore"); @@ -276,6 +281,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) getNameInDocument(),diffOut); #endif //#if MOD_TECHDRAW_HANDLE_FACES +// Base::Console().Message("DVP::execute - exits\n"); return DrawView::execute(); } @@ -308,6 +314,7 @@ short DrawViewPart::mustExecute() const void DrawViewPart::onChanged(const App::Property* prop) { DrawView::onChanged(prop); + //TODO: when scale changes, any Dimensions for this View sb recalculated. DVD should pick this up subject to topological naming issues. } @@ -988,179 +995,12 @@ void DrawViewPart::clearCosmeticVertexes(void) CosmeticVertexes.setValues(noVerts); } -//CosmeticVertex x,y are stored as unscaled, but mirrored values. -//if you are creating a CV based on calculations of scaled geometry, you need to -//unscale x,y before creation. -//if you are creating a CV based on calculations of mirrored geometry, you need to -//mirror again before creation. - -//returns CosmeticVertex index! not geomVertexNumber! -int DrawViewPart::addCosmeticVertex(Base::Vector3d pos) -{ -// Base::Console().Message("DVP::addCosmeticVertex(%s)\n", -// DrawUtil::formatVector(pos).c_str()); - std::vector verts = CosmeticVertexes.getValues(); - Base::Vector3d tempPos = DrawUtil::invertY(pos); - TechDraw::CosmeticVertex* cv = new TechDraw::CosmeticVertex(tempPos); - int newIdx = (int) (verts.size()); - verts.push_back(cv); - CosmeticVertexes.setValues(verts); - return newIdx; -} - -std::string DrawViewPart::addCosmeticVertexSS(Base::Vector3d pos) -{ -// Base::Console().Message("DVP::addCosmeticVertexSS(%s)\n", - // DrawUtil::formatVector(pos).c_str()); - std::vector verts = CosmeticVertexes.getValues(); - Base::Vector3d tempPos = DrawUtil::invertY(pos); - TechDraw::CosmeticVertex* cv = new TechDraw::CosmeticVertex(tempPos); - verts.push_back(cv); - CosmeticVertexes.setValues(verts); - std::string result = cv->getTagAsString(); - return result; -} - -int DrawViewPart::addCosmeticVertex(CosmeticVertex* cv) -{ - std::vector verts = CosmeticVertexes.getValues(); - int newIdx = (int) verts.size(); - verts.push_back(cv); - CosmeticVertexes.setValues(verts); - return newIdx; -} - -void DrawViewPart::removeCosmeticVertex(TechDraw::CosmeticVertex* cv) -{ -// Base::Console().Message("DVP::removeCosmeticVertex(%X)\n", cv); - bool found = false; - int i = 0; - std::vector verts = CosmeticVertexes.getValues(); - int stop = verts.size(); - for ( ; i < stop; i++) { - TechDraw::CosmeticVertex* v = verts.at(i); - if (cv == v) { - found = true; - break; - } - } - if ( (cv != nullptr) && - (found) ) { - removeCosmeticVertex(i); - } -} - -//this is by CV index, not the index returned by selection -void DrawViewPart::removeCosmeticVertex(int idx) -{ -// Base::Console().Message("DVP::removeCV(%d)\n", idx); - std::vector verts = CosmeticVertexes.getValues(); - if (idx < (int) verts.size()) { - verts.erase(verts.begin() + idx); - CosmeticVertexes.setValues(verts); - recomputeFeature(); - } -} - -void DrawViewPart::removeCosmeticVertex(std::string delTag) -{ -// Base::Console().Message("DVP::removeCV(%s)\n", delTag.c_str()); - std::vector cVerts = CosmeticVertexes.getValues(); - std::vector newVerts; - for (auto& cv: cVerts) { - if (cv->getTagAsString() != delTag) { - newVerts.push_back(cv); - } - } - CosmeticVertexes.setValues(newVerts); -// recomputeFeature(); -} - -void DrawViewPart::removeCosmeticVertex(std::vector delTags) -{ - std::vector cVerts = CosmeticVertexes.getValues(); -// Base::Console().Message("DVP::removeCosmeticVertex(list) - cVerts: %d\n", cVerts.size()); - std::vector newVerts; - for (auto& cv: cVerts) { - bool found = false; - for (auto& dt: delTags) { - if (cv->getTagAsString() == dt) { - found = true; //this cv is in delete list - break; - } - } - if (!found) { - newVerts.push_back(cv); - } - } - CosmeticVertexes.setValues(newVerts); -} - -//transition code. temporary. not used?? -int DrawViewPart::getCosmeticVertexIndex(std::string tagString) -{ - Base::Console().Message("DVP::getCosmeticVertexIndex(%s) - deprec?\n", tagString.c_str()); - int result = -1; - int iCV = 0; - const std::vector verts = CosmeticVertexes.getValues(); - for (auto& cv: verts) { - std::string cvTag = cv->getTagAsString(); - if (cvTag == tagString) { - result = iCV; - break; - } - iCV++; - } - return result; -} - -TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertex(std::string tagString) const -{ - CosmeticVertex* result = nullptr; - const std::vector verts = CosmeticVertexes.getValues(); - for (auto& cv: verts) { - std::string cvTag = cv->getTagAsString(); - if (cvTag == tagString) { - result = cv; - break; - } - } - return result; -} - -TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByIndex(int idx) const -{ - CosmeticVertex* result = nullptr; - const std::vector verts = CosmeticVertexes.getValues(); - if (idx < (int) verts.size()) { - result = verts.at(idx); - } - return result; -} - -// find the cosmetic vertex corresponding to geometry vertex idx -// used when selecting -TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByGeom(int idx) const -{ - CosmeticVertex* result = nullptr; - std::vector verts = CosmeticVertexes.getValues(); - TechDraw::Vertex* v = getProjVertexByIndex(idx); - if (v == nullptr) { - return result; - } - if (!v->cosmeticTag.empty()) { - result = getCosmeticVertex(v->cosmeticTag); - } - return result; -} - //add the cosmetic verts to geometry vertex list void DrawViewPart::addCosmeticVertexesToGeom(void) { // Base::Console().Message("DVP::addCosmeticVertexesToGeom()\n"); int iCV = 0; const std::vector cVerts = CosmeticVertexes.getValues(); - const std::vector gVerts = getVertexGeometry(); int stop = (int) cVerts.size(); for ( ; iCV < stop; iCV++) { int iGV = geometryObject->addCosmeticVertex(cVerts.at(iCV)->scaled(getScale()), @@ -1170,17 +1010,6 @@ void DrawViewPart::addCosmeticVertexesToGeom(void) } } -int DrawViewPart::add1CVToGV(int iCV) -{ - Base::Console().Message("DVP::add1CVToGV(%d) 1 - deprec?\n", iCV); - TechDraw::CosmeticVertex* cv = getCosmeticVertexByIndex(iCV); - int iGV = geometryObject->addCosmeticVertex(cv->scaled(getScale()), - cv->getTagAsString(), - iCV); - cv->linkGeom = iGV; - return iGV; -} - int DrawViewPart::add1CVToGV(std::string tag) { // Base::Console().Message("DVP::add1CVToGV(%s) 2\n", tag.c_str()); @@ -1188,7 +1017,6 @@ int DrawViewPart::add1CVToGV(std::string tag) if (cv == nullptr) { Base::Console().Message("DVP::add1CVToGV 2 - cv %s not found\n", tag.c_str()); } -// int iCV = getCosmeticVertexIndex(tag); //transition int iCV = -1; int iGV = geometryObject->addCosmeticVertex(cv->scaled(getScale()), cv->getTagAsString(), @@ -1197,6 +1025,23 @@ int DrawViewPart::add1CVToGV(std::string tag) return iGV; } +//update Vertex geometry with current CV's +void DrawViewPart::refreshCVGeoms(void) +{ +// Base::Console().Message("DVP::refreshCVGeoms()\n"); + + std::vector gVerts = getVertexGeometry(); + std::vector newGVerts; + for (auto& gv :gVerts) { + if (gv->cosmeticTag.empty()) { //keep only non-cv vertices + newGVerts.push_back(gv); + } + } + getGeometryObject()->setVertexGeometry(newGVerts); + addCosmeticVertexesToGeom(); +} + + //CosmeticEdges ------------------------------------------------------------------- //for completeness. not actually used anywhere? @@ -1605,6 +1450,15 @@ PyObject *DrawViewPart::getPyObject(void) return Py::new_reference_to(PythonObject); } +void DrawViewPart::handleChangedPropertyName(Base::XMLReader &reader, const char* TypeName, const char* PropName) +{ +// extHandleChangedPropertyName(reader, TypeName, PropName); // CosmeticExtension + DrawView::handleChangedPropertyName(reader, TypeName, PropName); +} + + + + // Python Drawing feature --------------------------------------------------------- namespace App { diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index e5b4ed7fa7..5a114006d7 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -41,6 +41,7 @@ #include "PropertyCenterLineList.h" #include "PropertyCosmeticEdgeList.h" #include "PropertyCosmeticVertexList.h" +#include "CosmeticExtension.h" #include "DrawView.h" class gp_Pnt; @@ -83,9 +84,9 @@ namespace TechDraw class DrawViewSection; -class TechDrawExport DrawViewPart : public DrawView +class TechDrawExport DrawViewPart : public DrawView, public CosmeticExtension { - PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawViewPart); + PROPERTY_HEADER_WITH_EXTENSIONS(TechDraw::DrawViewPart); public: DrawViewPart(void); @@ -110,7 +111,7 @@ public: App::PropertyBool IsoHidden; App::PropertyInteger IsoCount; - TechDraw::PropertyCosmeticVertexList CosmeticVertexes; +/* TechDraw::PropertyCosmeticVertexList CosmeticVertexes;*/ TechDraw::PropertyCosmeticEdgeList CosmeticEdges; TechDraw::PropertyCenterLineList CenterLines; TechDraw::PropertyGeomFormatList GeomFormats; @@ -173,22 +174,10 @@ public: bool isIso(void) const; - virtual int addCosmeticVertex(Base::Vector3d pos); - virtual int addCosmeticVertex(CosmeticVertex* cv); - std::string addCosmeticVertexSS(Base::Vector3d pos); - virtual void removeCosmeticVertex(TechDraw::CosmeticVertex* cv); - virtual void removeCosmeticVertex(int idx); - virtual void removeCosmeticVertex(std::string tagString); - virtual void removeCosmeticVertex(std::vector delTags); - - int getCosmeticVertexIndex(std::string tagString); - TechDraw::CosmeticVertex* getCosmeticVertex(std::string tagString) const; - TechDraw::CosmeticVertex* getCosmeticVertexByIndex(int idx) const; - TechDraw::CosmeticVertex* getCosmeticVertexByGeom(int idx) const; void clearCosmeticVertexes(void); + void refreshCVGeoms(void); void addCosmeticVertexesToGeom(void); void add1CosmeticVertexToGeom(int iCV); - int add1CVToGV(int iCV); int add1CVToGV(std::string tag); virtual int addCosmeticEdge(Base::Vector3d start, Base::Vector3d end); @@ -249,6 +238,9 @@ protected: TopoDS_Shape m_saveShape; //TODO: make this a Property. Part::TopoShapeProperty?? Base::Vector3d m_saveCentroid; //centroid before centering shape in origin + void handleChangedPropertyName(Base::XMLReader &reader, const char* TypeName, const char* PropName) override; + + private: bool nowUnsetting; diff --git a/src/Mod/TechDraw/App/DrawViewPartPy.xml b/src/Mod/TechDraw/App/DrawViewPartPy.xml index 3abc3c44f4..4b8d9cd656 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPy.xml +++ b/src/Mod/TechDraw/App/DrawViewPartPy.xml @@ -25,17 +25,32 @@ - makeCosmeticVertex(p1) - add a CosmeticVertex at p1 (View coordinates). Returns index of created vertex. + id = makeCosmeticVertex(p1) - add a CosmeticVertex at p1 (View coordinates). Returns unique id vertex. - + - getCosmeticVertexByIndex(idx) - returns CosmeticVertx[idx]. + id = makeCosmeticVertex3d(p1) - add a CosmeticVertex at p1 (3d model coordinates). Returns unique id vertex. + + + + + getCosmeticVertex(id) - returns CosmeticVertex with unique id. + + + + + getCosmeticVertexBySelection(name) - returns CosmeticVertex with name (Vertex6). Used in selections. + + + + + replaceCosmeticVertex(cv) - replaces CosmeticVertex in View. Returns True/False. - removeCosmeticVertex(idx) - remove CosmeticVertex[idx] from View. Returns None. + removeCosmeticVertex(cv) - remove CosmeticVertex from View. Returns None. diff --git a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp index 0f35ba67d6..cb0e1ad037 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp @@ -49,8 +49,8 @@ #include "DrawViewPart.h" #include "GeometryObject.h" #include "Cosmetic.h" +#include "CosmeticExtension.h" #include "DrawUtil.h" -#include "GeometryObject.h" // inclusion of the generated files (generated out of DrawViewPartPy.xml) #include @@ -59,6 +59,7 @@ #include #include + using namespace TechDraw; //TODO: errors to PyErrors @@ -102,6 +103,8 @@ PyObject* DrawViewPartPy::getHiddenEdges(PyObject *args) return pEdgeList; } +// remove all cosmetics + PyObject* DrawViewPartPy::clearCosmeticVertices(PyObject *args) { (void) args; @@ -138,7 +141,7 @@ PyObject* DrawViewPartPy::clearGeomFormats(PyObject *args) return Py_None; } - +//********* Cosmetic Vertex Routines ******************************************* PyObject* DrawViewPartPy::makeCosmeticVertex(PyObject *args) { PyObject* pPnt1 = nullptr; @@ -146,13 +149,144 @@ PyObject* DrawViewPartPy::makeCosmeticVertex(PyObject *args) throw Py::TypeError("expected (vector)"); } - DrawViewPart* item = getDrawViewPartPtr(); -// Base::Vector3d pnt1 = DrawUtil::invertY(static_cast(pPnt1)->value()); + DrawViewPart* dvp = getDrawViewPartPtr(); + std::string dvpName = dvp->getNameInDocument(); Base::Vector3d pnt1 = static_cast(pPnt1)->value(); - int idx = item->addCosmeticVertex(pnt1); - return PyLong_FromLong(idx); + std::string id = dvp->addCosmeticVertex(pnt1); + //int link = + dvp->add1CVToGV(id); + dvp->requestPaint(); + return PyUnicode_FromString(id.c_str()); //return tag for new CV } +PyObject* DrawViewPartPy::makeCosmeticVertex3d(PyObject *args) +{ + PyObject* pPnt1 = nullptr; + if (!PyArg_ParseTuple(args, "O!", &(Base::VectorPy::Type), &pPnt1)) { + throw Py::TypeError("expected (vector)"); + } + + DrawViewPart* dvp = getDrawViewPartPtr(); + Base::Vector3d pnt1 = static_cast(pPnt1)->value(); + Base::Vector3d centroid = dvp->getOriginalCentroid(); + pnt1 = pnt1 - centroid; + Base::Vector3d projected = DrawUtil::invertY(dvp->projectPoint(pnt1)); + + std::string id = dvp->addCosmeticVertex(projected); + //int link = + dvp->add1CVToGV(id); + dvp->refreshCVGeoms(); + dvp->requestPaint(); + return PyUnicode_FromString(id.c_str()); //return tag for new CV +} + +//get by unique tag +PyObject* DrawViewPartPy::getCosmeticVertex(PyObject *args) +{ +// Base::Console().Message("DVPP::getCosmeticVertex()\n"); + PyObject* result = nullptr; + char* id; //unique tag + if (!PyArg_ParseTuple(args, "s", &id)) { + throw Py::TypeError("expected (string)"); + } + DrawViewPart* dvp = getDrawViewPartPtr(); + TechDraw::CosmeticVertex* cv = dvp->getCosmeticVertex(id); + if (cv != nullptr) { + result = cv->getPyObject(); + } else { + result = Py_None; + } + return result; +} + +//get by selection name +PyObject* DrawViewPartPy::getCosmeticVertexBySelection(PyObject *args) +{ +// Base::Console().Message("DVPP::getCosmeticVertexBySelection()\n"); + PyObject* result = nullptr; + char* selName; //Selection routine name - "Vertex0" + if (!PyArg_ParseTuple(args, "s", &selName)) { + throw Py::TypeError("expected (string)"); + } + DrawViewPart* dvp = getDrawViewPartPtr(); + + TechDraw::CosmeticVertex* cv = dvp->getCosmeticVertexBySelection(selName); + if (cv != nullptr) { + result = cv->getPyObject(); + } else { + result = Py_None; + } + return result; +} + +PyObject* DrawViewPartPy::removeCosmeticVertex(PyObject *args) +{ +// Base::Console().Message("DVPP::removeCosmeticVertex()\n"); + DrawViewPart* dvp = getDrawViewPartPtr(); + if (dvp == nullptr) { + return Py_None; + } + + char* tag; + if (PyArg_ParseTuple(args, "s", &tag)) { + dvp->removeCosmeticVertex(tag); + dvp->refreshCVGeoms(); + dvp->requestPaint(); + return Py_None; + } + + PyObject* pCVToDelete = nullptr; + if (PyArg_ParseTuple(args, "O!", &(TechDraw::CosmeticVertexPy::Type), &pCVToDelete)) { + TechDraw::CosmeticVertexPy* cvPy = static_cast(pCVToDelete); + TechDraw::CosmeticVertex* cv = cvPy->getCosmeticVertexPtr(); + dvp->removeCosmeticVertex(cv->getTagAsString()); + dvp->refreshCVGeoms(); + dvp->requestPaint(); + return Py_None; + } + + PyObject* pDelList = nullptr; + if (PyArg_ParseTuple(args, "O", &pDelList)) { + if (PySequence_Check(pDelList)) { + Py_ssize_t nSize = PySequence_Size(pDelList); + for (Py_ssize_t i=0; i < nSize; i++) { + PyObject* item = PySequence_GetItem(pDelList, i); + if (!PyObject_TypeCheck(item, &(TechDraw::CosmeticVertexPy::Type))) { + std::string error = std::string("types in list must be 'CosmeticVertex', not "); + error += item->ob_type->tp_name; + throw Base::TypeError(error); + } + TechDraw::CosmeticVertexPy* cvPy = static_cast(item); + TechDraw::CosmeticVertex* cv = cvPy->getCosmeticVertexPtr(); + dvp->removeCosmeticVertex(cv->getTagAsString()); + } + dvp->refreshCVGeoms(); + dvp->requestPaint(); + } + } else { + throw Py::TypeError("expected (CosmeticVertex or [CosmeticVertex])"); + } + return Py_None; +} + +PyObject* DrawViewPartPy::replaceCosmeticVertex(PyObject *args) +{ + PyObject* pNewCV = nullptr; + if (!PyArg_ParseTuple(args, "O!", &(TechDraw::CosmeticVertexPy::Type), &pNewCV)) { + throw Py::TypeError("expected (CosmeticVertex)"); + } + DrawViewPart* dvp = getDrawViewPartPtr(); + TechDraw::CosmeticVertexPy* cvPy = static_cast(pNewCV); + TechDraw::CosmeticVertex* cv = cvPy->getCosmeticVertexPtr(); + bool result = dvp->replaceCosmeticVertex(cv); + dvp->refreshCVGeoms(); + dvp->requestPaint(); + return PyBool_FromLong((long) result); +} + + +//********* Cosmetic Line Routines ********************************************* + PyObject* DrawViewPartPy::makeCosmeticLine(PyObject *args) { PyObject* pPnt1 = nullptr; @@ -290,34 +424,23 @@ PyObject* DrawViewPartPy::makeCosmeticCircleArc(PyObject *args) return PyLong_FromLong(idx); } -PyObject* DrawViewPartPy::getCosmeticVertexByIndex(PyObject *args) -{ - PyObject* result = nullptr; - int idx = -1; - if (!PyArg_ParseTuple(args, "i", &idx)) { - throw Py::TypeError("expected (index)"); - } - DrawViewPart* dvp = getDrawViewPartPtr(); - TechDraw::CosmeticVertex* cv = dvp->getCosmeticVertexByIndex(idx); - if (cv != nullptr) { - result = new CosmeticVertexPy(new CosmeticVertex(cv)); - } else { - result = Py_None; - } - return result; -} +//PyObject* DrawViewPartPy::getCosmeticVertexByIndex(PyObject *args) +//{ +// PyObject* result = nullptr; +// int idx = -1; +// if (!PyArg_ParseTuple(args, "i", &idx)) { +// throw Py::TypeError("expected (index)"); +// } +// DrawViewPart* dvp = getDrawViewPartPtr(); +// TechDraw::CosmeticVertex* cv = dvp->getCosmeticVertexByIndex(idx); +// if (cv != nullptr) { +// result = new CosmeticVertexPy(new CosmeticVertex(cv)); +// } else { +// result = Py_None; +// } +// return result; +//} -PyObject* DrawViewPartPy::removeCosmeticVertex(PyObject *args) -{ - int idx = 0; - if (!PyArg_ParseTuple(args, "i", &idx)) { - throw Py::TypeError("expected (index)"); - } - DrawViewPart* dvp = getDrawViewPartPtr(); - dvp->removeCosmeticVertex(idx); - Py_INCREF(Py_None); - return Py_None; -} PyObject* DrawViewPartPy::getCosmeticEdgeByIndex(PyObject *args) { diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 1ff6f2697b..008365120e 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -572,6 +572,24 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca } //end TopExp } +//adds a new GeomVert surrogate for CV +//returns GeomVert selection index ("Vertex3") +// insertGeomForCV(cv) +int GeometryObject::addCosmeticVertex(CosmeticVertex* cv) +{ +// Base::Console().Message("GO::addCosmeticVertex(%X)\n", cv); + double scale = m_parent->getScale(); + Base::Vector3d pos = cv->scaled(scale); + TechDraw::Vertex* v = new TechDraw::Vertex(pos.x, pos.y); + v->cosmetic = true; + v->cosmeticLink = -1; //obs?? + v->cosmeticTag = cv->getTagAsString(); + v->hlrVisible = true; + int idx = vertexGeom.size(); + vertexGeom.push_back(v); + return idx; +} + //adds a new GeomVert to list for cv[link] int GeometryObject::addCosmeticVertex(Base::Vector3d pos, int link) { @@ -599,6 +617,8 @@ int GeometryObject::addCosmeticVertex(Base::Vector3d pos, std::string tagString, return idx; } +//================================================================================ + //do not need source index anymore. base has CosmeticTag int GeometryObject::addCosmeticEdge(TechDraw::BaseGeom* base, int s) diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h index d67db14632..aeb996af45 100644 --- a/src/Mod/TechDraw/App/GeometryObject.h +++ b/src/Mod/TechDraw/App/GeometryObject.h @@ -108,6 +108,8 @@ public: const std::vector & getEdgeGeometry() const { return edgeGeom; } const std::vector getVisibleFaceEdges(bool smooth, bool seam) const; const std::vector & getFaceGeometry() const { return faceGeom; } + + void setVertexGeometry(std::vector newVerts) {vertexGeom = newVerts; } void projectShape(const TopoDS_Shape &input, const gp_Ax2 viewAxis); @@ -142,8 +144,9 @@ public: TopoDS_Shape getHidIso(void) { return hidIso; } //Are removeXXXXX functions really needed for GO? - int addCosmeticVertex(Base::Vector3d pos, int link = -1); - int addCosmeticVertex(Base::Vector3d pos, std::string tagString, int link = -1); + int addCosmeticVertex(CosmeticVertex* cv); + int addCosmeticVertex(Base::Vector3d pos, int link = -1); //obs? + int addCosmeticVertex(Base::Vector3d pos, std::string tagString, int link = -1); //obs?? int addCosmeticEdge(TechDraw::BaseGeom* bg, int s = 0); int addCenterLine(TechDraw::BaseGeom* bg, int s = 0, int si = -1); diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp index 087d8eaf74..10b6d3893b 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -62,6 +62,8 @@ #include "ViewProviderTile.h" #include "ViewProviderWeld.h" +#include "ViewProviderCosmeticExtension.h" + // use a different name to CreateCommand() void CreateTechDrawCommands(void); @@ -141,6 +143,8 @@ PyMOD_INIT_FUNC(TechDrawGui) TechDrawGui::ViewProviderTile::init(); TechDrawGui::ViewProviderWeld::init(); + TechDrawGui::ViewProviderCosmeticExtension::init(); + // register preferences pages new Gui::PrefPageProducer ("TechDraw"); new Gui::PrefPageProducer ("TechDraw"); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index b0bbc28465..64e41cfb17 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -328,6 +328,8 @@ SET(TechDrawGuiViewProvider_SRCS ViewProviderTile.h ViewProviderWeld.cpp ViewProviderWeld.h + ViewProviderCosmeticExtension.cpp + ViewProviderCosmeticExtension.h ) SOURCE_GROUP("MRTE" FILES ${MRTE_SRCS}) diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 1ac77a5b45..2a94536140 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -662,7 +662,8 @@ void QGIViewPart::drawViewPart() } else { //regular Vertex if (showVertices) { QGIVertex *item = new QGIVertex(i); - TechDraw::CosmeticVertex* cv = viewPart->getCosmeticVertexByGeom(i); + TechDraw::CosmeticVertex* cv = viewPart->getCosmeticVertexBySelection(i); +// TechDraw::CosmeticVertex* cv = viewPart->getCosmeticVertexByGeom(i); if (cv != nullptr) { item->setNormalColor(cv->color.asValue()); item->setRadius(cv->size); diff --git a/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp b/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp new file mode 100644 index 0000000000..ee9a727986 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * 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_ +# ifdef _MSC_VER +# define _USE_MATH_DEFINES +# include +# endif //_MSC_VER +#endif + +#include + +#include "ViewProviderCosmeticExtension.h" +#include + +#include + +using namespace TechDrawGui; + +EXTENSION_PROPERTY_SOURCE(TechDrawGui::ViewProviderCosmeticExtension, Gui::ViewProviderExtension) + + +ViewProviderCosmeticExtension::ViewProviderCosmeticExtension() +{ + initExtensionType(ViewProviderCosmeticExtension::getExtensionClassTypeId()); +} + +QIcon ViewProviderCosmeticExtension::extensionMergeOverlayIcons(const QIcon & orig) const +{ + QIcon mergedicon = orig; + + return mergedicon; +} + +void ViewProviderCosmeticExtension::extensionUpdateData(const App::Property* prop) +{ + Gui::ViewProviderExtension::extensionUpdateData(prop); +} + +namespace Gui { + EXTENSION_PROPERTY_SOURCE_TEMPLATE(TechDrawGui::ViewProviderCosmeticExtensionPython, TechDrawGui::ViewProviderCosmeticExtension) + +// explicit template instantiation + template class TechDrawGuiExport ViewProviderExtensionPythonT; +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.h b/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.h new file mode 100644 index 0000000000..fe9bb30947 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * 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 GUI_VIEWPROVIDERCOSMETICEXTENSION_H +#define GUI_VIEWPROVIDERCOSMETICEXTENSION_H + +#include +#include + +namespace TechDrawGui +{ + +class TechDrawGuiExport ViewProviderCosmeticExtension : public Gui::ViewProviderExtension +{ + EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(TechDrawGui::ViewProviderCosmeticExtension); + +public: + /// Constructor + ViewProviderCosmeticExtension(void); + virtual ~ViewProviderCosmeticExtension() = default; + + virtual QIcon extensionMergeOverlayIcons(const QIcon & orig) const override; + + virtual void extensionUpdateData(const App::Property*) override; + +}; + +typedef Gui::ViewProviderExtensionPythonT ViewProviderCosmeticExtensionPython; + +} //namespace TechDrawGui + +#endif // GUI_VIEWPROVIDERCOSMETICEXTENSION_H