More about pcbnew undo/redo

This commit is contained in:
charras 2009-08-06 07:11:04 +00:00
parent d9ea63a857
commit 5699ee3b91
20 changed files with 433 additions and 321 deletions

View File

@ -34,7 +34,7 @@
ITEM_PICKER::ITEM_PICKER( EDA_BaseStruct* aItem, UndoRedoOpType aUndoRedoStatus )
{
m_UndoRedoStatus = aUndoRedoStatus;
m_PickedItem = aItem;
m_PickedItem = aItem;
m_PickedItemType = TYPE_NOT_INIT;
m_Link = NULL;
}
@ -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 );
}
/** 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 item;
@ -69,19 +77,87 @@ ITEM_PICKER PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::PopItem()
}
void PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::ClearItemsList()
/* delete only the list of EDA_BaseStruct * pointers, NOT the pointed data itself
/** Function ClearItemsList
* delete only the list of pickers, NOT the picked data itself
*/
void PICKED_ITEMS_LIST::PICKED_ITEMS_LIST::ClearItemsList()
{
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()
{
for(unsigned ii = 0; ii < m_ItemsList.size(); ii++ )
delete m_ItemsList[ii].m_PickedItem;
m_ItemsList.clear();
bool show_error_message = true;
// 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()
ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx )
{
ITEM_PICKER picker;
if( aIdx < m_ItemsList.size() )
picker = m_ItemsList[aIdx];
return picker;
}
/** function GetPickedItem
* @return a pointer to the picked item, or null if does not exist
* @param aIdx = index of the picked item in the picked list
@ -181,11 +259,13 @@ bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_BaseStruct* aLink, unsigned aIdx
* @param aIdx = index of the picker in the picked list
* @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() )
{
m_ItemsList[aIdx].m_PickedItem = aItem;
m_ItemsList[aIdx].m_PickedItem = aItem;
m_ItemsList[aIdx].m_UndoRedoStatus = aStatus;
return true;
}
@ -225,17 +305,19 @@ bool PICKED_ITEMS_LIST::RemovePickedItem( unsigned aIdx )
return true;
}
/** Function CopyList
* copy all data from aSource
* 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;
for(unsigned ii = 0; ii < aSource.GetCount(); ii++ )
for( unsigned ii = 0; ii < aSource.GetCount(); ii++ )
{
picker = aSource.m_ItemsList[ii];
PushItem(picker);
PushItem( picker );
}
}

View File

@ -290,12 +290,13 @@ void WinEDA_SchematicFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
itemWrapper.m_PickedItem = item;
itemWrapper.m_PickedItemType = item->Type();
itemWrapper.m_UndoRedoStatus = command;
itemWrapper.m_Link = aItemsList.GetPickedItemLink( ii );
switch( command )
{
case UR_CHANGED: /* Create a copy of item */
CopyOfItem = DuplicateStruct( item );
itemWrapper.m_Link = CopyOfItem;
if ( CopyOfItem )
if( itemWrapper.m_Link == NULL )
itemWrapper.m_Link = DuplicateStruct( item );
if ( itemWrapper.m_Link )
commandToUndo->PushItem( itemWrapper );
break;
@ -495,56 +496,7 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
// Delete items is they are not flagged UR_NEW, or if this is a block operation
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;
}
}
}
curr_cmd->ClearListAndDeleteItems();
delete curr_cmd; // Delete command
}
}

View File

