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.

239 lines
8.3 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014-2017 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  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. #ifndef __DRAWING_TOOL_H
  25. #define __DRAWING_TOOL_H
  26. #include <core/optional.h>
  27. #include <tool/tool_menu.h>
  28. #include <tools/pcb_tool_base.h>
  29. #include <tools/pcb_actions.h>
  30. namespace KIGFX
  31. {
  32. class VIEW;
  33. class VIEW_CONTROLS;
  34. }
  35. class BOARD;
  36. class PCB_BASE_EDIT_FRAME;
  37. class DRAWSEGMENT;
  38. class POLYGON_GEOM_MANAGER;
  39. /**
  40. * Class DRAWING_TOOL
  41. *
  42. * Tool responsible for drawing graphical elements like lines, arcs, circles, etc.
  43. */
  44. class DRAWING_TOOL : public PCB_TOOL_BASE
  45. {
  46. public:
  47. DRAWING_TOOL();
  48. ~DRAWING_TOOL();
  49. /// @copydoc TOOL_INTERACTIVE::Init()
  50. bool Init() override;
  51. /// @copydoc TOOL_INTERACTIVE::Reset()
  52. void Reset( RESET_REASON aReason ) override;
  53. ///> The possible drawing modes of DRAWING_TOOL
  54. enum class MODE
  55. {
  56. NONE,
  57. LINE,
  58. CIRCLE,
  59. ARC,
  60. TEXT,
  61. ANCHOR,
  62. DXF,
  63. DIMENSION,
  64. KEEPOUT,
  65. ZONE,
  66. GRAPHIC_POLYGON,
  67. VIA
  68. };
  69. /**
  70. * Function GetDrawingMode
  71. *
  72. * Returns the current drawing mode of the DRAWING_TOOL, or
  73. * MODE::NONE if not currently in any drawing mode
  74. */
  75. MODE GetDrawingMode() const;
  76. /**
  77. * Function DrawLine()
  78. * Starts interactively drawing a line. After invoking the function it expects the user
  79. * to click at least two times to determine the origin and the end for a line. If there are
  80. * more clicks, the line is drawn as a continous polyline.
  81. */
  82. int DrawLine( const TOOL_EVENT& aEvent );
  83. /**
  84. * Function DrawCircle()
  85. * Starts interactively drawing a circle. After invoking the function it expects the user
  86. * to first click on a point that is going to be used as the center of the circle. The second
  87. * click determines the circle radius.
  88. */
  89. int DrawCircle( const TOOL_EVENT& aEvent );
  90. /**
  91. * Function DrawArc()
  92. * Starts interactively drawing an arc. After invoking the function it expects the user
  93. * to first click on a point that is going to be used as the center of the arc. The second
  94. * click determines the origin and radius, the third one - the angle.
  95. */
  96. int DrawArc( const TOOL_EVENT& aEvent );
  97. /**
  98. * Function PlaceText()
  99. * Displays a dialog that allows one to input text and its settings and then
  100. * lets the user decide where to place the text in editor.
  101. */
  102. int PlaceText( const TOOL_EVENT& aEvent );
  103. /**
  104. * Function DrawDimension()
  105. * Starts interactively drawing a dimension. After invoking the function it expects the user
  106. * to first click on a point that is going to be used as the origin of the dimension.
  107. * The second click determines the end and the third click modifies its height.
  108. */
  109. int DrawDimension( const TOOL_EVENT& aEvent );
  110. /**
  111. * Function DrawZone()
  112. * Starts interactively drawing a zone. After invoking the function a zone settings dialog
  113. * is displayed. After confirmation it allows the user to set points that are going to be used
  114. * as a boundary polygon of the zone. Double click or clicking on the origin of the boundary
  115. * polyline finishes the drawing.
  116. *
  117. * The event parameter indicates which type of zone to draw:
  118. * ADD add a new zone/keepout with fresh settings
  119. * CUTOUT add a cutout to an existing zone
  120. * SIMILAR add a new zone with the same settings as an existing one
  121. */
  122. int DrawZone( const TOOL_EVENT& aEvent );
  123. int DrawVia( const TOOL_EVENT& aEvent );
  124. /**
  125. * Function PlaceImportedGraphics()
  126. * Places a drawing imported from a DXF or SVG file in module editor.
  127. */
  128. int PlaceImportedGraphics( const TOOL_EVENT& aEvent );
  129. /**
  130. * Function SetAnchor()
  131. * Places the footprint anchor (only in module editor).
  132. */
  133. int SetAnchor( const TOOL_EVENT& aEvent );
  134. ///> Sets up handlers for various events.
  135. void setTransitions() override;
  136. private:
  137. ///> Starts drawing a selected shape (i.e. DRAWSEGMENT).
  138. ///> @param aShape is the type of created shape (@see STROKE_T).
  139. ///> @param aGraphic is an object that is going to be used by the tool for drawing. It has to
  140. ///> be already created. The tool deletes the object if it is not added to a BOARD.
  141. ///> @param aStartingPoint is a starting point for this new DRAWSEGMENT. If exists
  142. ///> the new item has its start point set to aStartingPoint,
  143. ///> and its settings (width, layer) set to the current default values.
  144. ///> @return False if the tool was cancelled before the origin was set or origin and end are
  145. ///> the same point.
  146. bool drawSegment( int aShape, DRAWSEGMENT*& aGraphic, OPT<VECTOR2D> aStartingPoint );
  147. ///> Starts drawing an arc.
  148. ///> @param aGraphic is an object that is going to be used by the tool for drawing. It has to
  149. ///> be already created. The tool deletes the object if it is not added to a BOARD.
  150. ///> @return False if the tool was cancelled before the origin was set or origin and end are
  151. ///> the same point.
  152. bool drawArc( DRAWSEGMENT*& aGraphic, bool aImmediateMode );
  153. /**
  154. * Draws a polygon, that is added as a zone or a keepout area.
  155. *
  156. * @param aKeepout dictates if the drawn polygon is a zone or a
  157. * keepout area.
  158. * @param aMode dictates the mode of the zone tool:
  159. * ADD add a new zone/keepout with fresh settings
  160. * CUTOUT add a cutout to an existing zone
  161. * SIMILAR add a new zone with the same settings as an existing one
  162. */
  163. /**
  164. * Function getSourceZoneForAction()
  165. *
  166. * Gets a source zone item for an action that takes an existing zone
  167. * into account (for example a cutout of an existing zone). The source
  168. * zone is taken from the current selection
  169. *
  170. * @param aMode mode of the zone tool
  171. * @param aZone updated pointer to a suitable source zone,
  172. * or nullptr if none found, or the action doesn't need a source
  173. * @return true if a suitable zone was found, or the action doesn't
  174. * need a zone. False if the action needs a zone but none was found.
  175. */
  176. bool getSourceZoneForAction( ZONE_MODE aMode, ZONE_CONTAINER*& aZone );
  177. /**
  178. * Run the event loop for polygon creation, sending user input
  179. * on to the given POLYGON_GEOM_MANAGER for processing into a
  180. * complete polygon.
  181. */
  182. void runPolygonEventLoop( POLYGON_GEOM_MANAGER& aPolyGeomMgr );
  183. /**
  184. * Function constrainDimension()
  185. * Forces the dimension lime to be drawn on multiple of 45 degrees
  186. * @param aDimension is the dimension element currently being drawn
  187. */
  188. void constrainDimension( DIMENSION* dimension );
  189. ///> Returns the appropriate width for a segment depending on the settings.
  190. int getSegmentWidth( PCB_LAYER_ID aLayer ) const;
  191. ///> Selects a non-copper layer for drawing
  192. PCB_LAYER_ID getDrawingLayer() const;
  193. KIGFX::VIEW* m_view;
  194. KIGFX::VIEW_CONTROLS* m_controls;
  195. BOARD* m_board;
  196. PCB_BASE_EDIT_FRAME* m_frame;
  197. MODE m_mode;
  198. /// Stores the current line width for multisegment drawing.
  199. unsigned int m_lineWidth;
  200. // How does line width change after one -/+ key press.
  201. static const unsigned int WIDTH_STEP;
  202. // give internal access to drawing helper classes
  203. friend class ZONE_CREATE_HELPER;
  204. };
  205. #endif /* __DRAWING_TOOL_H */