BUNDLEBLDR.cpp 63.7 KB
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
/////////////////////////////////////////////////////////////////////////////////
//
// This file is part of SACAMOS, cable models for EMI simulations in SPICE.
// It was developed by the University of Nottingham and the Netherlands Aerospace
// Centre (NLR) for ESA under contract number 4000112765/14/NL/HK.
//
// Copyright (C) 2015 - 2018 University of Nottingham
//
// SACAMOS is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// SACAMOS is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// A copy of the GNU General Public License version 3 can be found in the
// file GNU_GPL_v3 in the root or at <http://www.gnu.org/licenses/>.
//
// wxWidgets is currently licenced under the "wxWindows Library Licence".
// A copy of the wxWindows Library Licence, Version 3.1 can be found in the file
// wxWindows_Library_Licence_v3-1 in the root or at:
// <https://www.wxwidgets.org/about/licence/>
//
// The University of Nottingham can be contacted at: ggiemr@nottingham.ac.uk
//
// File Contents:
//
// NAME
//     BUNDLEBLDR.cpp
//
// DESCRIPTION
//     Cable bundle builder application
//
// AUTHOR(S)
//     Steve Greedy
//
/////////////////////////////////////////////////////////////////////////////////
#include "BUNDLEBLDR.h"
#include "PLACE_CABLE.h"
#include "MESH_LAPLACE.h"


//#define debug 1
#include <wx/msgdlg.h>
#include <wx/filename.h>
#include <wx/dcclient.h>
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>

#define PI 3.14159265358979323846

using namespace std;

//(*InternalHeaders(BUNDLEBLDR)
#include <wx/settings.h>
#include <wx/intl.h>
#include <wx/string.h>
//*)

//(*IdInit(BUNDLEBLDR)
const long BUNDLEBLDR::ID_STATICTEXT1 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL1 = wxNewId();
const long BUNDLEBLDR::ID_PANEL2 = wxNewId();
const long BUNDLEBLDR::ID_LISTBOX1 = wxNewId();
const long BUNDLEBLDR::ID_PANEL3 = wxNewId();
const long BUNDLEBLDR::ID_CHECKBOX1 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT2 = wxNewId();
const long BUNDLEBLDR::ID_PANEL4 = wxNewId();
const long BUNDLEBLDR::ID_CHECKBOX2 = wxNewId();
const long BUNDLEBLDR::ID_COMBOBOX1 = wxNewId();
const long BUNDLEBLDR::ID_CHECKBOX3 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT6 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT7 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL4 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT8 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL5 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT13 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL9 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT14 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL10 = wxNewId();
const long BUNDLEBLDR::ID_PANEL5 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT11 = wxNewId();
const long BUNDLEBLDR::ID_CHECKBOX4 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT3 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL2 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT4 = wxNewId();
const long BUNDLEBLDR::ID_RADIOBUTTON1 = wxNewId();
const long BUNDLEBLDR::ID_RADIOBUTTON2 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT5 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL3 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT9 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL6 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT10 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL7 = wxNewId();
const long BUNDLEBLDR::ID_PANEL6 = wxNewId();
const long BUNDLEBLDR::ID_NOTEBOOK1 = wxNewId();
const long BUNDLEBLDR::ID_BUTTON1 = wxNewId();
const long BUNDLEBLDR::ID_BUTTON2 = wxNewId();
const long BUNDLEBLDR::ID_BUTTON3 = wxNewId();
const long BUNDLEBLDR::ID_PANEL1 = wxNewId();
const long BUNDLEBLDR::ID_STATICTEXT12 = wxNewId();
const long BUNDLEBLDR::ID_TEXTCTRL8 = wxNewId();
const long BUNDLEBLDR::ID_SPINBUTTON1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(BUNDLEBLDR,wxDialog)
	//(*EventTable(BUNDLEBLDR)
	//*)
END_EVENT_TABLE()

