diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp
index fb4417e7db..a3feb0332b 100644
--- a/src/Mod/TechDraw/App/Cosmetic.cpp
+++ b/src/Mod/TechDraw/App/Cosmetic.cpp
@@ -149,7 +149,6 @@ CosmeticVertex::CosmeticVertex() : TechDraw::Vertex()
//TODO: sort out 2x visible variables
Vertex::visible = true; //yuck
cosmetic = true;
-
createNewTag();
}
@@ -208,7 +207,8 @@ std::string CosmeticVertex::toString(void) const
" / " <<
style << "," <<
" / " <<
- visible;
+ visible << " / " ;
+ ss << getTagAsString();
return ss.str();
}
@@ -232,6 +232,7 @@ void CosmeticVertex::Save(Base::Writer &writer) const
writer.Stream() << writer.ind() << "" << endl;
const char v = visible?'1':'0';
writer.Stream() << writer.ind() << "" << endl;
+ writer.Stream() << writer.ind() << "" << endl;
}
void CosmeticVertex::Restore(Base::XMLReader &reader)
@@ -252,6 +253,11 @@ void CosmeticVertex::Restore(Base::XMLReader &reader)
style = reader.getAttributeAsInteger("value");
reader.readElement("Visible");
visible = (int)reader.getAttributeAsInteger("value")==0?false:true;
+ reader.readElement("Tag");
+ temp = reader.getAttribute("value");
+ boost::uuids::string_generator gen;
+ boost::uuids::uuid u1 = gen(temp);
+ tag = u1;
}
Base::Vector3d CosmeticVertex::scaled(double factor)
diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h
index 0f7074d619..ed1534c642 100644
--- a/src/Mod/TechDraw/App/Cosmetic.h
+++ b/src/Mod/TechDraw/App/Cosmetic.h
@@ -75,7 +75,6 @@ public:
virtual ~CosmeticVertex() = default;
std::string toString(void) const;
-/* bool fromCSV(std::string& lineSpec);*/
void dump(char* title);
Base::Vector3d scaled(double factor);
@@ -89,7 +88,7 @@ public:
CosmeticVertex* clone(void) const;
Base::Vector3d permaPoint; //permanent, unscaled value
- int linkGeom; //connection to corresponding "geom" Vertex
+ int linkGeom; //connection to corresponding "geom" Vertex (fragile - index based!)
App::Color color;
double size;
int style;
diff --git a/src/Mod/TechDraw/App/DrawDimHelper.cpp b/src/Mod/TechDraw/App/DrawDimHelper.cpp
index a6830eac55..86fd0f9892 100644
--- a/src/Mod/TechDraw/App/DrawDimHelper.cpp
+++ b/src/Mod/TechDraw/App/DrawDimHelper.cpp
@@ -120,6 +120,30 @@ void DrawDimHelper::makeExtentDim(DrawViewPart* dvp,
DrawViewDimExtent* extDim = dynamic_cast(distDim);
extDim->Source.setValue(dvp, edgeNames);
+ std::vector subElements = extDim->References2D.getSubValues();
+ std::vector cvTags;
+ std::string tag0;
+ std::string tag1;
+ TechDraw::Vertex* v0 = nullptr;
+ TechDraw::Vertex* v1 = nullptr;
+ if (subElements.size() > 1) {
+ int idx0 = DrawUtil::getIndexFromName(subElements[0]);
+ int idx1 = DrawUtil::getIndexFromName(subElements[1]);
+ v0 = dvp->getProjVertexByIndex(idx0);
+ v1 = dvp->getProjVertexByIndex(idx1);
+ if ( (v0 != nullptr) &&
+ (!v0->cosmeticTag.empty()) ) {
+ tag0 = v0->cosmeticTag;
+ }
+ if ( (v1 != nullptr) &&
+ (!v1->cosmeticTag.empty()) ) {
+ tag1 = v1->cosmeticTag;
+ }
+ cvTags.push_back(tag0);
+ cvTags.push_back(tag1);
+ extDim->CosmeticTags.setValues(cvTags);
+ }
+
//continue recomputes
dvp->getDocument()->setStatus(App::Document::Status::SkipRecompute, false);
extDim->recomputeFeature();
@@ -315,8 +339,6 @@ DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp,
TechDraw::DrawPage* page = dvp->findParentPage();
std::string pageName = page->getNameInDocument();
- double scale = dvp->getScale();
-
TechDraw::DrawViewDimension *dim = 0;
App::Document* doc = dvp->getDocument();
std::string dimName = doc->getUniqueObjectName("Dimension");
@@ -324,17 +346,15 @@ DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp,
dimName = doc->getUniqueObjectName("DimExtent");
}
- Base::Vector3d cleanMin = DrawUtil::invertY(inMin) / scale;
- int idx1 = dvp->addCosmeticVertex(cleanMin); //CV index
- dvp->add1CVToGV(idx1);
- Base::Vector3d cleanMax = DrawUtil::invertY(inMax) / scale;
- int idx2 = dvp->addCosmeticVertex(cleanMax);
- dvp->add1CVToGV(idx2);
+ double scale = dvp->getScale();
- CosmeticVertex* cv1 = dvp->getCosmeticVertexByIndex(idx1);
- CosmeticVertex* cv2 = dvp->getCosmeticVertexByIndex(idx2);
- int iGV1 = cv1->linkGeom;
- int iGV2 = cv2->linkGeom;
+ //regular dims will have trouble with geom indexes!
+ Base::Vector3d cleanMin = DrawUtil::invertY(inMin) / scale;
+ std::string tag1 = dvp->addCosmeticVertexSS(cleanMin);
+ int iGV1 = dvp->add1CVToGV(tag1);
+ Base::Vector3d cleanMax = DrawUtil::invertY(inMax) / scale;
+ std::string tag2 = dvp->addCosmeticVertexSS(cleanMax);
+ int iGV2 = dvp->add1CVToGV(tag2);
std::vector objs;
std::vector subs;
@@ -346,7 +366,6 @@ DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp,
objs.push_back(dvp);
ss.clear();
- ss.str("");
ss << "Vertex" << iGV2;
vertexName = ss.str();
subs.push_back(vertexName);
@@ -360,12 +379,13 @@ DrawViewDimension* DrawDimHelper::makeDistDim(DrawViewPart* dvp,
Base::Interpreter().runStringArg("App.activeDocument().addObject('TechDraw::DrawViewDimension','%s')",
dimName.c_str());
}
+
Base::Interpreter().runStringArg("App.activeDocument().%s.Type = '%s'",
dimName.c_str(), dimType.c_str());
+
Base::Interpreter().runStringArg("App.activeDocument().%s.addView(App.activeDocument().%s)",
pageName.c_str(),dimName.c_str());
-
dim = dynamic_cast(doc->getObject(dimName.c_str()));
if (!dim) {
throw Base::TypeError("DDH::makeDistDim - dim not found\n");
diff --git a/src/Mod/TechDraw/App/DrawViewDimExtent.cpp b/src/Mod/TechDraw/App/DrawViewDimExtent.cpp
index 6da6cf1369..afc2c103b7 100644
--- a/src/Mod/TechDraw/App/DrawViewDimExtent.cpp
+++ b/src/Mod/TechDraw/App/DrawViewDimExtent.cpp
@@ -74,6 +74,8 @@ DrawViewDimExtent::DrawViewDimExtent(void)
Source3d.setScope(App::LinkScope::Global);
ADD_PROPERTY_TYPE(DirExtent ,(0),"",App::Prop_Output,"Horizontal / Vertical");
+ ADD_PROPERTY_TYPE(CosmeticTags ,(""),"",App::Prop_Output,"Id of cosmetic endpoints");
+
//hide the properties the user can't edit in the property editor
Source3d.setStatus(App::Property::Hidden,true); //TBI
@@ -128,35 +130,34 @@ App::DocumentObjectExecReturn *DrawViewDimExtent::execute(void)
TechDraw::Vertex* v0 = nullptr;
TechDraw::Vertex* v1 = nullptr;
- const std::vector &subElements = References2D.getSubValues();
- if (subElements.size() > 1) {
- int idx0 = DrawUtil::getIndexFromName(subElements[0]);
- int idx1 = DrawUtil::getIndexFromName(subElements[1]);
- v0 = getViewPart()->getProjVertexByIndex(idx0);
- v1 = getViewPart()->getProjVertexByIndex(idx1);
-
- double length00 = (v0->pnt - refMin).Length();
- double length11 = (v1->pnt - refMax).Length();
- double length01 = (v0->pnt - refMax).Length();
- double length10 = (v1->pnt - refMin).Length();
- if ( ((length00 < tolerance) &&
- (length11 < tolerance)) ||
- ((length01 < tolerance) &&
- (length10 < tolerance)) ) {
- } else {
- //update GV
- v0->pnt = refMin;
- v1->pnt = refMax;
- // v0->occVertex = ???
- // v1->occVertex = ???
- //update CV
- double scale = dvp->getScale();
- int cv0 = v0->cosmeticLink;
- CosmeticVertex* cvTemp = dvp->getCosmeticVertexByIndex(cv0);
- cvTemp->permaPoint = refMin / scale;
- int cv1 = v1->cosmeticLink;
- cvTemp = dvp->getCosmeticVertexByIndex(cv1);
- cvTemp->permaPoint = refMax / scale;
+ std::vector cTags = CosmeticTags.getValues();
+ if (cTags.size() > 1) {
+ v0 = dvp->getProjVertexByCosTag(cTags[0]);
+ v1 = dvp->getProjVertexByCosTag(cTags[1]);
+ if ( (v0 != nullptr) &&
+ (v1 != nullptr) ) {
+ double length00 = (v0->pnt - refMin).Length();
+ double length11 = (v1->pnt - refMax).Length();
+ double length01 = (v0->pnt - refMax).Length();
+ double length10 = (v1->pnt - refMin).Length();
+ if ( ((length00 < tolerance) &&
+ (length11 < tolerance)) ||
+ ((length01 < tolerance) &&
+ (length10 < tolerance)) ) {
+ //nothing changed - nop
+ } else {
+ //update GV
+ v0->pnt = refMin;
+ v1->pnt = refMax;
+ // v0->occVertex = ???
+ // v1->occVertex = ???
+ //update CV
+ double scale = dvp->getScale();
+ CosmeticVertex* cvTemp = dvp->getCosmeticVertex(cTags[0]);
+ cvTemp->permaPoint = refMin / scale;
+ cvTemp = dvp->getCosmeticVertex(cTags[1]);
+ cvTemp->permaPoint = refMax / scale;
+ }
}
}
@@ -177,35 +178,67 @@ std::vector DrawViewDimExtent::getSubNames(void)
return result;
}
+pointPair DrawViewDimExtent::getPointsTwoVerts()
+{
+// Base::Console().Message("DVDE::getPointsTwoVerts() - %s\n",getNameInDocument());
+ pointPair result;
+ result.first = Base::Vector3d(0.0, 0.0, 0.0);
+ result.second = Base::Vector3d(0.0, 0.0, 0.0);
+ TechDraw::Vertex* v0 = nullptr;
+ TechDraw::Vertex* v1 = nullptr;
+ TechDraw::DrawViewPart* dvp = getViewPart();
+ if (dvp == nullptr) {
+ return result;
+ }
+
+ std::vector cTags = CosmeticTags.getValues();
+ if (cTags.size() > 1) {
+ v0 = dvp->getProjVertexByCosTag(cTags[0]);
+ v1 = dvp->getProjVertexByCosTag(cTags[1]);
+ if ( (v0 != nullptr) &&
+ (v1 != nullptr) ) {
+ result.first = v0->pnt;
+ result.second = v1->pnt;
+ }
+ }
+ return result;
+}
+
+//! validate 2D references - only checks if the target exists
+bool DrawViewDimExtent::checkReferences2D() const
+{
+// Base::Console().Message("DVDE::checkReFerences2d() - %s\n",getNameInDocument());
+ bool result = false;
+ TechDraw::DrawViewPart* dvp = getViewPart();
+ if (dvp == nullptr) {
+ return result;
+ }
+
+ std::vector cTags = CosmeticTags.getValues();
+ if (cTags.size() > 1) {
+ CosmeticVertex* cv0 = dvp->getCosmeticVertex(cTags[0]);
+ CosmeticVertex* cv1 = dvp->getCosmeticVertex(cTags[1]);
+ if ( (cv0 != nullptr) &&
+ (cv1 != nullptr) ) {
+ result = true;
+ }
+ }
+ return result;
+}
+
void DrawViewDimExtent::unsetupObject()
{
- //CV's need to be deleted, but deleting messes up all the indices to other CV's!
-// TechDraw::DrawViewPart* dvp = getViewPart();
-// std::vector cVerts = dvp->CosmeticVertexes.getValues();
-// Base::Console().Message("DVDE::unsetupObject() - cVerts: %d\n", cVerts.size());
-// TechDraw::Vertex* v0 = nullptr;
-// TechDraw::Vertex* v1 = nullptr;
-// const std::vector &subElements = References2D.getSubValues();
-// if (subElements.size() > 1) {
-// Base::Console().Message("DVDE::unsetupObject - more than 1 subElement\n");
-// int idx1 = DrawUtil::getIndexFromName(subElements[1]);
-// v1 = dvp->getProjVertexByIndex(idx1);
-// if (v1 != nullptr) {
-// int cv1 = v1->cosmeticLink;
-// dvp->removeCosmeticVertex(cv1);
-// }
+// bool isRemoving = testStatus(App::ObjectStatus::Remove);
+// Base::Console().Message("DVDE::unsetupObject - isRemove: %d status: %X\n",
+// isRemoving, getStatus());
+ TechDraw::DrawViewPart* dvp = getViewPart();
-// int idx0 = DrawUtil::getIndexFromName(subElements[0]);
-// v0 = dvp->getProjVertexByIndex(idx0);
-// if (v0 != nullptr) {
-// int cv0 = v0->cosmeticLink;
-// dvp->removeCosmeticVertex(cv0);
-// }
-// }
-// cVerts = dvp->CosmeticVertexes.getValues();
-// Base::Console().Message("DVDE::unsetupObject - exit - cVerts: %d\n", cVerts.size());
+ std::vector cTags = CosmeticTags.getValues();
+ dvp->removeCosmeticVertex(cTags);
DrawViewDimension::unsetupObject();
-// App::DocumentObject::unsetUpObject();
+
+ //dvp probably needs recomp/repaint here.
+ dvp->enforceRecompute();
}
PyObject *DrawViewDimExtent::getPyObject(void)
diff --git a/src/Mod/TechDraw/App/DrawViewDimExtent.h b/src/Mod/TechDraw/App/DrawViewDimExtent.h
index 1fa967a400..15537b0c78 100644
--- a/src/Mod/TechDraw/App/DrawViewDimExtent.h
+++ b/src/Mod/TechDraw/App/DrawViewDimExtent.h
@@ -45,18 +45,21 @@ public:
//Cosmetic End points are stored in DVD::References2d
App::PropertyLinkSubList Source3d; //Part::Feature & SubElements TBI
App::PropertyInteger DirExtent; //Horizontal, Vertical, TBD
+ App::PropertyStringList CosmeticTags; //id of cosmetic end points.
virtual App::DocumentObjectExecReturn *execute(void);
virtual short mustExecute() const;
virtual void unsetupObject();
+ virtual bool checkReferences2D(void) const;
+
//return PyObject as DrawViewDimExtentPy
virtual PyObject *getPyObject(void);
-
protected:
- void onChanged(const App::Property* prop);
+ virtual void onChanged(const App::Property* prop);
std::vector getSubNames(void);
+ virtual pointPair getPointsTwoVerts();
private:
};
diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp
index 4dd1e0ac97..cddb9950f5 100644
--- a/src/Mod/TechDraw/App/DrawViewDimension.cpp
+++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp
@@ -707,7 +707,7 @@ double DrawViewDimension::getDimValue()
} else {
// Projected Values
if (!checkReferences2D()) {
- Base::Console().Warning("DVD::getDimValue - %s - 2D references are corrupt\n",getNameInDocument());
+ Base::Console().Warning("DVD::getDimValue - %s - 2D references are corrupt (5)\n",getNameInDocument());
return result;
}
if ( Type.isValue("Distance") ||
@@ -775,7 +775,7 @@ pointPair DrawViewDimension::getPointsOneEdge()
if (geom && geom->geomType == TechDraw::GeomType::GENERIC) {
gen = static_cast(geom);
} else {
- Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
+ Base::Console().Error("Error: DVD - %s - 2D references are corrupt (1)\n",getNameInDocument());
return result;
}
result.first = gen->points[0];
@@ -795,7 +795,7 @@ pointPair DrawViewDimension::getPointsTwoEdges()
TechDraw::BaseGeom* geom1 = getViewPart()->getGeomByIndex(idx1);
if ((geom0 == nullptr) ||
(geom1 == nullptr) ) {
- Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
+ Base::Console().Error("Error: DVD - %s - 2D references are corrupt (2)\n",getNameInDocument());
return result;
}
result = closestPoints(geom0->occEdge,geom1->occEdge);
@@ -814,7 +814,7 @@ pointPair DrawViewDimension::getPointsTwoVerts()
TechDraw::Vertex* v1 = getViewPart()->getProjVertexByIndex(idx1);
if ((v0 == nullptr) ||
(v1 == nullptr) ) {
- Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
+ Base::Console().Error("Error: DVD - %s - 2D references are corrupt (3)\n",getNameInDocument());
return result;
}
result.first = v0->pnt;
@@ -841,7 +841,7 @@ pointPair DrawViewDimension::getPointsEdgeVert()
}
if ((v == nullptr) ||
(e == nullptr) ) {
- Base::Console().Error("Error: DVD - %s - 2D references are corrupt\n",getNameInDocument());
+ Base::Console().Error("Error: DVD - %s - 2D references are corrupt (4)\n",getNameInDocument());
return result;
}
result = closestPoints(e->occEdge,v->occVertex);
diff --git a/src/Mod/TechDraw/App/DrawViewDimension.h b/src/Mod/TechDraw/App/DrawViewDimension.h
index 93716322b9..44e877d01c 100644
--- a/src/Mod/TechDraw/App/DrawViewDimension.h
+++ b/src/Mod/TechDraw/App/DrawViewDimension.h
@@ -135,7 +135,7 @@ public:
int getRefType() const; //Vertex-Vertex, Edge, Edge-Edge
void setAll3DMeasurement();
void clear3DMeasurements(void);
- bool checkReferences2D(void) const;
+ virtual bool checkReferences2D(void) const;
pointPair getLinearPoints(void) {return m_linearPoints; }
arcPoints getArcPoints(void) {return m_arcPoints; }
anglePoints getAnglePoints(void) {return m_anglePoints; }
@@ -143,16 +143,16 @@ public:
bool references(std::string geomName) const;
protected:
- void onChanged(const App::Property* prop);
+ virtual void onChanged(const App::Property* prop);
virtual void onDocumentRestored();
bool showUnits() const;
bool useDecimals() const;
std::string getPrefix() const;
std::string getDefaultFormatSpec() const;
- pointPair getPointsOneEdge();
- pointPair getPointsTwoEdges();
- pointPair getPointsTwoVerts();
- pointPair getPointsEdgeVert();
+ virtual pointPair getPointsOneEdge();
+ virtual pointPair getPointsTwoEdges();
+ virtual pointPair getPointsTwoVerts();
+ virtual pointPair getPointsEdgeVert();
protected:
Measure::Measurement *measurement;
diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp
index e2699ffc43..67a7c2b763 100644
--- a/src/Mod/TechDraw/App/DrawViewPart.cpp
+++ b/src/Mod/TechDraw/App/DrawViewPart.cpp
@@ -283,7 +283,6 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
getNameInDocument(),diffOut);
#endif //#if MOD_TECHDRAW_HANDLE_FACES
-
return DrawView::execute();
}
@@ -612,6 +611,25 @@ TechDraw::Vertex* DrawViewPart::getProjVertexByIndex(int idx) const
return geoms.at(idx);
}
+TechDraw::Vertex* DrawViewPart::getProjVertexByCosTag(std::string cosTag)
+{
+ TechDraw::Vertex* result = nullptr;
+ std::vector gVerts = getVertexGeometry();
+ if (gVerts.empty()) {
+ Base::Console().Log("INFO - getProjVertexByCosTag(%s) - no Vertex Geometry.\n");
+ return result;
+ }
+
+ for (auto& gv: gVerts) {
+ if (gv->cosmeticTag == cosTag) {
+ result = gv;
+ break;
+ }
+ }
+ return result;
+}
+
+
//! returns existing geometry of 2D Face(idx)
std::vector DrawViewPart::getFaceEdgesByIndex(int idx) const
{
@@ -890,6 +908,8 @@ void DrawViewPart::clearCosmeticVertexes(void)
//returns CosmeticVertex index! not geomVertexNumber!
int DrawViewPart::addCosmeticVertex(Base::Vector3d pos)
{
+// Base::Console().Message("DVP::addCosmeticVertex(%s)\n",
+// DrawUtil::formatVector(pos).c_str());
std::vector verts = CosmeticVertexes.getValues();
Base::Vector3d tempPos = DrawUtil::invertY(pos);
TechDraw::CosmeticVertex* cv = new TechDraw::CosmeticVertex(tempPos);
@@ -899,6 +919,19 @@ int DrawViewPart::addCosmeticVertex(Base::Vector3d pos)
return newIdx;
}
+std::string DrawViewPart::addCosmeticVertexSS(Base::Vector3d pos)
+{
+// Base::Console().Message("DVP::addCosmeticVertexSS(%s)\n",
+ // DrawUtil::formatVector(pos).c_str());
+ std::vector verts = CosmeticVertexes.getValues();
+ Base::Vector3d tempPos = DrawUtil::invertY(pos);
+ TechDraw::CosmeticVertex* cv = new TechDraw::CosmeticVertex(tempPos);
+ verts.push_back(cv);
+ CosmeticVertexes.setValues(verts);
+ std::string result = cv->getTagAsString();
+ return result;
+}
+
int DrawViewPart::addCosmeticVertex(CosmeticVertex* cv)
{
std::vector verts = CosmeticVertexes.getValues();
@@ -910,7 +943,7 @@ int DrawViewPart::addCosmeticVertex(CosmeticVertex* cv)
void DrawViewPart::removeCosmeticVertex(TechDraw::CosmeticVertex* cv)
{
-// Base::Console().Message("DVP::removeCosmeticVertex(cv)\n");
+// Base::Console().Message("DVP::removeCosmeticVertex(%X)\n", cv);
bool found = false;
int i = 0;
std::vector verts = CosmeticVertexes.getValues();
@@ -931,6 +964,7 @@ void DrawViewPart::removeCosmeticVertex(TechDraw::CosmeticVertex* cv)
//this is by CV index, not the index returned by selection
void DrawViewPart::removeCosmeticVertex(int idx)
{
+// Base::Console().Message("DVP::removeCV(%d)\n", idx);
std::vector verts = CosmeticVertexes.getValues();
if (idx < (int) verts.size()) {
verts.erase(verts.begin() + idx);
@@ -939,32 +973,70 @@ void DrawViewPart::removeCosmeticVertex(int idx)
}
}
-void DrawViewPart::replaceCosmeticVertex(int idx, TechDraw::CosmeticVertex* cv)
+void DrawViewPart::removeCosmeticVertex(std::string delTag)
{
- std::vector verts = CosmeticVertexes.getValues();
- if (idx < (int) verts.size()) {
- verts.at(idx) = cv;
- recomputeFeature();
+// Base::Console().Message("DVP::removeCV(%s)\n", delTag.c_str());
+ std::vector cVerts = CosmeticVertexes.getValues();
+ std::vector newVerts;
+ for (auto& cv: cVerts) {
+ if (cv->getTagAsString() != delTag) {
+ newVerts.push_back(cv);
+ }
}
+ CosmeticVertexes.setValues(newVerts);
+// recomputeFeature();
}
-void DrawViewPart::replaceCosmeticVertexByGeom(int geomIndex, TechDraw::CosmeticVertex* cl)
+void DrawViewPart::removeCosmeticVertex(std::vector delTags)
{
- std::vector verts = CosmeticVertexes.getValues();
- int stop = (int) verts.size();
- int i = 0;
- bool found = false;
- if (geomIndex > -1) {
- for ( ; i < stop; i++ ) {
- if (verts.at(i)->linkGeom == geomIndex) {
- found = true;
- break;
+ std::vector cVerts = CosmeticVertexes.getValues();
+// Base::Console().Message("DVP::removeCosmeticVertex(list) - cVerts: %d\n", cVerts.size());
+ std::vector newVerts;
+ for (auto& cv: cVerts) {
+ bool found = false;
+ for (auto& dt: delTags) {
+ if (cv->getTagAsString() == dt) {
+ found = true; //this cv is in delete list
+ break;
}
}
- if (found) {
- replaceCosmeticVertex(i, cl);
+ if (!found) {
+ newVerts.push_back(cv);
}
}
+ CosmeticVertexes.setValues(newVerts);
+}
+
+//transition code. temporary. not used??
+int DrawViewPart::getCosmeticVertexIndex(std::string tagString)
+{
+ Base::Console().Message("DVP::getCosmeticVertexIndex(%s) - deprec?\n", tagString.c_str());
+ int result = -1;
+ int iCV = 0;
+ const std::vector verts = CosmeticVertexes.getValues();
+ for (auto& cv: verts) {
+ std::string cvTag = cv->getTagAsString();
+ if (cvTag == tagString) {
+ result = iCV;
+ break;
+ }
+ iCV++;
+ }
+ return result;
+}
+
+TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertex(std::string tagString) const
+{
+ CosmeticVertex* result = nullptr;
+ const std::vector verts = CosmeticVertexes.getValues();
+ for (auto& cv: verts) {
+ std::string cvTag = cv->getTagAsString();
+ if (cvTag == tagString) {
+ result = cv;
+ break;
+ }
+ }
+ return result;
}
TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByIndex(int idx) const
@@ -983,19 +1055,12 @@ TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByGeom(int idx) const
{
CosmeticVertex* result = nullptr;
std::vector verts = CosmeticVertexes.getValues();
- int stop = (int) verts.size();
- int i = 0;
- bool found = false;
- if (idx > -1) {
- for ( ; i < stop; i++ ) {
- if (verts.at(i)->linkGeom == idx) {
- found = true;
- break;
- }
- }
- if (found) {
- result = verts.at(i);
- }
+ TechDraw::Vertex* v = getProjVertexByIndex(idx);
+ if (v == nullptr) {
+ return result;
+ }
+ if (!v->cosmeticTag.empty()) {
+ result = getCosmeticVertex(v->cosmeticTag);
}
return result;
}
@@ -1009,33 +1074,38 @@ void DrawViewPart::addCosmeticVertexesToGeom(void)
const std::vector gVerts = getVertexGeometry();
int stop = (int) cVerts.size();
for ( ; iCV < stop; iCV++) {
- int iGV = geometryObject->addCosmeticVertex(cVerts.at(iCV)->scaled(getScale()), 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;
}
}
int DrawViewPart::add1CVToGV(int iCV)
{
-// Base::Console().Message("DVP::add1CVToGV(%d)\n", iCV);
+ Base::Console().Message("DVP::add1CVToGV(%d) 1 - deprec?\n", iCV);
TechDraw::CosmeticVertex* cv = getCosmeticVertexByIndex(iCV);
- int iGV = geometryObject->addCosmeticVertex(cv->scaled(getScale()), iCV);
+ int iGV = geometryObject->addCosmeticVertex(cv->scaled(getScale()),
+ cv->getTagAsString(),
+ iCV);
cv->linkGeom = iGV;
return iGV;
}
-//given a CosmeticVertex's index, return the corresponding geometry vertex's index
-int DrawViewPart::convertCosmeticVertexIndex(int iCV)
+int DrawViewPart::add1CVToGV(std::string tag)
{
-// Base::Console().Message("DVP::convertCosmeticVertexIndex(%d)\n",iCV);
- int result = -1;
- if (geometryObject != nullptr) {
- std::vector cVerts = CosmeticVertexes.getValues();
- TechDraw::CosmeticVertex* cv = cVerts.at(iCV);
- int temp = cv->linkGeom;
- result = temp;
- //could double check with tag comparison
+// Base::Console().Message("DVP::add1CVToGV(%s) 2\n", tag.c_str());
+ TechDraw::CosmeticVertex* cv = getCosmeticVertex(tag);
+ if (cv == nullptr) {
+ Base::Console().Message("DVP::add1CVToGV 2 - cv %s not found\n", tag.c_str());
}
- return result;
+// int iCV = getCosmeticVertexIndex(tag); //transition
+ int iCV = -1;
+ int iGV = geometryObject->addCosmeticVertex(cv->scaled(getScale()),
+ cv->getTagAsString(),
+ iCV);
+ cv->linkGeom = iGV;
+ return iGV;
}
//CosmeticEdges -------------------------------------------------------------------
@@ -1368,6 +1438,17 @@ void DrawViewPart::dumpVerts(std::string text)
}
}
+void DrawViewPart::dumpCosVerts(std::string text)
+{
+ std::vector cVerts = CosmeticVertexes.getValues();
+ Base::Console().Message("%s - dumping %d CosmeticVertexes\n",
+ text.c_str(), cVerts.size());
+ for (auto& cv: cVerts) {
+ cv->dump("a CV");
+ }
+}
+
+
void DrawViewPart::onDocumentRestored()
{
// requestPaint();
diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h
index 389f420bfc..debca7063d 100644
--- a/src/Mod/TechDraw/App/DrawViewPart.h
+++ b/src/Mod/TechDraw/App/DrawViewPart.h
@@ -137,6 +137,7 @@ public:
TechDraw::BaseGeom* getGeomByIndex(int idx) const; //get existing geom for edge idx in projection
TechDraw::Vertex* getProjVertexByIndex(int idx) const; //get existing geom for vertex idx in projection
+ TechDraw::Vertex* getProjVertexByCosTag(std::string cosTag);
std::vector getFaceEdgesByIndex(int idx) const; //get edges for face idx in projection
virtual Base::BoundBox3d getBoundingBox() const;
@@ -171,17 +172,21 @@ public:
virtual int addCosmeticVertex(Base::Vector3d pos);
virtual int addCosmeticVertex(CosmeticVertex* cv);
+ std::string addCosmeticVertexSS(Base::Vector3d pos);
virtual void removeCosmeticVertex(TechDraw::CosmeticVertex* cv);
virtual void removeCosmeticVertex(int idx);
- void replaceCosmeticVertex(int idx, TechDraw::CosmeticVertex* cv);
- void replaceCosmeticVertexByGeom(int geomIndex, TechDraw::CosmeticVertex* cl);
+ virtual void removeCosmeticVertex(std::string tagString);
+ virtual void removeCosmeticVertex(std::vector delTags);
+
+ int getCosmeticVertexIndex(std::string tagString);
+ TechDraw::CosmeticVertex* getCosmeticVertex(std::string tagString) const;
TechDraw::CosmeticVertex* getCosmeticVertexByIndex(int idx) const;
TechDraw::CosmeticVertex* getCosmeticVertexByGeom(int idx) const;
void clearCosmeticVertexes(void);
void addCosmeticVertexesToGeom(void);
void add1CosmeticVertexToGeom(int iCV);
- int convertCosmeticVertexIndex(int idx);
int add1CVToGV(int iCV);
+ int add1CVToGV(std::string tag);
virtual int addCosmeticEdge(Base::Vector3d start, Base::Vector3d end);
@@ -214,6 +219,7 @@ public:
void clearGeomFormats(void);
void dumpVerts(std::string text);
+ void dumpCosVerts(std::string text);
protected:
TechDraw::GeometryObject *geometryObject;
diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp
index 236cc8ff7f..08e3fcda6a 100644
--- a/src/Mod/TechDraw/App/Geometry.cpp
+++ b/src/Mod/TechDraw/App/Geometry.cpp
@@ -1310,6 +1310,7 @@ Vertex::Vertex()
occVertex = mkVert.Vertex();
cosmetic = false;
cosmeticLink = -1;
+ cosmeticTag = std::string();
}
Vertex::Vertex(const Vertex* v)
@@ -1322,6 +1323,7 @@ Vertex::Vertex(const Vertex* v)
occVertex = v->occVertex;
cosmetic = v->cosmetic;
cosmeticLink = v->cosmeticLink;
+ cosmeticTag = v->cosmeticTag;
}
Vertex::Vertex(double x, double y)
@@ -1335,6 +1337,7 @@ Vertex::Vertex(double x, double y)
occVertex = mkVert.Vertex();
cosmetic = false;
cosmeticLink = -1;
+ cosmeticTag = std::string();
}
Vertex::Vertex(Base::Vector3d v) : Vertex(v.x,v.y)
@@ -1371,6 +1374,8 @@ void Vertex::Save(Base::Writer &writer) const
const char c2 = cosmetic?'1':'0';
writer.Stream() << writer.ind() << "" << endl;
writer.Stream() << writer.ind() << "" << endl;
+ writer.Stream() << writer.ind() << "" << endl;
+ writer.Stream() << writer.ind() << "" << endl;
}
void Vertex::Restore(Base::XMLReader &reader)
@@ -1392,15 +1397,34 @@ void Vertex::Restore(Base::XMLReader &reader)
cosmetic = (bool)reader.getAttributeAsInteger("value")==0?false:true;
reader.readElement("CosmeticLink");
cosmeticLink = reader.getAttributeAsInteger("value");
+ reader.readElement("CosmeticTag");
+ cosmeticTag = reader.getAttribute("value");
+ reader.readElement("Tag");
+ std::string temp = reader.getAttribute("value");
+ boost::uuids::string_generator gen;
+ boost::uuids::uuid u1 = gen(temp);
+ tag = u1;
BRepBuilderAPI_MakeVertex mkVert(gp_Pnt(pnt.x, pnt.y, pnt.z));
occVertex = mkVert.Vertex();
}
+boost::uuids::uuid Vertex::getTag() const
+{
+ return tag;
+}
+
+std::string Vertex::getTagAsString(void) const
+{
+ std::string tmp = boost::uuids::to_string(getTag());
+ return tmp;
+}
+
void Vertex::dump()
{
- Base::Console().Message("TD::Vertex point: %s vis: %d cosmetic: %d cosLink: %d\n",
- DrawUtil::formatVector(pnt).c_str(), visible, cosmetic, cosmeticLink);
+ Base::Console().Message("TD::Vertex point: %s vis: %d cosmetic: %d cosLink: %d cosTag: %s\n",
+ DrawUtil::formatVector(pnt).c_str(), visible, cosmetic, cosmeticLink,
+ cosmeticTag.c_str());
}
diff --git a/src/Mod/TechDraw/App/Geometry.h b/src/Mod/TechDraw/App/Geometry.h
index db7ea02590..df5ca43273 100644
--- a/src/Mod/TechDraw/App/Geometry.h
+++ b/src/Mod/TechDraw/App/Geometry.h
@@ -24,6 +24,8 @@
#define TECHDRAW_GEOMETRY_H
#include
+#include
+#include
#include
#include
@@ -288,7 +290,6 @@ class TechDrawExport Vertex
virtual void Save(Base::Writer &/*writer*/) const;
virtual void Restore(Base::XMLReader &/*reader*/);
- virtual std::string getTagAsString() const { return std::string(); }
virtual void dump();
Base::Vector3d pnt;
@@ -301,12 +302,21 @@ class TechDrawExport Vertex
Base::Vector3d point(void) const { return Base::Vector3d(pnt.x,pnt.y,0.0); }
void point(Base::Vector3d v){ pnt = Base::Vector3d(v.x, v.y); }
bool cosmetic;
- int cosmeticLink;
- boost::uuids::uuid cosmeticTag;
-
+ int cosmeticLink; //deprec. use cosmeticTag
+ std::string cosmeticTag;
double x() {return pnt.x;}
double y() {return pnt.y;}
+
+ boost::uuids::uuid getTag() const;
+ virtual std::string getTagAsString(void) const;
+
+ protected:
+ //Uniqueness
+ void createNewTag();
+ void assignTag(const TechDraw::Vertex* v);
+
+ boost::uuids::uuid tag;
};
/// Encapsulates some useful static methods
diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp
index 2d3ca40375..7a219621d0 100644
--- a/src/Mod/TechDraw/App/GeometryObject.cpp
+++ b/src/Mod/TechDraw/App/GeometryObject.cpp
@@ -477,9 +477,24 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca
//adds a new GeomVert to list for cv[link]
int GeometryObject::addCosmeticVertex(Base::Vector3d pos, int link)
{
+ 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->visible = true;
+ int idx = vertexGeom.size();
+ vertexGeom.push_back(v);
+ return idx;
+}
+
+int GeometryObject::addCosmeticVertex(Base::Vector3d pos, std::string tagString, int link)
+{
+// 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->visible = true;
int idx = vertexGeom.size();
vertexGeom.push_back(v);
diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h
index 34fbe9ff4a..1dc52e6785 100644
--- a/src/Mod/TechDraw/App/GeometryObject.h
+++ b/src/Mod/TechDraw/App/GeometryObject.h
@@ -135,12 +135,9 @@ public:
//Are removeXXXXX functions really needed for GO?
int addCosmeticVertex(Base::Vector3d pos, int link = -1);
-/* void removeCosmeticVertex(TechDraw::CosmeticVertex* cv);*/
-/* void removeCosmeticVertex(int idx);*/
+ int addCosmeticVertex(Base::Vector3d pos, std::string tagString, int link = -1);
int addCosmeticEdge(TechDraw::BaseGeom* bg, int s = 0, int si = -1);
int addCenterLine(TechDraw::BaseGeom* bg, int s = 0, int si = -1);
-/* void removeCosmeticEdge(TechDraw::CosmeticEdge* ce);*/
-/* void removeCosmeticEdge(int idx);*/
protected:
//HLR output
diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp
index 15cd655d78..5215a5dc92 100644
--- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp
+++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp
@@ -1076,7 +1076,7 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg)
objFeat = static_cast ((*itSel).getObject());
SubNames = (*itSel).getSubNames();
}
- std::vector cv2Delete;
+ std::vector cv2Delete;
std::vector ce2Delete;
std::vector cl2Delete;
for (auto& s: SubNames) {
@@ -1098,11 +1098,13 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg)
}
}
} else if (geomType == "Vertex") {
+ //TODO: delete by tag
TechDraw::Vertex* tdv = objFeat->getProjVertexByIndex(idx);
if (tdv != nullptr) {
- int delIndex = tdv->cosmeticLink;
- if (!(delIndex < 0)) {
- cv2Delete.push_back(delIndex);
+// int delIndex = tdv->cosmeticLink;
+ std::string delTag = tdv->cosmeticTag;
+ if (!delTag.empty()) {
+ cv2Delete.push_back(delTag);
} else {
Base::Console().Message("CMD::eraser - geom: %d has no cv\n", idx);
}
@@ -1116,14 +1118,13 @@ void CmdTechDrawCosmeticEraser::activated(int iMsg)
}
}
- // delete items in reverse order so as not to invalidate indices
if (!cv2Delete.empty()) {
- std::sort(cv2Delete.begin(), cv2Delete.end());
- auto it = cv2Delete.rbegin();
- for ( ; it != cv2Delete.rend(); it++) {
- objFeat->removeCosmeticVertex((*it));
+ for (auto& cvTag: cv2Delete) {
+ objFeat->removeCosmeticVertex(cvTag);
}
+ objFeat->enforceRecompute();
}
+
if (!ce2Delete.empty()) {
std::sort(ce2Delete.begin(), ce2Delete.end());
auto itce = ce2Delete.rbegin();