Remove AdvanceDepth() hacks in favour of proper layers.

Also removes the bounding-box cache since the last big merge
should have sorted out the Update(GEOMETRY) calls.

Fixes: lp:1797271
* https://bugs.launchpad.net/kicad/+bug/1797271

Fixes: lp:1797268
* https://bugs.launchpad.net/kicad/+bug/1797268

Fixes: lp:1797075
* https://bugs.launchpad.net/kicad/+bug/1797075
This commit is contained in:
Jeff Young 2018-10-21 13:50:31 +01:00
parent 8ecdf58bad
commit f17c18bcce
30 changed files with 248 additions and 225 deletions

View File

@ -180,6 +180,14 @@ bool operator<( const LIB_ALIAS& aItem1, const LIB_ALIAS& aItem2 )
} }
void LIB_ALIAS::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 2;
aLayers[0] = LAYER_DEVICE;
aLayers[1] = LAYER_DEVICE_BACKGROUND;
}
/// http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared /// http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#weak_without_shared
struct null_deleter struct null_deleter
{ {
@ -761,6 +769,14 @@ const EDA_RECT LIB_PART::GetUnitBoundingBox( int aUnit, int aConvert ) const
} }
void LIB_PART::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 2;
aLayers[0] = LAYER_DEVICE;
aLayers[1] = LAYER_DEVICE_BACKGROUND;
}
const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const const EDA_RECT LIB_PART::GetBodyBoundingBox( int aUnit, int aConvert ) const
{ {
EDA_RECT bBox; EDA_RECT bBox;

View File

@ -176,6 +176,8 @@ public:
bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; } bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; }
void ViewGetLayers( int aLayers[], int& aCount ) const override;
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif #endif
@ -329,6 +331,8 @@ public:
wxArrayString& GetFootprints() { return m_FootprintList; } wxArrayString& GetFootprints() { return m_FootprintList; }
void ViewGetLayers( int aLayers[], int& aCount ) const override;
/** /**
* Get the bounding box for the symbol. * Get the bounding box for the symbol.
* *

View File

@ -153,6 +153,15 @@ void LIB_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
} }
void LIB_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
{
// Basic fallback
aCount = 2;
aLayers[0] = LAYER_DEVICE;
aLayers[1] = LAYER_DEVICE_BACKGROUND;
}
COLOR4D LIB_ITEM::GetDefaultColor() COLOR4D LIB_ITEM::GetDefaultColor()
{ {
return GetLayerColor( LAYER_DEVICE ); return GetLayerColor( LAYER_DEVICE );

View File

@ -219,6 +219,8 @@ public:
return (LIB_PART *)m_Parent; return (LIB_PART *)m_Parent;
} }
void ViewGetLayers( int aLayers[], int& aCount ) const override;
virtual bool HitTest( const wxPoint& aPosition ) const override virtual bool HitTest( const wxPoint& aPosition ) const override
{ {
return EDA_ITEM::HitTest( aPosition ); return EDA_ITEM::HitTest( aPosition );

View File

@ -393,26 +393,27 @@ const EDA_RECT LIB_FIELD::GetBoundingBox() const
} }
COLOR4D LIB_FIELD::GetDefaultColor() void LIB_FIELD::ViewGetLayers( int aLayers[], int& aCount ) const
{ {
COLOR4D color; aCount = 1;
switch( m_id ) switch( m_id )
{ {
case REFERENCE: case REFERENCE: aLayers[0] = LAYER_REFERENCEPART; break;
color = GetLayerColor( LAYER_REFERENCEPART ); case VALUE: aLayers[0] = LAYER_VALUEPART; break;
break; default: aLayers[0] = LAYER_FIELDS; break;
case VALUE:
color = GetLayerColor( LAYER_VALUEPART );
break;
default:
color = GetLayerColor( LAYER_FIELDS );
break;
} }
}
return color;
COLOR4D LIB_FIELD::GetDefaultColor()
{
switch( m_id )
{
case REFERENCE: return GetLayerColor( LAYER_REFERENCEPART );
case VALUE: return GetLayerColor( LAYER_VALUEPART );
default: return GetLayerColor( LAYER_FIELDS );
}
} }

View File

@ -158,6 +158,8 @@ public:
return m_Text.IsEmpty(); return m_Text.IsEmpty();
} }
void ViewGetLayers( int aLayers[], int& aCount ) const override;
/** /**
* @return true is this field is visible, false if flagged invisible * @return true is this field is visible, false if flagged invisible
*/ */

View File

@ -52,6 +52,13 @@ LIB_TEXT::LIB_TEXT( LIB_PART * aParent ) :
} }
void LIB_TEXT::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 1;
aLayers[0] = LAYER_NOTES;
}
bool LIB_TEXT::HitTest( const wxPoint& aPosition ) const bool LIB_TEXT::HitTest( const wxPoint& aPosition ) const
{ {
return HitTest( aPosition, 0, DefaultTransform ); return HitTest( aPosition, 0, DefaultTransform );

View File

@ -70,6 +70,8 @@ public:
return _( "Text" ); return _( "Text" );
} }
void ViewGetLayers( int aLayers[], int& aCount ) const override;
/** /**
* Sets the text item string to \a aText. * Sets the text item string to \a aText.
* *

View File

@ -1742,17 +1742,12 @@ void LIB_EDIT_FRAME::SetScreen( BASE_SCREEN* aScreen )
void LIB_EDIT_FRAME::RebuildView() void LIB_EDIT_FRAME::RebuildView()
{ {
KIGFX::SCH_VIEW* view = GetCanvas()->GetView();
view->Clear();
GetRenderSettings()->m_ShowUnit = m_unit; GetRenderSettings()->m_ShowUnit = m_unit;
GetRenderSettings()->m_ShowConvert = m_convert; GetRenderSettings()->m_ShowConvert = m_convert;
GetCanvas()->DisplayComponent( m_my_part );
view->DisplayComponent( m_my_part ); GetCanvas()->GetView()->HideWorksheet();
GetCanvas()->GetView()->ClearHiddenFlags();
view->HideWorksheet();
view->ClearHiddenFlags();
GetCanvas()->Refresh(); GetCanvas()->Refresh();
} }

View File

@ -100,6 +100,14 @@ void SCH_BUS_ENTRY_BASE::SwapData( SCH_ITEM* aItem )
} }
void SCH_BUS_ENTRY_BASE::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 1;
aLayers[0] = Type() == SCH_BUS_BUS_ENTRY_T ? LAYER_BUS : LAYER_WIRE;
}
const EDA_RECT SCH_BUS_ENTRY_BASE::GetBoundingBox() const const EDA_RECT SCH_BUS_ENTRY_BASE::GetBoundingBox() const
{ {
EDA_RECT box; EDA_RECT box;

View File

@ -83,6 +83,8 @@ public:
void SwapData( SCH_ITEM* aItem ) override; void SwapData( SCH_ITEM* aItem ) override;
void ViewGetLayers( int aLayers[], int& aCount ) const override;
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override; GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;

View File

@ -233,6 +233,14 @@ EDA_ITEM* SCH_COMPONENT::Clone() const
} }
void SCH_COMPONENT::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 2;
aLayers[0] = LAYER_DEVICE;
aLayers[1] = LAYER_DEVICE_BACKGROUND;
}
void SCH_COMPONENT::SetLibId( const LIB_ID& aLibId, PART_LIBS* aLibs ) void SCH_COMPONENT::SetLibId( const LIB_ID& aLibId, PART_LIBS* aLibs )
{ {
if( m_lib_id != aLibId ) if( m_lib_id != aLibId )

View File

@ -153,6 +153,8 @@ public:
const wxArrayString& GetPathsAndReferences() const { return m_PathsAndReferences; } const wxArrayString& GetPathsAndReferences() const { return m_PathsAndReferences; }
void ViewGetLayers( int aLayers[], int& aCount ) const override;
/** /**
* Return true for items which are moved with the anchor point at mouse cursor * Return true for items which are moved with the anchor point at mouse cursor
* and false for items moved with no reference to anchor. * and false for items moved with no reference to anchor.

View File

@ -40,6 +40,7 @@
using namespace std::placeholders; using namespace std::placeholders;
// Events used by EDA_DRAW_PANEL // Events used by EDA_DRAW_PANEL
// GAL TODO: some (most?) of these need to be implemented... // GAL TODO: some (most?) of these need to be implemented...
BEGIN_EVENT_TABLE( SCH_DRAW_PANEL, wxScrolledCanvas ) BEGIN_EVENT_TABLE( SCH_DRAW_PANEL, wxScrolledCanvas )
@ -69,13 +70,8 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ), EDA_DRAW_PANEL_GAL( aParentWindow, aWindowId, aPosition, aSize, aOptions, aGalType ),
m_parent( aParentWindow ) m_parent( aParentWindow )
{ {
#ifdef __WXMAC__
m_defaultCursor = m_currentCursor = wxCURSOR_CROSS;
m_showCrossHair = false;
#else
m_defaultCursor = m_currentCursor = wxCURSOR_ARROW; m_defaultCursor = m_currentCursor = wxCURSOR_ARROW;
m_showCrossHair = true; m_showCrossHair = true;
#endif
m_view = new KIGFX::SCH_VIEW( true ); m_view = new KIGFX::SCH_VIEW( true );
m_view->SetGAL( m_gal ); m_view->SetGAL( m_gal );
@ -143,8 +139,6 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId,
Show( true ); Show( true );
Raise(); Raise();
StartDrawing(); StartDrawing();
//printf("CreateGALPAnel\n");
//m_selectionArea = new KIGFX::PREVIEW::SELECTION_AREA;
} }
@ -182,13 +176,13 @@ void SCH_DRAW_PANEL::OnShow()
void SCH_DRAW_PANEL::setDefaultLayerOrder() void SCH_DRAW_PANEL::setDefaultLayerOrder()
{ {
/* for( LAYER_NUM i = 0; (unsigned) i < sizeof( GAL_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i ) for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
{ {
LAYER_NUM layer = GAL_LAYER_ORDER[i]; LAYER_NUM layer = SCH_LAYER_ORDER[i];
wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS ); wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
m_view->SetLayerOrder( layer, i ); m_view->SetLayerOrder( layer, i );
}*/ }
} }
@ -259,8 +253,6 @@ void SCH_DRAW_PANEL::setDefaultLayerDeps()
m_view->SetLayerTarget( LAYER_WORKSHEET , KIGFX::TARGET_NONCACHED ); m_view->SetLayerTarget( LAYER_WORKSHEET , KIGFX::TARGET_NONCACHED );
m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ) ; m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ) ;
m_view->SetLayerDisplayOnly( LAYER_DRC );
} }

View File

@ -68,6 +68,14 @@ SCH_ITEM::~SCH_ITEM()
} }
void SCH_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
{
// Basic fallback
aCount = 1;
aLayers[0] = LAYER_DEVICE;
}
bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const
{ {
if( m_Flags & STRUCT_DELETED || m_Flags & SKIP_STRUCT ) if( m_Flags & STRUCT_DELETED || m_Flags & SKIP_STRUCT )

View File

@ -169,6 +169,12 @@ public:
*/ */
void SetLayer( SCH_LAYER_ID aLayer ) { m_Layer = aLayer; } void SetLayer( SCH_LAYER_ID aLayer ) { m_Layer = aLayer; }
/**
* Function ViewGetLayers
* returns the layers the item is drawn on (which may be more than its "home" layer)
*/
void ViewGetLayers( int aLayers[], int& aCount ) const override;
/** /**
* Function GetPenSize virtual pure * Function GetPenSize virtual pure
* @return the size of the "pen" that be used to draw or plot this item * @return the size of the "pen" that be used to draw or plot this item

View File

@ -73,6 +73,13 @@ void SCH_JUNCTION::SwapData( SCH_ITEM* aItem )
} }
void SCH_JUNCTION::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 1;
aLayers[0] = LAYER_JUNCTION;
}
const EDA_RECT SCH_JUNCTION::GetBoundingBox() const const EDA_RECT SCH_JUNCTION::GetBoundingBox() const
{ {
EDA_RECT rect; EDA_RECT rect;

View File

@ -59,6 +59,8 @@ public:
void SwapData( SCH_ITEM* aItem ) override; void SwapData( SCH_ITEM* aItem ) override;
void ViewGetLayers( int aLayers[], int& aCount ) const override;
const EDA_RECT GetBoundingBox() const override; const EDA_RECT GetBoundingBox() const override;
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,

View File

@ -108,6 +108,13 @@ bool SCH_MARKER::Matches( wxFindReplaceData& aSearchData, void* aAuxData,
} }
void SCH_MARKER::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 1;
aLayers[0] = this->m_ErrorLevel == MARKER_SEVERITY_ERROR ? LAYER_ERC_ERR : LAYER_ERC_WARN;
}
const EDA_RECT SCH_MARKER::GetBoundingBox() const const EDA_RECT SCH_MARKER::GetBoundingBox() const
{ {
return GetBoundingBoxMarker(); return GetBoundingBoxMarker();

View File

@ -52,6 +52,8 @@ public:
return wxT( "SCH_MARKER" ); return wxT( "SCH_MARKER" );
} }
void ViewGetLayers( int aLayers[], int& aCount ) const override;
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDraw_mode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override; GR_DRAWMODE aDraw_mode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override;

View File

@ -49,7 +49,7 @@
#include <class_libentry.h> #include <class_libentry.h>
#include <class_library.h> #include <class_library.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <view/view.h>
#include <gal/graphics_abstraction_layer.h> #include <gal/graphics_abstraction_layer.h>
#include <colors_design_settings.h> #include <colors_design_settings.h>
@ -209,19 +209,16 @@ void SCH_PAINTER::draw( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit
size_t pinIndex = 0; size_t pinIndex = 0;
auto visitItem = [&]( LIB_ITEM& item, bool aBackground ) for( auto& item : aComp->GetDrawItems() )
{ {
if( aBackground != ( item.GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) )
return;
if( !aDrawFields && item.Type() == LIB_FIELD_T ) if( !aDrawFields && item.Type() == LIB_FIELD_T )
return; continue;
if( aUnit && item.GetUnit() && aUnit != item.GetUnit() ) if( aUnit && item.GetUnit() && aUnit != item.GetUnit() )
return; continue;
if( aConvert && item.GetConvert() && aConvert != item.GetConvert() ) if( aConvert && item.GetConvert() && aConvert != item.GetConvert() )
return; continue;
if( item.Type() == LIB_PIN_T ) if( item.Type() == LIB_PIN_T )
{ {
@ -236,18 +233,7 @@ void SCH_PAINTER::draw( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit
} }
else else
Draw( &item, aLayer ); Draw( &item, aLayer );
}; }
// Apply a z-order heuristic (because we don't yet let the user edit it):
// draw body-filled objects first.
for( auto& item : aComp->GetDrawItems() )
visitItem( item, true );
m_gal->AdvanceDepth();
for( auto& item : aComp->GetDrawItems() )
visitItem( item, false );
} }
@ -284,9 +270,9 @@ void SCH_PAINTER::triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D
} }
void SCH_PAINTER::setColors( const LIB_ITEM* aItem, bool aBackground ) bool SCH_PAINTER::setColors( const LIB_ITEM* aItem, int aLayer )
{ {
if( aBackground ) if( aLayer == LAYER_DEVICE_BACKGROUND && aItem->GetFillMode() == FILLED_WITH_BG_BODYCOLOR )
{ {
COLOR4D color = m_schSettings.GetLayerColor( LAYER_DEVICE_BACKGROUND ); COLOR4D color = m_schSettings.GetLayerColor( LAYER_DEVICE_BACKGROUND );
@ -297,8 +283,9 @@ void SCH_PAINTER::setColors( const LIB_ITEM* aItem, bool aBackground )
m_gal->SetFillColor( color ); m_gal->SetFillColor( color );
m_gal->SetIsStroke( false ); m_gal->SetIsStroke( false );
return true;
} }
else else if( aLayer == LAYER_DEVICE )
{ {
COLOR4D color = m_schSettings.GetLayerColor( LAYER_DEVICE ); COLOR4D color = m_schSettings.GetLayerColor( LAYER_DEVICE );
@ -311,7 +298,10 @@ void SCH_PAINTER::setColors( const LIB_ITEM* aItem, bool aBackground )
m_gal->SetIsFill( aItem->GetFillMode() == FILLED_SHAPE ); m_gal->SetIsFill( aItem->GetFillMode() == FILLED_SHAPE );
m_gal->SetFillColor( color ); m_gal->SetFillColor( color );
return true;
} }
return false;
} }
@ -320,14 +310,7 @@ void SCH_PAINTER::draw( LIB_RECTANGLE *aRect, int aLayer )
if( !isUnitAndConversionShown( aRect ) ) if( !isUnitAndConversionShown( aRect ) )
return; return;
if( aRect->GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) if( setColors( aRect, aLayer ) )
{
setColors( aRect, true );
m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) );
m_gal->AdvanceDepth();
}
setColors( aRect, false );
m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) ); m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) );
} }
@ -338,14 +321,7 @@ void SCH_PAINTER::draw( LIB_CIRCLE *aCircle, int aLayer )
if( !isUnitAndConversionShown( aCircle ) ) if( !isUnitAndConversionShown( aCircle ) )
return; return;
if( aCircle->GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) if( setColors( aCircle, aLayer ) )
{
setColors( aCircle, true );
m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() );
m_gal->AdvanceDepth();
}
setColors( aCircle, false );
m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() ); m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() );
} }
@ -366,13 +342,7 @@ void SCH_PAINTER::draw( LIB_ARC *aArc, int aLayer )
VECTOR2D pos = mapCoords( aArc->GetPosition() ); VECTOR2D pos = mapCoords( aArc->GetPosition() );
if( aArc->GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) if( setColors( aArc, aLayer ) )
{
setColors( aArc, true );
m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea );
}
setColors( aArc, false );
m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea ); m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea );
} }
@ -382,38 +352,31 @@ void SCH_PAINTER::draw( LIB_POLYLINE *aLine, int aLayer )
if( !isUnitAndConversionShown( aLine ) ) if( !isUnitAndConversionShown( aLine ) )
return; return;
const std::vector<wxPoint>& pts = aLine->GetPolyPoints(); const std::vector<wxPoint>& pts = aLine->GetPolyPoints();
std::deque<VECTOR2D> vtx; std::deque<VECTOR2D> vtx;
for( auto p : pts ) for( auto p : pts )
vtx.push_back( mapCoords( p ) ); vtx.push_back( mapCoords( p ) );
if( aLine->GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) if( setColors( aLine, aLayer ) )
{
setColors( aLine, true );
m_gal->DrawPolygon( vtx );
m_gal->AdvanceDepth();
}
setColors( aLine, false );
m_gal->DrawPolygon( vtx ); m_gal->DrawPolygon( vtx );
} }
void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer ) void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer )
{ {
// Must check layer as fields are sometimes drawn by their parent rather than
// directly from the view.
int layers[KIGFX::VIEW::VIEW_MAX_LAYERS], layers_count;
aField->ViewGetLayers( layers, layers_count );
if( aLayer != layers[0] )
return;
if( !isUnitAndConversionShown( aField ) ) if( !isUnitAndConversionShown( aField ) )
return; return;
COLOR4D color; COLOR4D color = aField->GetDefaultColor();
switch( aField->GetId() )
{
case REFERENCE: color = m_schSettings.GetLayerColor( LAYER_REFERENCEPART ); break;
case VALUE: color = m_schSettings.GetLayerColor( LAYER_VALUEPART ); break;
default: color = m_schSettings.GetLayerColor( LAYER_FIELDS ); break;
}
if( aField->IsMoving() ) if( aField->IsMoving() )
color = selectedBrightening( color ); color = selectedBrightening( color );
@ -515,6 +478,9 @@ static void drawPinDanglingSymbol( GAL* aGal, const VECTOR2I& aPos, const COLOR4
void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMoving ) void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling, bool isMoving )
{ {
if( aLayer != LAYER_DEVICE )
return;
if( !isUnitAndConversionShown( aPin ) ) if( !isUnitAndConversionShown( aPin ) )
return; return;
@ -1241,12 +1207,12 @@ void SCH_PAINTER::draw( SCH_HIERLABEL *aLabel, int aLayer )
void SCH_PAINTER::draw( SCH_SHEET *aSheet, int aLayer ) void SCH_PAINTER::draw( SCH_SHEET *aSheet, int aLayer )
{ {
VECTOR2D pos_sheetname = aSheet->GetSheetNamePosition();
VECTOR2D pos_filename = aSheet->GetFileNamePosition();
VECTOR2D pos = aSheet->GetPosition(); VECTOR2D pos = aSheet->GetPosition();
VECTOR2D size = aSheet->GetSize(); VECTOR2D size = aSheet->GetSize();
m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_SHEET ) ); if( aLayer == LAYER_SHEET_BACKGROUND )
{
m_gal->SetIsStroke( false );
if( aSheet->IsMoving() ) // Gives a filled background when moving for a better look if( aSheet->IsMoving() ) // Gives a filled background when moving for a better look
{ {
@ -1258,12 +1224,23 @@ void SCH_PAINTER::draw( SCH_SHEET *aSheet, int aLayer )
else else
{ {
// Could be modified later, when sheets can have their own fill color // Could be modified later, when sheets can have their own fill color
m_gal->SetIsFill ( false ); return;
} }
m_gal->DrawRectangle( pos, pos + size );
}
else if( aLayer == LAYER_SHEET )
{
m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_SHEET ) );
m_gal->SetIsStroke( true ); m_gal->SetIsStroke( true );
m_gal->SetIsFill( false );
m_gal->DrawRectangle( pos, pos + size ); m_gal->DrawRectangle( pos, pos + size );
auto nameAngle = 0.0; VECTOR2D pos_sheetname = aSheet->GetSheetNamePosition();
VECTOR2D pos_filename = aSheet->GetFileNamePosition();
double nameAngle = 0.0;
if( aSheet->IsVerticalOrientation() ) if( aSheet->IsVerticalOrientation() )
nameAngle = -M_PI/2; nameAngle = -M_PI/2;
@ -1293,6 +1270,7 @@ void SCH_PAINTER::draw( SCH_SHEET *aSheet, int aLayer )
for( auto& sheetPin : aSheet->GetPins() ) for( auto& sheetPin : aSheet->GetPins() )
draw( static_cast<SCH_HIERLABEL*>( &sheetPin ), aLayer ); draw( static_cast<SCH_HIERLABEL*>( &sheetPin ), aLayer );
}
} }

View File

@ -151,7 +151,7 @@ private:
bool isUnitAndConversionShown( const LIB_ITEM* aItem ); bool isUnitAndConversionShown( const LIB_ITEM* aItem );
void setColors( const LIB_ITEM* aItem, bool aBackground ); bool setColors( const LIB_ITEM* aItem, int aLayer );
void triLine ( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c ); void triLine ( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c );

View File

@ -96,29 +96,32 @@ void SCH_PREVIEW_PANEL::OnShow()
void SCH_PREVIEW_PANEL::setDefaultLayerOrder() void SCH_PREVIEW_PANEL::setDefaultLayerOrder()
{ {
/* for( LAYER_NUM i = 0; (unsigned) i < sizeof( GAL_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i ) for( LAYER_NUM i = 0; (unsigned) i < sizeof( SCH_LAYER_ORDER ) / sizeof( LAYER_NUM ); ++i )
{ {
LAYER_NUM layer = GAL_LAYER_ORDER[i]; LAYER_NUM layer = SCH_LAYER_ORDER[i];
wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS ); wxASSERT( layer < KIGFX::VIEW::VIEW_MAX_LAYERS );
m_view->SetLayerOrder( layer, i ); m_view->SetLayerOrder( layer, i );
}*/ }
} }
void SCH_PREVIEW_PANEL::setDefaultLayerDeps() void SCH_PREVIEW_PANEL::setDefaultLayerDeps()
{ {
// caching makes no sense for Cairo and other software renderers // caching makes no sense for Cairo and other software renderers
auto target = KIGFX::TARGET_NONCACHED; auto target = m_backend == GAL_TYPE_OPENGL ? KIGFX::TARGET_CACHED : KIGFX::TARGET_NONCACHED;
for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ ) for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; i++ )
m_view->SetLayerTarget( i, target ); m_view->SetLayerTarget( i, target );
m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY ); m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY );
m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ; m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ;
m_view->SetLayerTarget( LAYER_SELECT_OVERLAY , KIGFX::TARGET_OVERLAY );
m_view->SetLayerDisplayOnly( LAYER_SELECT_OVERLAY ) ;
m_view->SetLayerTarget( LAYER_WORKSHEET , KIGFX::TARGET_NONCACHED );
m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ) ; m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ) ;
m_view->SetLayerDisplayOnly( LAYER_DRC );
} }

