kicad/pcbnew/target_edit.cpp

292 lines
8.5 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2013 KiCad Developers, see change_log.txt for contributors.
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file target_edit.cpp
* @brief Functions to edit targets (class #PCB_TARGET).
*/
2007-05-06 16:03:28 +00:00
#include <fctsys.h>
#include <class_drawpanel.h>
#include <wxPcbStruct.h>
#include <dialog_helpers.h>
#include <base_units.h>
#include <gr_basic.h>
#include <board_commit.h>
2007-05-06 16:03:28 +00:00
#include <class_board.h>
#include <class_pcb_target.h>
#include <pcbnew.h>
#include <dialog_target_properties_base.h>
2009-08-03 07:55:08 +00:00
2007-05-06 16:03:28 +00:00
// Routines Locales
static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC );
static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel,
wxDC* aDC,
const wxPoint& aPosition,
bool aErase );
2007-05-06 16:03:28 +00:00
// Local variables :
static int MireDefaultSize = Millimeter2iu( 5 );
static PCB_TARGET s_TargetCopy( NULL ); /* Used to store "old" values of the
* current item parameters before
* edition (used in undo/redo or
* cancel operations)
2009-08-03 07:55:08 +00:00
*/
2007-05-06 16:03:28 +00:00
/*****************************************/
/* class TARGET_PROPERTIES_DIALOG_EDITOR */
/*****************************************/
2007-05-06 16:03:28 +00:00
class TARGET_PROPERTIES_DIALOG_EDITOR : public TARGET_PROPERTIES_DIALOG_EDITOR_BASE
2007-05-06 16:03:28 +00:00
{
private:
PCB_EDIT_FRAME* m_Parent;
wxDC* m_DC;
PCB_TARGET* m_Target;
2007-05-06 16:03:28 +00:00
public:
TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent, PCB_TARGET* Mire, wxDC* DC );
~TARGET_PROPERTIES_DIALOG_EDITOR() { }
2007-05-06 16:03:28 +00:00
private:
2016-09-24 18:53:15 +00:00
void OnOkClick( wxCommandEvent& event ) override;
void OnCancelClick( wxCommandEvent& event ) override;
2007-05-06 16:03:28 +00:00
};
void PCB_EDIT_FRAME::ShowTargetOptionsDialog( PCB_TARGET* aTarget, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
TARGET_PROPERTIES_DIALOG_EDITOR* frame =
new TARGET_PROPERTIES_DIALOG_EDITOR( this, aTarget, DC );
frame->ShowModal();
frame->Destroy();
2007-05-06 16:03:28 +00:00
}
TARGET_PROPERTIES_DIALOG_EDITOR::TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent,
PCB_TARGET* aTarget, wxDC* DC ) :
TARGET_PROPERTIES_DIALOG_EDITOR_BASE( parent )
2007-05-06 16:03:28 +00:00
{
m_Parent = parent;
2009-08-03 07:55:08 +00:00
m_DC = DC;
m_Target = aTarget;
// Size:
m_staticTextSizeUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
* 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.
2014-03-20 00:42:08 +00:00
m_TargetSizeCtrl->SetValue( StringFromValue( g_UserUnit, m_Target->GetSize() ) );
// Thickness:
m_staticTextThicknessUnits->SetLabel( GetUnitsLabel( g_UserUnit ) );
* 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.
2014-03-20 00:42:08 +00:00
m_TargetThicknessCtrl->SetValue( StringFromValue( g_UserUnit, m_Target->GetWidth() ) );
// Shape
2013-11-18 17:52:18 +00:00
m_TargetShape->SetSelection( m_Target->GetShape() ? 1 : 0 );
// OK button on return key.
SetDefaultItem( m_sdbSizerButtsOK );
// Now all widgets have the size fixed, call FinishDialogSettings
FinishDialogSettings();
2007-05-06 16:03:28 +00:00
}
void TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
EndModal( -1 );
2007-05-06 16:03:28 +00:00
}
/* Updates the different parameters for the component being edited
*/
void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
BOARD_COMMIT commit( m_Parent );
commit.Modify( m_Target );
2014-02-11 16:15:33 +00:00
if( m_DC )
m_Target->Draw( m_Parent->GetCanvas(), m_DC, GR_XOR );
2007-05-06 16:03:28 +00:00
// Save old item in undo list, if is is not currently edited (will be later if so)
bool pushCommit = ( m_Target->GetFlags() == 0 );
2009-08-03 07:55:08 +00:00
if( m_Target->GetFlags() != 0 ) // other edition in progress (MOVE, NEW ..)
m_Target->SetFlags( IN_EDIT ); // set flag in edit to force
// undo/redo/abort proper operation
2009-08-03 07:55:08 +00:00
* 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.
2014-03-20 00:42:08 +00:00
int tmp = ValueFromString( g_UserUnit, m_TargetThicknessCtrl->GetValue() );
m_Target->SetWidth( tmp );
* 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.
2014-03-20 00:42:08 +00:00
MireDefaultSize = ValueFromString( g_UserUnit, m_TargetSizeCtrl->GetValue() );
m_Target->SetSize( MireDefaultSize );
2013-11-18 17:52:18 +00:00
m_Target->SetShape( m_TargetShape->GetSelection() ? 1 : 0 );
2007-05-06 16:03:28 +00:00
2014-02-11 16:15:33 +00:00
if( m_DC )
m_Target->Draw( m_Parent->GetCanvas(), m_DC, ( m_Target->IsMoving() ) ? GR_XOR : GR_OR );
2007-05-06 16:03:28 +00:00
if( pushCommit )
commit.Push( _( "Modified alignment target" ) );
EndModal( 1 );
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::DeleteTarget( PCB_TARGET* aTarget, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( aTarget == NULL )
return;
2007-05-06 16:03:28 +00:00
aTarget->Draw( m_canvas, DC, GR_XOR );
SaveCopyInUndoList( aTarget, UR_DELETED );
aTarget->UnLink();
2007-05-06 16:03:28 +00:00
}
static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
BASE_SCREEN* screen = Panel->GetScreen();
PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem();
( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL );
2009-08-03 07:55:08 +00:00
Panel->SetMouseCapture( NULL, NULL );
if( target == NULL )
2009-08-03 07:55:08 +00:00
return;
target->Draw( Panel, DC, GR_XOR );
if( target->IsNew() ) // If it is new, delete it
{
target->Draw( Panel, DC, GR_XOR );
target->DeleteStructure();
target = NULL;
2009-08-03 07:55:08 +00:00
}
2011-12-14 04:29:25 +00:00
else // it is an existing item: retrieve initial values of parameters
2009-08-03 07:55:08 +00:00
{
if( ( target->GetFlags() & (IN_EDIT | IS_MOVED) ) )
{
2011-12-14 04:29:25 +00:00
target->SetPosition( s_TargetCopy.GetPosition() );
target->SetWidth( s_TargetCopy.GetWidth() );
target->SetSize( s_TargetCopy.GetSize() );
target->SetShape( s_TargetCopy.GetShape() );
}
target->ClearFlags();
target->Draw( Panel, DC, GR_OR );
}
2007-05-06 16:03:28 +00:00
}
PCB_TARGET* PCB_EDIT_FRAME::CreateTarget( wxDC* DC )
2007-05-06 16:03:28 +00:00
{
PCB_TARGET* target = new PCB_TARGET( GetBoard() );
2007-05-06 16:03:28 +00:00
target->SetFlags( IS_NEW );
2009-08-03 07:55:08 +00:00
GetBoard()->Add( target );
2007-05-06 16:03:28 +00:00
target->SetLayer( Edge_Cuts );
target->SetWidth( GetDesignSettings().m_EdgeSegmentWidth );
2011-12-14 04:29:25 +00:00
target->SetSize( MireDefaultSize );
target->SetPosition( GetCrossHairPosition() );
2007-05-06 16:03:28 +00:00
PlaceTarget( target, DC );
2007-05-06 16:03:28 +00:00
return target;
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::BeginMoveTarget( PCB_TARGET* aTarget, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( aTarget == NULL )
return;
s_TargetCopy = *aTarget;
aTarget->SetFlags( IS_MOVED );
m_canvas->SetMouseCapture( ShowTargetShapeWhileMovingMouse, AbortMoveAndEditTarget );
SetCurItem( aTarget );
2007-05-06 16:03:28 +00:00
}
void PCB_EDIT_FRAME::PlaceTarget( PCB_TARGET* aTarget, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( aTarget == NULL )
return;
2007-05-06 16:03:28 +00:00
aTarget->Draw( m_canvas, DC, GR_OR );
m_canvas->SetMouseCapture( NULL, NULL );
SetCurItem( NULL );
OnModify();
2009-08-03 07:55:08 +00:00
if( aTarget->IsNew() )
2009-08-03 07:55:08 +00:00
{
SaveCopyInUndoList( aTarget, UR_NEW );
aTarget->ClearFlags();
2009-08-03 07:55:08 +00:00
return;
}
if( aTarget->GetFlags() == IS_MOVED )
2009-08-03 07:55:08 +00:00
{
SaveCopyInUndoList( aTarget, UR_MOVED,
aTarget->GetPosition() - s_TargetCopy.GetPosition() );
aTarget->ClearFlags();
2009-08-03 07:55:08 +00:00
return;
}
if( (aTarget->GetFlags() & IN_EDIT) )
2009-08-03 07:55:08 +00:00
{
aTarget->SwapData( &s_TargetCopy );
SaveCopyInUndoList( aTarget, UR_CHANGED );
aTarget->SwapData( &s_TargetCopy );
2009-08-03 07:55:08 +00:00
}
aTarget->ClearFlags();
2007-05-06 16:03:28 +00:00
}
// Redraw the contour of the track while moving the mouse
static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aPosition, bool aErase )
2007-05-06 16:03:28 +00:00
{
BASE_SCREEN* screen = aPanel->GetScreen();
PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem();
2007-05-06 16:03:28 +00:00
if( target == NULL )
return;
2007-05-06 16:03:28 +00:00
if( aErase )
target->Draw( aPanel, aDC, GR_XOR );
2007-05-06 16:03:28 +00:00
target->SetPosition( aPanel->GetParent()->GetCrossHairPosition() );
2007-05-06 16:03:28 +00:00
target->Draw( aPanel, aDC, GR_XOR );
2007-05-06 16:03:28 +00:00
}