~showard314/ubuntu/natty/qtiplot/Python2.7_fix

« back to all changes in this revision

Viewing changes to qtiplot/src/importOPJ.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gudjon I. Gudjonsson
  • Date: 2007-03-25 12:06:27 UTC
  • Revision ID: james.westby@ubuntu.com-20070325120627-5pvdufddr7i0r74x
Tags: upstream-0.9~rc2
ImportĀ upstreamĀ versionĀ 0.9~rc2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : importOPJ.cpp
 
3
    Project              : QtiPlot
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006-2007 by Ion Vasilief, Alex Kargovsky, Tilman Hoener zu Siederdissen
 
6
    Email (use @ for *)  : ion_vasilief*yahoo.fr, kargovsky*yumr.phys.msu.su, thzs*gmx.net
 
7
    Description          : Origin project import class
 
8
 
 
9
 ***************************************************************************/
 
10
 
 
11
/***************************************************************************
 
12
 *                                                                         *
 
13
 *  This program is free software; you can redistribute it and/or modify   *
 
14
 *  it under the terms of the GNU General Public License as published by   *
 
15
 *  the Free Software Foundation; either version 2 of the License, or      *
 
16
 *  (at your option) any later version.                                    *
 
17
 *                                                                         *
 
18
 *  This program is distributed in the hope that it will be useful,        *
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 
21
 *  GNU General Public License for more details.                           *
 
22
 *                                                                         *
 
23
 *   You should have received a copy of the GNU General Public License     *
 
24
 *   along with this program; if not, write to the Free Software           *
 
25
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
 
26
 *   Boston, MA  02110-1301  USA                                           *
 
27
 *                                                                         *
 
28
 ***************************************************************************/
 
29
#include "importOPJ.h"
 
30
#include <OPJFile.h>
 
31
 
 
32
#include <QRegExp>
 
33
#include <QMessageBox>
 
34
#include <QDockWidget>
 
35
#include "Matrix.h"
 
36
#include "ColorBox.h"
 
37
#include "MultiLayer.h"
 
38
#include "Note.h"
 
39
#include "QwtHistogram.h"
 
40
 
 
41
#define OBJECTXOFFSET 200
 
42
 
 
43
QString strreverse(const QString &str) //QString reversing
 
44
{
 
45
        QString out="";
 
46
        for(int i=str.length()-1; i>=0; --i)
 
47
        {
 
48
                out+=str[i];
 
49
        }
 
50
        return out;
 
51
}
 
52
 
 
53
ImportOPJ::ImportOPJ(ApplicationWindow *app, const QString& filename) :
 
54
                mw(app)
 
55
{
 
56
        xoffset=0;
 
57
        OPJFile opj((const char *)filename.latin1());
 
58
        parse_error = opj.Parse();
 
59
        importTables(opj);
 
60
        importGraphs(opj);
 
61
        importNotes(opj);
 
62
        mw->showResults(opj.resultsLogString(),mw->logWindow->isVisible());
 
63
}
 
64
 
 
65
int ImportOPJ::translateOrigin2QtiplotLineStyle(int linestyle) {
 
66
        int qtiplotstyle=0;
 
67
        switch (linestyle)
 
68
        {
 
69
                case OPJFile::Solid:
 
70
                        qtiplotstyle=0;
 
71
                        break;
 
72
                case OPJFile::Dash:
 
73
                case OPJFile::ShortDash:
 
74
                        qtiplotstyle=1;
 
75
                        break;
 
76
                case OPJFile::Dot:
 
77
                case OPJFile::ShortDot:
 
78
                        qtiplotstyle=2;
 
79
                        break;
 
80
                case OPJFile::DashDot:
 
81
                case OPJFile::ShortDashDot:
 
82
                        qtiplotstyle=3;
 
83
                        break;
 
84
                case OPJFile::DashDotDot:
 
85
                        qtiplotstyle=4;
 
86
                        break;
 
87
        }
 
88
        return qtiplotstyle;
 
89
}
 
90
 
 
91
bool ImportOPJ::importTables(OPJFile opj)
 
