// ut_prcv.c                   RF                     2003-07-01
/*
 *
 * Copyright (C) 2016 CADCAM-Services Franz Reiter (franz.reiter@cadcam.co.at)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 *
-----------------------------------------------------
TODO:
- welche Func gives polygon from binaryObj ?
  UT3D_pta_dbo UT3D_npt_obj UT3D_npt_ox__ UT3D_pta_ox_lim
  UT3D_pta_sus > ?
- nachbauen - als UT3D_npt_prc_dbo

- welche Func makes display-dbo ?
   APT_Draw__ APT_DrawCirc / APT_DrawCurv / APT_DrawSur / APT_DrawSol
APT_DrawCirc GR_DrawCirc UT2D_npt_ci
APT_DrawCurv
  GR_DrawCvBSp UT3D_pta_bsp
  GR_DrawCvRBSp UT3D_cv_rbsp
  GR_DrawCvPol UT3D_pta_plg
  GR_DrawCvEll UT3D_npt_ell
  GR_DrawCvClot UT3D_npt_clot
  GR_DrawCvCCV UT3D_pta_ox_lim
           


-----------------------------------------------------
Modifications:
2016-10-19 Neu.  RF.

-----------------------------------------------------
*/
#ifdef globTag
void PRCV(){}
#endif
/*!
\file  ../ut/ut_prcv.c
\brief polygonal_representation_of_curve  (struct CurvPrcv)
\code

=====================================================
List_functions_start:

PRCV_set_dbo__    create PRCV from bin.obj
PRCV_basCv        create PRCV for basicCurve
PRCV_set_seg      add curve from vs to ve to PRCV
PRCV_set_find     get previous-parameter and next-parameter
PRCV_memspc_get   init memspc for CurvPrcv
PRCV_wrf__        write cvp into file "[M<subModelNr>]S<surf#>.odat"
PRCV_rdf__        read PRCV from file "[M<subModelNr>]S<surf#>.odat"
PRCV_rdf_free     free CurvPrcv

  // PRCV_insert_par
  // PRCV_insert__       Create PRC, add 1 or 2 intermediate points
  // PRCV_ccv__        get PRCV from trimmed-curve

PRCV_dump__
PRCV_dump_dbo
PRCV_test__
PRCV_test_set
PRCV_test_get

List_functions_end:
=====================================================
UTO_get_ptlim     get limiting parameters for curve
UT3D_ccv_obj      get trimmed-curve from bin-object (basecurves)
AP_GA_get         get attribute for curve

  
\endcode *//*----------------------------------------


see also: ../ut/ut_ccv.c   trimmed-curve functions


----------------------------------------
Every trimmed-curve (CurvCCV) refers to a basic-curve (typ,dbi).
  More than one trimmed-curves can point to the same basic-curve.


Every basic-curve has a PRCV (polygonal_representation_of_curve)
  The PRCV (struct CurvPrcv) is in a file;
    filename is tmp_dir/[M<subModelNr>]S<surf#>.odat

  Struct CurvPrcv is a polygonal_representation_of_curve -
    - a list of points (npt),
    - a list of the paramter-values of this points (npar), 
    - a list of the DB-indices of this points (nipt).
  



*/

#ifdef _MSC_VER
#include "../xa/MS_Def0.h"
#endif

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>




#include "../ut/ut_geo.h"
#include "../ut/ut_geo_const.h"           // UT3D_CCV_NUL
#include "../ut/ut_memTab.h"              // MemTab
#include "../ut/ut_os.h"                  // OS_ ..
#include "../db/ut_DB.h"                  // DB_GetObjDat

#include "../xa/xa_mem.h"                 // memspc*


//===========================================================================
// EXTERNALS:
// from ../xa/xa.c:
extern int       WC_modact_ind;         // -1=primary Model is active;
                                        // else subModel is being created



//==============================================================================
  int UTO_cv_ck_rev_clo_cyc (int *rev, int *clo, int *cyc, int typ, void *obj) {
//==============================================================================
/// \code
/// UTO_cv_ck_rev_clo_cyc    test closed,cyclic (if curve passes end-/startpoint)
///   curve must be closed
/// Output:
///   rev     direction; 0=forward, 1=reverse;
///   clo     closed; 0=yes, 1=not_closed. (-1=not set)
///   cyc     0  no, curve is NOT cyclic
//            1  yes, curve is cyclic (and closed)
///           -1 undefined (obj is not closed OR is line OR ..)
///   RetCod
///
/// \endcode
// see UTO_cv_ck_clo


  printf("============================================ \n");
  UT3D_stru_dump (typ, obj, " UTO_cv_ck_cyc ");


  if(typ == Typ_CI) {  // Circ

    // get rev-flag  (0=CCW; 1=CW)
    rev = DLIM01 (((Circ*)obj)->rad);

    // test if closed (0=yes, 1=not_closed, -1=undef, -2=degen)
    clo = UT3D_ck_ci360 ((Circ*)obj);
    // 0=yes = circ is a 360-deg-circ.

    // Basic-circle cannot be cyclic - startAngle always is 0.
    // Trimmed-circle can be cyclic.
    cyc = 0;

/*
  } else if(typ == Typ_CVELL) {    // CurvElli


  } else if(typ == Typ_CVPOL) {    // CurvPoly


  } else if(typ == Typ_CVBSP) {    // CurvBSpl


  } else if(typ == Typ_CVRBSP) {    // CurvRBSpl


  } else if(typ == Typ_CVCCV) {    // CurvCCV
*/

  }
  



  // all others (Typ_LN, ..) undefined
  return -1;

}


//================================================================
  int UTO_get_ptlim (double *v0, double *v1, int form, void *crv) {
//================================================================
// get limiting parameters for curve
// UT_VAL_MAX = undefined


  printf("UTO_get_ptlim %d\n",form);

  switch (form) {

    case Typ_CI:        // Circ
      *v0 = 0.0;
      *v1 = 1.0;        // RAD_360 / ((Circ*)crv)->ango;
                        // UT3D_par1_ci_angr UT3D_par1_ci_pt
      break;

    case Typ_CVBSP:
      *v0 = ((CurvBSpl*)crv)->v0;
      *v1 = ((CurvBSpl*)crv)->v1;
      break;

    case Typ_CVRBSP:
      *v0 = ((CurvRBSpl*)crv)->v0;
      *v1 = ((CurvRBSpl*)crv)->v1;
      break;

    case Typ_CVPOL:
      *v0 = ((CurvPoly*)crv)->v0;
      *v1 = ((CurvPoly*)crv)->v1;
      break;

    case Typ_CVCCV:      // CurvCCV
      *v0 = ((CurvCCV*)crv)->v0;
      *v1 = ((CurvCCV*)crv)->v1;
      break;

// Line ?
// Circ ?
// CurvElli ?
// CurvClot ?


    default:
      // unknown form
      printf("**** UTO_get_ptlim E001 %d\n",form);
      return -1;
  }


    // TESTBLOCK
    {  char s1[80], s2[80];
      if(*v0 == UT_VAL_MAX) strcpy(s1, "-undef-");
      else sprintf (s1, "%11.3f", *v0);
      if(*v1 == UT_VAL_MAX) strcpy(s2, "-undef-");
      else sprintf (s2, "%11.3f", *v1);
      printf("ex UTO_get_ptlim v0 = %s  v1 = %s\n", s1, s2);
    }
    // END TESTBLOCK

  return 0;

}


