//----------------------------------------------------------------------------- void modify_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; const char *eq=fl_input(mgl_gettext("Enter formula for data modification\nHere x, y, z in range [0,1], u is data value"),0); HMDT d = dynamic_cast<HMDT>(e->var); if(d && eq != NULL) { d->Modify(eq); e->refresh(); } }
//----------------------------------------------------------------------------- void crop_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; crop_dlg.OK = false; crop_dlg.wnd->set_modal(); crop_dlg.wnd->show(); while(crop_dlg.wnd->shown()) Fl::wait(); HMDT d = dynamic_cast<HMDT>(e->var); if(d && crop_dlg.OK) { int n1,n2; n1 = 0; n2 = d->nx; if(crop_dlg.x1->value()[0]) n1 = atoi(crop_dlg.x1->value()); if(crop_dlg.x2->value()[0]) n2 = atoi(crop_dlg.x2->value()); d->Crop(n1, n2, 'x'); n1 = 0; n2 = d->ny; if(crop_dlg.y1->value()[0]) n1 = atoi(crop_dlg.y1->value()); if(crop_dlg.y2->value()[0]) n2 = atoi(crop_dlg.y2->value()); d->Crop(n1, n2, 'y'); n1 = 0; n2 = d->nz; if(crop_dlg.z1->value()[0]) n1 = atoi(crop_dlg.z1->value()); if(crop_dlg.z2->value()[0]) n2 = atoi(crop_dlg.z2->value()); d->Crop(n1, n2, 'z'); e->refresh(); } }
//----------------------------------------------------------------------------- void load_dat_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; char *newfile = fl_file_chooser(mgl_gettext("Load Data?"), mgl_gettext("DAT Files (*.{dat,csv})\tAll Files (*)"), 0); HMDT d = dynamic_cast<HMDT>(e->var); if(d && newfile != NULL) { d->Read(newfile); e->refresh(); } }
//----------------------------------------------------------------------------- void imp_dat_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; const char *scheme, *newfile = fl_file_chooser(mgl_gettext("Import Data?"), mgl_gettext("PNG Files (*.png)\tAll Files (*)"), 0); HMDT d = dynamic_cast<HMDT>(e->var); if(d && newfile != NULL) { scheme = fl_input(mgl_gettext("Enter color scheme"),MGL_DEF_SCH); if(scheme) { d->Import(newfile,scheme); e->refresh(); } } }
//----------------------------------------------------------------------------- void normal_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; nrm_dlg.OK = false; nrm_dlg.wnd->label(mgl_gettext("Normalize data")); nrm_dlg.dir->hide(); nrm_dlg.sym->show(); nrm_dlg.wnd->set_modal(); nrm_dlg.wnd->show(); while(nrm_dlg.wnd->shown()) Fl::wait(); HMDT d = dynamic_cast<HMDT>(e->var); if(d && nrm_dlg.OK) { d->Norm(nrm_dlg.min->value(), nrm_dlg.max->value(), nrm_dlg.sym->value()); e->refresh(); } }
//----------------------------------------------------------------------------- void new_dat_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; xyz_dlg.box->label(mgl_gettext("Specify new data size\nData will be zero filled")); xyz_dlg.ch->label(mgl_gettext("not used")); xyz_dlg.OK = false; xyz_dlg.wnd->set_modal(); xyz_dlg.wnd->show(); while(xyz_dlg.wnd->shown()) Fl::wait(); HMDT d = dynamic_cast<HMDT>(e->var); if(d && xyz_dlg.OK) { d->Create(int(xyz_dlg.mx->value()), int(xyz_dlg.my->value()), int(xyz_dlg.mz->value())); e->refresh(); } }
//----------------------------------------------------------------------------- void squeeze_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; xyz_dlg.box->label(mgl_gettext("Specify the skiping step\nEach m-th point will be skiped")); xyz_dlg.ch->label(mgl_gettext("smoothed")); xyz_dlg.OK = false; xyz_dlg.wnd->set_modal(); xyz_dlg.wnd->show(); while(xyz_dlg.wnd->shown()) Fl::wait(); HMDT d = dynamic_cast<HMDT>(e->var); if(d && xyz_dlg.OK) { d->Squeeze(int(xyz_dlg.mx->value()), int(xyz_dlg.my->value()), int(xyz_dlg.mz->value()), xyz_dlg.ch->value()); e->refresh(); } }
//----------------------------------------------------------------------------- void resize_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; xyz_dlg.box->label(mgl_gettext("Specify new data size\nData will be interpolated")); xyz_dlg.ch->label(mgl_gettext("not used")); xyz_dlg.OK = false; xyz_dlg.wnd->set_modal(); xyz_dlg.wnd->show(); while(xyz_dlg.wnd->shown()) Fl::wait(); HMDT d = dynamic_cast<HMDT>(e->var); if(d && xyz_dlg.OK) { mglData dd = d->Resize(int(xyz_dlg.mx->value()), int(xyz_dlg.my->value()), int(xyz_dlg.mz->value())); mgl_data_set(d, &dd); e->refresh(); } }
//----------------------------------------------------------------------------- void fill_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; nrm_dlg.OK = false; nrm_dlg.wnd->label(mgl_gettext("Fill in range")); nrm_dlg.dir->show(); nrm_dlg.sym->hide(); nrm_dlg.wnd->set_modal(); nrm_dlg.wnd->show(); while(nrm_dlg.wnd->shown()) Fl::wait(); HMDT d = dynamic_cast<HMDT>(e->var); if(d && nrm_dlg.OK) { char r='x'; if(nrm_dlg.dir->value()==1) r='y'; if(nrm_dlg.dir->value()==2) r='z'; d->Fill(nrm_dlg.min->value(),nrm_dlg.max->value(),r); e->refresh(); } }
//----------------------------------------------------------------------------- void transp_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; trsp_dlg.OK = false; trsp_dlg.wnd->set_modal(); trsp_dlg.wnd->show(); while(trsp_dlg.wnd->shown()) Fl::wait(); HMDT d = dynamic_cast<HMDT>(e->var); if(d && trsp_dlg.OK) { if(trsp_dlg.xyz->value()) d->Transpose("xyz"); if(trsp_dlg.xzy->value()) d->Transpose("xzy"); if(trsp_dlg.yxz->value()) d->Transpose("yxz"); if(trsp_dlg.yzx->value()) d->Transpose("yzx"); if(trsp_dlg.zxy->value()) d->Transpose("zxy"); if(trsp_dlg.zyx->value()) d->Transpose("zyx"); e->refresh(); } }
//----------------------------------------------------------------------------- void MGL_EXPORT mgl_data_fill_eq(HMGL gr, HMDT d, const char *eq, HCDT vdat, HCDT wdat, const char *opt) { if(vdat && vdat->GetNN()!=d->GetNN()) return; // incompatible dimensions if(wdat && wdat->GetNN()!=d->GetNN()) return; gr->SaveState(opt); std::wstring s = d->Name(); d->Name(L"u"); mglDataV x(d->nx,d->ny,d->nz, gr->Min.x,gr->Max.x,'x'); x.Name(L"x"); mglDataV y(d->nx,d->ny,d->nz, gr->Min.y,gr->Max.y,'y'); y.Name(L"y"); mglDataV z(d->nx,d->ny,d->nz, gr->Min.z,gr->Max.z,'z'); z.Name(L"z"); mglDataV i(d->nx,d->ny,d->nz, 0,d->nx-1,'x'); i.Name(L"i"); mglDataV j(d->nx,d->ny,d->nz, 0,d->ny-1,'y'); j.Name(L"j"); mglDataV k(d->nx,d->ny,d->nz, 0,d->nz-1,'z'); k.Name(L"k"); mglDataV r(d->nx,d->ny,d->nz); r.Name(L"#$mgl"); mglData v(vdat), w(wdat); v.Name(L"v"); w.Name(L"w"); std::vector<mglDataA*> list; list.push_back(&x); list.push_back(&y); list.push_back(&z); list.push_back(&r); list.push_back(d); list.push_back(&v); list.push_back(&w); list.push_back(&i); list.push_back(&j); list.push_back(&k); d->Move(mglFormulaCalc(eq,list)); d->Name(s.c_str()); gr->LoadState(); }
//----------------------------------------------------------------------------- HMDT MGL_EXPORT mgl_data_ifs_file(const char *fname, const char *name, long n, long skip) { gzFile fp = gzopen(fname,"r"); if(!fp) return 0; // Couldn't open file file char *buf = mgl_read_gz(fp); gzclose(fp); char *s = strstr(buf,name); if(!s) return 0; // No data for fractal 'name' in the file char *p = strchr(s,'{'), *e; if(!p) return 0; // Wrong data format for fractal 'name' in the file bool ext3d = false; e = strstr(s,"(3D)"); if(e && e<p) ext3d = true; e = strstr(s,"(3d)"); if(e && e<p) ext3d = true; e = strchr(p,'}'); std::vector<mreal> nums; for(size_t i=0;p[i] && p+i<e;i++) { while(p[i]<=' ') i++; if(p[i]==';' || p[i]=='#') while(p[i] && p[i]!='\n') i++; if(strchr("0123456789.+-",p[i])) // this is number { nums.push_back(atof(p+i)); while(p[i]>' ') i++; } } HMDT dat = new mglData, res; if(ext3d) { dat->Set(&(nums[0]), 13, nums.size()/13, 1); res = mgl_data_ifs_3d(dat, n, skip); } else { dat->Set(&(nums[0]), 7, nums.size()/7, 1); res = mgl_data_ifs_2d(dat, n, skip); } delete dat; free(buf); return res; }
//----------------------------------------------------------------------------- void amin_cb(Fl_Widget*, void*v) { TableWindow* e = (TableWindow*)v; nwdt_dlg.kind->value(0); nwdt_dlg.OK = false; nwdt_dlg.wnd->set_modal(); nwdt_dlg.wnd->show(); while(nwdt_dlg.wnd->shown()) Fl::wait(); if(nwdt_dlg.OK) { char r[8]=""; if(nwdt_dlg.dx->value()) strcat(r,"x"); if(nwdt_dlg.dy->value()) strcat(r,"y"); if(nwdt_dlg.dz->value()) strcat(r,"z"); if(!r[0]) return; HMDT d = dynamic_cast<HMDT>(e->var); if(!nwdt_dlg.name->value()[0] || !strcmp(nwdt_dlg.name->value(),e->label())) fl_alert(mgl_gettext("Name for output variable should be differ from this name")); else if(d) { mglData dd = d->Min(r); mgl_data_set(Parse->AddVar(nwdt_dlg.name->value()), &dd); } } }
//----------------------------------------------------------------------------- // convert substrings to arguments void mglParser::FillArg(mglGraph *gr, int k, std::wstring *arg, mglArg *a) { register long n; for(n=1;n<k;n++) { mglDataA *v; mglNum *f; a[n-1].type = -1; if(arg[n][0]=='|') a[n-1].type = -1; else if(arg[n][0]=='\'') // this is string (simplest case) { a[n-1].type = 1; std::wstring &w=arg[n],f; wchar_t buf[32]; long i,i1,ll=w.length(); for(i=1;i<ll;i++) { if(w[i]=='\'') { if(i==ll-1) continue; i++; i1 = i; if(w[i1]==',') i1++; if(w[i1]==0) continue; for(;i<ll && w[i]!='\'';i++); if(i>i1) { if(w[i1]=='!') { HADT d = mglFormulaCalcC(w.substr(i1+1,i-i1-(w[i]=='\''?1:0)), this, DataList); mreal di = imag(d->a[0]), dr = real(d->a[0]); if(di>0) mglprintf(buf,32,L"%g+%gi",dr,di); else if(di<0) mglprintf(buf,32,L"%g-%gi",dr,-di); // TODO use \u2212 ??? else mglprintf(buf,32,L"%g",dr); a[n-1].w += buf; delete d; } else { HMDT d = mglFormulaCalc(w.substr(i1,i-i1-(w[i]=='\''?1:0)), this, DataList); mglprintf(buf,32,L"%g",d->a[0]); a[n-1].w += buf; delete d; } } } else a[n-1].w += w[i]; } } else if(arg[n][0]=='{') { // this is temp data mglData *u=new mglData; std::wstring s = arg[n].substr(1,arg[n].length()-2); a[n-1].w = u->s = L"/*"+s+L"*/"; a[n-1].type = 0; ParseDat(gr, s, *u); a[n-1].d = u; u->temp=true; DataList.push_back(u); } else if((v = FindVar(arg[n].c_str()))!=0) // try to find normal variables (for data creation) { a[n-1].type=0; a[n-1].d=v; a[n-1].w=v->s; } else if((f = FindNum(arg[n].c_str()))!=0) // try to find normal number (for data creation) { a[n-1].type=2; a[n-1].d=0; a[n-1].v=f->d; a[n-1].c=f->c; a[n-1].w = f->s; } else if(arg[n][0]=='!') // complex array is asked { // parse all numbers and formulas by unified way HADT d = mglFormulaCalcC(arg[n].substr(1), this, DataList); if(d->GetNN()==1) { if(CheckForName(arg[n].substr(1))) { a[n-1].type = 2; a[n-1].v = d->v(0); a[n-1].c = d->a[0]; } else { a[n-1].type = 0; a[n-1].d = AddVar(arg[n].c_str()); } delete d; } else { a[n-1].w = L"/*"+arg[n]+L"*/"; d->temp=true; DataList.push_back(d); a[n-1].type = 0; a[n-1].d = d; } } else { // parse all numbers and formulas by unified way HMDT d = mglFormulaCalc(arg[n], this, DataList); if(d->GetNN()==1) { if(CheckForName(arg[n])) { a[n-1].type = 2; a[n-1].c = a[n-1].v = d->v(0); } else { a[n-1].type = 0; a[n-1].d = AddVar(arg[n].c_str()); } delete d; } else { a[n-1].w = L"/*"+arg[n]+L"*/"; d->temp=true; DataList.push_back(d); a[n-1].type = 0; a[n-1].d = d; } } } }