diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-02-06 16:04:24 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-02-06 16:04:24 +0100 |
commit | 5d2c2b27a6323e2666378b986129b2a7c2c39e5c (patch) | |
tree | ce8982b6c0111f79791068de2c2d4c6ce3138a49 /app/bin/celev.c | |
parent | b623f5953691b2a0614e6f1f4def86bdbb9a4113 (diff) |
New upstream version 5.2.2GAupstream/5.2.2GA
Diffstat (limited to 'app/bin/celev.c')
-rw-r--r-- | app/bin/celev.c | 166 |
1 files changed, 77 insertions, 89 deletions
diff --git a/app/bin/celev.c b/app/bin/celev.c index 1da4b22..b80874f 100644 --- a/app/bin/celev.c +++ b/app/bin/celev.c @@ -19,18 +19,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <math.h> -#include <string.h> #include "cselect.h" #include "cundo.h" #include "custom.h" #include "fileio.h" -#include "i18n.h" #include "param.h" #include "track.h" #include "ccurve.h" -#include "utility.h" static wWin_p elevW; @@ -53,12 +49,12 @@ static paramData_t elevationPLs[] = { #define I_HEIGHT (1) { PD_FLOAT, &elevHeightV, "value", PDO_DIM|PDO_DLGNEWCOLUMN, &r_1000_1000 }, #define I_COMPUTED (2) - { PD_MESSAGE, NULL, "computed", 0, (void*)80 }, + { PD_MESSAGE, NULL, "computed", 0, I2VP(80) }, #define I_GRADE (3) - { PD_MESSAGE, NULL, "grade", 0, (void*)80 }, + { PD_MESSAGE, NULL, "grade", 0, I2VP(80) }, #define I_STATION (4) - { PD_STRING, elevStationV, "station", PDO_DLGUNDERCMDBUTT|PDO_STRINGLIMITLENGTH, (void*)200, NULL, 0, 0, sizeof(elevStationV)} }; -static paramGroup_t elevationPG = { "elev", 0, elevationPLs, sizeof elevationPLs/sizeof elevationPLs[0] }; + { PD_STRING, elevStationV, "station", PDO_DLGUNDERCMDBUTT|PDO_STRINGLIMITLENGTH, I2VP(200), NULL, 0, 0, sizeof(elevStationV)} }; +static paramGroup_t elevationPG = { "elev", 0, elevationPLs, COUNT( elevationPLs ) }; static dynArr_t anchors_da; #define anchors(N) DYNARR_N(trkSeg_t,anchors_da,N) @@ -129,14 +125,14 @@ void static CreateMoveAnchor(coOrd pos) { static void LayoutElevW( paramData_t * pd, int inx, - wPos_t colX, - wPos_t * x, - wPos_t * y ) + wWinPix_t colX, + wWinPix_t * x, + wWinPix_t * y ) { - static wPos_t h = 0; + static wWinPix_t h = 0; switch ( inx ) { case I_HEIGHT: - h = wControlGetHeight( elevationPLs[I_MODE].control )/((sizeof elevModeLabels/sizeof elevModeLabels[0])-1); + h = wControlGetHeight( elevationPLs[I_MODE].control )/(COUNT( elevModeLabels )-1); #ifndef WINDOWS h += 3; #endif @@ -243,7 +239,6 @@ static void ElevSelect( track_p trk, EPINX_T ep ) int mode; DIST_T elevX, grade, elev, dist; long radio; - BOOL_T computedOk; BOOL_T gradeOk = TRUE; track_p trk1; EPINX_T ep1; @@ -296,69 +291,55 @@ static void ElevSelect( track_p trk, EPINX_T ep ) elevModeV = radio; ParamLoadControl( &elevationPG, I_MODE ); gradeOk = ComputeElev( trk, ep, FALSE, &elevX, &grade, TRUE ); - computedOk = TRUE; - if (oldElevationEvaluation || computedOk) { - sprintf( message, "%0.2f%s", round(PutDim( elevX )*100.0)/100.0, (units==UNITS_METRIC?"cm":"\"") ); - ParamLoadMessage( &elevationPG, I_COMPUTED, message ); - if (gradeOk) { - sprintf( message, "%0.1f%%", fabs(round(grade*1000.0)/10.0) ); - } else { - if ( EndPtIsDefinedElev(trk,ep) ) { - elev = GetElevation(trk); - dist = GetTrkLength(trk,ep,-1); + sprintf( message, "%0.2f%s", round(PutDim( elevX )*100.0)/100.0, (units==UNITS_METRIC?"cm":"\"") ); + ParamLoadMessage( &elevationPG, I_COMPUTED, message ); + if (gradeOk) { + sprintf( message, "%0.1f%%", fabs(round(grade*1000.0)/10.0) ); + } else { + if ( EndPtIsDefinedElev(trk,ep) ) { + elev = GetElevation(trk); + dist = GetTrkLength(trk,ep,-1); + if (dist>0.1) + sprintf( message, "%0.1f%%", fabs(round(((elev-elevX)/dist)*1000.0))/10.0 ); + else + sprintf( message, _("Undefined") ); + if ( (trk1=GetTrkEndTrk(trk,ep)) && (ep1=GetEndPtConnectedToMe(trk1,trk))>=0 ) { + elev = GetElevation(trk1); + dist = GetTrkLength(trk1,ep1,-1); if (dist>0.1) - sprintf( message, "%0.1f%%", fabs(round((elev-elevX)/dist)*1000.0)/10.0 ); + sprintf( message+strlen(message), " - %0.1f%%", fabs(round(((elev-elevX)/dist)*1000.0))/10.0 ); else - sprintf( message, _("Undefined") ); - if ( (trk1=GetTrkEndTrk(trk,ep)) && (ep1=GetEndPtConnectedToMe(trk1,trk))>=0 ) { - elev = GetElevation(trk1); - dist = GetTrkLength(trk1,ep1,-1); - if (dist>0.1) - sprintf( message+strlen(message), " - %0.1f%%", fabs(round((elev-elevX)/dist)*1000.0)/10.0 ); - else - sprintf( message+strlen(message), " - %s", _("Undefined") ); - } - } else { - strcpy( message, _("Undefined") ); + sprintf( message+strlen(message), " - %s", _("Undefined") ); } - } - ParamLoadMessage( &elevationPG, I_GRADE, message ); - if ( (mode&ELEV_MASK)!=ELEV_DEF ) { - elevHeightV = elevX; - ParamLoadControl( &elevationPG, I_HEIGHT ); + } else { + strcpy( message, _("Undefined") ); } } + ParamLoadMessage( &elevationPG, I_GRADE, message ); + if ( (mode&ELEV_MASK)!=ELEV_DEF ) { + elevHeightV = elevX; + ParamLoadControl( &elevationPG, I_HEIGHT ); + } wShow(elevW); } static BOOL_T GetPointElev(track_p trk, coOrd pos, DIST_T * height) { - DIST_T len, len1, elev0, elev1, dist0, dist1; + DIST_T elev0, elev1, dist0, dist1; if ( IsTrack( trk ) && GetTrkEndPtCnt(trk) == 2 ) { + if ( GetTrkLength( trk, 0, 1 ) < 0.1 ) + return FALSE; dist0 = FindDistance(pos,GetTrkEndPos(trk,0)); dist1 = FindDistance(pos,GetTrkEndPos(trk,1)); - if (EndPtIsDefinedElev(trk,0)) - elev0 = GetTrkEndElevHeight(trk,0); - else { - if (!GetTrkEndElevCachedHeight(trk,0,&elev0,&len)) { - if (GetTrkLength( trk, 0, 1 )<0.1) return FALSE; - ComputeElev( trk, 0, FALSE, &elev0, NULL, TRUE ); - } - } - if (EndPtIsDefinedElev(trk,1)) - elev1 = GetTrkEndElevHeight(trk,1); - else { - if (!GetTrkEndElevCachedHeight(trk,1,&elev1,&len1)) { - if (GetTrkLength( trk, 0, 1 )<0.1) return FALSE; - ComputeElev( trk, 0, FALSE, &elev0, NULL, TRUE ); - } - } - if (dist1+dist0 < 0.1) { + ComputeElev( trk, 0, FALSE, &elev0, NULL, FALSE ); + ComputeElev( trk, 1, FALSE, &elev1, NULL, FALSE ); + if (dist1+dist0 <= 0.1) { *height = elev0; return TRUE; } *height = ((elev1-elev0)*(dist0/(dist0+dist1)))+elev0; return TRUE; - } else if (GetTrkEndPtCnt(trk) == 1 && GetTrkEndElevCachedHeight(trk,0,&elev0,&len)) { + } else if (GetTrkEndPtCnt(trk) == 1 && + ComputeElev( trk, 0, FALSE, &elev0, NULL, FALSE ) ) { *height = elev0; return TRUE; } @@ -387,7 +368,7 @@ static STATUS_T CmdElevation( wAction_t action, coOrd pos ) ParamControlActive( &elevationPG, I_STATION, FALSE ); ParamLoadMessage( &elevationPG, I_COMPUTED, "" ); ParamLoadMessage( &elevationPG, I_GRADE, "" ); - InfoMessage( _("Click on end, +Shift to split, +Ctrl to move description") ); + InfoMessage( _("Click on end, +Shift to split, +Ctrl to move description, +Alt to show elevation") ); elevTrk = NULL; elevUndo = FALSE; CmdMoveDescription( action, pos ); @@ -396,7 +377,7 @@ static STATUS_T CmdElevation( wAction_t action, coOrd pos ) case wActionMove: DYNARR_RESET(trkSeg_t,anchors_da); if (MyGetKeyState()&WKEY_CTRL) { - commandContext = (void*) 1; //Just end points + commandContext = I2VP(1); //Just end points CmdMoveDescription( action, pos ); return C_CONTINUE; } @@ -414,43 +395,46 @@ static STATUS_T CmdElevation( wAction_t action, coOrd pos ) InfoMessage( _("Move to end or track crossing") ); return C_CONTINUE; } - if ((trk1 = OnTrack2(&p2,FALSE, TRUE, FALSE, trk0)) != NULL) { - if (IsClose(FindDistance(p0,p2))) { - if (GetEndPtConnectedToMe(trk0,trk1) == -1) { //Not simply connected to each other!!! - if (GetTrkEndPtCnt(trk1) == 2) { - if (GetPointElev(trk1,p2,&elev1)) { - if (MyGetKeyState()&WKEY_SHIFT) { - InfoMessage (_("Crossing - First %0.3f, Second %0.3f, Clearance %0.3f - Click to Split"), PutDim(elev0), PutDim(elev1), PutDim(fabs(elev0-elev1))); - } else - InfoMessage (_("Crossing - First %0.3f, Second %0.3f, Clearance %0.3f"), PutDim(elev0), PutDim(elev1), PutDim(fabs(elev0-elev1))); + if (((MyGetKeyState()&WKEY_ALT))) { //Add square with Alt + if ((trk1 = OnTrack2(&p2,FALSE, TRUE, FALSE, trk0)) != NULL) { + if (IsClose(FindDistance(p0,p2))) { + if (GetEndPtConnectedToMe(trk0,trk1) == -1) { //Not simply connected to each other!!! + if (GetTrkEndPtCnt(trk1) == 2) { + if (GetPointElev(trk1,p2,&elev1)) { + if (MyGetKeyState()&WKEY_SHIFT) { + InfoMessage (_("Crossing - First %0.3f, Second %0.3f, Clearance %0.3f - Click to Split"), PutDim(elev0), PutDim(elev1), PutDim(fabs(elev0-elev1))); + } else + InfoMessage (_("Crossing - First %0.3f, Second %0.3f, Clearance %0.3f"), PutDim(elev0), PutDim(elev1), PutDim(fabs(elev0-elev1))); + } + CreateSquareAnchor(p2); + return C_CONTINUE; } - CreateSquareAnchor(p2); - return C_CONTINUE; } } } } if ((ep0 = PickEndPoint( p0, trk0 )) != -1) { - if (IsClose(FindDistance(GetTrkEndPos(trk0,ep0),pos))) { - CreateEndAnchor(GetTrkEndPos(trk0,ep0),FALSE); - InfoMessage (_("Track End elevation %0.3f"), PutDim(elev0)); - } else if ((MyGetKeyState()&WKEY_SHIFT) && QueryTrack(trk0,Q_MODIFY_CAN_SPLIT) + if ((MyGetKeyState()&WKEY_SHIFT) && QueryTrack(trk0,Q_MODIFY_CAN_SPLIT) && !(QueryTrack(trk0,Q_IS_TURNOUT))) { InfoMessage( _("Click to split here - elevation %0.3f"), PutDim(elev0)); CreateSplitAnchor(p0,trk0); - } else { - InfoMessage( _("Track Point elevation %0.3f"), PutDim(elev0)); + } else if ((IsClose(FindDistance(GetTrkEndPos(trk0,ep0),p0)) + || (FindDistance(GetTrkEndPos(trk0,ep0),p0)<minLength))) { + CreateEndAnchor(GetTrkEndPos(trk0,ep0),FALSE); + InfoMessage (_("Track End elevation %0.3f - snap End Pt"), PutDim(elev0)); + } else if (MyGetKeyState()&WKEY_ALT) { CreateEndAnchor(p0,TRUE); + InfoMessage (_("Track End elevation %0.3f"), PutDim(elev0)); } - } else InfoMessage( _("Click on end, +Shift to split, +Ctrl to move description") ); + } else InfoMessage( _("Click on End Pt, +Shift to split, +Ctrl to move description, +Alt show Elevation") ); } else - InfoMessage( _("Click on end, +Shift to split, +Ctrl to move description") ); + InfoMessage( _("Click on End Pt, +Shift to split, +Ctrl to move description, +Alt show Elevation") ); return C_CONTINUE; case C_DOWN: case C_MOVE: case C_UP: if (MyGetKeyState()&WKEY_CTRL) { - commandContext = (void*) 1; //Just end points + commandContext = I2VP(1); //Just end points CmdMoveDescription( action, pos ); DYNARR_RESET(trkSeg_t,anchors_da); elevTrk = NULL; @@ -466,10 +450,7 @@ static STATUS_T CmdElevation( wAction_t action, coOrd pos ) InfoMessage( _("Click on end, +Shift to split, +Ctrl to move description") ); } else { ep0 = PickEndPoint( p0, trk0 ); - if (IsClose(FindDistance(GetTrkEndPos(trk0,ep0),pos))) { - InfoMessage( _("Point selected!") ); - ElevSelect( trk0, ep0 ); - } else if ( (MyGetKeyState()&WKEY_SHIFT) ) { + if ( (MyGetKeyState()&WKEY_SHIFT) ) { UndoStart( _("Split track"), "SplitTrack( T%d[%d] )", GetTrkIndex(trk0), ep0 ); oldTrackCount = trackCount; if (!QueryTrack(trk0,Q_IS_TURNOUT) && @@ -479,6 +460,10 @@ static STATUS_T CmdElevation( wAction_t action, coOrd pos ) ElevSelect( trk0, ep0 ); UndoEnd(); elevUndo = FALSE; + } else if (IsClose(FindDistance(GetTrkEndPos(trk0,ep0),p0)) || + (FindDistance(GetTrkEndPos(trk0,ep0),p0)<minLength)) { //Snap if close visually or track + InfoMessage( _("Point selected!") ); + ElevSelect( trk0, ep0 ); } } DYNARR_RESET(trkSeg_t,anchors_da); @@ -493,10 +478,13 @@ static STATUS_T CmdElevation( wAction_t action, coOrd pos ) InfoMessage( "" ); return C_TERMINATE; case C_REDRAW: + wSetCursor(mainD.d,defaultCursor); DoElevHilight( NULL ); HilightSelectedEndPt( TRUE, elevTrk, elevEp ); - if (anchors_da.cnt) + if (anchors_da.cnt) { DrawSegs( &tempD, zero, 0.0, &anchors(0), anchors_da.cnt, trackGauge, wDrawColorBlack ); + wSetCursor(mainD.d,wCursorNone); + } CmdMoveDescription( action, pos ); return C_CONTINUE; } @@ -506,11 +494,11 @@ static STATUS_T CmdElevation( wAction_t action, coOrd pos ) -#include "bitmaps/elev.xpm" +#include "bitmaps/elevation.xpm" EXPORT void InitCmdElevation( wMenu_p menu ) { ParamRegister( &elevationPG ); - AddMenuButton( menu, CmdElevation, "cmdElevation", _("Elevation"), wIconCreatePixMap(elev_xpm), LEVEL0_50, IC_POPUP|IC_LCLICK|IC_RCLICK|IC_WANT_MOVE, ACCL_ELEVATION, NULL ); + AddMenuButton( menu, CmdElevation, "cmdElevation", _("Elevation"), wIconCreatePixMap(elevation_xpm[iconSize]), LEVEL0_50, IC_POPUP|IC_LCLICK|IC_RCLICK|IC_WANT_MOVE, ACCL_ELEVATION, NULL ); } |