@@ -317,6 +317,7 @@ def __init__(self, master, app=None):
317
317
self .algorithm_random_label = tk .Label (self ._frame , text = 'Number of trials' )
318
318
tk .Button (self ._frame , text = 'algorith information' , command = self .algorithm_info , bg = 'white' ) \
319
319
.place (x = start_x + dx * 10 , y = start_y + dy * 2 )
320
+
320
321
self .run_button = tk .Button (self ._frame , text = 'RUN OPTIMIZATION!' , command = self .run_optimizaion , bg = 'red' ,
321
322
font = 'Verdana 10' , fg = 'Yellow' )
322
323
self .run_button .place (x = start_x + dx * 10 , y = start_y )
@@ -426,6 +427,11 @@ def __init__(self, master, app=None):
426
427
font = 'Verdana 10' ,fg = 'black' )
427
428
self .run_results .place (x = start_x + dx * 13 , y = start_y - dy * 18 )
428
429
430
+ self .run_results_prev = tk .Button (self ._frame ,text = 'Show previous\n '
431
+ 'results' , command = self .show_previous_results , bg = 'white' ,
432
+ font = 'Verdana 10' ,fg = 'black' )
433
+ self .run_results_prev .place (x = start_x + dx * 15 , y = start_y - dy * 20 )
434
+
429
435
430
436
# ----------------------------------END OF OPTIMIZE SINGLE COPY-----------------------------------------------
431
437
self .progress_count = tk .IntVar ()
@@ -508,6 +514,15 @@ def selected_algorithm(self, event):
508
514
self ._ent_minstep .place (x = start_x + dx * 15 , y = start_y + 0 * dy )
509
515
self ._ent_minfunc .place (x = start_x + dx * 15 , y = start_y + 1 * dy )
510
516
517
+ def show_previous_results (self ):
518
+ # if type(self._geo_results) is not list():
519
+ # if self._geo_results is not None:
520
+ # return
521
+ # else:
522
+ # if self._geo_results[0] is not None:
523
+ # return
524
+ self .draw_select_canvas (opt_results = self ._geo_results )
525
+
511
526
def run_optimizaion (self , load_pre = False , save_results = True ):
512
527
'''
513
528
Function when pressing the optimization botton inside this window.
@@ -611,6 +626,7 @@ def run_optimizaion(self, load_pre = False, save_results = True):
611
626
* tuple ([val * 2 for val in self ._geo_results .keys ()]),
612
627
command = self .get_plate_field_options )
613
628
self ._ent_option_fractions .place (x = self ._option_fractions_place [0 ], y = self ._option_fractions_place [1 ])
629
+
614
630
# #SAVING RESULTS
615
631
# if save_results:
616
632
# with open('geo_opt_2.pickle', 'wb') as file:
@@ -633,9 +649,17 @@ def run_optimizaion(self, load_pre = False, save_results = True):
633
649
else :
634
650
filename = save_file .name
635
651
636
- save_file = self .draw_result_text (self ._geo_results , save_to_file = filename )
652
+ save_file , xplot , yplot = self .draw_result_text (self ._geo_results , save_to_file = filename )
637
653
self .draw_select_canvas (opt_results = self ._geo_results , save_file = save_file )
638
654
655
+ plt .axes (facecolor = 'lightslategray' )
656
+ plt .plot (xplot , yplot ,color = 'yellow' , linestyle = 'solid' , marker = 'o' ,markerfacecolor = 'white' , markersize = 6 )
657
+ plt .xlabel ('Length of plate fields [m]' )
658
+ plt .ylabel ('Weight / max weight' )
659
+ plt .title ('Length of plate fields vs. total weight' )
660
+ plt .grid ()
661
+ plt .show ()
662
+
639
663
def opt_get_fractions (self ):
640
664
''' Finding initial number of fractions '''
641
665
init_fractions = 0
@@ -988,13 +1012,14 @@ def draw_properties(self, init_obj=None, opt_obj=None, line=None):
988
1012
text = 'Lateral pressure: ' + str (lateral_press ) + ' kPa' ,
989
1013
font = 'Verdana 10 bold' , fill = 'red' )
990
1014
991
- def draw_select_canvas (self , load_selected = False , opt_results = None , save_file = None ):
1015
+ def draw_select_canvas (self , opt_results = None , save_file = None ):
992
1016
'''
993
1017
Making the lines canvas.
994
1018
:return:
995
1019
'''
996
1020
self ._canvas_select .delete ('all' )
997
1021
text_type = 'Verdana 8'
1022
+
998
1023
if opt_results is None :
999
1024
# stippled lines and text.
1000
1025
@@ -1123,7 +1148,8 @@ def draw_select_canvas(self, load_selected=False, opt_results = None, save_file
1123
1148
1124
1149
for data_idx , data in enumerate (values [1 ]):
1125
1150
for idx , stuc_info in enumerate (data ):
1126
- if type (stuc_info ) == ANYstructure .calc_structure .Structure :
1151
+ if type (stuc_info ) == ANYstructure_local .calc_structure .Structure :
1152
+
1127
1153
if y_loc > 700 :
1128
1154
y_loc = 120
1129
1155
start_x += 350
@@ -1196,7 +1222,6 @@ def draw_result_text(self, geo_opt_obj, save_to_file = None):
1196
1222
max_weight = weight if weight > max_weight else max_weight
1197
1223
1198
1224
1199
-
1200
1225
if save_to_file is not None :
1201
1226
save_file = open (save_to_file , 'w' )
1202
1227
save_file .write ('| Plate fields | Fields length | Weight index | All OK? |\n ' )
@@ -1232,15 +1257,10 @@ def draw_result_text(self, geo_opt_obj, save_to_file = None):
1232
1257
xplot .append (round (self ._geo_results [key ][1 ][0 ][0 ].get_span (),4 ))
1233
1258
yplot .append (round (self ._geo_results [key ][0 ] / max_weight , 4 ))
1234
1259
1235
- plt .axes (facecolor = 'lightslategray' )
1236
- plt .plot (xplot , yplot ,color = 'yellow' , linestyle = 'solid' , marker = 'o' ,markerfacecolor = 'white' , markersize = 6 )
1237
- plt .xlabel ('Length of plate fields [m]' )
1238
- plt .ylabel ('Weight / max weight' )
1239
- plt .title ('Length of plate fields vs. total weight' )
1240
- plt .grid ()
1241
- plt .show ()
1242
- if save_to_file :
1243
- return save_file
1260
+ if save_to_file is not None :
1261
+ return save_file , xplot , yplot
1262
+ else :
1263
+ return None , xplot , yplot
1244
1264
1245
1265
def algorithm_info (self ):
1246
1266
''' When button is clicked, info is displayed.'''
@@ -1365,12 +1385,12 @@ def button_1_click(self, event):
1365
1385
method is referenced in
1366
1386
'''
1367
1387
self ._previous_drag_mouse = [event .x , event .y ]
1368
- if type (self ._geo_results ) is not list ():
1369
- if self ._geo_results is not None :
1370
- return
1371
- else :
1372
- if self ._geo_results [0 ] is not None :
1373
- return
1388
+ # if type(self._geo_results) is not list():
1389
+ # if self._geo_results is not None:
1390
+ # return
1391
+ # else:
1392
+ # if self._geo_results[0] is not None:
1393
+ # return
1374
1394
click_x = self ._canvas_select .winfo_pointerx () - self ._canvas_select .winfo_rootx ()
1375
1395
click_y = self ._canvas_select .winfo_pointery () - self ._canvas_select .winfo_rooty ()
1376
1396
@@ -1471,7 +1491,7 @@ def save_and_close(self):
1471
1491
return
1472
1492
self ._frame .destroy ()
1473
1493
1474
- def toggle (self , found_files = None , obj = None , iterating = False ):
1494
+ def toggle (self , found_files = None , obj = None , iterating = False , given_path : str = None ):
1475
1495
'''
1476
1496
On off button.
1477
1497
:param found_files:
@@ -1496,13 +1516,22 @@ def toggle(self, found_files = None, obj = None, iterating = False):
1496
1516
self ._ent_spacing_upper .config (bg = 'lightgreen' )
1497
1517
self ._ent_spacing_lower .config (bg = 'lightgreen' )
1498
1518
self ._ent_delta_spacing .config (bg = 'lightgreen' )
1499
- self ._filez = list (askopenfilenames (parent = self ._frame , title = 'Choose files to open' ))
1519
+ self ._ent_pl_thk_upper .config (bg = 'lightgreen' )
1520
+ self ._ent_pl_thk_lower .config (bg = 'lightgreen' )
1521
+ self ._ent_delta_pl_thk .config (bg = 'lightgreen' )
1522
+ if given_path is None :
1523
+ self ._filez = list (askopenfilenames (parent = self ._frame , title = 'Choose files to open' ))
1524
+ else :
1525
+ self ._filez = [given_path ]
1500
1526
if self ._filez == []:
1501
1527
self ._toggle_btn .config (relief = "raised" )
1502
1528
self ._toggle_btn .config (bg = 'salmon' )
1503
1529
self ._ent_spacing_upper .config (bg = 'white' )
1504
1530
self ._ent_spacing_lower .config (bg = 'white' )
1505
1531
self ._ent_delta_spacing .config (bg = 'white' )
1532
+ self ._ent_pl_thk_upper .config (bg = 'white' )
1533
+ self ._ent_pl_thk_lower .config (bg = 'white' )
1534
+ self ._ent_delta_pl_thk .config (bg = 'white' )
1506
1535
1507
1536
return found_files , predefined_structure
1508
1537
@@ -1541,9 +1570,11 @@ def button_2_click_and_drag(self,event):
1541
1570
self ._canvas_draw_origo [1 ]- (self ._previous_drag_mouse [1 ]- event .y ))
1542
1571
1543
1572
self ._previous_drag_mouse = (event .x ,event .y )
1573
+
1544
1574
self .draw_select_canvas ()
1545
1575
1546
1576
if __name__ == '__main__' :
1547
1577
root = tk .Tk ()
1548
1578
my_app = CreateOptGeoWindow (master = root )
1579
+
1549
1580
root .mainloop ()
0 commit comments