Commit 0d57d670 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Add user write permission tests to PCBNew and other minor fixes.

* Check user write permissions before saving project, board, and footprint
  library files.
* Append read only to file name and path in title bar when the user
  does not have write privileges.
* Rename class WinEDA_ModuleEditFrame to FOOTPRINT_EDIT_FRAME.
* Lot's of Doxygen comment and coding style policy fixes.
parent 5fd409f8
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
/*  Forward declarations of classes. */
class WinEDA_CvpcbFrame;
class PCB_EDIT_FRAME;
class WinEDA_ModuleEditFrame;
class FOOTPRINT_EDIT_FRAME;
class BOARD;
class TEXTE_PCB;
class MODULE;
@@ -61,7 +61,7 @@ public:
    wxRealPoint             m_UserGridSize;

    EDA_3D_FRAME*           m_Draw3DFrame;
    WinEDA_ModuleEditFrame* m_ModuleEditFrame;
    FOOTPRINT_EDIT_FRAME*   m_ModuleEditFrame;

protected:
    BOARD*                  m_Pcb;
@@ -172,7 +172,6 @@ public:
     */
    GENERAL_COLLECTORS_GUIDE GetCollectorsGuide();


    /**
     * Function CursorGoto
     * positions the cursor at a given coordinate and reframes the drawing if
@@ -182,7 +181,6 @@ public:
     */
    void                     CursorGoto(  const wxPoint& aPos );


    void                     place_marqueur( wxDC*          DC,
                                             const wxPoint& pos,
                                             char*          pt_bitmap,
@@ -208,8 +206,14 @@ public:
                                    bool            aOverwrite,
                                    bool            aDisplayDialog );

    void    Archive_Modules( const wxString& LibName,
                             bool            NewModulesOnly );
    /**
     * Function Archive_Modules
     * Save in the library:
     * All new modules (ie modules not found in this lib) (if NewModulesOnly == true)
     * all modules (if NewModulesOnly == false)
     */
    void Archive_Modules( const wxString& LibName, bool NewModulesOnly );

    MODULE* GetModuleByName();

    /**
@@ -276,15 +280,17 @@ public:
                                              wxDC*         DC );

    void          AddPad( MODULE* Module, bool draw );

    /**
     * Function DeletePad
     * Delete the pad aPad.
     * Refresh the modified screen area
     * Refresh modified parameters of the parent module (bounding box, last date)
     * @param aPad = the pad to delete
     * @param aQuery = true to promt for confirmation, false to delete silently
     * @param aQuery = true to prompt for confirmation, false to delete silently
     */
    void          DeletePad( D_PAD* aPad, bool aQuery = true );

    void          StartMovePad( D_PAD* Pad, wxDC* DC );
    void          RotatePad( D_PAD* Pad, wxDC* DC );
    void          PlacePad( D_PAD* Pad, wxDC* DC );
+54 −17
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@

/*  Forward declarations of classes. */
class PCB_SCREEN;
class WinEDA_ModuleEditFrame;
class BOARD;
class TEXTE_PCB;
class MODULE;
@@ -141,6 +140,10 @@ public:
     */
    void             ToPrinter( wxCommandEvent& event );

    /**
     * Function SVG_Print
     * shows the print SVG file dialog.
     */
    void             SVG_Print( wxCommandEvent& event );

    // User interface update command event handlers.
@@ -341,11 +344,12 @@ public:
    void             ReCreateMenuBar();
    LAYER_BOX_SELECTOR* ReCreateLayerBox( EDA_TOOLBAR* parent );

    /** Virtual Function OnModify()
     * Must be called after a board change
     * in order to set the "modify" flag of the current screen
     * and prepare, if needed the refresh of the 3D frame showing the footprint
     * do not forget to call the basic OnModify function to update auxiliary info
    /**
     * Function OnModify
     * must be called after a board change to set the modified flag.
     * <p>
     * Reloads the 3D view if required and calls the base PCB_BASE_FRAME::OnModify function
     * to update auxiliary information.
     */
    virtual void OnModify();