@ -58,7 +58,8 @@ enum UndoRedoOpType {
UR_MOVED, // moved item, undo by move it
UR_MIRRORED_X, // mirrored item, undo by mirror X
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_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)
@ -104,19 +105,33 @@ private:
public:
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 );
/** PopItem
* @return the picker from the top of the list
* the picker is removed from the list
*/
ITEM_PICKER PopItem();
/** 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();
/** 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();
/** function GetCount()
* @return the count of pickers stored in this list
*/
unsigned GetCount() const
{
return m_ItemsList.size();

View File

@ -178,9 +178,6 @@ public:
// Gestion des modules
void InstallModuleOptionsFrame( MODULE* Module, wxDC * DC );
MODULE* Copie_Module( MODULE* module );
MODULE* Exchange_Module( wxWindow* winaff,
MODULE* old_module,
MODULE* new_module );
/** Function Save_Module_In_Library
* Save in an existing library a given footprint
@ -207,7 +204,6 @@ public:
int angle,
bool incremental );
void Place_Module( MODULE* module, wxDC* DC, bool aDoNotRecreateRatsnest = false );
void InstallExchangeModuleFrame( MODULE* ExchangeModuleModule );
// Graphic items edition:
void InstallGraphicItemPropertiesDialog( DRAWSEGMENT* aItem, wxDC* aDC );

View File

@ -330,6 +330,20 @@ public:
// Footprint edition (see also WinEDA_BasePcbFrame)
void StartMove_Module( MODULE* module, wxDC* DC );
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

View File

@ -125,6 +125,7 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
return;
}
// Swap layers:
int layer, layerimg;
layer = aItem->GetLayer();
layerimg = aImage->GetLayer();
@ -183,9 +184,14 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage )
break;
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_Width, ( (COTATION*) aImage )->m_Text->m_Width );
EXCHG( ( (COTATION*) aItem )->m_Text->m_Mirror, ( (COTATION*) aImage )->m_Text->m_Mirror );
}
break;
default:
@ -316,7 +322,6 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem,
if( aItem == NULL ) // Nothing to save
return;
BOARD_ITEM* CopyOfItem;
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
commandToUndo->m_TransformPoint = aTransformPoint;
@ -327,9 +332,9 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem,
switch( aCommandType )
{
case UR_CHANGED: /* Create a copy of schematic */
CopyOfItem = DuplicateStruct( aItem );
itemWrapper.m_Link = CopyOfItem;
if( CopyOfItem )
if( itemWrapper.m_Link == NULL ) // When not null, the copy is already done
itemWrapper.m_Link = DuplicateStruct( aItem );;
if( itemWrapper.m_Link )
commandToUndo->PushItem( itemWrapper );
break;
@ -337,6 +342,7 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( BOARD_ITEM* aItem,
case UR_MOVED:
case UR_FLIPPED:
case UR_ROTATED:
case UR_ROTATED_CLOCKWISE:
case UR_DELETED:
commandToUndo->PushItem( itemWrapper );
break;
@ -371,7 +377,6 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
UndoRedoOpType aTypeCommand,
const wxPoint& aTransformPoint )
{
BOARD_ITEM* CopyOfItem;
PICKED_ITEMS_LIST* commandToUndo = new PICKED_ITEMS_LIST();
commandToUndo->m_TransformPoint = aTransformPoint;
@ -389,17 +394,19 @@ void WinEDA_PcbFrame::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList,
itemWrapper.m_PickedItem = item;
itemWrapper.m_PickedItemType = item->Type();
itemWrapper.m_UndoRedoStatus = command;
itemWrapper.m_Link = aItemsList.GetPickedItemLink( ii );
switch( command )
{
case UR_CHANGED: /* Create a copy of item, and put in undo list */
CopyOfItem = DuplicateStruct( item );
itemWrapper.m_Link = CopyOfItem;
if( CopyOfItem )
case UR_CHANGED: /* If needed, create a copy of item, and put in undo list */
if( itemWrapper.m_Link == NULL ) // When not null, the copy is already done
itemWrapper.m_Link = DuplicateStruct( item );
if( itemWrapper.m_Link )
commandToUndo->PushItem( itemWrapper );
break;
case UR_MOVED:
case UR_ROTATED:
case UR_ROTATED_CLOCKWISE:
case UR_FLIPPED:
case UR_NEW:
case UR_DELETED:
@ -500,6 +507,10 @@ void WinEDA_PcbFrame::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRe
item->Rotate( aList->m_TransformPoint, aRedoCommand ? 900 : -900 );
break;
case UR_ROTATED_CLOCKWISE:
item->Rotate( aList->m_TransformPoint, aRedoCommand ? -900 : 900 );
break;
case UR_FLIPPED:
item->Flip( aList->m_TransformPoint );
break;
@ -609,45 +620,7 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
// Delete items is they are not flagged UR_NEW, or if this is a block operation
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;
}
}
curr_cmd->ClearListAndDeleteItems();
delete curr_cmd; // Delete command
}
}

