[TD]Python routines and extension for line formating

This commit is contained in:
wandererfan
2019-12-11 16:13:26 -05:00
committed by WandererFan
parent 08f23b84f7
commit 1ad2d35bce
11 changed files with 143 additions and 91 deletions

View File

@@ -1534,6 +1534,12 @@ boost::uuids::uuid GeomFormat::getTag() const
return tag;
}
std::string GeomFormat::getTagAsString(void) const
{
std::string tmp = boost::uuids::to_string(getTag());
return tmp;
}
void GeomFormat::createNewTag()
{
// Initialize a random number generator, to avoid Valgrind false positives.

View File

@@ -236,6 +236,8 @@ public:
Base::Vector3d m_start;
Base::Vector3d m_end;
//required to recalculate CL after source geom changes.
std::vector<std::string> m_faces;
std::vector<std::string> m_edges;
std::vector<std::string> m_verts;
@@ -296,6 +298,8 @@ public:
//Uniqueness
boost::uuids::uuid getTag() const;
virtual std::string getTagAsString(void) const;
protected:
void createNewTag();
void assignTag(const TechDraw::GeomFormat* gf);

View File

@@ -47,7 +47,9 @@ CosmeticExtension::CosmeticExtension()
{
static const char *cgroup = "Cosmetics";
EXTENSION_ADD_PROPERTY_TYPE(CosmeticVertexes ,(0),cgroup,App::Prop_Output,"CosmeticVertex Save/Restore");
EXTENSION_ADD_PROPERTY_TYPE(CosmeticVertexes, (0), cgroup, App::Prop_Output, "CosmeticVertex Save/Restore");
EXTENSION_ADD_PROPERTY_TYPE(CosmeticEdges, (0), cgroup, App::Prop_Output, "CosmeticEdge Save/Restore");
EXTENSION_ADD_PROPERTY_TYPE(GeomFormats ,(0),cgroup,App::Prop_Output,"Geometry format Save/Restore");
initExtensionType(CosmeticExtension::getExtensionClassTypeId());
}
@@ -287,6 +289,103 @@ bool CosmeticExtension::replaceCosmeticEdge(CosmeticEdge* newCE)
return result;
}
//********** Center Line *******************************************************
//********** Geometry Formats **************************************************
//returns unique GF id
//only adds gf to gflist property. does not add to display geometry until dvp repaints.
std::string CosmeticExtension::addGeomFormat(TechDraw::GeomFormat* gf)
{
// Base::Console().Message("CEx::addGeomFormat(gf: %X)\n", gf);
std::vector<GeomFormat*> formats = GeomFormats.getValues();
TechDraw::GeomFormat* newGF = new TechDraw::GeomFormat(gf);
formats.push_back(newGF);
GeomFormats.setValues(formats);
std::string result = newGF->getTagAsString();
return result;
}
//get GF by unique id
TechDraw::GeomFormat* CosmeticExtension::getGeomFormat(std::string tagString) const
{
// Base::Console().Message("CEx::getGeomFormat(%s)\n", tagString.c_str());
GeomFormat* result = nullptr;
const std::vector<TechDraw::GeomFormat*> formats = GeomFormats.getValues();
for (auto& gf: formats) {
std::string gfTag = gf->getTagAsString();
if (gfTag == tagString) {
result = gf;
break;
}
}
return result;
}
// find the cosmetic edge corresponding to selection name (Edge5)
// used when selecting
TechDraw::GeomFormat* CosmeticExtension::getGeomFormatBySelection(std::string name) const
{
// Base::Console().Message("CEx::getCEBySelection(%s)\n",name.c_str());
GeomFormat* result = nullptr;
App::DocumentObject* extObj = const_cast<App::DocumentObject*> (getExtendedObject());
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(extObj);
if (dvp == nullptr) {
return result;
}
int idx = DrawUtil::getIndexFromName(name);
const std::vector<TechDraw::GeomFormat*> formats = GeomFormats.getValues();
for (auto& gf: formats) {
if (gf->m_geomIndex == idx) {
result = gf;
break;
}
}
return result;
}
//overload for index only
TechDraw::GeomFormat* CosmeticExtension::getGeomFormatBySelection(int i) const
{
// Base::Console().Message("CEx::getCEBySelection(%d)\n", i);
std::stringstream ss;
ss << "Edge" << i;
std::string eName = ss.str();
return getGeomFormatBySelection(eName);
}
bool CosmeticExtension::replaceGeomFormat(GeomFormat* newGF)
{
// Base::Console().Message("CEx::replaceGF(%s)\n", newGF->getTagAsString().c_str());
bool result = false;
std::vector<GeomFormat*> gFormats = GeomFormats.getValues();
std::vector<GeomFormat*> newFormats;
std::string tag = newGF->getTagAsString();
for (auto& gf: gFormats) {
if (gf->getTagAsString() == tag) {
newFormats.push_back(newGF);
result = true;
} else {
newFormats.push_back(gf);
}
}
GeomFormats.setValues(newFormats);
return result;
}
void CosmeticExtension::removeGeomFormat(std::string delTag)
{
// Base::Console().Message("DVP::removeCE(%s)\n", delTag.c_str());
std::vector<GeomFormat*> cFormats = GeomFormats.getValues();
std::vector<GeomFormat*> newFormats;
for (auto& gf: cFormats) {
if (gf->getTagAsString() != delTag) {
newFormats.push_back(gf);
}
}
GeomFormats.setValues(newFormats);
}
//================================================================================
PyObject* CosmeticExtension::getExtensionPyObject(void) {

View File

@@ -33,6 +33,7 @@
#include "PropertyCosmeticVertexList.h"
#include "PropertyCosmeticEdgeList.h"
#include "PropertyGeomFormatList.h"
namespace TechDraw {
@@ -48,6 +49,8 @@ public:
TechDraw::PropertyCosmeticVertexList CosmeticVertexes;
TechDraw::PropertyCosmeticEdgeList CosmeticEdges;
// TechDraw::PropertyCenterLineList CenterLines;
TechDraw::PropertyGeomFormatList GeomFormats; //formats for geometric edges
virtual std::string addCosmeticVertex(Base::Vector3d pos);
virtual CosmeticVertex* getCosmeticVertexBySelection(std::string name) const;
@@ -66,6 +69,13 @@ public:
virtual void removeCosmeticEdge(std::string tag);
virtual void removeCosmeticEdge(std::vector<std::string> delTags);
virtual std::string addGeomFormat(TechDraw::GeomFormat* gf);
virtual GeomFormat* getGeomFormatBySelection(std::string name) const;
virtual GeomFormat* getGeomFormatBySelection(int i) const;
virtual GeomFormat* getGeomFormat(std::string id) const;
virtual bool replaceGeomFormat(TechDraw::GeomFormat* gf);
virtual void removeGeomFormat(std::string tag);
PyObject* getExtensionPyObject(void);

View File

@@ -161,9 +161,9 @@ DrawViewPart::DrawViewPart(void) :
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(CosmeticEdges ,(0),sgroup,App::Prop_Output,"CosmeticEdge 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");
// ADD_PROPERTY_TYPE(GeomFormats ,(0),sgroup,App::Prop_Output,"Geometry format Save/Restore");
geometryObject = nullptr;
getRunControl();
@@ -999,14 +999,11 @@ void DrawViewPart::clearCosmeticVertexes(void)
void DrawViewPart::addCosmeticVertexesToGeom(void)
{
// Base::Console().Message("DVP::addCosmeticVertexesToGeom()\n");
int iCV = 0;
const std::vector<TechDraw::CosmeticVertex*> cVerts = CosmeticVertexes.getValues();
int stop = (int) cVerts.size();
for ( ; iCV < stop; iCV++) {
int iGV = geometryObject->addCosmeticVertex(cVerts.at(iCV)->scaled(getScale()),
cVerts.at(iCV)->getTagAsString(),
iCV); //last param can be removed now?
cVerts.at(iCV)->linkGeom = iGV;
for (auto& cv: cVerts) {
int iGV = geometryObject->addCosmeticVertex(cv->scaled(getScale()),
cv->getTagAsString());
cv->linkGeom = iGV;
}
}
@@ -1017,10 +1014,8 @@ 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 = -1;
int iGV = geometryObject->addCosmeticVertex(cv->scaled(getScale()),
cv->getTagAsString(),
iCV);
cv->getTagAsString());
cv->linkGeom = iGV;
return iGV;
}
@@ -1244,51 +1239,6 @@ void DrawViewPart::clearGeomFormats(void)
}
}
int DrawViewPart::addGeomFormat(GeomFormat* gf)
{
std::vector<GeomFormat*> fmts = GeomFormats.getValues();
int newIdx = (int) fmts.size();
fmts.push_back(gf);
GeomFormats.setValues(fmts);
return newIdx;
}
void DrawViewPart::removeGeomFormat(int idx)
{
std::vector<GeomFormat*> fmts = GeomFormats.getValues();
if (idx < (int) fmts.size()) {
GeomFormat* toRemove = fmts[idx];
fmts.erase(fmts.begin() + idx);
GeomFormats.setValues(fmts);
delete toRemove;
requestPaint();
}
}
TechDraw::GeomFormat* DrawViewPart::getGeomFormatByIndex(int idx) const
{
GeomFormat* result = nullptr;
const std::vector<TechDraw::GeomFormat*> fmts = GeomFormats.getValues();
if (idx < (int) fmts.size()) {
result = fmts.at(idx);
}
return result;
}
//find the format corresponding to geometry edge idx
TechDraw::GeomFormat* DrawViewPart::getGeomFormatByGeom(int idx) const
{
GeomFormat* result = nullptr;
const std::vector<TechDraw::GeomFormat*> fmts = GeomFormats.getValues();
for (auto& f: fmts) {
if (f->m_geomIndex == idx) {
result = f;
break;
}
}
return result;
}
//------------------------------------------------------------------------------
void DrawViewPart::dumpVerts(std::string text)

