Commit b0923f78 authored by Pascal Baerten's avatar Pascal Baerten Committed by jean-pierre charras
Browse files

added eeschema rotate block patch from Pascal Baerten. Uncrustify files. fixed some issues.

Some minor issues (sheet and pin sheet rotate from menu) must be added
parents 4e3e2108 352dcb38
Loading
Loading
Loading
Loading
+78 −35
Original line number Original line Diff line number Diff line
@@ -21,6 +21,10 @@
// Imported functions:
// Imported functions:
void            MoveItemsInList( PICKED_ITEMS_LIST& aItemsList,
void            MoveItemsInList( PICKED_ITEMS_LIST& aItemsList,
                                 const wxPoint      aMoveVector );
                                 const wxPoint      aMoveVector );
void            RotateListOfItems( PICKED_ITEMS_LIST& aItemsList,
                                   wxPoint&           Center );
void            Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList,
                                      wxPoint&           aMirrorPoint );
void            MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList,
void            MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList,
                                   wxPoint&           Center );
                                   wxPoint&           Center );
void            DeleteItemsInList( WinEDA_DrawPanel*  panel,
void            DeleteItemsInList( WinEDA_DrawPanel*  panel,
@@ -124,6 +128,9 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
        err = TRUE;
        err = TRUE;
        break;
        break;


    case BLOCK_ROTATE:
    case BLOCK_MIRROR_X:
    case BLOCK_MIRROR_Y:
    case BLOCK_DRAG:        /* Drag */
    case BLOCK_DRAG:        /* Drag */
    case BLOCK_MOVE:        /* Move */
    case BLOCK_MOVE:        /* Move */
        if( DrawPanel->ManageCurseur )
        if( DrawPanel->ManageCurseur )
@@ -163,9 +170,6 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
    case BLOCK_ZOOM:        // Handled by HandleBlockEnd()
    case BLOCK_ZOOM:        // Handled by HandleBlockEnd()
    case BLOCK_DELETE:
    case BLOCK_DELETE:
    case BLOCK_SAVE:
    case BLOCK_SAVE:
    case BLOCK_ROTATE:
    case BLOCK_MIRROR_X:
    case BLOCK_MIRROR_Y:
    case BLOCK_FLIP:
    case BLOCK_FLIP:
    case BLOCK_ABORT:
    case BLOCK_ABORT:
    case BLOCK_SELECT_ITEMS_ONLY:
    case BLOCK_SELECT_ITEMS_ONLY:
@@ -240,6 +244,9 @@ int WinEDA_SchematicFrame::HandleBlockEnd( wxDC* DC )
        case BLOCK_DRAG:    /* Drag */
        case BLOCK_DRAG:    /* Drag */
            BreakSegmentOnJunction( (SCH_SCREEN*) GetScreen() );
            BreakSegmentOnJunction( (SCH_SCREEN*) GetScreen() );


        case BLOCK_ROTATE:
        case BLOCK_MIRROR_X:
        case BLOCK_MIRROR_Y:
        case BLOCK_MOVE:    /* Move */
        case BLOCK_MOVE:    /* Move */
        case BLOCK_COPY:    /* Copy */
        case BLOCK_COPY:    /* Copy */
            PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
            PickItemsInBlock( GetScreen()->m_BlockLocate, GetScreen() );
@@ -298,10 +305,6 @@ int WinEDA_SchematicFrame::HandleBlockEnd( wxDC* DC )
        case BLOCK_FLIP: /* pcbnew only! */
        case BLOCK_FLIP: /* pcbnew only! */
            break;
            break;


        case BLOCK_ROTATE:
        case BLOCK_MIRROR_X:
        case BLOCK_MIRROR_Y:
            break;


        case BLOCK_ZOOM: /* Window Zoom */
        case BLOCK_ZOOM: /* Window Zoom */
            zoom_command = TRUE;
            zoom_command = TRUE;
@@ -425,15 +428,53 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )




    case BLOCK_ROTATE:
    case BLOCK_ROTATE:
        if( DrawPanel->ManageCurseur )
            DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
        if( block->GetCount() )
        {
            ii = 1;
            /* Compute the rotation center and put it on grid */
            wxPoint rotationPoint = block->Centre();
            PutOnGrid( &rotationPoint );
            SaveCopyInUndoList( block->m_ItemsSelection,
                                UR_ROTATED,
                                rotationPoint );
            RotateListOfItems( block->m_ItemsSelection, rotationPoint );
            OnModify();
        }
        TestDanglingEnds( GetScreen()->EEDrawList, DC );
        DrawPanel->Refresh();
        block->m_State   = STATE_BLOCK_MOVE;
        block->m_Command = BLOCK_MOVE; //allows multiple rotate
        break;
        break;


    case BLOCK_MIRROR_X:
    case BLOCK_MIRROR_X:
        if( DrawPanel->ManageCurseur )
            DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
        if( block->GetCount() )
        {
            ii = 1;
            /* Compute the mirror center and put it on grid */
            wxPoint mirrorPoint = block->Centre();
            PutOnGrid( &mirrorPoint );
            SaveCopyInUndoList( block->m_ItemsSelection,
                                UR_MIRRORED_X,
                                mirrorPoint );
            Mirror_X_ListOfItems( block->m_ItemsSelection, mirrorPoint );
            OnModify();
            block->m_State   = STATE_BLOCK_MOVE;
            block->m_Command = BLOCK_MOVE; //allows multiple mirrors
        }
        TestDanglingEnds( GetScreen()->EEDrawList, DC );
        DrawPanel->Refresh();
        break;

    case BLOCK_MIRROR_Y:
    case BLOCK_MIRROR_Y:
        if( DrawPanel->ManageCurseur )
        if( DrawPanel->ManageCurseur )
            DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
            DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
        if( block->GetCount() )
        if( block->GetCount() )
        {
        {
            ii = -1;
            ii = 1;
            /* Compute the mirror center and put it on grid */
            /* Compute the mirror center and put it on grid */
            wxPoint mirrorPoint = block->Centre();
            wxPoint mirrorPoint = block->Centre();
            PutOnGrid( &mirrorPoint );
            PutOnGrid( &mirrorPoint );
@@ -442,6 +483,8 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )
                                mirrorPoint );
                                mirrorPoint );
            MirrorListOfItems( block->m_ItemsSelection, mirrorPoint );
            MirrorListOfItems( block->m_ItemsSelection, mirrorPoint );
            OnModify();
            OnModify();
            block->m_State   = STATE_BLOCK_MOVE;
            block->m_Command = BLOCK_MOVE; //allows multiple mirrors
        }
        }
        TestDanglingEnds( GetScreen()->EEDrawList, DC );
        TestDanglingEnds( GetScreen()->EEDrawList, DC );
        DrawPanel->Refresh();
        DrawPanel->Refresh();
