Commit ada6b6b8 authored by charras's avatar charras

Code cleaning

parent 02b670d8
......@@ -5,6 +5,13 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.
2009-Jan-02 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
++Eeschema:
Code cleaning.
LibDrawPolyline uses now std::vector<wxPoint> to handle corners.
2008-Dec-31 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================
......
......@@ -23,9 +23,9 @@ static SCH_ITEM* CopyStruct( WinEDA_DrawPanel* panel,
BASE_SCREEN* screen,
SCH_ITEM* DrawStruct );
static void CollectStructsToDrag( SCH_SCREEN* screen );
static void AddPickedItem( SCH_SCREEN* screen, wxPoint position );
static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* DrawLibItem,
wxPoint& position );
static void AddPickedItem( SCH_SCREEN* screen, wxPoint aPosition );
static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem,
wxPoint& aPosition );
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel,
wxDC* DC,
bool erase );
......@@ -182,9 +182,7 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
/* clear struct.m_Flags */
SCH_ITEM* Struct;
for( Struct = GetScreen()->EEDrawList;
Struct != NULL;
Struct = Struct->Next() )
for( Struct = GetScreen()->EEDrawList; Struct != NULL; Struct = Struct->Next() )
Struct->m_Flags = 0;
DrawPanel->ManageCurseur = NULL;
......@@ -203,9 +201,7 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
block->m_BlockDrawStruct = NULL;
}
SetToolID( m_ID_current_state,
DrawPanel->m_PanelDefaultCursor,
wxEmptyString );
SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor, wxEmptyString );
}
......@@ -1152,10 +1148,7 @@ bool PlaceStruct( BASE_SCREEN* screen, SCH_ITEM* DrawStruct )
if( !DrawStruct )
return FALSE;
move_vector.x = screen->m_Curseur.x -
screen->BlockLocate.m_BlockLastCursorPosition.x;
move_vector.y = screen->m_Curseur.y -
screen->BlockLocate.m_BlockLastCursorPosition.y;
move_vector = screen->m_Curseur - screen->BlockLocate.m_BlockLastCursorPosition;
switch( DrawStruct->Type() )
{
......@@ -1709,8 +1702,8 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint position )
/*********************************************************************************/
static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* DrawLibItem,
wxPoint& position )
static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem,
wxPoint& aPosition )
/*********************************************************************************/
{
EDA_LibComponentStruct* Entry;
......@@ -1720,19 +1713,19 @@ static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* DrawLibItem,
int orient;
LibDrawPin* Pin;
if( DrawLibItem )
if( aDrawLibItem )
{
NextItem = NULL;
if( ( Entry =
FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString,
FindLibPart( aDrawLibItem->m_ChipName.GetData(), wxEmptyString,
FIND_ROOT ) ) == NULL )
return NULL;
DEntry = Entry->m_Drawings;
Multi = DrawLibItem->m_Multi;
convert = DrawLibItem->m_Convert;
PartX = DrawLibItem->m_Pos.x;
PartY = DrawLibItem->m_Pos.y;
memcpy( TransMat, DrawLibItem->m_Transform, sizeof(TransMat) );
Multi = aDrawLibItem->m_Multi;
convert = aDrawLibItem->m_Convert;
PartX = aDrawLibItem->m_Pos.x;
PartY = aDrawLibItem->m_Pos.y;
memcpy( TransMat, aDrawLibItem->m_Transform, sizeof(TransMat) );
}
else
DEntry = NextItem;
......@@ -1753,10 +1746,7 @@ static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* DrawLibItem,
orient = Pin->ReturnPinDrawOrient( TransMat );
/* Calcul de la position du point de reference */
position.x = PartX + (TransMat[0][0] *Pin->m_Pos.x)
+ (TransMat[0][1] *Pin->m_Pos.y);
position.y = PartY + (TransMat[1][0] *Pin->m_Pos.x)
+ (TransMat[1][1] *Pin->m_Pos.y);
aPosition = TransformCoordinate( TransMat, Pin->m_Pos);
NextItem = DEntry->Next();
return DEntry;
}
......
/****************************************************/
/* BLOCK.CPP */
/* block_libedt.cpp */
/* Gestion des Operations sur Blocks et Effacements */
/****************************************************/
......@@ -139,11 +139,11 @@ int MarkItemsInBloc( EDA_LibComponentStruct* LibComponent,
case COMPONENT_POLYLINE_DRAW_TYPE:
{
int ii, imax = ( (LibDrawPolyline*) item )->m_CornersCount * 2;
int* ptpoly = ( (LibDrawPolyline*) item )->m_PolyList;
for( ii = 0; ii < imax; ii += 2 )
int ii, imax = ( (LibDrawPolyline*) item )->GetCornerCount();
for( ii = 0; ii < imax; ii ++ )
{
pos.x = ptpoly[ii]; pos.y = -ptpoly[ii + 1];
pos = ( (LibDrawPolyline*) item )->m_PolyPoints[ii];
NEGATE( pos.y );
if( Rect.Inside( pos ) )
{
item->m_Selected = IS_SELECTED;
......@@ -537,7 +537,7 @@ void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
if( LibEntry == NULL )
return;
offset.y = -offset.y; // Y axis for lib items is Down to Up: reverse y offset value
NEGATE( offset.y ); // Y axis for lib items is Down to Up: reverse y offset value
item = LibEntry->m_Drawings;
for( ; item != NULL; item = item->Next() )
{
......@@ -547,42 +547,31 @@ void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
switch( item->Type() )
{
case COMPONENT_PIN_DRAW_TYPE:
( (LibDrawPin*) item )->m_Pos.x += offset.x;
( (LibDrawPin*) item )->m_Pos.y += offset.y;
( (LibDrawPin*) item )->m_Pos += offset;
break;
case COMPONENT_ARC_DRAW_TYPE:
{
( (LibDrawArc*) item )->m_Pos.x += offset.x;
( (LibDrawArc*) item )->m_Pos.y += offset.y;
( (LibDrawArc*) item )->m_ArcStart.x += offset.x;
( (LibDrawArc*) item )->m_ArcStart.y += offset.y;
( (LibDrawArc*) item )->m_ArcEnd.x += offset.x;
( (LibDrawArc*) item )->m_ArcEnd.y += offset.y;
( (LibDrawArc*) item )->m_Pos += offset;
( (LibDrawArc*) item )->m_ArcStart += offset;
( (LibDrawArc*) item )->m_ArcEnd += offset;
break;
}
case COMPONENT_CIRCLE_DRAW_TYPE:
( (LibDrawCircle*) item )->m_Pos.x += offset.x;
( (LibDrawCircle*) item )->m_Pos.y += offset.y;
( (LibDrawCircle*) item )->m_Pos += offset;
break;
case COMPONENT_RECT_DRAW_TYPE:
( (LibDrawSquare*) item )->m_Pos.x += offset.x;
( (LibDrawSquare*) item )->m_Pos.y += offset.y;
( (LibDrawSquare*) item )->m_End.x += offset.x;
( (LibDrawSquare*) item )->m_End.y += offset.y;
( (LibDrawSquare*) item )->m_Pos += offset;
( (LibDrawSquare*) item )->m_End += offset;
break;
case COMPONENT_POLYLINE_DRAW_TYPE:
{
int ii, imax = ( (LibDrawPolyline*) item )->m_CornersCount * 2;
int* ptpoly = ( (LibDrawPolyline*) item )->m_PolyList;
for( ii = 0; ii < imax; ii += 2 )
{
ptpoly[ii] += offset.x;
ptpoly[ii + 1] += offset.y;
}
unsigned ii, imax = ( (LibDrawPolyline*) item )->GetCornerCount();
for( ii = 0; ii < imax; ii ++ )
( (LibDrawPolyline*) item )->m_PolyPoints[ii] += offset;
}
break;
......@@ -590,8 +579,7 @@ void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
break;
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
( (LibDrawText*) item )->m_Pos.x += offset.x;
( (LibDrawText*) item )->m_Pos.y += offset.y;
( (LibDrawText*) item )->m_Pos += offset;
break;
default:
......@@ -688,11 +676,10 @@ void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
case COMPONENT_POLYLINE_DRAW_TYPE:
{
int ii, imax = ( (LibDrawPolyline*) item )->m_CornersCount * 2;
int* ptpoly = ( (LibDrawPolyline*) item )->m_PolyList;
for( ii = 0; ii < imax; ii += 2 )
unsigned ii, imax = ( (LibDrawPolyline*) item )->GetCornerCount();
for( ii = 0; ii < imax; ii ++ )
{
SETMIRROR( ptpoly[ii] );
SETMIRROR( ( (LibDrawPolyline*) item )->m_PolyPoints[ii].x );
}
}
break;
......
......@@ -118,7 +118,6 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert )
**/
{
int xmin, xmax, ymin, ymax, x1, y1;
int* pt, ii;
LibEDA_BaseStruct* DrawEntry;
EDA_Rect BoundaryBox;
......@@ -232,21 +231,15 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert )
case COMPONENT_POLYLINE_DRAW_TYPE:
{
LibDrawPolyline* polyline = (LibDrawPolyline*) DrawEntry;
pt = polyline->m_PolyList;
for( ii = 0; ii < polyline->m_CornersCount; ii++ )
{
if( xmin > *pt )
xmin = *pt;
if( xmax < *pt )
xmax = *pt;
pt++;
if( ymin > *pt )
ymin = *pt;
if( ymax < *pt )
ymax = *pt;
pt++;
}
EDA_Rect rect = ((LibDrawPolyline*) DrawEntry)->GetBoundaryBox( );
xmin = MIN( xmin, rect.GetX() );
xmax = MAX( xmax, rect.GetX() );
ymin = MIN( ymin, rect.GetY() );
ymax = MAX( ymax, rect.GetY() );
xmin = MIN( xmin, rect.GetEnd().x );
xmax = MAX( xmax, rect.GetEnd().x );
ymin = MIN( ymin, rect.GetEnd().y );
ymax = MAX( ymax, rect.GetEnd().y );
}
break;
......@@ -257,9 +250,7 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert )
// Update the BoundaryBox. Remember the fact the screen Y axis is the reverse */
NEGATE(ymax); NEGATE(ymin); // Y is not is screen axis sense
// Ensure w and H > 0 (wxRect assume it)
if( xmax < xmin )
EXCHG( xmax, xmin );
// Ensure H > 0 (wxRect assume it)
if( ymax < ymin )
EXCHG( ymax, ymin );
BoundaryBox.SetX( xmin ); BoundaryBox.SetWidth( xmax - xmin );
......
......@@ -240,8 +240,8 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
int color = ReturnLayerColor( LAYER_DEVICE );
int linewidth = MAX( m_Width, g_DrawMinimunLineWidth );
static int* Buf_Poly_Drawings = NULL; // Buffer used to store current corners coordinates for drawings
static int Buf_Poly_Size = 0; // Buffer used to store current corners coordinates for drawings
static wxPoint* Buf_Poly_Drawings = NULL; // Buffer used to store current corners coordinates for drawings
static unsigned Buf_Poly_Size = 0; // Buffer used to store current corners coordinates for drawings
if( aColor < 0 ) // Used normal color or selected color
{
......@@ -254,25 +254,19 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
// Set the size of the buffer od coordinates
if( Buf_Poly_Drawings == NULL )
{
Buf_Poly_Size = m_CornersCount;
Buf_Poly_Drawings = (int*) MyMalloc( sizeof(int) * 2 * Buf_Poly_Size );
Buf_Poly_Size = m_PolyPoints.size();
Buf_Poly_Drawings = (wxPoint*) MyMalloc( sizeof(wxPoint) * Buf_Poly_Size );
}
else if( Buf_Poly_Size < m_CornersCount )
else if( Buf_Poly_Size < m_PolyPoints.size() )
{
Buf_Poly_Size = m_CornersCount;
Buf_Poly_Drawings = (int*) realloc( Buf_Poly_Drawings,
sizeof(int) * 2 * Buf_Poly_Size );
Buf_Poly_Size = m_PolyPoints.size();
Buf_Poly_Drawings = (wxPoint*) realloc( Buf_Poly_Drawings,
sizeof(wxPoint) * Buf_Poly_Size );
}
for( int ii = 0, jj = 0; ii < m_CornersCount; ii++, jj += 2 )
for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ )
{
pos1.x = m_PolyList[jj];
pos1.y = m_PolyList[jj + 1];
pos1 = TransformCoordinate( aTransformMatrix, pos1 ) + aOffset;
Buf_Poly_Drawings[jj] = pos1.x;
Buf_Poly_Drawings[jj + 1] = pos1.y;
Buf_Poly_Drawings[ii] = TransformCoordinate( aTransformMatrix, m_PolyPoints[ii] ) + aOffset;
}
FILL_T fill = aData ? NO_FILL : m_Fill;
......@@ -280,15 +274,15 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
fill = NO_FILL;
if( fill == FILLED_WITH_BG_BODYCOLOR )
GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
(wxPoint*) Buf_Poly_Drawings, 1, linewidth, color,
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
Buf_Poly_Drawings, 1, linewidth, color,
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( fill == FILLED_SHAPE )
GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
(wxPoint*) Buf_Poly_Drawings, 1, linewidth, color, color );
GRPoly( &aPanel->m_ClipBox, aDC,m_PolyPoints.size(),
Buf_Poly_Drawings, 1, linewidth, color, color );
else
GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
(wxPoint*) Buf_Poly_Drawings, 0, linewidth, color, color );
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
Buf_Poly_Drawings, 0, linewidth, color, color );
}
......@@ -520,8 +514,6 @@ LibDrawSegment* LibDrawSegment::GenCopy()
LibDrawPolyline::LibDrawPolyline() : LibEDA_BaseStruct( COMPONENT_POLYLINE_DRAW_TYPE )
{
m_CornersCount = 0;
m_PolyList = NULL;
m_Fill = NO_FILL;
m_Width = 0;
}
......@@ -532,16 +524,7 @@ LibDrawPolyline* LibDrawPolyline::GenCopy()
/************************************************/
{
LibDrawPolyline* newitem = new LibDrawPolyline();
int size;
newitem->m_CornersCount = m_CornersCount;
size = sizeof(int) * 2 * m_CornersCount;
if( size )
{
newitem->m_PolyList = (int*) MyMalloc( size );
memcpy( newitem->m_PolyList, m_PolyList, size );
}
newitem->m_PolyPoints = m_PolyPoints; // Vector copy
newitem->m_Width = m_Width;
newitem->m_Unit = m_Unit;
newitem->m_Convert = m_Convert;
......@@ -555,18 +538,55 @@ LibDrawPolyline* LibDrawPolyline::GenCopy()
void LibDrawPolyline::AddPoint( const wxPoint& point )
/***************************************************/
/* add a point to the polyline coordinate list, and realloc the memory
/* add a point to the polyline coordinate list
*/
{
int allocsize;
m_PolyPoints.push_back( point );
}
m_CornersCount++;
allocsize = 2 * sizeof(int) * m_CornersCount;
if( m_PolyList == NULL )
m_PolyList = (int*) MyMalloc( allocsize );
else
m_PolyList = (int*) realloc( m_PolyList, allocsize );
m_PolyList[(m_CornersCount * 2) - 2] = point.x;
m_PolyList[(m_CornersCount * 2) - 1] = -point.y;
/** Function HitTest
* @return true if the point aPosRef is near a segment
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to a segment
* @param aTransMat = the transform matrix
*/
bool LibDrawPolyline::HitTest( wxPoint aPosRef, int aThreshold, int aTransMat[2][2] )
{
aPosRef = TransformCoordinate( aTransMat, aPosRef);
/* Move origin coordinate to segment start point */
wxPoint end;
for ( unsigned ii = 0; ii < m_PolyPoints.size() -1; ii++ )
{
aPosRef -= m_PolyPoints[0];
end = m_PolyPoints[1] - m_PolyPoints[0];
if( distance( end.x, end.y, aPosRef.x, aPosRef.y, aThreshold ) )
return true;
}
return false;
}
/** Function GetBoundaryBox
* @return the boundary box for this, in library coordinates
*/
EDA_Rect LibDrawPolyline::GetBoundaryBox( )
{
EDA_Rect BoundaryBox;
int xmin, xmax, ymin, ymax;
xmin = xmax = m_PolyPoints[0].x;
ymin = ymax = m_PolyPoints[0].y;
for( unsigned ii = 1; ii < GetCornerCount(); ii++ )
{
xmin = MIN( xmin, m_PolyPoints[0].x );
xmax = MAX( xmax, m_PolyPoints[0].x );
ymin = MIN( ymin, m_PolyPoints[0].y );
ymax = MAX( ymax, m_PolyPoints[0].y );
}
BoundaryBox.SetX( xmin ); BoundaryBox.SetWidth( xmax - xmin );
BoundaryBox.SetY( ymin ); BoundaryBox.SetHeight( ymax - ymin );
return BoundaryBox;
}
......@@ -413,24 +413,18 @@ public:
int aDrawMode, void* aData, int aTransformMatrix[2][2] );
};
/*********************************************/
/* Graphic Body Item: Polygon (set of lines) */
/*********************************************/
/**********************************************************/
/* Graphic Body Item: Polygon and polyline (set of lines) */
/**********************************************************/
class LibDrawPolyline : public LibEDA_BaseStruct
{
public:
int m_CornersCount;
int* m_PolyList;
int m_Width; /* Tickness */
std::vector<wxPoint> m_PolyPoints; // list of points (>= 2)
public:
LibDrawPolyline();
~LibDrawPolyline()
{
if( m_PolyList )
free( m_PolyList );
}
~LibDrawPolyline() { }
virtual wxString GetClass() const
{
......@@ -449,6 +443,24 @@ public:
LibDrawPolyline* GenCopy();
void AddPoint( const wxPoint& point );
/** Function GetCornerCount
* @return the number of corners
*/
unsigned GetCornerCount() const { return m_PolyPoints.size(); }
/** Function HitTest
* @return true if the point aPosRef is near a segment
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to a segment
* @param aTransMat = the transform matrix
*/
bool HitTest( wxPoint aPosRef, int aThreshold, int aTransMat[2][2] );
/** Function GetBoundaryBox
* @return the boundary box for this, in library coordinates
*/
EDA_Rect GetBoundaryBox( );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void* aData, int aTransformMatrix[2][2] );
};
......
......@@ -168,18 +168,12 @@ LibDrawPin* WinEDA_SchematicFrame::LocatePinEnd( SCH_ITEM* DrawList, const wxPo
pinpos = Pin->m_Pos;
if( DrawLibItem == NULL )
pinpos.y = -pinpos.y;
NEGATE( pinpos.y );
else
{
int x1 = pinpos.x, y1 = pinpos.y;
pinpos.x = DrawLibItem->m_Pos.x + DrawLibItem->m_Transform[0][0] * x1
+ DrawLibItem->m_Transform[0][1] * y1;
pinpos.y = DrawLibItem->m_Pos.y + DrawLibItem->m_Transform[1][0] * x1
+ DrawLibItem->m_Transform[1][1] * y1;
}
pinpos = TransformCoordinate( DrawLibItem->m_Transform, pinpos);
if( (pos.x == pinpos.x) && (pos.y == pinpos.y) )
if( pos == pinpos )
return Pin;
return NULL;
}
......@@ -292,16 +286,10 @@ wxPoint ReturnPinPhysicalPosition( LibDrawPin* Pin,
wxPoint PinPos = Pin->m_Pos;
if( DrawLibItem == NULL )
PinPos.y = -PinPos.y;
NEGATE( PinPos.y );
else
{
int x = Pin->m_Pos.x, y = Pin->m_Pos.y;
PinPos.x = DrawLibItem->m_Pos.x + DrawLibItem->m_Transform[0][0] * x
+ DrawLibItem->m_Transform[0][1] * y;
PinPos.y = DrawLibItem->m_Pos.y + DrawLibItem->m_Transform[1][0] * x
+ DrawLibItem->m_Transform[1][1] * y;
}
PinPos = TransformCoordinate( DrawLibItem->m_Transform, Pin->m_Pos);
return PinPos;
}
......
......@@ -18,6 +18,8 @@
// Local variables:
static int s_SelectedRow;
#define COLUMN_FIELD_NAME 0
#define COLUMN_TEXT 1
/*****************************************************************************************/
class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB : public DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE
......@@ -146,10 +148,10 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::OnInitDialog( wxInitDialogEvent& event
columnLabel.SetImage( -1 );
columnLabel.SetText( _( "Name" ) );
fieldListCtrl->InsertColumn( 0, columnLabel );
fieldListCtrl->InsertColumn( COLUMN_FIELD_NAME, columnLabel );
columnLabel.SetText( _( "Value" ) );
fieldListCtrl->InsertColumn( 1, columnLabel );
fieldListCtrl->InsertColumn( COLUMN_TEXT, columnLabel );
wxString label = _( "Size" ) + ReturnUnitSymbol( g_UnitMetric );
textSizeLabel->SetLabel( label );
......@@ -298,27 +300,41 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::addFieldButtonHandler( wxCommandEvent&
/*****************************************************************************************/
void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::deleteFieldButtonHandler( wxCommandEvent& event )
/*****************************************************************************************/
/* Delete a field.
* Fields REFERENCE and VALUE are mandatory, and cannot be deleted.
* If a field is empty, it is removed.
* if not empty, the text is removed.
*/
{
unsigned fieldNdx = getSelectedFieldNdx();
if( fieldNdx >= m_FieldsBuf.size() ) // traps the -1 case too
return;
if( fieldNdx < FIELD1 )
if( fieldNdx <= VALUE )
{
wxBell();
return;
}
m_skipCopyFromPanel = true;
m_FieldsBuf.erase( m_FieldsBuf.begin() + fieldNdx );
fieldListCtrl->DeleteItem( fieldNdx );
if( m_FieldsBuf[fieldNdx].m_Text.IsEmpty() )
{
m_FieldsBuf.erase( m_FieldsBuf.begin() + fieldNdx );
fieldListCtrl->DeleteItem( fieldNdx );
if( fieldNdx >= m_FieldsBuf.size() )
--fieldNdx;
if( fieldNdx >= m_FieldsBuf.size() )
--fieldNdx;
// Reinitialize fields IDs and default names:
reinitializeFieldsIdAndDefaultNames();
}
else
{
m_FieldsBuf[fieldNdx].m_Text.Empty();
copySelectedFieldToPanel();
}
// Reinitialize fields IDs and default names:
reinitializeFieldsIdAndDefaultNames();
updateDisplay( );
setRowItem( fieldNdx, m_FieldsBuf[fieldNdx] );
......@@ -467,15 +483,15 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::setRowItem( int aFieldNdx, const LibDra
wxASSERT( ndx >= 0 );
fieldListCtrl->SetItem( ndx, 1, wxEmptyString );
fieldListCtrl->SetItem( ndx, COLUMN_TEXT, wxEmptyString );
}
fieldListCtrl->SetItem( aFieldNdx, 0, aField.m_Name );
fieldListCtrl->SetItem( aFieldNdx, 1, aField.m_Text );
fieldListCtrl->SetItem( aFieldNdx, COLUMN_FIELD_NAME, aField.m_Name );
fieldListCtrl->SetItem( aFieldNdx, COLUMN_TEXT, aField.m_Text );
// recompute the column widths here, after setting texts
fieldListCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE );
fieldListCtrl->SetColumnWidth( 1, wxLIST_AUTOSIZE );
fieldListCtrl->SetColumnWidth( COLUMN_FIELD_NAME, wxLIST_AUTOSIZE );
fieldListCtrl->SetColumnWidth( COLUMN_TEXT, wxLIST_AUTOSIZE );
}
......@@ -514,6 +530,9 @@ void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::copySelectedFieldToPanel()
// if fieldNdx == REFERENCE, VALUE, FOOTPRINT, or DATASHEET, then disable filed name editing
fieldNameTextCtrl->Enable( fieldNdx >= FIELD1 );
fieldNameTextCtrl->SetEditable( fieldNdx >= FIELD1 );
moveUpButton->Enable( fieldNdx >= FIELD1 ); // disable move up button for non moveable fields
// if fieldNdx == REFERENCE, VALUE, then disable delete button
deleteFieldButton->Enable( fieldNdx > VALUE );
fieldValueTextCtrl->SetValue( field.m_Text );
......
......@@ -40,7 +40,6 @@ void WinEDA_SchematicFrame::StartMoveCmpField( SCH_CMP_FIELD* aField, wxDC* DC )
}
wxPoint pos, newpos;
int x1, y1;
SCH_COMPONENT* comp = (SCH_COMPONENT*) aField->GetParent();
SAFE_DELETE( g_ItemToUndoCopy );
......@@ -50,19 +49,16 @@ void WinEDA_SchematicFrame::StartMoveCmpField( SCH_CMP_FIELD* aField, wxDC* DC )
/* Les positions sont calculees par la matrice TRANSPOSEE de la matrice
* de rotation-miroir */
x1 = aField->m_Pos.x - pos.x;
y1 = aField->m_Pos.y - pos.y;
newpos = aField->m_Pos - pos;
// Empirically this is necessary. The Y coordinate appears to be inverted
// under some circumstances, but that inversion is not preserved by all
// combinations of mirroring and rotation. The following clause is true
// when the number of rotations and the number of mirrorings are both odd.
if( comp->m_Transform[1][0] * comp->m_Transform[0][1] < 0 )
{
y1 = -y1;
}
newpos.x = pos.x + comp->m_Transform[0][0] * x1 + comp->m_Transform[1][0] * y1;
newpos.y = pos.y + comp->m_Transform[0][1] * x1 + comp->m_Transform[1][1] * y1;
NEGATE (newpos.y);
newpos = TransformCoordinate( comp->m_Transform, newpos) + pos;
DrawPanel->CursorOff( DC );
GetScreen()->m_Curseur = newpos;
......
......@@ -748,28 +748,28 @@ LibEDA_BaseStruct* GetDrawEntry (WinEDA_DrawFrame* frame,
case 'P': /* Polyline */
{
LibDrawPolyline* Polyl = new LibDrawPolyline();
int ccount = 0;
New = Polyl;
if( sscanf( &Line[2], "%d %d %d %d",
&Polyl->m_CornersCount, &Unit, &Convert,
&ccount, &Unit, &Convert,
&Polyl->m_Width ) == 4
&& Polyl->m_CornersCount > 0 )
&& ccount > 0 )
{
Polyl->m_Unit = Unit; Polyl->m_Convert = Convert;
Polyl->m_PolyList = (int*)
MyZMalloc( sizeof(int) * Polyl->m_CornersCount * 2 );
p = strtok( &Line[2], " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
for( i = 0; i < Polyl->m_CornersCount * 2 && !Error; i++ )
for( i = 0; i < ccount && !Error; i++ )
{
wxPoint point;
p = strtok( NULL, " \t\n" );
Error = sscanf( p, "%d", &point.x ) != 1;
p = strtok( NULL, " \t\n" );
Error = sscanf( p, "%d", &Polyl->m_PolyList[i] ) != 1;
Error = Error || sscanf( p, "%d", &point.y ) != 1;
Polyl->AddPoint(point);
}
Polyl->m_Fill = NO_FILL;
......@@ -787,8 +787,8 @@ LibEDA_BaseStruct* GetDrawEntry (WinEDA_DrawFrame* frame,
break;
default:
MsgLine.Printf( wxT( "Undefined DRAW command in line %d, aborted." ),
*LineNum );
MsgLine.Printf( wxT( "Undefined DRAW command in line %d\n%s, aborted." ),
*LineNum, Line );
DisplayError( frame, MsgLine );
return Head;
}
......
......@@ -149,10 +149,7 @@ SCH_ITEM * WinEDA_SchematicFrame::FindComponentAndItem(
}
wxPoint delta;
pos -= Component->m_Pos;
delta.x = Component->m_Transform[0][0] * pos.x + Component->m_Transform[0][1] * pos.y;
delta.y = Component->m_Transform[1][0] * pos.x + Component->m_Transform[1][1] * pos.y;
delta = TransformCoordinate( Component->m_Transform, pos);
pos = delta + Component->m_Pos;
wxPoint old_cursor_position = sheet->LastScreen()->m_Curseur;
......@@ -165,8 +162,7 @@ SCH_ITEM * WinEDA_SchematicFrame::FindComponentAndItem(
&( GetScreen()->m_StartVisu.y ));
// calcul des coord curseur avec origine = screen
curpos.x -= GetScreen()->m_StartVisu.x;
curpos.y -= GetScreen()->m_StartVisu.y;
curpos -= GetScreen()->m_StartVisu;
/* Il y a peut-etre necessite de recadrer le dessin: */
#define MARGIN 30
......@@ -420,7 +416,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem(
{
DrawSheetPath* Sheet, * FirstSheet = NULL;
SCH_ITEM* DrawList = NULL, * FirstStruct = NULL, * Struct = NULL;
int StartCount, ii, jj;
int StartCount;
bool NotFound;
wxPoint firstpos, pos, old_cursor_position;
static int Find_in_hierarchy;
......@@ -556,14 +552,9 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem(
{
SCH_COMPONENT* pSch = (SCH_COMPONENT*) Struct;
pos.x -= pSch->m_Pos.x;
pos.y -= pSch->m_Pos.y;
ii = pSch->m_Transform[0][0] * pos.x + pSch->m_Transform[0][1] * pos.y;
jj = pSch->m_Transform[1][0] * pos.x + pSch->m_Transform[1][1] * pos.y;
pos.x = ii + pSch->m_Pos.x;
pos.y = jj + pSch->m_Pos.y;
pos -= pSch->m_Pos;
pos = TransformCoordinate( pSch->m_Transform, pos );
pos += pSch->m_Pos;
}
old_cursor_position = Sheet->LastScreen()->m_Curseur;
......@@ -576,8 +567,7 @@ SCH_ITEM* WinEDA_SchematicFrame::FindSchematicItem(
&( GetScreen()->m_StartVisu.y ));
// calcul des coord curseur avec origine = screen
curpos.x -= m_CurrentSheet->LastScreen()->m_StartVisu.x;
curpos.y -= m_CurrentSheet->LastScreen()->m_StartVisu.y;
curpos -= m_CurrentSheet->LastScreen()->m_StartVisu;
/* Il y a peut-etre necessite de recadrer le dessin: */
#define MARGIN 30
......
......@@ -153,7 +153,7 @@ bool BlockActive = (GetScreen()->BlockLocate.m_Command != BLOCK_IDLE);
}
else if( (DrawEntry->m_Flags & IS_NEW) )
{
if( ((LibDrawPolyline*)DrawEntry)->m_CornersCount > 2 )
if( ((LibDrawPolyline*)DrawEntry)->GetCornerCount() > 2 )
{
msg = AddHotkeyName( _( "Delete Segment " ), s_Libedit_Hokeys_Descr, HK_DELETE_PIN );
ADD_MENUITEM(PopMenu,
......
......@@ -22,11 +22,11 @@ static SCH_ITEM* LastSnappedStruct = NULL;
static int PickedBoxMinX, PickedBoxMinY, PickedBoxMaxX, PickedBoxMaxY;
static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1,
int StartX2, int StartY2, int EndX2, int EndY2 );
static bool IsPointInBox( int pX, int pY,
static bool IsPointInBox( wxPoint aPosRef,
int BoxX1, int BoxY1, int BoxX2, int BoxY2 );
static bool IsPointOnSegment( int pX, int pY,
static bool IsPointOnSegment( wxPoint aPosRef,
int SegmX1, int SegmY1, int SegmX2, int SegmY2, int seuil = 0 );
static bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
SCH_ITEM* DrawList, DrawPickedStruct* DontSnapList, int zoom_value );
......@@ -119,13 +119,11 @@ SCH_ITEM* PickStruct( const wxPoint& refpos, BASE_SCREEN* screen, int SearchMask
*/
{
bool Snapped;
SCH_ITEM* DrawList = screen->EEDrawList;
if( screen==NULL || DrawList == NULL )
if( screen == NULL || screen->EEDrawList == NULL )
return NULL;
if( ( Snapped = SnapPoint2( refpos, SearchMask,
DrawList, NULL, screen->GetZoom() ) ) != FALSE )
screen->EEDrawList, NULL, screen->GetZoom() ) ) != FALSE )
{
return LastSnappedStruct;
}
......@@ -197,10 +195,10 @@ SCH_ITEM* PickStruct( EDA_Rect& block, BASE_SCREEN* screen, int SearchMask )
* If DontSnapList is not NULL, structes in this list are skipped. *
* The routine returns TRUE if point was snapped. *
*****************************************************************************/
bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
SCH_ITEM* DrawList, DrawPickedStruct* DontSnapList, int zoom_value )
{
int i, * Points, x = PosRef.x, y = PosRef.y;
int i, * Points;
int x1, y1, x2, y2, NumOfPoints2;
DrawPickedStruct* DontSnap;
int dx, dy;
......@@ -231,7 +229,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
{
x1 = Points[i]; y1 = Points[i + 1];
x2 = Points[i + 2]; y2 = Points[i + 3];
if( IsPointOnSegment( x, y, x1, y1, x2, y2 ) )
if( IsPointOnSegment( aPosRef, x1, y1, x2, y2 ) )
{
LastSnappedStruct = DrawList;
return TRUE;
......@@ -246,7 +244,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
if( !( SearchMask & (DRAWITEM | WIREITEM | BUSITEM) ) )
break;
if( IsPointOnSegment( x, y, STRUCT->m_Start.x, STRUCT->m_Start.y,
if( IsPointOnSegment( aPosRef, STRUCT->m_Start.x, STRUCT->m_Start.y,
STRUCT->m_End.x, STRUCT->m_End.y ) )
{
if( ( (SearchMask & DRAWITEM) && (STRUCT->GetLayer() == LAYER_NOTES) )
......@@ -256,15 +254,13 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
{
if( SearchMask & EXCLUDE_WIRE_BUS_ENDPOINTS )
{
if( x == STRUCT->m_Start.x && y == STRUCT->m_Start.y )
break;
if( x == STRUCT->m_End.x && y == STRUCT->m_End.y )
if( aPosRef == STRUCT->m_Start || aPosRef == STRUCT->m_End )
break;
}
if( SearchMask & WIRE_BUS_ENDPOINTS_ONLY )
{
if( !STRUCT->IsOneEndPointAt( wxPoint( x, y ) ) )
if( !STRUCT->IsOneEndPointAt( aPosRef ) )
break;
}
......@@ -281,7 +277,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
if( !( SearchMask & (RACCORDITEM) ) )
break;
if( IsPointOnSegment( x, y, STRUCT->m_Pos.x, STRUCT->m_Pos.y,
if( IsPointOnSegment( aPosRef, STRUCT->m_Pos.x, STRUCT->m_Pos.y,
STRUCT->m_End().x, STRUCT->m_End().y ) )
{
LastSnappedStruct = DrawList;
......@@ -299,7 +295,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
y1 = STRUCT->m_Pos.y - dx;
x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx;
if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{
LastSnappedStruct = DrawList;
return TRUE;
......@@ -317,7 +313,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
y1 = STRUCT->m_Pos.y - dx;
x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx;
if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{
LastSnappedStruct = DrawList;
return TRUE;
......@@ -334,7 +330,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
y1 = STRUCT->m_Pos.y - dx;
x2 = STRUCT->m_Pos.x + dx;
y2 = STRUCT->m_Pos.y + dx;
if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{
LastSnappedStruct = DrawList;
return TRUE;
......@@ -371,7 +367,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
break;
}
if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{
LastSnappedStruct = DrawList;
return TRUE;
......@@ -409,7 +405,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
break;
}
if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{
LastSnappedStruct = DrawList;
return TRUE;
......@@ -434,7 +430,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
continue;
EDA_Rect BoundaryBox = field->GetBoundaryBox();
if( BoundaryBox.Inside( x, y ) )
if( BoundaryBox.Inside( aPosRef ) )
{
LastSnappedStruct = field;
return TRUE;
......@@ -446,7 +442,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
#undef STRUCT
#define STRUCT ( (SCH_COMPONENT*) DrawList )
EDA_Rect BoundaryBox = STRUCT->GetBoundaryBox();
if( BoundaryBox.Inside( x, y ) )
if( BoundaryBox.Inside( aPosRef ) )
{
LastSnappedStruct = DrawList;
return TRUE;
......@@ -465,7 +461,7 @@ bool SnapPoint2( const wxPoint& PosRef, int SearchMask,
x2 = STRUCT->m_Pos.x + STRUCT->m_Size.x;
y2 = STRUCT->m_Pos.y + STRUCT->m_Size.y;
if( IsPointInBox( x, y, x1, y1, x2, y2 ) )
if( IsPointInBox( aPosRef, x1, y1, x2, y2 ) )
{
LastSnappedStruct = DrawList;
return TRUE;
......@@ -740,7 +736,7 @@ static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1,
/**********************************************************************/
static bool IsPointInBox( int pX, int pY,
static bool IsPointInBox( wxPoint aPosRef,
int BoxX1, int BoxY1, int BoxX2, int BoxY2 )
/**********************************************************************/
......@@ -754,7 +750,7 @@ static bool IsPointInBox( int pX, int pY,
if( BoxY1 > BoxY2 )
EXCHG( BoxY1, BoxY2 );
if( (pX >= BoxX1) && (pX <= BoxX2) && (pY >= BoxY1) && (pY <= BoxY2) )
if( (aPosRef.x >= BoxX1) && (aPosRef.x <= BoxX2) && (aPosRef.y >= BoxY1) && (aPosRef.y <= BoxY2) )
return TRUE;
else
......@@ -763,7 +759,7 @@ static bool IsPointInBox( int pX, int pY,
/********************************************************************************/
static bool IsPointOnSegment( int pX, int pY,
static bool IsPointOnSegment( wxPoint aPosRef,
int SegmX1, int SegmY1, int SegmX2, int SegmY2, int seuil )
/********************************************************************************/
......@@ -772,10 +768,10 @@ static bool IsPointOnSegment( int pX, int pY,
*/
{
/* Recalcul des coord avec SegmX1, SegmX2 comme origine */
pX -= SegmX1; pY -= SegmY1;
aPosRef.x -= SegmX1; aPosRef.y -= SegmY1;
SegmX2 -= SegmX1; SegmY2 -= SegmY1;
if( distance( SegmX2, SegmY2, pX, pY, seuil ) )
if( distance( SegmX2, SegmY2, aPosRef.x, aPosRef.y, seuil ) )
return TRUE;
else
......@@ -785,7 +781,7 @@ static bool IsPointOnSegment( int pX, int pY,
/*********************************************************************************/
LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
const wxPoint& refpoint,
const wxPoint& aRefPoint,
EDA_LibComponentStruct* LibEntry,
int Unit,
int Convert,
......@@ -798,8 +794,7 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
* toutes variantes)
*/
{
int x, y, dx, dy, ii, * ptpoly;
int px, py;
int dx, dy;
LibEDA_BaseStruct* DrawItem;
int seuil;
......@@ -815,8 +810,6 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
DrawItem = LibEntry->m_Drawings;
seuil = 3; /* Tolerance: 1/2 pas de petite grille */
px = refpoint.x;
py = refpoint.y;
for( ; DrawItem != NULL; DrawItem = DrawItem->Next() )
{
......@@ -832,10 +825,10 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
LibDrawArc* Arc = (LibDrawArc*) DrawItem;
if( (masque & LOCATE_COMPONENT_ARC_DRAW_TYPE) == 0 )
break;
dx = px - Arc->m_Pos.x;
dy = py + Arc->m_Pos.y;
ii = (int) sqrt( ((double)dx * dx) + ((double)dy * dy) );
if( abs( ii - Arc->m_Rayon ) <= seuil )
dx = aRefPoint.x - Arc->m_Pos.x;
dy = aRefPoint.y + Arc->m_Pos.y;
int dist = (int) sqrt( ((double)dx * dx) + ((double)dy * dy) );
if( abs( dist - Arc->m_Rayon ) <= seuil )
return DrawItem;
}
break;
......@@ -845,10 +838,10 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
LibDrawCircle* Circle = (LibDrawCircle*) DrawItem;
if( (masque & LOCATE_COMPONENT_CIRCLE_DRAW_TYPE) == 0 )
break;
dx = px - Circle->m_Pos.x;
dy = py + Circle->m_Pos.y;
ii = (int) sqrt( dx * dx + dy * dy );
if( abs( ii - Circle->m_Rayon ) <= seuil )
dx = aRefPoint.x - Circle->m_Pos.x;
dy = aRefPoint.y + Circle->m_Pos.y;
int dist = (int) sqrt( dx * dx + dy * dy );
if( abs( dist - Circle->m_Rayon ) <= seuil )
return DrawItem;
}
break;
......@@ -858,19 +851,19 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
LibDrawSquare* Square = (LibDrawSquare*) DrawItem;
if( (masque & LOCATE_COMPONENT_RECT_DRAW_TYPE) == 0 )
break;
if( IsPointOnSegment( px, py, // locate lower segment
if( IsPointOnSegment( aRefPoint, // locate lower segment
Square->m_Pos.x, -Square->m_Pos.y,
Square->m_End.x, -Square->m_Pos.y, seuil ) )
return DrawItem;
if( IsPointOnSegment( px, py, // locate right segment
if( IsPointOnSegment( aRefPoint, // locate right segment
Square->m_End.x, -Square->m_Pos.y,
Square->m_End.x, -Square->m_End.y, seuil ) )
return DrawItem;
if( IsPointOnSegment( px, py, // locate upper segment
if( IsPointOnSegment( aRefPoint, // locate upper segment
Square->m_End.x, -Square->m_End.y,
Square->m_Pos.x, -Square->m_End.y, seuil ) )
return DrawItem;
if( IsPointOnSegment( px, py, // locate left segment
if( IsPointOnSegment( aRefPoint, // locate left segment
Square->m_Pos.x, -Square->m_End.y,
Square->m_Pos.x, -Square->m_Pos.y, seuil ) )
return DrawItem;
......@@ -882,11 +875,12 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
LibDrawPolyline* polyline = (LibDrawPolyline*) DrawItem;
if( (masque & LOCATE_COMPONENT_POLYLINE_DRAW_TYPE) == 0 )
break;
ptpoly = polyline->m_PolyList;
for( ii = polyline->m_CornersCount - 1; ii > 0; ii--, ptpoly += 2 )
for( unsigned ii = 0; ii < polyline->m_PolyPoints.size()-1; ii++ )
{
if( IsPointOnSegment( px, py,
ptpoly[0], -ptpoly[1], ptpoly[2], -ptpoly[3], seuil ) )
if( IsPointOnSegment( aRefPoint,
polyline->m_PolyPoints[ii].x, -polyline->m_PolyPoints[ii].y,
polyline->m_PolyPoints[ii+1].x, -polyline->m_PolyPoints[ii+1].y, seuil ) )
return DrawItem;
}
}
......@@ -897,7 +891,7 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
LibDrawSegment* Segment = (LibDrawSegment*) DrawItem;
if( (masque & LOCATE_COMPONENT_LINE_DRAW_TYPE) == 0 )
break;
if( IsPointOnSegment( px, py,
if( IsPointOnSegment( aRefPoint,
Segment->m_Pos.x, -Segment->m_Pos.y,
Segment->m_End.x, -Segment->m_End.y, seuil ) )
return DrawItem;
......@@ -909,16 +903,17 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen,
LibDrawText* Text = (LibDrawText*) DrawItem;
if( (masque & LOCATE_COMPONENT_GRAPHIC_TEXT_DRAW_TYPE) == 0 )
break;
ii = Text->m_Text.Len(); if( ii < 2 )
ii = 2;
dx = (Text->m_Size.x * ii) / 2;
int len = Text->m_Text.Len();
if( len < 2 )
len = 2;
dx = (Text->m_Size.x * len) / 2;
dy = Text->m_Size.y / 2;
if( Text->m_Orient == TEXT_ORIENT_VERT )
{
EXCHG( dx, dy );
}
x = px - Text->m_Pos.x;
y = py + Text->m_Pos.y;
int x = aRefPoint.x - Text->m_Pos.x;
int y = aRefPoint.y + Text->m_Pos.y;
if( (abs( x ) <= dx) && (abs( y ) <= dy) )
return DrawItem; /* Texte trouve */
}
......
......@@ -308,11 +308,10 @@ void PlotLibPart( SCH_COMPONENT* DrawLibItem )
case COMPONENT_POLYLINE_DRAW_TYPE:
{
LibDrawPolyline* polyline = (LibDrawPolyline*) DEntry;
Poly = (int*) MyMalloc( sizeof(int) * 2 * polyline->m_CornersCount );
for( ii = 0; ii < polyline->m_CornersCount; ii++ )
Poly = (int*) MyMalloc( sizeof(int) * 2 * polyline->GetCornerCount() );
for( ii = 0; ii < (int)polyline->GetCornerCount(); ii++ )
{
pos.x = polyline->m_PolyList[ii * 2];
pos.y = polyline->m_PolyList[ii * 2 + 1];
pos = polyline->m_PolyPoints[ii];
pos = TransformCoordinate( TransMat, pos ) + DrawLibItem->m_Pos;
Poly[ii * 2] = pos.x;
Poly[ii * 2 + 1] = pos.y;
......
......@@ -157,17 +157,14 @@ bool LibDrawPin::Save( FILE* ExportFile ) const
bool LibDrawPolyline::Save( FILE* ExportFile ) const
/****************************************************/
{
int ii, * ptpoly;
int ccount = GetCornerCount();
fprintf( ExportFile, "P %d %d %d %d",
m_CornersCount,
ccount,
m_Unit, m_Convert,
m_Width );
ptpoly = m_PolyList;
for( ii = m_CornersCount; ii > 0; ii-- )
for( unsigned ii = 0; ii < GetCornerCount(); ii++ )
{
fprintf( ExportFile, " %d %d", *ptpoly, *(ptpoly + 1) );
ptpoly += 2;
fprintf( ExportFile, " %d %d", m_PolyPoints[ii].x, m_PolyPoints[ii].y );
}
fprintf( ExportFile, " %c\n", fill_tab[m_Fill] );
......
......@@ -196,7 +196,6 @@ LibEDA_BaseStruct* WinEDA_LibeditFrame::CreateGraphicItem( wxDC* DC )
*/
{
int DrawType;
int* ptpoly;
DrawPanel->m_IgnoreMouseEvents = TRUE;
......@@ -274,13 +273,11 @@ LibEDA_BaseStruct* WinEDA_LibeditFrame::CreateGraphicItem( wxDC* DC )
case COMPONENT_POLYLINE_DRAW_TYPE:
{
LibDrawPolyline* polyline = new LibDrawPolyline();
CurrentDrawItem = polyline;
polyline->m_CornersCount = 2;
ptpoly = (int*) MyZMalloc( 4 * sizeof(int) );
polyline->m_PolyList = ptpoly;
ptpoly[0] = ptpoly[2] = GetScreen()->m_Curseur.x;
ptpoly[1] = ptpoly[3] = -( GetScreen()->m_Curseur.y );
wxPoint point = GetScreen()->m_Curseur;
NEGATE( point.y );
polyline->AddPoint( point ); // Start point of the current segment
polyline->AddPoint( point ); // End point of the current segment
polyline->m_Fill = FlSymbol_Fill;
polyline->m_Width = g_LibSymbolDefaultLineWidth;
}
......@@ -378,6 +375,7 @@ void WinEDA_LibeditFrame::GraphicItemBeginDraw( wxDC* DC )
case COMPONENT_POLYLINE_DRAW_TYPE:
{
wxPoint pos = GetScreen()->m_Curseur;
NEGATE(pos.y);
( (LibDrawPolyline*) CurrentDrawItem )->AddPoint( pos );
}
break;
......@@ -423,52 +421,36 @@ static void RedrawWhileMovingCursor( WinEDA_DrawPanel* panel,
void MoveLibDrawItemAt( LibEDA_BaseStruct* DrawItem, wxPoint newpos )
/*****************************************************************/
{
int mx = newpos.x, my = newpos.y;
wxSize size;
NEGATE(newpos.y);
wxPoint size;
switch( DrawItem->Type() )
{
case COMPONENT_ARC_DRAW_TYPE:
{
int dx = mx - ( (LibDrawArc*) CurrentDrawItem )->m_Pos.x;
int dy = -my - ( (LibDrawArc*) CurrentDrawItem )->m_Pos.y;
( (LibDrawArc*) CurrentDrawItem )->m_Pos.x = mx;
( (LibDrawArc*) CurrentDrawItem )->m_Pos.y = -my;
( (LibDrawArc*) CurrentDrawItem )->m_ArcStart.x += dx;
( (LibDrawArc*) CurrentDrawItem )->m_ArcStart.y += dy;
( (LibDrawArc*) CurrentDrawItem )->m_ArcEnd.x += dx;
( (LibDrawArc*) CurrentDrawItem )->m_ArcEnd.y += dy;
wxPoint offset = newpos - ( (LibDrawArc*) CurrentDrawItem )->m_Pos;
( (LibDrawArc*) CurrentDrawItem )->m_Pos = newpos;
( (LibDrawArc*) CurrentDrawItem )->m_ArcStart += offset;
( (LibDrawArc*) CurrentDrawItem )->m_ArcEnd += offset;
break;
}
case COMPONENT_CIRCLE_DRAW_TYPE:
( (LibDrawCircle*) CurrentDrawItem )->m_Pos.x = mx;
( (LibDrawCircle*) CurrentDrawItem )->m_Pos.y = -my;
( (LibDrawCircle*) CurrentDrawItem )->m_Pos = newpos;
break;
case COMPONENT_RECT_DRAW_TYPE:
size.x = ( (LibDrawSquare*) CurrentDrawItem )->m_End.x -
( (LibDrawSquare*) CurrentDrawItem )->m_Pos.x;
size.y = ( (LibDrawSquare*) CurrentDrawItem )->m_End.y -
( (LibDrawSquare*) CurrentDrawItem )->m_Pos.y;
( (LibDrawSquare*) CurrentDrawItem )->m_Pos.x = mx;
( (LibDrawSquare*) CurrentDrawItem )->m_Pos.y = -my;
( (LibDrawSquare*) CurrentDrawItem )->m_End.x = mx + size.x;
( (LibDrawSquare*) CurrentDrawItem )->m_End.y = -my + size.y;
size = ( (LibDrawSquare*) CurrentDrawItem )->m_End - ( (LibDrawSquare*) CurrentDrawItem )->m_Pos;
( (LibDrawSquare*) CurrentDrawItem )->m_Pos = newpos;
( (LibDrawSquare*) CurrentDrawItem )->m_End = newpos + size;
break;
case COMPONENT_POLYLINE_DRAW_TYPE:
{
int ii, imax =
( (LibDrawPolyline*) CurrentDrawItem )->m_CornersCount * 2;
int* ptpoly = ( (LibDrawPolyline*) CurrentDrawItem )->m_PolyList;
int dx = mx - ptpoly[0];
int dy = -my - ptpoly[1];
int ii, imax = ( (LibDrawPolyline*) CurrentDrawItem )->GetCornerCount();
wxPoint offset = newpos - ( (LibDrawPolyline*) CurrentDrawItem )->m_PolyPoints[0];
for( ii = 0; ii < imax; ii += 2 )
{
ptpoly[ii] += dx;
ptpoly[ii + 1] += dy;
}
( (LibDrawPolyline*) CurrentDrawItem )->m_PolyPoints[ii] += offset;
}
break;
......@@ -476,8 +458,7 @@ void MoveLibDrawItemAt( LibEDA_BaseStruct* DrawItem, wxPoint newpos )
break;
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
( (LibDrawText*) CurrentDrawItem )->m_Pos.x = mx;
( (LibDrawText*) CurrentDrawItem )->m_Pos.y = -my;
( (LibDrawText*) CurrentDrawItem )->m_Pos = newpos;
break;
default:
......@@ -513,9 +494,7 @@ void WinEDA_LibeditFrame::StartMoveDrawSymbol( wxDC* DC )
break;
case COMPONENT_POLYLINE_DRAW_TYPE:
InitPosition.x = *( (LibDrawPolyline*) CurrentDrawItem )->m_PolyList;
InitPosition.y =
*( ( (LibDrawPolyline*) CurrentDrawItem )->m_PolyList + 1 );
InitPosition = ( (LibDrawPolyline*) CurrentDrawItem )->m_PolyPoints[0];
break;
case COMPONENT_LINE_DRAW_TYPE:
......@@ -543,11 +522,11 @@ void WinEDA_LibeditFrame::StartMoveDrawSymbol( wxDC* DC )
static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
{
int DrawMode = g_XorMode;
int* ptpoly;
int dx, dy;
BASE_SCREEN* Screen = panel->GetScreen();
int mx = Screen->m_Curseur.x,
my = Screen->m_Curseur.y;
wxPoint curr_pos = Screen->m_Curseur;
NEGATE(curr_pos.y);
GRSetDrawMode( DC, DrawMode );
......@@ -589,7 +568,7 @@ static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
case COMPONENT_ARC_DRAW_TYPE:
if( StateDrawArc == 1 )
{
ArcEndX = mx; ArcEndY = -my;
ArcEndX = curr_pos.x; ArcEndY = curr_pos.y;
}
if( StateDrawArc == 2 )
......@@ -600,31 +579,28 @@ static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
break;
case COMPONENT_CIRCLE_DRAW_TYPE:
dx = ( (LibDrawCircle*) CurrentDrawItem )->m_Pos.x - mx;
dy = ( (LibDrawCircle*) CurrentDrawItem )->m_Pos.y + my;
dx = ( (LibDrawCircle*) CurrentDrawItem )->m_Pos.x - curr_pos.x;
dy = ( (LibDrawCircle*) CurrentDrawItem )->m_Pos.y - curr_pos.y;
( (LibDrawCircle*) CurrentDrawItem )->m_Rayon =
(int) sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) );
( (LibDrawCircle*) CurrentDrawItem )->m_Fill = FlSymbol_Fill;
break;
case COMPONENT_RECT_DRAW_TYPE:
( (LibDrawSquare*) CurrentDrawItem )->m_End.x = mx;
( (LibDrawSquare*) CurrentDrawItem )->m_End.y = -my;
( (LibDrawSquare*) CurrentDrawItem )->m_End = curr_pos;
( (LibDrawSquare*) CurrentDrawItem )->m_Fill = FlSymbol_Fill;
break;
case COMPONENT_POLYLINE_DRAW_TYPE:
ptpoly = ( (LibDrawPolyline*) CurrentDrawItem )->m_PolyList;
ptpoly += 2 *
( ( (LibDrawPolyline*) CurrentDrawItem )->m_CornersCount - 1 );
ptpoly[0] = mx;
ptpoly[1] = -my;
{
unsigned idx = ( (LibDrawPolyline*) CurrentDrawItem )->GetCornerCount() - 1;
( (LibDrawPolyline*) CurrentDrawItem )->m_PolyPoints[idx] = curr_pos;
( (LibDrawPolyline*) CurrentDrawItem )->m_Fill = FlSymbol_Fill;
}
break;
case COMPONENT_LINE_DRAW_TYPE:
( (LibDrawSegment*) CurrentDrawItem )->m_End.x = mx;
( (LibDrawSegment*) CurrentDrawItem )->m_End.y = -my;
( (LibDrawSegment*) CurrentDrawItem )->m_End = curr_pos;
break;
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE: /* Traite par des routines specifiques */
......@@ -856,28 +832,24 @@ void WinEDA_LibeditFrame::DeleteDrawPoly( wxDC* DC )
if( CurrentDrawItem->Type() != COMPONENT_POLYLINE_DRAW_TYPE )
return;
int* ptpoly;
LibDrawPolyline* Poly = (LibDrawPolyline*) CurrentDrawItem;
DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry, wxPoint( 0, 0 ),
CurrentDrawItem, g_XorMode );
while( Poly->m_CornersCount > 2 ) // First segment is kept, only its end point is changed
while ( Poly->GetCornerCount() > 2 ) // First segment is kept, only its end point is changed
{
Poly->m_CornersCount--;
ptpoly = Poly->m_PolyList + ( 2 * (Poly->m_CornersCount - 1) );
if( (ptpoly[0] != GetScreen()->m_Curseur.x)
|| (ptpoly[1] != -GetScreen()->m_Curseur.y) )
Poly->m_PolyPoints.pop_back();
unsigned idx = Poly->GetCornerCount() - 1;
wxPoint point = GetScreen()->m_Curseur;
NEGATE( point.y );
if( Poly->m_PolyPoints[idx] != point )
{
ptpoly[0] = GetScreen()->m_Curseur.x;
ptpoly[1] = -( GetScreen()->m_Curseur.y);
Poly->m_PolyPoints[idx] = point;
break;
}
}
int allocsize = 2 * sizeof(int) * Poly->m_CornersCount;
Poly->m_PolyList = (int*) realloc( Poly->m_PolyList, allocsize );
DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry, wxPoint( 0, 0 ),
CurrentDrawItem, g_XorMode );
}
......@@ -270,9 +270,6 @@ static bool CompareSymbols( LibEDA_BaseStruct* DEntryRef,
* TRUE si they are identical, and therefore redundant
*/
{
int ii;
int* ptref, * ptcomp;
/* Comparaison des proprietes generales */
if( DEntryRef->Type() != DEntryCompare->Type() )
return FALSE;
......@@ -349,15 +346,12 @@ static bool CompareSymbols( LibEDA_BaseStruct* DEntryRef,
#undef CMPSTRUCT
#define REFSTRUCT ( (LibDrawPolyline*) DEntryRef )
#define CMPSTRUCT ( (LibDrawPolyline*) DEntryCompare )
if( REFSTRUCT->m_CornersCount != CMPSTRUCT->m_CornersCount )
if( REFSTRUCT->GetCornerCount() != CMPSTRUCT->GetCornerCount() )
return FALSE;
ptref = REFSTRUCT->m_PolyList;
ptcomp = CMPSTRUCT->m_PolyList;
for( ii = 2 * REFSTRUCT->m_CornersCount; ii > 0; ii-- )
for( unsigned ii = 0; ii < REFSTRUCT->GetCornerCount(); ii++ )
{
if( *ptref != *ptcomp )
return FALSE;
ptref++; ptcomp++;
if( REFSTRUCT->m_PolyPoints[ii] != CMPSTRUCT->m_PolyPoints[ii] )
return false;
}
break;
......@@ -440,14 +434,8 @@ void WinEDA_LibeditFrame::PlaceAncre()
case COMPONENT_POLYLINE_DRAW_TYPE:
#undef STRUCT
#define STRUCT ( (LibDrawPolyline*) DrawEntry )
int ii;
int* ptsegm;
for( ptsegm = STRUCT->m_PolyList,
ii = STRUCT->m_CornersCount; ii > 0; ii-- )
{
*ptsegm++ += offset.x;
*ptsegm++ += offset.y;
}
for( unsigned ii = 0; ii < STRUCT->GetCornerCount(); ii ++ )
STRUCT->m_PolyPoints[ii] += offset;
break;
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment