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 unsigned char GetUpdate(void);
340
344 void SetUpdate(unsigned char upd);
345
349 int GetAlwaysUpdate(void);
350
354 void SetAlwaysUpdate(int sau);
355
356 const int GetPCWCount(void);
357 const PCWProp* GetPCWProperties(void);
358
359 const int GetPinCount(void) { return PinCount; };
360 unsigned char* GetPins(void) { return Pins; };
361 const int GetPinCtrlCount(void) { return PinCtrlCount; };
362 const unsigned char* GetPinsCtrl(void) { return PinsCtrl; };
363
364protected:
368 virtual void RegisterRemoteControl(void){};
369
370 int id;
371 input_t input[MAX_IDS];
372 input_t* input_ids[MAX_IDS];
373 output_t output[MAX_IDS];
375 int inputc;
377 unsigned int Height;
378 unsigned int Width;
379 int X;
380 int Y;
382 unsigned int refresh;
384 float Scale;
385 unsigned int Update;
387 std::string Type;
388 int PinCount;
389 int PinCtrlCount;
390 unsigned char* Pins;
391 unsigned char* PinsCtrl;
392 board* pboard;
393 int Fsize;
394
398 void ReadMaps(void);
399
403 int PointInside(int x, int y, input_t input);
404
405 void SetPCWProperties(const PCWProp* pcwprop);
406 void SetPCWComboWithPinNames(const char* combo_name, const unsigned char pin);
407 unsigned char GetPWCComboSelectedPin(const char* combo_name);
408
409private:
410 const PCWProp* PCWProperties;
411 int PCWCount;
412 std::string Name;
413
417 void ReadInputMap(std::string fname);
418
422 void ReadOutputMap(std::string fname);
423};
424
425#endif /* PART_H */
426
427#ifndef PARTS_DEFS_H
428#define PARTS_DEFS_H
429
430#define MAX_PARTS 100
431
432extern int NUM_PARTS;
433
434#define part_init(name, function, menu) \
435 static part* function##_create(const unsigned int x, const unsigned int y, board* pboard_, const int id_) { \
436 part* p = new function(x, y, name, menu, pboard_, id_); \
437 p->Init(); \
438 return p; \
439 }; \
440 static void __attribute__((constructor)) function##_init(void); \
441 static void function##_init(void) { \
442 part_register(name, function##_create, menu); \
443 }
444
445typedef part* (*part_create_func)(const unsigned int x, const unsigned int y, board* pboard_, const int id_);
446
447void part_register(const char* name, part_create_func pcreate, const char* menu);
448
449part* create_part(std::string name, const unsigned int x, const unsigned int y, board* pboard_, const int id_);
450
451typedef struct {
452 char name[30];
453 part_create_func pcreate;
454 char menu[30];
455} part_desc;
456
457extern part_desc parts_list[MAX_PARTS];
458
459#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:386
float GetScale(void)
Return the orientation to draw.
Definition part.cc:367
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:489
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:371
int GetBitmap(void)
Return the Bitmap of part.
Definition part.h:264
int Y
Y position of part.
Definition part.h:380
virtual void SetOrientation(int orientation)
Set the orientation to draw.
Definition part.cc:347
virtual std::string GetPictureFileName(void)
Return the filename of part picture.
Definition part.cc:445
virtual void LoadPartImage(void)
Load Part Image.
Definition part.cc:314
virtual ~part(void)
Called once on part destruction.
Definition part.h:259
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:343
unsigned int Update
part need draw Update
Definition part.h:385
int GetOutputCount(void)
Get part output count.
Definition part.cc:402
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:438
output_t output[MAX_IDS]
output map elements
Definition part.h:373
input_t * input_ids[MAX_IDS]
input map elements by id order
Definition part.h:372
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:493
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:374
int Orientation
orientation to draw part
Definition part.h:383
int GetInputCount(void)
Get part input count.
Definition part.cc:391
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:381
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:378
void RotateCoords(unsigned int *x, unsigned int *y)
Return coords x y rotated by orientation.
Definition part.cc:413
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:370
unsigned int Height
Height of part.
Definition part.h:377
unsigned int refresh
redraw is needed
Definition part.h:382
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:371
void Draw(void)
Called ever 100ms to draw part.
Definition part.cc:537
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:533
virtual std::string GetPropertiesWindowFile(void)
Return the filename of properties window XML file.
Definition part.cc:453
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:457
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:449
void EvMouseButtonPress(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.cc:561
int outputc
output map elements counter
Definition part.h:376
int X
X position of part.
Definition part.h:379
void EvMouseButtonRelease(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.cc:572
void EvMouseMove(unsigned int button, unsigned int x, unsigned int y, unsigned int state)
Event handler on the part.
Definition part.cc:583
output_t * GetOutput(int n)
Get part input.
Definition part.cc:406
unsigned char GetUpdate(void)
Return if part need Draw update.
Definition part.cc:434
input_t * GetInput(int n)
Get part input.
Definition part.cc:395
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:368
float Scale
scale to draw part
Definition part.h:384
int inputc
input map elements counter
Definition part.h:375
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:451