Commit 7e24e438 authored by stambaughw's avatar stambaughw
Browse files

wxWidgets 2.9 string fixes and other minor updates.

* Replace all known instances of (const wxChar*) casts to GetChars() for
  wxWidgets 2.9 compatibility.
* Cleaned up get component dialog so last part gets saved on wild card
  selections.
* Remove redundant schematic component drawing code.
* Added SCH_COMPONENT constructor to create new component from library
  component object.
* Add message panel helpers to WinEDA_DrawFrame and update old message
  panel access code.
* Using library viewer to add component to schematic now respects unit
  and body style selection.
parent 64032f34
Loading
Loading
Loading
Loading
+63 −107
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@
#include "common.h"
#include "common.h"
#include "macros.h"
#include "macros.h"
#include "wxstruct.h"
#include "wxstruct.h"
#include "get_component_dialog.h"




/****************************************************************************/
/****************************************************************************/
@@ -15,46 +16,7 @@
/****************************************************************************/
/****************************************************************************/


static unsigned s_HistoryMaxCount = 8;  // Max number of items displayed in history list
static unsigned s_HistoryMaxCount = 8;  // Max number of items displayed in history list
static wxString s_ItemName;



enum selcmp_id {
    ID_ACCEPT_NAME = 3900,
    ID_ACCEPT_KEYWORD,
    ID_ENTER_NAME,
    ID_CANCEL,
    ID_LIST_ALL,
    ID_EXTRA_TOOL,
    ID_SEL_BY_LISTBOX
};

/***************************************/
class WinEDA_SelectCmp : public wxDialog
/***************************************/
{
private:
    WinEDA_DrawFrame* m_Parent;
    bool m_AuxTool;
    wxString*         m_Text;
    wxTextCtrl*       m_TextCtrl;
    wxListBox*        m_List;
public:
    bool m_GetExtraFunction;

public:

    // Constructor and destructor
    WinEDA_SelectCmp( WinEDA_DrawFrame* parent, const wxPoint& framepos,
                      wxArrayString& HistoryList, const wxString& Title,
                      bool show_extra_tool );
    ~WinEDA_SelectCmp() {};

private:
    void Accept( wxCommandEvent& event );
    void GetExtraSelection( wxCommandEvent& event );

    DECLARE_EVENT_TABLE()
};


BEGIN_EVENT_TABLE( WinEDA_SelectCmp, wxDialog )
BEGIN_EVENT_TABLE( WinEDA_SelectCmp, wxDialog )
    EVT_BUTTON( ID_ACCEPT_NAME, WinEDA_SelectCmp::Accept )
    EVT_BUTTON( ID_ACCEPT_NAME, WinEDA_SelectCmp::Accept )
@@ -66,28 +28,22 @@ BEGIN_EVENT_TABLE( WinEDA_SelectCmp, wxDialog )
END_EVENT_TABLE()
END_EVENT_TABLE()




/****************************************************************************/
/*
 * Dialog frame to choose a component or a footprint
 *   This dialog shows an history of last selected items
 */
WinEDA_SelectCmp::WinEDA_SelectCmp( WinEDA_DrawFrame* parent,
WinEDA_SelectCmp::WinEDA_SelectCmp( WinEDA_DrawFrame* parent,
                                    const wxPoint&    framepos,
                                    const wxPoint&    framepos,
                                    wxArrayString&    HistoryList,
                                    wxArrayString&    HistoryList,
                                    const wxString&   Title,
                                    const wxString&   Title,
                                    bool              show_extra_tool ) :
                                    bool              show_extra_tool ) :
    wxDialog( parent, -1, Title, framepos, wxDefaultSize, DIALOG_STYLE )
    wxDialog( parent, -1, Title, framepos, wxDefaultSize, DIALOG_STYLE )
/****************************************************************************/