View File

@@ -112,7 +112,6 @@ public:
App::PropertyInteger IsoCount;
TechDraw::PropertyCenterLineList CenterLines;
TechDraw::PropertyGeomFormatList GeomFormats;
virtual short mustExecute() const override;
virtual void onDocumentRestored() override;
@@ -175,13 +174,11 @@ public:
void clearCosmeticVertexes(void);
void refreshCVGeoms(void);
void addCosmeticVertexesToGeom(void);
void add1CosmeticVertexToGeom(int iCV);
int add1CVToGV(std::string tag);
void clearCosmeticEdges(void);
void refreshCEGeoms(void);
void addCosmeticEdgesToGeom(void);
void add1CosmeticEdgeToGeom(int iCE);
int add1CEToGE(std::string tag);
virtual int addCenterLine(TechDraw::CenterLine*);
@@ -196,10 +193,6 @@ public:
void clearCenterLines(void);
void addCenterLinesToGeom(void);
int addGeomFormat(TechDraw::GeomFormat* gf);
virtual void removeGeomFormat(int idx);
TechDraw::GeomFormat* getGeomFormatByIndex(int idx) const;
TechDraw::GeomFormat* getGeomFormatByGeom(int idx) const;
void clearGeomFormats(void);
void dumpVerts(const std::string text);

