Skip to content

Commit

Permalink
overhaul of ground plane generation and gerber export
Browse files Browse the repository at this point in the history
 - use clipper for all boolean operations
 - avoid ragged edges on polygons
  • Loading branch information
nraynaud authored and Kazade committed Mar 22, 2016
1 parent 48c2898 commit 844ff96
Show file tree
Hide file tree
Showing 16 changed files with 6,252 additions and 2,940 deletions.
4 changes: 4 additions & 0 deletions phoenix.pro
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ include(pri/sketch.pri)
include(pri/translations.pri)
include(pri/program.pri)
include(pri/qtsysteminfo.pri)
include(pri/clipper.pri)

!contains(DEFINES, QUAZIP_INSTALLED) {
include(pri/quazip.pri)
Expand All @@ -242,5 +243,8 @@ contains(DEFINES, QUAZIP_INSTALLED) {
TARGET = Fritzing
TEMPLATE = app

DISTFILES += \
clipper.pri


message("libs $$LIBS")
27 changes: 27 additions & 0 deletions pri/clipper.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# /*******************************************************************
#
# Part of the Fritzing project - http://fritzing.org
# Copyright (c) 2007-08 Fachhochschule Potsdam - http://fh-potsdam.de
#
# Fritzing is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Fritzing 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
#
# ********************************************************************

#********************************************************************/

HEADERS += \
src/lib/clipper/clipper.hpp

SOURCES += \
src/lib/clipper/clipper.cpp
66 changes: 3 additions & 63 deletions src/autoroute/panelizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void Panelizer::panelize(FApplication * app, const QString & panelFilename, bool
QSizeF svgSize(planePair->panelWidth, planePair->panelHeight);
SVG2gerber::ForWhy forWhy = layerThingList.at(i).forWhy;
if (forWhy == SVG2gerber::ForMask || forWhy == SVG2gerber::ForPasteMask) forWhy = SVG2gerber::ForCopper;
GerberGenerator::doEnd(planePair->svgs.at(i), 2, layerThingList.at(i).name, forWhy, svgSize * GraphicsUtils::StandardFritzingDPI, gerberDir.absolutePath(), prefix, suffix, false);
GerberGenerator::exportFile(planePair->svgs.at(i), 2, layerThingList.at(i).name, forWhy, svgSize * GraphicsUtils::StandardFritzingDPI, gerberDir.absolutePath(), prefix, suffix, false);
DebugDialog::debug("after converting " + prefix + " " + suffix);
}

Expand Down Expand Up @@ -1542,69 +1542,9 @@ void Panelizer::makeSVGs(MainWindow * mainWindow, ItemBase * board, const QStrin
renderThing.hideTerminalPoints = true;
renderThing.selectedItems = renderThing.renderBlocker = false;
QString one = mainWindow->pcbView()->renderToSVG(renderThing, board, layerThing.layerList);

QString clipString;
bool wantText = false;
switch (forWhy) {
case SVG2gerber::ForOutline:
one = GerberGenerator::cleanOutline(one);
break;
case SVG2gerber::ForPasteMask:
mainWindow->pcbView()->restoreCopperLogoItems(copperLogoItems);
mainWindow->pcbView()->restoreCopperLogoItems(holes);
one = mainWindow->pcbView()->makePasteMask(one, board, GraphicsUtils::StandardFritzingDPI, layerThing.layerList);
if (one.isEmpty()) continue;

forWhy = SVG2gerber::ForCopper;
break;
case SVG2gerber::ForMask:
mainWindow->pcbView()->restoreCopperLogoItems(copperLogoItems);
one = TextUtils::expandAndFill(one, "black", GerberGenerator::MaskClearanceMils * 2);
forWhy = SVG2gerber::ForCopper;
if (name.contains("bottom")) {
maskBottom = one;
}
else {
maskTop = one;
}
break;
case SVG2gerber::ForSilk:
wantText = true;
if (name.contains("bottom")) {
clipString = maskBottom;
}
else {
clipString = maskTop;
}
break;
case SVG2gerber::ForCopper:
case SVG2gerber::ForDrill:
treatAsCircle.clear();
foreach (QGraphicsItem * item, mainWindow->pcbView()->scene()->collidingItems(board)) {
ConnectorItem * connectorItem = dynamic_cast<ConnectorItem *>(item);
if (connectorItem == NULL) continue;
if (!connectorItem->isPath()) continue;
if (connectorItem->radius() == 0) continue;

treatAsCircle.insert(connectorItem->attachedToID(), connectorItem);
}
wantText = true;
break;
default:
wantText = true;
break;
}

if (wantText) {
collectTexts(one, texts);
//DebugDialog::debug("one " + one);
}

QString two = GerberGenerator::clipToBoard(one, board, name, forWhy, clipString, true, treatAsCircle);
treatAsCircle.clear();
if (two.isEmpty()) continue;
if (one.isEmpty()) continue;

TextUtils::writeUtf8(filename, two);
TextUtils::writeUtf8(filename, one);
}

if (texts.count() > 0) {
Expand Down
29 changes: 15 additions & 14 deletions src/items/logoitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ along with Fritzing. If not, see <http://www.gnu.org/licenses/>.
#include "../svg/groundplanegenerator.h"
#include "../utils/cursormaster.h"
#include "../debugdialog.h"
#include "../svg/clipperhelpers.h"

#include <QHBoxLayout>
#include <QVBoxLayout>
Expand Down Expand Up @@ -438,20 +439,20 @@ void LogoItem::loadImage(const QString & fileName, bool addName)

double res = image.dotsPerMeterX() / GraphicsUtils::InchesPerMeter;
if (this->m_standardizeColors) {
GroundPlaneGenerator gpg;
gpg.setLayerName(layerName());
gpg.setMinRunSize(1, 1);
gpg.scanImage(image, image.width(), image.height(), 1, res, colorString(), false, false, QSizeF(0, 0), 0, QPointF(0, 0));
if (gpg.newSVGs().count() < 1) {
FMessageBox::information(
NULL,
tr("Unable to display"),
tr("Unable to display image from %1").arg(fileName)
);
return;
}

svg = gpg.mergeSVGs("", layerName());
QString path = imageToSVGPath(image, 1);
QString svgDoc = TextUtils::makeSVGHeader(1, res, image.width() / res, image.height() / res)
+"<g id='"+layerName()+"'>"
+ path
+"</g>"
+ "</svg>";
QDomDocument doc;
QStringList exceptions;
exceptions << "none" << "";
QString toColor(colorString());
QDomElement element = doc.documentElement();
SvgFileSplitter::changeColors(element, toColor, exceptions);
TextUtils::mergeSvg(doc, svgDoc, layerName());
svg = TextUtils::mergeSvgFinish(doc);
}
else {
svg = TextUtils::makeSVGHeader(res, res, image.width(), image.height());
Expand Down
Loading

0 comments on commit 844ff96

Please sign in to comment.