PICSimLab - Programmable IC Simulator Laboratory 0.9.2
PICSimLab - API
Loading...
Searching...
No Matches
part.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2024 Luis Claudio GambĂ´a Lopes <lcgamboa@yahoo.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 For e-mail suggestions : lcgamboa@yahoo.com
24 ######################################################################## */
25
26#ifndef PART_H
27#define PART_H
28
29#include "board.h"
30
37enum { PCW_END, PCW_COMBO, PCW_LABEL, PCW_SPIND, PCW_EDIT, PCW_SPIN, PCW_TEXT, PCW_DCOMBO };
38
39typedef struct {
40 int pcw_type;
41 char label[20];
42} PCWProp;
43
49class part {
50public:
54 std::string GetName(void);
55
59 virtual std::string GetHelpURL(void);
60
64 virtual std::string GetAboutInfo(void) = 0;
65
69 void Draw(void);
70
74 virtual void DrawOutput(const unsigned int index) = 0;
75
79 virtual void PreProcess(void) {};
80
84 virtual void Process(void) {};
85
89 virtual void PostProcess(void) {};
90
94 virtual std::string GetPictureFileName(void);
95
99 virtual std::string GetMapFile(void);
100
104 virtual std::string GetPropertiesWindowFile(void);
105
109 int GetInputCount(void);
110
114 input_t* GetInput(int n);
115
119 int GetOutputCount(void);
120
124 output_t* GetOutput(int n);
125
129 virtual void Reset(void) {};
130
134 virtual void Stop(void) {};
135
139 void EvMouseButtonPress(unsigned int button, unsigned int x, unsigned int y, unsigned int state);
140
144 virtual void OnMouseButtonPress(unsigned int inputId, unsigned int button, unsigned int x, unsigned int y,
145 unsigned int state) {};
146
150 void EvMouseButtonRelease(unsigned int button, unsigned int x, unsigned int y, unsigned int state);
151
155 virtual void OnMouseButtonRelease(unsigned int inputId, unsigned int button, unsigned int x, unsigned int y,
156 unsigned int state) {};
157
161 void EvMouseMove(unsigned int button, unsigned int x, unsigned int y, unsigned int state);
162
166 virtual void OnMouseMove(unsigned int inputId, unsigned int button, unsigned int x, unsigned int y,
167 unsigned int state) {};
168
172 virtual void EvKeyPress(unsigned int key, unsigned int mask) {};
173
177 virtual void EvKeyRelease(unsigned int key, unsigned int mask) {};
178
182 virtual std::string WritePreferences(void) = 0;
183
187 virtual void ReadPreferences(std::string value) = 0;
188
192 virtual unsigned short GetInputId(char* name) = 0;
193
197 virtual unsigned short GetOutputId(char* name) = 0;
198
202 virtual void ConfigurePropertiesWindow(void) = 0;
203
207 virtual void ReadPropertiesWindow(void) = 0;
208
212 virtual void ComboChange(const char* controlname, std::string value) {};
213
217 virtual void SpinChange(const char* controlname, int value) {};
218
222 virtual void ButtonEvent(const char* controlname, unsigned int button, unsigned int x, unsigned int y,
223 unsigned int state) {};
224
228 virtual void KeyEvent(const char* controlname, unsigned int keysym, unsigned int ukeysym, unsigned int state) {};
229
233 virtual void Event(const char* controlname) {};
234
238 virtual void filedialog_EvOnClose(int retId) {};
239
243 part(const unsigned x, const unsigned y, const char* name, const char* type, board* pboard_, const int id_,
244 const int fsize = 8);
245
249 void Init(void);
250
254 virtual void PostInit(void) {};
255
259 virtual ~part(void) {};
260
264 int GetBitmap(void) { return BitmapId; };
265
269 int GetX(void) { return X; };
270
274 int GetY(void) { return Y; };
275
279 void SetX(int x) { X = x; };
280
284 void SetY(int y) { Y = y; };
285
289 unsigned int GetWidth(void) { return Width; };
290
294 unsigned int GetHeight(void) { return Height; };
295
299 int PointInside(int x, int y);
300
304 void RotateCoords(unsigned int* x, unsigned int* y);
305
309 virtual void LoadPartImage(void);
310
314 int GetOrientation(void);
315
319 virtual void SetOrientation(int orientation);
320
324 float GetScale(void);
325
329 virtual void SetScale(double scale);
330
334 int GetId(void) { return id; };
335
339 void SetId(int id_) { id = id_; };
340
344 unsigned char GetUpdate(void);
345
349 void SetUpdate(unsigned char upd);
350
354 int GetAlwaysUpdate(void);
355
359 void SetAlwaysUpdate(int sau);
360
361 const int GetPCWCount(void);
362 const PCWProp* GetPCWProperties(void);
363
364 const int GetPinCount(void) { return PinCount; };
365 unsigned char* GetPins(void) { return Pins; };
366 const int GetPinCtrlCount(void) { return PinCtrlCount; };
367 const unsigned char* GetPinsCtrl(void) { return PinsCtrl; };
368
369protected:
373 virtual void RegisterRemoteControl(void) {};
374
375 int id;
376 input_t input[MAX_IDS];
377 input_t* input_ids[MAX_IDS];
378 output_t output[MAX_IDS];
380 int inputc;
382 unsigned int Height;
383 unsigned int Width;
384 int X;
385 int Y;
387 unsigned int refresh;
389 float Scale;
390 unsigned int Update;
392 std::string Type;
393 int PinCount;
394 int PinCtrlCount;
395 unsigned char* Pins;
396 unsigned char* PinsCtrl;
397 board* pboard;
398 int Fsize;
399
403 void ReadMaps(void);
404
408 int PointInside(int x, int y, input_t input);
409
410 void SetPCWProperties(const PCWProp* pcwprop);
411 void SetPCWComboWithPinNames(const char* combo_name, const unsigned char pin);
412 unsigned char GetPWCComboSelectedPin(const char* combo_name);
413
414private:
415 const PCWProp* PCWProperties;
416 int PCWCount;
417 std::string Name;
418
422 void ReadInputMap(std::string fname);
423
427 void ReadOutputMap(std::string fname);
428};
429
430#endif /* PART_H */
431
432#ifndef PARTS_DEFS_H
433#define PARTS_DEFS_H
434
435#define MAX_PARTS 100
436
437extern int NUM_PARTS;
438
439#define part_init(name, function, menu) \
440 static part* function##_create(const unsigned int x, const unsigned int y, board* pboard_, const int id_) { \
441 part* p = new function(x, y, name, menu, pboard_, id_); \
442 p->Init(); \
443 return p; \
444 }; \
445 static void __attribute__((constructor)) function##_init(void); \
446 static void function##_init(void) { \
447 part_register(name, function##_create, menu); \
448 }
449
450typedef part* (*part_create_func)(const unsigned int x, const unsigned int y, board* pboard_, const int id_);
451
452void part_register(const char* name, part_create_func pcreate, const char* menu);
453
454part* create_part(std::string name, const unsigned int x, const unsigned int y, board* pboard_, const int id_);
455
456typedef struct {
457 char name[30];
458 part_create_func pcreate;
459 char menu[30];
460} part_desc;
461
462extern part_desc parts_list[MAX_PARTS];
463
464#endif /* PARTS_DEFS_H */
Board class.
Definition board.h:111
PART class.
Definition part.h:49
virtual void ConfigurePropertiesWindow(void)=0
Called to configure the properties window.
int always_update
part need to be update every clock cycle
Definition part.h:391
float GetScale(void)
Return the orientation to draw.
Definition part.cc:373
virtual void ReadPropertiesWindow(void)=0
Called when properties window close.
int GetAlwaysUpdate(void)
Return if part need to be update every clock cycle.
Definition part.cc:495
virtual void ReadPreferences(std::string value)=0
Called whe configuration file load preferences.
virtual void SpinChange(const char *controlname, int value)
Used by properties window spin.
Definition part.h:217
void ReadMaps(void)
read maps
Definition part.cc:67
unsigned int GetHeight(void)
Return height of part.
Definition part.h:294
virtual void ButtonEvent(const char *controlname, unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Used by windows of parts.
Definition part.h:222
virtual void OnMouseButtonRelease(unsigned int inputId, unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.h:155
virtual void Process(void)
Called every CPU step.
Definition part.h:84
void ReadOutputMap(std::string fname)
Read the Output Map.
Definition part.cc:166
void SetY(int y)
Set Y position of part.
Definition part.h:284
virtual void Event(const char *controlname)
Used by windows of parts.
Definition part.h:233
input_t input[MAX_IDS]
input map elements
Definition part.h:376
int GetBitmap(void)
Return the Bitmap of part.
Definition part.h:264
int Y
Y position of part.
Definition part.h:385
virtual void SetOrientation(int orientation)
Set the orientation to draw.
Definition part.cc:353
virtual std::string GetPictureFileName(void)
Return the filename of part picture.
Definition part.cc:451
virtual void LoadPartImage(void)
Load Part Image.
Definition part.cc:314
virtual ~part(void)
Called once on part destruction.
Definition part.h:259
void SetId(int id_)
Set the part ID.
Definition part.h:339
int GetX(void)
Return X position of part.
Definition part.h:269
virtual void PostProcess(void)
Called every end of CPU process.
Definition part.h:89
virtual void Stop(void)
Stop part simulation.
Definition part.h:134
int GetOrientation(void)
Return the orientation to draw.
Definition part.cc:349
unsigned int Update
part need draw Update
Definition part.h:390
int GetOutputCount(void)
Get part output count.
Definition part.cc:408
virtual void EvKeyPress(unsigned int key, unsigned int mask)
Event handler on the part.
Definition part.h:172
void SetUpdate(unsigned char upd)
Set part to Draw update.
Definition part.cc:444
output_t output[MAX_IDS]
output map elements
Definition part.h:378
input_t * input_ids[MAX_IDS]
input map elements by id order
Definition part.h:377
virtual unsigned short GetOutputId(char *name)=0
return the output ids numbers of names used in output map
virtual void ComboChange(const char *controlname, std::string value)
Used by properties window combos.
Definition part.h:212
void SetAlwaysUpdate(int sau)
Set if part need to be update every clock cycle.
Definition part.cc:499
virtual void filedialog_EvOnClose(int retId)
Used by properties window filedialogs.
Definition part.h:238
virtual void EvKeyRelease(unsigned int key, unsigned int mask)
Event handler on the part.
Definition part.h:177
output_t * output_ids[MAX_IDS]
output map elements by id order
Definition part.h:379
int Orientation
orientation to draw part
Definition part.h:388
int GetInputCount(void)
Get part input count.
Definition part.cc:397
virtual std::string GetAboutInfo(void)=0
Return the about information of part.
int GetId(void)
Get the part ID.
Definition part.h:334
int BitmapId
Internal Bitmap.
Definition part.h:386
virtual unsigned short GetInputId(char *name)=0
return the input ids numbers of names used in input map
virtual void PostInit(void)
Called once on part after initialization.
Definition part.h:254
unsigned int Width
Width of part.
Definition part.h:383
void RotateCoords(unsigned int *x, unsigned int *y)
Return coords x y rotated by orientation.
Definition part.cc:419
int PointInside(int x, int y)
Return if point x,y is inside of part.
Definition part.cc:243
virtual void Reset(void)
Reset part status.
Definition part.h:129
int id
part ID
Definition part.h:375
unsigned int Height
Height of part.
Definition part.h:382
unsigned int refresh
redraw is needed
Definition part.h:387
virtual void DrawOutput(const unsigned int index)=0
Called to draw every output.
virtual void SetScale(double scale)
Set the orientation to draw.
Definition part.cc:377
void Draw(void)
Called ever 100ms to draw part.
Definition part.cc:543
void ReadInputMap(std::string fname)
Read the Input Map.
Definition part.cc:82
std::string GetName(void)
Return the name of part.
Definition part.cc:539
virtual std::string GetPropertiesWindowFile(void)
Return the filename of properties window XML file.
Definition part.cc:459
virtual void PreProcess(void)
Called every start of CPU process.
Definition part.h:79
virtual std::string GetHelpURL(void)
Return the help url of part.
Definition part.cc:463
unsigned int GetWidth(void)
Return width of part.
Definition part.h:289
int GetY(void)
Return Y position of part.
Definition part.h:274
void Init(void)
Called once on part initialization.
Definition part.cc:58
virtual void OnMouseButtonPress(unsigned int inputId, unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.h:144
virtual void OnMouseMove(unsigned int inputId, unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.h:166
virtual std::string GetMapFile(void)
Return the filename of part picture map.
Definition part.cc:455
void EvMouseButtonPress(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.cc:567
int outputc
output map elements counter
Definition part.h:381
int X
X position of part.
Definition part.h:384
void EvMouseButtonRelease(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.cc:578
void EvMouseMove(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.cc:589
output_t * GetOutput(int n)
Get part input.
Definition part.cc:412
unsigned char GetUpdate(void)
Return if part need Draw update.
Definition part.cc:440
input_t * GetInput(int n)
Get part input.
Definition part.cc:401
virtual std::string WritePreferences(void)=0
Called to save part preferences in configuration file.
void SetX(int x)
Set X position of part.
Definition part.h:279
virtual void RegisterRemoteControl(void)
Register remote control variables.
Definition part.h:373
float Scale
scale to draw part
Definition part.h:389
int inputc
input map elements counter
Definition part.h:380
virtual void KeyEvent(const char *controlname, unsigned int keysym, unsigned int ukeysym, unsigned int state)
Used by windows of parts.
Definition part.h:228
Definition part.h:39
input map struct
Definition board.h:46
output map struct
Definition board.h:68
Definition part.h:456