Commit 424aac6c authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio
Browse files

TEXTE_MODULE cleanup in preparation for text on different layers

- Removed the friends MODULE and FOOTPRINT_EDIT_FRAME from TEXTE_MODULE
  (as in the @todo comment)

- Refactored the Rotate/Flip/Mirror for text in modules into the
  TEXTE_MODULE class itself (members RotateWithModule, FlipWithModule,
  MirrorWithModule)

- New behaviour in coloring text on screen: reference and value still
  take the color from the MOD_TEXT_FR_VISIBLE and MOD_TEXT_BK_VISIBLE
  visibles; other text takes the color of the layer containing it
  (except when hidden, obviously) but still get its visibility
  controlled by those visibles (probably the most intuitive and useful
  behaviour)

- Still need to decide: should text on a layer be hidden when the layer
  is? Probably yes (still to be implemented);

- Some comment fixed and many cast converted to static_cast
parent edb7cd60
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ public:
     * </p>
     * @return a const wxString object containing the string of the item.
     */
    virtual const wxString GetText() const { return m_Text; }
    virtual const wxString& GetText() const { return m_Text; }

    virtual void SetText( const wxString& aText ) { m_Text = aText; }

+7 −25
Original line number Diff line number Diff line
@@ -461,11 +461,7 @@ void MoveMarkedItems( MODULE* module, wxPoint offset )
        switch( item->Type() )
        {
        case PCB_MODULE_TEXT_T:
        {
            TEXTE_MODULE* tm = (TEXTE_MODULE*) item;
            tm->Offset( offset );
            tm->SetPos0( tm->GetPos0() + offset );
        }
            static_cast<TEXTE_MODULE*>( item )->Move( offset );
            break;

        case PCB_MODULE_EDGE_T:
@@ -588,14 +584,7 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all )
            break;

        case PCB_MODULE_TEXT_T:
            {
                TEXTE_MODULE* tm = (TEXTE_MODULE*) item;
                tmp = tm->GetTextPosition();
                SETMIRROR( tmp.x );
                tm->SetTextPosition( tmp );
                tmp.y = tm->GetPos0().y;
                tm->SetPos0( tmp );
            }
            static_cast<TEXTE_MODULE*>( item )->MirrorWithModule( offset.x );
            break;

        default:
@@ -655,18 +644,11 @@ void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all )
        break;

        case PCB_MODULE_TEXT_T:
        {
            TEXTE_MODULE* tm = (TEXTE_MODULE*) item;
            wxPoint pos = tm->GetTextPosition();
            ROTATE( pos );
            tm->SetTextPosition( pos );
            tm->SetPos0( tm->GetTextPosition() );
            tm->SetOrientation( tm->GetOrientation() + 900 );
        }
            static_cast<TEXTE_MODULE*>( item )->RotateWithModule( wxPoint( 0, 0 ), 900 );
            break;

        default:
            ;
            break;
        }

        item->ClearFlags();
