2017-03-09 09:09:13 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2019-07-02 13:28:37 +00:00
|
|
|
* Copyright (C) 2019 Kicad Developers, see AUTHORS.txt for contributors.
|
2017-03-09 09:09:13 +00:00
|
|
|
*
|
2019-07-02 13:28:37 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2017-03-09 09:09:13 +00:00
|
|
|
*
|
2019-07-02 13:28:37 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
2017-03-09 09:09:13 +00:00
|
|
|
*
|
2019-07-02 13:28:37 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-03-09 09:09:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <preview_items/preview_utils.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <base_units.h>
|
2019-08-31 14:35:33 +00:00
|
|
|
#include <painter.h>
|
2017-08-04 12:43:02 +00:00
|
|
|
#include <view/view.h>
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
double KIGFX::PREVIEW::PreviewOverlayDeemphAlpha( bool aDeemph )
|
|
|
|
{
|
|
|
|
return aDeemph ? 0.5 : 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
static wxString formatPreviewDimension( double aVal, EDA_UNITS aUnits )
|
2017-03-09 09:09:13 +00:00
|
|
|
{
|
|
|
|
int precision = 4;
|
|
|
|
|
|
|
|
// show a sane precision for the preview, which doesn't need to
|
|
|
|
// be accurate down to the nanometre
|
|
|
|
switch( aUnits )
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
case EDA_UNITS::MILLIMETRES:
|
2019-07-02 13:28:37 +00:00
|
|
|
precision = 3; // 1um
|
2017-03-09 09:09:13 +00:00
|
|
|
break;
|
2019-02-22 19:47:55 +00:00
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
case EDA_UNITS::INCHES:
|
2019-02-22 19:47:55 +00:00
|
|
|
precision = 4; // 0.1mil
|
2017-03-09 09:09:13 +00:00
|
|
|
break;
|
2019-02-22 19:47:55 +00:00
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
case EDA_UNITS::DEGREES:
|
2019-02-22 19:47:55 +00:00
|
|
|
precision = 1; // 0.1deg
|
2017-03-09 09:09:13 +00:00
|
|
|
break;
|
2019-02-22 19:47:55 +00:00
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
case EDA_UNITS::PERCENT:
|
2019-07-02 00:30:05 +00:00
|
|
|
precision = 1; // 0.1%
|
|
|
|
break;
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
case EDA_UNITS::UNSCALED:
|
2017-03-09 09:09:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString fmtStr = wxString::Format( "%%.%df", precision );
|
|
|
|
|
|
|
|
wxString str = wxString::Format( fmtStr, To_User_Unit( aUnits, aVal ) );
|
|
|
|
|
2019-02-22 19:47:55 +00:00
|
|
|
const wxString symbol = GetAbbreviatedUnitsLabel( aUnits, false );
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
if( symbol.size() )
|
|
|
|
str << " " << symbol;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
wxString KIGFX::PREVIEW::DimensionLabel( const wxString& prefix, double aVal, EDA_UNITS aUnits )
|
2017-03-09 09:09:13 +00:00
|
|
|
{
|
|
|
|
wxString str;
|
|
|
|
|
|
|
|
if( prefix.size() )
|
|
|
|
str << prefix << ": ";
|
|
|
|
|
|
|
|
str << formatPreviewDimension( aVal, aUnits );
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KIGFX::PREVIEW::SetConstantGlyphHeight( KIGFX::GAL& aGal, double aHeight )
|
|
|
|
{
|
|
|
|
aHeight /= aGal.GetWorldScale();
|
|
|
|
|
|
|
|
auto glyphSize = aGal.GetGlyphSize();
|
|
|
|
glyphSize = glyphSize * ( aHeight / glyphSize.y );
|
|
|
|
aGal.SetGlyphSize( glyphSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-04 12:43:02 +00:00
|
|
|
void KIGFX::PREVIEW::DrawTextNextToCursor( KIGFX::VIEW* aView,
|
2017-03-09 09:09:13 +00:00
|
|
|
const VECTOR2D& aCursorPos, const VECTOR2D& aTextQuadrant,
|
|
|
|
const std::vector<wxString>& aStrings )
|
|
|
|
{
|
2017-08-04 12:43:02 +00:00
|
|
|
auto gal = aView->GetGAL();
|
|
|
|
auto glyphSize = gal->GetGlyphSize();
|
2019-08-31 14:35:33 +00:00
|
|
|
auto rs = aView->GetPainter()->GetSettings();
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
const auto lineSpace = glyphSize.y * 0.2;
|
|
|
|
auto linePitch = glyphSize.y + lineSpace;
|
|
|
|
|
|
|
|
// radius string goes on the right of the cursor centre line
|
|
|
|
// with a small horizontal offset (enough to keep clear of a
|
|
|
|
// system cursor if present)
|
|
|
|
auto textPos = aCursorPos;
|
|
|
|
|
|
|
|
// if the text goes above the cursor, shift it up
|
|
|
|
if( aTextQuadrant.y > 0 )
|
|
|
|
{
|
|
|
|
textPos.y -= linePitch * ( aStrings.size() + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aTextQuadrant.x < 0 )
|
|
|
|
{
|
2017-08-04 12:43:02 +00:00
|
|
|
gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
textPos.x += 15.0 / gal->GetWorldScale();
|
2017-03-09 09:09:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-04 12:43:02 +00:00
|
|
|
gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
textPos.x -= 15.0 / gal->GetWorldScale();
|
2017-03-09 09:09:13 +00:00
|
|
|
}
|
|
|
|
|
2020-07-03 15:05:17 +00:00
|
|
|
gal->SetLineWidth( 1.0f ); // TODO(ISM): Set to the minimum GAL linewidth for HiDPI compatibility
|
2017-08-04 12:43:02 +00:00
|
|
|
gal->SetStrokeColor( rs->GetLayerColor( LAYER_AUX_ITEMS ).WithAlpha(
|
2017-03-09 09:09:13 +00:00
|
|
|
PreviewOverlayDeemphAlpha( true ) ) );
|
2017-08-04 12:43:02 +00:00
|
|
|
gal->SetIsFill( false );
|
2017-03-09 09:09:13 +00:00
|
|
|
|
|
|
|
// write strings top-to-bottom
|
|
|
|
for( const auto& str : aStrings )
|
|
|
|
{
|
|
|
|
textPos.y += linePitch;
|
2017-08-04 12:43:02 +00:00
|
|
|
gal->BitmapText( str, textPos, 0.0 );
|
2017-03-09 09:09:13 +00:00
|
|
|
}
|
|
|
|
}
|