Header clean up round 1.

This commit is contained in:
Wayne Stambaugh 2020-12-18 09:04:03 -05:00
parent 34fb55dc9c
commit bf00ebee3b
21 changed files with 1989 additions and 2122 deletions

View File

@ -35,71 +35,10 @@
/** /**
* BASE_SCREEN * Handles how to draw a screen (a board, a schematic ...)
* handles how to draw a screen (a board, a schematic ...)
*/ */
class BASE_SCREEN : public EDA_ITEM class BASE_SCREEN : public EDA_ITEM
{ {
private:
bool m_flagModified; ///< Indicates current drawing has been modified.
bool m_flagSave; ///< Indicates automatic file save.
/**
* The cross hair position in logical (drawing) units. The cross hair is not the cursor
* position. It is an addition indicator typically drawn on grid to indicate to the
* user where the current action will be performed.
*/
wxPoint m_crossHairPosition;
protected:
/**
* The number of #BASE_SCREEN objects in this design.
*
* This currently only has meaning for #SCH_SCREEN objects because #PCB_SCREEN object
* are limited to a single file. The count is virtual because #SCH_SCREEN objects can be
* used more than once so the screen (page) count can be more than the number of screen
* objects.
*/
int m_pageCount;
/**
* An integer based page number used for printing a range of pages.
*
* This page number is set before printing and plotting because page numbering does not
* reflect the actual page number in complex hiearachies in #SCH_SCREEN objects.
*/
int m_virtualPageNumber;
/**
* A user defined string page number used for printing and plotting.
*
* This currently only has meaning for #SCH_SCREEN objects because #PCB_SCREEN object
* are limited to a single file. This must be set before displaying, printing, or
* plotting the current sheet. If empty, the #m_virtualPageNumber value is converted
* to a string.
*/
wxString m_pageNumber;
public:
static wxString m_PageLayoutDescrFileName; ///< the name of the page layout descr file,
///< or emty to used the default pagelayout
wxPoint m_DrawOrg; ///< offsets for drawing the circuit on the screen
VECTOR2D m_LocalOrigin; ///< Relative Screen cursor coordinate (on grid)
///< in user units. (coordinates from last reset position)
wxPoint m_StartVisu; ///< Coordinates in drawing units of the current
///< view position (upper left corner of device)
bool m_Center; ///< Center on screen. If true (0.0) is centered on screen
///< coordinates can be < 0 and > 0 except for schematics.
///< false: when coordinates can only be >= 0 (schematics).
VECTOR2D m_ScrollCenter; ///< Current scroll center point in logical units.
bool m_Initialized;
public: public:
BASE_SCREEN( EDA_ITEM* aParent, KICAD_T aType = SCREEN_T ); BASE_SCREEN( EDA_ITEM* aParent, KICAD_T aType = SCREEN_T );
@ -142,9 +81,69 @@ public:
const wxString& GetPageNumber() const; const wxString& GetPageNumber() const;
void SetPageNumber( const wxString& aPageNumber ) { m_pageNumber = aPageNumber; } void SetPageNumber( const wxString& aPageNumber ) { m_pageNumber = aPageNumber; }
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override; void Show( int nestLevel, std::ostream& os ) const override;
#endif #endif
static wxString m_PageLayoutDescrFileName; ///< the name of the page layout descr file,
///< or emty to used the default pagelayout
wxPoint m_DrawOrg; ///< offsets for drawing the circuit on the screen
VECTOR2D m_LocalOrigin; ///< Relative Screen cursor coordinate (on grid)
///< in user units. (coordinates from last reset position)
wxPoint m_StartVisu; ///< Coordinates in drawing units of the current
///< view position (upper left corner of device)
bool m_Center; ///< Center on screen. If true (0.0) is centered on screen
///< coordinates can be < 0 and > 0 except for schematics.
///< false: when coordinates can only be >= 0 (schematics).
VECTOR2D m_ScrollCenter; ///< Current scroll center point in logical units.
bool m_Initialized;
protected:
/**
* The number of #BASE_SCREEN objects in this design.
*
* This currently only has meaning for #SCH_SCREEN objects because #PCB_SCREEN object
* are limited to a single file. The count is virtual because #SCH_SCREEN objects can be
* used more than once so the screen (page) count can be more than the number of screen
* objects.
*/
int m_pageCount;
/**
* An integer based page number used for printing a range of pages.
*
* This page number is set before printing and plotting because page numbering does not
* reflect the actual page number in complex hiearachies in #SCH_SCREEN objects.
*/
int m_virtualPageNumber;
/**
* A user defined string page number used for printing and plotting.
*
* This currently only has meaning for #SCH_SCREEN objects because #PCB_SCREEN object
* are limited to a single file. This must be set before displaying, printing, or
* plotting the current sheet. If empty, the #m_virtualPageNumber value is converted
* to a string.
*/
wxString m_pageNumber;
private:
bool m_flagModified; ///< Indicates current drawing has been modified.
bool m_flagSave; ///< Indicates automatic file save.
/**
* The cross hair position in logical (drawing) units. The cross hair is not the cursor
* position. It is an addition indicator typically drawn on grid to indicate to the
* user where the current action will be performed.
*/
wxPoint m_crossHairPosition;
}; };
#endif // BASE_SCREEN_H #endif // BASE_SCREEN_H

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -35,8 +35,8 @@ class PLOTTER;
/* /*
* BASIC_GAL is a minimal GAL implementation to draw, plot and convert * A minimal GAL implementation to draw, plot and convert stroke texts to a set of segments
* stroke texts to a set of segments for DRC tests, and to calculate text sizes. * for DRC tests, and to calculate text sizes.
* *
* Currently it allows one to use GAL and STROKE_FONT methods in legacy draw mode * Currently it allows one to use GAL and STROKE_FONT methods in legacy draw mode
* (using wxDC functions) in plot functions only for texts. * (using wxDC functions) in plot functions only for texts.
@ -56,24 +56,17 @@ struct TRANSFORM_PRM // A helper class to transform coordinates in BASIC_GAL
double m_rotAngle; double m_rotAngle;
}; };
class BASIC_GAL: public KIGFX::GAL class BASIC_GAL: public KIGFX::GAL
{ {
public:
wxDC* m_DC;
COLOR4D m_Color;
private:
TRANSFORM_PRM m_transform;
std::stack <TRANSFORM_PRM> m_transformHistory;
public: public:
BASIC_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions ) : BASIC_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions ) :
GAL( aDisplayOptions ) GAL( aDisplayOptions )
{ {
m_DC = NULL; m_DC = nullptr;
m_Color = RED; m_Color = RED;
m_plotter = NULL; m_plotter = nullptr;
m_callback = NULL; m_callback = nullptr;
m_callbackData = nullptr; m_callbackData = nullptr;
m_isClipped = false; m_isClipped = false;
} }
@ -83,7 +76,8 @@ public:
m_plotter = aPlotter; m_plotter = aPlotter;
} }
void SetCallback( void (* aCallback)( int x0, int y0, int xf, int yf, void* aData ), void* aData ) void SetCallback( void (* aCallback)( int x0, int y0, int xf, int yf, void* aData ),
void* aData )
{ {
m_callback = aCallback; m_callback = aCallback;
m_callbackData = aData; m_callbackData = aData;
@ -93,13 +87,13 @@ public:
/// If NULL, no clip will be made /// If NULL, no clip will be made
void SetClipBox( EDA_RECT* aClipBox ) void SetClipBox( EDA_RECT* aClipBox )
{ {
m_isClipped = aClipBox != NULL; m_isClipped = aClipBox != nullptr;
if( aClipBox ) if( aClipBox )
m_clipBox = *aClipBox; m_clipBox = *aClipBox;
} }
/// @brief Save the context. /// Save the context.
virtual void Save() override virtual void Save() override
{ {
m_transformHistory.push( m_transform ); m_transformHistory.push( m_transform );
@ -112,21 +106,24 @@ public:
} }
/** /**
* @brief Draw a polyline * Draw a polyline
*
* @param aPointList is a list of 2D-Vectors containing the polyline points. * @param aPointList is a list of 2D-Vectors containing the polyline points.
*/ */
virtual void DrawPolyline( const std::deque<VECTOR2D>& aPointList ) override; virtual void DrawPolyline( const std::deque<VECTOR2D>& aPointList ) override;
virtual void DrawPolyline( const VECTOR2D aPointList[], int aListSize ) override; virtual void DrawPolyline( const VECTOR2D aPointList[], int aListSize ) override;
/** Start and end points are defined as 2D-Vectors. /**
* Start and end points are defined as 2D-Vectors.
*
* @param aStartPoint is the start point of the line. * @param aStartPoint is the start point of the line.
* @param aEndPoint is the end point of the line. * @param aEndPoint is the end point of the line.
*/ */
virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) override; virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) override;
/** /**
* @brief Translate the context. * Translate the context.
* *
* @param aTranslation is the translation vector. * @param aTranslation is the translation vector.
*/ */
@ -136,7 +133,7 @@ public:
} }
/** /**
* @brief Rotate the context. * Rotate the context.
* *
* @param aAngle is the rotation angle in radians. * @param aAngle is the rotation angle in radians.
*/ */
@ -152,6 +149,14 @@ private:
// Apply the roation/translation transform to aPoint // Apply the roation/translation transform to aPoint
const VECTOR2D transform( const VECTOR2D& aPoint ) const; const VECTOR2D transform( const VECTOR2D& aPoint ) const;
public:
wxDC* m_DC;
COLOR4D m_Color;
private:
TRANSFORM_PRM m_transform;
std::stack <TRANSFORM_PRM> m_transformHistory;
// A clip box, to clip drawings in a wxDC (mandatory to avoid draw issues) // A clip box, to clip drawings in a wxDC (mandatory to avoid draw issues)
EDA_RECT m_clipBox; // The clip box EDA_RECT m_clipBox; // The clip box
bool m_isClipped; // Allows/disallows clipping bool m_isClipped; // Allows/disallows clipping
@ -162,8 +167,7 @@ private:
void (* m_callback)( int x0, int y0, int xf, int yf, void* aData ); void (* m_callback)( int x0, int y0, int xf, int yf, void* aData );
void* m_callbackData; // a optional parameter for m_callback void* m_callbackData; // a optional parameter for m_callback
// When calling the draw functions for plot, the plotter acts as a wxDC // When calling the draw functions for plot, the plotter acts as a wxDC to plot basic items.
// to plot basic items
PLOTTER* m_plotter; PLOTTER* m_plotter;
}; };

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2014-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,6 +24,7 @@
#ifndef BIN_MOD_H_ #ifndef BIN_MOD_H_
#define BIN_MOD_H_ #define BIN_MOD_H_
/// @todo Should this be a check for the wxWidgets version rather that `#if 0`.
#if 0 #if 0
#include <wx/filehistory.h> // wx 3.0: #include <wx/filehistory.h> // wx 3.0:
#else #else
@ -38,12 +39,11 @@
class APP_SETTINGS_BASE; class APP_SETTINGS_BASE;
/** /**
* Struct BIN_MOD * Pertains to a single program module, either an EXE or a DSO/DLL ("bin_mod").
* pertains to a single program module, either an EXE or a DSO/DLL ("bin_mod"). *
* It manages miscellaneous configuration file information pertinent to one bin_mod. * It manages miscellaneous configuration file information pertinent to one bin_mod.
* Because it serves in both DSO/DLLs and in EXEs, its name is neutral. * Because it serves in both DSO/DLLs and in EXEs, its name is neutral. Accessors are
* <p> * in containing (wrapper) classes.
* Accessors are in containing (wrapper) classes.
*/ */
struct BIN_MOD struct BIN_MOD
{ {
@ -54,8 +54,9 @@ struct BIN_MOD
void End(); void End();
/** /**
* Takes ownership of a new application settings object * Takes ownership of a new application settings object.
* @param aPtr is the settings object for this module *
* @param aPtr is the settings object for this module.
*/ */
void InitSettings( APP_SETTINGS_BASE* aPtr ) { m_config = aPtr; } void InitSettings( APP_SETTINGS_BASE* aPtr ) { m_config = aPtr; }
@ -65,8 +66,6 @@ struct BIN_MOD
wxString m_help_file; wxString m_help_file;
SEARCH_STACK m_search; SEARCH_STACK m_search;
}; };
#endif // BIN_MOD_H_ #endif // BIN_MOD_H_

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 jean-pierre.charras jp.charras at wanadoo.fr * Copyright (C) 2018 jean-pierre.charras jp.charras at wanadoo.fr
* Copyright (C) 2013-2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -41,27 +41,15 @@ class PLOTTER;
/** /**
* This class handle bitmap images in KiCad. * This class handle bitmap images in KiCad.
* It is not intended to be used alone, but inside another class,
* so all methods are protected ( or private )
* It is used in SCH_BITMAP class and WS_DRAW_ITEM_BITMAP (and other in future)
* *
* Remember not all plotters are able to plot a bitmap * It is not intended to be used alone, but inside another class so all methods are protected
* Mainly GERBER plotters cannot. * or private. It is used in #SCH_BITMAP class, #WS_DRAW_ITEM_BITMAP, and possibly others in
* the future.
*
* @warning Not all plotters are able to plot a bitmap. Mainly GERBER plotters cannot.
*/ */
class BITMAP_BASE class BITMAP_BASE
{ {
private:
double m_scale; // The scaling factor of the bitmap
// With m_pixelSizeIu, controls the actual draw size
wxImage* m_image; // the raw image data (png format)
wxBitmap* m_bitmap; // the bitmap used to draw/plot image
double m_pixelSizeIu; // The scaling factor of the bitmap
// to convert the bitmap size (in pixels)
// to internal KiCad units
// Usually does not change
int m_ppi; // the bitmap definition. the default is 300PPI
public: public:
BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) ); BITMAP_BASE( const wxPoint& pos = wxPoint( 0, 0 ) );
@ -73,7 +61,6 @@ public:
delete m_image; delete m_image;
} }
/* /*
* Accessors: * Accessors:
*/ */
@ -93,9 +80,9 @@ public:
void SetScale( double aScale ) { m_scale = aScale; } void SetScale( double aScale ) { m_scale = aScale; }
/* /*
* Function RebuildBitmap * Rebuild the internal bitmap used to draw/plot image.
* Rebuild the internal bitmap used to draw/plot image *
* must be called after a m_image change * This must be called after a #m_image change.
*/ */
void RebuildBitmap() { *m_bitmap = wxBitmap( *m_image ); } void RebuildBitmap() { *m_bitmap = wxBitmap( *m_image ); }
@ -106,36 +93,32 @@ public:
} }
/** /**
* Function ImportData * Copy aItem image to this object and update #m_bitmap.
* Copy aItem image to me and update m_bitmap
*/ */
void ImportData( BITMAP_BASE* aItem ); void ImportData( BITMAP_BASE* aItem );
/** /**
* Function GetScalingFactor * This scaling factor depends on #m_pixelSizeIu and #m_scale.
* @return the scaling factor from pixel size to actual draw size *
* this scaling factor depends on m_pixelSizeIu and m_scale * #m_pixelSizeIu gives the scaling factor between a pixel size and the internal units.
* m_pixelSizeIu gives the scaling factor between a pixel size and * #m_scale is an user dependent value, and gives the "zoom" value.
* the internal schematic units * - #m_scale = 1.0 = original size of bitmap.
* m_scale is an user dependant value, and gives the "zoom" value * - #m_scale < 1.0 = the bitmap is drawn smaller than its original size.
* m_scale = 1.0 = original size of bitmap. * - #m_scale > 1.0 = the bitmap is drawn bigger than its original size.
* m_scale < 1.0 = the bitmap is drawn smaller than its original size. *
* m_scale > 1.0 = the bitmap is drawn bigger than its original size. * @return The scaling factor from pixel size to actual draw size.
*/ */
double GetScalingFactor() const double GetScalingFactor() const
{ {
return m_pixelSizeIu * m_scale; return m_pixelSizeIu * m_scale;
} }
/** /**
* Function GetSize
* @return the actual size (in user units, not in pixels) of the image * @return the actual size (in user units, not in pixels) of the image
*/ */
wxSize GetSize() const; wxSize GetSize() const;
/** /**
* Function GetSizePixels
* @return the size in pixels of the image * @return the size in pixels of the image
*/ */
wxSize GetSizePixels() const wxSize GetSizePixels() const
@ -147,8 +130,7 @@ public:
} }
/** /**
* @return the bitmap definition in ppi * @return the bitmap definition in ppi, the default is 300 ppi.
* the default is 300 ppi
*/ */
int GetPPI() const int GetPPI() const
{ {
@ -156,12 +138,11 @@ public:
} }
/** /**
* Function GetBoundingBox * Return the orthogonal, bounding box of this object for display purposes.
* returns the orthogonal, bounding box of this object for display *
* purposes. This box should be an enclosing perimeter for visible * This box should be an enclosing perimeter for visible components of this object,
* components of this object, and the units should be in the pcb or * and the units should be in the pcb or schematic coordinate system. It is OK to
* schematic coordinate system. It is OK to overestimate the size * overestimate the size by a few counts.
* by a few counts.
*/ */
const EDA_RECT GetBoundingBox() const; const EDA_RECT GetBoundingBox() const;
@ -170,83 +151,98 @@ public:
/** /**
* Reads and stores in memory an image file. * Reads and stores in memory an image file.
* *
* Init the bitmap format used to draw this item. * Initialize the bitmap format used to draw this item. Supported images formats are
* supported images formats are format supported by wxImage * format supported by wxImage if all handlers are loaded. By default, .png, .jpeg
* if all handlers are loaded * are always loaded.
* by default, .png, .jpeg are always loaded
* *
* @param aFullFilename The full filename of the image file to read. * @param aFullFilename The full filename of the image file to read.
* @return bool - true if success reading else false. * @return true if success reading else false.
*/ */
bool ReadImageFile( const wxString& aFullFilename ); bool ReadImageFile( const wxString& aFullFilename );
/** /**
* Reads and stores in memory an image file. * Reads and stores in memory an image file.
* *
* Init the bitmap format used to draw this item. * Initialize the bitmap format used to draw this item.
* supported images formats are format supported by wxImage
* if all handlers are loaded
* by default, .png, .jpeg are always loaded
* *
* @param aInStream an input stream containing the file data * Supported images formats are format supported by wxImage if all handlers are loaded.
* @return bool - true if success reading else false. * By default, .png, .jpeg are always loaded.
*
* @param aInStream an input stream containing the file data.
* @return true if success reading else false.
*/ */
bool ReadImageFile( wxInputStream& aInStream ); bool ReadImageFile( wxInputStream& aInStream );
/** /**
* writes the bitmap data to aFile * Write the bitmap data to \a aFile.
* The format is png, in Hexadecimal form: *
* If the hexadecimal data is converted to binary it gives exactly a .png image data * The file format is png, in hexadecimal form. If the hexadecimal data is converted to
* binary it gives exactly a .png image data.
*
* @param aFile The FILE to write to. * @param aFile The FILE to write to.
* @return bool - true if success writing else false. * @return true if success writing else false.
*/ */
bool SaveData( FILE* aFile ) const; bool SaveData( FILE* aFile ) const;
/** /**
* writes the bitmap data to an array string * Write the bitmap data to an array string.
* The format is png, in Hexadecimal form: *
* If the hexadecimal data is converted to binary it gives exactly a .png image data * The format is png, in Hexadecimal form. If the hexadecimal data is converted to binary
* it gives exactly a .png image data.
*
* @param aPngStrings The wxArrayString to write to. * @param aPngStrings The wxArrayString to write to.
*/ */
void SaveData( wxArrayString& aPngStrings ) const; void SaveData( wxArrayString& aPngStrings ) const;
/** /**
* Load an image data saved by SaveData (png, in Hexadecimal form) * Load an image data saved by #SaveData.
* @param aLine - the LINE_READER used to read the data file. *
* @param aErrorMsg - Description of the error if an error occurs while loading the * The file format must be png format in hexadecimal.
* png bimap data. *
* @param aLine the LINE_READER used to read the data file.
* @param aErrorMsg Description of the error if an error occurs while loading the
* png bitmap data.
* @return true if the bitmap loaded successfully. * @return true if the bitmap loaded successfully.
*/ */
bool LoadData( LINE_READER& aLine, wxString& aErrorMsg ); bool LoadData( LINE_READER& aLine, wxString& aErrorMsg );
/** /**
* Function Mirror * Mirror image vertically (i.e. relative to its horizontal X axis ) or horizontally (i.e
* Mirror image vertically (i.e. relative to its horizontal X axis ) * relative to its vertical Y axis).
* or horizontally (i.e relative to its vertical Y axis) * @param aVertically false to mirror horizontally or true to mirror vertically.
* @param aVertically = false to mirror horizontally
* or true to mirror vertically
*/ */
void Mirror( bool aVertically ); void Mirror( bool aVertically );
/** /**
* Function Rotate
* Rotate image CW or CCW. * Rotate image CW or CCW.
* @param aRotateCCW = true to rotate CCW *
* @param aRotateCCW true to rotate CCW or false to rotate CW.
*/ */
void Rotate( bool aRotateCCW ); void Rotate( bool aRotateCCW );
/** /**
* Function PlotImage
* Plot bitmap on plotter. * Plot bitmap on plotter.
*
* If the plotter does not support bitmaps, plot a * If the plotter does not support bitmaps, plot a
* @param aPlotter = the plotter to use *
* @param aPos = the position od the center of the bitmap * @param aPlotter the plotter to use.
* @param aDefaultColor = the color used to plot the rectangle when bitmap is not supported * @param aPos the position of the center of the bitmap.
* @param aDefaultPensize = the pen size used to plot the rectangle when bitmap is not supported * @param aDefaultColor the color used to plot the rectangle when bitmap is not supported.
* @param aDefaultPensize the pen size used to plot the rectangle when bitmap is not supported.
*/ */
void PlotImage( PLOTTER* aPlotter, const wxPoint& aPos, void PlotImage( PLOTTER* aPlotter, const wxPoint& aPos,
KIGFX::COLOR4D aDefaultColor, int aDefaultPensize ); KIGFX::COLOR4D aDefaultColor, int aDefaultPensize );
private:
double m_scale; // The scaling factor of the bitmap
// With m_pixelSizeIu, controls the actual draw size
wxImage* m_image; // the raw image data (png format)
wxBitmap* m_bitmap; // the bitmap used to draw/plot image
double m_pixelSizeIu; // The scaling factor of the bitmap
// to convert the bitmap size (in pixels)
// to internal KiCad units
// Usually does not change
int m_ppi; // the bitmap definition. the default is 300PPI
}; };

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wandadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wandadoo.fr
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -43,9 +43,7 @@ class SHAPE;
class PCB_GROUP; class PCB_GROUP;
/** /**
* Enum PCB_SHAPE_TYPE_T * The set of shapes for PCB graphics and tracks and footprint graphics in the .m_Shape member
* is the set of shapes for PCB graphics and tracks and footprint graphics
* in the .m_Shape member
*/ */
enum PCB_SHAPE_TYPE_T enum PCB_SHAPE_TYPE_T
{ {
@ -77,18 +75,12 @@ static inline wxString PCB_SHAPE_TYPE_T_asString( PCB_SHAPE_TYPE_T a )
/** /**
* BOARD_ITEM * A base class for any item which can be embedded within the #BOARD container class, and
* is a base class for any item which can be embedded within the BOARD * therefore instances of derived classes should only be found in Pcbnew or other programs
* container class, and therefore instances of derived classes should only be * that use class #BOARD and its contents.
* found in Pcbnew or other programs that use class BOARD and its contents.
* The corresponding class in Eeschema is SCH_ITEM.
*/ */
class BOARD_ITEM : public EDA_ITEM class BOARD_ITEM : public EDA_ITEM
{ {
protected:
PCB_LAYER_ID m_layer;
PCB_GROUP* m_group;
public: public:
BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
EDA_ITEM( aParent, idtype ), EDA_ITEM( aParent, idtype ),
@ -115,11 +107,9 @@ public:
} }
/** /**
* Function GetCenter()
*
* This defaults to the center of the bounding box if not overridden. * This defaults to the center of the bounding box if not overridden.
* *
* @return centre point of the item * @return center point of the item
*/ */
virtual wxPoint GetCenter() const virtual wxPoint GetCenter() const
{ {
@ -139,8 +129,8 @@ public:
} }
/** /**
* Function IsConnected()
* Returns information if the object is derived from BOARD_CONNECTED_ITEM. * Returns information if the object is derived from BOARD_CONNECTED_ITEM.
*
* @return True if the object is of BOARD_CONNECTED_ITEM type, false otherwise. * @return True if the object is of BOARD_CONNECTED_ITEM type, false otherwise.
*/ */
virtual bool IsConnected() const virtual bool IsConnected() const
@ -162,12 +152,11 @@ public:
static wxPoint ZeroOffset; static wxPoint ZeroOffset;
/** /**
* Function GetEffectiveShape
* Some pad shapes can be complex (rounded/chamfered rectangle), even without considering * Some pad shapes can be complex (rounded/chamfered rectangle), even without considering
* custom shapes. This routine returns a COMPOUND shape (set of simple shapes which make * custom shapes. This routine returns a COMPOUND shape (set of simple shapes which make
* up the pad fod use with routing, collision determiniation, etc). * up the pad for use with routing, collision determination, etc).
* *
* Note that this list can contain a SHAPE_SIMPLE (a simple single-outline non-intersecting * @note This list can contain a SHAPE_SIMPLE (a simple single-outline non-intersecting
* polygon), but should never contain a SHAPE_POLY_SET (a complex polygon consisting of * polygon), but should never contain a SHAPE_POLY_SET (a complex polygon consisting of
* multiple outlines and/or holes). * multiple outlines and/or holes).
* *
@ -179,14 +168,12 @@ public:
BOARD_ITEM_CONTAINER* GetParent() const { return (BOARD_ITEM_CONTAINER*) m_parent; } BOARD_ITEM_CONTAINER* GetParent() const { return (BOARD_ITEM_CONTAINER*) m_parent; }
/** /**
* Function GetLayer * Return the primary layer this item is on.
* returns the primary layer this item is on.
*/ */
virtual PCB_LAYER_ID GetLayer() const { return m_layer; } virtual PCB_LAYER_ID GetLayer() const { return m_layer; }
/** /**
* Function GetLayerSet * Return a std::bitset of all layers on which the item physically resides.
* returns a std::bitset of all layers on which the item physically resides.
*/ */
virtual LSET GetLayerSet() const { return LSET( m_layer ); } virtual LSET GetLayerSet() const { return LSET( m_layer ); }
virtual void SetLayerSet( LSET aLayers ) virtual void SetLayerSet( LSET aLayers )
@ -197,11 +184,12 @@ public:
} }
/** /**
* Function SetLayer * Set the layer this item is on.
* sets the layer this item is on. *
* This method is virtual because some items (in fact: class DIMENSION)
* have a slightly different initialization.
*
* @param aLayer The layer number. * @param aLayer The layer number.
* is virtual because some items (in fact: class DIMENSION)
* have a slightly different initialization
*/ */
virtual void SetLayer( PCB_LAYER_ID aLayer ) virtual void SetLayer( PCB_LAYER_ID aLayer )
{ {
@ -209,8 +197,7 @@ public:
} }
/** /**
* Function Duplicate * Create a copy of a of this #BOARD_ITEM.
* creates a copy of a BOARD_ITEM.
*/ */
virtual BOARD_ITEM* Duplicate() const virtual BOARD_ITEM* Duplicate() const
{ {
@ -221,20 +208,25 @@ public:
} }
/** /**
* Swap data between aItem and aImage. * Swap data between \a aItem and \a aImage.
* aItem and aImage should have the same type *
* Used in undo redo command to swap values between an item and its copy * \a aItem and \a aImage should have the same type.
* Only values like layer, size .. which are modified by editing are swapped *
* @param aImage = the item image which contains data to swap * Used in undo and redo commands to swap values between an item and its copy.
* Only values like layer, size .. which are modified by editing are swapped.
*
* @param aImage the item image which contains data to swap.
*/ */
virtual void SwapData( BOARD_ITEM* aImage ); virtual void SwapData( BOARD_ITEM* aImage );
/** /**
* Function IsOnLayer * Test to see if this object is on the given layer.
* tests to see if this object is on the given layer. Virtual so objects like PAD, which *
* reside on multiple layers can do their own form of testing. * Virtual so objects like #PAD, which reside on multiple layers can do their own form
* of testing.
*
* @param aLayer The layer to test for. * @param aLayer The layer to test for.
* @return bool - true if on given layer, else false. * @return true if on given layer, else false.
*/ */
virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const virtual bool IsOnLayer( PCB_LAYER_ID aLayer ) const
{ {
@ -242,10 +234,9 @@ public:
} }
/** /**
* Function IsTrack * Test to see if this object is a track or via (or microvia).
* tests to see if this object is a track or via (or microvia). *
* form of testing. * @return true if a track or via, else false.
* @return bool - true if a track or via, else false.
*/ */
bool IsTrack() const bool IsTrack() const
{ {
@ -253,8 +244,7 @@ public:
} }
/** /**
* Function IsLocked * @return true if the object is locked, else false.
* @return bool - true if the object is locked, else false
*/ */
virtual bool IsLocked() const virtual bool IsLocked() const
{ {
@ -263,8 +253,7 @@ public:
} }
/** /**
* Function SetLocked * Modify the 'lock' status for of the item.
* modifies 'lock' status for of the item.
*/ */
virtual void SetLocked( bool aLocked ) virtual void SetLocked( bool aLocked )
{ {
@ -272,22 +261,19 @@ public:
} }
/** /**
* Function DeleteStructure * Delete this object after removing from its parent if it has one.
* deletes this object after removing from its parent if it has one.
*/ */
void DeleteStructure(); void DeleteStructure();
/** /**
* Function ShowShape * Convert the enum #PCB_SHAPE_TYPE_T integer value to a wxString.
* converts the enum PCB_SHAPE_TYPE_T integer value to a wxString.
*/ */
static wxString ShowShape( PCB_SHAPE_TYPE_T aShape ); static wxString ShowShape( PCB_SHAPE_TYPE_T aShape );
// Some geometric transforms, that must be rewritten for derived classes
/** /**
* Function Move * Move this object.
* move this object. *
* @param aMoveVector - the move vector for this object. * @param aMoveVector the move vector for this object.
*/ */
virtual void Move( const wxPoint& aMoveVector ) virtual void Move( const wxPoint& aMoveVector )
{ {
@ -301,10 +287,10 @@ public:
} }
/** /**
* Function Rotate
* Rotate this object. * Rotate this object.
* @param aRotCentre - the rotation point. *
* @param aAngle - the rotation angle in 0.1 degree. * @param aRotCentre the rotation point.
* @param aAngle the rotation angle in 0.1 degree.
*/ */
virtual void Rotate( const wxPoint& aRotCentre, double aAngle ) virtual void Rotate( const wxPoint& aRotCentre, double aAngle )
{ {
@ -317,10 +303,10 @@ public:
} }
/** /**
* Function Flip * Flip this object, i.e. change the board side for this object.
* Flip this object, i.e. change the board side for this object *
* @param aCentre - the rotation point. * @param aCentre the rotation point.
* @param aFlipLeftRight - mirror across Y axis instead of X (the default) * @param aFlipLeftRight mirror across Y axis instead of X (the default).
*/ */
virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) virtual void Flip( const wxPoint& aCentre, bool aFlipLeftRight )
{ {
@ -333,32 +319,30 @@ public:
} }
/** /**
* Function GetBoard * Return the #BOARD in which this #BOARD_ITEM resides, or NULL if none.
* returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
*/ */
virtual BOARD* GetBoard() const; virtual BOARD* GetBoard() const;
/** /**
* Function GetLayerName * Return the name of the PCB layer on which the item resides.
* returns the name of the PCB layer on which the item resides.
* *
* @return wxString containing the layer name associated with this item. * @return the layer name associated with this item.
*/ */
wxString GetLayerName() const; wxString GetLayerName() const;
virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
/** /**
* Function TransformShapeWithClearanceToPolygon * Convert the item shape to a closed polygon.
* Convert the item shape to a closed polygon *
* Used in filling zones calculations * Used in filling zones calculations. Circles and arcs are approximated by segments.
* Circles and arcs are approximated by segments *
* @param aCornerBuffer = a buffer to store the polygon * @param aCornerBuffer a buffer to store the polygon.
* @param aClearanceValue = the clearance around the pad * @param aClearanceValue the clearance around the pad.
* @param aError = the maximum deviation from true circle * @param aError the maximum deviation from true circle.
* @param aErrorLoc = should the approximation error be placed outside or inside the polygon? * @param aErrorLoc should the approximation error be placed outside or inside the polygon?
* @param ignoreLineWidth = used for edge cut items where the line width is only * @param ignoreLineWidth used for edge cut items where the line width is only
* for visualization * for visualization.
*/ */
virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, virtual void TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer,
PCB_LAYER_ID aLayer, int aClearanceValue, PCB_LAYER_ID aLayer, int aClearanceValue,
@ -376,6 +360,9 @@ protected:
* because layer names are customizable. * because layer names are customizable.
*/ */
virtual wxString layerMaskDescribe() const; virtual wxString layerMaskDescribe() const;
PCB_LAYER_ID m_layer;
PCB_GROUP* m_group;
}; };
#ifndef SWIG #ifndef SWIG
@ -385,6 +372,7 @@ DECLARE_ENUM_TO_WXANY( PCB_LAYER_ID );
/** /**
* A singleton item of this class is returned for a weak reference that no longer exists. * A singleton item of this class is returned for a weak reference that no longer exists.
*
* Its sole purpose is to flag the item as having been deleted. * Its sole purpose is to flag the item as having been deleted.
*/ */
class DELETED_BOARD_ITEM : public BOARD_ITEM class DELETED_BOARD_ITEM : public BOARD_ITEM

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018 CERN * Copyright (C) 2018 CERN
* Author: Maciej Suminski <maciej.suminski@cern.ch> * Author: Maciej Suminski <maciej.suminski@cern.ch>
* *
@ -62,16 +62,16 @@ struct BOARD_PRINTOUT_SETTINGS : public PRINTOUT_SETTINGS
void Save( APP_SETTINGS_BASE* aConfig ) override; void Save( APP_SETTINGS_BASE* aConfig ) override;
}; };
/** /**
* BOARD_PRINTOUT * An object derived from wxPrintout to handle the necessary information to control a printer
* is a class derived from wxPrintout to handle the necessary information to control a printer * when printing a board.
* when printing a board
*/ */
class BOARD_PRINTOUT : public wxPrintout class BOARD_PRINTOUT : public wxPrintout
{ {
public: public:
BOARD_PRINTOUT( const BOARD_PRINTOUT_SETTINGS& aParams, const KIGFX::VIEW* aView, BOARD_PRINTOUT( const BOARD_PRINTOUT_SETTINGS& aParams, const KIGFX::VIEW* aView,
const wxString& aTitle ); const wxString& aTitle );
virtual ~BOARD_PRINTOUT() {} virtual ~BOARD_PRINTOUT() {}
@ -84,14 +84,16 @@ public:
/** /**
* Print a page (or a set of pages). * Print a page (or a set of pages).
* Note: this function prepare print parameters for the function *
* which actually print the draw layers. * @note This function prepares the print parameters for the function which actually prints
* @param aLayerName = a text which can be printed as layer name * the draw layers.
* @param aPageNum = the number of the current page (only used to print this value) *
* @param aPageCount = the number of pages to ptint (only used to print this value) * @param aLayerName a text which can be printed as layer name.
* @param aPageNum the number of the current page (only used to print this value).
* @param aPageCount the number of pages to ptint (only used to print this value).
*/ */
virtual void DrawPage( const wxString& aLayerName = wxEmptyString, virtual void DrawPage( const wxString& aLayerName = wxEmptyString,
int aPageNum = 1, int aPageCount = 1 ); int aPageNum = 1, int aPageCount = 1 );
protected: protected:
///> Convert mils to internal units ///> Convert mils to internal units

View File

@ -77,7 +77,7 @@ public:
* If \p aParentWindow is not an EDA frame, a search through all the parents * If \p aParentWindow is not an EDA frame, a search through all the parents
* of the parent window will be done to find the frame. * of the parent window will be done to find the frame.
* *
* @param aParentWindow is the window immeidately containing this panel * @param aParentWindow is the window immediately containing this panel
*/ */
EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId, EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWindowId,
const wxPoint& aPosition, const wxSize& aSize, const wxPoint& aPosition, const wxSize& aSize,
@ -88,36 +88,35 @@ public:
virtual void SetFocus() override; virtual void SetFocus() override;
/** /**
* Function SwitchBackend * Switch method of rendering graphics.
* Switches method of rendering graphics. *
* @param aGalType is a type of rendering engine that you want to use. * @param aGalType is a type of rendering engine that you want to use.
*/ */
virtual bool SwitchBackend( GAL_TYPE aGalType ); virtual bool SwitchBackend( GAL_TYPE aGalType );
/** /**
* Function GetBackend * Return the type of backend currently used by GAL canvas.
* Returns the type of backend currently used by GAL canvas.
*/ */
inline GAL_TYPE GetBackend() const { return m_backend; } inline GAL_TYPE GetBackend() const { return m_backend; }
/** /**
* Function GetGAL() * Return a pointer to the GAL instance used in the panel.
* Returns a pointer to the GAL instance used in the panel. *
* @return The instance of GAL. * @return The instance of GAL.
*/ */
KIGFX::GAL* GetGAL() const { return m_gal; } KIGFX::GAL* GetGAL() const { return m_gal; }
/** /**
* Function GetView() * Return a pointer to the #VIEW instance used in the panel.
* Returns a pointer to the VIEW instance used in the panel. *
* @return The instance of VIEW. * @return The instance of #VIEW.
*/ */
virtual KIGFX::VIEW* GetView() const { return m_view; } virtual KIGFX::VIEW* GetView() const { return m_view; }
/** /**
* Function GetViewControls() * Return a pointer to the #VIEW_CONTROLS instance used in the panel.
* Returns a pointer to the VIEW_CONTROLS instance used in the panel. *
* @return The instance of VIEW_CONTROLS. * @return The instance of #VIEW_CONTROLS.
*/ */
KIGFX::VIEW_CONTROLS* GetViewControls() const KIGFX::VIEW_CONTROLS* GetViewControls() const
{ {
@ -128,42 +127,38 @@ public:
virtual void Refresh( bool aEraseBackground = true, const wxRect* aRect = NULL ) override; virtual void Refresh( bool aEraseBackground = true, const wxRect* aRect = NULL ) override;
/** /**
* Function ForceRefresh() * Force a redraw.
* Forces a redraw.
*/ */
void ForceRefresh(); void ForceRefresh();
/** /**
* Function SetEventDispatcher() * Set a dispatcher that processes events and forwards them to tools.
* Sets a dispatcher that processes events and forwards them to tools. *
* #DRAW_PANEL_GAL does not take over the ownership. Passing NULL disconnects all event
* handlers from the #DRAW_PANEL_GAL and parent frame.
*
* @param aEventDispatcher is the object that will be used for dispatching events. * @param aEventDispatcher is the object that will be used for dispatching events.
* DRAW_PANEL_GAL does not take over the ownership. Passing NULL disconnects all event
* handlers from the DRAW_PANEL_GAL and parent frame.
*/ */
void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher ); void SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher );
/** /**
* Function StartDrawing() * Begin drawing if it was stopped previously.
* Begins drawing if it was stopped previously.
*/ */
void StartDrawing(); void StartDrawing();
/** /**
* Function StopDrawing() * Prevent the GAL canvas from further drawing until it is recreated or #StartDrawing()
* Prevents the GAL canvas from further drawing till it is recreated * is called.
* or StartDrawing() is called.
*/ */
void StopDrawing(); void StopDrawing();
/** /**
* Function SetHighContrastLayer * Take care of display settings for the given layer to be displayed in high contrast mode.
* Takes care of display settings for the given layer to be displayed in high contrast mode.
*/ */
virtual void SetHighContrastLayer( int aLayer ); virtual void SetHighContrastLayer( int aLayer );
/** /**
* Function SetTopLayer * Move the selected layer to the top, so it is displayed above all others.
* Moves the selected layer to the top, so it is displayed above all others.
*/ */
virtual void SetTopLayer( int aLayer ); virtual void SetTopLayer( int aLayer );
@ -173,37 +168,35 @@ public:
} }
/** /**
* Function GetParentEDAFrame() * Returns parent #EDA_DRAW_FRAME, if available or NULL otherwise.
* Returns parent EDA_DRAW_FRAME, if available or NULL otherwise.
*/ */
EDA_DRAW_FRAME* GetParentEDAFrame() const { return m_edaFrame; } EDA_DRAW_FRAME* GetParentEDAFrame() const { return m_edaFrame; }
bool IsDialogPreview() const { return m_parent != (wxWindow*) m_edaFrame; } bool IsDialogPreview() const { return m_parent != (wxWindow*) m_edaFrame; }
/** /**
* Function OnShow()
* Called when the window is shown for the first time. * Called when the window is shown for the first time.
*/ */
virtual void OnShow() {} virtual void OnShow() {}
/** /**
* Set whether focus is taken on certain events (mouseover, keys, etc). This should * Set whether focus is taken on certain events (mouseover, keys, etc).
* be true (and is by default) for any primary canvas, but can be false to make *
* well-behaved preview panes and the like. * This should be true (and is by default) for any primary canvas, but can be false to make
* well behaved preview panes and the like.
*/ */
void SetStealsFocus( bool aStealsFocus ) { m_stealsFocus = aStealsFocus; } void SetStealsFocus( bool aStealsFocus ) { m_stealsFocus = aStealsFocus; }
/** /**
* Function SetCurrentCursor * Set the current cursor shape for this panel.
* Set the current cursor shape for this panel
*/ */
void SetCurrentCursor( KICURSOR cursor ); void SetCurrentCursor( KICURSOR cursor );
/** /**
* Returns the bounding box of the view that should be used if model is not valid * Return the bounding box of the view that should be used if model is not valid.
* For example, the worksheet bounding box for an empty PCB * For example, the worksheet bounding box for an empty PCB
* *
* @return the default bounding box for the panel * @return the default bounding box for the panel.
*/ */
virtual BOX2I GetDefaultViewBBox() const { return BOX2I(); } virtual BOX2I GetDefaultViewBBox() const { return BOX2I(); }
@ -214,25 +207,25 @@ public:
/** /**
* Repaint the canvas, and fix scrollbar cursors * Repaint the canvas, and fix scrollbar cursors
* Usually called by a OnPaint event, but because it do not use a wxPaintDC, *
* it can be called outside a wxPaintEvent. * Usually called by a OnPaint event.
*
* Because it does not use a wxPaintDC, it can be called outside a wxPaintEvent.
*/ */
void DoRePaint(); void DoRePaint();
/** /**
* Creates an overlay for rendering debug graphics. * Create an overlay for rendering debug graphics.
*/ */
std::shared_ptr<KIGFX::VIEW_OVERLAY> DebugOverlay(); std::shared_ptr<KIGFX::VIEW_OVERLAY> DebugOverlay();
/** /**
* Clears the contents of the debug overlay and removes it from the VIEW. * Clear the contents of the debug overlay and removes it from the VIEW.
*/ */
void ClearDebugOverlay(); void ClearDebugOverlay();
protected: protected:
virtual void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); virtual void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
void onSize( wxSizeEvent& aEvent ); void onSize( wxSizeEvent& aEvent );
void onEnter( wxMouseEvent& aEvent ); void onEnter( wxMouseEvent& aEvent );

