Commit 185a2544 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Component library editor bug fixes and other minor fixes.

* Fix bug that prevented component from being replaced in library when
  the component root name was changed.
* Fix drawing bug when changing text or field item string while move in
  progress.
* Fix drawing bug when rotating text item while move in progress.
* Prevent undo or redo when editing a component draw item.
* Fix assert bug when replacing component in library when the component
  root name was changed.
* Fix bug in field editor caused by new root alias implementation that
  prevented any field from being changed.
* Fix minor spacing issues with EESchema find dialog.
* Deprecate remaining internal linked list code from component library
  objects.
* Rename pin object files to match new library object file naming
  scheme.
* Move LIB_TEXT object definition into it's own header file.
parent 62916eb2
......@@ -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
......
......@@ -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 <OBJ_CMP_TO_LIST>& aComponentsList,
......
......@@ -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"
......
......@@ -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"
......
......@@ -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 <boost/foreach.hpp>
......@@ -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 )
......
......@@ -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();
......
......@@ -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;
......
......@@ -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...) */
......
......@@ -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 <wx/tokenzr.h>
......
......@@ -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"
......
......@@ -12,7 +12,7 @@
#include "eeschema_id.h"
#include "protos.h"
#include "lib_draw_item.h"
#include "class_pin.h"
#include "lib_pin.h"
/***************************************************************/
......
......@@ -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 {
......
......@@ -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; i<m_FieldsBuf.size(); ++i )
for( unsigned i=0; i<m_FieldsBuf.size(); ++i )
{
printf( "save[%d].name:'%s' value:'%s'\n", i,
CONV_TO_UTF8( m_FieldsBuf[i].m_Name ),
CONV_TO_UTF8( m_FieldsBuf[i].m_Text )
);
CONV_TO_UTF8( m_FieldsBuf[i].m_Name ),
CONV_TO_UTF8( m_FieldsBuf[i].m_Text ) );
}
#endif
......@@ -262,9 +261,9 @@ An alias %s already exists!\nCannot update this component" ),
m_LibEntry->SetFields( 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 );
}
......
......@@ -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"
......
......@@ -93,11 +93,11 @@
<property name="name">leftSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxFlexGridSizer" expanded="1">
<property name="proportion">0</property>
<object class="wxFlexGridSizer" expanded="0">
<property name="cols">2</property>
<property name="flexible_direction">wxBOTH</property>
<property name="growablecols"></property>
......@@ -109,11 +109,11 @@
<property name="permission">none</property>
<property name="rows">3</property>
<property name="vgap">3</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<object class="wxStaticText" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
......@@ -165,11 +165,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxEXPAND|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxComboBox" expanded="1">
<object class="wxComboBox" expanded="0">
<property name="bg"></property>
<property name="choices"></property>
<property name="context_help"></property>
......@@ -224,11 +224,11 @@
<event name="OnUpdateUI">OnUpdateDrcUI</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<object class="wxStaticText" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
......@@ -280,11 +280,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_HORIZONTAL|wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxComboBox" expanded="1">
<object class="wxComboBox" expanded="0">
<property name="bg"></property>
<property name="choices"></property>
<property name="context_help"></property>
......@@ -339,11 +339,11 @@
<event name="OnUpdateUI">OnUpdateDrcUI</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag"></property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<object class="wxStaticText" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
......@@ -395,20 +395,20 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxBoxSizer" expanded="1">
<object class="wxBoxSizer" expanded="0">
<property name="minimum_size"></property>
<property name="name">directionSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">3</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxRadioButton" expanded="1">
<object class="wxRadioButton" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
......@@ -461,11 +461,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">3</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxRadioButton" expanded="1">
<object class="wxRadioButton" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
......@@ -522,11 +522,11 @@
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<object class="wxCheckBox" expanded="0">
<property name="bg"></property>
<property name="checked">0</property>
<property name="context_help"></property>
......@@ -579,11 +579,11 @@
<event name="OnUpdateUI">OnUpdateWholeWordUI</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<object class="wxCheckBox" expanded="0">
<property name="bg"></property>
<property name="checked">0</property>
<property name="context_help"></property>
......@@ -636,11 +636,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<object class="wxCheckBox" expanded="0">
<property name="bg"></property>
<property name="checked">0</property>
<property name="context_help"></property>
......@@ -693,11 +693,11 @@
<event name="OnUpdateUI">OnUpdateWildcardUI</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<object class="wxCheckBox" expanded="0">
<property name="bg"></property>
<property name="checked">1</property>
<property name="context_help"></property>
......@@ -750,11 +750,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxALL</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<object class="wxCheckBox" expanded="0">
<property name="bg"></property>
<property name="checked">0</property>
<property name="context_help"></property>
......@@ -807,11 +807,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxBOTTOM|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<object class="wxCheckBox" expanded="0">
<property name="bg"></property>
<property name="checked">0</property>
<property name="context_help"></property>
......@@ -864,11 +864,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxALL</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<object class="wxCheckBox" expanded="0">
<property name="bg"></property>
<property name="checked">0</property>
<property name="context_help"></property>
......@@ -932,11 +932,11 @@
<property name="name">rightSizer</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<object class="wxButton" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
......@@ -989,11 +989,11 @@
<event name="OnUpdateUI">OnUpdateFindUI</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<object class="wxButton" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
......@@ -1046,11 +1046,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<object class="wxButton" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
......@@ -1103,11 +1103,11 @@
<event name="OnUpdateUI"></event>
</object>
</object>
<object class="sizeritem" expanded="1">
<object class="sizeritem" expanded="0">
<property name="border">6</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<object class="wxButton" expanded="0">
<property name="bg"></property>
<property name="context_help"></property>
<property name="context_menu">1</property>
......
......@@ -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 );
......
......@@ -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 );
}
......@@ -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"
......
......@@ -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"
......
......@@ -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" );
......
......@@ -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_
......@@ -18,10 +18,7 @@
#include "protos.h"
#include "class_libentry.h"
#include "transform.h"
#include <wx/tokenzr.h>
#include <wx/stream.h>
#include <wx/txtstrm.h>
#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;
......
......@@ -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();
......
/*****************/
/* 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"
......
......@@ -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" );
......
......@@ -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();
......
#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_
......@@ -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;
}
......
......@@ -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,
......
......@@ -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"
......
......@@ -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();
}
......@@ -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();
}
......
......@@ -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:
/**
......
......@@ -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;
title = Field->GetName();
Text = Field->m_Text;
case VALUE:
title = _( "Component Name / Value:" );
break;
wxTextEntryDialog dlg( this, title + wxT( ":" ), _( "Edit field" ), Text );
default:
break;
}
if( dlg.ShowModal() != wxID_OK || dlg.GetValue() == Text )
return;
Text = Field->m_Text;
{
wxTextEntryDialog dlg( this, title, _( "Edit field" ), Text );
if( dlg.ShowModal() != wxID_OK )
return; // cancelled by user
Text = dlg.GetValue( );
}
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,34 +68,26 @@ 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( save )
SaveCopyInUndoList( Field->GetParent() );
Field->m_Text = Text;
}
else
if( !Field->InEditMode() )
{
DisplayError( this, _( "No new text: no change" ) );
SaveCopyInUndoList( parent );
( (LIB_DRAW_ITEM*) Field )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode,
&fieldText, DefaultTransform );
}
fieldText = Field->GetFullText( m_unit );
int drawMode = g_XorMode;
Field->SetText( Text );
if( Field->m_Flags == 0 )
drawMode = GR_DEFAULT_DRAWMODE;
( ( LIB_DRAW_ITEM* )Field )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, drawMode,
&fieldText, DefaultTransform );
if( !Field->InEditMode() )
{
fieldText = Field->GetFullText( m_unit );
( (LIB_DRAW_ITEM*) Field )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode,
&fieldText, DefaultTransform );
}
OnModify();
UpdateAliasSelectList();
......
......@@ -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: <wx/xml/xml.h>
......
......@@ -10,7 +10,7 @@
#include "netlist.h"
#include "protos.h"
#include "class_library.h"
#include "class_pin.h"
#include "lib_pin.h"
#include "algorithm"
......
......@@ -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"
......
......@@ -14,7 +14,7 @@
#include "general.h"
#include "protos.h"
#include "class_library.h"
#include "class_pin.h"
#include "lib_pin.h"
/* Local functions : */
......
......@@ -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"
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment