Initial ground work to make schematic fields use unified move code.

* Remove external dependency for adding suffix to reference designator
  fields.
* Make schematic field get and set position methods transform coordinates
  relative to the parent component object that owns them.
* Make base text class get text method virtual so derived classes can
  change the base string according to their individual requirements.
* Fix a problem with default place schematic item add in last commit.
This commit is contained in:
Wayne Stambaugh 2011-10-21 14:17:51 -04:00
parent 78377058c9
commit 7bbe2f784e
8 changed files with 82 additions and 136 deletions

View File

@ -97,6 +97,7 @@ void SCH_ITEM::Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC )
m_Flags = 0; m_Flags = 0;
screen->SetModify(); screen->SetModify();
screen->SetCurItem( NULL ); screen->SetCurItem( NULL );
aFrame->DrawPanel->SetMouseCapture( NULL, NULL );
aFrame->DrawPanel->EndMouseCapture(); aFrame->DrawPanel->EndMouseCapture();
if( aDC ) if( aDC )

View File

@ -45,34 +45,18 @@
*/ */
static void moveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) static void moveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase )
{ {
wxPoint pos;
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) aPanel->GetParent();
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen(); SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
SCH_FIELD* currentField = (SCH_FIELD*)screen->GetCurItem(); SCH_FIELD* currentField = (SCH_FIELD*)screen->GetCurItem();
if( (currentField == NULL) || (currentField->Type() != SCH_FIELD_T) ) if( (currentField == NULL) || (currentField->Type() != SCH_FIELD_T) )
return; return;
SCH_COMPONENT* component = (SCH_COMPONENT*) currentField->GetParent();
currentField->m_AddExtraText = frame->m_Multiflag;
if( aErase ) if( aErase )
{ {
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
} }
pos = ( (SCH_COMPONENT*) currentField->GetParent() )->GetPosition(); currentField->SetPosition( screen->GetCrossHairPosition() );
// Actual positions are calculated by the rotation/mirror transform
// But here we want the relative position of the moved field
// and we know the actual position.
// So we are using the inverse rotation/mirror transform.
wxPoint pt( screen->GetCrossHairPosition() - pos );
TRANSFORM itrsfm = component->GetTransform().InverseTransform();
currentField->SetPosition( pos + itrsfm.TransformCoordinate( pt ) );
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
} }
@ -86,7 +70,6 @@ static void abortMoveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
if( currentField ) if( currentField )
{ {
currentField->m_AddExtraText = frame->m_Multiflag;
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
currentField->ClearFlags(); currentField->ClearFlags();
currentField->m_Pos = frame->m_OldPos; currentField->m_Pos = frame->m_OldPos;
@ -102,34 +85,16 @@ void SCH_EDIT_FRAME::MoveField( SCH_FIELD* aField, wxDC* aDC )
wxCHECK_RET( aField && (aField->Type() == SCH_FIELD_T) && !aField->GetText().IsEmpty(), wxCHECK_RET( aField && (aField->Type() == SCH_FIELD_T) && !aField->GetText().IsEmpty(),
wxT( "Cannot move invalid component field." ) ); wxT( "Cannot move invalid component field." ) );
LIB_COMPONENT* libEntry;
wxPoint pos, newpos;
SCH_COMPONENT* comp = (SCH_COMPONENT*) aField->GetParent(); SCH_COMPONENT* comp = (SCH_COMPONENT*) aField->GetParent();
GetScreen()->SetCurItem( aField ); GetScreen()->SetCurItem( aField );
SetUndoItem( comp ); SetUndoItem( comp );
pos = comp->GetPosition();
/* Positions are computed by the rotation/mirror transform. */
newpos = aField->m_Pos - pos;
newpos = comp->GetTransform().TransformCoordinate( newpos ) + pos;
DrawPanel->CrossHairOff( aDC ); DrawPanel->CrossHairOff( aDC );
GetScreen()->SetCrossHairPosition( newpos ); GetScreen()->SetCrossHairPosition( aField->GetPosition() );
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
m_OldPos = aField->m_Pos; m_OldPos = aField->m_Pos;
m_Multiflag = 0;
if( aField->GetId() == REFERENCE )
{
libEntry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
if( (libEntry != NULL) && (libEntry->GetPartCount() > 1) )
m_Multiflag = 1;
}
DrawPanel->SetMouseCapture( moveField, abortMoveField ); DrawPanel->SetMouseCapture( moveField, abortMoveField );
aField->SetFlags( IS_MOVED ); aField->SetFlags( IS_MOVED );
@ -143,7 +108,7 @@ void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField, wxDC* aDC )
wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T, wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T,
wxT( "Cannot edit invalid schematic field." ) ); wxT( "Cannot edit invalid schematic field." ) );
int fieldNdx, flag; int fieldNdx;
SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent(); SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T, wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T,
@ -165,15 +130,12 @@ create a new power component with the new value." ), GetChars( entry->GetName()
return; return;
} }
flag = 0;
if( fieldNdx == REFERENCE && entry->GetPartCount() > 1 )
flag = 1;
// Save old component in undo list if not already in edit, or moving. // Save old component in undo list if not already in edit, or moving.
if( aField->GetFlags() == 0 ) if( aField->GetFlags() == 0 )
SaveCopyInUndoList( component, UR_CHANGED ); SaveCopyInUndoList( component, UR_CHANGED );
// Don't use GetText() here. If the field is the reference designator and it's parent
// component has multiple parts, we don't want the part suffix added to the field.
wxString newtext = aField->m_Text; wxString newtext = aField->m_Text;
DrawPanel->m_IgnoreMouseEvents = true; DrawPanel->m_IgnoreMouseEvents = true;
@ -192,7 +154,6 @@ create a new power component with the new value." ), GetChars( entry->GetName()
if ( response != wxID_OK || newtext == aField->GetText() ) if ( response != wxID_OK || newtext == aField->GetText() )
return; // canceled by user return; // canceled by user
aField->m_AddExtraText = flag;
aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
if( !newtext.IsEmpty() ) if( !newtext.IsEmpty() )
@ -217,7 +178,9 @@ create a new power component with the new value." ), GetChars( entry->GetName()
} }
} }
else else
{
aField->m_Text = newtext; aField->m_Text = newtext;
}
} }
else else
{ {
@ -246,23 +209,12 @@ void SCH_EDIT_FRAME::RotateField( SCH_FIELD* aField, wxDC* aDC )
wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T && !aField->GetText().IsEmpty(), wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T && !aField->GetText().IsEmpty(),
wxT( "Cannot rotate invalid schematic field." ) ); wxT( "Cannot rotate invalid schematic field." ) );
int flag = 0;
LIB_COMPONENT* libEntry;
SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent(); SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
if( aField->GetId() == REFERENCE )
{
libEntry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
if( (libEntry != NULL) && (libEntry->GetPartCount() > 1) )
flag = 1;
}
// Save old component in undo list if not already in edit, or moving. // Save old component in undo list if not already in edit, or moving.
if( aField->GetFlags() == 0 ) if( aField->GetFlags() == 0 )
SaveCopyInUndoList( component, UR_CHANGED ); SaveCopyInUndoList( component, UR_CHANGED );
aField->m_AddExtraText = flag;
aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode ); aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
if( aField->m_Orient == TEXT_ORIENT_HORIZ ) if( aField->m_Orient == TEXT_ORIENT_HORIZ )