/* Dialog frame to choose a component or a footprint
 *   This dialog shows an history of last selected items
 */
{
{
    wxButton*     Button;
    wxButton*     Button;
    wxStaticText* Text;
    wxStaticText* Text;


    m_Parent  = parent;
    m_AuxTool = show_extra_tool;
    m_AuxTool = show_extra_tool;
    m_GetExtraFunction = FALSE;
    m_GetExtraFunction = false;

    s_ItemName.Empty();
    m_Text = &s_ItemName;


    wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
    wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
    SetSizer( MainBoxSizer );
    SetSizer( MainBoxSizer );
@@ -127,7 +83,7 @@ WinEDA_SelectCmp::WinEDA_SelectCmp( WinEDA_DrawFrame* parent,
                        wxGROW | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM,
                        wxGROW | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM,
                        5 );
                        5 );


    Button = new wxButton( this, ID_ACCEPT_KEYWORD, _( "Search KeyWord" ) );
    Button = new wxButton( this, ID_ACCEPT_KEYWORD, _( "Search by Keyword" ) );
    RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
    RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );


    Button = new wxButton( this, ID_CANCEL, _( "Cancel" ) );
    Button = new wxButton( this, ID_CANCEL, _( "Cancel" ) );
@@ -139,7 +95,7 @@ WinEDA_SelectCmp::WinEDA_SelectCmp( WinEDA_DrawFrame* parent,
#ifndef __WXMAC__
#ifndef __WXMAC__
    if( m_AuxTool )     /* The selection can be done by an extra function */
    if( m_AuxTool )     /* The selection can be done by an extra function */
    {
    {
        Button = new wxButton( this, ID_EXTRA_TOOL, _( "By Lib Browser" ) );
        Button = new wxButton( this, ID_EXTRA_TOOL, _( "Select by Browser" ) );
        RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
        RightBoxSizer->Add( Button, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
    }
    }
#endif
#endif
@@ -149,98 +105,98 @@ WinEDA_SelectCmp::WinEDA_SelectCmp( WinEDA_DrawFrame* parent,
}
}




/*********************************************************/
void WinEDA_SelectCmp::Accept( wxCommandEvent& event )
void WinEDA_SelectCmp::Accept( wxCommandEvent& event )
/*********************************************************/
{
{
    int id = wxID_OK;

    switch( event.GetId() )
    switch( event.GetId() )
    {
    {
    case ID_SEL_BY_LISTBOX:
    case ID_SEL_BY_LISTBOX:
        *m_Text = m_List->GetStringSelection();
        m_Text = m_List->GetStringSelection();
        break;
        break;


    case ID_ACCEPT_NAME:
    case ID_ACCEPT_NAME:
        *m_Text = m_TextCtrl->GetValue();
        m_Text = m_TextCtrl->GetValue();
        break;
        break;


    case ID_ACCEPT_KEYWORD:
    case ID_ACCEPT_KEYWORD:
        *m_Text = wxT( "= " ) + m_TextCtrl->GetValue();
        m_Text = wxT( "= " ) + m_TextCtrl->GetValue();
        break;
        break;


    case ID_CANCEL:
    case ID_CANCEL:
        *m_Text = wxEmptyString;
        m_Text = wxEmptyString;
        id = wxID_CANCEL;
        break;
        break;


    case ID_LIST_ALL:
    case ID_LIST_ALL:
        *m_Text = wxT( "*" );
        m_Text = wxT( "*" );
        break;
        break;
    }
    }


    m_Text->Trim( FALSE );      // Remove blanks at beginning
    m_Text.Trim( false );      // Remove blanks at beginning
    m_Text->Trim( TRUE );       // Remove blanks at end
    m_Text.Trim( true );       // Remove blanks at end
    Close( TRUE );

    if( IsModal() )
        EndModal( id );
    else
        Close( id );
}
}




/**************************************************************/
/* Get the component name by the extra function */
void WinEDA_SelectCmp::GetExtraSelection( wxCommandEvent& event )
void WinEDA_SelectCmp::GetExtraSelection( wxCommandEvent& event )
/**************************************************************/
{
    m_GetExtraFunction = true;


/* Get the component name by the extra function
    if( IsModal() )
 */
        EndModal( wxID_OK );
    else
        Close( wxID_OK );
}


wxString WinEDA_SelectCmp::GetComponentName( void )
{
{
    m_GetExtraFunction = TRUE;
    return m_Text;
    Close( TRUE );
}
}




/******************************************************************************/
void WinEDA_SelectCmp::SetComponentName( const wxString& name )
wxString GetComponentName( WinEDA_DrawFrame* frame,
{
                          wxArrayString& HistoryList, const wxString& Title,
    if( m_TextCtrl )
                          wxString (*AuxTool)( WinEDA_DrawFrame* parent ) )
        m_TextCtrl->SetValue( name );
/*******************************************************************************/
}


/* Dialog frame to choose a component name

 */
wxPoint GetComponentDialogPosition( void )
{
{
    wxPoint framepos;
    wxPoint pos;
    int     x, y, w, h;
    int     x, y, w, h;
    bool    GetExtraFunction;


    framepos = wxGetMousePosition();
    pos = wxGetMousePosition();
    wxClientDisplayRect( &x, &y, &w, &h );
    wxClientDisplayRect( &x, &y, &w, &h );
    framepos.x -= 100;
    pos.x -= 100;
    framepos.y -= 50;
    pos.y -= 50;
    if( framepos.x < x )
    if( pos.x < x )
        framepos.x = x;
        pos.x = x;
    if( framepos.y < y )
    if( pos.y < y )
        framepos.y = y;
        pos.y = y;
    if( framepos.x < x )
    if( pos.x < x )
        framepos.x = x;
        pos.x = x;
    x += w - 350;
    x += w - 350;
    if( framepos.x > x )
    if( pos.x > x )
        framepos.x = x;
        pos.x = x;
    if( framepos.y < y )
    if( pos.y < y )
        framepos.y = y;
        pos.y = y;
    WinEDA_SelectCmp* selframe =
        new WinEDA_SelectCmp( frame, framepos, HistoryList, Title,
                              AuxTool ? TRUE : FALSE );
    selframe->ShowModal();
    GetExtraFunction = selframe->m_GetExtraFunction;
    selframe->Destroy();

    if( GetExtraFunction )
        s_ItemName = AuxTool( frame );
    return s_ItemName;
}


    return pos;
}


/*******************************************************************************/
void AddHistoryComponentName( wxArrayString& HistoryList, const wxString& Name )
/*******************************************************************************/


/* Add the string "Name" to the history list HistoryList
/*
 * Add the string "Name" to the history list HistoryList
 */
 */
void AddHistoryComponentName( wxArrayString& HistoryList, const wxString& Name )
{
{
    int ii, c_max;
    int ii, c_max;


+2 −2
Original line number Original line Diff line number Diff line
@@ -671,7 +671,7 @@ bool LIB_COMPONENT::Load( FILE* file, char* line, int* lineNum,
                errorMsg.Printf( wxT( "error occurred at line %d " ), *lineNum );
                errorMsg.Printf( wxT( "error occurred at line %d " ), *lineNum );
            else
            else
                errorMsg.Printf( wxT( "error <%s> occurred at line %d " ),
                errorMsg.Printf( wxT( "error <%s> occurred at line %d " ),
                                 ( const wxChar* ) Msg, *lineNum );
                                 GetChars( Msg ), *lineNum );
            return false;
            return false;
        }
        }
    }
    }
