Commit bbda48f9 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Unify Eeschema orient commands and other minor fixes.

* Create command event handler for orienting schematic items and block.
* Remove redundant orient item and block command handler code and IDs.
* Remove redundant cancel current command event table entry.
* Remove unnecessary schematic bitmap object virtual functions.
* Set path when saving schematic sheet files to prevent assertion in
  updated path and file write permission test function.
* Restore directory and file name write permission test function to it's
  previous behavior to prevent unexpected save results.
* Add an assertion to verify the path is not empty to directory and file
  write permission test function.
* Improve documentation for path and file write permission test function.
* Fix Doxygen link warnings.
parent a834c47b
Loading
Loading
Loading
Loading
+8 −12
Original line number Original line Diff line number Diff line
@@ -543,25 +543,21 @@ bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName )
{
{
    wxString msg;
    wxString msg;


    wxCHECK_MSG( aFileName.IsOk(), false, wxT( "Invalid file name object.  Bad programmer!" ) );
    wxCHECK_MSG( aFileName.IsOk(), false,
                 wxT( "File name object is invalid.  Bad programmer!" ) );
    wxCHECK_MSG( !aFileName.GetPath().IsEmpty(), false,
                 wxT( "File name object path <" ) + aFileName.GetFullPath() +
                 wxT( "> is not set.  Bad programmer!" ) );


    if( aFileName.IsDir() && !aFileName.IsDirWritable() )
    if( aFileName.IsDir() && !aFileName.IsDirWritable() )
    {
    {
        msg.Printf( _( "You do not have write permissions to folder <%s>." ),
        msg.Printf( _( "You do not have write permissions to folder <%s>." ),
                    GetChars( aFileName.GetPath() ) );
                    GetChars( aFileName.GetPath() ) );
    }
    }
    else if( !aFileName.FileExists() )
    else if( !aFileName.FileExists() && !aFileName.IsDirWritable() )
    {
        // Extract filename path, and if void, uses the CWD
        // because IsDirWritable does not like void path
        wxString filedir = aFileName.GetPath();
        if( filedir.IsEmpty() )
            filedir = wxGetCwd();
        if( !aFileName.IsDirWritable(filedir) )
    {
    {
        msg.Printf( _( "You do not have write permissions to save file <%s> to folder <%s>." ),
        msg.Printf( _( "You do not have write permissions to save file <%s> to folder <%s>." ),
                        GetChars( aFileName.GetFullName() ), GetChars( filedir ) );
                    GetChars( aFileName.GetFullName() ), GetChars( aFileName.GetPath() ) );
        }
    }
    }
    else if( aFileName.FileExists() && !aFileName.IsFileWritable() )
    else if( aFileName.FileExists() && !aFileName.IsFileWritable() )
    {
    {
+8 −12
Original line number Original line Diff line number Diff line
@@ -117,9 +117,6 @@ enum id_eeschema_frm
    ID_POPUP_SCH_ADD_LABEL,
    ID_POPUP_SCH_ADD_LABEL,
    ID_POPUP_SCH_ADD_GLABEL,
    ID_POPUP_SCH_ADD_GLABEL,
    ID_POPUP_SCH_GETINFO_MARKER,
    ID_POPUP_SCH_GETINFO_MARKER,
    // Edit or change image orientation or context menu command IDs.
    ID_POPUP_SCH_MIRROR_X_IMAGE,
    ID_POPUP_SCH_MIRROR_Y_IMAGE,
    ID_POPUP_END_RANGE,
    ID_POPUP_END_RANGE,


    ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP,
    ID_POPUP_SCH_CALL_LIBEDIT_AND_LOAD_CMP,
@@ -160,22 +157,21 @@ enum id_eeschema_frm
    ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
    ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
    ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
    ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,


    // Change component orientation context menu command IDs.
    ID_POPUP_SCH_MIRROR_X_CMP,
    ID_POPUP_SCH_MIRROR_Y_CMP,
    ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE,
    ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE,
    ID_POPUP_SCH_ORIENT_NORMAL_CMP,

    ID_SELECT_ITEM_START,
    ID_SELECT_ITEM_START,
    ID_SELECT_ITEM_END = ID_SELECT_ITEM_START + MAX_SELECT_ITEM_IDS,
    ID_SELECT_ITEM_END = ID_SELECT_ITEM_START + MAX_SELECT_ITEM_IDS,


    ID_SCH_ROTATE_ITEM,
    // Change orientation command IDs.
    ID_SCH_MIRROR_X,
    ID_SCH_MIRROR_Y,
    ID_SCH_ORIENT_NORMAL,

    ID_SCH_ROTATE_CLOCKWISE,
    ID_SCH_ROTATE_COUNTERCLOCKWISE,
    ID_SCH_EDIT_ITEM,
    ID_SCH_EDIT_ITEM,
    ID_SCH_EDIT_COMPONENT_VALUE,
    ID_SCH_EDIT_COMPONENT_VALUE,
    ID_SCH_EDIT_COMPONENT_REFERENCE,
    ID_SCH_EDIT_COMPONENT_REFERENCE,
    ID_SCH_EDIT_COMPONENT_FOOTPRINT,
    ID_SCH_EDIT_COMPONENT_FOOTPRINT,
    ID_POPUP_SCH_MOVE_ITEM,
    ID_SCH_MOVE_ITEM,
    ID_SCH_DRAG_ITEM,
    ID_SCH_DRAG_ITEM,


    // Schematic editor commmands.  These are command IDs that are generated by multiple
    // Schematic editor commmands.  These are command IDs that are generated by multiple
+6 −1
Original line number Original line Diff line number Diff line
@@ -59,6 +59,11 @@ bool SCH_EDIT_FRAME::SaveEEFile( SCH_SCREEN* aScreen, int aSaveType, bool aCreat
    case FILE_SAVE_AS:
    case FILE_SAVE_AS:
        schematicFileName = aScreen->GetFileName();
        schematicFileName = aScreen->GetFileName();


        // Sheet file names are relative to the root sheet path which is the current
        // working directory.  The IsWritable funtion expects the path to be set.
        if( schematicFileName.GetPath().IsEmpty() )
            schematicFileName.Assign( wxFileName::GetCwd(), schematicFileName.GetFullName() );

        if( aCreateBackupFile )
        if( aCreateBackupFile )
        {
        {
            backupFileName = schematicFileName;
            backupFileName = schematicFileName;
+2 −27
Original line number Original line Diff line number Diff line
@@ -242,7 +242,7 @@ SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
/*
/*
 * Routine to rotate and mirror a component.
 * Routine to rotate and mirror a component.
 */
 */
void SCH_EDIT_FRAME::OnChangeComponentOrientation( wxCommandEvent& aEvent )
void SCH_EDIT_FRAME::OrientComponent( COMPONENT_ORIENTATION_T aOrientation )
{
{
    SCH_SCREEN* screen = GetScreen();
    SCH_SCREEN* screen = GetScreen();
    SCH_ITEM* item = screen->GetCurItem();
    SCH_ITEM* item = screen->GetCurItem();
@@ -252,31 +252,6 @@ void SCH_EDIT_FRAME::OnChangeComponentOrientation( wxCommandEvent& aEvent )


    SCH_COMPONENT* component = (SCH_COMPONENT*) item;
    SCH_COMPONENT* component = (SCH_COMPONENT*) item;


    int orientation;

    switch( aEvent.GetId() )
    {
    case ID_POPUP_SCH_MIRROR_X_CMP:
        orientation = CMP_MIRROR_X;
        break;

    case ID_POPUP_SCH_MIRROR_Y_CMP:
        orientation = CMP_MIRROR_Y;
        break;

    case ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE:
        orientation = CMP_ROTATE_COUNTERCLOCKWISE;
        break;

    case ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE:
        orientation = CMP_ROTATE_CLOCKWISE;
        break;

    case ID_POPUP_SCH_ORIENT_NORMAL_CMP:
    default:
        orientation = CMP_NORMAL;
    }

    DrawPanel->MoveCursorToCrossHair();
    DrawPanel->MoveCursorToCrossHair();


    if( component->GetFlags() == 0 )
    if( component->GetFlags() == 0 )
@@ -296,7 +271,7 @@ void SCH_EDIT_FRAME::OnChangeComponentOrientation( wxCommandEvent& aEvent )
    else
    else
        DrawPanel->RefreshDrawingRect( component->GetBoundingBox() );
        DrawPanel->RefreshDrawingRect( component->GetBoundingBox() );


    component->SetOrientation( orientation );
    component->SetOrientation( aOrientation );


    /* Redraw the component in the new position. */
    /* Redraw the component in the new position. */
    if( component->GetFlags() )
    if( component->GetFlags() )
+12 −56
Original line number Original line Diff line number Diff line
@@ -154,11 +154,13 @@ static EDA_HOTKEY HkAddGraphicPolyLine( wxT( "Add Graphic PolyLine" ), HK_ADD_GR
                                        'I', ID_LINE_COMMENT_BUTT );
                                        'I', ID_LINE_COMMENT_BUTT );
static EDA_HOTKEY HkAddGraphicText( wxT( "Add Graphic Text" ), HK_ADD_GRAPHIC_TEXT, 'T',
static EDA_HOTKEY HkAddGraphicText( wxT( "Add Graphic Text" ), HK_ADD_GRAPHIC_TEXT, 'T',
                                    ID_TEXT_COMMENT_BUTT );
                                    ID_TEXT_COMMENT_BUTT );
static EDA_HOTKEY HkMirrorYComponent( wxT( "Mirror Y Component" ), HK_MIRROR_Y_COMPONENT, 'Y' );
static EDA_HOTKEY HkMirrorY( wxT( "Mirror Y Component" ), HK_MIRROR_Y_COMPONENT, 'Y',
static EDA_HOTKEY HkMirrorXComponent( wxT( "Mirror X Component" ), HK_MIRROR_X_COMPONENT, 'X' );
                             ID_SCH_MIRROR_Y );
static EDA_HOTKEY HkMirrorX( wxT( "Mirror X Component" ), HK_MIRROR_X_COMPONENT, 'X',
                             ID_SCH_MIRROR_X );
static EDA_HOTKEY HkOrientNormalComponent( wxT( "Orient Normal Component" ),
static EDA_HOTKEY HkOrientNormalComponent( wxT( "Orient Normal Component" ),
                                           HK_ORIENT_NORMAL_COMPONENT, 'N' );
                                           HK_ORIENT_NORMAL_COMPONENT, 'N', ID_SCH_ORIENT_NORMAL );
static EDA_HOTKEY HkRotate( wxT( "Rotate Item" ), HK_ROTATE, 'R', ID_SCH_ROTATE_ITEM );
static EDA_HOTKEY HkRotate( wxT( "Rotate Item" ), HK_ROTATE, 'R', ID_SCH_ROTATE_CLOCKWISE );
static EDA_HOTKEY HkEdit( wxT( "Edit Schematic Item" ), HK_EDIT, 'E', ID_SCH_EDIT_ITEM );
static EDA_HOTKEY HkEdit( wxT( "Edit Schematic Item" ), HK_EDIT, 'E', ID_SCH_EDIT_ITEM );
static EDA_HOTKEY HkEditComponentValue( wxT( "Edit Component Value" ),
static EDA_HOTKEY HkEditComponentValue( wxT( "Edit Component Value" ),
                                        HK_EDIT_COMPONENT_VALUE, 'V',
                                        HK_EDIT_COMPONENT_VALUE, 'V',
@@ -168,7 +170,7 @@ static EDA_HOTKEY HkEditComponentFootprint( wxT( "Edit Component Footprint" ),
                                            ID_SCH_EDIT_COMPONENT_FOOTPRINT );
                                            ID_SCH_EDIT_COMPONENT_FOOTPRINT );
static EDA_HOTKEY HkMove( wxT( "Move Schematic Item" ),
static EDA_HOTKEY HkMove( wxT( "Move Schematic Item" ),
                          HK_MOVE_COMPONENT_OR_ITEM, 'M',
                          HK_MOVE_COMPONENT_OR_ITEM, 'M',
                          ID_POPUP_SCH_MOVE_ITEM );
                          ID_SCH_MOVE_ITEM );


static EDA_HOTKEY HkCopyComponentOrText( wxT( "Copy Component or Label" ),
static EDA_HOTKEY HkCopyComponentOrText( wxT( "Copy Component or Label" ),
                                         HK_COPY_COMPONENT_OR_LABEL, 'C',
                                         HK_COPY_COMPONENT_OR_LABEL, 'C',
@@ -222,8 +224,8 @@ EDA_HOTKEY* s_Schematic_Hotkey_List[] =
    &HkAddComponent,
    &HkAddComponent,
    &HkAddPower,
    &HkAddPower,
    &HkRotate,
    &HkRotate,
    &HkMirrorXComponent,
    &HkMirrorX,
    &HkMirrorYComponent,
    &HkMirrorY,
    &HkOrientNormalComponent,
    &HkOrientNormalComponent,
    &HkEdit,
    &HkEdit,
    &HkEditComponentValue,
    &HkEditComponentValue,
@@ -440,55 +442,6 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,


        break;
        break;


    case HK_MIRROR_Y_COMPONENT:     // Mirror Y (Component)
        if( screen->m_BlockLocate.m_State != STATE_NO_BLOCK )
        {
            HandleBlockEndByPopUp( BLOCK_MIRROR_Y, aDC );
            break;
        }

        if( aItem == NULL )
            aItem = LocateAndShowItem( aPosition, SCH_COLLECTOR::ComponentsOnly );

        if( aItem )
        {
            screen->SetCurItem( (SCH_ITEM*) aItem );
            cmd.SetId( ID_POPUP_SCH_MIRROR_Y_CMP );
            GetEventHandler()->ProcessEvent( cmd );
        }
        break;

    case HK_MIRROR_X_COMPONENT:     // Mirror X (Component)
        if( screen->m_BlockLocate.m_State != STATE_NO_BLOCK ) //allows bloc operation on hotkey
		{
            HandleBlockEndByPopUp( BLOCK_MIRROR_X, aDC );
            break;
		}

        if( aItem == NULL )
            aItem = LocateAndShowItem( aPosition, SCH_COLLECTOR::ComponentsOnly );

        if( aItem )
        {
            screen->SetCurItem( (SCH_ITEM*) aItem );
            cmd.SetId( ID_POPUP_SCH_MIRROR_X_CMP );
            GetEventHandler()->ProcessEvent( cmd );
        }
        break;

    case HK_ORIENT_NORMAL_COMPONENT:        // Orient 0, no mirror (Component)
        if( aItem == NULL )
            aItem = LocateAndShowItem( aPosition, SCH_COLLECTOR::ComponentsOnly );

        if( aItem )
        {
            screen->SetCurItem( (SCH_ITEM*) aItem );
            cmd.SetId( ID_POPUP_SCH_ORIENT_NORMAL_CMP );
            GetEventHandler()->ProcessEvent( cmd );
        }

        break;

    case HK_COPY_COMPONENT_OR_LABEL:        // Duplicate component or text/label
    case HK_COPY_COMPONENT_OR_LABEL:        // Duplicate component or text/label
        if( itemInEdit )
        if( itemInEdit )
            break;
            break;
@@ -505,6 +458,9 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
        wxPostEvent( this, cmd );
        wxPostEvent( this, cmd );
        break;
        break;


    case HK_MIRROR_Y_COMPONENT:             // Mirror Y
    case HK_MIRROR_X_COMPONENT:             // Mirror X
    case HK_ORIENT_NORMAL_COMPONENT:        // Orient 0, no mirror (Component)
    case HK_DRAG:                           // Start drag
    case HK_DRAG:                           // Start drag
    case HK_ROTATE:                         // Rotate schematic item or block.
    case HK_ROTATE:                         // Rotate schematic item or block.
    case HK_MOVE_COMPONENT_OR_ITEM:         // Start move schematic item.
    case HK_MOVE_COMPONENT_OR_ITEM:         // Start move schematic item.
Loading