92
{
 
93
        int visible_count=0;
 
94
        int QtiPlot_scaling_factor=10; //in Origin width is measured in characters while in QtiPlot - pixels --- need to be accurate
 
95
        for (int s=0; s<opj.numSpreads(); s++)
 
96
        {
 
97
                int nr_cols = opj.numCols(s);
 
98
                int maxrows = opj.maxRows(s);
 
99
 
 
100
                Table *table = (opj.spreadHidden(s)||opj.spreadLoose(s))&&opj.Version()==7.5 ? mw->newHiddenTable(opj.spreadName(s), opj.spreadLabel(s), maxrows, nr_cols)
 
101
                                                                                : mw->newTable(opj.spreadName(s), maxrows, nr_cols);
 
102
                if (!table)
 
103
                        return false;
 
104
 
 
105
                table->setWindowLabel(opj.spreadLabel(s));
 
106
                for (int j=0; j<nr_cols; j++)
 
107
                {
 
108
                        QString name(opj.colName(s,j));
 
109
                        table->setColName(j, name.replace(QRegExp(".*_"),""));
 
110
                        table->setCommand(j, QString(opj.colCommand(s,j)));
 
111
                        table->setColComment(j, QString(opj.colComment(s,j)));
 
112
                        table->changeColWidth(opj.colWidth(s,j)*QtiPlot_scaling_factor, j);
 
113
 
 
114
                        if (QString(opj.colType(s,j)) == "X")
 
115
                                table->setColPlotDesignation(j, Table::X);
 
116
                        else if (QString(opj.colType(s,j)) == "Y")
 
117
                                table->setColPlotDesignation(j, Table::Y);
 
118
                        else if (QString(opj.colType(s,j)) == "Z")
 
119
                                table->setColPlotDesignation(j, Table::Z);
 
120
                        else if (QString(opj.colType(s,j)) == "DX")
 
121
                                table->setColPlotDesignation(j, Table::xErr);
 
122
                        else if (QString(opj.colType(s,j)) == "DY")
 
123
                                table->setColPlotDesignation(j, Table::yErr);
 
124
                        else
 
125
                                table->setColPlotDesignation(j, Table::None);
 
126
 
 
127
            table->setHeaderColType();//update header
 
128
 
 
129
                        QString format;
 
130
                        switch(opj.colValueType(s,j))
 
131
                        {
 
132
                        case 0: //Numeric
 
133
                        case 6: //Text&Numeric
 
134
                                int f;
 
135
                                if(opj.colNumDisplayType(s,j)==0)
 
136
                                        f=0;
 
137
                                else
 
138
                                        switch(opj.colValueTypeSpec(s,j))
 
139
                                        {
 
140
                                        case 0: //Decimal 1000
 
141
                                                f=1;
 
142
                                                break;
 
143
                                        case 1: //Scientific
 
144
                                                f=2;
 
145
                                                break;
 
146
                                        case 2: //Engeneering
 
147
                                        case 3: //Decimal 1,000
 
148
                                                f=0;
 
149
                                                break;
 
150
                                        }
 
151
                                table->setColNumericFormat(f, opj.colDecPlaces(s,j), j);
 
152
                                break;
 
153
                        case 1: //Text
 
154
                                table->setTextFormat(j);
 
155
                                break;
 
156
                        case 2: // Date
 
157
                                switch(opj.colValueTypeSpec(s,j))
 
158
                                {
 
159
                                case 0:
 
160
                                case 9:
 
161
                                case 10:
 
162
                                        format="dd.MM.yyyy";
 
163
                                        break;
 
164
                                case 2:
 
165
                                        format="MMM d";
 
166
                                        break;
 
167
                                case 3:
 
168
                                        format="M/d";
 
169
                                        break;
 
170
                                case 4:
 
171
                                        format="d";
 
172
                                        break;
 
173
                                case 5:
 
174
                                case 6:
 
175
                                        format="ddd";
 
176
                                        break;
 
177
                                case 7:
 
178
                                        format="yyyy";
 
179
                                        break;
 
180
                                case 8:
 
181
                                        format="yy";
 
182
                                        break;
 
183
                                case 11:
 
184
                                case 12:
 
185
                                case 13:
 
186
                                case 14:
 
187
                                case 15:
 
188
                                        format="yyMMdd";
 
189
                                        break;
 
190
                                case 16:
 
191
                                case 17:
 
192
                                        format="MMM";
 
193
                                        break;
 
194
                                case 19:
 
195
                                        format="M-d-yyyy";
 
196
                                        break;
 
197
                                default:
 
198
                                        format="dd.MM.yyyy";
 
199
                                }
 
200
                                table->setDateFormat(format, j);
 
201
                                break;
 
202
                        case 3: // Time
 
203
                                switch(opj.colValueTypeSpec(s,j))
 
204
                                {
 
205
                                case 0:
 
206
                                        format="hh:mm";
 
207
                                        break;
 
208
                                case 1:
 
209
                                        format="hh";
 
210
                                        break;
 
211
                                case 2:
 
212
                                        format="hh:mm:ss";
 
213
                                        break;
 
214
                                case 3:
 
215
                                        format="hh:mm:ss.zzz";
 
216
                                        break;
 
217
                                case 4:
 
218
                                        format="hh ap";
 
219
                                        break;
 
220
                                case 5:
 
221
                                        format="hh:mm ap";
 
222
                                        break;
 
223
                                case 6:
 
224
                                        format="mm:ss";
 
225
                                        break;
 
226
                                case 7:
 
227
                                        format="mm:ss.zzz";
 
228
                                        break;
 
229
                                case 8:
 
230
                                        format="hhmm";
 
231
                                        break;
 
232
                                case 9:
 
233
                                        format="hhmmss";
 
234
                                        break;
 
235
                                case 10:
 
236
                                        format="hh:mm:ss.zzz";
 
237
                                        break;
 
238
                                }
 
239
                                table->setTimeFormat(format, j);
 
240
                                break;
 
241
                        case 4: // Month
 
242
                                switch(opj.colValueTypeSpec(s,j))
 
243
                                {
 
244
                                case 0:
 
245
                                case 2:
 
246
                                        format="shortMonthName";
 
247
                                        break;
 
248
                                case 1:
 
249
                                        format="longMonthName";
 
250
                                        break;
 
251
                                }
 
252
                                table->setMonthFormat(format, j);
 
253
                                break;
 
254
                        case 5: // Day
 
255
                                switch(opj.colValueTypeSpec(s,j))
 
256
                                {
 
257
                                case 0:
 
258
                                case 2:
 
259
                                        format="shortDayName";
 
260
                                        break;
 
261
                                case 1:
 
262
                                        format="longDayName";
 
263
                                        break;
 
264
                                }
 
265
                                table->setDayFormat(format, j);
 
266
                                break;
 
267
                        }
 
268
 
 
269
                        for (int i=0; i<opj.numRows(s,j); i++)
 
270
                        {
 
271
                                if(strcmp(opj.colType(s,j),"LABEL")&&opj.colValueType(s,j)!=1)
 
272
                                {// number
 
273
                                        double* val = (double*)opj.oData(s,j,i,true);
 
274
                                        if(fabs(*val)>0 && fabs(*val)<2.0e-300)// empty entry
 
275
                                                continue;
 
276
 
 
277
                                        table->setText(i, j, QString::number(*val));
 
278
                                }
 
279
                                else// label? doesn't seem to work
 
280
                                        table->setText(i, j, QString((char*)opj.oData(s,j,i)));
 
281
                        }
 
282
                }
 
283
 
 
284
 
 
285
                if(!(opj.spreadHidden(s)||opj.spreadLoose(s))||opj.Version()!=7.5)
 
286
                {
 
287
                        table->showNormal();
 
288
 
 
289
                        //cascade the tables
 
290
                        int dx=table->verticalHeaderWidth();
 
291
                        int dy=table->parentWidget()->frameGeometry().height() - table->height();
 
292
                        table->parentWidget()->move(QPoint(visible_count*dx+xoffset*OBJECTXOFFSET,visible_count*dy));
 
293
                        visible_count++;
 
294
                }
 
295
        }
 
296
 
 
297
//Import matrices
 
298
        for (int s=0; s<opj.numMatrices(); s++)
 
299
        {
 
300
                int nr_cols = opj.numMartixCols(s);
 
301
                int nr_rows = opj.numMartixRows(s);
 
302
 
 
303
                Matrix* matrix = mw->newMatrix(opj.matrixName(s), nr_rows, nr_cols);
 
304
                if (!matrix)
 
305
                        return false;
 
306
 
 
307
                matrix->setWindowLabel(opj.matrixLabel(s));
 
308
                matrix->setFormula(opj.matrixFormula(s));
 
309
                matrix->setColumnsWidth(opj.matrixWidth(s)*QtiPlot_scaling_factor);
 
310
                for (int j=0; j<nr_cols; j++)
 
311
                {
 
312
                        for (int i=0; i<nr_rows; i++)
 
313
                        {
 
314
                                double val = opj.matrixData(s,j,i);
 
315
                                if(fabs(val)>0 && fabs(val)<2.0e-300)// empty entry
 
316
                                        continue;
 
317
 
 
318
                                matrix->setCell(i, j, val);
 
319
                        }
 
320
                }
 
321
 
 
322
                matrix->saveCellsToMemory();
 
323
 
 
324
                QChar f;
 
325
                switch(opj.matrixValueTypeSpec(s))
 
326
                {
 
327
                case 0: //Decimal 1000
 
328
                        f='f';
 
329
                        break;
 
330
                case 1: //Scientific
 
331
                        f='e';
 
332
                        break;
 
333
                case 2: //Engeneering
 
334
                case 3: //Decimal 1,000
 
335
                        f='g';
 
336
                        break;
 
337
                }
 
338
                matrix->setNumericFormat(f, opj.matrixSignificantDigits(s));
 
339
 
 
340
                matrix->showNormal();
 
341
 
 
342
                //cascade the matrices
 
343
                int dx=matrix->verticalHeaderWidth();
 
344
                int dy=matrix->parentWidget()->frameGeometry().height() - matrix->height();
 
345
                matrix->parentWidget()->move(QPoint(visible_count*dx+xoffset*OBJECTXOFFSET,visible_count*dy));
 
346
                visible_count++;
 
347
 
 
348
        }
 
349
        
 
350
        if(visible_count>0)
 
351
                xoffset++;
 
352
        return true;
 
353
}
 