View File

@@ -627,7 +627,7 @@ PyObject* DrawViewPartPy::formatGeometricEdge(PyObject *args)
color = DrawUtil::pyTupleToColor(pColor);
DrawViewPart* dvp = getDrawViewPartPtr();
TechDraw::GeomFormat* gf = dvp->getGeomFormatByGeom(idx);
TechDraw::GeomFormat* gf = dvp->getGeomFormatBySelection(idx);
if (gf != nullptr) {
gf->m_format.m_style = style;
gf->m_format.m_color = color;

View File

@@ -593,27 +593,26 @@ int GeometryObject::addCosmeticVertex(CosmeticVertex* cv)
return idx;
}
//adds a new GeomVert to list for cv[link]
int GeometryObject::addCosmeticVertex(Base::Vector3d pos, int link)
//adds a new GeomVert to list
//should probably be called addVertex since not connect to CV by tag
int GeometryObject::addCosmeticVertex(Base::Vector3d pos)
{
Base::Console().Message("GO::addCosmeticVertex() 1 - deprec?\n");
TechDraw::Vertex* v = new TechDraw::Vertex(pos.x, pos.y);
v->cosmetic = true;
v->cosmeticLink = link;
v->cosmeticTag = "tbi";
v->cosmeticTag = "tbi"; //not connected to CV
v->hlrVisible = true;
int idx = vertexGeom.size();
vertexGeom.push_back(v);
return idx;
}
int GeometryObject::addCosmeticVertex(Base::Vector3d pos, std::string tagString, int link)
int GeometryObject::addCosmeticVertex(Base::Vector3d pos, std::string tagString)
{
// Base::Console().Message("GO::addCosmeticVertex() 2\n");
TechDraw::Vertex* v = new TechDraw::Vertex(pos.x, pos.y);
v->cosmetic = true;
v->cosmeticLink = link;
v->cosmeticTag = tagString;
v->cosmeticTag = tagString; //connected to CV
v->hlrVisible = true;
int idx = vertexGeom.size();
vertexGeom.push_back(v);
@@ -641,8 +640,7 @@ int GeometryObject::addCosmeticEdge(CosmeticEdge* ce)
//adds a new GeomEdge to list for ce[link]
//this should be made obsolete and the variant with tag used instead
int GeometryObject::addCosmeticEdge(Base::Vector3d start,
Base::Vector3d end,
int link)
Base::Vector3d end)
{
Base::Console().Message("GO::addCosmeticEdge() 1 - deprec?\n");
gp_Pnt gp1(start.x, start.y, start.z);
@@ -660,8 +658,7 @@ int GeometryObject::addCosmeticEdge(Base::Vector3d start,
int GeometryObject::addCosmeticEdge(Base::Vector3d start,
Base::Vector3d end,
std::string tagString,
int link)
std::string tagString)
{
Base::Console().Message("GO::addCosmeticEdge() 2\n");
gp_Pnt gp1(start.x, start.y, start.z);

View File

@@ -145,25 +145,19 @@ public:
TopoDS_Shape getHidIso(void) { return hidIso; }
int addCosmeticVertex(CosmeticVertex* cv);
int addCosmeticVertex(Base::Vector3d pos);
int addCosmeticVertex(Base::Vector3d pos,
int link = -1); //obs?
int addCosmeticVertex(Base::Vector3d pos,
std::string tagString,
int link = -1); //obs??
std::string tagString);
int addCosmeticEdge(CosmeticEdge* ce);
int addCosmeticEdge(Base::Vector3d start,
Base::Vector3d end,
int link = -1); //obs?
Base::Vector3d end);
int addCosmeticEdge(Base::Vector3d start,
Base::Vector3d end,
std::string tagString,
int link = -1); //obs??
std::string tagString);
int addCosmeticEdge(TechDraw::BaseGeom* base,
std::string tagString);
/* int addCosmeticEdge(TechDraw::BaseGeom* bg, int s = 0);*/
int addCenterLine(TechDraw::BaseGeom* bg, int s = 0, int si = -1);
protected:

