From b653da5e29191221317d44c6ccfede9ee4d43a72 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 27 Sep 2014 18:39:18 +0200 Subject: [PATCH] change name TEXTE_MODULE::MirrorWithModule to TEXTE_MODULE::MirrorTransformWithModule, because it is a function specific to a footprint transform in modedit. change also name TEXTE_MODULE::RotateWithModule to TEXTE_MODULE::RotateTransformWithModule for same reason. Pcbnew: fix Bug #1374484 (text changes position when module is flipped and rotated). Fix also some bugs in modedit, in block commands. --- pcbnew/block_module_editor.cpp | 71 +++++++++++++++++++++++++++------- pcbnew/class_text_mod.cpp | 34 ++++++++++------ pcbnew/class_text_mod.h | 14 ++++--- pcbnew/modedit.cpp | 7 ---- 4 files changed, 90 insertions(+), 36 deletions(-) diff --git a/pcbnew/block_module_editor.cpp b/pcbnew/block_module_editor.cpp index 68cf46eb77..2898af9260 100644 --- a/pcbnew/block_module_editor.cpp +++ b/pcbnew/block_module_editor.cpp @@ -400,6 +400,11 @@ void CopyMarkedItems( MODULE* module, wxPoint offset ) if( module == NULL ) return; + // Reference and value cannot be copied, they are unique. + // Ensure they are not selected + module->Reference().ClearFlags(); + module->Value().ClearFlags(); + for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() ) { if( !pad->IsSelected() ) @@ -440,6 +445,12 @@ void MoveMarkedItems( MODULE* module, wxPoint offset ) if( module == NULL ) return; + if( module->Reference().IsSelected() ) + module->Reference().MoveTransformWithModule( offset ); + + if( module->Value().IsSelected() ) + module->Value().MoveTransformWithModule( offset ); + D_PAD* pad = module->Pads(); for( ; pad != NULL; pad = pad->Next() ) @@ -461,7 +472,7 @@ void MoveMarkedItems( MODULE* module, wxPoint offset ) switch( item->Type() ) { case PCB_MODULE_TEXT_T: - static_cast( item )->Move( offset ); + static_cast( item )->MoveTransformWithModule( offset ); break; case PCB_MODULE_EDGE_T: @@ -477,9 +488,9 @@ void MoveMarkedItems( MODULE* module, wxPoint offset ) default: ; } - - item->ClearFlags(); } + + ClearMarkItems( module ); } @@ -518,6 +529,9 @@ void DeleteMarkedItems( MODULE* module ) item->DeleteStructure(); } + + // Ref and value can be flagged, but cannot be deleted + ClearMarkItems( module ); } @@ -534,6 +548,12 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all ) if( module == NULL ) return; + if( module->Reference().IsSelected() || force_all ) + module->Reference().MirrorTransformWithModule( offset.x ); + + if( module->Value().IsSelected() || force_all ) + module->Value().MirrorTransformWithModule( offset.x ); + for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() ) { // Skip pads not selected, i.e. not inside the block to mirror: @@ -584,15 +604,15 @@ void MirrorMarkedItems( MODULE* module, wxPoint offset, bool force_all ) break; case PCB_MODULE_TEXT_T: - static_cast( item )->MirrorWithModule( offset.x ); + static_cast( item )->MirrorTransformWithModule( offset.x ); break; default: break; } - - item->ClearFlags(); } + + ClearMarkItems( module ); } @@ -607,6 +627,12 @@ void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all ) if( module == NULL ) return; + if( module->Reference().IsSelected() || force_all ) + module->Reference().RotateTransformWithModule( offset, 900 ); + + if( module->Value().IsSelected() || force_all ) + module->Value().RotateTransformWithModule( offset, 900 ); + for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() ) { if( !pad->IsSelected() && !force_all ) @@ -622,7 +648,7 @@ void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all ) for( EDA_ITEM* item = module->GraphicalItems(); item; item = item->Next() ) { - if( !item->IsSelected() && !force_all) + if( !item->IsSelected() && !force_all ) continue; switch( item->Type() ) @@ -644,26 +670,27 @@ void RotateMarkedItems( MODULE* module, wxPoint offset, bool force_all ) break; case PCB_MODULE_TEXT_T: - static_cast( item )->RotateWithModule( wxPoint( 0, 0 ), 900 ); + static_cast( item )->RotateTransformWithModule( offset, 900 ); break; default: break; } - - item->ClearFlags(); } + + ClearMarkItems( module ); } void ClearMarkItems( MODULE* module ) { - EDA_ITEM* item; - if( module == NULL ) return; - item = module->GraphicalItems(); + module->Reference().ClearFlags(); + module->Value().ClearFlags(); + + EDA_ITEM* item = module->GraphicalItems(); for( ; item != NULL; item = item->Next() ) { @@ -692,6 +719,24 @@ int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect ) if( module == NULL ) return 0; + ClearMarkItems( module ); // Just in case ... + + pos = module->Reference().GetTextPosition(); + + if( Rect.Contains( pos ) ) + { + module->Reference().SetFlags( SELECTED ); + ItemsCount++; + } + + pos = module->Value().GetTextPosition(); + + if( Rect.Contains( pos ) ) + { + module->Value().SetFlags( SELECTED ); + ItemsCount++; + } + pad = module->Pads(); for( ; pad != NULL; pad = pad->Next() ) diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index ec0f29ff9a..957b25f321 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -105,33 +105,45 @@ void TEXTE_MODULE::Flip(const wxPoint& aCentre ) void TEXTE_MODULE::FlipWithModule( int aOffset ) { + // flipping the footprint is relative to the X axis m_Pos.y = aOffset - (m_Pos.y - aOffset); NEGATE_AND_NORMALIZE_ANGLE_POS( m_Orient ); + wxPoint tmp = GetPos0(); + tmp.y = -tmp.y; + SetPos0( tmp ); SetLayer( FlipLayer( GetLayer() ) ); m_Mirror = IsBackLayer( GetLayer() ); } -void TEXTE_MODULE::MirrorWithModule( int aOffset ) +void TEXTE_MODULE::MirrorTransformWithModule( int aOffset ) { - wxPoint tmp = GetTextPosition(); - tmp.x = aOffset - (tmp.x - aOffset); - SetTextPosition( tmp ); - tmp.y = GetPos0().y; - SetPos0( tmp ); + // Used in modedit, to transform the footprint + // the mirror is relative to the Y axis + // the position is mirrored, but the text itself is not mirrored + // Note also in module editor, m_Pos0 = m_Pos + m_Pos.x = aOffset - (m_Pos.x - aOffset); + m_Pos0 = m_Pos; NEGATE_AND_NORMALIZE_ANGLE_POS( m_Orient ); } -void TEXTE_MODULE::RotateWithModule( const wxPoint& aOffset, double aAngle ) +void TEXTE_MODULE::RotateTransformWithModule( const wxPoint& aOffset, double aAngle ) { - wxPoint pos = GetTextPosition(); - RotatePoint( &pos, aOffset, aAngle ); - SetTextPosition( pos ); - SetPos0( GetTextPosition() ); + // Used in modedit, to transform the footprint + // Note also in module editor, m_Pos0 = m_Pos + RotatePoint( &m_Pos, aOffset, aAngle ); + m_Pos0 = m_Pos; SetOrientation( GetOrientation() + aAngle ); } +void TEXTE_MODULE::MoveTransformWithModule( const wxPoint& aMoveVector ) +{ + // Used in modedit, to transform the footprint + // Note also in module editor, m_Pos0 = m_Pos + m_Pos0 += aMoveVector; + m_Pos = m_Pos0; +} void TEXTE_MODULE::Copy( TEXTE_MODULE* source ) { diff --git a/pcbnew/class_text_mod.h b/pcbnew/class_text_mod.h index f53ca488bb..6fb6e10af0 100644 --- a/pcbnew/class_text_mod.h +++ b/pcbnew/class_text_mod.h @@ -94,17 +94,21 @@ public: void Flip( const wxPoint& aCentre ); - /// Rotate entity during module rotation - void RotateWithModule( const wxPoint& aOffset, double aAngle ); + /// Rotate text during module rotation transform, in footprint editor + void RotateTransformWithModule( const wxPoint& aOffset, double aAngle ); /// Flip entity during module flip void FlipWithModule( int aOffset ); - /// Mirror entiry during module mirroring - void MirrorWithModule( int aOffset ); + /// Mirror text during module mirroring transform, in footprint editor + /// the text itself is not mirrored, only position. + void MirrorTransformWithModule( int aOffset ); + + /// move text during module mirroring transform, in footprint editor + void MoveTransformWithModule( const wxPoint& aMoveVector ); /// @deprecated it seems (but the type is used to 'protect' - //reference and value from deletion, and for identification) + // reference and value from deletion, and for identification) void SetType( TEXT_TYPE aType ) { m_Type = aType; } TEXT_TYPE GetType() const { return m_Type; } diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index ca0ccc137d..7e90c8a314 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -826,17 +826,10 @@ void FOOTPRINT_EDIT_FRAME::Transform( MODULE* module, int transform ) switch( transform ) { case ID_MODEDIT_MODULE_ROTATE: - module->Reference().RotateWithModule( wxPoint(0,0), angle ); - module->Value().RotateWithModule( wxPoint(0,0), angle ); - RotateMarkedItems( module, wxPoint(0,0), true ); break; case ID_MODEDIT_MODULE_MIRROR: - module->Reference().MirrorWithModule( 0 ); - module->Value().MirrorWithModule( 0 ); - - // Mirror pads and graphic items of the footprint: MirrorMarkedItems( module, wxPoint(0,0), true ); break;