summaryrefslogtreecommitdiff
path: root/pcbnew/import_dxf/dxf2brd_items.h
blob: 7e4f7e9de836f7fa9c1735946a4013cbe7af4cca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/****************************************************************************
**
** This file comes from the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz, rallazz@gmail.com
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License as published by the Free Software
** Foundation either version 2 of the License, or (at your option)
**  any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
**
**********************************************************************/


#ifndef FILTERDXFRW_H
#define FILTERDXFRW_H

#include "drw_interface.h"
#include "wx/wx.h"
#include <list>

class BOARD;
class BOARD_ITEM;

/**
 * This format filter class can import and export DXF files.
 * It depends on the dxflib library.
 *
 * @author Rallaz
 */
class DXF2BRD_CONVERTER : public DRW_Interface
{
private:
    std::list<BOARD_ITEM*> m_newItemsList;    // The list of new items added to the board
    double m_xOffset;       // X coord offset for conversion (in mm)
    double m_yOffset;       // Y coord offset for conversion (in mm)
    double m_defaultThickness;  // default line thickness for conversion (in mm)
    double m_DXF2mm;        // The scale factor to convert DXF units to mm
    int m_brdLayer;         // The board layer to place imported DXF items
    int m_version;          // the dxf version, not used here
    std::string m_codePage; // The code page, not used here
    bool m_useModuleItems;  // Use module items instead of board items when true.

public:
    DXF2BRD_CONVERTER();
    ~DXF2BRD_CONVERTER();

    bool IsUsingModuleItems() const { return m_useModuleItems; }
    void UseModuleItems( bool aUseModuleItems = true ) { m_useModuleItems = aUseModuleItems; }

    /**
     * Set the coordinate offset between the importede dxf items
     * and Pcbnew.
     * because dxf files have the Y axis from bottom to top;
     * aOffsetX = 0, and aOffsetY = - vertical page size to import a full page
     * @param aOffsetX = the X offset in mm
     * @param aOffsetY = the Y offset in mm
     */
    void SetOffset( double aOffsetX, double aOffsetY )
    {
        m_xOffset = aOffsetX;
        m_yOffset = aOffsetY;
    }

    /**
     * Set the layer number to import dxf items.
     * the layer should be a techicanl layer, not a copper layer
     */
    void SetBrdLayer( int aBrdLayer ) { m_brdLayer = aBrdLayer; }

    /**
     * Implementation of the method used for communicate
     * with this filter.
     *
     * @param aFile = the full filename.
     */
    bool ImportDxfFile( const wxString& aFile );

    /**
     * @return the list of new BOARD_ITEM
     */
    const std::list<BOARD_ITEM*>& GetItemsList() const
    {
        return m_newItemsList;
    }

private:
    // coordinate conversions from dxf to internal units
    int mapX( double aDxfCoordX );
    int mapY( double aDxfCoordY );
    int mapDim( double aDxfValue );

    // Functions to aid in the creation of a LWPolyline
    void insertLine( const wxRealPoint& aSegStart, const wxRealPoint& aSegEnd, int aWidth );
    void insertArc( const wxRealPoint& aSegStart, const wxRealPoint& aSegEnd,
                    double aBulge, int aWidth );

    // Methods from DRW_CreationInterface:
    // They are "call back" fonctions, called when the corresponding object
    // is read in dxf file
    // Depending of the application, they can do something or not
    virtual void addHeader( const DRW_Header* aData );
    virtual void addLType( const DRW_LType& aData ) {}
    virtual void addLayer( const DRW_Layer& aData );
    virtual void addDimStyle( const DRW_Dimstyle& aData ) {}
    virtual void addBlock( const DRW_Block& aData ) {}
    virtual void endBlock() {}
    virtual void addPoint( const DRW_Point& aData ) {}
    virtual void addLine( const DRW_Line& aData);
    virtual void addRay( const DRW_Ray& aData ) {}
    virtual void addXline( const DRW_Xline& aData ) {}
    virtual void addCircle( const DRW_Circle& aData );
    virtual void addArc( const DRW_Arc& aData );
    virtual void addEllipse( const DRW_Ellipse& aData ) {}
    virtual void addLWPolyline( const DRW_LWPolyline& aData );
    virtual void addText( const DRW_Text& aData );
    virtual void addPolyline( const DRW_Polyline& aData );
    virtual void addSpline( const DRW_Spline* aData ) {}
    virtual void addKnot( const DRW_Entity&) {}
    virtual void addInsert( const DRW_Insert& aData ){}
    virtual void addTrace( const DRW_Trace& aData ){}
    virtual void addSolid( const DRW_Solid& aData ){}
    virtual void addMText( const DRW_MText& aData);
    virtual void addDimAlign( const DRW_DimAligned* aData ) {}
    virtual void addDimLinear( const DRW_DimLinear* aData ) {}
    virtual void addDimRadial( const DRW_DimRadial* aData ) {}
    virtual void addDimDiametric( const DRW_DimDiametric* aData ) {}
    virtual void addDimAngular( const DRW_DimAngular* aData ) {}
    virtual void addDimAngular3P( const DRW_DimAngular3p* aData ) {}
    virtual void addDimOrdinate( const DRW_DimOrdinate* aData ) {}
    virtual void addLeader( const DRW_Leader* aData ) {}
    virtual void addHatch( const DRW_Hatch* aData ) {}
    virtual void addImage( const DRW_Image* aData ) {}
    virtual void linkImage( const DRW_ImageDef* aData ) {}

    virtual void add3dFace( const DRW_3Dface& aData ) {}
    virtual void addComment( const char*) {}

    virtual void addVport( const DRW_Vport& aData ) {}

    virtual void addTextStyle( const DRW_Textstyle& aData );

    virtual void addViewport( const DRW_Viewport& aData ) {}

    virtual void setBlock( const int aHandle ) {}

    /**
     * Converts a native unicode string into a DXF encoded string.
     *
     * DXF endoding includes the following special sequences:
     * - %%%c for a diameter sign
     * - %%%d for a degree sign
     * - %%%p for a plus/minus sign
     */
    static wxString toDxfString( const wxString& aStr );

    /**
     * Converts a DXF encoded string into a native Unicode string.
     */
    static wxString toNativeString( const wxString& aData );

    // These functions are not used in Kicad.
    // But because they are virtual pure in DRW_Interface, they should be defined
    virtual void writeTextstyles() {}
    virtual void writeVports() {}
    virtual void writeHeader( DRW_Header& aData ) {}
    virtual void writeEntities() {}
    virtual void writeLTypes() {}
    virtual void writeLayers() {}
    virtual void writeBlockRecords() {}
    virtual void writeBlocks() {}
    virtual void writeDimstyles() {}

    void writeLine();
    void writeMtext();

    virtual void addAppId( const DRW_AppId& data ) {}
    virtual void writeAppId() {}
};

#endif  // FILTERDXFRW_H