[TD]Simplify Cosmetic List & PyObject handling

This commit is contained in:
wandererfan
2020-05-11 15:30:29 -04:00
committed by WandererFan
parent 31bb4d84b9
commit 1533ea01ba
13 changed files with 92 additions and 88 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -282,7 +282,9 @@ bool CosmeticExtension::replaceCosmeticEdge(CosmeticEdge* newCE)
std::vector<CosmeticEdge*> 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 {

View File

@@ -1168,6 +1168,7 @@ void DrawViewPart::resetReferenceVerts()
//********
//* Cosmetics
//********
void DrawViewPart::clearCosmeticVertexes(void)
{
std::vector<CosmeticVertex*> 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<TechDraw::CosmeticEdge*> 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<TechDraw::BaseGeom *> gEdges = getEdgeGeometry();
std::vector<TechDraw::BaseGeom *> oldGEdges;
for (auto& ge :gEdges) {

View File

@@ -148,6 +148,11 @@
<UserDocu>getVertexByIndex(vertexIndex). Returns Part.TopoShape.</UserDocu>
</Documentation>
</Methode>
<Methode Name="requestPaint">
<Documentation>
<UserDocu>requestPaint(). Redraw the graphic for this View.</UserDocu>
</Documentation>
</Methode>
<CustomAttributes />
</PythonExport>
</GenerateModel>

View File

@@ -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<TechDraw::CosmeticEdgePy*>(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);
}

View File

@@ -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

View File

@@ -63,14 +63,12 @@ PropertyCenterLineList::PropertyCenterLineList()
PropertyCenterLineList::~PropertyCenterLineList()
{
for (std::vector<CenterLine*>::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<int>(_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<CenterLine*>& lValue)
{
aboutToSetValue();
std::vector<CenterLine*> 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<Part2DObject*>(this->getContainer());
if (PySequence_Check(value)) {
Py_ssize_t nSize = PySequence_Size(value);
std::vector<CenterLine*> 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<CenterLinePy*>(value);
@@ -153,7 +139,7 @@ void PropertyCenterLineList::Save(Writer &writer) const
{
writer.Stream() << writer.ind() << "<CenterLineList count=\"" << getSize() <<"\">" << endl;
writer.incInd();
for (int i = 0; i < getSize(); i++) {
for (int i = 0; i < getSize(); i++) {
writer.Stream() << writer.ind() << "<CenterLine type=\""
<< _lValueList[i]->getTypeId().getName() << "\">" << endl;
writer.incInd();

View File

@@ -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<CenterLine*>&);
/// index operator

View File

@@ -63,14 +63,12 @@ PropertyCosmeticEdgeList::PropertyCosmeticEdgeList()
PropertyCosmeticEdgeList::~PropertyCosmeticEdgeList()
{
for (std::vector<CosmeticEdge*>::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<int>(_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<CosmeticEdge*>& lValue)
{
aboutToSetValue();
std::vector<CosmeticEdge*> 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<CosmeticEdge*> values;

View File

@@ -64,7 +64,8 @@ public:
/** Sets the property
*/
void setValue(const CosmeticEdge*);
/* void setValue(const CosmeticEdge*);*/
void setValue(CosmeticEdge*);
void setValues(const std::vector<CosmeticEdge*>&);
/// index operator

View File

@@ -63,8 +63,6 @@ PropertyCosmeticVertexList::PropertyCosmeticVertexList()
PropertyCosmeticVertexList::~PropertyCosmeticVertexList()
{
for (std::vector<CosmeticVertex*>::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<int>(_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<CosmeticVertex*>& lValue)
{
aboutToSetValue();
std::vector<CosmeticVertex*> 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<CosmeticVertexPy*>(value);

View File

@@ -64,7 +64,7 @@ public:
/** Sets the property
*/
void setValue(const CosmeticVertex*);
void setValue(CosmeticVertex*);
void setValues(const std::vector<CosmeticVertex*>&);
/// index operator