354
 
 
355
bool ImportOPJ::importNotes(OPJFile opj)
 
356
{
 
357
        int visible_count=0;
 
358
        for (int n=0; n<opj.numNotes(); n++)
 
359
        {
 
360
                QString name=opj.noteName(n);
 
361
                QRegExp rx("^@(\\S+)$");
 
362
                if(rx.indexIn(name)==0)
 
363
                {
 
364
                        name=name.mid(2,name.length()-3);
 
365
                }
 
366
                Note *note = mw->newNote(name);
 
367
                if(!note)
 
368
                        return false;
 
369
                note->setWindowLabel(opj.noteLabel(n));
 
370
                note->setText(opj.noteText(n));
 
371
 
 
372
                //cascade the notes
 
373
                int dx=20;
 
374
                int dy=note->parentWidget()->frameGeometry().height() - note->height();
 
375
                note->parentWidget()->move(QPoint(visible_count*dx+xoffset*OBJECTXOFFSET,visible_count*dy));
 
376
                visible_count++;
 
377
        }
 
378
        if(visible_count>0)
 
379
                xoffset++;
 
380
        return true;
 
381
}
 
382
 
 
383
bool ImportOPJ::importGraphs(OPJFile opj)
 
384
{
 
385
        double pi=3.141592653589793;
 
386
        int visible_count=0;
 
387
        int tickTypeMap[]={0,3,1,2};
 
388
        for (int g=0; g<opj.numGraphs(); g++)
 
389
        {
 
390
                MultiLayer *ml = mw->multilayerPlot(opj.graphName(g));
 
391
                if (!ml)
 
392
                        return false;
 
393
                
 
394
                ml->hide();//!hack used in order to avoid resize and repaint events
 
395
                ml->setWindowLabel(opj.graphLabel(g));
 
396
                for(int l=0; l<opj.numLayers(g); l++)
 
397
                {
 
398
                        Graph *graph=ml->addLayer();
 
399
                        if(!graph)
 
400
                                return false;
 
401
                        
 
402
                        graph->setXAxisTitle(parseOriginText(QString::fromLocal8Bit(opj.layerXAxisTitle(g,l))));
 
403
                        graph->setYAxisTitle(parseOriginText(QString::fromLocal8Bit(opj.layerYAxisTitle(g,l))));
 
404
                        if(strlen(opj.layerLegend(g,l))>0)
 
405
                                graph->newLegend(parseOriginText(QString::fromLocal8Bit(opj.layerLegend(g,l))));
 
406
                        int auto_color=0;
 
407
                        int auto_color1=0;
 
408
                        int style=0;
 
409
                        for(int c=0; c<opj.numCurves(g,l); c++)
 
410
                        {
 
411
                                QString data(opj.curveDataName(g,l,c));
 
412
                                int color=0;
 
413
                                switch(opj.curveType(g,l,c))
 
414
                                {
 
415
                                case OPJFile::Line:
 
416
                                        style=Graph::Line;
 
417
                                        break;
 
418
                                case OPJFile::Scatter:
 
419
                                        style=Graph::Scatter;
 
420
                                        break;
 
421
                                case OPJFile::LineSymbol:
 
422
                                        style=Graph::LineSymbols;
 
423
                                        break;
 
424
                                case OPJFile::ErrorBar:
 
425
                                case OPJFile::XErrorBar:
 
426
                                        style=Graph::ErrorBars;
 
427
                                        break;
 
428
                                case OPJFile::Column:
 
429
                                        style=Graph::VerticalBars;
 
430
                                        break;
 
431
                                case OPJFile::Bar:
 
432
                                        style=Graph::HorizontalBars;
 
433
                                        break;
 
434
                                case OPJFile::Histogram:
 
435
                                        style=Graph::Histogram;
 
436
                                        break;
 
437
                                default:
 
438
                                        continue;
 
439
                                }
 
440
                                QString tableName;
 
441
                                switch(data[0].toAscii())
 
442
                                {
 
443
                                case 'T':
 
444
                                        tableName = data.right(data.length()-2);
 
445
                                        if(style==Graph::ErrorBars)
 
446
                                        {
 
447
                                                int flags=opj.curveSymbolType(g,l,c);
 
448
                                                graph->addErrorBars(tableName + "_" + opj.curveXColName(g,l,c), mw->table(tableName), tableName + "_" + opj.curveYColName(g,l,c),
 
449
                                                        ((flags&0x10)==0x10?0:1), ceil(opj.curveLineWidth(g,l,c)), ceil(opj.curveSymbolSize(g,l,c)), QColor(Qt::black),
 
450
                                                        (flags&0x40)==0x40, (flags&2)==2, (flags&1)==1);
 
451
                                        }
 
452
                                        else if(style==Graph::Histogram)
 
453
                                                graph->insertCurve(mw->table(tableName), tableName + "_" + opj.curveYColName(g,l,c), style);
 
454
                                        else
 
455
                                                graph->insertCurve(mw->table(tableName), tableName + "_" + opj.curveXColName(g,l,c), tableName + "_" + opj.curveYColName(g,l,c), style);
 
456
                                        break;
 
457
                                case 'F':
 
458
                                        QStringList formulas;
 
459
                                        QList<double> ranges;
 
460
                                        int s=opj.functionIndex(data.right(data.length()-2).toStdString().c_str());
 
461
                                        int type;
 
462
                                        if(opj.functionType(s)==1)//Polar
 
463
                                        {
 
464
                                                type=2;
 
465
                                                formulas << opj.functionFormula(s) << "x";
 
466
                                                ranges << pi/180*opj.functionBegin(s) << pi/180*opj.functionEnd(s);
 
467
                                        }
 
468
                                        else
 
469
                                        {
 
470
                                                type=0;
 
471
                                                formulas << opj.functionFormula(s);
 
472
                                                ranges << opj.functionBegin(s) << opj.functionEnd(s);
 
473
                                        }
 
474
                                        graph->addFunctionCurve(type, formulas, "x", ranges, opj.functionPoints(s), opj.functionName(s));
 
475
 
 
476
                                        mw->updateFunctionLists(type, formulas);
 
477
                                        break;
 
478
                                }
 
479
                                
 
480
                                CurveLayout cl = graph->initCurveLayout(style, opj.numCurves(g,l));
 
481
                                cl.sSize = ceil(opj.curveSymbolSize(g,l,c));
 
482
                                cl.penWidth=opj.curveSymbolThickness(g,l,c);
 
483
                                color=opj.curveSymbolColor(g,l,c);
 
484
                                if((style==Graph::Scatter||style==Graph::LineSymbols)&&color==0xF7)//0xF7 -Automatic color
 
485
                                        color=auto_color++;
 
486
                                cl.symCol=color;
 
487
                                switch(opj.curveSymbolType(g,l,c)&0xFF)
 
488
                                {
 
489
                                case 0: //NoSymbol
 
490
                                        cl.sType=0;
 
491
                                        break;
 
492
                                case 1: //Rect
 
493
                                        cl.sType=2;
 
494
                                        break;
 
495
                                case 2: //Ellipse
 
496
                                case 20://Sphere
 
497
                                        cl.sType=1;
 
498
                                        break;
 
499
                                case 3: //UTriangle
 
500
                                        cl.sType=6;
 
501
                                        break;
 
502
                                case 4: //DTriangle
 
503
                                        cl.sType=5;
 
504
                                        break;
 
505
                                case 5: //Diamond
 
506
                                        cl.sType=3;
 
507
                                        break;
 
508
                                case 6: //Cross +
 
509
                                        cl.sType=9;
 
510
                                        break;
 
511
                                case 7: //Cross x
 
512
                                        cl.sType=10;
 
513
                                        break;
 
514
                                case 8: //Snow
 
515
                                        cl.sType=13;
 
516
                                        break;
 
517
                                case 9: //Horizontal -
 
518
                                        cl.sType=11;
 
519
                                        break;
 
520
                                case 10: //Vertical |
 
521
                                        cl.sType=12;
 
522
                                        break;
 
523
                                case 15: //LTriangle
 
524
                                        cl.sType=7;
 
525
                                        break;
 
526
                                case 16: //RTriangle
 
527
                                        cl.sType=8;
 
528
                                        break;
 
529
                                case 17: //Hexagon
 
530
                                case 19: //Pentagon
 
531
                                        cl.sType=15;
 
532
                                        break;
 
533
                                case 18: //Star
 
534
                                        cl.sType=14;
 
535
                                        break;
 
536
                                default:
 
537
                                        cl.sType=0;
 
538
                                }
 
539
 
 
540
                                switch(opj.curveSymbolType(g,l,c)>>8)
 
541
                                {
 
542
                                case 0:
 
543
                                        cl.fillCol=color;
 
544
                                        break;
 
545
                                case 1:
 
546
                                case 2:
 
547
                                case 8:
 
548
                                case 9:
 
549
                                case 10:
 
550
                                case 11:
 
551
                                        color=opj.curveSymbolFillColor(g,l,c);
 
552
                                        if((style==Graph::Scatter||style==Graph::LineSymbols)&&color==0xF7)//0xF7 -Automatic color
 
553
                                                color=17;// depend on Origin settings - not stored in file
 
554
                                        cl.fillCol=color;
 
555
                                        break;
 
556
                                default:
 
557
                                        cl.fillCol=-1;
 
558
                                }
 
559
 
 
560
                                cl.lWidth = ceil(opj.curveLineWidth(g,l,c));
 
561
                                color=opj.curveLineColor(g,l,c);
 
562
                                cl.lCol=(color==0xF7?0:color); //0xF7 -Automatic color
 
563
                                int linestyle=opj.curveLineStyle(g,l,c);
 
564
                                cl.filledArea=(opj.curveIsFilledArea(g,l,c)||style==Graph::VerticalBars||style==Graph::HorizontalBars||style==Graph::Histogram)?1:0;
 
565
                                if(cl.filledArea)
 
566
                                {
 
567
                                        switch(opj.curveFillPattern(g,l,c))
 
568
                                        {
 
569
                                        case 0:
 
570
                                                cl.aStyle=0;
 
571
                                                break;
 
572
                                        case 1:
 
573
                                        case 2:
 
574
                                        case 3:
 
575
                                                cl.aStyle=4;
 
576
                                                break;
 
577
                                        case 4:
 
578
                                        case 5:
 
579
                                        case 6:
 
580
                                                cl.aStyle=5;
 
581
                                                break;
 
582
                                        case 7:
 
583
                                        case 8:
 
584
                                        case 9:
 
585
                                                cl.aStyle=6;
 
586
                                                break;
 
587
                                        case 10:
 
588
                                        case 11:
 
589
                                        case 12:
 
590
                                                cl.aStyle=1;
 
591
                                                break;
 
592
                                        case 13:
 
593
                                        case 14:
 
594
                                        case 15:
 
595
                                                cl.aStyle=2;
 
596
                                                break;
 
597
                                        case 16:
 
598
                                        case 17:
 
599
                                        case 18:
 
600
                                                cl.aStyle=3;
 
601
                                                break;
 
602
                                        }
 
603
                                        color=(cl.aStyle==0 ? opj.curveFillAreaColor(g,l,c) : opj.curveFillPatternColor(g,l,c));
 
604
                                        cl.aCol=(color==0xF7?0:color); //0xF7 -Automatic color
 
605
                                        if (style == Graph::VerticalBars || style == Graph::HorizontalBars || style == Graph::Histogram)
 
606
                                        {
 
607
                                                color=opj.curveFillPatternBorderColor(g,l,c);
 
608
                                                cl.lCol = (color==0xF7?0:color); //0xF7 -Automatic color
 
609
                                                color=(cl.aStyle==0 ? opj.curveFillAreaColor(g,l,c) : opj.curveFillPatternColor(g,l,c));
 
610
                                                cl.aCol=(color==0xF7?cl.lCol:color); //0xF7 -Automatic color
 
611
                                                cl.lWidth = ceil(opj.curveFillPatternBorderWidth(g,l,c));
 
612
                                                linestyle=opj.curveFillPatternBorderStyle(g,l,c);
 
613
                                        }
 
614
                                }
 
615
                                switch (linestyle)
 
616
                                {
 
617
                                        case OPJFile::Solid:
 
618
                                                cl.lStyle=0;
 
619
                                                break;
 
620
                                        case OPJFile::Dash:
 
621
                                        case OPJFile::ShortDash:
 
622
                                                cl.lStyle=1;
 
623
                                                break;
 
624
                                        case OPJFile::Dot:
 
625
                                        case OPJFile::ShortDot:
 
626
                                                cl.lStyle=2;
 
627
                                                break;
 
628
                                        case OPJFile::DashDot:
 
629
                                        case OPJFile::ShortDashDot:
 
630
                                                cl.lStyle=3;
 
631
                                                break;
 
632
                                        case OPJFile::DashDotDot:
 
633
                                                cl.lStyle=4;
 
634
                                                break;
 
635
                                }
 
636
                                
 
637
                                graph->updateCurveLayout(c, &cl);
 
638
                                if (style == Graph::VerticalBars || style == Graph::HorizontalBars)
 
639
                                {
 
640
                                        QwtBarCurve *b = (QwtBarCurve*)graph->curve(c);
 
641
                                        if (b)
 
642
                                                b->setGap(qRound(100-opj.curveSymbolSize(g,l,c)*10));
 
643
                                }
 
644
                                else if(style == Graph::Histogram)
 
645
                                {
 
646
                                        QwtHistogram *h = (QwtHistogram*)graph->curve(c);
 
647
                                        if (h)
 
648
                                        {
 
649
                                                vector<double> bin=opj.layerHistogram(g,l);
 
650
                                                if(bin.size()==3)
 
651
                                                        h->setBinning(false, bin[0], bin[1], bin[2]);
 
652
                                                h->loadData();
 
653
                                        }
 
654
                                }
 
655
                                switch(opj.curveLineConnect(g,l,c))
 
656
                                {
 
657
                                case OPJFile::NoLine:
 
658
                                        graph->setCurveStyle(c, QwtPlotCurve::NoCurve);
 
659
                                        break;
 
660
                                case OPJFile::Straight:
 
661
                                        graph->setCurveStyle(c, QwtPlotCurve::Lines);
 
662
                                        break;
 
663
                                case OPJFile::BSpline:
 
664
                                case OPJFile::Bezier:
 
665
                                case OPJFile::Spline:
 
666
                                        graph->setCurveStyle(c, 5);
 
667
                                        break;
 
668
                                case OPJFile::StepHorizontal:
 
669
                                case OPJFile::StepHCenter:
 
670
                                        graph->setCurveStyle(c, QwtPlotCurve::Steps);
 
671
                                        break;
 
672
                                case OPJFile::StepVertical:
 
673
                                case OPJFile::StepVCenter:
 
674
                                        graph->setCurveStyle(c, 6);
 
675
                                        break;
 
676
                                }
 
677
 
 
678
                        }
 
679
                        vector<double> rangeX=opj.layerXRange(g,l);
 
680
                        vector<int>    ticksX=opj.layerXTicks(g,l);
 
681
                        vector<double> rangeY=opj.layerYRange(g,l);
 
682
                        vector<int>        ticksY=opj.layerYTicks(g,l);
 
683
                        if(style==Graph::HorizontalBars)
 
684
                        {
 
685
                                graph->setScale(0,rangeX[0],rangeX[1],rangeX[2],ticksX[0],ticksX[1],opj.layerXScale(g,l));
 
686
                                graph->setScale(2,rangeY[0],rangeY[1],rangeY[2],ticksY[0],ticksY[1],opj.layerYScale(g,l));
 
687
                        }
 
688
                        else
 
689
                        {
 
690
                                graph->setScale(2,rangeX[0],rangeX[1],rangeX[2],ticksX[0],ticksX[1],opj.layerXScale(g,l));
 
691
                                graph->setScale(0,rangeY[0],rangeY[1],rangeY[2],ticksY[0],ticksY[1],opj.layerYScale(g,l));
 
692
                        }
 
693
                        
 
694
                        //grid
 
695
                        vector<graphGrid> grids=opj.layerGrid(g,l);
 
696
                        GridOptions grid;
 
697
                        grid.majorOnX=(grids[0].hidden?0:1);
 
698
                        grid.minorOnX=(grids[1].hidden?0:1);
 
699
                        grid.majorOnY=(grids[2].hidden?0:1);
 
700
                        grid.minorOnY=(grids[3].hidden?0:1);
 
701
                        grid.majorStyle=translateOrigin2QtiplotLineStyle(grids[0].style);
 
702
                        grid.majorCol=grids[0].color;
 
703
                        grid.majorWidth=ceil(grids[0].width);
 
704
                        grid.minorStyle=translateOrigin2QtiplotLineStyle(grids[1].style);
 
705
                        grid.minorCol=grids[1].color;
 
706
                        grid.minorWidth=ceil(grids[1].width);
 
707
                        grid.xZeroOn=0;
 
708
                        grid.yZeroOn=0;
 
709
                        grid.xAxis=2;
 
710
                        grid.yAxis=0;
 
711
                        graph->setGridOptions(grid);
 
712
 
 
713
                        vector<graphAxisFormat> formats=opj.layerAxisFormat(g,l);
 
714
                        vector<graphAxisTick> ticks=opj.layerAxisTickLabels(g,l);
 
715
                        for(int i=0; i<4; ++i)
 
716
                        {
 
717
                                QString data(ticks[i].dataName.c_str());
 
718
                                QString tableName=data.right(data.length()-2) + "_" + ticks[i].colName.c_str();
 
719
 
 
720
                                QString formatInfo;
 
721
                                int format;
 
722
                                int type;
 
723
                                int prec=ticks[i].decimal_places;
 
724
                                switch(ticks[i].value_type)
 
725
                                {
 
726
                                case OPJFile::Numeric:
 
727
                                        type=Graph::Numeric;
 
728
                                        switch(ticks[i].value_type_specification)
 
729
                                        {
 
730
                                        case 0: //Decimal 1000
 
731
                                                format=1;
 
732
                                                break;
 
733
                                        case 1: //Scientific
 
734
                                                format=2;
 
735
                                                break;
 
736
                                        case 2: //Engeneering
 
737
                                        case 3: //Decimal 1,000
 
738
                                                format=0;
 
739
                                                break;
 
740
                                        }
 
741
                                        if(prec==-1)
 
742
                                                prec=2;
 
743
                                        break;
 
744
                                case OPJFile::Text: //Text
 
745
                                        type=Graph::Txt;
 
746
                                        break;
 
747
                                case 2: // Date
 
748
                                        type=Graph::Date;
 
749
                                        break;
 
750
                                case 3: // Time
 
751
                                        type=Graph::Time;
 
752
                                        break;
 
753
                                case OPJFile::Month: // Month
 
754
                                        type=Graph::Month;
 
755
                                        format=ticks[i].value_type_specification;
 
756
                                        break;
 
757
                                case OPJFile::Day: // Day
 
758
                                        type=Graph::Day;
 
759
                                        format=ticks[i].value_type_specification;
 
760
                                        break;
 
761
                                case OPJFile::ColumnHeading:
 
762
                                        type=Graph::ColHeader;
 
763
                                        switch(ticks[i].value_type_specification)
 
764
                                        {
 
765
                                        case 0: //Decimal 1000
 
766
                                                format=1;
 
767
                                                break;
 
768
                                        case 1: //Scientific
 
769
                                                format=2;
 
770
                                                break;
 
771
                                        case 2: //Engeneering
 
772
                                        case 3: //Decimal 1,000
 
773
                                                format=0;
 
774
                                                break;
 
775
                                        }
 
776
                                        prec=2;
 
777
                                        break;
 
778
                                default:
 
779
                                        type=Graph::Numeric;
 
780
                                        format=0;
 
781
                                        prec=2;
 
782
                                }
 
783
 
 
784
                                graph->showAxis(i, type, tableName, mw->table(tableName), !(formats[i].hidden), 
 
785
                                        tickTypeMap[formats[i].majorTicksType], tickTypeMap[formats[i].minorTicksType], 
 
786
                                        !(ticks[i].hidden),     ColorBox::color(formats[i].color), format, prec, 
 
787
                                        ticks[i].rotation, 0, "", (ticks[i].color==0xF7 ? ColorBox::color(formats[i].color) : ColorBox::color(ticks[i].color)));
 
788
                        }
 
789
 
 
790
 
 
791
                        graph->setAutoscaleFonts(mw->autoScaleFonts);//restore user defined fonts behaviour
 
792
                graph->setIgnoreResizeEvents(!mw->autoResizeLayers);
 
793
                }
 
794
                //cascade the graphs
 
795
                if(!opj.graphHidden(g))
 
796
                {
 
797
                        int dx=20;
 
798
                        int dy=ml->parentWidget()->frameGeometry().height() - ml->height();
 
799
                        ml->parentWidget()->move(QPoint(visible_count*dx+xoffset*OBJECTXOFFSET,visible_count*dy));
 
800
                        visible_count++;
 
801
                        ml->show();
 
802
                        ml->arrangeLayers(true,true);
 
803
                }
 
804
                else
 
805
                {
 
806
                        ml->show();
 
807
                        ml->arrangeLayers(true,true);
 
808
                        mw->hideWindow(ml);
 
809
                }
 
810
        }
 
811
        if(visible_count>0)
 
812
                xoffset++;
 
813
        return true;
 
814
}
 
