diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index 113618ddcf..6d8f2b2440 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -364,24 +364,24 @@ void CosmeticEdge::dump(char* title) //********************************************************* CenterLine::CenterLine(void) { - start = Base::Vector3d(0.0, 0.0, 0.0); - end = Base::Vector3d(0.0, 0.0, 0.0); - mode = 0; - hShift = 0.0; - vShift = 0.0; - rotate = 0.0; - extendBy = 0.0; + m_start = Base::Vector3d(0.0, 0.0, 0.0); + m_end = Base::Vector3d(0.0, 0.0, 0.0); + m_mode = 0; + m_hShift = 0.0; + m_vShift = 0.0; + m_rotate = 0.0; + m_extendBy = 0.0; } CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2) { - start = p1; - end = p2; - mode = 0; - hShift = 0.0; - vShift = 0.0; - rotate = 0.0; - extendBy = 0.0; + m_start = p1; + m_end = p2; + m_mode = 0; + m_hShift = 0.0; + m_vShift = 0.0; + m_rotate = 0.0; + m_extendBy = 0.0; } CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2, @@ -391,13 +391,13 @@ CenterLine::CenterLine(Base::Vector3d p1, Base::Vector3d p2, double r, double x) { - start = p1; - end = p2; - mode = m; - hShift = h; - vShift = v; - rotate = r; - extendBy = x; + m_start = p1; + m_end = p2; + m_mode = m; + m_hShift = h; + m_vShift = v; + m_rotate = r; + m_extendBy = x; } CenterLine::~CenterLine() @@ -415,8 +415,8 @@ TechDraw::BaseGeom* CenterLine::scaledGeometry(TechDraw::DrawViewPart* partFeat) std::pair ends = calcEndPoints(partFeat, m_faces, - mode, extendBy, - hShift,vShift, rotate); + m_mode, m_extendBy, + m_hShift,m_vShift, m_rotate); TechDraw::BaseGeom* newGeom = nullptr; Base::Vector3d p1 = DrawUtil::invertY(ends.first); Base::Vector3d p2 = DrawUtil::invertY(ends.second); @@ -435,17 +435,17 @@ TechDraw::BaseGeom* CenterLine::scaledGeometry(TechDraw::DrawViewPart* partFeat) std::string CenterLine::toCSV(void) const { std::stringstream ss; - ss << start.x << "," << //0 - start.y << "," << //1 - start.z << "," << //2 - end.x << "," << //3 - end.y << "," << //4 - end.z << "," << //5 - mode << "," << //6 - hShift << "," << //7 - vShift << "," << //8 - rotate << "," << //9 - extendBy << "," << //10 + ss << m_start.x << "," << //0 + m_start.y << "," << //1 + m_start.z << "," << //2 + m_end.x << "," << //3 + m_end.y << "," << //4 + m_end.z << "," << //5 + m_mode << "," << //6 + m_hShift << "," << //7 + m_vShift << "," << //8 + m_rotate << "," << //9 + m_extendBy << "," << //10 m_faces.size(); //11 if (!m_faces.empty()) { for (auto& f: m_faces) { @@ -456,7 +456,7 @@ std::string CenterLine::toCSV(void) const } std::string clCSV = ss.str(); - std::string fmtCSV = fmt.toCSV(); + std::string fmtCSV = m_format.toCSV(); return clCSV + ",$$$," + fmtCSV; } @@ -483,22 +483,22 @@ bool CenterLine::fromCSV(std::string& lineSpec) double x = atof(values[0].c_str()); double y = atof(values[1].c_str()); double z = atof(values[2].c_str()); - start = Base::Vector3d (x,y,z); + m_start = Base::Vector3d (x,y,z); x = atof(values[3].c_str()); y = atof(values[4].c_str()); z = atof(values[5].c_str()); - end = Base::Vector3d (x,y,z); - mode = atoi(values[6].c_str()); - hShift = atof(values[7].c_str()); - vShift = atof(values[8].c_str()); - rotate = atof(values[9].c_str()); - extendBy = atof(values[10].c_str()); - int faceCount = atoi(values[11].c_str()); + m_end = Base::Vector3d (x,y,z); + m_mode = atoi(values[6].c_str()); + m_hShift = atof(values[7].c_str()); + m_vShift = atof(values[8].c_str()); + m_rotate = atof(values[9].c_str()); + m_extendBy = atof(values[10].c_str()); + int m_faceCount = atoi(values[11].c_str()); int i = 0; - for ( ; i < faceCount; i++ ) { + for ( ; i < m_faceCount; i++ ) { m_faces.push_back(values[12 + i]); } - fmt.fromCSV(tokens[1]); + m_format.fromCSV(tokens[1]); return true; } @@ -511,7 +511,7 @@ void CenterLine::dump(char* title) std::pair CenterLine::calcEndPoints(DrawViewPart* partFeat, std::vector faceNames, int vert, double ext, - double hShift, double vShift, + double m_hShift, double m_vShift, double rotate) { std::pair result; @@ -524,8 +524,8 @@ std::pair CenterLine::calcEndPoints(DrawViewPart faceBox.SetGap(0.0); double scale = partFeat->getScale(); - double hss = hShift * scale; - double vss = vShift * scale; + double hss = m_hShift * scale; + double vss = m_vShift * scale; for (auto& fn: faceNames) { if (TechDraw::DrawUtil::getGeomTypeFromName(fn) != "Face") { @@ -595,3 +595,71 @@ std::pair CenterLine::calcEndPoints(DrawViewPart return result; } +GeomFormat::GeomFormat() : + m_geomIndex(-1) +{ + m_format.m_style = LineFormat::getDefEdgeStyle(); + m_format.m_weight = LineFormat::getDefEdgeWidth(); + m_format.m_color = LineFormat::getDefEdgeColor(); + m_format.m_visible = true; +} + +GeomFormat::GeomFormat(int idx, + TechDraw::LineFormat fmt) : + m_geomIndex(idx) +{ + m_format.m_style = fmt.m_style; + m_format.m_weight = fmt.m_weight; + m_format.m_color = fmt.m_color; + m_format.m_visible = fmt.m_visible; + //m_format = fmt; //??? +} + +GeomFormat::~GeomFormat() +{ +} + +void GeomFormat::dump(char* title) +{ + Base::Console().Message("GF::dump - %s \n",title); + Base::Console().Message("GF::dump - %s \n",toCSV().c_str()); +} + +std::string GeomFormat::toCSV(void) const +{ + std::stringstream ss; + ss << m_geomIndex << ",$$$," << + m_format.toCSV(); + return ss.str(); +} + +bool GeomFormat::fromCSV(std::string& lineSpec) +{ + std::vector tokens = DrawUtil::tokenize(lineSpec); + if (tokens.empty()) { + Base::Console().Message("GeomFormat::fromCSV - tokenize failed - no tokens\n"); + return false; + } + + if (tokens[0].length() == 0) { + Base::Console().Message( "GeomFormat::fromCSV - token0 empty\n"); + return false; + } + + std::vector values = DrawUtil::split(tokens[0]); + unsigned int maxCells = 1; + if (values.size() < maxCells) { + Base::Console().Message( "GeomFormat::fromCSV(%s) invalid CSV entry\n",lineSpec.c_str() ); + return false; + } + m_geomIndex = atoi(values[0].c_str()); + + int lastToken = 1; + if (tokens.size() != 2) { + Base::Console().Message("CE::fromCSV - wrong number of tokens\n"); + return false; + } + m_format.fromCSV(tokens[lastToken]); + return true; +} + diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index bd61c35711..936365a2e1 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -123,21 +123,39 @@ public: TechDraw::DrawViewPart* partFeat, std::vector faceNames, int vert, double ext, - double hShift, double vShift, + double m_hShift, double m_vShift, double rotate); void dump(char* title); - Base::Vector3d start; - Base::Vector3d end; + Base::Vector3d m_start; + Base::Vector3d m_end; std::vector m_faces; - int mode; // vert/horiz/aligned - double hShift; - double vShift; - double rotate; - double extendBy; - LineFormat fmt; + int m_mode; // 0 - vert/ 1 - horiz/ 2 - aligned + double m_hShift; + double m_vShift; + double m_rotate; + double m_extendBy; + LineFormat m_format; }; +class TechDrawExport GeomFormat +{ +public: + GeomFormat(); + GeomFormat(int idx, + LineFormat fmt); + ~GeomFormat(); + + std::string toCSV(void) const; + bool fromCSV(std::string& lineSpec); + void dump(char* title); + + int m_geomIndex; + LineFormat m_format; +}; + + + } //end namespace TechDraw #endif //TECHDRAW_COSMETIC_H diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 6795538c5f..da51af4dcb 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -152,11 +152,13 @@ DrawViewPart::DrawViewPart(void) : ADD_PROPERTY_TYPE(CosmeticVertexList ,(""),sgroup,App::Prop_None,"CosmeticVertex Save/Restore"); ADD_PROPERTY_TYPE(CosmeticEdgeList ,(""),sgroup,App::Prop_None,"CosmeticEdge Save/Restore"); ADD_PROPERTY_TYPE(CenterLineList ,(""),sgroup,App::Prop_None,"CenterLine Save/Restore"); + ADD_PROPERTY_TYPE(GeomFormatList ,(""),sgroup,App::Prop_None,"Geometry format Save/Restore"); std::vector emptyList; CosmeticVertexList.setValues(emptyList); CosmeticEdgeList.setValues(emptyList); CenterLineList.setValues(emptyList); + GeomFormatList.setValues(emptyList); geometryObject = nullptr; getRunControl(); @@ -1380,11 +1382,96 @@ void DrawViewPart::addCenterLinesToGeom(void) } } +//build GFormatTable from GeomFormatList +void DrawViewPart::readGFormatProp(void) +{ + GFormatTable.clear(); + std::vector restoreFormats = GeomFormatList.getValues(); + if (restoreFormats.empty()) { + return; + } + for (auto& rf: restoreFormats) { + if (!rf.empty()) { + GeomFormat* gf = new GeomFormat(); + bool rc = gf->fromCSV(rf); + if (rc) { + GFormatTable.push_back(gf); + } else { + delete gf; + } + } + } +} + +void DrawViewPart::writeGFormatProp(void) +{ + std::vector saveFormats; + const std::vector gForms = getGeomFormats(); + for (auto& gf: gForms) { + std::string csv = gf->toCSV(); + saveFormats.push_back(csv); + } + GeomFormatList.setValues(saveFormats); +} + +void DrawViewPart::clearGeomFormats(void) +{ + GFormatTable.clear(); + std::vector noFormats; + GeomFormatList.setValues(noFormats); +} + +// adds a GeomFormat to GFormatTable and GeomFormatList +int DrawViewPart::addGeomFormat(GeomFormat* gf) +{ + int newIdx = (int) (GFormatTable.size()); + GFormatTable.push_back(gf); + std::string csv = gf->toCSV(); + std::vector formatList = GeomFormatList.getValues(); + formatList.push_back(csv); + GeomFormatList.setValues(formatList); + return newIdx; +} + +void DrawViewPart::removeGeomFormat(int idx) +{ + if (idx < (int) GFormatTable.size()) { + GFormatTable.erase(GFormatTable.begin() + idx); + writeGFormatProp(); + requestPaint(); + } +} + +TechDraw::GeomFormat* DrawViewPart::getGeomFormatByIndex(int idx) const +{ + GeomFormat* result = nullptr; + const std::vector fmts = getGeomFormats(); + if (idx < (int) fmts.size()) { + result = fmts.at(idx); + } + return result; +} + +//find the format corresponding to geometry edge idx +TechDraw::GeomFormat* DrawViewPart::getGeomFormatByGeom(int idx) const +{ + GeomFormat* result = nullptr; + const std::vector fmts = getGeomFormats(); + for (auto& f: fmts) { + if (f->m_geomIndex == idx) { + result = f; + break; + } + } + return result; +} + void DrawViewPart::onDocumentRestored() { readCVertexProp(); readCEdgeProp(); readCLineProp(); + readGFormatProp(); // requestPaint(); //if execute has not run yet, there will be no GO, and paint will not do anything. execute(); diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 2aa8215c06..6ef27e0d26 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -71,6 +71,7 @@ class DrawViewBalloon; class CosmeticVertex; class CosmeticEdge; class CenterLine; +class GeomFormat; } namespace TechDraw @@ -107,6 +108,7 @@ public: App::PropertyStringList CosmeticVertexList; App::PropertyStringList CosmeticEdgeList; App::PropertyStringList CenterLineList; + App::PropertyStringList GeomFormatList; virtual short mustExecute() const; virtual void onDocumentRestored() override; @@ -199,6 +201,13 @@ public: void addCosmeticEdgesToGeom(void); void addCenterLinesToGeom(void); + int addGeomFormat(TechDraw::GeomFormat* gf); + virtual void writeGFormatProp(void); + virtual void removeGeomFormat(int idx); + const std::vector & getGeomFormats(void) const { return GFormatTable; } + TechDraw::GeomFormat* getGeomFormatByIndex(int idx) const; + TechDraw::GeomFormat* getGeomFormatByGeom(int idx) const; + void clearGeomFormats(void); protected: TechDraw::GeometryObject *geometryObject; @@ -231,6 +240,9 @@ protected: std::vector CLineTable; void readCLineProp(void); + std::vector GFormatTable; + void readGFormatProp(void); + private: bool nowUnsetting; /* bool m_restoreComplete;*/ diff --git a/src/Mod/TechDraw/App/DrawViewPartPy.xml b/src/Mod/TechDraw/App/DrawViewPartPy.xml index c8e4a66228..0714198519 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPy.xml +++ b/src/Mod/TechDraw/App/DrawViewPartPy.xml @@ -63,6 +63,16 @@ clearCosmeticEdges() - remove all CosmeticLines from the View. Returns nothing. + + + clearCenterLines() - remove all CenterLines from the View. Returns nothing. + + + + + clearGeomFormats() - remove all GeomFormats from the View. Returns nothing. + + diff --git a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp index c6626f8758..6f3f00cadd 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp @@ -80,6 +80,25 @@ PyObject* DrawViewPartPy::clearCosmeticEdges(PyObject *args) return Py_None; } +PyObject* DrawViewPartPy::clearCenterLines(PyObject *args) +{ + (void) args; + DrawViewPart* item = getDrawViewPartPtr(); + item->clearCenterLines(); + Py_INCREF(Py_None); + return Py_None; +} + +PyObject* DrawViewPartPy::clearGeomFormats(PyObject *args) +{ + (void) args; + DrawViewPart* item = getDrawViewPartPtr(); + item->clearGeomFormats(); + Py_INCREF(Py_None); + return Py_None; +} + + PyObject* DrawViewPartPy::makeCosmeticVertex(PyObject *args) { PyObject* pPnt1 = nullptr; diff --git a/src/Mod/TechDraw/App/Geometry.h b/src/Mod/TechDraw/App/Geometry.h index 3117f075fa..0ceb01d23a 100644 --- a/src/Mod/TechDraw/App/Geometry.h +++ b/src/Mod/TechDraw/App/Geometry.h @@ -100,7 +100,7 @@ class TechDrawExport BaseGeom std::string dump(); protected: - int m_source; + int m_source; //0 - geom, 1 - cosmetic edge, 2 - centerline int m_sourceIndex; }; diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 543758c36d..7844b7b41e 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -54,6 +54,7 @@ set(TechDrawGui_MOC_HDRS TaskRichAnno.h TaskCosVertex.h TaskCenterLine.h + TaskLineDecor.h QGEPath.h QGTracker.h QGILeaderLine.h @@ -87,6 +88,7 @@ set(TechDrawGui_UIC_SRCS TaskBalloon.ui TaskCosVertex.ui TaskCenterLine.ui + TaskLineDecor.ui ) if(BUILD_QT5) @@ -159,6 +161,9 @@ SET(TechDrawGui_SRCS TaskCenterLine.ui TaskCenterLine.cpp TaskCenterLine.h + TaskLineDecor.ui + TaskLineDecor.cpp + TaskLineDecor.h DrawGuiUtil.cpp DrawGuiUtil.h Rez.cpp @@ -311,6 +316,7 @@ SET(TechDrawGuiTaskDlgs_SRCS mrichtextedit.ui TaskBalloon.ui TaskCenterLine.ui + TaskLineDecor.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index 33460fd883..b2d7d06e57 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -59,6 +59,7 @@ #include "TaskRichAnno.h" #include "TaskCosVertex.h" #include "TaskCenterLine.h" +#include "TaskLineDecor.h" #include "ViewProviderPage.h" #include "QGVPage.h" @@ -796,6 +797,89 @@ bool CmdTechDrawCosmeticEraser::isActive(void) return (havePage && haveView); } +//=========================================================================== +// TechDraw_DecorateLine +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDrawDecorateLine); + +CmdTechDrawDecorateLine::CmdTechDrawDecorateLine() + : Command("TechDraw_DecorateLine") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Change the appearance of a line"); + sToolTipText = QT_TR_NOOP("Change the appearance of a line"); + sWhatsThis = "TechDraw_DecorateLine"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-linedecor"; +} + +void CmdTechDrawDecorateLine::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::DrawViewPart* baseFeat = nullptr; + if (!selection.empty()) { + baseFeat = dynamic_cast(selection[0].getObject()); + if( baseFeat == nullptr ) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), + QObject::tr("No View in Selection.")); + return; + } + } else { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), + QObject::tr("You must select line(s) in a View.")); + return; + } + + std::vector SubNames; + + std::vector::iterator itSel = selection.begin(); + for (; itSel != selection.end(); itSel++) { + if ((*itSel).getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + baseFeat = static_cast ((*itSel).getObject()); + SubNames = (*itSel).getSubNames(); + } + } + std::vector edgeNames; + for (auto& s: SubNames) { + std::string geomType = DrawUtil::getGeomTypeFromName(s); + if (geomType == "Edge") { + edgeNames.push_back(s); + } + } + + if ( edgeNames.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection Error"), + QObject::tr("You must select line(s) to edit.")); + return; + } else { + Gui::Control().showDialog(new TaskDlgLineDecor(baseFeat, + edgeNames)); + } +} + +bool CmdTechDrawDecorateLine::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, false); + return (havePage && haveView); +} + void CreateTechDrawCommandsAnnotate(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -809,6 +893,7 @@ void CreateTechDrawCommandsAnnotate(void) rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); rcCmdMgr.addCommand(new CmdTechDrawFaceCenterLine()); rcCmdMgr.addCommand(new CmdTechDrawCosmeticEraser()); + rcCmdMgr.addCommand(new CmdTechDrawDecorateLine()); } //=========================================================================== diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index c22f17894b..ab7c9e59d2 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -440,21 +440,31 @@ void QGIViewPart::drawViewPart() showEdge = true; } } + bool showItem = true; if (showEdge) { item = new QGIEdge(i); item->setWidth(lineWidth); - //TODO: implement formats for geom lines. if ((*itGeom)->cosmetic == true) { int source = (*itGeom)->source(); int sourceIndex = (*itGeom)->sourceIndex(); if (source == 1) { //this is a "CosmeticEdge" - formatGeomFromCosmetic(sourceIndex, item); + showItem = formatGeomFromCosmetic(sourceIndex, item); } else if (source == 2) { //this is a "CenterLine" - formatGeomFromCenterLine(sourceIndex, item); + showItem = formatGeomFromCenterLine(sourceIndex, item); } else { Base::Console().Message("QGIVP::drawVP - edge: %d is confused - source: %d\n",i,source); } + } else { + //TODO: implement formats for geom lines. + TechDraw::GeomFormat* gf = viewPart->getGeomFormatByGeom(i); + if (gf != nullptr) { + item->setNormalColor(gf->m_format.m_color.asValue()); + item->setWidth(gf->m_format.m_weight * lineScaleFactor); + item->setStyle(gf->m_format.m_style); + showItem = gf->m_format.m_visible; + } } + addToGroup(item); //item is at scene(0,0), not group(0,0) item->setPos(0.0,0.0); //now at group(0,0) item->setPath(drawPainterPath(*itGeom)); @@ -468,6 +478,9 @@ void QGIViewPart::drawViewPart() item->setWidth(lineWidthIso); } item->setPrettyNormal(); + if (!showItem) { + item->hide(); + } //debug a path // QPainterPath edgePath=drawPainterPath(*itGeom); // std::stringstream edgeId; @@ -548,28 +561,34 @@ void QGIViewPart::drawViewPart() } } -void QGIViewPart::formatGeomFromCosmetic(int sourceIndex, QGIEdge* item) +bool QGIViewPart::formatGeomFromCosmetic(int sourceIndex, QGIEdge* item) { // Base::Console().Message("QGIVP::formatGeomFromCosmetic(%d)\n",sourceIndex); + bool result = true; auto partFeat( dynamic_cast(getViewObject()) ); TechDraw::CosmeticEdge* ce = partFeat->getCosmeticEdgeByIndex(sourceIndex); if (ce != nullptr) { item->setNormalColor(ce->m_format.m_color.asValue()); item->setWidth(ce->m_format.m_weight * lineScaleFactor); item->setStyle(ce->m_format.m_style); + result = ce->m_format.m_visible; } + return result; } -void QGIViewPart::formatGeomFromCenterLine(int sourceIndex, QGIEdge* item) +bool QGIViewPart::formatGeomFromCenterLine(int sourceIndex, QGIEdge* item) { // Base::Console().Message("QGIVP::formatGeomFromCenterLine(%d)\n",sourceIndex); + bool result = true; auto partFeat( dynamic_cast(getViewObject()) ); TechDraw::CenterLine* cl = partFeat->getCenterLineByIndex(sourceIndex); if (cl != nullptr) { - item->setNormalColor(cl->fmt.m_color.asValue()); - item->setWidth(cl->fmt.m_weight * lineScaleFactor); - item->setStyle(cl->fmt.m_style); + item->setNormalColor(cl->m_format.m_color.asValue()); + item->setWidth(cl->m_format.m_weight * lineScaleFactor); + item->setStyle(cl->m_format.m_style); + result = cl->m_format.m_visible; } + return result; } QGIFace* QGIViewPart::drawFace(TechDraw::Face* f, int idx) diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.h b/src/Mod/TechDraw/Gui/QGIViewPart.h index 6026e4c16e..60f8d42b41 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.h +++ b/src/Mod/TechDraw/Gui/QGIViewPart.h @@ -107,8 +107,8 @@ protected: bool prefPrintCenters(void); - void formatGeomFromCosmetic(int sourceIndex, QGIEdge* item); - void formatGeomFromCenterLine(int sourceIndex, QGIEdge* item); + bool formatGeomFromCosmetic(int sourceIndex, QGIEdge* item); + bool formatGeomFromCenterLine(int sourceIndex, QGIEdge* item); private: diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 4297c3ab87..aabbfccd30 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -68,6 +68,8 @@ icons/actions/techdraw-quadrant.svg icons/actions/techdraw-facecenterline.svg icons/actions/techdraw-eraser.svg + icons/actions/techdraw-linedecor.svg + icons/actions/techdraw-facedecor.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-facedecor.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-facedecor.svg new file mode 100644 index 0000000000..2e7e0f090f --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-facedecor.svg @@ -0,0 +1,129 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-linedecor.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-linedecor.svg new file mode 100644 index 0000000000..c47ad1294f --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-linedecor.svg @@ -0,0 +1,545 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TaskCenterLine.cpp b/src/Mod/TechDraw/Gui/TaskCenterLine.cpp index 407b2ab8b6..588b6b8150 100644 --- a/src/Mod/TechDraw/Gui/TaskCenterLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskCenterLine.cpp @@ -173,9 +173,9 @@ void TaskCenterLine::setUiEdit() ui->lstSubList->addItem(listItem); } - ui->cpLineColor->setColor(m_cl->fmt.m_color.asValue()); - ui->dsbWeight->setValue(m_cl->fmt.m_weight); - ui->cboxStyle->setCurrentIndex(m_cl->fmt.m_style); + ui->cpLineColor->setColor(m_cl->m_format.m_color.asValue()); + ui->dsbWeight->setValue(m_cl->m_format.m_weight); + ui->cboxStyle->setCurrentIndex(m_cl->m_format.m_style); int precision = Base::UnitsApi::getDecimals(); ui->dsbRotate->setDecimals(precision); @@ -183,21 +183,21 @@ void TaskCenterLine::setUiEdit() ui->rbVertical->setChecked(false); ui->rbHorizontal->setChecked(false); ui->rbAligned->setChecked(false); - if (m_cl->mode == 0) { + if (m_cl->m_mode == 0) { ui->rbVertical->setChecked(true); - } else if (m_cl->mode == 1) { + } else if (m_cl->m_mode == 1) { ui->rbHorizontal->setChecked(true); - } else if (m_cl->mode ==2) { + } else if (m_cl->m_mode ==2) { ui->rbAligned->setChecked(true); } - ui->dsbRotate->setValue(m_cl->rotate); + ui->dsbRotate->setValue(m_cl->m_rotate); Base::Quantity qVal; qVal.setUnit(Base::Unit::Length); - qVal.setValue(m_cl->vShift); + qVal.setValue(m_cl->m_vShift); ui->qsbVertShift->setValue(qVal); - qVal.setValue(m_cl->hShift); + qVal.setValue(m_cl->m_hShift); ui->qsbHorizShift->setValue(qVal); - qVal.setValue(m_cl->extendBy); + qVal.setValue(m_cl->m_extendBy); ui->qsbExtend->setValue(qVal); } @@ -221,28 +221,28 @@ void TaskCenterLine::createCenterLine(void) extendBy, hShift, vShift, rotate); TechDraw::CenterLine* cl = new TechDraw::CenterLine(ends.first, ends.second); - cl->start = ends.first; - cl->end = ends.second; + cl->m_start = ends.first; + cl->m_end = ends.second; App::Color ac; ac.setValue(ui->cpLineColor->color()); - cl->fmt.m_color = ac; - cl->fmt.m_weight = ui->dsbWeight->value(); - cl->fmt.m_style = ui->cboxStyle->currentIndex(); - cl->fmt.m_visible = true; + cl->m_format.m_color = ac; + cl->m_format.m_weight = ui->dsbWeight->value(); + cl->m_format.m_style = ui->cboxStyle->currentIndex(); + cl->m_format.m_visible = true; if (ui->rbVertical->isChecked()) { - cl->mode = 0; + cl->m_mode = 0; } else if (ui->rbHorizontal->isChecked()) { - cl->mode = 1; + cl->m_mode = 1; } else if (ui->rbAligned->isChecked()) { - cl->mode = 2; + cl->m_mode = 2; } cl->m_faces = m_subNames; - cl->rotate = rotate; - cl->vShift = vShift; - cl->hShift = hShift; - cl->extendBy = extendBy; + cl->m_rotate = rotate; + cl->m_vShift = vShift; + cl->m_hShift = hShift; + cl->m_extendBy = extendBy; m_partFeat->addCenterLine(cl); @@ -256,22 +256,22 @@ void TaskCenterLine::updateCenterLine(void) { // Base::Console().Message("TCL::updateCenterLine()\n"); Gui::Command::openCommand("Edit CenterLine"); - m_cl->fmt.m_color.setValue(ui->cpLineColor->color() ); - m_cl->fmt.m_weight = ui->dsbWeight->value(); - m_cl->fmt.m_style = ui->cboxStyle->currentIndex(); - m_cl->fmt.m_visible = true; + m_cl->m_format.m_color.setValue(ui->cpLineColor->color() ); + m_cl->m_format.m_weight = ui->dsbWeight->value(); + m_cl->m_format.m_style = ui->cboxStyle->currentIndex(); + m_cl->m_format.m_visible = true; if (ui->rbVertical->isChecked()) { - m_cl->mode = 0; + m_cl->m_mode = 0; } else if (ui->rbHorizontal->isChecked()) { - m_cl->mode = 1; + m_cl->m_mode = 1; } else if (ui->rbAligned->isChecked()) { - m_cl->mode = 2; + m_cl->m_mode = 2; } - m_cl->rotate = ui->dsbRotate->value(); - m_cl->vShift = ui->qsbVertShift->rawValue(); - m_cl->hShift = ui->qsbHorizShift->rawValue(); - m_cl->extendBy = ui->qsbExtend->rawValue(); + m_cl->m_rotate = ui->dsbRotate->value(); + m_cl->m_vShift = ui->qsbVertShift->rawValue(); + m_cl->m_hShift = ui->qsbHorizShift->rawValue(); + m_cl->m_extendBy = ui->qsbExtend->rawValue(); m_partFeat->replaceCenterLine(m_clIdx, m_cl); m_partFeat->requestPaint(); //is requestPaint enough here? // m_partFeat->recomputeFeature(); diff --git a/src/Mod/TechDraw/Gui/TaskLineDecor.cpp b/src/Mod/TechDraw/Gui/TaskLineDecor.cpp new file mode 100644 index 0000000000..0ecf65738f --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskLineDecor.cpp @@ -0,0 +1,275 @@ +/*************************************************************************** + * Copyright (c) 2018 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 +#include +#include +#include + +#include "TaskLineDecor.h" +#include + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +TaskLineDecor::TaskLineDecor(TechDraw::DrawViewPart* partFeat, + std::vector edgeNames) : + ui(new Ui_TaskLineDecor), + m_partFeat(partFeat), + m_edges(edgeNames) +{ + getDefaults(); + ui->setupUi(this); + + connect(ui->cb_Style, SIGNAL(currentIndexChanged( int )), this, SLOT(onStyleChanged(void))); + connect(ui->cc_Color, SIGNAL(changed( )), this, SLOT(onColorChanged(void))); + connect(ui->dsb_Weight, SIGNAL(valueChanged( double )), this, SLOT(onWeightChanged( void ))); + connect(ui->cb_Visible, SIGNAL(currentIndexChanged( int )), this, SLOT(onVisibleChanged( void ))); + + initUi(); +} + +TaskLineDecor::~TaskLineDecor() +{ + delete ui; +} + +void TaskLineDecor::initUi() +{ + std::string viewName = m_partFeat->getNameInDocument(); + ui->le_View->setText(Base::Tools::fromStdString(viewName)); + + std::stringstream ss; + for (auto& e: m_edges) { + int num = DrawUtil::getIndexFromName(e); + ss << num << ", "; + } + std::string temp = ss.str(); + if (!temp.empty()) { + temp.pop_back(); + } + ui->le_Lines->setText(Base::Tools::fromStdString(temp)); + + ui->cb_Style->setCurrentIndex(m_style); + ui->cc_Color->setColor(m_color.asValue()); + ui->dsb_Weight->setValue(m_weight); + ui->cb_Visible->setCurrentIndex(m_visible); +} + +void TaskLineDecor::getDefaults(void) +{ + m_style = LineFormat::getDefEdgeStyle(); + m_color = LineFormat::getDefEdgeColor(); + m_weight = LineFormat::getDefEdgeWidth(); + m_visible = 1; + + //set defaults to format of 1st edge + int num = DrawUtil::getIndexFromName(m_edges.front()); + BaseGeom* bg = m_partFeat->getGeomByIndex(num); + if (bg != nullptr) { + if (bg->cosmetic) { + if (bg->source() == 1) { + TechDraw::CosmeticEdge* ce = m_partFeat->getCosmeticEdgeByIndex(bg->sourceIndex()); + m_style = ce->m_format.m_style; + m_color = ce->m_format.m_color; + m_weight = ce->m_format.m_weight; + m_visible = ce->m_format.m_visible; + } else if (bg->source() == 2) { + TechDraw::CenterLine* cl = m_partFeat->getCenterLineByIndex(bg->sourceIndex()); + m_style = cl->m_format.m_style; + m_color = cl->m_format.m_color; + m_weight = cl->m_format.m_weight; + m_visible = cl->m_format.m_visible; + } + } else { + TechDraw::GeomFormat* gf = m_partFeat->getGeomFormatByGeom(num); + if (gf != nullptr) { + m_style = gf->m_format.m_style; + m_color = gf->m_format.m_color; + m_weight = gf->m_format.m_weight; + m_visible = gf->m_format.m_visible; + } + } + } +} + +void TaskLineDecor::onStyleChanged(void) +{ + m_style = ui->cb_Style->currentIndex(); + //livePreview(); +} + +void TaskLineDecor::onColorChanged(void) +{ + m_color.setValue(ui->cc_Color->color()); + //livePreview(); +} + +void TaskLineDecor::onWeightChanged(void) +{ + m_weight = ui->dsb_Weight->value(); + //livePreview(); +} + +void TaskLineDecor::onVisibleChanged(void) +{ + m_visible = ui->cb_Visible->currentIndex(); + //livePreview(); +} + +void TaskLineDecor::applyDecorations(void) +{ +// Base::Console().Message("TLD::applyDecorations()\n"); + for (auto& e: m_edges) { + int num = DrawUtil::getIndexFromName(e); + BaseGeom* bg = m_partFeat->getGeomByIndex(num); + if (bg != nullptr) { + if (bg->cosmetic) { + if (bg->source() == 1) { + TechDraw::CosmeticEdge* ce = m_partFeat->getCosmeticEdgeByIndex(bg->sourceIndex()); + ce->m_format.m_style = m_style; + ce->m_format.m_color = m_color; + ce->m_format.m_weight = m_weight; + ce->m_format.m_visible = m_visible; + } else if (bg->source() == 2) { + TechDraw::CenterLine* cl = m_partFeat->getCenterLineByIndex(bg->sourceIndex()); + cl->m_format.m_style = m_style; + cl->m_format.m_color = m_color; + cl->m_format.m_weight = m_weight; + cl->m_format.m_visible = m_visible; + } + } else { + TechDraw::GeomFormat* gf = m_partFeat->getGeomFormatByGeom(num); + if (gf != nullptr) { + gf->m_format.m_style = m_style; + gf->m_format.m_color = m_color; + gf->m_format.m_weight = m_weight; + gf->m_format.m_visible = m_visible; + } else { + TechDraw::LineFormat fmt(m_style, + m_weight, + m_color, + m_visible); + TechDraw::GeomFormat* newGF = new TechDraw::GeomFormat(num, + fmt); +// int idx = + m_partFeat->addGeomFormat(newGF); + } + } + } + } +} + +bool TaskLineDecor::accept() +{ + Gui::Document* doc = Gui::Application::Instance->getDocument(m_partFeat->getDocument()); + if (!doc) return false; + + applyDecorations(); + m_partFeat->requestPaint(); + + //Gui::Command::updateActive(); //no chain of updates here + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return true; +} + +bool TaskLineDecor::reject() +{ + Gui::Document* doc = Gui::Application::Instance->getDocument(m_partFeat->getDocument()); + if (!doc) return false; + + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + return false; +} + +void TaskLineDecor::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +TaskDlgLineDecor::TaskDlgLineDecor(TechDraw::DrawViewPart* partFeat, + std::vector edgeNames) : + TaskDialog() +{ + widget = new TaskLineDecor(partFeat, edgeNames); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-linedecor"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgLineDecor::~TaskDlgLineDecor() +{ +} + +//==== calls from the TaskView =============================================================== +void TaskDlgLineDecor::open() +{ + +} + +void TaskDlgLineDecor::clicked(int i) +{ + Q_UNUSED(i); +} + +bool TaskDlgLineDecor::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgLineDecor::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskLineDecor.h b/src/Mod/TechDraw/Gui/TaskLineDecor.h new file mode 100644 index 0000000000..8443f20f18 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskLineDecor.h @@ -0,0 +1,111 @@ +/*************************************************************************** + * Copyright (c) 2018 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_TASKLINEDECOR_H +#define GUI_TASKVIEW_TASKLINEDECOR_H + +#include +#include +#include +#include + +#include + +class Ui_TaskLineDecor; + +namespace App +{ +class DocumentObject; +} + + +namespace TechDrawGui +{ + +class TaskLineDecor : public QWidget +{ + Q_OBJECT + +public: + TaskLineDecor(TechDraw::DrawViewPart* partFeat, + std::vector edgeNames); + ~TaskLineDecor(); + +public: + virtual bool accept(); + virtual bool reject(); + +protected Q_SLOTS: + void onStyleChanged(void); + void onColorChanged(void); + void onWeightChanged(void); + void onVisibleChanged(void); + +protected: + void changeEvent(QEvent *e); + void initUi(void); + void applyDecorations(void); + void getDefaults(void); + +private: + Ui_TaskLineDecor* ui; + TechDraw::DrawViewPart* m_partFeat; + std::vector m_edges; + int m_style; + App::Color m_color; + double m_weight; + bool m_visible; +}; + +class TaskDlgLineDecor : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgLineDecor(TechDraw::DrawViewPart* partFeat, + std::vector edgeNames); + ~TaskDlgLineDecor(); + +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; } + +protected: + +private: + TaskLineDecor * widget; + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef GUI_TASKVIEW_TASKLINEDECOR_H diff --git a/src/Mod/TechDraw/Gui/TaskLineDecor.ui b/src/Mod/TechDraw/Gui/TaskLineDecor.ui new file mode 100644 index 0000000000..0911d0552b --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskLineDecor.ui @@ -0,0 +1,256 @@ + + + TechDrawGui::TaskLineDecor + + + + 0 + 0 + 395 + 294 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Line Decoration + + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + false + + + + + + + Lines + + + + + + + View + + + + + + + false + + + false + + + Qt::NoFocus + + + false + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Color + + + + + + + Style + + + + + + + Weight + + + + + + + + 0 + 0 + 0 + + + + + + + + Thickness of pattern lines. + + + 0.500000000000000 + + + + + + + Visible + + + + + + + 1 + + + 2 + + + 2 + + + 2 + + + + False + + + + + True + + + + + + + + 1 + + + + NoLine + + + + + Solid + + + + + Dash + + + + + Dot + + + + + DashDot + + + + + DashDotDot + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
+
+ + + + +
diff --git a/src/Mod/TechDraw/Gui/Workbench.cpp b/src/Mod/TechDraw/Gui/Workbench.cpp index 1f9d9f82bf..39e3e8a1d2 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -94,6 +94,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const *draw << "TechDraw_Midpoints"; *draw << "TechDraw_Quadrant"; *draw << "TechDraw_CosmeticEraser"; + *draw << "TechDraw_DecorateLine"; return root; } @@ -158,7 +159,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const *anno << "TechDraw_CosmeticVertexGrp"; *anno << "TechDraw_FaceCenterLine"; *anno << "TechDraw_CosmeticEraser"; - + *anno << "TechDraw_DecorateLine"; return root; } @@ -220,6 +221,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const *anno << "TechDraw_CosmeticVertexGrp"; *anno << "TechDraw_FaceCenterLine"; *anno << "TechDraw_CosmeticEraser"; + *anno << "TechDraw_DecorateLine"; return root; }