diff --git a/CHANGELOG.txt b/CHANGELOG.txt index e171ffbdcd..d2bf297ea8 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -10,6 +10,7 @@ email address. ++Eeschema: Code cleaning. LibDrawPolyline uses now std::vector to handle corners. + DrawPolylineStruct uses now std::vector to handle corners. diff --git a/eeschema/block.cpp b/eeschema/block.cpp index c3b8c60586..18b11b3757 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -626,7 +626,7 @@ void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& Center ) /* Given a structure rotate it to 90 degrees refer to the Center point. */ { - int dx, ii, * Points; + int dx; DrawPolylineStruct* DrawPoly; DrawJunctionStruct* DrawConnect; EDA_DrawLineStruct* DrawSegment; @@ -652,13 +652,12 @@ void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& Center ) case DRAW_POLYLINE_STRUCT_TYPE: DrawPoly = (DrawPolylineStruct*) DrawStruct; - Points = DrawPoly->m_Points; - for( ii = 0; ii < DrawPoly->m_NumOfPoints; ii++ ) + for( unsigned ii = 0; ii < DrawPoly->GetCornerCount(); ii++ ) { wxPoint point; - point.x = Points[ii * 2]; point.y = Points[ii * 2 + 1]; + point = DrawPoly->m_PolyPoints[ii]; MirrorYPoint( point, Center ); - Points[ii * 2] = point.x; Points[ii * 2 + 1] = point.y; + DrawPoly->m_PolyPoints[ii] = point; } break; @@ -740,7 +739,7 @@ void MirrorOneStruct( SCH_ITEM* DrawStruct, wxPoint& Center ) MirrorYPoint( DrawLibItem->m_Pos, Center ); dx -= DrawLibItem->m_Pos.x; - for( ii = 0; ii < DrawLibItem->GetFieldCount(); ii++ ) + for( int ii = 0; ii < DrawLibItem->GetFieldCount(); ii++ ) { /* move the fields to the new position because the component itself has moved */ DrawLibItem->GetField( ii )->m_Pos.x -= dx; @@ -1194,7 +1193,6 @@ void MoveOneStruct( SCH_ITEM* DrawStruct, const wxPoint& move_vector ) /* Given a structure move it by Dx, Dy. */ { - int ii, * Points; DrawPolylineStruct* DrawPoly; DrawJunctionStruct* DrawConnect; EDA_DrawLineStruct* DrawSegment; @@ -1215,11 +1213,9 @@ void MoveOneStruct( SCH_ITEM* DrawStruct, const wxPoint& move_vector ) case DRAW_POLYLINE_STRUCT_TYPE: DrawPoly = (DrawPolylineStruct*) DrawStruct; - Points = DrawPoly->m_Points; - for( ii = 0; ii < DrawPoly->m_NumOfPoints; ii++ ) + for( unsigned ii = 0; ii < DrawPoly->GetCornerCount(); ii++ ) { - Points[ii * 2] += move_vector.x; - Points[ii * 2 + 1] += move_vector.y; + DrawPoly->m_PolyPoints[ii] += move_vector; } break; @@ -1275,7 +1271,7 @@ void MoveOneStruct( SCH_ITEM* DrawStruct, const wxPoint& move_vector ) case TYPE_SCH_COMPONENT: DrawLibItem = (SCH_COMPONENT*) DrawStruct; DrawLibItem->m_Pos += move_vector; - for( ii = 0; ii < DrawLibItem->GetFieldCount(); ii++ ) + for( int ii = 0; ii < DrawLibItem->GetFieldCount(); ii++ ) { DrawLibItem->GetField( ii )->m_Pos += move_vector; } diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index 94d0c15f84..9dbc919f67 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -474,24 +474,22 @@ static void Show_Polyline_in_Ghost( WinEDA_DrawPanel* panel, wxDC* DC, bool eras GRSetDrawMode( DC, g_XorMode ); + int idx = NewPoly->GetCornerCount() - 1; if( g_HVLines ) { /* Coerce the line to vertical or horizontal one: */ - if( ABS( endpos.x - NewPoly->m_Points[NewPoly->m_NumOfPoints * 2 - 2] ) < - ABS( endpos.y - NewPoly->m_Points[NewPoly->m_NumOfPoints * 2 - 1] ) ) - endpos.x = NewPoly->m_Points[NewPoly->m_NumOfPoints * 2 - 2]; + if( ABS( endpos.x - NewPoly->m_PolyPoints[idx].x ) < + ABS( endpos.y - NewPoly->m_PolyPoints[idx].y ) ) + endpos.x = NewPoly->m_PolyPoints[idx].x; else - endpos.y = NewPoly->m_Points[NewPoly->m_NumOfPoints * 2 - 1]; + endpos.y = NewPoly->m_PolyPoints[idx].y; } - NewPoly->m_NumOfPoints++; if( erase ) RedrawOneStruct( panel, DC, NewPoly, g_XorMode, color ); - NewPoly->m_Points[NewPoly->m_NumOfPoints * 2 - 2] = endpos.x; - NewPoly->m_Points[NewPoly->m_NumOfPoints * 2 - 1] = endpos.y; + NewPoly->m_PolyPoints[idx] = endpos; RedrawOneStruct( panel, DC, NewPoly, g_XorMode, color ); - NewPoly->m_NumOfPoints--; } diff --git a/eeschema/class_libentry_fields.h b/eeschema/class_libentry_fields.h index 23092ee651..80ee38ed31 100644 --- a/eeschema/class_libentry_fields.h +++ b/eeschema/class_libentry_fields.h @@ -59,7 +59,7 @@ public: void SetFields( const std::vector aFields ); void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ); + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ); /** * Function HitTest diff --git a/eeschema/class_pin.cpp b/eeschema/class_pin.cpp index 36eec7e3bf..29a4acd59c 100644 --- a/eeschema/class_pin.cpp +++ b/eeschema/class_pin.cpp @@ -19,7 +19,7 @@ void LibDrawPin::Draw( WinEDA_DrawPanel* aPanel, int aColor, int aDrawMode, void* aData, - int aTransformMatrix[2][2] ) + const int aTransformMatrix[2][2] ) /**********************************************************************************************/ { // Invisibles pins are only drawn on request. @@ -866,7 +866,7 @@ wxPoint LibDrawPin::ReturnPinEndPoint() /********************************************************/ -int LibDrawPin::ReturnPinDrawOrient( int TransMat[2][2] ) +int LibDrawPin::ReturnPinDrawOrient( const int TransMat[2][2] ) /********************************************************/ /** Function ReturnPinDrawOrient diff --git a/eeschema/class_schematic_items.cpp b/eeschema/class_schematic_items.cpp index c7309d7513..89a9c7d6f8 100644 --- a/eeschema/class_schematic_items.cpp +++ b/eeschema/class_schematic_items.cpp @@ -427,8 +427,6 @@ DrawPolylineStruct::DrawPolylineStruct( int layer ) : SCH_ITEM( NULL, DRAW_POLYLINE_STRUCT_TYPE ) /***********************************************************/ { - m_NumOfPoints = 0; /* Number of XY pairs in Points array. */ - m_Points = NULL; /* XY pairs that forms the polyline. */ m_Width = GR_NORM_WIDTH; switch( layer ) @@ -454,8 +452,6 @@ DrawPolylineStruct::DrawPolylineStruct( int layer ) : DrawPolylineStruct::~DrawPolylineStruct() /*********************************************/ { - if( m_Points ) - free( m_Points ); } @@ -463,16 +459,9 @@ DrawPolylineStruct::~DrawPolylineStruct() DrawPolylineStruct* DrawPolylineStruct::GenCopy() /*****************************************************/ { - int memsize; - DrawPolylineStruct* newitem = new DrawPolylineStruct( m_Layer ); - - memsize = sizeof(int) * 2 * m_NumOfPoints; - newitem->m_NumOfPoints = m_NumOfPoints; - newitem->m_Points = (int*) MyZMalloc( memsize ); - memcpy( newitem->m_Points, m_Points, memsize ); - + newitem->m_PolyPoints = m_PolyPoints; // std::vector copy return newitem; } @@ -497,16 +486,15 @@ bool DrawPolylineStruct::Save( FILE* aFile ) const if( m_Width != GR_NORM_WIDTH ) width = "Bus"; if( fprintf( aFile, "Poly %s %s %d\n", - width, layer, m_NumOfPoints ) == EOF ) + width, layer, GetCornerCount() ) == EOF ) { success = false; return success; } - for( int ii = 0; ii < m_NumOfPoints; ii++ ) + for( unsigned ii = 0; ii < GetCornerCount(); ii++ ) { if( fprintf( aFile, "\t%-4d %-4d\n", - m_Points[ii * 2], - m_Points[ii * 2 + 1] ) == EOF ) + m_PolyPoints[ii ].x, m_PolyPoints[ii].y ) == EOF ) { success = false; break; diff --git a/eeschema/class_schematic_items.h b/eeschema/class_schematic_items.h new file mode 100644 index 0000000000..ee4c273822 --- /dev/null +++ b/eeschema/class_schematic_items.h @@ -0,0 +1,285 @@ +/************************************************************************/ +/* classes to handle items used in schematic: wires, bus, junctions ... */ +/************************************************************************/ + +#ifndef CLASS_SCHEMATIC_ITEMS_H +#define CLASS_SCHEMATIC_ITEMS_H + +#ifndef eda_global +#define eda_global extern +#endif + +#define DRAWJUNCTION_SIZE 16 /* Rayon du symbole connexion */ +#define DRAWMARKER_SIZE 16 /* Rayon du symbole marqueur */ +#define DRAWNOCONNECT_SIZE 48 /* Rayon du symbole No Connexion */ + +/* flags pour BUS ENTRY (bus to bus ou wire to bus */ +#define WIRE_TO_BUS 0 +#define BUS_TO_BUS 1 + + +enum TypeMarker { /* Type des Marqueurs */ + MARQ_UNSPEC, + MARQ_ERC, + MARQ_PCB, + MARQ_SIMUL, + MARQ_NMAX /* Derniere valeur: fin de tableau */ +}; + + +/* Messages correspondants aux types des marqueurs */ +#ifdef MAIN +const wxChar* NameMarqueurType[] = +{ + wxT( "" ), + wxT( "ERC" ), + wxT( "PCB" ), + wxT( "SIMUL" ), + wxT( "?????" ) +}; +#else +extern const wxChar* NameMarqueurType[]; +#endif + + +/** + * Class EDA_DrawLineStruct + * is a segment decription base class to describe items which have 2 end + * points (track, wire, draw line ...) + */ +class EDA_DrawLineStruct : public SCH_ITEM +{ +public: + int m_Width; // 0 = line, > 0 = tracks, bus ... + wxPoint m_Start; // Line start point + wxPoint m_End; // Line end point + + bool m_StartIsDangling; + bool m_EndIsDangling; // TRUE si Start ou End not connected (wires, tracks...) + +public: + EDA_DrawLineStruct( const wxPoint& pos, int layer ); + ~EDA_DrawLineStruct() { } + + EDA_DrawLineStruct* Next() const { return (EDA_DrawLineStruct*) Pnext; } + EDA_DrawLineStruct* Back() const { return (EDA_DrawLineStruct*) Pback; } + + virtual wxString GetClass() const + { + return wxT( "EDA_DrawLine" ); + } + + + bool IsOneEndPointAt( const wxPoint& pos ); + EDA_DrawLineStruct* GenCopy(); + + bool IsNull() + { + return m_Start == m_End; + } + + + EDA_Rect GetBoundingBox(); + + virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode, + int Color = -1 ); + + /** + * Function Save + * writes the data structures for this object out to a FILE in "*.brd" format. + * @param aFile The FILE to write to. + * @return bool - true if success writing else false. + */ + bool Save( FILE* aFile ) const; + +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ); + +#endif +}; + + +class DrawMarkerStruct : public SCH_ITEM /* marqueurs */ +{ +public: + wxPoint m_Pos; /* XY coordinates of marker. */ + TypeMarker m_Type; + int m_MarkFlags; // complements d'information + wxString m_Comment; /* Texte (commentaireassocie eventuel */ + +public: + DrawMarkerStruct( const wxPoint& pos, const wxString& text ); + ~DrawMarkerStruct(); + virtual wxString GetClass() const + { + return wxT( "DrawMarker" ); + } + + + DrawMarkerStruct* GenCopy(); + wxString GetComment(); + virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, + int draw_mode, int Color = -1 ); + + /** + * Function Save + * writes the data structures for this object out to a FILE in "*.brd" format. + * @param aFile The FILE to write to. + * @return bool - true if success writing else false. + */ + bool Save( FILE* aFile ) const; + +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ); + +#endif +}; + + +class DrawNoConnectStruct : public SCH_ITEM /* Symboles de non connexion */ +{ +public: + wxPoint m_Pos; /* XY coordinates of NoConnect. */ + +public: + DrawNoConnectStruct( const wxPoint& pos ); + ~DrawNoConnectStruct() { } + virtual wxString GetClass() const + { + return wxT( "DrawNoConnect" ); + } + + + DrawNoConnectStruct* GenCopy(); + virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, + int draw_mode, int Color = -1 ); + + /** + * Function Save + * writes the data structures for this object out to a FILE in "*.brd" format. + * @param aFile The FILE to write to. + * @return bool - true if success writing else false. + */ + bool Save( FILE* aFile ) const; + + EDA_Rect GetBoundingBox(); +}; + + +/** + * Class DrawBusEntryStruct + * Struct de descr 1 raccord a 45 degres de BUS ou WIRE + */ +class DrawBusEntryStruct : public SCH_ITEM +{ +public: + int m_Width; + wxPoint m_Pos; + wxSize m_Size; + +public: + DrawBusEntryStruct( const wxPoint& pos, int shape, int id ); + ~DrawBusEntryStruct() { } + + virtual wxString GetClass() const + { + return wxT( "DrawBusEntry" ); + } + + + DrawBusEntryStruct* GenCopy(); + wxPoint m_End() const; // retourne la coord de fin du raccord + virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, + int draw_mode, int Color = -1 ); + + /** + * Function Save + * writes the data structures for this object out to a FILE in "*.brd" format. + * @param aFile The FILE to write to. + * @return bool - true if success writing else false. + */ + bool Save( FILE* aFile ) const; + + EDA_Rect GetBoundingBox(); +}; + +class DrawPolylineStruct : public SCH_ITEM /* Polyligne (serie de segments) */ +{ +public: + int m_Width; /* Tickness */ + std::vector m_PolyPoints; // list of points (>= 2) + +public: + DrawPolylineStruct( int layer ); + ~DrawPolylineStruct(); + + virtual wxString GetClass() const + { + return wxT( "DrawPolyline" ); + } + + + DrawPolylineStruct* GenCopy(); + virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, + int draw_mode, int Color = -1 ); + + /** + * Function Save + * writes the data structures for this object out to a FILE in "*.brd" format. + * @param aFile The FILE to write to. + * @return bool - true if success writing else false. + */ + bool Save( FILE* aFile ) const; + + /** Function AddPoint + * add a corner to m_PolyPoints + */ + void AddPoint( const wxPoint& point ) + { + m_PolyPoints.push_back( point ); + } + + /** Function GetCornerCount + * @return the number of corners + */ + + unsigned GetCornerCount() const { return m_PolyPoints.size(); } +}; + +class DrawJunctionStruct : public SCH_ITEM +{ +public: + wxPoint m_Pos; /* XY coordinates of connection. */ + +public: + DrawJunctionStruct( const wxPoint& pos ); + ~DrawJunctionStruct() { } + + virtual wxString GetClass() const + { + return wxT( "DrawJunction" ); + } + + + EDA_Rect GetBoundingBox(); + + DrawJunctionStruct* GenCopy(); + + virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, + int draw_mode, int Color = -1 ); + /** + * Function Save + * writes the data structures for this object out to a FILE in "*.brd" format. + * @param aFile The FILE to write to. + * @return bool - true if success writing else false. + */ + bool Save( FILE* aFile ) const; + +#if defined(DEBUG) + void Show( int nestLevel, std::ostream& os ); + +#endif +}; + + +#endif /* CLASS_SCHEMATIC_ITEMS_H */ diff --git a/eeschema/classes_body_items.cpp b/eeschema/classes_body_items.cpp index a51c438165..0f9bb34ca9 100644 --- a/eeschema/classes_body_items.cpp +++ b/eeschema/classes_body_items.cpp @@ -23,7 +23,7 @@ LibEDA_BaseStruct::LibEDA_BaseStruct( KICAD_T struct_type ) : * 0 if the item is common to all units */ m_Convert = 0; /* Shape identification (for parts which have a convert shape) * 0 if the item is common to all shapes */ - m_Fill = NO_FILL; + m_Fill = NO_FILL; } @@ -39,7 +39,7 @@ LibEDA_BaseStruct::LibEDA_BaseStruct( KICAD_T struct_type ) : /**********************************************************************************************/ void LibDrawArc::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ) + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ) /**********************************************************************************************/ { wxPoint pos1, pos2, posc; @@ -75,31 +75,31 @@ void LibDrawArc::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffs if( fill == FILLED_WITH_BG_BODYCOLOR ) GRFilledArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2, - m_Rayon, linewidth, color, - ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); + m_Rayon, linewidth, color, + ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); else if( fill == FILLED_SHAPE && !aData ) GRFilledArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2, - m_Rayon, color, color ); + m_Rayon, color, color ); else #ifdef DRAW_ARC_WITH_ANGLE GRArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2, - m_Rayon, linewidth, color ); + m_Rayon, linewidth, color ); #else GRArc1( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y, - posc.x, posc.y, linewidth, color ); + posc.x, posc.y, linewidth, color ); #endif } /*************************************************************************************************/ void LibDrawCircle::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ) + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ) /*************************************************************************************************/ { wxPoint pos1; @@ -124,20 +124,20 @@ void LibDrawCircle::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aO if( fill == FILLED_WITH_BG_BODYCOLOR ) GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, - m_Rayon, linewidth, color, - ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); + m_Rayon, linewidth, color, + ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); else if( fill == FILLED_SHAPE ) GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, - m_Rayon, 0, color, color ); + m_Rayon, 0, color, color ); else GRCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, - m_Rayon, linewidth, color ); + m_Rayon, linewidth, color ); } /*************************************************************************************************/ void LibDrawText::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ) + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ) /*************************************************************************************************/ { wxPoint pos1, pos2; @@ -160,15 +160,15 @@ void LibDrawText::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOff int t1 = (aTransformMatrix[0][0] != 0) ^ (m_Orient != 0); DrawGraphicText( aPanel, aDC, pos1, (EDA_Colors) color, m_Text, - t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT, - m_Size, - GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, linewidth, m_Italic ); + t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT, + m_Size, + GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, linewidth, m_Italic ); } /*************************************************************************************************/ void LibDrawSquare::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ) + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ) /*************************************************************************************************/ { wxPoint pos1, pos2; @@ -193,20 +193,20 @@ void LibDrawSquare::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aO if( fill == FILLED_WITH_BG_BODYCOLOR && !aData ) GRFilledRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y, - linewidth, color, - ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); + linewidth, color, + ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); else if( m_Fill == FILLED_SHAPE && !aData ) GRFilledRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y, - linewidth, color, color ); + linewidth, color, color ); else GRRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y, - linewidth, color ); + linewidth, color ); } /*************************************************************************************************/ void LibDrawSegment::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ) + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ) /*************************************************************************************************/ { wxPoint pos1, pos2; @@ -233,17 +233,17 @@ void LibDrawSegment::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& a void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, int aDrawMode, void* aData, - int aTransformMatrix[2][2] ) + const int aTransformMatrix[2][2] ) /*************************************************************************************************/ { - wxPoint pos1; + wxPoint pos1; - int color = ReturnLayerColor( LAYER_DEVICE ); - int linewidth = MAX( m_Width, g_DrawMinimunLineWidth ); - 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 + int color = ReturnLayerColor( LAYER_DEVICE ); + int linewidth = MAX( m_Width, g_DrawMinimunLineWidth ); + 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 + if( aColor < 0 ) // Used normal color or selected color { if( (m_Selected & IS_SELECTED) ) color = g_ItemSelectetColor; @@ -261,12 +261,13 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, { Buf_Poly_Size = m_PolyPoints.size(); Buf_Poly_Drawings = (wxPoint*) realloc( Buf_Poly_Drawings, - sizeof(wxPoint) * Buf_Poly_Size ); + sizeof(wxPoint) * Buf_Poly_Size ); } for( unsigned ii = 0; ii < m_PolyPoints.size(); ii++ ) { - Buf_Poly_Drawings[ii] = TransformCoordinate( aTransformMatrix, m_PolyPoints[ii] ) + aOffset; + Buf_Poly_Drawings[ii] = + TransformCoordinate( aTransformMatrix, m_PolyPoints[ii] ) + aOffset; } FILL_T fill = aData ? NO_FILL : m_Fill; @@ -275,20 +276,20 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, if( fill == FILLED_WITH_BG_BODYCOLOR ) GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(), - Buf_Poly_Drawings, 1, linewidth, color, - ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); + Buf_Poly_Drawings, 1, linewidth, color, + ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); else if( fill == FILLED_SHAPE ) - GRPoly( &aPanel->m_ClipBox, aDC,m_PolyPoints.size(), - 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_PolyPoints.size(), - Buf_Poly_Drawings, 0, linewidth, color, color ); + Buf_Poly_Drawings, 0, linewidth, color, color ); } /*************************************************************************************************/ void LibDrawField::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ) + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ) /*************************************************************************************************/ /* if aData not NULL, aData must point a wxString which is used instead of the m_Text @@ -329,10 +330,10 @@ void LibDrawField::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOf wxString* text = aData ? (wxString*) aData : &m_Text; GRSetDrawMode( aDC, aDrawMode ); DrawGraphicText( aPanel, aDC, text_pos, - (EDA_Colors) color, text->GetData(), - m_Orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ, - m_Size, - m_HJustify, m_VJustify, linewidth, m_Italic ); + (EDA_Colors) color, text->GetData(), + m_Orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ, + m_Size, + m_HJustify, m_VJustify, linewidth, m_Italic ); } @@ -347,12 +348,12 @@ bool LibDrawField::HitTest( const wxPoint& refPos ) EDA_Rect bbox; // bounding box for the text bbox.SetOrigin( m_Pos ); - int dx; // X size for the full text - if ( m_FieldId == REFERENCE ) - dx = m_Size.x * (m_Text.Len( ) + 1); // The displayed text has one char more (U is displayed U?) + int dx; // X size for the full text + if( m_FieldId == REFERENCE ) + dx = m_Size.x * (m_Text.Len() + 1); // The displayed text has one char more (U is displayed U?) else - dx = m_Size.x * m_Text.Len( ); - dx = (int) ((double) dx * 10.0/9); // spacing between char is 0.1 the char size + dx = m_Size.x * m_Text.Len(); + dx = (int) ( (double) dx * 10.0 / 9 ); // spacing between char is 0.1 the char size int dy = m_Size.y; if( m_Orient ) @@ -386,7 +387,7 @@ LibDrawArc::LibDrawArc() : LibEDA_BaseStruct( COMPONENT_ARC_DRAW_TYPE ) /**************************************************************/ { m_Rayon = 0; - t1 = t2 = 0; + t1 = t2 = 0; m_Width = 0; m_Fill = NO_FILL; } @@ -398,12 +399,12 @@ LibDrawArc* LibDrawArc::GenCopy() { LibDrawArc* newitem = new LibDrawArc(); - newitem->m_Pos = m_Pos; + newitem->m_Pos = m_Pos; newitem->m_ArcStart = m_ArcStart; newitem->m_ArcEnd = m_ArcEnd; newitem->m_Rayon = m_Rayon; - newitem->t1 = t1; - newitem->t2 = t2; + newitem->t1 = t1; + newitem->t2 = t2; newitem->m_Width = m_Width; newitem->m_Unit = m_Unit; newitem->m_Convert = m_Convert; @@ -441,10 +442,10 @@ LibDrawCircle* LibDrawCircle::GenCopy() /*****************************************************************/ LibDrawText::LibDrawText() : LibEDA_BaseStruct( COMPONENT_GRAPHIC_TEXT_DRAW_TYPE ), - EDA_TextStruct() + EDA_TextStruct() /*****************************************************************/ { - m_Size = wxSize( 50, 50 ); + m_Size = wxSize( 50, 50 ); } @@ -454,18 +455,18 @@ LibDrawText* LibDrawText::GenCopy() { LibDrawText* newitem = new LibDrawText(); - newitem->m_Pos = m_Pos; - newitem->m_Orient = m_Orient; - newitem->m_Size = m_Size; - newitem->m_Attributs = m_Attributs; - newitem->m_Unit = m_Unit; - newitem->m_Convert = m_Convert; - newitem->m_Flags = m_Flags; - newitem->m_Text = m_Text; - newitem->m_Width = m_Width; + newitem->m_Pos = m_Pos; + newitem->m_Orient = m_Orient; + newitem->m_Size = m_Size; + newitem->m_Attributs = m_Attributs; + newitem->m_Unit = m_Unit; + newitem->m_Convert = m_Convert; + newitem->m_Flags = m_Flags; + newitem->m_Text = m_Text; + newitem->m_Width = m_Width; newitem->m_Italic = m_Italic; - newitem->m_HJustify = m_HJustify; - newitem->m_VJustify = m_VJustify; + newitem->m_HJustify = m_HJustify; + newitem->m_VJustify = m_VJustify; return newitem; } @@ -514,8 +515,8 @@ LibDrawSegment* LibDrawSegment::GenCopy() LibDrawPolyline::LibDrawPolyline() : LibEDA_BaseStruct( COMPONENT_POLYLINE_DRAW_TYPE ) { - m_Fill = NO_FILL; - m_Width = 0; + m_Fill = NO_FILL; + m_Width = 0; } @@ -524,6 +525,7 @@ LibDrawPolyline* LibDrawPolyline::GenCopy() /************************************************/ { LibDrawPolyline* newitem = new LibDrawPolyline(); + newitem->m_PolyPoints = m_PolyPoints; // Vector copy newitem->m_Width = m_Width; newitem->m_Unit = m_Unit; @@ -551,31 +553,33 @@ void LibDrawPolyline::AddPoint( const wxPoint& point ) * @param aThreshold = max distance to a segment * @param aTransMat = the transform matrix */ -bool LibDrawPolyline::HitTest( wxPoint aPosRef, int aThreshold, int aTransMat[2][2] ) +bool LibDrawPolyline::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] ) { + wxPoint ref, start, end; - aPosRef = TransformCoordinate( aTransMat, aPosRef); - /* Move origin coordinate to segment start point */ - wxPoint end; - for ( unsigned ii = 0; ii < m_PolyPoints.size() -1; ii++ ) + for( unsigned ii = 0; ii < m_PolyPoints.size() - 1; ii++ ) { - aPosRef -= m_PolyPoints[0]; - end = m_PolyPoints[1] - m_PolyPoints[0]; + start = TransformCoordinate( aTransMat, m_PolyPoints[0] ); + end = TransformCoordinate( aTransMat, m_PolyPoints[1] ); + ref = aPosRef - start; + end -= start; - if( distance( end.x, end.y, aPosRef.x, aPosRef.y, aThreshold ) ) - return true; + if( distance( end.x, end.y, ref.x, ref.y, aThreshold ) ) + return true; } return false; } + /** Function GetBoundaryBox * @return the boundary box for this, in library coordinates */ -EDA_Rect LibDrawPolyline::GetBoundaryBox( ) +EDA_Rect LibDrawPolyline::GetBoundaryBox() { - EDA_Rect BoundaryBox; - int xmin, xmax, ymin, ymax; + 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++ ) @@ -585,6 +589,7 @@ EDA_Rect LibDrawPolyline::GetBoundaryBox( ) 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 ); diff --git a/eeschema/classes_body_items.h b/eeschema/classes_body_items.h index f426a9ce57..b21f312c92 100644 --- a/eeschema/classes_body_items.h +++ b/eeschema/classes_body_items.h @@ -3,7 +3,7 @@ /****************************************************************/ /* Definitions of graphic items used to create shapes of component in libraries (libentry) -*/ + */ #ifndef CLASSES_BODY_ITEMS_H #define CLASSES_BODY_ITEMS_H @@ -56,7 +56,7 @@ enum ElectricPinType { /* Type des Pins. si modif: modifier tableau des mgs /* Messages d'affichage du type electrique */ eda_global const wxChar* MsgPinElectricType[] #ifdef MAIN -= { + = { wxT( "input" ), wxT( "output" ), wxT( "BiDi" ), @@ -68,7 +68,7 @@ eda_global const wxChar* MsgPinElectricType[] wxT( "openCol" ), wxT( "openEm" ), wxT( "?????" ) -} + } #endif @@ -128,11 +128,11 @@ public: class LibEDA_BaseStruct : public EDA_BaseStruct { public: - int m_Unit; /* Unit identification (for multi part per parkage) + int m_Unit; /* Unit identification (for multi part per parkage) * 0 if the item is common to all units */ - int m_Convert; /* Shape identification (for parts which have a convert shape) + int m_Convert; /* Shape identification (for parts which have a convert shape) * 0 if the item is common to all shapes */ - FILL_T m_Fill; /* NO_FILL, FILLED_SHAPE or FILLED_WITH_BG_BODYCOLOR. has meaning only for some items */ + FILL_T m_Fill; /* NO_FILL, FILLED_SHAPE or FILLED_WITH_BG_BODYCOLOR. has meaning only for some items */ public: LibEDA_BaseStruct* Next() @@ -158,7 +158,7 @@ public: * @param aTransformMatrix = Transform Matrix (rotaion, mirror ..) */ virtual void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ) = 0; + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ) = 0; /** * Function Save @@ -166,9 +166,9 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - virtual bool Save( FILE* aFile ) const = 0; + virtual bool Save( FILE* aFile ) const = 0; - void Display_Infos_DrawEntry( WinEDA_DrawFrame* frame ); + void Display_Infos_DrawEntry( WinEDA_DrawFrame* frame ); }; @@ -189,8 +189,8 @@ public: int m_PinNumSize, m_PinNameSize; /* Pin num and Pin name sizes */ // int m_PinNumWidth, m_PinNameWidth; /* (Currently Unused) Pin num and Pin name text width */ - wxPoint m_Pos; /* Position or centre (Arc and Circle) or start point (segments) */ - int m_Width; /* Tickness */ + wxPoint m_Pos; /* Position or centre (Arc and Circle) or start point (segments) */ + int m_Width; /* Tickness */ public: LibDrawPin(); @@ -211,30 +211,35 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - virtual bool Save( FILE* aFile ) const; + virtual bool Save( FILE* aFile ) const; - LibDrawPin* GenCopy(); - void Display_Infos( WinEDA_DrawFrame* frame ); - wxPoint ReturnPinEndPoint(); + LibDrawPin* GenCopy(); + void Display_Infos( WinEDA_DrawFrame* frame ); + wxPoint ReturnPinEndPoint(); - int ReturnPinDrawOrient( int TransMat[2][2] ); - void ReturnPinStringNum( wxString& buffer ) const; - void SetPinNumFromString( wxString& buffer ); + int ReturnPinDrawOrient( const int TransMat[2][2] ); + void ReturnPinStringNum( wxString& buffer ) const; + void SetPinNumFromString( wxString& buffer ); void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ); + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ); - void DrawPinSymbol( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& pin_pos, - int orient, - int DrawMode, int Color = -1 ); + void DrawPinSymbol( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& pin_pos, + int orient, + int DrawMode, int Color = -1 ); - void DrawPinTexts( WinEDA_DrawPanel* panel, wxDC* DC, - wxPoint& pin_pos, int orient, - int TextInside, bool DrawPinNum, bool DrawPinName, - int Color, int DrawMode ); - void PlotPinTexts( wxPoint& pin_pos, int orient, - int TextInside, bool DrawPinNum, bool DrawPinNameint, int aWidth, bool aItalic ); + void DrawPinTexts( WinEDA_DrawPanel* panel, wxDC* DC, + wxPoint& pin_pos, int orient, + int TextInside, bool DrawPinNum, bool DrawPinName, + int Color, int DrawMode ); + void PlotPinTexts( wxPoint& pin_pos, + int orient, + int TextInside, + bool DrawPinNum, + bool DrawPinNameint, + int aWidth, + bool aItalic ); }; @@ -248,8 +253,8 @@ public: int m_Rayon; int t1, t2; /* position des 2 extremites de l'arc en 0.1 degres */ wxPoint m_ArcStart, m_ArcEnd; /* position des 2 extremites de l'arc en coord reelles*/ - wxPoint m_Pos; /* Position or centre (Arc and Circle) or start point (segments) */ - int m_Width; /* Tickness */ + wxPoint m_Pos; /* Position or centre (Arc and Circle) or start point (segments) */ + int m_Width; /* Tickness */ public: LibDrawArc(); @@ -266,13 +271,13 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - virtual bool Save( FILE* aFile ) const; + virtual bool Save( FILE* aFile ) const; - LibDrawArc* GenCopy(); + LibDrawArc* GenCopy(); void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ); + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ); }; /*****************************/ @@ -281,7 +286,7 @@ public: class LibDrawCircle : public LibEDA_BaseStruct { public: - int m_Rayon; + int m_Rayon; wxPoint m_Pos; /* Position or centre (Arc and Circle) or start point (segments) */ int m_Width; /* Tickness */ @@ -300,13 +305,13 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - virtual bool Save( FILE* aFile ) const; + virtual bool Save( FILE* aFile ) const; - LibDrawCircle* GenCopy(); + LibDrawCircle* GenCopy(); void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ); + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ); }; @@ -316,10 +321,9 @@ public: /* Fields like Ref , value... are not Text, */ /* they are a separate class */ /*********************************************/ -class LibDrawText : public LibEDA_BaseStruct - , public EDA_TextStruct +class LibDrawText : public LibEDA_BaseStruct, + public EDA_TextStruct { - public: LibDrawText(); ~LibDrawText() { } @@ -335,13 +339,13 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - virtual bool Save( FILE* aFile ) const; + virtual bool Save( FILE* aFile ) const; - LibDrawText* GenCopy(); + LibDrawText* GenCopy(); void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ); + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ); }; @@ -370,13 +374,13 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - virtual bool Save( FILE* aFile ) const; + virtual bool Save( FILE* aFile ) const; - LibDrawSquare* GenCopy(); + LibDrawSquare* GenCopy(); void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ); + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ); }; /**********************************/ @@ -410,7 +414,7 @@ public: LibDrawSegment* GenCopy(); void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ); + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ); }; /**********************************************************/ @@ -419,8 +423,8 @@ public: class LibDrawPolyline : public LibEDA_BaseStruct { public: - int m_Width; /* Tickness */ - std::vector m_PolyPoints; // list of points (>= 2) + int m_Width; /* Tickness */ + std::vector m_PolyPoints; // list of points (>= 2) public: LibDrawPolyline(); @@ -438,10 +442,10 @@ public: * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ - virtual bool Save( FILE* aFile ) const; + virtual bool Save( FILE* aFile ) const; - LibDrawPolyline* GenCopy(); - void AddPoint( const wxPoint& point ); + LibDrawPolyline* GenCopy(); + void AddPoint( const wxPoint& point ); /** Function GetCornerCount * @return the number of corners @@ -454,15 +458,15 @@ public: * @param aThreshold = max distance to a segment * @param aTransMat = the transform matrix */ - bool HitTest( wxPoint aPosRef, int aThreshold, int aTransMat[2][2] ); + bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] ); /** Function GetBoundaryBox * @return the boundary box for this, in library coordinates */ - EDA_Rect GetBoundaryBox( ); + EDA_Rect GetBoundaryBox(); void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, - int aDrawMode, void* aData, int aTransformMatrix[2][2] ); + int aDrawMode, void* aData, const int aTransformMatrix[2][2] ); }; #endif // CLASSES_BODY_ITEMS_H diff --git a/eeschema/eelibs_draw_components.cpp b/eeschema/eelibs_draw_components.cpp index 40c55be539..0672a171f0 100644 --- a/eeschema/eelibs_draw_components.cpp +++ b/eeschema/eelibs_draw_components.cpp @@ -34,7 +34,7 @@ static void DrawLibPartAux( WinEDA_DrawPanel * panel, wxDC * DC, SCH_COMPONENT * Component, EDA_LibComponentStruct * Entry, const wxPoint &Pos, - int TransMat[2][2], + const int TransMat[2][2], int Multi, int convert, int DrawMode, int Color = -1, bool DrawPinText = TRUE ); @@ -42,7 +42,7 @@ static void DrawLibPartAux( WinEDA_DrawPanel * panel, wxDC * DC, static EDA_LibComponentStruct* DummyCmp; /***************************************************************************/ -wxPoint TransformCoordinate( int aTransformMatrix[2][2], wxPoint& aPosition ) +wxPoint TransformCoordinate( const int aTransformMatrix[2][2], const wxPoint& aPosition ) /***************************************************************************/ /** Function TransformCoordinate @@ -102,17 +102,13 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC, */ { int color; - int TransMat[2][2]; wxString Prefix; LibDrawField* Field; wxPoint text_pos; - /* Orientation normale */ - TransMat[0][0] = 1; TransMat[1][1] = -1; - TransMat[1][0] = TransMat[0][1] = 0; DrawLibPartAux( panel, DC, NULL, LibEntry, aOffset, - TransMat, Multi, + DefaultTransformMatrix, Multi, convert, DrawMode, Color ); /* Trace des 2 champs ref et value (Attention aux coord: la matrice @@ -139,7 +135,7 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC, Prefix = LibEntry->m_Prefix.m_Text + wxT( "?" ); if( (LibEntry->m_Prefix.m_Flags & IS_MOVED) == 0 ) - LibEntry->m_Prefix.Draw( panel, DC, aOffset, color, DrawMode, &Prefix, TransMat ); + LibEntry->m_Prefix.Draw( panel, DC, aOffset, color, DrawMode, &Prefix, DefaultTransformMatrix ); if( LibEntry->m_Name.m_Attributs & TEXT_NO_VISIBLE ) { @@ -151,7 +147,7 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC, else color = Color; if( (LibEntry->m_Name.m_Flags & IS_MOVED) == 0 ) - LibEntry->m_Name.Draw( panel, DC, aOffset, color, DrawMode, NULL, TransMat ); + LibEntry->m_Name.Draw( panel, DC, aOffset, color, DrawMode, NULL, DefaultTransformMatrix ); for( Field = LibEntry->m_Fields; Field != NULL; Field = Field->Next() ) { @@ -167,7 +163,7 @@ void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC, color = g_InvisibleItemColor; } else color = Color; - Field->Draw( panel, DC, aOffset, color, DrawMode, NULL, TransMat ); + Field->Draw( panel, DC, aOffset, color, DrawMode, NULL, DefaultTransformMatrix ); } // Trace de l'ancre @@ -446,7 +442,7 @@ void DrawLibPartAux( WinEDA_DrawPanel* panel, wxDC* DC, SCH_COMPONENT* Component, EDA_LibComponentStruct* Entry, const wxPoint& Pos, - int TransMat[2][2], + const int TransMat[2][2], int Multi, int convert, int DrawMode, int Color, bool DrawPinText ) { @@ -534,7 +530,7 @@ void DrawLibPartAux( WinEDA_DrawPanel* panel, wxDC* DC, * transform (only mirror and rotate so it remains on the unit circle) to * * a new point which is used to detect new angle. * *****************************************************************************/ -bool MapAngles( int* Angle1, int* Angle2, int TransMat[2][2] ) +bool MapAngles( int* Angle1, int* Angle2, const int TransMat[2][2] ) { int Angle, Delta; double x, y, t; diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp index 981e913490..d1912c393f 100644 --- a/eeschema/eeredraw.cpp +++ b/eeschema/eeredraw.cpp @@ -16,20 +16,20 @@ char marq_bitmap[] = { - 12, 12, 0, 0, /* Dimensions x et y, offsets x et y du bitmap de marqueurs*/ + 12, 12, 0, 0, /* Dimensions x et y, offsets x et y du bitmap de marqueurs*/ YELLOW, /* Couleur */ - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, /* bitmap: >= 1 : color, 0 = notrace */ - 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, - 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, - 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, - 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, /* bitmap: >= 1 : color, 0 = notrace */ + 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, + 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, + 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, + 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, + 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; char marqERC_bitmap[] = @@ -51,15 +51,15 @@ static EDA_BaseStruct* HighLightStruct = NULL; /************************************************************/ void DrawDanglingSymbol( WinEDA_DrawPanel* panel, wxDC* DC, - const wxPoint& pos, int Color ) + const wxPoint& pos, int Color ) /************************************************************/ { if( !g_IsPrinting ) // Draw but do not print the Dangling Symbol */ { GRRect( &panel->m_ClipBox, DC, - pos.x - DANGLING_SYMBOL_SIZE, pos.y - DANGLING_SYMBOL_SIZE, - pos.x + DANGLING_SYMBOL_SIZE, pos.y + DANGLING_SYMBOL_SIZE, - 0, Color ); + pos.x - DANGLING_SYMBOL_SIZE, pos.y - DANGLING_SYMBOL_SIZE, + pos.x + DANGLING_SYMBOL_SIZE, pos.y + DANGLING_SYMBOL_SIZE, + 0, Color ); } } @@ -77,7 +77,7 @@ void WinEDA_SchematicFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) /**********************************************************************/ /* - * Redraws only the active window which is assumed to be whole visible. + * Redraws only the active window which is assumed to be whole visible. */ { wxString title; @@ -127,7 +127,7 @@ void WinEDA_SchematicFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) else { title = wxT( "[" ); - title << GetScreen()->m_FileName << wxT( "] " ) << _("Sheet") ; + title << GetScreen()->m_FileName << wxT( "] " ) << _( "Sheet" ); title << wxT( " " ) << m_CurrentSheet->PathHumanReadable(); SetTitle( title ); } @@ -135,8 +135,12 @@ void WinEDA_SchematicFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) /******************************************************************************************************/ -void WinEDA_DrawPanel::PrintPage( wxDC* DC, bool Print_Sheet_Ref, int PrintMask, bool aPrintMirrorMode ) +void WinEDA_DrawPanel::PrintPage( wxDC* DC, + bool Print_Sheet_Ref, + int PrintMask, + bool aPrintMirrorMode ) /******************************************************************************************************/ + /** PrintPage * used to print a page. * Print the page pointed by ActiveScreen, set by the calling print function @@ -171,7 +175,7 @@ void RedrawStructList( WinEDA_DrawPanel* panel, wxDC* DC, SCH_ITEM* item = ( (DrawPickedStruct*) Structs )->m_PickedStruct; // uncomment line below when there is a virtual EDA_BaseStruct::GetBoundingBox() - // if( panel->m_ClipBox.Intersects( item->GetBoundingBox() ) ) + // if( panel->m_ClipBox.Intersects( item->GetBoundingBox() ) ) { RedrawOneStruct( panel, DC, item, DrawMode, Color ); } @@ -181,8 +185,8 @@ void RedrawStructList( WinEDA_DrawPanel* panel, wxDC* DC, if( !(Structs->m_Flags & IS_MOVED) ) { // uncomment line below when there is a virtual EDA_BaseStruct::GetBoundingBox() - // if( panel->m_ClipBox.Intersects( Structs->GetBoundingBox() ) ) - RedrawOneStruct( panel, DC, Structs, DrawMode, Color ); + // if( panel->m_ClipBox.Intersects( Structs->GetBoundingBox() ) ) + RedrawOneStruct( panel, DC, Structs, DrawMode, Color ); } } @@ -228,10 +232,10 @@ void EDA_DrawLineStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& if( m_Layer == LAYER_NOTES ) GRDashedLine( &panel->m_ClipBox, DC, m_Start.x + offset.x, m_Start.y + offset.y, - m_End.x + offset.x, m_End.y + offset.y, width, color ); + m_End.x + offset.x, m_End.y + offset.y, width, color ); else GRLine( &panel->m_ClipBox, DC, m_Start.x + offset.x, m_Start.y + offset.y, - m_End.x + offset.x, m_End.y + offset.y, width, color ); + m_End.x + offset.x, m_End.y + offset.y, width, color ); if( m_StartIsDangling ) DrawDanglingSymbol( panel, DC, m_Start + offset, color ); @@ -271,8 +275,8 @@ void DrawNoConnectStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint /* DRaw the "No Connect" symbol.. */ { const int DELTA = (DRAWNOCONNECT_SIZE / 2); - int pX, pY, color; - int width = g_DrawMinimunLineWidth; + int pX, pY, color; + int width = g_DrawMinimunLineWidth; pX = m_Pos.x + offset.x; pY = m_Pos.y + offset.y; @@ -290,7 +294,8 @@ void DrawNoConnectStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint EDA_Rect DrawNoConnectStruct::GetBoundingBox() { const int DELTA = (DRAWNOCONNECT_SIZE / 2); - EDA_Rect box( wxPoint(m_Pos.x-DELTA,m_Pos.y-DELTA), wxSize(2*DELTA,2*DELTA) ); + EDA_Rect box( wxPoint( m_Pos.x - DELTA, m_Pos.y - DELTA ), wxSize( 2 * DELTA, 2 * DELTA ) ); + box.Normalize(); return box; } @@ -318,26 +323,28 @@ void DrawBusEntryStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& width *= 3; GRLine( &panel->m_ClipBox, DC, m_Pos.x + offset.x, m_Pos.y + offset.y, - m_End().x + offset.x, m_End().y + offset.y, width, color ); + m_End().x + offset.x, m_End().y + offset.y, width, color ); } EDA_Rect DrawBusEntryStruct::GetBoundingBox() { - int dx = m_Pos.x - m_End().x; - int dy = m_Pos.y - m_End().y; - EDA_Rect box( wxPoint(m_Pos.x,m_Pos.y), wxSize(dx,dy) ); + int dx = m_Pos.x - m_End().x; + int dy = m_Pos.y - m_End().y; + EDA_Rect box( wxPoint( m_Pos.x, m_Pos.y ), wxSize( dx, dy ) ); + box.Normalize(); return box; } + /***************************************************************************** * Routine to redraw polyline struct. * *****************************************************************************/ void DrawPolylineStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int DrawMode, int Color ) { - int i, color; + int color; int zoom = panel->GetZoom(); int width = MAX( m_Width, g_DrawMinimunLineWidth ); @@ -353,22 +360,22 @@ void DrawPolylineStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& width *= 3; } - GRMoveTo( m_Points[0], m_Points[1] ); + GRMoveTo( m_PolyPoints[0].x, m_PolyPoints[0].y ); if( m_Layer == LAYER_NOTES ) { - for( i = 1; i < m_NumOfPoints; i++ ) - GRDashedLineTo( &panel->m_ClipBox, DC, m_Points[i * 2] + offset.x, - m_Points[i * 2 + 1] + offset.y, width, color ); + for( unsigned i = 1; i < GetCornerCount(); i++ ) + GRDashedLineTo( &panel->m_ClipBox, DC, m_PolyPoints[i].x + offset.x, + m_PolyPoints[i].y + offset.y, width, color ); } else { - for( i = 1; i < m_NumOfPoints; i++ ) + for( unsigned i = 1; i < GetCornerCount(); i++ ) GRLineTo( &panel->m_ClipBox, - DC, - m_Points[i * 2] + offset.x, - m_Points[i * 2 + 1] + offset.y, - width, - color ); + DC, + m_PolyPoints[i].x + offset.x, + m_PolyPoints[i].y + offset.y, + width, + color ); } } @@ -388,7 +395,7 @@ void DrawJunctionStruct::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& GRSetDrawMode( DC, DrawMode ); GRFilledCircle( &panel->m_ClipBox, DC, m_Pos.x + offset.x, m_Pos.y + offset.y, - DRAWJUNCTION_SIZE, 0, color, color ); + DRAWJUNCTION_SIZE, 0, color, color ); } @@ -398,12 +405,12 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, /**********************************************************/ /* Routine de redessin en mode fantome (Dessin simplifie en g_XorMode et - * g_GhostColor - * de structures. - * Utilisee dans les deplacements de blocs + * g_GhostColor + * de structures. + * Utilisee dans les deplacements de blocs */ { - int Width, ii; + int Width; int DrawMode = g_XorMode; int width = g_DrawMinimunLineWidth; @@ -414,12 +421,11 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, { case DRAW_POLYLINE_STRUCT_TYPE: { - DrawPolylineStruct* Struct; - Struct = (DrawPolylineStruct*) DrawStruct; - GRMoveTo( Struct->m_Points[0] + dx, Struct->m_Points[1] + dy ); - for( ii = 1; ii < Struct->m_NumOfPoints; ii++ ) - GRLineTo( &panel->m_ClipBox, DC, Struct->m_Points[ii * 2] + dx, - Struct->m_Points[ii * 2 + 1] + dy, width, g_GhostColor ); + DrawPolylineStruct* Struct = (DrawPolylineStruct*) DrawStruct; + GRMoveTo( Struct->m_PolyPoints[0].x + dx, Struct->m_PolyPoints[0].y + dy ); + for( unsigned ii = 1; ii < Struct->GetCornerCount(); ii++ ) + GRLineTo( &panel->m_ClipBox, DC, Struct->m_PolyPoints[ii].x + dx, + Struct->m_PolyPoints[ii].y + dy, width, g_GhostColor ); break; } @@ -439,11 +445,11 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, if( (Struct->m_Flags & ENDPOINT) == 0 ) { GRLineTo( &panel->m_ClipBox, - DC, - Struct->m_End.x + dx, - Struct->m_End.y + dy, - width, - g_GhostColor ); + DC, + Struct->m_End.x + dx, + Struct->m_End.y + dy, + width, + g_GhostColor ); } else { @@ -458,11 +464,11 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, int xx = Struct->m_Pos.x + dx, yy = Struct->m_Pos.y + dy; GRMoveTo( xx, yy ); GRLineTo( &panel->m_ClipBox, - DC, - Struct->m_Size.x + xx, - Struct->m_Size.y + yy, - width, - g_GhostColor ); + DC, + Struct->m_Size.x + xx, + Struct->m_Size.y + yy, + width, + g_GhostColor ); break; } @@ -472,13 +478,13 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, Struct = (DrawJunctionStruct*) DrawStruct; Width = DRAWJUNCTION_SIZE; GRFilledRect( &panel->m_ClipBox, - DC, - Struct->m_Pos.x - Width + dx, - Struct->m_Pos.y - Width + dy, - Struct->m_Pos.x + Width + dx, - Struct->m_Pos.y + Width + dy, - g_GhostColor, - g_GhostColor ); + DC, + Struct->m_Pos.x - Width + dx, + Struct->m_Pos.y - Width + dy, + Struct->m_Pos.x + Width + dx, + Struct->m_Pos.y + Width + dy, + g_GhostColor, + g_GhostColor ); break; } @@ -511,15 +517,15 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, case TYPE_SCH_COMPONENT: { EDA_LibComponentStruct* LibEntry; - SCH_COMPONENT* Struct; + SCH_COMPONENT* Struct; Struct = (SCH_COMPONENT*) DrawStruct; LibEntry = FindLibPart( Struct->m_ChipName.GetData(), wxEmptyString, FIND_ROOT ); if( LibEntry == NULL ) break; DrawingLibInGhost( panel, DC, LibEntry, Struct, Struct->m_Pos.x + dx, - Struct->m_Pos.y + dy, - Struct->m_Multi, Struct->m_Convert, - g_GhostColor, FALSE ); + Struct->m_Pos.y + dy, + Struct->m_Multi, Struct->m_Convert, + g_GhostColor, FALSE ); break; } @@ -527,8 +533,8 @@ void DrawStructsInGhost( WinEDA_DrawPanel* panel, wxDC* DC, { DrawSheetStruct* Struct = (DrawSheetStruct*) DrawStruct; GRRect( &panel->m_ClipBox, DC, Struct->m_Pos.x + dx, Struct->m_Pos.y + dy, - Struct->m_Pos.x + Struct->m_Size.x + dx, - Struct->m_Pos.y + Struct->m_Size.y + dy, width, g_GhostColor ); + Struct->m_Pos.x + Struct->m_Size.x + dx, + Struct->m_Pos.y + Struct->m_Size.y + dy, width, g_GhostColor ); break; } @@ -548,13 +554,13 @@ void Draw_Marqueur( WinEDA_DrawPanel* panel, wxDC* DC, /************************************************************/ /* - * Place un repere sur l'ecran au point de coordonnees PCB pos_X, pos_Y - * Le marqueur est defini par un tableau de 2 + (lig*col) elements: - * 1er element: dim nbre ligne - * 2er element: dim nbre col - * suite: lig * col elements a 0 ou 1 : si 1 mise a color du pixel + * Place un repere sur l'ecran au point de coordonnees PCB pos_X, pos_Y + * Le marqueur est defini par un tableau de 2 + (lig*col) elements: + * 1er element: dim nbre ligne + * 2er element: dim nbre col + * suite: lig * col elements a 0 ou 1 : si 1 mise a color du pixel * - * copie la description du marqueur en current_marqueur (global) + * copie la description du marqueur en current_marqueur (global) */ { int px, py, color; diff --git a/eeschema/load_one_schematic_file.cpp b/eeschema/load_one_schematic_file.cpp index 138c6bbf31..4f88e297d8 100644 --- a/eeschema/load_one_schematic_file.cpp +++ b/eeschema/load_one_schematic_file.cpp @@ -249,16 +249,12 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F layer = LAYER_BUS; PolylineStruct = new DrawPolylineStruct( layer ); - - PolylineStruct->m_NumOfPoints = ii; - PolylineStruct->m_Points = (int*) MyZMalloc( sizeof(int) * 2 * - PolylineStruct->m_NumOfPoints ); - for( ii = 0; ii < PolylineStruct->m_NumOfPoints; ii++ ) + for( unsigned jj = 0; jj < (unsigned)ii; jj++ ) { LineCount++; + wxPoint point; if( fgets( Line, 256 - 1, f ) == NULL - || sscanf( Line, "%d %d", &PolylineStruct->m_Points[ii * 2], - &PolylineStruct->m_Points[ii * 2 + 1] ) != 2 ) + || sscanf( Line, "%d %d", &point.x, &point.y ) != 2 ) { MsgDiag.Printf( wxT( "EESchema file polyline struct error at line %d, aborted" ), @@ -268,6 +264,8 @@ bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& F SAFE_DELETE( PolylineStruct ); break; } + + PolylineStruct->AddPoint( point ); } if( !Failed ) diff --git a/eeschema/locate.cpp b/eeschema/locate.cpp index da675e70a2..9379712e29 100644 --- a/eeschema/locate.cpp +++ b/eeschema/locate.cpp @@ -24,8 +24,7 @@ static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1, int StartX2, int StartY2, int EndX2, int EndY2 ); static bool IsPointInBox( wxPoint aPosRef, int BoxX1, int BoxY1, int BoxX2, int BoxY2 ); -static bool IsPointOnSegment( wxPoint aPosRef, - int SegmX1, int SegmY1, int SegmX2, int SegmY2, int seuil = 0 ); +static bool IsPointOnSegment( wxPoint aPosRef, wxPoint aSegmStart, wxPoint aSegmEnd, int aDist = 0 ); static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawList, DrawPickedStruct* DontSnapList, int zoom_value ); @@ -198,8 +197,7 @@ SCH_ITEM* PickStruct( EDA_Rect& block, BASE_SCREEN* screen, int SearchMask ) bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawList, DrawPickedStruct* DontSnapList, int zoom_value ) { - int i, * Points; - int x1, y1, x2, y2, NumOfPoints2; + int x1, y1, x2, y2; DrawPickedStruct* DontSnap; int dx, dy; @@ -223,13 +221,9 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, if( !( SearchMask & (DRAWITEM | WIREITEM | BUSITEM) ) ) break; - Points = STRUCT->m_Points; - NumOfPoints2 = STRUCT->m_NumOfPoints * 2; - for( i = 0; i < NumOfPoints2 - 2; i += 2 ) + for( unsigned i = 0; i < STRUCT->GetCornerCount() - 1; i ++ ) { - x1 = Points[i]; y1 = Points[i + 1]; - x2 = Points[i + 2]; y2 = Points[i + 3]; - if( IsPointOnSegment( aPosRef, x1, y1, x2, y2 ) ) + if( IsPointOnSegment( aPosRef, STRUCT->m_PolyPoints[i], STRUCT->m_PolyPoints[i+1] ) ) { LastSnappedStruct = DrawList; return TRUE; @@ -244,8 +238,7 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, if( !( SearchMask & (DRAWITEM | WIREITEM | BUSITEM) ) ) break; - if( IsPointOnSegment( aPosRef, STRUCT->m_Start.x, STRUCT->m_Start.y, - STRUCT->m_End.x, STRUCT->m_End.y ) ) + if( IsPointOnSegment( aPosRef, STRUCT->m_Start, STRUCT->m_End ) ) { if( ( (SearchMask & DRAWITEM) && (STRUCT->GetLayer() == LAYER_NOTES) ) || ( (SearchMask & WIREITEM) && (STRUCT->GetLayer() == LAYER_WIRE) ) @@ -277,8 +270,7 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, if( !( SearchMask & (RACCORDITEM) ) ) break; - if( IsPointOnSegment( aPosRef, STRUCT->m_Pos.x, STRUCT->m_Pos.y, - STRUCT->m_End().x, STRUCT->m_End().y ) ) + if( IsPointOnSegment( aPosRef, STRUCT->m_Pos, STRUCT->m_End() ) ) { LastSnappedStruct = DrawList; return TRUE; @@ -419,7 +411,7 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, if( SearchMask & FIELDCMPITEM ) { SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) DrawList; - for( i = REFERENCE; i < DrawLibItem->GetFieldCount(); i++ ) + for( int i = REFERENCE; i < DrawLibItem->GetFieldCount(); i++ ) { SCH_CMP_FIELD* field = DrawLibItem->GetField(i); @@ -491,10 +483,9 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, * defined by x1/y1 and x2/y2 (x1 < x2, y1 < y2), and return TRUE if so. This * * routine is used to pick all points in a given box. * *****************************************************************************/ -bool DrawStructInBox( int x1, int y1, int x2, int y2, - SCH_ITEM* DrawStruct ) +bool DrawStructInBox( int x1, int y1, int x2, int y2, SCH_ITEM* DrawStruct ) { - int i, * Points, xt1, yt1, xt2, yt2, NumOfPoints2; + int xt1, yt1, xt2, yt2; int dx, dy; wxString msg; @@ -503,12 +494,10 @@ bool DrawStructInBox( int x1, int y1, int x2, int y2, case DRAW_POLYLINE_STRUCT_TYPE: #undef STRUCT #define STRUCT ( (DrawPolylineStruct*) DrawStruct ) - Points = STRUCT->m_Points; - NumOfPoints2 = STRUCT->m_NumOfPoints * 2; - for( i = 0; i < NumOfPoints2; i += 2 ) + for( unsigned i = 0; i < STRUCT->GetCornerCount(); i ++ ) { - if( Points[i] >= x1 && Points[i] <= x2 - && Points[i + 1] >= y1 && Points[i + 1] <=y2 ) + if( STRUCT->m_PolyPoints[i].x >= x1 && STRUCT->m_PolyPoints[i].x <= x2 + && STRUCT->m_PolyPoints[i].y >= y1 && STRUCT->m_PolyPoints[i].y <=y2 ) return TRUE; } @@ -759,19 +748,18 @@ static bool IsPointInBox( wxPoint aPosRef, /********************************************************************************/ -static bool IsPointOnSegment( wxPoint aPosRef, - int SegmX1, int SegmY1, int SegmX2, int SegmY2, int seuil ) +static bool IsPointOnSegment( wxPoint aPosRef, wxPoint aSegmStart, wxPoint aSegmEnd, int aDist ) /********************************************************************************/ /* Routine detectant que le point pX,pY est sur le Segment X1,Y1 a X2,Y2 * Retourne TRUE ou FALSE. */ { - /* Recalcul des coord avec SegmX1, SegmX2 comme origine */ - aPosRef.x -= SegmX1; aPosRef.y -= SegmY1; - SegmX2 -= SegmX1; SegmY2 -= SegmY1; + /* Move coordinates origin to aSegmStart */ + aPosRef -= aSegmStart; + aSegmEnd -= aSegmStart; - if( distance( SegmX2, SegmY2, aPosRef.x, aPosRef.y, seuil ) ) + if( distance( aSegmEnd.x, aSegmEnd.y, aPosRef.x, aPosRef.y, aDist ) ) return TRUE; else @@ -788,10 +776,10 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen, int masque ) /*********************************************************************************/ -/* Routine de localisation d'un element de dessin de symbole( sauf pins ) - * Unit = Unite d'appartenance (si Unit = 0, recherche sur toutes unites) - * Convert = Conversion d'appartenance (si Convert = 0, recherche sur - * toutes variantes) +/* Locates a body item( not pins ) + * Unit = part number (if Unit = 0, all parts are considered) + * Convert = convert value for shape (si Convert = 0, all shapes are considered) + * remember the Y axis is from bottom to top in library entries for graphic items. */ { int dx, dy; @@ -847,25 +835,32 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen, break; case COMPONENT_RECT_DRAW_TYPE: - { // Locate a rect if the mouse cursor is on a segment + { // Locate a rect if the mouse cursor is on a side of this rectangle LibDrawSquare* Square = (LibDrawSquare*) DrawItem; if( (masque & LOCATE_COMPONENT_RECT_DRAW_TYPE) == 0 ) break; - if( IsPointOnSegment( aRefPoint, // locate lower segment - Square->m_Pos.x, -Square->m_Pos.y, - Square->m_End.x, -Square->m_Pos.y, seuil ) ) + wxPoint start, end; + start.x = Square->m_Pos.x; + start.y = -Square->m_Pos.y; + end.x = Square->m_End.x; + end.y = -Square->m_Pos.y; + // locate lower segment + if( IsPointOnSegment( aRefPoint, start, end , seuil ) ) return DrawItem; - if( IsPointOnSegment( aRefPoint, // locate right segment - Square->m_End.x, -Square->m_Pos.y, - Square->m_End.x, -Square->m_End.y, seuil ) ) + // locate right segment + start.x = Square->m_End.x; + end.y = -Square->m_End.y; + if( IsPointOnSegment( aRefPoint, start,end , seuil ) ) return DrawItem; - if( IsPointOnSegment( aRefPoint, // locate upper segment - Square->m_End.x, -Square->m_End.y, - Square->m_Pos.x, -Square->m_End.y, seuil ) ) + // locate upper segment + start.y = -Square->m_End.y; + end.x = Square->m_Pos.x; + if( IsPointOnSegment( aRefPoint, start, end, seuil ) ) return DrawItem; - if( IsPointOnSegment( aRefPoint, // locate left segment - Square->m_Pos.x, -Square->m_End.y, - Square->m_Pos.x, -Square->m_Pos.y, seuil ) ) + // locate left segment + start.x = Square->m_Pos.x; + end.x = -Square->m_Pos.y; + if( IsPointOnSegment( aRefPoint,start, end, seuil ) ) return DrawItem; } break; @@ -875,15 +870,9 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen, LibDrawPolyline* polyline = (LibDrawPolyline*) DrawItem; if( (masque & LOCATE_COMPONENT_POLYLINE_DRAW_TYPE) == 0 ) break; - - for( unsigned ii = 0; ii < polyline->m_PolyPoints.size()-1; ii++ ) - { - 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 ) ) + if ( polyline->HitTest(aRefPoint, seuil, DefaultTransformMatrix) ) return DrawItem; - } - } + } break; case COMPONENT_LINE_DRAW_TYPE: @@ -891,9 +880,9 @@ LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen, LibDrawSegment* Segment = (LibDrawSegment*) DrawItem; if( (masque & LOCATE_COMPONENT_LINE_DRAW_TYPE) == 0 ) break; - if( IsPointOnSegment( aRefPoint, - Segment->m_Pos.x, -Segment->m_Pos.y, - Segment->m_End.x, -Segment->m_End.y, seuil ) ) + wxPoint ref = aRefPoint; + NEGATE ( ref.y); + if( IsPointOnSegment( ref, Segment->m_Pos, Segment->m_End, seuil ) ) return DrawItem; } break; diff --git a/eeschema/program.h b/eeschema/program.h index 75697a195b..15385aa71a 100644 --- a/eeschema/program.h +++ b/eeschema/program.h @@ -18,271 +18,24 @@ #include "class_screen.h" #include "class_drawsheet.h" #include "class_text-label.h" - -#define DRAWJUNCTION_SIZE 16 /* Rayon du symbole connexion */ -#define DRAWMARKER_SIZE 16 /* Rayon du symbole marqueur */ -#define DRAWNOCONNECT_SIZE 48 /* Rayon du symbole No Connexion */ +#include "class_schematic_items.h" #define HIGHLIGHT_COLOR WHITE - #define TEXT_NO_VISIBLE 1 -/* flags pour BUS ENTRY (bus to bus ou wire to bus */ -#define WIRE_TO_BUS 0 -#define BUS_TO_BUS 1 - - -enum TypeMarker { /* Type des Marqueurs */ - MARQ_UNSPEC, - MARQ_ERC, - MARQ_PCB, - MARQ_SIMUL, - MARQ_NMAX /* Derniere valeur: fin de tableau */ -}; - - -/* Messages correspondants aux types des marqueurs */ +/* Rotation, mirror of graphic items in components bodies are handled by a transform matrix + * The default matix is useful to draw lib entries with a defualt matix ( no rotation, no mirrot + * but Y axis is bottom to top, and Y draw axis is to to bottom + * so we must have a default matix that reverses the Y coordinate and keeps the X coordiante + * DefaultTransformMatrix[0][0] = 1; DefaultTransformMatrix[1][1] = -1; + * DefaultTransformMatrix[1][0] = DefaultTransformMatrix[0][1] = 0; + */ +eda_global int DefaultTransformMatrix[2][2] #ifdef MAIN -const wxChar* NameMarqueurType[] = -{ - wxT( "" ), - wxT( "ERC" ), - wxT( "PCB" ), - wxT( "SIMUL" ), - wxT( "?????" ) -}; -#else -extern const wxChar* NameMarqueurType[]; + = { {1, 0}, {0, -1} } #endif - - -/* Forward declarations */ -class DrawSheetStruct; - - -/** - * Class EDA_DrawLineStruct - * is a segment decription base class to describe items which have 2 end - * points (track, wire, draw line ...) - */ -class EDA_DrawLineStruct : public SCH_ITEM -{ -public: - int m_Width; // 0 = line, > 0 = tracks, bus ... - wxPoint m_Start; // Line start point - wxPoint m_End; // Line end point - - bool m_StartIsDangling; - bool m_EndIsDangling; // TRUE si Start ou End not connected (wires, tracks...) - -public: - EDA_DrawLineStruct( const wxPoint& pos, int layer ); - ~EDA_DrawLineStruct() { } - - EDA_DrawLineStruct* Next() const { return (EDA_DrawLineStruct*) Pnext; } - EDA_DrawLineStruct* Back() const { return (EDA_DrawLineStruct*) Pback; } - - virtual wxString GetClass() const - { - return wxT( "EDA_DrawLine" ); - } - - - bool IsOneEndPointAt( const wxPoint& pos ); - EDA_DrawLineStruct* GenCopy(); - - bool IsNull() - { - return m_Start == m_End; - } - - EDA_Rect GetBoundingBox(); - - virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int draw_mode, - int Color = -1 ); - - /** - * Function Save - * writes the data structures for this object out to a FILE in "*.brd" format. - * @param aFile The FILE to write to. - * @return bool - true if success writing else false. - */ - bool Save( FILE* aFile ) const; - -#if defined(DEBUG) - void Show( int nestLevel, std::ostream& os ); -#endif -}; - - -class DrawMarkerStruct : public SCH_ITEM /* marqueurs */ -{ -public: - wxPoint m_Pos; /* XY coordinates of marker. */ - TypeMarker m_Type; - int m_MarkFlags; // complements d'information - wxString m_Comment; /* Texte (commentaireassocie eventuel */ - -public: - DrawMarkerStruct( const wxPoint& pos, const wxString& text ); - ~DrawMarkerStruct(); - virtual wxString GetClass() const - { - return wxT( "DrawMarker" ); - } - - - DrawMarkerStruct* GenCopy(); - wxString GetComment(); - virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, - int draw_mode, int Color = -1 ); - /** - * Function Save - * writes the data structures for this object out to a FILE in "*.brd" format. - * @param aFile The FILE to write to. - * @return bool - true if success writing else false. - */ - bool Save( FILE* aFile ) const; - -#if defined(DEBUG) - void Show( int nestLevel, std::ostream& os ); -#endif -}; - - -class DrawNoConnectStruct : public SCH_ITEM /* Symboles de non connexion */ -{ -public: - wxPoint m_Pos; /* XY coordinates of NoConnect. */ - -public: - DrawNoConnectStruct( const wxPoint& pos ); - ~DrawNoConnectStruct() { } - virtual wxString GetClass() const - { - return wxT( "DrawNoConnect" ); - } - - - DrawNoConnectStruct* GenCopy(); - virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, - int draw_mode, int Color = -1 ); - - /** - * Function Save - * writes the data structures for this object out to a FILE in "*.brd" format. - * @param aFile The FILE to write to. - * @return bool - true if success writing else false. - */ - bool Save( FILE* aFile ) const; - - EDA_Rect GetBoundingBox(); -}; - - -/** - * Class DrawBusEntryStruct - * Struct de descr 1 raccord a 45 degres de BUS ou WIRE - */ -class DrawBusEntryStruct : public SCH_ITEM -{ -public: - int m_Width; - wxPoint m_Pos; - wxSize m_Size; - -public: - DrawBusEntryStruct( const wxPoint& pos, int shape, int id ); - ~DrawBusEntryStruct() { } - - virtual wxString GetClass() const - { - return wxT( "DrawBusEntry" ); - } - - - DrawBusEntryStruct* GenCopy(); - wxPoint m_End() const ; // retourne la coord de fin du raccord - virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, - int draw_mode, int Color = -1 ); - - /** - * Function Save - * writes the data structures for this object out to a FILE in "*.brd" format. - * @param aFile The FILE to write to. - * @return bool - true if success writing else false. - */ - bool Save( FILE* aFile ) const; - - EDA_Rect GetBoundingBox(); -}; - -class DrawPolylineStruct : public SCH_ITEM /* Polyligne (serie de segments) */ -{ -public: - int m_Width; - int m_NumOfPoints; /* Number of XY pairs in Points array. */ - int* m_Points; /* XY pairs that forms the polyline. */ - -public: - DrawPolylineStruct( int layer ); - ~DrawPolylineStruct(); - - virtual wxString GetClass() const - { - return wxT( "DrawPolyline" ); - } - - - DrawPolylineStruct* GenCopy(); - virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, - int draw_mode, int Color = -1 ); - - /** - * Function Save - * writes the data structures for this object out to a FILE in "*.brd" format. - * @param aFile The FILE to write to. - * @return bool - true if success writing else false. - */ - bool Save( FILE* aFile ) const; - -}; - -class DrawJunctionStruct : public SCH_ITEM -{ -public: - wxPoint m_Pos; /* XY coordinates of connection. */ - -public: - DrawJunctionStruct( const wxPoint& pos ); - ~DrawJunctionStruct() { } - - virtual wxString GetClass() const - { - return wxT( "DrawJunction" ); - } - - EDA_Rect GetBoundingBox(); - - DrawJunctionStruct* GenCopy(); - virtual void Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, - int draw_mode, int Color = -1 ); - - /** - * Function Save - * writes the data structures for this object out to a FILE in "*.brd" format. - * @param aFile The FILE to write to. - * @return bool - true if success writing else false. - */ - bool Save( FILE* aFile ) const; - -#if defined(DEBUG) - void Show( int nestLevel, std::ostream& os ); -#endif - -}; - +; #define MAX_LAYERS 44 diff --git a/eeschema/protos.h b/eeschema/protos.h index fa6521f9d5..bcb4c06751 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -57,7 +57,7 @@ void DrawLibraryDrawStruct(WinEDA_DrawPanel * aPanel, wxDC * aDC, LibEDA_BaseStruct *aDrawItem, int aDrawMode, int aColor = -1); -bool MapAngles(int *Angle1, int *Angle2, int TransMat[2][2]); +bool MapAngles(int *Angle1, int *Angle2, const int TransMat[2][2]); EDA_LibComponentStruct * Read_Component_Definition(WinEDA_DrawFrame * frame, char * Line, FILE *f, int *LineNum); @@ -69,7 +69,7 @@ EDA_LibComponentStruct * Read_Component_Definition(WinEDA_DrawFrame * frame, cha * @param aPosition = the position to transform * @return the new coordinate */ -wxPoint TransformCoordinate( int aTransformMatrix[2][2], wxPoint & aPosition ); +wxPoint TransformCoordinate( const int aTransformMatrix[2][2], const wxPoint & aPosition ); LibraryStruct *FindLibrary(const wxString & Name); int LoadDocLib(WinEDA_DrawFrame * frame, const wxString & FullDocLibName, const wxString & Libname);