Constification of HitTest and GetParent

In particular HitTest for zones *do not* select the nearest vertex/edge as a side effect
This commit is contained in:
Lorenzo Marcantonio 2014-05-04 19:08:36 +02:00
parent 19c184df97
commit 342016b692
61 changed files with 188 additions and 176 deletions

View File

@ -80,7 +80,7 @@ public:
EDA_3D_CANVAS( EDA_3D_FRAME* parent, int* attribList = 0 );
~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(); }

View File

@ -81,7 +81,7 @@ public:
m_auimgr.UnInit();
};
PCB_BASE_FRAME* Parent() { return (PCB_BASE_FRAME*)GetParent(); }
PCB_BASE_FRAME* Parent() const { return (PCB_BASE_FRAME*)GetParent(); }
BOARD* GetBoard();

View File

@ -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();
return (EDA_DRAW_FRAME*) mom;

View File

@ -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
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 );
}
@ -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
#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],
m_Corners.size(), aPosition );
@ -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
bool WS_DRAW_ITEM_RECT::HitTest( const wxPoint& aPosition)
bool WS_DRAW_ITEM_RECT::HitTest( const wxPoint& aPosition) const
{
int dist = GetPenWidth()/2;
wxPoint start = GetStart();
@ -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
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 );
}
@ -394,9 +394,9 @@ void WS_DRAW_ITEM_BITMAP::DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC )
* Virtual function
* 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 )
return false;

View File

@ -52,7 +52,7 @@ public:
int GetSelection();
void OnSize( wxSizeEvent& event );
virtual CVPCB_MAINFRAME* GetParent();
virtual CVPCB_MAINFRAME* GetParent() const;
};

View File

@ -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();
}

View File

@ -654,14 +654,14 @@ public:
*/
void SetPartCount( int count );
int GetPartCount() { return m_unitCount; }
int GetPartCount() const { return m_unitCount; }
/**
* Function IsMulti
* @return true if the component has multiple parts per package.
* 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

View File

@ -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;
@ -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 )

View File

@ -100,9 +100,9 @@ public:
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

View File

@ -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;
@ -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;

View File

@ -72,9 +72,9 @@ public:
*/
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

View File

@ -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;
@ -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 )
aThreshold = GetPenSize() / 2;

View File

@ -61,9 +61,9 @@ public:
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;

View File

@ -237,12 +237,12 @@ public:
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) = 0;
LIB_COMPONENT* GetParent()
LIB_COMPONENT* GetParent() const
{
return (LIB_COMPONENT *)m_Parent;
}
virtual bool HitTest( const wxPoint& aPosition )
virtual bool HitTest( const wxPoint& aPosition ) const
{
return EDA_ITEM::HitTest( aPosition );
}
@ -255,7 +255,7 @@ public:
* @param aTransform The transform matrix.
* @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

View File

@ -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
// return always false if this field is void
@ -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 )
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
// U? or U?A)
if( m_id == REFERENCE )
{
extraCharCount++;
m_Text.Append('?');
LIB_COMPONENT* parent = (LIB_COMPONENT*)m_Parent;
wxString extended_text = tmp_text.GetText();
extended_text.Append('?');
const LIB_COMPONENT* parent = static_cast<const LIB_COMPONENT*>( m_Parent );
if ( parent && ( parent->GetPartCount() > 1 ) )
{
m_Text.Append('A');
extraCharCount++;
}
extended_text.Append('A');
tmp_text.SetText( extended_text );
}
wxPoint physicalpos = aTransform.TransformCoordinate( m_Pos );
wxPoint tmp = m_Pos;
m_Pos = physicalpos;
tmp_text.SetTextPosition( aTransform.TransformCoordinate( m_Pos ) );
/* The text orientation may need to be flipped if the
* transformation matrix causes xy axes to be flipped.
* this simple algo works only for schematic matrix (rot 90 or/and mirror)
*/
int t1 = ( aTransform.x1 != 0 ) ^ ( m_Orient != 0 );
int orient = t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT;
EXCHG( m_Orient, orient );
tmp_text.SetOrientation( t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT );
bool hit = TextHitTest( aPosition );
EXCHG( m_Orient, orient );
m_Pos = tmp;
while( extraCharCount-- )
m_Text.RemoveLast( );
return hit;
return tmp_text.TextHitTest( aPosition );
}

View File

@ -151,7 +151,7 @@ public:
* Function IsVoid
* @return true if the field value is void (no text in this field)
*/
bool IsVoid()
bool IsVoid() const
{
return m_Text.IsEmpty();
}
@ -169,9 +169,9 @@ public:
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 )
{

View File

@ -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 );
}
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 )
aThreshold = 0;

