Skip to content

Commit

Permalink
[TechDraw] - Line Decoration Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pavltom authored and WandererFan committed Oct 26, 2023
1 parent 5c602bb commit ded89f5
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 78 deletions.
16 changes: 16 additions & 0 deletions src/Mod/TechDraw/Gui/QGIEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
#include <App/Material.h>
#include <Base/Console.h>
#include <Base/Parameter.h>
#include <Gui/Control.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/DrawViewPart.h>

#include "QGIEdge.h"
#include "QGIViewPart.h"
#include "PreferencesGui.h"
#include "TaskLineDecor.h"


using namespace TechDrawGui;
Expand Down Expand Up @@ -114,3 +119,14 @@ QPainterPath QGIEdge::shape() const
outline = stroker.createStroke(path());
return outline;
}

void QGIEdge::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)

Check warning on line 123 in src/Mod/TechDraw/Gui/QGIEdge.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

unused parameter 'event' [-Wunused-parameter]

Check warning on line 123 in src/Mod/TechDraw/Gui/QGIEdge.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

unused parameter 'event' [clang-diagnostic-unused-parameter]
{
QGIView *parent = dynamic_cast<QGIView *>(parentItem());

Check warning on line 125 in src/Mod/TechDraw/Gui/QGIEdge.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]
if (parent && parent->getViewObject() && parent->getViewObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
TechDraw::DrawViewPart *baseFeat = static_cast<TechDraw::DrawViewPart *>(parent->getViewObject());

Check warning on line 127 in src/Mod/TechDraw/Gui/QGIEdge.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto]

Check warning on line 127 in src/Mod/TechDraw/Gui/QGIEdge.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not use static_cast to downcast from a base to a derived class; use dynamic_cast instead [cppcoreguidelines-pro-type-static-cast-downcast]
std::vector<std::string> edgeName(1, DrawUtil::makeGeomName("Edge", getProjIndex()));

Gui::Control().showDialog(new TaskDlgLineDecor(baseFeat, edgeName));

Check warning on line 130 in src/Mod/TechDraw/Gui/QGIEdge.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

initializing non-owner argument of type 'Gui::TaskView::TaskDialog *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]
}
}
3 changes: 3 additions & 0 deletions src/Mod/TechDraw/Gui/QGIEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class TechDrawGuiExport QGIEdge : public QGIPrimPath
double getEdgeFuzz(void) const;

protected:

void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;

int projIndex; //index of edge in Projection. must exist.

bool isCosmetic;
Expand Down
166 changes: 89 additions & 77 deletions src/Mod/TechDraw/Gui/TaskLineDecor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include <Mod/TechDraw/App/CenterLine.h>
#include <Mod/TechDraw/App/Cosmetic.h>
#include <Mod/TechDraw/App/Geometry.h>

#include "TaskLineDecor.h"
Expand All @@ -56,15 +55,16 @@ TaskLineDecor::TaskLineDecor(TechDraw::DrawViewPart* partFeat,
m_edges(edgeNames),
m_apply(true)
{
initializeRejectArrays();

getDefaults();
ui->setupUi(this);
initUi();

connect(ui->cb_Style, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskLineDecor::onStyleChanged);
connect(ui->cc_Color, &ColorButton::changed, this, &TaskLineDecor::onColorChanged);
connect(ui->dsb_Weight, qOverload<double>(&QuantitySpinBox::valueChanged), this, &TaskLineDecor::onWeightChanged);
connect(ui->cb_Visible, qOverload<int>(&QComboBox::currentIndexChanged), this, &TaskLineDecor::onVisibleChanged);

initUi();
}

TaskLineDecor::~TaskLineDecor()
Expand Down Expand Up @@ -94,6 +94,65 @@ void TaskLineDecor::initUi()
ui->cb_Visible->setCurrentIndex(m_visible);
}

TechDraw::LineFormat *TaskLineDecor::getFormatAccessPtr(const std::string &edgeName, std::string *newFormatTag)
{
BaseGeomPtr bg = m_partFeat->getEdge(edgeName);
if (bg) {
if (bg->getCosmetic()) {
if (bg->source() == SourceType::COSEDGE) {
TechDraw::CosmeticEdge *ce = m_partFeat->getCosmeticEdgeBySelection(edgeName);
if (ce) {
return &ce->m_format;
}
}
else if (bg->source() == SourceType::CENTERLINE) {
TechDraw::CenterLine *cl = m_partFeat->getCenterLineBySelection(edgeName);
if (cl) {
return &cl->m_format;
}
}
}
else {
TechDraw::GeomFormat *gf = m_partFeat->getGeomFormatBySelection(edgeName);
if (gf) {
return &gf->m_format;
}
else {
ViewProviderViewPart *viewPart = dynamic_cast<ViewProviderViewPart *>(QGIView::getViewProvider(m_partFeat));
if (viewPart) {
TechDraw::LineFormat lineFormat(Qt::SolidLine, viewPart->LineWidth.getValue(), LineFormat::getDefEdgeColor(), true);
TechDraw::GeomFormat geomFormat(DrawUtil::getIndexFromName(edgeName), lineFormat);

std::string formatTag = m_partFeat->addGeomFormat(&geomFormat);
if (newFormatTag) {
*newFormatTag = formatTag;
}

return &m_partFeat->getGeomFormat(formatTag)->m_format;
}
}
}
}
}

