You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
9.1 KiB

  1. /*********************************************************************/
  2. /** setvisu() : initialisations de l'ecran d'affichage du composant **/
  3. /*********************************************************************/
  4. #include "fctsys.h"
  5. #include "common.h"
  6. #include "wxstruct.h"
  7. #include "cvpcb.h"
  8. #include "id.h"
  9. #include "bitmaps.h"
  10. #include "protos.h"
  11. #define BITMAP wxBitmap
  12. /*****************************************************************/
  13. /* Construction de la table des evenements pour WinEDA_DrawFrame */
  14. /*****************************************************************/
  15. BEGIN_EVENT_TABLE( WinEDA_DisplayFrame, wxFrame )
  16. COMMON_EVENTS_DRAWFRAME EVT_CLOSE( WinEDA_DisplayFrame::OnCloseWindow )
  17. EVT_SIZE( WinEDA_DrawFrame::OnSize )
  18. EVT_TOOL_RANGE( ID_ZOOM_PLUS_BUTT, ID_ZOOM_PAGE_BUTT,
  19. WinEDA_DisplayFrame::Process_Zoom )
  20. EVT_TOOL( ID_OPTIONS_SETUP, WinEDA_DisplayFrame::InstallOptionsDisplay )
  21. EVT_TOOL( ID_CVPCB_SHOW3D_FRAME, WinEDA_BasePcbFrame::Show3D_Frame )
  22. END_EVENT_TABLE()
  23. /***************************************************************************/
  24. /* WinEDA_DisplayFrame: the frame to display the current focused footprint */
  25. /***************************************************************************/
  26. WinEDA_DisplayFrame::WinEDA_DisplayFrame( wxWindow* father, WinEDA_App* parent,
  27. const wxString& title,
  28. const wxPoint& pos, const wxSize& size, long style ) :
  29. WinEDA_BasePcbFrame( father, parent, CVPCB_DISPLAY_FRAME, title, pos, size, style )
  30. {
  31. m_FrameName = wxT( "CmpFrame" );
  32. m_Draw_Axis = TRUE; // TRUE if we want the axis
  33. m_Draw_Grid = TRUE; // TRUE if we want the grid
  34. m_Draw_Sheet_Ref = FALSE; // TRUE if we want the sheet references
  35. // Give an icon
  36. #ifdef __WINDOWS__
  37. SetIcon( wxICON( a_icon_cvpcb ) );
  38. #else
  39. SetIcon( wxICON( icon_cvpcb ) );
  40. #endif
  41. SetTitle( title );
  42. m_Pcb = new BOARD( NULL, this );
  43. m_CurrentScreen = new PCB_SCREEN( CVPCB_DISPLAY_FRAME );
  44. GetSettings();
  45. SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
  46. ReCreateHToolbar();
  47. ReCreateVToolbar();
  48. Show( TRUE );
  49. }
  50. /******************************************/
  51. WinEDA_DisplayFrame::~WinEDA_DisplayFrame()
  52. /******************************************/
  53. // Destructor
  54. {
  55. delete m_CurrentScreen;
  56. delete m_Pcb;
  57. m_Parent->m_CvpcbFrame->DrawFrame = NULL;
  58. }
  59. /************************************************************/
  60. void WinEDA_DisplayFrame::OnCloseWindow( wxCloseEvent& event )
  61. /************************************************************/
  62. /* Called when the frame is closed
  63. * Save current settings (frame position and size
  64. */
  65. {
  66. wxPoint pos;
  67. wxSize size;
  68. size = GetSize();
  69. pos = GetPosition();
  70. SaveSettings();
  71. Destroy();
  72. }
  73. /************************************************/
  74. void WinEDA_DisplayFrame::ReCreateVToolbar()
  75. /************************************************/
  76. {
  77. }
  78. /************************************************/
  79. void WinEDA_DisplayFrame::ReCreateHToolbar()
  80. /************************************************/
  81. {
  82. if( m_HToolBar != NULL )
  83. return;
  84. m_HToolBar = new WinEDA_Toolbar( TOOLBAR_MAIN, this, ID_H_TOOLBAR, TRUE );
  85. SetToolBar( m_HToolBar );
  86. m_HToolBar->AddTool( ID_OPTIONS_SETUP, wxEmptyString,
  87. BITMAP( display_options_xpm ),
  88. _( "Display Options" ) );
  89. m_HToolBar->AddSeparator();
  90. m_HToolBar->AddTool( ID_ZOOM_PLUS_BUTT, wxEmptyString, BITMAP( zoom_in_xpm ),
  91. _( "zoom + (F1)" ) );
  92. m_HToolBar->AddTool( ID_ZOOM_MOINS_BUTT, wxEmptyString, BITMAP( zoom_out_xpm ),
  93. _( "zoom - (F2)" ) );
  94. m_HToolBar->AddTool( ID_ZOOM_REDRAW_BUTT, wxEmptyString, BITMAP( repaint_xpm ),
  95. _( "redraw (F3)" ) );
  96. m_HToolBar->AddTool( ID_ZOOM_PAGE_BUTT, wxEmptyString, BITMAP( zoom_optimal_xpm ),
  97. _( "1:1 zoom" ) );
  98. m_HToolBar->AddSeparator();
  99. m_HToolBar->AddTool( ID_CVPCB_SHOW3D_FRAME, wxEmptyString, BITMAP( show_3d_xpm ),
  100. _( "1:1 zoom" ) );
  101. // after adding the buttons to the toolbar, must call Realize() to reflect
  102. // the changes
  103. m_HToolBar->Realize();
  104. }
  105. /*******************************************/
  106. void WinEDA_DisplayFrame::SetToolbars()
  107. /*******************************************/
  108. {
  109. }
  110. /*************************************************************************/
  111. void WinEDA_DisplayFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
  112. /*************************************************************************/
  113. {
  114. }
  115. /*************************************************************************/
  116. void WinEDA_DisplayFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
  117. /*************************************************************************/
  118. {
  119. }
  120. /*********************************************************************************/
  121. bool WinEDA_DisplayFrame::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
  122. /*********************************************************************************/
  123. {
  124. return true;
  125. }
  126. /****************************************************************/
  127. void WinEDA_DisplayFrame::GeneralControle( wxDC* DC, wxPoint Mouse )
  128. /****************************************************************/
  129. {
  130. wxSize delta;
  131. int flagcurseur = 0;
  132. int zoom = m_CurrentScreen->GetZoom();
  133. wxPoint curpos, oldpos;
  134. curpos = DrawPanel->CursorRealPosition( Mouse );
  135. oldpos = m_CurrentScreen->m_Curseur;
  136. delta.x = m_CurrentScreen->GetGrid().x / zoom;
  137. delta.y = m_CurrentScreen->GetGrid().y / zoom;
  138. if( delta.x <= 0 )
  139. delta.x = 1;
  140. if( delta.y <= 0 )
  141. delta.y = 1;
  142. if( g_KeyPressed )
  143. {
  144. switch( g_KeyPressed )
  145. {
  146. case WXK_F1:
  147. OnZoom( ID_ZOOM_PLUS_KEY );
  148. flagcurseur = 2;
  149. curpos = m_CurrentScreen->m_Curseur;
  150. break;
  151. case WXK_F2:
  152. OnZoom( ID_ZOOM_MOINS_KEY );
  153. flagcurseur = 2;
  154. curpos = m_CurrentScreen->m_Curseur;
  155. break;
  156. case WXK_F3:
  157. OnZoom( ID_ZOOM_REDRAW_KEY );
  158. flagcurseur = 2;
  159. break;
  160. case WXK_F4:
  161. OnZoom( ID_ZOOM_CENTER_KEY );
  162. flagcurseur = 2;
  163. curpos = m_CurrentScreen->m_Curseur;
  164. break;
  165. case ' ':
  166. m_CurrentScreen->m_O_Curseur = m_CurrentScreen->m_Curseur;
  167. break;
  168. case WXK_NUMPAD8: /* cursor moved up */
  169. case WXK_UP:
  170. DrawPanel->CalcScrolledPosition( Mouse.x, Mouse.y - delta.y,
  171. &Mouse.x, &Mouse.y );
  172. GRMouseWarp( DrawPanel, Mouse );
  173. break;
  174. case WXK_NUMPAD2: /* cursor moved down */
  175. case WXK_DOWN:
  176. DrawPanel->CalcScrolledPosition( Mouse.x, Mouse.y + delta.y,
  177. &Mouse.x, &Mouse.y );
  178. GRMouseWarp( DrawPanel, Mouse );
  179. break;
  180. case WXK_NUMPAD4: /* cursor moved left */
  181. case WXK_LEFT:
  182. DrawPanel->CalcScrolledPosition( Mouse.x - delta.x, Mouse.y,
  183. &Mouse.x, &Mouse.y );
  184. GRMouseWarp( DrawPanel, Mouse );
  185. break;
  186. case WXK_NUMPAD6: /* cursor moved right */
  187. case WXK_RIGHT:
  188. DrawPanel->CalcScrolledPosition( Mouse.x + delta.x, Mouse.y,
  189. &Mouse.x, &Mouse.y );
  190. GRMouseWarp( DrawPanel, Mouse );
  191. break;
  192. }
  193. }
  194. m_CurrentScreen->m_Curseur = curpos;
  195. /* Put cursor on grid */
  196. PutOnGrid( &m_CurrentScreen->m_Curseur );
  197. if( m_CurrentScreen->IsRefreshReq() )
  198. {
  199. flagcurseur = 2;
  200. RedrawActiveWindow( DC, TRUE );
  201. }
  202. if( (oldpos.x != m_CurrentScreen->m_Curseur.x)
  203. || (oldpos.y != m_CurrentScreen->m_Curseur.y) )
  204. {
  205. if( flagcurseur != 2 )
  206. {
  207. curpos = m_CurrentScreen->m_Curseur;
  208. m_CurrentScreen->m_Curseur = oldpos;
  209. DrawPanel->CursorOff( DC );
  210. m_CurrentScreen->m_Curseur = curpos;
  211. DrawPanel->CursorOn( DC );
  212. }
  213. if( DrawPanel->ManageCurseur )
  214. {
  215. DrawPanel->ManageCurseur( DrawPanel, DC, 0 );
  216. }
  217. }
  218. Affiche_Status_Box(); /* Display new cursor coordinates */
  219. }
  220. /*************************************************************************/
  221. void WinEDA_DisplayFrame::Process_Special_Functions( wxCommandEvent& event )
  222. /*************************************************************************/
  223. /* Called when a tool is selected, or when a popup menu is clicked
  224. * Currently : no action exists
  225. */
  226. {
  227. int id = event.GetId();
  228. wxClientDC dc( DrawPanel );
  229. DrawPanel->PrepareGraphicContext( &dc );
  230. switch( id )
  231. {
  232. default:
  233. wxMessageBox( wxT( "WinEDA_DisplayFrame::Process_Special_Functions error" ) );
  234. break;
  235. }
  236. SetToolbars();
  237. }