/////////////////////////////////////////////////////////////////////////////////
//
// 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
//     TWINAX.cpp
//
// DESCRIPTION
//     GUI for the construction of cable_spec file for cable type: Twinaxial
//
// AUTHOR(S)
//     Steve Greedy
//
/////////////////////////////////////////////////////////////////////////////////

#include "TWINAX.h"

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

//(*IdInit(TWINAX)
const long TWINAX::ID_STATICTEXT1 = wxNewId();
const long TWINAX::ID_TEXTCTRL1 = wxNewId();
const long TWINAX::ID_STATICTEXT2 = wxNewId();
const long TWINAX::ID_TEXTCTRL2 = wxNewId();
const long TWINAX::ID_STATICTEXT3 = wxNewId();
const long TWINAX::ID_TEXTCTRL3 = wxNewId();
const long TWINAX::ID_STATICTEXT4 = wxNewId();
const long TWINAX::ID_TEXTCTRL4 = wxNewId();
const long TWINAX::ID_STATICTEXT5 = wxNewId();
const long TWINAX::ID_TEXTCTRL5 = wxNewId();
const long TWINAX::ID_STATICTEXT6 = wxNewId();
const long TWINAX::ID_TEXTCTRL6 = wxNewId();
const long TWINAX::ID_STATICTEXT7 = wxNewId();
const long TWINAX::ID_TEXTCTRL7 = wxNewId();
const long TWINAX::ID_STATICTEXT8 = wxNewId();
const long TWINAX::ID_TEXTCTRL8 = wxNewId();
const long TWINAX::ID_STATICTEXT9 = wxNewId();
const long TWINAX::ID_TEXTCTRL9 = wxNewId();
const long TWINAX::ID_PANEL2 = wxNewId();
const long TWINAX::ID_STATICTEXT10 = wxNewId();
const long TWINAX::ID_TEXTCTRL10 = wxNewId();
const long TWINAX::ID_STATICTEXT11 = wxNewId();
const long TWINAX::ID_TEXTCTRL11 = wxNewId();
const long TWINAX::ID_STATICTEXT12 = wxNewId();
const long TWINAX::ID_STATICTEXT13 = wxNewId();
const long TWINAX::ID_STATICTEXT14 = wxNewId();
const long TWINAX::ID_CHECKBOX1 = wxNewId();
const long TWINAX::ID_PANEL4 = wxNewId();
const long TWINAX::ID_STATICTEXT23 = wxNewId();
const long TWINAX::ID_STATICTEXT24 = wxNewId();
const long TWINAX::ID_STATICTEXT25 = wxNewId();
const long TWINAX::ID_TEXTCTRL17 = wxNewId();
const long TWINAX::ID_STATICTEXT26 = wxNewId();
const long TWINAX::ID_TEXTCTRL18 = wxNewId();
const long TWINAX::ID_CHECKBOX4 = wxNewId();
const long TWINAX::ID_STATICTEXT15 = wxNewId();
const long TWINAX::ID_TEXTCTRL12 = wxNewId();
const long TWINAX::ID_STATICLINE1 = wxNewId();
const long TWINAX::ID_STATICLINE2 = wxNewId();
const long TWINAX::ID_STATICTEXT16 = wxNewId();
const long TWINAX::ID_TEXTCTRL13 = wxNewId();
const long TWINAX::ID_STATICTEXT17 = wxNewId();
const long TWINAX::ID_TEXTCTRL14 = wxNewId();
const long TWINAX::ID_STATICLINE3 = wxNewId();
const long TWINAX::ID_STATICLINE4 = wxNewId();
const long TWINAX::ID_STATICTEXT18 = wxNewId();
const long TWINAX::ID_TEXTCTRL15 = wxNewId();
const long TWINAX::ID_STATICTEXT19 = wxNewId();
const long TWINAX::ID_TEXTCTRL16 = wxNewId();
const long TWINAX::ID_PANEL3 = wxNewId();
const long TWINAX::ID_NOTEBOOK1 = wxNewId();
const long TWINAX::ID_STATICTEXT20 = wxNewId();
const long TWINAX::ID_CHECKBOX2 = wxNewId();
const long TWINAX::ID_STATICTEXT21 = wxNewId();
const long TWINAX::ID_COMBOBOX1 = wxNewId();
const long TWINAX::ID_STATICTEXT22 = wxNewId();
const long TWINAX::ID_CHECKBOX3 = wxNewId();
const long TWINAX::ID_BUTTON1 = wxNewId();
const long TWINAX::ID_BUTTON3 = wxNewId();
const long TWINAX::ID_BUTTON2 = wxNewId();
const long TWINAX::ID_PANEL1 = wxNewId();
//*)

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

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

	Create(parent, wxID_ANY, _("SACAMOS: TWINAX CABLE MODEL"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxMAXIMIZE_BOX|wxMINIMIZE_BOX, _T("wxID_ANY"));
	FlexGridSizer1 = new wxFlexGridSizer(0, 2, 0, 5);
	FlexGridSizer1->AddGrowableCol(1);
	StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("TWINAX Cable Properties"));
	FlexGridSizer2 = new wxFlexGridSizer(0, 1, 0, 0);
	BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
	StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Cable Name"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT1"));
	BoxSizer1->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"));
	BoxSizer1->Add(TextCtrl1, 2, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(BoxSizer1, 1, wxALL|wxEXPAND, 5);
	BoxSizer4 = new wxBoxSizer(wxHORIZONTAL);
	Notebook1 = new wxNotebook(this, ID_NOTEBOOK1, wxDefaultPosition, wxDefaultSize, 0, _T("ID_NOTEBOOK1"));
	Panel2 = new wxPanel(Notebook1, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL2"));
	FlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
	StaticText2 = new wxStaticText(Panel2, ID_STATICTEXT2, _("Inner Conductor Radius (m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
	FlexGridSizer3->Add(StaticText2, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl2 = new wxTextCtrl(Panel2, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
	FlexGridSizer3->Add(TextCtrl2, 1, wxALL, 5);
	StaticText3 = new wxStaticText(Panel2, ID_STATICTEXT3, _("Inner Dielectric Radius (m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
	FlexGridSizer3->Add(StaticText3, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl3 = new wxTextCtrl(Panel2, ID_TEXTCTRL3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
	FlexGridSizer3->Add(TextCtrl3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText4 = new wxStaticText(Panel2, ID_STATICTEXT4, _("Inner Conductor Separation (m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
	FlexGridSizer3->Add(StaticText4, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl4 = new wxTextCtrl(Panel2, ID_TEXTCTRL4, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL4"));
	FlexGridSizer3->Add(TextCtrl4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText5 = new wxStaticText(Panel2, ID_STATICTEXT5, _("Shield Radius (m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
	FlexGridSizer3->Add(StaticText5, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl5 = new wxTextCtrl(Panel2, ID_TEXTCTRL5, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL5"));
	FlexGridSizer3->Add(TextCtrl5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText6 = new wxStaticText(Panel2, ID_STATICTEXT6, _("Shield Thickness (m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
	FlexGridSizer3->Add(StaticText6, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl6 = new wxTextCtrl(Panel2, ID_TEXTCTRL6, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL6"));
	FlexGridSizer3->Add(TextCtrl6, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText7 = new wxStaticText(Panel2, ID_STATICTEXT7, _("Outer Dielectric Radius (m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT7"));
	FlexGridSizer3->Add(StaticText7, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl7 = new wxTextCtrl(Panel2, ID_TEXTCTRL7, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL7"));
	FlexGridSizer3->Add(TextCtrl7, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText8 = new wxStaticText(Panel2, ID_STATICTEXT8, _("Inner Conductor Conductivity (S/m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT8"));
	FlexGridSizer3->Add(StaticText8, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl8 = new wxTextCtrl(Panel2, ID_TEXTCTRL8, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL8"));
	FlexGridSizer3->Add(TextCtrl8, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText9 = new wxStaticText(Panel2, ID_STATICTEXT9, _("Shield Conductivity (S/m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT9"));
	FlexGridSizer3->Add(StaticText9, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl9 = new wxTextCtrl(Panel2, ID_TEXTCTRL9, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL9"));
	FlexGridSizer3->Add(TextCtrl9, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	Panel2->SetSizer(FlexGridSizer3);
	FlexGridSizer3->Fit(Panel2);
	FlexGridSizer3->SetSizeHints(Panel2);
	Panel4 = new wxPanel(Notebook1, ID_PANEL4, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL4"));
	FlexGridSizer4 = new wxFlexGridSizer(0, 2, 0, 0);
	FlexGridSizer4->AddGrowableCol(1);
	StaticText10 = new wxStaticText(Panel4, ID_STATICTEXT10, _("Inner Dielectric Permittivity"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT10"));
	FlexGridSizer4->Add(StaticText10, 1, wxALL, 5);
	TextCtrl10 = new wxTextCtrl(Panel4, ID_TEXTCTRL10, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL10"));
	FlexGridSizer4->Add(TextCtrl10, 1, wxALL|wxEXPAND, 5);
	StaticText11 = new wxStaticText(Panel4, ID_STATICTEXT11, _("Outer Dielectric Permittivity"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT11"));
	FlexGridSizer4->Add(StaticText11, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl11 = new wxTextCtrl(Panel4, ID_TEXTCTRL11, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL11"));
	FlexGridSizer4->Add(TextCtrl11, 1, wxALL|wxEXPAND, 5);
	StaticText12 = new wxStaticText(Panel4, ID_STATICTEXT12, _("Or"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT12"));
	FlexGridSizer4->Add(StaticText12, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText13 = new wxStaticText(Panel4, ID_STATICTEXT13, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT13"));
	FlexGridSizer4->Add(StaticText13, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText14 = new wxStaticText(Panel4, ID_STATICTEXT14, _("Frequency Dependant Model"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT14"));
	FlexGridSizer4->Add(StaticText14, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	CheckBox1 = new wxCheckBox(Panel4, ID_CHECKBOX1, _("Yes"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
	CheckBox1->SetValue(false);
	FlexGridSizer4->Add(CheckBox1, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	Panel4->SetSizer(FlexGridSizer4);
	FlexGridSizer4->Fit(Panel4);
	FlexGridSizer4->SetSizeHints(Panel4);
	Panel3 = new wxPanel(Notebook1, ID_PANEL3, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL3"));
	FlexGridSizer5 = new wxFlexGridSizer(0, 1, 0, 0);
	FlexGridSizer5->AddGrowableCol(0);
	FlexGridSizer8 = new wxFlexGridSizer(0, 2, 0, 0);
	StaticText23 = new wxStaticText(Panel3, ID_STATICTEXT23, _("R + j w L"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT23"));
	FlexGridSizer8->Add(StaticText23, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	StaticText24 = new wxStaticText(Panel3, ID_STATICTEXT24, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT24"));
	FlexGridSizer8->Add(StaticText24, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText25 = new wxStaticText(Panel3, ID_STATICTEXT25, _("R (ohms/m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT25"));
	FlexGridSizer8->Add(StaticText25, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl17 = new wxTextCtrl(Panel3, ID_TEXTCTRL17, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL17"));
	FlexGridSizer8->Add(TextCtrl17, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText26 = new wxStaticText(Panel3, ID_STATICTEXT26, _("H (henries/m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT26"));
	FlexGridSizer8->Add(StaticText26, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl18 = new wxTextCtrl(Panel3, ID_TEXTCTRL18, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL18"));
	FlexGridSizer8->Add(TextCtrl18, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	CheckBox4 = new wxCheckBox(Panel3, ID_CHECKBOX4, _("Advanced Description"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX4"));
	CheckBox4->SetValue(false);
	FlexGridSizer8->Add(CheckBox4, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer5->Add(FlexGridSizer8, 1, wxALL|wxEXPAND, 5);
	FlexGridSizer7 = new wxFlexGridSizer(0, 2, 0, 0);
	StaticText15 = new wxStaticText(Panel3, ID_STATICTEXT15, _("Angular f Normalisation"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT15"));
	FlexGridSizer7->Add(StaticText15, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl12 = new wxTextCtrl(Panel3, ID_TEXTCTRL12, _("1"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL12"));
	TextCtrl12->Disable();
	FlexGridSizer7->Add(TextCtrl12, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticLine1 = new wxStaticLine(Panel3, ID_STATICLINE1, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE1"));
	FlexGridSizer7->Add(StaticLine1, 1, wxALL|wxEXPAND, 5);
	StaticLine2 = new wxStaticLine(Panel3, ID_STATICLINE2, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE2"));
	FlexGridSizer7->Add(StaticLine2, 1, wxALL|wxEXPAND, 5);
	StaticText16 = new wxStaticText(Panel3, ID_STATICTEXT16, _("Order of Numerator Model"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT16"));
	FlexGridSizer7->Add(StaticText16, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl13 = new wxTextCtrl(Panel3, ID_TEXTCTRL13, _("1"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL13"));
	TextCtrl13->Disable();
	FlexGridSizer7->Add(TextCtrl13, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText17 = new wxStaticText(Panel3, ID_STATICTEXT17, _("Numerator Coefficients"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT17"));
	FlexGridSizer7->Add(StaticText17, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl14 = new wxTextCtrl(Panel3, ID_TEXTCTRL14, _("R L"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL14"));
	TextCtrl14->Disable();
	FlexGridSizer7->Add(TextCtrl14, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticLine3 = new wxStaticLine(Panel3, ID_STATICLINE3, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE3"));
	FlexGridSizer7->Add(StaticLine3, 1, wxALL|wxEXPAND, 5);
	StaticLine4 = new wxStaticLine(Panel3, ID_STATICLINE4, wxDefaultPosition, wxSize(10,-1), wxLI_HORIZONTAL, _T("ID_STATICLINE4"));
	FlexGridSizer7->Add(StaticLine4, 1, wxALL|wxEXPAND, 5);
	StaticText18 = new wxStaticText(Panel3, ID_STATICTEXT18, _("Order of Denominator Model"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT18"));
	FlexGridSizer7->Add(StaticText18, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl15 = new wxTextCtrl(Panel3, ID_TEXTCTRL15, _("0"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL15"));
	TextCtrl15->Disable();
	FlexGridSizer7->Add(TextCtrl15, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText19 = new wxStaticText(Panel3, ID_STATICTEXT19, _("Denominator Coefficients"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT19"));
	FlexGridSizer7->Add(StaticText19, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl16 = new wxTextCtrl(Panel3, ID_TEXTCTRL16, _("1"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL16"));
	TextCtrl16->Disable();
	FlexGridSizer7->Add(TextCtrl16, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer5->Add(FlexGridSizer7, 1, wxALL|wxEXPAND, 5);
	Panel3->SetSizer(FlexGridSizer5);
	FlexGridSizer5->Fit(Panel3);
	FlexGridSizer5->SetSizeHints(Panel3);
	Notebook1->AddPage(Panel2, _("General"), false);
	Notebook1->AddPage(Panel4, _("Material"), false);
	Notebook1->AddPage(Panel3, _("Transfer Impedance"), false);
	BoxSizer4->Add(Notebook1, 1, wxALL|wxEXPAND, 5);
	FlexGridSizer2->Add(BoxSizer4, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer6 = new wxFlexGridSizer(0, 2, 0, 0);
	StaticText20 = new wxStaticText(this, ID_STATICTEXT20, _("Use Laplace"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT20"));
	FlexGridSizer6->Add(StaticText20, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	CheckBox2 = new wxCheckBox(this, ID_CHECKBOX2, _("Yes"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX2"));
	CheckBox2->SetValue(false);
	FlexGridSizer6->Add(CheckBox2, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	StaticText21 = new wxStaticText(this, ID_STATICTEXT21, _("View Mesh"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT21"));
	FlexGridSizer6->Add(StaticText21, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	ComboBox1 = new wxComboBox(this, ID_COMBOBOX1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_COMBOBOX1"));
	FlexGridSizer6->Add(ComboBox1, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	StaticText22 = new wxStaticText(this, ID_STATICTEXT22, _("Refine Laplace Mesh"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT22"));
	FlexGridSizer6->Add(StaticText22, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	CheckBox3 = new wxCheckBox(this, ID_CHECKBOX3, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX3"));
	CheckBox3->SetValue(false);
	CheckBox3->Disable();
	FlexGridSizer6->Add(CheckBox3, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(FlexGridSizer6, 1, wxALL|wxEXPAND, 5);
	StaticBoxSizer1->Add(FlexGridSizer2, 8, wxALL, 5);
	BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
	Button1 = new wxButton(this, ID_BUTTON1, _("SAVE"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
	BoxSizer2->Add(Button1, 1, wxALL|wxALIGN_BOTTOM, 5);
	Button3 = new wxButton(this, ID_BUTTON3, _("BUILD"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON3"));
	BoxSizer2->Add(Button3, 1, wxALL|wxALIGN_BOTTOM, 5);
	Button2 = new wxButton(this, ID_BUTTON2, _("CLOSE"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
	BoxSizer2->Add(Button2, 1, wxALL|wxALIGN_BOTTOM, 5);
	StaticBoxSizer1->Add(BoxSizer2, 1, wxALL|wxEXPAND, 5);
	FlexGridSizer1->Add(StaticBoxSizer1, 1, wxALL|wxEXPAND, 5);
	StaticBoxSizer2 = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Cross Section"));
	Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxSize(500,500), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
	Panel1->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
	Panel1->SetToolTip(_("Double Click to Reset Schematic"));
	Panel1->SetHelpText(_("Double Click to Reset Schematic"));
	StaticBoxSizer2->Add(Panel1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer1->Add(StaticBoxSizer2, 1, wxALL|wxALIGN_LEFT|wxALIGN_TOP, 5);
	SetSizer(FlexGridSizer1);
	FlexGridSizer1->Fit(this);
	FlexGridSizer1->SetSizeHints(this);

	Connect(ID_TEXTCTRL2,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl2Text);
	Connect(ID_TEXTCTRL3,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl3Text);
	Connect(ID_TEXTCTRL4,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl4Text);
	Connect(ID_TEXTCTRL5,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl5Text);
	Connect(ID_TEXTCTRL6,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl6Text);
	Connect(ID_TEXTCTRL7,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl7Text);
	Connect(ID_TEXTCTRL8,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl8Text);
	Connect(ID_TEXTCTRL9,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl9Text);
	Connect(ID_TEXTCTRL10,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl10Text);
	Connect(ID_TEXTCTRL11,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl11Text);
	Connect(ID_CHECKBOX1,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&TWINAX::OnCheckBox1Click);
	Connect(ID_TEXTCTRL17,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl17Text);
	Connect(ID_TEXTCTRL18,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl18Text);
	Connect(ID_CHECKBOX4,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&TWINAX::OnCheckBox4Click);
	Connect(ID_TEXTCTRL12,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl12Text);
	Connect(ID_TEXTCTRL13,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl13Text);
	Connect(ID_TEXTCTRL14,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl14Text);
	Connect(ID_TEXTCTRL15,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl15Text);
	Connect(ID_TEXTCTRL16,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&TWINAX::OnTextCtrl16Text);
	Connect(ID_NOTEBOOK1,wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING,(wxObjectEventFunction)&TWINAX::OnNotebook1PageChanging);
	Connect(ID_COMBOBOX1,wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)&TWINAX::OnComboBox1Selected);
	Connect(ID_CHECKBOX3,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&TWINAX::OnCheckBox3Click);
	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&TWINAX::OnButton1Click);
	Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&TWINAX::OnButton3Click);
	Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&TWINAX::OnButton2Click);
	Panel1->Connect(wxEVT_PAINT,(wxObjectEventFunction)&TWINAX::OnPanel1Paint,0,this);
	Panel1->Connect(wxEVT_LEFT_DCLICK,(wxObjectEventFunction)&TWINAX::OnPanel1LeftDClick,0,this);
	Connect(wxID_ANY,wxEVT_INIT_DIALOG,(wxObjectEventFunction)&TWINAX::OnInit);
	Connect(wxEVT_PAINT,(wxObjectEventFunction)&TWINAX::OnPaint);
	//*)
}

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

void TWINAX::OnInit(wxInitDialogEvent& event)
{
    TextCtrl2->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    TextCtrl3->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    TextCtrl4->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    TextCtrl5->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    TextCtrl6->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    TextCtrl7->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    TextCtrl8->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    TextCtrl9->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    TextCtrl10->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    TextCtrl11->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
    CheckBox1->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&TWINAX::OnHighlightSchematic, this);
}


void TWINAX::OnPaint(wxPaintEvent& event)
{
    if (EDIT_EXISTING==true) EditExistingCable();
}

void TWINAX::SetPathToMOD(wxString Path, wxString Name)
{

    pathToMOD << Path;
    MODname << Name;
}

void TWINAX::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;
    }

    check_is_empty(TextCtrl2, &IsError);
    check_is_empty(TextCtrl3, &IsError);
    check_is_empty(TextCtrl4, &IsError);
    check_is_empty(TextCtrl5, &IsError);
    check_is_empty(TextCtrl6, &IsError);
    check_is_empty(TextCtrl7, &IsError);
    check_is_empty(TextCtrl8, &IsError);
    check_is_empty(TextCtrl9, &IsError);

    if (CheckBox1->GetValue())
    {

    }
    else
    {
        check_is_empty(TextCtrl10, &IsError);
        check_is_empty(TextCtrl11, &IsError);
    }


    if (CheckBox4->GetValue())
    {
        check_is_empty(TextCtrl12, &IsError);
        check_is_empty(TextCtrl13, &IsError);
        check_is_empty(TextCtrl14, &IsError);
        check_is_empty(TextCtrl15, &IsError);
        check_is_empty(TextCtrl16, &IsError);
    }
    else
    {
        check_is_empty(TextCtrl17, &IsError);
        check_is_empty(TextCtrl18, &IsError);
    }

    if ( IsError == 1)
    {
        wxMessageBox("Please fix highlighted errors" , _("Non numeric entry"));
        return;
    }

    WriteCableFile (fileName);

    Button1->Disable();
}

void TWINAX::OnButton3Click(wxCommandEvent& event)
{
    //clean up directory
    clean_temp_files();

    //CABLE BUIDER
    wxString fileName = TextCtrl1->GetValue();
    wxString command_line;

    wxString separator(wxFileName::GetPathSeparator());

    std::stringstream stream;

    stream  <<"." + separator
            << "cable_model_builder"
            << " "
            << ".." + separator + MODname + separator + "CABLE" + separator
            << fileName ;


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

    wxExecute (command_line, wxEXEC_SYNC);

    // Display Run Status
    RUN_STATUS *run_status = new RUN_STATUS(this);
    run_status->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 TWINAX::OnButton2Click(wxCommandEvent& event)
{
    //clean up directory
    clean_temp_files();
    Close();
}

void TWINAX::OnCheckBox1Click(wxCommandEvent& event)
{
    FD_ESR *winFD_ESR = new FD_ESR(this);

    if ( winFD_ESR->ShowModal() == wxID_OK )
    {
        FD_ESR1 = winFD_ESR->TextCtrl1->GetValue();
        FD_ESR2 = winFD_ESR->TextCtrl2->GetValue();
        FD_ESR3 = winFD_ESR->TextCtrl3->GetValue();
        FD_ESR4 = winFD_ESR->TextCtrl4->GetValue();
        FD_ESR5 = winFD_ESR->TextCtrl5->GetValue();

        FD_ESR6 = winFD_ESR->TextCtrl6->GetValue();
        FD_ESR7 = winFD_ESR->TextCtrl7->GetValue();
        FD_ESR8 = winFD_ESR->TextCtrl8->GetValue();
        FD_ESR9 = winFD_ESR->TextCtrl9->GetValue();
        FD_ESR10= winFD_ESR->TextCtrl10->GetValue();


        FD_Default = winFD_ESR->CheckBox1->GetValue();
        FD_ORDER = winFD_ESR->TextCtrl11->GetValue();
        FD_lin   = winFD_ESR->RadioButton1->GetValue();
        FD_Fmin  = winFD_ESR->TextCtrl12->GetValue();
        FD_Fmax  = winFD_ESR->TextCtrl13->GetValue();
        FD_Num   = winFD_ESR->TextCtrl14->GetValue();
    }
    winFD_ESR->Destroy();
}

void TWINAX::OnTextCtrl2Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl2, &IsError);
    check_is_positive (TextCtrl2, &IsError);
}

void TWINAX::OnTextCtrl3Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl3, &IsError);
    check_is_positive (TextCtrl3, &IsError);
    check_is_less_than(TextCtrl3, TextCtrl2, &IsError);
}

void TWINAX::OnTextCtrl4Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl4, &IsError);
    check_is_positive (TextCtrl3, &IsError);

    double value_tb3, value_tb4;
    wxString contents_tb3, contents_tb4;

    contents_tb3 = TextCtrl3->GetValue();
    contents_tb4 = TextCtrl4->GetValue();

    contents_tb3.ToDouble(&value_tb3);
    contents_tb4.ToDouble(&value_tb4);

    if (value_tb4 <= (value_tb3 + value_tb3))
    {
        TextCtrl4->SetBackgroundColour(wxColor(255,153,153));
        TextCtrl4->SetFocus();
        IsError = 1;
    }
}

void TWINAX::OnTextCtrl5Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl5, &IsError);
    check_is_positive (TextCtrl3, &IsError);

    // Is shield radius < inner conductor requirements
    double value_tb3, value_tb4, value_tb5;
    wxString contents_tb3, contents_tb4, contents_tb5;

    contents_tb3 = TextCtrl3->GetValue();
    contents_tb4 = TextCtrl4->GetValue();
    contents_tb5 = TextCtrl5->GetValue();

    contents_tb3.ToDouble(&value_tb3);
    contents_tb4.ToDouble(&value_tb4);
    contents_tb5.ToDouble(&value_tb5);

    if (value_tb5 < (value_tb3 + value_tb3 + value_tb4)){
        TextCtrl5->SetBackgroundColour(wxColor(255,153,153));
        TextCtrl5->SetFocus();
        IsError = 1;
    }
}

void TWINAX::OnTextCtrl6Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl6, &IsError);
    check_is_positive (TextCtrl6, &IsError);
}

void TWINAX::OnTextCtrl7Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl7, &IsError);
    check_is_positive (TextCtrl3, &IsError);

    // Is outer dielectric radius > shield radius + shield thickness
    double value_tb5, value_tb6, value_tb7;
    wxString contents_tb5, contents_tb6, contents_tb7;

    contents_tb7 = TextCtrl7->GetValue();
    contents_tb5 = TextCtrl5->GetValue();
    contents_tb6 = TextCtrl6->GetValue();

    contents_tb7.ToDouble(&value_tb7);
    contents_tb5.ToDouble(&value_tb5);
    contents_tb6.ToDouble(&value_tb6);

    if (value_tb7 < (value_tb5 + value_tb6)){
        TextCtrl7->SetBackgroundColour(wxColor(255,153,153));
        TextCtrl7->SetFocus();
        IsError = 1;
    }
}

void TWINAX::OnTextCtrl8Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl8, &IsError);
    check_is_positive (TextCtrl8, &IsError);
}

void TWINAX::OnTextCtrl9Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl9, &IsError);
    check_is_positive (TextCtrl9, &IsError);
}

void TWINAX::OnTextCtrl10Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl10, &IsError);
    check_is_positive (TextCtrl10, &IsError);
}

void TWINAX::OnTextCtrl11Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl11, &IsError);
    check_is_positive (TextCtrl11, &IsError);
}

void TWINAX::OnTextCtrl12Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl12, &IsError);
}

void TWINAX::OnTextCtrl13Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl13, &IsError);
}

void TWINAX::OnTextCtrl14Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl14, &IsError);
}

void TWINAX::OnTextCtrl15Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl15, &IsError);
}

void TWINAX::OnTextCtrl16Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl16, &IsError);
}

void TWINAX::OnTextCtrl17Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric(TextCtrl17, &IsError);
    check_is_positive(TextCtrl17, &IsError);
}

void TWINAX::OnTextCtrl18Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric(TextCtrl18, &IsError);
    check_is_positive(TextCtrl18, &IsError);
}

void TWINAX::WriteCableFile (wxString fileName)
{
    ofstream cableFile;

    wxString separator(wxFileName::GetPathSeparator());

    wxString fullFileName = pathToMOD + separator + "CABLE" + separator + fileName + ".cable_spec";

    cableFile.open (fullFileName);

    if (cableFile.is_open())
    {

        // minimum requirements for type Twinax
        cableFile <<"# MOD_cable_lib_dir \n";
        cableFile <<".." << separator << MODname << separator << "CABLE" << separator <<"\n";
        cableFile <<"Twinax\n";
        cableFile <<"3 \t#number of conductors \n";
        cableFile <<"8 \t#number of parameters \n";

        cableFile << TextCtrl2->GetValue() <<" \t# parameter 1: inner conductor radius (m)\n";
        cableFile << TextCtrl3->GetValue() <<" \t# parameter 2: inner dielectric radius (m)\n";
        cableFile << TextCtrl4->GetValue() <<" \t# parameter 3: inner conductor separation (m)\n";
        cableFile << TextCtrl5->GetValue() <<" \t# parameter 4: shield radius (m)\n";
        cableFile << TextCtrl6->GetValue() <<" \t# parameter 5: shield thickness (m)\n";
        cableFile << TextCtrl7->GetValue() <<" \t# parameter 6: outer dielectric radius (m)\n";
        cableFile << TextCtrl8->GetValue() <<" \t# parameter 7: inner conductor electric conductivity (m)\n";
        cableFile << TextCtrl9->GetValue() <<" \t# parameter 8: shield electric conductivity (m)\n";

        cableFile <<"2 \t#number of frequency dependent parameters \n";

        if (CheckBox1->GetValue()){
            cableFile << "# Inner dielectric relative permittivity\n";
            cableFile << FD_ESR1 <<" \t# w normalisation constant\n";
            cableFile << FD_ESR2 <<" # a order, a coefficents follow below\n";
            cableFile << FD_ESR3 <<" \n";
            cableFile << FD_ESR4 <<" # b order, b coefficents follow below\n";
            cableFile << FD_ESR5 <<" \n";

            cableFile << "#  Outer dielectric relative permittivity\n";
            cableFile << FD_ESR6 <<" \t# w normalisation constant\n";
            cableFile << FD_ESR7 <<" \t# a order, a coefficents follow below\n";
            cableFile << FD_ESR8 <<" \n";
            cableFile << FD_ESR9 <<" \t# b order, b coefficents follow below\n";
            cableFile << FD_ESR10<<" \n";

        }

        else{
            cableFile << "\t# Inner dielectric relative permittivity\n";
            cableFile << "1.0 \t# w normalisation constant\n";
            cableFile << "0 \t# a order, a coefficents follow below\n";
            cableFile << TextCtrl10->GetValue()<<"\n";
            cableFile << "0 \t# b order, b coefficents follow below\n";
            cableFile << "1.0\n";

            cableFile << "#  Outer dielectric relative permittivity\n";
            cableFile << "1.0 # w normalisation constant\n";
            cableFile << "0 # a order, a coefficents follow below\n";
            cableFile << TextCtrl11->GetValue()<<"\n";
            cableFile << "0 # b order, b coefficents follow below\n";
            cableFile << "1.0\n";
        }
        cableFile << "1 # number of frequency dependent transfer impedance models\n";
        cableFile << "#  Transfer impedance model \n";

        if (CheckBox4->GetValue())
        {
            cableFile << TextCtrl12->GetValue() <<" # angular frequency normalisation\n";
            cableFile << TextCtrl13->GetValue() <<" # order of numerator model\n";
            cableFile << TextCtrl14->GetValue() <<" # list of numerator coefficients a0 a1 a2... \n";
            cableFile << TextCtrl15->GetValue() <<" # order of denominator model\n";
            cableFile << TextCtrl16->GetValue() <<" # list of denominator coefficients b0 b1 b2... \n";
        }
        else
        {
            cableFile << "1 # angular frequency normalisation\n";
            cableFile << "1 # order of numerator model\n";
            cableFile << TextCtrl17->GetValue() <<" ";
            cableFile << TextCtrl18->GetValue() <<" \t# list of numerator coefficients a0 a1 a2... \n";
            cableFile << "0 # order of denominator model\n";
            cableFile << "1 # list of denominator coefficients b0 b1 b2... \n";
        }

        if (!FD_Default){

            cableFile << FD_ORDER <<"\t # order for filter fitting\n";
            if (FD_lin)
            {
                cableFile << "lin   # frequency range type for filter fitting type (lin or dB)\n";
            }
            else
            {
                cableFile << "log   # frequency range type for filter fitting type (lin or dB)\n";
            }
            cableFile << FD_Fmin <<" "<< FD_Fmax <<" "<< FD_Num <<"\t # fmin fmax number_of_frequencies for filter fitting\n";
        }

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

        if (CheckBox3->GetValue())
        {
            //cableFile << "Laplace_boundary_constant\n";
            //cableFile << MESH_PARAM1 <<"\n";
            cableFile << "Laplace_surface_mesh_constant\n";
            cableFile << MESH_PARAM2 <<"\n";
            //cableFile << "max_mesh_edge_length\n";
            //cableFile << MESH_PARAM3 <<"\n";

            CheckBox3 ->SetValue(false);
        }
    }
    cableFile.close();
}

void TWINAX::OnPanel1Paint(wxPaintEvent& event)
{
    twinaxSchematic();
}

void TWINAX::twinaxSchematic()
{
    int size_h, size_v;
    Panel1->GetSize(&size_h, &size_v );

    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(*wxBLUE);
    dc.DrawText("General Twinax Cable", 10, 15);

    float conductor_radius, dielectric_radius, insulation_radius, shield_radius, air_radius;

    insulation_radius = 0.3 * size_h;
    shield_radius = 0.26 * size_h;
    air_radius = 0.25 * size_h;
    dielectric_radius = 0.075 * size_h;
    conductor_radius = 0.06 * size_h;

    dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
    dc.SetBrush(wxBrush(wxColor(224,224,224), wxBDIAGONAL_HATCH));
    dc.DrawCircle( wxPoint(size_h/2,size_v/2), insulation_radius );

    dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
    dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
    dc.DrawCircle( wxPoint(size_h/2,size_v/2), shield_radius );

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

    dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
    dc.SetBrush(wxBrush(wxColor(224,224,224), wxFDIAGONAL_HATCH));
    dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), dielectric_radius );

    dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
    dc.SetBrush(wxBrush(wxColor(224,224,224), wxFDIAGONAL_HATCH));
    dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), dielectric_radius );

    dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
    dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
    dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), conductor_radius );

    dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
    dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
    dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), conductor_radius );
}

void TWINAX::OnHighlightSchematic(wxCommandEvent& event)
{
    twinaxSchematic();

    int ID = event.GetId();
    event.Skip(true);

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

    float conductor_radius, dielectric_radius, insulation_radius, shield_radius, air_radius;

    insulation_radius = 0.3 * size_h;
    shield_radius = 0.26 * size_h;
    air_radius = 0.25 * size_h;
    dielectric_radius = 0.075 * size_h;
    conductor_radius = 0.06 * size_h;

    float x, y;

    wxClientDC dc(Panel1);

    wxPoint arrowHead[3];

    if ( ID == ID_TEXTCTRL2)
    {
        x = conductor_radius * 0.7071;
        y = conductor_radius * 0.7071;
        dc.SetPen(wxPen(wxColor(51,51,255), 3));
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)),4 );
        dc.DrawLine( size_h/2,size_v/2-(0.1*size_v), size_h/2+x,size_v/2-(0.1*size_v)-y );

        arrowHead[0] = wxPoint(size_h/2+x,size_v/2-(0.1*size_v)-y);
        arrowHead[1] = wxPoint(size_h/2+x-5,size_v/2-(0.1*size_v)-y);
        arrowHead[2] = wxPoint(size_h/2+x,size_v/2-(0.1*size_v)-y+5);
        dc.DrawPolygon(WXSIZEOF(arrowHead), arrowHead);
    }

    if ( ID == ID_TEXTCTRL3)
    {
        x = dielectric_radius * 0.7071;
        y = dielectric_radius * 0.7071;
        dc.SetPen(wxPen(wxColor(51,51,255), 3));
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)),4 );
        dc.DrawLine( size_h/2,size_v/2-(0.1*size_v), size_h/2-x,size_v/2-(0.1*size_v)-y );

        arrowHead[0] = wxPoint(size_h/2-x,size_v/2-(0.1*size_v)-y);
        arrowHead[1] = wxPoint(size_h/2-x+5,size_v/2-(0.1*size_v)-y);
        arrowHead[2] = wxPoint(size_h/2-x,size_v/2-(0.1*size_v)-y+5);
        dc.DrawPolygon(WXSIZEOF(arrowHead), arrowHead);
    }

    if ( ID == ID_TEXTCTRL4)
    {
        dc.SetPen(wxPen(wxColor(51,51,255), 3));
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));
        dc.DrawLine( size_h/2,size_v/2-(0.1*size_v),  size_h/2,size_v/2+(0.1*size_v) );

        arrowHead[0] = wxPoint(size_h/2,size_v/2-(0.1*size_v));
        arrowHead[1] = wxPoint(size_h/2+5,size_v/2-(0.1*size_v)+5);
        arrowHead[2] = wxPoint(size_h/2-5,size_v/2-(0.1*size_v)+5);
        dc.DrawPolygon(WXSIZEOF(arrowHead), arrowHead);

        arrowHead[0] = wxPoint(size_h/2,size_v/2+(0.1*size_v));
        arrowHead[1] = wxPoint(size_h/2+5,size_v/2+(0.1*size_v)-5);
        arrowHead[2] = wxPoint(size_h/2-5,size_v/2+(0.1*size_v)-5);
        dc.DrawPolygon(WXSIZEOF(arrowHead), arrowHead);
    }

    if ( ID == ID_TEXTCTRL5)
    {
        x = shield_radius * 0.7071;
        y = shield_radius * 0.7071;
        dc.SetPen(wxPen(wxColor(51,51,255), 3));
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2),4 );
        dc.DrawLine( size_h/2,size_v/2, size_h/2-x,size_v/2-y );

        arrowHead[0] = wxPoint(size_h/2-x,size_v/2-y);
        arrowHead[1] = wxPoint(size_h/2-x+5,size_v/2-y);
        arrowHead[2] = wxPoint(size_h/2-x,size_v/2-y+5);
        dc.DrawPolygon(WXSIZEOF(arrowHead), arrowHead);
    }

    if ( ID == ID_TEXTCTRL6)
    {
        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), shield_radius );

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

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), conductor_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), conductor_radius );
    }

    if ( ID == ID_TEXTCTRL7)
    {
        x = insulation_radius * 0.7071;
        y = insulation_radius * 0.7071;
        dc.SetPen(wxPen(wxColor(51,51,255), 3));
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2),4 );
        dc.DrawLine( size_h/2,size_v/2, size_h/2+x,size_v/2-y );

        arrowHead[0] = wxPoint(size_h/2+x,size_v/2-y);
        arrowHead[1] = wxPoint(size_h/2+x-5,size_v/2-y);
        arrowHead[2] = wxPoint(size_h/2+x,size_v/2-y+5);
        dc.DrawPolygon(WXSIZEOF(arrowHead), arrowHead);
    }

    if ( ID == ID_TEXTCTRL8)
    {
        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), conductor_radius );

        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), conductor_radius );
    }

    if ( ID == ID_TEXTCTRL9)
    {
        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), shield_radius );

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

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), conductor_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), conductor_radius );

    }

    if ( ID == ID_TEXTCTRL10)
    {
        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), conductor_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), conductor_radius );

    }

    if ( ID == ID_TEXTCTRL11)
    {
        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), insulation_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), shield_radius );

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

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), conductor_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), conductor_radius );
    }

    if ( ID == ID_CHECKBOX1)
    {
        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxBDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), insulation_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2), shield_radius );

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

        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(51,51,255),1 ) );
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxFDIAGONAL_HATCH));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), dielectric_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2+(0.1*size_v)), conductor_radius );

        dc.SetPen( wxPen( wxColor(192,192,192),1 ) );
        dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
        dc.DrawCircle( wxPoint(size_h/2,size_v/2-(0.1*size_v)), conductor_radius );
    }
}

void TWINAX::OnNotebook1PageChanging(wxNotebookEvent& event)
{
    twinaxSchematic();
}

void TWINAX::OnPanel1LeftDClick(wxMouseEvent& event)
{
    twinaxSchematic();
}

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

void TWINAX::OnCheckBox3Click(wxCommandEvent& event)
{
    if (CheckBox3->GetValue())
    {
        MESH_PARAM *winMESH_PARAM = new MESH_PARAM(this);

        winMESH_PARAM->TextCtrl1->Disable();
        winMESH_PARAM->TextCtrl3->Disable();
        winMESH_PARAM->TextCtrl4->Disable();

        if ( winMESH_PARAM->ShowModal() == wxID_OK )
        {
            //MESH_PARAM1 = winMESH_PARAM->TextCtrl1->GetValue();
            MESH_PARAM2 = winMESH_PARAM->TextCtrl2->GetValue();
            //MESH_PARAM3 = winMESH_PARAM->TextCtrl3->GetValue();
        }
        winMESH_PARAM->Destroy();
    }

    WriteCableFile (TextCtrl1->GetValue());
}

void TWINAX::OnCheckBox4Click(wxCommandEvent& event)
{
    if (CheckBox4->GetValue())
    {
        TextCtrl17->Disable();
        TextCtrl18->Disable();
        TextCtrl12->Enable();
        TextCtrl13->Enable();
        TextCtrl14->Enable();
        TextCtrl15->Enable();
        TextCtrl16->Enable();
    }
    else
    {
        TextCtrl17->Enable();
        TextCtrl18->Enable();
        TextCtrl12->Disable();
        TextCtrl13->Disable();
        TextCtrl14->Disable();
        TextCtrl15->Disable();
        TextCtrl16->Disable();
    }

}

void TWINAX::EditExistingCable()
{
    Close();
}