View File

@ -131,9 +131,9 @@ public:
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 );

View File

@ -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;
@ -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;

View File

@ -74,9 +74,9 @@ public:
*/
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

View File

@ -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;
@ -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 )
aThreshold = GetPenSize() / 2;

View File

@ -65,9 +65,9 @@ public:
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;

View File

@ -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 );
}
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 )
aThreshold = 0;
wxPoint physicalpos = aTransform.TransformCoordinate( m_Pos );
wxPoint tmp = m_Pos;
m_Pos = physicalpos;
EDA_TEXT tmp_text( *this );
tmp_text.SetTextPosition( aTransform.TransformCoordinate( m_Pos ) );
/* The text orientation may need to be flipped if the
* transformation matrix causes xy axes to be flipped.
* this simple algo works only for schematic matrix (rot 90 or/and mirror)
*/
int t1 = ( aTransform.x1 != 0 ) ^ ( m_Orient != 0 );
int orient = t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT;
EXCHG( m_Orient, orient );
bool hit = TextHitTest( aPosition );
EXCHG( m_Orient, orient );
m_Pos = tmp;
return hit;
tmp_text.SetOrientation( t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT );
return tmp_text.TextHitTest( aPosition );
}

View File

@ -82,11 +82,11 @@ public:
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 );
}

View File

@ -210,7 +210,7 @@ public:
wxString GetSheetPath() const { return m_sheetPath; }
SCH_ITEM* GetParent() { return m_parent; }
SCH_ITEM* GetParent() const { return m_parent; }
};

View File

@ -148,7 +148,7 @@ public:
* Function GetParent
* @return the GERBVIEW_FRAME parent of this GERBER_IMAGE
*/
GERBVIEW_FRAME* GetParent()
GERBVIEW_FRAME* GetParent() const
{
return m_Parent;
}

View File

@ -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
wxPoint xyPos = aABPosition;
@ -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:
wxPoint ref_pos = GetXYPosition( 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 );

View File

@ -209,7 +209,7 @@ public:
* @param aABPosition = position in A,B plotter axis
* @return const wxPoint - The given position in X,Y axis.
*/
wxPoint GetXYPosition( const wxPoint& aABPosition );
wxPoint GetXYPosition( const wxPoint& aABPosition ) const;
/**
* Function GetDcodeDescr
@ -255,7 +255,7 @@ public:
* @param aRefPos a wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& aRefPos );
bool HitTest( const wxPoint& aRefPos ) const;
/**
* Function HitTest (overloaded)
@ -264,7 +264,7 @@ public:
* @param aRefArea a wxPoint to test
* @return bool - true if a hit, else false
*/
bool HitTest( EDA_RECT& aRefArea );
bool HitTest( const EDA_RECT& aRefArea ) const;
/**
* Function GetClass

View File

@ -456,14 +456,10 @@ public:
* Function HitTest
* 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.
* @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
}

View File

@ -254,7 +254,7 @@ public:
*/
wxString GetLayerName() const;
virtual bool HitTest( const wxPoint& aPosition )
virtual bool HitTest( const wxPoint& aPosition ) const
{
return EDA_ITEM::HitTest( aPosition );
}

View File

@ -123,7 +123,7 @@ public:
BASE_SCREEN* GetScreen();
EDA_DRAW_FRAME* GetParent();
EDA_DRAW_FRAME* GetParent() const;
void OnPaint( wxPaintEvent& event );

View File

@ -291,7 +291,10 @@ public:
bool IsConnected( const wxPoint& aPoint ) const;
/** @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

View File

@ -59,7 +59,7 @@ public:
EDA_COLOR_T GetColor() const { return m_color; }
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
*/
@ -69,7 +69,7 @@ public:
* Abstract function: should exist for derived items
* 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
@ -124,7 +124,7 @@ public:
* Virtual function
* 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.
@ -174,7 +174,7 @@ public:
* Virtual function
* 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.
@ -202,7 +202,7 @@ public:
* Virtual function
* 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.
@ -239,7 +239,7 @@ public:
* Virtual function
* 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.
@ -274,7 +274,7 @@ public:
* Virtual function
* 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.

View File

@ -17,7 +17,7 @@ private:
public:
TREE_PROJECT_FRAME* GetParent()
TREE_PROJECT_FRAME* GetParent() const
{
return m_Parent;
}

View File

@ -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 ) )
return true;

View File

@ -127,7 +127,7 @@ public:
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,
* bool aContained = true, int aAccuracy ) const

View File

@ -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 )
{

View File

@ -178,7 +178,7 @@ public:
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,
* bool aContained = true, int aAccuracy ) const

View File

