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.

151 lines
3.8 KiB

  1. /**
  2. * @file busentry.cpp
  3. * @brief Code to handle manipulation of bus entry objects.
  4. */
  5. #include "fctsys.h"
  6. #include "gr_basic.h"
  7. #include "class_drawpanel.h"
  8. #include "eeschema_id.h"
  9. #include "confirm.h"
  10. #include "wxEeschemaStruct.h"
  11. #include "general.h"
  12. #include "protos.h"
  13. #include "sch_bus_entry.h"
  14. static int s_LastShape = '\\';
  15. static wxPoint ItemInitialPosition;
  16. static void ExitBusEntry( EDA_DRAW_PANEL* Panel, wxDC* DC )
  17. {
  18. /* Exit bus entry mode. */
  19. SCH_BUS_ENTRY* BusEntry = (SCH_BUS_ENTRY*) Panel->GetScreen()->GetCurItem();
  20. if( BusEntry )
  21. {
  22. BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), g_XorMode );
  23. if( BusEntry->IsNew() )
  24. {
  25. delete BusEntry;
  26. Panel->GetScreen()->SetCurItem( NULL );
  27. }
  28. else
  29. {
  30. BusEntry->m_Pos = ItemInitialPosition;
  31. BusEntry->Draw( Panel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
  32. BusEntry->m_Flags = 0;
  33. }
  34. }
  35. SCH_EDIT_FRAME* parent = ( SCH_EDIT_FRAME* ) Panel->GetParent();
  36. parent->SetRepeatItem( NULL );
  37. }
  38. static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
  39. bool aErase )
  40. {
  41. // Draws the bus entry while moving the cursor
  42. BASE_SCREEN* screen = aPanel->GetScreen();
  43. SCH_BUS_ENTRY* BusEntry = (SCH_BUS_ENTRY*) screen->GetCurItem();
  44. if( BusEntry == NULL )
  45. return;
  46. /* Erase the last segment position. */
  47. if( aErase )
  48. BusEntry->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
  49. /* Redraw at the new position. */
  50. BusEntry->m_Pos = screen->GetCrossHairPosition();
  51. BusEntry->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
  52. }
  53. SCH_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusEntry( wxDC* DC, int entry_type )
  54. {
  55. // Create and place a new bus entry at cursor position
  56. SCH_BUS_ENTRY* BusEntry = new SCH_BUS_ENTRY( GetScreen()->GetCrossHairPosition(), s_LastShape,
  57. entry_type );
  58. BusEntry->m_Flags = IS_NEW;
  59. BusEntry->Place( this, DC );
  60. OnModify();
  61. return BusEntry;
  62. }
  63. void SCH_EDIT_FRAME::StartMoveBusEntry( SCH_BUS_ENTRY* BusEntry, wxDC* DC )
  64. {
  65. if( BusEntry == NULL )
  66. return;
  67. if( !BusEntry->IsNew() ) // not already in edit, save shape
  68. SetUndoItem( BusEntry );
  69. BusEntry->SetFlags( IS_MOVED );
  70. ItemInitialPosition = BusEntry->m_Pos;
  71. DrawPanel->CrossHairOff( DC );
  72. GetScreen()->SetCrossHairPosition( BusEntry->m_Pos );
  73. DrawPanel->MoveCursorToCrossHair();
  74. GetScreen()->SetCurItem( BusEntry );
  75. DrawPanel->m_mouseCaptureCallback = ShowWhileMoving;
  76. DrawPanel->m_endMouseCaptureCallback = ExitBusEntry;
  77. DrawPanel->CrossHairOn( DC );
  78. }
  79. /* set the shape of BusEntry (shape = / or \ )
  80. */
  81. void SCH_EDIT_FRAME::SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY* BusEntry, int entry_shape )
  82. {
  83. if( BusEntry == NULL )
  84. return;
  85. if( BusEntry->Type() != SCH_BUS_ENTRY_T )
  86. {
  87. DisplayError( this, wxT( "SetBusEntryType: Bad StructType" ) );
  88. return;
  89. }
  90. /* Put old item in undo list if it is not currently in edit */
  91. if( BusEntry->m_Flags == 0 )
  92. SaveCopyInUndoList( BusEntry, UR_CHANGED );
  93. BusEntry->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
  94. switch( entry_shape )
  95. {
  96. case '\\':
  97. s_LastShape = '\\';
  98. BusEntry->m_Size.y = 100;
  99. break;
  100. case '/':
  101. s_LastShape = '/';
  102. BusEntry->m_Size.y = -100;
  103. break;
  104. }
  105. GetScreen()->TestDanglingEnds();
  106. BusEntry->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
  107. OnModify( );
  108. }
  109. int SCH_EDIT_FRAME::GetBusEntryShape( SCH_BUS_ENTRY* BusEntry )
  110. {
  111. int entry_shape = '\\';
  112. if( BusEntry->m_Size.y < 0 )
  113. entry_shape = '/';
  114. return entry_shape;
  115. }