diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index fe85ab80db..82cb057440 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -22,7 +22,6 @@ set(EESCHEMA_SRCS class_library.cpp class_marker_sch.cpp class_netlist_object.cpp - class_pin.cpp class_sch_cmp_field.cpp class_sch_component.cpp class_schematic_items.cpp @@ -99,6 +98,7 @@ set(EESCHEMA_SRCS lib_draw_item.cpp lib_export.cpp lib_field.cpp + lib_pin.cpp lib_polyline.cpp lib_rectangle.cpp lib_text.cpp diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index 7f460f778f..a3e96cc363 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -15,7 +15,7 @@ #include "class_library.h" #include "protos.h" #include "netlist.h" -#include "class_pin.h" +#include "lib_pin.h" static int AddComponentsInSheetToList( std::vector & aComponentsList, diff --git a/eeschema/block.cpp b/eeschema/block.cpp index 1e07d72682..189cebcecc 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -14,7 +14,7 @@ #include "general.h" #include "class_marker_sch.h" #include "class_library.h" -#include "class_pin.h" +#include "lib_pin.h" #include "protos.h" diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index da52cdea58..c743e41eaf 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -10,7 +10,7 @@ #include "program.h" #include "lib_draw_item.h" -#include "class_pin.h" +#include "lib_pin.h" #include "general.h" #include "protos.h" diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 98a910ce29..2acd4b2af4 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -14,12 +14,13 @@ #include "protos.h" #include "class_library.h" #include "class_libentry.h" -#include "class_pin.h" +#include "lib_pin.h" #include "lib_arc.h" #include "lib_bezier.h" #include "lib_circle.h" #include "lib_polyline.h" #include "lib_rectangle.h" +#include "lib_text.h" #include @@ -293,6 +294,14 @@ wxString LIB_COMPONENT::ReturnSubReference( int aUnit ) } +void LIB_COMPONENT::SetName( const wxString& aName ) +{ + CMP_LIB_ENTRY::SetName( aName ); + GetValueField().m_Text = aName; + m_aliases[0]->SetName( aName ); +} + + void LIB_COMPONENT::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDc, const wxPoint& aOffset, int aMulti, int aConvert, int aDrawMode, int aColor, const TRANSFORM& aTransform, bool aShowPinText, bool aDrawFields, bool aOnlySelected ) diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 97cf776681..2ee9f87401 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -13,6 +13,7 @@ class CMP_LIBRARY; class LIB_ALIAS; +class LIB_FIELD; /** @@ -180,11 +181,7 @@ public: } - virtual void SetName( const wxString& aName ) - { - CMP_LIB_ENTRY::SetName( aName ); - GetValueField().m_Text = aName; - } + virtual void SetName( const wxString& aName ); virtual wxString GetLibraryName(); diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index 24563a214f..ba7d471729 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -342,7 +342,6 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* aOldComponent, { wxASSERT( aOldComponent != NULL ); wxASSERT( aNewComponent != NULL ); - wxASSERT( aOldComponent->GetName().CmpNoCase( aNewComponent->GetName() )== 0 ); /* Remove the old root component. The component will automatically be deleted * when all it's aliases are deleted. Do not place any code that accesses @@ -980,8 +979,7 @@ LIB_COMPONENT* CMP_LIBRARY::FindLibraryComponent( const wxString& aName, } -CMP_LIB_ENTRY* CMP_LIBRARY::FindLibraryEntry( const wxString& aName, - const wxString& aLibraryName ) +CMP_LIB_ENTRY* CMP_LIBRARY::FindLibraryEntry( const wxString& aName, const wxString& aLibraryName ) { CMP_LIB_ENTRY* entry = NULL; diff --git a/eeschema/class_netlist_object.h b/eeschema/class_netlist_object.h index def2be394a..9147151a32 100644 --- a/eeschema/class_netlist_object.h +++ b/eeschema/class_netlist_object.h @@ -6,7 +6,7 @@ #ifndef _CLASS_NETLIST_OBJECT_H_ #define _CLASS_NETLIST_OBJECT_H_ -#include "class_pin.h" // LIB_PIN::ReturnPinStringNum( m_PinNum ) +#include "lib_pin.h" // LIB_PIN::ReturnPinStringNum( m_PinNum ) /* Type of Net objects (wires, labels, pins...) */ diff --git a/eeschema/class_sch_component.cpp b/eeschema/class_sch_component.cpp index 1b61cb0487..dfc69fc5c5 100644 --- a/eeschema/class_sch_component.cpp +++ b/eeschema/class_sch_component.cpp @@ -16,7 +16,8 @@ #include "class_library.h" #include "dialog_schematic_find.h" #include "lib_rectangle.h" -#include "class_pin.h" +#include "lib_pin.h" +#include "lib_text.h" #include diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index 02bdaece6f..858faf8051 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -15,7 +15,7 @@ #include "libeditframe.h" #include "viewlib_frame.h" #include "lib_draw_item.h" -#include "class_pin.h" +#include "lib_pin.h" #include "class_marker_sch.h" diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index b07554cda4..ac85a666c6 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -12,7 +12,7 @@ #include "eeschema_id.h" #include "protos.h" #include "lib_draw_item.h" -#include "class_pin.h" +#include "lib_pin.h" /***************************************************************/ diff --git a/eeschema/dangling_ends.cpp b/eeschema/dangling_ends.cpp index 21ec6d5d2f..59b766da3f 100644 --- a/eeschema/dangling_ends.cpp +++ b/eeschema/dangling_ends.cpp @@ -11,7 +11,7 @@ #include "netlist.h" #include "protos.h" #include "class_library.h" -#include "class_pin.h" +#include "lib_pin.h" enum End_Type { diff --git a/eeschema/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialog_edit_libentry_fields_in_lib.cpp index 2970c3fe22..23dbd6dd23 100644 --- a/eeschema/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialog_edit_libentry_fields_in_lib.cpp @@ -218,16 +218,16 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnOKButtonClick( wxCommandEvent& event if( !copyPanelToSelectedField() ) return; - /* A new name could be entered in VALUE field. - * Must not be an existing alias name in alias list box */ - wxString* newvalue = &m_FieldsBuf[VALUE].m_Text; + /* If a new name entered in the VALUE field, that it not an existing alias name + * or root alias of the component */ + wxString newvalue = m_FieldsBuf[VALUE].m_Text; - if( m_LibEntry->HasAlias( *newvalue ) ) + if( m_LibEntry->HasAlias( newvalue ) && !m_LibEntry->GetAlias( newvalue )->IsRoot() ) { wxString msg; msg.Printf( _( "A new name is entered for this component\n\ An alias %s already exists!\nCannot update this component" ), - newvalue->GetData() ); + GetChars( newvalue ) ); DisplayError( this, msg ); return; } @@ -249,12 +249,11 @@ An alias %s already exists!\nCannot update this component" ), } #if defined(DEBUG) - for( unsigned i=0; iSetFields( m_FieldsBuf ); // We need to keep the name and the value the same at the moment! - SetName(m_LibEntry->GetValueField().m_Text); + SetName( m_LibEntry->GetValueField().m_Text ); - m_Parent->OnModify( ); + m_Parent->OnModify(); EndModal( 0 ); } diff --git a/eeschema/dialog_erc.cpp b/eeschema/dialog_erc.cpp index d0b8680344..793445bb99 100644 --- a/eeschema/dialog_erc.cpp +++ b/eeschema/dialog_erc.cpp @@ -15,7 +15,7 @@ #include "general.h" #include "netlist.h" #include "class_marker_sch.h" -#include "class_pin.h" +#include "lib_pin.h" #include "protos.h" #include "dialog_erc.h" diff --git a/eeschema/dialog_sch_find.fbp b/eeschema/dialog_sch_find.fbp index be797093ff..1cdea1ef18 100644 --- a/eeschema/dialog_sch_find.fbp +++ b/eeschema/dialog_sch_find.fbp @@ -93,11 +93,11 @@ leftSizer wxVERTICAL none - + 6 wxALL|wxEXPAND - 1 - + 0 + 2 wxBOTH @@ -109,11 +109,11 @@ none 3 3 - + 6 wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT 0 - + 1 @@ -165,11 +165,11 @@ - + 6 wxALIGN_CENTER_VERTICAL|wxEXPAND|wxLEFT|wxRIGHT 0 - + @@ -224,11 +224,11 @@ OnUpdateDrcUI - + 5 wxALIGN_CENTER_VERTICAL|wxALL 0 - + 1 @@ -280,11 +280,11 @@ - + 5 wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND 0 - + @@ -339,11 +339,11 @@ OnUpdateDrcUI - + 5 0 - + 1 @@ -395,20 +395,20 @@ - + 5 wxEXPAND 1 - + directionSizer wxVERTICAL none - + 3 wxALL 0 - + 1 @@ -461,11 +461,11 @@ - + 3 wxALL 0 - + 1 @@ -522,11 +522,11 @@ - + 6 wxALL 0 - + 0 @@ -579,11 +579,11 @@ OnUpdateWholeWordUI - + 6 wxBOTTOM|wxLEFT|wxRIGHT 0 - + 0 @@ -636,11 +636,11 @@ - + 6 wxBOTTOM|wxLEFT|wxRIGHT 0 - + 0 @@ -693,11 +693,11 @@ OnUpdateWildcardUI - + 6 wxBOTTOM|wxLEFT|wxRIGHT 0 - + 1 @@ -750,11 +750,11 @@ - + 6 - wxALL + wxBOTTOM|wxLEFT|wxRIGHT 0 - + 0 @@ -807,11 +807,11 @@ - + 6 wxBOTTOM|wxRIGHT|wxLEFT 0 - + 0 @@ -864,11 +864,11 @@ - + 6 - wxALL + wxBOTTOM|wxLEFT|wxRIGHT 0 - + 0 @@ -932,11 +932,11 @@ rightSizer wxVERTICAL none - + 6 wxALL|wxEXPAND 0 - + 1 @@ -989,11 +989,11 @@ OnUpdateFindUI - + 5 wxALL 0 - + 1 @@ -1046,11 +1046,11 @@ - + 5 wxALL 0 - + 1 @@ -1103,11 +1103,11 @@ - + 6 wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND 0 - + 1 diff --git a/eeschema/dialog_schematic_find_base.cpp b/eeschema/dialog_schematic_find_base.cpp index 27357f0513..a4dedcb0bc 100644 --- a/eeschema/dialog_schematic_find_base.cpp +++ b/eeschema/dialog_schematic_find_base.cpp @@ -65,7 +65,7 @@ DIALOG_SCH_FIND_BASE::DIALOG_SCH_FIND_BASE( wxWindow* parent, wxWindowID id, con leftGridSizer->Add( directionSizer, 1, wxEXPAND, 5 ); - leftSizer->Add( leftGridSizer, 1, wxALL|wxEXPAND, 6 ); + leftSizer->Add( leftGridSizer, 0, wxALL|wxEXPAND, 6 ); m_checkWholeWord = new wxCheckBox( this, wxID_ANY, _("Match &whole word"), wxDefaultPosition, wxDefaultSize, 0 ); leftSizer->Add( m_checkWholeWord, 0, wxALL, 6 ); @@ -81,13 +81,13 @@ DIALOG_SCH_FIND_BASE::DIALOG_SCH_FIND_BASE( wxWindow* parent, wxWindowID id, con leftSizer->Add( m_checkWrap, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 ); m_checkAllFields = new wxCheckBox( this, wxID_ANY, _("Search all component &fields"), wxDefaultPosition, wxDefaultSize, 0 ); - leftSizer->Add( m_checkAllFields, 0, wxALL, 6 ); + leftSizer->Add( m_checkAllFields, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 ); m_checkAllPins = new wxCheckBox( this, wxID_ANY, _("Search all pin names and numbers"), wxDefaultPosition, wxDefaultSize, 0 ); leftSizer->Add( m_checkAllPins, 0, wxBOTTOM|wxRIGHT|wxLEFT, 6 ); m_checkCurrentSheetOnly = new wxCheckBox( this, wxID_ANY, _("Search the current sheet on&ly"), wxDefaultPosition, wxDefaultSize, 0 ); - leftSizer->Add( m_checkCurrentSheetOnly, 0, wxALL, 6 ); + leftSizer->Add( m_checkCurrentSheetOnly, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 ); mainSizer->Add( leftSizer, 1, wxALL|wxEXPAND, 6 ); diff --git a/eeschema/edit_graphic_bodyitem_text.cpp b/eeschema/edit_graphic_bodyitem_text.cpp index 3c5f1e723e..de154659c3 100644 --- a/eeschema/edit_graphic_bodyitem_text.cpp +++ b/eeschema/edit_graphic_bodyitem_text.cpp @@ -14,6 +14,7 @@ #include "protos.h" #include "libeditframe.h" #include "class_libentry.h" +#include "lib_text.h" #include "dialog_bodygraphictext_properties_base.h" @@ -145,20 +146,18 @@ void Dialog_BodyGraphicText_Properties::OnOkClick( wxCommandEvent& event ) wxString Line; Line = m_TextValue->GetValue(); - m_Parent->m_textOrientation = - m_Orient->GetValue() ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ; + m_Parent->m_textOrientation = m_Orient->GetValue() ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ; wxString msg = m_TextSize->GetValue(); - m_Parent->m_textSize = ReturnValueFromString( g_UserUnit, msg, - m_Parent->m_InternalUnits ); + m_Parent->m_textSize = ReturnValueFromString( g_UserUnit, msg, m_Parent->m_InternalUnits ); m_Parent->m_drawSpecificConvert = m_CommonConvert->GetValue() ? false : true; m_Parent->m_drawSpecificUnit = m_CommonUnit->GetValue() ? false : true; if ( m_GraphicText ) { if ( ! Line.IsEmpty() ) - m_GraphicText->m_Text = Line; + m_GraphicText->SetText( Line ); else - m_GraphicText->m_Text = wxT("[null]"); + m_GraphicText->SetText( wxT( "[null]" ) ); m_GraphicText->m_Size.x = m_GraphicText->m_Size.y = m_Parent->m_textSize; m_GraphicText->m_Orient = m_Parent->m_textOrientation; @@ -224,14 +223,12 @@ void Dialog_BodyGraphicText_Properties::OnOkClick( wxCommandEvent& event ) void WinEDA_LibeditFrame::EditSymbolText( wxDC* DC, LIB_DRAW_ITEM* DrawItem ) { - int DrawMode = g_XorMode; - if ( ( DrawItem == NULL ) || ( DrawItem->Type() != COMPONENT_GRAPHIC_TEXT_DRAW_TYPE ) ) return; /* Deleting old text. */ - if( DC ) - DrawItem->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, DrawMode, NULL, DefaultTransform ); + if( DC && !DrawItem->InEditMode() ) + DrawItem->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, NULL, DefaultTransform ); Dialog_BodyGraphicText_Properties * frame = @@ -241,11 +238,7 @@ void WinEDA_LibeditFrame::EditSymbolText( wxDC* DC, LIB_DRAW_ITEM* DrawItem ) OnModify(); /* Display new text. */ - if( DC ) - { - if ( ( DrawItem->m_Flags & IS_MOVED ) == 0 ) - DrawMode = GR_DEFAULT_DRAWMODE; - - DrawItem->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, DrawMode, NULL, DefaultTransform ); - } + if( DC && !DrawItem->InEditMode() ) + DrawItem->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, GR_DEFAULT_DRAWMODE, NULL, + DefaultTransform ); } diff --git a/eeschema/erc.cpp b/eeschema/erc.cpp index 2647b8cc80..0314a344f4 100644 --- a/eeschema/erc.cpp +++ b/eeschema/erc.cpp @@ -14,7 +14,7 @@ #include "general.h" #include "netlist.h" #include "class_marker_sch.h" -#include "class_pin.h" +#include "lib_pin.h" #include "protos.h" #include "erc.h" diff --git a/eeschema/find.cpp b/eeschema/find.cpp index 3dcd07855f..1b6bd84089 100644 --- a/eeschema/find.cpp +++ b/eeschema/find.cpp @@ -20,7 +20,7 @@ #include "class_marker_sch.h" #include "protos.h" #include "class_library.h" -#include "class_pin.h" +#include "lib_pin.h" #include "kicad_device_context.h" diff --git a/eeschema/lib_arc.h b/eeschema/lib_arc.h index 73977703b8..5f9edfcd69 100644 --- a/eeschema/lib_arc.h +++ b/eeschema/lib_arc.h @@ -79,6 +79,7 @@ public: LIB_ARC( LIB_COMPONENT * aParent ); LIB_ARC( const LIB_ARC& aArc ); ~LIB_ARC() { } + virtual wxString GetClass() const { return wxT( "LIB_ARC" ); diff --git a/eeschema/lib_draw_item.h b/eeschema/lib_draw_item.h index c12e190832..bc72cba53c 100644 --- a/eeschema/lib_draw_item.h +++ b/eeschema/lib_draw_item.h @@ -128,11 +128,6 @@ public: wxString m_typeName; ///< Name of object displayed in the message panel. public: - LIB_DRAW_ITEM* Next() - { - return (LIB_DRAW_ITEM*) Pnext; - } - LIB_DRAW_ITEM( KICAD_T aType, LIB_COMPONENT* aComponent = NULL, @@ -428,139 +423,4 @@ protected: }; -/*********************************************/ -/* Graphic Body Item: Text */ -/* This is only a graphic text. */ -/* Fields like Ref , value... are not Text, */ -/* they are a separate class */ -/*********************************************/ -class LIB_TEXT : public LIB_DRAW_ITEM, public EDA_TextStruct -{ - int m_savedOrientation; ///< Temporary storage for orientation when editing. - bool m_rotate; ///< Flag to indicate a rotation occurred while editing. - - /** - * Draw the polyline. - */ - void drawGraphic( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, - int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform ); - - /** - * See LIB_DRAW_ITEM::saveAttributes(). - */ - void saveAttributes(); - - /** - * See LIB_DRAW_ITEM::restoreAttributes(). - */ - void restoreAttributes(); - - /** - * Calculate the text attributes ralative to \a aPosition while editing. - * - * @param aPosition - Edit position in drawing units. - */ - void calcEdit( const wxPoint& aPosition ); - -public: - LIB_TEXT( LIB_COMPONENT * aParent ); - LIB_TEXT( const LIB_TEXT& aText ); - ~LIB_TEXT() { } - - virtual wxString GetClass() const - { - return wxT( "LIB_TEXT" ); - } - - /** - * Write text object out to a FILE in "*.lib" format. - * - * @param aFile - The FILE to write to. - * @return - true if success writing else false. - */ - virtual bool Save( FILE* aFile ); - virtual bool Load( char* aLine, wxString& aErrorMsg ); - - /** - * Test if the given point is within the bounds of this object. - * - * @param refPos - A wxPoint to test - * @return - true if a hit, else false - */ - virtual bool HitTest( const wxPoint& refPos ); - - /** - * @param aPosRef = a wxPoint to test, in eeschema coordinates - * @param aThreshold = max distance to a segment - * @param aTransform = the transform matrix - * @return true if the point aPosRef is near a segment - */ - virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); - - /** - * Test if the given rectangle intersects this object. - * - * For now, an ending point must be inside this rect. - * - * @param aRect - the given EDA_Rect - * @return - true if a hit, else false - */ - virtual bool HitTest( EDA_Rect& aRect ) - { - return TextHitTest( aRect ); - } - - /** - * @return the size of the "pen" that be used to draw or plot this item - */ - virtual int GetPenSize( ); - - virtual void DisplayInfo( WinEDA_DrawFrame* aFrame ); - - virtual EDA_Rect GetBoundingBox(); - - void Rotate(); - - /** - * See LIB_DRAW_ITEM::BeginEdit(). - */ - void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ); - - /** - * See LIB_DRAW_ITEM::ContinueEdit(). - */ - bool ContinueEdit( const wxPoint aNextPoint ); - - /** - * See LIB_DRAW_ITEM::AbortEdit(). - */ - void EndEdit( const wxPoint& aPosition, bool aAbort = false ); - -protected: - virtual LIB_DRAW_ITEM* DoGenCopy(); - - /** - * Provide the text draw object specific comparison. - * - * The sort order is as follows: - * - Text string, case insensitive compare. - * - Text horizontal (X) position. - * - Text vertical (Y) position. - * - Text width. - * - Text height. - */ - virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const; - - virtual void DoOffset( const wxPoint& aOffset ); - virtual bool DoTestInside( EDA_Rect& aRect ); - virtual void DoMove( const wxPoint& aPosition ); - virtual wxPoint DoGetPosition() { return m_Pos; } - virtual void DoMirrorHorizontal( const wxPoint& aCenter ); - virtual void DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, - const TRANSFORM& aTransform ); - virtual int DoGetWidth() { return m_Width; } - virtual void DoSetWidth( int aWidth ) { m_Width = aWidth; } -}; - - #endif // _LIB_DRAW_ITEM_H_ diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index a8340d6aa3..5f2dc70a72 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -18,10 +18,7 @@ #include "protos.h" #include "class_libentry.h" #include "transform.h" - -#include -#include -#include +#include "lib_field.h" /*******************/ @@ -85,6 +82,7 @@ void LIB_FIELD::Init( int id ) m_typeName = _( "Field" ); m_Orient = TEXT_ORIENT_HORIZ; m_rotate = false; + m_updateText = false; // fields in RAM must always have names, because we are trying to get // less dependent on field ids and more dependent on names. @@ -348,6 +346,7 @@ void LIB_FIELD::drawGraphic( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& void LIB_FIELD::saveAttributes() { m_savedPos = m_Pos; + m_savedText = m_Text; m_savedOrientation = m_Orient; } @@ -355,6 +354,7 @@ void LIB_FIELD::saveAttributes() void LIB_FIELD::restoreAttributes() { m_Pos = m_savedPos; + m_Text = m_savedText; m_Orient = m_savedOrientation; } @@ -590,6 +590,68 @@ void LIB_FIELD::Rotate() } +wxString LIB_FIELD::GetName() +{ + wxString name; + + switch( m_FieldId ) + { + case REFERENCE: + name = _( "Reference" ); + break; + + case VALUE: + name = _( "Value" ); + break; + + case FOOTPRINT: + name = _( "Footprint" ); + break; + + case DATASHEET: + name = _( "Datasheet" ); + break; + + default: + if( m_Name.IsEmpty() ) + name.Printf( _( "Field%d" ), m_FieldId ); + else + name = m_Name; + } + + return name; +} + + +void LIB_FIELD::SetText( const wxString& aText ) +{ + if( aText == m_Text ) + return; + + wxString oldName = m_Text; + + if( m_FieldId == VALUE && m_Parent != NULL ) + { + LIB_COMPONENT* parent = GetParent(); + + // Set the parent component and root alias to the new name. + if( parent->GetName().CmpNoCase( aText ) != 0 ) + parent->SetName( aText ); + } + + if( InEditMode() ) + { + m_Text = oldName; + m_savedText = aText; + m_updateText = true; + } + else + { + m_Text = aText; + } +} + + void LIB_FIELD::BeginEdit( int aEditMode, const wxPoint aPosition ) { wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED ) ) != 0, @@ -629,6 +691,8 @@ void LIB_FIELD::EndEdit( const wxPoint& aPosition, bool aAbort ) restoreAttributes(); m_Flags = 0; + m_rotate = false; + m_updateText = false; SetEraseLastDrawItem( false ); } @@ -641,6 +705,12 @@ void LIB_FIELD::calcEdit( const wxPoint& aPosition ) m_rotate = false; } + if( m_updateText ) + { + EXCHG( m_Text, m_savedText ); + m_updateText = false; + } + if( m_Flags == IS_NEW ) { m_Pos = aPosition; diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 3848f188c9..7aa2794beb 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -18,8 +18,10 @@ */ class LIB_FIELD : public LIB_DRAW_ITEM, public EDA_TextStruct { - int m_savedOrientation; + wxString m_savedText; ///< Temporary storage for the string when edition. + int m_savedOrientation; ///< Temporary storage for orientation when editing. bool m_rotate; ///< Flag to indicate a rotation occurred while editing. + bool m_updateText; ///< Flag to indicate text change occurred while editing. /** * Draw the field. @@ -51,10 +53,6 @@ public: public: - LIB_FIELD* Next() const { return (LIB_FIELD*) Pnext; } - LIB_FIELD* Back() const { return (LIB_FIELD*) Pback; } - - LIB_FIELD( int idfield = 2 ); LIB_FIELD( LIB_COMPONENT * aParent, int idfield = 2 ); LIB_FIELD( const LIB_FIELD& field ); @@ -70,6 +68,17 @@ public: */ void Init( int idfield ); + /** + * Returns the field name. + * + * The first four field IDs are reserved and therefore always return their respective + * names. The user definable fields will return FieldN where N is the ID of the field + * when the m_Name member is empty. + * + * @return Name of the field. + */ + wxString GetName(); + /** Function GetPenSize virtual pure * @return the size of the "pen" that be used to draw or plot this item */ @@ -174,6 +183,19 @@ public: void Rotate(); + /** + * Sets the field text to \a aText. + * + * This method does more than juat set the set the field text. There are special + * cases when changing the text string alone is not enough. If the field is the + * value field, the parent component's name is changed as well. If the field is + * being moved, the name change must be delayed until the next redraw to prevent + * drawing artifacts. + * + * @param aText - New text value. + */ + void SetText( const wxString& aText ); + protected: virtual LIB_DRAW_ITEM* DoGenCopy(); diff --git a/eeschema/class_pin.cpp b/eeschema/lib_pin.cpp similarity index 99% rename from eeschema/class_pin.cpp rename to eeschema/lib_pin.cpp index 9f3786a8f1..c41e6a58e2 100644 --- a/eeschema/class_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -1,12 +1,11 @@ -/*****************/ -/* class_pin.cpp */ -/*****************/ +/***************/ +/* lib_pin.cpp */ +/***************/ #include "fctsys.h" #include "appl_wxstruct.h" #include "gr_basic.h" #include "trigo.h" -#include "common.h" #include "class_drawpanel.h" #include "drawtxt.h" #include "plot_common.h" @@ -16,7 +15,7 @@ #include "protos.h" #include "libeditframe.h" #include "class_libentry.h" -#include "class_pin.h" +#include "lib_pin.h" #include "transform.h" #include "bitmaps.h" diff --git a/eeschema/class_pin.h b/eeschema/lib_pin.h similarity index 99% rename from eeschema/class_pin.h rename to eeschema/lib_pin.h index 79d8b38bbf..b255d657c8 100644 --- a/eeschema/class_pin.h +++ b/eeschema/lib_pin.h @@ -116,9 +116,6 @@ public: LIB_PIN( const LIB_PIN& aPin ); ~LIB_PIN() { } - LIB_PIN* Next() const { return (LIB_PIN*) Pnext; } - LIB_PIN* Back() const { return (LIB_PIN*) Pback; } - virtual wxString GetClass() const { return wxT( "LIB_PIN" ); diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 2b5c0886c3..cfd2c8a2f5 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -20,15 +20,17 @@ #include "general.h" #include "protos.h" #include "transform.h" +#include "lib_text.h" LIB_TEXT::LIB_TEXT(LIB_COMPONENT * aParent) : LIB_DRAW_ITEM( COMPONENT_GRAPHIC_TEXT_DRAW_TYPE, aParent ), EDA_TextStruct() { - m_Size = wxSize( 50, 50 ); - m_typeName = _( "Text" ); - m_rotate = false; + m_Size = wxSize( 50, 50 ); + m_typeName = _( "Text" ); + m_rotate = false; + m_updateText = false; } @@ -361,6 +363,7 @@ void LIB_TEXT::drawGraphic( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& void LIB_TEXT::saveAttributes() { m_savedPos = m_Pos; + m_savedText = m_Text; m_savedOrientation = m_Orient; } @@ -368,6 +371,7 @@ void LIB_TEXT::saveAttributes() void LIB_TEXT::restoreAttributes() { m_Pos = m_savedPos; + m_Text = m_savedText; m_Orient = m_savedOrientation; } @@ -423,6 +427,23 @@ void LIB_TEXT::Rotate() } +void LIB_TEXT::SetText( const wxString& aText ) +{ + if( aText == m_Text ) + return; + + if( InEditMode() ) + { + m_savedText = aText; + m_updateText = true; + } + else + { + m_Text = aText; + } +} + + void LIB_TEXT::BeginEdit( int aEditMode, const wxPoint aPosition ) { wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED ) ) != 0, @@ -462,6 +483,8 @@ void LIB_TEXT::EndEdit( const wxPoint& aPosition, bool aAbort ) restoreAttributes(); m_Flags = 0; + m_rotate = false; + m_updateText = false; SetEraseLastDrawItem( false ); } @@ -474,6 +497,12 @@ void LIB_TEXT::calcEdit( const wxPoint& aPosition ) m_rotate = false; } + if( m_updateText ) + { + EXCHG( m_Text, m_savedText ); + m_updateText = false; + } + if( m_Flags == IS_NEW ) { SetEraseLastDrawItem(); diff --git a/eeschema/lib_text.h b/eeschema/lib_text.h new file mode 100644 index 0000000000..1bb901801e --- /dev/null +++ b/eeschema/lib_text.h @@ -0,0 +1,158 @@ + +#ifndef _LIB_TEXT_H_ +#define _LIB_TEXT_H_ + + +#include "lib_draw_item.h" + + +/*********************************************/ +/* Graphic Body Item: Text */ +/* This is only a graphic text. */ +/* Fields like Ref , value... are not Text, */ +/* they are a separate class */ +/*********************************************/ +class LIB_TEXT : public LIB_DRAW_ITEM, public EDA_TextStruct +{ + wxString m_savedText; ///< Temporary storage for the string when edition. + int m_savedOrientation; ///< Temporary storage for orientation when editing. + bool m_rotate; ///< Flag to indicate a rotation occurred while editing. + bool m_updateText; ///< Flag to indicate text change occurred while editing. + + /** + * Draw the polyline. + */ + void drawGraphic( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, + int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform ); + + /** + * See LIB_DRAW_ITEM::saveAttributes(). + */ + void saveAttributes(); + + /** + * See LIB_DRAW_ITEM::restoreAttributes(). + */ + void restoreAttributes(); + + /** + * Calculate the text attributes ralative to \a aPosition while editing. + * + * @param aPosition - Edit position in drawing units. + */ + void calcEdit( const wxPoint& aPosition ); + +public: + LIB_TEXT( LIB_COMPONENT * aParent ); + LIB_TEXT( const LIB_TEXT& aText ); + ~LIB_TEXT() { } + + virtual wxString GetClass() const + { + return wxT( "LIB_TEXT" ); + } + + /** + * Sets the text item string to \a aText. + * + * This method does more than juat set the set the text string. There are special + * cases when changing the text string alone is not enough. If the text item is + * being moved, the name change must be delayed until the next redraw to prevent + * drawing artifacts. + * + * @param aText - New text value. + */ + void SetText( const wxString& aText ); + + /** + * Write text object out to a FILE in "*.lib" format. + * + * @param aFile - The FILE to write to. + * @return - true if success writing else false. + */ + virtual bool Save( FILE* aFile ); + virtual bool Load( char* aLine, wxString& aErrorMsg ); + + /** + * Test if the given point is within the bounds of this object. + * + * @param refPos - A wxPoint to test + * @return - true if a hit, else false + */ + virtual bool HitTest( const wxPoint& refPos ); + + /** + * @param aPosRef = a wxPoint to test, in eeschema coordinates + * @param aThreshold = max distance to a segment + * @param aTransform = the transform matrix + * @return true if the point aPosRef is near a segment + */ + virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); + + /** + * Test if the given rectangle intersects this object. + * + * For now, an ending point must be inside this rect. + * + * @param aRect - the given EDA_Rect + * @return - true if a hit, else false + */ + virtual bool HitTest( EDA_Rect& aRect ) + { + return TextHitTest( aRect ); + } + + /** + * @return the size of the "pen" that be used to draw or plot this item + */ + virtual int GetPenSize( ); + + virtual void DisplayInfo( WinEDA_DrawFrame* aFrame ); + + virtual EDA_Rect GetBoundingBox(); + + void Rotate(); + + /** + * See LIB_DRAW_ITEM::BeginEdit(). + */ + void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ); + + /** + * See LIB_DRAW_ITEM::ContinueEdit(). + */ + bool ContinueEdit( const wxPoint aNextPoint ); + + /** + * See LIB_DRAW_ITEM::AbortEdit(). + */ + void EndEdit( const wxPoint& aPosition, bool aAbort = false ); + +protected: + virtual LIB_DRAW_ITEM* DoGenCopy(); + + /** + * Provide the text draw object specific comparison. + * + * The sort order is as follows: + * - Text string, case insensitive compare. + * - Text horizontal (X) position. + * - Text vertical (Y) position. + * - Text width. + * - Text height. + */ + virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const; + + virtual void DoOffset( const wxPoint& aOffset ); + virtual bool DoTestInside( EDA_Rect& aRect ); + virtual void DoMove( const wxPoint& aPosition ); + virtual wxPoint DoGetPosition() { return m_Pos; } + virtual void DoMirrorHorizontal( const wxPoint& aCenter ); + virtual void DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, + const TRANSFORM& aTransform ); + virtual int DoGetWidth() { return m_Width; } + virtual void DoSetWidth( int aWidth ) { m_Width = aWidth; } +}; + + +#endif // _LIB_TEXT_H_ diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 8524eefb54..0440e6f164 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -162,6 +162,7 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* aEntry, CMP_LIBR { SAFE_DELETE( m_component ); m_aliasName.Empty(); + m_oldRootName.Empty(); } m_component = new LIB_COMPONENT( *component ); @@ -175,7 +176,7 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* aEntry, CMP_LIBR return false; } - m_aliasName = aEntry->GetName(); + m_oldRootName = m_aliasName = aEntry->GetName(); m_unit = 1; m_convert = 1; @@ -458,6 +459,7 @@ All changes will be lost. Discard changes?" ) ) ) { SAFE_DELETE( m_component ); m_aliasName.Empty(); + m_oldRootName.Empty(); } DrawPanel->Refresh(); @@ -509,6 +511,7 @@ 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() ); @@ -573,6 +576,7 @@ void WinEDA_LibeditFrame::SaveOnePartInMemory() LIB_COMPONENT* oldComponent; LIB_COMPONENT* Component; wxString msg; + wxString rootName; if( m_component == NULL ) { @@ -591,12 +595,19 @@ void WinEDA_LibeditFrame::SaveOnePartInMemory() GetBaseScreen()->ClrModify(); - oldComponent = m_library->FindComponent( m_component->GetName() ); + // 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 ); if( oldComponent != NULL ) { - msg.Printf( _( "Component \"%s\" exists. Change it?" ), - GetChars( oldComponent->GetName() ) ); + msg.Printf( _( "Component \"%s\" exists. Change it?" ), GetChars( rootName ) ); + if( !IsOK( this, msg ) ) return; } diff --git a/eeschema/libedit_onleftclick.cpp b/eeschema/libedit_onleftclick.cpp index 6eed34b261..77efb28ab0 100644 --- a/eeschema/libedit_onleftclick.cpp +++ b/eeschema/libedit_onleftclick.cpp @@ -153,9 +153,8 @@ void WinEDA_LibeditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) if( ( m_drawItem == NULL ) || ( m_drawItem->m_Flags == 0 ) ) { // We can locate an item - m_drawItem = - m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, - GetScreen()->m_MousePosition ); + m_drawItem = m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, + GetScreen()->m_MousePosition ); if( m_drawItem == NULL ) { m_drawItem = m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, diff --git a/eeschema/libedit_onrightclick.cpp b/eeschema/libedit_onrightclick.cpp index c820f357a2..66cd9f6c50 100644 --- a/eeschema/libedit_onrightclick.cpp +++ b/eeschema/libedit_onrightclick.cpp @@ -18,7 +18,7 @@ #include "protos.h" #include "libeditframe.h" #include "class_libentry.h" -#include "class_pin.h" +#include "lib_pin.h" #include "lib_polyline.h" diff --git a/eeschema/libedit_undo_redo.cpp b/eeschema/libedit_undo_redo.cpp index 0cd81a78b8..0e80ca4ec5 100644 --- a/eeschema/libedit_undo_redo.cpp +++ b/eeschema/libedit_undo_redo.cpp @@ -13,10 +13,7 @@ #include "class_libentry.h" -/*************************************************************************/ -void WinEDA_LibeditFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy, - int unused_flag ) -/*************************************************************************/ +void WinEDA_LibeditFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy, int unused_flag ) { LIB_COMPONENT* CopyItem; PICKED_ITEMS_LIST* lastcmd; @@ -27,46 +24,47 @@ void WinEDA_LibeditFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy, return; lastcmd = new PICKED_ITEMS_LIST(); - ITEM_PICKER wrapper(CopyItem, UR_LIBEDIT); + ITEM_PICKER wrapper( CopyItem, UR_LIBEDIT ); lastcmd->PushItem(wrapper); GetScreen()->PushCommandToUndoList( lastcmd ); - /* Clear current flags (which can be temporary set by a current edit - * command) */ + + // Clear current flags (which can be temporary set by a current edit command). CopyItem->ClearStatus(); - /* Clear redo list, because after new save there is no redo to do */ + // Clear redo list, because after new save there is no redo to do. GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList ); } -/*************************************************************************/ -void WinEDA_LibeditFrame::GetComponentFromRedoList(wxCommandEvent& event) -/*************************************************************************/ - /* Redo the last edition: - * - Place the current edited library component in undo list - * - Get old version of the current edited library component + * - Place the current edited library component in undo list + * - Get old version of the current edited library component */ +void WinEDA_LibeditFrame::GetComponentFromRedoList(wxCommandEvent& event) { if ( GetScreen()->GetRedoCommandCount() <= 0 ) return; PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); - ITEM_PICKER wrapper(m_component, UR_LIBEDIT); - lastcmd->PushItem(wrapper); + ITEM_PICKER wrapper( m_component, UR_LIBEDIT ); + lastcmd->PushItem( wrapper ); GetScreen()->PushCommandToUndoList( lastcmd ); - lastcmd = GetScreen()->PopCommandFromRedoList( ); + lastcmd = GetScreen()->PopCommandFromRedoList(); wrapper = lastcmd->PopItem(); m_component = (LIB_COMPONENT*) wrapper.m_PickedItem; - if( m_component ) - m_component->SetNext( NULL ); + + if( m_component == NULL ) + return; + + if( !m_aliasName.IsEmpty() && !m_component->HasAlias( m_aliasName ) ) + m_aliasName = m_component->GetName(); + m_drawItem = NULL; UpdateAliasSelectList(); UpdatePartSelectList(); - if( m_component ) - SetShowDeMorgan( m_component->HasConversion() ); + SetShowDeMorgan( m_component->HasConversion() ); DisplayLibInfos(); DisplayCmpDoc(); OnModify( ); @@ -74,37 +72,37 @@ void WinEDA_LibeditFrame::GetComponentFromRedoList(wxCommandEvent& event) } -/************************************************************************/ -void WinEDA_LibeditFrame::GetComponentFromUndoList(wxCommandEvent& event) -/************************************************************************/ - /** Undo the last edition: - * - Place the current edited library component in Redo list - * - Get old version of the current edited library component + * - Place the current edited library component in Redo list + * - Get old version of the current edited library component */ +void WinEDA_LibeditFrame::GetComponentFromUndoList(wxCommandEvent& event) { if ( GetScreen()->GetUndoCommandCount() <= 0 ) return; PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); - ITEM_PICKER wrapper(m_component, UR_LIBEDIT); - lastcmd->PushItem(wrapper); + ITEM_PICKER wrapper( m_component, UR_LIBEDIT ); + lastcmd->PushItem( wrapper ); GetScreen()->PushCommandToRedoList( lastcmd ); - lastcmd = GetScreen()->PopCommandFromUndoList( ); + lastcmd = GetScreen()->PopCommandFromUndoList(); wrapper = lastcmd->PopItem(); m_component = (LIB_COMPONENT*) wrapper.m_PickedItem; - if( m_component ) - m_component->SetNext( NULL ); + if( m_component == NULL ) + return; + + if( !m_aliasName.IsEmpty() && !m_component->HasAlias( m_aliasName ) ) + m_aliasName = m_component->GetName(); + m_drawItem = NULL; UpdateAliasSelectList(); UpdatePartSelectList(); - if( m_component ) - SetShowDeMorgan( m_component->HasConversion() ); + SetShowDeMorgan( m_component->HasConversion() ); DisplayLibInfos(); DisplayCmpDoc(); - OnModify( ); + OnModify(); DrawPanel->Refresh(); } diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index a7255ba7ce..b1ddec190b 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -218,8 +218,7 @@ WinEDA_LibeditFrame::WinEDA_LibeditFrame( WinEDA_SchematicFrame* aParent, horiz.LeftDockable( false ).RightDockable( false ); m_auimgr.AddPane( m_HToolBar, - wxAuiPaneInfo( horiz ).Name( wxT( "m_HToolBar" ) ).Top(). - Row( 0 ) ); + wxAuiPaneInfo( horiz ).Name( wxT( "m_HToolBar" ) ).Top().Row( 0 ) ); m_auimgr.AddPane( m_VToolBar, wxAuiPaneInfo( vert ).Name( wxT( "m_VToolBar" ) ).Right() ); @@ -432,14 +431,14 @@ void WinEDA_LibeditFrame::OnUpdateNotEditingPart( wxUpdateUIEvent& event ) void WinEDA_LibeditFrame::OnUpdateUndo( wxUpdateUIEvent& event ) { event.Enable( m_component != NULL && GetScreen() != NULL - && GetScreen()->GetUndoCommandCount() != 0 ); + && GetScreen()->GetUndoCommandCount() != 0 && !IsEditingDrawItem() ); } void WinEDA_LibeditFrame::OnUpdateRedo( wxUpdateUIEvent& event ) { event.Enable( m_component != NULL && GetScreen() != NULL - && GetScreen()->GetRedoCommandCount() != 0 ); + && GetScreen()->GetRedoCommandCount() != 0 && !IsEditingDrawItem() ); } @@ -457,7 +456,7 @@ void WinEDA_LibeditFrame::OnUpdateViewDoc( wxUpdateUIEvent& event ) { LIB_ALIAS* alias = m_component->GetAlias( m_aliasName ); - wxCHECK_RET( alias != NULL, wxT( "Alias not found." ) ); + wxCHECK_RET( alias != NULL, wxT( "Alias <" ) + m_aliasName + wxT( "> not found." ) ); enable = !alias->GetDocFileName().IsEmpty(); } diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index 7c511fddbd..bff73a195e 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -7,12 +7,13 @@ #include "wxstruct.h" +#include "lib_draw_item.h" + class SCH_SCREEN; class CMP_LIBRARY; class LIB_COMPONENT; class LIB_ALIAS; -class LIB_DRAW_ITEM; class WinEDA_bodygraphics_PropertiesFrame; class Dialog_BodyGraphicText_Properties; @@ -23,6 +24,9 @@ class Dialog_BodyGraphicText_Properties; class WinEDA_LibeditFrame : public WinEDA_DrawFrame { LIB_COMPONENT* m_savedComponent; ///< 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. public: WinEDAChoiceBox* m_SelpartBox; // a Box to select a part to edit (if any) @@ -169,6 +173,8 @@ public: void DeleteSavedComponent(); + bool IsEditingDrawItem() { return m_drawItem && m_drawItem->InEditMode(); } + private: /** diff --git a/eeschema/libfield.cpp b/eeschema/libfield.cpp index 7c92badecb..b8b01ea07b 100644 --- a/eeschema/libfield.cpp +++ b/eeschema/libfield.cpp @@ -15,53 +15,35 @@ #include "class_library.h" -extern int m_unit; - void WinEDA_LibeditFrame::EditField( wxDC* DC, LIB_FIELD* Field ) { wxString Text; wxString title; - bool save = true; + wxString oldName; if( Field == NULL ) return; - switch( Field->m_FieldId ) - { - case REFERENCE: - title = _( "Reference:" ); - break; - - case VALUE: - title = _( "Component Name / Value:" ); - break; - - default: - break; - } - + title = Field->GetName(); Text = Field->m_Text; - { - wxTextEntryDialog dlg( this, title, _( "Edit field" ), Text ); - if( dlg.ShowModal() != wxID_OK ) - return; // cancelled by user - Text = dlg.GetValue( ); - } + 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 ) + if( ( Field->m_FieldId == REFERENCE || Field->m_FieldId == VALUE ) && Text.IsEmpty ( ) ) { - if( Text.IsEmpty ( ) ) - { - DisplayError( this, _( "Value or Reference cannot be void. Aborted" ) ); - return; - } + DisplayError( this, title + _( " field cannot be empty." ) ); + return; } - wxString fieldText = Field->GetFullText( m_unit ); + LIB_COMPONENT* parent = Field->GetParent(); /* 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 @@ -72,22 +54,11 @@ void WinEDA_LibeditFrame::EditField( wxDC* DC, LIB_FIELD* Field ) { wxString msg; - /* Test for an existing name in the current components alias list. */ - if( Field->GetParent()->HasAlias( Text ) ) - { - msg.Printf( _( "The field name <%s> is an existing alias of the \ -component <%s>.\nPlease choose another name that does not conflict with any \ -names in the alias list." ), - GetChars( Text ), - GetChars( Field->GetParent()->GetName() ) ); - DisplayError( this, msg ); - return; - } - - /* Test for an existing entry in the library to prevent duplicate - * entry names. + /* Test for an existing name in the current components alias list and in + * the current library. */ - if( m_library && m_library->FindEntry( Text ) != NULL ) + if( ( parent->HasAlias( Text ) && !parent->GetAlias( Text )->IsRoot() ) + || ( m_library && 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 \ @@ -97,35 +68,27 @@ not conflict with any library entries." ), DisplayError( this, msg ); return; } - - SaveCopyInUndoList( Field->GetParent() ); - save = false; - Field->GetParent()->SetName( Text ); } - ( ( LIB_DRAW_ITEM* )Field )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, - &fieldText, DefaultTransform ); + if( Field->m_FieldId == VALUE && Field->m_Text == m_aliasName ) + m_aliasName = Text; - if( !Text.IsEmpty() ) + if( !Field->InEditMode() ) { - if( save ) - SaveCopyInUndoList( Field->GetParent() ); - Field->m_Text = Text; + SaveCopyInUndoList( parent ); + ( (LIB_DRAW_ITEM*) Field )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, + &fieldText, DefaultTransform ); } - else + + Field->SetText( Text ); + + if( !Field->InEditMode() ) { - DisplayError( this, _( "No new text: no change" ) ); + fieldText = Field->GetFullText( m_unit ); + ( (LIB_DRAW_ITEM*) Field )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, + &fieldText, DefaultTransform ); } - fieldText = Field->GetFullText( m_unit ); - int drawMode = g_XorMode; - - if( Field->m_Flags == 0 ) - drawMode = GR_DEFAULT_DRAWMODE; - - ( ( LIB_DRAW_ITEM* )Field )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, drawMode, - &fieldText, DefaultTransform ); - OnModify(); UpdateAliasSelectList(); } diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index fe4cf002dd..7cace2008e 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -43,7 +43,7 @@ #include "netlist.h" #include "protos.h" #include "class_library.h" -#include "class_pin.h" +#include "lib_pin.h" #include "xnode.h" // also nests: diff --git a/eeschema/netlist.cpp b/eeschema/netlist.cpp index 2e1076f552..770c9dc6b6 100644 --- a/eeschema/netlist.cpp +++ b/eeschema/netlist.cpp @@ -10,7 +10,7 @@ #include "netlist.h" #include "protos.h" #include "class_library.h" -#include "class_pin.h" +#include "lib_pin.h" #include "algorithm" diff --git a/eeschema/pinedit.cpp b/eeschema/pinedit.cpp index fb5824abe1..694f575ce3 100644 --- a/eeschema/pinedit.cpp +++ b/eeschema/pinedit.cpp @@ -12,7 +12,7 @@ #include "libeditframe.h" #include "eeschema_id.h" #include "class_libentry.h" -#include "class_pin.h" +#include "lib_pin.h" #include "general.h" #include "protos.h" diff --git a/eeschema/plot.cpp b/eeschema/plot.cpp index 10045c0e60..1aeb361ec6 100644 --- a/eeschema/plot.cpp +++ b/eeschema/plot.cpp @@ -14,7 +14,7 @@ #include "general.h" #include "protos.h" #include "class_library.h" -#include "class_pin.h" +#include "lib_pin.h" /* Local functions : */ diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 716e448316..e27eb45396 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -18,7 +18,7 @@ #include "protos.h" #include "eeschema_id.h" #include "netlist.h" -#include "class_pin.h" +#include "lib_pin.h" #include "class_library.h" #include "annotate_dialog.h" diff --git a/eeschema/symbdraw.cpp b/eeschema/symbdraw.cpp index ec96ac6125..469bfd01cc 100644 --- a/eeschema/symbdraw.cpp +++ b/eeschema/symbdraw.cpp @@ -18,6 +18,7 @@ #include "lib_circle.h" #include "lib_polyline.h" #include "lib_rectangle.h" +#include "lib_text.h" static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );