diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index 82d9025f9e..d2fcaf9778 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -512,17 +512,24 @@ void CosmeticEdge::Restore(Base::XMLReader &reader) gen->Restore(reader); gen->occEdge = GeometryUtils::edgeFromGeneric(gen); m_geometry = (TechDraw::BaseGeom*) gen; - + permaStart = gen->getStartPoint(); + permaEnd = gen->getEndPoint(); } else if (gType == TechDraw::GeomType::CIRCLE) { TechDraw::Circle* circ = new TechDraw::Circle(); circ->Restore(reader); circ->occEdge = GeometryUtils::edgeFromCircle(circ); m_geometry = (TechDraw::BaseGeom*) circ; + permaRadius = circ->radius; + permaStart = circ->center; + permaEnd = circ->center; } else if (gType == TechDraw::GeomType::ARCOFCIRCLE) { TechDraw::AOC* aoc = new TechDraw::AOC(); aoc->Restore(reader); aoc->occEdge = GeometryUtils::edgeFromCircleArc(aoc); m_geometry = (TechDraw::BaseGeom*) aoc; + permaStart = aoc->startPnt; + permaEnd = aoc->endPnt; + permaRadius = aoc->radius; } else { Base::Console().Warning("CE::Restore - unimplemented geomType: %d\n", gType); } diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index d757e0168b..09815933e4 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -1290,7 +1290,7 @@ void DrawViewPart::refreshCEGeoms(void) std::vector gEdges = getEdgeGeometry(); std::vector oldGEdges; for (auto& ge :gEdges) { - if (ge->getCosmeticTag().empty()) { //keep only non-ce edges + if (ge->source() != SourceType::COSEDGE) { oldGEdges.push_back(ge); } } @@ -1328,8 +1328,7 @@ void DrawViewPart::refreshCLGeoms(void) std::vector gEdges = getEdgeGeometry(); std::vector newGEdges; for (auto& ge :gEdges) { - //TODO: this will keep CE & CL - if (ge->getCosmeticTag().empty()) { //keep only non-cl edges + if (ge->source() != SourceType::CENTERLINE) { newGEdges.push_back(ge); } } diff --git a/src/Mod/TechDraw/App/DrawViewPartPy.xml b/src/Mod/TechDraw/App/DrawViewPartPy.xml index ad2147a06e..0d741b1a08 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPy.xml +++ b/src/Mod/TechDraw/App/DrawViewPartPy.xml @@ -63,6 +63,11 @@ tag = makeCosmeticLine(p1, p2) - add a CosmeticEdge from p1 to p2(View coordinates). Returns tag of new CosmeticEdge. + + + tag = makeCosmeticLine3D(p1, p2) - add a CosmeticEdge from p1 to p2(3D coordinates). Returns tag of new CosmeticEdge. + + tag = makeCosmeticCircle(center, radius) - add a CosmeticEdge at center with radius radius(View coordinates). Returns tag of new CosmeticEdge. diff --git a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp index ebfa0e68fd..abb38c5925 100644 --- a/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp +++ b/src/Mod/TechDraw/App/DrawViewPartPyImp.cpp @@ -327,6 +327,53 @@ PyObject* DrawViewPartPy::makeCosmeticLine(PyObject *args) return PyUnicode_FromString(newTag.c_str()); //return tag for new CE } +PyObject* DrawViewPartPy::makeCosmeticLine3D(PyObject *args) +{ + PyObject* pPnt1 = nullptr; + PyObject* pPnt2 = nullptr; + int style = LineFormat::getDefEdgeStyle(); + double weight = LineFormat::getDefEdgeWidth(); + App::Color defCol = LineFormat::getDefEdgeColor(); + PyObject* pColor = nullptr; + + if (!PyArg_ParseTuple(args, "O!O!|idO", &(Base::VectorPy::Type), &pPnt1, + &(Base::VectorPy::Type), &pPnt2, + &style, &weight, + &pColor)) { + throw Py::TypeError("expected (vector, vector,[style,weight,color])"); + } + + DrawViewPart* dvp = getDrawViewPartPtr(); + Base::Vector3d centroid = dvp->getOriginalCentroid(); + + Base::Vector3d pnt1 = static_cast(pPnt1)->value(); + pnt1 = pnt1 - centroid; + pnt1 = DrawUtil::invertY(dvp->projectPoint(pnt1)); + + Base::Vector3d pnt2 = static_cast(pPnt2)->value(); + pnt2 = pnt2 - centroid; + pnt2 = DrawUtil::invertY(dvp->projectPoint(pnt2)); + + std::string newTag = dvp->addCosmeticEdge(pnt1, pnt2); + TechDraw::CosmeticEdge* ce = dvp->getCosmeticEdge(newTag); + if (ce != nullptr) { + ce->m_format.m_style = style; + ce->m_format.m_weight = weight; + if (pColor == nullptr) { + ce->m_format.m_color = defCol; + } else { + ce->m_format.m_color = DrawUtil::pyTupleToColor(pColor); + } + } else { + std::string msg = "DVPPI:makeCosmeticLine - line creation failed"; + Base::Console().Message("%s\n",msg.c_str()); + throw Py::RuntimeError(msg); + } + //int link = + dvp->add1CEToGE(newTag); + dvp->requestPaint(); + return PyUnicode_FromString(newTag.c_str()); //return tag for new CE +} PyObject* DrawViewPartPy::makeCosmeticCircle(PyObject *args) { PyObject* pPnt1 = nullptr; diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 9ffdbfd6de..6b2872b800 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -75,6 +75,7 @@ set(TechDrawGui_MOC_HDRS TaskActiveView.h TaskDetail.h QGIGhostHighlight.h + TaskCosmeticLine.h ) fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS}) @@ -112,6 +113,7 @@ set(TechDrawGui_UIC_SRCS SymbolChooser.ui TaskActiveView.ui TaskDetail.ui + TaskCosmeticLine.ui ) if(BUILD_QT5) @@ -226,6 +228,9 @@ SET(TechDrawGui_SRCS TaskDetail.h PreferencesGui.cpp PreferencesGui.h + TaskCosmeticLine.ui + TaskCosmeticLine.cpp + TaskCosmeticLine.h ) SET(TechDrawGuiView_SRCS @@ -393,6 +398,7 @@ SET(TechDrawGuiTaskDlgs_SRCS SymbolChooser.ui TaskActiveView.ui TaskDetail.ui + TaskCosmeticLine.ui ) SOURCE_GROUP("TaskDialogs" FILES ${TechDrawGuiTaskDlgs_SRCS}) diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index 6f32a3a717..006537ea99 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -64,6 +64,7 @@ #include "TaskCenterLine.h" #include "TaskLineDecor.h" #include "TaskWeldingSymbol.h" +#include "TaskCosmeticLine.h" #include "ViewProviderPage.h" #include "ViewProviderViewPart.h" #include "QGVPage.h" @@ -82,6 +83,7 @@ void execQuadrants(Gui::Command* cmd); void execCenterLine(Gui::Command* cmd); void exec2LineCenterLine(Gui::Command* cmd); void exec2PointCenterLine(Gui::Command* cmd); +void execLine2Points(Gui::Command* cmd); std::vector getSelectedSubElements(Gui::Command* cmd, TechDraw::DrawViewPart* &dvp, std::string subType = "Edge"); @@ -136,7 +138,9 @@ void CmdTechDrawLeaderLine::activated(int iMsg) } Gui::Control().showDialog(new TechDrawGui::TaskDlgLeaderLine(baseFeat, - page)); + page)); + updateActive(); + Gui::Selection().clearSelection(); } bool CmdTechDrawLeaderLine::isActive(void) @@ -187,6 +191,8 @@ void CmdTechDrawRichTextAnnotation::activated(int iMsg) Gui::Control().showDialog(new TaskDlgRichAnno(baseFeat, page)); + updateActive(); + Gui::Selection().clearSelection(); } bool CmdTechDrawRichTextAnnotation::isActive(void) @@ -239,6 +245,8 @@ void CmdTechDrawCosmeticVertexGroup::activated(int iMsg) default: Base::Console().Message("CMD::CVGrp - invalid iMsg: %d\n",iMsg); }; + updateActive(); + Gui::Selection().clearSelection(); } Gui::Action * CmdTechDrawCosmeticVertexGroup::createAction(void) @@ -423,6 +431,8 @@ void CmdTechDrawCosmeticVertex::activated(int iMsg) Gui::Control().showDialog(new TaskDlgCosVertex(baseFeat, page)); + updateActive(); + Gui::Selection().clearSelection(); } bool CmdTechDrawCosmeticVertex::isActive(void) @@ -870,6 +880,8 @@ void CmdTechDraw2PointCenterLine::activated(int iMsg) } exec2PointCenterLine(this); + updateActive(); + Gui::Selection().clearSelection(); } bool CmdTechDraw2PointCenterLine::isActive(void) @@ -951,6 +963,155 @@ void exec2PointCenterLine(Gui::Command* cmd) } } +//=========================================================================== +// TechDraw_2PointCosmeticLine +//=========================================================================== + +DEF_STD_CMD_A(CmdTechDraw2PointCosmeticLine) + +CmdTechDraw2PointCosmeticLine::CmdTechDraw2PointCosmeticLine() + : Command("TechDraw_2PointCosmeticLine") +{ + sAppModule = "TechDraw"; + sGroup = QT_TR_NOOP("TechDraw"); + sMenuText = QT_TR_NOOP("Add Cosmetic Line Through 2 Points"); + sToolTipText = sMenuText; + sWhatsThis = "TechDraw_2PointCosmeticLine"; + sStatusTip = sToolTipText; + sPixmap = "actions/techdraw-line2points"; +} + +void CmdTechDraw2PointCosmeticLine::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; + } + + execLine2Points(this); + + updateActive(); + Gui::Selection().clearSelection(); +} + +bool CmdTechDraw2PointCosmeticLine::isActive(void) +{ + bool havePage = DrawGuiUtil::needPage(this); + bool haveView = DrawGuiUtil::needView(this, true); + return (havePage && haveView); +} + +void execLine2Points(Gui::Command* cmd) +{ + TechDraw::DrawPage* page = DrawGuiUtil::findPage(cmd); + if (!page) { + return; + } + + std::vector selection = cmd->getSelection().getSelectionEx(); + TechDraw::DrawViewPart* baseFeat = nullptr; + std::vector subNames2D; + std::vector< std::pair > objs3D; + if (!selection.empty()) { + for (auto& so: selection) { + if (so.getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + baseFeat = static_cast (so.getObject()); + subNames2D = so.getSubNames(); + } else if (so.getObject()->isDerivedFrom(Part::Feature::getClassTypeId())) { + std::vector subNames3D = so.getSubNames(); + for (auto& sub3D: subNames3D) { + std::pair temp; + temp.first = static_cast(so.getObject()); + temp.second = sub3D; + objs3D.push_back(temp); + } + } else { + //garbage + } + } + } else { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("Selection is empty.")); + return; + } + + if (baseFeat == nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("You must select a base View for the line.")); + return; + } + + //TODO: should be a smarter check + if ( (subNames2D.empty()) && + (objs3D.empty()) ) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("Not enough points in selection.")); + return; + } + + std::vector edgeNames; + std::vector vertexNames; + for (auto& s: subNames2D) { + std::string geomType = DrawUtil::getGeomTypeFromName(s); + if (geomType == "Vertex") { + vertexNames.push_back(s); + } else if (geomType == "Edge") { + edgeNames.push_back(s); + } + } + + //check if editing existing edge + if (!edgeNames.empty() && (edgeNames.size() == 1)) { + TechDraw::CosmeticEdge* ce = baseFeat->getCosmeticEdgeBySelection(edgeNames.front()); + if (ce == nullptr) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("Selection is not a Cosmetic Line.")); + return; + } + Gui::Control().showDialog(new TaskDlgCosmeticLine(baseFeat, + edgeNames.front())); + return; + } + + double scale = baseFeat->getScale(); + std::vector points; + std::vector is3d; + //get the 2D points + if (!vertexNames.empty()) { + for (auto& v2d: vertexNames) { + int idx = DrawUtil::getIndexFromName(v2d); + TechDraw::Vertex* v = baseFeat->getProjVertexByIndex(idx); + Base::Vector3d p = DrawUtil::invertY(v->pnt); + points.push_back(p / scale); + is3d.push_back(false); + } + } + //get the 3D points + if (!objs3D.empty()) { + for (auto& o3D: objs3D) { + int idx = DrawUtil::getIndexFromName(o3D.second); + Part::TopoShape s = o3D.first->Shape.getShape(); + TopoDS_Vertex v = TopoDS::Vertex(s.getSubShape(TopAbs_VERTEX, idx)); + Base::Vector3d p = DrawUtil::vertex2Vector(v); + points.push_back(p); + is3d.push_back(true); + } + } + + if (points.size() != 2) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong Selection"), + QObject::tr("You must select 2 Vertexes.")); + return; + } + + Gui::Control().showDialog(new TaskDlgCosmeticLine(baseFeat, + points, + is3d)); +} //=========================================================================== // TechDraw_CosmeticEraser @@ -1147,6 +1308,8 @@ void CmdTechDrawDecorateLine::activated(int iMsg) Gui::Control().showDialog(new TaskDlgLineDecor(baseFeat, edgeNames)); + updateActive(); + Gui::Selection().clearSelection(); } bool CmdTechDrawDecorateLine::isActive(void) @@ -1274,6 +1437,8 @@ void CmdTechDrawWeldSymbol::activated(int iMsg) weldFeat = static_cast (welds.front()); Gui::Control().showDialog(new TaskDlgWeldingSymbol(weldFeat)); } + updateActive(); + Gui::Selection().clearSelection(); } bool CmdTechDrawWeldSymbol::isActive(void) @@ -1298,6 +1463,7 @@ void CreateTechDrawCommandsAnnotate(void) rcCmdMgr.addCommand(new CmdTechDrawFaceCenterLine()); rcCmdMgr.addCommand(new CmdTechDraw2LineCenterLine()); rcCmdMgr.addCommand(new CmdTechDraw2PointCenterLine()); + rcCmdMgr.addCommand(new CmdTechDraw2PointCosmeticLine()); rcCmdMgr.addCommand(new CmdTechDrawAnnotation()); rcCmdMgr.addCommand(new CmdTechDrawCosmeticEraser()); rcCmdMgr.addCommand(new CmdTechDrawDecorateLine()); diff --git a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc index 51d3619238..e89df5e3bf 100644 --- a/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc +++ b/src/Mod/TechDraw/Gui/Resources/TechDraw.qrc @@ -75,6 +75,7 @@ icons/actions/techdraw-facecenterline.svg icons/actions/techdraw-2linecenterline.svg icons/actions/techdraw-2pointcenterline.svg + icons/actions/techdraw-line2points.svg icons/actions/techdraw-CosmeticEraser.svg icons/actions/techdraw-DecorateLine.svg icons/actions/techdraw-facedecor.svg diff --git a/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-line2points.svg b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-line2points.svg new file mode 100644 index 0000000000..83216418c2 --- /dev/null +++ b/src/Mod/TechDraw/Gui/Resources/icons/actions/techdraw-line2points.svg @@ -0,0 +1,214 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp b/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp new file mode 100644 index 0000000000..a2bcd2fab8 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp @@ -0,0 +1,343 @@ +/*************************************************************************** + * Copyright (c) 2020 Wandererfan +#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 +#include +#include + +#include + +#include "DrawGuiStd.h" +#include "PreferencesGui.h" +#include "QGVPage.h" +#include "QGIView.h" +#include "QGIPrimPath.h" +#include "MDIViewPage.h" +#include "ViewProviderPage.h" +#include "ViewProviderViewPart.h" +#include "Rez.h" + +#include "TaskCosmeticLine.h" + +using namespace Gui; +using namespace TechDraw; +using namespace TechDrawGui; + +//ctor for edit +TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat, + std::string edgeName) : + ui(new Ui_TaskCosmeticLine), + m_partFeat(partFeat), + m_edgeName(edgeName), + m_saveCE(nullptr), + m_createMode(false) +{ + if (m_partFeat == nullptr) { + //should be caught in CMD caller + Base::Console().Error("TaskCosmeticLine - bad parameters. Can not proceed.\n"); + return; + } + + m_ce = m_partFeat->getCosmeticEdgeBySelection(m_edgeName); + if (m_ce == nullptr) { + Base::Console().Error("TaskCosmeticLine - bad parameters. Can not proceed.\n"); + return; + } + + ui->setupUi(this); + + setUiEdit(); +} + +//ctor for creation +TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat, + std::vector points, + std::vector is3d) : + ui(new Ui_TaskCosmeticLine), + m_partFeat(partFeat), + m_saveCE(nullptr), + m_points(points), + m_is3d(is3d), + m_createMode(true) +{ + if (m_partFeat == nullptr) { + //should be caught in CMD caller + Base::Console().Error("TaskCosmeticLine - bad parameters. Can not proceed.\n"); + return; + } + + ui->setupUi(this); + + setUiPrimary(); +} + +TaskCosmeticLine::~TaskCosmeticLine() +{ + delete ui; + if (m_saveCE != nullptr) { + delete m_saveCE; + } +} + +void TaskCosmeticLine::updateTask() +{ +// blockUpdate = true; + +// blockUpdate = false; +} + +void TaskCosmeticLine::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + ui->retranslateUi(this); + } +} + +void TaskCosmeticLine::setUiPrimary() +{ + setWindowTitle(QObject::tr("Create Cosmetic Line")); + + if (m_is3d.front()) { + ui->rb2d1->setChecked(false); + ui->rb3d1->setChecked(true); + } else { + ui->rb2d1->setChecked(true); + ui->rb3d1->setChecked(false); + } + if (m_is3d.back()) { + ui->rb2d2->setChecked(false); + ui->rb3d2->setChecked(true); + } else { + ui->rb2d2->setChecked(true); + ui->rb3d2->setChecked(false); + } + Base::Vector3d p1 = m_points.front(); + ui->qsbx1->setUnit(Base::Unit::Length); + ui->qsbx1->setValue(p1.x); + ui->qsby1->setUnit(Base::Unit::Length); + ui->qsby1->setValue(p1.y); + ui->qsby1->setUnit(Base::Unit::Length); + ui->qsbz1->setValue(p1.z); + + Base::Vector3d p2 = m_points.back(); + ui->qsbx2->setUnit(Base::Unit::Length); + ui->qsbx2->setValue(p2.x); + ui->qsby2->setUnit(Base::Unit::Length); + ui->qsby2->setValue(p2.y); + ui->qsbz2->setUnit(Base::Unit::Length); + ui->qsbz2->setValue(p2.z); +} + +void TaskCosmeticLine::setUiEdit() +{ + setWindowTitle(QObject::tr("Edit Cosmetic Line")); + + ui->rb2d1->setChecked(true); + ui->rb3d1->setChecked(false); + ui->rb2d2->setChecked(true); + ui->rb3d2->setChecked(false); + + Base::Vector3d p1 = DrawUtil::invertY(m_ce->permaStart); + ui->qsbx1->setValue(p1.x); + ui->qsby1->setValue(p1.y); + ui->qsbz1->setValue(p1.z); + + Base::Vector3d p2 = DrawUtil::invertY(m_ce->permaEnd); + ui->qsbx2->setValue(p2.x); + ui->qsby2->setValue(p2.y); + ui->qsbz2->setValue(p2.z); +} + +//****************************************************************************** +void TaskCosmeticLine::createCosmeticLine(void) +{ + double x = ui->qsbx1->value().getValue(); + double y = ui->qsby1->value().getValue(); + double z = ui->qsbz1->value().getValue(); + Base::Vector3d p0(x, y, z); + + x = ui->qsbx2->value().getValue(); + y = ui->qsby2->value().getValue(); + z = ui->qsbz2->value().getValue(); + Base::Vector3d p1(x, y, z); + + Base::Vector3d centroid = m_partFeat->getOriginalCentroid(); + + if (ui->rb3d1->isChecked()) { + p0 = p0 - centroid; + p0 = DrawUtil::invertY(m_partFeat->projectPoint(p0)); + } + + if (ui->rb3d2->isChecked()) { + p1 = p1 - centroid; + p1 = DrawUtil::invertY(m_partFeat->projectPoint(p1)); + } + + m_tag = m_partFeat->addCosmeticEdge(p0, p1); + m_ce = m_partFeat->getCosmeticEdge(m_tag); +} + +void TaskCosmeticLine::updateCosmeticLine(void) +{ + double x = ui->qsbx1->value().getValue(); + double y = ui->qsby1->value().getValue(); + double z = ui->qsbz1->value().getValue(); + Base::Vector3d p0(x, y, z); + p0 = DrawUtil::invertY(p0); + + x = ui->qsbx2->value().getValue(); + y = ui->qsby2->value().getValue(); + z = ui->qsbz2->value().getValue(); + Base::Vector3d p1(x, y, z); + p1 = DrawUtil::invertY(p1); + + //replace the geometry + m_ce->permaStart = p0; + m_ce->permaEnd = p1; + gp_Pnt gp1(p0.x, p0.y, p0.z); + gp_Pnt gp2(p1.x, p1.y, p1.z); + TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2); + auto oldGeom = m_ce->m_geometry; + m_ce->m_geometry = TechDraw::BaseGeom::baseFactory(e); + delete oldGeom; + +// Gui::Command::updateActive(); +// Gui::Command::commitCommand(); +} + +//****************************************************************************** + +bool TaskCosmeticLine::accept() +{ + if (m_createMode) { + createCosmeticLine(); + m_partFeat->add1CEToGE(m_tag); + m_partFeat->refreshCEGeoms(); + m_partFeat->requestPaint(); + } else { + //update mode + Gui::Command::openCommand("Update CosmeticLine"); + updateCosmeticLine(); + m_partFeat->refreshCEGeoms(); + m_partFeat->requestPaint(); + Gui::Command::updateActive(); + Gui::Command::commitCommand(); + } + + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + + return true; +} + +bool TaskCosmeticLine::reject() +{ + //there's nothing to do. + Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); + return false; +} +//////////////////////////////////////////////////////////////////////////////// +TaskDlgCosmeticLine::TaskDlgCosmeticLine(TechDraw::DrawViewPart* partFeat, + std::vector points, + std::vector is3d) + : TaskDialog() +{ + widget = new TaskCosmeticLine(partFeat, points, is3d); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-line2points"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgCosmeticLine::TaskDlgCosmeticLine(TechDraw::DrawViewPart* partFeat, + std::string edgeName) + : TaskDialog() +{ + widget = new TaskCosmeticLine(partFeat, edgeName); + taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("actions/techdraw-line2points"), + widget->windowTitle(), true, 0); + taskbox->groupLayout()->addWidget(widget); + Content.push_back(taskbox); +} + +TaskDlgCosmeticLine::~TaskDlgCosmeticLine() +{ +} + +void TaskDlgCosmeticLine::update() +{ +// widget->updateTask(); +} + +//==== calls from the TaskView =============================================================== +void TaskDlgCosmeticLine::open() +{ +} + +void TaskDlgCosmeticLine::clicked(int) +{ +} + +bool TaskDlgCosmeticLine::accept() +{ + widget->accept(); + return true; +} + +bool TaskDlgCosmeticLine::reject() +{ + widget->reject(); + return true; +} + +#include diff --git a/src/Mod/TechDraw/Gui/TaskCosmeticLine.h b/src/Mod/TechDraw/Gui/TaskCosmeticLine.h new file mode 100644 index 0000000000..387a2f7f9b --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskCosmeticLine.h @@ -0,0 +1,145 @@ +/*************************************************************************** + * Copyright (c) 2020 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_TASKCOSMETICLINE_H +#define TECHDRAWGUI_TASKCOSMETICLINE_H + +#include +#include +#include +#include + +#include + +#include + +class Ui_TaskCosmeticLine; + +namespace App { +class DocumentObject; +} + +namespace TechDraw +{ +class DrawPage; +class DrawView; +class DrawViewPart; +class CosmeticEdge; +class LineFormat; +} + +namespace TechDraw +{ +class Face; +} + +namespace TechDrawGui +{ +class QGVPage; +class QGIView; +class QGIPrimPath; +class MDIViewPage; +class ViewProviderViewPart; + +class TaskCosmeticLine : public QWidget +{ + Q_OBJECT + +public: + TaskCosmeticLine(TechDraw::DrawViewPart* baseFeat, + std::vector points, + std::vector is3d); + TaskCosmeticLine(TechDraw::DrawViewPart* baseFeat, + std::string edgeName); + ~TaskCosmeticLine(); + +public Q_SLOTS: + +public: + virtual bool accept(); + virtual bool reject(); + void updateTask(); + +protected Q_SLOTS: + +protected: + void changeEvent(QEvent *e); + + void setUiPrimary(void); + void setUiEdit(void); + + void createCosmeticLine(void); + void updateCosmeticLine(void); + +private: + Ui_TaskCosmeticLine * ui; + + TechDraw::DrawViewPart* m_partFeat; + + std::string m_edgeName; + int m_edgeIndex; + TechDraw::CosmeticEdge* m_ce; + TechDraw::CosmeticEdge* m_saveCE; + std::vector m_points; + std::vector m_is3d; + bool m_createMode; + std::string m_tag; +}; + +class TaskDlgCosmeticLine : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgCosmeticLine(TechDraw::DrawViewPart* baseFeat, + std::vector points, + std::vector is3d); + TaskDlgCosmeticLine(TechDraw::DrawViewPart* baseFeat, + std::string edgeName); + ~TaskDlgCosmeticLine(); + +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: + TaskCosmeticLine* widget; + + Gui::TaskView::TaskBox* taskbox; +}; + +} //namespace TechDrawGui + +#endif // #ifndef TECHDRAWGUI_TASKCOSMETICLINE_H diff --git a/src/Mod/TechDraw/Gui/TaskCosmeticLine.ui b/src/Mod/TechDraw/Gui/TaskCosmeticLine.ui new file mode 100644 index 0000000000..acdb774441 --- /dev/null +++ b/src/Mod/TechDraw/Gui/TaskCosmeticLine.ui @@ -0,0 +1,228 @@ + + + TechDrawGui::TaskCosmeticLine + + + + 0 + 0 + 350 + 331 + + + + + 0 + 0 + + + + + 250 + 0 + + + + Cosmetic Line + + + + + + + + View + + + + + + + false + + + false + + + Qt::NoFocus + + + false + + + + + + + + + + + 2d Point + + + true + + + false + + + + + + + 3d Point + + + false + + + + + + + + + + + X: + + + + + + + Y: + + + + + + + + + + + + + + Z: + + + + + + + + + + + + + + + + + + + + + + + + + 2d Point + + + true + + + false + + + + + + + 3d Point + + + false + + + + + + + + + + + + + + + + + + X: + + + + + + + Y: + + + + + + + + + + + + + + Z: + + + + + + + + + + + + + + + + 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 a3f2b76b2d..a314a304a7 100644 --- a/src/Mod/TechDraw/Gui/Workbench.cpp +++ b/src/Mod/TechDraw/Gui/Workbench.cpp @@ -69,6 +69,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const lines->setCommand("Add Lines"); *lines << "TechDraw_LeaderLine" << "TechDraw_FaceCenterLine" << "TechDraw_2LineCenterLine" << "TechDraw_2PointCenterLine"; + *lines << "TechDraw_2PointCosmeticLine"; // vertices Gui::MenuItem* vertices = new Gui::MenuItem; @@ -183,6 +184,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const // *anno << "TechDraw_FaceCenterLine"; // *anno << "TechDraw_2LineCenterLine"; // *anno << "TechDraw_2PointCenterLine"; + *anno << "TechDraw_2PointCosmeticLine"; *anno << "TechDraw_CosmeticEraser"; *anno << "TechDraw_DecorateLine"; *anno << "TechDraw_ShowAll"; @@ -256,6 +258,7 @@ Gui::ToolBarItem* Workbench::setupCommandBars() const // *anno << "TechDraw_FaceCenterLine"; // *anno << "TechDraw_2LineCenterLine"; // *anno << "TechDraw_2PointCenterLine"; + *anno << "TechDraw_2PointCosmeticLine"; *anno << "TechDraw_CosmeticEraser"; *anno << "TechDraw_DecorateLine"; *anno << "TechDraw_ShowAll";