summaryrefslogtreecommitdiff
path: root/app/bin/cswitchmotor.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/cswitchmotor.c')
-rw-r--r--app/bin/cswitchmotor.c62
1 files changed, 28 insertions, 34 deletions
diff --git a/app/bin/cswitchmotor.c b/app/bin/cswitchmotor.c
index a8e1c54..563e4b8 100644
--- a/app/bin/cswitchmotor.c
+++ b/app/bin/cswitchmotor.c
@@ -49,22 +49,18 @@
*
*/
-#include <ctype.h>
-#include <string.h>
-
#include "compound.h"
+#include "cselect.h"
#include "cundo.h"
#include "custom.h"
#include "fileio.h"
-#include "i18n.h"
#include "param.h"
#include "track.h"
#include "trackx.h"
-#ifdef WINDOWS
+#include "common-ui.h"
+#ifdef UTFCONVERT
#include "include/utf8convert.h"
-#endif // WINDOWS
-#include "utility.h"
-#include "messages.h"
+#endif // UTFCONVERT
EXPORT TRKTYP_T T_SWITCHMOTOR = -1;
@@ -90,13 +86,13 @@ static track_p last_motor;
static track_p first_motor;
static paramData_t switchmotorPLs[] = {
-/*0*/ { PD_STRING, switchmotorName, "name", PDO_NOPREF|PDO_STRINGLIMITLENGTH, (void*)200, N_("Name"), 0, 0, sizeof(switchmotorName)},
-/*1*/ { PD_STRING, switchmotorNormal, "normal", PDO_NOPREF|PDO_STRINGLIMITLENGTH, (void*)350, N_("Normal"), 0, 0, sizeof(switchmotorNormal)},
-/*2*/ { PD_STRING, switchmotorReverse, "reverse", PDO_NOPREF | PDO_STRINGLIMITLENGTH, (void*)350, N_("Reverse"), 0, 0, sizeof(switchmotorReverse)},
-/*3*/ { PD_STRING, switchmotorPointSense, "pointSense", PDO_NOPREF | PDO_STRINGLIMITLENGTH, (void*)350, N_("Point Sense"), 0, 0, sizeof(switchmotorPointSense)}
+/*0*/ { PD_STRING, switchmotorName, "name", PDO_NOPREF|PDO_NOTBLANK, I2VP(200), N_("Name"), 0, 0, sizeof(switchmotorName)},
+/*1*/ { PD_STRING, switchmotorNormal, "normal", PDO_NOPREF, I2VP(350), N_("Normal"), 0, 0, sizeof(switchmotorNormal)},
+/*2*/ { PD_STRING, switchmotorReverse, "reverse", PDO_NOPREF, I2VP(350), N_("Reverse"), 0, 0, sizeof(switchmotorReverse)},
+/*3*/ { PD_STRING, switchmotorPointSense, "pointSense", PDO_NOPREF, I2VP(350), N_("Point Sense"), 0, 0, sizeof(switchmotorPointSense)}
};
-static paramGroup_t switchmotorPG = { "switchmotor", 0, switchmotorPLs, sizeof switchmotorPLs/sizeof switchmotorPLs[0] };
+static paramGroup_t switchmotorPG = { "switchmotor", 0, switchmotorPLs, COUNT( switchmotorPLs ) };
static wWin_p switchmotorW;
static char switchmotorEditName[STR_SHORT_SIZE];
@@ -109,14 +105,14 @@ static track_p switchmotorEditTrack;
static paramIntegerRange_t r0_999999 = { 0, 999999 };
static paramData_t switchmotorEditPLs[] = {
- /*0*/ { PD_STRING, switchmotorEditName, "name", PDO_NOPREF | PDO_STRINGLIMITLENGTH, (void*)200, N_("Name"), 0, 0, sizeof(switchmotorEditName)},
-/*1*/ { PD_STRING, switchmotorEditNormal, "normal", PDO_NOPREF | PDO_STRINGLIMITLENGTH, (void*)350, N_("Normal"), 0, 0, sizeof(switchmotorEditNormal)},
-/*2*/ { PD_STRING, switchmotorEditReverse, "reverse", PDO_NOPREF | PDO_STRINGLIMITLENGTH, (void*)350, N_("Reverse"), 0, 0, sizeof(switchmotorEditReverse)},
-/*3*/ { PD_STRING, switchmotorEditPointSense, "pointSense", PDO_NOPREF | PDO_STRINGLIMITLENGTH, (void*)350, N_("Point Sense"), 0, 0, sizeof(switchmotorEditPointSense)},
+ /*0*/ { PD_STRING, switchmotorEditName, "name", PDO_NOPREF | PDO_NOTBLANK, I2VP(200), N_("Name"), 0, 0, sizeof(switchmotorEditName)},
+/*1*/ { PD_STRING, switchmotorEditNormal, "normal", PDO_NOPREF, I2VP(350), N_("Normal"), 0, 0, sizeof(switchmotorEditNormal)},
+/*2*/ { PD_STRING, switchmotorEditReverse, "reverse", PDO_NOPREF, I2VP(350), N_("Reverse"), 0, 0, sizeof(switchmotorEditReverse)},
+/*3*/ { PD_STRING, switchmotorEditPointSense, "pointSense", PDO_NOPREF, I2VP(350), N_("Point Sense"), 0, 0, sizeof(switchmotorEditPointSense)},
/*4*/ { PD_LONG, &switchmotorEditTonum, "turnoutNumber", PDO_NOPREF, &r0_999999, N_("Turnout Number"), BO_READONLY },
};
-static paramGroup_t switchmotorEditPG = { "switchmotorEdit", 0, switchmotorEditPLs, sizeof switchmotorEditPLs/sizeof switchmotorEditPLs[0] };
+static paramGroup_t switchmotorEditPG = { "switchmotorEdit", 0, switchmotorEditPLs, COUNT( switchmotorEditPLs ) };
static wWin_p switchmotorEditW;
/*
@@ -125,6 +121,7 @@ static dynArr_t switchmotorTrk_da;
*/
typedef struct switchmotorData_t {
+ extraDataBase_t base;
char * name;
char * normal;
char * reverse;
@@ -137,7 +134,7 @@ typedef struct switchmotorData_t {
static switchmotorData_p GetswitchmotorData ( track_p trk )
{
- return (switchmotorData_p) GetTrkExtraData(trk);
+ return GET_EXTRA_DATA( trk, T_SWITCHMOTOR, switchmotorData_t );
}
#if 0
@@ -148,14 +145,14 @@ static wDrawBitMap_p switchmotormark_bm = NULL;
static coOrd switchmotorPoly_Pix[] = {
{6,0}, {6,13}, {4,13}, {4,19}, {6,19}, {6,23}, {9,23}, {9,19}, {13,19},
{13,23}, {27,23}, {27,10}, {13,10}, {13,13}, {9,13}, {9,0}, {6,0} };
-#define switchmotorPoly_CNT (sizeof(switchmotorPoly_Pix)/sizeof(switchmotorPoly_Pix[0]))
+#define switchmotorPoly_CNT (COUNT(switchmotorPoly_Pix))
#define switchmotorPoly_SF (3.0)
static void ComputeSwitchMotorBoundingBox (track_p t)
{
coOrd hi, lo, p;
switchmotorData_p data_p = GetswitchmotorData(t);
- struct extraData *xx = GetTrkExtraData(data_p->turnout);
+ struct extraDataCompound_t *xx = GET_EXTRA_DATA(data_p->turnout, T_TURNOUT, extraDataCompound_t);
coOrd orig = xx->orig;
ANGLE_T angle = xx->angle;
SCALEINX_T s = GetTrkScale(data_p->turnout);
@@ -190,7 +187,7 @@ static void DrawSwitchMotor (track_p t, drawCmd_p d, wDrawColor color )
{
coOrd p[switchmotorPoly_CNT];
switchmotorData_p data_p = GetswitchmotorData(t);
- struct extraData *xx = GetTrkExtraData(data_p->turnout);
+ struct extraDataCompound_t *xx = GET_EXTRA_DATA(data_p->turnout, T_TURNOUT, extraDataCompound_t);
coOrd orig = xx->orig;
ANGLE_T angle = xx->angle;
SCALEINX_T s = GetTrkScale(data_p->turnout);
@@ -208,7 +205,7 @@ static void DrawSwitchMotor (track_p t, drawCmd_p d, wDrawColor color )
Translate (&p[iPoint], orig, x_angle, switchmotorPoly_Pix[iPoint].x * switchmotorPoly_SF / scaleRatio );
Translate (&p[iPoint], p[iPoint], y_angle, (10+switchmotorPoly_Pix[iPoint].y) * switchmotorPoly_SF / scaleRatio );
}
- DrawPoly(d, switchmotorPoly_CNT, p, NULL, color, 0, 1, 0);
+ DrawPoly(d, switchmotorPoly_CNT, p, NULL, color, 0, DRAW_FILL);
}
static struct {
@@ -411,9 +408,9 @@ static BOOL_T WriteSwitchMotor ( track_p t, FILE * f )
switchmotorData_p xx = GetswitchmotorData(t);
char *switchMotorName = MyStrdup(xx->name);
-#ifdef WINDOWS
+#ifdef UTFCONVERT
switchMotorName = Convert2UTF8(switchMotorName);
-#endif // WINDOWS
+#endif // UTFCONVERT
if (xx->turnout == NULL)
return FALSE;
@@ -437,9 +434,9 @@ static BOOL_T ReadSwitchMotor ( char * line )
if (!GetArgs(line+12,"ddqqqq",&index,&trkindex,&name,&normal,&reverse,&pointsense)) {
return FALSE;
}
-#ifdef WINDOWS
+#ifdef UTFCONVERT
ConvertUTF8ToSystem(name);
-#endif // WINDOWS
+#endif // UTFCONVERT
trk = NewTrack(index, T_SWITCHMOTOR, 0, sizeof(switchmotorData_t)+1);
xx = GetswitchmotorData( trk );
xx->name = name;
@@ -592,6 +589,7 @@ static STATUS_T CmdSwitchMotorCreate( wAction_t action, coOrd pos )
switch (action & 0xFF) {
case C_START:
InfoMessage( _("Select a turnout") );
+ SetAllTrackSelect( FALSE );
return C_CONTINUE;
case C_DOWN:
if ((trk = OnTrack(&pos, TRUE, TRUE )) == NULL) {
@@ -694,7 +692,7 @@ static STATUS_T CmdSwitchMotor (wAction_t action, coOrd pos )
LOG( log_switchmotor, 1, ("*** CmdSwitchMotor(%08x,{%f,%f})\n",action,pos.x,pos.y))
- switch ((long)commandContext) {
+ switch (VP2L(commandContext)) {
case SWITCHMOTOR_CREATE: return CmdSwitchMotorCreate(action,pos);
case SWITCHMOTOR_EDIT: return CmdSwitchMotorEdit(action,pos);
case SWITCHMOTOR_DELETE: return CmdSwitchMotorDelete(action,pos);
@@ -757,13 +755,9 @@ static POS_T swmhiliteBorder;
static wDrawColor swmhiliteColor = 0;
static void DrawSWMotorTrackHilite( void )
{
- wPos_t x, y, w, h;
if (swmhiliteColor==0)
swmhiliteColor = wDrawColorGray(87);
- w = (wPos_t)((swmhiliteSize.x/mainD.scale)*mainD.dpi+0.5);
- h = (wPos_t)((swmhiliteSize.y/mainD.scale)*mainD.dpi+0.5);
- mainD.CoOrd2Pix(&mainD,swmhiliteOrig,&x,&y);
- wDrawFilledRectangle( mainD.d, x, y, w, h, swmhiliteColor, wDrawOptTemp|wDrawOptTransparent );
+ DrawRectangle( &tempD, swmhiliteOrig, swmhiliteSize, swmhiliteColor, DRAW_TRANSPARENT );
}
static int SwitchmotorMgmProc ( int cmd, void * data )
@@ -844,7 +838,7 @@ EXPORT void SwitchmotorMgmLoad( void )
TRK_ITERATE(trk) {
if (GetTrkType(trk) != T_SWITCHMOTOR) continue;
- ContMgmLoad( switchmI, SwitchmotorMgmProc, (void *)trk );
+ ContMgmLoad( switchmI, SwitchmotorMgmProc, trk );
}
}