[TD]move dvp cosmetic functions to extension

This commit is contained in:
wandererfan
2023-07-11 09:07:41 -04:00
committed by WandererFan
parent 77ef529c5a
commit 6565732207
4 changed files with 217 additions and 225 deletions

View File

@@ -30,7 +30,7 @@
#include "Cosmetic.h"
#include "DrawUtil.h"
#include "DrawViewPart.h"
#include "GeometryObject.h"
using namespace TechDraw;
using namespace std;
@@ -53,11 +53,10 @@ CosmeticExtension::~CosmeticExtension()
{
}
//void CosmeticExtension::extHandleChangedPropertyName(Base::XMLReader &reader,
// const char* TypeName,
// const char* PropName)
//{
//}
TechDraw::DrawViewPart* CosmeticExtension::getOwner()
{
return static_cast<TechDraw::DrawViewPart*>(getExtendedObject());
}
//==============================================================================
//CosmeticVertex x, y are stored as unscaled, but mirrored (inverted Y) values.
@@ -66,6 +65,85 @@ CosmeticExtension::~CosmeticExtension()
//if you are creating a CV based on calculations of mirrored geometry, you need to
//mirror again before creation.
void CosmeticExtension::clearCosmeticVertexes()
{
std::vector<CosmeticVertex*> noVerts;
CosmeticVertexes.setValues(noVerts);
}
//add the cosmetic verts to owner's geometry vertex list
void CosmeticExtension::addCosmeticVertexesToGeom()
{
// Base::Console().Message("CE::addCosmeticVertexesToGeom()\n");
const std::vector<TechDraw::CosmeticVertex*> cVerts = CosmeticVertexes.getValues();
for (auto& cv : cVerts) {
double scale = getOwner()->getScale();
int iGV = getOwner()->getGeometryObject()->addCosmeticVertex(cv->scaled(scale), cv->getTagAsString());
cv->linkGeom = iGV;
}
}
int CosmeticExtension::add1CVToGV(std::string tag)
{
// Base::Console().Message("CE::add1CVToGV(%s)\n", tag.c_str());
TechDraw::CosmeticVertex* cv = getCosmeticVertex(tag);
if (!cv) {
Base::Console().Message("CE::add1CVToGV - cv %s not found\n", tag.c_str());
return 0;
}
double scale = getOwner()->getScale();
int iGV = getOwner()->getGeometryObject()->addCosmeticVertex(cv->scaled(scale), cv->getTagAsString());
cv->linkGeom = iGV;
return iGV;
}
//update Vertex geometry with current CV's
void CosmeticExtension::refreshCVGeoms()
{
// Base::Console().Message("CE::refreshCVGeoms()\n");
std::vector<TechDraw::VertexPtr> gVerts = getOwner()->getVertexGeometry();
std::vector<TechDraw::VertexPtr> newGVerts;
for (auto& gv : gVerts) {
if (gv->getCosmeticTag().empty()) {//keep only non-cv vertices
newGVerts.push_back(gv);
}
}
getOwner()->getGeometryObject()->setVertexGeometry(newGVerts);
addCosmeticVertexesToGeom();
}
//what is the CV's position in the big geometry q
int CosmeticExtension::getCVIndex(std::string tag)
{
// Base::Console().Message("CE::getCVIndex(%s)\n", tag.c_str());
std::vector<TechDraw::VertexPtr> gVerts = getOwner()->getVertexGeometry();
std::vector<TechDraw::CosmeticVertex*> cVerts = CosmeticVertexes.getValues();
int i = 0;
for (auto& gv : gVerts) {
if (gv->getCosmeticTag() == tag) {
return i;
}
i++;
}
// Nothing found
int base = gVerts.size();
i = 0;
for (auto& cv : cVerts) {
// Base::Console().Message("CE::getCVIndex - cv tag: %s\n",
// cv->getTagAsString().c_str());
if (cv->getTagAsString() == tag) {
return base + i;
}
i++;
}
// Base::Console().Message("CE::getCVIndex - returns: %d\n", result);
return -1;
}
//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)
@@ -145,6 +223,56 @@ void CosmeticExtension::removeCosmeticVertex(std::vector<std::string> delTags)
//********** Cosmetic Edge *****************************************************
void CosmeticExtension::clearCosmeticEdges()
{
std::vector<CosmeticEdge*> noEdges;
CosmeticEdges.setValues(noEdges);
}
//add the cosmetic edges to geometry edge list
void CosmeticExtension::addCosmeticEdgesToGeom()
{
// Base::Console().Message("CEx::addCosmeticEdgesToGeom()\n");
const std::vector<TechDraw::CosmeticEdge*> cEdges = CosmeticEdges.getValues();
for (auto& ce : cEdges) {
double scale = getOwner()->getScale();
TechDraw::BaseGeomPtr scaledGeom = ce->scaledGeometry(scale);
if (!scaledGeom)
continue;
// int iGE =
getOwner()->getGeometryObject()->addCosmeticEdge(scaledGeom, ce->getTagAsString());
}
}
int CosmeticExtension::add1CEToGE(std::string tag)
{
// Base::Console().Message("CEx::add1CEToGE(%s) 2\n", tag.c_str());
TechDraw::CosmeticEdge* ce = getCosmeticEdge(tag);
if (!ce) {
Base::Console().Message("CEx::add1CEToGE 2 - ce %s not found\n", tag.c_str());
return -1;
}
TechDraw::BaseGeomPtr scaledGeom = ce->scaledGeometry(getOwner()->getScale());
int iGE = getOwner()->getGeometryObject()->addCosmeticEdge(scaledGeom, tag);
return iGE;
}
//update Edge geometry with current CE's
void CosmeticExtension::refreshCEGeoms()
{
// Base::Console().Message("CEx::refreshCEGeoms()\n");
std::vector<TechDraw::BaseGeomPtr> gEdges = getOwner()->getEdgeGeometry();
std::vector<TechDraw::BaseGeomPtr> oldGEdges;
for (auto& ge : gEdges) {
if (ge->source() != SourceType::COSEDGE) {
oldGEdges.push_back(ge);
}
}
getOwner()->getGeometryObject()->setEdgeGeometry(oldGEdges);
addCosmeticEdgesToGeom();
}
//returns unique CE id
//only adds ce to celist property. does not add to display geometry until dvp executes.
std::string CosmeticExtension::addCosmeticEdge(Base::Vector3d start,
@@ -235,6 +363,57 @@ void CosmeticExtension::removeCosmeticEdge(std::vector<std::string> delTags)
//********** Center Line *******************************************************
void CosmeticExtension::clearCenterLines()
{
std::vector<CenterLine*> noLines;
CenterLines.setValues(noLines);
}
int CosmeticExtension::add1CLToGE(std::string tag)
{
// Base::Console().Message("CEx::add1CLToGE(%s) 2\n", tag.c_str());
TechDraw::CenterLine* cl = getCenterLine(tag);
if (!cl) {
Base::Console().Message("CEx::add1CLToGE 2 - cl %s not found\n", tag.c_str());
return -1;
}
TechDraw::BaseGeomPtr scaledGeom = cl->scaledGeometry(getOwner());
int iGE = getOwner()->getGeometryObject()->addCenterLine(scaledGeom, tag);
return iGE;
}
//update Edge geometry with current CL's
void CosmeticExtension::refreshCLGeoms()
{
// Base::Console().Message("CE::refreshCLGeoms()\n");
std::vector<TechDraw::BaseGeomPtr> gEdges = getOwner()->getEdgeGeometry();
std::vector<TechDraw::BaseGeomPtr> newGEdges;
for (auto& ge : gEdges) {
if (ge->source() != SourceType::CENTERLINE) {
newGEdges.push_back(ge);
}
}
getOwner()->getGeometryObject()->setEdgeGeometry(newGEdges);
addCenterLinesToGeom();
}
//add the center lines to geometry Edges list
void CosmeticExtension::addCenterLinesToGeom()
{
// Base::Console().Message("CE::addCenterLinesToGeom()\n");
const std::vector<TechDraw::CenterLine*> lines = CenterLines.getValues();
for (auto& cl : lines) {
TechDraw::BaseGeomPtr scaledGeom = cl->scaledGeometry(getOwner());
if (!scaledGeom) {
Base::Console().Error("CE::addCenterLinesToGeom - scaledGeometry is null\n");
continue;
}
// int idx =
getOwner()->getGeometryObject()->addCenterLine(scaledGeom, cl->getTagAsString());
}
}
//returns unique CL id
//only adds cl to cllist property. does not add to display geometry until dvp executes.
std::string CosmeticExtension::addCenterLine(Base::Vector3d start,
@@ -334,6 +513,17 @@ void CosmeticExtension::removeCenterLine(std::vector<std::string> delTags)
//********** Geometry Formats **************************************************
void CosmeticExtension::clearGeomFormats()
{
std::vector<GeomFormat*> noFormats;
std::vector<GeomFormat*> fmts = GeomFormats.getValues();
GeomFormats.setValues(noFormats);
for (auto& f : fmts) {
delete f;
}
}
//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)

View File

@@ -51,12 +51,22 @@ public:
TechDraw::PropertyCenterLineList CenterLines;
TechDraw::PropertyGeomFormatList GeomFormats; //formats for geometric edges
virtual void addCosmeticVertexesToGeom();
virtual void refreshCVGeoms();
virtual int add1CVToGV(std::string tag);
virtual int getCVIndex(std::string tag);
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 void removeCosmeticVertex(std::string tag);
virtual void removeCosmeticVertex(std::vector<std::string> delTags);
virtual void clearCosmeticVertexes();
virtual void refreshCEGeoms();
virtual void addCosmeticEdgesToGeom();
virtual int add1CEToGE(std::string tag);
virtual std::string addCosmeticEdge(Base::Vector3d start, Base::Vector3d end);
virtual std::string addCosmeticEdge(TechDraw::BaseGeomPtr bg);
@@ -65,6 +75,11 @@ public:
virtual CosmeticEdge* getCosmeticEdge(std::string id) const;
virtual void removeCosmeticEdge(std::string tag);
virtual void removeCosmeticEdge(std::vector<std::string> delTags);
virtual void clearCosmeticEdges();
virtual void refreshCLGeoms();
virtual void addCenterLinesToGeom();
virtual int add1CLToGE(std::string tag);
virtual std::string addCenterLine(Base::Vector3d start, Base::Vector3d end);
virtual std::string addCenterLine(TechDraw::CenterLine* cl);
@@ -74,13 +89,16 @@ public:
virtual CenterLine* getCenterLine(std::string tag) const;
virtual void removeCenterLine(std::string tag);
virtual void removeCenterLine(std::vector<std::string> delTags);
virtual void clearCenterLines();
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 void removeGeomFormat(std::string tag);
virtual void clearGeomFormats();
TechDraw::DrawViewPart* getOwner();
PyObject* getExtensionPyObject() override;

View File

@@ -1292,6 +1292,8 @@ Base::Vector3d DrawViewPart::getLegacyX(const Base::Vector3d& pt, const Base::Ve
return Base::Vector3d(gXDir.X(), gXDir.Y(), gXDir.Z());
}
// reference dimensions & their vertices
// these routines may be obsolete
void DrawViewPart::updateReferenceVert(std::string tag, Base::Vector3d loc2d)
{
@@ -1365,206 +1367,7 @@ void DrawViewPart::resetReferenceVerts()
addReferencesToGeom();
}
//********
//* Cosmetics
//********
void DrawViewPart::clearCosmeticVertexes()
{
std::vector<CosmeticVertex*> noVerts;
CosmeticVertexes.setValues(noVerts);
}
//add the cosmetic verts to geometry vertex list
void DrawViewPart::addCosmeticVertexesToGeom()
{
// Base::Console().Message("DVP::addCosmeticVertexesToGeom()\n");
const std::vector<TechDraw::CosmeticVertex*> cVerts = CosmeticVertexes.getValues();
for (auto& cv : cVerts) {
int iGV = geometryObject->addCosmeticVertex(cv->scaled(getScale()), cv->getTagAsString());
cv->linkGeom = iGV;
}
}
int DrawViewPart::add1CVToGV(std::string tag)
{
// Base::Console().Message("DVP::add1CVToGV(%s)\n", tag.c_str());
TechDraw::CosmeticVertex* cv = getCosmeticVertex(tag);
if (!cv) {
Base::Console().Message("DVP::add1CVToGV - cv %s not found\n", tag.c_str());
return 0;
}
int iGV = geometryObject->addCosmeticVertex(cv->scaled(getScale()), cv->getTagAsString());
cv->linkGeom = iGV;
return iGV;
}
//update Vertex geometry with current CV's
void DrawViewPart::refreshCVGeoms()
{
// Base::Console().Message("DVP::refreshCVGeoms()\n");
std::vector<TechDraw::VertexPtr> gVerts = getVertexGeometry();
std::vector<TechDraw::VertexPtr> newGVerts;
for (auto& gv : gVerts) {
if (gv->getCosmeticTag().empty()) {//keep only non-cv vertices
newGVerts.push_back(gv);
}
}
getGeometryObject()->setVertexGeometry(newGVerts);
addCosmeticVertexesToGeom();
}
//what is the CV's position in the big geometry q
int DrawViewPart::getCVIndex(std::string tag)
{
// Base::Console().Message("DVP::getCVIndex(%s)\n", tag.c_str());
std::vector<TechDraw::VertexPtr> gVerts = getVertexGeometry();
std::vector<TechDraw::CosmeticVertex*> cVerts = CosmeticVertexes.getValues();
int i = 0;
for (auto& gv : gVerts) {
if (gv->getCosmeticTag() == tag) {
return i;
}
i++;
}
// Nothing found
int base = gVerts.size();
i = 0;
for (auto& cv : cVerts) {
// Base::Console().Message("DVP::getCVIndex - cv tag: %s\n",
// cv->getTagAsString().c_str());
if (cv->getTagAsString() == tag) {
return base + i;
}
i++;
}
// Base::Console().Message("DVP::getCVIndex - returns: %d\n", result);
return -1;
}
//CosmeticEdges -------------------------------------------------------------------
//for completeness. not actually used anywhere?
void DrawViewPart::clearCosmeticEdges()
{
std::vector<CosmeticEdge*> noEdges;
CosmeticEdges.setValues(noEdges);
}
//add the cosmetic edges to geometry edge list
void DrawViewPart::addCosmeticEdgesToGeom()
{
// Base::Console().Message("CEx::addCosmeticEdgesToGeom()\n");
const std::vector<TechDraw::CosmeticEdge*> cEdges = CosmeticEdges.getValues();
for (auto& ce : cEdges) {
TechDraw::BaseGeomPtr scaledGeom = ce->scaledGeometry(getScale());
if (!scaledGeom)
continue;
// int iGE =
geometryObject->addCosmeticEdge(scaledGeom, ce->getTagAsString());
}
}
int DrawViewPart::add1CEToGE(std::string tag)
{
// Base::Console().Message("CEx::add1CEToGE(%s) 2\n", tag.c_str());
TechDraw::CosmeticEdge* ce = getCosmeticEdge(tag);
if (!ce) {
Base::Console().Message("CEx::add1CEToGE 2 - ce %s not found\n", tag.c_str());
return -1;
}
TechDraw::BaseGeomPtr scaledGeom = ce->scaledGeometry(getScale());
int iGE = geometryObject->addCosmeticEdge(scaledGeom, tag);
return iGE;
}
//update Edge geometry with current CE's
void DrawViewPart::refreshCEGeoms()
{
// Base::Console().Message("DVP::refreshCEGeoms()\n");
std::vector<TechDraw::BaseGeomPtr> gEdges = getEdgeGeometry();
std::vector<TechDraw::BaseGeomPtr> oldGEdges;
for (auto& ge : gEdges) {
if (ge->source() != SourceType::COSEDGE) {
oldGEdges.push_back(ge);
}
}
getGeometryObject()->setEdgeGeometry(oldGEdges);
addCosmeticEdgesToGeom();
}
// CenterLines -----------------------------------------------------------------
void DrawViewPart::clearCenterLines()
{
std::vector<CenterLine*> noLines;
CenterLines.setValues(noLines);
}
int DrawViewPart::add1CLToGE(std::string tag)
{
// Base::Console().Message("CEx::add1CLToGE(%s) 2\n", tag.c_str());
TechDraw::CenterLine* cl = getCenterLine(tag);
if (!cl) {
Base::Console().Message("CEx::add1CLToGE 2 - cl %s not found\n", tag.c_str());
return -1;
}
TechDraw::BaseGeomPtr scaledGeom = cl->scaledGeometry(this);
int iGE = geometryObject->addCenterLine(scaledGeom, tag);
return iGE;
}
//update Edge geometry with current CL's
void DrawViewPart::refreshCLGeoms()
{
// Base::Console().Message("DVP::refreshCLGeoms()\n");
std::vector<TechDraw::BaseGeomPtr> gEdges = getEdgeGeometry();
std::vector<TechDraw::BaseGeomPtr> newGEdges;
for (auto& ge : gEdges) {
if (ge->source() != SourceType::CENTERLINE) {
newGEdges.push_back(ge);
}
}
getGeometryObject()->setEdgeGeometry(newGEdges);
addCenterLinesToGeom();
}
//add the center lines to geometry Edges list
void DrawViewPart::addCenterLinesToGeom()
{
// Base::Console().Message("DVP::addCenterLinesToGeom()\n");
const std::vector<TechDraw::CenterLine*> lines = CenterLines.getValues();
for (auto& cl : lines) {
TechDraw::BaseGeomPtr scaledGeom = cl->scaledGeometry(this);
if (!scaledGeom) {
Base::Console().Error("DVP::addCenterLinesToGeom - scaledGeometry is null\n");
continue;
}
// int idx =
(void)geometryObject->addCenterLine(scaledGeom, cl->getTagAsString());
}
}
// GeomFormats -----------------------------------------------------------------
void DrawViewPart::clearGeomFormats()
{
std::vector<GeomFormat*> noFormats;
std::vector<GeomFormat*> fmts = GeomFormats.getValues();
GeomFormats.setValues(noFormats);
for (auto& f : fmts) {
delete f;
}
}
//------------------------------------------------------------------------------
// debugging ----------------------------------------------------------------------------
void DrawViewPart::dumpVerts(std::string text)
{

View File

@@ -197,25 +197,6 @@ public:
void removeAllReferencesFromGeom();
void resetReferenceVerts();
// routines related to cosmetic features
void clearCosmeticVertexes();
void refreshCVGeoms();
void addCosmeticVertexesToGeom();
int add1CVToGV(std::string tag);
int getCVIndex(std::string tag);
void clearCosmeticEdges();
void refreshCEGeoms();
void addCosmeticEdgesToGeom();
int add1CEToGE(std::string tag);
void clearCenterLines();
void refreshCLGeoms();
void addCenterLinesToGeom();
int add1CLToGE(std::string tag);
void clearGeomFormats();
// routines related to multi-threading
virtual void postHlrTasks(void);
virtual void postFaceExtractionTasks(void);