Add Set/GetOrientationDegrees and GetOrientationRadians for texts, pads and footprints to avoid internal units to usual angle units conversion in code (and avoid mistakes).
It should help if (or when) the internal angle unit used in kicad will be changed from 0.1 degree (a relic of code written for PCs without fpu) to degree ( a more natural unit).
This commit is contained in:
parent
ce331b03e8
commit
e46f706d4b
|
@ -134,7 +134,10 @@ public:
|
|||
int GetThickness() const { return m_Thickness; };
|
||||
|
||||
void SetOrientation( double aOrientation );
|
||||
void SetOrientationDegrees( double aOrientation ) { SetOrientation( aOrientation*10.0 ); }
|
||||
double GetOrientation() const { return m_Orient; }
|
||||
double GetOrientationDegrees() const { return m_Orient/10.0; }
|
||||
double GetOrientationRadians() const { return m_Orient*M_PI/1800; }
|
||||
|
||||
void SetItalic( bool isItalic ) { m_Italic = isItalic; }
|
||||
bool IsItalic() const { return m_Italic; }
|
||||
|
|
|
@ -208,6 +208,7 @@ template <class T> inline void NORMALIZE_ANGLE_360( T &Angle )
|
|||
}
|
||||
|
||||
/// Normalize angle to be in the 0.0 .. 360.0 range:
|
||||
/// angle is in 1/10 degees
|
||||
template <class T> inline void NORMALIZE_ANGLE_POS( T &Angle )
|
||||
{
|
||||
while( Angle < 0 )
|
||||
|
@ -216,6 +217,16 @@ template <class T> inline void NORMALIZE_ANGLE_POS( T &Angle )
|
|||
Angle -= 3600;
|
||||
}
|
||||
|
||||
/// Normalize angle to be in the 0.0 .. 360.0 range:
|
||||
/// angle is in degrees
|
||||
inline void NORMALIZE_ANGLE_DEGREES_POS( double &Angle )
|
||||
{
|
||||
while( Angle < 0 )
|
||||
Angle += 360.0;
|
||||
while( Angle >= 360.0 )
|
||||
Angle -= 360.0;
|
||||
}
|
||||
|
||||
/// Add two angles (keeping the result normalized). T2 is here
|
||||
// because most of the time it's an int (and templates don't promote in
|
||||
// that way)
|
||||
|
|
|
@ -576,7 +576,9 @@ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
|
|||
// display schematic path
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Netlist Path" ), m_Path, BROWN ) );
|
||||
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Layer" ), GetLayerName(), RED ) );
|
||||
// display the board side placement
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Board Side" ),
|
||||
IsFlipped()? _( "Back (Flipped)" ) : _( "Front" ), RED ) );
|
||||
|
||||
EDA_ITEM* PtStruct = m_Pads;
|
||||
nbpad = 0;
|
||||
|
@ -600,8 +602,8 @@ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
|
|||
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Status" ), msg, MAGENTA ) );
|
||||
|
||||
msg.Printf( wxT( "%.1f" ), m_Orient / 10.0 );
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, BROWN ) );
|
||||
msg.Printf( wxT( "%.1f" ), GetOrientationDegrees() );
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Rotation" ), msg, BROWN ) );
|
||||
|
||||
// Controls on right side of the dialog
|
||||
switch( m_Attributs & 255 )
|
||||
|
|
|
@ -161,7 +161,10 @@ public:
|
|||
const wxPoint& GetPosition() const { return m_Pos; } // was overload
|
||||
|
||||
void SetOrientation( double newangle );
|
||||
void SetOrientationDegrees( double aOrientation ) { SetOrientation( aOrientation*10.0 ); }
|
||||
double GetOrientation() const { return m_Orient; }
|
||||
double GetOrientationDegrees() const { return m_Orient/10.0; }
|
||||
double GetOrientationRadians() const { return m_Orient*M_PI/1800; }
|
||||
|
||||
const FPID& GetFPID() const { return m_fpid; }
|
||||
void SetFPID( const FPID& aFPID ) { m_fpid = aFPID; }
|
||||
|
|
|
@ -676,14 +676,14 @@ void D_PAD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM>& aList )
|
|||
aList.push_back( MSG_PANEL_ITEM( _( "Drill X / Y" ), Line, RED ) );
|
||||
}
|
||||
|
||||
double module_orient = module ? module->GetOrientation() : 0;
|
||||
double module_orient_degrees = module ? module->GetOrientationDegrees() : 0;
|
||||
|
||||
if( module_orient )
|
||||
if( module_orient_degrees != 0.0 )
|
||||
Line.Printf( wxT( "%3.1f(+%3.1f)" ),
|
||||
( m_Orient - module_orient ) / 10.0,
|
||||
module_orient / 10.0 );
|
||||
GetOrientationDegrees() - module_orient_degrees,
|
||||
module_orient_degrees );
|
||||
else
|
||||
Line.Printf( wxT( "%3.1f" ), m_Orient / 10.0 );
|
||||
Line.Printf( wxT( "%3.1f" ), GetOrientationDegrees() );
|
||||
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), Line, LIGHTBLUE ) );
|
||||
|
||||
|
|
|
@ -198,11 +198,18 @@ public:
|
|||
*/
|
||||
void SetOrientation( double aAngle );
|
||||
|
||||
/**
|
||||
* Set orientation in degrees
|
||||
*/
|
||||
void SetOrientationDegrees( double aOrientation ) { SetOrientation( aOrientation*10.0 ); }
|
||||
|
||||
/**
|
||||
* Function GetOrientation
|
||||
* returns the rotation angle of the pad in tenths of degrees, but soon degrees.
|
||||
*/
|
||||
double GetOrientation() const { return m_Orient; }
|
||||
double GetOrientationDegrees() const { return m_Orient/10.0; }
|
||||
double GetOrientationRadians() const { return m_Orient*M_PI/1800; }
|
||||
|
||||
void SetDrillShape( PAD_DRILL_SHAPE_T aDrillShape )
|
||||
{ m_drillShape = aDrillShape; }
|
||||
|
|
|
@ -316,7 +316,7 @@ double TEXTE_MODULE::GetDrawRotation() const
|
|||
if( module )
|
||||
rotation += module->GetOrientation();
|
||||
|
||||
// For angle = -90 .. 90 deg
|
||||
// Keep angle between -90 .. 90 deg. Otherwise the text is not easy to read
|
||||
while( rotation > 900 )
|
||||
rotation -= 1800;
|
||||
|
||||
|
@ -368,7 +368,7 @@ void TEXTE_MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
|
|||
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), msg, DARKGREEN ) );
|
||||
|
||||
msg.Printf( wxT( "%.1f" ), m_Orient / 10.0 );
|
||||
msg.Printf( wxT( "%.1f" ), GetOrientationDegrees() );
|
||||
aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
|
||||
|
||||
msg = ::CoordinateToString( m_Thickness );
|
||||
|
|
|
@ -121,6 +121,7 @@ public:
|
|||
* the footprint rotation is taken in account
|
||||
*/
|
||||
double GetDrawRotation() const;
|
||||
double GetDrawRotationRadians() const { return GetDrawRotation() * M_PI/1800; }
|
||||
|
||||
// Virtual function
|
||||
const EDA_RECT GetBoundingBox() const;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version Jun 17 2015)
|
||||
// C++ code generated with wxFormBuilder (version May 2 2016)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO "NOT" EDIT THIS FILE!
|
||||
|
@ -16,11 +16,11 @@ DIALOG_SELECT_PRETTY_LIB_BASE::DIALOG_SELECT_PRETTY_LIB_BASE( wxWindow* parent,
|
|||
wxBoxSizer* bSizerMain;
|
||||
bSizerMain = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_staticText = new wxStaticText( this, wxID_ANY, _("The footprint library is a folder with a name ending with .pretty\nFootprints are .kicad_mod files inside this folder."), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_staticText->Wrap( -1 );
|
||||
m_staticText->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 92, false, wxEmptyString ) );
|
||||
m_messageInfo = new wxStaticText( this, wxID_ANY, _("The footprint library is a folder with a name ending with .pretty\nFootprints are .kicad_mod files inside this folder."), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_messageInfo->Wrap( -1 );
|
||||
m_messageInfo->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) );
|
||||
|
||||
bSizerMain->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
|
||||
bSizerMain->Add( m_messageInfo, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
|
||||
|
||||
m_staticText3 = new wxStaticText( this, wxID_ANY, _("Path base:"), wxDefaultPosition, wxDefaultSize, 0 );
|
||||
m_staticText3->Wrap( -1 );
|
||||
|
@ -56,7 +56,6 @@ DIALOG_SELECT_PRETTY_LIB_BASE::DIALOG_SELECT_PRETTY_LIB_BASE( wxWindow* parent,
|
|||
|
||||
this->SetSizer( bSizerMain );
|
||||
this->Layout();
|
||||
bSizerMain->Fit( this );
|
||||
|
||||
this->Centre( wxBOTH );
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
<property name="minimum_size">-1,-1</property>
|
||||
<property name="name">DIALOG_SELECT_PRETTY_LIB_BASE</property>
|
||||
<property name="pos"></property>
|
||||
<property name="size">-1,-1</property>
|
||||
<property name="size">401,206</property>
|
||||
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
|
||||
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
|
||||
<property name="title">Select Footprint Library Folder</property>
|
||||
|
@ -133,7 +133,7 @@
|
|||
<property name="minimize_button">0</property>
|
||||
<property name="minimum_size"></property>
|
||||
<property name="moveable">1</property>
|
||||
<property name="name">m_staticText</property>
|
||||
<property name="name">m_messageInfo</property>
|
||||
<property name="pane_border">1</property>
|
||||
<property name="pane_position"></property>
|
||||
<property name="pane_size"></property>
|
||||
|
@ -474,7 +474,7 @@
|
|||
<property name="max_size"></property>
|
||||
<property name="maximize_button">0</property>
|
||||
<property name="maximum_size"></property>
|
||||
<property name="maxlength"></property>
|
||||
<property name="maxlength">0</property>
|
||||
<property name="min_size"></property>
|
||||
<property name="minimize_button">0</property>
|
||||
<property name="minimum_size"></property>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///////////////////////////////////////////////////////////////////////////
|
||||
// C++ code generated with wxFormBuilder (version Jun 17 2015)
|
||||
// C++ code generated with wxFormBuilder (version May 2 2016)
|
||||
// http://www.wxformbuilder.org/
|
||||
//
|
||||
// PLEASE DO "NOT" EDIT THIS FILE!
|
||||
|
@ -38,7 +38,7 @@ class DIALOG_SELECT_PRETTY_LIB_BASE : public DIALOG_SHIM
|
|||
private:
|
||||
|
||||
protected:
|
||||
wxStaticText* m_staticText;
|
||||
wxStaticText* m_messageInfo;
|
||||
wxStaticText* m_staticText3;
|
||||
wxDirPickerCtrl* m_dirCtrl;
|
||||
wxBoxSizer* m_SizerNewLibName;
|
||||
|
@ -56,7 +56,7 @@ class DIALOG_SELECT_PRETTY_LIB_BASE : public DIALOG_SHIM
|
|||
|
||||
public:
|
||||
|
||||
DIALOG_SELECT_PRETTY_LIB_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Select Footprint Library Folder"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
|
||||
DIALOG_SELECT_PRETTY_LIB_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Select Footprint Library Folder"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 401,206 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
|
||||
~DIALOG_SELECT_PRETTY_LIB_BASE();
|
||||
|
||||
};
|
||||
|
|
|
@ -565,7 +565,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
|
|||
|
||||
m_gal->Save();
|
||||
m_gal->Translate( VECTOR2D( aPad->GetPosition() ) );
|
||||
m_gal->Rotate( -aPad->GetOrientation() * M_PI / 1800.0 );
|
||||
m_gal->Rotate( -aPad->GetOrientationRadians() );
|
||||
|
||||
// Choose drawing settings depending on if we are drawing a pad itself or a hole
|
||||
VECTOR2D size;
|
||||
|
@ -771,7 +771,7 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer )
|
|||
if( module )
|
||||
{
|
||||
m_gal->Translate( module->GetPosition() );
|
||||
m_gal->Rotate( -module->GetOrientation() * M_PI / 1800.0 );
|
||||
m_gal->Rotate( -module->GetOrientationRadians() );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -812,7 +812,6 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer )
|
|||
|
||||
const COLOR4D& color = m_pcbSettings.GetColor( aText, aText->GetLayer() );
|
||||
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
|
||||
double orientation = aText->GetOrientation() * M_PI / 1800.0;
|
||||
|
||||
if( m_pcbSettings.m_sketchMode[aLayer] )
|
||||
{
|
||||
|
@ -829,7 +828,7 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer )
|
|||
m_gal->SetIsStroke( true );
|
||||
m_gal->SetStrokeColor( color );
|
||||
m_gal->SetTextAttributes( aText );
|
||||
m_gal->StrokeText( shownText, position, orientation );
|
||||
m_gal->StrokeText( shownText, position, aText->GetOrientationRadians() );
|
||||
}
|
||||
|
||||
|
||||
|
@ -841,7 +840,6 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
|
|||
|
||||
const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer );
|
||||
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
|
||||
double orientation = aText->GetDrawRotation() * M_PI / 1800.0;
|
||||
|
||||
if( m_pcbSettings.m_sketchMode[aLayer] )
|
||||
{
|
||||
|
@ -858,7 +856,7 @@ void PCB_PAINTER::draw( const TEXTE_MODULE* aText, int aLayer )
|
|||
m_gal->SetIsStroke( true );
|
||||
m_gal->SetStrokeColor( color );
|
||||
m_gal->SetTextAttributes( aText );
|
||||
m_gal->StrokeText( shownText, position, orientation );
|
||||
m_gal->StrokeText( shownText, position, aText->GetDrawRotationRadians() );
|
||||
|
||||
// Draw the umbilical line
|
||||
if( aText->IsSelected() && aText->GetType() != TEXTE_MODULE::TEXT_is_DIVERS )
|
||||
|
@ -989,11 +987,10 @@ void PCB_PAINTER::draw( const DIMENSION* aDimension, int aLayer )
|
|||
// Draw text
|
||||
TEXTE_PCB& text = aDimension->Text();
|
||||
VECTOR2D position( text.GetTextPosition().x, text.GetTextPosition().y );
|
||||
double orientation = text.GetOrientation() * M_PI / 1800.0;
|
||||
|
||||
m_gal->SetLineWidth( text.GetThickness() );
|
||||
m_gal->SetTextAttributes( &text );
|
||||
m_gal->StrokeText( text.GetShownText(), position, orientation );
|
||||
m_gal->StrokeText( text.GetShownText(), position, text.GetOrientationRadians() );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -741,13 +741,9 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, MODULE* aModule )
|
|||
|
||||
pin->padstack_id = padstack->padstack_id;
|
||||
|
||||
int angle = pad->GetOrientation() - aModule->GetOrientation(); // tenths of degrees
|
||||
|
||||
if( angle )
|
||||
{
|
||||
NORMALIZE_ANGLE_POS( angle );
|
||||
pin->SetRotation( angle / 10.0 );
|
||||
}
|
||||
double angle = pad->GetOrientationDegrees() - aModule->GetOrientationDegrees();
|
||||
NORMALIZE_ANGLE_DEGREES_POS( angle );
|
||||
pin->SetRotation( angle );
|
||||
|
||||
wxPoint pos( pad->GetPos0() );
|
||||
|
||||
|
@ -1865,7 +1861,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
|
|||
|
||||
comp->places.push_back( place );
|
||||
|
||||
place->SetRotation( module->GetOrientation()/10.0 );
|
||||
place->SetRotation( module->GetOrientationDegrees() );
|
||||
place->SetVertex( mapPt( module->GetPosition() ) );
|
||||
place->component_id = componentId;
|
||||
place->part_number = TO_UTF8( module->GetValue() );
|
||||
|
@ -1873,9 +1869,9 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
|
|||
// module is flipped from bottom side, set side to T_back
|
||||
if( module->GetFlag() )
|
||||
{
|
||||
int angle = 1800 - module->GetOrientation();
|
||||
NORMALIZE_ANGLE_POS( angle );
|
||||
place->SetRotation( angle / 10.0 );
|
||||
double angle = 180.0 - module->GetOrientationDegrees();
|
||||
NORMALIZE_ANGLE_DEGREES_POS( angle );
|
||||
place->SetRotation( angle );
|
||||
|
||||
place->side = T_back;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue