kicad/pcbnew/onleftclick.cpp

451 lines
14 KiB
C++
Raw Normal View History

2007-09-29 15:30:16 +00:00
/**************************************************************/
/* onleftclick.cpp: */
/* function called when the left button is clicked (released) */
/* function called when the left button is double clicked */
/**************************************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "pcbnew.h"
#include "autorout.h"
#include "id.h"
#include "protos.h"
#include "eda_dde.h"
/********************************************************************/
void WinEDA_PcbFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
/********************************************************************/
/* Handle the left buttom mouse click, when a tool is active
*/
{
BOARD_ITEM* DrawStruct = GetCurItem();
2008-02-23 04:53:44 +00:00
bool exit = false;
2007-09-29 15:30:16 +00:00
if( (m_ID_current_state == 0) || ( DrawStruct && DrawStruct->m_Flags ) )
{
DrawPanel->m_AutoPAN_Request = FALSE;
if( DrawStruct && DrawStruct->m_Flags ) // "POPUP" in progress
{
2008-02-23 04:53:44 +00:00
DrawPanel->m_IgnoreMouseEvents = TRUE;
DrawPanel->CursorOff( DC );
2007-09-29 15:30:16 +00:00
switch( DrawStruct->Type() )
{
case TYPEZONE_CONTAINER:
2008-02-23 04:53:44 +00:00
if ( (DrawStruct->m_Flags & IS_NEW) )
Begin_Zone( DC );
else
2008-02-23 04:53:44 +00:00
End_Move_Zone_Corner_Or_Outlines( DC, (ZONE_CONTAINER *) DrawStruct );
exit = true;
break;
2007-09-29 15:30:16 +00:00
case TYPETRACK:
case TYPEVIA:
if( DrawStruct->m_Flags & IS_DRAGGED )
{
PlaceDraggedTrackSegment( (TRACK*) DrawStruct, DC );
exit = true;
}
break;
case TYPETEXTE:
Place_Texte_Pcb( (TEXTE_PCB*) DrawStruct, DC );
exit = true;
break;
case TYPETEXTEMODULE:
PlaceTexteModule( (TEXTE_MODULE*) DrawStruct, DC );
exit = true;
break;
case TYPEPAD:
PlacePad( (D_PAD*) DrawStruct, DC );
exit = true;
break;
case TYPEMODULE:
Place_Module( (MODULE*) DrawStruct, DC );
exit = true;
break;
case TYPEMIRE:
Place_Mire( (MIREPCB*) DrawStruct, DC );
exit = true;
break;
case TYPEDRAWSEGMENT:
if( m_ID_current_state == 0 )
{
Place_DrawItem( (DRAWSEGMENT*) DrawStruct, DC );
exit = true;
}
break;
default:
if( m_ID_current_state == 0 )
{
DisplayError( this,
2008-01-14 19:24:41 +00:00
wxT( "WinEDA_PcbFrame::OnLeftClick() err: DrawType %d m_Flags != 0" ), DrawStruct->Type() );
2007-09-29 15:30:16 +00:00
exit = true;
}
2008-02-23 04:53:44 +00:00
break;
2007-09-29 15:30:16 +00:00
}
2008-02-23 04:53:44 +00:00
DrawPanel->m_IgnoreMouseEvents = FALSE;
DrawPanel->CursorOn( DC );
if ( exit ) return;
2007-09-29 15:30:16 +00:00
}
2008-02-23 04:53:44 +00:00
2007-09-29 15:30:16 +00:00
else if( !wxGetKeyState(WXK_SHIFT) && !wxGetKeyState(WXK_ALT) &&
!wxGetKeyState(WXK_CONTROL) )
{
DrawStruct = PcbGeneralLocateAndDisplay();
if( DrawStruct )
SendMessageToEESCHEMA( DrawStruct );
2008-02-23 04:53:44 +00:00
}
2007-09-29 15:30:16 +00:00
}
2008-02-23 04:53:44 +00:00
2007-09-29 15:30:16 +00:00
switch( m_ID_current_state )
{
case ID_MAIN_MENUBAR:
case 0:
break;
case ID_NO_SELECT_BUTT:
break;
case ID_PCB_MUWAVE_TOOL_SELF_CMD:
case ID_PCB_MUWAVE_TOOL_GAP_CMD:
case ID_PCB_MUWAVE_TOOL_STUB_CMD:
case ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD:
case ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD:
MuWaveCommand( DC, MousePos );
break;
case ID_PCB_HIGHLIGHT_BUTT:
2008-02-23 04:53:44 +00:00
{
int netcode = Select_High_Light( DC );
if( netcode < 0 )
m_Pcb->Display_Infos( this );
else
Affiche_Infos_Equipot( netcode, this );
}
2007-09-29 15:30:16 +00:00
break;
case ID_PCB_SHOW_1_RATSNEST_BUTT:
DrawStruct = PcbGeneralLocateAndDisplay();
Show_1_Ratsnest( DrawStruct, DC );
2008-02-23 04:53:44 +00:00
2007-09-29 15:30:16 +00:00
if( DrawStruct )
SendMessageToEESCHEMA( DrawStruct );
break;
case ID_PCB_MIRE_BUTT:
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
{
SetCurItem( Create_Mire( DC ) );
DrawPanel->MouseToCursorSchema();
}
else if( DrawStruct->Type() == TYPEMIRE )
{
Place_Mire( (MIREPCB*) DrawStruct, DC );
}
else
DisplayError( this, wxT( "Internal err: Struct not TYPEMIRE" ) );
break;
case ID_PCB_CIRCLE_BUTT:
case ID_PCB_ARC_BUTT:
case ID_LINE_COMMENT_BUTT:
{
int shape = S_SEGMENT;
if( m_ID_current_state == ID_PCB_CIRCLE_BUTT )
shape = S_CIRCLE;
if( m_ID_current_state == ID_PCB_ARC_BUTT )
shape = S_ARC;
2008-02-23 04:53:44 +00:00
if( ((PCB_SCREEN*)GetScreen())->m_Active_Layer <= LAST_COPPER_LAYER )
2007-09-29 15:30:16 +00:00
{
DisplayError( this, _( "Graphic not authorized on Copper layers" ) );
2007-09-29 15:30:16 +00:00
break;
}
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
{
2008-02-23 04:53:44 +00:00
DrawStruct = Begin_DrawSegment( NULL, shape, DC );
2007-09-29 15:30:16 +00:00
SetCurItem( DrawStruct );
DrawPanel->m_AutoPAN_Request = TRUE;
}
else if( DrawStruct
&& (DrawStruct->Type() == TYPEDRAWSEGMENT)
&& (DrawStruct->m_Flags & IS_NEW) )
{
DrawStruct = Begin_DrawSegment( (DRAWSEGMENT*) DrawStruct, shape, DC );
SetCurItem( DrawStruct );
DrawPanel->m_AutoPAN_Request = TRUE;
}
break;
}
case ID_TRACK_BUTT:
2008-02-23 04:53:44 +00:00
if( ((PCB_SCREEN*)GetScreen())->m_Active_Layer > LAST_COPPER_LAYER )
2007-09-29 15:30:16 +00:00
{
DisplayError( this, _( "Tracks on Copper layers only " ) );
break;
}
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
{
DrawStruct = Begin_Route( NULL, DC );
SetCurItem( DrawStruct );
if( DrawStruct )
DrawPanel->m_AutoPAN_Request = TRUE;
}
else if( DrawStruct &&
// (DrawStruct->Type() == TYPETRACK) &&
(DrawStruct->m_Flags & IS_NEW) )
{
TRACK* track = Begin_Route( (TRACK*) DrawStruct, DC );
if( track ) // c'est a dire si OK
SetCurItem( DrawStruct = track );
DrawPanel->m_AutoPAN_Request = TRUE;
}
break;
case ID_PCB_ZONES_BUTT:
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
{
2008-02-23 04:53:44 +00:00
if ( Begin_Zone( DC ) )
{
DrawStruct = m_Pcb->m_CurrentZoneContour;
GetScreen()->SetCurItem( DrawStruct );
}
2007-09-29 15:30:16 +00:00
}
else if( DrawStruct
&& (DrawStruct->Type() == TYPEZONE_CONTAINER)
2007-09-29 15:30:16 +00:00
&& (DrawStruct->m_Flags & IS_NEW) )
{
2008-02-23 04:53:44 +00:00
Begin_Zone( DC );
DrawStruct = m_Pcb->m_CurrentZoneContour;
GetScreen()->SetCurItem( DrawStruct );
2007-09-29 15:30:16 +00:00
}
else
DisplayError( this, wxT( "Edit: zone internal error" ) );
break;
case ID_TEXT_COMMENT_BUTT:
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
{
SetCurItem( Create_Texte_Pcb( DC ) );
DrawPanel->MouseToCursorSchema();
DrawPanel->m_AutoPAN_Request = TRUE;
}
else if( DrawStruct->Type() == TYPETEXTE )
{
Place_Texte_Pcb( (TEXTE_PCB*) DrawStruct, DC );
DrawPanel->m_AutoPAN_Request = FALSE;
}
else
DisplayError( this, wxT( "Internal err: Struct not TYPETEXTE" ) );
break;
case ID_COMPONENT_BUTT:
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
{
DrawPanel->MouseToCursorSchema();
2008-02-23 04:53:44 +00:00
DrawStruct = Load_Module_From_Library( wxEmptyString, DC );
2007-09-29 15:30:16 +00:00
SetCurItem( DrawStruct );
if( DrawStruct )
StartMove_Module( (MODULE*) DrawStruct, DC );
}
else if( DrawStruct->Type() == TYPEMODULE )
{
Place_Module( (MODULE*) DrawStruct, DC );
DrawPanel->m_AutoPAN_Request = FALSE;
}
else
DisplayError( this, wxT( "Internal err: Struct not TYPEMODULE" ) );
break;
case ID_PCB_COTATION_BUTT:
2008-02-23 04:53:44 +00:00
if( ((PCB_SCREEN*)GetScreen())->m_Active_Layer <= LAST_COPPER_LAYER )
2007-09-29 15:30:16 +00:00
{
DisplayError( this, _( "Cotation not authorized on Copper layers" ) );
2007-09-29 15:30:16 +00:00
break;
}
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
{
DrawStruct = Begin_Cotation( NULL, DC );
SetCurItem( DrawStruct );
DrawPanel->m_AutoPAN_Request = TRUE;
}
else if( DrawStruct
&& (DrawStruct->Type() == TYPECOTATION)
&& (DrawStruct->m_Flags & IS_NEW) )
{
2008-02-23 04:53:44 +00:00
DrawStruct = Begin_Cotation( (COTATION*) DrawStruct, DC );
2007-09-29 15:30:16 +00:00
SetCurItem( DrawStruct );
DrawPanel->m_AutoPAN_Request = TRUE;
}
else
DisplayError( this, wxT( "Internal err: Struct not COTATION" ) );
break;
case ID_PCB_DELETE_ITEM_BUTT:
if( !DrawStruct || (DrawStruct->m_Flags == 0) )
{
DrawStruct = PcbGeneralLocateAndDisplay();
if( DrawStruct && (DrawStruct->m_Flags == 0) )
{
RemoveStruct( DrawStruct, DC );
SetCurItem( DrawStruct = NULL );
}
}
break;
case ID_PCB_PLACE_OFFSET_COORD_BUTT:
DrawPanel->m_Draw_Auxiliary_Axis( DC, GR_XOR );
m_Auxiliary_Axis_Position = GetScreen()->m_Curseur;
DrawPanel->m_Draw_Auxiliary_Axis( DC, GR_COPY );
GetScreen()->SetModify();
break;
default:
DrawPanel->SetCursor( wxCURSOR_ARROW );
DisplayError( this, wxT( "WinEDA_PcbFrame::OnLeftClick() id error" ) );
SetToolID( 0, wxCURSOR_ARROW, wxEmptyString );
break;
}
}
/********************************************************************************/
void WinEDA_PcbFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
/********************************************************************************/
2008-02-23 04:53:44 +00:00
/* handle the double click on the mouse left button
2007-09-29 15:30:16 +00:00
*/
{
BOARD_ITEM* DrawStruct = GetCurItem();
wxPoint pos = GetPosition();
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
switch( m_ID_current_state )
{
case 0:
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
{
DrawStruct = PcbGeneralLocateAndDisplay();
}
if( (DrawStruct == NULL) || (DrawStruct->m_Flags != 0) )
break;
SendMessageToEESCHEMA( DrawStruct );
// An item is found
SetCurItem( DrawStruct );
switch( DrawStruct->Type() )
{
case TYPETRACK:
case TYPEVIA:
if( DrawStruct->m_Flags & IS_NEW )
{
End_Route( (TRACK*) DrawStruct, DC );
DrawPanel->m_AutoPAN_Request = FALSE;
}
else if( DrawStruct->m_Flags == 0 )
{
Edit_TrackSegm_Width( DC, (TRACK*) DrawStruct );
}
break;
case TYPETEXTE:
InstallTextPCBOptionsFrame( (TEXTE_PCB*) DrawStruct,
DC, ( (TEXTE_PCB*) DrawStruct )->m_Pos );
DrawPanel->MouseToCursorSchema();
break;
case TYPEPAD:
InstallPadOptionsFrame( (D_PAD*) DrawStruct, &dc, pos );
DrawPanel->MouseToCursorSchema();
break;
case TYPEMODULE:
InstallModuleOptionsFrame( (MODULE*) DrawStruct, &dc, pos );
DrawPanel->MouseToCursorSchema();
break;
case TYPEMIRE:
InstallMireOptionsFrame( (MIREPCB*) DrawStruct, &dc, pos );
DrawPanel->MouseToCursorSchema();
break;
case TYPETEXTEMODULE:
InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, &dc, pos );
DrawPanel->MouseToCursorSchema();
break;
case TYPEDRAWSEGMENT:
break;
case TYPEZONE_CONTAINER:
if( DrawStruct->m_Flags )
break;
Edit_Zone_Params( &dc, (ZONE_CONTAINER*) DrawStruct );
break;
2007-09-29 15:30:16 +00:00
default:
break;
}
break; // end case 0
case ID_TRACK_BUTT:
if( DrawStruct && (DrawStruct->m_Flags & IS_NEW) )
{
End_Route( (TRACK*) DrawStruct, DC );
DrawPanel->m_AutoPAN_Request = FALSE;
}
break;
case ID_PCB_ZONES_BUTT:
if ( End_Zone( DC ) )
2008-02-23 04:53:44 +00:00
{
DrawPanel->m_AutoPAN_Request = FALSE;
SetCurItem( NULL );
}
2007-09-29 15:30:16 +00:00
break;
case ID_LINE_COMMENT_BUTT:
case ID_PCB_ARC_BUTT:
case ID_PCB_CIRCLE_BUTT:
if( DrawStruct == NULL )
break;
if( DrawStruct->Type() != TYPEDRAWSEGMENT )
{
DisplayError( this, wxT( "DrawStruct Type error" ) );
DrawPanel->m_AutoPAN_Request = FALSE;
break;
}
if( (DrawStruct->m_Flags & IS_NEW) )
{
End_Edge( (DRAWSEGMENT*) DrawStruct, &dc );
DrawPanel->m_AutoPAN_Request = FALSE;
SetCurItem( NULL );
}
break;
}
}