View File

@ -40,45 +40,29 @@ class EDA_ITEM;
/** /**
* COLLECTOR * An abstract class that will find and hold all the objects according to
* is an abstract class that will find and hold all the objects according to
* an inspection done by the Inspect() function which must be implemented by * an inspection done by the Inspect() function which must be implemented by
* any derived class. When Inspect() finds an object that it wants to collect, * any derived class.
* i.e. one that it "likes", then it only has to do an Append( testItem )
* on it to add it to its collection, but in all cases for the scan to continue,
* Inspect() must return SEARCH_CONTINUE.
* *
* Later, after collection, the user can iterate through all the objects * When Inspect() finds an object that it wants to collect, i.e. one that it "likes", then
* in the remembered collection using GetCount() and the [int] operator. * it only has to do an Append( testItem )on it to add it to its collection, but in all cases
* for the scan to continue, Inspect() must return SEARCH_CONTINUE. Later, after collection,
* the user can iterate through all the objects in the remembered collection using GetCount()
* and the [int] operator.
*/ */
class COLLECTOR class COLLECTOR
{ {
protected:
std::vector<EDA_ITEM*> m_list; // Primary list of most likely items
std::vector<EDA_ITEM*> m_backupList; // Secondary list with items removed by heuristics
const KICAD_T* m_scanTypes;
INSPECTOR_FUNC m_inspector;
wxPoint m_refPos; // Reference position used to generate the collection.
EDA_RECT m_refBox; // Selection rectangle used to generate the collection.
public:
int m_Threshold; // Hit-test threshold in internal units.
wxString m_MenuTitle; // The title of selection disambiguation menu (if needed)
bool m_MenuCancelled; // Indicates selection disambiguation menu was cancelled
public: public:
COLLECTOR() : COLLECTOR() :
m_Threshold( 0 ),
m_MenuCancelled( false ),
m_scanTypes( 0 ), m_scanTypes( 0 ),
// Inspect() is virtual so calling it from a class common inspector preserves // Inspect() is virtual so calling it from a class common inspector preserves
// polymorphism. // polymorphism.
m_inspector( [=]( EDA_ITEM* aItem, void* aTestData ) m_inspector( [=]( EDA_ITEM* aItem, void* aTestData )
{ {
return this->Inspect( aItem, aTestData ); return this->Inspect( aItem, aTestData );
} ), } )
m_Threshold( 0 ),
m_MenuCancelled( false )
{ {
} }
@ -98,8 +82,7 @@ public:
CITER end() const { return m_list.cend(); } CITER end() const { return m_list.cend(); }
/** /**
* Function GetCount * Return the number of objects in the list.
* returns the number of objects in the list
*/ */
int GetCount() const int GetCount() const
{ {
@ -107,8 +90,7 @@ public:
} }
/** /**
* Function Empty * Clear the list.
* sets the list to empty
*/ */
void Empty() void Empty()
{ {
@ -116,8 +98,8 @@ public:
} }
/** /**
* Function Append * Add an item to the end of the list.
* adds an item to the end of the list. *
* @param item An EDA_ITEM* to add. * @param item An EDA_ITEM* to add.
*/ */
void Append( EDA_ITEM* item ) void Append( EDA_ITEM* item )
@ -126,8 +108,8 @@ public:
} }
/** /**
* Function Remove * Remove the item at \a aIndex (first position is 0).
* removes the item at \a aIndex (first position is 0); *
* @param aIndex The index into the list. * @param aIndex The index into the list.
*/ */
void Remove( int aIndex ) void Remove( int aIndex )
@ -136,8 +118,8 @@ public:
} }
/** /**
* Function Remove * Remove the item aItem (if exists in the collector).
* removes the item aItem (if exists in the collector). *
* @param aItem the item to be removed. * @param aItem the item to be removed.
*/ */
void Remove( const EDA_ITEM* aItem ) void Remove( const EDA_ITEM* aItem )
@ -151,8 +133,9 @@ public:
} }
/** /**
* Test if the collector has heuristic backup items * Test if the collector has heuristic backup items.
* @return true if Combine() can run to bring secondary items into the list *
* @return true if Combine() can run to bring secondary items into the list.
*/ */
bool HasAdditionalItems() bool HasAdditionalItems()
{ {
@ -160,7 +143,7 @@ public:
} }
/** /**
* Re-combines the backup list into the main list of the collector * Re-combine the backup list into the main list of the collector.
*/ */
void Combine() void Combine()
{ {
@ -169,7 +152,8 @@ public:
} }
/** /**
* Moves the item at \a aIndex (first position is 0) to the backup list * Move the item at \a aIndex (first position is 0) to the backup list.
*
* @param aIndex The index into the list. * @param aIndex The index into the list.
*/ */
void Transfer( int aIndex ) void Transfer( int aIndex )
@ -179,7 +163,8 @@ public:
} }
/** /**
* Moves the item aItem (if exists in the collector) to the backup list * Move \a aItem (if exists in the collector) to the backup list.
*
* @param aItem the item to be moved. * @param aItem the item to be moved.
*/ */
void Transfer( EDA_ITEM* aItem ) void Transfer( EDA_ITEM* aItem )
@ -196,22 +181,21 @@ public:
} }
/** /**
* Function operator[int] * Used for read only access and returns the object at \a aIndex.
* is used for read only access and returns the object at \a aIndex. *
* @param aIndex The index into the list. * @param aIndex The index into the list.
* @return EDA_ITEM* - or something derived from it, or NULL. * @return the object at \a aIndex something derived from it or NULL.
*/ */
virtual EDA_ITEM* operator[]( int aIndex ) const virtual EDA_ITEM* operator[]( int aIndex ) const
{ {
if( (unsigned)aIndex < (unsigned)GetCount() ) // (unsigned) excludes aIndex<0 also if( (unsigned)aIndex < (unsigned)GetCount() ) // (unsigned) excludes aIndex<0 also
return m_list[ aIndex ]; return m_list[ aIndex ];
return NULL; return nullptr;
} }
/** /**
* Function HasItem * Tests if \a aItem has already been collected.
* tests if \a aItem has already been collected.
* *
* @param aItem The EDA_ITEM* to be tested. * @param aItem The EDA_ITEM* to be tested.
* @return True if \a aItem is already collected. * @return True if \a aItem is already collected.
@ -228,9 +212,8 @@ public:
} }
/** /**
* Function SetScanTypes * Record the list of #KICAD_T types to consider for collection by the Inspect() function.
* records the list of KICAD_T types to consider for collection by *
* the Inspect() function.
* @param scanTypes An array of KICAD_T, terminated by EOT. No copy is * @param scanTypes An array of KICAD_T, terminated by EOT. No copy is
* is made of this array (so cannot come from caller's stack). * is made of this array (so cannot come from caller's stack).
*/ */
@ -244,21 +227,37 @@ public:
const EDA_RECT& GetBoundingBox() const { return m_refBox; } const EDA_RECT& GetBoundingBox() const { return m_refBox; }
/** /**
* Function CountType * Count the number of items matching \a aType.
* counts the number of items matching aType *
* @param aType type we are interested in * @param aType type we are interested in.
* @return number of occurences * @return number of occurrences.
*/ */
int CountType( KICAD_T aType ) int CountType( KICAD_T aType )
{ {
int cnt = 0; int cnt = 0;
for( size_t i = 0; i < m_list.size(); i++ ) for( size_t i = 0; i < m_list.size(); i++ )
{ {
if( m_list[i]->Type() == aType ) if( m_list[i]->Type() == aType )
cnt++; cnt++;
} }
return cnt; return cnt;
} }
int m_Threshold; // Hit-test threshold in internal units.
wxString m_MenuTitle; // The title of selection disambiguation menu (if needed)
bool m_MenuCancelled; // Indicates selection disambiguation menu was canceled
protected:
std::vector<EDA_ITEM*> m_list; // Primary list of most likely items
std::vector<EDA_ITEM*> m_backupList; // Secondary list with items removed by heuristics
const KICAD_T* m_scanTypes;
INSPECTOR_FUNC m_inspector;
wxPoint m_refPos; // Reference position used to generate the collection.
EDA_RECT m_refBox; // Selection rectangle used to generate the collection.};
}; };
#endif // COLLECTOR_H #endif // COLLECTOR_H

