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.

339 lines
9.1 KiB

18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: 3d_frame.cpp
  3. /////////////////////////////////////////////////////////////////////////////
  4. #ifdef __GNUG__
  5. #pragma implementation
  6. #pragma interface
  7. #endif
  8. #include "fctsys.h"
  9. #include <wx/colordlg.h>
  10. #if !wxUSE_GLCANVAS
  11. #error Please set wxUSE_GLCANVAS to 1 in setup.h.
  12. #endif
  13. #include "bitmaps.h"
  14. #include "id.h"
  15. #define VIEWER_MAIN
  16. #include "3d_viewer.h"
  17. #include "trackball.h"
  18. BEGIN_EVENT_TABLE( WinEDA3D_DrawFrame, wxFrame )
  19. EVT_TOOL_RANGE( ID_ZOOM_IN_BUTT, ID_ZOOM_PAGE_BUTT,
  20. WinEDA3D_DrawFrame::Process_Zoom )
  21. EVT_TOOL_RANGE( ID_START_COMMAND_3D, ID_END_COMMAND_3D,
  22. WinEDA3D_DrawFrame::Process_Special_Functions )
  23. EVT_MENU( wxID_EXIT, WinEDA3D_DrawFrame::Exit3DFrame )
  24. EVT_MENU( ID_MENU_SCREENCOPY_PNG, WinEDA3D_DrawFrame::Process_Special_Functions )
  25. EVT_MENU( ID_MENU_SCREENCOPY_JPEG, WinEDA3D_DrawFrame::Process_Special_Functions )
  26. EVT_CLOSE( WinEDA3D_DrawFrame::OnCloseWindow )
  27. END_EVENT_TABLE()
  28. /*******************************************************************/
  29. WinEDA3D_DrawFrame::WinEDA3D_DrawFrame( WinEDA_BasePcbFrame* parent,
  30. WinEDA_App* app_parent, const wxString& title,
  31. long style ) :
  32. wxFrame( parent, DISPLAY3D_FRAME, title,
  33. wxPoint( -1, -1 ), wxSize( -1, -1 ), style )
  34. /*******************************************************************/
  35. {
  36. m_FrameName = wxT( "Frame3D" );
  37. m_Canvas = NULL;
  38. m_Parent = parent;
  39. m_ParentAppl = app_parent;
  40. m_HToolBar = NULL;
  41. m_VToolBar = NULL;
  42. m_InternalUnits = 10000; // Unites internes = 1/10000 inch
  43. // Give it an icon
  44. SetIcon( wxICON( icon_w3d ) );
  45. GetSettings();
  46. SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
  47. // Create the status line
  48. int dims[5] = { -1, 100, 100, 100, 140 };
  49. CreateStatusBar( 5 );
  50. SetStatusWidths( 5, dims );
  51. ReCreateMenuBar();
  52. ReCreateHToolbar();
  53. // ReCreateAuxiliaryToolbar();
  54. ReCreateVToolbar();
  55. // Make a Pcb3D_GLCanvas
  56. m_Canvas = new Pcb3D_GLCanvas( this, -1, gl_attrib );
  57. /* init OpenGL once */
  58. m_Canvas->InitGL();
  59. }
  60. /***********************************************************/
  61. void WinEDA3D_DrawFrame::Exit3DFrame( wxCommandEvent& event )
  62. /***********************************************************/
  63. {
  64. Close( TRUE );
  65. }
  66. /***********************************************************/
  67. void WinEDA3D_DrawFrame::OnCloseWindow( wxCloseEvent& Event )
  68. /***********************************************************/
  69. {
  70. SaveSettings();
  71. if( m_Parent )
  72. {
  73. m_Parent->m_Draw3DFrame = NULL;
  74. }
  75. Destroy();
  76. }
  77. /******************************************/
  78. void WinEDA3D_DrawFrame::GetSettings()
  79. /******************************************/
  80. {
  81. wxString text;
  82. wxConfig* Config = m_ParentAppl->m_EDA_Config; // Current config used by application
  83. if( m_ParentAppl->m_EDA_Config )
  84. {
  85. text = m_FrameName + wxT( "Pos_x" );
  86. Config->Read( text, &m_FramePos.x );
  87. text = m_FrameName + wxT( "Pos_y" );
  88. Config->Read( text, &m_FramePos.y );
  89. text = m_FrameName + wxT( "Size_x" );
  90. Config->Read( text, &m_FrameSize.x, 600 );
  91. text = m_FrameName + wxT( "Size_y" );
  92. Config->Read( text, &m_FrameSize.y, 400 );
  93. Config->Read( wxT( "BgColor_Red" ), &g_Parm_3D_Visu.m_BgColor.m_Red, 0.0 );
  94. Config->Read( wxT( "BgColor_Green" ), &g_Parm_3D_Visu.m_BgColor.m_Green, 0.0 );
  95. Config->Read( wxT( "BgColor_Blue" ), &g_Parm_3D_Visu.m_BgColor.m_Blue, 0.0 );
  96. }
  97. #ifdef __WXMAC__
  98. // for macOSX, the window must be below system (macOSX) toolbar
  99. if( m_FramePos.y < GetMBarHeight() )
  100. m_FramePos.y = GetMBarHeight();
  101. #endif
  102. }
  103. /*******************************************/
  104. void WinEDA3D_DrawFrame::SaveSettings()
  105. /*******************************************/
  106. {
  107. wxString text;
  108. wxConfig* Config = m_ParentAppl->m_EDA_Config; // Current config used by application
  109. if( !Config )
  110. return;
  111. Config->Write( wxT( "BgColor_Red" ), g_Parm_3D_Visu.m_BgColor.m_Red );
  112. Config->Write( wxT( "BgColor_Green" ), g_Parm_3D_Visu.m_BgColor.m_Green );
  113. Config->Write( wxT( "BgColor_Blue" ), g_Parm_3D_Visu.m_BgColor.m_Blue );
  114. if( IsIconized() )
  115. return;
  116. m_FrameSize = GetSize();
  117. m_FramePos = GetPosition();
  118. text = m_FrameName + wxT( "Pos_x" );
  119. Config->Write( text, (long) m_FramePos.x );
  120. text = m_FrameName + wxT( "Pos_y" );
  121. Config->Write( text, (long) m_FramePos.y );
  122. text = m_FrameName + wxT( "Size_x" );
  123. Config->Write( text, (long) m_FrameSize.x );
  124. text = m_FrameName + wxT( "Size_y" );
  125. Config->Write( text, (long) m_FrameSize.y );
  126. }
  127. /***********************************************************/
  128. void WinEDA3D_DrawFrame::Process_Zoom( wxCommandEvent& event )
  129. /***********************************************************/
  130. {
  131. int ii;
  132. switch( event.GetId() )
  133. {
  134. case ID_ZOOM_PAGE_BUTT:
  135. for( ii = 0; ii < 4; ii++ )
  136. g_Parm_3D_Visu.m_Rot[ii] = 0.0;
  137. g_Parm_3D_Visu.m_Zoom = 1.0;
  138. g_Draw3d_dx = g_Draw3d_dy = 0;
  139. trackball( g_Parm_3D_Visu.m_Quat, 0.0, 0.0, 0.0, 0.0 );
  140. break;
  141. case ID_ZOOM_IN_BUTT:
  142. g_Parm_3D_Visu.m_Zoom /= 1.2;
  143. if( g_Parm_3D_Visu.m_Zoom <= 0.01 )
  144. g_Parm_3D_Visu.m_Zoom = 0.01;
  145. break;
  146. case ID_ZOOM_OUT_BUTT:
  147. g_Parm_3D_Visu.m_Zoom *= 1.2;
  148. break;
  149. case ID_ZOOM_REDRAW_BUTT:
  150. break;
  151. default:
  152. return;
  153. }
  154. m_Canvas->DisplayStatus();
  155. m_Canvas->Refresh( FALSE );
  156. }
  157. /************************************************************************/
  158. void WinEDA3D_DrawFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
  159. /************************************************************************/
  160. {
  161. }
  162. /*******************************************************************************/
  163. void WinEDA3D_DrawFrame::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
  164. /*******************************************************************************/
  165. {
  166. }
  167. /************************************/
  168. int WinEDA3D_DrawFrame::BestZoom()
  169. /************************************/
  170. // Retourne le meilleur zoom
  171. {
  172. return 1;
  173. }
  174. /*******************************************************************/
  175. void WinEDA3D_DrawFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg )
  176. /*******************************************************************/
  177. {
  178. }
  179. /************************************************************************/
  180. void WinEDA3D_DrawFrame::Process_Special_Functions( wxCommandEvent& event )
  181. /************************************************************************/
  182. {
  183. #define ROT_ANGLE 10.0
  184. switch( event.GetId() )
  185. {
  186. case ID_RELOAD3D_BOARD:
  187. NewDisplay();
  188. break;
  189. case ID_ROTATE3D_X_POS:
  190. g_Parm_3D_Visu.m_ROTX += ROT_ANGLE;
  191. break;
  192. case ID_ROTATE3D_X_NEG:
  193. g_Parm_3D_Visu.m_ROTX -= ROT_ANGLE;
  194. break;
  195. case ID_ROTATE3D_Y_POS:
  196. g_Parm_3D_Visu.m_ROTY += ROT_ANGLE;
  197. break;
  198. case ID_ROTATE3D_Y_NEG:
  199. g_Parm_3D_Visu.m_ROTY -= ROT_ANGLE;
  200. break;
  201. case ID_ROTATE3D_Z_POS:
  202. g_Parm_3D_Visu.m_ROTZ += ROT_ANGLE;
  203. break;
  204. case ID_ROTATE3D_Z_NEG:
  205. g_Parm_3D_Visu.m_ROTZ -= ROT_ANGLE;
  206. break;
  207. case ID_MOVE3D_LEFT:
  208. m_Canvas->SetView3D( WXK_LEFT );
  209. return;
  210. case ID_MOVE3D_RIGHT:
  211. m_Canvas->SetView3D( WXK_RIGHT );
  212. return;
  213. case ID_MOVE3D_UP:
  214. m_Canvas->SetView3D( WXK_UP );
  215. return;
  216. case ID_MOVE3D_DOWN:
  217. m_Canvas->SetView3D( WXK_DOWN );
  218. return;
  219. case ID_TOOL_SCREENCOPY_TOCLIBBOARD:
  220. case ID_MENU_SCREENCOPY_PNG:
  221. case ID_MENU_SCREENCOPY_JPEG:
  222. m_Canvas->TakeScreenshot( event );
  223. break;
  224. case ID_MENU3D_BGCOLOR_SELECTION:
  225. Set3DBgColor();
  226. return;
  227. default:
  228. wxMessageBox(
  229. wxT( "WinEDA3D_DrawFrame::Process_Special_Functions() error: unknown command" ) );
  230. return;
  231. }
  232. m_Canvas->DisplayStatus();
  233. m_Canvas->Refresh( FALSE );
  234. }
  235. /*****************************************/
  236. void WinEDA3D_DrawFrame::NewDisplay()
  237. /*****************************************/
  238. {
  239. m_Canvas->ClearLists();
  240. m_Canvas->InitGL();
  241. m_Canvas->DisplayStatus();
  242. m_Canvas->Refresh( FALSE );
  243. }
  244. /******************************************/
  245. void WinEDA3D_DrawFrame::Set3DBgColor()
  246. /******************************************/
  247. /* called to set the background color of the 3D scene
  248. */
  249. {
  250. S3D_Color color;
  251. wxColour newcolor, oldcolor;
  252. oldcolor.Set( (int) round( g_Parm_3D_Visu.m_BgColor.m_Red * 255 ),
  253. (int) round( g_Parm_3D_Visu.m_BgColor.m_Green * 255 ),
  254. (int) round( g_Parm_3D_Visu.m_BgColor.m_Blue * 255 ) );
  255. newcolor = wxGetColourFromUser( this, oldcolor );
  256. if( newcolor != oldcolor )
  257. {
  258. g_Parm_3D_Visu.m_BgColor.m_Red = (double) newcolor.Red() / 255.0;
  259. g_Parm_3D_Visu.m_BgColor.m_Green = (double) newcolor.Green() / 255.0;
  260. g_Parm_3D_Visu.m_BgColor.m_Blue = (double) newcolor.Blue() / 255.0;
  261. NewDisplay();
  262. }
  263. }