Move LIB_PART::Draw drawing options into a struct

This makes configuring the options clearer, avoiding the long list of
non-self-explanatory arguments at the small cost of requiring a few more
lines.
This commit is contained in:
Chris Pavlina 2017-02-19 13:40:26 -05:00
parent 5dea5e2ada
commit a61be7e00e
9 changed files with 106 additions and 70 deletions

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
* Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -343,12 +343,14 @@ void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
int unit = parent->GetUnit();
int convert = parent->GetConvert();
auto opts = PART_DRAW_OPTIONS::Default();
opts.draw_mode = g_XorMode;
opts.only_selected = true;
if( aErase )
{
block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
component->Draw( aPanel, aDC, block->GetMoveVector(), unit, convert,
g_XorMode, UNSPECIFIED_COLOR, DefaultTransform, true, true, true );
component->Draw( aPanel, aDC, block->GetMoveVector(), unit, convert, opts );
}
// Repaint new view
@ -357,6 +359,5 @@ void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
GRSetDrawMode( aDC, g_XorMode );
block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
component->Draw( aPanel, aDC, block->GetMoveVector(), unit, convert,
g_XorMode, UNSPECIFIED_COLOR, DefaultTransform, true, true, true );
component->Draw( aPanel, aDC, block->GetMoveVector(), unit, convert, opts );
}

View File

