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.

358 lines
9.1 KiB

  1. /*********************************************/
  2. /******* file initpcb.cpp ********************/
  3. /*********************************************/
  4. #include "fctsys.h"
  5. #include "common.h"
  6. #include "pcbnew.h"
  7. #include "autorout.h"
  8. #include "protos.h"
  9. /**************************************/
  10. /* dialog WinEDA_PcbGlobalDeleteFrame */
  11. /**************************************/
  12. #include "dialog_initpcb.cpp"
  13. /********************************************************************/
  14. void WinEDA_PcbFrame::InstallPcbGlobalDeleteFrame( const wxPoint& pos )
  15. /********************************************************************/
  16. {
  17. WinEDA_PcbGlobalDeleteFrame* frame =
  18. new WinEDA_PcbGlobalDeleteFrame( this );
  19. frame->ShowModal(); frame->Destroy();
  20. }
  21. /***********************************************************************/
  22. void WinEDA_PcbGlobalDeleteFrame::AcceptPcbDelete( wxCommandEvent& event )
  23. /***********************************************************************/
  24. {
  25. int track_mask;
  26. bool redraw = FALSE;
  27. wxClientDC dc( m_Parent->DrawPanel );
  28. m_Parent->DrawPanel->PrepareGraphicContext( &dc );
  29. if( m_DelAlls->GetValue() )
  30. {
  31. m_Parent->Clear_Pcb( TRUE );
  32. redraw = TRUE;
  33. }
  34. else
  35. {
  36. if( m_DelZones->GetValue() )
  37. {
  38. m_Parent->Erase_Zones( TRUE );
  39. redraw = TRUE;
  40. }
  41. if( m_DelTexts->GetValue() )
  42. {
  43. m_Parent->Erase_Textes_Pcb( TRUE );
  44. redraw = TRUE;
  45. }
  46. if( m_DelEdges->GetValue() )
  47. {
  48. m_Parent->Erase_Segments_Pcb( TRUE, TRUE );
  49. redraw = TRUE;
  50. }
  51. if( m_DelDrawings->GetValue() )
  52. {
  53. m_Parent->Erase_Segments_Pcb( FALSE, TRUE );
  54. redraw = TRUE;
  55. }
  56. if( m_DelModules->GetValue() )
  57. {
  58. m_Parent->Erase_Modules( TRUE );
  59. redraw = TRUE;
  60. }
  61. if( m_DelTracks->GetValue() )
  62. {
  63. {
  64. track_mask = 0;
  65. if( !m_TrackFilterLocked->GetValue() )
  66. track_mask |= SEGM_FIXE;
  67. if( !m_TrackFilterAR->GetValue() )
  68. track_mask |= SEGM_AR;
  69. m_Parent->Erase_Pistes( &dc, track_mask, TRUE );
  70. redraw = TRUE;
  71. }
  72. }
  73. if( m_DelMarkers->GetValue() )
  74. {
  75. m_Parent->Erase_Marqueurs();
  76. redraw = TRUE;
  77. }
  78. }
  79. if( redraw )
  80. {
  81. m_Parent->SetCurItem( NULL );
  82. m_Parent->ReDrawPanel();
  83. }
  84. EndModal( 1 );
  85. }
  86. /*********************************************************/
  87. bool WinEDA_BasePcbFrame::Clear_Pcb( bool query )
  88. /*********************************************************/
  89. /* Realise les init des pointeurs et variables
  90. * Si query == FALSE, il n'y aura pas de confirmation
  91. */
  92. {
  93. if( m_Pcb == NULL )
  94. return FALSE;
  95. if( query && GetScreen()->IsModify() )
  96. {
  97. if( m_Pcb->m_Drawings ||m_Pcb->m_Modules
  98. || m_Pcb->m_Track || m_Pcb->m_Zone )
  99. {
  100. if( !IsOK( this, _( "Current Board will be lost ?" ) ) )
  101. return FALSE;
  102. }
  103. }
  104. /* Suppression des listes chainees */
  105. m_Pcb->m_Equipots->DeleteStructList();
  106. m_Pcb->m_Equipots = NULL;
  107. m_Pcb->m_Drawings->DeleteStructList();
  108. m_Pcb->m_Drawings = NULL;
  109. m_Pcb->m_Modules->DeleteStructList();
  110. m_Pcb->m_Modules = NULL;
  111. m_Pcb->m_Track->DeleteStructList();
  112. m_Pcb->m_Track = NULL;
  113. m_Pcb->m_NbSegmTrack = 0;
  114. m_Pcb->m_Zone->DeleteStructList();
  115. m_Pcb->m_Zone = NULL;
  116. m_Pcb->m_NbSegmZone = 0;
  117. DelLimitesZone( NULL, FALSE );
  118. m_Pcb->DeleteMARKERs();
  119. m_Pcb->DeleteZONEOutlines();
  120. for( ; g_UnDeleteStackPtr != 0; )
  121. {
  122. g_UnDeleteStackPtr--;
  123. g_UnDeleteStack[g_UnDeleteStackPtr]->DeleteStructList();
  124. }
  125. /* init pointeurs et variables */
  126. GetScreen()->m_FileName.Empty();
  127. memset( buf_work, 0, BUFMEMSIZE );
  128. adr_lowmem = adr_max = buf_work;
  129. if( m_Pcb->m_Pads )
  130. {
  131. MyFree( m_Pcb->m_Pads );
  132. m_Pcb->m_Pads = NULL;
  133. }
  134. if( m_Pcb->m_Ratsnest )
  135. MyFree( m_Pcb->m_Ratsnest );
  136. if( m_Pcb->m_LocalRatsnest )
  137. MyFree( m_Pcb->m_LocalRatsnest );
  138. m_Pcb->m_Ratsnest = NULL;
  139. m_Pcb->m_LocalRatsnest = NULL;
  140. /* remise a 0 ou a une valeur initiale des variables de la structure */
  141. m_Pcb->m_BoundaryBox.SetOrigin( wxPoint( 0, 0 ) );
  142. m_Pcb->m_BoundaryBox.SetSize( wxSize( 0, 0 ) );
  143. m_Pcb->m_Status_Pcb = 0;
  144. m_Pcb->m_NbLoclinks = 0;
  145. m_Pcb->m_NbLinks = 0;
  146. m_Pcb->m_NbPads = 0;
  147. m_Pcb->m_NbNets = 0;
  148. m_Pcb->m_NbNodes = 0;
  149. m_Pcb->m_NbNoconnect = 0;
  150. m_Pcb->m_NbSegmTrack = 0;
  151. m_Pcb->m_NbSegmZone = 0;
  152. SetCurItem( NULL );
  153. /* Init parametres de gestion */
  154. GetScreen()->Init();
  155. g_HightLigt_Status = 0;
  156. for( int ii = 1; ii < HIST0RY_NUMBER; ii++ )
  157. {
  158. g_DesignSettings.m_ViaSizeHistory[ii] =
  159. g_DesignSettings.m_TrackWidhtHistory[ii] = 0;
  160. }
  161. g_DesignSettings.m_TrackWidhtHistory[0] = g_DesignSettings.m_CurrentTrackWidth;
  162. g_DesignSettings.m_ViaSizeHistory[0] = g_DesignSettings.m_CurrentViaSize;
  163. Zoom_Automatique( TRUE );
  164. DrawPanel->Refresh( TRUE );
  165. return TRUE;
  166. }
  167. /************************************************************/
  168. void WinEDA_PcbFrame::Erase_Zones( bool query )
  169. /************************************************************/
  170. {
  171. if( query && !IsOK( this, _( "Delete Zones ?" ) ) )
  172. return;
  173. if( m_Pcb->m_Zone )
  174. {
  175. m_Pcb->m_Zone->DeleteStructList();
  176. m_Pcb->m_Zone = NULL;
  177. m_Pcb->m_NbSegmZone = 0;
  178. }
  179. DelLimitesZone( NULL, FALSE );
  180. m_Pcb->DeleteZONEOutlines();
  181. GetScreen()->SetModify();
  182. }
  183. /*****************************************************************************/
  184. void WinEDA_PcbFrame::Erase_Segments_Pcb( bool is_edges, bool query )
  185. /*****************************************************************************/
  186. {
  187. BOARD_ITEM* PtStruct;
  188. BOARD_ITEM* PtNext;
  189. int masque_layer = (~EDGE_LAYER) & 0x1FFF0000;
  190. if( is_edges )
  191. {
  192. masque_layer = EDGE_LAYER;
  193. if( query && !IsOK( this, _( "Delete Board edges ?" ) ) )
  194. return;
  195. }
  196. else
  197. {
  198. if( query && !IsOK( this, _( "Delete draw items?" ) ) )
  199. return;
  200. }
  201. PtStruct = m_Pcb->m_Drawings;
  202. for( ; PtStruct != NULL; PtStruct = PtNext )
  203. {
  204. PtNext = PtStruct->Next();
  205. switch( PtStruct->Type() )
  206. {
  207. case TYPEDRAWSEGMENT:
  208. case TYPETEXTE:
  209. case TYPECOTATION:
  210. case TYPEMIRE:
  211. if( g_TabOneLayerMask[ PtStruct->GetLayer()] & masque_layer )
  212. PtStruct->DeleteStructure();
  213. break;
  214. default:
  215. DisplayError( this, wxT( "Unknown/unexpected Draw Type" ) );
  216. break;
  217. }
  218. }
  219. GetScreen()->SetModify();
  220. }
  221. /**************************************************************************/
  222. void WinEDA_PcbFrame::Erase_Pistes( wxDC * DC, int masque_type, bool query )
  223. /**************************************************************************/
  224. /* Efface les segments de piste, selon les autorisations affichees
  225. * masque_type = masque des options de selection:
  226. * SEGM_FIXE, SEGM_AR
  227. * Si un des bits est a 1, il n'y a pas effacement du segment de meme bit a 1
  228. */
  229. {
  230. TRACK* pt_segm;
  231. TRACK* PtNext;
  232. if( query && !IsOK( this, _( "Delete Tracks?" ) ) )
  233. return;
  234. /* Marquage des pistes a effacer */
  235. for( pt_segm = m_Pcb->m_Track; pt_segm != NULL; pt_segm = (TRACK*) PtNext )
  236. {
  237. PtNext = (TRACK*) pt_segm->Pnext;
  238. if( pt_segm->GetState( SEGM_FIXE | SEGM_AR ) & masque_type )
  239. continue;
  240. pt_segm->DeleteStructure();
  241. }
  242. GetScreen()->SetModify();
  243. Compile_Ratsnest( DC, TRUE );
  244. }
  245. /**************************************************************/
  246. void WinEDA_PcbFrame::Erase_Modules( bool query )
  247. /**************************************************************/
  248. {
  249. if( query && !IsOK( this, _( "Delete Modules?" ) ) )
  250. return;
  251. m_Pcb->m_Modules->DeleteStructList();
  252. m_Pcb->m_Modules = 0;
  253. m_Pcb->m_Status_Pcb = 0;
  254. m_Pcb->m_NbNets = 0;
  255. m_Pcb->m_NbPads = 0;
  256. m_Pcb->m_NbNodes = 0;
  257. m_Pcb->m_NbLinks = 0;
  258. m_Pcb->m_NbNoconnect = 0;
  259. GetScreen()->SetModify();
  260. }
  261. /************************************************************/
  262. void WinEDA_PcbFrame::Erase_Textes_Pcb( bool query )
  263. /************************************************************/
  264. {
  265. BOARD_ITEM* PtStruct, * PtNext;
  266. if( query && !IsOK( this, _( "Delete Pcb Texts" ) ) )
  267. return;
  268. PtStruct = m_Pcb->m_Drawings;
  269. for( ; PtStruct != NULL; PtStruct = PtNext )
  270. {
  271. PtNext = PtStruct->Next();
  272. if( PtStruct->Type() == TYPETEXTE )
  273. PtStruct ->DeleteStructure();
  274. }
  275. GetScreen()->SetModify();
  276. }
  277. /*******************************************/
  278. void WinEDA_PcbFrame::Erase_Marqueurs()
  279. /*******************************************/
  280. {
  281. m_Pcb->DeleteMARKERs();
  282. GetScreen()->SetModify(); // @todo : why mark this if MARKERs are not saved in the *.brd file?
  283. }