From 7f7e63dfe0f736c9ea74f8015d73ef2244800a82 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Tue, 19 Apr 2016 15:17:25 -0400 Subject: [PATCH] link Dimension to 3D geometry --- src/Mod/TechDraw/App/DrawViewDimension.cpp | 62 ++--- src/Mod/TechDraw/App/DrawViewDimension.h | 2 + src/Mod/TechDraw/Gui/CMakeLists.txt | 7 +- src/Mod/TechDraw/Gui/CommandCreateDims.cpp | 244 +++++++++++------- src/Mod/TechDraw/Gui/Resources/TechDraw.qrc | 1 + .../Gui/Resources/icons/LinkDimension.svg | 88 +++++++ src/Mod/TechDraw/Gui/TaskLinkDim.cpp | 201 +++++++++++++++ src/Mod/TechDraw/Gui/TaskLinkDim.h | 110 ++++++++ src/Mod/TechDraw/Gui/TaskLinkDim.ui | 155 +++++++++++ .../TechDraw/Gui/ViewProviderDimension.cpp | 15 +- src/Mod/TechDraw/Gui/Workbench.cpp | 2 + 11 files changed, 753 insertions(+), 134 deletions(-) create mode 100644 src/Mod/TechDraw/Gui/Resources/icons/LinkDimension.svg create mode 100644 src/Mod/TechDraw/Gui/TaskLinkDim.cpp create mode 100644 src/Mod/TechDraw/Gui/TaskLinkDim.h create mode 100644 src/Mod/TechDraw/Gui/TaskLinkDim.ui diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 9afa8c3b3..eadd0aab0 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -142,23 +142,7 @@ void DrawViewDimension::onChanged(const App::Property* prop) } } if (prop == &MeasureType) { - const std::vector &subElements = References.getSubValues(); - if (subElements.empty()) { - Base::Console().Log("INFO - DrawViewDimension::onChanged - no References yet\n"); - return; - } - std::vector::const_iterator subIt = subElements.begin(); - bool trueAllowed = true; - for(; subIt != subElements.end(); subIt++) { - std::string geomType = DrawUtil::getGeomTypeFromName((*subIt)); - int refIndex = DrawUtil::getIndexFromName((*subIt)); - int ref = get3DRef(refIndex,geomType); - if (ref < 0) { //-1 => no reference - trueAllowed = false; - break; - } - } - if (MeasureType.isValue("True") && !trueAllowed) { + if (MeasureType.isValue("True") && !measurement->hasReferences()) { Base::Console().Warning("Dimension %s missing Reference to 3D model. Must be Projected.\n", getNameInDocument()); MeasureType.setValue("Projected"); } @@ -192,31 +176,10 @@ App::DocumentObjectExecReturn *DrawViewDimension::execute(void) return App::DocumentObject::StdReturn; } - //Clear the previous measurement made - measurement->clear(); + //TODO: why not just use View's property directly? + ProjDirection.setValue(getViewPart()->Direction.getValue()); + XAxisDirection.setValue(getViewPart()->XAxisDirection.getValue()); - if (MeasureType.isValue("True")) { - //Update Dimension.measurement with 3D References - const std::vector &subElements = References.getSubValues(); - ProjDirection.setValue(getViewPart()->Direction.getValue()); - XAxisDirection.setValue(getViewPart()->XAxisDirection.getValue()); - //Overall assumption is that the dimensions are only allowed for one view - App::DocumentObject *docObj = getViewPart()->Source.getValue(); - std::vector::const_iterator subEl = subElements.begin(); - for(; subEl != subElements.end(); subEl++) { - //figure out which 3D geometry belongs to the 2D geometry in Dimension.References - //and update the Measurement.References - std::string geomType = DrawUtil::getGeomTypeFromName((*subEl)); - int refIndex = DrawUtil::getIndexFromName((*subEl)); - int ref = get3DRef(refIndex,geomType); - std::string newName = DrawUtil::makeGeomName(geomType, ref); - if (ref < 0) { - Base::Console().Log("INFO - FVD::execute - no 3D ref yet. Probably loading document.\n"); - } else { - measurement->addReference3D(docObj,newName.c_str()); - } - } - } //TODO: if MeasureType = Projected and the Projected shape changes, the Dimension may become invalid (see tilted Cube example) return App::DocumentObject::StdReturn; @@ -457,6 +420,22 @@ int DrawViewDimension::getRefType() const return refType; } +//!add 1 3D measurement Reference +void DrawViewDimension::setMeasurement(DocumentObject* obj, std::vector& subElements) const +{ + std::vector::iterator itSub = subElements.begin(); + for (; itSub != subElements.end(); itSub++) { + //int rc = + static_cast (measurement->addReference3D(obj,(*itSub).c_str())); + } +} + +//delete all previous measurements +void DrawViewDimension::clearMeasurements() +{ + measurement->clear(); +} + int DrawViewDimension::get3DRef(int refIndex, std::string geomType) const { int ref = -1; @@ -468,6 +447,7 @@ int DrawViewDimension::get3DRef(int refIndex, std::string geomType) const return ref; } + void DrawViewDimension::dumpRefs(char* text) const { Base::Console().Message("DUMP - %s\n",text); diff --git a/src/Mod/TechDraw/App/DrawViewDimension.h b/src/Mod/TechDraw/App/DrawViewDimension.h index 96590a37a..e3738404c 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.h +++ b/src/Mod/TechDraw/App/DrawViewDimension.h @@ -79,6 +79,8 @@ public: virtual std::string getFormatedValue() const; virtual double getDimValue() const; DrawViewPart* getViewPart() const; + void setMeasurement(DocumentObject* obj, std::vector& subElements) const; + void clearMeasurements(void); protected: void onChanged(const App::Property* prop); diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 2e331e2d6..13dee0662 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -42,6 +42,7 @@ set(TechDrawGui_MOC_HDRS QGIViewClip.h TaskProjGroup.h DlgPrefsTechDrawImp.h + TaskLinkDim.h ) fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) @@ -52,6 +53,7 @@ qt4_add_resources(TechDrawGui_SRCS Resources/TechDraw.qrc) set(TechDrawGui_UIC_SRCS DlgPrefsTechDraw.ui TaskProjGroup.ui + TaskLinkDim.ui ) qt4_wrap_ui(TechDrawGui_UIC_HDRS ${TechDrawGui_UIC_SRCS}) @@ -74,7 +76,9 @@ SET(TechDrawGui_SRCS DlgPrefsTechDraw.ui DlgPrefsTechDrawImp.cpp DlgPrefsTechDrawImp.h - + TaskLinkDim.ui + TaskLinkDim.cpp + TaskLinkDim.h ) SET(TechDrawGuiView_SRCS MDIViewPage.cpp @@ -160,6 +164,7 @@ SOURCE_GROUP("ViewProvider" FILES ${TechDrawGuiViewProvider_SRCS}) SET(TechDrawGuiTaskDlgs_SRCS TaskProjGroup.ui + TaskLinkDim.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp index c20927cc0..4a3f4e947 100644 --- a/src/Mod/TechDraw/Gui/CommandCreateDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandCreateDims.cpp @@ -54,16 +54,18 @@ # include "MDIViewPage.h" # include "ViewProviderPage.h" +#include "TaskLinkDim.h" using namespace TechDrawGui; using namespace std; //internal functions -bool _checkSelection(Gui::Command* cmd); -int _isValidSingleEdge(Gui::Command* cmd, bool trueDim=true); +bool _checkSelection(Gui::Command* cmd, unsigned maxObjs = 2); +bool _checkDrawViewPart(Gui::Command* cmd); +bool _checkPartFeature(Gui::Command* cmd); +int _isValidSingleEdge(Gui::Command* cmd); bool _isValidVertexes(Gui::Command* cmd); -int _isValidEdgeToEdge(Gui::Command* cmd, bool trueDim=true); -bool _isTrueAllowed(TechDraw::DrawViewPart* objFeat, const std::vector &SubNames); +int _isValidEdgeToEdge(Gui::Command* cmd); enum EdgeType{ isInvalid, @@ -95,7 +97,10 @@ CmdTechDrawNewDimension::CmdTechDrawNewDimension() void CmdTechDrawNewDimension::activated(int iMsg) { - bool result = _checkSelection(this); + bool result = _checkSelection(this,2); + if (!result) + return; + result = _checkDrawViewPart(this); if (!result) return; @@ -111,10 +116,7 @@ void CmdTechDrawNewDimension::activated(int iMsg) std::vector objs; std::vector subs; - //All Dimensions start as Projected - //bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); - //int edgeType = _isValidSingleEdge(this,trueDimAllowed); - int edgeType = _isValidSingleEdge(this,false); + int edgeType = _isValidSingleEdge(this); if (edgeType) { if (edgeType < isCircle) { @@ -186,7 +188,7 @@ void CmdTechDrawNewDimension::activated(int iMsg) dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); dim->References.setValues(objs, subs); - doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str()); std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); TechDraw::DrawPage *page = dynamic_cast(pages.front()); @@ -225,7 +227,10 @@ CmdTechDrawNewRadiusDimension::CmdTechDrawNewRadiusDimension() void CmdTechDrawNewRadiusDimension::activated(int iMsg) { - bool result = _checkSelection(this); + bool result = _checkSelection(this,1); + if (!result) + return; + result = _checkDrawViewPart(this); if (!result) return; @@ -240,10 +245,8 @@ void CmdTechDrawNewRadiusDimension::activated(int iMsg) std::vector objs; std::vector subs; - //All Dimensions start as Projected - //bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); - //int edgeType = _isValidSingleEdge(this,trueDimAllowed); - int edgeType = _isValidSingleEdge(this,false); if (edgeType == isCircle) { + int edgeType = _isValidSingleEdge(this); + if (edgeType == isCircle) { centerLine = true; objs.push_back(objFeat); subs.push_back(SubNames[0]); @@ -271,7 +274,7 @@ void CmdTechDrawNewRadiusDimension::activated(int iMsg) dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); dim->References.setValues(objs, subs); - doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str()); std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); TechDraw::DrawPage *page = dynamic_cast(pages.front()); @@ -311,7 +314,10 @@ CmdTechDrawNewDiameterDimension::CmdTechDrawNewDiameterDimension() void CmdTechDrawNewDiameterDimension::activated(int iMsg) { - bool result = _checkSelection(this); + bool result = _checkSelection(this,1); + if (!result) + return; + result = _checkDrawViewPart(this); if (!result) return; @@ -326,10 +332,7 @@ void CmdTechDrawNewDiameterDimension::activated(int iMsg) std::vector objs; std::vector subs; - //All Dimensions start as Projected - //bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); - //int edgeType = _isValidSingleEdge(this,trueDimAllowed); - int edgeType = _isValidSingleEdge(this,false); + int edgeType = _isValidSingleEdge(this); if (edgeType == isCircle) { centerLine = true; objs.push_back(objFeat); @@ -358,7 +361,7 @@ void CmdTechDrawNewDiameterDimension::activated(int iMsg) dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); dim->References.setValues(objs, subs); - doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str()); std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); TechDraw::DrawPage *page = dynamic_cast(pages.front()); @@ -398,7 +401,10 @@ CmdTechDrawNewLengthDimension::CmdTechDrawNewLengthDimension() void CmdTechDrawNewLengthDimension::activated(int iMsg) { - bool result = _checkSelection(this); + bool result = _checkSelection(this,2); + if (!result) + return; + result = _checkDrawViewPart(this); if (!result) return; @@ -413,10 +419,7 @@ void CmdTechDrawNewLengthDimension::activated(int iMsg) std::vector objs; std::vector subs; - //All Dimensions start as Projected - //bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); - //int edgeType = _isValidSingleEdge(this,trueDimAllowed); - int edgeType = _isValidSingleEdge(this,false); + int edgeType = _isValidSingleEdge(this); if ((edgeType == isHorizontal) || (edgeType == isVertical) || (edgeType == isDiagonal)) { @@ -451,7 +454,7 @@ void CmdTechDrawNewLengthDimension::activated(int iMsg) doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%%value%%'", FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str()); std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); TechDraw::DrawPage *page = dynamic_cast(pages.front()); @@ -491,7 +494,10 @@ CmdTechDrawNewDistanceXDimension::CmdTechDrawNewDistanceXDimension() void CmdTechDrawNewDistanceXDimension::activated(int iMsg) { - bool result = _checkSelection(this); + bool result = _checkSelection(this,2); + if (!result) + return; + result = _checkDrawViewPart(this); if (!result) return; @@ -506,10 +512,7 @@ void CmdTechDrawNewDistanceXDimension::activated(int iMsg) std::vector objs; std::vector subs; - //All Dimensions start as Projected - //bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); - //int edgeType = _isValidSingleEdge(this,trueDimAllowed); - int edgeType = _isValidSingleEdge(this,false); + int edgeType = _isValidSingleEdge(this); if ((edgeType == isHorizontal) || (edgeType == isDiagonal)) { objs.push_back(objFeat); @@ -542,7 +545,7 @@ void CmdTechDrawNewDistanceXDimension::activated(int iMsg) doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%%value%%'", FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str()); std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); TechDraw::DrawPage *page = dynamic_cast(pages.front()); @@ -582,7 +585,10 @@ CmdTechDrawNewDistanceYDimension::CmdTechDrawNewDistanceYDimension() void CmdTechDrawNewDistanceYDimension::activated(int iMsg) { - bool result = _checkSelection(this); + bool result = _checkSelection(this,2); + if (!result) + return; + result = _checkDrawViewPart(this); if (!result) return; @@ -597,10 +603,7 @@ void CmdTechDrawNewDistanceYDimension::activated(int iMsg) std::vector objs; std::vector subs; - //All Dimensions start as Projected - //bool trueDimAllowed = _isTrueAllowed(objFeat,SubNames); - //int edgeType = _isValidSingleEdge(this,trueDimAllowed); - int edgeType = _isValidSingleEdge(this,false); + int edgeType = _isValidSingleEdge(this); if ((edgeType == isVertical) || (edgeType == isDiagonal)) { objs.push_back(objFeat); @@ -632,7 +635,7 @@ void CmdTechDrawNewDistanceYDimension::activated(int iMsg) doCommand(Doc, "App.activeDocument().%s.FormatSpec = '%%value%%'", FeatName.c_str()); - doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str()); std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); TechDraw::DrawPage *page = dynamic_cast(pages.front()); @@ -672,7 +675,10 @@ CmdTechDrawNewAngleDimension::CmdTechDrawNewAngleDimension() void CmdTechDrawNewAngleDimension::activated(int iMsg) { - bool result = _checkSelection(this); + bool result = _checkSelection(this,2); + if (!result) + return; + result = _checkDrawViewPart(this); if (!result) return; @@ -686,8 +692,7 @@ void CmdTechDrawNewAngleDimension::activated(int iMsg) std::vector objs; std::vector subs; - //All Dimensions start as Projected - int edgeType = _isValidEdgeToEdge(this,false); + int edgeType = _isValidEdgeToEdge(this); if (edgeType == isAngle) { objs.push_back(objFeat); objs.push_back(objFeat); @@ -710,7 +715,7 @@ void CmdTechDrawNewAngleDimension::activated(int iMsg) dim = dynamic_cast(getDocument()->getObject(FeatName.c_str())); dim->References.setValues(objs, subs); - doCommand(Doc,"App.activeDocument().%s.ProjectionType = 'Projected'",FeatName.c_str()); + doCommand(Doc,"App.activeDocument().%s.MeasureType = 'Projected'",FeatName.c_str()); std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); TechDraw::DrawPage *page = dynamic_cast(pages.front()); @@ -730,6 +735,71 @@ bool CmdTechDrawNewAngleDimension::isActive(void) return hasActiveDocument(); } +//=========================================================================== +// TechDraw_LinkDimension +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawLinkDimension); + +CmdTechDrawLinkDimension::CmdTechDrawLinkDimension() + : Command("TechDraw_LinkDimension") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Link a dimension to 3D geometry"); + sToolTipText = QT_TR_NOOP("Link a dimension to 3D geometry"); + sWhatsThis = "TechDraw_LinkDimension"; + sStatusTip = sToolTipText; + sPixmap = "LinkDimension"; +} + +void CmdTechDrawLinkDimension::activated(int iMsg) +{ + bool result = _checkSelection(this,2); + if (!result) + return; + + std::vector selection = getSelection().getSelectionEx(); + TechDraw::DrawPage* page = 0; + Part::Feature* obj3D = 0; + std::vector subs; + std::vector::iterator itSel = selection.begin(); + for (; itSel != selection.end(); itSel++) { + if ((*itSel).getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) { + obj3D = dynamic_cast ((*itSel).getObject()); + subs = (*itSel).getSubNames(); + } + if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawPage::getClassTypeId())) { + page = dynamic_cast((*itSel).getObject()); + } + } + + //no page in selection, use first + if (!page) { + std::vector pages = getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); + page = dynamic_cast(pages.front()); + } + + if (!page || !obj3D) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"), + QObject::tr("Can't link a dimension from this selection")); + return; + } + + // dialog to select the Dimension to link + Gui::Control().showDialog(new TaskDlgLinkDim(obj3D,subs,page)); + + //openCommand("Link Dimension"); + //commitCommand(); + page->getDocument()->recompute(); + +} + +bool CmdTechDrawLinkDimension::isActive(void) +{ + return hasActiveDocument(); +} + void CreateTechDrawCommandsDims(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -741,6 +811,7 @@ void CreateTechDrawCommandsDims(void) rcCmdMgr.addCommand(new CmdTechDrawNewDistanceXDimension()); rcCmdMgr.addCommand(new CmdTechDrawNewDistanceYDimension()); rcCmdMgr.addCommand(new CmdTechDrawNewAngleDimension()); + rcCmdMgr.addCommand(new CmdTechDrawLinkDimension()); } //=========================================================================== @@ -748,7 +819,8 @@ void CreateTechDrawCommandsDims(void) //=========================================================================== //! common checks of Selection for Dimension commands -bool _checkSelection(Gui::Command* cmd) { +//non-empty selection, no more than maxObjs selected and at least 1 DrawingPage exists +bool _checkSelection(Gui::Command* cmd, unsigned maxObjs) { std::vector selection = cmd->getSelection().getSelectionEx(); if (selection.size() == 0) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), @@ -756,31 +828,51 @@ bool _checkSelection(Gui::Command* cmd) { return false; } - TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); - if(!objFeat) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), - QObject::tr("No Feature in selection")); - return false; - } - const std::vector &SubNames = selection[0].getSubNames(); - if (SubNames.size() != 1 && SubNames.size() != 2){ + if (SubNames.size() > maxObjs){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), - QObject::tr("Wrong number of objects selected")); + QObject::tr("Too many objects selected")); return false; } std::vector pages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); if (pages.empty()){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), - QObject::tr("Create a page to insert.")); + QObject::tr("Create a page first.")); return false; } return true; } -//! verify that Selection contains a valid Geometry for a single Edge Dimension (True or Projected) -int _isValidSingleEdge(Gui::Command* cmd, bool trueDim) { +bool _checkDrawViewPart(Gui::Command* cmd) { + std::vector selection = cmd->getSelection().getSelectionEx(); + TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); + if(!objFeat) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("No DrawViewPart in selection.")); + return false; + } + return true; +} + +bool _checkPartFeature(Gui::Command* cmd) { + bool result = false; + std::vector selection = cmd->getSelection().getSelectionEx(); + std::vector::iterator itSel = selection.begin(); + for (; itSel != selection.end(); itSel++) { + if (itSel->isDerivedFrom(Part::Feature::getClassTypeId())) { + result = true; + } + } + if(!result) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"), + QObject::tr("No DrawViewPart in selection.")); + } + return result; +} + +//! verify that Selection contains a valid Geometry for a single Edge Dimension +int _isValidSingleEdge(Gui::Command* cmd) { int edgeType = isInvalid; std::vector selection = cmd->getSelection().getSelectionEx(); TechDraw::DrawViewPart * objFeat = dynamic_cast(selection[0].getObject()); @@ -788,13 +880,7 @@ int _isValidSingleEdge(Gui::Command* cmd, bool trueDim) { if (SubNames.size() == 1) { //only 1 subshape selected if (DrawUtil::getGeomTypeFromName(SubNames[0]) == "Edge") { //the Name starts with "Edge" int GeoId = DrawUtil::getIndexFromName(SubNames[0]); - TechDrawGeometry::BaseGeom* geom = NULL; - if (trueDim) { - int ref = objFeat->getEdgeRefByIndex(GeoId); - geom = objFeat->getCompleteEdge(ref); //project edge onto its shape to get 2D geom - } else { - geom = objFeat->getProjEdgeByIndex(GeoId); - } + TechDrawGeometry::BaseGeom* geom = objFeat->getProjEdgeByIndex(GeoId); if (!geom) { Base::Console().Error("Logic Error: no geometry for GeoId: %d\n",GeoId); return isInvalid; @@ -842,7 +928,7 @@ bool _isValidVertexes(Gui::Command* cmd) { } //! verify that the Selection contains valid geometries for an Edge to Edge Dimension -int _isValidEdgeToEdge(Gui::Command* cmd, bool trueDim) { +int _isValidEdgeToEdge(Gui::Command* cmd) { //TODO: can the edges be in 2 different features?? int edgeType = isInvalid; std::vector selection = cmd->getSelection().getSelectionEx(); @@ -854,17 +940,8 @@ int _isValidEdgeToEdge(Gui::Command* cmd, bool trueDim) { DrawUtil::getGeomTypeFromName(SubNames[1]) == "Edge") { int GeoId0 = DrawUtil::getIndexFromName(SubNames[0]); int GeoId1 = DrawUtil::getIndexFromName(SubNames[1]); - TechDrawGeometry::BaseGeom* geom0 = NULL; - TechDrawGeometry::BaseGeom* geom1 = NULL; - if (trueDim) { - int ref0 = objFeat0->getEdgeRefByIndex(GeoId0); - int ref1 = objFeat0->getEdgeRefByIndex(GeoId1); - geom0 = objFeat0->getCompleteEdge(ref0); - geom1 = objFeat0->getCompleteEdge(ref1); - } else { - geom0 = objFeat0->getProjEdgeByIndex(GeoId0); - geom1 = objFeat0->getProjEdgeByIndex(GeoId1); - } + TechDrawGeometry::BaseGeom* geom0 = objFeat0->getProjEdgeByIndex(GeoId0); + TechDrawGeometry::BaseGeom* geom1 = objFeat0->getProjEdgeByIndex(GeoId1); if ((!geom0) || (!geom1)) { Base::Console().Error("Logic Error: no geometry for GeoId: %d or GeoId: %d\n",GeoId0,GeoId1); return isInvalid; @@ -898,18 +975,3 @@ int _isValidEdgeToEdge(Gui::Command* cmd, bool trueDim) { } return edgeType; } - -//! verify that each SubName has a corresponding Edge geometry in objFeat->Source -bool _isTrueAllowed(TechDraw::DrawViewPart* objFeat, const std::vector &SubNames) -{ - std::vector::const_iterator it = SubNames.begin(); - bool trueDimAllowed = true; - for (; it != SubNames.end(); it++) { - int idx = DrawUtil::getIndexFromName((*it)); - int ref = objFeat->getEdgeRefByIndex(idx); - if (ref < 0) { - trueDimAllowed = false; - } - } - return trueDimAllowed; -} diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 0184610d0..0ef78637a 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -8,6 +8,7 @@ icons/Dimension_Length.svg icons/Dimension_Radius.svg icons/Dimension_Vertical.svg + icons/LinkDimension.svg icons/Hatch.svg icons/Page.svg icons/Pages.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/LinkDimension.svg b/src/Mod/TechDraw/Gui/Resources/icons/LinkDimension.svg new file mode 100644 index 000000000..dfed2dfb7 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/LinkDimension.svg @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TaskLinkDim.cpp b/src/Mod/TechDraw/Gui/TaskLinkDim.cpp new file mode 100644 index 000000000..8b22ebc7d --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskLinkDim.cpp @@ -0,0 +1,201 @@ +/*************************************************************************** + * Copyright (c) 2016 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 +#endif // #ifndef _PreComp_ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include + +#include "TaskLinkDim.h" +#include "ui_TaskLinkDim.h" + +using namespace Gui; +using namespace TechDrawGui; + + +TaskLinkDim::TaskLinkDim(Part::Feature* part, std::vector& subs, TechDraw::DrawPage* page) : + ui(new Ui_TaskLinkDim), + m_part(part), + m_subs(subs), + m_page(page) +{ + ui->setupUi(this); + ui->selector->setAvailableLabel(tr("Available")); + ui->selector->setSelectedLabel(tr("Selected")); + + connect(ui->selector->availableTreeWidget(), SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), + this, SLOT(onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); + connect(ui->selector->selectedTreeWidget(), SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), + this, SLOT(onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); + + loadAvailDims(); + + ui->leFeature->setText(QString::fromStdString(part->getNameInDocument())); + ui->leGeometry1->setText(QString::fromStdString(subs.at(0))); + if (subs.size() > 1) { + ui->leGeometry2->setText(QString::fromStdString(subs.at(1))); + } +} + +TaskLinkDim::~TaskLinkDim() +{ + delete ui; +} + +void TaskLinkDim::loadAvailDims() +{ + App::Document* doc = m_page->getDocument(); + Gui::Document* guiDoc = Gui::Application::Instance->getDocument(doc); + if (!guiDoc) + return; + + std::vector pageViews = m_page->Views.getValues(); + std::vector::iterator itView = pageViews.begin(); + std::string result; + for (; itView != pageViews.end(); itView++) { + if ((*itView)->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) { + TechDraw::DrawViewDimension* dim = dynamic_cast((*itView)); + if (dim->References.getValues().size() == m_subs.size()) { + QString label = QString::fromUtf8((*itView)->Label.getValue()); + QString name = QString::fromUtf8((*itView)->getNameInDocument()); + QString tooltip = label + QString::fromUtf8(" / ") + name; + + QTreeWidgetItem* child = new QTreeWidgetItem(); + child->setText(0, label); + child->setToolTip(0, tooltip); + child->setData(0, Qt::UserRole, name); + Gui::ViewProvider* vp = guiDoc->getViewProvider(*itView); + if (vp) child->setIcon(0, vp->getIcon()); + ui->selector->availableTreeWidget()->addTopLevelItem(child); + } + } + } +} + +void TaskLinkDim::updateDims() +{ + int count = ui->selector->selectedTreeWidget()->topLevelItemCount(); + if (count == 0) { + return; + } + for (int i=0; iselector->selectedTreeWidget()->topLevelItem(i); + QString name = child->data(0, Qt::UserRole).toString(); + App::DocumentObject* obj = m_page->getDocument()->getObject(name.toStdString().c_str()); + TechDraw::DrawViewDimension* dim = dynamic_cast(obj); + dim->clearMeasurements(); + dim->setMeasurement(m_part,m_subs); + dim->MeasureType.setValue("True"); + } +} + +void TaskLinkDim::onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous) +{ + //if (previous) { + //picked item on "selected" side + //} + //if (current) { + //picked item on "available" side + //} +} + +bool TaskLinkDim::accept() +{ + updateDims(); + return true; +} + +bool TaskLinkDim::reject() +{ + return true; +} + +void TaskLinkDim::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgLinkDim::TaskDlgLinkDim(Part::Feature* part,std::vector& subs, TechDraw::DrawPage* page) : + TaskDialog() +{ + widget = new TaskLinkDim(part,subs,page); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("LinkDimension"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgLinkDim::~TaskDlgLinkDim() +{ +} + +void TaskDlgLinkDim::update() +{ + //widget->updateTask(); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgLinkDim::open() +{ +} + +void TaskDlgLinkDim::clicked(int i) +{ +} + +bool TaskDlgLinkDim::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgLinkDim::reject() +{ + widget->reject(); + return true; +} + +#include "moc_TaskLinkDim.cpp" diff --git a/src/Mod/TechDraw/Gui/TaskLinkDim.h b/src/Mod/TechDraw/Gui/TaskLinkDim.h new file mode 100644 index 000000000..efab4df87 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskLinkDim.h @@ -0,0 +1,110 @@ +/*************************************************************************** + * Copyright (c) 2016 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 GUI_TASKVIEW_TASKLINKDIM_H +#define GUI_TASKVIEW_TASKLINKDIM_H + +#include +#include + +#include "ui_TaskLinkDim.h" + +#include "ViewProviderDimension.h" +#include "../App/DrawViewDimension.h" + + +class Ui_TaskLinkDim; + +namespace App { + class Document; + class DocumentObject; +} + +namespace TechDraw { + class DrawViewPart; + class DrawViewDimension; +} + +namespace TechDrawGui +{ + +class TaskLinkDim : public QWidget +{ + Q_OBJECT + +public: + TaskLinkDim(Part::Feature* part,std::vector& subs, TechDraw::DrawPage* page); + ~TaskLinkDim(); + +public: + bool accept(); + bool reject(); + +protected Q_SLOTS: + void onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*); + +protected: + void changeEvent(QEvent *e); + void loadAvailDims(); + void updateDims(); + +private: + Ui_TaskLinkDim * ui; + Part::Feature* m_part; + std::vector m_subs; + TechDraw::DrawPage* m_page; +}; + +class TaskDlgLinkDim : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgLinkDim(Part::Feature* part,std::vector& subs, TechDraw::DrawPage* page); + ~TaskDlgLinkDim(); + +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(); + +protected: + +private: + TaskLinkDim * widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef GUI_TASKVIEW_TASKLINKDIM_H diff --git a/src/Mod/TechDraw/Gui/TaskLinkDim.ui b/src/Mod/TechDraw/Gui/TaskLinkDim.ui new file mode 100644 index 000000000..4e8a445a5 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskLinkDim.ui @@ -0,0 +1,155 @@ + + + TechDrawGui::TaskLinkDim + + + + 0 + 0 + 342 + 430 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Link Dimension + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + QLayout::SetDefaultConstraint + + + + + Link This 3D Geometry + + + + + + + + + + + + + Qt::NoFocus + + + color: rgb(120, 120, 120); + + + true + + + + + + + Geometry: + + + + + + + Qt::NoFocus + + + color: rgb(120, 120, 120); + + + true + + + + + + + Qt::NoFocus + + + color: rgb(120, 120, 120); + + + true + + + + + + + Feature: + + + + + + + + + + + + + To These Dimensions + + + + + + + + + + + + + + + + + + + + + + Gui::ActionSelector + QWidget +
Gui/Widgets.h
+
+
+ + +
diff --git a/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp index ffa1153e6..8c46b9464 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDimension.cpp @@ -76,8 +76,21 @@ std::vector ViewProviderDimension::getDisplayModes(void) const return StrList; } -void ViewProviderDimension::updateData(const App::Property*) +void ViewProviderDimension::updateData(const App::Property* p) { + if (p == &(getViewObject()->Type)) { + if (getViewObject()->Type.isValue("DistanceX")) { + sPixmap = "Dimension_Horizonatal"; + } else if (getViewObject()->Type.isValue("DistanceY")) { + sPixmap = "Dimension_Vertical"; + } else if (getViewObject()->Type.isValue("Radius")) { + sPixmap = "Dimension_Radius"; + } else if (getViewObject()->Type.isValue("Diameter")) { + sPixmap = "Dimension_Diameter"; + } else if (getViewObject()->Type.isValue("Angle")) { + sPixmap = "Dimension_Angle"; + } + } } TechDraw::DrawViewDimension* ViewProviderDimension::getViewObject() const diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 36c7479a3..ff4aec0ca 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -113,6 +113,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *dims << "TechDraw_NewRadiusDimension"; *dims << "TechDraw_NewDiameterDimension"; *dims << "TechDraw_NewAngleDimension"; + *dims << "TechDraw_LinkDimension"; // *dims << "TechDraw_NewDimension" Gui::ToolBarItem *file = new Gui::ToolBarItem(root); @@ -157,6 +158,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *dims << "TechDraw_NewRadiusDimension"; *dims << "TechDraw_NewDiameterDimension"; *dims << "TechDraw_NewAngleDimension"; + *dims << "TechDraw_LinkDimension"; // *dims << "TechDraw_NewDimension"; Gui::ToolBarItem *file = new Gui::ToolBarItem(root);