View File

@ -2,6 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright 2016-2017 CERN * Copyright 2016-2017 CERN
* Copyright (C) 2020 KiCad Developers, see change_log.txt for contributors.
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
@ -60,10 +61,8 @@ CHANGE_TYPE operator&( CHANGE_TYPE aTypeA, T aTypeB )
/** /**
* COMMIT * Represent a set of changes (additions, deletions or modifications) of a data model
* * (e.g. the BOARD) class.
* Represents a set of changes (additions, deletions or modifications)
* of a data model (e.g. the BOARD) class.
* *
* The class can be used to propagate changes to subscribed objects (e.g. views, ratsnest), * The class can be used to propagate changes to subscribed objects (e.g. views, ratsnest),
* and automatically create undo/redo points. * and automatically create undo/redo points.
@ -113,6 +112,7 @@ public:
} }
template<class Range> template<class Range>
COMMIT& StageItems( const Range& aRange, CHANGE_TYPE aChangeType ) COMMIT& StageItems( const Range& aRange, CHANGE_TYPE aChangeType )
{ {
for( const auto& item : aRange ) for( const auto& item : aRange )
@ -121,19 +121,19 @@ public:
return *this; return *this;
} }
///> Adds a change of the item aItem of type aChangeType to the change list. ///> Adds a change of the item aItem of type aChangeType to the change list.
virtual COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType ); virtual COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType );
virtual COMMIT& Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType ); virtual COMMIT& Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType );
virtual COMMIT& Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO aModFlag = UNDO_REDO::UNSPECIFIED ); virtual COMMIT& Stage( const PICKED_ITEMS_LIST& aItems,
UNDO_REDO aModFlag = UNDO_REDO::UNSPECIFIED );
///> Executes the changes. ///> Executes the changes.
virtual void Push( const wxString& aMessage = wxT( "A commit" ), virtual void Push( const wxString& aMessage = wxT( "A commit" ),
bool aCreateUndoEntry = true, bool aSetDirtyBit = true ) = 0; bool aCreateUndoEntry = true, bool aSetDirtyBit = true ) = 0;
///> Revertes the commit by restoring the modifed items state. ///> Revert the commit by restoring the modified items state.
virtual void Revert() = 0; virtual void Revert() = 0;
bool Empty() const bool Empty() const
@ -161,10 +161,11 @@ protected:
COMMIT& createModified( EDA_ITEM* aItem, EDA_ITEM* aCopy, int aExtraFlags = 0 ); COMMIT& createModified( EDA_ITEM* aItem, EDA_ITEM* aCopy, int aExtraFlags = 0 );
virtual void makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy = NULL ); virtual void makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy = nullptr );
/** /**
* Searches for an entry describing change for a particular item * Search for an entry describing change for a particular item.
*
* @return null if there is no related entry. * @return null if there is no related entry.
*/ */
COMMIT_LINE* findEntry( EDA_ITEM* aItem ); COMMIT_LINE* findEntry( EDA_ITEM* aItem );

View File

@ -56,16 +56,14 @@ class REPORTER;
/** /**
* Run a command in a child process. * Run a command in a child process.
* *
* @param aCommandLine The process and any arguments to it all in a single * @param aCommandLine The process and any arguments to it all in a single string.
* string.
* @param aFlags The same args as allowed for wxExecute() * @param aFlags The same args as allowed for wxExecute()
* @param callback wxProcess implementing OnTerminate to be run when the * @param callback wxProcess implementing OnTerminate to be run when the
child process finishes child process finishes
* @return int - pid of process, 0 in case of error (like return values of * @return pid of process, 0 in case of error (like return values of wxExecute()).
* wxExecute())
*/ */
int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC, int ProcessExecute( const wxString& aCommandLine, int aFlags = wxEXEC_ASYNC,
wxProcess *callback = NULL ); wxProcess *callback = nullptr );
/** /**
* Return the help file's full path. * Return the help file's full path.
@ -99,13 +97,13 @@ wxString SearchHelpFileFullPath( const SEARCH_STACK& aSearchStack, const wxStrin
*/ */
bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName, bool EnsureFileDirectoryExists( wxFileName* aTargetFullFileName,
const wxString& aBaseFilename, const wxString& aBaseFilename,
REPORTER* aReporter = NULL ); REPORTER* aReporter = nullptr );
/** /**
* Replace any environment variable & text variable references with their values. * Replace any environment variable & text variable references with their values.
* *
* @param aString = a string containing (perhaps) references to env var * @param aString a string containing (perhaps) references to env var
* @return a string where env var are replaced by their value * @return the expanded environment variable.
*/ */
const wxString ExpandEnvVarSubstitutions( const wxString& aString, PROJECT* aProject ); const wxString ExpandEnvVarSubstitutions( const wxString& aString, PROJECT* aProject );
@ -128,19 +126,18 @@ const wxString ResolveUriByEnvVars( const wxString& aUri, PROJECT* aProject );
#ifdef __WXMAC__ #ifdef __WXMAC__
/** /**
* OSX specific function GetOSXKicadUserDataDir * OSX specific function GetOSXKicadUserDataDir
* @return A wxString pointing to the user data directory for Kicad *
* @return The macOS specific user data directory for KiCad.
*/ */
wxString GetOSXKicadUserDataDir(); wxString GetOSXKicadUserDataDir();
/** /**
* OSX specific function GetOSXMachineDataDir * @return The macOS specific machine data directory for KiCad
* @return A wxString pointing to the machine data directory for Kicad
*/ */
wxString GetOSXKicadMachineDataDir(); wxString GetOSXKicadMachineDataDir();
/** /**
* OSX specific function GetOSXKicadDataDir * @return The macOS specific bundle data directory for KiCad
* @return A wxString pointing to the bundle data directory for Kicad
*/ */
wxString GetOSXKicadDataDir(); wxString GetOSXKicadDataDir();
#endif #endif
@ -180,16 +177,14 @@ namespace std
/** /**
* Helper function to print the given wxSize to a stream. * Helper function to print the given wxSize to a stream.
* *
* Used for debugging functions like EDA_ITEM::Show and also in unit * Used for debugging functions like EDA_ITEM::Show and also in unit testing fixtures.
* testing fixtures.
*/ */
std::ostream& operator<<( std::ostream& out, const wxSize& size ); std::ostream& operator<<( std::ostream& out, const wxSize& size );
/** /**
* Helper function to print the given wxPoint to a stream. * Helper function to print the given wxPoint to a stream.
* *
* Used for debugging functions like EDA_ITEM::Show and also in unit * Used for debugging functions like EDA_ITEM::Show and also in unit testing fixtures.
* testing fixtures.
*/ */
std::ostream& operator<<( std::ostream& out, const wxPoint& pt ); std::ostream& operator<<( std::ostream& out, const wxPoint& pt );

View File

@ -37,18 +37,15 @@
using KIGFX::COLOR4D; using KIGFX::COLOR4D;
/*
* NOTE: Everything in this file is deprecated, it only remains because advanced_config depends on
* it for the moment.
*/
/** /**
* Function ConfigBaseWriteDouble * A helper function to write doubles in configuration file.
* This is a helper function to write doubles in config *
* We cannot use wxConfigBase->Write for a double, because * We cannot use wxConfigBase->Write for a double, because this function uses a format with
* this function uses a format with very few digits in mantissa, * very few digits in mantissa and truncation issues are frequent. We use here a better
* and truncation issues are frequent. * floating format.
* We use here a better floating format. *
* @note Everything in this file is deprecated, it only remains because advanced_config depends on
* it for the moment.
*/ */
void ConfigBaseWriteDouble( wxConfigBase* aConfig, const wxString& aKey, double aValue ); void ConfigBaseWriteDouble( wxConfigBase* aConfig, const wxString& aKey, double aValue );
@ -74,17 +71,34 @@ enum paramcfg_id {
/** /**
* PARAM_CFG * A base class which establishes the interface functions ReadParam and SaveParam,
* is a base class which establishes the interface functions ReadParam and SaveParam,
* which are implemented by a number of derived classes, and these function's * which are implemented by a number of derived classes, and these function's
* doxygen comments are inherited also. * doxygen comments are inherited also.
* <p> *
* See kicad.odt or kicad.pdf, chapter 2 : * See kicad.odt or kicad.pdf, chapter 2 :
* "Installation and configuration/Initialization of the default config". * "Installation and configuration/Initialization of the default config".
*/ */
class PARAM_CFG class PARAM_CFG
{ {
public: public:
PARAM_CFG( const wxString& ident, const paramcfg_id type, const wxChar* group = nullptr,
const wxString& legacy_ident = wxEmptyString );
virtual ~PARAM_CFG() {}
/**
* Read the value of the parameter stored in \a aConfig.
*
* @param aConfig the wxConfigBase that holds the parameter.
*/
virtual void ReadParam( wxConfigBase* aConfig ) const {};
/**
* Save the value of the parameter stored in \a aConfig.
*
* @param aConfig the wxConfigBase that can store the parameter.
*/
virtual void SaveParam( wxConfigBase* aConfig ) const {};
wxString m_Ident; ///< Keyword in config data wxString m_Ident; ///< Keyword in config data
paramcfg_id m_Type; ///< Type of parameter paramcfg_id m_Type; ///< Type of parameter
wxString m_Group; ///< Group name (this is like a path in the config data) wxString m_Group; ///< Group name (this is like a path in the config data)
@ -93,39 +107,14 @@ public:
// If the m_Ident keyword isn't found, fall back and read values from m_Ident_legacy. // If the m_Ident keyword isn't found, fall back and read values from m_Ident_legacy.
// Note that values are always written to the current, non-legacy keyword. // Note that values are always written to the current, non-legacy keyword.
wxString m_Ident_legacy; wxString m_Ident_legacy;
public:
PARAM_CFG( const wxString& ident, const paramcfg_id type, const wxChar* group = NULL,
const wxString& legacy_ident = wxEmptyString );
virtual ~PARAM_CFG() {}
/**
* Function ReadParam
* reads the value of the parameter stored in aConfig
* @param aConfig = the wxConfigBase that holds the parameter
*/
virtual void ReadParam( wxConfigBase* aConfig ) const {};
/**
* Function SaveParam
* saves the value of the parameter stored in aConfig
* @param aConfig = the wxConfigBase that can store the parameter
*/
virtual void SaveParam( wxConfigBase* aConfig ) const {};
}; };
/** /**
* Configuration parameter - Integer Class * Configuration object for integers.
*
*/ */
class PARAM_CFG_INT : public PARAM_CFG class PARAM_CFG_INT : public PARAM_CFG
{ {
public:
int* m_Pt_param; ///< Pointer to the parameter value
int m_Min, m_Max; ///< Minimum and maximum values of the param type
int m_Default; ///< The default value of the parameter
public: public:
PARAM_CFG_INT( const wxString& ident, int* ptparam, int default_val = 0, PARAM_CFG_INT( const wxString& ident, int* ptparam, int default_val = 0,
int min = std::numeric_limits<int>::min(), int min = std::numeric_limits<int>::min(),
@ -140,147 +129,142 @@ public:
virtual void ReadParam( wxConfigBase* aConfig ) const override; virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override; virtual void SaveParam( wxConfigBase* aConfig ) const override;
int* m_Pt_param; ///< Pointer to the parameter value
int m_Min, m_Max; ///< Minimum and maximum values of the param type
int m_Default; ///< The default value of the parameter
}; };
/** /**
* Configuration parameter - Integer Class * Configuration for integers with unit conversion.
* with unit conversion. *
* Mainly used to store an integer value in millimeters (or inches) * Mainly used to store an integer value in millimeters (or inches) and retrieve it in
* and retrieve it in internal units * internal units. The stored value is a floating number.
* the stored value is a floating number
*/ */
class PARAM_CFG_INT_WITH_SCALE : public PARAM_CFG_INT class PARAM_CFG_INT_WITH_SCALE : public PARAM_CFG_INT
{ {
public:
double m_BIU_to_cfgunit; ///< the factor to convert the saved value in internal value
public: public:
PARAM_CFG_INT_WITH_SCALE( const wxString& ident, int* ptparam, int default_val = 0, PARAM_CFG_INT_WITH_SCALE( const wxString& ident, int* ptparam, int default_val = 0,
int min = std::numeric_limits<int>::min(), int min = std::numeric_limits<int>::min(),
int max = std::numeric_limits<int>::max(), int max = std::numeric_limits<int>::max(),
const wxChar* group = NULL, double aBiu2cfgunit = 1.0, const wxChar* group = nullptr, double aBiu2cfgunit = 1.0,
const wxString& legacy_ident = wxEmptyString ); const wxString& legacy_ident = wxEmptyString );
PARAM_CFG_INT_WITH_SCALE( bool insetup, const wxString& ident, int* ptparam, PARAM_CFG_INT_WITH_SCALE( bool insetup, const wxString& ident, int* ptparam,
int default_val = 0, int default_val = 0,
int min = std::numeric_limits<int>::min(), int min = std::numeric_limits<int>::min(),
int max = std::numeric_limits<int>::max(), int max = std::numeric_limits<int>::max(),
const wxChar* group = NULL, double aBiu2cfgunit = 1.0, const wxChar* group = nullptr, double aBiu2cfgunit = 1.0,
const wxString& legacy_ident = wxEmptyString ); const wxString& legacy_ident = wxEmptyString );
virtual void ReadParam( wxConfigBase* aConfig ) const override; virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override; virtual void SaveParam( wxConfigBase* aConfig ) const override;
public:
double m_BIU_to_cfgunit; ///< the factor to convert the saved value in internal value
}; };
/** /**
* Configuration parameter - Double Precision Class * Configuration object for double precision floating point numbers.
*
*/ */
class PARAM_CFG_DOUBLE : public PARAM_CFG class PARAM_CFG_DOUBLE : public PARAM_CFG
{ {
public: public:
PARAM_CFG_DOUBLE( const wxString& ident, double* ptparam,
double default_val = 0.0, double min = 0.0, double max = 10000.0,
const wxChar* group = nullptr );
PARAM_CFG_DOUBLE( bool Insetup, const wxString& ident, double* ptparam,
double default_val = 0.0, double min = 0.0, double max = 10000.0,
const wxChar* group = nullptr );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
double* m_Pt_param; ///< Pointer to the parameter value double* m_Pt_param; ///< Pointer to the parameter value
double m_Default; ///< The default value of the parameter double m_Default; ///< The default value of the parameter
double m_Min, m_Max; ///< Minimum and maximum values of the param type double m_Min, m_Max; ///< Minimum and maximum values of the param type
public:
PARAM_CFG_DOUBLE( const wxString& ident, double* ptparam,
double default_val = 0.0, double min = 0.0, double max = 10000.0,
const wxChar* group = NULL );
PARAM_CFG_DOUBLE( bool Insetup, const wxString& ident, double* ptparam,
double default_val = 0.0, double min = 0.0, double max = 10000.0,
const wxChar* group = NULL );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
}; };
/** /**
* Configuration parameter - Boolean Class * Configuration object for booleans.
*
*/ */
class PARAM_CFG_BOOL : public PARAM_CFG class PARAM_CFG_BOOL : public PARAM_CFG
{ {
public:
bool* m_Pt_param; ///< Pointer to the parameter value
int m_Default; ///< The default value of the parameter
public: public:
PARAM_CFG_BOOL( const wxString& ident, bool* ptparam, PARAM_CFG_BOOL( const wxString& ident, bool* ptparam,
int default_val = false, const wxChar* group = NULL, int default_val = false, const wxChar* group = nullptr,
const wxString& legacy_ident = wxEmptyString ); const wxString& legacy_ident = wxEmptyString );
PARAM_CFG_BOOL( bool Insetup, const wxString& ident, bool* ptparam, PARAM_CFG_BOOL( bool Insetup, const wxString& ident, bool* ptparam,
int default_val = false, const wxChar* group = NULL, int default_val = false, const wxChar* group = nullptr,
const wxString& legacy_ident = wxEmptyString ); const wxString& legacy_ident = wxEmptyString );
virtual void ReadParam( wxConfigBase* aConfig ) const override; virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override; virtual void SaveParam( wxConfigBase* aConfig ) const override;
bool* m_Pt_param; ///< Pointer to the parameter value
int m_Default; ///< The default value of the parameter
}; };
/** /**
* Configuration parameter - wxString Class * Configuration object for wxString objects.
*
*/ */
class PARAM_CFG_WXSTRING : public PARAM_CFG class PARAM_CFG_WXSTRING : public PARAM_CFG
{ {
public: public:
wxString* m_Pt_param; ///< Pointer to the parameter value PARAM_CFG_WXSTRING( const wxString& ident, wxString* ptparam, const wxChar* group = nullptr );
wxString m_default; ///< The default value of the parameter
public:
PARAM_CFG_WXSTRING( const wxString& ident, wxString* ptparam, const wxChar* group = NULL );
PARAM_CFG_WXSTRING( bool Insetup, PARAM_CFG_WXSTRING( bool Insetup,
const wxString& ident, const wxString& ident,
wxString* ptparam, wxString* ptparam,
const wxString& default_val = wxEmptyString, const wxString& default_val = wxEmptyString,
const wxChar* group = NULL ); const wxChar* group = nullptr );
virtual void ReadParam( wxConfigBase* aConfig ) const override; virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override; virtual void SaveParam( wxConfigBase* aConfig ) const override;
wxString* m_Pt_param; ///< Pointer to the parameter value
wxString m_default; ///< The default value of the parameter
}; };
/** /**
* Configuration parameter - std::set<wxString> * Configuration object for a set of wxString objects.
* *
*/ */
class PARAM_CFG_WXSTRING_SET : public PARAM_CFG class PARAM_CFG_WXSTRING_SET : public PARAM_CFG
{ {
public: public:
std::set<wxString>* m_Pt_param; ///< Pointer to the parameter value PARAM_CFG_WXSTRING_SET( const wxString& ident, std::set<wxString>* ptparam,
const wxChar* group = nullptr );
public:
PARAM_CFG_WXSTRING_SET( const wxString& ident, std::set<wxString>* ptparam, const wxChar* group = NULL );
PARAM_CFG_WXSTRING_SET( bool Insetup, PARAM_CFG_WXSTRING_SET( bool Insetup,
const wxString& ident, const wxString& ident,
std::set<wxString>* ptparam, std::set<wxString>* ptparam,
const wxChar* group = NULL ); const wxChar* group = nullptr );
virtual void ReadParam( wxConfigBase* aConfig ) const override; virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override; virtual void SaveParam( wxConfigBase* aConfig ) const override;
std::set<wxString>* m_Pt_param; ///< Pointer to the parameter value
}; };
/** /**
* Configuration parameter - PARAM_CFG_FILENAME Class * Configuration object for a file name object.
* Same as PARAM_CFG_WXSTRING, but stores "\" as "/". *
* and replace "/" by "\" under Windows. * Same as #PARAM_CFG_WXSTRING but stores "\" as "/" and replace "/" by "\" under Windows.
* Used to store paths and filenames in config files
*/ */
class PARAM_CFG_FILENAME : public PARAM_CFG class PARAM_CFG_FILENAME : public PARAM_CFG
{ {
public:
wxString* m_Pt_param; ///< Pointer to the parameter value
public: public:
PARAM_CFG_FILENAME( const wxString& ident, wxString* ptparam, PARAM_CFG_FILENAME( const wxString& ident, wxString* ptparam,
const wxChar* group = NULL ); const wxChar* group = nullptr );
virtual void ReadParam( wxConfigBase* aConfig ) const override; virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override; virtual void SaveParam( wxConfigBase* aConfig ) const override;
wxString* m_Pt_param; ///< Pointer to the parameter value
}; };
@ -290,9 +274,8 @@ public:
wxArrayString* m_Pt_param; ///< Pointer to the parameter value wxArrayString* m_Pt_param; ///< Pointer to the parameter value
public: public:
PARAM_CFG_LIBNAME_LIST( const wxChar* ident, PARAM_CFG_LIBNAME_LIST( const wxChar* ident, wxArrayString* ptparam,
wxArrayString* ptparam, const wxChar* group = nullptr );
const wxChar* group = NULL );
virtual void ReadParam( wxConfigBase* aConfig ) const override; virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override; virtual void SaveParam( wxConfigBase* aConfig ) const override;
@ -300,22 +283,21 @@ public:
/** /**
* Function wxConfigSaveSetups * Writes @a aList of #PARAM_CFG objects to @a aCfg.
* writes @a aList of PARAM_CFG to save configuration values to @a aCfg. *
* Only elements with m_Setup set true will be saved, hence the function name. * Only elements with m_Setup set true will be saved, hence the function name.
* *
* @param aCfg where to save * @param aCfg where to save.
* @param aList holds some configuration parameters, not all of which will * @param aList holds some configuration parameters, not all of which will necessarily be saved.
* necessarily be saved.
*/ */
void wxConfigSaveSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList ); void wxConfigSaveSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
/** /**
* Function wxConfigSaveParams * Write @a aList of #PARAM_CFG objects @a aCfg.
* writes @a aList of PARAM_CFG to save configuration values to @a aCfg. *
* Only elements with m_Setup set false will be saved, hence the function name. * Only elements with m_Setup set false will be saved, hence the function name.
* *
* @param aCfg where to save * @param aCfg where to save.
* @param aList holds some configuration parameters, not all of which will necessarily be saved. * @param aList holds some configuration parameters, not all of which will necessarily be saved.
* @param aGroup indicates in which group the value should be saved, unless the PARAM_CFG provides * @param aGroup indicates in which group the value should be saved, unless the PARAM_CFG provides
* its own group, in which case it will take precedence. aGroup may be empty. * its own group, in which case it will take precedence. aGroup may be empty.
@ -324,8 +306,8 @@ void wxConfigSaveParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aLis
const wxString& aGroup ); const wxString& aGroup );
/** /**
* Function wxConfigLoadSetups * Use @a aList of #PARAM_CFG object to load configuration values from @a aCfg.
* uses @a aList of PARAM_CFG to load configuration values from @a aCfg. *
* Only elements whose m_Setup field is true will be loaded. * Only elements whose m_Setup field is true will be loaded.
* *
* @param aCfg where to load from. * @param aCfg where to load from.
@ -334,8 +316,7 @@ void wxConfigSaveParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aLis
void wxConfigLoadSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList ); void wxConfigLoadSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
/** /**
* Function wxConfigLoadParams * Use @a aList of #PARAM_CFG objects to load configuration values from @a aCfg.
* uses @a aList of PARAM_CFG to load configuration values from @a aCfg.
* Only elements whose m_Setup field is false will be loaded. * Only elements whose m_Setup field is false will be loaded.
* *
* @param aCfg where to load from. * @param aCfg where to load from.

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2010 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2010 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -40,12 +40,10 @@ void ConvertMarkdown2Html( const wxString& aMarkdownInput, wxString& aHtmlOutput
class EDA_DRAW_FRAME; class EDA_DRAW_FRAME;
/** /**
* EDA_LIST_DIALOG
*
* A dialog which shows: * A dialog which shows:
* a list of elements for selection, * - a list of elements for selection,
* a text control to display help or info about the selected item. * - a text control to display help or info about the selected item.
* 2 buttons (OK and Cancel) * - 2 buttons (OK and Cancel)
* *
*/ */
class EDA_LIST_DIALOG : public EDA_LIST_DIALOG_BASE class EDA_LIST_DIALOG : public EDA_LIST_DIALOG_BASE
@ -53,20 +51,17 @@ class EDA_LIST_DIALOG : public EDA_LIST_DIALOG_BASE
public: public:
/** /**
* Constructor:
* @param aParent Pointer to the parent window. * @param aParent Pointer to the parent window.
* @param aTitle = The title shown on top. * @param aTitle The title shown on top.
* @param aItemHeaders an optional array containing the column header names for the dialog. * @param aItemHeaders an optional array containing the column header names for the dialog.
* @param aItemList = A wxArrayString of the list of elements. * @param aItemList A wxArrayString of the list of elements.
* @param aRefText = An item name if an item must be preselected. * @param aRefText An item name if an item must be preselected.
*/ */
EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle, EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
const wxArrayString& aItemHeaders, const wxArrayString& aItemHeaders,
const std::vector<wxArrayString>& aItemList, const std::vector<wxArrayString>& aItemList,
const wxString& aRefText ); const wxString& aRefText );
// ~EDA_LIST_DIALOG() {}
void SetListLabel( const wxString& aLabel ); void SetListLabel( const wxString& aLabel );
void SetOKLabel( const wxString& aLabel ); void SetOKLabel( const wxString& aLabel );
@ -74,11 +69,10 @@ public:
void InsertItems( const std::vector<wxArrayString>& aItemList, int aPosition = 0 ); void InsertItems( const std::vector<wxArrayString>& aItemList, int aPosition = 0 );
/** /**
* Function GetTextSelection * Return the selected text from \a aColumn in the wxListCtrl in the dialog.
* return the selected text from \a aColumn in the wxListCtrl in the dialog.
* *
* @param aColumn is the column to return the text from. * @param aColumn is the column to return the text from.
* @return a wxString object containing the selected text from \a aColumn. * @return the selected text from \a aColumn.
*/ */
wxString GetTextSelection( int aColumn = 0 ); wxString GetTextSelection( int aColumn = 0 );
@ -94,21 +88,11 @@ private:
}; };
/**************************************************************************/ /**
/* Class to edit/enter a coordinate (pair of values) ( INCHES or MM ) in */ * Object to edit/enter a coordinate (pair of values) ( INCHES or MM ) in dialog boxes.
/* dialog boxes, */ */
/**************************************************************************/
class EDA_POSITION_CTRL class EDA_POSITION_CTRL
{ {
public:
EDA_UNITS m_UserUnit;
wxTextCtrl* m_FramePosX;
wxTextCtrl* m_FramePosY;
private:
wxStaticText* m_TextX, * m_TextY;
public: public:
EDA_POSITION_CTRL( wxWindow* parent, const wxString& title, const wxPoint& pos_to_edit, EDA_POSITION_CTRL( wxWindow* parent, const wxString& title, const wxPoint& pos_to_edit,
EDA_UNITS user_unit, wxBoxSizer* BoxSizer ); EDA_UNITS user_unit, wxBoxSizer* BoxSizer );
@ -118,13 +102,21 @@ public:
void Enable( bool x_win_on, bool y_win_on ); void Enable( bool x_win_on, bool y_win_on );
void SetValue( int x_value, int y_value ); void SetValue( int x_value, int y_value );
wxPoint GetValue() const; wxPoint GetValue() const;
EDA_UNITS m_UserUnit;
wxTextCtrl* m_FramePosX;
wxTextCtrl* m_FramePosY;
private:
wxStaticText* m_TextX;
wxStaticText* m_TextY;
}; };
/************************************************************* /**
* Class to edit/enter a size (pair of values for X and Y size) * Object to edit/enter a size (pair of values for X and Y size ( INCHES or MM ) in dialog boxes.
* ( INCHES or MM ) in dialog boxes */
***************************************************************/
class EDA_SIZE_CTRL : public EDA_POSITION_CTRL class EDA_SIZE_CTRL : public EDA_POSITION_CTRL
{ {
public: public:
@ -132,9 +124,9 @@ public:
EDA_UNITS user_unit, wxBoxSizer* BoxSizer ); EDA_UNITS user_unit, wxBoxSizer* BoxSizer );
~EDA_SIZE_CTRL() { } ~EDA_SIZE_CTRL() { }
wxSize GetValue() const; wxSize GetValue() const;
}; };
#endif // DIALOG_HELPERS_H_ #endif // DIALOG_HELPERS_H_

