File: wxGuidingOptions.cpp

package info (click to toggle)
wxastrocapture 1.8.1%2Bgit20140821.796e1a1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 42,212 kB
  • sloc: cpp: 43,421; sh: 733; perl: 246; makefile: 14
file content (209 lines) | stat: -rw-r--r-- 8,407 bytes parent folder | download | duplicates (4)
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
#include "wxGuidingOptions.h"
#include "wxGuidingInterfaceFile.h"
#include "wxGuidingInterfaceBridge.h"
#include "wxGuidingInterfaceSerialPort.h"
#include "wxGuidingInterfaceParallelPort.h"
#include "wxGuidingInterfaceUsbPort.h"

#include "wxFactory.h"
#include "wxMessageArea.h"

#include "wxcustom/wxPropertyPage.h"

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

#include <map>
using namespace std;

//(*IdInit(wxGuidingOptions)
const long wxGuidingOptions::ID_PANEL1 = wxNewId();
const long wxGuidingOptions::ID_CHOICEBOOK1 = wxNewId();
const long wxGuidingOptions::ID_PANEL2 = wxNewId();
const long wxGuidingOptions::ID_NOTEBOOK1 = wxNewId();
const long wxGuidingOptions::ID_BUTTON1 = wxNewId();
const long wxGuidingOptions::ID_BUTTON2 = wxNewId();
//*)

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

wxGuidingOptions* wxGuidingOptions::m_self = 0;
wxGuidingOptions* wxGuidingOptions::singleton()
{
   return m_self;
}

