diff options
Diffstat (limited to 'app/bin/compound.c')
-rw-r--r-- | app/bin/compound.c | 285 |
1 files changed, 195 insertions, 90 deletions
diff --git a/app/bin/compound.c b/app/bin/compound.c index d1a16f5..627d2ef 100644 --- a/app/bin/compound.c +++ b/app/bin/compound.c @@ -38,6 +38,7 @@ #include "track.h" #include "utility.h" #include "messages.h" +#include "include/paramfile.h" /***************************************************************************** * @@ -45,6 +46,25 @@ * */ +//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) { + + 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--; + } + } + SetSegInxEP(&new_pp,j,old_EP); + return new_pp; + +} + BOOL_T WriteCompoundPathsEndPtsSegs( FILE * f, PATHPTR_T paths, @@ -55,11 +75,12 @@ BOOL_T WriteCompoundPathsEndPtsSegs( { int i; 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", *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; } for ( i=0; i<endPtCnt; i++ ) @@ -315,7 +336,7 @@ void DrawCompoundDescription( return; if ((labelEnable&LABELENABLE_TRKDESC)==0) return; - if ( (d->options&DC_GROUP) ) + if ( (d->options&DC_SIMPLE) ) return; if ( xx->special == TOpier ) { desc = xx->u.pier.name; @@ -340,18 +361,25 @@ void DrawCompoundDescription( DIST_T CompoundDescriptionDistance( coOrd pos, - track_p trk ) + track_p trk, + coOrd * dpos, + 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; - if ( (GetTrkBits( trk ) & TB_HIDEDESC) != 0 ) + if ( ((GetTrkBits( trk ) & TB_HIDEDESC) != 0 ) && !show_hidden) return 100000; p1 = xx->descriptionOrig; + coOrd offset = xx->descriptionOff; + if ( (GetTrkBits( trk ) & TB_HIDEDESC) != 0 ) offset = zero; Rotate( &p1, zero, xx->angle ); - p1.x += xx->orig.x + xx->descriptionOff.x; - p1.y += xx->orig.y + xx->descriptionOff.y; + p1.x += xx->orig.x + offset.x; + p1.y += xx->orig.y + offset.y; + if (hidden) *hidden = (GetTrkBits( trk ) & TB_HIDEDESC); + *dpos = p1; return FindDistance( p1, pos ); } @@ -370,6 +398,7 @@ STATUS_T CompoundDescriptionMove( case C_DOWN: editMode = TRUE; REORIGIN( p0, xx->descriptionOrig, xx->angle, xx->orig ) + DrawCompoundDescription( trk, &mainD, wDrawColorWhite ); case C_MOVE: case C_UP: @@ -383,13 +412,15 @@ STATUS_T CompoundDescriptionMove( if (action == C_UP) { editMode = FALSE; } - MainRedraw(); - MapRedraw(); + if ( action == C_UP ) { + DrawCompoundDescription( trk, &mainD, color ); + } return action==C_UP?C_TERMINATE:C_CONTINUE; break; case C_REDRAW: if (editMode) { - DrawLine( &tempD, p0, p1, 0, wDrawColorBlack ); + DrawCompoundDescription( trk, &tempD, wDrawColorBlue ); + DrawLine( &tempD, p0, p1, 0, wDrawColorBlue ); } } @@ -405,6 +436,18 @@ STATUS_T CompoundDescriptionMove( * */ +EXPORT void SetSegInxEP( + signed char * segChar, + int segInx, + EPINX_T segEP ) +{ + if (segEP == 1) { + * segChar = -(segInx+1); + } else { + * segChar = (segInx+1); + } + +} EXPORT void GetSegInxEP( signed char segChar, @@ -482,6 +525,7 @@ static struct { FLOAT_T elev[4]; coOrd orig; ANGLE_T angle; + descPivot_t pivot; char manuf[STR_SIZE]; char name[STR_SIZE]; char partno[STR_SIZE]; @@ -490,9 +534,10 @@ static struct { long pathCnt; FLOAT_T grade; DIST_T length; + drawLineType_e linetype; unsigned int layerNumber; } compoundData; -typedef enum { E0, A0, C0, R0, Z0, E1, A1, C1, R1, Z1, E2, A2, C2, R2, Z2, E3, A3, C3, R3, Z3, GR, OR, AN, MN, NM, PN, EC, SC, LY } compoundDesc_e; +typedef enum { E0, A0, C0, R0, Z0, E1, A1, C1, R1, Z1, E2, A2, C2, R2, Z2, E3, A3, C3, R3, Z3, GR, OR, AN, PV, MN, NM, PN, LT, SC, LY } compoundDesc_e; static descData_t compoundDesc[] = { /*E0*/ { DESC_POS, N_("End Pt 1: X,Y"), &compoundData.endPt[0] }, /*A0*/ { DESC_ANGLE, N_("Angle"), &compoundData.endAngle[0] }, @@ -517,10 +562,11 @@ static descData_t compoundDesc[] = { /*GR*/ { DESC_FLOAT, N_("Grade"), &compoundData.grade }, /*OR*/ { DESC_POS, N_("Origin: X,Y"), &compoundData.orig }, /*AN*/ { DESC_ANGLE, N_("Angle"), &compoundData.angle }, +/*PV*/ { DESC_PIVOT, N_("Pivot"), &compoundData.pivot }, /*MN*/ { DESC_STRING, N_("Manufacturer"), &compoundData.manuf, sizeof(compoundData.manuf)}, /*NM*/ { DESC_STRING, N_("Name"), &compoundData.name, sizeof(compoundData.name) }, /*PN*/ { DESC_STRING, N_("Part No"), &compoundData.partno, sizeof(compoundData.partno)}, -/*EC*/ { DESC_LONG, N_("# End Pts"), &compoundData.epCnt }, +/*LT*/ { DESC_LIST, N_("LineType"), &compoundData.linetype }, /*SC*/ { DESC_LONG, N_("# Segments"), &compoundData.segCnt }, /*LY*/ { DESC_LAYER, N_("Layer"), &compoundData.layerNumber }, { DESC_NULL } }; @@ -539,7 +585,11 @@ static void UpdateCompound( track_p trk, int inx, descData_p descUpd, BOOL_T nee BOOL_T titleChanged, flipped, ungrouped, split; char * newTitle; - if ( inx == -1 ) { + switch ( inx ) { + case -1: + case MN: + case NM: + case PN: titleChanged = FALSE; ParseCompoundTitle( xtitle(xx), &mP, &mL, &nP, &nL, &pP, &pL ); if (mP == NULL) mP = ""; @@ -616,7 +666,7 @@ static void UpdateCompound( track_p trk, int inx, descData_p descUpd, BOOL_T nee GetBoundingBox( trk, &hi, &lo ); if ( labelScale >= mainD.scale && !OFF_MAIND( lo, hi ) ) { - DrawCompoundDescription( trk, &tempD, GetTrkColor(trk,&tempD) ); + DrawCompoundDescription( trk, &mainD, wDrawColorWhite ); } /*sprintf( message, "%s\t%s\t%s", manufS, nameS, partnoS );*/ if (xx->title) MyFree(xx->title); @@ -626,12 +676,13 @@ static void UpdateCompound( track_p trk, int inx, descData_p descUpd, BOOL_T nee xx->split = split; if ( labelScale >= mainD.scale && !OFF_MAIND( lo, hi ) ) { - DrawCompoundDescription( trk, &tempD, GetTrkColor(trk,&tempD) ); + DrawCompoundDescription( trk, &mainD, GetTrkColor(trk,&tempD) ); } return; } UndrawNewTrack( trk ); + coOrd orig; switch ( inx ) { case OR: pos.x = compoundData.orig.x - xx->orig.x; @@ -643,17 +694,31 @@ static void UpdateCompound( track_p trk, int inx, descData_p descUpd, BOOL_T nee case A1: case A2: case A3: - if (inx==E3) ep=3; - else if (inx==E2) ep=2; - else if (inx==E1) ep=1; + if (inx==A3) ep=3; + else if (inx==A2) ep=2; + else if (inx==A1) ep=1; else ep=0; - RotateTrack( trk, xx->orig, NormalizeAngle( compoundData.endAngle[ep]-xx->angle ) ); + RotateTrack( trk, GetTrkEndPos(trk,ep), NormalizeAngle( compoundData.endAngle[ep]-GetTrkEndAngle(trk,ep) ) ); ComputeCompoundBoundingBox( trk ); - compoundData.angle = xx->angle; - compoundDesc[AN].mode |= DESC_CHANGE; break; case AN: - RotateTrack( trk, xx->orig, NormalizeAngle( compoundData.angle-xx->angle ) ); + orig = xx->orig; + GetBoundingBox(trk,&hi,&lo); + switch (compoundData.pivot) { + case DESC_PIVOT_MID: + orig.x = (hi.x-lo.x)/2+lo.x; + orig.y = (hi.y-lo.y)/2+lo.y; + break; + case DESC_PIVOT_SECOND: + orig.x = (hi.x-lo.x)/2+lo.x; + orig.y = (hi.y-lo.y)/2+lo.y; + orig.x = (orig.x - xx->orig.x)*2+xx->orig.x; + orig.y = (orig.y - xx->orig.y)*2+xx->orig.y; + break; + default: + break; + } + RotateTrack( trk, orig, NormalizeAngle( compoundData.angle-xx->angle ) ); ComputeCompoundBoundingBox( trk ); break; case E0: @@ -680,7 +745,7 @@ static void UpdateCompound( track_p trk, int inx, descData_p descUpd, BOOL_T nee break; for (int i=0;i<compoundData.epCnt;i++) { if (i==ep) continue; - ComputeElev( trk, i, FALSE, &compoundData.elev[i], NULL ); + ComputeElev( trk, i, FALSE, &compoundData.elev[i], NULL, TRUE ); } if ( compoundData.length > minLength ) compoundData.grade = fabs( (compoundData.elev[0]-compoundData.elev[1])/compoundData.length )*100.0; @@ -719,6 +784,13 @@ static void UpdateCompound( track_p trk, int inx, descData_p descUpd, BOOL_T nee compoundDesc[i*(E1-E0)+C0].mode |= DESC_CHANGE; } } + compoundData.orig = xx->orig; + compoundDesc[OR].mode |= DESC_CHANGE; + compoundData.angle = xx->angle; + compoundDesc[AN].mode |= DESC_CHANGE; + break; + case LT: + xx->lineType = compoundData.linetype; break; default: break; @@ -839,9 +911,10 @@ void DescribeCompound( compoundDesc[MN].mode = compoundDesc[NM].mode = compoundDesc[PN].mode = 0 /*DESC_NOREDRAW*/; - compoundDesc[EC].mode = compoundDesc[SC].mode = DESC_RO; compoundDesc[LY].mode = DESC_NOREDRAW; + compoundDesc[PV].mode = 0; + compoundData.pivot = DESC_PIVOT_FIRST; if (compoundData.epCnt >0) { for (int i=0;(i<compoundData.epCnt)&&(i<MAX_DESCRIBE_ENDS);i++) { compoundDesc[A0+(E1-E0)*i].mode = (int)mode; @@ -859,18 +932,37 @@ void DescribeCompound( compoundDesc[C0+(E1-E0)*i].mode = DESC_IGNORE; compoundDesc[R0+(E1-E0)*i].mode = DESC_IGNORE; } - ComputeElev( trk, i, FALSE, &compoundData.elev[i], NULL ); + ComputeElev( trk, i, FALSE, &compoundData.elev[i], NULL, FALSE ); compoundDesc[Z0+(E1-E0)*i].mode = (EndPtIsDefinedElev(trk,i)?0:DESC_RO)|DESC_NOREDRAW; } compoundDesc[GR].mode = DESC_RO; } + if ( compoundData.epCnt == 2 ) + compoundData.length = GetTrkLength( trk, 0, 1 ); if ( compoundData.length > minLength && compoundData.epCnt > 1) compoundData.grade = fabs( (compoundData.elev[0]-compoundData.elev[1])/compoundData.length )*100.0; else compoundData.grade = 0.0; + if (GetTrkEndPtCnt(trk) == 0) { + compoundDesc[LT].mode = 0; + } else + compoundDesc[LT].mode = DESC_IGNORE; + DoDescribe(trackType, trk, compoundDesc, UpdateCompound); + 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 ); + wListSetIndex( (wList_p)compoundDesc[LT].control0, compoundData.linetype ); + } + } @@ -880,6 +972,7 @@ void DeleteCompound( struct extraData *xx = GetTrkExtraData(t); FreeFilledDraw( xx->segCnt, xx->segs ); MyFree( xx->segs ); + xx->segs = NULL; } @@ -891,6 +984,7 @@ BOOL_T WriteCompound( EPINX_T ep, epCnt; long options; long position = 0; + drawLineType_e lineType = 0; PATHPTR_T path; BOOL_T rc = TRUE; @@ -918,10 +1012,11 @@ BOOL_T WriteCompound( position++; } } - rc &= fprintf(f, "%s %d %d %ld %ld 0 %s %d %0.6f %0.6f 0 %0.6f \"%s\"\n", + 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, - GetTrkScaleName(t), GetTrkVisible(t), + GetTrkIndex(t), GetTrkLayer(t), options, position, 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; for (ep=0; ep<epCnt; ep++ ) @@ -933,6 +1028,8 @@ BOOL_T WriteCompound( break; case TOpier: rc &= fprintf( f, "\tX %s %0.6f \"%s\"\n", PIER, xx->u.pier.height, xx->u.pier.name )>0; + break; + default: ; } @@ -950,6 +1047,34 @@ BOOL_T WriteCompound( * */ +EXPORT void SetCompoundLineType( track_p trk, int width ) { + struct extraData * xx = GetTrkExtraData(trk); + switch(width) { + case 0: + xx->lineType = DRAWLINESOLID; + break; + case 1: + xx->lineType = DRAWLINEDASH; + break; + case 2: + xx->lineType = DRAWLINEDOT; + break; + case 3: + xx->lineType = DRAWLINEDASHDOT; + break; + case 4: + xx->lineType = DRAWLINEDASHDOTDOT; + break; + case 5: + xx->lineType = DRAWLINECENTER; + break; + case 6: + xx->lineType = DRAWLINEPHANTOM; + break; + } +} + + EXPORT track_p NewCompound( TRKTYP_T trkType, @@ -959,6 +1084,7 @@ EXPORT track_p NewCompound( char * title, EPINX_T epCnt, trkEndPt_t * epp, + DIST_T * radii, int pathLen, char * paths, wIndex_t segCnt, @@ -994,13 +1120,23 @@ EXPORT track_p NewCompound( FixUpBezierSegs(xx->segs,xx->segCnt); ComputeCompoundBoundingBox( trk ); SetDescriptionOrig( trk ); - for ( ep=0; ep<epCnt; ep++ ) +// 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; } -void ReadCompound( +BOOL_T ReadCompound( char * line, TRKTYP_T trkType ) { @@ -1017,26 +1153,28 @@ void ReadCompound( char *cp; long options = 0; long position = 0; + long lineType = 0; PATHPTR_T path=NULL; if (paramVersion<3) { if ( !GetArgs( line, "dXsdpfq", &index, &layer, scale, &visible, &orig, &angle, &title ) ) - return; + return FALSE; } else if (paramVersion <= 5 && trkType == T_STRUCTURE) { if ( !GetArgs( line, "dL00sdpfq", &index, &layer, scale, &visible, &orig, &angle, &title ) ) - return; + return FALSE; } else { - if ( !GetArgs( line, paramVersion<9?"dLll0sdpYfq":"dLll0sdpffq", - &index, &layer, &options, &position, scale, &visible, &orig, &elev, &angle, &title ) ) - return; + if ( !GetArgs( line, paramVersion<9?"dLlldsdpYfq":"dLlldsdpffq", + &index, &layer, &options, &position, &lineType, scale, &visible, &orig, &elev, &angle, &title ) ) + return FALSE; } if (paramVersion >=3 && paramVersion <= 5 && trkType == T_STRUCTURE) strcpy( scale, curScaleName ); DYNARR_RESET( trkEndPt_t, tempEndPts_da ); pathCnt = 0; - ReadSegs(); + if ( !ReadSegs() ) + return FALSE; path = pathPtr; if ( tempEndPts_da.cnt > 0 && pathCnt <= 1 ) { pathCnt = 10; @@ -1051,9 +1189,17 @@ void ReadCompound( UpdateTitleMark( title, LookupScale(scale) ); } } - trk = NewCompound( trkType, index, orig, angle, title, 0, NULL, pathCnt, (char *)path, tempSegs_da.cnt, &tempSegs(0) ); + trk = NewCompound( trkType, index, orig, angle, title, 0, NULL, NULL, pathCnt, (char *)path, tempSegs_da.cnt, &tempSegs(0) ); SetEndPts( trk, 0 ); - SetTrkVisible(trk, visible); + if ( paramVersion < 3 ) { + SetTrkVisible(trk, visible!=0); + SetTrkNoTies(trk, FALSE); + SetTrkBridge(trk, FALSE); + } else { + SetTrkVisible(trk, visible&2); + SetTrkNoTies(trk, visible&4); + SetTrkBridge(trk, visible&8); + } SetTrkScale(trk, LookupScale( scale )); SetTrkLayer(trk, layer); SetTrkWidth(trk, (int)(options&3)); @@ -1062,68 +1208,27 @@ void ReadCompound( xx->flipped = (int)((options&0x10)!=0); xx->ungrouped = (int)((options&0x20)!=0); xx->split = (int)((options&0x40)!=0); + xx->lineType = lineType; xx->descriptionOff = descriptionOff; if ( ( options & 0x80 ) != 0 ) SetTrkBits( trk, TB_HIDEDESC ); -#ifdef LATER - trk = NewTrack( index, trkType, 0, sizeof (*xx) + 1 ); - SetEndPts( trk, 0 ); - xx = GetTrkExtraData(trk); - SetTrkVisible(trk, visible); - SetTrkScale(trk, LookupScale( scale )); - SetTrkLayer(trk, layer); - SetTrkWidth(trk, (int)(options&3)); - xx->orig = orig; - xx->angle = angle; - xx->customInfo = NULL; - xx->handlaid = (int)((options>>3)&0x01); - xx->flipped = (int)((options>>4)&0x01); - xx->segCnt = tempSegs_da.cnt; - xx->segs = MyMalloc( (tempSegs_da.cnt)*sizeof xx->segs[0] ); - if (paramVersion<6 && strlen( title ) > 2) { - cp = strchr( title, '\t' ); - if (cp != NULL) { - cp = strchr( cp, '\t' ); - } - if (cp == NULL) { - UpdateTitleMark(title, GetTrkScale(trk)); - } - } - xx->title = title; - if ( GetTrkEndPtCnt(trk) > 0 && pathCnt <= 1 ) { - xx->pathLen = 10; - xx->paths = xx->pathCurr = (PATHPTR_T)Malloc( xx->pathLen ); - memcpy( xx->paths, "Normal\01\0\0", xx->pathLen ); - } else { - xx->pathLen = pathCnt; - if (pathCnt > 0) { - xx->paths = xx->pathCurr = (PATHPTR_T)Malloc( pathCnt ); - memcpy( xpaths(xx), pathPtr, pathCnt ); - } else { - xx->paths = xx->pathCurr = NULL; - } - } - xx->segCnt = tempSegs_da.cnt; - memcpy( xx->segs, tempSegs_da.ptr, tempSegs_da.cnt * sizeof *xx->segs ); - - ComputeCompoundBoundingBox( trk ); - SetDescriptionOrig( trk ); - xx->descriptionOff = descriptionOff; -#endif if (tempSpecial[0] != '\0') { if (strncmp( tempSpecial, ADJUSTABLE, strlen(ADJUSTABLE) ) == 0) { xx->special = TOadjustable; - GetArgs( tempSpecial+strlen(ADJUSTABLE), "ff", - &xx->u.adjustable.minD, &xx->u.adjustable.maxD ); + if ( !GetArgs( tempSpecial+strlen(ADJUSTABLE), "ff", + &xx->u.adjustable.minD, &xx->u.adjustable.maxD ) ) + return FALSE; } else if (strncmp( tempSpecial, PIER, strlen(PIER) ) == 0) { xx->special = TOpier; - GetArgs( tempSpecial+strlen(PIER), "fq", - &xx->u.pier.height, &xx->u.pier.name ); + if ( !GetArgs( tempSpecial+strlen(PIER), "fq", + &xx->u.pier.height, &xx->u.pier.name ) ) + return FALSE; } else { InputError("Unknown special case", TRUE); + return FALSE; } } if (pathCnt > 0) { @@ -1138,7 +1243,7 @@ void ReadCompound( } } xx->pathCurr = path; - + return TRUE; } void MoveCompound( @@ -1217,12 +1322,12 @@ void FlipCompound( mP && strcmp( mP, mfg ) == 0 && nP && pP ) { if ( strcmp( nP, descL ) == 0 && strcmp( pP, partL ) == 0 ) { sprintf( message, "%s\t%s\t%s", mfg, descR, partR ); - xx->title = strdup( message ); + xx->title = MyStrdup( message ); return; } if ( strcmp( nP, descR ) == 0 && strcmp( pP, partR ) == 0 ) { sprintf( message, "%s\t%s\t%s", mfg, descL, partL ); - xx->title = strdup( message ); + xx->title = MyStrdup( message ); return; } } |