@ -313,15 +313,12 @@ void LIB_PART::SetName( const wxString& aName )
}
void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset, int aMulti,
int aConvert, GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor,
const TRANSFORM& aTransform, bool aShowPinText, bool aDrawFields,
bool aOnlySelected, const std::vector<bool>* aPinsDangling,
bool aShowElectricalType )
void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
int aMulti, int aConvert, const PART_DRAW_OPTIONS& aOpts )
{
BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL;
GRSetDrawMode( aDc, aDrawMode );
GRSetDrawMode( aDc, aOpts.draw_mode );
/* draw background for filled items using background option
* Solid lines will be drawn after the background
@ -330,14 +327,14 @@ void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
* If the color is not the default color (aColor != -1 )
*/
if( ! (screen && screen->m_IsPrinting && GetGRForceBlackPenState())
&& (aColor == UNSPECIFIED_COLOR) )
&& ( aOpts.color == UNSPECIFIED_COLOR ) )
{
for( LIB_ITEM& drawItem : drawings )
{
if( drawItem.m_Fill != FILLED_WITH_BG_BODYCOLOR )
continue;
if( aOnlySelected && !drawItem.IsSelected() )
if( aOpts.only_selected && !drawItem.IsSelected() )
continue;
// Do not draw an item while moving (the cursor handler does that)
@ -356,12 +353,14 @@ void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
if( drawItem.Type() == LIB_FIELD_T )
{
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) NULL, aTransform );
drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
aOpts.draw_mode, (void*) NULL, aOpts.transform );
}
// Now, draw only the background for items with
// m_Fill == FILLED_WITH_BG_BODYCOLOR:
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) false, aTransform );
drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
aOpts.draw_mode, (void*) false, aOpts.transform );
}
}
@ -370,7 +369,7 @@ void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
for( LIB_ITEM& drawItem : drawings )
{
if( aOnlySelected && !drawItem.IsSelected() )
if( aOpts.only_selected && !drawItem.IsSelected() )
continue;
// Do not draw an item while moving (the cursor handler does that)
@ -384,39 +383,50 @@ void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
if( aConvert && drawItem.m_Convert && ( drawItem.m_Convert != aConvert ) )
continue;
if( !aDrawFields && drawItem.Type() == LIB_FIELD_T )
if( drawItem.Type() == LIB_FIELD_T )
{
LIB_FIELD& field = dynamic_cast<LIB_FIELD&>( drawItem );
if( field.IsVisible() && !aOpts.draw_visible_fields )
continue;
if( !field.IsVisible() && !aOpts.draw_hidden_fields )
continue;
}
if( drawItem.Type() == LIB_PIN_T )
{
LIB_PIN& pin = dynamic_cast<LIB_PIN&>( drawItem );
uintptr_t flags = 0;
if( aShowPinText )
if( aOpts.show_pin_text )
flags |= PIN_DRAW_TEXTS;
if( aShowElectricalType )
if( aOpts.show_elec_type )
flags |= PIN_DRAW_ELECTRICAL_TYPE_NAME;
if( !aPinsDangling || (aPinsDangling->size() > pin_index && (*aPinsDangling)[pin_index] ) )
if( aOpts.PinIsDangling( pin_index ) )
flags |= PIN_DRAW_DANGLING;
if( pin.IsPowerConnection() && IsPower() )
flags |= PIN_DANGLING_HIDDEN;
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) flags, aTransform );
drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
aOpts.draw_mode, (void*) flags, aOpts.transform );
++pin_index;
}
else if( drawItem.Type() == LIB_FIELD_T )
{
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) NULL, aTransform );
drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
aOpts.draw_mode, (void*) NULL, aOpts.transform );
}
else
{
bool forceNoFill = drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR;
drawItem.Draw( aPanel, aDc, aOffset, aColor, aDrawMode, (void*) forceNoFill,
aTransform );
drawItem.Draw( aPanel, aDc, aOffset, aOpts.color,
aOpts.draw_mode, (void*) forceNoFill,
aOpts.transform );
}
}
@ -427,9 +437,9 @@ void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
EDA_RECT* const clipbox = aPanel ? aPanel->GetClipBox() : NULL;
GRLine( clipbox, aDc, aOffset.x, aOffset.y - len, aOffset.x,
aOffset.y + len, 0, aColor );
aOffset.y + len, 0, aOpts.color );
GRLine( clipbox, aDc, aOffset.x - len, aOffset.y, aOffset.x + len,
aOffset.y, 0, aColor );
aOffset.y, 0, aOpts.color );
#endif
/* Enable this to draw the bounding box around the component to validate
@ -437,7 +447,7 @@ void LIB_PART::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
#if 0
EDA_RECT bBox = GetUnitBoundingBox( aMulti, aConvert );
bBox.RevertYAxis();
bBox = aTransform.TransformCoordinate( bBox );
bBox = aOpts.transform.TransformCoordinate( bBox );
bBox.Move( aOffset );
GRRect( aPanel ? aPanel->GetClipBox() : NULL, aDc, bBox, 0, LIGHTMAGENTA );
#endif

View File

@ -174,6 +174,42 @@ extern bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 );
extern int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 );
struct PART_DRAW_OPTIONS
{
GR_DRAWMODE draw_mode; ///< Device context drawing mode, see wxDC
EDA_COLOR_T color; ///< Color to draw part in
TRANSFORM transform; ///< Coordinate adjustment settings
bool show_pin_text; ///< Whether to show pin texts
bool draw_visible_fields; ///< Whether to draw "visible" fields
bool draw_hidden_fields; ///< Whether to draw "hidden" fields
bool only_selected; ///< Draws only the body items that are selected, for block moves
std::vector<bool> dangling; ///< which pins should display as dangling, or empty for All
bool show_elec_type; ///< Whether to show the pin electrical type
static PART_DRAW_OPTIONS Default()
{
PART_DRAW_OPTIONS def;
def.draw_mode = GR_DEFAULT_DRAWMODE;
def.color = UNSPECIFIED_COLOR;
def.transform = DefaultTransform;
def.show_pin_text = true;
def.draw_visible_fields = true;
def.draw_hidden_fields = true;
def.only_selected = false;
def.show_elec_type = false;
return def;
}
bool PinIsDangling( size_t aPin ) const
{
if( aPin < dangling.size() )
return dangling[aPin];
else
return true;
}
};
/**
* Class LIB_PART
* defines a library part object.
@ -408,31 +444,11 @@ public:
* @param aOffset - Position of part.
* @param aMulti - unit if multiple units per part.
* @param aConvert - Component conversion (DeMorgan) if available.
* @param aDrawMode - Device context drawing mode, see wxDC.
* @param aColor - Color to draw part.
* @param aTransform - Coordinate adjustment settings.
* @param aShowPinText - Show pin text if true.
* @param aDrawFields - Draw field text if true otherwise just draw
* body items (useful to draw a body in schematic,
* because fields of schematic components replace
* the lib part fields).
* @param aOnlySelected - Draws only the body items that are selected.
* Used for block move redraws.
* @param aPinsDangling - if not NULL, this should be a pointer to
* vector<bool> exactly the same length as the number of pins,
* indicating whether each pin is dangling. If NULL, all pins
* will be drawn as if they were dangling.
* @param aShowElectricalType - show the electrical type name of the pin
* used only in component editor and component viewer
* @param aOpts - Drawing options
*/
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOffset,
int aMulti, int aConvert, GR_DRAWMODE aDrawMode,
EDA_COLOR_T aColor = UNSPECIFIED_COLOR,
const TRANSFORM& aTransform = DefaultTransform,
bool aShowPinText = true, bool aDrawFields = true,
bool aOnlySelected = false,
const std::vector<bool>* aPinsDangling = NULL,
bool aShowElectricalType = false );
int aMulti, int aConvert,
const PART_DRAW_OPTIONS& aOpts );
/**
* Plot lib part to plotter.

View File

@ -361,9 +361,8 @@ void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_PART* aComponent, int aUnit )
wxPoint offset = -bBox.Centre();
aComponent->Draw( NULL, &dc, offset, aUnit, m_deMorganConvert, GR_COPY,
UNSPECIFIED_COLOR, DefaultTransform, true, true, false );
auto opts = PART_DRAW_OPTIONS::Default();
aComponent->Draw( NULL, &dc, offset, aUnit, m_deMorganConvert, opts );
}

View File

@ -238,8 +238,7 @@ void DIALOG_RESCUE_EACH::renderPreview( LIB_PART* aComponent, int aUnit, wxPanel
if( !width || !height )
return;
aComponent->Draw( NULL, &dc, offset, aUnit, /* deMorganConvert */ 1, GR_COPY,
UNSPECIFIED_COLOR, DefaultTransform, true, true, false );
aComponent->Draw( NULL, &dc, offset, aUnit, 1, PART_DRAW_OPTIONS::Default() );
}

