Commit f1e5be9a authored by jean-pierre charras's avatar jean-pierre charras

Fix @JP messages (no bugs, just comment lines)

Eeschema: Viewlib is now accessible from Libedit (to browse libs or load a component to edit)
Libedit: uses now the same dialog as the schematic editor to load a component
Some code cleaning.
parent 9ef6ae5b
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
/*********************************/ /*********************************/
#include <fctsys.h> #include <fctsys.h>
//#include "gr_basic.h"
#include <common.h> #include <common.h>
#include <macros.h> #include <macros.h>
#include <wxstruct.h> #include <wxstruct.h>
...@@ -46,6 +45,7 @@ void DIALOG_GET_COMPONENT::initDialog( wxArrayString& aHistoryList ) ...@@ -46,6 +45,7 @@ void DIALOG_GET_COMPONENT::initDialog( wxArrayString& aHistoryList )
{ {
SetFocus(); SetFocus();
m_GetExtraFunction = false; m_GetExtraFunction = false;
m_selectionIsKeyword = false;
m_historyList->Append( aHistoryList ); m_historyList->Append( aHistoryList );
if( !m_auxToolSelector ) if( !m_auxToolSelector )
{ {
...@@ -63,6 +63,7 @@ void DIALOG_GET_COMPONENT::OnCancel( wxCommandEvent& event ) ...@@ -63,6 +63,7 @@ void DIALOG_GET_COMPONENT::OnCancel( wxCommandEvent& event )
void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event ) void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event )
{ {
m_selectionIsKeyword = false;
switch( event.GetId() ) switch( event.GetId() )
{ {
case ID_SEL_BY_LISTBOX: case ID_SEL_BY_LISTBOX:
...@@ -74,7 +75,8 @@ void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event ) ...@@ -74,7 +75,8 @@ void DIALOG_GET_COMPONENT::Accept( wxCommandEvent& event )
break; break;
case ID_ACCEPT_KEYWORD: case ID_ACCEPT_KEYWORD:
m_Text = wxT( "= " ) + m_textCmpNameCtrl->GetValue(); m_selectionIsKeyword = true;
m_Text = m_textCmpNameCtrl->GetValue();
break; break;
case ID_LIST_ALL: case ID_LIST_ALL:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <protos.h> #include <protos.h>
#include <class_library.h> #include <class_library.h>
#include <sch_component.h> #include <sch_component.h>
#include <libeditframe.h>
#include <viewlib_frame.h> #include <viewlib_frame.h>
#include <eeschema_id.h> #include <eeschema_id.h>
...@@ -48,7 +49,7 @@ ...@@ -48,7 +49,7 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void ) wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void )
{ {
wxSemaphore semaphore( 0, 1 ); wxSemaphore semaphore( 0, 1 );
wxString cmpname; wxString cmpname;
...@@ -60,6 +61,12 @@ wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void ) ...@@ -60,6 +61,12 @@ wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void )
m_ViewlibFrame = NULL; m_ViewlibFrame = NULL;
} }
if( m_LibeditFrame && m_LibeditFrame->m_ViewlibFrame )
{
m_LibeditFrame->m_ViewlibFrame->Destroy();
m_LibeditFrame->m_ViewlibFrame = NULL;
}
m_ViewlibFrame = new LIB_VIEW_FRAME( this, NULL, &semaphore ); m_ViewlibFrame = new LIB_VIEW_FRAME( this, NULL, &semaphore );
// Show the library viewer frame until it is closed // Show the library viewer frame until it is closed
while( semaphore.TryWait() == wxSEMA_BUSY ) // Wait for viewer closing event while( semaphore.TryWait() == wxSEMA_BUSY ) // Wait for viewer closing event
...@@ -74,36 +81,38 @@ wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void ) ...@@ -74,36 +81,38 @@ wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void )
return cmpname; return cmpname;
} }
/* /*
* load from a library and place a component * Function SelectComponentFromLib
* if libname != "", search in lib "libname" * Calls the library viewer to select component to import into schematic.
* else search in all loaded libs * if the library viewer is currently running, it is closed and reopened
* in modal mode.
* param aLibname = the lib name or an empty string.
* if aLibname is empty, the full list of libraries is used
* param aList = list of previously loaded components
* param aUseLibBrowser = bool to call the library viewer to select the component
* param aUnit = a point to int to return the selected unit (if any)
* param aConvert = a point to int to return the selected De Morgan shape (if any)
*
* return the component name
*/ */
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC, wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname,
const wxString& libname, wxArrayString& aHistoryList,
wxArrayString& HistoryList, bool aUseLibBrowser,
bool UseLibBrowser ) int* aUnit,
int* aConvert )
{ {
int CmpCount = 0; int CmpCount = 0;
int unit = 1; LIB_COMPONENT* libEntry = NULL;
int convert = 1; CMP_LIBRARY* currLibrary = NULL;
LIB_COMPONENT* Entry = NULL; wxString cmpName, keys, msg;
SCH_COMPONENT* component = NULL; bool allowWildSeach = true;
CMP_LIBRARY* Library = NULL;
wxString Name, keys, msg;
bool AllowWildSeach = true;
static wxString lastCommponentName;
m_itemToRepeat = NULL; if( !aLibname.IsEmpty() )
m_canvas->SetIgnoreMouseEvents( true );
if( !libname.IsEmpty() )
{ {
Library = CMP_LIBRARY::FindLibrary( libname ); currLibrary = CMP_LIBRARY::FindLibrary( aLibname );
if( Library != NULL ) if( currLibrary != NULL )
CmpCount = Library->GetCount(); CmpCount = currLibrary->GetCount();
} }
else else
{ {
...@@ -116,109 +125,132 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC, ...@@ -116,109 +125,132 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
/* Ask for a component name or key words */ /* Ask for a component name or key words */
msg.Printf( _( "component selection (%d items loaded):" ), CmpCount ); msg.Printf( _( "component selection (%d items loaded):" ), CmpCount );
DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), HistoryList, DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), aHistoryList,
msg, UseLibBrowser ); msg, aUseLibBrowser );
dlg.SetComponentName( lastCommponentName ); if( aHistoryList.GetCount() )
dlg.SetComponentName( aHistoryList[0] );
if ( dlg.ShowModal() == wxID_CANCEL ) if ( dlg.ShowModal() == wxID_CANCEL )
{ return wxEmptyString;
m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair();
return NULL;
}
if( dlg.m_GetExtraFunction ) if( dlg.m_GetExtraFunction )
{ {
Name = SelectFromLibBrowser(); cmpName = SelectComponentFromLibBrowser();
unit = m_ViewlibFrame->GetUnit(); if( aUnit )
convert = m_ViewlibFrame->GetConvert(); *aUnit = m_ViewlibFrame->GetUnit();
if( aConvert )
*aConvert = m_ViewlibFrame->GetConvert();
if( !cmpName.IsEmpty() )
AddHistoryComponentName( aHistoryList, cmpName );
return cmpName;
} }
else else
{ cmpName = dlg.GetComponentName();
Name = dlg.GetComponentName();
}
if( Name.IsEmpty() ) if( cmpName.IsEmpty() )
{ return wxEmptyString;
m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair();
return NULL;
}
#ifndef KICAD_KEEPCASE #ifndef KICAD_KEEPCASE
Name.MakeUpper(); cmpName.MakeUpper();
#endif #endif
if( Name.GetChar( 0 ) == '=' ) if( dlg.IsKeyword() )
{ {
AllowWildSeach = false; allowWildSeach = false;
keys = Name.AfterFirst( '=' ); keys = cmpName;
Name = DataBaseGetName( this, keys, Name ); cmpName = DataBaseGetName( this, keys, cmpName );
if( cmpName.IsEmpty() )
return wxEmptyString;
}
else if( cmpName == wxT( "*" ) )
{
allowWildSeach = false;
if( Name.IsEmpty() ) if( GetNameOfPartToLoad( this, currLibrary, cmpName ) == 0 )
{ return wxEmptyString;
m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair();
return NULL;
}
} }
else if( Name == wxT( "*" ) ) else if( cmpName.Contains( wxT( "?" ) ) || cmpName.Contains( wxT( "*" ) ) )
{ {
AllowWildSeach = false; allowWildSeach = false;
cmpName = DataBaseGetName( this, keys, cmpName );
if( GetNameOfPartToLoad( this, Library, Name ) == 0 ) if( cmpName.IsEmpty() )
{ return wxEmptyString;
m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair();
return NULL;
}
} }
else if( Name.Contains( wxT( "?" ) ) || Name.Contains( wxT( "*" ) ) )
libEntry = CMP_LIBRARY::FindLibraryComponent( cmpName, aLibname );
if( ( libEntry == NULL ) && allowWildSeach ) /* Search with wildcard */
{ {
AllowWildSeach = false; allowWildSeach = false;
Name = DataBaseGetName( this, keys, Name ); wxString wildname = wxChar( '*' ) + cmpName + wxChar( '*' );
cmpName = wildname;
cmpName = DataBaseGetName( this, keys, cmpName );
if( Name.IsEmpty() ) if( !cmpName.IsEmpty() )
{ libEntry = CMP_LIBRARY::FindLibraryComponent( cmpName, aLibname );
m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair();
return NULL;
}
}
Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname ); if( libEntry == NULL )
return wxEmptyString;
}
if( ( Entry == NULL ) && AllowWildSeach ) /* Search with wildcard */ if( libEntry == NULL )
{ {
AllowWildSeach = false; msg = _( "Failed to find part " ) + cmpName + _( " in library" );
wxString wildname = wxChar( '*' ) + Name + wxChar( '*' ); DisplayError( this, msg );
Name = wildname; return wxEmptyString;
Name = DataBaseGetName( this, keys, Name ); }
if( !Name.IsEmpty() ) AddHistoryComponentName( aHistoryList, cmpName );
Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname ); return cmpName;
}
if( Entry == NULL )
{ /*
m_canvas->SetIgnoreMouseEvents( false ); * load from a library and place a component
m_canvas->MoveCursorToCrossHair(); * if libname != "", search in lib "libname"
return NULL; * else search in all loaded libs
} */
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC,
const wxString& aLibname,
wxArrayString& aHistoryList,
bool aUseLibBrowser )
{
int unit = 1;
int convert = 1;
m_itemToRepeat = NULL;
m_canvas->SetIgnoreMouseEvents( true );
wxString Name = SelectComponentFromLibrary( aLibname, aHistoryList, aUseLibBrowser,
&unit, &convert );
if( Name.IsEmpty() )
{
m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair();
return NULL;
} }
#ifndef KICAD_KEEPCASE
Name.MakeUpper();
#endif
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( Name, aLibname );
m_canvas->SetIgnoreMouseEvents( false ); m_canvas->SetIgnoreMouseEvents( false );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
if( Entry == NULL ) if( Entry == NULL )
{ {
msg = _( "Failed to find part " ) + Name + _( " in library" ); wxString msg;
DisplayError( this, msg ); msg.Printf( _( "Failed to find part <%s> in library" ), GetChars( Name ) );
wxMessageBox( msg );
return NULL; return NULL;
} }
lastCommponentName = Name; SCH_COMPONENT* component;
AddHistoryComponentName( HistoryList, Name );
component = new SCH_COMPONENT( *Entry, m_CurrentSheet, unit, convert, component = new SCH_COMPONENT( *Entry, m_CurrentSheet, unit, convert,
GetScreen()->GetCrossHairPosition(), true ); GetScreen()->GetCrossHairPosition(), true );
...@@ -230,10 +262,10 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC, ...@@ -230,10 +262,10 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
// Set the component value that can differ from component name in lib, for aliases // Set the component value that can differ from component name in lib, for aliases
component->GetField( VALUE )->m_Text = Name; component->GetField( VALUE )->m_Text = Name;
component->DisplayInfo( this ); component->DisplayInfo( this );
component->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
component->SetFlags( IS_NEW ); component->SetFlags( IS_NEW );
MoveItem( (SCH_ITEM*) component, DC ); MoveItem( (SCH_ITEM*) component, aDC );
return component; return component;
} }
......
...@@ -113,10 +113,9 @@ bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( LIB_ALIAS* aLibEntry ) ...@@ -113,10 +113,9 @@ bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( LIB_ALIAS* aLibEntry )
void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
{ {
int i;
wxString msg; wxString msg;
wxString CmpName; wxString CmpName;
LIB_ALIAS* LibEntry = NULL; LIB_ALIAS* libEntry = NULL;
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
...@@ -133,9 +132,10 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) ...@@ -133,9 +132,10 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
return; return;
} }
i = GetNameOfPartToLoad( this, m_library, CmpName ); wxArrayString historyList;
CmpName = SelectComponentFromLibrary( m_library->GetName(), historyList, true, NULL, NULL );
if( i == 0 ) if( CmpName.IsEmpty() )
return; return;
GetScreen()->ClrModify(); GetScreen()->ClrModify();
...@@ -149,19 +149,39 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event ) ...@@ -149,19 +149,39 @@ void LIB_EDIT_FRAME::LoadOneLibraryPart( wxCommandEvent& event )
} }
/* Load the new library component */ /* Load the new library component */
LibEntry = m_library->FindEntry( CmpName ); libEntry = m_library->FindEntry( CmpName );
CMP_LIBRARY* searchLib = m_library;
if( libEntry == NULL )
{ // Not found in the active library: search inside the full list
// (can happen when using Viewlib to load a component)
libEntry = CMP_LIBRARY::FindLibraryEntry( CmpName );
if( libEntry )
{
searchLib = libEntry->GetLibrary();
// The entry to load is not in the active lib
// Ask for a new active lib
wxString msg;
msg << _("The selected component is not in the active library");
msg << wxT("\n\n");
msg << _("Do you want to change the active library?");
if( IsOK( this, msg ) )
SelectActiveLibrary( searchLib );
}
}
if( LibEntry == NULL ) if( libEntry == NULL )
{ {
msg.Printf( _( "Component name \"%s\" not found in library \"%s\"." ), msg.Printf( _( "Component name \"%s\" not found in library \"%s\"." ),
GetChars( CmpName ), GetChars( CmpName ),
GetChars( m_library->GetName() ) ); GetChars( searchLib->GetName() ) );
DisplayError( this, msg ); DisplayError( this, msg );
return; return;
} }
if( ! LoadComponentFromCurrentLib( LibEntry ) ) EXCHG( searchLib, m_library );
return; LoadComponentFromCurrentLib( libEntry );
EXCHG( searchLib, m_library );
DisplayLibInfos();
} }
......
...@@ -100,6 +100,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME ) ...@@ -100,6 +100,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_LIB, LIB_EDIT_FRAME::SaveActiveLibrary ) EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_LIB, LIB_EDIT_FRAME::SaveActiveLibrary )
EVT_TOOL( ID_LIBEDIT_SELECT_CURRENT_LIB, LIB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( ID_LIBEDIT_SELECT_CURRENT_LIB, LIB_EDIT_FRAME::Process_Special_Functions )
EVT_TOOL( ID_LIBEDIT_DELETE_PART, LIB_EDIT_FRAME::DeleteOnePart ) EVT_TOOL( ID_LIBEDIT_DELETE_PART, LIB_EDIT_FRAME::DeleteOnePart )
EVT_TOOL( ID_TO_LIBVIEW, LIB_EDIT_FRAME::OnOpenLibraryViewer )
EVT_TOOL( ID_LIBEDIT_NEW_PART, LIB_EDIT_FRAME::CreateNewLibraryPart ) EVT_TOOL( ID_LIBEDIT_NEW_PART, LIB_EDIT_FRAME::CreateNewLibraryPart )
EVT_TOOL( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnCreateNewPartFromExisting ) EVT_TOOL( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnCreateNewPartFromExisting )
......
...@@ -23,6 +23,37 @@ ...@@ -23,6 +23,37 @@
*/ */
#include <sch_base_frame.h> #include <sch_base_frame.h>
#include <viewlib_frame.h>
#include <libeditframe.h>
SCH_BASE_FRAME::SCH_BASE_FRAME( wxWindow* aParent,
id_drawframe aWindowType,
const wxString& aTitle,
const wxPoint& aPosition, const wxSize& aSize,
long aStyle ) :
EDA_DRAW_FRAME( aParent, aWindowType, aTitle, aPosition, aSize, aStyle )
{
m_ViewlibFrame = NULL;
m_LibeditFrame = NULL;
}
void SCH_BASE_FRAME::OnOpenLibraryViewer( wxCommandEvent& event )
{
if( m_ViewlibFrame )
{
m_ViewlibFrame->Show( true );
return;
}
if( m_LibeditFrame && m_LibeditFrame->m_ViewlibFrame )
{
m_LibeditFrame->m_ViewlibFrame->Show( true );
return;
}
m_ViewlibFrame = new LIB_VIEW_FRAME( this );
}
SCH_SCREEN* SCH_BASE_FRAME::GetScreen() const SCH_SCREEN* SCH_BASE_FRAME::GetScreen() const
......
...@@ -27,10 +27,6 @@ ...@@ -27,10 +27,6 @@
* @file schframe.cpp * @file schframe.cpp
*/ */
#ifdef __GNUG__
#pragma implementation
#endif
#include <fctsys.h> #include <fctsys.h>
#include <appl_wxstruct.h> #include <appl_wxstruct.h>
#include <gr_basic.h> #include <gr_basic.h>
...@@ -193,8 +189,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father, ...@@ -193,8 +189,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father,
m_showBorderAndTitleBlock = true; // true to show sheet references m_showBorderAndTitleBlock = true; // true to show sheet references
m_CurrentSheet = new SCH_SHEET_PATH(); m_CurrentSheet = new SCH_SHEET_PATH();
m_TextFieldSize = DEFAULT_SIZE_TEXT; m_TextFieldSize = DEFAULT_SIZE_TEXT;
m_LibeditFrame = NULL; // Component editor frame.
m_ViewlibFrame = NULL; // Frame for browsing component libraries
m_DefaultSchematicFileName = NAMELESS_PROJECT; m_DefaultSchematicFileName = NAMELESS_PROJECT;
m_DefaultSchematicFileName += wxT( ".sch" ); m_DefaultSchematicFileName += wxT( ".sch" );
m_showAllPins = false; m_showAllPins = false;
...@@ -776,20 +770,6 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event ) ...@@ -776,20 +770,6 @@ void SCH_EDIT_FRAME::OnOpenCvpcb( wxCommandEvent& event )
} }
} }
void SCH_EDIT_FRAME::OnOpenLibraryViewer( wxCommandEvent& event )
{
if( m_ViewlibFrame )
{
m_ViewlibFrame->Show( true );
}
else
{
m_ViewlibFrame = new LIB_VIEW_FRAME( this );
}
}
void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event ) void SCH_EDIT_FRAME::OnOpenLibraryEditor( wxCommandEvent& event )
{ {
SCH_COMPONENT* component = NULL; SCH_COMPONENT* component = NULL;
......
...@@ -118,6 +118,10 @@ void LIB_EDIT_FRAME::ReCreateHToolbar() ...@@ -118,6 +118,10 @@ void LIB_EDIT_FRAME::ReCreateHToolbar()
m_mainToolBar->AddTool( ID_LIBEDIT_DELETE_PART, wxEmptyString, KiBitmap( delete_xpm ), m_mainToolBar->AddTool( ID_LIBEDIT_DELETE_PART, wxEmptyString, KiBitmap( delete_xpm ),
_( "Delete component in current library" ) ); _( "Delete component in current library" ) );
m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_TO_LIBVIEW, wxEmptyString, KiBitmap( library_browse_xpm ),
HELP_RUN_LIB_VIEWER );
m_mainToolBar->AddSeparator(); m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_LIBEDIT_NEW_PART, wxEmptyString, KiBitmap( new_component_xpm ), m_mainToolBar->AddTool( ID_LIBEDIT_NEW_PART, wxEmptyString, KiBitmap( new_component_xpm ),
_( "Create a new component" ) ); _( "Create a new component" ) );
......
...@@ -255,7 +255,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( wxWindow* father, CMP_LIBRARY* Library, wxSemaph ...@@ -255,7 +255,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( wxWindow* father, CMP_LIBRARY* Library, wxSemaph
LIB_VIEW_FRAME::~LIB_VIEW_FRAME() LIB_VIEW_FRAME::~LIB_VIEW_FRAME()
{ {
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) wxGetApp().GetTopWindow(); SCH_BASE_FRAME* frame = (SCH_BASE_FRAME*) GetParent();
frame->SetLibraryViewerWindow( NULL ); frame->SetLibraryViewerWindow( NULL );
} }
......
...@@ -19,6 +19,7 @@ class DIALOG_GET_COMPONENT : public DIALOG_GET_COMPONENT_BASE ...@@ -19,6 +19,7 @@ class DIALOG_GET_COMPONENT : public DIALOG_GET_COMPONENT_BASE
private: private:
bool m_auxToolSelector; bool m_auxToolSelector;
wxString m_Text; wxString m_Text;
bool m_selectionIsKeyword;
public: public:
bool m_GetExtraFunction; bool m_GetExtraFunction;
...@@ -30,7 +31,21 @@ public: ...@@ -30,7 +31,21 @@ public:
bool show_extra_tool ); bool show_extra_tool );
~DIALOG_GET_COMPONENT() {}; ~DIALOG_GET_COMPONENT() {};
/**
* Function GetComponentName
* @return the selection (name or keyword)
*/
wxString GetComponentName( void ); wxString GetComponentName( void );
/**
* Function IsKeyword
* @return true if the returned string is a keyword
*/
bool IsKeyword( void )
{
return m_selectionIsKeyword;
}
void SetComponentName( const wxString& name ); void SetComponentName( const wxString& name );
private: private:
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
class PAGE_INFO; class PAGE_INFO;
class TITLE_BLOCK; class TITLE_BLOCK;
class LIB_VIEW_FRAME;
class LIB_EDIT_FRAME;
/** /**
...@@ -43,18 +45,27 @@ class TITLE_BLOCK; ...@@ -43,18 +45,27 @@ class TITLE_BLOCK;
*/ */
class SCH_BASE_FRAME : public EDA_DRAW_FRAME class SCH_BASE_FRAME : public EDA_DRAW_FRAME
{ {
protected:
LIB_VIEW_FRAME* m_ViewlibFrame; // A library viewer, common to SCH_EDIT_FRAME
// and LIB_EDIT_FRAME.
// has no meaning to LIB_VIEW_FRAME
LIB_EDIT_FRAME* m_LibeditFrame; // the library editor.
// Is used mainly in SCH_EDIT_FRAME
// but is defined here because some functions
// need to know if a library editor or a libray
// viewer is currently opened
public: public:
SCH_BASE_FRAME( wxWindow* aParent, SCH_BASE_FRAME( wxWindow* aParent,
id_drawframe aWindowType, id_drawframe aWindowType,
const wxString& aTitle, const wxString& aTitle,
const wxPoint& aPosition, const wxSize& aSize, const wxPoint& aPosition, const wxSize& aSize,
long aStyle = KICAD_DEFAULT_DRAWFRAME_STYLE ) : long aStyle = KICAD_DEFAULT_DRAWFRAME_STYLE );
EDA_DRAW_FRAME( aParent, aWindowType, aTitle, aPosition, aSize, aStyle )
{
}
SCH_SCREEN* GetScreen() const; // overload EDA_DRAW_FRAME SCH_SCREEN* GetScreen() const; // overload EDA_DRAW_FRAME
void SetLibraryViewerWindow( LIB_VIEW_FRAME* aFrame ) { m_ViewlibFrame = aFrame; }
void SetPageSettings( const PAGE_INFO& aPageSettings ); // overload EDA_DRAW_FRAME void SetPageSettings( const PAGE_INFO& aPageSettings ); // overload EDA_DRAW_FRAME
const PAGE_INFO& GetPageSettings () const; // overload EDA_DRAW_FRAME const PAGE_INFO& GetPageSettings () const; // overload EDA_DRAW_FRAME
const wxSize GetPageSizeIU() const; // overload EDA_DRAW_FRAME const wxSize GetPageSizeIU() const; // overload EDA_DRAW_FRAME
...@@ -64,6 +75,45 @@ public: ...@@ -64,6 +75,45 @@ public:
const TITLE_BLOCK& GetTitleBlock() const; // overload EDA_DRAW_FRAME const TITLE_BLOCK& GetTitleBlock() const; // overload EDA_DRAW_FRAME
void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ); // overload EDA_DRAW_FRAME void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ); // overload EDA_DRAW_FRAME
protected:
/**
* Function SelectComponentFromLibBrowser
* Calls the library viewer to select component to import into schematic.
* if the library viewer is currently running, it is closed and reopened
* in modal mode.
* @return the component name
*/
wxString SelectComponentFromLibBrowser( void );
/**
* Function SelectComponentFromLib
* Calls the library viewer to select component to import into schematic.
* if the library viewer is currently running, it is closed and reopened
* in modal mode.
* @param aLibname = the lib name or an empty string.
* if aLibname is empty, the full list of libraries is used
* @param aHistoryList = list of previously loaded components
* @param aUseLibBrowser = bool to call the library viewer to select the component
* @param aUnit = a point to int to return the selected unit (if any)
* @param aConvert = a point to int to return the selected De Morgan shape (if any)
*
* @return the component name
*/
wxString SelectComponentFromLibrary( const wxString& aLibname,
wxArrayString& aHistoryList,
bool aUseLibBrowser,
int* aUnit,
int* aConvert );
/**
* Function OnOpenLibraryViewer
* Open the library viewer only to browse library contents.
* If the viewed is already opened from this, raise the viewer
* If the viewed is already opened from an other window, close it and reopen
*/
void OnOpenLibraryViewer( wxCommandEvent& event );
}; };
#endif // SCH_BASE_FRAME_H_ #endif // SCH_BASE_FRAME_H_
...@@ -114,8 +114,6 @@ class SCH_EDIT_FRAME : public SCH_BASE_FRAME ...@@ -114,8 +114,6 @@ class SCH_EDIT_FRAME : public SCH_BASE_FRAME
{ {
private: private:
SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on. SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on.
LIB_VIEW_FRAME* m_ViewlibFrame;
LIB_EDIT_FRAME* m_LibeditFrame;
wxString m_DefaultSchematicFileName; wxString m_DefaultSchematicFileName;
int m_TextFieldSize; int m_TextFieldSize;
PARAM_CFG_ARRAY m_projectFileParams; PARAM_CFG_ARRAY m_projectFileParams;
...@@ -204,8 +202,6 @@ public: ...@@ -204,8 +202,6 @@ public:
void SetLibraryEditorWindow( LIB_EDIT_FRAME* aFrame ) { m_LibeditFrame = aFrame; } void SetLibraryEditorWindow( LIB_EDIT_FRAME* aFrame ) { m_LibeditFrame = aFrame; }
void SetLibraryViewerWindow( LIB_VIEW_FRAME* aFrame ) { m_ViewlibFrame = aFrame; }
bool GetShowAllPins() const { return m_showAllPins; } bool GetShowAllPins() const { return m_showAllPins; }
void SetShowAllPins( bool aEnable ) { m_showAllPins = aEnable; } void SetShowAllPins( bool aEnable ) { m_showAllPins = aEnable; }
...@@ -746,7 +742,6 @@ private: ...@@ -746,7 +742,6 @@ private:
void OnLoadProject( wxCommandEvent& event ); void OnLoadProject( wxCommandEvent& event );
void OnOpenPcbnew( wxCommandEvent& event ); void OnOpenPcbnew( wxCommandEvent& event );
void OnOpenCvpcb( wxCommandEvent& event ); void OnOpenCvpcb( wxCommandEvent& event );
void OnOpenLibraryViewer( wxCommandEvent& event );
void OnOpenLibraryEditor( wxCommandEvent& event ); void OnOpenLibraryEditor( wxCommandEvent& event );
void OnSetOptions( wxCommandEvent& event ); void OnSetOptions( wxCommandEvent& event );
void OnCancelCurrentCommand( wxCommandEvent& aEvent ); void OnCancelCurrentCommand( wxCommandEvent& aEvent );
...@@ -874,11 +869,6 @@ private: ...@@ -874,11 +869,6 @@ private:
SCH_SHEET* CreateSheet( wxDC* DC ); SCH_SHEET* CreateSheet( wxDC* DC );
void ReSizeSheet( SCH_SHEET* Sheet, wxDC* DC ); void ReSizeSheet( SCH_SHEET* Sheet, wxDC* DC );
/**
* Use the component viewer to select component to import into schematic.
*/
wxString SelectFromLibBrowser( void );
public: public:
/** /**
* Function EditSheet * Function EditSheet
......
...@@ -56,7 +56,13 @@ ...@@ -56,7 +56,13 @@
#define BLOCK_COLOR BROWN #define BLOCK_COLOR BROWN
// Functions defined here, but used also in other files
// These 2 functions are used in modedit to rotate or mirror the whole footprint
// so they are called with force_all = true
void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all = false );
void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all = false );
// Local functions:
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase ); bool aErase );
static int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect ); static int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect );
...@@ -64,8 +70,6 @@ static int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect ); ...@@ -64,8 +70,6 @@ static int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect );
static void ClearMarkItems( MODULE* module ); static void ClearMarkItems( MODULE* module );
static void CopyMarkedItems( MODULE* module, wxPoint offset ); static void CopyMarkedItems( MODULE* module, wxPoint offset );
static void MoveMarkedItems( MODULE* module, wxPoint offset ); static void MoveMarkedItems( MODULE* module, wxPoint offset );
static void MirrorMarkedItems( MODULE* module, wxPoint offset );
static void RotateMarkedItems( MODULE* module, wxPoint offset );
static void DeleteMarkedItems( MODULE* module ); static void DeleteMarkedItems( MODULE* module );
...@@ -521,8 +525,10 @@ void DeleteMarkedItems( MODULE* module ) ...@@ -521,8 +525,10 @@ void DeleteMarkedItems( MODULE* module )
/** Mirror marked items, refer to a Vertical axis at position offset /** Mirror marked items, refer to a Vertical axis at position offset
* Note: because this function is used in global transform,
* if force_all is true, all items will be mirrored
*/ */
void MirrorMarkedItems( MODULE* module, wxPoint offset ) void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all )
{ {
#define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x; #define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x;
wxPoint tmp; wxPoint tmp;
...@@ -533,9 +539,8 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset ) ...@@ -533,9 +539,8 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset )
for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() ) for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() )
{ {
// @JP why allow some pads to stay behind? Do not understand // Skip pads not selected, i.e. not inside the block to mirror:
// why this test is here. if( !pad->IsSelected() && !force_all )
if( !pad->IsSelected() )
continue; continue;
tmp = pad->GetPosition(); tmp = pad->GetPosition();
...@@ -557,7 +562,8 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset ) ...@@ -557,7 +562,8 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset )
for( EDA_ITEM* item = module->m_Drawings; item; item = item->Next() ) for( EDA_ITEM* item = module->m_Drawings; item; item = item->Next() )
{ {
if( !item->IsSelected() ) // @JP why allow some graphics to stay behind? // Skip items not selected, i.e. not inside the block to mirror:
if( !item->IsSelected() && !force_all )
continue; continue;
switch( item->Type() ) switch( item->Type() )
...@@ -600,9 +606,11 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset ) ...@@ -600,9 +606,11 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset )
} }
/** Rotate marked items, refer to a Vertical axis at position offset /** Rotate marked items, refer to a rotation point at position offset
* Note: because this function is used in global transform,
* if force_all is true, all items will be rotated
*/ */
void RotateMarkedItems( MODULE* module, wxPoint offset ) void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all )
{ {
#define ROTATE( z ) RotatePoint( (&z), offset, 900 ) #define ROTATE( z ) RotatePoint( (&z), offset, 900 )
...@@ -611,7 +619,7 @@ void RotateMarkedItems( MODULE* module, wxPoint offset ) ...@@ -611,7 +619,7 @@ void RotateMarkedItems( MODULE* module, wxPoint offset )
for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() ) for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() )
{ {
if( !pad->IsSelected() ) if( !pad->IsSelected() && !force_all )
continue; continue;
wxPoint pos = pad->GetPosition(); wxPoint pos = pad->GetPosition();
...@@ -624,7 +632,7 @@ void RotateMarkedItems( MODULE* module, wxPoint offset ) ...@@ -624,7 +632,7 @@ void RotateMarkedItems( MODULE* module, wxPoint offset )
for( EDA_ITEM* item = module->m_Drawings; item; item = item->Next() ) for( EDA_ITEM* item = module->m_Drawings; item; item = item->Next() )
{ {
if( !item->IsSelected() ) if( !item->IsSelected() && !force_all)
continue; continue;
switch( item->Type() ) switch( item->Type() )
......
...@@ -178,10 +178,10 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary, ...@@ -178,10 +178,10 @@ MODULE* PCB_BASE_FRAME::Load_Module_From_Library( const wxString& aLibrary,
moduleName.MakeUpper(); moduleName.MakeUpper();
if( moduleName[0] == '=' ) // Selection by keywords if( dlg.IsKeyword() ) // Selection by keywords
{ {
AllowWildSeach = false; AllowWildSeach = false;
keys = moduleName.AfterFirst( '=' ); keys = moduleName;
moduleName = Select_1_Module_From_List( this, aLibrary, wxEmptyString, keys ); moduleName = Select_1_Module_From_List( this, aLibrary, wxEmptyString, keys );
if( moduleName.IsEmpty() ) /* Cancel command */ if( moduleName.IsEmpty() ) /* Cancel command */
......
...@@ -28,6 +28,12 @@ ...@@ -28,6 +28,12 @@
#include <dialog_edit_module_for_Modedit.h> #include <dialog_edit_module_for_Modedit.h>
// Functions defined in block_module_editor, but used here
// These 2 functions are used in modedit to rotate or mirror the whole footprint
// so they are called with force_all = true
void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all = false );
void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all = false );
BOARD_ITEM* FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay( int aHotKeyCode ) BOARD_ITEM* FOOTPRINT_EDIT_FRAME::ModeditLocateAndDisplay( int aHotKeyCode )
{ {
...@@ -724,141 +730,57 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -724,141 +730,57 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
void FOOTPRINT_EDIT_FRAME::Transform( MODULE* module, int transform ) void FOOTPRINT_EDIT_FRAME::Transform( MODULE* module, int transform )
{ {
D_PAD* pad = module->m_Pads; TEXTE_MODULE* textmod;
EDA_ITEM* item = module->m_Drawings; wxPoint pos;
TEXTE_MODULE* textmod; double angle = 900; // Necessary +- 900 (+- 90 degrees).
EDGE_MODULE* edgemod; // Be prudent: because RotateMarkedItems is used to rotate some items
wxPoint pt; // used the same value as RotateMarkedItems
wxSize size;
double angle = 900; // Necessary +- 900 (+- 90 degrees) )
switch( transform ) switch( transform )
{ {
case ID_MODEDIT_MODULE_ROTATE: case ID_MODEDIT_MODULE_ROTATE:
module->SetOrientation( angle ); #define ROTATE( z ) RotatePoint( (&z), angle )
RotateMarkedItems( module, wxPoint(0,0), true );
for( ; pad; pad = pad->Next() )
{
pad->SetPos0( pad->GetPosition() );
pad->SetOrientation( pad->GetOrientation() - angle );
pt = pad->GetOffset();
RotatePoint( &pt, angle );
pad->SetOffset( pt );
size = pad->GetSize();
EXCHG( size.x, size.y );
pad->SetSize( size );
size = pad->GetDelta(); pos = module->m_Reference->GetPosition();
RotatePoint( &size.x, &size.y, -angle ); ROTATE( pos );
pad->SetDelta( size ); module->m_Reference->SetPosition( pos );
} module->m_Reference->SetPos0( module->m_Reference->GetPosition() );
module->m_Reference->SetPos0( module->m_Reference->m_Pos );
module->m_Reference->m_Orient += angle; module->m_Reference->m_Orient += angle;
if( module->m_Reference->m_Orient >= 1800 ) if( module->m_Reference->m_Orient >= 1800 )
module->m_Reference->m_Orient -= 1800; module->m_Reference->m_Orient -= 1800;
pos = module->m_Value->GetPosition();
ROTATE( pos );
module->m_Value->SetPosition( pos );
module->m_Value->SetPos0( module->m_Value->m_Pos ); module->m_Value->SetPos0( module->m_Value->m_Pos );
module->m_Value->m_Orient += angle; module->m_Value->m_Orient += angle;
if( module->m_Value->m_Orient >= 1800 ) if( module->m_Value->m_Orient >= 1800 )
module->m_Value->m_Orient -= 1800; module->m_Value->m_Orient -= 1800;
for( ; item != NULL; item = item->Next() )
{
if( item->Type() == PCB_MODULE_EDGE_T )
{
edgemod = (EDGE_MODULE*) item;
edgemod->SetStart0( edgemod->GetStart() );
edgemod->SetEnd0( edgemod->GetEnd() );
}
else if( item->Type() == PCB_MODULE_TEXT_T )
{
textmod = (TEXTE_MODULE*) item;
textmod->SetPos0( textmod->m_Pos );
}
}
module->m_Orient = 0;
break; break;
case ID_MODEDIT_MODULE_MIRROR: case ID_MODEDIT_MODULE_MIRROR:
for( ; pad; pad = pad->Next() ) // Mirror reference.
{
pad->SetY( -pad->GetPosition().y );
pt = pad->GetPos0();
NEGATE( pt.y );
pad->SetPos0( pt );
pt = pad->GetOffset();
NEGATE( pt.y );
pad->SetOffset( pt );
size = pad->GetDelta();
NEGATE( size.y );
pad->SetDelta( size );
if( pad->GetOrientation() )
pad->SetOrientation( 3600 - pad->GetOrientation() );
}
// Reverse mirror of reference.
textmod = module->m_Reference; textmod = module->m_Reference;
NEGATE( textmod->m_Pos.y ); NEGATE( textmod->m_Pos.x );
NEGATE( textmod->m_Pos0.y ); NEGATE( textmod->m_Pos0.x );
if( textmod->m_Orient ) if( textmod->m_Orient )
textmod->m_Orient = 3600 - textmod->m_Orient; textmod->m_Orient = 3600 - textmod->m_Orient;
// Reverse mirror of value. // Mirror value.
textmod = module->m_Value; textmod = module->m_Value;
NEGATE( textmod->m_Pos.y ); NEGATE( textmod->m_Pos.x );
NEGATE( textmod->m_Pos0.y ); NEGATE( textmod->m_Pos0.x );
if( textmod->m_Orient ) if( textmod->m_Orient )
textmod->m_Orient = 3600 - textmod->m_Orient; textmod->m_Orient = 3600 - textmod->m_Orient;
// Reverse mirror of footprints. // Mirror pads and graphic items of the footprint:
item = module->m_Drawings; MirrorMarkedItems( module, wxPoint(0,0), true );
for( ; item; item = item->Next() )
{
switch( item->Type() )
{
case PCB_MODULE_EDGE_T:
edgemod = (EDGE_MODULE*) item;
edgemod->SetStartY( -edgemod->GetStart().y );
edgemod->SetEndY( -edgemod->GetEnd().y );
// Invert local coordinates
NEGATE( edgemod->m_Start0.y );
NEGATE( edgemod->m_End0.y );
edgemod->SetAngle( -edgemod->GetAngle() );
break;
case PCB_MODULE_TEXT_T:
// Reverse mirror position and mirror.
textmod = (TEXTE_MODULE*) item;
NEGATE( textmod->m_Pos.y );
NEGATE( textmod->m_Pos0.y );
if( textmod->m_Orient )
textmod->m_Orient = 3600 - textmod->m_Orient;
break;
default:
DisplayError( this, wxT( "Draw type undefined" ) );
break;
}
}
break; break;
default: default:
......
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