@@ -739,7 +739,7 @@ bool LIB_COMPONENT::LoadDrawEntries( FILE* f, char* line,
        if( !newEntry->Load( line, errorMsg ) )
        if( !newEntry->Load( line, errorMsg ) )
        {
        {
            errorMsg.Printf( wxT( "error <%s> in DRAW command %c" ),
            errorMsg.Printf( wxT( "error <%s> in DRAW command %c" ),
                             ( const wxChar* ) errorMsg, line[0] );
                             GetChars( errorMsg ), line[0] );
            SAFE_DELETE( newEntry );
            SAFE_DELETE( newEntry );


            /* Flush till end of draw section */
            /* Flush till end of draw section */
+30 −30
Original line number Original line Diff line number Diff line
@@ -199,8 +199,8 @@ bool CMP_LIBRARY::AddAlias( LIB_ALIAS* alias )
        wxString msg;
        wxString msg;


        msg.Printf( _( "Cannot add duplicate alias <%s> to library <%s>." ),
        msg.Printf( _( "Cannot add duplicate alias <%s> to library <%s>." ),
                    (const wxChar*) alias->GetName(),
                    GetChars( alias->GetName() ),
                    (const wxChar*) m_fileName.GetName() );
                    GetChars( m_fileName.GetName() ) );
        return false;
        return false;
    }
    }


@@ -239,9 +239,9 @@ LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* cmp )
            {
            {
                wxLogError( _( "Conflict in library <%s>: alias <%s> already \
                wxLogError( _( "Conflict in library <%s>: alias <%s> already \
has root name <%s> and will not be assigned to root name <%s>." ),
has root name <%s> and will not be assigned to root name <%s>." ),
                        (const wxChar*) m_fileName.GetName(),
                            GetChars( m_fileName.GetName() ),
                        (const wxChar*) alias->GetComponent()->GetName(),
                            GetChars( alias->GetComponent()->GetName() ),
                        (const wxChar*) newCmp->GetName() );
                            GetChars( newCmp->GetName() ) );
            }
            }
        }
        }
    }
    }
