Commit ada6b6b8 authored by charras's avatar charras
Browse files

Code cleaning

parent 02b670d8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -5,6 +5,13 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.

2009-Jan-02 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
++Eeschema:
    Code cleaning.
    LibDrawPolyline uses now std::vector<wxPoint> to handle corners.



2008-Dec-31 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+16 −26
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@ static SCH_ITEM* CopyStruct( WinEDA_DrawPanel* panel,
                                      BASE_SCREEN*      screen,
                                      SCH_ITEM*         DrawStruct );
static void               CollectStructsToDrag( SCH_SCREEN* screen );
static void               AddPickedItem( SCH_SCREEN* screen, wxPoint position );
static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* DrawLibItem,
                                              wxPoint&       position );
static void               AddPickedItem( SCH_SCREEN* screen, wxPoint aPosition );
static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem,
                                              wxPoint&       aPosition );
static void               DrawMovingBlockOutlines( WinEDA_DrawPanel* panel,
                                                   wxDC*             DC,
                                                   bool              erase );
@@ -182,9 +182,7 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )

    /* clear struct.m_Flags  */
    SCH_ITEM* Struct;
    for( Struct = GetScreen()->EEDrawList;
        Struct != NULL;
        Struct = Struct->Next() )
    for( Struct = GetScreen()->EEDrawList; Struct != NULL; Struct = Struct->Next() )
        Struct->m_Flags = 0;

    DrawPanel->ManageCurseur = NULL;
@@ -203,9 +201,7 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
        block->m_BlockDrawStruct = NULL;
    }

    SetToolID( m_ID_current_state,
               DrawPanel->m_PanelDefaultCursor,
               wxEmptyString );
    SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor, wxEmptyString );
}


@@ -1152,10 +1148,7 @@ bool PlaceStruct( BASE_SCREEN* screen, SCH_ITEM* DrawStruct )
    if( !DrawStruct )
        return FALSE;

    move_vector.x = screen->m_Curseur.x -
                    screen->BlockLocate.m_BlockLastCursorPosition.x;
    move_vector.y = screen->m_Curseur.y -
                    screen->BlockLocate.m_BlockLastCursorPosition.y;
    move_vector = screen->m_Curseur - screen->BlockLocate.m_BlockLastCursorPosition;

    switch( DrawStruct->Type() )
    {
@@ -1709,8 +1702,8 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )


/*********************************************************************************/
static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* DrawLibItem,
                                              wxPoint&       position )
static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem,
                                              wxPoint&       aPosition )
/*********************************************************************************/
{
    EDA_LibComponentStruct* Entry;
@@ -1720,19 +1713,19 @@ static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* DrawLibItem,
    int orient;
    LibDrawPin* Pin;

    if( DrawLibItem )
    if( aDrawLibItem )
    {
        NextItem = NULL;
        if( ( Entry =
                 FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString,
                 FindLibPart( aDrawLibItem->m_ChipName.GetData(), wxEmptyString,
                              FIND_ROOT ) ) == NULL )
            return NULL;
        DEntry  = Entry->m_Drawings;
        Multi   = DrawLibItem->m_Multi;
        convert = DrawLibItem->m_Convert;
        PartX   = DrawLibItem->m_Pos.x;
        PartY   = DrawLibItem->m_Pos.y;
        memcpy( TransMat, DrawLibItem->m_Transform, sizeof(TransMat) );
        Multi   = aDrawLibItem->m_Multi;
        convert = aDrawLibItem->m_Convert;
        PartX   = aDrawLibItem->m_Pos.x;
        PartY   = aDrawLibItem->m_Pos.y;
        memcpy( TransMat, aDrawLibItem->m_Transform, sizeof(TransMat) );
    }
    else
        DEntry = NextItem;
@@ -1753,10 +1746,7 @@ static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* DrawLibItem,
        orient = Pin->ReturnPinDrawOrient( TransMat );

        /* Calcul de la position du point de reference */
        position.x = PartX + (TransMat[0][0] *Pin->m_Pos.x)
                     + (TransMat[0][1] *Pin->m_Pos.y);
        position.y = PartY + (TransMat[1][0] *Pin->m_Pos.x)
                     + (TransMat[1][1] *Pin->m_Pos.y);
        aPosition = TransformCoordinate( TransMat, Pin->m_Pos);
        NextItem = DEntry->Next();
        return DEntry;
    }
+20 −33
Original line number Diff line number Diff line
/****************************************************/
/*	BLOCK.CPP										*/
/*	block_libedt.cpp       							*/
/* Gestion des Operations sur Blocks et Effacements */
/****************************************************/