@ -64,7 +64,7 @@ public:
const wxPoint& GetPosition() const { return m_Pos; }
void SetPosition( const wxPoint& aPos ) { m_Pos = aPos; }
bool HitTest( const wxPoint& aPosition )
bool HitTest( const wxPoint& aPosition ) const
{
return HitTestMarker( aPosition );
}

View File

@ -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 dY = aPosition.y - m_Pos.y;

View File

@ -82,7 +82,7 @@ public:
void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
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,
* bool aContained = true, int aAccuracy ) const

View File

@ -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 ) )
return true;

View File

@ -324,7 +324,7 @@ public:
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,
* bool aContained = true, int aAccuracy ) const

View File

@ -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;

View File

@ -341,7 +341,7 @@ public:
* Function GetBoundingRadius
* 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
// m_boundingRadius to -1 to re-trigger the calculation from here.
@ -368,7 +368,7 @@ public:
bool IsOnLayer( LAYER_NUM aLayer ) const;
bool HitTest( const wxPoint& aPosition );
bool HitTest( const wxPoint& aPosition ) const;
wxString GetClass() const
{
@ -450,7 +450,8 @@ private:
*/
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
/// comparisons because this is faster than string comparison)

View File

@ -76,7 +76,7 @@ public:
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
bool HitTest( const wxPoint& aPosition )
bool HitTest( const wxPoint& aPosition ) const
{
return TextHitTest( aPosition );
}

View File

@ -163,7 +163,7 @@ void TEXTE_MODULE::SetLocalCoord()
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;
EDA_RECT area = GetTextBox( -1, -1 );
@ -455,6 +455,9 @@ void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const
case LAYER_N_FRONT:
aLayers[0] = ITEM_GAL_LAYER( MOD_TEXT_FR_VISIBLE ); // how about SILKSCREEN_N_FRONT?
break;
default:
wxFAIL_MSG( wxT( "Can't tell text layer" ) );
}
break;
}

View File

@ -148,7 +148,7 @@ public:
void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
bool HitTest( const wxPoint& aPosition );
bool HitTest( const wxPoint& aPosition ) const;
wxString GetClass() const
{

View File

@ -1236,7 +1236,7 @@ bool TRACK::HitTest( const wxPoint& aPosition )
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;

View File

@ -401,7 +401,7 @@ public:
const wxPoint& GetPosition() const { return m_Start; } // 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;

View File

@ -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;
if( HitTestForEdge( aPosition ) )
if( HitTestForEdge( aPosition ) >= 0 )
return true;
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
// we must have a default distance between the test point
// and a corner or a zone edge:
#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 );
m_CornerSelection = m_Poly->HitTestForCorner( refPos, distmax );
return m_CornerSelection >= 0;
return m_Poly->HitTestForCorner( refPos, distmax );
}
bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
int ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) const
{
int distmax = Millimeter2iu( MAX_DIST_IN_MM );
m_CornerSelection = m_Poly->HitTestForEdge( refPos, distmax );
return m_CornerSelection >= 0;
return m_Poly->HitTestForEdge( refPos, distmax );
}
@ -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:
SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
SetCornerPosition( aEdge, GetCornerPosition( aEdge ) + offset );
// 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 );
ii = m_Poly->GetContourStart( icont );
int icont = m_Poly->GetContour( aEdge );
aEdge = m_Poly->GetContourStart( icont );
}
else
{
ii++;
aEdge++;
}
SetCornerPosition( ii, GetCornerPosition( ii ) + offset );
SetCornerPosition( aEdge, GetCornerPosition( aEdge ) + offset );
m_Poly->Hatch();
}

View File