@@ -287,8 +287,8 @@ void CMP_LIBRARY::RemoveEntry( CMP_LIB_ENTRY* entry )
        {
        {
            wxLogWarning( wxT( "No root component found for alias <%s> in \
            wxLogWarning( wxT( "No root component found for alias <%s> in \
library <%s>." ),
library <%s>." ),
                          ( const wxChar* ) entry->GetName(),
                          GetChars( entry->GetName() ),
                          ( const wxChar* ) m_fileName.GetName() );
                          GetChars( m_fileName.GetName() ) );
        }
        }
        else
        else
        {
        {
@@ -297,9 +297,9 @@ library <%s>." ),
            if( index == wxNOT_FOUND )
            if( index == wxNOT_FOUND )
                wxLogWarning( wxT( "Alias <%s> not found in component <%s> \
                wxLogWarning( wxT( "Alias <%s> not found in component <%s> \
alias list in library <%s>" ),
alias list in library <%s>" ),
                              ( const wxChar* ) entry->GetName(),
                              GetChars( entry->GetName() ),
                              ( const wxChar* ) Root->GetName(),
                              GetChars( Root->GetName() ),
                              ( const wxChar* ) m_fileName.GetName() );
                              GetChars( m_fileName.GetName() ) );
            else
            else
                Root->m_AliasList.RemoveAt( index );
                Root->m_AliasList.RemoveAt( index );
        }
        }
@@ -329,9 +329,9 @@ alias list in library <%s>" ),
    {
    {
        wxLogWarning( wxT( "Alias <%s> for component <%s> not found in \
        wxLogWarning( wxT( "Alias <%s> for component <%s> not found in \
library <%s>" ),
library <%s>" ),
                      ( const wxChar* ) AliasName,
                      GetChars( AliasName ),
                      ( const wxChar* ) Root->GetName(),
                      GetChars( Root->GetName() ),
                      ( const wxChar* ) m_fileName.GetName() );
                      GetChars( m_fileName.GetName() ) );
        return;
        return;
    }
    }


