From 909b7fb4251422e92920bdceeb968cf0bac13ac1 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 19 Dec 2013 12:33:57 +0100 Subject: [PATCH] Dxf export: fix an issue in exported arcs. Update libdfx. Pcbnew:, libedit, Save lib as...: the new .pretty lib format is the default, instead of legacy .mod format. The legacy format is still selectable in the file selection dialog. --- common/common_plotDXF_functions.cpp | 11 ++++++++++- lib_dxf/libdxfrw.cpp | 8 ++++---- pcbnew/class_drawsegment.h | 16 ++++++++++++++-- pcbnew/import_dxf/dxf2brd_items.cpp | 17 +++++++++++------ pcbnew/librairi.cpp | 11 ++++++----- pcbnew/specctra_export.cpp | 2 +- 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/common/common_plotDXF_functions.cpp b/common/common_plotDXF_functions.cpp index cf216e03d4..2368cb98f7 100644 --- a/common/common_plotDXF_functions.cpp +++ b/common/common_plotDXF_functions.cpp @@ -386,7 +386,7 @@ void DXF_PLOTTER::ThickSegment( const wxPoint& aStart, const wxPoint& aEnd, int } } -/** Plot an arc in DXF format +/* Plot an arc in DXF format * Filling is not supported */ void DXF_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius, @@ -397,6 +397,14 @@ void DXF_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, i if( radius <= 0 ) return; + // In DXF, arcs are drawn CCW. + // In Kicad, arcs are CW or CCW + // If StAngle > EndAngle, it is CW. So transform it to CCW + if( StAngle > EndAngle ) + { + EXCHG( StAngle, EndAngle ); + } + DPOINT centre_dev = userToDeviceCoordinates( centre ); double radius_dev = userToDeviceSize( radius ); @@ -425,6 +433,7 @@ void DXF_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, double EXCHG( size.x, size.y ); orient = AddAngles( orient, 900 ); } + sketchOval( pos, size, orient, -1 ); } diff --git a/lib_dxf/libdxfrw.cpp b/lib_dxf/libdxfrw.cpp index ffbba1161a..2390b38bed 100644 --- a/lib_dxf/libdxfrw.cpp +++ b/lib_dxf/libdxfrw.cpp @@ -1683,7 +1683,7 @@ DRW_ImageDef* dxfRW::writeImage( DRW_Image* ent, std::string name ) writer->writeInt16( 282, ent->contrast ); writer->writeInt16( 283, ent->fade ); writer->writeString( 360, idReactor ); - id->reactors[idReactor] = ent->handle; + id->reactors[idReactor] = toHexStr( ent->handle ); return id; } @@ -3817,9 +3817,9 @@ bool dxfRW::processImageDef() std::string dxfRW::toHexStr( int n ) { #if defined(__APPLE__) - std::string buffer( 9, '\0' ); - snprintf( &buffer[0], 9, "%X", n ); - return buffer; + char buffer[9] = { '\0' }; + snprintf( buffer, 9, "%X", n ); + return std::string( buffer ); #else std::ostringstream Convert; Convert << std::uppercase << std::hex << n; diff --git a/pcbnew/class_drawsegment.h b/pcbnew/class_drawsegment.h index 66fc4c1d4e..dacd8061d2 100644 --- a/pcbnew/class_drawsegment.h +++ b/pcbnew/class_drawsegment.h @@ -116,8 +116,9 @@ public: void SetEndY( int y ) { m_End.y = y; } void SetEndX( int x ) { m_End.x = x; } - // Arc attributes are read only, since they are "calculated" from - // m_Start, m_End, and m_Angle. No Set...() functions. + // Some attributes are read only, since they are "calculated" from + // m_Start, m_End, and m_Angle. + // No Set...() function for these attributes. const wxPoint& GetCenter() const { return m_Start; } const wxPoint& GetArcStart() const { return m_End; } @@ -140,6 +141,17 @@ public: return KiROUND( radius ); } + /** + * Initialize the start arc point. can be used for circles + * to initialize one point of the cicumference + */ + void SetArcStart( const wxPoint& aArcStartPoint ) + { m_End = aArcStartPoint; } + + /** For arcs and circles: + */ + void SetCenter( const wxPoint& aCenterPoint ) { m_Start = aCenterPoint; } + /** * Function GetParentModule * returns a pointer to the parent module, or NULL if DRAWSEGMENT does not diff --git a/pcbnew/import_dxf/dxf2brd_items.cpp b/pcbnew/import_dxf/dxf2brd_items.cpp index a077dde28b..13a8c4b429 100644 --- a/pcbnew/import_dxf/dxf2brd_items.cpp +++ b/pcbnew/import_dxf/dxf2brd_items.cpp @@ -41,9 +41,11 @@ #include #include +#include #include #include #include +#include DXF2BRD_CONVERTER::DXF2BRD_CONVERTER() : DRW_Interface() { @@ -156,10 +158,10 @@ void DXF2BRD_CONVERTER::addCircle( const DRW_Circle& data ) segm->SetLayer( m_brdLayer ); segm->SetShape( S_CIRCLE ); wxPoint center( mapX( data.basePoint.x ), mapY( data.basePoint.y ) ); - segm->SetPosition( center ); + segm->SetCenter( center ); wxPoint circle_start( mapX( data.basePoint.x + data.radious ), mapY( data.basePoint.y ) ); - segm->SetEnd( circle_start ); + segm->SetArcStart( circle_start ); segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness : data.thickness ) ); appendToBoard( segm ); @@ -178,18 +180,21 @@ void DXF2BRD_CONVERTER::addArc( const DRW_Arc& data ) // Init arc centre: wxPoint center( mapX( data.basePoint.x ), mapY( data.basePoint.y ) ); - segm->SetPosition( center ); + segm->SetCenter( center ); // Init arc start point double arcStartx = data.radious; double arcStarty = 0; - RotatePoint( &arcStartx, &arcStarty, -RAD2DECIDEG( data.staangle ) ); + double startangle = data.staangle; + double endangle = data.endangle; + + RotatePoint( &arcStartx, &arcStarty, -RAD2DECIDEG( startangle ) ); wxPoint arcStart( mapX( arcStartx + data.basePoint.x ), mapY( arcStarty + data.basePoint.y ) ); - segm->SetEnd( arcStart ); + segm->SetArcStart( arcStart ); // calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew) - double angle = -RAD2DECIDEG( data.endangle - data.staangle ); + double angle = -RAD2DECIDEG( endangle - startangle ); if( angle > 0.0 ) angle -= 3600.0; diff --git a/pcbnew/librairi.cpp b/pcbnew/librairi.cpp index ab4c32630b..e767664afd 100644 --- a/pcbnew/librairi.cpp +++ b/pcbnew/librairi.cpp @@ -378,13 +378,14 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary() wxString wildcard; - wildcard << wxGetTranslation( LegacyFootprintLibPathWildcard ) << wxChar( '|' ) - << wxGetTranslation( KiCadFootprintLibPathWildcard ); +// wildcard << wxGetTranslation( LegacyFootprintLibPathWildcard ) << wxChar( '|' ) +// << wxGetTranslation( KiCadFootprintLibPathWildcard ); + wildcard << wxGetTranslation( KiCadFootprintLibPathWildcard ) << wxChar( '|' ) + << wxGetTranslation( LegacyFootprintLibPathWildcard ); // prompt user for libPath and PLUGIN (library) type wxFileDialog dlg( this, FMT_CREATE_LIB, fn.GetPath(), wxEmptyString, - wildcard, - wxFD_SAVE + wildcard, wxFD_SAVE // | wxFD_OVERWRITE_PROMPT overwrite is tested below // after file extension has been added. ); @@ -400,7 +401,7 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary() } // wildcard's filter index has legacy in position 0. - IO_MGR::PCB_FILE_T piType = ( dlg.GetFilterIndex() == 0 ) ? IO_MGR::LEGACY : IO_MGR::KICAD; + IO_MGR::PCB_FILE_T piType = ( dlg.GetFilterIndex() == 1 ) ? IO_MGR::LEGACY : IO_MGR::KICAD; // wxFileDialog does not supply nor enforce the file extension, add it here. if( piType == IO_MGR::LEGACY ) diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 193486946f..9d0327f097 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -1008,7 +1008,7 @@ void SPECCTRA_DB::fillBOUNDARY( BOARD* aBoard, BOUNDARY* boundary ) throw( IO_ER // Set maximum proximity threshold for point to point nearness metric for // board perimeter only, not interior keepouts yet. - prox = Mils2iu( 0 ); + prox = Mils2iu( 1 ); // Output the Edge.Cuts perimeter as circle or polygon. if( graphic->GetShape() == S_CIRCLE )