Skip to content

Commit

Permalink
More tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwheeler committed Jun 24, 2024
1 parent 4862ca5 commit abfb1a1
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 95 deletions.
11 changes: 10 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
Checks: 'google-*, bugprone-*, cppcoreguidelines-*, modernize-*, performance-*, readability-*'
Checks: >
google-*,
bugprone-*,
cppcoreguidelines-*,
modernize-*,
performance-*,
readability-*,
-readability-identifier-length,
-readability-magic-numbers,
-cppcoreguidelines-avoid-magic-numbers,
141 changes: 76 additions & 65 deletions src/brd_gui/brdview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@

#include "lib/printing/printers.h"
#include "lib/structure/utils.h"

// This is required behavior for Qt.
// NOLINTNEXTLINE(bugprone-suspicious-include)
#include "moc_brdview.cpp"

BrdView::BrdView(MainWindow *parent)
: QGraphicsView((QWidget *)parent), factor(1000) {
: QGraphicsView((QWidget *)parent),
scene(new QGraphicsScene()),
centerX(0),
centerY(0),
factor(1000) {
qDebug() << "BrdView::BrdView";
// This hides some annoying warnings printed to the console
viewport()->setAttribute(Qt::WA_AcceptTouchEvents, false);

scene = new QGraphicsScene();
scene->setBackgroundBrush(QColor(20, 20, 20));

scale(1, -1);

setScene(scene);

centerX = 0;
centerY = 0;
centerOn(centerX, centerY);

// drawFile();

if (parent != nullptr) {
((MainWindow *)parent)->updatePosition(QPointF(0, 0));
parent->updatePosition(QPointF(0, 0));
}
};

Expand All @@ -40,7 +43,7 @@ void BrdView::zoomOut() { scale(1 / 1.2, 1 / 1.2); }

void BrdView::zoomFit() { fitInView(scene->sceneRect(), Qt::KeepAspectRatio); }

bool BrdView::drewKey(const uint32_t ptr) {
auto BrdView::drewKey(const uint32_t ptr) -> bool {
return already_drawn.count(ptr) > 0;
}

Expand All @@ -58,7 +61,7 @@ void BrdView::keyPressEvent(QKeyEvent *event) {

void BrdView::mouseMoveEvent(QMouseEvent *event) {
const QPointF pos = mapToScene(event->pos());
((MainWindow *)parent())->updatePosition(pos * factor);
dynamic_cast<MainWindow *>(parent())->updatePosition(pos * factor);
}

void BrdView::mouseReleaseEvent(QMouseEvent *event) {
Expand All @@ -73,17 +76,18 @@ void BrdView::mouseReleaseEvent(QMouseEvent *event) {
const int ptr = item->data(0).toInt();
if (fs->is_type(ptr, 0x32)) {
// const x32<A_MAX> &inst = fs->get_x32(ptr);
print_struct((const uint32_t)ptr, *fs, 0);
print_struct(static_cast<const uint32_t>(ptr), *fs, 0);
// qDebug("Printing x32->ptr5");
// print_struct((const uint32_t)inst->ptr5, fs, 0);
} else {
print_struct((const uint32_t)ptr, *fs, 0);
print_struct(static_cast<const uint32_t>(ptr), *fs, 0);
}
std::printf("\n\n");
}
};

void BrdView::drawX01(const T01ArcSegment<kAMax> *inst, QPainterPath *path) {
void BrdView::drawX01(const T01ArcSegment<kAMax> *inst,
QPainterPath *path) const {
std::pair<int32_t, int32_t> center = x01_center(inst);
double r = static_cast<double>(inst->r);

Expand Down Expand Up @@ -229,7 +233,8 @@ void BrdView::drawX14(const T14Path<kAMax> *inst, QPen *pen_) {
item->setData(0, inst->k);
}

void BrdView::drawX15(const T15LineSegment<kAMax> *inst, QPainterPath *path) {
void BrdView::drawX15(const T15LineSegment<kAMax> *inst,
QPainterPath *path) const {
path->lineTo(inst->coords[2] / factor, inst->coords[3] / factor);

// QGraphicsItem *item = scene->addLine(
Expand All @@ -240,7 +245,8 @@ void BrdView::drawX15(const T15LineSegment<kAMax> *inst, QPainterPath *path) {
// item->setData(0, inst->k);
};

void BrdView::drawX16(const T16LineSegment<kAMax> *inst, QPainterPath *path) {
void BrdView::drawX16(const T16LineSegment<kAMax> *inst,
QPainterPath *path) const {
path->lineTo(inst->coords[2] / factor, inst->coords[3] / factor);

// QGraphicsItem *item = scene->addLine(
Expand All @@ -251,7 +257,8 @@ void BrdView::drawX16(const T16LineSegment<kAMax> *inst, QPainterPath *path) {
// item->setData(0, inst->k);
};

void BrdView::drawX17(const T17LineSegment<kAMax> *inst, QPainterPath *path) {
void BrdView::drawX17(const T17LineSegment<kAMax> *inst,
QPainterPath *path) const {
path->lineTo(inst->coords[2] / factor, inst->coords[3] / factor);

// QGraphicsItem *item = scene->addLine(
Expand Down Expand Up @@ -331,7 +338,7 @@ void BrdView::drawX28(const T28Shape<kAMax> *inst, QPen *pen) {
}
}

QColor lighterColor = QColor(customPen->color());
QColor lighterColor = customPen->color();
lighterColor.setAlpha(127);

QPen *polyPen;
Expand Down Expand Up @@ -379,7 +386,7 @@ void BrdView::drawX28(const T28Shape<kAMax> *inst, QPen *pen) {
item->setData(0, inst->k);

QPen *pen6 = new QPen(QColor(237, 211, 130, 127), 0);
for (auto &i_x34 : fs->iter_x34(inst->k)) {
for (const auto &i_x34 : fs->iter_x34(inst->k)) {
drawShape(i_x34.k, pen6);
}

Expand All @@ -395,7 +402,7 @@ void BrdView::drawX2B(const T2BSymbol<kAMax> *inst, QPen *pen) {
}

void BrdView::drawX2D(const T2DSymbolInstance<kAMax> *inst, QPen *pen) {
for (auto &inst_x14 : fs->iter_x14(*inst)) {
for (const auto &inst_x14 : fs->iter_x14(*inst)) {
drawShape(inst_x14.k, pen);
}

Expand Down Expand Up @@ -426,11 +433,11 @@ void BrdView::drawX2D(const T2DSymbolInstance<kAMax> *inst, QPen *pen) {

// drawShape(inst->ptr4[2], pen);

for (auto &i_x30 : fs->iter_x30(inst->k)) {
for (const auto &i_x30 : fs->iter_x30(inst->k)) {
drawX30(&i_x30, pen);
}

for (auto &i_x32 : fs->iter_x32(inst->k)) {
for (const auto &i_x32 : fs->iter_x32(inst->k)) {
drawX32(&i_x32, pen, inst->rotation);
}
}
Expand Down Expand Up @@ -542,7 +549,7 @@ void BrdView::drawX32(const T32SymbolPin<kAMax> *inst, QPen *pen,
x0D_inst.rotation + sym_rotation, *pen);

// Just draw the first part
const t13<kAMax> *first_part = &x1C_inst.parts[0];
const t13<kAMax> *first_part = x1C_inst.parts.data();
QGraphicsItem *pad;
QTransform t = QTransform()
.translate(center.x(), center.y())
Expand Down Expand Up @@ -633,7 +640,7 @@ void BrdView::drawX33(const x33<kAMax> *inst, QPen *pen) {

// drawShape(inst->ptr10, pen2);

first_part = &x1C_inst.parts[0];
first_part = x1C_inst.parts.data();
switch (first_part->t) {
case 2:
case 6:
Expand Down Expand Up @@ -690,11 +697,11 @@ void BrdView::drawShape(const uint32_t ptr, QPen *pen) {
if (already_drawn.count(ptr) > 0) {
// std::printf("Already drawn 0x%08X\n", ntohl(ptr));
return;
} else {
// std::printf("Drawing 0x%08X\n", ntohl(ptr));
already_drawn.insert(ptr);
}

// std::printf("Drawing 0x%08X\n", ntohl(ptr));
already_drawn.insert(ptr);

// QPen *darkerPen = new QPen(pen->color().lighter(101), 0.3);
QPen *darkerPen = pen;

Expand Down Expand Up @@ -794,10 +801,10 @@ void BrdView::drawFile() {
QPen *pen5 = new QPen(QColor(132, 169, 140, 127), 0);
QPen *pen6 = new QPen(QColor(237, 211, 130, 127), 0);

for (auto &i_x1B : fs->iter_t1B_net()) {
for (auto &i_x04 : fs->iter_x04(i_x1B.k)) {
for (const auto &i_x1B : fs->iter_t1B_net()) {
for (const auto &i_x04 : fs->iter_x04(i_x1B.k)) {
uint32_t k = i_x04.ptr2;
while (1) {
while (true) {
if (fs->is_type(k, 0x33)) {
auto &i = fs->get_x33(k);
// printf("- - Found x33 w/ key = 0x %08X\n", ntohl(k));
Expand Down Expand Up @@ -834,10 +841,10 @@ void BrdView::drawFile() {
}
}

for (auto &inst : fs->iter_x0C()) {
for (const auto &inst : fs->iter_x0C()) {
drawShape(inst.k, pen5);
}
for (auto &inst : fs->iter_x0C_2()) {
for (const auto &inst : fs->iter_x0C_2()) {
drawShape(inst.k, pen6);
}

Expand Down Expand Up @@ -876,8 +883,8 @@ void BrdView::drawFile() {
// drawShape(k, pen4);
// }

for (auto &x2B_inst : fs->iter_x2B()) {
for (auto &x2D_inst : fs->iter_x2D(x2B_inst.k)) {
for (const auto &x2B_inst : fs->iter_x2B()) {
for (const auto &x2D_inst : fs->iter_x2D(x2B_inst.k)) {
drawShape(x2D_inst.k, pen4);
}
}
Expand All @@ -903,7 +910,7 @@ void BrdView::drawFile() {
}
*/

for (auto &i_x03_x30 : fs->iter_x30()) {
for (const auto &i_x03_x30 : fs->iter_x30()) {
if (fs->is_type(i_x03_x30.k, 0x30)) {
drawShape(i_x03_x30.k, pen2);
}
Expand Down Expand Up @@ -969,41 +976,40 @@ void BrdView::drawFile() {
// }
};

QColor BrdView::customPenColor(uint32_t x05_k, QColor default_) {
auto BrdView::customPenColor(uint32_t x05_k, QColor default_) -> QColor {
if (fs->is_type(x05_k, 0x05)) {
const T05Line<kAMax> inst = fs->get_x05(x05_k);
if (onSelectedLayer(inst.subtype, inst.layer)) {
return QColorConstants::Svg::palevioletred;
} else {
return QColorConstants::Svg::darkseagreen;
}
} else if (fs->is_type(x05_k, 0x14)) {
return QColorConstants::Svg::darkseagreen;
}
if (fs->is_type(x05_k, 0x14)) {
return QColorConstants::Svg::goldenrod;
} else if (fs->is_type(x05_k, 0x28)) {
}
if (fs->is_type(x05_k, 0x28)) {
const T28Shape<kAMax> &inst = fs->get_x28(x05_k);
if (onSelectedLayer(inst.subtype, inst.layer)) {
return QColorConstants::Svg::palevioletred;
} else {
return default_;
// return QColorConstants::Svg::crimson;
}
} else if (fs->is_type(x05_k, 0x34)) {
return default_;
// return QColorConstants::Svg::crimson;
}
if (fs->is_type(x05_k, 0x34)) {
const x34<kAMax> &inst = fs->get_x34(x05_k);
if (onSelectedLayer(inst.subtype, inst.layer)) {
return QColorConstants::Svg::palevioletred;
} else {
return QColorConstants::Svg::blanchedalmond;
}
} else if (fs->is_type(x05_k, 0x30)) {
return QColorConstants::Svg::blanchedalmond;
}
if (fs->is_type(x05_k, 0x30)) {
const T30StringGraphic<kAMax> &inst = fs->get_x30(x05_k);
if (onSelectedLayer(inst.subtype, inst.layer)) {
return QColorConstants::Svg::lightsalmon;
} else {
return QColorConstants::Svg::darkviolet;
}
} else {
return QColorConstants::Svg::lightsteelblue;
return QColorConstants::Svg::darkviolet;
}
return QColorConstants::Svg::lightsteelblue;

/*
if (fs.x05_map->count(x05_k) > 0) {
Expand Down Expand Up @@ -1056,7 +1062,8 @@ QColor BrdView::customPenColor(uint32_t x05_k, QColor default_) {
*/
}

void BrdView::selectLayer(std::set<std::pair<uint16_t, uint16_t>> layers) {
void BrdView::selectLayer(
const std::set<std::pair<uint16_t, uint16_t>> &layers) {
selectedLayers = layers;
drawFile();

Expand Down Expand Up @@ -1103,36 +1110,40 @@ std::optional<QPointF> BrdView::startingPoint(uint32_t k) {
if (fs->is_type(k, 0x01)) {
const T01ArcSegment<kAMax> segment_inst = fs->get_x01(k);
return QPointF(segment_inst.coords[0], segment_inst.coords[1]);
} else if (fs->is_type(k, 0x15)) {
}
if (fs->is_type(k, 0x15)) {
const T15LineSegment<kAMax> segment_inst = fs->get_x15(k);
return QPointF(segment_inst.coords[0], segment_inst.coords[1]);
} else if (fs->is_type(k, 0x16)) {
}
if (fs->is_type(k, 0x16)) {
const T16LineSegment<kAMax> segment_inst = fs->get_x16(k);
return QPointF(segment_inst.coords[0], segment_inst.coords[1]);
} else if (fs->is_type(k, 0x17)) {
}
if (fs->is_type(k, 0x17)) {
const T17LineSegment<kAMax> segment_inst = fs->get_x17(k);
return QPointF(segment_inst.coords[0], segment_inst.coords[1]);
} else {
return std::optional<QPointF>();
}
return {};
}

std::optional<QPointF> BrdView::endingPoint(uint32_t k) {
if (fs->is_type(k, 0x01)) {
const T01ArcSegment<kAMax> segment_inst = fs->get_x01(k);
return QPointF(segment_inst.coords[2], segment_inst.coords[3]);
} else if (fs->is_type(k, 0x15)) {
}
if (fs->is_type(k, 0x15)) {
const T15LineSegment<kAMax> segment_inst = fs->get_x15(k);
return QPointF(segment_inst.coords[2], segment_inst.coords[3]);
} else if (fs->is_type(k, 0x16)) {
}
if (fs->is_type(k, 0x16)) {
const T16LineSegment<kAMax> segment_inst = fs->get_x16(k);
return QPointF(segment_inst.coords[2], segment_inst.coords[3]);
} else if (fs->is_type(k, 0x17)) {
}
if (fs->is_type(k, 0x17)) {
const T17LineSegment<kAMax> segment_inst = fs->get_x17(k);
return QPointF(segment_inst.coords[2], segment_inst.coords[3]);
} else {
return std::optional<QPointF>();
}
return {};
}

char *BrdView::netName(uint32_t k) {
Expand Down Expand Up @@ -1166,14 +1177,14 @@ void BrdView::drawDrillSymbol(uint32_t k, const DrillSymbol symbol,
symbol.shape == HexagonPointyTop) {
QPolygonF polygon;
// Adjust height to form actual hexagon
h = std::sqrt(3) / 2. * h;
polygon << QPointF(-1. * w / 4., h / 2.) / factor;
double adjusted_h = std::sqrt(3) / 2. * h;
polygon << QPointF(-1. * w / 4., adjusted_h / 2.) / factor;
polygon << QPointF(-1. * w / 2., 0) / factor;
polygon << QPointF(-1. * w / 4., -1. * h / 2.) / factor;
polygon << QPointF(w / 4., -1. * h / 2.) / factor;
polygon << QPointF(-1. * w / 4., -1. * adjusted_h / 2.) / factor;
polygon << QPointF(w / 4., -1. * adjusted_h / 2.) / factor;
polygon << QPointF(w / 2., 0.) / factor;
polygon << QPointF(w / 4., h / 2.) / factor;
polygon << QPointF(-1. * w / 4., h / 2.) / factor;
polygon << QPointF(w / 4., adjusted_h / 2.) / factor;
polygon << QPointF(-1. * w / 4., adjusted_h / 2.) / factor;
if (symbol.shape == HexagonPointyTop) {
t = t.rotate(30.);
}
Expand Down
Loading

0 comments on commit abfb1a1

Please sign in to comment.