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.

233 lines
6.1 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file block_commande.cpp
  26. * @brief Common routines for managing on block commands.
  27. */
  28. #include <fctsys.h>
  29. #include <gr_basic.h>
  30. #include <draw_frame.h>
  31. #include <common.h>
  32. #include <macros.h>
  33. #include <base_struct.h>
  34. #include <base_screen.h>
  35. #include <class_drawpanel.h>
  36. #include <confirm.h>
  37. #include <block_commande.h>
  38. BLOCK_SELECTOR::BLOCK_SELECTOR() :
  39. EDA_RECT()
  40. {
  41. m_state = STATE_NO_BLOCK; // State (enum BLOCK_STATE_T) of block.
  42. m_command = BLOCK_IDLE; // Type (enum BLOCK_COMMAND_T) of operation.
  43. m_color = BROWN;
  44. }
  45. BLOCK_SELECTOR::~BLOCK_SELECTOR()
  46. {
  47. ClearListAndDeleteItems();
  48. }
  49. void BLOCK_SELECTOR::SetMessageBlock( EDA_DRAW_FRAME* frame )
  50. {
  51. wxString msg;
  52. switch( m_command )
  53. {
  54. case BLOCK_IDLE:
  55. break;
  56. case BLOCK_MOVE: // Move
  57. case BLOCK_PRESELECT_MOVE: // Move with preselection list
  58. case BLOCK_MOVE_EXACT:
  59. msg = _( "Block Move" );
  60. break;
  61. case BLOCK_DRAG: // Drag
  62. msg = _( "Block Drag" );
  63. break;
  64. case BLOCK_DRAG_ITEM: // Drag
  65. msg = _( "Drag item" );
  66. break;
  67. case BLOCK_DUPLICATE: // Duplicate
  68. msg = _( "Block Duplicate" );
  69. break;
  70. case BLOCK_DELETE: // Delete
  71. msg = _( "Block Delete" );
  72. break;
  73. case BLOCK_COPY: // Copy
  74. msg = _( "Block Copy" );
  75. break;
  76. case BLOCK_PASTE:
  77. msg = _( "Block Paste" );
  78. break;
  79. case BLOCK_ZOOM: // Window Zoom
  80. msg = _( "Zoom to selection" );
  81. break;
  82. case BLOCK_ROTATE: // Rotate 90 deg
  83. msg = _( "Block Rotate" );
  84. break;
  85. case BLOCK_FLIP: // Flip
  86. msg = _( "Block Flip" );
  87. break;
  88. case BLOCK_MIRROR_X:
  89. case BLOCK_MIRROR_Y: // mirror
  90. msg = _( "Block Mirror" );
  91. break;
  92. case BLOCK_ABORT:
  93. break;
  94. default:
  95. msg = wxT( "???" );
  96. break;
  97. }
  98. frame->DisplayToolMsg( msg );
  99. }
  100. void BLOCK_SELECTOR::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
  101. GR_DRAWMODE aDrawMode, COLOR4D aColor )
  102. {
  103. if( !aDC )
  104. return;
  105. int w = GetWidth();
  106. int h = GetHeight();
  107. GRSetDrawMode( aDC, aDrawMode );
  108. if( w == 0 || h == 0 )
  109. GRLine( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
  110. GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
  111. else
  112. GRRect( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
  113. GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
  114. }
  115. void BLOCK_SELECTOR::InitData( EDA_DRAW_PANEL* aPanel, const wxPoint& startpos )
  116. {
  117. m_state = STATE_BLOCK_INIT;
  118. SetOrigin( startpos );
  119. SetSize( wxSize( 0, 0 ) );
  120. m_items.ClearItemsList();
  121. aPanel->SetMouseCapture( DrawAndSizingBlockOutlines, AbortBlockCurrentCommand );
  122. }
  123. void BLOCK_SELECTOR::ClearItemsList()
  124. {
  125. m_items.ClearItemsList();
  126. }
  127. void BLOCK_SELECTOR::ClearListAndDeleteItems()
  128. {
  129. m_items.ClearListAndDeleteItems();
  130. }
  131. void BLOCK_SELECTOR::PushItem( ITEM_PICKER& aItem )
  132. {
  133. m_items.PushItem( aItem );
  134. }
  135. void BLOCK_SELECTOR::Clear()
  136. {
  137. if( m_command != BLOCK_IDLE )
  138. {
  139. m_command = BLOCK_IDLE;
  140. m_state = STATE_NO_BLOCK;
  141. ClearItemsList();
  142. }
  143. }
  144. void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
  145. bool aErase )
  146. {
  147. BLOCK_SELECTOR* block;
  148. block = &aPanel->GetScreen()->m_BlockLocate;
  149. block->SetMoveVector( wxPoint( 0, 0 ) );
  150. if( aErase && aDC )
  151. block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );
  152. block->SetLastCursorPosition( aPanel->GetParent()->GetCrossHairPosition() );
  153. block->SetEnd( aPanel->GetParent()->GetCrossHairPosition() );
  154. if( aDC )
  155. block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );
  156. if( block->GetState() == STATE_BLOCK_INIT )
  157. {
  158. if( block->GetWidth() || block->GetHeight() )
  159. // 2nd point exists: the rectangle is not surface anywhere
  160. block->SetState( STATE_BLOCK_END );
  161. }
  162. }
  163. void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
  164. {
  165. BASE_SCREEN* screen = aPanel->GetScreen();
  166. if( aPanel->IsMouseCaptured() ) // Erase current drawing on screen
  167. {
  168. // Clear block outline.
  169. aPanel->CallMouseCapture( aDC, wxDefaultPosition, false );
  170. aPanel->SetMouseCapture( NULL, NULL );
  171. screen->SetCurItem( NULL );
  172. // Delete the picked wrapper if this is a picked list.
  173. screen->m_BlockLocate.ClearItemsList();
  174. }
  175. screen->m_BlockLocate.SetState( STATE_NO_BLOCK );
  176. screen->m_BlockLocate.SetCommand( BLOCK_ABORT );
  177. aPanel->GetParent()->HandleBlockEnd( aDC );
  178. screen->m_BlockLocate.SetCommand( BLOCK_IDLE );
  179. aPanel->GetParent()->DisplayToolMsg( wxEmptyString );
  180. aPanel->SetCursor( (wxStockCursor) aPanel->GetCurrentCursor() );
  181. }