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.

356 lines
9.3 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
  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. /**
  25. * @file lib_circle.cpp
  26. * @brief LIB_CIRCLE class implementation.
  27. */
  28. #include <fctsys.h>
  29. #include <gr_basic.h>
  30. #include <macros.h>
  31. #include <class_drawpanel.h>
  32. #include <plot_common.h>
  33. #include <trigo.h>
  34. #include <wxstruct.h>
  35. #include <richio.h>
  36. #include <base_units.h>
  37. #include <msgpanel.h>
  38. #include <general.h>
  39. #include <lib_circle.h>
  40. #include <transform.h>
  41. LIB_CIRCLE::LIB_CIRCLE( LIB_PART* aParent ) :
  42. LIB_ITEM( LIB_CIRCLE_T, aParent )
  43. {
  44. m_Radius = 0;
  45. m_Width = 0;
  46. m_Fill = NO_FILL;
  47. m_isFillable = true;
  48. m_typeName = _( "Circle" );
  49. }
  50. bool LIB_CIRCLE::Save( OUTPUTFORMATTER& aFormatter )
  51. {
  52. aFormatter.Print( 0, "C %d %d %d %d %d %d %c\n", m_Pos.x, m_Pos.y,
  53. m_Radius, m_Unit, m_Convert, m_Width, fill_tab[m_Fill] );
  54. return true;
  55. }
  56. bool LIB_CIRCLE::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
  57. {
  58. char tmp[256];
  59. char* line = (char*) aLineReader;
  60. int cnt = sscanf( line + 2, "%d %d %d %d %d %d %255s", &m_Pos.x, &m_Pos.y,
  61. &m_Radius, &m_Unit, &m_Convert, &m_Width, tmp );
  62. if( cnt < 6 )
  63. {
  64. aErrorMsg.Printf( _( "Circle only had %d parameters of the required 6" ), cnt );
  65. return false;
  66. }
  67. if( tmp[0] == 'F' )
  68. m_Fill = FILLED_SHAPE;
  69. if( tmp[0] == 'f' )
  70. m_Fill = FILLED_WITH_BG_BODYCOLOR;
  71. return true;
  72. }
  73. bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef ) const
  74. {
  75. int mindist = GetPenSize() / 2;
  76. // Have a minimal tolerance for hit test
  77. if( mindist < MINIMUM_SELECTION_DISTANCE )
  78. mindist = MINIMUM_SELECTION_DISTANCE;
  79. return HitTest( aPosRef, mindist, DefaultTransform );
  80. }
  81. bool LIB_CIRCLE::HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const
  82. {
  83. if( aThreshold < 0 )
  84. aThreshold = GetPenSize() / 2;
  85. int dist = KiROUND( GetLineLength( aPosRef, aTransform.TransformCoordinate( m_Pos ) ) );
  86. if( abs( dist - m_Radius ) <= aThreshold )
  87. return true;
  88. return false;
  89. }
  90. EDA_ITEM* LIB_CIRCLE::Clone() const
  91. {
  92. return new LIB_CIRCLE( *this );
  93. }
  94. int LIB_CIRCLE::compare( const LIB_ITEM& aOther ) const
  95. {
  96. wxASSERT( aOther.Type() == LIB_CIRCLE_T );
  97. const LIB_CIRCLE* tmp = ( LIB_CIRCLE* ) &aOther;
  98. if( m_Pos.x != tmp->m_Pos.x )
  99. return m_Pos.x - tmp->m_Pos.x;
  100. if( m_Pos.y != tmp->m_Pos.y )
  101. return m_Pos.y - tmp->m_Pos.y;
  102. if( m_Radius != tmp->m_Radius )
  103. return m_Radius - tmp->m_Radius;
  104. return 0;
  105. }
  106. void LIB_CIRCLE::SetOffset( const wxPoint& aOffset )
  107. {
  108. m_Pos += aOffset;
  109. }
  110. bool LIB_CIRCLE::Inside( EDA_RECT& aRect ) const
  111. {
  112. /*
  113. * FIXME: This fails to take into account the radius around the center
  114. * point.
  115. */
  116. return aRect.Contains( m_Pos.x, -m_Pos.y );
  117. }
  118. void LIB_CIRCLE::Move( const wxPoint& aPosition )
  119. {
  120. m_Pos = aPosition;
  121. }
  122. void LIB_CIRCLE::MirrorHorizontal( const wxPoint& aCenter )
  123. {
  124. m_Pos.x -= aCenter.x;
  125. m_Pos.x *= -1;
  126. m_Pos.x += aCenter.x;
  127. }
  128. void LIB_CIRCLE::MirrorVertical( const wxPoint& aCenter )
  129. {
  130. m_Pos.y -= aCenter.y;
  131. m_Pos.y *= -1;
  132. m_Pos.y += aCenter.y;
  133. }
  134. void LIB_CIRCLE::Rotate( const wxPoint& aCenter, bool aRotateCCW )
  135. {
  136. int rot_angle = aRotateCCW ? -900 : 900;
  137. RotatePoint( &m_Pos, aCenter, rot_angle );
  138. }
  139. void LIB_CIRCLE::Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
  140. const TRANSFORM& aTransform )
  141. {
  142. wxPoint pos = aTransform.TransformCoordinate( m_Pos ) + aOffset;
  143. if( aFill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
  144. {
  145. aPlotter->SetColor( GetLayerColor( LAYER_DEVICE_BACKGROUND ) );
  146. aPlotter->Circle( pos, m_Radius * 2, FILLED_SHAPE, 0 );
  147. }
  148. bool already_filled = m_Fill == FILLED_WITH_BG_BODYCOLOR;
  149. aPlotter->SetColor( GetLayerColor( LAYER_DEVICE ) );
  150. aPlotter->Circle( pos, m_Radius * 2, already_filled ? NO_FILL : m_Fill, GetPenSize() );
  151. }
  152. int LIB_CIRCLE::GetPenSize() const
  153. {
  154. return ( m_Width == 0 ) ? GetDefaultLineThickness() : m_Width;
  155. }
  156. void LIB_CIRCLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  157. EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, void* aData,
  158. const TRANSFORM& aTransform )
  159. {
  160. wxPoint pos1;
  161. EDA_COLOR_T color = GetLayerColor( LAYER_DEVICE );
  162. if( aColor < 0 ) // Used normal color or selected color
  163. {
  164. if( IsSelected() )
  165. color = GetItemSelectedColor();
  166. }
  167. else
  168. {
  169. color = aColor;
  170. }
  171. pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
  172. GRSetDrawMode( aDC, aDrawMode );
  173. FILL_T fill = aData ? NO_FILL : m_Fill;
  174. if( aColor >= 0 )
  175. fill = NO_FILL;
  176. EDA_RECT* const clipbox = aPanel? aPanel->GetClipBox() : NULL;
  177. if( fill == FILLED_WITH_BG_BODYCOLOR )
  178. GRFilledCircle( clipbox, aDC, pos1.x, pos1.y, m_Radius, GetPenSize(),
  179. (m_Flags & IS_MOVED) ? color : GetLayerColor( LAYER_DEVICE_BACKGROUND ),
  180. GetLayerColor( LAYER_DEVICE_BACKGROUND ) );
  181. else if( fill == FILLED_SHAPE )
  182. GRFilledCircle( clipbox, aDC, pos1.x, pos1.y, m_Radius, 0, color, color );
  183. else
  184. GRCircle( clipbox, aDC, pos1.x, pos1.y, m_Radius, GetPenSize(), color );
  185. /* Set to one (1) to draw bounding box around circle to validate bounding
  186. * box calculation. */
  187. #if 0
  188. EDA_RECT bBox = GetBoundingBox();
  189. bBox.RevertYAxis();
  190. bBox = aTransform.TransformCoordinate( bBox );
  191. bBox.Move( aOffset );
  192. GRRect( clipbox, aDC, bBox, 0, LIGHTMAGENTA );
  193. #endif
  194. }
  195. const EDA_RECT LIB_CIRCLE::GetBoundingBox() const
  196. {
  197. EDA_RECT rect;
  198. rect.SetOrigin( m_Pos.x - m_Radius, m_Pos.y - m_Radius );
  199. rect.SetEnd( m_Pos.x + m_Radius, m_Pos.y + m_Radius );
  200. rect.Inflate( ( GetPenSize()+1 ) / 2 );
  201. rect.RevertYAxis();
  202. return rect;
  203. }
  204. void LIB_CIRCLE::GetMsgPanelInfo( MSG_PANEL_ITEMS& aList )
  205. {
  206. wxString msg;
  207. EDA_RECT bBox = GetBoundingBox();
  208. LIB_ITEM::GetMsgPanelInfo( aList );
  209. msg = StringFromValue( g_UserUnit, m_Width, true );
  210. aList.push_back( MSG_PANEL_ITEM( _( "Line Width" ), msg, BLUE ) );
  211. msg = StringFromValue( g_UserUnit, m_Radius, true );
  212. aList.push_back( MSG_PANEL_ITEM( _( "Radius" ), msg, RED ) );
  213. msg.Printf( wxT( "(%d, %d, %d, %d)" ), bBox.GetOrigin().x,
  214. bBox.GetOrigin().y, bBox.GetEnd().x, bBox.GetEnd().y );
  215. aList.push_back( MSG_PANEL_ITEM( _( "Bounding Box" ), msg, BROWN ) );
  216. }
  217. wxString LIB_CIRCLE::GetSelectMenuText() const
  218. {
  219. return wxString::Format( _( "Circle center (%s, %s), radius %s" ),
  220. GetChars( CoordinateToString( m_Pos.x ) ),
  221. GetChars( CoordinateToString( m_Pos.y ) ),
  222. GetChars( CoordinateToString( m_Radius ) ) );
  223. }
  224. void LIB_CIRCLE::BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aPosition )
  225. {
  226. wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0,
  227. wxT( "Invalid edit mode for LIB_CIRCLE object." ) );
  228. if( aEditMode == IS_NEW )
  229. {
  230. m_Pos = m_initialPos = aPosition;
  231. }
  232. else if( aEditMode == IS_MOVED )
  233. {
  234. m_initialPos = m_Pos;
  235. m_initialCursorPos = aPosition;
  236. SetEraseLastDrawItem();
  237. }
  238. else if( aEditMode == IS_RESIZED )
  239. {
  240. SetEraseLastDrawItem();
  241. }
  242. m_Flags = aEditMode;
  243. }
  244. bool LIB_CIRCLE::ContinueEdit( const wxPoint aPosition )
  245. {
  246. wxCHECK_MSG( ( m_Flags & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0, false,
  247. wxT( "Bad call to ContinueEdit(). LIB_CIRCLE is not being edited." ) );
  248. return false;
  249. }
  250. void LIB_CIRCLE::EndEdit( const wxPoint& aPosition, bool aAbort )
  251. {
  252. wxCHECK_RET( ( m_Flags & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0,
  253. wxT( "Bad call to EndEdit(). LIB_CIRCLE is not being edited." ) );
  254. SetEraseLastDrawItem( false );
  255. m_Flags = 0;
  256. }
  257. void LIB_CIRCLE::calcEdit( const wxPoint& aPosition )
  258. {
  259. if( m_Flags == IS_NEW || m_Flags == IS_RESIZED )
  260. {
  261. if( m_Flags == IS_NEW )
  262. SetEraseLastDrawItem();
  263. m_Radius = KiROUND( GetLineLength( m_Pos, aPosition ) );
  264. }
  265. else
  266. {
  267. Move( m_initialPos + aPosition - m_initialCursorPos );
  268. }
  269. }