From 96e8f752be1be5881cd994093c9e84c8a5176a3e Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sun, 16 Feb 2020 13:37:43 -0500 Subject: [PATCH] [TD]Landmark Dims initial impl --- src/Mod/TechDraw/App/AppTechDraw.cpp | 2 + src/Mod/TechDraw/App/CMakeLists.txt | 2 + src/Mod/TechDraw/App/Cosmetic.cpp | 10 + src/Mod/TechDraw/App/Cosmetic.h | 3 + src/Mod/TechDraw/App/DrawView.cpp | 2 +- src/Mod/TechDraw/App/DrawView.h | 4 +- src/Mod/TechDraw/App/DrawViewDimension.cpp | 75 ++--- src/Mod/TechDraw/App/DrawViewDimension.h | 23 +- src/Mod/TechDraw/App/DrawViewPart.cpp | 182 +++++++++++- src/Mod/TechDraw/App/DrawViewPart.h | 14 + src/Mod/TechDraw/App/Geometry.cpp | 13 + src/Mod/TechDraw/App/Geometry.h | 1 + src/Mod/TechDraw/App/GeometryObject.cpp | 10 + src/Mod/TechDraw/App/GeometryObject.h | 4 + src/Mod/TechDraw/App/LandmarkDimension.cpp | 258 ++++++++++++++++ src/Mod/TechDraw/App/LandmarkDimension.h | 78 +++++ src/Mod/TechDraw/App/ShapeExtractor.cpp | 125 +++++++- src/Mod/TechDraw/App/ShapeExtractor.h | 13 +- src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 97 ++++++ src/Mod/TechDraw/Gui/QGVPage.cpp | 15 +- src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 1 + .../icons/techdraw-landmarkdistance.svg | 277 ++++++++++++++++++ .../TechDraw/Gui/ViewProviderDimension.cpp | 6 + src/Mod/TechDraw/Gui/Workbench.cpp | 52 ++-- 24 files changed, 1177 insertions(+), 90 deletions(-) create mode 100644 src/Mod/TechDraw/App/LandmarkDimension.cpp create mode 100644 src/Mod/TechDraw/App/LandmarkDimension.h create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/techdraw-landmarkdistance.svg diff --git a/src/Mod/TechDraw/App/AppTechDraw.cpp b/src/Mod/TechDraw/App/AppTechDraw.cpp index 7a1a1fc7c0..80dbc32d4c 100644 --- a/src/Mod/TechDraw/App/AppTechDraw.cpp +++ b/src/Mod/TechDraw/App/AppTechDraw.cpp @@ -28,6 +28,7 @@ #include "DrawViewAnnotation.h" #include "DrawViewDimension.h" #include "DrawViewDimExtent.h" +#include "LandmarkDimension.h" #include "DrawProjGroupItem.h" #include "DrawProjGroup.h" #include "DrawViewSymbol.h" @@ -85,6 +86,7 @@ PyMOD_INIT_FUNC(TechDraw) TechDraw::DrawViewMulti ::init(); TechDraw::DrawViewDimension ::init(); TechDraw::DrawViewDimExtent ::init(); + TechDraw::LandmarkDimension ::init(); TechDraw::DrawProjGroup ::init(); TechDraw::DrawProjGroupItem ::init(); TechDraw::DrawViewDetail ::init(); diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 7f5ffdfb4a..f8d3ec889f 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -100,6 +100,8 @@ SET(Draw_SRCS DrawViewDimension.h DrawViewDimExtent.cpp DrawViewDimExtent.h + LandmarkDimension.cpp + LandmarkDimension.h DrawViewBalloon.cpp DrawViewBalloon.h DrawViewSection.cpp diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index ae74470f6e..01f3aea3f9 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -191,6 +191,16 @@ CosmeticVertex::CosmeticVertex(Base::Vector3d loc) : TechDraw::Vertex(loc) } +void CosmeticVertex::move(Base::Vector3d newPos) +{ + permaPoint = newPos; +} + +void CosmeticVertex::moveRelative(Base::Vector3d movement) +{ + permaPoint += movement; +} + std::string CosmeticVertex::toString(void) const { std::stringstream ss; diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index 1c3591723e..961e753c54 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -77,6 +77,9 @@ public: CosmeticVertex(Base::Vector3d loc); virtual ~CosmeticVertex() = default; + void move(Base::Vector3d newPos); + void moveRelative(Base::Vector3d movement); + std::string toString(void) const; void dump(const char* title); Base::Vector3d scaled(double factor); diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 39f8407ff0..85f7c47125 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -434,6 +434,7 @@ void DrawView::handleChangedPropertyType( bool DrawView::keepUpdated(void) { +// Base::Console().Message("DV::keepUpdated() - %s\n", getNameInDocument()); bool result = false; bool pageUpdate = false; @@ -455,7 +456,6 @@ bool DrawView::keepUpdated(void) if (force) { //when do we turn this off?? result = true; } - return result; } diff --git a/src/Mod/TechDraw/App/DrawView.h b/src/Mod/TechDraw/App/DrawView.h index d7f3c0838e..58622db736 100644 --- a/src/Mod/TechDraw/App/DrawView.h +++ b/src/Mod/TechDraw/App/DrawView.h @@ -25,6 +25,7 @@ #include +#include #include #include @@ -45,6 +46,7 @@ class DrawLeaderLine; */ class TechDrawExport DrawView : public App::DocumentObject { + Q_DECLARE_TR_FUNCTIONS(TechDraw::DrawView); PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawView); public: @@ -88,7 +90,7 @@ public: virtual bool checkFit(void) const; virtual bool checkFit(DrawPage*) const; virtual void setPosition(double x, double y, bool force = false); - bool keepUpdated(void); + virtual bool keepUpdated(void); boost::signals2::signal signalGuiPaint; virtual double getScale(void) const; void checkScale(void); diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 2c5d14cd74..52e9c71dd0 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -82,15 +82,6 @@ const char* DrawViewDimension::MeasureTypeEnums[]= {"True", "Projected", NULL}; -enum RefType{ - invalidRef, - oneEdge, - twoEdge, - twoVertex, - vertexEdge, - threeVertex - }; - DrawViewDimension::DrawViewDimension(void) { ADD_PROPERTY_TYPE(References2D,(0,0),"",(App::Prop_None),"Projected Geometry References"); @@ -98,7 +89,7 @@ DrawViewDimension::DrawViewDimension(void) ADD_PROPERTY_TYPE(References3D,(0,0),"",(App::Prop_None),"3D Geometry References"); References3D.setScope(App::LinkScope::Global); - ADD_PROPERTY_TYPE(FormatSpec,("") , "Format", App::Prop_Output,"Dimension Format"); + ADD_PROPERTY_TYPE(FormatSpec,(getDefaultFormatSpec()) , "Format", App::Prop_Output,"Dimension Format"); ADD_PROPERTY_TYPE(Arbitrary,(false) ,"Format", App::Prop_Output,"Value overridden by user"); Type.setEnums(TypeEnums); //dimension type: length, radius etc @@ -112,7 +103,7 @@ DrawViewDimension::DrawViewDimension(void) //hide the properties the user can't edit in the property editor // References2D.setStatus(App::Property::Hidden,true); - References3D.setStatus(App::Property::Hidden,true); +// References3D.setStatus(App::Property::Hidden,true); //hide the DrawView properties that don't apply to Dimensions ScaleType.setStatus(App::Property::ReadOnly,true); @@ -161,6 +152,7 @@ void DrawViewDimension::onChanged(const App::Property* prop) MeasureType.setValue("Projected"); } } else if (prop == &References3D) { //have to rebuild the Measurement object +// Base::Console().Message("DVD::onChanged - References3D\n"); clear3DMeasurements(); //Measurement object if (!(References3D.getValues()).empty()) { setAll3DMeasurement(); @@ -219,14 +211,12 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) // Base::Console().Message("DVD::execute() - %s\n", getNameInDocument()); if (!keepUpdated()) { return App::DocumentObject::StdReturn; - } - DrawViewPart* dvp = getViewPart(); - if (dvp == nullptr) { - Base::Console().Message("DVD::execute - no DVP!\n"); - return App::DocumentObject::StdReturn; + } + DrawViewPart* dvp = getViewPart(); + if (dvp == nullptr) { + return App::DocumentObject::StdReturn; } - //any empty Reference2D?? if (!has2DReferences()) { //too soon? if (isRestoring() || getDocument()->testStatus(App::Document::Status::Restoring)) { @@ -243,7 +233,6 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) getDocument()->testStatus(App::Document::Status::Restoring)) { return App::DocumentObject::StdReturn; } else { - Base::Console().Warning("%s - target has no geometry\n", getNameInDocument()); return App::DocumentObject::StdReturn; } } @@ -259,7 +248,6 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) if ( Type.isValue("Distance") || Type.isValue("DistanceX") || Type.isValue("DistanceY") ) { - if (getRefType() == oneEdge) { m_linearPoints = getPointsOneEdge(); }else if (getRefType() == twoEdge) { @@ -721,9 +709,9 @@ double DrawViewDimension::getDimValue() } return result; } - if (getViewPart() == nullptr) { - return result; - } + if (getViewPart() == nullptr) { + return result; + } if (!getViewPart()->hasGeometry() ) { //happens when loading saved document return result; @@ -802,7 +790,6 @@ double DrawViewDimension::getDimValue() result = -result; } } - return result; } @@ -1226,27 +1213,27 @@ std::string DrawViewDimension::getDefaultFormatSpec() const return Base::Tools::toStdString(formatSpec); } -//! is refName a target of this Dim (2D references) -bool DrawViewDimension::references(std::string refName) const -{ - Base::Console().Message("DVD::references(%s) - %s\n",refName.c_str(),getNameInDocument()); - bool result = false; - const std::vector &objects = References2D.getValues(); - if (!objects.empty()) { - const std::vector &subElements = References2D.getSubValues(); - if (!subElements.empty()) { - for (auto& s: subElements) { - if (!s.empty()) { - if (s == refName) { - result = true; - break; - } - } - } - } - } - return result; -} +////! is refName a target of this Dim (2D references) +//bool DrawViewDimension::references(std::string refName) const +//{ +// Base::Console().Message("DVD::references(%s) - %s\n",refName.c_str(),getNameInDocument()); +// bool result = false; +// const std::vector &objects = References2D.getValues(); +// if (!objects.empty()) { +// const std::vector &subElements = References2D.getSubValues(); +// if (!subElements.empty()) { +// for (auto& s: subElements) { +// if (!s.empty()) { +// if (s == refName) { +// result = true; +// break; +// } +// } +// } +// } +// } +// return result; +//} PyObject *DrawViewDimension::getPyObject(void) { diff --git a/src/Mod/TechDraw/App/DrawViewDimension.h b/src/Mod/TechDraw/App/DrawViewDimension.h index 2b5473fe6d..0c09b1cab9 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.h +++ b/src/Mod/TechDraw/App/DrawViewDimension.h @@ -105,9 +105,19 @@ public: App::PropertyFloat OverTolerance; App::PropertyFloat UnderTolerance; + enum RefType{ + invalidRef, + oneEdge, + twoEdge, + twoVertex, + vertexEdge, + threeVertex + }; + + short mustExecute() const override; - bool has2DReferences(void) const; - bool has3DReferences(void) const; + virtual bool has2DReferences(void) const; + virtual bool has3DReferences(void) const; bool hasTolerance(void) const; /** @name methods override Feature */ @@ -125,14 +135,14 @@ public: virtual std::string getFormatedValue(int partial = 0); virtual double getDimValue(); - DrawViewPart* getViewPart() const; + virtual DrawViewPart* getViewPart() const; virtual QRectF getRect() const override { return QRectF(0,0,1,1);} //pretend dimensions always fit! static int getRefType1(const std::string s); static int getRefType2(const std::string s1, const std::string s2); static int getRefType3(const std::string g1, const std::string g2, const std::string g3); - int getRefType() const; //Vertex-Vertex, Edge, Edge-Edge + virtual int getRefType() const; //Vertex-Vertex, Edge, Edge-Edge void setAll3DMeasurement(); void clear3DMeasurements(void); virtual bool checkReferences2D(void) const; @@ -140,7 +150,7 @@ public: arcPoints getArcPoints(void) {return m_arcPoints; } anglePoints getAnglePoints(void) {return m_anglePoints; } bool leaderIntersectsArc(Base::Vector3d s, Base::Vector3d pointOnCircle); - bool references(std::string geomName) const; +/* bool references(std::string geomName) const;*/ bool isMultiValueSchema(void) const; @@ -164,13 +174,14 @@ protected: Base::Vector3d e2) const; pointPair closestPoints(TopoDS_Shape s1, TopoDS_Shape s2) const; + pointPair m_linearPoints; private: static const char* TypeEnums[]; static const char* MeasureTypeEnums[]; void dumpRefs2D(const char* text) const; //Dimension "geometry" - pointPair m_linearPoints; +/* pointPair m_linearPoints;*/ arcPoints m_arcPoints; anglePoints m_anglePoints; bool m_hasGeometry; diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index ac572df4e7..a10bc83218 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -64,10 +64,12 @@ #include #include #include +#include #include #include #include #include +#include #include @@ -99,6 +101,7 @@ #include "DrawViewBalloon.h" #include "DrawViewDetail.h" #include "DrawViewDimension.h" +#include "LandmarkDimension.h" #include "DrawViewPart.h" #include "DrawViewSection.h" #include "EdgeWalker.h" @@ -160,11 +163,6 @@ DrawViewPart::DrawViewPart(void) : ADD_PROPERTY_TYPE(IsoHidden ,(prefIsoHid()),sgroup,App::Prop_None,"Show Hidden Iso u,v lines"); ADD_PROPERTY_TYPE(IsoCount ,(prefIsoCount()),sgroup,App::Prop_None,"Number of iso parameters lines"); -// ADD_PROPERTY_TYPE(CosmeticVertexes ,(0),sgroup,App::Prop_Output,"CosmeticVertex Save/Restore"); -// ADD_PROPERTY_TYPE(CosmeticEdges ,(0),sgroup,App::Prop_Output,"CosmeticEdge Save/Restore"); -// ADD_PROPERTY_TYPE(CenterLines ,(0),sgroup,App::Prop_Output,"Geometry format Save/Restore"); -// ADD_PROPERTY_TYPE(GeomFormats ,(0),sgroup,App::Prop_Output,"Geometry format Save/Restore"); - geometryObject = nullptr; getRunControl(); //initialize bbox to non-garbage @@ -176,6 +174,16 @@ DrawViewPart::~DrawViewPart() delete geometryObject; } +std::vector DrawViewPart::getSourceShape2d(void) const +{ +// Base::Console().Message("DVP::getSourceShape2d()\n"); + std::vector result; + const std::vector& links = Source.getValues(); + result = ShapeExtractor::getShapes2d(links); + return result; +} + + TopoDS_Shape DrawViewPart::getSourceShape(void) const { TopoDS_Shape result; @@ -248,6 +256,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) return App::DocumentObject::StdReturn; } + bool haveX = checkXDirection(); if (!haveX) { //block touch/onChanged stuff @@ -260,6 +269,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) m_saveShape = shape; partExec(shape); + addShapes2d(); //second pass if required if (ScaleType.isValue("Automatic")) { @@ -270,8 +280,9 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) if (geometryObject != nullptr) { delete geometryObject; geometryObject = nullptr; - partExec(shape); +// partExec(shape); } + partExec(shape); } } @@ -335,15 +346,46 @@ void DrawViewPart::partExec(TopoDS_Shape shape) } } #endif //#if MOD_TECHDRAW_HANDLE_FACES - + std::vector verts = getVertexGeometry(); addCosmeticVertexesToGeom(); addCosmeticEdgesToGeom(); addCenterLinesToGeom(); + + addReferencesToGeom(); +} + +void DrawViewPart::addShapes2d(void) +{ + std::vector shapes = getSourceShape2d(); + for (auto& s: shapes) { + //just vertices for now + if (s.ShapeType() == TopAbs_VERTEX) { + gp_Pnt gp = BRep_Tool::Pnt(TopoDS::Vertex(s)); + Base::Vector3d vp(gp.X(), gp.Y(), gp.Z()); + vp = vp - m_saveCentroid; + //need to offset the point to match the big projection + Base::Vector3d projected = projectPoint(vp * getScale()); + TechDraw::Vertex* v1 = new TechDraw::Vertex(projected); + geometryObject->addVertex(v1); + } else if (s.ShapeType() == TopAbs_EDGE) { + //not supporting edges yet. +// Base::Console().Message("DVP::add2dShapes - found loose edge - isNull: %d\n", s.IsNull()); +// TopoDS_Shape sTrans = TechDraw::moveShape(s, +// m_saveCentroid * -1.0); +// TopoDS_Shape sScale = TechDraw::scaleShape(sTrans, +// getScale()); +// TopoDS_Shape sMirror = TechDraw::mirrorShape(sScale); +// TopoDS_Edge edge = TopoDS::Edge(sMirror); +// BaseGeom* bg = projectEdge(edge); + +// geometryObject->addEdge(bg); + //save connection between source feat and this edge + } + } } GeometryObject* DrawViewPart::makeGeometryForShape(TopoDS_Shape shape) { -// Base::Console().Message("DVP::makeGeometryforShape() - %s\n", Label.getValue()); gp_Pnt inputCenter; Base::Vector3d stdOrg(0.0,0.0,0.0); @@ -758,6 +800,7 @@ QRectF DrawViewPart::getRect() const //used to project a pt (ex SectionOrigin) onto paper plane Base::Vector3d DrawViewPart::projectPoint(const Base::Vector3d& pt) const { +// Base::Console().Message("DVP::projectPoint()\n"); Base::Vector3d stdOrg(0.0,0.0,0.0); gp_Ax2 viewAxis = getProjectionCS(stdOrg); gp_Pnt gPt(pt.x,pt.y,pt.z); @@ -770,6 +813,25 @@ Base::Vector3d DrawViewPart::projectPoint(const Base::Vector3d& pt) const return result; } +//project a loose edge onto the paper plane +//TODO:: loose edges not supported yet +BaseGeom* DrawViewPart::projectEdge(const TopoDS_Edge& e) const +{ + Base::Vector3d stdOrg(0.0,0.0,0.0); + gp_Ax2 viewAxis = getProjectionCS(stdOrg); + + gp_Pln plane(viewAxis); + TopoDS_Face paper = BRepBuilderAPI_MakeFace(plane); + BRepAlgo_NormalProjection projector(paper); + projector.Add(e); + projector.Build(); + TopoDS_Shape s = projector.Projection(); +// Base::Console().Message("DVP::projectEdge - s.IsNull: %d\n", s.IsNull()); +// BaseGeom* result = BaseGeom::baseFactory(pe); + BaseGeom* result = nullptr; + return result; +} + bool DrawViewPart::hasGeometry(void) const { bool result = false; @@ -1004,6 +1066,71 @@ Base::Vector3d DrawViewPart::getLegacyX(const Base::Vector3d& pt, return result; } + +void DrawViewPart::updateReferenceVert(std::string tag, Base::Vector3d loc2d) +{ + for (auto& v: m_referenceVerts) { + if (v->getTagAsString() == tag) { + v->pnt = loc2d; + break; + } + } +} + +void DrawViewPart::addReferencesToGeom(void) +{ +// Base::Console().Message("DVP::addReferences()\n"); + std::vector gVerts = getVertexGeometry(); + gVerts.insert(gVerts.end(), m_referenceVerts.begin(), m_referenceVerts.end()); + getGeometryObject()->setVertexGeometry(gVerts); +} + +//add a vertex that is not part of the geometry, but is used by +//ex. LandmarkDimension as a reference +std::string DrawViewPart::addReferenceVertex(Base::Vector3d v) +{ +// Base::Console().Message("DVP::addReferenceVertex(%s)\n", DrawUtil::formatVector(v).c_str()); + std::string refTag; + Base::Vector3d scaledV = v * getScale(); + TechDraw::Vertex* ref = new TechDraw::Vertex(scaledV); + ref->reference = true; + refTag = ref->getTagAsString(); + m_referenceVerts.push_back(ref); + return refTag; +} + +void DrawViewPart::removeReferenceVertex(std::string tag) +{ + std::vector newRefVerts; + for (auto& v: m_referenceVerts) { + if (v->getTagAsString() != tag) { + newRefVerts.push_back(v); + } else { +// delete v; //??? who deletes v? + } + } + resetReferenceVerts(); +} + +void DrawViewPart::removeAllReferencesFromGeom() +{ + std::vector gVerts = getVertexGeometry(); + std::vector newVerts; + for (auto& gv: gVerts) { + if (!gv->reference) { + newVerts.push_back(gv); + } + } + getGeometryObject()->setVertexGeometry(newVerts); +} + +void DrawViewPart::resetReferenceVerts() +{ +// Base::Console().Message("DVP::resetReferenceVerts()\n"); + removeAllReferencesFromGeom(); + addReferencesToGeom(); +} + //******** //* Cosmetics //******** @@ -1054,6 +1181,45 @@ void DrawViewPart::refreshCVGeoms(void) addCosmeticVertexesToGeom(); } +//what is the CV's position in the big geometry q +int DrawViewPart::getCVIndex(std::string tag) +{ +// Base::Console().Message("DVP::getCVIndex(%s)\n", tag.c_str()); + int result = -1; + std::vector gVerts = getVertexGeometry(); + Base::Console().Message("DVP::getCVIndex - gVerts: %d\n", gVerts.size()); + std::vector cVerts = CosmeticVertexes.getValues(); + Base::Console().Message("DVP::getCVIndex - cVerts: %d\n", cVerts.size()); + + int i = 0; + bool found = false; + for (auto& gv :gVerts) { + Base::Console().Message("DVP::getCVIndex - gv cosmetic: %d ctag: %s\n", + gv->cosmetic, gv->cosmeticTag.c_str()); + if (gv->cosmeticTag == tag) { + result = i; + found = true; + break; + } + i++; + } + if (!found) { //not in vertexGeoms + int base = gVerts.size(); + int i = 0; + for (auto& cv: cVerts) { +// Base::Console().Message("DVP::getCVIndex - cv tag: %s\n", +// cv->getTagAsString().c_str()); + if (cv->getTagAsString() == tag) { + result = base + i; + break; + } + i++; + } + } +// Base::Console().Message("DVP::getCVIndex - returns: %d\n", result); + return result; +} + //CosmeticEdges ------------------------------------------------------------------- diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index bc06e41efc..ca61b0f35f 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -146,6 +146,8 @@ public: virtual Base::Vector3d projectPoint(const Base::Vector3d& pt) const; + virtual BaseGeom* projectEdge(const TopoDS_Edge& e) const; + virtual gp_Ax2 getViewAxis(const Base::Vector3d& pt, const Base::Vector3d& direction, const bool flip=true) const; @@ -166,6 +168,8 @@ public: virtual TopoDS_Shape getSourceShape(void) const; virtual TopoDS_Shape getSourceShapeFused(void) const; + virtual std::vector getSourceShape2d(void) const; + bool isIso(void) const; @@ -173,6 +177,7 @@ public: void refreshCVGeoms(void); void addCosmeticVertexesToGeom(void); int add1CVToGV(std::string tag); + int getCVIndex(std::string tag); void clearCosmeticEdges(void); void refreshCEGeoms(void); @@ -190,6 +195,13 @@ public: void dumpCosVerts(const std::string text); void dumpCosEdges(const std::string text); + std::string addReferenceVertex(Base::Vector3d v); + void addReferencesToGeom(void); + void removeReferenceVertex(std::string tag); + void updateReferenceVert(std::string tag, Base::Vector3d loc2d); + void removeAllReferencesFromGeom(); + void resetReferenceVerts(); + protected: bool checkXDirection(void) const; @@ -202,6 +214,7 @@ protected: virtual TechDraw::GeometryObject* buildGeometryObject(TopoDS_Shape shape, gp_Ax2 viewAxis); //const?? virtual TechDraw::GeometryObject* makeGeometryForShape(TopoDS_Shape shape); //const?? void partExec(TopoDS_Shape shape); + virtual void addShapes2d(void); void extractFaces(); @@ -226,6 +239,7 @@ protected: bool prefIsoHid(void); int prefIsoCount(void); + std::vector m_referenceVerts; private: bool nowUnsetting; diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index 658696ce56..1e7ab9eb42 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -1293,6 +1293,7 @@ Vertex::Vertex() cosmetic = false; cosmeticLink = -1; cosmeticTag = std::string(); + reference = false; createNewTag(); } @@ -1307,6 +1308,7 @@ Vertex::Vertex(const Vertex* v) cosmetic = v->cosmetic; cosmeticLink = v->cosmeticLink; cosmeticTag = v->cosmeticTag; + reference = false; createNewTag(); } @@ -1322,6 +1324,7 @@ Vertex::Vertex(double x, double y) cosmetic = false; cosmeticLink = -1; cosmeticTag = std::string(); + reference = false; createNewTag(); } @@ -1360,6 +1363,11 @@ void Vertex::Save(Base::Writer &writer) const writer.Stream() << writer.ind() << "" << endl; writer.Stream() << writer.ind() << "" << endl; writer.Stream() << writer.ind() << "" << endl; + + //do we need to save this? always recreated by program. +// const char r = reference?'1':'0'; +// writer.Stream() << writer.ind() << "" << endl; + writer.Stream() << writer.ind() << "" << endl; } @@ -1384,6 +1392,11 @@ void Vertex::Restore(Base::XMLReader &reader) cosmeticLink = reader.getAttributeAsInteger("value"); reader.readElement("CosmeticTag"); cosmeticTag = reader.getAttribute("value"); + + //will restore read to eof looking for "Reference" in old docs?? YES!! +// reader.readElement("Reference"); +// reference = (bool)reader.getAttributeAsInteger("value")==0?false:true; + reader.readElement("VertexTag"); std::string temp = reader.getAttribute("value"); boost::uuids::string_generator gen; diff --git a/src/Mod/TechDraw/App/Geometry.h b/src/Mod/TechDraw/App/Geometry.h index 14d4b8c83e..daf17f576d 100644 --- a/src/Mod/TechDraw/App/Geometry.h +++ b/src/Mod/TechDraw/App/Geometry.h @@ -317,6 +317,7 @@ class TechDrawExport Vertex bool cosmetic; int cosmeticLink; //deprec. use cosmeticTag std::string cosmeticTag; + bool reference; //reference vertex (ex robust dimension) double x() {return pnt.x;} double y() {return pnt.y;} diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 33660c24d9..be47510549 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -573,6 +573,16 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca } //end TopExp } +void GeometryObject::addVertex(TechDraw::Vertex* v) +{ + vertexGeom.push_back(v); +} + +void GeometryObject::addEdge(TechDraw::BaseGeom* bg) +{ + edgeGeom.push_back(bg); +} + //********** Cosmetic Vertex *************************************************** //adds a new GeomVert surrogate for CV diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h index 25f858cc95..a89f9b6ff7 100644 --- a/src/Mod/TechDraw/App/GeometryObject.h +++ b/src/Mod/TechDraw/App/GeometryObject.h @@ -144,6 +144,10 @@ public: TopoDS_Shape getHidSeam(void) { return hidSeam; } TopoDS_Shape getHidIso(void) { return hidIso; } + void addVertex(TechDraw::Vertex* v); + void addEdge(TechDraw::BaseGeom* bg); + + int addCosmeticVertex(CosmeticVertex* cv); int addCosmeticVertex(Base::Vector3d pos); int addCosmeticVertex(Base::Vector3d pos, diff --git a/src/Mod/TechDraw/App/LandmarkDimension.cpp b/src/Mod/TechDraw/App/LandmarkDimension.cpp new file mode 100644 index 0000000000..d140ffb034 --- /dev/null +++ b/src/Mod/TechDraw/App/LandmarkDimension.cpp @@ -0,0 +1,258 @@ +/*************************************************************************** + * Copyright (c) 2020 WandererFan +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "Geometry.h" +#include "GeometryObject.h" +#include "DrawViewPart.h" +#include "DrawUtil.h" +#include "LineGroup.h" +#include "Cosmetic.h" +#include "ShapeExtractor.h" +#include "LandmarkDimension.h" + + +//#include // generated from LandmarkDimensionPy.xml + +using namespace TechDraw; + +//=========================================================================== +// LandmarkDimension +//=========================================================================== + +PROPERTY_SOURCE(TechDraw::LandmarkDimension, TechDraw::DrawViewDimension) + + +LandmarkDimension::LandmarkDimension(void) +{ + static const char *group = "Landmark"; + //this leaves a blank entry in position 1. + ADD_PROPERTY_TYPE(ReferenceTags,("") , group, App::Prop_Output,"Tags of Dimension Endpoints"); + std::vector noTags; + ReferenceTags.setValues(noTags); +} + +LandmarkDimension::~LandmarkDimension() +{ +} + +void LandmarkDimension::onChanged(const App::Property* prop) +{ + if (!isRestoring()) { + //this is only good for new RD creation, not restore from disk? + if (prop == &References3D) { + //handled in base class + } else if (prop == &ReferenceTags) { + //??? + } + } + + DrawViewDimension::onChanged(prop); +} + +short LandmarkDimension::mustExecute() const +{ + return DrawViewDimension::mustExecute(); +} + +App::DocumentObjectExecReturn *LandmarkDimension::execute(void) +{ +// Base::Console().Message("LD::execute() - %s\n", getNameInDocument()); + if (!keepUpdated()) { + return App::DocumentObject::StdReturn; + } + + DrawViewPart* dvp = getViewPart(); + if (dvp == nullptr) { + return App::DocumentObject::StdReturn; + } + References2D.setValue(dvp); + + std::vector features = References3D.getValues(); + //if distance, required size = 2 + //if angle, required size = 3; + unsigned int requiredSize = 2; + if (features.size() < requiredSize) { + return App::DocumentObject::StdReturn; + } + + std::vector points; + std::vector reprs = ReferenceTags.getValues(); + if (reprs.empty()) { + //add verts to dvp & vert tags to RD + for (auto& f: features) { + Base::Vector3d loc3d = ShapeExtractor::getLocation3dFromFeat(f); + Base::Vector3d loc2d = projectPoint(loc3d, dvp) * dvp->getScale(); + points.push_back(loc2d); + std::string tag = dvp->addReferenceVertex(loc2d); + reprs.push_back(tag); + } + ReferenceTags.setValues(reprs); + } else { + //update dvp referenceverts locations + int index = 0; + for (auto& f: features) { + Base::Vector3d loc3d = ShapeExtractor::getLocation3dFromFeat(f); + Base::Vector3d loc2d = projectPoint(loc3d, dvp) * dvp->getScale(); + points.push_back(loc2d); + dvp->updateReferenceVert(reprs.at(index), loc2d); + index++; + } + } + m_linearPoints.first = points.front(); + m_linearPoints.second = points.back(); + + App::DocumentObjectExecReturn* dvdResult = DrawViewDimension::execute(); + + dvp->resetReferenceVerts(); + dvp->requestPaint(); + return dvdResult; +} + +Base::Vector3d LandmarkDimension::projectPoint(const Base::Vector3d& pt, DrawViewPart* dvp) const +{ + Base::Vector3d stdOrg(0.0,0.0,0.0); + gp_Ax2 viewAxis = dvp->getProjectionCS(stdOrg); + Base::Vector3d alignedPt = pt - dvp->getOriginalCentroid(); + gp_Pnt gPt(alignedPt.x, alignedPt.y, alignedPt.z); + + HLRAlgo_Projector projector( viewAxis ); + gp_Pnt2d prjPnt; + projector.Project(gPt, prjPnt); + Base::Vector3d result(prjPnt.X(),prjPnt.Y(), 0.0); + result = DrawUtil::invertY(result); + return result; +} + +std::vector LandmarkDimension::get2DPoints(void) const +{ +// Base::Console().Message("LD::get2DPoints()\n"); + std::vector result; + std::vector refs3 = References3D.getValues(); + TechDraw::DrawViewPart* dvp = getViewPart(); + for (auto& r: refs3) { + Base::Vector3d loc3d = ShapeExtractor::getLocation3dFromFeat(r); + Base::Vector3d loc2d = projectPoint(loc3d, dvp); + result.push_back(loc2d); + } + return result; +} + +//! References2D are only used to store ParentView +bool LandmarkDimension::has2DReferences(void) const +{ + bool result = false; + const std::vector &objects = References2D.getValues(); + if (!objects.empty()) { + result = true; + } + return result; +} + +//! References2D are only used to store ParentView +bool LandmarkDimension::checkReferences2D() const +{ + return true; +} + +pointPair LandmarkDimension::getPointsTwoVerts() +{ +// Base::Console().Message("LD::getPointsTwoVerts() - %s\n",getNameInDocument()); + pointPair result; + + TechDraw::DrawViewPart* dvp = getViewPart(); + if (dvp != nullptr) { + std::vector points = get2DPoints(); + result.first = points.at(0) * dvp->getScale(); + result.second = points.at(1) * dvp->getScale(); + } + return result; +} + +int LandmarkDimension::getRefType() const +{ + //TODO: need changes here when other reference dim types added + return DrawViewDimension::RefType::twoVertex; +} + +DrawViewPart* LandmarkDimension::getViewPart() const +{ + DrawViewPart* result = nullptr; + std::vector refs2d = References2D.getValues(); + App::DocumentObject* obj = refs2d.front(); + DrawViewPart* dvp = dynamic_cast(obj); + if (dvp != nullptr) { + result = dvp; + } + return result; +} + +//clean up at deletion time +void LandmarkDimension::unsetupObject() +{ +// Base::Console().Message("LD::unsetupObject()\n"); + DrawViewPart* dvp = getViewPart(); + if (dvp != nullptr) { + std::vector tags = ReferenceTags.getValues(); + for (auto& t: tags) { + dvp->removeReferenceVertex(t); + } + } + DrawViewDimension::unsetupObject(); +} + +//??? why does getPyObject work sometimes and no others??? +//PyObject *LandmarkDimension::getPyObject(void) +//{ +// if (PythonObject.is(Py::_None())) { +// // ref counter is set to 1 +// PythonObject = Py::Object(new LandmarkDimensionPy(this),true); +// } +// return Py::new_reference_to(PythonObject); +//} + diff --git a/src/Mod/TechDraw/App/LandmarkDimension.h b/src/Mod/TechDraw/App/LandmarkDimension.h new file mode 100644 index 0000000000..3fe3c5b19a --- /dev/null +++ b/src/Mod/TechDraw/App/LandmarkDimension.h @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright (c) 2020 WandererFan +# include +# include + +#include "DrawViewDimension.h" + +class TopoDS_Shape; +class gp_Ax2; + +namespace Measure { +class Measurement; +} +namespace TechDraw +{ +class DrawViewPart; + +class TechDrawExport LandmarkDimension : public TechDraw::DrawViewDimension +{ + PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::LandmarkDimension); + +public: + /// Constructor + LandmarkDimension(); + virtual ~LandmarkDimension(); + + App::PropertyStringList ReferenceTags; //tags of 2d vertices in DVP + + virtual App::DocumentObjectExecReturn *execute(void) override; + short mustExecute() const override; + virtual const char* getViewProviderName(void) const override { + return "TechDrawGui::ViewProviderDimension"; } +/* virtual PyObject *getPyObject(void) override;*/ + + virtual bool checkReferences2D() const override; + virtual bool has2DReferences(void) const override; + virtual pointPair getPointsTwoVerts() override; + std::vector get2DPoints(void) const; + virtual DrawViewPart* getViewPart() const override; + virtual int getRefType() const override; + + gp_Ax2 getProjAxis(void) const; + +protected: + virtual void onChanged(const App::Property* prop) override; + virtual void unsetupObject() override; + + Base::Vector3d projectPoint(const Base::Vector3d& pt, DrawViewPart* dvp) const; + +private: +}; + +} //namespace TechDraw +#endif diff --git a/src/Mod/TechDraw/App/ShapeExtractor.cpp b/src/Mod/TechDraw/App/ShapeExtractor.cpp index 0ef9f0f00e..09063c2604 100644 --- a/src/Mod/TechDraw/App/ShapeExtractor.cpp +++ b/src/Mod/TechDraw/App/ShapeExtractor.cpp @@ -29,7 +29,11 @@ #include #include #include - +#include +#include +#include +#include +#include #include #include @@ -43,20 +47,53 @@ #include #include +#include +#include #include #include #include "ShapeExtractor.h" +#include "DrawUtil.h" using namespace TechDraw; +std::vector ShapeExtractor::getShapes2d(const std::vector links) +{ +// Base::Console().Message("SE::getShapes2d()\n"); + + std::vector shapes2d; + for (auto& l:links) { + const App::GroupExtension* gex = dynamic_cast(l); +// App::Property* gProp = l->getPropertyByName("Group"); + if (gex != nullptr) { + std::vector objs = gex->Group.getValues(); + for (auto& d: objs) { + if (is2dObject(d)) { + auto shape = Part::Feature::getShape(d); + if(!shape.IsNull()) { + shapes2d.push_back(shape); + } + } + } + } else { + if (is2dObject(l)) { + auto shape = Part::Feature::getShape(l); + if(!shape.IsNull()) { + shapes2d.push_back(shape); + } + } + } + } + return shapes2d; +} + TopoDS_Shape ShapeExtractor::getShapes(const std::vector links) { TopoDS_Shape result; std::vector sourceShapes; for (auto& l:links) { - auto shape = Part::Feature::getShape(l); //finds shape within DocObj?? + auto shape = Part::Feature::getShape(l); if(!shape.IsNull()) { // BRepTools::Write(shape, "DVPgetShape.brep"); //debug if (shape.ShapeType() > TopAbs_COMPSOLID) { //simple shape @@ -201,7 +238,8 @@ std::vector ShapeExtractor::extractDrawableShapes(const TopoDS_Sha extShapes.push_back(s); } } - //get edges not part of a solid + //vs using 2d geom as construction geom? + //get edges not part of a solid //???? should this look for Faces(Wires?) before Edges? TopExp_Explorer expEdge(shapeIn, TopAbs_EDGE, TopAbs_SOLID); for (int i = 1; expEdge.More(); expEdge.Next(), i++) { @@ -222,3 +260,84 @@ std::vector ShapeExtractor::extractDrawableShapes(const TopoDS_Sha return result; } +bool ShapeExtractor::is2dObject(App::DocumentObject* obj) +{ + bool result = false; + if (isEdgeType(obj) || isPointType(obj)) { + result = true; + } + return result; +} + +//skip edges for now. +bool ShapeExtractor::isEdgeType(App::DocumentObject* obj) +{ + (void) obj; + bool result = false; +// Base::Type t = obj->getTypeId(); +// if (t.isDerivedFrom(Part::Line::getClassTypeId()) ) { +// result = true; +// } else if (t.isDerivedFrom(Part::Circle::getClassTypeId())) { +// result = true; +// } else if (t.isDerivedFrom(Part::Ellipse::getClassTypeId())) { +// result = true; +// } else if (t.isDerivedFrom(Part::RegularPolygon::getClassTypeId())) { +// result = true; +// } + return result; +} + +bool ShapeExtractor::isPointType(App::DocumentObject* obj) +{ + bool result = false; + Base::Type t = obj->getTypeId(); + if (t.isDerivedFrom(Part::Vertex::getClassTypeId())) { + result = true; + } else if (isDraftPoint(obj)) { + result = true; + } + return result; +} + +bool ShapeExtractor::isDraftPoint(App::DocumentObject* obj) +{ +// Base::Console().Message("SE::isDraftPoint()\n"); + bool result = false; + //if the docObj doesn't have a Proxy property, it definitely isn't a Draft point + App::Property* proxy = obj->getPropertyByName("Proxy"); + if (proxy != nullptr) { + App::PropertyPythonObject* proxyPy = dynamic_cast(proxy); + std::string pp = proxyPy->toString(); +// Base::Console().Message("SE::isDraftPoint - pp: %s\n", pp.c_str()); + if (pp.find("Point") != std::string::npos) { + result = true; + } + } + return result; +} + +Base::Vector3d ShapeExtractor::getLocation3dFromFeat(App::DocumentObject* obj) +{ +// Base::Console().Message("SE::getLocation3dFromFeat()\n"); + Base::Vector3d result(0.0, 0.0, 0.0); + if (!isPointType(obj)) { + return result; + } +// if (isDraftPoint(obj) { +// //Draft Points are not necc. Part::PartFeature?? +// //if Draft option "use part primitives" is not set are Draft points still PartFeature? +// Base::Vector3d featPos = features[i]->(Placement.getValue()).Position(); + + Part::Feature* pf = dynamic_cast(obj); + if (pf != nullptr) { + TopoDS_Shape ts = pf->Shape.getValue(); + if (ts.ShapeType() == TopAbs_VERTEX) { + TopoDS_Vertex v = TopoDS::Vertex(ts); + result = DrawUtil::vertex2Vector(v); + } + } +// Base::Console().Message("SE::getLocation3dFromFeat - returns: %s\n", +// DrawUtil::formatVector(result).c_str()); + return result; +} + diff --git a/src/Mod/TechDraw/App/ShapeExtractor.h b/src/Mod/TechDraw/App/ShapeExtractor.h index 769e5dc4e6..a544824047 100644 --- a/src/Mod/TechDraw/App/ShapeExtractor.h +++ b/src/Mod/TechDraw/App/ShapeExtractor.h @@ -25,8 +25,6 @@ #include #include -#include -#include #include #include @@ -37,6 +35,9 @@ #include #include +#include +#include + namespace TechDraw { @@ -44,10 +45,18 @@ class TechDrawExport ShapeExtractor { public: static TopoDS_Shape getShapes(const std::vector links); + static std::vector getShapes2d(const std::vector links); static std::vector getShapesFromObject(const App::DocumentObject* docObj); static TopoDS_Shape getShapesFused(const std::vector links); static std::vector extractDrawableShapes(const TopoDS_Shape shapeIn); + static bool is2dObject(App::DocumentObject* obj); + static bool isEdgeType(App::DocumentObject* obj); + static bool isPointType(App::DocumentObject* obj); + static bool isDraftPoint(App::DocumentObject* obj); + static Base::Vector3d getLocation3dFromFeat(App::DocumentObject* obj); + + protected: private: diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp index cb0eaa42e4..50f5d50be7 100644 --- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -54,6 +54,7 @@ # include # include # include +# include # include # include # include @@ -1338,6 +1339,101 @@ void execVExtent(Gui::Command* cmd) 1); } +//=========================================================================== +// TechDraw_LandmarkDimension +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawLandmarkDimension) + +CmdTechDrawLandmarkDimension::CmdTechDrawLandmarkDimension() + : Command("TechDraw_LandmarkDimension") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Landmark Dimension"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_LandmarkDimension"; + sStatusTip = sToolTipText; + sPixmap = "techdraw-landmarkdistance"; +} + +void CmdTechDrawLandmarkDimension::activated(int iMsg) +{ + Q_UNUSED(iMsg); + bool result = _checkSelection(this,3); //redundant?? + if (!result) + return; + + const std::vector objects = getSelection(). + getObjectsOfType(Part::Feature::getClassTypeId()); //?? + if ( (objects.size() != 2) && + (objects.size() != 3) ) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select 2 or 3 point objects and 1 View. (1)")); + return; + } + + const std::vector 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)")); + return; + } + + TechDraw::DrawViewPart* dvp = dynamic_cast(views.front()); + + std::vector refs2d; + + std::vector subs; + subs.push_back("Vertex1"); + subs.push_back("Vertex1"); + TechDraw::DrawPage* page = dvp->findParentPage(); + std::string parentName = dvp->getNameInDocument(); + std::string PageName = page->getNameInDocument(); + + TechDraw::LandmarkDimension *dim = 0; + std::string FeatName = getUniqueObjectName("LandmarkDim"); + + openCommand("Create Dimension"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::LandmarkDimension','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + if (objects.size() == 2) { + //what about distanceX and distanceY?? + 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"); + } + + dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); + if (!dim) { + throw Base::TypeError("CmdTechDrawLandmarkDimension - dim not found\n"); + } + dim->References2D.setValues(refs2d, subs); + dim->References3D.setValues(objects, subs); + + commitCommand(); + dim->recomputeFeature(); + + //Horrible hack to force Tree update + double x = dvp->X.getValue(); + dvp->X.setValue(x); +} + +bool CmdTechDrawLandmarkDimension::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this); + return (havePage && haveView); +} + + //------------------------------------------------------------------------------ void CreateTechDrawCommandsDims(void) { @@ -1355,6 +1451,7 @@ void CreateTechDrawCommandsDims(void) rcCmdMgr.addCommand(new CmdTechDrawVerticalExtentDimension()); rcCmdMgr.addCommand(new CmdTechDrawHorizontalExtentDimension()); rcCmdMgr.addCommand(new CmdTechDrawLinkDimension()); + rcCmdMgr.addCommand(new CmdTechDrawLandmarkDimension()); } //=========================================================================== diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index 9ca683f90f..7d511ed58d 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -66,6 +66,7 @@ #include #include #include +//#include #include #include #include @@ -490,6 +491,7 @@ QGIView * QGVPage::addViewDimension(TechDraw::DrawViewDimension *dim) void QGVPage::addDimToParent(QGIViewDimension* dim, QGIView* parent) { +// Base::Console().Message("QGVP::addDimToParent()\n"); assert(dim); assert(parent); //blow up if we don't have Dimension or Parent QPointF posRef(0.,0.); @@ -617,10 +619,21 @@ QGIView * QGVPage::findParent(QGIView *view) const const std::vector qviews = getViews(); TechDraw::DrawView *myFeat = view->getViewObject(); +//LandmarkDimension shouldn't require special handling +// TechDraw::LandmarkDimension *robust = nullptr; +// robust = dynamic_cast(myFeat); +// if (robust != nullptr) { +// App::DocumentObject* robustParent = robust->ParentView.getValue(); +// for (auto& qv: qviews) { +// if(strcmp(qv->getViewName(), robustParent->getNameInDocument()) == 0) { +// return qv; +// } +// } +// } + //If type is dimension we check references first TechDraw::DrawViewDimension *dim = 0; dim = dynamic_cast(myFeat); - if(dim) { std::vector objs = dim->References2D.getValues(); diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 9718e8fe9a..bf08fac9b7 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -34,6 +34,7 @@ icons/TechDraw_Dimension_Link.svg icons/TechDraw_HorizontalExtentDimension.svg icons/TechDraw_VerticalExtentDimension.svg + icons/techdraw-landmarkdistance.svg icons/preferences-techdraw.svg icons/arrowdot.svg icons/arrowopendot.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/techdraw-landmarkdistance.svg b/src/Mod/TechDraw/Gui/Resources/icons/techdraw-landmarkdistance.svg new file mode 100644 index 0000000000..4cc6c5fa36 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/techdraw-landmarkdistance.svg @@ -0,0 +1,277 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + [WandererFan] + + + TechDraw_Dimension_Length + 2016-04-27 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + FreeCAD/src/Mod/TechDraw/Gui/Resources/icons/TechDraw_Dimension_Length.svg + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + [agryson] Alexander Gryson + + + + + double arrow + diagonal + arrow + + + Double arrow at angle between two diagonal bars + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp index 9f6be5953e..fab6b5a652 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp @@ -40,6 +40,7 @@ #include #include +#include #include "QGIViewDimension.h" #include "ViewProviderDimension.h" @@ -88,6 +89,11 @@ void ViewProviderDimension::attach(App::DocumentObject *pcFeat) { // call parent attach method ViewProviderDrawingView::attach(pcFeat); + + sPixmap = "TechDraw_Dimension"; + if (getViewObject()->isDerivedFrom(TechDraw::LandmarkDimension::getClassTypeId())) { + sPixmap = "techdraw-landmarkdistance"; + } } void ViewProviderDimension::setDisplayMode(const char* ModeName) diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index e8f56577dc..a3f2b76b2d 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -50,32 +50,34 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::MenuItem* draw = new Gui::MenuItem; root->insertItem(item, draw); - // dimensions - Gui::MenuItem* dimensions = new Gui::MenuItem; - dimensions->setCommand("Dimensions"); - *dimensions << "TechDraw_LengthDimension" << "TechDraw_HorizontalDimension" << "TechDraw_VerticalDimension" - << "TechDraw_RadiusDimension" << "TechDraw_DiameterDimension" << "TechDraw_AngleDimension" - << "TechDraw_HorizontalExtentDimension" << "TechDraw_VerticalExtentDimension" << "TechDraw_LinkDimension"; + // dimensions + Gui::MenuItem* dimensions = new Gui::MenuItem; + dimensions->setCommand("Dimensions"); + *dimensions << "TechDraw_LengthDimension" << "TechDraw_HorizontalDimension" << "TechDraw_VerticalDimension" + << "TechDraw_RadiusDimension" << "TechDraw_DiameterDimension" << "TechDraw_AngleDimension" + << "TechDraw_HorizontalExtentDimension" << "TechDraw_VerticalExtentDimension" << "TechDraw_LinkDimension" + << "TechDraw_LandmarkDimension" +; - // annotations - Gui::MenuItem* annotations = new Gui::MenuItem; - annotations->setCommand("Annotations"); - *annotations << "TechDraw_Annotation" << "TechDraw_RichTextAnnotation" << "TechDraw_Balloon"; + // annotations + Gui::MenuItem* annotations = new Gui::MenuItem; + annotations->setCommand("Annotations"); + *annotations << "TechDraw_Annotation" << "TechDraw_RichTextAnnotation" << "TechDraw_Balloon"; - // lines - Gui::MenuItem* lines = new Gui::MenuItem; - lines->setCommand("Add Lines"); - *lines << "TechDraw_LeaderLine" << "TechDraw_FaceCenterLine" - << "TechDraw_2LineCenterLine" << "TechDraw_2PointCenterLine"; + // lines + Gui::MenuItem* lines = new Gui::MenuItem; + lines->setCommand("Add Lines"); + *lines << "TechDraw_LeaderLine" << "TechDraw_FaceCenterLine" + << "TechDraw_2LineCenterLine" << "TechDraw_2PointCenterLine"; - // vertices - Gui::MenuItem* vertices = new Gui::MenuItem; - vertices->setCommand("Add Vertices"); - *vertices << "TechDraw_CosmeticVertex" << "TechDraw_Midpoints" - << "TechDraw_Quadrants"; + // vertices + Gui::MenuItem* vertices = new Gui::MenuItem; + vertices->setCommand("Add Vertices"); + *vertices << "TechDraw_CosmeticVertex" << "TechDraw_Midpoints" + << "TechDraw_Quadrants"; - // main menu - draw->setCommand("TechDraw"); + // main menu + draw->setCommand("TechDraw"); *draw << "TechDraw_PageDefault"; *draw << "TechDraw_PageTemplate"; *draw << "TechDraw_RedrawPage"; @@ -94,7 +96,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_ClipGroupAdd"; *draw << "TechDraw_ClipGroupRemove"; *draw << "Separator"; - *draw << dimensions; + *draw << dimensions; *draw << "Separator"; *draw << "TechDraw_ExportPageSVG"; *draw << "TechDraw_ExportPageDXF"; @@ -106,7 +108,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_ToggleFrame"; *draw << "Separator"; *draw << annotations; - *draw << lines; + *draw << lines; *draw << vertices; *draw << "TechDraw_CosmeticEraser"; *draw << "TechDraw_DecorateLine"; @@ -155,6 +157,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const // *dims << "TechDraw_VerticalExtentDimension"; *dims << "TechDraw_LinkDimension"; *dims << "TechDraw_Balloon"; + *dims << "TechDraw_LandmarkDimension"; // *dims << "TechDraw_Dimension" Gui::ToolBarItem *file = new Gui::ToolBarItem(root); @@ -227,6 +230,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const // *dims << "TechDraw_VerticalExtentDimension"; *dims << "TechDraw_LinkDimension"; *dims << "TechDraw_Balloon"; + *dims << "TechDraw_LandmarkDimension"; // *dims << "TechDraw_Dimension"; Gui::ToolBarItem *file = new Gui::ToolBarItem(root);