//==========================================================================
  int UT3D_ccv_obj (CurvCCV *ccv1, int form, long dbi, void *obj) {
//==========================================================================
// UT3D_ccv_obj      get trimmed-curve from bin-object (basecurves)
// Input:

// see UTO_cvtrm_cv


  UT3D_stru_dump (form, obj, " UT3D_ccv_obj");


  // init ccv1
  *ccv1 = UT3D_CCV_NUL;

  ccv1->typ = form;
  ccv1->dbi = dbi;


  switch (form) {

    case Typ_LN:
      break;

    case Typ_CI:     // Circ
      break;
/*
    case Typ_CVELL:  // CurvElli
      break;

    case Typ_CVCLOT: // CurvClot:
      break;
*/
    case Typ_CVBSP:  // CurvBSpl
      ccv1->v0  = ((CurvBSpl*)obj)->v0;
      ccv1->v1  = ((CurvBSpl*)obj)->v1;
      break;

    default:
      TX_Print ("***** UT3D_ccv_obj I1-%d",form);
      return -1;
  }


    // UT3D_stru_dump (Typ_CVCCV, ccv1, " ex UT3D_ccv_obj");

  return 0;

}


//================================================================
  int AP_GA_get (int *iAtt, int typ, long dbi) {
//================================================================
/// \code
/// get GraficAttribute for DB-obj
/// Output:
///  retCod    1  no GA-Record exists
///            0  OK, iAtt = GraficAttribute
/// \endcode

  int      basTyp;
  long     gaNr;
  ObjAtt   *ga1;


  basTyp = AP_typ_2_bastyp (typ);

  // find GA-rec if already exist
  gaNr = GA_find__ (basTyp, dbi);
  if(gaNr < 0) {
    *iAtt = Typ_Att_hili1;    // curves
    return 1;                 // skip, no GA-Record exists
  }


  GA_getRec (&ga1, gaNr);
  // if(typTyp == Typ_go_LCS) {
    *iAtt = ga1->iatt;


  return 0;

}

 
//================================================================
  int PRCV_test__ () {
//================================================================
 

  printf("PRCV_test__ \n");


  OS_system ("rm -rf /mnt/serv1/Devel/gcad3d/gCAD3D/tmp/*.odat");

  PRCV_test_1 (Typ_CV, 23L);  return 0;

  PRCV_test_set (Typ_CI, 20L);
  PRCV_test_set (Typ_CV, 20L);
  PRCV_test_set (Typ_CV, 23L);

    // TESTBLOCK
    PRCV_dump_dbo (2, Typ_CI, 20L);
    PRCV_dump_dbo (2, Typ_CV, 20L);
    // END TESTBLOCK


  // get PRCV for bin.Obj
  PRCV_test_get (Typ_CV, 23L);


  return 0;

}


//================================================================
  int PRCV_test_1 (int typ, long dbi) {
//================================================================
// test new func UTO_cv_ck_cyc


  int      irc, form, oNr, i1, sTyp, rev, clo, cyc;
  void     *obj;
  char     sObj[OBJ_SIZ_MAX];
  CurvCCV  *ccv1;


  printf("PRCV_test_1 %d %ld\n", typ, dbi);

  form = DB_GetObjDat (&obj, &oNr, typ, dbi);
    printf(" form=%d\n",form);
  if(form != Typ_CVCCV) return -1;


  //----------------------------------------------------------------
  for(i1=0; i1<oNr; ++i1) {

    // ccv1 = next trimmedCurve
    ccv1 = &((CurvCCV*)obj)[i1];
       printf("--------------------- CCV [%d] \n",i1);
       UT3D_stru_dump (Typ_CVCCV, ccv1, " ccv[%d]: ",i1);

    // get basic-curve
    UTO_cv_cvtrm (&sTyp, sObj, NULL, ccv1);

    // get flag cyclic
    UTO_cv_ck_rev_clo_cyc (&rev, &clo, &cyc, sTyp, sObj);

  }




  return 0;

}


//================================================================
  int PRCV_test_set (int typ, long dbi) {
//================================================================
 
  int   iAtt;
  long  dli;



  printf("################################################ \n");
  printf("PRCV_test_set %d %ld\n", typ, dbi);


/*
  // get dli
  dli = DL_find_obj (typ, dbi, -1L); 

  // if(dli >= 0) DL_SetInd (dli);  // overwrite existing DL-record

  // get GraficAttribute for curve
  AP_GA_get (&iAtt, typ, dbi);
    iAtt = 7; // TEST  7=gelb 9=rot
  
  if(dli >= 0) DL_set_iatt (dli, iAtt);  // overwrite attribute
*/

  // create PRCV for typ/dbi
  // mode: 1=write_file; 2=read_file; 4=display
  PRCV_set_dbo__ (typ, dbi);


    // TESTBLOCK
    // PRCV_dump_dbo (2, typ, dbi);
    // END TESTBLOCK

  return 0;

}


//================================================================
  int PRCV_test_get (int typ, long dbi) {
//================================================================
// get PRCV for bin.Obj
// display

  CurvPrcv prc1;

  // get memspc for prc1.  See also PRCV_memspc_get.
  PRCV_memspc_get (&prc1, -1, memspc201, sizeof(memspc201));
  

  // get PRCV from DB-obj (typ/dbi)
  prc1.typ  = typ;
  prc1.dbi  = dbi;
  prc1.mdli = WC_modact_ind;
  PRCV_get_dbo__ (&prc1, typ, dbi);


    // TESTBLOCK
    PRCV_dump__ (1, &prc1);
    // END TESTBLOCK

  return 0;

}


