Skip to content

Commit

Permalink
[TD]Python routines and extension for Cosmetic Edges
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Dec 17, 2019
1 parent d9e0c2e commit 08f23b8
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 270 deletions.
17 changes: 15 additions & 2 deletions src/Mod/TechDraw/App/Cosmetic.h
Expand Up @@ -41,6 +41,8 @@ class TopoDS_Edge;
namespace TechDraw {
class DrawViewPart;


//general purpose line format specifier
class TechDrawExport LineFormat
{
public:
Expand All @@ -64,6 +66,7 @@ class TechDrawExport LineFormat
std::string toString() const;
};

//********** Cosmetic Vertex ***************************************************
class TechDrawExport CosmeticVertex: public Base::Persistence, public TechDraw::Vertex
{
TYPESYSTEM_HEADER();
Expand Down Expand Up @@ -110,6 +113,9 @@ class TechDrawExport CosmeticVertex: public Base::Persistence, public TechDraw::

};

//********** CosmeticEdge ******************************************************

//?? should this inherit BaseGeom or have a BaseGeom member?
class TechDrawExport CosmeticEdge : public Base::Persistence, public TechDraw::BaseGeom
{
TYPESYSTEM_HEADER();
Expand All @@ -125,7 +131,6 @@ class TechDrawExport CosmeticEdge : public Base::Persistence, public TechDraw::B
TechDraw::BaseGeom* scaledGeometry(double scale);

virtual std::string toString(void) const;
/* virtual bool fromCSV(std::string& lineSpec);*/
void dump(const char* title);

// Persistence implementer ---------------------
Expand All @@ -137,6 +142,8 @@ class TechDrawExport CosmeticEdge : public Base::Persistence, public TechDraw::B
CosmeticEdge* copy(void) const;
CosmeticEdge* clone(void) const;

//Base::Vector3d permaStart; //persistent unscaled start/end points in View coords
//Base::Vector3d permaEnd;
TechDraw::BaseGeom* m_geometry;
LineFormat m_format;

Expand All @@ -151,6 +158,8 @@ class TechDrawExport CosmeticEdge : public Base::Persistence, public TechDraw::B
boost::uuids::uuid tag;
};

//***** CenterLine *************************************************************

class TechDrawExport CenterLine: public Base::Persistence
{
TYPESYSTEM_HEADER();
Expand Down Expand Up @@ -255,6 +264,9 @@ class TechDrawExport CenterLine: public Base::Persistence

};

//********** GeomFormat ********************************************************

// format specifier for geometric edges (Edge5)
class TechDrawExport GeomFormat: public Base::Persistence
{
TYPESYSTEM_HEADER();
Expand All @@ -278,7 +290,8 @@ class TechDrawExport GeomFormat: public Base::Persistence
std::string toString(void) const;
void dump(const char* title) const;

int m_geomIndex;
//std::string linkTag;
int m_geomIndex; //connection to edgeGeom
LineFormat m_format;

//Uniqueness
Expand Down
117 changes: 117 additions & 0 deletions src/Mod/TechDraw/App/CosmeticExtension.cpp
Expand Up @@ -171,6 +171,123 @@ bool CosmeticExtension::replaceCosmeticVertex(CosmeticVertex* newCV)
return result;
}

//********** Cosmetic Edge *****************************************************

//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,
Base::Vector3d end)
{
// Base::Console().Message("CEx::addCosmeticEdge(%s)\n",
// DrawUtil::formatVector(pos).c_str());
std::vector<CosmeticEdge*> edges = CosmeticEdges.getValues();
TechDraw::CosmeticEdge* ce = new TechDraw::CosmeticEdge(start, end);
edges.push_back(ce);
CosmeticEdges.setValues(edges);
std::string result = ce->getTagAsString();
return result;
}

std::string CosmeticExtension::addCosmeticEdge(TechDraw::BaseGeom* bg)
{
// Base::Console().Message("CEx::addCosmeticEdge(bg: %X)\n", bg);
std::vector<CosmeticEdge*> edges = CosmeticEdges.getValues();
TechDraw::CosmeticEdge* ce = new TechDraw::CosmeticEdge(bg);
edges.push_back(ce);
CosmeticEdges.setValues(edges);
std::string result = ce->getTagAsString();
return result;
}


