diff --git a/CHANGELOG.txt b/CHANGELOG.txt index aee95ee7f3..7bef03f917 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,19 @@ KiCad ChangeLog 2010 Please add newer entries at the top, list the date and your name with email address. +2010-dec-02 UPDATE Wayne Stambaugh +================================================================================ +++EESchema + * Move color configuration dialog to dialogs folder. + * Simplify color configuration dialog design, remove enable grid checkbox( I + think we have enough places to do this), and remove abbreviated labels. + * Restore changing value field behavior to create new component from the + current one and handle all of the potential library naming conflict issues. + * Create a toolbar button perform the same function as renaming the value + field for improved usability. + * Add new copy component bitmap contributed by Jean-Pierre Charras. + + 2010-dec-02, UPDATE Jean-Pierre Charras ================================================================================ Pcbnew: @@ -24,6 +37,7 @@ Gerbview: On the other hand, Gerber doc is not clear about the meaning of A and B scale. (Alas! Gerber doc is not clear about most of advanced commands) + 2010-nov-19 UPDATE Wayne Stambaugh ================================================================================ ++EESchema diff --git a/bitmaps/CMakeLists.txt b/bitmaps/CMakeLists.txt index af21302ab3..933ca0a295 100644 --- a/bitmaps/CMakeLists.txt +++ b/bitmaps/CMakeLists.txt @@ -64,6 +64,7 @@ set(BITMAP_SRCS component_select_alternate_shape.xpm config.xpm CopyBlock.xpm + copyComponent.xmp copy.xpm copper_layers_setup.cpp Cursor_Shape.xpm diff --git a/bitmaps/copyComponent.xpm b/bitmaps/copyComponent.xpm new file mode 100644 index 0000000000..e46fd80c4c --- /dev/null +++ b/bitmaps/copyComponent.xpm @@ -0,0 +1,38 @@ +/* XPM */ +const char *copyComponent_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 16 16 1", +"& c #080685", +"; c #CE3338", +". c #098409", +"+ c #ABAAAA", +": c #D44751", +"* c #885684", +"$ c #9794D7", +"@ c #BFB7ED", +"- c #640650", +" c None", +"= c #F80B0C", +"O c #ECECFC", +"# c #7F6CB6", +"% c #D3CFF7", +"o c #147A04", +"X c #4E9C54", +/* pixels */ +" .......X ", +" oOOOOO X.+ ", +"oo.OO@#$@%XX ", +" +oOO$&&&$+.+ ", +" oOO$&&&&@ooo+ ", +" .O%%@$&&*.++++", +" .%====-&-;+ ", +".oo@=O%@#&&*=+ ", +"++===O#&&&&&&: ", +" +=OO#&&&&#=++", +" + =OO%#&&$@===", +" =O%%%#$%#=++", +" +=%O%%%@%;;+ ", +" ===@@@@@$:=++ ", +" ++=======;++ ", +" ++++++++ " +}; diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 7eea7bb678..a489be7834 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -27,6 +27,7 @@ set(EESCHEMA_SRCS database.cpp delete.cpp delsheet.cpp + dialogs/dialog_color_config.cpp dialogs/dialog_plot_schematic_DXF.cpp dialogs/dialog_plot_schematic_DXF_base.cpp dialogs/dialog_plot_schematic_HPGL.cpp @@ -73,7 +74,6 @@ set(EESCHEMA_SRCS dialogs/dialog_SVG_print_base.cpp edit_component_in_schematic.cpp edit_label.cpp - eelayer.cpp eelibs_read_libraryfiles.cpp eeredraw.cpp eeschema.cpp diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index ea88aa2fad..ef0565ee43 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -1597,6 +1597,14 @@ LIB_ALIAS* LIB_COMPONENT::RemoveAlias( LIB_ALIAS* aAlias ) } +void LIB_COMPONENT::RemoveAllAliases() +{ + // Remove all of the aliases except the root alias. + while( m_aliases.size() > 1 ) + m_aliases.pop_back(); +} + + LIB_ALIAS* LIB_COMPONENT::GetAlias( const wxString& aName ) { wxCHECK2_MSG( !aName.IsEmpty(), return NULL, @@ -1619,3 +1627,13 @@ LIB_ALIAS* LIB_COMPONENT::GetAlias( size_t aIndex ) return m_aliases[aIndex]; } + + +void LIB_COMPONENT::AddAlias( const wxString& aName ) +{ + wxCHECK_RET( !HasAlias( aName ), + wxT( "Component <" ) + GetName() + wxT( "> already has an alias <" ) + + aName + wxT( ">. Bad programmer." ) ); + + m_aliases.push_back( new LIB_ALIAS( aName, this ) ); +} diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 9ddf87d2be..81e345f635 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -201,6 +201,18 @@ public: LIB_ALIAS* GetAlias( const wxString& aName ); + /** + * Function AddAlias + * + * Add an alias \a aName to the component. + * + * Duplicate alias names are not added to the alias list. Debug builds will raise an + * assertion. Release builds will fail silenetly. + * + * @param aName - Name of alias to add. + */ + void AddAlias( const wxString& aName ); + /** * Test if alias \a aName is in component alias list. * @@ -217,6 +229,8 @@ public: LIB_ALIAS* RemoveAlias( LIB_ALIAS* aAlias ); + void RemoveAllAliases(); + wxArrayString& GetFootPrints() { return m_FootprintList; } EDA_Rect GetBoundaryBox( int aUnit, int aConvert ); diff --git a/eeschema/dialogs/dialog_color_config.cpp b/eeschema/dialogs/dialog_color_config.cpp new file mode 100644 index 0000000000..c2921152e8 --- /dev/null +++ b/eeschema/dialogs/dialog_color_config.cpp @@ -0,0 +1,347 @@ + +/* Set up color Layers for EESchema + */ + +#include "fctsys.h" +#include "gr_basic.h" +#include "common.h" +#include "wxstruct.h" +#include "class_drawpanel.h" + +#include "general.h" +#include "protos.h" + +#include "dialog_color_config.h" + + +#define ID_COLOR_SETUP 1800 + + +static ColorButton GeneralColorButtons[] = { + { _( "Wire" ), LAYER_WIRE }, + { _( "Bus" ), LAYER_BUS }, + { _( "Junction" ), LAYER_JUNCTION }, + { _( "Label" ), LAYER_LOCLABEL }, + { _( "Global label" ), LAYER_GLOBLABEL }, + { _( "Net name" ), LAYER_NETNAM }, + { _( "Notes" ), LAYER_NOTES }, + { _( "No connection" ), LAYER_NOCONNECT }, + { wxT( "" ), -1 } // Sentinel marking end of list. +}; + +static ColorButton ComponentColorButtons[] = { + { _( "Body" ), LAYER_DEVICE }, + { _( "Body background" ), LAYER_DEVICE_BACKGROUND }, + { _( "Pin" ), LAYER_PIN }, + { _( "Pin number" ), LAYER_PINNUM }, + { _( "Pin name" ), LAYER_PINNAM }, + { _( "Reference" ), LAYER_REFERENCEPART }, + { _( "Value" ), LAYER_VALUEPART }, + { _( "Fields" ), LAYER_FIELDS }, + { wxT( "" ), -1 } // Sentinel marking end of list. +}; + +static ColorButton SheetColorButtons[] = { + { _( "Sheet" ), LAYER_SHEET }, + { _( "Sheet file name" ), LAYER_SHEETFILENAME }, + { _( "Sheet name" ), LAYER_SHEETNAME }, + { _( "Hierarchical label" ), LAYER_HIERLABEL }, + { wxT( "" ), -1 } // Sentinel marking end of list. +}; + +static ColorButton MiscColorButtons[] = { + { _( "Erc warning" ), LAYER_ERC_WARN }, + { _( "Erc error" ), LAYER_ERC_ERR }, + { _( "Grid" ), LAYER_GRID }, + { wxT( "" ), -1 } // Sentinel marking end of list. +}; + + +static ButtonIndex buttonGroups[] = { + { _( "General" ), GeneralColorButtons }, + { _( "Component" ), ComponentColorButtons }, + { _( "Sheet" ), SheetColorButtons }, + { _( "Miscellaneous" ), MiscColorButtons }, + { wxT( "" ), NULL } +}; + + +static int currentColors[ MAX_LAYER ]; + + +IMPLEMENT_DYNAMIC_CLASS( DIALOG_COLOR_CONFIG, wxDialog ) + + +DIALOG_COLOR_CONFIG::DIALOG_COLOR_CONFIG() +{ + Init(); +} + + +DIALOG_COLOR_CONFIG::DIALOG_COLOR_CONFIG( WinEDA_DrawFrame* aParent ) +{ + m_Parent = aParent; + Init(); + Create( aParent ); +} + + +DIALOG_COLOR_CONFIG::~DIALOG_COLOR_CONFIG() +{ +} + + +bool DIALOG_COLOR_CONFIG::Create( wxWindow* aParent, + wxWindowID aId, + const wxString& aCaption, + const wxPoint& aPosition, + const wxSize& aSize, + long aStyle ) +{ + SetExtraStyle( wxWS_EX_BLOCK_EVENTS ); + wxDialog::Create( aParent, aId, aCaption, aPosition, aSize, aStyle ); + + CreateControls(); + + if( GetSizer() ) + { + GetSizer()->SetSizeHints( this ); + } + + return true; +} + + +void DIALOG_COLOR_CONFIG::Init() +{ + OuterBoxSizer = NULL; + MainBoxSizer = NULL; + ColumnBoxSizer = NULL; + RowBoxSizer = NULL; + BitmapButton = NULL; + m_SelBgColor = NULL; + Line = NULL; + StdDialogButtonSizer = NULL; + Button = NULL; +} + + +void DIALOG_COLOR_CONFIG::CreateControls() +{ + wxStaticText* label; + int color; + int buttonId = 1800; + ButtonIndex* groups = buttonGroups; + + OuterBoxSizer = new wxBoxSizer( wxVERTICAL ); + SetSizer( OuterBoxSizer ); + + MainBoxSizer = new wxBoxSizer( wxHORIZONTAL ); + OuterBoxSizer->Add( MainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT, 5 ); + + while( groups->m_Buttons != NULL ) + { + ColorButton* buttons = groups->m_Buttons; + + ColumnBoxSizer = new wxBoxSizer( wxVERTICAL ); + MainBoxSizer->Add( ColumnBoxSizer, 1, wxALIGN_TOP | wxLEFT | wxTOP, 5 ); + RowBoxSizer = new wxBoxSizer( wxHORIZONTAL ); + ColumnBoxSizer->Add( RowBoxSizer, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 ); + + // Add a text string to identify the column of color select buttons. + label = new wxStaticText( this, wxID_ANY, groups->m_Name ); + + // Make the column label font bold. + wxFont font( label->GetFont() ); + font.SetWeight( wxFONTWEIGHT_BOLD ); + label->SetFont( font ); + + RowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); + + while( buttons->m_Layer >= 0 ) + { + RowBoxSizer = new wxBoxSizer( wxHORIZONTAL ); + ColumnBoxSizer->Add( RowBoxSizer, 0, wxGROW | wxALL, 0 ); + + wxMemoryDC iconDC; + wxBitmap bitmap( BUTT_SIZE_X, BUTT_SIZE_Y ); + + iconDC.SelectObject( bitmap ); + color = currentColors[ buttons->m_Layer ] = g_LayerDescr.LayerColor[ buttons->m_Layer ]; + iconDC.SetPen( *wxBLACK_PEN ); + wxBrush brush; + brush.SetColour( ColorRefs[ color ].m_Red, + ColorRefs[ color ].m_Green, + ColorRefs[ color ].m_Blue ); + brush.SetStyle( wxSOLID ); + + iconDC.SetBrush( brush ); + iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y ); + + BitmapButton = new wxBitmapButton( this, buttonId, bitmap, wxDefaultPosition, + wxSize( BUTT_SIZE_X+8, BUTT_SIZE_Y+6 ) ); + BitmapButton->SetClientData( (void*) buttons ); + RowBoxSizer->Add( BitmapButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 ); + + label = new wxStaticText( this, wxID_ANY, wxGetTranslation( buttons->m_Name ) ); + RowBoxSizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, 5 ); + buttonId += 1; + buttons++; + } + + groups++; + } + + Connect( 1800, buttonId - 1, wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler( DIALOG_COLOR_CONFIG::SetColor ) ); + + // Add a spacer to improve appearance. + ColumnBoxSizer->AddSpacer( 5 ); + + wxArrayString m_SelBgColorStrings; + m_SelBgColorStrings.Add( _( "White" ) ); + m_SelBgColorStrings.Add( _( "Black" ) ); + m_SelBgColor = new wxRadioBox( this, wxID_ANY, _( "Background Color" ), + wxDefaultPosition, wxDefaultSize, + m_SelBgColorStrings, 1, wxRA_SPECIFY_COLS ); + m_SelBgColor->SetSelection( ( g_DrawBgColor == BLACK ) ? 1 : 0 ); + ColumnBoxSizer->Add( m_SelBgColor, 1, wxGROW | wxRIGHT | wxTOP | wxBOTTOM, 5 ); + + // Provide a line to separate all of the controls added so far from the + // "OK", "Cancel", and "Apply" buttons (which will be added after that + // line). + Line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); + OuterBoxSizer->Add( Line, 0, wxGROW | wxALL, 5 ); + + // Provide a StdDialogButtonSizer to accommodate the OK, Cancel, and Apply + // buttons; using that type of sizer results in those buttons being + // automatically located in positions appropriate for each (OS) version of + // KiCad. + StdDialogButtonSizer = new wxStdDialogButtonSizer; + OuterBoxSizer->Add( StdDialogButtonSizer, 0, wxGROW | wxALL, 10 ); + + Button = new wxButton( this, wxID_OK, _( "OK" ), wxDefaultPosition, wxDefaultSize, 0 ); + StdDialogButtonSizer->AddButton( Button ); + + Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ), wxDefaultPosition, wxDefaultSize, 0 ); + StdDialogButtonSizer->AddButton( Button ); + Button->SetFocus(); + + Button = new wxButton( this, wxID_APPLY, _( "Apply" ), wxDefaultPosition, wxDefaultSize, 0 ); + StdDialogButtonSizer->AddButton( Button ); + + Connect( wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler( DIALOG_COLOR_CONFIG::OnOkClick ) ); + Connect( wxID_CANCEL, wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler( DIALOG_COLOR_CONFIG::OnCancelClick ) ); + Connect( wxID_APPLY, wxEVT_COMMAND_BUTTON_CLICKED, + wxCommandEventHandler( DIALOG_COLOR_CONFIG::OnApplyClick ) ); + + StdDialogButtonSizer->Realize(); + + // Dialog now needs to be resized, but the associated command is found elsewhere. +} + + +void DIALOG_COLOR_CONFIG::SetColor( wxCommandEvent& event ) +{ + wxBitmapButton* button = (wxBitmapButton*) event.GetEventObject(); + + wxCHECK_RET( button != NULL, wxT( "Color button event object is NULL." ) ); + + ColorButton* colorButton = (ColorButton*) button->GetClientData(); + + wxCHECK_RET( colorButton != NULL, wxT( "Client data not set for color button." ) ); + + int color = DisplayColorFrame( this, colorButton->m_Layer ); + + if( color < 0 || currentColors[ colorButton->m_Layer ] == color ) + return; + + currentColors[ colorButton->m_Layer ] = color; + + wxMemoryDC iconDC; + + wxBitmap bitmap = button->GetBitmapLabel(); + iconDC.SelectObject( bitmap ); + wxBrush brush; + iconDC.SetPen( *wxBLACK_PEN ); + brush.SetColour( ColorRefs[ color ].m_Red, + ColorRefs[ color ].m_Green, + ColorRefs[ color ].m_Blue ); + brush.SetStyle( wxSOLID ); + + iconDC.SetBrush( brush ); + iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y ); + button->SetBitmapLabel( bitmap ); + button->Refresh(); + + Refresh( false ); +} + + +void DIALOG_COLOR_CONFIG::UpdateLayerSettings() +{ + for( int i = 0; i < MAX_LAYERS; i++ ) + g_LayerDescr.LayerColor[ i ] = currentColors[ i ]; + + // Update color of background + if( m_SelBgColor->GetSelection() == 0 ) + g_DrawBgColor = WHITE; + else + g_DrawBgColor = BLACK; + + m_Parent->Refresh(); +} + + +void DIALOG_COLOR_CONFIG::OnOkClick( wxCommandEvent& WXUNUSED( event ) ) +{ + UpdateLayerSettings(); + m_Parent->DrawPanel->Refresh(); + EndModal( 1 ); +} + + +void DIALOG_COLOR_CONFIG::OnCancelClick( wxCommandEvent& WXUNUSED( event ) ) +{ + EndModal( -1 ); +} + + +void DIALOG_COLOR_CONFIG::OnApplyClick( wxCommandEvent& WXUNUSED( event ) ) +{ + UpdateLayerSettings(); + m_Parent->DrawPanel->Refresh(); +} + + +void SeedLayers() +{ + LayerStruct* LayerPointer = &g_LayerDescr; + int pt; + + LayerPointer->CommonColor = WHITE; + LayerPointer->Flags = 0; + pt = 0; + LayerPointer->CurrentWidth = 1; + + /* seed Up the Layer colours, set all user layers off */ + for( pt = 0; pt < MAX_LAYERS; pt++ ) + { + LayerPointer->LayerStatus[pt] = 0; + LayerPointer->LayerColor[pt] = DARKGRAY; + } + + LayerPointer->NumberOfLayers = pt - 1; + /* Specific colors: update by reading the config. */ +} + + +EDA_Colors ReturnLayerColor( int Layer ) +{ + if( g_LayerDescr.Flags == 0 ) + return (EDA_Colors) g_LayerDescr.LayerColor[Layer]; + else + return (EDA_Colors) g_LayerDescr.CommonColor; +} diff --git a/eeschema/dialogs/dialog_color_config.h b/eeschema/dialogs/dialog_color_config.h new file mode 100644 index 0000000000..a202b8cb66 --- /dev/null +++ b/eeschema/dialogs/dialog_color_config.h @@ -0,0 +1,86 @@ + +#ifndef _DIALOG_COLOR_CONFIG_H_ +#define _DIALOG_COLOR_CONFIG_H_ + +#include "wx/statline.h" + + +class wxBoxSizer; +class wxStaticLine; +class wxStdDialogButtonSizer; + + +// Specify the width and height of every (color-displaying / bitmap) button +const int BUTT_SIZE_X = 16; +const int BUTT_SIZE_Y = 16; + + +/********************/ +/* Layer menu list. */ +/********************/ + +struct ColorButton +{ + wxString m_Name; + int m_Layer; +}; + +struct ButtonIndex +{ + wxString m_Name; + ColorButton* m_Buttons; +}; + + +/***********************************************/ +/* Derived class for the frame color settings. */ +/***********************************************/ + +class DIALOG_COLOR_CONFIG: public wxDialog +{ +private: + DECLARE_DYNAMIC_CLASS( DIALOG_COLOR_CONFIG ) + + WinEDA_DrawFrame* m_Parent; + wxBoxSizer* OuterBoxSizer; + wxBoxSizer* MainBoxSizer; + wxBoxSizer* ColumnBoxSizer; + wxBoxSizer* RowBoxSizer; + wxBitmapButton* BitmapButton; + wxRadioBox* m_SelBgColor; + wxStaticLine* Line; + wxStdDialogButtonSizer* StdDialogButtonSizer; + wxButton* Button; + + // Creation + bool Create( wxWindow* aParent, + wxWindowID aId = wxID_ANY, + const wxString& aCaption = _( "EESchema Colors" ), + const wxPoint& aPosition = wxDefaultPosition, + const wxSize& aSize = wxDefaultSize, + long aStyle = wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER ); + + // Initializes member variables + void Init(); + + // Creates the controls and sizers + void CreateControls(); + + wxBitmap GetBitmapResource( const wxString& aName ); + wxIcon GetIconResource( const wxString& aName ); + static bool ShowToolTips(); + + void UpdateLayerSettings(); + void SetColor( wxCommandEvent& aEvent ); + void OnOkClick( wxCommandEvent& aEvent ); + void OnCancelClick( wxCommandEvent& aEvent ); + void OnApplyClick( wxCommandEvent& aEvent ); + +public: + // Constructors and destructor + DIALOG_COLOR_CONFIG(); + DIALOG_COLOR_CONFIG( WinEDA_DrawFrame* aParent ); + ~DIALOG_COLOR_CONFIG(); +}; + +#endif // _DIALOG_COLOR_CONFIG_H_ diff --git a/eeschema/eelayer.cpp b/eeschema/eelayer.cpp deleted file mode 100644 index 2b94665806..0000000000 --- a/eeschema/eelayer.cpp +++ /dev/null @@ -1,414 +0,0 @@ -/***************/ -/* eelayer.cpp */ -/***************/ - -/* Set up color Layers for EESchema - */ - -#include "fctsys.h" -#include "gr_basic.h" -#include "common.h" -#include "eeschema_id.h" -#include "wxstruct.h" -#include "class_drawpanel.h" - -#include "general.h" -#include "protos.h" - -#include "eelayer.h" // Header file associated with this file - -// Local variables: -static int CurrentColor[NB_BUTT]; // Holds color for each layer while dialog box open - -IMPLEMENT_DYNAMIC_CLASS( WinEDA_SetColorsFrame, wxDialog ) - -// Table of events for WinEDA_SetColorsFrame -BEGIN_EVENT_TABLE( WinEDA_SetColorsFrame, wxDialog ) - EVT_COMMAND_RANGE( ID_COLOR_SETUP, ID_COLOR_SETUP + NB_BUTT - 1, - wxEVT_COMMAND_BUTTON_CLICKED, - WinEDA_SetColorsFrame::SetColor ) - EVT_BUTTON( wxID_OK, WinEDA_SetColorsFrame::OnOkClick ) - EVT_BUTTON( wxID_CANCEL, WinEDA_SetColorsFrame::OnCancelClick ) - EVT_BUTTON( wxID_APPLY, WinEDA_SetColorsFrame::OnApplyClick ) -END_EVENT_TABLE() - - -/**************************************************************/ -void DisplayColorSetupFrame( WinEDA_DrawFrame* parent, - const wxPoint& framepos ) -{ -/**************************************************************/ - WinEDA_SetColorsFrame* frame = - new WinEDA_SetColorsFrame( parent, framepos ); - - frame->ShowModal(); - frame->Destroy(); -} - - -// Default Constructor (whose provision is mandated by the inclusion -// of DECLARE_DYNAMIC_CLASS( WinEDA_SetColorsFrame ) within eelayer.h) -WinEDA_SetColorsFrame::WinEDA_SetColorsFrame() -{ - Init(); -} - - -// Standard Constructor -WinEDA_SetColorsFrame::WinEDA_SetColorsFrame( WinEDA_DrawFrame* parent, - const wxPoint& framepos ) -{ - m_Parent = parent; - Init(); - Create( parent, - SYMBOL_WINEDA_SETCOLORSFRAME_IDNAME, - SYMBOL_WINEDA_SETCOLORSFRAME_TITLE, - framepos, - wxDefaultSize, - SYMBOL_WINEDA_SETCOLORSFRAME_STYLE ); -} - - -// Destructor -WinEDA_SetColorsFrame::~WinEDA_SetColorsFrame() -{ -} - - -/**********************************************************/ -bool WinEDA_SetColorsFrame::Create( wxWindow* parent, - wxWindowID id, - const wxString& caption, - const wxPoint& pos, - const wxSize& size, - long style ) -{ -/**********************************************************/ - SetExtraStyle( wxWS_EX_BLOCK_EVENTS ); - wxDialog::Create( parent, id, caption, pos, size, style ); - - CreateControls(); - if( GetSizer() ) - { - GetSizer()->SetSizeHints( this ); - } - return true; -} - - -/**********************************************************/ -void WinEDA_SetColorsFrame::Init() -{ -/**********************************************************/ - OuterBoxSizer = NULL; - MainBoxSizer = NULL; - ColumnBoxSizer = NULL; - RowBoxSizer = NULL; - Label = NULL; - BitmapButton = NULL; - m_ShowGrid = NULL; - m_SelBgColor = NULL; - Line = NULL; - StdDialogButtonSizer = NULL; - Button = NULL; -} - - -/**********************************************************/ -void WinEDA_SetColorsFrame::CreateControls() -{ -/**********************************************************/ - int lyr, grp, butt_ID, buttcolor; - - OuterBoxSizer = new wxBoxSizer( wxVERTICAL ); - SetSizer( OuterBoxSizer ); - - MainBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - OuterBoxSizer->Add( MainBoxSizer, 1, wxGROW | wxLEFT | wxRIGHT, 5 ); - - // Add various items to the dialog box, as determined by the - // details of each element contained within laytool_list[] - for( lyr = 0, grp = 0; lyr < NB_BUTT; lyr++ ) - { - // Look for the initial button of each group of controls. - if( lyr == 0 || lyr == laytool_index[grp]->m_Index + 1 ) - { - if( lyr != 0 ) - grp++; - - // Add another column sizer, unless the current value of - // grp is BUTTON_GROUPS - 1. (The very last group of controls - // differs from the previous groups in that its associated - // controls are located in the same column as the controls - // associated with the preceeding group.) - if( grp < BUTTON_GROUPS - 1 ) - { - ColumnBoxSizer = new wxBoxSizer( wxVERTICAL ); - MainBoxSizer->Add( ColumnBoxSizer, - 1, - wxALIGN_TOP | wxLEFT | wxTOP, - 5 ); - } - else - { - // Add a spacer to better separate the text string (which is - // about to be added) from the items located above it. - ColumnBoxSizer->AddSpacer( 5 ); - } - - RowBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - ColumnBoxSizer->Add( RowBoxSizer, - 0, - wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, - 5 ); - - // Add a text string to identify the following set of controls - Label = new wxStaticText( this, -1, laytool_index[grp]->m_Name, - wxDefaultPosition, wxDefaultSize, 0 ); - - // Make this text string bold (so that it stands out better) - Label->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), - wxNORMAL_FONT->GetFamily(), - wxNORMAL, wxBOLD, false, - wxNORMAL_FONT->GetFaceName() ) ); - - RowBoxSizer->Add( Label, 1, wxALIGN_CENTER_VERTICAL | wxALL, 5 ); - } - - RowBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - ColumnBoxSizer->Add( RowBoxSizer, 0, wxGROW | wxALL, 0 ); - - butt_ID = ID_COLOR_SETUP + lyr; - laytool_list[lyr]->m_Id = butt_ID; - wxMemoryDC iconDC; - wxBitmap ButtBitmap( BUTT_SIZE_X, BUTT_SIZE_Y ); - - iconDC.SelectObject( ButtBitmap ); - buttcolor = *laytool_list[lyr]->m_Color; - CurrentColor[lyr] = buttcolor; - wxBrush Brush; - iconDC.SelectObject( ButtBitmap ); - iconDC.SetPen( *wxBLACK_PEN ); - Brush.SetColour( ColorRefs[buttcolor].m_Red, - ColorRefs[buttcolor].m_Green, - ColorRefs[buttcolor].m_Blue ); - Brush.SetStyle( wxSOLID ); - - iconDC.SetBrush( Brush ); - iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y ); - - BitmapButton = - new wxBitmapButton( this, butt_ID, ButtBitmap, wxDefaultPosition, - wxSize( BUTT_SIZE_X+8, BUTT_SIZE_Y+6 ) ); - RowBoxSizer->Add( BitmapButton, - 0, - wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, - 5 ); - - laytool_list[lyr]->m_Button = BitmapButton; - - // Add a text string, unless the current value of lyr is NB_BUTT - 1 - if( lyr < NB_BUTT - 1 ) - { - Label = - new wxStaticText( this, wxID_STATIC, - wxGetTranslation( laytool_list[lyr]->m_Name ), - wxDefaultPosition, wxDefaultSize, 0 ); - RowBoxSizer->Add( Label, 1, wxALIGN_CENTER_VERTICAL | wxBOTTOM, 5 ); - } - else - { - // Special case; provide a checkbox instead (rather than a text - // string). - m_ShowGrid = - new wxCheckBox( this, ID_CHECKBOX_SHOW_GRID, _( "Grid" ), - wxDefaultPosition, wxDefaultSize, 0 ); - m_ShowGrid->SetValue( m_Parent->IsGridVisible() ); - RowBoxSizer->Add( m_ShowGrid, - 1, - wxALIGN_CENTER_VERTICAL | wxBOTTOM, - 5 ); - } - } - - // Add a spacer to improve appearance. - ColumnBoxSizer->AddSpacer( 5 ); - - wxArrayString m_SelBgColorStrings; - m_SelBgColorStrings.Add( _( "White" ) ); - m_SelBgColorStrings.Add( _( "Black" ) ); - m_SelBgColor = - new wxRadioBox( this, ID_RADIOBOX_BACKGROUND_COLOR, - _( "Background Color:" ), - wxDefaultPosition, wxDefaultSize, - m_SelBgColorStrings, 1, wxRA_SPECIFY_COLS ); - m_SelBgColor->SetSelection( ( g_DrawBgColor == BLACK ) ? 1 : 0 ); - ColumnBoxSizer->Add( m_SelBgColor, - 1, - wxGROW | wxRIGHT | wxTOP | wxBOTTOM, - 5 ); - - // Provide a line to separate all of the controls added so far from the - // "OK", "Cancel", and "Apply" buttons (which will be added after that - // line). - Line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, - wxLI_HORIZONTAL ); - OuterBoxSizer->Add( Line, 0, wxGROW | wxALL, 5 ); - - // Provide a StdDialogButtonSizer to accommodate the OK, Cancel, and Apply - // buttons; using that type of sizer results in those buttons being - // automatically located in positions appropriate for each (OS) version of - // KiCad. - StdDialogButtonSizer = new wxStdDialogButtonSizer; - OuterBoxSizer->Add( StdDialogButtonSizer, 0, wxGROW | wxALL, 10 ); - - Button = new wxButton( this, wxID_OK, _( "OK" ), wxDefaultPosition, - wxDefaultSize, 0 ); - StdDialogButtonSizer->AddButton( Button ); - - Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ), - wxDefaultPosition, wxDefaultSize, 0 ); - StdDialogButtonSizer->AddButton( Button ); - Button->SetFocus(); - - Button = new wxButton( this, wxID_APPLY, _( "Apply" ), wxDefaultPosition, - wxDefaultSize, 0 ); - StdDialogButtonSizer->AddButton( Button ); - - StdDialogButtonSizer->Realize(); - - // (Dialog now needs to be resized, but the associated command is found - // elsewhere.) -} - - -/**********************************************************/ -void WinEDA_SetColorsFrame::SetColor( wxCommandEvent& event ) -{ -/**********************************************************/ - int id = event.GetId(); - int color; - - wxBitmapButton* Button; - - color = DisplayColorFrame( this, - CurrentColor[id - ID_COLOR_SETUP] ); - - if( color < 0 ) - return; - - if( CurrentColor[id - ID_COLOR_SETUP] == color ) - return; - - CurrentColor[id - ID_COLOR_SETUP] = color; - wxMemoryDC iconDC; - - Button = laytool_list[id - ID_COLOR_SETUP]->m_Button; - - wxBitmap ButtBitmap = Button->GetBitmapLabel(); - iconDC.SelectObject( ButtBitmap ); - wxBrush Brush; - iconDC.SetPen( *wxBLACK_PEN ); - Brush.SetColour( ColorRefs[color].m_Red, - ColorRefs[color].m_Green, - ColorRefs[color].m_Blue ); - Brush.SetStyle( wxSOLID ); - - iconDC.SetBrush( Brush ); - iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y ); - Button->SetBitmapLabel( ButtBitmap ); - Button->Refresh(); - - Refresh( FALSE ); -} - - -/******************************************************************/ -void WinEDA_SetColorsFrame::UpdateLayerSettings() -{ -/******************************************************************/ - // Update colors for each layer - for( int lyr = 0; lyr < NB_BUTT; lyr++ ) - { - // (As a bitmap button has been provided for *every* layer, - // it is not necessary to check whether it actually has been - // provided for each of those layers.) - *laytool_list[lyr]->m_Color = CurrentColor[lyr]; - } - - // Update whether grid is actually displayed or otherwise - // The previous command compiles OK, but to prevent a warning - // from being generated when the Linux version is being compiled, - // the next two commands are provided instead. - m_Parent->SetGridVisibility( m_ShowGrid->GetValue() ); - - // Update color of background - if( m_SelBgColor->GetSelection() == 0 ) - g_DrawBgColor = WHITE; - else - g_DrawBgColor = BLACK; - - m_Parent->Refresh(); -} - - -/**********************************************************************/ -void WinEDA_SetColorsFrame::OnOkClick( wxCommandEvent& WXUNUSED( event ) ) -{ -/**********************************************************************/ - UpdateLayerSettings(); - m_Parent->DrawPanel->Refresh(); - EndModal( 1 ); -} - - -/*******************************************************************/ -void WinEDA_SetColorsFrame::OnCancelClick( wxCommandEvent& WXUNUSED( event ) ) -{ -/*******************************************************************/ - EndModal( -1 ); -} - - -/*******************************************************************/ -void WinEDA_SetColorsFrame::OnApplyClick( wxCommandEvent& WXUNUSED( event ) ) -{ -/*******************************************************************/ - UpdateLayerSettings(); - m_Parent->DrawPanel->Refresh(); -} - - -/*************************/ -void SeedLayers() -{ -/*************************/ - LayerStruct* LayerPointer = &g_LayerDescr; - int pt; - - LayerPointer->CommonColor = WHITE; - LayerPointer->Flags = 0; - pt = 0; - LayerPointer->CurrentWidth = 1; - - /* seed Up the Layer colours, set all user layers off */ - for( pt = 0; pt < MAX_LAYERS; pt++ ) - { - LayerPointer->LayerStatus[pt] = 0; - LayerPointer->LayerColor[pt] = DARKGRAY; - } - - LayerPointer->NumberOfLayers = pt - 1; - /* Specific colors: update by reading the config. */ -} - - -/***************************************/ -EDA_Colors ReturnLayerColor( int Layer ) -{ -/****************************************/ - if( g_LayerDescr.Flags == 0 ) - return (EDA_Colors) g_LayerDescr.LayerColor[Layer]; - else - return (EDA_Colors) g_LayerDescr.CommonColor; -} diff --git a/eeschema/eelayer.h b/eeschema/eelayer.h deleted file mode 100644 index 6a8edf24bc..0000000000 --- a/eeschema/eelayer.h +++ /dev/null @@ -1,335 +0,0 @@ -/*************/ -/* eelayer.h */ -/*************/ - -#ifndef _EELAYER_H_ -#define _EELAYER_H_ - -#include "wx/statline.h" - -#include "general.h" - - -class wxBoxSizer; -class wxStaticLine; -class wxStdDialogButtonSizer; - - -// Specify how many elements are contained within laytool_list[] -const int NB_BUTT = 23; // Includes an element associated with the grid - -// Specify how many elements are contained within laytool_index[] -const int BUTTON_GROUPS = 5; - -// Specify the numbers associated with assorted controls -enum col_sel_id { - ID_DIALOG = 1800, - ID_CHECKBOX_SHOW_GRID, - ID_RADIOBOX_BACKGROUND_COLOR, - ID_COLOR_SETUP -}; - -// #define SYMBOL_WINEDA_SETCOLORSFRAME_STYLE wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER -#define SYMBOL_WINEDA_SETCOLORSFRAME_STYLE wxDEFAULT_DIALOG_STYLE|MAYBE_RESIZE_BORDER -#define SYMBOL_WINEDA_SETCOLORSFRAME_TITLE _("EESchema Colors") -#define SYMBOL_WINEDA_SETCOLORSFRAME_IDNAME ID_DIALOG -// #define SYMBOL_WINEDA_SETCOLORSFRAME_SIZE wxSize(400, 300) -// #define SYMBOL_WINEDA_SETCOLORSFRAME_POSITION wxDefaultPosition - -#ifndef wxCLOSE_BOX -#define wxCLOSE_BOX 0x1000 -#endif - -// Specify the width and height of every (color-displaying / bitmap) button -const int BUTT_SIZE_X = 16; -const int BUTT_SIZE_Y = 16; - -// Macro utile : -#define ADR( numlayer ) & (g_LayerDescr.LayerColor[numlayer]) - - -/********************/ -/* Layer menu list. */ -/********************/ - -struct ColorButton -{ - wxString m_Name; - int* m_Color; - int m_Id; - wxBitmapButton* m_Button; -}; - -struct ButtonIndex -{ - wxString m_Name; // Title - int m_Index; // Index to last bitmap button in group -}; - - -static ColorButton Layer_Wire_Item = -{ - _( "Wire" ), // Title - ADR( LAYER_WIRE ) // Adr of optional parameter -}; - -static ColorButton Layer_Bus_Item = -{ - _( "Bus" ), // Title - ADR( LAYER_BUS ) // Adr of optional parameter -}; - -static ColorButton Layer_Junction_Item = -{ - _( "Junction" ), // Title - ADR( LAYER_JUNCTION ) // Adr of optional parameter -}; - -static ColorButton Layer_LocalLabel_Item = -{ - _( "Label" ), // Title - ADR( LAYER_LOCLABEL ) // Adr of optional parameter -}; - -static ColorButton Layer_GlobLabel_Item = -{ - _( "GlobLabel" ), // Title - ADR( LAYER_GLOBLABEL ) // Adr of optional parameter -}; - -static ColorButton Layer_NetNam_Item = -{ - _( "Netname" ), // Title - ADR( LAYER_NETNAM ) // Adr of optional parameter -}; - -static ColorButton Layer_Notes_Item = -{ - _( "Notes" ), // Title - ADR( LAYER_NOTES ) // Adr of optional parameter -}; - -static ColorButton Layer_NoConnect_Item = -{ - _( "NoConn" ), // Title - ADR( LAYER_NOCONNECT ) // Adr of optional parameter -}; - - -static ColorButton Layer_BodyDevice_Item = -{ - _( "Body" ), // Title - ADR( LAYER_DEVICE ) // Adr of optional parameter -}; - -static ColorButton Layer_BodyBackgroundDevice_Item = -{ - _( "Body Bg" ), // Title - ADR( LAYER_DEVICE_BACKGROUND ) // Adr of optional parameter -}; - -static ColorButton Layer_Pin_Item = -{ - _( "Pin" ), // Title - ADR( LAYER_PIN ) // Adr of optional parameter -}; - -static ColorButton Layer_PinNum_Item = -{ - _( "PinNum" ), // Title - ADR( LAYER_PINNUM ) // Adr of optional parameter -}; - -static ColorButton Layer_PinNam_Item = -{ - _( "PinNam" ), // Title - ADR( LAYER_PINNAM ) // Adr of optional parameter -}; - -static ColorButton Layer_Reference_Item = -{ - _( "Reference" ), // Title - ADR( LAYER_REFERENCEPART ) // Adr of optional parameter -}; - -static ColorButton Layer_Value_Item = -{ - _( "Value" ), // Title - ADR( LAYER_VALUEPART ) // Adr of optional parameter -}; - -static ColorButton Layer_Fields_Item = -{ - _( "Fields" ), // Title - ADR( LAYER_FIELDS ) // Adr of optional parameter -}; - - -static ColorButton Layer_Sheet_Item = -{ - _( "Sheet" ), // Title - ADR( LAYER_SHEET ) // Adr of optional parameter -}; - -static ColorButton Layer_SheetFileName_Item = -{ - _( "Sheetfile" ), // Title - ADR( LAYER_SHEETFILENAME ) // Adr of optional parameter -}; - -static ColorButton Layer_SheetName_Item = -{ - _( "SheetName" ), // Title - ADR( LAYER_SHEETNAME ) // Adr of optional parameter -}; - -static ColorButton Layer_SheetLabel_Item = -{ - _( "SheetLabel (Pin Sheet)" ), // Title - ADR( LAYER_SHEETLABEL ) // Adr of optional parameter -}; - -static ColorButton Layer_HierarchicalLabel_Item = -{ - _( "Hierarchical Label" ), // Title - ADR( LAYER_HIERLABEL ) // Adr of optional parameter -}; - -static ColorButton Layer_Erc_Warning_Item = -{ - _( "Erc Warning" ), // Title - ADR( LAYER_ERC_WARN ) // Adr of optional parameter -}; - -static ColorButton Layer_Erc_Error_Item = -{ - _( "Erc Error" ), // Title - ADR( LAYER_ERC_ERR ) // Adr of optional parameter -}; - - -static ColorButton* laytool_list[NB_BUTT] = { - &Layer_Wire_Item, - &Layer_Bus_Item, - &Layer_Junction_Item, - &Layer_LocalLabel_Item, - &Layer_GlobLabel_Item, - &Layer_NetNam_Item, - &Layer_Notes_Item, - &Layer_NoConnect_Item, - - &Layer_BodyDevice_Item, - &Layer_BodyBackgroundDevice_Item, - &Layer_Pin_Item, - &Layer_PinNum_Item, - &Layer_PinNam_Item, - &Layer_Reference_Item, - &Layer_Value_Item, - &Layer_Fields_Item, - - &Layer_Sheet_Item, - &Layer_SheetFileName_Item, - &Layer_SheetName_Item, - &Layer_SheetLabel_Item, - &Layer_HierarchicalLabel_Item, - - &Layer_Erc_Warning_Item, - &Layer_Erc_Error_Item, -}; - - -static ButtonIndex Msg_General = -{ - _( "General" ), // Title - 7 // Index to first bitmap button in group -}; - -static ButtonIndex MsgDevice_Item = -{ - _( "Device" ), // Title - 15 // Index to first bitmap button in group -}; - -static ButtonIndex Msg_Sheets = -{ - _( "Sheets" ), // Title - 20 // Index to first bitmap button in group -}; - -static ButtonIndex Msg_ErcMarck = -{ - _( "Erc Mark" ), // Title - 22 // Index to first bitmap button in group -}; - -static ButtonIndex Msg_Other = -{ - _( "Other" ), // Title - 23 // Index to first bitmap button in group -}; - - -static ButtonIndex* laytool_index[BUTTON_GROUPS] = { - &Msg_General, - &MsgDevice_Item, - &Msg_Sheets, - &Msg_ErcMarck, - &Msg_Other -}; - - -/***********************************************/ -/* Derived class for the frame color settings. */ -/***********************************************/ - -class WinEDA_SetColorsFrame: public wxDialog -{ -private: - DECLARE_DYNAMIC_CLASS( WinEDA_SetColorsFrame ) - DECLARE_EVENT_TABLE() - - WinEDA_DrawFrame* m_Parent; - wxBoxSizer* OuterBoxSizer; - wxBoxSizer* MainBoxSizer; - wxBoxSizer* ColumnBoxSizer; - wxBoxSizer* RowBoxSizer; - wxStaticText* Label; - wxBitmapButton* BitmapButton; - wxCheckBox* m_ShowGrid; - wxRadioBox* m_SelBgColor; - wxStaticLine* Line; - wxStdDialogButtonSizer* StdDialogButtonSizer; - wxButton* Button; - - // Creation - bool Create( wxWindow* parent, - wxWindowID id = SYMBOL_WINEDA_SETCOLORSFRAME_IDNAME, - const wxString& caption = SYMBOL_WINEDA_SETCOLORSFRAME_TITLE, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = SYMBOL_WINEDA_SETCOLORSFRAME_STYLE ); - - // Initializes member variables - void Init(); - - // Creates the controls and sizers - void CreateControls(); - - wxBitmap GetBitmapResource( const wxString& name ); - wxIcon GetIconResource( const wxString& name ); - static bool ShowToolTips(); - - void UpdateLayerSettings(); - void SetColor( wxCommandEvent& event ); - void OnOkClick( wxCommandEvent& event ); - void OnCancelClick( wxCommandEvent& event ); - void OnApplyClick( wxCommandEvent& event ); - -public: - // Constructors and destructor - WinEDA_SetColorsFrame(); - WinEDA_SetColorsFrame( WinEDA_DrawFrame* parent, const wxPoint& framepos ); - ~WinEDA_SetColorsFrame(); -}; - -#endif // _EELAYER_H_ diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index b4a983a137..63deb43b33 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -22,6 +22,7 @@ #include "dialog_hotkeys_editor.h" +#include "dialogs/dialog_color_config.h" #include "dialogs/dialog_eeschema_config.h" #include "dialogs/dialog_eeschema_options.h" @@ -41,23 +42,22 @@ void LIB_EDIT_FRAME::InstallConfigFrame( wxCommandEvent& event ) } +void LIB_EDIT_FRAME::OnColorConfig( wxCommandEvent& aEvent ) +{ + DIALOG_COLOR_CONFIG dlg( this ); + + dlg.ShowModal(); +} + + void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) { int id = event.GetId(); - wxPoint pos; wxFileName fn; WinEDA_SchematicFrame * schFrame = ( WinEDA_SchematicFrame * ) GetParent(); - wxGetMousePosition( &pos.x, &pos.y ); - - pos.y += 5; - switch( id ) { - case ID_COLORS_SETUP: - DisplayColorSetupFrame( this, pos ); - break; - case ID_CONFIG_SAVE: schFrame->SaveProjectFile( this, false ); break; @@ -103,6 +103,14 @@ void LIB_EDIT_FRAME::Process_Config( wxCommandEvent& event ) } +void WinEDA_SchematicFrame::OnColorConfig( wxCommandEvent& aEvent ) +{ + DIALOG_COLOR_CONFIG dlg( this ); + + dlg.ShowModal(); +} + + void WinEDA_SchematicFrame::InstallConfigFrame( wxCommandEvent& event ) { DIALOG_EESCHEMA_CONFIG CfgFrame( this, this ); @@ -114,19 +122,10 @@ void WinEDA_SchematicFrame::InstallConfigFrame( wxCommandEvent& event ) void WinEDA_SchematicFrame::Process_Config( wxCommandEvent& event ) { int id = event.GetId(); - wxPoint pos; wxFileName fn; - wxGetMousePosition( &pos.x, &pos.y ); - - pos.y += 5; - switch( id ) { - case ID_COLORS_SETUP: - DisplayColorSetupFrame( this, pos ); - break; - case ID_CONFIG_SAVE: SaveProjectFile( this, false ); break; diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index 37b36e1e23..44630043a2 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -136,7 +136,8 @@ enum id_eeschema_frm ID_LIBEDIT_SAVE_CURRENT_LIB, ID_LIBEDIT_SAVE_CURRENT_PART, ID_LIBEDIT_NEW_PART, - ID_LIBEDIT_GET_FRAME_EDIT_PART, + ID_LIBEDIT_NEW_PART_FROM_EXISTING, + ID_LIBEDIT_GET_FRAME_EDIT_PART, ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, ID_LIBEDIT_DELETE_PART, ID_DE_MORGAN_NORMAL_BUTT, diff --git a/eeschema/general.h b/eeschema/general.h index b81fae02b1..9497d16e9d 100644 --- a/eeschema/general.h +++ b/eeschema/general.h @@ -93,6 +93,7 @@ typedef enum LAYER_ERC_WARN, LAYER_ERC_ERR, LAYER_DEVICE_BACKGROUND, + LAYER_GRID, MAX_LAYER /* Maximum layers */ } LayerNumber; diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index f12efe4500..12658c5655 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -157,7 +157,6 @@ bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, CMP_LIBRARY* aLib { SAFE_DELETE( m_component ); m_aliasName.Empty(); - m_oldRootName.Empty(); } m_component = new LIB_COMPONENT( *component ); @@ -171,7 +170,7 @@ bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_ALIAS* aEntry, CMP_LIBRARY* aLib return false; } - m_oldRootName = m_aliasName = aEntry->GetName(); + m_aliasName = aEntry->GetName(); m_unit = 1; m_convert = 1; @@ -454,7 +453,6 @@ All changes will be lost. Discard changes?" ) ) ) { SAFE_DELETE( m_component ); m_aliasName.Empty(); - m_oldRootName.Empty(); } DrawPanel->Refresh(); @@ -510,7 +508,6 @@ lost!\n\nClear the current component from the screen?" ) ) ) return; } - m_oldRootName.Empty(); LIB_COMPONENT* component = new LIB_COMPONENT( name ); component->GetReferenceField().m_Text = dlg.GetReference(); component->SetPartCount( dlg.GetPartCount() ); @@ -575,7 +572,6 @@ void LIB_EDIT_FRAME::SaveOnePartInMemory() LIB_COMPONENT* oldComponent; LIB_COMPONENT* Component; wxString msg; - wxString rootName; if( m_component == NULL ) { @@ -594,18 +590,12 @@ void LIB_EDIT_FRAME::SaveOnePartInMemory() GetBaseScreen()->ClrModify(); - // If the component root name was changed, that is still the name of the component - // in the library. - if( !m_oldRootName.IsEmpty() && m_oldRootName != m_component->GetName() ) - rootName = m_oldRootName; - else - rootName = m_component->GetName(); - - oldComponent = m_library->FindComponent( rootName ); + oldComponent = m_library->FindComponent( m_component->GetName() ); if( oldComponent != NULL ) { - msg.Printf( _( "Component \"%s\" exists. Change it?" ), GetChars( rootName ) ); + msg.Printf( _( "Component \"%s\" already exists. Change it?" ), + GetChars( m_component->GetName() ) ); if( !IsOK( this, msg ) ) return; diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index ef9d771d7f..442ba51785 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -85,6 +85,8 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, WinEDA_DrawFrame ) 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_NEW_PART, LIB_EDIT_FRAME::CreateNewLibraryPart ) + EVT_TOOL( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnCreateNewPartFromExisting ) + EVT_TOOL( ID_LIBEDIT_SELECT_PART, LIB_EDIT_FRAME::LoadOneLibraryPart ) EVT_TOOL( ID_LIBEDIT_SAVE_CURRENT_PART, LIB_EDIT_FRAME::Process_Special_Functions ) EVT_TOOL( wxID_UNDO, LIB_EDIT_FRAME::GetComponentFromUndoList ) @@ -115,6 +117,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, WinEDA_DrawFrame ) EVT_MENU( ID_LIBEDIT_GEN_SVG_FILE, LIB_EDIT_FRAME::OnPlotCurrentComponent ) EVT_MENU( ID_GENERAL_HELP, WinEDA_DrawFrame::GetKicadHelp ) + EVT_MENU( ID_COLORS_SETUP, LIB_EDIT_FRAME::OnColorConfig ) EVT_MENU( ID_CONFIG_REQ, LIB_EDIT_FRAME::InstallConfigFrame ) EVT_MENU( ID_CONFIG_SAVE, LIB_EDIT_FRAME::Process_Config ) EVT_MENU( ID_CONFIG_READ, LIB_EDIT_FRAME::Process_Config ) @@ -145,6 +148,7 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, WinEDA_DrawFrame ) EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_FIELDS, LIB_EDIT_FRAME::OnUpdateEditingPart ) EVT_UPDATE_UI( ID_LIBEDIT_CHECK_PART, LIB_EDIT_FRAME::OnUpdateEditingPart ) EVT_UPDATE_UI( ID_LIBEDIT_GET_FRAME_EDIT_PART, LIB_EDIT_FRAME::OnUpdateEditingPart ) + EVT_UPDATE_UI( ID_LIBEDIT_NEW_PART_FROM_EXISTING, LIB_EDIT_FRAME::OnUpdateEditingPart ) EVT_UPDATE_UI( wxID_UNDO, LIB_EDIT_FRAME::OnUpdateUndo ) EVT_UPDATE_UI( wxID_REDO, LIB_EDIT_FRAME::OnUpdateRedo ) EVT_UPDATE_UI( ID_LIBEDIT_SAVE_CURRENT_LIB, LIB_EDIT_FRAME::OnUpdateSaveCurrentLib ) @@ -1058,3 +1062,16 @@ void LIB_EDIT_FRAME::InstallDimensionsDialog( wxCommandEvent& event ) DIALOG_LIBEDIT_DIMENSIONS dlg( this ); dlg.ShowModal(); } + + +void LIB_EDIT_FRAME::OnCreateNewPartFromExisting( wxCommandEvent& event ) +{ + wxCHECK_RET( m_component != NULL, + wxT( "Cannot create new part from non-existant current part." ) ); + + INSTALL_DC( dc, DrawPanel ); + DrawPanel->CursorOff( &dc ); + EditField( &dc, &m_component->GetValueField() ); + DrawPanel->MouseToCursorSchema(); + DrawPanel->CursorOn( &dc ); +} diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index 5fc8da9651..d7c91b93ce 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -25,14 +25,11 @@ class DIALOG_LIB_EDIT_TEXT; */ class LIB_EDIT_FRAME : public WinEDA_DrawFrame { - LIB_COMPONENT* m_tempCopyComponent; ///< Temporary copy of current component during edit. - wxString m_oldRootName; ///< The actual pointer of the component loaded from - ///< a library. Do not do anything with this pointer. - ///< It is to be used for reference purposes only. + LIB_COMPONENT* m_tempCopyComponent; ///< Temporary copy of current component during edit. public: - WinEDAChoiceBox* m_SelpartBox; // a Box to select a part to edit (if any) - WinEDAChoiceBox* m_SelAliasBox; // a box to select the alias to edit (if any) + WinEDAChoiceBox* m_SelpartBox; // a Box to select a part to edit (if any) + WinEDAChoiceBox* m_SelAliasBox; // a box to select the alias to edit (if any) public: LIB_EDIT_FRAME( WinEDA_SchematicFrame* aParent, const wxString& title, @@ -58,6 +55,7 @@ public: void InstallConfigFrame( wxCommandEvent& event ); void InstallDimensionsDialog( wxCommandEvent& event ); + void OnColorConfig( wxCommandEvent& aEvent ); void Process_Config( wxCommandEvent& event ); void OnPlotCurrentComponent( wxCommandEvent& event ); void Process_Special_Functions( wxCommandEvent& event ); @@ -67,6 +65,7 @@ public: void OnSelectPart( wxCommandEvent& event ); void DeleteOnePart( wxCommandEvent& event ); void CreateNewLibraryPart( wxCommandEvent& event ); + void OnCreateNewPartFromExisting( wxCommandEvent& event ); void OnEditComponentProperties( wxCommandEvent& event ); void InstallFieldsEditorDialog( wxCommandEvent& event ); void LoadOneLibraryPart( wxCommandEvent& event ); diff --git a/eeschema/libfield.cpp b/eeschema/libfield.cpp index 2485a95056..d0be979c57 100644 --- a/eeschema/libfield.cpp +++ b/eeschema/libfield.cpp @@ -16,78 +16,137 @@ #include "template_fieldnames.h" -void LIB_EDIT_FRAME::EditField( wxDC* DC, LIB_FIELD* Field ) +void LIB_EDIT_FRAME::EditField( wxDC* DC, LIB_FIELD* aField ) { - wxString Text; + wxString text; wxString title; + wxString caption; wxString oldName; - if( Field == NULL ) + if( aField == NULL ) return; - title = Field->GetName(); - Text = Field->m_Text; + LIB_COMPONENT* parent = aField->GetParent(); - wxTextEntryDialog dlg( this, title + wxT( ":" ), _( "Edit field" ), Text ); - - if( dlg.ShowModal() != wxID_OK || dlg.GetValue() == Text ) - return; - - Text = dlg.GetValue(); - - Text.Replace( wxT( " " ), wxT( "_" ) ); - - if( ( Field->m_FieldId == REFERENCE || Field->m_FieldId == VALUE ) && Text.IsEmpty ( ) ) + // Editing the component value field is equivalent to creating a new component based + // on the current component. Set the dialog message to inform the user. + if( aField->m_FieldId == VALUE ) { - DisplayError( this, title + _( " field cannot be empty." ) ); + caption = _( "Component Name" ); + title = _( "Enter a name to create a new component based on this one." ); + } + else + { + caption = _( "Edit Field" ); + title.Printf( _( "Enter a new value for the %s field." ), + GetChars( aField->GetName().Lower() ) ); + } + + wxTextEntryDialog dlg( this, title, caption, aField->m_Text ); + + if( dlg.ShowModal() != wxID_OK || dlg.GetValue() == aField->m_Text ) + return; + + text = dlg.GetValue(); + + text.Replace( wxT( " " ), wxT( "_" ) ); + + if( ( aField->m_FieldId == REFERENCE || aField->m_FieldId == VALUE ) && text.IsEmpty ( ) ) + { + title.Printf( _( "A %s field cannot be empty." ), GetChars(aField->GetName().Lower() ) ); + DisplayError( this, title ); return; } - wxString fieldText = Field->GetFullText( m_unit ); - LIB_COMPONENT* parent = Field->GetParent(); + wxString fieldText = aField->GetFullText( m_unit ); - /* If the value field is changed, this is equivalent to creating a new - * component from the old one. Check for an existing library entry of - * this "new" component and change the value only if there is no existing - * entry with the same name. + /* If the value field is changed, this is equivalent to creating a new component from + * the old one. Rename the component and remove any conflicting aliases to prevent name + * errors when updating the library. */ - if( Field->m_FieldId == VALUE && Text != Field->m_Text ) + if( aField->m_FieldId == VALUE ) { wxString msg; - /* Test for an existing name in the current components alias list and in - * the current library. - */ - if( ( parent->HasAlias( Text ) && !parent->GetAlias( Text )->IsRoot() ) - || ( m_library && m_library->FindEntry( Text ) != NULL ) ) + // Test the current library for name conflicts. + if( m_library->FindEntry( text ) != NULL ) { - msg.Printf( _( "The field name <%s> conflicts with an existing \ -entry in the component library <%s>.\nPlease choose another name that does \ -not conflict with any library entries." ), - GetChars( Text ), + msg.Printf( _( "The name <%s> conflicts with an existing entry in the component \ +library <%s>.\n\nDo you wish to replace the current component in library with this one?" ), + GetChars( text ), GetChars( m_library->GetName() ) ); - DisplayError( this, msg ); - return; + + int rsp = wxMessageBox( msg, _( "Confirm" ), + wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT, this ); + + if( rsp == wxNO ) + return; } + + // Test the current component for name conflicts. + if( parent->HasAlias( text ) ) + { + msg.Printf( _( "The current component already has an alias named <%s>.\n\nDo you \ +wish to remove this alias from the component?" ), + GetChars( text ), + GetChars( m_library->GetName() ) ); + + int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this ); + + if( rsp == wxNO ) + return; + + parent->RemoveAlias( text ); + } + + parent->SetName( text ); + + // Test the library for any conflicts with the any aliases in the current component. + if( parent->GetAliasCount() > 1 && m_library->Conflicts( parent ) ) + { + msg.Printf( _( "The new component contains alias names that conflict with entries \ +in the component library <%s>.\n\nDo you wish to remove all of the conflicting aliases from \ +this component?" ), + GetChars( m_library->GetName() ) ); + + int rsp = wxMessageBox( msg, _( "Confirm" ), wxYES_NO | wxICON_QUESTION, this ); + + if( rsp == wxNO ) + { + parent->SetName( fieldText ); + return; + } + + wxArrayString aliases = parent->GetAliasNames( false ); + + for( size_t i = 0; i < aliases.GetCount(); i++ ) + { + if( m_library->FindEntry( aliases[ i ] ) != NULL ) + parent->RemoveAlias( aliases[ i ] ); + } + } + + if( !parent->HasAlias( m_aliasName ) ) + m_aliasName = text; + } + else + { + aField->SetText( text ); } - if( Field->m_FieldId == VALUE && Field->m_Text == m_aliasName ) - m_aliasName = Text; - - if( !Field->InEditMode() ) + if( !aField->InEditMode() ) { SaveCopyInUndoList( parent ); - ( (LIB_DRAW_ITEM*) Field )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, - &fieldText, DefaultTransform ); + ( (LIB_DRAW_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, + &fieldText, DefaultTransform ); } - Field->SetText( Text ); - if( !Field->InEditMode() ) + if( !aField->InEditMode() ) { - fieldText = Field->GetFullText( m_unit ); - ( (LIB_DRAW_ITEM*) Field )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, - &fieldText, DefaultTransform ); + fieldText = aField->GetFullText( m_unit ); + ( (LIB_DRAW_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, + &fieldText, DefaultTransform ); } OnModify(); diff --git a/eeschema/protos.h b/eeschema/protos.h index 0174832981..bab205d2ab 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -188,7 +188,6 @@ void RedrawOneStruct( WinEDA_DrawPanel* panel, /**************/ void SeedLayers(); EDA_Colors ReturnLayerColor( int Layer ); -void DisplayColorSetupFrame( WinEDA_DrawFrame* parent, const wxPoint& pos ); /**************/ diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 159337332a..3946216700 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -75,7 +75,7 @@ BEGIN_EVENT_TABLE( WinEDA_SchematicFrame, WinEDA_DrawFrame ) ID_PREFERENCES_HOTKEY_END, WinEDA_SchematicFrame::Process_Config ) - EVT_TOOL( ID_COLORS_SETUP, WinEDA_SchematicFrame::Process_Config ) + EVT_MENU( ID_COLORS_SETUP, WinEDA_SchematicFrame::OnColorConfig ) EVT_TOOL( ID_OPTIONS_SETUP, WinEDA_SchematicFrame::OnSetOptions ) EVT_MENU_RANGE( ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, diff --git a/eeschema/tool_lib.cpp b/eeschema/tool_lib.cpp index b1c07019a9..3640cc898b 100644 --- a/eeschema/tool_lib.cpp +++ b/eeschema/tool_lib.cpp @@ -119,6 +119,10 @@ void LIB_EDIT_FRAME::ReCreateHToolbar() wxBitmap( import_cmp_from_lib_xpm ), _( "Load component to edit from the current lib" ) ); + m_HToolBar->AddTool( ID_LIBEDIT_NEW_PART_FROM_EXISTING, wxEmptyString, + wxBitmap( copyComponent_xpm ), + _( "Create a new component from the current one" ) ); + m_HToolBar->AddTool( ID_LIBEDIT_SAVE_CURRENT_PART, wxEmptyString, wxBitmap( save_part_in_mem_xpm ), _( "Update current component in current library" ) ); diff --git a/include/bitmaps.h b/include/bitmaps.h index 2e51d5c12c..e1491902ec 100644 --- a/include/bitmaps.h +++ b/include/bitmaps.h @@ -60,6 +60,7 @@ extern const char* component_select_unit_xpm[]; extern const char* config_xpm[]; extern const char* copper_layers_setup_xpm[]; extern const char* copyblock_xpm[]; +extern const char* copyComponent_xpm[]; extern const char* copy_button[]; extern const char* cursor_shape_xpm[]; extern const char* cursor_xpm[]; diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 724febb55f..6476a3e760 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -102,6 +102,7 @@ public: void OnCloseWindow( wxCloseEvent& Event ); void Process_Special_Functions( wxCommandEvent& event ); + void OnColorConfig( wxCommandEvent& aEvent ); void Process_Config( wxCommandEvent& event ); void GeneralControle( wxDC* DC, wxPoint MousePositionInPixels );