KiCad PCB EDA Suite
Loading...
Searching...
No Matches
plotter_dxf.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <cstdint>
23
24#include "plotter.h"
25
29enum class DXF_COLOR_T
30{
31 BLACK = 0,
281};
282
283class DXF_PLOTTER : public PLOTTER
284{
285public:
294
295 virtual PLOT_FORMAT GetPlotterType() const override
296 {
297 return PLOT_FORMAT::DXF;
298 }
299
300 static wxString GetDefaultFileExtension()
301 {
302 return wxString( wxT( "dxf" ) );
303 }
304
308 virtual void SetTextMode( PLOT_TEXT_MODE mode ) override
309 {
310 if( mode != PLOT_TEXT_MODE::DEFAULT )
312 }
313
317 virtual bool StartPlot( const wxString& aPageNumber ) override;
318 virtual bool EndPlot() override;
319
320 // For now we don't use 'thick' primitives, so no line width
321 virtual void SetCurrentLineWidth( int width, void* aData = nullptr ) override
322 {
324 }
325
326 virtual void SetDash( int aLineWidth, LINE_STYLE aLineStyle ) override;
327
331 virtual void SetColor( const COLOR4D& color ) override;
332
339 virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
340 double aScale, bool aMirror ) override;
341
345 virtual void Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill, int width,
346 int aCornerRadius = 0 ) override;
347
354 virtual void Circle( const VECTOR2I& pos, int diametre, FILL_T fill, int width ) override;
355
356 virtual void Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
357 const EDA_ANGLE& aAngle, double aRadius, FILL_T aFill, int aWidth ) override;
358
366 virtual void PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill, int aWidth,
367 void* aData = nullptr ) override;
368
369 virtual void PlotPoly( const SHAPE_LINE_CHAIN& aLineChain, FILL_T aFill, int aWidth,
370 void* aData = nullptr ) override;
371
372 virtual void ThickSegment( const VECTOR2I& start, const VECTOR2I& end, int width,
373 void* aData ) override;
374
375 virtual void ThickArc( const VECTOR2D& aCentre, const EDA_ANGLE& aStAngle, const EDA_ANGLE& aAngle,
376 double aRadius, int aWidth, void* aData ) override;
377
378 virtual void ThickRect( const VECTOR2I& p1, const VECTOR2I& p2, int width, void* aData ) override;
379
380 virtual void ThickCircle( const VECTOR2I& pos, int diametre, int width, void* aData ) override;
381
382 virtual void FilledCircle( const VECTOR2I& pos, int diametre, void* aData ) override;
383
384 virtual void ThickPoly( const SHAPE_POLY_SET& aPoly, int aWidth, void* aData ) override;
385
386 virtual void PenTo( const VECTOR2I& pos, char plume ) override;
387
392 virtual void FlashPadCircle( const VECTOR2I& pos, int diametre, void* aData ) override;
393
397 virtual void FlashPadOval( const VECTOR2I& aPos, const VECTOR2I& aSize,
398 const EDA_ANGLE& aOrient, void* aData ) override;
399
403 virtual void FlashPadRect( const VECTOR2I& aPos, const VECTOR2I& aSize,
404 const EDA_ANGLE& aOrient, void* aData ) override;
405 virtual void FlashPadRoundRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
406 int aCornerRadius, const EDA_ANGLE& aOrient,
407 void* aData ) override;
408 virtual void FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
409 const EDA_ANGLE& aOrient, SHAPE_POLY_SET* aPolygons,
410 void* aData ) override;
411
415 virtual void FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners,
416 const EDA_ANGLE& aPadOrient, void* aData ) override;
417 virtual void FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiameter, int aCornerCount,
418 const EDA_ANGLE& aOrient, void* aData ) override;
419
420 virtual void Text( const VECTOR2I& aPos,
421 const COLOR4D& aColor,
422 const wxString& aText,
423 const EDA_ANGLE& aOrient,
424 const VECTOR2I& aSize,
425 enum GR_TEXT_H_ALIGN_T aH_justify,
426 enum GR_TEXT_V_ALIGN_T aV_justify,
427 int aWidth,
428 bool aItalic,
429 bool aBold,
430 bool aMultilineAllowed,
431 KIFONT::FONT* aFont,
432 const KIFONT::METRICS& aFontMetrics,
433 void* aData = nullptr ) override;
434
435 virtual void PlotText( const VECTOR2I& aPos,
436 const COLOR4D& aColor,
437 const wxString& aText,
438 const TEXT_ATTRIBUTES& aAttributes,
439 KIFONT::FONT* aFont,
440 const KIFONT::METRICS& aFontMetrics,
441 void* aData = nullptr ) override;
442
448 void SetUnits( DXF_UNITS aUnit );
449
456 {
457 return m_plotUnits;
458 }
459
466 double GetUnitScaling() const
467 {
468 return m_unitScalingFactor;
469 }
470
476 unsigned int GetMeasurementDirective() const
477 {
479 }
480
486 unsigned int GetInsUnits() const
487 {
488 return m_insUnits;
489 }
490
491 // Finds the nearest legacy color to the given RGB values (aR, aG, aB).
492 int FindNearestLegacyColor( int aR, int aG, int aB );
493
494 // Retrieves the current layer name based on the output mode and optional layer ID.
495 wxString GetCurrentLayerName( DXF_LAYER_OUTPUT_MODE aMode, std::optional<PCB_LAYER_ID> aLayerId = std::nullopt );
496
497protected:
498 void plotOneLineOfText( const VECTOR2I& aPos, const COLOR4D& aColor, const wxString& aText,
499 const TEXT_ATTRIBUTES& aAttrs );
500
501 // Allocate the next DXF object handle. Handle 0 is reserved by the spec.
502 std::string nextHandle();
503
504 // Emit the R2000 entity prologue (opcode + handle + owner + AcDbEntity/layer +
505 // optional subclass) and return the allocated handle. Empty aOwner defaults to
506 // the *Model_Space BLOCK_RECORD. Pass nullptr for aSubclass on SEQEND.
507 std::string emitEntityHandle( const char* aEntityType, const char* aSubclass,
508 const std::string& aLayerName,
509 const std::string& aOwner = "" );
510
511 // Writes the OBJECTS section that closes the BLOCK_RECORD 340 references. Called
512 // from EndPlot() between ENTITIES/ENDSEC and EOF.
513 void writeObjectsSection();
514
515 // Emit the standard symbol-table header (TABLE, name, handle, owner, subclass,
516 // count) and return the table handle for use as the 330 owner of child records.
517 std::string emitSymbolTableHeader( const char* aTableName, int aCount );
518
522
526 unsigned int m_insUnits;
527
528 // Monotonic handle counter; zero is reserved by the DXF spec. 64-bit so even
529 // pathological multi-million-entity exports cannot wrap into the reserved 0 handle.
530 uint64_t m_handle = 0;
531
532 // BLOCK_RECORD handle for the *Model_Space layout; cached so every entity can
533 // reference it as its 330 owner tag.
535
536 // Layout bookkeeping carried from StartPlot to EndPlot so the OBJECTS section can
537 // emit one LAYOUT object per BLOCK_RECORD with the matching 330 back-pointer.
539 {
540 std::string name; // "Model" / "Layout1" / "Layout2"
541 std::string blockName; // "*Model_Space" / "*Paper_Space" / "*Paper_Space0"
542 std::string blockRecordHandle; // BLOCK_RECORD entry handle
543 std::string layoutHandle; // LAYOUT object handle (in OBJECTS section)
545 };
546
547 std::vector<DxfLayout> m_dxfLayouts;
552};
static const COLOR4D BLACK
Definition color4d.h:406
void plotOneLineOfText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttrs)
DXF_UNITS m_plotUnits
unsigned int m_insUnits
uint64_t m_handle
unsigned int GetInsUnits() const
Get the correct value for the $INSUNITS header variable given the current units.
virtual void PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
bool m_textAsLines
virtual void FlashPadCustom(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, SHAPE_POLY_SET *aPolygons, void *aData) override
virtual void ThickCircle(const VECTOR2I &pos, int diametre, int width, void *aData) override
static wxString GetDefaultFileExtension()
std::string m_layoutDictHandle
void SetUnits(DXF_UNITS aUnit)
Set the units to use for plotting the DXF file.
std::vector< DxfLayout > m_dxfLayouts
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the scale/position for the DXF plot.
virtual void ThickArc(const VECTOR2D &aCentre, const EDA_ANGLE &aStAngle, const EDA_ANGLE &aAngle, double aRadius, int aWidth, void *aData) override
virtual void Arc(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth) override
double GetUnitScaling() const
Get the scale factor to apply to convert the device units to be in the currently set units.
virtual void FlashPadOval(const VECTOR2I &aPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, void *aData) override
DXF oval pad: always done in sketch mode.
std::string emitEntityHandle(const char *aEntityType, const char *aSubclass, const std::string &aLayerName, const std::string &aOwner="")
std::string m_plotStyleNameDictHandle
virtual void FlashPadRect(const VECTOR2I &aPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, void *aData) override
DXF rectangular pad: always done in sketch mode.
virtual void ThickRect(const VECTOR2I &p1, const VECTOR2I &p2, int width, void *aData) override
virtual void FlashPadRoundRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, int aCornerRadius, const EDA_ANGLE &aOrient, void *aData) override
virtual void ThickPoly(const SHAPE_POLY_SET &aPoly, int aWidth, void *aData) override
virtual bool StartPlot(const wxString &aPageNumber) override
Open the DXF plot with a skeleton header.
unsigned int GetMeasurementDirective() const
Get the correct value for the $MEASUREMENT field given the current units.
virtual void FlashPadTrapez(const VECTOR2I &aPadPos, const VECTOR2I *aCorners, const EDA_ANGLE &aPadOrient, void *aData) override
DXF trapezoidal pad: only sketch mode is supported.
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width) override
DXF circle: full functionality; it even does 'fills' drawing a circle with a dual-arc polyline wide a...
virtual void FlashPadCircle(const VECTOR2I &pos, int diametre, void *aData) override
DXF round pad: always done in sketch mode; it could be filled but it isn't pretty if other kinds of p...
virtual void FilledCircle(const VECTOR2I &pos, int diametre, void *aData) override
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth, void *aData=nullptr) override
DXF polygon: doesn't fill it but at least it close the filled ones DXF does not know thick outline.
std::string m_modelSpaceHandle
wxString GetCurrentLayerName(DXF_LAYER_OUTPUT_MODE aMode, std::optional< PCB_LAYER_ID > aLayerId=std::nullopt)
Retrieves the current layer name or layer color name for DXF plotting.
std::string emitSymbolTableHeader(const char *aTableName, int aCount)
std::string m_namedObjectDictHandle
void writeObjectsSection()
virtual void SetTextMode(PLOT_TEXT_MODE mode) override
DXF handles NATIVE text emitting TEXT entities.
unsigned int m_measurementDirective
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width, int aCornerRadius=0) override
DXF rectangle: fill not supported.
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
virtual bool EndPlot() override
virtual void FlashRegularPolygon(const VECTOR2I &aShapePos, int aDiameter, int aCornerCount, const EDA_ANGLE &aOrient, void *aData) override
Flash a regular polygon.
virtual void PenTo(const VECTOR2I &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
virtual void SetColor(const COLOR4D &color) override
The DXF exporter handles 'colors' as layers...
int FindNearestLegacyColor(int aR, int aG, int aB)
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
Draw text with the plotter.
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, void *aData) override
std::string m_plotStyleNormalHandle
virtual PLOT_FORMAT GetPlotterType() const override
Return the effective plot engine in use.
DXF_UNITS GetUnits() const
The units currently enabled for plotting.
double m_unitScalingFactor
virtual void SetDash(int aLineWidth, LINE_STYLE aLineStyle) override
COLOR4D m_currentColor
std::string nextHandle()
LINE_STYLE m_currentLineType
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:98
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
int m_currentPenWidth
Definition plotter.h:712
PLOTTER(const PROJECT *aProject=nullptr)
Definition plotter.cpp:48
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
@ LIGHTGREEN
Definition color4d.h:63
@ PUREORANGE
Definition color4d.h:78
@ BROWN
Definition color4d.h:61
@ PURECYAN
Definition color4d.h:70
@ LIGHTBLUE
Definition color4d.h:62
@ WHITE
Definition color4d.h:48
@ LIGHTORANGE
Definition color4d.h:77
@ BLUE
Definition color4d.h:56
@ LIGHTGRAY
Definition color4d.h:47
@ DARKGRAY
Definition color4d.h:46
@ MAGENTA
Definition color4d.h:60
@ DARKORANGE
Definition color4d.h:75
@ DARKMAGENTA
Definition color4d.h:54
@ LIGHTYELLOW
Definition color4d.h:49
@ DARKCYAN
Definition color4d.h:52
@ NBCOLORS
Number of colors.
Definition color4d.h:79
@ PURERED
Definition color4d.h:71
@ GREEN
Definition color4d.h:57
@ CYAN
Definition color4d.h:58
@ DARKRED
Definition color4d.h:53
@ DARKBLUE
Definition color4d.h:50
@ LIGHTCYAN
Definition color4d.h:64
@ ORANGE
Definition color4d.h:76
@ PUREGREEN
Definition color4d.h:69
@ LIGHTMAGENTA
Definition color4d.h:66
@ PUREYELLOW
Definition color4d.h:73
@ YELLOW
Definition color4d.h:67
@ PUREBLUE
Definition color4d.h:68
@ LIGHTRED
Definition color4d.h:65
@ BLACK
Definition color4d.h:44
@ DARKGREEN
Definition color4d.h:51
@ PUREMAGENTA
Definition color4d.h:72
@ RED
Definition color4d.h:59
@ DARKBROWN
Definition color4d.h:55
FILL_T
Definition eda_shape.h:63
DXF_UNITS
Definition plotter.h:52
PLOT_TEXT_MODE
Which kind of text to output with the PSLIKE plotters.
Definition plotter.h:100
DXF_LAYER_OUTPUT_MODE
Specifies the output mode for the DXF layer.
Definition plotter.h:123
PLOT_FORMAT
The set of supported output plot formats.
Definition plotter.h:64
DXF_COLOR_T
Legacy colors for DXF file.
Definition plotter_dxf.h:30
LINE_STYLE
Dashed line types.
std::string blockRecordHandle
VECTOR2I end
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687
VECTOR2< double > VECTOR2D
Definition vector2d.h:686