BUNDLEBLDR::BUNDLEBLDR(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
	//(*Initialize(BUNDLEBLDR)
	wxBoxSizer* BoxSizer4;
	wxStaticBoxSizer* StaticBoxSizer2;
	wxBoxSizer* BoxSizer6;
	wxFlexGridSizer* FlexGridSizer4;
	wxBoxSizer* BoxSizer5;
	wxStaticBoxSizer* StaticBoxSizer4;
	wxFlexGridSizer* FlexGridSizer3;
	wxFlexGridSizer* FlexGridSizer5;
	wxFlexGridSizer* FlexGridSizer9;
	wxFlexGridSizer* FlexGridSizer2;
	wxBoxSizer* BoxSizer2;
	wxFlexGridSizer* FlexGridSizer7;
	wxStaticBoxSizer* StaticBoxSizer3;
	wxFlexGridSizer* FlexGridSizer8;
	wxBoxSizer* BoxSizer1;
	wxFlexGridSizer* FlexGridSizer6;
	wxStaticBoxSizer* StaticBoxSizer1;
	wxFlexGridSizer* FlexGridSizer1;
	wxBoxSizer* BoxSizer3;

	Create(parent, wxID_ANY, _("SACAMOS: CABLE BUNDLE BUILDER"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER, _T("wxID_ANY"));
	FlexGridSizer1 = new wxFlexGridSizer(1, 2, 0, 0);
	FlexGridSizer1->AddGrowableCol(1);
	FlexGridSizer1->AddGrowableRow(0);
	StaticBoxSizer4 = new wxStaticBoxSizer(wxVERTICAL, this, _("Bundle Specification"));
	FlexGridSizer3 = new wxFlexGridSizer(0, 1, 0, 0);
	BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
	StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Bundle Name"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
	BoxSizer2->Add(StaticText1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl1 = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
	BoxSizer2->Add(TextCtrl1, 2, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer3->Add(BoxSizer2, 1, wxALL|wxEXPAND, 5);
	BoxSizer5 = new wxBoxSizer(wxHORIZONTAL);
	Notebook1 = new wxNotebook(this, ID_NOTEBOOK1, wxDefaultPosition, wxSize(-1,380), 0, _T("ID_NOTEBOOK1"));
	Panel3 = new wxPanel(Notebook1, ID_PANEL3, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL3"));
	BoxSizer6 = new wxBoxSizer(wxVERTICAL);
	StaticBoxSizer2 = new wxStaticBoxSizer(wxVERTICAL, Panel3, _("Cable Component Browser"));
	Panel2 = new wxPanel(Panel3, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER|wxTAB_TRAVERSAL, _T("ID_PANEL2"));
	Panel2->SetMinSize(wxSize(300,0));
	StaticBoxSizer2->Add(Panel2, 1, wxALL|wxEXPAND, 5);
	BoxSizer6->Add(StaticBoxSizer2, 2, wxALL|wxEXPAND, 5);
	StaticBoxSizer3 = new wxStaticBoxSizer(wxVERTICAL, Panel3, _("Bundle Component Cables"));
	BoxSizer3 = new wxBoxSizer(wxVERTICAL);
	ListBox1 = new wxListBox(Panel3, ID_LISTBOX1, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_LISTBOX1"));
	BoxSizer3->Add(ListBox1, 1, wxALL|wxEXPAND, 5);
	StaticBoxSizer3->Add(BoxSizer3, 1, wxALL|wxEXPAND, 5);
	BoxSizer6->Add(StaticBoxSizer3, 2, wxALL|wxEXPAND, 5);
	Panel3->SetSizer(BoxSizer6);
	BoxSizer6->Fit(Panel3);
	BoxSizer6->SetSizeHints(Panel3);
	Panel4 = new wxPanel(Notebook1, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL4"));
	FlexGridSizer4 = new wxFlexGridSizer(0, 2, 0, 0);
	FlexGridSizer4->AddGrowableCol(1);
	CheckBox1 = new wxCheckBox(Panel4, ID_CHECKBOX1, _("Use Ground Plane"), wxDefaultPosition, wxSize(154,13), 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
	CheckBox1->SetValue(false);
	FlexGridSizer4->Add(CheckBox1, 1, wxALL|wxALIGN_LEFT, 5);
	StaticText2 = new wxStaticText(Panel4, ID_STATICTEXT2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
	FlexGridSizer4->Add(StaticText2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	Panel4->SetSizer(FlexGridSizer4);
	FlexGridSizer4->Fit(Panel4);
	FlexGridSizer4->SetSizeHints(Panel4);
	Panel5 = new wxPanel(Notebook1, ID_PANEL5, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL5"));
	FlexGridSizer5 = new wxFlexGridSizer(0, 2, 0, 0);
	CheckBox2 = new wxCheckBox(Panel5, ID_CHECKBOX2, _("Use Laplace"), wxDefaultPosition, wxSize(95,24), 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
	CheckBox2->SetValue(false);
	FlexGridSizer5->Add(CheckBox2, 1, wxALL, 5);
	ComboBox1 = new wxComboBox(Panel5, ID_COMBOBOX1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_COMBOBOX1"));
	FlexGridSizer5->Add(ComboBox1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	CheckBox3 = new wxCheckBox(Panel5, ID_CHECKBOX3, _("Refine Laplace Mesh"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX3"));
	CheckBox3->SetValue(false);
	CheckBox3->Disable();
	FlexGridSizer5->Add(CheckBox3, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	StaticText6 = new wxStaticText(Panel5, ID_STATICTEXT6, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
	FlexGridSizer5->Add(StaticText6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText7 = new wxStaticText(Panel5, ID_STATICTEXT7, _("Surface Mesh Constant"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT7"));
	FlexGridSizer5->Add(StaticText7, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl4 = new wxTextCtrl(Panel5, ID_TEXTCTRL4, _("3"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL4"));
	TextCtrl4->Disable();
	FlexGridSizer5->Add(TextCtrl4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText8 = new wxStaticText(Panel5, ID_STATICTEXT8, _("Boundary Constant"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT8"));
	FlexGridSizer5->Add(StaticText8, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl5 = new wxTextCtrl(Panel5, ID_TEXTCTRL5, _("3"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL5"));
	TextCtrl5->Disable();
	FlexGridSizer5->Add(TextCtrl5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText13 = new wxStaticText(Panel5, ID_STATICTEXT13, _("Max Mesh Edge Length"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT13"));
	FlexGridSizer5->Add(StaticText13, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl9 = new wxTextCtrl(Panel5, ID_TEXTCTRL9, _("1e-3"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL9"));
	TextCtrl9->Disable();
	FlexGridSizer5->Add(TextCtrl9, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText14 = new wxStaticText(Panel5, ID_STATICTEXT14, _("Ground Plane Edge Length"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT14"));
	FlexGridSizer5->Add(StaticText14, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl10 = new wxTextCtrl(Panel5, ID_TEXTCTRL10, _("1e-3"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL10"));
	TextCtrl10->Disable();
	FlexGridSizer5->Add(TextCtrl10, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	Panel5->SetSizer(FlexGridSizer5);
	FlexGridSizer5->Fit(Panel5);
	FlexGridSizer5->SetSizeHints(Panel5);
	Panel6 = new wxPanel(Notebook1, ID_PANEL6, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL6"));
	FlexGridSizer2 = new wxFlexGridSizer(0, 1, 0, 0);
	FlexGridSizer9 = new wxFlexGridSizer(0, 3, 0, 0);
	StaticText11 = new wxStaticText(Panel6, ID_STATICTEXT11, _("Use Filter Fitting Parameters"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT11"));
	FlexGridSizer9->Add(StaticText11, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	CheckBox4 = new wxCheckBox(Panel6, ID_CHECKBOX4, _("Yes"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX4"));
	CheckBox4->SetValue(false);
	FlexGridSizer9->Add(CheckBox4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(FlexGridSizer9, 1, wxALL|wxEXPAND, 5);
	FlexGridSizer6 = new wxFlexGridSizer(0, 2, 0, 0);
	StaticText3 = new wxStaticText(Panel6, ID_STATICTEXT3, _("Order for Filter Fitting "), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
	FlexGridSizer6->Add(StaticText3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl2 = new wxTextCtrl(Panel6, ID_TEXTCTRL2, _("-10"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
	TextCtrl2->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
	FlexGridSizer6->Add(TextCtrl2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(FlexGridSizer6, 1, wxALL|wxEXPAND, 5);
	FlexGridSizer7 = new wxFlexGridSizer(0, 3, 0, 0);
	StaticText4 = new wxStaticText(Panel6, ID_STATICTEXT4, _("Range Type"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
	FlexGridSizer7->Add(StaticText4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	RadioButton1 = new wxRadioButton(Panel6, ID_RADIOBUTTON1, _("Lin"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON1"));
	FlexGridSizer7->Add(RadioButton1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	RadioButton2 = new wxRadioButton(Panel6, ID_RADIOBUTTON2, _("Log"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_RADIOBUTTON2"));
	FlexGridSizer7->Add(RadioButton2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(FlexGridSizer7, 1, wxALL|wxEXPAND, 5);
	FlexGridSizer8 = new wxFlexGridSizer(0, 2, 0, 0);
	StaticText5 = new wxStaticText(Panel6, ID_STATICTEXT5, _("Frequency min (Hz)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
	FlexGridSizer8->Add(StaticText5, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl3 = new wxTextCtrl(Panel6, ID_TEXTCTRL3, _("1e3"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
	TextCtrl3->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
	FlexGridSizer8->Add(TextCtrl3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText9 = new wxStaticText(Panel6, ID_STATICTEXT9, _("Frequecy max (Hz)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT9"));
	FlexGridSizer8->Add(StaticText9, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl6 = new wxTextCtrl(Panel6, ID_TEXTCTRL6, _("1e9"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL6"));
	TextCtrl6->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
	FlexGridSizer8->Add(TextCtrl6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText10 = new wxStaticText(Panel6, ID_STATICTEXT10, _("Number of Frequencies"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT10"));
	FlexGridSizer8->Add(StaticText10, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl7 = new wxTextCtrl(Panel6, ID_TEXTCTRL7, _("12"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL7"));
	TextCtrl7->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
	FlexGridSizer8->Add(TextCtrl7, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(FlexGridSizer8, 1, wxALL|wxEXPAND, 5);
	Panel6->SetSizer(FlexGridSizer2);
	FlexGridSizer2->Fit(Panel6);
	FlexGridSizer2->SetSizeHints(Panel6);
	Notebook1->AddPage(Panel3, _("Bundle"), false);
	Notebook1->AddPage(Panel4, _("Ground Plane"), false);
	Notebook1->AddPage(Panel5, _("Laplace Solver"), false);
	Notebook1->AddPage(Panel6, _("Filter Fitting"), false);
	BoxSizer5->Add(Notebook1, 1, wxALL|wxEXPAND, 5);
	FlexGridSizer3->Add(BoxSizer5, 1, wxALL|wxEXPAND, 5);
	StaticBoxSizer4->Add(FlexGridSizer3, 8, wxALL|wxEXPAND, 5);
	BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
	Button1 = new wxButton(this, ID_BUTTON1, _("SAVE"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
	BoxSizer1->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	Button2 = new wxButton(this, ID_BUTTON2, _("BUILD"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
	BoxSizer1->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	Button3 = new wxButton(this, ID_BUTTON3, _("CLOSE"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
	BoxSizer1->Add(Button3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer4->Add(BoxSizer1, 1, wxALL, 5);
	FlexGridSizer1->Add(StaticBoxSizer4, 3, wxALL|wxEXPAND, 5);
	StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("2D Cross Section"));
	Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxSize(500,500), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
	Panel1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
	StaticBoxSizer1->Add(Panel1, 9, wxALL|wxEXPAND, 5);
	BoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
	StaticText12 = new wxStaticText(this, ID_STATICTEXT12, _("Cross Section xmax, ymax (m) = "), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT12"));
	BoxSizer4->Add(StaticText12, 4, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl8 = new wxTextCtrl(this, ID_TEXTCTRL8, _("0.030"), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER, wxDefaultValidator, _T("ID_TEXTCTRL8"));
	BoxSizer4->Add(TextCtrl8, 4, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SpinButton1 = new wxSpinButton(this, ID_SPINBUTTON1, wxDefaultPosition, wxDefaultSize, wxSP_VERTICAL|wxSP_ARROW_KEYS, _T("ID_SPINBUTTON1"));
	SpinButton1->SetRange(0, 100);
	BoxSizer4->Add(SpinButton1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer1->Add(BoxSizer4, 1, wxALL, 5);
	FlexGridSizer1->Add(StaticBoxSizer1, 1, wxALL, 5);
	SetSizer(FlexGridSizer1);
	FlexGridSizer1->Fit(this);
	FlexGridSizer1->SetSizeHints(this);

	Panel2->Connect(wxEVT_PAINT,(wxObjectEventFunction)&BUNDLEBLDR::OnPanel2Paint,0,this);
	Connect(ID_CHECKBOX1,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&BUNDLEBLDR::OnCheckBox1Click);
	Connect(ID_COMBOBOX1,wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)&BUNDLEBLDR::OnComboBox1Selected);
	Connect(ID_CHECKBOX3,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&BUNDLEBLDR::OnCheckBox3Click);
	Connect(ID_TEXTCTRL4,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&BUNDLEBLDR::OnTextCtrl4Text);
	Connect(ID_TEXTCTRL5,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&BUNDLEBLDR::OnTextCtrl5Text);
	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BUNDLEBLDR::OnButton1Click);
	Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BUNDLEBLDR::OnButton2Click);
	Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&BUNDLEBLDR::OnButton3Click);
	Panel1->Connect(wxEVT_PAINT,(wxObjectEventFunction)&BUNDLEBLDR::OnPanel1Paint,0,this);
	Connect(ID_TEXTCTRL8,wxEVT_COMMAND_TEXT_ENTER,(wxObjectEventFunction)&BUNDLEBLDR::OnTextCtrl8TextEnter);
	Connect(ID_SPINBUTTON1,wxEVT_SCROLL_THUMBTRACK,(wxObjectEventFunction)&BUNDLEBLDR::OnSpinButton1Change);
	Connect(ID_SPINBUTTON1,wxEVT_SCROLL_LINEUP,(wxObjectEventFunction)&BUNDLEBLDR::OnSpinButton1ChangeUp);
	Connect(ID_SPINBUTTON1,wxEVT_SCROLL_LINEDOWN,(wxObjectEventFunction)&BUNDLEBLDR::OnSpinButton1ChangeDown);
	Connect(wxID_ANY,wxEVT_INIT_DIALOG,(wxObjectEventFunction)&BUNDLEBLDR::OnInit);
	//*)

    ListBox1->Connect(wxEVT_RIGHT_DOWN,  wxMouseEventHandler(BUNDLEBLDR::OnListboxRDown), NULL, this);

	// Initialise the head node
    bundle_root = new Bundle;
    bundle_root->next = NULL;

    // Ths is the list
    bundle_list = bundle_root;

	// Load and populate file tree
	//PopulateTheDirectoryTree(PathToMOD);
}

void BUNDLEBLDR::OnListboxRDown(wxMouseEvent& event)
{
    int item = ListBox1->HitTest(event.GetPosition());

    if ( item != wxNOT_FOUND )
    {
        wxString strMessage;
        wxString strItem = ListBox1->GetString(item);

        strMessage = "Are you sure you wish to delete: ";
        strMessage = strMessage << strItem;
        // We have an item in the list to delete - shall we confirm?
        wxMessageDialog bb_ConfirmDelete (this, strMessage, _("Please confirm delete") ,wxYES_NO|wxCENTRE,wxDefaultPosition );

        bb_ConfirmDelete.ShowModal();

        //int RetVal = bb_ConfirmDelete.GetReturnCode();

        //if (  RetVal == wxID_YES )
        //{
            // Delete the item 'item' from the linked list
            removeElement(item);
            PopulateListControl();
            // And repopulate the listbox (clear it first!)

        //}

    }
    else
        wxMessageBox(_T("Listbox right clicked but no item clicked upon"),_("No item selected"));

    event.Skip();
}

void BUNDLEBLDR::PopulateListControl(void)
{
    ListBox1->Clear();

    Bundle *Current = bundle_root;

    while ( Current->next != NULL )
    {
        ListBox1->Append(Current->CableType);
        Current = Current->next;
    }
}

void BUNDLEBLDR::removeElement(int ItemIndex)
{

    Bundle *Current = bundle_root;
    Bundle *Previous = Current;
    //Bundle *Next = bundle_root->next;

    // Otherwise we look through the list for the item
    int i = 0;
    while( (Current!= NULL) &&  (i < ItemIndex) )
    {
        Previous = Current;
        Current = Current->next;
        i++;
    }

    if ( Current == bundle_root)    // Deleting the 1st item in the list
    {
        bundle_root = bundle_root->next;
    }
    else
    {
        Previous->next= Current->next;
    }

    delete Current;

}



BUNDLEBLDR::~BUNDLEBLDR()
{
	//(*Destroy(BUNDLEBLDR)
	//*)
}

void BUNDLEBLDR::PopulateTheDirectoryTree (wxString Path)
{

    #ifdef debug
        wxMessageBox(Path, _("PathToMod"));
    #endif

    int size_h, size_v;
    Panel2->GetSize(&size_h, &size_v );
    //wxGenericDirCtrl *tree;
    tree = (wxSpecificDirCtrl *) NULL;
    tree = new wxSpecificDirCtrl (Panel2, -1, Path,
        wxDefaultPosition,
        wxSize(size_h, size_v),
        wxSIMPLE_BORDER,//wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
         "*.cable_spec", 0,
        _T("Directory Listing"));

    Connect(tree->GetTreeCtrl()->GetId(),wxEVT_COMMAND_TREE_ITEM_ACTIVATED, (wxObjectEventFunction) (wxEventFunction)(wxCommandEventFunction) &BUNDLEBLDR::OnTreeSelectionChanged);


    //SetButtonState_FolderSelected();
}


void BUNDLEBLDR::OnTreeSelectionChanged(wxTreeEvent& evt)
{
    // A few file functions
    wxFileName fname (tree->GetFilePath());
    wxString File_Path = fname.GetPath();
    wxString File_FullName = fname.GetFullName();


    PLACE_CABLE *winPLACE_CABLE = new PLACE_CABLE(this);

    if ( winPLACE_CABLE->ShowModal() == wxID_OK )
    {
        bundle_list->x_offset = winPLACE_CABLE->TextCtrl1->GetValue();
        bundle_list->y_offset = winPLACE_CABLE->TextCtrl2->GetValue();
        bundle_list->rot_theta = winPLACE_CABLE->TextCtrl3->GetValue();
        bundle_list->CableType = File_FullName;

        // Create a new node additional cables
        bundle_list->next = new Bundle;

        // Set the current to the new one
        bundle_list = bundle_list->next;

        // Mark the NULL end of bundle component list
        bundle_list->next = NULL;

    };

    winPLACE_CABLE->Destroy();

    ListBox1->Append(File_FullName);

    DrawBundleCsection();

}


void BUNDLEBLDR::OnPanel2Paint(wxPaintEvent& event)
{

}


void BUNDLEBLDR::SetPathForDir(wxString Path, wxString Name)
{
    PathToMOD << Path;
    MODname << Name;
    PopulateTheDirectoryTree(PathToMOD);
}

void BUNDLEBLDR::OnCheckListBox1Toggled(wxCommandEvent& event)
{
}

void BUNDLEBLDR::OnPanel1Paint(wxPaintEvent& event)
{
    double maxDimension;

    wxString maxXY = TextCtrl8->GetValue();

    maxXY.ToDouble(&maxDimension);

    FormatPanel(maxDimension);
}

void BUNDLEBLDR::DrawBundleCsection()
{
    bundle_list = bundle_root;

    wxString x, y, rot, cable;

    while ( bundle_list->next != NULL )
    {
        cable = bundle_list->CableType;
        x = bundle_list->x_offset;
        y = bundle_list->y_offset;
        rot = bundle_list->rot_theta;

        DrawBundleCable(cable, x, y, rot);

        bundle_list = bundle_list->next;
    }
}


// BUNDLE GRAPHICAL SCHEMATIC - SET UP PANEL
void BUNDLEBLDR::FormatPanel(double maxDimension)

{
    int size_h, size_v;
    Panel1->GetSize(&size_h, &size_v );

    wxString scale;
    scale << maxDimension/2.0;

    wxClientDC dc(Panel1);
    dc.Clear();

    // Draw centre lines
    dc.SetPen( wxPen( wxColor(224,224,224),1 , wxDOT_DASH) );
    dc.DrawLine( 0, size_v/2, size_h,size_v/2 );
    dc.DrawLine( size_h/2, 0, size_h/2, size_v);

    dc.SetTextForeground(*wxBLACK);
    dc.DrawText("y=0", 5, (size_v/2)-15);
    dc.DrawText("x=0", (size_h/2)+5, size_v-20);

    // Draw ordinates
    dc.SetPen( wxPen( wxColor(255,0,0),1 ) );
    dc.DrawCircle( wxPoint(5,size_v-10), 5 );

    dc.DrawLine( 5, size_v-10, 30, size_v-10 );
    dc.DrawLine( 5, size_v-10, 5, size_v-35);
    dc.DrawText("y", 10, size_v-45);
    dc.DrawText("x", 30, size_v-25);

    dc.SetTextForeground(*wxBLUE);

    dc.DrawLine( size_h/2, size_v-50, size_h-size_h/4, size_v-50 );
    dc.DrawLine( size_h/2, size_v-50, size_h/2, size_v-40 );
    dc.DrawLine( size_h-size_h/4, size_v-50, size_h-size_h/4, size_v-40 );

    dc.DrawText("scale (m)", (size_h/2+50), size_v-70);
    dc.DrawText(scale, (size_h/2+55), size_v-40);
}

void BUNDLEBLDR::DrawBundleCable(wxString cable, wxString x, wxString y, wxString rot)
{
    wxString separator(wxFileName::GetPathSeparator());

    double xCoord, yCoord, rotation, maxDimension;

    x.ToDouble(&xCoord);
    y.ToDouble(&yCoord);
    rot.ToDouble(&rotation);

    yCoord = -1.0 * yCoord;

    int size_h, size_v;
    Panel1->GetSize(&size_h, &size_v );

    wxClientDC dc(Panel1);

    std::stringstream stream;
    stream << PathToMOD << separator << "CABLE"<< separator << cable;

    cable = (stream.str().c_str());

    std::ifstream cableFile;
    cableFile.open (cable);

    std::string str;

    std::getline(cableFile, str);
    std::getline(cableFile, str);
    std::getline(cableFile, str);

    float scaleFactor = (size_h/2 * 1.0);

    wxString maxXY = TextCtrl8->GetValue();

    maxXY.ToDouble(&maxDimension);

    if (str.compare("Cylindrical") == 0 ){

        std::getline(cableFile, str);
        std::getline(cableFile, str);

        float conductor_radius, dielectric_radius;

        cableFile >> conductor_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> dielectric_radius;

        float dielectric_Scaledradius,conductor_Scaledradius, scaledxCoord, scaledyCoord;

        dielectric_Scaledradius = (dielectric_radius/maxDimension)*scaleFactor;
        conductor_Scaledradius  = (conductor_radius/maxDimension)*scaleFactor;
        scaledxCoord = (xCoord/maxDimension)*scaleFactor;
        scaledyCoord = (yCoord/maxDimension)*scaleFactor;

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2+scaledxCoord,size_v/2+scaledyCoord), dielectric_Scaledradius );
        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2+scaledxCoord,size_v/2+scaledyCoord), conductor_Scaledradius );

    }

    if (str.compare("Coax") == 0 ){

        std::getline(cableFile, str);
        std::getline(cableFile, str);

        float inner_conductor_radius, shield_radius, outer_insulation, shield_thickness;

        cableFile >> inner_conductor_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> shield_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> outer_insulation;
        std::getline(cableFile, str); //Read to end of line
        std::getline(cableFile, str); //Read to end of line
        cableFile >> shield_thickness;

        float  inner_conductor_Scaledradius, shield_Scaledradius, outer_Scaledinsulation, shield_Scaledthickness, scaledxCoord, scaledyCoord;

        outer_Scaledinsulation  = (outer_insulation/maxDimension)*scaleFactor;
        shield_Scaledthickness  = (shield_thickness/maxDimension)*scaleFactor;
        shield_Scaledradius     = (shield_radius/maxDimension)*scaleFactor;
        inner_conductor_Scaledradius = (inner_conductor_radius/maxDimension)*scaleFactor;
        scaledxCoord = (xCoord/maxDimension)*scaleFactor;
        scaledyCoord = (yCoord/maxDimension)*scaleFactor;

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2+scaledxCoord,size_v/2+scaledyCoord), outer_Scaledinsulation );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2+scaledxCoord,size_v/2+scaledyCoord), shield_Scaledthickness+shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxLIGHT_GREY, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2+scaledxCoord,size_v/2+scaledyCoord), shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2+scaledxCoord,size_v/2+scaledyCoord), inner_conductor_Scaledradius );

    }

   if (str.compare("Twinax") == 0 ){

        std::getline(cableFile, str);
        std::getline(cableFile, str);

        float inner_conductor_radius, inner_dielectric_radius, conductor_separation, shield_radius, shield_thickness, outer_dielectric_radius;

        cableFile >> inner_conductor_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> inner_dielectric_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> conductor_separation;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> shield_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> shield_thickness;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> outer_dielectric_radius;

        float   outer_dielectric_Scaledradius,
                            shield_Scaledthickness,
                            shield_Scaledradius,
                            inner_dielectric_Scaledradius,
                            inner_conductor_Scaledradius,
                            conductor_Scaledseparation,
                            scaledxCoord,
                            scaledyCoord;

        outer_dielectric_Scaledradius = (outer_dielectric_radius/maxDimension)*scaleFactor;
        shield_Scaledthickness = (shield_thickness/maxDimension)*scaleFactor;
        shield_Scaledradius = (shield_radius/maxDimension)*scaleFactor;
        inner_dielectric_Scaledradius = (inner_dielectric_radius/maxDimension)*scaleFactor;
        inner_conductor_Scaledradius = (inner_conductor_radius/maxDimension)*scaleFactor;
        conductor_Scaledseparation = (conductor_separation/maxDimension)*scaleFactor;
        scaledxCoord = 2*(xCoord/maxDimension)*scaleFactor;
        scaledyCoord = 2*(yCoord/maxDimension)*scaleFactor;

        size_h = size_h + scaledxCoord;
        size_v = size_v + scaledyCoord;

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), outer_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), shield_Scaledthickness+shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxLIGHT_GREY, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2)+(conductor_Scaledseparation/2),size_v/2), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2)-(conductor_Scaledseparation/2),size_v/2), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2)+(conductor_Scaledseparation/2),size_v/2), inner_conductor_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2)-(conductor_Scaledseparation/2),size_v/2), inner_conductor_Scaledradius );
    }

    if (str.compare("Twisted_pair") == 0 ){

        std::getline(cableFile, str);
        std::getline(cableFile, str);

        float conductor_radius, conductor_separation, dielectric_radius;

        cableFile >> conductor_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> conductor_separation;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> dielectric_radius;

        float  conductor_Scaledradius, conductor_Scaledseparation, dielectric_Scaledradius, scaledxCoord, scaledyCoord;

        conductor_Scaledradius = (conductor_radius/maxDimension)*scaleFactor;
        conductor_Scaledseparation = (conductor_separation/maxDimension)*scaleFactor;
        dielectric_Scaledradius = (dielectric_radius/maxDimension)*scaleFactor;
        scaledxCoord = 2*(xCoord/maxDimension)*scaleFactor;
        scaledyCoord = 2*(yCoord/maxDimension)*scaleFactor;

        size_h = size_h + scaledxCoord;
        size_v = size_v + scaledyCoord;

        float wire_pos = (conductor_Scaledseparation/2)*0.707;

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2-wire_pos,size_v/2-wire_pos), conductor_Scaledradius );


        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2-wire_pos,size_v/2-wire_pos), dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2+wire_pos,size_v/2+wire_pos), conductor_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2+wire_pos,size_v/2+wire_pos), dielectric_Scaledradius );
    }

    if (str.compare("Shielded_twisted_pair") == 0 ){

        std::getline(cableFile, str);
        std::getline(cableFile, str);

        float inner_conductor_radius, inner_conductor_separation, inner_dielectric_radius, shield_radius, shield_thickness, outer_dielectric_radius;

        cableFile >> inner_conductor_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> inner_dielectric_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> inner_conductor_separation;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> shield_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> shield_thickness;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> outer_dielectric_radius;

        float   inner_conductor_Scaledradius,
                inner_conductor_Scaledseparation,
                inner_dielectric_Scaledradius,
                shield_Scaledradius,
                shield_Scaledthickness,
                outer_dielectric_Scaledradius,
                scaledxCoord,
                scaledyCoord;

        inner_conductor_Scaledradius = (inner_conductor_radius/maxDimension)*scaleFactor;
        inner_conductor_Scaledseparation = (inner_conductor_separation/maxDimension)*scaleFactor;
        inner_dielectric_Scaledradius = (inner_dielectric_radius/maxDimension)*scaleFactor;
        shield_Scaledradius = (shield_radius/maxDimension)*scaleFactor;
        shield_Scaledthickness =  (shield_thickness/maxDimension)*scaleFactor;
        outer_dielectric_Scaledradius = (outer_dielectric_radius/maxDimension)*scaleFactor;
        scaledxCoord = (xCoord/maxDimension)*scaleFactor;
        scaledyCoord = (yCoord/maxDimension)*scaleFactor;

        size_h = size_h + scaledxCoord;
        size_v = size_v + scaledyCoord;

        float wire_pos = (inner_conductor_Scaledseparation/2)*0.707;

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), outer_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), shield_Scaledthickness+shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2-wire_pos,size_v/2-wire_pos), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2-wire_pos,size_v/2-wire_pos), inner_conductor_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2+wire_pos,size_v/2+wire_pos), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2+wire_pos,size_v/2+wire_pos), inner_conductor_Scaledradius );
    }

    if (str.compare("Spacewire") == 0 ){

        std::getline(cableFile, str);
        std::getline(cableFile, str);

        float   inner_conductor_radius, inner_conductor_separation, inner_dielectric_radius, inner_shield_radius, inner_shield_thickness,
                inner_shield_jacket_radius, shielded_twisted_pair_radius, outer_shield_radius, outer_shield_thickness, outer_dielectric_radius;

        cableFile >> inner_conductor_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> inner_dielectric_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> inner_conductor_separation;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> inner_shield_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> inner_shield_thickness;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> inner_shield_jacket_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> shielded_twisted_pair_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> outer_shield_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> outer_shield_thickness;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> outer_dielectric_radius;

                float   inner_conductor_Scaledradius,
                inner_dielectric_Scaledradius,
                inner_conductor_Scaledseparation,
                inner_shield_Scaledradius,
                inner_shield_Scaledthickness,
                inner_shield_jacket_Scaledradius,
                shielded_twisted_pair_Scaledradius,
                outer_shield_Scaledradius,
                outer_shield_Scaledthickness,
                outer_dielectric_Scaledradius,
                scaledxCoord,
                scaledyCoord;

        inner_conductor_Scaledradius = (inner_conductor_radius/maxDimension)*scaleFactor;
        inner_dielectric_Scaledradius = (inner_dielectric_radius/maxDimension)*scaleFactor;
        inner_conductor_Scaledseparation = (inner_conductor_separation/maxDimension)*scaleFactor;
        inner_shield_Scaledradius = (inner_shield_radius/maxDimension)*scaleFactor;
        inner_shield_Scaledthickness = (inner_shield_thickness/maxDimension)*scaleFactor;
        inner_shield_jacket_Scaledradius = (inner_shield_jacket_radius/maxDimension)*scaleFactor;
        shielded_twisted_pair_Scaledradius = (shielded_twisted_pair_radius/maxDimension)*scaleFactor;
        outer_shield_Scaledradius = (outer_shield_radius/maxDimension)*scaleFactor;
        outer_shield_Scaledthickness = (outer_shield_thickness/maxDimension)*scaleFactor;
        outer_dielectric_Scaledradius = (outer_dielectric_radius/maxDimension)*scaleFactor;
        scaledxCoord = (xCoord/maxDimension)*scaleFactor;
        scaledyCoord = (yCoord/maxDimension)*scaleFactor;

        size_h = size_h + scaledxCoord;
        size_v = size_v + scaledyCoord;

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), outer_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), outer_shield_Scaledthickness+outer_shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), outer_shield_Scaledradius );

        //TP Top
        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2-shielded_twisted_pair_Scaledradius)), inner_shield_jacket_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2-shielded_twisted_pair_Scaledradius)), inner_shield_Scaledthickness + inner_shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2-shielded_twisted_pair_Scaledradius)), inner_shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2-shielded_twisted_pair_Scaledradius-inner_conductor_Scaledseparation/2)), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2-shielded_twisted_pair_Scaledradius+inner_conductor_Scaledseparation/2)), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2-shielded_twisted_pair_Scaledradius-inner_conductor_Scaledseparation/2)), inner_conductor_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2-shielded_twisted_pair_Scaledradius+inner_conductor_Scaledseparation/2)), inner_conductor_Scaledradius );


        //TP Left
        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint((size_h/2-shielded_twisted_pair_Scaledradius),size_v/2), inner_shield_jacket_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2-shielded_twisted_pair_Scaledradius),size_v/2), inner_shield_Scaledthickness + inner_shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2-shielded_twisted_pair_Scaledradius),size_v/2), inner_shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint((size_h/2-shielded_twisted_pair_Scaledradius-inner_conductor_Scaledseparation/2),size_v/2), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint((size_h/2-shielded_twisted_pair_Scaledradius+inner_conductor_Scaledseparation/2),size_v/2), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2-shielded_twisted_pair_Scaledradius-inner_conductor_Scaledseparation/2),size_v/2), inner_conductor_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2-shielded_twisted_pair_Scaledradius+inner_conductor_Scaledseparation/2),size_v/2), inner_conductor_Scaledradius );

        //TP Bottom
        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2+shielded_twisted_pair_Scaledradius)), inner_shield_jacket_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2+shielded_twisted_pair_Scaledradius)), inner_shield_Scaledthickness + inner_shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2+shielded_twisted_pair_Scaledradius)), inner_shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2+shielded_twisted_pair_Scaledradius+inner_conductor_Scaledseparation/2)), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2+shielded_twisted_pair_Scaledradius-inner_conductor_Scaledseparation/2)), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2+shielded_twisted_pair_Scaledradius+inner_conductor_Scaledseparation/2)), inner_conductor_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,(size_v/2+shielded_twisted_pair_Scaledradius-inner_conductor_Scaledseparation/2)), inner_conductor_Scaledradius );

        //TP Right
        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint((size_h/2+shielded_twisted_pair_Scaledradius),size_v/2), inner_shield_jacket_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2+shielded_twisted_pair_Scaledradius),size_v/2), inner_shield_Scaledthickness + inner_shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2+shielded_twisted_pair_Scaledradius),size_v/2), inner_shield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint((size_h/2+shielded_twisted_pair_Scaledradius-inner_conductor_Scaledseparation/2),size_v/2), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint((size_h/2+shielded_twisted_pair_Scaledradius+inner_conductor_Scaledseparation/2),size_v/2), inner_dielectric_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2+shielded_twisted_pair_Scaledradius-inner_conductor_Scaledseparation/2),size_v/2), inner_conductor_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint((size_h/2+shielded_twisted_pair_Scaledradius+inner_conductor_Scaledseparation/2),size_v/2), inner_conductor_Scaledradius );
    }

    if (str.compare("Overshield") == 0 ){

        std::getline(cableFile, str);
        std::getline(cableFile, str);

        float overshield_radius, overshield_thickness;

        cableFile >> overshield_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> overshield_thickness;


        float overshield_Scaledradius, overshield_Scaledthickness, scaledxCoord, scaledyCoord;

        overshield_Scaledradius     = (overshield_radius/maxDimension)*scaleFactor;
        overshield_Scaledthickness  = (overshield_thickness/maxDimension)*scaleFactor;
        scaledxCoord = (xCoord/maxDimension)*scaleFactor;
        scaledyCoord = (yCoord/maxDimension)*scaleFactor;

        size_h = size_h + scaledxCoord;
        size_v = size_v + scaledyCoord;

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), overshield_Scaledthickness+overshield_Scaledradius );

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), overshield_Scaledradius );
    }

    if (str.compare("flex_cable") == 0 ){

        float dielectric_width, dielectric_height, conductor_rows;

        std::getline(cableFile, str); //Read to end of line
        std::getline(cableFile, str); //Read to end of line
        cableFile >> dielectric_width;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> dielectric_height;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> conductor_rows;
        std::getline(cableFile, str); //Read to end of line

        float scaled_dielectric_width, scaled_dielectric_height, scaledxCoord, scaledyCoord;

        float dx1,dy1,dx2,dy2,dx3,dy3,dx4,dy4, tempx, tempy, rotation_rad;

        scaled_dielectric_width = (dielectric_width/maxDimension) * scaleFactor;
        scaled_dielectric_height = (dielectric_height/maxDimension) * scaleFactor;

        scaledxCoord = xCoord/maxDimension * scaleFactor;
        scaledyCoord = yCoord/maxDimension * scaleFactor;

        rotation_rad = rotation * (PI/180.0);

        float s = sin(rotation_rad);
        float c = cos(rotation_rad);

        dx1 = -scaled_dielectric_width/2;
        dy1 = scaled_dielectric_height/2;

        tempx = dx1*c - dy1*s;
        tempy = dx1*s + dy1*c;

        dx1 = size_h/2 + tempx + scaledxCoord;
        dy1 = size_v/2 + tempy + scaledyCoord ;

        //point 3
        dx2 = -scaled_dielectric_width/2;
        dy2 = -scaled_dielectric_height/2;

        tempx = dx2*c - dy2*s;
        tempy = dx2*s + dy2*c;

        dx2 = size_h/2 + tempx + scaledxCoord;
        dy2 = size_v/2 + tempy + scaledyCoord;

        //point 3
        dx3 =  scaled_dielectric_width/2;
        dy3 = -scaled_dielectric_height/2;

        tempx = dx3*c - dy3*s;
        tempy = dx3*s + dy3*c;

        dx3 = size_h/2 + tempx + scaledxCoord;
        dy3 = size_v/2 + tempy + scaledyCoord;

        //point 4
        dx4 = scaled_dielectric_width/2;
        dy4 = scaled_dielectric_height/2;

        tempx = dx4*c - dy4*s;
        tempy = dx4*s + dy4*c;

        dx4 = size_h/2 + tempx + scaledxCoord;
        dy4 = size_v/2 + tempy + scaledyCoord;


        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxBDIAGONAL_HATCH));

        dc.DrawLine(dx1, dy1, dx2, dy2);
        dc.DrawLine(dx2, dy2, dx3, dy3);
        dc.DrawLine(dx3, dy3, dx4, dy4);
        dc.DrawLine(dx4, dy4, dx1, dy1);

        float offset_x, offset_y, width, height,separation, conductors;

        for (int i = 0; i < conductor_rows;i++){
            cableFile >> offset_x;
            std::getline(cableFile, str); //Read to end of line

            cableFile >> offset_y;
            std::getline(cableFile, str); //Read to end of line

            cableFile >> width;
            std::getline(cableFile, str); //Read to end of line

            cableFile >> height;
            std::getline(cableFile, str); //Read to end of line

            cableFile >> separation;
            std::getline(cableFile, str); //Read to end of line

            cableFile >> conductors;
            std::getline(cableFile, str); //Read to end of line


            float scaled_conductor_width = width/maxDimension * scaleFactor;
            float scaled_conductor_height = height/maxDimension * scaleFactor;
            float scaled_conductor_separation = separation/maxDimension * scaleFactor;
            float scaled_offset_x = offset_x/maxDimension * scaleFactor;
            float scaled_offset_y = offset_y/maxDimension * scaleFactor;

            //calculate conductor origin, top left corner: start at no.1
            float x_origin = 0 - (scaled_conductor_width * conductors/2) - scaled_conductor_separation*(conductors - 1)/2  + scaled_offset_x;
            float y_origin = scaled_conductor_height/2 + scaled_offset_y;

            float cx1,cy1,cx2,cy2,cx3,cy3,cx4,cy4;

            dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
            dc.SetBrush(wxBrush(*wxWHITE, wxSOLID));

            for (int j = 0; j<conductors; j++){

                //point 1
                cx1 = x_origin + j * (scaled_conductor_width + scaled_conductor_separation);
                cy1 = y_origin;

                tempx = cx1*c - cy1*s;
                tempy = cx1*s + cy1*c;

                cx1 = tempx + scaledxCoord + size_h/2;
                cy1 = tempy + scaledyCoord + size_v/2;

                //point 3
                cx2 = x_origin + j * (scaled_conductor_width + scaled_conductor_separation);
                cy2 = y_origin - scaled_conductor_height;

                tempx = cx2*c - cy2*s;
                tempy = cx2*s + cy2*c;

                cx2 = tempx + scaledxCoord + size_h/2;
                cy2 = tempy + scaledyCoord + size_v/2;

                //point 3
                cx3 = x_origin + scaled_conductor_width + j * (scaled_conductor_width + scaled_conductor_separation);
                cy3 = y_origin - scaled_conductor_height;

                tempx = cx3*c - cy3*s;
                tempy = cx3*s + cy3*c;

                cx3 = tempx + scaledxCoord + size_h/2;
                cy3 = tempy + scaledyCoord + size_v/2;

                //point 4
                cx4 = x_origin + scaled_conductor_width + j * (scaled_conductor_width + scaled_conductor_separation);
                cy4 = y_origin;

                tempx = cx4*c - cy4*s;
                tempy = cx4*s + cy4*c;

                cx4 = tempx + scaledxCoord + size_h/2;
                cy4 = tempy + scaledyCoord + size_v/2;

                dc.DrawLine(cx1, cy1, cx2, cy2);
                dc.DrawLine(cx2, cy2, cx3, cy3);
                dc.DrawLine(cx3, cy3, cx4, cy4);
                dc.DrawLine(cx4, cy4, cx1, cy1);
            }
        }

    }

    if (str.compare("Dconnector") == 0 ){

        float conductors, conductor_radius, conductor_pitch, conductor_separation, shell_offset;

        cableFile >> conductors;
        std::getline(cableFile, str); //Read to end of line
        std::getline(cableFile, str); //Read to end of line
        cableFile >> conductor_radius;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> conductor_pitch;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> conductor_separation;
        std::getline(cableFile, str); //Read to end of line
        cableFile >> shell_offset;

//        float totalWidth = (conductors/2 * conductor_separation) + (2 * shell_offset) + (2 * conductor_radius);

        float   conductor_Scaledradius,
                conductor_Scaledpitch,
                conductor_Scaledseparation,
                scaledxCoord,
                scaledyCoord;


        float x_origin, y_origin;

        scaleFactor = (size_h * 0.25);

        conductor_Scaledradius = (conductor_radius/maxDimension)*scaleFactor;
        conductor_Scaledpitch = (conductor_pitch/maxDimension)*scaleFactor;
        conductor_Scaledseparation = (conductor_separation/maxDimension)*scaleFactor;

        scaledxCoord = (xCoord/maxDimension)*scaleFactor;
        scaledyCoord = (yCoord/maxDimension)*scaleFactor;

        size_h = size_h + scaledxCoord;
        size_v = size_v + scaledyCoord;

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK, wxSOLID));

        // Upper conductors & Shell
        int upper_conductors = conductors / 2;
        x_origin = (size_h/2) - (upper_conductors/2 * conductor_Scaledseparation);
        y_origin = (size_v/2) - (conductor_Scaledpitch);

        dc.SetPen( wxPen( wxColor(0,0,0),1 ) );
        dc.SetBrush(wxBrush(*wxBLACK));

        for(int i=0;i<upper_conductors;i++){

            dc.DrawCircle( wxPoint(x_origin,y_origin), conductor_Scaledradius );
            x_origin = x_origin + (conductor_Scaledpitch);
        }
        // Lower conductors
        int lower_conductors = (conductors / 2) - 1;
        x_origin = (size_h/2) - (lower_conductors/2 * conductor_Scaledseparation) + conductor_Scaledseparation/2;
        y_origin = (size_v/2) + (conductor_Scaledpitch); // This isn't correct!!

        for(int i=0;i<lower_conductors;i++){

            dc.DrawCircle( wxPoint(x_origin,y_origin), conductor_Scaledradius );
            x_origin = x_origin + (conductor_Scaledpitch);
        }
    }

}