View File

@ -82,23 +82,7 @@ class WX_EVENT_LOOP;
*/ */
class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER class DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
{ {
/**
* Properly handle the wxCloseEvent when in the quasimodal mode when not calling
* EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
*/
void OnCloseWindow( wxCloseEvent& aEvent );
/**
* Properly handle the default button events when in the quasimodal mode when not
* calling EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
*/
void OnButton( wxCommandEvent& aEvent );
protected:
virtual void OnCharHook( wxKeyEvent& aEvt );
public: public:
DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title, DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
@ -146,7 +130,6 @@ public:
} }
protected: protected:
/** /**
* In all dialogs, we must call the same functions to fix minimal dlg size, the default * In all dialogs, we must call the same functions to fix minimal dlg size, the default
* position and perhaps some others to fix a few issues depending on Windows Managers * position and perhaps some others to fix a few issues depending on Windows Managers
@ -187,6 +170,27 @@ protected:
*/ */
void resetSize(); void resetSize();
virtual void OnCharHook( wxKeyEvent& aEvt );
private:
/**
* Properly handle the wxCloseEvent when in the quasimodal mode when not calling
* EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
*/
void OnCloseWindow( wxCloseEvent& aEvent );
/**
* Properly handle the default button events when in the quasimodal mode when not
* calling EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
*/
void OnButton( wxCommandEvent& aEvent );
void OnGridEditorShown( wxGridEvent& event );
void OnGridEditorHidden( wxGridEvent& event );
DECLARE_EVENT_TABLE();
protected:
EDA_UNITS m_units; // userUnits for display and parsing EDA_UNITS m_units; // userUnits for display and parsing
std::string m_hash_key; // alternate for class_map when classname re-used std::string m_hash_key; // alternate for class_map when classname re-used
@ -205,11 +209,6 @@ protected:
std::vector<wxWindow*> m_tabOrder; std::vector<wxWindow*> m_tabOrder;
private:
void OnGridEditorShown( wxGridEvent& event );
void OnGridEditorHidden( wxGridEvent& event );
DECLARE_EVENT_TABLE()
}; };
#endif // DIALOG_SHIM_ #endif // DIALOG_SHIM_

View File

