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:
jean-pierre charras 2016-05-02 12:49:14 +02:00
parent ce331b03e8
commit e46f706d4b
13 changed files with 60 additions and 41 deletions

View File

@ -134,7 +134,10 @@ public:
int GetThickness() const { return m_Thickness; }; int GetThickness() const { return m_Thickness; };
void SetOrientation( double aOrientation ); void SetOrientation( double aOrientation );
void SetOrientationDegrees( double aOrientation ) { SetOrientation( aOrientation*10.0 ); }
double GetOrientation() const { return m_Orient; } 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; } void SetItalic( bool isItalic ) { m_Italic = isItalic; }
bool IsItalic() const { return m_Italic; } bool IsItalic() const { return m_Italic; }

View File

@ -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: /// 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 ) template <class T> inline void NORMALIZE_ANGLE_POS( T &Angle )
{ {
while( Angle < 0 ) while( Angle < 0 )
@ -216,6 +217,16 @@ template <class T> inline void NORMALIZE_ANGLE_POS( T &Angle )
Angle -= 3600; 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 /// 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 // because most of the time it's an int (and templates don't promote in
// that way) // that way)

View File

@ -576,7 +576,9 @@ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
// display schematic path // display schematic path
aList.push_back( MSG_PANEL_ITEM( _( "Netlist Path" ), m_Path, BROWN ) ); 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; EDA_ITEM* PtStruct = m_Pads;
nbpad = 0; nbpad = 0;
@ -600,8 +602,8 @@ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Status" ), msg, MAGENTA ) ); aList.push_back( MSG_PANEL_ITEM( _( "Status" ), msg, MAGENTA ) );
msg.Printf( wxT( "%.1f" ), m_Orient / 10.0 ); msg.Printf( wxT( "%.1f" ), GetOrientationDegrees() );
aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, BROWN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Rotation" ), msg, BROWN ) );
// Controls on right side of the dialog // Controls on right side of the dialog
switch( m_Attributs & 255 ) switch( m_Attributs & 255 )

View File

@ -161,7 +161,10 @@ public:
const wxPoint& GetPosition() const { return m_Pos; } // was overload const wxPoint& GetPosition() const { return m_Pos; } // was overload
void SetOrientation( double newangle ); void SetOrientation( double newangle );
void SetOrientationDegrees( double aOrientation ) { SetOrientation( aOrientation*10.0 ); }
double GetOrientation() const { return m_Orient; } 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; } const FPID& GetFPID() const { return m_fpid; }
void SetFPID( const FPID& aFPID ) { m_fpid = aFPID; } void SetFPID( const FPID& aFPID ) { m_fpid = aFPID; }

View File

@ -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 ) ); 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)" ), Line.Printf( wxT( "%3.1f(+%3.1f)" ),
( m_Orient - module_orient ) / 10.0, GetOrientationDegrees() - module_orient_degrees,
module_orient / 10.0 ); module_orient_degrees );
else 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 ) ); aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), Line, LIGHTBLUE ) );

View File

@ -198,11 +198,18 @@ public:
*/ */
void SetOrientation( double aAngle ); void SetOrientation( double aAngle );
/**
* Set orientation in degrees
*/
void SetOrientationDegrees( double aOrientation ) { SetOrientation( aOrientation*10.0 ); }
/** /**
* Function GetOrientation * Function GetOrientation
* returns the rotation angle of the pad in tenths of degrees, but soon degrees. * returns the rotation angle of the pad in tenths of degrees, but soon degrees.
*/ */
double GetOrientation() const { return m_Orient; } 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 ) void SetDrillShape( PAD_DRILL_SHAPE_T aDrillShape )
{ m_drillShape = aDrillShape; } { m_drillShape = aDrillShape; }

View File

@ -316,7 +316,7 @@ double TEXTE_MODULE::GetDrawRotation() const
if( module ) if( module )
rotation += module->GetOrientation(); 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 ) while( rotation > 900 )
rotation -= 1800; 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 ) ); 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 ) ); aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
msg = ::CoordinateToString( m_Thickness ); msg = ::CoordinateToString( m_Thickness );

View File