View File

@ -315,16 +315,7 @@ void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset
if( field->IsVisible() && !( field->m_Flags & IS_MOVED ) ) if( field->IsVisible() && !( field->m_Flags & IS_MOVED ) )
{ {
if( Entry->GetPartCount() > 1 ) field->Draw( panel, DC, offset, DrawMode );
{
field->m_AddExtraText = true;
field->Draw( panel, DC, offset, DrawMode );
}
else
{
field->m_AddExtraText = false;
field->Draw( panel, DC, offset, DrawMode );
}
} }
for( int ii = VALUE; ii < GetFieldCount(); ii++ ) for( int ii = VALUE; ii < GetFieldCount(); ii++ )
@ -1548,11 +1539,6 @@ bool SCH_COMPONENT::Matches( wxFindReplaceData& aSearchData, void* aAuxData,
// the .m_AddExtraText of the field must be set to add this identifier: // the .m_AddExtraText of the field must be set to add this identifier:
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName ); LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
if( Entry && Entry->GetPartCount() > 1 )
GetField( REFERENCE )->m_AddExtraText = true;
else
GetField( REFERENCE )->m_AddExtraText = false;
if( GetField( REFERENCE )->Matches( aSearchData, aAuxData, aFindLocation ) ) if( GetField( REFERENCE )->Matches( aSearchData, aAuxData, aFindLocation ) )
return true; return true;

View File

