From f1b36209b130b8f5da5423c8a2aedd2f42599868 Mon Sep 17 00:00:00 2001 From: dickelbeck Date: Tue, 1 Apr 2008 06:07:00 +0000 Subject: [PATCH] DRAWSEGMENT::Draw() --- gerbview/trpiste.cpp | 97 +-------------------------------- include/base_struct.h | 4 +- pcbnew/block.cpp | 9 ++-- pcbnew/class_board.h | 7 +++ pcbnew/class_drawsegment.cpp | 100 ++++++++++++++++++++++++++++++++++ pcbnew/class_drawsegment.h | 11 ++-- pcbnew/class_equipot.h | 29 ++++++---- pcbnew/tracepcb.cpp | 11 ++-- pcbnew/trpiste.cpp | 101 ++--------------------------------- 9 files changed, 149 insertions(+), 220 deletions(-) diff --git a/gerbview/trpiste.cpp b/gerbview/trpiste.cpp index 3c623b17d9..b7c7bd7ab6 100644 --- a/gerbview/trpiste.cpp +++ b/gerbview/trpiste.cpp @@ -221,103 +221,10 @@ void Trace_Segment( WinEDA_DrawPanel* panel, wxDC* DC, TRACK* track, int draw_mo void Trace_DrawSegmentPcb( WinEDA_DrawPanel* panel, wxDC* DC, DRAWSEGMENT* PtDrawSegment, int draw_mode ) /**************************************************************************/ - -/* Affichage d'un segment type drawing PCB: - * Entree : ox, oy = offset de trace - * draw_mode = mode de trace ( GR_OR, GR_XOR, GrAND) - * Les contours sont de differents type: - * segment - * cercle - * arc - */ { - int ux0, uy0, dx, dy; - int l_piste; - int color, mode; - int zoom = panel->GetZoom(); - int rayon; - - color = g_DesignSettings.m_LayerColor[PtDrawSegment->GetLayer()]; - if( color & ITEM_NOT_SHOW ) - return; - - GRSetDrawMode( DC, draw_mode ); - l_piste = PtDrawSegment->m_Width >> 1; /* l_piste = demi largeur piste */ - - /* coord de depart */ - ux0 = PtDrawSegment->m_Start.x; - uy0 = PtDrawSegment->m_Start.y; - - /* coord d'arrivee */ - dx = PtDrawSegment->m_End.x; - dy = PtDrawSegment->m_End.y; - - mode = DisplayOpt.DisplayPcbTrackFill ? FILLED : SKETCH; - - if( PtDrawSegment->m_Flags & FORCE_SKETCH ) - mode = SKETCH; - - if( l_piste < (L_MIN_DESSIN * zoom) ) - mode = FILAIRE; - - switch( PtDrawSegment->m_Shape ) - { - case S_CIRCLE: - rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); - if( mode == FILAIRE ) - { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, 0, color ); - } - else if( mode == SKETCH ) - { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon - l_piste, 0, color ); - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon + l_piste, 0, color ); - } - else - { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, PtDrawSegment->m_Width, color ); - } - break; - - case S_ARC: - { - int StAngle, EndAngle; - rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); - StAngle = (int) ArcTangente( dy - uy0, dx - ux0 ); - EndAngle = StAngle + PtDrawSegment->m_Angle; - if( mode == FILAIRE ) - GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, rayon, 0, color ); - else if( mode == SKETCH ) - { - GRArc( &panel->m_ClipBox, DC, ux0, uy0, 0, StAngle, EndAngle, - rayon - l_piste, color ); - GRArc( &panel->m_ClipBox, DC, ux0, uy0, 0, StAngle, EndAngle, - rayon + l_piste, color ); - } - else - { - GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon, PtDrawSegment->m_Width, color ); - } - } - break; + // @todo Replace all calls to Trace_DrawSegmentPcb() with this call: - - default: - if( mode == FILAIRE ) - GRLine( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, 0, color ); - else if( mode == SKETCH ) - { - GRCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, - PtDrawSegment->m_Width, color ); - } - else - { - GRFillCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, - PtDrawSegment->m_Width, color ); - } - break; - } + PtDrawSegment->Draw( panel, DC, draw_mode ); } diff --git a/include/base_struct.h b/include/base_struct.h index d7ec4d539f..3a80fdae0d 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -612,9 +612,7 @@ public: * BOARD_ITEMs which have their own color information. */ virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, - int aDrawMode, const wxPoint& offset = ZeroOffset ) - { - } + int aDrawMode, const wxPoint& offset = ZeroOffset ) = 0; /** diff --git a/pcbnew/block.cpp b/pcbnew/block.cpp index 256828b3c8..ace3372a46 100644 --- a/pcbnew/block.cpp +++ b/pcbnew/block.cpp @@ -503,12 +503,11 @@ void WinEDA_BasePcbFrame::Block_Delete( wxDC* DC ) switch( PtStruct->Type() ) { case TYPEDRAWSEGMENT: - #undef STRUCT - #define STRUCT ( (DRAWSEGMENT*) PtStruct ) - if( (g_TabOneLayerMask[STRUCT->GetLayer()] & masque_layer) == 0 ) + if( (g_TabOneLayerMask[PtStruct->GetLayer()] & masque_layer) == 0 ) break; if( ! PtStruct->HitTest( GetScreen()->BlockLocate ) ) break; + /* l'element est ici bon a etre efface */ Trace_DrawSegmentPcb( DrawPanel, DC, (DRAWSEGMENT*) PtStruct, GR_XOR ); PtStruct->DeleteStructure(); @@ -526,7 +525,7 @@ void WinEDA_BasePcbFrame::Block_Delete( wxDC* DC ) break; case TYPEMIRE: - if( (g_TabOneLayerMask[STRUCT->GetLayer()] & masque_layer) == 0 ) + if( (g_TabOneLayerMask[PtStruct->GetLayer()] & masque_layer) == 0 ) break; if( ! PtStruct->HitTest( GetScreen()->BlockLocate ) ) break; @@ -535,7 +534,7 @@ void WinEDA_BasePcbFrame::Block_Delete( wxDC* DC ) break; case TYPECOTATION: - if( (g_TabOneLayerMask[STRUCT->GetLayer()] & masque_layer) == 0 ) + if( (g_TabOneLayerMask[PtStruct->GetLayer()] & masque_layer) == 0 ) break; if( ! PtStruct->HitTest( GetScreen()->BlockLocate ) ) break; diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 9d4497c13f..fc55048c37 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -252,6 +252,13 @@ public: */ void Display_Infos( WinEDA_DrawFrame* frame ); + void Draw( WinEDA_DrawPanel* panel, wxDC* DC, + int aDrawMode, const wxPoint& offset = ZeroOffset ) + { + // void WinEDA_PcbFrame::Trace_Pcb( wxDC* DC, int mode ) + // goes here. + } + /** * Function Visit diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index 4862090f43..65ec934f3f 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -144,6 +144,106 @@ bool DRAWSEGMENT::ReadDrawSegmentDescr( FILE* File, int* LineNum ) } +void DRAWSEGMENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC, + int draw_mode, const wxPoint& notUsed ) +{ + int ux0, uy0, dx, dy; + int l_piste; + int color, mode; + int zoom; + int rayon; + + color = g_DesignSettings.m_LayerColor[GetLayer()]; + if( color & ITEM_NOT_SHOW ) + return; + + if( panel ) + zoom = panel->GetZoom(); + else + zoom = ActiveScreen->GetZoom(); + + GRSetDrawMode( DC, draw_mode ); + l_piste = m_Width >> 1; /* l_piste = demi largeur piste */ + + /* coord de depart */ + ux0 = m_Start.x; + uy0 = m_Start.y; + + /* coord d'arrivee */ + dx = m_End.x; + dy = m_End.y; + + mode = DisplayOpt.DisplayDrawItems; + if( m_Flags & FORCE_SKETCH ) + mode = SKETCH; + if( l_piste < (L_MIN_DESSIN * zoom) ) + mode = FILAIRE; + + switch( m_Shape ) + { + case S_CIRCLE: + rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); + if( mode == FILAIRE ) + { + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, color ); + } + else if( mode == SKETCH ) + { + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon - l_piste, color ); + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon + l_piste, color ); + } + else + { + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, m_Width, color ); + } + break; + + case S_ARC: + { + int StAngle, EndAngle; + rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); + StAngle = (int) ArcTangente( dy - uy0, dx - ux0 ); + EndAngle = StAngle + m_Angle; + + if( StAngle > EndAngle ) + EXCHG( StAngle, EndAngle ); + + if( mode == FILAIRE ) + GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, rayon, color ); + + else if( mode == SKETCH ) + { + GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, + rayon - l_piste, color ); + GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, + rayon + l_piste, color ); + } + else + { + GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, + rayon, m_Width, color ); + } + } + break; + + default: + if( mode == FILAIRE ) + GRLine( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, 0, color ); + else if( mode == SKETCH ) + { + GRCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, + m_Width, color ); + } + else + { + GRFillCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, + m_Width, color ); + } + break; + } +} + + // see pcbstruct.h void DRAWSEGMENT::Display_Infos( WinEDA_DrawFrame* frame ) { diff --git a/pcbnew/class_drawsegment.h b/pcbnew/class_drawsegment.h index 46d9570570..e5feb57181 100644 --- a/pcbnew/class_drawsegment.h +++ b/pcbnew/class_drawsegment.h @@ -49,6 +49,9 @@ public: void Copy( DRAWSEGMENT* source ); + void Draw( WinEDA_DrawPanel* panel, wxDC* DC, + int aDrawMode, const wxPoint& offset = ZeroOffset ); + /** * Function Display_Infos * has knowledge about the frame and how and where to put status information @@ -86,11 +89,11 @@ public: return wxT( "DRAWSEGMENT" ); } - -#if defined(DEBUG) + +#if defined(DEBUG) void Show( int nestLevel, std::ostream& os ); -#endif - +#endif + }; diff --git a/pcbnew/class_equipot.h b/pcbnew/class_equipot.h index e9e4bc9d4c..65ffb6a000 100644 --- a/pcbnew/class_equipot.h +++ b/pcbnew/class_equipot.h @@ -33,13 +33,13 @@ public: /** * Function GetPosition * returns the position of this object. - * @return wxPoint& - The position of this object, non-const so it + * @return wxPoint& - The position of this object, non-const so it * can be changed * A dummy to satisfy pure virtual BOARD::GetPosition() */ wxPoint& GetPosition(); - - + + /* Effacement memoire de la structure */ void UnLink(); @@ -51,18 +51,25 @@ public: * writes the data structures for this object out to a FILE in "*.brd" format. * @param aFile The FILE to write to. * @return bool - true if success writing else false. - */ + */ bool Save( FILE* aFile ) const; - - + + + void Draw( WinEDA_DrawPanel* panel, wxDC* DC, + int aDrawMode, const wxPoint& offset = ZeroOffset ) + { + // @todo we actually could show a NET, simply show all the tracks and pads + } + + /** * Function GetNet * @return int - the netcode */ int GetNet() const { return m_NetCode; } void SetNet( int aNetCode ) { m_NetCode = aNetCode; } - - + + /** * Function GetClass * returns the class name. @@ -73,17 +80,17 @@ public: return wxT("NET"); } - + #if defined(DEBUG) /** * Function Show * is used to output the object tree, currently for debugging only. - * @param nestLevel An aid to prettier tree indenting, and is the level + * @param nestLevel An aid to prettier tree indenting, and is the level * of nesting of this object within the overall tree. * @param os The ostream& to output to. */ virtual void Show( int nestLevel, std::ostream& os ); #endif - + }; diff --git a/pcbnew/tracepcb.cpp b/pcbnew/tracepcb.cpp index 7cd9c9168b..9e3f933fef 100644 --- a/pcbnew/tracepcb.cpp +++ b/pcbnew/tracepcb.cpp @@ -101,6 +101,12 @@ void WinEDA_PcbFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) #define DRAW_CUR_LAYER_LAST 1 +/* should make the function below this one: +void BOARD::Draw( WinEDA_DrawPanel* panel, wxDC* DC, + int aDrawMode, const wxPoint& offset = ZeroOffset ); +*/ + + /****************************************************/ void WinEDA_PcbFrame::Trace_Pcb( wxDC* DC, int mode ) /****************************************************/ @@ -149,13 +155,10 @@ void WinEDA_PcbFrame::Trace_Pcb( wxDC* DC, int mode ) case TYPECOTATION: case TYPETEXTE: case TYPEMIRE: + case TYPEDRAWSEGMENT: item->Draw( DrawPanel, DC, mode ); break; - case TYPEDRAWSEGMENT: - Trace_DrawSegmentPcb( DrawPanel, DC, (DRAWSEGMENT*) item, mode ); - break; - default: break; } diff --git a/pcbnew/trpiste.cpp b/pcbnew/trpiste.cpp index aa609b5f7c..f983460311 100644 --- a/pcbnew/trpiste.cpp +++ b/pcbnew/trpiste.cpp @@ -62,104 +62,9 @@ void Trace_Une_Piste( WinEDA_DrawPanel* panel, wxDC* DC, TRACK* Track, void Trace_DrawSegmentPcb( WinEDA_DrawPanel* panel, wxDC* DC, DRAWSEGMENT* PtDrawSegment, int draw_mode ) /*************************************************************/ - -/* Affichage d'un segment type drawing PCB: - * draw_mode = mode de trace ( GR_OR, GR_XOR, GrAND) - * Les contours sont de differents type: - * segment - * cercle - * arc - */ { - int ux0, uy0, dx, dy; - int l_piste; - int color, mode; - int zoom; - int rayon; - - color = g_DesignSettings.m_LayerColor[PtDrawSegment->GetLayer()]; - if( color & ITEM_NOT_SHOW ) - return; - - if( panel ) - zoom = panel->GetZoom(); - else - zoom = ActiveScreen->GetZoom(); - - GRSetDrawMode( DC, draw_mode ); - l_piste = PtDrawSegment->m_Width >> 1; /* l_piste = demi largeur piste */ - - /* coord de depart */ - ux0 = PtDrawSegment->m_Start.x; - uy0 = PtDrawSegment->m_Start.y; - - /* coord d'arrivee */ - dx = PtDrawSegment->m_End.x; - dy = PtDrawSegment->m_End.y; - - mode = DisplayOpt.DisplayDrawItems; - if( PtDrawSegment->m_Flags & FORCE_SKETCH ) - mode = SKETCH; - if( l_piste < (L_MIN_DESSIN * zoom) ) - mode = FILAIRE; + // @todo Replace all calls to Trace_DrawSegmentPcb() with this call: - switch( PtDrawSegment->m_Shape ) - { - case S_CIRCLE: - rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); - if( mode == FILAIRE ) - { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, color ); - } - else if( mode == SKETCH ) - { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon - l_piste, color ); - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon + l_piste, color ); - } - else - { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, PtDrawSegment->m_Width, color ); - } - break; - - case S_ARC: - { - int StAngle, EndAngle; - rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); - StAngle = (int) ArcTangente( dy - uy0, dx - ux0 ); - EndAngle = StAngle + PtDrawSegment->m_Angle; - if( StAngle > EndAngle ) - EXCHG( StAngle, EndAngle ); - if( mode == FILAIRE ) - GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, rayon, color ); - else if( mode == SKETCH ) - { - GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon - l_piste, color ); - GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon + l_piste, color ); - } - else - { - GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon, PtDrawSegment->m_Width, color ); - } - } - break; - - default: - if( mode == FILAIRE ) - GRLine( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, 0, color ); - else if( mode == SKETCH ) - { - GRCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, - PtDrawSegment->m_Width, color ); - } - else - { - GRFillCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, - PtDrawSegment->m_Width, color ); - } - break; - } + PtDrawSegment->Draw( panel, DC, draw_mode ); } +