displayframe.cpp 9.06 KB
Newer Older
plyatov's avatar
plyatov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*********************************************************************/
/** setvisu() : initialisations de l'ecran d'affichage du composant **/
/*********************************************************************/

#include "fctsys.h"
#include "common.h"

#include "wxstruct.h"
#include "cvpcb.h"
#include "id.h"
#include "bitmaps.h"

#include "protos.h"

#define BITMAP wxBitmap

/*****************************************************************/
/* Construction de la table des evenements pour WinEDA_DrawFrame */
/*****************************************************************/

21 22 23 24
BEGIN_EVENT_TABLE( WinEDA_DisplayFrame, wxFrame )

COMMON_EVENTS_DRAWFRAME EVT_CLOSE( WinEDA_DisplayFrame::OnCloseWindow )
EVT_SIZE( WinEDA_DrawFrame::OnSize )
25
EVT_TOOL_RANGE( ID_ZOOM_IN_BUTT, ID_ZOOM_PAGE_BUTT,
26 27 28 29
                WinEDA_DisplayFrame::Process_Zoom )
EVT_TOOL( ID_OPTIONS_SETUP, WinEDA_DisplayFrame::InstallOptionsDisplay )
EVT_TOOL( ID_CVPCB_SHOW3D_FRAME, WinEDA_BasePcbFrame::Show3D_Frame )
END_EVENT_TABLE()
plyatov's avatar
plyatov committed
30 31


32 33 34
/***************************************************************************/
/* WinEDA_DisplayFrame: the frame to display the current focused footprint */
/***************************************************************************/
plyatov's avatar
plyatov committed
35

36 37
WinEDA_DisplayFrame::WinEDA_DisplayFrame( wxWindow* father, WinEDA_App* parent,
                                          const wxString& title,
38 39
                                          const wxPoint& pos, const wxSize& size, long style ) :
    WinEDA_BasePcbFrame( father, parent, CVPCB_DISPLAY_FRAME, title, pos, size, style )
40 41
{
    m_FrameName      = wxT( "CmpFrame" );
42 43 44 45 46 47 48 49 50 51
    m_Draw_Axis      = TRUE;                    // TRUE if we want the axis
    m_Draw_Grid      = TRUE;                    // TRUE if we want the grid
    m_Draw_Sheet_Ref = FALSE;                   // TRUE if we want the sheet references

    // Give an icon
    #ifdef __WINDOWS__
    SetIcon( wxICON( a_icon_cvpcb ) );
    #else
    SetIcon( wxICON( icon_cvpcb ) );
    #endif
52
    SetTitle( title );
plyatov's avatar
plyatov committed
53

54
    m_Pcb = new             BOARD( NULL, this );
plyatov's avatar
plyatov committed
55

56
    m_CurrentScreen = new   PCB_SCREEN( CVPCB_DISPLAY_FRAME );
plyatov's avatar
plyatov committed
57

58 59 60 61 62
    GetSettings();
    SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
    ReCreateHToolbar();
    ReCreateVToolbar();
    Show( TRUE );
plyatov's avatar
plyatov committed
63 64 65
}


66
/******************************************/
67
WinEDA_DisplayFrame::~WinEDA_DisplayFrame()
68 69 70
/******************************************/

// Destructor
plyatov's avatar
plyatov committed
71
{
72
    delete m_CurrentScreen;
73

74
    delete m_Pcb;
75

76
    m_Parent->m_CvpcbFrame->DrawFrame = NULL;
plyatov's avatar
plyatov committed
77 78 79 80
}


/************************************************************/
81
void WinEDA_DisplayFrame::OnCloseWindow( wxCloseEvent& event )
plyatov's avatar
plyatov committed
82
/************************************************************/
83

84 85
/* Called when the frame is closed
 *  Save current settings (frame position and size
86
 */
plyatov's avatar
plyatov committed
87
{
88 89
    wxPoint pos;
    wxSize  size;
plyatov's avatar
plyatov committed
90

91 92
    size = GetSize();
    pos  = GetPosition();
plyatov's avatar
plyatov committed
93

94 95
    SaveSettings();
    Destroy();
plyatov's avatar
plyatov committed
96 97 98 99
}


