2007-08-24 15:10:46 +00:00
|
|
|
/*********************************************************************/
|
2009-09-04 18:57:37 +00:00
|
|
|
/* EESchema - symbdraw.cpp */
|
2007-08-24 15:10:46 +00:00
|
|
|
/* Create, move .. graphic shapes used to build and draw a component */
|
2009-09-04 18:57:37 +00:00
|
|
|
/* (lines, arcs .. */
|
2007-08-24 15:10:46 +00:00
|
|
|
/*********************************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "eeschema_id.h"
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
#include "protos.h"
|
2010-02-16 16:21:52 +00:00
|
|
|
#include "libeditframe.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_libentry.h"
|
2009-10-20 19:36:58 +00:00
|
|
|
#include "dialog_lib_edit_draw_item.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
#include <boost/foreach.hpp>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
#define EraseItem( item ) item->Draw( Panel, DC, wxPoint( 0,\
|
|
|
|
0 ), -1, g_XorMode, NULL,\
|
|
|
|
DefaultTransformMatrix )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
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 );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
static wxPoint InitPosition, StartCursor, ItemPreviousPos;
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
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;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
/*
|
|
|
|
* Show the dialog box for editing a graphical item properties
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2009-10-20 19:36:58 +00:00
|
|
|
void WinEDA_LibeditFrame::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-10-20 19:36:58 +00:00
|
|
|
if( DrawItem == NULL )
|
2009-09-25 18:49:04 +00:00
|
|
|
return;
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
LIB_COMPONENT* component = DrawItem->GetParent();
|
2008-09-09 16:56:47 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
DIALOG_LIB_EDIT_DRAW_ITEM dialog( this, DrawItem->m_typeName );
|
2008-09-09 16:56:47 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
dialog.SetWidthUnits( ReturnUnitSymbol( g_UnitMetric ) );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
wxString val = ReturnStringFromValue( g_UnitMetric, m_drawLineWidth,
|
|
|
|
m_InternalUnits );
|
2010-02-04 17:46:12 +00:00
|
|
|
dialog.SetWidth( val );
|
|
|
|
dialog.SetApplyToAllUnits( !m_drawSpecificUnit );
|
|
|
|
dialog.EnableApplyToAllUnits( component && component->GetPartCount() > 1 );
|
|
|
|
dialog.SetApplyToAllConversions( !m_drawSpecificConvert );
|
|
|
|
dialog.EnableApplyToAllConversions( component && component->HasConversion() );
|
2010-02-25 19:45:34 +00:00
|
|
|
// dialog.SetFillStyle( m_drawFillStyle ); // could better to show the current setting
|
|
|
|
dialog.SetFillStyle( DrawItem->m_Fill);
|
2010-02-04 17:46:12 +00:00
|
|
|
dialog.EnableFillStyle( DrawItem->IsFillable() );
|
|
|
|
|
|
|
|
if( dialog.ShowModal() == wxID_CANCEL )
|
2009-10-20 19:36:58 +00:00
|
|
|
return;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
val = dialog.GetWidth();
|
|
|
|
m_drawLineWidth = ReturnValueFromString( g_UnitMetric, val,
|
|
|
|
m_InternalUnits );
|
|
|
|
m_drawSpecificConvert = !dialog.GetApplyToAllConversions();
|
|
|
|
m_drawSpecificUnit = !dialog.GetApplyToAllUnits();
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-25 19:45:34 +00:00
|
|
|
#if 0
|
|
|
|
/* TODO: see if m_drawFillStyle must retain the last fill option or not.
|
|
|
|
* if the last is Filled, having next new graphic items created
|
|
|
|
* with filled body is often bad.
|
|
|
|
* currently m_drawFillStyle is left with the defualt value (not filled)
|
|
|
|
*/
|
2009-10-20 19:36:58 +00:00
|
|
|
if( DrawItem->IsFillable() )
|
2010-02-04 17:46:12 +00:00
|
|
|
m_drawFillStyle = (FILL_T) dialog.GetFillStyle();
|
2010-02-25 19:45:34 +00:00
|
|
|
#endif
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
// Save copy for undo is done before place.
|
|
|
|
if( !( DrawItem->m_Flags & IS_NEW ) )
|
|
|
|
SaveCopyInUndoList( DrawItem->GetParent() );
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
if( m_drawSpecificUnit )
|
|
|
|
DrawItem->m_Unit = GetUnit();
|
|
|
|
else
|
|
|
|
DrawItem->m_Unit = 0;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
if( m_drawSpecificConvert )
|
|
|
|
DrawItem->m_Convert = GetConvert();
|
|
|
|
else
|
|
|
|
DrawItem->m_Convert = 0;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
if( DrawItem->IsFillable() )
|
2010-02-25 19:45:34 +00:00
|
|
|
DrawItem->m_Fill = (FILL_T) dialog.GetFillStyle();
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
DrawItem->SetWidth( m_drawLineWidth );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
if( component )
|
|
|
|
component->GetDrawItemList().sort();
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
DrawItem->DisplayInfo( this );
|
|
|
|
DrawPanel->Refresh();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
static void AbortSymbolTraceOn( WinEDA_DrawPanel* Panel, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-02-04 17:46:12 +00:00
|
|
|
LIB_DRAW_ITEM* item;
|
|
|
|
WinEDA_LibeditFrame* parent = (WinEDA_LibeditFrame*) Panel->GetParent();
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
item = parent->GetDrawItem();
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
return;
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
arcState.stateDrawArc = 0;
|
|
|
|
Panel->ManageCurseur = NULL;
|
2007-08-24 15:10:46 +00:00
|
|
|
Panel->ForceCloseManageCurseur = NULL;
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( item->m_Flags & IS_NEW )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2010-01-13 13:43:36 +00:00
|
|
|
if( DC )
|
|
|
|
{
|
|
|
|
if( item->Type() == COMPONENT_ARC_DRAW_TYPE )
|
2010-02-04 17:46:12 +00:00
|
|
|
Panel->GetParent()->DrawPanel->Refresh();
|
2010-01-13 13:43:36 +00:00
|
|
|
else
|
|
|
|
item->Draw( Panel, DC, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
|
|
|
|
DefaultTransformMatrix );
|
|
|
|
}
|
2009-09-04 18:57:37 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
SAFE_DELETE( item );
|
2009-09-29 18:38:21 +00:00
|
|
|
parent->SetDrawItem( NULL );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-04 17:46:12 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
item->Draw( Panel, DC, wxPoint( 0, 0 ), -1, GR_DEFAULT_DRAWMODE, NULL,
|
|
|
|
DefaultTransformMatrix );
|
|
|
|
item->m_Flags = 0;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry,
|
|
|
|
wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
DrawPanel->ManageCurseur = SymbolDisplayDraw;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = AbortSymbolTraceOn;
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
switch( m_ID_current_state )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
case ID_LIBEDIT_BODY_ARC_BUTT:
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_ARC* Arc = new LIB_ARC( LibEntry );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem = Arc;
|
2010-02-04 17:46:12 +00:00
|
|
|
arcState.startPoint.x = arcState.endPoint.x = GetScreen()->m_Curseur.x;
|
|
|
|
arcState.startPoint.y = arcState.endPoint.y = -( GetScreen()->m_Curseur.y );
|
|
|
|
arcState.stateDrawArc = 1;
|
2009-10-20 19:36:58 +00:00
|
|
|
Arc->m_Fill = m_drawFillStyle;
|
|
|
|
Arc->m_Width = m_drawLineWidth;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-12-08 15:27:13 +00:00
|
|
|
break;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
case ID_LIBEDIT_BODY_CIRCLE_BUTT:
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_CIRCLE* Circle = new LIB_CIRCLE( LibEntry );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
m_drawItem = Circle;
|
|
|
|
Circle->m_Pos = GetScreen()->m_Curseur;
|
2009-06-18 13:30:52 +00:00
|
|
|
NEGATE( Circle->m_Pos.y );
|
2009-10-20 19:36:58 +00:00
|
|
|
Circle->m_Fill = m_drawFillStyle;
|
|
|
|
Circle->m_Width = m_drawLineWidth;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-12-08 15:27:13 +00:00
|
|
|
break;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
case ID_LIBEDIT_BODY_RECT_BUTT:
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_RECTANGLE* Square = new LIB_RECTANGLE( LibEntry );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
m_drawItem = Square;
|
|
|
|
Square->m_Pos = GetScreen()->m_Curseur;
|
2009-06-18 13:30:52 +00:00
|
|
|
NEGATE( Square->m_Pos.y );
|
2007-08-24 15:10:46 +00:00
|
|
|
Square->m_End = Square->m_Pos;
|
2009-10-20 19:36:58 +00:00
|
|
|
Square->m_Fill = m_drawFillStyle;
|
|
|
|
Square->m_Width = m_drawLineWidth;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-12-08 15:27:13 +00:00
|
|
|
break;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
case ID_LIBEDIT_BODY_LINE_BUTT:
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_POLYLINE* polyline = new LIB_POLYLINE( LibEntry );
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem = polyline;
|
2010-02-04 17:46:12 +00:00
|
|
|
wxPoint point = GetScreen()->m_Curseur;
|
2009-01-02 13:19:34 +00:00
|
|
|
NEGATE( point.y );
|
|
|
|
polyline->AddPoint( point ); // Start point of the current segment
|
|
|
|
polyline->AddPoint( point ); // End point of the current segment
|
2009-10-20 19:36:58 +00:00
|
|
|
polyline->m_Fill = m_drawFillStyle;
|
|
|
|
polyline->m_Width = m_drawLineWidth;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-12-08 15:27:13 +00:00
|
|
|
break;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
case COMPONENT_LINE_DRAW_TYPE:
|
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_SEGMENT* Segment = new LIB_SEGMENT( LibEntry );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
m_drawItem = Segment;
|
|
|
|
Segment->m_Pos = GetScreen()->m_Curseur;
|
2009-06-18 13:30:52 +00:00
|
|
|
NEGATE( Segment->m_Pos.y );
|
2007-08-24 15:10:46 +00:00
|
|
|
Segment->m_End = Segment->m_Pos;
|
2009-10-20 19:36:58 +00:00
|
|
|
Segment->m_Width = m_drawLineWidth;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-12-08 15:27:13 +00:00
|
|
|
break;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
case ID_LIBEDIT_BODY_TEXT_BUTT:
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_TEXT* Text = new LIB_TEXT( LibEntry );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
m_drawItem = Text;
|
|
|
|
Text->m_Size.x = Text->m_Size.y = m_textSize;
|
|
|
|
Text->m_Orient = m_textOrientation;
|
|
|
|
Text->m_Pos = GetScreen()->m_Curseur;
|
2009-06-18 13:30:52 +00:00
|
|
|
NEGATE( Text->m_Pos.y );
|
2010-01-13 13:43:36 +00:00
|
|
|
|
2009-12-29 10:35:11 +00:00
|
|
|
// Enter the graphic text info
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = true;
|
2007-08-24 15:10:46 +00:00
|
|
|
EditSymbolText( NULL, Text );
|
2009-12-29 10:35:11 +00:00
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = false;
|
2010-01-13 13:43:36 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
if( Text->m_Text.IsEmpty() )
|
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
SAFE_DELETE( Text );
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem = NULL;
|
2007-08-24 15:10:46 +00:00
|
|
|
DrawPanel->ManageCurseur = NULL;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StartMoveDrawSymbol( DC );
|
2009-09-04 18:57:37 +00:00
|
|
|
Text->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
|
|
|
|
DefaultTransformMatrix );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-08 15:27:13 +00:00
|
|
|
break;
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
DisplayError( this, wxT( "WinEDA_LibeditFrame::CreateGraphicItem() \
|
2010-02-04 17:46:12 +00:00
|
|
|
error" ) );
|
2009-09-25 18:49:04 +00:00
|
|
|
return NULL;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_drawItem )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem->m_Flags |= IS_NEW;
|
2009-10-19 19:00:47 +00:00
|
|
|
if( m_drawSpecificUnit )
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem->m_Unit = m_unit;
|
2009-10-19 19:00:47 +00:00
|
|
|
if( m_drawSpecificConvert )
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem->m_Convert = m_convert;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
return m_drawItem;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Create new library component graphic object.
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2009-09-29 18:38:21 +00:00
|
|
|
void WinEDA_LibeditFrame::GraphicItemBeginDraw( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_drawItem == NULL )
|
2007-08-24 15:10:46 +00:00
|
|
|
return;
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
switch( m_drawItem->Type() )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
case COMPONENT_ARC_DRAW_TYPE:
|
2010-02-04 17:46:12 +00:00
|
|
|
if( arcState.stateDrawArc == 1 )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
SymbolDisplayDraw( DrawPanel, DC, FALSE );
|
2010-02-04 17:46:12 +00:00
|
|
|
arcState.stateDrawArc = 2;
|
2007-08-24 15:10:46 +00:00
|
|
|
SymbolDisplayDraw( DrawPanel, DC, FALSE );
|
|
|
|
break;
|
|
|
|
}
|
2010-02-04 17:46:12 +00:00
|
|
|
if( arcState.stateDrawArc > 1 )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
EndDrawGraphicItem( DC );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_CIRCLE_DRAW_TYPE:
|
|
|
|
case COMPONENT_RECT_DRAW_TYPE:
|
|
|
|
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
|
|
|
EndDrawGraphicItem( DC );
|
|
|
|
return;
|
|
|
|
|
|
|
|
case COMPONENT_POLYLINE_DRAW_TYPE:
|
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
wxPoint pos = GetScreen()->m_Curseur;
|
2009-06-18 13:30:52 +00:00
|
|
|
NEGATE( pos.y );
|
2009-10-08 13:19:28 +00:00
|
|
|
( (LIB_POLYLINE*) m_drawItem )->AddPoint( pos );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-12-08 15:27:13 +00:00
|
|
|
break;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
case COMPONENT_LINE_DRAW_TYPE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Redraw the graphic shape while moving
|
2009-09-25 18:49:04 +00:00
|
|
|
*/
|
2008-12-08 15:27:13 +00:00
|
|
|
static void RedrawWhileMovingCursor( WinEDA_DrawPanel* panel,
|
|
|
|
wxDC* DC,
|
|
|
|
bool erase )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM* item;
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
item = ( (WinEDA_LibeditFrame*) panel->GetParent() )->GetDrawItem();
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
return;
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
BASE_SCREEN* Screen = panel->GetScreen();
|
2008-12-08 15:27:13 +00:00
|
|
|
wxPoint pos;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Erase shape in the old position*/
|
2007-08-24 15:10:46 +00:00
|
|
|
if( erase )
|
|
|
|
{
|
2009-09-04 18:57:37 +00:00
|
|
|
pos = ItemPreviousPos - StartCursor;
|
2009-09-25 18:49:04 +00:00
|
|
|
item->Draw( panel, DC, pos, -1, g_XorMode, NULL,
|
|
|
|
DefaultTransformMatrix );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Redraw moved shape */
|
2009-09-04 18:57:37 +00:00
|
|
|
pos = Screen->m_Curseur - StartCursor;
|
2009-09-25 18:49:04 +00:00
|
|
|
item->Draw( panel, DC, pos, -1, g_XorMode, NULL, DefaultTransformMatrix );
|
2007-08-24 15:10:46 +00:00
|
|
|
ItemPreviousPos = Screen->m_Curseur;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
void WinEDA_LibeditFrame::StartMoveDrawSymbol( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_drawItem == NULL )
|
2007-08-24 15:10:46 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
SetCursor( wxCURSOR_HAND );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem->m_Flags |= IS_MOVED;
|
2010-02-04 17:46:12 +00:00
|
|
|
StartCursor = GetScreen()->m_Curseur;
|
|
|
|
InitPosition = m_drawItem->GetPosition();
|
2008-04-17 16:25:29 +00:00
|
|
|
ItemPreviousPos = GetScreen()->m_Curseur;
|
2007-08-24 15:10:46 +00:00
|
|
|
DrawPanel->ManageCurseur = RedrawWhileMovingCursor;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = AbortSymbolTraceOn;
|
|
|
|
DrawPanel->ManageCurseur( DrawPanel, DC, TRUE );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
// @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;
|
2010-02-16 16:21:52 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
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.
|
2007-08-24 15:10:46 +00:00
|
|
|
static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-10-20 19:36:58 +00:00
|
|
|
int dx, dy;
|
2010-02-04 17:46:12 +00:00
|
|
|
int DrawMode = g_XorMode;
|
|
|
|
BASE_SCREEN* Screen = panel->GetScreen();
|
|
|
|
wxPoint currentCursorPosition = Screen->m_Curseur;
|
2009-10-20 19:36:58 +00:00
|
|
|
FILL_T fillStyle = NO_FILL;
|
2009-09-25 18:49:04 +00:00
|
|
|
LIB_DRAW_ITEM* item;
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
item = ( (WinEDA_LibeditFrame*) panel->GetParent() )->GetDrawItem();
|
2009-09-25 18:49:04 +00:00
|
|
|
|
|
|
|
if( item == NULL )
|
|
|
|
return;
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
fillStyle = ( (WinEDA_LibeditFrame*) panel->GetParent() )->GetFillStyle();
|
2009-10-20 19:36:58 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
NEGATE( currentCursorPosition.y );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
|
|
|
if( erase )
|
|
|
|
{
|
2010-02-04 17:46:12 +00:00
|
|
|
if( arcState.stateDrawArc == 1 )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
int Color = ReturnLayerColor( LAYER_DEVICE );
|
2010-02-04 17:46:12 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC, arcState.startPoint.x, -arcState.startPoint.y,
|
|
|
|
arcState.endPoint.x, -arcState.endPoint.y, 0, Color );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
item->Draw( panel, DC, wxPoint( 0, 0 ), -1, DrawMode, NULL,
|
|
|
|
DefaultTransformMatrix );
|
2010-02-04 17:46:12 +00:00
|
|
|
|
|
|
|
if( item->Type() == COMPONENT_ARC_DRAW_TYPE && item->m_Flags != IS_RESIZED )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
int Color = ReturnLayerColor( LAYER_DEVICE );
|
2010-02-04 17:46:12 +00:00
|
|
|
GRDashedLine( &panel->m_ClipBox, DC, arcState.startPoint.x, -arcState.startPoint.y,
|
2009-10-08 13:19:28 +00:00
|
|
|
( (LIB_ARC*) item )->m_Pos.x,
|
|
|
|
-( (LIB_ARC*) item )->m_Pos.y,
|
2007-08-24 15:10:46 +00:00
|
|
|
0, Color );
|
2010-02-04 17:46:12 +00:00
|
|
|
GRDashedLine( &panel->m_ClipBox, DC, arcState.endPoint.x, -arcState.endPoint.y,
|
2009-10-08 13:19:28 +00:00
|
|
|
( (LIB_ARC*) item )->m_Pos.x,
|
|
|
|
-( (LIB_ARC*) item )->m_Pos.y,
|
2007-08-24 15:10:46 +00:00
|
|
|
0, Color );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
switch( item->Type() )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
case COMPONENT_ARC_DRAW_TYPE:
|
2010-02-04 17:46:12 +00:00
|
|
|
if( item->m_Flags == IS_RESIZED )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2010-02-04 17:46:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
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
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2010-02-04 17:46:12 +00:00
|
|
|
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;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_CIRCLE_DRAW_TYPE:
|
2010-02-04 17:46:12 +00:00
|
|
|
dx = ( (LIB_CIRCLE*) item )->m_Pos.x - currentCursorPosition.x;
|
|
|
|
dy = ( (LIB_CIRCLE*) item )->m_Pos.y - currentCursorPosition.y;
|
2009-10-08 13:19:28 +00:00
|
|
|
( (LIB_CIRCLE*) item )->m_Radius =
|
2008-12-08 15:27:13 +00:00
|
|
|
(int) sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) );
|
2009-10-20 19:36:58 +00:00
|
|
|
item->m_Fill = fillStyle;
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_RECT_DRAW_TYPE:
|
2010-02-04 17:46:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-20 19:36:58 +00:00
|
|
|
item->m_Fill = fillStyle;
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_POLYLINE_DRAW_TYPE:
|
2009-01-02 13:19:34 +00:00
|
|
|
{
|
2010-02-04 17:46:12 +00:00
|
|
|
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;
|
2009-10-20 19:36:58 +00:00
|
|
|
item->m_Fill = fillStyle;
|
2009-01-02 13:19:34 +00:00
|
|
|
}
|
2009-06-18 13:30:52 +00:00
|
|
|
break;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
case COMPONENT_LINE_DRAW_TYPE:
|
2010-02-04 17:46:12 +00:00
|
|
|
( (LIB_SEGMENT*) item )->m_End = currentCursorPosition;
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
if( arcState.stateDrawArc == 1 )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
int Color = ReturnLayerColor( LAYER_DEVICE );
|
2010-02-04 17:46:12 +00:00
|
|
|
GRLine( &panel->m_ClipBox,
|
|
|
|
DC,
|
|
|
|
arcState.startPoint.x,
|
|
|
|
-arcState.startPoint.y,
|
|
|
|
arcState.endPoint.x,
|
|
|
|
-arcState.endPoint.y,
|
|
|
|
0,
|
|
|
|
Color );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
item->Draw( panel, DC, wxPoint( 0, 0 ), -1, DrawMode, NULL,
|
|
|
|
DefaultTransformMatrix );
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
if( item->Type() == COMPONENT_ARC_DRAW_TYPE && item->m_Flags != IS_RESIZED )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
int Color = ReturnLayerColor( LAYER_DEVICE );
|
2010-02-04 17:46:12 +00:00
|
|
|
GRDashedLine( &panel->m_ClipBox, DC, arcState.startPoint.x, -arcState.startPoint.y,
|
2009-10-08 13:19:28 +00:00
|
|
|
( (LIB_ARC*) item )->m_Pos.x,
|
|
|
|
-( (LIB_ARC*) item )->m_Pos.y,
|
2007-08-24 15:10:46 +00:00
|
|
|
0, Color );
|
2010-02-04 17:46:12 +00:00
|
|
|
GRDashedLine( &panel->m_ClipBox, DC, arcState.endPoint.x, -arcState.endPoint.y,
|
2009-10-08 13:19:28 +00:00
|
|
|
( (LIB_ARC*) item )->m_Pos.x,
|
|
|
|
-( (LIB_ARC*) item )->m_Pos.y,
|
2007-08-24 15:10:46 +00:00
|
|
|
0, Color );
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Place the new graphic object in the list of component drawing objects.
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2009-09-29 18:38:21 +00:00
|
|
|
void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_component == NULL || m_drawItem == NULL )
|
2007-08-24 15:10:46 +00:00
|
|
|
return;
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_drawItem->Type() == COMPONENT_ARC_DRAW_TYPE )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2010-02-04 17:46:12 +00:00
|
|
|
if( arcState.stateDrawArc == 1 ) /* Trace arc under way must be completed. */
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-09-29 18:38:21 +00:00
|
|
|
DisplayError( this, wxT( "Arc in progress.." ) );
|
|
|
|
return;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-29 18:38:21 +00:00
|
|
|
if( ( m_drawItem->m_Flags & IS_MOVED ) == 0 )
|
2007-08-24 15:10:46 +00:00
|
|
|
SymbolDisplayDraw( DrawPanel, DC, FALSE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
arcState.stateDrawArc = 0;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_drawItem->m_Flags & IS_NEW )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
SaveCopyInUndoList( m_component );
|
2009-09-29 18:38:21 +00:00
|
|
|
m_component->AddDrawItem( m_drawItem );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
switch( m_drawItem->Type() )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
case COMPONENT_ARC_DRAW_TYPE:
|
2009-10-20 19:36:58 +00:00
|
|
|
( (LIB_ARC*) m_drawItem )->m_Fill = m_drawFillStyle;
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_CIRCLE_DRAW_TYPE:
|
2009-10-20 19:36:58 +00:00
|
|
|
( (LIB_CIRCLE*) m_drawItem )->m_Fill = m_drawFillStyle;
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_RECT_DRAW_TYPE:
|
2009-10-20 19:36:58 +00:00
|
|
|
( (LIB_RECTANGLE*) m_drawItem )->m_Fill = m_drawFillStyle;
|
2010-02-04 17:46:12 +00:00
|
|
|
( (LIB_RECTANGLE*) m_drawItem )->m_isHeightLocked = false;
|
|
|
|
( (LIB_RECTANGLE*) m_drawItem )->m_isWidthLocked = false;
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_POLYLINE_DRAW_TYPE:
|
2009-10-20 19:36:58 +00:00
|
|
|
( (LIB_POLYLINE*) m_drawItem )->m_Fill = m_drawFillStyle;
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_PIN_DRAW_TYPE:
|
|
|
|
case COMPONENT_LINE_DRAW_TYPE:
|
|
|
|
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_ID_current_state )
|
|
|
|
SetCursor( wxCURSOR_PENCIL );
|
|
|
|
else
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
if( m_drawItem->m_Flags & IS_MOVED )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
wxPoint pos;
|
|
|
|
pos.x = GetScreen()->m_Curseur.x + InitPosition.x - StartCursor.x,
|
|
|
|
pos.y = GetScreen()->m_Curseur.y - InitPosition.y - StartCursor.y;
|
2009-09-25 18:49:04 +00:00
|
|
|
NEGATE( pos.y );
|
|
|
|
m_drawItem->Move( pos );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), m_unit, m_convert,
|
|
|
|
GR_DEFAULT_DRAWMODE );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem->m_Flags = 0;
|
|
|
|
m_drawItem = NULL;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
DrawPanel->ManageCurseur = NULL;
|
|
|
|
DrawPanel->ForceCloseManageCurseur = NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
//! @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 );
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
arc->m_Radius = wxRound( EuclideanNorm( centerStartVector ) );
|
2010-02-04 17:46:12 +00:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/*
|
|
|
|
* Routine for adjusting the parameters of the arc currently being drawn.
|
|
|
|
* Calculates the center, radius, angles for the arc current
|
2010-02-04 17:46:12 +00:00
|
|
|
* Passes through the points arcState.startPoint.x, arcState.endPoint.x Y and Y with the nearest center
|
2009-11-04 20:46:53 +00:00
|
|
|
* of the mouse position.
|
|
|
|
* Note: The center is obviously not on the grid
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
static void ComputeArc( LIB_ARC* DrawItem, wxPoint ArcCentre )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
int dx, dy;
|
2009-11-04 20:46:53 +00:00
|
|
|
int cX, cY;
|
2007-08-24 15:10:46 +00:00
|
|
|
int angle;
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
cX = ArcCentre.x;
|
|
|
|
cY = ArcCentre.y;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
cY = -cY; /* Attention to the orientation of the axis Y. */
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
/* Calculating cX and cY for the arc passes through arcState.startPoint.x, arcState.endPoint.x,
|
2009-11-04 20:46:53 +00:00
|
|
|
* X and Y */
|
2010-02-04 17:46:12 +00:00
|
|
|
dx = arcState.endPoint.x - arcState.startPoint.x;
|
|
|
|
dy = arcState.endPoint.y - arcState.startPoint.y;
|
|
|
|
cX -= arcState.startPoint.x;
|
|
|
|
cY -= arcState.startPoint.y;
|
2008-12-08 15:27:13 +00:00
|
|
|
angle = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
|
2009-11-04 20:46:53 +00:00
|
|
|
RotatePoint( &dx, &dy, angle ); /* The segment dx, dy is horizontal
|
|
|
|
* -> Length = dx, dy = 0 */
|
2007-08-24 15:10:46 +00:00
|
|
|
RotatePoint( &cX, &cY, angle );
|
2009-11-04 20:46:53 +00:00
|
|
|
cX = dx / 2; /* cX, cY is on the median segment 0.0 a dx, 0 */
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
RotatePoint( &cX, &cY, -angle );
|
2010-02-04 17:46:12 +00:00
|
|
|
cX += arcState.startPoint.x;
|
|
|
|
cY += arcState.startPoint.y;
|
2009-09-14 13:24:17 +00:00
|
|
|
DrawItem->m_Pos.x = cX;
|
|
|
|
DrawItem->m_Pos.y = cY;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
dx = arcState.startPoint.x - DrawItem->m_Pos.x;
|
|
|
|
dy = arcState.startPoint.y - DrawItem->m_Pos.y;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
DrawItem->m_Radius = (int) sqrt( ( (double) dx * dx ) +
|
2010-02-04 17:46:12 +00:00
|
|
|
( (double) dy * dy ) );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
DrawItem->m_t1 = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
dx = arcState.endPoint.x - DrawItem->m_Pos.x;
|
|
|
|
dy = arcState.endPoint.y - DrawItem->m_Pos.y;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
DrawItem->m_t2 = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
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;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
NORMALIZE_ANGLE( DrawItem->m_t1 );
|
|
|
|
NORMALIZE_ANGLE( DrawItem->m_t2 ); // angles = 0 .. 3600
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
// 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.
|
2009-09-14 13:24:17 +00:00
|
|
|
if( (DrawItem->m_t2 - DrawItem->m_t1) > 1800 )
|
|
|
|
DrawItem->m_t2 -= 3600;
|
|
|
|
else if( (DrawItem->m_t2 - DrawItem->m_t1) <= -1800 )
|
|
|
|
DrawItem->m_t2 += 3600;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
wxString msg;
|
2009-09-14 13:24:17 +00:00
|
|
|
angle = DrawItem->m_t2 - DrawItem->m_t1;
|
2007-08-24 15:10:46 +00:00
|
|
|
msg.Printf( _( "Arc %.1f deg" ), (float) angle / 10 );
|
2008-12-08 15:27:13 +00:00
|
|
|
WinEDA_SchematicFrame* frame =
|
|
|
|
(WinEDA_SchematicFrame*) wxGetApp().GetTopWindow();
|
|
|
|
frame->m_LibeditFrame->PrintMsg( msg );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
while( (DrawItem->m_t2 - DrawItem->m_t1) >= 1800 )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
DrawItem->m_t2--;
|
|
|
|
DrawItem->m_t1++;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
while( (DrawItem->m_t1 - DrawItem->m_t2) >= 1800 )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-09-14 13:24:17 +00:00
|
|
|
DrawItem->m_t2++;
|
|
|
|
DrawItem->m_t1--;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
2009-09-14 13:24:17 +00:00
|
|
|
NORMALIZE_ANGLE( DrawItem->m_t1 );
|
|
|
|
NORMALIZE_ANGLE( DrawItem->m_t2 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2010-02-04 17:46:12 +00:00
|
|
|
//! @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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
/*
|
|
|
|
* Used for deleting last entered segment while creating a Polyline
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2009-09-29 18:38:21 +00:00
|
|
|
void WinEDA_LibeditFrame::DeleteDrawPoly( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-25 18:49:04 +00:00
|
|
|
if( m_drawItem == NULL
|
|
|
|
|| m_drawItem->Type() != COMPONENT_POLYLINE_DRAW_TYPE )
|
2007-08-24 15:10:46 +00:00
|
|
|
return;
|
|
|
|
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_POLYLINE* Poly = (LIB_POLYLINE*) m_drawItem;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
|
|
|
|
DefaultTransformMatrix );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
// First segment is kept, only its end point is changed
|
|
|
|
while( Poly->GetCornerCount() > 2 )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-01-02 13:19:34 +00:00
|
|
|
Poly->m_PolyPoints.pop_back();
|
2009-06-18 13:30:52 +00:00
|
|
|
unsigned idx = Poly->GetCornerCount() - 1;
|
|
|
|
wxPoint point = GetScreen()->m_Curseur;
|
2009-01-02 13:19:34 +00:00
|
|
|
NEGATE( point.y );
|
|
|
|
if( Poly->m_PolyPoints[idx] != point )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2009-01-02 13:19:34 +00:00
|
|
|
Poly->m_PolyPoints[idx] = point;
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
m_drawItem->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
|
|
|
|
DefaultTransformMatrix );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|