@ -60,7 +60,6 @@ SCH_FIELD::SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent,
{ {
m_Pos = aPos; m_Pos = aPos;
m_FieldId = aFieldId; m_FieldId = aFieldId;
m_AddExtraText = false;
m_Attributs = TEXT_NO_VISIBLE; m_Attributs = TEXT_NO_VISIBLE;
m_Name = aName; m_Name = aName;
@ -74,7 +73,6 @@ SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) :
{ {
m_FieldId = aField.m_FieldId; m_FieldId = aField.m_FieldId;
m_Name = aField.m_Name; m_Name = aField.m_Name;
m_AddExtraText = aField.m_AddExtraText;
} }
@ -89,6 +87,26 @@ EDA_ITEM* SCH_FIELD::doClone() const
} }
wxString SCH_FIELD::GetText() const
{
wxString text = m_Text;
/* For more than one part per package, we must add the part selection
* A, B, ... or 1, 2, .. to the reference. */
if( m_FieldId == REFERENCE )
{
SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent;
wxCHECK_MSG( component != NULL, text,
wxT( "No component associated with field" ) + text );
text << LIB_COMPONENT::ReturnSubReference( component->GetUnit() );
}
return text;
}
int SCH_FIELD::GetPenSize() const int SCH_FIELD::GetPenSize() const
{ {
int pensize = m_Thickness; int pensize = m_Thickness;
@ -168,21 +186,8 @@ void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
else else
color = ReturnLayerColor( LAYER_FIELDS ); color = ReturnLayerColor( LAYER_FIELDS );
if( !m_AddExtraText || ( m_FieldId != REFERENCE ) ) DrawGraphicText( panel, DC, textpos, color, GetText(), orient, m_Size, hjustify, vjustify,
{ LineWidth, m_Italic, m_Bold );
DrawGraphicText( panel, DC, textpos, color, m_Text, orient, m_Size, hjustify, vjustify,
LineWidth, m_Italic, m_Bold );
}
else
{
/* For more than one part per package, we must add the part selection
* A, B, ... or 1, 2, .. to the reference. */
wxString fulltext = m_Text;
fulltext << LIB_COMPONENT::ReturnSubReference( parentComponent->GetUnit() );
DrawGraphicText( panel, DC, textpos, color, fulltext, orient, m_Size, hjustify, vjustify,
LineWidth, m_Italic, m_Bold );
}
/* Enable this to draw the bounding box around the text field to validate /* Enable this to draw the bounding box around the text field to validate
* the bounding box calculations. * the bounding box calculations.
@ -393,9 +398,6 @@ bool SCH_FIELD::Save( FILE* aFile ) const
void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC ) void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
{ {
int fieldNdx;
LIB_COMPONENT* Entry;
frame->DrawPanel->SetMouseCapture( NULL, NULL ); frame->DrawPanel->SetMouseCapture( NULL, NULL );
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent(); SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
@ -403,20 +405,6 @@ void SCH_FIELD::Place( SCH_EDIT_FRAME* frame, wxDC* DC )
// save old cmp in undo list // save old cmp in undo list
frame->SaveUndoItemInUndoList( component ); frame->SaveUndoItemInUndoList( component );
fieldNdx = m_FieldId;
m_AddExtraText = 0;
if( fieldNdx == REFERENCE )
{
Entry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
if( Entry != NULL )
{
if( Entry->GetPartCount() > 1 )
m_AddExtraText = 1;
}
}
Draw( frame->DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); Draw( frame->DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
ClearFlags(); ClearFlags();
frame->GetScreen()->SetCurItem( NULL ); frame->GetScreen()->SetCurItem( NULL );
@ -428,28 +416,7 @@ bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint
{ {
bool match; bool match;
if( aAuxData && m_FieldId == REFERENCE ) match = SCH_ITEM::Matches( GetText(), aSearchData );
{
// reference is a special field because:
// >> a part identifier is added in multi parts per package
// (the .m_AddExtraText of the field is set in this case )
// >> In complex hierarchies, the actual reference depend on the sheet path.
SCH_COMPONENT* pSch = (SCH_COMPONENT*) m_Parent;
SCH_SHEET_PATH* sheet = (SCH_SHEET_PATH*) aAuxData;
wxString fulltext = pSch->GetRef( sheet );
if( m_AddExtraText )
{
/* For more than one part per package, we must add the part selection
* A, B, ... or 1, 2, .. to the reference. */
int part_id = pSch->GetUnitSelection( sheet );
fulltext << LIB_COMPONENT::ReturnSubReference( part_id );
}
match = SCH_ITEM::Matches( fulltext, aSearchData );
}
else
match = SCH_ITEM::Matches( m_Text, aSearchData );
if( match ) if( match )
{ {
@ -603,3 +570,29 @@ void SCH_FIELD::doPlot( PLOTTER* aPlotter )
thickness, m_Italic, m_Bold ); thickness, m_Italic, m_Bold );
} }
} }
void SCH_FIELD::doSetPosition( const wxPoint& aPosition )
{
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
wxPoint pos = ( (SCH_COMPONENT*) GetParent() )->GetPosition();
// Actual positions are calculated by the rotation/mirror transform of the
// parent component of the field. The inverse transfrom is used to calculate
// the position relative to the parent component.
wxPoint pt = aPosition - pos;
m_Pos = pos + component->GetTransform().InverseTransform().TransformCoordinate( pt );
}
wxPoint SCH_FIELD::doGetPosition() const
{
SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent();
wxPoint pos = m_Pos - component->GetPosition();
return component->GetTransform().TransformCoordinate( pos ) + component->GetPosition();
}

View File

@ -60,9 +60,6 @@ public:
wxString m_Name; wxString m_Name;
bool m_AddExtraText; /**< for REFERENCE, add extra info
* (for REFERENCE: add part selection text */
public: public:
SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent, SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent,
wxString aName = wxEmptyString ); wxString aName = wxEmptyString );
@ -74,7 +71,7 @@ public:
virtual wxString GetClass() const virtual wxString GetClass() const
{ {
return wxT( "SCH_FIELD" ); return wxT( "SCH_FIELD" );
} }
/** /**
* Function GetName * Function GetName
@ -86,6 +83,15 @@ public:
int GetId() const { return m_FieldId; } int GetId() const { return m_FieldId; }
/**
* Function GetText
* overrides the default implementation to allow for the part suffix to be added
* to the reference designator field if the component has multiple parts.
*
* @return a wxString object containing the field's string.
*/
virtual wxString GetText() const;
void Place( SCH_EDIT_FRAME* frame, wxDC* DC ); void Place( SCH_EDIT_FRAME* frame, wxDC* DC );
EDA_RECT GetBoundingBox() const; EDA_RECT GetBoundingBox() const;
@ -208,8 +214,8 @@ private:
virtual bool doHitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const; virtual bool doHitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const;
virtual EDA_ITEM* doClone() const; virtual EDA_ITEM* doClone() const;
virtual void doPlot( PLOTTER* aPlotter ); virtual void doPlot( PLOTTER* aPlotter );
virtual wxPoint doGetPosition() const { return m_Pos; } virtual wxPoint doGetPosition() const;
virtual void doSetPosition( const wxPoint& aPosition ) { m_Pos = aPosition; } virtual void doSetPosition( const wxPoint& aPosition );
}; };

View File

@ -184,7 +184,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father,
m_Draw_Axis = FALSE; // true to show axis m_Draw_Axis = FALSE; // true to show axis
m_Draw_Sheet_Ref = true; // true to show sheet references m_Draw_Sheet_Ref = true; // true to show sheet references
m_CurrentSheet = new SCH_SHEET_PATH(); m_CurrentSheet = new SCH_SHEET_PATH();
m_Multiflag = 0;
m_TextFieldSize = DEFAULT_SIZE_TEXT; m_TextFieldSize = DEFAULT_SIZE_TEXT;
m_LibeditFrame = NULL; // Component editor frame. m_LibeditFrame = NULL; // Component editor frame.
m_ViewlibFrame = NULL; // Frame for browsing component libraries m_ViewlibFrame = NULL; // Frame for browsing component libraries

View File

@ -839,13 +839,23 @@ public:
/** /**
* Function GetTextStyleName * Function GetTextStyleName
* @return a wwString withe the style name( Normal, Italic, Bold, Bold+Italic) * @return a wxString with the style name( Normal, Italic, Bold, Bold+Italic)
*/ */
wxString GetTextStyleName(); wxString GetTextStyleName();
void SetText( const wxString& aText ) { m_Text = aText; } void SetText( const wxString& aText ) { m_Text = aText; }
wxString GetText() const { return m_Text; } /**
* Function GetText
* returns the string associated with the text object.
* <p>
* This function is virtual to allow derived classes to override getting the
* string to provide a way for modifying the base string by adding a suffix or
* prefix to the base string.
* </p>
* @return a wxString object containing the string of the item.
*/
virtual wxString GetText() const { return m_Text; }
GRTextHorizJustifyType GetHorizJustify() const { return m_HJustify; }; GRTextHorizJustifyType GetHorizJustify() const { return m_HJustify; };
GRTextVertJustifyType GetVertJustify() const { return m_VJustify; }; GRTextVertJustifyType GetVertJustify() const { return m_VJustify; };

View File

@ -105,7 +105,6 @@ class SCH_EDIT_FRAME : public EDA_DRAW_FRAME
public: public:
wxComboBox* m_SelPartBox; wxComboBox* m_SelPartBox;
SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on. SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on.
int m_Multiflag;
int m_NetlistFormat; int m_NetlistFormat;
int m_AddSubPrefix; int m_AddSubPrefix;
bool m_ShowAllPins; bool m_ShowAllPins;