//================================================================
  int PRCV_get_dbo__ (CurvPrcv *prc1) {
//================================================================
// get PRCV for DB-obj (typ/dbi)
// Input:
//   global:  using memspc201 for prc1-data
//   prc1     empty PRCV


  int      irc, i1, form, oNr;
  void     *obj;
  CurvCCV  *ccv1;


  printf("\n============================= PRCV_get_dbo__ %d %ld\n",
         prc1->typ,prc1->dbi);



  // test for CCV (must resolv)
  if(prc1->typ != Typ_CV) goto L_get__;

    form = DB_GetObjDat (&obj, &oNr, prc1->typ, prc1->dbi);
      printf(" form=%d\n",form);
    if(form != Typ_CVCCV) goto L_get__;

    //----------------------------------------------------------------
    for(i1=0; i1<oNr; ++i1) {

      // ccv1 = next trimmedCurve
      ccv1 = &((CurvCCV*)obj)[i1];
         printf("--------------------- CCV [%d] \n",i1);
         UT3D_stru_dump (Typ_CVCCV, ccv1, " ccv[%d]: ",i1);

      //----------------------------------------------------------------
      // add line
      if(ccv1->typ != Typ_LN) goto L_add_trCv;
      // start-of-contour: add startpoint
      if(prc1->ptNr < 1) PRCV_get_dbo_add_p (prc1, ccv1->ip0);
      // add endpoint
      PRCV_get_dbo_add_p (prc1, ccv1->ip1);
      continue;

      //----------------------------------------------------------------
      L_add_trCv:    // add trimmed curve
        // get PRCV of ccv1 from par ps to par pe to prc1
        PRCV_get_dbo_add_tc (prc1, ccv1);
        continue;
    }

    goto L_exit;


  //----------------------------------------------------------------
  L_get__:
    // get PRCV of basecurve
    printf("**** PRCV_get_dbo__ TODO 1\n");

    // irc = PRCV_rdf__ (prc1);
    // if(irc < 0) {
      // TX_Error ("PRCV_get_dbo__ E1-%d-%ld",prc1->typ,prc1->dbi);
      // return -1;
    // }


  //----------------------------------------------------------------
  L_exit:

    // TESTBLOCK
    PRCV_dump__ (0, prc1);
    // END TESTBLOCK

  return 0;

}


//================================================================
  int PRCV_get_dbo_add_p (CurvPrcv *prc1, long ip1) {
//================================================================
// add a single point to prc1

  Point   *ptx;


  printf("PRCV_get_dbo_add_p %ld\n",ip1);

  // get point
  ptx = DB_get_PT (ip1);

  // add point
  prc1->npt[prc1->ptNr] = *ptx;

  prc1->npar[prc1->ptNr] = -1.;
  prc1->nipt[prc1->ptNr] = ip1;

  if(prc1->ptNr < prc1->siz) prc1->ptNr += 1;
  else {
    printf("**** PRCV_get_dbo_add_p EOM\n");
    return -1;
  }

  return 0;

}


//================================================================
  int PRCV_get_dbo_add_tc (CurvPrcv *prc1, CurvCCV *ccv1) {
//================================================================
// add prc2 from par ps to par pe to prc1
      
  int      irc, ips, ipe, ptNr, irev;
  CurvPrcv prc2;

  UT3D_stru_dump (Typ_CVCCV, ccv1, " PRCV_get_dbo_add_tc ");

  // get prc2 = PRCV for ccv1

  prc2.typ  = ccv1->typ;
  prc2.dbi  = ccv1->dbi;
  prc2.mdli = WC_modact_ind;

  irc = PRCV_rdf__ (&prc2);
  if(irc < 0) {
    TX_Error ("PRCV_get_dbo_add_tc E1-%d-%ld",prc1->typ,prc1->dbi);
    return -1;
  }
    // PRCV_dump__ (2, &prc2);


  // find startIndex ips in prc2
  ips = PRCV_get_tc_find (ccv1->v0, ccv1->ip0, &prc2);
  if(ips < 0) return -1;

  
  // find endIndex in prc2
  ipe = PRCV_get_tc_find (ccv1->v1, ccv1->ip1, &prc2);
  if(ipe < 0) return -1;


/*
  // test if closed-curve
  UTO_cv_ck_clo

  // test reverse / cyclic
  UTO_cv_ck_cyc_rev 
*/

  // add prc2 from ips to ipe to prc1
    printf(" PRCV_get_dbo_add_tc ips=%d ipe=%d\n",ips,ipe);
  if(ips > ipe) {
    // only closed curves - forward:
    // from ips to ipEnd and from ipStart to ipe.
    MEM_swap_int (&ips, &ipe);
    irev = 1;
  } else irev = 0;

  ptNr = ipe - ips + 1;
  if((prc1->ptNr + ptNr) > prc1->siz) {
    printf("**** PRCV_get_dbo_add_tc EOM-p2\n");
    return -2;
  }

  memcpy (&prc1->npt[prc1->ptNr], &prc2.npt[ips], sizeof(Point) * ptNr);

  prc1->ptNr += ptNr;

  if(irev) {
    MEM_inv_rtab (ptNr, &prc1->npt[prc1->ptNr], sizeof(Point));
  }


  // free prc2
  PRCV_rdf_free (&prc2);

  return 0;

}


//=====================================================================
  int PRCV_get_tc_find (double vx, long ipdb, CurvPrcv *prc) {
//=====================================================================

  int   i1;




  if(vx == UT_VAL_MAX) goto L_ck_ipt;


  //----------------------------------------------------------------
  for(i1 = 0; i1 < prc->ptNr; ++i1) {
    if(vx != prc->npar[i1]) continue;
    return i1;
  }
  printf("**** PRCV_get_tc_find E1 %lf %ld\n",vx,ipdb);
  return -1;

  //----------------------------------------------------------------
  L_ck_ipt:
  for(i1 = 0; i1 < prc->ptNr; ++i1) {
    if(ipdb != prc->nipt[i1]) continue;
    return i1;
  }
  printf("**** PRCV_get_tc_find E2 %lf %ld\n",vx,ipdb);
  return -1;

}
 

