Commit c2b600ce authored by stambaughw's avatar stambaughw
Browse files

Replace wxList with boost::ptr_vector and fix automatic association bug in CVPCB.

* ALL: More changes for wxDC based zooming.
* 3D_VIEWER: Wrap 3d_viewer.h to prevent redefinitions.
* CVPcb: Replace wxList with boost::ptr_vector and take advantage of boost::foreach.
* CVPcb: Fix automatic association bug.
* CVPcb: Rename some variables for clarity and some minor code clean ups.
* CVPcb: Fix GTK sizing issue in library and path dialog.
* EESchema: Remove left over sizer from last commit from library and path dialog.
parent 7988f2ca
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Name:        3d_viewer.h
// Name:        3d_viewer.h
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

#ifndef __3D_VIEWER_H__
#define __3D_VIEWER_H__

#if !wxUSE_GLCANVAS
#if !wxUSE_GLCANVAS
#error Please set wxUSE_GLCANVAS to 1 in setup.h.
#error Please set wxUSE_GLCANVAS to 1 in setup.h.
#endif
#endif
@@ -172,3 +176,5 @@ extern double g_Draw3d_dx, g_Draw3d_dy;
extern double ZBottom, ZTop;
extern double ZBottom, ZTop;
extern double DataScale3D;  // coeff de conversion unites utilsateut -> unites 3D
extern double DataScale3D;  // coeff de conversion unites utilsateut -> unites 3D
extern int gl_attrib[];
extern int gl_attrib[];

#endif  /*  __3D_VIEWER_H__ */
+2 −2
Original line number Original line Diff line number Diff line
@@ -116,9 +116,9 @@ wxPoint BASE_SCREEN::CursorRealPosition( const wxPoint& ScreenPos )
    wxPoint curpos = ScreenPos;
    wxPoint curpos = ScreenPos;
    Unscale( curpos );
    Unscale( curpos );


#ifndef WX_ZOOM
//#ifndef WX_ZOOM
    curpos += m_DrawOrg;
    curpos += m_DrawOrg;
#endif
//#endif


    return curpos;
    return curpos;
}
}
+9 −2
Original line number Original line Diff line number Diff line
@@ -590,8 +590,15 @@ void WinEDA_DrawFrame::AdjustScrollBars()
#else
#else
    BASE_SCREEN* screen = GetBaseScreen();
    BASE_SCREEN* screen = GetBaseScreen();
    wxSize drawingSize = screen->ReturnPageSize() * 2;
    wxSize drawingSize = screen->ReturnPageSize() * 2;
    DrawPanel->SetScrollbars( 1, 1, drawingSize.x, drawingSize.y,
    wxCoord x, y;
                              screen->m_Curseur.x, screen->m_Curseur.y, true );
    wxClientDC DC( this );
    DrawPanel->PrepareGraphicContext( &DC );
    x = DC.LogicalToDeviceXRel( drawingSize.GetWidth() );
    y = DC.LogicalToDeviceYRel( drawingSize.GetHeight() );
    DrawPanel->SetScrollbars( 1, 1, x, y,
                              DC.LogicalToDeviceX( screen->m_Curseur.x ),
                              DC.LogicalToDeviceY( screen->m_Curseur.y ),
                              true );
#endif
#endif
}
}


+8 −11
Original line number Original line Diff line number Diff line
@@ -199,14 +199,12 @@ void WinEDA_DrawPanel::PrepareGraphicContext( wxDC* DC )
#ifdef WX_ZOOM
#ifdef WX_ZOOM
    double scale = GetScreen()->GetScalingFactor();
    double scale = GetScreen()->GetScalingFactor();
    wxPoint origin = GetScreen()->m_DrawOrg;
    wxPoint origin = GetScreen()->m_DrawOrg;
    wxLogDebug( wxT( "DC user scale factor: %0.3f, X origin: %d, Y " \
                     "origin: %d" ), scale, origin.x, origin.y );
    int ppuX, ppuY, startX, startY;
    int ppuX, ppuY, startX, startY;
    GetScrollPixelsPerUnit( & ppuX, & ppuY );
    GetScrollPixelsPerUnit( & ppuX, & ppuY );
    GetViewStart( &startX, &startY );
    GetViewStart( &startX, &startY );
    DC->SetDeviceOrigin( origin.x - startX * ppuX, origin.y - startY * ppuY );
    DC->SetDeviceOrigin( origin.x - startX * ppuX, origin.y - startY * ppuY );
    DC->SetUserScale( scale, scale );
    DC->SetUserScale( scale, scale );
    wxSize size = GetScreen()->ReturnPageSize() * 2 * scale;
