From 21d1402c0328aa0e66e0bf125661a89a6c7f90f0 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 23 Mar 2013 14:30:00 +0100 Subject: [PATCH] Pcbnew, ModEdit: fix issue when setting anchor position, and minor code cleaning. --- pcbnew/class_module.cpp | 57 +++++++++++++++++++++++++++++++ pcbnew/class_module.h | 13 ++++++++ pcbnew/editmod.cpp | 65 ++++-------------------------------- pcbnew/modedit_onclick.cpp | 15 +++++---- pcbnew/module_editor_frame.h | 1 - template/kicad.pro | 48 ++++++++++++++------------ 6 files changed, 111 insertions(+), 88 deletions(-) diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 52d4b5827f..5d1a9b183f 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -921,6 +921,63 @@ void MODULE::SetPosition( const wxPoint& newpos ) CalculateBoundingBox(); } +void MODULE::MoveAnchorPosition( const wxPoint& aMoveVector ) +{ + /* Move the reference point of the footprint + * the footprints elements (pads, outlines, edges .. ) are moved + * but: + * - the footprint position is not modified. + * - the relative (local) coordinates of these items are modified + */ + + wxPoint footprintPos = GetPosition(); + + /* Update the relative coordinates: + * The coordinates are relative to the anchor point. + * Calculate deltaX and deltaY from the anchor. */ + wxPoint moveVector = aMoveVector; + RotatePoint( &moveVector, -GetOrientation() ); + + // Update of the reference and value. + m_Reference->SetPos0( m_Reference->GetPos0() + moveVector ); + m_Reference->SetDrawCoord(); + m_Value->SetPos0( m_Value->GetPos0() + moveVector ); + m_Value->SetDrawCoord(); + + // Update the pad local coordinates. + for( D_PAD* pad = Pads(); pad; pad = pad->Next() ) + { + pad->SetPos0( pad->GetPos0() + moveVector ); + pad->SetPosition( pad->GetPos0() + footprintPos ); + } + + // Update the draw element coordinates. + for( EDA_ITEM* item = GraphicalItems(); item; item = item->Next() ) + { + switch( item->Type() ) + { + case PCB_MODULE_EDGE_T: + #undef STRUCT + #define STRUCT ( (EDGE_MODULE*) item ) + STRUCT->m_Start0 += moveVector; + STRUCT->m_End0 += moveVector; + STRUCT->SetDrawCoord(); + break; + + case PCB_MODULE_TEXT_T: + #undef STRUCT + #define STRUCT ( (TEXTE_MODULE*) item ) + STRUCT->SetPos0( STRUCT->GetPos0() + moveVector ); + STRUCT->SetDrawCoord(); + break; + + default: + break; + } + } + + CalculateBoundingBox(); +} void MODULE::SetOrientation( double newangle ) { diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index ee443af190..74041b7050 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -162,6 +162,19 @@ public: void Flip( const wxPoint& aCentre ); + /** + * Function MoveAnchorPosition + * Move the reference point of the footprint + * It looks like a move footprint: + * the footprints elements (pads, outlines, edges .. ) are moved + * However: + * - the footprint position is not modified. + * - the relative (local) coordinates of these items are modified + * (a move footprint does not change these local coordinates, + * but changes the footprint position) + */ + void MoveAnchorPosition( const wxPoint& aMoveVector ); + /** * function IsFlipped * @return true if the module is flipped, i.e. on the back side of the board diff --git a/pcbnew/editmod.cpp b/pcbnew/editmod.cpp index 2c8047c174..02a0e537fc 100644 --- a/pcbnew/editmod.cpp +++ b/pcbnew/editmod.cpp @@ -4,12 +4,11 @@ /************************************************/ #include -#include #include +#include #include #include #include -#include #include <3d_viewer.h> #include @@ -34,7 +33,7 @@ void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC ) // Raising an Exception - Fixes #764678 DIALOG_MODULE_BOARD_EDITOR* dialog = new DIALOG_MODULE_BOARD_EDITOR( this, Module, NULL ); #endif - + int retvalue = dialog->ShowModal(); /* retvalue = * -1 if abort, * 0 if exchange module, @@ -65,58 +64,6 @@ void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC ) } -/* - * Move the footprint anchor position to the current cursor position. - */ -void FOOTPRINT_EDIT_FRAME::Place_Ancre( MODULE* aModule ) -{ - wxPoint moveVector; - - if( aModule == NULL ) - return; - - moveVector = aModule->GetPosition() - GetScreen()->GetCrossHairPosition(); - - aModule->SetPosition( GetScreen()->GetCrossHairPosition() ); - - /* Update the relative coordinates: - * The coordinates are relative to the anchor point. - * Calculate deltaX and deltaY from the anchor. */ - RotatePoint( &moveVector, -aModule->GetOrientation() ); - - // Update the pad coordinates. - for( D_PAD* pad = (D_PAD*) aModule->Pads(); pad; pad = pad->Next() ) - { - pad->SetPos0( pad->GetPos0() + moveVector ); - } - - // Update the draw element coordinates. - for( EDA_ITEM* item = aModule->GraphicalItems(); item; item = item->Next() ) - { - switch( item->Type() ) - { - case PCB_MODULE_EDGE_T: - #undef STRUCT - #define STRUCT ( (EDGE_MODULE*) item ) - STRUCT->m_Start0 += moveVector; - STRUCT->m_End0 += moveVector; - break; - - case PCB_MODULE_TEXT_T: - #undef STRUCT - #define STRUCT ( (TEXTE_MODULE*) item ) - STRUCT->SetPos0( STRUCT->GetPos0() + moveVector ); - break; - - default: - break; - } - } - - aModule->CalculateBoundingBox(); -} - - void FOOTPRINT_EDIT_FRAME::RemoveStruct( EDA_ITEM* Item ) { if( Item == NULL ) @@ -134,13 +81,13 @@ void FOOTPRINT_EDIT_FRAME::RemoveStruct( EDA_ITEM* Item ) if( text->GetType() == TEXT_is_REFERENCE ) { - DisplayError( this, _( "Text is REFERENCE!" ) ); + DisplayError( this, _( "Cannot delete REFERENCE!" ) ); break; } if( text->GetType() == TEXT_is_VALUE ) { - DisplayError( this, _( "Text is VALUE!" ) ); + DisplayError( this, _( "Cannot delete VALUE!" ) ); break; } @@ -159,8 +106,8 @@ void FOOTPRINT_EDIT_FRAME::RemoveStruct( EDA_ITEM* Item ) default: { wxString Line; - Line.Printf( wxT( " Remove: draw item type %d unknown." ), Item->Type() ); - DisplayError( this, Line ); + Line.Printf( wxT( " RemoveStruct: item type %d unknown." ), Item->Type() ); + wxMessageBox( Line ); } break; } diff --git a/pcbnew/modedit_onclick.cpp b/pcbnew/modedit_onclick.cpp index ecabdf3304..aa5c25bc67 100644 --- a/pcbnew/modedit_onclick.cpp +++ b/pcbnew/modedit_onclick.cpp @@ -14,7 +14,6 @@ #include #include -//#include #include #include #include @@ -112,7 +111,7 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) } else { - DisplayError( this, wxT( "ProcessCommand error: item flags error" ) ); + wxMessageBox( wxT( "ProcessCommand error: unknown shape" ) ); } } break; @@ -140,13 +139,15 @@ void FOOTPRINT_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) || (module->GetFlags() != 0) ) break; - module->ClearFlags(); SaveCopyInUndoList( module, UR_MODEDIT ); - Place_Ancre( module ); // set the new relatives internal coordinates of items - RedrawScreen( wxPoint( 0, 0 ), true ); - // Replace the module in position 0, to recalculate absolutes coordinates of items - module->SetPosition( wxPoint( 0, 0 ) ); + // set the new relative internal local coordinates of footprint items + wxPoint moveVector = module->GetPosition() - + GetScreen()->GetCrossHairPosition(); + module->MoveAnchorPosition( moveVector ); + + // Usually, we do not need to change twice the anchor position, + // so deselect the active tool SetToolID( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor(), wxEmptyString ); SetCurItem( NULL ); m_canvas->Refresh(); diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h index c032b671e2..da3166e3ed 100644 --- a/pcbnew/module_editor_frame.h +++ b/pcbnew/module_editor_frame.h @@ -225,7 +225,6 @@ public: // Footprint edition - void Place_Ancre( MODULE* module ); void RemoveStruct( EDA_ITEM* Item ); /** diff --git a/template/kicad.pro b/template/kicad.pro index b956154c4c..a186ec4ffb 100644 --- a/template/kicad.pro +++ b/template/kicad.pro @@ -1,4 +1,4 @@ -update=13/10/2012 17:48:08 +update=21/03/2013 14:06:30 version=1 last_client=pcbnew [general] @@ -52,20 +52,21 @@ LibName30=valves [pcbnew] version=1 LastNetListRead= -PadDrlX=320 -PadDimH=550 -PadDimV=550 -BoardThickness=620 -TxtPcbV=600 -TxtPcbH=600 -TxtModV=500 -TxtModH=500 -TxtModW=100 -VEgarde=100 -DrawLar=120 -EdgeLar=80 -TxtLar=120 -MSegLar=120 +UseCmpFile=1 +PadDrill=0.6 +PadSizeH=1 +PadSizeV=1 +PcbTextSizeV=1 +PcbTextSizeH=1 +PcbTextThickness=0.3 +ModuleTextSizeV=1 +ModuleTextSizeH=1 +ModuleTextSizeThickness=0.15 +SolderMaskClearance=0 +SolderMaskMinWidth=0 +DrawSegmentWidth=0.2 +BoardOutlineThickness=0.15 +ModuleOutlineThickness=0.15 [pcbnew/libraries] LibDir= LibName1=sockets @@ -73,9 +74,14 @@ LibName2=connect LibName3=discret LibName4=pin_array LibName5=divers -LibName6=libcms -LibName7=display -LibName8=led -LibName9=dip_sockets -LibName10=pga_sockets -LibName11=valves +LibName6=smd_capacitors +LibName7=smd_resistors +LibName8=smd_crystal&oscillator +LibName9=smd_dil +LibName10=smd_transistors +LibName11=libcms +LibName12=display +LibName13=led +LibName14=dip_sockets +LibName15=pga_sockets +LibName16=valves