-
Notifications
You must be signed in to change notification settings - Fork 4
/
ns_ddx_figure.py
4379 lines (3672 loc) · 278 KB
/
ns_ddx_figure.py
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
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'''
SPDX-License-Identifier: Apache-2.0
Copyright 2023 Cisco Systems, Inc. and its affiliates
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
from pptx import Presentation
from pptx.enum.dml import MSO_LINE
from pptx.enum.text import MSO_ANCHOR, PP_ALIGN , MSO_AUTO_SIZE
from pptx.enum.shapes import MSO_SHAPE,MSO_CONNECTOR
from pptx.dml.color import RGBColor,MSO_THEME_COLOR
from pptx.dml.line import LineFormat
from pptx.shapes.connector import Connector
from pptx.util import Inches,Cm,Pt
import sys, os
import openpyxl
import math
import unicodedata
class ns_ddx_figure_run():
def __init__(self):
#parameter
ppt_min_width = 13.4 # inches
ppt_min_hight = 7.5 # inches
ppt_max_width = 56 # inches
ppt_max_hight = 56 # inches
ppt_meta_file = self.excel_file_path
### Shared system setting values
self.ws_name_PPT_META = self.worksheet_name
self.outline_margin_root_folder = 0.2 ## inches
self.outline_margin_sub_folder = 0.1 ## inches
### shared open the files
if os.path.isfile(self.output_ppt_file) == True:
self.active_ppt = Presentation(self.output_ppt_file)
else:
self.active_ppt = Presentation()
if self.flag_second_page == False:
# width inches of slide master
if (self.root_width + self.root_left * 2) < ppt_min_width:
self.active_ppt.slide_width = Inches(ppt_min_width)
elif (self.root_width + self.root_left * 2) > ppt_max_width:
self.active_ppt.slide_width = Inches(ppt_max_width)
else:
self.active_ppt.slide_width = Inches(self.root_width + self.root_left * 2)
# height inches of slide master
if (self.root_hight + self.root_top * 1.5) < ppt_min_hight:
self.active_ppt.slide_height = Inches(ppt_min_hight)
elif (self.root_hight + self.root_top * 1.5) > ppt_max_hight:
self.active_ppt.slide_height = Inches(ppt_max_hight)
else:
self.active_ppt.slide_height = Inches(self.root_hight + self.root_top * 1.5)
self.input_ppt_mata_excel = openpyxl.load_workbook(ppt_meta_file)
### shared open setting values
self.coord_list = [] # coord list of folders and shapes
self.shapes_size_array = [] # add ver 2.0 . for writing l2 figure
self.temp_list_num = 0
self.folder_font_type = 'Calibri'
self.folder_font_size = 10 # Pt
self.shape_font_type = 'Calibri'
self.shae_font_size = 6 # Pt
'''main'''
if self.ws_name_PPT_META != '<ALL_Worksheets>':
### select active worksheet
self.input_ppt_mata_excel.active = self.input_ppt_mata_excel[self.ws_name_PPT_META]
### add new slide
ns_ddx_figure_run.add_slide(self)
### add root folder and get location
ns_ddx_figure_run.add_root_folder(self)
### add sub folders from excel also shapes
ns_ddx_figure_run.add_sub_folder(self)
### add l2 material for l2 shape ###
if self.click_value == 'L2-3-2':
ns_ddx_figure_run.add_l2_material(self)
ns_ddx_figure_run.add_l2_line(self)
### add line between folder and shape
if self.click_value != 'L2-3-2':
ns_ddx_figure_run.add_line(self)
### last, save_pptx
ns_ddx_figure_run.save_pptx(self)
else:
print('<ALL_Worksheets> selected')
ws_list = self.input_ppt_mata_excel.get_sheet_names()
for ws_name in ws_list:
### select active worksheet
self.input_ppt_mata_excel.active = self.input_ppt_mata_excel[ws_name]
### clear coord_list
self.coord_list = [] # coord list of folders and shapes
### add new slide
ns_ddx_figure_run.add_slide(self)
### add root folder and get location
ns_ddx_figure_run.add_root_folder(self)
### add sub folders from excel also shapes
ns_ddx_figure_run.add_sub_folder(self)
### add line between folder and shape
ns_ddx_figure_run.add_line(self)
### last, save_pptx
ns_ddx_figure_run.save_pptx(self)
def add_slide(self):
self.title_only_slide_layout = self.active_ppt.slide_layouts[5]
self.slide = self.active_ppt.slides.add_slide(self.title_only_slide_layout)
def add_root_folder(self):
temp_rootfolder_row = 0
temp_rootfolder_flag = False
temp_row = 1
self.root_folder = [0.28, 1.42, 9.45, 5.75] # Defalut setting. left , top , width , hight(Inches) / EMU is 914400
while temp_rootfolder_row < 50000 and temp_rootfolder_flag == False:
temp_rootfolder_row += 1
if str(self.input_ppt_mata_excel.active.cell(temp_rootfolder_row, 1).value) == '<<ROOT_FOLDER>>':
temp_rootfolder_flag = True
temp_row = temp_rootfolder_row
### input page title text and input root holder values
self.shape = self.slide.shapes
self.shape.title.text = str(self.input_ppt_mata_excel.active.cell(temp_row+1, 2).value)
self.root_folder[0] = float(self.input_ppt_mata_excel.active.cell(temp_row+1, 5).value)
self.root_folder[1] = float(self.input_ppt_mata_excel.active.cell(temp_row+1, 6).value)
self.root_folder[2] = float(self.input_ppt_mata_excel.active.cell(temp_row+1, 7).value) * float(self.input_ppt_mata_excel.active.cell(temp_row+1, 3).value)
self.root_folder[3] = float(self.input_ppt_mata_excel.active.cell(temp_row+1, 8).value) * float(self.input_ppt_mata_excel.active.cell(temp_row+1, 4).value)
### change ppt title , add ver 2.1 ###
if self.click_value == 'VPN-1-1':
self.shape.title.text = '[VPNs on L1] All Areas'
# style size,outline
self.shape = self.shape.add_shape(MSO_SHAPE.RECTANGLE, Inches(self.root_folder[0]), Inches(self.root_folder[1]), Inches(self.root_folder[2]), Inches(self.root_folder[3]))
#style fill
shape_fill = self.shape.fill
#chage outline coler to 255,255,255 at ver 2.3.0
#shape_fill = shape_fill.background()
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(255, 255, 255)
# style line
shape_line = self.shape.line
shape_line.color.rgb = RGBColor(0, 0, 0)
shape_line.color.brightness = 0.0
shape_line.width = Pt(1.5)
shape_line.fill.solid()
self.shape.shadow.inherit = False
### adjust outline margin
self.root_folder[0] = self.root_folder[0] + self.outline_margin_root_folder
self.root_folder[1] = self.root_folder[1] + self.outline_margin_root_folder
self.root_folder[2] = self.root_folder[2] - (self.outline_margin_root_folder*2)
self.root_folder[3] = self.root_folder[3] - (self.outline_margin_root_folder*2)
def add_sub_folder(self):
###get number of row from meta excel
temp_row = 1
temp_temp_row_folder = 0
excel_row_sum = 0
excel_col_sum = 0
temp_count_set_width = 0
self.sub_folder_list = [[],[]] # row list , column list
self.margin_top_text = 0.0
self.margin_bottom_text = -0.05
temp_subfolder_row = 0
temp_subfolder_flag = False
while temp_subfolder_row < 50000 and temp_subfolder_flag == False:
temp_subfolder_row += 1
if str(self.input_ppt_mata_excel.active.cell(temp_subfolder_row, 1).value) == '<<POSITION_FOLDER>>':
temp_subfolder_flag = True
temp_row = temp_subfolder_row
while self.input_ppt_mata_excel.active.cell(temp_row, 1).value != None:
if self.input_ppt_mata_excel.active.cell(temp_row, 1).value != '<SET_WIDTH>' and str(self.input_ppt_mata_excel.active.cell(temp_row, 1).value).startswith('<<POSITION_FOLDER>>') != True:
self.sub_folder_list[0].append(self.input_ppt_mata_excel.active.cell(temp_row, 1).value)
excel_row_sum = excel_row_sum + float(self.input_ppt_mata_excel.active.cell(temp_row, 1).value)
elif self.input_ppt_mata_excel.active.cell(temp_row, 1).value == '<SET_WIDTH>' or str(self.input_ppt_mata_excel.active.cell(temp_row, 1).value).startswith('<<POSITION_FOLDER>>') == True:
temp_count_set_width +=1
temp_row += 1
#### Set initial value
self.sub_folder = [self.root_folder[0],self.root_folder[1],self.root_folder[2],self.root_folder[3]] # left , top , width , hight(Inches) / EMU is 914400
'''write sub folders'''
for temp_row_folder in range(temp_subfolder_row, temp_row):
if self.input_ppt_mata_excel.active.cell(temp_row_folder, 1).value == '<SET_WIDTH>' or str(self.input_ppt_mata_excel.active.cell(temp_row_folder, 1).value).startswith('<<POSITION_FOLDER>>') == True:
### get num col in each row
excel_col_sum = 0
temp_column = 2
self.sub_folder_list[1] = []
while self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_column).value != None:
self.sub_folder_list[1].append(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_column).value)
excel_col_sum = excel_col_sum + float(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_column).value)
temp_column +=1
if self.input_ppt_mata_excel.active.cell(temp_row_folder, 1).value != '<SET_WIDTH>' and str(self.input_ppt_mata_excel.active.cell(temp_row_folder, 1).value).startswith('<<POSITION_FOLDER>>') != True:
###write folders on the row
for temp_col_folder in range(0, len(self.sub_folder_list[1])):
### get width and hight reflected ratio
self.sub_folder[2] = (self.sub_folder_list[1][temp_col_folder] / excel_col_sum) * self.root_folder[2] #col
self.sub_folder[3] = (self.sub_folder_list[0][temp_temp_row_folder] / excel_row_sum) * self.root_folder[3] #row
### adjust margin
folder_left = self.sub_folder[0]
folder_top = self.sub_folder[1]
folder_width = self.sub_folder[2]
folder_hight = self.sub_folder[3]
### write sub folder
self.shape = self.slide.shapes
self.shape = self.shape.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(folder_left), Inches(folder_top), Inches(folder_width), Inches(folder_hight))
###add self.coord_list for line
self.temp_folder_text = 'dummy'
if self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value != None:
x_left = folder_left
x_middle = folder_left + (folder_width*0.5)
x_right = folder_left + folder_width
y_top = folder_top
y_middle = folder_top + (folder_hight*0.5)
y_down = folder_top + folder_hight
self.temp_folder_text = str(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value)
### refrect tag function own shape
if '<' in self.temp_folder_text:
self.temp_folder_text = str('<') + str(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value).split('<')[-1].split('>')[0] + str('>')
self.coord_list.append([self.temp_folder_text,x_left,x_middle,x_right,y_top,y_middle,y_down]) #coord of x_left,x_middle,x_right,y_top,y_middle,y_down
self.temp_list_num += 1
### pass to add_shape()
self.shape_folder_left = self.sub_folder[0]
self.shape_folder_top = self.sub_folder[1]
self.shape_folder_width = self.sub_folder[2]
self.shape_folder_hight = self.sub_folder[3]
### chenge left and top of start folder
self.sub_folder[0] = self.sub_folder[0] + self.sub_folder[2]
shape_fill = self.shape.fill
shape_fill = shape_fill.background()
shape_line = self.shape.line
shape_line.color.rgb = RGBColor(0, 0, 0)
shape_line.color.brightness = 0.0
shape_line.width = Pt(1.5)
self.shape.adjustments[0] = 0.1 # curve of ROUNDED_RECTANGLE 0.0~1.0
self.shape.shadow.inherit = False # disalbe dealut shadow effect
### change folder coler when create summary diagram at ver 2.3.4
if self.flag_second_page == True and self.click_value == '2-4-3':
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(254, 246, 240)
shape_line.color.rgb = RGBColor(251, 201, 159)
shape_line.width = Pt(2.0)
self.shape.adjustments[0] = 0.3
self.shape.text_frame.paragraphs[0].font.size = Pt(16)
'''change stlye from meta file'''
temp_style_row = 1
temp_style_flag = False
temp_match_flag = False
while temp_style_row < 50000 and temp_match_flag == False:
if str(self.input_ppt_mata_excel.active.cell(temp_style_row, 1).value) == '<<STYLE_FOLDER>>':
temp_style_flag = True
## Default set###
if str(self.input_ppt_mata_excel.active.cell(temp_style_row, 1).value) == '<DEFAULT>':
temp_default_value = self.input_ppt_mata_excel.active.cell(temp_style_row, 2).value
if temp_default_value == 'YES':
shape_line.fill.solid()
elif temp_default_value == 'NO':
shape_line.fill.background()
## empty valse set###
if temp_style_flag == True and self.input_ppt_mata_excel.active.cell(temp_style_row, 1).value == '<EMPTY>':
temp_empty_value = self.input_ppt_mata_excel.active.cell(temp_style_row, 2).value
if self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value == None:
if temp_empty_value == 'YES':
shape_line.fill.solid()
elif temp_empty_value == 'NO':
shape_line.fill.background()
''' delete shape for network sketcher'''
sp = self.shape._element
sp.getparent().remove(sp)
break
## Outline and Adjust Margin Option set###
if temp_style_flag == True and str(self.input_ppt_mata_excel.active.cell(temp_style_row, 1).value) == str(self.temp_folder_text):
temp_match_flag = True
if self.input_ppt_mata_excel.active.cell(temp_style_row, 2).value == 'YES':
shape_line.fill.solid()
elif self.input_ppt_mata_excel.active.cell(temp_style_row, 2).value == 'NO':
shape_line.fill.background()
''' delete shape for network sketcher'''
sp = self.shape._element
sp.getparent().remove(sp)
if self.input_ppt_mata_excel.active.cell(temp_style_row, 4).value != '<AUTO>':
self.shape_folder_top = self.shape_folder_top + self.input_ppt_mata_excel.active.cell(temp_style_row, 4).value
self.shape_folder_hight = self.shape_folder_hight - self.input_ppt_mata_excel.active.cell(temp_style_row, 4).value
if self.input_ppt_mata_excel.active.cell(temp_style_row, 5).value != '<AUTO>':
self.shape_folder_hight = self.shape_folder_hight - self.input_ppt_mata_excel.active.cell(temp_style_row, 5).value
### Add Text into the sub folder, when UP
if self.input_ppt_mata_excel.active.cell(temp_style_row, 3).value == 'UP':
if '<' in str(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value):
self.shape.text = str(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value).split('<')[0]
self.shape.text_frame.vertical_anchor = MSO_ANCHOR.TOP
self.shape.text_frame.margin_top = Inches(self.margin_top_text)
else:
self.shape.text = str(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value)
self.shape.text_frame.vertical_anchor = MSO_ANCHOR.TOP
self.shape.text_frame.margin_top = Inches(self.margin_top_text)
### Add Text into the sub folder, when DOWN
if self.input_ppt_mata_excel.active.cell(temp_style_row, 3).value == 'DOWN':
if '<' in str(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value):
self.shape.text = str(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value).split('<')[0]
self.shape.text_frame.vertical_anchor = MSO_ANCHOR.BOTTOM
self.shape.text_frame.margin_bottom = Inches(self.margin_bottom_text)
else:
self.shape.text = str(self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder+2).value)
self.shape.text_frame.vertical_anchor = MSO_ANCHOR.BOTTOM
self.shape.text_frame.margin_bottom = Inches(self.margin_bottom_text)
if self.input_ppt_mata_excel.active.cell(temp_style_row, 3).value == 'UP' or self.input_ppt_mata_excel.active.cell(temp_style_row, 3).value == 'DOWN':
self.shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
self.shape.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER
self.shape.text_frame.paragraphs[0].font.name = self.folder_font_type
self.shape.text_frame.paragraphs[0].font.size = Pt(self.folder_font_size)
break
## empty value set ###
if temp_style_flag == True and self.input_ppt_mata_excel.active.cell(temp_style_row, 1).value == None:
break
temp_style_row += 1
### change folder coler when create summary diagram at ver 2.3.4
if self.flag_second_page == True and self.click_value == '2-4-3':
self.shape.text_frame.paragraphs[0].font.size = Pt(16)
self.shape.text_frame.vertical_anchor = MSO_ANCHOR.MIDDLE
'''run add shapes in own sub folder'''
self.ddx_meta_row_folder = temp_row_folder
self.ddx_meta_col_folder = temp_col_folder + 2
if self.input_ppt_mata_excel.active.cell(temp_row_folder, temp_col_folder + 2).value != None:
ns_ddx_figure_run.add_shape(self)
temp_temp_row_folder +=1
self.sub_folder[0] = self.root_folder[0]
self.sub_folder[1] = self.sub_folder[1] + self.sub_folder[3]
def add_shape(self):
print('Write Folder ---> ' + str(self.input_ppt_mata_excel.active.cell(self.ddx_meta_row_folder, self.ddx_meta_col_folder).value))
#print(self.shape_folder_left,self.shape_folder_top,self.shape_folder_width,self.shape_folder_hight)
'''Define reflect margin in the sub folder'''
folder_left = self.shape_folder_left + self.outline_margin_sub_folder
folder_top = self.shape_folder_top + self.outline_margin_sub_folder
folder_width = self.shape_folder_width - (self.outline_margin_sub_folder * 2)
folder_hight = self.shape_folder_hight - (self.outline_margin_sub_folder * 2)
## to use shapes in subholder
shape_left = folder_left
shape_top = folder_top
shape_width = folder_width
shape_hight = folder_hight
### get row of <<POSITION_SHAPE>> ###
temp_positon_row = 1
temp_position_flag = False
while temp_positon_row < 50000 and temp_position_flag == False:
if str(self.input_ppt_mata_excel.active.cell(temp_positon_row, 1).value) == '<<POSITION_SHAPE>>':
temp_position_flag = True
temp_positon_row += 1
### Search row number of the sub_folder
temp_subfolder_row = temp_positon_row
temp_subfolder_flag = False
temp_subfolder_exceed_flag = False
while temp_subfolder_row < 50000 and temp_subfolder_flag == False:
if str(self.input_ppt_mata_excel.active.cell(temp_subfolder_row, 1).value) == str(self.temp_folder_text):
temp_subfolder_flag = True
if str(self.input_ppt_mata_excel.active.cell(temp_subfolder_row, 1).value).startswith('<<') == True:
temp_subfolder_exceed_flag = True
#print(str(self.input_ppt_mata_excel.active.cell(self.ddx_meta_row_folder, self.ddx_meta_col_folder).value) + ' is not found under <<POSITION_SHAPE>> in excel')
temp_subfolder_row += 1
### get num of row about the sub folder
if temp_subfolder_flag == True and temp_subfolder_exceed_flag == False:
temp_row = temp_subfolder_row -1
excel_row_sum = 0
self.shape_width_sum = 0.0
self.shape_hight_sum = 0.0
temp_subfolder_row_flag = False
temp_subfolder_col_flag = False
temp_subfolder_row_exceed_flag = False
while self.input_ppt_mata_excel.active.cell(temp_row, 1).value != '<END>' and temp_subfolder_row_flag == False:
if self.input_ppt_mata_excel.active.cell(temp_row, 1).value == '<END>':
temp_subfolder_row_flag = True
if temp_row > 50000:
temp_subfolder_row_exceed_flag = True
### get sum of hight of shapes
if temp_subfolder_row_flag == False:
self.shape_hight_sum = self.shape_hight_sum + ns_ddx_figure_run.get_shape_highest(self,temp_row)
#print('####CHECK#### ',self.shape.text,ns_ddx_figure_run.get_shape_highest(self,temp_row),temp_row)
### process of before while loop
temp_row += 1
excel_row_sum += 1
### write each shape into sub folder
if temp_subfolder_row_exceed_flag == False:
for temp_row_subfolder in range(temp_subfolder_row-1, temp_subfolder_row+excel_row_sum-1):
excel_col_sum = 0
self.shape_width_sum = 0
temp_col = 2
### get num of col on the row
while self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_col).value != '<END>' and temp_subfolder_col_flag == False:
if self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_col).value == '<END>':
temp_subfolder_col_flag = True
if temp_col > 1000:
temp_subfolder_col_flag = True
### get sum of width of shapes
if temp_subfolder_col_flag == False:
self.shape_width_sum += ns_ddx_figure_run.get_shape_width(self,self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_col).value)
### process of before while loop
temp_col += 1
excel_col_sum += 1
'''write each shape in the own sub folder'''
### get width and hight margin
temp_width_margin = (folder_width - self.shape_width_sum) / (excel_col_sum + 1)
temp_hight_margin = (folder_hight - self.shape_hight_sum) / (excel_row_sum + 1)
shape_top += temp_hight_margin
for temp_sub_col_count in range(2,excel_col_sum+2):
shape_left = shape_left + temp_width_margin
shape_degree = 0.0 # initial degree
shape_width = ns_ddx_figure_run.get_shape_width(self,self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value)
shape_hight = ns_ddx_figure_run.get_shape_hight(self,self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value)
segment_flag = False
### check meant to segment as <SEGMENT>
if str(self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value).startswith('<SEGMENT>') == True:
segment_flag = True
ns_ddx_figure_run.add_segment_line(self,shape_left,shape_top,shape_width,shape_hight,folder_left,folder_top,folder_width,folder_hight,temp_sub_col_count,temp_row_subfolder,temp_width_margin,temp_hight_margin)
###write normal shape
#add and _AIR_ not included at ver 2.2.2(a)
if self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value != None and segment_flag == False and '_AIR_' not in str(self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value):
self.shape = self.slide.shapes
self.shape = self.shape.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(shape_left), Inches(shape_top), Inches(shape_width), Inches(shape_hight))
## write text and reflected TAG function in the shape
if '<' in str(self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value):
self.shape.text = str(self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value).split('<')[0]
else:
self.shape.text = str(self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value)
self.shapes_size_array.append([self.shape.text,[shape_left, shape_top, shape_width, shape_hight]]) #add ver 2.0 for writing l2 shapes
###add self.coord_list for line
x_left = shape_left
x_middle = shape_left + (shape_width * 0.5)
x_right = shape_left + shape_width
y_top = shape_top
y_middle = shape_top + (shape_hight * 0.5)
y_down = shape_top + shape_hight
temp_shape_text = str(self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value)
### refrect tag function own shape
if '<' in temp_shape_text:
temp_shape_text = str('<')+str(self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value).split('<')[-1].split('>')[0]+str('>')
self.coord_list.append([temp_shape_text, x_left, x_middle, x_right, y_top, y_middle, y_down]) # coord of x_left,x_middle,x_right,y_top,y_middle,y_down
self.temp_list_num += 1
'''set to initial style'''
self.shape.adjustments[0] = 0.0
self.shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
self.shape.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER
self.shape.text_frame.paragraphs[0].font.name = self.shape_font_type
self.shape.text_frame.paragraphs[0].font.size = Pt(self.shae_font_size)
self.shape.text_frame.margin_top = 0
self.shape.text_frame.margin_bottom = 0
self.shape.text_frame.margin_left = 0
self.shape.text_frame.margin_right = 0
shape_fill = self.shape.fill
shape_fill = shape_fill.background()
shape_line = self.shape.line
shape_line.color.rgb = RGBColor(0, 0, 0)
shape_line.color.brightness = 0.0
shape_line.width = Pt(1.0)
self.shape.adjustments[0] = shape_degree # initial
self.shape.shadow.inherit = False # disalbe dealut shadow effect
### change style for _AIR_ shape###
if '_AIR_' in temp_shape_text:
shape_line.color.rgb = RGBColor(255, 255, 255)
self.shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(255, 255, 255)
'''change to specific style from excel meta'''
### search row of <<STYLE_SHAPE>
temp_style_shape_row = 1
temp_style_shape_flag = False
while temp_style_shape_row < 50000 and temp_style_shape_flag == False:
if str(self.input_ppt_mata_excel.active.cell(temp_style_shape_row, 1).value) == '<<STYLE_SHAPE>>':
temp_style_shape_flag = True
temp_style_shape_row += 1
###get style values of shape from excel meta
temp_temp_style_shape_row = temp_style_shape_row
temp_temp_style_shape_flag = False
while temp_temp_style_shape_row < 50000 and temp_temp_style_shape_flag == False:
if self.input_ppt_mata_excel.active.cell(temp_temp_style_shape_row, 1).value == None:
temp_temp_style_shape_flag = True
break
if str(self.input_ppt_mata_excel.active.cell(temp_temp_style_shape_row, 1).value) == str(temp_shape_text):
temp_temp_style_shape_flag = True
### Degree of Roundness###
self.shape.adjustments[0] = float(self.input_ppt_mata_excel.active.cell(temp_temp_style_shape_row, 4).value) # curve of ROUNDED_RECTANGLE 0.0~1.0
### fill Color ###
if self.input_ppt_mata_excel.active.cell(temp_temp_style_shape_row, 5).value == 'ORANGE':
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(253, 234, 218)
elif self.input_ppt_mata_excel.active.cell(temp_temp_style_shape_row, 5).value == 'BLUE':
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(220, 230, 242)
elif self.input_ppt_mata_excel.active.cell(temp_temp_style_shape_row, 5).value == 'GREEN':
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(235, 241, 222)
elif self.input_ppt_mata_excel.active.cell(temp_temp_style_shape_row, 5).value == 'GRAY':
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(242, 242, 242)
### change style for _AIR_ shape###
if '_AIR_' in temp_shape_text:
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(255, 255, 255)
'''
### change style for L2 materials shape### ver 2.0 for device frame, wp frame
'''
### DEVICE FRAME ###
if self.click_value == 'L2-3-2' and self.input_ppt_mata_excel.active.cell(temp_temp_style_shape_row, 5).value == 'GREEN':
self.shape.text_frame.paragraphs[0].alignment = PP_ALIGN.LEFT
self.shape.text_frame.vertical_anchor = MSO_ANCHOR.TOP
shape_fill.fore_color.rgb = RGBColor(250, 251, 247)
self.shape.text_frame.paragraphs[0].font.size = Pt(self.folder_font_size)
self.shape.text_frame.margin_left = Inches(0.1)
self.shape.text_frame.margin_top = Inches(0.05)
### WAY POINT ###
if self.click_value == 'L2-3-2' and self.input_ppt_mata_excel.active.cell(temp_temp_style_shape_row, 5).value == 'BLUE':
shape_fill.fore_color.rgb = RGBColor(237, 242, 249)
self.shape.adjustments[0] = 0.1
self.shape.text_frame.paragraphs[0].alignment = PP_ALIGN.LEFT
self.shape.text_frame.vertical_anchor = MSO_ANCHOR.TOP
self.shape.text_frame.paragraphs[0].font.size = Pt(self.folder_font_size)
self.shape.text_frame.margin_left = Inches(0.1)
temp_temp_style_shape_row += 1
### process of before loop
shape_left = shape_left + shape_width
# process before change row
shape_top += ns_ddx_figure_run.get_shape_highest(self,temp_row_subfolder)
shape_left = folder_left
def add_line(self):
#print('### self.coord_list ###')
#print(self.coord_list)
### get <<POSITION_LINE>> from excel
temp_line_row = 1
temp_line_flag = False
while temp_line_row < 50000 and temp_line_flag == False:
if str(self.input_ppt_mata_excel.active.cell(temp_line_row, 1).value) == '<<POSITION_LINE>>':
temp_line_flag = True
temp_line_row += 1
### read each row under <<POSITION_LINE>>
temp_temp_line_row = temp_line_row + 1
while temp_temp_line_row < 50000 and self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 1).value != None:
''' write each line From To'''
From_name = self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 1).value
To_name = self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 2).value
from_connect_x = 2
from_connect_y = 5
to_connect_x = 2
to_connect_y = 5
self.coord_match_from_flag = False
self.coord_match_to_flag = False
###GET From index type as list
for y, row in enumerate(self.coord_list):
try:
temp_from = (y, row.index(From_name))
self.coord_match_from_flag = True
break
except ValueError:
pass
###GET To index
for y, row in enumerate(self.coord_list):
try:
temp_to = (y, row.index(To_name))
self.coord_match_to_flag = True
break
except ValueError:
pass
if self.coord_match_from_flag == True and self.coord_match_to_flag == True:
### compare the coord value of shape and deside connect side on the shape
if self.coord_list[temp_from[0]][6] >= self.coord_list[temp_to[0]][4]:
from_connect_y = 4
to_connect_y = 6
else:
from_connect_y = 6
to_connect_y = 4
### change from_side and to_side of each shape coord
if str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 5).value) == 'RIGHT':
from_connect_x = 3
from_connect_y = 5
if str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 5).value) == 'LEFT':
from_connect_x = 1
from_connect_y = 5
if str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 6).value) == 'RIGHT':
to_connect_x = 3
to_connect_y = 5
if str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 6).value) == 'LEFT':
to_connect_x = 1
to_connect_y = 5
### set coord values
inche_from_connect_x = float(self.coord_list[temp_from[0]][from_connect_x])
inche_from_connect_y = float(self.coord_list[temp_from[0]][from_connect_y])
inche_to_connect_x = float(self.coord_list[temp_to[0]][to_connect_x])
inche_to_connect_y = float(self.coord_list[temp_to[0]][to_connect_y])
### apply offset value to x y coord
if self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 7).value != None: # From X
inche_from_connect_x = self.coord_list[temp_from[0]][from_connect_x] + self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 7).value
if self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 8).value != None: # From Y
inche_from_connect_y = self.coord_list[temp_from[0]][from_connect_y] + self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 8).value
if self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 9).value != None and self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 9).value != '<FROM_X>': # To X
inche_to_connect_x = self.coord_list[temp_to[0]][to_connect_x] + self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 9).value
if self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 10).value != None and self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 10).value != '<FROM_Y>': # To Y
inche_to_connect_y = self.coord_list[temp_to[0]][to_connect_y] + self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 10).value
'''if Offset To_X or Y cell is <FROM_X> below <<POSITION_LINE>> in excel '''
if str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 9).value) == '<FROM_X>':
inche_to_connect_x = inche_from_connect_x
if str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 10).value) == '<FROM_Y>':
inche_to_connect_y = inche_from_connect_y
#write line
self.shape = self.slide.shapes
self.shape = self.shape.add_connector(MSO_CONNECTOR.STRAIGHT, Inches(inche_from_connect_x), Inches(inche_from_connect_y), Inches(inche_to_connect_x), Inches(inche_to_connect_y))
'''change style of line'''
shape_line = self.shape.line
shape_line.color.rgb = RGBColor(0, 0, 0)
shape_line.color.brightness = 0.0
shape_line.width = Pt(0.5)
shape_line.fill.solid()
self.shape.shadow.inherit = False
if self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 12).value == 'NO':
shape_line.fill.background()
'''write oval mark meant to channel '''
if self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 11).value != None:
#calc degree
temp_y = inche_to_connect_y - inche_from_connect_y
temp_x = inche_to_connect_x - inche_from_connect_x
temp_degree = math.degrees(math.atan2(temp_y, temp_x))
#calc location
if self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 5).value != None:
temp_oval_width = 0.1
temp_oval_hight = float(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 11).value)
temp_oval_left = inche_from_connect_x + (((inche_to_connect_x - inche_from_connect_x) * 0.5) - (temp_oval_width * 0.5))
temp_oval_top = inche_from_connect_y + (((inche_to_connect_y - inche_from_connect_y) * 0.5) - (temp_oval_hight * 0.5))
else:
temp_oval_width = 0.1
temp_oval_hight = float(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 11).value)
temp_oval_left = inche_from_connect_x + (((inche_to_connect_x - inche_from_connect_x) * 0.5) - (temp_oval_width * 0.5))
temp_oval_top = inche_from_connect_y + (((inche_to_connect_y - inche_from_connect_y) * 0.5) - (temp_oval_hight * 0.5))
self.shape = self.slide.shapes
self.shape = self.shape.add_shape(MSO_SHAPE.OVAL, Inches(temp_oval_left), Inches(temp_oval_top), Inches(temp_oval_width), Inches(temp_oval_hight)) #Inches(shape_left), Inches(shape_top), Inches(shape_width), Inches(shape_hight)
self.shape.rotation = temp_degree
shape_fill = self.shape.fill
shape_fill = shape_fill.background()
shape_line = self.shape.line
shape_line.color.rgb = RGBColor(0, 0, 0)
shape_line.color.brightness = 0.0
shape_line.width = Pt(0.3)
self.shape.shadow.inherit = False # disalbe dealut shadow effect
'''Add line tag on the line'''
### From side tag
if self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 3).value != None:
ns_ddx_figure_run.add_line_tag(self,'From', inche_from_connect_x, inche_from_connect_y, inche_to_connect_x, inche_to_connect_y,temp_temp_line_row,From_name)
### To side tag
if self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 4).value != None:
ns_ddx_figure_run.add_line_tag(self,'To', inche_from_connect_x, inche_from_connect_y, inche_to_connect_x, inche_to_connect_y,temp_temp_line_row,To_name)
'''last process, increment row num '''
temp_temp_line_row += 1
def add_line_tag(self,tag_side, inche_from_connect_x, inche_from_connect_y, inche_to_connect_x, inche_to_connect_y,temp_temp_line_row,Target_name):
self.tag_font_size = 6
import ns_def
### calc tag_width
per_char_width = 0.045 # tuning value
font_size_hight = 0.014 # tuning value
if tag_side == 'From':
tag_width = ns_ddx_figure_run.get_east_asian_width_count(self,str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 3).value)) * per_char_width
tag_hight = self.tag_font_size * font_size_hight
#tag_width = ns_def.get_description_width_hight(self.shae_font_size,str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 3).value))[0]
#tag_hight = ns_def.get_description_width_hight(self.shae_font_size,str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 3).value))[1]
elif tag_side == 'To':
tag_width = ns_ddx_figure_run.get_east_asian_width_count(self,str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 4).value)) * per_char_width
tag_hight = self.tag_font_size * font_size_hight
#tag_width = ns_def.get_description_width_hight(self.shae_font_size, str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 4).value))[0]
#tag_hight = ns_def.get_description_width_hight(self.shae_font_size, str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 4).value))[1]
elif tag_side == 'Segment':
tag_width = ns_ddx_figure_run.get_east_asian_width_count(self,str(Target_name)) * per_char_width
tag_hight = self.tag_font_size * font_size_hight
#tag_width = ns_def.get_description_width_hight(self.shae_font_size, str(Target_name))[0]
#tag_hight = ns_def.get_description_width_hight(self.shae_font_size, str(Target_name))[1]
###get <<POSITION_TAG>> from excel
temp_line_row = 1
temp_line_flag = False
while temp_line_row < 50000 and temp_line_flag == False:
if str(self.input_ppt_mata_excel.active.cell(temp_line_row, 1).value) == '<<POSITION_TAG>>':
temp_line_flag = True
temp_line_row += 1
### Set Default value
tag_type = str(self.input_ppt_mata_excel.active.cell(temp_line_row, 2).value)
temp_tag_degree = 0
### read each row under <<POSITION_LINE>>
temp_temp_temp_line_row = temp_line_row + 1
temp_tag_flag = False
while temp_temp_temp_line_row < 50000 and self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value != None and temp_tag_flag == False:
if self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 2).value != None:
tag_type = str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 2).value)
if tag_side == 'From' and tag_type == 'SHAPE':
tag_left = inche_from_connect_x - (tag_width * 0.5)
tag_top = inche_from_connect_y - (tag_hight * 0.5)
temp_tag_text = str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 3).value)
### get position tag
if str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name and self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 3).value != None:
tag_left += float(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 3).value)
temp_tag_flag = True
elif str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name:
temp_tag_flag = True
if str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name and self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 4).value != None:
tag_top += float(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 4).value)
temp_tag_flag = True
elif str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name:
temp_tag_flag = True
elif tag_side == 'To'and tag_type == 'SHAPE':
tag_left = inche_to_connect_x - (tag_width * 0.5)
tag_top = inche_to_connect_y - (tag_hight * 0.5)
temp_tag_text = str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 4).value)
### get position tag
if str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name and self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 3).value != None:
tag_left += float(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 3).value)
temp_tag_flag = True
elif str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name:
temp_tag_flag = True
if str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name and self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 4).value != None:
tag_top += float(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 4).value)
temp_tag_flag = True
elif str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name:
temp_tag_flag = True
elif tag_side == 'From' and tag_type == 'LINE':
tag_left = inche_from_connect_x - (tag_width * 0.5)
tag_top = inche_from_connect_y - (tag_hight * 0.5)
temp_tag_text = str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 3).value)
#### calc degree
temp_y = inche_to_connect_y - inche_from_connect_y
temp_x = inche_to_connect_x - inche_from_connect_x
temp_degree = math.degrees(math.atan2(temp_y, temp_x))
### change position tag
if str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name and self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 5).value != None:
temp_tag_flag = True
tag_left += (math.cos(math.radians(temp_degree)) * self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 5).value)
tag_top += (math.sin(math.radians(temp_degree)) * self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 5).value)
if str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name and self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 6).value == 'YES':
temp_tag_degree = temp_degree
temp_tag_flag = True
if temp_x < 0:
temp_tag_degree += 180
elif tag_side == 'To' and tag_type == 'LINE':
tag_left = inche_to_connect_x - (tag_width * 0.5)
tag_top = inche_to_connect_y - (tag_hight * 0.5)
temp_tag_text = str(self.input_ppt_mata_excel.active.cell(temp_temp_line_row, 4).value)
#### calc degree
temp_y = inche_to_connect_y - inche_from_connect_y
temp_x = inche_to_connect_x - inche_from_connect_x
temp_degree = math.degrees(math.atan2(temp_y, temp_x))
### change position tag
if str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name and self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 5).value != None:
temp_tag_flag = True
tag_left -= (math.cos(math.radians(temp_degree)) * self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 5).value)
tag_top -= (math.sin(math.radians(temp_degree))*self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 5).value)
if str(self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 1).value) == Target_name and self.input_ppt_mata_excel.active.cell(temp_temp_temp_line_row, 6).value == 'YES':
temp_tag_degree = temp_degree
temp_tag_flag = True
if temp_x < 0:
temp_tag_degree += 180
elif tag_side == 'Segment':
self.adjust_segment_char_y = 0.025
self.segment_font_size = 8
self.tag_font_size = self.segment_font_size
tag_left = inche_to_connect_x - (tag_width)
tag_top = inche_to_connect_y - (tag_hight) + self.adjust_segment_char_y
temp_tag_text = Target_name
'''last process, increment row num '''
temp_temp_temp_line_row += 1
###Write Tag Name
'''if From is <BULLET>'''
if tag_side == 'From' and temp_tag_text == '<BULLET>':
tag_left = inche_from_connect_x - (self.size_bullet * 0.5)
tag_top = inche_from_connect_y - (self.size_bullet * 0.5)
tag_width = self.size_bullet
tag_hight = self.size_bullet
'''if To is <BULLET>'''
if tag_side == 'To' and temp_tag_text == '<BULLET>':
tag_left = inche_to_connect_x - (self.size_bullet * 0.5)
tag_top = inche_to_connect_y - (self.size_bullet * 0.5)
tag_width = self.size_bullet
tag_hight = self.size_bullet
self.shape = self.slide.shapes
self.shape = self.shape.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(tag_left), Inches(tag_top), Inches(tag_width), Inches(tag_hight))
self.shape.text = temp_tag_text
self.shape.rotation = temp_tag_degree
'''set initial style'''
self.shape.text_frame.paragraphs[0].font.color.rgb = RGBColor(0, 0, 0)
self.shape.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER
self.shape.text_frame.paragraphs[0].font.name = self.shape_font_type
self.shape.text_frame.paragraphs[0].font.size = Pt(self.tag_font_size)
self.shape.text_frame.margin_top = 0
self.shape.text_frame.margin_bottom = 0
self.shape.text_frame.margin_left = 0
self.shape.text_frame.margin_right = 0
self.shape.text_frame.auto_size = True
self.shape.text_frame.word_wrap = False
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(255, 255, 255)
shape_line = self.shape.line
shape_line.color.rgb = RGBColor(0, 0, 0)
shape_line.color.brightness = 0.0
shape_line.width = Pt(0.1)
self.shape.adjustments[0] = 0.99445 # initial #0.99445 is do not change for identify if tag
self.shape.shadow.inherit = False # disalbe dealut shadow effect
'''if To or From is <BULLET>'''
if temp_tag_text == '<BULLET>':
self.shape.text = ''
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(0, 0, 0)
shape_line = self.shape.line
shape_line.fill.background()
self.shape.adjustments[0] = 1.0 # initial
self.shape.shadow.inherit = False # disalbe dealut shadow effect
'''set segment line and write start and end bullet'''
if tag_side == 'Segment':
self.shape.text_frame.paragraphs[0].alignment = PP_ALIGN.RIGHT
shape_fill = self.shape.fill
shape_fill.background()
shape_line = self.shape.line
shape_line.fill.background()
self.shape.text_frame.vertical_anchor = MSO_ANCHOR.BOTTOM
###write bullet at start and end of the line
self.size_bullet = 0.04
self.shape = self.slide.shapes
self.shape = self.shape.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(inche_from_connect_x-(self.size_bullet*0.5)), Inches(inche_from_connect_y-(self.size_bullet*0.5)), Inches(self.size_bullet), Inches(self.size_bullet))
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(0, 0, 0)
shape_line = self.shape.line
shape_line.fill.background()
self.shape.adjustments[0] = 1.0 # initial
self.shape.shadow.inherit = False # disalbe dealut shadow effect
self.shape = self.slide.shapes
self.shape = self.shape.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(inche_to_connect_x-(self.size_bullet*0.5)), Inches(inche_to_connect_y-(self.size_bullet*0.5)), Inches(self.size_bullet), Inches(self.size_bullet))
shape_fill = self.shape.fill
shape_fill.solid()
shape_fill.fore_color.rgb = RGBColor(0, 0, 0)
shape_line = self.shape.line
shape_line.fill.background()
self.shape.adjustments[0] = 1.0 # initial
self.shape.shadow.inherit = False # disalbe dealut shadow effect
def add_segment_line(self,shape_left,shape_top,shape_width,shape_hight,folder_left,folder_top,folder_width,folder_hight,temp_sub_col_count,temp_row_subfolder,temp_width_margin,temp_hight_margin):
###input line list to list type
temp_cell_value = str(self.input_ppt_mata_excel.active.cell(temp_row_subfolder, temp_sub_col_count).value)
temp_cell_value = '["' + temp_cell_value.split('["')[-1].split('"]')[0] + '"]'
segment_line_list = eval(temp_cell_value)
### get total hight for multi segment lines
margin_segment_hight = (temp_hight_margin + shape_hight) / (len(segment_line_list)+1)