summaryrefslogtreecommitdiff
path: root/app/bin/cswitchmotor.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-08 11:53:00 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-08 11:53:00 +0200
commitb623f5953691b2a0614e6f1f4def86bdbb9a4113 (patch)
tree18102bd36f7e22eb2ba2b9f880e4cb29346f4cb8 /app/bin/cswitchmotor.c
parent359b557176b9bb2ff1aed2082641eed39c358d0d (diff)
New upstream version 5.2.0Beta2.1upstream/5.2.0Beta2.1
Diffstat (limited to 'app/bin/cswitchmotor.c')
-rw-r--r--app/bin/cswitchmotor.c108
1 files changed, 84 insertions, 24 deletions
diff --git a/app/bin/cswitchmotor.c b/app/bin/cswitchmotor.c
index 09e6709..a8e1c54 100644
--- a/app/bin/cswitchmotor.c
+++ b/app/bin/cswitchmotor.c
@@ -60,6 +60,9 @@
#include "param.h"
#include "track.h"
#include "trackx.h"
+#ifdef WINDOWS
+#include "include/utf8convert.h"
+#endif // WINDOWS
#include "utility.h"
#include "messages.h"
@@ -83,6 +86,9 @@ static char switchmotorReverse[STR_LONG_SIZE];
static char switchmotorPointSense[STR_LONG_SIZE];
static track_p switchmotorTurnout;
+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)},
@@ -126,6 +132,7 @@ typedef struct switchmotorData_t {
BOOL_T IsHilite;
TRKINX_T turnindx;
track_p turnout;
+ track_p next_motor;
} switchmotorData_t, *switchmotorData_p;
static switchmotorData_p GetswitchmotorData ( track_p trk )
@@ -201,7 +208,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 );
}
- DrawFillPoly(d, switchmotorPoly_CNT, p, wDrawColorBlack);
+ DrawPoly(d, switchmotorPoly_CNT, p, NULL, color, 0, 1, 0);
}
static struct {
@@ -308,7 +315,13 @@ static DIST_T DistanceSwitchMotor (track_p t, coOrd * p )
{
switchmotorData_p xx = GetswitchmotorData(t);
if (xx->turnout == NULL) return 0;
- return GetTrkDistance(xx->turnout,p);
+ coOrd center,hi,lo;
+ GetBoundingBox(t,&hi,&lo);
+ center.x = (hi.x+lo.x)/2;
+ center.y = (hi.y+lo.y)/2;
+ DIST_T d = FindDistance(center,*p);
+ *p = center;
+ return d;
}
static void DescribeSwitchMotor (track_p trk, char * str, CSIZE_T len )
@@ -326,7 +339,7 @@ static void DescribeSwitchMotor (track_p trk, char * str, CSIZE_T len )
*str = tolower((unsigned char)*str);
str++;
}
- sprintf( str, _("(%d): Layer=%d %s"),
+ sprintf( str, _("(%d): Layer=%u %s"),
GetTrkIndex(trk), GetTrkLayer(trk)+1, message );
strncpy(switchmotorData.name,xx->name,STR_SHORT_SIZE-1);
switchmotorData.name[STR_SHORT_SIZE-1] = '\0';
@@ -364,52 +377,89 @@ static void switchmotorDebug (track_p trk)
static void DeleteSwitchMotor ( track_p trk )
{
- LOG( log_switchmotor, 1,("*** DeleteSwitchMotor(%p)\n",trk))
- LOG( log_switchmotor, 1,("*** DeleteSwitchMotor(): index is %d\n",GetTrkIndex(trk)))
- switchmotorData_p xx = GetswitchmotorData(trk);
- LOG( log_switchmotor, 1,("*** DeleteSwitchMotor(): xx = %p, xx->name = %p, xx->normal = %p, xx->reverse = %p, xx->pointsense = %p\n",
+
+ track_p trk1;
+ switchmotorData_p xx1;
+
+ LOG( log_switchmotor, 1,("*** DeleteSwitchMotor(%p)\n",trk))
+ LOG( log_switchmotor, 1,("*** DeleteSwitchMotor(): index is %d\n",GetTrkIndex(trk)))
+ switchmotorData_p xx = GetswitchmotorData(trk);
+ LOG( log_switchmotor, 1,("*** DeleteSwitchMotor(): xx = %p, xx->name = %p, xx->normal = %p, xx->reverse = %p, xx->pointsense = %p\n",
xx,xx->name,xx->normal,xx->reverse,xx->pointsense))
MyFree(xx->name); xx->name = NULL;
MyFree(xx->normal); xx->normal = NULL;
MyFree(xx->reverse); xx->reverse = NULL;
MyFree(xx->pointsense); xx->pointsense = NULL;
+ if (first_motor == trk)
+ first_motor = xx->next_motor;
+ trk1 = first_motor;
+ while(trk1) {
+ xx1 = GetswitchmotorData (trk1);
+ if (xx1->next_motor == trk) {
+ xx1->next_motor = xx->next_motor;
+ break;
+ }
+ trk1 = xx1->next_motor;
+ }
+ if (trk == last_motor)
+ last_motor = trk1;
}
static BOOL_T WriteSwitchMotor ( track_p t, FILE * f )
{
BOOL_T rc = TRUE;
switchmotorData_p xx = GetswitchmotorData(t);
+ char *switchMotorName = MyStrdup(xx->name);
- if (xx->turnout == NULL) return FALSE;
+#ifdef WINDOWS
+ switchMotorName = Convert2UTF8(switchMotorName);
+#endif // WINDOWS
+
+ if (xx->turnout == NULL)
+ return FALSE;
rc &= fprintf(f, "SWITCHMOTOR %d %d \"%s\" \"%s\" \"%s\" \"%s\"\n",
- GetTrkIndex(t), GetTrkIndex(xx->turnout), xx->name,
+ GetTrkIndex(t), GetTrkIndex(xx->turnout), switchMotorName,
xx->normal, xx->reverse, xx->pointsense)>0;
+
+ MyFree(switchMotorName);
return rc;
}
-static void ReadSwitchMotor ( char * line )
+static BOOL_T ReadSwitchMotor ( char * line )
{
TRKINX_T trkindex;
wIndex_t index;
- track_p trk;
- switchmotorData_p xx;
+ track_p trk,last_trk;
+ switchmotorData_p xx,xx1;
char *name, *normal, *reverse, *pointsense;
LOG( log_switchmotor, 1, ("*** ReadSwitchMotor: line is '%s'\n",line))
if (!GetArgs(line+12,"ddqqqq",&index,&trkindex,&name,&normal,&reverse,&pointsense)) {
- return;
+ return FALSE;
}
+#ifdef WINDOWS
+ ConvertUTF8ToSystem(name);
+#endif // WINDOWS
trk = NewTrack(index, T_SWITCHMOTOR, 0, sizeof(switchmotorData_t)+1);
xx = GetswitchmotorData( trk );
xx->name = name;
xx->normal = normal;
xx->reverse = reverse;
xx->pointsense = pointsense;
- xx->turnindx = trkindex;
+ xx->turnindx = trkindex;
+ if (last_motor) {
+ last_trk = last_motor;
+ xx1 = GetswitchmotorData(last_trk);
+ xx1->next_motor = trk;
+ } else first_motor = trk;
+ xx->next_motor = NULL;
+ last_motor = trk;
+
LOG( log_switchmotor, 1,("*** ReadSwitchMotor(): trk = %p (%d), xx = %p\n",trk,GetTrkIndex(trk),xx))
LOG( log_switchmotor, 1,("*** ReadSwitchMotor(): name = %p, normal = %p, reverse = %p, pointsense = %p\n",
name,normal,reverse,pointsense))
switchmotorDebug(trk);
+ return TRUE;
}
EXPORT void ResolveSwitchmotorTurnout ( track_p trk )
@@ -472,19 +522,21 @@ static track_p FindSwitchMotor (track_p trk)
track_p a_trk;
switchmotorData_p xx;
- for (a_trk = NULL; TrackIterate( &a_trk ) ;) {
- if (GetTrkType(a_trk) == T_SWITCHMOTOR) {
- xx = GetswitchmotorData(a_trk);
+ a_trk = first_motor;
+ while (a_trk) {
+ xx = GetswitchmotorData(a_trk);
+ if (!IsTrackDeleted(a_trk)) {
if (xx->turnout == trk) return a_trk;
}
+ a_trk = xx->next_motor;
}
return NULL;
}
static void SwitchMotorOk ( void * junk )
{
- switchmotorData_p xx;
- track_p trk;
+ switchmotorData_p xx,xx1;
+ track_p trk,trk1;
LOG( log_switchmotor, 1, ("*** SwitchMotorOk()\n"))
ParamUpdate (&switchmotorPG );
@@ -502,12 +554,19 @@ static void SwitchMotorOk ( void * junk )
xx->reverse = MyStrdup(switchmotorReverse);
xx->pointsense = MyStrdup(switchmotorPointSense);
xx->turnout = switchmotorTurnout;
- LOG( log_switchmotor, 1,("*** SwitchMotorOk(): trk = %p (%d), xx = %p\n",trk,GetTrkIndex(trk),xx))
+ trk1 = last_motor;
+ if (trk1) {
+ xx1 = GetswitchmotorData( trk1 );
+ xx1->next_motor = trk;
+ } else first_motor = trk;
+ xx->next_motor = NULL;
+ last_motor = trk;
+ LOG( log_switchmotor, 1,("*** SwitchMotorOk(): trk = %p (%d), xx = %p\n",trk,GetTrkIndex(trk),xx))
switchmotorDebug(trk);
UndoEnd();
- wHide( switchmotorW );
- ComputeSwitchMotorBoundingBox(trk);
- DrawNewTrack(trk);
+ wHide( switchmotorW );
+ ComputeSwitchMotorBoundingBox(trk);
+ DrawNewTrack(trk);
}
static void NewSwitchMotorDialog(track_p trk)
@@ -704,7 +763,7 @@ static void DrawSWMotorTrackHilite( void )
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 );
+ wDrawFilledRectangle( mainD.d, x, y, w, h, swmhiliteColor, wDrawOptTemp|wDrawOptTransparent );
}
static int SwitchmotorMgmProc ( int cmd, void * data )
@@ -805,6 +864,7 @@ EXPORT void CheckDeleteSwitchmotor(track_p t)
{
track_p sm;
switchmotorData_p xx;
+ if (GetTrkType( t ) != T_TURNOUT) return; // SMs only on turnouts
while ((sm = FindSwitchMotor( t ))) { //Cope with multiple motors for one Turnout!
xx = GetswitchmotorData (sm);