Skip to content

Commit

Permalink
*) retain grid origin in the BOARD and save it in legacy and kicad bo…
Browse files Browse the repository at this point in the history
…ard files.

*) add hotkey for setting the grid origin as 'S', in board editor, module editor.
*) re-position the function interface for cursor movement from BASE_SCREEN into
   class EDA_DRAW_FRAME.  This is a prelude to getting rid of BASE_SCREEN or
   splitting it up.
  • Loading branch information
liftoff-sr committed Aug 3, 2013
1 parent 744dd80 commit efb3416
Show file tree
Hide file tree
Showing 100 changed files with 1,366 additions and 1,174 deletions.
26 changes: 13 additions & 13 deletions common/base_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,44 +288,44 @@ GRID_TYPE& BASE_SCREEN::GetGrid( size_t aIndex )
}


wxPoint BASE_SCREEN::GetNearestGridPosition( const wxPoint& aPosition,
wxRealPoint* aGridSize ) const
wxPoint BASE_SCREEN::getNearestGridPosition( const wxPoint& aPosition,
const wxPoint& aGridOrigin, wxRealPoint* aGridSize ) const
{
wxPoint pt;
wxPoint pt;
wxRealPoint gridSize;

if( aGridSize )
gridSize = *aGridSize;
else
gridSize = GetGridSize();

wxPoint gridOrigin = m_GridOrigin;

double offset = fmod( gridOrigin.x, gridSize.x );
double offset = fmod( aGridOrigin.x, gridSize.x );
int x = KiROUND( (aPosition.x - offset) / gridSize.x );

pt.x = KiROUND( x * gridSize.x + offset );

offset = fmod( gridOrigin.y, gridSize.y );
offset = fmod( aGridOrigin.y, gridSize.y );

int y = KiROUND( (aPosition.y - offset) / gridSize.y );
pt.y = KiROUND ( y * gridSize.y + offset );

return pt;
}


wxPoint BASE_SCREEN::GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize ) const
wxPoint BASE_SCREEN::getCursorPosition( bool aOnGrid, const wxPoint& aGridOrigin, wxRealPoint* aGridSize ) const
{
if( aOnGrid )
return GetNearestGridPosition( m_crossHairPosition, aGridSize );
return getNearestGridPosition( m_crossHairPosition, aGridOrigin, aGridSize );

return m_crossHairPosition;
}


wxPoint BASE_SCREEN::GetCrossHairScreenPosition() const
wxPoint BASE_SCREEN::getCrossHairScreenPosition() const
{
wxPoint pos = m_crossHairPosition - m_DrawOrg;
double scalar = GetScalingFactor();
double scalar = GetScalingFactor();

pos.x = KiROUND( (double) pos.x * scalar );
pos.y = KiROUND( (double) pos.y * scalar );
Expand All @@ -334,10 +334,10 @@ wxPoint BASE_SCREEN::GetCrossHairScreenPosition() const
}


void BASE_SCREEN::SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGrid )
void BASE_SCREEN::setCrossHairPosition( const wxPoint& aPosition, const wxPoint& aGridOrigin, bool aSnapToGrid )
{
if( aSnapToGrid )
m_crossHairPosition = GetNearestGridPosition( aPosition );
m_crossHairPosition = getNearestGridPosition( aPosition, aGridOrigin );
else
m_crossHairPosition = aPosition;
}
Expand Down
23 changes: 9 additions & 14 deletions common/base_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* depending on the application.
*/

#include <macros.h>
#include <base_struct.h>
#include <class_title_block.h>
#include <common.h>
Expand Down Expand Up @@ -187,7 +188,7 @@ void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )


/* Convert a value to a string using double notation.
* For readability, the mantissa has 3 or more digits (max 8 digits),
* For readability, the mantissa has 3 or more digits,
* the trailing 0 are removed if the mantissa has more than 3 digits
* and some trailing 0
* This function should be used to display values in dialogs because a value
Expand All @@ -198,23 +199,19 @@ void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
*/
wxString ReturnStringFromValue( EDA_UNITS_T aUnit, int aValue, bool aAddUnitSymbol )
{
wxString stringValue;
double value_to_print;

value_to_print = To_User_Unit( aUnit, aValue );
double value_to_print = To_User_Unit( aUnit, aValue );

#if defined( EESCHEMA )
stringValue.Printf( wxT( "%.3f" ), value_to_print );
#else
#if defined( USE_PCBNEW_NANOMETRES )
stringValue.Printf( wxT( "%.8f" ), value_to_print );
#else
stringValue.Printf( wxT( "%.4f" ), value_to_print );
#endif
wxString stringValue = wxString::Format( wxT( "%.3f" ), value_to_print );

// Strip trailing zeros. However, keep at least 3 digits in mantissa
// For readability
StripTrailingZeros( stringValue, 3 );

#else
std::string s = Double2Str( value_to_print );
wxString stringValue = FROM_UTF8( s.c_str() );

#endif

if( aAddUnitSymbol )
Expand Down Expand Up @@ -269,8 +266,6 @@ double From_User_Unit( EDA_UNITS_T aUnit, double aValue )
}




int ReturnValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue )
{
double value;
Expand Down
36 changes: 18 additions & 18 deletions common/block_commande.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
BLOCK_SELECTOR::BLOCK_SELECTOR() :
EDA_RECT()
{
m_state = STATE_NO_BLOCK; /* State (enum BLOCK_STATE_T) of block. */
m_command = BLOCK_IDLE; /* Type (enum BLOCK_COMMAND_T) of operation. */
m_state = STATE_NO_BLOCK; // State (enum BLOCK_STATE_T) of block.
m_command = BLOCK_IDLE; // Type (enum BLOCK_COMMAND_T) of operation.
m_color = BROWN;
}

Expand All @@ -62,45 +62,45 @@ void BLOCK_SELECTOR::SetMessageBlock( EDA_DRAW_FRAME* frame )
case BLOCK_IDLE:
break;

case BLOCK_MOVE: /* Move */
case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/
case BLOCK_MOVE: // Move
case BLOCK_PRESELECT_MOVE: // Move with preselection list
msg = _( "Block Move" );
break;

case BLOCK_DRAG: /* Drag */
case BLOCK_DRAG: // Drag
msg = _( "Block Drag" );
break;

case BLOCK_COPY: /* Copy */
case BLOCK_COPY: // Copy
msg = _( "Block Copy" );
break;

case BLOCK_DELETE: /* Delete */
case BLOCK_DELETE: // Delete
msg = _( "Block Delete" );
break;

case BLOCK_SAVE: /* Save */
case BLOCK_SAVE: // Save
msg = _( "Block Save" );
break;

case BLOCK_PASTE:
msg = _( "Block Paste" );
break;

case BLOCK_ZOOM: /* Window Zoom */
case BLOCK_ZOOM: // Window Zoom
msg = _( "Win Zoom" );
break;

case BLOCK_ROTATE: /* Rotate 90 deg */
case BLOCK_ROTATE: // Rotate 90 deg
msg = _( "Block Rotate" );
break;

case BLOCK_FLIP: /* Flip */
case BLOCK_FLIP: // Flip
msg = _( "Block Flip" );
break;

case BLOCK_MIRROR_X:
case BLOCK_MIRROR_Y: /* mirror */
case BLOCK_MIRROR_Y: // mirror
msg = _( "Block Mirror" );
break;

Expand Down Expand Up @@ -185,15 +185,15 @@ void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoin
if( aErase )
block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );

block->SetLastCursorPosition( aPanel->GetScreen()->GetCrossHairPosition() );
block->SetEnd( aPanel->GetScreen()->GetCrossHairPosition() );
block->SetLastCursorPosition( aPanel->GetParent()->GetCrossHairPosition() );
block->SetEnd( aPanel->GetParent()->GetCrossHairPosition() );

block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );

if( block->GetState() == STATE_BLOCK_INIT )
{
if( block->GetWidth() || block->GetHeight() )
/* 2nd point exists: the rectangle is not surface anywhere */
// 2nd point exists: the rectangle is not surface anywhere
block->SetState( STATE_BLOCK_END );
}
}
Expand All @@ -203,14 +203,14 @@ void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
{
BASE_SCREEN* screen = aPanel->GetScreen();

if( aPanel->IsMouseCaptured() ) /* Erase current drawing on screen */
if( aPanel->IsMouseCaptured() ) // Erase current drawing on screen
{
/* Clear block outline. */
// Clear block outline.
aPanel->CallMouseCapture( aDC, wxDefaultPosition, false );
aPanel->SetMouseCapture( NULL, NULL );
screen->SetCurItem( NULL );

/* Delete the picked wrapper if this is a picked list. */
// Delete the picked wrapper if this is a picked list.
if( screen->m_BlockLocate.GetCommand() != BLOCK_PASTE )
screen->m_BlockLocate.ClearItemsList();
}
Expand Down
82 changes: 67 additions & 15 deletions common/drawframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,18 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* aParent,
m_snapToGrid = true;
m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight();


//#define ZOOM_DISPLAY_SIZE 60
//#define COORD_DISPLAY_SIZE 165
//#define DELTA_DISPLAY_SIZE 245
//#define UNITS_DISPLAY_SIZE 65
#define FUNCTION_DISPLAY_SIZE 110

CreateStatusBar( 6 );

// set the size of the status bar subwindows:

wxWindow* stsbar = GetStatusBar();


int dims[] = {

// balance of status bar on far left is set to a default or whatever is left over.
// remainder of status bar on far left is set to a default or whatever is left over.
-1,

// When using GetTextSize() remember the width of '1' is not the same
// When using GetTextSize() remember the width of character '1' is not the same
// as the width of '0' unless the font is fixed width, and it usually won't be.

// zoom:
Expand All @@ -148,7 +140,9 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* aParent,
// units display, Inches is bigger than mm
GetTextSize( _( "Inches" ), stsbar ).x + 10,

FUNCTION_DISPLAY_SIZE,
// Size for the panel used as "Current tool in play": will take longest string from
// void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) in pcbnew/edit.cpp
GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
};

SetStatusWidths( DIM( dims ), dims );
Expand Down Expand Up @@ -381,7 +375,7 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
*/
m_LastGridSizeId = id - ID_POPUP_GRID_LEVEL_1000;
screen->SetGrid( id );
screen->SetCrossHairPosition( screen->RefPos( true ) );
SetCrossHairPosition( RefPos( true ) );
Refresh();
}

Expand Down Expand Up @@ -409,7 +403,7 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
return;

GetScreen()->SetZoom( selectedZoom );
RedrawScreen( GetScreen()->GetScrollCenterPosition(), false );
RedrawScreen( GetScrollCenterPosition(), false );
}
}

Expand Down Expand Up @@ -495,7 +489,7 @@ wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const
wxPoint pos = aPosition;

if( m_currentScreen != NULL && m_snapToGrid )
pos = m_currentScreen->GetNearestGridPosition( aPosition );
pos = GetNearestGridPosition( aPosition );

return pos;
}
Expand Down Expand Up @@ -878,7 +872,7 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )

// Calculate the scroll bar position in internal units to place the
// center position at the center of client rectangle.
screen->SetScrollCenterPosition( centerPositionIU );
SetScrollCenterPosition( centerPositionIU );

double posX = centerPositionIU.x - clientRectIU.width /2.0 - screen->m_DrawOrg.x;
double posY = centerPositionIU.y - clientRectIU.height/2.0 - screen->m_DrawOrg.y;
Expand Down Expand Up @@ -931,3 +925,61 @@ void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
screen->m_ScrollbarPos.x,
screen->m_ScrollbarPos.y, noRefresh );
}

//-----< BASE_SCREEN API moved here >--------------------------------------------

wxPoint EDA_DRAW_FRAME::GetCrossHairPosition( bool aInvertY ) const
{
return GetScreen()->getCrossHairPosition();
}


void EDA_DRAW_FRAME::SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGrid )
{
GetScreen()->setCrossHairPosition( aPosition, GetGridOrigin(), aSnapToGrid );
}


wxPoint EDA_DRAW_FRAME::GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize ) const
{
return GetScreen()->getCursorPosition( aOnGrid, GetGridOrigin(), aGridSize );
}


wxPoint EDA_DRAW_FRAME::GetNearestGridPosition( const wxPoint& aPosition, wxRealPoint* aGridSize ) const
{
return GetScreen()->getNearestGridPosition( aPosition, GetGridOrigin(), aGridSize );
}


wxPoint EDA_DRAW_FRAME::GetCrossHairScreenPosition() const
{
return GetScreen()->getCrossHairScreenPosition();
}


void EDA_DRAW_FRAME::SetMousePosition( const wxPoint& aPosition )
{
GetScreen()->setMousePosition( aPosition );
}


wxPoint EDA_DRAW_FRAME::RefPos( bool useMouse ) const
{
return GetScreen()->refPos( useMouse );
}


const wxPoint& EDA_DRAW_FRAME::GetScrollCenterPosition() const
{
return GetScreen()->getScrollCenterPosition();
}


void EDA_DRAW_FRAME::SetScrollCenterPosition( const wxPoint& aPoint )
{
GetScreen()->setScrollCenterPosition( aPoint );
}

//-----</BASE_SCREEN API moved here >--------------------------------------------

Loading

0 comments on commit efb3416

Please sign in to comment.