Commit 22f66571 authored by charras's avatar charras

Fixed bad 3D png pictures (return to an old code). Seems specific to wxGTK.

enhancement in Cvpcb: fast selection of components or footprint by typing the first letter of reference or footprint name
parent b739b227
...@@ -77,12 +77,8 @@ Pcb3D_GLCanvas::Pcb3D_GLCanvas( WinEDA3D_DrawFrame* parent ) : ...@@ -77,12 +77,8 @@ Pcb3D_GLCanvas::Pcb3D_GLCanvas( WinEDA3D_DrawFrame* parent ) :
#if wxCHECK_VERSION( 2, 9, 0 ) #if wxCHECK_VERSION( 2, 9, 0 )
// Explicitly create a new rendering context instance for this canvas. // Explicitly create a new rendering context instance for this canvas.
m_glRC = new wxGLContext(this); m_glRC = new wxGLContext(this);
// Make the new context current (activate it for use) with this canvas.
SetCurrent(*m_glRC);
#else
SetCurrent( );
#endif #endif
DisplayStatus(); DisplayStatus();
} }
...@@ -636,25 +632,13 @@ void Pcb3D_GLCanvas::TakeScreenshot( wxCommandEvent& event ) ...@@ -636,25 +632,13 @@ void Pcb3D_GLCanvas::TakeScreenshot( wxCommandEvent& event )
Redraw( true ); Redraw( true );
struct vieport_params wxSize image_size = GetClientSize();
{ wxClientDC dc( this );
GLint originx; wxBitmap bitmap( image_size.x, image_size.y );
GLint originy; wxMemoryDC memdc;
GLint x; memdc.SelectObject( bitmap );
GLint y; memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
} viewport; memdc.SelectObject( wxNullBitmap );
glGetIntegerv( GL_VIEWPORT, (GLint*) &viewport );
unsigned char* pixelbuffer = (unsigned char*) malloc( 3 * viewport.x * viewport.y );
glReadPixels( 0, 0, viewport.x, viewport.y, GL_RGB, GL_UNSIGNED_BYTE, pixelbuffer );
wxImage image( viewport.x, viewport.y );
image.SetData( pixelbuffer );
image = image.Mirror();
image = image.Rotate90().Rotate90();
wxBitmap bitmap( image, -1 );
if( event.GetId() == ID_TOOL_SCREENCOPY_TOCLIBBOARD ) if( event.GetId() == ID_TOOL_SCREENCOPY_TOCLIBBOARD )
{ {
...@@ -671,6 +655,8 @@ void Pcb3D_GLCanvas::TakeScreenshot( wxCommandEvent& event ) ...@@ -671,6 +655,8 @@ void Pcb3D_GLCanvas::TakeScreenshot( wxCommandEvent& event )
} }
else else
{ {
wxImage image = bitmap.ConvertToImage();
if( !image.SaveFile( FullFileName, if( !image.SaveFile( FullFileName,
fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) ) fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
wxLogError( wxT( "Can't save file" ) ); wxLogError( wxT( "Can't save file" ) );
......
...@@ -57,7 +57,8 @@ void Pcb3D_GLCanvas::Redraw( bool finish ) ...@@ -57,7 +57,8 @@ void Pcb3D_GLCanvas::Redraw( bool finish )
// handler, changing the size of one canvas causes a viewport setting that // handler, changing the size of one canvas causes a viewport setting that
// is wrong when next another canvas is repainted. // is wrong when next another canvas is repainted.
const wxSize ClientSize = GetClientSize(); const wxSize ClientSize = GetClientSize();
// *MUST* be called after SetCurrent( ):
// *MUST* be called *after* SetCurrent( ):
glViewport( 0, 0, ClientSize.x, ClientSize.y ); glViewport( 0, 0, ClientSize.x, ClientSize.y );
InitGL(); InitGL();
......
...@@ -11,6 +11,8 @@ set(CVPCB_SRCS ...@@ -11,6 +11,8 @@ set(CVPCB_SRCS
autosel.cpp autosel.cpp
cfg.cpp cfg.cpp
class_cvpcb.cpp class_cvpcb.cpp
class_components_listbox.cpp
class_footprints_listbox.cpp
cvframe.cpp cvframe.cpp
cvpcb.cpp cvpcb.cpp
dialog_cvpcb_config.cpp dialog_cvpcb_config.cpp
......
/*************************************************************************/
/* listboxes.cpp: class for displaying footprint list and component list */
/*************************************************************************/
#include "fctsys.h"
#include "wxstruct.h"
#include "common.h"
#include "id.h"
#include "cvpcb.h"
#include "protos.h"
#include "cvstruct.h"
/**************************************************/
/* ListBox handling the schematic components list */
/**************************************************/
COMPONENTS_LISTBOX::COMPONENTS_LISTBOX( WinEDA_CvpcbFrame* parent, wxWindowID id,
const wxPoint& loc, const wxSize& size,
int nbitems, wxString choice[] ) :
ITEMS_LISTBOX_BASE( parent, id, loc, size )
{
}
COMPONENTS_LISTBOX::~COMPONENTS_LISTBOX()
{
}
/* Build the events table for the schematic components list box
*/
BEGIN_EVENT_TABLE( COMPONENTS_LISTBOX, ITEMS_LISTBOX_BASE )
EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
EVT_CHAR( COMPONENTS_LISTBOX::OnChar )
END_EVENT_TABLE()
void COMPONENTS_LISTBOX::Clear()
{
m_ComponentList.Clear();
SetItemCount( 0 );
}
int COMPONENTS_LISTBOX::GetCount()
{
return m_ComponentList.Count();
}
void COMPONENTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
{
if( linecount >= m_ComponentList.Count() )
linecount = m_ComponentList.Count() - 1;
if( linecount >= 0 )
m_ComponentList[linecount] = text;
}
void COMPONENTS_LISTBOX::AppendLine( const wxString& text )
{
m_ComponentList.Add( text );
SetItemCount( m_ComponentList.Count() );
}
/*
* Overlaid function: MUST be provided in wxLC_VIRTUAL mode
* because real data are not handled by ITEMS_LISTBOX_BASE
*/
wxString COMPONENTS_LISTBOX::OnGetItemText( long item, long column ) const
{
return m_ComponentList.Item( item );
}
/*
* Enable or disable an item
*/
void COMPONENTS_LISTBOX::SetSelection( unsigned index, bool State )
{
if( (int) index >= GetCount() )
index = GetCount() - 1;
if( (index >= 0) && (GetCount() > 0) )
{
#ifndef __WXMAC__
Select( index, State );
#endif
EnsureVisible( index );
#ifdef __WXMAC__
Refresh();
#endif
}
}
/** function OnChar
* called on a key pressed
* Call default handler for some special keys,
* and for "ascii" keys, select the first component
* that the name starts by the letter.
* This is the defaut behaviour of a listbox, but because we use
* virtual lists, the listbox does not know anything to what is displayed,
* we must handle this behaviour here.
* Furthermore the reference of components is not at the beginning of
* displayed lines (the first word is the line number)
*/
void COMPONENTS_LISTBOX::OnChar( wxKeyEvent& event )
{
int key = event.GetKeyCode();
switch( key )
{
case WXK_HOME:
case WXK_END:
case WXK_UP:
case WXK_DOWN:
case WXK_PAGEUP:
case WXK_PAGEDOWN:
case WXK_LEFT:
case WXK_NUMPAD_LEFT:
event.Skip();
return;
case WXK_RIGHT:
case WXK_NUMPAD_RIGHT:
GetParent()->m_FootprintList->SetFocus();
return;
default:
break;
}
// Search for an item name starting by the key code:
key = toupper(key);
for( unsigned ii = 0; ii < m_ComponentList.GetCount(); ii++ )
{
wxString text = m_ComponentList.Item(ii);
/* search for the start char of the footprint name.
* we must skip the line number
*/
text.Trim(false); // Remove leading spaces in line
unsigned jj = 0;
for( ; jj < text.Len(); jj++ )
{ // skip line number
if( text[jj] == ' ' )
break;
}
for( ; jj < text.Len(); jj++ )
{ // skip blanks
if( text[jj] != ' ' )
break;
}
int start_char = toupper(text[jj]);
if ( key == start_char )
{
Focus( ii );
SetSelection( ii, true ); // Ensure visible
break;
}
}
}
/*************************************************************************/
/* listboxes.cpp: class for displaying footprint list and component list */
/*************************************************************************/
#include "fctsys.h"
#include "wxstruct.h"
#include "common.h"
#include "id.h"
#include "cvpcb.h"
#include "protos.h"
#include "cvstruct.h"
/***************************************/
/* ListBox handling the footprint list */
/***************************************/
FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX( WinEDA_CvpcbFrame* parent,
wxWindowID id, const wxPoint& loc,
const wxSize& size,
int nbitems, wxString choice[] ) :
ITEMS_LISTBOX_BASE( parent, id, loc, size )
{
m_UseFootprintFullList = true;
m_ActiveFootprintList = NULL;
SetActiveFootprintList( TRUE );
}
FOOTPRINTS_LISTBOX::~FOOTPRINTS_LISTBOX()
{
}
/*
* Return number of items
*/
int FOOTPRINTS_LISTBOX::GetCount()
{
return m_ActiveFootprintList->Count();
}
/*
* Change an item text
*/
void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
{
if( linecount >= m_ActiveFootprintList->Count() )
linecount = m_ActiveFootprintList->Count() - 1;
if( linecount >= 0 )
(*m_ActiveFootprintList)[linecount] = text;
}
wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint()
{
wxString FootprintName;
int ii = GetFirstSelected();
if( ii >= 0 )
{
wxString msg = (*m_ActiveFootprintList)[ii];
msg.Trim( TRUE );
msg.Trim( FALSE );
FootprintName = msg.AfterFirst( wxChar( ' ' ) );
}
return FootprintName;
}
void FOOTPRINTS_LISTBOX::AppendLine( const wxString& text )
{
m_ActiveFootprintList->Add( text );
SetItemCount( m_ActiveFootprintList->Count() );
}
/*
* Overlaid function: MUST be provided in wxLC_VIRTUAL mode
* because real data is not handled by ITEMS_LISTBOX_BASE
*/
wxString FOOTPRINTS_LISTBOX::OnGetItemText( long item, long column ) const
{
return m_ActiveFootprintList->Item( item );
}
/*
* Enable or disable an item
*/
void FOOTPRINTS_LISTBOX::SetSelection( unsigned index, bool State )
{
if( (int) index >= GetCount() )
index = GetCount() - 1;
if( (index >= 0) && (GetCount() > 0) )
{
#ifndef __WXMAC__
Select( index, State );
#endif
EnsureVisible( index );
#ifdef __WXMAC__
Refresh();
#endif
}
}
void FOOTPRINTS_LISTBOX::SetFootprintFullList( FOOTPRINT_LIST& list )
{
wxString msg;
int OldSelection = GetSelection();
m_FullFootprintList.Clear();
BOOST_FOREACH( FOOTPRINT & footprint, list ) {
msg.Printf( wxT( "%3d %s" ), m_FullFootprintList.GetCount() + 1,
footprint.m_Module.GetData() );
m_FullFootprintList.Add( msg );
}
SetActiveFootprintList( TRUE );
if( ( GetCount() == 0 )
|| ( OldSelection < 0 ) || ( OldSelection >= GetCount() ) )
SetSelection( 0, TRUE );
Refresh();
}
void FOOTPRINTS_LISTBOX::SetFootprintFilteredList( COMPONENT* Component,
FOOTPRINT_LIST& list )
{
FOOTPRINT_LIST::iterator i;
wxString msg;
unsigned jj;
int OldSelection = GetSelection();
bool HasItem = FALSE;
m_FilteredFootprintList.Clear();
BOOST_FOREACH( FOOTPRINT & footprint, list ) {
/* Search for matching footprints */
for( jj = 0; jj < Component->m_FootprintFilter.GetCount(); jj++ )
{
if( !footprint.m_Module.Matches( Component->m_FootprintFilter[jj] ) )
continue;
msg.Printf( wxT( "%3d %s" ), m_FilteredFootprintList.GetCount() + 1,
footprint.m_Module.GetData() );
m_FilteredFootprintList.Add( msg );
HasItem = TRUE;
}
}
if( HasItem )
SetActiveFootprintList( FALSE );
else
SetActiveFootprintList( TRUE );
if( ( GetCount() == 0 ) || ( OldSelection >= GetCount() ) )
SetSelection( 0, TRUE );
Refresh();
}
/** Set the footprint list. We can have 2 footprint list:
* The full footprint list
* The filtered footprint list (if the current selected component has a
* filter for footprints)
* @param FullList true = full footprint list, false = filtered footprint list
* @param Redraw = true to redraw the window
*/
void FOOTPRINTS_LISTBOX::SetActiveFootprintList( bool FullList, bool Redraw )
{
bool old_selection = m_UseFootprintFullList;
#ifdef __WINDOWS__
/* Workaround for a curious bug in wxWidgets:
* if we switch from a long list of footprints to a short list (a
* filtered footprint list), and if the selected item is near the end
* of the long list, the new list is not displayed from the top of
* the list box
*/
if( m_ActiveFootprintList )
{
bool new_selection;
if( FullList )
new_selection = TRUE;
else
new_selection = FALSE;
if( new_selection != old_selection )
SetSelection( 0, TRUE );
}
#endif
if( FullList )
{
m_UseFootprintFullList = TRUE;
m_ActiveFootprintList = &m_FullFootprintList;
SetItemCount( m_FullFootprintList.GetCount() );
}
else
{
m_UseFootprintFullList = FALSE;
m_ActiveFootprintList = &m_FilteredFootprintList;
SetItemCount( m_FilteredFootprintList.GetCount() );
}
if( Redraw )
{
if( !m_UseFootprintFullList
|| ( m_UseFootprintFullList != old_selection ) )
{
Refresh();
}
}
if( !m_UseFootprintFullList || ( m_UseFootprintFullList != old_selection ) )
{
GetParent()->SetStatusText( wxEmptyString, 0 );
GetParent()->SetStatusText( wxEmptyString, 1 );
}
wxString msg;
if( FullList )
msg.Printf( _( "Footprints (All): %d" ),
m_ActiveFootprintList->GetCount() );
else
msg.Printf( _( "Footprints (filtered): %d" ),
m_ActiveFootprintList->GetCount() );
GetParent()->SetStatusText( msg, 2 );
}
/**************************************/
/* Event table for the footprint list */
/**************************************/
BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
EVT_SIZE( ITEMS_LISTBOX_BASE::OnSize )
EVT_CHAR( FOOTPRINTS_LISTBOX::OnChar )
END_EVENT_TABLE()
/********************************************************/
void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
/********************************************************/
{
FOOTPRINT* Module;
wxString FootprintName = GetSelectedFootprint();
Module = GetModuleDescrByName( FootprintName, GetParent()->m_footprints );
if( GetParent()->DrawFrame )
{
GetParent()->CreateScreenCmp(); /* refresh general */
}
if( Module )
{
wxString msg;
msg = Module->m_Doc;
GetParent()->SetStatusText( msg, 0 );
msg = wxT( "KeyW: " );
msg += Module->m_KeyWord;
GetParent()->SetStatusText( msg, 1 );
}
}
/******************************************************/
void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
/******************************************************/
{
wxString FootprintName = GetSelectedFootprint();
GetParent()->SetNewPkg( FootprintName );
}
FOOTPRINT* GetModuleDescrByName( const wxString& FootprintName,
FOOTPRINT_LIST& list )
{
BOOST_FOREACH( FOOTPRINT & footprint, list ) {
if( footprint.m_Module == FootprintName )
return &footprint;
}
return NULL;
}
/** function OnChar
* called on a key pressed
* Call default handler for some special keys,
* and for "ascii" keys, select the first footprint
* that the name starts by the letter.
* This is the defaut behaviour of a listbox, but because we use
* virtual lists, the listbox does not know anything to what is displayed,
* we must handle this behaviour here.
* Furthermore the footprint name is not at the beginning of
* displayed lines (the first word is the line number)
*/
void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
{
int key = event.GetKeyCode();
switch( key )
{
case WXK_LEFT:
case WXK_NUMPAD_LEFT:
GetParent()->m_ListCmp->SetFocus();
return;
case WXK_HOME:
case WXK_END:
case WXK_UP:
case WXK_DOWN:
case WXK_PAGEUP:
case WXK_PAGEDOWN:
case WXK_RIGHT:
case WXK_NUMPAD_RIGHT:
event.Skip();
return;
default:
break;
}
// Search for an item name starting by the key code:
key = toupper(key);
for( unsigned ii = 0; ii < m_ActiveFootprintList->GetCount(); ii++ )
{
wxString text = m_ActiveFootprintList->Item(ii);
/* search for the start char of the footprint name.
* we must skip the line number
*/
text.Trim(false); // Remove leading spaces in line
unsigned jj = 0;
for( ; jj < text.Len(); jj++ )
{ // skip line number
if( text[jj] == ' ' )
break;
}
for( ; jj < text.Len(); jj++ )
{ // skip blanks
if( text[jj] != ' ' )
break;
}
int start_char = toupper(text[jj]);
if ( key == start_char )
{
Focus( ii );
SetSelection( ii, true ); // Ensure visible
break;
}
}
}
...@@ -84,7 +84,7 @@ BEGIN_EVENT_TABLE( WinEDA_CvpcbFrame, WinEDA_BasicFrame ) ...@@ -84,7 +84,7 @@ BEGIN_EVENT_TABLE( WinEDA_CvpcbFrame, WinEDA_BasicFrame )
WinEDA_CvpcbFrame::OnSelectFilteringFootprint ) WinEDA_CvpcbFrame::OnSelectFilteringFootprint )
// Frame events // Frame events
EVT_CHAR_HOOK( WinEDA_CvpcbFrame::OnChar ) EVT_CHAR( WinEDA_CvpcbFrame::OnChar )
EVT_CLOSE( WinEDA_CvpcbFrame::OnCloseWindow ) EVT_CLOSE( WinEDA_CvpcbFrame::OnCloseWindow )
EVT_SIZE( WinEDA_CvpcbFrame::OnSize ) EVT_SIZE( WinEDA_CvpcbFrame::OnSize )
...@@ -155,7 +155,7 @@ WinEDA_CvpcbFrame::WinEDA_CvpcbFrame( const wxString& title, long style ) : ...@@ -155,7 +155,7 @@ WinEDA_CvpcbFrame::WinEDA_CvpcbFrame( const wxString& title, long style ) :
// Creation des listes de modules disponibles et des composants du schema // Creation des listes de modules disponibles et des composants du schema
// Create child subwindows. // Create child subwindows.
BuildCmpListBox(); BuildCmpListBox();
BuildFootprintListBox(); BuildFOOTPRINTS_LISTBOX();
/* Creation des contraintes de dimension de la fenetre d'affichage des /* Creation des contraintes de dimension de la fenetre d'affichage des
* composants du schema */ * composants du schema */
...@@ -319,7 +319,22 @@ void WinEDA_CvpcbFrame::OnCloseWindow( wxCloseEvent& Event ) ...@@ -319,7 +319,22 @@ void WinEDA_CvpcbFrame::OnCloseWindow( wxCloseEvent& Event )
void WinEDA_CvpcbFrame::OnChar( wxKeyEvent& event ) void WinEDA_CvpcbFrame::OnChar( wxKeyEvent& event )
/************************************************/ /************************************************/
{ {
switch( event.GetKeyCode() )
{
case WXK_LEFT:
case WXK_NUMPAD_LEFT:
m_ListCmp->SetFocus();
break;
case WXK_RIGHT:
case WXK_NUMPAD_RIGHT:
m_FootprintList->SetFocus();;
break;
default:
event.Skip(); event.Skip();
break;
}
} }
......
...@@ -73,7 +73,7 @@ bool WinEDA_App::OnInit() ...@@ -73,7 +73,7 @@ bool WinEDA_App::OnInit()
frame->LoadProjectFile( fn.GetFullPath() ); frame->LoadProjectFile( fn.GetFullPath() );
frame->Show( TRUE ); frame->Show( TRUE );
frame->BuildFootprintListBox(); frame->BuildFOOTPRINTS_LISTBOX();
if( fn.IsOk() && fn.FileExists() ) if( fn.IsOk() && fn.FileExists() )
{ {
......
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
#include "cvpcb.h" #include "cvpcb.h"
/* Forward declarations of all top-level window classes. */ /* Forward declarations of all top-level window classes. */
class FootprintListBox; class FOOTPRINTS_LISTBOX;
class ListBoxCmp; class COMPONENTS_LISTBOX;
class WinEDA_DisplayFrame; class WinEDA_DisplayFrame;
...@@ -26,8 +26,8 @@ class WinEDA_CvpcbFrame : public WinEDA_BasicFrame ...@@ -26,8 +26,8 @@ class WinEDA_CvpcbFrame : public WinEDA_BasicFrame
public: public:
bool m_KeepCvpcbOpen; bool m_KeepCvpcbOpen;
FootprintListBox* m_FootprintList; FOOTPRINTS_LISTBOX* m_FootprintList;
ListBoxCmp* m_ListCmp; COMPONENTS_LISTBOX* m_ListCmp;
WinEDA_DisplayFrame* DrawFrame; WinEDA_DisplayFrame* DrawFrame;
WinEDA_Toolbar* m_HToolBar; // Toolbar horizontal haut d'ecran WinEDA_Toolbar* m_HToolBar; // Toolbar horizontal haut d'ecran
wxFileName m_NetlistFileName; wxFileName m_NetlistFileName;
...@@ -48,7 +48,7 @@ protected: ...@@ -48,7 +48,7 @@ protected:
// Constructor and destructor // Constructor and destructor
public: public:
WinEDA_CvpcbFrame( const wxString &title, WinEDA_CvpcbFrame( const wxString& title,
long style = KICAD_DEFAULT_DRAWFRAME_STYLE ); long style = KICAD_DEFAULT_DRAWFRAME_STYLE );
~WinEDA_CvpcbFrame(); ~WinEDA_CvpcbFrame();
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
void SetNewPkg( const wxString& package ); void SetNewPkg( const wxString& package );
void BuildCmpListBox(); void BuildCmpListBox();
void BuildFootprintListBox(); void BuildFOOTPRINTS_LISTBOX();
void CreateScreenCmp(); void CreateScreenCmp();
int SaveNetList( const wxString& FullFileName ); int SaveNetList( const wxString& FullFileName );
int SaveComponentList( const wxString& FullFileName ); int SaveComponentList( const wxString& FullFileName );
...@@ -103,30 +103,28 @@ public: ...@@ -103,30 +103,28 @@ public:
}; };
/***********************************************/ /*********************************************************************/
/* ListBox derivee pour l'affichage des listes */ /* ListBox (base class) to display lists of components or footprints */
/***********************************************/ /*********************************************************************/
class ListBoxBase : public wxListView class ITEMS_LISTBOX_BASE : public wxListView
{ {
public: public:
ITEMS_LISTBOX_BASE( WinEDA_CvpcbFrame* aParent, wxWindowID aId,
const wxPoint& aLocation, const wxSize& aSize );
ListBoxBase( WinEDA_CvpcbFrame * parent, wxWindowID id, ~ITEMS_LISTBOX_BASE();
const wxPoint &loc, const wxSize &size );
~ListBoxBase();
int GetSelection(); int GetSelection();
void OnSize( wxSizeEvent& event ); void OnSize( wxSizeEvent& event );
virtual WinEDA_CvpcbFrame* GetParent(); virtual WinEDA_CvpcbFrame* GetParent();
}; };
/************************************************************/ /******************************************/
/* ListBox derivee pour l'affichage de la liste des Modules */ /* ListBox showing the list of footprints */
/************************************************************/ /******************************************/
class FootprintListBox : public ListBoxBase class FOOTPRINTS_LISTBOX : public ITEMS_LISTBOX_BASE
{ {
private: private:
wxArrayString m_FullFootprintList; wxArrayString m_FullFootprintList;
...@@ -136,10 +134,10 @@ public: ...@@ -136,10 +134,10 @@ public:
bool m_UseFootprintFullList; bool m_UseFootprintFullList;
public: public:
FootprintListBox( WinEDA_CvpcbFrame * parent, wxWindowID id, FOOTPRINTS_LISTBOX( WinEDA_CvpcbFrame* parent, wxWindowID id,
const wxPoint &loc, const wxSize &size, const wxPoint& loc, const wxSize& size,
int nbitems, wxString choice[] ); int nbitems, wxString choice[] );
~FootprintListBox(); ~FOOTPRINTS_LISTBOX();
int GetCount(); int GetCount();
void SetSelection( unsigned index, bool State = TRUE ); void SetSelection( unsigned index, bool State = TRUE );
...@@ -152,17 +150,20 @@ public: ...@@ -152,17 +150,20 @@ public:
wxString GetSelectedFootprint(); wxString GetSelectedFootprint();
wxString OnGetItemText( long item, long column ) const; wxString OnGetItemText( long item, long column ) const;
// Events functions:
void OnLeftClick( wxListEvent& event ); void OnLeftClick( wxListEvent& event );
void OnLeftDClick( wxListEvent& event ); void OnLeftDClick( wxListEvent& event );
void OnChar( wxKeyEvent& event );
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/***************************************************************/ /****************************************************/
/* ListBox derivee pour l'affichage de la liste des Composants */ /* ListBox showing the list of schematic components */
/***************************************************************/ /****************************************************/
class ListBoxCmp : public ListBoxBase class COMPONENTS_LISTBOX : public ITEMS_LISTBOX_BASE
{ {
public: public:
wxArrayString m_ComponentList; wxArrayString m_ComponentList;
...@@ -170,11 +171,11 @@ public: ...@@ -170,11 +171,11 @@ public:
public: public:
ListBoxCmp( WinEDA_CvpcbFrame * parent, wxWindowID id, COMPONENTS_LISTBOX( WinEDA_CvpcbFrame* parent, wxWindowID id,
const wxPoint &loc, const wxSize &size, const wxPoint& loc, const wxSize& size,
int nbitems, wxString choice[] ); int nbitems, wxString choice[] );
~ListBoxCmp(); ~COMPONENTS_LISTBOX();
void Clear(); void Clear();
int GetCount(); int GetCount();
...@@ -183,12 +184,15 @@ public: ...@@ -183,12 +184,15 @@ public:
void SetString( unsigned linecount, const wxString& text ); void SetString( unsigned linecount, const wxString& text );
void AppendLine( const wxString& text ); void AppendLine( const wxString& text );
// Events functions:
void OnChar( wxKeyEvent& event );
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/*******************************************************/ /*******************************************************/
/* class WWinEDA_DisplayFrame: public WinEDA_DrawFrame */ /* class WinEDA_DisplayFrame: used to display footprints */
/*******************************************************/ /*******************************************************/
class WinEDA_DisplayFrame : public WinEDA_BasePcbFrame class WinEDA_DisplayFrame : public WinEDA_BasePcbFrame
...@@ -197,8 +201,8 @@ public: ...@@ -197,8 +201,8 @@ public:
public: public:
WinEDA_DisplayFrame( WinEDA_CvpcbFrame* father, WinEDA_DisplayFrame( WinEDA_CvpcbFrame* father,
const wxString &title, const wxString& title,
const wxPoint &pos, const wxSize &size, const wxPoint& pos, const wxSize& size,
long style = KICAD_DEFAULT_DRAWFRAME_STYLE ); long style = KICAD_DEFAULT_DRAWFRAME_STYLE );
~WinEDA_DisplayFrame(); ~WinEDA_DisplayFrame();
...@@ -225,10 +229,11 @@ public: ...@@ -225,10 +229,11 @@ public:
*/ */
virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy,
UndoRedoOpType aTypeCommand = UR_UNSPECIFIED, UndoRedoOpType aTypeCommand = UR_UNSPECIFIED,
const wxPoint& aTransformPoint = wxPoint(0,0) ) const wxPoint& aTransformPoint = wxPoint( 0, 0 ) )
{ {
} }
/** Function SaveCopyInUndoList (overloaded). /** Function SaveCopyInUndoList (overloaded).
* Creates a new entry in undo list of commands. * Creates a new entry in undo list of commands.
* add a list of pickers to handle a list of items * add a list of pickers to handle a list of items
...@@ -237,11 +242,12 @@ public: ...@@ -237,11 +242,12 @@ public:
* @param aTransformPoint = the reference point of the transformation, for commands like move * @param aTransformPoint = the reference point of the transformation, for commands like move
*/ */
virtual void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, UndoRedoOpType aTypeCommand, virtual void SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint = wxPoint(0,0) ) const wxPoint& aTransformPoint = wxPoint( 0, 0 ) )
{ {
// currently: do nothing in cvpcb. // currently: do nothing in cvpcb.
} }
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
......
...@@ -130,7 +130,7 @@ void DIALOG_CVPCB_CONFIG::OnOkClick( wxCommandEvent& event ) ...@@ -130,7 +130,7 @@ void DIALOG_CVPCB_CONFIG::OnOkClick( wxCommandEvent& event )
LoadFootprintFiles( m_Parent->m_ModuleLibNames, LoadFootprintFiles( m_Parent->m_ModuleLibNames,
m_Parent->m_footprints ); m_Parent->m_footprints );
m_Parent->BuildFootprintListBox(); m_Parent->BuildFOOTPRINTS_LISTBOX();
} }
m_Parent->SaveProjectFile( m_Parent->m_NetlistFileName.GetFullPath() ); m_Parent->SaveProjectFile( m_Parent->m_NetlistFileName.GetFullPath() );
......
...@@ -98,7 +98,7 @@ bool WinEDA_CvpcbFrame::ReadNetList() ...@@ -98,7 +98,7 @@ bool WinEDA_CvpcbFrame::ReadNetList()
LoadProjectFile( m_NetlistFileName.GetFullPath() ); LoadProjectFile( m_NetlistFileName.GetFullPath() );
LoadFootprintFiles( m_ModuleLibNames, m_footprints ); LoadFootprintFiles( m_ModuleLibNames, m_footprints );
BuildFootprintListBox(); BuildFOOTPRINTS_LISTBOX();
m_ListCmp->Clear(); m_ListCmp->Clear();
m_undefinedComponentCnt = 0; m_undefinedComponentCnt = 0;
......
...@@ -12,23 +12,24 @@ ...@@ -12,23 +12,24 @@
#include "cvstruct.h" #include "cvstruct.h"
/******************************************************************************/ /******************************************************************************
/* Basic class (from wxListView) for displaying component and footprint lists */ * Basic class (from wxListView) to display component and footprint lists
/* Not directly used: the 2 list boxes actually used are derived from it */ * Not directly used: the 2 list boxes actually used are derived from it
/******************************************************************************/ ******************************************************************************/
ListBoxBase::ListBoxBase( WinEDA_CvpcbFrame* parent, wxWindowID id, #define LISTB_STYLE wxSUNKEN_BORDER | wxLC_NO_HEADER | \
const wxPoint& loc, const wxSize& size ) : wxLC_SINGLE_SEL | wxLC_REPORT | wxLC_VIRTUAL
wxListView( parent, id, loc, size,
wxSUNKEN_BORDER | wxLC_NO_HEADER | ITEMS_LISTBOX_BASE::ITEMS_LISTBOX_BASE( WinEDA_CvpcbFrame* aParent, wxWindowID aId,
wxLC_SINGLE_SEL | wxLC_REPORT | wxLC_VIRTUAL ) const wxPoint& aLocation, const wxSize& aSize ) :
wxListView( aParent, aId, aLocation, aSize, LISTB_STYLE )
{ {
InsertColumn( 0, wxEmptyString ); InsertColumn( 0, wxEmptyString );
SetColumnWidth( 0, wxLIST_AUTOSIZE ); SetColumnWidth( 0, wxLIST_AUTOSIZE );
} }
ListBoxBase::~ListBoxBase() ITEMS_LISTBOX_BASE::~ITEMS_LISTBOX_BASE()
{ {
} }
...@@ -36,7 +37,7 @@ ListBoxBase::~ListBoxBase() ...@@ -36,7 +37,7 @@ ListBoxBase::~ListBoxBase()
/* /*
* Adjust the column width to the entire available window width * Adjust the column width to the entire available window width
*/ */
void ListBoxBase::OnSize( wxSizeEvent& event ) void ITEMS_LISTBOX_BASE::OnSize( wxSizeEvent& event )
{ {
wxSize size = GetClientSize(); wxSize size = GetClientSize();
int width = 0; int width = 0;
...@@ -50,200 +51,18 @@ void ListBoxBase::OnSize( wxSizeEvent& event ) ...@@ -50,200 +51,18 @@ void ListBoxBase::OnSize( wxSizeEvent& event )
/* /*
* Return an index for the selected item * Return an index for the selected item
*/ */
int ListBoxBase::GetSelection() int ITEMS_LISTBOX_BASE::GetSelection()
{ {
return GetFirstSelected(); return GetFirstSelected();
} }
WinEDA_CvpcbFrame* ListBoxBase::GetParent() WinEDA_CvpcbFrame* ITEMS_LISTBOX_BASE::GetParent()
{ {
return (WinEDA_CvpcbFrame*) wxListView::GetParent(); return (WinEDA_CvpcbFrame*) wxListView::GetParent();
} }
/***************************************/
/* ListBox handling the footprint list */
/***************************************/
FootprintListBox::FootprintListBox( WinEDA_CvpcbFrame* parent,
wxWindowID id, const wxPoint& loc,
const wxSize& size,
int nbitems, wxString choice[] ) :
ListBoxBase( parent, id, loc, size )
{
m_UseFootprintFullList = true;
m_ActiveFootprintList = NULL;
SetActiveFootprintList( TRUE );
}
FootprintListBox::~FootprintListBox()
{
}
/*
* Return number of items
*/
int FootprintListBox::GetCount()
{
return m_ActiveFootprintList->Count();
}
/*
* Change an item text
*/
void FootprintListBox::SetString( unsigned linecount, const wxString& text )
{
if( linecount >= m_ActiveFootprintList->Count() )
linecount = m_ActiveFootprintList->Count() - 1;
if( linecount >= 0 )
(*m_ActiveFootprintList)[linecount] = text;
}
wxString FootprintListBox::GetSelectedFootprint()
{
wxString FootprintName;
int ii = GetFirstSelected();
if( ii >= 0 )
{
wxString msg = (*m_ActiveFootprintList)[ii];
msg.Trim( TRUE );
msg.Trim( FALSE );
FootprintName = msg.AfterFirst( wxChar( ' ' ) );
}
return FootprintName;
}
void FootprintListBox::AppendLine( const wxString& text )
{
m_ActiveFootprintList->Add( text );
SetItemCount( m_ActiveFootprintList->Count() );
}
/*
* Overlaid function: MUST be provided in wxLC_VIRTUAL mode
* because real data is not handled by ListBoxBase
*/
wxString FootprintListBox::OnGetItemText( long item, long column ) const
{
return m_ActiveFootprintList->Item( item );
}
/*
* Enable or disable an item
*/
void FootprintListBox::SetSelection( unsigned index, bool State )
{
if( (int) index >= GetCount() )
index = GetCount() - 1;
if ( (index >= 0) && (GetCount() > 0) )
{
#ifndef __WXMAC__
Select( index, State );
#endif
EnsureVisible( index );
#ifdef __WXMAC__
Refresh();
#endif
}
}
/**************************************************/
/* ListBox handling the schematic components list */
/**************************************************/
ListBoxCmp::ListBoxCmp( WinEDA_CvpcbFrame* parent, wxWindowID id,
const wxPoint& loc, const wxSize& size,
int nbitems, wxString choice[] ) :
ListBoxBase( parent, id, loc, size )
{
}
ListBoxCmp::~ListBoxCmp()
{
}
/* Build the events table for the schematic components list box
*/
BEGIN_EVENT_TABLE( ListBoxCmp, ListBoxBase )
EVT_SIZE( ListBoxBase::OnSize )
END_EVENT_TABLE()
void ListBoxCmp::Clear()
{
m_ComponentList.Clear();
SetItemCount( 0 );
}
int ListBoxCmp::GetCount()
{
return m_ComponentList.Count();
}
void ListBoxCmp::SetString( unsigned linecount, const wxString& text )
{
if( linecount >= m_ComponentList.Count() )
linecount = m_ComponentList.Count() - 1;
if( linecount >= 0 )
m_ComponentList[linecount] = text;
}
void ListBoxCmp::AppendLine( const wxString& text )
{
m_ComponentList.Add( text );
SetItemCount( m_ComponentList.Count() );
}
/*
* Overlaid function: MUST be provided in wxLC_VIRTUAL mode
* because real data are not handled by ListBoxBase
*/
wxString ListBoxCmp::OnGetItemText( long item, long column ) const
{
return m_ComponentList.Item( item );
}
/*
* Enable or disable an item
*/
void ListBoxCmp::SetSelection( unsigned index, bool State )
{
if( (int) index >= GetCount() )
index = GetCount() - 1;
if ( (index >= 0) && (GetCount() > 0) )
{
#ifndef __WXMAC__
Select( index, State );
#endif
EnsureVisible( index );
#ifdef __WXMAC__
Refresh();
#endif
}
}
/* /*
* Create or update the schematic components list. * Create or update the schematic components list.
*/ */
...@@ -255,7 +74,7 @@ void WinEDA_CvpcbFrame::BuildCmpListBox() ...@@ -255,7 +74,7 @@ void WinEDA_CvpcbFrame::BuildCmpListBox()
if( m_ListCmp == NULL ) if( m_ListCmp == NULL )
{ {
m_ListCmp = new ListBoxCmp( this, ID_CVPCB_COMPONENT_LIST, m_ListCmp = new COMPONENTS_LISTBOX( this, ID_CVPCB_COMPONENT_LIST,
wxDefaultPosition, size, wxDefaultPosition, size,
0, NULL ); 0, NULL );
m_ListCmp->SetBackgroundColour( wxColour( 225, 255, 255 ) ); m_ListCmp->SetBackgroundColour( wxColour( 225, 255, 255 ) );
...@@ -268,8 +87,7 @@ void WinEDA_CvpcbFrame::BuildCmpListBox() ...@@ -268,8 +87,7 @@ void WinEDA_CvpcbFrame::BuildCmpListBox()
m_ListCmp->m_ComponentList.Clear(); m_ListCmp->m_ComponentList.Clear();
BOOST_FOREACH( COMPONENT& component, m_components ) BOOST_FOREACH( COMPONENT & component, m_components ) {
{
msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1, msg.Printf( CMP_FORMAT, m_ListCmp->GetCount() + 1,
component.m_Reference.GetData(), component.m_Reference.GetData(),
component.m_Value.GetData(), component.m_Value.GetData(),
...@@ -282,11 +100,10 @@ void WinEDA_CvpcbFrame::BuildCmpListBox() ...@@ -282,11 +100,10 @@ void WinEDA_CvpcbFrame::BuildCmpListBox()
} }
/* /*
* Create or update the footprint list. * Create or update the footprint list.
*/ */
void WinEDA_CvpcbFrame::BuildFootprintListBox() void WinEDA_CvpcbFrame::BuildFOOTPRINTS_LISTBOX()
{ {
wxString msg; wxString msg;
wxSize size( 10, 10 ); wxSize size( 10, 10 );
...@@ -294,7 +111,7 @@ void WinEDA_CvpcbFrame::BuildFootprintListBox() ...@@ -294,7 +111,7 @@ void WinEDA_CvpcbFrame::BuildFootprintListBox()
if( m_FootprintList == NULL ) if( m_FootprintList == NULL )
{ {
m_FootprintList = new FootprintListBox( this, ID_CVPCB_FOOTPRINT_LIST, m_FootprintList = new FOOTPRINTS_LISTBOX( this, ID_CVPCB_FOOTPRINT_LIST,
wxDefaultPosition, size, wxDefaultPosition, size,
0, NULL ); 0, NULL );
m_FootprintList->SetBackgroundColour( wxColour( 225, 255, 225 ) ); m_FootprintList->SetBackgroundColour( wxColour( 225, 255, 225 ) );
...@@ -310,189 +127,3 @@ void WinEDA_CvpcbFrame::BuildFootprintListBox() ...@@ -310,189 +127,3 @@ void WinEDA_CvpcbFrame::BuildFootprintListBox()
msg.Printf( _( "Footprints: %d" ), m_FootprintList->GetCount() ); msg.Printf( _( "Footprints: %d" ), m_FootprintList->GetCount() );
SetStatusText( msg, 2 ); SetStatusText( msg, 2 );
} }
void FootprintListBox::SetFootprintFullList( FOOTPRINT_LIST& list )
{
wxString msg;
int OldSelection = GetSelection();
m_FullFootprintList.Clear();
BOOST_FOREACH( FOOTPRINT& footprint, list )
{
msg.Printf( wxT( "%3d %s" ), m_FullFootprintList.GetCount() + 1,
footprint.m_Module.GetData() );
m_FullFootprintList.Add( msg );
}
SetActiveFootprintList( TRUE );
if( ( GetCount() == 0 )
|| ( OldSelection < 0 ) || ( OldSelection >= GetCount() ) )
SetSelection( 0, TRUE );
Refresh();
}
void FootprintListBox::SetFootprintFilteredList( COMPONENT* Component,
FOOTPRINT_LIST& list )
{
FOOTPRINT_LIST::iterator i;
wxString msg;
unsigned jj;
int OldSelection = GetSelection();
bool HasItem = FALSE;
m_FilteredFootprintList.Clear();
BOOST_FOREACH( FOOTPRINT& footprint, list )
{
/* Search for matching footprints */
for( jj = 0; jj < Component->m_FootprintFilter.GetCount(); jj++ )
{
if( !footprint.m_Module.Matches( Component->m_FootprintFilter[jj] ) )
continue;
msg.Printf( wxT( "%3d %s" ), m_FilteredFootprintList.GetCount() + 1,
footprint.m_Module.GetData() );
m_FilteredFootprintList.Add( msg );
HasItem = TRUE;
}
}
if( HasItem )
SetActiveFootprintList( FALSE );
else
SetActiveFootprintList( TRUE );
if( ( GetCount() == 0 ) || ( OldSelection >= GetCount() ) )
SetSelection( 0, TRUE );
Refresh();
}
/** Set the footprint list. We can have 2 footprint list:
* The full footprint list
* The filtered footprint list (if the current selected component has a
* filter for footprints)
* @param FullList true = full footprint list, false = filtered footprint list
* @param Redraw = true to redraw the window
*/
void FootprintListBox::SetActiveFootprintList( bool FullList, bool Redraw )
{
bool old_selection = m_UseFootprintFullList;
#ifdef __WINDOWS__
/* Workaround for a curious bug in wxWidgets:
* if we switch from a long list of footprints to a short list (a
* filtered footprint list), and if the selected item is near the end
* of the long list, the new list is not displayed from the top of
* the list box
*/
if ( m_ActiveFootprintList )
{
bool new_selection;
if( FullList )
new_selection = TRUE;
else
new_selection = FALSE;
if( new_selection != old_selection )
SetSelection( 0, TRUE );
}
#endif
if( FullList )
{
m_UseFootprintFullList = TRUE;
m_ActiveFootprintList = &m_FullFootprintList;
SetItemCount( m_FullFootprintList.GetCount() );
}
else
{
m_UseFootprintFullList = FALSE;
m_ActiveFootprintList = &m_FilteredFootprintList;
SetItemCount( m_FilteredFootprintList.GetCount() );
}
if( Redraw )
{
if( !m_UseFootprintFullList
|| ( m_UseFootprintFullList != old_selection ) )
{
Refresh();
}
}
if( !m_UseFootprintFullList || ( m_UseFootprintFullList != old_selection ) )
{
GetParent()->SetStatusText( wxEmptyString, 0 );
GetParent()->SetStatusText( wxEmptyString, 1 );
}
wxString msg;
if( FullList )
msg.Printf( _( "Footprints (All): %d" ),
m_ActiveFootprintList->GetCount() );
else
msg.Printf( _( "Footprints (filtered): %d" ),
m_ActiveFootprintList->GetCount() );
GetParent()->SetStatusText( msg, 2 );
}
/**************************************/
/* Event table for the footprint list */
/**************************************/
BEGIN_EVENT_TABLE( FootprintListBox, ListBoxBase )
EVT_SIZE( ListBoxBase::OnSize )
END_EVENT_TABLE()
/********************************************************/
void FootprintListBox::OnLeftClick( wxListEvent& event )
/********************************************************/
{
FOOTPRINT* Module;
wxString FootprintName = GetSelectedFootprint();
Module = GetModuleDescrByName( FootprintName, GetParent()->m_footprints );
if( GetParent()->DrawFrame )
{
GetParent()->CreateScreenCmp(); /* refresh general */
}
if( Module )
{
wxString msg;
msg = Module->m_Doc;
GetParent()->SetStatusText( msg, 0 );
msg = wxT( "KeyW: " );
msg += Module->m_KeyWord;
GetParent()->SetStatusText( msg, 1 );
}
}
/******************************************************/
void FootprintListBox::OnLeftDClick( wxListEvent& event )
/******************************************************/
{
wxString FootprintName = GetSelectedFootprint();
GetParent()->SetNewPkg( FootprintName );
}
FOOTPRINT* GetModuleDescrByName( const wxString& FootprintName,
FOOTPRINT_LIST& list )
{
BOOST_FOREACH( FOOTPRINT& footprint, list )
{
if( footprint.m_Module == FootprintName )
return &footprint;
}
return NULL;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment