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.

783 lines
22 KiB

15 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
* 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
* 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
15 years ago
16 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
* 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) 2004 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file pinedit.cpp
  27. * @brief Eeschema pin edit code.
  28. */
  29. #include <fctsys.h>
  30. #include <gr_basic.h>
  31. #include <class_drawpanel.h>
  32. #include <confirm.h>
  33. #include <class_sch_screen.h>
  34. #include <base_units.h>
  35. #include <msgpanel.h>
  36. #include <libeditframe.h>
  37. #include <eeschema_id.h>
  38. #include <class_libentry.h>
  39. #include <lib_pin.h>
  40. #include <general.h>
  41. #include <../common/dialogs/dialog_display_info_HTML_base.h>
  42. #include <dialog_lib_edit_pin.h>
  43. extern void IncrementLabelMember( wxString& name, int aIncrement );
  44. static void AbortPinMove( EDA_DRAW_PANEL* Panel, wxDC* DC );
  45. static void DrawMovePin( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositon, bool aErase );
  46. static wxPoint OldPos;
  47. static wxPoint PinPreviousPos;
  48. static ELECTRICAL_PINTYPE LastPinType = PIN_INPUT;
  49. static int LastPinOrient = PIN_RIGHT;
  50. static GRAPHIC_PINSHAPE LastPinShape = PINSHAPE_LINE;
  51. static bool LastPinCommonConvert = false;
  52. static bool LastPinCommonUnit = false;
  53. static bool LastPinVisible = true;
  54. // The -1 is a non-valid value to trigger delayed initialization
  55. static int LastPinLength = -1;
  56. static int LastPinNameSize = -1;
  57. static int LastPinNumSize = -1;
  58. static int GetLastPinLength()
  59. {
  60. if( LastPinLength == -1 )
  61. LastPinLength = LIB_EDIT_FRAME::GetDefaultPinLength();
  62. return LastPinLength;
  63. }
  64. static int GetLastPinNameSize()
  65. {
  66. if( LastPinNameSize == -1 )
  67. LastPinNameSize = LIB_EDIT_FRAME::GetPinNameDefaultSize();
  68. return LastPinNameSize;
  69. }
  70. static int GetLastPinNumSize()
  71. {
  72. if( LastPinNumSize == -1 )
  73. LastPinNumSize = LIB_EDIT_FRAME::GetPinNumDefaultSize();
  74. return LastPinNumSize;
  75. }
  76. void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event )
  77. {
  78. if( m_drawItem == NULL || m_drawItem->Type() != LIB_PIN_T )
  79. return;
  80. STATUS_FLAGS item_flags = m_drawItem->GetFlags(); // save flags to restore them after editing
  81. LIB_PIN* pin = (LIB_PIN*) m_drawItem;
  82. DIALOG_LIB_EDIT_PIN dlg( this, pin );
  83. wxString units = GetUnitsLabel( g_UserUnit );
  84. dlg.SetOrientationList( LIB_PIN::GetOrientationNames(), LIB_PIN::GetOrientationSymbols() );
  85. dlg.SetOrientation( LIB_PIN::GetOrientationCodeIndex( pin->GetOrientation() ) );
  86. dlg.SetStyle( pin->GetShape() );
  87. dlg.SetElectricalType( pin->GetType() );
  88. dlg.SetPinName( pin->GetName() );
  89. dlg.SetPinNameTextSize( StringFromValue( g_UserUnit, pin->GetNameTextSize() ) );
  90. dlg.SetPinNameTextSizeUnits( units );
  91. dlg.SetPadName( pin->GetNumberString() );
  92. dlg.SetPadNameTextSize( StringFromValue( g_UserUnit, pin->GetNumberTextSize() ) );
  93. dlg.SetPadNameTextSizeUnits( units );
  94. dlg.SetLength( StringFromValue( g_UserUnit, pin->GetLength() ) );
  95. dlg.SetLengthUnits( units );
  96. dlg.SetAddToAllParts( pin->GetUnit() == 0 );
  97. dlg.SetAddToAllBodyStyles( pin->GetConvert() == 0 );
  98. dlg.SetVisible( pin->IsVisible() );
  99. /* This ugly hack fixes a bug in wxWidgets 2.8.7 and likely earlier
  100. * versions for the flex grid sizer in wxGTK that prevents the last
  101. * column from being sized correctly. It doesn't cause any problems
  102. * on win32 so it doesn't need to wrapped in ugly #ifdef __WXGTK__
  103. * #endif.
  104. */
  105. dlg.Layout();
  106. dlg.Fit();
  107. dlg.SetMinSize( dlg.GetSize() );
  108. if( dlg.ShowModal() == wxID_CANCEL )
  109. {
  110. if( pin->IsNew() )
  111. {
  112. pin->SetFlags( IS_CANCELLED );
  113. m_canvas->EndMouseCapture();
  114. }
  115. return;
  116. }
  117. // Save the pin properties to use for the next new pin.
  118. LastPinNameSize = ValueFromString( g_UserUnit, dlg.GetPinNameTextSize() );
  119. LastPinNumSize = ValueFromString( g_UserUnit, dlg.GetPadNameTextSize() );
  120. LastPinOrient = LIB_PIN::GetOrientationCode( dlg.GetOrientation() );
  121. LastPinLength = ValueFromString( g_UserUnit, dlg.GetLength() );
  122. LastPinShape = dlg.GetStyle();
  123. LastPinType = dlg.GetElectricalType();
  124. LastPinCommonConvert = dlg.GetAddToAllBodyStyles();
  125. LastPinCommonUnit = dlg.GetAddToAllParts();
  126. LastPinVisible = dlg.GetVisible();
  127. pin->EnableEditMode( true, m_editPinsPerPartOrConvert );
  128. pin->SetName( dlg.GetPinName() );
  129. pin->SetNameTextSize( GetLastPinNameSize() );
  130. pin->SetNumber( dlg.GetPadName() );
  131. pin->SetNumberTextSize( GetLastPinNumSize() );
  132. pin->SetOrientation( LastPinOrient );
  133. pin->SetLength( GetLastPinLength() );
  134. pin->SetType( LastPinType );
  135. pin->SetShape( LastPinShape );
  136. pin->SetConversion( ( LastPinCommonConvert ) ? 0 : m_convert );
  137. pin->SetPartNumber( ( LastPinCommonUnit ) ? 0 : m_unit );
  138. pin->SetVisible( LastPinVisible );
  139. if( pin->IsModified() || pin->IsNew() )
  140. {
  141. if( !pin->InEditMode() )
  142. SaveCopyInUndoList( pin->GetParent() );
  143. OnModify( );
  144. MSG_PANEL_ITEMS items;
  145. pin->GetMsgPanelInfo( items );
  146. SetMsgPanel( items );
  147. m_canvas->Refresh();
  148. }
  149. pin->EnableEditMode( false, m_editPinsPerPartOrConvert );
  150. // Restore pin flags, that can be changed by the dialog editor
  151. pin->ClearFlags();
  152. pin->SetFlags( item_flags );
  153. }
  154. /**
  155. * Clean up after aborting a move pin command.
  156. */
  157. static void AbortPinMove( EDA_DRAW_PANEL* Panel, wxDC* DC )
  158. {
  159. LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) Panel->GetParent();
  160. if( parent == NULL )
  161. return;
  162. LIB_PIN* pin = (LIB_PIN*) parent->GetDrawItem();
  163. if( pin == NULL || pin->Type() != LIB_PIN_T )
  164. return;
  165. pin->ClearFlags();
  166. if( pin->IsNew() )
  167. delete pin;
  168. else
  169. parent->RestoreComponent();
  170. // clear edit flags
  171. parent->SetDrawItem( NULL );
  172. parent->SetLastDrawItem( NULL );
  173. Panel->Refresh( true );
  174. }
  175. /**
  176. * Managed cursor callback for placing component pins.
  177. */
  178. void LIB_EDIT_FRAME::PlacePin()
  179. {
  180. LIB_PIN* cur_pin = (LIB_PIN*) m_drawItem;
  181. bool ask_for_pin = true;
  182. wxPoint newpos;
  183. bool status;
  184. // Some tests
  185. if( !cur_pin || cur_pin->Type() != LIB_PIN_T )
  186. {
  187. wxMessageBox( wxT( "LIB_EDIT_FRAME::PlacePin() error" ) );
  188. return;
  189. }
  190. newpos = GetCrossHairPosition( true );
  191. LIB_PART* part = GetCurPart();
  192. // Test for an other pin in same new position:
  193. for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
  194. {
  195. if( pin == cur_pin || newpos != pin->GetPosition() || pin->GetFlags() )
  196. continue;
  197. if( ask_for_pin && SynchronizePins() )
  198. {
  199. m_canvas->SetIgnoreMouseEvents( true );
  200. status = IsOK( this, _( "This position is already occupied by another pin. Continue?" ) );
  201. m_canvas->MoveCursorToCrossHair();
  202. m_canvas->SetIgnoreMouseEvents( false );
  203. if( !status )
  204. return;
  205. else
  206. ask_for_pin = false;
  207. }
  208. }
  209. // Create Undo from GetTempCopyComponent() if exists ( i.e. after a pin move)
  210. // or from m_component (pin add ...)
  211. if( GetTempCopyComponent() )
  212. SaveCopyInUndoList( GetTempCopyComponent() );
  213. else
  214. SaveCopyInUndoList( part );
  215. m_canvas->SetMouseCapture( NULL, NULL );
  216. OnModify();
  217. cur_pin->Move( newpos );
  218. if( cur_pin->IsNew() )
  219. {
  220. LastPinOrient = cur_pin->GetOrientation();
  221. LastPinType = cur_pin->GetType();
  222. LastPinShape = cur_pin->GetShape();
  223. if( SynchronizePins() )
  224. CreateImagePins( cur_pin, m_unit, m_convert, m_showDeMorgan );
  225. m_lastDrawItem = cur_pin;
  226. part->AddDrawItem( m_drawItem );
  227. }
  228. // Put linked pins in new position, and clear flags
  229. for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
  230. {
  231. if( pin->GetFlags() == 0 )
  232. continue;
  233. pin->Move( cur_pin->GetPosition() );
  234. pin->ClearFlags();
  235. }
  236. m_drawItem = NULL;
  237. m_canvas->Refresh();
  238. }
  239. /**
  240. * Prepare the displacement of a pin
  241. *
  242. * Locate the pin pointed to by the cursor, and set the cursor management
  243. * function move the pin.
  244. */
  245. void LIB_EDIT_FRAME::StartMovePin( wxDC* DC )
  246. {
  247. LIB_PIN* cur_pin = (LIB_PIN*) m_drawItem;
  248. wxPoint startPos;
  249. TempCopyComponent();
  250. LIB_PART* part = GetCurPart();
  251. // Mark pins for moving.
  252. for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
  253. {
  254. pin->ClearFlags();
  255. if( pin == cur_pin )
  256. continue;
  257. if( pin->GetPosition() == cur_pin->GetPosition() &&
  258. pin->GetOrientation() == cur_pin->GetOrientation() && SynchronizePins() )
  259. {
  260. pin->SetFlags( IS_LINKED | IS_MOVED );
  261. }
  262. }
  263. cur_pin->SetFlags( IS_LINKED | IS_MOVED );
  264. PinPreviousPos = OldPos = cur_pin->GetPosition();
  265. startPos.x = OldPos.x;
  266. startPos.y = -OldPos.y;
  267. // m_canvas->CrossHairOff( DC );
  268. SetCrossHairPosition( startPos );
  269. m_canvas->MoveCursorToCrossHair();
  270. MSG_PANEL_ITEMS items;
  271. cur_pin->GetMsgPanelInfo( items );
  272. SetMsgPanel( items );
  273. m_canvas->SetMouseCapture( DrawMovePin, AbortPinMove );
  274. // m_canvas->CrossHairOn( DC );
  275. // Refresh the screen to avoid color artifacts when drawing
  276. // the pin in Edit mode and moving it from its start position
  277. m_canvas->Refresh();
  278. }
  279. /* Move pin to the current mouse position. This function is called by the
  280. * cursor management code. */
  281. static void DrawMovePin( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
  282. bool aErase )
  283. {
  284. LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) aPanel->GetParent();
  285. if( parent == NULL )
  286. return;
  287. LIB_PIN* cur_pin = (LIB_PIN*) parent->GetDrawItem();
  288. if( cur_pin == NULL || cur_pin->Type() != LIB_PIN_T )
  289. return;
  290. wxPoint pinpos = cur_pin->GetPosition();
  291. bool showPinText = true;
  292. // Erase pin in old position
  293. if( aErase )
  294. {
  295. cur_pin->Move( PinPreviousPos );
  296. cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), UNSPECIFIED_COLOR, g_XorMode,
  297. &showPinText, DefaultTransform );
  298. }
  299. // Redraw pin in new position
  300. cur_pin->Move( aPanel->GetParent()->GetCrossHairPosition( true ) );
  301. cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), UNSPECIFIED_COLOR, g_XorMode,
  302. &showPinText, DefaultTransform );
  303. PinPreviousPos = cur_pin->GetPosition();
  304. /* Keep the original position for existing pin (for Undo command)
  305. * and the current position for a new pin */
  306. if( !cur_pin->IsNew() )
  307. cur_pin->Move( pinpos );
  308. }
  309. /*
  310. * Create a new pin.
  311. */
  312. void LIB_EDIT_FRAME::CreatePin( wxDC* DC )
  313. {
  314. bool showPinText = true;
  315. LIB_PART* part = GetCurPart();
  316. if( !part )
  317. return;
  318. part->ClearStatus();
  319. LIB_PIN* pin = new LIB_PIN( part );
  320. m_drawItem = pin;
  321. pin->SetFlags( IS_NEW );
  322. pin->SetUnit( m_unit );
  323. pin->SetConvert( m_convert );
  324. // Flag pins to consider
  325. if( SynchronizePins() )
  326. pin->SetFlags( IS_LINKED );
  327. pin->Move( GetCrossHairPosition( true ) );
  328. pin->SetLength( GetLastPinLength() );
  329. pin->SetOrientation( LastPinOrient );
  330. pin->SetType( LastPinType );
  331. pin->SetShape( LastPinShape );
  332. pin->SetNameTextSize( GetLastPinNameSize() );
  333. pin->SetNumberTextSize( GetLastPinNumSize() );
  334. pin->SetConvert( LastPinCommonConvert ? 0 : m_convert );
  335. pin->SetUnit( LastPinCommonUnit ? 0 : m_unit );
  336. pin->SetVisible( LastPinVisible );
  337. PinPreviousPos = pin->GetPosition();
  338. m_canvas->SetIgnoreMouseEvents( true );
  339. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  340. cmd.SetId( ID_LIBEDIT_EDIT_PIN );
  341. GetEventHandler()->ProcessEvent( cmd );
  342. m_canvas->MoveCursorToCrossHair();
  343. m_canvas->SetIgnoreMouseEvents( false );
  344. if( pin->GetFlags() & IS_CANCELLED )
  345. {
  346. deleteItem( DC );
  347. }
  348. else
  349. {
  350. ClearTempCopyComponent();
  351. m_canvas->SetMouseCapture( DrawMovePin, AbortPinMove );
  352. if( DC )
  353. pin->Draw( m_canvas, DC, wxPoint( 0, 0 ), UNSPECIFIED_COLOR, GR_COPY, &showPinText,
  354. DefaultTransform );
  355. }
  356. }
  357. void LIB_EDIT_FRAME::CreateImagePins( LIB_PIN* aPin, int aUnit, int aConvert, bool aDeMorgan )
  358. {
  359. int ii;
  360. LIB_PIN* NewPin;
  361. if( !SynchronizePins() )
  362. return;
  363. // Create "convert" pin at the current position.
  364. if( aDeMorgan && ( aPin->GetConvert() != 0 ) )
  365. {
  366. NewPin = (LIB_PIN*) aPin->Clone();
  367. if( aPin->GetConvert() > 1 )
  368. NewPin->SetConvert( 1 );
  369. else
  370. NewPin->SetConvert( 2 );
  371. aPin->GetParent()->AddDrawItem( NewPin );
  372. }
  373. for( ii = 1; ii <= aPin->GetParent()->GetUnitCount(); ii++ )
  374. {
  375. if( ii == aUnit || aPin->GetUnit() == 0 )
  376. continue; // Pin common to all units.
  377. NewPin = (LIB_PIN*) aPin->Clone();
  378. // To avoid mistakes, gives this pin a new pin number because
  379. // it does no have the save pin number as the master pin
  380. // Because we do not know the actual number, give it '??'
  381. wxString unknownNum( wxT( "??" ) );
  382. NewPin->SetPinNumFromString( unknownNum );
  383. if( aConvert != 0 )
  384. NewPin->SetConvert( 1 );
  385. NewPin->SetUnit( ii );
  386. aPin->GetParent()->AddDrawItem( NewPin );
  387. if( !( aDeMorgan && ( aPin->GetConvert() != 0 ) ) )
  388. continue;
  389. NewPin = (LIB_PIN*) aPin->Clone();
  390. NewPin->SetConvert( 2 );
  391. // Gives this pin a new pin number
  392. // Because we do not know the actual number, give it '??'
  393. NewPin->SetPinNumFromString( unknownNum );
  394. if( aPin->GetUnit() != 0 )
  395. NewPin->SetUnit( ii );
  396. aPin->GetParent()->AddDrawItem( NewPin );
  397. }
  398. }
  399. /* aMasterPin is the "template" pin
  400. * aId is a param to select what should be mofified:
  401. * - aId = ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM:
  402. * Change pins text name size
  403. * - aId = ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM:
  404. * Change pins text num size
  405. * - aId = ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM:
  406. * Change pins length.
  407. *
  408. * If aMasterPin is selected ( .m_flag == IS_SELECTED ),
  409. * only the other selected pins are modified
  410. */
  411. void LIB_EDIT_FRAME::GlobalSetPins( LIB_PIN* aMasterPin, int aId )
  412. {
  413. LIB_PART* part = GetCurPart();
  414. if( !part || !aMasterPin )
  415. return;
  416. if( aMasterPin->Type() != LIB_PIN_T )
  417. return;
  418. OnModify( );
  419. bool selected = aMasterPin->IsSelected();
  420. for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
  421. {
  422. if( pin->GetConvert() && pin->GetConvert() != m_convert )
  423. continue;
  424. // Is it the "selected mode" ?
  425. if( selected && !pin->IsSelected() )
  426. continue;
  427. switch( aId )
  428. {
  429. case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM:
  430. pin->SetNumberTextSize( aMasterPin->GetNumberTextSize() );
  431. break;
  432. case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM:
  433. pin->SetNameTextSize( aMasterPin->GetNameTextSize() );
  434. break;
  435. case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM:
  436. pin->SetLength( aMasterPin->GetLength() );
  437. break;
  438. }
  439. // Clear the flag IS_CHANGED, which was set by previous changes (if any)
  440. // but not used here.
  441. pin->ClearFlags( IS_CHANGED );
  442. }
  443. }
  444. // Create a new pin based on the previous pin with an incremented pin number.
  445. void LIB_EDIT_FRAME::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin )
  446. {
  447. wxString msg;
  448. LIB_PART* part = GetCurPart();
  449. if( !part || !SourcePin || SourcePin->Type() != LIB_PIN_T )
  450. return;
  451. LIB_PIN* pin = (LIB_PIN*) SourcePin->Clone();
  452. pin->ClearFlags();
  453. pin->SetFlags( IS_NEW );
  454. wxPoint step;
  455. switch( pin->GetOrientation() )
  456. {
  457. case PIN_UP:
  458. step.x = GetRepeatPinStep();
  459. break;
  460. case PIN_DOWN:
  461. step.x = GetRepeatPinStep();
  462. break;
  463. case PIN_LEFT:
  464. step.y = - GetRepeatPinStep();
  465. break;
  466. case PIN_RIGHT:
  467. step.y = - GetRepeatPinStep();
  468. break;
  469. }
  470. pin->Move( pin->GetPosition() + step );
  471. wxString nextName = pin->GetName();
  472. IncrementLabelMember( nextName, GetRepeatDeltaLabel() );
  473. pin->SetName( nextName );
  474. pin->PinStringNum( msg );
  475. IncrementLabelMember( msg, GetRepeatDeltaLabel() );
  476. pin->SetPinNumFromString( msg );
  477. m_drawItem = pin;
  478. if( SynchronizePins() )
  479. pin->SetFlags( IS_LINKED );
  480. wxPoint savepos = GetCrossHairPosition();
  481. m_canvas->CrossHairOff( DC );
  482. SetCrossHairPosition( wxPoint( pin->GetPosition().x, -pin->GetPosition().y ) );
  483. // Add this new pin in list, and creates pins for others parts if needed
  484. m_drawItem = pin;
  485. ClearTempCopyComponent();
  486. PlacePin();
  487. m_lastDrawItem = pin;
  488. SetCrossHairPosition( savepos );
  489. m_canvas->CrossHairOn( DC );
  490. MSG_PANEL_ITEMS items;
  491. pin->GetMsgPanelInfo( items );
  492. SetMsgPanel( items );
  493. OnModify( );
  494. }
  495. // helper function to sort pins by pin num
  496. bool sort_by_pin_number( const LIB_PIN* ref, const LIB_PIN* tst )
  497. {
  498. int test = ref->GetNumber() - tst->GetNumber();
  499. if( test == 0 )
  500. {
  501. test = ref->GetConvert() - tst->GetConvert();
  502. }
  503. if( test == 0 )
  504. {
  505. test = ref->GetUnit() - tst->GetUnit();
  506. }
  507. return test < 0;
  508. }
  509. void LIB_EDIT_FRAME::OnCheckComponent( wxCommandEvent& event )
  510. {
  511. LIB_PART* part = GetCurPart();
  512. if( !part )
  513. return;
  514. const int MIN_GRID_SIZE = 25;
  515. LIB_PINS pinList;
  516. part->GetPins( pinList );
  517. if( pinList.size() == 0 )
  518. {
  519. DisplayInfoMessage( this, _( "No pins!" ) );
  520. return;
  521. }
  522. // Sort pins by pin num, so 2 duplicate pins
  523. // (pins with the same number) will be consecutive in list
  524. sort( pinList.begin(), pinList.end(), sort_by_pin_number );
  525. // Test for duplicates:
  526. DIALOG_DISPLAY_HTML_TEXT_BASE error_display( this, wxID_ANY,
  527. _( "Marker Information" ),
  528. wxDefaultPosition,
  529. wxSize( 750, 600 ) );
  530. int dup_error = 0;
  531. for( unsigned ii = 1; ii < pinList.size(); ii++ )
  532. {
  533. wxString stringPinNum, stringCurrPinNum;
  534. LIB_PIN* curr_pin = pinList[ii];
  535. LIB_PIN* pin = pinList[ii - 1];
  536. if( pin->GetNumber() != curr_pin->GetNumber()
  537. || pin->GetConvert() != curr_pin->GetConvert()
  538. || pin->GetUnit() != curr_pin->GetUnit() )
  539. continue;
  540. dup_error++;
  541. pin->PinStringNum( stringPinNum );
  542. /* TODO I dare someone to find a way to make happy translators on
  543. this thing! Lorenzo */
  544. curr_pin->PinStringNum( stringCurrPinNum );
  545. wxString msg = wxString::Format( _(
  546. "<b>Duplicate pin %s</b> \"%s\" at location <b>(%.3f, %.3f)</b>"
  547. " conflicts with pin %s \"%s\" at location <b>(%.3f, %.3f)</b>" ),
  548. GetChars( stringCurrPinNum ),
  549. GetChars( curr_pin->GetName() ),
  550. curr_pin->GetPosition().x / 1000.0,
  551. -curr_pin->GetPosition().y / 1000.0,
  552. GetChars( stringPinNum ),
  553. GetChars( pin->GetName() ),
  554. pin->GetPosition().x / 1000.0,
  555. -pin->GetPosition().y / 1000.0
  556. );
  557. if( part->GetUnitCount() > 1 )
  558. {
  559. msg += wxString::Format( _( " in part %c" ), 'A' + curr_pin->GetUnit() - 1 );
  560. }
  561. if( m_showDeMorgan )
  562. {
  563. if( curr_pin->GetConvert() )
  564. msg += _( " of converted" );
  565. else
  566. msg += _( " of normal" );
  567. }
  568. msg += wxT( ".<br>" );
  569. error_display.m_htmlWindow->AppendToPage( msg );
  570. }
  571. // Test for off grid pins:
  572. int offgrid_error = 0;
  573. for( unsigned ii = 0; ii < pinList.size(); ii++ )
  574. {
  575. LIB_PIN* pin = pinList[ii];
  576. if( ( (pin->GetPosition().x % MIN_GRID_SIZE) == 0 ) &&
  577. ( (pin->GetPosition().y % MIN_GRID_SIZE) == 0 ) )
  578. continue;
  579. // "pin" is off grid here.
  580. offgrid_error++;
  581. wxString stringPinNum;
  582. pin->PinStringNum( stringPinNum );
  583. wxString msg = wxString::Format( _(
  584. "<b>Off grid pin %s</b> \"%s\" at location <b>(%.3f, %.3f)</b>" ),
  585. GetChars( stringPinNum ),
  586. GetChars( pin->GetName() ),
  587. pin->GetPosition().x / 1000.0,
  588. -pin->GetPosition().y / 1000.0
  589. );
  590. if( part->GetUnitCount() > 1 )
  591. {
  592. msg += wxString::Format( _( " in part %c" ), 'A' + pin->GetUnit() - 1 );
  593. }
  594. if( m_showDeMorgan )
  595. {
  596. if( pin->GetConvert() )
  597. msg += _( " of converted" );
  598. else
  599. msg += _( " of normal" );
  600. }
  601. msg += wxT( ".<br>" );
  602. error_display.m_htmlWindow->AppendToPage( msg );
  603. }
  604. if( !dup_error && !offgrid_error )
  605. DisplayInfoMessage( this, _( "No off grid or duplicate pins were found." ) );
  606. else
  607. error_display.ShowModal();
  608. }