//================================================================
  int PRCV_set_dbo__ (int typ, long dbi) {
//================================================================
// create PRCV for DB-obj (typ/dbi)
// Input:
//   typ,dbi  dbo baseCurve
 
  int      irc, form, oNr, ptNr, i1, i2, oTyp;
  long     ip0s, ip0e, ip1s, ip1e, ipe;
  long     ipdb0s, ipdb0x,ipdb0e, ipdb1s, ipdb1x, ipdb1e;
  double   v0x, v1x, v0s, v0e, v1s, v1e;
  Point    *pa3, *ptx;
  char     cvCut[OBJ_SIZ_MAX];
  void     *obj, *cvBas;
  CurvCCV  *ccv1;
  CurvPrcv prc1, prc2;


  printf("============================= PRCV_set_dbo__ %d %ld\n",typ,dbi);


  form = DB_GetObjDat (&obj, &oNr, typ, dbi);
    printf(" form=%d\n",form);


  //----------------------------------------------------------------
  if(form != Typ_CVCCV) goto L_basCv;

  // resolv CCV; 
  // CCV does not have own PRCV; decode its component-curves and add all
  // necessary trim-points into its basic-curves.
  for(i1=0; i1<oNr; ++i1) {

    // ccv1 = next trimmedCurve
    ccv1 = &((CurvCCV*)obj)[i1];
       printf("--------------------- CCV [%d] \n",i1);
       UT3D_stru_dump (Typ_CVCCV, ccv1, " ccv[%d]: ",i1);

    // Lines: direct (no PRCV-file)
    if(ccv1->typ == Typ_LN) continue;

// TODO: CCV in CCV sollte recursiv aufgelöst werden !

    // get limiting parameters for curve
    v0x = ccv1->v0;
    v1x = ccv1->v1;
    ipdb0x = ccv1->ip0;
    ipdb1x = ccv1->ip1;
      printf(" v0x=%lf v1x=%lf\n",v0x,v1x);
      printf(" ipdb0x=%ld ipdb1x=%ld\n",ipdb0x,ipdb1x);

    // get basicCurve of trimmedCurve
    form = DB_GetObjDat (&cvBas, &i2, ccv1->typ, ccv1->dbi);
      printf(" form=%d oNr=%d\n",form,i2);
      // UT3D_stru_dump (form, cvBas, " UT3D_ccv_obj");


    // get v0-parameter for trimmedCurve
    if(v0x == UT_VAL_MAX) {
      // get parameter from point
      // get point from ipx
      ptx = DB_get_PT (ipdb0x);
      // get parameters from point
      UTO_parpt_pt_obj (&v0x, ptx, form, cvBas);
        // irc = UTO_get_ptlim (&v0, &v1, Typ_CVCCV, ccv1);
        // if(irc < 0) return -1;
    }

    // get v1-parameter for trimmedCurve
    if(v1x == UT_VAL_MAX) {
      // get parameter from point
      // get point from ipx
      ptx = DB_get_PT (ipdb1x);
      // get parameters from point
      UTO_parpt_pt_obj (&v1x, ptx, form, cvBas);
        // irc = UTO_get_ptlim (&v0, &v1, Typ_CVCCV, ccv1);
        // if(irc < 0) return -1;
    }
      printf(" v0x=%lf v1x=%lf\n",v0x,v1x);


    // make (v0x < v1x)
    if(v0x > v1x) {
      MEM_swap_2db (&v0x, &v1x);
      MEM_swap_2lg (&ipdb0x, &ipdb1x);
      printf(" mod1: v0x=%lf v1x=%lf\n",v0x,v1x);
    }


    // get PRCV of basecurve
    prc1.typ  = ccv1->typ;
    prc1.dbi  = ccv1->dbi;
    prc1.mdli = WC_modact_ind;
    irc = PRCV_rdf__ (&prc1);
    if(irc < 0) {
      TX_Error ("PRCV_set_dbo__ E1-%d-%ld",prc1.typ,prc1.dbi); 
      return -1;
    }
      // PRCV_dump__ (&prc1);

    // index last point
    ipe = prc1.ptNr - 1;


    // get memspc for prc2
    PRCV_memspc_get (&prc2, prc1.ptNr + 12, memspc501, sizeof(memspc501));

    // init prc2
    prc2.typ  = prc1.typ;
    prc2.dbi  = prc1.dbi;
    prc2.mdli = prc1.mdli;


    
    // find previous-parameter v0s and next-parameter v0e for v0x
    irc = PRCV_set_find (&ipdb0s, &ip0s, &v0s,
                         &ipdb0e, &ip0e, &v0e, &prc1, &v0x);
    if(irc < 0) goto L_Err1_exit;
      printf(" ip0s=%ld ip0e=%ld v0s=%lf v0e=%lf\n",ip0s,ip0e,v0s,v0e);



    // find previous-parameter v1s and next-parameter v1e for v1x
    irc = PRCV_set_find (&ipdb1s, &ip1s, &v1s,
                         &ipdb1e, &ip1e, &v1e, &prc1, &v1x);
    if(irc < 0) goto L_Err1_exit;
      printf(" ip1s=%ld ip1e=%ld v1s=%lf v1e=%lf\n",ip1s,ip1e,v1s,v1e);


    // test if (v0e >= v1x); if yes:
    if(v0e >= v1x) {
      v0e = v1x;
      v1s = v1x;
      ip1s = ip0e;
    }


    // copy 0.0 bis v0s (0 - ip0s)
      printf(" copy 0 - ip0s=%ld\n",ip0s);
    if(ip0s > 0) {
      printf("**** TODO COPY 1\n");
    }

    // add v0s bis v0x
      printf(" add v0s=%lf - v0x=%lf\n",v0s,v0x);
    if(v0s < v0x) {
      PRCV_set_seg (&prc2, form, cvBas, v0s, v0x, ipdb0s, ipdb0x);
    }

    // add v0x bis v0e
      printf(" add v0x=%lf - v0e=%lf\n",v0x,v0e);
    if(v0x < v0e) {
      PRCV_set_seg (&prc2, form, cvBas, v0x, v0e, ipdb0x, ipdb0e);
    }

    // copy v0e bis v1s (ip0e - ip1s)
      printf(" copy ip0e=%ld - ip1s=%ld\n",ip0e,ip1s);
    if(ip0e < ip1s) {
      printf("**** TODO COPY 2\n");
    }

    // add v1s bis v1x
      printf(" add v1s=%lf - v1x=%lf\n",v1s,v1x);
    if(v1s < v1x) {
      PRCV_set_seg (&prc2, form, cvBas, v1s, v1x, ipdb1s, ipdb1x);
    }

    // add v1x bis v1e
      printf(" add v1x=%lf - v1e=%lf\n",v1x,v1e);
    if(v1x < v1e) {
      PRCV_set_seg (&prc2, form, cvBas, v1x, v1e, ipdb1x, ipdb1e);
    }

    // copy v1e bis 1.0 (ip1e - end)
      printf(" copy ip1e=%ld - end=%ld\n",ip1e,ipe);
    if(ip0e < ipe) {
      printf("**** TODO COPY 3\n");
    }

      // TESTBLOCK
      // PRCV_dump__ (1, &prc2);
      // END TESTBLOCK

    // store curve
    PRCV_wrf__ (&prc2);

    PRCV_rdf_free (&prc1);

  }
  goto L_exit;



  //----------------------------------------------------------------
  L_basCv:
    // get PRCV of basecurve
    prc1.typ  = typ;
    prc1.dbi  = dbi;
    prc1.mdli = WC_modact_ind;
    irc = PRCV_rdf__ (&prc1);
    if(irc < 0) return PRCV_basCv (form, obj, dbi);


    // ip0 = 0;   // basCrv: no points !
    // ip1 = 0;   // basCrv: no points !

    // get limiting parameters for curve
    irc = UTO_get_ptlim (&v0x, &v1x, form, obj);
    if(irc < 0) return -1;

    printf("**** TODO AA1 \n");

    // find previous-parameter and next-parameter

    // copy curve start-parameter to previous-parameter

    // create and add curve previous-parameter to new-parameter
    // insert startpoint
    // irc = PRCV_insert_par (&prc2, &prc1, form, obj, v0, ip0);
    // if(irc < 0) return -1;

    // create and add curve new-parameter to next-parameter
    // insert endpoint
    // irc = PRCV_insert_par (&prc2, &prc1, form, obj, v1, ip1);
    // if(irc < 0) return -1;

    // copy curve next-parameter to end-parameter

    // store curve
    // PRCV_wrf__


  // // get trimmed-curve from bin-object (basecurve)
  // irc = UT3D_ccv_obj (&ccv1, form, dbi, obj);
  // // get PRCV from trimmed-curve
  // irc = PRCV_ccv__ (mode, &ccv1, form, obj, NULL, iAtt);
  // if(irc < 0) return irc;



  //----------------------------------------------------------------
  L_exit:
    return 0;



  //----------------------------------------------------------------
  L_Err1_exit:
    PRCV_rdf_free (&prc1);
    return irc;
}


