aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.BL/Helpers/SegmentsCsvHelper.cs
blob: 18dde341b4764220ebbd6cdbb47832b7b2ec5d09 (plain)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Builders;
using Tango.BL.DTO;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.CSV;
using Tango.PMR.Exports;

namespace Tango.BL.Helpers
{
    public static class SegmentsCsvHelper
    {
        private const double MAX_VOLUME = 200;

        public class SegmentsCsvResult
        {
            public Rml Rml { get; set; }
            public List<Segment> Segments { get; set; }

            public SegmentsCsvResult()
            {
                Segments = new List<Segment>();
            }
        }

        public class SegmentCsvModel
        {
            [CsvOrder(0)]
            public String Index { get; set; }

            [CsvOrder(1)]
            public String ThreadName { get; set; }

            [CsvOrder(2)]
            public String ColorSpace { get; set; }

            [CsvOrder(3)]
            public String Length { get; set; }

            [CsvOrder(4)]
            public String CatalogName1 { get; set; }

            [CsvOrder(5)]
            public String CatalogItem1 { get; set; }

            [CsvOrder(6)]
            public String Red1 { get; set; }
            [CsvOrder(7)]
            public String Green1 { get; set; }
            [CsvOrder(8)]
            public String Blue1 { get; set; }

            [CsvOrder(9)]
            public String L1 { get; set; }
            [CsvOrder(10)]
            public String A1 { get; set; }
            [CsvOrder(11)]
            public String B1 { get; set; }



            [CsvOrder(12)]
            public String Cyan1 { get; set; }
            [CsvOrder(13)]
            public String Magenta1 { get; set; }
            [CsvOrder(14)]
            public String Yellow1 { get; set; }
            [CsvOrder(15)]
            public String Black1 { get; set; }

            [CsvOrder(16)]
            public String CatalogName2 { get; set; }
            [CsvOrder(17)]
            public String CatalogItem2 { get; set; }

            [CsvOrder(18)]
            public String Red2 { get; set; }
            [CsvOrder(19)]
            public String Green2 { get; set; }
            [CsvOrder(20)]
            public String Blue2 { get; set; }

            [CsvOrder(21)]
            public String L2 { get; set; }
            [CsvOrder(22)]
            public String A2 { get; set; }
            [CsvOrder(23)]
            public String B2 { get; set; }


            [CsvOrder(24)]
            public String Cyan2 { get; set; }
            [CsvOrder(25)]
            public String Magenta2 { get; set; }
            [CsvOrder(26)]
            public String Yellow2 { get; set; }
            [CsvOrder(27)]
            public String Black2 { get; set; }

            public bool IsRgb2NullOrEqual()
            {
                if (String.IsNullOrWhiteSpace(Red2) || String.IsNullOrWhiteSpace(Green2) || String.IsNullOrWhiteSpace(Blue2)) return true;
                if (Red1 == Red2 && Green1 == Green2 && Blue1 == Blue2) return true;
                return false;
            }

            internal bool IsVolumeNullOrEqual()
            {
                if (String.IsNullOrWhiteSpace(Cyan2) || String.IsNullOrWhiteSpace(Magenta2) || String.IsNullOrWhiteSpace(Yellow2) || String.IsNullOrWhiteSpace(Black2)) return true;
                if (Cyan1 == Cyan2 && Magenta1 == Magenta2 && Yellow1 == Yellow2 && Black1 == Black2) return true;
                return false;
            }

            internal bool IsCatalogNameNullOrEqual()
            {
                if (String.IsNullOrWhiteSpace(CatalogName2) || String.IsNullOrEmpty(CatalogItem2)) return true;
                if (CatalogName1 == CatalogName2 && CatalogItem1 == CatalogItem2) return true;
                return false;
            }

            internal bool IsLab2NullOrEqual()
            {
                if (String.IsNullOrWhiteSpace(L2) || String.IsNullOrWhiteSpace(A2) || String.IsNullOrWhiteSpace(B2)) return true;
                if (L1 == L2 && A1 == A2 && B1 == B2) return true;
                return false;
            }
        }

