-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.h
716 lines (677 loc) · 30.8 KB
/
main.h
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
/*
* Copyright (c) 2022-2025 plc-user
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef MAIN_H
#define MAIN_H
#include <iostream> // for IO-Operations
#include <fstream> // for file-Operations
#include <sstream> // for String-Streams
#include <cstdint> // int8_t, ...
#include <string> // we handle strings here
#include <getopt.h> // for Commandline-Parameters
#include <filesystem> // for exe-filename
#include <list> // for list of UUIDs
// project-includes
#include "inc/pugixml/pugixml.hpp"
#include "inc/helpers.h"
#include "inc/elements.h"
// =============================================================================
// global variables
// =============================================================================
const std::string sVersion = "v0.5.3";
// the element-file to process:
static std::string ElementFile = "";
static std::string SVGFile = "SampleFile.svg";
static std::string ElementFileScaled = "SampleFile.SCALED.elmt";
// we need a "Pugi-Node":
static pugi::xml_node node;
// some Bits for control
static bool xIsElmtFile = false;
static bool xIsDirFile = false;
static bool xPrintHelp = false;
static bool xReadFromStdIn = false;
static bool xPrintToStdOut = false;
static bool xCreateSVG = false;
static bool xCreateELMT = true;
static bool xStopWithError = false;
static bool xScaleElement = true;
static bool xMoveElement = false;
static bool xRemoveAllTerminals = false;
static bool xOverwriteOriginal = false;
static bool xFlipHor = false;
static bool xFlipVert = false;
static bool xRotate90 = false;
// to find out, if we need to renew UUIDs for "dynamic_text" or "terminal":
static std::list <std::string> lsUUIDsDynTexts;
static std::list <std::string> lsUUIDsTerminals;
static bool xTerminalsUUIDsUnique = true;
static bool xDynTextsUUIDsUnique = true;
// max. Number of decimals:
static size_t decimals = 2; // number of decimals for floating-point values
static double MinLineLength = 0.025; //
static double scaleX = 1.0;
static double scaleY = 1.0;
static double moveX = 0.0;
static double moveY = 0.0;
//
// --- function-prototypes -----------------------------------------------------
//
int parseCommandline(int argc, char *argv[]);
void PrintHelp(const std::string &s, const std::string &v);
bool CheckUUIDs(void);
void ProcessDirFile(pugi::xml_node);
void ProcessElement(pugi::xml_node);
std::string ToSVG(pugi::xml_node);
// the possible Commandlineparameters:
static const char cOptions[] = "f:hioF:x:y:X:Y:d:";
static struct option long_options[]={
{"file",required_argument,nullptr,'f'},
{"help",no_argument,nullptr,'h'},
{"stdin",no_argument,nullptr,'i'},
{"stdout",no_argument,nullptr,'o'},
{"factor",required_argument,nullptr,'F'},
{"factorx",required_argument,nullptr,'x'},
{"factory",required_argument,nullptr,'y'},
{"movex",required_argument,nullptr,'X'},
{"movey",required_argument,nullptr,'Y'},
{"decimals",required_argument,nullptr,'d'},
{"RemoveAllTerminals",no_argument,nullptr,1000}, // "long-opt" only!!!
{"FlipHorizontal",no_argument,nullptr,1001}, // "long-opt" only!!!
{"FlipVertical",no_argument,nullptr,1002}, // "long-opt" only!!!
{"OverwriteOriginal",no_argument,nullptr,1003}, // "long-opt" only!!!
{"toSVG",no_argument,nullptr,1004}, // "long-opt" only!!!
{"Rot90",no_argument,nullptr,1005}, // "long-opt" only!!!
{0,0,0,0}
};
/******************************************************************************/
int parseCommandline(int argc, char *argv[]) {
int c;
int option_index = 12345;
std::string sTmp = "";
while ((c=getopt_long(argc,argv,cOptions,long_options,&option_index))!=-1) {
if (_DEBUG_) std::cerr << "long-opt-name: " << long_options[option_index].name << std::endl;
switch(c) {
case 0:
if (long_options[option_index].flag != 0){
if (_DEBUG_)
std::cerr << "(long_options[option_index].flag != 0)\n";
break;
}
case 1000:
if (std::string(long_options[option_index].name) == "RemoveAllTerminals"){
if (_DEBUG_)
std::cerr << "Remove all terminals from Element!\n";
xRemoveAllTerminals = true;
}
break;
case 1001:
if (std::string(long_options[option_index].name) == "FlipHorizontal"){
if (_DEBUG_)
std::cerr << "Flip Element horizontally!\n";
xFlipHor = true;
}
break;
case 1002:
if (std::string(long_options[option_index].name) == "FlipVertical"){
if (_DEBUG_)
std::cerr << "Flip Element vertically!\n";
xFlipVert = true;
}
break;
case 1003:
if (std::string(long_options[option_index].name) == "OverwriteOriginal"){
if (_DEBUG_)
std::cerr << "Overwrite original file with scaled data!\n";
xOverwriteOriginal = true;
}
break;
case 1004:
if (std::string(long_options[option_index].name) == "toSVG"){
if (_DEBUG_)
std::cerr << "create SVG-data from Element-File\n";
xCreateSVG = true;
xCreateELMT = false; // entoder-weder ... Beides gibt's nicht!
}
break;
case 1005:
if (std::string(long_options[option_index].name) == "Rot90"){
if (_DEBUG_)
std::cerr << "rotate element clockwise by 90 degree\n";
xRotate90 = true;
}
break;
case 'd':
sTmp = std::string(optarg);
CheckForDoubleString(sTmp);
if ((sTmp == "WontWork") || (stod(std::string(sTmp)) < 0.0)) {
std::cerr << "could not convert \"" << optarg << "\" to valid number!" << std::endl;
xStopWithError = true;
} else {
decimals = size_t(std::floor(stod(std::string(optarg))));
if (_DEBUG_)
std::cerr << "set number of decimals to " << decimals << "\n";
MinLineLength = 1.5;
for (uint8_t i=0; i < decimals; i++) { MinLineLength /= 10.0; }
}
break;
case 'i':
if (_DEBUG_)
std::cerr << "Read from STDIN\n";
xReadFromStdIn = true;
xPrintToStdOut = true;
break;
case 'o':
if (_DEBUG_)
std::cerr << "Output to STDOUT\n";
xPrintToStdOut = true;
break;
case 'h':
if (_DEBUG_)
std::cerr << "Help wanted...\n";
xPrintHelp = true;
break;
case 'f':
if (_DEBUG_)
std::cerr << "use filename \"" << optarg << "\"\n";
ElementFile = std::string(optarg);
break;
case 'F':
xScaleElement = true;
sTmp = std::string(optarg);
CheckForDoubleString(sTmp);
if (sTmp == "WontWork"){
std::cerr << "could not convert \"" << optarg << "\" to float!" << std::endl;
xStopWithError = true;
} else {
if (_DEBUG_) std::cerr << "Factor: " << sTmp << std::endl;
scaleX = stod(sTmp);
scaleY = scaleX;
if (scaleX < 0.01) {
std::cerr << "scaling-factor negative or too small: " << sTmp << std::endl;
xStopWithError = true;
}
}
break;
case 'x':
xScaleElement = true;
sTmp = std::string(optarg);
CheckForDoubleString(sTmp);
if (sTmp == "WontWork"){
std::cerr << "could not convert \"" << optarg << "\" to float!" << std::endl;
xStopWithError = true;
} else {
if (_DEBUG_) std::cerr << "FactorX: " << sTmp << std::endl;
scaleX = stod(sTmp);
if (scaleX < 0.01) {
std::cerr << "scaling-factor negative or too small: " << sTmp << std::endl;
xStopWithError = true;
}
}
break;
case 'y':
xScaleElement = true;
sTmp = std::string(optarg);
CheckForDoubleString(sTmp);
if (sTmp == "WontWork"){
std::cerr << "could not convert \"" << optarg << "\" to float!" << std::endl;
xStopWithError = true;
} else {
if (_DEBUG_) std::cerr << "FactorY: " << sTmp << std::endl;
scaleY = stod(sTmp);
if (scaleY < 0.01) {
std::cerr << "scaling-factor negative or too small: " << sTmp << std::endl;
xStopWithError = true;
}
}
break;
case 'X':
xMoveElement = true;
sTmp = std::string(optarg);
CheckForDoubleString(sTmp);
if (sTmp == "WontWork"){
std::cerr << "could not convert \"" << optarg << "\" to float!" << std::endl;
xStopWithError = true;
} else {
if (_DEBUG_) std::cerr << "MoveX: " << sTmp << std::endl;
moveX = stod(sTmp);
if (std::abs(moveX) < 0.01) {
std::cerr << "delta-value too small: " << sTmp << std::endl;
xStopWithError = true;
}
}
break;
case 'Y':
xMoveElement = true;
sTmp = std::string(optarg);
CheckForDoubleString(sTmp);
if (sTmp == "WontWork"){
std::cerr << "could not convert \"" << optarg << "\" to float!" << std::endl;
xStopWithError = true;
} else {
if (_DEBUG_) std::cerr << "MoveY: " << sTmp << std::endl;
moveY = stod(sTmp);
if (std::abs(moveY) < 0.01) {
std::cerr << "delta-value too small: " << sTmp << std::endl;
xStopWithError = true;
}
}
break;
case '?':
std::cerr << " * * * there were non-handled option(s)!"<< std::endl;
xStopWithError = true;
break;
}
}
if (_DEBUG_) std::cerr << "optind=" << optind << "; argc="<<argc << std::endl;
// are there "non-option-Arguments"?
int iDiff = argc - optind;
if (optind < argc) {
if (_DEBUG_) std::cerr << "non-option ARGV-elements:" << std::endl;
while (optind < argc) {
if (_DEBUG_) std::cerr << optind << ": " << argv[optind] << std::endl;
optind++;
}
if (_DEBUG_) std::cerr << std::endl;
}
// return number of non-option-arguments:
return iDiff;
}
/******************************************************************************/
/******************************************************************************/
void PrintHelp(const std::string &s, const std::string &v){
std::stringstream ss;
ss << std::filesystem::path(s).filename().stem(); // without extension
std::string sExeName = ss.str();
std::cout << std::endl
<< sExeName << " version " << v << " needs arguments!" << std::endl
<< std::endl
<< "usage:" << std::endl
<< sExeName << " [options] FILENAME" << std::endl
<< std::endl
<< " -i | --stdin input-data is read from stdin, a given filename is \n"
<< " ignored and scaled element will be written to stdout\n"
<< " -o | --stdout output will be written to stdout \n"
<< " -F VALUE or \n"
<< " --factor VALUE factor for both directions (x, y, rx, height, ...) \n"
<< " -x VALUE or \n"
<< " --factorx VALUE factor for x-values (x, rx, width, ...) \n"
<< " -y VALUE or \n"
<< " --factory VALUE factor for y-values (y, ry, height, ...) \n"
<< " -X VALUE or \n"
<< " --movex VALUE move in x-direction after scaling \n"
<< " -Y VALUE or \n"
<< " --movey VALUE move in y-direction after scaling \n"
<< " -f FILENAME or \n"
<< " --file FILENAME the file that will be used \n"
<< " -d VALUE or \n"
<< " --decimals VALUE number of decimals for float-values in output \n"
<< " -h | --help show this help \n"
<< std::endl
<< " there are also some \"long-opt\"-only options: \n"
<< std::endl
<< " \"--toSVG\" creates data for a Scalable-Vector-Graphic \n"
<< " instead of a QElectroTech-element \n"
<< " \"--RemoveAllTerminals\" removes all terminals from the element \n"
<< " (useful for front-views or \"thumbnails\") \n"
<< " \"--FlipHorizontal\" flips all graphical elements horizontally \n"
<< " (useful during creation of elements) \n"
<< " \"--FlipVertical\" flips all graphical elements vertically \n"
<< " (useful during creation of elements) \n"
<< " \"--Rot90\" rotate element clockwise by 90 degree \n"
<< " (useful during creation of elements) \n"
<< " \"--OverwriteOriginal\" the original file is replaced by scaled one \n"
<< " (CAUTION: Be careful with this option!) \n"
<< std::endl
<< "As always with free software: Use it at your own risk! \n\n";
}
/******************************************************************************/
/******************************************************************************/
bool CheckUUIDs(void) {
uint64_t u64DynTextsOrg = lsUUIDsDynTexts.size();
lsUUIDsDynTexts.sort();
lsUUIDsDynTexts.unique();
xDynTextsUUIDsUnique = (lsUUIDsDynTexts.size() == u64DynTextsOrg);
if (xDynTextsUUIDsUnique == false) {
std::cerr << " * * UUIDs of dynamic_texts are not unique: Create new ones! * *\n";
}
uint64_t u64TerminalsOrg = lsUUIDsTerminals.size();
lsUUIDsTerminals.sort();
lsUUIDsTerminals.unique();
xTerminalsUUIDsUnique = (lsUUIDsTerminals.size() == u64TerminalsOrg);
if (xTerminalsUUIDsUnique == false) {
std::cerr << " * * UUIDs of terminals are not unique: Create new ones! * *\n";
}
return (xDynTextsUUIDsUnique && xTerminalsUUIDsUnique);
}
/******************************************************************************/
/******************************************************************************/
void ProcessDirFile(pugi::xml_node doc) {
NamesList Namen;
Namen.ReadFromPugiNode(doc.child("qet-directory").child("names"));
Namen.WriteToPugiNode(doc.child("qet-directory").child("names"));
//
}
/******************************************************************************/
/******************************************************************************/
void ProcessElement(pugi::xml_node doc) {
RectMinMax ElmtMinMax; // for Re-Calc of DefinitionLine!
// create or renew element's uuid:
if (!(doc.child("definition").child("uuid"))) {
if (_DEBUG_) std::cerr << "Erstelle Element-UUID!\n" ;
doc.child("definition").prepend_child("uuid");
doc.child("definition").child("uuid").append_attribute("uuid").set_value(("{" + CreateUUID(false) + "}"));
} else {
if (_DEBUG_) std::cerr << "Aktualisiere vorhandene Element-UUID!\n" ;
doc.child("definition").child("uuid").attribute("uuid").set_value(("{" + CreateUUID(false) + "}"));
}
// wenn die Anschlüsse alle weg sollen...
if (xRemoveAllTerminals==true) {
if (_DEBUG_) std::cerr << "change \"link_type\" to \"thumbnail\"" << std::endl;
doc.child("definition").attribute("link_type").set_value("thumbnail");
while(doc.child("definition").child("description").remove_child("terminal"));
}
// wir lesen die Bauteil-Namen, um nach Sprache zu sortieren
NamesList Namen;
Namen.ReadFromPugiNode(doc.child("definition").child("names"));
Namen.WriteToPugiNode(doc.child("definition").child("names"));
// wir lesen die Bauteil-Informationen, um nach Namen zu sortieren
ElementInfo EiList;
EiList.ReadFromPugiNode(doc.child("definition").child("elementInformations"));
EiList.WriteToPugiNode(doc.child("definition").child("elementInformations"));
// ein wenig Werbung in eigener Sache: Programmnamen hinzufügen:
AuthorInfo AInfo;
AInfo.UpdatePugiNode(doc.child("definition").child("informations"));
// in einer Schleife die Elemente bearbeiten - wir starten hier:
pugi::xml_node node = doc.child("definition").child("description").first_child();
// ... in a loop all parts
for (; node; node = node.next_sibling())
{
if ((std::string(node.name())) == "rect") {
ElmtRect rect;
rect.Clear();
rect.ReadFromPugiNode(node);
if (xFlipHor) rect.Flip();
if (xFlipVert) rect.Mirror();
if (xRotate90) rect.Rot90();
rect.Scale(scaleX, scaleY);
if (xMoveElement) rect.Move(moveX, moveY);
rect.WriteToPugiNode(node, decimals);
ElmtMinMax.addx(rect.GetX());
ElmtMinMax.addx(rect.GetX()+rect.GetWidth());
ElmtMinMax.addy(rect.GetY());
ElmtMinMax.addy(rect.GetY()+rect.GetHeight());
}
if ((std::string(node.name())) == "arc") {
ElmtArc arc;
arc.Clear();
arc.ReadFromPugiNode(node);
if (xFlipHor) arc.Flip();
if (xFlipVert) arc.Mirror();
if (xRotate90) arc.Rot90();
arc.Scale(scaleX, scaleY);
if (xMoveElement) arc.Move(moveX, moveY);
arc.Normalize();
arc.WriteToPugiNode(node, decimals);
ElmtMinMax.addx(arc.GetMinX());
ElmtMinMax.addx(arc.GetMaxX());
ElmtMinMax.addy(arc.GetMinY());
ElmtMinMax.addy(arc.GetMaxY());
}
if (((std::string(node.name())) == "ellipse") || ((std::string(node.name())) == "circle")) {
ElmtEllipse elli;
elli.Clear();
elli.ReadFromPugiNode(node);
if (xFlipHor) elli.Flip();
if (xFlipVert) elli.Mirror();
if (xRotate90) elli.Rot90();
elli.Scale(scaleX, scaleY);
if (xMoveElement) elli.Move(moveX, moveY);
elli.WriteToPugiNode(node, decimals);
ElmtMinMax.addx(elli.GetX());
ElmtMinMax.addx(elli.GetX()+elli.GetWidth());
ElmtMinMax.addy(elli.GetY());
ElmtMinMax.addy(elli.GetY()+elli.GetHeight());
node.set_name("ellipse");
}
if ((std::string(node.name())) == "text") {
ElmtText text;
text.ReadFromPugiNode(node);
if (xFlipHor) text.Flip();
if (xFlipVert) text.Mirror();
if (xRotate90) text.Rot90();
text.Scale(scaleX, scaleY);
if (xMoveElement) text.Move(moveX, moveY);
text.WriteToPugiNode(node, decimals);
if (!((text.GetText() == "") || (text.GetText() == "_"))) {
ElmtMinMax.addx(text.GetX()-text.GetSize());
ElmtMinMax.addx(text.GetX()+text.GetSize());
ElmtMinMax.addy(text.GetY()-text.GetSize());
ElmtMinMax.addy(text.GetY()+text.GetSize());
}
}
if ((std::string(node.name())) == "terminal") {
ElmtTerminal term;
term.ReadFromPugiNode(node);
if (xFlipHor) term.Flip();
if (xFlipVert) term.Mirror();
if (xRotate90) term.Rot90();
term.Scale(scaleX, scaleY);
if (xMoveElement) term.Move(moveX, moveY);
if (node.attribute("uuid")) {
lsUUIDsTerminals.push_back(node.attribute("uuid").as_string());
}
term.WriteToPugiNode(node);
ElmtMinMax.addx(term.GetX()-5);
ElmtMinMax.addx(term.GetX()+5);
ElmtMinMax.addy(term.GetY()+5);
ElmtMinMax.addy(term.GetY()-5);
}
if ((std::string(node.name())) == "input") {
ElmtInput input;
input.ConvertToDynText(node);
}
if ((std::string(node.name())) == "dynamic_text") {
ElmtDynText dyntext;
dyntext.ReadFromPugiNode(node);
if (xFlipHor) dyntext.Flip();
if (xFlipVert) dyntext.Mirror();
if (xRotate90) dyntext.Rot90();
dyntext.Scale(scaleX, scaleY);
if (xMoveElement) dyntext.Move(moveX, moveY);
if (node.attribute("uuid")) {
lsUUIDsDynTexts.push_back(node.attribute("uuid").as_string());
}
dyntext.WriteToPugiNode(node, decimals);
if (!((dyntext.GetText() == "") || (dyntext.GetText() == "_"))) {
ElmtMinMax.addx(dyntext.GetX()-dyntext.GetSize());
ElmtMinMax.addx(dyntext.GetX()+dyntext.GetSize());
ElmtMinMax.addy(dyntext.GetY()-dyntext.GetSize());
ElmtMinMax.addy(dyntext.GetY()+dyntext.GetSize());
}
}
if ((std::string(node.name())) == "line") {
ElmtLine line;
if (line.ReadFromPugiNode(node) == true) {
if (xFlipHor) line.Flip();
if (xFlipVert) line.Mirror();
if (xRotate90) line.Rot90();
line.Scale(scaleX, scaleY);
if (xMoveElement) line.Move(moveX, moveY);
line.CleanUp(node, MinLineLength);
line.WriteToPugiNode(node, decimals);
if (line.CheckIndex(node.name()) == true) {
ElmtMinMax.addx(line.GetMinX());
ElmtMinMax.addx(line.GetMaxX());
ElmtMinMax.addy(line.GetMinY());
ElmtMinMax.addy(line.GetMaxY());
} else { node.set_name("LINE_NodeToDelete"); }
} else {
// Invalid line will be ignored and deleted later!
node.set_name("LINE_NodeToDelete");
}
}
if ((std::string(node.name())) == "polygon") {
ElmtPolygon poly;
if (poly.ReadFromPugiNode(node) == true) {
if (xFlipHor) poly.Flip();
if (xFlipVert) poly.Mirror();
if (xRotate90) poly.Rot90();
poly.Scale(scaleX, scaleY);
if (xMoveElement) poly.Move(moveX, moveY);
poly.CleanUp(node, MinLineLength);
poly.WriteToPugiNode(node, decimals);
if (poly.CheckIndex(node.name()) == true) {
ElmtMinMax.addx(poly.GetMinX());
ElmtMinMax.addx(poly.GetMaxX());
ElmtMinMax.addy(poly.GetMinY());
ElmtMinMax.addy(poly.GetMaxY());
} else { node.set_name("POLYGON_NodeToDelete"); }
} else {
// Invalid polygon will be ignored and deleted later!
node.set_name("POLYGON_NodeToDelete");
}
}
}
// Cleanup the QET-Element by removing invalid parts:
while(doc.child("definition").child("description").remove_child("LINE_NodeToDelete"));
while(doc.child("definition").child("description").remove_child("POLYGON_NodeToDelete"));
// die UUIDs prüfen, ob sie denn wirklich "unique" sind:
if (CheckUUIDs() == false) {
// in einer Schleife die UUIDs der Elemente bearbeiten:
node = doc.child("definition").child("description").first_child();
for (; node; node = node.next_sibling())
{
if (((std::string(node.name())) == "terminal") && (xTerminalsUUIDsUnique == false)) {
std::string uuid = "{" + CreateUUID(false) + "}";
node.attribute("uuid").set_value(uuid);
}
if (((std::string(node.name())) == "dynamic_text") && (xDynTextsUUIDsUnique == false)) {
std::string uuid = "{" + CreateUUID(false) + "}";
node.attribute("uuid").set_value(uuid);
}
}
}
// die Listen der UUIDs werden nicht mehr benötigt: leeren!
lsUUIDsDynTexts.clear();
lsUUIDsTerminals.clear();
// die definitionLine muss auf jeden Fall angepasst werden:
DefinitionLine defline;
defline.ReadFromPugiNode(doc.child("definition"));
defline.ReCalc(ElmtMinMax);
defline.WriteToPugiNode(doc.child("definition"));
}
/******************************************************************************/
/******************************************************************************/
std::string ToSVG(pugi::xml_node node) {
std::string s = "";
s += "<svg xmlns=\"http://www.w3.org/2000/svg\"\n";
s += " xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n";
node = node.child("definition");
// in der DefinitionLine stehen die Abmessungen drin:
DefinitionLine DefLine;
DefLine.ReadFromPugiNode(node);
// Daten für Abmessungen aus Definition-Line:
s += " width=\"" + std::to_string(DefLine.Getwidth());
s += "\" height=\"" + std::to_string(DefLine.Getheight()) + "\">\n";
// hier die Definition von "terminal", falls im Element vorhanden:
if (node.child("description").child("terminal")) {
s += " <defs>\n";
s += " <g id=\"terminal\" stroke-width=\"1\" stroke-linecap=\"square\">\n";
s += " <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"4\" stroke=\"#0000FF\" />\n";
s += " <line x1=\"0\" y1=\"1\" x2=\"0\" y2=\"4\" stroke=\"#FF0000\" />\n";
s += " </g>\n";
s += " </defs>\n";
}
// dann weiter mit der Gruppierung der Elemente inklusive Verschiebung mit Daten aus Definition-Line:
// da drin auch die allgemeingültige Anweisung für "stroke-linecap=(butt|round|square)" bei QET: square
s += " <g transform=\"translate(" + std::to_string(DefLine.Gethotspot_x());
s += "," + std::to_string(DefLine.Gethotspot_y()) + ")\" stroke-linecap=\"square\">\n";
// Hier nun die Schleife für die grafischen Elemente
// edit the graphical elements of the QET-Element:
node = node.child("description").first_child();
// ... in a loop
for (; node; node = node.next_sibling())
{ //std::cout << ".";
if ((std::string(node.name())) == "rect") {
ElmtRect rect;
rect.Clear();
rect.ReadFromPugiNode(node);
s += " "; s += rect.AsSVGstring(decimals); s += "\n";
}
if ((std::string(node.name())) == "text") {
ElmtText text;
text.Clear();
text.ReadFromPugiNode(node);
s += " "; s += text.AsSVGstring(decimals); s += "\n";
}
if ((std::string(node.name())) == "dynamic_text") {
ElmtDynText dyntext;
dyntext.Clear();
dyntext.ReadFromPugiNode(node);
s += " "; s += dyntext.AsSVGstring(decimals); s += "\n";
}
if (((std::string(node.name())) == "ellipse") || ((std::string(node.name())) == "circle")) {
ElmtEllipse elli;
elli.Clear();
elli.ReadFromPugiNode(node);
s += " "; s += elli.AsSVGstring(decimals); s += "\n";
}
if ((std::string(node.name())) == "terminal") {
ElmtTerminal term;
term.Clear();
term.ReadFromPugiNode(node);
s += " "; s += term.AsSVGstring(decimals); s += "\n";
}
if ((std::string(node.name())) == "arc") {
ElmtArc arc;
arc.Clear();
arc.ReadFromPugiNode(node);
s += " "; s += arc.AsSVGstring(decimals); s += "\n";
}
if ((std::string(node.name())) == "polygon") {
ElmtPolygon pol;
pol.Clear();
if (pol.ReadFromPugiNode(node) == true) {
s += " "; s += pol.AsSVGstring(decimals); s += "\n";
} else {
s += " INVALID Polygon in Element-File\n";
}
}
if ((std::string(node.name())) == "line") {
ElmtLine lin;
lin.Clear();
if (lin.ReadFromPugiNode(node) == true) {
s += " "; s += lin.AsSVGstring(decimals); s += "\n";
} else {
s += " INVALID Line in Element-File\n";
}
}
}
// und nun noch die letzten schließenden Tags:
s += " </g>\n Your Browser does not support inline SVG!\n</svg>";
// FERTIG!
return s;
}
/******************************************************************************/
#endif //#ifndef MAIN_H