void BUNDLEBLDR::OnButton1Click(wxCommandEvent& event)
{
    int IsError = 0;

    wxString fileName = TextCtrl1->GetValue();

    TextCtrl1->SetBackgroundColour(wxColor(255,255,255));

    if (fileName == "")
    {
        wxMessageBox("Please Specify a Cable Name" , _("Missing Cable Name"));
        return;
    }

    WriteBundleFile(fileName);

    Button1->Disable();
}

void BUNDLEBLDR::WriteBundleFile(wxString fileName)
{
    ofstream cableFile;
    wxString separator(wxFileName::GetPathSeparator());

    wxString fullFileName = PathToMOD + separator + "BUNDLE" + separator + fileName + ".bundle_spec";

    cableFile.open (fullFileName);

    if (cableFile.is_open())
    {
        cableFile << "#MOD_cable_lib_dir" << "\n";

        cableFile <<".." << separator << MODname << separator << "CABLE" << separator <<"\n";

        cableFile << "#MOD_cable_lib_dir" << "\n";

        cableFile <<".." << separator << MODname << separator << "BUNDLE" << separator <<"\n";

        cableFile << ListBox1->GetCount() << " #Number of cables in bundle, cable list follows\n";

        bundle_list = bundle_root;

        wxString x, y, rot, cable;

        while ( bundle_list->next != NULL )
        {

            cable = bundle_list->CableType;

            //Remove file extension
            size_t lastindex = cable.find_last_of(".");
            wxString cable_name = cable.substr(0, lastindex); //at the moment here requires full path to file

            x = bundle_list->x_offset;
            y = bundle_list->y_offset;
            rot = bundle_list->rot_theta;

            cableFile << cable_name <<"\n";
            cableFile << x << "\t" << y << "\t" << rot << "\n";

            bundle_list = bundle_list->next;
        }

        if (CheckBox1->GetValue())
        {
            cableFile << "ground_plane\n";
        }
        else
        {
            cableFile <<"no_ground_plane\n";
        }


        if (CheckBox4->GetValue())
        {
            cableFile << TextCtrl2->GetValue() <<"\t # order for filter fitting\n";
            if (RadioButton1)
            {
                cableFile << "lin   # frequency range type for filter fitting type (lin or dB)";
            }
            else
            {
                cableFile << "log   # frequency range type for filter fitting type (lin or dB)";
            }
            cableFile << TextCtrl3->GetValue() <<" "<< TextCtrl6->GetValue() <<" "<< TextCtrl7->GetValue() <<"\t # fmin fmax number_of_frequencies for filter fitting";

        }

        if (CheckBox2->GetValue())
        {
            cableFile << "use_laplace\n";
        }
        else
        {
            cableFile << "no_laplace\n";
        }

        if (CheckBox3->GetValue())
        {
            cableFile << "Laplace_boundary_constant\n";
            cableFile << TextCtrl4->GetValue() <<"\n";
            cableFile << "Laplace_surface_mesh_constant\n";
            cableFile << TextCtrl5->GetValue() <<"\n";
            cableFile << "max_mesh_edge_length\n";
            cableFile << TextCtrl9->GetValue() <<"\n";

            if (CheckBox1->GetValue())
            {
                cableFile << "gp_mesh_edge_length\n";
                cableFile << TextCtrl10->GetValue() <<"\n";
            }
            CheckBox3 ->SetValue(false);
        }
    }
    cableFile.close();

}