View File

@ -424,6 +424,14 @@ wxPoint SCH_SHEET::GetFileNamePosition()
} }
void SCH_SHEET::ViewGetLayers( int aLayers[], int& aCount ) const
{
aCount = 2;
aLayers[0] = LAYER_SHEET;
aLayers[1] = LAYER_SHEET_BACKGROUND;
}
void SCH_SHEET::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, void SCH_SHEET::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor ) const wxPoint& aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor )
{ {

View File

@ -544,6 +544,8 @@ public:
SCH_ITEM& operator=( const SCH_ITEM& aSheet ); SCH_ITEM& operator=( const SCH_ITEM& aSheet );
void ViewGetLayers( int aLayers[], int& aCount ) const override;
wxPoint GetPosition() const override { return m_pos; } wxPoint GetPosition() const override { return m_pos; }
void SetPosition( const wxPoint& aPosition ) override; void SetPosition( const wxPoint& aPosition ) override;

View File

@ -52,31 +52,6 @@ SCH_VIEW::~SCH_VIEW()
} }
static const LAYER_NUM SCH_LAYER_ORDER[] =
{
LAYER_GP_OVERLAY,
LAYER_DRC,
LAYER_WORKSHEET
};
void SCH_VIEW::Add( VIEW_ITEM* aItem, int aDrawPriority )
{
// store the bounding box as eeschema can change them at weird moments (i.e.)
// while changing/resolving library references, resulting in incorrect bboxes
// and invisible components
m_cachedBBoxes[ aItem ] = aItem->ViewBBox();
VIEW::Add( aItem, aDrawPriority );
}
void SCH_VIEW::Remove( VIEW_ITEM* aItem )
{
m_cachedBBoxes.erase( aItem );
VIEW::Remove( aItem );
}
void SCH_VIEW::DisplaySheet( SCH_SCREEN *aSheet ) void SCH_VIEW::DisplaySheet( SCH_SCREEN *aSheet )
{ {
@ -186,48 +161,5 @@ void SCH_VIEW::HideWorksheet()
} }
void SCH_VIEW::Redraw()
{
std::set<EDA_ITEM*> toUpdate;
BOX2I rect;
rect.SetMaximum();
auto visitor = [&]( VIEW_ITEM* aItem ) -> bool {
auto cached = m_cachedBBoxes.find( aItem );
const auto bb = aItem->ViewBBox();
if( cached == m_cachedBBoxes.end() )
{
m_cachedBBoxes[aItem] = bb;
return true;
}
if( bb != cached->second )
{
Update( aItem, KIGFX::GEOMETRY );
m_cachedBBoxes[aItem] = bb;
}
return true;
};
/* HACK: since eeschema doesn't have any notification mechanism for changing sch items' geometry,
the bounding boxes may become inconsistend with the VIEW Rtree causing disappearing components
(depending on the zoom level). This code keeps a cache of bboxes and checks (at every redraw) if
they haven't changed wrs to the cached version. It eats up some extra CPU cycles, but for the
complexity of schematics's graphics it has negligible effect on perforamance.
*/
for( auto i = m_orderedLayers.rbegin(); i != m_orderedLayers.rend(); ++i )
{
( *i )->items->Query( rect, visitor );
}
m_gal->EnableDepthTest( false );
VIEW::Redraw();
}
}; };