@ -217,6 +217,10 @@ public:
int GetSelectedCorner() const { return m_CornerSelection; }
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; }
void SetLocalFlags( int aFlags ) { m_localFlgs = aFlags; }
@ -234,7 +238,7 @@ public:
* @param aRefPos A wxPoint to test
* @return bool - true if a hit, else false
*/
virtual bool HitTest( const wxPoint& aPosition );
virtual bool HitTest( const wxPoint& aPosition ) const;
/**
* Function HitTest
@ -342,7 +346,7 @@ public:
* @return true if found
* @param refPos : A wxPoint to test
*/
bool HitTestForCorner( const wxPoint& refPos );
int HitTestForCorner( const wxPoint& refPos ) const;
/**
* Function HitTestForEdge
@ -351,7 +355,7 @@ public:
* @return true if found
* @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,
* bool aContained = true, int aAccuracy ) const
@ -400,10 +404,11 @@ public:
/**
* 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 aEdge = start point of the outline edge
*/
void MoveEdge( const wxPoint& offset );
void MoveEdge( const wxPoint& offset, int aEdge );
/**
* Function Rotate

View File

@ -35,6 +35,7 @@
#include <pcbnew_id.h>
#include <class_board.h>
#include <class_module.h>
#include <class_zone.h>
#include <pcbnew.h>
#include <protos.h>
@ -160,8 +161,9 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode )
(*m_Collector)[i]->Show( 0, std::cout );
#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)
* Trigger the selection of the current edge for new-style zones
*/
time_t timestampzone = 0;
@ -169,18 +171,32 @@ BOARD_ITEM* PCB_BASE_FRAME::PcbGeneralLocateAndDisplay( int aHotKeyCode )
{
item = (*m_Collector)[ii];
if( item->Type() != PCB_ZONE_T )
continue;
switch( item->Type() )
{
case PCB_ZONE_T:
// Found a TYPE ZONE
if( item->GetTimeStamp() == timestampzone ) // Remove it, redundant, zone already found
{
m_Collector->Remove( ii );
ii--;
}
else
{
timestampzone = item->GetTimeStamp();
}
break;
// Found a TYPE ZONE
if( item->GetTimeStamp() == timestampzone ) // Remove it, redundant, zone already found
{
m_Collector->Remove( ii );
ii--;
}
else
{
timestampzone = item->GetTimeStamp();
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;
}
}

View File

@ -16,7 +16,7 @@ public:
void OnOkClick( 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:
void OnMiddleBtnPanEnbl( wxCommandEvent& event )

View File

@ -2234,6 +2234,8 @@ void EAGLE_PLUGIN::packageCircle( MODULE* aModule, CPTREE& aTree ) const
case ECO1_N: layer = SILKSCREEN_N_FRONT; break;
case ECO2_N: layer = SILKSCREEN_N_BACK; break;
*/
default:
break;
}
gr->SetLayer( layer );

View File

@ -661,14 +661,14 @@ void PCB_EDIT_FRAME::createPopUpMenuForZones( ZONE_CONTAINER* edge_zone, wxMenu*
edge_zone->GetIsKeepout() ? _("Keepout Area") : _( "Zones" ),
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,
_( "Move Corner" ), KiBitmap( move_xpm ) );
AddMenuItem( zones_menu, ID_POPUP_PCB_DELETE_ZONE_CORNER,
_( "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,
_( "Create Corner" ), KiBitmap( add_corner_xpm ) );

View File

@ -401,9 +401,9 @@ struct hitVisitor
{
PNS_ITEMSET& m_items;
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 ) {};
bool operator()( PNS_ITEM* aItem )
@ -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;
// fixme: we treat a point as an infinitely small circle - this is inefficient.

View File

@ -140,7 +140,7 @@ public:
int aKindMask = PNS_ITEM::ANY );
///> Hit detection
const PNS_ITEMSET HitTest( const VECTOR2I& aPoint );
const PNS_ITEMSET HitTest( const VECTOR2I& aPoint ) const;
void Add( PNS_ITEM* aItem );
void Remove( PNS_ITEM* aItem );

View File

@ -433,9 +433,9 @@ void Abort_Zone_Move_Corner_Or_Outlines( EDA_DRAW_PANEL* Panel, wxDC* DC )
}
else if( zone->IsDragging() )
{
wxPoint offset;
offset = s_CornerInitialPosition - s_CursorLastPosition;
zone->MoveEdge( offset );
wxPoint offset = s_CornerInitialPosition - s_CursorLastPosition;
int selection = zone->GetSelectedCorner();
zone->MoveEdge( offset, selection );
}
else
{
@ -485,9 +485,9 @@ void Show_Zone_Corner_Or_Outline_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC*
}
else if( zone->IsDragging() )
{
wxPoint offset;
offset = pos - s_CursorLastPosition;
zone->MoveEdge( offset );
wxPoint offset = pos - s_CursorLastPosition;
int selection = zone->GetSelectedCorner();
zone->MoveEdge( offset, selection );
s_CursorLastPosition = pos;
}
else

View File

@ -96,7 +96,7 @@ bool TestPointInsidePolygon( const CPOLYGONS_LIST& aPolysList,
/* Function TestPointInsidePolygon (overlaid)
* 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
int ics, ice;

View File

@ -34,6 +34,6 @@ bool TestPointInsidePolygon( const CPOLYGONS_LIST& aPolysList,
* @param aRefPoint: the point coordinate to test
* @return true if the point is inside, false for outside
*/
bool TestPointInsidePolygon( wxPoint* aPolysList,
bool TestPointInsidePolygon( const wxPoint* aPolysList,
int aCount,
wxPoint aRefPoint );
const wxPoint &aRefPoint );