Commit f08585f9 authored by charras's avatar charras

Added dialog box to edit graphic items

parent 5c790f50
/**************************************/
/* dialog_graphic_item_properties.cpp */
/**************************************/
/* Edit parameters values of graphic items type DRAWSEGMENTS:
* Lines
* Circles
* Arcs
* used as graphic elements found on non copper layers in boards
* items on edge layers are considered as graphic items
* Pcb texts are not always graphic items and are not handled here
*/
#include "fctsys.h"
#include "macros.h"
#include "common.h"
#include "pcbnew.h"
#include "dialog_graphic_item_properties_base.h"
///////////////////////////////////////////////////////////////////////////
class DialogGraphicItemProperties: public DialogGraphicItemProperties_base
{
private:
WinEDA_BasePcbFrame* m_Parent;
wxDC* m_DC;
DRAWSEGMENT* m_Item;
public:
DialogGraphicItemProperties( WinEDA_BasePcbFrame* aParent, DRAWSEGMENT * aItem, wxDC * aDC);
~DialogGraphicItemProperties() {};
private:
void OnInitDialog( wxInitDialogEvent& event );
void OnOkClick( wxCommandEvent& event );
void OnCancelClick( wxCommandEvent& event );
void OnLayerChoice( wxCommandEvent& event );
};
DialogGraphicItemProperties::DialogGraphicItemProperties( WinEDA_BasePcbFrame* aParent, DRAWSEGMENT * aItem, wxDC * aDC):
DialogGraphicItemProperties_base( aParent )
{
m_Parent = aParent;
m_DC = aDC;
m_Item = aItem;
}
/*******************************************************************************************/
void WinEDA_BasePcbFrame::InstallGraphicItemPropertiesDialog(DRAWSEGMENT * aItem, wxDC* aDC)
/*******************************************************************************************/
{
DrawPanel->m_IgnoreMouseEvents = TRUE;
DialogGraphicItemProperties* dialog = new DialogGraphicItemProperties( this,
aItem, aDC );
dialog->ShowModal(); dialog->Destroy();
DrawPanel->MouseToCursorSchema();
DrawPanel->m_IgnoreMouseEvents = FALSE;
}
/**************************************************************************/
void DialogGraphicItemProperties::OnInitDialog( wxInitDialogEvent& event )
/**************************************************************************/
/* Initialize messages and values in text control,
* according to the item parameters values
*/
{
SetFont( *g_DialogFont );
SetFocus();
wxString msg;
// Change texts according to the segment shape:
switch ( m_Item->m_Shape )
{
case S_CIRCLE:
m_Start_Center_XText->SetLabel(_("Center X"));
m_Start_Center_YText->SetLabel(_("Center Y"));
m_EndX_Radius_Text->SetLabel(_("Point X"));
m_EndY_Text->SetLabel(_("Point Y"));
m_Angle_Text->Show(false);
m_Angle_Ctrl->Show(false);
break;
case S_ARC:
m_Start_Center_XText->SetLabel(_("Center X"));
m_Start_Center_YText->SetLabel(_("Center Y"));
m_EndX_Radius_Text->SetLabel(_("Start Point X"));
m_EndY_Text->SetLabel(_("Start Point Y"));
msg << m_Item->m_Angle;
m_Angle_Ctrl->SetValue(msg);
break;
default:
m_Angle_Text->Show(false);
m_Angle_Ctrl->Show(false);
break;
}
AddUnitSymbol( *m_Start_Center_XText );
PutValueInLocalUnits( *m_Center_StartXCtrl, m_Item->m_Start.x,
m_Parent->m_InternalUnits );
AddUnitSymbol( *m_Start_Center_YText );
PutValueInLocalUnits( *m_Center_StartYCtrl, m_Item->m_Start.y,
m_Parent->m_InternalUnits );
AddUnitSymbol( *m_EndX_Radius_Text );
PutValueInLocalUnits( *m_EndX_Radius_Ctrl, m_Item->m_End.x,
m_Parent->m_InternalUnits );
AddUnitSymbol( *m_EndY_Text );
PutValueInLocalUnits( *m_EndY_Ctrl, m_Item->m_End.y,
m_Parent->m_InternalUnits );
AddUnitSymbol( *m_ItemThicknessText );
PutValueInLocalUnits( *m_ThicknessCtrl, m_Item->m_Width,
m_Parent->m_InternalUnits );
AddUnitSymbol( *m_DefaultThicknessText );
int thickness;
if( m_Item->GetLayer() == EDGE_N )
thickness = g_DesignSettings.m_EdgeSegmentWidth;
else
thickness = g_DesignSettings.m_DrawSegmentWidth;
PutValueInLocalUnits( *m_DefaultThicknessCtrl, thickness,
m_Parent->m_InternalUnits );
for( int layer=FIRST_NO_COPPER_LAYER; layer <= LAST_NO_COPPER_LAYER; ++layer )
{
m_LayerSelection->Append( m_Parent->m_Pcb->GetLayerName( layer ) );
}
int layer = m_Item->GetLayer();
// Control:
if ( layer < FIRST_NO_COPPER_LAYER )
layer = FIRST_NO_COPPER_LAYER;
if ( layer > LAST_NO_COPPER_LAYER )
layer = LAST_NO_COPPER_LAYER;
m_LayerSelection->SetSelection( layer - FIRST_NO_COPPER_LAYER );
}
/*******************************************************************/
void DialogGraphicItemProperties::OnLayerChoice( wxCommandEvent& event )
/*******************************************************************/
{
int thickness;
if( (m_LayerSelection->GetCurrentSelection() + FIRST_NO_COPPER_LAYER) == EDGE_N )
thickness = g_DesignSettings.m_EdgeSegmentWidth;
else
thickness = g_DesignSettings.m_DrawSegmentWidth;
PutValueInLocalUnits( *m_DefaultThicknessCtrl, thickness,
m_Parent->m_InternalUnits );
}
/*******************************************************************/
void DialogGraphicItemProperties::OnOkClick( wxCommandEvent& event )
/*******************************************************************/
/* Copy values in text contro to the item parameters
*/
{
wxString msg;
if ( m_DC )
m_Item->Draw( m_Parent->DrawPanel, m_DC, GR_XOR );
msg = m_Center_StartXCtrl->GetValue();
m_Item->m_Start.x = ReturnValueFromString( g_UnitMetric, msg,
m_Parent->m_InternalUnits );
msg = m_Center_StartYCtrl->GetValue();
m_Item->m_Start.y = ReturnValueFromString( g_UnitMetric, msg,
m_Parent->m_InternalUnits );
msg = m_EndX_Radius_Ctrl->GetValue();
m_Item->m_End.x = ReturnValueFromString( g_UnitMetric, msg,
m_Parent->m_InternalUnits );
msg = m_EndY_Ctrl->GetValue();
m_Item->m_End.y = ReturnValueFromString( g_UnitMetric, msg,
m_Parent->m_InternalUnits );
msg = m_ThicknessCtrl->GetValue();
m_Item->m_Width = ReturnValueFromString( g_UnitMetric, msg,
m_Parent->m_InternalUnits );
msg = m_DefaultThicknessCtrl->GetValue();
int thickness = ReturnValueFromString( g_UnitMetric, msg,
m_Parent->m_InternalUnits );
m_Item->SetLayer( m_LayerSelection->GetCurrentSelection() + FIRST_NO_COPPER_LAYER);
if( m_Item->GetLayer() == EDGE_N )
g_DesignSettings.m_EdgeSegmentWidth = thickness;
else
g_DesignSettings.m_DrawSegmentWidth = thickness;
if ( m_Item->m_Shape == S_ARC )
{
long angle;
m_Angle_Ctrl->GetValue().ToLong(&angle);
NORMALIZE_ANGLE(angle);
m_Item->m_Angle = angle;
}
m_Parent->GetScreen()->SetModify();
if ( m_DC )
m_Item->Draw( m_Parent->DrawPanel, m_DC, GR_OR );
m_Item->Display_Infos( m_Parent );
Close( TRUE );
}
void DialogGraphicItemProperties::OnCancelClick( wxCommandEvent& event )
{
event.Skip();
}
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "dialog_graphic_item_properties_base.h"
///////////////////////////////////////////////////////////////////////////
DialogGraphicItemProperties_base::DialogGraphicItemProperties_base( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bMainSizer;
bMainSizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bLeftSizer;
bLeftSizer = new wxBoxSizer( wxVERTICAL );
m_Start_Center_XText = new wxStaticText( this, wxID_ANY, wxT("Start Position X"), wxDefaultPosition, wxDefaultSize, 0 );
m_Start_Center_XText->Wrap( -1 );
bLeftSizer->Add( m_Start_Center_XText, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_Center_StartXCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bLeftSizer->Add( m_Center_StartXCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_Start_Center_YText = new wxStaticText( this, wxID_ANY, wxT("Start Position Y"), wxDefaultPosition, wxDefaultSize, 0 );
m_Start_Center_YText->Wrap( -1 );
bLeftSizer->Add( m_Start_Center_YText, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_Center_StartYCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bLeftSizer->Add( m_Center_StartYCtrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_EndX_Radius_Text = new wxStaticText( this, wxID_ANY, wxT("End Position X"), wxDefaultPosition, wxDefaultSize, 0 );
m_EndX_Radius_Text->Wrap( -1 );
bLeftSizer->Add( m_EndX_Radius_Text, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_EndX_Radius_Ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bLeftSizer->Add( m_EndX_Radius_Ctrl, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
m_EndY_Text = new wxStaticText( this, wxID_ANY, wxT("End Position Y"), wxDefaultPosition, wxDefaultSize, 0 );
m_EndY_Text->Wrap( -1 );
bLeftSizer->Add( m_EndY_Text, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_EndY_Ctrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bLeftSizer->Add( m_EndY_Ctrl, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
m_Angle_Text = new wxStaticText( this, wxID_ANY, wxT("Arc Angle (0.1 degree)"), wxDefaultPosition, wxDefaultSize, 0 );
m_Angle_Text->Wrap( -1 );
bLeftSizer->Add( m_Angle_Text, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_Angle_Ctrl = new wxTextCtrl( this, wxID_ANGLE_CTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bLeftSizer->Add( m_Angle_Ctrl, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
bMainSizer->Add( bLeftSizer, 1, wxEXPAND, 5 );
wxBoxSizer* bMiddleSizer;
bMiddleSizer = new wxBoxSizer( wxVERTICAL );
m_ItemThicknessText = new wxStaticText( this, wxID_ANY, wxT("Item Thickness"), wxDefaultPosition, wxDefaultSize, 0 );
m_ItemThicknessText->Wrap( -1 );
bMiddleSizer->Add( m_ItemThicknessText, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_ThicknessCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_ThicknessCtrl->SetToolTip( wxT("Thickness of this item") );
bMiddleSizer->Add( m_ThicknessCtrl, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
m_DefaultThicknessText = new wxStaticText( this, wxID_ANY, wxT("Default Thickness"), wxDefaultPosition, wxDefaultSize, 0 );
m_DefaultThicknessText->Wrap( -1 );
bMiddleSizer->Add( m_DefaultThicknessText, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_DefaultThicknessCtrl = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_DefaultThicknessCtrl->SetToolTip( wxT("Default value for thickness when creating a new graphic item") );
bMiddleSizer->Add( m_DefaultThicknessCtrl, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bMiddleSizer->Add( m_staticline1, 0, wxEXPAND | wxALL, 5 );
m_LayerText = new wxStaticText( this, wxID_ANY, wxT("Layer:"), wxDefaultPosition, wxDefaultSize, 0 );
m_LayerText->Wrap( -1 );
bMiddleSizer->Add( m_LayerText, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
wxArrayString m_LayerSelectionChoices;
m_LayerSelection = new wxChoice( this, wxID_LAYER_SELECTION, wxDefaultPosition, wxDefaultSize, m_LayerSelectionChoices, 0 );
m_LayerSelection->SetSelection( 0 );
bMiddleSizer->Add( m_LayerSelection, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
bMainSizer->Add( bMiddleSizer, 1, wxEXPAND, 5 );
wxBoxSizer* bRightSizer;
bRightSizer = new wxBoxSizer( wxVERTICAL );
m_buttonOK = new wxButton( this, wxID_OK, wxT("OK"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonOK->SetDefault();
bRightSizer->Add( m_buttonOK, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
m_buttonCANCEL = new wxButton( this, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
bRightSizer->Add( m_buttonCANCEL, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
bMainSizer->Add( bRightSizer, 0, wxALIGN_CENTER_VERTICAL, 5 );
this->SetSizer( bMainSizer );
this->Layout();
// Connect Events
this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DialogGraphicItemProperties_base::OnInitDialog ) );
m_LayerSelection->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DialogGraphicItemProperties_base::OnLayerChoice ), NULL, this );
m_buttonOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DialogGraphicItemProperties_base::OnOkClick ), NULL, this );
m_buttonCANCEL->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DialogGraphicItemProperties_base::OnCancelClick ), NULL, this );
}
DialogGraphicItemProperties_base::~DialogGraphicItemProperties_base()
{
// Disconnect Events
this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DialogGraphicItemProperties_base::OnInitDialog ) );
m_LayerSelection->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DialogGraphicItemProperties_base::OnLayerChoice ), NULL, this );
m_buttonOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DialogGraphicItemProperties_base::OnOkClick ), NULL, this );
m_buttonCANCEL->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DialogGraphicItemProperties_base::OnCancelClick ), NULL, this );
}
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __dialog_graphic_item_properties_base__
#define __dialog_graphic_item_properties_base__
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/textctrl.h>
#include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/choice.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class DialogGraphicItemProperties_base
///////////////////////////////////////////////////////////////////////////////
class DialogGraphicItemProperties_base : public wxDialog
{
private:
protected:
enum
{
wxID_ANGLE_CTRL = 1000,
wxID_LAYER_SELECTION,
};
wxStaticText* m_Start_Center_XText;
wxTextCtrl* m_Center_StartXCtrl;
wxStaticText* m_Start_Center_YText;
wxTextCtrl* m_Center_StartYCtrl;
wxStaticText* m_EndX_Radius_Text;
wxTextCtrl* m_EndX_Radius_Ctrl;
wxStaticText* m_EndY_Text;
wxTextCtrl* m_EndY_Ctrl;
wxStaticText* m_Angle_Text;
wxTextCtrl* m_Angle_Ctrl;
wxStaticText* m_ItemThicknessText;
wxTextCtrl* m_ThicknessCtrl;
wxStaticText* m_DefaultThicknessText;
wxTextCtrl* m_DefaultThicknessCtrl;
wxStaticLine* m_staticline1;
wxStaticText* m_LayerText;
wxChoice* m_LayerSelection;
wxButton* m_buttonOK;
wxButton* m_buttonCANCEL;
// Virtual event handlers, overide them in your derived class
virtual void OnInitDialog( wxInitDialogEvent& event ){ event.Skip(); }
virtual void OnLayerChoice( wxCommandEvent& event ){ event.Skip(); }
virtual void OnOkClick( wxCommandEvent& event ){ event.Skip(); }
virtual void OnCancelClick( wxCommandEvent& event ){ event.Skip(); }
public:
DialogGraphicItemProperties_base( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Graphic item properties"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 348,247 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER|wxSYSTEM_MENU );
~DialogGraphicItemProperties_base();
};
#endif //__dialog_graphic_item_properties_base__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment