Commit 85c5aa22 authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio

Constification of HitTest and GetParent

In particular HitTest for zones *do not* select the nearest vertex/edge as a side effect
parent f16f248b
...@@ -80,7 +80,7 @@ public: ...@@ -80,7 +80,7 @@ public:
EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 ); EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 );
~EDA_3D_CANVAS(); ~EDA_3D_CANVAS();
EDA_3D_FRAME* Parent() { return (EDA_3D_FRAME*)GetParent(); } EDA_3D_FRAME* Parent() const { return static_cast<EDA_3D_FRAME*>( GetParent() ); }
BOARD* GetBoard() { return Parent()->GetBoard(); } BOARD* GetBoard() { return Parent()->GetBoard(); }
......
...@@ -81,7 +81,7 @@ public: ...@@ -81,7 +81,7 @@ public:
m_auimgr.UnInit(); m_auimgr.UnInit();
}; };
PCB_BASE_FRAME* Parent() { return (PCB_BASE_FRAME*)GetParent(); } PCB_BASE_FRAME* Parent() const { return (PCB_BASE_FRAME*)GetParent(); }
BOARD* GetBoard(); BOARD* GetBoard();
......
...@@ -165,7 +165,7 @@ EDA_DRAW_PANEL::~EDA_DRAW_PANEL() ...@@ -165,7 +165,7 @@ EDA_DRAW_PANEL::~EDA_DRAW_PANEL()
} }
EDA_DRAW_FRAME* EDA_DRAW_PANEL::GetParent() EDA_DRAW_FRAME* EDA_DRAW_PANEL::GetParent() const
{ {
wxWindow* mom = wxScrolledWindow::GetParent(); wxWindow* mom = wxScrolledWindow::GetParent();
return (EDA_DRAW_FRAME*) mom; return (EDA_DRAW_FRAME*) mom;
......
...@@ -192,7 +192,7 @@ void WS_DRAW_ITEM_TEXT::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC ) ...@@ -192,7 +192,7 @@ void WS_DRAW_ITEM_TEXT::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC )
} }
// return true if the point aPosition is on the text // return true if the point aPosition is on the text
bool WS_DRAW_ITEM_TEXT::HitTest( const wxPoint& aPosition) bool WS_DRAW_ITEM_TEXT::HitTest( const wxPoint& aPosition) const
{ {
return EDA_TEXT::TextHitTest( aPosition, 0 ); return EDA_TEXT::TextHitTest( aPosition, 0 );
} }
...@@ -221,7 +221,7 @@ void WS_DRAW_ITEM_POLYGON::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC ) ...@@ -221,7 +221,7 @@ void WS_DRAW_ITEM_POLYGON::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC )
// return true if the point aPosition is inside one of polygons // return true if the point aPosition is inside one of polygons
#include <polygon_test_point_inside.h> #include <polygon_test_point_inside.h>
bool WS_DRAW_ITEM_POLYGON::HitTest( const wxPoint& aPosition) bool WS_DRAW_ITEM_POLYGON::HitTest( const wxPoint& aPosition) const
{ {
return TestPointInsidePolygon( &m_Corners[0], return TestPointInsidePolygon( &m_Corners[0],
m_Corners.size(), aPosition ); m_Corners.size(), aPosition );
...@@ -249,7 +249,7 @@ void WS_DRAW_ITEM_RECT::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC ) ...@@ -249,7 +249,7 @@ void WS_DRAW_ITEM_RECT::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC )
} }
// return true if the point aPosition is on the rect outline // return true if the point aPosition is on the rect outline
bool WS_DRAW_ITEM_RECT::HitTest( const wxPoint& aPosition) bool WS_DRAW_ITEM_RECT::HitTest( const wxPoint& aPosition) const
{ {
int dist = GetPenWidth()/2; int dist = GetPenWidth()/2;
wxPoint start = GetStart(); wxPoint start = GetStart();
...@@ -316,7 +316,7 @@ void WS_DRAW_ITEM_LINE::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC ) ...@@ -316,7 +316,7 @@ void WS_DRAW_ITEM_LINE::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC )
} }
// return true if the point aPosition is on the text // return true if the point aPosition is on the text
bool WS_DRAW_ITEM_LINE::HitTest( const wxPoint& aPosition) bool WS_DRAW_ITEM_LINE::HitTest( const wxPoint& aPosition) const
{ {
return TestSegmentHit( aPosition, GetStart(), GetEnd(), GetPenWidth()/2 ); return TestSegmentHit( aPosition, GetStart(), GetEnd(), GetPenWidth()/2 );
} }
...@@ -394,9 +394,9 @@ void WS_DRAW_ITEM_BITMAP::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC ) ...@@ -394,9 +394,9 @@ void WS_DRAW_ITEM_BITMAP::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC )
* Virtual function * Virtual function
* return true if the point aPosition is on bitmap * return true if the point aPosition is on bitmap
*/ */
bool WS_DRAW_ITEM_BITMAP::HitTest( const wxPoint& aPosition) bool WS_DRAW_ITEM_BITMAP::HitTest( const wxPoint& aPosition) const
{ {
WORKSHEET_DATAITEM_BITMAP* parent = (WORKSHEET_DATAITEM_BITMAP*)GetParent(); const WORKSHEET_DATAITEM_BITMAP* parent = static_cast<const WORKSHEET_DATAITEM_BITMAP*>( GetParent() );
if( parent->m_ImageBitmap == NULL ) if( parent->m_ImageBitmap == NULL )
return false; return false;
......
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
int GetSelection(); int GetSelection();
void OnSize( wxSizeEvent& event ); void OnSize( wxSizeEvent& event );
virtual CVPCB_MAINFRAME* GetParent(); virtual CVPCB_MAINFRAME* GetParent() const;
}; };
......
...@@ -79,7 +79,7 @@ int ITEMS_LISTBOX_BASE::GetSelection() ...@@ -79,7 +79,7 @@ int ITEMS_LISTBOX_BASE::GetSelection()
} }
CVPCB_MAINFRAME* ITEMS_LISTBOX_BASE::GetParent() CVPCB_MAINFRAME* ITEMS_LISTBOX_BASE::GetParent() const
{ {
return (CVPCB_MAINFRAME*) wxListView::GetParent(); return (CVPCB_MAINFRAME*) wxListView::GetParent();
} }
...@@ -654,14 +654,14 @@ public: ...@@ -654,14 +654,14 @@ public:
*/ */
void SetPartCount( int count ); void SetPartCount( int count );
int GetPartCount() { return m_unitCount; } int GetPartCount() const { return m_unitCount; }
/** /**
* Function IsMulti * Function IsMulti
* @return true if the component has multiple parts per package. * @return true if the component has multiple parts per package.
* When happens, the reference has a sub reference ti identify part * When happens, the reference has a sub reference ti identify part
*/ */
bool IsMulti() { return m_unitCount > 1; } bool IsMulti() const { return m_unitCount > 1; }
/** /**
* Function SubReference * Function SubReference
......
...@@ -171,7 +171,7 @@ bool LIB_ARC::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) ...@@ -171,7 +171,7 @@ bool LIB_ARC::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
} }
bool LIB_ARC::HitTest( const wxPoint& aRefPoint ) bool LIB_ARC::HitTest( const wxPoint& aRefPoint ) const
{ {
int mindist = GetPenSize() / 2; int mindist = GetPenSize() / 2;
...@@ -183,7 +183,7 @@ bool LIB_ARC::HitTest( const wxPoint& aRefPoint ) ...@@ -183,7 +183,7 @@ bool LIB_ARC::HitTest( const wxPoint& aRefPoint )
} }
bool LIB_ARC::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ) bool LIB_ARC::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
{ {
if( aThreshold < 0 ) if( aThreshold < 0 )
......
...@@ -100,9 +100,9 @@ public: ...@@ -100,9 +100,9 @@ public:
bool Load( LINE_READER& aLineReader, wxString& aErrorMsg ); bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ); bool HitTest( const wxPoint& aPosition, int aThreshold, const TRANSFORM& aTransform ) const;
const EDA_RECT GetBoundingBox() const; // Virtual const EDA_RECT GetBoundingBox() const; // Virtual
......
...@@ -345,7 +345,7 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& ...@@ -345,7 +345,7 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
} }
bool LIB_BEZIER::HitTest( const wxPoint& aRefPos ) bool LIB_BEZIER::HitTest( const wxPoint& aRefPos ) const
{ {
int mindist = GetPenSize() / 2; int mindist = GetPenSize() / 2;
...@@ -357,7 +357,7 @@ bool LIB_BEZIER::HitTest( const wxPoint& aRefPos ) ...@@ -357,7 +357,7 @@ bool LIB_BEZIER::HitTest( const wxPoint& aRefPos )
} }
bool LIB_BEZIER::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ) bool LIB_BEZIER::HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const
{ {
wxPoint ref, start, end; wxPoint ref, start, end;
......
...@@ -72,9 +72,9 @@ public: ...@@ -72,9 +72,9 @@ public:
*/ */
unsigned GetCornerCount() const { return m_PolyPoints.size(); } unsigned GetCornerCount() const { return m_PolyPoints.size(); }
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); bool HitTest( const wxPoint& aPosRef, int aThreshold, const TRANSFORM& aTransform ) const;
const EDA_RECT GetBoundingBox() const; // Virtual const EDA_RECT GetBoundingBox() const; // Virtual
......
...@@ -87,7 +87,7 @@ bool LIB_CIRCLE::Load( LINE_READER& aLineReader, wxString& aErrorMsg ) ...@@ -87,7 +87,7 @@ bool LIB_CIRCLE::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
} }
bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef ) bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef ) const
{ {
int mindist = GetPenSize() / 2; int mindist = GetPenSize() / 2;
...@@ -99,7 +99,7 @@ bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef ) ...@@ -99,7 +99,7 @@ bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
} }
bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ) bool LIB_CIRCLE::HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const
{ {
if( aThreshold < 0 ) if( aThreshold < 0 )
aThreshold = GetPenSize() / 2; aThreshold = GetPenSize() / 2;
......
...@@ -61,9 +61,9 @@ public: ...@@ -61,9 +61,9 @@ public:
bool Load( LINE_READER& aLineReader, wxString& aErrorMsg ); bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); bool HitTest( const wxPoint& aPosRef, int aThreshold, const TRANSFORM& aTransform ) const;
int GetPenSize( ) const; int GetPenSize( ) const;
......
...@@ -237,12 +237,12 @@ public: ...@@ -237,12 +237,12 @@ public:
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) = 0; virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) = 0;
LIB_COMPONENT* GetParent() LIB_COMPONENT* GetParent() const
{ {
return (LIB_COMPONENT *)m_Parent; return (LIB_COMPONENT *)m_Parent;
} }
virtual bool HitTest( const wxPoint& aPosition ) virtual bool HitTest( const wxPoint& aPosition ) const
{ {
return EDA_ITEM::HitTest( aPosition ); return EDA_ITEM::HitTest( aPosition );
} }
...@@ -255,7 +255,7 @@ public: ...@@ -255,7 +255,7 @@ public:
* @param aTransform The transform matrix. * @param aTransform The transform matrix.
* @return True if the point \a aPosition is near this object * @return True if the point \a aPosition is near this object
*/ */
virtual bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ) = 0; virtual bool HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const = 0;
/** /**
* @return the boundary box for this, in library coordinates * @return the boundary box for this, in library coordinates
......
...@@ -320,7 +320,7 @@ void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a ...@@ -320,7 +320,7 @@ void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a
} }
bool LIB_FIELD::HitTest( const wxPoint& aPosition ) bool LIB_FIELD::HitTest( const wxPoint& aPosition ) const
{ {
// Because HitTest is mainly used to select the field // Because HitTest is mainly used to select the field
// return always false if this field is void // return always false if this field is void
...@@ -331,49 +331,37 @@ bool LIB_FIELD::HitTest( const wxPoint& aPosition ) ...@@ -331,49 +331,37 @@ bool LIB_FIELD::HitTest( const wxPoint& aPosition )
} }
bool LIB_FIELD::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ) bool LIB_FIELD::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
{ {
if( aThreshold < 0 ) if( aThreshold < 0 )
aThreshold = 0; aThreshold = 0;
int extraCharCount = 0; // Build a temporary copy of the text for hit testing
EDA_TEXT tmp_text( *this );
// Reference designator text has one or 2 additional character (displays // Reference designator text has one or 2 additional character (displays
// U? or U?A) // U? or U?A)
if( m_id == REFERENCE ) if( m_id == REFERENCE )
{ {
extraCharCount++; wxString extended_text = tmp_text.GetText();
m_Text.Append('?'); extended_text.Append('?');
LIB_COMPONENT* parent = (LIB_COMPONENT*)m_Parent; const LIB_COMPONENT* parent = static_cast<const LIB_COMPONENT*>( m_Parent );
if ( parent && ( parent->GetPartCount() > 1 ) ) if ( parent && ( parent->GetPartCount() > 1 ) )
{ extended_text.Append('A');
m_Text.Append('A'); tmp_text.SetText( extended_text );
extraCharCount++;
}
} }
wxPoint physicalpos = aTransform.TransformCoordinate( m_Pos ); tmp_text.SetTextPosition( aTransform.TransformCoordinate( m_Pos ) );
wxPoint tmp = m_Pos;
m_Pos = physicalpos;
/* The text orientation may need to be flipped if the /* The text orientation may need to be flipped if the
* transformation matrix causes xy axes to be flipped. * transformation matrix causes xy axes to be flipped.
* this simple algo works only for schematic matrix (rot 90 or/and mirror) * this simple algo works only for schematic matrix (rot 90 or/and mirror)
*/ */
int t1 = ( aTransform.x1 != 0 ) ^ ( m_Orient != 0 ); int t1 = ( aTransform.x1 != 0 ) ^ ( m_Orient != 0 );
int orient = t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT; tmp_text.SetOrientation( t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT );
EXCHG( m_Orient, orient );
bool hit = TextHitTest( aPosition );
EXCHG( m_Orient, orient );
m_Pos = tmp;
while( extraCharCount-- )
m_Text.RemoveLast( );
return hit; return tmp_text.TextHitTest( aPosition );
} }
......
...@@ -151,7 +151,7 @@ public: ...@@ -151,7 +151,7 @@ public:
* Function IsVoid * Function IsVoid
* @return true if the field value is void (no text in this field) * @return true if the field value is void (no text in this field)
*/ */
bool IsVoid() bool IsVoid() const
{ {
return m_Text.IsEmpty(); return m_Text.IsEmpty();
} }
...@@ -169,9 +169,9 @@ public: ...@@ -169,9 +169,9 @@ public:
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ); bool HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const;
void operator=( const LIB_FIELD& field ) void operator=( const LIB_FIELD& field )
{ {
......
...@@ -525,13 +525,13 @@ void LIB_PIN::EnableEditMode( bool enable, bool editPinByPin ) ...@@ -525,13 +525,13 @@ void LIB_PIN::EnableEditMode( bool enable, bool editPinByPin )
} }
bool LIB_PIN::HitTest( const wxPoint& aPosition ) bool LIB_PIN::HitTest( const wxPoint& aPosition ) const
{ {
return HitTest( aPosition, 0, DefaultTransform ); return HitTest( aPosition, 0, DefaultTransform );
} }
bool LIB_PIN::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ) bool LIB_PIN::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
{ {
if( aThreshold < 0 ) if( aThreshold < 0 )
aThreshold = 0; aThreshold = 0;
......
...@@ -131,9 +131,9 @@ public: ...@@ -131,9 +131,9 @@ public:
bool Load( LINE_READER& aLineReader, wxString& aErrorMsg ); bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); bool HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const;
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
......
...@@ -321,7 +321,7 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint ...@@ -321,7 +321,7 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
} }
bool LIB_POLYLINE::HitTest( const wxPoint& aPosition ) bool LIB_POLYLINE::HitTest( const wxPoint& aPosition ) const
{ {
int mindist = GetPenSize() / 2; int mindist = GetPenSize() / 2;
...@@ -333,7 +333,7 @@ bool LIB_POLYLINE::HitTest( const wxPoint& aPosition ) ...@@ -333,7 +333,7 @@ bool LIB_POLYLINE::HitTest( const wxPoint& aPosition )
} }
bool LIB_POLYLINE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ) bool LIB_POLYLINE::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
{ {
wxPoint ref, start, end; wxPoint ref, start, end;
......
...@@ -74,9 +74,9 @@ public: ...@@ -74,9 +74,9 @@ public:
*/ */
unsigned GetCornerCount() const { return m_PolyPoints.size(); } unsigned GetCornerCount() const { return m_PolyPoints.size(); }
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ); bool HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const;
const EDA_RECT GetBoundingBox() const; // Virtual const EDA_RECT GetBoundingBox() const; // Virtual
......
...@@ -267,7 +267,7 @@ const EDA_RECT LIB_RECTANGLE::GetBoundingBox() const ...@@ -267,7 +267,7 @@ const EDA_RECT LIB_RECTANGLE::GetBoundingBox() const
} }
bool LIB_RECTANGLE::HitTest( const wxPoint& aPosition ) bool LIB_RECTANGLE::HitTest( const wxPoint& aPosition ) const
{ {
int mindist = ( GetPenSize() / 2 ) + 1; int mindist = ( GetPenSize() / 2 ) + 1;
...@@ -279,7 +279,7 @@ bool LIB_RECTANGLE::HitTest( const wxPoint& aPosition ) ...@@ -279,7 +279,7 @@ bool LIB_RECTANGLE::HitTest( const wxPoint& aPosition )
} }
bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ) bool LIB_RECTANGLE::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
{ {
if( aThreshold < 0 ) if( aThreshold < 0 )
aThreshold = GetPenSize() / 2; aThreshold = GetPenSize() / 2;
......
...@@ -65,9 +65,9 @@ public: ...@@ -65,9 +65,9 @@ public:
bool Load( LINE_READER& aLineReader, wxString& aErrorMsg ); bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); bool HitTest( const wxPoint &aPosRef, int aThreshold, const TRANSFORM& aTransform ) const;
int GetPenSize( ) const; int GetPenSize( ) const;
......
...@@ -185,32 +185,27 @@ bool LIB_TEXT::Load( LINE_READER& aLineReader, wxString& errorMsg ) ...@@ -185,32 +185,27 @@ bool LIB_TEXT::Load( LINE_READER& aLineReader, wxString& errorMsg )
} }
bool LIB_TEXT::HitTest( const wxPoint& aPosition ) bool LIB_TEXT::HitTest( const wxPoint& aPosition ) const
{ {
return HitTest( aPosition, 0, DefaultTransform ); return HitTest( aPosition, 0, DefaultTransform );
} }
bool LIB_TEXT::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ) bool LIB_TEXT::HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const
{ {
if( aThreshold < 0 ) if( aThreshold < 0 )
aThreshold = 0; aThreshold = 0;
wxPoint physicalpos = aTransform.TransformCoordinate( m_Pos ); EDA_TEXT tmp_text( *this );
wxPoint tmp = m_Pos; tmp_text.SetTextPosition( aTransform.TransformCoordinate( m_Pos ) );
m_Pos = physicalpos;
/* The text orientation may need to be flipped if the /* The text orientation may need to be flipped if the
* transformation matrix causes xy axes to be flipped. * transformation matrix causes xy axes to be flipped.
* this simple algo works only for schematic matrix (rot 90 or/and mirror) * this simple algo works only for schematic matrix (rot 90 or/and mirror)
*/ */
int t1 = ( aTransform.x1 != 0 ) ^ ( m_Orient != 0 ); int t1 = ( aTransform.x1 != 0 ) ^ ( m_Orient != 0 );
int orient = t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT; tmp_text.SetOrientation( t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT );
EXCHG( m_Orient, orient ); return tmp_text.TextHitTest( aPosition );
bool hit = TextHitTest( aPosition );
EXCHG( m_Orient, orient );
m_Pos = tmp;
return hit;
} }
......
...@@ -82,11 +82,11 @@ public: ...@@ -82,11 +82,11 @@ public:
bool Load( LINE_READER& aLineReader, wxString& aErrorMsg ); bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ); bool HitTest( const wxPoint &aPosition, int aThreshold, const TRANSFORM& aTransform ) const;
bool HitTest( EDA_RECT& aRect ) bool HitTest( const EDA_RECT& aRect ) const
{ {
return TextHitTest( aRect ); return TextHitTest( aRect );
} }
......
...@@ -210,7 +210,7 @@ public: ...@@ -210,7 +210,7 @@ public:
wxString GetSheetPath() const { return m_sheetPath; } wxString GetSheetPath() const { return m_sheetPath; }
SCH_ITEM* GetParent() { return m_parent; } SCH_ITEM* GetParent() const { return m_parent; }
}; };
......
...@@ -148,7 +148,7 @@ public: ...@@ -148,7 +148,7 @@ public:
* Function GetParent * Function GetParent
* @return the GERBVIEW_FRAME parent of this GERBER_IMAGE * @return the GERBVIEW_FRAME parent of this GERBER_IMAGE
*/ */
GERBVIEW_FRAME* GetParent() GERBVIEW_FRAME* GetParent() const
{ {
return m_Parent; return m_Parent;
} }
......
...@@ -131,7 +131,7 @@ wxPoint GERBER_DRAW_ITEM::GetABPosition( const wxPoint& aXYPosition ) const ...@@ -131,7 +131,7 @@ wxPoint GERBER_DRAW_ITEM::GetABPosition( const wxPoint& aXYPosition ) const
} }
wxPoint GERBER_DRAW_ITEM::GetXYPosition( const wxPoint& aABPosition ) wxPoint GERBER_DRAW_ITEM::GetXYPosition( const wxPoint& aABPosition ) const
{ {
// do the inverse transform made by GetABPosition // do the inverse transform made by GetABPosition
wxPoint xyPos = aABPosition; wxPoint xyPos = aABPosition;
...@@ -577,7 +577,7 @@ void GERBER_DRAW_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) ...@@ -577,7 +577,7 @@ void GERBER_DRAW_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
} }
bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos ) bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos ) const
{ {
// calculate aRefPos in XY gerber axis: // calculate aRefPos in XY gerber axis:
wxPoint ref_pos = GetXYPosition( aRefPos ); wxPoint ref_pos = GetXYPosition( aRefPos );
...@@ -592,7 +592,7 @@ bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos ) ...@@ -592,7 +592,7 @@ bool GERBER_DRAW_ITEM::HitTest( const wxPoint& aRefPos )
} }
bool GERBER_DRAW_ITEM::HitTest( EDA_RECT& aRefArea ) bool GERBER_DRAW_ITEM::HitTest( const EDA_RECT& aRefArea ) const
{ {
wxPoint pos = GetABPosition( m_Start ); wxPoint pos = GetABPosition( m_Start );
......
...@@ -209,7 +209,7 @@ public: ...@@ -209,7 +209,7 @@ public:
* @param aABPosition = position in A,B plotter axis * @param aABPosition = position in A,B plotter axis
* @return const wxPoint - The given position in X,Y axis. * @return const wxPoint - The given position in X,Y axis.
*/ */
wxPoint GetXYPosition( const wxPoint& aABPosition ); wxPoint GetXYPosition( const wxPoint& aABPosition ) const;
/** /**
* Function GetDcodeDescr * Function GetDcodeDescr
...@@ -255,7 +255,7 @@ public: ...@@ -255,7 +255,7 @@ public:
* @param aRefPos a wxPoint to test * @param aRefPos a wxPoint to test
* @return bool - true if a hit, else false * @return bool - true if a hit, else false
*/ */
bool HitTest( const wxPoint& aRefPos ); bool HitTest( const wxPoint& aRefPos ) const;
/** /**
* Function HitTest (overloaded) * Function HitTest (overloaded)
...@@ -264,7 +264,7 @@ public: ...@@ -264,7 +264,7 @@ public:
* @param aRefArea a wxPoint to test * @param aRefArea a wxPoint to test
* @return bool - true if a hit, else false * @return bool - true if a hit, else false
*/ */
bool HitTest( EDA_RECT& aRefArea ); bool HitTest( const EDA_RECT& aRefArea ) const;
/** /**
* Function GetClass * Function GetClass
......
...@@ -456,14 +456,10 @@ public: ...@@ -456,14 +456,10 @@ public:
* Function HitTest * Function HitTest
* tests if \a aPosition is contained within or on the bounding area of an item. * tests if \a aPosition is contained within or on the bounding area of an item.
* *
* @note This function cannot be const because some of the derive objects perform
* intermediate calculations which change object members. Make sure derived
* objects do not declare this as const.
*
* @param aPosition A reference to a wxPoint object containing the coordinates to test. * @param aPosition A reference to a wxPoint object containing the coordinates to test.
* @return True if \a aPosition is within or on the item bounding area. * @return True if \a aPosition is within or on the item bounding area.
*/ */
virtual bool HitTest( const wxPoint& aPosition ) virtual bool HitTest( const wxPoint& aPosition ) const
{ {
return false; // derived classes should override this function return false; // derived classes should override this function
} }
......
...@@ -254,7 +254,7 @@ public: ...@@ -254,7 +254,7 @@ public:
*/ */
wxString GetLayerName() const; wxString GetLayerName() const;
virtual bool HitTest( const wxPoint& aPosition ) virtual bool HitTest( const wxPoint& aPosition ) const
{ {
return EDA_ITEM::HitTest( aPosition ); return EDA_ITEM::HitTest( aPosition );
} }
......
...@@ -123,7 +123,7 @@ public: ...@@ -123,7 +123,7 @@ public:
BASE_SCREEN* GetScreen(); BASE_SCREEN* GetScreen();
EDA_DRAW_FRAME* GetParent(); EDA_DRAW_FRAME* GetParent() const;
void OnPaint( wxPaintEvent& event ); void OnPaint( wxPaintEvent& event );
......
...@@ -291,7 +291,10 @@ public: ...@@ -291,7 +291,10 @@ public:
bool IsConnected( const wxPoint& aPoint ) const; bool IsConnected( const wxPoint& aPoint ) const;
/** @copydoc EDA_ITEM::HitTest(const wxPoint&) */ /** @copydoc EDA_ITEM::HitTest(const wxPoint&) */
virtual bool HitTest( const wxPoint& aPosition ) { return HitTest( aPosition, 0 ); } virtual bool HitTest( const wxPoint& aPosition ) const
{
return HitTest( aPosition, 0 );
}
/** /**
* Function HitTest * Function HitTest
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
EDA_COLOR_T GetColor() const { return m_color; } EDA_COLOR_T GetColor() const { return m_color; }
WS_DRAW_TYPE GetType() const { return m_type; }; WS_DRAW_TYPE GetType() const { return m_type; };
WORKSHEET_DATAITEM* GetParent() { return m_parent; } WORKSHEET_DATAITEM* GetParent() const { return m_parent; }
/** The function to draw a WS_DRAW_ITEM /** The function to draw a WS_DRAW_ITEM
*/ */
...@@ -69,7 +69,7 @@ public: ...@@ -69,7 +69,7 @@ public:
* Abstract function: should exist for derived items * Abstract function: should exist for derived items
* return true if the point aPosition is on the item * return true if the point aPosition is on the item
*/ */
virtual bool HitTest( const wxPoint& aPosition) = 0; virtual bool HitTest( const wxPoint& aPosition) const = 0;
/** /**
* Abstract function: should exist for derived items * Abstract function: should exist for derived items
...@@ -124,7 +124,7 @@ public: ...@@ -124,7 +124,7 @@ public:
* Virtual function * Virtual function
* return true if the point aPosition is on the line * return true if the point aPosition is on the line
*/ */
virtual bool HitTest( const wxPoint& aPosition); virtual bool HitTest( const wxPoint& aPosition) const;
/** /**
* return true if the point aPosition is on the starting point of this item. * return true if the point aPosition is on the starting point of this item.
...@@ -174,7 +174,7 @@ public: ...@@ -174,7 +174,7 @@ public:
* Virtual function * Virtual function
* return true if the point aPosition is inside one polygon * return true if the point aPosition is inside one polygon
*/ */
virtual bool HitTest( const wxPoint& aPosition); virtual bool HitTest( const wxPoint& aPosition) const;
/** /**
* return true if the point aPosition is on the starting point of this item. * return true if the point aPosition is on the starting point of this item.
...@@ -202,7 +202,7 @@ public: ...@@ -202,7 +202,7 @@ public:
* Virtual function * Virtual function
* return true if the point aPosition is on one edge of the rectangle * return true if the point aPosition is on one edge of the rectangle
*/ */
virtual bool HitTest( const wxPoint& aPosition); virtual bool HitTest( const wxPoint& aPosition) const;
/** /**
* return true if the point aPosition is on the starting point of this item. * return true if the point aPosition is on the starting point of this item.
...@@ -239,7 +239,7 @@ public: ...@@ -239,7 +239,7 @@ public:
* Virtual function * Virtual function
* return true if the point aPosition is on the text * return true if the point aPosition is on the text
*/ */
virtual bool HitTest( const wxPoint& aPosition); virtual bool HitTest( const wxPoint& aPosition) const;
/** /**
* return true if the point aPosition is on the starting point of this item. * return true if the point aPosition is on the starting point of this item.
...@@ -274,7 +274,7 @@ public: ...@@ -274,7 +274,7 @@ public:
* Virtual function * Virtual function
* return true if the point aPosition is on bitmap * return true if the point aPosition is on bitmap
*/ */
virtual bool HitTest( const wxPoint& aPosition); virtual bool HitTest( const wxPoint& aPosition) const;
/** /**
* return true if the point aPosition is on the reference point of this item. * return true if the point aPosition is on the reference point of this item.
......
...@@ -17,7 +17,7 @@ private: ...@@ -17,7 +17,7 @@ private:
public: public:
TREE_PROJECT_FRAME* GetParent() TREE_PROJECT_FRAME* GetParent() const
{ {
return m_Parent; return m_Parent;
} }
......
...@@ -396,7 +396,7 @@ void DIMENSION::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) ...@@ -396,7 +396,7 @@ void DIMENSION::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
} }
bool DIMENSION::HitTest( const wxPoint& aPosition ) bool DIMENSION::HitTest( const wxPoint& aPosition ) const
{ {
if( m_Text.TextHitTest( aPosition ) ) if( m_Text.TextHitTest( aPosition ) )
return true; return true;
......
...@@ -127,7 +127,7 @@ public: ...@@ -127,7 +127,7 @@ public:
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
/** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect, /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
* bool aContained = true, int aAccuracy ) const * bool aContained = true, int aAccuracy ) const
......
...@@ -475,7 +475,7 @@ const EDA_RECT DRAWSEGMENT::GetBoundingBox() const ...@@ -475,7 +475,7 @@ const EDA_RECT DRAWSEGMENT::GetBoundingBox() const
} }
bool DRAWSEGMENT::HitTest( const wxPoint& aPosition ) bool DRAWSEGMENT::HitTest( const wxPoint& aPosition ) const
{ {
switch( m_Shape ) switch( m_Shape )
{ {
......
...@@ -178,7 +178,7 @@ public: ...@@ -178,7 +178,7 @@ public:
virtual const EDA_RECT GetBoundingBox() const; virtual const EDA_RECT GetBoundingBox() const;
virtual bool HitTest( const wxPoint& aPosition ); virtual bool HitTest( const wxPoint& aPosition ) const;
/** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect, /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
* bool aContained = true, int aAccuracy ) const * bool aContained = true, int aAccuracy ) const
......
...@@ -64,7 +64,7 @@ public: ...@@ -64,7 +64,7 @@ public:
const wxPoint& GetPosition() const { return m_Pos; } const wxPoint& GetPosition() const { return m_Pos; }
void SetPosition( const wxPoint& aPos ) { m_Pos = aPos; } void SetPosition( const wxPoint& aPos ) { m_Pos = aPos; }
bool HitTest( const wxPoint& aPosition ) bool HitTest( const wxPoint& aPosition ) const
{ {
return HitTestMarker( aPosition ); return HitTestMarker( aPosition );
} }
......
...@@ -158,7 +158,7 @@ void PCB_TARGET::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE mode_color, ...@@ -158,7 +158,7 @@ void PCB_TARGET::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE mode_color,
} }
bool PCB_TARGET::HitTest( const wxPoint& aPosition ) bool PCB_TARGET::HitTest( const wxPoint& aPosition ) const
{ {
int dX = aPosition.x - m_Pos.x; int dX = aPosition.x - m_Pos.x;
int dY = aPosition.y - m_Pos.y; int dY = aPosition.y - m_Pos.y;
......
...@@ -82,7 +82,7 @@ public: ...@@ -82,7 +82,7 @@ public:
void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset ); GR_DRAWMODE aDrawMode, const wxPoint& offset = ZeroOffset );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
/** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect, /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
* bool aContained = true, int aAccuracy ) const * bool aContained = true, int aAccuracy ) const
......
...@@ -549,7 +549,7 @@ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) ...@@ -549,7 +549,7 @@ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
} }
bool MODULE::HitTest( const wxPoint& aPosition ) bool MODULE::HitTest( const wxPoint& aPosition ) const
{ {
if( m_BoundaryBox.Contains( aPosition ) ) if( m_BoundaryBox.Contains( aPosition ) )
return true; return true;
......
...@@ -324,7 +324,7 @@ public: ...@@ -324,7 +324,7 @@ public:
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
/** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect, /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
* bool aContained = true, int aAccuracy ) const * bool aContained = true, int aAccuracy ) const
......
...@@ -637,7 +637,7 @@ bool D_PAD::IsOnLayer( LAYER_NUM aLayer ) const ...@@ -637,7 +637,7 @@ bool D_PAD::IsOnLayer( LAYER_NUM aLayer ) const
} }
bool D_PAD::HitTest( const wxPoint& aPosition ) bool D_PAD::HitTest( const wxPoint& aPosition ) const
{ {
int dx, dy; int dx, dy;
......
...@@ -341,7 +341,7 @@ public: ...@@ -341,7 +341,7 @@ public:
* Function GetBoundingRadius * Function GetBoundingRadius
* returns the radius of a minimum sized circle which fully encloses this pad. * returns the radius of a minimum sized circle which fully encloses this pad.
*/ */
int GetBoundingRadius() int GetBoundingRadius() const
{ {
// Any member function which would affect this calculation should set // Any member function which would affect this calculation should set
// m_boundingRadius to -1 to re-trigger the calculation from here. // m_boundingRadius to -1 to re-trigger the calculation from here.
...@@ -368,7 +368,7 @@ public: ...@@ -368,7 +368,7 @@ public:
bool IsOnLayer( LAYER_NUM aLayer ) const; bool IsOnLayer( LAYER_NUM aLayer ) const;
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
wxString GetClass() const wxString GetClass() const
{ {
...@@ -450,7 +450,8 @@ private: ...@@ -450,7 +450,8 @@ private:
*/ */
int boundingRadius() const; int boundingRadius() const;
int m_boundingRadius; ///< radius of the circle containing the pad shape // Actually computed and cached on demand by the accessor
mutable int m_boundingRadius; ///< radius of the circle containing the pad shape
/// Pad name (4 char) or a long identifier (used in pad name /// Pad name (4 char) or a long identifier (used in pad name
/// comparisons because this is faster than string comparison) /// comparisons because this is faster than string comparison)
......
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
bool HitTest( const wxPoint& aPosition ) bool HitTest( const wxPoint& aPosition ) const
{ {
return TextHitTest( aPosition ); return TextHitTest( aPosition );
} }
......
...@@ -163,7 +163,7 @@ void TEXTE_MODULE::SetLocalCoord() ...@@ -163,7 +163,7 @@ void TEXTE_MODULE::SetLocalCoord()
RotatePoint( &m_Pos0.x, &m_Pos0.y, -angle ); RotatePoint( &m_Pos0.x, &m_Pos0.y, -angle );
} }
bool TEXTE_MODULE::HitTest( const wxPoint& aPosition ) bool TEXTE_MODULE::HitTest( const wxPoint& aPosition ) const
{ {
wxPoint rel_pos; wxPoint rel_pos;
EDA_RECT area = GetTextBox( -1, -1 ); EDA_RECT area = GetTextBox( -1, -1 );
...@@ -455,6 +455,9 @@ void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const ...@@ -455,6 +455,9 @@ void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
case LAYER_N_FRONT: case LAYER_N_FRONT:
aLayers[0] = ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE ); // how about SILKSCREEN_N_FRONT? aLayers[0] = ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE ); // how about SILKSCREEN_N_FRONT?
break; break;
default:
wxFAIL_MSG( wxT( "Can't tell text layer" ) );
} }
break; break;
} }
......
...@@ -148,7 +148,7 @@ public: ...@@ -148,7 +148,7 @@ public:
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ); void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
bool HitTest( const wxPoint& aPosition ); bool HitTest( const wxPoint& aPosition ) const;
wxString GetClass() const wxString GetClass() const
{ {
......
...@@ -1236,7 +1236,7 @@ bool TRACK::HitTest( const wxPoint& aPosition ) ...@@ -1236,7 +1236,7 @@ bool TRACK::HitTest( const wxPoint& aPosition )
return TestSegmentHit( aPosition, m_Start, m_End, m_Width / 2 ); return TestSegmentHit( aPosition, m_Start, m_End, m_Width / 2 );
} }
bool VIA::HitTest( const wxPoint& aPosition ) bool VIA::HitTest( const wxPoint& aPosition ) const
{ {
int max_dist = m_Width / 2; int max_dist = m_Width / 2;
......
...@@ -401,7 +401,7 @@ public: ...@@ -401,7 +401,7 @@ public:
const wxPoint& GetPosition() const { return m_Start; } // was overload const wxPoint& GetPosition() const { return m_Start; } // was overload
void SetPosition( const wxPoint& aPoint ) { m_Start = aPoint; m_End = aPoint; } // was overload void SetPosition( const wxPoint& aPoint ) { m_Start = aPoint; m_End = aPoint; } // was overload
virtual bool HitTest( const wxPoint& aPosition ); virtual bool HitTest( const wxPoint& aPosition ) const;
virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const; virtual bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const;
......
...@@ -440,37 +440,42 @@ int ZONE_CONTAINER::GetThermalReliefCopperBridge( D_PAD* aPad ) const ...@@ -440,37 +440,42 @@ int ZONE_CONTAINER::GetThermalReliefCopperBridge( D_PAD* aPad ) const
} }
bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition ) bool ZONE_CONTAINER::HitTest( const wxPoint& aPosition ) const
{ {
if( HitTestForCorner( aPosition ) ) if( HitTestForCorner( aPosition ) >= 0 )
return true; return true;
if( HitTestForEdge( aPosition ) ) if( HitTestForEdge( aPosition ) >= 0 )
return true; return true;
return false; return false;
} }
void ZONE_CONTAINER::SetSelectedCorner( const wxPoint& aPosition )
{
m_CornerSelection = HitTestForCorner( aPosition );
if( m_CornerSelection < 0 )
m_CornerSelection = HitTestForEdge( aPosition );
}
// Zones outlines have no thickness, so it Hit Test functions // Zones outlines have no thickness, so it Hit Test functions
// we must have a default distance between the test point // we must have a default distance between the test point
// and a corner or a zone edge: // and a corner or a zone edge:
#define MAX_DIST_IN_MM 0.25 #define MAX_DIST_IN_MM 0.25
bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos ) int ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos ) const
{ {
int distmax = Millimeter2iu( MAX_DIST_IN_MM ); int distmax = Millimeter2iu( MAX_DIST_IN_MM );
m_CornerSelection = m_Poly->HitTestForCorner( refPos, distmax ); return m_Poly->HitTestForCorner( refPos, distmax );
return m_CornerSelection >= 0;
} }
bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) int ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) const
{ {
int distmax = Millimeter2iu( MAX_DIST_IN_MM ); int distmax = Millimeter2iu( MAX_DIST_IN_MM );
m_CornerSelection = m_Poly->HitTestForEdge( refPos, distmax ); return m_Poly->HitTestForEdge( refPos, distmax );
return m_CornerSelection >= 0;
} }
...@@ -700,25 +705,23 @@ void ZONE_CONTAINER::Move( const wxPoint& offset ) ...@@ -700,25 +705,23 @@ void ZONE_CONTAINER::Move( const wxPoint& offset )
} }
void ZONE_CONTAINER::MoveEdge( const wxPoint& offset ) void ZONE_CONTAINER::MoveEdge( const wxPoint& offset, int aEdge )
{ {
int ii = m_CornerSelection;
// Move the start point of the selected edge: // Move the start point of the selected edge:
SetCornerPosition( ii, GetCornerPosition( ii ) + offset ); SetCornerPosition( aEdge, GetCornerPosition( aEdge ) + offset );
// Move the end point of the selected edge: // Move the end point of the selected edge:
if( m_Poly->m_CornersList.IsEndContour( ii ) || ii == GetNumCorners() - 1 ) if( m_Poly->m_CornersList.IsEndContour( aEdge ) || aEdge == GetNumCorners() - 1 )
{ {
int icont = m_Poly->GetContour( ii ); int icont = m_Poly->GetContour( aEdge );
ii = m_Poly->GetContourStart( icont ); aEdge = m_Poly->GetContourStart( icont );
} }
else else
{ {
ii++; aEdge++;
} }
SetCornerPosition( ii, GetCornerPosition( ii ) + offset ); SetCornerPosition( aEdge, GetCornerPosition( aEdge ) + offset );
m_Poly->Hatch(); m_Poly->Hatch();
} }
......
...@@ -217,6 +217,10 @@ public: ...@@ -217,6 +217,10 @@ public:
int GetSelectedCorner() const { return m_CornerSelection; } int GetSelectedCorner() const { return m_CornerSelection; }
void SetSelectedCorner( int aCorner ) { m_CornerSelection = aCorner; } void SetSelectedCorner( int aCorner ) { m_CornerSelection = aCorner; }
///
// Like HitTest but selects the current corner to be operated on
void SetSelectedCorner( const wxPoint& aPosition );
int GetLocalFlags() const { return m_localFlgs; } int GetLocalFlags() const { return m_localFlgs; }
void SetLocalFlags( int aFlags ) { m_localFlgs = aFlags; } void SetLocalFlags( int aFlags ) { m_localFlgs = aFlags; }
...@@ -234,7 +238,7 @@ public: ...@@ -234,7 +238,7 @@ public:
* @param aRefPos A wxPoint to test * @param aRefPos A wxPoint to test
* @return bool - true if a hit, else false * @return bool - true if a hit, else false
*/ */
virtual bool HitTest( const wxPoint& aPosition ); virtual bool HitTest( const wxPoint& aPosition ) const;
/** /**
* Function HitTest * Function HitTest
...@@ -342,7 +346,7 @@ public: ...@@ -342,7 +346,7 @@ public:
* @return true if found * @return true if found
* @param refPos : A wxPoint to test * @param refPos : A wxPoint to test
*/ */
bool HitTestForCorner( const wxPoint& refPos ); int HitTestForCorner( const wxPoint& refPos ) const;
/** /**
* Function HitTestForEdge * Function HitTestForEdge
...@@ -351,7 +355,7 @@ public: ...@@ -351,7 +355,7 @@ public:
* @return true if found * @return true if found
* @param refPos : A wxPoint to test * @param refPos : A wxPoint to test
*/ */
bool HitTestForEdge( const wxPoint& refPos ); int HitTestForEdge( const wxPoint& refPos ) const;
/** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect, /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
* bool aContained = true, int aAccuracy ) const * bool aContained = true, int aAccuracy ) const
...@@ -400,10 +404,11 @@ public: ...@@ -400,10 +404,11 @@ public:
/** /**
* Function MoveEdge * Function MoveEdge
* Move the outline Edge. m_CornerSelection is the start point of the outline edge * Move the outline Edge
* @param offset = moving vector * @param offset = moving vector
* @param aEdge = start point of the outline edge
*/ */
void MoveEdge( const wxPoint& offset ); void MoveEdge( const wxPoint& offset, int aEdge );
/** /**
* Function Rotate * Function Rotate
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <pcbnew_id.h> #include <pcbnew_id.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
#include <class_zone.h>
#include <pcbnew.h> #include <pcbnew.h>
#include <protos.h> #include <protos.h>
...@@ -160,8 +161,9 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode ) ...@@ -160,8 +161,9 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode )
(*m_Collector)[i]->Show( 0, std::cout ); (*m_Collector)[i]->Show( 0, std::cout );
#endif #endif
/* Remove redundancies: sometime, zones are found twice, /* Remove redundancies: sometime, legacy zones are found twice,
* because zones can be filled by overlapping segments (this is a fill option) * because zones can be filled by overlapping segments (this is a fill option)
* Trigger the selection of the current edge for new-style zones
*/ */
time_t timestampzone = 0; time_t timestampzone = 0;
...@@ -169,18 +171,32 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode ) ...@@ -169,18 +171,32 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode )
{ {
item = (*m_Collector)[ii]; item = (*m_Collector)[ii];
if( item->Type() != PCB_ZONE_T ) switch( item->Type() )
continue;
// Found a TYPE ZONE
if( item->GetTimeStamp() == timestampzone ) // Remove it, redundant, zone already found
{ {
m_Collector->Remove( ii ); case PCB_ZONE_T:
ii--; // Found a TYPE ZONE
} if( item->GetTimeStamp() == timestampzone ) // Remove it, redundant, zone already found
else {
{ m_Collector->Remove( ii );
timestampzone = item->GetTimeStamp(); ii--;
}
else
{
timestampzone = item->GetTimeStamp();
}
break;
case PCB_ZONE_AREA_T:
{
/* We need to do the selection now because the menu text
* depends on it */
ZONE_CONTAINER *zone = static_cast<ZONE_CONTAINER*>( item );
zone->SetSelectedCorner( RefPos( true ) );
}
break;
default:
break;
} }
} }
......
...@@ -16,7 +16,7 @@ public: ...@@ -16,7 +16,7 @@ public:
void OnOkClick( wxCommandEvent& event ); void OnOkClick( wxCommandEvent& event );
void OnCancelClick( wxCommandEvent& event ); void OnCancelClick( wxCommandEvent& event );
PCB_EDIT_FRAME* GetParent() { return (PCB_EDIT_FRAME*) wxDialog::GetParent(); } PCB_EDIT_FRAME* GetParent() const { return (PCB_EDIT_FRAME*) wxDialog::GetParent(); }
private: private:
void OnMiddleBtnPanEnbl( wxCommandEvent& event ) void OnMiddleBtnPanEnbl( wxCommandEvent& event )
......
...@@ -2234,6 +2234,8 @@ void EAGLE_PLUGIN::packageCircle( MODULE* aModule, CPTREE& aTree ) const ...@@ -2234,6 +2234,8 @@ void EAGLE_PLUGIN::packageCircle( MODULE* aModule, CPTREE& aTree ) const
case ECO1_N: layer = SILKSCREEN_N_FRONT; break; case ECO1_N: layer = SILKSCREEN_N_FRONT; break;
case ECO2_N: layer = SILKSCREEN_N_BACK; break; case ECO2_N: layer = SILKSCREEN_N_BACK; break;
*/ */
default:
break;
} }
gr->SetLayer( layer ); gr->SetLayer( layer );
......
...@@ -661,14 +661,14 @@ void PCB_EDIT_FRAME::createPopUpMenuForZones( ZONE_CONTAINER* edge_zone, wxMenu* ...@@ -661,14 +661,14 @@ void PCB_EDIT_FRAME::createPopUpMenuForZones( ZONE_CONTAINER* edge_zone, wxMenu*
edge_zone->GetIsKeepout() ? _("Keepout Area") : _( "Zones" ), edge_zone->GetIsKeepout() ? _("Keepout Area") : _( "Zones" ),
KiBitmap( add_zone_xpm ) ); KiBitmap( add_zone_xpm ) );
if( edge_zone->HitTestForCorner( RefPos( true ) ) ) if( edge_zone->HitTestForCorner( RefPos( true ) ) >= 0 )
{ {
AddMenuItem( zones_menu, ID_POPUP_PCB_MOVE_ZONE_CORNER, AddMenuItem( zones_menu, ID_POPUP_PCB_MOVE_ZONE_CORNER,
_( "Move Corner" ), KiBitmap( move_xpm ) ); _( "Move Corner" ), KiBitmap( move_xpm ) );
AddMenuItem( zones_menu, ID_POPUP_PCB_DELETE_ZONE_CORNER, AddMenuItem( zones_menu, ID_POPUP_PCB_DELETE_ZONE_CORNER,
_( "Delete Corner" ), KiBitmap( delete_xpm ) ); _( "Delete Corner" ), KiBitmap( delete_xpm ) );
} }
else if( edge_zone->HitTestForEdge( RefPos( true ) ) ) else if( edge_zone->HitTestForEdge( RefPos( true ) ) >= 0 )
{ {
AddMenuItem( zones_menu, ID_POPUP_PCB_ADD_ZONE_CORNER, AddMenuItem( zones_menu, ID_POPUP_PCB_ADD_ZONE_CORNER,
_( "Create Corner" ), KiBitmap( add_corner_xpm ) ); _( "Create Corner" ), KiBitmap( add_corner_xpm ) );
......
...@@ -401,9 +401,9 @@ struct hitVisitor ...@@ -401,9 +401,9 @@ struct hitVisitor
{ {
PNS_ITEMSET& m_items; PNS_ITEMSET& m_items;
const VECTOR2I& m_point; const VECTOR2I& m_point;
PNS_NODE* m_world; const PNS_NODE* m_world;
hitVisitor( PNS_ITEMSET& aTab, const VECTOR2I& aPoint, PNS_NODE* aWorld ) : hitVisitor( PNS_ITEMSET& aTab, const VECTOR2I& aPoint, const PNS_NODE* aWorld ) :
m_items( aTab ), m_point( aPoint ), m_world( aWorld ) {}; m_items( aTab ), m_point( aPoint ), m_world( aWorld ) {};
bool operator()( PNS_ITEM* aItem ) bool operator()( PNS_ITEM* aItem )
...@@ -423,7 +423,7 @@ struct hitVisitor ...@@ -423,7 +423,7 @@ struct hitVisitor
}; };
const PNS_ITEMSET PNS_NODE::HitTest( const VECTOR2I& aPoint ) const PNS_ITEMSET PNS_NODE::HitTest( const VECTOR2I& aPoint ) const
{ {
PNS_ITEMSET items; PNS_ITEMSET items;
// fixme: we treat a point as an infinitely small circle - this is inefficient. // fixme: we treat a point as an infinitely small circle - this is inefficient.
......
...@@ -140,7 +140,7 @@ public: ...@@ -140,7 +140,7 @@ public:
int aKindMask = PNS_ITEM::ANY ); int aKindMask = PNS_ITEM::ANY );
///> Hit detection ///> Hit detection
const PNS_ITEMSET HitTest( const VECTOR2I& aPoint ); const PNS_ITEMSET HitTest( const VECTOR2I& aPoint ) const;
void Add( PNS_ITEM* aItem ); void Add( PNS_ITEM* aItem );
void Remove( PNS_ITEM* aItem ); void Remove( PNS_ITEM* aItem );
......
...@@ -433,9 +433,9 @@ void Abort_Zone_Move_Corner_Or_Outlines( EDA_DRAW_PANEL* Panel, wxDC* DC ) ...@@ -433,9 +433,9 @@ void Abort_Zone_Move_Corner_Or_Outlines( EDA_DRAW_PANEL* Panel, wxDC* DC )
} }
else if( zone->IsDragging() ) else if( zone->IsDragging() )
{ {
wxPoint offset; wxPoint offset = s_CornerInitialPosition - s_CursorLastPosition;
offset = s_CornerInitialPosition - s_CursorLastPosition; int selection = zone->GetSelectedCorner();
zone->MoveEdge( offset ); zone->MoveEdge( offset, selection );
} }
else else
{ {
...@@ -485,9 +485,9 @@ void Show_Zone_Corner_Or_Outline_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* ...@@ -485,9 +485,9 @@ void Show_Zone_Corner_Or_Outline_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC*
} }
else if( zone->IsDragging() ) else if( zone->IsDragging() )
{ {
wxPoint offset; wxPoint offset = pos - s_CursorLastPosition;
offset = pos - s_CursorLastPosition; int selection = zone->GetSelectedCorner();
zone->MoveEdge( offset ); zone->MoveEdge( offset, selection );
s_CursorLastPosition = pos; s_CursorLastPosition = pos;
} }
else else
......
...@@ -96,7 +96,7 @@ bool TestPointInsidePolygon( const CPOLYGONS_LIST& aPolysList, ...@@ -96,7 +96,7 @@ bool TestPointInsidePolygon( const CPOLYGONS_LIST& aPolysList,
/* Function TestPointInsidePolygon (overlaid) /* Function TestPointInsidePolygon (overlaid)
* same as previous, but use wxPoint and aCount corners * same as previous, but use wxPoint and aCount corners
*/ */
bool TestPointInsidePolygon( wxPoint *aPolysList, int aCount,wxPoint aRefPoint ) bool TestPointInsidePolygon( const wxPoint *aPolysList, int aCount, const wxPoint &aRefPoint )
{ {
// count intersection points to right of (refx,refy). If odd number, point (refx,refy) is inside polyline // count intersection points to right of (refx,refy). If odd number, point (refx,refy) is inside polyline
int ics, ice; int ics, ice;
......
...@@ -34,6 +34,6 @@ bool TestPointInsidePolygon( const CPOLYGONS_LIST& aPolysList, ...@@ -34,6 +34,6 @@ bool TestPointInsidePolygon( const CPOLYGONS_LIST& aPolysList,
* @param aRefPoint: the point coordinate to test * @param aRefPoint: the point coordinate to test
* @return true if the point is inside, false for outside * @return true if the point is inside, false for outside
*/ */
bool TestPointInsidePolygon( wxPoint* aPolysList, bool TestPointInsidePolygon( const wxPoint* aPolysList,
int aCount, int aCount,
wxPoint aRefPoint ); const wxPoint &aRefPoint );
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