void BUNDLEBLDR::OnButton2Click(wxCommandEvent& event)
{
    //clean up directory
    clean_temp_files();

    wxString fileName = TextCtrl1->GetValue();

    wxString command_line;

    wxString separator(wxFileName::GetPathSeparator());

    WriteBundleFile (TextCtrl1->GetValue());

    std::stringstream stream;
    stream  <<"." + separator
            << "cable_bundle_model_builder"
            << " "
            << ".." + separator + MODname + separator + "BUNDLE" + separator
            << fileName ;

    command_line << stream.str().c_str();

    wxExecute (command_line,wxEXEC_SYNC);

    // Display Run Status
    RUN_STATUS *run_status_bundle = new RUN_STATUS(this);
    run_status_bundle->ShowModal();

    //Button1->Enable();

    if (CheckBox2->GetValue())
    {
        wxString pattern(("*.msh.vtk"));
        wxString file;

        ComboBox1->Clear();

        file = wxFindFirstFile(pattern);

        while ( !file.empty())
        {
            wxString meshfile = file;

            size_t extindex = meshfile.find_last_of (".");

            meshfile  = meshfile.substr(0, extindex);

            extindex = meshfile.find_last_of (".");

            meshfile  = meshfile.substr(0, extindex);

            meshfile = meshfile.substr(2,meshfile.length());

            ComboBox1->Append(meshfile);

            file = wxFindNextFile();
        }
        CheckBox3->Enable();

    }
}

void BUNDLEBLDR::OnButton3Click(wxCommandEvent& event)
{
    PopulateTheDirectoryTree(PathToMOD);
    //clean up directory
    clean_temp_files();
    Close();
}

void BUNDLEBLDR::OnCheckBox1Click(wxCommandEvent& event)
{
    int size_h, size_v;
    Panel1->GetSize(&size_h, &size_v );

    wxClientDC dc(Panel1);

    // Ground Plane
    dc.SetPen( wxPen( (*wxBLACK) ,5 , wxSOLID) );
    dc.DrawLine( 0, size_v/2, size_h,size_v/2 );

    TextCtrl10->Enable();

}

void BUNDLEBLDR::OnCheckBox3Click(wxCommandEvent& event)
{
    if (CheckBox3->GetValue())
    {
        TextCtrl4->Enable();
        TextCtrl5->Enable();
        TextCtrl9->Enable();
    }

    //WriteBundleFile (TextCtrl1->GetValue());
}

void BUNDLEBLDR::OnComboBox1Selected(wxCommandEvent& event)
{
    wxString meshToView;
    meshToView<<ComboBox1->GetValue();
    draw_mesh(Panel1,meshToView);

    MeshSelected = 1;
}

void BUNDLEBLDR::OnTextCtrl4Text(wxCommandEvent& event)
{
    TextCtrl4->SetForegroundColour(*wxBLACK);
    int IsError = 0;
    check_is_numeric(TextCtrl4, &IsError);
}

