You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

429 lines
14 KiB

  1. /***************/
  2. /* eelayer.cpp */
  3. /***************/
  4. /* Set up color Layers for EESchema
  5. */
  6. #if defined(__GNUG__) && !defined(__APPLE__)
  7. #pragma implementation "eelayer.h"
  8. #endif
  9. // For compilers that support precompilation, includes "wx/wx.h".
  10. #include "wx/wxprec.h"
  11. #ifdef __BORLANDC__
  12. #pragma hdrstop
  13. #endif
  14. #ifndef WX_PRECOMP
  15. #include "wx/wx.h"
  16. #endif
  17. #include "fctsys.h"
  18. #include "gr_basic.h"
  19. #include "common.h"
  20. #include "program.h"
  21. #include "libcmp.h"
  22. #include "general.h"
  23. #include "id.h"
  24. #include "protos.h"
  25. #include "eelayer.h" // Header file associated with this file
  26. // Local variables:
  27. int CurrentColor[NB_BUTT]; // Holds color for each layer while dialog box open
  28. IMPLEMENT_DYNAMIC_CLASS( WinEDA_SetColorsFrame, wxDialog )
  29. // Table of events for WinEDA_SetColorsFrame
  30. BEGIN_EVENT_TABLE( WinEDA_SetColorsFrame, wxDialog )
  31. EVT_COMMAND_RANGE( ID_COLOR_SETUP, ID_COLOR_SETUP + NB_BUTT - 1,
  32. wxEVT_COMMAND_BUTTON_CLICKED,
  33. WinEDA_SetColorsFrame::SetColor )
  34. EVT_BUTTON( wxID_OK, WinEDA_SetColorsFrame::OnOkClick )
  35. EVT_BUTTON( wxID_CANCEL, WinEDA_SetColorsFrame::OnCancelClick )
  36. EVT_BUTTON( wxID_APPLY, WinEDA_SetColorsFrame::OnApplyClick )
  37. END_EVENT_TABLE()
  38. /**************************************************************/
  39. void DisplayColorSetupFrame( WinEDA_DrawFrame* parent,
  40. const wxPoint& framepos )
  41. /**************************************************************/
  42. {
  43. WinEDA_SetColorsFrame* frame =
  44. new WinEDA_SetColorsFrame( parent, framepos );
  45. frame->ShowModal();
  46. frame->Destroy();
  47. }
  48. // Default Constructor (whose provision is mandated by the inclusion
  49. // of DECLARE_DYNAMIC_CLASS( WinEDA_SetColorsFrame ) within eelayer.h)
  50. WinEDA_SetColorsFrame::WinEDA_SetColorsFrame()
  51. {
  52. Init();
  53. }
  54. // Standard Constructor
  55. WinEDA_SetColorsFrame::WinEDA_SetColorsFrame( WinEDA_DrawFrame* parent,
  56. const wxPoint& framepos )
  57. {
  58. m_Parent = parent;
  59. Init();
  60. Create( parent,
  61. SYMBOL_WINEDA_SETCOLORSFRAME_IDNAME,
  62. SYMBOL_WINEDA_SETCOLORSFRAME_TITLE,
  63. framepos,
  64. wxDefaultSize,
  65. SYMBOL_WINEDA_SETCOLORSFRAME_STYLE );
  66. }
  67. // Destructor
  68. WinEDA_SetColorsFrame::~WinEDA_SetColorsFrame() { }
  69. /**********************************************************/
  70. bool WinEDA_SetColorsFrame::Create( wxWindow* parent, wxWindowID id,
  71. const wxString& caption, const wxPoint& pos,
  72. const wxSize& size, long style )
  73. /**********************************************************/
  74. {
  75. SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
  76. wxDialog::Create( parent, id, caption, pos, size, style );
  77. CreateControls();
  78. if (GetSizer())
  79. {
  80. GetSizer()->SetSizeHints(this);
  81. }
  82. return true;
  83. }
  84. /**********************************************************/
  85. void WinEDA_SetColorsFrame::Init()
  86. /**********************************************************/
  87. {
  88. OuterBoxSizer = NULL;
  89. MainBoxSizer = NULL;
  90. ColumnBoxSizer = NULL;
  91. RowBoxSizer = NULL;
  92. Label = NULL;
  93. BitmapButton = NULL;
  94. m_ShowGrid = NULL;
  95. m_SelBgColor = NULL;
  96. Line = NULL;
  97. StdDialogButtonSizer = NULL;
  98. Button = NULL;
  99. }
  100. /**********************************************************/
  101. void WinEDA_SetColorsFrame::CreateControls()
  102. /**********************************************************/
  103. {
  104. int lyr, grp, butt_ID, buttcolor;
  105. SetFont( *g_DialogFont );
  106. OuterBoxSizer = new wxBoxSizer(wxVERTICAL);
  107. SetSizer(OuterBoxSizer);
  108. MainBoxSizer = new wxBoxSizer(wxHORIZONTAL);
  109. OuterBoxSizer->Add(MainBoxSizer, 1, wxGROW|wxLEFT|wxRIGHT, 5);
  110. // Add various items to the dialog box, as determined by the
  111. // details of each element contained within laytool_list[]
  112. for( lyr = 0, grp = 0; lyr < NB_BUTT; lyr++ )
  113. {
  114. // Look for the initial button of each group of controls.
  115. if( lyr == 0 || lyr == laytool_index[grp]->m_Index + 1 )
  116. {
  117. if( lyr != 0 )
  118. grp++;
  119. // Add another column sizer, unless the current value of
  120. // grp is BUTTON_GROUPS - 1. (The very last group of controls
  121. // differs from the previous groups in that its associated
  122. // controls are located in the same column as the controls
  123. // associated with the preceeding group.)
  124. if( grp < BUTTON_GROUPS - 1 )
  125. {
  126. ColumnBoxSizer = new wxBoxSizer(wxVERTICAL);
  127. MainBoxSizer->Add(ColumnBoxSizer, 1, wxALIGN_TOP|wxLEFT|wxTOP, 5);
  128. }
  129. else
  130. {
  131. // Add a spacer to better separate the text string (which is
  132. // about to be added) from the items located above it.
  133. ColumnBoxSizer->AddSpacer(5);
  134. }
  135. RowBoxSizer = new wxBoxSizer(wxHORIZONTAL);
  136. ColumnBoxSizer->Add(RowBoxSizer, 0, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM, 5);
  137. // Add a text string to identify the following set of controls
  138. Label = new wxStaticText( this, -1, laytool_index[grp]->m_Name,
  139. wxDefaultPosition, wxDefaultSize, 0 );
  140. // Make this text string bold (so that it stands out better)
  141. Label->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxNORMAL_FONT->GetFamily(),
  142. wxNORMAL, wxBOLD, false, wxNORMAL_FONT->GetFaceName() ) );
  143. RowBoxSizer->Add(Label, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
  144. }
  145. RowBoxSizer = new wxBoxSizer(wxHORIZONTAL);
  146. ColumnBoxSizer->Add(RowBoxSizer, 0, wxGROW|wxALL, 0);
  147. butt_ID = ID_COLOR_SETUP + lyr;
  148. laytool_list[lyr]->m_Id = butt_ID;
  149. wxMemoryDC iconDC;
  150. wxBitmap ButtBitmap( BUTT_SIZE_X, BUTT_SIZE_Y );
  151. iconDC.SelectObject( ButtBitmap );
  152. buttcolor = *laytool_list[lyr]->m_Color;
  153. CurrentColor[lyr] = buttcolor;
  154. wxBrush Brush;
  155. iconDC.SelectObject( ButtBitmap );
  156. iconDC.SetPen( *wxBLACK_PEN );
  157. Brush.SetColour(
  158. ColorRefs[buttcolor].m_Red,
  159. ColorRefs[buttcolor].m_Green,
  160. ColorRefs[buttcolor].m_Blue
  161. );
  162. Brush.SetStyle( wxSOLID );
  163. iconDC.SetBrush( Brush );
  164. iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
  165. BitmapButton = new wxBitmapButton( this, butt_ID, ButtBitmap, wxDefaultPosition, wxSize(BUTT_SIZE_X, BUTT_SIZE_Y) );
  166. RowBoxSizer->Add(BitmapButton, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxBOTTOM, 5);
  167. laytool_list[lyr]->m_Button = BitmapButton;
  168. // Add a text string, unless the current value of lyr is NB_BUTT - 1
  169. if( lyr < NB_BUTT - 1 )
  170. {
  171. Label = new wxStaticText( this, wxID_STATIC, wxGetTranslation( laytool_list[lyr]->m_Name ),
  172. wxDefaultPosition, wxDefaultSize, 0 );
  173. RowBoxSizer->Add(Label, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5);
  174. }
  175. else
  176. {
  177. // Special case; provide a checkbox instead (rather than a text string).
  178. m_ShowGrid = new wxCheckBox( this, ID_CHECKBOX_SHOW_GRID, _("Grid"), wxDefaultPosition, wxDefaultSize, 0 );
  179. m_ShowGrid->SetValue( m_Parent->m_Draw_Grid );
  180. RowBoxSizer->Add(m_ShowGrid, 1, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5);
  181. }
  182. }
  183. // Add a spacer to improve appearance.
  184. ColumnBoxSizer->AddSpacer(5);
  185. wxArrayString m_SelBgColorStrings;
  186. m_SelBgColorStrings.Add(_("White"));
  187. m_SelBgColorStrings.Add(_("Black"));
  188. m_SelBgColor = new wxRadioBox( this, ID_RADIOBOX_BACKGROUND_COLOR, _("Background Color:"),
  189. wxDefaultPosition, wxDefaultSize, m_SelBgColorStrings, 1, wxRA_SPECIFY_COLS );
  190. m_SelBgColor->SetSelection( ( g_DrawBgColor == BLACK ) ? 1 : 0 );
  191. ColumnBoxSizer->Add(m_SelBgColor, 1, wxGROW|wxRIGHT|wxTOP|wxBOTTOM, 5);
  192. // Provide a line to separate all of the controls added so far from the
  193. // "OK", "Cancel", and "Apply" buttons (which will be added after that line).
  194. Line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
  195. OuterBoxSizer->Add(Line, 0, wxGROW|wxALL, 5);
  196. // Provide a StdDialogButtonSizer to accommodate the OK, Cancel, and Apply
  197. // buttons; using that type of sizer results in those buttons being
  198. // automatically located in positions appropriate for each (OS) version of KiCad.
  199. StdDialogButtonSizer = new wxStdDialogButtonSizer;
  200. OuterBoxSizer->Add(StdDialogButtonSizer, 0, wxGROW|wxALL, 10);
  201. Button = new wxButton( this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
  202. Button->SetForegroundColour( *wxRED );
  203. StdDialogButtonSizer->AddButton(Button);
  204. Button = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
  205. Button->SetForegroundColour( *wxBLUE );
  206. StdDialogButtonSizer->AddButton(Button);
  207. Button->SetFocus();
  208. Button = new wxButton( this, wxID_APPLY, _("Apply"), wxDefaultPosition, wxDefaultSize, 0 );
  209. StdDialogButtonSizer->AddButton(Button);
  210. StdDialogButtonSizer->Realize();
  211. // (Dialog now needs to be resized, but the associated command is found elsewhere.)
  212. }
  213. /**********************************************************/
  214. bool WinEDA_SetColorsFrame::ShowToolTips()
  215. /**********************************************************/
  216. {
  217. return true;
  218. }
  219. /**********************************************************/
  220. wxBitmap WinEDA_SetColorsFrame::GetBitmapResource( const wxString& name )
  221. /**********************************************************/
  222. {
  223. wxUnusedVar(name);
  224. return wxNullBitmap;
  225. }
  226. /**********************************************************/
  227. wxIcon WinEDA_SetColorsFrame::GetIconResource( const wxString& name )
  228. /**********************************************************/
  229. {
  230. wxUnusedVar(name);
  231. return wxNullIcon;
  232. }
  233. /**********************************************************/
  234. void WinEDA_SetColorsFrame::SetColor( wxCommandEvent& event )
  235. /**********************************************************/
  236. {
  237. int id = event.GetId();
  238. int color;
  239. wxBitmapButton* Button;
  240. color = DisplayColorFrame( this,
  241. CurrentColor[id - ID_COLOR_SETUP] );
  242. if( color < 0 )
  243. return;
  244. if( CurrentColor[id - ID_COLOR_SETUP] == color )
  245. return;
  246. CurrentColor[id - ID_COLOR_SETUP] = color;
  247. wxMemoryDC iconDC;
  248. Button = laytool_list[id - ID_COLOR_SETUP]->m_Button;
  249. wxBitmap ButtBitmap = Button->GetBitmapLabel();
  250. iconDC.SelectObject( ButtBitmap );
  251. wxBrush Brush;
  252. iconDC.SetPen( *wxBLACK_PEN );
  253. Brush.SetColour(
  254. ColorRefs[color].m_Red,
  255. ColorRefs[color].m_Green,
  256. ColorRefs[color].m_Blue
  257. );
  258. Brush.SetStyle( wxSOLID );
  259. iconDC.SetBrush( Brush );
  260. iconDC.DrawRectangle( 0, 0, BUTT_SIZE_X, BUTT_SIZE_Y );
  261. Button->SetBitmapLabel( ButtBitmap );
  262. Button->Refresh();
  263. Refresh( FALSE );
  264. }
  265. /******************************************************************/
  266. void WinEDA_SetColorsFrame::UpdateLayerSettings()
  267. /******************************************************************/
  268. {
  269. // Update colors for each layer
  270. for( int lyr = 0; lyr < NB_BUTT; lyr++ )
  271. {
  272. // (As a bitmap button has been provided for *every* layer,
  273. // it is not necessary to check whether it actually has been
  274. // provided for each of those layers.)
  275. *laytool_list[lyr]->m_Color = CurrentColor[lyr];
  276. }
  277. // Update whether grid is actually displayed or otherwise
  278. // m_Parent->m_Draw_Grid = g_ShowGrid = m_ShowGrid->GetValue();
  279. // The previous command compiles OK, but to prevent a warning
  280. // from being generated when the Linux version is being compiled,
  281. // the next two commands are provided instead.
  282. g_ShowGrid = m_ShowGrid->GetValue();
  283. m_Parent->m_Draw_Grid = g_ShowGrid;
  284. // Update color of background
  285. if( m_SelBgColor->GetSelection() == 0 )
  286. g_DrawBgColor = WHITE;
  287. else
  288. g_DrawBgColor = BLACK;
  289. m_Parent->SetDrawBgColor( g_DrawBgColor );
  290. }
  291. /**********************************************************************/
  292. void WinEDA_SetColorsFrame::OnOkClick( wxCommandEvent& WXUNUSED (event) )
  293. /**********************************************************************/
  294. {
  295. UpdateLayerSettings();
  296. m_Parent->ReDrawPanel();
  297. EndModal( 1 );
  298. }
  299. /*******************************************************************/
  300. void WinEDA_SetColorsFrame::OnCancelClick( wxCommandEvent& WXUNUSED (event) )
  301. /*******************************************************************/
  302. {
  303. EndModal( -1 );
  304. }
  305. /*******************************************************************/
  306. void WinEDA_SetColorsFrame::OnApplyClick( wxCommandEvent& WXUNUSED (event) )
  307. /*******************************************************************/
  308. {
  309. UpdateLayerSettings();
  310. m_Parent->ReDrawPanel();
  311. }
  312. /*************************/
  313. void SeedLayers()
  314. /*************************/
  315. {
  316. LayerStruct* LayerPointer = &g_LayerDescr;
  317. int pt;
  318. LayerPointer->CommonColor = WHITE;
  319. LayerPointer->Flags = 0;
  320. pt = 0;
  321. LayerPointer->CurrentWidth = 1;
  322. /* seed Up the Layer colours, set all user layers off */
  323. for( pt = 0; pt < MAX_LAYERS; pt++ )
  324. {
  325. LayerPointer->LayerStatus[pt] = 0;
  326. LayerPointer->LayerColor[pt] = DARKGRAY;
  327. }
  328. LayerPointer->NumberOfLayers = pt - 1;
  329. /* Couleurs specifiques: Mise a jour par la lecture de la config */
  330. }
  331. /*******************************/
  332. int ReturnLayerColor( int Layer )
  333. /*******************************/
  334. {
  335. if( g_LayerDescr.Flags == 0 )
  336. return g_LayerDescr.LayerColor[Layer];
  337. else
  338. return g_LayerDescr.CommonColor;
  339. }