eeredraw.cpp 8.23 KB
Newer Older
plyatov's avatar
plyatov committed
1
/*****************************************************************************
2 3
*   Program to draw EE diagrams.                                             *
* This module redraw/draw all structs.                                       *
plyatov's avatar
plyatov committed
4 5 6 7 8
*****************************************************************************/

#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
9
#include "class_drawpanel.h"
10
#include "appl_wxstruct.h"
11

plyatov's avatar
plyatov committed
12 13 14
#include "program.h"
#include "general.h"
#include "protos.h"
15 16
#include "class_library.h"

17
#include "build_version.h"
plyatov's avatar
plyatov committed
18

19
static EDA_BaseStruct* HighLightStruct = NULL;
plyatov's avatar
plyatov committed
20

21

22
void DrawDanglingSymbol( WinEDA_DrawPanel* panel, wxDC* DC,
charras's avatar
charras committed
23
                         const wxPoint& pos, int Color )
plyatov's avatar
plyatov committed
24
{
25 26 27
    BASE_SCREEN* screen = panel->GetScreen();

    if( !screen->m_IsPrinting ) /* Draw but do not print the Dangling Symbol */
28 29
    {
        GRRect( &panel->m_ClipBox, DC,
charras's avatar
charras committed
30 31 32
                pos.x - DANGLING_SYMBOL_SIZE, pos.y - DANGLING_SYMBOL_SIZE,
                pos.x + DANGLING_SYMBOL_SIZE, pos.y + DANGLING_SYMBOL_SIZE,
                0, Color );
33
    }
plyatov's avatar
plyatov committed
34 35 36
}


37
void SetHighLightStruct( EDA_BaseStruct* HighLight )
plyatov's avatar
plyatov committed
38
{
39
    HighLightStruct = HighLight;
plyatov's avatar
plyatov committed
40 41
}

42

plyatov's avatar
plyatov committed
43
/*
charras's avatar
charras committed
44
 * Redraws only the active window which is assumed to be whole visible.
45
 */
46
void WinEDA_SchematicFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
plyatov's avatar
plyatov committed
47
{
48 49 50 51 52 53 54 55 56
    wxString title;

    if( GetScreen() == NULL )
        return;

    ActiveScreen = GetScreen();

    DrawPanel->DrawBackGround( DC );

57 58
    RedrawStructList( DrawPanel, DC, GetScreen()->EEDrawList,
                      GR_DEFAULT_DRAWMODE );
59

60
    TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness );
61

62 63
    GetScreen()->ClrRefreshReq();

64 65 66
    if( DrawPanel->ManageCurseur )
        DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );

67
    DrawPanel->DrawCursor( DC );
68 69

    // Display the sheet filename, and the sheet path, for non root sheets
70
    if( GetScreen()->m_FileName == m_DefaultSchematicFileName )
71
    {
72 73
        wxString msg = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
        title.Printf( wxT( "%s [%s]" ), msg.GetData(),
74
                     GetScreen()->m_FileName.GetData() );
75 76 77 78
        SetTitle( title );
    }
    else
    {
79
        title = wxT( "[" );
charras's avatar
charras committed
80
        title << GetScreen()->m_FileName << wxT( "]  " ) << _( "Sheet" );
81
        title << wxT( " " ) << m_CurrentSheet->PathHumanReadable();
82 83
        SetTitle( title );
    }
plyatov's avatar
plyatov committed
84 85
}

86

87 88
/**
 * PrintPage
89 90
 * used to print a page.
 * Print the page pointed by ActiveScreen, set by the calling print function
91 92 93
 * @param aDC = wxDC given by the calling print function
 * @param aPrint_Sheet_Ref = true to print page references
 * @param aPrintMask = not used here
94
 * @param aPrintMirrorMode = not used here (Set when printing in mirror mode)
95
 * @param aData = a pointer on an auxiliary data (not used here)
96
 */
