← Back to team overview

kicad-developers team mailing list archive

Patch for Module Position in Module Edit Dialog

 

For some reason, my email did not get through to the list, so please
find the patch pasted in at the bottom of this through the yahoo
groups interface..

--

Hi Guys,

Please find attached a patch for adding module position to the Module
Edit dialog for pcbnew.

A couple of points -

(1) I'm not a c++ programmer, or a wxWidgets person so be gentle :)

(2) Please feel free to review and offer enhancement advice for me to
get the patch approved. I gather there is no regression test suite or
anything.

(3) Things that need to be done are either to get the wxTextValidator
working properly, or else validate the input manually. Also, the
screen needs a redraw if the module is repositioned through the
dialog, otherwise the module appears twice.

This added functionality is very useful for positioning
electro-mechanical parts like switches, displays and connectors and
things. I always prefer to type in the coordinates of these parts
rather than position them with a mouse.

Looking forward to some advice and feedback.

Best Regards,

Brian Sidebotham.

--

Index: pcbnew/dialog_edit_module.cpp
===================================================================
--- pcbnew/dialog_edit_module.cpp	(revision 1234)
+++ pcbnew/dialog_edit_module.cpp	(working copy)
@@ -168,6 +168,8 @@
wxBoxSizer* PropLeftSizer;
wxBoxSizer* PropRightSizer;
wxString msg;
+ wxStaticText* XPositionStatic = new
wxStaticText(m_PanelProperties, -1, _("X"));
+ wxStaticText* YPositionStatic = new
wxStaticText(m_PanelProperties, -1, _("Y"));
 
/* Create a sizer for controls in the left column */
PropLeftSizer = new wxBoxSizer( wxVERTICAL );
@@ -186,6 +188,24 @@
_( "Edit Module" ) );
Button->SetForegroundColour( wxColor( 0, 128, 80 ) );
PropRightSizer->Add( Button, 0, wxGROW | wxALL, 5 );
+
+ wxStaticBox* positionBox = new wxStaticBox(m_PanelProperties,
-1, _("Position") );
+ wxStaticBoxSizer* positionBoxSizer = new wxStaticBoxSizer(
positionBox, wxVERTICAL );
+ PropRightSizer->Add(positionBoxSizer, 0,
wxALIGN_CENTER_HORIZONTAL | wxALL, 5 );
+
+ m_ModPositionX = new wxTextCtrl( m_PanelProperties,
ID_MODULE_EDIT_X_POSITION, _(""), wxDefaultPosition, wxDefaultSize, 0,
wxTextValidator(wxFILTER_NUMERIC, NULL), wxTextCtrlNameStr);
+
+ PutValueInLocalUnits( *m_ModPositionX,
m_CurrentModule->GetPosition().x, PCB_INTERNAL_UNIT );
+ AddUnitSymbol( *XPositionStatic, g_UnitMetric );
+ positionBoxSizer->Add( XPositionStatic, 0, wxGROW | wxALL, 5 );
+ positionBoxSizer->Add( m_ModPositionX, 0, wxALL, 5 );
+
+ m_ModPositionY = new wxTextCtrl( m_PanelProperties,
ID_MODULE_EDIT_Y_POSITION, _(""), wxDefaultPosition, wxDefaultSize, 0,
wxTextValidator(wxFILTER_NUMERIC, NULL), wxTextCtrlNameStr);
+
+ PutValueInLocalUnits( *m_ModPositionY,
m_CurrentModule->GetPosition().y, PCB_INTERNAL_UNIT );
+ AddUnitSymbol( *YPositionStatic, g_UnitMetric );
+ positionBoxSizer->Add( YPositionStatic, 0, wxGROW | wxALL, 5 );
+ positionBoxSizer->Add( m_ModPositionY, 0, wxALL, 5 );
}
else // Module is edited in libedit
{
@@ -496,10 +516,17 @@
/******************************************************************************/
{
bool change_layer = FALSE;
+ wxPoint modpos;
 
+ // Set Module Position
+ modpos.x = ReturnValueFromTextCtrl( *m_ModPositionX,
PCB_INTERNAL_UNIT );
+ modpos.y = ReturnValueFromTextCtrl( *m_ModPositionY,
PCB_INTERNAL_UNIT );
+ m_CurrentModule->SetPosition(modpos);
+
if( m_DC )
m_Parent->DrawPanel->CursorOff( m_DC );
 
+
if( m_OrientValue )
{
long orient = 0; wxString msg = m_OrientValue->GetValue();
Index: pcbnew/dialog_edit_module.h
===================================================================
--- pcbnew/dialog_edit_module.h	(revision 1234)
+++ pcbnew/dialog_edit_module.h	(working copy)
@@ -15,7 +15,9 @@
ID_BROWSE_3D_LIB,
ID_ADD_3D_SHAPE,
ID_REMOVE_3D_SHAPE,
-	ID_NOTEBOOK
+	ID_NOTEBOOK,
+	ID_MODULE_EDIT_X_POSITION,
+	ID_MODULE_EDIT_Y_POSITION,
};
 
class Panel3D_Ctrl;
@@ -44,9 +46,10 @@
wxButton * m_DeleteFieddButton;
wxTextCtrl *m_Doc, *m_Keyword;
wxBoxSizer * m_GeneralBoxSizer;
- wxBoxSizer* m_PanelPropertiesBoxSizer;
+ wxBoxSizer* m_PanelPropertiesBoxSizer;
+ wxTextCtrl *m_ModPositionX, *m_ModPositionY;
+ wxString *m_ModPosXStr, *m_ModPosYStr;
 
-
public:
// Constructor and destructor
WinEDA_ModulePropertiesFrame(WinEDA_BasePcbFrame *parent,







Follow ups