kicad/pcbnew/edgemod.cpp

441 lines
13 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) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.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 edgemod.cpp:
* @brief Functions to edit graphic items used to draw footprint edges.
*
* @todo - Arc functions not compete but menus are ready to use.
*/
2007-05-06 16:03:28 +00:00
#include <fctsys.h>
#include <trigo.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <wxPcbStruct.h>
#include <base_units.h>
#include <module_editor_frame.h>
#include <class_board.h>
#include <class_module.h>
#include <class_edge_mod.h>
#include <pcbnew.h>
2007-05-06 16:03:28 +00:00
static void ShowNewEdgeModule( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool erase );
static void Abort_Move_ModuleOutline( EDA_DRAW_PANEL* Panel, wxDC* DC );
static void ShowCurrentOutlineWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aPosition, bool aErase );
2007-05-06 16:03:28 +00:00
2011-12-14 04:29:25 +00:00
static double ArcValue = 900;
static wxPoint MoveVector; // Move vector for move edge
static wxPoint CursorInitialPosition; // Mouse cursor initial position for move command
2007-05-06 16:03:28 +00:00
void FOOTPRINT_EDIT_FRAME::Start_Move_EdgeMod( EDGE_MODULE* aEdge, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
if( aEdge == NULL )
return;
aEdge->Draw( m_canvas, DC, GR_XOR );
aEdge->SetFlags( IS_MOVED );
MoveVector.x = MoveVector.y = 0;
CursorInitialPosition = GetCrossHairPosition();
m_canvas->SetMouseCapture( ShowCurrentOutlineWhileMoving, Abort_Move_ModuleOutline );
SetCurItem( aEdge );
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
2007-05-06 16:03:28 +00:00
}
2011-12-14 04:29:25 +00:00
void FOOTPRINT_EDIT_FRAME::Place_EdgeMod( EDGE_MODULE* aEdge )
2007-05-06 16:03:28 +00:00
{
2011-12-14 04:29:25 +00:00
if( aEdge == NULL )
return;
2011-12-14 04:29:25 +00:00
aEdge->SetStart( aEdge->GetStart() - MoveVector );
aEdge->SetEnd( aEdge->GetEnd() - MoveVector );
2011-12-14 04:29:25 +00:00
aEdge->SetStart0( aEdge->GetStart0() - MoveVector );
aEdge->SetEnd0( aEdge->GetEnd0() - MoveVector );
aEdge->ClearFlags();
m_canvas->SetMouseCapture( NULL, NULL );
SetCurItem( NULL );
OnModify();
2011-12-14 04:29:25 +00:00
MODULE* module = (MODULE*) aEdge->GetParent();
module->CalculateBoundingBox();
m_canvas->Refresh( );
2007-05-06 16:03:28 +00:00
}
/* Redraw the current moved graphic item when mouse is moving
* Use this function to show an existing outline, in move command
*/
static void ShowCurrentOutlineWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aPosition, bool aErase )
2007-05-06 16:03:28 +00:00
{
BASE_SCREEN* screen = aPanel->GetScreen();
EDGE_MODULE* edge = (EDGE_MODULE*) screen->GetCurItem();
2007-05-06 16:03:28 +00:00
if( edge == NULL )
return;
2007-05-06 16:03:28 +00:00
MODULE* module = (MODULE*) edge->GetParent();
2007-05-06 16:03:28 +00:00
if( aErase )
{
edge->Draw( aPanel, aDC, GR_XOR, MoveVector );
}
2007-05-06 16:03:28 +00:00
MoveVector = -(aPanel->GetParent()->GetCrossHairPosition() - CursorInitialPosition);
2007-05-06 16:03:28 +00:00
edge->Draw( aPanel, aDC, GR_XOR, MoveVector );
2007-05-06 16:03:28 +00:00
module->CalculateBoundingBox();
2007-05-06 16:03:28 +00:00
}
/* Redraw the current graphic item during its creation
* Use this function to show a new outline, in begin command
*/
static void ShowNewEdgeModule( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
bool aErase )
2007-05-06 16:03:28 +00:00
{
BASE_SCREEN* screen = aPanel->GetScreen();
EDGE_MODULE* edge = (EDGE_MODULE*) screen->GetCurItem();
2007-05-06 16:03:28 +00:00
if( edge == NULL )
return;
2007-05-06 16:03:28 +00:00
MODULE* module = (MODULE*) edge->GetParent();
2007-05-06 16:03:28 +00:00
// if( erase )
{
edge->Draw( aPanel, aDC, GR_XOR );
}
2007-05-06 16:03:28 +00:00
edge->SetEnd( aPanel->GetParent()->GetCrossHairPosition() );
2007-05-06 16:03:28 +00:00
2011-12-14 04:29:25 +00:00
// Update relative coordinate.
edge->SetEnd0( edge->GetEnd() - module->GetPosition() );
2011-12-14 04:29:25 +00:00
wxPoint pt( edge->GetEnd0() );
2011-12-14 04:29:25 +00:00
RotatePoint( &pt, -module->GetOrientation() );
edge->SetEnd0( pt );
2007-05-06 16:03:28 +00:00
edge->Draw( aPanel, aDC, GR_XOR );
2007-05-06 16:03:28 +00:00
2011-12-14 04:29:25 +00:00
module->CalculateBoundingBox();
2007-05-06 16:03:28 +00:00
}
void FOOTPRINT_EDIT_FRAME::Edit_Edge_Width( EDGE_MODULE* aEdge )
2007-05-06 16:03:28 +00:00
{
MODULE* module = GetBoard()->m_Modules;
SaveCopyInUndoList( module, UR_MODEDIT );
2010-07-20 18:11:34 +00:00
if( aEdge == NULL )
{
aEdge = (EDGE_MODULE*) (BOARD_ITEM*) module->GraphicalItems();
for( BOARD_ITEM *item = module->GraphicalItems(); item; item = item->Next() )
{
aEdge = dynamic_cast<EDGE_MODULE*>( item );
if( aEdge )
aEdge->SetWidth( GetDesignSettings().m_ModuleSegmentWidth );
}
}
else
{
aEdge->SetWidth( GetDesignSettings().m_ModuleSegmentWidth );
}
OnModify();
module->CalculateBoundingBox();
module->SetLastEditTime();
2007-05-06 16:03:28 +00:00
}
void FOOTPRINT_EDIT_FRAME::Edit_Edge_Layer( EDGE_MODULE* aEdge )
2007-05-06 16:03:28 +00:00
{
// note: if aEdge == NULL, all outline segments will be modified
MODULE* module = GetBoard()->m_Modules;
LAYER_NUM layer = SILKSCREEN_N_FRONT;
bool modified = false;
if( aEdge )
layer = aEdge->GetLayer();
// Ask for the new layer
LAYER_NUM new_layer = SelectLayer(layer, EDGE_LAYER );
if( layer < 0 )
return;
if( IsCopperLayer( new_layer ) )
2008-04-01 05:21:50 +00:00
{
/* an edge is put on a copper layer, and it is very dangerous. a
*confirmation is requested */
if( !IsOK( this,
_( "The graphic item will be on a copper layer. This is very dangerous. Are you sure?" ) ) )
2008-04-01 05:21:50 +00:00
return;
}
if( aEdge == NULL )
{
for( BOARD_ITEM *item = module->GraphicalItems() ; item != NULL;
item = item->Next() )
{
aEdge = dynamic_cast<EDGE_MODULE*>( item );
if( aEdge && (aEdge->GetLayer() != new_layer) )
{
if( ! modified ) // save only once
SaveCopyInUndoList( module, UR_MODEDIT );
aEdge->SetLayer( new_layer );
modified = true;
}
}
}
else if( aEdge->GetLayer() != new_layer )
{
SaveCopyInUndoList( module, UR_MODEDIT );
aEdge->SetLayer( new_layer );
modified = true;
}
if( modified )
{
module->CalculateBoundingBox();
module->SetLastEditTime();
}
2007-05-06 16:03:28 +00:00
}
void FOOTPRINT_EDIT_FRAME::Enter_Edge_Width( EDGE_MODULE* aEdge )
2007-05-06 16:03:28 +00:00
{
wxString buffer;
* 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
buffer = StringFromValue( g_UserUnit, GetDesignSettings().m_ModuleSegmentWidth );
2010-07-20 18:11:34 +00:00
wxTextEntryDialog dlg( this, _( "New Width:" ), _( "Edge Width" ), buffer );
2010-07-20 18:11:34 +00:00
if( dlg.ShowModal() != wxID_OK )
return; // canceled by user
2010-07-20 18:11:34 +00:00
buffer = dlg.GetValue( );
* 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
GetDesignSettings().m_ModuleSegmentWidth = ValueFromString( g_UserUnit, buffer );
2010-07-20 18:11:34 +00:00
if( aEdge )
{
2011-12-14 04:29:25 +00:00
MODULE* module = GetBoard()->m_Modules;
aEdge->SetWidth( GetDesignSettings().m_ModuleSegmentWidth );
2011-12-14 04:29:25 +00:00
module->CalculateBoundingBox();
OnModify();
}
2007-05-06 16:03:28 +00:00
}
void FOOTPRINT_EDIT_FRAME::Delete_Edge_Module( EDGE_MODULE* aEdge )
2007-05-06 16:03:28 +00:00
{
if( aEdge == NULL )
return;
if( aEdge->Type() != PCB_MODULE_EDGE_T )
{
DisplayError( this, wxT( "StructType error: PCB_MODULE_EDGE_T expected" ) );
return;
}
MODULE* module = (MODULE*) aEdge->GetParent();
// Delete segment.
aEdge->DeleteStructure();
module->SetLastEditTime();
module->CalculateBoundingBox();
OnModify();
2007-05-06 16:03:28 +00:00
}
/* abort function in moving outline.
*/
static void Abort_Move_ModuleOutline( EDA_DRAW_PANEL* Panel, wxDC* DC )
2007-05-06 16:03:28 +00:00
{
EDGE_MODULE* edge = (EDGE_MODULE*) Panel->GetScreen()->GetCurItem();
Panel->SetMouseCapture( NULL, NULL );
if( edge && ( edge->Type() == PCB_MODULE_EDGE_T ) )
{
if( edge->IsNew() ) // On aborting, delete new outline.
{
MODULE* module = (MODULE*) edge->GetParent();
edge->Draw( Panel, DC, GR_XOR, MoveVector );
edge->DeleteStructure();
module->CalculateBoundingBox();
}
else // On aborting, move existing outline to its initial position.
{
edge->Draw( Panel, DC, GR_XOR, MoveVector );
edge->ClearFlags();
edge->Draw( Panel, DC, GR_OR );
}
}
Panel->GetScreen()->SetCurItem( NULL );
2007-05-06 16:03:28 +00:00
}
EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge,
wxDC* DC,
2012-05-22 17:51:18 +00:00
STROKE_T type_edge )
2007-05-06 16:03:28 +00:00
{
MODULE* module = GetBoard()->m_Modules;
2008-12-06 08:21:54 +00:00
if( module == NULL )
return NULL;
if( aEdge == NULL ) // Start a new edge item
{
SaveCopyInUndoList( module, UR_MODEDIT );
2008-12-06 08:21:54 +00:00
aEdge = new EDGE_MODULE( module );
MoveVector.x = MoveVector.y = 0;
2011-12-14 04:29:25 +00:00
// Add the new item to the Drawings list head
module->GraphicalItems().PushFront( aEdge );
2011-12-14 04:29:25 +00:00
// Update characteristics of the segment or arc.
aEdge->SetFlags( IS_NEW );
aEdge->SetAngle( 0 );
aEdge->SetShape( type_edge );
2008-12-06 08:21:54 +00:00
if( aEdge->GetShape() == S_ARC )
aEdge->SetAngle( ArcValue );
2008-12-06 08:21:54 +00:00
aEdge->SetWidth( GetDesignSettings().m_ModuleSegmentWidth );
aEdge->SetLayer( module->GetLayer() );
2008-12-06 08:21:54 +00:00
// The default layer for an edge is the corresponding silk layer
if( module->IsFlipped() )
aEdge->SetLayer( SILKSCREEN_N_BACK );
else
aEdge->SetLayer( SILKSCREEN_N_FRONT );
2008-12-06 08:21:54 +00:00
2011-12-14 04:29:25 +00:00
// Initialize the starting point of the new segment or arc
aEdge->SetStart( GetCrossHairPosition() );
2008-12-06 08:21:54 +00:00
2011-12-14 04:29:25 +00:00
// Initialize the ending point of the new segment or arc
aEdge->SetEnd( aEdge->GetStart() );
2011-12-14 04:29:25 +00:00
// Initialize the relative coordinates
aEdge->SetStart0( aEdge->GetStart() - module->GetPosition() );
2008-12-06 08:21:54 +00:00
RotatePoint( &aEdge->m_Start0, -module->GetOrientation() );
2008-12-06 08:21:54 +00:00
aEdge->m_End0 = aEdge->m_Start0;
module->CalculateBoundingBox();
m_canvas->SetMouseCapture( ShowNewEdgeModule, Abort_Move_ModuleOutline );
}
2009-11-15 14:12:53 +00:00
/* Segment creation in progress.
* The ending coordinate is updated by the function
* ShowNewEdgeModule() called on move mouse event
* during the segment creation
2008-12-06 08:21:54 +00:00
*/
else
{
if( type_edge == S_SEGMENT )
{
if( aEdge->m_Start0 != aEdge->m_End0 )
{
aEdge->Draw( m_canvas, DC, GR_OR );
2008-12-06 08:21:54 +00:00
EDGE_MODULE* newedge = new EDGE_MODULE( *aEdge );
2008-12-06 08:21:54 +00:00
// insert _after_ aEdge, which is the same as inserting before aEdge->Next()
module->GraphicalItems().Insert( newedge, aEdge->Next() );
aEdge->ClearFlags();
aEdge = newedge; // point now new item
aEdge->SetFlags( IS_NEW );
aEdge->SetWidth( GetDesignSettings().m_ModuleSegmentWidth );
aEdge->SetStart( GetCrossHairPosition() );
aEdge->SetEnd( aEdge->GetStart() );
2011-12-14 04:29:25 +00:00
// Update relative coordinate.
aEdge->SetStart0( aEdge->GetStart() - module->GetPosition() );
2011-12-14 04:29:25 +00:00
wxPoint pt( aEdge->GetStart0() );
2011-12-14 04:29:25 +00:00
RotatePoint( &pt, -module->GetOrientation() );
2008-12-06 08:21:54 +00:00
aEdge->SetStart0( pt );
2008-12-06 08:21:54 +00:00
aEdge->SetEnd0( aEdge->GetStart0() );
module->CalculateBoundingBox();
module->SetLastEditTime();
OnModify();
}
}
else
{
wxMessageBox( wxT( "Begin_Edge() error" ) );
}
}
return aEdge;
2007-05-06 16:03:28 +00:00
}
void FOOTPRINT_EDIT_FRAME::End_Edge_Module( EDGE_MODULE* aEdge )
2007-05-06 16:03:28 +00:00
{
MODULE* module = GetBoard()->m_Modules;
if( aEdge )
{
aEdge->ClearFlags();
// If last segment length is 0: remove it
if( aEdge->GetStart() == aEdge->GetEnd() )
aEdge->DeleteStructure();
}
module->CalculateBoundingBox();
module->SetLastEditTime();
OnModify();
m_canvas->SetMouseCapture( NULL, NULL );
2007-05-06 16:03:28 +00:00
}