diff --git a/src/main/java/ru/futurelink/gerber/panelizer/gui/ColorSettings.java b/src/main/java/ru/futurelink/gerber/panelizer/gui/ColorSettings.java new file mode 100644 index 0000000..ee3bcb3 --- /dev/null +++ b/src/main/java/ru/futurelink/gerber/panelizer/gui/ColorSettings.java @@ -0,0 +1,36 @@ +package ru.futurelink.gerber.panelizer.gui; + +import io.qt.gui.QColor; +import io.qt.gui.QPen; +import lombok.Getter; + +public class ColorSettings { + @Getter + private final QPen axisPen; + @Getter private final QPen drillPen; + @Getter private final QPen outlinePen; + @Getter private final QPen selectedPen; + @Getter private final QPen validFeaturePen; + @Getter private final QPen invalidFeaturePen; + @Getter private final QPen marksPen; + + private static ColorSettings instance = null; + + public static ColorSettings getInstance() { + if (instance == null) { + instance = new ColorSettings(); + } + return instance; + } + + private ColorSettings() { + axisPen = new QPen(new QColor(200, 200, 200), 1); + drillPen = new QPen(new QColor(180, 180, 180), 1); + outlinePen = new QPen(new QColor(0, 0, 0, 255), 1); + selectedPen = new QPen(new QColor(0, 0, 200), 2); + validFeaturePen = new QPen(new QColor(0, 200, 0), 1); + invalidFeaturePen = new QPen(new QColor(200, 0, 0), 1); + marksPen = new QPen(new QColor(200, 0, 200), 1); + } +} + diff --git a/src/main/java/ru/futurelink/gerber/panelizer/gui/GerberPainter.java b/src/main/java/ru/futurelink/gerber/panelizer/gui/GerberPainter.java index 5c4bd32..c8739ab 100644 --- a/src/main/java/ru/futurelink/gerber/panelizer/gui/GerberPainter.java +++ b/src/main/java/ru/futurelink/gerber/panelizer/gui/GerberPainter.java @@ -21,37 +21,17 @@ public class GerberPainter extends QPainter { @Getter private final double scale; @Getter private final QPointF center; - private final Settings settings; + private final ColorSettings colorSettings = ColorSettings.getInstance(); private final static double arcQ = 2880 / Math.PI; - static class Settings { - QPen axisPen; - QPen drillPen; - QPen outlinePen; - QPen selectedPen; - QPen validFeaturePen; - QPen invalidFeaturePen; - QPen marksPen; - Settings() { - axisPen = new QPen(new QColor(200, 200, 200), 1); - drillPen = new QPen(new QColor(180, 180, 180), 1); - outlinePen = new QPen(new QColor(0, 0, 0, 255), 1); - selectedPen = new QPen(new QColor(0, 0, 200), 2); - validFeaturePen = new QPen(new QColor(0, 200, 0), 1); - invalidFeaturePen = new QPen(new QColor(200, 0, 0), 1); - marksPen = new QPen(new QColor(200, 0, 200), 1); - } - } - - public GerberPainter(QWidget parent, Settings settings, double scale, QPointF center) { + public GerberPainter(QWidget parent, double scale, QPointF center) { super(parent); this.scale = scale; this.center = center; - this.settings = settings; } - void drawAxis(QPointF center, int width, int height) { - setPen(settings.axisPen); + public void drawAxis(QPointF center, int width, int height) { + setPen(colorSettings.getAxisPen()); drawLine( (int) Math.round(center.x() / scale), 0, (int) Math.round(center.x() / scale), height); @@ -60,8 +40,8 @@ void drawAxis(QPointF center, int width, int height) { width, (int) Math.round(center.y() / scale)); } - void drawBoundingBoxMarks(QRectF box) { - setPen(settings.marksPen); + public void drawBoundingBoxMarks(QRectF box) { + setPen(colorSettings.getMarksPen()); // Bounding box var topLeft = translatedPoint(box.topLeft(), null); @@ -78,7 +58,7 @@ void drawBoundingBoxMarks(QRectF box) { drawLine((int) cx - 10, (int) bottomRight.y(), (int) cx + 10, (int) bottomRight.y()); } - void drawHoles(QPainter painter, Layer layer, QPointF offset) { + public void drawHoles(QPainter painter, Layer layer, QPointF offset) { if (layer instanceof Excellon e) { var hi = e.holes(); while (hi.hasNext()) { @@ -90,13 +70,13 @@ void drawHoles(QPainter painter, Layer layer, QPointF offset) { ); var dia = h.getDiameter() / scale / 2; - painter.setPen(settings.drillPen); + painter.setPen(colorSettings.getDrillPen()); painter.drawEllipse(c, dia, dia); } } } - void drawBatchOutline(QPainter painter, BatchMerger.BatchInstance b, boolean selected) { + public void drawBatchOutline(QPainter painter, BatchMerger.BatchInstance b, boolean selected) { var rect = new QRectF( Math.round((b.getTopLeft().getX().doubleValue() + center.x()) / scale), -Math.round((b.getTopLeft().getY().doubleValue() - center.y()) / scale), @@ -106,7 +86,7 @@ void drawBatchOutline(QPainter painter, BatchMerger.BatchInstance b, boolean sel // Board batch title // ----------------- - painter.setPen(selected ? settings.selectedPen : settings.outlinePen); + painter.setPen(selected ? colorSettings.getSelectedPen() : colorSettings.getOutlinePen()); painter.drawText( new QPointF( rect.x() + rect.width() / 2 - (float) textRect.width() / 2, @@ -124,12 +104,12 @@ void drawBatchOutline(QPainter painter, BatchMerger.BatchInstance b, boolean sel // ------------- var outlineLayer = b.getBatch().getLayer(Layer.Type.EdgeCuts); if (outlineLayer instanceof Gerber g) { - painter.setPen(selected ? settings.selectedPen : new QPen(new QColor(0, 0, 0, 0), 1)); + painter.setPen(selected ? colorSettings.getSelectedPen() : new QPen(new QColor(0, 0, 0, 0), 1)); drawGerber(g, new QPointF(b.getOffset().getX().doubleValue(), b.getOffset().getY().doubleValue())); } } - void drawGerber(Gerber g, QPointF offset) { + public void drawGerber(Gerber g, QPointF offset) { var currentInterpolation = Geometry.Interpolation.LINEAR; var currentPoint = new QPointF(0, 0); for (var cmd : g.getContents()) { @@ -172,14 +152,14 @@ void drawGerber(Gerber g, QPointF offset) { } } - void drawFeature(QPainter painter, Feature f, boolean selected) { + public void drawFeature(QPainter painter, Feature f, boolean selected) { if (f instanceof RoundFeature m) { var dia = (int) Math.round(m.getRadius() / scale); var c = translatedPoint(m.getCenter().getX().doubleValue(), m.getCenter().getY().doubleValue()); painter.setPen(selected ? - settings.selectedPen : - m.isValid() ? settings.validFeaturePen : settings.invalidFeaturePen + colorSettings.getSelectedPen() : + m.isValid() ? colorSettings.getValidFeaturePen() : colorSettings.getInvalidFeaturePen() ); // Draw feature sign diff --git a/src/main/java/ru/futurelink/gerber/panelizer/gui/MainWindow.java b/src/main/java/ru/futurelink/gerber/panelizer/gui/MainWindow.java index 6a869de..03244d3 100644 --- a/src/main/java/ru/futurelink/gerber/panelizer/gui/MainWindow.java +++ b/src/main/java/ru/futurelink/gerber/panelizer/gui/MainWindow.java @@ -9,11 +9,14 @@ import lombok.Getter; import ru.futurelink.gerber.panelizer.batch.BatchMerger; import ru.futurelink.gerber.panelizer.batch.BatchSettings; +import ru.futurelink.gerber.panelizer.gui.widgets.ExportSettingsDialog; +import ru.futurelink.gerber.panelizer.gui.widgets.MergerPanelWidget; +import ru.futurelink.gerber.panelizer.gui.widgets.ProjectManagerWidget; public class MainWindow extends QMainWindow { private final static String appName = "Gerber Panelizer"; @Getter private final QMenuBar menuBar; - @Getter private final MergerPanel workArea; + @Getter private final MergerPanelWidget workArea; private final QLabel statusCoords; private final QLabel statusSize; @@ -27,7 +30,7 @@ public MainWindow() { batchSettings = BatchSettings.getInstance(); - workArea = new MergerPanel(this, new BatchMerger("merged")); + workArea = new MergerPanelWidget(this, new BatchMerger("merged")); setCentralWidget(workArea); statusBar = new QStatusBar(this); diff --git a/src/main/java/ru/futurelink/gerber/panelizer/gui/MergerProject.java b/src/main/java/ru/futurelink/gerber/panelizer/gui/MergerProject.java index 9860283..a6a15f5 100644 --- a/src/main/java/ru/futurelink/gerber/panelizer/gui/MergerProject.java +++ b/src/main/java/ru/futurelink/gerber/panelizer/gui/MergerProject.java @@ -26,7 +26,7 @@ public class MergerProject extends QObject { @Getter private final HashMap batchPlacements; @Getter private final HashMap featurePlacements; - static class BatchPlacement { + public static class BatchPlacement { @Getter UUID batchUUID; @Getter double x; @Getter double y; @@ -37,13 +37,13 @@ public BatchPlacement(UUID batchUUID, double x, double y) { this.y = y; } - void move(double x, double y) { + public void move(double x, double y) { this.x = x; this.y = y; } } - static class FeaturePlacement { + public static class FeaturePlacement { @Getter Class featureClass; @Getter double x; @Getter double y; @@ -53,7 +53,7 @@ public FeaturePlacement(Class cls, double x, double y) { this.y = y; } - void move(double x, double y) { + public void move(double x, double y) { this.x = x; this.y = y; } diff --git a/src/main/java/ru/futurelink/gerber/panelizer/gui/ExportSettingsDialog.java b/src/main/java/ru/futurelink/gerber/panelizer/gui/widgets/ExportSettingsDialog.java similarity index 97% rename from src/main/java/ru/futurelink/gerber/panelizer/gui/ExportSettingsDialog.java rename to src/main/java/ru/futurelink/gerber/panelizer/gui/widgets/ExportSettingsDialog.java index d629c25..ea144cc 100644 --- a/src/main/java/ru/futurelink/gerber/panelizer/gui/ExportSettingsDialog.java +++ b/src/main/java/ru/futurelink/gerber/panelizer/gui/widgets/ExportSettingsDialog.java @@ -1,10 +1,9 @@ -package ru.futurelink.gerber.panelizer.gui; +package ru.futurelink.gerber.panelizer.gui.widgets; import io.qt.core.Qt; import io.qt.gui.QBrush; import io.qt.gui.QColor; import io.qt.widgets.*; -import lombok.Getter; import ru.futurelink.gerber.panelizer.Layer; import ru.futurelink.gerber.panelizer.batch.BatchSettings; diff --git a/src/main/java/ru/futurelink/gerber/panelizer/gui/MergerPanel.java b/src/main/java/ru/futurelink/gerber/panelizer/gui/widgets/MergerPanelWidget.java similarity index 96% rename from src/main/java/ru/futurelink/gerber/panelizer/gui/MergerPanel.java rename to src/main/java/ru/futurelink/gerber/panelizer/gui/widgets/MergerPanelWidget.java index 370cea3..3a35c2b 100644 --- a/src/main/java/ru/futurelink/gerber/panelizer/gui/MergerPanel.java +++ b/src/main/java/ru/futurelink/gerber/panelizer/gui/widgets/MergerPanelWidget.java @@ -1,4 +1,4 @@ -package ru.futurelink.gerber.panelizer.gui; +package ru.futurelink.gerber.panelizer.gui.widgets; import io.qt.core.*; import io.qt.gui.*; @@ -13,10 +13,13 @@ import ru.futurelink.gerber.panelizer.canvas.fetaures.MouseBites; import ru.futurelink.gerber.panelizer.exceptions.MergerException; import ru.futurelink.gerber.panelizer.gbr.Gerber; +import ru.futurelink.gerber.panelizer.gui.ColorSettings; +import ru.futurelink.gerber.panelizer.gui.GerberPainter; +import ru.futurelink.gerber.panelizer.gui.Utils; import java.util.UUID; -public class MergerPanel extends QWidget { +public class MergerPanelWidget extends QWidget { @Getter private final BatchMerger merger; private double scale; @@ -26,7 +29,6 @@ public class MergerPanel extends QWidget { private QPoint mousePressPoint; private Object instanceUnderMouse; private Object instanceSelected; - private final GerberPainter.Settings painterSettings; public final Signal1 mouseMoved = new Signal1<>(); public final Signal1 deleteItem = new Signal1<>(); public final Signal1 moveItem = new Signal1<>(); @@ -37,14 +39,13 @@ public class MergerPanel extends QWidget { private final QAction addFeatureAction; private final QAction deleteAction; - public MergerPanel(QWidget parent, BatchMerger m) { + public MergerPanelWidget(QWidget parent, BatchMerger m) { super(parent); merger = m; scale = 0.25; margin = 0; center = new QPointF(10, 10); mousePressPoint = null; - painterSettings = new GerberPainter.Settings(); addFeatureAction = new QAction("Add MouseBites feature"); addFeatureAction.triggered.connect(this, "addMouseBites(boolean)"); @@ -273,7 +274,7 @@ protected void wheelEvent(QWheelEvent event) { @Override protected void paintEvent(QPaintEvent event) { - var painter = new GerberPainter(this, painterSettings, scale, center); + var painter = new GerberPainter(this, scale, center); painter.setBackground(new QBrush(new QColor(40, 40, 40))); painter.setRenderHint(QPainter.RenderHint.Antialiasing); @@ -338,7 +339,7 @@ private boolean isInCircle(QPointF p, Point center, double radius) { Math.pow(p.y() - center.getY().doubleValue(), 2) < radius * radius); } - void mergeDisplayLayers() { + public void mergeDisplayLayers() { try { merger.mergeLayer(Layer.Type.EdgeCuts); merger.mergeLayer(Layer.Type.FrontMask); diff --git a/src/main/java/ru/futurelink/gerber/panelizer/gui/ProjectManagerWidget.java b/src/main/java/ru/futurelink/gerber/panelizer/gui/widgets/ProjectManagerWidget.java similarity index 96% rename from src/main/java/ru/futurelink/gerber/panelizer/gui/ProjectManagerWidget.java rename to src/main/java/ru/futurelink/gerber/panelizer/gui/widgets/ProjectManagerWidget.java index 7e153bd..d0607f7 100644 --- a/src/main/java/ru/futurelink/gerber/panelizer/gui/ProjectManagerWidget.java +++ b/src/main/java/ru/futurelink/gerber/panelizer/gui/widgets/ProjectManagerWidget.java @@ -1,4 +1,4 @@ -package ru.futurelink.gerber.panelizer.gui; +package ru.futurelink.gerber.panelizer.gui.widgets; import io.qt.core.QFileInfo; import io.qt.core.QStringList; @@ -12,6 +12,7 @@ import ru.futurelink.gerber.panelizer.canvas.fetaures.RoundFeature; import ru.futurelink.gerber.panelizer.exceptions.GerberException; import ru.futurelink.gerber.panelizer.exceptions.MergerException; +import ru.futurelink.gerber.panelizer.gui.MergerProject; import java.io.File; import java.io.IOException; @@ -21,13 +22,14 @@ public class ProjectManagerWidget extends QDockWidget { private final QTreeWidget projectTree; @Getter private MergerProject project; - @Getter MergerPanel workArea; + @Getter + MergerPanelWidget workArea; @Getter private boolean modified; @Getter private String filename; public final Signal1 projectNameChanged = new Signal1<>(); - public ProjectManagerWidget(QWidget parent, MergerPanel workArea) { + public ProjectManagerWidget(QWidget parent, MergerPanelWidget workArea) { super(parent); setFeatures(DockWidgetFeature.NoDockWidgetFeatures); setWindowTitle("Project structure"); @@ -158,7 +160,7 @@ private void moveItem(Object obj) { refresh(); } - final void newProject() { + public final void newProject() { filename = null; project = new MergerProject(this); setProject(project); @@ -166,7 +168,7 @@ final void newProject() { projectNameChanged.emit(getProjectName()); } - final void openProject() { + public final void openProject() { try { var dlg = new QFileDialog(this); dlg.setWindowTitle("Open project"); @@ -210,7 +212,7 @@ final void openProject() { } } - final void saveProject() { + public final void saveProject() { var settings = BatchSettings.getInstance(); try { if (filename != null) { @@ -233,7 +235,7 @@ final void saveProject() { } } - final void saveProjectAs() { + public final void saveProjectAs() { var settings = BatchSettings.getInstance(); var dlg = new QFileDialog(this); dlg.setWindowTitle("Save project as..."); @@ -252,7 +254,7 @@ final void saveProjectAs() { } } - final void addBatch() { + public final void addBatch() { try { var dlg = new QFileDialog(this); dlg.setWindowTitle("Add batch ZIP..."); @@ -268,7 +270,7 @@ final void addBatch() { } } - void export() { + public void export() { var settings = BatchSettings.getInstance(); var dlg = new QFileDialog(this); dlg.setWindowTitle("Export merged batch ZIP...");