Dxf importer: fix some issues, especially the rotation angle of texts.
This commit is contained in:
parent
c56d6ad2dd
commit
b0ab53ac26
|
@ -316,24 +316,20 @@ void DXF_IMPORT_PLUGIN::addArc( const DL_ArcData& aData )
|
||||||
// Init arc centre:
|
// Init arc centre:
|
||||||
VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) );
|
VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) );
|
||||||
|
|
||||||
|
// aData.anglex is in degrees.
|
||||||
|
double startangle = aData.angle1;
|
||||||
|
double endangle = aData.angle2;
|
||||||
|
|
||||||
// Init arc start point
|
// Init arc start point
|
||||||
double arcStartx = aData.radius;
|
VECTOR2D startPoint( aData.radius, 0.0 );
|
||||||
double arcStarty = 0;
|
startPoint = startPoint.Rotate( startangle * M_PI / 180.0 );
|
||||||
|
VECTOR2D arcStart( mapX( startPoint.x + aData.cx ), mapY( startPoint.y + aData.cy ) );
|
||||||
// aData.anglex is in degrees. Our internal units are 0.1 degree
|
|
||||||
// so convert DXF angles (in degrees) to our units
|
|
||||||
#define DXF2ANGLEUI 10
|
|
||||||
double startangle = aData.angle1 * DXF2ANGLEUI;
|
|
||||||
double endangle = aData.angle2 * DXF2ANGLEUI;
|
|
||||||
|
|
||||||
RotatePoint( &arcStartx, &arcStarty, -startangle );
|
|
||||||
VECTOR2D arcStart( mapX( arcStartx + aData.cx ), mapY( arcStarty + aData.cy ) );
|
|
||||||
|
|
||||||
// calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
|
// calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
|
||||||
double angle = -( endangle - startangle );
|
double angle = -( endangle - startangle );
|
||||||
|
|
||||||
if( angle > 0.0 )
|
if( angle > 0.0 )
|
||||||
angle -= 3600.0;
|
angle -= 360.0;
|
||||||
|
|
||||||
double lineWidth = mapWidth( attributes.getWidth() );
|
double lineWidth = mapWidth( attributes.getWidth() );
|
||||||
m_internalImporter.AddArc( center, arcStart, angle, lineWidth );
|
m_internalImporter.AddArc( center, arcStart, angle, lineWidth );
|
||||||
|
@ -447,13 +443,17 @@ void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
double angle = aData.angle * 10;
|
// dxf_lib imports text angle in radians (although there are no comment about that.
|
||||||
double angleInRads = angle / 10.0 * M_PI / 180.0;
|
// So, for the moment, convert this angle to degrees
|
||||||
|
double angle_degree = aData.angle * 180 / M_PI;
|
||||||
|
// We also need the angle in radians. so convert angle_degree to radians
|
||||||
|
// regardless the aData.angle unit
|
||||||
|
double angleInRads = angle_degree * M_PI / 180.0;
|
||||||
double cosine = cos(angleInRads);
|
double cosine = cos(angleInRads);
|
||||||
double sine = sin(angleInRads);
|
double sine = sin(angleInRads);
|
||||||
|
|
||||||
m_internalImporter.AddText( refPoint, text, textHeight, charWidth, textThickness, angle,
|
m_internalImporter.AddText( refPoint, text, textHeight, charWidth, textThickness,
|
||||||
hJustify, vJustify );
|
angle_degree, hJustify, vJustify );
|
||||||
|
|
||||||
// Calculate the boundary box and update the image limits:
|
// Calculate the boundary box and update the image limits:
|
||||||
bottomLeft.x = bottomLeft.x * cosine - bottomLeft.y * sine;
|
bottomLeft.x = bottomLeft.x * cosine - bottomLeft.y * sine;
|
||||||
|
@ -600,13 +600,17 @@ void DXF_IMPORT_PLUGIN::addMText( const DL_MTextData& aData )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
double angle = aData.angle * 10;
|
// dxf_lib imports text angle in radians (although there are no comment about that.
|
||||||
double angleInRads = angle / 10.0 * M_PI / 180.0;
|
// So, for the moment, convert this angle to degrees
|
||||||
|
double angle_degree = aData.angle * 180/M_PI;
|
||||||
|
// We also need the angle in radians. so convert angle_degree to radians
|
||||||
|
// regardless the aData.angle unit
|
||||||
|
double angleInRads = angle_degree * M_PI / 180.0;
|
||||||
double cosine = cos(angleInRads);
|
double cosine = cos(angleInRads);
|
||||||
double sine = sin(angleInRads);
|
double sine = sin(angleInRads);
|
||||||
|
|
||||||
m_internalImporter.AddText( textpos, text, textHeight, charWidth,
|
m_internalImporter.AddText( textpos, text, textHeight, charWidth,
|
||||||
textThickness, angle, hJustify, vJustify );
|
textThickness, angle_degree, hJustify, vJustify );
|
||||||
|
|
||||||
bottomLeft.x = bottomLeft.x * cosine - bottomLeft.y * sine;
|
bottomLeft.x = bottomLeft.x * cosine - bottomLeft.y * sine;
|
||||||
bottomLeft.y = bottomLeft.x * sine + bottomLeft.y * cosine;
|
bottomLeft.y = bottomLeft.x * sine + bottomLeft.y * cosine;
|
||||||
|
@ -924,7 +928,7 @@ void DXF_IMPORT_PLUGIN::insertArc( const VECTOR2D& aSegStart, const VECTOR2D& aS
|
||||||
double cy = h * sin( offAng ) + ym;
|
double cy = h * sin( offAng ) + ym;
|
||||||
VECTOR2D center( SCALE_FACTOR( cx ), SCALE_FACTOR( -cy ) );
|
VECTOR2D center( SCALE_FACTOR( cx ), SCALE_FACTOR( -cy ) );
|
||||||
VECTOR2D arc_start;
|
VECTOR2D arc_start;
|
||||||
double angle = RAD2DECIDEG( ang );
|
double angle = RAD2DEG( ang );
|
||||||
|
|
||||||
if( ang < 0.0 )
|
if( ang < 0.0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -202,22 +202,20 @@ public:
|
||||||
* @param aCenter is the arc center point expressed in mm.
|
* @param aCenter is the arc center point expressed in mm.
|
||||||
* @param aStart is the arc arm end point expressed in mm.
|
* @param aStart is the arc arm end point expressed in mm.
|
||||||
* Its length is the arc radius.
|
* Its length is the arc radius.
|
||||||
* @param aAngle is the arc angle expressed in decidegrees.
|
* @param aAngle is the arc angle expressed in degrees.
|
||||||
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
|
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
|
||||||
*/
|
*/
|
||||||
virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth ) = 0;
|
virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth ) = 0;
|
||||||
|
|
||||||
virtual void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) = 0;
|
virtual void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) = 0;
|
||||||
|
|
||||||
//virtual void AddArc( const VECTOR2D& aOrigin, double aStartAngle, double aEndAngle ) = 0;
|
|
||||||
//
|
|
||||||
/**
|
/**
|
||||||
* @brief Creates an object representing a text.
|
* @brief Creates an object representing a text.
|
||||||
* @param aOrigin is the text position.
|
* @param aOrigin is the text position.
|
||||||
* @param aText is the displayed text.
|
* @param aText is the displayed text.
|
||||||
* @param aHeight is the text height expressed in mm.
|
* @param aHeight is the text height expressed in mm.
|
||||||
* @param aWidth is the text width expressed in mm.
|
* @param aWidth is the text width expressed in mm.
|
||||||
* @param aOrientation is the text orientation angle expressed in decidegrees.
|
* @param aOrientation is the text orientation angle expressed in degrees.
|
||||||
* @param aHJustify is the text horizontal justification.
|
* @param aHJustify is the text horizontal justification.
|
||||||
* @param aVJustify is the text vertical justification.
|
* @param aVJustify is the text vertical justification.
|
||||||
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
|
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
|
||||||
|
|
|
@ -90,7 +90,8 @@ void GRAPHICS_IMPORTER_PCBNEW::AddCircle( const VECTOR2D& aCenter, double aRadiu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GRAPHICS_IMPORTER_PCBNEW::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth )
|
void GRAPHICS_IMPORTER_PCBNEW::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart,
|
||||||
|
double aAngle, double aWidth )
|
||||||
{
|
{
|
||||||
unique_ptr<DRAWSEGMENT> arc( createDrawing() );
|
unique_ptr<DRAWSEGMENT> arc( createDrawing() );
|
||||||
arc->SetShape( S_ARC );
|
arc->SetShape( S_ARC );
|
||||||
|
@ -98,7 +99,7 @@ void GRAPHICS_IMPORTER_PCBNEW::AddArc( const VECTOR2D& aCenter, const VECTOR2D&
|
||||||
arc->SetWidth( MapLineWidth( aWidth ) );
|
arc->SetWidth( MapLineWidth( aWidth ) );
|
||||||
arc->SetCenter( MapCoordinate( aCenter) );
|
arc->SetCenter( MapCoordinate( aCenter) );
|
||||||
arc->SetArcStart( MapCoordinate( aStart ) );
|
arc->SetArcStart( MapCoordinate( aStart ) );
|
||||||
arc->SetAngle( aAngle );
|
arc->SetAngle( aAngle * 10.0 ); // Pcbnew uses the decidegree
|
||||||
|
|
||||||
if( arc->Type() == PCB_MODULE_EDGE_T )
|
if( arc->Type() == PCB_MODULE_EDGE_T )
|
||||||
static_cast<EDGE_MODULE*>( arc.get() )->SetLocalCoord();
|
static_cast<EDGE_MODULE*>( arc.get() )->SetLocalCoord();
|
||||||
|
@ -138,7 +139,7 @@ void GRAPHICS_IMPORTER_PCBNEW::AddText( const VECTOR2D& aOrigin, const wxString&
|
||||||
boardItem->SetLayer( GetLayer() );
|
boardItem->SetLayer( GetLayer() );
|
||||||
textItem->SetThickness( MapLineWidth( aThickness ) );
|
textItem->SetThickness( MapLineWidth( aThickness ) );
|
||||||
textItem->SetTextPos( MapCoordinate( aOrigin ) );
|
textItem->SetTextPos( MapCoordinate( aOrigin ) );
|
||||||
textItem->SetTextAngle( aOrientation );
|
textItem->SetTextAngle( aOrientation * 10.0 ); // Pcbnew uses the decidegree
|
||||||
textItem->SetTextWidth( aWidth * ImportScalingFactor() );
|
textItem->SetTextWidth( aWidth * ImportScalingFactor() );
|
||||||
textItem->SetTextHeight( aHeight * ImportScalingFactor() );
|
textItem->SetTextHeight( aHeight * ImportScalingFactor() );
|
||||||
textItem->SetVertJustify( aVJustify );
|
textItem->SetVertJustify( aVJustify );
|
||||||
|
|
|
@ -62,7 +62,8 @@ public:
|
||||||
|
|
||||||
void AddCircle( const VECTOR2D& aOrigin, double aRadius, double aWidth ) override;
|
void AddCircle( const VECTOR2D& aOrigin, double aRadius, double aWidth ) override;
|
||||||
|
|
||||||
void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth ) override;
|
void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle,
|
||||||
|
double aWidth ) override;
|
||||||
|
|
||||||
void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) override;
|
void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue