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.

175 lines
5.6 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2010 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2016 KiCad Developers, see CHANGELOG.TXT for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <fctsys.h>
  25. #include <macros.h>
  26. #include <gr_basic.h>
  27. #include <base_units.h>
  28. #include <bitmaps.h>
  29. #include <lib_edit_frame.h>
  30. #include <class_libentry.h>
  31. #include <lib_pin.h>
  32. #include <dialog_lib_edit_pin.h>
  33. DIALOG_LIB_EDIT_PIN::DIALOG_LIB_EDIT_PIN( EDA_DRAW_FRAME* parent, LIB_PIN* aPin ) :
  34. DIALOG_LIB_EDIT_PIN_BASE( parent )
  35. {
  36. // Creates a dummy pin to show on a panel, inside this dialog:
  37. m_dummyPin = new LIB_PIN( *aPin );
  38. // m_dummyPin changes do not propagate to other pins of the current lib component,
  39. // so set parent to null and clear flags
  40. m_dummyPin->SetParent( NULL );
  41. m_dummyPin->ClearFlags();
  42. m_panelShowPin->SetBackgroundColour( parent->GetDrawBgColor().ToColour() );
  43. // Set tab order
  44. m_textPadName->MoveAfterInTabOrder(m_textPinName);
  45. m_sdbSizerButtonsOK->SetDefault();
  46. // On some windows manager (Unity, XFCE), this dialog is
  47. // not always raised, depending on this dialog is run.
  48. // Force it to be raised
  49. Raise();
  50. }
  51. DIALOG_LIB_EDIT_PIN::~DIALOG_LIB_EDIT_PIN()
  52. {
  53. delete m_dummyPin;
  54. }
  55. void DIALOG_LIB_EDIT_PIN::OnInitDialog( wxInitDialogEvent& event )
  56. {
  57. m_textPinName->SetFocus();
  58. // Now all widgets have the size fixed, call FinishDialogSettings
  59. FinishDialogSettings();
  60. }
  61. /*
  62. * Draw (on m_panelShowPin) the pin currently edited
  63. * accroding to current settings in dialog
  64. */
  65. void DIALOG_LIB_EDIT_PIN::OnPaintShowPanel( wxPaintEvent& event )
  66. {
  67. wxPaintDC dc( m_panelShowPin );
  68. wxSize dc_size = dc.GetSize();
  69. dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
  70. // Give a parent to m_dummyPin only from draw purpose.
  71. // In fact m_dummyPin should not have a parent, but draw functions need a parent
  72. // to know some options, about pin texts
  73. LIB_EDIT_FRAME* libframe = (LIB_EDIT_FRAME*) GetParent();
  74. m_dummyPin->SetParent( libframe->GetCurPart() );
  75. // Calculate a suitable scale to fit the available draw area
  76. EDA_RECT bBox = m_dummyPin->GetBoundingBox();
  77. double xscale = (double) dc_size.x / bBox.GetWidth();
  78. double yscale = (double) dc_size.y / bBox.GetHeight();
  79. double scale = std::min( xscale, yscale );
  80. // Give a 10% margin
  81. scale *= 0.9;
  82. dc.SetUserScale( scale, scale );
  83. wxPoint offset = -bBox.Centre();
  84. GRResetPenAndBrush( &dc );
  85. // This is a flag for m_dummyPin->Draw
  86. uintptr_t flags = uintptr_t( PIN_DRAW_TEXTS | PIN_DRAW_DANGLING );
  87. m_dummyPin->Draw( NULL, &dc, offset, COLOR4D::UNSPECIFIED, GR_COPY,
  88. (void*)flags, DefaultTransform );
  89. m_dummyPin->SetParent(NULL);
  90. event.Skip();
  91. }
  92. void DIALOG_LIB_EDIT_PIN::OnCloseDialog( wxCloseEvent& event )
  93. {
  94. EndModal( wxID_CANCEL );
  95. }
  96. void DIALOG_LIB_EDIT_PIN::OnCancelButtonClick( wxCommandEvent& event )
  97. {
  98. EndModal( wxID_CANCEL );
  99. }
  100. void DIALOG_LIB_EDIT_PIN::OnOKButtonClick( wxCommandEvent& event )
  101. {
  102. EndModal( wxID_OK );
  103. }
  104. // Called when a pin properties changes
  105. void DIALOG_LIB_EDIT_PIN::OnPropertiesChange( wxCommandEvent& event )
  106. {
  107. if( ! IsShown() ) // do nothing at init time
  108. return;
  109. int pinNameSize = ValueFromString( g_UserUnit, GetPinNameTextSize() );
  110. int pinNumSize = ValueFromString( g_UserUnit, GetPadNameTextSize());
  111. int pinOrient = LIB_PIN::GetOrientationCode( GetOrientation() );
  112. int pinLength = ValueFromString( g_UserUnit, GetLength() );
  113. GRAPHIC_PINSHAPE pinShape = GetStyle();
  114. ELECTRICAL_PINTYPE pinType = GetElectricalType();
  115. m_dummyPin->SetName( GetPinName() );
  116. m_dummyPin->SetNameTextSize( pinNameSize );
  117. m_dummyPin->SetNumber( GetPadName() );
  118. m_dummyPin->SetNumberTextSize( pinNumSize );
  119. m_dummyPin->SetOrientation( pinOrient );
  120. m_dummyPin->SetLength( pinLength );
  121. m_dummyPin->SetShape( pinShape );
  122. m_dummyPin->SetVisible( GetVisible() );
  123. m_dummyPin->SetType( pinType );
  124. m_panelShowPin->Refresh();
  125. }
  126. void DIALOG_LIB_EDIT_PIN::SetDlgUnitsLabel( const wxString& units )
  127. {
  128. m_staticNameTextSizeUnits->SetLabel( units );
  129. m_staticNumberTextSizeUnits->SetLabel( units );
  130. m_staticLengthUnits->SetLabel( units );
  131. m_staticPosXUnits->SetLabel( units );
  132. m_staticPosYUnits->SetLabel( units );
  133. }
  134. void DIALOG_LIB_EDIT_PIN::SetOrientationList( const wxArrayString& list,
  135. const BITMAP_DEF* aBitmaps )
  136. {
  137. for ( unsigned ii = 0; ii < list.GetCount(); ii++ )
  138. {
  139. if( aBitmaps == NULL )
  140. m_choiceOrientation->Append( list[ii] );
  141. else
  142. m_choiceOrientation->Insert( list[ii], KiBitmap( aBitmaps[ii] ), ii );
  143. }
  144. }