Пример #1
0
int msInsertClass(layerObj *layer, classObj *classobj, int nIndex) 
{
    int i;

    if (!classobj)
    {
        msSetError(MS_CHILDERR, "Cannot insert NULL class", "msInsertClass()");
        return -1;
    }
        
    /* Ensure there is room for a new class */
    if (msGrowLayerClasses(layer) == NULL) {
        return -1;
    }
    /* Catch attempt to insert past end of styles array */
    else if (nIndex >= layer->numclasses) {
        msSetError(MS_CHILDERR, "Cannot insert class beyond index %d",
                   "msInsertClass()", layer->numclasses-1);
        return -1;
    }
    else if (nIndex < 0) { /* Insert at the end by default */
#ifndef __cplusplus
        layer->class[layer->numclasses]=classobj;
#else
        layer->_class[layer->numclasses]=classobj;
#endif
	/* set parent pointer */
	classobj->layer=layer;
	MS_REFCNT_INCR(classobj);
        layer->numclasses++;
        return layer->numclasses-1;
    }
Пример #2
0
/* For MapScript, exactly the same the msInsertStyle */
int msInsertLabelStyle(labelObj *label, styleObj *style, int nStyleIndex)
{
  int i;

  if (!style) {
    msSetError(MS_CHILDERR, "Can't insert a NULL Style", "msInsertLabelStyle()");
    return -1;
  }

  /* Ensure there is room for a new style */
  if (msGrowLabelStyles(label) == NULL) {
    return -1;
  }
  /* Catch attempt to insert past end of styles array */
  else if (nStyleIndex >= label->numstyles) {
    msSetError(MS_CHILDERR, "Cannot insert style beyond index %d", "insertLabelStyle()", label->numstyles-1);
    return -1;
  } else if (nStyleIndex < 0) { /* Insert at the end by default */
    label->styles[label->numstyles]=style;
    MS_REFCNT_INCR(style);
    label->numstyles++;
    return label->numstyles-1;
  } else if (nStyleIndex >= 0 && nStyleIndex < label->numstyles) {
    /* Move styles existing at the specified nStyleIndex or greater */
    /* to a higher nStyleIndex */
    for (i=label->numstyles-1; i>=nStyleIndex; i--) {
      label->styles[i+1] = label->styles[i];
    }
    label->styles[nStyleIndex]=style;
    MS_REFCNT_INCR(style);
    label->numstyles++;
    return nStyleIndex;
  } else {
    msSetError(MS_CHILDERR, "Invalid nStyleIndex", "insertLabelStyle()");
    return -1;
  }
}
Пример #3
0
int msAppendOutputFormat(mapObj *map, outputFormatObj *format)
{
  /* -------------------------------------------------------------------- */
  /*      Attach to map.                                                  */
  /* -------------------------------------------------------------------- */
  assert(map);
  map->numoutputformats++;
  if (map->outputformatlist == NULL)
    map->outputformatlist = (outputFormatObj **) malloc(sizeof(void*));
  else
    map->outputformatlist = (outputFormatObj **)
                            realloc(map->outputformatlist,
                                    sizeof(void*) * map->numoutputformats );

  map->outputformatlist[map->numoutputformats-1] = format;
  MS_REFCNT_INCR(format);

  return map->numoutputformats;
}
Пример #4
0
int msAppendSymbol(symbolSetObj *symbolset, symbolObj *symbol)
{
  /* Allocate memory for new symbol if needed */
  if (msGrowSymbolSet(symbolset) == NULL)
    return -1;

  /* we need to free the symbolObj that was already allocated as we are
   going to replace it with the provided symbolObj*. Not the most efficient
   technique, but this function should be rarely called, and in any case only
   by mapscript. Another option could be to use msCopySymbol(), in which case
   the call to MS_REFCNT_INCR(symbol) should be removed.*/
  if(symbolset->symbol[symbolset->numsymbols]) {
    msFreeSymbol(symbolset->symbol[symbolset->numsymbols]);
    msFree(symbolset->symbol[symbolset->numsymbols]);
  }
  symbolset->symbol[symbolset->numsymbols]=symbol;
  MS_REFCNT_INCR(symbol);
  return symbolset->numsymbols++;
}
Пример #5
0
int msInsertLayer(mapObj *map, layerObj *layer, int nIndex)
{
  if (!layer) {
    msSetError(MS_CHILDERR, "Can't insert a NULL Layer", "msInsertLayer()");
    return -1;
  }

  /* Ensure there is room for a new layer */
  if (map->numlayers == map->maxlayers) {
    if (msGrowMapLayers(map) == NULL)
      return -1;
  }

  /* msGrowMapLayers allocates the new layer which we don't need to do since we have 1 that we are inserting
                  not sure if it is possible for this to be non null otherwise, but better to check since this function
                  replaces the value */
  if (map->layers[map->numlayers]!=NULL)
    free(map->layers[map->numlayers]);

  /* Catch attempt to insert past end of layers array */
  if (nIndex >= map->numlayers) {
    msSetError(MS_CHILDERR, "Cannot insert layer beyond index %d",
               "msInsertLayer()", map->numlayers-1);
    return -1;
  } else if (nIndex < 0) { /* Insert at the end by default */
    map->layerorder[map->numlayers] = map->numlayers;
    GET_LAYER(map, map->numlayers) = layer;
    GET_LAYER(map, map->numlayers)->index = map->numlayers;
    GET_LAYER(map, map->numlayers)->map = map;
    MS_REFCNT_INCR(layer);
    map->numlayers++;
    return map->numlayers-1;
  } else if (nIndex >= 0 && nIndex < map->numlayers) {
    /* Move existing layers at the specified nIndex or greater */
    /* to an index one higher */
    int i;
    for (i=map->numlayers; i>nIndex; i--) {
      GET_LAYER(map, i)=GET_LAYER(map, i-1);
      GET_LAYER(map, i)->index = i;
    }

    /* assign new layer to specified index */
    GET_LAYER(map, nIndex)=layer;
    GET_LAYER(map, nIndex)->index = nIndex;
    GET_LAYER(map, nIndex)->map = map;

    /* adjust layers drawing order */
    for (i=map->numlayers; i>nIndex; i--) {
      map->layerorder[i] = map->layerorder[i-1];
      if (map->layerorder[i] >= nIndex) map->layerorder[i]++;
    }
    for (i=0; i<nIndex; i++) {
      if (map->layerorder[i] >= nIndex) map->layerorder[i]++;
    }
    map->layerorder[nIndex] = nIndex;

    /* increment number of layers and return */
    MS_REFCNT_INCR(layer);
    map->numlayers++;
    return nIndex;
  } else {
    msSetError(MS_CHILDERR, "Invalid index", "msInsertLayer()");
    return -1;
  }
}