/////////////////////////////////////////////////////////////////////////////////
//
// 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 .
//
// 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:
//
//
// The University of Nottingham can be contacted at: ggiemr@nottingham.ac.uk
//
// File Contents:
//
// NAME
// SW1_GUIMain.cpp
//
// DESCRIPTION
// Main application GUI for SACAMOS
//
// AUTHOR(S)
// Steve Greedy
//
/////////////////////////////////////////////////////////////////////////////////
#include "SW1_GUIMain.h"
//(*InternalHeaders(SW1_GUIFrame)
#include
#include
#include
#include
#include
#include
//*)
#define debug 0
//helper functions
enum wxbuildinfoformat
{
short_f, long_f
};
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
//(*IdInit(SW1_GUIFrame)
const long SW1_GUIFrame::ID_PANEL1 = wxNewId();
const long SW1_GUIFrame::ID_STATICBITMAP1 = wxNewId();
const long SW1_GUIFrame::ID_PANEL2 = wxNewId();
const long SW1_GUIFrame::ID_CREATEMOD = wxNewId();
const long SW1_GUIFrame::ID_SELECTMOD = wxNewId();
const long SW1_GUIFrame::ID_MENUITEM1 = wxNewId();
const long SW1_GUIFrame::ID_CYLINDRICAL = wxNewId();
const long SW1_GUIFrame::ID_COAX = wxNewId();
const long SW1_GUIFrame::ID_TWINAX = wxNewId();
const long SW1_GUIFrame::ID_UTP = wxNewId();
const long SW1_GUIFrame::ID_TP = wxNewId();
const long SW1_GUIFrame::ID_SPACEWIRE = wxNewId();
const long SW1_GUIFrame::ID_FLEX = wxNewId();
const long SW1_GUIFrame::ID_DSUB = wxNewId();
const long SW1_GUIFrame::ID_OVERSHIELD = wxNewId();
const long SW1_GUIFrame::ID_NEWBUNDLE = wxNewId();
const long SW1_GUIFrame::ID_EDITBUNDLE = wxNewId();
const long SW1_GUIFrame::ID_NEWSPICE = wxNewId();
const long SW1_GUIFrame::ID_MENUITEM2 = wxNewId();
const long SW1_GUIFrame::idMenuAbout = wxNewId();
const long SW1_GUIFrame::ID_STATUSBAR1 = wxNewId();
//*)
BEGIN_EVENT_TABLE(SW1_GUIFrame,wxFrame)
//(*EventTable(SW1_GUIFrame)
//*)
END_EVENT_TABLE()
SW1_GUIFrame::SW1_GUIFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(SW1_GUIFrame)
wxStaticBoxSizer* StaticBoxSizer2;
wxMenuItem* MenuItem2;
wxMenuItem* MenuItem1;
wxMenu* Menu1;
wxMenuBar* MenuBar1;
wxStaticBoxSizer* StaticBoxSizer1;
wxFlexGridSizer* FlexGridSizer1;
wxMenu* Menu2;
Create(parent, wxID_ANY, _("SACAMOS"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
{
wxIcon FrameIcon;
FrameIcon.CopyFromBitmap(wxBitmap(wxImage(_T("resources//spacewire_schematic_64x64.ico"))));
SetIcon(FrameIcon);
}
FlexGridSizer1 = new wxFlexGridSizer(1, 2, 0, 5);
FlexGridSizer1->AddGrowableCol(1);
FlexGridSizer1->AddGrowableRow(0);
StaticBoxSizer1 = new wxStaticBoxSizer(wxVERTICAL, this, _("MOD Browser"));
Panel1 = new wxPanel(this, ID_PANEL1, wxDefaultPosition, wxSize(300,300), wxSIMPLE_BORDER|wxTAB_TRAVERSAL, _T("ID_PANEL1"));
StaticBoxSizer1->Add(Panel1, 1, wxALL|wxEXPAND, 5);
FlexGridSizer1->Add(StaticBoxSizer1, 0, wxALL|wxEXPAND, 5);
StaticBoxSizer2 = new wxStaticBoxSizer(wxHORIZONTAL, this, wxEmptyString);
Panel2 = new wxPanel(this, ID_PANEL2, wxDefaultPosition, wxSize(600,600), wxSIMPLE_BORDER|wxTAB_TRAVERSAL, _T("ID_PANEL2"));
Panel2->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVECAPTION));
Panel2->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
StaticBitmap1 = new wxStaticBitmap(Panel2, ID_STATICBITMAP1, wxBitmap(wxImage(_T("resources//Sacamos_Logo_v2.png"))), wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxFULL_REPAINT_ON_RESIZE, _T("ID_STATICBITMAP1"));
StaticBoxSizer2->Add(Panel2, 1, wxALL|wxEXPAND, 5);
FlexGridSizer1->Add(StaticBoxSizer2, 2, wxALL|wxEXPAND, 5);
SetSizer(FlexGridSizer1);
MenuBar1 = new wxMenuBar();
Menu1 = new wxMenu();
Menu6 = new wxMenuItem(Menu1, ID_CREATEMOD, _("Create MOD"), wxEmptyString, wxITEM_NORMAL);
Menu1->Append(Menu6);
MenuItem3 = new wxMenuItem(Menu1, ID_SELECTMOD, _("Select MOD"), _("Browse to MOD root folder"), wxITEM_NORMAL);
Menu1->Append(MenuItem3);
Menu1->AppendSeparator();
MenuItem1 = new wxMenuItem(Menu1, ID_MENUITEM1, _("&Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
Menu1->Append(MenuItem1);
MenuBar1->Append(Menu1, _("&File"));
Menu3 = new wxMenu();
MenuItem5 = new wxMenuItem(Menu3, ID_CYLINDRICAL, _("Cylindrical Cable"), wxEmptyString, wxITEM_NORMAL);
Menu3->Append(MenuItem5);
MenuItem4 = new wxMenuItem(Menu3, ID_COAX, _("Coaxial Cable"), wxEmptyString, wxITEM_NORMAL);
Menu3->Append(MenuItem4);
MenuItem6 = new wxMenuItem(Menu3, ID_TWINAX, _("Twinax Cable"), wxEmptyString, wxITEM_NORMAL);
Menu3->Append(MenuItem6);
MenuItem7 = new wxMenuItem(Menu3, ID_UTP, _("Twisted Pair Cable"), wxEmptyString, wxITEM_NORMAL);
Menu3->Append(MenuItem7);
MenuItem8 = new wxMenuItem(Menu3, ID_TP, _("Shielded Twisted Pair Cable"), wxEmptyString, wxITEM_NORMAL);
Menu3->Append(MenuItem8);
MenuItem9 = new wxMenuItem(Menu3, ID_SPACEWIRE, _("Spacewire"), wxEmptyString, wxITEM_NORMAL);
Menu3->Append(MenuItem9);
MenuItem11 = new wxMenuItem(Menu3, ID_FLEX, _("Flex Cable"), wxEmptyString, wxITEM_NORMAL);
Menu3->Append(MenuItem11);
MenuItem14 = new wxMenuItem(Menu3, ID_DSUB, _("D Sub Connector"), wxEmptyString, wxITEM_NORMAL);
Menu3->Append(MenuItem14);
MenuItem10 = new wxMenuItem(Menu3, ID_OVERSHIELD, _("Overshield"), wxEmptyString, wxITEM_NORMAL);
Menu3->Append(MenuItem10);
MenuBar1->Append(Menu3, _("Cable Model"));
Menu4 = new wxMenu();
MenuItem12 = new wxMenuItem(Menu4, ID_NEWBUNDLE, _("Create Bundle"), wxEmptyString, wxITEM_NORMAL);
Menu4->Append(MenuItem12);
MenuItem13 = new wxMenuItem(Menu4, ID_EDITBUNDLE, _("Edit Bundle"), wxEmptyString, wxITEM_NORMAL);
Menu4->Append(MenuItem13);
MenuItem13->Enable(false);
MenuBar1->Append(Menu4, _("Bundle Model"));
Menu5 = new wxMenu();
MenuItem16 = new wxMenuItem(Menu5, ID_NEWSPICE, _("Create Spice Bundle Model"), wxEmptyString, wxITEM_NORMAL);
Menu5->Append(MenuItem16);
Menu5->AppendSeparator();
Menu7 = new wxMenuItem(Menu5, ID_MENUITEM2, _("Export Spice Models"), wxEmptyString, wxITEM_NORMAL);
Menu5->Append(Menu7);
MenuBar1->Append(Menu5, _("Spice Model"));
Menu2 = new wxMenu();
MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
Menu2->Append(MenuItem2);
MenuBar1->Append(Menu2, _("Help"));
SetMenuBar(MenuBar1);
StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, wxST_SIZEGRIP, _T("ID_STATUSBAR1"));
int __wxStatusBarWidths_1[1] = { -1 };
int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
SetStatusBar(StatusBar1);
DirDialog1 = new wxDirDialog(this, _("Select the MOD Directory"), wxEmptyString, wxDD_DEFAULT_STYLE|wxSIMPLE_BORDER, wxDefaultPosition, wxDefaultSize, _T("wxDirDialog"));
FlexGridSizer1->Fit(this);
FlexGridSizer1->SetSizeHints(this);
Panel1->Connect(wxEVT_PAINT,(wxObjectEventFunction)&SW1_GUIFrame::OnPanel1Paint,0,this);
Panel2->Connect(wxEVT_PAINT,(wxObjectEventFunction)&SW1_GUIFrame::OnPanel2Paint,0,this);
Connect(ID_CREATEMOD,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::onCreateMOD);
Connect(ID_SELECTMOD,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::onSelectMOD);
Connect(ID_MENUITEM1,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnQuit);
Connect(ID_CYLINDRICAL,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnCYLINDRICAL);
Connect(ID_COAX,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnCOAXIAL);
Connect(ID_TWINAX,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnTWINAX);
Connect(ID_UTP,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnUTP);
Connect(ID_TP,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnTP);
Connect(ID_SPACEWIRE,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnSPACEWIRE);
Connect(ID_FLEX,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnFLEXCABLE);
Connect(ID_DSUB,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnDSUB);
Connect(ID_OVERSHIELD,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnOVERSHIELD);
Connect(ID_NEWBUNDLE,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnNEWBUNDLE);
Connect(ID_NEWSPICE,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnCREATESPICE);
Connect(ID_MENUITEM2,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnEXPORTSPICE);
Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&SW1_GUIFrame::OnAbout);
//*)
// Disable Top Menu Items Until MOD location is chosen
MenuBar1->EnableTop(MenuBar1->FindMenu(_("&Cable Model")),false);
MenuBar1->EnableTop(MenuBar1->FindMenu(_("&Bundle Model")),false);
MenuBar1->EnableTop(MenuBar1->FindMenu(_("&Spice Model")),false);
allowResize = 0;
StatusBar1 -> SetStatusText(wxT("Ready"));
}
SW1_GUIFrame::~SW1_GUIFrame()
{
//(*Destroy(SW1_GUIFrame)
//*)
}
void SW1_GUIFrame::OnQuit(wxCommandEvent& event)
{
//clean up temporary files
clean_temp_files();
Close();
}
void SW1_GUIFrame::OnAbout(wxCommandEvent& event)
{
ABOUT *about = new ABOUT(this);
about->ShowModal();
}
void SW1_GUIFrame::onSelectMOD(wxCommandEvent& event)
{
// Create a new wxDirDialog dialog
wxDirDialog* dirDialog = new wxDirDialog(this);
// Display the dialog and transfer the contents to
// the wxTextCtrl on the main frame if the user
// doesn't cancel
if (dirDialog->ShowModal() == wxID_OK)
{
wxString selectedFile = dirDialog->GetPath();
PathToMOD << dirDialog->GetPath();
// Show the selected folder in the status bar
SetStatusText(selectedFile, 0);
PopulateTheDirectoryTree (selectedFile);
}
allowResize = 1;
dirDialog->Destroy();
wxStringTokenizer tkz(PathToMOD, wxT("\\"));
while (tkz.HasMoreTokens())
{
MODname = tkz.GetNextToken();
}
}
void SW1_GUIFrame::onCreateMOD(wxCommandEvent& event)
{
// Create a new wxDirDialog dialog
wxDirDialog* dirDialog = new wxDirDialog(this);
// Display the dialog and transfer the contents to
// the wxTextCtrl on the main frame if the user
// doesn't cancel
if (dirDialog->ShowModal() == wxID_OK)
{
wxString selectedFile = dirDialog->GetPath();
PathToMOD << dirDialog->GetPath();
wxStringTokenizer tkz(PathToMOD, wxT("/"));
while (tkz.HasMoreTokens())
{
MODname = tkz.GetNextToken();
}
wxString folder, dirName;
folder = PathToMOD + "/CABLE";
dirName = folder;
if (!wxDirExists(dirName))
wxMkdir(dirName, 0);
folder = PathToMOD + "/BUNDLE";
dirName = folder;
if (!wxDirExists(dirName))
wxMkdir(dirName, 0);
folder = PathToMOD + "/SPICE";
dirName = folder;
if (!wxDirExists(dirName))
wxMkdir(dirName, 0);
folder = PathToMOD + "/SPICE/SYMBOL";
dirName = folder;
if (!wxDirExists(dirName))
wxMkdir(dirName, 0);
wxMenuBar* MenuBar1 = GetMenuBar();
MenuBar1->EnableTop(MenuBar1->FindMenu(_("&Cable Model")),true);
MenuBar1->EnableTop(MenuBar1->FindMenu(_("&Bundle Model")),true);
MenuBar1->EnableTop(MenuBar1->FindMenu(_("&Spice Model")),true);
}
dirDialog->Destroy();
}
void SW1_GUIFrame::PopulateTheDirectoryTree ( wxString RootFolder)
{
int size_h, size_v;
Panel1->GetSize(&size_h, &size_v );
if (tree != NULL)
tree->Destroy();
tree = (wxSpecificDirCtrl *) NULL;
tree = new wxSpecificDirCtrl (Panel1, -1, RootFolder,
wxDefaultPosition,
wxSize(size_h,size_v),
wxSIMPLE_BORDER,//wxDIRCTRL_3D_INTERNAL|wxSUNKEN_BORDER,
wxEmptyString, 0,
_T("Directory Listing"));
Connect(tree->GetTreeCtrl()->GetId(),wxEVT_COMMAND_TREE_ITEM_ACTIVATED, (wxObjectEventFunction) (wxEventFunction)(wxCommandEventFunction) &SW1_GUIFrame::OnTreeSelectionChanged);
//SetButtonState_FolderSelected();
wxMenuBar* MenuBar1 = GetMenuBar();
MenuBar1->EnableTop(MenuBar1->FindMenu(_("&Cable Model")),true);
MenuBar1->EnableTop(MenuBar1->FindMenu(_("&Bundle Model")),true);
MenuBar1->EnableTop(MenuBar1->FindMenu(_("&Spice Model")),true);
}
void SW1_GUIFrame::OnTreeSelectionChanged(wxTreeEvent& evt)
{
wxFileName fname (tree->GetFilePath());
wxString File_Path = fname.GetPath();
wxString File_FUllName = fname.GetFullName();
wxString File_FullNamePath = fname.GetFullPath();
StaticBitmap1->Hide();
if(File_FUllName.substr(File_FUllName.find_last_of(".") + 1) == "cable_spec") {
draw_cable(Panel2,File_FullNamePath, 0, 0);
}
else
if(File_FUllName.substr(File_FUllName.find_last_of(".") + 1) == "bundle_spec") {
draw_bundle(Panel2, PathToMOD, File_FullNamePath);
}
}
void SW1_GUIFrame::OnCYLINDRICAL(wxCommandEvent& event)
{
CYLINDRICAL *cylindrical = new CYLINDRICAL(this);
cylindrical->SetPathToMOD(PathToMOD, MODname);
cylindrical->ShowModal();
}
void SW1_GUIFrame::OnCOAXIAL(wxCommandEvent& event)
{
COAXIAL *coaxial = new COAXIAL(this);
coaxial->SetPathToMOD(PathToMOD, MODname);
coaxial->ShowModal();
}
void SW1_GUIFrame::OnTWINAX(wxCommandEvent& event)
{
TWINAX *twinax = new TWINAX(this);
twinax->SetPathToMOD(PathToMOD, MODname);
twinax->ShowModal();
}
void SW1_GUIFrame::OnUTP(wxCommandEvent& event)
{
UTP *utp = new UTP(this);
utp->SetPathToMOD(PathToMOD, MODname);
utp->ShowModal();
}
void SW1_GUIFrame::OnTP(wxCommandEvent& event)
{
TP *tp = new TP(this);
tp->SetPathToMOD(PathToMOD, MODname);
tp->ShowModal();
}
void SW1_GUIFrame::OnSPACEWIRE(wxCommandEvent& event)
{
SPACEWIRE *spacewire = new SPACEWIRE(this);
spacewire->SetPathToMOD(PathToMOD, MODname);
spacewire->ShowModal();
}
void SW1_GUIFrame::OnOVERSHIELD(wxCommandEvent& event)
{
OVERSHIELD *overshield = new OVERSHIELD(this);
overshield->SetPathToMOD(PathToMOD, MODname);
overshield->ShowModal();
}
void SW1_GUIFrame::OnFLEXCABLE(wxCommandEvent& event)
{
FLEXCABLE *flexcable = new FLEXCABLE(this);
flexcable->SetPathToMOD(PathToMOD, MODname);
flexcable->ShowModal();
}
void SW1_GUIFrame::OnDSUB(wxCommandEvent& event)
{
DCONN *dsub = new DCONN(this);
dsub->SetPathToMOD(PathToMOD, MODname);
dsub->ShowModal();
}
void SW1_GUIFrame::OnNEWBUNDLE(wxCommandEvent& event)
{
BUNDLEBLDR *bundle = new BUNDLEBLDR(this);
bundle->SetPathForDir(PathToMOD, MODname);
bundle->ShowModal();
}
void SW1_GUIFrame::OnCREATESPICE(wxCommandEvent& event)
{
SPICEMODEL *spice = new SPICEMODEL(this);
spice->SetPathForDir(PathToMOD, MODname);
spice->ShowModal();
}
void SW1_GUIFrame::OnEXPORTSPICE(wxCommandEvent& event)
{
EXPORT_SPICE *exportspice = new EXPORT_SPICE(this);
exportspice->SetPathToMOD(PathToMOD, MODname);
exportspice->ShowModal();
}
void SW1_GUIFrame::OnPanel1Paint(wxPaintEvent& event)
{
}
void SW1_GUIFrame::OnPanel2Paint(wxPaintEvent& event)
{
}