Skip to content

Commit

Permalink
[TD] Landmark Dim minor clean ups
Browse files Browse the repository at this point in the history
- clean up reference vertices on delete

- protect fail on close empty Page

- hide unimplemented functions
  • Loading branch information
WandererFan committed Feb 27, 2020
1 parent 233453c commit 8533527
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 30 deletions.
46 changes: 33 additions & 13 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/TechDraw/App/DrawViewPart.h
Expand Up @@ -124,10 +124,10 @@ class TechDrawExport DrawViewPart : public DrawView, public CosmeticExtension
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; }
Expand Down
21 changes: 19 additions & 2 deletions src/Mod/TechDraw/App/LandmarkDimension.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
//{
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/LandmarkDimension.h
Expand Up @@ -52,6 +52,8 @@ class TechDrawExport LandmarkDimension : public TechDraw::DrawViewDimension

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;*/
Expand Down
24 changes: 13 additions & 11 deletions src/Mod/TechDraw/Gui/CommandCreateDims.cpp
Expand Up @@ -1360,24 +1360,23 @@ 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;
}

const std::vector<App::DocumentObject*> views = getSelection().
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;
}

Expand All @@ -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) {
Expand Down

0 comments on commit 8533527

Please sign in to comment.