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: 6943 $: 22 $Author: irascibl@gmail.com $: 23 $Date: 2013-03-30 14:06:38 +0100 (Sa, 30. Mrz 2013) $ 24 25 ********************************************************************/ 26 27 28 #ifndef PEMAINWINDOW_H_ 29 #define PEMAINWINDOW_H_ 30 31 32 #include "../mainwindow/mainwindow.h" 33 #include "../model/modelpartshared.h" 34 #include "../sketch/sketchwidget.h" 35 #include "peconnectorsview.h" 36 37 class IconSketchWidget : public SketchWidget 38 { 39 Q_OBJECT 40 41 public: 42 IconSketchWidget(ViewLayer::ViewID, QWidget *parent=0); 43 44 void addViewLayers(); 45 }; 46 47 struct ViewThing { 48 ItemBase * itemBase; 49 QDomDocument * document; 50 int svgChangeCount; 51 bool everZoomed; 52 SketchWidget * sketchWidget; 53 QString referenceFile; 54 QString originalSvgPath; 55 bool firstTime; 56 bool busMode; 57 58 ViewThing(); 59 }; 60 61 class PEMainWindow : public MainWindow 62 { 63 Q_OBJECT 64 65 public: 66 PEMainWindow(class ReferenceModel * referenceModel, QWidget * parent); 67 ~PEMainWindow(); 68 69 bool setInitialItem(class PaletteItem *); 70 void changeTags(const QStringList &, bool updateDisplay); 71 void changeProperties(const QHash<QString, QString> &, bool updateDisplay); 72 void changeMetadata(const QString & name, const QString & value, bool updateDisplay); 73 void changeConnectorMetadata(ConnectorMetadata *, bool updateDisplay); 74 void changeSvg(SketchWidget *, const QString & filename, int changeDirection); 75 void relocateConnectorSvg(SketchWidget *, const QString & id, const QString & terminalID, const QString & oldGorn, const QString & oldGornTerminal, const QString & newGorn, const QString & newGornTerminal, int changeDirection); 76 void moveTerminalPoint(SketchWidget *, const QString & id, QSizeF, QPointF, int changeDirection); 77 void restoreFzp(const QString & filename); 78 bool editsModuleID(const QString &); 79 void addBusConnector(const QString & busID, const QString & connectorID); 80 void removeBusConnector(const QString & busID, const QString & connectorID, bool display); 81 void changeSMD(const QString & smd, const QString & filename, int changeDirection); 82 void changeReferenceFile(ViewLayer::ViewID viewID, const QString referenceFile); 83 void changeOriginalFile(ViewLayer::ViewID viewID, const QString originalFile, int changeCount); 84 85 signals: 86 void addToMyPartsSignal(ModelPart *); 87 88 public slots: 89 void metadataChanged(const QString & name, const QString & value); 90 void propertiesChanged(const QHash<QString, QString> &); 91 void tagsChanged(const QStringList &); 92 void connectorMetadataChanged(struct ConnectorMetadata *); 93 void removedConnectors(QList<ConnectorMetadata *> &); 94 void highlightSlot(class PEGraphicsItem *); 95 void pegiMousePressed(class PEGraphicsItem *, bool & ignore); 96 void pegiMouseReleased(class PEGraphicsItem *); 97 void pegiTerminalPointMoved(class PEGraphicsItem *, QPointF); 98 void pegiTerminalPointChanged(class PEGraphicsItem *, QPointF before, QPointF after); 99 void switchedConnector(int); 100 void removedConnector(const QDomElement &); 101 void terminalPointChanged(const QString & how); 102 void terminalPointChanged(const QString & coord, double value); 103 void getSpinAmount(double & amount); 104 void pickModeChanged(bool); 105 void busModeChanged(bool); 106 void connectorCountChanged(int); 107 void deleteBusConnection(); 108 void newWireSlot(Wire *); 109 void wireChangedSlot(class Wire*, const QLineF & oldLine, const QLineF & newLine, QPointF oldPos, QPointF newPos, ConnectorItem * from, ConnectorItem * to); 110 void connectorsTypeChanged(Connector::ConnectorType); 111 void smdChanged(const QString &); 112 void showing(SketchWidget *); 113 void updateExportMenu(); 114 void updateEditMenu(); 115 void s2sMessageSlot(const QString & message); 116 117 protected: 118 void closeEvent(QCloseEvent * event); 119 bool event(QEvent *); 120 void initLockedFiles(bool lockFiles); 121 void initSketchWidgets(bool withIcons); 122 void initProgrammingWidget(); 123 void initDock(); 124 void moreInitDock(); 125 void setInitialView(); 126 void createActions(); 127 void createMenus(); 128 QList<QWidget*> getButtonsForView(ViewLayer::ViewID); 129 void connectPairs(); 130 QMenu *breadboardItemMenu(); 131 QMenu *schematicItemMenu(); 132 QMenu *pcbItemMenu(); 133 QMenu *pcbWireMenu(); 134 QMenu *schematicWireMenu(); 135 QMenu *breadboardWireMenu(); 136 void setTitle(); 137 void createViewMenuActions(bool showWelcome); 138 void createFileMenuActions(); 139 void createViewMenu(); 140 void createEditMenu(); 141 QHash<QString, QString> getOldProperties(); 142 QDomElement findConnector(const QString & id, int & index); 143 void changeConnectorElement(QDomElement & connector, ConnectorMetadata *); 144 void initSvgTree(SketchWidget *, ItemBase *, QDomDocument &); 145 void initConnectors(bool updateConnectorsView); 146 QString createSvgFromImage(const QString &origFilePath); 147 // QString makeSvgPath(const QString & referenceFile, SketchWidget * sketchWidget, bool useIndex); 148 QString makeSvgPath2(SketchWidget * sketchWidget); 149 QString saveFzp(); 150 void reload(bool firstTime); 151 void createFileMenu(); 152 void updateChangeCount(SketchWidget * sketchWidget, int changeDirection); 153 class PEGraphicsItem * findConnectorItem(); 154 void terminalPointChangedAux(PEGraphicsItem * pegi, QPointF before, QPointF after); 155 void showInOS(QWidget *parent, const QString &pathIn); 156 void switchedConnector(int, SketchWidget *); 157 PEGraphicsItem * makePegi(QSizeF size, QPointF topLeft, ItemBase * itemBase, QDomElement & element, double z); 158 QRectF getPixelBounds(FSvgRenderer & renderer, QDomElement & element); 159 bool canSave(); 160 bool saveAs(bool overWrite); 161 void setBeforeClosingText(const QString & filename, QMessageBox & messageBox); 162 QString getPartTitle(); 163 void killPegi(); 164 bool loadFzp(const QString & path); 165 void removedConnectorsAux(QList<QDomElement> & connectors); 166 //QString getFzpReferenceFile(); 167 QString getSvgReferenceFile(const QString & filename); 168 QString makeDesc(const QString & referenceFile); 169 void insertDesc(const QString & referenceFile, QString & svg); 170 void updateRaiseWindowAction(); 171 bool writeXml(const QString & path, const QString & text, bool temp); 172 void displayBuses(); 173 QDomElement findBus(const QDomElement &, const QString &); 174 QDomElement findNodeMemberBus(const QDomElement & buses, const QString & connectorID); 175 void replaceProperty(const QString & key, const QString & value, QDomElement & properties); 176 QWidget * createTabWidget(); 177 void addTab(QWidget * widget, const QString & label); 178 int currentTabIndex(); 179 void setCurrentTabIndex(int); 180 QWidget * currentTabWidget(); 181 void changeSpecialProperty(const QString & name, const QString & value); 182 bool eventFilter(QObject *, QEvent *); 183 void relocateConnector(PEGraphicsItem * pegi); 184 void clearPickMode(); 185 void deleteBuses(); 186 QList<PEGraphicsItem *> getPegiList(SketchWidget *); 187 void fillInMetadata(const QDomElement & connector, ConnectorMetadata & cmd); 188 void setConnectorSMD(bool toSMD, QDomElement & connector); 189 bool activeLayerWidgetAlwaysOn(); 190 void updateFileMenu(); 191 void reuseImage(ViewLayer::ViewID); 192 void setImageAttribute(QDomElement & layers, const QString & image); 193 void setImageAttribute(QDomElement & fzpRoot, const QString & svgPath, ViewLayer::ViewID viewID); 194 QString makeNewVariant(const QString & family); 195 void connectorWarning(); 196 bool anyMarquee(); 197 bool anyVisible(); 198 QString makeDirName(); 199 void initWelcomeView(); 200 201 protected slots: 202 void initZoom(); 203 void showMetadataView(); 204 void showConnectorsView(); 205 void showIconView(); 206 void loadImage(); 207 bool save(); 208 bool saveAs(); 209 void showInOS(); 210 void tabWidget_currentChanged(int index); 211 void backupSketch(); 212 void updateWindowMenu(); 213 void updateWireMenu(); 214 void closeLater(); 215 void resetNextPick(); 216 void reuseBreadboard(); 217 void reuseSchematic(); 218 void reusePCB(); 219 void convertToTenth(); 220 void hideOtherViews(); 221 void updateLayerMenu(bool resetLayout = false); 222 void updateAssignedConnectors(); 223 void itemAddedSlot(ModelPart *, ItemBase *, ViewLayer::ViewLayerPlacement, const ViewGeometry &, long id, SketchWidget * dropOrigin); 224 void itemMovedSlot(ItemBase *); 225 void clickedItemCandidateSlot(QGraphicsItem *, bool & ok); 226 void resizedSlot(ItemBase *); 227 228 229 protected: 230 QDomDocument m_fzpDocument; 231 QDomDocument m_iconDocument; 232 QDomDocument m_breadboardDocument; 233 QDomDocument m_schematicDocument; 234 QDomDocument m_pcbDocument; 235 236 QAction * m_showMetadataViewAct; 237 QAction * m_showConnectorsViewAct; 238 QAction * m_showIconAct; 239 QAction * m_showInOSAct; 240 class WireAction * m_deleteBusConnectionAct; 241 QAction * m_reuseBreadboardAct; 242 QAction * m_reuseSchematicAct; 243 QAction * m_reusePCBAct; 244 QAction * m_hideOtherViewsAct; 245 QAction * m_convertToTenthAct; 246 247 QPointer<SketchAreaWidget> m_iconWidget; 248 QPointer<class IconSketchWidget> m_iconGraphicsView; 249 class PEMetadataView * m_metadataView; 250 class PEConnectorsView * m_connectorsView; 251 class PEToolView * m_peToolView; 252 class PESvgView * m_peSvgView; 253 QString m_guid; 254 QString m_prefix; 255 int m_fileIndex; 256 QHash<ViewLayer::ViewID, ViewThing *> m_viewThings; 257 QString m_userPartsFolderPath; 258 QString m_userPartsFolderSvgPath; 259 bool m_canSave; 260 QString m_originalFzpPath; 261 QString m_originalModuleID; 262 bool m_gaveSaveWarning; 263 QStringList m_filesToDelete; 264 QList< QPointer<QWidget> > m_inFocusWidgets; 265 bool m_inPickMode; 266 bool m_useNextPick; 267 QList<QDomElement> m_connectorList; 268 269 QString m_removedConnector; 270 }; 271 272 273 #endif /* PEMAINWINDOW_H_ */ 274