@ -2,7 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application. * This program source code file is part of KICAD, a free EDA CAD application.
* *
* Copyright (C) 2007-2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2007-2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2007-2015 Kicad Developers, see change_log.txt for contributors. * Copyright (C) 2007-2020 Kicad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -34,8 +34,7 @@
#ifndef SWIG #ifndef SWIG
/** /**
* Struct KEYWORD * Hold a keyword string and its unique integer token.
* holds a keyword string and its unique integer token.
*/ */
struct KEYWORD struct KEYWORD
{ {
@ -51,9 +50,9 @@ struct KEYWORD
/** /**
* Enum DSN_SYNTAX_T * List all the DSN lexer's tokens that are supported in lexing.
* lists all the DSN lexer's tokens that are supported in lexing. It is up *
* to the parser if it wants also to support them. * It is up to the parser if it wants also to support them.
*/ */
enum DSN_SYNTAX_T enum DSN_SYNTAX_T
{ {
@ -72,47 +71,384 @@ enum DSN_SYNTAX_T
/** /**
* DSNLEXER * Implement a lexical analyzer for the SPECCTRA DSN file format.
* implements a lexical analyzer for the SPECCTRA DSN file format. It *
* reads lexical tokens from the current LINE_READER through the NextTok() * It reads lexical tokens from the current #LINE_READER through the #NextTok() function.
* function.
*/ */
class DSNLEXER class DSNLEXER
{ {
public:
/**
* Initialize a DSN lexer and prepares to read from aFile which is already open and has
* \a aFilename.
*
* @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount. This
* token table need not contain the lexer separators such as '(' ')', etc.
* @param aKeywordCount is the count of tokens in aKeywordTable.
* @param aFile is an open file, which will be closed when this is destructed.
* @param aFileName is the name of the file
*/
DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
FILE* aFile, const wxString& aFileName );
/**
* Initialize a DSN lexer and prepares to read from @a aSExpression.
*
* @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount. This
* token table need not contain the lexer separators such as '(' ')', etc.
* @param aKeywordCount is the count of tokens in aKeywordTable.
* @param aSExpression is text to feed through a STRING_LINE_READER
* @param aSource is a description of aSExpression, used for error reporting.
*/
DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
const std::string& aSExpression, const wxString& aSource = wxEmptyString );
/**
* Initialize a DSN lexer and prepares to read from @a aSExpression.
*
* Use this one without a keyword table with the DOM parser in ptree.h.
*
* @param aSExpression is text to feed through a #STRING_LINE_READER
* @param aSource is a description of aSExpression, used for error reporting.
*/
DSNLEXER( const std::string& aSExpression, const wxString& aSource = wxEmptyString );
/**
* Initialize a DSN lexer and prepares to read from @a aLineReader which is already
* open, and may be in use by other DSNLEXERs also.
*
* No ownership is taken of @a aLineReader. This enables it to be used by other DSNLEXERs.
*
* @param aKeywordTable is an array of #KEYWORDS holding \a aKeywordCount. This
* token table need not contain the lexer separators such as '(' ')', etc.
* @param aKeywordCount is the count of tokens in aKeywordTable.
* @param aLineReader is any subclassed instance of LINE_READER, such as
* #STRING_LINE_READER or #FILE_LINE_READER. No ownership is taken.
*/
DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
LINE_READER* aLineReader = NULL );
virtual ~DSNLEXER();
/**
* Usable only for DSN lexers which share the same #LINE_READER.
*
* Synchronizes the pointers handling the data read by the #LINE_READER. Allows 2
* #DNSLEXER objects to share the same current line, when switching from a #DNSLEXER
* to another #DNSLEXER
* @param aLexer the model.
* @return true if the sync can be made ( at least the same line reader ).
*/
bool SyncLineReaderWith( DSNLEXER& aLexer );
/**
* Change the behavior of this lexer into or out of "specctra mode".
*
* If specctra mode, then:
* -#) stringDelimiter can be changed.
* -#) KiCad quoting protocol is not in effect.
* -#) space_in_quoted_tokens is functional else none of the above are true.
*
* The default mode is non-specctra mode, meaning:
* -#) stringDelimiter cannot be changed.
* -#) KiCad quoting protocol is in effect.
* -#) space_in_quoted_tokens is not functional.
*/
void SetSpecctraMode( bool aMode );
/**
* Manage a stack of LINE_READERs in order to handle nested file inclusion.
*
* This function pushes aLineReader onto the top of a stack of LINE_READERs and makes
* it the current #LINE_READER with its own #GetSource(), line number and line text.
* A grammar must be designed such that the "include" token (whatever its various names),
* and any of its parameters are not followed by anything on that same line,
* because PopReader always starts reading from a new line upon returning to
* the original #LINE_READER.
*/
void PushReader( LINE_READER* aLineReader );
/**
* Delete the top most #LINE_READER from an internal stack of LINE_READERs and
* in the case of #FILE_LINE_READER this means the associated FILE is closed.
*
* The most recently used former #LINE_READER on the stack becomes the
* current #LINE_READER and its previous position in its input stream and the
* its latest line number should pertain. PopReader always starts reading
* from a new line upon returning to the previous #LINE_READER. A pop is only
* possible if there are at least 2 #LINE_READERs on the stack, since popping
* the last one is not supported.
*
* @return the LINE_READER that was in use before the pop, or NULL
* if there was not at least two readers on the stack and therefore the
* pop failed.
*/
LINE_READER* PopReader();
/**
* Return the next token found in the input file or DSN_EOF when reaching the end of
* file.
*
* Users should wrap this function to return an enum to aid in grammar debugging while
* running under a debugger, but leave this lower level function returning an int (so
* the enum does not collide with another usage).
*
* @return the type of token found next.
* @throw IO_ERROR only if the #LINE_READER throws it.
*/
int NextTok();
/**
* Call #NextTok() and then verifies that the token read in satisfies #IsSymbol().
*
* @return the actual token read in.
* @throw IO_ERROR if the next token does not satisfy IsSymbol().
*/
int NeedSYMBOL();
/**
* Call #NextTok() and then verifies that the token read in satisfies bool IsSymbol() or
* the next token is #DSN_NUMBER.
*
* @return the actual token read in.
* @throw IO_ERROR if the next token does not satisfy the above test.
*/
int NeedSYMBOLorNUMBER();
/**
* Call #NextTok() and then verifies that the token read is type #DSN_NUMBER.
*
* @return the actual token read in.
* @throw IO_ERROR if the next token does not satisfy the above test.
*/
int NeedNUMBER( const char* aExpectation );
/**
* Return whatever #NextTok() returned the last time it was called.
*/
int CurTok() const
{
return curTok;
}
/**
* Return whatever NextTok() returned the 2nd to last time it was called.
*/
int PrevTok() const
{
return prevTok;
}
/**
* Used to support "loose" matches (quoted tokens).
*/
int GetCurStrAsToken() const
{
return findToken( curText );
}
/**
* Change the string delimiter from the default " to some other character and return
* the old value.
*
* @param aStringDelimiter The character in lowest 8 bits.
* @return The old delimiter in the lowest 8 bits.
*/
char SetStringDelimiter( char aStringDelimiter )
{
int old = stringDelimiter;
if( specctraMode )
stringDelimiter = aStringDelimiter;
return old;
}
/**
* Change the setting controlling whether a space in a quoted string isa terminator.
*
* @param val If true, means
*/
bool SetSpaceInQuotedTokens( bool val )
{
bool old = space_in_quoted_tokens;
if( specctraMode )
space_in_quoted_tokens = val;
return old;
}
/**
* Change the handling of comments.
*
* If set true, comments are returned as single line strings with a terminating newline.
* Otherwise they are consumed by the lexer and not returned.
*/
bool SetCommentsAreTokens( bool val )
{
bool old = commentsAreTokens;
commentsAreTokens = val;
return old;
}
/**
* Check the next sequence of tokens and reads them into a wxArrayString if they are
* comments.
*
* Reading continues until a non-comment token is encountered, and such last read token
* remains as #CurTok() and as #CurText(). No push back or "un get" mechanism is used
* for this support. Upon return you simply avoid calling NextTok() for the next token,
* but rather #CurTok().
*
* @return Heap allocated block of comments or NULL if none. The caller owns the
* allocation and must delete if not NULL.
*/
wxArrayString* ReadCommentLines();
/**
* Test a token to see if it is a symbol.
*
* This means it cannot be a special delimiter character such as #DSN_LEFT, #DSN_RIGHT,
* #DSN_QUOTE, etc. It may however, coincidentally match a keyword and still be a symbol.
*/
static bool IsSymbol( int aTok );
/**
* Throw an #IO_ERROR exception with an input file specific error message.
*
* @param aTok is the token/keyword type which was expected at the current input location.
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Expecting( int aTok ) const;
/**
* Throw an #IO_ERROR exception with an input file specific error message.
*
* @param aTokenList is the token/keyword type which was expected at the
* current input location, e.g. "pin|graphic|property".
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Expecting( const char* aTokenList ) const;
/**
* Throw an #IO_ERROR exception with an input file specific error message.
*
* @param aTok is the token/keyword type which was not expected at the
* current input location.
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Unexpected( int aTok ) const;
/**
* Throw an #IO_ERROR exception with an input file specific error message.
*
* @param aToken is the token which was not expected at the current input location.
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Unexpected( const char* aToken ) const;
/**
* Throw an #IO_ERROR exception with a message saying specifically that \a aTok
* is a duplicate of one already seen in current context.
*
* @param aTok is the token/keyword type which was not expected at the current input
* location.
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Duplicate( int aTok );
/**
* Call #NextTok() and then verifies that the token read in is a #DSN_LEFT.
*
* @throw IO_ERROR if the next token is not a #DSN_LEFT
*/
void NeedLEFT();
/**
* Call #NextTok() and then verifies that the token read in is a #DSN_RIGHT.
*
* @throw IO_ERROR if the next token is not a #DSN_RIGHT
*/
void NeedRIGHT();
/**
* Return the C string representation of a #DSN_T value.
*/
const char* GetTokenText( int aTok ) const;
/**
* Return a quote wrapped wxString representation of a token value.
*/
wxString GetTokenString( int aTok ) const;
static const char* Syntax( int aTok );
/**
* Return a pointer to the current token's text.
*/
const char* CurText() const
{
return curText.c_str();
}
/**
* Return a reference to current token in std::string form.
*/
const std::string& CurStr() const
{
return curText;
}
/**
* Return the current token text as a wxString, assuming that the input byte stream
* is UTF8 encoded.
*/
wxString FromUTF8() const
{
return wxString::FromUTF8( curText.c_str() );
}
/**
* Return the current line number within my #LINE_READER.
*/
int CurLineNumber() const
{
return reader->LineNumber();
}
/**
* Return the current line of text from which the #CurText() would return its token.
*/
const char* CurLine() const
{
return (const char*)(*reader);
}
/**
* Return the current #LINE_READER source.
*
* @return source of the lines of text, e.g. a filename or "clipboard".
*/
const wxString& CurSource() const
{
return reader->GetSource();
}
/**
* Return the byte offset within the current line, using a 1 based index.
*
* @return a one based index into the current line.
*/
int CurOffset() const
{
return curOffset + 1;
}
#ifndef SWIG #ifndef SWIG
protected: protected:
bool iOwnReaders; ///< on readerStack, should I delete them?
const char* start;
const char* next;
const char* limit;
char dummy[1]; ///< when there is no reader.
typedef std::vector<LINE_READER*> READER_STACK;
READER_STACK readerStack; ///< all the LINE_READERs by pointer.
LINE_READER* reader; ///< no ownership. ownership is via readerStack, maybe, if iOwnReaders
bool specctraMode; ///< if true, then:
///< 1) stringDelimiter can be changed
///< 2) Kicad quoting protocol is not in effect
///< 3) space_in_quoted_tokens is functional
///< else not.
char stringDelimiter;
bool space_in_quoted_tokens; ///< blank spaces within quoted strings
bool commentsAreTokens; ///< true if should return comments as tokens
int prevTok; ///< curTok from previous NextTok() call.
int curOffset; ///< offset within current line of the current token
int curTok; ///< the current token obtained on last NextTok()
std::string curText; ///< the text of the current token
const KEYWORD* keywords; ///< table sorted by CMake for bsearch()
unsigned keywordCount; ///< count of keywords table
KEYWORD_MAP keyword_hash; ///< fast, specialized "C string" hashtable
void init(); void init();
int readLine() int readLine()
@ -136,12 +472,11 @@ protected:
} }
/** /**
* Function findToken * Take @a aToken string and looks up the string in the keywords table.
* takes aToken string and looks up the string in the keywords table.
* *
* @param aToken is a string to lookup in the keywords table. * @param aToken is a string to lookup in the keywords table.
* @return int - with a value from the enum DSN_T matching the keyword text, * @return with a value from the enum #DSN_T matching the keyword text,
* or DSN_SYMBOL if @a aToken is not in the kewords table. * or #DSN_SYMBOL if @a aToken is not in the keywords table.
*/ */
int findToken( const std::string& aToken ) const; int findToken( const std::string& aToken ) const;
@ -156,399 +491,40 @@ protected:
return false; return false;
} }
bool iOwnReaders; ///< on readerStack, should I delete them?
const char* start;
const char* next;
const char* limit;
char dummy[1]; ///< when there is no reader.
typedef std::vector<LINE_READER*> READER_STACK;
READER_STACK readerStack; ///< all the LINE_READERs by pointer.
///< no ownership. ownership is via readerStack, maybe, if iOwnReaders
LINE_READER* reader;
bool specctraMode; ///< if true, then:
///< 1) stringDelimiter can be changed
///< 2) Kicad quoting protocol is not in effect
///< 3) space_in_quoted_tokens is functional
///< else not.
char stringDelimiter;
bool space_in_quoted_tokens; ///< blank spaces within quoted strings
bool commentsAreTokens; ///< true if should return comments as tokens
int prevTok; ///< curTok from previous NextTok() call.
int curOffset; ///< offset within current line of the current token
int curTok; ///< the current token obtained on last NextTok()
std::string curText; ///< the text of the current token
const KEYWORD* keywords; ///< table sorted by CMake for bsearch()
unsigned keywordCount; ///< count of keywords table
KEYWORD_MAP keyword_hash; ///< fast, specialized "C string" hashtable
#endif // SWIG #endif // SWIG
public:
/**
* Constructor ( FILE*, const wxString& )
* intializes a DSN lexer and prepares to read from aFile which
* is already open and has aFilename.
*
* @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount. This
* token table need not contain the lexer separators such as '(' ')', etc.
* @param aKeywordCount is the count of tokens in aKeywordTable.
* @param aFile is an open file, which will be closed when this is destructed.
* @param aFileName is the name of the file
*/
DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
FILE* aFile, const wxString& aFileName );
/**
* Constructor ( const KEYWORD*, unsigned, const std::string&, const wxString& )
* intializes a DSN lexer and prepares to read from @a aSExpression.
*
* @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount. This
* token table need not contain the lexer separators such as '(' ')', etc.
* @param aKeywordCount is the count of tokens in aKeywordTable.
* @param aSExpression is text to feed through a STRING_LINE_READER
* @param aSource is a description of aSExpression, used for error reporting.
*/
DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
const std::string& aSExpression, const wxString& aSource = wxEmptyString );
/**
* Constructor ( const std::string&, const wxString& )
* intializes a DSN lexer and prepares to read from @a aSExpression. Use this
* one without a keyword table with the DOM parser in ptree.h.
*
* @param aSExpression is text to feed through a STRING_LINE_READER
* @param aSource is a description of aSExpression, used for error reporting.
*/
DSNLEXER( const std::string& aSExpression, const wxString& aSource = wxEmptyString );
/**
* Constructor ( LINE_READER* )
* intializes a DSN lexer and prepares to read from @a aLineReader which
* is already open, and may be in use by other DSNLEXERs also. No ownership
* is taken of @a aLineReader. This enables it to be used by other DSNLEXERs also.
*
* @param aKeywordTable is an array of KEYWORDS holding \a aKeywordCount. This
* token table need not contain the lexer separators such as '(' ')', etc.
*
* @param aKeywordCount is the count of tokens in aKeywordTable.
*
* @param aLineReader is any subclassed instance of LINE_READER, such as
* STRING_LINE_READER or FILE_LINE_READER. No ownership is taken.
*/
DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
LINE_READER* aLineReader = NULL );
virtual ~DSNLEXER();
/**
* Useable only for DSN lexers which share the same LINE_READER
* Synchronizes the pointers handling the data read by the LINE_READER
* Allows 2 DNSLEXER to share the same current line, when switching from a
* DNSLEXER to another DNSLEXER
* @param aLexer = the model
* @return true if the sync can be made ( at least the same line reader )
*/
bool SyncLineReaderWith( DSNLEXER& aLexer );
/**
* Function SetSpecctraMode
* changes the behavior of this lexer into or out of "specctra mode". If
* specctra mode, then:
* 1) stringDelimiter can be changed
* 2) Kicad quoting protocol is not in effect
* 3) space_in_quoted_tokens is functional
* else none of the above are true. The default mode is non-specctra mode, meaning:
* 1) stringDelimiter cannot be changed
* 2) Kicad quoting protocol is in effect
* 3) space_in_quoted_tokens is not functional
*/
void SetSpecctraMode( bool aMode );
/**
* Function PushReader
* manages a stack of LINE_READERs in order to handle nested file inclusion.
* This function pushes aLineReader onto the top of a stack of LINE_READERs and makes
* it the current LINE_READER with its own GetSource(), line number and line text.
* A grammar must be designed such that the "include" token (whatever its various names),
* and any of its parameters are not followed by anything on that same line,
* because PopReader always starts reading from a new line upon returning to
* the original LINE_READER.
*/
void PushReader( LINE_READER* aLineReader );
/**
* Function PopReader
* deletes the top most LINE_READER from an internal stack of LINE_READERs and
* in the case of FILE_LINE_READER this means the associated FILE is closed.
* The most recently used former LINE_READER on the stack becomes the
* current LINE_READER and its previous position in its input stream and the
* its latest line number should pertain. PopReader always starts reading
* from a new line upon returning to the previous LINE_READER. A pop is only
* possible if there are at least 2 LINE_READERs on the stack, since popping
* the last one is not supported.
*
* @return LINE_READER* - is the one that was in use before the pop, or NULL
* if there was not at least two readers on the stack and therefore the
* pop failed.
*/
LINE_READER* PopReader();
// Some functions whose return value is best overloaded to return an enum
// in a derived class.
//-----<overload return values to tokens>------------------------------
/**
* Function NextTok
* returns the next token found in the input file or DSN_EOF when reaching
* the end of file. Users should wrap this function to return an enum
* to aid in grammar debugging while running under a debugger, but leave
* this lower level function returning an int (so the enum does not collide
* with another usage).
* @return int - the type of token found next.
* @throw IO_ERROR - only if the LINE_READER throws it.
*/
int NextTok();
/**
* Function NeedSYMBOL
* calls NextTok() and then verifies that the token read in
* satisfies bool IsSymbol().
* If not, an IO_ERROR is thrown.
* @return int - the actual token read in.
* @throw IO_ERROR, if the next token does not satisfy IsSymbol()
*/
int NeedSYMBOL();
/**
* Function NeedSYMBOLorNUMBER
* calls NextTok() and then verifies that the token read in
* satisfies bool IsSymbol() or tok==DSN_NUMBER.
* If not, an IO_ERROR is thrown.
* @return int - the actual token read in.
* @throw IO_ERROR, if the next token does not satisfy the above test
*/
int NeedSYMBOLorNUMBER();
/**
* Function NeedNUMBER
* calls NextTok() and then verifies that the token read is type DSN_NUMBER.
* If not, and IO_ERROR is thrown using text from aExpectation.
* @return int - the actual token read in.
* @throw IO_ERROR, if the next token does not satisfy the above test
*/
int NeedNUMBER( const char* aExpectation );
/**
* Function CurTok
* returns whatever NextTok() returned the last time it was called.
*/
int CurTok() const
{
return curTok;
}
/**
* Function PrevTok
* returns whatever NextTok() returned the 2nd to last time it was called.
*/
int PrevTok() const
{
return prevTok;
}
/**
* Function GetCurStrAsToken
* Used to support "loose" matches (quoted tokens)
*/
int GetCurStrAsToken() const
{
return findToken( curText );
}
//-----</overload return values to tokens>-----------------------------
/**
* Function SetStringDelimiter
* changes the string delimiter from the default " to some other character
* and returns the old value.
* @param aStringDelimiter The character in lowest 8 bits.
* @return int - The old delimiter in the lowest 8 bits.
*/
char SetStringDelimiter( char aStringDelimiter )
{
int old = stringDelimiter;
if( specctraMode )
stringDelimiter = aStringDelimiter;
return old;
}
/**
* Function SetSpaceInQuotedTokens
* changes the setting controlling whether a space in a quoted string is
* a terminator.
* @param val If true, means
*/
bool SetSpaceInQuotedTokens( bool val )
{
bool old = space_in_quoted_tokens;
if( specctraMode )
space_in_quoted_tokens = val;
return old;
}
/**
* Function SetCommentsAreTokens
* changes the handling of comments. If set true, comments are returns
* as single line strings with a terminating newline, else they are
* consumed by the lexer and not returned.
*/
bool SetCommentsAreTokens( bool val )
{
bool old = commentsAreTokens;
commentsAreTokens = val;
return old;
}
/**
* Function ReadCommentLines
* checks the next sequence of tokens and reads them into a wxArrayString
* if they are comments. Reading continues until a non-comment token is
* encountered, and such last read token remains as CurTok() and as CurText().
* No push back or "un get" mechanism is used for this support. Upon return
* you simply avoid calling NextTok() for the next token, but rather CurTok().
*
* @return wxArrayString* - heap allocated block of comments, or NULL if none;
* caller owns the allocation and must delete if not NULL.
*/
wxArrayString* ReadCommentLines();
/**
* Function IsSymbol
* tests a token to see if it is a symbol. This means it cannot be a
* special delimiter character such as DSN_LEFT, DSN_RIGHT, DSN_QUOTE, etc. It may
* however, coincidentally match a keyword and still be a symbol.
*/
static bool IsSymbol( int aTok );
/**
* Function Expecting
* throws an IO_ERROR exception with an input file specific error message.
* @param aTok is the token/keyword type which was expected at the current input location.
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Expecting( int aTok ) const;
/**
* Function Expecting
* throws an IO_ERROR exception with an input file specific error message.
* @param aTokenList is the token/keyword type which was expected at the
* current input location, e.g. "pin|graphic|property"
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Expecting( const char* aTokenList ) const;
/**
* Function Unexpected
* throws an IO_ERROR exception with an input file specific error message.
* @param aTok is the token/keyword type which was not expected at the
* current input location.
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Unexpected( int aTok ) const;
/**
* Function Unexpected
* throws an IO_ERROR exception with an input file specific error message.
* @param aToken is the token which was not expected at the
* current input location.
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Unexpected( const char* aToken ) const;
/**
* Function Duplicate
* throws an IO_ERROR exception with a message saying specifically that aTok
* is a duplicate of one already seen in current context.
* @param aTok is the token/keyword type which was not expected at the
* current input location.
* @throw IO_ERROR with the location within the input file of the problem.
*/
void Duplicate( int aTok );
/**
* Function NeedLEFT
* calls NextTok() and then verifies that the token read in is a DSN_LEFT.
* If it is not, an IO_ERROR is thrown.
* @throw IO_ERROR, if the next token is not a DSN_LEFT
*/
void NeedLEFT();
/**
* Function NeedRIGHT
* calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
* If it is not, an IO_ERROR is thrown.
* @throw IO_ERROR, if the next token is not a DSN_RIGHT
*/
void NeedRIGHT();
/**
* Function GetTokenText
* returns the C string representation of a DSN_T value.
*/
const char* GetTokenText( int aTok ) const;
/**
* Function GetTokenString
* returns a quote wrapped wxString representation of a token value.
*/
wxString GetTokenString( int aTok ) const;
static const char* Syntax( int aTok );
/**
* Function CurText
* returns a pointer to the current token's text.
*/
const char* CurText() const
{
return curText.c_str();
}
/**
* Function CurStr
* returns a reference to current token in std::string form.
*/
const std::string& CurStr() const
{
return curText;
}
/**
* Function FromUTF8
* returns the current token text as a wxString, assuming that the input
* byte stream is UTF8 encoded.
*/
wxString FromUTF8() const
{
return wxString::FromUTF8( curText.c_str() );
}
/**
* Function CurLineNumber
* returns the current line number within my LINE_READER
*/
int CurLineNumber() const
{
return reader->LineNumber();
}
/**
* Function CurLine
* returns the current line of text, from which the CurText() would return
* its token.
*/
const char* CurLine() const
{
return (const char*)(*reader);
}
/**
* Function CurFilename
* returns the current LINE_READER source.
* @return const wxString& - the source of the lines of text,
* e.g. a filename or "clipboard".
*/
const wxString& CurSource() const
{
return reader->GetSource();
}
/**
* Function CurOffset
* returns the byte offset within the current line, using a 1 based index.
* @return int - a one based index into the current line.
*/
int CurOffset() const
{
return curOffset + 1;
}
}; };
#endif // DSNLEXER_H_ #endif // DSNLEXER_H_

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2009-2015 Jean-Pierre Charras, jp.charras wanadoo.fr * Copyright (C) 2009-2015 Jean-Pierre Charras, jp.charras wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -96,140 +96,15 @@ wxDECLARE_EVENT( UNITS_CHANGED, wxCommandEvent );
* This class is not intended to be used directly. It provides support for automatic calls * This class is not intended to be used directly. It provides support for automatic calls
* to SaveSettings() function. SaveSettings() for a derived class can choose to do nothing, * to SaveSettings() function. SaveSettings() for a derived class can choose to do nothing,
* or rely on basic SaveSettings() support in this base class to do most of the work by * or rely on basic SaveSettings() support in this base class to do most of the work by
* calling it from the derived class's SaveSettings(). * calling it from the derived class's SaveSettings(). This class is not a #KIWAY_PLAYER
* <p> * because #KICAD_MANAGER_FRAME is derived from it and that class is not a player.
* This class is not a KIWAY_PLAYER because KICAD_MANAGER_FRAME is derived from it
* and that class is not a player.
* </p>
*/ */
class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER class EDA_BASE_FRAME : public wxFrame, public TOOLS_HOLDER, public KIWAY_HOLDER
{ {
/**
* (with its unexpected name so it does not collide with the real OnWindowClose()
* function provided in derived classes) is called just before a window
* closing, and is used to call a derivation specific
* SaveSettings(). SaveSettings() is called for all derived wxFrames in this
* base class overload. (Calling it from a destructor is deprecated since the
* wxFrame's position is not available in the destructor on linux.) In other words,
* you should not need to call SaveSettings() anywhere, except in this
* one function found only in this class.
*/
void windowClosing( wxCloseEvent& event );
wxWindow* findQuasiModalDialog();
/**
* Return true if the frame is shown in our modal mode
* and false if the frame is shown as an usual frame
* In modal mode, the caller that created the frame is responsible to Destroy()
* this frame after closing
*/
virtual bool IsModal() const { return false; }
protected:
FRAME_T m_ident; // Id Type (pcb, schematic, library..)
wxPoint m_framePos;
wxSize m_frameSize;
bool m_maximizeByDefault;
// These contain the frame size and position for when it is not maximized
wxPoint m_normalFramePos;
wxSize m_normalFrameSize;
wxString m_aboutTitle; // Name of program displayed in About.
wxAuiManager m_auimgr;
wxString m_perspective; // wxAuiManager perspective.
WX_INFOBAR* m_infoBar; // Infobar for the frame
wxString m_configName; // Prefix used to identify some params (frame size...)
// and to name some config files (legacy hotkey files)
SETTINGS_MANAGER* m_settingsManager;
FILE_HISTORY* m_fileHistory; // The frame's recently opened file list
bool m_hasAutoSave;
bool m_autoSaveState;
int m_autoSaveInterval; // The auto save interval time in seconds.
wxTimer* m_autoSaveTimer;
int m_undoRedoCountMax; // undo/Redo command Max depth
UNDO_REDO_CONTAINER m_undoList; // Objects list for the undo command (old data)
UNDO_REDO_CONTAINER m_redoList; // Objects list for the redo command (old data)
wxString m_mruPath; // Most recently used path.
EDA_UNITS m_userUnits;
// Map containing the UI update handlers registered with wx for each action
std::map<int, UIUpdateHandler> m_uiUpdateMap;
bool m_isClosing; // Set by the close window event handler after frames are asked if they can close
// Allows other functions when called to know our state is cleanup
bool m_isNonUserClose; // Set by NonUserClose() to indicate that the user did not request the current close
///> Default style flags used for wxAUI toolbars
static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
/**
* @return the suffix to be appended to the file extension on backup
*/
static wxString GetBackupSuffix()
{
return wxT( "-bak" );
}
/**
* @return the string to prepend to a file name for automatic save.
*/
static wxString GetAutoSaveFilePrefix()
{
return wxT( "_autosave-" );
}
/**
* Handle the auto save timer event.
*/
void onAutoSaveTimer( wxTimerEvent& aEvent );
/**
* Return the auto save status of the application.
*
* Override this function if your derived frame supports automatic file saving.
*/
virtual bool isAutoSaveRequired() const { return false; }
/**
* This should be overridden by the derived class to handle the auto save feature.
*
* @return true if the auto save was successful otherwise false.
*/
virtual bool doAutoSave();
virtual bool canCloseWindow( wxCloseEvent& aCloseEvent ) { return true; }
virtual void doCloseWindow() { }
/**
* Called when when the units setting has changed to allow for any derived classes
* to handle refreshing and controls that have units based measurements in them. The
* default version only updates the status bar. Don't forget to call the default
* in your derived class or the status bar will not get updated properly.
*/
virtual void unitsChangeRefresh() { }
/**
* Setup the UI conditions for the various actions and their controls in this frame.
*/
virtual void setupUIConditions();
DECLARE_EVENT_TABLE()
public: public:
EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize, const wxPoint& aPos, const wxSize& aSize, long aStyle,
long aStyle, const wxString& aFrameName, KIWAY* aKiway ); const wxString& aFrameName, KIWAY* aKiway );
~EDA_BASE_FRAME(); ~EDA_BASE_FRAME();
@ -272,7 +147,7 @@ public:
virtual void OnCharHook( wxKeyEvent& event ); virtual void OnCharHook( wxKeyEvent& event );
/** /**
* The TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu * The #TOOL_DISPATCHER needs these to work around some issues in wxWidgets where the menu
* events aren't captured by the menus themselves. * events aren't captured by the menus themselves.
*/ */
void OnMenuEvent( wxMenuEvent& event ); void OnMenuEvent( wxMenuEvent& event );
@ -293,12 +168,12 @@ public:
virtual void UnregisterUIUpdateHandler( int aID ) override; virtual void UnregisterUIUpdateHandler( int aID ) override;
/** /**
* Handles events generated when the UI is trying to figure out the current state of the UI controls * Handle events generated when the UI is trying to figure out the current state of the
* related to TOOL_ACTIONS (e.g. enabled, checked, etc.). * UI controls related to #TOOL_ACTIONS (e.g. enabled, checked, etc.).
* *
* @param aEvent is the wxUpdateUIEvent to be processed. * @param aEvent is the wxUpdateUIEvent to be processed.
* @param aFrame is the frame to get the selection from * @param aFrame is the frame to get the selection from
* @param aCond are the UI SELECTION_CONDITIONS used * @param aCond are the #UI SELECTION_CONDITIONS used
*/ */
static void HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame, static void HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
ACTION_CONDITIONS aCond ); ACTION_CONDITIONS aCond );
@ -317,7 +192,7 @@ public:
bool IsType( FRAME_T aType ) const { return m_ident == aType; } bool IsType( FRAME_T aType ) const { return m_ident == aType; }
/** /**
* Return a SEARCH_STACK pertaining to entire program. * Return a #SEARCH_STACK pertaining to entire program.
* *
* This is overloaded in #KICAD_MANAGER_FRAME * This is overloaded in #KICAD_MANAGER_FRAME
*/ */
@ -331,104 +206,113 @@ public:
void PrintMsg( const wxString& text ); void PrintMsg( const wxString& text );
/** /**
* @return the WX_INFOBAR that can be displayed on the top of the canvas * @return the #WX_INFOBAR that can be displayed on the top of the canvas.
*/ */
WX_INFOBAR* GetInfoBar() { return m_infoBar; } WX_INFOBAR* GetInfoBar() { return m_infoBar; }
/** /**
* Show the WX_INFOBAR displayed on the top of the canvas with a message * Show the #WX_INFOBAR displayed on the top of the canvas with a message
* and a Error icon on the left of the infobar. The infobar will be closed * and a error icon on the left of the infobar.
* after a timeaout *
* The infobar will be closed after a timeout.
*
* @param aErrorMsg is the message to display * @param aErrorMsg is the message to display
* @param aShowCloseButton = true to show a close button on the right of the * @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
* WX_INFOBAR
*/ */
void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton = false ); void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton = false );
/** /**
* Show the WX_INFOBAR displayed on the top of the canvas with a message * Show the #WX_INFOBAR displayed on the top of the canvas with a message and a warning
* and a Warning icon on the left of the infobar. The infobar will be closed * icon on the left of the infobar.
* after a timeaout *
* @param aErrorMsg is the message to display * The infobar will be closed after a timeout.
* @param aShowCloseButton = true to show a close button on the right of the *
* WX_INFOBAR * @param aErrorMsg is the message to display.
* @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
*/ */
void ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton = false ); void ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton = false );
/** /**
* Show the WX_INFOBAR displayed on the top of the canvas with a message * Show the #WX_INFOBAR displayed on the top of the canvas with a message and an info
* and a Info icon on the left of the infobar. The infobar will be closed * icon on the left of the infobar.
* after a timeaout *
* @param aErrorMsg is the message to display * The infobar will be closed after a timeout.
* @param aShowCloseButton = true to show a close button on the right of the *
* WX_INFOBAR * @param aErrorMsg is the message to display.
* @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
*/ */
void ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton = false ); void ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton = false );
/** /**
* Returns the settings object used in SaveSettings(), and is overloaded in * Returns the settings object used in SaveSettings(), and is overloaded in
* KICAD_MANAGER_FRAME * #KICAD_MANAGER_FRAME.
*/ */
virtual APP_SETTINGS_BASE* config() const; virtual APP_SETTINGS_BASE* config() const;
/** /**
* Function InstallPreferences
* Allow a frame to load its preference panels (if any) into the preferences dialog. * Allow a frame to load its preference panels (if any) into the preferences dialog.
* @param aParent a paged dialog into which the preference panels should be installed *
* @param aParent a paged dialog into which the preference panels should be installed.
*/ */
virtual void InstallPreferences( PAGED_DIALOG* , PANEL_HOTKEYS_EDITOR* ) { } virtual void InstallPreferences( PAGED_DIALOG* , PANEL_HOTKEYS_EDITOR* ) { }
void LoadWindowState( const wxString& aFileName ); void LoadWindowState( const wxString& aFileName );
/** /**
* Loads window settings from the given settings object * Load window settings from the given settings object.
* Normally called by LoadSettings unless the window in question is a child window that *
* stores its settings somewhere other than APP_SETTINGS_BASE::m_Window * Normally called by #LoadSettings() unless the window in question is a child window
* that* stores its settings somewhere other than #APP_SETTINGS_BASE::m_Window.
*/ */
void LoadWindowSettings( const WINDOW_SETTINGS* aCfg ); void LoadWindowSettings( const WINDOW_SETTINGS* aCfg );
/** /**
* Saves window settings to the given settings object * Save window settings to the given settings object.
* Normally called by SaveSettings unless the window in question is a child window that *
* stores its settings somewhere other than APP_SETTINGS_BASE::m_Window * Normally called by #SaveSettings unless the window in question is a child window that
* stores its settings somewhere other than #APP_SETTINGS_BASE::m_Window.
*/ */
void SaveWindowSettings( WINDOW_SETTINGS* aCfg ); void SaveWindowSettings( WINDOW_SETTINGS* aCfg );
/** /**
* Load common frame parameters from a configuration file. * Load common frame parameters from a configuration file.
* *
* Don't forget to call the base method or your frames won't * Don't forget to call the base method or your frames won't remember their positions
* remember their positions and sizes. * and sizes.
*/ */
virtual void LoadSettings( APP_SETTINGS_BASE* aCfg ); virtual void LoadSettings( APP_SETTINGS_BASE* aCfg );
/** /**
* Saves common frame parameters to a configuration data file. * Save common frame parameters to a configuration data file.
* *
* Don't forget to call the base class's SaveSettings() from * Don't forget to call the base class's SaveSettings() from your derived
* your derived SaveSettings() otherwise the frames won't remember their * #SaveSettings() otherwise the frames won't remember their positions and sizes.
* positions and sizes.
*/ */
virtual void SaveSettings( APP_SETTINGS_BASE* aCfg ); virtual void SaveSettings( APP_SETTINGS_BASE* aCfg );
/** /**
* Returns a pointer to the window settings for this frame. * Return a pointer to the window settings for this frame.
*
* By default, points to aCfg->m_Window for top-level frames. * By default, points to aCfg->m_Window for top-level frames.
*
* @param aCfg is this frame's config object * @param aCfg is this frame's config object
*/ */
virtual WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg ); virtual WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg );
/** /**
* Load frame state info from a configuration file * Load frame state info from a configuration file
*/ */
virtual void LoadWindowState( const WINDOW_STATE& aState ); virtual void LoadWindowState( const WINDOW_STATE& aState );
/** /**
* Get the configuration base name.
*
* This is usually the name of the frame set by CTOR, except for frames shown in
* multiple modes in which case the m_configName must be set to the base name so
* that a single configuration can be used.
*
* @return a base name prefix used in Load/Save settings to build the full name of keys * @return a base name prefix used in Load/Save settings to build the full name of keys
* used in config. * used in configuration.
* This is usually the name of the frame set by CTOR, except for frames shown in multiple
* modes in which case the m_configName must be set to the base name so that a single
* config can be used.
*/ */
wxString ConfigBaseName() override wxString ConfigBaseName() override
{ {
@ -440,19 +324,18 @@ public:
* Save changes to the project settings to the project (.pro) file. * Save changes to the project settings to the project (.pro) file.
* *
* The method is virtual so you can override it to call the suitable save method. * The method is virtual so you can override it to call the suitable save method.
* The base method do nothing * The base method does nothing.
* @param aAskForSave = true to open a dialog before saving the settings *
* @param aAskForSave true to open a dialog before saving the settings.
*/ */
virtual void SaveProjectSettings() {}; virtual void SaveProjectSettings() {};
// Read/Save and Import/export hotkeys config
/** /**
* Prompt the user for a hotkey file to read, and read it. * Prompt the user for a hotkey file to read, and read it.
* *
* @param aActionMap = current hotkey map (over which the imported hotkeys will be applied) * @param aActionMap current hotkey map (over which the imported hotkeys will be applied).
* @param aDefaultShortname = a default short name (extension not needed) * @param aDefaultShortname a default short name (extension not needed) like
* like eechema, kicad... * Eeschema, KiCad...
*/ */
void ImportHotkeyConfigFromFile( std::map<std::string, TOOL_ACTION*> aActionMap, void ImportHotkeyConfigFromFile( std::map<std::string, TOOL_ACTION*> aActionMap,
const wxString& aDefaultShortname ); const wxString& aDefaultShortname );
@ -461,7 +344,7 @@ public:
* Fetches the file name from the file history list. * Fetches the file name from the file history list.
* *
* This removes the selected file, if this file does not exist. The menu is also updated, * This removes the selected file, if this file does not exist. The menu is also updated,
* if FILE_HISTORY::UseMenu was called at init time * if #FILE_HISTORY::UseMenu was called at initialization time.
* *
* @param cmdId The command ID associated with the \a aFileHistory object. * @param cmdId The command ID associated with the \a aFileHistory object.
* @param type Please document me! * @param type Please document me!
@ -486,8 +369,8 @@ public:
* The menu is also updated, if FILE_HISTORY::UseMenu was called at init time. * The menu is also updated, if FILE_HISTORY::UseMenu was called at init time.
* *
* @param FullFileName The full file name including the path. * @param FullFileName The full file name including the path.
* @param aFileHistory The FILE_HISTORY in use. * @param aFileHistory The FILE_HISTORY in use. If NULL, the main application file
* If NULL, the main application file history is used. * history is used.
*/ */
void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = nullptr ); void UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory = nullptr );
@ -507,6 +390,7 @@ public:
/** /**
* Get the full filename + path of the currently opened file in the frame. * Get the full filename + path of the currently opened file in the frame.
*
* If no file is open, an empty string is returned. * If no file is open, an empty string is returned.
* *
* @return the filename and full path to the open file * @return the filename and full path to the open file
@ -527,13 +411,13 @@ public:
/** /**
* Checks if \a aFileName can be written. * Checks if \a aFileName can be written.
* <p> *
* The function performs a number of tests on \a aFileName to verify that it can be saved. * The function performs a number of tests on \a aFileName to verify that it can be saved.
* If \a aFileName defines a path with no file name, them the path is tested for user write * If \a aFileName defines a path with no file name, them the path is tested for user write
* permission. If \a aFileName defines a file name that does not exist in the path, the * permission. If \a aFileName defines a file name that does not exist in the path, the
* path is tested for user write permission. If \a aFileName defines a file that already * path is tested for user write permission. If \a aFileName defines a file that already
* exits, the file name is tested for user write permissions. * exits, the file name is tested for user write permissions.
* </p> *>
* @note The file name path must be set or an assertion will be raised on debug builds and * @note The file name path must be set or an assertion will be raised on debug builds and
* return false on release builds. * return false on release builds.
* @param aFileName The full path and/or file name of the file to test. * @param aFileName The full path and/or file name of the file to test.
@ -544,13 +428,13 @@ public:
/** /**
* Check if an auto save file exists for \a aFileName and takes the appropriate action * Check if an auto save file exists for \a aFileName and takes the appropriate action
* depending on the user input. * depending on the user input.
* <p> *
* If an auto save file exists for \a aFileName, the user is prompted if they wish to * If an auto save file exists for \a aFileName, the user is prompted if they wish to
* replace file \a aFileName with the auto saved file. If the user chooses to replace the * replace file \a aFileName with the auto saved file. If the user chooses to replace the
* file, the backup file of \a aFileName is removed, \a aFileName is renamed to the backup * file, the backup file of \a aFileName is removed, \a aFileName is renamed to the backup
* file name, and the auto save file is renamed to \a aFileName. If user chooses to keep * file name, and the auto save file is renamed to \a aFileName. If user chooses to keep
* the existing version of \a aFileName, the auto save file is removed. * the existing version of \a aFileName, the auto save file is removed.
* </p> *
* @param aFileName A wxFileName object containing the file name to check. * @param aFileName A wxFileName object containing the file name to check.
*/ */
void CheckForAutoSaveFile( const wxFileName& aFileName ); void CheckForAutoSaveFile( const wxFileName& aFileName );
@ -599,60 +483,50 @@ public:
*/ */
wxSize GetWindowSize(); wxSize GetWindowSize();
/* general Undo/Redo command control */
/** /**
* Function ClearUndoORRedoList (virtual). * Remove the \a aItemCount of old commands from \a aList and delete commands, pickers
* this function must remove the aItemCount old commands from aList * and picked items if needed.
* and delete commands, pickers and picked items if needed *
* Because picked items must be deleted only if they are not in use, this * Because picked items must be deleted only if they are not in use, this is a virtual
* is a virtual pure function that must be created for SCH_SCREEN and * pure function that must be created for #SCH_SCREEN and #PCB_SCREEN. Commands are
* PCB_SCREEN * deleted from the older to the last.
* @param aList = the UNDO_REDO_CONTAINER of commands *
* @param aItemCount = number of old commands to delete. -1 to remove all * @param aList = the #UNDO_REDO_CONTAINER of commands.
* old commands this will empty the list of commands. * @param aItemCount number of old commands to delete. -1 to remove all old commands
* Commands are deleted from the older to the last. * this will empty the list of commands.
*/ */
enum UNDO_REDO_LIST { UNDO_LIST, REDO_LIST }; enum UNDO_REDO_LIST { UNDO_LIST, REDO_LIST };
virtual void ClearUndoORRedoList( UNDO_REDO_LIST aList, int aItemCount = -1 ) virtual void ClearUndoORRedoList( UNDO_REDO_LIST aList, int aItemCount = -1 )
{ } { }
/** /**
* Function ClearUndoRedoList * Clear the undo and redo list using #ClearUndoORRedoList()
* clear undo and redo list, using ClearUndoORRedoList() *
* picked items are deleted by ClearUndoORRedoList() according to their * Picked items are deleted by ClearUndoORRedoList() according to their status.
* status
*/ */
virtual void ClearUndoRedoList(); virtual void ClearUndoRedoList();
/** /**
* Function PushCommandToUndoList * Add a command to undo in the undo list.
* add a command to undo in undo list *
* delete the very old commands when the max count of undo commands is * Delete the very old commands when the max count of undo commands is reached.
* reached
* ( using ClearUndoORRedoList)
*/ */
virtual void PushCommandToUndoList( PICKED_ITEMS_LIST* aItem ); virtual void PushCommandToUndoList( PICKED_ITEMS_LIST* aItem );
/** /**
* Function PushCommandToRedoList * Add a command to redo in the redo list.
* add a command to redo in redo list *
* delete the very old commands when the max count of redo commands is * Delete the very old commands when the max count of redo commands is reached.
* reached
* ( using ClearUndoORRedoList)
*/ */
virtual void PushCommandToRedoList( PICKED_ITEMS_LIST* aItem ); virtual void PushCommandToRedoList( PICKED_ITEMS_LIST* aItem );
/** PopCommandFromUndoList /**
* return the last command to undo and remove it from list * Return the last command to undo and remove it from list, nothing is deleted.
* nothing is deleted.
*/ */
virtual PICKED_ITEMS_LIST* PopCommandFromUndoList(); virtual PICKED_ITEMS_LIST* PopCommandFromUndoList();
/** PopCommandFromRedoList /**
* return the last command to undo and remove it from list * Return the last command to undo and remove it from list, nothing is deleted.
* nothing is deleted.
*/ */
virtual PICKED_ITEMS_LIST* PopCommandFromRedoList(); virtual PICKED_ITEMS_LIST* PopCommandFromRedoList();
@ -666,6 +540,137 @@ public:
m_isNonUserClose = true; m_isNonUserClose = true;
return Close( aForce ); return Close( aForce );
} }
protected:
///< Default style flags used for wxAUI toolbars.
static constexpr int KICAD_AUI_TB_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_PLAIN_BACKGROUND;
/**
* @return the suffix to be appended to the file extension on backup
*/
static wxString GetBackupSuffix()
{
return wxT( "-bak" );
}
/**
* @return the string to prepend to a file name for automatic save.
*/
static wxString GetAutoSaveFilePrefix()
{
return wxT( "_autosave-" );
}
/**
* Handle the auto save timer event.
*/
void onAutoSaveTimer( wxTimerEvent& aEvent );
/**
* Return the auto save status of the application.
*
* Override this function if your derived frame supports automatic file saving.
*/
virtual bool isAutoSaveRequired() const { return false; }
/**
* This should be overridden by the derived class to handle the auto save feature.
*
* @return true if the auto save was successful otherwise false.
*/
virtual bool doAutoSave();
virtual bool canCloseWindow( wxCloseEvent& aCloseEvent ) { return true; }
virtual void doCloseWindow() { }
/**
* Called when when the units setting has changed to allow for any derived classes
* to handle refreshing and controls that have units based measurements in them.
*
* The default version only updates the status bar. Don't forget to call the default
* in your derived class or the status bar will not get updated properly.
*/
virtual void unitsChangeRefresh() { }
/**
* Setup the UI conditions for the various actions and their controls in this frame.
*/
virtual void setupUIConditions();
DECLARE_EVENT_TABLE()
private:
/**
* (with its unexpected name so it does not collide with the real OnWindowClose()
* function provided in derived classes) is called just before a window
* closing, and is used to call a derivation specific SaveSettings().
*
* #SaveSettings() is called for all derived wxFrames in this base class overload.
* Calling it from a destructor is deprecated since the wxFrame's position is not
* available in the destructor on linux. In other words, you should not need to
* call #SaveSettings() anywhere, except in this one function found only in this class.
*/
void windowClosing( wxCloseEvent& event );
wxWindow* findQuasiModalDialog();
/**
* Return true if the frame is shown in our modal mode and false if the frame is
* shown as an usual frame.
*
* In modal mode, the caller that created the frame is responsible to Destroy()
* this frame after closing.
*/
virtual bool IsModal() const { return false; }
protected:
FRAME_T m_ident; // Id Type (pcb, schematic, library..)
wxPoint m_framePos;
wxSize m_frameSize;
bool m_maximizeByDefault;
// These contain the frame size and position for when it is not maximized
wxPoint m_normalFramePos;
wxSize m_normalFrameSize;
wxString m_aboutTitle; // Name of program displayed in About.
wxAuiManager m_auimgr;
wxString m_perspective; // wxAuiManager perspective.
WX_INFOBAR* m_infoBar; // Infobar for the frame
wxString m_configName; // Prefix used to identify some params (frame size...)
// and to name some config files (legacy hotkey files)
SETTINGS_MANAGER* m_settingsManager;
FILE_HISTORY* m_fileHistory; // The frame's recently opened file list
bool m_hasAutoSave;
bool m_autoSaveState;
int m_autoSaveInterval; // The auto save interval time in seconds.
wxTimer* m_autoSaveTimer;
int m_undoRedoCountMax; // undo/Redo command Max depth
UNDO_REDO_CONTAINER m_undoList; // Objects list for the undo command (old data)
UNDO_REDO_CONTAINER m_redoList; // Objects list for the redo command (old data)
wxString m_mruPath; // Most recently used path.
EDA_UNITS m_userUnits;
///< Map containing the UI update handlers registered with wx for each action.
std::map<int, UIUpdateHandler> m_uiUpdateMap;
///< Set by the close window event handler after frames are asked if they can close.
///< Allows other functions when called to know our state is cleanup.
bool m_isClosing;
///< Set by #NonUserClose() to indicate that the user did not request the current close.
bool m_isNonUserClose;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2009-2014 Jerry Jacobs * Copyright (C) 2009-2014 Jerry Jacobs
* Copyright (C) 1992-2019 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 1992-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -33,24 +33,23 @@
/** /**
* Function KeywordMatch * Search \a aKeyList for any words found in \a aDatabase.
* searches \a aKeyList for any words found in \a aDatabase.
* *
* @return true if keyword is found. * @return true if keyword is found.
*/ */
bool KeywordMatch( const wxString& aKeys, const wxString& aDatabase ); bool KeywordMatch( const wxString& aKeys, const wxString& aDatabase );
/** /**
* Function GetAssociatedDocument * Open a document (file) with the suitable browser.
* open a document (file) with the suitable browser. Environmental variables are *
* substituted before the document name is resolved for either browser or file * Environmental variables are substituted before the document name is resolved for
* @param aParent = main frame * either browser or file. If \a aDocName begins with http: or ftp: or www. the
* @param aDocName = filename of file to open (Full filename or short filename) * default internet browser is launched.
* if \a aDocName begins with http: or ftp: or www. the default internet browser is launched *
* @param aParent main frame.
* @param aDocName filename of file to open (Full filename or short filename).
*/ */
bool GetAssociatedDocument( wxWindow* aParent, bool GetAssociatedDocument( wxWindow* aParent, const wxString& aDocName, PROJECT* aProject );
const wxString& aDocName,
PROJECT* aProject );
#endif /* __INCLUDE__EDA_DOC_H__ */ #endif /* __INCLUDE__EDA_DOC_H__ */

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -61,99 +61,26 @@ using KIGFX::RENDER_SETTINGS;
/** /**
* The base class for create windows for drawing purpose. The Eeschema, Pcbnew and * The base class for create windows for drawing purpose.
* GerbView main windows are just a few examples of classes derived from EDA_DRAW_FRAME. *
* The Eeschema, Pcbnew and GerbView main windows are just a few examples of classes
* derived from EDA_DRAW_FRAME.
*/ */
class EDA_DRAW_FRAME : public KIWAY_PLAYER class EDA_DRAW_FRAME : public KIWAY_PLAYER
{ {
BASE_SCREEN* m_currentScreen; ///< current used SCREEN
EDA_DRAW_PANEL_GAL* m_canvas;
///< GAL display options - this is the frame's interface to setting GAL display options
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions;
/// Default display origin transforms object
ORIGIN_TRANSFORMS m_originTransforms;
protected:
wxSocketServer* m_socketServer;
std::vector<wxSocketBase*> m_sockets; ///< interprocess communication
std::unique_ptr<wxSingleInstanceChecker> m_file_checker; ///< prevents opening same file multiple times.
bool m_showPageLimits; // True to display the page limits
COLOR4D m_gridColor; // Grid color
COLOR4D m_drawBgColor; // The background color of the draw canvas; BLACK for
// Pcbnew, BLACK or WHITE for eeschema
int m_undoRedoCountMax; // Default Undo/Redo command Max depth, to be handed
// to screens
bool m_polarCoords; // For those frames that support polar coordinates
bool m_showBorderAndTitleBlock; // Show the worksheet (border and title block).
long m_firstRunDialogSetting; // Show first run dialog on startup
wxChoice* m_gridSelectBox;
wxChoice* m_zoomSelectBox;
ACTION_TOOLBAR* m_mainToolBar;
ACTION_TOOLBAR* m_auxiliaryToolBar; // Additional tools under main toolbar
ACTION_TOOLBAR* m_drawToolBar; // Drawing tools (typically on right edge of window)
ACTION_TOOLBAR* m_optionsToolBar; // Options (typically on left edge of window)
wxFindReplaceData* m_findReplaceData;
wxArrayString m_findStringHistoryList;
wxArrayString m_replaceStringHistoryList;
EDA_MSG_PANEL* m_messagePanel;
int m_msgFrameHeight;
COLOR_SETTINGS* m_colorSettings;
/// The current canvas type
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType;
virtual void SetScreen( BASE_SCREEN* aScreen ) { m_currentScreen = aScreen; }
void unitsChangeRefresh() override;
void setupUnits( APP_SETTINGS_BASE* aCfg );
/**
* Determines the Canvas type to load (with prompt if required) and initializes m_canvasType
*/
void resolveCanvasType();
/**
* Returns the canvas type stored in the application settings.
*/
EDA_DRAW_PANEL_GAL::GAL_TYPE loadCanvasTypeSetting();
/**
* Stores the canvas type in the application settings.
*/
bool saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType );
/**
* Sets the common key-pair for exiting the application (Ctrl-Q) and ties it
* to the wxID_EXIT event id. This is useful in sub-applications to pass the event
* up to a non-owning window
*/
void initExitKey();
public: public:
EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
FRAME_T aFrameType, const wxPoint& aPos, const wxSize& aSize, long aStyle,
const wxString& aTitle,
const wxPoint& aPos, const wxSize& aSize,
long aStyle,
const wxString& aFrameName ); const wxString& aFrameName );
~EDA_DRAW_FRAME(); ~EDA_DRAW_FRAME();
/** /**
* Mark a schematic file as being in use. Use ReleaseFile() to undo this. * Mark a schematic file as being in use.
* *
* @param aFileName = full path to the file. * Use #ReleaseFile() to undo this.
*
* @param aFileName full path to the file.
* @return false if the file was already locked, true otherwise. * @return false if the file was already locked, true otherwise.
*/ */
bool LockFile( const wxString& aFileName ); bool LockFile( const wxString& aFileName );
@ -184,15 +111,17 @@ public:
void ToggleUserUnits() override; void ToggleUserUnits() override;
/** /**
* Get the pair or units in current use. The primary unit is the main * Get the pair or units in current use.
* unit of the frame, and the secondary unit is the unit of the other *
* system that was used most recently. * The primary unit is the main unit of the frame, and the secondary unit is the unit
* of the other system that was used most recently.
*/ */
void GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits ); void GetUnitPair( EDA_UNITS& aPrimaryUnit, EDA_UNITS& aSecondaryUnits );
/** /**
* Return the absolute coordinates of the origin of the snap grid. This is * Return the absolute coordinates of the origin of the snap grid.
* treated as a relative offset, and snapping will occur at multiples of the grid *
* This is treated as a relative offset and snapping will occur at multiples of the grid
* size relative to this point. * size relative to this point.
*/ */
virtual const wxPoint& GetGridOrigin() const = 0; virtual const wxPoint& GetGridOrigin() const = 0;
@ -202,7 +131,7 @@ public:
* Return the nearest \a aGridSize location to \a aPosition. * Return the nearest \a aGridSize location to \a aPosition.
* *
* @param aPosition The position to check. * @param aPosition The position to check.
* @return The nearst grid position. * @return The nearest grid position.
*/ */
wxPoint GetNearestGridPosition( const wxPoint& aPosition ) const; wxPoint GetNearestGridPosition( const wxPoint& aPosition ) const;
@ -236,23 +165,24 @@ public:
* @param isDirectory indicates the library files are directories * @param isDirectory indicates the library files are directories
* @return true for OK; false for Cancel. * @return true for OK; false for Cancel.
*/ */
bool LibraryFileBrowser( bool doOpen, wxFileName& aFilename, bool LibraryFileBrowser( bool doOpen, wxFileName& aFilename, const wxString& wildcard,
const wxString& wildcard, const wxString& ext, const wxString& ext, bool isDirectory = false );
bool isDirectory = false );
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override; void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
virtual wxString GetScreenDesc() const; virtual wxString GetScreenDesc() const;
/** /**
* Return a pointer to a BASE_SCREEN or one of its derivatives. It is overloaded by * Return a pointer to a BASE_SCREEN or one of its derivatives.
* derived classes to return SCH_SCREEN or PCB_SCREEN. *
* It is overloaded by derived classes to return #SCH_SCREEN or #PCB_SCREEN.
*/ */
virtual BASE_SCREEN* GetScreen() const { return m_currentScreen; } virtual BASE_SCREEN* GetScreen() const { return m_currentScreen; }
/** /**
* Execute a remote command sent via socket (to port KICAD_PCB_PORT_SERVICE_NUMBER, * Execute a remote command sent via socket (to port KICAD_PCB_PORT_SERVICE_NUMBER,
* currently 4242). * currently 4242).
*
* Subclasses should override to implement actual command handlers. * Subclasses should override to implement actual command handlers.
*/ */
virtual void ExecuteRemoteCommand( const char* cmdline ){} virtual void ExecuteRemoteCommand( const char* cmdline ){}
@ -267,6 +197,7 @@ public:
/* /*
* These 4 functions provide a basic way to show/hide grid and /get/set grid color. * These 4 functions provide a basic way to show/hide grid and /get/set grid color.
*
* These parameters are saved in KiCad config for each main frame. * These parameters are saved in KiCad config for each main frame.
*/ */
bool IsGridVisible() const; bool IsGridVisible() const;
@ -282,7 +213,7 @@ public:
* application setting is saved. If you override this method, make sure you call down * application setting is saved. If you override this method, make sure you call down
* to the base class. * to the base class.
* *
* @param event - Command event from the grid size combobox on the toolbar. * @param event Command event from the grid size combobox on the toolbar.
*/ */
void OnSelectGrid( wxCommandEvent& event ); void OnSelectGrid( wxCommandEvent& event );
@ -290,7 +221,7 @@ public:
/** /**
* Rebuild the grid combobox to respond to any changes in the GUI (units, user * Rebuild the grid combobox to respond to any changes in the GUI (units, user
* grid changes, etc.) * grid changes, etc.).
*/ */
void UpdateGridSelectBox(); void UpdateGridSelectBox();
@ -318,8 +249,8 @@ public:
/** /**
* Set the zoom factor when selected by the zoom list box in the main tool bar. * Set the zoom factor when selected by the zoom list box in the main tool bar.
* *
* @note List position 0 is fit to page * @note List position 0 is fit to page.
* List position >= 1 = zoom (1 to zoom max) * List position >= 1 = zoom (1 to zoom max).
* Last list position is custom zoom not in zoom list. * Last list position is custom zoom not in zoom list.
*/ */
virtual void OnSelectZoom( wxCommandEvent& event ); virtual void OnSelectZoom( wxCommandEvent& event );
@ -337,37 +268,37 @@ public:
virtual void HardRedraw(); virtual void HardRedraw();
/** /**
* Redraw the screen with best zoom level and the best centering * Redraw the screen with best zoom level and the best centering that shows all the
* that shows all the page or the board * page or the board.
*/ */
virtual void Zoom_Automatique( bool aWarpPointer ); virtual void Zoom_Automatique( bool aWarpPointer );
/** /**
* Useful to focus on a particular location, in find functions * Useful to focus on a particular location, in find functions.
* Move the graphic cursor (crosshair cursor) at a given coordinate and reframes *
* the drawing if the requested point is out of view or if center on location is requested. * Move the graphic cursor (crosshair cursor) at a given coordinate and reframes the
* drawing if the requested point is out of view or if center on location is requested.
*
* @param aPos is the point to go to. * @param aPos is the point to go to.
*/ */
void FocusOnLocation( const wxPoint& aPos ); void FocusOnLocation( const wxPoint& aPos );
/** /**
* Function CreateBasicMenu * Construct a "basic" menu for a tool, containing only items that apply to all tools
* * (e.g. zoom and grid).
* Construct a "basic" menu for a tool, containing only items
* that apply to all tools (e.g. zoom and grid)
*/ */
void AddStandardSubMenus( TOOL_MENU& aMenu ); void AddStandardSubMenus( TOOL_MENU& aMenu );
/** /**
* Prints the page layout with the frame and the basic inscriptions. * Prints the page layout with the frame and the basic inscriptions.
* *
* @param aScreen screen to draw * @param aScreen screen to draw.
* @param aMils2Iu The mils to Iu conversion factor. * @param aMils2Iu The mils to Iu conversion factor.
* @param aFilename The filename to display in basic inscriptions. * @param aFilename The filename to display in basic inscriptions.
* @param aSheetLayer The layer displayed from pcbnew. * @param aSheetLayer The layer displayed from PcbNew.
*/ */
void PrintWorkSheet( RENDER_SETTINGS* aSettings, BASE_SCREEN* aScreen, double aMils2Iu, void PrintWorkSheet( RENDER_SETTINGS* aSettings, BASE_SCREEN* aScreen, double aMils2Iu,
const wxString &aFilename, const wxString &aSheetLayer = wxEmptyString ); const wxString& aFilename, const wxString& aSheetLayer = wxEmptyString );
void DisplayToolMsg( const wxString& msg ) override; void DisplayToolMsg( const wxString& msg ) override;
@ -408,13 +339,12 @@ public:
/** /**
* Append a message to the message panel. * Append a message to the message panel.
* *
* This helper method checks to make sure the message panel exists in * This helper method checks to make sure the message panel exists in the frame and
* the frame and appends a message to it using the message panel * appends a message to it using the message panel AppendMessage() method.
* AppendMessage() method.
* *
* @param aTextUpper - The message upper text. * @param aTextUpper The message upper text.
* @param aTextLower - The message lower text. * @param aTextLower The message lower text.
* @param aPadding - Number of spaces to pad between messages. * @param aPadding Number of spaces to pad between messages.
*/ */
void AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding = 6 ); void AppendMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding = 6 );
@ -434,9 +364,9 @@ public:
/** /**
* Helper function that erases the msg panel and then appends a single message * Helper function that erases the msg panel and then appends a single message
* *
* @param aTextUpper - The message upper text. * @param aTextUpper The message upper text.
* @param aTextLower - The message lower text. * @param aTextLower The message lower text.
* @param aPadding - Number of spaces to pad between messages. * @param aPadding Number of spaces to pad between messages.
*/ */
void SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding = 6 ); void SetMsgPanel( const wxString& aTextUpper, const wxString& aTextLower, int aPadding = 6 );
@ -453,7 +383,7 @@ public:
/** /**
* Print the page pointed by current screen, set by the calling print function. * Print the page pointed by current screen, set by the calling print function.
* *
* @param aDC = wxDC given by the calling print function * @param aDC wxDC given by the calling print function
*/ */
virtual void PrintPage( RENDER_SETTINGS* aSettings ); virtual void PrintPage( RENDER_SETTINGS* aSettings );
@ -496,9 +426,9 @@ public:
* false makes it ignore any items outside the PCB edge such as fabrication * false makes it ignore any items outside the PCB edge such as fabrication
* notes. * notes.
* *
* @param aIncludeAllVisible - True = Include everything visible in bbox calculations * @param aIncludeAllVisible True to include everything visible in bbox calculations,
* False = Ignore some visible items (program dependent) * false to ignore some visible items (program dependent).
* @return BOX2I - Bounding box of document (ignoring some items as requested) * @return Bounding box of the document (ignoring some items as requested).
*/ */
virtual const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const; virtual const BOX2I GetDocumentExtents( bool aIncludeAllVisible = true ) const;
@ -508,6 +438,83 @@ public:
void RecreateToolbars(); void RecreateToolbars();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
protected:
virtual void SetScreen( BASE_SCREEN* aScreen ) { m_currentScreen = aScreen; }
void unitsChangeRefresh() override;
void setupUnits( APP_SETTINGS_BASE* aCfg );
/**
* Determines the Canvas type to load (with prompt if required) and initializes m_canvasType
*/
void resolveCanvasType();
/**
* Returns the canvas type stored in the application settings.
*/
EDA_DRAW_PANEL_GAL::GAL_TYPE loadCanvasTypeSetting();
/**
* Stores the canvas type in the application settings.
*/
bool saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType );
/**
* Sets the common key-pair for exiting the application (Ctrl-Q) and ties it
* to the wxID_EXIT event id.
*
* This is useful in sub-applications to pass the event up to a non-owning window.
*/
void initExitKey();
wxSocketServer* m_socketServer;
std::vector<wxSocketBase*> m_sockets; ///< interprocess communication
///< Prevents opening same file multiple times.
std::unique_ptr<wxSingleInstanceChecker> m_file_checker;
bool m_showPageLimits; // True to display the page limits
COLOR4D m_gridColor; // Grid color
COLOR4D m_drawBgColor; // The background color of the draw canvas; BLACK for
// Pcbnew, BLACK or WHITE for Eeschema
int m_undoRedoCountMax; // Default Undo/Redo command Max depth, to be handed
// to screens
bool m_polarCoords; // For those frames that support polar coordinates
bool m_showBorderAndTitleBlock; // Show the worksheet (border and title block).
long m_firstRunDialogSetting; // Show first run dialog on startup
wxChoice* m_gridSelectBox;
wxChoice* m_zoomSelectBox;
ACTION_TOOLBAR* m_mainToolBar;
ACTION_TOOLBAR* m_auxiliaryToolBar; // Additional tools under main toolbar
ACTION_TOOLBAR* m_drawToolBar; // Drawing tools (typically on right edge of window)
ACTION_TOOLBAR* m_optionsToolBar; // Options (typically on left edge of window)
wxFindReplaceData* m_findReplaceData;
wxArrayString m_findStringHistoryList;
wxArrayString m_replaceStringHistoryList;
EDA_MSG_PANEL* m_messagePanel;
int m_msgFrameHeight;
COLOR_SETTINGS* m_colorSettings;
///< The current canvas type.
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType;
private:
BASE_SCREEN* m_currentScreen; ///< current used SCREEN
EDA_DRAW_PANEL_GAL* m_canvas;
///< This the frame's interface to setting GAL display options.
KIGFX::GAL_DISPLAY_OPTIONS m_galDisplayOptions;
///< Default display origin transforms object.
ORIGIN_TRANSFORMS m_originTransforms;
}; };
#endif // DRAW_FRAME_H_ #endif // DRAW_FRAME_H_

