30 #include <QTextStream>
31 #include <QMessageBox>
51 Bounding_x1 = Bounding_x2 = Bounding_y1 = Bounding_y2 = 0;
53 xAxis.numGraphs = yAxis.numGraphs = zAxis.numGraphs = 0;
54 xAxis.min = xAxis.low =
55 yAxis.min = yAxis.low = zAxis.min = zAxis.low = 0.0;
56 xAxis.max = xAxis.up =
57 yAxis.max = yAxis.up = zAxis.max = zAxis.up = 1.0;
58 xAxis.GridOn = yAxis.GridOn =
true;
60 xAxis.log = yAxis.log = zAxis.log =
false;
62 xAxis.limit_min = yAxis.limit_min = zAxis.limit_min = 0.0;
63 xAxis.limit_max = yAxis.limit_max = zAxis.limit_max = 1.0;
64 xAxis.step = yAxis.step = zAxis.step = 1.0;
65 xAxis.autoScale = yAxis.autoScale = zAxis.autoScale =
true;
74 GridPen = QPen(Qt::lightGray,0);
75 Graphs.setAutoDelete(
true);
76 Arcs.setAutoDelete(
true);
77 Lines.setAutoDelete(
true);
78 Texts.setAutoDelete(
true);
90 for(
Line *pl = Lines.first(); pl != 0; pl = Lines.next()) {
92 p->
drawLine(cx+pl->x1, cy-pl->y1, cx+pl->x2, cy-pl->y2);
96 for(
struct Arc *pa = Arcs.first(); pa != 0; pa = Arcs.next()) {
98 p->
drawArc(cx+pa->x, cy-pa->y, pa->w, pa->h, pa->angle, pa->arclen);
103 for(pg = Graphs.first(); pg != 0; pg = Graphs.next())
104 pg->
paint(p, cx, cy);
110 QMatrix wm = p->
Painter->worldMatrix();
111 for(
Text *pt = Texts.first(); pt != 0; pt = Texts.next()) {
113 QMatrix(pt->mCos, -pt->mSin, pt->mSin, pt->mCos,
114 p->
DX +
float(cx+pt->x) * p->
Scale,
115 p->
DY +
float(cy-pt->y) * p->
Scale));
118 p->
Painter->drawText(0, 0, pt->s);
120 p->
Painter->setWorldMatrix(wm);
121 p->
Painter->setWorldXForm(
false);
127 for(pg = Graphs.first(); pg != 0; pg = Graphs.next())
129 pm->paint(p, cx, cy);
135 p->
map(cx, cy-y2, x_, y_);
136 fx_ = float(x2)*p->
Scale + 10;
137 fy_ = float(y2)*p->
Scale + 10;
139 p->
Painter->setPen(QPen(Qt::darkGray,3));
141 p->
Painter->setPen(QPen(Qt::darkRed,2));
160 int x, y, w, wmax = 0;
163 int LineSpacing = metrics.lineSpacing();
168 if(xAxis.Label.isEmpty()) {
170 for(pg = Graphs.first(); pg != 0; pg = Graphs.next()) {
175 w = metrics.width(pD->
Var) >> 1;
176 if(w > wmax) wmax = w;
177 Texts.append(
new Text(x-w, y, pD->
Var, pg->
Color, 12.0));
180 w = metrics.width(
"real("+pg->
Var+
")") >> 1;
181 if(w > wmax) wmax = w;
182 Texts.append(
new Text(x-w, y,
"real("+pg->
Var+
")",
190 w = metrics.width(Str) >> 1;
191 if(w > wmax) wmax = w;
192 Texts.append(
new Text(x-w, y, Str, Qt::black, 12.0));
195 Bounding_y1 = y - LineSpacing;
196 Bounding_x2 = wmax - (x2 >> 1);
197 if(Bounding_x2 < 0) Bounding_x2 = 0;
198 Bounding_x1 = Bounding_x2;
204 if(yAxis.Label.isEmpty()) {
206 for(pg = Graphs.first(); pg != 0; pg = Graphs.next()) {
210 w = metrics.width(pg->
Var) >> 1;
211 if(w > wmax) wmax = w;
212 Texts.append(
new Text(x, y-w, pg->
Var, pg->
Color, 12.0, 0.0, 1.0));
215 w = metrics.width(
"imag("+pg->
Var+
")") >> 1;
216 if(w > wmax) wmax = w;
217 Texts.append(
new Text(x, y-w,
"imag("+pg->
Var+
")",
218 pg->
Color, 12.0, 0.0, 1.0));
223 if(w > wmax) wmax = w;
225 pg->
Color, 12.0, 0.0, 1.0));
232 w = metrics.width(Str) >> 1;
233 if(w > wmax) wmax = w;
234 Texts.append(
new Text(x, y-w, Str, Qt::black, 12.0, 0.0, 1.0));
237 if(Bounding_x1 < -x) Bounding_x1 = -x;
242 if(zAxis.Label.isEmpty()) {
244 for(pg = Graphs.first(); pg != 0; pg = Graphs.next()) {
248 w = metrics.width(pg->
Var) >> 1;
249 if(w > wmax) wmax = w;
250 Texts.append(
new Text(x, y+w, pg->
Var,
251 pg->
Color, 12.0, 0.0, -1.0));
254 w = metrics.width(
"imag("+pg->
Var+
")") >> 1;
255 if(w > wmax) wmax = w;
256 Texts.append(
new Text(x, y+w,
"imag("+pg->
Var+
")",
257 pg->
Color, 12.0, 0.0, -1.0));
262 if(w > wmax) wmax = w;
264 pg->
Color, 12.0, 0.0, -1.0));
271 w = metrics.width(Str) >> 1;
272 if(w > wmax) wmax = w;
273 Texts.append(
new Text(x, y+w, Str, Qt::black, 12.0, 0.0, -1.0));
276 if(Bounding_x2 < x) Bounding_x2 = x;
282 if(wmax < Bounding_y1) Bounding_y1 = wmax;
292 else if(x >
float(x2))
297 else if(y >
float(y2))
307 float R = float(x2)/2.0 + 1.0;
310 return ((x*x + y*y) <= R*R);
318 float x=0, y=0, dx, dy;
319 float x_1 = *(p-4), y_1 = *(p-3);
320 float x_2 = *(p-2), y_2 = *(p-1);
322 int code1 = regionCode(x_1, y_1);
323 int code2 = regionCode(x_2, y_2);
324 if((code1 | code2) == 0)
return;
326 if(code1 != 0)
if(*(p-5) >= 0) {
342 if((code1 | code2) == 0)
break;
344 if(code1) code = code1;
350 y = y_1 - dy * x_1 / dx;
354 y = y_1 + dy * (x2-x_1) / dx;
358 x = x_1 - dx * y_1 / dy;
362 x = x_1 + dx * (y2-y_1) / dy;
369 code1 = regionCode(x, y);
374 code2 = regionCode(x, y);
397 float R = float(x2) / 2.0;
398 float x_1 = *(p-4) - R, y_1 = *(p-3) - R;
399 float x_2 = *(p-2) - R, y_2 = *(p-1) - R;
402 float dt2 = dt1 - x_2*x_2 - y_2*y_2;
403 dt1 -= x_1*x_1 + y_1*y_1;
405 if(dt1 >= 0.0)
if(dt2 >= 0.0)
return;
407 if(dt1 < 0.0)
if(*(p-5) >= 0.0) {
414 float C = x_1*x + y_1*y;
416 float F = C*C + dt1*D;
432 if((dt1 > 0.0) && (dt1 < D)) {
433 *(p-4) = x_1 - x*dt1 / D;
434 *(p-3) = y_1 - y*dt1 / D;
443 if((dt2 > 0.0) && (dt2 < D)) {
444 *(p-2) = x_1 - x*dt2 / D;
445 *(p-1) = y_1 - y*dt2 / D;
471 int i, z, tmp, Counter=2;
472 float dx, dy, xtmp, ytmp;
473 int Size = ((2*(g->
cPointsX.getFirst()->count) + 1) * g->
countY) + 10;
475 if(xAxis.autoScale)
if(yAxis.autoScale)
if(zAxis.autoScale)
481 float *p = (
float*)malloc( Size*
sizeof(
float) );
488 if(g->
yAxisNo == 0) pa = &yAxis;
491 double Stroke=10.0, Space=10.0;
494 for(i=g->
countY; i>0; i--) {
495 px = g->
cPointsX.getFirst()->Points;
496 calcCoordinate(px, pz, py, p, p+1, pa);
498 for(z=g->
cPointsX.getFirst()->count-1; z>0; z--) {
500 calcCoordinate(px, pz, py, p, p+1, pa);
508 if((*(p-2) < 0) || (*(p-1) < 0))
524 Stroke = 10.0; Space = 6.0;
527 Stroke = 2.0; Space = 4.0;
530 Stroke = 24.0; Space = 8.0;
534 for(i=g->
countY; i>0; i--) {
535 px = g->
cPointsX.getFirst()->Points;
536 for(z=g->
cPointsX.getFirst()->count; z>0; z--) {
537 calcCoordinate(px, pz, py, p, p+1, pa);
538 if(insideDiagram(*p, *(p+1)))
552 for(i=g->
countY; i>0; i--) {
555 px = g->
cPointsX.getFirst()->Points;
556 calcCoordinate(px, pz, py, &xtmp, &ytmp, pa);
560 for(z=g->
cPointsX.getFirst()->count-1; z>0; z--) {
563 calcCoordinate(px, pz, py, &xtmp, &ytmp, pa);
566 dist += sqrt(
double(dx*dx + dy*dy));
567 if(Flag == 1)
if(dist <= 0.0) {
572 if((++Counter) >= 2) clip(p);
575 alpha = atan2(
double(dy),
double(dx));
579 *(p++) = xtmp -
float(dist*cos(alpha));
580 *(p++) = ytmp -
float(dist*sin(alpha));
581 if((++Counter) >= 2) clip(p);
588 if((++Counter) >= 2) clip(p);
593 if(*(p-3) < 0) p -= 2;
595 if(Counter < 0) Counter = -50000;
606 if((*(p-2) < 0) || (*(p-1) < 0))
624 _x1 = cx - Bounding_x1;
625 _y1 = cy - y2 - Bounding_y2;
626 _x2 = cx + x2 + Bounding_x2;
627 _y2 = cy - Bounding_y1;
633 if(x_ >= cx-x1)
if(x_ <= cx+x3)
if(y_ >= cy-y2)
if(y_ <= cy+y1)
644 float fCX = float(cx), fCY = float(cy);
645 float fX2 = float(cx+x2), fY2 = float(cy-y2);
646 if(fX < fCX-len)
return false;
647 if(fX > fX2+len)
return false;
648 if(fY < fY2-len)
return false;
649 if(fY > fCY+len)
return false;
652 if(fX < fCX+len) State = 1;
653 else if(fX <= fX2-len)
return false;
654 if(fY > fCY-len) State |= 2;
655 else if(fY >= fY2+len)
return false;
670 for(z=pD->
count; z>0; z--) {
673 if(x > xAxis.max) xAxis.max = x;
674 if(x < xAxis.min) xAxis.min = x;
679 if(Name ==
"Rect3D") {
683 for(z=pDy->
count; z>0; z--) {
686 if(y > yAxis.max) yAxis.max = y;
687 if(y < yAxis.min) yAxis.min = y;
694 if(pg->
yAxisNo == 0) pa = &yAxis;
704 if(fabs(y) >= 1e-250) x = sqrt(x*x+y*y);
706 if(x > pa->
max) pa->
max = x;
707 if(x < pa->min) pa->
min = x;
712 if(x > xAxis.max) xAxis.max = x;
713 if(x < xAxis.min) xAxis.min = x;
716 if(y > pa->
max) pa->
max = y;
717 if(y < pa->min) pa->
min = y;
726 int yNum = yAxis.numGraphs;
727 int zNum = zAxis.numGraphs;
728 yAxis.numGraphs = zAxis.numGraphs = 0;
730 double xmin = xAxis.min, ymin = yAxis.min, zmin = zAxis.min;
731 double xmax = xAxis.max, ymax = yAxis.max, zmax = zAxis.max;
732 yAxis.min = zAxis.min = xAxis.min = DBL_MAX;
733 yAxis.max = zAxis.max = xAxis.max = -DBL_MAX;
736 for(
Graph *pg = Graphs.first(); pg != 0; pg = Graphs.next()) {
737 if(loadVarData(defaultDataSet, pg) != 1)
741 pg->lastLoaded = QDateTime::currentDateTime();
745 yAxis.numGraphs = yNum;
746 zAxis.numGraphs = zNum;
748 xAxis.min = xmin; yAxis.min = ymin; zAxis.min = zmin;
749 xAxis.max = xmax; yAxis.max = ymax; zAxis.max = zmax;
753 if(xAxis.min > xAxis.max)
754 xAxis.min = xAxis.max = 0.0;
755 if(yAxis.min > yAxis.max)
756 yAxis.min = yAxis.max = 0.0;
757 if(zAxis.min > zAxis.max)
758 zAxis.min = zAxis.max = 0.0;
771 yAxis.min = zAxis.min = xAxis.min = DBL_MAX;
772 yAxis.max = zAxis.max = xAxis.max = -DBL_MAX;
773 yAxis.numGraphs = zAxis.numGraphs = 0;
776 for(
Graph *pg = Graphs.first(); pg != 0; pg = Graphs.next())
779 if(xAxis.min > xAxis.max) {
783 if(yAxis.min > yAxis.max) {
787 if(zAxis.min > zAxis.max) {
791 if((Name ==
"Polar") || (Name ==
"Smith")) {
792 if(yAxis.min > zAxis.min) yAxis.min = zAxis.min;
793 if(yAxis.max < zAxis.max) yAxis.max = zAxis.max;
802 int valid = calcDiagram();
805 for(pg = Graphs.first(); pg != 0; pg = Graphs.next()) {
810 if((valid & (pg->
yAxisNo+1)) != 0)
822 for(pg = Graphs.first(); pg != 0; pg = Graphs.next())
832 QFileInfo Info(fileName);
834 int pos = g->
Var.find(
':');
841 setlocale (LC_NUMERIC,
"C");
844 file.setName(fileName);
848 file.setName(Info.dirPath()+QDir::separator() + g->
Var.left(pos)+
".dat");
849 Variable = g->
Var.mid(pos+1);
860 if(Variable.isEmpty())
return 0;
862 if(Variable.right(2) ==
".X")
863 if(Name.at(0) !=
'T')
867 if(!file.open(QIODevice::ReadOnly))
return 0;
872 QByteArray FileContent;
873 FileContent = file.readAll();
875 char *FileString = FileContent.data();
876 if(!FileString)
return 0;
877 char *pPos = FileString+FileContent.size()-1;
878 if(*pPos >
' ')
if(*pPos !=
'>')
return 0;
884 bool isIndep =
false;
885 Variable =
"dep "+Variable+
" ";
888 char *pFile = strstr(FileString, Variable.latin1());
890 if(*(pFile-1) ==
'<')
892 else if(strncmp(pFile-3,
"<in", 3) == 0) {
896 pFile = strstr(pFile+4, Variable.latin1());
902 pFile += Variable.length();
903 pPos = strchr(pFile,
'>');
906 Line = QString(pFile);
911 tmp = Line.section(
' ', pos, pos);
912 while(!tmp.isEmpty()) {
915 tmp = Line.section(
' ', pos, pos);
926 counting = Line.toInt(&ok);
930 p =
new double[counting];
933 for(
int z=1; z<=counting; z++) *(p++) = double(z);
934 if(xAxis.min > 1.0) xAxis.min = 1.0;
935 if(xAxis.max <
double(counting)) xAxis.max = double(counting);
941 if(Name ==
"Rect3D") bLast = g->
cPointsX.at(1);
943 double min_tmp = xAxis.min, max_tmp = xAxis.max;
950 else if(pD == bLast) pa = &yAxis;
951 counting = loadIndepVarData(pD->Var, FileString, pa, g);
952 if(counting <= 0)
return 0;
963 p =
new double[2*counting];
965 if(g->
yAxisNo == 0) pa = &yAxis;
973 if(Variable.right(3) !=
".X ")
975 for(
int z=counting; z>0; z--) {
977 while((*pPos) && (*pPos <=
' ')) pPos++;
978 x = strtod(pPos, &pEnd);
983 if(((*pEnd !=
'+') && (*pEnd !=
'-')) || (*pPos !=
'j')) {
989 y = strtod(pPos, &pEnd);
996 if(fabs(y) >= 1e-250) x = sqrt(x*x+y*y);
998 if(x > pa->
max) pa->
max = x;
999 if(x < pa->min) pa->
min = x;
1004 if(x > xAxis.max) xAxis.max = x;
1005 if(x < xAxis.min) xAxis.min = x;
1008 if(y > pa->
max) pa->
max = y;
1009 if(y < pa->min) pa->
min = y;
1017 char *pc = (
char*)p;
1018 pEnd = pc + 2*(counting-1)*
sizeof(
double);
1020 for(
int z=counting; z>0; z--) {
1022 while((*pPos) && (*pPos <=
' ')) pPos++;
1028 while(*pPos >
' ') {
1029 *(pc++) = *(pPos++);
1031 counting = pc - (
char*)g->
cPointsY;
1032 pc = (
char*)realloc(g->
cPointsY, counting+1024);
1036 pEnd += counting+1020;
1052 bool isIndep =
false;
1057 setlocale (LC_NUMERIC,
"C");
1059 Line =
"dep "+Variable+
" ";
1062 char *pFile = strstr(FileString, Line.latin1());
1064 if(*(pFile-1) ==
'<')
1066 else if(strncmp(pFile-3,
"<in", 3) == 0) {
1070 pFile = strstr(pFile+4, Line.latin1());
1073 if(!pFile)
return -1;
1075 pFile += Line.length();
1076 char *pPos = strchr(pFile,
'>');
1077 if(!pPos)
return -1;
1079 Line = QString(pFile);
1084 if(Line.find(
' ') >= 0)
return -1;
1085 Line =
"<indep "+Line+
" ";
1086 pPos = strstr(FileString, Line.latin1());
1087 if(!pPos)
return -1;
1088 pPos += Line.length();
1089 pEnd = strchr(pPos,
'>');
1090 if(!pEnd)
return -1;
1092 Line = QString(pPos);
1098 int n = Line.toInt(&ok);
1101 double *p =
new double[n];
1110 while((*pPos) && (*pPos <=
' ')) pPos++;
1112 for(
int z=0; z<n; z++) {
1114 x = strtod(pPos, &pEnd);
1123 if(x > pa->
max) pa->
max = x;
1124 if(x < pa->min) pa->
min = x;
1128 while((*pPos) && (*pPos <=
' ')) pPos++;
1138 if(g1 == g2)
return true;
1142 while(g1Data && g2Data) {
1143 if(g1Data->
Var != g2Data->
Var)
return false;
1148 if(g1Data)
return false;
1149 if(g2Data)
return false;
1155 const QFontMetrics& metrics,
int colWidth,
int x,
int y)
1158 int w = metrics.boundingRect(Str).width();
1161 if((x+colWidth) >= x2) {
1163 Lines.append(
new Line(x2-6, y-4, x2+7, y-4, QPen(Qt::red,2)));
1164 Lines.append(
new Line(x2, y-7, x2+6, y-4, QPen(Qt::red,2)));
1165 Lines.append(
new Line(x2, y-1, x2+6, y-4, QPen(Qt::red,2)));
1199 QString s =
"<"+Name+
" "+QString::number(cx)+
" "+QString::number(cy)+
" ";
1200 s += QString::number(x2)+
" "+QString::number(y2)+
" ";
1202 if(xAxis.GridOn) c |= 1;
1203 if(hideLines) c |= 2;
1205 s +=
" " + GridPen.color().name() +
" " + QString::number(GridPen.style());
1207 if(xAxis.log) s+=
" 1";
else s +=
" 0";
1209 if(yAxis.log) c |= 1;
1210 if(zAxis.log) c |= 2;
1213 if(xAxis.autoScale) s+=
" 1 ";
1215 s += QString::number(xAxis.limit_min) +
" ";
1216 s += QString::number(xAxis.step) +
" ";
1217 s += QString::number(xAxis.limit_max);
1218 if(yAxis.autoScale) s+=
" 1 ";
1220 s += QString::number(yAxis.limit_min) +
" ";
1221 s += QString::number(yAxis.step) +
" ";
1222 s += QString::number(yAxis.limit_max);
1223 if(zAxis.autoScale) s+=
" 1 ";
1225 s += QString::number(zAxis.limit_min) +
" ";
1226 s += QString::number(zAxis.step) +
" ";
1227 s += QString::number(zAxis.limit_max) +
" ";
1229 s += QString::number(rotX)+
" "+QString::number(rotY)+
" "+
1230 QString::number(rotZ);
1233 s +=
" \""+xAxis.Label+
"\" \""+yAxis.Label+
"\" \""+zAxis.Label+
"\">\n";
1235 for(
Graph *pg=Graphs.first(); pg != 0; pg=Graphs.next())
1236 s += pg->save()+
"\n";
1238 s +=
" </"+Name+
">";
1248 if(s.at(0) !=
'<')
return false;
1249 if(s.at(s.length()-1) !=
'>')
return false;
1250 s = s.mid(1, s.length()-2);
1253 n = s.section(
' ',1,1);
1255 if(!ok)
return false;
1257 n = s.section(
' ',2,2);
1259 if(!ok)
return false;
1261 n = s.section(
' ',3,3);
1263 if(!ok)
return false;
1265 n = s.section(
' ',4,4);
1267 if(!ok)
return false;
1270 n = s.section(
' ',5,5);
1271 c = n.at(0).latin1() -
'0';
1272 xAxis.GridOn = yAxis.GridOn = (c & 1) != 0;
1273 hideLines = (c & 2) != 0;
1275 n = s.section(
' ',6,6);
1277 co.setNamedColor(n);
1278 GridPen.setColor(co);
1279 if(!GridPen.color().isValid())
return false;
1281 n = s.section(
' ',7,7);
1282 GridPen.setStyle((Qt::PenStyle)n.toInt(&ok));
1283 if(!ok)
return false;
1285 n = s.section(
' ',8,8);
1286 xAxis.log = n.at(0) !=
'0';
1287 c = n.at(1).latin1();
1288 yAxis.log = ((c -
'0') & 1) == 1;
1289 zAxis.log = ((c -
'0') & 2) == 2;
1291 n = s.section(
' ',9,9);
1292 if(n.at(0) !=
'"') {
1293 if(n ==
"1") xAxis.autoScale =
true;
1294 else xAxis.autoScale =
false;
1296 n = s.section(
' ',10,10);
1297 xAxis.limit_min = n.toDouble(&ok);
1298 if(!ok)
return false;
1300 n = s.section(
' ',11,11);
1301 xAxis.step = n.toDouble(&ok);
1302 if(!ok)
return false;
1304 n = s.section(
' ',12,12);
1305 xAxis.limit_max = n.toDouble(&ok);
1306 if(!ok)
return false;
1308 n = s.section(
' ',13,13);
1309 if(n ==
"1") yAxis.autoScale =
true;
1310 else yAxis.autoScale =
false;
1312 n = s.section(
' ',14,14);
1313 yAxis.limit_min = n.toDouble(&ok);
1314 if(!ok)
return false;
1316 n = s.section(
' ',15,15);
1317 yAxis.step = n.toDouble(&ok);
1318 if(!ok)
return false;
1320 n = s.section(
' ',16,16);
1321 yAxis.limit_max = n.toDouble(&ok);
1322 if(!ok)
return false;
1324 n = s.section(
' ',17,17);
1325 if(n ==
"1") zAxis.autoScale =
true;
1326 else zAxis.autoScale =
false;
1328 n = s.section(
' ',18,18);
1329 zAxis.limit_min = n.toDouble(&ok);
1330 if(!ok)
return false;
1332 n = s.section(
' ',19,19);
1333 zAxis.step = n.toDouble(&ok);
1334 if(!ok)
return false;
1336 n = s.section(
' ',20,20);
1337 zAxis.limit_max = n.toDouble(&ok);
1338 if(!ok)
return false;
1340 n = s.section(
' ',21,21);
1341 if(n.at(0) !=
'"') {
1342 rotX = n.toInt(&ok);
1343 if(!ok)
return false;
1345 n = s.section(
' ',22,22);
1346 rotY = n.toInt(&ok);
1347 if(!ok)
return false;
1349 n = s.section(
' ',23,23);
1350 rotZ = n.toInt(&ok);
1351 if(!ok)
return false;
1355 xAxis.Label = s.section(
'"',1,1);
1356 yAxis.Label = s.section(
'"',3,3);
1357 zAxis.Label = s.section(
'"',5,5);
1362 while(!stream->atEnd()) {
1363 s = stream->readLine();
1364 s = s.stripWhiteSpace();
1365 if(s.isEmpty())
continue;
1367 if(s == (
"</"+Name+
">"))
return true;
1368 if(s.section(
' ', 0,0) ==
"<Mkr") {
1372 pg = Graphs.current();
1373 if(!pg)
return false;
1397 xAxis.low = xAxis.min;
1398 xAxis.up = xAxis.max;
1401 if(fabs(Axis->
min) > Axis->
max)
1402 Axis->
max = fabs(Axis->
min);
1404 if(Axis->
max > 1.01) Axis->
up = 1.05*Axis->
max;
1405 else Axis->
up = 1.0;
1410 GridX = GridY = int(Axis->
step);
1419 calcSmithAxisScale(Axis, GridX, GridY);
1422 if(!xAxis.GridOn)
return;
1424 bool Zplane = ((Mode & 1) == 1);
1425 bool Above = ((Mode & 2) == 2);
1426 bool Below = ((Mode & 4) == 4);
1430 double im, n_cos, n_sin, real, real1, real2, root;
1431 double rMAXq = Axis->
up*Axis->
up;
1432 int theta, beta, phi, len, m, x, y;
1434 int R1 = int(x2/Axis->
up + 0.5);
1437 for(m=1; m<GridY; m++) {
1438 n_sin =
M_PI*double(m)/double(GridY);
1441 im = (1.0-n_cos)/n_sin * pow(Axis->
up,0.7);
1442 y = int(im/Axis->
up*x2 + 0.5);
1444 if(Axis->
up <= 1.0) {
1445 beta = int(16.0*180.0*atan2(n_sin-im,n_cos-1.0)/
M_PI - 0.5);
1446 if(beta<0) beta += 16*360;
1447 theta = 16*270-beta;
1451 real = (rMAXq+1.0)/(rMAXq-1.0);
1452 root = real*real - im*im - 1.0;
1459 real1 = sqrt(root)-real;
1460 real2 = -sqrt(root)-real;
1462 root = (real1+1.0)*(real1+1.0) + im*im;
1463 n_cos = (real1*real1 + im*im - 1.0) / root;
1464 n_sin = 2.0*im / root;
1465 beta = int(16.0*180.0*atan2(n_sin-1.0/im,n_cos-1.0)/
M_PI);
1466 if(beta<0) beta += 16*360;
1468 root = (real2+1.0)*(real2+1.0) + im*im;
1469 n_cos = (real2*real2 + im*im - 1.0) / root;
1470 n_sin = 2.0*im / root;
1471 theta = int(16.0*180.0*atan2(n_sin-1/im,n_cos-1)/
M_PI);
1472 if(theta<0) theta += 16*360;
1473 theta = theta - beta;
1474 if(theta < 0) theta = 16*360+theta;
1479 x = (x2 + R1 - y) >> 1;
1481 x = (x2 - R1 - y) >> 1;
1482 beta = 16*180 - beta - theta;
1483 if(beta < 0) beta += 16*360;
1487 Arcs.append(
new struct Arc(x, dx2+y, y, y, beta, theta, GridPen));
1489 Arcs.append(
new struct Arc(x, dx2, y, y, 16*360-beta-theta, theta, GridPen));
1496 if(Above) { beta = 0; theta = 16*180; }
1497 if(Below) theta += 16*180;
1499 for(m=1; m<GridX; m++) {
1500 im = m*(Axis->
up+1.0)/GridX - Axis->
up;
1501 y = int((1.0-im)/Axis->
up*
double(dx2) + 0.5);
1504 x = ((x2+R1)>>1) - y;
1507 if(fabs(fabs(im)-1.0) > 0.2)
1508 Arcs.append(
new struct Arc(x, (x2+y)>>1, y, y, beta, theta, GridPen));
1510 if(Axis->
up > 1.0) {
1512 im = (rMAXq-1.0)/(im*(im/2.0+1.0)) - 1.0;
1516 Arcs.append(
new struct Arc(x, (x2+y)>>1, y, y, beta, theta, GridPen));
1518 phi = int(16.0*180.0/
M_PI*acos(im));
1520 if(Above && Below) len += len;
1521 else if(Below) phi = 16*180;
1522 if(!Zplane) phi += 16*180;
1523 Arcs.append(
new struct Arc(x, (x2+y)>>1, y, y, phi, len, GridPen));
1530 if(Axis->
up > 1.0) {
1533 Arcs.append(
new struct Arc(x, y, R1, R1, beta, theta, QPen(Qt::black,0)));
1537 y = int(sqrt(rMAXq-1)/Axis->
up*dx2 + 0.5);
1541 Lines.append(
new Line(x, dx2+m, x, dx2-y, GridPen));
1553 double& GridStep,
double& zD)
1557 numGrids = floor(
double(x2)/80.0);
1558 Expo = floor(log10(Axis->
max/numGrids));
1559 Base = Axis->
max/numGrids/pow(10.0,Expo);
1561 if(Base < 1.5) Base = 1.0;
1565 if(Base < 7.5) Base = 5.0;
1566 else { Base = 1.0; Expo++; }
1568 GridStep = Base * pow(10.0,Expo);
1569 numGrids -= floor(numGrids - Axis->
max/GridStep);
1570 Axis->
up = GridStep*numGrids;
1572 zD = double(x2) / numGrids;
1576 GridStep = Axis->
step;
1579 if(fabs(zD) < 2.0) {
1581 GridStep = Axis->
step = Axis->
up;
1591 xAxis.low = xAxis.min;
1592 xAxis.up = xAxis.max;
1594 if(fabs(Axis->
min) > Axis->
max)
1595 Axis->
max = fabs(Axis->
min);
1598 bool Above = ((Mode & 1) == 1);
1599 bool Below = ((Mode & 2) == 2);
1602 if(Above) i = y2;
else i = y2>>1;
1603 if(Below) z = 0;
else z = y2>>1;
1605 Lines.append(
new Line(x2>>1, i, x2>>1, z, GridPen));
1609 if(Above) { beta = 0; len = 16*180; }
1610 if(Below) len += 16*180;
1614 if(!Below) tPos = (y2>>1) + 3;
1615 else tPos = (y2>>1) - tHeight + 3;
1617 double Expo, Base, numGrids, GridStep, zD;
1619 calcPolarAxisScale(Axis, numGrids, GridStep, zD);
1622 double GridNum = 0.0;
1623 for(i=
int(numGrids); i>1; i--) {
1625 GridNum += GridStep;
1628 phi = int(16.0*180.0/
M_PI*atan(
double(2*tHeight)/zD));
1629 if(!Below) tmp = beta + phi;
1631 Arcs.append(
new struct Arc((x2-z)>>1, (y2+z)>>1, z, z, tmp, len-phi,
1637 Expo = floor(log10(Axis->
max));
1638 Base = ceil(Axis->
max/pow(10.0,Expo) - 0.01);
1639 Axis->
up = Base * pow(10.0,Expo);
1644 phi = int(16.0*180.0/
M_PI*atan(
double(2*tHeight)/
double(x2)));
1645 if(!Below) tmp = phi;
1647 Arcs.append(
new struct Arc(0, y2, x2, y2, tmp, 16*360-phi, QPen(Qt::black,0)));
1650 QSize r = metrics.size(0, Texts.current()->s);
1651 len = x2+r.width()-4;
1652 if(len > x3) x3 = len;
1666 double& zDstep,
double& GridStep,
double Dist)
1669 double numGrids, Base, Expo, corr;
1672 if(fabs(Axis->
max-Axis->
min) < 1e-200) {
1673 if((Axis->
max == 0.0) && (Axis->
min == 0.0)) {
1678 Axis->
up = Axis->
max + fabs(Axis->
max);
1679 Axis->
low = Axis->
min - fabs(Axis->
min);
1682 else if(Axis != &xAxis) {
1688 Axis->
up = Axis->
max;
1693 numGrids = floor(Dist/60.0);
1694 if(numGrids < 1.0) Base = Axis->
up-Axis->
low;
1695 else Base = (Axis->
up-Axis->
low)/numGrids;
1696 Expo = floor(log10(Base));
1697 Base = Base/pow(10.0,Expo);
1699 if(Base < 1.5) Base = 1.0;
1703 if(Base < 7.5) Base = 5.0;
1704 else { Base = 1.0; Expo++; }
1706 GridStep = Base * pow(10.0,Expo);
1707 corr = floor((Axis->
up-Axis->
low)/GridStep - numGrids);
1708 if(corr < 0.0) corr++;
1713 zD = fabs(fmod(Axis->
up, GridStep));
1714 GridNum = zD/GridStep;
1715 if((1.0-GridNum) < 1e-10) GridNum = 0.0;
1716 if(Axis->
up <= 0.0) {
1717 if(GridNum < 0.3) { Axis->
up += zD; zD = 0.0; }
1719 else if(GridNum > 0.7) Axis->
up += GridStep-zD;
1720 else if(GridNum < 0.1)
1721 if(GridNum*Dist >= 1.0)
1722 Axis->
up += 0.3*GridStep;
1726 zD = fabs(fmod(Axis->
low, GridStep));
1727 GridNum = zD/GridStep;
1728 if((1.0-GridNum) < 1e-10) zD = GridNum = 0.0;
1729 if(Axis->
low <= 0.0) {
1730 if(GridNum > 0.7) { Axis->
low -= GridStep-zD; zD = 0.0; }
1731 else if(GridNum < 0.1)
1732 if(GridNum*Dist >= 1.0) {
1733 Axis->
low -= 0.3*GridStep;
1741 if((1.0-GridNum)*Dist >= 1.0) {
1742 Axis->
low -= 0.3*GridStep;
1747 else { Axis->
low -= zD; zD = 0.0; }
1750 GridNum = Axis->
low + zD;
1751 zD /= (Axis->
up-Axis->
low)/Dist;
1759 GridStep = Axis->
step;
1762 zDstep = GridStep/(Axis->
up-Axis->
low)*Dist;
1764 if(fabs(zDstep) < 2.0) {
1766 GridStep = Axis->
step = Axis->
up-Axis->
low;
1784 double& zDstep,
double& corr,
int len)
1786 if(fabs(Axis->
max-Axis->
min) < 1e-200) {
1798 bool mirror=
false, mirror2=
false;
1800 if(Axis->
up < 0.0) {
1802 Axis->
low = -Axis->
up;
1815 Expo = floor(log10(Axis->
max));
1816 Base = Axis->
max/pow(10.0,Expo);
1817 if(Base > 3.0001) Axis->
up = pow(10.0,Expo+1.0);
1818 else if(Base < 1.0001) Axis->
up = pow(10.0,Expo);
1819 else Axis->
up = 3.0 * pow(10.0,Expo);
1821 Expo = floor(log10(Axis->
min));
1822 Base = Axis->
min/pow(10.0,Expo);
1823 if(Base < 2.999) Axis->
low = pow(10.0,Expo);
1824 else if(Base > 9.999) Axis->
low = pow(10.0,Expo+1.0);
1825 else Axis->
low = 3.0 * pow(10.0,Expo);
1827 corr = double(len) / log10(Axis->
up / Axis->
low);
1831 zDstep = pow(10.0,Expo);
1840 if(Axis->
up < Axis->
low) {
1842 Axis->
low = Axis->
up;
1847 Expo = floor(log10(Axis->
low));
1848 Base = ceil(Axis->
low/pow(10.0,Expo));
1849 zD = Base * pow(10.0, Expo);
1850 zDstep = pow(10.0,Expo);
1851 if(zD > 9.5*zDstep) zDstep *= 10.0;
1853 corr = double(len) / log10(Axis->
up / Axis->
low);
1854 z = int(corr*log10(zD / Axis->
low) + 0.5);
1858 Axis->
low = Axis->
up;
1865 Axis->
low = -Axis->
up;
1869 if(mirror == mirror2)
return false;
1877 double GridStep, corr, zD, zDstep, GridNum;
1886 if(Axis->
max*Axis->
min <= 0.0)
return false;
1890 back = calcAxisLogScale(Axis, z, zD, zDstep, corr, y2);
1893 while((z <= y2) && (z >= 0)) {
1894 if(Axis->
GridOn)
if(z < y2)
if(z > 0)
1895 Lines.prepend(
new Line(0, z, x2, z, GridPen));
1897 if((zD < 1.5*zDstep) || (z == 0)) {
1899 if(Axis->
up < 0.0) tmp =
'-'+tmp;
1901 w = metrics.width(tmp);
1902 if(maxWidth < w) maxWidth = w;
1904 Texts.append(
new Text(x0+7, z-6, tmp));
1906 Texts.append(
new Text(-w-7, z-6, tmp));
1909 Lines.append(
new Line(x0-5, z, x0+5, z, QPen(Qt::black,0)));
1913 if(zD > 9.5*zDstep) zDstep *= 10.0;
1915 z = int(corr*log10(zD / fabs(Axis->
up)) + 0.5);
1919 z = int(corr*log10(zD / fabs(Axis->
low)) + 0.5);
1923 back = calcAxisScale(Axis, GridNum, zD, zDstep, GridStep,
double(y2));
1926 if(Axis->
up == 0.0) Expo = log10(fabs(Axis->
up-Axis->
low));
1927 else Expo = log10(fabs(Axis->
up));
1931 while((z <= y2) && (z >= 0)) {
1932 if(fabs(GridNum) < 0.01*pow(10.0, Expo)) GridNum = 0.0;
1935 w = metrics.width(tmp);
1936 if(maxWidth < w) maxWidth = w;
1938 Texts.append(
new Text(x0+8, z-6, tmp));
1940 Texts.append(
new Text(-w-7, z-6, tmp));
1941 GridNum += GridStep;
1943 if(Axis->
GridOn)
if(z < y2)
if(z > 0)
1944 Lines.prepend(
new Line(0, z, x2, z, GridPen));
1945 Lines.append(
new Line(x0-5, z, x0+5, z, QPen(Qt::black,0)));
1950 if(x0 == 0) x1 = maxWidth+14;
1951 else x3 = x2+maxWidth+14;
Diagram(int _cx=0, int _cy=0)
virtual bool insideDiagram(float, float)
Q3PtrList< Marker > Markers
void getCenter(int &, int &)
void drawResizeRect(int, int)
int regionCode(float, float)
bool load(const QString &, QTextStream *)
virtual void createAxisLabels()
void PostPaintEvent(PE pe, int x1=0, int y1=0, int x2=0, int y2=0, int a=0, int b=0, bool PaintOnViewport=false)
#define GRAPHSTYLE_LONGDASH
void map(int, int, int &, int &)
tQucsSettings QucsSettings
bool sameDependencies(Graph *, Graph *)
void drawLine(int, int, int, int)
QString StringNum(double num, char form, int Precision)
bool load(const QString &)
void setCenter(int, int, bool relative=false)
Definitions and declarations for the main application.
QString StringNiceNum(double num)
void getAxisLimits(Graph *)
virtual void clip(float *&)
void encode_String(const QString &Input, QString &Output)
bool getSelected(int, int)
void createSmithChart(Axis *, int Mode=7)
void createPolarDiagram(Axis *, int Mode=3)
int loadVarData(const QString &, Graph *)
void Bounding(int &, int &, int &, int &)
void drawArc(int, int, int, int, int, int)
int checkColumnWidth(const QString &, const QFontMetrics &, int, int, int)
bool calcAxisLogScale(Axis *, int &, double &, double &, double &, int)
virtual void paint(ViewPainter *)
virtual void calcData(Graph *)
bool calcAxisScale(Axis *, double &, double &, double &, double &, double)
void paint(ViewPainter *, int, int)
virtual Diagram * newOne()
void loadGraphData(const QString &)
void calcSmithAxisScale(Axis *, int &, int &)
Q3PtrList< DataX > cPointsX
int loadIndepVarData(const QString &, char *, Axis *, Graph *)
void calcPolarAxisScale(Axis *, double &, double &, double &)
bool calcYAxis(Axis *, int)
void paintScheme(Schematic *)
bool resizeTouched(float, float, float)
bool load(const QString &Line)