View File

@ -380,10 +380,6 @@ public:
#endif
/**************************/
/* footprint operations : */
/**************************/
void Change_Side_Module( MODULE* Module, wxDC* DC );
/*************************/
/* Copper Areas handling */

View File

@ -11,7 +11,7 @@
/* Routines Locales */
static void Exit_EditCotation( WinEDA_DrawPanel* Panel, wxDC* DC );
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" : */
static int status_cotation; /* = 0 : pas de cotation en cours
@ -349,7 +349,7 @@ void WinEDA_PcbFrame::Install_Edit_Cotation( COTATION* Cotation,
WinEDA_CotationPropertiesFrame* frame = new WinEDA_CotationPropertiesFrame( this,
Cotation, DC, pos );
Ajuste_Details_Cotation( Cotation );
Ajuste_Details_Cotation( Cotation, true );
frame->ShowModal();
frame->Destroy();
}
@ -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
@ -411,8 +411,8 @@ static void Ajuste_Details_Cotation( COTATION* Cotation )
/* On tient compte de l'inclinaison de la cote */
if( mesure )
{
hx = (abs) ( (int) ( ( (float) deltay * hx ) / mesure ) );
hy = (abs) ( (int) ( ( (float) deltax * hy ) / mesure ) );
hx = (abs) ( (int) ( ( (double) deltay * hx ) / mesure ) );
hy = (abs) ( (int) ( ( (double) deltax * hy ) / mesure ) );
if( Cotation->TraitG_ox > Cotation->Barre_ox )
hx = -hx;
@ -476,7 +476,10 @@ static void Ajuste_Details_Cotation( COTATION* Cotation )
if( (Cotation->m_Text->m_Orient > 900) && (Cotation->m_Text->m_Orient <2700) )
Cotation->m_Text->m_Orient -= 1800;
Cotation->m_Value = mesure;
valeur_param( Cotation->m_Value, msg );
Cotation->SetText( msg );
if( !aDoNotChangeText )
{
Cotation->m_Value = mesure;
valeur_param( Cotation->m_Value, msg );
Cotation->SetText( msg );
}
}

View File

@ -14,6 +14,7 @@
#include "gestfich.h"
#include "3d_struct.h"
#include "3d_viewer.h"
#include "wxPcbStruct.h"
#include "dialog_edit_module.h"
extern bool GoToEditor;
@ -569,7 +570,7 @@ void WinEDA_ModulePropertiesFrame::OnOkClick( wxCommandEvent& event )
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 )
@ -668,7 +669,7 @@ void WinEDA_ModulePropertiesFrame::GotoModuleEditor( 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!
m_Parent->SetCurItem( NULL );

View File

@ -765,7 +765,10 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
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;
case ID_POPUP_PCB_ROTATE_MODULE_CLOCKWISE:
@ -777,7 +780,9 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
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;
case ID_POPUP_PCB_CHANGE_SIDE_MODULE:
@ -788,7 +793,11 @@ void WinEDA_PcbFrame::Process_Special_Functions( wxCommandEvent& event )
SetCurItem( GetCurItem()->GetParent() );
if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
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;
case ID_POPUP_PCB_EDIT_MODULE:

View File

@ -100,7 +100,7 @@ void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event )
module->flag = 0;
if( module->GetLayer() == COPPER_LAYER_N )
{
GetBoard()->Change_Side_Module( module, NULL );
module->Flip( module->m_Pos );
module->flag = 1;
}
}
@ -132,7 +132,7 @@ void WinEDA_PcbFrame::ExportToGenCAD( wxCommandEvent& event )
{
if( module->flag )
{
GetBoard()->Change_Side_Module( module, NULL );
module->Flip( module->m_Pos );
module->flag = 0;
}
}

View File

@ -513,7 +513,7 @@ void WinEDA_PcbFrame::OnHotKey(wxDC* DC, int hotkey, EDA_BaseStruct* DrawStruct)
break;
case HK_FLIP_FOOTPRINT: // move to other side
GetBoard()->Change_Side_Module(module, DC);
Change_Side_Module(module, DC);
break;
case HK_DRAG_FOOTPRINT: // Start move (and drag) module

