Commit 5699ee3b authored by charras's avatar charras

More about pcbnew undo/redo

parent d9ea63a8
...@@ -50,12 +50,20 @@ PICKED_ITEMS_LIST::~PICKED_ITEMS_LIST() ...@@ -50,12 +50,20 @@ PICKED_ITEMS_LIST::~PICKED_ITEMS_LIST()
} }
void PICKED_ITEMS_LIST::PushItem( ITEM_PICKER& aItem) /** PushItem
* push a picker to the top of the list
* @param aItem = picker to push
*/
void PICKED_ITEMS_LIST::PushItem( ITEM_PICKER& aItem )
{ {
m_ItemsList.push_back( aItem ); m_ItemsList.push_back( aItem );
} }
/** PopItem
* @return the picker from the top of the list
* the picker is removed from the list
*/
ITEM_PICKER PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::PopItem() ITEM_PICKER PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::PopItem()
{ {
ITEM_PICKER item; ITEM_PICKER item;
...@@ -69,19 +77,87 @@ ITEM_PICKER PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::PopItem() ...@@ -69,19 +77,87 @@ ITEM_PICKER PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::PopItem()
} }
void PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::ClearItemsList() /** Function ClearItemsList
* delete only the list of pickers, NOT the picked data itself
/* delete only the list of EDA_BaseStruct * pointers, NOT the pointed data itself
*/ */
void PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::ClearItemsList()
{ {
m_ItemsList.clear(); m_ItemsList.clear();
} }
/** Function ClearListAndDeleteItems
* delete the list of pickers, AND the data pointed
* by m_PickedItem or m_PickedItemLink, according to the type of undo/redo command recorded
*/
void PICKED_ITEMS_LIST::ClearListAndDeleteItems() void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
{ {
for(unsigned ii = 0; ii < m_ItemsList.size(); ii++ ) bool show_error_message = true;
delete m_ItemsList[ii].m_PickedItem;
m_ItemsList.clear(); // Delete items is they are not flagged UR_NEW, or if this is a block operation
while( GetCount() > 0 )
{
ITEM_PICKER wrapper = PopItem();
if( wrapper.m_PickedItem == NULL ) // No more item in list.
break;
switch( wrapper.m_UndoRedoStatus )
{
case UR_UNSPECIFIED:
if( show_error_message )
wxMessageBox( wxT( "ClearUndoORRedoList() error: UR_UNSPECIFIED command type" ) );
show_error_message = false;
break;
case UR_WIRE_IMAGE:
{
// Specific to eeschema: a linked list of wires is stored.
// the wrapper picks only the first item (head of list), and is owner of all picked items
EDA_BaseStruct* item = wrapper.m_PickedItem;
while( item )
{
// Delete old copy of wires
EDA_BaseStruct* nextitem = item->Next();
delete item;
item = nextitem;
}
}
break;
case UR_MOVED:
case UR_FLIPPED:
case UR_MIRRORED_X:
case UR_MIRRORED_Y:
case UR_ROTATED:
case UR_ROTATED_CLOCKWISE:
case UR_NEW: // Do nothing, items are in use, the picker is not owner of items
break;
case UR_CHANGED:
delete wrapper.m_Link; // the picker is owner of this item
break;
case UR_DELETED: // the picker is owner of this item
case UR_LIBEDIT: /* Libedit save always a copy of the current item
* So, the picker is always owner of the picked item
*/
case UR_MODEDIT: /* Specific to the module editor
* (modedit creates a full copy of the current module when changed),
* and the picker is owner of this item
*/
delete wrapper.m_PickedItem;
break;
default:
{
wxString msg;
msg.Printf( wxT(
"ClearUndoORRedoList() error: unknown command type %d" ),
wrapper.m_UndoRedoStatus );
wxMessageBox( msg );
}
break;
}
}
} }
...@@ -94,12 +170,14 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems() ...@@ -94,12 +170,14 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx ) ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx )
{ {
ITEM_PICKER picker; ITEM_PICKER picker;
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
picker = m_ItemsList[aIdx]; picker = m_ItemsList[aIdx];
return picker; return picker;
} }
/** function GetPickedItem /** function GetPickedItem
* @return a pointer to the picked item, or null if does not exist * @return a pointer to the picked item, or null if does not exist
* @param aIdx = index of the picked item in the picked list * @param aIdx = index of the picked item in the picked list
...@@ -181,7 +259,9 @@ bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_BaseStruct* aLink, unsigned aIdx ...@@ -181,7 +259,9 @@ bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_BaseStruct* aLink, unsigned aIdx
* @param aIdx = index of the picker in the picked list * @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist * @return true if the picker exists, or false if does not exist
*/ */
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_BaseStruct* aItem, UndoRedoOpType aStatus, unsigned aIdx ) bool PICKED_ITEMS_LIST::SetPickedItem( EDA_BaseStruct* aItem,
UndoRedoOpType aStatus,
unsigned aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
{ {
...@@ -225,17 +305,19 @@ bool PICKED_ITEMS_LIST::RemovePickedItem( unsigned aIdx ) ...@@ -225,17 +305,19 @@ bool PICKED_ITEMS_LIST::RemovePickedItem( unsigned aIdx )
return true; return true;
} }
/** Function CopyList /** Function CopyList
* copy all data from aSource * copy all data from aSource
* Items picked are not copied. just pointer on them are copied * Items picked are not copied. just pointer on them are copied
*/ */
void PICKED_ITEMS_LIST::CopyList(const PICKED_ITEMS_LIST & aSource) void PICKED_ITEMS_LIST::CopyList( const PICKED_ITEMS_LIST& aSource )
{ {
ITEM_PICKER picker; ITEM_PICKER picker;
for(unsigned ii = 0; ii < aSource.GetCount(); ii++ )
for( unsigned ii = 0; ii < aSource.GetCount(); ii++ )
{ {
picker = aSource.m_ItemsList[ii]; picker = aSource.m_ItemsList[ii];
PushItem(picker); PushItem( picker );
} }
} }
......
...@@ -290,12 +290,13 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, ...@@ -290,12 +290,13 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
itemWrapper.m_PickedItem = item; itemWrapper.m_PickedItem = item;
itemWrapper.m_PickedItemType = item->Type(); itemWrapper.m_PickedItemType = item->Type();
itemWrapper.m_UndoRedoStatus = command; itemWrapper.m_UndoRedoStatus = command;
itemWrapper.m_Link = aItemsList.GetPickedItemLink( ii );
switch( command ) switch( command )
{ {
case UR_CHANGED: /* Create a copy of item */ case UR_CHANGED: /* Create a copy of item */
CopyOfItem = DuplicateStruct( item ); if( itemWrapper.m_Link == NULL )
itemWrapper.m_Link = CopyOfItem; itemWrapper.m_Link = DuplicateStruct( item );
if ( CopyOfItem ) if ( itemWrapper.m_Link )
commandToUndo->PushItem( itemWrapper ); commandToUndo->PushItem( itemWrapper );
break; break;
...@@ -495,56 +496,7 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ...@@ -495,56 +496,7 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0]; PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
aList.m_CommandsList.erase( aList.m_CommandsList.begin() ); aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
// Delete items is they are not flagged UR_NEW, or if this is a block operation curr_cmd->ClearListAndDeleteItems();
while( 1 )
{
ITEM_PICKER wrapper = curr_cmd->PopItem();
EDA_BaseStruct* item = wrapper.m_PickedItem;
if( item == NULL ) // No more item in list.
break;
switch( wrapper.m_UndoRedoStatus )
{
case UR_WIRE_IMAGE:
while( item )
{ // Delete old copy of wires
EDA_BaseStruct* nextitem = item->Next();
delete item;
item = nextitem;
}
break;
case UR_MOVED:
case UR_MIRRORED_X:
case UR_MIRRORED_Y:
case UR_ROTATED:
case UR_NEW: // Do nothing, items are in use
break;
case UR_LIBEDIT: // Libedit save always a copy of the current item
delete item; // So, the picker is always owner of the picked item
break;
case UR_DELETED:
delete item; // Delete the picked item, because it was deleted from schematic
break;
case UR_CHANGED:
delete wrapper.m_Link; // Delete the copy of item (the item is itself in use)
break;
default:
{
wxString msg;
msg.Printf(
wxT("ClearUndoORRedoList() error: unexpected undo/redo type %d"),
wrapper.m_UndoRedoStatus );
wxMessageBox( msg );
break;
}
}
}
delete curr_cmd; // Delete command delete curr_cmd; // Delete command
} }
} }
...@@ -58,7 +58,8 @@ enum UndoRedoOpType { ...@@ -58,7 +58,8 @@ enum UndoRedoOpType {
UR_MOVED, // moved item, undo by move it UR_MOVED, // moved item, undo by move it
UR_MIRRORED_X, // mirrored item, undo by mirror X UR_MIRRORED_X, // mirrored item, undo by mirror X
UR_MIRRORED_Y, // mirrored item, undo by mirror Y UR_MIRRORED_Y, // mirrored item, undo by mirror Y
UR_ROTATED, // Rotated item, undo by rotating it UR_ROTATED, // Rotated item (counterclockwise), undo by rotating it
UR_ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it
UR_FLIPPED, // flipped (board items only), undo by flipping it UR_FLIPPED, // flipped (board items only), undo by flipping it
UR_WIRE_IMAGE, // Specific to eeschema: handle wires changes UR_WIRE_IMAGE, // Specific to eeschema: handle wires changes
UR_MODEDIT, // Specific to the module editor (modedit creates a full copy of the current module when changed) UR_MODEDIT, // Specific to the module editor (modedit creates a full copy of the current module when changed)
...@@ -104,19 +105,33 @@ private: ...@@ -104,19 +105,33 @@ private:
public: public:
PICKED_ITEMS_LIST(); PICKED_ITEMS_LIST();
~PICKED_ITEMS_LIST(); ~PICKED_ITEMS_LIST();
/** PushItem
* push a picker to the top of the list
* @param aItem = picker to push
*/
void PushItem( ITEM_PICKER& aItem ); void PushItem( ITEM_PICKER& aItem );
/** PopItem
* @return the picker from the top of the list
* the picker is removed from the list
*/
ITEM_PICKER PopItem(); ITEM_PICKER PopItem();
/** Function ClearItemsList /** Function ClearItemsList
* delete only the list of EDA_BaseStruct * pointers, NOT the pointed data itself * delete only the list of pickers, NOT the picked data itself
*/ */
void ClearItemsList(); void ClearItemsList();
/** Function ClearListAndDeleteItems /** Function ClearListAndDeleteItems
* delete only the list of EDA_BaseStruct * pointers, AND the data pinted by m_Item * delete the list of pickers, AND the data pointed
* by m_PickedItem or m_PickedItemLink, according to the type of undo/redo command recorded
*/ */
void ClearListAndDeleteItems(); void ClearListAndDeleteItems();
/** function GetCount()
* @return the count of pickers stored in this list
*/
unsigned GetCount() const unsigned GetCount() const
{ {
return m_ItemsList.size(); return m_ItemsList.size();
......
...@@ -178,9 +178,6 @@ public: ...@@ -178,9 +178,6 @@ public:
// Gestion des modules // Gestion des modules
void InstallModuleOptionsFrame( MODULE* Module, wxDC * DC ); void InstallModuleOptionsFrame( MODULE* Module, wxDC * DC );
MODULE* Copie_Module( MODULE* module ); MODULE* Copie_Module( MODULE* module );
MODULE* Exchange_Module( wxWindow* winaff,
MODULE* old_module,
MODULE* new_module );
/** Function Save_Module_In_Library /** Function Save_Module_In_Library
* Save in an existing library a given footprint * Save in an existing library a given footprint
...@@ -207,7 +204,6 @@ public: ...@@ -207,7 +204,6 @@ public:
int angle, int angle,
bool incremental ); bool incremental );
void Place_Module( MODULE* module, wxDC* DC, bool aDoNotRecreateRatsnest = false ); void Place_Module( MODULE* module, wxDC* DC, bool aDoNotRecreateRatsnest = false );
void InstallExchangeModuleFrame( MODULE* ExchangeModuleModule );
// Graphic items edition: // Graphic items edition:
void InstallGraphicItemPropertiesDialog( DRAWSEGMENT* aItem, wxDC* aDC ); void InstallGraphicItemPropertiesDialog( DRAWSEGMENT* aItem, wxDC* aDC );
......
...@@ -330,6 +330,20 @@ public: ...@@ -330,6 +330,20 @@ public:
// Footprint edition (see also WinEDA_BasePcbFrame) // Footprint edition (see also WinEDA_BasePcbFrame)
void StartMove_Module( MODULE* module, wxDC* DC ); void StartMove_Module( MODULE* module, wxDC* DC );
bool Delete_Module( MODULE* module, wxDC* DC, bool aAskBeforeDeleting ); bool Delete_Module( MODULE* module, wxDC* DC, bool aAskBeforeDeleting );
void Change_Side_Module( MODULE* Module, wxDC* DC );
void InstallExchangeModuleFrame( MODULE* ExchangeModuleModule );
/** function Exchange_Module
* Replaces OldModule by NewModule, using OldModule settings:
* position, orientation, pad netnames ...)
* OldModule is deleted or put in undo list.
* @param aOldModule = footprint to replace
* @param aNewModule = footprint to put
* @param aUndoPickList = the undo list used to save OldModule. If null, OldModule is deleted
*/
void Exchange_Module( MODULE* aOldModule,
MODULE* aNewModule,
PICKED_ITEMS_LIST* aUndoPickList);
// loading modules: see WinEDA_BasePcbFrame // loading modules: see WinEDA_BasePcbFrame
......
...@@ -125,6 +125,7 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) ...@@ -125,6 +125,7 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
return; return;
} }
// Swap layers:
int layer, layerimg; int layer, layerimg;
layer = aItem->GetLayer(); layer = aItem->GetLayer();
layerimg = aImage->GetLayer(); layerimg = aImage->GetLayer();
...@@ -183,9 +184,14 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) ...@@ -183,9 +184,14 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
break; break;
case TYPE_COTATION: case TYPE_COTATION:
{
wxString txt = ( (COTATION*) aItem )->GetText();
( (COTATION*) aItem )->SetText( ((COTATION*) aImage )->GetText() );
( (COTATION*) aImage )->SetText( txt );
EXCHG( ( (COTATION*) aItem )->m_Text->m_Size, ( (COTATION*) aImage )->m_Text->m_Size ); EXCHG( ( (COTATION*) aItem )->m_Text->m_Size, ( (COTATION*) aImage )->m_Text->m_Size );
EXCHG( ( (COTATION*) aItem )->m_Text->m_Width, ( (COTATION*) aImage )->m_Text->m_Width ); EXCHG( ( (COTATION*) aItem )->m_Text->m_Width, ( (COTATION*) aImage )->m_Text->m_Width );
EXCHG( ( (COTATION*) aItem )->m_Text->m_Mirror, ( (COTATION*) aImage )->m_Text->m_Mirror ); EXCHG( ( (COTATION*) aItem )->m_Text->m_Mirror, ( (COTATION*) aImage )->m_Text->m_Mirror );
}
break; break;
default: default:
...@@ -316,7 +322,6 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem, ...@@ -316,7 +322,6 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem,
if( aItem == NULL ) // Nothing to save if( aItem == NULL ) // Nothing to save
return; return;
BOARD_ITEM* CopyOfItem;
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST(); PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
commandToUndo->m_TransformPoint = aTransformPoint; commandToUndo->m_TransformPoint = aTransformPoint;
...@@ -327,9 +332,9 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem, ...@@ -327,9 +332,9 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem,
switch( aCommandType ) switch( aCommandType )
{ {
case UR_CHANGED: /* Create a copy of schematic */ case UR_CHANGED: /* Create a copy of schematic */
CopyOfItem = DuplicateStruct( aItem ); if( itemWrapper.m_Link == NULL ) // When not null, the copy is already done
itemWrapper.m_Link = CopyOfItem; itemWrapper.m_Link = DuplicateStruct( aItem );;
if( CopyOfItem ) if( itemWrapper.m_Link )
commandToUndo->PushItem( itemWrapper ); commandToUndo->PushItem( itemWrapper );
break; break;
...@@ -337,6 +342,7 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem, ...@@ -337,6 +342,7 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem,
case UR_MOVED: case UR_MOVED:
case UR_FLIPPED: case UR_FLIPPED:
case UR_ROTATED: case UR_ROTATED:
case UR_ROTATED_CLOCKWISE:
case UR_DELETED: case UR_DELETED:
commandToUndo->PushItem( itemWrapper ); commandToUndo->PushItem( itemWrapper );
break; break;
...@@ -371,7 +377,6 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, ...@@ -371,7 +377,6 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand, UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint ) const wxPoint& aTransformPoint )
{ {
BOARD_ITEM* CopyOfItem;
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST(); PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
commandToUndo->m_TransformPoint = aTransformPoint; commandToUndo->m_TransformPoint = aTransformPoint;
...@@ -389,17 +394,19 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, ...@@ -389,17 +394,19 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
itemWrapper.m_PickedItem = item; itemWrapper.m_PickedItem = item;
itemWrapper.m_PickedItemType = item->Type(); itemWrapper.m_PickedItemType = item->Type();
itemWrapper.m_UndoRedoStatus = command; itemWrapper.m_UndoRedoStatus = command;
itemWrapper.m_Link = aItemsList.GetPickedItemLink( ii );
switch( command ) switch( command )
{ {
case UR_CHANGED: /* Create a copy of item, and put in undo list */ case UR_CHANGED: /* If needed, create a copy of item, and put in undo list */
CopyOfItem = DuplicateStruct( item ); if( itemWrapper.m_Link == NULL ) // When not null, the copy is already done
itemWrapper.m_Link = CopyOfItem; itemWrapper.m_Link = DuplicateStruct( item );
if( CopyOfItem ) if( itemWrapper.m_Link )
commandToUndo->PushItem( itemWrapper ); commandToUndo->PushItem( itemWrapper );
break; break;
case UR_MOVED: case UR_MOVED:
case UR_ROTATED: case UR_ROTATED:
case UR_ROTATED_CLOCKWISE:
case UR_FLIPPED: case UR_FLIPPED:
case UR_NEW: case UR_NEW:
case UR_DELETED: case UR_DELETED:
...@@ -500,6 +507,10 @@ void WinEDA_PcbFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRe ...@@ -500,6 +507,10 @@ void WinEDA_PcbFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRe
item->Rotate( aList->m_TransformPoint, aRedoCommand ? 900 : -900 ); item->Rotate( aList->m_TransformPoint, aRedoCommand ? 900 : -900 );
break; break;
case UR_ROTATED_CLOCKWISE:
item->Rotate( aList->m_TransformPoint, aRedoCommand ? -900 : 900 );
break;
case UR_FLIPPED: case UR_FLIPPED:
item->Flip( aList->m_TransformPoint ); item->Flip( aList->m_TransformPoint );
break; break;
...@@ -609,45 +620,7 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ...@@ -609,45 +620,7 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0]; PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
aList.m_CommandsList.erase( aList.m_CommandsList.begin() ); aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
// Delete items is they are not flagged UR_NEW, or if this is a block operation curr_cmd->ClearListAndDeleteItems();
while( 1 )
{
ITEM_PICKER wrapper = curr_cmd->PopItem();
if( wrapper.m_PickedItem == NULL ) // No more item in list.
break;
switch( wrapper.m_UndoRedoStatus )
{
case UR_UNSPECIFIED:
if( displ_error )
wxMessageBox( wxT( "ClearUndoORRedoList() error: unspecified item type" ) );
displ_error = false;
break;
case UR_MOVED:
case UR_FLIPPED:
case UR_MIRRORED_X:
case UR_MIRRORED_Y:
case UR_ROTATED:
case UR_NEW: // Do nothing, items are in use, the picker is not owner of items
break;
case UR_CHANGED:
delete wrapper.m_Link; // the picker is owner of this item
break;
case UR_MODEDIT: /* Specific to the module editor
* (modedit creates a full copy of the current module when changed),
* and the picker is owner of this item
*/
delete wrapper.m_PickedItem;
break;
default:
delete wrapper.m_PickedItem; // the picker is owner of this item
break;
}
}
delete curr_cmd; // Delete command delete curr_cmd; // Delete command
} }
} }
...@@ -380,10 +380,6 @@ public: ...@@ -380,10 +380,6 @@ public:
#endif #endif
/**************************/
/* footprint operations : */
/**************************/
void Change_Side_Module( MODULE* Module, wxDC* DC );
/*************************/ /*************************/
/* Copper Areas handling */ /* Copper Areas handling */
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
/* Routines Locales */ /* Routines Locales */
static void Exit_EditCotation( WinEDA_DrawPanel* Panel, wxDC* DC ); static void Exit_EditCotation( WinEDA_DrawPanel* Panel, wxDC* DC );
static void Montre_Position_New_Cotation( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ); static void Montre_Position_New_Cotation( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
static void Ajuste_Details_Cotation( COTATION* pts ); static void Ajuste_Details_Cotation( COTATION* pts, bool aDoNotChangeText = false );
/* Variables "locales" : */ /* Variables "locales" : */
static int status_cotation; /* = 0 : pas de cotation en cours static int status_cotation; /* = 0 : pas de cotation en cours
...@@ -349,7 +349,7 @@ void WinEDA_PcbFrame::Install_Edit_Cotation( COTATION* Cotation, ...@@ -349,7 +349,7 @@ void WinEDA_PcbFrame::Install_Edit_Cotation( COTATION* Cotation,
WinEDA_CotationPropertiesFrame* frame = new WinEDA_CotationPropertiesFrame( this, WinEDA_CotationPropertiesFrame* frame = new WinEDA_CotationPropertiesFrame( this,
Cotation, DC, pos ); Cotation, DC, pos );
Ajuste_Details_Cotation( Cotation ); Ajuste_Details_Cotation( Cotation, true );
frame->ShowModal(); frame->ShowModal();
frame->Destroy(); frame->Destroy();
} }
...@@ -372,7 +372,7 @@ void WinEDA_PcbFrame::Delete_Cotation( COTATION* Cotation, wxDC* DC ) ...@@ -372,7 +372,7 @@ void WinEDA_PcbFrame::Delete_Cotation( COTATION* Cotation, wxDC* DC )
/*****************************************************/ /*****************************************************/
static void Ajuste_Details_Cotation( COTATION* Cotation ) static void Ajuste_Details_Cotation( COTATION* Cotation, bool aDoNotChangeText )
/*****************************************************/ /*****************************************************/
/* Calcule les details des coordonnees des differents segments constitutifs /* Calcule les details des coordonnees des differents segments constitutifs
...@@ -411,8 +411,8 @@ static void Ajuste_Details_Cotation( COTATION* Cotation ) ...@@ -411,8 +411,8 @@ static void Ajuste_Details_Cotation( COTATION* Cotation )
/* On tient compte de l'inclinaison de la cote */ /* On tient compte de l'inclinaison de la cote */
if( mesure ) if( mesure )
{ {
hx = (abs) ( (int) ( ( (float) deltay * hx ) / mesure ) ); hx = (abs) ( (int) ( ( (double) deltay * hx ) / mesure ) );
hy = (abs) ( (int) ( ( (float) deltax * hy ) / mesure ) ); hy = (abs) ( (int) ( ( (double) deltax * hy ) / mesure ) );
if( Cotation->TraitG_ox > Cotation->Barre_ox ) if( Cotation->TraitG_ox > Cotation->Barre_ox )
hx = -hx; hx = -hx;
...@@ -476,7 +476,10 @@ static void Ajuste_Details_Cotation( COTATION* Cotation ) ...@@ -476,7 +476,10 @@ static void Ajuste_Details_Cotation( COTATION* Cotation )
if( (Cotation->m_Text->m_Orient > 900) && (Cotation->m_Text->m_Orient <2700) ) if( (Cotation->m_Text->m_Orient > 900) && (Cotation->m_Text->m_Orient <2700) )
Cotation->m_Text->m_Orient -= 1800; Cotation->m_Text->m_Orient -= 1800;
if( !aDoNotChangeText )
{
Cotation->m_Value = mesure; Cotation->m_Value = mesure;
valeur_param( Cotation->m_Value, msg ); valeur_param( Cotation->m_Value, msg );
Cotation->SetText( msg ); Cotation->SetText( msg );
}
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "gestfich.h" #include "gestfich.h"
#include "3d_struct.h" #include "3d_struct.h"
#include "3d_viewer.h" #include "3d_viewer.h"
#include "wxPcbStruct.h"
#include "dialog_edit_module.h" #include "dialog_edit_module.h"
extern bool GoToEditor; extern bool GoToEditor;
...@@ -569,7 +570,7 @@ void WinEDA_ModulePropertiesFrame::OnOkClick( wxCommandEvent& event ) ...@@ -569,7 +570,7 @@ void WinEDA_ModulePropertiesFrame::OnOkClick( wxCommandEvent& event )
if( change_layer ) if( change_layer )
{ {
m_Parent->GetBoard()->Change_Side_Module( m_CurrentModule, m_DC ); ((WinEDA_PcbFrame*)m_Parent)->Change_Side_Module( m_CurrentModule, m_DC );
} }
if( m_AutoPlaceCtrl->GetSelection() == 1 ) if( m_AutoPlaceCtrl->GetSelection() == 1 )
...@@ -668,7 +669,7 @@ void WinEDA_ModulePropertiesFrame::GotoModuleEditor( wxCommandEvent& event ) ...@@ -668,7 +669,7 @@ void WinEDA_ModulePropertiesFrame::GotoModuleEditor( wxCommandEvent& event )
void WinEDA_ModulePropertiesFrame::ExchangeModule( wxCommandEvent& event ) void WinEDA_ModulePropertiesFrame::ExchangeModule( wxCommandEvent& event )
/**********************************************************************/ /**********************************************************************/
{ {
m_Parent->InstallExchangeModuleFrame( m_CurrentModule ); ((WinEDA_PcbFrame*)m_Parent)->InstallExchangeModuleFrame( m_CurrentModule );
// Attention: si il y a eu echange, m_CurrentModule a t delete! // Attention: si il y a eu echange, m_CurrentModule a t delete!
m_Parent->SetCurItem( NULL ); m_Parent->SetCurItem( NULL );
......
...@@ -765,7 +765,10 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -765,7 +765,10 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE ) if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
break; break;
Rotate_Module( &dc, (MODULE*) GetCurItem(), -900, true );
if( !(GetCurItem()->m_Flags & IS_MOVED) ) /* This is a simple rotation, no other edition in progress */
SaveCopyInUndoList(GetCurItem(), UR_ROTATED, ((MODULE*)GetCurItem())->m_Pos);
Rotate_Module( &dc, (MODULE*) GetCurItem(), 900, true );
break; break;
case ID_POPUP_PCB_ROTATE_MODULE_CLOCKWISE: case ID_POPUP_PCB_ROTATE_MODULE_CLOCKWISE:
...@@ -777,7 +780,9 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -777,7 +780,9 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE ) if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
break; break;
Rotate_Module( &dc, (MODULE*) GetCurItem(), 900, true ); if( !(GetCurItem()->m_Flags & IS_MOVED) ) /* This is a simple rotation, no other edition in progress */
SaveCopyInUndoList(GetCurItem(), UR_ROTATED_CLOCKWISE, ((MODULE*)GetCurItem())->m_Pos);
Rotate_Module( &dc, (MODULE*) GetCurItem(), -900, true );
break; break;
case ID_POPUP_PCB_CHANGE_SIDE_MODULE: case ID_POPUP_PCB_CHANGE_SIDE_MODULE:
...@@ -788,7 +793,11 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -788,7 +793,11 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
SetCurItem( GetCurItem()->GetParent() ); SetCurItem( GetCurItem()->GetParent() );
if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE ) if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
break; break;
GetBoard()->Change_Side_Module( (MODULE*) GetCurItem(), &dc );
if( !(GetCurItem()->m_Flags & IS_MOVED) ) /* This is a simple flip, no other edition in progress */
SaveCopyInUndoList(GetCurItem(), UR_FLIPPED, ((MODULE*)GetCurItem())->m_Pos);
Change_Side_Module( (MODULE*) GetCurItem(), &dc );
break; break;
case ID_POPUP_PCB_EDIT_MODULE: case ID_POPUP_PCB_EDIT_MODULE:
......
...@@ -100,7 +100,7 @@ void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event ) ...@@ -100,7 +100,7 @@ void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event )
module->flag = 0; module->flag = 0;
if( module->GetLayer() == COPPER_LAYER_N ) if( module->GetLayer() == COPPER_LAYER_N )
{ {
GetBoard()->Change_Side_Module( module, NULL ); module->Flip( module->m_Pos );
module->flag = 1; module->flag = 1;
} }
} }
...@@ -132,7 +132,7 @@ void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event ) ...@@ -132,7 +132,7 @@ void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event )
{ {
if( module->flag ) if( module->flag )
{ {
GetBoard()->Change_Side_Module( module, NULL ); module->Flip( module->m_Pos );
module->flag = 0; module->flag = 0;
} }
} }
......
...@@ -513,7 +513,7 @@ void WinEDA_PcbFrame::OnHotKey(wxDC* DC, int hotkey, EDA_BaseStruct* DrawStruct) ...@@ -513,7 +513,7 @@ void WinEDA_PcbFrame::OnHotKey(wxDC* DC, int hotkey, EDA_BaseStruct* DrawStruct)
break; break;
case HK_FLIP_FOOTPRINT: // move to other side case HK_FLIP_FOOTPRINT: // move to other side
GetBoard()->Change_Side_Module(module, DC); Change_Side_Module(module, DC);
break; break;
case HK_DRAG_FOOTPRINT: // Start move (and drag) module case HK_DRAG_FOOTPRINT: // Start move (and drag) module
......
...@@ -83,7 +83,7 @@ void WinEDA_ModuleEditFrame::Load_Module_From_BOARD( MODULE* Module ) ...@@ -83,7 +83,7 @@ void WinEDA_ModuleEditFrame::Load_Module_From_BOARD( MODULE* Module )
GetScreen()->m_Curseur.x = GetScreen()->m_Curseur.y = 0; GetScreen()->m_Curseur.x = GetScreen()->m_Curseur.y = 0;
Place_Module( Module, NULL ); Place_Module( Module, NULL );
if( Module->GetLayer() != CMP_N ) if( Module->GetLayer() != CMP_N )
GetBoard()->Change_Side_Module( Module, NULL ); Module->Flip( Module->m_Pos );
Rotate_Module( NULL, Module, 0, FALSE ); Rotate_Module( NULL, Module, 0, FALSE );
GetScreen()->ClrModify(); GetScreen()->ClrModify();
Zoom_Automatique( TRUE ); Zoom_Automatique( TRUE );
......
...@@ -291,10 +291,14 @@ void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event ) ...@@ -291,10 +291,14 @@ void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event )
if( source_module ) // this is an update command if( source_module ) // this is an update command
{ {
// The new module replace the old module (pos, orient, ref, value and connexions are kept) // In the main board,
// the new module replace the old module (pos, orient, ref, value and connexions are kept)
// and the source_module (old module) is deleted // and the source_module (old module) is deleted
newmodule = pcbframe->Exchange_Module( this, source_module, newmodule ); PICKED_ITEMS_LIST pickList;
pcbframe->Exchange_Module( source_module, newmodule, &pickList );
newmodule->m_TimeStamp = module_in_edit->m_Link; newmodule->m_TimeStamp = module_in_edit->m_Link;
if( pickList.GetCount() )
pcbframe->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
} }
else // This is an insert command else // This is an insert command
{ {
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
static void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC ); static void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC );
/* Variables locales : */ /* Variables locales : */
static int ModuleInitOrient; // Lors des moves, val init de l'orient (pour annulation) static MODULE* s_ModuleInitialCopy = NULL; // Copy of module for abort/undo command
static int ModuleInitLayer; // Lors des moves, val init de la couche (pour annulation) static PICKED_ITEMS_LIST s_PickedList; // a picked list to save initial module and dragged tracks
/*************************************************************************/ /*************************************************************************/
...@@ -102,11 +102,18 @@ void WinEDA_PcbFrame::StartMove_Module( MODULE* module, wxDC* DC ) ...@@ -102,11 +102,18 @@ void WinEDA_PcbFrame::StartMove_Module( MODULE* module, wxDC* DC )
if( module == NULL ) if( module == NULL )
return; return;
if( s_ModuleInitialCopy )
delete s_ModuleInitialCopy;
s_PickedList.ClearItemsList(); // Should be empty, but...
// Creates a copy of the cuttent module, for abort and undo commands
s_ModuleInitialCopy = new MODULE( GetBoard());
s_ModuleInitialCopy->Copy( module );
s_ModuleInitialCopy->m_Flags = 0;
SetCurItem( module ); SetCurItem( module );
GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK; GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
module->m_Flags |= IS_MOVED; module->m_Flags |= IS_MOVED;
ModuleInitOrient = module->m_Orient;
ModuleInitLayer = module->GetLayer();
GetScreen()->m_Curseur = module->m_Pos; GetScreen()->m_Curseur = module->m_Pos;
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
...@@ -123,6 +130,15 @@ void WinEDA_PcbFrame::StartMove_Module( MODULE* module, wxDC* DC ) ...@@ -123,6 +130,15 @@ void WinEDA_PcbFrame::StartMove_Module( MODULE* module, wxDC* DC )
if( g_Drag_Pistes_On ) if( g_Drag_Pistes_On )
{ {
Build_Drag_Liste( DrawPanel, DC, module ); Build_Drag_Liste( DrawPanel, DC, module );
ITEM_PICKER itemWrapper(NULL, UR_CHANGED);
for( DRAG_SEGM* pt_drag = g_DragSegmentList; pt_drag != NULL; pt_drag = pt_drag->Pnext )
{
TRACK * segm = pt_drag->m_Segm;
itemWrapper.m_PickedItem = segm;
itemWrapper.m_Link = segm->Copy();
itemWrapper.m_Link->SetState( EDIT, OFF );
s_PickedList.PushItem(itemWrapper);
}
} }
GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST; GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST;
...@@ -154,7 +170,7 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC ) ...@@ -154,7 +170,7 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC )
DRAG_SEGM* pt_drag; DRAG_SEGM* pt_drag;
TRACK* pt_segm; TRACK* pt_segm;
MODULE* module; MODULE* module;
WinEDA_BasePcbFrame* pcbframe = (WinEDA_BasePcbFrame*) Panel->m_Parent; WinEDA_PcbFrame* pcbframe = (WinEDA_PcbFrame*) Panel->m_Parent;
module = (MODULE*) pcbframe->GetScreen()->GetCurItem(); module = (MODULE*) pcbframe->GetScreen()->GetCurItem();
pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK; pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
...@@ -203,12 +219,12 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC ) ...@@ -203,12 +219,12 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC )
} }
/* Reaffichage du module a l'ecran */ /* Reaffichage du module a l'ecran */
if( module ) if( module && s_ModuleInitialCopy )
{ {
if( ModuleInitOrient != module->m_Orient ) if( s_ModuleInitialCopy->m_Orient != module->m_Orient )
pcbframe->Rotate_Module( NULL, module, ModuleInitOrient, FALSE ); pcbframe->Rotate_Module( NULL, module, s_ModuleInitialCopy->m_Orient, FALSE );
if( ModuleInitLayer != module->GetLayer() ) if( s_ModuleInitialCopy->GetLayer() != module->GetLayer() )
pcbframe->GetBoard()->Change_Side_Module( module, NULL ); pcbframe->Change_Side_Module( module, NULL );
module->Draw( Panel, DC, GR_OR ); module->Draw( Panel, DC, GR_OR );
} }
g_Drag_Pistes_On = FALSE; g_Drag_Pistes_On = FALSE;
...@@ -216,6 +232,10 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC ) ...@@ -216,6 +232,10 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC )
Panel->ForceCloseManageCurseur = NULL; Panel->ForceCloseManageCurseur = NULL;
pcbframe->SetCurItem( NULL ); pcbframe->SetCurItem( NULL );
delete s_ModuleInitialCopy;
s_ModuleInitialCopy = NULL;
s_PickedList.ClearListAndDeleteItems();
pcbframe->GetBoard()->m_Status_Pcb &= ~DO_NOT_SHOW_GENERAL_RASTNEST; // Display ratsnest is allowed pcbframe->GetBoard()->m_Status_Pcb &= ~DO_NOT_SHOW_GENERAL_RASTNEST; // Display ratsnest is allowed
if( g_Show_Ratsnest ) if( g_Show_Ratsnest )
pcbframe->DrawGeneralRatsnest( DC ); pcbframe->DrawGeneralRatsnest( DC );
...@@ -290,7 +310,7 @@ bool WinEDA_PcbFrame::Delete_Module( MODULE* module, wxDC* DC, bool aAskBeforeDe ...@@ -290,7 +310,7 @@ bool WinEDA_PcbFrame::Delete_Module( MODULE* module, wxDC* DC, bool aAskBeforeDe
/** /**
* Function Delete Module * Function Delete Module
* Remove a footprint from m_Modules linked list and put it in undelete buffer * Remove a footprint from m_Modules linked list and put it in undelete buffer
* The net rastenes and pad list are recalcualed * The rastnest and pad list are recalcualed
* @param module = footprint to delete * @param module = footprint to delete
* @param DC = currentDevice Context. if NULL: do not redraw new ratsnets and dirty rectange * @param DC = currentDevice Context. if NULL: do not redraw new ratsnets and dirty rectange
* @param aPromptBeforeDeleting : if true: ask for confirmation before deleting * @param aPromptBeforeDeleting : if true: ask for confirmation before deleting
...@@ -340,7 +360,7 @@ bool WinEDA_PcbFrame::Delete_Module( MODULE* module, wxDC* DC, bool aAskBeforeDe ...@@ -340,7 +360,7 @@ bool WinEDA_PcbFrame::Delete_Module( MODULE* module, wxDC* DC, bool aAskBeforeDe
/****************************************************************************/ /****************************************************************************/
void BOARD::Change_Side_Module( MODULE* Module, wxDC* DC ) void WinEDA_PcbFrame::Change_Side_Module( MODULE* Module, wxDC* DC )
/****************************************************************************/ /****************************************************************************/
/** /**
...@@ -359,22 +379,22 @@ void BOARD::Change_Side_Module( MODULE* Module, wxDC* DC ) ...@@ -359,22 +379,22 @@ void BOARD::Change_Side_Module( MODULE* Module, wxDC* DC )
if( (Module->GetLayer() != CMP_N) && (Module->GetLayer() != COPPER_LAYER_N) ) if( (Module->GetLayer() != CMP_N) && (Module->GetLayer() != COPPER_LAYER_N) )
return; return;
m_PcbFrame->GetScreen()->SetModify(); GetScreen()->SetModify();
if( !(Module->m_Flags & IS_MOVED) ) if( !(Module->m_Flags & IS_MOVED) ) /* This is a simple flip, no other edition in progress */
{ {
m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK); GetBoard()->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK);
if( DC && m_PcbFrame ) if( DC )
{ {
int tmp = Module->m_Flags; int tmp = Module->m_Flags;
Module->m_Flags |= DO_NOT_DRAW; Module->m_Flags |= DO_NOT_DRAW;
m_PcbFrame->DrawPanel->PostDirtyRect( Module->GetBoundingBox() ); DrawPanel->PostDirtyRect( Module->GetBoundingBox() );
Module->m_Flags = tmp; Module->m_Flags = tmp;
} }
/* Effacement chevelu general si necessaire */ /* Effacement chevelu general si necessaire */
if( DC && g_Show_Ratsnest ) if( DC && g_Show_Ratsnest )
m_PcbFrame->DrawGeneralRatsnest( DC ); DrawGeneralRatsnest( DC );
/* Init des variables utilisees dans la routine Dessine_Drag_segment() */ /* Init des variables utilisees dans la routine Dessine_Drag_segment() */
g_Offset_Module.x = 0; g_Offset_Module.x = 0;
...@@ -383,37 +403,36 @@ void BOARD::Change_Side_Module( MODULE* Module, wxDC* DC ) ...@@ -383,37 +403,36 @@ void BOARD::Change_Side_Module( MODULE* Module, wxDC* DC )
else // Module en deplacement else // Module en deplacement
{ {
/* efface empreinte ( vue en contours) si elle a ete deja dessinee */ /* efface empreinte ( vue en contours) si elle a ete deja dessinee */
if( DC && m_PcbFrame ) if( DC )
{ {
DrawModuleOutlines( m_PcbFrame->DrawPanel, DC, Module ); DrawModuleOutlines( DrawPanel, DC, Module );
Dessine_Segments_Dragges( m_PcbFrame->DrawPanel, DC ); Dessine_Segments_Dragges( DrawPanel, DC );
} }
} }
/* Flip the module */ /* Flip the module */
Module->Flip( Module->m_Pos ); Module->Flip( Module->m_Pos );
if( m_PcbFrame ) Module->DisplayInfo( this );
Module->DisplayInfo( m_PcbFrame );
if( !(Module->m_Flags & IS_MOVED) ) /* Inversion simple */ if( !(Module->m_Flags & IS_MOVED) ) /* Inversion simple */
{ {
if( DC && m_PcbFrame ) if( DC )
{ {
Module->Draw( m_PcbFrame->DrawPanel, DC, GR_OR ); Module->Draw( DrawPanel, DC, GR_OR );
/* affichage chevelu general si necessaire */ /* affichage chevelu general si necessaire */
m_PcbFrame->Compile_Ratsnest( DC, true ); Compile_Ratsnest( DC, true );
} }
} }
else else
{ {
if( DC && m_PcbFrame ) if( DC )
{ {
DrawModuleOutlines( m_PcbFrame->DrawPanel, DC, Module ); DrawModuleOutlines( DrawPanel, DC, Module );
Dessine_Segments_Dragges( m_PcbFrame->DrawPanel, DC ); Dessine_Segments_Dragges( DrawPanel, DC );
} }
m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK; GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
} }
} }
...@@ -425,14 +444,13 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec ...@@ -425,14 +444,13 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec
/* Place a l'endroit pointe par la souris le module deja existant selectionne /* Place a l'endroit pointe par la souris le module deja existant selectionne
* auparavant. * auparavant.
* Entree: module = num du module a replacer * Entree: module = num du module a replacer
* DC ( si NULL: pas d'affichage a l'ran * DC ( si NULL: pas d'affichage a l'ecran
* Sortie : * Sortie :
* mise a jour des nouvelles coord des differents elements du module * mise a jour des nouvelles coord des differents elements du module
* affichage a l'ecran du module * affichage a l'ecran du module
*/ */
{ {
TRACK* pt_segm; TRACK* pt_segm;
DRAG_SEGM* pt_drag;
wxPoint newpos; wxPoint newpos;
if( module == 0 ) if( module == 0 )
...@@ -441,6 +459,27 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec ...@@ -441,6 +459,27 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec
GetScreen()->SetModify(); GetScreen()->SetModify();
GetBoard()->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK); GetBoard()->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK);
if( (module->m_Flags & IS_NEW ) )
{
SaveCopyInUndoList(module, UR_NEW);
}
else if( (module->m_Flags & IS_MOVED ) )
{
ITEM_PICKER picker(module, UR_CHANGED);
picker.m_Link = s_ModuleInitialCopy;
s_PickedList.PushItem(picker);
s_ModuleInitialCopy = NULL; // the picker is now owner of s_ModuleInitialCopy.
}
if ( s_PickedList.GetCount() )
{
SaveCopyInUndoList(s_PickedList, UR_UNSPECIFIED);
// Clear list, but DO NOT delete items,
// because they are owned by the saved undo list and they therefore in use
s_PickedList.ClearItemsList();
}
if( g_Show_Module_Ratsnest && (GetBoard()->m_Status_Pcb & LISTE_PAD_OK) && DC ) if( g_Show_Module_Ratsnest && (GetBoard()->m_Status_Pcb & LISTE_PAD_OK) && DC )
trace_ratsnest_module( DC ); trace_ratsnest_module( DC );
...@@ -450,11 +489,11 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec ...@@ -450,11 +489,11 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec
if( DC ) if( DC )
module->Draw( DrawPanel, DC, GR_OR ); module->Draw( DrawPanel, DC, GR_OR );
/* Tracage des segments dragges et liberation memoire */
if( g_DragSegmentList ) if( g_DragSegmentList )
{ {
pt_drag = g_DragSegmentList; /* Redraw dragged track segments */
for( ; pt_drag != NULL; pt_drag = pt_drag->Pnext ) for( DRAG_SEGM* pt_drag = g_DragSegmentList; pt_drag != NULL; pt_drag = pt_drag->Pnext )
{ {
pt_segm = pt_drag->m_Segm; pt_segm = pt_drag->m_Segm;
pt_segm->SetState( EDIT, OFF ); pt_segm->SetState( EDIT, OFF );
...@@ -462,9 +501,9 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec ...@@ -462,9 +501,9 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec
pt_segm->Draw( DrawPanel, DC, GR_OR ); pt_segm->Draw( DrawPanel, DC, GR_OR );
} }
// Delete drag list
EraseDragListe(); EraseDragListe();
} }
if( !aDoNotRecreateRatsnest ) if( !aDoNotRecreateRatsnest )
Compile_Ratsnest( DC, true ); Compile_Ratsnest( DC, true );
...@@ -477,6 +516,9 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec ...@@ -477,6 +516,9 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec
DrawPanel->ForceCloseManageCurseur = NULL; DrawPanel->ForceCloseManageCurseur = NULL;
module->m_Flags = 0; module->m_Flags = 0;
g_Drag_Pistes_On = FALSE; g_Drag_Pistes_On = FALSE;
delete s_ModuleInitialCopy;
s_ModuleInitialCopy = NULL;
} }
...@@ -498,10 +540,9 @@ void WinEDA_BasePcbFrame::Rotate_Module( wxDC* DC, MODULE* module, ...@@ -498,10 +540,9 @@ void WinEDA_BasePcbFrame::Rotate_Module( wxDC* DC, MODULE* module,
GetScreen()->SetModify(); GetScreen()->SetModify();
/* efface ancienne position */ if( !(module->m_Flags & IS_MOVED) ) /* This is a simple rotation, no other edition in progress */
if( !(module->m_Flags & IS_MOVED) ) /* Rotation simple */
{ {
if( DC ) if( DC ) // Erase footprint to screen
{ {
int tmp = module->m_Flags; int tmp = module->m_Flags;
module->m_Flags |= DO_NOT_DRAW; module->m_Flags |= DO_NOT_DRAW;
......
...@@ -475,7 +475,10 @@ MODULE* ReadNetModule( WinEDA_PcbFrame* aFrame, ...@@ -475,7 +475,10 @@ MODULE* ReadNetModule( WinEDA_PcbFrame* aFrame,
MODULE* NewModule = MODULE* NewModule =
aFrame->Get_Librairie_Module( wxEmptyString, NameLibCmp, true ); aFrame->Get_Librairie_Module( wxEmptyString, NameLibCmp, true );
if( NewModule ) /* Change old module to the new module (and delete the old one)*/ if( NewModule ) /* Change old module to the new module (and delete the old one)*/
Module = aFrame->Exchange_Module( NULL, Module, NewModule ); {
aFrame->Exchange_Module( Module, NewModule, NULL );
Module = NewModule;
}
} }
else else
{ {
......
...@@ -22,75 +22,7 @@ ...@@ -22,75 +22,7 @@
/* Bitmaps */ /* Bitmaps */
#include "bitmaps.h" #include "bitmaps.h"
static wxMenu* Append_Track_Width_List();
/********************************************/
static wxMenu* Append_Track_Width_List()
/********************************************/
/* create a wxMenu * which shows the last used track widths and via diameters
* @return a pointeur to the menu
*/
{
#define TRACK_HISTORY_NUMBER_MAX 6
#define VIA_HISTORY_NUMBER_MAX 4
int ii;
wxString msg;
wxMenu* trackwidth_menu;
double value;
trackwidth_menu = new wxMenu;
ADD_MENUITEM( trackwidth_menu, ID_PCB_TRACK_SIZE_SETUP,
_( "New Width/Size" ), showtrack_xpm );
trackwidth_menu->Append( ID_POPUP_PCB_SELECT_AUTO_WIDTH,
_( "Auto Width" ),
_(
"Use the track width when starting on a track, otherwise the current track width" ),
TRUE );
if( g_DesignSettings.m_UseConnectedTrackWidth )
trackwidth_menu->Check( ID_POPUP_PCB_SELECT_AUTO_WIDTH, TRUE );
for( ii = 0; (ii < HISTORY_NUMBER) && (ii < TRACK_HISTORY_NUMBER_MAX); ii++ )
{
if( g_DesignSettings.m_TrackWidthHistory[ii] == 0 )
break;
value = To_User_Unit( g_UnitMetric,
g_DesignSettings.m_TrackWidthHistory[ii],
PCB_INTERNAL_UNIT );
if( g_UnitMetric == INCHES ) // Affichage en mils
msg.Printf( _( "Track %.1f" ), value * 1000 );
else
msg.Printf( _( "Track %.3f" ), value );
trackwidth_menu->Append( ID_POPUP_PCB_SELECT_WIDTH1 + ii, msg, wxEmptyString, TRUE );
if( (g_DesignSettings.m_TrackWidthHistory[ii] == g_DesignSettings.m_CurrentTrackWidth)
&& !g_DesignSettings.m_UseConnectedTrackWidth )
trackwidth_menu->Check( ID_POPUP_PCB_SELECT_WIDTH1 + ii, TRUE );
}
trackwidth_menu->AppendSeparator();
for( ii = 0; (ii < HISTORY_NUMBER) && (ii < VIA_HISTORY_NUMBER_MAX); ii++ )
{
if( g_DesignSettings.m_ViaSizeHistory[ii] == 0 )
break;
value = To_User_Unit( g_UnitMetric,
g_DesignSettings.m_ViaSizeHistory[ii],
PCB_INTERNAL_UNIT );
if( g_UnitMetric == INCHES )
msg.Printf( _( "Via %.1f" ), value * 1000 );
else
msg.Printf( _( "Via %.3f" ), value );
trackwidth_menu->Append( ID_POPUP_PCB_SELECT_VIASIZE1 + ii, msg, wxEmptyString, TRUE );
if( g_DesignSettings.m_ViaSizeHistory[ii] == g_DesignSettings.m_CurrentViaSize )
trackwidth_menu->Check( ID_POPUP_PCB_SELECT_VIASIZE1 + ii, TRUE );
}
return trackwidth_menu;
}
/******************************************************************************/ /******************************************************************************/
...@@ -733,18 +665,18 @@ void WinEDA_PcbFrame::createPopUpMenuForFootprints( MODULE* aModule, wxMenu* men ...@@ -733,18 +665,18 @@ void WinEDA_PcbFrame::createPopUpMenuForFootprints( MODULE* aModule, wxMenu* men
msg, drag_module_xpm ); msg, drag_module_xpm );
} }
msg = AddHotkeyName( _( "Rotate +" ), s_Board_Editor_Hokeys_Descr, HK_ROTATE_FOOTPRINT ); msg = AddHotkeyName( _( "Rotate +" ), s_Board_Editor_Hokeys_Descr, HK_ROTATE_FOOTPRINT );
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_ROTATE_MODULE_CLOCKWISE,
msg, rotate_module_pos_xpm );
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_ROTATE_MODULE_COUNTERCLOCKWISE, ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_ROTATE_MODULE_COUNTERCLOCKWISE,
msg, rotate_module_pos_xpm );
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_ROTATE_MODULE_CLOCKWISE,
_( "Rotate -" ), rotate_module_neg_xpm ); _( "Rotate -" ), rotate_module_neg_xpm );
msg = AddHotkeyName( _( "Flip" ), s_Board_Editor_Hokeys_Descr, HK_FLIP_FOOTPRINT ); msg = AddHotkeyName( _( "Flip" ), s_Board_Editor_Hokeys_Descr, HK_FLIP_FOOTPRINT );
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_CHANGE_SIDE_MODULE, ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_CHANGE_SIDE_MODULE,
msg, invert_module_xpm ); msg, invert_module_xpm );
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_EDIT_MODULE,
_( "Edit" ), edit_module_xpm );
if( !flags ) if( !flags )
{ {
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_EDIT_MODULE,
_( "Edit" ), edit_module_xpm );
sub_menu_footprint->AppendSeparator(); sub_menu_footprint->AppendSeparator();
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_DELETE_MODULE, ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_DELETE_MODULE,
_( "Delete Module" ), delete_module_xpm ); _( "Delete Module" ), delete_module_xpm );
...@@ -887,3 +819,73 @@ void WinEDA_PcbFrame::createPopUpMenuForMarkers( MARKER_PCB* aMarker, wxMenu* aP ...@@ -887,3 +819,73 @@ void WinEDA_PcbFrame::createPopUpMenuForMarkers( MARKER_PCB* aMarker, wxMenu* aP
ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_DELETE_MARKER, _( "Delete Marker" ), delete_xpm ); ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_DELETE_MARKER, _( "Delete Marker" ), delete_xpm );
ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_GETINFO_MARKER, _( "Marker Error Info" ), info_xpm ); ADD_MENUITEM( aPopMenu, ID_POPUP_PCB_GETINFO_MARKER, _( "Marker Error Info" ), info_xpm );
} }
/********************************************/
static wxMenu* Append_Track_Width_List()
/********************************************/
/* create a wxMenu * which shows the last used track widths and via diameters
* @return a pointeur to the menu
*/
{
#define TRACK_HISTORY_NUMBER_MAX 6
#define VIA_HISTORY_NUMBER_MAX 4
int ii;
wxString msg;
wxMenu* trackwidth_menu;
double value;
trackwidth_menu = new wxMenu;
ADD_MENUITEM( trackwidth_menu, ID_PCB_TRACK_SIZE_SETUP,
_( "New Width/Size" ), showtrack_xpm );
trackwidth_menu->Append( ID_POPUP_PCB_SELECT_AUTO_WIDTH,
_( "Auto Width" ),
_(
"Use the track width when starting on a track, otherwise the current track width" ),
TRUE );
if( g_DesignSettings.m_UseConnectedTrackWidth )
trackwidth_menu->Check( ID_POPUP_PCB_SELECT_AUTO_WIDTH, TRUE );
for( ii = 0; (ii < HISTORY_NUMBER) && (ii < TRACK_HISTORY_NUMBER_MAX); ii++ )
{
if( g_DesignSettings.m_TrackWidthHistory[ii] == 0 )
break;
value = To_User_Unit( g_UnitMetric,
g_DesignSettings.m_TrackWidthHistory[ii],
PCB_INTERNAL_UNIT );
if( g_UnitMetric == INCHES ) // Affichage en mils
msg.Printf( _( "Track %.1f" ), value * 1000 );
else
msg.Printf( _( "Track %.3f" ), value );
trackwidth_menu->Append( ID_POPUP_PCB_SELECT_WIDTH1 + ii, msg, wxEmptyString, TRUE );
if( (g_DesignSettings.m_TrackWidthHistory[ii] == g_DesignSettings.m_CurrentTrackWidth)
&& !g_DesignSettings.m_UseConnectedTrackWidth )
trackwidth_menu->Check( ID_POPUP_PCB_SELECT_WIDTH1 + ii, TRUE );
}
trackwidth_menu->AppendSeparator();
for( ii = 0; (ii < HISTORY_NUMBER) && (ii < VIA_HISTORY_NUMBER_MAX); ii++ )
{
if( g_DesignSettings.m_ViaSizeHistory[ii] == 0 )
break;
value = To_User_Unit( g_UnitMetric,
g_DesignSettings.m_ViaSizeHistory[ii],
PCB_INTERNAL_UNIT );
if( g_UnitMetric == INCHES )
msg.Printf( _( "Via %.1f" ), value * 1000 );
else
msg.Printf( _( "Via %.3f" ), value );
trackwidth_menu->Append( ID_POPUP_PCB_SELECT_VIASIZE1 + ii, msg, wxEmptyString, TRUE );
if( g_DesignSettings.m_ViaSizeHistory[ii] == g_DesignSettings.m_CurrentViaSize )
trackwidth_menu->Check( ID_POPUP_PCB_SELECT_VIASIZE1 + ii, TRUE );
}
return trackwidth_menu;
}
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "specctra.h" #include "specctra.h"
#include "collectors.h" #include "collectors.h"
#include "wxPcbStruct.h" // Change_Side_Module() #include "wxPcbStruct.h"
#include "pcbstruct.h" // HISTORY_NUMBER #include "pcbstruct.h" // HISTORY_NUMBER
#include "confirm.h" // DisplayError() #include "confirm.h" // DisplayError()
#include "gestfich.h" // EDA_FileSelector() #include "gestfich.h" // EDA_FileSelector()
...@@ -113,7 +113,7 @@ void WinEDA_PcbFrame::ExportToSpecctra( wxCommandEvent& event ) ...@@ -113,7 +113,7 @@ void WinEDA_PcbFrame::ExportToSpecctra( wxCommandEvent& event )
db.RevertMODULEs( GetBoard() ); db.RevertMODULEs( GetBoard() );
// The two calls below to BOARD::Change_Side_Module(), both set the // The two calls below to MODULE::Flip(), both set the
// modified flag, yet their actions cancel each other out, so it should // modified flag, yet their actions cancel each other out, so it should
// be ok to clear the modify flag. // be ok to clear the modify flag.
if( !wasModified ) if( !wasModified )
...@@ -1451,7 +1451,7 @@ void SPECCTRA_DB::FlipMODULEs( BOARD* aBoard ) ...@@ -1451,7 +1451,7 @@ void SPECCTRA_DB::FlipMODULEs( BOARD* aBoard )
module->flag = 0; module->flag = 0;
if( module->GetLayer() == COPPER_LAYER_N ) if( module->GetLayer() == COPPER_LAYER_N )
{ {
aBoard->Change_Side_Module( module, NULL ); module->Flip( module->m_Pos );
module->flag = 1; module->flag = 1;
} }
} }
...@@ -1471,7 +1471,7 @@ void SPECCTRA_DB::RevertMODULEs( BOARD* aBoard ) ...@@ -1471,7 +1471,7 @@ void SPECCTRA_DB::RevertMODULEs( BOARD* aBoard )
{ {
if( module->flag ) if( module->flag )
{ {
aBoard->Change_Side_Module( module, NULL ); module->Flip( module->m_Pos );
module->flag = 0; module->flag = 0;
} }
} }
......
...@@ -413,7 +413,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError ) ...@@ -413,7 +413,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError )
if( module->GetLayer() != CMP_N ) if( module->GetLayer() != CMP_N )
{ {
// module is on copper layer (back) // module is on copper layer (back)
aBoard->Change_Side_Module( module, 0 ); module->Flip( module->m_Pos );
} }
module->SetOrientation( orientation ); module->SetOrientation( orientation );
} }
...@@ -423,7 +423,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError ) ...@@ -423,7 +423,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError )
if( module->GetLayer() != COPPER_LAYER_N ) if( module->GetLayer() != COPPER_LAYER_N )
{ {
// module is on component layer (front) // module is on component layer (front)
aBoard->Change_Side_Module( module, 0 ); module->Flip( module->m_Pos );
} }
module->SetOrientation( orientation ); module->SetOrientation( orientation );
} }
......
...@@ -25,13 +25,13 @@ class DIALOG_EXCHANGE_MODULE : public DIALOG_EXCHANGE_MODULE_BASE ...@@ -25,13 +25,13 @@ class DIALOG_EXCHANGE_MODULE : public DIALOG_EXCHANGE_MODULE_BASE
{ {
private: private:
WinEDA_BasePcbFrame* m_Parent; WinEDA_PcbFrame* m_Parent;
MODULE* m_CurrentModule; MODULE* m_CurrentModule;
public: public:
// Constructor and destructor // Constructor and destructor
DIALOG_EXCHANGE_MODULE( WinEDA_BasePcbFrame* aParent, MODULE* aModule ); DIALOG_EXCHANGE_MODULE( WinEDA_PcbFrame* aParent, MODULE* aModule );
~DIALOG_EXCHANGE_MODULE() { }; ~DIALOG_EXCHANGE_MODULE() { };
private: private:
...@@ -46,13 +46,14 @@ private: ...@@ -46,13 +46,14 @@ private:
void Change_ModuleAll(); void Change_ModuleAll();
int Maj_ListeCmp( const wxString& reference, const wxString& old_name, int Maj_ListeCmp( const wxString& reference, const wxString& old_name,
const wxString& new_name, bool ShowError ); const wxString& new_name, bool ShowError );
MODULE* Change_1_Module( MODULE* Module, bool Change_1_Module( MODULE* Module,
const wxString& new_module, const wxString& new_module,
PICKED_ITEMS_LIST* aUndoPickList,
bool ShowError ); bool ShowError );
}; };
DIALOG_EXCHANGE_MODULE::DIALOG_EXCHANGE_MODULE( WinEDA_BasePcbFrame* parent, MODULE* Module ) : DIALOG_EXCHANGE_MODULE::DIALOG_EXCHANGE_MODULE( WinEDA_PcbFrame* parent, MODULE* Module ) :
DIALOG_EXCHANGE_MODULE_BASE( parent ) DIALOG_EXCHANGE_MODULE_BASE( parent )
{ {
m_Parent = parent; m_Parent = parent;
...@@ -63,7 +64,7 @@ DIALOG_EXCHANGE_MODULE::DIALOG_EXCHANGE_MODULE( WinEDA_BasePcbFrame* parent, MOD ...@@ -63,7 +64,7 @@ DIALOG_EXCHANGE_MODULE::DIALOG_EXCHANGE_MODULE( WinEDA_BasePcbFrame* parent, MOD
} }
void WinEDA_BasePcbFrame::InstallExchangeModuleFrame( MODULE* Module ) void WinEDA_PcbFrame::InstallExchangeModuleFrame( MODULE* Module )
{ {
DIALOG_EXCHANGE_MODULE dialog( this, Module ); DIALOG_EXCHANGE_MODULE dialog( this, Module );
...@@ -195,7 +196,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference, ...@@ -195,7 +196,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
fprintf( NewFile, "Cmp-Mod V01 Genere par PcbNew le %s\n", fprintf( NewFile, "Cmp-Mod V01 Genere par PcbNew le %s\n",
DateAndTime( Line ) ); DateAndTime( Line ) );
bool start_descr = FALSE; bool start_descr = false;
while( fgets( Line, sizeof(Line), FichCmp ) != NULL ) while( fgets( Line, sizeof(Line), FichCmp ) != NULL )
{ {
if( strnicmp( Line, "Reference = ", 9 ) == 0 ) if( strnicmp( Line, "Reference = ", 9 ) == 0 )
...@@ -212,7 +213,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference, ...@@ -212,7 +213,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
if( (strnicmp( Line, "Begin", 5 ) == 0) if( (strnicmp( Line, "Begin", 5 ) == 0)
|| (strnicmp( Line, "End", 3 ) == 0) ) || (strnicmp( Line, "End", 3 ) == 0) )
{ {
start_descr = FALSE; start_descr = false;
} }
if( start_descr && strnicmp( Line, "IdModule", 8 ) == 0 ) if( start_descr && strnicmp( Line, "IdModule", 8 ) == 0 )
...@@ -222,7 +223,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference, ...@@ -222,7 +223,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
msg = wxT( " * in <" ) + fn.GetFullPath() + wxT( ">.\n" ); msg = wxT( " * in <" ) + fn.GetFullPath() + wxT( ">.\n" );
m_WinMessages->AppendText( msg ); m_WinMessages->AppendText( msg );
start_descr = FALSE; start_descr = false;
} }
fputs( Line, NewFile ); fputs( Line, NewFile );
} }
...@@ -250,11 +251,16 @@ void DIALOG_EXCHANGE_MODULE::Change_Module() ...@@ -250,11 +251,16 @@ void DIALOG_EXCHANGE_MODULE::Change_Module()
if( newmodulename == wxEmptyString ) if( newmodulename == wxEmptyString )
return; return;
if( Change_1_Module( m_CurrentModule, newmodulename, true ) ) PICKED_ITEMS_LIST pickList;
if( Change_1_Module( m_CurrentModule, newmodulename, &pickList, true ) )
{ {
m_Parent->Compile_Ratsnest( NULL, true ); m_Parent->Compile_Ratsnest( NULL, true );
m_Parent->DrawPanel->Refresh(); m_Parent->DrawPanel->Refresh();
} }
if( pickList.GetCount() )
m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
} }
...@@ -273,10 +279,10 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue ) ...@@ -273,10 +279,10 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
{ {
wxString msg; wxString msg;
MODULE* Module, * PtBack; MODULE* Module, * PtBack;
bool change = FALSE; bool change = false;
wxString newmodulename = m_NewModule->GetValue(); wxString newmodulename = m_NewModule->GetValue();
wxString value, lib_reference; wxString value, lib_reference;
bool check_module_value = FALSE; bool check_module_value = false;
int ShowErr = 3; // Affiche 3 messages d'err maxi int ShowErr = 3; // Affiche 3 messages d'err maxi
if( m_Parent->GetBoard()->m_Modules == NULL ) if( m_Parent->GetBoard()->m_Modules == NULL )
...@@ -307,12 +313,12 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue ) ...@@ -307,12 +313,12 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
* Change_1_Module() modifie le dernier module de la liste * Change_1_Module() modifie le dernier module de la liste
*/ */
PICKED_ITEMS_LIST pickList;
/* note: for the first module in chain (the last here), Module->Back() points the board or is NULL /* note: for the first module in chain (the last here), Module->Back() points the board or is NULL
*/ */
Module = m_Parent->GetBoard()->m_Modules.GetLast(); Module = m_Parent->GetBoard()->m_Modules.GetLast();
for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack ) for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack )
{ {
MODULE* module;
PtBack = Module->Back(); PtBack = Module->Back();
if( lib_reference.CmpNoCase( Module->m_LibRef ) != 0 ) if( lib_reference.CmpNoCase( Module->m_LibRef ) != 0 )
continue; continue;
...@@ -321,8 +327,7 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue ) ...@@ -321,8 +327,7 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
if( value.CmpNoCase( Module->m_Value->m_Text ) != 0 ) if( value.CmpNoCase( Module->m_Value->m_Text ) != 0 )
continue; continue;
} }
module = Change_1_Module( Module, newmodulename.GetData(), ShowErr ); if( Change_1_Module( Module, newmodulename.GetData(), &pickList, ShowErr ) )
if( module )
change = true; change = true;
else if( ShowErr ) else if( ShowErr )
ShowErr--; ShowErr--;
...@@ -333,6 +338,9 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue ) ...@@ -333,6 +338,9 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
m_Parent->Compile_Ratsnest( NULL, true ); m_Parent->Compile_Ratsnest( NULL, true );
m_Parent->DrawPanel->Refresh(); m_Parent->DrawPanel->Refresh();
} }
if( pickList.GetCount() )
m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
} }
...@@ -347,7 +355,7 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue ) ...@@ -347,7 +355,7 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
void DIALOG_EXCHANGE_MODULE::Change_ModuleAll() void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
{ {
MODULE* Module, * PtBack; MODULE* Module, * PtBack;
bool change = FALSE; bool change = false;
int ShowErr = 3; // Affiche 3 messages d'err maxi int ShowErr = 3; // Affiche 3 messages d'err maxi
if( m_Parent->GetBoard()->m_Modules == NULL ) if( m_Parent->GetBoard()->m_Modules == NULL )
...@@ -360,13 +368,15 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll() ...@@ -360,13 +368,15 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
* Change_1_Module() modifie le dernier module de la liste * Change_1_Module() modifie le dernier module de la liste
*/ */
PICKED_ITEMS_LIST pickList;
/* note: for the first module in chain (the last here), Module->Back() points the board or is NULL /* note: for the first module in chain (the last here), Module->Back() points the board or is NULL
*/ */
Module = m_Parent->GetBoard()->m_Modules.GetLast(); Module = m_Parent->GetBoard()->m_Modules.GetLast();
for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack ) for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack )
{ {
PtBack = Module->Back(); PtBack = Module->Back();
if( Change_1_Module( Module, Module->m_LibRef.GetData(), ShowErr ) ) if( Change_1_Module( Module, Module->m_LibRef.GetData(), &pickList, ShowErr ) )
change = true; change = true;
else if( ShowErr ) else if( ShowErr )
ShowErr--; ShowErr--;
...@@ -377,6 +387,8 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll() ...@@ -377,6 +387,8 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
m_Parent->Compile_Ratsnest( NULL, true ); m_Parent->Compile_Ratsnest( NULL, true );
m_Parent->DrawPanel->Refresh(); m_Parent->DrawPanel->Refresh();
} }
if( pickList.GetCount() )
m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
} }
...@@ -388,12 +400,13 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll() ...@@ -388,12 +400,13 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
* - memes textes valeur et ref * - memes textes valeur et ref
* - memes netnames pour pads de meme nom * - memes netnames pour pads de meme nom
* Retourne : * Retourne :
* 0 si pas de changement ( si le nouveau module n'est pas en libr) * false si pas de changement ( si le nouveau module n'est pas en libr)
* 1 si OK * true si OK
* Ratsnest *must be recalculated* after modules changes * Ratsnest *must be recalculated* after modules changes
*/ */
MODULE* DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module, bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module,
const wxString& new_module, const wxString& new_module,
PICKED_ITEMS_LIST* aUndoPickList,
bool ShowError ) bool ShowError )
{ {
wxString namecmp, oldnamecmp; wxString namecmp, oldnamecmp;
...@@ -401,7 +414,7 @@ MODULE* DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module, ...@@ -401,7 +414,7 @@ MODULE* DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module,
wxString Line; wxString Line;
if( Module == NULL ) if( Module == NULL )
return NULL; return false;
wxBusyCursor dummy; wxBusyCursor dummy;
...@@ -415,89 +428,91 @@ MODULE* DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module, ...@@ -415,89 +428,91 @@ MODULE* DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module,
m_WinMessages->AppendText( Line ); m_WinMessages->AppendText( Line );
namecmp.Trim( true ); namecmp.Trim( true );
namecmp.Trim( FALSE ); namecmp.Trim( false );
NewModule = m_Parent->Get_Librairie_Module( wxEmptyString, NewModule = m_Parent->Get_Librairie_Module( wxEmptyString,
namecmp, namecmp,
ShowError ); ShowError );
if( NewModule == NULL ) /* Nouveau module NON trouve, reaffichage de l'ancien */ if( NewModule == NULL ) /* Nouveau module NON trouve, reaffichage de l'ancien */
{ {
m_WinMessages->AppendText( wxT( "No\n" ) ); m_WinMessages->AppendText( wxT( "No\n" ) );
return NULL; return false;
} }
if( Module == m_CurrentModule ) if( Module == m_CurrentModule )
m_CurrentModule = NewModule; m_CurrentModule = NewModule;
m_WinMessages->AppendText( wxT( "Ok\n" ) ); m_WinMessages->AppendText( wxT( "Ok\n" ) );
m_Parent->Exchange_Module( this, Module, NewModule ); m_Parent->Exchange_Module( Module, NewModule, aUndoPickList );
Maj_ListeCmp( NewModule->m_Reference->m_Text, Maj_ListeCmp( NewModule->m_Reference->m_Text,
oldnamecmp, oldnamecmp,
namecmp, namecmp,
ShowError ); ShowError );
return NewModule; return true;
} }
/* /** function Exchange_Module
* Remplace le module OldModule par le module NewModule (en conservant * Replaces OldModule by NewModule, using OldModule settings:
* position, orientation..) * position, orientation, pad netnames ...)
* OldModule est supprim� de la memoire. * OldModule is deleted or put in undo list.
* @param aOldModule = footprint to replace
* @param aNewModule = footprint to put
* @param aUndoPickList = the undo list used to save OldModule. If null, OldModule is deleted
*/ */
MODULE* WinEDA_BasePcbFrame::Exchange_Module( wxWindow* winaff, void WinEDA_PcbFrame::Exchange_Module( MODULE* aOldModule,
MODULE* OldModule, MODULE* aNewModule,
MODULE* NewModule ) PICKED_ITEMS_LIST* aUndoPickList)
{ {
wxPoint oldpos; /* memorisation temporaire pos curseur */ wxPoint oldpos; /* memorisation temporaire pos curseur */
D_PAD* pad, * old_pad; D_PAD* pad, * old_pad;
if( (OldModule->Type() != TYPE_MODULE) if( (aOldModule->Type() != TYPE_MODULE) || (aNewModule->Type() != TYPE_MODULE) )
|| (NewModule->Type() != TYPE_MODULE) )
{ {
DisplayError( winaff, wxMessageBox( wxT( "WinEDA_PcbFrame::Exchange_Module() StuctType error" ) );
wxT( "WinEDA_BasePcbFrame::Exchange_Module() StuctType error" ) ); return;
} }
NewModule->SetParent( GetBoard() ); aNewModule->SetParent( GetBoard() );
GetBoard()->m_Status_Pcb = 0; GetBoard()->m_Status_Pcb = 0;
oldpos = GetScreen()->m_Curseur; oldpos = GetScreen()->m_Curseur;
GetScreen()->m_Curseur = OldModule->m_Pos; GetScreen()->m_Curseur = aOldModule->m_Pos;
/* place module without ratsnets refresh: this will be made later /* place module without ratsnets refresh: this will be made later
* when all modules are on board * when all modules are on board
*/ */
Place_Module( NewModule, NULL, true ); Place_Module( aNewModule, NULL, true );
GetScreen()->m_Curseur = oldpos; GetScreen()->m_Curseur = oldpos;
/* Flip footprint if needed */ /* Flip footprint if needed */
if( OldModule->GetLayer() != NewModule->GetLayer() ) if( aOldModule->GetLayer() != aNewModule->GetLayer() )
{ {
GetBoard()->Change_Side_Module( NewModule, NULL ); aNewModule->Flip( aNewModule->m_Pos );
} }
/* Rotate footprint if needed */ /* Rotate footprint if needed */
if( OldModule->m_Orient != NewModule->m_Orient ) if( aOldModule->m_Orient != aNewModule->m_Orient )
{ {
Rotate_Module( NULL, NewModule, OldModule->m_Orient, FALSE ); Rotate_Module( NULL, aNewModule, aOldModule->m_Orient, false );
} }
/* Update reference and value */ /* Update reference and value */
NewModule->m_Reference->m_Text = OldModule->m_Reference->m_Text; aNewModule->m_Reference->m_Text = aOldModule->m_Reference->m_Text;
NewModule->m_Value->m_Text = OldModule->m_Value->m_Text; aNewModule->m_Value->m_Text = aOldModule->m_Value->m_Text;
/* Mise a jour des autres parametres */ /* Mise a jour des autres parametres */
NewModule->m_TimeStamp = OldModule->m_TimeStamp; aNewModule->m_TimeStamp = aOldModule->m_TimeStamp;
NewModule->m_Path = OldModule->m_Path; aNewModule->m_Path = aOldModule->m_Path;
/* Update pad netnames ( when possible) */ /* Update pad netnames ( when possible) */
pad = NewModule->m_Pads; pad = aNewModule->m_Pads;
for( ; pad != NULL; pad = pad->Next() ) for( ; pad != NULL; pad = pad->Next() )
{ {
pad->SetNetname( wxEmptyString ); pad->SetNetname( wxEmptyString );
pad->SetNet( 0 ); pad->SetNet( 0 );
old_pad = OldModule->m_Pads; old_pad = aOldModule->m_Pads;
for( ; old_pad != NULL; old_pad = old_pad->Next() ) for( ; old_pad != NULL; old_pad = old_pad->Next() )
{ {
if( strnicmp( pad->m_Padname, old_pad->m_Padname, if( strnicmp( pad->m_Padname, old_pad->m_Padname,
...@@ -509,14 +524,20 @@ MODULE* WinEDA_BasePcbFrame::Exchange_Module( wxWindow* winaff, ...@@ -509,14 +524,20 @@ MODULE* WinEDA_BasePcbFrame::Exchange_Module( wxWindow* winaff,
} }
} }
/* Effacement de l'ancien module */ if( aUndoPickList )
OldModule->DeleteStructure(); {
GetBoard()->Remove(aOldModule);
ITEM_PICKER picker_old(aOldModule, UR_DELETED);
ITEM_PICKER picker_new(aNewModule, UR_NEW);
aUndoPickList->PushItem(picker_old);
aUndoPickList->PushItem(picker_new);
}
else /* Effacement de l'ancien module */
aOldModule->DeleteStructure();
GetBoard()->m_Status_Pcb = 0; GetBoard()->m_Status_Pcb = 0;
NewModule->m_Flags = 0; aNewModule->m_Flags = 0;
GetScreen()->SetModify(); GetScreen()->SetModify();
return NewModule;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment