forked from Saluev/python-liborigin2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathliborigin.pyx
950 lines (772 loc) · 34.8 KB
/
liborigin.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
cimport objects
from objects cimport bool, string, vector, pair, tree, tree_node, OriginFile
cimport cython.operator
from cython.operator import dereference as deref
#from PyQt4 import QtCore, QtGui
#Qt = QtCore.Qt
####################################################################################################
########################################## ###########################################
######################################### Object classes ###########################################
######################################### ############################################
####################################################################################################
cdef class Color:
cdef public int type # enum
cdef public int regular, starting, column
cdef public object custom
cdef void copy(self, const objects.Color *arg):
self.type = <int>arg.type
self.regular = arg.regular
self.starting = arg.starting
self.column = arg.column
cdef class Rect:
cdef public int left, top, right, bottom
cdef void copy(self, const objects.Rect *arg):
self.left = arg.left
self.top = arg.top
self.right = arg.right
self.bottom = arg.bottom
cdef class ColorMapLevel:
cdef public object fillColor, fillPatternColor, lineColor
cdef public int fillPattern, lineStyle
cdef public float fillPatternLineWidth, lineWidth
cdef public bool lineVisible, labelVisible
cdef void copy(self, const objects.ColorMapLevel *lvl):
self.fillColor = makeColor(lvl.fillColor)
self.fillPatternColor = makeColor(lvl.fillPatternColor)
self.lineColor = makeColor(lvl.lineColor)
self.fillPattern = lvl.fillPattern
self.lineStyle = lvl.lineStyle
self.fillPatternLineWidth = lvl.fillPatternLineWidth
self.lineWidth = lvl.lineWidth
self.lineVisible = lvl.lineVisible
self.labelVisible = lvl.labelVisible
cdef class ColorMap:
cdef public bool fillEnabled
cdef public object levels
cdef void copy(self, const objects.ColorMap *mp):
self.fillEnabled = mp.fillEnabled
self.levels = []
for i in xrange(mp.levels.size()):
self.levels.append((mp.levels[i].first, makeColorMapLevel(mp.levels[i].second)))
cdef class Window:
cdef public string name, label
cdef public int objectID
cdef public bool hidden
cdef public int state, title # enums
cdef public object frameRect
cdef public long creationDate, modificationDate
cdef void copy(self, const objects.Window *wnd):
self.name = wnd.name
self.label = wnd.label
self.objectID = wnd.objectID
self.hidden = wnd.hidden
self.state = <int>wnd.state
self.title = <int>wnd.title
self.frameRect = makeRect(wnd.frameRect)
self.creationDate = wnd.creationDate
self.modificationDate = wnd.modificationDate
cdef class SpreadColumn:
cdef public string name, command, comment
cdef public int type, valueType, numericDisplayType # enums
cdef public int valueTypeSpecification, significantDigits, decimalPlaces, width, index, colIndex, sheet
cdef public object data
cdef void copy(self, const objects.SpreadColumn *col):
cdef const double *doublePointer
cdef const string *stringPointer
cdef double doubleValue
cdef string stringValue
self.name = col.name
self.type = <int>col.type
self.valueType = <int>col.valueType
self.valueTypeSpecification = col.valueTypeSpecification
self.significantDigits = col.significantDigits
self.decimalPlaces = col.decimalPlaces
self.numericDisplayType = <int>col.numericDisplayType
self.command = col.command
self.comment = col.comment
self.width = col.width
self.index = col.index
self.colIndex = col.colIndex
self.sheet = col.sheet
self.data = []
# data copying is... umm... complicated.
# Because of FUCKING BOOST::VARIANT!11
dataSize = col.data.size()
for i in range(dataSize):
doublePointer = objects.getDoubleFromVariant(&(col.data[i]))
stringPointer = objects.getStringFromVariant(&(col.data[i]))
if doublePointer:
doubleValue = deref(doublePointer)
self.data.append(float(doubleValue))
else:
stringValue = deref(stringPointer)
self.data.append(stringValue)
cdef class SpreadSheet(Window):
cdef public int maxRows, sheets
cdef public bool loose
cdef public object columns
cdef void copy(self, const objects.Window *wnd):
Window.copy(self, wnd)
cdef const objects.SpreadSheet *sht = <objects.SpreadSheet*>wnd
self.maxRows = sht.maxRows
self.loose = sht.loose
self.sheets = sht.sheets
self.columns = [makeSpreadColumn(sht.columns[i]) for i in xrange(sht.columns.size())]
cdef class MatrixSheet:
cdef public int rowCount, columnCount, valueTypeSpecification, significantDigits, decimalPlaces
cdef public int numericDisplayType, view # enums
cdef public string command, name
cdef public int width, index, sheets
cdef public object colorMap, data, coordinates
cdef void copy(self, const objects.MatrixSheet *mtxsh):
self.rowCount = mtxsh.rowCount
self.columnCount = mtxsh.columnCount
self.valueTypeSpecification = mtxsh.valueTypeSpecification
self.significantDigits = mtxsh.significantDigits
self.decimalPlaces = mtxsh.decimalPlaces
self.numericDisplayType = <int>mtxsh.numericDisplayType
self.command = mtxsh.command
self.name = mtxsh.name
self.width = mtxsh.width
self.index = mtxsh.index
self.view = <int>mtxsh.view
self.colorMap = makeColorMap(mtxsh.colorMap)
self.data = [mtxsh.data[i] for i in xrange(mtxsh.data.size())]
self.coordinates = [mtxsh.coordinates[i] for i in xrange(mtxsh.coordinates.size())]
cdef class Matrix(Window):
cdef public int activeSheet
cdef public int header # enums
cdef public object sheets
cdef void copy(self, const objects.Window *wnd):
Window.copy(self, wnd)
cdef const objects.Matrix *mtx = <objects.Matrix*>wnd
self.header = <int>mtx.header
self.activeSheet = mtx.activeSheet
self.sheets = [makeMatrixSheet(mtx.sheets[i]) for i in xrange(mtx.sheets.size())]
cdef class Function:
cdef public string name, formula
cdef public int type # enum
cdef public float begin, end
cdef public int totalPoints, index
cdef void copy(self, const objects.Function *f):
self.name = f.name
self.formula = f.formula
self.type = <int>f.type
self.begin = f.begin
self.end = f.end
self.totalPoints = f.totalPoints
self.index = f.index
cdef class TextBox:
cdef public string text
cdef public object clientRect, color
cdef public int fontSize, rotation, tab
cdef public int borderType, attach #enums
cdef void copy(self, const objects.TextBox *tb):
self.text = tb.text
self.clientRect = makeRect(tb.clientRect)
self.color = makeColor(tb.color)
self.fontSize = tb.fontSize
self.rotation = tb.rotation
self.tab = tb.tab
self.borderType = <int>tb.borderType
self.attach = <int>tb.attach
cdef class PieProperties:
cdef public int viewAngle, thickness, rotation, radius, \
horizontalOffset, displacedSectionCount, displacement, distance
cdef public bool clockwiseRotation, formatAutomatic, formatValues, formatPercentages, \
formatCategories, positionAssociate
cdef void copy(self, const objects.PieProperties *arg):
self.clockwiseRotation = arg.clockwiseRotation
self.formatAutomatic = arg.formatAutomatic
self.formatValues = arg.formatValues
self.formatPercentages = arg.formatPercentages
self.formatCategories = arg.formatCategories
self.positionAssociate = arg.positionAssociate
cdef class TextProperties:
cdef public object color # Color
cdef public bool fontBold, fontItalic, fontUnderline, whiteOut
cdef public int justify # enum
cdef public int rotation, xOffset, yOffset, fontSize
cdef void copy(self, const objects.TextProperties *arg):
self.color = makeColor(arg.color)
self.fontBold = arg.fontBold
self.fontItalic = arg.fontItalic
self.fontUnderline = arg.fontUnderline
self.whiteOut = arg.whiteOut
self.justify = <int>arg.justify
self.rotation = arg.rotation
self.xOffset = arg.xOffset
self.yOffset = arg.yOffset
self.fontSize = arg.fontSize
cdef class VectorProperties:
cdef public object color # Color
cdef public float width, multiplier
cdef public int arrowLength, arrowAngle, constAngle, constMagnitude # original arrowLength has a typo
cdef public bool arrowClosed
cdef public string endXColumnName, endYColumnName, angleColumnName, magnitudeColumnName
cdef void copy(self, const objects.VectorProperties *arg):
self.color = makeColor(arg.color)
self.width = arg.width
self.multiplier = arg.multiplier
self.arrowClosed = arg.arrowClosed
self.endXColumnName = arg.endXColumnName
self.endYColumnName = arg.endYColumnName
self.angleColumnName = arg.angleColumnName
self.magnitudeColumnName = arg.magnitudeColumnName
cdef class SurfaceColoration:
cdef public bool fill, contour
cdef public object lineColor # Color
cdef public float lineWidth
cdef void copy(self, const objects.SurfaceColoration *arg):
self.fill = arg.fill
self.contour = arg.contour
self.lineColor = makeColor(arg.lineColor)
self.lineWidth = arg.lineWidth
cdef class SurfaceProperties:
cdef public int type
cdef public int grids # enum
cdef public float gridLineWidth
cdef public object gridColor, frontColor, backColor, xSideWallColor, ySideWallColor # Color
cdef public object surface, topContour, bottomContour # SurfaceColoration
cdef public object colorMap # ColorMap
cdef public bool backColorEnabled, sideWallEnabled
cdef void copy(self, const objects.SurfaceProperties *arg):
self.type = arg.type
self.grids = <int>arg.grids
self.gridLineWidth = arg.gridLineWidth
self.gridColor = makeColor(arg.gridColor)
self.frontColor = makeColor(arg.frontColor)
self.backColor = makeColor(arg.backColor)
self.xSideWallColor = makeColor(arg.xSideWallColor)
self.ySideWallColor = makeColor(arg.ySideWallColor)
self.surface = makeSurfaceColoration(arg.surface)
self.topContour = makeSurfaceColoration(arg.topContour)
self.bottomContour = makeSurfaceColoration(arg.bottomContour)
self.colorMap = makeColorMap(arg.colorMap)
self.backColorEnabled = arg.backColorEnabled
self.sideWallEnabled = arg.sideWallEnabled
cdef class PercentileProperties:
cdef public int maxSymbolType, p99SymbolType, meanSymbolType, p1SymbolType, minSymbolType, \
symbolSize, boxRange, whiskersRange, labels
cdef public object symbolColor, symbolFillColor # Color
cdef public float boxCoeff, whiskersCoeff
cdef public bool diamondBox
cdef void copy(self, const objects.PercentileProperties *arg):
self.maxSymbolType = arg.maxSymbolType
self.p99SymbolType = arg.p99SymbolType
self.meanSymbolType = arg.meanSymbolType
self.p1SymbolType = arg.p1SymbolType
self.minSymbolType = arg.minSymbolType
self.boxRange = arg.boxRange
self.whiskersRange = arg.whiskersRange
self.symbolColor = makeColor(arg.symbolColor)
self.symbolFillColor = makeColor(arg.symbolFillColor)
self.boxCoeff = arg.boxCoeff
self.whiskersCoeff = arg.whiskersCoeff
self.diamondBox = arg.diamondBox
self.labels = arg.labels
cdef class GraphCurve:
cdef public int type, lineTransparency, lineStyle, lineConnect, boxWidth, fillAreaType, fillAreaPattern, \
fillAreaTransparency, fillAreaPatternBorderStyle, symbolType, symbolFillTransparency, symbolThickness, pointOffset
cdef public string dataName, xDataName, xColumnName, yColumnName, zColumnName
cdef public object lineColor, fillAreaColor, fillAreaPatternColor, fillAreaPatternBorderColor, \
symbolColor, symbolFillColor # Color
cdef public object pie, vector, text, surface, colorMap
cdef public float lineWidth, fillAreaPatternWidth, fillAreaPatternBorderWidth, symbolSize
cdef public bool hidden, fillArea, fillAreaWithLineTransparency, connectSymbols
cdef void copy(self, const objects.GraphCurve *arg):
self.hidden = arg.hidden
self.type = arg.type
self.lineStyle = arg.lineStyle
self.lineTransparency = arg.lineTransparency
self.lineConnect = arg.lineConnect
self.boxWidth = arg.boxWidth
self.fillAreaType = arg.fillAreaType
self.fillAreaPattern = arg.fillAreaPattern
self.fillAreaTransparency = arg.fillAreaTransparency
self.fillAreaWithLineTransparency = arg.fillAreaWithLineTransparency
self.symbolFillTransparency = arg.symbolFillTransparency
self.symbolThickness = arg.symbolThickness
self.pointOffset = arg.pointOffset
self.dataName = arg.dataName
self.xDataName = arg.xDataName
self.xColumnName = arg.xColumnName
self.yColumnName = arg.yColumnName
self.zColumnName = arg.zColumnName
self.lineColor = makeColor(arg.lineColor)
self.fillAreaColor = makeColor(arg.fillAreaColor)
self.fillAreaPatternColor = makeColor(arg.fillAreaPatternColor)
self.fillAreaPatternBorderColor = makeColor(arg.fillAreaPatternBorderColor)
self.symbolColor = makeColor(arg.symbolColor)
self.symbolFillColor = makeColor(arg.symbolFillColor)
self.pie = makePieProperties(arg.pie)
self.vector = makeVectorProperties(arg.vector)
self.text = makeTextProperties(arg.text)
self.surface = makeSurfaceProperties(arg.surface)
self.colorMap = makeColorMap(arg.colorMap)
self.lineWidth = arg.lineWidth
self.fillAreaPatternWidth = arg.fillAreaPatternWidth
self.fillAreaPatternBorderWidth = arg.fillAreaPatternBorderWidth
self.symbolSize = arg.symbolSize
self.fillArea = arg.fillArea
self.connectSymbols = arg.connectSymbols
cdef class GraphAxisBreak:
cdef public bool show, log10
cdef public float gabFrom, to, position, scaleIncrementBefore, scaleIncrementAfter
cdef public int minorTicksBefore, minorTicksAfter
cdef void copy(self, const objects.GraphAxisBreak *arg):
self.show = arg.show
self.log10 = arg.log10
self.gabFrom = arg.gabFrom
self.to = arg.to
self.position = arg.position
self.scaleIncrementBefore = arg.scaleIncrementBefore
self.scaleIncrementAfter = arg.scaleIncrementAfter
self.minorTicksBefore = arg.minorTicksBefore
self.minorTicksAfter = arg.minorTicksAfter
cdef class GraphGrid:
cdef public bool hidden
cdef public int color, style
cdef public float width
cdef void copy(self, const objects.GraphGrid *arg):
self.hidden = arg.hidden
self.color = arg.color
self.style = arg.style
self.width = arg.width
cdef class GraphAxisFormat:
cdef public bool hidden
cdef public int color, majorTicksType, minorTicksType, axisPosition
cdef public float thickness, majorTickLength, axisPositionValue
cdef public object label # TextBox
cdef public string prefix, suffix, factor
cdef void copy(self, const objects.GraphAxisFormat *arg):
self.hidden = arg.hidden
self.color = arg.color
self.majorTicksType = arg.majorTicksType
self.minorTicksType = arg.minorTicksType
self.axisPosition = arg.axisPosition
self.thickness = arg.thickness
self.majorTickLength = arg.majorTickLength
self.axisPositionValue = arg.axisPositionValue
self.label = makeTextBox(arg.label)
self.prefix = arg.prefix
self.suffix = arg.suffix
self.factor = arg.factor
cdef class GraphAxisTick:
cdef public bool showMajorLabels, fontBold
cdef public int color, valueTypeSpecification, decimalPlaces, fontSize, rotation
cdef public int valueType # enum
cdef public string dataName, columnName
cdef void copy(self, const objects.GraphAxisTick *arg):
self.showMajorLabels = arg.showMajorLabels
self.fontBold = arg.fontBold
self.color = arg.color
self.valueTypeSpecification = arg.valueTypeSpecification
self.decimalPlaces = arg.decimalPlaces
self.fontSize = arg.fontSize
self.rotation = arg.rotation
self.valueType = <int>arg.valueType
self.dataName = arg.dataName
self.columnName = arg.columnName
cdef class GraphAxis:
cdef public int position # enum
cdef public bool zeroLine, oppositeLine
cdef public float min, max, step
cdef public int majorTicks, minorTicks, scale
cdef public object majorGrid, minorGrid # GraphGrid
cdef public object formatAxis # GraphAxisFormat x 2
cdef public object tickAxis # GraphAxisTick x 2
cdef void copy(self, const objects.GraphAxis *arg):
self.position = <int>arg.position
self.zeroLine = arg.zeroLine
self.oppositeLine = arg.oppositeLine
self.min = arg.min
self.max = arg.max
self.step = arg.step
self.majorTicks = arg.majorTicks
self.minorTicks = arg.minorTicks
self.scale = arg.scale
self.majorGrid = makeGraphGrid(arg.majorGrid)
self.minorGrid = makeGraphGrid(arg.minorGrid)
self.formatAxis = [makeGraphAxisFormat(arg.formatAxis[0]), makeGraphAxisFormat(arg.formatAxis[1])]
self.tickAxis = [makeGraphAxisTick(arg.tickAxis[0]), makeGraphAxisTick(arg.tickAxis[1])]
cdef class Figure:
cdef public int type, attach # enums
cdef public object clientRect # Rect
cdef public object color, fillAreaColor, fillAreaPatternColor # Color
cdef public int style, fillAreaPattern,
cdef public float width, fillAreaPatternWidth
cdef public bool useBorderColor
cdef void copy(self, const objects.Figure *arg):
self.type = <int>arg.type
self.attach = <int>arg.attach
self.clientRect = makeRect(arg.clientRect)
self.color = makeColor(arg.color)
self.fillAreaColor = makeColor(arg.fillAreaColor)
self.fillAreaPatternColor = makeColor(arg.fillAreaPatternColor)
self.width = arg.width
self.fillAreaPatternWidth = arg.fillAreaPatternWidth
self.useBorderColor = arg.useBorderColor
cdef class LineVertex:
cdef public int shapeType
cdef public float shapeWidth, shapeLength, x, y
cdef void copy(self, const objects.LineVertex *arg):
self.shapeType = arg.shapeType
self.shapeWidth = arg.shapeWidth
self.shapeLength = arg.shapeLength
self.x = arg.x
self.y = arg.y
cdef class Line:
cdef public object clientRect # Rect
cdef public object color # Color
cdef public int attach # enum
cdef public float width
cdef public int style
cdef public object begin, end # LineVertex
cdef void copy(self, const objects.Line *arg):
self.clientRect = makeRect(arg.clientRect)
self.color = makeColor(arg.color)
self.attach = <int>arg.attach
self.width = arg.width
self.style = arg.style
self.begin = makeLineVertex(arg.begin)
self.end = makeLineVertex(arg.end)
cdef class Bitmap:
cdef public object clientRect # Rect
cdef public int attach, borderType # enums
cdef public int size
cdef public string windowName
cdef public object data
cdef void copy(self, const objects.Bitmap *arg):
self.clientRect = makeRect(arg.clientRect)
self.attach = <int>arg.attach
self.borderType = <int>arg.borderType
self.size = arg.size
self.windowName = arg.windowName
self.data = [arg.data[i] for i in xrange(self.size)]
cdef class ColorScale:
cdef public bool visible, reverseOrder
cdef public int labelGap, colorBarThickness
cdef public object labelsColor # Color
cdef void copy(self, const objects.ColorScale *arg):
self.visible = arg.visible
self.reverseOrder = arg.reverseOrder
self.labelGap = arg.labelGap
self.colorBarThickness = arg.colorBarThickness
self.labelsColor = makeColor(arg.labelsColor)
cdef class GraphLayer:
cdef public object clientRect # Rect
cdef public object legend # TextBox
cdef public object backgroundColor # Color
cdef public int borderType # enum
cdef public int imageProfileTool, xOffset, yOffset
cdef public object xAxis, yAxis, zAxis # GraphAxis
cdef public object xAxisBreak, yAxisBreak, zAxisBreak # GraphAxisBreak
cdef public float histogramBin, histogramBegin, histogramEnd, xAngle, yAngle, zAngle,\
xLength, yLength, zLength, vLine, hLine
cdef public object percentile # PercentileProperties
cdef public object colorScale # ColorScale
cdef public object texts, pieTexts, lines, figures, bitmaps, curves
cdef public bool isWaterfall, gridOnTop, exchangedAxes, isXYY3D, orthographic3D
cdef void copy(self, const objects.GraphLayer *arg):
self.clientRect = makeRect(arg.clientRect)
self.legend = makeTextBox(arg.legend)
self.backgroundColor = makeColor(arg.backgroundColor)
self.borderType = <int>arg.borderType
self.xAxis = makeGraphAxis(arg.xAxis)
self.yAxis = makeGraphAxis(arg.yAxis)
self.zAxis = makeGraphAxis(arg.zAxis)
self.xAxisBreak = makeGraphAxisBreak(arg.xAxisBreak)
self.yAxisBreak = makeGraphAxisBreak(arg.yAxisBreak)
self.zAxisBreak = makeGraphAxisBreak(arg.zAxisBreak)
self.histogramBin = arg.histogramBin
self.histogramBegin = arg.histogramBegin
self.histogramEnd = arg.histogramEnd
self.vLine = arg.vLine
self.hLine = arg.hLine
self.percentile = makePercentileProperties(arg.percentile)
self.colorScale = makeColorScale(arg.colorScale)
self.texts = [makeTextBox (arg.texts[i] ) for i in xrange(arg.texts.size() )]
self.pieTexts = [makeTextBox (arg.pieTexts[i]) for i in xrange(arg.pieTexts.size())]
self.lines = [makeLine (arg.lines[i] ) for i in xrange(arg.lines.size() )]
self.figures = [makeFigure (arg.figures[i] ) for i in xrange(arg.figures.size() )]
self.bitmaps = [makeBitmap (arg.bitmaps[i] ) for i in xrange(arg.bitmaps.size() )]
self.curves = [makeGraphCurve(arg.curves[i] ) for i in xrange(arg.curves.size() )]
self.xAngle = arg.xAngle
self.yAngle = arg.yAngle
self.zAngle = arg.zAngle
self.xLength = arg.xLength
self.yLength = arg.yLength
self.zLength = arg.zLength
self.imageProfileTool = arg.imageProfileTool
self.isWaterfall = arg.isWaterfall
self.xOffset = arg.xOffset
self.yOffset = arg.yOffset
self.gridOnTop = arg.gridOnTop
self.exchangedAxes = arg.exchangedAxes
self.isXYY3D = arg.isXYY3D
self.orthographic3D = arg.orthographic3D
cdef class GraphLayerRange:
cdef public float min, max, step
cdef void copy(self, const objects.GraphLayerRange *arg):
self.min = arg.min
self.max = arg.max
self.step = arg.step
cdef class Graph(Window):
cdef public object layers
cdef public int width, height
cdef public bool is3D, isLayout, connectMissingData
cdef public string templateName
cdef void copy(self, const objects.Window *wnd):
Window.copy(self, wnd)
cdef const objects.Graph *grph = <objects.Graph*>wnd
self.layers = [makeGraphLayer(grph.layers[i]) for i in xrange(grph.layers.size())]
self.width = grph.width
self.height = grph.height
self.is3D = grph.is3D
self.isLayout = grph.isLayout
self.connectMissingData = grph.connectMissingData
self.templateName = grph.templateName
cdef class Note(Window):
cdef public string text
cdef void copy(self, const objects.Window *wnd):
Window.copy(self, wnd)
cdef const objects.Note *nt = <objects.Note*>wnd
self.text = nt.text
cdef class ProjectNode:
cdef public int type # enum
cdef public string name
cdef public int creationDate, modificationDate
cdef public bool active
cdef void copy(self, const objects.ProjectNode *pn):
self.type = <int>pn.type
self.name = pn.name
self.creationDate = pn.creationDate
self.modificationDate = pn.modificationDate
self.active = pn.active
####################################################################################################
########################################## ############################################
######################################### Object makers ############################################
######################################### #############################################
####################################################################################################
cdef makeColor(const objects.Color &arg):
result = Color()
result.copy(&arg)
return result
#if clr.cType == objects.ctRegular: # TODO: implement commented colors
# result = [Qt.black, Qt.red, Qt.green, Qt.blue, Qt.cyan, Qt.magenta, Qt.yellow, Qt.darkYellow,
# "Qt.navy", "Qt.purple", "Qt.wine", "Qt.olive", Qt.darkCyan, "Qt.royal", "Qt.orange",
# "Qt.violet", "Qt.pink", Qt.white, Qt.lightGray, Qt.gray, "Qt.lightYellow",
# "Qt.lightCyan", "Qt.lightMagenta", Qt.darkGray][clr.regular] # TODO: check which byte is used
#elif clr.cType == objects.ctRGB:
# result = QtGui.QColor(clr.custom[0], clr.custom[1], clr.custom[2])
#elif clr.cType == objects.ctNone:
# result = None
#elif clr.cType == objects.ctAutomatic:
# result = "auto"
#else: # TODO: other color objects
# print "Unimplemented color: %d" % <int>clr.cType
# result = QtGui.QColor()
#return result
cdef makeRect(const objects.Rect &arg):
result = Rect()
result.copy(&arg)
return result
#return QtCore.QRect(QtCore.QPoint(arg.left, arg.top), QtCore.QPoint(arg.right, arg.bottom))
cdef makeColorMapLevel(const objects.ColorMapLevel &lvl):
result = ColorMapLevel()
result.copy(&lvl)
return result
cdef makeColorMap(const objects.ColorMap &mp):
result = ColorMap()
result.copy(&mp)
return result
cdef makeSpreadColumn(const objects.SpreadColumn &col):
result = SpreadColumn()
result.copy(&col)
return result
cdef makeSpreadSheet(const objects.SpreadSheet &sht):
result = SpreadSheet()
result.copy(&sht)
print "Loading book #%d(%s/%s) (%d sheets, %d columns)" % (result.objectID, result.name, result.label.replace(b"\n", b""), result.sheets, len(result.columns))
return result
cdef makeMatrixSheet(const objects.MatrixSheet &mtxsh):
result = MatrixSheet()
result.copy(&mtxsh)
return result
cdef makeMatrix(const objects.Matrix &mtx):
result = Matrix()
result.copy(&mtx)
print "Loading matrix #%d(%s/%s)" % (result.objectID, result.name, result.label.replace(b"\n", b""))
return result
cdef makeFunction(const objects.Function &f):
result = Function()
result.copy(&f)
print "Loading function #%d(%s)" % (result.index, result.name)
return result
cdef makeTextBox(const objects.TextBox &arg):
result = TextBox()
result.copy(&arg)
return result
cdef makePieProperties(const objects.PieProperties &arg):
result = PieProperties()
result.copy(&arg)
return result
cdef makeVectorProperties(const objects.VectorProperties &arg):
result = VectorProperties()
result.copy(&arg)
return result
cdef makeTextProperties(const objects.TextProperties &arg):
result = TextProperties()
result.copy(&arg)
return result
cdef makeSurfaceColoration(const objects.SurfaceColoration &arg):
result = SurfaceColoration()
result.copy(&arg)
return result
cdef makeSurfaceProperties(const objects.SurfaceProperties &arg):
result = SurfaceProperties()
result.copy(&arg)
return result
cdef makePercentileProperties(const objects.PercentileProperties &arg):
result = PercentileProperties()
result.copy(&arg)
return result
cdef makeGraphCurve(const objects.GraphCurve &arg):
result = GraphCurve()
result.copy(&arg)
return result
cdef makeGraphAxisBreak(const objects.GraphAxisBreak &arg):
result = GraphAxisBreak()
result.copy(&arg)
return result
cdef makeGraphGrid(const objects.GraphGrid &arg):
result = GraphGrid()
result.copy(&arg)
return result
cdef makeGraphAxisFormat(const objects.GraphAxisFormat &arg):
result = GraphAxisFormat()
result.copy(&arg)
return result
cdef makeGraphAxisTick(const objects.GraphAxisTick &arg):
result = GraphAxisTick()
result.copy(&arg)
return result
cdef makeGraphAxis(const objects.GraphAxis &arg):
result = GraphAxis()
result.copy(&arg)
return result
cdef makeFigure(const objects.Figure &arg):
result = Figure()
result.copy(&arg)
return result
cdef makeLineVertex(const objects.LineVertex &arg):
result = LineVertex()
result.copy(&arg)
return result
cdef makeLine(const objects.Line &arg):
result = Line()
result.copy(&arg)
return result
cdef makeBitmap(const objects.Bitmap &arg):
result = Bitmap()
result.copy(&arg)
return result
cdef makeColorScale(const objects.ColorScale &arg):
result = ColorScale()
result.copy(&arg)
return result
cdef makeGraphLayer(const objects.GraphLayer &arg):
result = GraphLayer()
result.copy(&arg)
return result
cdef makeGraphLayerRange(const objects.GraphLayerRange &arg):
result = GraphLayerRange()
result.copy(&arg)
return result
cdef makeGraph(const objects.Graph &arg):
result = Graph()
result.copy(&arg)
print "Loading graph #%d(%s/%s) (%d layers, 3D: %s)" % (result.objectID, result.name, result.label.replace(b"\n", b""), len(result.layers), result.is3D)
return result
cdef makeNote(const objects.Note &nt):
result = Note()
result.copy(&nt)
print "Loading note #%d(%s/%s)" % (result.objectID, result.name, result.label.replace(b"\n", b""))
return result
cdef makeProjectNode(const objects.ProjectNode &pn):
result = ProjectNode()
result.copy(&pn)
return result
cdef makeTreeNode(tree_node[objects.ProjectNode] *nd):
cdef tree[objects.ProjectNode].leaf_iterator *it = new tree[objects.ProjectNode].leaf_iterator(nd)
cdef tree[objects.ProjectNode].iterator_base *tmp = new tree[objects.ProjectNode].iterator_base(nd)
numel = tmp.number_of_children()
del tmp
children = []
for i in xrange(numel):
child = makeProjectNode(deref(deref(it)))
print child.name
children.append(child)
cython.operator.preincrement(it)
del it
return children
cdef makeTree(const tree[objects.ProjectNode] *tr):
cdef tree[objects.ProjectNode].pre_order_iterator it = tr.begin()
print "Going to pythonify tree with %d nodes." % tr.size()
return makeTreeNode(it.node)
####################################################################################################
####################################### ############################################
###################################### Python interface ############################################
###################################### #############################################
####################################################################################################
cdef void cProgressCallback(double progress, void *user_data):
pyProgressCallback = <object>user_data
if pyProgressCallback:
pyProgressCallback(float(progress))
cdef void tell(int &objCount, int &objHandled, void *callback):
cython.operator.preincrement(objHandled)
if callback != NULL:
pyCallback = <object>callback
# pyCallback(0.9 + 0.1 * (objHandled / float(objCount)))
cdef getNodes(OriginFile *originFile, pyCallback):
print "Origin file version: %g" % originFile.version()
spreadCount = originFile.spreadCount()
matrixCount = originFile.matrixCount()
functionCount = originFile.functionCount()
graphCount = originFile.graphCount()
noteCount = originFile.noteCount()
print spreadCount, matrixCount, functionCount, graphCount, noteCount
cdef int objectsCount = spreadCount + matrixCount + functionCount + graphCount + noteCount
cdef int objectsHandled = 0
spreads, matrices, functions, graphs, notes = [], [], [], [], []
for i in xrange(spreadCount):
spreads.append(makeSpreadSheet(originFile.spread(i)))
tell(objectsCount, objectsHandled, <void*>pyCallback)
matrices = [makeMatrix (originFile.matrix (i)) for i in xrange(matrixCount )]
objectsHandled += matrixCount
functions = [makeFunction (originFile.function(i)) for i in xrange(functionCount)]
objectsHandled += functionCount
for i in xrange(graphCount):
graphs.append(makeGraph(originFile.graph(i)))
tell(objectsCount, objectsHandled, <void*>pyCallback)
notes = [makeNote (originFile.note (i)) for i in xrange(noteCount )]
objectsHandled += noteCount
#spreads = [makeSpreadSheet(originFile.spread (i)) for i in xrange(spreadCount )]
#matrices = [makeMatrix (originFile.matrix (i)) for i in xrange(matrixCount )]
#functions = [makeFunction (originFile.function(i)) for i in xrange(functionCount)]
#graphs = [makeGraph (originFile.graph (i)) for i in xrange(graphCount )]
#notes = [makeNote (originFile.note (i)) for i in xrange(noteCount )]
#cdef const tree[objects.ProjectNode] *project = originFile.project()
#tree = makeTree(project)
return {'functions': functions,
'matrices': matrices,
'spreads': spreads,
'graphs': graphs,
'notes': notes}
def parseOriginFile(filename, pyCallback=None):
cdef OriginFile *originFile = new OriginFile(str.encode(filename))
cdef objects.ProgressCallback cCallback = cProgressCallback
cdef void *pyCallbackPtr = <void*>pyCallback
result = originFile.parse(cCallback, pyCallbackPtr) # FIXME: something is wrong here
return result and getNodes(originFile, pyCallback)