| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <Base/Console.h> |
| |
|
| | #include "CenterLine.h" |
| | #include "CosmeticExtension.h" |
| | #include "CosmeticExtensionPy.h" |
| | #include "Cosmetic.h" |
| | #include "DrawUtil.h" |
| | #include "DrawViewPart.h" |
| | #include "GeometryObject.h" |
| |
|
| | using namespace TechDraw; |
| | using namespace std; |
| | using DU = DrawUtil; |
| |
|
| | EXTENSION_PROPERTY_SOURCE(TechDraw::CosmeticExtension, App::DocumentObjectExtension) |
| |
|
| | CosmeticExtension::CosmeticExtension() |
| | { |
| | static const char *cgroup = "Cosmetics"; |
| |
|
| | EXTENSION_ADD_PROPERTY_TYPE(CosmeticVertexes, (nullptr), cgroup, App::Prop_Output, "CosmeticVertex Save/Restore"); |
| | EXTENSION_ADD_PROPERTY_TYPE(CosmeticEdges, (nullptr), cgroup, App::Prop_Output, "CosmeticEdge Save/Restore"); |
| | EXTENSION_ADD_PROPERTY_TYPE(CenterLines ,(nullptr), cgroup, App::Prop_Output, "CenterLine Save/Restore"); |
| | EXTENSION_ADD_PROPERTY_TYPE(GeomFormats ,(nullptr), cgroup, App::Prop_Output, "Geometry format Save/Restore"); |
| |
|
| | initExtensionType(CosmeticExtension::getExtensionClassTypeId()); |
| | } |
| |
|
| | CosmeticExtension::~CosmeticExtension() |
| | { |
| | |
| | |
| | } |
| |
|
| | |
| | TechDraw::DrawViewPart* CosmeticExtension::getOwner() |
| | { |
| | return static_cast<TechDraw::DrawViewPart*>(getExtendedObject()); |
| | } |
| |
|
| | |
| | void CosmeticExtension::deleteCosmeticElements(std::vector<std::string> removables) |
| | { |
| | DrawViewPart* viewPart = getOwner(); |
| | for (auto& name : removables) { |
| | if (DU::getGeomTypeFromName(name) == "Vertex" && |
| | viewPart->isCosmeticVertex(name)) { |
| | CosmeticVertex* vert = getCosmeticVertexBySelection(name); |
| | removeCosmeticVertex(vert->getTagAsString()); |
| | continue; |
| | } |
| | if (DU::getGeomTypeFromName(name) == "Edge" && |
| | ( viewPart->isCosmeticEdge(name) || |
| | viewPart->isCenterLine(name))) { |
| | CosmeticEdge* edge = getCosmeticEdgeBySelection(name); |
| | if (edge) { |
| | |
| | removeCosmeticEdge(edge->getTagAsString()); |
| | continue; |
| | } |
| | CenterLine* line = getCenterLineBySelection(name); |
| | if (line) { |
| | removeCenterLine(line->getTagAsString()); |
| | continue; |
| | } |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| | void CosmeticExtension::clearCosmeticVertexes() |
| | { |
| | std::vector<TechDraw::CosmeticVertex*> cVerts = CosmeticVertexes.getValues(); |
| | for (auto& vert : cVerts) { |
| | delete vert; |
| | } |
| | std::vector<CosmeticVertex*> noVerts; |
| | CosmeticVertexes.setValues(noVerts); |
| | } |
| |
|
| | |
| | void CosmeticExtension::addCosmeticVertexesToGeom() |
| | { |
| | const std::vector<TechDraw::CosmeticVertex*> cVerts = CosmeticVertexes.getValues(); |
| | for (auto& cv : cVerts) { |
| | double scale = getOwner()->getScale(); |
| | double rotDegrees = getOwner()->Rotation.getValue(); |
| | Base::Vector3d cvPosition = cv->rotatedAndScaled(scale, rotDegrees); |
| | int iGV = getOwner()->getGeometryObject()->addCosmeticVertex(cvPosition, cv->getTagAsString()); |
| | cv->linkGeom = iGV; |
| | } |
| | } |
| |
|
| | |
| | int CosmeticExtension::add1CVToGV(const std::string& tag) |
| | { |
| | 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(); |
| | double rotDegrees = getOwner()->Rotation.getValue(); |
| | Base::Vector3d cvPosition = cv->rotatedAndScaled(scale, rotDegrees); |
| | int iGV = getOwner()->getGeometryObject()->addCosmeticVertex(cvPosition, cv->getTagAsString()); |
| | cv->linkGeom = iGV; |
| | return iGV; |
| | } |
| |
|
| | |
| | void CosmeticExtension::refreshCVGeoms() |
| | { |
| | std::vector<TechDraw::VertexPtr> gVerts = getOwner()->getVertexGeometry(); |
| | std::vector<TechDraw::VertexPtr> newGVerts; |
| | for (auto& gv : gVerts) { |
| | if (gv->getCosmeticTag().empty()) { |
| | newGVerts.push_back(gv); |
| | } |
| | } |
| | getOwner()->getGeometryObject()->setVertexGeometry(newGVerts); |
| | addCosmeticVertexesToGeom(); |
| | } |
| |
|
| | |
| | |
| | int CosmeticExtension::getCVIndex(const std::string& tag) |
| | { |
| | |
| | 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++; |
| | } |
| |
|
| | |
| | int base = gVerts.size(); |
| | i = 0; |
| | for (auto& cv : cVerts) { |
| | |
| | |
| | if (cv->getTagAsString() == tag) { |
| | return base + i; |
| | } |
| | i++; |
| | } |
| |
|
| | |
| | return -1; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | std::string CosmeticExtension::addCosmeticVertex(const Base::Vector3d& pos, bool invert) |
| | { |
| | |
| | |
| | std::vector<CosmeticVertex*> verts = CosmeticVertexes.getValues(); |
| | Base::Vector3d tempPos = pos; |
| | if (invert) { |
| | tempPos = DrawUtil::invertY(pos); |
| | } |
| | TechDraw::CosmeticVertex* cv = new TechDraw::CosmeticVertex(tempPos); |
| | verts.push_back(cv); |
| | CosmeticVertexes.setValues(verts); |
| | return cv->getTagAsString(); |
| | } |
| |
|
| | |
| | TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertex(const std::string& tagString) const |
| | { |
| | |
| | const std::vector<TechDraw::CosmeticVertex*> verts = CosmeticVertexes.getValues(); |
| | for (auto& cv: verts) { |
| | std::string cvTag = cv->getTagAsString(); |
| | if (cvTag == tagString) { |
| | return cv; |
| | } |
| | } |
| | return nullptr; |
| | } |
| |
|
| | |
| | |
| | TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(const std::string& name) const |
| | { |
| | |
| | App::DocumentObject* extObj = const_cast<App::DocumentObject*> (getExtendedObject()); |
| | TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(extObj); |
| | if (!dvp) { |
| | return nullptr; |
| | } |
| | int idx = DrawUtil::getIndexFromName(name); |
| | TechDraw::VertexPtr v = dvp->getProjVertexByIndex(idx); |
| | if (!v || v->getCosmeticTag().empty()) { |
| | return nullptr; |
| | } |
| | return getCosmeticVertex(v->getCosmeticTag()); |
| | } |
| |
|
| | |
| | TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(const int i) const |
| | { |
| | std::stringstream ss; |
| | ss << "Vertex" << i; |
| | std::string vName = ss.str(); |
| | return getCosmeticVertexBySelection(vName); |
| | } |
| |
|
| | |
| | void CosmeticExtension::removeCosmeticVertex(const std::string& delTag) |
| | { |
| | std::vector<CosmeticVertex*> cVerts = CosmeticVertexes.getValues(); |
| | std::vector<CosmeticVertex*> newVerts; |
| | for (auto& cv: cVerts) { |
| | if (cv->getTagAsString() != delTag) { |
| | newVerts.push_back(cv); |
| | } |
| | } |
| | CosmeticVertexes.setValues(newVerts); |
| | } |
| |
|
| | |
| | void CosmeticExtension::removeCosmeticVertex(const std::vector<std::string>& delTags) |
| | { |
| | for (auto& t: delTags) { |
| | removeCosmeticVertex(t); |
| | } |
| | } |
| |
|
| | |
| |
|
| | |
| | |
| | void CosmeticExtension::clearCosmeticEdges() |
| | { |
| | std::vector<TechDraw::CosmeticEdge*> cEdges = CosmeticEdges.getValues(); |
| | for (auto& edge : cEdges) { |
| | delete edge; |
| | } |
| | std::vector<CosmeticEdge*> noEdges; |
| | CosmeticEdges.setValues(noEdges); |
| | } |
| |
|
| | |
| | void CosmeticExtension::addCosmeticEdgesToGeom() |
| | { |
| | const std::vector<TechDraw::CosmeticEdge*> cEdges = CosmeticEdges.getValues(); |
| | for (auto& ce : cEdges) { |
| | double scale = getOwner()->getScale(); |
| | double rotDegrees = getOwner()->Rotation.getValue(); |
| | TechDraw::BaseGeomPtr scaledGeom = ce->scaledAndRotatedGeometry(scale, rotDegrees); |
| | if (!scaledGeom) |
| | continue; |
| | |
| | getOwner()->getGeometryObject()->addCosmeticEdge(scaledGeom, ce->getTagAsString()); |
| | } |
| | } |
| |
|
| | |
| | int CosmeticExtension::add1CEToGE(const std::string& tag) |
| | { |
| | TechDraw::CosmeticEdge* ce = getCosmeticEdge(tag); |
| | if (!ce) { |
| | Base::Console().message("CEx::add1CEToGE 2 - ce %s not found\n", tag.c_str()); |
| | return -1; |
| | } |
| | double scale = getOwner()->getScale(); |
| | double rotDegrees = getOwner()->Rotation.getValue(); |
| | TechDraw::BaseGeomPtr scaledGeom = ce->scaledAndRotatedGeometry(scale, rotDegrees); |
| | int iGE = getOwner()->getGeometryObject()->addCosmeticEdge(scaledGeom, tag); |
| |
|
| | return iGE; |
| | } |
| |
|
| | |
| | void CosmeticExtension::refreshCEGeoms() |
| | { |
| | std::vector<TechDraw::BaseGeomPtr> gEdges = getOwner()->getEdgeGeometry(); |
| | std::vector<TechDraw::BaseGeomPtr> oldGEdges; |
| | for (auto& ge : gEdges) { |
| | if (ge->source() != SourceType::COSMETICEDGE) { |
| | oldGEdges.push_back(ge); |
| | } |
| | } |
| | getOwner()->getGeometryObject()->setEdgeGeometry(oldGEdges); |
| | addCosmeticEdgesToGeom(); |
| | } |
| |
|
| | |
| | |
| | std::string CosmeticExtension::addCosmeticEdge(Base::Vector3d start, |
| | Base::Vector3d end) |
| | { |
| | std::vector<CosmeticEdge*> edges = CosmeticEdges.getValues(); |
| | TechDraw::CosmeticEdge* ce = new TechDraw::CosmeticEdge(start, end); |
| | edges.push_back(ce); |
| | CosmeticEdges.setValues(edges); |
| | return ce->getTagAsString(); |
| | } |
| |
|
| | |
| | |
| | std::string CosmeticExtension::addCosmeticEdge(TechDraw::BaseGeomPtr bg) |
| | { |
| | std::vector<CosmeticEdge*> edges = CosmeticEdges.getValues(); |
| | TechDraw::CosmeticEdge* ce = new TechDraw::CosmeticEdge(bg); |
| | edges.push_back(ce); |
| | CosmeticEdges.setValues(edges); |
| | return ce->getTagAsString(); |
| | } |
| |
|
| | |
| | TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdge(const std::string& tagString) const |
| | { |
| | const std::vector<TechDraw::CosmeticEdge*> edges = CosmeticEdges.getValues(); |
| | for (auto& ce: edges) { |
| | std::string ceTag = ce->getTagAsString(); |
| | if (ceTag == tagString) { |
| | return ce; |
| | } |
| | } |
| |
|
| | |
| | return nullptr; |
| | } |
| |
|
| | |
| | |
| | TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdgeBySelection(const std::string& name) const |
| | { |
| | App::DocumentObject* extObj = const_cast<App::DocumentObject*> (getExtendedObject()); |
| | TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(extObj); |
| | if (!dvp) { |
| | return nullptr; |
| | } |
| | int idx = DrawUtil::getIndexFromName(name); |
| | TechDraw::BaseGeomPtr base = dvp->getGeomByIndex(idx); |
| | if (!base || base->getCosmeticTag().empty()) { |
| | return nullptr; |
| | } |
| |
|
| | return getCosmeticEdge(base->getCosmeticTag()); |
| | } |
| |
|
| | |
| | TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdgeBySelection(int i) const |
| | { |
| | std::stringstream edgeName; |
| | edgeName << "Edge" << i; |
| | return getCosmeticEdgeBySelection(edgeName.str()); |
| | } |
| |
|
| | |
| | void CosmeticExtension::removeCosmeticEdge(const std::string& delTag) |
| | { |
| | 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(const std::vector<std::string>& delTags) |
| | { |
| | std::vector<CosmeticEdge*> cEdges = CosmeticEdges.getValues(); |
| | for (auto& t: delTags) { |
| | removeCosmeticEdge(t); |
| | } |
| | } |
| |
|
| | |
| |
|
| | |
| | void CosmeticExtension::clearCenterLines() |
| | { |
| | std::vector<TechDraw::CenterLine*> cLines = CenterLines.getValues(); |
| | for (auto& line : cLines) { |
| | delete line; |
| | } |
| | std::vector<CenterLine*> noLines; |
| | CenterLines.setValues(noLines); |
| | } |
| |
|
| | int CosmeticExtension::add1CLToGE(const std::string& tag) |
| | { |
| | TechDraw::CenterLine* cl = getCenterLine(tag); |
| | if (!cl) { |
| | return -1; |
| | } |
| | TechDraw::BaseGeomPtr scaledGeom = cl->scaledAndRotatedGeometry(getOwner()); |
| | int iGE = getOwner()->getGeometryObject()->addCenterLine(scaledGeom, tag); |
| |
|
| | return iGE; |
| | } |
| |
|
| | |
| | void CosmeticExtension::refreshCLGeoms() |
| | { |
| | 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(); |
| | } |
| |
|
| | |
| | void CosmeticExtension::addCenterLinesToGeom() |
| | { |
| | const std::vector<TechDraw::CenterLine*> lines = CenterLines.getValues(); |
| | for (auto& cl : lines) { |
| | TechDraw::BaseGeomPtr scaledGeom = cl->scaledAndRotatedGeometry(getOwner()); |
| | if (!scaledGeom) { |
| | Base::Console().error("CE::addCenterLinesToGeom - scaledGeometry is null\n"); |
| | continue; |
| | } |
| | |
| | getOwner()->getGeometryObject()->addCenterLine(scaledGeom, cl->getTagAsString()); |
| | } |
| | } |
| |
|
| | |
| | |
| | std::string CosmeticExtension::addCenterLine(Base::Vector3d start, |
| | Base::Vector3d end) |
| | { |
| | std::vector<CenterLine*> cLines = CenterLines.getValues(); |
| | TechDraw::CenterLine* cl = new TechDraw::CenterLine(start, end); |
| | cLines.push_back(cl); |
| | CenterLines.setValues(cLines); |
| | return cl->getTagAsString(); |
| | } |
| |
|
| | std::string CosmeticExtension::addCenterLine(TechDraw::CenterLine* cl) |
| | { |
| | std::vector<CenterLine*> cLines = CenterLines.getValues(); |
| | cLines.push_back(cl); |
| | CenterLines.setValues(cLines); |
| | return cl->getTagAsString(); |
| | } |
| |
|
| |
|
| | std::string CosmeticExtension::addCenterLine(TechDraw::BaseGeomPtr bg) |
| | { |
| | std::vector<CenterLine*> cLines = CenterLines.getValues(); |
| | TechDraw::CenterLine* cl = new TechDraw::CenterLine(bg); |
| | cLines.push_back(cl); |
| | CenterLines.setValues(cLines); |
| | return cl->getTagAsString(); |
| | } |
| |
|
| | |
| | TechDraw::CenterLine* CosmeticExtension::getCenterLine(const std::string& tagString) const |
| | { |
| | const std::vector<TechDraw::CenterLine*> cLines = CenterLines.getValues(); |
| | for (auto& cl: cLines) { |
| | std::string clTag = cl->getTagAsString(); |
| | if (clTag == tagString) { |
| | return cl; |
| | } |
| | } |
| | return nullptr; |
| | } |
| |
|
| | |
| | |
| | TechDraw::CenterLine* CosmeticExtension::getCenterLineBySelection(const std::string& name) const |
| | { |
| | App::DocumentObject* extObj = const_cast<App::DocumentObject*> (getExtendedObject()); |
| | TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(extObj); |
| | if (!dvp) { |
| | return nullptr; |
| | } |
| | int idx = DrawUtil::getIndexFromName(name); |
| | TechDraw::BaseGeomPtr base = dvp->getGeomByIndex(idx); |
| | if (!base || base->getCosmeticTag().empty()) { |
| | return nullptr; |
| | } |
| | return getCenterLine(base->getCosmeticTag()); |
| | } |
| |
|
| | |
| | TechDraw::CenterLine* CosmeticExtension::getCenterLineBySelection(int i) const |
| | { |
| | std::stringstream edgeName; |
| | edgeName << "Edge" << i; |
| | return getCenterLineBySelection(edgeName.str()); |
| | } |
| |
|
| | void CosmeticExtension::removeCenterLine(const std::string& delTag) |
| | { |
| | std::vector<CenterLine*> cLines = CenterLines.getValues(); |
| | std::vector<CenterLine*> newLines; |
| | for (auto& cl: cLines) { |
| | if (cl->getTagAsString() != delTag) { |
| | newLines.push_back(cl); |
| | } |
| | } |
| | CenterLines.setValues(newLines); |
| | } |
| |
|
| | void CosmeticExtension::removeCenterLine(const std::vector<std::string>& delTags) |
| | { |
| | for (auto& t: delTags) { |
| | removeCenterLine(t); |
| | } |
| | } |
| |
|
| |
|
| | |
| |
|
| | void CosmeticExtension::clearGeomFormats() |
| | { |
| | |
| | GeomFormats.setValues({}); |
| | } |
| |
|
| | |
| | |
| | std::string CosmeticExtension::addGeomFormat(TechDraw::GeomFormat* gf) |
| | { |
| | std::vector<GeomFormat*> formats = GeomFormats.getValues(); |
| | TechDraw::GeomFormat* newGF = new TechDraw::GeomFormat(gf); |
| | formats.push_back(newGF); |
| | GeomFormats.setValues(formats); |
| | return newGF->getTagAsString(); |
| | } |
| |
|
| |
|
| | |
| | TechDraw::GeomFormat* CosmeticExtension::getGeomFormat(const std::string& tagString) const |
| | { |
| | const std::vector<TechDraw::GeomFormat*> formats = GeomFormats.getValues(); |
| | for (auto& gf: formats) { |
| | std::string gfTag = gf->getTagAsString(); |
| | if (gfTag == tagString) { |
| | return gf; |
| | } |
| | } |
| |
|
| | |
| | return nullptr; |
| | } |
| |
|
| | |
| | |
| | TechDraw::GeomFormat* CosmeticExtension::getGeomFormatBySelection(const std::string& name) const |
| | { |
| | App::DocumentObject* extObj = const_cast<App::DocumentObject*> (getExtendedObject()); |
| | TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(extObj); |
| | if (!dvp) { |
| | return nullptr; |
| | } |
| | int idx = DrawUtil::getIndexFromName(name); |
| | const std::vector<TechDraw::GeomFormat*> formats = GeomFormats.getValues(); |
| | for (auto& gf: formats) { |
| | if (gf->m_geomIndex == idx) { |
| | return gf; |
| | } |
| | } |
| |
|
| | |
| | return nullptr; |
| | } |
| |
|
| | |
| | TechDraw::GeomFormat* CosmeticExtension::getGeomFormatBySelection(int i) const |
| | { |
| | std::stringstream edgeName; |
| | edgeName << "Edge" << i; |
| | return getGeomFormatBySelection(edgeName.str()); |
| | } |
| |
|
| | void CosmeticExtension::removeGeomFormat(const std::string& delTag) |
| | { |
| | 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) { |
| | if (ExtensionPythonObject.is(Py::_None())){ |
| | |
| | ExtensionPythonObject = Py::Object(new CosmeticExtensionPy(this), true); |
| | } |
| | return Py::new_reference_to(ExtensionPythonObject); |
| | } |
| |
|
| | namespace App { |
| | |
| | EXTENSION_PROPERTY_SOURCE_TEMPLATE(TechDraw::CosmeticExtensionPython, TechDraw::CosmeticExtension) |
| | |
| |
|
| | |
| | template class TechDrawExport ExtensionPythonT<TechDraw::CosmeticExtension>; |
| | } |
| |
|
| |
|
| |
|