From a14a7a0ccc9de76aeab0b2e4bbf58f1a79deedc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 3 Jul 2024 10:19:30 +0200 Subject: New upstream version 5.3.0GA --- app/bin/cselect.c | 2828 +++++++++++++++++++++++++++-------------------------- 1 file changed, 1442 insertions(+), 1386 deletions(-) (limited to 'app/bin/cselect.c') diff --git a/app/bin/cselect.c b/app/bin/cselect.c index 1b153b9..a1158bc 100644 --- a/app/bin/cselect.c +++ b/app/bin/cselect.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "common.h" @@ -37,8 +37,8 @@ #include "cjoin.h" #include "draw.h" #include "misc.h" -#include "trackx.h" #include "common-ui.h" +#include "ctrain.h" #include "bitmaps/bmendpt.xbm" @@ -54,6 +54,9 @@ EXPORT wIndex_t moveCmdInx; EXPORT wIndex_t rotateCmdInx; EXPORT wIndex_t flipCmdInx; +EXPORT long selectMode = 0; +EXPORT long selectZero = 1; + #define MAXMOVEMODE (3) static long moveMode = MAXMOVEMODE; static BOOL_T enableMoveDraw = TRUE; @@ -76,25 +79,27 @@ static dynArr_t tlist_da; { DYNARR_APPEND( track_p, tlist_da, 10 );\ Tlist(tlist_da.cnt-1) = T; } -BOOL_T TListSearch(track_p T) { - for (int i=0;i 0 && (selectedTrackCount == 0) && !display_only ) + if ( inx > 0 && (selectedTrackCount == 0) && !display_only ) { return; + } trk = Tlist(inx); if (!GetLayerFrozen(GetTrkLayer(trk))) { if (inx!=0 && - GetTrkSelected(trk)) { - if (display_only) + GetTrkSelected(trk)) { + if (display_only) { DrawTrack(trk,&tempD,wDrawColorPreviewSelected ); + } continue; } else if (GetTrkSelected(trk)) { - if (display_only) + if (display_only) { DrawTrack(trk,&tempD,wDrawColorPreviewUnselected); + } continue; } } @@ -550,11 +580,11 @@ static void SelectConnectedTracks( trk1 = GetTrkEndTrk( trk, ep ); if (trk1 && !TListSearch(trk1) && GetLayerVisible( GetTrkLayer( trk1 ))) { if (GetTrkSelected(trk1)) { - if (display_only) DrawTrack(trk1,&tempD,wDrawColorPreviewSelected ); - } else TlistAppend( trk1 ); + if (display_only) { DrawTrack(trk1,&tempD,wDrawColorPreviewSelected ); } + } else { TlistAppend( trk1 ); } } } - if (display_only && !GetLayerFrozen(GetTrkLayer(trk))) DrawTrack(trk,&tempD,wDrawColorPreviewSelected ); + if (display_only && !GetLayerFrozen(GetTrkLayer(trk))) { DrawTrack(trk,&tempD,wDrawColorPreviewSelected ); } else if (!GetTrkSelected(trk)) { if (GetLayerModule(GetTrkLayer(trk))) { continue; @@ -575,44 +605,47 @@ static void SelectConnectedTracks( } typedef void (*doModuleTrackCallBack_t)(track_p, BOOL_T); -static int DoModuleTracks( int moduleLayer, doModuleTrackCallBack_t doit, BOOL_T val) +static int DoModuleTracks( int moduleLayer, doModuleTrackCallBack_t doit, + BOOL_T val) { track_p trk; trk = NULL; int cnt = 0; while ( TrackIterate( &trk ) ) { if (GetTrkLayer(trk) == moduleLayer) { - doit( trk, val ); - cnt++; + doit( trk, val ); + cnt++; } } return cnt; } -static void DrawSingleTrack(track_p trk, BOOL_T bit) { +static void DrawSingleTrack(track_p trk, BOOL_T bit) +{ DrawTrack(trk,&tempD,bit?wDrawColorPreviewSelected:wDrawColorPreviewUnselected); } typedef BOOL_T (*testSelectedTrackCallBack_t)(track_p, int); -static BOOL_T TestAllSelectedTracks( testSelectedTrackCallBack_t testit, int value) +static BOOL_T TestAllSelectedTracks( testSelectedTrackCallBack_t testit, + int value) { track_p trk; - trk = NULL; - while ( TrackIterate( &trk ) ) { - if (GetTrkSelected(trk)) { - if ( !testit( trk, value ) ) { - return FALSE; - } + trk = NULL; + while ( TrackIterate( &trk ) ) { + if (GetTrkSelected(trk)) { + if ( !testit( trk, value ) ) { + return FALSE; } } + } return TRUE; } typedef BOOL_T (*doSelectedTrackCallBack_t)(track_p, BOOL_T); -static void DoSelectedTracks( doSelectedTrackCallBack_t doit ) +EXPORT void DoSelectedTracks( doSelectedTrackCallBack_t doit ) { track_p trk; trk = NULL; @@ -645,8 +678,9 @@ static BOOL_T SelectedTracksAreFrozen( void ) EXPORT void SelectTrackWidth( void* width ) { track_p trk; - if (SelectedTracksAreFrozen()) + if (SelectedTracksAreFrozen()) { return; + } if (selectedTrackCount<=0) { ErrorMessage( MSG_NO_SELECTED_TRK ); return; @@ -670,8 +704,9 @@ static void SelectLineType( void* widthVP ) { int width = (int)VP2L(widthVP); track_p trk; - if (SelectedTracksAreFrozen()) + if (SelectedTracksAreFrozen()) { return; + } if (selectedTrackCount<=0) { ErrorMessage( MSG_NO_SELECTED_TRK ); return; @@ -682,11 +717,11 @@ static void SelectLineType( void* widthVP ) while ( TrackIterate( &trk ) ) { if (GetTrkSelected(trk)) { UndoModify( trk ); - if (QueryTrack(trk, Q_CAN_MODIFY_CONTROL_POINTS)) + if (QueryTrack(trk, Q_CAN_MODIFY_CONTROL_POINTS)) { SetBezierLineType(trk, width); - else if (QueryTrack(trk, Q_IS_DRAW)) + } else if (QueryTrack(trk, Q_IS_DRAW)) { SetLineType( trk, width ); - else if (QueryTrack(trk, Q_IS_STRUCTURE)) { + } else if (QueryTrack(trk, Q_IS_STRUCTURE)) { SetCompoundLineType(trk, width); } } @@ -707,13 +742,15 @@ EXPORT int SelectDelete( void ) } } - if (doingDouble || (GetCurrentCommand() == modifyCmdInx)) return 1; + if (doingDouble || (GetCurrentCommand() == modifyCmdInx)) { return 1; } - if (SelectedTracksAreFrozen()) + if (SelectedTracksAreFrozen()) { return 0; + } if (selectedTrackCount>0) { BOOL_T UndoStarted = FALSE; - if (!TestAllSelectedTracks(QueryTrack,(int)Q_ISTRAIN)) { // If all Cars, don't bother with UndoStart as there will be nothing to delete + if (!TestAllSelectedTracks(QueryTrack, + (int)Q_ISTRAIN)) { // If all Cars, don't bother with UndoStart as there will be nothing to delete UndoStarted = TRUE; UndoStart( _("Delete Tracks"), "delete" ); } @@ -725,8 +762,9 @@ EXPORT int SelectDelete( void ) wDrawDelayUpdate( mapD.d, FALSE ); selectedTrackCount = 0; SelectedTrackCountChange(); - if (UndoStarted) + if (UndoStarted) { UndoEnd(); + } } else { ErrorMessage( MSG_NO_SELECTED_TRK ); } @@ -736,7 +774,8 @@ EXPORT int SelectDelete( void ) /* * Called By Windows directly with Delete Key. We first try a simple Delete, and if that doesn't work saying "In Modify" we call Modify with a Text key for Delete */ -EXPORT void TrySelectDelete( void ) { +EXPORT void TrySelectDelete( void ) +{ if(SelectDelete() == 1) { CmdModify((C_TEXT+(int)(127<<8)),zero); } @@ -756,13 +795,15 @@ static BOOL_T FlipHidden( track_p trk, BOOL_T unused ) UndrawNewTrack( trk2 ); }*/ UndoModify( trk ); - if ( drawTunnel == 0 ) + if ( drawTunnel == 0 ) { flipHiddenDoSelectRecount = TRUE; + } if (GetTrkVisible(trk)) { ClrTrkBits( trk, TB_VISIBLE|(drawTunnel==0?(TB_SELECTED|TB_SELREDRAW):0) ); ClrTrkBits (trk, TB_BRIDGE); ClrTrkBits (trk, TB_NOTIES); -; } else { + ; + } else { SetTrkBits( trk, TB_VISIBLE ); } /*DrawNewTrack( trk );*/ @@ -787,6 +828,18 @@ static BOOL_T FlipBridge( track_p trk, BOOL_T unused ) return TRUE; } +static BOOL_T FlipRoadbed( track_p trk, BOOL_T unused ) +{ + UndoModify( trk ); + if (GetTrkRoadbed(trk)) { + ClrTrkBits( trk, TB_ROADBED ); + } else { + SetTrkBits( trk, TB_ROADBED ); + SetTrkBits( trk, TB_VISIBLE); + } + return TRUE; +} + static BOOL_T FlipTies( track_p trk, BOOL_T unused ) { UndoModify( trk ); @@ -801,8 +854,9 @@ static BOOL_T FlipTies( track_p trk, BOOL_T unused ) EXPORT void SelectTunnel( void * unused ) { - if (SelectedTracksAreFrozen()) + if (SelectedTracksAreFrozen()) { return; + } if (selectedTrackCount>0) { flipHiddenDoSelectRecount = FALSE; UndoStart( _("Hide Tracks (Tunnel)"), "tunnel" ); @@ -813,14 +867,16 @@ EXPORT void SelectTunnel( void * unused ) } else { ErrorMessage( MSG_NO_SELECTED_TRK ); } - if ( flipHiddenDoSelectRecount ) + if ( flipHiddenDoSelectRecount ) { SelectRecount(); + } } EXPORT void SelectBridge( void * unused ) { - if (SelectedTracksAreFrozen()) + if (SelectedTracksAreFrozen()) { return; + } if (selectedTrackCount>0) { flipHiddenDoSelectRecount = FALSE; UndoStart( _("Bridge Tracks "), "bridge" ); @@ -834,10 +890,29 @@ EXPORT void SelectBridge( void * unused ) MainRedraw(); // SelectBridge } +EXPORT void SelectRoadbed( void * unused ) +{ + if (SelectedTracksAreFrozen()) { + return; + } + if (selectedTrackCount>0) { + flipHiddenDoSelectRecount = FALSE; + UndoStart( _("Roadbed Tracks "), "roadbed" ); + wDrawDelayUpdate( mainD.d, TRUE ); + DoSelectedTracks( FlipRoadbed ); + wDrawDelayUpdate( mainD.d, FALSE ); + UndoEnd(); + } else { + ErrorMessage( MSG_NO_SELECTED_TRK ); + } + MainRedraw(); // SelectBridge +} + EXPORT void SelectTies( void * unused ) { - if (SelectedTracksAreFrozen()) + if (SelectedTracksAreFrozen()) { return; + } if (selectedTrackCount>0) { flipHiddenDoSelectRecount = FALSE; UndoStart( _("Ties Tracks "), "noties" ); @@ -874,22 +949,23 @@ static BOOL_T SetLayer( track_p trk, BOOL_T unused ) EXPORT void MoveSelectedTracksToCurrentLayer( void * unused ) { - if (SelectedTracksAreFrozen()) + if (SelectedTracksAreFrozen()) { return; - if (selectedTrackCount>0) { - UndoStart( _("Move To Current Layer"), "changeLayer" ); - DoSelectedTracks( SetLayer ); - UndoEnd(); - } else { - ErrorMessage( MSG_NO_SELECTED_TRK ); - } + } + if (selectedTrackCount>0) { + UndoStart( _("Move To Current Layer"), "changeLayer" ); + DoSelectedTracks( SetLayer ); + UndoEnd(); + } else { + ErrorMessage( MSG_NO_SELECTED_TRK ); + } } EXPORT void SelectCurrentLayer( void * unused ) { track_p trk; trk = NULL; - if (GetLayerFrozen(curLayer)) return; + if (GetLayerFrozen(curLayer)) { return; } while ( TrackIterate( &trk ) ) { if ((!GetTrkSelected(trk)) && GetTrkLayer(trk) == curLayer) { SelectOneTrack( trk, TRUE ); @@ -898,7 +974,8 @@ EXPORT void SelectCurrentLayer( void * unused ) RedrawSelectedTracksBoundary(); } -EXPORT void DeselectLayer( unsigned int layer ) { +EXPORT void DeselectLayer( unsigned int layer ) +{ track_p trk; trk = NULL; while ( TrackIterate( &trk ) ) { @@ -926,8 +1003,9 @@ static BOOL_T ClearElevation( track_p trk, BOOL_T unused ) EXPORT void ClearElevations( void * unused ) { - if (SelectedTracksAreFrozen()) + if (SelectedTracksAreFrozen()) { return; + } if (selectedTrackCount>0) { UndoStart( _("Clear Elevations"), "clear elevations" ); DoSelectedTracks( ClearElevation ); @@ -951,8 +1029,9 @@ static BOOL_T AddElevation( track_p trk, BOOL_T unused ) if ((trk1=GetTrkEndTrk(trk,ep))) { ep1 = GetEndPtConnectedToMe( trk1, trk ); if (ep1 >= 0) { - if (GetTrkSelected(trk1) && GetTrkIndex(trk1)0) { elevDelta = delta; UndoStart( _("Add Elevations"), "add elevations" ); @@ -985,8 +1065,9 @@ EXPORT void AddElevations( DIST_T delta ) EXPORT void DoRefreshCompound( void * unused ) { - if (SelectedTracksAreFrozen()) + if (SelectedTracksAreFrozen()) { return; + } if (selectedTrackCount>0) { UndoStart( _("Refresh Compound"), "refresh compound" ); DoSelectedTracks( RefreshCompound ); @@ -1000,7 +1081,8 @@ EXPORT void DoRefreshCompound( void * unused ) static drawCmd_t tempSegsD = { - NULL, &tempSegDrawFuncs, 0, 1, 0.0, {0.0, 0.0}, {0.0, 0.0}, Pix2CoOrd, CoOrd2Pix }; + NULL, &tempSegDrawFuncs, 0, 1, 0.0, {0.0, 0.0}, {0.0, 0.0}, Pix2CoOrd, CoOrd2Pix +}; EXPORT void WriteSelectedTracksToTempSegs( void ) { track_p trk; @@ -1008,8 +1090,9 @@ EXPORT void WriteSelectedTracksToTempSegs( void ) tempSegsD.dpi = mainD.dpi; for ( trk=NULL; TrackIterate(&trk); ) { if ( GetTrkSelected( trk ) ) { - if ( IsTrack( trk ) ) + if ( IsTrack( trk ) ) { continue; + } ClrTrkBits( trk, TB_SELECTED ); DrawTrack( trk, &tempSegsD, wDrawColorBlack ); SetTrkBits( trk, TB_SELECTED ); @@ -1017,260 +1100,6 @@ EXPORT void WriteSelectedTracksToTempSegs( void ) } } -static char rescaleFromScale[20]; -static char rescaleFromGauge[20]; - -static char * rescaleToggleLabels[] = { N_("Scale"), N_("Ratio"), NULL }; -static long rescaleMode; -static wIndex_t rescaleFromScaleInx; -static wIndex_t rescaleFromGaugeInx; -static wIndex_t rescaleToScaleInx; -static wIndex_t rescaleToGaugeInx; -static wIndex_t rescaleToInx; -static long rescaleNoChangeDim = FALSE; -static FLOAT_T rescalePercent; -static char * rescaleChangeDimLabels[] = { N_("Do not resize track"), NULL }; -static paramFloatRange_t r0o001_10000 = { 0.001, 10000.0 }; -static paramData_t rescalePLs[] = { -#define I_RESCALE_MODE (0) - { PD_RADIO, &rescaleMode, "toggle", PDO_NOPREF, &rescaleToggleLabels, N_("Rescale by:"), BC_HORZ|BC_NOBORDER }, -#define I_RESCALE_FROM_SCALE (1) - { PD_STRING, rescaleFromScale, "fromS", PDO_NOPREF|PDO_STRINGLIMITLENGTH, I2VP(100), N_("From:"),0, 0, sizeof(rescaleFromScale)}, -#define I_RESCALE_FROM_GAUGE (2) - { PD_STRING, rescaleFromGauge, "fromG", PDO_NOPREF|PDO_DLGHORZ | PDO_STRINGLIMITLENGTH, I2VP(100), " / ", 0, 0, sizeof(rescaleFromGauge)}, -#define I_RESCALE_TO_SCALE (3) - { PD_DROPLIST, &rescaleToScaleInx, "toS", PDO_NOPREF|PDO_LISTINDEX, I2VP(100), N_("To: ") }, -#define I_RESCALE_TO_GAUGE (4) - { PD_DROPLIST, &rescaleToGaugeInx, "toG", PDO_NOPREF|PDO_LISTINDEX|PDO_DLGHORZ, NULL, " / " }, -#define I_RESCALE_CHANGE (5) - { PD_TOGGLE, &rescaleNoChangeDim, "change-dim", 0, &rescaleChangeDimLabels, "", BC_HORZ|BC_NOBORDER }, -#define I_RESCALE_PERCENT (6) - { PD_FLOAT, &rescalePercent, "ratio", 0, &r0o001_10000, N_("Ratio") }, - { PD_MESSAGE, "%", NULL, PDO_DLGHORZ } }; -static paramGroup_t rescalePG = { "rescale", 0, rescalePLs, COUNT( rescalePLs ) }; - - -static long getboundsCount; -static coOrd getboundsLo, getboundsHi; - -static BOOL_T GetboundsDoIt( track_p trk, BOOL_T unused ) -{ - coOrd hi, lo; - - GetBoundingBox( trk, &hi, &lo ); - if ( getboundsCount == 0 ) { - getboundsLo = lo; - getboundsHi = hi; - } else { - if ( lo.x < getboundsLo.x ) getboundsLo.x = lo.x; - if ( lo.y < getboundsLo.y ) getboundsLo.y = lo.y; - if ( hi.x > getboundsHi.x ) getboundsHi.x = hi.x; - if ( hi.y > getboundsHi.y ) getboundsHi.y = hi.y; - } - getboundsCount++; - return TRUE; -} - -static coOrd rescaleShift; -static BOOL_T RescaleDoIt( track_p trk, BOOL_T unused ) -{ - EPINX_T ep, ep1; - track_p trk1; - UndrawNewTrack( trk ); - UndoModify(trk); - if ( rescalePercent != 100.0 ) { - for (ep=0; ep mapD.size.x ) { - d = getboundsHi.x - mapD.size.x; - if ( getboundsLo.x < d ) - d = getboundsLo.x; - getboundsHi.x -= d; - getboundsLo.x -= d; - } - if ( getboundsLo.y < 0 ) { - getboundsHi.y -= getboundsLo.y; - getboundsLo.y = 0; - } else if ( getboundsHi.y > mapD.size.y ) { - d = getboundsHi.y - mapD.size.y; - if ( getboundsLo.y < d ) - d = getboundsLo.y; - getboundsHi.y -= d; - getboundsLo.y -= d; - } - if ( rescaleNoChangeDim == 0 && - (getboundsHi.x > mapD.size.x || - getboundsHi.y > mapD.size.y )) { - NoticeMessage( MSG_RESCALE_TOO_BIG, _("Ok"), NULL, FormatDistance(getboundsHi.x), FormatDistance(getboundsHi.y) ); - } - rescaleShift.x = (getboundsLo.x+getboundsHi.x)/2.0 - center.x*ratio; - rescaleShift.y = (getboundsLo.y+getboundsHi.y)/2.0 - center.y*ratio; - - rescaleToInx = GetScaleInx( rescaleToScaleInx, rescaleToGaugeInx ); - DoSelectedTracks( RescaleDoIt ); - - // rescale the background if it exists and the layout is resized - if (HasBackGround() && ratio != 1.0) { - coOrd pos = GetLayoutBackGroundPos(); - double size = GetLayoutBackGroundSize(); - pos.x = ratio * pos.x + rescaleShift.x; - pos.y = ratio * pos.y + rescaleShift.y; - SetLayoutBackGroundPos(pos); - - size *= ratio; - SetLayoutBackGroundSize(size); - } - DoRedraw(); - wHide( rescalePG.win ); -} - - -static void RescaleDlgUpdate( - paramGroup_p pg, - int inx, - void * valueP ) -{ - switch (inx) { - case I_RESCALE_MODE: - wControlShow( pg->paramPtr[I_RESCALE_FROM_SCALE].control, rescaleMode==0 ); - wControlActive( pg->paramPtr[I_RESCALE_FROM_SCALE].control, FALSE ); - wControlShow( pg->paramPtr[I_RESCALE_TO_SCALE].control, rescaleMode==0 ); - wControlShow( pg->paramPtr[I_RESCALE_FROM_GAUGE].control, rescaleMode==0 ); - wControlActive( pg->paramPtr[I_RESCALE_FROM_GAUGE].control, FALSE ); - wControlShow( pg->paramPtr[I_RESCALE_TO_GAUGE].control, rescaleMode==0 ); - wControlShow( pg->paramPtr[I_RESCALE_CHANGE].control, rescaleMode==0 ); - wControlActive( pg->paramPtr[I_RESCALE_PERCENT].control, rescaleMode==1 ); - if ( rescaleMode!=0 ) - break; - case I_RESCALE_TO_SCALE: - LoadGaugeList( (wList_p)rescalePLs[I_RESCALE_TO_GAUGE].control, *((int *)valueP) ); - rescaleToGaugeInx = 0; - ParamLoadControl( pg, I_RESCALE_TO_GAUGE ); - ParamLoadControl( pg, I_RESCALE_TO_SCALE ); - rescalePercent = GetScaleDescRatio(rescaleFromScaleInx)/GetScaleDescRatio(rescaleToScaleInx)*100.0; - wControlActive( pg->paramPtr[I_RESCALE_CHANGE].control, (rescaleFromScaleInx != rescaleToScaleInx) ); - ParamLoadControl( pg, I_RESCALE_PERCENT ); - break; - case I_RESCALE_TO_GAUGE: - ParamLoadControl( pg, I_RESCALE_TO_GAUGE ); - break; - case I_RESCALE_FROM_SCALE: - ParamLoadControl( pg, I_RESCALE_FROM_SCALE ); - break; - case I_RESCALE_FROM_GAUGE: - ParamLoadControl( pg, I_RESCALE_FROM_GAUGE ); - break; - case I_RESCALE_CHANGE: - ParamLoadControl( pg, I_RESCALE_CHANGE ); - break; - case -1: - break; - } - ParamDialogOkActive( pg, rescalePercent!=100.0 || rescaleFromGaugeInx != rescaleToGaugeInx ); -} - -/** - * Get the scale gauge information for the selected track pieces. - * FIXME: special cases like tracks pieces with different gauges or scale need to be handled - * - * \param IN trk track element - * \param IN unused - * \return TRUE; - */ - -static BOOL_T SelectedScaleGauge( track_p trk, BOOL_T unused ) -{ - char *scaleName; - SCALEINX_T scale; - SCALEDESCINX_T scaleInx; - GAUGEINX_T gaugeInx; - - scale = GetTrkScale( trk ); - scaleName = GetScaleName( scale ); - if( strcmp( scaleName, "*" )) { - GetScaleGauge( scale, &scaleInx, &gaugeInx ); - strcpy( rescaleFromScale,GetScaleDesc( scaleInx )); - strcpy( rescaleFromGauge, GetGaugeDesc( scaleInx, gaugeInx )); - - rescaleFromScaleInx = scaleInx; - rescaleFromGaugeInx = gaugeInx; - rescaleToScaleInx = scaleInx; - rescaleToGaugeInx = gaugeInx; - } - - return TRUE; -} - -/** - * Bring up the rescale dialog. The dialog for rescaling the selected pieces - * of track is created if necessary and shown. Handling of user input is done via - * RescaleDlgUpdate() - */ - -EXPORT void DoRescale( void * unused ) -{ - if ( rescalePG.win == NULL ) { - ParamCreateDialog( &rescalePG, MakeWindowTitle(_("Rescale")), _("Ok"), RescaleDlgOk, wHide, TRUE, NULL, F_BLOCK, RescaleDlgUpdate ); - LoadScaleList( (wList_p)rescalePLs[I_RESCALE_TO_SCALE].control ); - LoadGaugeList( (wList_p)rescalePLs[I_RESCALE_TO_GAUGE].control, GetLayoutCurScaleDesc() ); /* set correct gauge list here */ - rescaleFromScaleInx = GetLayoutCurScale(); - rescaleToScaleInx = rescaleFromScaleInx; - rescalePercent = 100.0; - } - - DoSelectedTracks( SelectedScaleGauge ); - - RescaleDlgUpdate( &rescalePG, I_RESCALE_MODE, &rescaleMode ); - RescaleDlgUpdate( &rescalePG, I_RESCALE_CHANGE, &rescaleMode ); - - RescaleDlgUpdate( &rescalePG, I_RESCALE_FROM_GAUGE, rescaleFromGauge ); - RescaleDlgUpdate( &rescalePG, I_RESCALE_FROM_SCALE, rescaleFromScale ); - - RescaleDlgUpdate( &rescalePG, I_RESCALE_TO_SCALE, &rescaleToScaleInx ); - RescaleDlgUpdate( &rescalePG, I_RESCALE_TO_GAUGE, &rescaleToGaugeInx ); - - wShow( rescalePG.win ); -} - static void DrawSelectedTracksD( drawCmd_p d, wDrawColor color ) { @@ -1282,31 +1111,35 @@ static void DrawSelectedTracksD( drawCmd_p d, wDrawColor color ) trk = Tlist(inx); if (d != &mapD) { GetBoundingBox( trk, &hi, &lo ); - if ( OFF_D( d->orig, d->size, lo, hi ) ) + if ( OFF_D( d->orig, d->size, lo, hi ) ) { continue; + } } - if (color != wDrawColorWhite) + if (color != wDrawColorWhite) { ClrTrkBits(trk, TB_UNDRAWN); - if (color == wDrawColorWhite) + } + if (color == wDrawColorWhite) { SetTrkBits( trk, TB_UNDRAWN ); + } } MainRedraw(); //Omitting all the tracks with TB_UNDRAWN set /*wDrawDelayUpdate( d->d, FALSE );*/ } static BOOL_T AddSelectedTrack( - track_p trk, BOOL_T unused ) + track_p trk, BOOL_T unused ) { DYNARR_APPEND( track_p, tlist_da, 10 ); DYNARR_LAST( track_p, tlist_da ) = trk; return TRUE; } -static BOOL_T RemoveSelectedTrack(track_p trk) { +static BOOL_T RemoveSelectedTrack(track_p trk) +{ - for(int i=0;i getSelectedBoundsHi.x ) { getSelectedBoundsHi.x = hi.x; } + if ( hi.y > getSelectedBoundsHi.y ) { getSelectedBoundsHi.y = hi.y; } + } + getSelectedBoundsCount++; + return TRUE; +} + +EXPORT void GetSelectedBounds( coOrd * low, coOrd * high ) +{ + getSelectedBoundsCount = 0; + DoSelectedTracks( GetBoundsDoIt ); + *low = getSelectedBoundsLo; + *high = getSelectedBoundsHi; +} + static coOrd moveOrig; static ANGLE_T moveAngle; static coOrd moveD_hi, moveD_lo; static drawCmd_t moveD = { - NULL, &tempSegDrawFuncs, DC_SIMPLE, 1, 0.0, {0.0, 0.0}, {0.0, 0.0}, Pix2CoOrd, CoOrd2Pix }; + NULL, &tempSegDrawFuncs, DC_SIMPLE, 1, 0.0, {0.0, 0.0}, {0.0, 0.0}, Pix2CoOrd, CoOrd2Pix +}; @@ -1347,12 +1210,13 @@ static void AccumulateTracks( void ) if (trk) { GetBoundingBox( trk, &hi, &lo ); if (lo.x <= moveD_hi.x && hi.x >= moveD_lo.x && - lo.y <= moveD_hi.y && hi.y >= moveD_lo.y ) { - if (!QueryTrack(trk,Q_IS_CORNU)) - DrawTrack( trk, &moveD, wDrawColorBlack ); + lo.y <= moveD_hi.y && hi.y >= moveD_lo.y ) { + if (!QueryTrack(trk,Q_IS_CORNU)) { + DrawTrack( trk, &moveD, wDrawColorBlack ); } - movedCnt++; } + movedCnt++; + } } InfoCount( movedCnt ); /*wDrawDelayUpdate( moveD.d, FALSE );*/ @@ -1360,13 +1224,15 @@ static void AccumulateTracks( void ) static dynArr_t auto_select_da; -static void AddEndCornus() { - for (int i=0;i=0;j--) { + for (int j=GetTrkEndPtCnt(trk)-1; j>=0; j--) { tc = GetTrkEndTrk(trk,j); - if (tc && !GetTrkSelected(tc) && QueryTrack(tc,Q_IS_CORNU) && !QueryTrack(trk,Q_IS_CORNU)) { //On end and cornu + if (tc && !GetTrkSelected(tc) && QueryTrack(tc,Q_IS_CORNU) + && !QueryTrack(trk,Q_IS_CORNU)) { //On end and cornu SelectOneTrack( tc, TRUE ); DYNARR_APPEND(track_p,tlist_da,1); //Add to selected list DYNARR_LAST(track_p,tlist_da) = tc; @@ -1377,9 +1243,10 @@ static void AddEndCornus() { } } -static void RemoveEndCornus() { +static void RemoveEndCornus() +{ track_p tc; - for (int i=0;i moveD_hi.x) + } + if (corner[inx].x > moveD_hi.x) { moveD_hi.x = corner[inx].x; - if (corner[inx].y > moveD_hi.y) + } + if (corner[inx].y > moveD_hi.y) { moveD_hi.y = corner[inx].y; + } } } AccumulateTracks(); @@ -1456,9 +1327,10 @@ static void DrawMovedTracks( void ) int inx; track_p trk; dynArr_t cornu_segs; + DYNARR_INIT( trkSeg_t, cornu_segs ); - DrawSegs( &tempD, moveOrig, moveAngle, &tempSegs(0), tempSegs_da.cnt, - 0.0, selectedColor ); + DrawSegsDA( &tempD, NULL, moveOrig, moveAngle, &tempSegs_da, 0.0, selectedColor, + 0 ); for ( inx=0; inx=0) { @@ -1719,7 +1604,8 @@ wBool_t FindEndIntersection(coOrd base, coOrd orig, ANGLE_T angle, track_p * t1, epp = PickEndPoint(pos2,tt); //Any close end point (even joined) if (epp>=0) { ct = GetTrkEndTrk(tt,epp); - if (ct && GetTrkSelected(ct)) { //Point is junction to selected track - so will be broken + if (ct && GetTrkSelected( + ct)) { //Point is junction to selected track - so will be broken DIST_T d = FindDistance(pos1,GetTrkEndPos(tt,epp)); if (IsClose(d)) { *ep1 = epp; @@ -1738,14 +1624,15 @@ wBool_t FindEndIntersection(coOrd base, coOrd orig, ANGLE_T angle, track_p * t1, return FALSE; } -void DrawHighlightLayer(int layer) { +void DrawHighlightLayer(int layer) +{ track_p ts = NULL; BOOL_T initial = TRUE; coOrd layer_hi = zero,layer_lo = zero; while ( TrackIterate( &ts ) ) { - if ( !GetLayerVisible( GetTrkLayer( ts))) continue; - if (!GetTrkSelected(ts)) continue; - if (GetTrkLayer(ts) != layer) continue; + if ( !GetLayerVisible( GetTrkLayer( ts))) { continue; } + if (!GetTrkSelected(ts)) { continue; } + if (GetTrkLayer(ts) != layer) { continue; } coOrd hi,lo; GetBoundingBox(ts, &hi, &lo); if (initial) { @@ -1753,10 +1640,10 @@ void DrawHighlightLayer(int layer) { layer_lo = lo; initial = FALSE; } else { - if (layer_hi.x < hi.x ) layer_hi.x = hi.x; - if (layer_hi.y < hi.y ) layer_hi.y = hi.y; - if (layer_lo.x > lo.x ) layer_lo.x = lo.x; - if (layer_lo.y > lo.y ) layer_lo.y = lo.y; + if (layer_hi.x < hi.x ) { layer_hi.x = hi.x; } + if (layer_hi.y < hi.y ) { layer_hi.y = hi.y; } + if (layer_lo.x > lo.x ) { layer_lo.x = lo.x; } + if (layer_lo.y > lo.y ) { layer_lo.y = lo.y; } } } wDrawPix_t margin = (10.5*mainD.scale/mainD.dpi); @@ -1777,7 +1664,8 @@ void DrawHighlightLayer(int layer) { DrawPoly(&tempD,4,rect,type,wDrawColorPowderedBlue,wDrawLineDash,DRAW_CLOSED); } -void SetUpMenu2(coOrd pos, track_p trk) { +void SetUpMenu2(coOrd pos, track_p trk) +{ wMenuPushEnable( menuPushModify,FALSE); wMenuPushEnable(descriptionMI,FALSE); wMenuPushEnable( rotateAlignMI, FALSE ); @@ -1785,12 +1673,13 @@ void SetUpMenu2(coOrd pos, track_p trk) { wMenuPushEnable( bridgeMI, FALSE ); wMenuPushEnable( tiesMI, FALSE ); if ((trk) && - QueryTrack(trk,Q_CAN_ADD_ENDPOINTS)) { //Turntable snap to center if within 1/4 radius + QueryTrack(trk, + Q_CAN_ADD_ENDPOINTS)) { //Turntable snap to center if within 1/4 radius trackParams_t trackParams; if (GetTrackParams(PARAMS_CORNU, trk, pos, &trackParams)) { DIST_T dist = FindDistance(pos, trackParams.ttcenter); if (dist < trackParams.ttradius/4) { - cmdMenuPos = trackParams.ttcenter; + cmdMenuPos = trackParams.ttcenter; } } } @@ -1801,24 +1690,25 @@ void SetUpMenu2(coOrd pos, track_p trk) { } if (trk) { wMenuPushEnable( menuPushModify, - (QueryTrack( trk, Q_CAN_MODIFY_CONTROL_POINTS ) || - QueryTrack( trk, Q_IS_CORNU ) || - (QueryTrack( trk, Q_IS_DRAW ) && !QueryTrack( trk, Q_IS_TEXT )) || - QueryTrack( trk, Q_IS_ACTIVATEABLE))); + (QueryTrack( trk, Q_CAN_MODIFY_CONTROL_POINTS ) || + QueryTrack( trk, Q_IS_CORNU ) || + (QueryTrack( trk, Q_IS_DRAW ) && !QueryTrack( trk, Q_IS_TEXT )) || + QueryTrack( trk, Q_IS_ACTIVATEABLE))); } if ((trk)) { wMenuPushEnable(descriptionMI, QueryTrack( trk, Q_HAS_DESC )); moveDescTrk = trk; moveDescPos = pos; } - if (selectedTrackCount>0) + if (selectedTrackCount>0) { wMenuPushEnable( rotateAlignMI, TRUE ); + } } static STATUS_T CmdMove( - wAction_t action, - coOrd pos ) + wAction_t action, + coOrd pos ) { static coOrd base; static coOrd orig; @@ -1832,166 +1722,172 @@ static STATUS_T CmdMove( switch( action & 0xFF) { - case C_START: - DYNARR_RESET(trkSeg_t,anchors_da); - if (selectedTrackCount == 0) { - ErrorMessage( MSG_NO_SELECTED_TRK ); - return C_TERMINATE; - } - if (SelectedTracksAreFrozen()) { - return C_TERMINATE; - } - InfoMessage( _("Drag to move selected tracks - Shift+Ctrl+Arrow micro-steps the move") ); - state = 0; - ep1 = -1; - ep2 = -1; - doingMove = FALSE; - break; + case C_START: + DYNARR_RESET(trkSeg_t,anchors_da); + if (selectedTrackCount == 0) { + ErrorMessage( MSG_NO_SELECTED_TRK ); + return C_TERMINATE; + } + if (SelectedTracksAreFrozen()) { + return C_TERMINATE; + } + InfoMessage( + _("Drag to move selected tracks - Shift+Ctrl+Arrow micro-steps the move") ); + state = 0; + ep1 = -1; + ep2 = -1; + doingMove = FALSE; + break; - case wActionMove: - DYNARR_RESET(trkSeg_t,anchors_da); - CreateMoveAnchor(pos); - break; - case C_DOWN: - DYNARR_RESET(trkSeg_t,anchors_da); - if (doingMove) { - doingMove = FALSE; - UndoEnd(); - } + case wActionMove: + DYNARR_RESET(trkSeg_t,anchors_da); + CreateMoveAnchor(pos); + break; + case C_DOWN: + DYNARR_RESET(trkSeg_t,anchors_da); + if (doingMove) { + doingMove = FALSE; + UndoEnd(); + } - if (SelectedTracksAreFrozen()) { - return C_TERMINATE; - } - UndoStart( _("Move Tracks"), "move" ); - base = zero; - orig = pos; - DYNARR_RESET(track_p,auto_select_da); - GetMovedTracks(TRUE); - SetMoveD( TRUE, base, 0.0 ); - drawCount = 0; - state = 1; - return C_CONTINUE; - case C_MOVE: - DYNARR_RESET(trkSeg_t,anchors_da); - ep1=-1; - ep2=-1; - drawEnable = enableMoveDraw; - base.x = pos.x - orig.x; - base.y = pos.y - orig.y; - if ((MyGetKeyState() & WKEY_ALT) == 0) SnapPos( &base ); - SetMoveD( TRUE, base, 0.0 ); - if (((MyGetKeyState()&(WKEY_ALT)) == 0) == magneticSnap) { // ALT - if (FindEndIntersection(base,zero,0.0,&t1,&ep1,&t2,&ep2)) { - coOrd pos2 = GetTrkEndPos(t2,ep2); - pos2.x +=base.x; - pos2.y +=base.y; - CreateEndAnchor(pos2,FALSE); - CreateEndAnchor(GetTrkEndPos(t1,ep1),TRUE); - } + if (SelectedTracksAreFrozen()) { + return C_TERMINATE; + } + UndoStart( _("Move Tracks"), "move" ); + base = zero; + orig = pos; + DYNARR_RESET(track_p,auto_select_da); + GetMovedTracks(TRUE); + SetMoveD( TRUE, base, 0.0 ); + drawCount = 0; + state = 1; + return C_CONTINUE; + case C_MOVE: + DYNARR_RESET(trkSeg_t,anchors_da); + ep1=-1; + ep2=-1; + drawEnable = enableMoveDraw; + base.x = pos.x - orig.x; + base.y = pos.y - orig.y; + if ((MyGetKeyState() & WKEY_ALT) == 0) { SnapPos( &base ); } + SetMoveD( TRUE, base, 0.0 ); + if (((MyGetKeyState()&(WKEY_ALT)) == 0) == magneticSnap) { // ALT + if (FindEndIntersection(base,zero,0.0,&t1,&ep1,&t2,&ep2)) { + coOrd pos2 = GetTrkEndPos(t2,ep2); + pos2.x +=base.x; + pos2.y +=base.y; + CreateEndAnchor(pos2,FALSE); + CreateEndAnchor(GetTrkEndPos(t1,ep1),TRUE); } + } #ifdef DRAWCOUNT - InfoMessage( " [%s %s] #%ld", FormatDistance(base.x), FormatDistance(base.y), drawCount ); + InfoMessage( " [%s %s] #%ld", FormatDistance(base.x), FormatDistance(base.y), + drawCount ); #else - InfoMessage( " [%s %s]", FormatDistance(base.x), FormatDistance(base.y) ); + InfoMessage( " [%s %s]", FormatDistance(base.x), FormatDistance(base.y) ); #endif - drawEnable = TRUE; - return C_CONTINUE; - case C_UP: - DYNARR_RESET(trkSeg_t,anchors_da); - state = 0; - FreeTempStrings(); - if (t1 && ep1>=0 && t2 && ep2>=0) { - MoveToJoin(t2,ep2,t1,ep1); - } else { - MoveTracks( FALSE, TRUE, FALSE, base, zero, 0.0, TRUE ); - } - ep1 = -1; - ep2 = -1; - RemoveEndCornus(); - tlist_da.cnt = 0; - return C_TERMINATE; + drawEnable = TRUE; + return C_CONTINUE; + case C_UP: + DYNARR_RESET(trkSeg_t,anchors_da); + state = 0; + FreeTempStrings(); + if (t1 && ep1>=0 && t2 && ep2>=0) { + MoveToJoin(t2,ep2,t1,ep1); + } else { + MoveTracks( FALSE, TRUE, FALSE, base, zero, 0.0, TRUE ); + } + ep1 = -1; + ep2 = -1; + RemoveEndCornus(); + DYNARR_RESET( track_p, tlist_da ); + return C_TERMINATE; - case C_CMDMENU: - if (doingMove) UndoEnd(); - doingMove = FALSE; - base = pos; - track_p trk = OnTrack(&pos, FALSE, FALSE); //Note pollutes pos if turntable - if ((trk) && - QueryTrack(trk,Q_CAN_ADD_ENDPOINTS)) { //Turntable snap to center if within 1/4 radius - trackParams_t trackParams; - if (GetTrackParams(PARAMS_CORNU, trk, pos, &trackParams)) { - DIST_T dist = FindDistance(base, trackParams.ttcenter); - if (dist < trackParams.ttradius/4) { - cmdMenuPos = trackParams.ttcenter; - } + case C_CMDMENU: + if (doingMove) { UndoEnd(); } + doingMove = FALSE; + base = pos; + track_p trk = OnTrack(&pos, FALSE, FALSE); //Note pollutes pos if turntable + if ((trk) && + QueryTrack(trk, + Q_CAN_ADD_ENDPOINTS)) { //Turntable snap to center if within 1/4 radius + trackParams_t trackParams; + if (GetTrackParams(PARAMS_CORNU, trk, pos, &trackParams)) { + DIST_T dist = FindDistance(base, trackParams.ttcenter); + if (dist < trackParams.ttradius/4) { + cmdMenuPos = trackParams.ttcenter; } } - moveDescPos = pos; - moveDescTrk = trk; - SetUpMenu2(pos,trk); - menuPos = pos; - wMenuPopupShow( selectPopup2M ); - return C_CONTINUE; + } + moveDescPos = pos; + moveDescTrk = trk; + SetUpMenu2(pos,trk); + menuPos = pos; + wMenuPopupShow( selectPopup2M ); + return C_CONTINUE; - case C_TEXT: - if ((action>>8) == 'c') { - panCenter = pos; - LOG( log_pan, 2, ( "PanCenter:Sel-%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) ); - PanHere(I2VP(0)); - } - if ((action>>8) == 'e') { - DoZoomExtents(I2VP(0)); - } - if ((action>>8 == 's')) { - DoZoomExtents(I2VP(1)); - } - if ((action>>8) == '0' || (action>>8 == 'o')) { - PanMenuEnter(I2VP('o')); - } - if ((action>>8) == 127 || (action>>8) == 8) - SelectDelete(); + case C_TEXT: + if ((action>>8) == 'c') { + panCenter = pos; + LOG( log_pan, 2, ( "PanCenter:Sel-%d %0.3f %0.3f\n", __LINE__, panCenter.x, + panCenter.y ) ); + PanHere(I2VP(0)); + } + if ((action>>8) == 'e') { + DoZoomExtents(I2VP(0)); + } + if ((action>>8 == 's')) { + DoZoomExtents(I2VP(1)); + } + if ((action>>8) == '0' || (action>>8 == 'o')) { + PanMenuEnter(I2VP('o')); + } + if ((action>>8) == 127 || (action>>8) == 8) { + SelectDelete(); + } + break; + case C_REDRAW: + /* DO_REDRAW */ + //Draw all existing highlight boxes only + DrawHighlightBoxes(FALSE, FALSE, NULL); + HighlightSelectedTracks(NULL, TRUE, TRUE); + DrawSegsDA( &tempD, NULL, zero, 0.0, &anchors_da, trackGauge, wDrawColorBlack, + 0 ); + if ( state == 0 ) { break; - case C_REDRAW: - /* DO_REDRAW */ - //Draw all existing highlight boxes only - DrawHighlightBoxes(FALSE, FALSE, NULL); - HighlightSelectedTracks(NULL, TRUE, TRUE); - if (anchors_da.cnt) - DrawSegs( &tempD, zero, 0.0, &anchors(0), anchors_da.cnt, trackGauge, wDrawColorBlack ); - if ( state == 0 ) - break; - DrawMovedTracks(); + } + DrawMovedTracks(); - break; + break; - case wActionExtKey: - if (state) return C_CONTINUE; - if (SelectedTracksAreFrozen()) return C_TERMINATE; - if ((MyGetKeyState() & - (WKEY_SHIFT | WKEY_CTRL)) == (WKEY_SHIFT | WKEY_CTRL)) { //Both - base = zero; - DIST_T w = tempD.scale/tempD.dpi; - switch((wAccelKey_e) action>>8) { - case wAccelKey_Up: - base.y = w; - break; - case wAccelKey_Down: - base.y = -w; - break; - case wAccelKey_Left: - base.x = -w; - break; - case wAccelKey_Right: - base.x = w; - break; - default: - return C_CONTINUE; - break; - } + case wActionExtKey: + if (state) { return C_CONTINUE; } + if (SelectedTracksAreFrozen()) { return C_TERMINATE; } + if ((MyGetKeyState() & + (WKEY_SHIFT | WKEY_CTRL)) == (WKEY_SHIFT | WKEY_CTRL)) { //Both + base = zero; + DIST_T w = tempD.scale/tempD.dpi; + switch((wAccelKey_e) action>>8) { + case wAccelKey_Up: + base.y = w; + break; + case wAccelKey_Down: + base.y = -w; + break; + case wAccelKey_Left: + base.x = -w; + break; + case wAccelKey_Right: + base.x = w; + break; + default: + return C_CONTINUE; + break; + } drawEnable = enableMoveDraw; GetMovedTracks(TRUE); - if (!doingMove) UndoStart( _("Move Tracks"), "move" ); + if (!doingMove) { UndoStart( _("Move Tracks"), "move" ); } doingMove = TRUE; SetMoveD( TRUE, base, 0.0 ); MoveTracks( FALSE, TRUE, FALSE, base, zero, 0.0, FALSE ); @@ -2002,28 +1898,28 @@ static STATUS_T CmdMove( } RemoveEndCornus(); return C_CONTINUE; - } - break; + } + break; - case C_FINISH: - if (doingMove) { - doingMove = FALSE; - UndoEnd(); - } - RemoveEndCornus(); - tlist_da.cnt = 0; - break; - case C_CONFIRM: - case C_CANCEL: - if (doingMove) { - doingMove = FALSE; - UndoUndo(NULL); - } - RemoveEndCornus(); - tlist_da.cnt = 0; - break; - default: - break; + case C_FINISH: + if (doingMove) { + doingMove = FALSE; + UndoEnd(); + } + RemoveEndCornus(); + DYNARR_RESET( track_p, tlist_da ); + break; + case C_CONFIRM: + case C_CANCEL: + if (doingMove) { + doingMove = FALSE; + UndoUndo(NULL); + } + RemoveEndCornus(); + DYNARR_RESET( track_p, tlist_da ); + break; + default: + break; } return C_CONTINUE; } @@ -2045,8 +1941,8 @@ static void RotateAlign( void * alignVP ) } static STATUS_T CmdRotate( - wAction_t action, - coOrd pos ) + wAction_t action, + coOrd pos ) { static coOrd base; static coOrd orig_base; @@ -2068,303 +1964,332 @@ static STATUS_T CmdRotate( switch( action ) { - case C_START: - DYNARR_RESET(trkSeg_t,anchors_da); - state = 0; - if (selectedTrackCount == 0) { - ErrorMessage( MSG_NO_SELECTED_TRK ); - return C_TERMINATE; - } - if (SelectedTracksAreFrozen()) { - return C_TERMINATE; - } - InfoMessage( _("Drag to rotate selected tracks, Shift+RightClick for QuickRotate Menu") ); - wMenuPushEnable( rotateAlignMI, TRUE ); - rotateAlignState = 0; - ep1 = -1; - ep2 = -1; - break; - case wActionMove: - DYNARR_RESET(trkSeg_t,anchors_da); - CreateRotateAnchor(pos); - break; - case C_DOWN: - DYNARR_RESET(trkSeg_t,anchors_da); - state = 1; - if (SelectedTracksAreFrozen()) { - return C_TERMINATE; - } - UndoStart( _("Rotate Tracks"), "rotate" ); - DYNARR_RESET(track_p,auto_select_da); - if ( rotateAlignState == 0 ) { - drawnAngle = FALSE; - angle = 0.0; - base = orig = pos; - trk = OnTrack(&pos, FALSE, FALSE); //Note pollutes pos if turntable - if ((trk) && - QueryTrack(trk,Q_CAN_ADD_ENDPOINTS)) { //Turntable snap to center if within 1/4 radius - trackParams_t trackParams; - if (GetTrackParams(PARAMS_CORNU, trk, pos, &trackParams)) { - DIST_T dist = FindDistance(base, trackParams.ttcenter); - if (dist < trackParams.ttradius/4) { - base = orig = trackParams.ttcenter; - InfoMessage( _("Center of Rotation snapped to Turntable center") ); - } + case C_START: + DYNARR_RESET(trkSeg_t,anchors_da); + state = 0; + if (selectedTrackCount == 0) { + ErrorMessage( MSG_NO_SELECTED_TRK ); + return C_TERMINATE; + } + if (SelectedTracksAreFrozen()) { + return C_TERMINATE; + } + InfoMessage( + _("Drag to rotate selected tracks, Shift+RightClick for QuickRotate Menu") ); + wMenuPushEnable( rotateAlignMI, TRUE ); + rotateAlignState = 0; + ep1 = -1; + ep2 = -1; + break; + case wActionMove: + DYNARR_RESET(trkSeg_t,anchors_da); + CreateRotateAnchor(pos); + break; + case C_DOWN: + DYNARR_RESET(trkSeg_t,anchors_da); + state = 1; + if (SelectedTracksAreFrozen()) { + return C_TERMINATE; + } + UndoStart( _("Rotate Tracks"), "rotate" ); + DYNARR_RESET(track_p,auto_select_da); + if ( rotateAlignState == 0 ) { + drawnAngle = FALSE; + angle = 0.0; + base = orig = pos; + trk = OnTrack(&pos, FALSE, FALSE); //Note pollutes pos if turntable + if ((trk) && + QueryTrack(trk, + Q_CAN_ADD_ENDPOINTS)) { //Turntable snap to center if within 1/4 radius + trackParams_t trackParams; + if (GetTrackParams(PARAMS_CORNU, trk, pos, &trackParams)) { + DIST_T dist = FindDistance(base, trackParams.ttcenter); + if (dist < trackParams.ttradius/4) { + base = orig = trackParams.ttcenter; + InfoMessage( _("Center of Rotation snapped to Turntable center") ); } } - CreateRotateAnchor(orig); - GetMovedTracks(TRUE); - SetMoveD( FALSE, base, angle ); + } + CreateRotateAnchor(orig); + GetMovedTracks(TRUE); + SetMoveD( FALSE, base, angle ); - /*DrawLine( &mainD, base, orig, 0, wDrawColorBlack ); - DrawMovedTracks(FALSE, orig, angle);*/ - } else { - pos1 = pos; - drawnAngle = FALSE; - onTrackInSplit = TRUE; - trk = OnTrack( &pos, TRUE, FALSE ); - onTrackInSplit = FALSE; - if ( trk == NULL ) return C_CONTINUE; - angle1 = NormalizeAngle( GetAngleAtPoint( trk, pos, NULL, NULL ) ); - if ( rotateAlignState == 1 ) { - if ( !GetTrkSelected(trk) ) { - NoticeMessage( MSG_1ST_TRACK_MUST_BE_SELECTED, _("Ok"), NULL ); - } else { - base = pos; - baseAngle = angle1; - getboundsCount = 0; - DoSelectedTracks( GetboundsDoIt ); - orig.x = (getboundsLo.x+getboundsHi.x)/2.0; - orig.y = (getboundsLo.y+getboundsHi.y)/2.0; -/*printf( "orig = [%0.3f %0.3f], baseAngle = %0.3f\n", orig.x, orig.y, baseAngle );*/ - } + /*DrawLine( &mainD, base, orig, 0, wDrawColorBlack ); + DrawMovedTracks(FALSE, orig, angle);*/ + } else { + pos1 = pos; + drawnAngle = FALSE; + onTrackInSplit = TRUE; + trk = OnTrack( &pos, TRUE, FALSE ); + onTrackInSplit = FALSE; + if ( trk == NULL ) { return C_CONTINUE; } + angle1 = NormalizeAngle( GetAngleAtPoint( trk, pos, NULL, NULL ) ); + if ( rotateAlignState == 1 ) { + if ( !GetTrkSelected(trk) ) { + NoticeMessage( MSG_1ST_TRACK_MUST_BE_SELECTED, _("Ok"), NULL ); } else { - if ( GetTrkSelected(trk) ) { - ErrorMessage( MSG_2ND_TRACK_MUST_BE_UNSELECTED ); - angle = 0; - } else { - angle = NormalizeAngle(angle1-baseAngle); - //if ( angle > 90 && angle < 270 ) - // angle = NormalizeAngle( angle + 180.0 ); - //if ( NormalizeAngle( FindAngle( base, pos1 ) - angle1 ) < 180.0 ) - // angle = NormalizeAngle( angle + 180.0 ); -/*printf( "angle 1 = %0.3f\n", angle );*/ - if ( angle1 > 180.0 ) angle1 -= 180.0; - InfoMessage( _("Angle %0.3f"), angle1 ); - } - GetMovedTracks(TRUE); - SetMoveD( FALSE, orig, angle ); + coOrd low, high; + base = pos; + baseAngle = angle1; + GetSelectedBounds( &low, &high ); +// getboundsCount = 0; +// DoSelectedTracks( GetboundsDoIt ); +// orig.x = (getboundsLo.x+getboundsHi.x)/2.0; +// orig.y = (getboundsLo.y+getboundsHi.y)/2.0; + orig.x = (low.x+high.x)/2.0; + orig.y = (low.y+high.y)/2.0; + /*printf( "orig = [%0.3f %0.3f], baseAngle = %0.3f\n", orig.x, orig.y, baseAngle );*/ } - } - return C_CONTINUE; - case C_MOVE: - DYNARR_RESET(trkSeg_t,anchors_da); - ep1=-1; - ep2=-1; - if ( rotateAlignState == 1 ) - return C_CONTINUE; - if ( rotateAlignState == 2 ) { - pos1 = pos; - onTrackInSplit = TRUE; - trk = OnTrack( &pos, TRUE, FALSE ); - onTrackInSplit = FALSE; - if ( trk == NULL ) - return C_CONTINUE; + } else { if ( GetTrkSelected(trk) ) { ErrorMessage( MSG_2ND_TRACK_MUST_BE_UNSELECTED ); - return C_CONTINUE; + angle = 0; + } else { + angle = NormalizeAngle(angle1-baseAngle); + //if ( angle > 90 && angle < 270 ) + // angle = NormalizeAngle( angle + 180.0 ); + //if ( NormalizeAngle( FindAngle( base, pos1 ) - angle1 ) < 180.0 ) + // angle = NormalizeAngle( angle + 180.0 ); + /*printf( "angle 1 = %0.3f\n", angle );*/ + if ( angle1 > 180.0 ) { angle1 -= 180.0; } + InfoMessage( _("Angle %0.3f"), angle1 ); } - angle1 = NormalizeAngle( GetAngleAtPoint( trk, pos, NULL, NULL ) ); - angle = NormalizeAngle(angle1-baseAngle); - if ( angle > 90 && angle < 270 ) - angle = NormalizeAngle( angle + 180.0 ); - if ( NormalizeAngle( FindAngle( pos, pos1 ) - angle1 ) < 180.0 ) - angle = NormalizeAngle( angle + 180.0 ); - if ( angle1 > 180.0 ) angle1 -= 180.0; - InfoMessage( _("Angle %0.3f"), angle1 ); + GetMovedTracks(TRUE); SetMoveD( FALSE, orig, angle ); -/*printf( "angle 2 = %0.3f\n", angle );*/ + } + } + return C_CONTINUE; + case C_MOVE: + DYNARR_RESET(trkSeg_t,anchors_da); + ep1=-1; + ep2=-1; + if ( rotateAlignState == 1 ) { + return C_CONTINUE; + } + if ( rotateAlignState == 2 ) { + pos1 = pos; + onTrackInSplit = TRUE; + trk = OnTrack( &pos, TRUE, FALSE ); + onTrackInSplit = FALSE; + if ( trk == NULL ) { return C_CONTINUE; } - ANGLE_T diff_angle = 0.0; - base = pos; - drawEnable = enableMoveDraw; - if ( FindDistance( orig, pos ) > (20.0/BASE_DPI)*mainD.scale ) { - ANGLE_T old_angle = angle; - angle = FindAngle( orig, pos ); - if (!drawnAngle) { - baseAngle = angle; - drawnAngle = TRUE; - direction_set = FALSE; + if ( GetTrkSelected(trk) ) { + ErrorMessage( MSG_2ND_TRACK_MUST_BE_UNSELECTED ); + return C_CONTINUE; + } + angle1 = NormalizeAngle( GetAngleAtPoint( trk, pos, NULL, NULL ) ); + angle = NormalizeAngle(angle1-baseAngle); + if ( angle > 90 && angle < 270 ) { + angle = NormalizeAngle( angle + 180.0 ); + } + if ( NormalizeAngle( FindAngle( pos, pos1 ) - angle1 ) < 180.0 ) { + angle = NormalizeAngle( angle + 180.0 ); + } + if ( angle1 > 180.0 ) { angle1 -= 180.0; } + InfoMessage( _("Angle %0.3f"), angle1 ); + SetMoveD( FALSE, orig, angle ); + /*printf( "angle 2 = %0.3f\n", angle );*/ + return C_CONTINUE; + } + ANGLE_T diff_angle = 0.0; + base = pos; + drawEnable = enableMoveDraw; + if ( FindDistance( orig, pos ) > (20.0/BASE_DPI)*mainD.scale ) { + ANGLE_T old_angle = angle; + angle = FindAngle( orig, pos ); + if (!drawnAngle) { + baseAngle = angle; + drawnAngle = TRUE; + direction_set = FALSE; + } else { + if (!direction_set) { + if (DifferenceBetweenAngles(baseAngle,angle)>=0) { clockwise = TRUE; } + else { clockwise = FALSE; } + direction_set = TRUE; } else { - if (!direction_set) { - if (DifferenceBetweenAngles(baseAngle,angle)>=0) clockwise = TRUE; - else clockwise = FALSE; - direction_set = TRUE; + if (clockwise) { + if (DifferenceBetweenAngles(baseAngle,angle)<0 + && fabs(DifferenceBetweenAngles(baseAngle, old_angle))<5) { + clockwise = FALSE; + } } else { - if (clockwise) { - if (DifferenceBetweenAngles(baseAngle,angle)<0 && fabs(DifferenceBetweenAngles(baseAngle, old_angle))<5) - clockwise = FALSE; - } else { - if (DifferenceBetweenAngles(baseAngle,angle)>=0 && fabs(DifferenceBetweenAngles(baseAngle,old_angle))<5) - clockwise = TRUE; + if (DifferenceBetweenAngles(baseAngle,angle)>=0 + && fabs(DifferenceBetweenAngles(baseAngle,old_angle))<5) { + clockwise = TRUE; } } } - orig_base = base = pos; - //angle = NormalizeAngle( angle-baseAngle ); - diff_angle = DifferenceBetweenAngles(baseAngle,angle); - if ( (MyGetKeyState() & (WKEY_CTRL|WKEY_SHIFT)) == (WKEY_CTRL|WKEY_SHIFT) ) { //Both Shift+Ctrl - if (clockwise) { - if (diff_angle<0) diff_angle+=360; - } else { - if (diff_angle>0) diff_angle-=360; - } - diff_angle = floor((diff_angle+7.5)/15.0)*15.0; - angle = baseAngle+diff_angle; + } + orig_base = base = pos; + //angle = NormalizeAngle( angle-baseAngle ); + diff_angle = DifferenceBetweenAngles(baseAngle,angle); + if ( (MyGetKeyState() & (WKEY_CTRL|WKEY_SHIFT)) == + (WKEY_CTRL|WKEY_SHIFT) ) { //Both Shift+Ctrl + if (clockwise) { + if (diff_angle<0) { diff_angle+=360; } + } else { + if (diff_angle>0) { diff_angle-=360; } } - Translate( &base, orig, angle, FindDistance(orig,pos) ); //Line one - Translate( &orig_base,orig, baseAngle, FindDistance(orig,pos)<=(60.0/BASE_DPI*mainD.scale)?FindDistance(orig,pos):60.0/BASE_DPI*mainD.scale ); //Line two - SetMoveD( FALSE, orig, NormalizeAngle( angle-baseAngle ) ); - if (((MyGetKeyState()&(WKEY_ALT)) == WKEY_ALT) != magneticSnap) { //Just Shift - if (FindEndIntersection(zero,orig,NormalizeAngle( angle-baseAngle ),&t1,&ep1,&t2,&ep2)) { - coOrd pos2 = GetTrkEndPos(t2,ep2); - coOrd pos1 = GetTrkEndPos(t1,ep1); - Rotate(&pos2,orig,NormalizeAngle( angle-baseAngle )); - CreateEndAnchor(pos2,FALSE); - CreateEndAnchor(pos1,TRUE); - } + diff_angle = floor((diff_angle+7.5)/15.0)*15.0; + angle = baseAngle+diff_angle; + } + Translate( &base, orig, angle, FindDistance(orig,pos) ); //Line one + Translate( &orig_base,orig, baseAngle, FindDistance(orig, + pos)<=(60.0/BASE_DPI*mainD.scale)?FindDistance(orig, + pos):60.0/BASE_DPI*mainD.scale ); //Line two + SetMoveD( FALSE, orig, NormalizeAngle( angle-baseAngle ) ); + if (((MyGetKeyState()&(WKEY_ALT)) == WKEY_ALT) != magneticSnap) { //Just Shift + if (FindEndIntersection(zero,orig,NormalizeAngle( angle-baseAngle ),&t1,&ep1, + &t2,&ep2)) { + coOrd pos2 = GetTrkEndPos(t2,ep2); + coOrd pos1 = GetTrkEndPos(t1,ep1); + Rotate(&pos2,orig,NormalizeAngle( angle-baseAngle )); + CreateEndAnchor(pos2,FALSE); + CreateEndAnchor(pos1,TRUE); } + } #ifdef DRAWCOUNT - InfoMessage( _("Angle %0.3f #%ld"), fabs(diff_angle), drawCount ); + InfoMessage( _("Angle %0.3f #%ld"), fabs(diff_angle), drawCount ); #else - InfoMessage( _("Angle %0.3f %s"), fabs(diff_angle), clockwise?"Clockwise":"Counter-Clockwise" ); + InfoMessage( _("Angle %0.3f %s"), fabs(diff_angle), + clockwise?"Clockwise":"Counter-Clockwise" ); #endif - wFlush(); - drawEnable = TRUE; - } else - InfoMessage( _("Origin Set. Drag away to set start angle")); + wFlush(); + drawEnable = TRUE; + } else { + InfoMessage( _("Origin Set. Drag away to set start angle")); + } - return C_CONTINUE; + return C_CONTINUE; - case C_UP: - DYNARR_RESET(trkSeg_t,anchors_da); - state = 0; - if (t1 && ep1>=0 && t2 && ep2>=0) { - MoveToJoin(t2,ep2,t1,ep1); - CleanSegs(&tempSegs_da); - rotateAlignState = 0; - } else { - if ( rotateAlignState == 1 ) { - if ( trk && GetTrkSelected(trk) ) { - InfoMessage( _("Align: Click on the 2nd unselected object") ); - rotateAlignState = 2; - } - return C_CONTINUE; - } - CleanSegs(&tempSegs_da); - if ( rotateAlignState == 2 ) { - MoveTracks( FALSE, FALSE, TRUE, zero, orig, angle, TRUE ); - rotateAlignState = 0; - } else if (drawnAngle) { - MoveTracks( FALSE, FALSE, TRUE, zero, orig, NormalizeAngle( angle-baseAngle ), TRUE ); + case C_UP: + DYNARR_RESET(trkSeg_t,anchors_da); + state = 0; + if (t1 && ep1>=0 && t2 && ep2>=0) { + MoveToJoin(t2,ep2,t1,ep1); + CleanSegs(&tempSegs_da); + rotateAlignState = 0; + } else { + if ( rotateAlignState == 1 ) { + if ( trk && GetTrkSelected(trk) ) { + InfoMessage( _("Align: Click on the 2nd unselected object") ); + rotateAlignState = 2; } + return C_CONTINUE; } - UndoEnd(); - RemoveEndCornus(); - tlist_da.cnt = 0; - return C_TERMINATE; + CleanSegs(&tempSegs_da); + if ( rotateAlignState == 2 ) { + MoveTracks( FALSE, FALSE, TRUE, zero, orig, angle, TRUE ); + rotateAlignState = 0; + } else if (drawnAngle) { + MoveTracks( FALSE, FALSE, TRUE, zero, orig, NormalizeAngle( angle-baseAngle ), + TRUE ); + } + } + UndoEnd(); + RemoveEndCornus(); + DYNARR_RESET( track_p, tlist_da ); + return C_TERMINATE; - case C_CMDMENU: - base = pos; - trk = OnTrack(&pos, FALSE, FALSE); //Note pollutes pos if turntable - if ((trk) && - QueryTrack(trk,Q_CAN_ADD_ENDPOINTS)) { //Turntable snap to center if within 1/4 radius - trackParams_t trackParams; - if (GetTrackParams(PARAMS_CORNU, trk, pos, &trackParams)) { - DIST_T dist = FindDistance(base, trackParams.ttcenter); - if (dist < trackParams.ttradius/4) { - cmdMenuPos = trackParams.ttcenter; - } + case C_CMDMENU: + base = pos; + trk = OnTrack(&pos, FALSE, FALSE); //Note pollutes pos if turntable + if ((trk) && + QueryTrack(trk, + Q_CAN_ADD_ENDPOINTS)) { //Turntable snap to center if within 1/4 radius + trackParams_t trackParams; + if (GetTrackParams(PARAMS_CORNU, trk, pos, &trackParams)) { + DIST_T dist = FindDistance(base, trackParams.ttcenter); + if (dist < trackParams.ttradius/4) { + cmdMenuPos = trackParams.ttcenter; } } - moveDescPos = pos; - moveDescTrk = trk; - SetUpMenu2(pos,trk); - menuPos = pos; - wMenuPopupShow( selectPopup2M ); - return C_CONTINUE; + } + moveDescPos = pos; + moveDescTrk = trk; + SetUpMenu2(pos,trk); + menuPos = pos; + wMenuPopupShow( selectPopup2M ); + return C_CONTINUE; - case C_TEXT: - if ((action>>8) == 'd') { - panCenter = pos; - LOG( log_pan, 2, ( "PanCenter:Sel-%d %0.3f %0.3f\n", __LINE__, panCenter.x, panCenter.y ) ); - PanHere(I2VP(0)); - } - if ((action>>8) == 'e') { - DoZoomExtents(I2VP(0)); - } - if ((action>>8) == 's') { - DoZoomExtents(I2VP(1)); - } - if ((action>>8) == '0' || (action>>8 == 'o')) { - PanMenuEnter(I2VP('o')); - } + case C_TEXT: + if ((action>>8) == 'd') { + panCenter = pos; + LOG( log_pan, 2, ( "PanCenter:Sel-%d %0.3f %0.3f\n", __LINE__, panCenter.x, + panCenter.y ) ); + PanHere(I2VP(0)); + } + if ((action>>8) == 'e') { + DoZoomExtents(I2VP(0)); + } + if ((action>>8) == 's') { + DoZoomExtents(I2VP(1)); + } + if ((action>>8) == '0' || (action>>8 == 'o')) { + PanMenuEnter(I2VP('o')); + } + break; + case C_REDRAW: + DrawHighlightBoxes(FALSE,FALSE,NULL); + HighlightSelectedTracks(NULL, TRUE, TRUE); + DrawSegsDA( &tempD, NULL, zero, 0.0, &anchors_da, trackGauge, wDrawColorBlack, + 0 ); + /* DO_REDRAW */ + if ( state == 0 ) { break; - case C_REDRAW: - DrawHighlightBoxes(FALSE,FALSE,NULL); - HighlightSelectedTracks(NULL, TRUE, TRUE); - if (anchors_da.cnt) - DrawSegs( &tempD, zero, 0.0, &anchors(0), anchors_da.cnt, trackGauge, wDrawColorBlack ); - /* DO_REDRAW */ - if ( state == 0 ) - break; - if ( rotateAlignState != 2 ) { - DIST_T width = tempD.scale*0.15; - DrawLine( &tempD, base, orig, 0, wDrawColorBlue ); - if (drawnAngle) { - DrawLine( &tempD, orig_base, orig, (wDrawWidth)width/2, wDrawColorBlue ); - ANGLE_T a = DifferenceBetweenAngles(FindAngle(orig, orig_base),FindAngle(orig, base)); - - DIST_T dist = FindDistance(orig,base); - if (dist>(60.0/BASE_DPI)*mainD.scale) dist = (60.0/BASE_DPI)*mainD.scale; - - if (direction_set) { - if (clockwise) { - if (a<0) a = a + 360; - DrawArc( &tempD, orig, dist/2, FindAngle(orig,orig_base), a, FALSE, 0, wDrawColorBlue); - } else { - if (a>0) a = a - 360; - DrawArc( &tempD, orig, dist/2, FindAngle(orig,base), fabs(a), FALSE, 0, wDrawColorBlue); - } - DIST_T d; - d = mainD.scale*0.25; - ANGLE_T arrow_a = NormalizeAngle(FindAngle(orig,orig_base)+a/2); - coOrd arr1,arr2,arr3; - Translate(&arr2,orig,arrow_a,dist/2); - if (clockwise) arrow_a +=90; - else arrow_a -=90; - Translate(&arr1,arr2,arrow_a+135,d/2); - Translate(&arr3,arr2,arrow_a-135,d/2); - DrawLine( &tempD, arr1, arr2, 0, wDrawColorBlue ); - DrawLine( &tempD, arr2, arr3, 0, wDrawColorBlue ); + } + if ( rotateAlignState != 2 ) { + DIST_T width = tempD.scale*0.15; + DrawLine( &tempD, base, orig, 0, wDrawColorBlue ); + if (drawnAngle) { + DrawLine( &tempD, orig_base, orig, (wDrawWidth)width/2, wDrawColorBlue ); + ANGLE_T a = DifferenceBetweenAngles(FindAngle(orig, orig_base),FindAngle(orig, + base)); + + DIST_T dist = FindDistance(orig,base); + if (dist>(60.0/BASE_DPI)*mainD.scale) { dist = (60.0/BASE_DPI)*mainD.scale; } + + if (direction_set) { + if (clockwise) { + if (a<0) { a = a + 360; } + DrawArc( &tempD, orig, dist/2, FindAngle(orig,orig_base), a, FALSE, 0, + wDrawColorBlue); + } else { + if (a>0) { a = a - 360; } + DrawArc( &tempD, orig, dist/2, FindAngle(orig,base), fabs(a), FALSE, 0, + wDrawColorBlue); } + DIST_T d; + d = mainD.scale*0.25; + ANGLE_T arrow_a = NormalizeAngle(FindAngle(orig,orig_base)+a/2); + coOrd arr1,arr2,arr3; + Translate(&arr2,orig,arrow_a,dist/2); + if (clockwise) { arrow_a +=90; } + else { arrow_a -=90; } + Translate(&arr1,arr2,arrow_a+135,d/2); + Translate(&arr3,arr2,arrow_a-135,d/2); + DrawLine( &tempD, arr1, arr2, 0, wDrawColorBlue ); + DrawLine( &tempD, arr2, arr3, 0, wDrawColorBlue ); } - } - DrawMovedTracks(); - break; } + DrawMovedTracks(); + break; + + } return C_CONTINUE; } -static void QuickMove( void* pos) { +static void QuickMove( void* pos) +{ coOrd move_pos = *(coOrd*)pos; DYNARR_RESET(track_p,auto_select_da); - if ( SelectedTracksAreFrozen() ) + if ( SelectedTracksAreFrozen() ) { return; + } wDrawDelayUpdate( mainD.d, TRUE ); GetMovedTracks(FALSE); UndoStart( _("Move Tracks"), "Move Tracks" ); @@ -2372,16 +2297,18 @@ static void QuickMove( void* pos) { wDrawDelayUpdate( mainD.d, FALSE ); } -static track_p SelectTrackByIndex(TRKINX_T ti, char * message ) { +static track_p SelectTrackByIndex(TRKINX_T ti, char * message ) +{ track_p trk = FindTrack(ti); if (trk) { if (!GetLayerFrozen( GetTrkLayer( trk ) ) ) { if (GetLayerModule(GetTrkLayer(trk))) { DoModuleTracks(GetTrkLayer(trk),DrawSingleTrack,TRUE); - snprintf(message, STR_LONG_SIZE, "%s %d",_("In module layer:"),GetTrkLayer(trk)+1); + snprintf(message, STR_LONG_SIZE, "%s %d",_("In module layer:"), + GetTrkLayer(trk)+1); } else { - if (!GetLayerVisible(GetTrkLayer(trk))) FlipLayer(I2VP(GetTrkLayer(trk))); - if (!GetTrkVisible(trk) && drawTunnel==0 ) drawTunnel = 1; //Force DRAW_TUNNEL_DASH + if (!GetLayerVisible(GetTrkLayer(trk))) { FlipLayer(I2VP(GetTrkLayer(trk))); } + if (!GetTrkVisible(trk) && drawTunnel==0 ) { drawTunnel = 1; } //Force DRAW_TUNNEL_DASH SelectOneTrack(trk,TRUE); } } else { @@ -2394,7 +2321,8 @@ static track_p SelectTrackByIndex(TRKINX_T ti, char * message ) { return trk; } -EXPORT void SelectByIndex( void* string) { +EXPORT void SelectByIndex( void* string) +{ char result[STR_LONG_SIZE] = ""; char * message; SetAllTrackSelect(FALSE); @@ -2414,13 +2342,13 @@ EXPORT void SelectByIndex( void* string) { } } cp = strtok(NULL,","); - if (cp) single = FALSE; + if (cp) { single = FALSE; } } DoZoomExtents(I2VP(1)); - if (strlen(result)) + if (strlen(result)) { InfoMessage(result); - else if (single && trk) { + } else if (single && trk) { char msg[STR_SIZE]; DescribeTrack( trk, msg, sizeof msg ); InfoMessage( msg ); @@ -2433,8 +2361,9 @@ static void QuickRotate( void* pangle ) { ANGLE_T angle = (ANGLE_T)VP2L(pangle); DYNARR_RESET(track_p,auto_select_da); - if ( SelectedTracksAreFrozen() ) + if ( SelectedTracksAreFrozen() ) { return; + } wDrawDelayUpdate( mainD.d, TRUE ); GetMovedTracks(FALSE); //DrawSelectedTracksD( &mainD, wDrawColorWhite ); @@ -2457,8 +2386,9 @@ static void ChangeDetailedFlag( void * mode ) if ( ( GetTrkBits( moveDescTrk ) & TB_DETAILDESC ) == 0 ) { ClrTrkBits( moveDescTrk, TB_HIDEDESC ); SetTrkBits( moveDescTrk, TB_DETAILDESC ); - } else + } else { ClrTrkBits( moveDescTrk, TB_DETAILDESC ); + } DrawNewTrack( moveDescTrk ); wDrawDelayUpdate( mainD.d, FALSE ); } @@ -2469,10 +2399,11 @@ static void ChangeDescFlag( void * mode ) UndoStart( _("Toggle Label"), "Modedesc( T%d )", GetTrkIndex(moveDescTrk) ); UndoModify( moveDescTrk ); UndrawNewTrack( moveDescTrk ); - if ( ( GetTrkBits( moveDescTrk ) & TB_HIDEDESC ) == 0 ) + if ( ( GetTrkBits( moveDescTrk ) & TB_HIDEDESC ) == 0 ) { SetTrkBits( moveDescTrk, TB_HIDEDESC ); - else + } else { ClrTrkBits( moveDescTrk, TB_HIDEDESC ); + } DrawNewTrack( moveDescTrk ); wDrawDelayUpdate( mainD.d, FALSE ); } @@ -2481,134 +2412,142 @@ static void ChangeDescFlag( void * mode ) * Mode_o -1 = everything, 0 = elevations only, 1 = descriptions only */ -track_p FindTrackDescription(coOrd pos, EPINX_T * ep_o, int * mode_o, BOOL_T show_hidden, BOOL_T * hidden_o) { - track_p trk = NULL; - DIST_T d, dd = DIST_INF; - track_p trk1 = NULL; - EPINX_T ep1=-1, ep=-1; - BOOL_T hidden_t, hidden; - coOrd dpos = pos; - coOrd cpos; - int mode = -1; - while ( TrackIterate( &trk1 ) ) { - if ( !GetLayerVisible(GetTrkLayer(trk1)) ) - continue; - if ( (!GetTrkVisible(trk1)) && drawTunnel==0 ) - continue; - if ( GetLayerFrozen( GetTrkLayer( trk1 ) )) - continue; - if ( (labelEnable&LABELENABLE_ENDPT_ELEV)!=0 && *mode_o <= 0) { - for ( ep1=0; ep1