~ubuntu-branches/ubuntu/maverick/scidavis/maverick

« back to all changes in this revision

Viewing changes to scidavis/src/importOPJ.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

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