From eac742e3dbb785aac8737d1c66f2c7fe5a52be2c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 10 Sep 2013 14:31:52 +0200 Subject: [PATCH 01/22] Added const modifiers where applicable. --- include/worksheet_shape_builder.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/worksheet_shape_builder.h b/include/worksheet_shape_builder.h index a7d4644172..a29ddfe55e 100644 --- a/include/worksheet_shape_builder.h +++ b/include/worksheet_shape_builder.h @@ -108,9 +108,9 @@ public: } // Accessors: - int GetPenWidth() { return m_penWidth; } - const wxPoint& GetStart() { return m_start; } - const wxPoint& GetEnd() { return m_end; } + int GetPenWidth() const { return m_penWidth; } + const wxPoint& GetStart() const { return m_start; } + const wxPoint& GetEnd() const { return m_end; } /** The function to draw a WS_DRAW_ITEM_LINE */ @@ -158,9 +158,9 @@ public: } // Accessors: - int GetPenWidth() { return m_penWidth; } - bool IsFilled() { return m_fill; } - const wxPoint& GetPosition() { return m_pos; } + int GetPenWidth() const { return m_penWidth; } + bool IsFilled() const { return m_fill; } + const wxPoint& GetPosition() const { return m_pos; } /** The function to draw a WS_DRAW_ITEM_POLYGON */ From b4d05af28f1876e51e6f6612b673181247e6372d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 10 Sep 2013 14:35:10 +0200 Subject: [PATCH 02/22] Modified default grid/origin settings. --- common/drawframe.cpp | 12 +++++------- common/gal/graphics_abstraction_layer.cpp | 4 +++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 9c0e500778..b0f27cc002 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -981,18 +981,16 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) // Switch to GAL rendering if( !m_galCanvasActive ) { - // Set up grid settings - gal->SetGridVisibility( IsGridVisible() ); - gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) ); - gal->SetGridOrigin( VECTOR2D( screen->GetGridOrigin() ) ); - gal->SetGridOriginMarkerSize( 15 ); - gal->SetGridDrawThreshold( 10 ); - // Set up viewport double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() ); view->SetScale( zoom ); view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) ); } + + // Set up grid settings + gal->SetGridVisibility( IsGridVisible() ); + gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) ); + gal->SetGridOrigin( VECTOR2D( screen->GetGridOrigin() ) ); } else { diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index 50e3d5723d..0a4c9a4dd9 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -48,12 +48,14 @@ GAL::GAL() : // Set grid defaults SetGridVisibility( true ); SetGridStyle( GRID_STYLE_LINES ); + SetGridOriginMarkerSize( 15 ); + SetGridDrawThreshold( 10 ); SetCoarseGrid( 10 ); SetGridLineWidth( 0.5 ); // Initialize the cursor shape SetCursorColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); - SetCursorSize( 20 ); + SetCursorSize( 15 ); SetCursorEnabled( true ); strokeFont.LoadNewStrokeFont( newstroke_font, newstroke_font_bufsize ); From 4551ded37e103fb9fc19f5ccf9f25e82e975412e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 10 Sep 2013 17:07:46 +0200 Subject: [PATCH 03/22] Some more missing D()->DBG() changes. --- .../dialogs/dialog_edit_component_in_schematic.cpp | 12 ++++++------ .../dialogs/dialog_edit_libentry_fields_in_lib.cpp | 12 ++++++------ eeschema/eeschema_config.cpp | 6 +++--- eeschema/lib_field.cpp | 2 +- eeschema/netform.cpp | 4 ++-- eeschema/template_fieldnames.cpp | 4 ++-- gerbview/class_aperture_macro.cpp | 2 +- gerbview/rs274x.cpp | 6 +++--- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp index 926d2d6080..2dfb3045b9 100644 --- a/eeschema/dialogs/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialogs/dialog_edit_component_in_schematic.cpp @@ -188,7 +188,7 @@ DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::DIALOG_EDIT_COMPONENT_IN_SCHEMATIC( wxWindow void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& event ) { - D( printf( "OnListItemDeselected()\n" ); ) + DBG( printf( "OnListItemDeselected()\n" ); ) if( !m_skipCopyFromPanel ) { @@ -200,7 +200,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemDeselected( wxListEvent& even void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnListItemSelected( wxListEvent& event ) { - D( printf( "OnListItemSelected()\n" ); ) + DBG( printf( "OnListItemSelected()\n" ); ) // remember the selected row, statically s_SelectedRow = event.GetIndex(); @@ -448,7 +448,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::moveUpButtonHandler( wxCommandEvent& ev // and in the fieldListCtrl SCH_FIELD tmp = m_FieldsBuf[fieldNdx - 1]; - D( printf( "tmp.m_Text=\"%s\" tmp.m_Name=\"%s\"\n", + DBG( printf( "tmp.m_Text=\"%s\" tmp.m_Name=\"%s\"\n", TO_UTF8( tmp.GetText() ), TO_UTF8( tmp.GetName( false ) ) ); ) m_FieldsBuf[fieldNdx - 1] = m_FieldsBuf[fieldNdx]; @@ -866,12 +866,12 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel() if( mirror == CMP_MIRROR_X ) { mirrorRadioBox->SetSelection( 1 ); - D( printf( "mirror=X,1\n" ); ) + DBG( printf( "mirror=X,1\n" ); ) } else if( mirror == CMP_MIRROR_Y ) { mirrorRadioBox->SetSelection( 2 ); - D( printf( "mirror=Y,2\n" ); ) + DBG( printf( "mirror=Y,2\n" ); ) } else mirrorRadioBox->SetSelection( 0 ); @@ -891,7 +891,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel() // Show the "Parts Locked" option? if( !m_LibEntry || !m_LibEntry->UnitsLocked() ) { - D( printf( "partsAreLocked->false\n" ); ) + DBG( printf( "partsAreLocked->false\n" ); ) partsAreLockedLabel->Show( false ); } diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index d4f5b2159e..8fe7d7c2a5 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -472,7 +472,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() // fixed fields: for( int i=0; im_Name ) ); ) + DBG( printf( "add template:%s\n", TO_UTF8( it->m_Name ) ); ) fld.SetName( it->m_Name ); fld.SetText( it->m_Value ); // empty? ok too. @@ -509,7 +509,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() } else { - D( printf( "match template:%s\n", TO_UTF8( libField->GetName() ) ); ) + DBG( printf( "match template:%s\n", TO_UTF8( libField->GetName() ) ); ) fld = *libField; // copy values from component, m_Name too } @@ -525,7 +525,7 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::initBuffers() if( !buf ) { - D( printf( "add cmp:%s\n", TO_UTF8( cmp->GetName() ) ); ) + DBG( printf( "add cmp:%s\n", TO_UTF8( cmp->GetName() ) ); ) m_FieldsBuf.push_back( *cmp ); } } @@ -721,11 +721,11 @@ bool DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copyPanelToSelectedField() if( field.GetId() >= MANDATORY_FIELDS ) { wxString name = fieldNameTextCtrl->GetValue(); - D( printf("name:%s\n", TO_UTF8( name ) ); ) + DBG( printf("name:%s\n", TO_UTF8( name ) ); ) field.SetName( name ); } - D( printf("setname:%s\n", TO_UTF8( field.GetName() ) ); ) + DBG( printf("setname:%s\n", TO_UTF8( field.GetName() ) ); ) setRowItem( fieldNdx, field ); // update fieldListCtrl diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 832a2b274f..2cd3e3931e 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -292,7 +292,7 @@ void SCH_EDIT_FRAME::OnSetOptions( wxCommandEvent& event ) for( unsigned i=0; i=0 && m_id < MANDATORY_FIELDS ) { - D(printf( "trying to set a MANDATORY_FIELD's name\n" );) + DBG(printf( "trying to set a MANDATORY_FIELD's name\n" );) return; } diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index fbb16a245b..3b2ae8b74a 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -417,7 +417,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam wxFileName tmpFile = aFullFileName; tmpFile.SetExt( INTERMEDIATE_NETLIST_EXT ); - D(printf("tmpFile:'%s'\n", TO_UTF8( tmpFile.GetFullPath() ) );) + DBG(printf("tmpFile:'%s'\n", TO_UTF8( tmpFile.GetFullPath() ) );) ret = helper.WriteGENERICNetList( tmpFile.GetFullPath() ); if( !ret ) @@ -435,7 +435,7 @@ bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileNam tmpFile.GetFullPath(), aFullFileName ); - D(printf("commandLine:'%s'\n", TO_UTF8( commandLine ) );) + DBG(printf("commandLine:'%s'\n", TO_UTF8( commandLine ) );) ProcessExecute( commandLine, wxEXEC_SYNC ); diff --git a/eeschema/template_fieldnames.cpp b/eeschema/template_fieldnames.cpp index c3c1730659..92ef9a90e9 100644 --- a/eeschema/template_fieldnames.cpp +++ b/eeschema/template_fieldnames.cpp @@ -151,7 +151,7 @@ int TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName ) { if( m_Fields[i].m_Name == aFieldName.m_Name ) { - D( printf( "inserting template fieldname:'%s' at %d\n", + DBG( printf( "inserting template fieldname:'%s' at %d\n", TO_UTF8( aFieldName.m_Name ), i ); ) m_Fields[i] = aFieldName; @@ -159,7 +159,7 @@ int TEMPLATES::AddTemplateFieldName( const TEMPLATE_FIELDNAME& aFieldName ) } } - // D(printf("appending template fieldname:'%s'\n", aFieldName.m_Name.utf8_str() );) + // DBG(printf("appending template fieldname:'%s'\n", aFieldName.m_Name.utf8_str() );) // the name is legal and not previously added to the config container, append // it and return its index within the container. diff --git a/gerbview/class_aperture_macro.cpp b/gerbview/class_aperture_macro.cpp index 28dabd5e19..3ea87648e1 100644 --- a/gerbview/class_aperture_macro.cpp +++ b/gerbview/class_aperture_macro.cpp @@ -409,7 +409,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, case AMP_UNKNOWN: default: - D( printf( "AM_PRIMITIVE::DrawBasicShape() err: unknown prim id %d\n",primitive_id) ); + DBG( printf( "AM_PRIMITIVE::DrawBasicShape() err: unknown prim id %d\n",primitive_id) ); break; } } diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index d65cc3bafa..e35c94bd2e 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -167,7 +167,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, if( m_GerbMetric ) conv_scale /= 25.4; -// D( printf( "%22s: Command <%c%c>\n", __func__, (command >> 8) & 0xFF, command & 0xFF ); ) +// DBG( printf( "%22s: Command <%c%c>\n", __func__, (command >> 8) & 0xFF, command & 0xFF ); ) switch( command ) { @@ -521,7 +521,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, m_ImageNegative = true; else m_ImageNegative = false; - D( printf( "%22s: IMAGE_POLARITY m_ImageNegative=%s\n", __func__, + DBG( printf( "%22s: IMAGE_POLARITY m_ImageNegative=%s\n", __func__, m_ImageNegative ? "true" : "false" ); ) break; @@ -531,7 +531,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, else GetLayerParams().m_LayerNegative = false; - D( printf( "%22s: LAYER_POLARITY m_LayerNegative=%s\n", __func__, + DBG( printf( "%22s: LAYER_POLARITY m_LayerNegative=%s\n", __func__, GetLayerParams().m_LayerNegative ? "true" : "false" ); ) break; From fa85685baae9f173ad64468485d789daee83d0ae Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 11 Sep 2013 10:30:39 +0200 Subject: [PATCH 04/22] Fixed COLOR4D( EDA_COLOR_T aColor ) and added asserts. --- common/gal/color4d.cpp | 6 +++--- include/gal/color4d.h | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/common/gal/color4d.cpp b/common/gal/color4d.cpp index b28b4d1b68..e2cd0af05e 100644 --- a/common/gal/color4d.cpp +++ b/common/gal/color4d.cpp @@ -30,9 +30,9 @@ using namespace KiGfx; COLOR4D::COLOR4D( EDA_COLOR_T aColor ) { - r = g_ColorRefs[aColor].m_Red; - g = g_ColorRefs[aColor].m_Green; - b = g_ColorRefs[aColor].m_Blue; + r = g_ColorRefs[aColor].m_Red / 255.0; + g = g_ColorRefs[aColor].m_Green / 255.0; + b = g_ColorRefs[aColor].m_Blue / 255.0; a = 1.0; } diff --git a/include/gal/color4d.h b/include/gal/color4d.h index d89a629c47..7398d796e8 100644 --- a/include/gal/color4d.h +++ b/include/gal/color4d.h @@ -28,6 +28,7 @@ #define COLOR4D_H_ #include +#include namespace KiGfx { @@ -55,6 +56,10 @@ public: COLOR4D( double aRed, double aGreen, double aBlue, double aAlpha ) : r( aRed ), g( aGreen ), b( aBlue ), a( aAlpha ) { + assert( r >= 0.0 && r <= 1.0 ); + assert( g >= 0.0 && g <= 1.0 ); + assert( b >= 0.0 && b <= 1.0 ); + assert( a >= 0.0 && a <= 1.0 ); } /** @@ -82,6 +87,8 @@ public: */ COLOR4D& Brighten( double aFactor ) { + assert( aFactor >= 0.0 && aFactor <= 1.0 ); + r = r * ( 1.0 - aFactor ) + aFactor; g = g * ( 1.0 - aFactor ) + aFactor; b = b * ( 1.0 - aFactor ) + aFactor; @@ -97,6 +104,8 @@ public: */ COLOR4D& Darken( double aFactor ) { + assert( aFactor >= 0.0 && aFactor <= 1.0 ); + r = r * ( 1.0 - aFactor ); g = g * ( 1.0 - aFactor ); b = b * ( 1.0 - aFactor ); @@ -126,6 +135,8 @@ public: */ COLOR4D Brightened( double aFactor ) const { + assert( aFactor >= 0.0 && aFactor <= 1.0 ); + return COLOR4D( r * ( 1.0 - aFactor ) + aFactor, g * ( 1.0 - aFactor ) + aFactor, b * ( 1.0 - aFactor ) + aFactor, @@ -140,6 +151,8 @@ public: */ COLOR4D Darkened( double aFactor ) const { + assert( aFactor >= 0.0 && aFactor <= 1.0 ); + return COLOR4D( r * ( 1.0 - aFactor ), g * ( 1.0 - aFactor ), b * ( 1.0 - aFactor ), From c0b6d159fc1d0764a4dd37da372e554872cc9627 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 11 Sep 2013 11:11:27 +0200 Subject: [PATCH 05/22] Added one more function to convert colors. --- common/gr_basic.cpp | 20 ++++++++++---------- include/colors.h | 8 ++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/common/gr_basic.cpp b/common/gr_basic.cpp index 7eaef89d57..8c7f70131d 100644 --- a/common/gr_basic.cpp +++ b/common/gr_basic.cpp @@ -1488,12 +1488,12 @@ bool ColorIsLight( EDA_COLOR_T aColor ) EDA_COLOR_T ColorFindNearest( const wxColour &aColor ) { - EDA_COLOR_T candidate = BLACK; + return ColorFindNearest( aColor.Red(), aColor.Green(), aColor.Blue() ); +} - // These are ints because we will subtract them later - int r = aColor.Red(); - int g = aColor.Green(); - int b = aColor.Blue(); +EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB ) +{ + EDA_COLOR_T candidate = BLACK; /* Find the 'nearest' color in the palette. This is fun. There is a gazilion of metrics for the color space and no one of the @@ -1511,11 +1511,11 @@ EDA_COLOR_T ColorFindNearest( const wxColour &aColor ) for( EDA_COLOR_T trying = BLACK; trying < NBCOLORS; trying = NextColor(trying) ) { const StructColors &c = g_ColorRefs[trying]; - int distance = (r - c.m_Red) * (r - c.m_Red) + - (g - c.m_Green) * (g - c.m_Green) + - (b - c.m_Blue) * (b - c.m_Blue); - if( distance < nearest_distance && c.m_Red >= r && - c.m_Green >= g && c.m_Blue >= b ) + int distance = (aR - c.m_Red) * (aR - c.m_Red) + + (aG - c.m_Green) * (aG - c.m_Green) + + (aB - c.m_Blue) * (aB - c.m_Blue); + if( distance < nearest_distance && c.m_Red >= aR && + c.m_Green >= aG && c.m_Blue >= aB ) { nearest_distance = distance; candidate = trying; diff --git a/include/colors.h b/include/colors.h index 7074b68abb..4cca37efa9 100644 --- a/include/colors.h +++ b/include/colors.h @@ -139,6 +139,14 @@ EDA_COLOR_T ColorByName( const wxChar *aName ); /// Find the nearest color match EDA_COLOR_T ColorFindNearest( const wxColour &aColor ); +/** + * Find the nearest color match + * @param aR is the red component of the color to be matched (in range 0-255) + * @param aG is the green component of the color to be matched (in range 0-255) + * @param aG is the blue component of the color to be matched (in range 0-255) + */ +EDA_COLOR_T ColorFindNearest( int aR, int aG, int aB ); + /** * Check if a color is light i.e. if black would be more readable than * white on it From f6b7ab79946413f5f007bce919e56b936ebebf6f Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 11 Sep 2013 11:34:10 +0200 Subject: [PATCH 06/22] Changed some 'magic numbers' into constants. Added const modifier in appropriate spots. --- common/gal/graphics_abstraction_layer.cpp | 5 ++--- common/worksheet.cpp | 2 +- eeschema/schframe.cpp | 2 +- include/gal/graphics_abstraction_layer.h | 6 ++++++ include/painter.h | 2 +- include/wxEeschemaStruct.h | 2 +- include/wxstruct.h | 2 +- pcbnew/tools/selection_area.h | 2 +- 8 files changed, 14 insertions(+), 9 deletions(-) diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index 0a4c9a4dd9..0282e69327 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -29,7 +29,6 @@ #include #include - using namespace KiGfx; GAL::GAL() : @@ -41,7 +40,7 @@ GAL::GAL() : SetFillColor( COLOR4D( 0.0, 0.0, 0.0, 0.0 ) ); SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); SetZoomFactor( 1.0 ); - SetDepthRange( VECTOR2D( -2048, 2047 ) ); + SetDepthRange( VECTOR2D( GAL::MIN_DEPTH, GAL::MAX_DEPTH ) ); SetFlip( false, false ); SetLineWidth( 1.0 ); @@ -114,7 +113,7 @@ void GAL::DrawGrid() // Draw the origin marker double origSize = static_cast( gridOriginMarkerSize ) / worldScale; - SetLayerDepth( 0.0 ); + SetLayerDepth( GAL::GRID_DEPTH ); SetIsFill( false ); SetIsStroke( true ); SetStrokeColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); diff --git a/common/worksheet.cpp b/common/worksheet.cpp index 4e2b1d116c..75f65b25cc 100644 --- a/common/worksheet.cpp +++ b/common/worksheet.cpp @@ -101,7 +101,7 @@ void EDA_DRAW_FRAME::DrawWorkSheet( wxDC* aDC, BASE_SCREEN* aScreen, int aLineWi } -wxString EDA_DRAW_FRAME::GetScreenDesc() +wxString EDA_DRAW_FRAME::GetScreenDesc() const { // Virtual function. In basic class, returns // an empty string. diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 653709f516..b295d8ec04 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -324,7 +324,7 @@ SCH_SCREEN* SCH_EDIT_FRAME::GetScreen() const } -wxString SCH_EDIT_FRAME::GetScreenDesc() +wxString SCH_EDIT_FRAME::GetScreenDesc() const { wxString s = m_CurrentSheet->PathHumanReadable(); diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 2b87606de0..77cb3c48a8 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -818,6 +818,9 @@ public: depthStack.pop(); } + /// Depth level on which the grid is drawn + static const int GRID_DEPTH = 1024; + protected: std::stack depthStack; ///< Stored depth values VECTOR2D screenSize; ///< Screen size in screen coordinates @@ -884,6 +887,9 @@ protected: * @param aCursorSize is the size of the cursor. */ virtual void initCursor( int aCursorSize ) = 0; + + static const int MIN_DEPTH = -2048; + static const int MAX_DEPTH = 2047; }; } // namespace KiGfx diff --git a/include/painter.h b/include/painter.h index d546981369..3a8a7c392f 100644 --- a/include/painter.h +++ b/include/painter.h @@ -195,7 +195,7 @@ public: * Returns pointer to current settings that are going to be used when drawing items. * @return Current rendering settings. */ - virtual RENDER_SETTINGS* GetSettings() + virtual RENDER_SETTINGS* GetSettings() const { return m_settings; } diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 8607c835f7..bcd4194409 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -356,7 +356,7 @@ public: */ void OnModify(); - virtual wxString GetScreenDesc(); + virtual wxString GetScreenDesc() const; void InstallConfigFrame( wxCommandEvent& event ); diff --git a/include/wxstruct.h b/include/wxstruct.h index 6cdd0fec65..d5dfd47842 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -499,7 +499,7 @@ public: EDA_DRAW_PANEL* GetCanvas() { return m_canvas; } - virtual wxString GetScreenDesc(); + virtual wxString GetScreenDesc() const; /** * Function GetScreen diff --git a/pcbnew/tools/selection_area.h b/pcbnew/tools/selection_area.h index 8cc380b4ab..28bf0f8b63 100644 --- a/pcbnew/tools/selection_area.h +++ b/pcbnew/tools/selection_area.h @@ -63,7 +63,7 @@ public: m_end = aEnd; } - void Show( int x, std::ostream& st) const + void Show( int x, std::ostream& st ) const { } From efa1ac380767e35d469eef95900fe272a9f53f3c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 11 Sep 2013 11:39:46 +0200 Subject: [PATCH 07/22] Moved GetColor() from PAINTER to RENDER_SETTINGS. Fixed recaching of custom items. --- common/view/view.cpp | 7 +-- include/painter.h | 20 ++++----- pcbnew/pcb_painter.cpp | 98 +++++++++++++++++++++--------------------- pcbnew/pcb_painter.h | 6 +-- 4 files changed, 66 insertions(+), 65 deletions(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index f8ba2db28f..4c16035a36 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -370,7 +370,7 @@ struct VIEW::updateItemsColor void operator()( VIEW_ITEM* aItem ) { // Obtain the color that should be used for coloring the item - const COLOR4D color = painter->GetColor( aItem, layer ); + const COLOR4D color = painter->GetSettings()->GetColor( aItem, layer ); int group = aItem->getGroup( layer ); if( group >= 0 ) @@ -672,7 +672,8 @@ struct VIEW::recacheLayer { int group = gal->BeginGroup(); aItem->setGroup( layer, group ); - view->m_painter->Draw( static_cast( aItem ), layer ); + if( !view->m_painter->Draw( aItem, layer ) ) + aItem->ViewDraw( layer, gal, BOX2I() ); // Alternative drawing method gal->EndGroup(); } else @@ -836,7 +837,7 @@ void VIEW::updateItemColor( VIEW_ITEM* aItem, int aLayer ) wxASSERT( (unsigned) aLayer < m_layers.size() ); // Obtain the color that should be used for coloring the item on the specific layerId - const COLOR4D color = m_painter->GetColor( aItem, aLayer ); + const COLOR4D color = m_painter->GetSettings()->GetColor( aItem, aLayer ); int group = aItem->getGroup( aLayer ); // Change the color, only if it has group assigned diff --git a/include/painter.h b/include/painter.h index 3a8a7c392f..7384b37c10 100644 --- a/include/painter.h +++ b/include/painter.h @@ -113,6 +113,16 @@ public: m_hiContrastEnabled = aEnabled; } + /** + * Function GetColor + * Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer + * using currently used render settings. + * @param aItem is the VIEW_ITEM. + * @param aLayer is the layer. + * @return The color. + */ + virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0; + protected: /** * Function update @@ -217,16 +227,6 @@ public: */ virtual void DrawBrightened( const VIEW_ITEM* aItem ); - /** - * Function GetColor - * Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer - * using currently used render settings. - * @param aItem is the VIEW_ITEM. - * @param aLayer is the layer. - * @return The color. - */ - virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) = 0; - protected: /// Instance of graphic abstraction layer that gives an interface to call /// commands used to draw (eg. DrawLine, DrawCircle, etc.) diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 45841207ed..21936aa3ca 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -137,6 +137,41 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ) } +const COLOR4D& PCB_RENDER_SETTINGS::GetColor( const VIEW_ITEM* aItem, int aLayer ) const +{ + int netCode = -1; + + if( aItem ) + { + if( static_cast( aItem )->IsSelected() ) + { + return m_layerColorsSel[aLayer]; + } + + // Try to obtain the netcode for the item + const BOARD_CONNECTED_ITEM* item = dynamic_cast( aItem ); + if( item ) + netCode = item->GetNet(); + } + + // Return grayish color for non-highlighted layers in the high contrast mode + if( m_hiContrastEnabled && m_activeLayers.count( aLayer ) == 0 ) + return m_hiContrastColor; + + // Single net highlight mode + if( m_highlightEnabled ) + { + if( netCode == m_highlightNetcode ) + return m_layerColorsHi[aLayer]; + else + return m_layerColorsDark[aLayer]; + } + + // No special modificators enabled + return m_layerColors[aLayer]; +} + + void PCB_RENDER_SETTINGS::update() { // Calculate darkened/highlighted variants of layer colors @@ -159,41 +194,6 @@ PCB_PAINTER::PCB_PAINTER( GAL* aGal ) : } -const COLOR4D& PCB_PAINTER::GetColor( const VIEW_ITEM* aItem, int aLayer ) -{ - int netCode = -1; - - if( aItem ) - { - if( static_cast( aItem )->IsSelected() ) - { - return m_pcbSettings->m_layerColorsSel[aLayer]; - } - - // Try to obtain the netcode for the item - const BOARD_CONNECTED_ITEM* item = dynamic_cast( aItem ); - if( item ) - netCode = item->GetNet(); - } - - // Return grayish color for non-highlighted layers in the high contrast mode - if( m_pcbSettings->m_hiContrastEnabled && m_pcbSettings->m_activeLayers.count( aLayer ) == 0 ) - return m_pcbSettings->m_hiContrastColor; - - // Single net highlight mode - if( m_pcbSettings->m_highlightEnabled ) - { - if( netCode == m_pcbSettings->m_highlightNetcode ) - return m_pcbSettings->m_layerColorsHi[aLayer]; - else - return m_pcbSettings->m_layerColorsDark[aLayer]; - } - - // No special modificators enabled - return m_pcbSettings->m_layerColors[aLayer]; -} - - bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) { const BOARD_ITEM* item = static_cast( aItem ); @@ -280,8 +280,8 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) double textSize = std::min( static_cast( width ), length / netName.length() ); // Set a proper color for the label - color = GetColor( aTrack, aTrack->GetLayer() ); - COLOR4D labelColor = GetColor( NULL, aLayer ); + color = m_pcbSettings->GetColor( aTrack, aTrack->GetLayer() ); + COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer ); if( color.GetBrightness() > 0.5 ) m_gal->SetStrokeColor( labelColor.Inverted() ); @@ -301,7 +301,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) else if( IsCopperLayer( aLayer )) { // Draw a regular track - color = GetColor( aTrack, aLayer ); + color = m_pcbSettings->GetColor( aTrack, aLayer ); m_gal->SetStrokeColor( color ); m_gal->SetIsStroke( true ); @@ -340,7 +340,7 @@ void PCB_PAINTER::draw( const SEGVIA* aVia, int aLayer ) else return; - color = GetColor( aVia, aLayer ); + color = m_pcbSettings->GetColor( aVia, aLayer ); if( m_pcbSettings->m_sketchModeSelect[VIAS_VISIBLE] ) { @@ -419,8 +419,8 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) m_gal->SetMirrored( false ); // Set a proper color for the label - color = GetColor( aPad, aPad->GetLayer() ); - COLOR4D labelColor = GetColor( NULL, aLayer ); + color = m_pcbSettings->GetColor( aPad, aPad->GetLayer() ); + COLOR4D labelColor = m_pcbSettings->GetColor( NULL, aLayer ); if( color.GetBrightness() > 0.5 ) m_gal->SetStrokeColor( labelColor.Inverted() ); @@ -466,7 +466,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) } // Pad drawing - color = GetColor( aPad, aLayer ); + color = m_pcbSettings->GetColor( aPad, aLayer ); if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] ) { // Outline mode @@ -619,7 +619,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment ) { - COLOR4D color = GetColor( NULL, aSegment->GetLayer() ); + COLOR4D color = m_pcbSettings->GetColor( NULL, aSegment->GetLayer() ); m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); @@ -708,7 +708,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer ) if( aText->GetText().Length() == 0 ) return; - COLOR4D strokeColor = GetColor( NULL, aText->GetLayer() ); + COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aText->GetLayer() ); VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); double orientation = aText->GetOrientation() * M_PI / 1800.0; @@ -732,8 +732,8 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) if( aText->GetLength() == 0 ) return; - COLOR4D strokeColor = GetColor( NULL, aLayer ); - VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y); + COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aLayer ); + VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); double orientation = aText->GetDrawRotation() * M_PI / 1800.0; m_gal->SetStrokeColor( strokeColor ); @@ -747,7 +747,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone ) { - COLOR4D color = GetColor( NULL, aZone->GetLayer() ); + COLOR4D color = m_pcbSettings->GetColor( NULL, aZone->GetLayer() ); std::deque corners; PCB_RENDER_SETTINGS::DisplayZonesMode displayMode = m_pcbSettings->m_displayZoneMode; @@ -824,7 +824,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) else { int layer = aDimension->GetLayer(); - COLOR4D strokeColor = GetColor( NULL, layer ); + COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, layer ); m_gal->SetStrokeColor( strokeColor ); m_gal->SetIsFill( false ); @@ -850,7 +850,7 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer ) void PCB_PAINTER::draw( const PCB_TARGET* aTarget ) { - COLOR4D strokeColor = GetColor( NULL, aTarget->GetLayer() ); + COLOR4D strokeColor = m_pcbSettings->GetColor( NULL, aTarget->GetLayer() ); VECTOR2D position( aTarget->GetPosition() ); double size, radius; diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index 952a042f39..c8ce09a4bb 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -85,6 +85,9 @@ public: */ void LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ); + /// @copydoc RENDER_SETTINGS::GetColor() + virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const; + protected: /// @copydoc RENDER_SETTINGS::Update() void update(); @@ -130,9 +133,6 @@ public: m_pcbSettings = dynamic_cast( aSettings ); } - /// @copydoc PAINTER::GetColor() - virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ); - protected: PCB_RENDER_SETTINGS* m_pcbSettings; From 60c84abfe4779f4392522a58849874ee371ee03d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 11 Sep 2013 12:09:22 +0200 Subject: [PATCH 08/22] Changed lifetime of RENDER_SETTINGS (now they are accessible right after PAINTER object is created). --- common/painter.cpp | 5 ++--- include/painter.h | 11 ++++------- pcbnew/pcb_painter.cpp | 2 ++ pcbnew/pcb_painter.h | 4 +++- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/common/painter.cpp b/common/painter.cpp index 5787b5427c..8b9d1c6568 100644 --- a/common/painter.cpp +++ b/common/painter.cpp @@ -64,14 +64,13 @@ void RENDER_SETTINGS::update() PAINTER::PAINTER( GAL* aGal ) : - m_gal( aGal ), m_settings( NULL ), m_brightenedColor( 0.0, 1.0, 0.0, 0.9 ) + m_gal( aGal ), m_brightenedColor( 0.0, 1.0, 0.0, 0.9 ) { } PAINTER::~PAINTER() { - delete m_settings; } @@ -91,7 +90,7 @@ void PAINTER::DrawBrightened( const VIEW_ITEM* aItem ) m_gal->PushDepth(); m_gal->SetLayerDepth( -1.0 ); - // Draw semitransparent box that marks items as brightened + // Draw an outline that marks items as brightened m_gal->SetIsStroke( true ); m_gal->SetLineWidth( 100000.0 ); m_gal->SetStrokeColor( m_brightenedColor ); diff --git a/include/painter.h b/include/painter.h index 7384b37c10..c846bdc98d 100644 --- a/include/painter.h +++ b/include/painter.h @@ -32,7 +32,7 @@ #include #include - +#include class EDA_ITEM; class COLORS_DESIGN_SETTINGS; @@ -187,10 +187,7 @@ public: */ virtual void ApplySettings( RENDER_SETTINGS* aSettings ) { - if( m_settings ) - delete m_settings; - - m_settings = aSettings; + m_settings.reset( aSettings ); } /** @@ -207,7 +204,7 @@ public: */ virtual RENDER_SETTINGS* GetSettings() const { - return m_settings; + return m_settings.get(); } /** @@ -233,7 +230,7 @@ protected: GAL* m_gal; /// Colors and display modes settings that are going to be used when drawing items. - RENDER_SETTINGS* m_settings; + boost::shared_ptr m_settings; /// Color of brightened item frame COLOR4D m_brightenedColor; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 21936aa3ca..742ef0e188 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -191,6 +191,8 @@ void PCB_RENDER_SETTINGS::update() PCB_PAINTER::PCB_PAINTER( GAL* aGal ) : PAINTER( aGal ) { + m_settings.reset( new PCB_RENDER_SETTINGS() ); + m_pcbSettings = (PCB_RENDER_SETTINGS*) m_settings.get(); } diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index c8ce09a4bb..d7f922e623 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -27,6 +27,7 @@ #define __CLASS_PCB_PAINTER_H #include +#include #include class EDA_ITEM; @@ -130,10 +131,11 @@ public: PAINTER::ApplySettings( aSettings ); // Store PCB specific render settings - m_pcbSettings = dynamic_cast( aSettings ); + m_pcbSettings = (PCB_RENDER_SETTINGS*) m_settings.get(); //dynamic_cast( aSettings ); } protected: + /// Just a properly casted pointer to settings PCB_RENDER_SETTINGS* m_pcbSettings; // Drawing functions for various types of PCB-specific items From 7da892b49acc276ecbea1385f58596028a023901 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 11 Sep 2013 14:42:12 +0200 Subject: [PATCH 09/22] Added drawing of worksheet layout. --- common/CMakeLists.txt | 15 +- common/painter.cpp | 15 +- common/worksheet_item.cpp | 205 ++++++++++++++++++++++ include/layers_id_colors_and_visibility.h | 4 +- include/painter.h | 7 + include/worksheet_item.h | 163 +++++++++++++++++ pcbnew/basepcbframe.cpp | 15 ++ pcbnew/pcb_painter.cpp | 1 + 8 files changed, 410 insertions(+), 15 deletions(-) create mode 100644 common/worksheet_item.cpp create mode 100644 include/worksheet_item.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 67b27f893d..3c3630b85a 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -32,6 +32,7 @@ set(GAL_SRCS # Common part drawpanel_gal.cpp painter.cpp + worksheet_item.cpp gal/graphics_abstraction_layer.cpp gal/stroke_font.cpp gal/color4d.cpp @@ -156,13 +157,13 @@ set(COMMON_SRCS system/fcontext.s - tool/tool_base.cpp - tool/tool_manager.cpp - tool/tool_dispatcher.cpp - tool/tool_event.cpp - tool/tool_interactive.cpp - tool/context_menu.cpp - ) + tool/tool_base.cpp + tool/tool_manager.cpp + tool/tool_dispatcher.cpp + tool/tool_event.cpp + tool/tool_interactive.cpp + tool/context_menu.cpp +) add_library(common STATIC ${COMMON_SRCS}) diff --git a/common/painter.cpp b/common/painter.cpp index 8b9d1c6568..ddff0c9820 100644 --- a/common/painter.cpp +++ b/common/painter.cpp @@ -32,13 +32,14 @@ using namespace KiGfx; RENDER_SETTINGS::RENDER_SETTINGS() { // Set the default initial values - m_highlightFactor = 0.5; - m_selectFactor = 0.5; - m_layerOpacity = 0.8; - m_highlightEnabled = false; - m_hiContrastEnabled = false; - m_hiContrastFactor = 0.2; - m_outlineWidth = 1; + m_highlightFactor = 0.5; + m_selectFactor = 0.5; + m_layerOpacity = 0.8; + m_highlightEnabled = false; + m_hiContrastEnabled = false; + m_hiContrastFactor = 0.2; + m_outlineWidth = 1; + m_worksheetLineWidth = 100000; // Store the predefined colors used in KiCad in format used by GAL for( int i = 0; i < NBCOLORS; i++ ) diff --git a/common/worksheet_item.cpp b/common/worksheet_item.cpp new file mode 100644 index 0000000000..40790de477 --- /dev/null +++ b/common/worksheet_item.cpp @@ -0,0 +1,205 @@ +/* + * 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 + */ + +/** + * @file worksheet_item.cpp + * @brief Class that handles properties and drawing of worksheet layout. + */ + +#include +#include +#include +#include +#include +#include + +using namespace KiGfx; + +WORKSHEET_ITEM::WORKSHEET_ITEM( const std::string& aFileName, const std::string& aSheetName, + const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ) : + EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type + m_fileName( aFileName ), m_sheetName( aSheetName ), + m_titleBlock( aTitleBlock ), m_pageInfo( aPageInfo ), m_sheetNumber( 1 ), m_sheetCount( 1 ) {} + + +void WORKSHEET_ITEM::SetPageInfo( const PAGE_INFO* aPageInfo ) +{ + m_pageInfo = aPageInfo; + ViewUpdate( GEOMETRY ); +} + + +void WORKSHEET_ITEM::SetTitleBlock( const TITLE_BLOCK* aTitleBlock ) +{ + m_titleBlock = aTitleBlock; + ViewUpdate( GEOMETRY ); +} + + +const BOX2I WORKSHEET_ITEM::ViewBBox() const +{ + BOX2I bbox; + + if( m_pageInfo != NULL ) + { + bbox.SetOrigin( VECTOR2I( 0, 0 ) ); + bbox.SetEnd( VECTOR2I( m_pageInfo->GetWidthMils() * 25400, + m_pageInfo->GetHeightMils() * 25400 ) ); + } + else + { + bbox.SetMaximum(); + } + + return bbox; +} + + +void WORKSHEET_ITEM::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const +{ + RENDER_SETTINGS* settings = m_view->GetPainter()->GetSettings(); + wxString fileName( m_fileName ); + wxString sheetName( m_sheetName ); + WS_DRAW_ITEM_LIST drawList; + + drawList.SetPenSize( settings->GetWorksheetLineWidth() ); + // Sorry,but I don't get this multi #ifdef from include/convert_to_biu.h, so here goes a magic + // number. IU_PER_MILS should be 25400 (as in a different compiltion unit), but somehow + // it equals 1 in this case.. + drawList.SetMilsToIUfactor( 25400 /* IU_PER_MILS */ ); + drawList.SetSheetNumber( m_sheetNumber ); + drawList.SetSheetCount( m_sheetCount ); + drawList.SetFileName( fileName ); + drawList.SetSheetName( sheetName ); + + COLOR4D color = settings->GetColor( this, aLayer ); + 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 ) + { + switch( item->GetType() ) + { + case WS_DRAW_ITEM_BASE::wsg_line: + draw( static_cast( item ), aGal ); + break; + + case WS_DRAW_ITEM_BASE::wsg_rect: + draw( static_cast( item ), aGal ); + break; + + case WS_DRAW_ITEM_BASE::wsg_poly: + draw( static_cast( item ), aGal ); + break; + + case WS_DRAW_ITEM_BASE::wsg_text: + draw( static_cast( item ), aGal ); + break; + } + + item = drawList.GetNext(); + } +} + + +void WORKSHEET_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const +{ + aCount = 1; + aLayers[0] = ITEM_GAL_LAYER( WORKSHEET ); +} + + +void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_LINE* aItem, GAL* aGal ) const +{ + aGal->SetIsStroke( true ); + aGal->SetIsFill( false ); + aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetLineWidth( aItem->GetPenWidth() ); + aGal->DrawLine( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) ); +} + + +void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_RECT* aItem, GAL* aGal ) const +{ + aGal->SetIsStroke( true ); + aGal->SetIsFill( false ); + aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetLineWidth( aItem->GetPenWidth() ); + aGal->DrawRectangle( VECTOR2D( aItem->GetStart() ), VECTOR2D( aItem->GetEnd() ) ); +} + + +void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_POLYGON* aItem, GAL* aGal ) const +{ + std::deque corners; + BOOST_FOREACH( wxPoint point, aItem->m_Corners ) + { + corners.push_back( VECTOR2D( point ) ); + } + + if( aItem->IsFilled() ) + { + aGal->SetFillColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetIsFill( true ); + aGal->SetIsStroke( false ); + aGal->DrawPolygon( corners ); + } + else + { + aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetIsFill( false ); + aGal->SetIsStroke( true ); + aGal->SetLineWidth( aItem->GetPenWidth() ); + aGal->DrawPolyline( corners ); + } +} + + +void WORKSHEET_ITEM::draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const +{ + VECTOR2D position( aItem->GetTextPosition().x, aItem->GetTextPosition().y ); + + aGal->SetStrokeColor( COLOR4D( aItem->GetColor() ) ); + aGal->SetLineWidth( aItem->GetThickness() ); + aGal->SetTextAttributes( aItem ); + aGal->StrokeText( std::string( aItem->GetText().mb_str() ), position, 0.0 ); +} + + +void WORKSHEET_ITEM::drawBorder( GAL* aGal ) const +{ + VECTOR2D origin = VECTOR2D( 0.0, 0.0 ); + VECTOR2D end = VECTOR2D( m_pageInfo->GetWidthMils() * 25400, + m_pageInfo->GetHeightMils() * 25400 ); + + aGal->SetIsStroke( true ); + aGal->SetIsFill( false ); + aGal->SetStrokeColor( COLOR4D( 0.5, 0.5, 0.5, 1.0 ) ); + aGal->DrawRectangle( origin, end ); +} diff --git a/include/layers_id_colors_and_visibility.h b/include/layers_id_colors_and_visibility.h index 3ab011d3b5..6959ad3fd7 100644 --- a/include/layers_id_colors_and_visibility.h +++ b/include/layers_id_colors_and_visibility.h @@ -241,6 +241,7 @@ enum PCB_VISIBLE PADS_NETNAMES_VISIBLE, SELECTION, + WORKSHEET, GP_OVERLAY, // General purpose overlay END_PCB_VISIBLE_LIST // sentinel @@ -290,7 +291,8 @@ const LAYER_NUM GalLayerOrder[] = ITEM_GAL_LAYER( LAYER_1_NETNAMES_VISIBLE ), LAYER_N_BACK, ADHESIVE_N_BACK, SOLDERPASTE_N_BACK, SILKSCREEN_N_BACK, - ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ) + ITEM_GAL_LAYER( MOD_TEXT_BK_VISIBLE ), + ITEM_GAL_LAYER( WORKSHEET ) }; /** diff --git a/include/painter.h b/include/painter.h index c846bdc98d..1cbd2df94b 100644 --- a/include/painter.h +++ b/include/painter.h @@ -32,6 +32,7 @@ #include #include +#include #include class EDA_ITEM; @@ -123,6 +124,11 @@ public: */ virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0; + float GetWorksheetLineWidth() const + { + return m_worksheetLineWidth; + } + protected: /** * Function update @@ -147,6 +153,7 @@ protected: float m_selectFactor; ///< Specifies how color of selected items is changed float m_layerOpacity; ///< Determines opacity of all layers float m_outlineWidth; ///< Line width used when drawing outlines + float m_worksheetLineWidth; ///< Line width used when drawing worksheet /// Map of colors that were usually used for display std::map m_legacyColorMap; diff --git a/include/worksheet_item.h b/include/worksheet_item.h new file mode 100644 index 0000000000..e4cff49fa3 --- /dev/null +++ b/include/worksheet_item.h @@ -0,0 +1,163 @@ +/* + * 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 + */ + +/** + * @file worksheet_item.h + * @brief Class that handles properties and drawing of worksheet layout. + */ + +#ifndef WORKSHEET_ITEM_H +#define WORKSHEET_ITEM_H + +#include + +class BOARD; +class PAGE_INFO; +class TITLE_BLOCK; +class WS_DRAW_ITEM_LINE; +class WS_DRAW_ITEM_RECT; +class WS_DRAW_ITEM_POLYGON; +class WS_DRAW_ITEM_TEXT; + +namespace KiGfx +{ +class GAL; + +class WORKSHEET_ITEM : public EDA_ITEM +{ +public: + WORKSHEET_ITEM( const std::string& aFileName, const std::string& aSheetName, + const PAGE_INFO* aPageInfo, const TITLE_BLOCK* aTitleBlock ); + ~WORKSHEET_ITEM() {} + + /** + * Function SetFileName() + * Sets the file name displayed in the title block. + * + * @param aFileName is the new file name. + */ + void SetFileName( const std::string& aFileName ) + { + m_fileName = aFileName; + ViewUpdate( GEOMETRY ); + } + + /** + * Function SetSheetName() + * Sets the sheet name displayed in the title block. + * + * @param aSheetName is the new sheet name. + */ + void SetSheetName( const std::string& aSheetName ) + { + m_sheetName = aSheetName; + ViewUpdate( GEOMETRY ); + } + + /** + * Function SetPageInfo() + * Changes the PAGE_INFO object used to draw the worksheet. + * + * @param aPageInfo is the new PAGE_INFO object. + */ + void SetPageInfo( const PAGE_INFO* aPageInfo ); + + /** + * Function SetTitleBlock() + * Changes the TITLE_BLOCK object used to draw the worksheet. + * + * @param aTitleBlock is the new TITLE_BLOCK object. + */ + void SetTitleBlock( const TITLE_BLOCK* aTitleBlock ); + + /** + * Function SetSheetNumber() + * Changes the sheet number displayed in the title block. + * + * @param aSheetNumber is the new sheet number. + */ + void SetSheetNumber( int aSheetNumber ) + { + m_sheetNumber = aSheetNumber; + ViewUpdate( GEOMETRY ); + + } + + /** + * Function SetSheetCount() + * Changes the sheets count number displayed in the title block. + * + * @param aSheetCount is the new sheets count number. + */ + void SetSheetCount( int aSheetCount ) + { + m_sheetCount = aSheetCount; + ViewUpdate( GEOMETRY ); + } + + /// @copydoc VIEW_ITEM::ViewBBox() + const BOX2I ViewBBox() const; + + /// @copydoc VIEW_ITEM::ViewDraw() + void ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const; + + /// @copydoc VIEW_ITEM::ViewGetLayers() + void ViewGetLayers( int aLayers[], int& aCount ) const; + + /// @copydoc EDA_ITEM::Show() + void Show( int x, std::ostream& st ) const + { + } + +protected: + /// File name displayed in the title block + std::string m_fileName; + + /// Sheet name displayed in the title block + std::string m_sheetName; + + /// Title block that contains properties of the title block displayed in the worksheet. + const TITLE_BLOCK* m_titleBlock; + + /// Worksheet page information. + const PAGE_INFO* m_pageInfo; + + /// Sheet number displayed in the title block. + int m_sheetNumber; + + /// Sheets count number displayed in the title block. + int m_sheetCount; + + // Functions for drawing items that makes a worksheet + void draw( const WS_DRAW_ITEM_LINE* aItem, GAL* aGal ) const; + void draw( const WS_DRAW_ITEM_RECT* aItem, GAL* aGal ) const; + void draw( const WS_DRAW_ITEM_POLYGON* aItem, GAL* aGal ) const; + void draw( const WS_DRAW_ITEM_TEXT* aItem, GAL* aGal ) const; + + /// Draws a border that determines the page size. + void drawBorder( GAL* aGal ) const; +}; +} + +#endif /* WORKSHEET_ITEM_H */ diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 4d418d0e57..9692ba9738 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -202,6 +203,20 @@ void PCB_BASE_FRAME::ViewReloadBoard( const BOARD* aBoard ) const view->Add( zone ); } + // Add an entry for the worksheet layout + KiGfx::WORKSHEET_ITEM* worksheet = new KiGfx::WORKSHEET_ITEM( + std::string( aBoard->GetFileName().mb_str() ), + std::string( GetScreenDesc().mb_str() ), + &GetPageSettings(), &GetTitleBlock() ); + BASE_SCREEN* screen = GetScreen(); + if( screen != NULL ) + { + worksheet->SetSheetNumber( GetScreen()->m_ScreenNumber ); + worksheet->SetSheetCount( GetScreen()->m_NumberOfScreens ); + } + + view->Add( worksheet ); + view->RecacheAllItems( true ); if( m_galCanvasActive ) diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 742ef0e188..9fccb84562 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -75,6 +75,7 @@ void PCB_RENDER_SETTINGS::ImportLegacyColors( COLORS_DESIGN_SETTINGS* aSettings m_layerColors[ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE )] = COLOR4D( 0.8, 0.8, 0.8, 0.7 ); 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 ); // Netnames for copper layers for( LAYER_NUM layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; ++layer ) From e38019d74e1e81b20c5ac02987be2a5b7aed885c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 11 Sep 2013 16:38:40 +0200 Subject: [PATCH 10/22] Removed some dead code. --- common/view/view.cpp | 6 +++--- common/view/view_group.cpp | 4 ++-- common/view/view_item.cpp | 7 +------ common/worksheet_item.cpp | 6 +++--- include/view/view_group.h | 3 +-- include/view/view_item.h | 9 ++------- include/worksheet_item.h | 2 +- pcbnew/tools/selection_area.cpp | 2 +- pcbnew/tools/selection_area.h | 2 +- 9 files changed, 15 insertions(+), 26 deletions(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index 4c16035a36..ac72ab9157 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -586,7 +586,7 @@ void VIEW::draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate ) const group = m_gal->BeginGroup(); aItem->setGroup( aLayer, group ); if( !m_painter->Draw( aItem, aLayer ) ) - aItem->ViewDraw( aLayer, m_gal, BOX2I() ); // Alternative drawing method + aItem->ViewDraw( aLayer, m_gal ); // Alternative drawing method m_gal->EndGroup(); } } @@ -594,7 +594,7 @@ void VIEW::draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate ) const { // Immediate mode if( !m_painter->Draw( aItem, aLayer ) ) - aItem->ViewDraw( aLayer, m_gal, BOX2I() ); // Alternative drawing method + aItem->ViewDraw( aLayer, m_gal ); // Alternative drawing method } // Draws a bright contour around the item @@ -673,7 +673,7 @@ struct VIEW::recacheLayer int group = gal->BeginGroup(); aItem->setGroup( layer, group ); if( !view->m_painter->Draw( aItem, layer ) ) - aItem->ViewDraw( layer, gal, BOX2I() ); // Alternative drawing method + aItem->ViewDraw( layer, gal ); // Alternative drawing method gal->EndGroup(); } else diff --git a/common/view/view_group.cpp b/common/view/view_group.cpp index d4cc2472bc..d6f90bb0ba 100644 --- a/common/view/view_group.cpp +++ b/common/view/view_group.cpp @@ -85,7 +85,7 @@ const BOX2I VIEW_GROUP::ViewBBox() const } -void VIEW_GROUP::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const +void VIEW_GROUP::ViewDraw( int aLayer, GAL* aGal ) const { PAINTER* painter = m_view->GetPainter(); @@ -103,7 +103,7 @@ void VIEW_GROUP::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) co aGal->SetLayerDepth( m_view->GetLayerOrder( layers[i] ) ); if( !painter->Draw( item, layers[i] ) ) - item->ViewDraw( layers[i], aGal, aVisibleArea ); // Alternative drawing method + item->ViewDraw( layers[i], aGal ); // Alternative drawing method } } } diff --git a/common/view/view_item.cpp b/common/view/view_item.cpp index 4104d06c1a..94b4ccafe7 100644 --- a/common/view/view_item.cpp +++ b/common/view/view_item.cpp @@ -48,17 +48,12 @@ void VIEW_ITEM::ViewSetVisible( bool aIsVisible ) } -void VIEW_ITEM::ViewUpdate( int aUpdateFlags, bool aForceImmediateRedraw ) +void VIEW_ITEM::ViewUpdate( int aUpdateFlags ) { if( !m_view ) return; m_view->invalidateItem( this, aUpdateFlags ); - - if( aForceImmediateRedraw ) - { - m_view->Redraw(); - } } diff --git a/common/worksheet_item.cpp b/common/worksheet_item.cpp index 40790de477..9845e48f92 100644 --- a/common/worksheet_item.cpp +++ b/common/worksheet_item.cpp @@ -76,7 +76,7 @@ const BOX2I WORKSHEET_ITEM::ViewBBox() const } -void WORKSHEET_ITEM::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const +void WORKSHEET_ITEM::ViewDraw( int aLayer, GAL* aGal ) const { RENDER_SETTINGS* settings = m_view->GetPainter()->GetSettings(); wxString fileName( m_fileName ); @@ -84,8 +84,8 @@ void WORKSHEET_ITEM::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea WS_DRAW_ITEM_LIST drawList; drawList.SetPenSize( settings->GetWorksheetLineWidth() ); - // Sorry,but I don't get this multi #ifdef from include/convert_to_biu.h, so here goes a magic - // number. IU_PER_MILS should be 25400 (as in a different compiltion unit), but somehow + // Sorry, but I don't get this multi #ifdef from include/convert_to_biu.h, so here goes a magic + // number. IU_PER_MILS should be 25400 (as in a different compilation unit), but somehow // it equals 1 in this case.. drawList.SetMilsToIUfactor( 25400 /* IU_PER_MILS */ ); drawList.SetSheetNumber( m_sheetNumber ); diff --git a/include/view/view_group.h b/include/view/view_group.h index ab48e80028..514000bac3 100644 --- a/include/view/view_group.h +++ b/include/view/view_group.h @@ -107,9 +107,8 @@ public: * * @param aLayer is the layer which should be drawn. * @param aGal is the GAL that should be used for drawing. - * @param aVisibleArea is limiting the drawing area. */ - virtual void ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const; + virtual void ViewDraw( int aLayer, GAL* aGal ) const; /** * Function ViewGetLayers() diff --git a/include/view/view_item.h b/include/view/view_item.h index 49f0b7d492..5200acb973 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -101,11 +101,8 @@ public: * * @param aLayer: current drawing layer * @param aGal: pointer to the GAL device we are drawing on - * @param aVisibleArea: area (in world space coordinates) that is relevant for drawing. For - * example, when drawing a bitmap, one can clip the blitting area to aVisibleArea, reducing - * drawing time. */ - virtual void ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const { }; + virtual void ViewDraw( int aLayer, GAL* aGal ) const {}; /** * Function ViewGetLayers() @@ -155,10 +152,8 @@ public: * this item has changed. For static views calling has no effect. * * @param aUpdateFlags: how much the object has changed - * @param aForceImmediateRedraw: when true, the VIEW is redrawn immediately, - * otherwise, it will be redrawn upon next call of VIEW::Update() */ - virtual void ViewUpdate( int aUpdateFlags = ALL, bool aForceImmediateRedraw = false ); + virtual void ViewUpdate( int aUpdateFlags = ALL ); /** * Function ViewRelease() diff --git a/include/worksheet_item.h b/include/worksheet_item.h index e4cff49fa3..b26ec01085 100644 --- a/include/worksheet_item.h +++ b/include/worksheet_item.h @@ -120,7 +120,7 @@ public: const BOX2I ViewBBox() const; /// @copydoc VIEW_ITEM::ViewDraw() - void ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const; + void ViewDraw( int aLayer, GAL* aGal ) const; /// @copydoc VIEW_ITEM::ViewGetLayers() void ViewGetLayers( int aLayers[], int& aCount ) const; diff --git a/pcbnew/tools/selection_area.cpp b/pcbnew/tools/selection_area.cpp index 5c30de222c..33d73d6d68 100644 --- a/pcbnew/tools/selection_area.cpp +++ b/pcbnew/tools/selection_area.cpp @@ -47,7 +47,7 @@ void SELECTION_AREA::ViewGetLayers( int aLayers[], int& aCount ) const } -void SELECTION_AREA::ViewDraw( int aLayer, GAL* aGal, const BOX2I& aVisibleArea ) const +void SELECTION_AREA::ViewDraw( int aLayer, 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 28bf0f8b63..50db94f927 100644 --- a/pcbnew/tools/selection_area.h +++ b/pcbnew/tools/selection_area.h @@ -50,7 +50,7 @@ public: virtual const BOX2I ViewBBox() const; - void ViewDraw( int aLayer, KiGfx::GAL* aGal, const BOX2I& aVisibleArea ) const; + void ViewDraw( int aLayer, KiGfx::GAL* aGal ) const; void ViewGetLayers( int aLayers[], int& aCount ) const; void SetOrigin ( VECTOR2I aOrigin ) From f8ae1a9997fdf7b49ef2fdca19c659a970c4969c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 11 Sep 2013 19:37:52 +0200 Subject: [PATCH 11/22] Removed some potential memory leaks. --- common/tool/tool_manager.cpp | 13 +++++++++++++ include/wxBasePcbFrame.h | 4 ++-- include/wxPcbStruct.h | 1 + pcbnew/pcbframe.cpp | 1 + pcbnew/tools/pcb_tools.cpp | 7 +++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 03250f8fff..0c7a97538c 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -86,6 +86,19 @@ TOOL_MANAGER::TOOL_MANAGER() } +TOOL_MANAGER::~TOOL_MANAGER() +{ + std::map::iterator it, it_end; + + for( it = m_toolState.begin(), it_end = m_toolState.end(); it != it_end; ++it ) + { + delete it->second->cofunc; // delete cofunction + delete it->second; // delete TOOL_STATE + delete it->first; // delete the tool itself + } +} + + void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool ) { TOOL_STATE* st = new TOOL_STATE; diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 874349dfd0..fdaaa1f767 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -95,8 +95,8 @@ protected: /// main window. wxAuiToolBar* m_auxiliaryToolBar; - TOOL_MANAGER *m_toolManager; - TOOL_DISPATCHER *m_toolDispatcher; + TOOL_MANAGER* m_toolManager; + TOOL_DISPATCHER* m_toolDispatcher; void updateGridSelectBox(); void updateZoomSelectBox(); diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 29a65a34e5..af93d93bf0 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -118,6 +118,7 @@ protected: // to know the footprint name of components. void setupTools(); + void destroyTools(); void onGenericCommand( wxCommandEvent& aEvent ); // we'll use lower case function names for private member functions. diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 7a7a6f6e4e..8904b35e81 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -485,6 +485,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, PCB_EDIT_FRAME::~PCB_EDIT_FRAME() { + destroyTools(); m_RecordingMacros = -1; for( int i = 0; i < 10; i++ ) diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index 0dc342a17d..30692560d8 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -50,6 +50,13 @@ void PCB_EDIT_FRAME::setupTools() } +void PCB_EDIT_FRAME::destroyTools() +{ + delete m_toolDispatcher; + delete m_toolManager; +} + + void PCB_EDIT_FRAME::onGenericCommand( wxCommandEvent &aEvent ) { m_toolDispatcher->DispatchWxCommand( aEvent ); From 944a61100b1e42976cef39b72c5bcc3100c5fa05 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 12 Sep 2013 09:44:57 +0200 Subject: [PATCH 12/22] Fixed memory leaks in containers. --- common/gal/opengl/cached_container.cpp | 149 ++++++++++++---------- common/gal/opengl/noncached_container.cpp | 5 - common/gal/opengl/opengl_gal.cpp | 2 + common/gal/opengl/vertex_manager.cpp | 9 +- common/view/view_item.cpp | 6 - include/gal/opengl/cached_container.h | 21 +-- include/gal/opengl/noncached_container.h | 4 +- include/gal/opengl/vertex_container.h | 14 +- include/gal/opengl/vertex_manager.h | 6 + include/view/view_item.h | 10 +- 10 files changed, 126 insertions(+), 100 deletions(-) diff --git a/common/gal/opengl/cached_container.cpp b/common/gal/opengl/cached_container.cpp index ea718530ce..12682d858f 100644 --- a/common/gal/opengl/cached_container.cpp +++ b/common/gal/opengl/cached_container.cpp @@ -42,7 +42,7 @@ using namespace KiGfx; CACHED_CONTAINER::CACHED_CONTAINER( unsigned int aSize ) : - VERTEX_CONTAINER( aSize ) + VERTEX_CONTAINER( aSize ), m_item( NULL ) { // In the beginning there is only free space m_freeChunks.insert( Chunk( aSize, 0 ) ); @@ -51,35 +51,45 @@ CACHED_CONTAINER::CACHED_CONTAINER( unsigned int aSize ) : void CACHED_CONTAINER::SetItem( VERTEX_ITEM* aItem ) { - if( aItem == NULL ) - { - wxASSERT( m_item != NULL ); + wxASSERT( aItem != NULL ); - // Finishing the item - if( m_itemSize < m_chunkSize ) - { - // There is some not used but reserved memory left, so we should return it to the pool - int itemOffset = m_item->GetOffset(); + m_item = aItem; + m_itemSize = m_item->GetSize(); + m_chunkSize = m_itemSize; - // Add the not used memory back to the pool - m_freeChunks.insert( Chunk( m_chunkSize - m_itemSize, itemOffset + m_itemSize ) ); - m_freeSpace += ( m_chunkSize - m_itemSize ); - // mergeFreeChunks(); - } - - m_item = NULL; - } + if( m_itemSize == 0 ) + m_items.insert( m_item ); // The item was not stored before else - { - m_item = aItem; - m_itemSize = m_item->GetSize(); - m_chunkSize = m_itemSize; + m_chunkOffset = m_item->GetOffset(); - if( m_itemSize == 0 ) - m_items.insert( m_item ); // The item was not stored before - else - m_chunkOffset = m_item->GetOffset(); +#if CACHED_CONTAINER_TEST > 1 + wxLogDebug( wxT( "Adding/editing item 0x%08lx (size %d)" ), (long) m_item, m_itemSize ); +#endif +} + + +void CACHED_CONTAINER::FinishItem() +{ + wxASSERT( m_item != NULL ); + wxASSERT( m_item->GetSize() == m_itemSize ); + + // Finishing the previously edited item + if( m_itemSize < m_chunkSize ) + { + // There is some not used but reserved memory left, so we should return it to the pool + int itemOffset = m_item->GetOffset(); + + // Add the not used memory back to the pool + m_freeChunks.insert( Chunk( m_chunkSize - m_itemSize, itemOffset + m_itemSize ) ); + m_freeSpace += ( m_chunkSize - m_itemSize ); + // mergeFreeChunks(); // veery slow and buggy } + +#if CACHED_CONTAINER_TEST > 1 + wxLogDebug( wxT( "Finishing item 0x%08lx (size %d)" ), (long) m_item, m_itemSize ); + test(); + m_item = NULL; // electric fence +#endif } @@ -109,6 +119,7 @@ VERTEX* CACHED_CONTAINER::Allocate( unsigned int aSize ) VERTEX* reserved = &m_vertices[m_chunkOffset + m_itemSize]; m_itemSize += aSize; + // Now the item officially possesses the memory chunk m_item->setSize( m_itemSize ); // The content has to be updated @@ -117,16 +128,40 @@ VERTEX* CACHED_CONTAINER::Allocate( unsigned int aSize ) #if CACHED_CONTAINER_TEST > 1 test(); #endif +#if CACHED_CONTAINER_TEST > 2 + showFreeChunks(); + showReservedChunks(); +#endif return reserved; } -void CACHED_CONTAINER::Erase() +void CACHED_CONTAINER::Delete( VERTEX_ITEM* aItem ) { - wxASSERT( m_item != NULL ); + wxASSERT( aItem != NULL ); + wxASSERT( m_items.find( aItem ) != m_items.end() ); - freeItem( m_item ); + int size = aItem->GetSize(); + int offset = aItem->GetOffset(); + +#if CACHED_CONTAINER_TEST > 1 + wxLogDebug( wxT( "Removing 0x%08lx (size %d offset %d)" ), (long) aItem, size, offset ); +#endif + + // Insert a free memory chunk entry in the place where item was stored + if( size > 0 ) + { + m_freeChunks.insert( Chunk( size, offset ) ); + m_freeSpace += size; + // Indicate that the item is not stored in the container anymore + aItem->setSize( 0 ); + } + m_items.erase( aItem ); + +#if CACHED_CONTAINER_TEST > 1 + test(); +#endif // Dynamic memory freeing, there is no point in holding // a large amount of memory when there is no use for it @@ -176,10 +211,10 @@ VERTEX* CACHED_CONTAINER::GetVertices( const VERTEX_ITEM* aItem ) const unsigned int CACHED_CONTAINER::reallocate( unsigned int aSize ) { + wxASSERT( aSize > 0 ); + #if CACHED_CONTAINER_TEST > 2 - wxLogDebug( wxT( "Resize 0x%08x to %d" ), (int) m_item, aSize ); - showFreeChunks(); - showReservedChunks(); + wxLogDebug( wxT( "Resize 0x%08lx from %d to %d" ), (long) m_item, m_itemSize, aSize ); #endif // Is there enough space to store vertices? @@ -203,7 +238,7 @@ unsigned int CACHED_CONTAINER::reallocate( unsigned int aSize ) return UINT_MAX; } - // Look for the free space of at least given size + // Look for the free space chunk of at least given size FreeChunkMap::iterator newChunk = m_freeChunks.lower_bound( aSize ); if( newChunk == m_freeChunks.end() ) @@ -240,6 +275,7 @@ unsigned int CACHED_CONTAINER::reallocate( unsigned int aSize ) m_itemSize * VertexSize ); // Free the space previously used by the chunk + wxASSERT( m_itemSize > 0 ); m_freeChunks.insert( Chunk( m_itemSize, m_chunkOffset ) ); m_freeSpace += m_itemSize; } @@ -254,15 +290,10 @@ unsigned int CACHED_CONTAINER::reallocate( unsigned int aSize ) } m_freeSpace -= aSize; - // mergeFreeChunks(); + // mergeFreeChunks(); // veery slow and buggy m_item->setOffset( chunkOffset ); -#if CACHED_CONTAINER_TEST > 2 - showFreeChunks(); - showReservedChunks(); -#endif - return chunkOffset; } @@ -271,11 +302,10 @@ bool CACHED_CONTAINER::defragment( VERTEX* aTarget ) { #if CACHED_CONTAINER_TEST > 0 wxLogDebug( wxT( "Defragmenting" ) ); -#endif -#ifdef __WXDEBUG__ + prof_counter totalTime; prof_start( &totalTime, false ); -#endif /* __WXDEBUG__ */ +#endif if( aTarget == NULL ) { @@ -313,14 +343,15 @@ bool CACHED_CONTAINER::defragment( VERTEX* aTarget ) // Now there is only one big chunk of free memory m_freeChunks.clear(); + wxASSERT( m_freeSpace > 0 ); m_freeChunks.insert( Chunk( m_freeSpace, m_currentSize - m_freeSpace ) ); -#ifdef __WXDEBUG__ +#if CACHED_CONTAINER_TEST > 0 prof_end( &totalTime ); wxLogDebug( wxT( "Defragmented the container storing %d vertices / %.1f ms" ), m_currentSize - m_freeSpace, (double) totalTime.value / 1000.0 ); -#endif /* __WXDEBUG__ */ +#endif return true; } @@ -331,10 +362,10 @@ void CACHED_CONTAINER::mergeFreeChunks() if( m_freeChunks.size() <= 1 ) // There are no chunks that can be merged return; -#ifdef __WXDEBUG__ +#ifdef CACHED_CONTAINER_TEST > 0 prof_counter totalTime; prof_start( &totalTime, false ); -#endif /* __WXDEBUG__ */ +#endif // Reversed free chunks map - this one stores chunk size with its offset as the key std::list freeChunks; @@ -375,11 +406,11 @@ void CACHED_CONTAINER::mergeFreeChunks() // Add the last one m_freeChunks.insert( std::make_pair( size, offset ) ); -#ifdef __WXDEBUG__ +#ifdef CACHED_CONTAINER_TEST > 0 prof_end( &totalTime ); wxLogDebug( wxT( "Merged free chunks / %.1f ms" ), (double) totalTime.value / 1000.0 ); -#endif /* __WXDEBUG__ */ +#endif test(); } @@ -387,6 +418,8 @@ void CACHED_CONTAINER::mergeFreeChunks() bool CACHED_CONTAINER::resizeContainer( unsigned int aNewSize ) { + wxASSERT( aNewSize != m_currentSize ); + #if CACHED_CONTAINER_TEST > 0 wxLogDebug( wxT( "Resizing container from %d to %d" ), m_currentSize, aNewSize ); #endif @@ -413,6 +446,7 @@ bool CACHED_CONTAINER::resizeContainer( unsigned int aNewSize ) // We have to correct freeChunks after defragmentation m_freeChunks.clear(); + wxASSERT( aNewSize - reservedSpace() > 0 ); m_freeChunks.insert( Chunk( aNewSize - reservedSpace(), reservedSpace() ) ); } else @@ -439,21 +473,6 @@ bool CACHED_CONTAINER::resizeContainer( unsigned int aNewSize ) } -void CACHED_CONTAINER::freeItem( VERTEX_ITEM* aItem ) -{ - int size = aItem->GetSize(); - int offset = aItem->GetOffset(); - - // Insert a free memory chunk entry in the place where item was stored - m_freeChunks.insert( Chunk( size, offset ) ); - m_freeSpace += size; - m_items.erase( aItem ); - - // Indicate that the item is not stored in the container anymore - aItem->setSize( 0 ); -} - - unsigned int CACHED_CONTAINER::getPowerOf2( unsigned int aNumber ) const { unsigned int power = 1; @@ -476,6 +495,7 @@ void CACHED_CONTAINER::showFreeChunks() { unsigned int offset = getChunkOffset( *it ); unsigned int size = getChunkSize( *it ); + wxASSERT( size > 0 ); wxLogDebug( wxT( "[0x%08x-0x%08x] (size %d)" ), offset, offset + size - 1, size ); @@ -494,9 +514,10 @@ void CACHED_CONTAINER::showReservedChunks() VERTEX_ITEM* item = *it; unsigned int offset = item->GetOffset(); unsigned int size = item->GetSize(); + wxASSERT( size > 0 ); - wxLogDebug( wxT( "[0x%08x-0x%08x] @ 0x%08x (size %d)" ), - offset, offset + size - 1, (int) item, size ); + wxLogDebug( wxT( "[0x%08x-0x%08x] @ 0x%08lx (size %d)" ), + offset, offset + size - 1, (long) item, size ); } } diff --git a/common/gal/opengl/noncached_container.cpp b/common/gal/opengl/noncached_container.cpp index f7eb3f897a..9c2ab066f8 100644 --- a/common/gal/opengl/noncached_container.cpp +++ b/common/gal/opengl/noncached_container.cpp @@ -82,11 +82,6 @@ VERTEX* NONCACHED_CONTAINER::Allocate( unsigned int aSize ) } -void NONCACHED_CONTAINER::Erase() -{ -} - - void NONCACHED_CONTAINER::Clear() { m_freePtr = 0; diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index 4d40e28978..f1b9b95031 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -638,6 +638,7 @@ int OPENGL_GAL::BeginGroup() void OPENGL_GAL::EndGroup() { + cachedManager.FinishItem(); isGrouping = false; } @@ -662,6 +663,7 @@ void OPENGL_GAL::ChangeGroupDepth( int aGroupNumber, int aDepth ) void OPENGL_GAL::DeleteGroup( int aGroupNumber ) { + // Frees memory in the container as well groups.erase( aGroupNumber ); } diff --git a/common/gal/opengl/vertex_manager.cpp b/common/gal/opengl/vertex_manager.cpp index 876a793241..65a80826f7 100644 --- a/common/gal/opengl/vertex_manager.cpp +++ b/common/gal/opengl/vertex_manager.cpp @@ -88,10 +88,15 @@ void VERTEX_MANAGER::SetItem( VERTEX_ITEM& aItem ) const } +void VERTEX_MANAGER::FinishItem() const +{ + m_container->FinishItem(); +} + + void VERTEX_MANAGER::FreeItem( VERTEX_ITEM& aItem ) const { - m_container->SetItem( &aItem ); - m_container->Erase(); + m_container->Delete( &aItem ); } diff --git a/common/view/view_item.cpp b/common/view/view_item.cpp index 94b4ccafe7..d7e563109b 100644 --- a/common/view/view_item.cpp +++ b/common/view/view_item.cpp @@ -137,9 +137,3 @@ void VIEW_ITEM::deleteGroups() m_groups = NULL; m_groupsSize = 0; } - - -bool VIEW_ITEM::storesGroups() const -{ - return ( m_groupsSize > 0 ); -} diff --git a/include/gal/opengl/cached_container.h b/include/gal/opengl/cached_container.h index 6409d34356..d770f9bc46 100644 --- a/include/gal/opengl/cached_container.h +++ b/include/gal/opengl/cached_container.h @@ -36,10 +36,8 @@ #include #include -#ifdef __WXDEBUG__ // Debug messages verbosity level -// #define CACHED_CONTAINER_TEST 2 -#endif +//#define CACHED_CONTAINER_TEST 1 namespace KiGfx { @@ -54,11 +52,14 @@ public: ///< @copydoc VERTEX_CONTAINER::SetItem() virtual void SetItem( VERTEX_ITEM* aItem ); + ///< @copydoc VERTEX_CONTAINER::FinishItem() + virtual void FinishItem(); + ///< @copydoc VERTEX_CONTAINER::Allocate() virtual VERTEX* Allocate( unsigned int aSize ); - ///< @copydoc VERTEX_CONTAINER::Erase() - virtual void Erase(); + ///< @copydoc VERTEX_CONTAINER::Delete() + virtual void Delete( VERTEX_ITEM* aItem ); ///< @copydoc VERTEX_CONTAINER::Clear() virtual void Clear(); @@ -130,14 +131,6 @@ protected: */ virtual bool resizeContainer( unsigned int aNewSize ); - /** - * Function freeItem() - * frees the space occupied by the item and returns it to the free space pool. - * - * @param aItem is the item to be freed. - */ - virtual void freeItem( VERTEX_ITEM* aItem ); - /** * Function getPowerOf2() * returns the nearest power of 2, bigger than aNumber. @@ -170,7 +163,7 @@ private: } /// Debug & test functions -#ifdef CACHED_CONTAINER_TEST +#if CACHED_CONTAINER_TEST > 0 void showFreeChunks(); void showReservedChunks(); void test(); diff --git a/include/gal/opengl/noncached_container.h b/include/gal/opengl/noncached_container.h index 0ff2f20a27..3cb6d1bf85 100644 --- a/include/gal/opengl/noncached_container.h +++ b/include/gal/opengl/noncached_container.h @@ -50,8 +50,8 @@ public: ///< @copydoc VERTEX_CONTAINER::Allocate() virtual VERTEX* Allocate( unsigned int aSize ); - ///< @copydoc VERTEX_CONTAINER::Erase() - virtual void Erase(); + ///< @copydoc VERTEX_CONTAINER::Delete() + void Delete( VERTEX_ITEM* aItem ) {}; ///< @copydoc VERTEX_CONTAINER::Clear() virtual void Clear(); diff --git a/include/gal/opengl/vertex_container.h b/include/gal/opengl/vertex_container.h index efca90b2f8..fb2a404846 100644 --- a/include/gal/opengl/vertex_container.h +++ b/include/gal/opengl/vertex_container.h @@ -54,6 +54,12 @@ public: */ virtual void SetItem( VERTEX_ITEM* aItem ) = 0; + /** + * Function FinishItem() + * does the cleaning after adding an item. + */ + virtual void FinishItem() {}; + /** * Function Allocate() * returns allocated space (possibly resizing the reserved memory chunk or allocating a new @@ -66,10 +72,12 @@ public: virtual VERTEX* Allocate( unsigned int aSize ) = 0; /** - * Function Erase() - * erases all vertices associated with the current item (set by SetItem()). + * Function Delete() + * erases the selected item. + * + * @param aItem is the item to be erased. */ - virtual void Erase() = 0; + virtual void Delete( VERTEX_ITEM* aItem ) = 0; /** * Function Clear() diff --git a/include/gal/opengl/vertex_manager.h b/include/gal/opengl/vertex_manager.h index bacb99867e..79f9dbd64b 100644 --- a/include/gal/opengl/vertex_manager.h +++ b/include/gal/opengl/vertex_manager.h @@ -232,6 +232,12 @@ public: */ void SetItem( VERTEX_ITEM& aItem ) const; + /** + * Function FinishItem() + * does the cleaning after adding an item. + */ + void FinishItem() const; + /** * Function FreeItem() * frees the memory occupied by the item, so it is no longer stored in the container. diff --git a/include/view/view_item.h b/include/view/view_item.h index 5200acb973..8004c4264b 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -70,8 +70,7 @@ public: ALL = 0xff }; - VIEW_ITEM() : m_view( NULL ), m_visible( true ), m_groups( NULL ), - m_groupsSize( 0 ) {} + VIEW_ITEM() : m_view( NULL ), m_visible( true ), m_groups( NULL ), m_groupsSize( 0 ) {} /** * Destructor. For dynamic views, removes the item from the view. @@ -236,7 +235,10 @@ protected: * * @returns true in case it is cached at least for one layer. */ - virtual bool storesGroups() const; + inline virtual bool storesGroups() const + { + return ( m_groupsSize > 0 ); + } /// Stores layer numbers used by the item. std::bitset m_layers; @@ -253,7 +255,7 @@ protected: m_layers.reset(); for( int i = 0; i < aCount; ++i ) - m_layers.set(aLayers[i]); + m_layers.set( aLayers[i] ); } }; From b57331f450100ce29b98fba6f8111bde8641eadd Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 12 Sep 2013 10:24:23 +0200 Subject: [PATCH 13/22] Move tool is activated when drag event starts nearby selected items. --- pcbnew/tools/selection_tool.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 63689482b5..ec4d661a24 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -111,8 +111,28 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) } else { - // Now user wants to drag the selected items - m_toolMgr->InvokeTool( "pcbnew.InteractiveMove" ); + bool runTool = false; + + // 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 ) + { + BOX2I itemBox = (*it)->ViewBBox(); + itemBox.Inflate( 500000 ); // Give some margin for gripping an item + + if( itemBox.Contains( evt->Position() ) ) + { + // Click event occurred within a selected item bounding box + // -> user wants to drag selected items + runTool = true; + break; + } + } + + if( runTool ) + m_toolMgr->InvokeTool( "pcbnew.InteractiveMove" ); + else + clearSelection(); } } else if( dragging ) @@ -131,7 +151,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem ) { - if( m_selectedItems.find( aItem ) != m_selectedItems.end() ) + if( aItem->IsSelected() ) { aItem->ClearSelected(); m_selectedItems.erase( aItem ); From fcfbe920d5a2997cb3414e5a96dd65d23f54d855 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 12 Sep 2013 10:46:22 +0200 Subject: [PATCH 14/22] Removed selection disambiguation in case when there is a choice between a footprint and a smaller component (smaller components have priority). --- pcbnew/tools/selection_tool.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index ec4d661a24..277f7ccb2c 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -151,7 +151,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem ) { - if( aItem->IsSelected() ) + if( m_selectedItems.find( aItem ) != m_selectedItems.end() ) { aItem->ClearSelected(); m_selectedItems.erase( aItem ); @@ -204,9 +204,29 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere ) break; default: - item = disambiguationMenu( &collector ); - if( item ) - toggleSelection( item ); + // Remove footprints, they have to be selected by clicking on area that does not + // contain anything but footprint + for( int i = 0; i < collector.GetCount(); ++i ) + { + BOARD_ITEM* boardItem = ( collector )[i]; + if( boardItem->Type() == PCB_MODULE_T ) + { + wxLogDebug( wxT( "Removing %s" ), boardItem->GetSelectMenuText() ); + collector.Remove( i ); + } + } + + // Let's see if there is still disambiguation in selection.. + if( collector.GetCount() == 1 ) + { + toggleSelection( collector[0] ); + } + else + { + item = disambiguationMenu( &collector ); + if( item ) + toggleSelection( item ); + } break; } } @@ -326,7 +346,7 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) for( int i = 0; i < limit; ++i ) { wxString text; - BOARD_ITEM *item = ( *aCollector )[i]; + BOARD_ITEM* item = ( *aCollector )[i]; text = item->GetSelectMenuText(); m_menu->Add( text, i ); } From 9b2a45013388499460362f776077ebdf4d48946f Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 12 Sep 2013 10:54:11 +0200 Subject: [PATCH 15/22] Fixed rollback of traces movement. --- pcbnew/tools/move_tool.cpp | 2 +- pcbnew/tools/move_tool.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pcbnew/tools/move_tool.cpp b/pcbnew/tools/move_tool.cpp index f0783f6a40..f7839211c1 100644 --- a/pcbnew/tools/move_tool.cpp +++ b/pcbnew/tools/move_tool.cpp @@ -61,7 +61,7 @@ void MOVE_TOOL::Reset() } // the tool launches upon reception of activate ("pcbnew.InteractiveMove") - Go( &MOVE_TOOL::Main, TOOL_EVENT( TC_Command, TA_ActivateTool, GetName() ) ); //"pcbnew.InteractiveMove")); + Go( &MOVE_TOOL::Main, TOOL_EVENT( TC_Command, TA_ActivateTool, GetName() ) ); } diff --git a/pcbnew/tools/move_tool.h b/pcbnew/tools/move_tool.h index 1022230a69..1645237527 100644 --- a/pcbnew/tools/move_tool.h +++ b/pcbnew/tools/move_tool.h @@ -89,7 +89,8 @@ private: void RestorePosition() { - item->SetPosition( wxPoint( position.x, position.y ) ); + wxPoint curPosition = item->GetPosition(); + item->Move( wxPoint( position.x - curPosition.x, position.y - curPosition.y ) ); } void RestoreVisibility() From 7d41dc16164ace37f30cccebb9a8cb435b92c12e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 12 Sep 2013 18:24:53 +0200 Subject: [PATCH 16/22] Currently selected layer is displayed on the top. --- common/tool/tool_dispatcher.cpp | 2 - common/view/view.cpp | 6 +- include/wxPcbStruct.h | 18 ++-- pcbnew/class_pcb_layer_widget.cpp | 4 +- pcbnew/deltrack.cpp | 4 +- pcbnew/dialogs/dialog_general_options.cpp | 4 +- pcbnew/dialogs/dialog_global_deletion.cpp | 2 +- pcbnew/dialogs/dialog_layers_setup.cpp | 10 +- pcbnew/dimension.cpp | 2 +- pcbnew/edit.cpp | 20 ++-- pcbnew/editedge.cpp | 4 +- pcbnew/editrack-part2.cpp | 12 +-- pcbnew/hotkeys_board_editor.cpp | 10 +- pcbnew/onleftclick.cpp | 6 +- pcbnew/pcbframe.cpp | 117 +++++++++++++++------- pcbnew/tool_pcb.cpp | 2 +- pcbnew/toolbars_update_user_interface.cpp | 2 +- pcbnew/zones_by_polygon.cpp | 8 +- 18 files changed, 139 insertions(+), 94 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 018e54b566..eb3b777b20 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -217,8 +217,6 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP || type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ) { - wxMouseEvent* me = static_cast( &aEvent ); - pos = getView()->ToWorld ( getCurrentMousePos() ); if( pos != m_lastMousePos ) { diff --git a/common/view/view.cpp b/common/view/view.cpp index ac72ab9157..a24b7ac4e5 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -41,7 +41,7 @@ using namespace KiGfx; VIEW::VIEW( bool aIsDynamic ) : - m_enableOrderModifier( false ), + m_enableOrderModifier( true ), m_scale( 1.0 ), m_painter( NULL ), m_gal( NULL ), @@ -415,6 +415,8 @@ void VIEW::UpdateAllLayersColor() updateItemsColor visitor( l->id, m_painter, m_gal ); l->items->Query( r, visitor ); } + + MarkDirty(); } @@ -525,6 +527,8 @@ void VIEW::UpdateAllLayersOrder() { ChangeLayerDepth( l.first, l.second.renderingOrder ); } + + MarkDirty(); } diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index af93d93bf0..2110eb75d9 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -136,21 +136,13 @@ protected: * will change the currently active layer to \a aLayer and also * update the PCB_LAYER_WIDGET. */ - void setActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true ) - { - ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; - - setHighContrastLayer( aLayer ); - - if( doLayerWidgetUpdate ) - syncLayerWidgetLayer(); - } + void setCurrentLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate = true ); /** * Function getActiveLayer * returns the active layer */ - LAYER_NUM getActiveLayer() + LAYER_NUM getCurrentLayer() { return ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer; } @@ -161,6 +153,12 @@ protected: */ void setHighContrastLayer( LAYER_NUM aLayer ); + /** + * Function setTopLayer + * moves the selected layer to the top, so it is displayed above all others. + */ + void setTopLayer( LAYER_NUM aLayer ); + /** * Function syncLayerWidgetLayer * updates the currently layer "selection" within the PCB_LAYER_WIDGET. diff --git a/pcbnew/class_pcb_layer_widget.cpp b/pcbnew/class_pcb_layer_widget.cpp index 07b46f4fa9..e334c05d59 100644 --- a/pcbnew/class_pcb_layer_widget.cpp +++ b/pcbnew/class_pcb_layer_widget.cpp @@ -183,7 +183,7 @@ void PCB_LAYER_WIDGET::onPopupSelection( wxCommandEvent& event ) if( IsCopperLayer( layer ) ) { bool loc_visible = visible; - if( force_active_layer_visible && (layer == myframe->getActiveLayer() ) ) + if( force_active_layer_visible && (layer == myframe->getCurrentLayer() ) ) loc_visible = true; cb->SetValue( loc_visible ); @@ -354,7 +354,7 @@ bool PCB_LAYER_WIDGET::OnLayerSelect( LAYER_NUM aLayer ) { // the layer change from the PCB_LAYER_WIDGET can be denied by returning // false from this function. - myframe->setActiveLayer( aLayer, false ); + myframe->setCurrentLayer( aLayer, false ); if( m_alwaysShowActiveCopperLayer ) OnLayerSelected(); diff --git a/pcbnew/deltrack.cpp b/pcbnew/deltrack.cpp index 2a77f9faec..6833543db9 100644 --- a/pcbnew/deltrack.cpp +++ b/pcbnew/deltrack.cpp @@ -53,7 +53,7 @@ TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack ) { if( g_CurrentTrackList.GetCount() > 0 ) { - LAYER_NUM previous_layer = getActiveLayer(); + LAYER_NUM previous_layer = getCurrentLayer(); DBG( g_CurrentTrackList.VerifyListIntegrity(); ) @@ -86,7 +86,7 @@ TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack ) // Correct active layer which could change if a via // has been erased - setActiveLayer( previous_layer ); + setCurrentLayer( previous_layer ); UpdateStatusBar(); diff --git a/pcbnew/dialogs/dialog_general_options.cpp b/pcbnew/dialogs/dialog_general_options.cpp index 37854ac88f..2d10c8d6ea 100644 --- a/pcbnew/dialogs/dialog_general_options.cpp +++ b/pcbnew/dialogs/dialog_general_options.cpp @@ -238,8 +238,8 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) // Apply new display options to the GAL canvas (this is faster than recaching) settings->LoadDisplayOptions( DisplayOpt ); - setHighContrastLayer( getActiveLayer() ); - m_galCanvas->GetView()->EnableTopLayer( state ); + setHighContrastLayer( getCurrentLayer() ); +// m_galCanvas->GetView()->EnableTopLayer( state ); if( m_galCanvasActive ) m_galCanvas->Refresh(); diff --git a/pcbnew/dialogs/dialog_global_deletion.cpp b/pcbnew/dialogs/dialog_global_deletion.cpp index 3048f5b7c0..7812296232 100644 --- a/pcbnew/dialogs/dialog_global_deletion.cpp +++ b/pcbnew/dialogs/dialog_global_deletion.cpp @@ -37,7 +37,7 @@ DIALOG_GLOBAL_DELETION::DIALOG_GLOBAL_DELETION( PCB_EDIT_FRAME* parent ) void PCB_EDIT_FRAME::InstallPcbGlobalDeleteFrame( const wxPoint& pos ) { DIALOG_GLOBAL_DELETION dlg( this ); - dlg.SetCurrentLayer( getActiveLayer() ); + dlg.SetCurrentLayer( getCurrentLayer() ); dlg.ShowModal(); } diff --git a/pcbnew/dialogs/dialog_layers_setup.cpp b/pcbnew/dialogs/dialog_layers_setup.cpp index d06f501394..ab8f18c97e 100644 --- a/pcbnew/dialogs/dialog_layers_setup.cpp +++ b/pcbnew/dialogs/dialog_layers_setup.cpp @@ -669,11 +669,11 @@ void PCB_EDIT_FRAME::InstallDialogLayerSetup() if( dlg.ShowModal() == wxID_CANCEL ) return; - wxLogDebug( wxT( "Current layer selected %d." ), getActiveLayer() ); + wxLogDebug( wxT( "Current layer selected %d." ), getCurrentLayer() ); // If the current active layer was removed, find the next avaiable layer to set as the // active layer. - if( !( GetLayerMask( getActiveLayer() ) & GetBoard()->GetEnabledLayers() ) ) + if( !( GetLayerMask( getCurrentLayer() ) & GetBoard()->GetEnabledLayers() ) ) { for( LAYER_NUM i = FIRST_LAYER; i < NB_LAYERS; ++i ) { @@ -684,14 +684,14 @@ void PCB_EDIT_FRAME::InstallDialogLayerSetup() if( GetLayerMask( tmp ) & GetBoard()->GetEnabledLayers() ) { - wxLogDebug( wxT( "Setting current layer to %d." ), getActiveLayer() ); - setActiveLayer( tmp, true ); + wxLogDebug( wxT( "Setting current layer to %d." ), getCurrentLayer() ); + setCurrentLayer( tmp, true ); break; } } } else { - setActiveLayer( getActiveLayer(), true ); + setCurrentLayer( getCurrentLayer(), true ); } } diff --git a/pcbnew/dimension.cpp b/pcbnew/dimension.cpp index 391addb6f9..bf72fdfc8a 100644 --- a/pcbnew/dimension.cpp +++ b/pcbnew/dimension.cpp @@ -245,7 +245,7 @@ DIMENSION* PCB_EDIT_FRAME::EditDimension( DIMENSION* aDimension, wxDC* aDC ) aDimension = new DIMENSION( GetBoard() ); aDimension->SetFlags( IS_NEW ); - aDimension->SetLayer( getActiveLayer() ); + aDimension->SetLayer( getCurrentLayer() ); aDimension->m_crossBarO = aDimension->m_crossBarF = pos; aDimension->m_featureLineDO = aDimension->m_featureLineDF = pos; diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 47e60041ba..65974bc83b 100755 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -917,10 +917,10 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_PCB_SELECT_LAYER: - itmp = SelectLayer( getActiveLayer(), UNDEFINED_LAYER, UNDEFINED_LAYER ); + itmp = SelectLayer( getCurrentLayer(), UNDEFINED_LAYER, UNDEFINED_LAYER ); if( itmp >= 0 ) - setActiveLayer( itmp ); + setCurrentLayer( itmp ); m_canvas->MoveCursorToCrossHair(); break; @@ -930,19 +930,19 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_PCB_SELECT_NO_CU_LAYER: - itmp = SelectLayer( getActiveLayer(), FIRST_NON_COPPER_LAYER, UNDEFINED_LAYER ); + itmp = SelectLayer( getCurrentLayer(), FIRST_NON_COPPER_LAYER, UNDEFINED_LAYER ); if( itmp >= 0 ) - setActiveLayer( itmp ); + setCurrentLayer( itmp ); m_canvas->MoveCursorToCrossHair(); break; case ID_POPUP_PCB_SELECT_CU_LAYER: - itmp = SelectLayer( getActiveLayer(), UNDEFINED_LAYER, LAST_COPPER_LAYER ); + itmp = SelectLayer( getCurrentLayer(), UNDEFINED_LAYER, LAST_COPPER_LAYER ); if( itmp >= 0 ) - setActiveLayer( itmp ); + setCurrentLayer( itmp ); break; @@ -952,7 +952,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_TOOLBARH_PCB_SELECT_LAYER: - setActiveLayer( m_SelLayerBox->GetLayerSelection() ); + setCurrentLayer( m_SelLayerBox->GetLayerSelection() ); if( DisplayOpt.ContrastModeDisplay ) m_canvas->Refresh( true ); @@ -1240,7 +1240,7 @@ void PCB_EDIT_FRAME::RemoveStruct( BOARD_ITEM* Item, wxDC* DC ) void PCB_EDIT_FRAME::SwitchLayer( wxDC* DC, LAYER_NUM layer ) { - LAYER_NUM curLayer = getActiveLayer(); + LAYER_NUM curLayer = getCurrentLayer(); // Check if the specified layer matches the present layer if( layer == curLayer ) @@ -1282,7 +1282,7 @@ void PCB_EDIT_FRAME::SwitchLayer( wxDC* DC, LAYER_NUM layer ) GetScreen()->m_Route_Layer_TOP = curLayer; GetScreen()->m_Route_Layer_BOTTOM = layer; - setActiveLayer( curLayer ); + setCurrentLayer( curLayer ); if( Other_Layer_Route( (TRACK*) GetScreen()->GetCurItem(), DC ) ) { @@ -1303,7 +1303,7 @@ void PCB_EDIT_FRAME::SwitchLayer( wxDC* DC, LAYER_NUM layer ) // and a non-copper layer, or vice-versa? // ... - setActiveLayer( layer ); + setCurrentLayer( layer ); if( DisplayOpt.ContrastModeDisplay ) RefreshCanvas(); diff --git a/pcbnew/editedge.cpp b/pcbnew/editedge.cpp index acc881c687..1bc862c958 100644 --- a/pcbnew/editedge.cpp +++ b/pcbnew/editedge.cpp @@ -246,7 +246,7 @@ DRAWSEGMENT* PCB_EDIT_FRAME::Begin_DrawSegment( DRAWSEGMENT* Segment, STROKE_T s s_large = GetDesignSettings().m_DrawSegmentWidth; - if( getActiveLayer() == EDGE_N ) + if( getCurrentLayer() == EDGE_N ) { s_large = GetDesignSettings().m_EdgeSegmentWidth; } @@ -255,7 +255,7 @@ DRAWSEGMENT* PCB_EDIT_FRAME::Begin_DrawSegment( DRAWSEGMENT* Segment, STROKE_T s { SetCurItem( Segment = new DRAWSEGMENT( GetBoard() ) ); Segment->SetFlags( IS_NEW ); - Segment->SetLayer( getActiveLayer() ); + Segment->SetLayer( getCurrentLayer() ); Segment->SetWidth( s_large ); Segment->SetShape( shape ); Segment->SetAngle( 900 ); diff --git a/pcbnew/editrack-part2.cpp b/pcbnew/editrack-part2.cpp index e36a3a92a1..40c5f73eb3 100644 --- a/pcbnew/editrack-part2.cpp +++ b/pcbnew/editrack-part2.cpp @@ -52,10 +52,10 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) if( aTrack == NULL ) { - if( getActiveLayer() != ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ) - setActiveLayer( ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ); + if( getCurrentLayer() != ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ) + setCurrentLayer( ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ); else - setActiveLayer(((PCB_SCREEN*)GetScreen())->m_Route_Layer_BOTTOM ); + setCurrentLayer(((PCB_SCREEN*)GetScreen())->m_Route_Layer_BOTTOM ); UpdateStatusBar(); return true; @@ -109,7 +109,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) via->SetLayerPair( LAYER_N_BACK, LAYER_N_FRONT ); via->SetDrill( GetBoard()->GetCurrentViaDrill() ); - LAYER_NUM first_layer = getActiveLayer(); + LAYER_NUM first_layer = getCurrentLayer(); LAYER_NUM last_layer; // prepare switch to new active layer: @@ -172,7 +172,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) return false; } - setActiveLayer( last_layer ); + setCurrentLayer( last_layer ); TRACK* lastNonVia = g_CurrentTrackSegment; @@ -194,7 +194,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) */ // set the layer to the new value - track->SetLayer( getActiveLayer() ); + track->SetLayer( getCurrentLayer() ); /* the start point is the via position and the end point is the cursor * which also is on the via (will change when moving mouse) diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp index 30b07f55b2..eeedca4df2 100644 --- a/pcbnew/hotkeys_board_editor.cpp +++ b/pcbnew/hotkeys_board_editor.cpp @@ -243,7 +243,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit break; case HK_SWITCH_LAYER_TO_PREVIOUS: - ll = getActiveLayer(); + ll = getCurrentLayer(); if( (ll <= LAYER_N_BACK) || (ll > LAYER_N_FRONT) ) break; @@ -259,7 +259,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit break; case HK_SWITCH_LAYER_TO_NEXT: - ll = getActiveLayer(); + ll = getCurrentLayer(); if( (ll < LAYER_N_BACK) || (ll >= LAYER_N_FRONT) ) break; @@ -365,7 +365,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit break; case HK_BACK_SPACE: - if( /*m_ID_current_state == ID_TRACK_BUTT &&*/ (getActiveLayer() <= LAYER_N_FRONT) ) + if( /*m_ID_current_state == ID_TRACK_BUTT &&*/ (getCurrentLayer() <= LAYER_N_FRONT) ) { if( !itemCurrentlyEdited ) { @@ -572,7 +572,7 @@ bool PCB_EDIT_FRAME::OnHotkeyDeleteItem( wxDC* aDC ) switch( GetToolId() ) { case ID_TRACK_BUTT: - if( getActiveLayer() > LAYER_N_FRONT ) + if( getCurrentLayer() > LAYER_N_FRONT ) return false; if( ItemFree ) @@ -941,7 +941,7 @@ bool PCB_EDIT_FRAME::OnHotkeyPlaceItem( wxDC* aDC ) */ TRACK * PCB_EDIT_FRAME::OnHotkeyBeginRoute( wxDC* aDC ) { - if( getActiveLayer() > LAYER_N_FRONT ) + if( getCurrentLayer() > LAYER_N_FRONT ) return NULL; bool itemCurrentlyEdited = (GetCurItem() && GetCurItem()->GetFlags()); diff --git a/pcbnew/onleftclick.cpp b/pcbnew/onleftclick.cpp index f655b1a6a0..62e11ddacb 100644 --- a/pcbnew/onleftclick.cpp +++ b/pcbnew/onleftclick.cpp @@ -243,7 +243,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) if( GetToolId() == ID_PCB_ARC_BUTT ) shape = S_ARC; - if( IsCopperLayer( getActiveLayer() ) ) + if( IsCopperLayer( getCurrentLayer() ) ) { DisplayError( this, _( "Graphic not allowed on Copper layers" ) ); break; @@ -267,7 +267,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) break; case ID_TRACK_BUTT: - if( !IsCopperLayer( getActiveLayer() ) ) + if( !IsCopperLayer( getCurrentLayer() ) ) { DisplayError( this, _( "Tracks on Copper layers only " ) ); break; @@ -367,7 +367,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) break; case ID_PCB_DIMENSION_BUTT: - if( IsCopperLayer( getActiveLayer() ) ) + if( IsCopperLayer( getCurrentLayer() ) ) { DisplayError( this, _( "Dimension not allowed on Copper layers" ) ); break; diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index bc257d29cc..b970df681f 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -730,7 +730,7 @@ void PCB_EDIT_FRAME::SetGridColor(EDA_COLOR_T aColor) bool PCB_EDIT_FRAME::IsMicroViaAcceptable( void ) { int copperlayercnt = GetBoard()->GetCopperLayerCount( ); - LAYER_NUM currLayer = getActiveLayer(); + LAYER_NUM currLayer = getCurrentLayer(); if( !GetDesignSettings().m_MicroViasAllowed ) return false; // Obvious.. @@ -754,55 +754,100 @@ void PCB_EDIT_FRAME::setHighContrastLayer( LAYER_NUM aLayer ) KiGfx::VIEW* view = m_galCanvas->GetView(); KiGfx::RENDER_SETTINGS* rSettings = view->GetPainter()->GetSettings(); -// if( DisplayOpt.ContrastModeDisplay ) + setTopLayer( aLayer ); + + rSettings->ClearActiveLayers(); + rSettings->SetActiveLayer( aLayer ); + + if( IsCopperLayer( aLayer ) ) { - view->ClearTopLayers(); - view->SetTopLayer( aLayer ); + // Bring some other layers to the front in case of copper layers and make them colored + // fixme do not like the idea of storing the list of layers here, + // should be done in some other way I guess.. + 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 ) + }; - rSettings->ClearActiveLayers(); - rSettings->SetActiveLayer( aLayer ); + for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) + rSettings->SetActiveLayer( layers[i] ); - if( IsCopperLayer( aLayer ) ) + // Pads should be shown too + if( aLayer == FIRST_COPPER_LAYER ) { - // Bring some other layers to the front in case of copper layers and make them colored - 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 ) - }; + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); + } + else if( aLayer == LAST_COPPER_LAYER ) + { + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); + } + } - for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) - { - view->SetTopLayer( layers[i] ); - rSettings->SetActiveLayer( layers[i] ); - } + view->UpdateAllLayersColor(); +} - // Pads should be shown too - if( aLayer == FIRST_COPPER_LAYER ) - { - view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); - view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); - rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); - rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); - } - else if( aLayer == LAST_COPPER_LAYER ) - { - view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); - view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); - rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); - rSettings->SetActiveLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); - } + +void PCB_EDIT_FRAME::setTopLayer( LAYER_NUM aLayer ) +{ + // Set display settings for high contrast mode + KiGfx::VIEW* view = m_galCanvas->GetView(); + + view->ClearTopLayers(); + view->SetTopLayer( aLayer ); + + if( IsCopperLayer( aLayer ) ) + { + // Bring some other layers to the front in case of copper layers and make them colored + // fixme do not like the idea of storing the list of layers here, + // should be done in some other way I guess.. + 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 ) + }; + + for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) + { + view->SetTopLayer( layers[i] ); } - view->UpdateAllLayersOrder(); - view->UpdateAllLayersColor(); + // Pads should be shown too + if( aLayer == FIRST_COPPER_LAYER ) + { + view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_VISIBLE ) ); + view->SetTopLayer( ITEM_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE ) ); + } + else if( aLayer == LAST_COPPER_LAYER ) + { + view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_VISIBLE ) ); + view->SetTopLayer( ITEM_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE ) ); + } } + + view->UpdateAllLayersOrder(); +} + + +void PCB_EDIT_FRAME::setCurrentLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate ) +{ + ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; + + setHighContrastLayer( aLayer ); + + if( doLayerWidgetUpdate ) + syncLayerWidgetLayer(); + + if( m_galCanvasActive ) + m_galCanvas->Refresh(); } void PCB_EDIT_FRAME::syncLayerWidgetLayer() { - m_Layers->SelectLayer( getActiveLayer() ); + m_Layers->SelectLayer( getCurrentLayer() ); m_Layers->OnLayerSelected(); } diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp index 5b6fe3b95f..533106bf9b 100644 --- a/pcbnew/tool_pcb.cpp +++ b/pcbnew/tool_pcb.cpp @@ -105,7 +105,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator() previous_Route_Layer_BOTTOM_color, previous_via_color; /* get colors, and redraw bitmap button only on changes */ - active_layer_color = GetBoard()->GetLayerColor(getActiveLayer()); + active_layer_color = GetBoard()->GetLayerColor(getCurrentLayer()); if( previous_active_layer_color != active_layer_color ) { diff --git a/pcbnew/toolbars_update_user_interface.cpp b/pcbnew/toolbars_update_user_interface.cpp index 23d850d2b1..bd77618169 100644 --- a/pcbnew/toolbars_update_user_interface.cpp +++ b/pcbnew/toolbars_update_user_interface.cpp @@ -96,7 +96,7 @@ void PCB_EDIT_FRAME::OnUpdateSelectViaSize( wxUpdateUIEvent& aEvent ) void PCB_EDIT_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent ) { - m_SelLayerBox->SetLayerSelection( getActiveLayer() ); + m_SelLayerBox->SetLayerSelection( getCurrentLayer() ); } diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index 8973ffccb3..05d57bd5bb 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -518,7 +518,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) if( !GetBoard()->m_CurrentZoneContour ) { if( GetToolId() == ID_PCB_KEEPOUT_AREA_BUTT && - getActiveLayer() >= FIRST_NON_COPPER_LAYER ) + getCurrentLayer() >= FIRST_NON_COPPER_LAYER ) { DisplayError( this, _( "Error: a keepout area is allowed only on copper layers" ) ); @@ -537,7 +537,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) ZONE_EDIT_T edited; // Init zone params to reasonable values - zone->SetLayer( getActiveLayer() ); + zone->SetLayer( getCurrentLayer() ); // Prompt user for parameters: m_canvas->SetIgnoreMouseEvents( true ); @@ -602,7 +602,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) return 0; // Switch active layer to the selected zone layer - setActiveLayer( zoneInfo.m_CurrentZone_Layer ); + setCurrentLayer( zoneInfo.m_CurrentZone_Layer ); SetZoneSettings( zoneInfo ); } @@ -612,7 +612,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) // zone (add cutout or similar zone) zoneInfo.m_CurrentZone_Layer = s_CurrentZone->GetLayer(); - setActiveLayer( s_CurrentZone->GetLayer() ); + setCurrentLayer( s_CurrentZone->GetLayer() ); zoneInfo << *s_CurrentZone; From 87d81a6d920cc4d8aa146f893486d30f6d8f4c0e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 13 Sep 2013 10:26:08 +0200 Subject: [PATCH 17/22] Mouse movement events are sent during autopanning, as the cursor position changes in the world coordinates (even if it stays still in the screen coordinates). It allows tools to update their state, as if the mouse was moved. --- common/drawpanel_gal.cpp | 9 ++++++--- common/tool/tool_dispatcher.cpp | 7 +++++-- common/view/wx_view_controls.cpp | 5 ++++- include/tool/tool_dispatcher.h | 3 +++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index fa0b004e49..2d169b37db 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -87,10 +87,12 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin Connect( wxEVT_MIDDLE_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MIDDLE_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_MOUSEWHEEL, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); -// Connect( wxEVT_CHAR_HOOK, wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ) ); + Connect( wxEVT_CHAR_HOOK, wxEventHandler( EDA_DRAW_PANEL_GAL::skipEvent ) ); Connect( wxEVT_KEY_UP, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); Connect( wxEVT_KEY_DOWN, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), NULL, this ); -// Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); + Connect( wxEVT_ENTER_WINDOW, wxEventHandler( EDA_DRAW_PANEL_GAL::onEnter ), NULL, this ); + Connect( TOOL_DISPATCHER::EVT_REFRESH_MOUSE, wxEventHandler( EDA_DRAW_PANEL_GAL::onEvent ), + NULL, this ); m_refreshTimer.SetOwner( this ); Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); @@ -243,8 +245,9 @@ void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) } -void EDA_DRAW_PANEL_GAL::onEnter ( wxEvent& aEvent ) +void EDA_DRAW_PANEL_GAL::onEnter( wxEvent& aEvent ) { + // Getting focus is necessary in order to receive key events properly SetFocus(); } diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index eb3b777b20..03ff9ef9b3 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -41,6 +41,8 @@ using boost::optional; +const wxEventType TOOL_DISPATCHER::EVT_REFRESH_MOUSE = wxNewEventType(); + struct TOOL_DISPATCHER::ButtonState { ButtonState( TOOL_MouseButtons aButton, const wxEventType& aDownEvent, @@ -215,10 +217,11 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) if( type == wxEVT_MOTION || type == wxEVT_MOUSEWHEEL || type == wxEVT_LEFT_DOWN || type == wxEVT_LEFT_UP || type == wxEVT_MIDDLE_DOWN || type == wxEVT_MIDDLE_UP || - type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP ) + type == wxEVT_RIGHT_DOWN || type == wxEVT_RIGHT_UP || + type == EVT_REFRESH_MOUSE ) { pos = getView()->ToWorld ( getCurrentMousePos() ); - if( pos != m_lastMousePos ) + if( pos != m_lastMousePos || type == EVT_REFRESH_MOUSE ) { motion = true; m_lastMousePos = pos; diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 838f5b82a0..1349948501 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -28,6 +28,7 @@ #include #include #include +#include using namespace KiGfx; @@ -197,7 +198,9 @@ void WX_VIEW_CONTROLS::onTimer( wxTimerEvent& aEvent ) dir = m_view->ToWorld( dir, false ); m_view->SetCenter( m_view->GetCenter() + dir * m_autoPanSpeed ); - m_parentPanel->Refresh(); + // Notify tools that the cursor position has changed in the world coordinates + wxCommandEvent moveEvent( TOOL_DISPATCHER::EVT_REFRESH_MOUSE ); + wxPostEvent( m_parentPanel, moveEvent ); } break; diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index ae1db0c4d2..f5b7bacae0 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -65,6 +65,9 @@ public: virtual void DispatchWxEvent( wxEvent& aEvent ); virtual void DispatchWxCommand( wxCommandEvent& aEvent ); + /// Event that forces mouse move event in the dispatcher + static const wxEventType EVT_REFRESH_MOUSE; + private: static const int MouseButtonCount = 3; static const int DragTimeThreshold = 300; From 404bfdcf306299a878efc4569610cd072e421561 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 13 Sep 2013 11:28:47 +0200 Subject: [PATCH 18/22] Changed VIEW::PrepareTargets() to more appropriate name VIEW::ClearTargets(). Added SELECTION layer to always-on-top list. --- common/drawpanel_gal.cpp | 5 ++--- common/view/view.cpp | 2 +- include/view/view.h | 4 ++-- pcbnew/pcbframe.cpp | 6 ++++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/common/drawpanel_gal.cpp b/common/drawpanel_gal.cpp index 2d169b37db..7087d1e86d 100644 --- a/common/drawpanel_gal.cpp +++ b/common/drawpanel_gal.cpp @@ -131,7 +131,7 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) m_gal->SetBackgroundColor( KiGfx::COLOR4D( 0.0, 0.0, 0.0, 1.0 ) ); m_gal->ClearScreen(); - m_view->PrepareTargets(); + m_view->ClearTargets(); // Grid has to be redrawn only when the NONCACHED target is redrawn if( m_view->IsTargetDirty( KiGfx::TARGET_NONCACHED ) ) m_gal->DrawGrid(); @@ -240,8 +240,7 @@ void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) m_eventDispatcher->DispatchWxEvent( aEvent ); } -// if( m_view->IsDirty() ) - Refresh(); + Refresh(); } diff --git a/common/view/view.cpp b/common/view/view.cpp index a24b7ac4e5..8531688714 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -714,7 +714,7 @@ void VIEW::Clear() } -void VIEW::PrepareTargets() +void VIEW::ClearTargets() { if( IsTargetDirty( TARGET_CACHED ) || IsTargetDirty( TARGET_NONCACHED ) ) { diff --git a/include/view/view.h b/include/view/view.h index c5146d3540..8d4329b3d9 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -377,10 +377,10 @@ public: void UpdateAllLayersOrder(); /** - * Function PrepareTargets() + * Function ClearTargets() * Clears targets that are marked as dirty. */ - void PrepareTargets(); + void ClearTargets(); /** * Function Redraw() diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index b970df681f..bf15c21989 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -767,7 +767,8 @@ 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( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ), + ITEM_GAL_LAYER( SELECTION ) }; for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) @@ -806,7 +807,8 @@ void PCB_EDIT_FRAME::setTopLayer( 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( PADS_HOLES_VISIBLE ), ITEM_GAL_LAYER( PADS_NETNAMES_VISIBLE ), + ITEM_GAL_LAYER( SELECTION ) }; for( unsigned int i = 0; i < sizeof( layers ) / sizeof( LAYER_NUM ); ++i ) From fa57fee9bbdfd99fc8ce3a31d11ca7a24d987fd9 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 13 Sep 2013 11:38:16 +0200 Subject: [PATCH 19/22] Removed VIEW_LAYER.isDirty flag. --- common/view/view.cpp | 20 ++++---------------- include/view/view.h | 1 - 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index 8531688714..4409806c3c 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -80,7 +80,6 @@ void VIEW::AddLayer( int aLayer, bool aDisplayOnly ) m_layers[aLayer].items = new VIEW_RTREE(); m_layers[aLayer].renderingOrder = aLayer; m_layers[aLayer].enabled = true; - m_layers[aLayer].isDirty = false; m_layers[aLayer].displayOnly = aDisplayOnly; m_layers[aLayer].target = TARGET_CACHED; } @@ -100,7 +99,7 @@ void VIEW::Add( VIEW_ITEM* aItem ) { VIEW_LAYER& l = m_layers[layers[i]]; l.items->Insert( aItem ); - l.isDirty = true; + MarkTargetDirty( l.target ); } if( m_dynamic ) @@ -120,7 +119,6 @@ void VIEW::Remove( VIEW_ITEM* aItem ) { VIEW_LAYER& l = m_layers[layers[i]]; l.items->Remove( aItem ); - l.isDirty = true; } } @@ -568,8 +566,6 @@ void VIEW::redrawRect( const BOX2I& aRect ) m_gal->SetLayerDepth( l->renderingOrder ); l->items->Query( aRect, drawFunc ); } - - l->isDirty = false; } } @@ -815,8 +811,7 @@ void VIEW::invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags ) } // Mark those layers as dirty, so the VIEW will be refreshed - m_layers[layerId].isDirty = true; - MarkTargetDirty( m_layers[layerId].target ); // TODO remove? + MarkTargetDirty( m_layers[layerId].target ); } } @@ -876,7 +871,7 @@ void VIEW::updateBbox( VIEW_ITEM* aItem ) VIEW_LAYER& l = m_layers[layers[i]]; l.items->Remove( aItem ); l.items->Insert( aItem ); - l.isDirty = true; + MarkTargetDirty( l.target ); } } @@ -920,7 +915,7 @@ void VIEW::RecacheAllItems( bool aImmediately ) m_gal->SetLayerDepth( l->renderingOrder ); recacheLayer visitor( this, m_gal, l->id, aImmediately ); l->items->Query( r, visitor ); - l->isDirty = true; + MarkTargetDirty( l->target ); } } @@ -941,12 +936,5 @@ bool VIEW::IsTargetDirty( int aTarget ) const if( m_dirtyTargets[aTarget] ) return true; - // Check if any of layers belonging to the target is dirty - BOOST_FOREACH( VIEW_LAYER* l, m_orderedLayers ) - { - if( l->target == aTarget && l->isDirty ) - return true; - } - return false; } diff --git a/include/view/view.h b/include/view/view.h index 8d4329b3d9..5013fdaf91 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -459,7 +459,6 @@ private: struct VIEW_LAYER { bool enabled; ///* is the layer to be rendered? - bool isDirty; ///* does it contain any dirty items (updated since last redraw) bool displayOnly; ///* is the layer display only? VIEW_RTREE* items; ///* R-tree indexing all items on this layer. int renderingOrder; ///* rendering order of this layer From 5e41599d1310dd6834c0f7f35bbe7e85f62fe4fd Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 13 Sep 2013 15:05:57 +0200 Subject: [PATCH 20/22] Removed unnecessary debug message --- pcbnew/tools/selection_tool.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 277f7ccb2c..cd1a4be5a1 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -210,10 +210,7 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere ) { BOARD_ITEM* boardItem = ( collector )[i]; if( boardItem->Type() == PCB_MODULE_T ) - { - wxLogDebug( wxT( "Removing %s" ), boardItem->GetSelectMenuText() ); collector.Remove( i ); - } } // Let's see if there is still disambiguation in selection.. From 5a461f5bb3465bc70a62f6d3883d2603b077e375 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 13 Sep 2013 15:30:45 +0200 Subject: [PATCH 21/22] Caps for lines are drawn only when segments are wider than 1.0 --- common/gal/opengl/opengl_gal.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index f1b9b95031..07b5238cf1 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -233,8 +233,11 @@ void OPENGL_GAL::DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoin drawLineQuad( aStartPoint, aEndPoint ); // Line caps - drawFilledSemiCircle( aStartPoint, lineWidth / 2, lineAngle + M_PI / 2 ); - drawFilledSemiCircle( aEndPoint, lineWidth / 2, lineAngle - M_PI / 2 ); + if( lineWidth > 1.0 ) + { + drawFilledSemiCircle( aStartPoint, lineWidth / 2, lineAngle + M_PI / 2 ); + drawFilledSemiCircle( aEndPoint, lineWidth / 2, lineAngle - M_PI / 2 ); + } } From 5700075b7a117ae9f1f8a752a58458d8a9d4c83a Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 13 Sep 2013 15:31:19 +0200 Subject: [PATCH 22/22] Added missing functions for checking type of keyboard event --- include/tool/tool_event.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/tool/tool_event.h b/include/tool/tool_event.h index 1033a2f51a..592624c321 100644 --- a/include/tool/tool_event.h +++ b/include/tool/tool_event.h @@ -229,6 +229,16 @@ public: return m_keyCode; } + bool IsKeyUp() const + { + return m_actions == TA_KeyUp; + } + + bool IsKeyDown() const + { + return m_actions == TA_KeyDown; + } + void Ignore(); void SetMouseDragOrigin( const VECTOR2D &aP )