~ubuntu-branches/debian/sid/3depict/sid

« back to all changes in this revision

Viewing changes to src/ExportRngDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): D Haley
  • Date: 2010-08-09 21:23:50 UTC
  • Revision ID: james.westby@ubuntu.com-20100809212350-cg6yumndhwi3bqws
Tags: upstream-0.0.1
ImportĀ upstreamĀ versionĀ 0.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      ExportRngDialog.cpp  - "Range" data export dialog
 
3
 *      Copyright (C) 2010, D Haley 
 
4
 
 
5
 *      This program is free software: you can redistribute it and/or modify
 
6
 *      it under the terms of the GNU General Public License as published by
 
7
 *      the Free Software Foundation, either version 3 of the License, or
 
8
 *      (at your option) any later version.
 
9
 
 
10
 *      This program is distributed in the hope that it will be useful,
 
11
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *      GNU General Public License for more details.
 
14
 
 
15
 *      You should have received a copy of the GNU General Public License
 
16
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
#include "ExportRngDialog.h"
 
20
 
 
21
#include <fstream>
 
22
// begin wxGlade: ::extracode
 
23
 
 
24
// end wxGlade
 
25
 
 
26
enum
 
27
{
 
28
    ID_LIST_ACTIVATE=wxID_ANY+1,
 
29
};
 
