Changeset 326 in Sophya for trunk/SophyaPI/PIext/servnobjm.cc
- Timestamp:
- Jun 23, 1999, 4:41:47 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/servnobjm.cc
r295 r326 24 24 #include "ntuple.h" 25 25 #include "hisprof.h" 26 27 #include "piscdrawwdg.h" 28 #include "pisurfdr.h" 29 #include "pipodrw.h" 26 30 27 31 … … 122 126 FILE *fip; 123 127 string fname = TmpDir + "expf_pia_dl.c"; 124 string fnamer = TmpDir + "expf_pia_dl";125 128 string cmd; 126 129 int rc; … … 147 150 fputs("return(1); \n} \n", fip); 148 151 fclose(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 152 string func = "expf_pia_dl_func"; 153 return((PlotExprFunc)LinkFunctionFromFile(fname, func)); 154 } 155 156 157 /* --Methode-- */ 158 DlFunction Services2NObjMgr::LinkFunctionFromFile(string const & fname, string const & funcname) 159 { 161 160 // Le link dynamique 162 161 CloseDLL(); 163 162 dynlink = PDynLinkMgr::BuildFromCFile(fname); 164 163 if (dynlink == NULL) { 165 cerr << "NamedObjMgr/LinkFunctionFromFile_Erreur: Erreur ouverture SO " << endl;164 cerr << "NamedObjMgr/LinkFunctionFromFile_Erreur: Erreur creation/Ouverture SO " << endl; 166 165 return(NULL); 167 166 } … … 181 180 { 182 181 if (dynlink) delete dynlink; dynlink = NULL; 182 } 183 184 /* --Methode-- */ 185 void Services2NObjMgr::PlotFunc(string const & expfunc, float xmin, float xmax, int np, string dopt) 186 { 187 FILE *fip; 188 string fname = TmpDir + "func1_pia_dl.c"; 189 string cmd; 190 int rc; 191 192 if (!mImgapp) return; 193 194 cmd = "rm -f " + fname; 195 rc = system(cmd.c_str()); 196 // printf("PlotFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc); 197 198 if ((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 205 fputs("#include <math.h> \n", fip); 206 fputs("double func1_pia_dl_func(double x) \n{\n", fip); 207 fprintf(fip,"return(%s); \n}\n", expfunc.c_str()); 208 fclose(fip); 209 210 string func = "func1_pia_dl_func"; 211 DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func); 212 if (!f) return; 213 PlotFunc(f, xmin, xmax, np, dopt); 214 CloseDLL(); 215 return; 216 } 217 218 /* --Methode-- */ 219 void Services2NObjMgr::PlotFunc2D(string const & expfunc, float xmin, float xmax, float ymin, float ymax, 220 int npx, int npy, string dopt) 221 { 222 FILE *fip; 223 string fname = TmpDir + "func2_pia_dl.c"; 224 string cmd; 225 int rc; 226 227 if (!mImgapp) return; 228 229 cmd = "rm " + fname; 230 rc = system(cmd.c_str()); 231 // printf("PlotFunc2D_Do> %s (Rc=%d)\n", cmd.c_str(), rc); 232 233 if ((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 240 fputs("#include <math.h> \n", fip); 241 fputs("double func2_pia_dl_func(double x, double y) \n{\n", fip); 242 fprintf(fip,"return(%s); \n}\n", expfunc.c_str()); 243 fclose(fip); 244 245 string func = "func2_pia_dl_func"; 246 DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func); 247 if (!f) return; 248 PlotFunc2D(f, xmin, xmax, ymin, ymax, npx, npy, dopt); 249 CloseDLL(); 250 return; 251 } 252 253 /* --Methode-- */ 254 void Services2NObjMgr::PlotFuncFrCFile(string const & fname, string const & func, float xmin, float xmax, 255 int np, string dopt) 256 { 257 DlFunctionOfX f = (DlFunctionOfX) LinkFunctionFromFile(fname, func); 258 if (!f) return; 259 PlotFunc(f, xmin, xmax, np, dopt); 260 CloseDLL(); 261 return; 262 } 263 264 /* --Methode-- */ 265 void Services2NObjMgr::PlotFunc2DFrCFile(string const & fname, string const & func, float xmin, float xmax, 266 float ymin, float ymax, int npx, int npy, string dopt) 267 { 268 DlFunctionOfXY f = (DlFunctionOfXY) LinkFunctionFromFile(fname, func); 269 if (!f) return; 270 PlotFunc2D(f, xmin, xmax, ymin, ymax, npx, npy, dopt); 271 CloseDLL(); 272 return; 273 } 274 275 /* --Methode-- */ 276 void Services2NObjMgr::PlotFunc(DlFunctionOfX f, float xmin, float xmax, int np, string dopt) 277 { 278 if (!mImgapp) return; 279 280 int k; 281 if (np < 1) np = 1; 282 if (xmax <= xmin) xmax = xmin+1.; 283 Vector* vpy = new Vector(np); 284 285 double xx; 286 double dx = (xmax-xmin)/np; 287 TRY { 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 300 if (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 312 return; 313 } 314 315 /* --Methode-- */ 316 void Services2NObjMgr::PlotFunc2D(DlFunctionOfXY f, float xmin, float xmax, float ymin, float ymax, 317 int npx, int npy, string dopt) 318 { 319 if (!mImgapp) return; 320 321 if (npx < 3) npx = 3; 322 if (npy < 3) npy = 3; 323 if (npx > 250) npx = 250; 324 if (npy > 250) npy = 250; 325 if (xmax <= xmin) xmax = xmin+1.; 326 if (ymax <= ymin) ymax = ymin+1.; 327 328 Matrix* mtx = new Matrix(npy, npx); 329 330 int i,j; 331 double xx, yy; 332 double dx = (xmax-xmin)/npx; 333 double dy = (ymax-ymin)/npy; 334 // printf(" -- DBG -- %d %d , %g %g , %g %g \n", npx, npy, xmin, xmax, ymin, ymax); 335 TRY { 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 352 if (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 364 return; 183 365 } 184 366 … … 211 393 if (fgsrgr) mImgapp->SaveGraphicAtt(); 212 394 213 if ( gratt.substr(0,3) == "def") { // Remise aux valeurs par defaut = non defini395 if ( (gratt == "def") || (gratt == "default") ) { // Remise aux valeurs par defaut = non defini 214 396 mImgapp->SetColAtt(); 215 397 mImgapp->SetLineAtt();
Note:
See TracChangeset
for help on using the changeset viewer.