diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index 933339b3e3..ff22550845 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -295,7 +295,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_MODEDIT_NEW_MODULE: { - if( ! Clear_Pcb( true ) ) + if( !Clear_Pcb( true ) ) break; SetCrossHairPosition( wxPoint( 0, 0 ) ); @@ -317,6 +317,9 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) Zoom_Automatique( false ); } + if( IsGalCanvasActive() ) + updateView(); + GetScreen()->ClrModify(); } break; diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 1c299c6984..4adc0bc13c 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -50,7 +50,7 @@ PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS() m_displayZoneMode = DZ_SHOW_FILLED; // By default everything should be displayed as filled - for( unsigned int i = 0; i < END_PCB_VISIBLE_LIST; ++i ) + for( unsigned int i = 0; i < TOTAL_LAYER_COUNT; ++i ) { m_sketchMode[i] = false; } @@ -102,9 +102,9 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ) m_padNumbers = aOptions.DisplayPadNum; // Whether to draw tracks, vias & pads filled or as outlines - m_sketchMode[PADS_VISIBLE] = !aOptions.DisplayPadFill; - m_sketchMode[VIA_THROUGH_VISIBLE] = !aOptions.DisplayViaFill; - m_sketchMode[TRACKS_VISIBLE] = !aOptions.DisplayPcbTrackFill; + m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )] = !aOptions.DisplayPadFill; + m_sketchMode[ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE )] = !aOptions.DisplayViaFill; + m_sketchMode[ITEM_GAL_LAYER( TRACKS_VISIBLE )] = !aOptions.DisplayPcbTrackFill; switch( aOptions.DisplayNetNamesMode ) { @@ -313,7 +313,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) m_gal->SetStrokeColor( color ); m_gal->SetIsStroke( true ); - if( m_pcbSettings.m_sketchMode[TRACKS_VISIBLE] ) + if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( TRACKS_VISIBLE )] ) { // Outline mode m_gal->SetLineWidth( m_pcbSettings.m_outlineWidth ); @@ -350,7 +350,7 @@ void PCB_PAINTER::draw( const VIA* aVia, int aLayer ) const COLOR4D& color = m_pcbSettings.GetColor( aVia, aLayer ); - if( m_pcbSettings.m_sketchMode[VIA_THROUGH_VISIBLE] ) + if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( VIA_THROUGH_VISIBLE )] ) { // Outline mode m_gal->SetIsFill( false ); @@ -481,7 +481,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) // Pad drawing const COLOR4D& color = m_pcbSettings.GetColor( aPad, aLayer ); - if( m_pcbSettings.m_sketchMode[PADS_VISIBLE] ) + if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )] ) { // Outline mode m_gal->SetIsFill( false ); @@ -544,7 +544,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) m = ( size.y - size.x ); n = size.x; - if( m_pcbSettings.m_sketchMode[PADS_VISIBLE] ) + if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )] ) { // Outline mode m_gal->DrawArc( VECTOR2D( 0, -m ), n, -M_PI, 0 ); @@ -565,7 +565,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) m = ( size.x - size.y ); n = size.y; - if( m_pcbSettings.m_sketchMode[PADS_VISIBLE] ) + if( m_pcbSettings.m_sketchMode[ITEM_GAL_LAYER( PADS_VISIBLE )] ) { // Outline mode m_gal->DrawArc( VECTOR2D( -m, 0 ), n, M_PI / 2, 3 * M_PI / 2 ); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 9d19cc3541..170f723e09 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -76,6 +76,8 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason ) int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) { + boost::optional startingPoint; + if( m_editModules ) { m_frame->SetToolID( ID_MODEDIT_LINE_TOOL, wxCURSOR_PENCIL, _( "Add graphic line" ) ); @@ -83,7 +85,7 @@ int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) MODULE* module = m_board->m_Modules; EDGE_MODULE* line = new EDGE_MODULE( module ); - while( drawSegment( S_SEGMENT, reinterpret_cast( line ) ) ) + while( drawSegment( S_SEGMENT, reinterpret_cast( line ), startingPoint ) ) { if( line ) { @@ -92,6 +94,11 @@ int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) line->SetLocalCoord(); line->SetParent( module ); module->GraphicalItems().PushFront( line ); + startingPoint = line->GetEnd(); + } + else + { + startingPoint = boost::none; } line = new EDGE_MODULE( module ); @@ -103,13 +110,18 @@ int DRAWING_TOOL::DrawLine( TOOL_EVENT& aEvent ) DRAWSEGMENT* line = new DRAWSEGMENT; - while( drawSegment( S_SEGMENT, line ) ) + while( drawSegment( S_SEGMENT, line, startingPoint ) ) { if( line ) { m_board->Add( line ); m_frame->OnModify(); m_frame->SaveCopyInUndoList( line, UR_NEW ); + startingPoint = line->GetEnd(); + } + else + { + startingPoint = boost::none; } line = new DRAWSEGMENT; @@ -853,7 +865,8 @@ int DRAWING_TOOL::SetAnchor( TOOL_EVENT& aEvent ) } -bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic ) +bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic, + boost::optional aStartingPoint ) { // Only two shapes are currently supported assert( aShape == S_SEGMENT || aShape == S_CIRCLE ); @@ -872,12 +885,33 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic ) bool direction45 = false; // 45 degrees only mode bool started = false; + VECTOR2I cursorPos = m_controls->GetCursorPosition(); + + if( aStartingPoint ) + { + LAYER_NUM layer = m_frame->GetScreen()->m_Active_Layer; + + // Init the new item attributes + aGraphic->SetShape( (STROKE_T) aShape ); + aGraphic->SetWidth( m_board->GetDesignSettings().m_DrawSegmentWidth ); + aGraphic->SetStart( wxPoint( aStartingPoint->x, aStartingPoint->y ) ); + aGraphic->SetEnd( wxPoint( cursorPos.x, cursorPos.y ) ); + aGraphic->SetLayer( layer ); + + if( aShape == S_SEGMENT ) + line45 = *aGraphic; // used only for direction 45 mode with lines + + preview.Add( aGraphic ); + m_controls->SetAutoPan( true ); + + started = true; + } // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { bool updatePreview = false; // should preview be updated - VECTOR2I cursorPos = m_controls->GetCursorPosition(); + cursorPos = m_controls->GetCursorPosition(); // Enable 45 degrees lines only mode by holding control if( direction45 != evt->Modifier( MD_CTRL ) && started && aShape == S_SEGMENT ) @@ -940,10 +974,7 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic ) aGraphic->SetLayer( layer ); if( aShape == S_SEGMENT ) - { line45 = *aGraphic; // used only for direction 45 mode with lines - line45.SetLayer( layer ); - } preview.Add( aGraphic ); m_controls->SetAutoPan( true ); @@ -965,7 +996,6 @@ bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT*& aGraphic ) { // a clear sign that the current drawing is finished delete aGraphic; // but only if at least one graphic was created aGraphic = NULL; // otherwise - force user to draw more or cancel - started = false; } preview.Clear(); diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 42a6dbfdf3..178d751a8f 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -26,6 +26,7 @@ #define __DRAWING_TOOL_H #include +#include namespace KIGFX { @@ -150,7 +151,8 @@ private: ///> be already created. The tool deletes the object if it is not added to a BOARD. ///> @return False if the tool was cancelled before the origin was set or origin and end are ///> the same point. - bool drawSegment( int aShape, DRAWSEGMENT*& aGraphic ); + bool drawSegment( int aShape, DRAWSEGMENT*& aGraphic, + boost::optional aStartingPoint = boost::none ); ///> Starts drawing an arc. ///> @param aGraphic is an object that is going to be used by the tool for drawing. It has to