Blame view

GUI/SW1/SRC/DCONN.cpp 25 KB
886c558b   Steve Greedy   SACAMOS Public Re...
1
2
3
4
5
6
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
2a0d305e   Steve Greedy   Modifications to ...
7
// Copyright (C) 2015 - 2018 University of Nottingham
886c558b   Steve Greedy   SACAMOS Public Re...
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
//
// 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
//     DCONN.cpp
//
// DESCRIPTION
//     GUI for the construction of cable_spec file for cable type: Dconnector
//
// AUTHOR(S)
//     Steve Greedy
//
/////////////////////////////////////////////////////////////////////////////////
#include "DCONN.h"

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

//(*IdInit(DCONN)
const long DCONN::ID_STATICTEXT1 = wxNewId();
const long DCONN::ID_TEXTCTRL1 = wxNewId();
const long DCONN::ID_STATICTEXT2 = wxNewId();
const long DCONN::ID_TEXTCTRL2 = wxNewId();
const long DCONN::ID_STATICTEXT3 = wxNewId();
const long DCONN::ID_TEXTCTRL3 = wxNewId();
const long DCONN::ID_STATICTEXT4 = wxNewId();
const long DCONN::ID_TEXTCTRL4 = wxNewId();
const long DCONN::ID_STATICTEXT5 = wxNewId();
const long DCONN::ID_TEXTCTRL5 = wxNewId();
const long DCONN::ID_STATICTEXT6 = wxNewId();
const long DCONN::ID_CHECKBOX1 = wxNewId();
const long DCONN::ID_STATICTEXT7 = wxNewId();
const long DCONN::ID_COMBOBOX1 = wxNewId();
const long DCONN::ID_STATICTEXT8 = wxNewId();
const long DCONN::ID_CHECKBOX2 = wxNewId();
const long DCONN::ID_BUTTON1 = wxNewId();
const long DCONN::ID_BUTTON2 = wxNewId();
const long DCONN::ID_BUTTON3 = wxNewId();
const long DCONN::ID_PANEL1 = wxNewId();
//*)

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