@@ -384,12 +388,16 @@ public:
     */
    void             ReFillLayerWidget();

    /**
     * Function Show3D_Frame
     * displays the 3D view of current printed circuit board.
     */
    void             Show3D_Frame( wxCommandEvent& event );
    void             GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );

    /**
     * Function ShowDesignRulesEditor
     * Display the Design Rules Editor.
     * displays the Design Rules Editor.
     */
    void             ShowDesignRulesEditor( wxCommandEvent& event );

@@ -567,11 +575,16 @@ public:
    void ToPostProcess( wxCommandEvent& event );

    void OnFileHistory( wxCommandEvent& event );

    /**
     * Function Files_io
     * is the command event handler for read and write file commands.
     */
    void Files_io( wxCommandEvent& event );

    /**
     * Function LoadOnePcbFile
     *  Load a Kicad board (.brd) file.
     * loads a Kicad board (.brd) from \a aFileName.
     *
     *  @param aFileName - File name including path. If empty, a file dialog will
     *                     be displayed.
@@ -595,7 +608,16 @@ public:
     */
    int  ReadPcbFile( LINE_READER* aReader, bool Append );

    bool SavePcbFile( const wxString& FileName );
    /**
     * Function SavePcbFile
     * writes the board data structures to \a a aFileName
     *
     * @param aFileName The file name to write or wxEmptyString to prompt user for
     *                  file name.
     * @return True if file was saved successfully.
     */
    bool SavePcbFile( const wxString& aFileName );

    int  SavePcbFormatAscii( FILE* File );
    bool WriteGeneralDescrPcb( FILE* File );

@@ -643,7 +665,7 @@ public:
     * @param aFullFileName = the full filename of the file to create
     * @param aScale = the general scaling factor. 1.0 to export in inches
     * @param aExport3DFiles = true to copy 3D shapes in the subir a3D_Subdir
     * @param a3D_Subdir = sub directory where 3D sahpes files are copied
     * @param a3D_Subdir = sub directory where 3D shapes files are copied
     * used only when aExport3DFiles == true
     * @return true if Ok.
     */
@@ -761,11 +783,15 @@ public:
    // Track and via edition:
    void   Via_Edit_Control( wxCommandEvent& event );

    /* Return true if a microvia can be put on board
    /**
     * Function IsMicroViaAcceptable
     * return true if a microvia can be placed on the board.
     * <p>
     * A microvia is a small via restricted to 2 near neighbor layers
     * because its is hole is made by laser which can penetrate only one layer
     * It is mainly used to connect BGA to the first inner layer
     * And it is allowed from an external layer to the first inner layer
     * </p>
     */
    bool IsMicroViaAcceptable( void );

@@ -1158,6 +1184,17 @@ public:
     */
    virtual void SetLanguage( wxCommandEvent& event );

    /**
     * Function UpdateTitle
     * sets the main window title bar text.
     * <p>
     * If file name defined by PCB_SCREEN::m_FileName is not set, the title is set to the
     * application name appended with no file.  Otherwise, the title is set to the full path
     * and file name and read only is appended to the title if the user does not have write
     * access to the file.
     */
    void UpdateTitle();

    DECLARE_EVENT_TABLE()
};

+40 −34
Original line number Diff line number Diff line
@@ -36,11 +36,7 @@ static void RotateMarkedItems( MODULE* module, wxPoint offset );
static void DeleteMarkedItems( MODULE* module );


/* Return the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to
 * the key (ALT, SHIFT ALT ..) pressed when dragging mouse and left or
 * middle button pressed
 */
int WinEDA_ModuleEditFrame::ReturnBlockCommand( int key )
int FOOTPRINT_EDIT_FRAME::ReturnBlockCommand( int key )
{
    int cmd;

@@ -83,17 +79,7 @@ int WinEDA_ModuleEditFrame::ReturnBlockCommand( int key )
}


