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.

943 lines
34 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*************************************************/
  2. /* class_board.h - Class BOARD to handle a board */
  3. /*************************************************/
  4. #ifndef CLASS_BOARD_H
  5. #define CLASS_BOARD_H
  6. #include "dlist.h"
  7. #include "class_netinfo.h"
  8. #include "class_colors_design_settings.h"
  9. #include "class_board_design_settings.h"
  10. class ZONE_CONTAINER;
  11. /**
  12. * Enum LAYER_T
  13. * gives the allowed types of layers, same as Specctra DSN spec.
  14. */
  15. enum LAYER_T {
  16. LT_SIGNAL,
  17. LT_POWER,
  18. LT_MIXED,
  19. LT_JUMPER
  20. };
  21. /**
  22. * Struct LAYER
  23. * holds information pertinent to a layer of a BOARD.
  24. */
  25. struct LAYER
  26. {
  27. /** The name of the layer, there should be no spaces in this name. */
  28. wxString m_Name;
  29. /** The type of the layer */
  30. LAYER_T m_Type;
  31. // int m_Color;
  32. // bool m_Visible; // ? use flags in m_Color instead ?
  33. /**
  34. * Function ShowType
  35. * converts a LAYER_T enum to a const char*
  36. * @param aType The LAYER_T to convert
  37. * @return const char* - The string representation of the layer type.
  38. */
  39. static const char* ShowType( LAYER_T aType );
  40. /**
  41. * Function ParseType
  42. * converts a string to a LAYER_T
  43. * @param aType The const char* to convert
  44. * @return LAYER_T - The binary representation of the layer type, or
  45. * LAYER_T(-1) if the string is invalid
  46. */
  47. static LAYER_T ParseType( const char* aType );
  48. };
  49. /** a small helper class to handle a stock of specific vias diameter and drill pair
  50. * in the BOARD class
  51. */
  52. class VIA_DIMENSION
  53. {
  54. public:
  55. int m_Diameter; // <= 0 means use Netclass via diameter
  56. int m_Drill; // <= 0 means use Netclass via drill
  57. VIA_DIMENSION()
  58. {
  59. m_Diameter = 0; m_Drill = 0;
  60. }
  61. bool operator ==( const VIA_DIMENSION& other ) const
  62. {
  63. return (m_Diameter == other.m_Diameter)
  64. && (m_Drill == other.m_Drill);
  65. }
  66. bool operator <( const VIA_DIMENSION& other ) const
  67. {
  68. if( m_Diameter != other.m_Diameter )
  69. return m_Diameter < other.m_Diameter;
  70. return m_Drill < other.m_Drill;
  71. }
  72. };
  73. /**
  74. * Class BOARD
  75. * holds information pertinent to a PCBNEW printed circuit board.
  76. */
  77. #define HISTORY_MAX_COUNT 8
  78. class BOARD : public BOARD_ITEM
  79. {
  80. friend class WinEDA_PcbFrame;
  81. private:
  82. typedef std::vector<MARKER_PCB*> MARKERS; // @todo: switch to boost:ptr_vector, and change ~BOARD()
  83. MARKERS m_markers; ///< MARKER_PCBs for clearance problems, owned by pointer
  84. typedef std::vector<ZONE_CONTAINER*> ZONE_CONTAINERS; // @todo: switch to boost::ptr_vector, and change ~BOARD()
  85. ZONE_CONTAINERS m_ZoneDescriptorList; ///< edge zone descriptors, owned by pointer
  86. LAYER m_Layer[NB_COPPER_LAYERS];
  87. public:
  88. WinEDA_BasePcbFrame* m_PcbFrame; // Window of visualization
  89. EDA_Rect m_BoundaryBox; // Board size and position
  90. int m_Status_Pcb; // Flags used in ratsnet calculation and update
  91. int m_NbNodes; // Active pads (pads attached to a net ) count
  92. int m_NbNoconnect; // Active ratsnet count (rastnests not already connected by tracks)
  93. DLIST<BOARD_ITEM> m_Drawings; // linked list of lines & texts
  94. DLIST<MODULE> m_Modules; // linked list of MODULEs
  95. DLIST<TRACK> m_Track; // linked list of TRACKs and SEGVIAs
  96. DLIST<SEGZONE> m_Zone; // linked list of SEGZONEs
  97. NETINFO_LIST* m_NetInfo; // nets info list (name, design constraints ..
  98. std::vector<RATSNEST_ITEM> m_FullRatsnest; // Rastnest list for the BOARD
  99. std::vector<RATSNEST_ITEM> m_LocalRatsnest; /* Rastnest list relative to a given footprint
  100. * (used while moving a footprint) */
  101. ZONE_CONTAINER* m_CurrentZoneContour; // zone contour currently in progress
  102. NETCLASSES m_NetClasses; ///< List of current netclasses. There is always the default netclass
  103. wxString m_CurrentNetClassName; /* Current net class name used to display netclass info.
  104. * this is also the last used netclass after starting a track
  105. */
  106. // handling of vias and tracks size:
  107. // the first value is always the value of the current NetClass
  108. // The others values are extra values
  109. std::vector <VIA_DIMENSION> m_ViasDimensionsList; // vias size and drill list(max count = HISTORY_MAX_COUNT)
  110. // The first value is the current netclass via size
  111. std::vector <int> m_TrackWidthList; // tracks widths (max count = HISTORY_MAX_COUNT)
  112. // The first value is the current netclass track width
  113. unsigned m_ViaSizeSelector; // index for m_ViaSizeList to select the value
  114. // 0 is the index selection of the default value Netclass
  115. unsigned m_TrackWidthSelector; // index for m_TrackWidthList to select the value
  116. private:
  117. BOARD_DESIGN_SETTINGS* m_boardDesignSettings; // Link to current design settings
  118. COLORS_DESIGN_SETTINGS* m_colorsSettings; // Link to current colors settings
  119. /**********************************/
  120. public:
  121. BOARD( EDA_BaseStruct* aParent, WinEDA_BasePcbFrame* frame );
  122. ~BOARD();
  123. /**
  124. * Function GetDefaultLayerName
  125. * returns a default name of a PCB layer when given \a aLayerNumber. This
  126. * function is static so it can be called without a BOARD instance. Use
  127. * GetLayerName() if want the layer names of a specific BOARD, which could
  128. * be different than the default if the user has renamed any copper layers.
  129. *
  130. * @param aLayerNumber is the layer number to fetch
  131. * @return wxString - containing the layer name or "BAD INDEX" if aLayerNumber
  132. * is not legal
  133. */
  134. static wxString GetDefaultLayerName( int aLayerNumber );
  135. /**
  136. * Function GetPosition
  137. * is here to satisfy BOARD_ITEM's requirements, but this implementation
  138. * is a dummy.
  139. * @return const wxPoint& of (0,0)
  140. */
  141. wxPoint& GetPosition();
  142. /**
  143. * Function Add
  144. * adds the given item to this BOARD and takes ownership of its memory.
  145. * @param aBoardItem The item to add to this board.
  146. * @param aControl An int which can vary how the item is added.
  147. */
  148. void Add( BOARD_ITEM* aBoardItem, int aControl = 0 );
  149. #define ADD_APPEND 1 ///< aControl flag for Add( aControl ), appends not inserts
  150. /**
  151. * Function Delete
  152. * removes the given single item from this BOARD and deletes its memory.
  153. * @param aBoardItem The item to remove from this board and delete
  154. */
  155. void Delete( BOARD_ITEM* aBoardItem )
  156. {
  157. wxASSERT( aBoardItem ); // developers should run DEBUG versions and fix such calls with NULL
  158. if( aBoardItem )
  159. delete Remove( aBoardItem );
  160. }
  161. /**
  162. * Function Remove
  163. * removes \a aBoardItem from this BOARD and returns it to caller without
  164. * deleting it.
  165. * @param aBoardItem The item to remove from this board.
  166. * @return BOARD_ITEM* \a aBoardItem which was passed in.
  167. */
  168. BOARD_ITEM* Remove( BOARD_ITEM* aBoardItem );
  169. /**
  170. * Function DeleteMARKERs
  171. * deletes ALL MARKERS from the board.
  172. */
  173. void DeleteMARKERs();
  174. /**
  175. * Function DeleteZONEOutlines
  176. * deletes ALL zone outlines from the board.
  177. */
  178. void DeleteZONEOutlines();
  179. /**
  180. * Function GetMARKER
  181. * returns the MARKER at a given index.
  182. * @param index The array type index into a collection of MARKER_PCBS.
  183. * @return MARKER_PCB* - a pointer to the MARKER_PCB or NULL if index out of range.
  184. */
  185. MARKER_PCB* GetMARKER( int index ) const
  186. {
  187. if( (unsigned) index < m_markers.size() )
  188. return m_markers[index];
  189. return NULL;
  190. }
  191. /**
  192. * Function GetMARKERCount
  193. * @return int - The number of MARKER_PCBS.
  194. */
  195. int GetMARKERCount() const
  196. {
  197. return (int) m_markers.size();
  198. }
  199. /**
  200. * Function GetCopperLayerCount
  201. * @return int - The number of copper layers in the BOARD.
  202. */
  203. int GetCopperLayerCount() const;
  204. void SetCopperLayerCount( int aCount );
  205. /**
  206. * Function GetEnabledLayers
  207. * is a proxy function that calls the correspondent function in m_BoardSettings
  208. * Returns a bit-mask of all the layers that are enabled
  209. * @return int - the enabled layers in bit-mapped form.
  210. */
  211. int GetEnabledLayers() const;
  212. /**
  213. * Function SetEnabledLayers
  214. * is a proxy function that calls the correspondent function in m_BoardSettings
  215. * Changes the bit-mask of enabled layers
  216. * @param aMask = The new bit-mask of enabled layers
  217. */
  218. void SetEnabledLayers( int aLayerMask );
  219. /**
  220. * Function IsLayerEnabled
  221. * is a proxy function that calls the correspondent function in m_BoardSettings
  222. * tests whether a given layer is enabled
  223. * @param aLayerIndex = The index of the layer to be tested
  224. * @return bool - true if the layer is visible.
  225. */
  226. bool IsLayerEnabled( int aLayer ) const
  227. {
  228. return GetBoardDesignSettings()->IsLayerEnabled( aLayer );
  229. }
  230. /**
  231. * Function IsLayerVisible
  232. * is a proxy function that calls the correspondent function in m_BoardSettings
  233. * tests whether a given layer is visible
  234. * @param aLayerIndex = The index of the layer to be tested
  235. * @return bool - true if the layer is visible.
  236. */
  237. bool IsLayerVisible( int aLayerIndex ) const
  238. {
  239. return GetBoardDesignSettings()->IsLayerVisible( aLayerIndex );
  240. }
  241. /**
  242. * Function GetVisibleLayers
  243. * is a proxy function that calls the correspondent function in m_BoardSettings
  244. * Returns a bit-mask of all the layers that are visible
  245. * @return int - the visible layers in bit-mapped form.
  246. */
  247. int GetVisibleLayers() const;
  248. /**
  249. * Function SetVisibleLayers
  250. * is a proxy function that calls the correspondent function in m_BoardSettings
  251. * changes the bit-mask of visible layers
  252. * @param aMask = The new bit-mask of visible layers
  253. */
  254. void SetVisibleLayers( int aLayerMask );
  255. // these 2 functions are not tidy at this time, since there are PCB_VISIBLEs that
  256. // are not stored in the bitmap.
  257. /**
  258. * Function GetVisibleElements
  259. * is a proxy function that calls the correspondent function in m_BoardSettings
  260. * returns a bit-mask of all the element categories that are visible
  261. * @return int - the visible element bitmap or-ed from enum PCB_VISIBLE
  262. * @see enum PCB_VISIBLE
  263. */
  264. int GetVisibleElements() const;
  265. /**
  266. * Function SetVisibleElements
  267. * is a proxy function that calls the correspondent function in m_BoardSettings
  268. * changes the bit-mask of visible element categories
  269. * @param aMask = The new bit-mask of visible element bitmap or-ed from enum PCB_VISIBLE
  270. * @see enum PCB_VISIBLE
  271. */
  272. void SetVisibleElements( int aMask );
  273. /**
  274. * Function SetVisibleAlls
  275. * changes the bit-mask of visible element categories and layers
  276. * @see enum PCB_VISIBLE
  277. */
  278. void SetVisibleAlls();
  279. /**
  280. * Function IsElementVisible
  281. * tests whether a given element category is visible. Keep this as an
  282. * inline function.
  283. * @param aPCB_VISIBLE is from the enum by the same name
  284. * @return bool - true if the element is visible.
  285. * @see enum PCB_VISIBLE
  286. */
  287. bool IsElementVisible( int aPCB_VISIBLE ) const;
  288. /**
  289. * Function SetElementVisibility
  290. * changes the visibility of an element category
  291. * @param aPCB_VISIBLE is from the enum by the same name
  292. * @param aNewState = The new visibility state of the element category
  293. * @see enum PCB_VISIBLE
  294. */
  295. void SetElementVisibility( int aPCB_VISIBLE, bool aNewState );
  296. /**
  297. * Function IsModuleLayerVisible
  298. * expects either of the two layers on which a module can reside, and returns
  299. * whether that layer is visible.
  300. * @param layer One of the two allowed layers for modules: LAYER_N_FRONT or LAYER_N_BACK
  301. * @return bool - true if the layer is visible, else false.
  302. */
  303. bool IsModuleLayerVisible( int layer );
  304. /**
  305. * Function GetVisibleElementColor
  306. * returns the color of a pcb visible element.
  307. * @see enum PCB_VISIBLE
  308. */
  309. int GetVisibleElementColor( int aPCB_VISIBLE );
  310. void SetVisibleElementColor( int aPCB_VISIBLE, int aColor );
  311. /** Function GetBoardDesignSettings
  312. * @return the current BOARD_DESIGN_SETTINGS in use
  313. */
  314. BOARD_DESIGN_SETTINGS* GetBoardDesignSettings() const
  315. {
  316. return m_boardDesignSettings;
  317. }
  318. /** Function SetBoardDesignSettings
  319. * @param aDesignSettings = the new BOARD_DESIGN_SETTINGS to use
  320. */
  321. void SetBoardDesignSettings( BOARD_DESIGN_SETTINGS* aDesignSettings)
  322. {
  323. m_boardDesignSettings = aDesignSettings;
  324. }
  325. /** Function SetBoardSettings
  326. * @return the current COLORS_DESIGN_SETTINGS in use
  327. */
  328. COLORS_DESIGN_SETTINGS* GetColorsSettings() const
  329. {
  330. return m_colorsSettings;
  331. }
  332. /** Function SetColorsSettings
  333. * @param aColorsSettings = the new COLORS_DESIGN_SETTINGS to use
  334. */
  335. void SetColorsSettings(COLORS_DESIGN_SETTINGS* aColorsSettings)
  336. {
  337. m_colorsSettings = aColorsSettings;
  338. }
  339. /**
  340. * Function GetLayerName
  341. * returns the name of the layer given by aLayerIndex.
  342. *
  343. * @param aLayerIndex A layer index, like LAYER_N_BACK, etc.
  344. * @return wxString - the layer name.
  345. */
  346. wxString GetLayerName( int aLayerIndex ) const;
  347. /**
  348. * Function SetLayerName
  349. * changes the name of the layer given by aLayerIndex.
  350. *
  351. * @param aLayerIndex A layer index, like LAYER_N_BACK, etc.
  352. * @param aLayerName The new layer name
  353. * @return bool - true if aLayerName was legal and unique amoung other
  354. * layer names at other layer indices and aLayerIndex was within range, else false.
  355. */
  356. bool SetLayerName( int aLayerIndex, const wxString& aLayerName );
  357. /**
  358. * Function GetLayerType
  359. * returns the type of the copper layer given by aLayerIndex.
  360. *
  361. * @param aLayerIndex A layer index, like LAYER_N_BACK, etc.
  362. * @return LAYER_T - the layer type, or LAYER_T(-1) if the
  363. * index was out of range.
  364. */
  365. LAYER_T GetLayerType( int aLayerIndex ) const;
  366. /**
  367. * Function SetLayerType
  368. * changes the type of the layer given by aLayerIndex.
  369. *
  370. * @param aLayerIndex A layer index, like LAYER_N_BACK, etc.
  371. * @param aLayerType The new layer type.
  372. * @return bool - true if aLayerType was legal and aLayerIndex was within range, else false.
  373. */
  374. bool SetLayerType( int aLayerIndex, LAYER_T aLayerType );
  375. /**
  376. * Function SetLayerColor
  377. * changes a layer color for any valid layer, including non-copper ones.
  378. */
  379. void SetLayerColor( int aLayer, int aColor );
  380. /**
  381. * Function GetLayerColor
  382. * gets a layer color for any valid layer, including non-copper ones.
  383. */
  384. int GetLayerColor( int aLayer );
  385. /* Functions to get some items count */
  386. int GetNumSegmTrack();
  387. int GetNumSegmZone();
  388. unsigned GetNoconnectCount(); // Return the number of missing links.
  389. /**
  390. * Function GetNumRatsnests
  391. * @return int - The number of rats
  392. */
  393. unsigned GetRatsnestsCount()
  394. {
  395. return m_FullRatsnest.size();
  396. }
  397. /** Function GetNodesCount
  398. * @return the number of pads members of nets (i.e. with netcode > 0)
  399. */
  400. unsigned GetNodesCount();
  401. /** Function GetPadsCount
  402. * @return the number of pads in board
  403. */
  404. unsigned GetPadsCount()
  405. {
  406. return m_NetInfo->GetPadsCount();
  407. }
  408. bool ComputeBoundaryBox();
  409. /**
  410. * Function DisplayInfo
  411. * has knowledge about the frame and how and where to put status information
  412. * about this object into the frame's message panel.
  413. * Is virtual from EDA_BaseStruct.
  414. * @param frame A WinEDA_DrawFrame in which to print status information.
  415. */
  416. void DisplayInfo( WinEDA_DrawFrame* frame );
  417. void Draw( WinEDA_DrawPanel* panel, wxDC* DC,
  418. int aDrawMode, const wxPoint& offset = ZeroOffset );
  419. /**
  420. * Function DrawHighLight
  421. * redraws the objects in the board that are associated with the given aNetCode
  422. * and turns on or off the brilliance associated with that net according to the
  423. * current value of global g_HighLight_Status
  424. * @param aDrawPanel is needed for the clipping support.
  425. * @param aNetCode is the net number to highlight or to dim.
  426. */
  427. void DrawHighLight( WinEDA_DrawPanel* aDrawPanel, wxDC* DC, int aNetCode );
  428. /**
  429. * Function Visit
  430. * may be re-implemented for each derived class in order to handle
  431. * all the types given by its member data. Implementations should call
  432. * inspector->Inspect() on types in scanTypes[], and may use IterateForward()
  433. * to do so on lists of such data.
  434. * @param inspector An INSPECTOR instance to use in the inspection.
  435. * @param testData Arbitrary data used by the inspector.
  436. * @param scanTypes Which KICAD_T types are of interest and the order
  437. * is significant too, terminated by EOT.
  438. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
  439. * else SCAN_CONTINUE, and determined by the inspector.
  440. */
  441. SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData,
  442. const KICAD_T scanTypes[] );
  443. /**
  444. * Function FindNet
  445. * searches for a net with the given netcode.
  446. * @param aNetcode A netcode to search for.
  447. * @return NETINFO_ITEM_ITEM* - the net or NULL if not found.
  448. */
  449. NETINFO_ITEM* FindNet( int aNetcode ) const;
  450. /**
  451. * Function FindNet overlayed
  452. * searches for a net with the given name.
  453. * @param aNetname A Netname to search for.
  454. * @return NETINFO_ITEM* - the net or NULL if not found.
  455. */
  456. NETINFO_ITEM* FindNet( const wxString& aNetname ) const;
  457. /**
  458. * Function FindModuleByReference
  459. * searches for a MODULE within this board with the given
  460. * reference designator. Finds only the first one, if there
  461. * is more than one such MODULE.
  462. * @param aReference The reference designator of the MODULE to find.
  463. * @return MODULE* - If found, the MODULE having the given reference
  464. * designator, else NULL.
  465. */
  466. MODULE* FindModuleByReference( const wxString& aReference ) const;
  467. /**
  468. * Function ReturnSortedNetnamesList
  469. * @param aNames An array string to fill with net names.
  470. * @param aSortbyPadsCount : true = sort by active pads count, false = no sort (i.e. leave the sort by net names)
  471. * @return int - net names count.
  472. */
  473. int ReturnSortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCount );
  474. /**************************************/
  475. /** function relative to NetClasses: **/
  476. /**************************************/
  477. /**
  478. * Function SynchronizeNetsAndNetClasses
  479. * copies NETCLASS info to each NET, based on NET membership in a NETCLASS.
  480. * Must be called after a Design Rules edition, or after reading a netlist (or editing the list of nets)
  481. * Also this function removes the non existing nets in netclasses and add net nets in default netclass
  482. * (this happens after reading a netlist)
  483. * @param none
  484. * @return none
  485. */
  486. void SynchronizeNetsAndNetClasses();
  487. /**
  488. * Function SetCurrentNetClass
  489. * Must be called after a netclass selection (or after a netclass parameter change
  490. * Initialise vias and tracks values displayed in comb boxes of the auxiliary toolbar
  491. * and some others parameters (netclass name ....)
  492. * @param aNetClassName = the new netclass name
  493. * @return true if lists of tracks and vias sizes are modified
  494. */
  495. bool SetCurrentNetClass( const wxString& aNetClassName );
  496. /** function GetBiggestClearanceValue
  497. * @return the biggest clearance value found in NetClasses list
  498. */
  499. int GetBiggestClearanceValue();
  500. /** function GetCurrentTrackWidth
  501. * @return the current track width, according to the selected options
  502. * ( using the default netclass value or a preset value )
  503. * the default netclass is always in m_TrackWidthList[0]
  504. */
  505. int GetCurrentTrackWidth()
  506. {
  507. return m_TrackWidthList[m_TrackWidthSelector];
  508. }
  509. /** function GetCurrentViaSize
  510. * @return the current via size, according to the selected options
  511. * ( using the default netclass value or a preset value )
  512. * the default netclass is always in m_TrackWidthList[0]
  513. */
  514. int GetCurrentViaSize()
  515. {
  516. return m_ViasDimensionsList[m_ViaSizeSelector].m_Diameter;
  517. }
  518. /** function GetCurrentViaDrill
  519. * @return the current via size, according to the selected options
  520. * ( using the default netclass value or a preset value )
  521. * the default netclass is always in m_TrackWidthList[0]
  522. */
  523. int GetCurrentViaDrill()
  524. {
  525. return m_ViasDimensionsList[m_ViaSizeSelector].m_Drill > 0 ?
  526. m_ViasDimensionsList[m_ViaSizeSelector].m_Drill : -1;
  527. }
  528. /** function GetCurrentMicroViaSize
  529. * @return the current micro via size,
  530. * that is the current netclass value
  531. */
  532. int GetCurrentMicroViaSize();
  533. /** function GetCurrentMicroViaDrill
  534. * @return the current micro via drill,
  535. * that is the current netclass value
  536. */
  537. int GetCurrentMicroViaDrill();
  538. /***************************************************************************/
  539. /**
  540. * Function Save
  541. * writes the data structures for this object out to a FILE in "*.brd" format.
  542. * @param aFile The FILE to write to.
  543. * @return bool - true if success writing else false.
  544. */
  545. bool Save( FILE* aFile ) const;
  546. /**
  547. * Function GetClass
  548. * returns the class name.
  549. * @return wxString
  550. */
  551. wxString GetClass() const
  552. {
  553. return wxT( "BOARD" );
  554. }
  555. #if defined(DEBUG)
  556. /**
  557. * Function Show
  558. * is used to output the object tree, currently for debugging only.
  559. * @param nestLevel An aid to prettier tree indenting, and is the level
  560. * of nesting of this object within the overall tree.
  561. * @param os The ostream& to output to.
  562. */
  563. void Show( int nestLevel, std::ostream& os );
  564. #endif
  565. /*************************/
  566. /* Copper Areas handling */
  567. /*************************/
  568. /**
  569. * Function HitTestForAnyFilledArea
  570. * tests if the given wxPoint is within the bounds of a filled area of this zone.
  571. * the test is made on zones on layer from aStartLayer to aEndLayer
  572. * Note: if a zone has its flag BUSY (in .m_State) is set, it is ignored.
  573. * @param refPos A wxPoint to test
  574. * @param aStartLayer the first layer to test
  575. * @param aEndLayer the last layer (-1 to ignore it) to test
  576. * @return ZONE_CONTAINER* return a pointer to the ZONE_CONTAINER found, else NULL
  577. */
  578. ZONE_CONTAINER* HitTestForAnyFilledArea( const wxPoint& aRefPos,
  579. int aStartLayer,
  580. int aEndLayer = -1 );
  581. /**
  582. * Function RedrawAreasOutlines
  583. * Redraw all areas outlines on layer aLayer ( redraw all if aLayer < 0 )
  584. */
  585. void RedrawAreasOutlines( WinEDA_DrawPanel* panel,
  586. wxDC* aDC,
  587. int aDrawMode,
  588. int aLayer );
  589. /**
  590. * Function RedrawFilledAreas
  591. * Redraw all filled areas on layer aLayer ( redraw all if aLayer < 0 )
  592. */
  593. void RedrawFilledAreas( WinEDA_DrawPanel* panel,
  594. wxDC* aDC,
  595. int aDrawMode,
  596. int aLayer );
  597. /**
  598. * Function SetAreasNetCodesFromNetNames
  599. * Set the .m_NetCode member of all copper areas, according to the area Net Name
  600. * The SetNetCodesFromNetNames is an equivalent to net name, for fast comparisons.
  601. * However the Netcode is an arbitrary equivalence, it must be set after each netlist read
  602. * or net change
  603. * Must be called after pad netcodes are calculated
  604. * @return : error count
  605. * For non copper areas, netcode is set to 0
  606. */
  607. int SetAreasNetCodesFromNetNames( void );
  608. /**
  609. * Function GetArea
  610. * returns the Area (Zone Container) at a given index.
  611. * @param index The array type index into a collection of ZONE_CONTAINER *.
  612. * @return ZONE_CONTAINER* - a pointer to the Area or NULL if index out of range.
  613. */
  614. ZONE_CONTAINER* GetArea( int index ) const
  615. {
  616. if( (unsigned) index < m_ZoneDescriptorList.size() )
  617. return m_ZoneDescriptorList[index];
  618. return NULL;
  619. }
  620. /**
  621. * Function GetAreaIndex
  622. * returns the Area Index for the given Zone Container.
  623. * @param aArea :The ZONE_CONTAINER to find.
  624. * @return an Area Index in m_ZoneDescriptorList or -1 if non found.
  625. */
  626. int GetAreaIndex( const ZONE_CONTAINER* aArea ) const
  627. {
  628. for( int ii = 0; ii < GetAreaCount(); ii++ ) // Search for aArea in list
  629. {
  630. if( aArea == GetArea( ii ) ) // Found !
  631. return ii;
  632. }
  633. return -1;
  634. }
  635. /**
  636. * Function GetAreaCount
  637. * @return int - The number of Areas or ZONE_CONTAINER.
  638. */
  639. int GetAreaCount() const
  640. {
  641. return (int) m_ZoneDescriptorList.size();
  642. }
  643. /* Functions used in test, merge and cut outlines */
  644. /** Function AddArea
  645. * Add an empty copper area to board areas list
  646. * @param aNewZonesList = a PICKED_ITEMS_LIST * where to store new areas pickers (useful in undo commands)
  647. * can be NULL
  648. * @param aNetcode = the necode of the copper area (0 = no net)
  649. * @param aLayer = the layer of area
  650. * @param aStartPointPosition = position of the first point of the polygon outline of this area
  651. * @param aHatch = hacth option
  652. * @return pointer to the new area
  653. */
  654. ZONE_CONTAINER* AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode,
  655. int aLayer, wxPoint aStartPointPosition, int aHatch );
  656. /**
  657. * Function InsertArea
  658. * add empty copper area to net, inserting after m_ZoneDescriptorList[iarea]
  659. * @return pointer to the new area
  660. */
  661. ZONE_CONTAINER* InsertArea( int netcode, int iarea, int layer, int x, int y, int hatch );
  662. /**
  663. * Function CompleteArea
  664. * complete copper area contour by adding a line from last to first corner
  665. * if there is only 1 or 2 corners, remove (delete) the area
  666. * @param area_to_complete = area to complete or remove
  667. * @param style = style of last corner
  668. * @return 1 if Ok, 0 if area removed
  669. */
  670. int CompleteArea( ZONE_CONTAINER* area_to_complete, int style );
  671. /**
  672. * Function TestAreaPolygon
  673. * Test an area for self-intersection.
  674. *
  675. * @param CurrArea = copper area to test
  676. * @return :
  677. * -1 if arcs intersect other sides
  678. * 0 if no intersecting sides
  679. * 1 if intersecting sides, but no intersecting arcs
  680. * Also sets utility2 flag of area with return value
  681. */
  682. int TestAreaPolygon( ZONE_CONTAINER* CurrArea );
  683. /**
  684. * Function ClipAreaPolygon
  685. * Process an area that has been modified, by clipping its polygon against itself.
  686. * This may change the number and order of copper areas in the net.
  687. * @param aNewZonesList = a PICKED_ITEMS_LIST * where to store new areas pickers (useful in undo commands)
  688. * can be NULL
  689. * @param aCurrArea = the zone to process
  690. * @param bMessageBoxInt == true, shows message when clipping occurs.
  691. * @param bMessageBoxArc == true, shows message when clipping can't be done due to arcs.
  692. * @param bRetainArcs = true to handle arcs (not really used in kicad)
  693. * @return :
  694. * -1 if arcs intersect other sides, so polygon can't be clipped
  695. * 0 if no intersecting sides
  696. * 1 if intersecting sides
  697. * Also sets areas->utility1 flags if areas are modified
  698. */
  699. int ClipAreaPolygon( PICKED_ITEMS_LIST* aNewZonesList,
  700. ZONE_CONTAINER* aCurrArea,
  701. bool bMessageBoxArc,
  702. bool bMessageBoxInt,
  703. bool bRetainArcs = TRUE );
  704. /**
  705. * Process an area that has been modified, by clipping its polygon against
  706. * itself and the polygons for any other areas on the same net.
  707. * This may change the number and order of copper areas in the net.
  708. * @param aModifiedZonesList = a PICKED_ITEMS_LIST * where to store deleted or added areas
  709. * (useful in undo commands. Can be NULL
  710. * @param modified_area = area to test
  711. * @param bMessageBox : if TRUE, shows message boxes when clipping occurs.
  712. * @return :
  713. * -1 if arcs intersect other sides, so polygon can't be clipped
  714. * 0 if no intersecting sides
  715. * 1 if intersecting sides, polygon clipped
  716. */
  717. int AreaPolygonModified( PICKED_ITEMS_LIST* aModifiedZonesList,
  718. ZONE_CONTAINER* modified_area,
  719. bool bMessageBoxArc,
  720. bool bMessageBoxInt );
  721. /**
  722. * Function CombineAllAreasInNet
  723. * Checks all copper areas in net for intersections, combining them if found
  724. * @param aDeletedList = a PICKED_ITEMS_LIST * where to store deleted areas (useful in undo commands
  725. * can be NULL
  726. * @param aNetCode = net to consider
  727. * @param bMessageBox : if true display warning message box
  728. * @param bUseUtility : if true, don't check areas if both utility flags are 0
  729. * Sets utility flag = 1 for any areas modified
  730. * If an area has self-intersecting arcs, doesn't try to combine it
  731. */
  732. int CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList,
  733. int aNetCode,
  734. bool bMessageBox,
  735. bool bUseUtility );
  736. /** Function RemoveArea
  737. * remove copper area from net, and put it in a deleted list (if exists)
  738. * @param aDeletedList = a PICKED_ITEMS_LIST * where to store deleted areas (useful in undo commands
  739. * can be NULL
  740. * @param area_to_remove = area to delete or put in deleted list
  741. */
  742. void RemoveArea( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_to_remove );
  743. /**
  744. * Function TestAreaIntersections
  745. * Check for intersection of a given copper area with other areas in same net
  746. * @param area_to_test = area to compare to all other areas in the same net
  747. */
  748. bool TestAreaIntersections( ZONE_CONTAINER* area_to_test );
  749. /**
  750. * Function TestAreaIntersection
  751. * Test for intersection of 2 copper areas
  752. * area_to_test must be after area_ref in m_ZoneDescriptorList
  753. * @param area_ref = area reference
  754. * @param area_to_test = area to compare for intersection calculations
  755. * @return : 0 if no intersection
  756. * 1 if intersection
  757. * 2 if arcs intersect
  758. */
  759. int TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_to_test );
  760. /**
  761. * Function CombineAreas
  762. * If possible, combine 2 copper areas
  763. * @param aDeletedList = a PICKED_ITEMS_LIST * where to store deleted areas (useful in undo commands
  764. * can be NULL
  765. * @param area_ref = the main area (zone)
  766. * @param area_to_combine = the zone that can be merged with area_ref
  767. * area_ref must be BEFORE area_to_combine
  768. * area_to_combine will be deleted, if areas are combined
  769. * @return : 0 if no intersection
  770. * 1 if intersection
  771. * 2 if arcs intersect
  772. */
  773. int CombineAreas( PICKED_ITEMS_LIST* aDeletedList,
  774. ZONE_CONTAINER* area_ref,
  775. ZONE_CONTAINER* area_to_combine );
  776. /**
  777. * Function Test_Drc_Areas_Outlines_To_Areas_Outlines
  778. * Test Areas outlines for DRC:
  779. * Test areas inside other areas
  780. * Test areas too close
  781. * @param aArea_To_Examine: area to compare with other areas. if NULL: all areas are compared to all others
  782. * @param aCreate_Markers: if true create DRC markers. False: do not creates anything
  783. * @return errors count
  784. */
  785. int Test_Drc_Areas_Outlines_To_Areas_Outlines( ZONE_CONTAINER* aArea_To_Examine,
  786. bool aCreate_Markers );
  787. /****** function relative to ratsnest calculations: */
  788. /**
  789. * Function Test_Connection_To_Copper_Areas
  790. * init .m_ZoneSubnet parameter in tracks and pads according to the connections to areas found
  791. * @param aNetcode = netcode to analyze. if -1, analyze all nets
  792. */
  793. void Test_Connections_To_Copper_Areas( int aNetcode = -1 );
  794. };
  795. #endif // #ifndef CLASS_BOARD_H