Blame view

GUI/SW2/SRC/src/main/HelpTasks.cpp 12.6 KB
886c558b   Steve Greedy   SACAMOS Public Re...
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
//**************************************************************************************************
//                                          HelpTasks.cpp                                          *
//                                         ---------------                                         *
//  Started     : 2005-06-03                                                                       *
//  Last Update : 2016-10-09                                                                       *
//  Copyright   : (C) 2005-2016 MSWaters                                                           *
//**************************************************************************************************

//**************************************************************************************************
//                                                                                                 *
//      This program is free software; you can redistribute it and/or modify it under the          *
//      terms of the GNU General Public License as published by the Free Software Foundation;      *
//      either version 3 of the License, or (at your option) any later version.                    *
//                                                                                                 *
//**************************************************************************************************

#include "HelpTasks.hpp"
#include "FrmMain.hpp"

// The application icons
#include "icons/gspiceui-32x32.xpm"
#include "icons/html-forward.xpm"
#include "icons/html-back.xpm"
#include "icons/html-close.xpm"

//**************************************************************************************************
// Implement an event table in which the events are routed to their respective handler functions in
// the class. If -1 is given as the ID, the given handler will be invoked for any event of the
// specified type.

wxBEGIN_EVENT_TABLE( HelpTasks, wxFrame )

  EVT_TOOL( HelpTasks::ID_TBR_FORWD, HelpTasks::OnToolForwd )
  EVT_TOOL( HelpTasks::ID_TBR_BCKWD, HelpTasks::OnToolBckwd )
  EVT_TOOL( HelpTasks::ID_TBR_CLOSE, HelpTasks::OnToolClose )

  EVT_CLOSE(                         HelpTasks::OnFrmClose  )

wxEND_EVENT_TABLE( )

//**************************************************************************************************
// Constructor.
//
// Argument List :
//   poFrmMain - A pointer to the parent frame

HelpTasks::HelpTasks( FrmMain * poFrmMain ) :
                  wxFrame( poFrmMain, -1, wxT(""), wxDefaultPosition,
                           wxDefaultSize, wxDEFAULT_FRAME_STYLE ),
                  m_oHtmlWin( this )
{
  // Set the pointer to the parent frame
  m_poFrmMain = poFrmMain;

  // Initialize the help viewer
  Initialize( );
}

//**************************************************************************************************
// Destructor.

HelpTasks::~HelpTasks( )
{
}

//**************************************************************************************************
// Initialize the main frame.

void  HelpTasks::Initialize( void )
{
  // Set the frame icon
  SetIcon( wxICON( gspiceui32x32 ) );

  // Set the frame title
  SetTitle( );

  // Call all the initialization functions
  InitToolBar( );
  InitHtmlWin( );
  InitPosnSize( );
}

//**************************************************************************************************
// Initialize the tool bar.

void  HelpTasks::InitToolBar( void )
{
  wxBitmap  * poPixMap[ 3 ];
  wxToolBar * poToolBar;

  // Create the tool bar
  poToolBar = CreateToolBar( wxHORIZONTAL | wxTB_FLAT );

  // Create the bitmaps for the tools
  poPixMap[ 0 ] = new wxBitmap( html_back_xpm    );
  poPixMap[ 1 ] = new wxBitmap( html_forward_xpm );
  poPixMap[ 2 ] = new wxBitmap( html_close_xpm   );

  // Add the tools to the toolbar
  poToolBar->AddTool( ID_TBR_BCKWD, wxT(""), *(poPixMap[ 0 ]), wxT("Back")    );
  poToolBar->AddTool( ID_TBR_FORWD, wxT(""), *(poPixMap[ 1 ]), wxT("Forward") );
  poToolBar->AddTool( ID_TBR_CLOSE, wxT(""), *(poPixMap[ 2 ]), wxT("Close")   );

  // Realize the toolbar
  poToolBar->Realize( );

  // Can delete the bitmaps since they're reference counted
  for( int i1=0; i1<3; i1++ ) delete poPixMap[ i1 ];
}

//**************************************************************************************************
// Initialize the frames position amd size.

void  HelpTasks::InitHtmlWin( void )
{
  // Enable display of image types
  wxInitAllImageHandlers( );

  // Set suitable wxHtmlWindow font sizes
  int  ia[ 7 ]={ 9,10,11,14,16,18,20 };
  m_oHtmlWin.SetFonts( wxT(""), wxT(""), ia );
}

//**************************************************************************************************
// Initialize the frames position amd size.

void  HelpTasks::InitPosnSize( void )
{
  int  iPosnX, iPosnY, iSizeW, iSizeH;

  // Get the position and size from the configuration object
  iPosnX = g_oConfig.iGetHelpPosnX( );
  iPosnY = g_oConfig.iGetHelpPosnY( );
  iSizeW = g_oConfig.iGetHelpSizeW( );
  iSizeH = g_oConfig.iGetHelpSizeH( );

  // Set the position and size
  if( iPosnX>0 && iPosnY>0 ) Move( iPosnX, iPosnY );
  if( iSizeW>0 && iSizeH>0 ) SetClientSize( iSizeW, iSizeH );
}

//**************************************************************************************************
// Determine the path to the applications base installation point.
//
// Return Values :
//   Success - The path to the installation point
//   Failure - An empty string

wxString & HelpTasks::rosGetInstallPath( void )
{
  static  wxString  osPath;
  wxPathList  opl1;
  wxFileName  ofn1;
  wxString    os1;

  osPath.Empty( );

  // Get the command used to envoke this process
  ofn1 = wxTheApp->argv[ 0 ];

  if( ! ofn1.GetPath( ).IsEmpty( ) )
  { // Extract the desired part of the path
    ofn1.Normalize( );  // Expand abbreviations eg. "..", "~', etc.
  }
  else
  { // Search env. var. PATH for the first occurrence of the app. name
    opl1.AddEnvList( wxT("PATH") );
    os1 = opl1.FindAbsoluteValidPath( ofn1.GetFullName( ) );
    ofn1 = os1;
  }

  osPath = ofn1.GetPath( );
  if( osPath.AfterLast( wxT('/') ) == wxT("bin") )
    osPath = osPath.BeforeLast( wxT('/') );

  return( osPath );
}

//**************************************************************************************************
// Set the help frame title.

void  HelpTasks::SetTitle( void )
{
  wxString  os1;

  os1 = wxT("GNU Spice GUI - User Manual");

  if( ! m_oHtmlWin.GetOpenedPage( ).IsEmpty( ) )
    os1 << wxT("  -  ") << m_oHtmlWin.GetOpenedPage( );

  wxFrame::SetTitle( os1 );
}

//**************************************************************************************************
// Display the gSpiceUI User Manual.

void  HelpTasks::ManualUser( void )
{
  wxFileName  ofn1, ofn2;
  wxString    os1;

  // Check if the manual has been loaded into memory
  if( m_oHtmlWin.GetOpenedPage( ).IsEmpty( ) )
  {
    // Specify the two locations to search
    os1 = rosGetInstallPath( );
    if( os1.IsEmpty( ) ) return;
    ofn1 = os1 + wxT("/share/gspiceui/html/User-Manual.html");
    ofn2 = os1 + wxT("/html/User-Manual.html");

    // Search for the manual
    if(      ofn1.FileExists( ) ) os1 = ofn1.GetFullPath( );
    else if( ofn2.FileExists( ) ) os1 = ofn2.GetFullPath( );
    else
    {
      // Display an error message
      os1.Empty( );
      os1 << wxT("\nThe base manual page \"") << ofn1.GetFullName( ) << wxT('\"')
          << wxT(" couldn't be found in either of the following locations :\n\n")
          << wxT("     ") << ofn1.GetPath( ) << wxT("/\n")
          << wxT("     ") << ofn2.GetPath( ) << wxT("/\n");
      wxMessageBox( os1, wxT("User Manual"), wxOK | wxCENTRE, m_poFrmMain );
      return;
    }

    // Load the manual
    m_oHtmlWin.LoadPage( os1 );
    SetTitle( );
  }

  // Show the manual
  Show( true );
}

//**************************************************************************************************
// Display the about message dialog.

void  HelpTasks::About( void )
{
  wxString  os1;
  long      lStyle;

  os1 << wxT("\ngSpiceUI vSACAMOS (version SACAMOS) is a lightly modified")
	  << wxT("\nversion of gSpiceUI authored by Mike Waters:")
      << wxT("\n(https://sourceforge.net/projects/gspiceui/).")
      << wxT("\nThe modifications do not alter the intended functionality of the ")
      << wxT("\noriginal project but simply adds an addtional set of menu commands ")
      << wxT("\nfrom which  guide the user through the steps required to utilise the  ")
	  << wxT("\nSpice sub-circuits genrated by SACAMOS, i.e: \n")

	  << wxT("\n   i)  Import the symbols generated by SACAMOS into gschem")
	  << wxT("\n   ii) Launch gSchem to design a schematic")
	  << wxT("\n  iii) Generate the netlist against which ro run the Ngspice solver")
	  << wxT("\n  iv)  View the results using gnuplot\n")
	 
	  << wxT("\ngSpiceUI v SACAMOS modifies the following gSpiceUI files:")
	  << wxT("\nFrmMaain.cpp,FrmMain.hpp, FileTasks.cpp and HelpTasks.cpp\n\n")
  
	  << wxT("\n                                     " ) << APP_NAME
      << wxT("\n                     Version ")          << APP_VERSION
                                            << wxT(" (") << APP_DATE << wxT(")")
      << wxT("\n               ")                        << APP_COPYRIGHT
      << wxT("\n\n")

      << wxT("\nThis application is intended to provide a GUI for various")
      << wxT("\nfreely available electronic circuit simulation engines :\n")
      << wxT("\n                 - NG-Spice")
      << wxT("\n                 - GNU-Cap\n")

      << wxT("\nSchematic files are imported using gnetlist and waveform     ")
      << wxT("\ndata can be viewed using either ") << rosEnumEngToStr( eSIMR_NGSPICE )
      << wxT(" or ") << rosEnumEngToStr( eSIMR_GNUCAP ) << wxT(".\n")

      << wxT("\nThis application is written in C++ and uses the wxWidgets")
      << wxT("\nlibrary which is a free and open source widget toolkit and")
      << wxT("\ntools library. wxWidgets version ")
      << wxMAJOR_VERSION << wxT('.') << wxMINOR_VERSION << wxT('.') << wxRELEASE_NUMBER
      << wxT(" was used in this")
      << wxT("\nbuild of ") << APP_NAME << wxT(".\n")

      << wxT("\n") << APP_NAME << wxT(" is free software; you can redistribute it and/or")
      << wxT("\nmodify it under the terms of the GNU Library General")
      << wxT("\nPublic Licence as published by the Free Software")
      << wxT("\nFoundation; either version 3 of the Licence, or (at your")
      << wxT("\noption) any later version.\n")

      << wxT("\n") << APP_NAME << wxT(" is distributed in the hope that it will be useful,")
      << wxT("\nbut WITHOUT ANY WARRANTY; without even the implied")
      << wxT("\nwarranty of MERCHANTABILITY or FITNESS FOR A")
      << wxT("\nPARTICULAR PURPOSE.");

  lStyle = wxOK | wxICON_INFORMATION;

  wxMessageBox( os1, wxT("About gSpiceUI"), lStyle, m_poFrmMain );
}

//**************************************************************************************************
// Go to the next page in the history store.
//
// Argument List :
//   roEvtCmd - The event to be processed

void  HelpTasks::OnToolForwd( wxCommandEvent & roEvtCmd )
{
  if( m_oHtmlWin.HistoryCanForward( ) )
    m_oHtmlWin.HistoryForward( );
}

//**************************************************************************************************
// Go to the previous page in the history store.
//
// Argument List :
//   roEvtCmd - The event to be processed

void  HelpTasks::OnToolBckwd( wxCommandEvent & roEvtCmd )
{
  if( m_oHtmlWin.HistoryCanBack( ) )
    m_oHtmlWin.HistoryBack( );
}

//**************************************************************************************************
// Close the help viewer frame.
//
// Argument List :
//   roEvtCmd - The event to be processed

void  HelpTasks::OnToolClose( wxCommandEvent & roEvtCmd )
{
  int  iPosnX, iPosnY, iSizeW, iSizeH;

  // Save the frame size and position
  GetPosition( &iPosnX, &iPosnY );
  GetClientSize( &iSizeW, &iSizeH );
  g_oConfig.bSetHelpPosnX( iPosnX );
  g_oConfig.bSetHelpPosnY( iPosnY );
  g_oConfig.bSetHelpSizeW( iSizeW );
  g_oConfig.bSetHelpSizeH( iSizeH );

  g_oConfig.bFlush( );  // Write changes to the configuration file

  Show( false );        // Hide the frame

  // Reset the HTML Window settings
  while( m_oHtmlWin.HistoryCanBack( ) )
    m_oHtmlWin.HistoryBack( );
  m_oHtmlWin.HistoryClear( );
  m_oHtmlWin.Scroll( 0, 0 );
}

//**************************************************************************************************
// Close the help viewer frame.
//
// Argument List :
//   roEvtClose - The event to be processed

void  HelpTasks::OnFrmClose( wxCloseEvent & roEvtClose )
{
  wxCommandEvent  oEvtCmd;

  OnToolClose( oEvtCmd );
}

//**************************************************************************************************