diff options
Diffstat (limited to 'app/bin/compound.c')
-rw-r--r-- | app/bin/compound.c | 430 |
1 files changed, 277 insertions, 153 deletions
diff --git a/app/bin/compound.c b/app/bin/compound.c index 627d2ef..b6d5847 100644 --- a/app/bin/compound.c +++ b/app/bin/compound.c @@ -21,11 +21,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <ctype.h> -#include <math.h> -#include <string.h> - - #include "tbezier.h" #include "cjoin.h" #include "common.h" @@ -33,39 +28,173 @@ #include "cundo.h" #include "dynstring.h" #include "fileio.h" -#include "i18n.h" #include "shrtpath.h" #include "track.h" -#include "utility.h" -#include "messages.h" +#include "draw.h" #include "include/paramfile.h" +#include "common-ui.h" /***************************************************************************** * - * Misc + * Paths * */ -//Convert the internal path segment into the external one - which is based on the index count of only the track segments -char ConvertPathSegToExternal(char signed pp, int segCnt,trkSeg_p segs) { +#ifndef NEWPATH +/* GetPaths() + * + * Return the paths for 'trk'. + * + * \param trk IN Get paths for track 'trk' + */ +EXPORT PATHPTR_T GetPaths( track_p trk ) +{ + struct extraDataCompound_t * xx = GET_EXTRA_DATA( trk, T_NOTRACK, extraDataCompound_t ); + if ( GetTrkType(trk) == T_STRUCTURE && xx->paths != NULL ) { + LogPrintf( "GetPaths( STRUCTURE, paths!=NULL )\n" ); + } + if ( GetTrkType(trk) == T_TURNOUT && xx->paths == NULL ) { + LogPrintf( "GetPaths( TURNOUT, paths==NULL )\n" ); + } + return xx->paths; +} +#endif - char signed new_pp; - int old_inx; - EPINX_T old_EP; - GetSegInxEP(pp,&old_inx,&old_EP); - int j = old_inx; - for (int i=0;i<old_inx;i++) { - if ( !IsSegTrack(&segs[i]) ) { - j--; - } +/* GetPathsLength() + * + * Return the length of the paths object + * + * \param paths IN paths object + */ +EXPORT wIndex_t GetPathsLength( PATHPTR_T paths ) +{ + PATHPTR_T pp; + ASSERT( paths != NULL ); + for ( pp = paths; pp[0]; pp+=2 ) + for ( pp += strlen( (char*)pp ); pp[0] || pp[1]; pp++ ); + return (wIndex_t)(pp - paths + 1); +} + + +#ifndef NEWPATH +/* SetPaths() + * + * Set the paths for 'trk'. + * Called when paths are read from a layout file, copied from a param def'n or + * from a Spilt turnout. + * + * \param trk IN + * \param paths IN + */ +EXPORT void SetPaths( track_p trk, PATHPTR_T paths ) +{ + if ( GetTrkType(trk) == T_STRUCTURE && paths != NULL ) { + LogPrintf( "SetPaths( STRUCTURE, paths!=NULL )\n" ); + } + if ( GetTrkType(trk) == T_TURNOUT && paths == NULL ) { + LogPrintf( "SetPaths( TURNOUT, paths==NULL )\n" ); } - SetSegInxEP(&new_pp,j,old_EP); - return new_pp; + struct extraDataCompound_t * xx = GET_EXTRA_DATA( trk, T_NOTRACK, extraDataCompound_t ); + if ( xx->paths ) + MyFree( xx->paths ); + if ( paths == NULL ) { + xx->paths = NULL; + } else { + wIndex_t pathLen = GetPathsLength( paths ); + xx->paths = memdup( paths, pathLen * sizeof *xx->paths ); + } + xx->currPath = NULL; + xx->currPathIndex = 0; +} +#endif + + +/* GetCurrPath() + * + * Return the current path for 'trk'. + * Current path is the .currPathIndex'th path + * If the .currPathIndex is greater then the number of paths, return the first + * + * \param trk IN + */ +EXPORT PATHPTR_T GetCurrPath( track_p trk ) +{ + struct extraDataCompound_t * xx = GET_EXTRA_DATA( trk, T_TURNOUT, extraDataCompound_t ); + if ( xx->currPath ) + return xx->currPath; + PATHPTR_T path = GetPaths( trk ); + for ( wIndex_t position = xx->currPathIndex; + position > 0 && path[0]; + path+=2, position-- ) { + for ( path += strlen( (char*)path ); path[0] || path[1]; path++ ); + } + if ( !path[0] ) { + xx->currPathIndex = 0; + path = GetPaths( trk ); + } + xx->currPath = path; + return xx->currPath; } -BOOL_T WriteCompoundPathsEndPtsSegs( + +EXPORT long GetCurrPathIndex( track_p trk ) +{ + if ( GetTrkType( trk ) != T_TURNOUT ) + return 0; + struct extraDataCompound_t * xx = GET_EXTRA_DATA( trk, T_TURNOUT, extraDataCompound_t ); + return xx->currPathIndex; +} + + +EXPORT void SetCurrPathIndex( track_p trk, long position ) +{ + if ( GetTrkType( trk ) != T_TURNOUT ) + return; + struct extraDataCompound_t * xx = GET_EXTRA_DATA( trk, T_TURNOUT, extraDataCompound_t ); + xx->currPathIndex = position; + xx->currPath = NULL; +} + +#ifndef NEWPATH +/* GetParamPaths() + * + * Return the paths for turnout parameter 'to'. + * + * \param to IN + */ +PATHPTR_T GetParamPaths( turnoutInfo_t * to ) +{ + return to->paths; +} + +/* SetParamPaths() + * + * Set paths for a Turnout Parameter 'to' + * Used when creating a new turnout def'n + * + * \param to IN + * \param paths IN + */ +void SetParamPaths( turnoutInfo_t * to, PATHPTR_T paths ) +{ + if ( paths ) { + wIndex_t len = GetPathsLength(paths); + to->paths = (PATHPTR_T)memdup( paths, len * ( sizeof * to->paths ) ); + } else { + to->paths = NULL; + } +} +#endif + +/***************************************************************************** + * + * + * + */ + +EXPORT BOOL_T WriteCompoundPathsEndPtsSegs( FILE * f, PATHPTR_T paths, wIndex_t segCnt, @@ -77,11 +206,13 @@ BOOL_T WriteCompoundPathsEndPtsSegs( PATHPTR_T pp; BOOL_T rc = TRUE; - for ( pp=paths; *pp; pp+=2 ) { - rc &= fprintf( f, "\tP \"%s\"", pp )>0; - for ( pp+=strlen((char *)pp)+1; pp[0]!=0 || pp[1]!=0; pp++ ) - rc &= fprintf( f, " %d", ConvertPathSegToExternal(pp[0],segCnt,segs) )>0; - rc &= fprintf( f, "\n" )>0; + if ( paths ) { + for ( pp=paths; *pp; pp+=2 ) { + rc &= fprintf( f, "\tP \"%s\"", pp )>0; + for ( pp+=strlen((char *)pp)+1; pp[0]!=0 || pp[1]!=0; pp++ ) + rc &= fprintf( f, " %d", pp[0] )>0; + rc &= fprintf( f, "\n" )>0; + } } for ( i=0; i<endPtCnt; i++ ) rc &= fprintf( f, "\tE %0.6f %0.6f %0.6f\n", @@ -101,7 +232,7 @@ EXPORT void ParseCompoundTitle( int * partnoL ) { char * cp1, *cp2; - int len; + size_t len; *manufP = *nameP = *partnoP = NULL; *manufL = *nameL = *partnoL = 0; len = strlen( title ); @@ -111,17 +242,17 @@ EXPORT void ParseCompoundTitle( if ( cp2 ) { cp2++; *partnoP = cp2; - *partnoL = title+len-cp2; + *partnoL = (int)(title+len-cp2); len = cp2-title-1; } cp1++; *nameP = cp1; - *nameL = title+len-cp1; + *nameL = (int)(title+len-cp1); *manufP = title; - *manufL = cp1-title-1; + *manufL = (int)(cp1-title-1); } else { *nameP = title; - *nameL = len; + *nameL = (int)len; } } @@ -131,7 +262,7 @@ void FormatCompoundTitle( char * title ) { char *cp1, *cp2=NULL, *cq; - int len; + size_t len; FLOAT_T price; BOOL_T needSep; cq = message; @@ -210,10 +341,10 @@ void FormatCompoundTitle( void ComputeCompoundBoundingBox( track_p trk ) { - struct extraData *xx; + struct extraDataCompound_t *xx; coOrd hi, lo; - xx = GetTrkExtraData(trk); + xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); GetSegBounds( xx->orig, xx->angle, xx->segCnt, xx->segs, &lo, &hi ); hi.x += lo.x; @@ -290,7 +421,7 @@ EXPORT void CompoundClearDemoDefns( void ) void SetDescriptionOrig( track_p trk ) { - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); int i, j; coOrd p0, p1; @@ -328,7 +459,7 @@ void DrawCompoundDescription( { wFont_p fp; coOrd p1; - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); char * desc; long layoutLabelsOption = layoutLabels; @@ -336,24 +467,30 @@ void DrawCompoundDescription( return; if ((labelEnable&LABELENABLE_TRKDESC)==0) return; - if ( (d->options&DC_SIMPLE) ) + if ( (d->options&(DC_SIMPLE|DC_SEGTRACK)) ) return; - if ( xx->special == TOpier ) { - desc = xx->u.pier.name; - } else { - if ( xx->flipped ) - layoutLabelsOption |= LABEL_FLIPPED; - if ( xx->ungrouped ) - layoutLabelsOption |= LABEL_UNGROUPED; - if ( xx->split ) - layoutLabelsOption |= LABEL_SPLIT; - FormatCompoundTitle( layoutLabelsOption, xtitle(xx) ); - desc = message; - } - p1 = xx->descriptionOrig; - Rotate( &p1, zero, xx->angle ); - p1.x += xx->orig.x + xx->descriptionOff.x; - p1.y += xx->orig.y + xx->descriptionOff.y; + if ( xx->special == TOpier ) { + desc = xx->u.pier.name; + } else { + if ( xx->flipped ) + layoutLabelsOption |= LABEL_FLIPPED; + if ( xx->ungrouped ) + layoutLabelsOption |= LABEL_UNGROUPED; + if ( xx->split ) + layoutLabelsOption |= LABEL_SPLIT; + FormatCompoundTitle( layoutLabelsOption, xtitle(xx) ); + desc = message; + } + p1 = xx->descriptionOrig; + Rotate( &p1, zero, xx->angle ); + coOrd p0; + p0.x = p1.x+xx->orig.x; + p0.y = p1.y+xx->orig.y; + p1.x += xx->orig.x + xx->descriptionOff.x; + p1.y += xx->orig.y + xx->descriptionOff.y; + if (color == drawColorPreviewSelected) { + DrawLine( d, p0, p1, 0, color ); + } fp = wStandardFont( F_TIMES, FALSE, FALSE ); DrawBoxedString( (xx->special==TOpier)?BOX_INVERT:BOX_NONE, d, p1, desc, fp, (wFontSize_t)descriptionFontSize, color, 0.0 ); } @@ -366,12 +503,12 @@ DIST_T CompoundDescriptionDistance( BOOL_T show_hidden, BOOL_T * hidden) { - struct extraData *xx = GetTrkExtraData(trk); coOrd p1; if (GetTrkType(trk) != T_TURNOUT && GetTrkType(trk) != T_STRUCTURE) - return 100000; + return DIST_INF; + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); if ( ((GetTrkBits( trk ) & TB_HIDEDESC) != 0 ) && !show_hidden) - return 100000; + return DIST_INF; p1 = xx->descriptionOrig; coOrd offset = xx->descriptionOff; if ( (GetTrkBits( trk ) & TB_HIDEDESC) != 0 ) offset = zero; @@ -380,6 +517,10 @@ DIST_T CompoundDescriptionDistance( p1.y += xx->orig.y + offset.y; if (hidden) *hidden = (GetTrkBits( trk ) & TB_HIDEDESC); *dpos = p1; + + coOrd tpos = pos; + if (DistanceCompound(trk,&tpos)<FindDistance( p1, pos )) + return DistanceCompound(trk,&pos); return FindDistance( p1, pos ); } @@ -389,7 +530,7 @@ STATUS_T CompoundDescriptionMove( wAction_t action, coOrd pos ) { - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); static coOrd p0, p1; static BOOL_T editMode; wDrawColor color; @@ -470,7 +611,7 @@ DIST_T DistanceCompound( track_p t, coOrd * p ) { - struct extraData *xx = GetTrkExtraData(t); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(t, T_NOTRACK, extraDataCompound_t); EPINX_T ep; DIST_T d0, d1; coOrd p0, p2; @@ -483,7 +624,7 @@ DIST_T DistanceCompound( d0 = DistanceSegs( xx->orig, xx->angle, xx->segCnt, xx->segs, p, NULL ); } else if ( programMode != MODE_TRAIN || GetTrkEndPtCnt(t) <= 0 ) { d0 = DistanceSegs( xx->orig, xx->angle, xx->segCnt, xx->segs, p, NULL ); - if (programMode != MODE_TRAIN && GetTrkEndPtCnt(t) > 0 && d0 < 10000.0) { + if (programMode != MODE_TRAIN && GetTrkEndPtCnt(t) > 0 && d0 < DIST_INF) { ep = PickEndPoint( *p, t ); *p = GetTrkEndPos(t,ep); } @@ -492,11 +633,11 @@ DIST_T DistanceCompound( Rotate( &p0, xx->orig, -xx->angle ); p0.x -= xx->orig.x; p0.y -= xx->orig.y; - d0 = 1000000.0; - path = xx->pathCurr; - for ( path=xx->pathCurr+strlen((char *)xx->pathCurr)+1; path[0] || path[1]; path++ ) { + d0 = DIST_INF; + path = GetCurrPath( t ); + for ( path += strlen((char *)path)+1; path[0] || path[1]; path++ ) { if ( path[0] != 0 ) { - d1 = 1000000.0; + d1 = DIST_INF; GetSegInxEP( *path, &segInx, &segEP ); segProcData.distance.pos1 = p0; SegProc( SEGPROC_DISTANCE, &xx->segs[segInx], &segProcData ); @@ -506,7 +647,7 @@ DIST_T DistanceCompound( } } } - if ( d0 < 1000000.0 ) { + if ( d0 < DIST_INF ) { p2.x += xx->orig.x; p2.y += xx->orig.y; Rotate( &p2, xx->orig, xx->angle ); @@ -575,7 +716,7 @@ static descData_t compoundDesc[] = { static void UpdateCompound( track_p trk, int inx, descData_p descUpd, BOOL_T needUndoStart ) { - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); const char * manufS, * nameS, * partnoS; char * mP, *nP, *pP; int mL, nL, pL; @@ -806,7 +947,7 @@ void DescribeCompound( char * str, CSIZE_T len ) { - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); int fix; EPINX_T ep, epCnt; char * mP, *nP, *pP, *cnP; @@ -953,13 +1094,13 @@ void DescribeCompound( if ( compoundDesc[LT].control0!=NULL) { wListClear( (wList_p)compoundDesc[LT].control0 ); - wListAddValue( (wList_p)compoundDesc[LT].control0, _("Solid"), NULL, (void*)0 ); - wListAddValue( (wList_p)compoundDesc[LT].control0, _("Dash"), NULL, (void*)1 ); - wListAddValue( (wList_p)compoundDesc[LT].control0, _("Dot"), NULL, (void*)2 ); - wListAddValue( (wList_p)compoundDesc[LT].control0, _("DashDot"), NULL, (void*)3 ); - wListAddValue( (wList_p)compoundDesc[LT].control0, _("DashDotDot"), NULL, (void*)4 ); - wListAddValue( (wList_p)compoundDesc[LT].control0, _("CenterDot"), NULL, (void*)5 ); - wListAddValue( (wList_p)compoundDesc[LT].control0, _("PhantomDot"), NULL, (void*)6 ); + wListAddValue( (wList_p)compoundDesc[LT].control0, _("Solid"), NULL, I2VP(0) ); + wListAddValue( (wList_p)compoundDesc[LT].control0, _("Dash"), NULL, I2VP(1) ); + wListAddValue( (wList_p)compoundDesc[LT].control0, _("Dot"), NULL, I2VP(2) ); + wListAddValue( (wList_p)compoundDesc[LT].control0, _("DashDot"), NULL, I2VP(3) ); + wListAddValue( (wList_p)compoundDesc[LT].control0, _("DashDotDot"), NULL, I2VP(4) ); + wListAddValue( (wList_p)compoundDesc[LT].control0, _("CenterDot"), NULL, I2VP(5) ); + wListAddValue( (wList_p)compoundDesc[LT].control0, _("PhantomDot"), NULL, I2VP(6) ); wListSetIndex( (wList_p)compoundDesc[LT].control0, compoundData.linetype ); } @@ -969,9 +1110,9 @@ void DescribeCompound( void DeleteCompound( track_p t ) { - struct extraData *xx = GetTrkExtraData(t); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(t, T_NOTRACK, extraDataCompound_t); FreeFilledDraw( xx->segCnt, xx->segs ); - MyFree( xx->segs ); + if (xx->segCnt>0) MyFree( xx->segs ); xx->segs = NULL; } @@ -980,42 +1121,34 @@ BOOL_T WriteCompound( track_p t, FILE * f ) { - struct extraData *xx = GetTrkExtraData(t); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(t, T_NOTRACK, extraDataCompound_t); EPINX_T ep, epCnt; long options; long position = 0; drawLineType_e lineType = 0; - PATHPTR_T path; BOOL_T rc = TRUE; options = (long)GetTrkWidth(t); if (xx->handlaid) - options |= 0x08; + options |= COMPOUND_OPTION_HANDLAID; if (xx->flipped) - options |= 0x10; + options |= COMPOUND_OPTION_FLIPPED; if (xx->ungrouped) - options |= 0x20; + options |= COMPOUND_OPTION_UNGROUPED; if (xx->split) - options |= 0x40; + options |= COMPOUND_OPTION_SPLIT; + if (xx->pathOverRide) + options |= COMPOUND_OPTION_PATH_OVERRIDE; + if (xx->pathNoCombine) + options |= COMPOUND_OPTION_PATH_NOCOMBINE; if ( ( GetTrkBits( t ) & TB_HIDEDESC ) != 0 ) - options |= 0x80; + options |= COMPOUND_OPTION_HIDEDESC; epCnt = GetTrkEndPtCnt(t); - if ( epCnt > -0 ) { - path = xx->paths; - while ( path != xx->pathCurr ) { - path += strlen((char*)path)+1; - while ( path[0] || path[1] ) - path++; - path += 2; - if ( *path == 0 ) - break; - position++; - } - } lineType = xx->lineType; rc &= fprintf(f, "%s %d %d %ld %ld %d %s %d %0.6f %0.6f 0 %0.6f \"%s\"\n", GetTrkTypeName(t), - GetTrkIndex(t), GetTrkLayer(t), options, position, lineType, + GetTrkIndex(t), GetTrkLayer(t), options, + GetCurrPathIndex(t), lineType, GetTrkScaleName(t), GetTrkVisible(t)|(GetTrkNoTies(t)?1<<2:0)|(GetTrkBridge(t)?1<<3:0), xx->orig.x, xx->orig.y, xx->angle, PutTitle(xtitle(xx)) )>0; @@ -1034,7 +1167,7 @@ BOOL_T WriteCompound( ; } rc &= fprintf( f, "\tD %0.6f %0.6f\n", xx->descriptionOff.x, xx->descriptionOff.y )>0; - rc &= WriteCompoundPathsEndPtsSegs( f, xpaths(xx), xx->segCnt, xx->segs, 0, NULL ); + rc &= WriteCompoundPathsEndPtsSegs( f, GetPaths( t ), xx->segCnt, xx->segs, 0, NULL ); return rc; } @@ -1048,7 +1181,7 @@ BOOL_T WriteCompound( */ EXPORT void SetCompoundLineType( track_p trk, int width ) { - struct extraData * xx = GetTrkExtraData(trk); + struct extraDataCompound_t * xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); switch(width) { case 0: xx->lineType = DRAWLINESOLID; @@ -1084,18 +1217,16 @@ EXPORT track_p NewCompound( char * title, EPINX_T epCnt, trkEndPt_t * epp, - DIST_T * radii, - int pathLen, - char * paths, + PATHPTR_T paths, wIndex_t segCnt, trkSeg_p segs ) { track_p trk; - struct extraData * xx; + struct extraDataCompound_t * xx; EPINX_T ep; trk = NewTrack( index, trkType, epCnt, sizeof (*xx) + 1 ); - xx = GetTrkExtraData(trk); + xx = GET_EXTRA_DATA(trk, trkType, extraDataCompound_t); xx->orig = pos; xx->angle = angle; xx->handlaid = FALSE; @@ -1107,12 +1238,7 @@ EXPORT track_p NewCompound( xx->title = MyStrdup( title ); xx->customInfo = NULL; xx->special = TOnormal; - if ( pathLen > 0 ) - xx->paths = memdup( paths, pathLen ); - else - xx->paths = (PATHPTR_T)""; - xx->pathLen = pathLen; - xx->pathCurr = xx->paths; + SetPaths( trk, paths ); xx->segCnt = segCnt; xx->segs = memdup( segs, segCnt * sizeof *segs ); trkSeg_p p = xx->segs; @@ -1120,17 +1246,8 @@ EXPORT track_p NewCompound( FixUpBezierSegs(xx->segs,xx->segCnt); ComputeCompoundBoundingBox( trk ); SetDescriptionOrig( trk ); -// if (radii) { -// xx->special = TOcurved; -// xx->u.curved.radii.max = 0; -// xx->u.curved.radii.cnt = 0; -// DYNARR_SET(DIST_T,xx->u.curved.radii,epCnt); -// } for ( ep=0; ep<epCnt; ep++ ) { SetTrkEndPoint( trk, ep, epp[ep].pos, epp[ep].angle ); -// if (radii) { -// DYNARR_N(DIST_T,xx->u.curved.radii,ep) = radii[ep]; -// } } return trk; } @@ -1141,7 +1258,7 @@ BOOL_T ReadCompound( TRKTYP_T trkType ) { track_p trk; - struct extraData *xx; + struct extraDataCompound_t *xx; TRKINX_T index; BOOL_T visible; coOrd orig; @@ -1154,7 +1271,6 @@ BOOL_T ReadCompound( long options = 0; long position = 0; long lineType = 0; - PATHPTR_T path=NULL; if (paramVersion<3) { if ( !GetArgs( line, "dXsdpfq", @@ -1175,10 +1291,15 @@ BOOL_T ReadCompound( pathCnt = 0; if ( !ReadSegs() ) return FALSE; - path = pathPtr; - if ( tempEndPts_da.cnt > 0 && pathCnt <= 1 ) { - pathCnt = 10; - path = (PATHPTR_T)"Normal\01\0\0"; + if ( trkType == T_TURNOUT ) { + if ( tempEndPts_da.cnt <= 0 ) { + InputError( "Turnout defn without EndPoints", TRUE ); + return FALSE; + } + if ( pathCnt <= 1 ) { + InputError( "Turnout defn without a Path", TRUE ); + return FALSE; + } } if (paramVersion<6 && strlen( title ) > 2) { cp = strchr( title, '\t' ); @@ -1189,7 +1310,9 @@ BOOL_T ReadCompound( UpdateTitleMark( title, LookupScale(scale) ); } } - trk = NewCompound( trkType, index, orig, angle, title, 0, NULL, NULL, pathCnt, (char *)path, tempSegs_da.cnt, &tempSegs(0) ); + trk = NewCompound( trkType, index, orig, angle, title, 0, NULL, + pathCnt > 1 ? pathPtr : NULL, + tempSegs_da.cnt, &tempSegs(0) ); SetEndPts( trk, 0 ); if ( paramVersion < 3 ) { SetTrkVisible(trk, visible!=0); @@ -1203,14 +1326,16 @@ BOOL_T ReadCompound( SetTrkScale(trk, LookupScale( scale )); SetTrkLayer(trk, layer); SetTrkWidth(trk, (int)(options&3)); - xx = GetTrkExtraData(trk); - xx->handlaid = (int)((options&0x08)!=0); - xx->flipped = (int)((options&0x10)!=0); - xx->ungrouped = (int)((options&0x20)!=0); - xx->split = (int)((options&0x40)!=0); + xx = GET_EXTRA_DATA(trk, trkType, extraDataCompound_t); + xx->handlaid = (int)((options&COMPOUND_OPTION_HANDLAID)!=0); + xx->flipped = (int)((options&COMPOUND_OPTION_FLIPPED)!=0); + xx->ungrouped = (int)((options&COMPOUND_OPTION_UNGROUPED)!=0); + xx->split = (int)((options&COMPOUND_OPTION_SPLIT)!=0); + xx->pathOverRide = (int)((options&COMPOUND_OPTION_PATH_OVERRIDE)!=0); + xx->pathNoCombine = (int)((options&COMPOUND_OPTION_PATH_NOCOMBINE)!=0); xx->lineType = lineType; xx->descriptionOff = descriptionOff; - if ( ( options & 0x80 ) != 0 ) + if ( ( options & COMPOUND_OPTION_HIDEDESC ) != 0 ) SetTrkBits( trk, TB_HIDEDESC ); if (tempSpecial[0] != '\0') { @@ -1231,18 +1356,7 @@ BOOL_T ReadCompound( return FALSE; } } - if (pathCnt > 0) { - path = xx->pathCurr; - while ( position-- ) { - path += strlen((char *)path)+1; - while ( path[0] || path[1] ) - path++; - path += 2; - if ( *path == 0 ) - path = xx->paths; - } - } - xx->pathCurr = path; + SetCurrPathIndex( trk, position ); return TRUE; } @@ -1250,7 +1364,7 @@ void MoveCompound( track_p trk, coOrd orig ) { - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); xx->orig.x += orig.x; xx->orig.y += orig.y; ComputeCompoundBoundingBox( trk ); @@ -1262,7 +1376,7 @@ void RotateCompound( coOrd orig, ANGLE_T angle ) { - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); Rotate( &xx->orig, orig, angle ); xx->angle = NormalizeAngle( xx->angle + angle ); Rotate( &xx->descriptionOff, zero, angle ); @@ -1274,7 +1388,7 @@ void RescaleCompound( track_p trk, FLOAT_T ratio ) { - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); xx->orig.x *= ratio; xx->orig.y *= ratio; xx->descriptionOff.x *= ratio; @@ -1290,7 +1404,7 @@ void FlipCompound( coOrd orig, ANGLE_T angle ) { - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCompound_t *xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); EPINX_T ep, epCnt; char * mP, *nP, *pP; int mL, nL, pL; @@ -1405,19 +1519,21 @@ typedef struct { char * type; char * name; FLOAT_T price; + DynString indexes; } enumCompound_t; static dynArr_t enumCompound_da; #define EnumCompound(N) DYNARR_N( enumCompound_t,enumCompound_da,N) BOOL_T EnumerateCompound( track_p trk ) { - struct extraData *xx; + struct extraDataCompound_t *xx; INT_T inx, inx2; int cmp; long listLabelsOption = listLabels; + char * index = MyMalloc(10); if ( trk != NULL ) { - xx = GetTrkExtraData(trk); + xx = GET_EXTRA_DATA(trk, T_NOTRACK, extraDataCompound_t); if ( xx->flipped ) listLabelsOption |= LABEL_FLIPPED; #ifdef LATER @@ -1428,11 +1544,14 @@ BOOL_T EnumerateCompound( track_p trk ) #endif FormatCompoundTitle( listLabelsOption, xtitle(xx) ); if (message[0] == '\0') - return TRUE; + return FALSE; //No content for (inx = 0; inx < enumCompound_da.cnt; inx++ ) { cmp = strcmp( EnumCompound(inx).name, message ); if ( cmp == 0 ) { EnumCompound(inx).count++; + sprintf(index,",%d",GetTrkIndex(trk)); + DynStringCatCStr(&(EnumCompound(inx).indexes),index); + MyFree(index); return TRUE; } else if ( cmp > 0 ) { break; @@ -1443,9 +1562,11 @@ BOOL_T EnumerateCompound( track_p trk ) EnumCompound(inx2) = EnumCompound(inx2-1); EnumCompound(inx).name = MyStrdup( message ); if (strlen(message) > (size_t)enumerateMaxDescLen) - enumerateMaxDescLen = strlen(message); + enumerateMaxDescLen = (int)strlen(message); EnumCompound(inx).type = GetTrkTypeName( trk ); EnumCompound(inx).count = 1; + DynStringMalloc(&(EnumCompound(inx).indexes),100); + DynStringPrintf(&(EnumCompound(inx).indexes),"%d",GetTrkIndex(trk)); FormatCompoundTitle( LABEL_MANUF|LABEL_DESCR|LABEL_PARTNO, xtitle(xx) ); wPrefGetFloat( "price list", message, &(EnumCompound(inx).price), 0.0 ); } else { @@ -1455,12 +1576,15 @@ BOOL_T EnumerateCompound( track_p trk ) if (EnumCompound(inx).type[0] == *type) { EnumerateList( EnumCompound(inx).count, EnumCompound(inx).price, - EnumCompound(inx).name ); + EnumCompound(inx).name, + DynStringSize(&(EnumCompound(inx).indexes))?DynStringToCStr(&(EnumCompound(inx).indexes)):NULL); } + DynStringFree(&(EnumCompound(inx).indexes)); } } DYNARR_RESET( enumCompound_t, enumCompound_da ); } + MyFree(index); return TRUE; } |