@@ -515,6 +558,7 @@ void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList )


    /* save the new list: */
    /* save the new list: */
    ITEM_PICKER item;
    ITEM_PICKER item;

    // In list the wrapper is owner of the shematic item, we can use the UR_DELETED
    // In list the wrapper is owner of the shematic item, we can use the UR_DELETED
    // status for the picker because pickers with this status are owner of the picked item
    // status for the picker because pickers with this status are owner of the picked item
    // (or TODO ?: create a new status like UR_DUPLICATE)
    // (or TODO ?: create a new status like UR_DUPLICATE)
@@ -677,8 +721,7 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
            SCH_SHEET* sheet = (SCH_SHEET*) Struct;
            SCH_SHEET* sheet = (SCH_SHEET*) Struct;


            // Add all pins sheets of a selected hierarchical sheet to the list
            // Add all pins sheets of a selected hierarchical sheet to the list
            BOOST_FOREACH( SCH_SHEET_PIN label, sheet->GetSheetPins() )
            BOOST_FOREACH( SCH_SHEET_PIN label, sheet->GetSheetPins() ) {
            {
                AddPickedItem( screen, label.m_Pos );
                AddPickedItem( screen, label.m_Pos );
            }
            }
        }
        }
+60 −19
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@
#include "class_drawpanel.h"
#include "class_drawpanel.h"
#include "drawtxt.h"
#include "drawtxt.h"
#include "confirm.h"
#include "confirm.h"
#include "trigo.h"


#include "program.h"
#include "program.h"
#include "general.h"
#include "general.h"
@@ -204,6 +205,16 @@ bool SCH_SHEET::HasLabel( const wxString& aName )
    return false;
    return false;
}
}


bool SCH_SHEET::IsVerticalOrientation()
{ 
    BOOST_FOREACH( SCH_SHEET_PIN label, m_labels )
    {
        if( label.GetEdge()>1 ) 
        return true;
    }
    return false;   
}