@@ -742,7 +724,7 @@ int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect )
            break;

        case PCB_MODULE_TEXT_T:
            pos = ( (TEXTE_MODULE*) item )->GetTextPosition();
            pos = static_cast<TEXTE_MODULE*>( item )->GetTextPosition();

            if( Rect.Contains( pos ) )
            {
+6 −3
Original line number Diff line number Diff line
@@ -168,9 +168,12 @@ void MODULE::TransformGraphicShapesWithClearanceToPolygonSet(
        switch( item->Type() )
        {
        case PCB_MODULE_TEXT_T:
            if( ((TEXTE_MODULE*)item)->GetLayer() == aLayer )
                texts.push_back( (TEXTE_MODULE *) item );
            {
                TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
                if( text->GetLayer() == aLayer )
                    texts.push_back( text );
                break;
            }

        case PCB_MODULE_EDGE_T:
            outline = (EDGE_MODULE*) item;
+2 −2
Original line number Diff line number Diff line
@@ -168,8 +168,8 @@ void BOARD::Move( const wxPoint& aMoveVector ) // overload
        PCB_TARGET_T,
        PCB_VIA_T,
        PCB_TRACE_T,
        //        PCB_PAD_T,
        //        PCB_MODULE_TEXT_T,
        //        PCB_PAD_T,            Can't be at board level
        //        PCB_MODULE_TEXT_T,    Can't be at board level
        PCB_MODULE_T,
        PCB_ZONE_AREA_T,
        EOT
+41 −59
Original line number Diff line number Diff line
@@ -72,8 +72,8 @@ MODULE::MODULE( BOARD* parent ) :
    m_ThermalWidth = 0; // Use zone setting by default
    m_ThermalGap = 0; // Use zone setting by default

    // These are special and mandatory text fields
    m_Reference = new TEXTE_MODULE( this, TEXTE_MODULE::TEXT_is_REFERENCE );

    m_Value = new TEXTE_MODULE( this, TEXTE_MODULE::TEXT_is_VALUE );

    // Reserve one void 3D entry, to avoid problems with void list
@@ -131,7 +131,7 @@ MODULE::MODULE( const MODULE& aModule ) :
        {
        case PCB_MODULE_TEXT_T:
        case PCB_MODULE_EDGE_T:
            newItem = (BOARD_ITEM*)item->Clone();
            newItem = static_cast<BOARD_ITEM*>( item->Clone() );
            newItem->SetParent( this );
            m_Drawings.PushBack( newItem );
            break;
@@ -242,18 +242,21 @@ void MODULE::Copy( MODULE* aModule )
        switch( item->Type() )
        {
        case PCB_MODULE_TEXT_T:
            TEXTE_MODULE * textm;
            textm = new TEXTE_MODULE( this );
            textm->Copy( (TEXTE_MODULE*) item );
            {
                TEXTE_MODULE* textm = new TEXTE_MODULE( this );
                textm->Copy( static_cast<TEXTE_MODULE*>( item ) );
                m_Drawings.PushBack( textm );
                break;
            }

        case PCB_MODULE_EDGE_T:
            {
                EDGE_MODULE * edge;
                edge = new EDGE_MODULE( this );
                edge->Copy( (EDGE_MODULE*) item );
                m_Drawings.PushBack( edge );
                break;
            }

        default:
            wxLogMessage( wxT( "MODULE::Copy() Internal Err:  unknown type" ) );
@@ -299,9 +302,10 @@ void MODULE::Add( BOARD_ITEM* aBoardItem, bool doAppend )
    switch( aBoardItem->Type() )
    {
    case PCB_MODULE_TEXT_T:
        // Only common texts can be added this way. Reference and value are not hold in the DLIST.
        // Only user texts can be added this way. Reference and value are not hold in the DLIST.
        assert( static_cast<TEXTE_MODULE*>( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS );
        /* no break */

        // no break

    case PCB_MODULE_EDGE_T:
        if( doAppend )
@@ -337,9 +341,10 @@ BOARD_ITEM* MODULE::Remove( BOARD_ITEM* aBoardItem )
    switch( aBoardItem->Type() )
    {
    case PCB_MODULE_TEXT_T:
        // Only common texts can be added this way. Reference and value are not hold in the DLIST.
        // Only user texts can be removed this way. Reference and value are not hold in the DLIST.
        assert( static_cast<TEXTE_MODULE*>( aBoardItem )->GetType() == TEXTE_MODULE::TEXT_is_DIVERS );
        /* no break */

        // no break

    case PCB_MODULE_EDGE_T:
        return m_Drawings.Remove( static_cast<BOARD_ITEM*>( aBoardItem ) );
@@ -912,8 +917,6 @@ void MODULE::Rotate( const wxPoint& aRotCentre, double aAngle )

void MODULE::Flip( const wxPoint& aCentre )
{
    TEXTE_MODULE* text;

    // Move module to its final position:
    wxPoint finalPos = m_Pos;

@@ -933,24 +936,10 @@ void MODULE::Flip( const wxPoint& aCentre )
        pad->Flip( m_Pos );

    // Mirror reference.
    text = m_Reference;
    text->m_Pos.y -= m_Pos.y;
    NEGATE( text->m_Pos.y );
    text->m_Pos.y += m_Pos.y;
    NEGATE(text->m_Pos0.y);
    NEGATE_AND_NORMALIZE_ANGLE_POS( text->m_Orient );
    text->SetLayer( FlipLayer( text->GetLayer() ) );
    text->m_Mirror = IsBackLayer( GetLayer() );
    m_Reference->FlipWithModule( m_Pos.y );

    // Mirror value.
    text = m_Value;
    text->m_Pos.y -= m_Pos.y;
    NEGATE( text->m_Pos.y );
    text->m_Pos.y += m_Pos.y;
    NEGATE( text->m_Pos0.y );
    NEGATE_AND_NORMALIZE_ANGLE_POS( text->m_Orient );
    text->SetLayer( FlipLayer( text->GetLayer() ) );
    text->m_Mirror = IsBackLayer( GetLayer() );
    m_Value->FlipWithModule( m_Pos.y );

    // Reverse mirror module graphics and texts.
    for( EDA_ITEM* item = m_Drawings; item; item = item->Next() )
@@ -986,14 +975,7 @@ void MODULE::Flip( const wxPoint& aCentre )
            break;

        case PCB_MODULE_TEXT_T:
            text = (TEXTE_MODULE*) item;
            text->m_Pos.y -= m_Pos.y;
            NEGATE( text->m_Pos.y );
            text->m_Pos.y += m_Pos.y;
            NEGATE( text->m_Pos0.y );
            NEGATE_AND_NORMALIZE_ANGLE_POS( text->m_Orient );
            text->SetLayer( FlipLayer( text->GetLayer() ) );
            text->m_Mirror = IsBackLayer( GetLayer() );
            static_cast<TEXTE_MODULE*>( item )->FlipWithModule( m_Pos.y );
            break;

        default:
@@ -1032,8 +1014,8 @@ void MODULE::SetPosition( const wxPoint& newpos )

        case PCB_MODULE_TEXT_T:
        {
            TEXTE_MODULE* text = (TEXTE_MODULE*) item;
            text->m_Pos += delta;
            TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
            text->SetTextPosition( text->GetTextPosition() + delta );
            break;
        }

@@ -1083,19 +1065,21 @@ void MODULE::MoveAnchorPosition( const wxPoint& aMoveVector )
        switch( item->Type() )
        {
        case PCB_MODULE_EDGE_T:
            #undef STRUCT
            #define STRUCT ( (EDGE_MODULE*) item )
            STRUCT->m_Start0 += moveVector;
            STRUCT->m_End0   += moveVector;
            STRUCT->SetDrawCoord();
            {
                EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
                edge->m_Start0 += moveVector;
                edge->m_End0   += moveVector;
                edge->SetDrawCoord();
                break;
            }

        case PCB_MODULE_TEXT_T:
            #undef STRUCT
            #define STRUCT ( (TEXTE_MODULE*) item )
            STRUCT->SetPos0( STRUCT->GetPos0() + moveVector );
            STRUCT->SetDrawCoord();
            {
                TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
                text->SetPos0( text->GetPos0() + moveVector );
                text->SetDrawCoord();
                break;
            }

        default:
            break;
@@ -1135,14 +1119,12 @@ void MODULE::SetOrientation( double newangle )
    {
        if( item->Type() == PCB_MODULE_EDGE_T )
        {
            EDGE_MODULE* edge = (EDGE_MODULE*) item;
            edge->SetDrawCoord();
            static_cast<EDGE_MODULE*>( item )->SetDrawCoord();
        }

        else if( item->Type() == PCB_MODULE_TEXT_T )
        {
            TEXTE_MODULE* text = (TEXTE_MODULE*) item;
            text->SetDrawCoord();
            static_cast<TEXTE_MODULE*>( item )->SetDrawCoord();
        }
    }

Loading