File indexing completed on 2024-06-09 13:46:35

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef PINMAPPING_H
0012 #define PINMAPPING_H
0013 
0014 #include "circuiticndocument.h"
0015 #include "component.h"
0016 #include "icnview.h"
0017 
0018 #include <QDialog>
0019 
0020 class ECKeyPad;
0021 class ECSevenSegment;
0022 class MicroInfo;
0023 class PIC_IC;
0024 class PinMapDocument;
0025 class PinMapView;
0026 
0027 /**
0028 Stores a pin mapping Pic <--> [component] where component is set by the Type
0029 (e.g. Keypad or Seven Segment). Used for FlowCode.
0030 @author David Saxton
0031 */
0032 class PinMapping
0033 {
0034 public:
0035     enum Type { SevenSegment, Keypad_4x3, Keypad_4x4, Invalid };
0036 
0037     /**
0038      * Creates an invalid PinMapping, required by Qt templates.
0039      */
0040     PinMapping();
0041     /**
0042      * Creates a PinMapping with the given type.
0043      */
0044     PinMapping(Type type);
0045     ~PinMapping();
0046 
0047     Type type() const
0048     {
0049         return m_type;
0050     }
0051 
0052     QStringList pins() const
0053     {
0054         return m_pins;
0055     }
0056     void setPins(const QStringList &pins)
0057     {
0058         m_pins = pins;
0059     }
0060 
0061 protected:
0062     QStringList m_pins;
0063     Type m_type;
0064 };
0065 typedef QMap<QString, PinMapping> PinMappingMap;
0066 
0067 /**
0068 Dialog for editing a Pin Mapping
0069 @author David Saxton
0070 */
0071 class PinMapEditor : public QDialog
0072 {
0073     Q_OBJECT
0074 public:
0075     PinMapEditor(PinMapping *PinMapping, MicroInfo *Info, QWidget *parent);
0076 
0077 protected slots:
0078     void slotApply();
0079     void slotOk();
0080 
0081 protected:
0082     void savePinMapping();
0083 
0084     PinMapping *m_pPinMapping;
0085     PinMapDocument *m_pPinMapDocument;
0086     PinMapView *m_pPinMapView;
0087 };
0088 
0089 /**
0090 For use with FlowParts that require a pin map (e.g. Keypad and Seven Segment).
0091 @author David Saxton
0092 To see a document like this: put down a PIC, click advanced on it, then down in the pin map definitions dialog
0093 click add/modify, select something in the appearing dialog, and there is it.
0094 It's similar to a circuit.
0095 */
0096 // because this document is similar to a circuit, the nodes are the electronic nodes
0097 class PinMapDocument : public CircuitICNDocument
0098 {
0099     Q_OBJECT
0100 public:
0101     PinMapDocument();
0102     ~PinMapDocument() override;
0103 
0104     void init(const PinMapping &PinMapping, MicroInfo *microInfo);
0105 
0106     bool isValidItem(Item *item) override;
0107     bool isValidItem(const QString &itemId) override;
0108 
0109     PinMapping pinMapping() const;
0110 
0111     void deleteSelection() override;
0112 
0113 protected:
0114     PinMapping::Type m_pinMappingType;
0115     ECKeyPad *m_pKeypad;
0116     ECSevenSegment *m_pSevenSegment;
0117     PIC_IC *m_pPicComponent;
0118 };
0119 
0120 /**
0121 @author David Saxton
0122 */
0123 class PinMapView : public ICNView
0124 {
0125     Q_OBJECT
0126 public:
0127     PinMapView(PinMapDocument *pinMapDocument, ViewContainer *viewContainer, uint viewAreaId);
0128     ~PinMapView() override;
0129 };
0130 
0131 class PIC_IC : public Component
0132 {
0133 public:
0134     PIC_IC(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0135     ~PIC_IC() override;
0136 
0137     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0138     static LibraryItem *libraryItem();
0139 
0140     void initPackage(MicroInfo *info);
0141 };
0142 
0143 #endif