00001
00002
00003
00004 #ifndef __WIRE_H
00005 #define __WIRE_H
00006
00007 #include "graphics.h"
00008
00009 #include <vector>
00010
00011 using namespace std;
00012
00013
00014 const static int WIRE_MODE_VERT_FIRST = 0;
00015 const static int WIRE_MODE_HORIZ_FIRST = 1;
00016
00017 const static int WIREPOINT_TYPE_INVALID = 0;
00018 const static int WIREPOINT_TYPE_NORMAL_USER_PLACED = 1;
00019 const static int WIREPOINT_TYPE_NORMAL_GENERATED = 2;
00020 const static int WIREPOINT_TYPE_CONNECTOR_CONNECTED = 3;
00021 const static int WIREPOINT_TYPE_CONNECTOR_DISCONNECTED = 4;
00022 const static int WIREPOINT_TYPE_IN_PIN = 5;
00023 const static int WIREPOINT_TYPE_OUT_PIN = 6;
00024
00025 const static int COMPONENT_TYPE = 0;
00026 const static int WIRE_TYPE = 1;
00027
00028
00029
00030 class WirePoint{
00031 public:
00032 WirePoint(int x, int y, int type);
00033 WirePoint(WirePoint *wirepoint);
00034 ~WirePoint();
00035
00036 void draw(Graphics *g, int scale, int direction);
00037 int x;
00038 int y;
00039 int type;
00040 };
00041
00042 class Wire;
00043
00044 class WireEnd{
00045
00046 friend class Wire;
00047
00048 public:
00049 WireEnd(Wire *parent);
00050 ~WireEnd();
00051
00052 void connect_to(WireEnd *w);
00053 void connect_to(ComponentPin *p);
00054
00055 void disconnect_from(WireEnd *w);
00056 void disconnect_from(ComponentPin *p);
00057
00058 void print();
00059
00060 Wire *parent;
00061
00062 protected:
00063 vector<ComponentPin *> connected_pins;
00064 vector<WireEnd *> connected_wireends;
00065
00066 };
00067
00068 void print(vector<WireEnd *> *list);
00069
00070 bool line_segment_contains(WirePoint *line_start,
00071 WirePoint *line_end, int tx, int ty);
00072
00073 static int wire_index_counter = 0;
00074
00075 class Wire{
00076
00077 friend class WireEnd;
00078
00079 public:
00080 Wire(WirePoint *startpoint);
00081 ~Wire();
00082 int index;
00083
00084
00085 public:
00086
00087 WireEnd *start;
00088 WireEnd *end;
00089
00090
00091 void draw(Graphics *g, int scale, bool selected);
00092 bool add_point(WirePoint *p);
00093 void move_last_point(int newx, int newy);
00094 bool remove_last_point();
00095 bool contains(int tx, int ty);
00096 Wire *break_at(int tx, int ty, WireEnd *wireend);
00097
00098
00099
00100
00101
00102
00103 void get_connected_wires(vector<Wire *> *wirelist);
00104 void get_connected_components(vector<Component *> *sending,
00105 vector<Component *> *receiving);
00106
00107
00108
00109
00110
00111
00112
00113
00114 vector<WirePoint *> wirepoints;
00115
00116 int mode;
00117
00118
00119
00120 };
00121
00122
00123
00124
00125 #endif