/************************************************/
100
void WinEDA_DisplayFrame::ReCreateVToolbar()
plyatov's avatar
plyatov committed
101 102 103 104 105 106
/************************************************/
{
}


/************************************************/
107
void WinEDA_DisplayFrame::ReCreateHToolbar()
plyatov's avatar
plyatov committed
108 109
/************************************************/
{
110 111 112 113
    if( m_HToolBar != NULL )
        return;

    m_HToolBar = new WinEDA_Toolbar( TOOLBAR_MAIN, this, ID_H_TOOLBAR, TRUE );
plyatov's avatar
plyatov committed
114

115
    SetToolBar( m_HToolBar );
plyatov's avatar
plyatov committed
116

117 118 119
    m_HToolBar->AddTool( ID_OPTIONS_SETUP, wxEmptyString,
                        BITMAP( display_options_xpm ),
                        _( "Display Options" ) );
plyatov's avatar
plyatov committed
120

121
    m_HToolBar->AddSeparator();
plyatov's avatar
plyatov committed
122

123
    m_HToolBar->AddTool( ID_ZOOM_IN_BUTT, wxEmptyString, BITMAP( zoom_in_xpm ),
124
                        _( "zoom + (F1)" ) );
plyatov's avatar
plyatov committed
125

126
    m_HToolBar->AddTool( ID_ZOOM_OUT_BUTT, wxEmptyString, BITMAP( zoom_out_xpm ),
127
                        _( "zoom - (F2)" ) );
plyatov's avatar
plyatov committed
128

129 130
    m_HToolBar->AddTool( ID_ZOOM_REDRAW_BUTT, wxEmptyString, BITMAP( repaint_xpm ),
                        _( "redraw (F3)" ) );
plyatov's avatar
plyatov committed
131

132 133
    m_HToolBar->AddTool( ID_ZOOM_PAGE_BUTT, wxEmptyString, BITMAP( zoom_optimal_xpm ),
                        _( "1:1 zoom" ) );
plyatov's avatar
plyatov committed
134

135 136 137
    m_HToolBar->AddSeparator();
    m_HToolBar->AddTool( ID_CVPCB_SHOW3D_FRAME, wxEmptyString, BITMAP( show_3d_xpm ),
                        _( "1:1 zoom" ) );
plyatov's avatar
plyatov committed
138

139 140 141
    // after adding the buttons to the toolbar, must call Realize() to reflect
    // the changes
    m_HToolBar->Realize();
plyatov's avatar
plyatov committed
142 143 144 145
}


/*******************************************/
146
void WinEDA_DisplayFrame::SetToolbars()
plyatov's avatar
plyatov committed
147 148 149 150 151
/*******************************************/
{
}


152
/*************************************************************************/
153
void WinEDA_DisplayFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
154
/*************************************************************************/
plyatov's avatar
plyatov committed
155 156 157
{
}

158

159
/*************************************************************************/
160
void WinEDA_DisplayFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
161
/*************************************************************************/
plyatov's avatar
plyatov committed
162 163 164
{
}

165

166 167 168
/*********************************************************************************/
bool WinEDA_DisplayFrame::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
/*********************************************************************************/
plyatov's avatar
plyatov committed
169
{
170
    return true;
plyatov's avatar
plyatov committed
171 172 173 174
}