@ -121,6 +121,7 @@ public:
* the footprint rotation is taken in account * the footprint rotation is taken in account
*/ */
double GetDrawRotation() const; double GetDrawRotation() const;
double GetDrawRotationRadians() const { return GetDrawRotation() * M_PI/1800; }
// Virtual function // Virtual function
const EDA_RECT GetBoundingBox() const; const EDA_RECT GetBoundingBox() const;

View File

@ -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/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
@ -16,11 +16,11 @@ DIALOG_SELECT_PRETTY_LIB_BASE::DIALOG_SELECT_PRETTY_LIB_BASE( wxWindow* parent,
wxBoxSizer* bSizerMain; wxBoxSizer* bSizerMain;
bSizerMain = new wxBoxSizer( wxVERTICAL ); 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_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_staticText->Wrap( -1 ); m_messageInfo->Wrap( -1 );
m_staticText->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 92, false, wxEmptyString ) ); 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 = new wxStaticText( this, wxID_ANY, _("Path base:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText3->Wrap( -1 ); m_staticText3->Wrap( -1 );
@ -56,7 +56,6 @@ DIALOG_SELECT_PRETTY_LIB_BASE::DIALOG_SELECT_PRETTY_LIB_BASE( wxWindow* parent,
this->SetSizer( bSizerMain ); this->SetSizer( bSizerMain );
this->Layout(); this->Layout();
bSizerMain->Fit( this );
this->Centre( wxBOTH ); this->Centre( wxBOTH );

View File

@ -44,7 +44,7 @@
<property name="minimum_size">-1,-1</property> <property name="minimum_size">-1,-1</property>
<property name="name">DIALOG_SELECT_PRETTY_LIB_BASE</property> <property name="name">DIALOG_SELECT_PRETTY_LIB_BASE</property>
<property name="pos"></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="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property> <property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Select Footprint Library Folder</property> <property name="title">Select Footprint Library Folder</property>
@ -133,7 +133,7 @@
<property name="minimize_button">0</property> <property name="minimize_button">0</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>
<property name="moveable">1</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_border">1</property>
<property name="pane_position"></property> <property name="pane_position"></property>
<property name="pane_size"></property> <property name="pane_size"></property>
@ -474,7 +474,7 @@
<property name="max_size"></property> <property name="max_size"></property>
<property name="maximize_button">0</property> <property name="maximize_button">0</property>
<property name="maximum_size"></property> <property name="maximum_size"></property>
<property name="maxlength"></property> <property name="maxlength">0</property>
<property name="min_size"></property> <property name="min_size"></property>
<property name="minimize_button">0</property> <property name="minimize_button">0</property>
<property name="minimum_size"></property> <property name="minimum_size"></property>

View File

@ -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/ // http://www.wxformbuilder.org/
// //
// PLEASE DO "NOT" EDIT THIS FILE! // PLEASE DO "NOT" EDIT THIS FILE!
@ -38,7 +38,7 @@ class DIALOG_SELECT_PRETTY_LIB_BASE : public DIALOG_SHIM
private: private:
protected: protected:
wxStaticText* m_staticText; wxStaticText* m_messageInfo;
wxStaticText* m_staticText3; wxStaticText* m_staticText3;
wxDirPickerCtrl* m_dirCtrl; wxDirPickerCtrl* m_dirCtrl;
wxBoxSizer* m_SizerNewLibName; wxBoxSizer* m_SizerNewLibName;
@ -56,7 +56,7 @@ class DIALOG_SELECT_PRETTY_LIB_BASE : public DIALOG_SHIM
public: 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(); ~DIALOG_SELECT_PRETTY_LIB_BASE();
}; };

View File

@ -565,7 +565,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer )
m_gal->Save(); m_gal->Save();
m_gal->Translate( VECTOR2D( aPad->GetPosition() ) ); 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 // Choose drawing settings depending on if we are drawing a pad itself or a hole
VECTOR2D size; VECTOR2D size;
@ -771,7 +771,7 @@ void PCB_PAINTER::draw( const DRAWSEGMENT* aSegment, int aLayer )
if( module ) if( module )
{ {
m_gal->Translate( module->GetPosition() ); m_gal->Translate( module->GetPosition() );
m_gal->Rotate( -module->GetOrientation() * M_PI / 1800.0 ); m_gal->Rotate( -module->GetOrientationRadians() );
} }
else else
{ {
@ -812,7 +812,6 @@ void PCB_PAINTER::draw( const TEXTE_PCB* aText, int aLayer )
const COLOR4D& color = m_pcbSettings.GetColor( aText, aText->GetLayer() ); const COLOR4D& color = m_pcbSettings.GetColor( aText, aText->GetLayer() );
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
double orientation = aText->GetOrientation() * M_PI / 1800.0;
if( m_pcbSettings.m_sketchMode[aLayer] ) 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->SetIsStroke( true );
m_gal->SetStrokeColor( color ); m_gal->SetStrokeColor( color );
m_gal->SetTextAttributes( aText ); 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 ); const COLOR4D& color = m_pcbSettings.GetColor( aText, aLayer );
VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y ); VECTOR2D position( aText->GetTextPosition().x, aText->GetTextPosition().y );
double orientation = aText->GetDrawRotation() * M_PI / 1800.0;
if( m_pcbSettings.m_sketchMode[aLayer] ) 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->SetIsStroke( true );
m_gal->SetStrokeColor( color ); m_gal->SetStrokeColor( color );
m_gal->SetTextAttributes( aText ); m_gal->SetTextAttributes( aText );
m_gal->StrokeText( shownText, position, orientation ); m_gal->StrokeText( shownText, position, aText->GetDrawRotationRadians() );
// Draw the umbilical line // Draw the umbilical line
if( aText->IsSelected() && aText->GetType() != TEXTE_MODULE::TEXT_is_DIVERS ) 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 // Draw text
TEXTE_PCB& text = aDimension->Text(); TEXTE_PCB& text = aDimension->Text();
VECTOR2D position( text.GetTextPosition().x, text.GetTextPosition().y ); VECTOR2D position( text.GetTextPosition().x, text.GetTextPosition().y );
double orientation = text.GetOrientation() * M_PI / 1800.0;
m_gal->SetLineWidth( text.GetThickness() ); m_gal->SetLineWidth( text.GetThickness() );
m_gal->SetTextAttributes( &text ); m_gal->SetTextAttributes( &text );
m_gal->StrokeText( text.GetShownText(), position, orientation ); m_gal->StrokeText( text.GetShownText(), position, text.GetOrientationRadians() );
} }

