diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 834591c9be..22218fc239 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -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 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 { EDA_RECT bBox; diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index eb51cfe143..cc2743ddd3 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -176,6 +176,8 @@ public: bool operator==( const LIB_ALIAS* aAlias ) const { return this == aAlias; } + void ViewGetLayers( int aLayers[], int& aCount ) const override; + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } #endif @@ -329,6 +331,8 @@ public: wxArrayString& GetFootprints() { return m_FootprintList; } + void ViewGetLayers( int aLayers[], int& aCount ) const override; + /** * Get the bounding box for the symbol. * diff --git a/eeschema/lib_draw_item.cpp b/eeschema/lib_draw_item.cpp index 806ece92bf..381ce9b392 100644 --- a/eeschema/lib_draw_item.cpp +++ b/eeschema/lib_draw_item.cpp @@ -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() { return GetLayerColor( LAYER_DEVICE ); diff --git a/eeschema/lib_draw_item.h b/eeschema/lib_draw_item.h index b69b7735d9..2d0e4f03f7 100644 --- a/eeschema/lib_draw_item.h +++ b/eeschema/lib_draw_item.h @@ -219,6 +219,8 @@ public: return (LIB_PART *)m_Parent; } + void ViewGetLayers( int aLayers[], int& aCount ) const override; + virtual bool HitTest( const wxPoint& aPosition ) const override { return EDA_ITEM::HitTest( aPosition ); diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index 144f8ddcd2..715ffb44a2 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -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 ) { - case REFERENCE: - color = GetLayerColor( LAYER_REFERENCEPART ); - break; - - case VALUE: - color = GetLayerColor( LAYER_VALUEPART ); - break; - - default: - color = GetLayerColor( LAYER_FIELDS ); - break; + case REFERENCE: aLayers[0] = LAYER_REFERENCEPART; break; + case VALUE: aLayers[0] = LAYER_VALUEPART; break; + default: aLayers[0] = 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 ); + } } diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 6e863db96a..6fef8b8cbe 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -158,6 +158,8 @@ public: return m_Text.IsEmpty(); } + void ViewGetLayers( int aLayers[], int& aCount ) const override; + /** * @return true is this field is visible, false if flagged invisible */ diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index a20f188dee..cf037fe297 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -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 { return HitTest( aPosition, 0, DefaultTransform ); diff --git a/eeschema/lib_text.h b/eeschema/lib_text.h index 78acc2aae6..a167083857 100644 --- a/eeschema/lib_text.h +++ b/eeschema/lib_text.h @@ -70,6 +70,8 @@ public: return _( "Text" ); } + void ViewGetLayers( int aLayers[], int& aCount ) const override; + /** * Sets the text item string to \a aText. * diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index 9e42882f15..be6091e571 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -1742,17 +1742,12 @@ void LIB_EDIT_FRAME::SetScreen( BASE_SCREEN* aScreen ) void LIB_EDIT_FRAME::RebuildView() { - KIGFX::SCH_VIEW* view = GetCanvas()->GetView(); - - view->Clear(); - GetRenderSettings()->m_ShowUnit = m_unit; GetRenderSettings()->m_ShowConvert = m_convert; + GetCanvas()->DisplayComponent( m_my_part ); - view->DisplayComponent( m_my_part ); - - view->HideWorksheet(); - view->ClearHiddenFlags(); + GetCanvas()->GetView()->HideWorksheet(); + GetCanvas()->GetView()->ClearHiddenFlags(); GetCanvas()->Refresh(); } diff --git a/eeschema/sch_bus_entry.cpp b/eeschema/sch_bus_entry.cpp index 1cda2a1031..b8f7dd9c2f 100644 --- a/eeschema/sch_bus_entry.cpp +++ b/eeschema/sch_bus_entry.cpp @@ -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 { EDA_RECT box; diff --git a/eeschema/sch_bus_entry.h b/eeschema/sch_bus_entry.h index b7de34d1ee..ad50c418b7 100644 --- a/eeschema/sch_bus_entry.h +++ b/eeschema/sch_bus_entry.h @@ -83,6 +83,8 @@ public: 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, GR_DRAWMODE aDrawMode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override; diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index 5016a73bee..572cbf1d85 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -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 ) { if( m_lib_id != aLibId ) diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index e44e1fc8dd..6cf6dc7ad2 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -153,6 +153,8 @@ public: 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 * and false for items moved with no reference to anchor. diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index 4b36aa4769..b4f3288125 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -40,6 +40,7 @@ using namespace std::placeholders; + // Events used by EDA_DRAW_PANEL // GAL TODO: some (most?) of these need to be implemented... 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 ), m_parent( aParentWindow ) { -#ifdef __WXMAC__ - m_defaultCursor = m_currentCursor = wxCURSOR_CROSS; - m_showCrossHair = false; -#else m_defaultCursor = m_currentCursor = wxCURSOR_ARROW; m_showCrossHair = true; -#endif m_view = new KIGFX::SCH_VIEW( true ); m_view->SetGAL( m_gal ); @@ -143,8 +139,6 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, Show( true ); Raise(); 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() { -/* 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 ); m_view->SetLayerOrder( layer, i ); - }*/ + } } @@ -259,8 +253,6 @@ void SCH_DRAW_PANEL::setDefaultLayerDeps() m_view->SetLayerTarget( LAYER_WORKSHEET , KIGFX::TARGET_NONCACHED ); m_view->SetLayerDisplayOnly( LAYER_WORKSHEET ) ; - - m_view->SetLayerDisplayOnly( LAYER_DRC ); } diff --git a/eeschema/sch_item_struct.cpp b/eeschema/sch_item_struct.cpp index 89dc4711e9..6a42e5b1a8 100644 --- a/eeschema/sch_item_struct.cpp +++ b/eeschema/sch_item_struct.cpp @@ -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 { if( m_Flags & STRUCT_DELETED || m_Flags & SKIP_STRUCT ) diff --git a/eeschema/sch_item_struct.h b/eeschema/sch_item_struct.h index 2e1e187ac1..f434f1e1c2 100644 --- a/eeschema/sch_item_struct.h +++ b/eeschema/sch_item_struct.h @@ -169,6 +169,12 @@ public: */ 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 * @return the size of the "pen" that be used to draw or plot this item diff --git a/eeschema/sch_junction.cpp b/eeschema/sch_junction.cpp index 49799b57b6..3810b83039 100644 --- a/eeschema/sch_junction.cpp +++ b/eeschema/sch_junction.cpp @@ -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 { EDA_RECT rect; diff --git a/eeschema/sch_junction.h b/eeschema/sch_junction.h index 39f54dc73c..5300d964a8 100644 --- a/eeschema/sch_junction.h +++ b/eeschema/sch_junction.h @@ -59,6 +59,8 @@ public: void SwapData( SCH_ITEM* aItem ) override; + void ViewGetLayers( int aLayers[], int& aCount ) const override; + const EDA_RECT GetBoundingBox() const override; void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, diff --git a/eeschema/sch_marker.cpp b/eeschema/sch_marker.cpp index debac65032..6669cfcb6c 100644 --- a/eeschema/sch_marker.cpp +++ b/eeschema/sch_marker.cpp @@ -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 { return GetBoundingBoxMarker(); diff --git a/eeschema/sch_marker.h b/eeschema/sch_marker.h index c364f28448..84c01ad58b 100644 --- a/eeschema/sch_marker.h +++ b/eeschema/sch_marker.h @@ -52,6 +52,8 @@ public: return wxT( "SCH_MARKER" ); } + void ViewGetLayers( int aLayers[], int& aCount ) const override; + void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, GR_DRAWMODE aDraw_mode, COLOR4D aColor = COLOR4D::UNSPECIFIED ) override; diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 830b3ea1fa..0eb174e2fb 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -49,7 +49,7 @@ #include #include #include - +#include #include #include @@ -209,19 +209,16 @@ void SCH_PAINTER::draw( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit 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 ) - return; + continue; if( aUnit && item.GetUnit() && aUnit != item.GetUnit() ) - return; + continue; if( aConvert && item.GetConvert() && aConvert != item.GetConvert() ) - return; + continue; if( item.Type() == LIB_PIN_T ) { @@ -236,18 +233,7 @@ void SCH_PAINTER::draw( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit } else 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 ); @@ -297,8 +283,9 @@ void SCH_PAINTER::setColors( const LIB_ITEM* aItem, bool aBackground ) m_gal->SetFillColor( color ); m_gal->SetIsStroke( false ); + return true; } - else + else if( aLayer == 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->SetFillColor( color ); + return true; } + + return false; } @@ -320,15 +310,8 @@ void SCH_PAINTER::draw( LIB_RECTANGLE *aRect, int aLayer ) if( !isUnitAndConversionShown( aRect ) ) return; - if( aRect->GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) - { - setColors( aRect, true ); + if( setColors( aRect, aLayer ) ) m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) ); - m_gal->AdvanceDepth(); - } - - setColors( aRect, false ); - m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) ); } @@ -338,15 +321,8 @@ void SCH_PAINTER::draw( LIB_CIRCLE *aCircle, int aLayer ) if( !isUnitAndConversionShown( aCircle ) ) return; - if( aCircle->GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) - { - setColors( aCircle, true ); + if( setColors( aCircle, aLayer ) ) m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() ); - m_gal->AdvanceDepth(); - } - - setColors( aCircle, false ); - m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() ); } @@ -366,14 +342,8 @@ void SCH_PAINTER::draw( LIB_ARC *aArc, int aLayer ) VECTOR2D pos = mapCoords( aArc->GetPosition() ); - if( aArc->GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) - { - setColors( aArc, true ); + if( setColors( aArc, aLayer ) ) m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea ); - } - - setColors( aArc, false ); - m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea ); } @@ -382,38 +352,31 @@ void SCH_PAINTER::draw( LIB_POLYLINE *aLine, int aLayer ) if( !isUnitAndConversionShown( aLine ) ) return; - const std::vector& pts = aLine->GetPolyPoints(); std::deque vtx; for( auto p : pts ) vtx.push_back( mapCoords( p ) ); - if( aLine->GetFillMode() == FILLED_WITH_BG_BODYCOLOR ) - { - setColors( aLine, true ); + if( setColors( aLine, aLayer ) ) m_gal->DrawPolygon( vtx ); - m_gal->AdvanceDepth(); - } - - setColors( aLine, false ); - m_gal->DrawPolygon( vtx ); } 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 ) ) return; - COLOR4D color; - - 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; - } + COLOR4D color = aField->GetDefaultColor(); if( aField->IsMoving() ) 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 ) { + if( aLayer != LAYER_DEVICE ) + return; + if( !isUnitAndConversionShown( aPin ) ) return; @@ -1241,58 +1207,70 @@ void SCH_PAINTER::draw( SCH_HIERLABEL *aLabel, 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 size = aSheet->GetSize(); - m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_SHEET ) ); - - if( aSheet->IsMoving() ) // Gives a filled background when moving for a better look + if( aLayer == LAYER_SHEET_BACKGROUND ) { - // Select a fill color working well with black and white background color, - // both in Opengl and Cairo - m_gal->SetFillColor( COLOR4D( 0.1, 0.5, 0.5, 0.3 ) ); - m_gal->SetIsFill( true ); + m_gal->SetIsStroke( false ); + + if( aSheet->IsMoving() ) // Gives a filled background when moving for a better look + { + // Select a fill color working well with black and white background color, + // both in Opengl and Cairo + m_gal->SetFillColor( COLOR4D( 0.1, 0.5, 0.5, 0.3 ) ); + m_gal->SetIsFill( true ); + } + else + { + // Could be modified later, when sheets can have their own fill color + return; + } + + m_gal->DrawRectangle( pos, pos + size ); } - else + else if( aLayer == LAYER_SHEET ) { - // Could be modified later, when sheets can have their own fill color - m_gal->SetIsFill ( false ); + m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_SHEET ) ); + m_gal->SetIsStroke( true ); + + m_gal->SetIsFill( false ); + + m_gal->DrawRectangle( pos, pos + size ); + + VECTOR2D pos_sheetname = aSheet->GetSheetNamePosition(); + VECTOR2D pos_filename = aSheet->GetFileNamePosition(); + double nameAngle = 0.0; + + if( aSheet->IsVerticalOrientation() ) + nameAngle = -M_PI/2; + + m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_SHEETNAME ) ); + + auto text = wxT( "Sheet: " ) + aSheet->GetName(); + + m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); + m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_BOTTOM ); + + auto txtSize = aSheet->GetSheetNameSize(); + + m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) ); + m_gal->SetFontBold( false ); + m_gal->SetFontItalic( false ); + + m_gal->StrokeText( text, pos_sheetname, nameAngle ); + + txtSize = aSheet->GetFileNameSize(); + m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) ); + m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_SHEETFILENAME ) ); + m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_TOP ); + + text = wxT( "File: " ) + aSheet->GetFileName(); + m_gal->StrokeText( text, pos_filename, nameAngle ); + + for( auto& sheetPin : aSheet->GetPins() ) + draw( static_cast( &sheetPin ), aLayer ); } - m_gal->SetIsStroke( true ); - m_gal->DrawRectangle( pos, pos + size ); - - auto nameAngle = 0.0; - - if( aSheet->IsVerticalOrientation() ) - nameAngle = -M_PI/2; - - m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_SHEETNAME ) ); - - auto text = wxT( "Sheet: " ) + aSheet->GetName(); - - m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); - m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_BOTTOM ); - - auto txtSize = aSheet->GetSheetNameSize(); - - m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) ); - m_gal->SetFontBold( false ); - m_gal->SetFontItalic( false ); - - m_gal->StrokeText( text, pos_sheetname, nameAngle ); - - txtSize = aSheet->GetFileNameSize(); - m_gal->SetGlyphSize( VECTOR2D( txtSize, txtSize ) ); - m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_SHEETFILENAME ) ); - m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_TOP ); - - text = wxT( "File: " ) + aSheet->GetFileName(); - m_gal->StrokeText( text, pos_filename, nameAngle ); - - for( auto& sheetPin : aSheet->GetPins() ) - draw( static_cast( &sheetPin ), aLayer ); } diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index 384e6fefa4..95d0691d41 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -151,7 +151,7 @@ private: 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 ); diff --git a/eeschema/sch_preview_panel.cpp b/eeschema/sch_preview_panel.cpp index f18016018a..14c8a6ca9d 100644 --- a/eeschema/sch_preview_panel.cpp +++ b/eeschema/sch_preview_panel.cpp @@ -96,29 +96,32 @@ void SCH_PREVIEW_PANEL::OnShow() 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 ); m_view->SetLayerOrder( layer, i ); - }*/ + } } void SCH_PREVIEW_PANEL::setDefaultLayerDeps() { // 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++ ) m_view->SetLayerTarget( i, target ); m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_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_DRC ); } diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index affd7c8b58..f964522ba3 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -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, const wxPoint& aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor ) { diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h index 0db142b65c..fe8a2523cf 100644 --- a/eeschema/sch_sheet.h +++ b/eeschema/sch_sheet.h @@ -544,6 +544,8 @@ public: SCH_ITEM& operator=( const SCH_ITEM& aSheet ); + void ViewGetLayers( int aLayers[], int& aCount ) const override; + wxPoint GetPosition() const override { return m_pos; } void SetPosition( const wxPoint& aPosition ) override; diff --git a/eeschema/sch_view.cpp b/eeschema/sch_view.cpp index fe598b1ab3..ead07bdd86 100644 --- a/eeschema/sch_view.cpp +++ b/eeschema/sch_view.cpp @@ -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 ) { @@ -186,48 +161,5 @@ void SCH_VIEW::HideWorksheet() } -void SCH_VIEW::Redraw() -{ - std::set 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(); -} - }; diff --git a/eeschema/sch_view.h b/eeschema/sch_view.h index 7da1a60631..c677382167 100644 --- a/eeschema/sch_view.h +++ b/eeschema/sch_view.h @@ -13,6 +13,23 @@ class SCH_SHEET; class SCH_SCREEN; 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 { class VIEW_GROUP; @@ -29,9 +46,6 @@ public: SCH_VIEW( bool aIsDynamic ); ~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_SCREEN *aSheet ); void DisplayComponent( LIB_PART *aPart ); @@ -49,14 +63,11 @@ public: void ClearHiddenFlags(); void HideWorksheet(); - virtual void Redraw() override; - private: std::unique_ptr m_worksheet; std::unique_ptr m_selectionArea; std::unique_ptr m_preview; std::vector m_ownedItems; - std::unordered_map m_cachedBBoxes; }; }; // namespace diff --git a/include/layers_id_colors_and_visibility.h b/include/layers_id_colors_and_visibility.h index cc4efaa029..068b0608f9 100644 --- a/include/layers_id_colors_and_visibility.h +++ b/include/layers_id_colors_and_visibility.h @@ -253,6 +253,7 @@ enum SCH_LAYER_ID: int LAYER_ERC_WARN, LAYER_ERC_ERR, LAYER_DEVICE_BACKGROUND, + LAYER_SHEET_BACKGROUND, LAYER_SCHEMATIC_GRID, LAYER_SCHEMATIC_BACKGROUND, LAYER_SCHEMATIC_CURSOR, diff --git a/pcbnew/tools/footprint_editor_tools.cpp b/pcbnew/tools/footprint_editor_tools.cpp index 4ca0807dda..6476ba2c11 100644 --- a/pcbnew/tools/footprint_editor_tools.cpp +++ b/pcbnew/tools/footprint_editor_tools.cpp @@ -107,6 +107,13 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) pad->IncrementPadName( true, true ); return std::unique_ptr( pad ); } + + void PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit ) override + { + auto pad = dynamic_cast( aItem ); + m_frame->Export_Pad_Settings( pad ); + aCommit.Add( aItem ); + } }; PAD_PLACER placer; diff --git a/pcbnew/tools/pcb_tool.cpp b/pcbnew/tools/pcb_tool.cpp index 9d6900f427..fd1dfa4492 100644 --- a/pcbnew/tools/pcb_tool.cpp +++ b/pcbnew/tools/pcb_tool.cpp @@ -180,8 +180,7 @@ void PCB_TOOL::doInteractiveItemPlacement( INTERACTIVE_PLACER_BASE* aPlacer, if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) ) { - const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( - *frame(), *evt ); + const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt ); newItem->Rotate( newItem->GetPosition(), rotationAngle ); view()->Update( &preview ); }