Constant-size page layout object handles w/respect to zoom.
Fixes: lp:1787491 * https://bugs.launchpad.net/kicad/+bug/1787491
This commit is contained in:
parent
86a801aabc
commit
a6d10d6e28
|
@ -101,7 +101,7 @@ void WS_DRAW_ITEM_LIST::Draw( EDA_RECT* aClipBox, wxDC* aDC )
|
||||||
}
|
}
|
||||||
|
|
||||||
// The selected items are drawn after (usually 0 or 1)
|
// The selected items are drawn after (usually 0 or 1)
|
||||||
int markerSize = WORKSHEET_DATAITEM::GetMarkerSizeUi();
|
int markerSize = WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC );
|
||||||
|
|
||||||
for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() )
|
for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() )
|
||||||
{
|
{
|
||||||
|
@ -210,12 +210,12 @@ bool WS_DRAW_ITEM_TEXT::HitTest( const EDA_RECT& aRect ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool WS_DRAW_ITEM_TEXT::HitTestStartPoint( const wxPoint& aPosition)
|
bool WS_DRAW_ITEM_TEXT::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||||
{
|
{
|
||||||
wxPoint pos = GetTextPos();
|
wxPoint pos = GetTextPos();
|
||||||
|
|
||||||
if( std::abs( pos.x - aPosition.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 &&
|
if( std::abs( pos.x - aPosition.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 &&
|
||||||
std::abs( pos.y - aPosition.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 )
|
std::abs( pos.y - aPosition.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -276,12 +276,12 @@ bool WS_DRAW_ITEM_POLYGON::HitTest( const EDA_RECT& aRect ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool WS_DRAW_ITEM_POLYGON::HitTestStartPoint( const wxPoint& aPosition)
|
bool WS_DRAW_ITEM_POLYGON::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||||
{
|
{
|
||||||
wxPoint pos = GetPosition();
|
wxPoint pos = GetPosition();
|
||||||
|
|
||||||
if( std::abs( pos.x - aPosition.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 &&
|
if( std::abs( pos.x - aPosition.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 &&
|
||||||
std::abs( pos.y - aPosition.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 )
|
std::abs( pos.y - aPosition.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -368,25 +368,25 @@ bool WS_DRAW_ITEM_RECT::HitTest( const EDA_RECT& aRect ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool WS_DRAW_ITEM_RECT::HitTestStartPoint( const wxPoint& aPosition)
|
bool WS_DRAW_ITEM_RECT::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||||
{
|
{
|
||||||
wxPoint dist = GetStart() - aPosition;
|
wxPoint dist = GetStart() - aPosition;
|
||||||
|
|
||||||
if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 &&
|
if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 &&
|
||||||
std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 )
|
std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool WS_DRAW_ITEM_RECT::HitTestEndPoint( const wxPoint& aPosition)
|
bool WS_DRAW_ITEM_RECT::HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||||
{
|
{
|
||||||
wxPoint pos = GetEnd();
|
wxPoint pos = GetEnd();
|
||||||
|
|
||||||
int dist = (int) hypot( pos.x - aPosition.x, pos.y - aPosition.y );
|
int dist = (int) hypot( pos.x - aPosition.x, pos.y - aPosition.y );
|
||||||
|
|
||||||
if( dist <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 )
|
if( dist <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -416,45 +416,45 @@ bool WS_DRAW_ITEM_LINE::HitTest( const EDA_RECT& aRect ) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool WS_DRAW_ITEM_LINE::HitTestStartPoint( const wxPoint& aPosition)
|
bool WS_DRAW_ITEM_LINE::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||||
{
|
{
|
||||||
wxPoint dist = GetStart() - aPosition;
|
wxPoint dist = GetStart() - aPosition;
|
||||||
|
|
||||||
if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 &&
|
if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 &&
|
||||||
std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 )
|
std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool WS_DRAW_ITEM_LINE::HitTestEndPoint( const wxPoint& aPosition)
|
bool WS_DRAW_ITEM_LINE::HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||||
{
|
{
|
||||||
wxPoint dist = GetEnd() - aPosition;
|
wxPoint dist = GetEnd() - aPosition;
|
||||||
|
|
||||||
if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 &&
|
if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 &&
|
||||||
std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 )
|
std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WS_DRAW_ITEM_LIST::Locate( std::vector <WS_DRAW_ITEM_BASE*>& aList,
|
void WS_DRAW_ITEM_LIST::Locate( wxDC* aDC, std::vector <WS_DRAW_ITEM_BASE*>& aList,
|
||||||
const wxPoint& aPosition)
|
const wxPoint& aPosition )
|
||||||
{
|
{
|
||||||
for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() )
|
for( WS_DRAW_ITEM_BASE* item = GetFirst(); item; item = GetNext() )
|
||||||
{
|
{
|
||||||
item->m_Flags &= ~(LOCATE_STARTPOINT|LOCATE_ENDPOINT);
|
item->m_Flags &= ~(LOCATE_STARTPOINT|LOCATE_ENDPOINT);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
if( item->HitTestStartPoint ( aPosition ) )
|
if( item->HitTestStartPoint ( aDC, aPosition ) )
|
||||||
{
|
{
|
||||||
item->m_Flags |= LOCATE_STARTPOINT;
|
item->m_Flags |= LOCATE_STARTPOINT;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( item->HitTestEndPoint ( aPosition ) )
|
if( item->HitTestEndPoint ( aDC, aPosition ) )
|
||||||
{
|
{
|
||||||
item->m_Flags |= LOCATE_ENDPOINT;
|
item->m_Flags |= LOCATE_ENDPOINT;
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -511,12 +511,12 @@ bool WS_DRAW_ITEM_BITMAP::HitTest( const EDA_RECT& aRect ) 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.
|
||||||
*/
|
*/
|
||||||
bool WS_DRAW_ITEM_BITMAP::HitTestStartPoint( const wxPoint& aPosition)
|
bool WS_DRAW_ITEM_BITMAP::HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition )
|
||||||
{
|
{
|
||||||
wxPoint dist = m_pos - aPosition;
|
wxPoint dist = m_pos - aPosition;
|
||||||
|
|
||||||
if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 &&
|
if( std::abs( dist.x) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 &&
|
||||||
std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi()/2 )
|
std::abs( dist.y) <= WORKSHEET_DATAITEM::GetMarkerSizeUi( aDC ) / 2 )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -205,9 +205,15 @@ public:
|
||||||
return KiROUND( m_DefaultLineWidth * m_WSunits2Iu );
|
return KiROUND( m_DefaultLineWidth * m_WSunits2Iu );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetMarkerSizeUi()
|
static int GetMarkerSizeUi( wxDC* aDC )
|
||||||
{
|
{
|
||||||
return KiROUND( 0.5 * m_WSunits2Iu );
|
double x, y;
|
||||||
|
double scale;
|
||||||
|
|
||||||
|
aDC->GetUserScale( &x, &y );
|
||||||
|
scale = (x + y ) / 2; // should be equal, but if not best we can do is average
|
||||||
|
|
||||||
|
return KiROUND( 0.01 * m_WSunits2Iu / scale );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -119,7 +119,7 @@ public:
|
||||||
* (texts or polygons)
|
* (texts or polygons)
|
||||||
* the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2
|
* the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2
|
||||||
*/
|
*/
|
||||||
virtual bool HitTestStartPoint( const wxPoint& aPosition) = 0;
|
virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return true if the point aPosition is near the ending point of this item
|
* return true if the point aPosition is near the ending point of this item
|
||||||
|
@ -127,7 +127,7 @@ public:
|
||||||
* 2 points
|
* 2 points
|
||||||
* the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2
|
* the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2
|
||||||
*/
|
*/
|
||||||
virtual bool HitTestEndPoint( const wxPoint& aPosition)
|
virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -176,14 +176,14 @@ public:
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
virtual bool HitTestStartPoint( const wxPoint& aPosition) override;
|
virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return true if the point aPosition is on the ending point of this item
|
* return true if the point aPosition is on the ending point of this item
|
||||||
* This is avirtual function which should be overriden for items defien by
|
* This is avirtual function which should be overriden for items defien by
|
||||||
* 2 points
|
* 2 points
|
||||||
*/
|
*/
|
||||||
virtual bool HitTestEndPoint( const wxPoint& aPosition) override;
|
virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class draws a polygon
|
// This class draws a polygon
|
||||||
|
@ -233,7 +233,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
virtual bool HitTestStartPoint( const wxPoint& aPosition) override;
|
virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class draws a not filled rectangle with thick segment
|
// This class draws a not filled rectangle with thick segment
|
||||||
|
@ -268,14 +268,14 @@ public:
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
virtual bool HitTestStartPoint( const wxPoint& aPosition) override;
|
virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return true if the point aPosition is on the ending point of this item
|
* return true if the point aPosition is on the ending point of this item
|
||||||
* This is avirtual function which should be overriden for items defien by
|
* This is avirtual function which should be overriden for items defien by
|
||||||
* 2 points
|
* 2 points
|
||||||
*/
|
*/
|
||||||
virtual bool HitTestEndPoint( const wxPoint& aPosition) override;
|
virtual bool HitTestEndPoint( wxDC *aDC, const wxPoint& aPosition ) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class draws a graphic text.
|
// This class draws a graphic text.
|
||||||
|
@ -317,7 +317,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
virtual bool HitTestStartPoint( const wxPoint& aPosition) override;
|
virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class draws a bitmap.
|
// This class draws a bitmap.
|
||||||
|
@ -359,7 +359,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
virtual bool HitTestStartPoint( const wxPoint& aPosition) override;
|
virtual bool HitTestStartPoint( wxDC *aDC, const wxPoint& aPosition ) override;
|
||||||
|
|
||||||
const wxPoint GetPosition() const { return m_pos; }
|
const wxPoint GetPosition() const { return m_pos; }
|
||||||
};
|
};
|
||||||
|
@ -592,7 +592,7 @@ public:
|
||||||
* @param aList = the list of items found
|
* @param aList = the list of items found
|
||||||
* @param aPosition the position (in user units) to locate items
|
* @param aPosition the position (in user units) to locate items
|
||||||
*/
|
*/
|
||||||
void Locate(std::vector <WS_DRAW_ITEM_BASE*>& aList, const wxPoint& aPosition);
|
void Locate(wxDC* aDC, std::vector <WS_DRAW_ITEM_BASE*>& aList, const wxPoint& aPosition);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -267,7 +267,7 @@ bool PL_EDITOR_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode,
|
||||||
if( busy )
|
if( busy )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if( (item = Locate( aPosition )) == NULL )
|
if( (item = Locate( aDC, aPosition ) ) == NULL )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Only rect and lines have a end point.
|
// Only rect and lines have a end point.
|
||||||
|
|
|
@ -55,7 +55,7 @@ void PL_EDITOR_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
|
||||||
}
|
}
|
||||||
|
|
||||||
item = m_treePagelayout->GetPageLayoutSelectedItem();
|
item = m_treePagelayout->GetPageLayoutSelectedItem();
|
||||||
WORKSHEET_DATAITEM* newitem = Locate( aPosition );
|
WORKSHEET_DATAITEM* newitem = Locate( aDC, aPosition );
|
||||||
|
|
||||||
if( newitem == NULL )
|
if( newitem == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include <worksheet_shape_builder.h>
|
#include <worksheet_shape_builder.h>
|
||||||
#include <worksheet_dataitem.h>
|
#include <worksheet_dataitem.h>
|
||||||
#include <hotkeys.h>
|
#include <hotkeys.h>
|
||||||
|
#include <kicad_device_context.h>
|
||||||
|
|
||||||
// Helper function to add menuitems relative to items creation
|
// Helper function to add menuitems relative to items creation
|
||||||
void AddNewItemsCommand( wxMenu* aMainMenu )
|
void AddNewItemsCommand( wxMenu* aMainMenu )
|
||||||
|
@ -83,8 +84,9 @@ bool PL_EDITOR_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* aPopMenu )
|
||||||
|
|
||||||
if( ! busy ) // No item currently edited
|
if( ! busy ) // No item currently edited
|
||||||
{
|
{
|
||||||
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
||||||
WORKSHEET_DATAITEM* old_item = m_treePagelayout->GetPageLayoutSelectedItem();
|
WORKSHEET_DATAITEM* old_item = m_treePagelayout->GetPageLayoutSelectedItem();
|
||||||
WORKSHEET_DATAITEM* item = Locate( aPosition );
|
WORKSHEET_DATAITEM* item = Locate( &dc, aPosition );
|
||||||
|
|
||||||
if( item && old_item != item )
|
if( item && old_item != item )
|
||||||
{
|
{
|
||||||
|
|
|
@ -600,7 +600,7 @@ WORKSHEET_DATAITEM * PL_EDITOR_FRAME::GetSelectedItem()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( const wxPoint& aPosition )
|
WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( wxDC* aDC, const wxPoint& aPosition )
|
||||||
{
|
{
|
||||||
const PAGE_INFO& pageInfo = GetPageSettings();
|
const PAGE_INFO& pageInfo = GetPageSettings();
|
||||||
TITLE_BLOCK t_block = GetTitleBlock();
|
TITLE_BLOCK t_block = GetTitleBlock();
|
||||||
|
@ -625,7 +625,7 @@ WORKSHEET_DATAITEM* PL_EDITOR_FRAME::Locate( const wxPoint& aPosition )
|
||||||
// We do not use here the COLLECTOR classes in use in pcbnew and eeschema
|
// We do not use here the COLLECTOR classes in use in pcbnew and eeschema
|
||||||
// because the locate requirements are very basic.
|
// because the locate requirements are very basic.
|
||||||
std::vector <WS_DRAW_ITEM_BASE*> list;
|
std::vector <WS_DRAW_ITEM_BASE*> list;
|
||||||
drawList.Locate( list, aPosition );
|
drawList.Locate( aDC, list, aPosition );
|
||||||
|
|
||||||
if( list.size() == 0 )
|
if( list.size() == 0 )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -358,7 +358,7 @@ public:
|
||||||
* @return the page layout item found at position aPosition
|
* @return the page layout item found at position aPosition
|
||||||
* @param aPosition = the position (in user units) of the reference point
|
* @param aPosition = the position (in user units) of the reference point
|
||||||
*/
|
*/
|
||||||
WORKSHEET_DATAITEM *Locate( const wxPoint& aPosition );
|
WORKSHEET_DATAITEM *Locate( wxDC* aDC, const wxPoint& aPosition );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a move item command
|
* Initialize a move item command
|
||||||
|
|
Loading…
Reference in New Issue