View File

@ -83,7 +83,7 @@ void WinEDA_ModuleEditFrame::Load_Module_From_BOARD( MODULE* Module )
GetScreen()->m_Curseur.x = GetScreen()->m_Curseur.y = 0;
Place_Module( Module, NULL );
if( Module->GetLayer() != CMP_N )
GetBoard()->Change_Side_Module( Module, NULL );
Module->Flip( Module->m_Pos );
Rotate_Module( NULL, Module, 0, FALSE );
GetScreen()->ClrModify();
Zoom_Automatique( TRUE );

View File

@ -291,10 +291,14 @@ void WinEDA_ModuleEditFrame::Process_Special_Functions( wxCommandEvent& event )
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
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;
if( pickList.GetCount() )
pcbframe->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
}
else // This is an insert command
{

View File

@ -24,8 +24,8 @@
static void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC );
/* Variables locales : */
static int ModuleInitOrient; // Lors des moves, val init de l'orient (pour annulation)
static int ModuleInitLayer; // Lors des moves, val init de la couche (pour annulation)
static MODULE* s_ModuleInitialCopy = NULL; // Copy of module for abort/undo command
static PICKED_ITEMS_LIST s_PickedList; // a picked list to save initial module and dragged tracks
/*************************************************************************/
@ -98,15 +98,22 @@ MODULE* WinEDA_BasePcbFrame::GetModuleByName()
void WinEDA_PcbFrame::StartMove_Module( MODULE* module, wxDC* DC )
/**********************************************************************/
{
if( module == NULL )
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 );
GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
module->m_Flags |= IS_MOVED;
ModuleInitOrient = module->m_Orient;
ModuleInitLayer = module->GetLayer();
GetScreen()->m_Curseur = module->m_Pos;
DrawPanel->MouseToCursorSchema();
@ -123,6 +130,15 @@ void WinEDA_PcbFrame::StartMove_Module( MODULE* module, wxDC* DC )
if( g_Drag_Pistes_On )
{
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;
@ -154,7 +170,7 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC )
DRAG_SEGM* pt_drag;
TRACK* pt_segm;
MODULE* module;
WinEDA_BasePcbFrame* pcbframe = (WinEDA_BasePcbFrame*) Panel->m_Parent;
WinEDA_PcbFrame* pcbframe = (WinEDA_PcbFrame*) Panel->m_Parent;
module = (MODULE*) pcbframe->GetScreen()->GetCurItem();
pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK;
@ -203,12 +219,12 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC )
}
/* Reaffichage du module a l'ecran */
if( module )
if( module && s_ModuleInitialCopy )
{
if( ModuleInitOrient != module->m_Orient )
pcbframe->Rotate_Module( NULL, module, ModuleInitOrient, FALSE );
if( ModuleInitLayer != module->GetLayer() )
pcbframe->GetBoard()->Change_Side_Module( module, NULL );
if( s_ModuleInitialCopy->m_Orient != module->m_Orient )
pcbframe->Rotate_Module( NULL, module, s_ModuleInitialCopy->m_Orient, FALSE );
if( s_ModuleInitialCopy->GetLayer() != module->GetLayer() )
pcbframe->Change_Side_Module( module, NULL );
module->Draw( Panel, DC, GR_OR );
}
g_Drag_Pistes_On = FALSE;
@ -216,6 +232,10 @@ void Abort_MoveOrCopyModule( WinEDA_DrawPanel* Panel, wxDC* DC )
Panel->ForceCloseManageCurseur = 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
if( g_Show_Ratsnest )
pcbframe->DrawGeneralRatsnest( DC );
@ -290,7 +310,7 @@ bool WinEDA_PcbFrame::Delete_Module( MODULE* module, wxDC* DC, bool aAskBeforeDe
/**
* Function Delete Module
* 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 DC = currentDevice Context. if NULL: do not redraw new ratsnets and dirty rectange
* @param aPromptBeforeDeleting : if true: ask for confirmation before deleting
@ -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 )
if( (Module->GetLayer() != CMP_N) && (Module->GetLayer() != COPPER_LAYER_N) )
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);
if( DC && m_PcbFrame )
GetBoard()->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK);
if( DC )
{
int tmp = Module->m_Flags;
Module->m_Flags |= DO_NOT_DRAW;
m_PcbFrame->DrawPanel->PostDirtyRect( Module->GetBoundingBox() );
DrawPanel->PostDirtyRect( Module->GetBoundingBox() );
Module->m_Flags = tmp;
}
/* Effacement chevelu general si necessaire */
if( DC && g_Show_Ratsnest )
m_PcbFrame->DrawGeneralRatsnest( DC );
DrawGeneralRatsnest( DC );
/* Init des variables utilisees dans la routine Dessine_Drag_segment() */
g_Offset_Module.x = 0;
@ -383,37 +403,36 @@ void BOARD::Change_Side_Module( MODULE* Module, wxDC* DC )
else // Module en deplacement
{
/* efface empreinte ( vue en contours) si elle a ete deja dessinee */
if( DC && m_PcbFrame )
if( DC )
{
DrawModuleOutlines( m_PcbFrame->DrawPanel, DC, Module );
Dessine_Segments_Dragges( m_PcbFrame->DrawPanel, DC );
DrawModuleOutlines( DrawPanel, DC, Module );
Dessine_Segments_Dragges( DrawPanel, DC );
}
}
/* Flip the module */
Module->Flip( Module->m_Pos );
if( m_PcbFrame )
Module->DisplayInfo( m_PcbFrame );
Module->DisplayInfo( this );
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 */
m_PcbFrame->Compile_Ratsnest( DC, true );
Compile_Ratsnest( DC, true );
}
}
else
{
if( DC && m_PcbFrame )
if( DC )
{
DrawModuleOutlines( m_PcbFrame->DrawPanel, DC, Module );
Dessine_Segments_Dragges( m_PcbFrame->DrawPanel, DC );
DrawModuleOutlines( DrawPanel, DC, Module );
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
/* Place a l'endroit pointe par la souris le module deja existant selectionne
* auparavant.
* Entree: module = num du module a replacer
* DC ( si NULL: pas d'affichage a l'<EFBFBD>ran
* DC ( si NULL: pas d'affichage a l'ecran
* Sortie :
* mise a jour des nouvelles coord des differents elements du module
* affichage a l'ecran du module
*/
{
TRACK* pt_segm;
DRAG_SEGM* pt_drag;
wxPoint newpos;
if( module == 0 )
@ -441,6 +459,27 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec
GetScreen()->SetModify();
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 )
trace_ratsnest_module( DC );
@ -450,11 +489,11 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec
if( DC )
module->Draw( DrawPanel, DC, GR_OR );
/* Tracage des segments dragges et liberation memoire */
if( g_DragSegmentList )
{
pt_drag = g_DragSegmentList;
for( ; pt_drag != NULL; pt_drag = pt_drag->Pnext )
/* Redraw dragged track segments */
for( DRAG_SEGM* pt_drag = g_DragSegmentList; pt_drag != NULL; pt_drag = pt_drag->Pnext )
{
pt_segm = pt_drag->m_Segm;
pt_segm->SetState( EDIT, OFF );
@ -462,9 +501,9 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec
pt_segm->Draw( DrawPanel, DC, GR_OR );
}
// Delete drag list
EraseDragListe();
}
if( !aDoNotRecreateRatsnest )
Compile_Ratsnest( DC, true );
@ -477,6 +516,9 @@ void WinEDA_BasePcbFrame::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRec
DrawPanel->ForceCloseManageCurseur = NULL;
module->m_Flags = 0;
g_Drag_Pistes_On = FALSE;
delete s_ModuleInitialCopy;
s_ModuleInitialCopy = NULL;
}
@ -498,10 +540,9 @@ void WinEDA_BasePcbFrame::Rotate_Module( wxDC* DC, MODULE* module,
GetScreen()->SetModify();
/* efface ancienne position */
if( !(module->m_Flags & IS_MOVED) ) /* Rotation simple */
if( !(module->m_Flags & IS_MOVED) ) /* This is a simple rotation, no other edition in progress */
{
if( DC )
if( DC ) // Erase footprint to screen
{
int tmp = module->m_Flags;
module->m_Flags |= DO_NOT_DRAW;

View File

@ -475,7 +475,10 @@ MODULE* ReadNetModule( WinEDA_PcbFrame* aFrame,
MODULE* NewModule =
aFrame->Get_Librairie_Module( wxEmptyString, NameLibCmp, true );
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
{

View File

@ -22,75 +22,7 @@
/* Bitmaps */
#include "bitmaps.h"
/********************************************/
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;
}
static wxMenu* Append_Track_Width_List();
/******************************************************************************/
@ -732,19 +664,19 @@ void WinEDA_PcbFrame::createPopUpMenuForFootprints( MODULE* aModule, wxMenu* men
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_DRAG_MODULE_REQUEST,
msg, drag_module_xpm );
}
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 );
msg = AddHotkeyName( _( "Rotate +" ), s_Board_Editor_Hokeys_Descr, HK_ROTATE_FOOTPRINT );
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 );
msg = AddHotkeyName( _( "Flip" ), s_Board_Editor_Hokeys_Descr, HK_FLIP_FOOTPRINT );
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_CHANGE_SIDE_MODULE,
msg, invert_module_xpm );
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_EDIT_MODULE,
_( "Edit" ), edit_module_xpm );
if( !flags )
{
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_EDIT_MODULE,
_( "Edit" ), edit_module_xpm );
sub_menu_footprint->AppendSeparator();
ADD_MENUITEM( sub_menu_footprint, ID_POPUP_PCB_DELETE_MODULE,
_( "Delete Module" ), delete_module_xpm );
@ -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_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;
}