30
 
 
31
ExportRngDialog::ExportRngDialog(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
 
32
    wxDialog(parent, id, title, pos, size, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxTHICK_FRAME)
 
33
{
 
34
    // begin wxGlade: ExportRngDialog::ExportRngDialog
 
35
    lblRanges = new wxStaticText(this, wxID_ANY, wxT("Range Sources"));
 
36
    listRanges = new wxListCtrl(this, ID_LIST_ACTIVATE, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxSUNKEN_BORDER);
 
37
    label_3 = new wxStaticText(this, wxID_ANY, wxT("Details"));
 
38
    gridDetails = new wxGrid(this, wxID_ANY);
 
39
    btnOK = new wxButton(this, wxID_SAVE, wxEmptyString);
 
40
   btnCancel = new wxButton(this, wxID_CANCEL, wxEmptyString);
 
41
 
 
42
    set_properties();
 
43
    do_layout();
 
44
    // end wxGlade
 
45
 
 
46
    //Add columns to report listviews
 
47
    listRanges->InsertColumn(0,_("Source Filter"));
 
48
    listRanges->InsertColumn(1,_("Ions"));
 
49
    listRanges->InsertColumn(2,_("Ranges"));
 
50
 
 
51
}
 
52
 
 
53
 
 
54
BEGIN_EVENT_TABLE(ExportRngDialog, wxDialog)
 
55
    // begin wxGlade: ExportRngDialog::event_table
 
56
    EVT_LIST_ITEM_ACTIVATED(ID_LIST_ACTIVATE, ExportRngDialog::OnListRangeItemActivate)
 
57
    EVT_BUTTON(wxID_SAVE, ExportRngDialog::OnSave)
 
58
    EVT_BUTTON(wxID_CANCEL, ExportRngDialog::OnCancel)
 
59
    // end wxGlade
 
60
END_EVENT_TABLE();
 
61
 
 
62
 
 
63
void ExportRngDialog::OnListRangeItemActivate(wxListEvent &event)
 
64
{
 
65
        updateGrid(event.GetIndex());
 
66
 
 
67
        selectedRange=event.GetIndex();
 
68
}
 
69
 
 
70
void ExportRngDialog::updateGrid(unsigned int index)
 
71
{
 
72
        const RangeFileFilter *rangeData;
 
73
        rangeData=(RangeFileFilter *)rngFilters[index];
 
74
 
 
75
        gridDetails->BeginBatch();
 
76
        gridDetails->DeleteCols(0,gridDetails->GetNumberCols());
 
77
        gridDetails->DeleteRows(0,gridDetails->GetNumberRows());
 
78
 
 
79
        gridDetails->AppendCols(3);
 
80
        gridDetails->SetColLabelValue(0,wxT("Param"));
 
81
        gridDetails->SetColLabelValue(1,wxT("Value"));
 
82
        gridDetails->SetColLabelValue(2,wxT("Value2"));
 
83
 
 
84
        unsigned int nRows;
 
85
        nRows=rangeData->rng.getNumIons()+rangeData->rng.getNumRanges() + 4;
 
86
        gridDetails->AppendRows(nRows);
 
87
 
 
88
 
 
89
        gridDetails->SetCellValue(0,0,_("Ion Name"));
 
90
        gridDetails->SetCellValue(0,1,_("Num Ranges"));
 
91
        unsigned int row=1;
 
92
        std::string tmpStr;
 
93
 
 
94
        //Add ion data, then range data
 
95
        for(unsigned int ui=0;ui<rangeData->rng.getNumIons(); ui++)
 
96
        {       
 
97
                //Use format 
 
98
                // ION NAME  | NUMBER OF RANGES
 
99
                gridDetails->SetCellValue(row,0,wxStr(rangeData->rng.getName(ui)));
 
100
                stream_cast(tmpStr,rangeData->rng.getNumRanges(ui));
 
101
                gridDetails->SetCellValue(row,1,wxStr(tmpStr));
 
102
                row++;
 
103
        }
 
104
 
 
105
        row++;  
 
106
        gridDetails->SetCellValue(row,0,_("Ion"));
 
107
        gridDetails->SetCellValue(row,1,_("Range Start"));
 
108
        gridDetails->SetCellValue(row,2,_("Range end"));
 
109
        row++;  
 
110
 
 
111
        for(unsigned int ui=0;ui<rangeData->rng.getNumRanges(); ui++)
 
112
        {
 
113
                std::pair<float,float> rngPair;
 
114
                unsigned int ionID;
 
115
 
 
116
                rngPair=rangeData->rng.getRange(ui);
 
117
                ionID=rangeData->rng.getIonID(ui);
 
118
                gridDetails->SetCellValue(row,0,
 
119
                        wxStr(rangeData->rng.getName(ionID)));
 
120
 
 
121
                stream_cast(tmpStr,rngPair.first);
 
122
                gridDetails->SetCellValue(row,1,wxStr(tmpStr));
 
123
 
 
124
                stream_cast(tmpStr,rngPair.second);
 
125
                gridDetails->SetCellValue(row,2,wxStr(tmpStr));
 
126
                        
 
127
                row++;  
 
128
        }       
 
129
 
 
130
        gridDetails->EndBatch();
 
131
}
 
132
 
 
133
void ExportRngDialog::OnSave(wxCommandEvent &event)
 
134
{
 
135
 
 
136
        if(!rngFilters.size())
 
137
                EndModal(wxID_CANCEL);
 
138
 
 
139
        //create a file chooser for later.
 
140
        wxFileDialog *wxF = new wxFileDialog(this,wxT("Save pos..."), wxT(""),
 
141
                wxT(""),wxT("ORNL format RNG (*.rng)|*.rng|All Files (*)|*"),wxSAVE);
 
142
        //Show, then check for user cancelling export dialog
 
143
        if(wxF->ShowModal() == wxID_CANCEL)
 
144
        {
 
145
                wxF->Destroy();
 
146
                return; 
 
147
        }
 
148
        
 
149
        std::string dataFile = stlStr(wxF->GetPath());
 
150
 
 
151
 
 
152
        if(((RangeFileFilter *)(rngFilters[selectedRange]))->rng.write(dataFile.c_str()))
 
153
        {
 
154
                std::string errString;
 
155
                errString="Unable to save. Check output destination can be written to.";
 
156
                
 
157
                wxMessageDialog *wxD  =new wxMessageDialog(this,wxStr(errString)
 
158
                                                ,wxT("Save error"),wxOK|wxICON_ERROR);
 
159
                wxD->ShowModal();
 
160
                wxD->Destroy();
 
161
                return;
 
162
        }
 
163
 
 
164
        EndModal(wxID_OK);
 
165
}
 
166
 
 
167
void ExportRngDialog::OnCancel(wxCommandEvent &event)
 
168
{
 
169
        EndModal(wxID_CANCEL);
 
170
}
 
171
// wxGlade: add ExportRngDialog event handlers
 
172
 
 
173
 
 
174
void ExportRngDialog::addRangeData(std::vector<const Filter *> rangeData)
 
175
{
 
176
#ifdef DEBUG
 
177
        //This function should only recieve rangefile filters
 
178
        for(unsigned int ui=0;ui<rangeData.size(); ui++)
 
179
                ASSERT(rangeData[ui]->getType() == FILTER_TYPE_RANGEFILE);
 
180
#endif
 
181
 
 
182
        rngFilters.resize(rangeData.size());
 
183
        std::copy(rangeData.begin(),rangeData.end(),rngFilters.begin());
 
184
 
 
185
        updateRangeList();
 
186
 
 
187
        if(rangeData.size())
 
188
        {
 
189
                //Use the first item to populate the grid
 
190
                updateGrid(0);
 
191
                //select the first item
 
192
                listRanges->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
 
193
 
 
194
                selectedRange=0;
 
195
        }
 
196
}
 
197
 
 
198
 
 
199
void ExportRngDialog::updateRangeList()
 
200
{
 
201
        listRanges->DeleteAllItems();
 
202
        for(unsigned int ui=0;ui<rngFilters.size(); ui++)
 
203
        {
 
204
                const RangeFileFilter *rangeData;
 
205
                rangeData=(RangeFileFilter *)rngFilters[ui];
 
206
                std::string tmpStr;
 
207
                long itemIndex;
 
208
                itemIndex=listRanges->InsertItem(0, wxStr(rangeData->getUserString())); 
 
209
                unsigned int nIons,nRngs; 
 
210
                nIons = rangeData->rng.getNumIons();
 
211
                nRngs = rangeData->rng.getNumIons();
 
212
 
 
213
                stream_cast(tmpStr,nIons);
 
214
                listRanges->SetItem(itemIndex, 1, wxStr(tmpStr)); 
 
215
                stream_cast(tmpStr,nRngs);
 
216
                listRanges->SetItem(itemIndex, 2, wxStr(tmpStr)); 
 
217
                
 
218
        }
 
219
}
 
220
 
 
221
void ExportRngDialog::set_properties()
 
222
{
 
223
    // begin wxGlade: ExportRngDialog::set_properties
 
224
    SetTitle(wxT("Export Range"));
 
225
    gridDetails->CreateGrid(0, 0);
 
226
        gridDetails->SetRowLabelSize(0);
 
227
        gridDetails->SetColLabelSize(0);
 
228
 
 
229
    listRanges->SetToolTip(wxT("List of rangefiles in filter tree"));
 
230
    gridDetails->EnableEditing(false);
 
231
    gridDetails->SetToolTip(wxT("Detailed view of selected range"));
 
232
    // end wxGlade
 
233
}
 
234
 
 
235
 
 
236
void ExportRngDialog::do_layout()
 
237
{
 
238
    // begin wxGlade: ExportRngDialog::do_layout
 
239
    wxBoxSizer* sizer_2 = new wxBoxSizer(wxVERTICAL);
 
240
    wxBoxSizer* sizer_3 = new wxBoxSizer(wxHORIZONTAL);
 
241
    wxBoxSizer* sizer_14 = new wxBoxSizer(wxHORIZONTAL);
 
242
    wxBoxSizer* sizer_15 = new wxBoxSizer(wxVERTICAL);
 
243
    wxBoxSizer* sizer_16 = new wxBoxSizer(wxVERTICAL);
 
244
    sizer_16->Add(lblRanges, 0, wxLEFT|wxTOP, 5);
 
245
    sizer_16->Add(listRanges, 1, wxALL|wxEXPAND, 5);
 
246
    sizer_14->Add(sizer_16, 1, wxEXPAND, 0);
 
247
    sizer_14->Add(10, 20, 0, 0, 0);
 
248
    sizer_15->Add(label_3, 0, wxLEFT|wxTOP, 5);
 
249
    sizer_15->Add(gridDetails, 1, wxALL|wxEXPAND, 5);
 
250
    sizer_14->Add(sizer_15, 1, wxEXPAND, 0);
 
251
    sizer_2->Add(sizer_14, 1, wxEXPAND, 0);
 
252
    sizer_3->Add(20, 20, 1, 0, 0);
 
253
    sizer_3->Add(btnOK, 0, wxALL, 5);
 
254
    sizer_3->Add(btnCancel, 0, wxALL, 5);
 
255
    sizer_2->Add(sizer_3, 0, wxEXPAND, 0);
 
256
    SetSizer(sizer_2);
 
257
    sizer_2->Fit(this);
 
258
    Layout();
 
259
    // end wxGlade
 
260
}
 
261