bool SCH_SHEET::HasUndefinedLabels()
bool SCH_SHEET::HasUndefinedLabels()
{
{
@@ -316,18 +327,7 @@ SCH_SHEET_PIN* SCH_SHEET::GetLabel( const wxPoint& aPosition )


    BOOST_FOREACH( SCH_SHEET_PIN& label, m_labels )
    BOOST_FOREACH( SCH_SHEET_PIN& label, m_labels )
    {
    {
        size = ( label.GetLength() + 1 ) * label.m_Size.x;
        if (label.HitTest(aPosition)) return &label;
        if( label.m_Edge )
            size = -size;
        minx = label.m_Pos.x;
        maxx = label.m_Pos.x + size;
        if( maxx < minx )
            EXCHG( maxx, minx );
        dy = label.m_Size.x / 2;

        if( ( ABS( aPosition.y - label.m_Pos.y ) <= dy )
            && ( aPosition.x <= maxx ) && ( aPosition.x >= minx ) )
            return &label;
    }
    }


    return NULL;
    return NULL;
@@ -358,6 +358,8 @@ void SCH_SHEET::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
    int      txtcolor;
    int      txtcolor;
    wxString Text;
    wxString Text;
    int      color;
    int      color;
    int      name_orientation;
    wxPoint  pos_sheetname,pos_filename;
    wxPoint  pos = m_Pos + aOffset;
    wxPoint  pos = m_Pos + aOffset;
    int      LineWidth = g_DrawDefaultLineThickness;
    int      LineWidth = g_DrawDefaultLineThickness;


@@ -369,7 +371,18 @@ void SCH_SHEET::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,


    GRRect( &aPanel->m_ClipBox, aDC, pos.x, pos.y,
    GRRect( &aPanel->m_ClipBox, aDC, pos.x, pos.y,
            pos.x + m_Size.x, pos.y + m_Size.y, LineWidth, color );
            pos.x + m_Size.x, pos.y + m_Size.y, LineWidth, color );

    if (IsVerticalOrientation()) 
    {
        pos_sheetname=wxPoint( pos.x-8, pos.y+m_Size.y );
        pos_filename=wxPoint( pos.x+m_Size.x+4, pos.y+m_Size.y );
        name_orientation=TEXT_ORIENT_VERT;
    }
    else
    {
        pos_sheetname=wxPoint( pos.x, pos.y - 8 );
        pos_filename=wxPoint( pos.x, pos.y + m_Size.y + 4 );
        name_orientation=TEXT_ORIENT_HORIZ;
    }
    /* Draw text : SheetName */
    /* Draw text : SheetName */
    if( aColor > 0 )
    if( aColor > 0 )
        txtcolor = aColor;
        txtcolor = aColor;
@@ -377,8 +390,8 @@ void SCH_SHEET::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
        txtcolor = ReturnLayerColor( LAYER_SHEETNAME );
        txtcolor = ReturnLayerColor( LAYER_SHEETNAME );


    Text = wxT( "Sheet: " ) + m_SheetName;
    Text = wxT( "Sheet: " ) + m_SheetName;
    DrawGraphicText( aPanel, aDC, wxPoint( pos.x, pos.y - 8 ),
    DrawGraphicText( aPanel, aDC, pos_sheetname,
                     (EDA_Colors) txtcolor, Text, TEXT_ORIENT_HORIZ,
                     (EDA_Colors) txtcolor, Text, name_orientation,
                     wxSize( m_SheetNameSize, m_SheetNameSize ),
                     wxSize( m_SheetNameSize, m_SheetNameSize ),
                     GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_BOTTOM, LineWidth,
                     GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_BOTTOM, LineWidth,
                     false, false, false );
                     false, false, false );
@@ -389,8 +402,8 @@ void SCH_SHEET::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
    else
    else
        txtcolor = ReturnLayerColor( LAYER_SHEETFILENAME );
        txtcolor = ReturnLayerColor( LAYER_SHEETFILENAME );
    Text = wxT( "File: " ) + m_FileName;
    Text = wxT( "File: " ) + m_FileName;
    DrawGraphicText( aPanel, aDC, wxPoint( pos.x, pos.y + m_Size.y + 4 ),
    DrawGraphicText( aPanel, aDC, pos_filename,
                     (EDA_Colors) txtcolor, Text, TEXT_ORIENT_HORIZ,
                     (EDA_Colors) txtcolor, Text, name_orientation,
                     wxSize( m_FileNameSize, m_FileNameSize ),
                     wxSize( m_FileNameSize, m_FileNameSize ),
                     GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_TOP, LineWidth,
                     GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_TOP, LineWidth,
                     false, false, false );
                     false, false, false );
@@ -741,6 +754,34 @@ void SCH_SHEET::DisplayInfo( WinEDA_DrawFrame* frame )
}
}




