summaryrefslogtreecommitdiff
path: root/app/bin/cstruct.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2022-02-06 16:04:24 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2022-02-06 16:04:24 +0100
commit5d2c2b27a6323e2666378b986129b2a7c2c39e5c (patch)
treece8982b6c0111f79791068de2c2d4c6ce3138a49 /app/bin/cstruct.c
parentb623f5953691b2a0614e6f1f4def86bdbb9a4113 (diff)
New upstream version 5.2.2GAupstream/5.2.2GA
Diffstat (limited to 'app/bin/cstruct.c')
-rw-r--r--app/bin/cstruct.c173
1 files changed, 97 insertions, 76 deletions
diff --git a/app/bin/cstruct.c b/app/bin/cstruct.c
index 6907e2c..fc13924 100644
--- a/app/bin/cstruct.c
+++ b/app/bin/cstruct.c
@@ -20,30 +20,23 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include <ctype.h>
-#include <math.h>
-#include <stdint.h>
-#include <string.h>
-
#include "compound.h"
+#include "cselect.h"
#include "cundo.h"
#include "custom.h"
#include "fileio.h"
-#include "i18n.h"
#include "layout.h"
-#include "messages.h"
#include "param.h"
+#include "cselect.h"
#include "include/paramfile.h"
#include "track.h"
-#include "utility.h"
#include "ccurve.h"
+#include "common-ui.h"
EXPORT TRKTYP_T T_STRUCTURE = -1;
EXPORT dynArr_t structureInfo_da;
-typedef struct compoundData extraData;
-
static wIndex_t pierListInx;
EXPORT turnoutInfo_t * curStructure = NULL;
@@ -63,13 +56,13 @@ static drawCmd_t structureD = {
static wIndex_t structureHotBarCmdInx;
static wIndex_t structureInx;
static long hideStructureWindow;
-static void RedrawStructure(void);
+static void RedrawStructure( wDraw_p d, void * context, wWinPix_t x, wWinPix_t y );
-static wPos_t structureListWidths[] = { 80, 80, 220 };
+static wWinPix_t structureListWidths[] = { 80, 80, 220 };
static const char * structureListTitles[] = { N_("Manufacturer"), N_("Part No"), N_("Description") };
static paramListData_t listData = { 13, 400, 3, structureListWidths, structureListTitles };
static const char * hideLabels[] = { N_("Hide"), NULL };
-static paramDrawData_t structureDrawData = { 490, 200, (wDrawRedrawCallBack_p)RedrawStructure, NULL, &structureD };
+static paramDrawData_t structureDrawData = { 490, 200, RedrawStructure, NULL, &structureD };
static paramData_t structurePLs[] = {
#define I_LIST (0)
#define structureListL ((wList_p)structurePLs[I_LIST].control)
@@ -77,14 +70,14 @@ static paramData_t structurePLs[] = {
#define I_DRAW (1)
{ PD_DRAW, NULL, "canvas", PDO_NOPSHUPD|PDO_DLGUNDERCMDBUTT|PDO_DLGRESIZE, &structureDrawData, NULL, 0 },
#define I_HIDE (2)
- { PD_TOGGLE, &hideStructureWindow, "hide", PDO_DLGCMDBUTTON, /*CAST_AWAY_CONST*/(void*)hideLabels, NULL, BC_NOBORDER },
+ { PD_TOGGLE, &hideStructureWindow, "hide", PDO_DLGCMDBUTTON, hideLabels, NULL, BC_NOBORDER },
#define I_MSGSCALE (3)
- { PD_MESSAGE, NULL, NULL, 0, (void*)80 },
+ { PD_MESSAGE, NULL, NULL, 0, I2VP(80) },
#define I_MSGWIDTH (4)
- { PD_MESSAGE, NULL, NULL, 0, (void*)80 },
+ { PD_MESSAGE, NULL, NULL, 0, I2VP(80) },
#define I_MSGHEIGHT (5)
- { PD_MESSAGE, NULL, NULL, 0, (void*)80 } };
-static paramGroup_t structurePG = { "structure", 0, structurePLs, sizeof structurePLs/sizeof structurePLs[0] };
+ { PD_MESSAGE, NULL, NULL, 0, I2VP(80) } };
+static paramGroup_t structurePG = { "structure", 0, structurePLs, COUNT( structurePLs ) };
@@ -136,8 +129,7 @@ EXPORT turnoutInfo_t * CreateNewStructure(
else
to->contentsLabel = curSubContents;
to->endCnt = 0;
- to->pathLen = 0;
- to->paths = (PATHPTR_T)"";
+ SetParamPaths( to, NULL );
if (updateList && structureListL != NULL) {
FormatCompoundTitle( LABEL_TABBED|LABEL_MANUF|LABEL_PARTNO|LABEL_DESCR, to->title );
if (message[0] != '\0')
@@ -162,6 +154,25 @@ StructureDelete(void *structure)
MyFree(to->title);
MyFree(to->segs);
+ if (to->special) {
+ switch(to->special) {
+ case TOpier:
+ MyFree(to->u.pier.name);
+ to->u.pier.name = NULL;
+ break;
+ case TOpierInfo:
+ for(int pierInx=0;pierInx<to->u.pierInfo.cnt;pierInx++) {
+ if (to->u.pierInfo.info[pierInx].name)
+ MyFree(to->u.pierInfo.info[pierInx].name);
+ to->u.pierInfo.info[pierInx].name = NULL;
+ }
+ MyFree(to->u.pierInfo.info);
+ to->u.pierInfo.cnt = 0;
+ break;
+ default:;
+ }
+ }
+
MyFree(to);
return(TRUE);
}
@@ -207,6 +218,17 @@ DeleteStructures(int fileIndex)
structureInfo_da.cnt -= cnt;
}
+/**
+ * Check to find out to what extent the contents of the parameter file can be used with
+ * the current layout scale / gauge.
+ *
+ * If parameter scale == layout we have an exact fit.
+ * If parameter scale == layout scale +/15% we have compatible track.
+ *
+ * \param paramFileIndex
+ * \param scaleIndex
+ * \return
+ */
enum paramFileState
GetStructureCompatibility(int paramFileIndex, SCALEINX_T scaleIndex)
{
@@ -218,14 +240,22 @@ GetStructureCompatibility(int paramFileIndex, SCALEINX_T scaleIndex)
return(PARAMFILE_UNLOADED);
}
+ //Loop over all entries until an exact fit is found if none return if compatibles were found
+
for (i = 0; i < structureInfo_da.cnt; i++) {
turnoutInfo_t *to = structureInfo(i);
if (to->paramFileIndex == paramFileIndex) {
- if (GetScaleRatio(to->scaleInx) == ratio || to->scaleInx == SCALE_ANY) {
+ SCALE_FIT_T fit = CompatibleScale(FIT_STRUCTURE,to->scaleInx,scaleIndex);
+ if (fit == FIT_EXACT) {
ret = PARAMFILE_FIT;
break;
- }
+ }
+ //Within 15% of scale
+ if (fit == FIT_COMPATIBLE) {
+ ret = PARAMFILE_COMPATIBLE;
+ }
}
+
}
return(ret);
}
@@ -281,7 +311,7 @@ EXPORT turnoutInfo_t * StructAdd( long mode, SCALEINX_T scale, wList_p list, coO
to = structureInfo(inx);
if ( IsParamValid(to->paramFileIndex) &&
to->segCnt > 0 &&
- CompatibleScale( FALSE, to->scaleInx, scale ) &&
+ (FIT_NONE != CompatibleScale( FIT_STRUCTURE, to->scaleInx, scale )) &&
to->segCnt != 0 ) {
if (to1 == NULL)
to1 = to;
@@ -316,7 +346,7 @@ static void DrawStructure(
drawCmd_p d,
wDrawColor color )
{
- struct extraData *xx = GetTrkExtraData(t);
+ struct extraDataCompound_t *xx = GET_EXTRA_DATA(t, T_STRUCTURE, extraDataCompound_t);
d->options &= ~DC_NOTSOLIDLINE;
switch(xx->lineType) {
@@ -365,7 +395,7 @@ static ANGLE_T GetAngleStruct(
EPINX_T * ep0,
EPINX_T * ep1 )
{
- struct extraData * xx = GetTrkExtraData(trk);
+ struct extraDataCompound_t * xx = GET_EXTRA_DATA(trk, T_STRUCTURE, extraDataCompound_t);
ANGLE_T angle;
pos.x -= xx->orig.x;
@@ -393,8 +423,8 @@ static BOOL_T QueryStructure( track_p trk, int query )
static wBool_t CompareStruct( track_cp trk1, track_cp trk2 )
{
- struct extraData *xx1 = GetTrkExtraData( trk1 );
- struct extraData *xx2 = GetTrkExtraData( trk2 );
+ struct extraDataCompound_t *xx1 = GET_EXTRA_DATA( trk1, T_STRUCTURE, extraDataCompound_t );
+ struct extraDataCompound_t *xx2 = GET_EXTRA_DATA( trk2, T_STRUCTURE, extraDataCompound_t );
char * cp = message + strlen(message);
REGRESS_CHECK_POS( "Orig", xx1, xx2, orig )
REGRESS_CHECK_ANGLE( "Angle", xx1, xx2, angle )
@@ -446,8 +476,8 @@ static trackCmd_t structureCmds = {
CompareStruct };
static paramData_t pierPLs[] = {
- { PD_DROPLIST, &pierListInx, "inx", 0, (void*)50, N_("Pier Number") } };
-static paramGroup_t pierPG = { "structure-pier", 0, pierPLs, sizeof pierPLs/sizeof pierPLs[0] };
+ { PD_DROPLIST, &pierListInx, "inx", 0, I2VP(50), N_("Pier Number") } };
+static paramGroup_t pierPG = { "structure-pier", 0, pierPLs, COUNT( pierPLs ) };
#define pierL ((wList_p)pierPLs[0].control)
static void ShowPierL( void )
@@ -495,7 +525,7 @@ static wWin_p structureW;
static void RescaleStructure( void )
{
DIST_T xscale, yscale;
- wPos_t ww, hh;
+ wWinPix_t ww, hh;
DIST_T w, h;
wDrawGetSize( structureD.d, &ww, &hh );
w = ww/structureD.dpi - 0.2;
@@ -540,13 +570,13 @@ static void structureChange( long changes )
maxStructureDim.x += 2*trackGauge;
maxStructureDim.y += 2*trackGauge;
/*RescaleStructure();*/
- RedrawStructure();
+ RedrawStructure( structureD.d, NULL, 0, 0 );
return;
}
-static void RedrawStructure()
+static void RedrawStructure( wDraw_p d, void * context, wWinPix_t x, wWinPix_t y )
{
RescaleStructure();
LOG( log_structure, 2, ( "SelStructure(%s)\n", (curStructure?curStructure->title:"<NULL>") ) )
@@ -578,8 +608,8 @@ static void StructureDlgUpdate(
NewStructure();
curStructure = to;
ShowPierL();
- RedrawStructure();
- ParamDialogOkActive( &structurePG, FALSE );
+ RedrawStructure( structureD.d, NULL, 0, 0 );
+ /* ParamDialogOkActive( &structurePG, FALSE ); */
}
@@ -689,8 +719,7 @@ static ANGLE_T PlaceStructure(
static void NewStructure( void )
{
track_p trk;
- struct extraData *xx;
- wIndex_t titleLen;
+ struct extraDataCompound_t *xx;
wIndex_t pierInx;
if (curStructure->segCnt < 1) {
@@ -704,23 +733,8 @@ static void NewStructure( void )
return;
}
UndoStart( _("Place Structure"), "newStruct" );
- titleLen = strlen( curStructure->title );
- trk = NewCompound( T_STRUCTURE, 0, Dst.pos, Dst.angle, curStructure->title, 0, NULL, NULL, 0, "", curStructure->segCnt, curStructure->segs );
- xx = GetTrkExtraData(trk);
-#ifdef LATER
- trk = NewTrack( 0, T_STRUCTURE, 0, sizeof (*xx) + 1 );
- xx->orig = Dst.pos;
- xx->angle = Dst.angle;
- xx->segs = MyMalloc( (curStructure->segCnt)*sizeof curStructure->segs[0] );
-
- /*
- * copy data */
- xx->segCnt = curStructure->segCnt;
- memcpy( xx->segs, curStructure->segs, xx->segCnt * sizeof *(trkSeg_p)0 );
- xx->title = curStructure->title;
- xx->pathLen = 0;
- xx->paths = "";
-#endif
+ trk = NewCompound( T_STRUCTURE, 0, Dst.pos, Dst.angle, curStructure->title, 0, NULL, NULL, curStructure->segCnt, curStructure->segs );
+ xx = GET_EXTRA_DATA(trk, T_STRUCTURE, extraDataCompound_t);
switch(curStructure->special) {
case TOnormal:
xx->special = TOnormal;
@@ -747,13 +761,6 @@ static void NewStructure( void )
SetTrkVisible( trk, TRUE );
SetTrkNoTies( trk, FALSE);
SetTrkBridge( trk, FALSE);
-#ifdef LATER
- ComputeCompoundBoundingBox( trk );
-
- SetDescriptionOrig( trk );
- xx->descriptionOff = zero;
- xx->descriptionSize = zero;
-#endif
DrawNewTrack( trk );
/*DrawStructure( trk, &mainD, wDrawColorBlack, 0 );*/
@@ -768,7 +775,7 @@ static void StructRotate( void * pangle )
{
if (Dst.state == 0)
return;
- ANGLE_T angle = (ANGLE_T)(long)pangle;
+ ANGLE_T angle = (ANGLE_T)VP2L(pangle);
angle /= 1000.0;
Dst.pos = cmdMenuPos;
Rotate( &Dst.pos, cmdMenuPos, angle );
@@ -796,7 +803,7 @@ EXPORT STATUS_T CmdStructureAction(
Dst.state = 0;
Dst.angle = 00.0;
ShowPierL();
- InfoMessage(_("Left-Drag to place, Ctrl+Left-Drag or Right-Drag to Rotate, Space or Enter to accept, Esc to Cancel"));
+ SetAllTrackSelect( FALSE );
return C_CONTINUE;
case wActionMove:
@@ -849,7 +856,7 @@ EXPORT STATUS_T CmdStructureAction(
DYNARR_RESET(trkSeg_t,anchors_da);
if ( curStructure == NULL ) return C_CONTINUE;
rot1 = pos;
- if ( FindDistance( rot0, rot1 ) > (6.0/75.0)*mainD.scale ) {
+ if ( FindDistance( rot0, rot1 ) > (6.0/BASE_DPI)*mainD.scale ) {
angle = FindAngle( rot0, rot1 );
if (!validAngle) {
baseAngle = angle;
@@ -880,16 +887,25 @@ EXPORT STATUS_T CmdStructureAction(
return C_CONTINUE;
case C_REDRAW:
+ wSetCursor(mainD.d,defaultCursor);
if (Dst.state)
DrawSegs( &tempD, Dst.pos, Dst.angle,
- curStructure->segs, curStructure->segCnt, 0.0, wDrawColorBlue );
+ curStructure->segs, curStructure->segCnt, 0.0, selectedColor );
if (anchors_da.cnt>0) {
DrawSegs( &tempD, zero, 0.0, &anchors(0), anchors_da.cnt, trackGauge, wDrawColorBlack );
+ wSetCursor(mainD.d,wCursorNone);
}
if (Dst.state == 2)
DrawLine( &tempD, rot0, rot1, 0, wDrawColorBlack );
return C_CONTINUE;
+ case C_LCLICK:
+ DYNARR_RESET(trkSeg_t,anchors_da);
+ if ( curStructure == NULL ) return C_CONTINUE;
+ CmdStructureAction( C_DOWN, pos );
+ CmdStructureAction( C_UP, pos );
+ return C_CONTINUE;
+
case C_CANCEL:
DYNARR_RESET(trkSeg_t,anchors_da);
Dst.state = 0;
@@ -934,7 +950,7 @@ static STATUS_T CmdStructure(
case C_START:
if (structureW == NULL) {
- structureW = ParamCreateDialog( &structurePG, MakeWindowTitle(_("Structure")), _("Ok"), (paramActionOkProc)DoStructOk, (paramActionCancelProc)Reset, TRUE, NULL, F_RESIZE, StructureDlgUpdate );
+ structureW = ParamCreateDialog( &structurePG, MakeWindowTitle(_("Structure")), _("Close"), (paramActionOkProc)DoStructOk, wHide, TRUE, NULL, F_RESIZE, StructureDlgUpdate );
RegisterChangeNotification( structureChange );
}
ParamDialogOkActive( &structurePG, FALSE );
@@ -949,11 +965,12 @@ static STATUS_T CmdStructure(
if (structureIndex > 0 && structurePtr) {
curStructure = structurePtr;
wListSetIndex( structureListL, structureIndex );
- RedrawStructure();
+ RedrawStructure( structureD.d, NULL, 0, 0 );
}
InfoMessage( _("Select Structure and then drag to place"));
ParamLoadControls( &structurePG );
ParamGroupRecord( &structurePG );
+ SetAllTrackSelect( FALSE );
return CmdStructureAction( action, pos );
case wActionMove:
@@ -993,6 +1010,10 @@ static STATUS_T CmdStructure(
return CmdStructureAction( action, pos );
return C_CONTINUE;
+ case C_LCLICK:
+ CmdStructureAction( action, pos );
+ return C_CONTINUE;
+
case C_CANCEL:
wHide( structureW );
/*no break*/
@@ -1021,7 +1042,7 @@ static char * CmdStructureHotBarProc(
case HB_SELECT:
CmdStructureAction( C_FINISH, zero );
curStructure = to;
- DoCommandB( (void*)(intptr_t)structureHotBarCmdInx );
+ DoCommandB( I2VP(structureHotBarCmdInx) );
return NULL;
case HB_LISTTITLE:
FormatCompoundTitle( listLabels, to->title );
@@ -1034,8 +1055,8 @@ static char * CmdStructureHotBarProc(
case HB_FULLTITLE:
return to->title;
case HB_DRAW:
- origP->x -= to->orig.x;
- origP->y -= to->orig.y;
+ //origP->x -= to->orig.x;
+ //origP->y -= to->orig.y;
DrawSegs( d, *origP, 0.0, to->segs, to->segCnt, trackGauge, wDrawColorBlack );
return NULL;
}
@@ -1051,7 +1072,7 @@ EXPORT void AddHotBarStructures( void )
to = structureInfo(inx);
if ( !( IsParamValid(to->paramFileIndex) &&
to->segCnt > 0 &&
- CompatibleScale( FALSE, to->scaleInx, GetLayoutCurScale()) ) )
+ (FIT_NONE != CompatibleScale( FIT_STRUCTURE, to->scaleInx, GetLayoutCurScale())) ) )
/*( (strcmp( to->scale, "*" ) == 0 && strcasecmp( curScaleName, "DEMO" ) != 0 ) ||
strncasecmp( to->scale, curScaleName, strlen(to->scale) ) == 0 ) ) )*/
continue;
@@ -1066,7 +1087,7 @@ static STATUS_T CmdStructureHotBar(
switch (action & 0xFF) {
case C_START:
- structureChange( CHANGE_PARAMS );
+ //structureChange( CHANGE_PARAMS );
if (curStructure == NULL) {
NoticeMessage( MSG_STRUCT_NO_STRUCTS, _("Ok"), NULL );
return C_TERMINATE;
@@ -1074,10 +1095,10 @@ static STATUS_T CmdStructureHotBar(
FormatCompoundTitle( listLabels|LABEL_DESCR, curStructure->title );
InfoMessage( _("Place %s and draw into position"), message );
wIndex_t listIndex = FindListItemByContext( structureListL, curStructure );
- if ( listIndex > 0 )
+ if ( listIndex >= 0 )
structureInx = listIndex;
- //ParamLoadControls( &structurePG );
- //ParamGroupRecord( &structurePG );
+ ParamLoadControls( &structurePG );
+ ParamGroupRecord( &structurePG );
return CmdStructureAction( action, pos );
case wActionMove:
@@ -1121,11 +1142,11 @@ static STATUS_T CmdStructureHotBar(
}
}
-#include "bitmaps/struct.xpm"
+#include "bitmaps/building.xpm"
EXPORT void InitCmdStruct( wMenu_p menu )
{
- AddMenuButton( menu, CmdStructure, "cmdStructure", _("Structure"), wIconCreatePixMap(struct_xpm), LEVEL0_50, IC_WANT_MOVE|IC_STICKY|IC_CMDMENU|IC_POPUP2, ACCL_STRUCTURE, NULL );
+ AddMenuButton( menu, CmdStructure, "cmdStructure", _("Structure"), wIconCreatePixMap(building_xpm[iconSize]), LEVEL0_50, IC_WANT_MOVE|IC_STICKY|IC_CMDMENU|IC_POPUP2, ACCL_STRUCTURE, NULL );
structureHotBarCmdInx = AddMenuButton( menu, CmdStructureHotBar, "cmdStructureHotBar", "", NULL, LEVEL0_50, IC_WANT_MOVE|IC_STICKY|IC_CMDMENU|IC_POPUP2, 0, NULL );
ParamRegister( &structurePG );
if ( structPopupM == NULL ) {