2007-08-24 15:10:46 +00:00
|
|
|
/****************************************/
|
|
|
|
/* Modules to handle component drawing. */
|
|
|
|
/****************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
#include "class_library.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
#include <boost/foreach.hpp>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
//#define DRAW_ARC_WITH_ANGLE // Used to select function to draw arcs
|
2008-09-13 18:59:57 +00:00
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/***************************************************************************/
|
2008-09-13 18:59:57 +00:00
|
|
|
/** Function TransformCoordinate
|
2009-04-05 20:49:15 +00:00
|
|
|
* Calculate the wew coordinate from the old one, according to the transform
|
|
|
|
* matrix.
|
2008-09-13 18:59:57 +00:00
|
|
|
* @param aTransformMatrix = rotation, mirror .. matrix
|
|
|
|
* @param aPosition = the position to transform
|
|
|
|
* @return the new coordinate
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
/***************************************************************************/
|
|
|
|
wxPoint TransformCoordinate( const int aTransformMatrix[2][2],
|
|
|
|
const wxPoint& aPosition )
|
2008-09-13 18:59:57 +00:00
|
|
|
{
|
|
|
|
wxPoint new_pos;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
new_pos.x = ( aTransformMatrix[0][0] * aPosition.x ) +
|
|
|
|
( aTransformMatrix[0][1] * aPosition.y );
|
|
|
|
new_pos.y = ( aTransformMatrix[1][0] * aPosition.x ) +
|
|
|
|
( aTransformMatrix[1][1] * aPosition.y );
|
2008-09-13 18:59:57 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return new_pos;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2009-04-05 20:49:15 +00:00
|
|
|
* Routine to rotate the given angular direction by the given Transformation. *
|
|
|
|
* Input (and output) angles must be as follows: *
|
|
|
|
* Unit is 0.1 degre *
|
|
|
|
* Angle1 in [0..3600], Angle2 > Angle1 in [0..7200]. Arc is assumed to be *
|
|
|
|
* less than 180.0 degrees. *
|
|
|
|
* Algorithm: *
|
|
|
|
* Map the angles to a point on the unit circle which is mapped using the *
|
|
|
|
* transform (only mirror and rotate so it remains on the unit circle) to *
|
|
|
|
* a new point which is used to detect new angle. *
|
|
|
|
*****************************************************************************/
|
2009-01-02 17:07:50 +00:00
|
|
|
bool MapAngles( int* Angle1, int* Angle2, const int TransMat[2][2] )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
int Angle, Delta;
|
|
|
|
double x, y, t;
|
|
|
|
bool swap = FALSE;
|
|
|
|
|
|
|
|
Delta = *Angle2 - *Angle1;
|
|
|
|
if( Delta >= 1800 )
|
|
|
|
{
|
|
|
|
*Angle1 -= 1;
|
|
|
|
*Angle2 += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = cos( *Angle1 * M_PI / 1800.0 );
|
|
|
|
y = sin( *Angle1 * M_PI / 1800.0 );
|
|
|
|
t = x * TransMat[0][0] + y * TransMat[0][1];
|
|
|
|
y = x * TransMat[1][0] + y * TransMat[1][1];
|
|
|
|
x = t;
|
2009-04-05 20:49:15 +00:00
|
|
|
*Angle1 = (int) ( atan2( y, x ) * 1800.0 / M_PI + 0.5 );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
x = cos( *Angle2 * M_PI / 1800.0 );
|
|
|
|
y = sin( *Angle2 * M_PI / 1800.0 );
|
|
|
|
t = x * TransMat[0][0] + y * TransMat[0][1];
|
|
|
|
y = x * TransMat[1][0] + y * TransMat[1][1];
|
|
|
|
x = t;
|
2009-04-05 20:49:15 +00:00
|
|
|
*Angle2 = (int) ( atan2( y, x ) * 1800.0 / M_PI + 0.5 );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
NORMALIZE_ANGLE( *Angle1 );
|
|
|
|
NORMALIZE_ANGLE( *Angle2 );
|
|
|
|
if( *Angle2 < *Angle1 )
|
|
|
|
*Angle2 += 3600;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( *Angle2 - *Angle1 > 1800 ) /* Need to swap the two angles. */
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
Angle = (*Angle1);
|
|
|
|
*Angle1 = (*Angle2);
|
|
|
|
*Angle2 = Angle;
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE( *Angle1 );
|
|
|
|
NORMALIZE_ANGLE( *Angle2 );
|
|
|
|
if( *Angle2 < *Angle1 )
|
|
|
|
*Angle2 += 3600;
|
|
|
|
swap = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Delta >= 1800 )
|
|
|
|
{
|
|
|
|
*Angle1 += 1;
|
|
|
|
*Angle2 -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return swap;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|