← Back to team overview

kicad-developers team mailing list archive

[PATCH] Add axis origin marker to Footprint Editor

 

To match functionality of the Legacy canvas I propose we extend the
GAL ORIGIN_VIEWITEM class to allow us to add an axis origin marker
when using the Footprint Editor. I'm sure even while in the stable
feature-lock this is okay to commit, but an ack will be good before I
go ahead.

Also, Orson, thanks for your information about this, can you also ack
that you're happy with the class extension? Otherwise feel free to
contact me to implement this in another way if you'd rather...

Best Regards,

Brian.
=== modified file 'common/origin_viewitem.cpp'
--- common/origin_viewitem.cpp	2015-06-18 15:51:53 +0000
+++ common/origin_viewitem.cpp	2015-09-03 21:19:45 +0000
@@ -30,7 +30,7 @@
 
 ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) :
     EDA_ITEM( NOT_USED ),   // this item is never added to a BOARD so it needs no type
-    m_position( aPosition ), m_size( aSize ), m_color( aColor ), m_style( aStyle )
+    m_position( aPosition ), m_size( aSize ), m_color( aColor ), m_style( aStyle ), m_drawatzero( false )
 {
 }
 
@@ -45,8 +45,9 @@
 
 void ORIGIN_VIEWITEM::ViewDraw( int, GAL* aGal ) const
 {
-    // Legacy canvas does not draw markers if they are located in the (0, 0) point
-    if( m_position.x == 0 && m_position.y == 0 )
+    // Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is. This
+    // mimics the Legacy canvas that doesn't display most targets at 0,0
+    if( !m_drawatzero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
         return;
 
     aGal->SetIsStroke( true );
@@ -54,25 +55,31 @@
     aGal->SetLineWidth( 1 );
     aGal->SetStrokeColor( m_color );
     VECTOR2D scaledSize = m_view->ToWorld( VECTOR2D( m_size, m_size ), false );
-    aGal->DrawCircle( m_position, scaledSize.x );
-
-    switch( m_style )
+
+    // Draw a circle around the marker's centre point if the style demands it
+    if( ( m_style == CCROSS ) || ( m_style == CDOT ) || ( m_style == CX ) )
+        aGal->DrawCircle( m_position, scaledSize.x );
+
+    switch( m_style & 0xFF )
     {
         case NONE:
             break;
 
         case CROSS:
+        case CCROSS:
             aGal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ), m_position + VECTOR2D( scaledSize.x, 0 ) );
             aGal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ), m_position + VECTOR2D( 0, scaledSize.y ) );
             break;
 
         case X:
+        case CX:
             aGal->DrawLine( m_position - scaledSize, m_position + scaledSize );
             scaledSize.y = -scaledSize.y;
             aGal->DrawLine( m_position - scaledSize, m_position + scaledSize );
             break;
 
         case DOT:
+        case CDOT:
             aGal->DrawCircle( m_position, scaledSize.x / 4 );
             break;
     }

=== modified file 'include/origin_viewitem.h'
--- include/origin_viewitem.h	2015-06-18 15:51:53 +0000
+++ include/origin_viewitem.h	2015-09-03 20:52:14 +0000
@@ -42,10 +42,11 @@
 {
 public:
     ///> Marker symbol styles
-    enum MARKER_STYLE { NONE, CROSS, X, DOT };
+    enum MARKER_STYLE { NONE, CROSS, X, DOT, CCROSS, CX, CDOT };
 
-    ORIGIN_VIEWITEM( const COLOR4D& aColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 ), MARKER_STYLE aStyle = X,
-                     int aSize = 16, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) );
+    ORIGIN_VIEWITEM( const COLOR4D& aColor = COLOR4D( 1.0, 1.0, 1.0, 1.0 ),
+                     MARKER_STYLE aStyle = CX, int aSize = 16,
+                     const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) );
 
     const BOX2I ViewBBox() const;
 
@@ -71,6 +72,11 @@
         return wxT( "ORIGIN_VIEWITEM" );
     }
 
+    inline void SetDrawAtZero( bool aDrawFlag )
+    {
+        m_drawatzero = aDrawFlag;
+    }
+
     inline void SetPosition( const VECTOR2D& aPosition )
     {
         m_position = aPosition;
@@ -123,6 +129,9 @@
 
     ///> Marker symbol.
     MARKER_STYLE    m_style;
+
+    ///> If set, the target will be drawn even if it's position is 0,0
+    bool            m_drawatzero;
 };
 
 } // namespace KIGFX