void BUNDLEBLDR::OnInit(wxInitDialogEvent& event)
{
    TextCtrl4->SetForegroundColour(*wxLIGHT_GREY);
    TextCtrl5->SetForegroundColour(*wxLIGHT_GREY);
}

void BUNDLEBLDR::OnTextCtrl5Text(wxCommandEvent& event)
{
    TextCtrl5->SetForegroundColour(*wxBLACK);
    int IsError = 0;
    check_is_numeric(TextCtrl5, &IsError);
}

void BUNDLEBLDR::OnSpinButton1Change(wxSpinEvent& event)
{

    double maxDimension;

    wxString maxXY = TextCtrl8->GetValue();

    maxXY.ToDouble(&maxDimension);

    FormatPanel(maxDimension);

    DrawBundleCsection();

}

void BUNDLEBLDR::OnTextCtrl8TextEnter(wxCommandEvent& event)
{
    double maxDimension;

    wxString maxXY = TextCtrl8->GetValue();

    maxXY.ToDouble(&maxDimension);

    FormatPanel(maxDimension);

    DrawBundleCsection();

}

void BUNDLEBLDR::OnSpinButton1ChangeUp(wxSpinEvent& event)
{
    double maxDimension;

    wxString maxXY = TextCtrl8->GetValue();

    maxXY.ToDouble(&maxDimension);

    maxDimension = maxDimension + 0.001;

    maxXY = "";

    maxXY << maxDimension;

    TextCtrl8 ->SetValue(maxXY);

    FormatPanel(maxDimension);

    DrawBundleCsection();
}

void BUNDLEBLDR::OnSpinButton1ChangeDown(wxSpinEvent& event)
{
    double maxDimension;

    wxString maxXY = TextCtrl8->GetValue();

    maxXY.ToDouble(&maxDimension);

    maxDimension = maxDimension - 0.001;

    if (maxDimension <=0) maxDimension = 0;

    maxXY = "";

    maxXY << maxDimension;

    TextCtrl8 ->SetValue(maxXY);

    FormatPanel(maxDimension);

    DrawBundleCsection();
}