View File

@ -70,28 +70,28 @@ class MSG_PANEL_ITEM;
/** /**
* Typedef INSPECTOR * Used to inspect and possibly collect the (search) results of iterating over a list or
* is used to inspect and possibly collect the * tree of #KICAD_T objects.
* (search) results of iterating over a list or tree of KICAD_T objects.
* Provide an implementation as needed to inspect EDA_ITEMs visited via
* EDA_ITEM::Visit() and EDA_ITEM::IterateForward().
* <p>
* FYI the std::function may hold a lambda, std::bind, pointer to func, or
* ptr to member function, per modern C++. It is used primarily for searching,
* but not limited to that. It can also collect or modify the scanned objects.
* 'Capturing' lambdas are particularly convenient because they can use context
* and this often means @a aTestData is not used.
* *
* @param aItem An EDA_ITEM to examine. * Provide an implementation as needed to inspect EDA_ITEMs visited via #EDA_ITEM::Visit()
* and #EDA_ITEM::IterateForward().
*
* FYI the std::function may hold a lambda, std::bind, pointer to func, or ptr to member
* function, per modern C++. It is used primarily for searching, but not limited to that.
* It can also collect or modify the scanned objects. 'Capturing' lambdas are particularly
* convenient because they can use context and this often means @a aTestData is not used.
*
* @param aItem An #EDA_ITEM to examine.
* @param aTestData is arbitrary data needed by the inspector to determine * @param aTestData is arbitrary data needed by the inspector to determine
* if the EDA_ITEM under test meets its match criteria, and is often NULL * if the EDA_ITEM under test meets its match criteria, and is often NULL
* with the advent of capturing lambdas. * with the advent of capturing lambdas.
* @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to * @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to
* stop the scan, else #SEARCH_CONTINUE; * stop the scan, else #SEARCH_CONTINUE;
*/ */
typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC; typedef std::function< SEARCH_RESULT ( EDA_ITEM* aItem, void* aTestData ) > INSPECTOR_FUNC;
typedef const INSPECTOR_FUNC& INSPECTOR; /// std::function passed to nested users by ref, avoids copying std::function ///< std::function passed to nested users by ref, avoids copying std::function.
typedef const INSPECTOR_FUNC& INSPECTOR;
// These define are used for the .m_flags and .m_UndoRedoStatus member of the // These define are used for the .m_flags and .m_UndoRedoStatus member of the
@ -142,41 +142,20 @@ typedef const INSPECTOR_FUNC& INSPECTOR; /// std::function passed to nested u
typedef unsigned STATUS_FLAGS; typedef unsigned STATUS_FLAGS;
/** /**
* EDA_ITEM * A base class for most all the KiCad significant classes used in schematics and boards.
* is a base class for most all the KiCad significant classes used in schematics and boards.
*/ */
class EDA_ITEM : public KIGFX::VIEW_ITEM class EDA_ITEM : public KIGFX::VIEW_ITEM
{ {
public:
const KIID m_Uuid;
private:
/**
* Run time identification, _keep private_ so it can never be changed after a ctor
* sets it. See comment near SetType() regarding virtual functions.
*/
KICAD_T m_structType;
protected:
STATUS_FLAGS m_status;
EDA_ITEM* m_parent; ///< Linked list: Link (parent struct)
bool m_forceVisible;
STATUS_FLAGS m_flags;
protected:
EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
EDA_ITEM( KICAD_T idType );
EDA_ITEM( const EDA_ITEM& base );
public: public:
virtual ~EDA_ITEM() { }; virtual ~EDA_ITEM() { };
/** /**
* Function Type() * Returns the type of object.
* *
* returns the type of object. This attribute should never be changed after a ctor sets * This attribute should never be changed after a ctor sets it, so there is no public
* it, so there is no public "setter" method. * "setter" method.
* @return KICAD_T - the type of object. *
* @return the type of object.
*/ */
inline KICAD_T Type() const { return m_structType; } inline KICAD_T Type() const { return m_structType; }
@ -242,8 +221,8 @@ public:
} }
/** /**
* Function IsType * Check whether the item is one of the listed types.
* Checks whether the item is one of the listed types *
* @param aScanTypes List of item types * @param aScanTypes List of item types
* @return true if the item type is contained in the list aScanTypes * @return true if the item type is contained in the list aScanTypes
*/ */
@ -262,9 +241,8 @@ public:
} }
/** /**
* Function SetForceVisible * Set and clear force visible flag used to force the item to be drawn even if it's draw
* is used to set and cleag force visible flag used to force the item to be drawn * attribute is set to not visible.
* even if it's draw attribute is set to not visible.
* *
* @param aEnable True forces the item to be drawn. False uses the item's visibility * @param aEnable True forces the item to be drawn. False uses the item's visibility
* setting to determine if the item is to be drawn. * setting to determine if the item is to be drawn.
@ -274,8 +252,7 @@ public:
bool IsForceVisible() const { return m_forceVisible; } bool IsForceVisible() const { return m_forceVisible; }
/** /**
* Function GetMsgPanelInfo * Populate \a aList of #MSG_PANEL_ITEM objects with it's internal state for display
* populates \a aList of #MSG_PANEL_ITEM objects with it's internal state for display
* purposes. * purposes.
* *
* @param aList is the list to populate. * @param aList is the list to populate.
@ -285,8 +262,7 @@ public:
} }
/** /**
* Function HitTest * Test if \a aPosition is contained within or on the bounding box of an item.
* tests if \a aPosition is contained within or on the bounding box of an item.
* *
* @param aPosition A reference to a wxPoint object containing the coordinates to test. * @param aPosition A reference to a wxPoint object containing the coordinates to test.
* @param aAccuracy Increase the item bounding box by this amount. * @param aAccuracy Increase the item bounding box by this amount.
@ -298,10 +274,9 @@ public:
} }
/** /**
* Function HitTest * Test if \a aRect intersects or is contained within the bounding box of an item.
* tests if \a aRect intersects or is contained within the bounding box of an item.
* *
* @param aRect A reference to a EDA_RECT object containing the rectangle to test. * @param aRect A reference to a #EDA_RECT object containing the rectangle to test.
* @param aContained Set to true to test for containment instead of an intersection. * @param aContained Set to true to test for containment instead of an intersection.
* @param aAccuracy Increase \a aRect by this amount. * @param aAccuracy Increase \a aRect by this amount.
* @return True if \a aRect contains or intersects the item bounding box. * @return True if \a aRect contains or intersects the item bounding box.
@ -312,13 +287,11 @@ public:
} }
/** /**
* Function GetBoundingBox * Return the orthogonal bounding box of this object for display purposes.
* returns the orthogonal, bounding box of this object for display *
* purposes.
* This box should be an enclosing perimeter for visible components of this * This box should be an enclosing perimeter for visible components of this
* object, and the units should be in the pcb or schematic coordinate * object, and the units should be in the pcb or schematic coordinate
* system. * system. It is OK to overestimate the size by a few counts.
* It is OK to overestimate the size by a few counts.
*/ */
virtual const EDA_RECT GetBoundingBox() const; virtual const EDA_RECT GetBoundingBox() const;
@ -326,15 +299,13 @@ public:
virtual void SetPosition( const wxPoint& aPos ) {}; virtual void SetPosition( const wxPoint& aPos ) {};
/** /**
* Function GetFocusPosition * Similar to GetPosition, but allows items to return their visual center rather
* similar to GetPosition, but allows items to return their visual center rather
* than their anchor. * than their anchor.
*/ */
virtual const wxPoint GetFocusPosition() const { return GetPosition(); } virtual const wxPoint GetFocusPosition() const { return GetPosition(); }
/** /**
* Function Clone * Create a duplicate of this item with linked list members set to NULL.
* creates a duplicate of this item with linked list members set to NULL.
* *
* The default version will return NULL in release builds and likely crash the * The default version will return NULL in release builds and likely crash the
* program. In debug builds, a warning message indicating the derived class * program. In debug builds, a warning message indicating the derived class
@ -348,25 +319,23 @@ public:
virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site. virtual EDA_ITEM* Clone() const; // should not be inline, to save the ~ 6 bytes per call site.
/** /**
* Function Visit * May be re-implemented for each derived class in order to handle all the types given
* may be re-implemented for each derived class in order to handle * by its member data.
* all the types given by its member data. Implementations should call *
* inspector->Inspect() on types in scanTypes[], and may use * Implementations should call inspector->Inspect() on types in scanTypes[], and may use
* IterateForward() * #IterateForward() to do so on lists of such data.
* to do so on lists of such data. *
* @param inspector An INSPECTOR instance to use in the inspection. * @param inspector An #INSPECTOR instance to use in the inspection.
* @param testData Arbitrary data used by the inspector. * @param testData Arbitrary data used by the inspector.
* @param scanTypes Which KICAD_T types are of interest and the order * @param scanTypes Which# KICAD_T types are of interest and the order
* is significant too, terminated by EOT. * is significant too, terminated by EOT.
* @return SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan, * @return #SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan,
* else SCAN_CONTINUE, and determined by the inspector. * else #SCAN_CONTINUE, and determined by the inspector.
*/ */
virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ); virtual SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] );
/** /**
* @copydoc SEARCH_RESULT IterateForward( EDA_ITEM*, INSPECTOR, void*, const KICAD_T ) * This changes first parameter to avoid the DList and use the main queue instead.
*
* This changes first parameter to avoid the DList and use the main queue instead
*/ */
template< class T > template< class T >
static SEARCH_RESULT IterateForward( std::deque<T>& aList, static SEARCH_RESULT IterateForward( std::deque<T>& aList,
@ -385,9 +354,7 @@ public:
} }
/** /**
* @copydoc SEARCH_RESULT IterateForward( EDA_ITEM*, INSPECTOR, void*, const KICAD_T ) * Change first parameter to avoid the DList and use std::vector instead.
*
* This changes first parameter to avoid the DList and use std::vector instead
*/ */
template <class T> template <class T>
static SEARCH_RESULT IterateForward( static SEARCH_RESULT IterateForward(
@ -404,43 +371,41 @@ public:
} }
/** /**
* Function GetClass * Return the class name.
* returns the class name.
* @return wxString
*/ */
virtual wxString GetClass() const = 0; virtual wxString GetClass() const = 0;
/** /**
* Function GetSelectMenuText * Return the text to display to be used in the selection clarification context menu
* returns the text to display to be used in the selection clarification context menu * when multiple items are found at the current cursor position.
* when multiple items are found at the current cursor position. The default version *
* of this function raises an assertion in the debug mode and returns a string to * The default version of this function raises an assertion in the debug mode and
* indicate that it was not overridden to provide the object specific text. * returns a string to indicate that it was not overridden to provide the object
* specific text.
* *
* @return The menu text string. * @return The menu text string.
*/ */
virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const; virtual wxString GetSelectMenuText( EDA_UNITS aUnits ) const;
/** /**
* Function GetMenuImage * Return a pointer to an image to be used in menus.
* returns a pointer to an image to be used in menus. The default version returns *
* the right arrow image. Override this function to provide object specific menu * The default version returns the right arrow image. Override this function to provide
* images. * object specific menu images.
*
* @return The menu image associated with the item. * @return The menu image associated with the item.
*/ */
virtual BITMAP_DEF GetMenuImage() const; virtual BITMAP_DEF GetMenuImage() const;
/** /**
* Function Matches * Compare the item against the search criteria in \a aSearchData.
* compares the item against the search criteria in \a aSearchData.
* *
* The base class returns false since many of the objects derived from EDA_ITEM * The base class returns false since many of the objects derived from EDA_ITEM
* do not have any text to search. * do not have any text to search.
* *
* @param aSearchData A reference to a wxFindReplaceData object containing the * @param aSearchData A reference to a wxFindReplaceData object containing the
* search criteria. * search criteria.
* @param aAuxData A pointer to optional data required for the search or NULL * @param aAuxData A pointer to optional data required for the search or NULL if not used.
* if not used.
* @return True if the item's text matches the search criteria in \a aSearchData. * @return True if the item's text matches the search criteria in \a aSearchData.
*/ */
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData ) virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData )
@ -449,40 +414,34 @@ public:
} }
/** /**
* Helper function used in search and replace dialog * Perform a text replace on \a aText using the find and replace criteria in
* Function Replace
* performs a text replace on \a aText using the find and replace criteria in
* \a aSearchData on items that support text find and replace. * \a aSearchData on items that support text find and replace.
* *
* @param aSearchData A reference to a wxFindReplaceData object containing the * @param aSearchData A reference to a wxFindReplaceData object containing the
* search and replace criteria. * search and replace criteria.
* @param aText A reference to a wxString object containing the text to be * @param aText A reference to a wxString object containing the text to be replaced.
* replaced.
* @return True if \a aText was modified, otherwise false. * @return True if \a aText was modified, otherwise false.
*/ */
static bool Replace( wxFindReplaceData& aSearchData, wxString& aText ); static bool Replace( wxFindReplaceData& aSearchData, wxString& aText );
/** /**
* Function Replace * Perform a text replace using the find and replace criteria in \a aSearchData
* performs a text replace using the find and replace criteria in \a aSearchData
* on items that support text find and replace. * on items that support text find and replace.
* *
* This function must be overridden for items that support text replace. * This function must be overridden for items that support text replace.
* *
* @param aSearchData A reference to a wxFindReplaceData object containing the * @param aSearchData A reference to a wxFindReplaceData object containing the search and
* search and replace criteria. * replace criteria.
* @param aAuxData A pointer to optional data required for the search or NULL * @param aAuxData A pointer to optional data required for the search or NULL if not used.
* if not used.
* @return True if the item text was modified, otherwise false. * @return True if the item text was modified, otherwise false.
*/ */
virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) { return false; } virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = nullptr )
{
return false;
}
/** /**
* Function IsReplaceable * Override this method in any derived object that supports test find and replace.
* <p>
* Override this method in any derived object that supports test find and
* replace.
* </p>
* *
* @return True if the item has replaceable text that can be modified using * @return True if the item has replaceable text that can be modified using
* the find and replace dialog. * the find and replace dialog.
@ -498,9 +457,8 @@ public:
bool operator<( const EDA_ITEM& aItem ) const; bool operator<( const EDA_ITEM& aItem ) const;
/** /**
* Function Sort * Helper function to be used by the C++ STL sort algorithm for sorting a STL
* is a helper function to be used by the C++ STL sort algorithm for sorting a STL * container of #EDA_ITEM pointers.
* container of EDA_ITEM pointers.
* *
* @param aLeft The left hand item to compare. * @param aLeft The left hand item to compare.
* @param aRight The right hand item to compare. * @param aRight The right hand item to compare.
@ -509,8 +467,7 @@ public:
static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; } static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
/** /**
* Operator assignment * Assign the members of \a aItem to another object.
* is used to assign the members of \a aItem to another object.
*/ */
EDA_ITEM& operator=( const EDA_ITEM& aItem ); EDA_ITEM& operator=( const EDA_ITEM& aItem );
@ -521,32 +478,37 @@ public:
#if defined(DEBUG) #if defined(DEBUG)
/** /**
* Function Show * Output the object tree, currently for debugging only.
* is used to output the object tree, currently for debugging only. *
* This is pure virtual so compiler warns if somebody mucks up a derived declaration.
*
* @param nestLevel An aid to prettier tree indenting, and is the level * @param nestLevel An aid to prettier tree indenting, and is the level
* of nesting of this object within the overall tree. * of nesting of this object within the overall tree.
* @param os The ostream& to output to. * @param os The ostream& to output to.
*/ */
virtual void Show( int nestLevel, std::ostream& os ) const = 0; virtual void Show( int nestLevel, std::ostream& os ) const = 0;
// pure virtual so compiler warns if somebody mucks up a derived declaration
void ShowDummy( std::ostream& os ) const; ///< call this if you are a lazy developer void ShowDummy( std::ostream& os ) const; ///< call this if you are a lazy developer
/** /**
* Function NestedSpace * Output nested space for pretty indenting.
* outputs nested space for pretty indenting. *
* @param nestLevel The nest count * @param nestLevel The nest count.
* @param os The ostream&, where to output * @param os The ostream&, where to output
* @return std::ostream& - for continuation. * @return The std::ostream& for continuation.
**/ **/
static std::ostream& NestedSpace( int nestLevel, std::ostream& os ); static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
#endif #endif
protected: protected:
EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
EDA_ITEM( KICAD_T idType );
EDA_ITEM( const EDA_ITEM& base );
/** /**
* Function Matches * Compare \a aText against search criteria in \a aSearchData.
* compares \a aText against search criteria in \a aSearchData. *
* This is a helper function for simplify derived class logic. * This is a helper function for simplify derived class logic.
* *
* @param aText A reference to a wxString object containing the string to test. * @param aText A reference to a wxString object containing the string to test.
@ -554,12 +516,27 @@ protected:
* @return True if \a aText matches the search criteria in \a aSearchData. * @return True if \a aText matches the search criteria in \a aSearchData.
*/ */
bool Matches( const wxString& aText, wxFindReplaceData& aSearchData ); bool Matches( const wxString& aText, wxFindReplaceData& aSearchData );
public:
const KIID m_Uuid;
protected:
STATUS_FLAGS m_status;
EDA_ITEM* m_parent; ///< Linked list: Link (parent struct)
bool m_forceVisible;
STATUS_FLAGS m_flags;
private:
/**
* Run time identification, _keep private_ so it can never be changed after a ctor
* sets it. See comment near SetType() regarding virtual functions.
*/
KICAD_T m_structType;
}; };
/** /**
* Function new_clone * Provide cloning capabilities for all Boost pointer containers of #EDA_ITEM pointers.
* provides cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
* *
* @param aItem EDA_ITEM to clone. * @param aItem EDA_ITEM to clone.
* @return Clone of \a aItem. * @return Clone of \a aItem.
@ -575,4 +552,4 @@ inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
*/ */
typedef std::vector< EDA_ITEM* > EDA_ITEMS; typedef std::vector< EDA_ITEM* > EDA_ITEMS;
#endif // EDA_ITEM_H #endif // EDA_ITEM_H