wxGuidingOptions::wxGuidingOptions(wxWindow* parent,wxWindowID id,const wxPoint& WXUNUSED(pos),const wxSize& WXUNUSED(size))
{
	//(*Initialize(wxGuidingOptions)
	wxButton* ApplyButton;
	wxBoxSizer* BoxSizer2;
	wxButton* CloseButton;
	wxBoxSizer* BoxSizer1;
	wxBoxSizer* BoxSizer3;
	
	Create(parent, id, _("Guiding Options"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER, _T("id"));
	SetClientSize(wxDefaultSize);
	Move(wxDefaultPosition);
	BoxSizer1 = new wxBoxSizer(wxVERTICAL);
	Notebook1 = new wxNotebook(this, ID_NOTEBOOK1, wxDefaultPosition, wxDefaultSize, 0, _T("ID_NOTEBOOK1"));
	m_calibration = new SettingsGuiding(Notebook1, ID_PANEL1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
	m_guiding_interface = new wxPanel(Notebook1, ID_PANEL2, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL2"));
	BoxSizer3 = new wxBoxSizer(wxVERTICAL);
	m_interfaceChoiceBook = new wxChoicebook(m_guiding_interface, ID_CHOICEBOOK1, wxDefaultPosition, wxDefaultSize, 0, _T("ID_CHOICEBOOK1"));
	BoxSizer3->Add(m_interfaceChoiceBook, 1, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_BOTTOM, 5);
	m_guiding_interface->SetSizer(BoxSizer3);
	BoxSizer3->Fit(m_guiding_interface);
	BoxSizer3->SetSizeHints(m_guiding_interface);
	Notebook1->AddPage(m_calibration, _("Calibration"), false);
	Notebook1->AddPage(m_guiding_interface, _("Guiding Interface"), false);
	BoxSizer1->Add(Notebook1, 1, wxALL|wxEXPAND|wxALIGN_LEFT|wxALIGN_TOP, 5);
	BoxSizer2 = new wxBoxSizer(wxHORIZONTAL);
	ApplyButton = new wxButton(this, ID_BUTTON1, _("Apply"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
	BoxSizer2->Add(ApplyButton, 1, wxALL|wxALIGN_LEFT|wxALIGN_TOP, 5);
	CloseButton = new wxButton(this, ID_BUTTON2, _("Close"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
	BoxSizer2->Add(CloseButton, 1, wxALL|wxALIGN_LEFT|wxALIGN_TOP, 5);
	BoxSizer1->Add(BoxSizer2, 0, wxLEFT|wxRIGHT|wxALIGN_RIGHT|wxALIGN_BOTTOM, 5);
	SetSizer(BoxSizer1);
	BoxSizer1->Fit(this);
	BoxSizer1->SetSizeHints(this);
	
	Connect(ID_CHOICEBOOK1,wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED,(wxObjectEventFunction)&wxGuidingOptions::OnIinterfaceChoiceBookPageChanged);
	Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxGuidingOptions::OnApplyButtonClick);
	Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxGuidingOptions::OnCloseButtonClick);
	//*)

   m_self = this;
   Init();
}

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

void wxGuidingOptions::Init()
{
   InitInterfaces();
}

void wxGuidingOptions::InitInterfaces()
{
   /// Add the required pages to m_interfaceChoiceBook
   /// First delete what we have so far
   m_interfaceChoiceBook->DeleteAllPages();

   /// File interface is always available
   wxGuidingInterfaceFile* file_page = new wxGuidingInterfaceFile(m_interfaceChoiceBook);
   m_interfaceChoiceBook->AddPage(file_page,file_page->GetName());

   /// Bridge interface is always available
   wxGuidingInterfaceBridge* bridge_page = new wxGuidingInterfaceBridge(m_interfaceChoiceBook);
   m_interfaceChoiceBook->AddPage(bridge_page,bridge_page->GetName());

   /// traverse the serial and parallel ports

   /// maintain a map between interface names and choicebook page numbers
   map<wxString,int> interface_pages;
   int ipageno = 0;
   interface_pages[wxT("FILE_INTERFACE")]   = ipageno++;
   interface_pages[wxT("BRIDGE_INTERFACE")] = ipageno++;

   wxPortDescrList& pList = wxF()->portManager()->PortDescriptors();
   wxPortDescrList::port_iterator iport = pList.port_begin();
   while(iport != pList.port_end()){
      const wxPortDescr& port_entry = pList.PortDescr(iport++);
      if (port_entry.IsGuidePort())  {
         if(port_entry.IsPortSerial()) {

            /// create and add the serial port page
            wxGuidingInterfaceSerialPort* serial_port_page = new wxGuidingInterfaceSerialPort(m_interfaceChoiceBook);
            serial_port_page->SetName(port_entry.PortName());
            m_interfaceChoiceBook->AddPage(serial_port_page,serial_port_page->GetName());
            interface_pages[serial_port_page->GetName()] = ipageno++;
         }
         else if(port_entry.IsPortParallel()) {

            /// create and add the parallel port page
            wxGuidingInterfaceParallelPort* parallel_port_page = new wxGuidingInterfaceParallelPort(m_interfaceChoiceBook);
            parallel_port_page->SetName(port_entry.PortName());
            m_interfaceChoiceBook->AddPage(parallel_port_page,parallel_port_page->GetName());
            interface_pages[parallel_port_page->GetName()] = ipageno++;
         }
         else if(port_entry.IsPortGPUSB()) {

            /// create and add the GPUSB port page
            wxGuidingInterfaceUsbPort* usb_port_page = new wxGuidingInterfaceUsbPort(m_interfaceChoiceBook);
            usb_port_page->SetName(port_entry.PortName());
            m_interfaceChoiceBook->AddPage(usb_port_page,usb_port_page->GetName());
            interface_pages[usb_port_page->GetName()] = ipageno++;
         }
      }
   }

   /// select the default page based on the last saved configuration
   wxString default_page = wxT("FILE_INTERFACE");
   wxGuider::guider_interface intfc = wxF()->guider()->interface_type();
   switch(intfc) {
      case wxGuider::FILE_INTERFACE:   { default_page = wxT("FILE_INTERFACE")   ; break; }
      case wxGuider::BRIDGE_INTERFACE: { default_page = wxT("BRIDGE_INTERFACE") ; break; }
      case wxGuider::PORT_INTERFACE:   {
         if(wxGuiderPort*  port = wxF()->guidePort()) {
            default_page = port->PortName();
         }
         break;
      }
      default: { };
   };

   /// force the page selection
   m_interfaceChoiceBook->ChangeSelection(interface_pages[default_page]);
   m_interfaceChoiceBook->Refresh();

}

void wxGuidingOptions::OnIinterfaceChoiceBookPageChanged(wxChoicebookEvent& WXUNUSED(event))
{
   if(wxNoteBookPageEx* page = dynamic_cast<wxNoteBookPageEx*>(m_interfaceChoiceBook->GetPage(m_interfaceChoiceBook->GetSelection()))) {

      /// reinitialise the page
      page->Init();
   }
   else {
      wxMessageSink(wxT("Programming error: OnIinterfaceChoiceBookPageChanged failed to get ChoiceBook page"));
   }
}


void wxGuidingOptions::OnApplyButtonClick(wxCommandEvent& WXUNUSED(event))
{
   /// Just a cludge until we have eliminated the old guiding dialog
   /// Don't show message here if dynamic_cast returns 0, since some pages are not wxPropertyPage
   if(wxPropertyPage* page =  dynamic_cast<wxPropertyPage*>(Notebook1->GetPage(Notebook1->GetSelection()))) {
      /// Apply the page
      page->OnApply();
   }


   if(wxNoteBookPageEx* interface_page = dynamic_cast<wxNoteBookPageEx*>(m_interfaceChoiceBook->GetPage(m_interfaceChoiceBook->GetSelection()))) {

      /// Apply the page
      interface_page->OnApply();
   }
   else {
      wxMessageSink(wxT("Programming error: OnApplyButtonClick failed to get ChoiceBook page"));
   }
}

void wxGuidingOptions::OnCloseButtonClick(wxCommandEvent& WXUNUSED(event))
{
   /// close the dialog
   /// The dialog is a singleton, so we simply hide it
   Show(false);
}