示例#1
0
//-----------------------------------------------------------------------------
void MemPanel::refresh()
{
	long n = parser.GetNumVar(), m=0;
	for(long i=0;i<n;i++)	if(parser.GetVar(i))	m++;
	tab->setRowCount(m);
	QString s;
	QTableWidgetItem *it;
	Qt::ItemFlags flags=Qt::ItemIsSelectable|Qt::ItemIsEnabled;
	for(long i=m=0;i<n;i++)
	{
		mglDataA *v = parser.GetVar(i);
		if(!v)	continue;
		s = QString::fromStdWString(v->s);
		it = new QTableWidgetItem(s);
		tab->setItem(m,0,it);	it->setFlags(flags);
		s.sprintf("%ld * %ld * %ld", v->GetNx(), v->GetNy(), v->GetNz());
		it = new QTableWidgetItem(s);
		tab->setItem(m,1,it);	it->setFlags(flags);
		it->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
		s.sprintf("%12ld", v->GetNN()*sizeof(mreal));
		it = new QTableWidgetItem(s);
		tab->setItem(m,2,it);	it->setFlags(flags);
		it->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
		if(v->o)	refreshData((QWidget *)v->o);
		m++;
	}
	tab->sortItems(colSort);
}
示例#2
0
//-----------------------------------------------------------------------------
void NewCmdDialog::nameChanged(int s)
{
	QString n=name->itemText(s), par, a;
	int k;
	if(n.isEmpty())	return;
	QStringList ss;	ss<<(pathHelp);
	help->setSearchPaths(ss);
	help->setSource(tr("mgl_en")+".html#"+n);
	// clear old
	kind->clear();	kinds.clear();	for(k=0;k<NUM_CH;k++)	argn[k].clear();
	// try to find the keyword
	if(!parser.CmdType(n.toStdString().c_str()))	return;
	info->setText(QString::fromLocal8Bit(parser.CmdDesc(n.toStdString().c_str())));

	par = QString::fromLocal8Bit(parser.CmdFormat(n.toStdString().c_str()));
	int i0 = par.indexOf(' ');	// first space if present
	if(i0<0)	{	kind->addItem(par);	return;	}	// no arguments
	// parse kind of arguments
	par = par.mid(i0);
	for(k=0;k<NUM_CH;k++)
	{
		a = par.section('|',k,k);
		if(a.isEmpty())	break;
		a=a.trimmed();
		kinds<<n+" "+a;
		parse(argn[k],a);
	}
	kind->addItems(kinds);	kind->setCurrentIndex(0);	replace = false;
}
示例#3
0
//-----------------------------------------------------------------------------
void MemPanel::delData()
{
	if(tab->rowCount()<1)	return;
	int	n = tab->currentRow();
	if(n<0)	n = 0;
	mglDataA *v = parser.FindVar(tab->item(n,0)->text().toStdString().c_str());
	if(!v && v->o)	((QWidget *)v->o)->close();
	parser.DeleteVar(tab->item(n,0)->text().toStdString().c_str());
	refresh();
}
示例#4
0
//-----------------------------------------------------------------------------
void DataDialog::updateNames()
{
	name->clear();
	long i, n = parser.GetNumVar();
	for(i=0;i<n;i++)
	{
		const mglDataA *v = parser.GetVar(i);
		if(v)	name->addItem(QString::fromStdWString(v->s));
	}
}
示例#5
0
void MainWindow::editPosChanged()
{
	QString text = edit->selection(), dlm(" #;:\t");
	int n = text.length(), i;
	for(i=0;i<n;i++)	if(dlm.contains(text[i]))	break;
	text.truncate(i);

	QByteArray qxtext = text.toLatin1();
	const char *ctext = qxtext.constData();
	const char *desc = parser.CmdDesc(ctext);
	const char *form = parser.CmdFormat(ctext);
	if(form)	setStatus(QString(desc)+": "+QString(form));
	else	setStatus(_("Not recognized"));
}
示例#6
0
//-----------------------------------------------------------------------------
void MemPanel::delAllData()
{
	if(QMessageBox::information(this, tr("UDAV - delete all data"),
			tr("Do you want to delete all data?"), QMessageBox::No,
			QMessageBox::Yes)!=QMessageBox::Yes)	return;
	parser.DeleteAll();	refresh();
}
示例#7
0
//-----------------------------------------------------------------------------
void DatPanel::hist()
{
	QLabel *l;
	QLineEdit *id, *v1, *v2;
	QSpinBox *nm;
	QPushButton *b;
	QDialog *d = new QDialog(this);	d->setWindowTitle(tr("UDAV - Make histogram"));
	QGridLayout *g = new QGridLayout(d);
	l = new QLabel(tr("From"), d);	g->addWidget(l,0,0);
	l = new QLabel(tr("To"), d);	g->addWidget(l,0,1);
	v1 = new QLineEdit(d);	g->addWidget(v1,1,0);
	v2 = new QLineEdit(d);	g->addWidget(v2,1,1);
	l = new QLabel(tr("Number of points"), d);	g->addWidget(l,2,0);
	l = new QLabel(tr("Put in variable"), d);	g->addWidget(l,2,1);
	nm = new QSpinBox(d);	nm->setRange(2,8192);	g->addWidget(nm,3,0);
	id = new QLineEdit(d);	nm->setSingleStep(10);	g->addWidget(id,3,1);
	b = new QPushButton(tr("Cancel"), d);	g->addWidget(b,4,0);
	connect(b, SIGNAL(clicked()), d, SLOT(reject()));
	b = new QPushButton(tr("OK"), d);		g->addWidget(b,4,1);
	connect(b, SIGNAL(clicked()), d, SLOT(accept()));	b->setDefault(true);
	// now execute dialog and get values
	bool res = d->exec();
	if(res && !v1->text().isEmpty() && !v2->text().isEmpty() && !id->text().isEmpty())
	{
		mglData *vv = dynamic_cast<mglData*>(parser.AddVar(id->text().toLocal8Bit().constData()));
		if(vv)	vv->Set(mgl_data_hist(var, nm->value(), v1->text().toDouble(), v2->text().toDouble(),0));
		updateDataItems();
	}
}
示例#8
0
//-----------------------------------------------------------------------------
void DataOpenDialog::prepareResult()
{
	code = "";	numDataOpened++;	data = name->text();
	// prepare unique value of name for next time
	char buf[32];	snprintf(buf,32,"mgl_%d",numDataOpened);
	buf[31]=0;	name->setText(buf);
	mglData *v = dynamic_cast<mglData*>(parser.AddVar(data.toLocal8Bit().constData()));
	if(!v)	return;
	int dd=0;
	if(rA->isChecked())	//	auto sizes
	{
		setlocale(LC_NUMERIC, "C");	v->Read(file.toLocal8Bit().constData());	setlocale(LC_NUMERIC, "");
		if(v->nx==1)	{	v->nx = v->ny;	v->ny = v->nz;	}
		code=QString("#read %1 '%2'\n").arg(data).arg(file);
	}
	else if(rM->isChecked())	//	manual sizes
	{
		int x=nx->text().toInt(), y=ny->text().toInt(), z=nz->text().toInt();
		setlocale(LC_NUMERIC, "C");	v->Read(file.toLocal8Bit().constData(),x,y,z);	setlocale(LC_NUMERIC, "");
		code=QString("#read %1 '%2' %3 %4 %5\n").arg(data).arg(file).arg(x).arg(y).arg(z);
	}
	else if(r2->isChecked())	//	matrix
	{
		setlocale(LC_NUMERIC, "C");	v->ReadMat(file.toLocal8Bit().constData());	setlocale(LC_NUMERIC, "");
		code=QString("#readmat %1 '%2'\n").arg(data).arg(file);		dd=1;
	}
	else if(r3->isChecked())	//	3d-data
	{
		setlocale(LC_NUMERIC, "C");	v->ReadMat(file.toLocal8Bit().constData(),3);	setlocale(LC_NUMERIC, "");
		code=QString("#readmat %1 '%2' 3\n").arg(data).arg(file);	dd=2;
	}
	if(scr->lineEdit()->text().isEmpty() || scr->lineEdit()->text()==tr("default"))
	{
		if(v->nz>1 || dd==2)
			code+=QString("rotate 40 60\ncrange %1:box\nsurf3 %1\n").arg(data);
		else if(v->ny>1 || dd==1)
			code+=QString("rotate 40 60\ncrange %1:zrange %1:box\nsurf %1\n").arg(data);
		else	code+=QString("yrange %1:box\nplot %1\n").arg(data);
	}
	else
	{
		QString str;
		QFile fp(scr->lineEdit()->text());
		if(fp.open(QFile::ReadOnly | QIODevice::Text))
		{
			QTextStream in(&fp);
			str = in.readAll();
			code += str.arg(data);
		}
	}

	QSettings settings("udav","UDAV");
	settings.setPath(QSettings::IniFormat, QSettings::UserScope, "UDAV");
	settings.beginGroup("/UDAV");
	settings.setValue("/dataScr", dataScr);
	settings.endGroup();

	accept();
}
示例#9
0
//-----------------------------------------------------------------------------
void NewCmdDialog::fillList()
{
	type->addItem(QPixmap(plot_xpm), tr("1D plots"));
	type->addItem(QPixmap(preview_xpm), tr("2D plots"));
	type->addItem(QPixmap(":/png/weather-clouds.png"), tr("3D plots"));
	type->addItem(QPixmap(tiles_xpm), tr("Dual plots"));
	type->addItem(QPixmap(vect_xpm), tr("Vector plots"));
	type->addItem(QPixmap(other_xpm), tr("Other plots"));
	type->addItem(QPixmap(text_xpm), tr("Text and legend"));
	type->addItem(QPixmap(table_xpm), tr("Create data and I/O"));
	type->addItem(QPixmap(oper_dir_xpm), tr("Data transform"));
	type->addItem(QPixmap(oper_dir_xpm), tr("Data handling"));
	type->addItem(QPixmap(axis_xpm), tr("Axis and colorbar"));
	type->addItem(QPixmap(axis_sh_xpm), tr("Axis setup"));
	type->addItem(QPixmap(":/png/preferences-system.png"), tr("General setup"));
	type->addItem(QPixmap(box_xpm), tr("Scale and rotate"));
	type->addItem(QPixmap(":/png/media-playback-start.png"), tr("Program flow"));
	type->addItem(QPixmap(curve_xpm), tr("Primitives"));

	// now fill it automatically from parser for all categories
	long i, n = parser.GetCmdNum();
	for(i=0;i<n;i++)
	{
		const char *name = parser.GetCmdName(i);
		switch(parser.CmdType(name))
		{
		case 1:	cmds[5]<<name;	break;
		case 2:	cmds[5]<<name;	break;
		case 3:	cmds[12]<<name;	break;
		case 4:	cmds[9]<<name;	break;
		case 5:	cmds[7]<<name;	break;
		case 6:	cmds[13]<<name;	break;
		case 7:	cmds[14]<<name;	break;
		case 8:	cmds[0]<<name;	break;
		case 9:	cmds[1]<<name;	break;
		case 10:	cmds[2]<<name;	break;
		case 11:	cmds[3]<<name;	break;
		case 12:	cmds[4]<<name;	break;
		case 13:	cmds[10]<<name;	break;
		case 14:	cmds[15]<<name;	break;
		case 15:	cmds[11]<<name;	break;
		case 16:	cmds[6]<<name;	break;
		case 17:	cmds[8]<<name;	break;
		}
	}
}
示例#10
0
//-----------------------------------------------------------------------------
void MemPanel::editData(int n)
{
	if(tab->rowCount()<1)	return;
	if(n<0)	n = tab->currentRow();
	if(n<0)	n = 0;
	mglDataA *v = parser.FindVar(tab->item(n,0)->text().toStdString().c_str());
	if(!v)	return;
	QWidget *t;
	if(v->o)	t = (QWidget *)v->o;
	else		t = newDataWnd(infoDlg,wnd,v);
	t->showMaximized();	t->activateWindow();
}
示例#11
0
//-----------------------------------------------------------------------------
void MemPanel::newTable()
{
	bool ok;
	QString name = QInputDialog::getText(this, tr("UDAV - New variable"),
				tr("Enter name for new variable"), QLineEdit::Normal, "", &ok);
	if(!ok || name.isEmpty())	return;
	mglData *v = parser.AddVar(name.toStdString().c_str());
	QWidget *t;
	if(v->o)	t = (QWidget *)v->o;
	else		t = newDataWnd(infoDlg,wnd,v);
	t->showMaximized();	t->activateWindow();
	refresh();
}
示例#12
0
//-----------------------------------------------------------------------------
void MemPanel::infoData()
{
	if(tab->rowCount()<1)	return;
	int	n = tab->currentRow();
	if(n<0)	n = 0;
	mglDataA *v = parser.FindVar(tab->item(n,0)->text().toStdString().c_str());
	if(!v)	return;
	infoDlg->setVar(v);
	QString s = QString::fromStdWString(v->s);
	infoDlg->setWindowTitle(s + tr(" - UDAV preview"));
	infoDlg->refresh();
	infoDlg->show();
}
示例#13
0
//-----------------------------------------------------------------------------
void DataDialog::nameChanged()
{
	QString var = name->currentText();
	wchar_t *txt=new wchar_t[var.length()+1];
	var.toWCharArray(txt);	txt[var.length()]=0;
	mglData dat=parser.Calc(txt);	delete []txt;
	x1->setMaximum(dat.nx-1);	x1->setValue(-1);
	x2->setMaximum(dat.nx-1);	x2->setValue(-1);
	y1->setMaximum(dat.ny-1);	y1->setValue(-1);
	y2->setMaximum(dat.ny-1);	y2->setValue(-1);
	z1->setMaximum(dat.nz-1);	z1->setValue(-1);
	z2->setMaximum(dat.nz-1);	z2->setValue(-1);
}
示例#14
0
//-----------------------------------------------------------------------------
void DataDialog::updateRes()
{
	result = name->currentText();
	int nx1 = x1->value(), nx2 = x2->value(), ny1 = y1->value(), ny2 = y2->value(), nz1 = z1->value(), nz2 = z2->value();
	if(nx1>=0 || ny1>=0 || nz1>=0 || nx2>=0 || ny2>=0 || nz2>=0)
		result += "(" + (nx1<0?"":QString::number(nx1)) + ":" + (nx2<0?"":QString::number(nx2)) + "," +
						(ny1<0?"":QString::number(ny1)) + ":" + (ny2<0?"":QString::number(ny2)) + "," +
						(nz1<0?"":QString::number(nz1)) + ":" + (nz2<0?"":QString::number(nz2)) + ")";
	if(oper->currentIndex()>0)
		result = "{" + oper->currentText() + " " + result + " '" + dirs->currentText() + "'}";
	wchar_t *txt=new wchar_t[result.length()+1];
	result.toWCharArray(txt);	txt[result.length()]=0;
	mglData dat=parser.Calc(txt);	delete []txt;
	sizes->setText(tr("Result (will have sizes ") + QString::number(dat.nx)+"*"+QString::number(dat.ny)+"*"+QString::number(dat.nz)+")"	);
	res->setText(result);
}
示例#15
0
//-----------------------------------------------------------------------------
void ArgsDialog::putArguments()
{
	int len=0;
	for(int i=0;i<10;i++)
			if(a[i]->text().length()>len)
				len = a[i]->text().length();
	wchar_t *str = new wchar_t[len+2];
	for(int i=0;i<10;i++)
	{
		QString s = a[i]->text();
		int j, n = s.length();
		for(j=0;j<n;j++)	str[j] = (s[j]).unicode();
		str[j] = 0;
		parser.AddParam(i, str);
	}
	delete []str;	accept();
}
示例#16
0
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
	char ch, iname[256]="";
	mgl_suppress_warn(true);
	while(1)
	{
		ch = getopt(argc, argv, "1:2:3:4:5:6:7:8:9:hL:s:");
		if(ch>='1' && ch<='9')	p.AddParam(ch-'0', optarg);
		else if(ch=='s')
		{
			setlocale(LC_CTYPE, "");
			FILE *fp = fopen(optarg,"r");
			if(fp)
			{
				wchar_t ch;
				while((ch=fgetwc(fp))!=WEOF)	opt.push_back(ch);
				fclose(fp);
			}
		}
		else if(ch=='L')	setlocale(LC_CTYPE, optarg);
		else if(ch=='h' || (ch==-1 && optind>=argc))
		{
			printf("mglview show plot from MGL script or MGLD file.\nCurrent version is 2.%g\n",MGL_VER2);
			printf("Usage:\tmglview [parameter(s)] scriptfile\n");
			printf(
				"\t-1 str       set str as argument $1 for script\n"
				"\t...          ...\n"
				"\t-9 str       set str as argument $9 for script\n"
				"\t-s opt       set MGL script for setting up the plot\n"
				"\t-L loc       set locale to loc\n"
				"\t-            get script from standard input\n"
				"\t-h           print this message\n" );
			ch = 'h';	break;
		}
		else if(ch==-1 && optind<argc)
		{	strncpy(iname, argv[optind][0]=='-'?"":argv[optind],256);	break;	}
	}
	if(ch=='h')	return 0;

	bool mgld=(*iname && iname[strlen(iname)-1]=='d');
	if(!mgld)
	{
		str = opt + L"\n";
		setlocale(LC_CTYPE, "");
		FILE *fp = *iname?fopen(iname,"r"):stdin;
		if(fp)
		{
			wchar_t ch;
			while((ch=fgetwc(fp))!=WEOF)	str.push_back(ch);
			fclose(fp);
		}
		else	{	printf("No file for MGL script\n");	return 0;	}
	}

	mgl_ask_func = mgl_ask_gets;
	mgl_ask_func = mgl_ask_qt;
	mglQT gr(mgld?NULL:show, *iname?iname:"mglview");
	if(mgld)
	{
		gr.Setup(false);
		gr.NewFrame();	setlocale(LC_NUMERIC, "C");
		if(!opt.empty())
		{
			p.Execute(&gr,opt.c_str());
			printf("Setup script: %s\n",gr.Message());
			gr.ImportMGLD(iname,true);
		}
		else	gr.ImportMGLD(iname);
		setlocale(LC_NUMERIC, "");	gr.EndFrame();
		gr.Update();
	}
	if(!mglGlobalMess.empty())	printf("%s",mglGlobalMess.c_str());
	return gr.Run();
}
示例#17
0
//-----------------------------------------------------------------------------
int show(mglGraph *gr)
{
	p.Execute(gr,str.c_str());
	printf("%s\n",gr->Message());
	return 0;
}
示例#18
0
//-----------------------------------------------------------------------------
void DatPanel::oper()
{
	QLineEdit *f1;
	QPushButton *b;
	QDialog *d = new QDialog(this);
	d->setWindowTitle(tr("UDAV - change data"));
	QVBoxLayout *v = new QVBoxLayout(d);
	QComboBox *c = new QComboBox(d);	v->addWidget(c);
	c->addItem(tr("Fill data by formula"));
	c->addItem(tr("Transpose data with new dimensions"));
	c->addItem(tr("Smooth data along direction(s)"));
	c->addItem(tr("Summarize data along direction(s)"));
	c->addItem(tr("Integrate data along direction(s)"));
	c->addItem(tr("Differentiate data along direction(s)"));
	c->addItem(tr("Laplace transform along direction(s)"));
	c->addItem(tr("Swap data along direction(s)"));
	c->addItem(tr("Mirror data along direction(s)"));
	c->addItem(tr("Sin-Fourier transform along direction(s)"));
	c->addItem(tr("Cos-Fourier transform along direction(s)"));
	c->addItem(tr("Hankel transform along direction(s)"));
	c->addItem(tr("Sew data along direction(s)"));
	c->addItem(tr("Find envelope along direction(s)"));
	c->setCurrentIndex(0);

	f1 = new QLineEdit("z",d);	v->addWidget(f1);
	QHBoxLayout *h = new QHBoxLayout();	v->addLayout(h);	h->addStretch(1);
	b = new QPushButton(tr("Cancel"), d);	h->addWidget(b);
	connect(b, SIGNAL(clicked()), d, SLOT(reject()));
	b = new QPushButton(tr("OK"), d);		h->addWidget(b);
	connect(b, SIGNAL(clicked()), d, SLOT(accept()));
	b->setDefault(true);
	// now execute dialog and get values
	bool res = d->exec();
	QString 	val = f1->text(), mgl;
	int k = c->currentIndex();
	QString self = QString::fromWCharArray(var->s.c_str());
	if(res)
	{
		if(k<0)
		{
			QMessageBox::warning(d, tr("UDAV - make new data"),
				tr("No action is selected. Do nothing."));
			return;
		}
		switch(k)
		{
		case 0:	mgl = "modify "+self+" '"+val+"'";	break;
		case 1:	mgl = "transpose "+self+" '"+val+"'";	break;
		case 2:	mgl = "smooth "+self+" '"+val+"'";	break;
		case 3:	mgl = "cumsum "+self+" '"+val+"'";	break;
		case 4:	mgl = "integrate "+self+" '"+val+"'";	break;
		case 5:	mgl = "diff "+self+" '"+val+"'";	break;
		case 6:	mgl = "diff2 "+self+" '"+val+"'";	break;
		case 7:	mgl = "swap "+self+" '"+val+"'";	break;
		case 8:	mgl = "mirror "+self+" '"+val+"'";	break;
		case 9:	mgl = "sinfft "+self+" '"+val+"'";	break;
		case 10:	mgl = "cosfft "+self+" '"+val+"'";	break;
		case 11:	mgl = "hankel "+self+" '"+val+"'";	break;
		case 12:	mgl = "sew "+self+" '"+val+"'";	break;
		case 13:	mgl = "envelop "+self+" '"+val+"'";	break;
		}
	}
	if(!mgl.isEmpty())
	{
		mglGraph gr;
		parser.Execute(&gr,mgl.toLocal8Bit().constData());
		opers += mgl+"\n";
		updateDataItems();
	}
}
示例#19
0
//-----------------------------------------------------------------------------
void QMGLSyntax::highlightBlock(const QString &text)
{
	register int i, j, m = text.length(),s=0;
	bool arg = false, nl = true;
	QString num("+-.0123456789:");
	i=0;
	setCurrentBlockState(-1);
	if(previousBlockState()==1)
	{
		bool cont=false;
		j=i;	i++;
		for(;i<m && text[i]!='\'';i++)
		{
			if(text[i]>' ')		cont=false;
			if(text[i]=='\\')	cont=true;
		}
		setFormat(j,i-j+1,mglColorScheme[1]);
		if(cont && i==m)	setCurrentBlockState(1);
	}
	for(;i<m;i++)				// highlight paragraph
	{
		if(text[i]=='(')	s++;	if(text[i]==')')	s--;
		if(text[i]==' ' || text[i]=='\t')	continue;
		else if(text[i]=='#')	// comment
		{	setFormat(i,m-i,mglColorScheme[0]);	break;	}
		else if(text[i]=='\'')	// string
		{
			bool cont=false;
			j=i;	i++;
			for(;i<m && text[i]!='\'';i++)
			{
				if(text[i]>' ')		cont=false;
				if(text[i]=='\\')	cont=true;
			}
			setFormat(j,i-j+1,mglColorScheme[1]);
			if(cont && i==m)	setCurrentBlockState(1);
		}
		else if(nl)				// keyword
		{
			char *s = new char[m+1];
			for(j=i;j<text.length() && !text[j].isSpace() && text[j]!=':';j++)
				s[j-i] = text[j].toLatin1();
			s[j-i]=0;
			int type = parser.CmdType(s);
			if(type)	setFormat(i,j-i+1,type!=7 ? (type==5 ? mglColorScheme[6] : mglColorScheme[2]) : mglColorScheme[7]);
			delete []s;
		}
		else if(text[i]==';')	{	arg = true;	nl = false;	continue;	}
		else if(text[i]==':' && s==0)	{	nl=true;	continue;	}
		else if(arg)			// option
		{
			const char *o[13]={"xrange","yrange","zrange","cut","meshnum","alpha","light","ambient","diffuse","size","legend","number","value"};
			unsigned l;
			for(j=0;j<13;j++)
			{
				l = strlen(o[j]);
				if(text.indexOf(o[j],i)==i && (i+l==long(text.length()) || text[i+l].isSpace()))
					setFormat(i,l,mglColorScheme[3]);
			}
		}
		else if(text[i]=='.' && i+1<text.length() && text[i+1].isLetter())	// suffix
		{
			for(j=i;j<text.length() && !text[j].isSpace();j++){};
			setFormat(i,j-i+1,mglColorScheme[4]);
		}
		else if(num.contains(text[i]))	// number
			setFormat(i,1,mglColorScheme[5]);
		else if((text[i]=='e' || text[i]=='E') && i+1<text.length() && num.contains(text[i-1]) && num.contains(text[i+1]) )
			setFormat(i,1,mglColorScheme[5]);
		else		// number as its symbolic id
		{
			const char *o[]={"nan","inf","pi","on","off"};
			int l[5] = {3, 3, 2, 2, 3};
			for(j=0;j<5;j++)
				if(text.indexOf(o[j],i)==i && (i+l[j]==text.length() || text[i+l[j]].isSpace()))
					setFormat(i,l[j],mglColorScheme[5]);
		}
		arg = nl = false;
	}
}
示例#20
0
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
	QString lang="";
	QSettings settings("udav","UDAV");
	settings.setPath(QSettings::IniFormat, QSettings::UserScope, "UDAV");
	settings.beginGroup("/UDAV");
	pathHelp = settings.value("/helpPath", MGL_DOC_DIR).toString();
	pathFont = settings.value("/userFont", "").toString();
	lang = settings.value("/udavLang", "").toString();
	
	const char *loc="";
	if(lang=="en")	loc = "C.UTF8";
