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.

110 lines
3.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017-2022 Kicad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include "preview_items/bezier_assistant.h"
  24. #include <preview_items/draw_context.h>
  25. #include <preview_items/preview_utils.h>
  26. #include <gal/graphics_abstraction_layer.h>
  27. #include <view/view.h>
  28. #include <base_units.h>
  29. #include <trigo.h>
  30. using namespace KIGFX::PREVIEW;
  31. BEZIER_ASSISTANT::BEZIER_ASSISTANT( const BEZIER_GEOM_MANAGER& aManager,
  32. const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits ) :
  33. EDA_ITEM( NOT_USED ), m_constructMan( aManager ), m_iuScale( aIuScale ), m_units( aUnits )
  34. {
  35. }
  36. const BOX2I BEZIER_ASSISTANT::ViewBBox() const
  37. {
  38. BOX2I tmp;
  39. // no bounding box when no graphic shown
  40. if( m_constructMan.IsReset() )
  41. return tmp;
  42. // this is an edit-time artefact; no reason to try and be smart with the bounding box
  43. // (besides, we can't tell the text extents without a view to know what the scale is)
  44. tmp.SetMaximum();
  45. return tmp;
  46. }
  47. void BEZIER_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
  48. {
  49. KIGFX::GAL& gal = *aView->GetGAL();
  50. // not in a position to draw anything
  51. if( m_constructMan.IsReset() )
  52. return;
  53. gal.ResetTextAttributes();
  54. const VECTOR2I start = m_constructMan.GetStart();
  55. const BEZIER_GEOM_MANAGER::BEZIER_STEPS step = m_constructMan.GetStep();
  56. KIGFX::PREVIEW::DRAW_CONTEXT preview_ctx( *aView );
  57. int dashSize = KiROUND( aView->ToWorld( 12 ) );
  58. if( step >= BEZIER_GEOM_MANAGER::BEZIER_STEPS::SET_CONTROL1 )
  59. {
  60. // Draw the first control point control line
  61. preview_ctx.DrawLineDashed( start, m_constructMan.GetControlC1(), dashSize, dashSize / 2,
  62. false );
  63. }
  64. if( step >= BEZIER_GEOM_MANAGER::BEZIER_STEPS::SET_CONTROL2 )
  65. {
  66. const VECTOR2I c2vec = m_constructMan.GetControlC2() - m_constructMan.GetEnd();
  67. // Draw the second control point control line as a double length line
  68. // centred on the end point
  69. preview_ctx.DrawLineDashed( m_constructMan.GetEnd() - c2vec, m_constructMan.GetControlC2(),
  70. dashSize, dashSize / 2, false );
  71. }
  72. std::vector<wxString> cursorStrings;
  73. if( step >= BEZIER_GEOM_MANAGER::BEZIER_STEPS::SET_END )
  74. {
  75. // Going to need a better way to get a length here
  76. // const int length = m_constructMan.GetBezierLength();
  77. // Have enough points to report a bezier length
  78. // cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "L" ), 12300000,
  79. // m_iuScale, m_units ) );
  80. }
  81. if( !cursorStrings.empty() )
  82. {
  83. // place the text next to cursor, on opposite side from radius
  84. DrawTextNextToCursor( aView, m_constructMan.GetLastPoint(),
  85. start - m_constructMan.GetLastPoint(), cursorStrings,
  86. aLayer == LAYER_SELECT_OVERLAY );
  87. }
  88. }