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.

262 lines
7.8 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
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2014 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. /**
  25. * @file operations_on_items_lists.cpp
  26. * @brief Functions used in block commands, or undo/redo, to move, mirror, delete, copy ...
  27. * lists of schematic items.
  28. */
  29. #include <fctsys.h>
  30. #include <pgm_base.h>
  31. #include <class_drawpanel.h>
  32. #include <schframe.h>
  33. #include <general.h>
  34. #include <protos.h>
  35. #include <sch_bus_entry.h>
  36. #include <sch_marker.h>
  37. #include <sch_line.h>
  38. #include <sch_no_connect.h>
  39. #include <sch_sheet.h>
  40. #include <sch_component.h>
  41. #include <sch_junction.h>
  42. void SetSchItemParent( SCH_ITEM* Struct, SCH_SCREEN* Screen )
  43. {
  44. switch( Struct->Type() )
  45. {
  46. case SCH_JUNCTION_T:
  47. case SCH_TEXT_T:
  48. case SCH_LABEL_T:
  49. case SCH_GLOBAL_LABEL_T:
  50. case SCH_HIERARCHICAL_LABEL_T:
  51. case SCH_COMPONENT_T:
  52. case SCH_LINE_T:
  53. case SCH_BUS_BUS_ENTRY_T:
  54. case SCH_BUS_WIRE_ENTRY_T:
  55. case SCH_SHEET_T:
  56. case SCH_MARKER_T:
  57. case SCH_NO_CONNECT_T:
  58. Struct->SetParent( Screen );
  59. break;
  60. case SCH_SHEET_PIN_T:
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& rotationPoint )
  67. {
  68. for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
  69. {
  70. SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
  71. item->Rotate( rotationPoint ); // Place it in its new position.
  72. item->ClearFlags();
  73. }
  74. }
  75. void MirrorY( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint )
  76. {
  77. for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
  78. {
  79. SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
  80. item->MirrorY( aMirrorPoint.x ); // Place it in its new position.
  81. item->ClearFlags();
  82. }
  83. }
  84. void MirrorX( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint )
  85. {
  86. for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
  87. {
  88. SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
  89. item->MirrorX( aMirrorPoint.y ); // Place it in its new position.
  90. item->ClearFlags();
  91. }
  92. }
  93. /**
  94. * Function MoveItemsInList
  95. * Move a list of items to a given move vector
  96. * @param aItemsList = list of picked items
  97. * @param aMoveVector = the move vector value
  98. */
  99. void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector )
  100. {
  101. for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
  102. {
  103. SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
  104. item->Move( aMoveVector );
  105. }
  106. }
  107. /**
  108. * Function DeleteItemsInList
  109. * delete schematic items in aItemsList
  110. * deleted items are put in undo list
  111. */
  112. void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList )
  113. {
  114. SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen();
  115. SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) panel->GetParent();
  116. PICKED_ITEMS_LIST itemsList;
  117. for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
  118. {
  119. SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
  120. ITEM_PICKER itemWrapper( item, UR_DELETED );
  121. if( item->Type() == SCH_SHEET_PIN_T )
  122. {
  123. /* this item is depending on a sheet, and is not in global list */
  124. wxMessageBox( wxT( "DeleteItemsInList() err: unexpected SCH_SHEET_PIN_T" ) );
  125. }
  126. else
  127. {
  128. screen->Remove( item );
  129. /* Unlink the structure */
  130. itemsList.PushItem( itemWrapper );
  131. }
  132. }
  133. frame->SaveCopyInUndoList( itemsList, UR_DELETED );
  134. }
  135. void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem )
  136. {
  137. wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) );
  138. // Here, aItem is not null.
  139. SCH_SCREEN* screen = GetScreen();
  140. if( aItem->Type() == SCH_SHEET_PIN_T )
  141. {
  142. // This iten is attached to a node, and is not accessible by the global list directly.
  143. SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent();
  144. wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
  145. wxT( "Sheet label has invalid parent item." ) );
  146. SaveCopyInUndoList( (SCH_ITEM*) sheet, UR_CHANGED );
  147. sheet->RemovePin( (SCH_SHEET_PIN*) aItem );
  148. m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() );
  149. }
  150. else
  151. {
  152. screen->Remove( aItem );
  153. SaveCopyInUndoList( aItem, UR_DELETED );
  154. m_canvas->RefreshDrawingRect( aItem->GetBoundingBox() );
  155. }
  156. }
  157. /* Routine to copy a new entity of an object for each object in list and
  158. * reposition it.
  159. * Return the new created object list in aItemsList
  160. */
  161. void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList,
  162. const wxPoint aMoveVector )
  163. {
  164. SCH_ITEM* newitem;
  165. if( aItemsList.GetCount() == 0 )
  166. return;
  167. for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
  168. {
  169. newitem = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
  170. aItemsList.SetPickedItem( newitem, ii );
  171. aItemsList.SetPickedItemStatus( UR_NEW, ii );
  172. {
  173. switch( newitem->Type() )
  174. {
  175. case SCH_JUNCTION_T:
  176. case SCH_LINE_T:
  177. case SCH_BUS_BUS_ENTRY_T:
  178. case SCH_BUS_WIRE_ENTRY_T:
  179. case SCH_TEXT_T:
  180. case SCH_LABEL_T:
  181. case SCH_GLOBAL_LABEL_T:
  182. case SCH_HIERARCHICAL_LABEL_T:
  183. case SCH_SHEET_PIN_T:
  184. case SCH_MARKER_T:
  185. case SCH_NO_CONNECT_T:
  186. default:
  187. break;
  188. case SCH_SHEET_T:
  189. {
  190. SCH_SHEET* sheet = (SCH_SHEET*) newitem;
  191. sheet->SetTimeStamp( GetNewTimeStamp() );
  192. break;
  193. }
  194. case SCH_COMPONENT_T:
  195. ( (SCH_COMPONENT*) newitem )->SetTimeStamp( GetNewTimeStamp() );
  196. ( (SCH_COMPONENT*) newitem )->ClearAnnotation( NULL );
  197. break;
  198. }
  199. SetSchItemParent( newitem, screen );
  200. screen->Append( newitem );
  201. }
  202. }
  203. MoveItemsInList( aItemsList, aMoveVector );
  204. }
  205. /**
  206. * Function DuplicateStruct
  207. * Routine to create a new copy of given struct.
  208. * The new object is not put in draw list (not linked)
  209. * @param aDrawStruct = the SCH_ITEM to duplicate
  210. * @param aClone (default = false)
  211. * if true duplicate also some parameters that must be unique
  212. * (timestamp and sheet name)
  213. * aClone must be false. use true only is undo/redo duplications
  214. */
  215. SCH_ITEM* DuplicateStruct( SCH_ITEM* aDrawStruct, bool aClone )
  216. {
  217. wxCHECK_MSG( aDrawStruct != NULL, NULL,
  218. wxT( "Cannot duplicate NULL schematic item! Bad programmer." ) );
  219. SCH_ITEM* NewDrawStruct = (SCH_ITEM*) aDrawStruct->Clone();
  220. if( aClone )
  221. NewDrawStruct->SetTimeStamp( aDrawStruct->GetTimeStamp() );
  222. return NewDrawStruct;
  223. }