KiCad PCB EDA Suite
TRANSFORM Class Reference

Class for tranforming drawing coordinates for a wxDC device context. More...

#include <transform.h>

Public Member Functions

 TRANSFORM ()
 The default construct creates a tranform that draws object is the normal orientation. More...
 
 TRANSFORM (int ax1, int ay1, int ax2, int ay2)
 
bool operator== (const TRANSFORM &aTransform) const
 
bool operator!= (const TRANSFORM &aTransform) const
 
wxPoint TransformCoordinate (const wxPoint &aPoint) const
 Calculate a new coordinate according to the mirror/rotation transform. More...
 
EDA_RECT TransformCoordinate (const EDA_RECT &aRect) const
 Calculate a new rect according to the mirror/rotation transform. More...
 
TRANSFORM InverseTransform () const
 Calculate the Inverse mirror/rotation transform. More...
 
bool MapAngles (int *aAngle1, int *aAngle2) const
 Calculate new angles according to the transform. More...
 

Public Attributes

int x1
 
int y1
 
int x2
 
int y2
 

Detailed Description

Class for tranforming drawing coordinates for a wxDC device context.

This probably should be a base class with all pure methods and a derived class named WXDC_TRANFORM be created. Then in the future if some new device context is used, a new transform could be derived from the base class and all the drawable objects would have to do is provide overloaded draw methods to use the new transorm.

Definition at line 45 of file transform.h.

Constructor & Destructor Documentation

TRANSFORM::TRANSFORM ( )
inline

The default construct creates a tranform that draws object is the normal orientation.

Definition at line 56 of file transform.h.

56 : x1( 1 ), y1( 0 ), x2( 0 ), y2( -1 ) {}
int y2
Definition: transform.h:51
int x2
Definition: transform.h:50
int x1
Definition: transform.h:48
int y1
Definition: transform.h:49
TRANSFORM::TRANSFORM ( int  ax1,
int  ay1,
int  ax2,
int  ay2 
)
inline

Definition at line 58 of file transform.h.

58 : x1( ax1 ), y1( ay1 ), x2( ax2 ), y2( ay2 ) {}
int y2
Definition: transform.h:51
int x2
Definition: transform.h:50
int x1
Definition: transform.h:48
int y1
Definition: transform.h:49

Member Function Documentation

TRANSFORM TRANSFORM::InverseTransform ( ) const

Calculate the Inverse mirror/rotation transform.

Useful to calculate coordinates relative to a component which must be for a non rotated, non mirrored item from the actual coordinate.

Returns
The inverse transform.

Definition at line 58 of file transform.cpp.

References x1, x2, y1, and y2.

Referenced by SCH_COLLECTOR::Inspect(), and SCH_FIELD::SetPosition().

59 {
60  int invx1;
61  int invx2;
62  int invy1;
63  int invy2;
64 
65  /* Calculates the inverse matrix coeffs:
66  * for a matrix m{x1, x2, y1, y2}
67  * the inverse matrix is 1/(x1*y2 -x2*y1) m{y2,-x2,-y1,x1)
68  */
69  int det = x1*y2 -x2*y1; // Is never null, because the inverse matrix exists
70  invx1 = y2/det;
71  invx2 = -x2/det;
72  invy1 = -y1/det;
73  invy2 = x1/det;
74 
75  TRANSFORM invtransform( invx1, invy1, invx2, invy2 );
76  return invtransform;
77 }
int y2
Definition: transform.h:51
int x2
Definition: transform.h:50
int x1
Definition: transform.h:48
int y1
Definition: transform.h:49
Class for tranforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
bool TRANSFORM::MapAngles ( int *  aAngle1,
int *  aAngle2 
) const

Calculate new angles according to the transform.

Parameters
aAngle1= The first angle to transform
aAngle2= The second angle to transform
Returns
True if the angles were swapped during the transform.

Definition at line 80 of file transform.cpp.

References DECIDEG2RAD(), KiROUND(), NORMALIZE_ANGLE_POS(), RAD2DECIDEG(), opti_s::t, x1, x2, y1, and y2.

Referenced by LIB_ARC::drawGraphic(), LIB_ARC::GetBoundingBox(), and LIB_ARC::Plot().