97 98 99
void WinEDA_DrawPanel::PrintPage( wxDC* aDC, bool aPrint_Sheet_Ref,
                                  int aPrintMask, bool aPrintMirrorMode,
                                    void * aData)
plyatov's avatar
plyatov committed
100
{
101
    wxBeginBusyCursor();
plyatov's avatar
plyatov committed
102

103
    RedrawStructList( this, aDC, ActiveScreen->EEDrawList, GR_COPY );
plyatov's avatar
plyatov committed
104

105 106
    if( aPrint_Sheet_Ref )
        m_Parent->TraceWorkSheet( aDC, ActiveScreen, g_DrawDefaultLineThickness );
plyatov's avatar
plyatov committed
107

108
    wxEndBusyCursor();
plyatov's avatar
plyatov committed
109 110 111 112
}


/*****************************************************************************
113 114
* Routine to redraw list of structs.                                         *
* If the list is of DrawPickStruct types then the picked item are drawn.     *
plyatov's avatar
plyatov committed
115
*****************************************************************************/
116
void RedrawStructList( WinEDA_DrawPanel* panel, wxDC* DC,
117
                       SCH_ITEM* Structlist, int DrawMode, int Color )
plyatov's avatar
plyatov committed
118
{
119
    while( Structlist )
120
    {
121
        if( !(Structlist->m_Flags & IS_MOVED) )
122
        {
123 124 125 126
// uncomment line below when there is a virtual
// EDA_BaseStruct::GetBoundingBox()
            //      if( panel->m_ClipBox.Intersects( Structs->GetBoundingBox()
            // ) )
127
            RedrawOneStruct( panel, DC, Structlist, DrawMode, Color );
128 129
        }

130
        Structlist = Structlist->Next();
131
    }
plyatov's avatar
plyatov committed
132 133
}

134

plyatov's avatar
plyatov committed
135
/*****************************************************************************
136
* Routine to redraw list of structs.                                         *
plyatov's avatar
plyatov committed
137
*****************************************************************************/
138
void RedrawOneStruct( WinEDA_DrawPanel* panel, wxDC* DC,
139
                      SCH_ITEM* Struct, int DrawMode, int Color )
plyatov's avatar
plyatov committed
140
{
141 142
    if( Struct == NULL )
        return;
plyatov's avatar
plyatov committed
143

144 145
    if( HighLightStruct == Struct )
        Color = HIGHLIGHT_COLOR;
plyatov's avatar
plyatov committed
146

147
    Struct->Draw( panel, DC, wxPoint( 0, 0 ), DrawMode, Color );
plyatov's avatar
plyatov committed
148 149 150
}


151 152 153 154 155
/* Routine for repainting item in ghost mode. Used in the block moves. */
void DrawStructsInGhost( WinEDA_DrawPanel* aPanel,
                         wxDC*             aDC,
                         SCH_ITEM*         aItem,
                         const wxPoint&    aOffset )