@@ -373,9 +373,9 @@ LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* oldComponent,


            wxLogDebug( wxT( "Removing extra alias <%s> from component <%s> \
            wxLogDebug( wxT( "Removing extra alias <%s> from component <%s> \
in library <%s>." ),
in library <%s>." ),
                        (const wxChar*) oldComponent->m_AliasList[ i ],
                        GetChars( oldComponent->m_AliasList[ i ] ),
                        (const wxChar*) oldComponent->GetName(),
                        GetChars( oldComponent->GetName() ),
                        (const wxChar*) m_fileName.GetName() );
                        GetChars( m_fileName.GetName() ) );


            RemoveEntry( oldComponent->m_AliasList[ i ] );
            RemoveEntry( oldComponent->m_AliasList[ i ] );
        }
        }
@@ -392,9 +392,9 @@ in library <%s>." ),


            wxLogDebug( wxT( "Adding extra alias <%s> from component <%s> \
            wxLogDebug( wxT( "Adding extra alias <%s> from component <%s> \
in library <%s>." ),
in library <%s>." ),
                        (const wxChar*) newComponent->m_AliasList[ i ],
                        GetChars( newComponent->m_AliasList[ i ] ),
                        (const wxChar*) newComponent->GetName(),
                        GetChars( newComponent->GetName() ),
                        (const wxChar*) m_fileName.GetName() );
                        GetChars( m_fileName.GetName() ) );


            alias = new LIB_ALIAS( newComponent->m_AliasList[ i ],
            alias = new LIB_ALIAS( newComponent->m_AliasList[ i ],
                                   newComponent );
                                   newComponent );
@@ -534,7 +534,7 @@ number is invalid.\n\nIn future versions of EESchema this library may not \
load correctly.  To resolve this problem open the library in the library \
load correctly.  To resolve this problem open the library in the library \
editor and save it.  If this library is the project cache library, save \
editor and save it.  If this library is the project cache library, save \
the current schematic." ),
the current schematic." ),
                          (const wxChar*) GetName() );
                          GetChars( GetName() ) );
        }
        }
        else
        else
        {
        {
@@ -542,7 +542,7 @@ the current schematic." ),
            m_verMinor = (int) minor;
            m_verMinor = (int) minor;


            wxLogDebug( wxT( "Component library <%s> is version %d.%d." ),
            wxLogDebug( wxT( "Component library <%s> is version %d.%d." ),
                        (const wxChar*) GetName(), m_verMajor, m_verMinor );
                        GetChars( GetName() ), m_verMajor, m_verMinor );
        }
        }
    }
    }


@@ -573,8 +573,8 @@ the current schematic." ),
                if( FindEntry( LibEntry->GetName() ) != NULL )
                if( FindEntry( LibEntry->GetName() ) != NULL )
                {
                {
                    wxLogWarning( duplicate_name_msg,
                    wxLogWarning( duplicate_name_msg,
                                  (const wxChar*) m_fileName.GetName(),
                                  GetChars( m_fileName.GetName() ),
                                  (const wxChar*) LibEntry->GetName() );
                                  GetChars( LibEntry->GetName() ) );
                }
                }


                /* If we are here, this part is O.k. - put it in: */
                /* If we are here, this part is O.k. - put it in: */
@@ -584,8 +584,8 @@ the current schematic." ),
            else
            else
            {
            {
                wxLogWarning( _( "Library <%s> component load error %s." ),
                wxLogWarning( _( "Library <%s> component load error %s." ),
                              (const wxChar*) m_fileName.GetName(),
                              GetChars( m_fileName.GetName() ),
                              (const wxChar*) msg );
                              GetChars( msg ) );
                msg.Clear();
                msg.Clear();
                delete LibEntry;
                delete LibEntry;
            }
            }
