Commit 3ddc57e6 authored by charras's avatar charras
Browse files

fixed some minor bugs and code cleanup

parent 826daace
Loading
Loading
Loading
Loading
+16 −5
Original line number Original line Diff line number Diff line
@@ -235,17 +235,18 @@ EDA_Rect EDA_TextStruct::GetTextBox( int aLine )


    // calculate the H and V size
    // calculate the H and V size
    int    dx = LenSize( *text );
    int    dx = LenSize( *text );
    int    dy = m_Size.y + m_Width;
    int    dy = GetInterline();
    int extra_dy = (m_Size.y * 3)/10;      // extra dy value for letters like j and y


    /* Creates bounding box (rectangle) for an horizontal text */
    /* Creates bounding box (rectangle) for an horizontal text */
    wxSize textsize = wxSize( dx, dy );
    wxSize textsize = wxSize( dx, dy );
    rect.SetOrigin( m_Pos );
    rect.SetOrigin( m_Pos );
    // extra dy interval for letters like j and y and ]
    int extra_dy = dy - m_Size.y;
    rect.Move(wxPoint(0, -extra_dy/2 ) ); // move origin by the half extra interval


    // for multiline texts ans aLine < 0, merge all rectangles
    // for multiline texts and aLine < 0, merge all rectangles
    if( m_MultilineAllowed && aLine < 0 )
    if( m_MultilineAllowed && aLine < 0 )
    {
    {
        dy = GetInterline();
        for( unsigned ii = 1; ii < list->GetCount(); ii++ )
        for( unsigned ii = 1; ii < list->GetCount(); ii++ )
        {
        {
            text = &list->Item( ii );
            text = &list->Item( ii );
@@ -256,8 +257,8 @@ EDA_Rect EDA_TextStruct::GetTextBox( int aLine )
    }
    }
    delete list;
    delete list;


    textsize.y += extra_dy;
    rect.SetSize( textsize );
    rect.SetSize( textsize );
    rect.Inflate( m_Width/2 );      // ensure a small margin


    /* Now, calculate the rect origin, according to text justification
    /* Now, calculate the rect origin, according to text justification
     * At this point the rectangle origin is the text origin (m_Pos).
     * At this point the rectangle origin is the text origin (m_Pos).
@@ -474,6 +475,16 @@ void EDA_Rect::Normalize()
}
}





/** Function Move
 * Move this rectangle by the aMoveVector value (this is a relative move)
 * @param aMoveVector = a wxPoint that is the value to move this rectangle
 */
void EDA_Rect::Move( const wxPoint& aMoveVector )
{
    m_Pos += aMoveVector;
}

/*******************************************/
/*******************************************/
bool EDA_Rect::Inside( const wxPoint& point )
bool EDA_Rect::Inside( const wxPoint& point )
/*******************************************/
/*******************************************/
+8 −0
Original line number Original line Diff line number Diff line
@@ -210,6 +210,14 @@ public:
    void            SetTimeStamp( long aNewTimeStamp);
    void            SetTimeStamp( long aNewTimeStamp);


    EDA_Rect        GetBoundaryBox() const;
    EDA_Rect        GetBoundaryBox() const;

    /**
     * Function GetBoundingBox
     * returns the orthogonal, bounding box of this object for display purposes.
     * This box should be an enclosing perimeter for visible components of this
     * object, and the units should be in the pcb or schematic coordinate system.
     * It is OK to overestimate the size by a few counts.
     */
    EDA_Rect        GetBoundingBox();
    EDA_Rect        GetBoundingBox();


    /**
    /**
+25 −18
Original line number Original line Diff line number Diff line
@@ -144,15 +144,20 @@ void DrawBusEntryStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
DrawJunctionStruct::DrawJunctionStruct( const wxPoint& pos ) :
DrawJunctionStruct::DrawJunctionStruct( const wxPoint& pos ) :
    SCH_ITEM( NULL, DRAW_JUNCTION_STRUCT_TYPE )
    SCH_ITEM( NULL, DRAW_JUNCTION_STRUCT_TYPE )
{
{
#define DRAWJUNCTION_DIAMETER  32   /* Diameter of junction symbol between wires */
    m_Pos   = pos;
    m_Pos   = pos;
    m_Layer = LAYER_JUNCTION;
    m_Layer = LAYER_JUNCTION;
    m_Size.x = m_Size.y = DRAWJUNCTION_DIAMETER;
#undef DRAWJUNCTION_DIAMETER
}
}