void SCH_SHEET::Rotate(wxPoint rotationPoint)
{
    RotatePoint(&m_Pos,rotationPoint,900);
    RotatePoint(&m_Size.x,&m_Size.y,900);
    if (m_Size.x<0) {
        m_Pos.x+=m_Size.x;
        NEGATE(m_Size.x);
    }
    if (m_Size.y<0) {
        m_Pos.y+=m_Size.y;
        NEGATE(m_Size.y);
    }
    BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, m_labels )
    {
        sheetPin.Rotate( rotationPoint );
    }
}
void SCH_SHEET::Mirror_X( int aXaxis_position )
{
    m_Pos.y -= aXaxis_position;
    NEGATE( m_Pos.y );
    m_Pos.y += aXaxis_position;
    m_Pos.y -= m_Size.y;
    BOOST_FOREACH( SCH_SHEET_PIN& sheetPin, m_labels )
    {
        sheetPin.Mirror_X( aXaxis_position );
    }
}
/** virtual function Mirror_Y
/** virtual function Mirror_Y
 * mirror item relative to an Y axis
 * mirror item relative to an Y axis
 * @param aYaxis_position = the y axis position
 * @param aYaxis_position = the y axis position
@@ -770,8 +811,7 @@ void SCH_SHEET::Resize( const wxSize& aSize )
    /* Move the sheet labels according to the new sheet size. */
    /* Move the sheet labels according to the new sheet size. */
    BOOST_FOREACH( SCH_SHEET_PIN& label, m_labels )
    BOOST_FOREACH( SCH_SHEET_PIN& label, m_labels )
    {
    {
        if( label.m_Edge )
        label.ConstraintOnEdge(label.m_Pos);
            label.m_Pos.x = m_Pos.x + m_Size.x;
    }
    }
}
}


@@ -817,3 +857,4 @@ void SCH_SHEET::Show( int nestLevel, std::ostream& os )
}
}


#endif
#endif
+60 −49
Original line number Original line Diff line number Diff line
@@ -8,7 +8,7 @@
#include "base_struct.h"
#include "base_struct.h"
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/foreach.hpp>
#include <boost/foreach.hpp>

#include "class_text-label.h"


extern SCH_SHEET* g_RootSheet;
extern SCH_SHEET* g_RootSheet;


@@ -22,17 +22,29 @@ extern SCH_SHEET* g_RootSheet;
 * connected to a wire, bus, or label.  In the schematic page represented by
 * connected to a wire, bus, or label.  In the schematic page represented by
 * the sheet, it corresponds to a hierarchical label.
 * the sheet, it corresponds to a hierarchical label.
 */
 */
class SCH_SHEET_PIN : public SCH_ITEM, public EDA_TextStruct

//class SCH_SHEET_PIN : public SCH_ITEM, public EDA_TextStruct
class SCH_SHEET_PIN : public SCH_HIERLABEL
{
{
private:
private:
    int m_Number;       ///< Label number use for saving sheet label to file.
    int m_Number;       ///< Label number use for saving sheet label to file.
                        ///< Sheet label numbering begins at 2.
                        ///< Sheet label numbering begins at 2.
                        ///< 0 is reserved for the sheet name.
                        ///< 0 is reserved for the sheet name.
                        ///< 1 is reserve for the sheet file name.
                        ///< 1 is reserve for the sheet file name.
    int m_Edge;                     /* For pin labels only: sheet edge (0 to 3) of the pin
                                     * m_Edge define on which edge the pin is positionned:
                                     *        0: pin on left side
                                     *        1: pin on right side
                                     *        2: pin on top side
                                     *        3: pin on bottom side
                                     *  for compatibility reasons, this does not follow same values as text
                                     *  orientation.
                                     */


public:
public:
    int  m_Edge, m_Shape;

    bool m_IsDangling;  // TRUE non connected
    //int m_Shape;
    //bool m_IsDangling;  // TRUE non connected


public:
public:
    SCH_SHEET_PIN( SCH_SHEET* parent,
    SCH_SHEET_PIN( SCH_SHEET* parent,
@@ -46,6 +58,7 @@ public:
        return wxT( "SCH_SHEET_PIN" );
        return wxT( "SCH_SHEET_PIN" );
    }
    }



    bool operator  ==( const SCH_SHEET_PIN* aPin ) const;
    bool operator  ==( const SCH_SHEET_PIN* aPin ) const;


    SCH_SHEET_PIN* GenCopy();
    SCH_SHEET_PIN* GenCopy();
@@ -55,6 +68,8 @@ public:
        return (SCH_SHEET_PIN*) Pnext;
        return (SCH_SHEET_PIN*) Pnext;
    }
    }


    void SwapData( SCH_SHEET_PIN* copyitem );

    /**
    /**
     * Get the sheet label number.
     * Get the sheet label number.
     *
     *
@@ -68,6 +83,9 @@ public:
     * @param aNumber - New sheet number label.
     * @param aNumber - New sheet number label.
     */
     */
    void        SetNumber( int aNumber );
    void        SetNumber( int aNumber );
    void        SetEdge( int aEdge );
    int         GetEdge();
    void        ConstraintOnEdge( wxPoint Pos );


    /**
    /**
     * Get the parent sheet object of this sheet pin.
     * Get the parent sheet object of this sheet pin.
@@ -79,18 +97,9 @@ public:


    void        Place( WinEDA_SchematicFrame* frame, wxDC* DC );
    void        Place( WinEDA_SchematicFrame* frame, wxDC* DC );


    void Draw( WinEDA_DrawPanel* panel,
/*the functions Draw, CreateGraphicShape and Plot are no removed as
               wxDC*             DC,
 *  as this shape is already handled as HIERLABEL ...
               const wxPoint&    offset,
               int               draw_mode,
               int               Color = -1 );

    /**
     * Plot this sheet pin object to aPlotter.
     *
     * @param aPlotter - The plotter object to plot to.
 */
 */
    void Plot( PLOTTER* aPlotter );


    /**
    /**
     * Function Save
     * Function Save
@@ -118,8 +127,6 @@ public:
     * @param aCorner_list = list to fill with polygon corners coordinates
     * @param aCorner_list = list to fill with polygon corners coordinates
     * @param Pos = Position of the shape
     * @param Pos = Position of the shape
     */
     */
    void        CreateGraphicShape( std::vector <wxPoint>& aCorner_list,
                                    const wxPoint&         Pos );


    // Geometric transforms (used in block operations):
    // Geometric transforms (used in block operations):