@@ -610,8 +610,8 @@ void CMP_LIBRARY::LoadAliases( LIB_COMPONENT* component )
        if( FindEntry( component->m_AliasList[ii] ) != NULL )
        if( FindEntry( component->m_AliasList[ii] ) != NULL )
        {
        {
            wxLogError( duplicate_name_msg,
            wxLogError( duplicate_name_msg,
                        (const wxChar*) m_fileName.GetName(),
                        GetChars( m_fileName.GetName() ),
                        (const wxChar*) component->m_AliasList[ii] );
                        GetChars( component->m_AliasList[ii] ) );
        }
        }


        alias = new LIB_ALIAS( component->m_AliasList[ii], component, this );
        alias = new LIB_ALIAS( component->m_AliasList[ii], component, this );
@@ -654,14 +654,14 @@ bool CMP_LIBRARY::LoadDocs( wxString& errMsg )
    if( f == NULL )
    if( f == NULL )
    {
    {
        errMsg.Printf( _( "Could not open component document libray file <%s>." ),
        errMsg.Printf( _( "Could not open component document libray file <%s>." ),
                       (const wxChar*) fn.GetFullPath() );
                       GetChars( fn.GetFullPath() ) );
        return false;
        return false;
    }
    }


    if( GetLine( f, Line, &LineNum, sizeof(Line) ) == NULL )
    if( GetLine( f, Line, &LineNum, sizeof(Line) ) == NULL )
    {
    {
        errMsg.Printf( _( "Component document libray file <%s> is empty." ),
        errMsg.Printf( _( "Component document libray file <%s> is empty." ),
                       (const wxChar*) fn.GetFullPath() );
                       GetChars( fn.GetFullPath() ) );
        fclose( f );
        fclose( f );
        return false;
        return false;
    }
    }
@@ -670,7 +670,7 @@ bool CMP_LIBRARY::LoadDocs( wxString& errMsg )
    {
    {
        errMsg.Printf( _( "File <%s> is not a valid component library \
        errMsg.Printf( _( "File <%s> is not a valid component library \
document file." ),
document file." ),
                       (const wxChar*) fn.GetFullPath() );
                       GetChars( fn.GetFullPath() ) );
        fclose( f );
        fclose( f );
        return false;
        return false;
    }
    }
+122 −76
Original line number Original line Diff line number Diff line
@@ -50,89 +50,78 @@ void CreateDummyCmp()
}
}




/*****************************************************************************
/*******************************************************************/
* Routine to draw the given part at given position, transformed/mirror as
SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) :
* specified, and in the given drawing mode.
    SCH_ITEM( aParent, TYPE_SCH_COMPONENT )
* if Color < 0: Draw in normal color
* else draw  in color = Color
*****************************************************************************/
/* DrawMode  = GrXOR, GrOR ..*/
void DrawLibPartAux( WinEDA_DrawPanel* panel, wxDC* DC,
                     SCH_COMPONENT* Component, LIB_COMPONENT* Entry,
                     const wxPoint& Pos, const int TransMat[2][2],
                     int Multi, int convert, int DrawMode,
                     int Color, bool DrawPinText )
{
    Entry->Draw( panel, DC, Pos, Multi, convert, DrawMode, Color, TransMat,
                 DrawPinText, false );

    /* Enable this to draw the bounding box around the component to validate
     * the bounding box calculations. */
#if 0
    /* Draw the component boundary box */
{
{
        EDA_Rect BoundaryBox;
    Init( aPos );
        if( Component )
            BoundaryBox = Component->GetBoundaryBox();
        else
            BoundaryBox = Entry->GetBoundaryBox( Multi, convert );
        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 );
        BoundaryBox = Component->GetField( REFERENCE )->GetBoundaryBox();
        x1 = BoundaryBox.GetX();
        y1 = BoundaryBox.GetY();
        x2 = BoundaryBox.GetRight();
        y2 = BoundaryBox.GetBottom();
        GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
        BoundaryBox = Component->GetField( VALUE )->GetBoundaryBox();
        x1 = BoundaryBox.GetX();
        y1 = BoundaryBox.GetY();
        x2 = BoundaryBox.GetRight();
        y2 = BoundaryBox.GetBottom();
        GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
    }
#endif
}
}





