File indexing completed on 2024-05-05 05:46:09

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by John Myers                                      *
0003  *   electronerd@electronerdia.net                                         *
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 ROTOSWITCH_H
0012 #define ROTOSWITCH_H
0013 
0014 #include "component.h"
0015 #include <QVector>
0016 
0017 struct SwitchPosition {
0018     ECNode *node;
0019     Switch *posSwitch;
0020     bool isMomentary;
0021     int pinAngle;
0022 };
0023 
0024 /**
0025  * A rotary switch
0026  * \author John Myers
0027  */
0028 class ECRotoSwitch : public Component
0029 {
0030 public:
0031     ECRotoSwitch(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0032     ~ECRotoSwitch() override;
0033 
0034     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0035     static LibraryItem *libraryItem();
0036 
0037     void buttonStateChanged(const QString &id, bool state) override;
0038     void dataChanged() override;
0039 
0040 private:
0041     void drawShape(QPainter &p) override;
0042 
0043     int m_numPositions;
0044     int m_curPosition;
0045 
0046     /// Half the total width of the component including pins
0047     static const int _pinOuterRadius = 64;
0048     /// The width of the pins
0049     static const int _pinWidth = 8;
0050     /// the radius of the circle centered at the origin and tangent to the inner edge of the rows of pins
0051     static const int _pinInnerRadius = _pinOuterRadius - _pinWidth;
0052     /// gap between pins and contact circles
0053     static const int _wireGap = 7;
0054     /// The radius of the largest circle tangent to the pin circles
0055     static const int _contactOuterRadius = _pinInnerRadius - _wireGap;
0056     /// The radius of the circles used to show positions
0057     static const int _contactRadius = 2;
0058     /// The radius of the ring of positions
0059     static const int _contactRingRadius = _contactOuterRadius - _contactRadius;
0060 
0061     QVector<SwitchPosition> m_positions;
0062     ECNode *m_inNode;
0063 
0064 protected:
0065     void setUpSwitches();
0066 
0067 protected:
0068     void setActivePosition(int newPosition);
0069 };
0070 #endif // ROTOSWITCH_H