Skip to content

Commit

Permalink
chg: Code refactor - Remove direct use of Wprop window !minor
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Jan 31, 2024
1 parent 8423dc3 commit e54291e
Show file tree
Hide file tree
Showing 128 changed files with 1,565 additions and 1,361 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PACKAGE=picsimlab
MAINVER=0
MINORVER=9
VERSION=0.9.1
DATE=240129
DATE=240131
VERSION_STABLE=0.9.1
31 changes: 10 additions & 21 deletions src/lib/part.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,34 +510,23 @@ const PCWProp* part::GetPCWProperties(void) {
return PCWProperties;
}

void part::SetPCWComboWithPinNames(CPWindow* WProp, const char* combo_name, const unsigned char pin) {
void part::SetPCWComboWithPinNames(const char* combo_name, const unsigned char pin) {
std::string spin;

CCombo* combo = (CCombo*)WProp->GetChildByName(combo_name);
SpareParts.WPropCmd(combo_name, WPA_COMBOSETITEMS, SpareParts.GetPinsNames().c_str());

if (combo) {
combo->SetItems(SpareParts.GetPinsNames());
if (pin == 0)
combo->SetText("0 NC");
else {
spin = SpareParts.GetPinName(pin);
combo->SetText(std::to_string(pin) + " " + spin);
}
if (pin == 0) {
SpareParts.WPropCmd(combo_name, WPA_COMBOSETTEXT, "0 NC");
} else {
printf("PICSimLab: Combo (%s) not found in Part Configuration Window!\n", combo_name);
spin = SpareParts.GetPinName(pin);
SpareParts.WPropCmd(combo_name, WPA_COMBOSETTEXT, (std::to_string(pin) + " " + spin).c_str());
}
}

unsigned char part::GetPWCComboSelectedPin(CPWindow* WProp, const char* combo_name) {
int selectedpin = 0;
CCombo* combo = (CCombo*)WProp->GetChildByName(combo_name);

if (combo) {
selectedpin = atoi(combo->GetText());
} else {
printf("PICSimLab: Combo (%s) not found in Part Configuration Window!\n", combo_name);
}
return selectedpin;
unsigned char part::GetPWCComboSelectedPin(const char* combo_name) {
char buff[64];
SpareParts.WPropCmd(combo_name, WPA_COMBOGETTEXT, NULL, buff);
return atoi(buff);
}

std::string part::GetName(void) {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/part.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ class part {
/**
* @brief Called to configure the properties window
*/
virtual void ConfigurePropertiesWindow(CPWindow* WProp) = 0;
virtual void ConfigurePropertiesWindow(void) = 0;

/**
* @brief Called when properties window close
*/
virtual void ReadPropertiesWindow(CPWindow* WProp) = 0;
virtual void ReadPropertiesWindow(void) = 0;

/**
* @brief Used by properties window combos
Expand Down Expand Up @@ -399,8 +399,8 @@ class part {
int PointInside(int x, int y, input_t input);

void SetPCWProperties(const PCWProp* pcwprop);
void SetPCWComboWithPinNames(CPWindow* WProp, const char* combo_name, const unsigned char pin);
unsigned char GetPWCComboSelectedPin(CPWindow* WProp, const char* combo_name);
void SetPCWComboWithPinNames(const char* combo_name, const unsigned char pin);
unsigned char GetPWCComboSelectedPin(const char* combo_name);

private:
const PCWProp* PCWProperties;
Expand Down
12 changes: 9 additions & 3 deletions src/lib/spareparts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ CSpareParts::CSpareParts() {
fdtype = -1;
PartOnDraw = -1;

PropButtonRelease = NULL;
PropComboChange = NULL;
PropSpinChange = NULL;
PartEvent = NULL;
PartKeyEvent = NULL;
PartButtonEvent = NULL;

OnCanvasCmd = NULL;
OnWPropCmd = NULL;
}

void CSpareParts::Init(CWindow* win) {
Expand Down Expand Up @@ -678,4 +676,12 @@ int CSpareParts::CanvasCmd(const CanvasCmd_t cmd) {
return (*SpareParts.OnCanvasCmd)(cmd);
}
return -1;
}

int CSpareParts::WPropCmd(const char* ControlName, const PICSimLabWPropAction action, const char* Value,
void* ReturnBuff) {
if (SpareParts.OnWPropCmd) {
return (*SpareParts.OnWPropCmd)(ControlName, action, Value, ReturnBuff);
}
return -1;
}
43 changes: 38 additions & 5 deletions src/lib/spareparts.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,39 @@

#define IOINIT 110

enum PICSimLabWPropAction {
WPA_COMBOSETITEMS,
WPA_COMBOSETTEXT,
WPA_COMBOGETTEXT,
WPA_SPINDSETMAX,
WPA_SPINDSETMIN,
WPA_SPINDSETVALUE,
WPA_SPINDGETVALUE,
WPA_SPINSETMAX,
WPA_SPINSETMIN,
WPA_SPINSETVALUE,
WPA_SPINGETVALUE,

WPA_TEXTCLEAR,
WPA_TEXTADDLINE,
WPA_TEXTGETLINE,
WPA_TEXTGETLINECOUNT,

WPA_EDITSETTEXT,
WPA_EDITGETTEXT,

WPA_LABELSETTEXT,

WPA_SETENABLE,
WPA_SETWIDTH,
WPA_SETHEIGHT,
WPA_SETVISIBLE,
WPA_SETX,
WPA_SETY,

WPA_LAST,
};

class CSpareParts {
public:
CSpareParts();
Expand Down Expand Up @@ -95,11 +128,6 @@ class CSpareParts {
CFileDialog* GetFileDialog(void) { return filedialog; }
void Reset(void);

void (CControl::*PropButtonRelease)(CControl* control, const uint button, const uint x, const uint y,
const uint mask);
void (CControl::*PropComboChange)(CControl* control);
void (CControl::*PropSpinChange)(CControl* control);

void (CControl::*PartButtonEvent)(CControl* control, const uint button, const uint x, const uint y,
const uint mask);
void (CControl::*PartEvent)(CControl* control);
Expand All @@ -126,8 +154,13 @@ class CSpareParts {

static int CanvasCmd(const CanvasCmd_t cmd);

static int WPropCmd(const char* ControlName, const PICSimLabWPropAction action, const char* Value,
void* ReturnBuff = NULL);

int (*OnCanvasCmd)(const CanvasCmd_t cmd);

int (*OnWPropCmd)(const char* ControlName, const PICSimLabWPropAction action, const char* Value, void* ReturnBuff);

private:
float scale;
board* pboard;
Expand Down
28 changes: 14 additions & 14 deletions src/parts/input_ADXL345.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,22 @@ void cpart_ADXL345::ReadPreferences(std::string value) {
Reset();
}

void cpart_ADXL345::ConfigurePropertiesWindow(CPWindow* WProp) {
SetPCWComboWithPinNames(WProp, "combo3", adxl_pins[0]);
SetPCWComboWithPinNames(WProp, "combo4", adxl_pins[1]);
SetPCWComboWithPinNames(WProp, "combo5", adxl_pins[2]);
SetPCWComboWithPinNames(WProp, "combo6", adxl_pins[3]);
SetPCWComboWithPinNames(WProp, "combo7", adxl_pins[4]);
SetPCWComboWithPinNames(WProp, "combo8", adxl_pins[5]);
void cpart_ADXL345::ConfigurePropertiesWindow(void) {
SetPCWComboWithPinNames("combo3", adxl_pins[0]);
SetPCWComboWithPinNames("combo4", adxl_pins[1]);
SetPCWComboWithPinNames("combo5", adxl_pins[2]);
SetPCWComboWithPinNames("combo6", adxl_pins[3]);
SetPCWComboWithPinNames("combo7", adxl_pins[4]);
SetPCWComboWithPinNames("combo8", adxl_pins[5]);
}

void cpart_ADXL345::ReadPropertiesWindow(CPWindow* WProp) {
adxl_pins[0] = GetPWCComboSelectedPin(WProp, "combo3");
adxl_pins[1] = GetPWCComboSelectedPin(WProp, "combo4");
adxl_pins[2] = GetPWCComboSelectedPin(WProp, "combo5");
adxl_pins[3] = GetPWCComboSelectedPin(WProp, "combo6");
adxl_pins[4] = GetPWCComboSelectedPin(WProp, "combo7");
adxl_pins[5] = GetPWCComboSelectedPin(WProp, "combo8");
void cpart_ADXL345::ReadPropertiesWindow(void) {
adxl_pins[0] = GetPWCComboSelectedPin("combo3");
adxl_pins[1] = GetPWCComboSelectedPin("combo4");
adxl_pins[2] = GetPWCComboSelectedPin("combo5");
adxl_pins[3] = GetPWCComboSelectedPin("combo6");
adxl_pins[4] = GetPWCComboSelectedPin("combo7");
adxl_pins[5] = GetPWCComboSelectedPin("combo8");
}

void cpart_ADXL345::PreProcess(void) {
Expand Down
4 changes: 2 additions & 2 deletions src/parts/input_ADXL345.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class cpart_ADXL345 : public part {
void OnMouseButtonPress(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseButtonRelease(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseMove(uint inputId, uint button, uint x, uint y, uint state) override;
void ConfigurePropertiesWindow(CPWindow* WProp) override;
void ReadPropertiesWindow(CPWindow* WProp) override;
void ConfigurePropertiesWindow(void) override;
void ReadPropertiesWindow(void) override;
std::string WritePreferences(void) override;
void ReadPreferences(std::string value) override;
unsigned short GetInputId(char* name) override;
Expand Down
19 changes: 10 additions & 9 deletions src/parts/input_LDR.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,20 @@ void cpart_LDR::ReadPreferences(std::string value_) {
sscanf(value_.c_str(), "%hhu,%hhu,%hhu,%f", &output_pins[0], &output_pins[1], &value, &vthreshold);
}

void cpart_LDR::ConfigurePropertiesWindow(CPWindow* WProp) {
SetPCWComboWithPinNames(WProp, "combo2", output_pins[0]);
SetPCWComboWithPinNames(WProp, "combo3", output_pins[1]);
void cpart_LDR::ConfigurePropertiesWindow(void) {
SetPCWComboWithPinNames("combo2", output_pins[0]);
SetPCWComboWithPinNames("combo3", output_pins[1]);

((CSpind*)WProp->GetChildByName("spind5"))->SetMax(vmax);
((CSpind*)WProp->GetChildByName("spind5"))->SetValue(vthreshold);
SpareParts.WPropCmd("spind5", WPA_SPINDSETMAX, std::to_string(vmax).c_str());
SpareParts.WPropCmd("spind5", WPA_SPINDSETMIN, "0");
SpareParts.WPropCmd("spind5", WPA_SPINDSETVALUE, std::to_string(vthreshold).c_str());
}

void cpart_LDR::ReadPropertiesWindow(CPWindow* WProp) {
output_pins[0] = GetPWCComboSelectedPin(WProp, "combo2");
output_pins[1] = GetPWCComboSelectedPin(WProp, "combo3");
void cpart_LDR::ReadPropertiesWindow(void) {
output_pins[0] = GetPWCComboSelectedPin("combo2");
output_pins[1] = GetPWCComboSelectedPin("combo3");

vthreshold = ((CSpind*)WProp->GetChildByName("spind5"))->GetValue();
SpareParts.WPropCmd("spind5", WPA_SPINDGETVALUE, NULL, &vthreshold);
}

part_init(PART_LDR_Name, cpart_LDR, "Input");
4 changes: 2 additions & 2 deletions src/parts/input_LDR.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class cpart_LDR : public part {
void OnMouseButtonPress(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseButtonRelease(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseMove(uint inputId, uint button, uint x, uint y, uint state) override;
void ConfigurePropertiesWindow(CPWindow* WProp) override;
void ReadPropertiesWindow(CPWindow* WProp) override;
void ConfigurePropertiesWindow(void) override;
void ReadPropertiesWindow(void) override;
std::string WritePreferences(void) override;
void ReadPreferences(std::string value) override;
void Reset(void) override;
Expand Down
28 changes: 14 additions & 14 deletions src/parts/input_MPU6050.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,22 +241,22 @@ void cpart_MPU6050::ReadPreferences(std::string value) {
Reset();
}

void cpart_MPU6050::ConfigurePropertiesWindow(CPWindow* WProp) {
SetPCWComboWithPinNames(WProp, "combo3", mpu_pins[0]);
SetPCWComboWithPinNames(WProp, "combo4", mpu_pins[1]);
SetPCWComboWithPinNames(WProp, "combo5", mpu_pins[2]);
SetPCWComboWithPinNames(WProp, "combo6", mpu_pins[3]);
SetPCWComboWithPinNames(WProp, "combo7", mpu_pins[4]);
SetPCWComboWithPinNames(WProp, "combo8", mpu_pins[5]);
void cpart_MPU6050::ConfigurePropertiesWindow(void) {
SetPCWComboWithPinNames("combo3", mpu_pins[0]);
SetPCWComboWithPinNames("combo4", mpu_pins[1]);
SetPCWComboWithPinNames("combo5", mpu_pins[2]);
SetPCWComboWithPinNames("combo6", mpu_pins[3]);
SetPCWComboWithPinNames("combo7", mpu_pins[4]);
SetPCWComboWithPinNames("combo8", mpu_pins[5]);
}

void cpart_MPU6050::ReadPropertiesWindow(CPWindow* WProp) {
mpu_pins[0] = GetPWCComboSelectedPin(WProp, "combo3");
mpu_pins[1] = GetPWCComboSelectedPin(WProp, "combo4");
mpu_pins[2] = GetPWCComboSelectedPin(WProp, "combo5");
mpu_pins[3] = GetPWCComboSelectedPin(WProp, "combo6");
mpu_pins[4] = GetPWCComboSelectedPin(WProp, "combo7");
mpu_pins[5] = GetPWCComboSelectedPin(WProp, "combo8");
void cpart_MPU6050::ReadPropertiesWindow(void) {
mpu_pins[0] = GetPWCComboSelectedPin("combo3");
mpu_pins[1] = GetPWCComboSelectedPin("combo4");
mpu_pins[2] = GetPWCComboSelectedPin("combo5");
mpu_pins[3] = GetPWCComboSelectedPin("combo6");
mpu_pins[4] = GetPWCComboSelectedPin("combo7");
mpu_pins[5] = GetPWCComboSelectedPin("combo8");
}

void cpart_MPU6050::PreProcess(void) {
Expand Down
4 changes: 2 additions & 2 deletions src/parts/input_MPU6050.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class cpart_MPU6050 : public part {
void OnMouseButtonPress(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseButtonRelease(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseMove(uint inputId, uint button, uint x, uint y, uint state) override;
void ConfigurePropertiesWindow(CPWindow* WProp) override;
void ReadPropertiesWindow(CPWindow* WProp) override;
void ConfigurePropertiesWindow(void) override;
void ReadPropertiesWindow(void) override;
std::string WritePreferences(void) override;
void ReadPreferences(std::string value) override;
unsigned short GetInputId(char* name) override;
Expand Down
12 changes: 6 additions & 6 deletions src/parts/input_bmp180.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ void cpart_bmp180::ReadPreferences(std::string value_) {
Reset();
}

void cpart_bmp180::ConfigurePropertiesWindow(CPWindow* WProp) {
SetPCWComboWithPinNames(WProp, "combo1", input_pins[0]);
SetPCWComboWithPinNames(WProp, "combo2", input_pins[1]);
void cpart_bmp180::ConfigurePropertiesWindow(void) {
SetPCWComboWithPinNames("combo1", input_pins[0]);
SetPCWComboWithPinNames("combo2", input_pins[1]);
}

void cpart_bmp180::ReadPropertiesWindow(CPWindow* WProp) {
input_pins[0] = GetPWCComboSelectedPin(WProp, "combo1");
input_pins[1] = GetPWCComboSelectedPin(WProp, "combo2");
void cpart_bmp180::ReadPropertiesWindow(void) {
input_pins[0] = GetPWCComboSelectedPin("combo1");
input_pins[1] = GetPWCComboSelectedPin("combo2");
}

void cpart_bmp180::PreProcess(void) {
Expand Down
4 changes: 2 additions & 2 deletions src/parts/input_bmp180.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class cpart_bmp180 : public part {
void OnMouseButtonPress(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseButtonRelease(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseMove(uint inputId, uint button, uint x, uint y, uint state) override;
void ConfigurePropertiesWindow(CPWindow* WProp) override;
void ReadPropertiesWindow(CPWindow* WProp) override;
void ConfigurePropertiesWindow(void) override;
void ReadPropertiesWindow(void) override;
std::string WritePreferences(void) override;
void ReadPreferences(std::string value) override;
unsigned short GetInputId(char* name) override;
Expand Down
20 changes: 10 additions & 10 deletions src/parts/input_bmp280.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,18 @@ void cpart_bmp280::ReadPreferences(std::string value_) {
Reset();
}

void cpart_bmp280::ConfigurePropertiesWindow(CPWindow* WProp) {
SetPCWComboWithPinNames(WProp, "combo3", input_pins[0]);
SetPCWComboWithPinNames(WProp, "combo4", input_pins[1]);
SetPCWComboWithPinNames(WProp, "combo5", input_pins[2]);
SetPCWComboWithPinNames(WProp, "combo6", output_pins[0]);
void cpart_bmp280::ConfigurePropertiesWindow(void) {
SetPCWComboWithPinNames("combo3", input_pins[0]);
SetPCWComboWithPinNames("combo4", input_pins[1]);
SetPCWComboWithPinNames("combo5", input_pins[2]);
SetPCWComboWithPinNames("combo6", output_pins[0]);
}

void cpart_bmp280::ReadPropertiesWindow(CPWindow* WProp) {
input_pins[0] = GetPWCComboSelectedPin(WProp, "combo3");
input_pins[1] = GetPWCComboSelectedPin(WProp, "combo4");
input_pins[2] = GetPWCComboSelectedPin(WProp, "combo5");
output_pins[0] = GetPWCComboSelectedPin(WProp, "combo6");
void cpart_bmp280::ReadPropertiesWindow(void) {
input_pins[0] = GetPWCComboSelectedPin("combo3");
input_pins[1] = GetPWCComboSelectedPin("combo4");
input_pins[2] = GetPWCComboSelectedPin("combo5");
output_pins[0] = GetPWCComboSelectedPin("combo6");
}

void cpart_bmp280::PreProcess(void) {
Expand Down
4 changes: 2 additions & 2 deletions src/parts/input_bmp280.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class cpart_bmp280 : public part {
void OnMouseButtonPress(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseButtonRelease(uint inputId, uint button, uint x, uint y, uint state) override;
void OnMouseMove(uint inputId, uint button, uint x, uint y, uint state) override;
void ConfigurePropertiesWindow(CPWindow* WProp) override;
void ReadPropertiesWindow(CPWindow* WProp) override;
void ConfigurePropertiesWindow(void) override;
void ReadPropertiesWindow(void) override;
std::string WritePreferences(void) override;
void ReadPreferences(std::string value) override;
unsigned short GetInputId(char* name) override;
Expand Down
8 changes: 4 additions & 4 deletions src/parts/input_dht11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ void cpart_dht11::ReadPreferences(std::string value_) {
sscanf(value_.c_str(), "%hhu,%hhu,%hhu", &output_pins[0], &values[0], &values[1]);
}

void cpart_dht11::ConfigurePropertiesWindow(CPWindow* WProp) {
SetPCWComboWithPinNames(WProp, "combo2", output_pins[0]);
void cpart_dht11::ConfigurePropertiesWindow(void) {
SetPCWComboWithPinNames("combo2", output_pins[0]);
}

void cpart_dht11::ReadPropertiesWindow(CPWindow* WProp) {
output_pins[0] = GetPWCComboSelectedPin(WProp, "combo2");
void cpart_dht11::ReadPropertiesWindow(void) {
output_pins[0] = GetPWCComboSelectedPin("combo2");
}

part_init(PART_DHT11_Name, cpart_dht11, "Input");
Loading

0 comments on commit e54291e

Please sign in to comment.