← Back to team overview

kicad-developers team mailing list archive

[PATCH] Make pcbnew show & edit radius for circle objects

 

This commit makes the object properties dialog in pcbnew show the circle
radius instead of the end point coordinates. When saving the change, the
original direction of the end point is preserved.
---
 pcbnew/class_drawsegment.h                        | 24 ++++++++++++++
 pcbnew/dialogs/dialog_graphic_item_properties.cpp | 39 +++++++++++++++++------
 2 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/pcbnew/class_drawsegment.h b/pcbnew/class_drawsegment.h
index 411a5a2..6843954 100644
--- a/pcbnew/class_drawsegment.h
+++ b/pcbnew/class_drawsegment.h
@@ -147,6 +147,30 @@ public:
     }
 
     /**
+     * Function SetRadius
+     * sets the radius of this item (preserving direction)
+     * Has meaning only for arc and circle
+     */
+    void SetRadius( int aRadius )
+    {
+        double old_r = GetLineLength( m_Start, m_End );
+        wxPoint r_vec = m_End - m_Start;
+        if( old_r < 1 )
+        {
+            /* If the circle is degenerate, use the x coordinate for radius */
+            r_vec.x = aRadius;
+            r_vec.y = 0;
+        }
+        else
+        {
+            /* Expand/shrink the vector to the new radius */
+            r_vec.x = KiROUND( (double)r_vec.x * aRadius / old_r );
+            r_vec.y = KiROUND( (double)r_vec.y * aRadius / old_r );
+        }
+        m_End = m_Start + r_vec;
+    }
+
+    /**
      * Initialize the start arc point. can be used for circles
      * to initialize one point of the cicumference
      */
diff --git a/pcbnew/dialogs/dialog_graphic_item_properties.cpp b/pcbnew/dialogs/dialog_graphic_item_properties.cpp
index d8c2098..b87ff4f 100644
--- a/pcbnew/dialogs/dialog_graphic_item_properties.cpp
+++ b/pcbnew/dialogs/dialog_graphic_item_properties.cpp
@@ -145,11 +145,14 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow()
         SetTitle( _( "Circle Properties" ) );
         m_StartPointXLabel->SetLabel( _( "Center X:" ) );
         m_StartPointYLabel->SetLabel( _( "Center Y:" ) );
-        m_EndPointXLabel->SetLabel( _( "Point X:" ) );
-        m_EndPointYLabel->SetLabel( _( "Point Y:" ) );
+        m_EndPointXLabel->SetLabel( _( "Radius:" ) );
+        m_EndPointYLabel->Show( false );
+        m_EndY_Ctrl->Show( false );
+        m_EndPointYUnit->Show( false );
         m_AngleText->Show( false );
         m_AngleCtrl->Show( false );
         m_AngleUnit->Show( false );
+
         break;
 
     case S_ARC:
@@ -177,7 +180,10 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow()
 
     PutValueInLocalUnits( *m_Center_StartYCtrl, m_item->GetStart().y );
 
-    PutValueInLocalUnits( *m_EndX_Radius_Ctrl, m_item->GetEnd().x );
+    if( m_item->GetShape() == S_CIRCLE )
+        PutValueInLocalUnits( *m_EndX_Radius_Ctrl, m_item->GetRadius());
+    else
+        PutValueInLocalUnits( *m_EndX_Radius_Ctrl, m_item->GetEnd().x);
 
     PutValueInLocalUnits( *m_EndY_Ctrl, m_item->GetEnd().y );
 
@@ -240,11 +246,19 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow()
     msg = m_Center_StartYCtrl->GetValue();
     m_item->SetStartY( ValueFromString( g_UserUnit, msg ) );
 
-    msg = m_EndX_Radius_Ctrl->GetValue();
-    m_item->SetEndX( ValueFromString( g_UserUnit, msg ) );
+    if( m_item->GetShape() == S_CIRCLE )
+    {
+        msg = m_EndX_Radius_Ctrl->GetValue();
+        m_item->SetRadius( ValueFromString( g_UserUnit, msg ) );
+    }
+    else
+    {
+        msg = m_EndX_Radius_Ctrl->GetValue();
+        m_item->SetEndX( ValueFromString( g_UserUnit, msg ) );
 
-    msg = m_EndY_Ctrl->GetValue();
-    m_item->SetEndY( ValueFromString( g_UserUnit, msg ) );
+        msg = m_EndY_Ctrl->GetValue();
+        m_item->SetEndY( ValueFromString( g_UserUnit, msg ) );
+    }
 
     msg = m_ThicknessCtrl->GetValue();
     m_item->SetWidth( ValueFromString( g_UserUnit, msg ) );
@@ -300,11 +314,18 @@ bool DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate()
             error_msgs.Add( _( "The arc angle must be greater than zero." ) );
         }
 
-        // Fall through.
+        // Check radius.
+        if( (startx == endx) && (starty == endy) )
+        {
+            error_msgs.Add( _( "The radius must be greater than zero." ) );
+        }
+
+        break;
+
     case S_CIRCLE:
 
         // Check radius.
-        if( (startx == endx) && (starty == endy) )
+        if( endx <= 0 )
         {
             error_msgs.Add( _( "The radius must be greater than zero." ) );
         }

References