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.

804 lines
23 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
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.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 <base_units.h>
  34. #include <msgpanel.h>
  35. #include <lib_edit_frame.h>
  36. #include <eeschema_id.h>
  37. #include <class_libentry.h>
  38. #include <lib_pin.h>
  39. #include <general.h>
  40. #include <confirm.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( GetDrawItem() == NULL || GetDrawItem()->Type() != LIB_PIN_T )
  79. return;
  80. STATUS_FLAGS item_flags = GetDrawItem()->GetFlags(); // save flags to restore them after editing
  81. LIB_PIN* pin = (LIB_PIN*) GetDrawItem();
  82. DIALOG_LIB_EDIT_PIN dlg( this, pin );
  83. wxString units = GetUnitsLabel( g_UserUnit );
  84. dlg.SetDlgUnitsLabel( units );
  85. dlg.SetOrientationList( LIB_PIN::GetOrientationNames(), LIB_PIN::GetOrientationSymbols() );
  86. dlg.SetOrientation( LIB_PIN::GetOrientationCodeIndex( pin->GetOrientation() ) );
  87. dlg.SetStyle( pin->GetShape() );
  88. dlg.SetElectricalType( pin->GetType() );
  89. dlg.SetPinName( pin->GetName() );
  90. dlg.SetPinNameTextSize( StringFromValue( g_UserUnit, pin->GetNameTextSize() ) );
  91. dlg.SetPinPositionX( StringFromValue( g_UserUnit, pin->GetPosition().x ) );
  92. dlg.SetPinPositionY( StringFromValue( g_UserUnit, -pin->GetPosition().y ) );
  93. dlg.SetPadName( pin->GetNumber() );
  94. dlg.SetPadNameTextSize( StringFromValue( g_UserUnit, pin->GetNumberTextSize() ) );
  95. dlg.SetLength( StringFromValue( g_UserUnit, pin->GetLength() ) );
  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. // Test the pin position validity: to avoid issues in schematic,
  118. // it must be on a 50 mils grid
  119. wxPoint pinpos;
  120. pinpos.x = ValueFromString( g_UserUnit, dlg.GetPinPositionX() );
  121. pinpos.y = -ValueFromString( g_UserUnit, dlg.GetPinPositionY() );
  122. const int acceptable_mingrid = 50;
  123. if( (pinpos.x % acceptable_mingrid) || (pinpos.y % acceptable_mingrid) )
  124. {
  125. wxString msg;
  126. msg.Printf( _( "This pin is not on a %d mils grid\n"
  127. "It will be not easy to connect in schematic\n"
  128. "Do you want to continue?"), acceptable_mingrid );
  129. if( !IsOK( this, msg ) )
  130. return;
  131. }
  132. // Save the pin properties to use for the next new pin.
  133. LastPinNameSize = ValueFromString( g_UserUnit, dlg.GetPinNameTextSize() );
  134. LastPinNumSize = ValueFromString( g_UserUnit, dlg.GetPadNameTextSize() );
  135. LastPinOrient = LIB_PIN::GetOrientationCode( dlg.GetOrientation() );
  136. LastPinLength = ValueFromString( g_UserUnit, dlg.GetLength() );
  137. LastPinShape = dlg.GetStyle();
  138. LastPinType = dlg.GetElectricalType();
  139. LastPinCommonConvert = dlg.GetAddToAllBodyStyles();
  140. LastPinCommonUnit = dlg.GetAddToAllParts();
  141. LastPinVisible = dlg.GetVisible();
  142. if( !pin->InEditMode() )
  143. SaveCopyInUndoList( pin->GetParent() );
  144. pin->EnableEditMode( true, SynchronizePins()? false : true );
  145. pin->SetName( dlg.GetPinName() );
  146. pin->SetNameTextSize( GetLastPinNameSize() );
  147. pin->SetNumber( dlg.GetPadName() );
  148. pin->SetNumberTextSize( GetLastPinNumSize() );
  149. pin->SetOrientation( LastPinOrient );
  150. pin->SetLength( GetLastPinLength() );
  151. pin->SetPinPosition( pinpos );
  152. pin->SetType( LastPinType );
  153. pin->SetShape( LastPinShape );
  154. pin->SetConversion( ( LastPinCommonConvert ) ? 0 : m_convert );
  155. pin->SetPartNumber( ( LastPinCommonUnit ) ? 0 : m_unit );
  156. pin->SetVisible( LastPinVisible );
  157. if( pin->IsModified() || pin->IsNew() )
  158. {
  159. OnModify( );
  160. MSG_PANEL_ITEMS items;
  161. pin->GetMsgPanelInfo( items );
  162. SetMsgPanel( items );
  163. m_canvas->Refresh();
  164. }
  165. pin->EnableEditMode( false );
  166. // Restore pin flags, that can be changed by the dialog editor
  167. pin->ClearFlags();
  168. pin->SetFlags( item_flags );
  169. }
  170. /**
  171. * Clean up after aborting a move pin command.
  172. */
  173. static void AbortPinMove( EDA_DRAW_PANEL* Panel, wxDC* DC )
  174. {
  175. LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) Panel->GetParent();
  176. if( parent == NULL )
  177. return;
  178. LIB_PIN* pin = (LIB_PIN*) parent->GetDrawItem();
  179. if( pin == NULL || pin->Type() != LIB_PIN_T )
  180. return;
  181. pin->ClearFlags();
  182. if( pin->IsNew() )
  183. delete pin;
  184. else
  185. parent->RestoreComponent();
  186. // clear edit flags
  187. parent->SetDrawItem( NULL );
  188. parent->SetLastDrawItem( NULL );
  189. Panel->Refresh( true );
  190. }
  191. /**
  192. * Managed cursor callback for placing component pins.
  193. */
  194. void LIB_EDIT_FRAME::PlacePin()
  195. {
  196. LIB_PIN* cur_pin = (LIB_PIN*) GetDrawItem();
  197. // Some tests
  198. if( !cur_pin || cur_pin->Type() != LIB_PIN_T )
  199. {
  200. wxMessageBox( wxT( "LIB_EDIT_FRAME::PlacePin() error" ) );
  201. return;
  202. }
  203. wxPoint newpos;
  204. newpos = GetCrossHairPosition( true );
  205. LIB_PART* part = GetCurPart();
  206. // Test for another pin in same new position in other units:
  207. bool ask_for_pin = true;
  208. for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
  209. {
  210. if( pin == cur_pin || newpos != pin->GetPosition() || pin->GetFlags() )
  211. continue;
  212. // test for same body style
  213. if( pin->GetConvert() && pin->GetConvert() != cur_pin->GetConvert() )
  214. continue;
  215. if( ask_for_pin && SynchronizePins() )
  216. {
  217. m_canvas->SetIgnoreMouseEvents( true );
  218. wxString msg;
  219. msg.Printf( _( "This position is already occupied by another pin, in unit %d.\n"
  220. "Continue?" ), pin->GetUnit() );
  221. bool status = IsOK( this, msg );
  222. m_canvas->MoveCursorToCrossHair();
  223. m_canvas->SetIgnoreMouseEvents( false );
  224. if( !status )
  225. return;
  226. else
  227. ask_for_pin = false;
  228. }
  229. }
  230. // Create Undo from GetTempCopyComponent() if exists ( i.e. after a pin move)
  231. // or from m_component (pin add ...)
  232. if( GetTempCopyComponent() )
  233. SaveCopyInUndoList( GetTempCopyComponent() );
  234. else
  235. SaveCopyInUndoList( part );
  236. m_canvas->SetMouseCapture( NULL, NULL );
  237. cur_pin->Move( newpos );
  238. if( cur_pin->IsNew() )
  239. {
  240. LastPinOrient = cur_pin->GetOrientation();
  241. LastPinType = cur_pin->GetType();
  242. LastPinShape = cur_pin->GetShape();
  243. if( SynchronizePins() )
  244. CreateImagePins( cur_pin );
  245. m_lastDrawItem = cur_pin;
  246. part->AddDrawItem( GetDrawItem() );
  247. }
  248. // Put linked pins in new position, and clear flags
  249. for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
  250. {
  251. if( pin->GetFlags() == 0 )
  252. continue;
  253. pin->Move( cur_pin->GetPosition() );
  254. pin->ClearFlags();
  255. }
  256. SetDrawItem( NULL );
  257. OnModify();
  258. m_canvas->Refresh();
  259. }
  260. void LIB_EDIT_FRAME::StartMovePin( LIB_ITEM* aItem )
  261. {
  262. LIB_PIN* cur_pin = (LIB_PIN*) aItem;
  263. wxPoint startPos;
  264. TempCopyComponent();
  265. LIB_PART* part = GetCurPart();
  266. // Clear pin flags and mark pins for moving. All pins having the same location
  267. // orientation, and body style are flagged.
  268. for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
  269. {
  270. pin->ClearFlags();
  271. if( !SynchronizePins() )
  272. continue;
  273. if( pin == cur_pin )
  274. continue;
  275. if( pin->GetPosition() == cur_pin->GetPosition() &&
  276. pin->GetOrientation() == cur_pin->GetOrientation() &&
  277. pin->GetConvert() == cur_pin->GetConvert()
  278. )
  279. {
  280. pin->SetFlags( IS_LINKED | IS_MOVED );
  281. }
  282. }
  283. cur_pin->SetFlags( IS_LINKED | IS_MOVED );
  284. PinPreviousPos = OldPos = cur_pin->GetPosition();
  285. startPos.x = OldPos.x;
  286. startPos.y = -OldPos.y;
  287. SetCrossHairPosition( startPos );
  288. m_canvas->MoveCursorToCrossHair();
  289. MSG_PANEL_ITEMS items;
  290. cur_pin->GetMsgPanelInfo( items );
  291. SetMsgPanel( items );
  292. m_canvas->SetMouseCapture( DrawMovePin, AbortPinMove );
  293. // Refresh the screen to avoid color artifacts when drawing
  294. // the pin in Edit mode and moving it from its start position
  295. m_canvas->Refresh();
  296. }
  297. /* Move pin to the current mouse position. This function is called by the
  298. * cursor management code. */
  299. static void DrawMovePin( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
  300. bool aErase )
  301. {
  302. LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) aPanel->GetParent();
  303. if( parent == NULL )
  304. return;
  305. LIB_PIN* cur_pin = (LIB_PIN*) parent->GetDrawItem();
  306. if( cur_pin == NULL || cur_pin->Type() != LIB_PIN_T )
  307. return;
  308. wxPoint pinpos = cur_pin->GetPosition();
  309. int show_opts = PIN_DRAW_TEXTS | PIN_DRAW_DANGLING | PIN_DANGLING_HIDDEN;
  310. if( parent->GetShowElectricalType() )
  311. show_opts |= PIN_DRAW_ELECTRICAL_TYPE_NAME;
  312. // In LIB_PIN::Draw() a void* parameter used as flag to pass show_opts.
  313. // Build it:
  314. void* showOptions = reinterpret_cast<void*>( show_opts );
  315. // Erase pin in old position
  316. if( aErase )
  317. {
  318. cur_pin->Move( PinPreviousPos );
  319. cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode,
  320. showOptions, DefaultTransform );
  321. }
  322. // Redraw pin in new position
  323. cur_pin->Move( aPanel->GetParent()->GetCrossHairPosition( true ) );
  324. cur_pin->Draw( aPanel, aDC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode,
  325. showOptions, DefaultTransform );
  326. PinPreviousPos = cur_pin->GetPosition();
  327. /* Keep the original position for existing pin (for Undo command)
  328. * and the current position for a new pin */
  329. if( !cur_pin->IsNew() )
  330. cur_pin->Move( pinpos );
  331. }
  332. /*
  333. * Create a new pin.
  334. */
  335. void LIB_EDIT_FRAME::CreatePin( wxDC* DC )
  336. {
  337. LIB_PART* part = GetCurPart();
  338. if( !part )
  339. return;
  340. part->ClearStatus();
  341. LIB_PIN* pin = new LIB_PIN( part );
  342. SetDrawItem( pin );
  343. pin->SetFlags( IS_NEW );
  344. pin->SetUnit( m_unit );
  345. pin->SetConvert( m_convert );
  346. // Flag pins to consider
  347. if( SynchronizePins() )
  348. pin->SetFlags( IS_LINKED );
  349. pin->Move( GetCrossHairPosition( true ) );
  350. pin->SetLength( GetLastPinLength() );
  351. pin->SetOrientation( LastPinOrient );
  352. pin->SetType( LastPinType );
  353. pin->SetShape( LastPinShape );
  354. pin->SetNameTextSize( GetLastPinNameSize() );
  355. pin->SetNumberTextSize( GetLastPinNumSize() );
  356. pin->SetConvert( LastPinCommonConvert ? 0 : m_convert );
  357. pin->SetUnit( LastPinCommonUnit ? 0 : m_unit );
  358. pin->SetVisible( LastPinVisible );
  359. PinPreviousPos = pin->GetPosition();
  360. m_canvas->SetIgnoreMouseEvents( true );
  361. wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
  362. cmd.SetId( ID_LIBEDIT_EDIT_PIN );
  363. GetEventHandler()->ProcessEvent( cmd );
  364. m_canvas->MoveCursorToCrossHair();
  365. m_canvas->SetIgnoreMouseEvents( false );
  366. if( pin->GetFlags() & IS_CANCELLED )
  367. {
  368. deleteItem( DC, pin );
  369. }
  370. else
  371. {
  372. ClearTempCopyComponent();
  373. m_canvas->SetMouseCapture( DrawMovePin, AbortPinMove );
  374. if( DC )
  375. {
  376. int show_opts = PIN_DRAW_TEXTS | PIN_DRAW_DANGLING | PIN_DANGLING_HIDDEN;
  377. if( GetShowElectricalType() )
  378. show_opts |= PIN_DRAW_ELECTRICAL_TYPE_NAME;
  379. // In LIB_PIN::Draw() a void* parameter used as flag to pass show_opts.
  380. // Build it:
  381. void* showOptions = reinterpret_cast<void*>( show_opts );
  382. pin->Draw( m_canvas, DC, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, GR_COPY,
  383. showOptions, DefaultTransform );
  384. }
  385. }
  386. }
  387. void LIB_EDIT_FRAME::CreateImagePins( LIB_PIN* aPin )
  388. {
  389. int ii;
  390. LIB_PIN* newPin;
  391. // if "synchronize pins edition" option is off, do not create any similar pin for other
  392. // units and/or shapes: each unit is edited regardless other units or body
  393. if( !SynchronizePins() )
  394. return;
  395. if( aPin->GetUnit() == 0 ) // Pin common to all units: no need to create similar pins.
  396. return;
  397. // When units are interchangeable, all units are expected to have similar pins
  398. // at the same position
  399. // to facilitate pin edition, create pins for all other units for the current body style
  400. // at the same position as aPin
  401. for( ii = 1; ii <= aPin->GetParent()->GetUnitCount(); ii++ )
  402. {
  403. if( ii == aPin->GetUnit() )
  404. continue;
  405. newPin = (LIB_PIN*) aPin->Clone();
  406. // To avoid mistakes, gives this pin a new pin number because
  407. // it does no have the save pin number as the master pin
  408. // Because we do not know the actual number, give it a temporary number
  409. wxString unknownNum;
  410. unknownNum.Printf( "%s-U%c", aPin->GetNumber(), wxChar( 'A' + ii - 1 ) );
  411. newPin->SetNumber( unknownNum );
  412. newPin->SetUnit( ii );
  413. aPin->GetParent()->AddDrawItem( newPin );
  414. }
  415. }
  416. /* aMasterPin is the "template" pin
  417. * aId is a param to select what should be mofified:
  418. * - aId = ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM:
  419. * Change pins text name size
  420. * - aId = ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM:
  421. * Change pins text num size
  422. * - aId = ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM:
  423. * Change pins length.
  424. *
  425. * If aMasterPin is selected ( .m_flag == IS_SELECTED ),
  426. * only the other selected pins are modified
  427. */
  428. void LIB_EDIT_FRAME::GlobalSetPins( LIB_PIN* aMasterPin, int aId )
  429. {
  430. LIB_PART* part = GetCurPart();
  431. if( !part || !aMasterPin )
  432. return;
  433. if( aMasterPin->Type() != LIB_PIN_T )
  434. return;
  435. bool selected = aMasterPin->IsSelected();
  436. for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
  437. {
  438. if( pin->GetConvert() && pin->GetConvert() != m_convert )
  439. continue;
  440. // Is it the "selected mode" ?
  441. if( selected && !pin->IsSelected() )
  442. continue;
  443. switch( aId )
  444. {
  445. case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM:
  446. pin->SetNumberTextSize( aMasterPin->GetNumberTextSize() );
  447. break;
  448. case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM:
  449. pin->SetNameTextSize( aMasterPin->GetNameTextSize() );
  450. break;
  451. case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM:
  452. pin->SetLength( aMasterPin->GetLength() );
  453. break;
  454. }
  455. // Clear the flag IS_CHANGED, which was set by previous changes (if any)
  456. // but not used here.
  457. pin->ClearFlags( IS_CHANGED );
  458. }
  459. // Now changes are made, call OnModify() to validate thes changes and set
  460. // the global change for UI
  461. OnModify();
  462. }
  463. // Create a new pin based on the previous pin with an incremented pin number.
  464. void LIB_EDIT_FRAME::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin )
  465. {
  466. wxString msg;
  467. LIB_PART* part = GetCurPart();
  468. if( !part || !SourcePin || SourcePin->Type() != LIB_PIN_T )
  469. return;
  470. LIB_PIN* pin = (LIB_PIN*) SourcePin->Clone();
  471. pin->ClearFlags();
  472. pin->SetFlags( IS_NEW );
  473. wxPoint step;
  474. switch( pin->GetOrientation() )
  475. {
  476. case PIN_UP:
  477. step.x = GetRepeatPinStep();
  478. break;
  479. case PIN_DOWN:
  480. step.x = GetRepeatPinStep();
  481. break;
  482. case PIN_LEFT:
  483. step.y = - GetRepeatPinStep();
  484. break;
  485. case PIN_RIGHT:
  486. step.y = - GetRepeatPinStep();
  487. break;
  488. }
  489. pin->Move( pin->GetPosition() + step );
  490. wxString nextName = pin->GetName();
  491. IncrementLabelMember( nextName, GetRepeatDeltaLabel() );
  492. pin->SetName( nextName );
  493. msg = pin->GetNumber();
  494. IncrementLabelMember( msg, GetRepeatDeltaLabel() );
  495. pin->SetNumber( msg );
  496. SetDrawItem( pin );
  497. if( SynchronizePins() )
  498. pin->SetFlags( IS_LINKED );
  499. wxPoint savepos = GetCrossHairPosition();
  500. m_canvas->CrossHairOff( DC );
  501. SetCrossHairPosition( wxPoint( pin->GetPosition().x, -pin->GetPosition().y ) );
  502. // Add this new pin in list, and creates pins for others parts if needed
  503. SetDrawItem( pin );
  504. ClearTempCopyComponent();
  505. PlacePin();
  506. m_lastDrawItem = pin;
  507. SetCrossHairPosition( savepos );
  508. m_canvas->CrossHairOn( DC );
  509. MSG_PANEL_ITEMS items;
  510. pin->GetMsgPanelInfo( items );
  511. SetMsgPanel( items );
  512. OnModify( );
  513. }
  514. // helper function to sort pins by pin num
  515. bool sort_by_pin_number( const LIB_PIN* ref, const LIB_PIN* tst )
  516. {
  517. int test = ref->GetNumber().Cmp( tst->GetNumber() );
  518. if( test == 0 )
  519. {
  520. test = ref->GetConvert() - tst->GetConvert();
  521. }
  522. if( test == 0 )
  523. {
  524. test = ref->GetUnit() - tst->GetUnit();
  525. }
  526. return test < 0;
  527. }
  528. void LIB_EDIT_FRAME::OnCheckComponent( wxCommandEvent& event )
  529. {
  530. LIB_PART* part = GetCurPart();
  531. if( !part )
  532. return;
  533. const int MIN_GRID_SIZE = 25;
  534. LIB_PINS pinList;
  535. part->GetPins( pinList );
  536. if( pinList.size() == 0 )
  537. {
  538. DisplayInfoMessage( this, _( "No pins!" ) );
  539. return;
  540. }
  541. // Sort pins by pin num, so 2 duplicate pins
  542. // (pins with the same number) will be consecutive in list
  543. sort( pinList.begin(), pinList.end(), sort_by_pin_number );
  544. // Test for duplicates:
  545. DIALOG_DISPLAY_HTML_TEXT_BASE error_display( this, wxID_ANY,
  546. _( "Marker Information" ),
  547. wxDefaultPosition,
  548. wxSize( 750, 600 ) );
  549. int dup_error = 0;
  550. for( unsigned ii = 1; ii < pinList.size(); ii++ )
  551. {
  552. LIB_PIN* curr_pin = pinList[ii];
  553. LIB_PIN* pin = pinList[ii - 1];
  554. if( pin->GetNumber() != curr_pin->GetNumber()
  555. || pin->GetConvert() != curr_pin->GetConvert() )
  556. continue;
  557. dup_error++;
  558. /* TODO I dare someone to find a way to make happy translators on
  559. this thing! Lorenzo */
  560. wxString msg = wxString::Format( _(
  561. "<b>Duplicate pin %s</b> \"%s\" at location <b>(%.3f, %.3f)</b>"
  562. " conflicts with pin %s \"%s\" at location <b>(%.3f, %.3f)</b>" ),
  563. GetChars( curr_pin->GetNumber() ),
  564. GetChars( curr_pin->GetName() ),
  565. curr_pin->GetPosition().x / 1000.0,
  566. -curr_pin->GetPosition().y / 1000.0,
  567. GetChars( pin->GetNumber() ),
  568. GetChars( pin->GetName() ),
  569. pin->GetPosition().x / 1000.0,
  570. -pin->GetPosition().y / 1000.0
  571. );
  572. if( part->GetUnitCount() > 1 )
  573. {
  574. msg += wxString::Format( _( " in units %c and %c" ),
  575. 'A' + curr_pin->GetUnit() - 1,
  576. 'A' + pin->GetUnit() - 1 );
  577. }
  578. if( m_showDeMorgan )
  579. {
  580. if( curr_pin->GetConvert() )
  581. msg += _( " of converted" );
  582. else
  583. msg += _( " of normal" );
  584. }
  585. msg += wxT( ".<br>" );
  586. error_display.m_htmlWindow->AppendToPage( msg );
  587. }
  588. // Test for off grid pins:
  589. int offgrid_error = 0;
  590. for( unsigned ii = 0; ii < pinList.size(); ii++ )
  591. {
  592. LIB_PIN* pin = pinList[ii];
  593. if( ( (pin->GetPosition().x % MIN_GRID_SIZE) == 0 ) &&
  594. ( (pin->GetPosition().y % MIN_GRID_SIZE) == 0 ) )
  595. continue;
  596. // "pin" is off grid here.
  597. offgrid_error++;
  598. wxString msg = wxString::Format( _(
  599. "<b>Off grid pin %s</b> \"%s\" at location <b>(%.3f, %.3f)</b>" ),
  600. GetChars( pin->GetNumber() ),
  601. GetChars( pin->GetName() ),
  602. pin->GetPosition().x / 1000.0,
  603. -pin->GetPosition().y / 1000.0
  604. );
  605. if( part->GetUnitCount() > 1 )
  606. {
  607. msg += wxString::Format( _( " in symbol %c" ), 'A' + pin->GetUnit() - 1 );
  608. }
  609. if( m_showDeMorgan )
  610. {
  611. if( pin->GetConvert() )
  612. msg += _( " of converted" );
  613. else
  614. msg += _( " of normal" );
  615. }
  616. msg += wxT( ".<br>" );
  617. error_display.m_htmlWindow->AppendToPage( msg );
  618. }
  619. if( !dup_error && !offgrid_error )
  620. DisplayInfoMessage( this, _( "No off grid or duplicate pins were found." ) );
  621. else
  622. error_display.ShowModal();
  623. }