~pierre-parent-k/kicad/length-tunning

« back to all changes in this revision

Viewing changes to eeschema/lib_field.cpp

  • Committer: Pierre Parent
  • Date: 2014-07-06 10:32:13 UTC
  • mfrom: (4798.1.179 kicad)
  • Revision ID: pierre.parent@insa-rouen.fr-20140706103213-wjsdy0hc9q6wbz5v
Merge with lp:kicad 4977

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
void LIB_FIELD::Init( int id )
68
68
{
69
69
    m_id = id;
70
 
    m_Size.x = m_Size.y = DEFAULT_SIZE_TEXT;
 
70
    m_Size.x = GetDefaultTextSize();
 
71
    m_Size.y = GetDefaultTextSize();
71
72
    m_typeName = _( "Field" );
72
73
    m_Orient = TEXT_ORIENT_HORIZ;
73
74
    m_rotate = false;
320
321
}
321
322
 
322
323
 
323
 
bool LIB_FIELD::HitTest( const wxPoint& aPosition )
 
324
bool LIB_FIELD::HitTest( const wxPoint& aPosition ) const
324
325
{
325
326
    // Because HitTest is mainly used to select the field
326
327
    // return always false if this field is void
331
332
}
332
333
 
333
334
 
334
 
bool LIB_FIELD::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform )
 
335
bool LIB_FIELD::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
335
336
{
336
337
    if( aThreshold < 0 )
337
338
        aThreshold = 0;
338
339
 
339
 
    int extraCharCount = 0;
 
340
    // Build a temporary copy of the text for hit testing
 
341
    EDA_TEXT tmp_text( *this );
340
342
 
341
343
    // Reference designator text has one or 2 additional character (displays
342
344
    // U? or U?A)
343
345
    if( m_id == REFERENCE )
344
346
    {
345
 
        extraCharCount++;
346
 
        m_Text.Append('?');
347
 
        LIB_COMPONENT* parent = (LIB_COMPONENT*)m_Parent;
 
347
        wxString extended_text = tmp_text.GetText();
 
348
        extended_text.Append('?');
 
349
        const LIB_COMPONENT* parent = static_cast<const LIB_COMPONENT*>( m_Parent );
348
350
 
349
351
        if ( parent && ( parent->GetPartCount() > 1 ) )
350
 
        {
351
 
            m_Text.Append('A');
352
 
            extraCharCount++;
353
 
        }
 
352
            extended_text.Append('A');
 
353
        tmp_text.SetText( extended_text );
354
354
    }
355
355
 
356
 
    wxPoint physicalpos = aTransform.TransformCoordinate( m_Pos );
357
 
    wxPoint tmp = m_Pos;
358
 
    m_Pos = physicalpos;
 
356
    tmp_text.SetTextPosition( aTransform.TransformCoordinate( m_Pos ) );
359
357
 
360
358
    /* The text orientation may need to be flipped if the
361
359
     *  transformation matrix causes xy axes to be flipped.
362
360
     * this simple algo works only for schematic matrix (rot 90 or/and mirror)
363
361
     */
364
362
    int t1 = ( aTransform.x1 != 0 ) ^ ( m_Orient != 0 );
365
 
    int orient = t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT;
366
 
    EXCHG( m_Orient, orient );
367
 
 
368
 
    bool hit = TextHitTest( aPosition );
369
 
 
370
 
    EXCHG( m_Orient, orient );
371
 
    m_Pos = tmp;
372
 
 
373
 
    while( extraCharCount-- )
374
 
        m_Text.RemoveLast( );
375
 
 
376
 
    return hit;
 
363
    tmp_text.SetOrientation( t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT );
 
364
 
 
365
    return tmp_text.TextHitTest( aPosition );
377
366
}
378
367
 
379
368