//    wxSize size = GetScreen()->ReturnPageSize() * 2 * scale;
//    DC->SetLogicalOrigin( origin.x, origin.y );
//    DC->SetLogicalOrigin( origin.x, origin.y );
#endif
#endif
    SetBoundaryBox();
    SetBoundaryBox();
@@ -368,12 +366,11 @@ wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition( void )


    GetScreen()->Unscale( realpos );
    GetScreen()->Unscale( realpos );
#ifdef WX_ZOOM
#ifdef WX_ZOOM
    wxCoord x, y;
//    wxCoord x, y;
    wxClientDC DC( this );
//    wxClientDC DC( this );
    PrepareGraphicContext( &DC );
//    PrepareGraphicContext( &DC );
    x = DC.DeviceToLogicalX( realpos.x );
//    realpos.x = DC.DeviceToLogicalX( realpos.x );
    y = DC.DeviceToLogicalY( realpos.y );
//    realpos.y = DC.DeviceToLogicalY( realpos.y );
    return wxPoint( x, y );
#else
#else
    realpos += GetScreen()->m_DrawOrg;
    realpos += GetScreen()->m_DrawOrg;
#endif
#endif
+58 −62
Original line number Original line Diff line number Diff line
@@ -15,19 +15,21 @@
#include "protos.h"
#include "protos.h"
#include "cvstruct.h"
#include "cvstruct.h"



#define QUOTE '\''
#define QUOTE '\''


class AUTOMODULE
class FOOTPRINT_ALIAS
{
{
public:
public:
    int         m_Type;
    int         m_Type;
    AUTOMODULE* Pnext;
    wxString    m_Name;
    wxString    m_Name;
    wxString    m_LibName;
    wxString    m_FootprintName;


    AUTOMODULE() { m_Type = 0; Pnext = NULL; }
    FOOTPRINT_ALIAS() { m_Type = 0; }
};
};


typedef boost::ptr_vector< FOOTPRINT_ALIAS > FOOTPRINT_ALIAS_LIST;



/*
/*
 * read the string between quotes and put it in aTarget
 * read the string between quotes and put it in aTarget
@@ -68,18 +70,13 @@ char * ReadQuotedText(wxString & aTarget, char * aText)
 */
 */