DrawJunctionStruct* DrawJunctionStruct::GenCopy()
DrawJunctionStruct* DrawJunctionStruct::GenCopy()
{
{
    DrawJunctionStruct* newitem = new DrawJunctionStruct( m_Pos );
    DrawJunctionStruct* newitem = new DrawJunctionStruct( m_Pos );


    newitem->m_Size  = m_Size;
    newitem->m_Layer = m_Layer;
    newitem->m_Layer = m_Layer;
    newitem->m_Flags = m_Flags;
    newitem->m_Flags = m_Flags;


@@ -183,13 +188,11 @@ EDA_Rect DrawJunctionStruct::GetBoundingBox()


// return a bounding box
// return a bounding box
{
{
    int      width = DRAWJUNCTION_DIAMETER;
    EDA_Rect rect;
    int      xmin  = m_Pos.x - (DRAWJUNCTION_DIAMETER/2);
    rect.SetOrigin(m_Pos);
    int      ymin  = m_Pos.y - (DRAWJUNCTION_DIAMETER/2);
    rect.Inflate( (GetPenSize() + m_Size.x)/2);

    EDA_Rect ret( wxPoint( xmin, ymin ), wxSize( width, width ) );


    return ret;
    return rect;
};
};




@@ -202,7 +205,7 @@ bool DrawJunctionStruct::HitTest( const wxPoint& aPosRef )
    wxPoint dist = aPosRef - m_Pos;
    wxPoint dist = aPosRef - m_Pos;


    return sqrt( ( (double) ( dist.x * dist.x ) ) +
    return sqrt( ( (double) ( dist.x * dist.x ) ) +
                 ( (double) ( dist.y * dist.y ) ) ) < (DRAWJUNCTION_DIAMETER/2);
                 ( (double) ( dist.y * dist.y ) ) ) < (m_Size.x/2);
}
}




@@ -231,7 +234,7 @@ void DrawJunctionStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
    GRSetDrawMode( DC, DrawMode );
    GRSetDrawMode( DC, DrawMode );


    GRFilledCircle( &panel->m_ClipBox, DC, m_Pos.x + offset.x,
    GRFilledCircle( &panel->m_ClipBox, DC, m_Pos.x + offset.x,
                    m_Pos.y + offset.y, (DRAWJUNCTION_DIAMETER/2), 0, color,
                    m_Pos.y + offset.y, (m_Size.x/2), 0, color,
                    color );
                    color );
}
}


@@ -257,7 +260,10 @@ void DrawJunctionStruct::Show( int nestLevel, std::ostream& os )
DrawNoConnectStruct::DrawNoConnectStruct( const wxPoint& pos ) :
DrawNoConnectStruct::DrawNoConnectStruct( const wxPoint& pos ) :
    SCH_ITEM( NULL, DRAW_NOCONNECT_STRUCT_TYPE )
    SCH_ITEM( NULL, DRAW_NOCONNECT_STRUCT_TYPE )
{
{
#define DRAWNOCONNECT_SIZE 48       /* No symbol connection range. */
    m_Pos = pos;
    m_Pos = pos;
    m_Size.x = m_Size.y = DRAWNOCONNECT_SIZE;
#undef DRAWNOCONNECT_SIZE
}
}




