00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __CANVAS_ITEMS_DOT_H
00023 #define __CANVAS_ITEMS_DOT_H
00024
00025 #include <smartptr.h>
00026 #include <qcanvas.h>
00027 #include <vector>
00028 #include <list>
00029 #include <mathGutz.h>
00030
00031 typedef std::vector<QCanvasItem*> CanvasItemPVec;
00032
00033 namespace CID {
00034 enum PEN_BRUSH_COLOR_IDS {
00035 PRIMARY,
00036 SECONDARY,
00037 TERTIERY,
00038 PICKED,
00039 PRE_PICKED,
00040 PBC_LAST
00041 };
00042
00043 const QColor PRIMARY_COLOR = Qt::white;
00044 const QColor SECONDARY_COLOR = Qt::lightGray;
00045 const QColor TERTIERY_COLOR = Qt::gray;
00046 const QColor PICKED_COLOR = Qt::red;
00047 const QColor PRE_PICKED_COLOR = Qt::darkRed;
00048
00049
00050
00051
00052
00053
00054
00055 extern int NUM_PCB;
00056 extern QColor COLORS[];
00057 extern QPen PENS[];
00058 extern QBrush BRUSHES[];
00059
00060 }
00061
00062
00063
00064 class CanvasItemBase;
00065
00066
00067
00068
00069
00070 class CompositeItem : public gutz::Counted {
00071 public:
00072 CompositeItem() {}
00073 virtual ~CompositeItem() {}
00074
00075
00076 virtual void childUpdate(CanvasItemBase *child) = 0;
00077
00078 virtual void childMovedBy(CanvasItemBase *child, gutz::vec3d dv) = 0;
00079
00080 virtual void childMoved(CanvasItemBase *child, gutz::vec3d last, gutz::vec3d point) = 0;
00081
00082 protected:
00083 };
00084
00085 typedef gutz::SmartPtr<CompositeItem> CompositeItemSP;
00086 typedef std::list<CompositeItemSP> CompositeItemSPList;
00087
00088 class NodeItem;
00089
00090
00091
00092
00093
00094
00095
00096 class CanvasItemIF :
00097 public QCanvasPolygonalItem
00098 {
00099 public:
00100 virtual ~CanvasItemIF(){}
00101
00102
00103
00104 virtual QPointArray areaPoints() const = 0;
00105
00106 virtual void drawShape(QPainter &p) = 0;
00107
00108
00109
00110 virtual void setSelected(bool yes);
00111
00112
00113 virtual void setActive(bool yes);
00114
00115
00116
00117 bool getUpdateLinks() const { return _updateLinks; }
00118 void setUpdateLinks(bool yes) {_updateLinks = yes; }
00119
00120 protected:
00121 CanvasItemIF();
00122 CanvasItemIF(QCanvas *canvas, CompositeItem *comp)
00123 : QCanvasPolygonalItem(canvas), _comp(comp),
00124 _updateLinks(true)
00125 {}
00126
00127 void updatePen();
00128
00129 CompositeItem *_comp;
00130
00131 bool _updateLinks;
00132 };
00133
00134
00135
00136
00137
00138
00139 class CanvasItemBase : public CanvasItemIF, public gutz::Counted
00140 {
00141 public:
00142
00143 protected:
00144 CanvasItemBase();
00145 CanvasItemBase(QCanvas *canvas, CompositeItem *comp)
00146 : CanvasItemIF(canvas, comp)
00147 {}
00148 };
00149
00150 typedef gutz::SmartPtr<CanvasItemBase> CanvasItemBaseSP;
00151
00152
00153
00154
00155
00156
00157 class EdgeItem: public CanvasItemBase
00158 {
00159 public:
00160 EdgeItem( NodeItem*, NodeItem*, QCanvas *canvas, CompositeItem *comp = 0 );
00161 virtual ~EdgeItem() {}
00162
00163
00164 void setPoints(double sx, double sy, double ex, double ey);
00165 void setPoints(const gutz::vec3d start, const gutz::vec3d end);
00166
00167 gutz::vec3d startPoint() const {return _start;}
00168 gutz::vec3d endPoint() const {return _end;}
00169
00170 virtual void setStartPoint(gutz::vec3d start);
00171 virtual void setEndPoint(gutz::vec3d end);
00172
00173
00174 virtual void moveBy(double dx, double dy);
00175
00176
00177 virtual QPointArray areaPoints() const;
00178
00179 protected:
00180
00181 virtual void drawShape(QPainter &p);
00182
00183 gutz::vec3d _start;
00184 gutz::vec3d _end;
00185 NodeItem *_startNode;
00186 NodeItem *_endNode;
00187 };
00188
00189 typedef gutz::SmartPtr<EdgeItem> EdgeItemSP;
00190 typedef std::vector<EdgeItemSP> EdgeItemVec;
00191
00192
00193
00194
00195
00196
00197 class NodeItem: public CanvasItemBase
00198 {
00199 public:
00200 NodeItem( QCanvas *canvas, double x = 0, double y = 0, CompositeItem *comp = 0 );
00201 virtual ~NodeItem() {}
00202
00203
00204
00205 virtual void setPoint(double x, double y, EdgeItem *mover=0);
00206 virtual void setPoint(gutz::vec3d v, EdgeItem *mover=0);
00207 gutz::vec3d getPoint() const { return gutz::vec3d(x(),y(),z()); }
00208
00209
00210 void setSize(int sz) {_sz = sz;}
00211
00212 QPoint center() { return boundingRect().center(); }
00213
00214
00215
00216 virtual void moveBy(double dx, double dy);
00217
00218
00219 virtual QPointArray areaPoints() const;
00220
00221
00222
00223 void addInEdge( EdgeItem *edge ) { inList.append( edge ); }
00224 void addOutEdge( EdgeItem *edge ) { outList.append( edge ); }
00225
00226 protected:
00227
00228 virtual void drawShape(QPainter &p);
00229
00230 QPtrList<EdgeItem> inList;
00231 QPtrList<EdgeItem> outList;
00232
00233 int _sz;
00234
00235 };
00236
00237 typedef gutz::SmartPtr<NodeItem> NodeItemSP;
00238 typedef std::vector<NodeItemSP> NodeItemVec;
00239
00240
00241
00242
00243
00244
00245 class PolygonEdit: public CanvasItemIF, public CompositeItem
00246 {
00247 public:
00248 PolygonEdit( QCanvas *canvas, CompositeItem *comp = 0 );
00249 virtual ~PolygonEdit();
00250
00251 virtual void setPoints(QPointArray p);
00252
00253 QPointArray areaPoints() const;
00254
00255
00256 virtual void childUpdate(CanvasItemBase *child){};
00257
00258 virtual void childMovedBy(CanvasItemBase *child, gutz::vec3d dv){};
00259
00260 virtual void childMoved(CanvasItemBase *child, gutz::vec3d last, gutz::vec3d point){};
00261
00262 virtual void moveBy(double dx, double dy) {}
00263
00264 virtual void moveBy(gutz::vec3d dv);
00265
00266 protected:
00267 virtual void drawShape(QPainter &p);
00268 void nukePoints();
00269 void nukeEdges();
00270
00271
00272 int getEdgeIndex(CanvasItemBase *ptr);
00273 int getNodeIndex(CanvasItemBase *ptr);
00274
00275 NodeItemVec _points;
00276 EdgeItemVec _edges;
00277 };
00278
00279 #endif
00280