File: Backend.cpp

package info (click to toggle)
mathgl 8.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 248,044 kB
  • sloc: cpp: 87,365; ansic: 3,299; javascript: 3,284; pascal: 1,562; python: 52; sh: 51; makefile: 47; f90: 22
file content (95 lines) | stat: -rw-r--r-- 2,724 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <QMessageBox>
#include <QTextStream>
#include <QFile>
#include <QDebug>
#include "Backend.hpp"
#include <mgl2/mgl.h>
#undef sprintf	// fix libintl bug of defining sprintf
//-----------------------------------------------------------------------------
Backend::Backend(QObject *parent) : QObject(parent) { }
//-----------------------------------------------------------------------------
QString Backend::show(const QString& text) const
{
	static size_t counter=size_t(0xffffffff*mgl_rnd());
	char tmp[256];
	snprintf(tmp,256,"%s/mathgl%lu.json", P_tmpdir, counter);
	tmp[255]=0;	counter++;
	qDebug() << __FUNCTION__;
	wchar_t *wtext;
	mglGraph gr;
	gr.SetFaceNum(200);
	mglParse pr;
	pr.AllowSetSize(true);
	setlocale(LC_ALL, "");	setlocale(LC_NUMERIC, "C");
	wtext = new wchar_t[text.size()+1];
	text.toWCharArray(wtext);
	wtext[text.size()] = 0;
	pr.Execute(&gr,wtext);
	delete[] wtext;
	gr.WriteJSON(tmp);
	setlocale(LC_NUMERIC, "");

	QFile f(tmp);
	f.open(QIODevice::ReadOnly);
	QTextStream ts(&f);
	ts.setAutoDetectUnicode(true);
	const QString json = ts.readAll();
	f.remove();
	return json;
}
//-----------------------------------------------------------------------------
QString Backend::coor(const QString& xy, const QString& text) const
{
	wchar_t *wtext;
	qDebug() << __FUNCTION__;
	mglGraph gr;
	mglParse pr;
	pr.AllowSetSize(true);
	setlocale(LC_ALL, "");	setlocale(LC_NUMERIC, "C");
	wtext = new wchar_t[text.size()+1];
	text.toWCharArray(wtext);
	wtext[text.size()] = 0;
	pr.Execute(&gr,wtext);
	delete[] wtext;
	gr.Finish();

	int x = (int)xy.section(" ",0,0).toDouble();
	int y = (int)xy.section(" ",1,1).toDouble();
	mglPoint p = gr.CalcXYZ(x,y);
	QString res = QString("x = %1, y = %2, z = %3 for point (%4, %5)\n").arg(p.x).arg(p.y).arg(p.z).arg(x).arg(y);
	qDebug() << res+"\nask"+xy;
	return res+"\nask"+xy;
}
//-----------------------------------------------------------------------------
QString Backend::geometry(const QString& mgl) const
{
	qDebug() << __FUNCTION__;
	char tmp[256];
	static size_t counter=size_t(0xffffffff*mgl_rnd());
	snprintf(tmp,256,"%s/mathgl%lu.json", P_tmpdir, counter);
	tmp[255]=0;	counter++;
	wchar_t *wmgl;
	mglGraph gr;
#if 0
	gr.SetFaceNum(200);
#endif
	mglParse pr;
	pr.AllowSetSize(true);
	setlocale(LC_ALL, "");	setlocale(LC_NUMERIC, "C");
	wmgl = new wchar_t[mgl.size()+1];
	mgl.toWCharArray(wmgl);
	wmgl[mgl.size()] = 0;
	pr.Execute(&gr,wmgl);
	delete[] wmgl;
	gr.WriteJSON(tmp);
	setlocale(LC_NUMERIC, "");

	QFile f(tmp);
	f.open(QIODevice::ReadOnly);
	QTextStream ts(&f);
	ts.setAutoDetectUnicode(true);
	const QString json = ts.readAll();
	f.remove();
	return json;
}
//-----------------------------------------------------------------------------