@@ -265,6 +271,7 @@ DrawNoConnectStruct* DrawNoConnectStruct::GenCopy()
{
{
    DrawNoConnectStruct* newitem = new DrawNoConnectStruct( m_Pos );
    DrawNoConnectStruct* newitem = new DrawNoConnectStruct( m_Pos );


    newitem->m_Size  = m_Size;
    newitem->m_Flags = m_Flags;
    newitem->m_Flags = m_Flags;


    return newitem;
    return newitem;
@@ -273,11 +280,11 @@ DrawNoConnectStruct* DrawNoConnectStruct::GenCopy()


EDA_Rect DrawNoConnectStruct::GetBoundingBox()
EDA_Rect DrawNoConnectStruct::GetBoundingBox()
{
{
    const int DELTA = DRAWNOCONNECT_SIZE / 2;
    int delta = (GetPenSize() + m_Size.x)/2;
    EDA_Rect  box( wxPoint( m_Pos.x - DELTA, m_Pos.y - DELTA ),
    EDA_Rect  box;
                   wxSize( 2 * DELTA, 2 * DELTA ) );
    box.SetOrigin( m_Pos );
    box.Inflate(delta);


    box.Normalize();
    return box;
    return box;
}
}


@@ -290,7 +297,7 @@ EDA_Rect DrawNoConnectStruct::GetBoundingBox()
bool DrawNoConnectStruct::HitTest( const wxPoint& aPosRef )
bool DrawNoConnectStruct::HitTest( const wxPoint& aPosRef )
{
{
    int     width = g_DrawDefaultLineThickness;
    int     width = g_DrawDefaultLineThickness;
    int     delta = ( DRAWNOCONNECT_SIZE + width) / 2;
    int     delta = ( m_Size.x + width) / 2;


    wxPoint dist = aPosRef - m_Pos;
    wxPoint dist = aPosRef - m_Pos;


@@ -331,7 +338,7 @@ int DrawNoConnectStruct::GetPenSize()
void DrawNoConnectStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
void DrawNoConnectStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
                                const wxPoint& offset, int DrawMode, int Color )
                                const wxPoint& offset, int DrawMode, int Color )
{
{
    const int DELTA = (DRAWNOCONNECT_SIZE / 2);
    int delta = m_Size.x / 2;
    int       pX, pY, color;
    int       pX, pY, color;
    int       width = g_DrawDefaultLineThickness;
    int       width = g_DrawDefaultLineThickness;


@@ -343,10 +350,10 @@ void DrawNoConnectStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
        color = ReturnLayerColor( LAYER_NOCONNECT );
        color = ReturnLayerColor( LAYER_NOCONNECT );
    GRSetDrawMode( DC, DrawMode );
    GRSetDrawMode( DC, DrawMode );


    GRLine( &panel->m_ClipBox, DC, pX - DELTA, pY - DELTA, pX + DELTA,
    GRLine( &panel->m_ClipBox, DC, pX - delta, pY - delta, pX + delta,
            pY + DELTA, width, color );
            pY + delta, width, color );
    GRLine( &panel->m_ClipBox, DC, pX + DELTA, pY - DELTA, pX - DELTA,
    GRLine( &panel->m_ClipBox, DC, pX + delta, pY - delta, pX - delta,
            pY + DELTA, width, color );
            pY + delta, width, color );
}
}




+31 −4
Original line number Original line Diff line number Diff line
@@ -5,10 +5,6 @@
#ifndef CLASS_SCHEMATIC_ITEMS_H
#ifndef CLASS_SCHEMATIC_ITEMS_H
#define CLASS_SCHEMATIC_ITEMS_H
#define CLASS_SCHEMATIC_ITEMS_H


#define DRAWJUNCTION_DIAMETER  32   /* Diameter of junction symbol between
                                     * wires */
#define DRAWNOCONNECT_SIZE 48       /* No symbol connection range. */

/* Flags for BUS ENTRY (bus to bus or wire to bus */
/* Flags for BUS ENTRY (bus to bus or wire to bus */
#define WIRE_TO_BUS 0
#define WIRE_TO_BUS 0
#define BUS_TO_BUS  1
#define BUS_TO_BUS  1
@@ -51,6 +47,13 @@ public:
    }
    }




    /**
     * Function GetBoundingBox
     * returns the orthogonal, bounding box of this object for display purposes.
     * This box should be an enclosing perimeter for visible components of this
     * object, and the units should be in the pcb or schematic coordinate system.
     * It is OK to overestimate the size by a few counts.
     */
    EDA_Rect     GetBoundingBox();
    EDA_Rect     GetBoundingBox();


    virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
    virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
@@ -107,6 +110,7 @@ class DrawNoConnectStruct : public SCH_ITEM
{
{
public:
public:
    wxPoint m_Pos;                      /* XY coordinates of NoConnect. */
    wxPoint m_Pos;                      /* XY coordinates of NoConnect. */
    wxSize m_Size;                      // size of this symbol


public:
public:
    DrawNoConnectStruct( const wxPoint& pos );
    DrawNoConnectStruct( const wxPoint& pos );
@@ -143,7 +147,15 @@ public:
     */
     */
    bool HitTest( const wxPoint& aPosRef );
    bool HitTest( const wxPoint& aPosRef );


    /**
     * Function GetBoundingBox
     * returns the orthogonal, bounding box of this object for display purposes.
     * This box should be an enclosing perimeter for visible components of this
     * object, and the units should be in the pcb or schematic coordinate system.
     * It is OK to overestimate the size by a few counts.
     */
    EDA_Rect             GetBoundingBox();
    EDA_Rect             GetBoundingBox();

    // Geometric transforms (used in block operations):
    // Geometric transforms (used in block operations):
    /** virtual function Move
    /** virtual function Move
     * move item to a new position.
     * move item to a new position.
@@ -204,6 +216,13 @@ public:
     */
     */
    bool                Save( FILE* aFile ) const;
    bool                Save( FILE* aFile ) const;


    /**
     * Function GetBoundingBox
     * returns the orthogonal, bounding box of this object for display purposes.
     * This box should be an enclosing perimeter for visible components of this
     * object, and the units should be in the pcb or schematic coordinate system.
     * It is OK to overestimate the size by a few counts.
     */
    EDA_Rect            GetBoundingBox();
    EDA_Rect            GetBoundingBox();


    /** Function GetPenSize
    /** Function GetPenSize
@@ -313,6 +332,7 @@ class DrawJunctionStruct : public SCH_ITEM
{
{
public:
public:
    wxPoint m_Pos;                  /* XY coordinates of connection. */
    wxPoint m_Pos;                  /* XY coordinates of connection. */
    wxSize m_Size;


public:
public:
    DrawJunctionStruct( const wxPoint& pos );
    DrawJunctionStruct( const wxPoint& pos );
@@ -330,6 +350,13 @@ public:
     */
     */
    bool HitTest( const wxPoint& aPosRef );
    bool HitTest( const wxPoint& aPosRef );


    /**
     * Function GetBoundingBox
     * returns the orthogonal, bounding box of this object for display purposes.
     * This box should be an enclosing perimeter for visible components of this
     * object, and the units should be in the pcb or schematic coordinate system.
     * It is OK to overestimate the size by a few counts.
     */
    EDA_Rect            GetBoundingBox();
    EDA_Rect            GetBoundingBox();


    DrawJunctionStruct* GenCopy();
    DrawJunctionStruct* GenCopy();
+67 −2
Original line number Original line Diff line number Diff line
@@ -600,6 +600,19 @@ void SCH_TEXT::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& aOffset,
    EXCHG( linewidth, m_Width );            // set initial value
    EXCHG( linewidth, m_Width );            // set initial value
    if( m_IsDangling )
    if( m_IsDangling )
        DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );
        DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );

    // Enable these line to draw the bounding box (debug tests purposes only)