        public static Task<SegmentsCsvResult> FromFile(String filePath, Machine machine, ObservablesContext context)
        {
            return Task.Factory.StartNew(() =>
            {
                List<SegmentCsvModel> rows = CsvFile.Read<SegmentCsvModel>(new CsvSource(filePath)).ToList();

                List<Segment> segments = new List<Segment>();

                var catalogs = new CatalogsCollectionBuilder(context).SetAll().WithGroups().WithItems().BuildList();
                var colorSpaces = context.ColorSpaces.ToList();

                if (machine.Configuration == null || machine.Configuration.IdsPacks == null || machine.Configuration.IdsPacks.Count == 0)
                {
                    machine = new MachineBuilder(context).Set(machine.Guid).WithConfiguration().Build();
                }

                String threadName = null;

                if (rows.Count > 0)
                {
                    threadName = rows.First().ThreadName;
                }

                Rml rml = null;

                if (threadName.IsNotNullOrEmpty())
                {
                    rml = context.Rmls.FirstOrDefault(x => x.Name == threadName || x.DisplayName == threadName);
                    if (rml == null) throw new InvalidOperationException($"Thread type '{threadName}' not found.");
                }

                if (machine.SiteGuid != null)
                {
                    if (!context.SitesRmls.Any(x => x.SiteGuid == machine.SiteGuid && x.RmlGuid == rml.Guid))
                    {
                        throw new InvalidOperationException($"Thread type '{threadName}' is not allowed for this machine's site.");
                    }
                }

                var idsPacks = machine.Configuration.NoneEmptyIdsPacks.ToList();

                var cyanIdsPack = idsPacks.FirstOrDefault(x => x.LiquidType.Type == LiquidTypes.Cyan);
                var magentaIdsPack = idsPacks.FirstOrDefault(x => x.LiquidType.Type == LiquidTypes.Magenta);
                var yellowIdsPack = idsPacks.FirstOrDefault(x => x.LiquidType.Type == LiquidTypes.Yellow);
                var blackIdsPack = idsPacks.FirstOrDefault(x => x.LiquidType.Type == LiquidTypes.Black);

                int lineCount = 0;

                foreach (var row in rows)
                {
                    lineCount++;

                    try
                    {
                        Segment segment = new Segment();
                        segment.Name = "Standard Segment";

                        double length;
                        if (!double.TryParse(row.Length, out length))
                        {
                            continue; //Ignore none indexed rows. Maybe there are many empty rows at the end to the document...
                        }

                        int segmentIndex;
                        if (!int.TryParse(row.Index, out segmentIndex))
                        {
                            throw new InvalidOperationException($"Value Index '{row.Index}' should be a number on line'{lineCount}'.");
                        }

                        segment.Length = length;
                        segment.SegmentIndex = segmentIndex;

                        ColorSpace colorSpace = colorSpaces.SingleOrDefault(x => x.Name == row.ColorSpace);

                        if (colorSpace == null) throw new InvalidOperationException($"Color space '{row.ColorSpace}' not found on line '{lineCount}'.");

                        BrushStop stop1 = new BrushStop();
                        stop1.StopIndex = 1;
                        stop1.ColorSpace = colorSpace;
                        stop1.OffsetPercent = 0;
                        stop1.Segment = segment;
                        segment.BrushStops.Add(stop1);

                        if (colorSpace.Space == ColorSpaces.RGB)
                        {
                            int red1;
                            if (!int.TryParse(row.Red1, out red1))
                            {
                                throw new InvalidOperationException($"Value Red1 '{row.Red1}' should be a number on line'{lineCount}'.");
                            }
                            stop1.Red = red1;
                            if (stop1.Red < 0 || stop1.Red > 255) throw new InvalidOperationException($"Value red1 '{row.Red1}' is out of range on line '{lineCount}'.");

                            int green1;
                            if (!int.TryParse(row.Green1, out green1))
                            {
                                throw new InvalidOperationException($"Value Green1 '{row.Green1}' should be a number on line'{lineCount}'.");
                            }
                            stop1.Green = green1;
                            if (stop1.Green < 0 || stop1.Green > 255) throw new InvalidOperationException($"Value green1 '{row.Green1}' is out of range on line '{lineCount}'.");

                            int blue1;
                            if (!int.TryParse(row.Blue1, out blue1))
                            {
                                throw new InvalidOperationException($"Value Blue1 '{row.Blue1}' should be a number on line'{lineCount}'.");
                            }
                            stop1.Blue = blue1;
                            if (stop1.Blue < 0 || stop1.Blue > 255) throw new InvalidOperationException($"Value blue1 '{row.Blue1}' is out of range on line '{lineCount}'.");

                            if (!row.IsRgb2NullOrEqual())
                            {
                                BrushStop stop2 = new BrushStop();
                                stop2.StopIndex = 2;
                                stop2.ColorSpace = stop1.ColorSpace;
                                stop2.OffsetPercent = 100;

                                int red2;
                                if (!int.TryParse(row.Red2, out red2))
                                {
                                    throw new InvalidOperationException($"Value Red2 '{row.Red2}' should be a number on line'{lineCount}'.");
                                }
                                stop2.Red = red2;
                                if (stop2.Red < 0 || stop2.Red > 255) throw new InvalidOperationException($"Value red2 '{row.Red2}' is out of range on line '{lineCount}'.");

                                int green2;
                                if (!int.TryParse(row.Green2, out green2))
                                {
                                    throw new InvalidOperationException($"Value Green2 '{row.Green2}' should be a number on line'{lineCount}'.");
                                }
                                stop2.Green = green2;
                                if (stop2.Green < 0 || stop2.Green > 255) throw new InvalidOperationException($"Value green2 '{row.Green2}' is out of range on line '{lineCount}'.");

                                int blue2;
                                if (!int.TryParse(row.Blue2, out blue2))
                                {
                                    throw new InvalidOperationException($"Value Blue2 '{row.Blue2}' should be a number on line'{lineCount}'.");
                                }
                                stop2.Blue = blue2;
                                if (stop2.Blue < 0 || stop2.Blue > 255) throw new InvalidOperationException($"Value blue2 '{row.Blue2}' is out of range on line '{lineCount}'.");

                                segment.BrushStops.Add(stop2);
                                stop2.Segment = segment;
                            }
                        }
                        else if (colorSpace.Space == ColorSpaces.Volume)
                        {
                            double cyan1;
                            if (!double.TryParse(row.Cyan1, out cyan1))
                            {
                                throw new InvalidOperationException($"Value Cyan1 '{row.Cyan1}' should be a number on line'{lineCount}.'!");
                            }
                            if (cyan1 < 0 || cyan1 > MAX_VOLUME) throw new InvalidOperationException($"Value Cyan1 '{row.Cyan1}' is out of range on line '{lineCount}.'!");
                            stop1.SetVolume(cyanIdsPack.PackIndex, cyan1);

                            double magenta1;
                            if (!double.TryParse(row.Magenta1, out magenta1))
                            {
                                throw new InvalidOperationException($"Value Magenta1 '{row.Magenta1}' should be a number on line'{lineCount}.'!");
                            }
                            if (magenta1 < 0 || magenta1 > MAX_VOLUME) throw new InvalidOperationException($"Value Magenta1 '{row.Magenta1}' is out of range on line '{lineCount}.'!");

                            stop1.SetVolume(magentaIdsPack.PackIndex, magenta1);

                            double yellow1 = double.Parse(row.Yellow1);
                            if (!double.TryParse(row.Yellow1, out yellow1))
                            {
                                throw new InvalidOperationException($"Value Yellow1 '{row.Yellow1}' should be a number on line'{lineCount}.'!");
                            }
                            if (yellow1 < 0 || yellow1 > MAX_VOLUME) throw new InvalidOperationException($"Value Yellow1 '{row.Yellow1}' is out of range on line '{lineCount}.'!");

                            stop1.SetVolume(yellowIdsPack.PackIndex, yellow1);

                            double black1 = double.Parse(row.Black1);
                            if (!double.TryParse(row.Black1, out black1))
                            {
                                throw new InvalidOperationException($"Value Black1 '{row.Black1}' should be a number on line'{lineCount}.'!");
                            }
                            if (black1 < 0 || black1 > MAX_VOLUME) throw new InvalidOperationException($"Value Black1 '{row.Black1}' is out of range on line '{lineCount}.'!");

                            stop1.SetVolume(blackIdsPack.PackIndex, black1);

                            if (!row.IsVolumeNullOrEqual())
                            {
                                BrushStop stop2 = new BrushStop();
                                stop2.StopIndex = 2;
                                stop2.ColorSpace = stop1.ColorSpace;
                                stop2.OffsetPercent = 100;

                                double cyan2;
                                if (!double.TryParse(row.Cyan2, out cyan2))
                                {
                                    throw new InvalidOperationException($"Value Cyan2 '{row.Cyan2}' should be a number on line'{lineCount}.'!");
                                }
                                if (cyan2 < 0 || cyan2 > MAX_VOLUME) throw new InvalidOperationException($"Value Cyan2 '{row.Cyan2}' is out of range on line '{lineCount}.'!");
                                stop2.SetVolume(cyanIdsPack.PackIndex, cyan2);

                                double magenta2;
                                if (!double.TryParse(row.Magenta2, out magenta2))
                                {
                                    throw new InvalidOperationException($"Value Magenta2 '{row.Magenta2}' should be a number on line'{lineCount}.'!");
                                }
                                if (magenta2 < 0 || magenta2 > MAX_VOLUME) throw new InvalidOperationException($"Value Magenta2 '{row.Magenta2}' is out of range on line '{lineCount}.'!");

                                stop2.SetVolume(magentaIdsPack.PackIndex, magenta2);

                                double yellow2 = double.Parse(row.Yellow2);
                                if (!double.TryParse(row.Yellow2, out yellow2))
                                {
                                    throw new InvalidOperationException($"Value Yellow2 '{row.Yellow2}' should be a number on line'{lineCount}.'!");
                                }
                                if (yellow2 < 0 || yellow2 > MAX_VOLUME) throw new InvalidOperationException($"Value Yellow2 '{row.Yellow2}' is out of range on line '{lineCount}.'!");

                                stop2.SetVolume(yellowIdsPack.PackIndex, yellow2);

                                double black2 = double.Parse(row.Black2);
                                if (!double.TryParse(row.Black2, out black2))
                                {
                                    throw new InvalidOperationException($"Value Black2 '{row.Black2}' should be a number on line'{lineCount}.'!");
                                }
                                if (black2 < 0 || black2 > MAX_VOLUME) throw new InvalidOperationException($"Value Black2 '{row.Black2}' is out of range on line '{lineCount}.'!");

                                stop2.SetVolume(blackIdsPack.PackIndex, black2);

                                segment.BrushStops.Add(stop2);
                                stop2.Segment = segment;
                            }
                        }
                        else if (colorSpace.Space == ColorSpaces.Catalog)
                        {
                            var catalog = catalogs.FirstOrDefault(x => x.Name == row.CatalogName1);
                            if (catalog == null)
                            {
                                throw new InvalidOperationException($"Catalog '{row.CatalogName1}' not found on line '{lineCount}'.");
                            }

                            if (machine.SiteGuid != null)
                            {
                                if (!context.SitesCatalogs.Any(x => x.SiteGuid == machine.SiteGuid && x.ColorCatalogGuid == catalog.Guid))
                                {
                                    throw new InvalidOperationException($"Catalog '{catalog.Name}' is not assigned for this machine's site.");
                                }
                            }

                            var item = catalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).FirstOrDefault(x => x.Name == row.CatalogItem1);
                            if (item == null)
                            {
                                throw new InvalidOperationException($"Catalog item '{row.CatalogItem1}' not found on catalog '{catalog.Name}' on line '{lineCount}'.");
                            }

                            stop1.ColorCatalog = catalog;
                            stop1.ColorCatalogsItem = item;
                            stop1.Color = item.Color;
                            if (!row.IsCatalogNameNullOrEqual())
                            {
                                var catalog2 = catalogs.FirstOrDefault(x => x.Name == row.CatalogName2);
                                if (catalog2 == null)
                                {
                                    throw new InvalidOperationException($"Catalog '{row.CatalogName2}' not found on line '{lineCount}'.");
                                }

                                if (machine.SiteGuid != null)
                                {
                                    if (!context.SitesCatalogs.Any(x => x.SiteGuid == machine.SiteGuid && x.ColorCatalogGuid == catalog2.Guid))
                                    {
                                        throw new InvalidOperationException($"Catalog '{catalog2.Name}' is not assigned for this machine's site.");
                                    }
                                }

                                var item2 = catalog2.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).FirstOrDefault(x => x.Name == row.CatalogItem2);
                                if (item2 == null)
                                {
                                    throw new InvalidOperationException($"Catalog item '{row.CatalogItem2}' not found on catalog '{catalog2.Name}' on line '{lineCount}'.");
                                }
                                BrushStop stop2 = new BrushStop();
                                stop2.StopIndex = 2;
                                stop2.ColorSpace = stop1.ColorSpace;
                                stop2.ColorCatalog = catalog2;
                                stop2.ColorCatalogsItem = item2;
                                stop2.Color = item2.Color;
                                stop2.OffsetPercent = 100;
                                segment.BrushStops.Add(stop2);
                                stop2.Segment = segment;
                            }
                        }
                        else if (colorSpace.Space == ColorSpaces.LAB)
                        {
                            double number;
                            if (!double.TryParse(row.L1, out number))
                                throw new InvalidOperationException($"Value L1 '{row.L1}' should be a number on line'{lineCount}'.");
                            stop1.L = number;
                            if (stop1.L < 0 || stop1.L > 100) throw new InvalidOperationException($"Value L1 '{row.L1}' is out of range on line '{lineCount}'.");

                            if (!double.TryParse(row.A1, out number))
                                throw new InvalidOperationException($"Value A1 '{row.A1}' should be a number on line'{lineCount}'.");
                            stop1.A = number;
                            if (stop1.A < -128 || stop1.A > 128) throw new InvalidOperationException($"Value A1 '{row.A1}' is out of range on line '{lineCount}'.");

                            if (!double.TryParse(row.B1, out number))
                                throw new InvalidOperationException($"Value B1 '{row.B1}' should be a number on line'{lineCount}'.");
                            stop1.B = number;
                            if (stop1.B < -128 || stop1.B > 128) throw new InvalidOperationException($"Value B1 '{row.B1}' is out of range on line '{lineCount}'.");
                            if (!row.IsLab2NullOrEqual())
                            {
                                BrushStop stop2 = new BrushStop();
                                stop2.StopIndex = 2;
                                stop2.ColorSpace = stop1.ColorSpace;
                                stop2.OffsetPercent = 100;

                                double l2;
                                if (!double.TryParse(row.L2, out l2))
                                    throw new InvalidOperationException($"Value L2 '{row.L2}' should be a number on line'{lineCount}'.");
                                stop2.L = l2;
                                if (stop2.L < 0 || stop2.L > 100) throw new InvalidOperationException($"Value L2 '{row.L2}' is out of range on line '{lineCount}'.");

                                double a2;
                                if (!double.TryParse(row.A2, out a2))
                                    throw new InvalidOperationException($"Value A2 '{row.A2}' should be a number on line'{lineCount}'.");
                                stop2.A = a2;
                                if (stop2.A < -128 || stop2.A > 128) throw new InvalidOperationException($"Value A2 '{row.A2}' is out of range on line '{lineCount}'.");

                                double b2;
                                if (!double.TryParse(row.B2, out b2))
                                    throw new InvalidOperationException($"Value B2 '{row.B2}' should be a number on line'{lineCount}'.");
                                stop2.B = b2;
                                if (stop2.B < -128 || stop2.B > 128) throw new InvalidOperationException($"Value B2 '{row.B2}' is out of range on line '{lineCount}'.");

                                segment.BrushStops.Add(stop2);
                                stop2.Segment = segment;
                            }
                        }
                        segments.Add(segment);
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidOperationException($"Error parsing file on line {lineCount}.\n{ex.Message}");
                    }
                }

                return new SegmentsCsvResult()
                {
                    Segments = segments,
                    Rml = rml
                };
            });
        }

        static async void ToFile(String filePath, List<Segment> segments)
        {
            await Task.Factory.StartNew(() =>
            {
                SegmentCsvModel model = new SegmentCsvModel();
                List<string> columnNames = model.GetType().GetProperties().Select(x => x.Name).ToList();
                CsvFile<SegmentCsvModel> csvFile = new CsvFile<SegmentCsvModel>(new CsvDestination(filePath), new CsvDefinition()
                {
                    Columns = columnNames
                });
                foreach (var segment in segments)
                {
                    SegmentCsvModel csvmodel = new SegmentCsvModel();
                    csvmodel.Index = segment.SegmentIndex.ToString();
                    csvmodel.Length = segment.Length.ToString();
                    if (segment.BrushStops.Count > 2) throw new InvalidOperationException($"Cannot save more than two brush stops!");
                    //save first brush stop
                    if (segment.BrushStops.Count > 0)
                    {
                        var brushStop1 = segment.BrushStops[0];
                        csvmodel.ColorSpace = brushStop1.ColorSpace.Name;
                        if (csvmodel.ColorSpace == ColorSpaces.RGB.ToDescription())
                        {
                            csvmodel.Red1 = brushStop1.Red.ToString();
                            csvmodel.Green1 = brushStop1.Green.ToString();
                            csvmodel.Blue1 = brushStop1.Blue.ToString();
                        }
                        else if (csvmodel.ColorSpace == ColorSpaces.Volume.ToDescription())
                        {
                            csvmodel.Cyan1 = brushStop1.GetVolume(LiquidTypes.Cyan).ToString();
                            csvmodel.Magenta1 = brushStop1.GetVolume(LiquidTypes.Magenta).ToString();
                            csvmodel.Yellow1 = brushStop1.GetVolume(LiquidTypes.Yellow).ToString();
                            csvmodel.Black1 = brushStop1.GetVolume(LiquidTypes.Black).ToString();
                        }
                        else if (csvmodel.ColorSpace == ColorSpaces.Catalog.ToDescription())
                        {
                            csvmodel.CatalogName1 = brushStop1.ColorCatalog.Name;
                            csvmodel.CatalogItem1 = brushStop1.ColorCatalogsItem.Name;
                        }
                        else if (csvmodel.ColorSpace == ColorSpaces.LAB.ToDescription())
                        {
                            csvmodel.L1 = brushStop1.L.ToString();
                            csvmodel.A1 = brushStop1.A.ToString();
                            csvmodel.B1 = brushStop1.B.ToString();
                        }
                    }
                    if (segment.BrushStops.Count > 1)
                    {
                        var brushStop2 = segment.BrushStops[1];
                        if (csvmodel.ColorSpace == ColorSpaces.RGB.ToDescription())
                        {
                            csvmodel.Red2 = brushStop2.Red.ToString();
                            csvmodel.Green2 = brushStop2.Green.ToString();
                            csvmodel.Blue2 = brushStop2.Blue.ToString();
                        }
                        else if (csvmodel.ColorSpace == ColorSpaces.Volume.ToDescription())
                        {
                            csvmodel.Cyan2 = brushStop2.GetVolume(LiquidTypes.Cyan).ToString();
                            csvmodel.Magenta2 = brushStop2.GetVolume(LiquidTypes.Magenta).ToString();
                            csvmodel.Yellow2 = brushStop2.GetVolume(LiquidTypes.Yellow).ToString();
                            csvmodel.Black2 = brushStop2.GetVolume(LiquidTypes.Black).ToString();
                        }
                        else if (csvmodel.ColorSpace == ColorSpaces.Catalog.ToDescription())
                        {
                            csvmodel.CatalogName2 = brushStop2.ColorCatalog.Name;
                            csvmodel.CatalogItem2 = brushStop2.ColorCatalogsItem.Name;
                        }
                        else if (csvmodel.ColorSpace == ColorSpaces.LAB.ToDescription())
                        {
                            csvmodel.L2 = brushStop2.L.ToString();
                            csvmodel.A2 = brushStop2.A.ToString();
                            csvmodel.B2 = brushStop2.B.ToString();
                        }
                    }

                    csvFile.Append(csvmodel);
                }
            });
        }
    }
}