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.

287 lines
8.4 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
* 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
* 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
* 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
14 years ago
14 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file target_edit.cpp
  27. * @brief Functions to edit targets (class #PCB_TARGET).
  28. */
  29. #include <fctsys.h>
  30. #include <class_drawpanel.h>
  31. #include <wxPcbStruct.h>
  32. #include <dialog_helpers.h>
  33. #include <base_units.h>
  34. #include <gr_basic.h>
  35. #include <class_board.h>
  36. #include <class_mire.h>
  37. #include <pcbnew.h>
  38. #include <dialog_target_properties_base.h>
  39. // Routines Locales
  40. static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC );
  41. static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel,
  42. wxDC* aDC,
  43. const wxPoint& aPosition,
  44. bool aErase );
  45. // Local variables :
  46. static int MireDefaultSize = Millimeter2iu( 5 );
  47. static PCB_TARGET s_TargetCopy( NULL ); /* Used to store "old" values of the
  48. * current item parameters before
  49. * edition (used in undo/redo or
  50. * cancel operations)
  51. */
  52. /*****************************************/
  53. /* class TARGET_PROPERTIES_DIALOG_EDITOR */
  54. /*****************************************/
  55. class TARGET_PROPERTIES_DIALOG_EDITOR : public TARGET_PROPERTIES_DIALOG_EDITOR_BASE
  56. {
  57. private:
  58. PCB_EDIT_FRAME* m_Parent;
  59. wxDC* m_DC;
  60. PCB_TARGET* m_Target;
  61. public:
  62. TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent, PCB_TARGET* Mire, wxDC* DC );
  63. ~TARGET_PROPERTIES_DIALOG_EDITOR() { }
  64. private:
  65. void OnOkClick( wxCommandEvent& event );
  66. void OnCancelClick( wxCommandEvent& event );
  67. };
  68. void PCB_EDIT_FRAME::ShowTargetOptionsDialog( PCB_TARGET* aTarget, wxDC* DC )
  69. {
  70. TARGET_PROPERTIES_DIALOG_EDITOR* frame =
  71. new TARGET_PROPERTIES_DIALOG_EDITOR( this, aTarget, DC );
  72. frame->ShowModal();
  73. frame->Destroy();
  74. }
  75. TARGET_PROPERTIES_DIALOG_EDITOR::TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent,
  76. PCB_TARGET* aTarget, wxDC* DC ) :
  77. TARGET_PROPERTIES_DIALOG_EDITOR_BASE( parent )
  78. {
  79. m_Parent = parent;
  80. m_DC = DC;
  81. m_Target = aTarget;
  82. // Size:
  83. m_staticTextSizeUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
  84. m_TargetSizeCtrl->SetValue( StringFromValue( g_UserUnit, m_Target->GetSize() ) );
  85. // Thickness:
  86. m_staticTextThicknessUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
  87. m_TargetThicknessCtrl->SetValue( StringFromValue( g_UserUnit, m_Target->GetWidth() ) );
  88. // Shape
  89. m_TargetShape->SetSelection( m_Target->GetShape() ? 1 : 0 );
  90. // OK button on return key.
  91. SetDefaultItem( m_sdbSizerButtsOK );
  92. GetSizer()->Fit( this );
  93. GetSizer()->SetSizeHints( this );
  94. Centre();
  95. }
  96. void TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick( wxCommandEvent& event )
  97. {
  98. EndModal( -1 );
  99. }
  100. /* Updates the different parameters for the component being edited
  101. */
  102. void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event )
  103. {
  104. if( m_DC )
  105. m_Target->Draw( m_Parent->GetCanvas(), m_DC, GR_XOR );
  106. // Save old item in undo list, if is is not currently edited (will be later if so)
  107. if( m_Target->GetFlags() == 0 )
  108. m_Parent->SaveCopyInUndoList( m_Target, UR_CHANGED );
  109. if( m_Target->GetFlags() != 0 ) // other edition in progress (MOVE, NEW ..)
  110. m_Target->SetFlags( IN_EDIT ); // set flag in edit to force
  111. // undo/redo/abort proper operation
  112. int tmp = ValueFromString( g_UserUnit, m_TargetThicknessCtrl->GetValue() );
  113. m_Target->SetWidth( tmp );
  114. MireDefaultSize = ValueFromString( g_UserUnit, m_TargetSizeCtrl->GetValue() );
  115. m_Target->SetSize( MireDefaultSize );
  116. m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
  117. if( m_DC )
  118. m_Target->Draw( m_Parent->GetCanvas(), m_DC, ( m_Target->IsMoving() ) ? GR_XOR : GR_OR );
  119. m_Parent->OnModify();
  120. EndModal( 1 );
  121. }
  122. void PCB_EDIT_FRAME::DeleteTarget( PCB_TARGET* aTarget, wxDC* DC )
  123. {
  124. if( aTarget == NULL )
  125. return;
  126. aTarget->Draw( m_canvas, DC, GR_XOR );
  127. SaveCopyInUndoList( aTarget, UR_DELETED );
  128. aTarget->UnLink();
  129. }
  130. static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC )
  131. {
  132. BASE_SCREEN* screen = Panel->GetScreen();
  133. PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem();
  134. ( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL );
  135. Panel->SetMouseCapture( NULL, NULL );
  136. if( target == NULL )
  137. return;
  138. target->Draw( Panel, DC, GR_XOR );
  139. if( target->IsNew() ) // If it is new, delete it
  140. {
  141. target->Draw( Panel, DC, GR_XOR );
  142. target->DeleteStructure();
  143. target = NULL;
  144. }
  145. else // it is an existing item: retrieve initial values of parameters
  146. {
  147. if( ( target->GetFlags() & (IN_EDIT | IS_MOVED) ) )
  148. {
  149. target->SetPosition( s_TargetCopy.GetPosition() );
  150. target->SetWidth( s_TargetCopy.GetWidth() );
  151. target->SetSize( s_TargetCopy.GetSize() );
  152. target->SetShape( s_TargetCopy.GetShape() );
  153. }
  154. target->ClearFlags();
  155. target->Draw( Panel, DC, GR_OR );
  156. }
  157. }
  158. PCB_TARGET* PCB_EDIT_FRAME::CreateTarget( wxDC* DC )
  159. {
  160. PCB_TARGET* target = new PCB_TARGET( GetBoard() );
  161. target->SetFlags( IS_NEW );
  162. GetBoard()->Add( target );
  163. target->SetLayer( Edge_Cuts );
  164. target->SetWidth( GetDesignSettings().m_EdgeSegmentWidth );
  165. target->SetSize( MireDefaultSize );
  166. target->SetPosition( GetCrossHairPosition() );
  167. PlaceTarget( target, DC );
  168. return target;
  169. }
  170. void PCB_EDIT_FRAME::BeginMoveTarget( PCB_TARGET* aTarget, wxDC* DC )
  171. {
  172. if( aTarget == NULL )
  173. return;
  174. s_TargetCopy = *aTarget;
  175. aTarget->SetFlags( IS_MOVED );
  176. m_canvas->SetMouseCapture( ShowTargetShapeWhileMovingMouse, AbortMoveAndEditTarget );
  177. SetCurItem( aTarget );
  178. }
  179. void PCB_EDIT_FRAME::PlaceTarget( PCB_TARGET* aTarget, wxDC* DC )
  180. {
  181. if( aTarget == NULL )
  182. return;
  183. aTarget->Draw( m_canvas, DC, GR_OR );
  184. m_canvas->SetMouseCapture( NULL, NULL );
  185. SetCurItem( NULL );
  186. OnModify();
  187. if( aTarget->IsNew() )
  188. {
  189. SaveCopyInUndoList( aTarget, UR_NEW );
  190. aTarget->ClearFlags();
  191. return;
  192. }
  193. if( aTarget->GetFlags() == IS_MOVED )
  194. {
  195. SaveCopyInUndoList( aTarget, UR_MOVED,
  196. aTarget->GetPosition() - s_TargetCopy.GetPosition() );
  197. aTarget->ClearFlags();
  198. return;
  199. }
  200. if( (aTarget->GetFlags() & IN_EDIT) )
  201. {
  202. aTarget->SwapData( &s_TargetCopy );
  203. SaveCopyInUndoList( aTarget, UR_CHANGED );
  204. aTarget->SwapData( &s_TargetCopy );
  205. }
  206. aTarget->ClearFlags();
  207. }
  208. // Redraw the contour of the track while moving the mouse
  209. static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
  210. const wxPoint& aPosition, bool aErase )
  211. {
  212. BASE_SCREEN* screen = aPanel->GetScreen();
  213. PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem();
  214. if( target == NULL )
  215. return;
  216. if( aErase )
  217. target->Draw( aPanel, aDC, GR_XOR );
  218. target->SetPosition( aPanel->GetParent()->GetCrossHairPosition() );
  219. target->Draw( aPanel, aDC, GR_XOR );
  220. }