//================================================================
  int PRCV_set_seg (CurvPrcv *prc, int form, void *cvBas,
                       double vs, double ve, long ipdbs, long ipdbe) { 
//================================================================
// add curve from vs to ve to PRCV

  int     irc, i1, iis, iie, ptNr, tabSiz;
  char    cvMod[OBJ_SIZ_MAX];
  Point   *pTab;


  printf("PRCV_set_seg form=%d vs=%lf ve=%lf ipdbs=%ld ipdbe=%ld\n",form,
         vs,ve,ipdbs,ipdbe);
    // UT3D_stru_dump (form, cvBas, " PRCV_set_seg - cvBas ");


  // create a copy of cvBas with modified v0, v1
  memcpy (cvMod, cvBas, OBJ_SIZ_MAX);
    // UT3D_stru_dump (form, cvMod, " PRCV_set_seg - cvMod1 ");
  UTO_set_ptlim (form, cvMod, NULL, &vs, NULL, &ve);
    // UT3D_stru_dump (form, cvMod, " PRCV_set_seg - cvMod2 ");


  //----------------------------------------------------------------
  iis = prc->ptNr;
  if(iis > 0) --iis;        // overwrite last point.

  pTab = &prc->npt[iis];             // add new points from here ..
  tabSiz = prc->siz - iis;           // remaining nr of points
    // printf(" iis=%d tabSiz=%d\n",iis,tabSiz);


  ptNr = 0;
  irc = UT3D_npt_obj (&ptNr, pTab, tabSiz, form, cvMod, 1, UT_DISP_cv);
  if(irc < 0) {
    printf("**** PRCV_set_seg UT3D_npt_obj %d\n",irc);
    return -1;
  }
  prc->ptNr = iis + ptNr;

  //----------------------------------------------------------------
  // init all parameters = invalid
  for(i1=0; i1<ptNr; ++i1) {
    prc->npar[iis + i1] = UT_VAL_MAX;
    prc->nipt[iis + i1] = 0;
  }

  prc->npar[iis] = vs;
  prc->nipt[iis] = ipdbs;
    // printf(" npar[%d]=%lf\n",iis,prc->npar[iis]);


  iie = iis + ptNr - 1;
  prc->npar[iie] = ve;
  prc->nipt[iie] = ipdbe;
    // printf(" npar[%d]=%lf\n",iie,prc->npar[iie]);


    // TESTBLOCK
    printf("ex PRCV_set_seg prc.ptNr=%d iis=%d ptNr=%d\n",prc->ptNr,iis,ptNr);
    // PRCV_dump__ (2, prc);
    // END TESTBLOCK




  return 0;

}

/*
//================================================================
  int PRCV_insert_par (CurvPrcv *prc2, CurvPrcv *prc1,
                       int form, void *cvBas, double vx, long ipx) {
//================================================================
 
  int     irc;
  long    ips, ipe;
  Point   *ptx;

  
  printf("PRCV_insert_par form=%d ipx=%ld\n",form,ipx);


  // get parameter vx from ipx
  if(vx != UT_VAL_MAX) goto L_1;

  // get point from ipx
  ptx = DB_get_PT (ipx);

  // get parameters from point
  UTO_parpt_pt_obj (&vx, ptx, form, cvBas);




  //----------------------------------------------------------------
  L_1:
    printf("PRCV_insert_par vx=%lf ipx=%ld form=%d\n",vx,ipx,form);

    // find previous-parameter v0 and next-parameter v1
    irc = PRCV_set_find (&ips, &ipe, prc1, &vx);
    if(irc < 0) return irc;

    // copy curve start-parameter to previous-parameter

    // create and add curve previous-parameter to new-parameter
    // irc = PRCV_insert_cvTrm (&prc1, form, obj, v0, ipx);
    // if(irc < 0) return -1;

    // create and add curve new-parameter to next-parameter
    // irc = PRCV_insert_cvTrm (&prc1, form, obj, v1, ipx);
    // if(irc < 0) return -1;

    // copy curve next-parameter to end-parameter



  // get points -> prc.npt
  // irc = UT3D_npt_obj (&prc->ptNr, prc->npt, tabSiz, form, cvBas, 1, UT_DISP_cv);

  // fix index of start/endpoints in PRCV

  return 0;

}
*/

