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
|
/// MetaOptionsDlg.cpp
/**
*/
#include <wx/wxprec.h>
#include <wx/spinctrl.h>
#include <wx/statline.h>
#include "MetaOptionsDlg.h"
#include "NewMetaOutputter.h"
using namespace jcs;
BEGIN_EVENT_TABLE(MetaOptionsDlg, wxDialog)
EVT_BUTTON(wxID_OK, MetaOptionsDlg::OnOkay)
EVT_BUTTON(wxID_CLEAR, MetaOptionsDlg::OnClear)
END_EVENT_TABLE()
///
/**
*/
MetaOptionsDlg::MetaOptionsDlg(NewMetaOutputter* outputter)
: BasicOptionsDlg(_("MetaImage options"), outputter),
mOutputter(outputter)
{
wxBoxSizer* dlgSizer = new wxBoxSizer(wxVERTICAL);
dlgSizer->Add(myPanel);
wxString check_text(_("Save header only "));
mpHeaderOnlyCheck = new wxCheckBox(this, -1, check_text);
mpHeaderOnlyCheck->SetValue(mOutputter->SaveHeaderOnly());
dlgSizer->Add(mpHeaderOnlyCheck, 0, wxALL, 10);
dlgSizer->Add(new wxStaticText(this, -1, _("Add fields")), 0, wxTOP|wxLEFT, 10);
mpCheckList = new wxCheckListBox(this, -1);
Dictionary* dicom = Dicom_Dictionary::Instance();
std::vector<std::string> tagList = dicom->TagList();
for (unsigned int i = 0; i < tagList.size(); ++i) {
mAddTag(tagList.at(i));
}
mpCheckList->SetSize(mpCheckList->GetBestSize());
dlgSizer->Add(mpCheckList, 1, wxEXPAND|wxALL, 10);
wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
buttonSizer->Add(new wxButton(this, wxID_CLEAR, _("Clear fields")), 0, wxRIGHT, 10);
wxButton* okayButton = new wxButton(this, wxID_OK, _("Okay"));
buttonSizer->Add(okayButton, 0, wxRIGHT, 10);
buttonSizer->Add(new wxButton(this, wxID_CANCEL, _("Cancel")));
okayButton->SetDefault();
dlgSizer->Add(buttonSizer, 0, wxALIGN_RIGHT|wxALL, 10);
SetSizer(dlgSizer);
dlgSizer->Fit(this);
mNeedsRebuild = false;
}
///
/**
*/
void
MetaOptionsDlg::SetFields(std::vector<std::string> fields)
{
for (unsigned int i = 0; i < fields.size(); ++i) {
mCheckItem(fields.at(i));
}
}
///
/**
*/
std::vector<std::string>
MetaOptionsDlg::GetFields() const
{
std::vector<std::string> fields;
int n_items = mpCheckList->GetCount();
for (int i = 0; i < n_items; ++i) {
if (mpCheckList->IsChecked(i)) {
fields.push_back(static_cast<const char*>(mpCheckList->GetString(i).mb_str(wxConvLocal)));
}
}
return fields;
}
///
/**
*/
int
MetaOptionsDlg::mAddTag(const std::string tag)
{
if (tag.compare(0, 2, "Mf")) { // ignore metafile elements
mpCheckList->Append(wxString(tag.c_str(), wxConvLocal));
}
return 1;
}
///
/**
*/
int
MetaOptionsDlg::mCheckItem(const std::string item)
{
int index = mpCheckList->FindString(wxString(item.c_str(), wxConvLocal));
mpCheckList->Check(index);
return 1;
}
///
/**
*/
void
MetaOptionsDlg::OnClear(wxCommandEvent& event)
{
int n_items = mpCheckList->GetCount();
for (int i = 0; i < n_items; ++i)
mpCheckList->Check(i, false);
}
///
/**
*/
void
MetaOptionsDlg::OnOkay(wxCommandEvent& event)
{
bool rbld = Rebuild();
bool nfSave = SaveNameFields();
bool hdrOnly = (SaveHeaderOnly() != mOutputter->SaveHeaderOnly());
mNeedsRebuild = rbld || hdrOnly || nfSave;
BasicOptionsDlg::OnOkay(event);
mOutputter->SetSaveHeader(SaveHeaderOnly());
mOutputter->fields = GetFields();
EndModal(event.GetId());
}
|