View File

@ -34,7 +34,7 @@
#include "specctra.h"
#include "collectors.h"
#include "wxPcbStruct.h" // Change_Side_Module()
#include "wxPcbStruct.h"
#include "pcbstruct.h" // HISTORY_NUMBER
#include "confirm.h" // DisplayError()
#include "gestfich.h" // EDA_FileSelector()
@ -113,7 +113,7 @@ void WinEDA_PcbFrame::ExportToSpecctra( wxCommandEvent& event )
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
// be ok to clear the modify flag.
if( !wasModified )
@ -1451,7 +1451,7 @@ void SPECCTRA_DB::FlipMODULEs( BOARD* aBoard )
module->flag = 0;
if( module->GetLayer() == COPPER_LAYER_N )
{
aBoard->Change_Side_Module( module, NULL );
module->Flip( module->m_Pos );
module->flag = 1;
}
}
@ -1471,7 +1471,7 @@ void SPECCTRA_DB::RevertMODULEs( BOARD* aBoard )
{
if( module->flag )
{
aBoard->Change_Side_Module( module, NULL );
module->Flip( module->m_Pos );
module->flag = 0;
}
}

View File

@ -413,7 +413,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError )
if( module->GetLayer() != CMP_N )
{
// module is on copper layer (back)
aBoard->Change_Side_Module( module, 0 );
module->Flip( module->m_Pos );
}
module->SetOrientation( orientation );
}
@ -423,8 +423,8 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IOError )
if( module->GetLayer() != COPPER_LAYER_N )
{
// module is on component layer (front)
aBoard->Change_Side_Module( module, 0 );
}
module->Flip( module->m_Pos );
}
module->SetOrientation( orientation );
}
else