//===========================================================================
  int PRCV_set_find (long *ipdbs, long *ips, double *vs,
                     long *ipdbe, long *ipe, double *ve,
                     CurvPrcv *prc1, double *vx) {
//===========================================================================
// get previous-parameter and next-parameter

  int    i1, ie;


  printf("PRCV_set_find %lf\n",*vx);

  ie = prc1->ptNr - 1;

  *ips   = 0;
  *vs    = prc1->npar[0];
  *ipdbs = prc1->nipt[0];

  *ipe   = ie;
  *ve    = prc1->npar[ie];
  *ipdbe = prc1->nipt[ie];

    // TESTBLOCK
    printf(" ips=%ld ipe=%ld vs=%lf ve=%lf\n",*ips,*ipe,*vs,*ve);
    // END TESTBLOCK

  for(i1 = 0; i1 < prc1->ptNr; ++i1) {

    if(prc1->npar[i1] == UT_VAL_MAX) continue;
    if(prc1->npar[i1] < *vx) {
      *ips = i1;
      *vs  = prc1->npar[i1];
      *ipdbs = prc1->nipt[i1];
      continue;
    }

    *ipe = i1;
    *ve  = prc1->npar[i1];
    *ipdbe = prc1->nipt[i1];

  }

    printf("ex PRCV_set_find ips=%ld ipdbs=%ld vs=%lf ipe=%ld ipdbe=%ld ve=%lf vx=%lf\n",
           *ips,*ipdbs,*vs, *ipe,*ipdbe,*ve, *vx);


  return 0;

}

 
//================================================================
  int PRCV_basCv (int form, void *cvBas, long dbi) {
//================================================================
// create PRCV for basicCurve

  int       irc, i1, ptNr, tabSiz;
  // long      ips, ipe;
  double    v0, v1;
  CurvPrcv  prc;


  printf("PRCV_basCv \n");
  UT3D_stru_dump (form, cvBas, " PRCV_basCv ");


  //----------------------------------------------------------------
  // get nr of necessary points for bin-cvCut
  ptNr = UT3D_ptNr_obj (form, cvBas, UT_DISP_cv);
  if(ptNr < 2) {TX_Error ("PRCV_basCv E2-TODO"); return -1;}

  tabSiz = ptNr + 12;
    printf(" tabSiz=%d\n",tabSiz);


  //----------------------------------------------------------------
  // get memSpc for PRCV
  prc.siz  = tabSiz;
  prc.ptNr = 0;
  prc.npt  = (Point*)MEM_alloc_tmp(sizeof(Point) * tabSiz);
  prc.npar = (double*)MEM_alloc_tmp(sizeof(double) * tabSiz);
  prc.nipt = (long*)MEM_alloc_tmp(sizeof(long) * tabSiz);
  prc.fTmp = 1;  // 0=malloced-must-free; 1=heapSpc

  // init
  prc.typ  = AP_typ_2_bastyp (form);
  prc.dbi  = dbi;
  prc.mdli = WC_modact_ind;

  // init all pointIndices = 0
  memset (prc.nipt, '\0', sizeof(long) * tabSiz);

  // init all parameters = invalid
  for(i1=0; i1<tabSiz; ++i1) prc.npar[i1] = UT_VAL_MAX;



  //----------------------------------------------------------------
  // get points -> prc.npt
  ptNr = 0;
  irc = UT3D_npt_obj (&ptNr, prc.npt, tabSiz, form, cvBas, 1, UT_DISP_cv);
  prc.ptNr = ptNr;
  if(irc < 0) return -1;
    printf(" npt_cvCut irc=%d ptNr=%d\n",irc,ptNr);
  // see also: UT3D_npt_obj UT3D_npt_ci UT3D_cv_ci UT3D_pta_ccv


  // get limiting parameters for curve
  irc = UTO_get_ptlim (&v0, &v1, form, cvBas);
  if(irc < 0) return -1;


  // set parameters
  prc.npar[0] = v0;
  i1 = prc.ptNr - 1;
  prc.npar[i1] = v1;


    // TESTBLOCK
    // PRCV_dump__ (1, &prc);
    // END TESTBLOCK


  //----------------------------------------------------------------
  // write file
  PRCV_wrf__ (&prc);


  return 0;

}