@@ -137,13 +144,11 @@ public:
     * mirror item relative to an Y axis
     * mirror item relative to an Y axis
     * @param aYaxis_position = the y axis position
     * @param aYaxis_position = the y axis position
     */
     */
    virtual void Mirror_Y( int aYaxis_position )

    {
    virtual void Mirror_Y( int aYaxis_position );
        m_Edge   = m_Edge ? 0 : 1;
    virtual void Rotate( wxPoint rotationPoint );
        m_Pos.x -= aYaxis_position;
    virtual void Mirror_X( int aXaxis_position );
        NEGATE(  m_Pos.x );

        m_Pos.x += aYaxis_position;
    }


    /**
    /**
     * Compare schematic sheet entry (pin?) name against search string.
     * Compare schematic sheet entry (pin?) name against search string.
@@ -215,6 +220,11 @@ public:
    SCH_SHEET*     GenCopy();
    SCH_SHEET*     GenCopy();
    void           DisplayInfo( WinEDA_DrawFrame* frame );
    void           DisplayInfo( WinEDA_DrawFrame* frame );


    /* there is no member for orientation in sch_sheet, to preserve file
     * format, we detect orientation based on pin edges
     */
    bool           IsVerticalOrientation();

    /**
    /**
     * Add aLabel to this sheet.
     * Add aLabel to this sheet.
     *
     *
@@ -389,8 +399,7 @@ public:
    virtual void Move( const wxPoint& aMoveVector )
    virtual void Move( const wxPoint& aMoveVector )
    {
    {
        m_Pos += aMoveVector;
        m_Pos += aMoveVector;
        BOOST_FOREACH( SCH_SHEET_PIN& label, m_labels )
        BOOST_FOREACH( SCH_SHEET_PIN & label, m_labels ) {
        {
            label.Move( aMoveVector );
            label.Move( aMoveVector );
        }
        }
    }
    }
@@ -401,6 +410,8 @@ public:
     * @param aYaxis_position = the y axis position
     * @param aYaxis_position = the y axis position
     */
     */
    virtual void Mirror_Y( int aYaxis_position );
    virtual void Mirror_Y( int aYaxis_position );
    virtual void Mirror_X( int aXaxis_position );
    virtual void Rotate( wxPoint rotationPoint );


    /**
    /**
     * Compare schematic sheet file and sheet name against search string.
     * Compare schematic sheet file and sheet name against search string.
+172 −136
Original line number Original line Diff line number Diff line
@@ -17,20 +17,33 @@
#include "class_drawpanel.h"
#include "class_drawpanel.h"
#include "drawtxt.h"
#include "drawtxt.h"
#include "plot_common.h"
#include "plot_common.h"
#include "trigo.h"


#include "program.h"
#include "program.h"
#include "general.h"
#include "general.h"
#include "protos.h"
#include "protos.h"


/* m_Edge define on which edge the pin is positionned:
 *
 *        0: pin on left side
 *        1: pin on right side
 *        2: pin on top side
 *        3: pin on bottom side
 *  for compatibility reasons, this does not follow same values as text
 *  ortientation.
 */


SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent, const wxPoint& pos, const wxString& text ) :
SCH_SHEET_PIN::SCH_SHEET_PIN( SCH_SHEET* parent, const wxPoint& pos, const wxString& text ) :
    SCH_ITEM( parent, DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ), EDA_TextStruct( text )
    SCH_HIERLABEL( pos, text, DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE )
{
{
    SetParent( parent );
    wxASSERT( parent );
    wxASSERT( parent );
    wxASSERT( Pnext == NULL );
    m_Layer = LAYER_SHEETLABEL;
    m_Layer = LAYER_SHEETLABEL;
    m_Pos   = pos;
    m_Pos   = pos;
    m_Edge  = 0;
    if( parent->IsVerticalOrientation() )
        SetEdge( 2 );
    else
        SetEdge( 0 );
    m_Shape = NET_INPUT;
    m_Shape = NET_INPUT;
    m_IsDangling = TRUE;
    m_IsDangling = TRUE;
    m_Number     = 2;
    m_Number     = 2;
@@ -41,14 +54,26 @@ SCH_SHEET_PIN* SCH_SHEET_PIN::GenCopy()
{
{
    SCH_SHEET_PIN* newitem = new SCH_SHEET_PIN( (SCH_SHEET*) m_Parent, m_Pos, m_Text );
    SCH_SHEET_PIN* newitem = new SCH_SHEET_PIN( (SCH_SHEET*) m_Parent, m_Pos, m_Text );


    newitem->m_Edge   = m_Edge;
    newitem->SetEdge( GetEdge() );
    newitem->m_Shape = m_Shape;
    newitem->m_Shape = m_Shape;
    newitem->m_Number = m_Number;
    newitem->SetNumber( GetNumber() );

    return newitem;
    return newitem;
}
}




void SCH_SHEET_PIN::SwapData( SCH_SHEET_PIN* copyitem )
{
    SCH_TEXT::SwapData( (SCH_TEXT*) copyitem );
    int tmp;
    tmp = copyitem->GetNumber();
    copyitem->SetNumber( GetNumber() );
    SetNumber( tmp );
    tmp = copyitem->GetEdge();
    copyitem->SetEdge( GetEdge() );
    SetEdge( tmp );
}


bool SCH_SHEET_PIN::operator==( const SCH_SHEET_PIN* aPin ) const
bool SCH_SHEET_PIN::operator==( const SCH_SHEET_PIN* aPin ) const
{
{
    return aPin == this;
    return aPin == this;
@@ -72,153 +97,88 @@ void SCH_SHEET_PIN::SetNumber( int aNumber )
}
}




/*****************************************************************************/
void SCH_SHEET_PIN::SetEdge( int aEdge )
/* Routine to create hierarchical labels */
/*****************************************************************************/
void SCH_SHEET_PIN::Draw( WinEDA_DrawPanel* panel,
                          wxDC*             DC,
                          const wxPoint&    offset,
                          int               DrawMode,
                          int               Color )
{
{
    GRTextHorizJustifyType       side;
    SCH_SHEET* Sheet = (SCH_SHEET*) GetParent();
    EDA_Colors                   txtcolor;
    int posx, tposx, posy;

    static std::vector <wxPoint> Poly;


    int LineWidth = GetPenSize();
    /* use -1 to adjust text orientation without changing edge*/
    if( aEdge > -1 )
        m_Edge = aEdge;
    switch( m_Edge )
    {
    case 0:        /* pin on left side*/
        m_Pos.x = Sheet->m_Pos.x;
        SetSchematicTextOrientation( 2 ); /* Orientation horiz inverse */
        break;


    if( Color >= 0 )
    case 1:        /* pin on right side*/
        txtcolor = (EDA_Colors) Color;
        m_Pos.x = Sheet->m_Pos.x + Sheet->m_Size.x;
    else
        SetSchematicTextOrientation( 0 ); /* Orientation horiz normal */
        txtcolor = ReturnLayerColor( m_Layer );
        break;
    GRSetDrawMode( DC, DrawMode );


    posx = m_Pos.x + offset.x;
    case 2:        /* pin on top side*/
    posy = m_Pos.y + offset.y;
        m_Pos.y = Sheet->m_Pos.y;
    wxSize size = m_Size;
        SetSchematicTextOrientation( 3 ); /* Orientation vert BOTTOM  */
        break;


    if( !m_Text.IsEmpty() )
    case 3:        /* pin on bottom side*/
    {
        m_Pos.y = Sheet->m_Pos.y + Sheet->m_Size.y;
        if( m_Edge )
        SetSchematicTextOrientation( 1 ); /* Orientation vert UP  */
        {
        break;
            tposx = posx - size.x;
            side  = GR_TEXT_HJUSTIFY_RIGHT;
        }
        else
        {
            tposx = posx + size.x + (size.x / 8);
            side  = GR_TEXT_HJUSTIFY_LEFT;
    }
    }
        DrawGraphicText( panel, DC, wxPoint( tposx, posy ), txtcolor,
                         m_Text, TEXT_ORIENT_HORIZ, size, side,
                         GR_TEXT_VJUSTIFY_CENTER, LineWidth, false, false );
}
}


    /* Draw the graphic symbol */
    CreateGraphicShape( Poly, m_Pos + offset );
    int FillShape = false;
    GRPoly( &panel->m_ClipBox, DC, Poly.size(), &Poly[0],
            FillShape, LineWidth, txtcolor, txtcolor );
}



int SCH_SHEET_PIN::GetEdge()
void SCH_SHEET_PIN::Plot( PLOTTER* aPlotter )
{
{
    wxASSERT( aPlotter != NULL );
    return m_Edge;

}
    EDA_Colors txtcolor = UNSPECIFIED_COLOR;
    int        posx, tposx, posy, size;


    static std::vector <wxPoint> Poly;


    txtcolor = ReturnLayerColor( GetLayer() );
/* ConstraintOnEdge is used to ajust label position to egde based
 * on proximity to vertical / horizontal edge.
 * used by sheetlab and resize
 */
void SCH_SHEET_PIN::ConstraintOnEdge( wxPoint Pos )
{
    SCH_SHEET* Sheet = (SCH_SHEET*) GetParent();


    posx = m_Pos.x;
    if( Sheet == NULL )
    posy = m_Pos.y;
        return;
    size = m_Size.x;
    GRTextHorizJustifyType side;


    if( m_Edge )
    if( m_Edge<2 ) /*horizontal sheetpin*/
    {
    {
        tposx = posx - size;
        if( Pos.x > ( Sheet->m_Pos.x + ( Sheet->m_Size.x / 2 ) ) )
        side  = GR_TEXT_HJUSTIFY_RIGHT;
        {
            SetEdge( 1 );
        }
        }
        else
        else
        {
        {
        tposx = posx + size + (size / 8);
            SetEdge( 0 );
        side  = GR_TEXT_HJUSTIFY_LEFT;
        }
        }


    int thickness = GetPenSize();
        m_Pos.y = Pos.y;
    aPlotter->set_current_line_width( thickness );
        if( m_Pos.y < Sheet->m_Pos.y )

            m_Pos.y = Sheet->m_Pos.y;
    aPlotter->text( wxPoint( tposx, posy ), txtcolor, m_Text, TEXT_ORIENT_HORIZ,
        if( m_Pos.y > (Sheet->m_Pos.y + Sheet->m_Size.y) )
                    wxSize( size, size ), side, GR_TEXT_VJUSTIFY_CENTER, thickness,
            m_Pos.y = Sheet->m_Pos.y + Sheet->m_Size.y;
                    m_Italic, m_Bold );

    /* Draw the associated graphic symbol */
    CreateGraphicShape( Poly, m_Pos );

    aPlotter->poly( Poly.size(), &Poly[0].x, NO_FILL );
    }
    }

    else /* vertical sheetpin*/

/** function CreateGraphicShape
 * Calculates the graphic shape (a polygon) associated to the text
 * @param aCorner_list = list to fill with polygon corners coordinates
 * @param Pos = Position of the shape
 */
void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aCorner_list,
                                        const wxPoint& Pos )
    {
    {
    wxSize size = m_Size;
        if( Pos.y > ( Sheet->m_Pos.y + ( Sheet->m_Size.y / 2 ) ) )

    aCorner_list.clear();
    if( m_Edge )
        {
        {
        size.x = -size.x;
            SetEdge( 3 ); //bottom
        size.y = -size.y;
        }
        }

        else
    int size2 = size.x / 2;

    aCorner_list.push_back( Pos );
    switch( m_Shape )
        {
        {
    case 0:         /* input |> */
            SetEdge( 2 ); //top
        aCorner_list.push_back( wxPoint( Pos.x, Pos.y - size2 ) );
        }
        aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y - size2 ) );
        aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y ) );
        aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y + size2 ) );
        aCorner_list.push_back( wxPoint( Pos.x, Pos.y + size2 ) );
        aCorner_list.push_back( Pos );
        break;

    case 1:         /* output <| */
        aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y - size2 ) );
        aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y - size2 ) );
        aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y + size2 ) );
        aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y + size2 ) );
        aCorner_list.push_back( Pos );
        break;

    case 2:         /* bidi <> */
    case 3:         /* TriSt <> */
        aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y - size2 ) );
        aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y ) );
        aCorner_list.push_back( wxPoint( Pos.x + size2, Pos.y + size2 ) );
        aCorner_list.push_back( Pos );
        break;


    default:         /* unsp []*/
        m_Pos.x = Pos.x;
        aCorner_list.push_back( wxPoint( Pos.x, Pos.y - size2 ) );
        if( m_Pos.x < Sheet->m_Pos.x )
        aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y - size2 ) );
            m_Pos.x = Sheet->m_Pos.x;
        aCorner_list.push_back( wxPoint( Pos.x + size.x, Pos.y + size2 ) );
        if( m_Pos.x > (Sheet->m_Pos.x + Sheet->m_Size.x) )
        aCorner_list.push_back( wxPoint( Pos.x, Pos.y + size2 ) );
            m_Pos.x = Sheet->m_Pos.x + Sheet->m_Size.x;
        aCorner_list.push_back( Pos );
        break;
    }
    }
}
}