815
 
 
816
QString ImportOPJ::parseOriginText(const QString &str)
 
817
{
 
818
        QStringList lines=str.split("\n");
 
819
        QString text="";
 
820
        for(int i=0; i<lines.size(); ++i)
 
821
        {
 
822
                if(i>0)
 
823
                        text.append("\n");
 
824
                text.append(parseOriginTags(lines[i]));
 
825
        }
 
826
        return text;
 
827
}
 
828
 
 
829
QString ImportOPJ::parseOriginTags(const QString &str)
 
830
{
 
831
        QString line=str;
 
832
        //replace \l(...) and %(...) tags
 
833
        QRegExp rxline("\\\\\\s*l\\s*\\(\\s*\\d+\\s*\\)");
 
834
        QRegExp rxcol("\\%\\(\\d+\\)");
 
835
        int pos = rxline.indexIn(line);
 
836
        while (pos > -1) {
 
837
                QString value = rxline.cap(0);
 
838
                int len=value.length();
 
839
                value.replace(QRegExp(" "),"");
 
840
                value="\\c{"+value.mid(3,value.length()-4)+"}";
 
841
                line.replace(pos, len, value);
 
842
                pos = rxline.indexIn(line);
 
843
        }
 
844
        //Lookbehind conditions are not supported - so need to reverse string
 
845
        QRegExp rx("\\)[^\\)\\(]*\\((?!\\s*[buig\\+\\-]\\s*\\\\)");
 
846
        QRegExp rxfont("\\)[^\\)\\(]*\\((?![^\\:]*\\:f\\s*\\\\)");
 
847
        QString linerev = strreverse(line);
 
848
        QString lBracket=strreverse("&lbracket;");
 
849
        QString rBracket=strreverse("&rbracket;");
 
850
        QString ltagBracket=strreverse("&ltagbracket;");
 
851
        QString rtagBracket=strreverse("&rtagbracket;");
 
852
        int pos1=rx.indexIn(linerev);
 
853
        int pos2=rxfont.indexIn(linerev);
 
854
        
 
855
        while (pos1>-1 || pos2>-1) {
 
856
                if(pos1==pos2)
 
857
                {
 
858
                        QString value = rx.cap(0);
 
859
                        int len=value.length();
 
860
                        value=rBracket+value.mid(1,len-2)+lBracket;
 
861
                        linerev.replace(pos1, len, value);
 
862
                }
 
863
                else if ((pos1>pos2&&pos2!=-1)||pos1==-1)
 
864
                {
 
865
                        QString value = rxfont.cap(0);
 
866
                        int len=value.length();
 
867
                        value=rtagBracket+value.mid(1,len-2)+ltagBracket;
 
868
                        linerev.replace(pos2, len, value);
 
869
                }
 
870
                else if ((pos2>pos1&&pos1!=-1)||pos2==-1)
 
871
                {
 
872
                        QString value = rx.cap(0);
 
873
                        int len=value.length();
 
874
                        value=rtagBracket+value.mid(1,len-2)+ltagBracket;
 
875
                        linerev.replace(pos1, len, value);
 
876
                }
 
877
                
 
878
                pos1=rx.indexIn(linerev);
 
879
                pos2=rxfont.indexIn(linerev);
 
880
        }
 
881
        linerev.replace(ltagBracket, "(");
 
882
        linerev.replace(rtagBracket, ")");
 
883
        
 
884
        line = strreverse(linerev);
 
885
        
 
886
        //replace \b(...), \i(...), \u(...), \g(...), \+(...), \-(...), \f:font(...) tags
 
887
        QString rxstr[]={
 
888
                "\\\\\\s*b\\s*\\(",
 
889
                "\\\\\\s*i\\s*\\(",
 
890
                "\\\\\\s*u\\s*\\(",
 
891
                "\\\\\\s*g\\s*\\(",
 
892
                "\\\\\\s*\\+\\s*\\(",
 
893
                "\\\\\\s*\\-\\s*\\(",
 
894
                "\\\\\\s*f\\:[^\\(]*\\("};
 
895
        int postag[]={0,0,0,0,0,0,0};
 
896
        QString ltag[]={"<b>","<i>","<u>","<font face=Symbol>","<sup>","<sub>","<font face=%1>"};
 
897
        QString rtag[]={"</b>","</i>","</u>","</font>","</sup>","</sub>","</font>"};
 
898
        QRegExp rxtags[7];
 
899
        for(int i=0; i<7; ++i)
 
900
                rxtags[i].setPattern(rxstr[i]+"[^\\(\\)]*\\)");
 
901
 
 
902
        bool flag=true;
 
903
        while(flag) {
 
904
                for(int i=0; i<7; ++i)
 
905
                {
 
906
                        postag[i] = rxtags[i].indexIn(line);
 
907
                        while (postag[i] > -1) {
 
908
                                QString value = rxtags[i].cap(0);
 
909
                                int len=value.length();
 
910
                                int pos2=value.indexOf("(");
 
911
                                if(i<6)
 
912
                                        value=ltag[i]+value.mid(pos2+1,len-pos2-2)+rtag[i];
 
913
                                else
 
914
                                {
 
915
                                        int posfont=value.indexOf("f:");
 
916
                                        value=ltag[i].arg(value.mid(posfont+2,pos2-posfont-2))+value.mid(pos2+1,len-pos2-2)+rtag[i];
 
917
                                }
 
918
                                line.replace(postag[i], len, value);
 
919
                                postag[i] = rxtags[i].indexIn(line);
 
920
                        }
 
921
                }
 
922
                flag=false;
 
923
                for(int i=0; i<7; ++i)
 
924
                {
 
925
                        if(rxtags[i].indexIn(line)>-1)
 
926
                        {
 
927
                                flag=true;
 
928
                                break;
 
929
                        }
 
930
                }
 
931
        }
 
932
 
 
933
        //replace unclosed tags
 
934
        for(int i=0; i<6; ++i)
 
935
                line.replace(QRegExp(rxstr[i]), ltag[i]);
 
936
        rxfont.setPattern(rxstr[6]);
 
937
        pos = rxfont.indexIn(line);
 
938
        while (pos > -1) {
 
939
                QString value = rxfont.cap(0);
 
940
                int len=value.length();
 
941
                int posfont=value.indexOf("f:");
 
942
                value=ltag[6].arg(value.mid(posfont+2,len-posfont-3));
 
943
                line.replace(pos, len, value);
 
944
                pos = rxfont.indexIn(line);
 
945
        }
 
946
 
 
947
        line.replace("&lbracket;", "(");
 
948
        line.replace("&rbracket;", ")");
 
949
 
 
950
        return line;
 
951
}
 
952
 
 
953
//TODO: bug in grid dialog
 
954
//              scale/minor ticks checkbox
 
955
//              histogram: autobin export
 
956
//              if prec not setted - automac+4digits