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.

180 lines
5.1 KiB

  1. /*************************************/
  2. /* Modules de creations de Bus Entry */
  3. /*************************************/
  4. #include "fctsys.h"
  5. #include "gr_basic.h"
  6. #include "common.h"
  7. #include "class_drawpanel.h"
  8. #include "id.h"
  9. #include "confirm.h"
  10. #include "program.h"
  11. #include "libcmp.h"
  12. #include "general.h"
  13. #include "protos.h"
  14. /* Routines Locales */
  15. /* Variables locales */
  16. static int s_LastShape = '\\';
  17. static wxPoint ItemInitialPosition;
  18. /**************************************************************/
  19. static void ExitBusEntry( WinEDA_DrawPanel* Panel, wxDC* DC )
  20. /**************************************************************/
  21. /* Routine de sortie des menus de trace */
  22. {
  23. DrawBusEntryStruct* BusEntry =
  24. (DrawBusEntryStruct*) Panel->GetScreen()->GetCurItem();
  25. if( BusEntry ) /* trace en cours */
  26. {
  27. RedrawOneStruct( Panel, DC, BusEntry, g_XorMode );
  28. if( BusEntry->m_Flags & IS_NEW )
  29. {
  30. delete BusEntry;
  31. Panel->GetScreen()->SetCurItem( NULL );
  32. }
  33. else
  34. {
  35. BusEntry->m_Pos = ItemInitialPosition;
  36. RedrawOneStruct( Panel, DC, BusEntry, GR_DEFAULT_DRAWMODE );
  37. BusEntry->m_Flags = 0;
  38. }
  39. }
  40. g_ItemToRepeat = NULL;
  41. Panel->ManageCurseur = NULL;
  42. Panel->ForceCloseManageCurseur = NULL;
  43. }
  44. /************************************************************************/
  45. static void ShowWhileMoving( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
  46. /************************************************************************/
  47. /* Dessin du Segment "BusEntry" lors des deplacements du curseur
  48. */
  49. {
  50. BASE_SCREEN* screen = panel->GetScreen();
  51. DrawBusEntryStruct* BusEntry = (DrawBusEntryStruct*) screen->GetCurItem();
  52. if( BusEntry == NULL )
  53. return;
  54. /* effacement apres deplacement curseur */
  55. if( erase )
  56. RedrawOneStruct( panel, DC, BusEntry, g_XorMode );
  57. /* Reaffichage au bon endroit */
  58. BusEntry->m_Pos = screen->m_Curseur;
  59. RedrawOneStruct( panel, DC, BusEntry, g_XorMode );
  60. }
  61. /**********************************************************************************/
  62. DrawBusEntryStruct* WinEDA_SchematicFrame::CreateBusEntry( wxDC* DC, int entry_type )
  63. /**********************************************************************************/
  64. /* Create a new bus entry, and prepare moving function (for later place it)
  65. */
  66. {
  67. DrawBusEntryStruct* BusEntry = new DrawBusEntryStruct( GetScreen()->m_Curseur,
  68. s_LastShape, entry_type );
  69. BusEntry->m_Flags = IS_NEW;
  70. DrawPanel->CursorOff( DC ); // Erase schematic cursor
  71. RedrawOneStruct( DrawPanel, DC, BusEntry, g_XorMode );
  72. DrawPanel->CursorOn( DC ); // Display schematic cursor
  73. GetScreen()->SetModify();
  74. StartMoveBusEntry( BusEntry, DC );
  75. return BusEntry;
  76. }
  77. /**************************************************************************/
  78. void WinEDA_SchematicFrame::StartMoveBusEntry( DrawBusEntryStruct* BusEntry,
  79. wxDC* DC )
  80. /**************************************************************************/
  81. {
  82. if( BusEntry == NULL )
  83. return;
  84. if( (BusEntry->m_Flags & IS_NEW) == 0 ) // => not already in edit, save shape */
  85. {
  86. delete g_ItemToUndoCopy;
  87. g_ItemToUndoCopy = BusEntry->GenCopy();
  88. }
  89. BusEntry->m_Flags |= IS_MOVED;
  90. ItemInitialPosition = BusEntry->m_Pos;
  91. DrawPanel->CursorOff( DC );
  92. GetScreen()->m_Curseur = BusEntry->m_Pos;
  93. DrawPanel->MouseToCursorSchema();
  94. GetScreen()->SetCurItem( BusEntry );
  95. DrawPanel->ManageCurseur = ShowWhileMoving;
  96. DrawPanel->ForceCloseManageCurseur = ExitBusEntry;
  97. DrawPanel->CursorOn( DC );
  98. }
  99. /************************************************************/
  100. void WinEDA_SchematicFrame::SetBusEntryShape( wxDC* DC,
  101. DrawBusEntryStruct* BusEntry, int entry_shape )
  102. /************************************************************/
  103. /* set the shape of BusEntry (shape = / or \ )
  104. */
  105. {
  106. if( BusEntry == NULL )
  107. return;
  108. if( BusEntry->Type() != DRAW_BUSENTRY_STRUCT_TYPE )
  109. {
  110. DisplayError( this, wxT( "SetBusEntryType: Bad StructType" ) );
  111. return;
  112. }
  113. /* Put old item in undo list if it is not currently in edit */
  114. if( BusEntry->m_Flags == 0 )
  115. SaveCopyInUndoList( BusEntry, UR_CHANGED );
  116. RedrawOneStruct( DrawPanel, DC, BusEntry, g_XorMode );
  117. switch( entry_shape )
  118. {
  119. case '\\':
  120. s_LastShape = '\\';
  121. BusEntry->m_Size.y = 100;
  122. break;
  123. case '/':
  124. s_LastShape = '/';
  125. BusEntry->m_Size.y = -100;
  126. break;
  127. }
  128. TestDanglingEnds( GetScreen()->EEDrawList, NULL );
  129. RedrawOneStruct( DrawPanel, DC, BusEntry, g_XorMode );
  130. GetScreen()->SetModify();
  131. }
  132. /************************************************************************/
  133. int WinEDA_SchematicFrame::GetBusEntryShape( DrawBusEntryStruct* BusEntry )
  134. /************************************************************************/
  135. {
  136. int entry_shape = '\\';
  137. if( BusEntry->m_Size.y < 0 )
  138. entry_shape = '/';
  139. return entry_shape;
  140. }