81 {
82  wxCHECK_MSG( aAngle1 != NULL && aAngle2 != NULL, false,
83  wxT( "Cannot map NULL point angles." ) );
84 
85  int Angle, Delta;
86  double x, y, t;
87  bool swap = false;
88 
89  Delta = *aAngle2 - *aAngle1;
90  if( Delta >= 1800 )
91  {
92  *aAngle1 -= 1;
93  *aAngle2 += 1;
94  }
95 
96  x = cos( DECIDEG2RAD( *aAngle1 ) );
97  y = sin( DECIDEG2RAD( *aAngle1 ) );
98  t = x * x1 + y * y1;
99  y = x * x2 + y * y2;
100  x = t;
101  *aAngle1 = KiROUND( RAD2DECIDEG( atan2( y, x ) ) );
102 
103  x = cos( DECIDEG2RAD( *aAngle2 ) );
104  y = sin( DECIDEG2RAD( *aAngle2 ) );
105  t = x * x1 + y * y1;
106  y = x * x2 + y * y2;
107  x = t;
108  *aAngle2 = KiROUND( RAD2DECIDEG( atan2( y, x ) ) );
109 
110  NORMALIZE_ANGLE_POS( *aAngle1 );
111  NORMALIZE_ANGLE_POS( *aAngle2 );
112  if( *aAngle2 < *aAngle1 )
113  *aAngle2 += 3600;
114 
115  if( *aAngle2 - *aAngle1 > 1800 ) // Need to swap the two angles
116  {
117  Angle = (*aAngle1);
118  *aAngle1 = (*aAngle2);
119  *aAngle2 = Angle;
120 
121  NORMALIZE_ANGLE_POS( *aAngle1 );
122  NORMALIZE_ANGLE_POS( *aAngle2 );
123  if( *aAngle2 < *aAngle1 )
124  *aAngle2 += 3600;
125  swap = true;
126  }
127 
128  if( Delta >= 1800 )
129  {
130  *aAngle1 += 1;
131  *aAngle2 -= 1;
132  }
133 
134  return swap;
135 }
int y2
Definition: transform.h:51
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
int x2
Definition: transform.h:50
double RAD2DECIDEG(double rad)
Definition: trigo.h:196
int x1
Definition: transform.h:48
void NORMALIZE_ANGLE_POS(T &Angle)
Definition: trigo.h:222
int y1
Definition: transform.h:49
double DECIDEG2RAD(double deg)
Definition: trigo.h:195
bool TRANSFORM::operator!= ( const TRANSFORM aTransform) const
inline

Definition at line 62 of file transform.h.

62 { return !( *this == aTransform ); }
bool TRANSFORM::operator== ( const TRANSFORM aTransform) const

Definition at line 32 of file transform.cpp.

References x1, x2, y1, and y2.

33 {
34  return ( x1 == aTransform.x1 &&
35  y1 == aTransform.y1 &&
36  x2 == aTransform.x2 &&
37  y2 == aTransform.y2 );
38 }
int y2
Definition: transform.h:51
int x2
Definition: transform.h:50
int x1
Definition: transform.h:48
int y1
Definition: transform.h:49
wxPoint TRANSFORM::TransformCoordinate ( const wxPoint aPoint) const

Calculate a new coordinate according to the mirror/rotation transform.

Useful to calculate actual coordinates of a point from coordinates relative to a component which are given for a non rotated, non mirrored item

Parameters
aPoint= The position to transform
Returns
The transformed coordinate.

Definition at line 41 of file transform.cpp.

References wxPoint::x, x1, x2, wxPoint::y, y1, and y2.

Referenced by LIB_PART::Draw(), LIB_CIRCLE::drawGraphic(), LIB_POLYLINE::drawGraphic(), LIB_RECTANGLE::drawGraphic(), LIB_BEZIER::drawGraphic(), LIB_TEXT::drawGraphic(), LIB_ARC::drawGraphic(), LIB_FIELD::drawGraphic(), LIB_PIN::drawGraphic(), SCH_EDIT_FRAME::FindComponentAndItem(), SCH_FIELD::GetBoundingBox(), LIB_ARC::GetBoundingBox(), SCH_COMPONENT::GetConnectionPoints(), LIB_PIN::GetMsgPanelInfo(), SCH_COMPONENT::GetNetListItem(), SCH_COMPONENT::GetPinPhysicalPosition(), SCH_FIELD::GetPosition(), SCH_COMPONENT::GetScreenCoord(), LIB_CIRCLE::HitTest(), LIB_RECTANGLE::HitTest(), LIB_BEZIER::HitTest(), LIB_POLYLINE::HitTest(), LIB_TEXT::HitTest(), LIB_FIELD::HitTest(), SCH_COLLECTOR::Inspect(), SCH_FIND_COLLECTOR::Inspect(), LIB_PIN::PinDrawOrient(), LIB_BEZIER::Plot(), LIB_CIRCLE::Plot(), LIB_RECTANGLE::Plot(), LIB_POLYLINE::Plot(), LIB_TEXT::Plot(), LIB_ARC::Plot(), LIB_FIELD::Plot(), LIB_PIN::Plot(), SCH_FIELD::SetPosition(), and TransformCoordinate().

42 {
43  return wxPoint( ( x1 * aPoint.x ) + ( y1 * aPoint.y ),
44  ( x2 * aPoint.x ) + ( y2 * aPoint.y ) );
45 }
int y2
Definition: transform.h:51
int x2
Definition: transform.h:50
int x1
Definition: transform.h:48
int y1
Definition: transform.h:49
EDA_RECT TRANSFORM::TransformCoordinate ( const EDA_RECT aRect) const

Calculate a new rect according to the mirror/rotation transform.

Useful to calculate actual coordinates of a point from coordinates relative to a component which are given for a non rotated, non mirrored item

Parameters
aRect= The rectangle to transform
Returns
The transformed rectangle.

Definition at line 47 of file transform.cpp.

References EDA_RECT::GetEnd(), EDA_RECT::GetOrigin(), EDA_RECT::SetEnd(), EDA_RECT::SetOrigin(), and TransformCoordinate().

48 {
49  EDA_RECT rect;
50  rect.SetOrigin( TransformCoordinate( aRect.GetOrigin() ) );
51  rect.SetEnd( TransformCoordinate( aRect.GetEnd() ) );
52  return rect;
53 }
void SetOrigin(const wxPoint &pos)
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:41
const wxPoint & GetOrigin() const
void SetEnd(int x, int y)
const wxPoint GetEnd() const
Class EDA_RECT handles the component boundary box.

Member Data Documentation


The documentation for this class was generated from the following files: