* KIWAY Milestone A): Make major modules into DLL/DSOs.

!   The initial testing of this commit should be done using a Debug build so that
    all the wxASSERT()s are enabled.  Also, be sure and keep enabled the
    USE_KIWAY_DLLs option.  The tree won't likely build without it.  Turning it
    off is senseless anyways.  If you want stable code, go back to a prior version,
    the one tagged with "stable".

*   Relocate all functionality out of the wxApp derivative into more finely
    targeted purposes:
    a) DLL/DSO specific
    b) PROJECT specific
    c) EXE or process specific
    d) configuration file specific data
    e) configuration file manipulations functions.

    All of this functionality was blended into an extremely large wxApp derivative
    and that was incompatible with the desire to support multiple concurrently
    loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
    An amazing amount of organization come from simply sorting each bit of
    functionality into the proper box.

*   Switch to wxConfigBase from wxConfig everywhere except instantiation.
*   Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
    PGM_SINGLE_TOP,
*   Remove "Return" prefix on many function names.
*   Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
*   Fix building boost for use in a DSO on linux.
*   Remove some of the assumptions in the CMakeLists.txt files that windows had
    to be the host platform when building windows binaries.
*   Reduce the number of wxStrings being constructed at program load time via
    static construction.
*   Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
    these functions are useful even when the wxConfigBase comes from another
    source, as is the case in the KICAD_MANAGER_FRAME.
*   Move the setting of the KIPRJMOD environment variable into class PROJECT,
    so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
*   Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
    its child wxFrames and wxDialogs now have a Kiway() member function which
    returns a KIWAY& that that window tree branch is in support of.  This is like
    wxWindows DNA in that child windows get this member with proper value at time
    of construction.
*   Anticipate some of the needs for milestones B) and C) and make code
    adjustments now in an effort to reduce work in those milestones.
*   No testing has been done for python scripting, since milestone C) has that
    being largely reworked and re-thought-out.
