-
-
Notifications
You must be signed in to change notification settings - Fork 500
/
Copy pathdrawpanel.cpp
1270 lines (1016 loc) · 37.3 KB
/
drawpanel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************/
/* drawpanel.cpp - WinEDA_DrawPanel class */
/******************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "macros.h"
#include "id.h"
// Local defines
#define CURSOR_SIZE 12 // Cursor size in pixels
// Locad variables
/* Used to inhibit a response to a mouse left button release, after a double click
* (when releasing the left button at the end of the second click
* Used in eeschema to inhibit a mouse left release command when switching between
* hierarchical sheets on a double click
*/
static bool s_IgnoreNextLeftButtonRelease = false;
// Events used by WinEDA_DrawPanel
BEGIN_EVENT_TABLE( WinEDA_DrawPanel, wxScrolledWindow )
EVT_LEAVE_WINDOW( WinEDA_DrawPanel::OnMouseLeaving )
EVT_MOUSEWHEEL( WinEDA_DrawPanel::OnMouseWheel )
EVT_MOUSE_EVENTS( WinEDA_DrawPanel::OnMouseEvent )
EVT_CHAR( WinEDA_DrawPanel::OnKeyEvent )
EVT_CHAR_HOOK( WinEDA_DrawPanel::OnKeyEvent )
EVT_PAINT( WinEDA_DrawPanel::OnPaint )
EVT_SIZE( WinEDA_DrawPanel::OnSize )
EVT_ERASE_BACKGROUND( WinEDA_DrawPanel::OnEraseBackground )
EVT_SCROLLWIN( WinEDA_DrawPanel::OnScroll )
EVT_ACTIVATE( WinEDA_DrawPanel::OnActivate )
EVT_MENU_RANGE( ID_POPUP_GRID_LEVEL_1000, ID_POPUP_GRID_USER,
WinEDA_DrawPanel::OnPopupGridSelect )
EVT_MENU_RANGE( ID_PAN_UP, ID_PAN_RIGHT, WinEDA_DrawPanel::OnPan )
END_EVENT_TABLE()
/************************************************************************/
/* WinEDA_DrawPanel basic functions (WinEDA_DrawPanel is the main panel)*/
/************************************************************************/
WinEDA_DrawPanel::WinEDA_DrawPanel( WinEDA_DrawFrame* parent, int id,
const wxPoint& pos, const wxSize& size ) :
wxScrolledWindow( parent, id, pos, size,
wxBORDER | wxNO_FULL_REPAINT_ON_RESIZE )
{
m_Parent = parent;
m_ScrollButt_unit = 40;
SetBackgroundColour( wxColour( ColorRefs[g_DrawBgColor].m_Red,
ColorRefs[g_DrawBgColor].m_Green,
ColorRefs[g_DrawBgColor].m_Blue ) );
EnableScrolling( TRUE, TRUE );
m_ClipBox.SetSize( size );
m_ClipBox.SetX( 0 );
m_ClipBox.SetY( 0 );
m_CanStartBlock = -1; // Command block can start if >= 0
m_AbortEnable = m_AbortRequest = FALSE;
m_AutoPAN_Enable = TRUE;
m_IgnoreMouseEvents = 0;
ManageCurseur = NULL;
ForceCloseManageCurseur = NULL;
if( wxGetApp().m_EDA_Config )
m_AutoPAN_Enable = wxGetApp().m_EDA_Config->Read( wxT( "AutoPAN" ),
TRUE );
m_AutoPAN_Request = FALSE;
m_Block_Enable = FALSE;
m_PanelDefaultCursor = m_PanelCursor = wxCURSOR_ARROW;
m_CursorLevel = 0;
m_PrintIsMirrored = false;
}
BASE_SCREEN* WinEDA_DrawPanel::GetScreen()
{
WinEDA_DrawFrame* parentFrame = m_Parent;
wxASSERT( parentFrame );
return parentFrame->GetBaseScreen();
}
/*****************************************************************************
*
* Draw the schematic cursor which is usually on grid
*
*****************************************************************************/
void WinEDA_DrawPanel::Trace_Curseur( wxDC* DC, int color )
{
if( m_CursorLevel != 0 || DC == NULL )
return;
wxPoint Cursor = GetScreen()->m_Curseur;
GRSetDrawMode( DC, GR_XOR );
if( g_CursorShape == 1 ) /* Trace d'un reticule */
{
int dx = GetScreen()->Unscale( m_ClipBox.GetWidth() );
int dy = GetScreen()->Unscale( m_ClipBox.GetHeight() );
GRLine( &m_ClipBox, DC, Cursor.x - dx, Cursor.y,
Cursor.x + dx, Cursor.y, 0, color ); // axe Y
GRLine( &m_ClipBox, DC, Cursor.x, Cursor.y - dx,
Cursor.x, Cursor.y + dy, 0, color ); // axe X
}
else
{
int len = GetScreen()->Unscale( CURSOR_SIZE );
GRLine( &m_ClipBox, DC, Cursor.x - len, Cursor.y,
Cursor.x + len, Cursor.y, 0, color );
GRLine( &m_ClipBox, DC, Cursor.x, Cursor.y - len,
Cursor.x, Cursor.y + len, 0, color );
}
}
/*******************************************************************/
void WinEDA_DrawPanel::CursorOff( wxDC* DC )
/*******************************************************************/
/*
* Remove the grid cursor from the display in preparation for other drawing operations
*/
{
Trace_Curseur( DC );
--m_CursorLevel;
}
/*******************************************************************/
void WinEDA_DrawPanel::CursorOn( wxDC* DC )
/*******************************************************************/
/*
* Display the grid cursor
*/
{
++m_CursorLevel;
Trace_Curseur( DC );
if( m_CursorLevel > 0 ) // Shouldn't happen, but just in case ..
m_CursorLevel = 0;
}
/***********************************/
int WinEDA_DrawPanel::GetZoom()
/***********************************/
{
return GetScreen()->GetZoom();
}
/***************************************/
void WinEDA_DrawPanel::SetZoom( int zoom )
/***************************************/
{
GetScreen()->SetZoom( zoom );
}
/************************************/
wxSize WinEDA_DrawPanel::GetGrid()
/************************************/
{
return GetScreen()->GetGrid();
}
/******************************************************/
void WinEDA_DrawPanel::PrepareGraphicContext( wxDC* DC )
/******************************************************/
{
GRResetPenAndBrush( DC );
DC->SetBackgroundMode( wxTRANSPARENT );
#ifdef WX_ZOOM
double scale = 1.0 / (double) GetZoom();
DC->SetUserScale( scale, scale );
DoPrepareDC( *DC );
#endif
SetBoundaryBox();
}
/**********************************************************************/
wxPoint WinEDA_DrawPanel::CursorRealPosition( const wxPoint& ScreenPos )
/**********************************************************************/
/** CursorRealPosition (used to calculate the cursor position in internal units)
* @return position (in internal units)
* @param ScreenPos = absolute position in pixels
*/
{
return GetScreen()->CursorRealPosition( ScreenPos );
}
/********************************************************/
bool WinEDA_DrawPanel::IsPointOnDisplay( wxPoint ref_pos )
/********************************************************/
/** Funcion IsPointOnDisplay
* @param ref_pos is the position to test in pixels, relative to the panel.
* @return TRUE if ref_pos is a point currently visible on screen
* FALSE if ref_pos is out of screen
*/
{
wxPoint pos;
EDA_Rect display_rect;
SetBoundaryBox();
display_rect = m_ClipBox;
// Reduction legere des dimension de l'ecran utile pour eviter cadrage
// en limite d'ecran
#define PIXEL_MARGIN 8
display_rect.Inflate( -PIXEL_MARGIN, -PIXEL_MARGIN );
// Conversion en coord physiques
pos = CalcUnscrolledPosition( display_rect.GetPosition() );
GetScreen()->Unscale( pos );
pos += GetScreen()->m_DrawOrg;
display_rect.m_Pos = pos;
GetScreen()->Unscale( display_rect.m_Size );
return display_rect.Inside( ref_pos );
}
void WinEDA_DrawPanel::PostDirtyRect( EDA_Rect aRect )
{
// D( printf( "1) PostDirtyRect( x=%d, y=%d, width=%d, height=%d)\n", aRect.m_Pos.x, aRect.m_Pos.y, aRect.m_Size.x, aRect.m_Size.y ); )
// Convert the rect coordinates and size to pixels (make a draw clip box):
ConvertPcbUnitsToPixelsUnits( &aRect );
// Ensure the rectangle is large enough after truncations.
// The pcb units have finer granularity than the pixels, so it can happen
// that the rectangle is not large enough for the erase portion.
aRect.m_Size.x += 2; // += 1 is not enough!
aRect.m_Size.y += 2;
// D( printf( "2) PostDirtyRect( x=%d, y=%d, width=%d, height=%d)\n", aRect.m_Pos.x, aRect.m_Pos.y, aRect.m_Size.x, aRect.m_Size.y ); )
// pass wxRect() via EDA_Rect::operator wxRect() overload
RefreshRect( aRect, TRUE );
}
/************************************************************************/
void WinEDA_DrawPanel::ConvertPcbUnitsToPixelsUnits( EDA_Rect* aRect )
/************************************************************************/
{
// Calculate the draw area origin in internal units:
wxPoint pos = aRect->GetPosition();
ConvertPcbUnitsToPixelsUnits( &pos );
aRect->SetOrigin( pos ); // rect origin in pixel units
GetScreen()->Scale( aRect->m_Size );
}
/***************************************************************************/
void WinEDA_DrawPanel::ConvertPcbUnitsToPixelsUnits( wxPoint* aPosition )
/***************************************************************************/
{
// Calculate the draw area origin in internal units:
wxPoint drwOrig;
int x_axis_scale, y_axis_scale;
// Origin in scroll units;
GetViewStart( &drwOrig.x, &drwOrig.y );
GetScrollPixelsPerUnit( &x_axis_scale, &y_axis_scale );
// Origin in pixels units
drwOrig.x *= x_axis_scale;
drwOrig.y *= y_axis_scale;
// Origin in internal units
GetScreen()->Unscale( drwOrig );
// Real origin, according to the "plot" origin
drwOrig += GetScreen()->m_DrawOrg;
// position in internal units, relative to the visible draw area origin
*aPosition -= drwOrig;
// position in pixels, relative to the visible draw area origin
GetScreen()->Scale( *aPosition );
}
/********************************************************/
wxPoint WinEDA_DrawPanel::CursorScreenPosition()
/********************************************************/
/** CursorScreenPosition
* @return the curseur position in pixels in the panel draw area on screen )
*/
{
wxPoint pos = GetScreen()->m_Curseur;
pos -= GetScreen()->m_DrawOrg;
GetScreen()->Scale( pos );
return pos;
}
/*********************************************************/
wxPoint WinEDA_DrawPanel::GetScreenCenterRealPosition( void )
/*********************************************************/
/** Function GetScreenCenterRealPosition()
* @return position (in internal units) of the current area centre showed on screen
*/
{
wxSize size;
wxPoint realpos;
size = GetClientSize() / 2;
realpos = CalcUnscrolledPosition( wxPoint( size.x, size.y ) );
GetScreen()->Unscale( realpos );
realpos += GetScreen()->m_DrawOrg;
return realpos;
}
/**********************************************/
void WinEDA_DrawPanel::MouseToCursorSchema()
/**********************************************/
/* Move the mouse cursor to the current schematic cursor
*/
{
wxPoint Mouse = CursorScreenPosition();
MouseTo( Mouse );
}
/****************************************************/
void WinEDA_DrawPanel::MouseTo( const wxPoint& Mouse )
/****************************************************/
/** Move the mouse cursor to the position "Mouse"
* @param Mouse = new mouse cursor position
*/
{
wxPoint mouse;
#ifdef WX_ZOOM
CalcScrolledPosition( Mouse.x, Mouse.y, &mouse.x, &mouse.y );
#else
mouse = Mouse - GetScreen()->m_StartVisu;
#endif
WarpPointer( mouse.x, mouse.y );
}
/********************************************************/
void WinEDA_DrawPanel::OnActivate( wxActivateEvent& event )
/********************************************************/
/**
* Called on window activation.
* init the member m_CanStartBlock to avoid a block start command
* on activation (because a left mouse buton can be pressed and no block command wanted
* This happens when enter on a hierarchycat sheet on double click
*/
{
m_CanStartBlock = -1; // Block Command can't start
event.Skip();
}
/***********************************************************/
void WinEDA_DrawPanel::OnEraseBackground( wxEraseEvent& event )
/***********************************************************/
{
event.Skip();
}
/*********************************************************/
void WinEDA_DrawPanel::OnScroll( wxScrollWinEvent& event )
/*********************************************************/
{
int id = event.GetEventType();
int dir, value = 0;
int x, y;
GetViewStart( &x, &y );
dir = event.GetOrientation(); // wxHORIZONTAL or wxVERTICAL
if( id == wxEVT_SCROLLWIN_LINEUP )
value = -m_ScrollButt_unit;
else if( id == wxEVT_SCROLLWIN_LINEDOWN )
value = m_ScrollButt_unit;
else if( id == wxEVT_SCROLLWIN_THUMBTRACK )
{
value = event.GetPosition();
if( dir == wxHORIZONTAL )
Scroll( value, -1 );
else
Scroll( -1, value );
return;
}
else
{
event.Skip();
return;
}
if( dir == wxHORIZONTAL )
{
Scroll( x + value, -1 );
}
else
{
Scroll( -1, y + value );
}
event.Skip();
}
/*************************************************/
void WinEDA_DrawPanel::OnSize( wxSizeEvent& event )
/*************************************************/
{
SetBoundaryBox();
event.Skip();
}
/******************************************/
void WinEDA_DrawPanel::SetBoundaryBox()
/******************************************/
/** Function SetBoundaryBox()
* set the m_ClipBox member to the current displayed rectangle dimensions
*/
{
BASE_SCREEN* Screen = GetScreen();;
if( !Screen )
return;
wxPoint org;
int ii, jj;
GetViewStart( &org.x, &org.y );
GetScrollPixelsPerUnit( &ii, &jj );
org.x *= ii;
org.y *= jj;
Screen->m_StartVisu = org;
m_ClipBox.SetOrigin( org );
m_ClipBox.SetSize( GetClientSize() );
#ifdef WX_ZOOM
CalcUnscrolledPosition( m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y,
&m_ClipBox.m_Pos.x, &m_ClipBox.m_Pos.y );
#else
m_ClipBox.m_Pos -= GetScreen()->m_StartVisu;
#endif
m_ScrollButt_unit = MIN( Screen->m_SizeVisu.x, Screen->m_SizeVisu.y ) / 4;
if( m_ScrollButt_unit < 2 )
m_ScrollButt_unit = 2;
Screen->m_ScrollbarPos.x = GetScrollPos( wxHORIZONTAL );
Screen->m_ScrollbarPos.y = GetScrollPos( wxVERTICAL );
}
/*********************************************/
void WinEDA_DrawPanel::EraseScreen( wxDC* DC )
/*********************************************/
{
GRSetDrawMode( DC, GR_COPY );
GRSFilledRect( &m_ClipBox, DC, m_ClipBox.GetX(), m_ClipBox.GetY(),
m_ClipBox.GetRight(), m_ClipBox.GetBottom(),
g_DrawBgColor, g_DrawBgColor );
}
#if wxUSE_GRAPHICS_CONTEXT
// note: wxUSE_GRAPHICS_CONTEXT must be set to 1 in wxWidgets
// see setup.h in wx Widgets.
// wxWidgets configure can need option --enable-graphics_ctx
// Currently, **only for tests**
//#define USE_GCDC_IN_KICAD // uncommment it to use wxGCDC
#endif
/***************************************************/
void WinEDA_DrawPanel::OnPaint( wxPaintEvent& event )
/***************************************************/
{
#ifdef USE_GCDC_IN_KICAD
wxPaintDC pDC( this );
wxGCDC paintDC(pDC); // Following line should be disabled on MSW and OS X
paintDC.GetGraphicsContext()->Translate(0.5, 0.5); // Fix for pixel offset bug http://trac.wxwidgets.org/ticket/4187
#else
wxPaintDC paintDC( this );
#endif
EDA_Rect tmp;
wxRect PaintClipBox;
wxPoint org;
PrepareGraphicContext( &paintDC );
tmp = m_ClipBox;
org = m_ClipBox.GetOrigin();
wxRegion upd = GetUpdateRegion(); // get the update rect list
// get the union of all rectangles in the update region, 'upd'
PaintClipBox = upd.GetBox();
#if 0 && defined (DEBUG)
printf( "1) PaintClipBox=(%d, %d, %d, %d) org=(%d, %d) m_ClipBox=(%d, %d, %d, %d)\n",
PaintClipBox.x,
PaintClipBox.y,
PaintClipBox.width,
PaintClipBox.height,
org.x, org.y,
m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y,
m_ClipBox.m_Size.x, m_ClipBox.m_Size.y
);
#endif
PaintClipBox.Offset( org );
#ifdef WX_ZOOM
BASE_SCREEN* screen = GetScreen();
screen->Unscale( m_ClipBox.m_Pos );
screen->Unscale( m_ClipBox.m_Size );
#else
m_ClipBox.SetX( PaintClipBox.GetX() );
m_ClipBox.SetY( PaintClipBox.GetY() );
m_ClipBox.SetWidth( PaintClipBox.GetWidth() );
m_ClipBox.SetHeight( PaintClipBox.GetHeight() );
#endif
#if 0 && defined (DEBUG)
printf( "2) PaintClipBox=(%d, %d, %d, %d) org=(%d, %d) m_ClipBox=(%d, %d, %d, %d)\n",
PaintClipBox.x,
PaintClipBox.y,
PaintClipBox.width,
PaintClipBox.height,
org.x, org.y,
m_ClipBox.m_Pos.x, m_ClipBox.m_Pos.y,
m_ClipBox.m_Size.x, m_ClipBox.m_Size.y
);
#endif
PaintClipBox = m_ClipBox;
// call ~wxDCClipper() before ~wxPaintDC()
{
wxDCClipper dcclip( paintDC, PaintClipBox );
ReDraw( &paintDC, TRUE );
}
m_ClipBox = tmp;
event.Skip();
}
/****************************************************/
void WinEDA_DrawPanel::ReDraw( wxDC* DC, bool erasebg )
/****************************************************/
{
BASE_SCREEN* Screen = GetScreen();
if( Screen == NULL )
return;
if( ( g_DrawBgColor != WHITE ) && ( g_DrawBgColor != BLACK ) )
g_DrawBgColor = BLACK;
if( g_DrawBgColor == WHITE )
{
g_XorMode = GR_NXOR;
g_GhostColor = BLACK;
}
else
{
g_XorMode = GR_XOR;
g_GhostColor = WHITE;
}
#ifdef WX_ZOOM
double scale = 1.0 / (double) GetZoom();
DC->SetUserScale( scale, scale );
#endif
if( erasebg )
PrepareGraphicContext( DC );
DC->SetFont( *g_StdFont );
SetBackgroundColour( wxColour( ColorRefs[g_DrawBgColor].m_Red,
ColorRefs[g_DrawBgColor].m_Green,
ColorRefs[g_DrawBgColor].m_Blue ) );
GRResetPenAndBrush( DC );
DC->SetBackground( *wxBLACK_BRUSH );
DC->SetBackgroundMode( wxTRANSPARENT );
m_Parent->RedrawActiveWindow( DC, erasebg );
}
/***********************************************/
void WinEDA_DrawPanel::DrawBackGround( wxDC* DC )
/***********************************************/
/** Function DrawBackGround
* @param DC = current Device Context
* Draws X , Y axis
* draws the grid
* - the grid is drawn only if the zoom level allows a good visibility
* - the grid is always centered on the screen centre
*/
{
int Color = BLUE;
BASE_SCREEN* screen = GetScreen();
int ii, jj, xg, yg, color;
wxSize pas_grille_affichee;
bool drawgrid = FALSE;
wxSize size;
wxPoint org;
double pasx, pasy;
color = g_GridColor;
GRSetDrawMode( DC, GR_COPY );
/* The grid must be visible. this is possible only is grid value
* and zoom value are sufficient
*/
drawgrid = m_Parent->m_Draw_Grid;
pas_grille_affichee = screen->GetGrid();
ii = screen->Scale( pas_grille_affichee.x );
if( ii < 5 )
{
pas_grille_affichee.x *= 2;
ii *= 2;
}
if( ii < 5 )
drawgrid = FALSE; // The gris is small
ii = screen->Scale( pas_grille_affichee.y );
if( ii < 5 )
{
pas_grille_affichee.y *= 2;
ii *= 2;
}
if( ii < 5 )
drawgrid = FALSE; // The gris is small
GetViewStart( &org.x, &org.y );
GetScrollPixelsPerUnit( &ii, &jj );
wxLogDebug( _T( "View start: %d, %d, scroll bar PPI: %d, %d" ),
org.x, org.y, ii, jj );
org.x *= ii;
org.y *= jj;
screen->m_StartVisu = org;
wxLogDebug( _T( "Scroll bar drawing position: %d. %d" ), org.x, org.y );
screen->Unscale( org );
org += screen->m_DrawOrg;
size = GetClientSize();
screen->Unscale( size );
pasx = screen->m_Grid.x * m_Parent->m_InternalUnits;
pasy = screen->m_Grid.y * m_Parent->m_InternalUnits;
if( drawgrid )
{
m_Parent->PutOnGrid( &org );
GRSetColorPen( DC, color );
for( ii = 0; ; ii++ )
{
xg = ii * pas_grille_affichee.x;
int xpos = org.x + xg;
for( jj = 0; ; jj++ )
{
yg = jj * pas_grille_affichee.y;
GRPutPixel( &m_ClipBox, DC, xpos, org.y + yg, color );
if( yg > size.y )
break;
}
if( xg > size.x )
break;
}
}
/* Draw axis */
if( m_Parent->m_Draw_Axis )
{
/* Draw the Y axis */
GRDashedLine( &m_ClipBox, DC, 0, -screen->ReturnPageSize().y,
0, screen->ReturnPageSize().y, 0, Color );
/* Draw the X axis */
GRDashedLine( &m_ClipBox, DC, -screen->ReturnPageSize().x, 0,
screen->ReturnPageSize().x, 0, 0, Color );
}
/* Draw auxiliary axis */
if( m_Parent->m_Draw_Auxiliary_Axis )
{
m_Draw_Auxiliary_Axis( DC, FALSE );
}
}
/********************************************************************/
void WinEDA_DrawPanel::m_Draw_Auxiliary_Axis( wxDC* DC, int drawmode )
/********************************************************************/
/** m_Draw_Auxiliary_Axis
* Draw the Auxiliary Axis, used in pcbnew which as origin coordinates
* for gerber and excellon files
*/
{
if( m_Parent->m_Auxiliary_Axis_Position.x == 0
&& m_Parent->m_Auxiliary_Axis_Position.y == 0 )
return;
int Color = DARKRED;
BASE_SCREEN* screen = GetScreen();
GRSetDrawMode( DC, drawmode );
/* Draw the Y axis */
GRDashedLine( &m_ClipBox, DC,
m_Parent->m_Auxiliary_Axis_Position.x,
-screen->ReturnPageSize().y,
m_Parent->m_Auxiliary_Axis_Position.x,
screen->ReturnPageSize().y,
0, Color );
/* Draw the X axis */
GRDashedLine( &m_ClipBox, DC,
-screen->ReturnPageSize().x,
m_Parent->m_Auxiliary_Axis_Position.y,
screen->ReturnPageSize().x,
m_Parent->m_Auxiliary_Axis_Position.y,
0, Color );
}
/*******************************************************/
bool WinEDA_DrawPanel::OnRightClick( wxMouseEvent& event )
/*******************************************************/
/** Build and display a Popup menu on a right mouse button click
* @return true if a popup menu is shown, or false
*/
{
wxPoint pos;
wxMenu MasterMenu;
pos = event.GetPosition();
if( !m_Parent->OnRightClick( pos, &MasterMenu ) )
return false;
AddMenuZoom( &MasterMenu );
m_IgnoreMouseEvents = TRUE;
PopupMenu( &MasterMenu, pos );
MouseToCursorSchema();
m_IgnoreMouseEvents = FALSE;
return true;
}
/******************************************************/
void WinEDA_DrawPanel::OnMouseLeaving( wxMouseEvent& event )
/*******************************************************/
// Called when the canvas receives a mouse event leaving frame. //
{
if( ManageCurseur == NULL ) // Pas de commande encours
m_AutoPAN_Request = FALSE;
if( !m_AutoPAN_Enable || !m_AutoPAN_Request || m_IgnoreMouseEvents )
return;
// Auto pan if mouse is leave working aera:
wxSize size = GetClientSize();
if( ( size.x < event.GetX() ) || ( size.y < event.GetY() )
|| ( event.GetX() <= 0) || ( event.GetY() <= 0 ) )
{
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED, ID_POPUP_ZOOM_CENTER );
cmd.SetEventObject( this );
GetEventHandler()->ProcessEvent( cmd );
}
}
/*
* Handle mouse wheel events.
*
* The mouse wheel is used to provide support for zooming and panning. This
* is accomplished by converting mouse wheel events in psuedo menu command
* events.
*/
void WinEDA_DrawPanel::OnMouseWheel( wxMouseEvent& event )
{
wxRect rect = GetRect();
/* This fixes a bad rectangle horizontal position returned by the
* schematic library veiwer panel. It may have something to do with
* the sash window. */
rect.Offset( -rect.x, -rect.y );
/* Ignore scroll events if the cursor is outside the drawing area. */
if( event.GetWheelRotation() == 0 || !GetParent()->IsEnabled()
|| !rect.Contains( event.GetPosition() ) )
{
wxLogDebug( wxT( "OnMouseWheel() position(%d, %d) " \
"rectangle(%d, %d, %d, %d)" ),
event.GetPosition().x, event.GetPosition().y,
rect.x, rect.y, rect.width, rect.height );
event.Skip();
return;
}
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetEventObject( this );
// This is a zoom in or out command
if( event.GetWheelRotation() > 0 )
{
if( event.ShiftDown() && !event.ControlDown() )
cmd.SetId( ID_PAN_UP );
else if( event.ControlDown() && !event.ShiftDown() )
cmd.SetId( ID_PAN_LEFT );
else
cmd.SetId( ID_POPUP_ZOOM_IN );
}
else if ( event.GetWheelRotation() < 0 )
{
if( event.ShiftDown() && !event.ControlDown() )
cmd.SetId( ID_PAN_DOWN );
else if( event.ControlDown() && !event.ShiftDown() )
cmd.SetId( ID_PAN_RIGHT );
else
cmd.SetId( ID_POPUP_ZOOM_OUT );
}
GetEventHandler()->ProcessEvent( cmd );
}
/******************************************************/
void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
/*******************************************************/
// Called when the canvas receives a mouse event. //
{
int localrealbutt = 0, localbutt = 0, localkey = 0;
BASE_SCREEN* screen = GetScreen();
static WinEDA_DrawPanel* LastPanel;
if( !screen )
return;
#define MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND 5 /* Adjust value to filter mouse deplacement before
* consider the drag mouse is really a drag command, not just a movement while click
*/
static int MinDragEventCount; /* counts the drag events.
* used to filter mouse moves before starting a block command
* a block comman can be started only if MinDragEventCount > MIN_DRAG_COUNT_FOR_START_BLOCK_COMMAND
* in order to avoid spurious block commands
*/
if( event.Leaving() || event.Entering() )
{
m_CanStartBlock = -1;
}
if( ManageCurseur == NULL ) // No command in progress
m_AutoPAN_Request = FALSE;
if( m_Parent->m_FrameIsActive )
SetFocus();
else
return;
if( !event.IsButton() && !event.Moving()
&& !event.Dragging() && !localkey )
{
return;
}
if( event.RightDown() )
{
OnRightClick( event );
return;
}
if( m_IgnoreMouseEvents )
return;
if( event.LeftIsDown() )
localrealbutt |= GR_M_LEFT_DOWN;
if( event.MiddleIsDown() )
localrealbutt |= GR_M_MIDDLE_DOWN;
if( event.LeftDown() )
localbutt = GR_M_LEFT_DOWN;
if( event.ButtonDClick( 1 ) )
localbutt = GR_M_LEFT_DOWN | GR_M_DCLICK;
if( event.MiddleDown() )
localbutt = GR_M_MIDDLE_DOWN;
if( event.ButtonDClick( 2 ) )
{
}
; // Unused
localrealbutt |= localbutt; /* compensation defaut wxGTK */
/* Compute absolute m_MousePosition in pixel units: */
screen->m_MousePositionInPixels = CalcUnscrolledPosition( event.GetPosition() );
/* Compute absolute m_MousePosition in user units: */
screen->m_MousePosition = CursorRealPosition( screen->m_MousePositionInPixels );
wxClientDC DC( this );
int kbstat = 0;
DC.SetBackground( *wxBLACK_BRUSH );
PrepareGraphicContext( &DC );
g_KeyPressed = localkey;
if( event.ShiftDown() )
kbstat |= GR_KB_SHIFT;
if( event.ControlDown() )
kbstat |= GR_KB_CTRL;
if( event.AltDown() )
kbstat |= GR_KB_ALT;
g_MouseOldButtons = localrealbutt;
// Calling Double Click and Click functions :
if( localbutt == (int) (GR_M_LEFT_DOWN | GR_M_DCLICK) )
{
m_Parent->OnLeftDClick( &DC, screen->m_MousePositionInPixels );
// inhibit a response to the mouse left button release,
// because we have a double click, and we do not want a new OnLeftClick command at end of this Double Click
s_IgnoreNextLeftButtonRelease = true;
}
else if( event.LeftUp() )
{
if( screen->BlockLocate.m_State==STATE_NO_BLOCK // A block command is in progress: a left up is the end of block
&& !s_IgnoreNextLeftButtonRelease ) // This is the end of a double click, already seen
m_Parent->OnLeftClick( &DC, screen->m_MousePositionInPixels );
s_IgnoreNextLeftButtonRelease = false;
}
if( !event.LeftIsDown() )
{
/* be sure there is a response to a left button release command