View File

@ -13,6 +13,23 @@ class SCH_SHEET;
class SCH_SCREEN; class SCH_SCREEN;
class LIB_PART; class LIB_PART;
static const LAYER_NUM SCH_LAYER_ORDER[] =
{
LAYER_GP_OVERLAY, LAYER_SELECT_OVERLAY,
LAYER_ERC_ERR, LAYER_ERC_WARN,
LAYER_REFERENCEPART, LAYER_VALUEPART, LAYER_FIELDS,
LAYER_JUNCTION,
LAYER_WIRE, LAYER_BUS,
LAYER_DEVICE,
LAYER_DEVICE_BACKGROUND,
LAYER_NOTES,
LAYER_SHEET,
LAYER_SHEET_BACKGROUND,
LAYER_WORKSHEET
};
namespace KIGFX namespace KIGFX
{ {
class VIEW_GROUP; class VIEW_GROUP;
@ -29,9 +46,6 @@ public:
SCH_VIEW( bool aIsDynamic ); SCH_VIEW( bool aIsDynamic );
~SCH_VIEW(); ~SCH_VIEW();
virtual void Add( VIEW_ITEM* aItem, int aDrawPriority = -1 ) override;
virtual void Remove( VIEW_ITEM* aItem ) override;
void DisplaySheet( SCH_SHEET *aSheet ); void DisplaySheet( SCH_SHEET *aSheet );
void DisplaySheet( SCH_SCREEN *aSheet ); void DisplaySheet( SCH_SCREEN *aSheet );
void DisplayComponent( LIB_PART *aPart ); void DisplayComponent( LIB_PART *aPart );
@ -49,14 +63,11 @@ public:
void ClearHiddenFlags(); void ClearHiddenFlags();
void HideWorksheet(); void HideWorksheet();
virtual void Redraw() override;
private: private:
std::unique_ptr<WORKSHEET_VIEWITEM> m_worksheet; std::unique_ptr<WORKSHEET_VIEWITEM> m_worksheet;
std::unique_ptr<KIGFX::PREVIEW::SELECTION_AREA> m_selectionArea; std::unique_ptr<KIGFX::PREVIEW::SELECTION_AREA> m_selectionArea;
std::unique_ptr<KIGFX::VIEW_GROUP> m_preview; std::unique_ptr<KIGFX::VIEW_GROUP> m_preview;
std::vector<EDA_ITEM *> m_ownedItems; std::vector<EDA_ITEM *> m_ownedItems;
std::unordered_map<VIEW_ITEM*, BOX2I> m_cachedBBoxes;
}; };
}; // namespace }; // namespace

