Blame view

GUI/SW1/SRC/EXPORT_SPICE.cpp 7.9 KB
886c558b   Steve Greedy   SACAMOS Public Re...
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
/////////////////////////////////////////////////////////////////////////////////
//
// 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 - 2017 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
//     EXPORT_SPICE.cpp
//
// DESCRIPTION
//     Export spice models from SACAMOS to spice version specific locations
//
// AUTHOR(S)
//     Steve Greedy
//
/////////////////////////////////////////////////////////////////////////////////

#include "EXPORT_SPICE.h"

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

//(*IdInit(EXPORT_SPICE)
const long EXPORT_SPICE::ID_DIRPICKERCTRL1 = wxNewId();
const long EXPORT_SPICE::ID_DIRPICKERCTRL2 = wxNewId();
const long EXPORT_SPICE::ID_BUTTON1 = wxNewId();
const long EXPORT_SPICE::ID_BUTTON2 = wxNewId();
//*)

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

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

	Create(parent, wxID_ANY, _("SACAMOS: Export Spice Models"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T("wxID_ANY"));
	FlexGridSizer1 = new wxFlexGridSizer(0, 3, 0, 0);
	BoxSizer1 = new wxBoxSizer(wxVERTICAL);
	StaticBoxSizer1 = new wxStaticBoxSizer(wxHORIZONTAL, this, _("Ngspice: Path to symbol library"));
	DirPickerCtrl1 = new wxDirPickerCtrl(this, ID_DIRPICKERCTRL1, wxEmptyString, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDIRP_DIR_MUST_EXIST|wxDIRP_USE_TEXTCTRL, wxDefaultValidator, _T("ID_DIRPICKERCTRL1"));
	StaticBoxSizer1->Add(DirPickerCtrl1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer1->Add(StaticBoxSizer1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	StaticBoxSizer2 = new wxStaticBoxSizer(wxHORIZONTAL, this, _("LTspice: Path to symbol library"));
	DirPickerCtrl2 = new wxDirPickerCtrl(this, ID_DIRPICKERCTRL2, wxEmptyString, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDIRP_DIR_MUST_EXIST|wxDIRP_USE_TEXTCTRL, wxDefaultValidator, _T("ID_DIRPICKERCTRL2"));
	StaticBoxSizer2->Add(DirPickerCtrl2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer1->Add(StaticBoxSizer2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
	Button1 = new wxButton(this, ID_BUTTON1, _("EXPORT"), 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, _("CLOSE"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
	BoxSizer2->Add(Button2, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	BoxSizer1->Add(BoxSizer2, 1, wxALL|wxEXPAND, 5);
	FlexGridSizer1->Add(BoxSizer1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
	SetSizer(FlexGridSizer1);
	FlexGridSizer1->Fit(this);
	FlexGridSizer1->SetSizeHints(this);

	Connect(ID_DIRPICKERCTRL1,wxEVT_COMMAND_DIRPICKER_CHANGED,(wxObjectEventFunction)&EXPORT_SPICE::OnDirPickerCtrl1DirChanged);
	Connect(ID_DIRPICKERCTRL2,wxEVT_COMMAND_DIRPICKER_CHANGED,(wxObjectEventFunction)&EXPORT_SPICE::OnDirPickerCtrl2DirChanged);
	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&EXPORT_SPICE::OnButton1Click);
	Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&EXPORT_SPICE::OnButton2Click);
	//*)
}

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

void EXPORT_SPICE::SetPathToMOD(wxString Path, wxString Name)
{
    pathToMOD << Path;
    MODname << Name;
}


void EXPORT_SPICE::OnButton2Click(wxCommandEvent& event)
{
    Close();
}

void EXPORT_SPICE::OnDirPickerCtrl1DirChanged(wxFileDirPickerEvent& event)
{
}

void EXPORT_SPICE::OnDirPickerCtrl2DirChanged(wxFileDirPickerEvent& event)
{
    wxString lt_sym_dir = DirPickerCtrl2->GetPath();

    wxString sacamos_sym_dir = wxGetCwd() + MODname + "\\SPICE\\SYMBOL\\";

}

void EXPORT_SPICE::OnButton1Click(wxCommandEvent& event)
{

    wxString sacamos_sym_dir = "..\\" + MODname + "\\SPICE\\SYMBOL\\";
    wxSetWorkingDirectory(sacamos_sym_dir);

    wxString file, pattern;

    if (DirPickerCtrl1->GetPath() != "")
    {
        wxString ng_sym_from, ng_sym_to;

        wxString ng_sym_dir = DirPickerCtrl1->GetPath();

        pattern = "*.sym";

        file = wxFindFirstFile(pattern);

        while ( !file.empty())
        {
            wxString file_no_path = wxFileNameFromPath(file);

            size_t lastindex = file_no_path.find_last_of(".");
            wxString file_name = file_no_path.substr(0, lastindex);

            ng_sym_from = file_no_path;
            ng_sym_to = ng_sym_dir + "\\" + file_no_path;

            wxCopyFile(ng_sym_from, ng_sym_to);
            wxTextFile file_to_edit(ng_sym_to);

            if (file_to_edit.Open())
            {
                size_t i;
                for (i = 0; i <file_to_edit.GetLineCount(); i++)
                {
                    if (file_to_edit[i] == ("file=PATH_TO_TRANSMISSION_LINE_SUB_CIRCUITS/" + file_name + "_NGspice.lib"))
                    {
                        file_to_edit[i] = "file=" + pathToMOD + "\\SPICE\\" + file_name + "_NGspice.lib";
                    }
                file_to_edit.Write();
                }
            file_to_edit.Close();
            }

            file = wxFindNextFile();
        }
    }


    if (DirPickerCtrl2->GetPath() != "")
    {
        wxString lt_sym_from, lt_sym_to;

        wxString lt_sym_dir = DirPickerCtrl2->GetPath();

        pattern = "*.asy";

        file = wxFindFirstFile(pattern);

        while ( !file.empty())
        {
            wxString file_no_path = wxFileNameFromPath(file);

            size_t lastindex = file_no_path.find_last_of(".");
            wxString file_name = file_no_path.substr(0, lastindex);

            lt_sym_from = file_no_path;
            lt_sym_to = lt_sym_dir + "\\" + file_no_path;

            wxCopyFile(lt_sym_from, lt_sym_to);
            wxTextFile file_to_edit(lt_sym_to);

            if (file_to_edit.Open())
            {
                size_t i;
                for (i = 0; i <file_to_edit.GetLineCount(); i++)
                {
                    if (file_to_edit[i] == ("SYMATTR ModelFile PATH_TO_TRANSMISSION_LINE_SUB_CIRCUITS/" + file_name + "_LTspice.lib"))
                    {
                        file_to_edit[i] = "SYMATTR ModelFile " + pathToMOD + "\\SPICE\\" + file_name + "_LTspice.lib";
                    }
                file_to_edit.Write();
                }
            file_to_edit.Close();
            }

            file = wxFindNextFile();
        }
    }

    wxSetWorkingDirectory(pathToMOD);
}