@@ -139,11 +139,11 @@ int MarkItemsInBloc( EDA_LibComponentStruct* LibComponent,

        case COMPONENT_POLYLINE_DRAW_TYPE:
        {
            int  ii, imax = ( (LibDrawPolyline*) item )->m_CornersCount * 2;
            int* ptpoly = ( (LibDrawPolyline*) item )->m_PolyList;
            for( ii = 0; ii < imax; ii += 2 )
            int  ii, imax = ( (LibDrawPolyline*) item )->GetCornerCount();
            for( ii = 0; ii < imax; ii ++ )
            {
                pos.x = ptpoly[ii]; pos.y = -ptpoly[ii + 1];
                pos = ( (LibDrawPolyline*) item )->m_PolyPoints[ii];
                NEGATE( pos.y );
                if( Rect.Inside( pos ) )
                {
                    item->m_Selected = IS_SELECTED;
@@ -537,7 +537,7 @@ void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
    if( LibEntry == NULL )
        return;

    offset.y = -offset.y;  // Y axis for lib items is Down to Up: reverse y offset value
    NEGATE( offset.y );  // Y axis for lib items is Down to Up: reverse y offset value
    item = LibEntry->m_Drawings;
    for( ; item != NULL; item = item->Next() )
    {
@@ -547,42 +547,31 @@ void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
        switch( item->Type() )
        {
        case COMPONENT_PIN_DRAW_TYPE:
            ( (LibDrawPin*) item )->m_Pos.x += offset.x;
            ( (LibDrawPin*) item )->m_Pos.y += offset.y;
            ( (LibDrawPin*) item )->m_Pos += offset;
            break;

        case COMPONENT_ARC_DRAW_TYPE:
        {
            ( (LibDrawArc*) item )->m_Pos.x      += offset.x;
            ( (LibDrawArc*) item )->m_Pos.y      += offset.y;
            ( (LibDrawArc*) item )->m_ArcStart.x += offset.x;
            ( (LibDrawArc*) item )->m_ArcStart.y += offset.y;
            ( (LibDrawArc*) item )->m_ArcEnd.x   += offset.x;
            ( (LibDrawArc*) item )->m_ArcEnd.y   += offset.y;
            ( (LibDrawArc*) item )->m_Pos     += offset;
            ( (LibDrawArc*) item )->m_ArcStart += offset;
            ( (LibDrawArc*) item )->m_ArcEnd   += offset;
            break;
        }

        case COMPONENT_CIRCLE_DRAW_TYPE:
            ( (LibDrawCircle*) item )->m_Pos.x += offset.x;
            ( (LibDrawCircle*) item )->m_Pos.y += offset.y;
            ( (LibDrawCircle*) item )->m_Pos += offset;
            break;

        case COMPONENT_RECT_DRAW_TYPE:
            ( (LibDrawSquare*) item )->m_Pos.x += offset.x;
            ( (LibDrawSquare*) item )->m_Pos.y += offset.y;
            ( (LibDrawSquare*) item )->m_End.x += offset.x;
            ( (LibDrawSquare*) item )->m_End.y += offset.y;
            ( (LibDrawSquare*) item )->m_Pos += offset;
            ( (LibDrawSquare*) item )->m_End += offset;
            break;

        case COMPONENT_POLYLINE_DRAW_TYPE:
        {
            int ii, imax = ( (LibDrawPolyline*) item )->m_CornersCount * 2;
            int* ptpoly = ( (LibDrawPolyline*) item )->m_PolyList;
            for( ii = 0; ii < imax; ii += 2 )
            {
                ptpoly[ii]     += offset.x;
                ptpoly[ii + 1] += offset.y;
            }
            unsigned ii, imax = ( (LibDrawPolyline*) item )->GetCornerCount();
            for( ii = 0; ii < imax; ii ++ )
                ( (LibDrawPolyline*) item )->m_PolyPoints[ii] += offset;
        }
            break;

@@ -590,8 +579,7 @@ void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
            break;

        case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
            ( (LibDrawText*) item )->m_Pos.x += offset.x;
            ( (LibDrawText*) item )->m_Pos.y += offset.y;
            ( (LibDrawText*) item )->m_Pos += offset;
            break;

        default:
@@ -688,11 +676,10 @@ void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )

        case COMPONENT_POLYLINE_DRAW_TYPE:
        {
            int ii, imax = ( (LibDrawPolyline*) item )->m_CornersCount * 2;
            int* ptpoly = ( (LibDrawPolyline*) item )->m_PolyList;
            for( ii = 0; ii < imax; ii += 2 )
            unsigned ii, imax = ( (LibDrawPolyline*) item )->GetCornerCount();
            for( ii = 0; ii < imax; ii ++ )
            {
                SETMIRROR( ptpoly[ii] );
                SETMIRROR( ( (LibDrawPolyline*) item )->m_PolyPoints[ii].x );
            }
        }
            break;
+10 −19
Original line number Diff line number Diff line
@@ -118,7 +118,6 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert )
 **/
{
    int                xmin, xmax, ymin, ymax, x1, y1;
    int*               pt, ii;
    LibEDA_BaseStruct* DrawEntry;
    EDA_Rect           BoundaryBox;

@@ -232,21 +231,15 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert )

        case COMPONENT_POLYLINE_DRAW_TYPE:
        {
            LibDrawPolyline* polyline = (LibDrawPolyline*) DrawEntry;
            pt = polyline->m_PolyList;
            for( ii = 0; ii < polyline->m_CornersCount; ii++ )
            {
                if( xmin > *pt )
                    xmin = *pt;
                if( xmax < *pt )
                    xmax = *pt;
                pt++;
                if( ymin > *pt )
                    ymin = *pt;
                if( ymax < *pt )
                    ymax = *pt;
                pt++;
            }
            EDA_Rect rect = ((LibDrawPolyline*) DrawEntry)->GetBoundaryBox( );
            xmin = MIN( xmin, rect.GetX() );
            xmax = MAX( xmax, rect.GetX() );
            ymin = MIN( ymin, rect.GetY() );
            ymax = MAX( ymax, rect.GetY() );
            xmin = MIN( xmin, rect.GetEnd().x );
            xmax = MAX( xmax, rect.GetEnd().x );
            ymin = MIN( ymin, rect.GetEnd().y );
            ymax = MAX( ymax, rect.GetEnd().y );
        }
        break;

@@ -257,9 +250,7 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert )

    // Update the BoundaryBox. Remember the fact the screen Y axis is the reverse */
    NEGATE(ymax); NEGATE(ymin);    // Y is not is screen axis sense
    // Ensure w and H > 0 (wxRect assume it)
    if( xmax < xmin )
        EXCHG( xmax, xmin );
    // Ensure H > 0 (wxRect assume it)
    if( ymax < ymin )
        EXCHG( ymax, ymin );
    BoundaryBox.SetX( xmin ); BoundaryBox.SetWidth( xmax - xmin );
+64 −44
Original line number Diff line number Diff line
@@ -240,8 +240,8 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,

    int         color     = ReturnLayerColor( LAYER_DEVICE );
    int         linewidth = MAX( m_Width, g_DrawMinimunLineWidth );
    static int* Buf_Poly_Drawings = NULL;               // Buffer used to store current corners coordinates for drawings
    static int  Buf_Poly_Size = 0;                      // Buffer used to store current corners coordinates for drawings
    static wxPoint* Buf_Poly_Drawings = NULL;               // Buffer used to store current corners coordinates for drawings
    static unsigned  Buf_Poly_Size = 0;                      // Buffer used to store current corners coordinates for drawings

    if( aColor < 0 )                                    // Used normal color or selected color
    {
@@ -254,25 +254,19 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
    // Set the size of the buffer od coordinates
    if( Buf_Poly_Drawings == NULL )
    {
        Buf_Poly_Size     = m_CornersCount;
        Buf_Poly_Drawings = (int*) MyMalloc( sizeof(int) * 2 * Buf_Poly_Size );
        Buf_Poly_Size     = m_PolyPoints.size();
        Buf_Poly_Drawings = (wxPoint*) MyMalloc( sizeof(wxPoint) * Buf_Poly_Size );
    }
    else if( Buf_Poly_Size < m_CornersCount )
    else if( Buf_Poly_Size < m_PolyPoints.size() )
    {
        Buf_Poly_Size     = m_CornersCount;
        Buf_Poly_Drawings = (int*) realloc( Buf_Poly_Drawings,
            sizeof(int) * 2 * Buf_Poly_Size );
        Buf_Poly_Size     = m_PolyPoints.size();
        Buf_Poly_Drawings = (wxPoint*) realloc( Buf_Poly_Drawings,
            sizeof(wxPoint) * Buf_Poly_Size );
    }

    for( int ii = 0, jj = 0; ii < m_CornersCount; ii++, jj += 2 )
    for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
    {
        pos1.x = m_PolyList[jj];
        pos1.y = m_PolyList[jj + 1];

        pos1 = TransformCoordinate( aTransformMatrix, pos1 ) + aOffset;

        Buf_Poly_Drawings[jj]     = pos1.x;
        Buf_Poly_Drawings[jj + 1] = pos1.y;
        Buf_Poly_Drawings[ii] = TransformCoordinate( aTransformMatrix, m_PolyPoints[ii] ) + aOffset;
    }

    FILL_T fill = aData ? NO_FILL : m_Fill;
@@ -280,15 +274,15 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
        fill = NO_FILL;

    if( fill == FILLED_WITH_BG_BODYCOLOR )
        GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
            (wxPoint*) Buf_Poly_Drawings, 1, linewidth, color,
        GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
            Buf_Poly_Drawings, 1, linewidth, color,
            ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
    else if( fill == FILLED_SHAPE  )
        GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
            (wxPoint*) Buf_Poly_Drawings, 1, linewidth, color, color );
        GRPoly( &aPanel->m_ClipBox, aDC,m_PolyPoints.size(),
            Buf_Poly_Drawings, 1, linewidth, color, color );
    else
        GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
            (wxPoint*) Buf_Poly_Drawings, 0, linewidth, color, color );
        GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
            Buf_Poly_Drawings, 0, linewidth, color, color );
}


