1 /******************************************************************* 2 3 Part of the Fritzing project - http://fritzing.org 4 Copyright (c) 2007-2014 Fachhochschule Potsdam - http://fh-potsdam.de 5 6 Fritzing is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Fritzing is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Fritzing. If not, see <http://www.gnu.org/licenses/>. 18 19 ******************************************************************** 20 21 $Revision: 6968 $: 22 $Author: irascibl@gmail.com $: 23 $Date: 2013-04-15 17:44:14 +0200 (Mo, 15. Apr 2013) $ 24 25 ********************************************************************/ 26 27 #ifndef PANELIZER_H 28 #define PANELIZER_H 29 30 #include <QString> 31 #include <QSizeF> 32 33 #include "../mainwindow/mainwindow.h" 34 #include "../items/itembase.h" 35 #include "cmrouter/tile.h" 36 37 38 struct PlanePair 39 { 40 Plane * thePlane; 41 Plane * thePlane90; 42 TileRect tilePanelRect; 43 TileRect tilePanelRect90; 44 double panelWidth; 45 double panelHeight; 46 QStringList svgs; 47 QString layoutSVG; 48 int index; 49 }; 50 51 struct PanelItem { 52 // per window 53 QString boardName; 54 QString path; 55 int required; 56 int maxOptional; 57 int optionalPriority; 58 int produced; 59 QSizeF boardSizeInches; 60 long boardID; 61 PanelItem * refPanelItem; 62 63 // per instance 64 double x, y; 65 bool rotate90; 66 PlanePair * planePair; 67 68 PanelItem(); 69 70 PanelItem(PanelItem * from); 71 }; 72 73 struct BestPlace 74 { 75 Tile * bestTile; 76 TileRect bestTileRect; 77 TileRect maxRect; 78 int width; 79 int height; 80 double bestArea; 81 bool rotate90; 82 Plane* plane; 83 84 BestPlace(); 85 }; 86 87 struct PanelType { 88 double width; 89 double height; 90 double c1; 91 double c2; 92 QString name; 93 }; 94 95 struct PanelParams 96 { 97 QList<PanelType *> panelTypes; 98 double panelSpacing; 99 double panelBorder; 100 QString prefix; 101 }; 102 103 struct LayerThing { 104 LayerList layerList; 105 QString name; 106 SVG2gerber::ForWhy forWhy; 107 QString suffix; 108 LayerThingLayerThing109 LayerThing(const QString & n, LayerList ll, SVG2gerber::ForWhy fw, const QString & s) { 110 layerList = ll; 111 name = n; 112 forWhy = fw; 113 suffix = s; 114 } 115 }; 116 117 class Panelizer 118 { 119 public: 120 static void panelize(class FApplication *, const QString & panelFilename, bool customPartsOnly); 121 static void inscribe(class FApplication *, const QString & panelFilename, bool drc, bool noMessages); 122 static int placeBestFit(Tile * tile, UserData userData); 123 static int checkDonuts(MainWindow *, bool displayMessage); 124 static int checkText(MainWindow *, bool displayMessage); 125 126 protected: 127 static bool initPanelParams(QDomElement & root, PanelParams &); 128 static PlanePair * makePlanePair(PanelParams &, bool big); 129 static void collectFiles(const QDir & outputDir, QDomElement & path, QHash<QString, QString> & fzzFilePaths); 130 static bool checkBoards(QDomElement & board, QHash<QString, QString> & fzzFilePaths); 131 static bool openWindows(QDomElement & board, QHash<QString, QString> & fzzFilePaths, class FApplication *, PanelParams &, QDir & fzDir, QDir & svgDir, QList<PanelItem *> & refPanelItems, QList<LayerThing> & layerThingList, bool customPartsOnly, QDir & copyDir); 132 static void bestFit(QList<PanelItem *> & insertPanelItems, PanelParams &, QList<PlanePair *> &, bool customPartsOnly); 133 static bool bestFitOne(PanelItem * panelItem, PanelParams & panelParams, QList<PlanePair *> & planePairs, bool createNew, bool customPartsOnly); 134 static void addOptional(int optionalCount, QList<PanelItem *> & refPanelItems, QList<PanelItem *> & insertPanelItems, PanelParams &, QList<PlanePair *> &); 135 static class MainWindow * inscribeBoard(QDomElement & board, QHash<QString, QString> & fzzFilePaths, FApplication * app, QDir & fzDir, bool drc, bool noMessages, QDir & copyDir); 136 static void doOnePanelItem(PlanePair * planePair, QList<LayerThing> & layerThingList, PanelItem * panelItem, QDir & svgDir); 137 static void makeSVGs(MainWindow *, ItemBase *, const QString & boardName, QList<LayerThing> & layerThingList, QDir & saveDir, QFileInfo & copyInfo); 138 static void shrinkLastPanel( QList<PlanePair *> & planePairs, QList<PanelItem *> & insertPanelItems, PanelParams &, bool customPartsOnly); 139 static int bestFitLoop(QList<PanelItem *> & refPanelItems, PanelParams &, bool customPartsOnly, QList<PlanePair *> & returnPlanePairs, QList<PanelItem *> & returnInsertPanelItems, const QDir & svgDir); 140 static double calcCost(PanelParams &, QList<PlanePair *> &, int divisor); 141 static void writePanelizerOutput(const QString & message); 142 static void initPanelizerOutput(const QString & filename, const QString & initialMsg); 143 static void collectFilenames(const QString & filenames); 144 static void writePanelizerFilenames(const QString & panelFilename); 145 }; 146 147 #endif 148