View File

@ -253,9 +253,9 @@ void LIB_EDIT_FRAME::RedrawComponent( wxDC* aDC, wxPoint aOffset )
wxString fieldfullText = field->GetFullText( m_unit );
field->EDA_TEXT::SetText( fieldfullText ); // change the field text string only
part->Draw( m_canvas, aDC, aOffset, m_unit, m_convert, GR_DEFAULT_DRAWMODE,
UNSPECIFIED_COLOR, DefaultTransform,
true, true,false, NULL, GetShowElectricalType() );
auto opts = PART_DRAW_OPTIONS::Default();
opts.show_elec_type = GetShowElectricalType();
part->Draw( m_canvas, aDC, aOffset, m_unit, m_convert, opts );
field->EDA_TEXT::SetText( fieldText ); // restore the field text string
}
}

View File

@ -5,7 +5,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -208,7 +208,7 @@ void LIB_EDIT_FRAME::PrintPage( wxDC* aDC, LSET aPrintMask, bool aPrintMirrorMod
plot_offset.x = pagesize.x/2;
plot_offset.y = pagesize.y/2;
part->Draw( m_canvas, aDC, plot_offset, m_unit, m_convert, GR_DEFAULT_DRAWMODE );
part->Draw( m_canvas, aDC, plot_offset, m_unit, m_convert, PART_DRAW_OPTIONS::Default() );
}

View File

@ -349,18 +349,29 @@ void SCH_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOff
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor,
bool aDrawPinText )
{
auto opts = PART_DRAW_OPTIONS::Default();
opts.draw_mode = aDrawMode;
opts.color = aColor;
opts.transform = m_transform;
opts.show_pin_text = aDrawPinText;
opts.draw_visible_fields = false;
opts.draw_hidden_fields = false;
if( PART_SPTR part = m_part.lock() )
{
// Draw pin targets if part is being dragged
bool dragging = aPanel->GetScreen()->GetCurItem() == this && aPanel->IsMouseCaptured();
part->Draw( aPanel, aDC, m_Pos + aOffset, m_unit, m_convert, aDrawMode, aColor,
m_transform, aDrawPinText, false, false, dragging ? NULL : &m_isDangling );
if( !dragging )
{
opts.dangling = m_isDangling;
}
part->Draw( aPanel, aDC, m_Pos + aOffset, m_unit, m_convert, opts );
}
else // Use dummy() part if the actual cannot be found.
{
dummy()->Draw( aPanel, aDC, m_Pos + aOffset, 0, 0, aDrawMode, aColor,
m_transform, aDrawPinText, false );
dummy()->Draw( aPanel, aDC, m_Pos + aOffset, 0, 0, opts );
}
SCH_FIELD* field = GetField( REFERENCE );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2015-2016 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2015-2017 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -219,9 +219,9 @@ void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
else
msg = _( "None" );
part->Draw( m_canvas, DC, wxPoint( 0, 0 ), m_unit, m_convert, GR_DEFAULT_DRAWMODE,
UNSPECIFIED_COLOR, DefaultTransform,
true, true,false, NULL, GetShowElectricalType() );
auto opts = PART_DRAW_OPTIONS::Default();
opts.show_elec_type = GetShowElectricalType();
part->Draw( m_canvas, DC, wxPoint( 0, 0 ), m_unit, m_convert, opts );
// Redraw the cursor
m_canvas->DrawCrossHair( DC );