Changeset 326 in Sophya for trunk/SophyaPI/PIext/servnobjm.cc


Ignore:
Timestamp:
Jun 23, 1999, 4:41:47 PM (26 years ago)
Author:
ercodmgr
Message:

1/ NTupleInterface mis ds Outils++ et complete -
2/ Les PINtuple et PINtup3D utilisent maintenant NTupleInterface
3/ Debut modification interface NObjMgr - Reza 23/6/99

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/servnobjm.cc

    r295 r326  
    2424#include "ntuple.h"
    2525#include "hisprof.h"
     26
     27#include "piscdrawwdg.h"
     28#include "pisurfdr.h"
     29#include "pipodrw.h"
    2630
    2731
     
    122126FILE *fip;
    123127string fname = TmpDir + "expf_pia_dl.c";
    124 string fnamer = TmpDir + "expf_pia_dl";
    125128string cmd;
    126129int rc;
     
    147150fputs("return(1); \n} \n", fip);
    148151fclose(fip);
    149 
    150 return((PlotExprFunc)LinkFunctionFromFile(fnamer, "expf_pia_dl_func"));
    151 }
    152 
    153 
    154 /* --Methode-- */
    155 DlFunction Services2NObjMgr::LinkFunctionFromFile(string& fnamer, char* funcname)
    156 {
    157 string fname = fnamer + ".c" ;
    158 string fnameobj = fnamer + ".o" ;
    159 string fnameso = fnamer + ".so";
    160 
     152string func = "expf_pia_dl_func";
     153return((PlotExprFunc)LinkFunctionFromFile(fname, func));
     154}
     155
     156
     157/* --Methode-- */
     158DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname)
     159{
    161160//  Le link dynamique
    162161CloseDLL();
    163162dynlink = PDynLinkMgr::BuildFromCFile(fname);
    164163if (dynlink == NULL) {
    165   cerr << "NamedObjMgr/LinkFunctionFromFile_Erreur: Erreur ouverture SO " << endl;
     164  cerr << "NamedObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl;
    166165  return(NULL);
    167166  }
     
    181180{
    182181if (dynlink) delete dynlink;   dynlink = NULL;
     182}
     183
     184/* --Methode-- */
     185void Services2NObjMgr::PlotFunc(string const & expfunc, float xmin, float xmax, int np, string dopt)
     186{
     187FILE *fip;
     188string fname = TmpDir + "func1_pia_dl.c";
     189string  cmd;
     190int rc;
     191
     192if (!mImgapp)  return;
     193
     194cmd = "rm -f " + fname;
     195rc = system(cmd.c_str());
     196// printf("PlotFunc_Do> %s  (Rc=%d)\n", cmd.c_str(), rc);
     197
     198if ((fip = fopen(fname.c_str(), "w")) == NULL)   {
     199  string sn = fname;
     200  cout << "NamedObjMgr/PlotFunc_Erreur: Pb. Ouverture " << sn << endl;
     201  return;
     202  }
     203
     204// constitution du fichier a compiler
     205fputs("#include <math.h> \n", fip);
     206fputs("double func1_pia_dl_func(double x) \n{\n", fip);
     207fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
     208fclose(fip);
     209
     210string func = "func1_pia_dl_func";
     211DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
     212if (!f) return;
     213PlotFunc(f, xmin, xmax, np, dopt);
     214CloseDLL();
     215return;
     216}
     217
     218/* --Methode-- */
     219void Services2NObjMgr::PlotFunc2D(string const & expfunc, float xmin, float xmax, float ymin, float ymax,
     220                             int npx, int npy, string dopt)
     221{
     222FILE *fip;
     223string fname = TmpDir + "func2_pia_dl.c";
     224string cmd;
     225int rc;
     226
     227if (!mImgapp)  return;
     228
     229cmd = "rm " + fname;
     230rc = system(cmd.c_str());
     231// printf("PlotFunc2D_Do> %s  (Rc=%d)\n", cmd.c_str(), rc);
     232
     233if ((fip = fopen(fname.c_str(), "w")) == NULL)   {
     234  string sn = fname;
     235  cout << "NamedObjMgr/PlotFunc2D_Erreur: Pb. Ouverture " << sn << endl;
     236  return;
     237  }
     238
     239// constitution du fichier a compiler
     240fputs("#include <math.h> \n", fip);
     241fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip);
     242fprintf(fip,"return(%s); \n}\n", expfunc.c_str());
     243fclose(fip);
     244
     245string func = "func2_pia_dl_func";
     246DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
     247if (!f)  return;
     248PlotFunc2D(f, xmin, xmax, ymin, ymax, npx, npy, dopt);
     249CloseDLL();
     250return;
     251}
     252
     253/* --Methode-- */
     254void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, float xmin, float xmax,
     255                                       int np, string dopt)
     256{
     257DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func);
     258if (!f) return;
     259PlotFunc(f, xmin, xmax, np, dopt);
     260CloseDLL();
     261return;
     262}
     263
     264/* --Methode-- */
     265void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, float xmin, float xmax,
     266                                         float ymin, float ymax, int npx, int npy, string dopt)
     267{
     268DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func);
     269if (!f)  return;
     270PlotFunc2D(f, xmin, xmax, ymin, ymax, npx, npy, dopt);
     271CloseDLL();
     272return;
     273}
     274
     275/* --Methode-- */
     276void Services2NObjMgr::PlotFunc(DlFunctionOfX f, float xmin, float xmax, int np, string dopt)
     277{
     278if (!mImgapp)  return;
     279
     280int k;
     281if (np < 1) np = 1;
     282if (xmax <= xmin) xmax = xmin+1.;
     283Vector* vpy = new Vector(np);
     284
     285double xx;
     286double dx = (xmax-xmin)/np;
     287TRY {
     288  for(k=0; k<np; k++) { xx = xmin+dx*k; (*vpy)(k) = f(xx); }
     289} CATCH(merr) {
     290  fflush(stdout);
     291  cout << endl;
     292  cerr << endl;
     293  string es = PeidaExc(merr);
     294  cerr << "Services2NObjMgr::PlotFunc()  Exception :" << merr << es;
     295  delete vpy;
     296  vpy = NULL;
     297  } ENDTRY;
     298
     299
     300if (vpy) {
     301  string nom = "Func";
     302  P1DArrayAdapter* vya = new POVectorAdapter(vpy, true);
     303  vya->DefineXCoordinate(xmin, (xmax-xmin)/np);
     304  PIYfXDrawer* dr = new   PIYfXDrawer(vya, NULL, true) ;
     305  bool fgsr = true;
     306  dopt = "thinline," + dopt;
     307  int opt = DecodeDispOption(dopt, fgsr);
     308  int wrsid = mImgapp->DispScDrawer(dr, nom, opt);
     309  if (fgsr) mImgapp->RestoreGraphicAtt();
     310  }
     311
     312return;
     313}
     314
     315/* --Methode-- */
     316void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, float xmin, float xmax, float ymin, float ymax,
     317                             int npx, int npy, string dopt)
     318{
     319if (!mImgapp)  return;
     320
     321if (npx < 3) npx = 3;
     322if (npy < 3) npy = 3;
     323if (npx > 250) npx = 250;
     324if (npy > 250) npy = 250;
     325if (xmax <= xmin) xmax = xmin+1.;
     326if (ymax <= ymin) ymax = ymin+1.;
     327
     328Matrix* mtx = new Matrix(npy, npx);
     329
     330int i,j;
     331double xx, yy;
     332double dx = (xmax-xmin)/npx;
     333double dy = (ymax-ymin)/npy;
     334// printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax);
     335TRY {
     336  for(j=0; j<npy; j++) {
     337    yy = ymin+dy*j;
     338    for(i=0; i<npx; i++) {
     339      xx = xmin+dx*i;
     340      (*mtx)(j, i) = f(xx, yy);
     341    }
     342  }
     343} CATCH(merr) {
     344  fflush(stdout);
     345  cout << endl;
     346  cerr << endl;
     347  string es = PeidaExc(merr);
     348  cerr << "Services2NObjMgr::PlotFunc2D()  Exception :" << merr << es;
     349  delete mtx;  mtx = NULL;
     350  } ENDTRY;
     351
     352if (mtx) {
     353  string nom = "Func2";
     354  int wrsid = 0;
     355  bool fgsr = true;
     356  int opt = DecodeDispOption(dopt, fgsr);
     357  P2DArrayAdapter* arr = new POMatrixAdapter(mtx, true);
     358  arr->DefineXYCoordinates(xmin, ymin, dx, dy);
     359  PISurfaceDrawer* sdr = new PISurfaceDrawer(arr, true, true, true);
     360  wrsid = mImgapp->Disp3DDrawer(sdr, nom, opt);
     361  if (fgsr) mImgapp->RestoreGraphicAtt();
     362  }
     363
     364return;
    183365}
    184366
     
    211393if (fgsrgr) mImgapp->SaveGraphicAtt();
    212394
    213 if (gratt.substr(0,3) == "def")  {  // Remise aux valeurs par defaut = non defini
     395if ( (gratt == "def") || (gratt == "default") )  {  // Remise aux valeurs par defaut = non defini
    214396  mImgapp->SetColAtt();
    215397  mImgapp->SetLineAtt();
Note: See TracChangeset for help on using the changeset viewer.