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.

736 lines
21 KiB

  1. /****************************************************/
  2. /* Gestion des composants specifiques aux microndes */
  3. /****************************************************/
  4. /* Fichier MUONDE.CPP */
  5. #include "fctsys.h"
  6. #include "gr_basic.h"
  7. #include "common.h"
  8. #include "trigo.h"
  9. #include "pcbnew.h"
  10. #include "autorout.h"
  11. #include "drag.h"
  12. #include <string.h>
  13. #include "protos.h"
  14. /* fonctions importees */
  15. /* Fonctions locales */
  16. //static void Exit_Muonde(WinEDA_DrawFrame * frame, wxDC *DC);
  17. /* Variables locales : */
  18. #define COEFF_COUNT 6
  19. double* PolyEdges;
  20. int PolyEdgesCount;
  21. double ShapeScaleX, ShapeScaleY;
  22. wxSize ShapeSize;
  23. int PolyShapeType;
  24. #include "gen_self.h"
  25. /***************************************************************************/
  26. MODULE* WinEDA_PcbFrame::Create_MuWaveBasicShape( wxDC* DC,
  27. const wxString& name, int pad_count )
  28. /***************************************************************************/
  29. /* Create a footprint with pad_count pads for micro wave applications
  30. * This footprint has pad_count pads:
  31. * SMD, rectangular, H size = V size = current track width.
  32. */
  33. {
  34. MODULE* Module;
  35. int pad_num = 1;
  36. wxString Line;
  37. Module = Create_1_Module( DC, name );
  38. if( Module == NULL )
  39. return NULL;
  40. Module->m_TimeStamp = GetTimeStamp();
  41. Module->m_Value->m_Size = wxSize( 30, 30 );
  42. Module->m_Value->m_Pos0.y = -30;
  43. Module->m_Value->m_Pos.y += Module->m_Value->m_Pos0.y;
  44. Module->m_Reference->m_Size = wxSize( 30, 30 );
  45. Module->m_Reference->m_Pos0.y = 30;
  46. Module->m_Reference->m_Pos.y += Module->m_Reference->m_Pos0.y;
  47. /* Creation des pastilles formant le gap */
  48. while( pad_count-- )
  49. {
  50. D_PAD* pad;
  51. pad = new D_PAD( Module );
  52. pad->Pback = Module;
  53. if( Module->m_Pads == NULL )
  54. {
  55. Module->m_Pads = pad;
  56. }
  57. else
  58. {
  59. Module->m_Pads->Pback = pad;
  60. pad->Pnext = Module->m_Pads;
  61. Module->m_Pads = pad;
  62. }
  63. pad->m_Size.x = pad->m_Size.y = g_DesignSettings.m_CurrentTrackWidth;
  64. pad->m_Pos = Module->m_Pos;
  65. pad->m_PadShape = RECT;
  66. pad->m_Attribut = SMD;
  67. pad->m_Masque_Layer = CMP_LAYER;
  68. Line.Printf( wxT( "%d" ), pad_num );
  69. pad->SetPadName( Line );
  70. pad_num++;
  71. }
  72. if( DC )
  73. Module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
  74. return Module;
  75. }
  76. #if 0
  77. /**********************************************************/
  78. static void Exit_Muonde( WinEDA_DrawFrame* frame, wxDC* DC )
  79. /**********************************************************/
  80. {
  81. MODULE* Module = (MODULE*) frame->m_CurrentScreen->GetCurItem();
  82. if( Module )
  83. {
  84. if( Module->m_Flags & IS_NEW )
  85. {
  86. Module->Draw( frame->DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );
  87. DeleteStructure( Module );
  88. }
  89. else
  90. {
  91. Module->Draw( frame->DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );
  92. }
  93. }
  94. frame->DrawPanel->ManageCurseur = NULL;
  95. frame->DrawPanel->ForceCloseManageCurseur = NULL;
  96. frame->m_CurrentScreen->SetCurItem( NULL );
  97. }
  98. #endif
  99. /***************************************************************************/
  100. MODULE* WinEDA_PcbFrame::Create_MuWaveComponent( wxDC* DC, int shape_type )
  101. /***************************************************************************/
  102. /* Create a module "GAP" or "STUB"
  103. * This a "gap" or "stub" used in micro wave designs
  104. * This modue has 2 pads:
  105. * SMD, rectangular, H size = V size = current track width.
  106. * the "gap" is isolation created between this 2 pads
  107. */
  108. {
  109. int gap_size, oX, ii;
  110. float fcoeff;
  111. D_PAD* pt_pad;
  112. MODULE* Module;
  113. wxString msg, cmp_name;
  114. int pad_count = 2;
  115. int angle = 0;
  116. bool abort;
  117. /* Entree de la longueur desiree du gap*/
  118. gap_size = g_DesignSettings.m_CurrentTrackWidth; // Valeur raisonnable
  119. switch( shape_type )
  120. {
  121. case 0:
  122. msg = _( "Gap" );
  123. cmp_name = wxT( "GAP" );
  124. break;
  125. case 1:
  126. msg = _( "Stub" );
  127. cmp_name = wxT( "STUB" );
  128. pad_count = 2;
  129. break;
  130. case 2:
  131. msg = _( "Arc Stub" );
  132. cmp_name = wxT( "ASTUB" );
  133. pad_count = 1;
  134. break;
  135. default:
  136. msg = wxT( "???" );
  137. break;
  138. }
  139. wxString value;
  140. if( g_UnitMetric )
  141. {
  142. fcoeff = 10000.0 / 25.4;
  143. value.Printf( wxT( "%2.4f" ), gap_size / fcoeff );
  144. msg += _( " (mm):" );
  145. abort = Get_Message( msg, value, this );
  146. }
  147. else
  148. {
  149. fcoeff = 10000.0;
  150. value.Printf( wxT( "%2.3f" ), gap_size / fcoeff );
  151. msg += _( " (inch):" );
  152. abort = Get_Message( msg, value, this );
  153. }
  154. double fval;
  155. if( !value.ToDouble( &fval ) )
  156. {
  157. DisplayError( this, _( "Incorrect number, abort" ) );
  158. abort = TRUE;
  159. }
  160. gap_size = ABS( (int) round( fval * fcoeff ) );
  161. if( !abort && (shape_type == 2) )
  162. {
  163. fcoeff = 10.0;
  164. value.Printf( wxT( "%3.1f" ), angle / fcoeff );
  165. msg = _( "Angle (0.1deg):" );
  166. abort = Get_Message( msg, value, this );
  167. if( !value.ToDouble( &fval ) )
  168. {
  169. DisplayError( this, _( "Incorrect number, abort" ) );
  170. abort = TRUE;
  171. }
  172. angle = ABS( (int) round( fval * fcoeff ) );
  173. if( angle > 1800 )
  174. angle = 1800;
  175. }
  176. if( abort )
  177. {
  178. DrawPanel->MouseToCursorSchema();
  179. return NULL;
  180. }
  181. Module = Create_MuWaveBasicShape( NULL, cmp_name, pad_count );
  182. pt_pad = Module->m_Pads;
  183. switch( shape_type )
  184. {
  185. case 0: //Gap :
  186. oX = pt_pad->m_Pos0.x = -(gap_size + pt_pad->m_Size.x) / 2;
  187. pt_pad->m_Pos.x += pt_pad->m_Pos0.x;
  188. pt_pad = (D_PAD*) pt_pad->Pnext;
  189. pt_pad->m_Pos0.x = oX + gap_size + pt_pad->m_Size.x;
  190. pt_pad->m_Pos.x += pt_pad->m_Pos0.x;
  191. break;
  192. case 1: //Stub :
  193. pt_pad->SetPadName( wxT( "1" ) );
  194. pt_pad = (D_PAD*) pt_pad->Pnext;
  195. pt_pad->m_Pos0.y = -(gap_size + pt_pad->m_Size.y) / 2;
  196. pt_pad->m_Size.y = gap_size;
  197. pt_pad->m_Pos.y += pt_pad->m_Pos0.y;
  198. break;
  199. case 2: //Arc Stub :
  200. {
  201. EDGE_MODULE* edge; int* ptr, theta;
  202. ii = angle / 50;
  203. edge = new EDGE_MODULE( Module );
  204. Module->m_Drawings = edge;
  205. edge->Pback = Module;
  206. edge->m_Shape = S_POLYGON;
  207. edge->SetLayer( LAYER_CMP_N );
  208. edge->m_PolyCount = ii + 3;
  209. edge->m_PolyList = (int*) MyMalloc( edge->m_PolyCount * 2 * sizeof(int) );
  210. ptr = edge->m_PolyList;
  211. edge->m_Start0.y = -pt_pad->m_Size.y / 2;
  212. *ptr = 0; ptr++;
  213. *ptr = 0; ptr++;
  214. theta = -angle / 2;
  215. for( ii = 1; ii < edge->m_PolyCount - 1; ii++ )
  216. {
  217. int x, y;
  218. x = 0; y = -gap_size;
  219. RotatePoint( &x, &y, theta );
  220. *ptr = x; ptr++; *ptr = y; ptr++;
  221. theta += 50;
  222. if( theta > angle / 2 )
  223. theta = angle / 2;
  224. }
  225. *ptr = edge->m_PolyList[0]; ptr++;
  226. *ptr = edge->m_PolyList[1];
  227. break;
  228. }
  229. default:
  230. break;
  231. }
  232. Module->Set_Rectangle_Encadrement();
  233. Module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
  234. DrawPanel->MouseToCursorSchema();
  235. m_Pcb->m_Status_Pcb = 0;
  236. m_CurrentScreen->SetModify();
  237. return Module;
  238. }
  239. /**************** Polygon Shapes ***********************/
  240. enum id_mw_cmd {
  241. ID_ACCEPT_OPT = 1000,
  242. ID_CANCEL_OPT,
  243. ID_READ_SHAPE_FILE
  244. };
  245. /*************************************************/
  246. class WinEDA_SetParamShapeFrame : public wxDialog
  247. /*************************************************/
  248. /* Reglages des parametres des forme polynomiales
  249. */
  250. {
  251. private:
  252. WinEDA_PcbFrame* m_Parent;
  253. wxRadioBox* m_ShapeOptionCtrl;
  254. WinEDA_SizeCtrl* m_SizeCtrl;
  255. public:
  256. // Constructor and destructor
  257. WinEDA_SetParamShapeFrame( WinEDA_PcbFrame* parent, const wxPoint& pos );
  258. ~WinEDA_SetParamShapeFrame( void ) { };
  259. private:
  260. void OnCloseWindow( wxCloseEvent& event );
  261. void OnCancel( wxCommandEvent& event );
  262. void ReadDataShapeDescr( wxCommandEvent& event );
  263. void AcceptOptions( wxCommandEvent& event );
  264. DECLARE_EVENT_TABLE()
  265. };
  266. /* Construction de la table des evenements pour WinEDA_SetParamShapeFrame */
  267. BEGIN_EVENT_TABLE( WinEDA_SetParamShapeFrame, wxDialog )
  268. EVT_BUTTON( ID_ACCEPT_OPT, WinEDA_SetParamShapeFrame::AcceptOptions )
  269. EVT_BUTTON( ID_CANCEL_OPT, WinEDA_SetParamShapeFrame::OnCancel )
  270. EVT_BUTTON( ID_READ_SHAPE_FILE, WinEDA_SetParamShapeFrame::ReadDataShapeDescr )
  271. END_EVENT_TABLE()
  272. /*************************************************/
  273. /* Constructeur de WinEDA_SetParamShapeFrame */
  274. /************************************************/
  275. WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( WinEDA_PcbFrame* parent,
  276. const wxPoint& framepos ) :
  277. wxDialog( parent, -1, _( "Complex shape" ), framepos, wxSize( 350, 280 ),
  278. DIALOG_STYLE )
  279. {
  280. m_Parent = parent;
  281. SetFont( *g_DialogFont );
  282. if( PolyEdges )
  283. free( PolyEdges );
  284. PolyEdges = NULL;
  285. PolyEdgesCount = 0;
  286. wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
  287. SetSizer( MainBoxSizer );
  288. wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
  289. wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
  290. MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
  291. MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  292. wxButton* Button = new wxButton( this, ID_ACCEPT_OPT, _( "Ok" ) );
  293. Button->SetForegroundColour( *wxRED );
  294. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  295. Button = new wxButton( this, ID_CANCEL_OPT, _( "Cancel" ) );
  296. Button->SetForegroundColour( *wxBLUE );
  297. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  298. Button = new wxButton( this, ID_READ_SHAPE_FILE, _( "Read Shape Descr File" ) );
  299. Button->SetForegroundColour( wxColor( 0, 100, 0 ) );
  300. RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 );
  301. wxString shapelist[3] = { _( "Normal" ), _( "Symmetrical" ), _( "mirrored" ) };
  302. m_ShapeOptionCtrl = new wxRadioBox( this, -1, _(
  303. "ShapeOption" ),
  304. wxDefaultPosition, wxDefaultSize, 3, shapelist, 1,
  305. wxRA_SPECIFY_COLS );
  306. LeftBoxSizer->Add( m_ShapeOptionCtrl, 0, wxGROW | wxALL, 5 );
  307. m_SizeCtrl = new WinEDA_SizeCtrl( this, _( "Size" ),
  308. ShapeSize,
  309. g_UnitMetric, LeftBoxSizer, PCB_INTERNAL_UNIT );
  310. GetSizer()->Fit( this );
  311. GetSizer()->SetSizeHints( this );
  312. }
  313. /**********************************************************************/
  314. void WinEDA_SetParamShapeFrame::OnCancel( wxCommandEvent& WXUNUSED (event) )
  315. /**********************************************************************/
  316. {
  317. if( PolyEdges )
  318. free( PolyEdges );
  319. PolyEdges = NULL;
  320. PolyEdgesCount = 0;
  321. EndModal( 0 );
  322. }
  323. /*******************************************************************/
  324. void WinEDA_SetParamShapeFrame::AcceptOptions( wxCommandEvent& event )
  325. /*******************************************************************/
  326. {
  327. ShapeSize = m_SizeCtrl->GetValue();
  328. PolyShapeType = m_ShapeOptionCtrl->GetSelection();
  329. EndModal( 1 );
  330. }
  331. /************************************************************************/
  332. void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event )
  333. /************************************************************************/
  334. /* Read a description shape file
  335. * File format is
  336. * Unit=MM
  337. * XScale=271.501
  338. * YScale=1.00133
  339. *
  340. * $COORD
  341. * 0 0.6112600148417837
  342. * 0.001851851851851852 0.6104800531118608
  343. * ....
  344. * $ENDCOORD
  345. *
  346. * Each line is the X Y coord (normalised units from 0 to 1)
  347. */
  348. {
  349. wxString FullFileName;
  350. wxString ext, mask;
  351. FILE* File;
  352. char Line[1024];
  353. double unitconv = 10000;
  354. char* param1, * param2;
  355. int bufsize;
  356. double* ptbuf;
  357. ext = wxT( ".txt" );
  358. mask = wxT( "*" ) + ext;
  359. FullFileName = EDA_FileSelector( _( "Read descr shape file" ),
  360. wxEmptyString, /* Chemin par defaut */
  361. FullFileName, /* nom fichier par defaut */
  362. ext, /* extension par defaut */
  363. mask, /* Masque d'affichage */
  364. this,
  365. wxFD_OPEN,
  366. TRUE /* ne change pas de repertoire courant */
  367. );
  368. if( FullFileName.IsEmpty() )
  369. return;
  370. File = wxFopen( FullFileName, wxT( "rt" ) );
  371. if( File == NULL )
  372. {
  373. DisplayError( this, _( "File not found" ) );
  374. return;
  375. }
  376. bufsize = 100;
  377. ptbuf = PolyEdges = (double*) MyZMalloc( bufsize * 2 * sizeof(double) );
  378. setlocale( LC_NUMERIC, "C" );
  379. int LineNum = 0;
  380. while( GetLine( File, Line, &LineNum, sizeof(Line) - 1 ) != NULL )
  381. {
  382. param1 = strtok( Line, " =\n\r" );
  383. param2 = strtok( NULL, " \t\n\r" );
  384. if( strnicmp( param1, "Unit", 4 ) == 0 )
  385. {
  386. if( strnicmp( param2, "inch", 4 ) == 0 )
  387. unitconv = 10000;
  388. if( strnicmp( param2, "mm", 2 ) == 0 )
  389. unitconv = 10000 / 25.4;
  390. }
  391. if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 )
  392. break;
  393. if( strnicmp( param1, "$COORD", 6 ) == 0 )
  394. {
  395. while( GetLine( File, Line, &LineNum, sizeof(Line) - 1 ) != NULL )
  396. {
  397. param1 = strtok( Line, " \t\n\r" );
  398. param2 = strtok( NULL, " \t\n\r" );
  399. if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 )
  400. break;
  401. if( bufsize <= PolyEdgesCount )
  402. {
  403. int index = ptbuf - PolyEdges;
  404. bufsize *= 2;
  405. ptbuf = PolyEdges = (double*) realloc( PolyEdges, bufsize * 2 *
  406. sizeof(double) );
  407. ptbuf += index;
  408. }
  409. *ptbuf = atof( param1 );
  410. ptbuf++;
  411. *ptbuf = atof( param2 );
  412. ptbuf++;
  413. PolyEdgesCount++;
  414. }
  415. }
  416. if( strnicmp( Line, "XScale", 6 ) == 0 )
  417. {
  418. ShapeScaleX = atof( param2 );
  419. }
  420. if( strnicmp( Line, "YScale", 6 ) == 0 )
  421. {
  422. ShapeScaleY = atof( param2 );
  423. }
  424. }
  425. if( PolyEdgesCount == 0 )
  426. {
  427. free( PolyEdges );
  428. PolyEdges = NULL;
  429. }
  430. fclose( File );
  431. setlocale( LC_NUMERIC, "" ); // revert to the current locale
  432. ShapeScaleX *= unitconv;
  433. ShapeScaleY *= unitconv;
  434. m_SizeCtrl->SetValue( (int) ShapeScaleX, (int) ShapeScaleY );
  435. }
  436. /*************************************************************/
  437. MODULE* WinEDA_PcbFrame::Create_MuWavePolygonShape( wxDC* DC )
  438. /*************************************************************/
  439. {
  440. D_PAD* pad1, * pad2;
  441. MODULE* Module;
  442. wxString cmp_name;
  443. int pad_count = 2;
  444. EDGE_MODULE* edge; int* ptr;
  445. int ii, npoints;
  446. WinEDA_SetParamShapeFrame* frame = new WinEDA_SetParamShapeFrame( this, wxPoint( -1, -1 ) );
  447. int ok = frame->ShowModal(); frame->Destroy();
  448. DrawPanel->MouseToCursorSchema();
  449. if( ok != 1 )
  450. {
  451. if( PolyEdges )
  452. free( PolyEdges );
  453. PolyEdges = NULL;
  454. PolyEdgesCount = 0;
  455. return NULL;
  456. }
  457. if( PolyShapeType == 2 ) // mirrored
  458. ShapeScaleY = -ShapeScaleY;
  459. ShapeSize.x = (int) round( ShapeScaleX );
  460. ShapeSize.y = (int) round( ShapeScaleY );
  461. if( (ShapeSize.x) == 0 || (ShapeSize.y == 0) )
  462. {
  463. DisplayError( this, _( "Shape has a null size!" ) );
  464. return NULL;
  465. }
  466. if( PolyEdgesCount == 0 )
  467. {
  468. DisplayError( this, _( "Shape has no points!" ) );
  469. return NULL;
  470. }
  471. cmp_name = wxT( "POLY" );
  472. Module = Create_MuWaveBasicShape( NULL, cmp_name, pad_count );
  473. pad1 = Module->m_Pads;
  474. pad1->m_Pos0.x = -ShapeSize.x / 2;
  475. pad1->m_Pos.x += pad1->m_Pos0.x;
  476. pad2 = (D_PAD*) pad1->Pnext;
  477. pad2->m_Pos0.x = pad1->m_Pos0.x + ShapeSize.x;
  478. pad2->m_Pos.x += pad2->m_Pos0.x;
  479. edge = new EDGE_MODULE( Module );
  480. Module->m_Drawings = edge;
  481. edge->Pback = Module;
  482. edge->m_Shape = S_POLYGON;
  483. edge->SetLayer( LAYER_CMP_N );
  484. npoints = PolyEdgesCount;
  485. switch( PolyShapeType )
  486. {
  487. case 0: // Single
  488. case 2: // Single, mirrored
  489. edge->m_PolyCount = PolyEdgesCount + 2;
  490. break;
  491. case 1: // Symetric
  492. edge->m_PolyCount = (2 * PolyEdgesCount) + 2;
  493. break;
  494. }
  495. edge->m_PolyList = (int*) MyMalloc( edge->m_PolyCount * 2 * sizeof(int) );
  496. ptr = edge->m_PolyList;
  497. // Init start point coord:
  498. *ptr = pad1->m_Pos0.x; ptr++;
  499. *ptr = 0; ptr++;
  500. double* dptr = PolyEdges;
  501. wxPoint first_cordinate, last_cordinate;
  502. for( ii = 0; ii < npoints; ii++ ) // Copy points
  503. {
  504. last_cordinate.x = *ptr = (int) round( *dptr * ShapeScaleX ) + pad1->m_Pos0.x;
  505. dptr++; ptr++;
  506. last_cordinate.y = *ptr = -(int) round( *dptr * ShapeScaleY );
  507. dptr++; ptr++;
  508. }
  509. first_cordinate.y = edge->m_PolyList[3];
  510. switch( PolyShapeType )
  511. {
  512. int* ptr1;
  513. case 0: // Single
  514. case 2: // Single mirrored
  515. // Init end point coord:
  516. *ptr = pad2->m_Pos0.x = last_cordinate.x; ptr++;
  517. *ptr = 0;
  518. pad1->m_Size.x = pad1->m_Size.y = ABS( first_cordinate.y );
  519. pad2->m_Size.x = pad2->m_Size.y = ABS( last_cordinate.y );
  520. pad1->m_Pos0.y = first_cordinate.y / 2;
  521. pad2->m_Pos0.y = last_cordinate.y / 2;
  522. pad1->m_Pos.y = pad1->m_Pos0.y + Module->m_Pos.y;
  523. pad2->m_Pos.y = pad2->m_Pos0.y + Module->m_Pos.y;
  524. break;
  525. case 1: // Symetric
  526. ptr1 = ptr - 2;
  527. for( ii = 0; ii <= npoints; ii++ )
  528. {
  529. *ptr = *ptr1; // Copy X coord
  530. ptr++;
  531. *ptr = -*(ptr1 + 1); // Copy Y coord, mirror X axis
  532. ptr1 -= 2; ptr++;
  533. }
  534. pad1->m_Size.x = pad1->m_Size.y = 2* ABS( first_cordinate.y );
  535. pad2->m_Size.x = pad2->m_Size.y = 2* ABS( last_cordinate.y );
  536. break;
  537. }
  538. free( PolyEdges );
  539. PolyEdgesCount = 0;
  540. PolyEdges = NULL;
  541. Module->Set_Rectangle_Encadrement();
  542. Module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
  543. m_Pcb->m_Status_Pcb = 0;
  544. m_CurrentScreen->SetModify();
  545. return Module;
  546. }
  547. /***************************************************************/
  548. void WinEDA_PcbFrame::Edit_Gap( wxDC* DC, MODULE* Module )
  549. /***************************************************************/
  550. /*
  551. * Edit le module GAP, c'est a dire modifie la position et la taille
  552. * des pastilles formant le gap pour obtenir une nouvelle valeur du gap
  553. */
  554. {
  555. int gap_size, oX;
  556. float fcoeff;
  557. D_PAD* pad, * next_pad;
  558. wxString msg;
  559. if( Module == NULL )
  560. return; /* Module non trouve */
  561. /* Test si module = gap ( nom commence par GAP, et 2 pastilles) */
  562. msg = Module->m_Reference->m_Text.Left( 3 );
  563. if( msg != wxT( "GAP" ) )
  564. return;
  565. pad = Module->m_Pads;
  566. if( pad == NULL )
  567. {
  568. DisplayError( this, _( "No pad for this module" ) ); return;
  569. }
  570. next_pad = (D_PAD*) pad->Pnext;
  571. if( next_pad == NULL )
  572. {
  573. DisplayError( this, _( "Only one pad for this module" ) ); return;
  574. }
  575. /* Effacement du module: */
  576. Module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_XOR );
  577. /* Calcul de la dimension actuelle */
  578. gap_size = next_pad->m_Pos0.x - pad->m_Pos0.x - pad->m_Size.x;
  579. /* Entree de la longueur desiree du gap*/
  580. if( g_UnitMetric )
  581. {
  582. fcoeff = 10000.0 / 25.4;
  583. msg.Printf( wxT( "%2.3f" ), gap_size / fcoeff );
  584. Get_Message( _( "Gap (mm):" ), msg, this );
  585. }
  586. else
  587. {
  588. fcoeff = 10000.0;
  589. msg.Printf( wxT( "%2.4f" ), gap_size / fcoeff );
  590. Get_Message( _( "Gap (inch):" ), msg, this );
  591. }
  592. if( !msg.IsEmpty() )
  593. {
  594. double fval;
  595. if( msg.ToDouble( &fval ) )
  596. gap_size = (int) ( fval * fcoeff );
  597. }
  598. /* Mise a jour des tailles des pastilles formant le gap */
  599. pad->m_Size.x = pad->m_Size.y = g_DesignSettings.m_CurrentTrackWidth;
  600. pad->m_Pos0.y = 0;
  601. oX = pad->m_Pos0.x = -( (gap_size + pad->m_Size.x) / 2 );
  602. pad->m_Pos.x = pad->m_Pos0.x + Module->m_Pos.x;
  603. pad->m_Pos.y = pad->m_Pos0.y + Module->m_Pos.y;
  604. RotatePoint( &(pad->m_Pos.x), &(pad->m_Pos.y),
  605. Module->m_Pos.x, Module->m_Pos.y, Module->m_Orient );
  606. next_pad->m_Size.x = next_pad->m_Size.y = g_DesignSettings.m_CurrentTrackWidth;
  607. next_pad->m_Pos0.y = 0;
  608. next_pad->m_Pos0.x = oX + gap_size + next_pad->m_Size.x;
  609. next_pad->m_Pos.x = next_pad->m_Pos0.x + Module->m_Pos.x;
  610. next_pad->m_Pos.y = next_pad->m_Pos0.y + Module->m_Pos.y;
  611. RotatePoint( &(next_pad->m_Pos.x), &(next_pad->m_Pos.y),
  612. Module->m_Pos.x, Module->m_Pos.y, Module->m_Orient );
  613. Module->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_OR );
  614. }