void TaskLineDecor::initializeRejectArrays()
{
m_originalFormats.resize(m_edges.size());
m_createdFormatTags.resize(m_edges.size());

for (size_t i = 0; i < m_edges.size(); ++i) {
std::string newTag;
TechDraw::LineFormat *accessPtr = getFormatAccessPtr(m_edges[i], &newTag);

if (accessPtr) {
m_originalFormats[i] = *accessPtr;
if (!newTag.empty()) {
m_createdFormatTags[i] = newTag;
}
}
}
}

void TaskLineDecor::getDefaults()
{
// Base::Console().Message("TLD::getDefaults()\n");
Expand All @@ -103,44 +162,12 @@ void TaskLineDecor::getDefaults()
m_visible = true;

//set defaults to format of 1st edge
if (!m_edges.empty()) {
int num = DrawUtil::getIndexFromName(m_edges.front());
BaseGeomPtr bg = m_partFeat->getGeomByIndex(num);
if (bg) {
if (bg->getCosmetic()) {
if (bg->source() == 1) {
TechDraw::CosmeticEdge* ce = m_partFeat->getCosmeticEdgeBySelection(m_edges.front());
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->getCenterLine(bg->getCosmeticTag);
TechDraw::CenterLine* cl = m_partFeat->getCenterLineBySelection(m_edges.front());
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->getGeomFormatBySelection(num);
if (gf) {
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;
} else {
Gui::ViewProvider* vp = QGIView::getViewProvider(m_partFeat);
auto partVP = dynamic_cast<ViewProviderViewPart*>(vp);
if (partVP) {
m_weight = partVP->LineWidth.getValue();
m_style = Qt::SolidLine; // = 1
m_color = LineFormat::getDefEdgeColor();
m_visible = true;
}
}
}
}
if (!m_originalFormats.empty()) {
LineFormat &lf = m_originalFormats.front();
m_style = lf.m_style;
m_color = lf.m_color;
m_weight = lf.m_weight;
m_visible = lf.m_visible;
}
}

Expand Down Expand Up @@ -176,42 +203,12 @@ void TaskLineDecor::applyDecorations()
{
// Base::Console().Message("TLD::applyDecorations()\n");
for (auto& e: m_edges) {

Check warning on line 205 in src/Mod/TechDraw/Gui/TaskLineDecor.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing space around colon in range-based for loop [whitespace/forcolon] [2]
int num = DrawUtil::getIndexFromName(e);
BaseGeomPtr bg = m_partFeat->getGeomByIndex(num);
if (bg) {
if (bg->getCosmetic()) {
if (bg->source() == 1) {
TechDraw::CosmeticEdge* ce = m_partFeat->getCosmeticEdgeBySelection(e);
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->getCenterLine(bg->getCosmeticTag());
TechDraw::CenterLine* cl = m_partFeat->getCenterLineBySelection(e);
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->getGeomFormatBySelection(num);
if (gf) {
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);
}
}
LineFormat *lf = getFormatAccessPtr(e);
if (lf) {
lf->m_style = m_style;
lf->m_color = m_color;
lf->m_weight = m_weight;
lf->m_visible = m_visible;
}
}
}
Expand Down Expand Up @@ -242,6 +239,21 @@ bool TaskLineDecor::reject()
if (!doc)
return false;

for (size_t i = 0; i < m_originalFormats.size(); ++i) {
std::string &formatTag = m_createdFormatTags[i];
if (formatTag.empty()) {
LineFormat *lf = getFormatAccessPtr(m_edges[i]);
if (lf) {
*lf = m_originalFormats[i];
}
}
else {
m_partFeat->removeGeomFormat(formatTag);
}
}

m_partFeat->requestPaint();

Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
return false;
}
Expand Down
10 changes: 9 additions & 1 deletion src/Mod/TechDraw/Gui/TaskLineDecor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <Gui/TaskView/TaskDialog.h>
#include <Gui/TaskView/TaskView.h>
#include <Mod/TechDraw/TechDrawGlobal.h>

#include <Mod/TechDraw/App/Cosmetic.h>

namespace App
{
Expand Down Expand Up @@ -62,13 +62,21 @@ protected Q_SLOTS:
protected:
void changeEvent(QEvent *e) override;
void initUi();

TechDraw::LineFormat *getFormatAccessPtr(const std::string &edgeName, std::string *newFormatTag = nullptr);
void initializeRejectArrays();

void applyDecorations();
void getDefaults();

private:
std::unique_ptr<Ui_TaskLineDecor> ui;
TechDraw::DrawViewPart* m_partFeat;
std::vector<std::string> m_edges;

std::vector<TechDraw::LineFormat> m_originalFormats;
std::vector<std::string> m_createdFormatTags;

int m_style;
App::Color m_color;
double m_weight;
Expand Down

0 comments on commit ded89f5

Please sign in to comment.