From 3f7570ad80da2c685090b54d054041b4029154e3 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 15 May 2019 07:37:36 -0400 Subject: [PATCH] Initial version addCosmeticVertex --- src/Mod/TechDraw/App/CMakeLists.txt | 2 + src/Mod/TechDraw/App/Cosmetic.cpp | 143 +++ src/Mod/TechDraw/App/Cosmetic.h | 58 ++ src/Mod/TechDraw/App/DrawView.cpp | 13 +- src/Mod/TechDraw/App/DrawView.h | 5 +- src/Mod/TechDraw/App/DrawViewPart.cpp | 115 ++- src/Mod/TechDraw/App/DrawViewPart.h | 16 +- src/Mod/TechDraw/App/DrawViewPartPy.xml | 5 + src/Mod/TechDraw/App/DrawViewPartPyImp.cpp | 8 + src/Mod/TechDraw/App/Geometry.cpp | 9 +- src/Mod/TechDraw/App/GeometryObject.cpp | 9 + src/Mod/TechDraw/App/GeometryObject.h | 3 + src/Mod/TechDraw/Gui/AppTechDrawGui.cpp | 2 + src/Mod/TechDraw/Gui/CMakeLists.txt | 9 +- src/Mod/TechDraw/Gui/Command.cpp | 45 +- src/Mod/TechDraw/Gui/CommandAnnotate.cpp | 406 +++++++++ src/Mod/TechDraw/Gui/CommandDecorate.cpp | 206 ++--- src/Mod/TechDraw/Gui/QGIViewPart.cpp | 53 +- src/Mod/TechDraw/Gui/QGIViewPart.h | 1 + src/Mod/TechDraw/Gui/QGTracker.cpp | 22 +- src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 2 + .../icons/actions/techdraw-annotation.svg | 832 +++++++++++++++--- .../icons/actions/techdraw-midpoint.svg | 290 ++++++ .../icons/actions/techdraw-mline.svg | 161 ++-- .../icons/actions/techdraw-point.svg | 8 +- .../icons/actions/techdraw-quadrant.svg | 295 +++++++ src/Mod/TechDraw/Gui/Rez.cpp | 5 + src/Mod/TechDraw/Gui/Rez.h | 1 + src/Mod/TechDraw/Gui/TaskCosVertex.cpp | 391 ++++++++ src/Mod/TechDraw/Gui/TaskCosVertex.h | 175 ++++ src/Mod/TechDraw/Gui/TaskCosVertex.ui | 211 +++++ src/Mod/TechDraw/Gui/Workbench.cpp | 35 +- 32 files changed, 3157 insertions(+), 379 deletions(-) create mode 100644 src/Mod/TechDraw/App/Cosmetic.cpp create mode 100644 src/Mod/TechDraw/App/Cosmetic.h create mode 100644 src/Mod/TechDraw/Gui/CommandAnnotate.cpp create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-midpoint.svg create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-quadrant.svg create mode 100644 src/Mod/TechDraw/Gui/TaskCosVertex.cpp create mode 100644 src/Mod/TechDraw/Gui/TaskCosVertex.h create mode 100644 src/Mod/TechDraw/Gui/TaskCosVertex.ui diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 61f8659a0f..d3faadadf3 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -123,6 +123,8 @@ SET(Geometry_SRCS Geometry.h GeometryObject.cpp GeometryObject.h + Cosmetic.cpp + Cosmetic.h ) SET(Python_SRCS diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp new file mode 100644 index 0000000000..6b0d2a9cc7 --- /dev/null +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -0,0 +1,143 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +#endif // #ifndef _PreComp_ + +#include +#include +#include +#include + +#include +#include + +#include "DrawUtil.h" + +#include "Cosmetic.h" + +using namespace TechDraw; + +CosmeticVertex::CosmeticVertex() +{ + pageLocation = Base::Vector3d(0.0, 0.0, 0.0); + modelLocation = Base::Vector3d(0.0, 0.0, 0.0); + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("VertexColor", 0x00000000)); + + linkGeom = -1; + color = fcColor; + size = 3.0; + style = 1; + visible = true; +} + +CosmeticVertex::CosmeticVertex(Base::Vector3d loc) +{ + pageLocation = loc; + modelLocation = loc; + + Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> + GetGroup("Preferences")->GetGroup("Mod/TechDraw/Decorations"); + App::Color fcColor; + fcColor.setPackedValue(hGrp->GetUnsigned("VertexColor", 0xff000000)); + + linkGeom = -1; + color = fcColor; + //TODO: size = hGrp->getFloat("VertexSize",30.0); + size = 30.0; + style = 1; //TODO: implement styled vertexes + visible = true; +} + +std::string CosmeticVertex::toCSV(void) const +{ + std::stringstream ss; + ss << pageLocation.x << "," << + pageLocation.y << "," << + pageLocation.z << "," << + + modelLocation.x << "," << + modelLocation.y << "," << + modelLocation.z << "," << + + linkGeom << "," << + color.asHexString() << "," << + size << "," << + style << "," << + visible << + std::endl; + return ss.str(); +} + +bool CosmeticVertex::fromCSV(std::string& lineSpec) +{ + unsigned int maxCells = 11; + if (lineSpec.length() == 0) { + Base::Console().Message( "CosmeticVertex::fromCSV - lineSpec empty\n"); + return false; + } + std::vector values = split(lineSpec); + Base::Console().Message("CV::fromCSV - values: %d\n",values.size()); + if (values.size() < maxCells) { + Base::Console().Message( "CosmeticVertex::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() ); + return false; + } + double x = atof(values[0].c_str()); + double y = atof(values[1].c_str()); + double z = atof(values[2].c_str()); + pageLocation = Base::Vector3d (x,y,z); + x = atof(values[3].c_str()); + y = atof(values[4].c_str()); + z = atof(values[5].c_str()); + modelLocation = Base::Vector3d (x,y,z); + linkGeom = atoi(values[6].c_str()); + color.fromHexString(values[7]); + size = atof(values[8].c_str()); + style = atoi(values[9].c_str()); + visible = atoi(values[10].c_str()); + return true; +} + +std::vector CosmeticVertex::split(std::string csvLine) +{ + Base::Console().Message("CV::split - csvLine: %s\n",csvLine.c_str()); + std::vector result; + std::stringstream lineStream(csvLine); + std::string cell; + + while(std::getline(lineStream,cell, ',')) + { + result.push_back(cell); + } + return result; +} + +void CosmeticVertex::dump(char* title) +{ + Base::Console().Message("CV::dump - %s \n",title); + Base::Console().Message("CV::dump - %s \n",toCSV().c_str()); +} + diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h new file mode 100644 index 0000000000..575b2d8fea --- /dev/null +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAW_COSMETIC_H +#define TECHDRAW_COSMETIC_H + +#include +#include + +namespace TechDraw { + +class TechDrawExport CosmeticVertex +{ +public: + CosmeticVertex(); + CosmeticVertex(Base::Vector3d loc); + virtual ~CosmeticVertex() = default; + + std::string toCSV(void) const; + bool fromCSV(std::string& lineSpec); + void dump(char* title); + + Base::Vector3d pageLocation; + Base::Vector3d modelLocation; + int linkGeom; //connection to corresponding "real" Vertex + App::Color color; + double size; + int style; + bool visible; + +protected: + std::vector split(std::string csvLine); + +}; + + +} //end namespace TechDraw + +#endif //TECHDRAW_COSMETIC_H diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 5219d712b9..b5a77263e3 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -39,7 +39,6 @@ #include #include -#include "DrawView.h" #include "DrawPage.h" #include "DrawViewCollection.h" #include "DrawViewClip.h" @@ -47,11 +46,15 @@ #include "DrawProjGroupItem.h" #include "DrawLeaderLine.h" #include "DrawUtil.h" +#include "Geometry.h" +#include "Cosmetic.h" #include // generated from DrawViewPy.xml -using namespace TechDraw; +#include "DrawView.h" +using namespace TechDraw; +using namespace TechDrawGeometry; //=========================================================================== // DrawView @@ -323,12 +326,6 @@ std::vector DrawView::getLeaders() const return result; } -void DrawView::addRandomVertex(Base::Vector3d pos) -{ - (void) pos; - Base::Console().Message("DV::addRandomVertex()\n"); -} - void DrawView::Restore(Base::XMLReader &reader) { // this is temporary code for backwards compat (within v0.17). can probably be deleted once there are no development diff --git a/src/Mod/TechDraw/App/DrawView.h b/src/Mod/TechDraw/App/DrawView.h index 3329ced0df..5c5b4a98a0 100644 --- a/src/Mod/TechDraw/App/DrawView.h +++ b/src/Mod/TechDraw/App/DrawView.h @@ -38,6 +38,7 @@ namespace TechDraw class DrawPage; class DrawViewClip; class DrawLeaderLine; +class CosmeticVertex; /** Base class of all View Features in the drawing module */ @@ -90,8 +91,8 @@ public: void requestPaint(void); virtual void handleXYLock(void); virtual bool isLocked(void) const; - virtual void addRandomVertex(Base::Vector3d pos); - std::vector getLeaders() const; + + std::vector getLeaders(void) const; protected: virtual void onChanged(const App::Property* prop) override; diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index c9c78ae0d6..05d8eb118b 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -102,7 +102,7 @@ #include "DrawPage.h" #include "EdgeWalker.h" #include "LineGroup.h" - +#include "Cosmetic.h" #include // generated from DrawViewPartPy.xml @@ -117,7 +117,9 @@ using namespace std; PROPERTY_SOURCE(TechDraw::DrawViewPart, TechDraw::DrawView) -DrawViewPart::DrawViewPart(void) : geometryObject(0) +DrawViewPart::DrawViewPart(void) : + geometryObject(0), + on1(true) { static const char *group = "Projection"; static const char *sgroup = "HLR Parameters"; @@ -148,8 +150,16 @@ DrawViewPart::DrawViewPart(void) : geometryObject(0) ADD_PROPERTY_TYPE(IsoHidden ,(false),sgroup,App::Prop_None,"Hidden Iso u,v lines on/off"); ADD_PROPERTY_TYPE(IsoCount ,(0),sgroup,App::Prop_None,"Number of isoparameters"); + ADD_PROPERTY_TYPE(CosmeticVertexList ,(""),sgroup,App::Prop_None,"CosmeticVertex Save/Restore"); + geometryObject = nullptr; getRunControl(); + +// Base::Vector3d org(0.0,0.0,0.0); //App side coords +// addRandomVertex(org); +// Base::Vector3d pt(11.0,11.0,0.0); +// addRandomVertex(pt); + } DrawViewPart::~DrawViewPart() @@ -279,6 +289,13 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) if (!keepUpdated()) { return App::DocumentObject::StdReturn; } + + //this is ghastly! but no convenient method for "object ready" + if (on1) { + rebuildCosmoVertex(); + on1 = false; + } + App::Document* doc = getDocument(); bool isRestoring = doc->testStatus(App::Document::Status::Restoring); const std::vector& links = Source.getValues(); @@ -324,6 +341,13 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) Rotation.getValue()); } geometryObject = buildGeometryObject(mirroredShape,viewAxis); + //add back the cosmetic vertices + Base::Console().Message("DVP::execute - cosmoVertex: %d \n",cosmoVertex.size()); + for (auto& v: cosmoVertex) { + Base::Console().Message("DVP::execute - adding random vertex\n"); + int idx = geometryObject->addRandomVertex(v->pageLocation * getScale()); + v->linkGeom = idx; + } #if MOD_TECHDRAW_HANDLE_FACES auto start = chrono::high_resolution_clock::now(); @@ -380,7 +404,6 @@ short DrawViewPart::mustExecute() const void DrawViewPart::onChanged(const App::Property* prop) { DrawView::onChanged(prop); - //TODO: when scale changes, any Dimensions for this View sb recalculated. DVD should pick this up subject to topological naming issues. } @@ -867,10 +890,34 @@ bool DrawViewPart::showSectionEdges(void) return m_sectionEdges; } +//build cosmoVertex from CosmeticVertexList +void DrawViewPart::rebuildCosmoVertex(void) +{ + Base::Console().Message("DVP::rebuildCosmoVertx()\n"); + cosmoVertex.clear(); + std::vector restoreVerts = CosmeticVertexList.getValues(); + Base::Console().Message("DVP::rebuildCosmoVertex - verts in: %d \n",restoreVerts.size()); + for (auto& rv: restoreVerts) { + if (!rv.empty()) { + CosmeticVertex* cv = new CosmeticVertex(); + bool rc = cv->fromCSV(rv); + if (rc) { +// int idx = geometryObject->addRandomVertex(cv->pageLocation * getScale()); +// cv->linkGeom = idx; + cosmoVertex.push_back(cv); + } else { + delete cv; + } + } + } + Base::Console().Message("DVP::rebuildCosmoVertex - cosmoVertexs: %d \n",cosmoVertex.size()); +} + //! remove features that are useless without this DVP //! hatches, geomhatches, dimensions,... void DrawViewPart::unsetupObject() { + Base::Console().Message("DVP::unsetupObject()\n"); nowUnsetting = true; App::Document* doc = getDocument(); std::string docName = doc->getName(); @@ -924,7 +971,6 @@ void DrawViewPart::unsetupObject() } } } - } //! is this an Isometric projection? @@ -939,6 +985,67 @@ bool DrawViewPart::isIso(void) const return result; } +//******** +//* Cosmetics +//******** + +// adds a cosmetic vertex to cosmoVertex and CosmeticVertexList +int DrawViewPart::addRandomVertex(Base::Vector3d pos) +{ +// Base::Console().Message("DVP::addRandomVertex(%s)\n", DrawUtil::formatVector(pos).c_str()); + int newIdx = -1; + TechDraw::CosmeticVertex* rVert = new TechDraw::CosmeticVertex(pos); + cosmoVertex.push_back(rVert); + + //stuff stringList + std::vector saveVerts; + const std::vector cosVerts = getCosmeticVertex(); + for (auto& cv: cosVerts) { + std::string csv = cv->toCSV(); + saveVerts.push_back(csv); + } + CosmeticVertexList.setValues(saveVerts); + Base::Console().Message("DVP::addRandomVertex - saveVerts: %d \n",saveVerts.size()); + + return newIdx; +} + +TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByIndex(int idx) const +{ +// Base::Console().Message("DVP::getCosmeticVertexByIndex(%d)\n", idx); + int cosmoOffset = 1000; + int realIdx = idx - cosmoOffset; + CosmeticVertex* result = nullptr; + const std::vector verts = getCosmeticVertex(); + if ((unsigned) realIdx < verts.size()) { + result = verts.at(realIdx); + } + return result; +} + +//find the cosmetic vertex corresponding to geometry vertex idx +TechDraw::CosmeticVertex* DrawViewPart::getCosmeticVertexByLink(int idx) const +{ +// Base::Console().Message("DVP::getVosmeticVertexByLinkIndex(%d)\n", idx); + CosmeticVertex* result = nullptr; + const std::vector verts = getCosmeticVertex(); + for (auto& cv: verts) { + if (cv->linkGeom == idx) { + result = cv; + break; + } + } + return result; +} + +void DrawViewPart::clearCV(void) +{ + Base::Console().Message("DVP::clearCV()\n"); + cosmoVertex.clear(); + std::vector noVerts; + CosmeticVertexList.setValues(noVerts); +} + PyObject *DrawViewPart::getPyObject(void) { if (PythonObject.is(Py::_None())) { diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 2287106455..6c7848b69f 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -68,6 +68,7 @@ class DrawProjectSplit; class DrawViewSection; class DrawViewDetail; class DrawViewBalloon; +class CosmeticVertex; } namespace TechDraw @@ -101,6 +102,8 @@ public: App::PropertyBool IsoHidden; App::PropertyInteger IsoCount; + App::PropertyStringList CosmeticVertexList; + std::vector getHatches(void) const; std::vector getGeomHatches(void) const; std::vector getDimensions() const; @@ -136,7 +139,7 @@ public: const bool flip=true) const; virtual short mustExecute() const; -/* virtual void onDocumentRestored() override;*/ +// virtual void onDocumentRestored() override; bool handleFaces(void); bool showSectionEdges(void); @@ -162,6 +165,12 @@ public: virtual TopoDS_Shape getSourceShapeFused(void) const; bool isIso(void) const; + virtual int addRandomVertex(Base::Vector3d pos); + const std::vector & getCosmeticVertex(void) const { return cosmoVertex; } + TechDraw::CosmeticVertex* getCosmeticVertexByIndex(int idx) const; + TechDraw::CosmeticVertex* getCosmeticVertexByLink(int idx) const; + void clearCV(void); + protected: TechDrawGeometry::GeometryObject *geometryObject; Base::BoundBox3d bbox; @@ -183,8 +192,13 @@ protected: bool m_sectionEdges; bool m_handleFaces; + //Cosmetics + std::vector cosmoVertex; + void rebuildCosmoVertex(void); + private: bool nowUnsetting; + bool on1; /* bool m_restoreComplete;*/ }; diff --git a/src/Mod/TechDraw/App/DrawViewPartPy.xml b/src/Mod/TechDraw/App/DrawViewPartPy.xml index fa2a9607d2..b5c923006b 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPy.xml +++ b/src/Mod/TechDraw/App/DrawViewPartPy.xml @@ -13,6 +13,11 @@ Feature for creating and manipulating Technical Drawing Part Views + + + clearCV() - remove all CosmeticVertices from the View. Returns nothing. + + diff --git a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp index 8afe123f35..337bf35f10 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp @@ -15,6 +15,14 @@ std::string DrawViewPartPy::representation(void) const return std::string(""); } +PyObject* DrawViewPartPy::clearCV(PyObject *args) +{ + (void) args; + DrawViewPart* item = getDrawViewPartPtr(); + item->clearCV(); + Py_INCREF(Py_None); + return Py_None; +} PyObject *DrawViewPartPy::getCustomAttributes(const char* /*attr*/) const { diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index f18832db0f..3a8cba7d79 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -67,11 +67,14 @@ #include #include #include +#include -#include +#include +#include + +#include "DrawUtil.h" #include "Geometry.h" -#include "DrawUtil.h" using namespace TechDrawGeometry; using namespace TechDraw; @@ -955,3 +958,5 @@ BaseGeomPtrVector GeometryUtils::chainGeoms(BaseGeomPtrVector geoms) } return result; } + + diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 1bf2b8e454..a17feb1598 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -472,6 +472,15 @@ void GeometryObject::addGeomFromCompound(TopoDS_Shape edgeCompound, edgeClass ca } //end TopExp } +int GeometryObject::addRandomVertex(Base::Vector3d pos) +{ +// Base::Console().Message("GO::addRandomVertex(%s)\n",DrawUtil::formatVector(pos).c_str()); + TechDrawGeometry::Vertex* v = new TechDrawGeometry::Vertex(pos.x, - pos.y); + vertexGeom.push_back(v); + int idx = vertexGeom.size() - 1; + return idx; +} + //! empty Face geometry void GeometryObject::clearFaceGeom() { diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h index 4a33dd130b..ec5ae78c79 100644 --- a/src/Mod/TechDraw/App/GeometryObject.h +++ b/src/Mod/TechDraw/App/GeometryObject.h @@ -125,6 +125,9 @@ public: TopoDS_Shape getHidSeam(void) { return hidSeam; } TopoDS_Shape getHidIso(void) { return hidIso; } + int addRandomVertex(Base::Vector3d pos); + + protected: //HLR output TopoDS_Shape visHard; diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp index 7d49d667f1..fba82bd380 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -64,6 +64,7 @@ void CreateTechDrawCommands(void); void CreateTechDrawCommandsDims(void); void CreateTechDrawCommandsDecorate(void); +void CreateTechDrawCommandsAnnotate(void); void loadTechDrawResource() { @@ -108,6 +109,7 @@ PyMOD_INIT_FUNC(TechDrawGui) CreateTechDrawCommands(); CreateTechDrawCommandsDims(); CreateTechDrawCommandsDecorate(); + CreateTechDrawCommandsAnnotate(); TechDrawGui::Workbench::init(); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 9c5b46b250..769f0e33e6 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -41,6 +41,7 @@ set(TechDrawGui_MOC_HDRS TaskGeomHatch.h TaskLeaderLine.h TaskRichAnno.h + TaskCosVertex.h QGEPath.h QGTracker.h QGILeaderLine.h @@ -72,7 +73,8 @@ set(TechDrawGui_UIC_SRCS TaskRichAnno.ui mrichtextedit.ui TaskBalloon.ui - ) + TaskCosVertex.ui +) if(BUILD_QT5) qt5_wrap_ui(TechDrawGui_UIC_HDRS ${TechDrawGui_UIC_SRCS}) @@ -102,6 +104,7 @@ SET(TechDrawGui_SRCS Command.cpp CommandCreateDims.cpp CommandDecorate.cpp + CommandAnnotate.cpp Resources/TechDraw.qrc PreCompiled.cpp PreCompiled.h @@ -137,6 +140,9 @@ SET(TechDrawGui_SRCS TaskRichAnno.ui TaskRichAnno.cpp TaskRichAnno.h + TaskCosVertex.ui + TaskCosVertex.cpp + TaskCosVertex.h DrawGuiUtil.cpp DrawGuiUtil.h Rez.cpp @@ -285,6 +291,7 @@ SET(TechDrawGuiTaskDlgs_SRCS TaskGeomHatch.ui TaskLeaderLine.ui TaskRichAnno.ui + TaskCosVertex.ui mrichtextedit.ui TaskBalloon.ui ) diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index a13c7d618f..a9f126e75e 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -63,7 +63,6 @@ #include #include #include -#include #include #include #include @@ -641,46 +640,6 @@ bool CmdTechDrawProjGroup::isActive(void) // return DrawGuiUtil::needPage(this); //} -//=========================================================================== -// TechDraw_Annotation -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawAnnotation); - -CmdTechDrawAnnotation::CmdTechDrawAnnotation() - : Command("TechDraw_Annotation") -{ - // setting the Gui eye-candy - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Insert Annotation"); - sToolTipText = QT_TR_NOOP("Insert Annotation"); - sWhatsThis = "TechDraw_NewAnnotation"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-annotation"; -} - -void CmdTechDrawAnnotation::activated(int iMsg) -{ - Q_UNUSED(iMsg); - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - std::string PageName = page->getNameInDocument(); - - std::string FeatName = getUniqueObjectName("Annotation"); - openCommand("Create Annotation"); - doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewAnnotation','%s')",FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); - updateActive(); - commitCommand(); -} - -bool CmdTechDrawAnnotation::isActive(void) -{ - return DrawGuiUtil::needPage(this); -} - //=========================================================================== // TechDraw_NewBalloon //=========================================================================== @@ -1292,8 +1251,6 @@ bool CmdTechDrawExportPageDxf::isActive(void) return DrawGuiUtil::needPage(this); } - - void CreateTechDrawCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -1305,7 +1262,7 @@ void CreateTechDrawCommands(void) rcCmdMgr.addCommand(new CmdTechDrawNewViewDetail()); // rcCmdMgr.addCommand(new CmdTechDrawNewMulti()); //deprecated rcCmdMgr.addCommand(new CmdTechDrawProjGroup()); - rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); +// rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); rcCmdMgr.addCommand(new CmdTechDrawClip()); rcCmdMgr.addCommand(new CmdTechDrawClipPlus()); rcCmdMgr.addCommand(new CmdTechDrawClipMinus()); diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp new file mode 100644 index 0000000000..e1613f5e5c --- /dev/null +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -0,0 +1,406 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +# include +#endif //#ifndef _PreComp_ + +#include + +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include +# include + +# include + +#include +#include +#include +#include +#include +#include + +#include "DrawGuiUtil.h" +#include "MDIViewPage.h" +#include "TaskLeaderLine.h" +#include "TaskRichAnno.h" +#include "TaskCosVertex.h" +#include "ViewProviderPage.h" + +using namespace TechDrawGui; +using namespace std; + + +//internal functions +bool _checkSelectionHatch(Gui::Command* cmd); + +//=========================================================================== +// TechDraw_Leader +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawLeaderLine); + +CmdTechDrawLeaderLine::CmdTechDrawLeaderLine() + : Command("TechDraw_LeaderLine") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add a line to a view"); + sToolTipText = QT_TR_NOOP("Add a line to a view"); + sWhatsThis = "TechDraw_LeaderLine"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-mline"; +} + +void CmdTechDrawLeaderLine::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg != nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), + QObject::tr("Close active task dialog and try again.")); + return; + } + + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawView* baseFeat = nullptr; + if (!selection.empty()) { + baseFeat = dynamic_cast(selection[0].getObject()); + if( baseFeat == nullptr ) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), + QObject::tr("Can not attach leader. No base View selected.")); + return; + } + } else { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), + QObject::tr("You must select a base View for the line.")); + return; + } + + Gui::Control().showDialog(new TechDrawGui::TaskDlgLeaderLine(baseFeat, + page)); +} + +bool CmdTechDrawLeaderLine::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, false); + return (havePage && haveView); +} + +//=========================================================================== +// TechDraw_RichAnno +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawRichAnno); + +CmdTechDrawRichAnno::CmdTechDrawRichAnno() + : Command("TechDraw_RichAnno") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add a rich text annotation"); + sToolTipText = QT_TR_NOOP("Add a rich text annotation"); + sWhatsThis = "TechDraw_RichAnno"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-textleader"; +} + +void CmdTechDrawRichAnno::activated(int iMsg) +{ + Q_UNUSED(iMsg); + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg != nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), + QObject::tr("Close active task dialog and try again.")); + return; + } + + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawView* baseFeat = nullptr; + if (!selection.empty()) { + baseFeat = dynamic_cast(selection[0].getObject()); +// if( baseFeat == nullptr ) { +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), +// QObject::tr("Can not attach leader. No base View selected.")); +// return; +// } +// } else { +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), +// QObject::tr("You must select a base View for the line.")); +// return; + } + + Gui::Control().showDialog(new TaskDlgRichAnno(baseFeat, + page)); +} + +bool CmdTechDrawRichAnno::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, false); + return (havePage && haveView); +} + +//=========================================================================== +// TechDraw_CosmeticVertex +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawCosmeticVertex); + +CmdTechDrawCosmeticVertex::CmdTechDrawCosmeticVertex() + : Command("TechDraw_CosmeticVertex") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add a cosmetic vertex"); + sToolTipText = QT_TR_NOOP("Add a cosmetic vertex"); + sWhatsThis = "TechDraw_CosmeticVertex"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-point"; +} + +void CmdTechDrawCosmeticVertex::activated(int iMsg) +{ + Q_UNUSED(iMsg); + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg != nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), + QObject::tr("Close active task dialog and try again.")); + return; + } + + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector shapes = getSelection(). + getObjectsOfType(TechDraw::DrawViewPart::getClassTypeId()); + if (shapes.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("No DrawViewPart objects in this selection")); + return; + } + + TechDraw::DrawViewPart* baseFeat = nullptr; + baseFeat = dynamic_cast((*shapes.begin())); + if (baseFeat == nullptr) { + Base::Console().Message("CMD::CosmeticVertex - 1st shape is not DVP. WTF?\n"); + return; + } + + Gui::Control().showDialog(new TaskDlgCosVertex(baseFeat, + page)); +} + +bool CmdTechDrawCosmeticVertex::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, false); + return (havePage && haveView); +} + +//=========================================================================== +// TechDraw_Midpoints +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawMidpoints); + +CmdTechDrawMidpoints::CmdTechDrawMidpoints() + : Command("TechDraw_Midpoints") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add midpoint vertices"); + sToolTipText = QT_TR_NOOP("Add midpoint vertices"); + sWhatsThis = "TechDraw_Midpoints"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-midpoint"; +} + +void CmdTechDrawMidpoints::activated(int iMsg) +{ + Q_UNUSED(iMsg); + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg != nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), + QObject::tr("Close active task dialog and try again.")); + return; + } + + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector selection = getSelection().getSelectionEx(); +// TechDraw::DrawView* baseFeat = nullptr; +// if (!selection.empty()) { +// baseFeat = dynamic_cast(selection[0].getObject()); +// } + +// Gui::Control().showDialog(new TaskDlgMidpoints(baseFeat, +// page)); + Base::Console().Message("CMD::Midpoints - start dialog here!\n"); +} + +bool CmdTechDrawMidpoints::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, false); + return (havePage && haveView); +} + +//=========================================================================== +// TechDraw_Quadrant +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawQuadrant); + +CmdTechDrawQuadrant::CmdTechDrawQuadrant() + : Command("TechDraw_Quadrant") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add quadrant vertices"); + sToolTipText = QT_TR_NOOP("Add quadrant vertices"); + sWhatsThis = "TechDraw_Quadrant"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-quadrant"; +} + +void CmdTechDrawQuadrant::activated(int iMsg) +{ + Q_UNUSED(iMsg); + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg != nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), + QObject::tr("Close active task dialog and try again.")); + return; + } + + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + + std::vector selection = getSelection().getSelectionEx(); +// TechDraw::DrawView* baseFeat = nullptr; +// if (!selection.empty()) { +// baseFeat = dynamic_cast(selection[0].getObject()); +// } + +// Gui::Control().showDialog(new TaskDlgQuadrant(baseFeat, +// page)); + Base::Console().Message("CMD::Quadrant - start dialog here!\n"); +} + +bool CmdTechDrawQuadrant::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, false); + return (havePage && haveView); +} + +//=========================================================================== +// TechDraw_Annotation +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawAnnotation); + +CmdTechDrawAnnotation::CmdTechDrawAnnotation() + : Command("TechDraw_Annotation") +{ + // setting the Gui eye-candy + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Insert Annotation"); + sToolTipText = QT_TR_NOOP("Insert Annotation"); + sWhatsThis = "TechDraw_NewAnnotation"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-annotation"; +} + +void CmdTechDrawAnnotation::activated(int iMsg) +{ + Q_UNUSED(iMsg); + TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); + if (!page) { + return; + } + std::string PageName = page->getNameInDocument(); + + std::string FeatName = getUniqueObjectName("Annotation"); + openCommand("Create Annotation"); + doCommand(Doc,"App.activeDocument().addObject('TechDraw::DrawViewAnnotation','%s')",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); + updateActive(); + commitCommand(); +} + +bool CmdTechDrawAnnotation::isActive(void) +{ + return DrawGuiUtil::needPage(this); +} + +void CreateTechDrawCommandsAnnotate(void) +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + + rcCmdMgr.addCommand(new CmdTechDrawLeaderLine()); + rcCmdMgr.addCommand(new CmdTechDrawRichAnno()); + rcCmdMgr.addCommand(new CmdTechDrawCosmeticVertex()); + rcCmdMgr.addCommand(new CmdTechDrawMidpoints()); + rcCmdMgr.addCommand(new CmdTechDrawQuadrant()); + rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); +} + +//=========================================================================== +// Selection Validation Helpers +//=========================================================================== + + diff --git a/src/Mod/TechDraw/Gui/CommandDecorate.cpp b/src/Mod/TechDraw/Gui/CommandDecorate.cpp index 99368484a2..8c544222b4 100644 --- a/src/Mod/TechDraw/Gui/CommandDecorate.cpp +++ b/src/Mod/TechDraw/Gui/CommandDecorate.cpp @@ -69,103 +69,44 @@ using namespace std; //internal functions bool _checkSelectionHatch(Gui::Command* cmd); -//=========================================================================== -// TechDraw_Leader -//=========================================================================== +////=========================================================================== +//// TechDraw_Leader +////=========================================================================== -DEF_STD_CMD_A(CmdTechDrawLeaderLine); +//DEF_STD_CMD_A(CmdTechDrawLeaderLine); -CmdTechDrawLeaderLine::CmdTechDrawLeaderLine() - : Command("TechDraw_LeaderLine") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add a line to a view"); - sToolTipText = QT_TR_NOOP("Add a line to a view"); - sWhatsThis = "TechDraw_LeaderLine"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-mline"; -} +//CmdTechDrawLeaderLine::CmdTechDrawLeaderLine() +// : Command("TechDraw_LeaderLine") +//{ +// sAppModule = "TechDraw"; +// sGroup = QT_TR_NOOP("TechDraw"); +// sMenuText = QT_TR_NOOP("Add a line to a view"); +// sToolTipText = QT_TR_NOOP("Add a line to a view"); +// sWhatsThis = "TechDraw_LeaderLine"; +// sStatusTip = sToolTipText; +// sPixmap = "actions/techdraw-mline"; +//} -void CmdTechDrawLeaderLine::activated(int iMsg) -{ - Q_UNUSED(iMsg); +//void CmdTechDrawLeaderLine::activated(int iMsg) +//{ +// Q_UNUSED(iMsg); - Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); - if (dlg != nullptr) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), - QObject::tr("Close active task dialog and try again.")); - return; - } +// Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); +// if (dlg != nullptr) { +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), +// QObject::tr("Close active task dialog and try again.")); +// return; +// } - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } +// TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); +// if (!page) { +// return; +// } - std::vector selection = getSelection().getSelectionEx(); - TechDraw::DrawView* baseFeat = nullptr; - if (!selection.empty()) { - baseFeat = dynamic_cast(selection[0].getObject()); - if( baseFeat == nullptr ) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("Can not attach leader. No base View selected.")); - return; - } - } else { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), - QObject::tr("You must select a base View for the line.")); - return; - } - - Gui::Control().showDialog(new TechDrawGui::TaskDlgLeaderLine(baseFeat, - page)); -} - -bool CmdTechDrawLeaderLine::isActive(void) -{ - bool havePage = DrawGuiUtil::needPage(this); - bool haveView = DrawGuiUtil::needView(this, false); - return (havePage && haveView); -} - -//=========================================================================== -// TechDraw_RichAnno -//=========================================================================== - -DEF_STD_CMD_A(CmdTechDrawRichAnno); - -CmdTechDrawRichAnno::CmdTechDrawRichAnno() - : Command("TechDraw_RichAnno") -{ - sAppModule = "TechDraw"; - sGroup = QT_TR_NOOP("TechDraw"); - sMenuText = QT_TR_NOOP("Add a rich text annotation"); - sToolTipText = QT_TR_NOOP("Add a rich text annotation"); - sWhatsThis = "TechDraw_RichAnno"; - sStatusTip = sToolTipText; - sPixmap = "actions/techdraw-textleader"; -} - -void CmdTechDrawRichAnno::activated(int iMsg) -{ - Q_UNUSED(iMsg); - Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); - if (dlg != nullptr) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), - QObject::tr("Close active task dialog and try again.")); - return; - } - - TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); - if (!page) { - return; - } - - std::vector selection = getSelection().getSelectionEx(); - TechDraw::DrawView* baseFeat = nullptr; - if (!selection.empty()) { - baseFeat = dynamic_cast(selection[0].getObject()); +// std::vector selection = getSelection().getSelectionEx(); +// TechDraw::DrawView* baseFeat = nullptr; +// if (!selection.empty()) { +// baseFeat = dynamic_cast(selection[0].getObject()); // if( baseFeat == nullptr ) { // QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), // QObject::tr("Can not attach leader. No base View selected.")); @@ -175,18 +116,77 @@ void CmdTechDrawRichAnno::activated(int iMsg) // QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), // QObject::tr("You must select a base View for the line.")); // return; - } +// } - Gui::Control().showDialog(new TaskDlgRichAnno(baseFeat, - page)); -} +// Gui::Control().showDialog(new TechDrawGui::TaskDlgLeaderLine(baseFeat, +// page)); +//} -bool CmdTechDrawRichAnno::isActive(void) -{ - bool havePage = DrawGuiUtil::needPage(this); - bool haveView = DrawGuiUtil::needView(this, false); - return (havePage && haveView); -} +//bool CmdTechDrawLeaderLine::isActive(void) +//{ +// bool havePage = DrawGuiUtil::needPage(this); +// bool haveView = DrawGuiUtil::needView(this, false); +// return (havePage && haveView); +//} + +////=========================================================================== +//// TechDraw_RichAnno +////=========================================================================== + +//DEF_STD_CMD_A(CmdTechDrawRichAnno); + +//CmdTechDrawRichAnno::CmdTechDrawRichAnno() +// : Command("TechDraw_RichAnno") +//{ +// sAppModule = "TechDraw"; +// sGroup = QT_TR_NOOP("TechDraw"); +// sMenuText = QT_TR_NOOP("Add a rich text annotation"); +// sToolTipText = QT_TR_NOOP("Add a rich text annotation"); +// sWhatsThis = "TechDraw_RichAnno"; +// sStatusTip = sToolTipText; +// sPixmap = "actions/techdraw-textleader"; +//} + +//void CmdTechDrawRichAnno::activated(int iMsg) +//{ +// Q_UNUSED(iMsg); +// Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); +// if (dlg != nullptr) { +// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Task In Progress"), +// QObject::tr("Close active task dialog and try again.")); +// return; +// } + +// TechDraw::DrawPage* page = DrawGuiUtil::findPage(this); +// if (!page) { +// return; +// } + +// std::vector selection = getSelection().getSelectionEx(); +// TechDraw::DrawView* baseFeat = nullptr; +// if (!selection.empty()) { +// baseFeat = dynamic_cast(selection[0].getObject()); +//// if( baseFeat == nullptr ) { +//// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), +//// QObject::tr("Can not attach leader. No base View selected.")); +//// return; +//// } +//// } else { +//// QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), +//// QObject::tr("You must select a base View for the line.")); +//// return; +// } + +// Gui::Control().showDialog(new TaskDlgRichAnno(baseFeat, +// page)); +//} + +//bool CmdTechDrawRichAnno::isActive(void) +//{ +// bool havePage = DrawGuiUtil::needPage(this); +// bool haveView = DrawGuiUtil::needView(this, false); +// return (havePage && haveView); +//} //=========================================================================== // TechDraw_NewHatch @@ -469,8 +469,8 @@ void CreateTechDrawCommandsDecorate(void) rcCmdMgr.addCommand(new CmdTechDrawImage()); rcCmdMgr.addCommand(new CmdTechDrawToggleFrame()); // rcCmdMgr.addCommand(new CmdTechDrawRedrawPage()); - rcCmdMgr.addCommand(new CmdTechDrawLeaderLine()); - rcCmdMgr.addCommand(new CmdTechDrawRichAnno()); +// rcCmdMgr.addCommand(new CmdTechDrawLeaderLine()); +// rcCmdMgr.addCommand(new CmdTechDrawRichAnno()); } //=========================================================================== diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 339753c43d..cb0750fc52 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -50,6 +50,7 @@ #include #include +#include #include #include #include @@ -57,6 +58,8 @@ #include #include #include +#include +#include #include "Rez.h" #include "ZVALUE.h" @@ -77,6 +80,7 @@ #include "ViewProviderViewPart.h" #include "MDIViewPage.h" +using namespace TechDraw; using namespace TechDrawGui; using namespace TechDrawGeometry; @@ -458,6 +462,23 @@ void QGIViewPart::drawViewPart() // dumpPath(edgeId.str().c_str(),edgePath); } } + // Draw Cosmetic Edges +// int cosmoEdgeStart = 1000; +// const std::vector &cEdges = viewPart->getEdgeCosmetic(); +// std::vector::const_iterator itcEdge = cEdges.begin(); +// QGIEdge* item; +// for(int i = 0 ; itcEdge != cEdges.end(); itcEdge++, i++) { +// item = new QGIEdge(cosmoEdgeStart + i); +// addToGroup(item); +// item->setPos(0.0,0.0); +//// item->setPath(drawPainterPath(*itcEdge)); //this won't work +// item->setWidth((*itcEdge)->width); +// item->setColor((*itcEdge)->color.asValue(); +// item->setZValue(ZVALUE::EDGE); +// item->setPrettyNormal(); +// +// } + // Draw Vertexs: Base::Reference hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> @@ -487,14 +508,42 @@ void QGIViewPart::drawViewPart() } } else if(!usePolygonHLR){ //Disable dots WHEN usePolygonHLR QGIVertex *item = new QGIVertex(i); - item->setNormalColor(vertexColor); + TechDraw::CosmeticVertex* cv = viewPart->getCosmeticVertexByLink(i); + if (cv != nullptr) { + Base::Console().Message("QGIVP::draw - found a cv!\n"); + cv->dump("QGIVP::draw"); +// item->setNormalColor(vertexColor); + item->setNormalColor(cv->color.asValue()); + item->setRadius(cv->size); +// item->setRadius(lineWidth * vertexScaleFactor); +// item->setStyle(cv->style); + } else { + item->setNormalColor(vertexColor); + item->setRadius(lineWidth * vertexScaleFactor); + } item->setPrettyNormal(); addToGroup(item); item->setPos(Rez::guiX((*vert)->pnt.x), Rez::guiX((*vert)->pnt.y)); - item->setRadius(lineWidth * vertexScaleFactor); item->setZValue(ZVALUE::VERTEX); } } +// //draw cosmetic vertices +// int cosmoVertStart = 1000; +// std::vector cVerts = viewPart->getCosmeticVertex(); +// Base::Console().Message("QGIVP::draw - %s - cVerts: %d\n",getViewName(),cVerts.size()); +// std::vector::const_iterator itcVert = cVerts.begin(); +// for(int i = 0 ; itcVert != cVerts.end(); ++itcVert, i++) { +// QGIVertex *item = new QGIVertex(cosmoVertStart + i); +// item->setNormalColor((*itcVert)->color.asValue()); +// item->setPrettyNormal(); +// addToGroup(item); +// //TODO: need to apply scale to position unless position is already scaled +// item->setPos(Rez::guiX((*itcVert)->pageLocation.x), - Rez::guiX((*itcVert)->pageLocation.y)); +// item->setRadius((*itcVert)->size); +// item->setStyle((Qt::PenStyle)(*itcVert)->style); +// item->setZValue(ZVALUE::VERTEX); +// Base::Console().Message("QGIVP::draw - cVert.toCSV: %s \n",(*itcVert)->toCSV().c_str()); +// } } //draw detail highlights diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.h b/src/Mod/TechDraw/Gui/QGIViewPart.h index 7822302a45..51bff1994f 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.h +++ b/src/Mod/TechDraw/Gui/QGIViewPart.h @@ -35,6 +35,7 @@ class DrawViewSection; class DrawHatch; class DrawGeomHatch; class DrawViewDetail; +class DrawView; } namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/QGTracker.cpp b/src/Mod/TechDraw/Gui/QGTracker.cpp index ebf97c8a39..4684801e40 100644 --- a/src/Mod/TechDraw/Gui/QGTracker.cpp +++ b/src/Mod/TechDraw/Gui/QGTracker.cpp @@ -181,7 +181,7 @@ void QGTracker::hoverMoveEvent(QGraphicsSceneHoverEvent* event) void QGTracker::keyPressEvent(QKeyEvent * event) { -// Base::Console().Message("QGT::keyPressEvent()\n"); + Base::Console().Message("QGT::keyPressEvent()\n"); if (event->key() == Qt::Key_Escape) { terminateDrawing(); } @@ -237,6 +237,7 @@ QPointF QGTracker::snapToAngle(QPointF dumbPt) //mouse event reactions void QGTracker::onMousePress(QPointF pos) { + Base::Console().Message("QGT::onMousePress(%s)\n", TechDraw::DrawUtil::formatVector(pos).c_str()); m_points.push_back(pos); TrackerMode mode = getTrackerMode(); if (m_points.size() > 1) { @@ -254,18 +255,21 @@ void QGTracker::onMousePress(QPointF pos) break; case TrackerMode::Point: //do nothing +// setPoint(m_points); break; } - } else if (m_points.size() == 1) { //first point selected + } else if (m_points.size() == 1) { //first point selected + Base::Console().Message("QGT::onMousePress - m_points.size == 1\n"); getPickedQGIV(pos); setCursor(Qt::CrossCursor); - Q_EMIT qViewPicked(pos, m_qgParent); +// Q_EMIT qViewPicked(pos, m_qgParent); //not in use yet. if (mode == TrackerMode::Point) { + Base::Console().Message("QGT::onMousePress - mode = Point\n"); setPoint(m_points); terminateDrawing(); } } - + if ( (m_points.size() == 2) && ( (getTrackerMode() == TrackerMode::Circle) || (getTrackerMode() == TrackerMode::Rectangle) ) ) { //only 2 points for square/circle @@ -297,8 +301,12 @@ void QGTracker::onMouseMove(QPointF pos) void QGTracker::onDoubleClick(QPointF pos) { -// Base::Console().Message("QGTracker::onDoubleClick()\n"); + Base::Console().Message("QGTracker::onDoubleClick()\n"); Q_UNUSED(pos); + TrackerMode mode = getTrackerMode(); + if (mode == TrackerMode::Point) { + setPoint(m_points); + } terminateDrawing(); } @@ -448,7 +456,7 @@ void QGTracker::setPoint(std::vector pts) prepareGeometryChange(); QPainterPath newPath; QPointF center = pts.front(); - double radius = 5.0; + double radius = 50.0; newPath.addEllipse(center, radius, radius); setPath(newPath); setPrettyNormal(); @@ -466,7 +474,7 @@ std::vector QGTracker::convertPoints(void) void QGTracker::terminateDrawing(void) { -// Base::Console().Message("QGTracker::terminateDrawing()\n"); + Base::Console().Message("QGTracker::terminateDrawing()\n"); m_track->hide(); setCursor(Qt::ArrowCursor); Q_EMIT drawingFinished(m_points, m_qgParent); diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 5bc826b0dd..2ffcc25fcb 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -63,6 +63,8 @@ icons/actions/techdraw-mline.svg icons/actions/techdraw-textleader.svg icons/actions/techdraw-point.svg + icons/actions/techdraw-midpoint.svg + icons/actions/techdraw-quadrant.svg icons/actions/section-up.svg icons/actions/section-down.svg icons/actions/section-left.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-annotation.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-annotation.svg index 28443ce2c8..66887bea9c 100755 --- a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-annotation.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-annotation.svg @@ -1,123 +1,716 @@ - - - - - + + + + + + - - - + + + - - - - + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - + + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - - + + + + + + - - - - - - - - + + + - + - + image/svg+xml - - + + [WandererFan] @@ -146,19 +739,30 @@ - - - - - - - - - - - - - - + + + + Abc diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-midpoint.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-midpoint.svg new file mode 100644 index 0000000000..5cbfba6bc5 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-midpoint.svg @@ -0,0 +1,290 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-mline.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-mline.svg index d333c2ed70..e55ec9ed4c 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-mline.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-mline.svg @@ -15,7 +15,7 @@ height="64" id="svg3085" sodipodi:docname="techdraw-mline.svg" - inkscape:version="0.92.3 (2405546, 2018-03-11)"> + inkscape:version="0.92.4 (unknown)"> image/svg+xml - + @@ -179,80 +179,83 @@ x="13.788582" y="46.145554" id="tspan3132" /> - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-point.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-point.svg index 13c123c3fd..02ff56a871 100644 --- a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-point.svg +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-point.svg @@ -30,8 +30,8 @@ id="namedview983" showgrid="true" inkscape:zoom="8.03125" - inkscape:cx="39.769112" - inkscape:cy="41.31852" + inkscape:cx="17.107633" + inkscape:cy="40.322411" inkscape:window-x="0" inkscape:window-y="26" inkscape:window-maximized="1" @@ -139,7 +139,7 @@ image/svg+xml - + @@ -154,7 +154,7 @@ id="tspan3132" /> + transform="matrix(2,0,0,2,-43.603159,-71.356076)"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/Rez.cpp b/src/Mod/TechDraw/Gui/Rez.cpp index 6cbb4b7bfa..72b847fb99 100644 --- a/src/Mod/TechDraw/Gui/Rez.cpp +++ b/src/Mod/TechDraw/Gui/Rez.cpp @@ -85,6 +85,11 @@ Base::Vector3d Rez::appX(Base::Vector3d v) return result; } +QPointF Rez::appX(QPointF p) +{ + return appPt(p); +} + //Misc conversions QPointF Rez::guiPt(QPointF p) diff --git a/src/Mod/TechDraw/Gui/Rez.h b/src/Mod/TechDraw/Gui/Rez.h index 11d8365977..c98ace0a54 100644 --- a/src/Mod/TechDraw/Gui/Rez.h +++ b/src/Mod/TechDraw/Gui/Rez.h @@ -47,6 +47,7 @@ public: static double appX(double x); static Base::Vector2d appX(Base::Vector2d v); static Base::Vector3d appX(Base::Vector3d v); + static QPointF appX(QPointF p); static QPointF guiPt(QPointF p); static QPointF appPt(QPointF p); diff --git a/src/Mod/TechDraw/Gui/TaskCosVertex.cpp b/src/Mod/TechDraw/Gui/TaskCosVertex.cpp new file mode 100644 index 0000000000..2ee2c141ed --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskCosVertex.cpp @@ -0,0 +1,391 @@ +/*************************************************************************** + * Copyright (c) 2019 Wandererfan +#endif // #ifndef _PreComp_ + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "DrawGuiStd.h" +#include "QGVPage.h" +#include "QGIView.h" +#include "QGIPrimPath.h" +#include "MDIViewPage.h" +#include "ViewProviderPage.h" +#include "QGTracker.h" +#include "QGEPath.h" +#include "Rez.h" + +#include "TaskCosVertex.h" + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +//ctor for creation +TaskCosVertex::TaskCosVertex(TechDraw::DrawViewPart* baseFeat, + TechDraw::DrawPage* page) : + ui(new Ui_TaskCosVertex), + m_tracker(nullptr), + m_baseFeat(baseFeat), + m_basePage(page), + m_createMode(true), + m_inProgressLock(false), + m_pbTrackerState(TRACKERPICK), + m_savePoint(QPointF(0.0,0.0)), + pointFromTracker(false) +{ + if ( (m_basePage == nullptr) || + (m_baseFeat == nullptr) ) { + //should be caught in CMD caller + Base::Console().Error("TaskCosVertex - bad parameters. Can not proceed.\n"); + return; + } + + ui->setupUi(this); + + Gui::Document* activeGui = Gui::Application::Instance->getDocument(m_basePage->getDocument()); + Gui::ViewProvider* vp = activeGui->getViewProvider(m_basePage); + ViewProviderPage* vpp = static_cast(vp); + m_mdi = vpp->getMDIViewPage(); + m_scene = m_mdi->m_scene; + m_view = m_mdi->getQGVPage(); + + setUiPrimary(); + + connect(ui->pbTracker, SIGNAL(clicked(bool)), + this, SLOT(onTrackerClicked(bool))); + + m_trackerMode = QGTracker::TrackerMode::Point; +} + +TaskCosVertex::~TaskCosVertex() +{ + delete ui; +} + +void TaskCosVertex::updateTask() +{ +// blockUpdate = true; + +// blockUpdate = false; +} + +void TaskCosVertex::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +void TaskCosVertex::setUiPrimary() +{ +// Base::Console().Message("TCV::setUiPrimary()\n"); + setWindowTitle(QObject::tr("New Cosmetic Vertex")); + + if (m_baseFeat != nullptr) { + std::string baseName = m_baseFeat->getNameInDocument(); + ui->leBaseView->setText(Base::Tools::fromStdString(baseName)); + } + ui->pbTracker->setText(QString::fromUtf8("Point Picker")); + ui->pbTracker->setEnabled(true); + ui->qsbX->setEnabled(true); + ui->qsbY->setEnabled(true); + ui->qsbZ->setEnabled(false); +} + +void TaskCosVertex::updateUi(void) +{ + //need to unscale & unRez m_savePoint for display +// double scale = m_baseFeat->getScale(); +// double x = Rez::appX(m_savePoint.x() / scale); +// double y = Rez::appX(- m_savePoint.y() / scale) ; + double x = m_savePoint.x(); + double y = - m_savePoint.y(); + double z = 0.0; + ui->qsbX->setValue(x); + ui->qsbY->setValue(y); + ui->qsbZ->setValue(z); +} + +void TaskCosVertex::addCosVertex(QPointF qPos) +{ +// Base::Console().Message("TCV::addCosVertex(%s)\n", TechDraw::DrawUtil::formatVector(qPos).c_str()); + Base::Vector3d pos(qPos.x(), -qPos.y()); +// int idx = + (void) m_baseFeat->addRandomVertex(pos); + m_baseFeat->requestPaint(); +} + + +//********** Tracker routines ******************************************************************* +void TaskCosVertex::onTrackerClicked(bool b) +{ + Q_UNUSED(b); + Base::Console().Message("TCV::onTrackerClicked() m_pbTrackerState: %d\n", + m_pbTrackerState); + if (m_pbTrackerState == TRACKERCANCEL) { + removeTracker(); + + m_pbTrackerState = TRACKERPICK; + ui->pbTracker->setText(QString::fromUtf8("Pick Points")); + enableTaskButtons(true); + + setEditCursor(Qt::ArrowCursor); + return; + } + + if (getCreateMode()) { + m_inProgressLock = true; + m_saveContextPolicy = m_mdi->contextMenuPolicy(); + m_mdi->setContextMenuPolicy(Qt::PreventContextMenu); + m_trackerMode = QGTracker::TrackerMode::Point; + setEditCursor(Qt::CrossCursor); + startTracker(); + + QString msg = tr("Pick a point for cosmetic vertex"); + getMainWindow()->statusBar()->show(); + Gui::getMainWindow()->showMessage(msg,3000); + ui->pbTracker->setText(QString::fromUtf8("Escape picking")); + ui->pbTracker->setEnabled(true); + m_pbTrackerState = TRACKERCANCEL; + enableTaskButtons(false); + } +} + +void TaskCosVertex::startTracker(void) +{ +// Base::Console().Message("TCV::startTracker()\n"); + if (m_trackerMode == QGTracker::TrackerMode::None) { + return; + } + + if (m_tracker == nullptr) { + m_tracker = new QGTracker(m_scene, m_trackerMode); + QObject::connect( + m_tracker, SIGNAL(drawingFinished(std::vector, QGIView*)), + this , SLOT (onTrackerFinished(std::vector, QGIView*)) + ); + } else { + //this is too harsh. but need to avoid restarting process + throw Base::RuntimeError("TechDrawNewLeader - tracker already active\n"); + } + setEditCursor(Qt::CrossCursor); + QString msg = tr("Left click to set a point"); + Gui::getMainWindow()->statusBar()->show(); + Gui::getMainWindow()->showMessage(msg,3000); +} + +void TaskCosVertex::onTrackerFinished(std::vector pts, QGIView* qgParent) +{ + Base::Console().Message("TCV::onTrackerFinished()\n"); + if (pts.empty()) { + Base::Console().Error("TaskCosVertex - no points available\n"); + return; + } + if (qgParent != nullptr) { + m_qgParent = qgParent; + } else { + //if vertex is outside of baseFeat, qgParent will be nullptr + QGVPage* qgvp = m_mdi->getQGVPage(); + QGIView* qgiv = qgvp->findQViewForDocObj(m_baseFeat); + m_qgParent = qgiv; + Base::Console().Message("TaskCosVertex - qgParent is nullptr\n"); +// return; + } + + //save point unscaled. + double scale = m_baseFeat->getScale(); + QPointF temp = pts.front(); + QPointF temp2 = m_qgParent->mapFromScene(temp) / scale; + m_savePoint = Rez::appX(temp2); + pointFromTracker = true; + updateUi(); + m_tracker->sleep(true); + m_inProgressLock = false; + ui->pbTracker->setEnabled(false); + enableTaskButtons(true); + setEditCursor(Qt::ArrowCursor); +} + +void TaskCosVertex::removeTracker(void) +{ +// Base::Console().Message("TCV::removeTracker()\n"); + if ( (m_tracker != nullptr) && + (m_tracker->scene() != nullptr) ) { + m_scene->removeItem(m_tracker); + delete m_tracker; + m_tracker = nullptr; + } +} + +void TaskCosVertex::setEditCursor(QCursor c) +{ + if (m_baseFeat != nullptr) { + QGIView* qgivBase = m_view->findQViewForDocObj(m_baseFeat); + qgivBase->setCursor(c); + } +} + +void TaskCosVertex::abandonEditSession(void) +{ + QString msg = tr("In progress edit abandoned. Start over."); + getMainWindow()->statusBar()->show(); + Gui::getMainWindow()->showMessage(msg,4000); + + ui->pbTracker->setEnabled(true); + + setEditCursor(Qt::ArrowCursor); +} + +void TaskCosVertex::saveButtons(QPushButton* btnOK, + QPushButton* btnCancel) +{ + m_btnOK = btnOK; + m_btnCancel = btnCancel; +} + +void TaskCosVertex::enableTaskButtons(bool b) +{ + m_btnOK->setEnabled(b); + m_btnCancel->setEnabled(b); +} + +//****************************************************************************** +bool TaskCosVertex::accept() +{ +// Base::Console().Message("TCV::accept()\n"); + + Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument()); + if (!doc) return false; + + removeTracker(); + if (pointFromTracker) { + addCosVertex(m_savePoint); + } else { + double x = ui->qsbX->rawValue(); + double y = ui->qsbY->rawValue(); +// double z = ui->qsbZ->rawValue(); + QPointF uiPoint(x,-y); + addCosVertex(uiPoint); + } + m_baseFeat->recomputeFeature(); + m_baseFeat->requestPaint(); + m_mdi->setContextMenuPolicy(m_saveContextPolicy); + m_trackerMode = QGTracker::TrackerMode::None; + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return true; +} + +bool TaskCosVertex::reject() +{ + Gui::Document* doc = Gui::Application::Instance->getDocument(m_basePage->getDocument()); + if (!doc) return false; + + if (m_mdi != nullptr) { + m_mdi->setContextMenuPolicy(m_saveContextPolicy); + } + m_trackerMode = QGTracker::TrackerMode::None; + + //make sure any dangling objects are cleaned up + Gui::Command::doCommand(Gui::Command::Gui,"App.activeDocument().recompute()"); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return false; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgCosVertex::TaskDlgCosVertex(TechDraw::DrawViewPart* baseFeat, + TechDraw::DrawPage* page) + : TaskDialog() +{ + widget = new TaskCosVertex(baseFeat,page); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-mline"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgCosVertex::~TaskDlgCosVertex() +{ +} + +void TaskDlgCosVertex::update() +{ +// widget->updateTask(); +} + +void TaskDlgCosVertex::modifyStandardButtons(QDialogButtonBox* box) +{ + QPushButton* btnOK = box->button(QDialogButtonBox::Ok); + QPushButton* btnCancel = box->button(QDialogButtonBox::Cancel); + widget->saveButtons(btnOK, btnCancel); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgCosVertex::open() +{ +} + +void TaskDlgCosVertex::clicked(int) +{ +} + +bool TaskDlgCosVertex::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgCosVertex::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskCosVertex.h b/src/Mod/TechDraw/Gui/TaskCosVertex.h new file mode 100644 index 0000000000..21072877c0 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskCosVertex.h @@ -0,0 +1,175 @@ +/*************************************************************************** + * Copyright (c) 2019 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_TASKCOSVERTEX_H +#define TECHDRAWGUI_TASKCOSVERTEX_H + +#include +#include +#include +#include + +#include + +#include "QGTracker.h" + +//TODO: make this a proper enum +#define TRACKERPICK 0 +#define TRACKEREDIT 1 +#define TRACKERCANCEL 2 +#define TRACKERCANCELEDIT 3 + +class Ui_TaskCosVertex; + +namespace App { +class DocumentObject; +} + +namespace TechDraw +{ +class DrawPage; +class DrawView; +class DrawCosVertex; +} + +namespace TechDrawGui +{ +class QGVPage; +class QGIView; +class QGIPrimPath; +class MDIViewPage; +class QGTracker; +class QGEPath; +class QGMText; +class QGICosVertex; +class ViewProviderLeader; + +class TaskCosVertex : public QWidget +{ + Q_OBJECT + +public: + TaskCosVertex(TechDraw::DrawViewPart* baseFeat, + TechDraw::DrawPage* page); +/* TaskCosVertex(TechDrawGui::ViewProviderLeader* leadVP);*/ + ~TaskCosVertex(); + +public Q_SLOTS: + void onTrackerClicked(bool b); + void onTrackerFinished(std::vector pts, QGIView* qgParent); + +public: + virtual bool accept(); + virtual bool reject(); + virtual void setCreateMode(bool b) { m_createMode = b; } + virtual bool getCreateMode(void) { return m_createMode; } + void updateTask(); + void saveButtons(QPushButton* btnOK, + QPushButton* btnCancel); + void enableTaskButtons(bool b); + +/*protected Q_SLOTS:*/ +/* void onPointPicked(QPointF pt);*/ + +protected: + void changeEvent(QEvent *e); + void startTracker(void); + void removeTracker(void); + void abandonEditSession(void); + + void addCosVertex(QPointF qPos); + + void blockButtons(bool b); + void setUiPrimary(void); + void updateUi(void); + void setEditCursor(QCursor c); + + QGIView* findParentQGIV(); + +private: + Ui_TaskCosVertex * ui; + bool blockUpdate; + + QGTracker* m_tracker; + + MDIViewPage* m_mdi; + QGraphicsScene* m_scene; + QGVPage* m_view; +/* ViewProviderLeader* m_lineVP;*/ + TechDraw::DrawViewPart* m_baseFeat; + TechDraw::DrawPage* m_basePage; +/* TechDraw::DrawCosVertex* m_lineFeat;*/ +/* std::string m_leaderName;*/ +/* std::string m_leaderType;*/ + QGIView* m_qgParent; + std::string m_qgParentName; + + bool m_createMode; + + QGTracker::TrackerMode m_trackerMode; + Qt::ContextMenuPolicy m_saveContextPolicy; + bool m_inProgressLock; + + QPushButton* m_btnOK; + QPushButton* m_btnCancel; + + int m_pbTrackerState; + QPointF m_savePoint; + bool pointFromTracker; +}; + +class TaskDlgCosVertex : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgCosVertex(TechDraw::DrawViewPart* baseFeat, + TechDraw::DrawPage* page); + ~TaskDlgCosVertex(); + +public: + /// is called the TaskView when the dialog is opened + virtual void open(); + /// is called by the framework if an button is clicked which has no accept or reject role + virtual void clicked(int); + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept(); + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + /// is called by the framework if the user presses the help button + virtual void helpRequested() { return;} + virtual bool isAllowedAlterDocument(void) const + { return false; } + void update(); + + void modifyStandardButtons(QDialogButtonBox* box); + +protected: + +private: + TaskCosVertex * widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef TECHDRAWGUI_TASKCOSVERTEX_H diff --git a/src/Mod/TechDraw/Gui/TaskCosVertex.ui b/src/Mod/TechDraw/Gui/TaskCosVertex.ui new file mode 100644 index 0000000000..0c7efcae63 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskCosVertex.ui @@ -0,0 +1,211 @@ + + + TechDrawGui::TaskCosVertex + + + + 0 + 0 + 409 + 405 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Cosmetic Vertex + + + + :/icons/actions/techdraw-point.svg:/icons/actions/techdraw-point.svg + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Raised + + + + + + + + + + false + + + false + + + Qt::NoFocus + + + false + + + + + + + Base View + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Point Picker + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + X + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Z + + + + + + + Y + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+
+ + + + +
diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 3d713b6713..4f8db85e26 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -21,7 +21,6 @@ * * ***************************************************************************/ - #include "PreCompiled.h" #ifndef _PreComp_ @@ -61,7 +60,6 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_NewViewSection"; *draw << "TechDraw_NewViewDetail"; *draw << "Separator"; - *draw << "TechDraw_Annotation"; *draw << "TechDraw_DraftView"; *draw << "TechDraw_ArchView"; *draw << "TechDraw_Spreadsheet"; @@ -89,8 +87,12 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_Image"; *draw << "TechDraw_ToggleFrame"; // *decor << "TechDraw_RedrawPage"; + *draw << "TechDraw_Annotation"; *draw << "TechDraw_LeaderLine"; *draw << "TechDraw_RichAnno"; + *draw << "TechDraw_CosmeticVertex"; + *draw << "TechDraw_Midpoints"; + *draw << "TechDraw_Quadrant"; return root; } @@ -110,7 +112,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *views << "TechDraw_ProjGroup"; *views << "TechDraw_NewViewSection"; *views << "TechDraw_NewViewDetail"; - *views << "TechDraw_Annotation"; +// *views << "TechDraw_Annotation"; *views << "TechDraw_DraftView"; *views << "TechDraw_ArchView"; *views << "TechDraw_Spreadsheet"; @@ -147,8 +149,16 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *decor << "TechDraw_Image"; *decor << "TechDraw_ToggleFrame"; // *decor << "TechDraw_RedrawPage"; - *decor << "TechDraw_LeaderLine"; - *decor << "TechDraw_RichAnno"; + + Gui::ToolBarItem *anno = new Gui::ToolBarItem(root); + anno->setCommand("TechDraw Annotation"); + *anno << "TechDraw_Annotation"; + *anno << "TechDraw_LeaderLine"; + *anno << "TechDraw_RichAnno"; + *anno << "TechDraw_CosmeticVertex"; + *anno << "TechDraw_Midpoints"; + *anno << "TechDraw_Quadrant"; + return root; } @@ -167,7 +177,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *views << "TechDraw_ProjGroup"; *views << "TechDraw_NewViewSection"; *views << "TechDraw_NewViewDetail"; - *views << "TechDraw_Annotation"; +// *views << "TechDraw_Annotation"; *views << "TechDraw_DraftView"; *views << "TechDraw_Spreadsheet"; @@ -203,8 +213,17 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *decor << "TechDraw_Image"; *decor << "TechDraw_ToggleFrame"; // *decor << "TechDraw_RedrawPage"; - *decor << "TechDraw_LeaderLine"; - *decor << "TechDraw_RichAnno"; +// *decor << "TechDraw_LeaderLine"; +// *decor << "TechDraw_RichAnno"; + + Gui::ToolBarItem *anno = new Gui::ToolBarItem(root); + anno->setCommand("TechDraw Annotation"); + *anno << "TechDraw_Annotation"; + *anno << "TechDraw_LeaderLine"; + *anno << "TechDraw_RichAnno"; + *anno << "TechDraw_CosmeticVertex"; + *anno << "TechDraw_Midpoints"; + *anno << "TechDraw_Quadrant"; return root; }