SCH_COMPONENT::SCH_COMPONENT( LIB_COMPONENT& libComponent, DrawSheetPath* sheet,
/*******************************************************************/
                              int unit, int convert, const wxPoint& pos,
SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) :
                              bool setNewItemFlag ) :
    SCH_ITEM( aParent, TYPE_SCH_COMPONENT )
    SCH_ITEM( NULL, TYPE_SCH_COMPONENT )
{
{
    m_Multi = 0;    /* In multi unit chip - which unit to draw. */
    Init( pos );


    m_Pos = aPos;
    m_Multi     = unit;
    m_Convert   = convert;
    m_ChipName  = libComponent.GetName();
    m_TimeStamp = GetTimeStamp();


    m_Convert = 0;  /* De Morgan Handling  */
    if( setNewItemFlag )
        m_Flags = IS_NEW | IS_MOVED;


    /* The rotation/mirror transformation matrix. pos normal */
    GetField( VALUE )->m_Pos = libComponent.m_Name.m_Pos + m_Pos;
    m_Transform[0][0] = 1;
    GetField( VALUE )->ImportValues( libComponent.m_Name );
    m_Transform[0][1] = 0;
    GetField( VALUE )->m_Text = m_ChipName;
    m_Transform[1][0] = 0;
    m_Transform[1][1] = -1;


    m_Fields.reserve( NUMBER_OF_FIELDS );
    wxString msg = libComponent.m_Prefix.m_Text;
    if( msg.IsEmpty() )
        msg = wxT( "U" );
    msg += wxT( "?" );


    for( int i = 0; i < NUMBER_OF_FIELDS; ++i )
    // update the reference -- just the prefix for now.
    {
    SetRef( sheet, msg );
        SCH_CMP_FIELD field( aPos, i, this, ReturnDefaultFieldName( i ) );


        if( i==REFERENCE )
    GetField( REFERENCE )->m_Pos = libComponent.m_Prefix.m_Pos + m_Pos;
            field.SetLayer( LAYER_REFERENCEPART );
    GetField( REFERENCE )->ImportValues( libComponent.m_Prefix );
        else if( i==VALUE )
    m_PrefixString = libComponent.m_Prefix.m_Text;
            field.SetLayer( LAYER_VALUEPART );


        // else keep LAYER_FIELDS from SCH_CMP_FIELD constructor
    /* Init des autres champs si predefinis dans la librairie */
    LIB_FIELD* EntryField;
    int        ii;


        // SCH_CMP_FIELD's implicitly created copy constructor is called in here
    for( EntryField = libComponent.m_Fields; EntryField != NULL;
         EntryField = EntryField->Next() )
    {
        if( EntryField->m_Text.IsEmpty() && EntryField->m_Name.IsEmpty() )
            continue;

        ii = EntryField->m_FieldId;
        if( ii < 2 )        // Reference or value, already done
            continue;

        if( ii >= GetFieldCount() )
        {   // This entry has more than the default count: add extra fields
            while( ii >= GetFieldCount() )
            {
                int field_id = GetFieldCount();
                SCH_CMP_FIELD field( wxPoint( 0, 0 ), field_id, this,
                                     ReturnDefaultFieldName( ii ) );
                AddField( field );
                AddField( field );
            }
            }
        }


    m_PrefixString = wxString( _( "U" ) );
        SCH_CMP_FIELD* curr_field = GetField( ii );

        curr_field->m_Pos = m_Pos + EntryField->m_Pos;
        curr_field->ImportValues( *EntryField );
        curr_field->m_Text = EntryField->m_Text;
        curr_field->m_Name =
            ( ii < FIELD1 ) ? ReturnDefaultFieldName( ii ) : EntryField->m_Name;
    }
}
}




@@ -157,12 +146,46 @@ SCH_COMPONENT::SCH_COMPONENT( const SCH_COMPONENT& aTemplate ) :
}
}




void SCH_COMPONENT::Init( const wxPoint& pos )
{
    m_Pos = pos;
    m_Multi = 0;    /* In multi unit chip - which unit to draw. */
    m_Convert = 0;  /* De Morgan Handling  */

    /* The rotation/mirror transformation matrix. pos normal */
    m_Transform[0][0] = 1;
    m_Transform[0][1] = 0;
    m_Transform[1][0] = 0;
    m_Transform[1][1] = -1;

    m_Fields.reserve( NUMBER_OF_FIELDS );

    for( int i = 0; i < NUMBER_OF_FIELDS; ++i )
    {
        SCH_CMP_FIELD field( pos, i, this, ReturnDefaultFieldName( i ) );

        if( i==REFERENCE )
            field.SetLayer( LAYER_REFERENCEPART );
        else if( i==VALUE )
            field.SetLayer( LAYER_VALUEPART );

        // else keep LAYER_FIELDS from SCH_CMP_FIELD constructor

        // SCH_CMP_FIELD's implicitly created copy constructor is called in here
        AddField( field );
    }

    m_PrefixString = wxString( _( "U" ) );
}


/*****************************************************************************
/*****************************************************************************
* Routine to draw the given part at given position, transformed/mirror as	 *
* Routine to draw the given part at given position, transformed/mirror as	 *
* specified, and in the given drawing mode. Only this one is visible...		 *
* specified, and in the given drawing mode. Only this one is visible...		 *
*****************************************************************************/
*****************************************************************************/
void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
                          const wxPoint& offset, int DrawMode, int Color )
                          const wxPoint& offset, int DrawMode, int Color,
                          bool DrawPinText )
{
{
    LIB_COMPONENT* Entry;
    LIB_COMPONENT* Entry;
    int  ii;
    int  ii;
@@ -172,19 +195,16 @@ void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,


    if( Entry == NULL )
    if( Entry == NULL )
    {
    {
        /* composant non trouve, on affiche un composant "dummy" */
        /* Create a dummy component if the actual component can not be found. */
        dummy = TRUE;
        dummy = TRUE;
        if( DummyCmp == NULL )
        if( DummyCmp == NULL )
            CreateDummyCmp();
            CreateDummyCmp();
        Entry = DummyCmp;
        Entry = DummyCmp;
    }
    }


    DrawLibPartAux( panel, DC, this, Entry, m_Pos + offset,  m_Transform,
    Entry->Draw( panel, DC, m_Pos + offset, dummy ? 0 : m_Multi,
                    dummy ? 0 : m_Multi, dummy ? 0 : m_Convert, DrawMode );
                 dummy ? 0 : m_Convert, DrawMode, Color, m_Transform,

                 DrawPinText );
    /* Trace des champs, avec placement et orientation selon orient. du
     *  composant
     */


    SCH_CMP_FIELD* field = GetField( REFERENCE );
    SCH_CMP_FIELD* field = GetField( REFERENCE );


@@ -212,6 +232,32 @@ void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,


        field->Draw( panel, DC, offset, DrawMode );
        field->Draw( panel, DC, offset, DrawMode );
    }
    }


#if 0
    /* Draw the component boundary box */
    {
        EDA_Rect BoundaryBox;
        BoundaryBox = GetBoundaryBox();
        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 );
        BoundaryBox = GetField( REFERENCE )->GetBoundaryBox();
        x1 = BoundaryBox.GetX();
        y1 = BoundaryBox.GetY();
        x2 = BoundaryBox.GetRight();
        y2 = BoundaryBox.GetBottom();
        GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
        BoundaryBox = GetField( VALUE )->GetBoundaryBox();
        x1 = BoundaryBox.GetX();
        y1 = BoundaryBox.GetY();
        x2 = BoundaryBox.GetRight();
        y2 = BoundaryBox.GetBottom();
        GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
    }
#endif
}
}




+31 −8

File changed.

Preview size limit exceeded, changes collapsed.

Loading