/*====================================================================*\
FILE    :  UgParamFeatLabel.c
PURPOSE :  Example that demonstrates use of parameter functions.

HISTORY..
DATE       BUILD      AUTHOR    MODIFICATIONS
04-dec-97 H-02-02    Bojan     $$1   Created.
\*====================================================================*/

#include <ProToolkit.h>
#include <ProParameter.h>
#include <ProSelection.h>
#include <ProUtil.h>

#include <TestError.h>
 
/*=====================================================================*\
Function : UserLabelFeature
Purpose  : Function labels a feature with a string parameter.
\*=====================================================================*/
int UserLabelFeature()
{
  ProModelitem  feature;
  ProSelection  *sel;
  ProParameter  param;
  ProParamvalue value;
  ProFileName   msgfil;
  ProName       name;
  ProLine       line;
  ProError      err;
  int           nsel;


/*---------------------------------------------------------------------*\
  Setup the name of the message file
\*---------------------------------------------------------------------*/
    ProStringToWstring(msgfil,"msg_ugparam.txt");

/*---------------------------------------------------------------------*\
   Select a feature to label. If nothing is selected exit function.
\*---------------------------------------------------------------------*/
    err = ProMessageDisplay(msgfil,"USER Select a feature to label");
    ERROR_CHECK("UserLabelFeature","ProMessageDisplay",err);

    err = ProSelect("feature",1, NULL,NULL,NULL,NULL, &sel, &nsel);
    ERROR_CHECK("UserLabelFeature","ProSelect",err);

    if(nsel <= 0)
        return(0);

/*---------------------------------------------------------------------*\
   Get the model item from selection.
\*---------------------------------------------------------------------*/
    err = ProSelectionModelitemGet(sel[0], &feature);
    ERROR_CHECK("UserLabelFeature","ProSelectionModelitemGet",err);

/*---------------------------------------------------------------------*\
   Get the name of the parameter.
\*---------------------------------------------------------------------*/
    err = ProMessageDisplay(msgfil,"USER %0s", "Enter the name of the parameter: ");
    err = ProMessageStringRead(PRO_NAME_SIZE, name);

/*---------------------------------------------------------------------*\
   Set parameter type and value.
\*---------------------------------------------------------------------*/
    value.type = PRO_PARAM_STRING;

    err = ProMessageDisplay(msgfil,"USER %0s", "Enter the parameter string line: ");
    err = ProMessageStringRead(PRO_LINE_SIZE, value.value.s_val);

/*---------------------------------------------------------------------*\
   If the parameter exists, set its new value. Otherwise, create it.
\*---------------------------------------------------------------------*/
    err = ProParameterInit(&feature, name, &param);
    ERROR_CHECK("UserLabelFeature","ProParameterInit", err);
    
    if( err == PRO_TK_E_NOT_FOUND)
    {
         err = ProParameterCreate(&feature, name, &value, &param);
         ERROR_CHECK("UserLabelFeature","ProParameterCreate",err);
    }
    else
    {
         err = ProParameterValueSet(&param, &value);
         ERROR_CHECK("UserLabelFeature","ProParameterCreate",err);
    }

  return(PRO_TK_NO_ERROR);
}