/*
//=====================================================================
  int PRCV_insert__ (CurvCCV *ccvi, int form, void *cvCut, void *cvBas) {
//=====================================================================
// Create PRC with one or 2 intermediate points
// insert cutPoints ip0 and ip1 into PRC of basicCurve
// Input:
//   ccvi      trimmed-curve
//   form      type of data of cvBas and cvCut
//   cvCut     data standardCurve of ccvi
//   cvBas     data baseCurve (ccvi->dbi) NULL if cvCut == cvBas
// Output:
//   irc       -1  PRCV (file)  for baseCurve does not exist
//
// load basecurve; find previous-point, find next-point;
// make curve previous-point to insert-point
// make curve insert-point to next-point;
// write curve start-point to previous-point;
// write curve previous-point to insert-point;
// write curve insert-point to end-point.

// replacing PRCV_ccv__


  int       irc, ptNr, tabSiz, mode, ips, ipe;
  Point     *ptx;
  CurvCCV   cvx;
  CurvPrcv  prcBas, prcCut;


  printf("--------------------------------- \n");
  UT3D_stru_dump (Typ_CVCCV, ccvi, " PRCV_insert__ ccvi");
 

  // prcBas.dbi  = ccvi->dbi;
  // prcBas.mdli = WC_modact_ind;


  // load basecurve;
  irc = PRCV_rdf__ (&prcBas);
  if(irc < 0) {
    // create basicCurve
    return -1;
  }


  //----------------------------------------------------------------
  // get nr of necessary points for bin-cvCut
  if(prcBas.ptNr < 2) {
    ptNr = UT3D_ptNr_obj (form, cvCut, UT_DISP_cv);
    if(ptNr < 2) {TX_Error ("PRCV_ccv__ E2-TODO"); return -1;}
    prcCut.ptNr = ptNr;
      printf(" ptNr=%d\n",ptNr);
  }


  //----------------------------------------------------------------
  // get memSpc for PRCV
  tabSiz = prcCut.ptNr + 10;
    printf(" tabSiz=%d\n",tabSiz);
  prcCut.npt = (Point*)MEM_alloc_tmp(sizeof(Point) * tabSiz);
  prcCut.npar = (double*)MEM_alloc_tmp(sizeof(double) * tabSiz);
  prcCut.nipt = (long*)MEM_alloc_tmp(sizeof(long) * tabSiz);
  prcCut.fTmp = 1;  // 0=malloced-must-free; 1=heapSpc

  // init
  memset (prcCut.nipt, '\0', sizeof(long) * tabSiz);


  // first ccvi->ip0, then ccvi->ip1
  cvx = *ccvi;

  if(prcBas.ptNr < 2) {
    mode = 2;
    goto L_nxt_pt;
  }

  mode = 0;       // mode: 0=ip0_to_ipx; 1=ipx_to_ip1; 2=ip0_to_ip1
  // get ips = startpoint of basic-curve
  // get ipe = endpoint of basic-curve


  //================================================================
  L_nxt_pt:

  // find previous-point, find next-point;
  if(mode == 0) {
    // ips_to_ip0
    cvx.ip0 = ccvi->ip0;
    cvx.ip1 = ips;

  } else if(mode == 1) {
    // ip1_to_ipe
    cvx.ip0 = ccvi->ip1;
    cvx.ip1 = ipe;

    // else mode = 2; ip0_to_ip1 - basic curve does not yet exist !
  }


  // get points for cvx
  prcCut.ptNr = 0;
  irc = UT3D_npt_obj (&prcCut.ptNr, prcCut.npt, tabSiz, form, &cvx,1,UT_DISP_cv);
  if(irc < 0) return -1;
    printf(" npt_cvx irc=%d ptNr=%d\n",irc,ptNr);
  // UT3D_npt_obj UT3D_npt_ci UT3D_cv_ci UT3D_pta_ccv




//   // insert point ipx;
//   // get parameter vx of point ipx
//   if(ccvi->v0 == UT_VAL_MAX) {
//     UTO_parpt_pt_obj (&vx, &ptx, form, cvBas);
//   }



  // insert cutPoint ip0


  // insert cutPoint ip1


// make curve previous-point to insert-point
// make curve insert-point to next-point;
// write curve start-point to previous-point;
// write curve previous-point to insert-point;
// write curve insert-point to end-point.



//   if(mode == 0) {
//     mode = 1;       // mode: 0=ip0_to_ipx; 1=ipx_to_ip1; 2=ip0_to_ip1
//     goto L_nxt_pt;
//   }
//   //================================================================


  PRCV_rdf_free (&prcBas);


  return 0;

}


//=========================================================================
  int PRCV_ccv__ (int mode, CurvCCV *ccvi,
                  int form, void *cvCut, void *cvBas, int iAtt) {
//=========================================================================
// get PRCV from trimmed-curve
// Input:
//   mode      1=write_file; 2=read_file; 4=display
//   ccvi      trimmed-curve
//   cvCut     data standardCurve of ccvi
//   cvBas     data basic-curve (ccvi->dbi) NULL if cvCut == cvBas
// Output:
//   file or display (mode)
 
  int       irc, oNr, ptNr, tabSiz, i1;
  long      l1, dli;
  CurvPrcv  prc;


  printf("=========================================== \n");
  printf("PRCV_ccv__ mode=%d iatt=%d\n",mode,iAtt);
  UT3D_stru_dump (Typ_CVCCV, ccvi, " ccvi");
  UT3D_dump_dbo (Typ_PT, ccvi->ip0, " ip0");
  UT3D_dump_dbo (Typ_PT, ccvi->ip1, " ip1");


  prc.typ  = AP_typ_2_bastyp (form);
  prc.dbi  = ccvi->dbi;
  prc.mdli = WC_modact_ind;


  //----------------------------------------------------------------
  // bit 2: read_file
  if(mode & 2) { 
    PRCV_rdf__ (&prc);
    goto L_100;
  }


  //----------------------------------------------------------------
  // get nr of necessary points for bin-cvCut
  ptNr = UT3D_ptNr_obj (form, cvCut, UT_DISP_cv);
  if(ptNr < 2) {TX_Error ("PRCV_ccv__ E2-TODO"); return -1;}

  prc.ptNr = ptNr;
    printf(" ptNr=%d\n",ptNr);


  //----------------------------------------------------------------
  // get memSpc for PRCV
  tabSiz = ptNr + 10;
  prc.npt = (Point*)MEM_alloc_tmp(sizeof(Point) * tabSiz);
  prc.npar = (double*)MEM_alloc_tmp(sizeof(double) * tabSiz);
  prc.nipt = (long*)MEM_alloc_tmp(sizeof(long) * tabSiz);
  prc.fTmp = 1;  // 0=malloced-must-free; 1=heapSpc

  // init
  memset (prc.nipt, '\0', sizeof(long) * tabSiz);



  //----------------------------------------------------------------
  // get points & parameters
  prc.ptNr = 0;
  irc = UT3D_npt_obj (&prc.ptNr, prc.npt, tabSiz, form, cvCut, 1, UT_DISP_cv);
  if(irc < 0) return -1;
    printf(" npt_cvCut irc=%d ptNr=%d\n",irc,ptNr);
  // UT3D_npt_obj UT3D_npt_ci UT3D_cv_ci UT3D_pta_ccv


  // store DB-ID's in PRCV
  i1 = prc.ptNr - 1;
  prc.nipt[0] = ccvi->ip0;
  prc.nipt[i1] = ccvi->ip1;


  // get & store parameters in PRCV
  if(ccvi->v0 == UT_VAL_MAX) 
    UTO_parpt_pt_obj (&prc.npar[0], &prc.npt[0], form, cvBas);

  if(ccvi->v1 == UT_VAL_MAX) 
    UTO_parpt_pt_obj (&prc.npar[i1], &prc.npt[i1], form, cvBas);

    printf(" par[%d]=%f\n",0,prc.npar[0]);
    printf(" par[%d]=%f\n",i1, prc.npar[i1]);


  // PRCV OK; use it according mode
    PRCV_dump__ (1, &prc);


  //----------------------------------------------------------------
  L_100:
  //----------------------------------------------------------------
  // bit 1: write_file
  if(mode & 1) { 
    PRCV_wrf__ (&prc);
  }


  //----------------------------------------------------------------
  // bit 2: display
  if(mode & 4) {
    dli = DL_StoreObj (Typ_CI, ccvi->dbi, iAtt);
      printf(" DISP: dli=%ld\n",dli);
      // for(i1=0;i1<prc.ptNr;++i1) UT3D_stru_dump(Typ_PT,&prc.npt[i1],"%d",i1);
    GL_DrawPoly (&dli, iAtt, prc.ptNr, prc.npt);
  }


  //----------------------------------------------------------------
  // free memspc
  if(!prc.fTmp) PRCV_rdf_free (&prc);


  return 0;

}
*/

