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.

210 lines
7.3 KiB

12 years ago
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 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 <tool/tool_interactive.h>
  27. namespace KIGFX
  28. {
  29. class VIEW;
  30. class VIEW_CONTROLS;
  31. }
  32. class BOARD;
  33. class PCB_EDIT_FRAME;
  34. class DRAWSEGMENT;
  35. /**
  36. * Class DRAWING_TOOL
  37. *
  38. * Tool responsible for drawing graphical elements like lines, arcs, circles, etc.
  39. */
  40. class DRAWING_TOOL : public TOOL_INTERACTIVE
  41. {
  42. public:
  43. DRAWING_TOOL();
  44. ~DRAWING_TOOL();
  45. /// @copydoc TOOL_INTERACTIVE::Reset()
  46. void Reset( RESET_REASON aReason );
  47. /**
  48. * Function DrawLine()
  49. * Starts interactively drawing a line. After invoking the function it expects the user
  50. * to click at least two times to determine the origin and the end for a line. If there are
  51. * more clicks, the line is drawn as a continous polyline.
  52. */
  53. int DrawLine( TOOL_EVENT& aEvent );
  54. /**
  55. * Function DrawCircle()
  56. * Starts interactively drawing a circle. After invoking the function it expects the user
  57. * to first click on a point that is going to be used as the center of the circle. The second
  58. * click determines the circle radius.
  59. */
  60. int DrawCircle( TOOL_EVENT& aEvent );
  61. /**
  62. * Function DrawArc()
  63. * Starts interactively drawing an arc. After invoking the function it expects the user
  64. * to first click on a point that is going to be used as the center of the arc. The second
  65. * click determines the origin and radius, the third one - the angle.
  66. */
  67. int DrawArc( TOOL_EVENT& aEvent );
  68. /**
  69. * Function PlaceText()
  70. * Displays a dialog that allows to input text and its settings and then lets the user decide
  71. * where to place the text in editor.
  72. */
  73. int PlaceText( TOOL_EVENT& aEvent );
  74. /**
  75. * Function DrawDimension()
  76. * Starts interactively drawing a dimension. After invoking the function it expects the user
  77. * to first click on a point that is going to be used as the origin of the dimension.
  78. * The second click determines the end and the third click modifies its height.
  79. */
  80. int DrawDimension( TOOL_EVENT& aEvent );
  81. /**
  82. * Function DrawZone()
  83. * Starts interactively drawing a zone. After invoking the function a zone settings dialog
  84. * is displayed. After confirmation it allows the user to set points that are going to be used
  85. * as a boundary polygon of the zone. Double click or clicking on the origin of the boundary
  86. * polyline finishes the drawing.
  87. */
  88. int DrawZone( TOOL_EVENT& aEvent );
  89. /**
  90. * Function DrawKeepout()
  91. * Starts interactively drawing a keepout area. After invoking the function an area settings
  92. * dialog is displayed. After confirmation it allows the user to set points that are going to
  93. * be used as a boundary polygon of the area. Double click or clicking on the origin of the
  94. * boundary polyline finishes the drawing.
  95. */
  96. int DrawKeepout( TOOL_EVENT& aEvent );
  97. /**
  98. * Function PlaceTarget()
  99. * Allows user to place a layer alignment target.
  100. */
  101. int PlaceTarget( TOOL_EVENT& aEvent );
  102. /**
  103. * Function PlaceModule()
  104. * Displays a dialog to select a module to be added and allows the user to set its position.
  105. */
  106. int PlaceModule( TOOL_EVENT& aEvent );
  107. /**
  108. * Function PlacePad()
  109. * Places a pad in the module editor.
  110. */
  111. int PlacePad( TOOL_EVENT& aEvent );
  112. /**
  113. * Function SetAnchor()
  114. * Places the footprint anchor (only in module editor).
  115. */
  116. int SetAnchor( TOOL_EVENT& aEvent );
  117. /**
  118. * Function EditModules()
  119. * Toggles edit module mode. When enabled, one may select parts of modules individually
  120. * (graphics, pads, etc.), so they can be modified.
  121. * @param aEnabled decides if the mode should be enabled.
  122. */
  123. void EditModules( bool aEnabled )
  124. {
  125. m_editModules = aEnabled;
  126. }
  127. private:
  128. ///> Starts drawing a selected shape (i.e. DRAWSEGMENT).
  129. ///> @param aShape is the type of created shape (@see STROKE_T).
  130. ///> @param aGraphic is an object that is going to be used by the tool for drawing. It has to
  131. ///> be already created. The tool deletes the object if it is not added to a BOARD.
  132. ///> @return False if the tool was cancelled before the origin was set or origin and end are
  133. ///> the same point.
  134. bool drawSegment( int aShape, DRAWSEGMENT* aGraphic );
  135. ///> Starts drawing an arc.
  136. ///> @param aGraphic is an object that is going to be used by the tool for drawing. It has to
  137. ///> be already created. The tool deletes the object if it is not added to a BOARD.
  138. ///> @return False if the tool was cancelled before the origin was set or origin and end are
  139. ///> the same point.
  140. bool drawArc( DRAWSEGMENT* aGraphic );
  141. ///> Draws a polygon, that is added as a zone or a keepout area.
  142. ///> @param aKeepout decides if the drawn polygon is a zone or a keepout area.
  143. int drawZone( bool aKeepout );
  144. /**
  145. * Function placeTextModule()
  146. * Displays a dialog that allows to input text and its settings and then lets the user decide
  147. * where to place the text in module .
  148. */
  149. int placeTextModule();
  150. /**
  151. * Function placeTextPcb()
  152. * Displays a dialog that allows to input text and its settings and then lets the user decide
  153. * where to place the text in board editor.
  154. */
  155. int placeTextPcb();
  156. /**
  157. * Function make45DegLine()
  158. * Forces a DRAWSEGMENT to be drawn at multiple of 45 degrees. The origin stays the same,
  159. * the end of the aSegment is modified according to the current cursor position.
  160. * @param aSegment is the segment that is currently drawn.
  161. * @param aHelper is a helper line that shows the next possible segment.
  162. */
  163. void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const;
  164. /**
  165. * Function getNextPadName()
  166. * Compute the 'next' pad number for autoincrement.
  167. * */
  168. wxString getNextPadName() const;
  169. ///> Sets up handlers for various events.
  170. void setTransitions();
  171. KIGFX::VIEW* m_view;
  172. KIGFX::VIEW_CONTROLS* m_controls;
  173. BOARD* m_board;
  174. PCB_EDIT_FRAME* m_frame;
  175. /// Edit module mode flag
  176. bool m_editModules;
  177. // How does line width change after one -/+ key press.
  178. static const int WIDTH_STEP = 100000;
  179. };
  180. #endif /* __DRAWING_TOOL_H */