bool SCH_FIELD::Replace( wxFindReplaceData& aSearchData, void* aAuxData ) { bool isReplaced; wxString text = GetFullyQualifiedText(); if( m_id == REFERENCE ) { wxCHECK_MSG( aAuxData != NULL, false, wxT( "Cannot replace reference designator without valid sheet path." ) ); wxCHECK_MSG( aSearchData.GetFlags() & FR_REPLACE_REFERENCES, false, wxT( "Invalid replace component reference field call." ) ) ; SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent; wxCHECK_MSG( component != NULL, false, wxT( "No component associated with field" ) + text ); text = component->GetRef( (SCH_SHEET_PATH*) aAuxData ); // if( component->GetPartCount() > 1 ) // text << LIB_COMPONENT::ReturnSubReference( component->GetUnit() ); isReplaced = EDA_ITEM::Replace( aSearchData, text ); if( isReplaced ) component->SetRef( (SCH_SHEET_PATH*) aAuxData, text ); } else { isReplaced = EDA_ITEM::Replace( aSearchData, m_Text ); } return isReplaced; }
void SCH_FIELD::Plot( PLOTTER* aPlotter ) { SCH_COMPONENT* parent = ( SCH_COMPONENT* ) GetParent(); wxCHECK_RET( parent != NULL && parent->Type() == SCH_COMPONENT_T, wxT( "Cannot plot field with invalid parent." ) ); COLOR4D color = GetLayerColor( GetLayer() ); if( !IsVisible() ) return; if( IsVoid() ) return; /* Calculate the text orientation, according to the component * orientation/mirror */ int orient = GetTextAngle(); if( parent->GetTransform().y1 ) // Rotate component 90 deg. { if( orient == TEXT_ANGLE_HORIZ ) orient = TEXT_ANGLE_VERT; else orient = TEXT_ANGLE_HORIZ; } /* Calculate the text justification, according to the component * orientation/mirror * this is a bit complicated due to cumulative calculations: * - numerous cases (mirrored or not, rotation) * - the DrawGraphicText function recalculate also H and H justifications * according to the text orientation. * - When a component is mirrored, the text is not mirrored and * justifications are complicated to calculate * so the more easily way is to use no justifications ( Centered text ) * and use GetBoundaryBox to know the text coordinate considered as centered */ EDA_RECT BoundaryBox = GetBoundingBox(); EDA_TEXT_HJUSTIFY_T hjustify = GR_TEXT_HJUSTIFY_CENTER; EDA_TEXT_VJUSTIFY_T vjustify = GR_TEXT_VJUSTIFY_CENTER; wxPoint textpos = BoundaryBox.Centre(); int thickness = GetPenSize(); aPlotter->Text( textpos, color, GetFullyQualifiedText(), orient, GetTextSize(), hjustify, vjustify, thickness, IsItalic(), IsBold() ); }
const EDA_RECT SCH_FIELD::GetBoundingBox() const { SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent; int linewidth = ( m_Thickness == 0 ) ? GetDefaultLineThickness() : m_Thickness; // We must pass the effective text thickness to GetTextBox // when calculating the bounding box linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold ); // Calculate the text bounding box: EDA_RECT rect; if( m_id == REFERENCE ) // multi units have one letter or more added to reference { SCH_FIELD text( *this ); // Make a local copy to change text // because GetBoundingBox() is const text.SetText( GetFullyQualifiedText() ); rect = text.GetTextBox( -1, linewidth ); } else rect = GetTextBox( -1, linewidth ); // Calculate the bounding box position relative to the component: wxPoint origin = parentComponent->GetPosition(); wxPoint pos = m_Pos - origin; wxPoint begin = rect.GetOrigin() - origin; wxPoint end = rect.GetEnd() - origin; RotatePoint( &begin, pos, m_Orient ); RotatePoint( &end, pos, m_Orient ); // Due to the Y axis direction, we must mirror the bounding box, // relative to the text position: begin.y -= pos.y; end.y -= pos.y; NEGATE( begin.y ); NEGATE( end.y ); begin.y += pos.y; end.y += pos.y; // Now, apply the component transform (mirror/rot) begin = parentComponent->GetTransform().TransformCoordinate( begin ); end = parentComponent->GetTransform().TransformCoordinate( end ); rect.SetOrigin( begin); rect.SetEnd( end); rect.Move( origin ); rect.Normalize(); return rect; }
bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation ) { bool match; wxString text = GetFullyQualifiedText(); // User defined fields have an ID of -1. if( ((m_id > VALUE || m_id < REFERENCE) && !(aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS)) || ((m_id == REFERENCE) && !(aSearchData.GetFlags() & FR_REPLACE_REFERENCES)) ) return false; wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText() ); // Take sheet path into account which effects the reference field and the unit for // components with multiple parts. if( m_id == REFERENCE && aAuxData != NULL ) { SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent; wxCHECK_MSG( component != NULL, false, wxT( "No component associated with field" ) + text ); text = component->GetRef( (SCH_SHEET_PATH*) aAuxData ); if( component->GetPartCount() > 1 ) text << LIB_COMPONENT::ReturnSubReference( component->GetUnit() ); } match = SCH_ITEM::Matches( text, aSearchData ); if( match ) { if( aFindLocation ) *aFindLocation = GetBoundingBox().Centre(); return true; } return false; }
void SCH_FIELD::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offset, GR_DRAWMODE DrawMode, EDA_COLOR_T Color ) { int orient; EDA_COLOR_T color; wxPoint textpos; SCH_COMPONENT* parentComponent = (SCH_COMPONENT*) m_Parent; int LineWidth = m_Thickness; if( LineWidth == 0 ) // Use default values for pen size { if( m_Bold ) LineWidth = GetPenSizeForBold( m_Size.x ); else LineWidth = GetDefaultLineThickness(); } // Clip pen size for small texts: LineWidth = Clamp_Text_PenSize( LineWidth, m_Size, m_Bold ); if( ((m_Attributs & TEXT_NO_VISIBLE) && !m_forceVisible) || IsVoid() ) return; GRSetDrawMode( DC, DrawMode ); // Calculate the text orientation according to the component orientation. orient = m_Orient; if( parentComponent->GetTransform().y1 ) // Rotate component 90 degrees. { if( orient == TEXT_ORIENT_HORIZ ) orient = TEXT_ORIENT_VERT; else orient = TEXT_ORIENT_HORIZ; } /* Calculate the text justification, according to the component * orientation/mirror this is a bit complicated due to cumulative * calculations: * - numerous cases (mirrored or not, rotation) * - the DrawGraphicText function recalculate also H and H justifications * according to the text orientation. * - When a component is mirrored, the text is not mirrored and * justifications are complicated to calculate * so the more easily way is to use no justifications ( Centered text ) * and use GetBoundaryBox to know the text coordinate considered as centered */ EDA_RECT boundaryBox = GetBoundingBox(); textpos = boundaryBox.Centre(); if( m_forceVisible ) { color = DARKGRAY; } else { if( m_id == REFERENCE ) color = GetLayerColor( LAYER_REFERENCEPART ); else if( m_id == VALUE ) color = GetLayerColor( LAYER_VALUEPART ); else color = GetLayerColor( LAYER_FIELDS ); } EDA_RECT* clipbox = panel? panel->GetClipBox() : NULL; DrawGraphicText( clipbox, DC, textpos, color, GetFullyQualifiedText(), orient, m_Size, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, LineWidth, m_Italic, m_Bold ); // While moving: don't loose visual contact to which component this label belongs. if ( IsWireImage() ) { const wxPoint origin = parentComponent->GetPosition(); textpos = m_Pos - origin; textpos = parentComponent->GetScreenCoord( textpos ); textpos += parentComponent->GetPosition(); GRLine( clipbox, DC, origin.x, origin.y, textpos.x, textpos.y, 2, DARKGRAY ); } /* Enable this to draw the bounding box around the text field to validate * the bounding box calculations. */ #if 0 // Draw boundary box: GRRect( panel->GetClipBox(), DC, boundaryBox, 0, BROWN ); // Draw the text anchor point /* Calculate the text position, according to the component * orientation/mirror */ textpos = m_Pos - parentComponent->GetPosition(); textpos = parentComponent->GetScreenCoord( textpos ); textpos += parentComponent->GetPosition(); const int len = 10; GRLine( clipbox, DC, textpos.x - len, textpos.y, textpos.x + len, textpos.y, 0, BLUE ); GRLine( clipbox, DC, textpos.x, textpos.y - len, textpos.x, textpos.y + len, 0, BLUE ); #endif }