//=====================================================================
  int PRCV_memspc_get (CurvPrcv *prc, int ptNr, char* mSpc, int mSiz) {
//=====================================================================
// Input:
//   ptNr     -1   use complete space
//            >0   get only this size
//   mSpc     memspc to be used
//   mSiz     size of mSpc in chars


  int   ii;
  char  *cp1;


  printf("PRCV_memspc_get %d\n",ptNr);


  ii = sizeof(Point) + sizeof(double) + sizeof(long);

  if(ptNr < 0) {
    // compute size
    ptNr = mSiz / ii;

  } else {
    // check size
    if((ptNr * ii) > mSiz) {
      printf("**** PRCV_memspc_get EOM\n");
      return -1;
    }
  }


  cp1 = mSpc;
  prc->npt = (Point*)cp1;
  cp1 += (sizeof(Point) * ptNr);
  prc->npar = (double*)cp1;
  cp1 += (sizeof(double) * ptNr);
  prc->nipt = (long*)cp1;

  prc->siz  = ptNr;   // size
  prc->ptNr = 0;
  prc->fTmp = 1;      // 0=malloced-must-free; 1=do not free

  return 0;

}

 
//================================================================
  int PRCV_wrf__ (CurvPrcv *prc) {
//================================================================
// write cvp into file "[M<subModelNr>]S<surf#>.odat"
// ofid   (objectfile-id)   subModelNr [M<subModelNr>]S<surf#>.odat
//  see APED_oid_dbo__


  int       rNr;
  char      ofid[128], cTyp;
  FILE      *fp1;


  cTyp = AP_typChar_typ (prc->typ);

  printf("PRCV_wrf__ M%d %c%ld\n",prc->mdli,cTyp,prc->dbi);


  if(prc->mdli >= 0) {           // 0-n = sind in Submodel; -1=main
    sprintf(ofid,"%sM%d_%c%ld.odat",OS_get_tmp_dir(),cTyp,prc->mdli,prc->dbi);
  } else {
    sprintf(ofid,"%s%c%ld.odat",OS_get_tmp_dir(),cTyp,prc->dbi);
  }
    printf(" ofid=|%s|\n",ofid);



  if((fp1=fopen(ofid,"wb")) == NULL) {
    TX_Print("PRCV_wrf__ E001 |%s|",ofid);
    return -1;
  }


  rNr = prc->ptNr;

  fwrite(prc, sizeof(CurvPrcv), 1, fp1);

  fwrite(prc->npt, sizeof(Point), rNr, fp1);
  fwrite(prc->npar, sizeof(double), rNr, fp1);
  fwrite(prc->nipt, sizeof(long), rNr, fp1);

  fclose(fp1);

    printf("ex PRCV_wrf__ ptNr=%d\n",rNr);


  return 0;

}


//================================================================
  int PRCV_rdf__ (CurvPrcv *prc) {
//================================================================
// read PRCV from file "[M<subModelNr>]S<surf#>.odat"
// Input:
//   prc->typ
//   prc->dbi
//   prc->mdli
// Output:
//   retCod      0 OK; MUST PRCV_rdf_free()
//              -1 file not found
//
// ofid   (objectfile-id)   subModelNr [M<subModelNr>]S<surf#>.odat
//  see APED_oid_dbo__


  int      tabSiz, ptNr;
  char     ofid[128], cTyp;
  FILE     *fp1;


  cTyp = AP_typChar_typ (prc->typ);

  printf("PRCV_rdf__ M%d %c%ld\n",prc->mdli,cTyp,prc->dbi);


  if(prc->mdli >= 0) {           // 0-n = sind in Submodel; -1=main
    sprintf(ofid,"%sM%d_%c%ld.odat",OS_get_tmp_dir(),cTyp,prc->mdli,prc->dbi);
  } else {
    sprintf(ofid,"%s%c%ld.odat",OS_get_tmp_dir(),cTyp,prc->dbi);
  }
    printf(" ofid=|%s|\n",ofid);



  if((fp1=fopen(ofid,"rb")) == NULL) {
    printf("**** PRCV_rdf__ I001 |%s|\n",ofid);
    return -1;
  }


  fread(prc, sizeof(CurvPrcv), 1, fp1);

  // set new siz
  ptNr = prc->ptNr;
  tabSiz = ptNr + 10;
  prc->siz = tabSiz;

  // get memSpc for PRCV.  See also PRCV_memspc_get.
  prc->npt = (Point*)malloc(sizeof(Point) * tabSiz);
  prc->npar = (double*)malloc(sizeof(double) * tabSiz);
  prc->nipt = (long*)malloc(sizeof(long) * tabSiz);
  prc->fTmp = 0;  // 0=malloced-must-free; 1=heapSpc


  fread(prc->npt, sizeof(Point), ptNr, fp1);
  fread(prc->npar, sizeof(double), ptNr, fp1);
  fread(prc->nipt, sizeof(long), ptNr, fp1);

  fclose(fp1);


  prc->fTmp = 2;
  
    printf("ex PRCV_rdf__ ptNr=%d\n",prc->ptNr);

  return 0;

}


//================================================================
  int PRCV_rdf_free (CurvPrcv *prc) {
//================================================================
 
  if(!prc->fTmp) {

    if(prc->npt)  free (prc->npt);
    if(prc->npar)  free (prc->npar);
    if(prc->nipt)  free (prc->nipt);
  }

  return 0;

}


//================================================================
  int PRCV_dump_dbo (int mode, int dbTyp, long dbi) {
//================================================================
// no PRC-files for Line, CurvCCV
// Input:
//   mode     0 print short
//            1 display
//            2 print all


  int       irc;
  CurvPrcv  prc;


  printf("PRCV_dump_dbo %d %d %ld\n",mode,dbTyp,dbi);

  // if((dbTyp == Typ_LN)      ||
     // (dbTyp == Typ_CVCCV)) goto L_e1;   hier nicht form !


  prc.typ  = dbTyp;
  prc.dbi  = dbi;
  prc.mdli = WC_modact_ind;


  irc = PRCV_rdf__ (&prc);
  if(irc < 0) return -1;

  PRCV_dump__ (mode, &prc);

  PRCV_rdf_free (&prc);

  return 0;

  // L_e1:
    // printf("**** PRCV_dump_dbo I1 %d %ld\n",dbTyp, dbi);
    // return -1;
}

 
//================================================================
  int PRCV_dump__ (int mode, CurvPrcv *prc) {
//================================================================
// Input:
//   mode     0 print short
//            1 display
//            2 print all
 

  int    i1, iatt;
  char   s1[80];


  printf("----------------------------------- PRCV_dump__ ptNr=%d siz=%d\n",
         prc->ptNr, prc->siz);

  for(i1 = 0; i1 < prc->ptNr; ++i1) {

    iatt = ATT_COL_YELLOW;

    if(mode == 2) {
      // print all
      if(prc->npar[i1] == UT_VAL_MAX) strcpy(s1, "    -undef-");
      else sprintf (s1, "%11.3f", prc->npar[i1]);
      printf("%5d pt = %11.3f %11.3f %11.3f   par %s   dbi %5ld\n", i1,
             prc->npt[i1].x, prc->npt[i1].y, prc->npt[i1].z,
             s1, // prc->npar[i1],
             prc->nipt[i1]);


    // print marked-points
    } else {
      if(prc->npar[i1] != UT_VAL_MAX) {
        iatt = ATT_COL_RED;
        // printf("prc.npar[%d] = %lf\n",i1,prc->npar[i1]);
        printf("%5d pt = %11.3f %11.3f %11.3f   par %11.3f   dbi %5ld\n", i1,
               prc->npt[i1].x, prc->npt[i1].y, prc->npt[i1].z,
               prc->npar[i1],
             prc->nipt[i1]);
      }
    }


    // display
    if(mode == 1) {
      APT_disp_SymB (SYM_TRI_S, iatt, &prc->npt[i1]);
      if(prc->nipt[i1]) GR_Disp_txi (&prc->npt[i1], i1, 0);
    }

  }
  
  return 0;

}


// EOF
