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:
parent
78377058c9
commit
7bbe2f784e
|
@ -97,6 +97,7 @@ void SCH_ITEM::Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC )
|
|||
m_Flags = 0;
|
||||
screen->SetModify();
|
||||
screen->SetCurItem( NULL );
|
||||
aFrame->DrawPanel->SetMouseCapture( NULL, NULL );
|
||||
aFrame->DrawPanel->EndMouseCapture();
|
||||
|
||||
if( aDC )
|
||||
|
|
|
@ -45,34 +45,18 @@
|
|||
*/
|
||||
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_FIELD* currentField = (SCH_FIELD*)screen->GetCurItem();
|
||||
|
||||
if( (currentField == NULL) || (currentField->Type() != SCH_FIELD_T) )
|
||||
return;
|
||||
|
||||
SCH_COMPONENT* component = (SCH_COMPONENT*) currentField->GetParent();
|
||||
|
||||
currentField->m_AddExtraText = frame->m_Multiflag;
|
||||
|
||||
if( aErase )
|
||||
{
|
||||
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
||||
}
|
||||
|
||||
pos = ( (SCH_COMPONENT*) currentField->GetParent() )->GetPosition();
|
||||
|
||||
// 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->SetPosition( screen->GetCrossHairPosition() );
|
||||
|
||||
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
||||
}
|
||||
|
@ -86,7 +70,6 @@ static void abortMoveField( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
|
|||
|
||||
if( currentField )
|
||||
{
|
||||
currentField->m_AddExtraText = frame->m_Multiflag;
|
||||
currentField->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
||||
currentField->ClearFlags();
|
||||
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(),
|
||||
wxT( "Cannot move invalid component field." ) );
|
||||
|
||||
LIB_COMPONENT* libEntry;
|
||||
wxPoint pos, newpos;
|
||||
SCH_COMPONENT* comp = (SCH_COMPONENT*) aField->GetParent();
|
||||
|
||||
GetScreen()->SetCurItem( aField );
|
||||
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 );
|
||||
GetScreen()->SetCrossHairPosition( newpos );
|
||||
GetScreen()->SetCrossHairPosition( aField->GetPosition() );
|
||||
DrawPanel->MoveCursorToCrossHair();
|
||||
|
||||
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 );
|
||||
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,
|
||||
wxT( "Cannot edit invalid schematic field." ) );
|
||||
|
||||
int fieldNdx, flag;
|
||||
int fieldNdx;
|
||||
SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
flag = 0;
|
||||
|
||||
if( fieldNdx == REFERENCE && entry->GetPartCount() > 1 )
|
||||
flag = 1;
|
||||
|
||||
// Save old component in undo list if not already in edit, or moving.
|
||||
if( aField->GetFlags() == 0 )
|
||||
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;
|
||||
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() )
|
||||
return; // canceled by user
|
||||
|
||||
aField->m_AddExtraText = flag;
|
||||
aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
||||
|
||||
if( !newtext.IsEmpty() )
|
||||
|
@ -217,7 +178,9 @@ create a new power component with the new value." ), GetChars( entry->GetName()
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aField->m_Text = newtext;
|
||||
}
|
||||
}
|
||||
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(),
|
||||
wxT( "Cannot rotate invalid schematic field." ) );
|
||||
|
||||
int flag = 0;
|
||||
LIB_COMPONENT* libEntry;
|
||||
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.
|
||||
if( aField->GetFlags() == 0 )
|
||||
SaveCopyInUndoList( component, UR_CHANGED );
|
||||
|
||||
aField->m_AddExtraText = flag;
|
||||
aField->Draw( DrawPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
|
||||
|
||||
if( aField->m_Orient == TEXT_ORIENT_HORIZ )
|
||||
|
|
|
@ -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( Entry->GetPartCount() > 1 )
|
||||
{
|
||||
field->m_AddExtraText = true;
|
||||
field->Draw( panel, DC, offset, DrawMode );
|
||||
}
|
||||
else
|
||||
{
|
||||
field->m_AddExtraText = false;
|
||||
field->Draw( panel, DC, offset, DrawMode );
|
||||
}
|
||||
field->Draw( panel, DC, offset, DrawMode );
|
||||
}
|
||||
|
||||
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:
|
||||
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 ) )
|
||||
return true;
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ SCH_FIELD::SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent,
|
|||
{
|
||||
m_Pos = aPos;
|
||||
m_FieldId = aFieldId;
|
||||
m_AddExtraText = false;
|
||||
m_Attributs = TEXT_NO_VISIBLE;
|
||||
m_Name = aName;
|
||||
|
||||
|
@ -74,7 +73,6 @@ SCH_FIELD::SCH_FIELD( const SCH_FIELD& aField ) :
|
|||
{
|
||||
m_FieldId = aField.m_FieldId;
|
||||
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 pensize = m_Thickness;
|
||||
|
@ -168,21 +186,8 @@ void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
|
|||
else
|
||||
color = ReturnLayerColor( LAYER_FIELDS );
|
||||
|
||||
if( !m_AddExtraText || ( m_FieldId != REFERENCE ) )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
DrawGraphicText( panel, DC, textpos, color, GetText(), orient, m_Size, hjustify, vjustify,
|
||||
LineWidth, m_Italic, m_Bold );
|
||||
|
||||
/* Enable this to draw the bounding box around the text field to validate
|
||||
* 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 )
|
||||
{
|
||||
int fieldNdx;
|
||||
LIB_COMPONENT* Entry;
|
||||
|
||||
frame->DrawPanel->SetMouseCapture( NULL, NULL );
|
||||
|
||||
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
|
||||
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 );
|
||||
ClearFlags();
|
||||
frame->GetScreen()->SetCurItem( NULL );
|
||||
|
@ -428,28 +416,7 @@ bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint
|
|||
{
|
||||
bool match;
|
||||
|
||||
if( aAuxData && m_FieldId == REFERENCE )
|
||||
{
|
||||
// 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 );
|
||||
match = SCH_ITEM::Matches( GetText(), aSearchData );
|
||||
|
||||
if( match )
|
||||
{
|
||||
|
@ -603,3 +570,29 @@ void SCH_FIELD::doPlot( PLOTTER* aPlotter )
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -60,9 +60,6 @@ public:
|
|||
|
||||
wxString m_Name;
|
||||
|
||||
bool m_AddExtraText; /**< for REFERENCE, add extra info
|
||||
* (for REFERENCE: add part selection text */
|
||||
|
||||
public:
|
||||
SCH_FIELD( const wxPoint& aPos, int aFieldId, SCH_COMPONENT* aParent,
|
||||
wxString aName = wxEmptyString );
|
||||
|
@ -74,7 +71,7 @@ public:
|
|||
virtual wxString GetClass() const
|
||||
{
|
||||
return wxT( "SCH_FIELD" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function GetName
|
||||
|
@ -86,6 +83,15 @@ public:
|
|||
|
||||
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 );
|
||||
|
||||
EDA_RECT GetBoundingBox() const;
|
||||
|
@ -208,8 +214,8 @@ private:
|
|||
virtual bool doHitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const;
|
||||
virtual EDA_ITEM* doClone() const;
|
||||
virtual void doPlot( PLOTTER* aPlotter );
|
||||
virtual wxPoint doGetPosition() const { return m_Pos; }
|
||||
virtual void doSetPosition( const wxPoint& aPosition ) { m_Pos = aPosition; }
|
||||
virtual wxPoint doGetPosition() const;
|
||||
virtual void doSetPosition( const wxPoint& aPosition );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -184,7 +184,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( wxWindow* father,
|
|||
m_Draw_Axis = FALSE; // true to show axis
|
||||
m_Draw_Sheet_Ref = true; // true to show sheet references
|
||||
m_CurrentSheet = new SCH_SHEET_PATH();
|
||||
m_Multiflag = 0;
|
||||
m_TextFieldSize = DEFAULT_SIZE_TEXT;
|
||||
m_LibeditFrame = NULL; // Component editor frame.
|
||||
m_ViewlibFrame = NULL; // Frame for browsing component libraries
|
||||
|
|
|
@ -839,13 +839,23 @@ public:
|
|||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
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; };
|
||||
GRTextVertJustifyType GetVertJustify() const { return m_VJustify; };
|
||||
|
|
|
@ -105,7 +105,6 @@ class SCH_EDIT_FRAME : public EDA_DRAW_FRAME
|
|||
public:
|
||||
wxComboBox* m_SelPartBox;
|
||||
SCH_SHEET_PATH* m_CurrentSheet; ///< which sheet we are presently working on.
|
||||
int m_Multiflag;
|
||||
int m_NetlistFormat;
|
||||
int m_AddSubPrefix;
|
||||
bool m_ShowAllPins;
|
||||
|
|
Loading…
Reference in New Issue