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.

323 lines
9.0 KiB

16 years ago
16 years ago
  1. /***********************************/
  2. /* Edit segments and edges of PCB. */
  3. /***********************************/
  4. #include "fctsys.h"
  5. #include "common.h"
  6. #include "class_drawpanel.h"
  7. #include "confirm.h"
  8. #include "pcbnew.h"
  9. #include "wxPcbStruct.h"
  10. #include "class_board_design_settings.h"
  11. #include "protos.h"
  12. static void Exit_EditEdge( WinEDA_DrawPanel* Panel, wxDC* DC );
  13. static void Montre_Position_NewSegment( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
  14. static void Move_Segment( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
  15. static wxPoint s_InitialPosition; // Initial cursor position.
  16. static wxPoint s_LastPosition; // Current cursor position.
  17. /* Start move of a graphic element type DRAWSEGMENT */
  18. void WinEDA_PcbFrame::Start_Move_DrawItem( DRAWSEGMENT* drawitem, wxDC* DC )
  19. {
  20. if( drawitem == NULL )
  21. return;
  22. drawitem->Draw( DrawPanel, DC, GR_XOR );
  23. drawitem->m_Flags |= IS_MOVED;
  24. s_InitialPosition = s_LastPosition = GetScreen()->m_Curseur;
  25. drawitem->DisplayInfo( this );
  26. DrawPanel->ManageCurseur = Move_Segment;
  27. DrawPanel->ForceCloseManageCurseur = Exit_EditEdge;
  28. SetCurItem( drawitem );
  29. DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
  30. }
  31. /*
  32. * Place graphic element of type DRAWSEGMENT.
  33. */
  34. void WinEDA_PcbFrame::Place_DrawItem( DRAWSEGMENT* drawitem, wxDC* DC )
  35. {
  36. if( drawitem == NULL )
  37. return;
  38. SaveCopyInUndoList(drawitem, UR_MOVED, s_LastPosition - s_InitialPosition);
  39. drawitem->Draw( DrawPanel, DC, GR_OR );
  40. DrawPanel->ManageCurseur = NULL;
  41. DrawPanel->ForceCloseManageCurseur = NULL;
  42. SetCurItem( NULL );
  43. OnModify();
  44. drawitem->m_Flags = 0;
  45. }
  46. /*
  47. * Redraw segment during cursor movement.
  48. */
  49. static void Move_Segment( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
  50. {
  51. DRAWSEGMENT* Segment = (DRAWSEGMENT*) panel->GetScreen()->GetCurItem();
  52. int t_fill = DisplayOpt.DisplayDrawItems;
  53. if( Segment == NULL )
  54. return;
  55. DisplayOpt.DisplayDrawItems = SKETCH;
  56. if( erase )
  57. Segment->Draw( panel, DC, GR_XOR );
  58. wxPoint delta;
  59. delta = panel->GetScreen()->m_Curseur - s_LastPosition;
  60. Segment->m_Start += delta;
  61. Segment->m_End += delta;
  62. s_LastPosition = panel->GetScreen()->m_Curseur;
  63. Segment->Draw( panel, DC, GR_XOR );
  64. DisplayOpt.DisplayDrawItems = t_fill;
  65. }
  66. void WinEDA_PcbFrame::Delete_Segment_Edge( DRAWSEGMENT* Segment, wxDC* DC )
  67. {
  68. EDA_BaseStruct* PtStruct;
  69. int track_fill_copy = DisplayOpt.DisplayDrawItems;
  70. if( Segment == NULL )
  71. return;
  72. if( Segment->m_Flags & IS_NEW ) // Trace in progress.
  73. {
  74. /* Delete current segment. */
  75. DisplayOpt.DisplayDrawItems = SKETCH;
  76. Segment->Draw( DrawPanel, DC, GR_XOR );
  77. PtStruct = Segment->Back();
  78. Segment ->DeleteStructure();
  79. if( PtStruct && (PtStruct->Type() == TYPE_DRAWSEGMENT ) )
  80. Segment = (DRAWSEGMENT*) PtStruct;
  81. DisplayOpt.DisplayDrawItems = track_fill_copy;
  82. SetCurItem( NULL );
  83. }
  84. else if( Segment->m_Flags == 0 )
  85. {
  86. Segment->Draw( DrawPanel, DC, GR_XOR );
  87. Segment->m_Flags = 0;
  88. SaveCopyInUndoList(Segment, UR_DELETED);
  89. Segment->UnLink();
  90. SetCurItem( NULL );
  91. OnModify();
  92. }
  93. }
  94. void WinEDA_PcbFrame::Delete_Drawings_All_Layer( int aLayer )
  95. {
  96. if( aLayer <= LAST_COPPER_LAYER )
  97. {
  98. DisplayError( this, _( "Copper layer global delete not allowed!" ) );
  99. return;
  100. }
  101. wxString msg = _( "Delete Layer " ) + GetBoard()->GetLayerName( aLayer );
  102. if( !IsOK( this, msg ) )
  103. return;
  104. PICKED_ITEMS_LIST pickList;
  105. ITEM_PICKER picker(NULL, UR_DELETED);
  106. BOARD_ITEM* PtNext;
  107. for( BOARD_ITEM* item = GetBoard()->m_Drawings; item; item = PtNext )
  108. {
  109. PtNext = item->Next();
  110. switch( item->Type() )
  111. {
  112. case TYPE_DRAWSEGMENT:
  113. case TYPE_TEXTE:
  114. case TYPE_DIMENSION:
  115. case TYPE_MIRE:
  116. if( item->GetLayer() == aLayer )
  117. {
  118. item->UnLink();
  119. picker.m_PickedItem = item;
  120. pickList.PushItem( picker );
  121. }
  122. break;
  123. default:
  124. {
  125. wxString msg;
  126. msg.Printf( wxT("Delete_Drawings_All_Layer() error: unknown type %d"),
  127. item->Type() );
  128. wxMessageBox( msg );
  129. break;
  130. }
  131. }
  132. }
  133. if( pickList.GetCount() )
  134. {
  135. OnModify();
  136. SaveCopyInUndoList(pickList, UR_DELETED);
  137. }
  138. }
  139. static void Exit_EditEdge( WinEDA_DrawPanel* Panel, wxDC* DC )
  140. {
  141. DRAWSEGMENT* Segment = (DRAWSEGMENT*) Panel->GetScreen()->GetCurItem();
  142. if( Segment == NULL )
  143. return;
  144. if( Segment->m_Flags & IS_NEW )
  145. {
  146. Panel->ManageCurseur( Panel, DC, FALSE );
  147. Segment ->DeleteStructure();
  148. Segment = NULL;
  149. }
  150. else
  151. {
  152. wxPoint pos = Panel->GetScreen()->m_Curseur;
  153. Panel->GetScreen()->m_Curseur = s_InitialPosition;
  154. Panel->ManageCurseur( Panel, DC, TRUE );
  155. Panel->GetScreen()->m_Curseur = pos;
  156. Segment->m_Flags = 0;
  157. Segment->Draw( Panel, DC, GR_OR );
  158. }
  159. Panel->ManageCurseur = NULL;
  160. Panel->ForceCloseManageCurseur = NULL;
  161. ( (WinEDA_PcbFrame*) Panel->GetParent() )->SetCurItem( NULL );
  162. }
  163. /* Initialize the drawing of a segment of type other than trace.
  164. */
  165. DRAWSEGMENT* WinEDA_PcbFrame::Begin_DrawSegment( DRAWSEGMENT* Segment,
  166. int shape, wxDC* DC )
  167. {
  168. int s_large;
  169. int angle = 0;
  170. DRAWSEGMENT* DrawItem;
  171. s_large = GetBoard()->GetBoardDesignSettings()->m_DrawSegmentWidth;
  172. if( getActiveLayer() == EDGE_N )
  173. {
  174. s_large = GetBoard()->GetBoardDesignSettings()->m_EdgeSegmentWidth;
  175. }
  176. if( shape == S_ARC )
  177. angle = 900;
  178. if( Segment == NULL ) /* Create new trace. */
  179. {
  180. SetCurItem( Segment = new DRAWSEGMENT( GetBoard() ) );
  181. Segment->m_Flags = IS_NEW;
  182. Segment->SetLayer( getActiveLayer() );
  183. Segment->m_Width = s_large;
  184. Segment->m_Shape = shape;
  185. Segment->m_Angle = 900;
  186. Segment->m_Start = Segment->m_End = GetScreen()->m_Curseur;
  187. DrawPanel->ManageCurseur = Montre_Position_NewSegment;
  188. DrawPanel->ForceCloseManageCurseur = Exit_EditEdge;
  189. }
  190. else /* The ending point ccordinate Segment->m_End was updated by he function
  191. * Montre_Position_NewSegment() called on a move mouse event
  192. * during the segment creation
  193. */
  194. {
  195. if( Segment->m_Start != Segment->m_End )
  196. {
  197. if( Segment->m_Shape == S_SEGMENT )
  198. {
  199. SaveCopyInUndoList(Segment, UR_NEW );
  200. GetBoard()->Add( Segment );
  201. OnModify();
  202. Segment->m_Flags = 0;
  203. Segment->Draw( DrawPanel, DC, GR_OR );
  204. DrawItem = Segment;
  205. SetCurItem( Segment = new DRAWSEGMENT( GetBoard() ) );
  206. Segment->m_Flags = IS_NEW;
  207. Segment->SetLayer( DrawItem->GetLayer() );
  208. Segment->m_Width = s_large;
  209. Segment->m_Shape = DrawItem->m_Shape;
  210. Segment->m_Type = DrawItem->m_Type;
  211. Segment->m_Angle = DrawItem->m_Angle;
  212. Segment->m_Start = Segment->m_End = DrawItem->m_End;
  213. Montre_Position_NewSegment( DrawPanel, DC, FALSE );
  214. }
  215. else
  216. {
  217. End_Edge( Segment, DC );
  218. Segment = NULL;
  219. }
  220. }
  221. }
  222. return Segment;
  223. }
  224. void WinEDA_PcbFrame::End_Edge( DRAWSEGMENT* Segment, wxDC* DC )
  225. {
  226. if( Segment == NULL )
  227. return;
  228. Segment->Draw( DrawPanel, DC, GR_OR );
  229. /* Delete if segment length is zero. */
  230. if( Segment->m_Start == Segment->m_End )
  231. Segment ->DeleteStructure();
  232. else
  233. {
  234. Segment->m_Flags = 0;
  235. GetBoard()->Add( Segment );
  236. OnModify();
  237. SaveCopyInUndoList( Segment, UR_NEW );
  238. }
  239. DrawPanel->ManageCurseur = NULL;
  240. DrawPanel->ForceCloseManageCurseur = NULL;
  241. SetCurItem( NULL );
  242. }
  243. /* Redraw segment during cursor movement
  244. */
  245. static void Montre_Position_NewSegment( WinEDA_DrawPanel* panel,
  246. wxDC* DC, bool erase )
  247. {
  248. DRAWSEGMENT* Segment = (DRAWSEGMENT*)
  249. panel->GetScreen()->GetCurItem();
  250. int t_fill = DisplayOpt.DisplayDrawItems;
  251. if( Segment == NULL )
  252. return;
  253. DisplayOpt.DisplayDrawItems = SKETCH;
  254. if( erase )
  255. Segment->Draw( panel, DC, GR_XOR );
  256. if( Segments_45_Only && ( Segment->m_Shape == S_SEGMENT ) )
  257. {
  258. Calcule_Coord_Extremite_45( Segment->m_Start.x, Segment->m_Start.y,
  259. &Segment->m_End.x, &Segment->m_End.y );
  260. }
  261. else /* here the angle is arbitrary */
  262. {
  263. Segment->m_End = panel->GetScreen()->m_Curseur;
  264. }
  265. Segment->Draw( panel, DC, GR_XOR );
  266. DisplayOpt.DisplayDrawItems = t_fill;
  267. }