It is currently Fri Oct 31, 2014 1:47 am

Function to create a drop-down dialog with a list of layers.

Function to create a drop-down dialog with a list of layers.

Postby tu2011 » Sun Jun 24, 2012 9:56 pm

/******************************************************************************************************************
*FUNCTION: This function test a layer to see if it's one of the specified type, i.e. Special, Derived, Drawn, All*
* *
*******************************************************************************************************************/
bool LLayer_IsOfType(LFile pFile, LLayer pLayer, LLayerType LayerType)
{
if (LayerType == Special)
{
if ( (pLayer == LLayer_GetSpecial(pFile, GridLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, OriginLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, CellOutlineLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, ErrorLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, IconLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, DragBoxLayer)) )
return true;
else
return false;
}
if (LayerType == Derived)
{
if (LLayer_IsDerived(pLayer))
return true;
else
return false;
}
if (LayerType == Drawn)
{
if (!LLayer_IsDerived(pLayer))
{
if ((pLayer == LLayer_GetSpecial(pFile, GridLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, OriginLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, CellOutlineLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, ErrorLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, IconLayer)) ||
(pLayer == LLayer_GetSpecial(pFile, DragBoxLayer)))
return false;
else
return true;
}
}
if (LayerType == All)
{
return true;
}
else
return false;
}//End of LLayer_IsOfType() function.



/**************************************************************************************************************
*FUNCTION: Provides a dialog box with a list of Layers of a specified type, i.e. Special, Derived, Drawn, All*
*EXAMPLE: LLayer_PickList(pSrcFile, "Select source layer to copy", All);
*********************************************************************************************************/

LLayer LLayer_PickList(LFile pFile, const char* szDialogTitle, LLayerType LayerType)
{
// Count the number of layers.
long lNumOfLayers = 0;
LLayer pLayer = NULL;
char szLayerName[MAX_LAYER_NAME];
long i = 0;

if (NotAssigned(pFile))
{
LDialog_MsgBox("Invalid pointer to File");
return NULL;
}

for(pLayer = LLayer_GetList(pFile); Assigned(pLayer); pLayer = LLayer_GetNext(pLayer))
{
if (LLayer_IsOfType(pFile, pLayer, LayerType))
lNumOfLayers++;
}

// Allocate space for all of the layer names.
char** szaLayerNames = (char **) malloc(lNumOfLayers * sizeof(char *)); // Array of pointers.
LLayer* paLayers = (LLayer *) malloc(lNumOfLayers * sizeof(LLayer *)); // Array of pointers.
// Add all the layer names to the array of layer names.
for(pLayer = LLayer_GetList(pFile); Assigned(pLayer); pLayer = LLayer_GetNext(pLayer))
{

if (LLayer_IsOfType(pFile, pLayer, LayerType))
{
// Get the name.
paLayers[i] = pLayer;
LLayer_GetName(pLayer, szLayerName, sizeof(szLayerName));
// Allocate space for the name.
szaLayerNames[i] = (char *) malloc((strlen(szLayerName) + 1) * sizeof(char));
// Add it to the list of layers.
strcpy(szaLayerNames[i++], szLayerName);
}
}

// Display the picklist.
int nLayerResult = LDialog_PickList(szDialogTitle, (const char**)(szaLayerNames), lNumOfLayers, 0);

if(nLayerResult >= 0)
return paLayers[nLayerResult];
else
return NULL;

// Deallocate the cell name array.
for(i = 0; i < lNumOfLayers; i++)
{
free(szaLayerNames[i]);
free(paLayers[i]);
}
free(szaLayerNames);
free(paLayers);
} // End of Function: PickList
tu2011
 

Re: Function to create a drop-down dialog with a list of lay

Postby jvdborght@sofics.com » Thu Sep 18, 2014 6:32 am

It took me a while to find out that you still had to define the LLayerType variable
typedef enum {Special, Derived, Drawn, All} LLayerType;

But anyway, a great help to build a macro that allowed me to move layers in my layer palette. Thanks!
jvdborght@sofics.com
 
Posts: 1
Joined: Tue May 13, 2014 11:27 pm


Return to UPI and TCL scripts

Who is online

Users browsing this forum: No registered users and 1 guest


Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 35 on Thu Jan 09, 2014 2:15 am

Users browsing this forum: No registered users and 1 guest

Login Form