Opened 19 years ago

Closed 18 years ago

#1495 closed defect (fixed)

Support for classObj.text using mapscript

Reported by: szekerest Owned by: sdlime
Priority: high Milestone:
Component: MapScript-SWIG Version: 4.8
Severity: normal Keywords:
Cc:

Description

The current version 4.6.1 does not really support classObj.text, however it 
would provide convenient way to display labels base on multiple fields.

It would be easy to bring into effect this, since getExpression and 
setExpression do almost the same. (see class.i)

To support expressionObj would be more complicated.

Tamas Szekeres

Change History (5)

comment:1 by szekerest, 18 years ago

Steve,

Would you consider adding the following code to class.i

int setTextString(char *text) 
    {
      if (!text || strlen(text) == 0) {
          freeExpression(&self->text);
          return MS_SUCCESS;
      }
      else return msLoadExpressionString(&self->text, text);
  }
  
  %newobject getTextString;
  char *getTextString() {
    char exprstring[256];
    switch(self->text.type) {
    case(MS_REGEX):
      snprintf(exprstring, 255, "/%s/", self->text.string);
      return strdup(exprstring);
    case(MS_STRING):
      snprintf(exprstring, 255, "\"%s\"", self->text.string);
      return strdup(exprstring);
    case(MS_EXPRESSION):
      snprintf(exprstring, 255, "(%s)", self->text.string);
      return strdup(exprstring);
    }
    return NULL;
  }

similarly to setExpression and getExpressionString.

This would ensure the only way to achieve labeling by multiple layer 
attributes with SWIG mapscript.

Tamas Szekeres

comment:2 by sdlime, 18 years ago

Status: newassigned
Version: 4.64.8
Will commit this over the weekend and in time for 4.8.

Steve

comment:3 by sdlime, 18 years ago

I'd really like to add this as getText/setText. setText exists but has an
unecessary argument (a *layerObj), so you can set a class text attribute now.
I've got a query on the developer list asking for permission to fix that. I've
added the get method you sent as getText...

It looks like this in CVS:

  /* Should be deprecated!  Completely bogus layer argument.  SG. */
  int setText(layerObj *layer, char *text) {
    if (!text || strlen(text) == 0) {
      freeExpression(&self->text);
      return MS_SUCCESS;
    }
    else return msLoadExpressionString(&self->text, text);
  }

  %newobject getText;
  char *getText() {
    char exprstring[256];
    switch(self->text.type) {
    case(MS_REGEX):
      snprintf(exprstring, 255, "/%s/", self->text.string);
      return strdup(exprstring);
    case(MS_STRING):
      snprintf(exprstring, 255, "\"%s\"", self->text.string);
      return strdup(exprstring);
    case(MS_EXPRESSION):
      snprintf(exprstring, 255, "(%s)", self->text.string);
      return strdup(exprstring);
    }
    return NULL;
  }

Steve

comment:4 by szekerest, 18 years ago

I agree with you there.

comment:5 by sdlime, 18 years ago

Resolution: fixed
Status: assignedclosed
Marking as fixed for 4.8.
Note: See TracTickets for help on using tickets.