Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunStitchFrame.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
27 #include "RunStitchFrame.h"
28 
29 RunStitchFrame::RunStitchFrame(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size) //ProjectArray projList, wxListBox *projListBox)
30  : wxFrame(parent, -1, title, pos, size, wxRESIZE_BORDER | wxCAPTION | wxCLIP_CHILDREN), m_isStitching(false)
31 {
32 
33  wxBoxSizer* topsizer = new wxBoxSizer( wxVERTICAL );
34  m_stitchPanel = new RunStitchPanel(this);
35 
36  topsizer->Add(m_stitchPanel, 1, wxEXPAND | wxALL, 2);
37 
38  topsizer->Add( new wxButton(this, wxID_CANCEL, _("Cancel")),
39  0, wxALL | wxALIGN_RIGHT, 10);
40 
41 #ifdef __WXMSW__
42  // wxFrame does have a strange background color on Windows..
43  this->SetBackgroundColour(m_stitchPanel->GetBackgroundColour());
44 #endif
45 
46  SetSizer( topsizer );
47  Bind(wxEVT_BUTTON, &RunStitchFrame::OnCancel, this, wxID_CANCEL);
48  Bind(wxEVT_END_PROCESS, &RunStitchFrame::OnProcessTerminate, this);
49 }
50 
52 {
53  if(m_projectId<0) //if a fake stitchframe is used (for a command), it doesn't have a stitch panel
54  {
55  return m_pid;
56  }
57  else
58  {
59  return m_stitchPanel->GetPid();
60  }
61 }
62 
64 {
65  return m_projectId;
66 }
67 
69 {
70  if(m_projectId<0) //if a fake stitchframe is used (for a command), it doesn't have a stitch panel
71  {
72  m_pid = pid;
73  }
74  else
75  {
77  }
78 }
79 
81 {
82  m_projectId=id;
83 }
84 
85 void RunStitchFrame::OnCancel(wxCommandEvent& WXUNUSED(event))
86 {
87  DEBUG_TRACE("");
88  if (m_isStitching)
89  {
91  m_isStitching = false;
92  }
93  else
94  {
95  Close();
96  }
97 }
98 
99 void RunStitchFrame::OnProcessTerminate(wxProcessEvent& event)
100 {
101  if (! m_isStitching)
102  {
103  event.SetEventObject( this );
104  event.m_exitcode = 1;
105  event.SetId(m_projectId);
106  DEBUG_TRACE("Sending wxProcess event");
107  this->GetParent()->GetEventHandler()->ProcessEvent( event );
108  // TODO: Cleanup files?
109  Close();
110  }
111  else
112  {
113  m_isStitching = false;
114  if (event.GetExitCode() != 0)
115  {
116  event.SetEventObject( this );
117  event.SetId(m_projectId);
118  this->GetParent()->GetEventHandler()->ProcessEvent( event );
119  Close();
120  }
121  else
122  {
123  event.SetEventObject( this );
124  event.SetId(m_projectId);
125  DEBUG_TRACE("Sending wxProcess event");
126  this->GetParent()->GetEventHandler()->ProcessEvent( event );
127  Close();
128  }
129  }
130 }
131 
132 bool RunStitchFrame::StitchProject(wxString scriptFile, wxString outname, wxString userDefinedOutput)
133 {
134  if (! m_stitchPanel->StitchProject(scriptFile, outname, userDefinedOutput))
135  {
136  return false;
137  }
138  m_isStitching = true;
139  m_isDetecting = false;
140  return true;
141 }
142 
143 bool RunStitchFrame::DetectProject(wxString scriptFile, wxString userDefinedAssistant)
144 {
145  if (! m_stitchPanel->DetectProject(scriptFile, userDefinedAssistant))
146  {
147  return false;
148  }
149  m_isStitching = true;
150  m_isDetecting = true;
151  return true;
152 }
153 
154 bool RunStitchFrame::SaveLog(const wxString& filename)
155 {
156  return m_stitchPanel->SaveLog(filename);
157 };
RunStitchFrame(wxWindow *parent, const wxString &title, const wxPoint &pos, const wxSize &size)
Stitch a pto project file, with GUI output etc.
void OnCancel(wxCommandEvent &event)
Cancels project execution - kills process.
void OnProcessTerminate(wxProcessEvent &event)
RunStitchPanel * m_stitchPanel
bool StitchProject(const wxString &scriptFile, const wxString &outname, const wxString &userDefinedOutput=wxEmptyString)
#define DEBUG_TRACE(msg)
Definition: utils.h:67
bool StitchProject(wxString scriptFile, wxString outname, wxString userDefinedOutput=wxEmptyString)
Starts stitching of project file.
int GetProcessId()
Returns process ID of running process.
bool DetectProject(wxString scriptFile, wxString userDefinedAssistant=wxEmptyString)
starts assistant of project file
bool SaveLog(const wxString &filename)
save the content of the window into a given log file
bool DetectProject(const wxString &scriptFile, const wxString &userDefinedAssistant=wxEmptyString)
void SetProjectId(int id)
Sets project id from batch.
int GetProjectId()
Gets project id from batch.
void SetProcessId(int pid)
Sets process ID of running process (if running process from outside)
bool SaveLog(const wxString &filename)
save the content of the window into a given log file