plyatov's avatar
plyatov committed
156
{
157
    int DrawMode = g_XorMode;
158
    int width    = g_DrawDefaultLineThickness;
159

160
    GRSetDrawMode( aDC, DrawMode );
161

162
    switch( aItem->Type() )
163 164 165
    {
    case DRAW_POLYLINE_STRUCT_TYPE:
    {
166
        SCH_POLYLINE* Struct = (SCH_POLYLINE*) aItem;
167 168
        GRMoveTo( Struct->m_PolyPoints[0].x + aOffset.x,
                  Struct->m_PolyPoints[0].y + aOffset.y );
charras's avatar
charras committed
169
        for( unsigned ii = 1; ii < Struct->GetCornerCount(); ii++ )
170 171 172 173 174 175
            GRLineTo( &aPanel->m_ClipBox,
                      aDC,
                      Struct->m_PolyPoints[ii].x + aOffset.x,
                      Struct->m_PolyPoints[ii].y + aOffset.y,
                      width,
                      g_GhostColor );
176 177 178 179 180 181

        break;
    }

    case DRAW_SEGMENT_STRUCT_TYPE:
    {
182 183
        SCH_LINE* Struct;
        Struct = (SCH_LINE*) aItem;
184 185
        if( (Struct->m_Flags & STARTPOINT) == 0 )
        {
186 187
            GRMoveTo( Struct->m_Start.x + aOffset.x,
                      Struct->m_Start.y + aOffset.y );
188 189 190 191 192 193 194
        }
        else
        {
            GRMoveTo( Struct->m_Start.x, Struct->m_Start.y );
        }
        if( (Struct->m_Flags & ENDPOINT) == 0 )
        {
195 196
            GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_End.x + aOffset.x,
                      Struct->m_End.y + aOffset.y, width, g_GhostColor );
197 198 199
        }
        else
        {
200
            GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_End.x,
201
                      Struct->m_End.y, width, g_GhostColor );
202 203 204 205 206 207
        }
        break;
    }

    case DRAW_BUSENTRY_STRUCT_TYPE:
    {
208 209
        SCH_BUS_ENTRY* Struct = (SCH_BUS_ENTRY*) aItem;
        wxPoint        start  = Struct->m_Pos + aOffset;
210 211 212
        GRMoveTo( start.x, start.y );
        GRLineTo( &aPanel->m_ClipBox, aDC, Struct->m_Size.x + start.x,
                  Struct->m_Size.y + start.y, width, g_GhostColor );
213 214 215 216 217
        break;
    }

    case DRAW_JUNCTION_STRUCT_TYPE:
    {
218 219
        SCH_JUNCTION* Struct;
        Struct = (SCH_JUNCTION*) aItem;
220
        Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor );
221 222 223
        break;
    }

224
    case TYPE_SCH_TEXT:
225
    {
226
        SCH_TEXT* Struct;
227 228
        Struct = (SCH_TEXT*) aItem;
        Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor );
229 230 231
        break;
    }

232 233 234
    case TYPE_SCH_LABEL:
    case TYPE_SCH_GLOBALLABEL:
    case TYPE_SCH_HIERLABEL:
235
    {
236
        SCH_LABEL* Struct;
237 238
        Struct = (SCH_LABEL*) aItem;
        Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor );
239 240 241 242 243
        break;
    }

    case DRAW_NOCONNECT_STRUCT_TYPE:
    {
244 245
        SCH_NO_CONNECT* Struct;
        Struct = (SCH_NO_CONNECT*) aItem;
246
        Struct->Draw( aPanel, aDC, aOffset, DrawMode, g_GhostColor );
247 248 249
        break;
    }

250
    case TYPE_SCH_COMPONENT:
251
    {
252
        SCH_COMPONENT* Component = (SCH_COMPONENT*) aItem;
253

254
        if( Component == NULL )
255
            break;
256 257

        Component->Draw( aPanel, aDC, aOffset, g_XorMode, g_GhostColor, false );
258 259 260 261 262
        break;
    }

    case DRAW_SHEET_STRUCT_TYPE:
    {
263
        SCH_SHEET* Struct = (SCH_SHEET*) aItem;
264 265 266 267 268 269 270 271
        GRRect( &aPanel->m_ClipBox,
                aDC,
                Struct->m_Pos.x + aOffset.x,
                Struct->m_Pos.y + aOffset.y,
                Struct->m_Pos.x + Struct->m_Size.x + aOffset.x,
                Struct->m_Pos.y + Struct->m_Size.y + aOffset.y,
                width,
                g_GhostColor );
272 273 274
        break;
    }

charras's avatar
charras committed
275
    case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE:
276
    case TYPE_SCH_MARKER:
277 278 279 280 281
        break;

    default:
        break;
    }
plyatov's avatar
plyatov committed
282
}