@@ -520,8 +514,6 @@ LibDrawSegment* LibDrawSegment::GenCopy()

LibDrawPolyline::LibDrawPolyline() : LibEDA_BaseStruct( COMPONENT_POLYLINE_DRAW_TYPE )
{
    m_CornersCount = 0;
    m_PolyList = NULL;
    m_Fill   = NO_FILL;
    m_Width  = 0;
}
@@ -532,16 +524,7 @@ LibDrawPolyline* LibDrawPolyline::GenCopy()
/************************************************/
{
    LibDrawPolyline* newitem = new LibDrawPolyline();

    int size;

    newitem->m_CornersCount = m_CornersCount;
    size = sizeof(int) * 2 * m_CornersCount;
    if( size )
    {
        newitem->m_PolyList = (int*) MyMalloc( size );
        memcpy( newitem->m_PolyList, m_PolyList, size );
    }
    newitem->m_PolyPoints = m_PolyPoints;   // Vector copy
    newitem->m_Width   = m_Width;
    newitem->m_Unit    = m_Unit;
    newitem->m_Convert = m_Convert;
@@ -555,18 +538,55 @@ LibDrawPolyline* LibDrawPolyline::GenCopy()
void LibDrawPolyline::AddPoint( const wxPoint& point )
/***************************************************/

/* add a point to the polyline coordinate list, and realloc the memory
/* add a point to the polyline coordinate list
 */
{
    int allocsize;
    m_PolyPoints.push_back( point );
}

    m_CornersCount++;
    allocsize = 2 * sizeof(int) * m_CornersCount;
    if( m_PolyList == NULL )
        m_PolyList = (int*) MyMalloc( allocsize );
    else
        m_PolyList = (int*) realloc( m_PolyList, allocsize );

    m_PolyList[(m_CornersCount * 2) - 2] = point.x;
    m_PolyList[(m_CornersCount * 2) - 1] = -point.y;
/** Function HitTest
 * @return true if the point aPosRef is near a segment
 * @param aPosRef = a wxPoint to test
 * @param aThreshold = max distance to a segment
 * @param aTransMat = the transform matrix
 */
bool LibDrawPolyline::HitTest( wxPoint aPosRef, int aThreshold, int aTransMat[2][2] )
{

    aPosRef = TransformCoordinate( aTransMat, aPosRef);
    /* Move origin coordinate to segment start point */
    wxPoint end;
    for ( unsigned ii = 0; ii < m_PolyPoints.size() -1; ii++ )
    {
    aPosRef -= m_PolyPoints[0];
    end = m_PolyPoints[1] - m_PolyPoints[0];

    if( distance( end.x, end.y, aPosRef.x, aPosRef.y, aThreshold ) )
        return true;
    }

    return false;
}

/** Function GetBoundaryBox
 * @return the boundary box for this, in library coordinates
 */
EDA_Rect LibDrawPolyline::GetBoundaryBox( )
{
    EDA_Rect           BoundaryBox;
    int xmin, xmax, ymin, ymax;
    xmin = xmax = m_PolyPoints[0].x;
    ymin = ymax = m_PolyPoints[0].y;
    for( unsigned ii = 1; ii < GetCornerCount(); ii++ )
    {
        xmin = MIN( xmin, m_PolyPoints[0].x );
        xmax = MAX( xmax, m_PolyPoints[0].x );
        ymin = MIN( ymin, m_PolyPoints[0].y );
        ymax = MAX( ymax, m_PolyPoints[0].y );
    }
    BoundaryBox.SetX( xmin ); BoundaryBox.SetWidth( xmax - xmin );
    BoundaryBox.SetY( ymin ); BoundaryBox.SetHeight( ymax - ymin );

    return BoundaryBox;
}
Loading