/****************************************************************/
175
void WinEDA_DisplayFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
plyatov's avatar
plyatov committed
176 177
/****************************************************************/
{
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    wxSize  delta;
    int     flagcurseur = 0;
    int     zoom = m_CurrentScreen->GetZoom();
    wxPoint curpos, oldpos;

    curpos = DrawPanel->CursorRealPosition( Mouse );
    oldpos = m_CurrentScreen->m_Curseur;

    delta.x = m_CurrentScreen->GetGrid().x / zoom;
    delta.y = m_CurrentScreen->GetGrid().y / zoom;
    if( delta.x <= 0 )
        delta.x = 1;
    if( delta.y <= 0 )
        delta.y = 1;

    if( g_KeyPressed )
    {
        switch( g_KeyPressed )
        {
        case WXK_F1:
198
            OnZoom( ID_ZOOM_IN_KEY );
199 200 201 202 203
            flagcurseur = 2;
            curpos = m_CurrentScreen->m_Curseur;
            break;

        case WXK_F2:
204
            OnZoom( ID_ZOOM_OUT_KEY );
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
            flagcurseur = 2;
            curpos = m_CurrentScreen->m_Curseur;
            break;

        case WXK_F3:
            OnZoom( ID_ZOOM_REDRAW_KEY );
            flagcurseur = 2;
            break;

        case WXK_F4:
            OnZoom( ID_ZOOM_CENTER_KEY );
            flagcurseur = 2;
            curpos = m_CurrentScreen->m_Curseur;
            break;

        case ' ':
            m_CurrentScreen->m_O_Curseur = m_CurrentScreen->m_Curseur;
            break;

224
        case WXK_NUMPAD8:       /* cursor moved up */
225 226 227 228 229 230
        case WXK_UP:
            DrawPanel->CalcScrolledPosition( Mouse.x, Mouse.y - delta.y,
                                             &Mouse.x, &Mouse.y );
            GRMouseWarp( DrawPanel, Mouse );
            break;

231
        case WXK_NUMPAD2:       /* cursor moved down */
232 233 234 235 236 237
        case WXK_DOWN:
            DrawPanel->CalcScrolledPosition( Mouse.x, Mouse.y + delta.y,
                                             &Mouse.x, &Mouse.y );
            GRMouseWarp( DrawPanel, Mouse );
            break;

238
        case WXK_NUMPAD4:       /*  cursor moved left */
239 240 241 242 243 244
        case WXK_LEFT:
            DrawPanel->CalcScrolledPosition( Mouse.x - delta.x, Mouse.y,
                                             &Mouse.x, &Mouse.y );
            GRMouseWarp( DrawPanel, Mouse );
            break;

245
        case WXK_NUMPAD6:      /*  cursor moved right */
246 247 248 249 250 251 252 253 254
        case WXK_RIGHT:
            DrawPanel->CalcScrolledPosition( Mouse.x + delta.x, Mouse.y,
                                             &Mouse.x, &Mouse.y );
            GRMouseWarp( DrawPanel, Mouse );
            break;
        }
    }

    m_CurrentScreen->m_Curseur = curpos;
255
    /* Put cursor on grid */
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
    PutOnGrid( &m_CurrentScreen->m_Curseur );

    if( m_CurrentScreen->IsRefreshReq() )
    {
        flagcurseur = 2;
        RedrawActiveWindow( DC, TRUE );
    }

    if( (oldpos.x != m_CurrentScreen->m_Curseur.x)
       || (oldpos.y != m_CurrentScreen->m_Curseur.y) )
    {
        if( flagcurseur != 2 )
        {
            curpos = m_CurrentScreen->m_Curseur;
            m_CurrentScreen->m_Curseur = oldpos;
            DrawPanel->CursorOff( DC );

            m_CurrentScreen->m_Curseur = curpos;
            DrawPanel->CursorOn( DC );
        }

        if( DrawPanel->ManageCurseur )
        {
            DrawPanel->ManageCurseur( DrawPanel, DC, 0 );
        }
    }

283
    Affiche_Status_Box();    /* Display new cursor coordinates */
plyatov's avatar
plyatov committed
284 285
}

286

plyatov's avatar
plyatov committed
287
/*************************************************************************/
288
void WinEDA_DisplayFrame::Process_Special_Functions( wxCommandEvent& event )
plyatov's avatar
plyatov committed
289
/*************************************************************************/
290

291 292
/* Called when a tool is selected, or when a popup menu is clicked
 *  Currently : no action exists
293
 */
plyatov's avatar
plyatov committed
294
{
295
    int        id = event.GetId();
plyatov's avatar
plyatov committed
296

297
    wxClientDC dc( DrawPanel );
plyatov's avatar
plyatov committed
298

299
    DrawPanel->PrepareGraphicContext( &dc );
plyatov's avatar
plyatov committed
300

301 302 303 304 305 306
    switch( id )
    {
    default:
        wxMessageBox( wxT( "WinEDA_DisplayFrame::Process_Special_Functions error" ) );
        break;
    }
plyatov's avatar
plyatov committed
307

308 309
    SetToolbars();
}