void WinEDA_CvpcbFrame::AssocieModule( wxCommandEvent& event )
void WinEDA_CvpcbFrame::AssocieModule( wxCommandEvent& event )
{
{
    COMPONENT_LIST::iterator iCmp;
    FOOTPRINT_ALIAS_LIST aliases;
    FOOTPRINT_LIST::iterator iFp;
    FOOTPRINT_ALIAS*     alias;
    wxFileName           fn;
    wxFileName           fn;
    wxString             msg, tmp;
    wxString             msg, tmp;
    char                 Line[1024];
    char                 Line[1024];
    FILE*                file;
    FILE*                file;
    AUTOMODULE* ItemModule, * NextMod;
    AUTOMODULE* BaseListeMod = NULL;
    COMPONENT*  Component;
    FOOTPRINT*  footprint;
    size_t               ii;
    size_t               ii;
    int         nb_correspondances = 0;


    if( m_components.empty() )
    if( m_components.empty() )
        return;
        return;
@@ -89,7 +86,6 @@ void WinEDA_CvpcbFrame::AssocieModule( wxCommandEvent& event )
    {
    {
        fn = m_AliasLibNames[ii];
        fn = m_AliasLibNames[ii];
        fn.SetExt( FootprintAliasFileExtension );
        fn.SetExt( FootprintAliasFileExtension );

        tmp = wxGetApp().FindLibraryPath( fn );
        tmp = wxGetApp().FindLibraryPath( fn );


        if( !tmp )
        if( !tmp )
@@ -101,6 +97,8 @@ void WinEDA_CvpcbFrame::AssocieModule( wxCommandEvent& event )
            continue;
            continue;
        }
        }


        wxLogDebug( wxT( "Opening footprint alias file: %s." ), tmp.c_str() );

        file = wxFopen( tmp, wxT( "rt" ) );
        file = wxFopen( tmp, wxT( "rt" ) );


        if( file == NULL )
        if( file == NULL )
@@ -114,71 +112,69 @@ void WinEDA_CvpcbFrame::AssocieModule( wxCommandEvent& event )
        while( GetLine( file, Line, NULL, sizeof(Line) ) != NULL )
        while( GetLine( file, Line, NULL, sizeof(Line) ) != NULL )
        {
        {
            char* text = Line;
            char* text = Line;
            text = ReadQuotedText(tmp, text);
            wxString value, footprint;

            text = ReadQuotedText( value, text );


            if ( text == NULL || (*text == 0 )  )
            if( text == NULL || ( *text == 0 ) || value.IsEmpty() )
                continue;
                continue;


            ItemModule = new AUTOMODULE();
            text++;
            ItemModule->Pnext = BaseListeMod;
            text = ReadQuotedText( footprint, text );
            BaseListeMod = ItemModule;


            /* stockage du composant ( 'namecmp'  'namelib')
            if( footprint.IsEmpty() )
             *  name et namelib */
                continue;
            ItemModule->m_Name = tmp;


            alias = new FOOTPRINT_ALIAS();
            alias->m_Name = value;
            alias->m_FootprintName = footprint;
            wxLogDebug( wxT( "Adding alias %s for footprint %s" ),
                        value.c_str(), footprint.c_str() );
            aliases.push_back( alias );
            text++;
            text++;
            ReadQuotedText(ItemModule->m_LibName, text);

            nb_correspondances++;
        }
        }


        fclose( file );
        fclose( file );
    }
    }


    /* display some info */
    /* Display the number of footpint aliases.  */
    msg.Printf( _( "%d equivalences" ), nb_correspondances );
    msg.Printf( _( "%d footprint aliases found." ), aliases.size() );
    SetStatusText( msg, 0 );
    SetStatusText( msg, 0 );
    wxMessageBox(msg);


    for( iCmp = m_components.begin(); iCmp != m_components.end(); ++iCmp )
    ii = 0;
    {
        Component = *iCmp;
        m_ListCmp->SetSelection( m_components.IndexOf( Component ), TRUE );


        if( Component->m_Module.IsEmpty() )
    BOOST_FOREACH( COMPONENT& component, m_components )
    {
    {
            ItemModule = BaseListeMod;
        m_ListCmp->SetSelection( ii, true );
            for( ; ItemModule != NULL; ItemModule = ItemModule->Pnext )

            {
        if( !component.m_Module.IsEmpty() )
                if( ItemModule->m_Name.CmpNoCase( Component->m_Valeur ) != 0 )
            continue;
            continue;


                for( iFp = m_footprints.begin(); iFp != m_footprints.end(); ++iFp )
        BOOST_FOREACH( FOOTPRINT_ALIAS& alias, aliases )
        {
        {
                    footprint = *iFp;
            if( alias.m_Name.CmpNoCase( component.m_Value ) != 0 )
                continue;


                    if( ItemModule->m_LibName.CmpNoCase( footprint->m_Module ) == 0 )
            BOOST_FOREACH( FOOTPRINT& footprint, m_footprints )
            {
                if( alias.m_FootprintName.CmpNoCase( footprint.m_Module ) == 0 )
                {
                {
                        SetNewPkg( footprint->m_Module );
                    SetNewPkg( footprint.m_Module );
                    break;
                    break;
                }
                }
            }
            }


                msg.Printf( _( "Component %s: Footprint %s not found in " \
            if( component.m_Module.IsEmpty() )
                               "libraries" ), Component->m_Valeur.GetData(),
            {
                            ItemModule->m_LibName.GetData() );
                msg.Printf( _( "Component %s: footprint %s not found in " \
                DisplayError( this, msg, 10 );
                               "any of the project footprint libraries." ),
            }
                            component.m_Reference.c_str(),
                            alias.m_FootprintName.c_str() );
                wxMessageBox( msg, _( "CVPcb Error" ), wxOK | wxICON_ERROR,
                              this );
            }
            }
        }
        }


    /* free memory: */
        ii += 1;
    for( ItemModule = BaseListeMod; ItemModule != NULL; ItemModule = NextMod )
    {
        NextMod = ItemModule->Pnext;
        delete ItemModule;
    }
    }

    BaseListeMod = NULL;
}
}
Loading