Eeschema: Added patch from Torsten Huter addeing hotkeys and enhancements in libeditor
Some fixes.
This commit is contained in:
parent
ac97a5746d
commit
edf64afc3b
|
@ -388,6 +388,41 @@ void RotatePoint( double* pX, double* pY, int angle )
|
|||
}
|
||||
|
||||
|
||||
double EuclideanNorm( wxPoint vector )
|
||||
{
|
||||
return sqrt( (double) vector.x * (double) vector.x + (double) vector.y * (double) vector.y );
|
||||
}
|
||||
|
||||
|
||||
wxPoint TwoPointVector( wxPoint startPoint, wxPoint endPoint )
|
||||
{
|
||||
return endPoint - startPoint;
|
||||
}
|
||||
|
||||
|
||||
double DistanceLinePoint( wxPoint linePointA, wxPoint linePointB, wxPoint referencePoint )
|
||||
{
|
||||
return fabs( (linePointB.x - linePointA.x) * (linePointA.y - referencePoint.y) -
|
||||
(linePointA.x - referencePoint.x ) * (linePointB.y - linePointA.y) )
|
||||
/ EuclideanNorm( TwoPointVector( linePointA, linePointB ) );
|
||||
}
|
||||
|
||||
|
||||
bool HitTestPoints( wxPoint pointA, wxPoint pointB, double threshold )
|
||||
{
|
||||
wxPoint vectorAB = TwoPointVector( pointA, pointB );
|
||||
double distance = EuclideanNorm( vectorAB );
|
||||
|
||||
return distance < threshold;
|
||||
}
|
||||
|
||||
|
||||
int CrossProduct( wxPoint vectorA, wxPoint vectorB )
|
||||
{
|
||||
return vectorA.x * vectorB.y - vectorA.y * vectorB.x;
|
||||
}
|
||||
|
||||
|
||||
double fsinus[3600] =
|
||||
{
|
||||
0.0000000000, 0.0017453284, 0.0034906514, 0.0052359638,
|
||||
|
|
|
@ -514,6 +514,10 @@ void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList )
|
|||
|
||||
/* save the new list: */
|
||||
ITEM_PICKER item;
|
||||
// In list the wrapper is owner of the shematic item, we can use the UR_DELETED
|
||||
// status for the picker because pickers with this status are owner of the picked item
|
||||
// (or TODO ?: create a new status like UR_DUPLICATE)
|
||||
item.m_UndoRedoStatus = UR_DELETED;
|
||||
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
|
||||
{
|
||||
/* Make a copy of the original picked item. */
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include "protos.h"
|
||||
#include "classes_body_items.h"
|
||||
|
||||
|
||||
static int fill_tab[3] = { 'N', 'F', 'f' };
|
||||
|
||||
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
|
||||
|
@ -231,13 +230,12 @@ bool LIB_ARC::HitTest( const wxPoint& aRefPoint )
|
|||
int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
|
||||
|
||||
// Have a minimal tolerance for hit test
|
||||
if( mindist < 3 )
|
||||
mindist = 3; // = 3 mils
|
||||
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
||||
mindist = MINIMUM_SELECTION_DISTANCE;
|
||||
|
||||
return HitTest( aRefPoint, mindist, DefaultTransformMatrix );
|
||||
}
|
||||
|
||||
|
||||
/** Function HitTest
|
||||
* @return true if the point aPosRef is near this object
|
||||
* @param aRefPoint = a wxPoint to test
|
||||
|
@ -245,38 +243,45 @@ bool LIB_ARC::HitTest( const wxPoint& aRefPoint )
|
|||
* of a line)
|
||||
* @param aTransMat = the transform matrix
|
||||
*/
|
||||
bool LIB_ARC::HitTest( wxPoint aRefPoint, int aThreshold,
|
||||
const int aTransMat[2][2] )
|
||||
bool LIB_ARC::HitTest( wxPoint aReferencePoint, int aThreshold,
|
||||
const int aTransformationMatrix[2][2] )
|
||||
{
|
||||
|
||||
// TODO: use aTransMat to calculmates parameters
|
||||
wxPoint relpos = aRefPoint;
|
||||
wxPoint relativePosition = aReferencePoint;
|
||||
|
||||
NEGATE( relpos.y ); // reverse Y axis
|
||||
NEGATE( relativePosition.y ); // reverse Y axis
|
||||
|
||||
relpos -= m_Pos;
|
||||
int dist = wxRound( sqrt( ( (double) relpos.x * (double) relpos.x ) +
|
||||
( (double) relpos.y * (double) relpos.y ) ) );
|
||||
int distance = wxRound( EuclideanNorm(TwoPointVector(m_Pos, relativePosition) ) );
|
||||
|
||||
if( abs( dist - m_Radius ) > aThreshold )
|
||||
if( abs( distance - m_Radius ) > aThreshold )
|
||||
return false;
|
||||
|
||||
// We are on the circle, ensure we are only on the arc, i.e. between
|
||||
// m_ArcStart and m_ArcEnd
|
||||
int astart = m_t1; // arc starting point ( in 0.1 degree)
|
||||
int aend = m_t2; // arc ending point ( in 0.1 degree)
|
||||
int atest = wxRound( atan2( (double) relpos.y,
|
||||
(double) relpos.x ) * 1800.0 / M_PI );
|
||||
NORMALIZE_ANGLE_180( atest );
|
||||
NORMALIZE_ANGLE_180( astart );
|
||||
NORMALIZE_ANGLE_180( aend );
|
||||
|
||||
if( astart > aend )
|
||||
EXCHG( astart, aend );
|
||||
wxPoint startEndVector = TwoPointVector( m_ArcStart, m_ArcEnd);
|
||||
wxPoint startRelativePositionVector = TwoPointVector( m_ArcStart, relativePosition);
|
||||
|
||||
if( atest >= astart && atest <= aend )
|
||||
return true;
|
||||
wxPoint centerStartVector = TwoPointVector( m_Pos, m_ArcStart);
|
||||
wxPoint centerEndVector = TwoPointVector( m_Pos, m_ArcEnd);
|
||||
wxPoint centerRelativePositionVector = TwoPointVector( m_Pos, relativePosition);
|
||||
|
||||
return false;
|
||||
// Compute the cross product to check if the point is in the sector
|
||||
int crossProductStart = CrossProduct(centerStartVector, centerRelativePositionVector);
|
||||
int crossProductEnd = CrossProduct(centerEndVector, centerRelativePositionVector);
|
||||
|
||||
// The cross products need to be exchanged, depending on which side the center point
|
||||
// relative to the start point to end point vector lies
|
||||
if (CrossProduct(startEndVector, startRelativePositionVector) < 0 ){
|
||||
EXCHG(crossProductStart, crossProductEnd);
|
||||
}
|
||||
|
||||
// When the cross products have a different sign, the point lies in sector
|
||||
// also check, if the reference is near start or end point
|
||||
return HitTestPoints(m_ArcStart, relativePosition, MINIMUM_SELECTION_DISTANCE) ||
|
||||
HitTestPoints(m_ArcEnd, relativePosition, MINIMUM_SELECTION_DISTANCE) ||
|
||||
(crossProductStart <= 0 && crossProductEnd >= 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -603,8 +608,8 @@ bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
|
|||
int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
|
||||
|
||||
// Have a minimal tolerance for hit test
|
||||
if( mindist < 3 )
|
||||
mindist = 3; // = 3 mils
|
||||
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
||||
mindist = MINIMUM_SELECTION_DISTANCE;
|
||||
|
||||
return HitTest( aPosRef, mindist, DefaultTransformMatrix );
|
||||
}
|
||||
|
@ -811,6 +816,9 @@ LIB_RECTANGLE::LIB_RECTANGLE( LIB_COMPONENT* aParent ) :
|
|||
m_Fill = NO_FILL;
|
||||
m_isFillable = true;
|
||||
m_typeName = _( "Rectangle" );
|
||||
m_isHeightLocked = false;
|
||||
m_isWidthLocked = false;
|
||||
m_isStartPointSelected = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1037,8 +1045,8 @@ bool LIB_RECTANGLE::HitTest( const wxPoint& aRefPoint )
|
|||
int mindist = (m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2) + 1;
|
||||
|
||||
// Have a minimal tolerance for hit test
|
||||
if( mindist < 3 )
|
||||
mindist = 3; // = 3 mils
|
||||
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
||||
mindist = MINIMUM_SELECTION_DISTANCE;
|
||||
|
||||
return HitTest( aRefPoint, mindist, DefaultTransformMatrix );
|
||||
}
|
||||
|
@ -1079,8 +1087,9 @@ bool LIB_RECTANGLE::HitTest( wxPoint aRefPoint, int aThreshold,
|
|||
return true;
|
||||
|
||||
// locate left segment
|
||||
start.x = actualStart.x;
|
||||
end.x = actualStart.y;
|
||||
start = actualStart;
|
||||
end.x = actualStart.x;
|
||||
end.y = actualEnd.y;
|
||||
if( TestSegmentHit( aRefPoint, start, end, aThreshold ) )
|
||||
return true;
|
||||
|
||||
|
@ -1282,8 +1291,8 @@ bool LIB_SEGMENT::HitTest( const wxPoint& aPosRef )
|
|||
int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
|
||||
|
||||
// Have a minimal tolerance for hit test
|
||||
if( mindist < 3 )
|
||||
mindist = 3; // = 3 mils
|
||||
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
||||
mindist = MINIMUM_SELECTION_DISTANCE;
|
||||
|
||||
return HitTest( aPosRef, mindist, DefaultTransformMatrix );
|
||||
}
|
||||
|
@ -1613,8 +1622,8 @@ bool LIB_POLYLINE::HitTest( const wxPoint& aRefPos )
|
|||
int mindist = m_Width ? m_Width / 2 : g_DrawDefaultLineThickness / 2;
|
||||
|
||||
// Have a minimal tolerance for hit test
|
||||
if( mindist < 3 )
|
||||
mindist = 3; // = 3 mils
|
||||
if( mindist < MINIMUM_SELECTION_DISTANCE )
|
||||
mindist = MINIMUM_SELECTION_DISTANCE;
|
||||
return HitTest( aRefPos, mindist, DefaultTransformMatrix );
|
||||
}
|
||||
|
||||
|
@ -1980,8 +1989,8 @@ bool LIB_BEZIER::HitTest( const wxPoint& aRefPos )
|
|||
{
|
||||
int mindist = m_Width ? m_Width /2 : g_DrawDefaultLineThickness / 2;
|
||||
// Have a minimal tolerance for hit test
|
||||
if ( mindist < 3 )
|
||||
mindist = 3; // = 3 mils
|
||||
if ( mindist < MINIMUM_SELECTION_DISTANCE )
|
||||
mindist = MINIMUM_SELECTION_DISTANCE;
|
||||
return HitTest( aRefPos, mindist, DefaultTransformMatrix );
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class LIB_PIN;
|
|||
#define CLOCK_PIN_DIM 40 /* Dim of clock pin symbol. */
|
||||
#define IEEE_SYMBOL_PIN_DIM 40 /* Dim of special pin symbol. */
|
||||
|
||||
|
||||
#define MINIMUM_SELECTION_DISTANCE 15 // Minimum selection distance in mils
|
||||
|
||||
/**
|
||||
* The component library pin object electrical types used in ERC tests.
|
||||
|
@ -978,6 +978,9 @@ public:
|
|||
wxPoint m_End; /* Rectangle end point. */
|
||||
wxPoint m_Pos; /* Rectangle start point. */
|
||||
int m_Width; /* Line width */
|
||||
bool m_isWidthLocked; /* Flag: Keep width locked */
|
||||
bool m_isHeightLocked; /* Flag: Keep height locked */
|
||||
bool m_isStartPointSelected; /* Flag: is the upper left edge selected ? */
|
||||
|
||||
public:
|
||||
LIB_RECTANGLE(LIB_COMPONENT * aParent);
|
||||
|
@ -1146,6 +1149,7 @@ class LIB_POLYLINE : public LIB_DRAW_ITEM
|
|||
public:
|
||||
int m_Width; /* Line width */
|
||||
std::vector<wxPoint> m_PolyPoints; // list of points (>= 2)
|
||||
int m_ModifyIndex; // Index of the polyline point to modify
|
||||
|
||||
public:
|
||||
LIB_POLYLINE(LIB_COMPONENT * aParent);
|
||||
|
|
|
@ -166,6 +166,7 @@ enum id_eeschema_frm
|
|||
ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM,
|
||||
ID_POPUP_LIBEDIT_BODY_EDIT_ITEM,
|
||||
ID_POPUP_LIBEDIT_DELETE_ITEM,
|
||||
ID_POPUP_LIBEDIT_MODIFY_ITEM,
|
||||
ID_POPUP_LIBEDIT_END_CREATE_ITEM,
|
||||
ID_POPUP_LIBEDIT_CANCEL_EDITING,
|
||||
ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST,
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
* added both in eeschema and libedit)
|
||||
* Add the new code in the switch in OnHotKey() function.
|
||||
* when the variable ItemInEdit is true, an item is currently edited.
|
||||
* This can be usefull if the new function cannot be executed while an item is
|
||||
* This can be useful if the new function cannot be executed while an item is
|
||||
* currently being edited
|
||||
* ( For example, one cannot start a new wire when a component is moving.)
|
||||
*
|
||||
|
@ -102,16 +102,16 @@ static Ki_HotkeyInfo HkMirrorXComponent( wxT( "Mirror X Component" ),
|
|||
HK_MIRROR_X_COMPONENT, 'X' );
|
||||
static Ki_HotkeyInfo HkOrientNormalComponent( wxT( "Orient Normal Component" ),
|
||||
HK_ORIENT_NORMAL_COMPONENT, 'N' );
|
||||
static Ki_HotkeyInfo HkRotateComponentOrItem( wxT( "Rotate Schematic Item" ),
|
||||
HK_ROTATE_COMPONENT_OR_ITEM, 'R' );
|
||||
static Ki_HotkeyInfo HkEditComponent( wxT( "Edit Component or Label" ),
|
||||
HK_EDIT_COMPONENT_OR_LABEL, 'E' );
|
||||
static Ki_HotkeyInfo HkRotate( wxT( "Rotate Schematic Item" ),
|
||||
HK_ROTATE, 'R' );
|
||||
static Ki_HotkeyInfo HkEdit( wxT( "Edit Schematic Item" ),
|
||||
HK_EDIT, 'E' );
|
||||
static Ki_HotkeyInfo HkEditComponentValue( wxT( "Edit Component Value" ),
|
||||
HK_EDIT_COMPONENT_VALUE, 'V' );
|
||||
static Ki_HotkeyInfo HkEditComponentFootprint( wxT( "Edit Component Footprint" ),
|
||||
HK_EDIT_COMPONENT_FOOTPRINT,
|
||||
'F' );
|
||||
static Ki_HotkeyInfo HkMoveComponentOrItem( wxT( "Move Schematic Item" ),
|
||||
static Ki_HotkeyInfo HkMove( wxT( "Move Schematic Item" ),
|
||||
HK_MOVE_COMPONENT_OR_ITEM, 'M',
|
||||
ID_POPUP_SCH_MOVE_CMP_REQUEST );
|
||||
|
||||
|
@ -119,8 +119,8 @@ static Ki_HotkeyInfo HkCopyComponentOrText( wxT( "Copy Component or Label" ),
|
|||
HK_COPY_COMPONENT_OR_LABEL, 'C',
|
||||
ID_POPUP_SCH_COPY_ITEM );
|
||||
|
||||
static Ki_HotkeyInfo HkDragComponent( wxT( "Drag Component" ),
|
||||
HK_DRAG_COMPONENT, 'G',
|
||||
static Ki_HotkeyInfo HkDrag( wxT( "Drag Schematic Item" ),
|
||||
HK_DRAG, 'G',
|
||||
ID_POPUP_SCH_DRAG_CMP_REQUEST );
|
||||
static Ki_HotkeyInfo HkMove2Drag( wxT( "Switch move block to drag block" ),
|
||||
HK_MOVEBLOCK_TO_DRAGBLOCK, '\t' );
|
||||
|
@ -130,12 +130,10 @@ static Ki_HotkeyInfo HkDelete( wxT( "Delete Item" ), HK_DELETE, WXK_DELETE );
|
|||
static Ki_HotkeyInfo HkNextSearch( wxT( "Next Search" ), HK_NEXT_SEARCH,
|
||||
WXK_F5 );
|
||||
|
||||
// Library editor:
|
||||
// Special keys for library editor:
|
||||
static Ki_HotkeyInfo HkInsertPin( wxT( "Repeat Pin" ), HK_REPEAT_LAST,
|
||||
WXK_INSERT );
|
||||
static Ki_HotkeyInfo HkEditPin( wxT( "Edit Pin" ), HK_EDIT_PIN, 'E' );
|
||||
static Ki_HotkeyInfo HkMovePin( wxT( "Move Pin" ), HK_LIBEDIT_MOVE_GRAPHIC_ITEM, 'M' );
|
||||
static Ki_HotkeyInfo HkRotatePin( wxT( "Rotate Pin" ), HK_LIBEDIT_ROTATE_PIN, 'R' );
|
||||
static Ki_HotkeyInfo HkDeletePin( wxT( "Delete Pin" ), HK_DELETE_PIN,
|
||||
WXK_DELETE );
|
||||
|
||||
|
@ -144,10 +142,14 @@ static Ki_HotkeyInfo HkDeletePin( wxT( "Delete Pin" ), HK_DELETE_PIN,
|
|||
Ki_HotkeyInfo* s_Common_Hotkey_List[] =
|
||||
{
|
||||
&HkHelp,
|
||||
&HkZoomIn, &HkZoomOut, &HkZoomRedraw,
|
||||
&HkZoomCenter, &HkZoomAuto,
|
||||
&HkZoomIn,
|
||||
&HkZoomOut,
|
||||
&HkZoomRedraw,
|
||||
&HkZoomCenter,
|
||||
&HkZoomAuto,
|
||||
&HkResetLocalCoord,
|
||||
&HkUndo, &HkRedo,
|
||||
&HkUndo,
|
||||
&HkRedo,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -155,12 +157,20 @@ Ki_HotkeyInfo* s_Common_Hotkey_List[] =
|
|||
Ki_HotkeyInfo* s_Schematic_Hotkey_List[] =
|
||||
{
|
||||
&HkNextSearch,
|
||||
&HkDelete, &HkInsert, &HkMove2Drag,
|
||||
&HkMoveComponentOrItem, &HkCopyComponentOrText,
|
||||
&HkDragComponent, &HkAddComponent,
|
||||
&HkRotateComponentOrItem, &HkMirrorXComponent, &HkMirrorYComponent,
|
||||
&HkDelete,
|
||||
&HkInsert,
|
||||
&HkMove2Drag,
|
||||
&HkMove,
|
||||
&HkCopyComponentOrText,
|
||||
&HkDrag,
|
||||
&HkAddComponent,
|
||||
&HkRotate,
|
||||
&HkMirrorXComponent,
|
||||
&HkMirrorYComponent,
|
||||
&HkOrientNormalComponent,
|
||||
&HkEditComponent,&HkEditComponentValue,&HkEditComponentFootprint,
|
||||
&HkEdit,
|
||||
&HkEditComponentValue,
|
||||
&HkEditComponentFootprint,
|
||||
&HkBeginWire,
|
||||
NULL
|
||||
};
|
||||
|
@ -169,10 +179,11 @@ Ki_HotkeyInfo* s_Schematic_Hotkey_List[] =
|
|||
Ki_HotkeyInfo* s_LibEdit_Hotkey_List[] =
|
||||
{
|
||||
&HkInsertPin,
|
||||
&HkEditPin,
|
||||
&HkEdit,
|
||||
&HkMovePin,
|
||||
&HkDeletePin,
|
||||
&HkRotatePin,
|
||||
&HkRotate,
|
||||
&HkDrag,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -336,6 +347,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
break;
|
||||
|
||||
case HK_BEGIN_WIRE:
|
||||
|
||||
/* An item is selected. If edited and not a wire, a new command is not
|
||||
* possible */
|
||||
if( !ItemInEdit && screen->m_BlockLocate.m_State == STATE_NO_BLOCK )
|
||||
|
@ -359,7 +371,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
}
|
||||
break;
|
||||
|
||||
case HK_ROTATE_COMPONENT_OR_ITEM: // Component or other schematic item rotation
|
||||
case HK_ROTATE: // Component or other schematic item rotation
|
||||
|
||||
if( DrawStruct == NULL )
|
||||
{
|
||||
|
@ -400,6 +412,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
case TYPE_SCH_HIERLABEL:
|
||||
wxPostEvent( this, eventRotateText );
|
||||
break;
|
||||
|
||||
case DRAW_PART_TEXT_STRUCT_TYPE:
|
||||
wxPostEvent( this, eventRotateField );
|
||||
|
||||
|
@ -453,7 +466,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
}
|
||||
break;
|
||||
|
||||
case HK_DRAG_COMPONENT: // Start drag component
|
||||
case HK_DRAG: // Start drag
|
||||
case HK_MOVE_COMPONENT_OR_ITEM: // Start move component or other schematic item
|
||||
case HK_COPY_COMPONENT_OR_LABEL: // Duplicate component or text/label
|
||||
if( ItemInEdit )
|
||||
|
@ -470,14 +483,16 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
DrawStruct = LocateSmallestComponent( GetScreen() );
|
||||
if( DrawStruct == NULL )
|
||||
break;
|
||||
if( DrawStruct->Type() == DRAW_SHEET_STRUCT_TYPE ){
|
||||
if( DrawStruct->Type() == DRAW_SHEET_STRUCT_TYPE )
|
||||
{
|
||||
// If it's a sheet, then check if a pinsheet is under the cursor
|
||||
SCH_SHEET_PIN* slabel = LocateSheetLabel( (SCH_SHEET*) DrawStruct,
|
||||
GetScreen()->m_Curseur );
|
||||
if( slabel )
|
||||
DrawStruct = slabel;
|
||||
}
|
||||
if (DrawStruct->Type() == DRAW_JUNCTION_STRUCT_TYPE){
|
||||
if( DrawStruct->Type() == DRAW_JUNCTION_STRUCT_TYPE )
|
||||
{
|
||||
// If it's a junction, pick the underlying wire instead
|
||||
DrawStruct = PickStruct( GetScreen()->m_Curseur, GetScreen(), WIREITEM );
|
||||
}
|
||||
|
@ -494,7 +509,8 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
break;
|
||||
}
|
||||
|
||||
if( DrawStruct && (DrawStruct->m_Flags == 0) ){
|
||||
if( DrawStruct && (DrawStruct->m_Flags == 0) )
|
||||
{
|
||||
GetScreen()->SetCurItem( (SCH_ITEM*) DrawStruct );
|
||||
|
||||
// Create the events for moving a component or other schematic item
|
||||
|
@ -509,7 +525,6 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
|
||||
switch( DrawStruct->Type() )
|
||||
{
|
||||
|
||||
// select the correct event for moving an schematic object
|
||||
// and add it to the event queue
|
||||
case TYPE_SCH_COMPONENT:
|
||||
|
@ -542,7 +557,7 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
|
||||
break;
|
||||
|
||||
case HK_EDIT_COMPONENT_OR_LABEL:
|
||||
case HK_EDIT:
|
||||
|
||||
if( ItemInEdit )
|
||||
break;
|
||||
|
@ -561,9 +576,9 @@ void WinEDA_SchematicFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
|
||||
if( DrawStruct )
|
||||
{
|
||||
|
||||
wxCommandEvent eventEditPinsheet( wxEVT_COMMAND_TOOL_CLICKED,
|
||||
ID_POPUP_SCH_EDIT_SHEET );
|
||||
|
||||
switch( DrawStruct->Type() )
|
||||
{
|
||||
case TYPE_SCH_COMPONENT:
|
||||
|
@ -713,26 +728,54 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
wxBell();
|
||||
break;
|
||||
|
||||
case HK_EDIT_PIN:
|
||||
case HK_EDIT:
|
||||
m_drawItem = LocateItemUsingCursor();
|
||||
|
||||
if( m_drawItem && m_drawItem->Type() == COMPONENT_PIN_DRAW_TYPE )
|
||||
if( m_drawItem )
|
||||
{
|
||||
switch( m_drawItem->Type() )
|
||||
{
|
||||
case COMPONENT_PIN_DRAW_TYPE:
|
||||
cmd.SetId( ID_LIBEDIT_EDIT_PIN );
|
||||
GetEventHandler()->ProcessEvent( cmd );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case HK_LIBEDIT_ROTATE_PIN:
|
||||
case COMPONENT_ARC_DRAW_TYPE:
|
||||
case COMPONENT_CIRCLE_DRAW_TYPE:
|
||||
case COMPONENT_RECT_DRAW_TYPE:
|
||||
case COMPONENT_POLYLINE_DRAW_TYPE:
|
||||
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
||||
cmd.SetId( ID_POPUP_LIBEDIT_BODY_EDIT_ITEM );
|
||||
GetEventHandler()->ProcessEvent( cmd );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case HK_ROTATE:
|
||||
m_drawItem = LocateItemUsingCursor();
|
||||
|
||||
if( m_drawItem && m_drawItem->Type() == COMPONENT_PIN_DRAW_TYPE )
|
||||
if( m_drawItem )
|
||||
{
|
||||
switch( m_drawItem->Type() )
|
||||
{
|
||||
case COMPONENT_PIN_DRAW_TYPE:
|
||||
cmd.SetId( ID_LIBEDIT_ROTATE_PIN );
|
||||
GetEventHandler()->ProcessEvent( cmd );
|
||||
}
|
||||
break;
|
||||
|
||||
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
||||
cmd.SetId( ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT );
|
||||
GetEventHandler()->ProcessEvent( cmd );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
@ -757,5 +800,16 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey,
|
|||
Process_Special_Functions( evt );
|
||||
}
|
||||
break;
|
||||
|
||||
case HK_DRAG:
|
||||
m_drawItem = LocateItemUsingCursor();
|
||||
|
||||
if( m_drawItem )
|
||||
{
|
||||
wxCommandEvent evt;
|
||||
evt.SetId( ID_POPUP_LIBEDIT_MODIFY_ITEM );
|
||||
Process_Special_Functions( evt );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ enum hotkey_id_commnand {
|
|||
HK_UNDO,
|
||||
HK_REDO,
|
||||
HK_MOVEBLOCK_TO_DRAGBLOCK,
|
||||
HK_ROTATE_COMPONENT_OR_ITEM,
|
||||
HK_EDIT_COMPONENT_OR_LABEL,
|
||||
HK_ROTATE,
|
||||
HK_EDIT,
|
||||
HK_EDIT_COMPONENT_VALUE,
|
||||
HK_EDIT_COMPONENT_FOOTPRINT,
|
||||
HK_MIRROR_X_COMPONENT,
|
||||
|
@ -34,7 +34,7 @@ enum hotkey_id_commnand {
|
|||
HK_ORIENT_NORMAL_COMPONENT,
|
||||
HK_MOVE_COMPONENT_OR_ITEM,
|
||||
HK_COPY_COMPONENT_OR_LABEL,
|
||||
HK_DRAG_COMPONENT,
|
||||
HK_DRAG,
|
||||
HK_ADD_NEW_COMPONENT,
|
||||
HK_BEGIN_WIRE
|
||||
};
|
||||
|
|
|
@ -30,6 +30,8 @@ void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
|
|||
{
|
||||
if( DrawEntry && DrawEntry->m_Flags )
|
||||
{
|
||||
// Don't put copy in undo list while resizing (because it's already done)
|
||||
if (!(DrawEntry->m_Flags & IS_RESIZED))
|
||||
SaveCopyInUndoList( m_component );
|
||||
|
||||
switch( DrawEntry->Type() )
|
||||
|
|
|
@ -84,9 +84,17 @@ bool WinEDA_LibeditFrame::OnRightClick( const wxPoint& MousePos,
|
|||
HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST,
|
||||
msg, move_arc_xpm );
|
||||
msg = AddHotkeyName( _( "Drag Arc Size" ), s_Libedit_Hokeys_Descr,
|
||||
HK_DRAG );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM,
|
||||
msg, move_arc_xpm );
|
||||
}
|
||||
|
||||
msg = AddHotkeyName( _( "Edit Arc Options" ), s_Libedit_Hokeys_Descr,
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM,
|
||||
_( "Arc Options" ), options_arc_xpm );
|
||||
msg, options_arc_xpm );
|
||||
|
||||
if( DrawEntry->m_Flags == 0 )
|
||||
{
|
||||
msg = AddHotkeyName( _( "Delete Arc " ), s_Libedit_Hokeys_Descr,
|
||||
|
@ -104,8 +112,20 @@ bool WinEDA_LibeditFrame::OnRightClick( const wxPoint& MousePos,
|
|||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST,
|
||||
msg, move_circle_xpm );
|
||||
}
|
||||
|
||||
if( DrawEntry->m_Flags == 0 )
|
||||
{
|
||||
msg = AddHotkeyName( _( "Drag Circle Outline" ), s_Libedit_Hokeys_Descr,
|
||||
HK_DRAG );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM,
|
||||
msg, move_rectangle_xpm );
|
||||
}
|
||||
|
||||
msg = AddHotkeyName( _( "Edit Circle Options" ), s_Libedit_Hokeys_Descr,
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM,
|
||||
_( "Circle Options" ), options_circle_xpm );
|
||||
msg, options_circle_xpm );
|
||||
|
||||
if( DrawEntry->m_Flags == 0 )
|
||||
{
|
||||
msg = AddHotkeyName( _( "Delete Circle " ),
|
||||
|
@ -118,20 +138,33 @@ bool WinEDA_LibeditFrame::OnRightClick( const wxPoint& MousePos,
|
|||
case COMPONENT_RECT_DRAW_TYPE:
|
||||
if( DrawEntry->m_Flags == 0 )
|
||||
{
|
||||
msg = AddHotkeyName( _( "Move Rect " ), s_Libedit_Hokeys_Descr,
|
||||
msg = AddHotkeyName( _( "Move Rectangle " ), s_Libedit_Hokeys_Descr,
|
||||
HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST,
|
||||
msg, move_rectangle_xpm );
|
||||
}
|
||||
|
||||
msg = AddHotkeyName( _( "Edit Rectangle Options" ), s_Libedit_Hokeys_Descr,
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM,
|
||||
_( "Rect Options" ), options_rectangle_xpm );
|
||||
msg, options_rectangle_xpm );
|
||||
|
||||
if( DrawEntry->m_Flags == 0 )
|
||||
{
|
||||
msg = AddHotkeyName( _( "Delete Rect " ), s_Libedit_Hokeys_Descr,
|
||||
msg = AddHotkeyName( _( "Drag Rectangle Edge" ), s_Libedit_Hokeys_Descr,
|
||||
HK_DRAG );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM,
|
||||
msg, move_rectangle_xpm );
|
||||
}
|
||||
|
||||
if( DrawEntry->m_Flags == 0 )
|
||||
{
|
||||
msg = AddHotkeyName( _( "Delete Rectangle " ), s_Libedit_Hokeys_Descr,
|
||||
HK_DELETE_PIN );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM,
|
||||
msg, delete_rectangle_xpm );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
||||
|
@ -142,10 +175,17 @@ bool WinEDA_LibeditFrame::OnRightClick( const wxPoint& MousePos,
|
|||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST,
|
||||
msg, move_text_xpm );
|
||||
}
|
||||
|
||||
msg = AddHotkeyName( _( "Edit Text " ), s_Libedit_Hokeys_Descr,
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM,
|
||||
_( "Text Editor" ), edit_text_xpm );
|
||||
msg, edit_text_xpm );
|
||||
|
||||
msg = AddHotkeyName( _( "Rotate Text " ), s_Libedit_Hokeys_Descr,
|
||||
HK_ROTATE );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT,
|
||||
_( "Rotate Text" ), edit_text_xpm );
|
||||
msg, edit_text_xpm );
|
||||
|
||||
if( DrawEntry->m_Flags == 0 )
|
||||
{
|
||||
msg = AddHotkeyName( _( "Delete Text " ), s_Libedit_Hokeys_Descr,
|
||||
|
@ -162,14 +202,23 @@ bool WinEDA_LibeditFrame::OnRightClick( const wxPoint& MousePos,
|
|||
HK_LIBEDIT_MOVE_GRAPHIC_ITEM );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST,
|
||||
msg, move_line_xpm );
|
||||
msg = AddHotkeyName( _( "Drag Edge Point" ), s_Libedit_Hokeys_Descr,
|
||||
HK_DRAG );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM,
|
||||
msg, move_line_xpm );
|
||||
}
|
||||
|
||||
if( DrawEntry->m_Flags & IS_NEW )
|
||||
{
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_END_CREATE_ITEM,
|
||||
_( "Line End" ), apply_xpm );
|
||||
}
|
||||
|
||||
msg = AddHotkeyName( _( "Edit Line Options" ), s_Libedit_Hokeys_Descr,
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM,
|
||||
_( "Line Options" ), options_segment_xpm );
|
||||
msg, options_segment_xpm );
|
||||
|
||||
if( DrawEntry->m_Flags == 0 )
|
||||
{
|
||||
msg = AddHotkeyName( _( "Delete Line " ), s_Libedit_Hokeys_Descr,
|
||||
|
@ -188,6 +237,7 @@ bool WinEDA_LibeditFrame::OnRightClick( const wxPoint& MousePos,
|
|||
msg, delete_segment_xpm );
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case COMPONENT_FIELD_DRAW_TYPE:
|
||||
|
@ -236,10 +286,10 @@ void AddMenusForPin( wxMenu* PopMenu,
|
|||
msg, move_xpm );
|
||||
}
|
||||
|
||||
msg = AddHotkeyName( _( "Edit Pin " ), s_Libedit_Hokeys_Descr, HK_EDIT_PIN );
|
||||
msg = AddHotkeyName( _( "Edit Pin " ), s_Libedit_Hokeys_Descr, HK_EDIT);
|
||||
ADD_MENUITEM( PopMenu, ID_LIBEDIT_EDIT_PIN, msg, edit_xpm );
|
||||
|
||||
msg = AddHotkeyName( _( "Rotate Pin " ), s_Libedit_Hokeys_Descr, HK_LIBEDIT_ROTATE_PIN );
|
||||
msg = AddHotkeyName( _( "Rotate Pin " ), s_Libedit_Hokeys_Descr, HK_ROTATE );
|
||||
ADD_MENUITEM( PopMenu, ID_LIBEDIT_ROTATE_PIN, msg, rotate_pin_xpm );
|
||||
|
||||
if( not_in_move )
|
||||
|
|
|
@ -172,6 +172,7 @@ private:
|
|||
LIB_DRAW_ITEM* CreateGraphicItem( LIB_COMPONENT* LibEntry, wxDC* DC );
|
||||
void GraphicItemBeginDraw( wxDC* DC );
|
||||
void StartMoveDrawSymbol( wxDC* DC );
|
||||
void StartModifyDrawSymbol( wxDC* DC ); //<! Modify the item, adjust size etc.
|
||||
void EndDrawGraphicItem( wxDC* DC );
|
||||
void LoadOneSymbol();
|
||||
void SaveOneSymbol();
|
||||
|
|
|
@ -653,6 +653,7 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
|
|||
}
|
||||
|
||||
INSTALL_DC( dc, DrawPanel );
|
||||
|
||||
switch( id )
|
||||
{
|
||||
case ID_POPUP_LIBEDIT_CANCEL_EDITING:
|
||||
|
@ -815,6 +816,24 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
|
|||
StartMoveDrawSymbol( &dc );
|
||||
break;
|
||||
|
||||
case ID_POPUP_LIBEDIT_MODIFY_ITEM:
|
||||
|
||||
if( m_drawItem == NULL )
|
||||
break;
|
||||
|
||||
DrawPanel->MouseToCursorSchema();
|
||||
if( m_drawItem->Type() == COMPONENT_RECT_DRAW_TYPE
|
||||
|| m_drawItem->Type() == COMPONENT_CIRCLE_DRAW_TYPE
|
||||
|| m_drawItem->Type() == COMPONENT_POLYLINE_DRAW_TYPE
|
||||
|| m_drawItem->Type() == COMPONENT_ARC_DRAW_TYPE
|
||||
)
|
||||
{
|
||||
SaveCopyInUndoList( m_component );
|
||||
StartModifyDrawSymbol( &dc );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT:
|
||||
if( m_drawItem == NULL )
|
||||
break;
|
||||
|
@ -914,6 +933,7 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
|
|||
m_lastDrawItem = NULL;
|
||||
}
|
||||
|
||||
|
||||
/** Called on activate the frame.
|
||||
* Test if the current library exists
|
||||
* the library list can be changed by the schematic editor after reloading a new schematic
|
||||
|
@ -928,6 +948,7 @@ void WinEDA_LibeditFrame::OnActivate( wxActivateEvent& event )
|
|||
EnsureActiveLibExists();
|
||||
}
|
||||
|
||||
|
||||
void WinEDA_LibeditFrame::EnsureActiveLibExists()
|
||||
{
|
||||
if( m_library == NULL )
|
||||
|
|
|
@ -247,7 +247,7 @@ void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field )
|
|||
}
|
||||
|
||||
msg = AddHotkeyName( _( "Rotate Field" ),
|
||||
s_Schematic_Hokeys_Descr, HK_ROTATE_COMPONENT_OR_ITEM );
|
||||
s_Schematic_Hokeys_Descr, HK_ROTATE );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_FIELD,
|
||||
msg, rotate_field_xpm );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_FIELD,
|
||||
|
@ -285,14 +285,14 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
|
|||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_CMP_REQUEST,
|
||||
msg, move_xpm );
|
||||
msg = AddHotkeyName( _( "Drag Component" ), s_Schematic_Hokeys_Descr,
|
||||
HK_DRAG_COMPONENT );
|
||||
HK_DRAG );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST,
|
||||
msg, move_xpm );
|
||||
}
|
||||
|
||||
wxMenu* orientmenu = new wxMenu;
|
||||
msg = AddHotkeyName( _( "Rotate +" ), s_Schematic_Hokeys_Descr,
|
||||
HK_ROTATE_COMPONENT_OR_ITEM );
|
||||
HK_ROTATE );
|
||||
ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE,
|
||||
msg, rotate_pos_xpm );
|
||||
ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE,
|
||||
|
@ -312,7 +312,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
|
|||
|
||||
wxMenu* editmenu = new wxMenu;
|
||||
msg = AddHotkeyName( _( "Edit" ), s_Schematic_Hokeys_Descr,
|
||||
HK_EDIT_COMPONENT_OR_LABEL );
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CMP, msg,
|
||||
edit_component_xpm );
|
||||
|
||||
|
@ -393,11 +393,11 @@ void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel )
|
|||
msg, copy_button );
|
||||
}
|
||||
msg = AddHotkeyName( _( "Rotate Global Label" ), s_Schematic_Hokeys_Descr,
|
||||
HK_ROTATE_COMPONENT_OR_ITEM );
|
||||
HK_ROTATE );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT,
|
||||
msg, rotate_glabel_xpm );
|
||||
msg = AddHotkeyName( _( "Edit Global Label" ), s_Schematic_Hokeys_Descr,
|
||||
HK_EDIT_COMPONENT_OR_LABEL );
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT,
|
||||
msg, edit_text_xpm );
|
||||
msg = AddHotkeyName( _( "Delete Global Label" ), s_Schematic_Hokeys_Descr,
|
||||
|
@ -437,11 +437,11 @@ void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel )
|
|||
msg, copy_button );
|
||||
}
|
||||
msg = AddHotkeyName( _( "Rotate Hierarchical Label" ), s_Schematic_Hokeys_Descr,
|
||||
HK_ROTATE_COMPONENT_OR_ITEM );
|
||||
HK_ROTATE );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT,
|
||||
_( "Rotate Hierarchical Label" ), rotate_glabel_xpm );
|
||||
msg = AddHotkeyName( _( "Edit Hierarchical Label" ), s_Schematic_Hokeys_Descr,
|
||||
HK_EDIT_COMPONENT_OR_LABEL );
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT,
|
||||
_( "Edit Hierarchical Label" ), edit_text_xpm );
|
||||
msg = AddHotkeyName( _( "Delete Hierarchical Label" ), s_Schematic_Hokeys_Descr,
|
||||
|
@ -480,11 +480,11 @@ void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label )
|
|||
msg, copy_button );
|
||||
}
|
||||
msg = AddHotkeyName( _( "Rotate Label" ), s_Schematic_Hokeys_Descr,
|
||||
HK_ROTATE_COMPONENT_OR_ITEM );
|
||||
HK_ROTATE );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT,
|
||||
msg, rotate_pos_xpm );
|
||||
msg = AddHotkeyName( _( "Edit Label" ), s_Schematic_Hokeys_Descr,
|
||||
HK_EDIT_COMPONENT_OR_LABEL );
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT,
|
||||
msg, edit_text_xpm );
|
||||
msg = AddHotkeyName( _( "Delete Label" ), s_Schematic_Hokeys_Descr,
|
||||
|
@ -524,11 +524,11 @@ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text )
|
|||
msg, copy_button );
|
||||
}
|
||||
msg = AddHotkeyName( _( "Rotate Text" ), s_Schematic_Hokeys_Descr,
|
||||
HK_ROTATE_COMPONENT_OR_ITEM );
|
||||
HK_ROTATE );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, msg,
|
||||
rotate_pos_xpm );
|
||||
msg = AddHotkeyName( _( "Edit Text" ), s_Schematic_Hokeys_Descr,
|
||||
HK_EDIT_COMPONENT_OR_LABEL );
|
||||
HK_EDIT );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, msg,
|
||||
edit_text_xpm );
|
||||
msg = AddHotkeyName( _( "Delete Text" ), s_Schematic_Hokeys_Descr,
|
||||
|
@ -601,7 +601,7 @@ void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire,
|
|||
}
|
||||
|
||||
msg = AddHotkeyName( _( "Drag Wire" ), s_Schematic_Hokeys_Descr,
|
||||
HK_DRAG_COMPONENT );
|
||||
HK_DRAG );
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_WIRE_REQUEST, msg,
|
||||
move_track_xpm );
|
||||
PopMenu->AppendSeparator();
|
||||
|
@ -688,7 +688,7 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
|
|||
else
|
||||
{
|
||||
msg = AddHotkeyName( _( "Edit Sheet" ),
|
||||
s_Schematic_Hokeys_Descr, HK_EDIT_COMPONENT_OR_LABEL );
|
||||
s_Schematic_Hokeys_Descr, HK_EDIT );
|
||||
|
||||
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_SHEET, msg,
|
||||
edit_sheet_xpm );
|
||||
|
|
|
@ -20,17 +20,44 @@
|
|||
#include "class_libentry.h"
|
||||
#include "dialog_lib_edit_draw_item.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#define EraseItem( item ) item->Draw( Panel, DC, wxPoint( 0,\
|
||||
0 ), -1, g_XorMode, NULL,\
|
||||
DefaultTransformMatrix )
|
||||
|
||||
static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
|
||||
static void ComputeArc( LIB_ARC* DrawItem, wxPoint ArcCentre );
|
||||
static void ComputeArcRadiusAngles( LIB_ARC* arc );
|
||||
static wxPoint ComputeCircumCenter( wxPoint A, wxPoint B, wxPoint C );
|
||||
static void RedrawWhileMovingCursor( WinEDA_DrawPanel* panel,
|
||||
wxDC* DC,
|
||||
bool erase );
|
||||
|
||||
|
||||
static int StateDrawArc, ArcStartX, ArcStartY, ArcEndX, ArcEndY;
|
||||
static wxPoint InitPosition, StartCursor, ItemPreviousPos;
|
||||
|
||||
typedef enum {
|
||||
START_POINT, END_POINT, OUTLINE
|
||||
} SelectedPoint;
|
||||
|
||||
// Attributes of the arc in edit
|
||||
static struct
|
||||
{
|
||||
wxPoint startPoint, endPoint; //!< Start, end coordinates
|
||||
int stateDrawArc; //!< The actual drawing state
|
||||
double distanceCenter; //!< Distance from arc center to middle of start-/end-point
|
||||
SelectedPoint selectedPoint; //!< The selected point while modifying
|
||||
int direction; //!< Determines the side of the center point relative to start/end point
|
||||
} arcState;
|
||||
|
||||
// Structure for saving attributes before modifying graphics objects
|
||||
static struct
|
||||
{
|
||||
wxPoint startPoint;
|
||||
wxPoint endPoint;
|
||||
wxPoint centerPoint;
|
||||
int radius;
|
||||
} savedAttributes;
|
||||
|
||||
/*
|
||||
* Show the dialog box for editing a graphical item properties
|
||||
|
@ -42,31 +69,31 @@ void WinEDA_LibeditFrame::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem )
|
|||
|
||||
LIB_COMPONENT* component = DrawItem->GetParent();
|
||||
|
||||
DIALOG_LIB_EDIT_DRAW_ITEM dlg( this, DrawItem->m_typeName );
|
||||
DIALOG_LIB_EDIT_DRAW_ITEM dialog( this, DrawItem->m_typeName );
|
||||
|
||||
dlg.SetWidthUnits( ReturnUnitSymbol( g_UnitMetric ) );
|
||||
dialog.SetWidthUnits( ReturnUnitSymbol( g_UnitMetric ) );
|
||||
|
||||
wxString val = ReturnStringFromValue( g_UnitMetric, m_drawLineWidth,
|
||||
m_InternalUnits );
|
||||
dlg.SetWidth( val );
|
||||
dlg.SetApplyToAllUnits( !m_drawSpecificUnit );
|
||||
dlg.EnableApplyToAllUnits( component && component->GetPartCount() > 1 );
|
||||
dlg.SetApplyToAllConversions( !m_drawSpecificConvert );
|
||||
dlg.EnableApplyToAllConversions( component && component->HasConversion() );
|
||||
dlg.SetFillStyle( m_drawFillStyle );
|
||||
dlg.EnableFillStyle( DrawItem->IsFillable() );
|
||||
dialog.SetWidth( val );
|
||||
dialog.SetApplyToAllUnits( !m_drawSpecificUnit );
|
||||
dialog.EnableApplyToAllUnits( component && component->GetPartCount() > 1 );
|
||||
dialog.SetApplyToAllConversions( !m_drawSpecificConvert );
|
||||
dialog.EnableApplyToAllConversions( component && component->HasConversion() );
|
||||
dialog.SetFillStyle( m_drawFillStyle );
|
||||
dialog.EnableFillStyle( DrawItem->IsFillable() );
|
||||
|
||||
if( dlg.ShowModal() == wxID_CANCEL )
|
||||
if( dialog.ShowModal() == wxID_CANCEL )
|
||||
return;
|
||||
|
||||
val = dlg.GetWidth();
|
||||
val = dialog.GetWidth();
|
||||
m_drawLineWidth = ReturnValueFromString( g_UnitMetric, val,
|
||||
m_InternalUnits );
|
||||
m_drawSpecificConvert = !dlg.GetApplyToAllConversions();
|
||||
m_drawSpecificUnit = !dlg.GetApplyToAllUnits();
|
||||
m_drawSpecificConvert = !dialog.GetApplyToAllConversions();
|
||||
m_drawSpecificUnit = !dialog.GetApplyToAllUnits();
|
||||
|
||||
if( DrawItem->IsFillable() )
|
||||
m_drawFillStyle = (FILL_T) dlg.GetFillStyle();
|
||||
m_drawFillStyle = (FILL_T) dialog.GetFillStyle();
|
||||
|
||||
// Save copy for undo is done before place.
|
||||
if( !( DrawItem->m_Flags & IS_NEW ) )
|
||||
|
@ -106,7 +133,7 @@ static void AbortSymbolTraceOn( WinEDA_DrawPanel* Panel, wxDC* DC )
|
|||
if( item == NULL )
|
||||
return;
|
||||
|
||||
StateDrawArc = 0;
|
||||
arcState.stateDrawArc = 0;
|
||||
Panel->ManageCurseur = NULL;
|
||||
Panel->ForceCloseManageCurseur = NULL;
|
||||
|
||||
|
@ -125,11 +152,54 @@ static void AbortSymbolTraceOn( WinEDA_DrawPanel* Panel, wxDC* DC )
|
|||
parent->SetDrawItem( NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Restore old attributes, when the item was modified
|
||||
if( item->m_Flags == IS_RESIZED )
|
||||
{
|
||||
EraseItem( item );
|
||||
|
||||
switch( item->Type() )
|
||||
{
|
||||
case COMPONENT_CIRCLE_DRAW_TYPE:
|
||||
( (LIB_CIRCLE*) item )->m_Radius = savedAttributes.radius;
|
||||
break;
|
||||
|
||||
case COMPONENT_RECT_DRAW_TYPE:
|
||||
( (LIB_RECTANGLE*) item )->m_Pos = savedAttributes.startPoint;
|
||||
( (LIB_RECTANGLE*) item )->m_End = savedAttributes.endPoint;
|
||||
break;
|
||||
|
||||
case COMPONENT_POLYLINE_DRAW_TYPE:
|
||||
{
|
||||
wxPoint point = savedAttributes.startPoint;
|
||||
int index = ( (LIB_POLYLINE*) item )->m_ModifyIndex;
|
||||
( ( (LIB_POLYLINE*) item )->m_PolyPoints )[index] = point;
|
||||
}
|
||||
break;
|
||||
|
||||
case COMPONENT_ARC_DRAW_TYPE:
|
||||
( (LIB_ARC*) item )->m_ArcStart = savedAttributes.startPoint;
|
||||
( (LIB_ARC*) item )->m_ArcEnd = savedAttributes.endPoint;
|
||||
( (LIB_ARC*) item )->m_Pos = savedAttributes.centerPoint;
|
||||
|
||||
ComputeArcRadiusAngles( (LIB_ARC*) item );
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
item->m_Flags = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
wxPoint curpos = Panel->GetScreen()->m_Curseur;
|
||||
Panel->GetScreen()->m_Curseur = StartCursor;
|
||||
RedrawWhileMovingCursor( Panel, DC, TRUE );
|
||||
Panel->GetScreen()->m_Curseur = curpos;
|
||||
}
|
||||
|
||||
item->Draw( Panel, DC, wxPoint( 0, 0 ), -1, GR_DEFAULT_DRAWMODE, NULL,
|
||||
DefaultTransformMatrix );
|
||||
item->m_Flags = 0;
|
||||
|
@ -150,9 +220,9 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry,
|
|||
LIB_ARC* Arc = new LIB_ARC( LibEntry );
|
||||
|
||||
m_drawItem = Arc;
|
||||
ArcStartX = ArcEndX = GetScreen()->m_Curseur.x;
|
||||
ArcStartY = ArcEndY = -( GetScreen()->m_Curseur.y );
|
||||
StateDrawArc = 1;
|
||||
arcState.startPoint.x = arcState.endPoint.x = GetScreen()->m_Curseur.x;
|
||||
arcState.startPoint.y = arcState.endPoint.y = -( GetScreen()->m_Curseur.y );
|
||||
arcState.stateDrawArc = 1;
|
||||
Arc->m_Fill = m_drawFillStyle;
|
||||
Arc->m_Width = m_drawLineWidth;
|
||||
}
|
||||
|
@ -272,14 +342,14 @@ void WinEDA_LibeditFrame::GraphicItemBeginDraw( wxDC* DC )
|
|||
switch( m_drawItem->Type() )
|
||||
{
|
||||
case COMPONENT_ARC_DRAW_TYPE:
|
||||
if( StateDrawArc == 1 )
|
||||
if( arcState.stateDrawArc == 1 )
|
||||
{
|
||||
SymbolDisplayDraw( DrawPanel, DC, FALSE );
|
||||
StateDrawArc = 2;
|
||||
arcState.stateDrawArc = 2;
|
||||
SymbolDisplayDraw( DrawPanel, DC, FALSE );
|
||||
break;
|
||||
}
|
||||
if( StateDrawArc > 1 )
|
||||
if( arcState.stateDrawArc > 1 )
|
||||
{
|
||||
EndDrawGraphicItem( DC );
|
||||
return;
|
||||
|
@ -358,13 +428,165 @@ void WinEDA_LibeditFrame::StartMoveDrawSymbol( wxDC* DC )
|
|||
}
|
||||
|
||||
|
||||
/* Manage mouse events when creating new graphic object. */
|
||||
// @brief Modify a graphic symbol (drag edges etc.)
|
||||
void WinEDA_LibeditFrame::StartModifyDrawSymbol( wxDC* DC )
|
||||
{
|
||||
if( m_drawItem == NULL )
|
||||
return;
|
||||
|
||||
// TODO Check if this is really required
|
||||
StartCursor = GetScreen()->m_Curseur;
|
||||
InitPosition = m_drawItem->GetPosition();
|
||||
ItemPreviousPos = GetScreen()->m_Curseur;
|
||||
|
||||
switch( m_drawItem->Type() )
|
||||
{
|
||||
case COMPONENT_ARC_DRAW_TYPE:
|
||||
{
|
||||
wxPoint cursor = StartCursor;
|
||||
cursor.y = -cursor.y;
|
||||
|
||||
// The arc center point has to be rotated with while adjusting the
|
||||
// start or end point, determine the side of this point and the distance
|
||||
// from the start / end point
|
||||
wxPoint startPoint = ( (LIB_ARC*) m_drawItem )->m_ArcStart;
|
||||
wxPoint endPoint = ( (LIB_ARC*) m_drawItem )->m_ArcEnd;
|
||||
wxPoint centerPoint = ( (LIB_ARC*) m_drawItem )->m_Pos;
|
||||
wxPoint middlePoint = wxPoint( (startPoint.x + endPoint.x) / 2,
|
||||
(startPoint.y + endPoint.y) / 2 );
|
||||
wxPoint centerVector = centerPoint - middlePoint;
|
||||
wxPoint startEndVector = TwoPointVector( startPoint, endPoint );
|
||||
arcState.distanceCenter = EuclideanNorm( centerVector );
|
||||
|
||||
// Determine on which side is the center point
|
||||
arcState.direction = CrossProduct( startEndVector, centerVector ) ? 1 : -1;
|
||||
|
||||
arcState.startPoint = startPoint;
|
||||
arcState.endPoint = endPoint;
|
||||
|
||||
// Save the old values
|
||||
savedAttributes.startPoint = startPoint;
|
||||
savedAttributes.endPoint = endPoint;
|
||||
savedAttributes.centerPoint = centerPoint;
|
||||
|
||||
// Drag either the start, end point or the outline
|
||||
if( HitTestPoints( startPoint, cursor, MINIMUM_SELECTION_DISTANCE ) )
|
||||
{
|
||||
arcState.selectedPoint = START_POINT;
|
||||
}
|
||||
else if( HitTestPoints( endPoint, cursor, MINIMUM_SELECTION_DISTANCE ) )
|
||||
{
|
||||
arcState.selectedPoint = END_POINT;
|
||||
}
|
||||
else
|
||||
arcState.selectedPoint = OUTLINE;
|
||||
|
||||
arcState.stateDrawArc = 0;
|
||||
|
||||
m_drawItem->m_Flags |= IS_RESIZED;
|
||||
}
|
||||
break;
|
||||
|
||||
case COMPONENT_RECT_DRAW_TYPE:
|
||||
{
|
||||
// Save old attributes
|
||||
savedAttributes.startPoint = ( (LIB_RECTANGLE*) m_drawItem )->m_Pos;
|
||||
savedAttributes.endPoint = ( (LIB_RECTANGLE*) m_drawItem )->m_End;
|
||||
|
||||
// Resize rectangle
|
||||
m_drawItem->m_Flags |= IS_RESIZED;
|
||||
|
||||
// If the cursor is not on the rectangle edge point,
|
||||
// lock the width or height
|
||||
|
||||
wxPoint rectEnd = ( (LIB_RECTANGLE*) m_drawItem )->m_End;
|
||||
wxPoint rectStart = ( (LIB_RECTANGLE*) m_drawItem )->m_Pos;
|
||||
wxPoint cursor = StartCursor;
|
||||
cursor.y = -cursor.y;
|
||||
|
||||
( (LIB_RECTANGLE*) m_drawItem )->m_isStartPointSelected =
|
||||
abs( rectStart.x - cursor.x ) < MINIMUM_SELECTION_DISTANCE
|
||||
|| abs( rectStart.y - cursor.y ) < MINIMUM_SELECTION_DISTANCE;
|
||||
|
||||
if( ( (LIB_RECTANGLE*) m_drawItem )->m_isStartPointSelected )
|
||||
{
|
||||
( (LIB_RECTANGLE*) m_drawItem )->m_isWidthLocked =
|
||||
abs( rectStart.x - cursor.x ) >= MINIMUM_SELECTION_DISTANCE;
|
||||
|
||||
( (LIB_RECTANGLE*) m_drawItem )->m_isHeightLocked =
|
||||
abs( rectStart.y - cursor.y ) >= MINIMUM_SELECTION_DISTANCE;
|
||||
}
|
||||
else
|
||||
{
|
||||
( (LIB_RECTANGLE*) m_drawItem )->m_isWidthLocked =
|
||||
abs( rectEnd.x - cursor.x ) >= MINIMUM_SELECTION_DISTANCE;
|
||||
|
||||
( (LIB_RECTANGLE*) m_drawItem )->m_isHeightLocked =
|
||||
abs( rectEnd.y - cursor.y ) >= MINIMUM_SELECTION_DISTANCE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case COMPONENT_CIRCLE_DRAW_TYPE:
|
||||
savedAttributes.radius = ( (LIB_CIRCLE*) m_drawItem )->m_Radius;
|
||||
m_drawItem->m_Flags |= IS_RESIZED;
|
||||
break;
|
||||
|
||||
case COMPONENT_POLYLINE_DRAW_TYPE:
|
||||
{
|
||||
// Drag one edge point of the polyline
|
||||
|
||||
m_drawItem->m_Flags |= IS_RESIZED;
|
||||
|
||||
// Find the nearest edge point to be dragged
|
||||
wxPoint cursor = StartCursor;
|
||||
wxPoint startPoint = ( ( (LIB_POLYLINE*) m_drawItem )->m_PolyPoints )[0];
|
||||
cursor.y = NEGATE( cursor.y );
|
||||
|
||||
// Begin with the first list point as nearest point
|
||||
int index = 0;
|
||||
( (LIB_POLYLINE*) m_drawItem )->m_ModifyIndex = 0;
|
||||
savedAttributes.startPoint = startPoint;
|
||||
|
||||
// First distance is the current minimum distance
|
||||
int distanceMin = (cursor - startPoint).x * (cursor - startPoint).x
|
||||
+ (cursor - startPoint).y * (cursor - startPoint).y;
|
||||
|
||||
// Find the right index of the point to be dragged
|
||||
BOOST_FOREACH( wxPoint point, ( ( (LIB_POLYLINE*) m_drawItem )->m_PolyPoints ) ) {
|
||||
int distancePoint = (cursor - point).x * (cursor - point).x +
|
||||
(cursor - point).y * (cursor - point).y;
|
||||
|
||||
if( distancePoint < distanceMin )
|
||||
{
|
||||
// Save point
|
||||
savedAttributes.startPoint = point;
|
||||
|
||||
( (LIB_POLYLINE*) m_drawItem )->m_ModifyIndex = index;
|
||||
distanceMin = distancePoint;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
DrawPanel->ManageCurseur = SymbolDisplayDraw;
|
||||
DrawPanel->ForceCloseManageCurseur = AbortSymbolTraceOn;
|
||||
DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
|
||||
}
|
||||
|
||||
|
||||
//! @brief Manage mouse events when creating new graphic object or modifying an graphic object.
|
||||
static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
||||
{
|
||||
int dx, dy;
|
||||
int DrawMode = g_XorMode;
|
||||
BASE_SCREEN* Screen = panel->GetScreen();
|
||||
wxPoint curr_pos = Screen->m_Curseur;
|
||||
wxPoint currentCursorPosition = Screen->m_Curseur;
|
||||
FILL_T fillStyle = NO_FILL;
|
||||
LIB_DRAW_ITEM* item;
|
||||
|
||||
|
@ -375,30 +597,31 @@ static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
|||
|
||||
fillStyle = ( (WinEDA_LibeditFrame*) panel->GetParent() )->GetFillStyle();
|
||||
|
||||
NEGATE( curr_pos.y );
|
||||
NEGATE( currentCursorPosition.y );
|
||||
|
||||
GRSetDrawMode( DC, DrawMode );
|
||||
|
||||
if( erase )
|
||||
{
|
||||
if( StateDrawArc == 1 )
|
||||
if( arcState.stateDrawArc == 1 )
|
||||
{
|
||||
int Color = ReturnLayerColor( LAYER_DEVICE );
|
||||
GRLine( &panel->m_ClipBox, DC, ArcStartX, -ArcStartY,
|
||||
ArcEndX, -ArcEndY, 0, Color );
|
||||
GRLine( &panel->m_ClipBox, DC, arcState.startPoint.x, -arcState.startPoint.y,
|
||||
arcState.endPoint.x, -arcState.endPoint.y, 0, Color );
|
||||
}
|
||||
else
|
||||
{
|
||||
item->Draw( panel, DC, wxPoint( 0, 0 ), -1, DrawMode, NULL,
|
||||
DefaultTransformMatrix );
|
||||
if( item->Type() == COMPONENT_ARC_DRAW_TYPE )
|
||||
|
||||
if( item->Type() == COMPONENT_ARC_DRAW_TYPE && item->m_Flags != IS_RESIZED )
|
||||
{
|
||||
int Color = ReturnLayerColor( LAYER_DEVICE );
|
||||
GRDashedLine( &panel->m_ClipBox, DC, ArcStartX, -ArcStartY,
|
||||
GRDashedLine( &panel->m_ClipBox, DC, arcState.startPoint.x, -arcState.startPoint.y,
|
||||
( (LIB_ARC*) item )->m_Pos.x,
|
||||
-( (LIB_ARC*) item )->m_Pos.y,
|
||||
0, Color );
|
||||
GRDashedLine( &panel->m_ClipBox, DC, ArcEndX, -ArcEndY,
|
||||
GRDashedLine( &panel->m_ClipBox, DC, arcState.endPoint.x, -arcState.endPoint.y,
|
||||
( (LIB_ARC*) item )->m_Pos.x,
|
||||
-( (LIB_ARC*) item )->m_Pos.y,
|
||||
0, Color );
|
||||
|
@ -409,42 +632,168 @@ static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
|||
switch( item->Type() )
|
||||
{
|
||||
case COMPONENT_ARC_DRAW_TYPE:
|
||||
if( StateDrawArc == 1 )
|
||||
if( item->m_Flags == IS_RESIZED )
|
||||
{
|
||||
ArcEndX = curr_pos.x;
|
||||
ArcEndY = curr_pos.y;
|
||||
wxPoint newCenterPoint;
|
||||
|
||||
// Choose the point of the arc to be adjusted
|
||||
if( arcState.selectedPoint == START_POINT )
|
||||
{
|
||||
arcState.startPoint = currentCursorPosition;
|
||||
arcState.endPoint = ( (LIB_ARC*) item )->m_ArcEnd;
|
||||
}
|
||||
else if( arcState.selectedPoint == END_POINT )
|
||||
{
|
||||
arcState.endPoint = currentCursorPosition;
|
||||
arcState.startPoint = ( (LIB_ARC*) item )->m_ArcStart;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use the cursor for adjusting the arc curvature
|
||||
arcState.startPoint = ( (LIB_ARC*) item )->m_ArcStart;
|
||||
arcState.endPoint = ( (LIB_ARC*) item )->m_ArcEnd;
|
||||
|
||||
wxPoint middlePoint = wxPoint( (arcState.startPoint.x + arcState.endPoint.x) / 2,
|
||||
(arcState.startPoint.y + arcState.endPoint.y) / 2 );
|
||||
|
||||
|
||||
// If the distance is too small, use the old center point
|
||||
// else the new center point is calculated over the three points start/end/cursor
|
||||
if( DistanceLinePoint( arcState.startPoint, arcState.endPoint,
|
||||
currentCursorPosition )
|
||||
> MINIMUM_SELECTION_DISTANCE )
|
||||
{
|
||||
newCenterPoint = ComputeCircumCenter( arcState.startPoint,
|
||||
currentCursorPosition, arcState.endPoint );
|
||||
}
|
||||
else
|
||||
{
|
||||
newCenterPoint = ( (LIB_ARC*) item )->m_Pos;
|
||||
}
|
||||
|
||||
if( StateDrawArc == 2 )
|
||||
// Determine if the arc angle is larger than 180 degrees -> this happens if both
|
||||
// points (cursor position, center point) lie on the same side of the vector start-end
|
||||
int crossA = CrossProduct( TwoPointVector( arcState.startPoint, arcState.endPoint ),
|
||||
TwoPointVector( arcState.endPoint,
|
||||
currentCursorPosition ) );
|
||||
int crossB = CrossProduct( TwoPointVector( arcState.startPoint, arcState.endPoint ),
|
||||
TwoPointVector( arcState.endPoint, newCenterPoint ) );
|
||||
|
||||
bool isLarger180degrees = (crossA < 0 && crossB < 0) || (crossA >=0 && crossB >=0);
|
||||
|
||||
if( isLarger180degrees )
|
||||
newCenterPoint = ( (LIB_ARC*) item )->m_Pos;
|
||||
}
|
||||
|
||||
if( arcState.selectedPoint == START_POINT || arcState.selectedPoint == END_POINT )
|
||||
{
|
||||
// Compute the new center point when the start/end points are modified
|
||||
wxPoint middlePoint = wxPoint( (arcState.startPoint.x + arcState.endPoint.x) / 2,
|
||||
(arcState.startPoint.y + arcState.endPoint.y) / 2 );
|
||||
|
||||
wxPoint startEndVector = TwoPointVector( arcState.startPoint, arcState.endPoint );
|
||||
wxPoint perpendicularVector = wxPoint( -startEndVector.y, startEndVector.x );
|
||||
|
||||
double lengthPerpendicularVector = EuclideanNorm( perpendicularVector );
|
||||
|
||||
// prevent too large values, division / 0
|
||||
if( lengthPerpendicularVector < 1e-1 )
|
||||
lengthPerpendicularVector = 1e-1;
|
||||
|
||||
perpendicularVector.x = (int) ( (double) perpendicularVector.x *
|
||||
arcState.distanceCenter /
|
||||
lengthPerpendicularVector ) * arcState.direction;
|
||||
perpendicularVector.y = (int) ( (double) perpendicularVector.y *
|
||||
arcState.distanceCenter /
|
||||
lengthPerpendicularVector ) * arcState.direction;
|
||||
|
||||
newCenterPoint = middlePoint + perpendicularVector;
|
||||
|
||||
( (LIB_ARC*) item )->m_ArcStart = arcState.startPoint;
|
||||
( (LIB_ARC*) item )->m_ArcEnd = arcState.endPoint;
|
||||
}
|
||||
|
||||
( (LIB_ARC*) item )->m_Pos = newCenterPoint;
|
||||
ComputeArcRadiusAngles( (LIB_ARC*) item );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( arcState.stateDrawArc == 1 )
|
||||
{
|
||||
arcState.endPoint.x = currentCursorPosition.x;
|
||||
arcState.endPoint.y = currentCursorPosition.y;
|
||||
}
|
||||
|
||||
if( arcState.stateDrawArc == 2 )
|
||||
{
|
||||
ComputeArc( (LIB_ARC*) item, Screen->m_Curseur );
|
||||
}
|
||||
item->m_Fill = fillStyle;
|
||||
}
|
||||
break;
|
||||
|
||||
case COMPONENT_CIRCLE_DRAW_TYPE:
|
||||
dx = ( (LIB_CIRCLE*) item )->m_Pos.x - curr_pos.x;
|
||||
dy = ( (LIB_CIRCLE*) item )->m_Pos.y - curr_pos.y;
|
||||
dx = ( (LIB_CIRCLE*) item )->m_Pos.x - currentCursorPosition.x;
|
||||
dy = ( (LIB_CIRCLE*) item )->m_Pos.y - currentCursorPosition.y;
|
||||
( (LIB_CIRCLE*) item )->m_Radius =
|
||||
(int) sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) );
|
||||
item->m_Fill = fillStyle;
|
||||
break;
|
||||
|
||||
case COMPONENT_RECT_DRAW_TYPE:
|
||||
( (LIB_RECTANGLE*) item )->m_End = curr_pos;
|
||||
if( ( (LIB_RECTANGLE*) item )->m_isHeightLocked )
|
||||
{
|
||||
if( ( (LIB_RECTANGLE*) item )->m_isStartPointSelected )
|
||||
{
|
||||
( (LIB_RECTANGLE*) item )->m_Pos.x = currentCursorPosition.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
( (LIB_RECTANGLE*) item )->m_End.x = currentCursorPosition.x;
|
||||
}
|
||||
}
|
||||
else if( ( (LIB_RECTANGLE*) item )->m_isWidthLocked )
|
||||
{
|
||||
if( ( (LIB_RECTANGLE*) item )->m_isStartPointSelected )
|
||||
{
|
||||
( (LIB_RECTANGLE*) item )->m_Pos.y = currentCursorPosition.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
( (LIB_RECTANGLE*) item )->m_End.y = currentCursorPosition.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( (LIB_RECTANGLE*) item )->m_isStartPointSelected )
|
||||
{
|
||||
( (LIB_RECTANGLE*) item )->m_Pos = currentCursorPosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
( (LIB_RECTANGLE*) item )->m_End = currentCursorPosition;
|
||||
}
|
||||
}
|
||||
|
||||
item->m_Fill = fillStyle;
|
||||
break;
|
||||
|
||||
case COMPONENT_POLYLINE_DRAW_TYPE:
|
||||
{
|
||||
unsigned idx = ( (LIB_POLYLINE*) item )->GetCornerCount() - 1;
|
||||
( (LIB_POLYLINE*) item )->m_PolyPoints[idx] = curr_pos;
|
||||
unsigned idx;
|
||||
|
||||
if( item->m_Flags == IS_RESIZED )
|
||||
idx = ( (LIB_POLYLINE*) item )->m_ModifyIndex;
|
||||
else
|
||||
idx = ( (LIB_POLYLINE*) item )->GetCornerCount() - 1;
|
||||
|
||||
( (LIB_POLYLINE*) item )->m_PolyPoints[idx] = currentCursorPosition;
|
||||
item->m_Fill = fillStyle;
|
||||
}
|
||||
break;
|
||||
|
||||
case COMPONENT_LINE_DRAW_TYPE:
|
||||
( (LIB_SEGMENT*) item )->m_End = curr_pos;
|
||||
( (LIB_SEGMENT*) item )->m_End = currentCursorPosition;
|
||||
break;
|
||||
|
||||
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
||||
|
@ -454,25 +803,31 @@ static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
|||
;
|
||||
}
|
||||
|
||||
if( StateDrawArc == 1 )
|
||||
if( arcState.stateDrawArc == 1 )
|
||||
{
|
||||
int Color = ReturnLayerColor( LAYER_DEVICE );
|
||||
GRLine( &panel->m_ClipBox, DC, ArcStartX, -ArcStartY, ArcEndX,
|
||||
-ArcEndY, 0, Color );
|
||||
GRLine( &panel->m_ClipBox,
|
||||
DC,
|
||||
arcState.startPoint.x,
|
||||
-arcState.startPoint.y,
|
||||
arcState.endPoint.x,
|
||||
-arcState.endPoint.y,
|
||||
0,
|
||||
Color );
|
||||
}
|
||||
else
|
||||
{
|
||||
item->Draw( panel, DC, wxPoint( 0, 0 ), -1, DrawMode, NULL,
|
||||
DefaultTransformMatrix );
|
||||
|
||||
if( item->Type() == COMPONENT_ARC_DRAW_TYPE )
|
||||
if( item->Type() == COMPONENT_ARC_DRAW_TYPE && item->m_Flags != IS_RESIZED )
|
||||
{
|
||||
int Color = ReturnLayerColor( LAYER_DEVICE );
|
||||
GRDashedLine( &panel->m_ClipBox, DC, ArcStartX, -ArcStartY,
|
||||
GRDashedLine( &panel->m_ClipBox, DC, arcState.startPoint.x, -arcState.startPoint.y,
|
||||
( (LIB_ARC*) item )->m_Pos.x,
|
||||
-( (LIB_ARC*) item )->m_Pos.y,
|
||||
0, Color );
|
||||
GRDashedLine( &panel->m_ClipBox, DC, ArcEndX, -ArcEndY,
|
||||
GRDashedLine( &panel->m_ClipBox, DC, arcState.endPoint.x, -arcState.endPoint.y,
|
||||
( (LIB_ARC*) item )->m_Pos.x,
|
||||
-( (LIB_ARC*) item )->m_Pos.y,
|
||||
0, Color );
|
||||
|
@ -491,7 +846,7 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC )
|
|||
|
||||
if( m_drawItem->Type() == COMPONENT_ARC_DRAW_TYPE )
|
||||
{
|
||||
if( StateDrawArc == 1 ) /* Trace arc under way must be completed. */
|
||||
if( arcState.stateDrawArc == 1 ) /* Trace arc under way must be completed. */
|
||||
{
|
||||
DisplayError( this, wxT( "Arc in progress.." ) );
|
||||
return;
|
||||
|
@ -503,7 +858,7 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC )
|
|||
}
|
||||
}
|
||||
|
||||
StateDrawArc = 0;
|
||||
arcState.stateDrawArc = 0;
|
||||
|
||||
if( m_drawItem->m_Flags & IS_NEW )
|
||||
{
|
||||
|
@ -522,6 +877,8 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC )
|
|||
|
||||
case COMPONENT_RECT_DRAW_TYPE:
|
||||
( (LIB_RECTANGLE*) m_drawItem )->m_Fill = m_drawFillStyle;
|
||||
( (LIB_RECTANGLE*) m_drawItem )->m_isHeightLocked = false;
|
||||
( (LIB_RECTANGLE*) m_drawItem )->m_isWidthLocked = false;
|
||||
break;
|
||||
|
||||
case COMPONENT_POLYLINE_DRAW_TYPE:
|
||||
|
@ -565,10 +922,60 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC )
|
|||
}
|
||||
|
||||
|
||||
//! @brief Compute the missing attributes (angles, radius),
|
||||
// when the three points (start, end, center) given
|
||||
//! @param arc Arc to be modified
|
||||
static void ComputeArcRadiusAngles( LIB_ARC* arc )
|
||||
{
|
||||
wxPoint centerStartVector = TwoPointVector( arc->m_Pos, arc->m_ArcStart );
|
||||
wxPoint centerEndVector = TwoPointVector( arc->m_Pos, arc->m_ArcEnd );
|
||||
|
||||
arc->m_Radius = EuclideanNorm( centerStartVector );
|
||||
|
||||
arc->m_t1 = (int) ( atan2( (double) centerStartVector.y,
|
||||
(double) centerStartVector.x ) * 1800 / M_PI );
|
||||
|
||||
arc->m_t2 = (int) ( atan2( (double) centerEndVector.y,
|
||||
(double) centerEndVector.x ) * 1800 / M_PI );
|
||||
|
||||
NORMALIZE_ANGLE( arc->m_t1 );
|
||||
NORMALIZE_ANGLE( arc->m_t2 ); // angles = 0 .. 3600
|
||||
|
||||
// Restrict angle to less than 180 to avoid PBS display mirror
|
||||
// Trace because it is assumed that the arc is less than 180 deg to find
|
||||
// orientation after rotate or mirror.
|
||||
if( (arc->m_t2 - arc->m_t1) > 1800 )
|
||||
arc->m_t2 -= 3600;
|
||||
else if( (arc->m_t2 - arc->m_t1) <= -1800 )
|
||||
arc->m_t2 += 3600;
|
||||
|
||||
wxString msg;
|
||||
int angle = arc->m_t2 - arc->m_t1;
|
||||
msg.Printf( _( "Arc %.1f deg" ), (float) angle / 10 );
|
||||
WinEDA_SchematicFrame* frame =
|
||||
(WinEDA_SchematicFrame*) wxGetApp().GetTopWindow();
|
||||
frame->m_LibeditFrame->PrintMsg( msg );
|
||||
|
||||
while( (arc->m_t2 - arc->m_t1) >= 1800 )
|
||||
{
|
||||
arc->m_t2--;
|
||||
arc->m_t1++;
|
||||
}
|
||||
|
||||
while( (arc->m_t1 - arc->m_t2) >= 1800 )
|
||||
{
|
||||
arc->m_t2++;
|
||||
arc->m_t1--;
|
||||
}
|
||||
|
||||
NORMALIZE_ANGLE( arc->m_t1 );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Routine for adjusting the parameters of the arc currently being drawn.
|
||||
* Calculates the center, radius, angles for the arc current
|
||||
* Passes through the points ArcStartX, ArcEndX Y and Y with the nearest center
|
||||
* Passes through the points arcState.startPoint.x, arcState.endPoint.x Y and Y with the nearest center
|
||||
* of the mouse position.
|
||||
* Note: The center is obviously not on the grid
|
||||
*/
|
||||
|
@ -583,12 +990,12 @@ static void ComputeArc( LIB_ARC* DrawItem, wxPoint ArcCentre )
|
|||
|
||||
cY = -cY; /* Attention to the orientation of the axis Y. */
|
||||
|
||||
/* Calculating cX and cY for the arc passes through ArcStartX, ArcEndX,
|
||||
/* Calculating cX and cY for the arc passes through arcState.startPoint.x, arcState.endPoint.x,
|
||||
* X and Y */
|
||||
dx = ArcEndX - ArcStartX;
|
||||
dy = ArcEndY - ArcStartY;
|
||||
cX -= ArcStartX;
|
||||
cY -= ArcStartY;
|
||||
dx = arcState.endPoint.x - arcState.startPoint.x;
|
||||
dy = arcState.endPoint.y - arcState.startPoint.y;
|
||||
cX -= arcState.startPoint.x;
|
||||
cY -= arcState.startPoint.y;
|
||||
angle = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
|
||||
RotatePoint( &dx, &dy, angle ); /* The segment dx, dy is horizontal
|
||||
* -> Length = dx, dy = 0 */
|
||||
|
@ -596,28 +1003,28 @@ static void ComputeArc( LIB_ARC* DrawItem, wxPoint ArcCentre )
|
|||
cX = dx / 2; /* cX, cY is on the median segment 0.0 a dx, 0 */
|
||||
|
||||
RotatePoint( &cX, &cY, -angle );
|
||||
cX += ArcStartX;
|
||||
cY += ArcStartY;
|
||||
cX += arcState.startPoint.x;
|
||||
cY += arcState.startPoint.y;
|
||||
DrawItem->m_Pos.x = cX;
|
||||
DrawItem->m_Pos.y = cY;
|
||||
|
||||
dx = ArcStartX - DrawItem->m_Pos.x;
|
||||
dy = ArcStartY - DrawItem->m_Pos.y;
|
||||
dx = arcState.startPoint.x - DrawItem->m_Pos.x;
|
||||
dy = arcState.startPoint.y - DrawItem->m_Pos.y;
|
||||
|
||||
DrawItem->m_Radius = (int) sqrt( ( (double) dx * dx ) +
|
||||
( (double) dy * dy ) );
|
||||
|
||||
DrawItem->m_t1 = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
|
||||
|
||||
dx = ArcEndX - DrawItem->m_Pos.x;
|
||||
dy = ArcEndY - DrawItem->m_Pos.y;
|
||||
dx = arcState.endPoint.x - DrawItem->m_Pos.x;
|
||||
dy = arcState.endPoint.y - DrawItem->m_Pos.y;
|
||||
|
||||
DrawItem->m_t2 = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
|
||||
|
||||
DrawItem->m_ArcStart.x = ArcStartX;
|
||||
DrawItem->m_ArcStart.y = ArcStartY;
|
||||
DrawItem->m_ArcEnd.x = ArcEndX;
|
||||
DrawItem->m_ArcEnd.y = ArcEndY;
|
||||
DrawItem->m_ArcStart.x = arcState.startPoint.x;
|
||||
DrawItem->m_ArcStart.y = arcState.startPoint.y;
|
||||
DrawItem->m_ArcEnd.x = arcState.endPoint.x;
|
||||
DrawItem->m_ArcEnd.y = arcState.endPoint.y;
|
||||
|
||||
NORMALIZE_ANGLE( DrawItem->m_t1 );
|
||||
NORMALIZE_ANGLE( DrawItem->m_t2 ); // angles = 0 .. 3600
|
||||
|
@ -654,6 +1061,42 @@ static void ComputeArc( LIB_ARC* DrawItem, wxPoint ArcCentre )
|
|||
}
|
||||
|
||||
|
||||
//! @brief Given three points A B C, compute the circumcenter of the resulting triangle
|
||||
//! reference: http://en.wikipedia.org/wiki/Circumscribed_circle
|
||||
//! Coordinates of circumcenter in Cartesian coordinates
|
||||
static wxPoint ComputeCircumCenter( wxPoint A, wxPoint B, wxPoint C )
|
||||
{
|
||||
double circumCenterX, circumCenterY;
|
||||
double Ax = (double) A.x;
|
||||
double Ay = (double) A.y;
|
||||
double Bx = (double) B.x;
|
||||
double By = (double) B.y;
|
||||
double Cx = (double) C.x;
|
||||
double Cy = (double) C.y;
|
||||
|
||||
wxPoint circumCenter;
|
||||
|
||||
double D = 2.0 * ( Ax * ( By - Cy ) + Bx * ( Cy - Ay ) + Cx * ( Ay - By ) );
|
||||
|
||||
// prevent division / 0
|
||||
if( fabs( D ) < 1e-7 )
|
||||
D = 1e-7;
|
||||
|
||||
circumCenterX = ( (Ay * Ay + Ax * Ax) * (By - Cy) +
|
||||
(By * By + Bx * Bx) * (Cy - Ay) +
|
||||
(Cy * Cy + Cx * Cx) * (Ay - By) ) / D;
|
||||
|
||||
circumCenterY = ( (Ay * Ay + Ax * Ax) * (Cx - Bx) +
|
||||
(By * By + Bx * Bx) * (Ax - Cx) +
|
||||
(Cy * Cy + Cx * Cx) * (Bx - Ax) ) / D;
|
||||
|
||||
circumCenter.x = (int) circumCenterX;
|
||||
circumCenter.y = (int) circumCenterY;
|
||||
|
||||
return circumCenter;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Used for deleting last entered segment while creating a Polyline
|
||||
*/
|
||||
|
|
|
@ -22,6 +22,36 @@ int ArcTangente( int dy, int dx );
|
|||
|
||||
bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY );
|
||||
|
||||
//! @brief Compute the distance between a line and a reference point
|
||||
//! Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
|
||||
//! @param linePointA Point on line
|
||||
//! @param linePointB Point on line
|
||||
//! @param referencePoint Reference point
|
||||
double DistanceLinePoint(wxPoint linePointA, wxPoint linePointB, wxPoint referencePoint);
|
||||
|
||||
//! @brief Euclidean norm of a 2D vector
|
||||
//! @param vector Two-dimensional vector
|
||||
//! @return Euclidean norm of the vector
|
||||
double EuclideanNorm(wxPoint vector);
|
||||
|
||||
//! @brief Vector between two points
|
||||
//! @param startPoint The start point
|
||||
//! @param endPoint The end point
|
||||
//! @return Vector between the points
|
||||
wxPoint TwoPointVector(wxPoint startPoint, wxPoint endPoint);
|
||||
|
||||
//! @brief Test, if two points are near each other
|
||||
//! @param pointA First point
|
||||
//! @param pointB Second point
|
||||
//! @param threshold The maximum distance
|
||||
//! @return True or false
|
||||
bool HitTestPoints(wxPoint pointA, wxPoint pointB, double threshold);
|
||||
|
||||
//! @brief Determine the cross product
|
||||
//! @param vectorA Two-dimensional vector
|
||||
//! @param vectorB Two-dimensional vector
|
||||
int CrossProduct(wxPoint vectorA, wxPoint vectorB);
|
||||
|
||||
|
||||
/** Function TestSegmentHit
|
||||
* test for hit on line segment
|
||||
|
@ -34,6 +64,8 @@ bool DistanceTest( int seuil, int dx, int dy, int spot_cX, int spot_cY );
|
|||
bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd,
|
||||
int aDist );
|
||||
|
||||
|
||||
|
||||
/*******************/
|
||||
/* Macro NEW_COORD */
|
||||
/*******************/
|
||||
|
|
Loading…
Reference in New Issue