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.

118 lines
4.1 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/arc_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. ARC_ASSISTANT::ARC_ASSISTANT( const ARC_GEOM_MANAGER& aManager, EDA_UNITS aUnits ) :
  32. EDA_ITEM( NOT_USED ),
  33. m_constructMan( aManager ),
  34. m_units( aUnits )
  35. {
  36. }
  37. const BOX2I ARC_ASSISTANT::ViewBBox() const
  38. {
  39. BOX2I tmp;
  40. // no bounding box when no graphic shown
  41. if( m_constructMan.IsReset() )
  42. return tmp;
  43. // this is an edit-time artefact; no reason to try and be smart with the bounding box
  44. // (besides, we can't tell the text extents without a view to know what the scale is)
  45. tmp.SetMaximum();
  46. return tmp;
  47. }
  48. void ARC_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
  49. {
  50. KIGFX::GAL& gal = *aView->GetGAL();
  51. // not in a position to draw anything
  52. if( m_constructMan.IsReset() )
  53. return;
  54. gal.ResetTextAttributes();
  55. const VECTOR2I origin = m_constructMan.GetOrigin();
  56. KIGFX::PREVIEW::DRAW_CONTEXT preview_ctx( *aView );
  57. // draw first radius line
  58. bool dimFirstLine = m_constructMan.GetStep() > ARC_GEOM_MANAGER::SET_START;
  59. preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetStartRadiusEnd(),
  60. dimFirstLine );
  61. std::vector<wxString> cursorStrings;
  62. if( m_constructMan.GetStep() == ARC_GEOM_MANAGER::SET_START )
  63. {
  64. // haven't started the angle selection phase yet
  65. EDA_ANGLE initAngle = m_constructMan.GetStartAngle();
  66. // draw the radius guide circle
  67. preview_ctx.DrawCircle( origin, m_constructMan.GetRadius(), true );
  68. initAngle.Normalize720();
  69. cursorStrings.push_back( DimensionLabel( "r", m_constructMan.GetRadius(), m_units ) );
  70. cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), initAngle.AsDegrees(),
  71. EDA_UNITS::DEGREES ) );
  72. }
  73. else
  74. {
  75. preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetEndRadiusEnd(), false );
  76. EDA_ANGLE start = m_constructMan.GetStartAngle();
  77. EDA_ANGLE subtended = m_constructMan.GetSubtended();
  78. EDA_ANGLE endAngle = start + subtended;
  79. // draw dimmed extender line to cursor
  80. preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetLastPoint(), true );
  81. cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "Δθ" ), subtended.AsDegrees(),
  82. EDA_UNITS::DEGREES ) );
  83. cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), endAngle.AsDegrees(),
  84. EDA_UNITS::DEGREES ) );
  85. }
  86. // place the text next to cursor, on opposite side from radius
  87. DrawTextNextToCursor( aView, m_constructMan.GetLastPoint(),
  88. origin - m_constructMan.GetLastPoint(), cursorStrings,
  89. aLayer == LAYER_SELECT_OVERLAY );
  90. }