View File

@ -25,13 +25,13 @@ class DIALOG_EXCHANGE_MODULE : public DIALOG_EXCHANGE_MODULE_BASE
{
private:
WinEDA_BasePcbFrame* m_Parent;
WinEDA_PcbFrame* m_Parent;
MODULE* m_CurrentModule;
public:
// Constructor and destructor
DIALOG_EXCHANGE_MODULE( WinEDA_BasePcbFrame* aParent, MODULE* aModule );
DIALOG_EXCHANGE_MODULE( WinEDA_PcbFrame* aParent, MODULE* aModule );
~DIALOG_EXCHANGE_MODULE() { };
private:
@ -46,13 +46,14 @@ private:
void Change_ModuleAll();
int Maj_ListeCmp( const wxString& reference, const wxString& old_name,
const wxString& new_name, bool ShowError );
MODULE* Change_1_Module( MODULE* Module,
bool Change_1_Module( MODULE* Module,
const wxString& new_module,
PICKED_ITEMS_LIST* aUndoPickList,
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 )
{
m_Parent = parent;
@ -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 );
@ -195,7 +196,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
fprintf( NewFile, "Cmp-Mod V01 Genere par PcbNew le %s\n",
DateAndTime( Line ) );
bool start_descr = FALSE;
bool start_descr = false;
while( fgets( Line, sizeof(Line), FichCmp ) != NULL )
{
if( strnicmp( Line, "Reference = ", 9 ) == 0 )
@ -212,7 +213,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
if( (strnicmp( Line, "Begin", 5 ) == 0)
|| (strnicmp( Line, "End", 3 ) == 0) )
{
start_descr = FALSE;
start_descr = false;
}
if( start_descr && strnicmp( Line, "IdModule", 8 ) == 0 )
@ -222,7 +223,7 @@ int DIALOG_EXCHANGE_MODULE::Maj_ListeCmp( const wxString& reference,
msg = wxT( " * in <" ) + fn.GetFullPath() + wxT( ">.\n" );
m_WinMessages->AppendText( msg );
start_descr = FALSE;
start_descr = false;
}
fputs( Line, NewFile );
}
@ -250,11 +251,16 @@ void DIALOG_EXCHANGE_MODULE::Change_Module()
if( newmodulename == wxEmptyString )
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->DrawPanel->Refresh();
}
if( pickList.GetCount() )
m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
}
@ -273,10 +279,10 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
{
wxString msg;
MODULE* Module, * PtBack;
bool change = FALSE;
bool change = false;
wxString newmodulename = m_NewModule->GetValue();
wxString value, lib_reference;
bool check_module_value = FALSE;
bool check_module_value = false;
int ShowErr = 3; // Affiche 3 messages d'err maxi
if( m_Parent->GetBoard()->m_Modules == NULL )
@ -307,12 +313,12 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
* Change_1_Module() modifie le dernier module de la liste
*/
/* note: for the first module in chain (the last here), Module->Back() points the board or is NULL
PICKED_ITEMS_LIST pickList;
/* 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();
for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack )
{
MODULE* module;
PtBack = Module->Back();
if( lib_reference.CmpNoCase( Module->m_LibRef ) != 0 )
continue;
@ -321,8 +327,7 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
if( value.CmpNoCase( Module->m_Value->m_Text ) != 0 )
continue;
}
module = Change_1_Module( Module, newmodulename.GetData(), ShowErr );
if( module )
if( Change_1_Module( Module, newmodulename.GetData(), &pickList, ShowErr ) )
change = true;
else if( ShowErr )
ShowErr--;
@ -333,6 +338,9 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleId( bool aUseValue )
m_Parent->Compile_Ratsnest( NULL, true );
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 )
void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
{
MODULE* Module, * PtBack;
bool change = FALSE;
bool change = false;
int ShowErr = 3; // Affiche 3 messages d'err maxi
if( m_Parent->GetBoard()->m_Modules == NULL )
@ -360,13 +368,15 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
* Change_1_Module() modifie le dernier module de la liste
*/
/* note: for the first module in chain (the last here), Module->Back() points the board or is NULL
PICKED_ITEMS_LIST pickList;
/* 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();
for( ; Module && ( Module->Type() == TYPE_MODULE ); Module = PtBack )
{
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;
else if( ShowErr )
ShowErr--;
@ -377,6 +387,8 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
m_Parent->Compile_Ratsnest( NULL, true );
m_Parent->DrawPanel->Refresh();
}
if( pickList.GetCount() )
m_Parent->SaveCopyInUndoList( pickList, UR_UNSPECIFIED );
}
@ -388,12 +400,13 @@ void DIALOG_EXCHANGE_MODULE::Change_ModuleAll()
* - memes textes valeur et ref
* - memes netnames pour pads de meme nom
* Retourne :
* 0 si pas de changement ( si le nouveau module n'est pas en libr)
* 1 si OK
* false si pas de changement ( si le nouveau module n'est pas en libr)
* true si OK
* 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,
PICKED_ITEMS_LIST* aUndoPickList,
bool ShowError )
{
wxString namecmp, oldnamecmp;
@ -401,7 +414,7 @@ MODULE* DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module,
wxString Line;
if( Module == NULL )
return NULL;
return false;
wxBusyCursor dummy;
@ -415,89 +428,91 @@ MODULE* DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* Module,
m_WinMessages->AppendText( Line );
namecmp.Trim( true );
namecmp.Trim( FALSE );
namecmp.Trim( false );
NewModule = m_Parent->Get_Librairie_Module( wxEmptyString,
namecmp,
ShowError );
if( NewModule == NULL ) /* Nouveau module NON trouve, reaffichage de l'ancien */
{
m_WinMessages->AppendText( wxT( "No\n" ) );
return NULL;
return false;
}
if( Module == m_CurrentModule )
m_CurrentModule = NewModule;
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,
oldnamecmp,
namecmp,
ShowError );
return NewModule;
return true;
}
/*
* Remplace le module OldModule par le module NewModule (en conservant
* position, orientation..)
* OldModule est supprim<EFBFBD> de la memoire.
/** 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
*/
MODULE* WinEDA_BasePcbFrame::Exchange_Module( wxWindow* winaff,
MODULE* OldModule,
MODULE* NewModule )
void WinEDA_PcbFrame::Exchange_Module( MODULE* aOldModule,
MODULE* aNewModule,
PICKED_ITEMS_LIST* aUndoPickList)
{
wxPoint oldpos; /* memorisation temporaire pos curseur */
D_PAD* pad, * old_pad;
if( (OldModule->Type() != TYPE_MODULE)
|| (NewModule->Type() != TYPE_MODULE) )
if( (aOldModule->Type() != TYPE_MODULE) || (aNewModule->Type() != TYPE_MODULE) )
{
DisplayError( winaff,
wxT( "WinEDA_BasePcbFrame::Exchange_Module() StuctType error" ) );
wxMessageBox( wxT( "WinEDA_PcbFrame::Exchange_Module() StuctType error" ) );
return;
}
NewModule->SetParent( GetBoard() );
aNewModule->SetParent( GetBoard() );
GetBoard()->m_Status_Pcb = 0;
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
* when all modules are on board
*/
Place_Module( NewModule, NULL, true );
Place_Module( aNewModule, NULL, true );
GetScreen()->m_Curseur = oldpos;
/* 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 */
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 */
NewModule->m_Reference->m_Text = OldModule->m_Reference->m_Text;
NewModule->m_Value->m_Text = OldModule->m_Value->m_Text;
aNewModule->m_Reference->m_Text = aOldModule->m_Reference->m_Text;
aNewModule->m_Value->m_Text = aOldModule->m_Value->m_Text;
/* Mise a jour des autres parametres */
NewModule->m_TimeStamp = OldModule->m_TimeStamp;
NewModule->m_Path = OldModule->m_Path;
aNewModule->m_TimeStamp = aOldModule->m_TimeStamp;
aNewModule->m_Path = aOldModule->m_Path;
/* Update pad netnames ( when possible) */
pad = NewModule->m_Pads;
pad = aNewModule->m_Pads;
for( ; pad != NULL; pad = pad->Next() )
{
pad->SetNetname( wxEmptyString );
pad->SetNet( 0 );
old_pad = OldModule->m_Pads;
old_pad = aOldModule->m_Pads;
for( ; old_pad != NULL; old_pad = old_pad->Next() )
{
if( strnicmp( pad->m_Padname, old_pad->m_Padname,
@ -509,14 +524,20 @@ MODULE* WinEDA_BasePcbFrame::Exchange_Module( wxWindow* winaff,
}
}
/* Effacement de l'ancien module */
OldModule->DeleteStructure();
if( aUndoPickList )
{
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;
NewModule->m_Flags = 0;
aNewModule->m_Flags = 0;
GetScreen()->SetModify();
return NewModule;
}