From d73d15366562e30386269a768ed12e4ba1c76873 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 9 Aug 2013 15:04:10 +0200 Subject: [PATCH] Added selection boxes for texts. --- pcbnew/class_pcb_text.cpp | 12 ++++ pcbnew/class_pcb_text.h | 9 ++- pcbnew/class_text_mod.cpp | 5 +- pcbnew/class_text_mod.h | 1 - pcbnew/pcb_painter.cpp | 104 ++++++++++++++++++---------------- pcbnew/pcb_painter.h | 5 +- pcbnew/tools/selection_tool.h | 4 +- 7 files changed, 82 insertions(+), 58 deletions(-) diff --git a/pcbnew/class_pcb_text.cpp b/pcbnew/class_pcb_text.cpp index 4ff4c02b88..2ce86606aa 100644 --- a/pcbnew/class_pcb_text.cpp +++ b/pcbnew/class_pcb_text.cpp @@ -223,3 +223,15 @@ const BOX2I TEXTE_PCB::ViewBBox() const return BOX2I( rect.GetOrigin(), rect.GetSize() ); } } + + +void TEXTE_PCB::ViewGetLayers( int aLayers[], int& aCount ) const +{ + // Layer that simply displays the text + aLayers[0] = m_Layer; + + // On the general purpose overlay there is a selection box displayed + aLayers[1] = ITEM_GAL_LAYER( GP_OVERLAY ); + + aCount = 2; +} diff --git a/pcbnew/class_pcb_text.h b/pcbnew/class_pcb_text.h index d947cd05c9..4bf5395b63 100644 --- a/pcbnew/class_pcb_text.h +++ b/pcbnew/class_pcb_text.h @@ -121,12 +121,15 @@ public: EDA_ITEM* Clone() const; + /// @copydoc VIEW_ITEM::ViewBBox() + virtual const BOX2I ViewBBox() const; + + /// @copydoc VIEW_ITEM::ViewGetLayers() + virtual void ViewGetLayers( int aLayers[], int& aCount ) const; + #if defined(DEBUG) virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override #endif - - /// @copydoc VIEW_ITEM::ViewBBox() - virtual const BOX2I ViewBBox() const; }; #endif // #define CLASS_PCB_TEXT_H diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index 4ecfc2767a..d84cac4860 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -456,5 +456,8 @@ void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const break; } - aCount = 1; + // On the general purpose overlay there is a selection box displayed + aLayers[1] = ITEM_GAL_LAYER( GP_OVERLAY ); + + aCount = 2; } diff --git a/pcbnew/class_text_mod.h b/pcbnew/class_text_mod.h index 31e2e6d3d2..42add84304 100644 --- a/pcbnew/class_text_mod.h +++ b/pcbnew/class_text_mod.h @@ -142,7 +142,6 @@ public: return wxT( "MTEXT" ); } - wxString GetSelectMenuText() const; BITMAP_DEF GetMenuImage() const { return footprint_text_xpm; } diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 6143e24219..11a278e924 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -224,7 +224,7 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) break; case PCB_TEXT_T: - draw( (TEXTE_PCB*) aItem ); + draw( (TEXTE_PCB*) aItem, aLayer ); break; case PCB_MODULE_TEXT_T: @@ -662,65 +662,55 @@ void PCB_PAINTER::draw( const MODULE* aModule ) { // For modules we have to draw a selection box if needed if( aModule->IsSelected() ) - { - BOX2I boundingBox = aModule->ViewBBox(); - - m_gal->SetIsStroke( false ); - m_gal->SetIsFill( true ); - m_gal->SetFillColor( COLOR4D( 1.0, 1.0, 1.0, 0.5 ) ); - m_gal->DrawRectangle( boundingBox.GetOrigin(), boundingBox.GetEnd() ); - } + drawSelectionBox( aModule ); } -void PCB_PAINTER::draw( const TEXTE_PCB* aText ) +void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer ) { - if( aText->GetText().Length() == 0 ) - return; + if( aLayer == ITEM_GAL_LAYER( GP_OVERLAY ) ) + { + if( aText->IsSelected() ) + drawSelectionBox( aText ); + } + else + { + if( aText->GetText().Length() == 0 ) + return; - COLOR4D strokeColor = GetColor( NULL, aText->GetLayer() ); - VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); - double orientation = aText->GetOrientation() * M_PI / 1800.0; + COLOR4D strokeColor = GetColor( NULL, aText->GetLayer() ); + VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); + double orientation = aText->GetOrientation() * M_PI / 1800.0; - m_gal->SetStrokeColor( strokeColor ); - m_gal->SetLineWidth( aText->GetThickness() ); - m_gal->SetTextAttributes( aText ); - m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); + m_gal->SetStrokeColor( strokeColor ); + m_gal->SetLineWidth( aText->GetThickness() ); + m_gal->SetTextAttributes( aText ); + m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); + } } void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer ) { - if( aText->GetLength() == 0 ) - return; - - COLOR4D strokeColor = GetColor( NULL, aLayer ); - VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y); - double orientation = aText->GetDrawRotation() * M_PI / 1800.0; - - m_gal->PushDepth(); - - /*if(aText->IsSelected()) + if( aLayer == ITEM_GAL_LAYER( GP_OVERLAY ) ) { - EDA_RECT bb (aText->GetBoundingBox()); - VECTOR2D s (bb.GetOrigin()); - VECTOR2D e (bb.GetEnd()); - m_gal->SetFillColor( COLOR4D (1.0, 1.0, 1.0, 0.3) ); - m_gal->SetStrokeColor( COLOR4D (1.0, 1.0, 1.0, 0.5) ); - m_gal->SetIsFill(true); - m_gal->SetIsStroke(true); - m_gal->SetLineWidth(0); - m_gal->DrawRectangle(s, e); - }*/ - - m_gal->AdvanceDepth(); + if( aText->IsSelected() ) + drawSelectionBox( aText ); + } + else + { + if( aText->GetLength() == 0 ) + return; - m_gal->SetStrokeColor( strokeColor ); - m_gal->SetLineWidth( aText->GetThickness() ); - m_gal->SetTextAttributes( aText ); - m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); + COLOR4D strokeColor = GetColor( NULL, aLayer ); + VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y); + double orientation = aText->GetDrawRotation() * M_PI / 1800.0; - m_gal->PopDepth(); + m_gal->SetStrokeColor( strokeColor ); + m_gal->SetLineWidth( aText->GetThickness() ); + m_gal->SetTextAttributes( aText ); + m_gal->StrokeText( std::string( aText->GetText().mb_str() ), position, orientation ); + } } @@ -796,7 +786,8 @@ void PCB_PAINTER::draw( const ZONE_CONTAINER* aZone ) void PCB_PAINTER::draw( const DIMENSION* aDimension ) { - COLOR4D strokeColor = GetColor( NULL, aDimension->GetLayer() ); + int layer = aDimension->GetLayer(); + COLOR4D strokeColor = GetColor( NULL, layer ); m_gal->SetStrokeColor( strokeColor ); m_gal->SetIsFill( false ); @@ -805,15 +796,17 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension ) // Draw an arrow m_gal->DrawLine( VECTOR2D( aDimension->m_crossBarO ), VECTOR2D( aDimension->m_crossBarF ) ); - m_gal->DrawLine( VECTOR2D( aDimension->m_featureLineGO ), VECTOR2D( aDimension->m_featureLineGF ) ); - m_gal->DrawLine( VECTOR2D( aDimension->m_featureLineDO ), VECTOR2D( aDimension->m_featureLineDF ) ); + m_gal->DrawLine( VECTOR2D( aDimension->m_featureLineGO ), + VECTOR2D( aDimension->m_featureLineGF ) ); + m_gal->DrawLine( VECTOR2D( aDimension->m_featureLineDO ), + VECTOR2D( aDimension->m_featureLineDF ) ); m_gal->DrawLine( VECTOR2D( aDimension->m_arrowD1O ), VECTOR2D( aDimension->m_arrowD1F ) ); m_gal->DrawLine( VECTOR2D( aDimension->m_arrowD2O ), VECTOR2D( aDimension->m_arrowD2F ) ); m_gal->DrawLine( VECTOR2D( aDimension->m_arrowG1O ), VECTOR2D( aDimension->m_arrowG1F ) ); m_gal->DrawLine( VECTOR2D( aDimension->m_arrowG2O ), VECTOR2D( aDimension->m_arrowG2F ) ); // Draw text - draw( &aDimension->Text() ); + draw( &aDimension->Text(), layer ); } @@ -853,3 +846,14 @@ void PCB_PAINTER::draw( const PCB_TARGET* aTarget ) m_gal->Restore(); } + + +void PCB_PAINTER::drawSelectionBox( const VIEW_ITEM* aItem ) const +{ + BOX2I boundingBox = aItem->ViewBBox(); + + m_gal->SetIsStroke( false ); + m_gal->SetIsFill( true ); + m_gal->SetFillColor( COLOR4D( 1.0, 1.0, 1.0, 0.5 ) ); + m_gal->DrawRectangle( boundingBox.GetOrigin(), boundingBox.GetEnd() ); +} diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index 3c220ee164..14ae4e156e 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -142,11 +142,14 @@ protected: void draw( const D_PAD*, int ); void draw( const DRAWSEGMENT* ); void draw( const MODULE* ); - void draw( const TEXTE_PCB* ); + void draw( const TEXTE_PCB*, int ); void draw( const TEXTE_MODULE*, int ); void draw( const ZONE_CONTAINER* ); void draw( const DIMENSION* ); void draw( const PCB_TARGET* ); + + /// Draws a white semitransparent box indicating an item as selected + void drawSelectionBox( const VIEW_ITEM* aItem ) const; }; } // namespace KiGfx diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 7072cc3cdd..bec3a8a871 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -50,8 +50,8 @@ class GENERAL_COLLECTOR; class SELECTION_TOOL : public TOOL_INTERACTIVE { public: - SELECTION_TOOL (); - ~SELECTION_TOOL (); + SELECTION_TOOL(); + ~SELECTION_TOOL(); void Reset(); int Main( TOOL_EVENT& aEvent );