View File

@@ -570,7 +570,6 @@ void QGIViewPart::drawViewPart()
int source = (*itGeom)->source();
int sourceIndex = (*itGeom)->sourceIndex();
if (source == COSMETICEDGE) {
// showItem = formatGeomFromCosmetic(sourceIndex, item);
std::string cTag = (*itGeom)->getCosmeticTag();
showItem = formatGeomFromCosmetic(cTag, item);
} else if (source == CENTERLINE) {
@@ -579,7 +578,7 @@ void QGIViewPart::drawViewPart()
Base::Console().Message("QGIVP::drawVP - edge: %d is confused - source: %d\n",i,source);
}
} else {
TechDraw::GeomFormat* gf = viewPart->getGeomFormatByGeom(i);
TechDraw::GeomFormat* gf = viewPart->getGeomFormatBySelection(i);
if (gf != nullptr) {
item->setNormalColor(gf->m_format.m_color.asValue<QColor>());
item->setWidth(gf->m_format.m_weight * lineScaleFactor);

View File

@@ -132,7 +132,7 @@ void TaskLineDecor::getDefaults(void)
m_visible = cl->m_format.m_visible;
}
} else {
TechDraw::GeomFormat* gf = m_partFeat->getGeomFormatByGeom(num);
TechDraw::GeomFormat* gf = m_partFeat->getGeomFormatBySelection(num);
if (gf != nullptr) {
m_style = gf->m_format.m_style;
m_color = gf->m_format.m_color;
@@ -199,7 +199,7 @@ void TaskLineDecor::applyDecorations(void)
cl->m_format.m_visible = m_visible;
}
} else {
TechDraw::GeomFormat* gf = m_partFeat->getGeomFormatByGeom(num);
TechDraw::GeomFormat* gf = m_partFeat->getGeomFormatBySelection(num);
if (gf != nullptr) {
gf->m_format.m_style = m_style;
gf->m_format.m_color = m_color;