From b703d8156102d0936bf6e33db079005b06c6f1fa Mon Sep 17 00:00:00 2001 From: Marco Mattila Date: Tue, 5 Jun 2012 14:44:22 +0300 Subject: [PATCH] Add missing checks and undo support to pcbnew zone duplication. --- include/wxPcbStruct.h | 8 ++++++ pcbnew/class_zone_settings.cpp | 1 + pcbnew/edit.cpp | 13 +--------- pcbnew/zones_by_polygon.cpp | 47 ++++++++++++++++++++++++++++++++++ polygon/PolyLine.h | 1 + 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 3cf5496d1e..12f62d4fce 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -196,6 +196,14 @@ protected: */ int propagate(); + /** + * Function duplicateZone + * duplicates the given zone. + * @param aDC is the current Device Context. + * @param aZone is the zone to duplicate + */ + void duplicateZone( wxDC* aDC, ZONE_CONTAINER* aZone ); + public: PCB_LAYER_BOX_SELECTOR* m_SelLayerBox; // a combo box to display and select active layer wxComboBox* m_SelTrackWidthBox; // a combo box to display and select current track width diff --git a/pcbnew/class_zone_settings.cpp b/pcbnew/class_zone_settings.cpp index 845f8b4b50..3368d30522 100644 --- a/pcbnew/class_zone_settings.cpp +++ b/pcbnew/class_zone_settings.cpp @@ -86,5 +86,6 @@ void ZONE_SETTINGS::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport ) c aTarget.SetPriority( m_ZonePriority ); aTarget.SetNet( m_NetcodeSelection ); aTarget.SetLayer( m_CurrentZone_Layer ); + aTarget.m_Poly->SetLayer( m_CurrentZone_Layer ); } } diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index d31ab9f14b..d1e55c5de0 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -470,18 +470,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_PCB_ZONE_DUPLICATE: { ZONE_CONTAINER* zone = (ZONE_CONTAINER*) GetCurItem(); - ZONE_CONTAINER* newZone = new ZONE_CONTAINER( m_Pcb ); - newZone->Copy( zone ); - ZONE_SETTINGS zoneSettings; - zoneSettings << *zone; - if( InvokeCopperZonesEditor( this, &zoneSettings ) ) - { - zoneSettings.ExportSetting( *newZone ); - m_Pcb->Add( newZone ); - newZone->Draw( m_canvas, &dc, GR_OR ); - } - else - delete newZone; + duplicateZone( &dc, zone ); } break; diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index b543640cb5..9d6c613018 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -107,6 +107,53 @@ void PCB_EDIT_FRAME::Add_Zone_Cutout( wxDC* DC, ZONE_CONTAINER* aZone ) } +void PCB_EDIT_FRAME::duplicateZone( wxDC* aDC, ZONE_CONTAINER* aZone ) +{ + ZONE_CONTAINER* newZone = new ZONE_CONTAINER( GetBoard() ); + newZone->Copy( aZone ); + newZone->UnFill(); + ZONE_SETTINGS zoneSettings; + zoneSettings << *aZone; + + if( InvokeCopperZonesEditor( this, &zoneSettings ) ) + { + zoneSettings.ExportSetting( *newZone ); + newZone->m_Poly->Hatch(); + + _AuxiliaryList.ClearListAndDeleteItems(); + s_PickedList.ClearListAndDeleteItems(); + SaveCopyOfZones( s_PickedList, GetBoard(), newZone->GetNet(), newZone->GetLayer() ); + GetBoard()->Add( newZone ); + + ITEM_PICKER picker( newZone, UR_NEW ); + s_PickedList.PushItem( picker ); + + GetScreen()->SetCurItem( NULL ); // This outline may be deleted when merging outlines + + // Combine zones if possible + GetBoard()->AreaPolygonModified( &_AuxiliaryList, newZone, true, s_Verbose ); + + // Redraw zones + GetBoard()->RedrawAreasOutlines( m_canvas, aDC, GR_OR, newZone->GetLayer() ); + GetBoard()->RedrawFilledAreas( m_canvas, aDC, GR_OR, newZone->GetLayer() ); + + if( GetBoard()->GetAreaIndex( newZone ) >= 0 + && GetBoard()->Test_Drc_Areas_Outlines_To_Areas_Outlines( newZone, true ) ) + { + DisplayError( this, _( "Duplicate Zone: The outline of the duplicated zone fails DRC check!" ) ); + } + + UpdateCopyOfZonesList( s_PickedList, _AuxiliaryList, GetBoard() ); + SaveCopyInUndoList( s_PickedList, UR_UNSPECIFIED ); + s_PickedList.ClearItemsList(); + + OnModify(); + } + else + delete newZone; +} + + int PCB_EDIT_FRAME::Delete_LastCreatedCorner( wxDC* DC ) { ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour; diff --git a/polygon/PolyLine.h b/polygon/PolyLine.h index 3aa6ba60f3..f9d98a2ba1 100644 --- a/polygon/PolyLine.h +++ b/polygon/PolyLine.h @@ -159,6 +159,7 @@ public: void AppendArc( int xi, int yi, int xf, int yf, int xc, int yc, int num ); // access functions + void SetLayer( int aLayer ) { m_layer = aLayer; } int GetLayer() { return m_layer; } int GetNumCorners(); int GetNumSides();