Commit 945f5f1e authored by charras's avatar charras
Browse files

eeschema: code cleaning.

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


2008-Apr-09 UPDATE  Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
+eeschema
    code cleaning.


2008-Apr-09 UPDATE  Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
2008-Apr-09 UPDATE  Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
================================================================================
+eeschema
+eeschema
+14 −3
Original line number Original line Diff line number Diff line
@@ -133,7 +133,14 @@ CmpListStruct* AllocateCmpListStrct( int numcomponents )
}
}




/* qsort function to annotate items by their position. */
/* qsort function to annotate items by their position.
*  Components are sorted
*      by reference
*      if same reference: by sheet
*          if same sheet, by X pos
*          	  if same X pos, by Y pos
*          		if same Y pos, by time stamp
*/
int AnnotateByPosition( const void* o1, const void* o2 )
int AnnotateByPosition( const void* o1, const void* o2 )
{
{
    CmpListStruct* item1 = (CmpListStruct*) o1;
    CmpListStruct* item1 = (CmpListStruct*) o1;
@@ -214,6 +221,10 @@ void DeleteAnnotation( WinEDA_SchematicFrame* parent, bool annotateSchematic )
*  Compute the annotation of the components for the whole project, or the
*  Compute the annotation of the components for the whole project, or the
*  current sheet only.  All the components or the new ones only will be
*  current sheet only.  All the components or the new ones only will be
*  annotated.
*  annotated.
* @param parent = Schematic frame
* @param annotateSchematic : true = entire schematic annotation, false = current scheet only
* @param sortByPosition : true = annotate by sorting X position, false = annotate by sorting value
* @param resetAnnotation : true = remove previous annotation false = anotate new components only
*****************************************************************************/
*****************************************************************************/
void AnnotateComponents( WinEDA_SchematicFrame* parent,
void AnnotateComponents( WinEDA_SchematicFrame* parent,
                         bool                   annotateSchematic,
                         bool                   annotateSchematic,
@@ -277,10 +288,10 @@ void AnnotateComponents( WinEDA_SchematicFrame* parent,


    if( sortByPosition )
    if( sortByPosition )
        qsort( BaseListeCmp, NbOfCmp, sizeof(CmpListStruct),
        qsort( BaseListeCmp, NbOfCmp, sizeof(CmpListStruct),
            ( int( * ) ( const void*, const void* ) )AnnotateByValue );
            ( int( * ) ( const void*, const void* ) )AnnotateByPosition );
    else
    else
        qsort( BaseListeCmp, NbOfCmp, sizeof(CmpListStruct),
        qsort( BaseListeCmp, NbOfCmp, sizeof(CmpListStruct),
            ( int( * ) ( const void*, const void* ) )AnnotateByPosition );
            ( int( * ) ( const void*, const void* ) ) AnnotateByValue);


    /* Recalculate reference numbers */
    /* Recalculate reference numbers */
    ComputeReferenceNumber( BaseListeCmp, NbOfCmp );
    ComputeReferenceNumber( BaseListeCmp, NbOfCmp );
+3 −0
Original line number Original line Diff line number Diff line
@@ -331,6 +331,9 @@ bool WinEDA_AnnotateFrame::GetResetItems( void )
}
}


bool WinEDA_AnnotateFrame::GetSortOrder( void )
bool WinEDA_AnnotateFrame::GetSortOrder( void )
/**
 * @return true if annotation by position, false if annotation by value
 */
{
{
    wxASSERT_MSG( (m_rbSortByPosition != NULL) &&
    wxASSERT_MSG( (m_rbSortByPosition != NULL) &&
                  m_rbSortByPosition->IsKindOf( CLASSINFO( wxRadioButton ) ),
                  m_rbSortByPosition->IsKindOf( CLASSINFO( wxRadioButton ) ),
+76 −0
Original line number Original line Diff line number Diff line
@@ -77,6 +77,82 @@ DrawSheetStruct::~DrawSheetStruct()
}
}





/**********************************************/
bool DrawSheetStruct::Save( FILE *f )
/***********************************************/
/* Routine utilisee dans la routine precedente.
    Assure la sauvegarde de la structure LibItemStruct
*/
{
int ii;
bool Failed = FALSE;
DrawSheetLabelStruct * SheetLabel;

    fprintf(f, "$Sheet\n");

    if (fprintf(f, "S %-4d %-4d %-4d %-4d\n",
                    m_Pos.x,m_Pos.y,
                    m_Size.x,m_Size.y) == EOF){
        Failed = TRUE; return(Failed);
    }

    //save the unique timestamp, like other shematic parts.
    if( fprintf(f, "U %8.8lX\n", m_TimeStamp)  == EOF ){
        Failed = TRUE; return(Failed);
    }

    /* Generation de la liste des 2 textes (sheetname et filename) */
    if ( ! m_SheetName.IsEmpty())
    {
        if(fprintf(f,"F0 \"%s\" %d\n", CONV_TO_UTF8(m_SheetName), m_SheetNameSize) == EOF)
        {
            Failed = TRUE; return(Failed);
        }
    }

    if( ! GetFileName().IsEmpty())
    {
        if(fprintf(f,"F1 \"%s\" %d\n", CONV_TO_UTF8(GetFileName()), m_FileNameSize) == EOF)
        {
            Failed = TRUE; return(Failed);
        }
    }

    /* Generation de la liste des labels (entrees) de la sous feuille */
    ii = 2;
    SheetLabel = m_Label;
    while( SheetLabel != NULL )
    {
        int type = 'U', side = 'L';

        if( SheetLabel->m_Text.IsEmpty() ) continue;
        if( SheetLabel->m_Edge ) side = 'R';

        switch(SheetLabel->m_Shape)
        {
            case NET_INPUT: type = 'I'; break;
            case NET_OUTPUT: type = 'O'; break;
            case NET_BIDI: type = 'B'; break;
            case NET_TRISTATE: type = 'T'; break;
            case NET_UNSPECIFIED: type = 'U'; break;
        }

        if(fprintf(f,"F%d \"%s\" %c %c %-3d %-3d %-3d\n", ii,
            CONV_TO_UTF8(SheetLabel->m_Text), type, side,
            SheetLabel->m_Pos.x, SheetLabel->m_Pos.y,
            SheetLabel->m_Size.x) == EOF)
        {
            Failed = TRUE; break;
        }
        ii++;
        SheetLabel = (DrawSheetLabelStruct*)SheetLabel->Pnext;
    }

    fprintf(f, "$EndSheet\n");
    return(Failed);
}

/***********************************************/
/***********************************************/
DrawSheetStruct* DrawSheetStruct::GenCopy()
DrawSheetStruct* DrawSheetStruct::GenCopy()
/***********************************************/
/***********************************************/
+195 −0
Original line number Original line Diff line number Diff line
/********************************************/
/* Definitions for the EESchema program:	*/
/********************************************/

#ifndef CLASS_DRAWSHEET_H
#define CLASS_DRAWSHEET_H

#ifndef eda_global
#define eda_global extern
#endif

#include "base_struct.h"

extern DrawSheetStruct* g_RootSheet;


class DrawSheetLabelStruct : public EDA_BaseStruct,
    public EDA_TextStruct
{
public:
    int  m_Layer;
    int  m_Edge, m_Shape;
    bool m_IsDangling;  // TRUE non connected

public:
    DrawSheetLabelStruct( DrawSheetStruct* parent,
                          const wxPoint& pos = wxPoint( 0, 0 ),
                          const wxString& text = wxEmptyString );

    ~DrawSheetLabelStruct() { }
    virtual wxString GetClass() const
    {
        return wxT( "DrawSheetLabelStruct" );
    }


    DrawSheetLabelStruct*   GenCopy();

    DrawSheetLabelStruct* Next()
    { return (DrawSheetLabelStruct*) Pnext; }

    void                    Place( WinEDA_DrawFrame* frame, wxDC* DC );
    virtual void            Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
                                  int draw_mode, int Color = -1 );
};


/* class DrawSheetStruct
  * This class is the sheet symbol placed in a schematic, and is the entry point for a sub schematic
 */
WX_DEFINE_ARRAY( DrawSheetStruct *, SheetGrowArray );

class DrawSheetStruct : public EDA_BaseStruct /*public SCH_SCREEN*/    /* Gestion de la hierarchie */
{
public:
    wxString              m_SheetName;  //this is equivalent to C101 for components:
    // it is stored in F0 ... of the file.
private:
    wxString              m_FileName;   //also in SCH_SCREEN (redundant),
                                        //but need it here for loading after
                                        //reading the sheet description from file.
public:
    int                   m_SheetNameSize;	// Size (height) of the text, used to draw the name

    int                   m_FileNameSize;	// Size (height) of the text, used to draw the name
    wxPoint               m_Pos;
    wxSize                m_Size;           /* Position and Size of sheet symbol */
    int                   m_Layer;
    DrawSheetLabelStruct* m_Label;          /* Points de connection, linked list.*/
    int                   m_NbLabel;        /* Nombre de points de connexion */
    SCH_SCREEN*           m_AssociatedScreen;   /* Associated Screen which handle the physical data
                                                  * In complex hierarchies we can have many DrawSheetStruct using the same data
                                                 */
    int                   m_SheetNumber;    // sheet number (used for info)
    int                   m_NumberOfSheets; // Sheets count in the whole schematic (used for info)

public:
    DrawSheetStruct( const wxPoint& pos = wxPoint( 0, 0 ) );
    ~DrawSheetStruct();
    virtual wxString GetClass() const
    {
        return wxT( "DrawSheetStruct" );
    }

    /** Function Save
     * Write on file a DrawSheetStruct description
     * @param f = output file
     * return an error: false if ok, true if error
    */
    bool Save( FILE *f );

    void                Place( WinEDA_DrawFrame* frame, wxDC* DC );
    DrawSheetStruct*    GenCopy();
    void                Display_Infos( WinEDA_DrawFrame* frame );
    void                CleanupSheet( WinEDA_SchematicFrame* frame, wxDC* DC );
    virtual void        Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
                              int draw_mode, int Color = -1 );
    EDA_Rect            GetBoundingBox();
    void                SwapData( DrawSheetStruct* copyitem );
    void                DeleteAnnotation( bool recurse );
    int                 ComponentCount();
    bool                Load( WinEDA_SchematicFrame* frame );
    bool                SearchHierarchy( wxString filename, SCH_SCREEN** screen );
    bool                LocatePathOfScreen( SCH_SCREEN* screen, DrawSheetPath* list );
    int                 CountSheets();
    wxString            GetFileName(void);
    void                SetFileName(const wxString & aFilename); // Set a new filename without changing anything else
    bool                ChangeFileName(WinEDA_SchematicFrame * aFrame, const wxString & aFileName); // Set a new filename and manage data and associated screen

    //void 		RemoveSheet(DrawSheetStruct* sheet);
    //to remove a sheet, just delete it
    //-- the destructor should take care of everything else.
};


/**********************************************/
/* class to handle a series of sheets *********/
/* a 'path' so to speak.. *********************/
/**********************************************/
#define DSLSZ 32
class DrawSheetPath
{
public:
    int m_numSheets;
    DrawSheetStruct* m_sheets[DSLSZ];

    DrawSheetPath();
    ~DrawSheetPath() { };
    void                Clear() { m_numSheets = 0; }
    int                 Cmp( DrawSheetPath& d );
    DrawSheetStruct*    Last();
    SCH_SCREEN*         LastScreen();
    EDA_BaseStruct*     LastDrawList();
    void                Push( DrawSheetStruct* sheet );
    DrawSheetStruct*    Pop();
    wxString            Path();
    wxString            PathHumanReadable();
    void                UpdateAllScreenReferences();

    bool operator       =( const DrawSheetPath& d1 );

    bool operator       ==( const DrawSheetPath& d1 );

    bool operator       !=( const DrawSheetPath& d1 );
};


/*******************************************************/
/* Class to handle the list of *Sheets* in a hierarchy */
/*******************************************************/

// sheets are not unique - can have many sheets with the same
// filename and the same SCH_SCREEN reference.
class EDA_SheetList
{
private:
    DrawSheetPath* m_List;
    int            m_count;     /* Number of sheets included in hierarchy,
                                  * starting at the given sheet in constructor . the given sheet is counted
                                 */
    int            m_index;
    DrawSheetPath  m_currList;

public:
    EDA_SheetList( DrawSheetStruct* sheet )
    {
        m_index = 0;
        m_count = 0;
        m_List  = NULL;
        if( sheet == NULL )
            sheet = g_RootSheet;
        BuildSheetList( sheet );
    }


    ~EDA_SheetList()
    {
        if( m_List )
        {
            free( m_List );
        }
        m_List = NULL;
    }


    int GetCount() { return m_count; }
    DrawSheetPath*  GetFirst();
    DrawSheetPath*  GetNext();
    DrawSheetPath*  GetSheet( int index );

private:
    void            BuildSheetList( DrawSheetStruct* sheet );
};

#endif /* CLASS_DRAWSHEET_H */
Loading