From c1e1da1f2bec2c71849db5abcbabab6118c00dd9 Mon Sep 17 00:00:00 2001 From: charras Date: Tue, 30 Jun 2009 19:21:41 +0000 Subject: [PATCH] Eeschema: added GetPenSize() used in Draw and Plot functions to get the thickness of lines. Work in progress --- eeschema/class_drawsheet.cpp | 8 +++ eeschema/class_drawsheet.h | 10 ++++ eeschema/class_hierarchical_PIN_sheet.cpp | 11 +++- eeschema/class_schematic_items.cpp | 64 +++++++++++++++++++---- eeschema/class_schematic_items.h | 34 ++++++++++++ eeschema/component_class.h | 6 +++ eeschema/plot.cpp | 32 +++--------- include/sch_item_struct.h | 5 ++ 8 files changed, 135 insertions(+), 35 deletions(-) diff --git a/eeschema/class_drawsheet.cpp b/eeschema/class_drawsheet.cpp index 0195fd5d31..036cb8e66b 100644 --- a/eeschema/class_drawsheet.cpp +++ b/eeschema/class_drawsheet.cpp @@ -285,6 +285,14 @@ void DrawSheetStruct::CleanupSheet( WinEDA_SchematicFrame* aFrame, bool aRedraw } +/** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ +int DrawSheetStruct::GetPenSize( ) +{ + return g_DrawDefaultLineThickness; +} + /**************************************************************************************/ void DrawSheetStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, diff --git a/eeschema/class_drawsheet.h b/eeschema/class_drawsheet.h index 03301c72a0..11cecba823 100644 --- a/eeschema/class_drawsheet.h +++ b/eeschema/class_drawsheet.h @@ -59,6 +59,11 @@ public: #endif + /** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ + virtual int GetPenSize( ); + /** function CreateGraphicShape * Calculates the graphic shape (a polygon) associated to the text * @param aCorner_list = list to fill with polygon corners coordinates @@ -121,6 +126,11 @@ public: */ void CleanupSheet( WinEDA_SchematicFrame* frame, bool aRedraw ); + /** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ + virtual int GetPenSize( ); + /** Function Draw * Draw the hierarchical sheet shape * @param aPanel = the current DrawPanel diff --git a/eeschema/class_hierarchical_PIN_sheet.cpp b/eeschema/class_hierarchical_PIN_sheet.cpp index 366557705c..bea65366e5 100644 --- a/eeschema/class_hierarchical_PIN_sheet.cpp +++ b/eeschema/class_hierarchical_PIN_sheet.cpp @@ -57,6 +57,15 @@ Hierarchical_PIN_Sheet_Struct* Hierarchical_PIN_Sheet_Struct::GenCopy() } +/** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ +int Hierarchical_PIN_Sheet_Struct::GetPenSize( ) +{ + return g_DrawDefaultLineThickness; +} + + /********************************************************************************************/ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int DrawMode, int Color ) @@ -69,7 +78,7 @@ void Hierarchical_PIN_Sheet_Struct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, con static std::vector Poly; - int LineWidth = g_DrawDefaultLineThickness; + int LineWidth = GetPenSize( ); if( Color >= 0 ) txtcolor = (EDA_Colors) Color; diff --git a/eeschema/class_schematic_items.cpp b/eeschema/class_schematic_items.cpp index 355fa2c804..0028b91a3c 100644 --- a/eeschema/class_schematic_items.cpp +++ b/eeschema/class_schematic_items.cpp @@ -112,11 +112,26 @@ EDA_Rect DrawBusEntryStruct::GetBoundingBox() } +/** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ +int DrawBusEntryStruct::GetPenSize( ) +{ + int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width; + if( m_Layer == LAYER_BUS ) // TODO: find a better way to handle bus thickness + { + pensize = wxRound(pensize * 1.3); + pensize = MAX(pensize, 3); + } + + return pensize; +} + + void DrawBusEntryStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int DrawMode, int Color ) { int color; - int width = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width; if( Color >= 0 ) color = Color; @@ -124,14 +139,8 @@ void DrawBusEntryStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, color = ReturnLayerColor( m_Layer ); GRSetDrawMode( DC, DrawMode ); - if( m_Layer == LAYER_BUS ) // TODO: find a better way to handle bus thickness - { - width = wxRound(width * 1.3); - width = MAX(width, 3); - } - GRLine( &panel->m_ClipBox, DC, m_Pos.x + offset.x, m_Pos.y + offset.y, - m_End().x + offset.x, m_End().y + offset.y, width, color ); + m_End().x + offset.x, m_End().y + offset.y, GetPenSize( ), color ); } @@ -203,6 +212,15 @@ bool DrawJunctionStruct::HitTest( const wxPoint& aPosRef ) } +/** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + * has no meaning for DrawJunctionStruct + */ +int DrawJunctionStruct::GetPenSize( ) +{ + return 0; +} + /***************************************************************************** * Routine to redraw connection struct. * *****************************************************************************/ @@ -303,6 +321,14 @@ bool DrawNoConnectStruct::Save( FILE* aFile ) const } +/** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ +int DrawNoConnectStruct::GetPenSize( ) +{ + return g_DrawDefaultLineThickness; +} + void DrawNoConnectStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int DrawMode, int Color ) { @@ -577,11 +603,20 @@ bool EDA_DrawLineStruct::Save( FILE* aFile ) const } +/** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ +int EDA_DrawLineStruct::GetPenSize( ) +{ + int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width; + return pensize; +} + void EDA_DrawLineStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int DrawMode, int Color ) { int color; - int width = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width; + int width = GetPenSize( ); if( Color >= 0 ) color = Color; @@ -687,11 +722,20 @@ bool DrawPolylineStruct::Save( FILE* aFile ) const } +/** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ +int DrawPolylineStruct::GetPenSize( ) +{ + int pensize = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width; + return pensize; +} + void DrawPolylineStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int DrawMode, int Color ) { int color; - int width = (m_Width == 0) ? g_DrawDefaultLineThickness : m_Width; + int width = GetPenSize( ); if( Color >= 0 ) color = Color; diff --git a/eeschema/class_schematic_items.h b/eeschema/class_schematic_items.h index 26d9a5bde4..c852595aac 100644 --- a/eeschema/class_schematic_items.h +++ b/eeschema/class_schematic_items.h @@ -78,6 +78,11 @@ public: */ bool Save( FILE* aFile ) const; + /** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ + virtual int GetPenSize( ); + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ); #endif @@ -116,6 +121,12 @@ public: */ bool Save( FILE* aFile ) const; + /** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + * for a marker, has no meaning, but it is necessary to satisfy the SCH_ITEM class requirements + */ + virtual int GetPenSize( ) { return 0; }; + #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ); #endif @@ -137,6 +148,12 @@ public: DrawNoConnectStruct* GenCopy(); + + /** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ + virtual int GetPenSize( ); + virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode, int Color = -1 ); @@ -197,6 +214,12 @@ public: bool Save( FILE* aFile ) const; EDA_Rect GetBoundingBox(); + + /** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ + virtual int GetPenSize( ); + }; class DrawPolylineStruct : public SCH_ITEM /* Polyligne (serie de segments) */ @@ -242,6 +265,12 @@ public: */ unsigned GetCornerCount() const { return m_PolyPoints.size(); } + + /** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ + virtual int GetPenSize( ); + }; @@ -270,6 +299,11 @@ public: DrawJunctionStruct* GenCopy(); + /** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + */ + virtual int GetPenSize( ); + virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode, int Color = -1 ); diff --git a/eeschema/component_class.h b/eeschema/component_class.h index f2e70ba22d..47cda596a0 100644 --- a/eeschema/component_class.h +++ b/eeschema/component_class.h @@ -279,6 +279,12 @@ public: void SetUnitSelection( DrawSheetPath* aSheet, int aUnitSelection ); + /** Function GetPenSize + * @return the size of the "pen" that be used to draw or plot this item + * for a component, has no meaning, but it is necessary to satisfy the SCH_ITEM class requirements + */ + virtual int GetPenSize( ) { return 0; } + #if defined (DEBUG) /** diff --git a/eeschema/plot.cpp b/eeschema/plot.cpp index ebf1b577b0..51fb503c95 100644 --- a/eeschema/plot.cpp +++ b/eeschema/plot.cpp @@ -38,7 +38,7 @@ static void PlotNoConnectStruct( Plotter* plotter, DrawNoConnectStruct* Struct ) pX = Struct->m_Pos.x; pY = Struct->m_Pos.y; - plotter->set_current_line_width( -1 ); + plotter->set_current_line_width( Struct->GetPenSize( ) ); plotter->move_to( wxPoint( pX - DELTA, pY - DELTA ) ); plotter->finish_to( wxPoint( pX + DELTA, pY + DELTA ) ); plotter->move_to( wxPoint( pX + DELTA, pY - DELTA ) ); @@ -126,9 +126,7 @@ static void PlotLibPart( Plotter* plotter, SCH_COMPONENT* DrawLibItem ) * transformation matrix causes xy axes to be flipped. */ t1 = (TransMat[0][0] != 0) ^ (Text->m_Orient != 0); pos = TransformCoordinate( TransMat, Text->m_Pos ) + DrawLibItem->m_Pos; - int thickness = (Text->m_Width == 0) ? g_DrawDefaultLineThickness : Text->m_Width; - thickness = Clamp_Text_PenSize( thickness, Text->m_Size, Text->m_Bold ); - + int thickness = Text->GetPenSize( ); plotter->text( pos, CharColor, Text->m_Text, t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT, @@ -167,8 +165,9 @@ static void PlotLibPart( Plotter* plotter, SCH_COMPONENT* DrawLibItem ) pos = TransformCoordinate( TransMat, Pin->m_Pos ) + DrawLibItem->m_Pos; /* Dessin de la pin et du symbole special associe */ + int thickness = Pin->GetPenSize(); + plotter->set_current_line_width( thickness ); PlotPinSymbol( plotter, pos, Pin->m_PinLen, orient, Pin->m_PinShape ); - int thickness = g_DrawDefaultLineThickness; Pin->PlotPinTexts( plotter, pos, orient, Entry->m_TextInside, Entry->m_DrawPinNum, Entry->m_DrawPinName, @@ -414,8 +413,6 @@ static void PlotPinSymbol( Plotter* plotter, const wxPoint& pos, plotter->set_color( color ); - plotter->set_current_line_width( -1 ); - MapX1 = MapY1 = 0; x1 = pos.x; y1 = pos.y; switch( orient ) @@ -607,12 +604,7 @@ static void Plot_Hierarchical_PIN_Sheet( Plotter* plotter, side = GR_TEXT_HJUSTIFY_LEFT; } - int thickness = - (aHierarchical_PIN->m_Width == - 0) ? g_DrawDefaultLineThickness : aHierarchical_PIN->m_Width; - thickness = Clamp_Text_PenSize( thickness, - aHierarchical_PIN->m_Size, - aHierarchical_PIN->m_Bold ); + int thickness = aHierarchical_PIN->GetPenSize( ); plotter->set_current_line_width( thickness ); plotter->text( wxPoint( tposx, posy ), txtcolor, @@ -640,7 +632,7 @@ static void PlotSheetStruct( Plotter* plotter, DrawSheetStruct* Struct ) plotter->set_color( ReturnLayerColor( Struct->m_Layer ) ); - int thickness = g_DrawDefaultLineThickness; + int thickness = Struct->GetPenSize( ); plotter->set_current_line_width( thickness ); plotter->move_to( Struct->m_Pos ); @@ -706,6 +698,7 @@ void PlotDrawlist( Plotter* plotter, SCH_ITEM* drawlist ) int layer; wxPoint StartPos, EndPos; + plotter->set_current_line_width( drawlist->GetPenSize( ) ); switch( drawlist->Type() ) { case DRAW_BUSENTRY_STRUCT_TYPE: /* Struct Raccord et Segment sont identiques */ @@ -732,7 +725,6 @@ void PlotDrawlist( Plotter* plotter, SCH_ITEM* drawlist ) switch( layer ) { case LAYER_NOTES: /* Trace en pointilles */ - plotter->set_current_line_width( g_DrawDefaultLineThickness ); plotter->set_dash( true ); plotter->move_to( StartPos ); plotter->finish_to( EndPos ); @@ -740,18 +732,10 @@ void PlotDrawlist( Plotter* plotter, SCH_ITEM* drawlist ) break; case LAYER_BUS: /* Trait large */ - { - int thickness = wxRound( g_DrawDefaultLineThickness * 2 ); - if( thickness < 3 ) - thickness = 3; - /* We NEED it to be thick, even on HPGL */ - plotter->thick_segment( StartPos, EndPos, thickness, FILLED ); - plotter->set_current_line_width( g_DrawDefaultLineThickness ); - } + plotter->thick_segment( StartPos, EndPos, drawlist->GetPenSize( ), FILLED ); break; default: - plotter->set_current_line_width( g_DrawDefaultLineThickness ); plotter->move_to( StartPos ); plotter->finish_to( EndPos ); break; diff --git a/include/sch_item_struct.h b/include/sch_item_struct.h index cc8eaba8f9..a778f7b36b 100644 --- a/include/sch_item_struct.h +++ b/include/sch_item_struct.h @@ -47,6 +47,11 @@ public: */ void SetLayer( int aLayer ) { m_Layer = aLayer; } + /** Function GetPenSize virtual pure + * @return the size of the "pen" that be used to draw or plot this item + */ + virtual int GetPenSize( ) = 0; + /** * Function Draw */