kicad/eeschema/viewlibs.cpp

294 lines
7.0 KiB
C++
Raw Normal View History

/**
* @file viewlibs.cpp
*/
#include <fctsys.h>
* 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.
2014-03-20 00:42:08 +00:00
#include <kiway.h>
#include <gr_basic.h>
* 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.
2014-03-20 00:42:08 +00:00
#include <pgm_base.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <eda_doc.h>
#include <class_sch_screen.h>
#include <general.h>
#include <protos.h>
#include <viewlib_frame.h>
#include <eeschema_id.h>
#include <class_library.h>
#include <dialog_helpers.h>
#define NEXT_PART 1
#define NEW_PART 0
#define PREVIOUS_PART -1
void LIB_VIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
{
wxString msg;
LIB_ALIAS* entry;
int ii, id = event.GetId();
switch( id )
{
case ID_LIBVIEW_SELECT_LIB:
SelectCurrentLibrary();
break;
case ID_LIBVIEW_SELECT_PART:
SelectAndViewLibraryPart( NEW_PART );
break;
case ID_LIBVIEW_NEXT:
SelectAndViewLibraryPart( NEXT_PART );
break;
case ID_LIBVIEW_PREVIOUS:
SelectAndViewLibraryPart( PREVIOUS_PART );
break;
case ID_LIBVIEW_VIEWDOC:
entry = Prj().SchLibs()->FindLibraryEntry( m_entryName, m_libraryName );
if( entry && !entry->GetDocFileName().IsEmpty() )
* 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.
2014-03-20 00:42:08 +00:00
{
SEARCH_STACK* lib_search = Prj().SchSearchS();
* 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.
2014-03-20 00:42:08 +00:00
GetAssociatedDocument( this, entry->GetDocFileName(), lib_search );
* 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.
2014-03-20 00:42:08 +00:00
}
break;
case ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT:
m_mainToolBar->ToggleTool( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, true );
m_mainToolBar->ToggleTool( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, false );
m_convert = 1;
m_canvas->Refresh();
break;
case ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT:
m_mainToolBar->ToggleTool( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, false );
m_mainToolBar->ToggleTool( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, true );
m_convert = 2;
m_canvas->Refresh();
break;
case ID_LIBVIEW_SELECT_PART_NUMBER:
2014-01-19 16:36:12 +00:00
ii = m_selpartBox->GetCurrentSelection();
if( ii < 0 )
return;
m_unit = ii + 1;
m_canvas->Refresh();
break;
default:
msg << wxT( "LIB_VIEW_FRAME::Process_Special_Functions error: id = " ) << id;
DisplayError( this, msg );
break;
}
}
void LIB_VIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
{
}
bool LIB_VIEW_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
{
return true;
}
void LIB_VIEW_FRAME::DisplayLibInfos()
{
PART_LIBS* libs = Prj().SchLibs();
if( libs )
{
PART_LIB* lib = libs->FindLibrary( m_libraryName );
wxString msg = _( "Library Browser" );
msg += wxT( " [" );
if( lib )
msg += lib->GetFullFileName();
else
msg += _( "no library selected" );
msg += wxT( "]" );
SetTitle( msg );
}
}
void LIB_VIEW_FRAME::SelectCurrentLibrary()
{
PART_LIB* Lib;
Lib = SelectLibraryFromList( this );
if( Lib )
{
m_entryName.Empty();
m_libraryName = Lib->GetName();
DisplayLibInfos();
2014-01-19 16:36:12 +00:00
if( m_libList )
{
ReCreateListCmp();
m_canvas->Refresh();
DisplayLibInfos();
ReCreateHToolbar();
2014-01-19 16:36:12 +00:00
int id = m_libList->FindString( m_libraryName.GetData() );
if( id >= 0 )
2014-01-19 16:36:12 +00:00
m_libList->SetSelection( id );
}
}
}
void LIB_VIEW_FRAME::SelectAndViewLibraryPart( int option )
{
if( m_libraryName.IsEmpty() )
SelectCurrentLibrary();
if( m_libraryName.IsEmpty() )
return;
if( PART_LIBS* libs = Prj().SchLibs() )
{
if( PART_LIB* lib = libs->FindLibrary( m_libraryName ) )
{
if( m_entryName.IsEmpty() || option == NEW_PART )
{
ViewOneLibraryContent( lib, NEW_PART );
return;
}
if( lib->FindEntry( m_entryName ) )
{
if( option == NEXT_PART )
ViewOneLibraryContent( lib, NEXT_PART );
if( option == PREVIOUS_PART )
ViewOneLibraryContent( lib, PREVIOUS_PART );
}
}
}
}
void LIB_VIEW_FRAME::ViewOneLibraryContent( PART_LIB* Lib, int Flag )
{
int NumOfParts = 0;
LIB_ALIAS* entry;
wxString CmpName;
if( Lib )
NumOfParts = Lib->GetCount();
if( NumOfParts == 0 )
{
DisplayError( this, wxT( "No library or library is empty!" ) );
return;
}
if( Lib == NULL )
return;
if( Flag == NEW_PART )
{
DisplayComponentsNamesInLib( this, Lib, CmpName, m_entryName );
}
if( Flag == NEXT_PART )
{
entry = Lib->GetNextEntry( m_entryName );
if( entry )
CmpName = entry->GetName();
}
if( Flag == PREVIOUS_PART )
{
entry = Lib->GetPreviousEntry( m_entryName );
if( entry )
CmpName = entry->GetName();
}
m_unit = 1;
m_convert = 1;
entry = Lib->FindEntry( CmpName );
m_entryName = CmpName;
DisplayLibInfos();
Zoom_Automatique( false );
m_canvas->Refresh( );
2014-01-19 16:36:12 +00:00
if( m_cmpList )
{
2014-01-19 16:36:12 +00:00
int id = m_cmpList->FindString( m_entryName.GetData() );
if( id >= 0 )
2014-01-19 16:36:12 +00:00
m_cmpList->SetSelection( id );
}
ReCreateHToolbar();
}
void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
{
if( PART_LIBS* libs = Prj().SchLibs() )
{
if( PART_LIB* lib = libs->FindLibrary( m_libraryName ) )
{
if( LIB_ALIAS* entry = lib->FindEntry( m_entryName ) )
{
if( LIB_PART* part = entry->GetPart() )
{
wxString msg;
wxString tmp;
m_canvas->DrawBackGround( DC );
if( !entry->IsRoot() )
{
// Temporarily change the name field text to reflect the alias name.
msg = entry->GetName();
tmp = part->GetName();
part->SetName( msg );
if( m_unit < 1 )
m_unit = 1;
if( m_convert < 1 )
m_convert = 1;
}
else
{
msg = _( "None" );
}
part->Draw( m_canvas, DC, wxPoint( 0, 0 ), m_unit, m_convert, GR_DEFAULT_DRAWMODE );
// Redraw the cursor
m_canvas->DrawCrossHair( DC );
if( !tmp.IsEmpty() )
part->SetName( tmp );
ClearMsgPanel();
AppendMsgPanel( _( "Part" ), part->GetName(), BLUE, 6 );
AppendMsgPanel( _( "Alias" ), msg, RED, 6 );
AppendMsgPanel( _( "Description" ), entry->GetDescription(), CYAN, 6 );
AppendMsgPanel( _( "Key words" ), entry->GetKeyWords(), DARKDARKGRAY );
}
}
}
}
}