/**
 * Function HandleBlockEnd( )
 * Handle the "end"  of a block command,
 * i.e. is called at the end of the definition of the area of a block.
 * depending on the current block command, this command is executed
 * or parameters are initialized to prepare a call to HandleBlockPlace
 * in GetScreen()->m_BlockLocate
 * @return false if no item selected, or command finished,
 * true if some items found and HandleBlockPlace must be called later
 */
bool WinEDA_ModuleEditFrame::HandleBlockEnd( wxDC* DC )
bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC )
{
    int  itemsCount    = 0;
    bool nextcmd = false;
@@ -121,8 +107,8 @@ bool WinEDA_ModuleEditFrame::HandleBlockEnd( wxDC* DC )
    case BLOCK_DRAG:        /* Drag */
    case BLOCK_MOVE:        /* Move */
    case BLOCK_COPY:        /* Copy */
        itemsCount = MarkItemsInBloc( currentModule,
                                      GetScreen()->m_BlockLocate );
        itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );

        if( itemsCount )
        {
            nextcmd = true;
@@ -147,8 +133,10 @@ bool WinEDA_ModuleEditFrame::HandleBlockEnd( wxDC* DC )

    case BLOCK_DELETE:     /* Delete */
        itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );

        if( itemsCount )
            SaveCopyInUndoList( currentModule, UR_MODEDIT );

        DeleteMarkedItems( currentModule );
        break;

@@ -158,8 +146,10 @@ bool WinEDA_ModuleEditFrame::HandleBlockEnd( wxDC* DC )

    case BLOCK_ROTATE:
        itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );

        if( itemsCount )
            SaveCopyInUndoList( currentModule, UR_MODEDIT );

        RotateMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
        break;

@@ -168,8 +158,10 @@ bool WinEDA_ModuleEditFrame::HandleBlockEnd( wxDC* DC )
    case BLOCK_MIRROR_Y:
    case BLOCK_FLIP:     /* mirror */
        itemsCount = MarkItemsInBloc( currentModule, GetScreen()->m_BlockLocate );

        if( itemsCount )
            SaveCopyInUndoList( currentModule, UR_MODEDIT );

        MirrorMarkedItems( currentModule, GetScreen()->m_BlockLocate.Centre() );
        break;

@@ -202,15 +194,7 @@ bool WinEDA_ModuleEditFrame::HandleBlockEnd( wxDC* DC )
}


/******************************************************/
void WinEDA_ModuleEditFrame::HandleBlockPlace( wxDC* DC )
/******************************************************/

/* Routine to handle the BLOCK PLACE command
 *  Last routine for block operation for:
 *  - block move & drag
 *  - block copy & paste
 */
void FOOTPRINT_EDIT_FRAME::HandleBlockPlace( wxDC* DC )
{
    MODULE* currentModule = GetBoard()->m_Modules;

@@ -326,6 +310,7 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx
            {
                if( pad->m_Selected == 0 )
                    continue;

                pad->Draw( aPanel, aDC, g_XorMode, move_offset );
            }
        }