#if 0
    {
        EDA_Rect BoundaryBox;
        BoundaryBox = GetBoundingBox();
        int x1 = BoundaryBox.GetX();
        int y1 = BoundaryBox.GetY();
        int x2 = BoundaryBox.GetRight();
        int y2 = BoundaryBox.GetBottom();
        GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
    }
#endif
}
}




@@ -844,6 +857,19 @@ void SCH_HIERLABEL::Draw( WinEDA_DrawPanel* panel,


    if( m_IsDangling )
    if( m_IsDangling )
        DrawDanglingSymbol( panel, DC, m_Pos + offset, color );
        DrawDanglingSymbol( panel, DC, m_Pos + offset, color );

    // Enable these line to draw the bounding box (debug tests purposes only)
#if 0
    {
        EDA_Rect BoundaryBox;
        BoundaryBox = GetBoundingBox();
        int x1 = BoundaryBox.GetX();
        int y1 = BoundaryBox.GetY();
        int x2 = BoundaryBox.GetRight();
        int y2 = BoundaryBox.GetBottom();
        GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
    }
#endif
}
}




@@ -965,6 +991,19 @@ void SCH_GLOBALLABEL::Draw( WinEDA_DrawPanel* panel,


    if( m_IsDangling )
    if( m_IsDangling )
        DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );
        DrawDanglingSymbol( panel, DC, m_Pos + aOffset, color );

    // Enable these line to draw the bounding box (debug tests purposes only)
#if 0
    {
        EDA_Rect BoundaryBox;
        BoundaryBox = GetBoundingBox();
        int x1 = BoundaryBox.GetX();
        int y1 = BoundaryBox.GetY();
        int x2 = BoundaryBox.GetRight();
        int y2 = BoundaryBox.GetBottom();
        GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
    }
#endif
}
}




@@ -1109,9 +1148,9 @@ EDA_Rect SCH_GLOBALLABEL::GetBoundingBox()




/***********************************/
/***********************************/
EDA_Rect SCH_TEXT::GetBoundingBox()
EDA_Rect SCH_LABEL::GetBoundingBox()
{
/***********************************/
/***********************************/
{
    int x, y, dx, dy, length, height;
    int x, y, dx, dy, length, height;


    x = m_Pos.x;
    x = m_Pos.x;
@@ -1156,3 +1195,29 @@ EDA_Rect SCH_TEXT::GetBoundingBox()
    box.Normalize();
    box.Normalize();
    return box;
    return box;
}
}

/***********************************/
EDA_Rect SCH_TEXT::GetBoundingBox()
/***********************************/
{
    // We must pass the effective text thickness to GetTextBox
    // when calculating the bounding box
    int linewidth =
        (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width;
    linewidth = Clamp_Text_PenSize( linewidth, m_Size, m_Bold );
    EXCHG( linewidth, m_Width );            // Set the real width
    EDA_Rect rect = GetTextBox( -1 );
    EXCHG( linewidth, m_Width );            // set initial value

    if( m_Orient )   // Rotate rect
    {
        wxPoint pos = rect.GetOrigin();
        wxPoint end = rect.GetEnd();
        RotatePoint( &pos, m_Pos, m_Orient );
        RotatePoint( &end, m_Pos, m_Orient );
        rect.SetOrigin(pos);
        rect.SetEnd(end);
    }

    return rect;
}
Loading