1 /* 2 Copyright (C) 1998,1999,2000,2001,2002,2003,2004 3 T. Scott Dattalo and Ralf Forsberg 4 5 This file is part of gpsim. 6 7 gpsim is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2, or (at your option) 10 any later version. 11 12 gpsim is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with gpsim; see the file COPYING. If not, write to 19 the Free Software Foundation, 59 Temple Place - Suite 330, 20 Boston, MA 02111-1307, USA. */ 21 22 #ifndef GUI_GUI_BREADBOARD_H_ 23 #define GUI_GUI_BREADBOARD_H_ 24 25 #include "../src/packages.h" 26 #include "../src/stimuli.h" 27 #include "gui_object.h" 28 29 #include <string> 30 #include <vector> 31 32 class CrossReferenceToGUI; 33 class GUI_Processor; 34 class Module; 35 36 // 37 // The Breadboard window data 38 // 39 40 class Breadboard_Window; 41 42 enum eOrientation {LEFT, UP, RIGHT, DOWN}; 43 enum eDirection {PIN_INPUT, PIN_OUTPUT}; 44 typedef enum {PIN_DIGITAL, PIN_ANALOG, PIN_OTHER} pintype; 45 46 // Routing types 47 typedef enum {R_NONE, R_LEFT, R_RIGHT, R_UP, R_DOWN} route_direction; 48 49 class point { 50 public: 51 int x; 52 int y; 53 }; 54 55 56 class path { 57 public: 58 point p; 59 route_direction dir; 60 }; 61 // End routing types 62 63 64 class GuiModule; 65 //======================================================================== 66 67 // 68 // GuiBreadBoardObject - Base class for things that can be drawn in the 69 // breadboard window. 70 // 71 72 class GuiBreadBoardObject { 73 public: 74 GuiBreadBoardObject(Breadboard_Window *, int x, int y); 75 virtual ~GuiBreadBoardObject(); 76 77 virtual void Draw() = 0; 78 virtual void Update() = 0; 79 virtual void Destroy() = 0; 80 IsBuilt()81 bool IsBuilt() 82 { 83 return m_bIsBuilt; 84 } bbw()85 Breadboard_Window *bbw() 86 { 87 return m_bbw; 88 } 89 void SetPosition(int x, int y); x()90 int x() 91 { 92 return m_x; 93 } y()94 int y() 95 { 96 return m_y; 97 } width()98 int width() 99 { 100 return m_width; 101 } height()102 int height() 103 { 104 return m_height; 105 } 106 107 protected: 108 Breadboard_Window *m_bbw; 109 110 int m_x; // Position in layout widget 111 int m_y; // Position in layout widget 112 int m_width; // 113 int m_height; // 114 bool m_bIsBuilt; // True after the object gets displayed. 115 }; 116 117 118 //------------------------------------------------------------------------ 119 // GuiPin 120 class GuiPin : public GuiBreadBoardObject { 121 public: 122 GuiPin(Breadboard_Window *, GuiModule *, Package *, unsigned int pin_number); getState()123 bool getState() 124 { 125 return value; 126 } putState(bool bNewState)127 void putState(bool bNewState) 128 { 129 value = bNewState; 130 } 131 void toggleState(); 132 void toggleDirection(); 133 134 void addXref(CrossReferenceToGUI *); 135 virtual void Draw(); 136 virtual void Update(); 137 virtual void Destroy(); 138 139 void SetModulePosition(int x, int y); module_x()140 int module_x() 141 { 142 return m_module_x; 143 } module_y()144 int module_y() 145 { 146 return m_module_y; 147 } 148 149 void SetLabelPosition(int x, int y); label_x()150 int label_x() 151 { 152 return m_label_x; 153 } label_y()154 int label_y() 155 { 156 return m_label_y; 157 } 158 bool DrawGUIlabel(); 159 void DrawLabel(cairo_t *cr); 160 SetOrientation(eOrientation o)161 void SetOrientation(eOrientation o) 162 { 163 orientation = o; 164 } 165 number()166 unsigned int number() 167 { 168 return m_pkgPinNumber; 169 } getSnode()170 Stimulus_Node *getSnode() 171 { 172 return getIOpin() ? getIOpin()->snode : nullptr; 173 } getIOpin()174 IOPIN *getIOpin() 175 { 176 return package->get_pin(m_pkgPinNumber); 177 } 178 const char *pinName(); 179 180 GtkWidget *m_pinDrawingArea; 181 182 eDirection direction; 183 eOrientation orientation; 184 pintype type; 185 186 protected: 187 bool value; 188 // IOPIN *iopin; 189 Package *package; 190 CrossReferenceToGUI *xref; 191 192 GuiModule *m_pModule; // Module to which this pin belongs. 193 int m_module_x; // Pin coordinates within parent module 194 int m_module_y; // 195 196 int m_label_x; // Pin Label coordinates (within parent module). 197 int m_label_y; 198 199 int m_pkgPinNumber; // 200 201 private: 202 static gboolean expose_pin(GtkWidget *widget, GdkEventExpose *event, 203 GuiPin *p); 204 }; 205 206 207 enum module_type {PIC_MODULE, EXTERNAL_MODULE}; 208 209 class BB_ModuleLabel { 210 public: 211 BB_ModuleLabel(const std::string &text, PangoFontDescription *font); 212 ~BB_ModuleLabel(); 213 gobj()214 GtkWidget *gobj() 215 { 216 return m_label; 217 } 218 219 private: 220 GtkWidget *m_label; 221 }; 222 223 224 //------------------------------------------------------------------------ 225 // GuiModule 226 // 227 // The GuiModule holds the graphics for a gpsim module that is displayed in 228 // the bread board window. The GuiModule serves as the link between the gui 229 // and the simulation engine. In other words, the GuiModule provides an 230 // interface through which the simulation engine may be accessed. 231 // 232 // All GuiModules have a one-to-one with a gpsim Module. (see src/modules.h) 233 // The GuiModule knows how to get access to a Module's pin information. 234 // 235 class GuiModule : public GuiBreadBoardObject { 236 public: 237 GuiModule(Module *, Breadboard_Window *); 238 239 void SetPosition(int x, int y); 240 void GetPosition(int &x, int &y); 241 double Distance(int x, int y); 242 243 virtual void Update(); 244 virtual void UpdatePins(); 245 virtual void Build(); 246 virtual void Draw(); 247 virtual void Destroy(); 248 virtual void DrawCaseOutline(cairo_t *); 249 250 virtual void AddPin(unsigned int); 251 virtual void AddPinGeometry(GuiPin *); 252 pin_count()253 int pin_count() 254 { 255 return m_pin_count; 256 } pins()257 std::vector<GuiPin *> * pins() 258 { 259 return &m_pins; 260 } module()261 Module *module() 262 { 263 return m_module; 264 } module_widget()265 GtkWidget *module_widget() 266 { 267 return m_module_widget; 268 } pinLabel_widget()269 GtkWidget *pinLabel_widget() 270 { 271 return m_pinLabel_widget; 272 } name_widget()273 GtkWidget *name_widget() 274 { 275 return m_name_widget->gobj(); 276 } 277 278 protected: 279 Module *m_module; 280 GtkWidget *m_module_widget; // As returned from module. If NULL, it becomes a static GtkPixmap 281 GtkWidget *m_pinLabel_widget;// A drawing area for pin labels. 282 int m_module_x; // These coordinates are an offset from m_x and m_y defined in 283 int m_module_y; /* GuiBreadBoardObject. Their purpose is to allow clients to 284 * reposition a customly created module_widget */ 285 286 BB_ModuleLabel *m_name_widget; // Name of widget, positioned above module_widget. 287 288 int pinnameWidths[4]; 289 int m_pin_count; 290 291 std::vector<GuiPin *> m_pins; 292 293 private: 294 static gboolean module_expose(GtkWidget *widget, GdkEventExpose *event, GuiModule *p); 295 }; 296 297 298 class GuiDipModule : public GuiModule { 299 public: 300 GuiDipModule(Module *, Breadboard_Window *); 301 virtual void DrawCaseOutline(cairo_t *); 302 }; 303 304 305 struct gui_node { 306 Breadboard_Window *bbw; 307 Stimulus_Node *node; 308 GtkWidget *tree_item; 309 }; 310 311 312 class Breadboard_Window : public GUI_Object { 313 public: 314 315 PangoFontDescription *pinstatefont; 316 PangoFontDescription *pinnamefont; 317 318 int pinnameheight; 319 320 GtkWidget *layout; 321 322 std::vector<GuiModule *> modules; 323 std::vector<Stimulus_Node *> nodes; 324 325 GtkWidget *tree; 326 327 GtkWidget *pic_frame; 328 GtkWidget *node_frame; 329 GtkWidget *module_frame; 330 GtkWidget *stimulus_frame; 331 332 GtkWidget *attribute_clist; 333 GtkWidget *attribute_entry; 334 GtkWidget *attribute_button; 335 336 GtkWidget *node_clist; 337 338 GtkWidget *stimulus_settings_label; 339 340 GtkWidget *stimulus_add_node_button; 341 342 GtkAdjustment *hadj, *vadj; 343 344 GtkTreeIter *node_iter; 345 346 GuiPin *selected_pin; 347 struct gui_node *selected_node; 348 GuiModule *selected_module; 349 350 explicit Breadboard_Window(GUI_Processor *gp); 351 virtual ~Breadboard_Window(); 352 353 virtual void Build(); 354 virtual void NewProcessor(GUI_Processor *gp); 355 virtual void Update(); 356 virtual void NewModule(Module *module); 357 virtual void NodeConfigurationChanged(Stimulus_Node *node); 358 359 void draw_nodes(); 360 void update_board_matrix(); 361 void clear_nodes(); 362 363 GtkWidget *status_line; 364 365 private: 366 GtkWidget *bb_vbox(); 367 GtkWidget *bb_hbox(); 368 GtkWidget *add_button(const char *label, GCallback f, GtkWidget *box); 369 370 static void pointer_cb(GtkWidget *w, GdkEventButton *event, 371 Breadboard_Window *bbw); 372 static void remove_module(GtkWidget *button, Breadboard_Window *bbw); 373 374 GuiModule *m_MainCpuModule; 375 376 static gboolean layout_expose(GtkWidget *widget, 377 GdkEventExpose *event, Breadboard_Window *bbw); 378 }; 379 380 381 #endif // GUI_GUI_BREADBOARD_H_ 382 383