@@ -235,8 +195,24 @@ bool SCH_SHEET_PIN::Save( FILE* aFile ) const


    if( m_Text.IsEmpty() )
    if( m_Text.IsEmpty() )
        return true;
        return true;
    if( m_Edge )
    switch( m_Edge )
    {
    case 0:     //pin on left side
        side = 'L';
        break;

    case 1:     //pin on right side
        side = 'R';
        side = 'R';
        break;

    case 2:      //pin on top side
        side = 'T';
        break;

    case 3:     //pin on bottom side
        side = 'B';
        break;
    }


    switch( m_Shape )
    switch( m_Shape )
    {
    {
@@ -273,6 +249,66 @@ bool SCH_SHEET_PIN::Matches( wxFindReplaceData& aSearchData )
}
}




void SCH_SHEET_PIN::Mirror_X( int aXaxis_position )
{
    int p = m_Pos.y - aXaxis_position;

    m_Pos.y = aXaxis_position - p;
    switch( m_Edge )
    {
    case 2:
        SetEdge( 3 );
        break;

    case 3:
        SetEdge( 2 );
        break;
    }
}


void SCH_SHEET_PIN::Mirror_Y( int aYaxis_position )
{
    int p = m_Pos.x - aYaxis_position;

    m_Pos.x = aYaxis_position - p;
    switch( m_Edge )
    {
    case 0:
        SetEdge( 1 );
        break;

    case 1:
        SetEdge( 0 );
        break;
    }
}