View File

@ -741,13 +741,9 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, MODULE* aModule )
pin->padstack_id = padstack->padstack_id; pin->padstack_id = padstack->padstack_id;
int angle = pad->GetOrientation() - aModule->GetOrientation(); // tenths of degrees double angle = pad->GetOrientationDegrees() - aModule->GetOrientationDegrees();
NORMALIZE_ANGLE_DEGREES_POS( angle );
if( angle ) pin->SetRotation( angle );
{
NORMALIZE_ANGLE_POS( angle );
pin->SetRotation( angle / 10.0 );
}
wxPoint pos( pad->GetPos0() ); wxPoint pos( pad->GetPos0() );
@ -1865,7 +1861,7 @@ void SPECCTRA_DB::FromBOARD( BOARD* aBoard )
comp->places.push_back( place ); comp->places.push_back( place );
place->SetRotation( module->GetOrientation()/10.0 ); place->SetRotation( module->GetOrientationDegrees() );
place->SetVertex( mapPt( module->GetPosition() ) ); place->SetVertex( mapPt( module->GetPosition() ) );
place->component_id = componentId; place->component_id = componentId;
place->part_number = TO_UTF8( module->GetValue() ); 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 // module is flipped from bottom side, set side to T_back
if( module->GetFlag() ) if( module->GetFlag() )
{ {
int angle = 1800 - module->GetOrientation(); double angle = 180.0 - module->GetOrientationDegrees();
NORMALIZE_ANGLE_POS( angle ); NORMALIZE_ANGLE_DEGREES_POS( angle );
place->SetRotation( angle / 10.0 ); place->SetRotation( angle );
place->side = T_back; place->side = T_back;
} }