@@ -434,15 +419,18 @@ void MoveMarkedItems( MODULE* module, wxPoint offset )
        return;

    D_PAD* pad = module->m_Pads;

    for( ; pad != NULL; pad = pad->Next() )
    {
        if( pad->m_Selected == 0 )
            continue;

        pad->SetPosition( pad->GetPosition() + offset );
        pad->m_Pos0 += offset;
    }

    item = module->m_Drawings;

    for( ; item != NULL; item = item->Next() )
    {
        if( item->m_Selected == 0 )
@@ -485,20 +473,26 @@ void DeleteMarkedItems( MODULE* module )
        return;

    pad = module->m_Pads;

    for( ; pad != NULL; pad = next_pad )
    {
        next_pad = pad->Next();

        if( pad->m_Selected == 0 )
            continue;

        pad->DeleteStructure();
    }

    item = module->m_Drawings;

    for( ; item != NULL; item = next_item )
    {
        next_item = item->Next();

        if( item->m_Selected == 0 )
            continue;

        item->DeleteStructure();
    }
}
@@ -515,10 +509,12 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset )
        return;

    D_PAD* pad = module->m_Pads;

    for( ; pad != NULL; pad = pad->Next() )
    {
        if( pad->m_Selected == 0 )
            continue;

        SETMIRROR( pad->GetPosition().x );
        pad->m_Pos0.x = pad->GetPosition().x;
        NEGATE( pad->m_Offset.x );
@@ -528,6 +524,7 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset )
    }

    item = module->m_Drawings;

    for( ; item != NULL; item = item->Next() )
    {
        if( item->m_Selected == 0 )
@@ -536,7 +533,8 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset )
        switch( item->Type() )
        {
        case TYPE_EDGE_MODULE:
        {  EDGE_MODULE * edge =  (EDGE_MODULE*) item;
        {
            EDGE_MODULE * edge =  (EDGE_MODULE*) item;
            SETMIRROR( edge->m_Start.x );
            edge->m_Start0.x = edge->m_Start.x;
            SETMIRROR( edge->m_End.x );
@@ -547,8 +545,7 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset )

        case TYPE_TEXTE_MODULE:
            SETMIRROR( ( (TEXTE_MODULE*) item )->GetPosition().x );
            ( (TEXTE_MODULE*) item )->m_Pos0.x =
                ( (TEXTE_MODULE*) item )->GetPosition().x;
            ( (TEXTE_MODULE*) item )->m_Pos0.x = ( (TEXTE_MODULE*) item )->GetPosition().x;
            break;

        default:
@@ -572,10 +569,12 @@ void RotateMarkedItems( MODULE* module, wxPoint offset )
        return;

    D_PAD* pad = module->m_Pads;

    for( ; pad != NULL; pad = pad->Next() )
    {
        if( pad->m_Selected == 0 )
            continue;

        ROTATE( pad->GetPosition() );
        pad->m_Pos0    = pad->GetPosition();
        pad->m_Orient += 900;
@@ -583,6 +582,7 @@ void RotateMarkedItems( MODULE* module, wxPoint offset )
    }

    item = module->m_Drawings;

    for( ; item != NULL; item = item->Next() )
    {
        if( item->m_Selected == 0 )
@@ -592,16 +592,14 @@ void RotateMarkedItems( MODULE* module, wxPoint offset )
        {
        case TYPE_EDGE_MODULE:
            ROTATE( ( (EDGE_MODULE*) item )->m_Start );
            ( (EDGE_MODULE*) item )->m_Start0 =
                ( (EDGE_MODULE*) item )->m_Start;
            ( (EDGE_MODULE*) item )->m_Start0 = ( (EDGE_MODULE*) item )->m_Start;
            ROTATE( ( (EDGE_MODULE*) item )->m_End );
            ( (EDGE_MODULE*) item )->m_End0 = ( (EDGE_MODULE*) item )->m_End;
            break;

        case TYPE_TEXTE_MODULE:
            ROTATE( ( (TEXTE_MODULE*) item )->GetPosition() );
            ( (TEXTE_MODULE*) item )->m_Pos0 =
                ( (TEXTE_MODULE*) item )->GetPosition();
            ( (TEXTE_MODULE*) item )->m_Pos0 = ( (TEXTE_MODULE*) item )->GetPosition();
            ( (TEXTE_MODULE*) item )->m_Orient += 900;
            break;

@@ -622,10 +620,12 @@ void ClearMarkItems( MODULE* module )
        return;

    item = module->m_Drawings;

    for( ; item != NULL; item = item->Next() )
        item->m_Flags = item->m_Selected = 0;

    item = module->m_Pads;

    for( ; item != NULL; item = item->Next() )
        item->m_Flags = item->m_Selected = 0;
}
@@ -645,10 +645,12 @@ int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect )
        return 0;

    pad = module->m_Pads;

    for( ; pad != NULL; pad = pad->Next() )
    {
        pad->m_Selected = 0;
        pos = pad->GetPosition();

        if( Rect.Contains( pos ) )
        {
            pad->m_Selected = IS_SELECTED;
@@ -657,6 +659,7 @@ int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect )
    }

    item = module->m_Drawings;

    for( ; item != NULL; item = item->Next() )
    {
        item->m_Selected = 0;
@@ -669,15 +672,18 @@ int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect )
                item->m_Selected = IS_SELECTED;
                ItemsCount++;
            }

            break;

        case TYPE_TEXTE_MODULE:
            pos = ( (TEXTE_MODULE*) item )->GetPosition();

            if( Rect.Contains( pos ) )
            {
                item->m_Selected = IS_SELECTED;
                ItemsCount++;
            }

            break;

        default:
+24 −38
Original line number Diff line number Diff line
@@ -24,22 +24,19 @@

FOOTPRINT_LIBRARY::FOOTPRINT_LIBRARY( FILE * aFile, FILTER_READER * aReader )
{
    wxASSERT( m_reader || m_file );
    wxASSERT( aFile != NULL );

    m_file = aFile;
    m_reader = aReader;
    m_LineNum = 0;
}

/* function IsLibrary
 * Read the library file Header
 * return > 0 if this file is a footprint lib
 * (currentlu return 1 but could be a value > 1 for future file formats
 */

int FOOTPRINT_LIBRARY::IsLibrary( )
{
    char *line;
    char buffer[1024];

    if( m_reader )
    {
        m_reader->ReadLine();
@@ -52,6 +49,7 @@ int FOOTPRINT_LIBRARY::IsLibrary( )
    }

    StrPurge( line );

    if( strnicmp( line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) == 0 )
        return 1;

@@ -59,11 +57,6 @@ int FOOTPRINT_LIBRARY::IsLibrary( )
}


/*
 * function RebuildIndex
 * Read the full library file and build the list od footprints found
 * and do not use the $INDEX ... $EndINDEX section
 */
bool FOOTPRINT_LIBRARY::RebuildIndex()
{
    m_List.Clear();
@@ -76,6 +69,7 @@ bool FOOTPRINT_LIBRARY::RebuildIndex()
        {
            char * line = m_reader->Line();
            StrPurge( line );

            if( strnicmp( line, "$MODULE", 7 ) == 0 )
            {
                sscanf( line + 7, " %s", name );
@@ -86,6 +80,7 @@ bool FOOTPRINT_LIBRARY::RebuildIndex()
    else
    {
        char line[1024];

        while( GetLine( m_file, line, &m_LineNum ) )
        {
            if( strnicmp( line, "$MODULE", 7 ) == 0 )
@@ -99,29 +94,30 @@ bool FOOTPRINT_LIBRARY::RebuildIndex()
    return true;
}

/* function ReadSectionIndex
 * Read the $INDEX ... $EndINDEX section
 * list of footprints is stored in m_List
 */

bool FOOTPRINT_LIBRARY::ReadSectionIndex()
{
    // Some broken INDEX sections have more than one section
    // So we must read the next line after $EndINDEX tag,
    // to see if this is not a new $INDEX tag.
    bool exit = false;

    if( m_reader )
    {
        while( m_reader->ReadLine() )
        {
            char * line = m_reader->Line();
            StrPurge( line );

            if( strnicmp( line, "$INDEX", 6 ) == 0 )
            {
                exit = false;

                while( m_reader->ReadLine() )
                {
                    StrPurge( line );
                    m_List.Add( FROM_UTF8( line ) );

                    if( strnicmp( line, "$EndINDEX", 9 ) == 0 )
                    {
                        exit = true;
@@ -136,15 +132,18 @@ bool FOOTPRINT_LIBRARY::ReadSectionIndex()
    else
    {
        char line[1024];

        while( GetLine( m_file, line, &m_LineNum ) )
        {
            if( strnicmp( line, "$INDEX", 6 ) == 0 )
            {
                exit = false;

                while( GetLine( m_file, line, &m_LineNum ) )
                {
                    StrPurge( line );
                    m_List.Add( FROM_UTF8( line ) );

                    if( strnicmp( line, "$EndINDEX", 9 ) == 0 )
                    {
                        exit = true;
@@ -153,16 +152,16 @@ bool FOOTPRINT_LIBRARY::ReadSectionIndex()
                }
            }
            else if( exit )
            {
                break;
            }
        }
    }

    return true;
}

/* Function WriteHeader
 * Write the library header
 */

bool FOOTPRINT_LIBRARY::WriteHeader()
{
    char line[256];
@@ -171,34 +170,28 @@ bool FOOTPRINT_LIBRARY::WriteHeader()
    return true;
}

/* Function WriteSectionIndex
 * Write the $INDEX ... $EndINDEX section.
 * This section is filled by names in m_List
 */

bool FOOTPRINT_LIBRARY::WriteSectionIndex()
{
    fputs( "$INDEX\n", m_file );

    for( unsigned ii = 0; ii < m_List.GetCount(); ii++ )
    {
        fprintf( m_file, "%s\n", TO_UTF8( m_List[ii] ) );
    }

    fputs( "$EndINDEX\n", m_file );
    return true;
}

/* Function WriteEndOfFile
 * Write the last line section.
 */

bool FOOTPRINT_LIBRARY::WriteEndOfFile()
{
    fputs( "$EndLIBRARY\n", m_file );
    return true;
}

/*
 * Function FindInList
 * Search for aName int m_List and return true if found
 */

bool FOOTPRINT_LIBRARY::FindInList( const wxString & aName )
{
    for( unsigned ii = 0; ii < m_List.GetCount(); ii++ )
@@ -210,11 +203,7 @@ bool FOOTPRINT_LIBRARY::FindInList( const wxString & aName )
    return false;
}

/**
 * Function RemoveFromList
 * Search for aName int m_List and remove it
 * @return true if found and removed
 */

bool FOOTPRINT_LIBRARY::RemoveFromList( const wxString & aName )
{
    for( unsigned ii = 0; ii < m_List.GetCount(); ii++ )
@@ -229,10 +218,7 @@ bool FOOTPRINT_LIBRARY::RemoveFromList( const wxString & aName )
    return false;
}

/**
 * Function SortList
 * Sort m_List in alphabetic order
 */

void FOOTPRINT_LIBRARY::SortList()
{
    m_List.Sort();
+3 −3
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ public:
    int m_LineNum;              // the line count

private:
    FILTER_READER * m_reader;   // FILTER_READER to read file. id NULL, use m_file
    FILTER_READER * m_reader;   // FILTER_READER to read file. If NULL, use m_file
    FILE * m_file;              // footprint file to read/write.

public:
@@ -23,7 +23,7 @@ public:
     * @param aFile = a FILE * pointer used for write operations,
     * and read operations when aReader = NULL
     * @param aReader = a FILTER_READER pointer used for read operations
     * If NULL, a direct aFILE read is used
     * If NULL, a direct aFile read is used
     */
    FOOTPRINT_LIBRARY( FILE * aFile, FILTER_READER * aReader = NULL );

@@ -39,7 +39,7 @@ public:

    /**
     * function RebuildIndex
     * Read the full library file and build the list od footprints found
     * Read the full library file and build the list of footprints found
     * Do not use the $INDEX ... $EndINDEX section
     */
    bool RebuildIndex();
Loading