This commit is contained in:
Dick Hollenbeck
2014-03-19 19:42:08 -05:00
parent ec9c949c9b
commit 2c67c3ff80
335 changed files with 9281 additions and 6943 deletions
+185 -97
View File
@@ -21,8 +21,11 @@
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <fctsys.h>
#include <appl_wxstruct.h>
#include <macros.h>
#include <pgm_base.h>
#include <wxstruct.h>
#include <confirm.h>
#include <gestfich.h>
@@ -39,47 +42,53 @@
#include <colors_selection.h>
#include <build_version.h>
#include <menus_helpers.h>
#include <kiway.h>
#include <kiface_i.h>
#define KEYWORD_FRAME_POSX wxT( "Bmconverter_Pos_x" )
#define KEYWORD_FRAME_POSY wxT( "Bmconverter_Pos_y" )
#define KEYWORD_FRAME_SIZEX wxT( "Bmconverter_Size_x" )
#define KEYWORD_FRAME_SIZEY wxT( "Bmconverter_Size_y" )
#define KEYWORD_LAST_INPUT_FILE wxT( "Last_input" )
#define KEYWORD_LAST_OUTPUT_FILE wxT( "Last_output" )
#define KEYWORD_LAST_FORMAT wxT( "Last_format" )
#define KEYWORD_BINARY_THRESHOLD wxT( "Threshold" )
#define KEYWORD_BW_NEGATIVE wxT( "Negative_choice" )
#define KEYWORD_FRAME_POSX wxT( "Bmconverter_Pos_x" )
#define KEYWORD_FRAME_POSY wxT( "Bmconverter_Pos_y" )
#define KEYWORD_FRAME_SIZEX wxT( "Bmconverter_Size_x" )
#define KEYWORD_FRAME_SIZEY wxT( "Bmconverter_Size_y" )
#define KEYWORD_LAST_INPUT_FILE wxT( "Last_input" )
#define KEYWORD_LAST_OUTPUT_FILE wxT( "Last_output" )
#define KEYWORD_LAST_FORMAT wxT( "Last_format" )
#define KEYWORD_BINARY_THRESHOLD wxT( "Threshold" )
#define KEYWORD_BW_NEGATIVE wxT( "Negative_choice" )
extern int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE* aOutfile, int aFormat );
/* Class BM2CMP_FRAME_BASE
This is the main frame for this application
*/
/**
* Class BM2CMP_FRAME_BASE
* is the main frame for this application
*/
class BM2CMP_FRAME : public BM2CMP_FRAME_BASE
{
private:
wxImage m_Pict_Image;
wxBitmap m_Pict_Bitmap;
wxImage m_Greyscale_Image;
wxBitmap m_Greyscale_Bitmap;
wxImage m_NB_Image;
wxBitmap m_BN_Bitmap;
wxString m_BitmapFileName;
wxString m_ConvertedFileName;
wxSize m_FrameSize;
wxPoint m_FramePos;
wxConfig * m_Config;
wxImage m_Pict_Image;
wxBitmap m_Pict_Bitmap;
wxImage m_Greyscale_Image;
wxBitmap m_Greyscale_Bitmap;
wxImage m_NB_Image;
wxBitmap m_BN_Bitmap;
wxString m_BitmapFileName;
wxString m_ConvertedFileName;
wxSize m_FrameSize;
wxPoint m_FramePos;
wxConfig* m_Config;
public:
BM2CMP_FRAME();
BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent );
~BM2CMP_FRAME();
// overload KIWAY_PLAYER virtual
bool OpenProjectFiles( const std::vector<wxString>& aFilenames, int aCtl=0 );
private:
// Event handlers
void OnPaint( wxPaintEvent& event );
void OnLoadFile( wxCommandEvent& event );
bool LoadFile( wxString& aFullFileName );
void OnExport( wxCommandEvent& event );
/**
@@ -114,8 +123,11 @@ private:
};
BM2CMP_FRAME::BM2CMP_FRAME() : BM2CMP_FRAME_BASE( NULL )
BM2CMP_FRAME::BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
BM2CMP_FRAME_BASE( aParent )
{
SetKiway( this, aKiway );
int tmp;
m_Config = new wxConfig();
m_Config->Read( KEYWORD_FRAME_POSX, & m_FramePos.x, -1 );
@@ -124,15 +136,16 @@ BM2CMP_FRAME::BM2CMP_FRAME() : BM2CMP_FRAME_BASE( NULL )
m_Config->Read( KEYWORD_FRAME_SIZEY, & m_FrameSize.y, -1 );
m_Config->Read( KEYWORD_LAST_INPUT_FILE, &m_BitmapFileName );
m_Config->Read( KEYWORD_LAST_OUTPUT_FILE, &m_ConvertedFileName );
if( m_Config->Read( KEYWORD_BINARY_THRESHOLD, &tmp ) )
m_sliderThreshold->SetValue( tmp );
if( m_Config->Read( KEYWORD_BW_NEGATIVE, &tmp ) )
m_rbOptions->SetSelection( tmp ? 1 : 0 );
m_Config->Read( KEYWORD_LAST_FORMAT, &tmp );
m_radioBoxFormat->SetSelection( tmp );
// Give an icon
wxIcon icon;
icon.CopyFromBitmap( KiBitmap( icon_bitmap2component_xpm ) );
@@ -144,14 +157,14 @@ BM2CMP_FRAME::BM2CMP_FRAME() : BM2CMP_FRAME_BASE( NULL )
m_buttonExport->Enable( false );
if ( m_FramePos == wxDefaultPosition )
if( m_FramePos == wxDefaultPosition )
Centre();
}
BM2CMP_FRAME::~BM2CMP_FRAME()
{
if( ( m_Config == NULL ) || IsIconized() )
if( !m_Config || IsIconized() )
return;
m_FrameSize = GetSize();
@@ -207,23 +220,24 @@ void BM2CMP_FRAME::OnPaint( wxPaintEvent& event )
*/
void BM2CMP_FRAME::OnLoadFile( wxCommandEvent& event )
{
wxFileName fn(m_BitmapFileName);
wxString path = fn.GetPath();
wxFileName fn(m_BitmapFileName);
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
path = wxGetCwd();
wxFileDialog FileDlg( this, _( "Choose Image" ), path, wxEmptyString,
wxFileDialog fileDlg( this, _( "Choose Image" ), path, wxEmptyString,
_( "Image Files " ) + wxImage::GetImageExtWildcard(),
wxFD_OPEN );
int diag = FileDlg.ShowModal();
int diag = fileDlg.ShowModal();
if( diag != wxID_OK )
return;
wxString fullFilename = FileDlg.GetPath();
wxString fullFilename = fileDlg.GetPath();
if( ! LoadFile( fullFilename ) )
if( !OpenProjectFiles( std::vector<wxString>( 1, fullFilename ) ) )
return;
m_buttonExport->Enable( true );
@@ -232,13 +246,22 @@ void BM2CMP_FRAME::OnLoadFile( wxCommandEvent& event )
}
bool BM2CMP_FRAME::LoadFile( wxString& aFullFileName )
bool BM2CMP_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
{
m_BitmapFileName = aFullFileName;
// Prj().MaybeLoadProjectSettings();
m_BitmapFileName = aFileSet[0];
if( !m_Pict_Image.LoadFile( m_BitmapFileName ) )
{
wxMessageBox( _( "Couldn't load image from <%s>" ), m_BitmapFileName.c_str() );
/* LoadFile has its own UI, no need for further failure notification here
wxString msg = wxString::Format(
_( "Could not load image '%s'" ),
GetChars( aFilename )
);
wxMessageBox( msg );
*/
return false;
}
@@ -249,6 +272,7 @@ bool BM2CMP_FRAME::LoadFile( wxString& aFullFileName )
int nb = m_Pict_Bitmap.GetDepth();
wxString msg;
msg.Printf( wxT( "%d" ), w );
m_SizeXValue->SetLabel(msg);
msg.Printf( wxT( "%d" ), h );
@@ -262,12 +286,14 @@ bool BM2CMP_FRAME::LoadFile( wxString& aFullFileName )
m_Greyscale_Image.Destroy();
m_Greyscale_Image = m_Pict_Image.ConvertToGreyscale( );
if( m_rbOptions->GetSelection() > 0 )
NegateGreyscaleImage( );
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image );
m_NB_Image = m_Greyscale_Image;
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
Binarize( (double) m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
return true;
}
@@ -297,9 +323,10 @@ void BM2CMP_FRAME::Binarize( double aThreshold )
m_BN_Bitmap = wxBitmap( m_NB_Image );
}
void BM2CMP_FRAME::NegateGreyscaleImage( )
{
unsigned char pix;
unsigned char pix;
int h = m_Greyscale_Image.GetHeight();
int w = m_Greyscale_Image.GetWidth();
@@ -321,58 +348,61 @@ void BM2CMP_FRAME::OnOptionsSelection( wxCommandEvent& event )
Refresh();
}
void BM2CMP_FRAME::OnThresholdChange( wxScrollEvent& event )
{
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
Refresh();
}
void BM2CMP_FRAME::OnExport( wxCommandEvent& event )
{
int sel = m_radioBoxFormat->GetSelection();
switch( sel )
{
case 0:
OnExportEeschema();
break;
case 0:
OnExportEeschema();
break;
case 1:
OnExportPcbnew( true );
break;
case 1:
OnExportPcbnew( true );
break;
case 2:
OnExportPcbnew( false );
break;
case 2:
OnExportPcbnew( false );
break;
case 3:
OnExportPostScript();
break;
case 3:
OnExportPostScript();
break;
case 4:
OnExportLogo();
break;
case 4:
OnExportLogo();
break;
}
}
void BM2CMP_FRAME::OnExportLogo()
{
wxFileName fn(m_ConvertedFileName);
wxString path = fn.GetPath();
wxFileName fn(m_ConvertedFileName);
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
path = ::wxGetCwd();
wxString msg = _( "Logo file (*.kicad_wks)|*.kicad_wks" );
wxFileDialog FileDlg( this, _( "Create a logo file" ), path, wxEmptyString,
wxFileDialog fileDlg( this, _( "Create a logo file" ), path, wxEmptyString,
msg,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
int diag = FileDlg.ShowModal();
int diag = fileDlg.ShowModal();
if( diag != wxID_OK )
return;
m_ConvertedFileName = FileDlg.GetPath();
m_ConvertedFileName = fileDlg.GetPath();
FILE* outfile;
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
@@ -389,24 +419,26 @@ void BM2CMP_FRAME::OnExportLogo()
fclose( outfile );
}
void BM2CMP_FRAME::OnExportPostScript()
{
wxFileName fn(m_ConvertedFileName);
wxString path = fn.GetPath();
wxFileName fn( m_ConvertedFileName );
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
if( path.IsEmpty() || !wxDirExists( path ) )
path = ::wxGetCwd();
wxString msg = _( "Postscript file (*.ps)|*.ps" );
wxFileDialog FileDlg( this, _( "Create a Postscript file" ), path, wxEmptyString,
wxFileDialog fileDlg( this, _( "Create a Postscript file" ), path, wxEmptyString,
msg,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
int diag = FileDlg.ShowModal();
int diag = fileDlg.ShowModal();
if( diag != wxID_OK )
return;
m_ConvertedFileName = FileDlg.GetPath();
m_ConvertedFileName = fileDlg.GetPath();
FILE* outfile;
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
@@ -423,27 +455,29 @@ void BM2CMP_FRAME::OnExportPostScript()
fclose( outfile );
}
void BM2CMP_FRAME::OnExportEeschema()
{
wxFileName fn(m_ConvertedFileName);
wxString path = fn.GetPath();
wxFileName fn( m_ConvertedFileName );
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
path = ::wxGetCwd();
wxString msg = _( "Schematic lib file (*.lib)|*.lib" );
wxFileDialog FileDlg( this, _( "Create a lib file for Eeschema" ), path, wxEmptyString,
wxFileDialog fileDlg( this, _( "Create a lib file for Eeschema" ), path, wxEmptyString,
msg,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
int diag = FileDlg.ShowModal();
int diag = fileDlg.ShowModal();
if( diag != wxID_OK )
return;
m_ConvertedFileName = FileDlg.GetPath();
m_ConvertedFileName = fileDlg.GetPath();
FILE* outfile;
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
FILE* outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
if( outfile == NULL )
{
@@ -460,29 +494,29 @@ void BM2CMP_FRAME::OnExportEeschema()
void BM2CMP_FRAME::OnExportPcbnew( bool aLegacyFormat )
{
wxFileName fn(m_ConvertedFileName);
wxString path = fn.GetPath();
wxFileName fn( m_ConvertedFileName );
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
if( path.IsEmpty() || !wxDirExists( path ) )
path = ::wxGetCwd();
wxString msg = aLegacyFormat ?
_( "Footprint file (*.emp)|*.emp" ) :
_( "Footprint file (*.kicad_mod)|*.kicad_mod" );
wxFileDialog FileDlg( this, _( "Create a footprint file for PcbNew" ),
wxFileDialog fileDlg( this, _( "Create a footprint file for PcbNew" ),
path, wxEmptyString,
msg,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
int diag = FileDlg.ShowModal();
int diag = fileDlg.ShowModal();
if( diag != wxID_OK )
return;
m_ConvertedFileName = FileDlg.GetPath();
m_ConvertedFileName = fileDlg.GetPath();
FILE* outfile;
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
FILE* outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
if( outfile == NULL )
{
@@ -496,6 +530,7 @@ void BM2CMP_FRAME::OnExportPcbnew( bool aLegacyFormat )
fclose( outfile );
}
void BM2CMP_FRAME::ExportFile( FILE* aOutfile, int aFormat )
{
// Create a potrace bitmap
@@ -525,29 +560,82 @@ void BM2CMP_FRAME::ExportFile( FILE* aOutfile, int aFormat )
}
// EDA_APP
IMPLEMENT_APP( EDA_APP )
//-----<KIFACE>-----------------------------------------------------------------
///-----------------------------------------------------------------------------
// EDA_APP
// main program
//-----------------------------------------------------------------------------
namespace BMP2CMP {
bool EDA_APP::OnInit()
static struct IFACE : public KIFACE_I
{
wxInitAllImageHandlers();
bool OnKifaceStart( PGM_BASE* aProgram );
InitEDA_Appl( wxT( "BMP2CMP" ) );
wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 )
{
switch( aClassId )
{
wxFrame* frame = new BM2CMP_FRAME();
SetTopWindow( frame );
frame->Show( true );
default:
{
KIWAY_PLAYER* frame = new BM2CMP_FRAME( aKiway, aParent );
return frame;
}
}
}
return true;
/**
* Function IfaceOrAddress
* return a pointer to the requested object. The safest way to use this
* is to retrieve a pointer to a static instance of an interface, similar to
* how the KIFACE interface is exported. But if you know what you are doing
* use it to retrieve anything you want.
*
* @param aDataId identifies which object you want the address of.
*
* @return void* - and must be cast into the know type.
*/
void* IfaceOrAddress( int aDataId )
{
return NULL;
}
IFACE( const char* aDSOname, KIWAY::FACE_T aType ) :
KIFACE_I( aDSOname, aType )
{}
} kiface( "BMP2CMP", KIWAY::FACE_BMP2CMP );
} // namespace BMP2CMP
using namespace BMP2CMP;
static PGM_BASE* process;
KIFACE_I& Kiface()
{
return kiface;
}
void EDA_APP::MacOpenFile( const wxString& aFileName )
// KIFACE_GETTER's actual spelling is a substitution macro found in kiway.h.
// KIFACE_GETTER will not have name mangling due to declaration in kiway.h.
MY_API( KIFACE* ) KIFACE_GETTER( int* aKIFACEversion, int aKIWAYversion, PGM_BASE* aProgram )
{
process = (PGM_BASE*) aProgram;
return &kiface;
}
#if defined(BUILD_KIWAY_DLLS)
PGM_BASE& Pgm()
{
wxASSERT( process ); // KIFACE_GETTER has already been called.
return *process;
}
#endif
bool IFACE::OnKifaceStart( PGM_BASE* aProgram )
{
return start_common();
}