void SCH_SHEET_PIN::Rotate( wxPoint rotationPoint )
{
    RotatePoint( &m_Pos, rotationPoint, 900 );
    switch( m_Edge )
    {
    case 0:     //pin on left side
        SetEdge( 3 );
        break;

    case 1:     //pin on right side
        SetEdge( 2 );
        break;

    case 2:      //pin on top side
        SetEdge( 0 );
        break;

    case 3:     //pin on bottom side
        SetEdge( 1 );
        break;
    }
}


#if defined(DEBUG)
#if defined(DEBUG)
void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os )
void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os )
{
{
+24 −1
Original line number Original line Diff line number Diff line
@@ -8,6 +8,7 @@
#include "common.h"
#include "common.h"
#include "program.h"
#include "program.h"
#include "general.h"
#include "general.h"
#include "trigo.h"


#include "class_marker_sch.h"
#include "class_marker_sch.h"
#include "erc.h"
#include "erc.h"
@@ -147,3 +148,25 @@ void SCH_MARKER::DisplayInfo( WinEDA_DrawFrame* aFrame )
    aFrame->AppendMsgPanel( _( "Electronics rule check error" ),
    aFrame->AppendMsgPanel( _( "Electronics rule check error" ),
                            GetReporter().GetErrorText(), DARKRED );
                            GetReporter().GetErrorText(), DARKRED );
}
}


void SCH_MARKER::Rotate( wxPoint rotationPoint )
{
    RotatePoint( &m_Pos, rotationPoint, 900 );
}


void SCH_MARKER::Mirror_X( int aXaxis_position )
{
    m_Pos.y -= aXaxis_position;
    m_Pos.y  = -m_Pos.y;
    m_Pos.y += aXaxis_position;
}


void SCH_MARKER::Mirror_Y( int aYaxis_position )
{
    m_Pos.x -= aYaxis_position;
    m_Pos.x  = -m_Pos.x;
    m_Pos.x += aYaxis_position;
}
Loading