#if WIN32
	if(lang=="ru")	loc = "ru_RU.cp1251";
#else
	if(lang=="ru")	loc = "ru_RU.utf8";
#endif
	if(lang=="es")	{	loc = "es_ES.utf8";	lang="en";	}	// TODO remove lang="en"; then Spanish translation is ready !
	mgl_textdomain(argv?argv[0]:NULL,loc);
	
	bool showHint = settings.value("/showHint", true).toBool();
	mglCompleter = settings.value("/completer",  true).toBool();
	settings.endGroup();

	mgl_suppress_warn(true);
	QCoreApplication::setAttribute(Qt::AA_X11InitThreads);
#ifdef WIN32
	QCoreApplication::addLibraryPath("c:/plugins/");
	QCoreApplication::addLibraryPath(QFileInfo(QString::fromLocal8Bit(argv[0])).absolutePath().append("/plugins/"));
#endif
	mgl_ask_func = mgl_ask_qt;
	QApplication a(argc, argv);
	QTranslator translator;
//QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#if defined(WIN32)
	if(pathHelp.isEmpty())	pathHelp = a.applicationDirPath()+"\\";
#else
	if(pathHelp.isEmpty())	pathHelp=MGL_DOC_DIR;
#endif

	if(!lang.isEmpty())
	{
		if(!translator.load("udav_"+lang, UDAV_DIR))
			translator.load("udav_"+lang, pathHelp);
		a.installTranslator(&translator);
	}

	udavLoadDefCommands();
	parser.AllowSetSize(true);
	MainWindow *mw = new MainWindow();
	if(argc>1)
	{
		QTextCodec *codec = QTextCodec::codecForLocale();
		mw->load(codec->toUnicode(argv[1]), true);
	}
	mw->show();
	mw->edit->edit->setFocus();
	a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
	if(showHint)	udavShowHint(mw);
	return a.exec();
}
示例#21
0
//-----------------------------------------------------------------------------
void DatPanel::newdat()
{
	QLabel *l;
	QLineEdit *f1, *f2;
	QPushButton *b;
	QDialog *d = new QDialog(this);
	d->setWindowTitle(tr("UDAV - make new data"));
	QVBoxLayout *v = new QVBoxLayout(d);
	QComboBox *c = new QComboBox(d);	v->addWidget(c);
	c->addItem(tr("Sum along direction(s)"));
	c->addItem(tr("Min along direction(s)"));
	c->addItem(tr("Max along direction(s)"));
	c->addItem(tr("Momentum along 'x' for function"));
	c->addItem(tr("Momentum along 'y' for function"));
	c->addItem(tr("Momentum along 'z' for function"));
	c->setCurrentIndex(0);

	f1 = new QLineEdit("z",d);	v->addWidget(f1);
	QCheckBox *cb = new QCheckBox(tr("Put into this data array"), d);	v->addWidget(cb);
	l = new QLabel(tr("or enter name for new variable"), d);	v->addWidget(l);
	f2 = new QLineEdit(d);		v->addWidget(f2);
	QHBoxLayout *h = new QHBoxLayout();	v->addLayout(h);	h->addStretch(1);
	b = new QPushButton(tr("Cancel"), d);	h->addWidget(b);
	connect(b, SIGNAL(clicked()), d, SLOT(reject()));
	b = new QPushButton(tr("OK"), d);		h->addWidget(b);
	connect(b, SIGNAL(clicked()), d, SLOT(accept()));
	b->setDefault(true);
	// now execute dialog and get values
	bool res = d->exec();
	QString 	val = f1->text(), mgl;
	int k = c->currentIndex();
	QString self = QString::fromWCharArray(var->s.c_str());
	if(res)
	{
		if(k<0)
		{
			QMessageBox::warning(d, tr("UDAV - make new data"),
				tr("No action is selected. Do nothing."));
			return;
		}
		if(val.isEmpty())
		{
			QMessageBox::warning(d, tr("UDAV - make new data"),
				tr("No direction/formula is entered. Do nothing."));
			return;
		}
		if(cb->isChecked())	k += 6;
		QString name = f2->text();
		switch(k)
		{
		case 0:	mgl = "sum "+name+" "+self+" '"+val+"'";	break;
		case 1:	mgl = "min "+name+" "+self+" '"+val+"'";	break;
		case 2:	mgl = "max "+name+" "+self+" '"+val+"'";	break;
		case 3:	mgl = "momentum "+name+" "+self+" 'x' '"+val+"'";	break;
		case 4:	mgl = "momentum "+name+" "+self+" 'y' '"+val+"'";	break;
		case 5:	mgl = "momentum "+name+" "+self+" 'z' '"+val+"'";	break;
		case 6:	mgl = "copy "+self+" {sum "+self+" '"+val+"'}";	break;
		case 7:	mgl = "copy "+self+" {min "+self+" '"+val+"'}";	break;
		case 8:	mgl = "copy "+self+" {max "+self+" '"+val+"'}";	break;
		case 9:	mgl = "copy "+self+" {momentum "+self+" 'x' '"+val+"'}";	break;
		case 10:	mgl = "copy "+self+" {momentum "+self+" 'y' '"+val+"'}";	break;
		case 11:	mgl = "copy "+self+" {momentum "+self+" 'z' '"+val+"'}";	break;
		}
	}
	if(!mgl.isEmpty())
	{
		mglGraph gr;
		parser.Execute(&gr,mgl.toLocal8Bit().constData());
		if(k>=6)	opers += mgl+"\n";
		updateDataItems();
	}
}