=== modified file 'pcbnew/moduleframe.cpp'
--- pcbnew/moduleframe.cpp	2015-08-26 09:50:16 +0000
+++ pcbnew/moduleframe.cpp	2015-09-03 19:21:09 +0000
@@ -931,6 +931,7 @@
     m_toolManager->GetTool<SELECTION_TOOL>()->EditModules( true );
     m_toolManager->GetTool<EDIT_TOOL>()->EditModules( true );
     m_toolManager->GetTool<DRAWING_TOOL>()->EditModules( true );
+    m_toolManager->GetTool<PCBNEW_CONTROL>()->EditModules( true );
 
     m_toolManager->ResetTools( TOOL_BASE::RUN );
     m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );

=== modified file 'pcbnew/tools/pcb_editor_control.cpp'
--- pcbnew/tools/pcb_editor_control.cpp	2015-08-03 09:53:58 +0000
+++ pcbnew/tools/pcb_editor_control.cpp	2015-09-03 20:56:09 +0000
@@ -85,7 +85,7 @@
     TOOL_INTERACTIVE( "pcbnew.EditorControl" ), m_frame( NULL ), m_zoneMenu( NULL )
 {
     m_placeOrigin = new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D( 0.8, 0.0, 0.0, 1.0 ),
-                                                KIGFX::ORIGIN_VIEWITEM::CROSS );
+                                                KIGFX::ORIGIN_VIEWITEM::CCROSS );
     m_probingSchToPcb = false;
 }
 

=== modified file 'pcbnew/tools/pcbnew_control.cpp'
--- pcbnew/tools/pcbnew_control.cpp	2015-08-07 16:24:42 +0000
+++ pcbnew/tools/pcbnew_control.cpp	2015-09-03 20:55:19 +0000
@@ -58,15 +58,23 @@
 
 
 PCBNEW_CONTROL::PCBNEW_CONTROL() :
-    TOOL_INTERACTIVE( "pcbnew.Control" ), m_frame( NULL )
+    TOOL_INTERACTIVE( "pcbnew.Control" ), m_frame( NULL ), m_editModules( false )
 {
     m_gridOrigin = new KIGFX::ORIGIN_VIEWITEM();
+
+    // Generate an origin marker at 0,0 which is used as an axis origin marker (0,0)
+    m_axisOrigin = new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D(0.0, 0.5, 1.0, 1.0),
+                                               KIGFX::ORIGIN_VIEWITEM::CROSS,
+                                               200,
+                                               VECTOR2D(0,0) );
+    m_axisOrigin->SetDrawAtZero( true );
 }
 
 
 PCBNEW_CONTROL::~PCBNEW_CONTROL()
 {
     delete m_gridOrigin;
+    delete m_axisOrigin;
 }
 
 
@@ -79,6 +87,18 @@
         m_gridOrigin->SetPosition( getModel<BOARD>()->GetGridOrigin() );
         getView()->Remove( m_gridOrigin );
         getView()->Add( m_gridOrigin );
+
+        if( m_editModules )
+        {
+            // Draw the axis origin if we're editing modules (essentially in the footprint editor)
+            getView()->Remove( m_axisOrigin );
+            getView()->Add( m_axisOrigin );
+        }
+        else
+        {
+            // If we're not editing modules, make sure the axis origin is not in the view
+            getView()->Remove( m_axisOrigin );
+        }
     }
 }
 

=== modified file 'pcbnew/tools/pcbnew_control.h'
--- pcbnew/tools/pcbnew_control.h	2015-08-07 16:24:42 +0000
+++ pcbnew/tools/pcbnew_control.h	2015-09-03 20:29:18 +0000
@@ -47,6 +47,18 @@
     /// @copydoc TOOL_INTERACTIVE::Reset()
     void Reset( RESET_REASON aReason );
 
+    /**
+     * Function EditModules()
+     *
+     * Toggles edit module mode. When enabled, one may select parts of modules individually
+     * (graphics, pads, etc.), so they can be modified.
+     * @param aEnabled decides if the mode should be enabled.
+     */
+    inline void EditModules( bool aEnabled )
+    {
+        m_editModules = aEnabled;
+    }
+
     // View controls
     int ZoomInOut( const TOOL_EVENT& aEvent );
     int ZoomInOutCenter( const TOOL_EVENT& aEvent );
@@ -101,8 +113,14 @@
     ///> Grid origin marker.
     KIGFX::ORIGIN_VIEWITEM* m_gridOrigin;
 
+    ///> Axis 0 marker
+    KIGFX::ORIGIN_VIEWITEM* m_axisOrigin;
+
     ///> Applies the legacy canvas grid settings for GAL.
     void updateGrid();
+
+    /// Edit module mode flag.
+    bool m_editModules;
 };
 
 #endif


Follow ups