/*\
 * Extended entity data by Leon Kos, march 1993
 * AUTOCAD12, HyperWaft Project
 * Zagon programa (xload "eed") in EED s tem da Piknemo na entiteto
 * $Id: EED.CPP 1.1 1995/01/08 08:11:16 leon Exp $
\*/

#include  <afc/adsapp.hpp>

#include <string.h>



int
printDxf (struct resbuf * eb)
{				/* primer ADS12/104 */

  int rt, resType;

  if (eb == NULL)
    return RTNONE;
  

    resType = eb->restype % 1000;

  if ((resType >= 0) && (resType <= 9))
    rt = RTSTR;
  

  else if ((resType >= 10) && (resType <= 19))
    rt = RT3DPOINT;
  

  else if ((resType >= 38) && (resType <= 59))
    rt = RTREAL;
  

  else if ((resType >= 60) && (resType <= 79))
    rt = RTSHORT;
  

  else if ((resType >= 210) && (resType <= 239))
    rt = RT3DPOINT;
  

  else if (resType < 0)
    rt = resType;
  

  else
    rt = RTNONE;


  switch (rt)
    {
    case RTSHORT:
      ads_printf ("(%d . %d) ", eb->restype, eb->resval.rint);
      break;

    case RTREAL:
      ads_printf ("(%d . %0.3f) ", eb->restype, eb->resval.rreal);
      break;

    case RTSTR:
      ads_printf ("(%d . \"%s\") ", eb->restype, eb->resval.rstring);
      break;

    case RT3DPOINT:
      ads_printf ("(%d . %0.3f %0.3f %0.3f) ", eb->restype, 
          eb->resval.rpoint[X], eb->resval.rpoint[Y], 
          eb->resval.rpoint[Z]);
      
    break;

    case RTNONE:
      ads_printf ("(%d . Nepoznan tip) ", eb->restype);
      break;

    case -1:
    case -2:
      ads_printf ("(%d . <Entity name: %8lx>) ", eb->restype, 
      eb->resval.rlname[0]);
    }

  return eb->restype;
}


void
berient (void)
{
  static struct resbuf appName =
  {NULL, RTSTR};
  ads_name ent;
  ads_point pt;
  struct resbuf *ebuf, *eb;

  appName.resval.rstring = strdup ("*");
  ads_entsel ( /*MSG4*/ "Pikni na gradnik >", ent, pt);
  ads_textscr ();
  ads_printf ("Entity name [%d], [%d]\n", ent[1], ent[2]);
  ebuf = ads_entgetx (ent, &appName);
  for (eb = ebuf; eb != NULL; eb = eb->rbnext)
    printDxf (eb);
  ads_relrb (ebuf);
}

#if 0


 /* Poisce string v vseh gradnikih, ki imajo EED */ 
void
locatehandle (void)
{
  static struct resbuf appName =
  {NULL, RTSTR};		/* Extended entity data filter */
  ads_name ent, ssname;
  struct resbuf *ebuf, *eb;
  long sslen, i;
  char handle[30];

  appName.resval.rstring = strdup ("*");

  ads_textscr ();

  ads_ssget ("X", NULL, NULL, NULL, ssname);	/* Izberemo vse gradnike */

  ads_getstring (0, "Vstavi handle, ki ga isces v EED (max: 16 znakov):", 
                    handle);
  

    ads_sslength (ssname, (long *) &sslen);
  ads_printf ("Stevilo izbranih gradnikov: %ld", sslen);

  for (i = 1; i <= sslen; i++)
    {
      ads_ssname (ssname, i, ent);
      ebuf = ads_entgetx (&ent, &appName);
      for (eb = ebuf; eb != NULL; eb = eb->rbnext)
	    if (eb->restype % 1000 == 5 /* Ali je to EED Handle */ 
      &&strcmp (eb->resval.rstring, handle) == 0)
	  {
	    for (eb = ebuf; eb != NULL; eb = eb->rbnext)
	      {
      		printDxf (eb);
	      }
	    ads_printf ("\n");
	    break;
	  }
      ads_relrb (ebuf);
    }
  return ads_ssfree (ssname);
}

#endif

void main (int argc, char *argv[])
{
    ADSApplication eed;
    eed.Register(berient, "c:eed");
    eed.Run(argc, argv);
}


syntax highlighted by Code2HTML, v. 0.9.1