1 /***************************************************************************
2  *
3  * Project:  OpenCPN
4  * Purpose:  S57 Chart Object
5  * Author:   David Register
6  *
7  ***************************************************************************
8  *   Copyright (C) 2010 by David S. Register                               *
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program; if not, write to the                         *
22  *   Free Software Foundation, Inc.,                                       *
23  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.         *
24  **************************************************************************/
25 
26 #ifndef __SENCMGR_H__
27 #define __SENCMGR_H__
28 
29 // ----------------------------------------------------------------------------
30 // Useful Prototypes
31 // ----------------------------------------------------------------------------
32 
33 
34 //----------------------------------------------------------------------------
35 // Constants
36 //----------------------------------------------------------------------------
37 
38 //----------------------------------------------------------------------------
39 // Fwd Defns
40 //----------------------------------------------------------------------------
41 
42 class s57chart;
43 class SENCBuildThread;
44 
45 
46 typedef enum
47 {
48     THREAD_INACTIVE = 0,
49     THREAD_PENDING,
50     THREAD_STARTED,
51     THREAD_FINISHED
52 } SENCThreadStatus;
53 
54 typedef enum{
55     SENC_BUILD_INACTIVE = 0,
56     SENC_BUILD_PENDING,
57     SENC_BUILD_STARTED,
58     SENC_BUILD_DONE_NOERROR,
59     SENC_BUILD_DONE_ERROR,
60 } EVENTSENCResult;
61 
62 extern  const wxEventType wxEVT_OCPN_BUILDSENCTHREAD;
63 
64 //----------------------------------------------------------------------------
65 // s57 Chart Thread based SENC job ticket
66 //----------------------------------------------------------------------------
67 class SENCJobTicket
68 {
69 public:
70     SENCJobTicket();
~SENCJobTicket()71     ~SENCJobTicket() {}
72 
73     s57chart *m_chart;
74     wxString m_FullPath000;
75     wxString m_SENCFileName;
76     double ref_lat, ref_lon;
77     double m_LOD_meters;
78 
79     SENCBuildThread *m_thread;
80 
81     SENCThreadStatus m_status;
82     EVENTSENCResult m_SENCResult;
83 };
84 
85 
86 
87 //----------------------------------------------------------------------------
88 // s57 Chart Thread based SENC creator status message
89 //----------------------------------------------------------------------------
90 class OCPN_BUILDSENC_ThreadEvent: public wxEvent
91 {
92 public:
93     OCPN_BUILDSENC_ThreadEvent( wxEventType commandType = wxEVT_NULL, int id = 0 );
94     ~OCPN_BUILDSENC_ThreadEvent( );
95 
96     // required for sending with wxPostEvent()
97     wxEvent *Clone() const;
98 
99     int stat;
100     EVENTSENCResult type;
101     SENCJobTicket *m_ticket;
102 
103 
104 private:
105 };
106 
107 //----------------------------------------------------------------------------
108 // s57 Chart Thread based SENC creator
109 //----------------------------------------------------------------------------
110 class SENCThreadManager : public wxEvtHandler
111 {
112 public:
113     SENCThreadManager();
114     ~SENCThreadManager();
115 
116     void OnEvtThread( OCPN_BUILDSENC_ThreadEvent & event );
117 
118     SENCThreadStatus ScheduleJob( SENCJobTicket *ticket);
119     void FinishJob(SENCJobTicket *ticket);
120     void StartTopJob();
121     bool IsChartInTicketlist(s57chart *chart);
122     bool SetChartPointer(s57chart *chart, void *new_ptr);
123     int GetJobCount();
124 
125     int                 m_max_jobs;
126 
127     std::vector<SENCJobTicket *> ticket_list;
128 };
129 
130 
131 //----------------------------------------------------------------------------
132 // s57 Chart Thread based SENC creator
133 //----------------------------------------------------------------------------
134 class SENCBuildThread : public wxThread
135 {
136 public:
137     SENCBuildThread( SENCJobTicket *ticket, SENCThreadManager *manager);
138     void *Entry();
139 
140     wxString m_FullPath000;
141     wxString m_SENCFileName;
142     s57chart *m_chart;
143     SENCThreadManager *m_manager;
144     SENCJobTicket *m_ticket;
145 
146 };
147 
148 
149 
150 
151 
152 #endif
153