[TD] Landmark Dim minor clean ups

- clean up reference vertices on delete

- protect fail on close empty Page

- hide unimplemented functions
This commit is contained in:
wandererfan
2020-02-26 09:35:30 -05:00
committed by WandererFan
parent 75dea4bc24
commit fd240e9ea2
5 changed files with 71 additions and 30 deletions

View File

@@ -335,6 +335,9 @@ void DrawViewPart::partExec(TopoDS_Shape shape)
{
// Base::Console().Message("DVP::partExec()\n");
geometryObject = makeGeometryForShape(shape);
if (geometryObject == nullptr) {
return;
}
#if MOD_TECHDRAW_HANDLE_FACES
// auto start = std::chrono::high_resolution_clock::now();
@@ -347,7 +350,7 @@ void DrawViewPart::partExec(TopoDS_Shape shape)
}
}
#endif //#if MOD_TECHDRAW_HANDLE_FACES
std::vector<TechDraw::Vertex*> verts = getVertexGeometry();
// std::vector<TechDraw::Vertex*> verts = getVertexGeometry();
addCosmeticVertexesToGeom();
addCosmeticEdgesToGeom();
addCenterLinesToGeom();
@@ -486,6 +489,9 @@ TechDraw::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape,
//! make faces from the existing edge geometry
void DrawViewPart::extractFaces()
{
if (geometryObject == nullptr) {
return;
}
geometryObject->clearFaceGeom();
const std::vector<TechDraw::BaseGeom*>& goEdges =
geometryObject->getVisibleFaceEdges(SmoothVisible.getValue(),SeamVisible.getValue());
@@ -668,18 +674,29 @@ std::vector<TechDraw::DrawViewBalloon*> DrawViewPart::getBalloons() const
const std::vector<TechDraw::Vertex *> DrawViewPart::getVertexGeometry() const
{
std::vector<TechDraw::Vertex*> gVerts = geometryObject->getVertexGeometry();
return gVerts;
std::vector<TechDraw::Vertex *> result;
if (geometryObject != nullptr) {
result = geometryObject->getVertexGeometry();
}
return result;
}
const std::vector<TechDraw::Face *> & DrawViewPart::getFaceGeometry() const
const std::vector<TechDraw::Face *> DrawViewPart::getFaceGeometry() const
{
return geometryObject->getFaceGeometry();
std::vector<TechDraw::Face*> result;
if (geometryObject != nullptr) {
result = geometryObject->getFaceGeometry();
}
return result;
}
const std::vector<TechDraw::BaseGeom *> & DrawViewPart::getEdgeGeometry() const
const std::vector<TechDraw::BaseGeom*> DrawViewPart::getEdgeGeometry() const
{
return geometryObject->getEdgeGeometry();
std::vector<TechDraw::BaseGeom *> result;
if (geometryObject != nullptr) {
result = geometryObject->getEdgeGeometry();
}
return result;
}
//! returns existing BaseGeom of 2D Edge(idx)
@@ -1113,20 +1130,23 @@ void DrawViewPart::removeReferenceVertex(std::string tag)
// delete v; //??? who deletes v?
}
}
m_referenceVerts = newRefVerts;
resetReferenceVerts();
}
void DrawViewPart::removeAllReferencesFromGeom()
{
// Base::Console().Message("DVP::removeAllReferencesFromGeom()\n");
std::vector<TechDraw::Vertex *> gVerts = getVertexGeometry();
std::vector<TechDraw::Vertex *> newVerts;
for (auto& gv: gVerts) {
if (!gv->reference) {
newVerts.push_back(gv);
if (!m_referenceVerts.empty()) {
std::vector<TechDraw::Vertex *> gVerts = getVertexGeometry();
std::vector<TechDraw::Vertex *> newVerts;
for (auto& gv: gVerts) {
if (!gv->reference) {
newVerts.push_back(gv);
}
}
getGeometryObject()->setVertexGeometry(newVerts);
}
getGeometryObject()->setVertexGeometry(newVerts);
}
void DrawViewPart::resetReferenceVerts()

View File

@@ -124,10 +124,10 @@ public:
std::vector<TechDraw::DrawViewDimension*> getDimensions() const;
std::vector<TechDraw::DrawViewBalloon*> getBalloons() const;
const std::vector<TechDraw::Vertex *> getVertexGeometry() const;
const std::vector<TechDraw::BaseGeom *> & getEdgeGeometry() const;
const std::vector<TechDraw::BaseGeom *> getVisibleFaceEdges() const;
const std::vector<TechDraw::Face *> & getFaceGeometry() const;
const std::vector<TechDraw::Vertex*> getVertexGeometry() const;
const std::vector<TechDraw::BaseGeom*> getEdgeGeometry() const;
const std::vector<TechDraw::BaseGeom*> getVisibleFaceEdges() const;
const std::vector<TechDraw::Face*> getFaceGeometry() const;
bool hasGeometry(void) const;
TechDraw::GeometryObject* getGeometryObject(void) const { return geometryObject; }

View File

@@ -115,7 +115,7 @@ App::DocumentObjectExecReturn *LandmarkDimension::execute(void)
std::vector<DocumentObject*> features = References3D.getValues();
//if distance, required size = 2
//if angle, required size = 3;
//if angle, required size = 3; //not implemented yet
unsigned int requiredSize = 2;
if (features.size() < requiredSize) {
return App::DocumentObject::StdReturn;
@@ -147,7 +147,7 @@ App::DocumentObjectExecReturn *LandmarkDimension::execute(void)
m_linearPoints.first = points.front();
m_linearPoints.second = points.back();
//m_anglePoints.first =
//m_anglePoints.first = //not implemented yet
App::DocumentObjectExecReturn* dvdResult = DrawViewDimension::execute();
@@ -258,6 +258,23 @@ void LandmarkDimension::onDocumentRestored()
DrawViewDimension::onDocumentRestored();
}
void LandmarkDimension::unsetupObject()
{
// bool isRemoving = testStatus(App::ObjectStatus::Remove);
// Base::Console().Message("LD::unsetupObject - isRemove: %d status: %X\n",
// isRemoving, getStatus());
TechDraw::DrawViewPart* dvp = getViewPart();
std::vector<std::string> tags = ReferenceTags.getValues();
for (auto& t: tags) {
dvp->removeReferenceVertex(t);
}
dvp->resetReferenceVerts();
dvp->requestPaint();
}
//??? why does getPyObject work sometimes and no others???
//PyObject *LandmarkDimension::getPyObject(void)
//{

View File

@@ -52,6 +52,8 @@ public:
virtual App::DocumentObjectExecReturn *execute(void) override;
short mustExecute() const override;
virtual void unsetupObject() override;
virtual const char* getViewProviderName(void) const override {
return "TechDrawGui::ViewProviderDimension"; }
/* virtual PyObject *getPyObject(void) override;*/

View File

@@ -1360,16 +1360,15 @@ CmdTechDrawLandmarkDimension::CmdTechDrawLandmarkDimension()
void CmdTechDrawLandmarkDimension::activated(int iMsg)
{
Q_UNUSED(iMsg);
bool result = _checkSelection(this,3); //redundant??
bool result = _checkSelection(this,3);
if (!result)
return;
const std::vector<App::DocumentObject*> objects = getSelection().
getObjectsOfType(Part::Feature::getClassTypeId()); //??
if ( (objects.size() != 2) &&
(objects.size() != 3) ) {
if (objects.size() != 2) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select 2 or 3 point objects and 1 View. (1)"));
QObject::tr("Select 2 point objects and 1 View. (1)"));
return;
}
@@ -1377,7 +1376,7 @@ void CmdTechDrawLandmarkDimension::activated(int iMsg)
getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId());
if (views.size() != 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select 2 or 3 two point objects and 1 View. (2)"));
QObject::tr("Select 2 point objects and 1 View. (2)"));
return;
}
@@ -1403,13 +1402,16 @@ void CmdTechDrawLandmarkDimension::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str(), "Distance");
refs2d.push_back(dvp);
refs2d.push_back(dvp);
} else if (objects.size() == 3) {
doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str(), "Angle3Pt");
refs2d.push_back(dvp);
refs2d.push_back(dvp);
refs2d.push_back(dvp);
subs.push_back("Vertex1");
}
// } else if (objects.size() == 3) { //not implemented yet
// doCommand(Doc,"App.activeDocument().%s.Type = '%s'",FeatName.c_str(), "Angle3Pt");
// refs2d.push_back(dvp);
// refs2d.push_back(dvp);
// refs2d.push_back(dvp);
// //subs.push_back("Vertex1");
// //subs.push_back("Vertex1");
// //subs.push_back("Vertex1");
// }
dim = dynamic_cast<TechDraw::LandmarkDimension *>(getDocument()->getObject(FeatName.c_str()));
if (!dim) {