xp_comm_proj/dlgtools/read/rd_dlg.c
/*********************************************************************

  process the dlg file to remove garbage

*********************************************************************/
process the dlg file to remove garbage
process the dlg file to remove garbage
int process_dlg(
		Dlg  *dlg,
		int ram_block,
		int debug_flag
		)
{
  int status, ii, jj, kk, mm;
  Header  *header;
  Pb      *pb;
  Node    *node;
  Area    *area;
  Line    *line;
  Poly    *poly;
  int n_nodes, n_lines, n_areas;
  int inode, iline, iarea, ivalid;
  int total_nodes;
  int added_nodes;
  int *valid;
  int n_valid;
#include "../gen_proc.h"
  sprintf(  LFNC_function_name, "read_dlg" );
  header = &(dlg->header);
  pb     = &(dlg->pb);
  poly  = &(dlg->polys);
  {
    valid = ( int * ) ram_more( ram_block,
			       sizeof(int)
			       * pb->n_areas );
    if( valid == NULL )
      {
	MY_ERROR( "malloc on data->valid" );
	return(0);
      }
    n_valid = 0;
    for( iarea=0; iarea < pb->n_areas; iarea++ )
      {
	area = &(pb->areas[iarea]);
	valid[n_valid] = 1;
	if( area->n_attributes  <  2  ||
	    area->attributes[0] != 91 ||
	    area->attributes[2] != 92    )
	  {
	    valid[ n_valid ] = 0;
	  }
	for( ii=0; ii<area->n_lines; ii++ )
	  {
	    if( abs(area->lines[ii]) < 1 )
	      {
		valid[ n_valid ] = 0;
	      }
	  }
	if( valid[n_valid] == 1 )
	  {
	    valid[n_valid] = iarea;
	    n_valid += 1;
	  }
      }
    if( n_valid < 1 )
      {
	MY_MESSAGE( "no valid areas");
	return(0);
      }
  }
  {
    poly->n_polys = n_valid;
    poly->poly_limits = (int *) ram_more( ram_block,
					 sizeof(int)
					 * poly->n_polys * 2 );
    if( poly->poly_limits == NULL )
      {
	MY_ERROR( "malloc poly->poly_limits" );
	return(0);
      }
    poly->poly_area = (int *) ram_more( ram_block,
				       sizeof(int)
				       * poly->n_polys );
    if( poly->poly_area == NULL )
      {
	MY_ERROR( "malloc poly->poly_area" );
	return(0);
      }
    for( ivalid=0; ivalid<n_valid; ivalid++ )
      {
	poly->poly_area[ ivalid ] = valid[ ivalid ];
      }
    total_nodes = 0;
    for( ivalid=0; ivalid<n_valid; ivalid++ )
      {
	iarea = valid[ ivalid ];
	area = &(pb->areas[iarea]);
	for( ii=0; ii<area->n_lines; ii++ )
	  {
	    iline = abs(area->lines[ii]) - 1;
	    line = &(pb->lines[ iline ] );
	    total_nodes += line->n_nodes - 1;
	  }
	total_nodes += 1;
       }
    poly->total_nodes = total_nodes;
    poly->poly_xy = (float *) ram_more( ram_block,
				       sizeof(float)
				       * total_nodes * 2 );
    if( poly->poly_xy == NULL )
      {
	MY_ERROR( "malloc on poly_xy" );
	return(0);
      }
    total_nodes = 0;
    for( ivalid=0; ivalid<n_valid; ivalid++ )
      {
	iarea = valid[ ivalid ];
	area = &(pb->areas[iarea]);
	added_nodes = 0;
	for( ii=0; ii<area->n_lines; ii++ )
	  {
	    iline = abs( area->lines[ii] ) - 1;
	    line = &(pb->lines[iline]);
	    if(  area->lines[ii] > 0 )
	      {
		for( jj=0; jj<line->n_nodes - 1; jj++ )
		  {
		    kk = total_nodes + added_nodes + jj;
		    mm = jj;
		    poly->poly_xy[2*kk+0] = line->nodes[2*mm+0];
		    poly->poly_xy[2*kk+1] = line->nodes[2*mm+1];
		  }
	      }
	    else
	      {
		for( jj=0; jj<line->n_nodes - 1; jj++ )
		  {
		    kk = total_nodes + added_nodes + jj;
		    mm = line->n_nodes - 1 - jj;
		    poly->poly_xy[2*kk+0] = line->nodes[2*mm+0];
		    poly->poly_xy[2*kk+1] = line->nodes[2*mm+1];
		  }
	      }
	    added_nodes += line->n_nodes - 1;
	  }
	kk = total_nodes + added_nodes;
	jj = total_nodes;
	poly->poly_xy[2*kk+0] = poly->poly_xy[2*jj+0];
	poly->poly_xy[2*kk+1] = poly->poly_xy[2*jj+1];
	added_nodes += 1;
	poly->poly_limits[ 2*ivalid+0 ] = total_nodes;
	poly->poly_limits[ 2*ivalid+1 ] = added_nodes;
	total_nodes += added_nodes;
      }
  }
  return(1);
}
int process_dlg ( Dlg * dlg , int ram_block , int debug_flag ) { int status , ii , jj , kk , mm ; Header * header ; Pb * pb ; Node * node ; Area * area ; Line * line ; Poly * poly ; int n_nodes , n_lines , n_areas ; int inode , iline , iarea , ivalid ; int total_nodes ; int added_nodes ; int * valid ; int n_valid ; #include " " sprintf ( LFNC_function_name , " " ) ; header = & ( dlg -> header ) ; pb = & ( dlg -> pb ) ; poly = & ( dlg -> polys ) ; { valid = ( int * ) ram_more ( ram_block , sizeof ( int ) * pb -> n_areas ) ; if ( valid == NULL ) { MY_ERROR ( " " ) ; return ( 0 ) ; } n_valid = 0 ; for ( iarea = 0 ; iarea < pb -> n_areas ; iarea ++ ) { area = & ( pb -> areas [ iarea ] ) ; valid [ n_valid ] = 1 ; if ( area -> n_attributes < 2 || area -> attributes [ 0 ] != 91 || area -> attributes [ 2 ] != 92 ) { valid [ n_valid ] = 0 ; } for ( ii = 0 ; ii < area -> n_lines ; ii ++ ) { if ( abs ( area -> lines [ ii ] ) < 1 ) { valid [ n_valid ] = 0 ; } } if ( valid [ n_valid ] == 1 ) { valid [ n_valid ] = iarea ; n_valid += 1 ; } } if ( n_valid < 1 ) { MY_MESSAGE ( " " ) ; return ( 0 ) ; } } { poly -> n_polys = n_valid ; poly -> poly_limits = ( int * ) ram_more ( ram_block , sizeof ( int ) * poly -> n_polys * 2 ) ; if ( poly -> poly_limits == NULL ) { MY_ERROR ( " " ) ; return ( 0 ) ; } poly -> poly_area = ( int * ) ram_more ( ram_block , sizeof ( int ) * poly -> n_polys ) ; if ( poly -> poly_area == NULL ) { MY_ERROR ( " " ) ; return ( 0 ) ; } for ( ivalid = 0 ; ivalid < n_valid ; ivalid ++ ) { poly -> poly_area [ ivalid ] = valid [ ivalid ] ; } total_nodes = 0 ; for ( ivalid = 0 ; ivalid < n_valid ; ivalid ++ ) { iarea = valid [ ivalid ] ; area = & ( pb -> areas [ iarea ] ) ; for ( ii = 0 ; ii < area -> n_lines ; ii ++ ) { iline = abs ( area -> lines [ ii ] ) - 1 ; line = & ( pb -> lines [ iline ] ) ; total_nodes += line -> n_nodes - 1 ; } total_nodes += 1 ; } poly -> total_nodes = total_nodes ; poly -> poly_xy = ( float * ) ram_more ( ram_block , sizeof ( float ) * total_nodes * 2 ) ; if ( poly -> poly_xy == NULL ) { MY_ERROR ( " " ) ; return ( 0 ) ; } total_nodes = 0 ; for ( ivalid = 0 ; ivalid < n_valid ; ivalid ++ ) { iarea = valid [ ivalid ] ; area = & ( pb -> areas [ iarea ] ) ; added_nodes = 0 ; for ( ii = 0 ; ii < area -> n_lines ; ii ++ ) { iline = abs ( area -> lines [ ii ] ) - 1 ; line = & ( pb -> lines [ iline ] ) ; if ( area -> lines [ ii ] > 0 ) { for ( jj = 0 ; jj < line -> n_nodes - 1 ; jj ++ ) { kk = total_nodes + added_nodes + jj ; mm = jj ; poly -> poly_xy [ 2 * kk + 0 ] = line -> nodes [ 2 * mm + 0 ] ; poly -> poly_xy [ 2 * kk + 1 ] = line -> nodes [ 2 * mm + 1 ] ; } } else { for ( jj = 0 ; jj < line -> n_nodes - 1 ; jj ++ ) { kk = total_nodes + added_nodes + jj ; mm = line -> n_nodes - 1 - jj ; poly -> poly_xy [ 2 * kk + 0 ] = line -> nodes [ 2 * mm + 0 ] ; poly -> poly_xy [ 2 * kk + 1 ] = line -> nodes [ 2 * mm + 1 ] ; } } added_nodes += line -> n_nodes - 1 ; } kk = total_nodes + added_nodes ; jj = total_nodes ; poly -> poly_xy [ 2 * kk + 0 ] = poly -> poly_xy [ 2 * jj + 0 ] ; poly -> poly_xy [ 2 * kk + 1 ] = poly -> poly_xy [ 2 * jj + 1 ] ; added_nodes += 1 ; poly -> poly_limits [ 2 * ivalid + 0 ] = total_nodes ; poly -> poly_limits [ 2 * ivalid + 1 ] = added_nodes ; total_nodes += added_nodes ; } } return ( 1 ) ; }
process the dlg file to remove garbage
process the dlg file to remove garbage
/*******************************************************************

    parameters

  *******************************************************************/ /*******************************************************************

    the rest

  *******************************************************************/ /*******************************************************************

    generics

  *******************************************************************/ /*******************************************************************

    set some pointers

  *******************************************************************/ /*******************************************************************

    remove unneeded areas

  *******************************************************************/ /*****************************************************************

      allocate

    *****************************************************************/ /*****************************************************************

      search

    *****************************************************************/ /*************************************************************

	  point

        *************************************************************/ /*************************************************************

	  initialize to valid

        *************************************************************/ /*************************************************************

	  check attributes and decide

        *************************************************************/ /*************************************************************

	  make sure the area is actually a single area and not
	  multplle loops

        *************************************************************/ /*************************************************************

	  add if still valid (i.e passed all tests)

        *************************************************************/ /*******************************************************************

    compute closed polylines for each area

  *******************************************************************/ /*****************************************************************

      set the number of polys' and allocate for polyline limits
      and referernce to original area

    *****************************************************************/ /*****************************************************************

      set the referencing

    *****************************************************************/ /*****************************************************************

      first determine the totals for allocation

      foreach area, add up the nodes on all the lines. subtract one
      for each line since the ends overlap. and unity to the sum
      since the ends must overlap to close

    *****************************************************************/ /*****************************************************************

      now allocate for all the nodes for all the polylines

    *****************************************************************/ /*****************************************************************

      now compute the true polygons and load into arrays. also load
      the pointers to the limits for each polyline

    *****************************************************************/ /*****************************************************
	      
	      modify entry into our array to allow for line
	      reversal so we get correct ordering
	
	      *****************************************************/ /* now close the loop */ /*******************************************************************

    bye-bye

  *******************************************************************/