diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index 903793b990..90abbcb2f0 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -318,11 +318,14 @@ CosmeticVertex* CosmeticVertex::clone(void) const PyObject* CosmeticVertex::getPyObject(void) { -// return new CosmeticVertexPy(new CosmeticVertex(this->copy())); //shouldn't this be clone? - PyObject* result = new CosmeticVertexPy(this->clone()); - return result; + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new CosmeticVertexPy(this),true); + } + return Py::new_reference_to(PythonObject); } + void CosmeticVertex::dump(const char* title) { Base::Console().Message("CV::dump - %s \n",title); @@ -403,12 +406,13 @@ void CosmeticEdge::initialize(void) m_geometry->setCosmeticTag(getTagAsString()); } -void CosmeticEdge::unscaleEnds(double scale) -{ - permaStart = permaStart / scale; - permaEnd = permaEnd / scale; - permaRadius = permaRadius / scale; -} +//why is this needed? isn't permaxxxx always unscaled?? +//void CosmeticEdge::unscaleEnds(double scale) +//{ +// permaStart = permaStart / scale; +// permaEnd = permaEnd / scale; +// permaRadius = permaRadius / scale; +//} TechDraw::BaseGeom* CosmeticEdge::scaledGeometry(double scale) { @@ -567,9 +571,14 @@ CosmeticEdge* CosmeticEdge::clone(void) const PyObject* CosmeticEdge::getPyObject(void) { - return new CosmeticEdgePy(this->clone()); + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new CosmeticEdgePy(this),true); + } + return Py::new_reference_to(PythonObject); } + //********************************************************* TYPESYSTEM_SOURCE(TechDraw::CenterLine,Base::Persistence) @@ -1419,9 +1428,14 @@ CenterLine *CenterLine::clone(void) const PyObject* CenterLine::getPyObject(void) { - return new CenterLinePy(this->clone()); + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new CenterLinePy(this),true); + } + return Py::new_reference_to(PythonObject); } + void CenterLine::setShifts(double h, double v) { m_hShift = h; @@ -1615,7 +1629,11 @@ GeomFormat* GeomFormat::copy(void) const PyObject* GeomFormat::getPyObject(void) { - return new GeomFormatPy(new GeomFormat(this->copy())); + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new GeomFormatPy(this),true); + } + return Py::new_reference_to(PythonObject); } bool CosmeticVertex::restoreCosmetic(void) diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index 961e753c54..91cbf02a25 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -113,6 +113,9 @@ protected: boost::uuids::uuid tag; + Py::Object PythonObject; + + }; //********** CosmeticEdge ****************************************************** @@ -147,7 +150,7 @@ public: Base::Vector3d permaStart; //persistent unscaled start/end points in View coords? Base::Vector3d permaEnd; double permaRadius; - void unscaleEnds(double scale); +// void unscaleEnds(double scale); TechDraw::BaseGeom* m_geometry; LineFormat m_format; @@ -158,8 +161,10 @@ protected: //Uniqueness void createNewTag(); void assignTag(const TechDraw::CosmeticEdge* ce); - boost::uuids::uuid tag; + + Py::Object PythonObject; + }; //***** CenterLine ************************************************************* @@ -269,6 +274,8 @@ protected: boost::uuids::uuid tag; + Py::Object PythonObject; + }; //********** GeomFormat ******************************************************** @@ -310,6 +317,7 @@ protected: void assignTag(const TechDraw::GeomFormat* gf); boost::uuids::uuid tag; + Py::Object PythonObject; }; } //end namespace TechDraw diff --git a/src/Mod/TechDraw/App/CosmeticExtension.cpp b/src/Mod/TechDraw/App/CosmeticExtension.cpp index a59863ddbe..be67d20dff 100644 --- a/src/Mod/TechDraw/App/CosmeticExtension.cpp +++ b/src/Mod/TechDraw/App/CosmeticExtension.cpp @@ -282,7 +282,9 @@ bool CosmeticExtension::replaceCosmeticEdge(CosmeticEdge* newCE) std::vector newEdges; std::string tag = newCE->getTagAsString(); for (auto& ce: cEdges) { - if (ce->getTagAsString() == tag) { + Base::Console().Message("CX::replaceCosmeticEdge - newCE: %X/%s matching: %X/xxx \n", + newCE, tag.c_str(), ce); + if (ce->getTagAsString() == tag) { //<<<< newEdges.push_back(newCE); result = true; } else { diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 74fd8d0629..17697d65af 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -1168,6 +1168,7 @@ void DrawViewPart::resetReferenceVerts() //******** //* Cosmetics //******** + void DrawViewPart::clearCosmeticVertexes(void) { std::vector noVerts; @@ -1263,7 +1264,7 @@ void DrawViewPart::clearCosmeticEdges(void) //add the cosmetic edges to geometry edge list void DrawViewPart::addCosmeticEdgesToGeom(void) { -// Base::Console().Message("CEx::addCosmeticEdgesToGeom()\n"); + Base::Console().Message("CEx::addCosmeticEdgesToGeom()\n"); const std::vector cEdges = CosmeticEdges.getValues(); for (auto& ce: cEdges) { TechDraw::BaseGeom* scaledGeom = ce->scaledGeometry(getScale()); @@ -1294,7 +1295,7 @@ int DrawViewPart::add1CEToGE(std::string tag) //update Edge geometry with current CE's void DrawViewPart::refreshCEGeoms(void) { -// Base::Console().Message("DVP::refreshCEGeoms()\n"); + Base::Console().Message("DVP::refreshCEGeoms()\n"); std::vector gEdges = getEdgeGeometry(); std::vector oldGEdges; for (auto& ge :gEdges) { diff --git a/src/Mod/TechDraw/App/DrawViewPartPy.xml b/src/Mod/TechDraw/App/DrawViewPartPy.xml index fcf6bf9bf1..1e08c465d7 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPy.xml +++ b/src/Mod/TechDraw/App/DrawViewPartPy.xml @@ -148,6 +148,11 @@ getVertexByIndex(vertexIndex). Returns Part.TopoShape. + + + requestPaint(). Redraw the graphic for this View. + + diff --git a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp index a25f510514..69e49b8145 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp @@ -105,8 +105,16 @@ PyObject* DrawViewPartPy::getHiddenEdges(PyObject *args) return pEdgeList; } -// remove all cosmetics +PyObject* DrawViewPartPy::requestPaint(PyObject *args) +{ + (void) args; + DrawViewPart* item = getDrawViewPartPtr(); + item->requestPaint(); + Py_INCREF(Py_None); + return Py_None; +} +// remove all cosmetics PyObject* DrawViewPartPy::clearCosmeticVertices(PyObject *args) { (void) args; @@ -457,8 +465,8 @@ PyObject* DrawViewPartPy::getCosmeticEdge(PyObject *args) TechDraw::CosmeticEdge* ce = dvp->getCosmeticEdge(tag); if (ce != nullptr) { // result = new CosmeticEdgePy(new CosmeticEdge(ce)); - result = new CosmeticEdgePy(ce->clone()); -// result = ce->getPyObject(); +// result = new CosmeticEdgePy(ce->clone()); + result = ce->getPyObject(); } else { Base::Console().Error("DVPPI::getCosmeticEdge - edge %s not found\n", tag); } @@ -478,8 +486,8 @@ PyObject* DrawViewPartPy::getCosmeticEdgeBySelection(PyObject *args) TechDraw::CosmeticEdge* ce = dvp->getCosmeticEdgeBySelection(name); if (ce != nullptr) { -// result = ce->getPyObject(); - result = new CosmeticEdgePy(ce->clone()); + result = ce->getPyObject(); +// result = new CosmeticEdgePy(ce->clone()); } else { Base::Console().Error("DVPPI::getCosmeticEdgebySelection - edge for name %s not found\n", name); } @@ -489,6 +497,7 @@ PyObject* DrawViewPartPy::getCosmeticEdgeBySelection(PyObject *args) PyObject* DrawViewPartPy::replaceCosmeticEdge(PyObject *args) { // Base::Console().Message("DVPPI::replaceCosmeticEdge()\n"); + bool result = false; PyObject* pNewCE; if (!PyArg_ParseTuple(args, "O!", &(TechDraw::CosmeticEdgePy::Type), &pNewCE)) { throw Py::TypeError("expected (CosmeticEdge)"); @@ -496,9 +505,11 @@ PyObject* DrawViewPartPy::replaceCosmeticEdge(PyObject *args) DrawViewPart* dvp = getDrawViewPartPtr(); TechDraw::CosmeticEdgePy* cePy = static_cast(pNewCE); TechDraw::CosmeticEdge* ce = cePy->getCosmeticEdgePtr(); - bool result = dvp->replaceCosmeticEdge(ce); - dvp->refreshCEGeoms(); - dvp->requestPaint(); + if (ce != nullptr) { + result = dvp->replaceCosmeticEdge(ce); //<<< + dvp->refreshCEGeoms(); + dvp->requestPaint(); + } return PyBool_FromLong((long) result); } diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 2180d9be7f..63f2573e6f 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -636,7 +636,7 @@ int GeometryObject::addCosmeticVertex(Base::Vector3d pos, std::string tagString) // insertGeomForCE(ce) int GeometryObject::addCosmeticEdge(CosmeticEdge* ce) { - Base::Console().Message("GO::addCosmeticEdge(%X)\n", ce); + Base::Console().Message("GO::addCosmeticEdge(%X) 0\n", ce); double scale = m_parent->getScale(); TechDraw::BaseGeom* e = ce->scaledGeometry(scale); e->cosmetic = true; @@ -687,6 +687,7 @@ int GeometryObject::addCosmeticEdge(Base::Vector3d start, int GeometryObject::addCosmeticEdge(TechDraw::BaseGeom* base, std::string tagString) { + Base::Console().Message("GO::addCosmeticEdge(%X, %s) 3\n", base, tagString.c_str()); base->cosmetic = true; base->hlrVisible = true; base->source(1); //1-CosmeticEdge, 2-CenterLine diff --git a/src/Mod/TechDraw/App/PropertyCenterLineList.cpp b/src/Mod/TechDraw/App/PropertyCenterLineList.cpp index fbe6f29d3b..1439ebb718 100644 --- a/src/Mod/TechDraw/App/PropertyCenterLineList.cpp +++ b/src/Mod/TechDraw/App/PropertyCenterLineList.cpp @@ -63,14 +63,12 @@ PropertyCenterLineList::PropertyCenterLineList() PropertyCenterLineList::~PropertyCenterLineList() { - for (std::vector::iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) - if (*it) delete *it; } void PropertyCenterLineList::setSize(int newSize) { - for (unsigned int i = newSize; i < _lValueList.size(); i++) - delete _lValueList[i]; +// for (unsigned int i = newSize; i < _lValueList.size(); i++) +// delete _lValueList[i]; _lValueList.resize(newSize); } @@ -79,15 +77,12 @@ int PropertyCenterLineList::getSize(void) const return static_cast(_lValueList.size()); } -void PropertyCenterLineList::setValue(const CenterLine* lValue) +void PropertyCenterLineList::setValue(CenterLine* lValue) { if (lValue) { aboutToSetValue(); - CenterLine* newVal = lValue->clone(); - for (unsigned int i = 0; i < _lValueList.size(); i++) - delete _lValueList[i]; _lValueList.resize(1); - _lValueList[0] = newVal; + _lValueList[0] = lValue; hasSetValue(); } } @@ -95,13 +90,9 @@ void PropertyCenterLineList::setValue(const CenterLine* lValue) void PropertyCenterLineList::setValues(const std::vector& lValue) { aboutToSetValue(); - std::vector oldVals(_lValueList); _lValueList.resize(lValue.size()); - // copy all objects for (unsigned int i = 0; i < lValue.size(); i++) - _lValueList[i] = lValue[i]->clone(); - for (unsigned int i = 0; i < oldVals.size(); i++) - delete oldVals[i]; + _lValueList[i] = lValue[i]; hasSetValue(); } @@ -115,9 +106,6 @@ PyObject *PropertyCenterLineList::getPyObject(void) void PropertyCenterLineList::setPyObject(PyObject *value) { - // check container of this property to notify about changes -// Part2DObject* part2d = dynamic_cast(this->getContainer()); - if (PySequence_Check(value)) { Py_ssize_t nSize = PySequence_Size(value); std::vector values; @@ -135,8 +123,6 @@ void PropertyCenterLineList::setPyObject(PyObject *value) } setValues(values); -// if (part2d) -// part2d->acceptCenterLine(); } else if (PyObject_TypeCheck(value, &(CenterLinePy::Type))) { CenterLinePy *pcObject = static_cast(value); @@ -153,7 +139,7 @@ void PropertyCenterLineList::Save(Writer &writer) const { writer.Stream() << writer.ind() << "" << endl; writer.incInd(); - for (int i = 0; i < getSize(); i++) { + for (int i = 0; i < getSize(); i++) { writer.Stream() << writer.ind() << "getTypeId().getName() << "\">" << endl; writer.incInd(); diff --git a/src/Mod/TechDraw/App/PropertyCenterLineList.h b/src/Mod/TechDraw/App/PropertyCenterLineList.h index d42bb0bec7..a4ce6ef034 100644 --- a/src/Mod/TechDraw/App/PropertyCenterLineList.h +++ b/src/Mod/TechDraw/App/PropertyCenterLineList.h @@ -47,16 +47,7 @@ class TechDrawExport PropertyCenterLineList: public App::PropertyLists TYPESYSTEM_HEADER(); public: - /** - * A constructor. - * A more elaborate description of the constructor. - */ PropertyCenterLineList(); - - /** - * A destructor. - * A more elaborate description of the destructor. - */ virtual ~PropertyCenterLineList(); virtual void setSize(int newSize); @@ -64,7 +55,7 @@ public: /** Sets the property */ - void setValue(const CenterLine*); + void setValue(CenterLine*); void setValues(const std::vector&); /// index operator diff --git a/src/Mod/TechDraw/App/PropertyCosmeticEdgeList.cpp b/src/Mod/TechDraw/App/PropertyCosmeticEdgeList.cpp index b1bd9d22c1..8cd243f2ea 100644 --- a/src/Mod/TechDraw/App/PropertyCosmeticEdgeList.cpp +++ b/src/Mod/TechDraw/App/PropertyCosmeticEdgeList.cpp @@ -63,14 +63,12 @@ PropertyCosmeticEdgeList::PropertyCosmeticEdgeList() PropertyCosmeticEdgeList::~PropertyCosmeticEdgeList() { - for (std::vector::iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) - if (*it) delete *it; } void PropertyCosmeticEdgeList::setSize(int newSize) { - for (unsigned int i = newSize; i < _lValueList.size(); i++) - delete _lValueList[i]; +// for (unsigned int i = newSize; i < _lValueList.size(); i++) +// delete _lValueList[i]; _lValueList.resize(newSize); } @@ -79,15 +77,14 @@ int PropertyCosmeticEdgeList::getSize(void) const return static_cast(_lValueList.size()); } -void PropertyCosmeticEdgeList::setValue(const CosmeticEdge* lValue) + +//_lValueList is not const. so why do we pass a const paramter? +void PropertyCosmeticEdgeList::setValue(CosmeticEdge* lValue) { if (lValue) { aboutToSetValue(); - CosmeticEdge* newVal = lValue->clone(); - for (unsigned int i = 0; i < _lValueList.size(); i++) - delete _lValueList[i]; _lValueList.resize(1); - _lValueList[0] = newVal; + _lValueList[0] = lValue; hasSetValue(); } } @@ -95,13 +92,9 @@ void PropertyCosmeticEdgeList::setValue(const CosmeticEdge* lValue) void PropertyCosmeticEdgeList::setValues(const std::vector& lValue) { aboutToSetValue(); - std::vector oldVals(_lValueList); _lValueList.resize(lValue.size()); - // copy all objects for (unsigned int i = 0; i < lValue.size(); i++) - _lValueList[i] = lValue[i]->clone(); - for (unsigned int i = 0; i < oldVals.size(); i++) - delete oldVals[i]; + _lValueList[i] = lValue[i]; hasSetValue(); } @@ -115,8 +108,6 @@ PyObject *PropertyCosmeticEdgeList::getPyObject(void) void PropertyCosmeticEdgeList::setPyObject(PyObject *value) { - // check container of this property to notify about changes - if (PySequence_Check(value)) { Py_ssize_t nSize = PySequence_Size(value); std::vector values; diff --git a/src/Mod/TechDraw/App/PropertyCosmeticEdgeList.h b/src/Mod/TechDraw/App/PropertyCosmeticEdgeList.h index 4b36524d3c..df1c07179c 100644 --- a/src/Mod/TechDraw/App/PropertyCosmeticEdgeList.h +++ b/src/Mod/TechDraw/App/PropertyCosmeticEdgeList.h @@ -64,7 +64,8 @@ public: /** Sets the property */ - void setValue(const CosmeticEdge*); +/* void setValue(const CosmeticEdge*);*/ + void setValue(CosmeticEdge*); void setValues(const std::vector&); /// index operator diff --git a/src/Mod/TechDraw/App/PropertyCosmeticVertexList.cpp b/src/Mod/TechDraw/App/PropertyCosmeticVertexList.cpp index bb0bf12335..21176b2ad3 100644 --- a/src/Mod/TechDraw/App/PropertyCosmeticVertexList.cpp +++ b/src/Mod/TechDraw/App/PropertyCosmeticVertexList.cpp @@ -63,8 +63,6 @@ PropertyCosmeticVertexList::PropertyCosmeticVertexList() PropertyCosmeticVertexList::~PropertyCosmeticVertexList() { - for (std::vector::iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) - if (*it) delete *it; } void PropertyCosmeticVertexList::setSize(int newSize) @@ -79,15 +77,12 @@ int PropertyCosmeticVertexList::getSize(void) const return static_cast(_lValueList.size()); } -void PropertyCosmeticVertexList::setValue(const CosmeticVertex* lValue) +void PropertyCosmeticVertexList::setValue(CosmeticVertex* lValue) { if (lValue) { aboutToSetValue(); - CosmeticVertex* newVal = lValue->clone(); - for (unsigned int i = 0; i < _lValueList.size(); i++) - delete _lValueList[i]; _lValueList.resize(1); - _lValueList[0] = newVal; + _lValueList[0] = lValue; hasSetValue(); } } @@ -95,13 +90,9 @@ void PropertyCosmeticVertexList::setValue(const CosmeticVertex* lValue) void PropertyCosmeticVertexList::setValues(const std::vector& lValue) { aboutToSetValue(); - std::vector oldVals(_lValueList); _lValueList.resize(lValue.size()); - // copy all objects for (unsigned int i = 0; i < lValue.size(); i++) - _lValueList[i] = lValue[i]->clone(); - for (unsigned int i = 0; i < oldVals.size(); i++) - delete oldVals[i]; + _lValueList[i] = lValue[i]; hasSetValue(); } @@ -134,8 +125,6 @@ void PropertyCosmeticVertexList::setPyObject(PyObject *value) } setValues(values); -// if (part2d) -// part2d->acceptCosmeticVertex(); } else if (PyObject_TypeCheck(value, &(CosmeticVertexPy::Type))) { CosmeticVertexPy *pcObject = static_cast(value); diff --git a/src/Mod/TechDraw/App/PropertyCosmeticVertexList.h b/src/Mod/TechDraw/App/PropertyCosmeticVertexList.h index 6cb2e95922..58ee06a692 100644 --- a/src/Mod/TechDraw/App/PropertyCosmeticVertexList.h +++ b/src/Mod/TechDraw/App/PropertyCosmeticVertexList.h @@ -64,7 +64,7 @@ public: /** Sets the property */ - void setValue(const CosmeticVertex*); + void setValue(CosmeticVertex*); void setValues(const std::vector&); /// index operator