View File

@ -2,8 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2014 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -34,12 +33,11 @@
#include <math/box2.h> #include <math/box2.h>
/** /**
* EDA_RECT * Handle the component boundary box.
* handles the component boundary box. *
* This class is similar to wxRect, but some wxRect functions are very curious, * This class is similar to wxRect, but some wxRect functions are very curious, and are
* and are working only if dimensions are >= 0 (not always the case in KiCad) * working only if dimensions are >= 0 (not always the case in KiCad) and also KiCad needs
* and also KiCad needs some specific method. * some specific method which makes this a more suitable class.
* so I prefer this more suitable class
*/ */
class EDA_RECT class EDA_RECT
{ {
@ -61,50 +59,44 @@ public:
wxPoint Centre() const wxPoint Centre() const
{ {
return wxPoint( m_pos.x + ( m_size.x >> 1 ), return wxPoint( m_pos.x + ( m_size.x >> 1 ), m_pos.y + ( m_size.y >> 1 ) );
m_pos.y + ( m_size.y >> 1 ) );
} }
/** /**
* Function Move * Move the rectangle by the \a aMoveVector.
* moves the rectangle by the \a aMoveVector. *
* @param aMoveVector A wxPoint that is the value to move this rectangle * @param aMoveVector A wxPoint that is the value to move this rectangle.
*/ */
void Move( const wxPoint& aMoveVector ); void Move( const wxPoint& aMoveVector );
/** /**
* Function Normalize * Ensures that the height ant width are positive.
* ensures that the height ant width are positive.
*/ */
void Normalize(); void Normalize();
/** /**
* Function Contains * @param aPoint the wxPoint to test.
* @param aPoint = the wxPoint to test * @return true if aPoint is inside the boundary box. A point on a edge is seen as inside.
* @return true if aPoint is inside the boundary box. A point on a edge is seen as inside
*/ */
bool Contains( const wxPoint& aPoint ) const; bool Contains( const wxPoint& aPoint ) const;
/** /**
* Function Contains * @param x the x coordinate of the point to test.
* @param x = the x coordinate of the point to test * @param y the x coordinate of the point to test.
* @param y = the x coordinate of the point to test
* @return true if point is inside the boundary box. A point on a edge is seen as inside * @return true if point is inside the boundary box. A point on a edge is seen as inside
*/ */
bool Contains( int x, int y ) const { return Contains( wxPoint( x, y ) ); } bool Contains( int x, int y ) const { return Contains( wxPoint( x, y ) ); }
/** /**
* Function Contains * @param aRect the EDA_RECT to test.
* @param aRect = the EDA_RECT to test * @return true if aRect is Contained. A common edge is seen as contained.
* @return true if aRect is Contained. A common edge is seen as contained
*/ */
bool Contains( const EDA_RECT& aRect ) const; bool Contains( const EDA_RECT& aRect ) const;
const wxSize GetSize() const { return m_size; } const wxSize GetSize() const { return m_size; }
/** /**
* @brief GetSizeMax * @return the max size dimension.
* @return the max size dimension
*/ */
int GetSizeMax() const { return ( m_size.x > m_size.y ) ? m_size.x : m_size.y; } int GetSizeMax() const { return ( m_size.x > m_size.y ) ? m_size.x : m_size.y; }
@ -114,7 +106,10 @@ public:
const wxPoint GetOrigin() const { return m_pos; } const wxPoint GetOrigin() const { return m_pos; }
const wxPoint GetPosition() const { return m_pos; } const wxPoint GetPosition() const { return m_pos; }
const wxPoint GetEnd() const { return wxPoint( m_pos.x + m_size.x, m_pos.y + m_size.y ); } const wxPoint GetEnd() const { return wxPoint( m_pos.x + m_size.x, m_pos.y + m_size.y ); }
const wxPoint GetCenter() const { return wxPoint( m_pos.x + ( m_size.x / 2 ), m_pos.y + ( m_size.y / 2 ) ); } const wxPoint GetCenter() const
{
return wxPoint( m_pos.x + ( m_size.x / 2 ), m_pos.y + ( m_size.y / 2 ) );
}
int GetWidth() const { return m_size.x; } int GetWidth() const { return m_size.x; }
int GetHeight() const { return m_size.y; } int GetHeight() const { return m_size.y; }
@ -203,8 +198,7 @@ public:
} }
/** /**
* Function RevertYAxis * Mirror the rectangle from the X axis (negate Y pos and size).
* Mirror the rectangle from the X axis (negate Y pos and size)
*/ */
void RevertYAxis() void RevertYAxis()
{ {
@ -214,42 +208,40 @@ public:
} }
/** /**
* Function Intersects * Test for a common area between rectangles.
* tests for a common area between rectangles.
* *
* @param aRect A rectangle to test intersection with. * @param aRect A rectangle to test intersection with.
* @return bool - true if the argument rectangle intersects this rectangle. * @return true if the argument rectangle intersects this rectangle.
* (i.e. if the 2 rectangles have at least a common point) * (i.e. if the 2 rectangles have at least a common point)
*/ */
bool Intersects( const EDA_RECT& aRect ) const; bool Intersects( const EDA_RECT& aRect ) const;
/** /**
* Tests for a common area between this rectangle, * Tests for a common area between this rectangle, and a rectangle with arbitrary rotation
* and a rectangle with arbitrary rotation
* *
* @param aRect a rectangle to test intersection with * @param aRect a rectangle to test intersection with.
* @param aRot rectangle rotation (in 1/10 degrees) * @param aRot rectangle rotation (in 1/10 degrees).
*/ */
bool Intersects( const EDA_RECT& aRect, double aRot ) const; bool Intersects( const EDA_RECT& aRect, double aRot ) const;
/** /**
* Function Intersects * Test for a common area between a segment and this rectangle.
* tests for a common area between a segment and this rectangle.
* *
* @param aPoint1 First point of the segment to test intersection with. * @param aPoint1 First point of the segment to test intersection with.
* @param aPoint2 Second point of the segment to test intersection with. * @param aPoint2 Second point of the segment to test intersection with.
* @return bool - true if the argument segment intersects this rectangle. * @return true if the argument segment intersects this rectangle.
* (i.e. if the segment and rectangle have at least a common point) * (i.e. if the segment and rectangle have at least a common point)
*/ */
bool Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2 ) const; bool Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2 ) const;
/** /**
* Tests for intersection between a segment and this rectangle, returning the intersections * Test for intersection between a segment and this rectangle, returning the intersections.
* @param aPoint1 is the first point of the segment to test intersection with *
* @param aPoint2 is the second point of the segment to test intersection with * @param aPoint1 is the first point of the segment to test intersection with.
* @param aIntersection1 will be filled with the first intersection point, if any * @param aPoint2 is the second point of the segment to test intersection with.
* @param aIntersection2 will be filled with the second intersection point, if any * @param aIntersection1 will be filled with the first intersection point, if any.
* @return true if the segment intersects the rect * @param aIntersection2 will be filled with the second intersection point, if any.
* @return true if the segment intersects the rect.
*/ */
bool Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2, bool Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2,
wxPoint* aIntersection1, wxPoint* aIntersection2 ) const; wxPoint* aIntersection1, wxPoint* aIntersection2 ) const;
@ -265,29 +257,26 @@ public:
const wxPoint FarthestPointTo( const wxPoint& aPoint ) const; const wxPoint FarthestPointTo( const wxPoint& aPoint ) const;
/** /**
* Function IntersectsCircle * Test for a common area between a circle and this rectangle.
* tests for a common area between a circle and this rectangle
* *
* @param aCenter center of the circle * @param aCenter center of the circle.
* @param aRadius radius of the circle * @param aRadius radius of the circle.
*/ */
bool IntersectsCircle( const wxPoint& aCenter, const int aRadius ) const; bool IntersectsCircle( const wxPoint& aCenter, const int aRadius ) const;
/** /**
* IntersectsCircleEdge * Test for intersection between this rect and the edge (radius) of a circle.
* Tests for intersection between this rect and the edge (radius) of a circle
* *
* @param aCenter center of the circle * @param aCenter center of the circle.
* @param aRadius radius of the circle * @param aRadius radius of the circle.
* @param aWidth width of the circle edge * @param aWidth width of the circle edge.
*/ */
bool IntersectsCircleEdge( const wxPoint& aCenter, const int aRadius, const int aWidth ) const; bool IntersectsCircleEdge( const wxPoint& aCenter, const int aRadius, const int aWidth ) const;
/** /**
* Function operator(wxRect) * Overload the cast operator to return a wxRect.
* overloads the cast operator to return a wxRect *
* wxRect does not accept negative values for size, so ensure the * wxRect does not accept negative values for size, so ensure the wxRect size is always >= 0.
* wxRect size is always >= 0
*/ */
operator wxRect() const operator wxRect() const
{ {
@ -297,9 +286,9 @@ public:
} }
/** /**
* Function operator(BOX2I) * Overload the cast operator to return a BOX2I.
* overloads the cast operator to return a BOX2I *
* @return BOX2I - this box shaped as a BOX2I object. * @return this box shaped as a BOX2I object.
*/ */
operator BOX2I() const operator BOX2I() const
{ {
@ -309,56 +298,54 @@ public:
} }
/** /**
* Function Inflate * Inflate the rectangle horizontally by \a dx and vertically by \a dy. If \a dx
* inflates the rectangle horizontally by \a dx and vertically by \a dy. If \a dx
* and/or \a dy is negative the rectangle is deflated. * and/or \a dy is negative the rectangle is deflated.
*/ */
EDA_RECT& Inflate( wxCoord dx, wxCoord dy ); EDA_RECT& Inflate( wxCoord dx, wxCoord dy );
/** /**
* Function Inflate * Inflate the rectangle horizontally and vertically by \a aDelta. If \a aDelta
* inflates the rectangle horizontally and vertically by \a aDelta. If \a aDelta
* is negative the rectangle is deflated. * is negative the rectangle is deflated.
*/ */
EDA_RECT& Inflate( int aDelta ); EDA_RECT& Inflate( int aDelta );
/** /**
* Function Merge * Modify the position and size of the rectangle in order to contain \a aRect.
* modifies the position and size of the rectangle in order to contain \a aRect. It is *
* mainly used to calculate bounding boxes. * It is mainly used to calculate bounding boxes.
*
* @param aRect The rectangle to merge with this rectangle. * @param aRect The rectangle to merge with this rectangle.
*/ */
void Merge( const EDA_RECT& aRect ); void Merge( const EDA_RECT& aRect );
/** /**
* Function Merge * Modify the position and size of the rectangle in order to contain the given point.
* modifies the position and size of the rectangle in order to contain the given point. *
* @param aPoint The point to merge with the rectangle. * @param aPoint The point to merge with the rectangle.
*/ */
void Merge( const wxPoint& aPoint ); void Merge( const wxPoint& aPoint );
/** /**
* Function GetArea * Return the area of the rectangle.
* returns the area of the rectangle. *
* @return The area of the rectangle. * @return The area of the rectangle.
*/ */
double GetArea() const; double GetArea() const;
/** /**
* Function Common * Return the area that is common with another rectangle.
* returns the area that is common with another rectangle. *
* @param aRect is the rectangle to find the common area with. * @param aRect is the rectangle to find the common area with.
* @return The common area rect or 0-sized rectangle if there is no intersection. * @return The common area rect or 0-sized rectangle if there is no intersection.
*/ */
EDA_RECT Common( const EDA_RECT& aRect ) const; EDA_RECT Common( const EDA_RECT& aRect ) const;
/** /**
* Function GetBoundingBoxRotated * Useful to calculate bounding box of rotated items, when rotation if not k*90 degrees.
* @return the bounding box of this, after rotation *
* @param aAngle = the rotation angle in 0.1 deg. * @return the bounding box of this, after rotation.
* @param aRotCenter = the rotation point. * @param aAngle the rotation angle in 0.1 deg.
* useful to calculate bounding box of rotated items, when * @param aRotCenter the rotation point.
* rotation if not k*90 degrees
*/ */
const EDA_RECT GetBoundingBoxRotated( wxPoint aRotCenter, double aAngle ) const; const EDA_RECT GetBoundingBoxRotated( wxPoint aRotCenter, double aAngle ) const;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 Jean-Pierre Charras, jpe.charras at wanadoo.fr * Copyright (C) 2013 Jean-Pierre Charras, jpe.charras at wanadoo.fr
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -111,10 +111,10 @@ struct TEXT_EFFECTS
/** /**
* A mix-in class (via multiple inheritance) that handles texts such as * A mix-in class (via multiple inheritance) that handles texts such as labels, parts,
* labels, parts, components, or footprints. Because it's a mix-in class, care * components, or footprints. Because it's a mix-in class, care is used to provide
* is used to provide function names (accessors) that to not collide with function * function names (accessors) that to not collide with function names likely to be seen
* names likely to be seen in the combined derived classes. * in the combined derived classes.
*/ */
class EDA_TEXT class EDA_TEXT
{ {
@ -134,7 +134,8 @@ public:
/** /**
* Return the string actually shown after processing of the base text. * Return the string actually shown after processing of the base text.
* @aParam aDepth is used to prevent infinite recusions and loops when expanding *
* @param aDepth is used to prevent infinite recursions and loops when expanding
* text variables. * text variables.
*/ */
virtual wxString GetShownText( int aDepth = 0 ) const { return m_shown_text; } virtual wxString GetShownText( int aDepth = 0 ) const { return m_shown_text; }
@ -142,6 +143,7 @@ public:
/** /**
* A version of GetShownText() which also indicates whether or not the text needs * A version of GetShownText() which also indicates whether or not the text needs
* to be processed for text variables. * to be processed for text variables.
*
* @param processTextVars [out] * @param processTextVars [out]
*/ */
wxString GetShownText( bool* processTextVars ) const wxString GetShownText( bool* processTextVars ) const
@ -165,8 +167,7 @@ public:
int GetTextThickness() const { return m_e.penwidth; }; int GetTextThickness() const { return m_e.penwidth; };
/** /**
* The EffectiveTextPenWidth uses the text thickness if > 1 or * The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
* aDefaultWidth.
*/ */
int GetEffectiveTextPenWidth( int aDefaultWidth = 0 ) const; int GetEffectiveTextPenWidth( int aDefaultWidth = 0 ) const;
@ -195,9 +196,8 @@ public:
bool IsMirrored() const { return m_e.Bit( TE_MIRROR ); } bool IsMirrored() const { return m_e.Bit( TE_MIRROR ); }
/** /**
* @param aAllow true if ok to use multiline option, false * @param aAllow true if ok to use multiline option, false if ok to use only single line
* if ok to use only single line text. (Single line is faster in * text. (Single line is faster in calculations than multiline.)
* calculations than multiline.)
*/ */
void SetMultilineAllowed( bool aAllow ) { m_e.Bit( TE_MULTILINE, aAllow ); } void SetMultilineAllowed( bool aAllow ) { m_e.Bit( TE_MULTILINE, aAllow ); }
bool IsMultilineAllowed() const { return m_e.Bit( TE_MULTILINE ); } bool IsMultilineAllowed() const { return m_e.Bit( TE_MULTILINE ); }
@ -211,7 +211,7 @@ public:
/** /**
* Set the text effects from another instance. * Set the text effects from another instance.
* *
* TEXT_EFFECTS is not exposed in the public API, but includes everything except the actual * #TEXT_EFFECTS is not exposed in the public API, but includes everything except the actual
* text string itself. * text string itself.
*/ */
void SetEffects( const EDA_TEXT& aSrc ); void SetEffects( const EDA_TEXT& aSrc );
@ -219,7 +219,7 @@ public:
/** /**
* Swap the text effects of the two involved instances. * Swap the text effects of the two involved instances.
* *
* TEXT_EFFECTS is not exposed in the public API, but includes everything except the actual * #TEXT_EFFECTS is not exposed in the public API, but includes everything except the actual
* text string itself. * text string itself.
*/ */
void SwapEffects( EDA_TEXT& aTradingPartner ); void SwapEffects( EDA_TEXT& aTradingPartner );
@ -267,10 +267,10 @@ public:
/** /**
* Print this text object to the device context \a aDC. * Print this text object to the device context \a aDC.
* *
* @param aDC = the current Device Context * @param aDC the current Device Context.
* @param aOffset = draw offset (usually (0,0)) * @param aOffset draw offset (usually (0,0)).
* @param aColor = text color * @param aColor text color.
* @param aDisplay_mode = FILLED or SKETCH * @param aDisplay_mode #FILLED or #SKETCH.
*/ */
void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, COLOR4D aColor, void Print( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, COLOR4D aColor,
OUTLINE_MODE aDisplay_mode = FILLED ); OUTLINE_MODE aDisplay_mode = FILLED );
@ -290,9 +290,9 @@ public:
* Used in filling zones calculations * Used in filling zones calculations
* Circles and arcs are approximated by segments * Circles and arcs are approximated by segments
* *
* @param aCornerBuffer = a buffer to store the polygon * @param aCornerBuffer a buffer to store the polygon.
* @param aClearanceValue = the clearance around the text bounding box * @param aClearanceValue the clearance around the text bounding box
* to the real clearance value (usually near from 1.0) * to the real clearance value (usually near from 1.0).
*/ */
void TransformBoundingBoxWithClearanceToPolygon( SHAPE_POLY_SET* aCornerBuffer, void TransformBoundingBoxWithClearanceToPolygon( SHAPE_POLY_SET* aCornerBuffer,
int aClearanceValue ) const; int aClearanceValue ) const;
@ -302,33 +302,34 @@ public:
/** /**
* Test if \a aPoint is within the bounds of this object. * Test if \a aPoint is within the bounds of this object.
* *
* @param aPoint- A wxPoint to test * @param aPoint A wxPoint to test.
* @param aAccuracy - Amount to inflate the bounding box. * @param aAccuracy Amount to inflate the bounding box.
* @return bool - true if a hit, else false * @return true if a hit, else false.
*/ */
virtual bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const; virtual bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const;
/** /**
* Test if object bounding box is contained within or intersects \a aRect. * Test if object bounding box is contained within or intersects \a aRect.
* *
* @param aRect - Rect to test against. * @param aRect Rect to test against.
* @param aContains - Test for containment instead of intersection if true. * @param aContains Test for containment instead of intersection if true.
* @param aAccuracy - Amount to inflate the bounding box. * @param aAccuracy Amount to inflate the bounding box.
* @return bool - true if a hit, else false * @return true if a hit, else false.
*/ */
virtual bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const; virtual bool TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy = 0 ) const;
/** /**
* @return the text length in internal units * @return the text length in internal units.
* @param aLine : the line of text to consider. * @param aLine the line of text to consider. For single line text, this parameter
* For single line text, this parameter is always m_Text * is always m_Text.
* @param aThickness : the stroke width of the text * @param aThickness the stroke width of the text.
*/ */
int LenSize( const wxString& aLine, int aThickness ) const; int LenSize( const wxString& aLine, int aThickness ) const;
/** /**
* Useful in multiline texts to calculate the full text or a line area (for zones filling, * Useful in multiline texts to calculate the full text or a line area (for zones filling,
* locate functions....) * locate functions....)
*
* @param aLine The line of text to consider. Pass -1 for all lines. * @param aLine The line of text to consider. Pass -1 for all lines.
* @param aInvertY Invert the Y axis when calculating bounding box. * @param aInvertY Invert the Y axis when calculating bounding box.
* @return the rect containing the line of text (i.e. the position and the size of one line) * @return the rect containing the line of text (i.e. the position and the size of one line)
@ -347,20 +348,19 @@ public:
int GetInterline() const; int GetInterline() const;
/** /**
* @return a wxString with the style name( Normal, Italic, Bold, Bold+Italic) * @return a wxString with the style name( Normal, Italic, Bold, Bold+Italic).
*/ */
wxString GetTextStyleName() const; wxString GetTextStyleName() const;
/** /**
* Populate \a aPositions with the position of each line of * Populate \a aPositions with the position of each line of a multiline text, according
* a multiline text, according to the vertical justification and the * to the vertical justification and the rotation of the whole text.
* rotation of the whole text
* *
* @param aPositions is the list to populate by the wxPoint positions * @param aPositions is the list to populate by the wxPoint positions.
* @param aLineCount is the number of lines (not recalculated here * @param aLineCount is the number of lines (not recalculated here for efficiency reasons.
* for efficiency reasons
*/ */
void GetLinePositions( std::vector<wxPoint>& aPositions, int aLineCount ) const; void GetLinePositions( std::vector<wxPoint>& aPositions, int aLineCount ) const;
/** /**
* Output the object to \a aFormatter in s-expression form. * Output the object to \a aFormatter in s-expression form.
* *
@ -374,6 +374,18 @@ public:
virtual double GetDrawRotation() const; virtual double GetDrawRotation() const;
private: private:
/**
* Print each line of this EDA_TEXT..
*
* @param aOffset draw offset (usually (0,0)).
* @param aColor text color.
* @param aFillMode FILLED or SKETCH
* @param aText the single line of text to draw.
* @param aPos the position of this line ).
*/
void printOneLineOfText( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, COLOR4D aColor,
OUTLINE_MODE aFillMode, const wxString& aText, const wxPoint& aPos );
wxString m_text; wxString m_text;
wxString m_shown_text; // Cache of unescaped text for efficient access wxString m_shown_text; // Cache of unescaped text for efficient access
bool m_shown_text_has_text_var_refs; bool m_shown_text_has_text_var_refs;
@ -387,20 +399,6 @@ private:
TE_MULTILINE, TE_MULTILINE,
TE_VISIBLE, TE_VISIBLE,
}; };
private:
/**
* Print each line of this EDA_TEXT.
*
* @param aOffset = draw offset (usually (0,0))
* @param aColor = text color
* @param aFillMode = FILLED or SKETCH
* @param aText = the single line of text to draw.
* @param aPos = the position of this line ).
*/
void printOneLineOfText( RENDER_SETTINGS* aSettings, const wxPoint& aOffset, COLOR4D aColor,
OUTLINE_MODE aFillMode, const wxString& aText,
const wxPoint& aPos );
}; };