View File

@ -253,6 +253,7 @@ enum SCH_LAYER_ID: int
LAYER_ERC_WARN, LAYER_ERC_WARN,
LAYER_ERC_ERR, LAYER_ERC_ERR,
LAYER_DEVICE_BACKGROUND, LAYER_DEVICE_BACKGROUND,
LAYER_SHEET_BACKGROUND,
LAYER_SCHEMATIC_GRID, LAYER_SCHEMATIC_GRID,
LAYER_SCHEMATIC_BACKGROUND, LAYER_SCHEMATIC_BACKGROUND,
LAYER_SCHEMATIC_CURSOR, LAYER_SCHEMATIC_CURSOR,

View File

@ -107,6 +107,13 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
pad->IncrementPadName( true, true ); pad->IncrementPadName( true, true );
return std::unique_ptr<BOARD_ITEM>( pad ); return std::unique_ptr<BOARD_ITEM>( pad );
} }
void PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit ) override
{
auto pad = dynamic_cast<D_PAD*>( aItem );
m_frame->Export_Pad_Settings( pad );
aCommit.Add( aItem );
}
}; };
PAD_PLACER placer; PAD_PLACER placer;

View File

@ -180,8 +180,7 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer,
if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) ) if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
{ {
const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
*frame(), *evt );
newItem->Rotate( newItem->GetPosition(), rotationAngle ); newItem->Rotate( newItem->GetPosition(), rotationAngle );
view()->Update( &preview ); view()->Update( &preview );
} }