DCONN::DCONN(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
	//(*Initialize(DCONN)
	wxStaticBoxSizer* StaticBoxSizer2;
	wxFlexGridSizer* FlexGridSizer4;
	wxFlexGridSizer* FlexGridSizer3;
	wxFlexGridSizer* FlexGridSizer2;
	wxBoxSizer* BoxSizer2;
	wxStaticBoxSizer* StaticBoxSizer3;
	wxBoxSizer* BoxSizer1;
	wxStaticBoxSizer* StaticBoxSizer1;
	wxFlexGridSizer* FlexGridSizer1;

	Create(parent, wxID_ANY, _("SACAMOS: D-SUB CONNECTOR MODEL"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
	FlexGridSizer1 = new wxFlexGridSizer(0, 2, 0, 0);
	StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, this, _("D-SUB Connector Parameters"));
	FlexGridSizer2 = new wxFlexGridSizer(0, 1, 0, 0);
	BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
	StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Connector 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, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(BoxSizer1, 1, wxALL|wxEXPAND, 5);
	StaticBoxSizer3 = new wxStaticBoxSizer(wxHORIZONTAL, this, _("General Properties"));
	FlexGridSizer3 = new wxFlexGridSizer(0, 2, 0, 0);
	StaticText2 = new wxStaticText(this, ID_STATICTEXT2, _("Conductor Radius"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT2"));
	FlexGridSizer3->Add(StaticText2, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl2 = new wxTextCtrl(this, ID_TEXTCTRL2, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
	FlexGridSizer3->Add(TextCtrl2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticText3 = new wxStaticText(this, ID_STATICTEXT3, _("Conductor Separation X (m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT3"));
	FlexGridSizer3->Add(StaticText3, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl3 = new wxTextCtrl(this, 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(this, ID_STATICTEXT4, _("Conductor Separation Y (m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT4"));
	FlexGridSizer3->Add(StaticText4, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl4 = new wxTextCtrl(this, 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(this, ID_STATICTEXT5, _("Shield Offset (m)"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT5"));
	FlexGridSizer3->Add(StaticText5, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	TextCtrl5 = new wxTextCtrl(this, ID_TEXTCTRL5, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL5"));
	FlexGridSizer3->Add(TextCtrl5, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer3->Add(FlexGridSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(StaticBoxSizer3, 0, wxALL|wxEXPAND, 5);
	FlexGridSizer4 = new wxFlexGridSizer(0, 2, 0, 0);
	StaticText6 = new wxStaticText(this, ID_STATICTEXT6, _("Use Laplace"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT6"));
	FlexGridSizer4->Add(StaticText6, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	CheckBox1 = new wxCheckBox(this, ID_CHECKBOX1, _("Yes"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
	CheckBox1->SetValue(true);
	CheckBox1->Disable();
	FlexGridSizer4->Add(CheckBox1, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	StaticText7 = new wxStaticText(this, ID_STATICTEXT7, _("View Mesh"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT7"));
	FlexGridSizer4->Add(StaticText7, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	ComboBox1 = new wxComboBox(this, ID_COMBOBOX1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_COMBOBOX1"));
	FlexGridSizer4->Add(ComboBox1, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	StaticText8 = new wxStaticText(this, ID_STATICTEXT8, _("Refine Laplace Mesh"), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICTEXT8"));
	FlexGridSizer4->Add(StaticText8, 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);
	CheckBox2->Disable();
	FlexGridSizer4->Add(CheckBox2, 1, wxALL|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(FlexGridSizer4, 1, wxALL|wxEXPAND, 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_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	Button2 = new wxButton(this, ID_BUTTON2, _("BUILD"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
	BoxSizer2->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"));
	BoxSizer2->Add(Button3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer2->Add(BoxSizer2, 1, wxALL|wxEXPAND, 5);
	StaticBoxSizer1->Add(FlexGridSizer2, 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"));
	StaticBoxSizer2->Add(Panel1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	FlexGridSizer1->Add(StaticBoxSizer2, 1, wxALL|wxALIGN_TOP|wxALIGN_CENTER_HORIZONTAL, 5);
	SetSizer(FlexGridSizer1);
	FlexGridSizer1->Fit(this);
	FlexGridSizer1->SetSizeHints(this);

	Connect(ID_TEXTCTRL2,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&DCONN::OnTextCtrl2Text);
	Connect(ID_TEXTCTRL3,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&DCONN::OnTextCtrl3Text);
	Connect(ID_TEXTCTRL4,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&DCONN::OnTextCtrl4Text);
	Connect(ID_TEXTCTRL5,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&DCONN::OnTextCtrl5Text);
	Connect(ID_COMBOBOX1,wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)&DCONN::OnComboBox1Selected);
	Connect(ID_CHECKBOX2,wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)&DCONN::OnCheckBox2Click);
	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&DCONN::OnButton1Click);
	Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&DCONN::OnButton2Click);
	Connect(ID_BUTTON3,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&DCONN::OnButton3Click);
	Panel1->Connect(wxEVT_PAINT,(wxObjectEventFunction)&DCONN::OnPanel1Paint,0,this);
	Panel1->Connect(wxEVT_LEFT_DCLICK,(wxObjectEventFunction)&DCONN::OnPanel1LeftDClick,0,this);
2a0d305e   Steve Greedy   Modifications to ...
169
	Connect(wxID_ANY,wxEVT_INIT_DIALOG,(wxObjectEventFunction)&DCONN::OnInit);
dd86ff43   Steve Greedy   Updates to SW1
170
	Connect(wxEVT_PAINT,(wxObjectEventFunction)&DCONN::OnPaint);
886c558b   Steve Greedy   SACAMOS Public Re...
171
	//*)
886c558b   Steve Greedy   SACAMOS Public Re...
172
173
174
175
176
177
178
179
}

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

886c558b   Steve Greedy   SACAMOS Public Re...
180

2a0d305e   Steve Greedy   Modifications to ...
181
182
void DCONN::OnInit(wxInitDialogEvent& event)
{
886c558b   Steve Greedy   SACAMOS Public Re...
183
184
185
186
    TextCtrl2->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&DCONN::OnHighlightSchematic, this);
    TextCtrl3->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&DCONN::OnHighlightSchematic, this);
    TextCtrl4->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&DCONN::OnHighlightSchematic, this);
    TextCtrl5->Bind(wxEVT_SET_FOCUS,(wxObjectEventFunction)&DCONN::OnHighlightSchematic, this);
886c558b   Steve Greedy   SACAMOS Public Re...
187
188
}

2a0d305e   Steve Greedy   Modifications to ...
189

dd86ff43   Steve Greedy   Updates to SW1
190
void DCONN::OnPaint(wxPaintEvent& event)
886c558b   Steve Greedy   SACAMOS Public Re...
191
{
dd86ff43   Steve Greedy   Updates to SW1
192
    if (EDIT_EXISTING==true) EditExistingCable();
886c558b   Steve Greedy   SACAMOS Public Re...
193
194
}

886c558b   Steve Greedy   SACAMOS Public Re...
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
void DCONN::SetPathToMOD(wxString Path, wxString Name)
{

    pathToMOD << Path;
    MODname << Name;

}

void DCONN::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);
    if (IsError ==1)
    {
        return;
    }

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

    WriteCableFile(fileName);

    Button1->Disable();
}

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

    //CABLE BUIDER
    wxString fileName = TextCtrl1->GetValue();
2a0d305e   Steve Greedy   Modifications to ...
244
    wxString command_line;
886c558b   Steve Greedy   SACAMOS Public Re...
245

1bcf33cb   Steve Greedy   Modifications to ...
246
    wxString separator(wxFileName::GetPathSeparator());
886c558b   Steve Greedy   SACAMOS Public Re...
247
248

    std::stringstream stream;
1bcf33cb   Steve Greedy   Modifications to ...
249
250
251

    stream  <<"." + separator
            << "cable_model_builder"
886c558b   Steve Greedy   SACAMOS Public Re...
252
            << " "
1bcf33cb   Steve Greedy   Modifications to ...
253
            << ".." + separator + MODname + separator + "CABLE" + separator
886c558b   Steve Greedy   SACAMOS Public Re...
254
255
            << fileName ;

2a0d305e   Steve Greedy   Modifications to ...
256
257
    command_line << stream.str().c_str();

3d24aeb1   Steve Greedy   Modification to s...
258
    wxExecute (command_line, wxEXEC_SYNC);;
886c558b   Steve Greedy   SACAMOS Public Re...
259
260
261
262
263
264
265
266
267

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

    Button1->Enable();

    if (CheckBox1->GetValue())
    {
dd86ff43   Steve Greedy   Updates to SW1
268
269
270

        wxString pattern (("*.msh.vtk")) ;

886c558b   Steve Greedy   SACAMOS Public Re...
271
        wxString file;
886c558b   Steve Greedy   SACAMOS Public Re...
272
273
274
275

        ComboBox1->Clear();

        file = wxFindFirstFile(pattern);
dd86ff43   Steve Greedy   Updates to SW1
276

886c558b   Steve Greedy   SACAMOS Public Re...
277
278
279
        while ( !file.empty())
        {
                wxString meshfile = file;
dd86ff43   Steve Greedy   Updates to SW1
280
281
282
283
284
                size_t extindex = meshfile.find_last_of (".");

                meshfile  = meshfile.substr(0, extindex);

                extindex = meshfile.find_last_of (".");
886c558b   Steve Greedy   SACAMOS Public Re...
285
286
287

                meshfile  = meshfile.substr(0, extindex);

dd86ff43   Steve Greedy   Updates to SW1
288
289
                meshfile = meshfile.substr(2,meshfile.length());

886c558b   Steve Greedy   SACAMOS Public Re...
290
                ComboBox1->Append(meshfile);
886c558b   Steve Greedy   SACAMOS Public Re...
291

dd86ff43   Steve Greedy   Updates to SW1
292
293
                file = wxFindNextFile();
        }
886c558b   Steve Greedy   SACAMOS Public Re...
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

        CheckBox2->Enable();
    }
}

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

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

void DCONN::OnTextCtrl3Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl3, &IsError);
}

void DCONN::OnTextCtrl4Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl4, &IsError);
}

void DCONN::OnTextCtrl5Text(wxCommandEvent& event)
{
    int IsError = 0;
    check_is_numeric_list(TextCtrl5, &IsError);
}

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

1bcf33cb   Steve Greedy   Modifications to ...
334
335
336
    wxString separator(wxFileName::GetPathSeparator());

    wxString fullFileName = pathToMOD + separator + "CABLE" + separator + fileName + ".cable_spec";
886c558b   Steve Greedy   SACAMOS Public Re...
337
338
339
340
341
342
343

    cableFile.open (fullFileName);

    if (cableFile.is_open())
    {
        // minimum requirements for type Cylindrical
        cableFile <<"# MOD_cable_lib_dir \n";
1bcf33cb   Steve Greedy   Modifications to ...
344
        cableFile <<".." << separator << MODname << separator << "CABLE" << separator <<"\n";
886c558b   Steve Greedy   SACAMOS Public Re...
345
346
347
348
349
350
        cableFile <<"Dconnector\n";
        cableFile <<"10 #number of conductors \n";
        cableFile <<"4 #number of parameters \n";
        cableFile << TextCtrl2->GetValue() <<" # parameter 1: conductor radius\n";
        cableFile << TextCtrl3->GetValue() <<" # parameter 2: conductor pitch (separation in x)\n";
        cableFile << TextCtrl4->GetValue() <<" # parameter 3: conductor separation in y \n";
00c8775f   Steve Greedy   Update SW1
351
        cableFile << TextCtrl5->GetValue() <<" # offset from conductors to shell \n";
886c558b   Steve Greedy   SACAMOS Public Re...
352
353
354
355
356
357
358
        cableFile <<"0 # number of frequency dependent parameters\n";
        cableFile <<"0 # number of transfer impedance models \n";
        cableFile <<"use_laplace \n";
    }

    if (CheckBox2->GetValue())
    {
dd86ff43   Steve Greedy   Updates to SW1
359
360
        //cableFile << "Laplace_boundary_constant\n";
        //cableFile << MESH_PARAM1 <<"\n";
886c558b   Steve Greedy   SACAMOS Public Re...
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
        cableFile << "Laplace_surface_mesh_constant\n";
        cableFile << MESH_PARAM2 <<"\n";

        CheckBox2 ->SetValue(false);
    }

    cableFile.close();
}

void DCONN::OnPanel1Paint(wxPaintEvent& event)
{
    dconnSchematic();
}

void DCONN::dconnSchematic()
{
    int size_h, size_v;
    Panel1->GetSize(&size_h, &size_v );

    float   shell_top_x, shell_top_x1, shell_top_y,
            shell_bot_x, shell_bot_x1, shell_bot_y;


    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("D Connector", 10, 15);


    float conductor_radius, conductor_separation_x, conductor_separation_y, shell_offset;

    conductor_radius = 0.04 * size_h;
    conductor_separation_x = 0.16 * size_h;
    conductor_separation_y = 0.16 * size_v;
    shell_offset = 0.05 * size_h;

    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 - conductor_separation_x/2), conductor_radius );
    dc.DrawCircle( wxPoint(size_h/2 - conductor_separation_x,size_v/2 - conductor_separation_y/2), conductor_radius );
    dc.DrawCircle( wxPoint(size_h/2 - 2 * conductor_separation_x,size_v/2 - conductor_separation_y/2), conductor_radius );
    dc.DrawCircle( wxPoint(size_h/2 + 2 * conductor_separation_x,size_v/2 - conductor_separation_y/2), conductor_radius );
    dc.DrawCircle( wxPoint(size_h/2 - conductor_separation_x/2,size_v/2 + conductor_separation_y/2), conductor_radius );
    dc.DrawCircle( wxPoint(size_h/2 - 1.5 *conductor_separation_x,size_v/2 + conductor_separation_y/2), conductor_radius );
    dc.DrawCircle( wxPoint(size_h/2 + 1.5 *conductor_separation_x,size_v/2 + conductor_separation_y/2), conductor_radius );

    dc.SetPen( wxPen( wxColor(192,192,192),4 , wxDOT) );
    dc.SetBrush(wxBrush(wxColor(224,224,224), wxSOLID));
    dc.DrawLine( size_h/2 + 2 * conductor_radius,size_v/2 - conductor_separation_y/2, size_h/2 + 1.5 * conductor_separation_x,size_v/2 - conductor_separation_y/2 );
    dc.DrawLine( size_h/2 + conductor_radius,size_v/2 + conductor_separation_y/2, size_h/2 + conductor_separation_x,size_v/2 + conductor_separation_y/2 );

    dc.SetPen( wxPen( wxColor(192,192,192),4) );

    shell_top_x = size_h/2 - (2.0 * conductor_separation_x);
    shell_top_x1= size_h/2 + (2.0 * conductor_separation_x);

    shell_bot_x = size_h/2 - (1.5 * conductor_separation_x);
    shell_bot_x1= size_h/2 + (1.5 * conductor_separation_x);

    shell_top_y = size_v/2 - conductor_radius - conductor_separation_y/2 - shell_offset;
    shell_bot_y= size_v/2 + conductor_radius + conductor_separation_y/2 + shell_offset;

    dc.DrawLine( shell_top_x, shell_top_y, shell_top_x1, shell_top_y);
    dc.DrawLine( shell_bot_x, shell_bot_y, shell_bot_x1, shell_bot_y);

    float theta_rad =  atan(0.5* conductor_separation_x/conductor_separation_y);
    float theta_deg = 360 * theta_rad/(2.0 * PI);
    float x_diff = (conductor_radius + shell_offset) * cos(theta_rad);
    float y_diff = (conductor_radius + shell_offset) * sin(theta_rad);

    dc.DrawLine((size_h/2 - 2.0 * conductor_separation_x) - x_diff, size_v/2 - conductor_separation_y/2 + y_diff,
                (size_h/2 - 1.5 * conductor_separation_x) - x_diff, size_v/2 + conductor_separation_y/2 + y_diff);

    dc.DrawLine((size_h/2 + 2.0 * conductor_separation_x) + x_diff, size_v/2 - conductor_separation_y/2 + y_diff,
                (size_h/2 + 1.5 * conductor_separation_x) + x_diff, size_v/2 + conductor_separation_y/2 + y_diff);

    dc.SetBrush(wxBrush(wxColor(224,224,224), wxTRANSPARENT));

    dc.DrawEllipticArc(size_h/2 - 2.0 * conductor_separation_x - conductor_radius - shell_offset, shell_top_y,
                       2.0 * (conductor_radius + shell_offset), 2.0 * (conductor_radius + shell_offset)
                       , 90, 180 + theta_deg);

    dc.DrawEllipticArc(size_h/2 - 1.5 * conductor_separation_x - conductor_radius - shell_offset, shell_bot_y - 2.0 * (conductor_radius + shell_offset),
                       2.0 * (conductor_radius + shell_offset), 2.0 * (conductor_radius + shell_offset)
                       , 180 + theta_deg, 270);

    dc.DrawEllipticArc(size_h/2 + 2.0 * conductor_separation_x - conductor_radius - shell_offset, shell_top_y,
                       2.0 * (conductor_radius + shell_offset), 2.0 * (conductor_radius + shell_offset)
                       , 0 - theta_deg, 90);

    dc.DrawEllipticArc(size_h/2 + 1.5 * conductor_separation_x - conductor_radius - shell_offset, shell_bot_y - 2.0 * (conductor_radius + shell_offset),
                       2.0 * (conductor_radius + shell_offset), 2.0 * (conductor_radius + shell_offset)
                       , 270, 360-theta_deg);
}

void DCONN::OnHighlightSchematic(wxCommandEvent& event)
{
    dconnSchematic();

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

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

    float conductor_radius, conductor_separation_x, conductor_separation_y, shell_offset;

    conductor_radius = 0.04 * size_h;
    conductor_separation_x = 0.16 * size_h;
    conductor_separation_y = 0.16 * size_v;
    shell_offset = 0.05 * 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 - conductor_separation_y/2),3 );
        dc.DrawLine( size_h/2, size_v/2 - conductor_separation_y/2, size_h/2+x,size_v/2 - conductor_separation_y/2 - y);

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

    if ( ID == ID_TEXTCTRL3)
    {
        dc.SetPen(wxPen(wxColor(51,51,255), 3));
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));


        dc.DrawLine(size_h/2, size_v/2 - conductor_separation_y/2,
                    size_h/2 - conductor_separation_x, size_v/2 - conductor_separation_y/2);

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

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

    if ( ID == ID_TEXTCTRL4)
    {
        dc.SetPen(wxPen(wxColor(51,51,255), 3, wxDOT_DASH));
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));


        dc.DrawLine(size_h/2, size_v/2 - conductor_separation_y/2,
                    size_h/2 - conductor_separation_x, size_v/2 - conductor_separation_y/2);

        dc.SetPen(wxPen(wxColor(51,51,255), 3));
        dc.DrawLine(size_h/2 - conductor_separation_x/2, size_v/2 + conductor_separation_y/2,
                    size_h/2 - conductor_separation_x/2, size_v/2 - conductor_separation_y/2);

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

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

    }

    if ( ID == ID_TEXTCTRL5)
    {
        dc.SetPen(wxPen(wxColor(51,51,255), 3));
        dc.SetBrush(wxBrush(wxColor(51,51,255), wxSOLID));


        dc.DrawLine(size_h/2, size_v/2 - conductor_separation_y/2 - conductor_radius,
                    size_h/2, size_v/2 - conductor_separation_y/2  - conductor_radius - shell_offset);

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

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

    }
}

void DCONN::OnPanel1LeftDClick(wxMouseEvent& event)
{
    dconnSchematic();
}

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

void DCONN::OnCheckBox2Click(wxCommandEvent& event)
{
    if (CheckBox2->GetValue())
    {
        MESH_PARAM *winMESH_PARAM = new MESH_PARAM(this);

        winMESH_PARAM->TextCtrl1->Disable();
dd86ff43   Steve Greedy   Updates to SW1
589
590
        winMESH_PARAM->TextCtrl3->Disable();
        winMESH_PARAM->TextCtrl4->Disable();
886c558b   Steve Greedy   SACAMOS Public Re...
591
592
593

        if ( winMESH_PARAM->ShowModal() == wxID_OK )
        {
886c558b   Steve Greedy   SACAMOS Public Re...
594
595
596
597
598
599
            MESH_PARAM2 = winMESH_PARAM->TextCtrl2->GetValue();
        }
        winMESH_PARAM->Destroy();
    }
    WriteCableFile (TextCtrl1->GetValue());
}
c2690fc5   Steve Greedy   Resolve Merge Err...
600
601
602
603
604

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