diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 8c24056a1d..0ad5bf307d 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2010 Jean-Pierre Charras, jp.charras@wanadoo.fr * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index 88cfaa49b1..58a39e8aa6 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -1,7 +1,3 @@ -/*************************************************************/ -/* board editor: undo and redo functions for board editor */ -/*************************************************************/ - /* * This program source code file is part of KiCad, a free EDA CAD application. * @@ -45,8 +41,8 @@ /* Functions to undo and redo edit commands. - * commmands to undo are stored in CurrentScreen->m_UndoList - * commmands to redo are stored in CurrentScreen->m_RedoList + * commands to undo are stored in CurrentScreen->m_UndoList + * commands to redo are stored in CurrentScreen->m_RedoList * * m_UndoList and m_RedoList handle a std::vector of PICKED_ITEMS_LIST * Each PICKED_ITEMS_LIST handle a std::vector of pickers (class ITEM_PICKER), @@ -89,8 +85,8 @@ * => The list of item(s) is used to create a deleted list in undo list(same as a delete * command) * - * Some block operations that change items can be undoed without memorise items, just the - * coordiantes of the transform: + * Some block operations that change items can be undone without memorize items, just the + * coordinates of the transform: * move list of items (undo/redo is made by moving with the opposite move vector) * mirror (Y) and flip list of items (undo/redo is made by mirror or flip items) * so they are handled specifically. @@ -101,7 +97,7 @@ /** * Function TestForExistingItem * test if aItem exists somewhere in lists of items - * This is a function unsed by PutDataInPreviousState to be sure an item was not deleted + * This is a function used by PutDataInPreviousState to be sure an item was not deleted * since an undo or redo. * This could be possible: * - if a call to SaveCopyInUndoList was forgotten in Pcbnew @@ -177,15 +173,6 @@ static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem ) } -/** - * Function SwapData - * Used in undo / redo command: - * swap data between Item and a copy - * swapped data is data modified by edition, mainly sizes and texts - * so ONLY FEW values are swapped - * @param aItem = the item - * @param aImage = a copy of the item - */ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) { if( aItem == NULL || aImage == NULL ) @@ -287,16 +274,6 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) case PCB_TEXT_T: std::swap( *((TEXTE_PCB*)aItem), *((TEXTE_PCB*)aImage) ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_Mirror, ( (TEXTE_PCB*) aImage )->m_Mirror ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_Size, ( (TEXTE_PCB*) aImage )->m_Size ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_Pos, ( (TEXTE_PCB*) aImage )->m_Pos ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_Thickness, ( (TEXTE_PCB*) aImage )->m_Thickness ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_Orient, ( (TEXTE_PCB*) aImage )->m_Orient ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_Text, ( (TEXTE_PCB*) aImage )->m_Text ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_Italic, ( (TEXTE_PCB*) aImage )->m_Italic ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_Bold, ( (TEXTE_PCB*) aImage )->m_Bold ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_HJustify, ( (TEXTE_PCB*) aImage )->m_HJustify ); - // EXCHG( ( (TEXTE_PCB*) aItem )->m_VJustify, ( (TEXTE_PCB*) aImage )->m_VJustify ); break; case PCB_TARGET_T: @@ -304,19 +281,7 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) break; case PCB_DIMENSION_T: - { - std::swap( *((DIMENSION*)aItem), *((DIMENSION*)aImage) ); - // wxString txt = ( (DIMENSION*) aItem )->GetText(); - // ( (DIMENSION*) aItem )->SetText( ( (DIMENSION*) aImage )->GetText() ); - // ( (DIMENSION*) aImage )->SetText( txt ); - // EXCHG( ( (DIMENSION*) aItem )->m_Width, ( (DIMENSION*) aImage )->m_Width ); - // EXCHG( ( (DIMENSION*) aItem )->m_Text.m_Size, ( (DIMENSION*) aImage )->m_Text.m_Size ); - // EXCHG( ( (DIMENSION*) aItem )->m_Text.m_Pos, ( (DIMENSION*) aImage )->m_Text.m_Pos ); - // EXCHG( ( (DIMENSION*) aItem )->m_Text.m_Thickness, - // ( (DIMENSION*) aImage )->m_Text.m_Thickness ); - // EXCHG( ( (DIMENSION*) aItem )->m_Text.m_Mirror, - // ( (DIMENSION*) aImage )->m_Text.m_Mirror ); - } + std::swap( *((DIMENSION*)aItem), *((DIMENSION*)aImage) ); break; case PCB_ZONE_T: @@ -327,18 +292,6 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) } -/* - * Function SaveCopyInUndoList - * Create a copy of the current board item, and put it in the undo list. - * - * aCommandType = - * UR_CHANGED - * UR_NEW - * UR_DELETED - * UR_MOVED - * UR_FLIPPED - * UR_ROTATED - */ void PCB_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem, UNDO_REDO_T aCommandType, const wxPoint& aTransformPoint ) @@ -364,7 +317,7 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem, case UR_DELETED: #ifdef USE_WX_OVERLAY // Avoid to redraw when autoplacing - if( aItem->Type() == PCB_MODULE_T ) + if( aItem->Type() == PCB_MODULE_T ) if( ((MODULE*)aItem)->GetFlags() & MODULE_to_PLACE ) break; m_canvas->Refresh(); @@ -400,12 +353,6 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem, } -/** - * Function SaveCopyInUndoList - * @param aItemsList = a PICKED_ITEMS_LIST of items to save - * @param aTypeCommand = type of comand ( UR_CHANGED, UR_NEW, UR_DELETED ... - * @param aTransformPoint - Transform items around this point. - */ void PCB_EDIT_FRAME::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, UNDO_REDO_T aTypeCommand, const wxPoint& aTransformPoint ) @@ -478,15 +425,6 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, } -/** - * Function PutDataInPreviousState - * Used in undo or redo command. - * Put data pointed by List in the previous state, i.e. the state memorised by List - * @param aList = a PICKED_ITEMS_LIST pointer to the list of items to undo/redo - * @param aRedoCommand = a bool: true for redo, false for undo - * @param aRebuildRatsnet = a bool: true to rebuid ratsnet (normal use, and default), false - * to just retrieve las state (used in abort commands that do not need to rebuild ratsnest) - */ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRedoCommand, bool aRebuildRatsnet ) { @@ -497,7 +435,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed // Undo in the reverse order of list creation: (this can allow stacked changes // like the same item can be changes and deleted in the same complex command - bool build_item_list = true; // if true the list of esiting items must be rebuilt + bool build_item_list = true; // if true the list of existing items must be rebuilt + for( int ii = aList->GetCount()-1; ii >= 0 ; ii-- ) { item = (BOARD_ITEM*) aList->GetPickedItem( ii ); @@ -508,19 +447,21 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed * - if a call to SaveCopyInUndoList was forgotten in Pcbnew * - in zones outlines, when a change in one zone merges this zone with an other * This test avoids a Pcbnew crash - * Obviouly, this test is not made for deleted items + * Obviously, this test is not made for deleted items */ UNDO_REDO_T status = aList->GetPickedItemStatus( ii ); + if( status != UR_DELETED ) { if( build_item_list ) // Build list of existing items, for integrity test TestForExistingItem( GetBoard(), NULL ); + build_item_list = false; if( !TestForExistingItem( GetBoard(), item ) ) { - // Remove this non existant item + // Remove this non existent item aList->RemovePicker( ii ); ii++; // the current item was removed, ii points now the next item // decrement it because it will be incremented later @@ -595,18 +536,12 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed if( not_found ) wxMessageBox( wxT( "Incomplete undo/redo operation: some items not found" ) ); - // Rebuild pointers and rastnest that can be changed. + // Rebuild pointers and ratsnest that can be changed. if( reBuild_ratsnest && aRebuildRatsnet ) Compile_Ratsnest( NULL, true ); } -/** - * Function GetBoardFromUndoList - * Undo the last edition: - * - Save the current board state in Redo list - * - Get an old version of the board state from Undo list - */ void PCB_EDIT_FRAME::GetBoardFromUndoList( wxCommandEvent& event ) { if( GetScreen()->GetUndoCommandCount() <= 0 ) @@ -626,13 +561,6 @@ void PCB_EDIT_FRAME::GetBoardFromUndoList( wxCommandEvent& event ) } -/** - * Function GetBoardFromRedoList - * Redo the last edition: - * - Save the current board in Undo list - * - Get an old version of the board from Redo list - * @return none - */ void PCB_EDIT_FRAME::GetBoardFromRedoList( wxCommandEvent& event ) { if( GetScreen()->GetRedoCommandCount() == 0 ) @@ -654,17 +582,6 @@ void PCB_EDIT_FRAME::GetBoardFromRedoList( wxCommandEvent& event ) } -/** - * Function ClearUndoORRedoList - * free the undo or redo list from List element - * Wrappers are deleted. - * datas pointed by wrappers are deleted if not in use in schematic - * i.e. when they are copy of a schematic item or they are no more in use (DELETED) - * @param aList = the UNDO_REDO_CONTAINER to clear - * @param aItemCount = the count of items to remove. < 0 for all items - * items (commands stored in list) are removed from the beginning of the list. - * So this function can be called to remove old commands - */ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ) { if( aItemCount == 0 ) diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp index fdde78ef48..01b90df8f8 100644 --- a/pcbnew/hotkeys_board_editor.cpp +++ b/pcbnew/hotkeys_board_editor.cpp @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2009 Jean-Pierre Charras, jp.charras@wanadoo.fr + * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + /** * @file hotkeys_board_editor.cpp */ @@ -117,7 +141,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit macros_record.m_HotkeyCode = aHotkeyCode; macros_record.m_Idcommand = HK_Descr->m_Idcommand; macros_record.m_Position = GetNearestGridPosition( aPosition ) - - m_Macros[m_RecordingMacros].m_StartPosition; + m_Macros[m_RecordingMacros].m_StartPosition; m_Macros[m_RecordingMacros].m_Record.push_back( macros_record ); wxString msg; msg.Printf( _( "Add key [%c] in macro %d" ), aHotkeyCode, m_RecordingMacros ); @@ -168,7 +192,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit if( GetCanvas()->IsMouseCaptured() ) GetCanvas()->CallMouseCapture( aDC, wxDefaultPosition, false ); - if( GetBoard()->GetTrackWidthIndex() < GetBoard()->m_TrackWidthList.size() - 1) + if( GetBoard()->GetTrackWidthIndex() < GetBoard()->m_TrackWidthList.size() - 1 ) GetBoard()->SetTrackWidthIndex( GetBoard()->GetTrackWidthIndex() + 1 ); else GetBoard()->SetTrackWidthIndex( 0 ); @@ -594,7 +618,7 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC ) { item = PcbGeneralLocateAndDisplay(); - if( item && !item->IsTrack( ) ) + if( item && !item->IsTrack() ) return false; Delete_Track( aDC, (TRACK*) item ); @@ -945,15 +969,7 @@ bool PCB_EDIT_FRAME::OnHotkeyPlaceItem( wxDC* aDC ) return false; } -/* - * Function OnHotkeyBeginRoute - * If the current active layer is a copper layer, - * and if no item currently edited, starta new track on - * the current copper layer - * If a new track is in progress, terminate the current segment and - * start a new one. - * Returns a reference to the track if a track is created, or NULL - */ + TRACK * PCB_EDIT_FRAME::OnHotkeyBeginRoute( wxDC* aDC ) { if( getActiveLayer() > LAYER_N_FRONT ) @@ -1004,42 +1020,48 @@ bool PCB_EDIT_FRAME::OnHotkeyRotateItem( int aIdCommand ) bool itemCurrentlyEdited = item && item->GetFlags(); int evt_type = 0; // Used to post a wxCommandEvent on demand - if( !itemCurrentlyEdited ) - item = PcbGeneralLocateAndDisplay(); - - if( item == NULL ) - return false; - - SetCurItem( item ); - - switch( item->Type() ) + // Allows block rotate operation on hot key. + if( GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK ) { - case PCB_MODULE_T: - { - if( aIdCommand == HK_ROTATE_ITEM ) // Rotation - evt_type = ID_POPUP_PCB_ROTATE_MODULE_COUNTERCLOCKWISE; - - if( aIdCommand == HK_FLIP_ITEM ) // move to other side - evt_type = ID_POPUP_PCB_CHANGE_SIDE_MODULE; + evt_type = ID_POPUP_ROTATE_BLOCK; } - break; + else + { + if( !itemCurrentlyEdited ) + item = PcbGeneralLocateAndDisplay(); - case PCB_TEXT_T: - if( aIdCommand == HK_ROTATE_ITEM ) // Rotation - evt_type = ID_POPUP_PCB_ROTATE_TEXTEPCB; - else if( aIdCommand == HK_FLIP_ITEM ) - evt_type = ID_POPUP_PCB_FLIP_TEXTEPCB; + if( item == NULL ) + return false; - break; + SetCurItem( item ); - case PCB_MODULE_TEXT_T: - if( aIdCommand == HK_ROTATE_ITEM ) // Rotation - evt_type = ID_POPUP_PCB_ROTATE_TEXTMODULE; + switch( item->Type() ) + { + case PCB_MODULE_T: + if( aIdCommand == HK_ROTATE_ITEM ) // Rotation + evt_type = ID_POPUP_PCB_ROTATE_MODULE_COUNTERCLOCKWISE; - break; + if( aIdCommand == HK_FLIP_ITEM ) // move to other side + evt_type = ID_POPUP_PCB_CHANGE_SIDE_MODULE; + break; - default: - break; + case PCB_TEXT_T: + if( aIdCommand == HK_ROTATE_ITEM ) // Rotation + evt_type = ID_POPUP_PCB_ROTATE_TEXTEPCB; + else if( aIdCommand == HK_FLIP_ITEM ) + evt_type = ID_POPUP_PCB_FLIP_TEXTEPCB; + + break; + + case PCB_MODULE_TEXT_T: + if( aIdCommand == HK_ROTATE_ITEM ) // Rotation + evt_type = ID_POPUP_PCB_ROTATE_TEXTMODULE; + + break; + + default: + break; + } } if( evt_type != 0 ) diff --git a/pcbnew/protos.h b/pcbnew/protos.h index 7218e7508d..b469212b7b 100644 --- a/pcbnew/protos.h +++ b/pcbnew/protos.h @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2007 Jean-Pierre Charras, jp.charras@wanadoo.fr + * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + /** * @file pcbnew/protos.h */ @@ -17,7 +41,8 @@ class MODULE; * Function SwapData * Used in undo / redo command: * swap data between Item and a copy - * swapped data is data modified by edition, so NOT ALL values are swapped + * swapped data is data modified by edition, mainly sizes and texts + * so ONLY FEW values are swapped * @param aItem = the item * @param aImage = a copy of the item */