PICSimLab - Programmable IC Simulator Laboratory 0.9.3
PICSimLab - API
Loading...
Searching...
No Matches
part.h
1/* ########################################################################
2
3 PICSimLab - Programmable IC Simulator Laboratory
4
5 ########################################################################
6
7 Copyright (c) : 2010-2026 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
36
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 int ReadPreferences(std::string value) = 0;
188
192 virtual int PreferencesNumberFields(void) = 0;
193
197 virtual unsigned short GetInputId(char* name) = 0;
198
202 virtual unsigned short GetOutputId(char* name) = 0;
203
207 virtual void ConfigurePropertiesWindow(void) = 0;
208
212 virtual void ReadPropertiesWindow(void) = 0;
213
217 virtual void ComboChange(const char* controlname, std::string value) {};
218
222 virtual void SpinChange(const char* controlname, int value) {};
223
227 virtual void ButtonEvent(const char* controlname, unsigned int button, unsigned int x, unsigned int y,
228 unsigned int state) {};
229
233 virtual void KeyEvent(const char* controlname, unsigned int keysym, unsigned int ukeysym, unsigned int state) {};
234
238 virtual void Event(const char* controlname) {};
239
243 virtual void filedialog_EvOnClose(int retId) {};
244
248 part(const unsigned x, const unsigned y, const char* name, const char* type, board* pboard_, const int id_,
249 const int fsize = 8);
250
254 void Init(void);
255
259 virtual void PostInit(void) {};
260
264 virtual ~part(void) {};
265
269 int GetBitmap(void) { return BitmapId; };
270
274 int GetX(void) { return X; };
275
279 int GetY(void) { return Y; };
280
284 void SetX(int x) { X = x; };
285
289 void SetY(int y) { Y = y; };
290
294 unsigned int GetWidth(void) { return Width; };
295
299 unsigned int GetHeight(void) { return Height; };
300
304 int PointInside(int x, int y);
305
309 void RotateCoords(unsigned int* x, unsigned int* y);
310
314 virtual void LoadPartImage(void);
315
319 int GetOrientation(void);
320
324 virtual void SetOrientation(int orientation);
325
329 float GetScale(void);
330
334 virtual void SetScale(double scale);
335
339 int GetId(void) { return id; };
340
344 virtual void SetId(int id_) { id = id_; };
345
349 unsigned char GetUpdate(void);
350
354 void SetUpdate(unsigned char upd);
355
359 int GetAlwaysUpdate(void);
360
364 void SetAlwaysUpdate(int sau);
365
366 const int GetPCWCount(void);
367 const PCWProp* GetPCWProperties(void);
368
369 const int GetPinCount(void) { return PinCount; };
370 unsigned char* GetPins(void) { return Pins; };
371 const int GetPinCtrlCount(void) { return PinCtrlCount; };
372 const unsigned char* GetPinsCtrl(void) { return PinsCtrl; };
373
374protected:
378 virtual void RegisterRemoteControl(void) {};
379
380 int id;
381 input_t input[MAX_IDS];
382 input_t* input_ids[MAX_IDS];
383 output_t output[MAX_IDS];
385 int inputc;
387 unsigned int Height;
388 unsigned int Width;
389 int X;
390 int Y;
392 unsigned int refresh;
394 float Scale;
395 unsigned int Update;
397 std::string Type;
398 int PinCount;
399 int PinCtrlCount;
400 unsigned char* Pins;
401 unsigned char* PinsCtrl;
402 board* pboard;
403 int Fsize;
404
408 void ReadMaps(void);
409
413 int PointInside(int x, int y, input_t input);
414
415 void SetPCWProperties(const PCWProp* pcwprop);
416 void SetPCWComboWithPinNames(const char* combo_name, const unsigned char pin);
417 unsigned char GetPWCComboSelectedPin(const char* combo_name);
418
419private:
420 const PCWProp* PCWProperties;
421 int PCWCount;
422 std::string Name;
423
427 void ReadInputMap(std::string fname);
428
432 void ReadOutputMap(std::string fname);
433};
434
435#endif /* PART_H */
436
437#ifndef PARTS_DEFS_H
438#define PARTS_DEFS_H
439
440#define MAX_PARTS 100
441
442extern int NUM_PARTS;
443
444#define part_init(name, function, menu) \
445 static part* function##_create(const unsigned int x, const unsigned int y, board* pboard_, const int id_) { \
446 part* p = new function(x, y, name, menu, pboard_, id_); \
447 p->Init(); \
448 return p; \
449 }; \
450 static void __attribute__((constructor)) function##_init(void); \
451 static void function##_init(void) { \
452 part_register(name, function##_create, menu); \
453 }
454
455typedef part* (*part_create_func)(const unsigned int x, const unsigned int y, board* pboard_, const int id_);
456
457void part_register(const char* name, part_create_func pcreate, const char* menu);
458
459part* create_part(std::string name, const unsigned int x, const unsigned int y, board* pboard_, const int id_);
460
461typedef struct {
462 char name[30];
463 part_create_func pcreate;
464 char menu[30];
465} part_desc;
466
467extern part_desc parts_list[MAX_PARTS];
468
469#endif /* PARTS_DEFS_H */
Board class.
Definition board.h:114
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:396
float GetScale(void)
Return the orientation to draw.
Definition part.cc:369
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:490
virtual void SpinChange(const char *controlname, int value)
Used by properties window spin.
Definition part.h:222
void ReadMaps(void)
read maps
Definition part.cc:67
unsigned int GetHeight(void)
Return height of part.
Definition part.h:299
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:227
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:165
void SetY(int y)
Set Y position of part.
Definition part.h:289
virtual void Event(const char *controlname)
Used by windows of parts.
Definition part.h:238
input_t input[MAX_IDS]
input map elements
Definition part.h:381
int GetBitmap(void)
Return the Bitmap of part.
Definition part.h:269
int Y
Y position of part.
Definition part.h:390
virtual void SetOrientation(int orientation)
Set the orientation to draw.
Definition part.cc:350
virtual std::string GetPictureFileName(void)
Return the filename of part picture.
Definition part.cc:446
virtual void LoadPartImage(void)
Load Part Image.
Definition part.cc:311
virtual ~part(void)
Called once on part destruction.
Definition part.h:264
int GetX(void)
Return X position of part.
Definition part.h:274
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
virtual void SetId(int id_)
Set the part ID.
Definition part.h:344
int GetOrientation(void)
Return the orientation to draw.
Definition part.cc:346
unsigned int Update
part need draw Update
Definition part.h:395
int GetOutputCount(void)
Get part output count.
Definition part.cc:403
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:439
output_t output[MAX_IDS]
output map elements
Definition part.h:383
part(const unsigned x, const unsigned y, const char *name, const char *type, board *pboard_, const int id_, const int fsize=8)
Called once on part creation.
Definition part.cc:30
virtual int ReadPreferences(std::string value)=0
Called whe configuration file load preferences, return the number of preferences processed.
input_t * input_ids[MAX_IDS]
input map elements by id order
Definition part.h:382
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:217
void SetAlwaysUpdate(int sau)
Set if part need to be update every clock cycle.
Definition part.cc:494
virtual void filedialog_EvOnClose(int retId)
Used by properties window filedialogs.
Definition part.h:243
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:384
int Orientation
orientation to draw part
Definition part.h:393
int GetInputCount(void)
Get part input count.
Definition part.cc:392
virtual std::string GetAboutInfo(void)=0
Return the about information of part.
int GetId(void)
Get the part ID.
Definition part.h:339
int BitmapId
Internal Bitmap.
Definition part.h:391
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:259
unsigned int Width
Width of part.
Definition part.h:388
void RotateCoords(unsigned int *x, unsigned int *y)
Return coords x y rotated by orientation.
Definition part.cc:414
int PointInside(int x, int y)
Return if point x,y is inside of part.
Definition part.cc:240
virtual void Reset(void)
Reset part status.
Definition part.h:129
int id
part ID
Definition part.h:380
unsigned int Height
Height of part.
Definition part.h:387
unsigned int refresh
redraw is needed
Definition part.h:392
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:373
void Draw(void)
Called ever 100ms to draw part.
Definition part.cc:538
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:534
virtual std::string GetPropertiesWindowFile(void)
Return the filename of properties window XML file.
Definition part.cc:454
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:458
unsigned int GetWidth(void)
Return width of part.
Definition part.h:294
int GetY(void)
Return Y position of part.
Definition part.h:279
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:450
void EvMouseButtonPress(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.cc:562
int outputc
output map elements counter
Definition part.h:386
int X
X position of part.
Definition part.h:389
virtual int PreferencesNumberFields(void)=0
Return the number of fields in preferences.
void EvMouseButtonRelease(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.cc:573
void EvMouseMove(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.cc:584
output_t * GetOutput(int n)
Get part input.
Definition part.cc:407
unsigned char GetUpdate(void)
Return if part need Draw update.
Definition part.cc:435
input_t * GetInput(int n)
Get part input.
Definition part.cc:396
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:284
virtual void RegisterRemoteControl(void)
Register remote control variables.
Definition part.h:378
float Scale
scale to draw part
Definition part.h:394
int inputc
input map elements counter
Definition part.h:385
virtual void KeyEvent(const char *controlname, unsigned int keysym, unsigned int ukeysym, unsigned int state)
Used by windows of parts.
Definition part.h:233
Definition part.h:39
input map struct
Definition board.h:46
output map struct
Definition board.h:68
Definition part.h:461