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: 6998 $: 22 $Author: irascibl@gmail.com $: 23 $Date: 2013-04-28 13:51:10 +0200 (So, 28. Apr 2013) $ 24 25 ********************************************************************/ 26 27 28 #ifndef PALETTEITEM_H 29 #define PALETTEITEM_H 30 31 #include <QRectF> 32 #include <QPainterPath> 33 #include <QPixmap> 34 #include <QVariant> 35 #include <QComboBox> 36 #include <QRadioButton> 37 #include <QDoubleValidator> 38 #include <QLineEdit> 39 40 #include "paletteitembase.h" 41 #include "../viewlayer.h" 42 43 typedef QString (*GenModuleID)(QMap<QString, QString> & currPropsMap); 44 typedef QString (*GenSvg)(const QString & expectedFileName); 45 typedef QString (*GenFzp)(const QString &); 46 47 struct HoleClassThing { 48 QString holeSize; 49 QString ringThickness; 50 QString holeSizeValue; 51 QHash<QString, QString> holeSizes; 52 QList<QString> holeSizeKeys; // need this for menu item ordering purposes 53 QPointF ringThicknessRange; 54 QPointF holeDiameterRange; 55 56 }; 57 58 struct HoleSettings 59 { 60 QString holeDiameter; 61 QString ringThickness; 62 HoleClassThing * holeThing; 63 QPointer<QDoubleValidator> diameterValidator; 64 QPointer<QDoubleValidator> thicknessValidator; 65 QPointer<QLineEdit> diameterEdit; 66 QPointer<QLineEdit> thicknessEdit; 67 QPointer<QRadioButton> inRadioButton; 68 QPointer<QRadioButton> mmRadioButton; 69 QPointer<QComboBox> sizesComboBox; 70 71 QString currentUnits(); 72 QString holeSize(); 73 }; 74 75 class PaletteItem : public PaletteItemBase 76 { 77 Q_OBJECT 78 79 public: 80 // after calling this constructor if you want to render the loaded svg (either from model or from file), MUST call <renderImage> 81 PaletteItem(ModelPart *, ViewLayer::ViewID, const ViewGeometry & viewGeometry, long id, QMenu * itemMenu, bool doLabel); 82 ~PaletteItem(); 83 84 void removeLayerKin(); 85 void addLayerKin(class LayerKinPaletteItem * lkpi); 86 const QList<class ItemBase *> & layerKin(); 87 virtual void loadLayerKin(const LayerHash & viewLayers, ViewLayer::ViewLayerPlacement); 88 void rotateItem(double degrees, bool includeRatsnest); 89 void flipItem(Qt::Orientations orientation); 90 void moveItem(ViewGeometry & viewGeometry); 91 void transformItem2(const QMatrix &); 92 void setItemPos(QPointF & pos); 93 94 bool renderImage(ModelPart * modelPart, ViewLayer::ViewID viewID, const LayerHash & viewLayers, ViewLayer::ViewLayerID, bool doConnectors, QString & error); 95 96 void setTransforms(); 97 void syncKinMoved(QPointF offset, QPointF loc); 98 99 void setInstanceTitle(const QString&, bool initial); 100 101 bool swap(ModelPart* newModelPart, const LayerHash &layerHash, bool reinit, class SwapCommand *); 102 void setHidden(bool hidden); 103 void setInactive(bool inactivate); 104 bool collectFemaleConnectees(QSet<ItemBase *> & items); 105 void collectWireConnectees(QSet<class Wire *> & wires); 106 void clearModelPart(); 107 bool mousePressEventK(PaletteItemBase * originalItem, QGraphicsSceneMouseEvent *); 108 void resetID(); 109 void slamZ(double z); 110 void resetImage(class InfoGraphicsView *); 111 void resetKinImage(ItemBase * layerKin, InfoGraphicsView * infoGraphicsView); 112 bool collectExtraInfo(QWidget * parent, const QString & family, const QString & prop, const QString & value, bool swappingEnabled, QString & returnProp, QString & returnValue, QWidget * & returnWidget, bool & hide); 113 QStringList collectValues(const QString & family, const QString & prop, QString & value); 114 virtual bool changePinLabels(bool singleRow, bool sip); 115 QStringList getPinLabels(bool & hasLocal); 116 void renamePins(const QStringList & labels, bool singleRow); 117 void resetConnectors(); 118 void resetConnectors(ItemBase * otherLayer, FSvgRenderer * otherLayerRenderer); 119 void resetConnector(ItemBase * itemBase, SvgIdLayer * svgIdLayer); 120 QStringList sipOrDipOrLabels(bool & hasLayout, bool & sip); 121 void resetLayerKin(const QString & svg); 122 QTransform untransform(); 123 void retransform(const QTransform &); 124 125 public: 126 static QString genFZP(const QString & moduleid, const QString & templateName, int minPins, int maxPins, int steps, bool smd); 127 128 static QWidget * createHoleSettings(QWidget * parent, HoleSettings &, bool swappingEnabled, const QString & currentHoleSize, bool advanced); 129 static void updateValidators(HoleSettings &); 130 static void updateEditTexts(HoleSettings &); 131 static void updateSizes(HoleSettings &); 132 static void initHoleSettings(HoleSettings & holeSettings, HoleClassThing *); 133 static bool setHoleSize(QString & holeSize, bool force, HoleSettings & holeSettings); 134 static QString changeUnits(HoleSettings &); 135 static bool changeDiameter(HoleSettings & holeSettings, QObject * sender); 136 static bool changeThickness(HoleSettings & holeSettings, QObject * sender); 137 138 signals: 139 void pinLabelSwap(ItemBase *, const QString & moduleID); 140 141 protected slots: 142 void openPinLabelDialog(); 143 144 protected: 145 void syncKinSelection(bool selected, PaletteItemBase * originator); 146 QVariant itemChange(GraphicsItemChange change, const QVariant &value); 147 void updateConnections(bool includeRatsnest, QList<ConnectorItem *> & already); 148 void mousePressEvent(QGraphicsSceneMouseEvent *event); 149 void figureHover(); 150 bool isSingleRow(const QList<ConnectorItem *> & connectorItems); 151 QList<Connector *> sortConnectors(); 152 QString hackSvgHoleSize(const QString & holeDiameter, const QString & ringThickness); 153 QString hackFzpHoleSize(const QString & moduleID, const QString & pcbFilename, const QString & holeSize); 154 QString appendHoleSize(const QString & moduleID, const QString & holeSize, const QString & ringThickness); 155 void generateSwap(const QString & text, GenModuleID, GenFzp, GenSvg makeBreadboardSvg, GenSvg makeSchematicSvg, GenSvg makePcbSvg); 156 bool makeLocalModifications(QByteArray & svg, const QString & filename); 157 void makeOneKin(qint64 & id, ViewLayer::ViewLayerID, ViewLayer::ViewLayerPlacement, ViewGeometry &, const LayerHash &); 158 159 protected: 160 void setUpHoleSizes(const QString & type, HoleClassThing &); 161 void setUpHoleSizesAux(HoleClassThing &, const QString & type); 162 bool collectHoleSizeInfo(const QString & defaultHoleSizeValue, QWidget * parent, bool swappingEnabled, QString & returnProp, QString & returnValue, QWidget * & returnWidget); 163 static QStringList getSizes(QString & holeSize, HoleSettings &); 164 static QString hackFzpHoleSize(QDomDocument & document, const QString & newModuleID, const QString & pcbFilename, const QString & newSize); 165 static QString hackFzpHoleSize(const QString & fzp, const QString & moduleid, int hsix); 166 static QString hackSvgHoleSize(QDomDocument & domDocument, const QString & holeDiameter, const QString & ringThickness); 167 static QString hackSvgHoleSizeAux(const QString & svg, const QString & expectedFileName); 168 169 protected slots: 170 virtual void changeHoleSize(const QString &); 171 virtual void changeUnits(bool); 172 void changeDiameter(); 173 void changeThickness(); 174 175 176 public: 177 static const QString HoleSizePrefix; 178 179 protected: 180 QList<class ItemBase *> m_layerKin; 181 HoleSettings m_holeSettings; 182 int m_flipCount; 183 184 }; 185 186 #endif 187