From d1a8285f818eb7e5c3d6a05709ea21a808490b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 19 Mar 2018 19:55:58 +0100 Subject: New upstream version 5.1.0 --- app/bin/dlayer.c | 1538 +++++++++++++++++++++++++++++------------------------- 1 file changed, 841 insertions(+), 697 deletions(-) (limited to 'app/bin/dlayer.c') diff --git a/app/bin/dlayer.c b/app/bin/dlayer.c index c79d783..71d151e 100644 --- a/app/bin/dlayer.c +++ b/app/bin/dlayer.c @@ -1,7 +1,5 @@ /** \file dlayer.c * Functions and dialogs for handling layers. - * - * $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/bin/dlayer.c,v 1.9 2009-06-15 19:29:57 m_fischer Exp $ */ /* XTrkCad - Model Railroad CAD @@ -23,12 +21,17 @@ */ #include - -#include "track.h" -#include "i18n.h" - +#include #include +#include +#include "custom.h" +#include "dynstring.h" +#include "fileio.h" +#include "i18n.h" +#include "messages.h" +#include "param.h" +#include "track.h" /***************************************************************************** * @@ -45,195 +48,208 @@ #define LAYERPREF_COLOR "color" #define LAYERPREF_FLAGS "flags" -EXPORT LAYER_T curLayer; -EXPORT long layerCount = 10; +unsigned int curLayer; +long layerCount = 10; static long newLayerCount = 10; -static LAYER_T layerCurrent = NUM_LAYERS; +static unsigned int layerCurrent = NUM_LAYERS; static BOOL_T layoutLayerChanged = FALSE; -static wIcon_p show_layer_bmps[NUM_BUTTONS]; -/*static wIcon_p hide_layer_bmps[NUM_BUTTONS]; */ +static wIcon_p show_layer_bmps[NUM_BUTTONS]; static wButton_p layer_btns[NUM_BUTTONS]; /**< layer buttons on toolbar */ /** Layer selector on toolbar */ -static wList_p setLayerL; +static wList_p setLayerL; -/*static wMessage_p layerNumM;*/ /** Describe the properties of a layer */ typedef struct { - char name[STR_SHORT_SIZE]; /**< Layer name */ - wDrawColor color; /**< layer color, is an index into a color table */ - BOOL_T frozen; /**< Frozen flag */ - BOOL_T visible; /**< visible flag */ - BOOL_T onMap; /**< is layer shown map */ - long objCount; /**< number of objects on layer */ - } layer_t; - + char name[STR_SHORT_SIZE]; /**< Layer name */ + wDrawColor color; /**< layer color, is an index into a color table */ + BOOL_T frozen; /**< Frozen flag */ + BOOL_T visible; /**< visible flag */ + BOOL_T onMap; /**< is layer shown map */ + long objCount; /**< number of objects on layer */ +} layer_t; + static layer_t layers[NUM_LAYERS]; static layer_t *layers_save = NULL; static int oldColorMap[][3] = { - { 255, 255, 255 }, /* White */ - { 0, 0, 0 }, /* Black */ - { 255, 0, 0 }, /* Red */ - { 0, 255, 0 }, /* Green */ - { 0, 0, 255 }, /* Blue */ - { 255, 255, 0 }, /* Yellow */ - { 255, 0, 255 }, /* Purple */ - { 0, 255, 255 }, /* Aqua */ - { 128, 0, 0 }, /* Dk. Red */ - { 0, 128, 0 }, /* Dk. Green */ - { 0, 0, 128 }, /* Dk. Blue */ - { 128, 128, 0 }, /* Dk. Yellow */ - { 128, 0, 128 }, /* Dk. Purple */ - { 0, 128, 128 }, /* Dk. Aqua */ - { 65, 105, 225 }, /* Royal Blue */ - { 0, 191, 255 }, /* DeepSkyBlue */ - { 125, 206, 250 }, /* LightSkyBlue */ - { 70, 130, 180 }, /* Steel Blue */ - { 176, 224, 230 }, /* Powder Blue */ - { 127, 255, 212 }, /* Aquamarine */ - { 46, 139, 87 }, /* SeaGreen */ - { 152, 251, 152 }, /* PaleGreen */ - { 124, 252, 0 }, /* LawnGreen */ - { 50, 205, 50 }, /* LimeGreen */ - { 34, 139, 34 }, /* ForestGreen */ - { 255, 215, 0 }, /* Gold */ - { 188, 143, 143 }, /* RosyBrown */ - { 139, 69, 19 }, /* SaddleBrown */ - { 245, 245, 220 }, /* Beige */ - { 210, 180, 140 }, /* Tan */ - { 210, 105, 30 }, /* Chocolate */ - { 165, 42, 42 }, /* Brown */ - { 255, 165, 0 }, /* Orange */ - { 255, 127, 80 }, /* Coral */ - { 255, 99, 71 }, /* Tomato */ - { 255, 105, 180 }, /* HotPink */ - { 255, 192, 203 }, /* Pink */ - { 176, 48, 96 }, /* Maroon */ - { 238, 130, 238 }, /* Violet */ - { 160, 32, 240 }, /* Purple */ - { 16, 16, 16 }, /* Gray */ - { 32, 32, 32 }, /* Gray */ - { 48, 48, 48 }, /* Gray */ - { 64, 64, 64 }, /* Gray */ - { 80, 80, 80 }, /* Gray */ - { 96, 96, 96 }, /* Gray */ - { 112, 112, 122 }, /* Gray */ - { 128, 128, 128 }, /* Gray */ - { 144, 144, 144 }, /* Gray */ - { 160, 160, 160 }, /* Gray */ - { 176, 176, 176 }, /* Gray */ - { 192, 192, 192 }, /* Gray */ - { 208, 208, 208 }, /* Gray */ - { 224, 224, 224 }, /* Gray */ - { 240, 240, 240 }, /* Gray */ - { 0, 0, 0 } /* BlackPixel */ - }; - -static void DoLayerOp( void * data ); + { 255, 255, 255 }, /* White */ + { 0, 0, 0 }, /* Black */ + { 255, 0, 0 }, /* Red */ + { 0, 255, 0 }, /* Green */ + { 0, 0, 255 }, /* Blue */ + { 255, 255, 0 }, /* Yellow */ + { 255, 0, 255 }, /* Purple */ + { 0, 255, 255 }, /* Aqua */ + { 128, 0, 0 }, /* Dk. Red */ + { 0, 128, 0 }, /* Dk. Green */ + { 0, 0, 128 }, /* Dk. Blue */ + { 128, 128, 0 }, /* Dk. Yellow */ + { 128, 0, 128 }, /* Dk. Purple */ + { 0, 128, 128 }, /* Dk. Aqua */ + { 65, 105, 225 }, /* Royal Blue */ + { 0, 191, 255 }, /* DeepSkyBlue */ + { 125, 206, 250 }, /* LightSkyBlue */ + { 70, 130, 180 }, /* Steel Blue */ + { 176, 224, 230 }, /* Powder Blue */ + { 127, 255, 212 }, /* Aquamarine */ + { 46, 139, 87 }, /* SeaGreen */ + { 152, 251, 152 }, /* PaleGreen */ + { 124, 252, 0 }, /* LawnGreen */ + { 50, 205, 50 }, /* LimeGreen */ + { 34, 139, 34 }, /* ForestGreen */ + { 255, 215, 0 }, /* Gold */ + { 188, 143, 143 }, /* RosyBrown */ + { 139, 69, 19 }, /* SaddleBrown */ + { 245, 245, 220 }, /* Beige */ + { 210, 180, 140 }, /* Tan */ + { 210, 105, 30 }, /* Chocolate */ + { 165, 42, 42 }, /* Brown */ + { 255, 165, 0 }, /* Orange */ + { 255, 127, 80 }, /* Coral */ + { 255, 99, 71 }, /* Tomato */ + { 255, 105, 180 }, /* HotPink */ + { 255, 192, 203 }, /* Pink */ + { 176, 48, 96 }, /* Maroon */ + { 238, 130, 238 }, /* Violet */ + { 160, 32, 240 }, /* Purple */ + { 16, 16, 16 }, /* Gray */ + { 32, 32, 32 }, /* Gray */ + { 48, 48, 48 }, /* Gray */ + { 64, 64, 64 }, /* Gray */ + { 80, 80, 80 }, /* Gray */ + { 96, 96, 96 }, /* Gray */ + { 112, 112, 122 }, /* Gray */ + { 128, 128, 128 }, /* Gray */ + { 144, 144, 144 }, /* Gray */ + { 160, 160, 160 }, /* Gray */ + { 176, 176, 176 }, /* Gray */ + { 192, 192, 192 }, /* Gray */ + { 208, 208, 208 }, /* Gray */ + { 224, 224, 224 }, /* Gray */ + { 240, 240, 240 }, /* Gray */ + { 0, 0, 0 } /* BlackPixel */ +}; + +static void DoLayerOp(void * data); static void UpdateLayerDlg(void); -/* static void LoadLayerLists(); */ -static void LayerSetCounts(); -static void InitializeLayers( void LayerInitFunc( void ), int newCurrLayer ); -static void LayerPrefSave( void ); -static void LayerPrefLoad( void ); -EXPORT BOOL_T GetLayerVisible( LAYER_T layer ) +static void InitializeLayers(void LayerInitFunc(void), int newCurrLayer); +static void LayerPrefSave(void); +static void LayerPrefLoad(void); + +int IsLayerValid(unsigned int layer) { - if (layer < 0 || layer >= NUM_LAYERS) - return TRUE; - else - return layers[(int)layer].visible; + return (layer <= NUM_LAYERS); } - -EXPORT BOOL_T GetLayerFrozen( LAYER_T layer ) +BOOL_T GetLayerVisible(unsigned int layer) { - if (layer < 0 || layer >= NUM_LAYERS) - return TRUE; - else - return layers[(int)layer].frozen; + if (!IsLayerValid(layer)) { + return TRUE; + } else { + return layers[layer].visible; + } } -EXPORT BOOL_T GetLayerOnMap( LAYER_T layer ) +BOOL_T GetLayerFrozen(unsigned int layer) { - if (layer < 0 || layer >= NUM_LAYERS) - return TRUE; - else - return layers[(int)layer].onMap; + if (!IsLayerValid(layer)) { + return TRUE; + } else { + return layers[layer].frozen; + } } -EXPORT char * GetLayerName( LAYER_T layer ) +BOOL_T GetLayerOnMap(unsigned int layer) { - if (layer < 0 || layer >= NUM_LAYERS) - return NULL; - else - return layers[(int)layer].name; + if (!IsLayerValid(layer)) { + return TRUE; + } else { + return layers[layer].onMap; + } } -EXPORT void NewLayer( void ) +char * GetLayerName(unsigned int layer) { + if (!IsLayerValid(layer)) { + return NULL; + } else { + return layers[layer].name; + } } - -EXPORT wDrawColor GetLayerColor( LAYER_T layer ) +wDrawColor GetLayerColor(unsigned int layer) { - return layers[(int)layer].color; + return layers[layer].color; } -static void FlipLayer( void * arg ) +static void FlipLayer(unsigned int layer) { - LAYER_T l = (LAYER_T)(long)arg; - wBool_t visible; - if ( l < 0 || l >= NUM_LAYERS ) - return; - if ( l == curLayer && layers[(int)l].visible) { - wButtonSetBusy( layer_btns[(int)l], layers[(int)l].visible ); - NoticeMessage( MSG_LAYER_HIDE, _("Ok"), NULL ); - return; - } - RedrawLayer( l, FALSE ); - visible = !layers[(int)l].visible; - layers[(int)l].visible = visible; - if (l= NUM_LAYERS ) - curLayer = 0; - if ( !layers[(int)curLayer].visible ) - FlipLayer( (void*)(intptr_t)inx ); - if ( recordF ) - fprintf( recordF, "SETCURRLAYER %d\n", inx ); + unsigned int newLayer = (unsigned int)inx; + + if (layers[newLayer].frozen) { + NoticeMessage(MSG_LAYER_SEL_FROZEN, _("Ok"), NULL); + wListSetIndex(setLayerL, curLayer); + return; + } + + curLayer = newLayer; + + if (!IsLayerValid(curLayer)) { + curLayer = 0; + } + + if (!layers[curLayer].visible) { + FlipLayer(inx); + } + + if (recordF) { + fprintf(recordF, "SETCURRLAYER %d\n", inx); + } } -static void PlaybackCurrLayer( char * line ) +static void PlaybackCurrLayer(char * line) { - wIndex_t layer; - layer = atoi(line); - wListSetIndex( setLayerL, layer ); - SetCurrLayer( layer, NULL, 0, NULL, NULL ); + wIndex_t layer; + layer = atoi(line); + wListSetIndex(setLayerL, layer); + SetCurrLayer(layer, NULL, 0, NULL, NULL); } /** @@ -243,19 +259,35 @@ static void PlaybackCurrLayer( char * line ) * \param color IN new color */ -static void SetLayerColor( int inx, wDrawColor color ) +static void SetLayerColor(unsigned int inx, wDrawColor color) +{ + if (color != layers[inx].color) { + if (inx < NUM_BUTTONS) { + wIconSetColor(show_layer_bmps[inx], color); + wButtonSetLabel(layer_btns[inx], (char*)show_layer_bmps[inx]); + } + + layers[inx].color = color; + layoutLayerChanged = TRUE; + } +} + +char * +FormatLayerName(unsigned int layerNumber) { - if ( color != layers[inx].color ) { - if (inx < NUM_BUTTONS) { - wIconSetColor( show_layer_bmps[inx], color ); - wButtonSetLabel( layer_btns[inx], (char*)show_layer_bmps[inx] ); - } - layers[inx].color = color; - layoutLayerChanged = TRUE; - } + DynString string;// = NaS; + char *result; + DynStringMalloc(&string, 0); + DynStringPrintf(&string, + "%2d %c %s", + layerNumber + 1, + (layers[layerNumber].objCount > 0 ? '+' : '-'), + layers[layerNumber].name); + result = strdup(DynStringToCStr(&string)); + DynStringFree(&string); + return result; } - #include "bitmaps/l1.xbm" #include "bitmaps/l2.xbm" @@ -359,31 +391,32 @@ static void SetLayerColor( int inx, wDrawColor color ) static char * show_layer_bits[NUM_BUTTONS] = { - l1_bits, l2_bits, l3_bits, l4_bits, l5_bits, l6_bits, l7_bits, l8_bits, l9_bits, l10_bits, - l11_bits, l12_bits, l13_bits, l14_bits, l15_bits, l16_bits, l17_bits, l18_bits, l19_bits, l20_bits, - l21_bits, l22_bits, l23_bits, l24_bits, l25_bits, l26_bits, l27_bits, l28_bits, l29_bits, l30_bits, - l31_bits, l32_bits, l33_bits, l34_bits, l35_bits, l36_bits, l37_bits, l38_bits, l39_bits, l40_bits, - l41_bits, l42_bits, l43_bits, l44_bits, l45_bits, l46_bits, l47_bits, l48_bits, l49_bits, l50_bits, - l51_bits, l52_bits, l53_bits, l54_bits, l55_bits, l56_bits, l57_bits, l58_bits, l59_bits, l60_bits, - l61_bits, l62_bits, l63_bits, l64_bits, l65_bits, l66_bits, l67_bits, l68_bits, l69_bits, l70_bits, - l71_bits, l72_bits, l73_bits, l74_bits, l75_bits, l76_bits, l77_bits, l78_bits, l79_bits, l80_bits, - l81_bits, l82_bits, l83_bits, l84_bits, l85_bits, l86_bits, l87_bits, l88_bits, l89_bits, l90_bits, - l91_bits, l92_bits, l93_bits, l94_bits, l95_bits, l96_bits, l97_bits, l98_bits, l99_bits, + l1_bits, l2_bits, l3_bits, l4_bits, l5_bits, l6_bits, l7_bits, l8_bits, l9_bits, l10_bits, + l11_bits, l12_bits, l13_bits, l14_bits, l15_bits, l16_bits, l17_bits, l18_bits, l19_bits, l20_bits, + l21_bits, l22_bits, l23_bits, l24_bits, l25_bits, l26_bits, l27_bits, l28_bits, l29_bits, l30_bits, + l31_bits, l32_bits, l33_bits, l34_bits, l35_bits, l36_bits, l37_bits, l38_bits, l39_bits, l40_bits, + l41_bits, l42_bits, l43_bits, l44_bits, l45_bits, l46_bits, l47_bits, l48_bits, l49_bits, l50_bits, + l51_bits, l52_bits, l53_bits, l54_bits, l55_bits, l56_bits, l57_bits, l58_bits, l59_bits, l60_bits, + l61_bits, l62_bits, l63_bits, l64_bits, l65_bits, l66_bits, l67_bits, l68_bits, l69_bits, l70_bits, + l71_bits, l72_bits, l73_bits, l74_bits, l75_bits, l76_bits, l77_bits, l78_bits, l79_bits, l80_bits, + l81_bits, l82_bits, l83_bits, l84_bits, l85_bits, l86_bits, l87_bits, l88_bits, l89_bits, l90_bits, + l91_bits, l92_bits, l93_bits, l94_bits, l95_bits, l96_bits, l97_bits, l98_bits, l99_bits, }; -static EXPORT long layerRawColorTab[] = { - wRGB( 0, 0,255), /* blue */ - wRGB( 0, 0,128), /* dk blue */ - wRGB( 0,128, 0), /* dk green */ - wRGB(255,255, 0), /* yellow */ - wRGB( 0,255, 0), /* green */ - wRGB( 0,255,255), /* lt cyan */ - wRGB(128, 0, 0), /* brown */ - wRGB(128, 0,128), /* purple */ - wRGB(128,128, 0), /* green-brown */ - wRGB(255, 0,255)}; /* lt-purple */ -static EXPORT wDrawColor layerColorTab[COUNT(layerRawColorTab)]; +static long layerRawColorTab[] = { + wRGB(0, 0,255), /* blue */ + wRGB(0, 0,128), /* dk blue */ + wRGB(0,128, 0), /* dk green */ + wRGB(255,255, 0), /* yellow */ + wRGB(0,255, 0), /* green */ + wRGB(0,255,255), /* lt cyan */ + wRGB(128, 0, 0), /* brown */ + wRGB(128, 0,128), /* purple */ + wRGB(128,128, 0), /* green-brown */ + wRGB(255, 0,255) +}; /* lt-purple */ +static wDrawColor layerColorTab[COUNT(layerRawColorTab)]; static wWin_p layerW; @@ -392,7 +425,7 @@ static wDrawColor layerColor; static long layerVisible = TRUE; static long layerFrozen = FALSE; static long layerOnMap = TRUE; -static void LayerOk( void * ); +static void LayerOk(void *); static BOOL_T layerRedrawMap = FALSE; #define ENUMLAYER_RELOAD (1) @@ -406,24 +439,24 @@ static paramIntegerRange_t i0_20 = { 0, NUM_BUTTONS }; static paramData_t layerPLs[] = { #define I_LIST (0) - { PD_DROPLIST, NULL, "layer", PDO_LISTINDEX|PDO_DLGNOLABELALIGN, (void*)250 }, + { PD_DROPLIST, NULL, "layer", PDO_LISTINDEX|PDO_DLGNOLABELALIGN, (void*)250 }, #define I_NAME (1) - { PD_STRING, layerName, "name", PDO_NOPREF, (void*)(250-54), N_("Name") }, + { PD_STRING, layerName, "name", PDO_NOPREF, (void*)(250-54), N_("Name") }, #define I_COLOR (2) - { PD_COLORLIST, &layerColor, "color", PDO_NOPREF, NULL, N_("Color") }, + { PD_COLORLIST, &layerColor, "color", PDO_NOPREF, NULL, N_("Color") }, #define I_VIS (3) - { PD_TOGGLE, &layerVisible, "visible", PDO_NOPREF, visibleLabels, N_("Visible"), BC_HORZ|BC_NOBORDER }, + { PD_TOGGLE, &layerVisible, "visible", PDO_NOPREF, visibleLabels, N_("Visible"), BC_HORZ|BC_NOBORDER }, #define I_FRZ (4) - { PD_TOGGLE, &layerFrozen, "frozen", PDO_NOPREF|PDO_DLGHORZ, frozenLabels, N_("Frozen"), BC_HORZ|BC_NOBORDER }, + { PD_TOGGLE, &layerFrozen, "frozen", PDO_NOPREF|PDO_DLGHORZ, frozenLabels, N_("Frozen"), BC_HORZ|BC_NOBORDER }, #define I_MAP (5) - { PD_TOGGLE, &layerOnMap, "onmap", PDO_NOPREF|PDO_DLGHORZ, onMapLabels, N_("On Map"), BC_HORZ|BC_NOBORDER }, + { PD_TOGGLE, &layerOnMap, "onmap", PDO_NOPREF|PDO_DLGHORZ, onMapLabels, N_("On Map"), BC_HORZ|BC_NOBORDER }, #define I_COUNT (6) - { PD_STRING, NULL, "object-count", PDO_NOPREF|PDO_DLGBOXEND, (void*)(80), N_("Count"), BO_READONLY }, - { PD_MESSAGE, N_("Personal Preferences"), NULL, PDO_DLGRESETMARGIN, (void *)180 }, - { PD_BUTTON, (void*)DoLayerOp, "reset", PDO_DLGRESETMARGIN, 0, N_("Load"), 0, (void *)ENUMLAYER_RELOAD }, - { PD_BUTTON, (void*)DoLayerOp, "save", PDO_DLGHORZ, 0, N_("Save"), 0, (void *)ENUMLAYER_SAVE }, - { PD_BUTTON, (void*)DoLayerOp, "clear", PDO_DLGHORZ | PDO_DLGBOXEND, 0, N_("Defaults"), 0, (void *)ENUMLAYER_CLEAR }, - { PD_LONG, &newLayerCount, "button-count", PDO_DLGBOXEND|PDO_DLGRESETMARGIN, &i0_20, N_("Number of Layer Buttons") }, + { PD_STRING, NULL, "object-count", PDO_NOPREF|PDO_DLGBOXEND, (void*)(80), N_("Count"), BO_READONLY }, + { PD_MESSAGE, N_("Personal Preferences"), NULL, PDO_DLGRESETMARGIN, (void *)180 }, + { PD_BUTTON, (void*)DoLayerOp, "reset", PDO_DLGRESETMARGIN, 0, N_("Load"), 0, (void *)ENUMLAYER_RELOAD }, + { PD_BUTTON, (void*)DoLayerOp, "save", PDO_DLGHORZ, 0, N_("Save"), 0, (void *)ENUMLAYER_SAVE }, + { PD_BUTTON, (void*)DoLayerOp, "clear", PDO_DLGHORZ | PDO_DLGBOXEND, 0, N_("Defaults"), 0, (void *)ENUMLAYER_CLEAR }, + { PD_LONG, &newLayerCount, "button-count", PDO_DLGBOXEND|PDO_DLGRESETMARGIN, &i0_20, N_("Number of Layer Buttons") }, }; static paramGroup_t layerPG = { "layer", 0, layerPLs, sizeof layerPLs/sizeof layerPLs[0] }; @@ -433,120 +466,125 @@ static paramGroup_t layerPG = { "layer", 0, layerPLs, sizeof layerPLs/sizeof lay /** * Load the layer settings to hard coded system defaults */ - + void -LayerSystemDefaults( void ) +LayerSystemDefaults(void) { - int inx; - - for ( inx=0;inx0?'+':'-', layers[inx].name ); - wListAddValue( layerL, message, NULL, NULL ); - } - - sprintf( message, "%2d : %s", inx+1, layers[inx].name ); - wListAddValue( setLayerL, message, NULL, NULL ); - } - - /* set current layer to selected */ - wListSetIndex( setLayerL, curLayer ); - if ( layerL ) - wListSetIndex( layerL, curLayer ); + int inx; + /* clear both lists */ + wListClear(setLayerL); + + if (layerL) { + wListClear(layerL); + } + + /* add all layers to both lists */ + for (inx=0; inx= 0 && inx < NUM_LAYERS ) - layers[inx].objCount++; - } + int inx; + track_p trk; + + for (inx=0; inx= 0 && inx < NUM_LAYERS) { + layers[inx].objCount++; + } + } } /** @@ -722,16 +766,16 @@ EXPORT void LayerSetCounts( void ) * from the preferences file. */ -EXPORT void +void DefaultLayerProperties(void) { - InitializeLayers( LayerPrefLoad, 0 ); + InitializeLayers(LayerPrefLoad, 0); + UpdateLayerDlg(); - UpdateLayerDlg(); - if( layoutLayerChanged ) { - MainProc( mainW, wResize_e, NULL ); - layoutLayerChanged = FALSE; - } + if (layoutLayerChanged) { + MainProc(mainW, wResize_e, NULL); + layoutLayerChanged = FALSE; + } } /** @@ -739,158 +783,190 @@ DefaultLayerProperties(void) * */ -static void LayerUpdate( void ) +static void LayerUpdate(void) { - BOOL_T redraw; - ParamLoadData( &layerPG ); - if (layerCurrent < 0 || layerCurrent >= NUM_LAYERS) - return; - if (layerCurrent == curLayer && layerFrozen) { - NoticeMessage( MSG_LAYER_FREEZE, _("Ok"), NULL ); - layerFrozen = FALSE; - ParamLoadControl( &layerPG, I_FRZ ); - } - if (layerCurrent == curLayer && !layerVisible) { - NoticeMessage( MSG_LAYER_HIDE, _("Ok"), NULL ); - layerVisible = TRUE; - ParamLoadControl( &layerPG, I_VIS ); - } - - if( strcmp( layers[(int)layerCurrent].name, layerName ) || - layerColor != layers[(int)layerCurrent].color || - layers[(int)layerCurrent].visible != (BOOL_T)layerVisible || - layers[(int)layerCurrent].frozen != (BOOL_T)layerFrozen || - layers[(int)layerCurrent].onMap != (BOOL_T)layerOnMap ) { - - changed = TRUE; - SetWindowTitle(); - } - - if ( layerL ) { - strncpy( layers[(int)layerCurrent].name, layerName, sizeof layers[(int)layerCurrent].name ); - sprintf( message, "%2d %c %s", (int)layerCurrent+1, layers[(int)layerCurrent].objCount>0?'+':'-', layers[(int)layerCurrent].name ); - wListSetValues( layerL, layerCurrent, message, NULL, NULL ); - } - - sprintf( message, "%2d : %s", (int)layerCurrent+1, layers[(int)layerCurrent].name ); - wListSetValues( setLayerL, layerCurrent, message, NULL, NULL ); - if (layerCurrent < NUM_BUTTONS) { - if (strlen(layers[(int)layerCurrent].name)>0) - wControlSetBalloonText( (wControl_p)layer_btns[(int)layerCurrent], layers[(int)layerCurrent].name ); - else - wControlSetBalloonText( (wControl_p)layer_btns[(int)layerCurrent], _("Show/Hide Layer") ); - } - redraw = ( layerColor != layers[(int)layerCurrent].color || - (BOOL_T)layerVisible != layers[(int)layerCurrent].visible ); - if ( (!layerRedrawMap) && redraw) - RedrawLayer( (LAYER_T)layerCurrent, FALSE ); - - SetLayerColor( layerCurrent, layerColor ); - - if (layerCurrent0) { + wControlSetBalloonText((wControl_p)layer_btns[(int)layerCurrent], + layers[(int)layerCurrent].name); + } else { + wControlSetBalloonText((wControl_p)layer_btns[(int)layerCurrent], + _("Show/Hide Layer")); + } + } + + redraw = (layerColor != layers[(int)layerCurrent].color || + (BOOL_T)layerVisible != layers[(int)layerCurrent].visible); + + if ((!layerRedrawMap) && redraw) { + RedrawLayer((unsigned int)layerCurrent, FALSE); + } + + SetLayerColor(layerCurrent, layerColor); + + if (layerCurrent= NUM_LAYERS) - return; - layerCurrent = (LAYER_T)inx; - strcpy( layerName, layers[inx].name ); - layerVisible = layers[inx].visible; - layerFrozen = layers[inx].frozen; - layerOnMap = layers[inx].onMap; - layerColor = layers[inx].color; - sprintf( message, "%ld", layers[inx].objCount ); - - ParamLoadMessage( &layerPG, I_COUNT, message ); - ParamLoadControls( &layerPG ); + LayerUpdate(); + + if (inx < 0 || inx >= NUM_LAYERS) { + return; + } + + layerCurrent = (unsigned int)inx; + strcpy(layerName, layers[inx].name); + layerVisible = layers[inx].visible; + layerFrozen = layers[inx].frozen; + layerOnMap = layers[inx].onMap; + layerColor = layers[inx].color; + sprintf(message, "%ld", layers[inx].objCount); + ParamLoadMessage(&layerPG, I_COUNT, message); + ParamLoadControls(&layerPG); } -EXPORT void ResetLayers( void ) +void ResetLayers(void) { - int inx; - for ( inx=0;inx NUM_BUTTONS ) - newLayerCount = NUM_BUTTONS; - layerCount = newLayerCount; - } - if (layoutLayerChanged) - MainProc( mainW, wResize_e, NULL ); - wHide( layerW ); + LayerSelect(layerCurrent); + + if (newLayerCount != layerCount) { + layoutLayerChanged = TRUE; + + if (newLayerCount > NUM_BUTTONS) { + newLayerCount = NUM_BUTTONS; + } + + layerCount = newLayerCount; + } + + if (layoutLayerChanged) { + MainProc(mainW, wResize_e, NULL); + } + + wHide(layerW); } static void LayerDlgUpdate( - paramGroup_p pg, - int inx, - void * valueP ) + paramGroup_p pg, + int inx, + void * valueP) { - switch (inx) { - case I_LIST: - LayerSelect( (wIndex_t)*(long*)valueP ); - break; - case I_NAME: - LayerUpdate(); - break; - case I_MAP: - layerRedrawMap = TRUE; - break; - } + switch (inx) { + case I_LIST: + LayerSelect((wIndex_t)*(long*)valueP); + break; + + case I_NAME: + LayerUpdate(); + break; + + case I_MAP: + layerRedrawMap = TRUE; + break; + } } -static void DoLayer( void * junk ) +static void DoLayer(void * junk) { - if (layerW == NULL) - layerW = ParamCreateDialog( &layerPG, MakeWindowTitle(_("Layers")), _("Done"), LayerOk, NULL, TRUE, NULL, 0, LayerDlgUpdate ); + if (layerW == NULL) { + layerW = ParamCreateDialog(&layerPG, MakeWindowTitle(_("Layers")), _("Done"), + LayerOk, NULL, TRUE, NULL, 0, LayerDlgUpdate); + } + + /* set the globals to the values for the current layer */ + UpdateLayerDlg(); + layerRedrawMap = FALSE; + wShow(layerW); + layoutLayerChanged = FALSE; +} - /* set the globals to the values for the current layer */ - UpdateLayerDlg(); - - layerRedrawMap = FALSE; - wShow( layerW ); - layoutLayerChanged = FALSE; +BOOL_T ReadLayers(char * line) +{ + char * name; + int inx, visible, frozen, color, onMap; + unsigned long rgb; + + /* older files didn't support layers */ + + if (paramVersion < 7) { + return TRUE; + } + + /* set the current layer */ + + if (strncmp(line, "CURRENT", 7) == 0) { + curLayer = atoi(line+7); + + if (!IsLayerValid(curLayer)) { + curLayer = 0; + } + + if (layerL) { + wListSetIndex(layerL, curLayer); + } + + if (setLayerL) { + wListSetIndex(setLayerL, curLayer); + } + + return TRUE; + } + + /* get the properties for a layer from the file and update the layer accordingly */ + + if (!GetArgs(line, "ddddu0000q", &inx, &visible, &frozen, &onMap, &rgb, + &name)) { + return FALSE; + } + + if (paramVersion < 9) { + if ((int)rgb < sizeof oldColorMap/sizeof oldColorMap[0]) { + rgb = wRGB(oldColorMap[(int)rgb][0], oldColorMap[(int)rgb][1], + oldColorMap[(int)rgb][2]); + } else { + rgb = 0; + } + } + + if (inx < 0 || inx >= NUM_LAYERS) { + return FALSE; + } + + color = wDrawFindColor(rgb); + SetLayerColor(inx, color); + strncpy(layers[inx].name, name, sizeof layers[inx].name); + layers[inx].visible = visible; + layers[inx].frozen = frozen; + layers[inx].onMap = onMap; + layers[inx].color = color; + + if (inx 0) { + wControlSetBalloonText((wControl_p)layer_btns[(int)inx], layers[inx].name); + } + + wButtonSetBusy(layer_btns[(int)inx], visible); + } + MyFree(name); + + return TRUE; } +/** + * Find out whether layer information should be saved to the layout file. + * Usually only layers where settings are off from the default are written. + * NOTE: as a fix for a problem with XTrkCadReader a layer definition is + * written for each layer that is used. + * + * \param layerNumber IN index of the layer + * \return TRUE if configured, FALSE if not + */ -EXPORT BOOL_T ReadLayers( char * line ) +bool +IsLayerConfigured(unsigned int layerNumber) { - char * name; - int inx, visible, frozen, color, onMap; - unsigned long rgb; - - /* older files didn't support layers */ - - if (paramVersion < 7) - return TRUE; - - /* set the current layer */ - - if ( strncmp( line, "CURRENT", 7 ) == 0 ) { - curLayer = atoi( line+7 ); - if ( curLayer < 0 ) - curLayer = 0; - - if (layerL) - wListSetIndex( layerL, curLayer ); - if (setLayerL) - wListSetIndex( setLayerL, curLayer ); - - return TRUE; - } - - /* get the properties for a layer from the file and update the layer accordingly */ - - if (!GetArgs( line, "ddddu0000q", &inx, &visible, &frozen, &onMap, &rgb, &name )) - return FALSE; - if (paramVersion < 9) { - if ( rgb >= 0 && (int)rgb < sizeof oldColorMap/sizeof oldColorMap[0] ) - rgb = wRGB( oldColorMap[(int)rgb][0], oldColorMap[(int)rgb][1], oldColorMap[(int)rgb][2] ); - else - rgb = 0; - } - if (inx < 0 || inx >= NUM_LAYERS) - return FALSE; - color = wDrawFindColor(rgb); - SetLayerColor( inx, color ); - strncpy( layers[inx].name, name, sizeof layers[inx].name ); - layers[inx].visible = visible; - layers[inx].frozen = frozen; - layers[inx].onMap = onMap; - layers[inx].color = color; - if (inx 0) { - wControlSetBalloonText( (wControl_p)layer_btns[(int)inx], layers[inx].name ); - } - wButtonSetBusy( layer_btns[(int)inx], visible ); - } - return TRUE; + return (!layers[layerNumber].visible || + layers[layerNumber].frozen || + !layers[layerNumber].onMap || + layers[layerNumber].color != + layerColorTab[layerNumber % (COUNT(layerColorTab))] || + layers[layerNumber].name[0] || + layers[layerNumber].objCount); } +/** + * Save the layer information to the file. + * + * \paran f IN open file handle + * \return always TRUE + */ -EXPORT BOOL_T WriteLayers( FILE * f ) +BOOL_T WriteLayers(FILE * f) { - int inx; - BOOL_T rc = TRUE; - for (inx=0; inx0; - rc &= fprintf( f, "LAYERS CURRENT %d\n", curLayer )>0; - return TRUE; + unsigned int inx; + + for (inx = 0; inx < NUM_LAYERS; inx++) { + if (IsLayerConfigured(inx)) { + fprintf(f, "LAYERS %u %d %d %d %ld %d %d %d %d \"%s\"\n", + inx, + layers[inx].visible, + layers[inx].frozen, + layers[inx].onMap, + wDrawGetRGB(layers[inx].color), + 0, 0, 0, 0, + PutTitle(layers[inx].name)); + } + } + + fprintf(f, "LAYERS CURRENT %u\n", curLayer); + return TRUE; } -EXPORT void InitLayers( void ) +void InitLayers(void) { - int i; - - wPrefGetInteger( PREFSECT, "layer-button-count", &layerCount, layerCount ); - for ( i = 0; i