//get CE by unique id
TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdge(std::string tagString) const
{
// Base::Console().Message("CEx::getCosmeticEdge(%s)\n", tagString.c_str());
CosmeticEdge* result = nullptr;
const std::vector<TechDraw::CosmeticEdge*> edges = CosmeticEdges.getValues();
for (auto& ce: edges) {
std::string ceTag = ce->getTagAsString();
if (ceTag == tagString) {
result = ce;
break;
}
}
return result;
}

// find the cosmetic edge corresponding to selection name (Edge5)
// used when selecting
TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdgeBySelection(std::string name) const
{
// Base::Console().Message("CEx::getCEBySelection(%s)\n",name.c_str());
CosmeticEdge* 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);
TechDraw::BaseGeom* base = dvp->getGeomByIndex(idx);
if (base == nullptr) {
return result;
}
if (!base->getCosmeticTag().empty()) {
result = getCosmeticEdge(base->getCosmeticTag());
}
return result;
}

//overload for index only
TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdgeBySelection(int i) const
{
// Base::Console().Message("CEx::getCEBySelection(%d)\n", i);
std::stringstream ss;
ss << "Edge" << i;
std::string eName = ss.str();
return getCosmeticEdgeBySelection(eName);
}

void CosmeticExtension::removeCosmeticEdge(std::string delTag)
{
// Base::Console().Message("DVP::removeCE(%s)\n", delTag.c_str());
std::vector<CosmeticEdge*> cEdges = CosmeticEdges.getValues();
std::vector<CosmeticEdge*> newEdges;
for (auto& ce: cEdges) {
if (ce->getTagAsString() != delTag) {
newEdges.push_back(ce);
}
}
CosmeticEdges.setValues(newEdges);
}

void CosmeticExtension::removeCosmeticEdge(std::vector<std::string> delTags)
{
for (auto& t: delTags) {
removeCosmeticEdge(t);
}
}

bool CosmeticExtension::replaceCosmeticEdge(CosmeticEdge* newCE)
{
// Base::Console().Message("DVP::replaceCE(%s)\n", newCE->getTagAsString().c_str());
bool result = false;
std::vector<CosmeticEdge*> cEdges = CosmeticEdges.getValues();
std::vector<CosmeticEdge*> newEdges;
std::string tag = newCE->getTagAsString();
for (auto& ce: cEdges) {
if (ce->getTagAsString() == tag) {
newEdges.push_back(newCE);
result = true;
} else {
newEdges.push_back(ce);
}
}
CosmeticEdges.setValues(newEdges);
return result;
}


//================================================================================
PyObject* CosmeticExtension::getExtensionPyObject(void) {
if (ExtensionPythonObject.is(Py::_None())){
Expand Down
12 changes: 12 additions & 0 deletions src/Mod/TechDraw/App/CosmeticExtension.h
Expand Up @@ -32,6 +32,7 @@
#include <Base/Exception.h>

#include "PropertyCosmeticVertexList.h"
#include "PropertyCosmeticEdgeList.h"


namespace TechDraw {
Expand All @@ -46,6 +47,7 @@ class TechDrawExport CosmeticExtension : public App::DocumentObjectExtension {
virtual ~CosmeticExtension();

TechDraw::PropertyCosmeticVertexList CosmeticVertexes;
TechDraw::PropertyCosmeticEdgeList CosmeticEdges;

virtual std::string addCosmeticVertex(Base::Vector3d pos);
virtual CosmeticVertex* getCosmeticVertexBySelection(std::string name) const;
Expand All @@ -55,6 +57,16 @@ class TechDrawExport CosmeticExtension : public App::DocumentObjectExtension {
virtual void removeCosmeticVertex(std::string tag);
virtual void removeCosmeticVertex(std::vector<std::string> delTags);

virtual std::string addCosmeticEdge(Base::Vector3d start, Base::Vector3d end);
virtual std::string addCosmeticEdge(TechDraw::BaseGeom* bg);
virtual CosmeticEdge* getCosmeticEdgeBySelection(std::string name) const;
virtual CosmeticEdge* getCosmeticEdgeBySelection(int i) const;
virtual CosmeticEdge* getCosmeticEdge(std::string id) const;
virtual bool replaceCosmeticEdge(CosmeticEdge* newEdge);
virtual void removeCosmeticEdge(std::string tag);
virtual void removeCosmeticEdge(std::vector<std::string> delTags);


PyObject* getExtensionPyObject(void);

protected:
Expand Down

0 comments on commit 08f23b8

Please sign in to comment.