From b907e74d375538eff71e4b4b0b8943d61ab84ecc Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 13 Sep 2013 17:45:40 +0200 Subject: [PATCH 01/19] Added more required layers for pads (adhesive, solder paste & solder mask) --- pcbnew/basepcbframe.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 9692ba9738..bd23efa35c 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -857,8 +857,17 @@ void PCB_BASE_FRAME::LoadSettings() view->SetRequired( ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( VIAS_VISIBLE ) ); view->SetRequired( ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ) ); view->SetRequired( ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ) ); + view->SetRequired( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + view->SetRequired( ADHESIVE_N_FRONT, ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + view->SetRequired( SOLDERPASTE_N_FRONT, ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + view->SetRequired( SOLDERMASK_N_FRONT, ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + view->SetRequired( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ), ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + view->SetRequired( ADHESIVE_N_BACK, ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + view->SetRequired( SOLDERPASTE_N_BACK, ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + view->SetRequired( SOLDERMASK_N_BACK, ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + view->SetLayerTarget( ITEM_GAL_LAYER( SELECTION ), KiGfx::TARGET_OVERLAY ); view->SetLayerTarget( ITEM_GAL_LAYER( GP_OVERLAY ), KiGfx::TARGET_OVERLAY ); From e0f3e2900b313d17fc7630a964e1458e837b4ad1 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 09:51:24 +0200 Subject: [PATCH 02/19] Changed alignment. --- common/system/jump_x86_64_sysv_elf_gas.S | 2 +- common/system/make_x86_64_sysv_elf_gas.S | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/common/system/jump_x86_64_sysv_elf_gas.S b/common/system/jump_x86_64_sysv_elf_gas.S index 40b65d7db6..c22f6e8038 100644 --- a/common/system/jump_x86_64_sysv_elf_gas.S +++ b/common/system/jump_x86_64_sysv_elf_gas.S @@ -41,7 +41,7 @@ .text .globl jump_fcontext .type jump_fcontext,@function -.align 16 +.align 8 jump_fcontext: movq %rbx, (%rdi) /* save RBX */ movq %r12, 0x8(%rdi) /* save R12 */ diff --git a/common/system/make_x86_64_sysv_elf_gas.S b/common/system/make_x86_64_sysv_elf_gas.S index ba040d0519..188cc931e5 100644 --- a/common/system/make_x86_64_sysv_elf_gas.S +++ b/common/system/make_x86_64_sysv_elf_gas.S @@ -40,8 +40,12 @@ .text .globl make_fcontext + +#ifndef __APPLE__ .type make_fcontext,@function -.align 16 +#endif + +.align 8 make_fcontext: leaq -0x58(%rdi), %rax /* reserve space for fcontext_t at top of context stack */ @@ -70,5 +74,8 @@ finish: xorq %rdi, %rdi /* exit code is zero */ call _exit@PLT /* exit application */ hlt -.size make_fcontext,.-make_fcontext + +#ifndef __APPLE__ +.size make_fcontext,.-make_fcontext +#endif From 9fbf45ebfca3ac86c63c5d1203570818eaa984aa Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 09:51:53 +0200 Subject: [PATCH 03/19] Fixed drawing outlined track segments. --- common/gal/opengl/opengl_gal.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 07b5238cf1..78cb44962e 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -278,10 +278,8 @@ void OPENGL_GAL::DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndP VECTOR2D( lineLength, -aWidth / 2.0 ) ); // Draw line caps - drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), - ( aWidth + lineWidth ) / 2, M_PI / 2 ); - drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), - ( aWidth + lineWidth ) / 2, -M_PI / 2 ); + drawStrokedSemiCircle( VECTOR2D( 0.0, 0.0 ), aWidth / 2, M_PI / 2 ); + drawStrokedSemiCircle( VECTOR2D( lineLength, 0.0 ), aWidth / 2, -M_PI / 2 ); Restore(); } From 86f520f76e27061cf71d1a5ed2aad9dbcd94ac59 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 09:52:47 +0200 Subject: [PATCH 04/19] Sorted out headers. --- pcbnew/tools/selection_area.cpp | 8 +++----- pcbnew/tools/selection_area.h | 13 ++++++------- pcbnew/tools/selection_tool.cpp | 2 ++ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pcbnew/tools/selection_area.cpp b/pcbnew/tools/selection_area.cpp index 33d73d6d68..c96751cb31 100644 --- a/pcbnew/tools/selection_area.cpp +++ b/pcbnew/tools/selection_area.cpp @@ -22,11 +22,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include - -#include - #include "selection_area.h" +#include +#include using namespace KiGfx; @@ -47,7 +45,7 @@ void SELECTION_AREA::ViewGetLayers( int aLayers[], int& aCount ) const } -void SELECTION_AREA::ViewDraw( int aLayer, GAL* aGal ) const +void SELECTION_AREA::ViewDraw( int aLayer, KiGfx::GAL* aGal ) const { aGal->SetLineWidth( 1.0 ); aGal->SetStrokeColor( COLOR4D( 1.0, 1.0, 0.4, 1.0 ) ); diff --git a/pcbnew/tools/selection_area.h b/pcbnew/tools/selection_area.h index 50db94f927..10079dccd5 100644 --- a/pcbnew/tools/selection_area.h +++ b/pcbnew/tools/selection_area.h @@ -25,15 +25,14 @@ #ifndef __SELECTION_AREA_H #define __SELECTION_AREA_H -#include -#include - -#include - -#include -#include #include #include +#include + +namespace KiGfx +{ +class GAL; +} /** * Class SELECTION_AREA diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index cd1a4be5a1..d9045a3b02 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -36,6 +36,8 @@ #include #include +#include +#include #include "selection_tool.h" #include "selection_area.h" From 573f9841df80dd67263ea407ff788b9434e6aef7 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 11:00:59 +0200 Subject: [PATCH 05/19] Better way of marking 'brightened' mode for items. --- common/painter.cpp | 22 ---------------------- common/view/view.cpp | 6 ------ include/base_struct.h | 4 ++-- include/painter.h | 7 ------- pcbnew/CMakeLists.txt | 1 + pcbnew/tools/selection_tool.cpp | 20 +++++++++++++++----- 6 files changed, 18 insertions(+), 42 deletions(-) diff --git a/common/painter.cpp b/common/painter.cpp index ddff0c9820..b6181c4210 100644 --- a/common/painter.cpp +++ b/common/painter.cpp @@ -79,25 +79,3 @@ void PAINTER::SetGAL( GAL* aGal ) { m_gal = aGal; } - - -void PAINTER::DrawBrightened( const VIEW_ITEM* aItem ) -{ - BOX2I box = aItem->ViewBBox(); - - RenderTarget oldTarget = m_gal->GetTarget(); - m_gal->SetTarget( TARGET_OVERLAY ); - - m_gal->PushDepth(); - m_gal->SetLayerDepth( -1.0 ); - - // Draw an outline that marks items as brightened - m_gal->SetIsStroke( true ); - m_gal->SetLineWidth( 100000.0 ); - m_gal->SetStrokeColor( m_brightenedColor ); - - m_gal->DrawRectangle( box.GetOrigin(), box.GetOrigin() + box.GetSize() ); - m_gal->PopDepth(); - - m_gal->SetTarget( oldTarget ); -} diff --git a/common/view/view.cpp b/common/view/view.cpp index 4409806c3c..1aa45473d2 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -596,12 +596,6 @@ void VIEW::draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate ) const if( !m_painter->Draw( aItem, aLayer ) ) aItem->ViewDraw( aLayer, m_gal ); // Alternative drawing method } - - // Draws a bright contour around the item - if( static_cast( aItem )->IsBrightened() ) - { - m_painter->DrawBrightened( aItem ); - } } diff --git a/include/base_struct.h b/include/base_struct.h index b61368e0d1..5843fc52fd 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -474,11 +474,11 @@ public: inline void SetSelected() { SetFlags( SELECTED ); ViewUpdate( COLOR ); } inline void SetHighlighted() { SetFlags( HIGHLIGHTED ); ViewUpdate( COLOR ); } - inline void SetBrightened() { SetFlags( BRIGHTENED ); ViewUpdate( COLOR ); } + inline void SetBrightened() { SetFlags( BRIGHTENED ); } inline void ClearSelected() { ClearFlags( SELECTED ); ViewUpdate( COLOR ); } inline void ClearHighlighted() { ClearFlags( HIGHLIGHTED ); ViewUpdate( COLOR ); } - inline void ClearBrightened() { ClearFlags( BRIGHTENED ); ViewUpdate( COLOR ); } + inline void ClearBrightened() { ClearFlags( BRIGHTENED ); } void SetModified(); diff --git a/include/painter.h b/include/painter.h index 1cbd2df94b..43b0363c2b 100644 --- a/include/painter.h +++ b/include/painter.h @@ -224,13 +224,6 @@ public: */ virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) = 0; - /** - * Function DrawBrightened - * Draws a special marking for the item. - * @param aItem is the item that is going to be marked. - */ - virtual void DrawBrightened( const VIEW_ITEM* aItem ); - protected: /// Instance of graphic abstraction layer that gives an interface to call /// commands used to draw (eg. DrawLine, DrawCircle, etc.) diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 02c943d0d9..bce6beeaa3 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -221,6 +221,7 @@ set(PCBNEW_CLASS_SRCS tools/selection_tool.cpp tools/selection_area.cpp + tools/bright_box.cpp tools/move_tool.cpp tools/pcb_tools.cpp ) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index d9045a3b02..b64eebbe00 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -41,6 +41,7 @@ #include "selection_tool.h" #include "selection_area.h" +#include "bright_box.h" using namespace KiGfx; using boost::optional; @@ -334,8 +335,8 @@ bool SELECTION_TOOL::selectMultiple() BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) { - OPT_TOOL_EVENT evt; BOARD_ITEM* current = NULL; + boost::shared_ptr brightBox; m_menu.reset( new CONTEXT_MENU() ); m_menu->SetTitle( _( "Clarify selection" ) ); @@ -352,10 +353,13 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) SetContextMenu( m_menu.get(), CMENU_NOW ); - while( evt = Wait() ) + while( OPT_TOOL_EVENT evt = Wait() ) { + wxLogDebug( wxT( "disambiguation menu event") ); + if( evt->Action() == TA_ContextMenuUpdate ) { + // User has pointed an item, so show it in a different way if( current ) current->ClearBrightened(); @@ -380,14 +384,20 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) { current = ( *aCollector )[*id]; current->SetSelected(); - return current; } - return NULL; + break; + } + + if( current && current->IsBrightened() ) + { + brightBox.reset( new BRIGHT_BOX( current ) ); + getView()->Add( brightBox.get() ); } } - return NULL; + getView()->MarkTargetDirty( TARGET_OVERLAY ); + return current; } From 8a1c97ea5606b27d18eaca6ea7bcf64c62e4d5b9 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 11:08:31 +0200 Subject: [PATCH 06/19] More careful check on the net number while drawing net labels for tracks. --- pcbnew/pcb_painter.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 6810f5049f..da3e69313b 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -273,7 +273,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) if( m_pcbSettings->m_netNamesOnTracks && IsNetnameLayer( aLayer ) ) { // If there is a net name - display it on the track - if( netNumber != 0 ) + if( netNumber > 0 ) { VECTOR2D line = ( end - start ); double length = line.EuclideanNorm(); @@ -283,6 +283,9 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) return; NETINFO_ITEM* net = ( (BOARD*) aTrack->GetParent() )->FindNet( netNumber ); + if( net == NULL ) + return; + std::string netName = std::string( net->GetShortNetname().mb_str() ); VECTOR2D textPosition = start + line / 2.0; // center of the track double textOrientation = -atan( line.y / line.x ); From 7207de9beae4af09a8fc01ce74621b44ca59c936 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 14:44:03 +0200 Subject: [PATCH 07/19] Fixed bounding box for dimension. --- pcbnew/class_dimension.cpp | 19 +++++++++++++++++++ pcbnew/class_dimension.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index c6dab49476..f7dacdc2a6 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -468,6 +468,15 @@ EDA_RECT DIMENSION::GetBoundingBox() const ymax = std::max( ymax, m_featureLineGO.y ); ymax = std::max( ymax, m_featureLineGF.y ); + xmin = std::min( xmin, m_featureLineDO.x ); + xmin = std::min( xmin, m_featureLineDF.x ); + ymin = std::min( ymin, m_featureLineDO.y ); + ymin = std::min( ymin, m_featureLineDF.y ); + xmax = std::max( xmax, m_featureLineDO.x ); + xmax = std::max( xmax, m_featureLineDF.x ); + ymax = std::max( ymax, m_featureLineDO.y ); + ymax = std::max( ymax, m_featureLineDF.y ); + bBox.SetX( xmin ); bBox.SetY( ymin ); bBox.SetWidth( xmax - xmin + 1 ); @@ -489,6 +498,16 @@ wxString DIMENSION::GetSelectMenuText() const } +const BOX2I DIMENSION::ViewBBox() const +{ + BOX2I dimBBox = BOX2I( VECTOR2I( GetBoundingBox().GetPosition() ), + VECTOR2I( GetBoundingBox().GetSize() ) ); + dimBBox.Merge( m_Text.ViewBBox() ); + + return dimBBox; +} + + void DIMENSION::ViewGetLayers( int aLayers[], int& aCount ) const { // Layer that simply displays the text diff --git a/pcbnew/class_dimension.h b/pcbnew/class_dimension.h index c92aae7433..25baeca80f 100644 --- a/pcbnew/class_dimension.h +++ b/pcbnew/class_dimension.h @@ -144,6 +144,9 @@ public: EDA_ITEM* Clone() const; + /// @copydoc VIEW_ITEM::ViewBBox() + virtual const BOX2I ViewBBox() const; + /// @copydoc VIEW_ITEM::ViewGetLayers() virtual void ViewGetLayers( int aLayers[], int& aCount ) const; From 373c8d6441da7d91d199fb020ad2f76e97a4db04 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 15:19:48 +0200 Subject: [PATCH 08/19] Changed to worksheet border color to match the rest of the worksheet layout. --- common/worksheet_item.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/common/worksheet_item.cpp b/common/worksheet_item.cpp index 9845e48f92..900770040c 100644 --- a/common/worksheet_item.cpp +++ b/common/worksheet_item.cpp @@ -200,6 +200,5 @@ void WORKSHEET_ITEM::drawBorder( GAL* aGal ) const aGal->SetIsStroke( true ); aGal->SetIsFill( false ); - aGal->SetStrokeColor( COLOR4D( 0.5, 0.5, 0.5, 1.0 ) ); aGal->DrawRectangle( origin, end ); } From 8e0674b7247aceb7e2f2ce6ba2c85c2a0e952e31 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 16:18:43 +0200 Subject: [PATCH 09/19] Unified marking of selected items. --- pcbnew/pcb_painter.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index da3e69313b..b85e0874e6 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -631,7 +631,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment ) { - COLOR4D color = m_pcbSettings->GetColor( NULL, aSegment->GetLayer() ); + COLOR4D color = m_pcbSettings->GetColor( aSegment, aSegment->GetLayer() ); m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); @@ -720,7 +720,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer ) if( aText->GetText().Length() == 0 ) return; - COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aText->GetLayer() ); + COLOR4D strokeColor = m_pcbSettings->GetColor( aText, aText->GetLayer() ); VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); double orientation = aText->GetOrientation() * M_PI / 1800.0; @@ -744,7 +744,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) if( aText->GetLength() == 0 ) return; - COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aLayer ); + COLOR4D strokeColor = m_pcbSettings->GetColor( aText, aLayer ); VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); double orientation = aText->GetDrawRotation() * M_PI / 1800.0; @@ -759,7 +759,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone ) { - COLOR4D color = m_pcbSettings->GetColor( NULL, aZone->GetLayer() ); + COLOR4D color = m_pcbSettings->GetColor( aZone, aZone->GetLayer() ); std::deque corners; PCB_RENDER_SETTINGS::DisplayZonesMode displayMode = m_pcbSettings->m_displayZoneMode; @@ -836,7 +836,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) else { int layer = aDimension->GetLayer(); - COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, layer ); + COLOR4D strokeColor = m_pcbSettings->GetColor( aDimension, layer ); m_gal->SetStrokeColor( strokeColor ); m_gal->SetIsFill( false ); @@ -855,14 +855,20 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) m_gal->DrawLine( VECTOR2D( aDimension->m_arrowG2O ), VECTOR2D( aDimension->m_arrowG2F ) ); // Draw text - draw( &aDimension->Text(), layer ); + TEXTE_PCB& text = aDimension->Text(); + VECTOR2D position( text.GetTextPosition().x, text.GetTextPosition().y ); + double orientation = text.GetOrientation() * M_PI / 1800.0; + + m_gal->SetLineWidth( text.GetThickness() ); + m_gal->SetTextAttributes( &text ); + m_gal->StrokeText( std::string( text.GetText().mb_str() ), position, orientation ); } } void PCB_PAINTER::draw( const PCB_TARGET* aTarget ) { - COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aTarget->GetLayer() ); + COLOR4D strokeColor = m_pcbSettings->GetColor( aTarget, aTarget->GetLayer() ); VECTOR2D position( aTarget->GetPosition() ); double size, radius; @@ -888,10 +894,8 @@ void PCB_PAINTER::draw( const PCB_TARGET* aTarget ) radius = aTarget->GetSize() / 3.0; } - m_gal->DrawLine( VECTOR2D( -size, 0.0 ), - VECTOR2D( size, 0.0 ) ); - m_gal->DrawLine( VECTOR2D( 0.0, -size ), - VECTOR2D( 0.0, size ) ); + m_gal->DrawLine( VECTOR2D( -size, 0.0 ), VECTOR2D( size, 0.0 ) ); + m_gal->DrawLine( VECTOR2D( 0.0, -size ), VECTOR2D( 0.0, size ) ); m_gal->DrawCircle( VECTOR2D( 0.0, 0.0 ), radius ); m_gal->Restore(); From ab21124b71361d188d58e3da42e61b38706c5a7d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 16 Sep 2013 16:46:02 +0200 Subject: [PATCH 10/19] Reenabled snapping for tools. --- common/tool/tool_dispatcher.cpp | 14 +++----------- common/view/wx_view_controls.cpp | 23 ++++++++++++++++++----- include/tool/tool_dispatcher.h | 2 -- include/view/view_controls.h | 24 ++---------------------- include/view/wx_view_controls.h | 6 ++++++ 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 03ff9ef9b3..ad3a38c857 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -122,15 +123,6 @@ int TOOL_DISPATCHER::decodeModifiers( const wxKeyboardState* aState ) const } -wxPoint TOOL_DISPATCHER::getCurrentMousePos() const -{ - wxPoint msp = wxGetMousePosition(); - wxPoint winp = m_editFrame->GetGalCanvas()->GetScreenPosition(); - - return wxPoint( msp.x - winp.x, msp.y - winp.y ); -} - - bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ) { ButtonState* st = m_buttons[aIndex]; @@ -208,7 +200,6 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) { bool motion = false, buttonEvents = false; - VECTOR2D pos; optional evt; int type = aEvent.GetEventType(); @@ -220,7 +211,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP || type == EVT_REFRESH_MOUSE ) { - pos = getView()->ToWorld ( getCurrentMousePos() ); + VECTOR2D screenPos = m_toolMgr->GetViewControls()->GetCursorPosition(); + VECTOR2D pos = getView()->ToWorld( screenPos ); if( pos != m_lastMousePos || type == EVT_REFRESH_MOUSE ) { motion = true; diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 1349948501..9776710676 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -65,11 +65,6 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) m_mousePosition.x = aEvent.GetX(); m_mousePosition.y = aEvent.GetY(); - if( m_snappingEnabled ) - m_cursorPosition = m_view->GetGAL()->GetGridPoint( m_mousePosition ); - else - m_cursorPosition = m_mousePosition; - bool isAutoPanning = false; if( m_autoPanEnabled ) @@ -222,6 +217,24 @@ void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled ) } +const VECTOR2D WX_VIEW_CONTROLS::GetMousePosition() const +{ + wxPoint msp = wxGetMousePosition(); + wxPoint winp = m_parentPanel->GetScreenPosition(); + + return VECTOR2D( msp.x - winp.x, msp.y - winp.y ); +} + + +const VECTOR2D WX_VIEW_CONTROLS::GetCursorPosition() const +{ + if( m_snappingEnabled ) + return m_view->GetGAL()->GetGridPoint( GetMousePosition() ); + else + return GetMousePosition(); +} + + bool WX_VIEW_CONTROLS::handleAutoPanning( const wxMouseEvent& aEvent ) { VECTOR2D p( aEvent.GetX(), aEvent.GetY() ); diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index f5b7bacae0..cb3273f744 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -76,8 +76,6 @@ private: bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ); bool handlePopupMenu( wxEvent& aEvent ); - wxPoint getCurrentMousePos() const; - int decodeModifiers( const wxKeyboardState* aState ) const; struct ButtonState; diff --git a/include/view/view_controls.h b/include/view/view_controls.h index 3b686d966c..ca539f467c 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -110,10 +110,7 @@ public: * * @return The current mouse pointer position. */ - virtual const VECTOR2D& GetMousePosition() const - { - return m_mousePosition; - } + virtual const VECTOR2D GetMousePosition() const = 0; /** * Function GetCursorPosition() @@ -122,21 +119,7 @@ public: * * @return The current cursor position in screen coordinates. */ - virtual const VECTOR2D& GetCursorPosition() const - { - return m_cursorPosition; - } - - /** - * Function SetCursorPosition() - * Allows to move the cursor to a different location. - * - * @param aPosition is the new location expressed in screen coordinates. - */ - virtual void SetCursorPosition( const VECTOR2D& aPosition ) - { - m_cursorPosition = aPosition; - } + virtual const VECTOR2D GetCursorPosition() const = 0; protected: /// Pointer to controlled VIEW. @@ -145,9 +128,6 @@ protected: /// Current mouse position VECTOR2D m_mousePosition; - /// Current cursor position - VECTOR2D m_cursorPosition; - /// Should the cursor snap to grid or move freely bool m_snappingEnabled; diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index 7c905f2f9c..8562afbb82 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -78,6 +78,12 @@ public: m_state = IDLE; } + /// @copydoc VIEW_CONTROLS::GetMousePosition() + virtual const VECTOR2D GetMousePosition() const; + + /// @copydoc VIEW_CONTROLS::GetCursorPosition() + virtual const VECTOR2D GetCursorPosition() const; + private: /// Possible states for WX_VIEW_CONTROLS enum State { From 3d0753c920461f717d04de0cc80ce120a7108de4 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 17 Sep 2013 11:19:15 +0200 Subject: [PATCH 11/19] Added get functions for high contrast mode fields. --- include/painter.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/painter.h b/include/painter.h index 43b0363c2b..5f9631506a 100644 --- a/include/painter.h +++ b/include/painter.h @@ -80,6 +80,16 @@ public: m_activeLayers.erase( aLayerId ); } + /** + * Function GetActiveLayers() + * Returns the set of currently active layers. + * @return The set of currently active layers. + */ + const std::set GetActiveLayers() + { + return m_activeLayers; + } + /** * Function ClearActiveLayers * Clears the list of active layers. @@ -89,6 +99,16 @@ public: m_activeLayers.clear(); } + /** + * Function IsActiveLayer + * Returns information whether the queried layer is marked as active. + * @return True if the queried layer is marked as active. + */ + inline bool IsActiveLayer( int aLayerId ) const + { + return ( m_activeLayers.count( aLayerId ) > 0 ); + } + /** * Function SetHighlight * Turns on/off highlighting - it may be done for the active layer or the specified net. @@ -114,6 +134,16 @@ public: m_hiContrastEnabled = aEnabled; } + /** + * Function GetHighContrast + * Returns information about high contrast display mode. + * @return True if the high contrast mode is on, false otherwise. + */ + inline bool GetHighContrast() const + { + return m_hiContrastEnabled; + } + /** * Function GetColor * Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer From f53dafd496bbc6beac9466990273ba5e23a0dd00 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 17 Sep 2013 11:21:42 +0200 Subject: [PATCH 12/19] Modules are marked to be on copper layer too. --- pcbnew/class_module.cpp | 3 ++- pcbnew/pcb_painter.cpp | 11 +++++++---- pcbnew/pcb_painter.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 0b68f61e64..680be27848 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1027,6 +1027,7 @@ void MODULE::SetOrientation( double newangle ) void MODULE::ViewGetLayers( int aLayers[], int& aCount ) const { - aCount = 1; + aCount = 2; aLayers[0] = ITEM_GAL_LAYER( SELECTION ); // Selection box + aLayers[1] = m_Layer; } diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index b85e0874e6..ea89ecd81d 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -229,7 +229,7 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) break; case PCB_MODULE_T: - draw( (MODULE*) aItem ); + draw( (MODULE*) aItem, aLayer ); break; case PCB_TEXT_T: @@ -700,11 +700,14 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment ) } -void PCB_PAINTER::draw( const MODULE* aModule ) +void PCB_PAINTER::draw( const MODULE* aModule, int aLayer ) { // For modules we have to draw a selection box if needed - if( aModule->IsSelected() ) - drawSelectionBox( aModule ); + if( aLayer == ITEM_GAL_LAYER( SELECTION ) ) + { + if( aModule->IsSelected() ) + drawSelectionBox( aModule ); + } } diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index 2e106f2b93..6899c54979 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -145,7 +145,7 @@ protected: void draw( const SEGVIA*, int ); void draw( const D_PAD*, int ); void draw( const DRAWSEGMENT* ); - void draw( const MODULE* ); + void draw( const MODULE*, int ); void draw( const TEXTE_PCB*, int ); void draw( const TEXTE_MODULE*, int ); void draw( const ZONE_CONTAINER* ); From c5c65d366d538882706ae68be87d4cc8110af76a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 17 Sep 2013 11:23:00 +0200 Subject: [PATCH 13/19] Selection box color is put into render settings. Selection layer is removed from active layers. --- pcbnew/pcb_painter.cpp | 3 ++- pcbnew/pcbframe.cpp | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index ea89ecd81d..a2cae1c427 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -76,6 +76,7 @@ void PCB_RENDER_SETTINGS::ImportLegacyColors( COLORS_DESIGN_SETTINGS* aSettings m_layerColors[ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 ); m_layerColors[ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 ); m_layerColors[ITEM_GAL_LAYER( WORKSHEET )] = COLOR4D( 0.5, 0.0, 0.0, 1.0 ); + m_layerColors[ITEM_GAL_LAYER( SELECTION )] = COLOR4D( 1.0, 1.0, 1.0, 0.5 ); // Netnames for copper layers for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) @@ -911,6 +912,6 @@ void PCB_PAINTER::drawSelectionBox( const VIEW_ITEM* aItem ) const m_gal->SetIsStroke( false ); m_gal->SetIsFill( true ); - m_gal->SetFillColor( COLOR4D( 1.0, 1.0, 1.0, 0.5 ) ); + m_gal->SetFillColor( m_pcbSettings->GetLayerColor( ITEM_GAL_LAYER( SELECTION ) ) ); m_gal->DrawRectangle( boundingBox.GetOrigin(), boundingBox.GetEnd() ); } diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index bf15c21989..e581f53a32 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -767,8 +767,7 @@ void PCB_EDIT_FRAME::setHighContrastLayer( LAYER_NUM aLayer ) LAYER_NUM layers[] = { GetNetnameLayer( aLayer ), ITEM_GAL_LAYER( VIAS_VISIBLE ), ITEM_GAL_LAYER( VIAS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_VISIBLE ), - ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ), - ITEM_GAL_LAYER( SELECTION ) + ITEM_GAL_LAYER( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ) }; for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) From 867067aa9c22b23e30d16d9d70cf7225c7eae9e2 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 17 Sep 2013 11:32:47 +0200 Subject: [PATCH 14/19] Selection in high contrast mode selects only items that are shown as active. --- pcbnew/tools/selection_tool.cpp | 46 ++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index b64eebbe00..6324937d73 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -118,7 +119,8 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) // Check if dragging event started within the currently selected items bounding box std::set::iterator it, it_end; - for( it = m_selectedItems.begin(), it_end = m_selectedItems.end(); it != it_end; ++it ) + for( it = m_selectedItems.begin(), it_end = m_selectedItems.end(); + it != it_end; ++it ) { BOX2I itemBox = (*it)->ViewBBox(); itemBox.Inflate( 500000 ); // Give some margin for gripping an item @@ -207,8 +209,8 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere ) break; default: - // Remove footprints, they have to be selected by clicking on area that does not - // contain anything but footprint + // Remove modules, they have to be selected by clicking on area that does not + // contain anything but module footprint for( int i = 0; i < collector.GetCount(); ++i ) { BOARD_ITEM* boardItem = ( collector )[i]; @@ -343,20 +345,26 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) int limit = std::min( 10, aCollector->GetCount() ); + int addedItems = 0; for( int i = 0; i < limit; ++i ) { wxString text; BOARD_ITEM* item = ( *aCollector )[i]; - text = item->GetSelectMenuText(); - m_menu->Add( text, i ); + if( selectable( item ) ) + { + text = item->GetSelectMenuText(); + m_menu->Add( text, i ); + addedItems++; + } } + if( addedItems == 0 ) // none of items was selectable + return NULL; + SetContextMenu( m_menu.get(), CMENU_NOW ); while( OPT_TOOL_EVENT evt = Wait() ) { - wxLogDebug( wxT( "disambiguation menu event") ); - if( evt->Action() == TA_ContextMenuUpdate ) { // User has pointed an item, so show it in a different way @@ -404,6 +412,30 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) bool SELECTION_TOOL::selectable( const BOARD_ITEM* aItem ) { BOARD* board = getModel( PCB_T ); + bool highContrast = getView()->GetPainter()->GetSettings()->GetHighContrast(); + + if( highContrast ) + { + bool onActive = false; + int layers[KiGfx::VIEW::VIEW_MAX_LAYERS], layers_count; + + // Filter out items that do not belong to active layers + std::set activeLayers = getView()->GetPainter()-> + GetSettings()->GetActiveLayers(); + aItem->ViewGetLayers( layers, layers_count ); + + for( int i = 0; i < layers_count; ++i ) + { + if( activeLayers.count( layers[i] ) > 0 ) // Item is on at least one active layer + { + onActive = true; + break; + } + } + + if( !onActive ) + return false; + } switch( aItem->Type() ) { From 300c066b683c03b6fecd4042604ce44c16517a3f Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 17 Sep 2013 13:47:33 +0200 Subject: [PATCH 15/19] The last fix to selection rules. --- pcbnew/tools/selection_tool.cpp | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 6324937d73..8559e81f6a 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -210,11 +210,11 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere ) default: // Remove modules, they have to be selected by clicking on area that does not - // contain anything but module footprint - for( int i = 0; i < collector.GetCount(); ++i ) + // contain anything but module footprint and not selectable items + for( int i = collector.GetCount() - 1; i >= 0 ; --i ) { BOARD_ITEM* boardItem = ( collector )[i]; - if( boardItem->Type() == PCB_MODULE_T ) + if( boardItem->Type() == PCB_MODULE_T || !selectable( boardItem ) ) collector.Remove( i ); } @@ -223,7 +223,7 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere ) { toggleSelection( collector[0] ); } - else + else if( collector.GetCount() > 1 ) { item = disambiguationMenu( &collector ); if( item ) @@ -345,22 +345,14 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) int limit = std::min( 10, aCollector->GetCount() ); - int addedItems = 0; for( int i = 0; i < limit; ++i ) { wxString text; BOARD_ITEM* item = ( *aCollector )[i]; - if( selectable( item ) ) - { - text = item->GetSelectMenuText(); - m_menu->Add( text, i ); - addedItems++; - } + text = item->GetSelectMenuText(); + m_menu->Add( text, i ); } - if( addedItems == 0 ) // none of items was selectable - return NULL; - SetContextMenu( m_menu.get(), CMENU_NOW ); while( OPT_TOOL_EVENT evt = Wait() ) @@ -411,7 +403,6 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) bool SELECTION_TOOL::selectable( const BOARD_ITEM* aItem ) { - BOARD* board = getModel( PCB_T ); bool highContrast = getView()->GetPainter()->GetSettings()->GetHighContrast(); if( highContrast ) @@ -437,6 +428,7 @@ bool SELECTION_TOOL::selectable( const BOARD_ITEM* aItem ) return false; } + BOARD* board = getModel( PCB_T ); switch( aItem->Type() ) { case PCB_VIA_T: From 3f6fa861905c0a28978cdd9700fde03b81910c12 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 17 Sep 2013 14:46:48 +0200 Subject: [PATCH 16/19] Fixed random color of worksheet border. --- common/worksheet_item.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/worksheet_item.cpp b/common/worksheet_item.cpp index 900770040c..9eefc3d908 100644 --- a/common/worksheet_item.cpp +++ b/common/worksheet_item.cpp @@ -97,9 +97,6 @@ void WORKSHEET_ITEM::ViewDraw( int aLayer, GAL* aGal ) const EDA_COLOR_T edaColor = ColorFindNearest( color.r * 255, color.g * 255, color.b * 255 ); drawList.BuildWorkSheetGraphicList( *m_pageInfo, *m_titleBlock, edaColor, edaColor ); - // Draw gray line that outlines the sheet size - drawBorder( aGal ); - // Draw all the components that make the page layout WS_DRAW_ITEM_BASE* item = drawList.GetFirst(); while( item ) @@ -125,6 +122,9 @@ void WORKSHEET_ITEM::ViewDraw( int aLayer, GAL* aGal ) const item = drawList.GetNext(); } + + // Draw gray line that outlines the sheet size + drawBorder( aGal ); } From 56c78d44bff25e7167124beec2ec27a2c4dff3aa Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 18 Sep 2013 17:04:07 +0200 Subject: [PATCH 17/19] Moved Type() method from EDA_ITEM to VIEW_ITEM. --- include/base_struct.h | 105 +------------------------------------ include/view/view_item.h | 109 +++++++++++++++++++++++++++++++++++++++ pcbnew/pcb_painter.cpp | 2 +- 3 files changed, 111 insertions(+), 105 deletions(-) diff --git a/include/base_struct.h b/include/base_struct.h index 5843fc52fd..9f615dc946 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -47,104 +47,6 @@ extern std::ostream& operator <<( std::ostream& out, const wxPoint& pt ); #endif -/** - * Enum KICAD_T - * is the set of class identification values, stored in EDA_ITEM::m_StructType - */ -enum KICAD_T { - NOT_USED = -1, ///< the 3d code uses this value - - EOT = 0, ///< search types array terminator (End Of Types) - - TYPE_NOT_INIT = 0, - PCB_T, - SCREEN_T, ///< not really an item, used to identify a screen - - // Items in pcb - PCB_MODULE_T, ///< class MODULE, a footprint - PCB_PAD_T, ///< class D_PAD, a pad in a footprint - PCB_LINE_T, ///< class DRAWSEGMENT, a segment not on copper layers - PCB_TEXT_T, ///< class TEXTE_PCB, text on a layer - PCB_MODULE_TEXT_T, ///< class TEXTE_MODULE, text in a footprint - PCB_MODULE_EDGE_T, ///< class EDGE_MODULE, a footprint edge - PCB_TRACE_T, ///< class TRACKE, a track segment (segment on a copper layer) - PCB_VIA_T, ///< class SEGVIA, a via (like a track segment on a copper layer) - PCB_ZONE_T, ///< class SEGZONE, a segment used to fill a zone area (segment on a - ///< copper layer) - PCB_MARKER_T, ///< class MARKER_PCB, a marker used to show something - PCB_DIMENSION_T, ///< class DIMENSION, a dimension (graphic item) - PCB_TARGET_T, ///< class PCB_TARGET, a target (graphic item) - PCB_ZONE_AREA_T, ///< class ZONE_CONTAINER, a zone area - PCB_ITEM_LIST_T, ///< class BOARD_ITEM_LIST, a list of board items - - // Schematic draw Items. The order of these items effects the sort order. - // It is currently ordered to mimic the old Eeschema locate behavior where - // the smallest item is the selected item. - SCH_MARKER_T, - SCH_JUNCTION_T, - SCH_NO_CONNECT_T, - SCH_BUS_WIRE_ENTRY_T, - SCH_BUS_BUS_ENTRY_T, - SCH_LINE_T, - SCH_BITMAP_T, - SCH_TEXT_T, - SCH_LABEL_T, - SCH_GLOBAL_LABEL_T, - SCH_HIERARCHICAL_LABEL_T, - SCH_FIELD_T, - SCH_COMPONENT_T, - SCH_SHEET_PIN_T, - SCH_SHEET_T, - - // Be prudent with these 3 types: - // they should be used only to locate a specific field type - // among SCH_FIELD_T items types - SCH_FIELD_LOCATE_REFERENCE_T, - SCH_FIELD_LOCATE_VALUE_T, - SCH_FIELD_LOCATE_FOOTPRINT_T, - - // General - SCH_SCREEN_T, - - /* - * Draw items in library component. - * - * The order of these items effects the sort order for items inside the - * "DRAW/ENDDRAW" section of the component definition in a library file. - * If you add a new draw item, type, please make sure you add it so the - * sort order is logical. - */ - LIB_COMPONENT_T, - LIB_ALIAS_T, - LIB_ARC_T, - LIB_CIRCLE_T, - LIB_TEXT_T, - LIB_RECTANGLE_T, - LIB_POLYLINE_T, - LIB_BEZIER_T, - LIB_PIN_T, - - /* - * Fields are not saved inside the "DRAW/ENDDRAW". Add new draw item - * types before this line. - */ - LIB_FIELD_T, - - /* - * For GerbView: items type: - */ - TYPE_GERBER_DRAW_ITEM, - - /* - * for Pl_Editor, in undo/redo commands - */ - TYPE_PL_EDITOR_LAYOUT, - - // End value - MAX_STRUCT_TYPE_ID -}; - - /** * Enum FILL_T * is the set of fill types used in plotting or drawing enclosed areas. @@ -440,12 +342,7 @@ public: EDA_ITEM( const EDA_ITEM& base ); virtual ~EDA_ITEM() { }; - /** - * Function Type - * returns the type of object. This attribute should never be changed - * after a constructor sets it, so there is no public "setter" method. - * @return KICAD_T - the type of object. - */ + /// @copydoc VIEW_ITEM::Type() KICAD_T Type() const { return m_StructType; } void SetTimeStamp( time_t aNewTimeStamp ) { m_TimeStamp = aNewTimeStamp; } diff --git a/include/view/view_item.h b/include/view/view_item.h index 8004c4264b..cbf8be7967 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -36,6 +36,104 @@ #include #include +/** + * Enum KICAD_T + * is the set of class identification values, stored in EDA_ITEM::m_StructType + */ +enum KICAD_T { + NOT_USED = -1, ///< the 3d code uses this value + + EOT = 0, ///< search types array terminator (End Of Types) + + TYPE_NOT_INIT = 0, + PCB_T, + SCREEN_T, ///< not really an item, used to identify a screen + + // Items in pcb + PCB_MODULE_T, ///< class MODULE, a footprint + PCB_PAD_T, ///< class D_PAD, a pad in a footprint + PCB_LINE_T, ///< class DRAWSEGMENT, a segment not on copper layers + PCB_TEXT_T, ///< class TEXTE_PCB, text on a layer + PCB_MODULE_TEXT_T, ///< class TEXTE_MODULE, text in a footprint + PCB_MODULE_EDGE_T, ///< class EDGE_MODULE, a footprint edge + PCB_TRACE_T, ///< class TRACKE, a track segment (segment on a copper layer) + PCB_VIA_T, ///< class SEGVIA, a via (like a track segment on a copper layer) + PCB_ZONE_T, ///< class SEGZONE, a segment used to fill a zone area (segment on a + ///< copper layer) + PCB_MARKER_T, ///< class MARKER_PCB, a marker used to show something + PCB_DIMENSION_T, ///< class DIMENSION, a dimension (graphic item) + PCB_TARGET_T, ///< class PCB_TARGET, a target (graphic item) + PCB_ZONE_AREA_T, ///< class ZONE_CONTAINER, a zone area + PCB_ITEM_LIST_T, ///< class BOARD_ITEM_LIST, a list of board items + + // Schematic draw Items. The order of these items effects the sort order. + // It is currently ordered to mimic the old Eeschema locate behavior where + // the smallest item is the selected item. + SCH_MARKER_T, + SCH_JUNCTION_T, + SCH_NO_CONNECT_T, + SCH_BUS_WIRE_ENTRY_T, + SCH_BUS_BUS_ENTRY_T, + SCH_LINE_T, + SCH_BITMAP_T, + SCH_TEXT_T, + SCH_LABEL_T, + SCH_GLOBAL_LABEL_T, + SCH_HIERARCHICAL_LABEL_T, + SCH_FIELD_T, + SCH_COMPONENT_T, + SCH_SHEET_PIN_T, + SCH_SHEET_T, + + // Be prudent with these 3 types: + // they should be used only to locate a specific field type + // among SCH_FIELD_T items types + SCH_FIELD_LOCATE_REFERENCE_T, + SCH_FIELD_LOCATE_VALUE_T, + SCH_FIELD_LOCATE_FOOTPRINT_T, + + // General + SCH_SCREEN_T, + + /* + * Draw items in library component. + * + * The order of these items effects the sort order for items inside the + * "DRAW/ENDDRAW" section of the component definition in a library file. + * If you add a new draw item, type, please make sure you add it so the + * sort order is logical. + */ + LIB_COMPONENT_T, + LIB_ALIAS_T, + LIB_ARC_T, + LIB_CIRCLE_T, + LIB_TEXT_T, + LIB_RECTANGLE_T, + LIB_POLYLINE_T, + LIB_BEZIER_T, + LIB_PIN_T, + + /* + * Fields are not saved inside the "DRAW/ENDDRAW". Add new draw item + * types before this line. + */ + LIB_FIELD_T, + + /* + * For GerbView: items type: + */ + TYPE_GERBER_DRAW_ITEM, + + /* + * for Pl_Editor, in undo/redo commands + */ + TYPE_PL_EDITOR_LAYOUT, + + // End value + MAX_STRUCT_TYPE_ID +}; + + namespace KiGfx { // Forward declarations @@ -81,6 +179,17 @@ public: delete[] m_groups; }; + /** + * Function Type + * returns the type of object. This attribute should never be changed + * after a constructor sets it, so there is no public "setter" method. + * @return KICAD_T - the type of object. + */ + virtual KICAD_T Type() const + { + return NOT_USED; + } + /** * Function ViewBBox() * returns the bounding box of the item covering all its layers. diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 5fa4c10e2e..dbc023eba7 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -207,7 +207,7 @@ PCB_PAINTER::PCB_PAINTER( GAL* aGal ) : bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) { // the "cast" applied in here clarifies which overloaded draw() is called - switch( item->Type() ) + switch( aItem->Type() ) { case PCB_ZONE_T: case PCB_TRACE_T: From 9b16651607ea5b657b729949df54509ed910a6db Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 18 Sep 2013 17:36:54 +0200 Subject: [PATCH 18/19] Added limits for VIEW scale values & panning area. --- common/view/view.cpp | 24 +++++++++++++++++++++++- include/view/view.h | 29 +++++++++++++++++++++++++++++ pcbnew/basepcbframe.cpp | 1 + 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index 529b966d49..5d529f4559 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -45,8 +45,11 @@ VIEW::VIEW( bool aIsDynamic ) : m_scale( 1.0 ), m_painter( NULL ), m_gal( NULL ), - m_dynamic( aIsDynamic ) + m_dynamic( aIsDynamic ), + m_scaleLimits( 15000.0, 1.0 ) { + m_panBoundary.SetMaximum(); + // Redraw everything at the beginning for( int i = 0; i < TARGETS_NUMBER; ++i ) MarkTargetDirty( i ); @@ -290,6 +293,11 @@ void VIEW::SetScale( double aScale ) void VIEW::SetScale( double aScale, const VECTOR2D& aAnchor ) { + if( aScale > m_scaleLimits.x ) + aScale = m_scaleLimits.x; + else if( aScale < m_scaleLimits.y ) + aScale = m_scaleLimits.y; + VECTOR2D a = ToScreen( aAnchor ); m_gal->SetZoomFactor( aScale ); @@ -308,6 +316,20 @@ void VIEW::SetScale( double aScale, const VECTOR2D& aAnchor ) void VIEW::SetCenter( const VECTOR2D& aCenter ) { m_center = aCenter; + + if( !m_panBoundary.Contains( aCenter ) ) + { + if( aCenter.x < m_panBoundary.GetLeft() ) + m_center.x = m_panBoundary.GetLeft(); + else if( aCenter.x > m_panBoundary.GetRight() ) + m_center.x = m_panBoundary.GetRight(); + + if( aCenter.y < m_panBoundary.GetTop() ) + m_center.y = m_panBoundary.GetTop(); + else if( aCenter.y > m_panBoundary.GetBottom() ) + m_center.y = m_panBoundary.GetBottom(); + } + m_gal->SetLookAtPoint( m_center ); m_gal->ComputeWorldScreenMatrix(); diff --git a/include/view/view.h b/include/view/view.h index 714283ef44..dc6a27691a 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -455,6 +455,29 @@ public: m_dirtyTargets[i] = true; } + /** + * Function SetPanBoundary() + * Sets limits for panning area. + * @param aBoundary is the box that limits panning area. + */ + void SetPanBoundary( const BOX2I& aBoundary ) + { + m_panBoundary = aBoundary; + } + + /** + * Function SetScaleLimits() + * Sets minimum and maximum values for scale. + * @param aMaximum is the maximum value for scale.. + * @param aMinimum is the minimum value for scale. + */ + void SetScaleLimits( double aMaximum, double aMinimum ) + { + wxASSERT_MSG( aMaximum > aMinimum, wxT( "I guess you passed parameters in wrong order" ) ); + + m_scaleLimits = VECTOR2D( aMaximum, aMinimum ); + } + static const int VIEW_MAX_LAYERS = 128; ///* maximum number of layers that may be shown private: @@ -588,6 +611,12 @@ private: /// Rendering order modifier for layers that are marked as top layers static const int TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS; + + /// Panning boundaries + BOX2I m_panBoundary; + + /// Zoom limits + VECTOR2D m_scaleLimits; }; } // namespace KiGfx diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index bd23efa35c..a6c0ec42ec 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -217,6 +217,7 @@ void PCB_BASE_FRAME::ViewReloadBoard( const BOARD* aBoard ) const view->Add( worksheet ); + view->SetPanBoundary( worksheet->ViewBBox() ); view->RecacheAllItems( true ); if( m_galCanvasActive ) From 9ec4520c451a355dd25975a4a2dc0413c4d91c5b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 18 Sep 2013 19:51:57 +0200 Subject: [PATCH 19/19] Added missing files --- pcbnew/tools/bright_box.cpp | 72 +++++++++++++++++++++++++++++++++++++ pcbnew/tools/bright_box.h | 62 ++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 pcbnew/tools/bright_box.cpp create mode 100644 pcbnew/tools/bright_box.h diff --git a/pcbnew/tools/bright_box.cpp b/pcbnew/tools/bright_box.cpp new file mode 100644 index 0000000000..f1c0802522 --- /dev/null +++ b/pcbnew/tools/bright_box.cpp @@ -0,0 +1,72 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "bright_box.h" +#include +#include + +using namespace KiGfx; + +BRIGHT_BOX::BRIGHT_BOX( BOARD_ITEM* aItem ) : + EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type + item( aItem ) +{ +} + + +const BOX2I BRIGHT_BOX::ViewBBox() const +{ + return item->ViewBBox(); +} + + +void BRIGHT_BOX::ViewGetLayers( int aLayers[], int& aCount ) const +{ + aLayers[0] = BrightBoxLayer; + aCount = 1; +} + + +void BRIGHT_BOX::ViewDraw( int aLayer, GAL* aGal ) const +{ + aGal->SetIsStroke( true ); + aGal->SetIsFill( false ); + aGal->SetLineWidth( LineWidth ); + aGal->SetStrokeColor( BrightColor ); + + if( item->Type() == PCB_TRACE_T ) + { + const TRACK* track = static_cast( item ); + + aGal->DrawSegment( track->GetStart(), track->GetEnd(), track->GetWidth() ); + } + else + { + BOX2I box = item->ViewBBox(); + + aGal->DrawRectangle( box.GetOrigin(), box.GetOrigin() + box.GetSize() ); + } +} + +const COLOR4D BRIGHT_BOX::BrightColor = KiGfx::COLOR4D( 0.0, 1.0, 0.0, 1.0 ); diff --git a/pcbnew/tools/bright_box.h b/pcbnew/tools/bright_box.h new file mode 100644 index 0000000000..e1748dbd28 --- /dev/null +++ b/pcbnew/tools/bright_box.h @@ -0,0 +1,62 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2013 CERN + * @author Maciej Suminski + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __BRIGHT_BOX_H +#define __BRIGHT_BOX_H + +#include +#include +#include +#include +#include + +/** + * Class BRIGHT_BOX + * + * Draws a decoration to indicate a brightened item. + */ +class BRIGHT_BOX : public EDA_ITEM +{ +public: + BRIGHT_BOX( BOARD_ITEM* aItem ); + ~BRIGHT_BOX() {}; + + virtual const BOX2I ViewBBox() const; + + void ViewDraw( int aLayer, KiGfx::GAL* aGal ) const; + void ViewGetLayers( int aLayers[], int& aCount ) const; + + void Show( int x, std::ostream& st ) const + { + } + +private: + static const int BrightBoxLayer = ITEM_GAL_LAYER( SELECTION ); + static const KiGfx::COLOR4D BrightColor; + static const double LineWidth = 100000.0; + + BOARD_ITEM* item; +}; + +#endif