Pass objects by reference instead of on the stack part 2.

This commit is contained in:
Wayne Stambaugh 2021-06-08 13:47:06 -04:00
parent ed0e0a00c0
commit e6346e3103
16 changed files with 163 additions and 175 deletions

View File

@ -62,7 +62,6 @@
using KIGFX::COLOR4D; using KIGFX::COLOR4D;
// The constructor:
DS_DATA_ITEM::DS_DATA_ITEM( DS_ITEM_TYPE aType ) DS_DATA_ITEM::DS_DATA_ITEM( DS_ITEM_TYPE aType )
{ {
m_pageOption = ALL_PAGES; m_pageOption = ALL_PAGES;
@ -144,13 +143,7 @@ int DS_DATA_ITEM::GetPenSizeUi()
} }
// move item to aPosition void DS_DATA_ITEM::MoveToUi( const wxPoint& aPosition )
// starting point is moved to aPosition
// the Ending point is moved to a position which keeps the item size
// (if both coordinates have the same corner reference)
// MoveToUi and MoveTo takes the graphic position (i.e relative to the left top
// paper corner
void DS_DATA_ITEM::MoveToUi( wxPoint aPosition )
{ {
DPOINT pos_mm; DPOINT pos_mm;
pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu; pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;
@ -160,7 +153,7 @@ void DS_DATA_ITEM::MoveToUi( wxPoint aPosition )
} }
void DS_DATA_ITEM::MoveTo( DPOINT aPosition ) void DS_DATA_ITEM::MoveTo( const DPOINT& aPosition )
{ {
DPOINT vector = aPosition - GetStartPos(); DPOINT vector = aPosition - GetStartPos();
DPOINT endpos = vector + GetEndPos(); DPOINT endpos = vector + GetEndPos();
@ -176,10 +169,7 @@ void DS_DATA_ITEM::MoveTo( DPOINT aPosition )
} }
/* move the starting point of the item to a new position void DS_DATA_ITEM::MoveStartPointTo( const DPOINT& aPosition )
* aPosition = the new position of the starting point, in mm
*/
void DS_DATA_ITEM::MoveStartPointTo( DPOINT aPosition )
{ {
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance(); DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
DPOINT position; DPOINT position;
@ -212,10 +202,7 @@ void DS_DATA_ITEM::MoveStartPointTo( DPOINT aPosition )
} }
/* move the starting point of the item to a new position void DS_DATA_ITEM::MoveStartPointToUi( const wxPoint& aPosition )
* aPosition = the new position of the starting point in graphic units
*/
void DS_DATA_ITEM::MoveStartPointToUi( wxPoint aPosition )
{ {
DPOINT pos_mm( aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu, DPOINT pos_mm( aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu,
aPosition.y / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu ); aPosition.y / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu );
@ -224,13 +211,7 @@ void DS_DATA_ITEM::MoveStartPointToUi( wxPoint aPosition )
} }
/** void DS_DATA_ITEM::MoveEndPointTo( const DPOINT& aPosition )
* move the ending point of the item to a new position
* has meaning only for items defined by 2 points
* (segments and rectangles)
* aPosition = the new position of the ending point, in mm
*/
void DS_DATA_ITEM::MoveEndPointTo( DPOINT aPosition )
{ {
DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance(); DS_DATA_MODEL& model = DS_DATA_MODEL::GetTheInstance();
DPOINT position; DPOINT position;
@ -273,12 +254,7 @@ void DS_DATA_ITEM::MoveEndPointTo( DPOINT aPosition )
} }
/* move the ending point of the item to a new position void DS_DATA_ITEM::MoveEndPointToUi( const wxPoint& aPosition )
* has meaning only for items defined by 2 points
* (segments and rectangles)
* aPosition = the new position of the ending point in graphic units
*/
void DS_DATA_ITEM::MoveEndPointToUi( wxPoint aPosition )
{ {
DPOINT pos_mm; DPOINT pos_mm;
pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu; pos_mm.x = aPosition.x / DS_DATA_MODEL::GetTheInstance().m_WSunits2Iu;

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-2016 CERN * Copyright (C) 2013-2016 CERN
* Copyright (C) 2019 Kicad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
* *
* @author Jean-Pierre Charras, jp.charras at wanadoo.fr * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
* *
@ -51,34 +51,32 @@ static const char* getTokenName( T aTok )
// Therefore the constructor is protected. // Therefore the constructor is protected.
class DS_DATA_MODEL_IO class DS_DATA_MODEL_IO
{ {
protected:
OUTPUTFORMATTER* m_out;
DS_DATA_MODEL_IO() { m_out = NULL; }
virtual ~DS_DATA_MODEL_IO() {}
public: public:
void Format( DS_DATA_MODEL* aDrawingSheet ) const; void Format( DS_DATA_MODEL* aDrawingSheet ) const;
void Format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const; void Format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const;
protected:
DS_DATA_MODEL_IO() { m_out = NULL; }
virtual ~DS_DATA_MODEL_IO() {}
private: private:
void format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const; void format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const;
void format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const; void format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const;
void format( DS_DATA_ITEM_POLYGONS* aItem, int aNestLevel ) void format( DS_DATA_ITEM_POLYGONS* aItem, int aNestLevel ) const;
const;
void format( DS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) const; void format( DS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) const;
void formatCoordinate( const char* aToken, POINT_COORD& aCoord ) const; void formatCoordinate( const char* aToken, POINT_COORD& aCoord ) const;
void formatRepeatParameters( DS_DATA_ITEM* aItem ) const; void formatRepeatParameters( DS_DATA_ITEM* aItem ) const;
void formatOptions( DS_DATA_ITEM* aItem ) const; void formatOptions( DS_DATA_ITEM* aItem ) const;
protected:
OUTPUTFORMATTER* m_out;
}; };
// A helper class to write a drawing sheet to a file // A helper class to write a drawing sheet to a file
class DS_DATA_MODEL_FILEIO : public DS_DATA_MODEL_IO class DS_DATA_MODEL_FILEIO : public DS_DATA_MODEL_IO
{ {
FILE_OUTPUTFORMATTER * m_fileout;
public: public:
DS_DATA_MODEL_FILEIO( const wxString& aFilename ) : DS_DATA_MODEL_FILEIO( const wxString& aFilename ) :
DS_DATA_MODEL_IO() DS_DATA_MODEL_IO()
@ -98,18 +96,19 @@ public:
{ {
delete m_fileout; delete m_fileout;
} }
private:
FILE_OUTPUTFORMATTER* m_fileout;
}; };
// A helper class to write a drawing sheet to a string // A helper class to write a drawing sheet to a string
class DS_DATA_MODEL_STRINGIO : public DS_DATA_MODEL_IO class DS_DATA_MODEL_STRINGIO : public DS_DATA_MODEL_IO
{ {
STRING_FORMATTER * m_writer;
wxString & m_output;
public: public:
DS_DATA_MODEL_STRINGIO( wxString& aOutputString ) : DS_DATA_MODEL_STRINGIO( const wxString& aOutputString ) :
DS_DATA_MODEL_IO(), m_output( aOutputString ) DS_DATA_MODEL_IO(),
m_output( aOutputString )
{ {
try try
{ {
@ -127,12 +126,13 @@ public:
m_output = FROM_UTF8( m_writer->GetString().c_str() ); m_output = FROM_UTF8( m_writer->GetString().c_str() );
delete m_writer; delete m_writer;
} }
private:
STRING_FORMATTER* m_writer;
wxString m_output;
}; };
/*
* Save the description in a file
*/
void DS_DATA_MODEL::Save( const wxString& aFullFileName ) void DS_DATA_MODEL::Save( const wxString& aFullFileName )
{ {
DS_DATA_MODEL_FILEIO writer( aFullFileName ); DS_DATA_MODEL_FILEIO writer( aFullFileName );
@ -140,16 +140,15 @@ void DS_DATA_MODEL::Save( const wxString& aFullFileName )
} }
/* Save the description in a buffer void DS_DATA_MODEL::SaveInString( const wxString& aOutputString )
*/
void DS_DATA_MODEL::SaveInString( wxString& aOutputString )
{ {
DS_DATA_MODEL_STRINGIO writer( aOutputString ); DS_DATA_MODEL_STRINGIO writer( aOutputString );
writer.Format( this ); writer.Format( this );
} }
void DS_DATA_MODEL::SaveInString( std::vector<DS_DATA_ITEM*> aItemsList, wxString& aOutputString ) void DS_DATA_MODEL::SaveInString( std::vector<DS_DATA_ITEM*>& aItemsList,
const wxString& aOutputString )
{ {
DS_DATA_MODEL_STRINGIO writer( aOutputString ); DS_DATA_MODEL_STRINGIO writer( aOutputString );
@ -311,6 +310,7 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_TEXT* aItem, int aNestLevel ) const
m_out->Print( 0, ")\n" ); m_out->Print( 0, ")\n" );
} }
void DS_DATA_MODEL_IO::format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const void DS_DATA_MODEL_IO::format( DS_DATA_MODEL* aModel, DS_DATA_ITEM* aItem, int aNestLevel ) const
{ {
if( aItem->GetType() == DS_DATA_ITEM::DS_RECT ) if( aItem->GetType() == DS_DATA_ITEM::DS_RECT )
@ -421,8 +421,7 @@ void DS_DATA_MODEL_IO::format( DS_DATA_ITEM_BITMAP* aItem, int aNestLevel ) cons
} }
void DS_DATA_MODEL_IO::formatCoordinate( const char * aToken, void DS_DATA_MODEL_IO::formatCoordinate( const char * aToken, POINT_COORD & aCoord ) const
POINT_COORD & aCoord ) const
{ {
m_out->Print( 0, " (%s %s %s", aToken, m_out->Print( 0, " (%s %s %s", aToken,
double2Str( aCoord.m_Pos.x ).c_str(), double2Str( aCoord.m_Pos.x ).c_str(),

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 (C) 2020 CERN * Copyright (C) 2020 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Jon Evans <jon@craftyjon.com> * @author Jon Evans <jon@craftyjon.com>
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
@ -26,9 +27,12 @@
#include <kicad_string.h> #include <kicad_string.h>
#include <convert_to_biu.h> #include <convert_to_biu.h>
const int netSettingsSchemaVersion = 0; const int netSettingsSchemaVersion = 0;
static OPT<int> getInPcbUnits( const nlohmann::json& aObj, const std::string& aKey, OPT<int> aDefault = OPT<int>() )
static OPT<int> getInPcbUnits( const nlohmann::json& aObj, const std::string& aKey,
OPT<int> aDefault = OPT<int>() )
{ {
if( aObj.contains( aKey ) && aObj[aKey].is_number() ) if( aObj.contains( aKey ) && aObj[aKey].is_number() )
return PcbMillimeter2iu( aObj[aKey].get<double>() ); return PcbMillimeter2iu( aObj[aKey].get<double>() );
@ -36,6 +40,7 @@ static OPT<int> getInPcbUnits( const nlohmann::json& aObj, const std::string& aK
return aDefault; return aDefault;
}; };
NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath ), NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath ),
m_NetClasses() m_NetClasses()
@ -69,31 +74,40 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
if( netclass->HasClearance() ) if( netclass->HasClearance() )
netclassJson.push_back( { "clearance", PcbIu2Millimeter( netclass->GetClearance() ) } ); netclassJson.push_back( { "clearance",
PcbIu2Millimeter( netclass->GetClearance() ) } );
if( netclass->HasTrackWidth() ) if( netclass->HasTrackWidth() )
netclassJson.push_back( { "track_width", PcbIu2Millimeter( netclass->GetTrackWidth() ) } ); netclassJson.push_back( { "track_width",
PcbIu2Millimeter( netclass->GetTrackWidth() ) } );
if( netclass->HasViaDiameter() ) if( netclass->HasViaDiameter() )
netclassJson.push_back( { "via_diameter", PcbIu2Millimeter( netclass->GetViaDiameter() ) } ); netclassJson.push_back( { "via_diameter",
PcbIu2Millimeter( netclass->GetViaDiameter() ) } );
if( netclass->HasViaDrill() ) if( netclass->HasViaDrill() )
netclassJson.push_back( { "via_drill", PcbIu2Millimeter( netclass->GetViaDrill() ) } ); netclassJson.push_back( { "via_drill",
PcbIu2Millimeter( netclass->GetViaDrill() ) } );
if( netclass->HasuViaDiameter() ) if( netclass->HasuViaDiameter() )
netclassJson.push_back( { "microvia_diameter", PcbIu2Millimeter( netclass->GetuViaDiameter() ) } ); netclassJson.push_back( { "microvia_diameter",
PcbIu2Millimeter( netclass->GetuViaDiameter() ) } );
if( netclass->HasuViaDrill() ) if( netclass->HasuViaDrill() )
netclassJson.push_back( { "microvia_drill", PcbIu2Millimeter( netclass->GetuViaDrill() ) } ); netclassJson.push_back( { "microvia_drill",
PcbIu2Millimeter( netclass->GetuViaDrill() ) } );
if( netclass->HasDiffPairWidth() ) if( netclass->HasDiffPairWidth() )
netclassJson.push_back( { "diff_pair_width", PcbIu2Millimeter( netclass->GetDiffPairWidth() ) } ); netclassJson.push_back( { "diff_pair_width",
PcbIu2Millimeter( netclass->GetDiffPairWidth() ) } );
if( netclass->HasDiffPairGap() ) if( netclass->HasDiffPairGap() )
netclassJson.push_back( { "diff_pair_gap", PcbIu2Millimeter( netclass->GetDiffPairGap() ) } ); netclassJson.push_back( { "diff_pair_gap",
PcbIu2Millimeter( netclass->GetDiffPairGap() ) } );
if( netclass->HasDiffPairViaGap() ) if( netclass->HasDiffPairViaGap() )
netclassJson.push_back( { "diff_pair_via_gap", PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) } ); netclassJson.push_back( { "diff_pair_via_gap",
PcbIu2Millimeter( netclass->GetDiffPairViaGap() ) } );
if( idx > 0 ) // No need to store members of Default netclass if( idx > 0 ) // No need to store members of Default netclass
{ {
@ -188,8 +202,10 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
if( entry.contains( "pcb_color" ) && entry["pcb_color"].is_string() ) if( entry.contains( "pcb_color" ) && entry["pcb_color"].is_string() )
netclass->SetPcbColor( entry["pcb_color"].get<KIGFX::COLOR4D>() ); netclass->SetPcbColor( entry["pcb_color"].get<KIGFX::COLOR4D>() );
if( entry.contains( "schematic_color" ) && entry["schematic_color"].is_string() ) if( entry.contains( "schematic_color" )
netclass->SetSchematicColor( entry["schematic_color"].get<KIGFX::COLOR4D>() ); && entry["schematic_color"].is_string() )
netclass->SetSchematicColor(
entry["schematic_color"].get<KIGFX::COLOR4D>() );
if( netclass != defaultClass ) if( netclass != defaultClass )
m_NetClasses.Add( netclass ); m_NetClasses.Add( netclass );
@ -397,7 +413,7 @@ bool NET_SETTINGS::ParseBusVector( const wxString& aBus, wxString* aName,
} }
bool NET_SETTINGS::ParseBusGroup( wxString aGroup, wxString* aName, bool NET_SETTINGS::ParseBusGroup( const wxString& aGroup, wxString* aName,
std::vector<wxString>* aMemberList ) std::vector<wxString>* aMemberList )
{ {
size_t groupLen = aGroup.length(); size_t groupLen = aGroup.length();

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 (C) 2020 CERN * Copyright (C) 2020 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Jon Evans <jon@craftyjon.com> * @author Jon Evans <jon@craftyjon.com>
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
@ -30,8 +31,8 @@ PROJECT_LOCAL_SETTINGS::PROJECT_LOCAL_SETTINGS( PROJECT* aProject, const wxStrin
JSON_SETTINGS( aFilename, SETTINGS_LOC::PROJECT, projectLocalSettingsVersion, JSON_SETTINGS( aFilename, SETTINGS_LOC::PROJECT, projectLocalSettingsVersion,
/* aCreateIfMissing = */ true, /* aCreateIfDefault = */ false, /* aCreateIfMissing = */ true, /* aCreateIfDefault = */ false,
/* aWriteFile = */ true ), /* aWriteFile = */ true ),
m_project( aProject ), m_SelectionFilter(),
m_SelectionFilter() m_project( aProject )
{ {
m_params.emplace_back( new PARAM_LAMBDA<std::string>( "board.visible_layers", m_params.emplace_back( new PARAM_LAMBDA<std::string>( "board.visible_layers",
[&]() -> std::string [&]() -> std::string

View File

@ -88,19 +88,6 @@ private:
aCount = m_layers.size(); aCount = m_layers.size();
} }
VIEW* m_view; ///< Current dynamic view the item is assigned to.
int m_flags; ///< Visibility flags
int m_requiredUpdate; ///< Flag required for updating
int m_drawPriority; ///< Order to draw this item in a layer, lowest first
///< Helper for storing cached items group ids
typedef std::pair<int, int> GroupPair;
///< Indexes of cached GAL display lists corresponding to the item (for every layer it.
///< occupies)(in the std::pair "first" stores layer number, "second" stores group id).
GroupPair* m_groups;
int m_groupsSize;
/** /**
* Return number of the group id for the given layer, or -1 in case it was not cached before. * Return number of the group id for the given layer, or -1 in case it was not cached before.
* *
@ -196,10 +183,6 @@ private:
} }
} }
/// Stores layer numbers used by the item.
std::vector<int> m_layers;
/** /**
* Save layers used by the item. * Save layers used by the item.
* *
@ -242,6 +225,23 @@ private:
{ {
return m_flags == VISIBLE; return m_flags == VISIBLE;
} }
VIEW* m_view; ///< Current dynamic view the item is assigned to.
int m_flags; ///< Visibility flags
int m_requiredUpdate; ///< Flag required for updating
int m_drawPriority; ///< Order to draw this item in a layer, lowest first
///< Helper for storing cached items group ids
typedef std::pair<int, int> GroupPair;
///< Indexes of cached GAL display lists corresponding to the item (for every layer it.
///< occupies)(in the std::pair "first" stores layer number, "second" stores group id).
GroupPair* m_groups;
int m_groupsSize;
/// Stores layer numbers used by the item.
std::vector<int> m_layers;
}; };
@ -602,8 +602,9 @@ void VIEW::SetCenter( const VECTOR2D& aCenter )
} }
void VIEW::SetCenter( VECTOR2D aCenter, const BOX2D& occultingScreenRect ) void VIEW::SetCenter( const VECTOR2D& aCenter, const BOX2D& occultingScreenRect )
{ {
VECTOR2D center( aCenter );
BOX2D screenRect( VECTOR2D( 0, 0 ), m_gal->GetScreenPixelSize() ); BOX2D screenRect( VECTOR2D( 0, 0 ), m_gal->GetScreenPixelSize() );
if( !screenRect.Intersects( occultingScreenRect ) ) if( !screenRect.Intersects( occultingScreenRect ) )
@ -621,19 +622,19 @@ void VIEW::SetCenter( VECTOR2D aCenter, const BOX2D& occultingScreenRect )
if( std::max( topExposed, bottomExposed ) > std::max( leftExposed, rightExposed ) ) if( std::max( topExposed, bottomExposed ) > std::max( leftExposed, rightExposed ) )
{ {
if( topExposed > bottomExposed ) if( topExposed > bottomExposed )
aCenter.y += ToWorld( screenRect.GetHeight() / 2 - topExposed / 2 ); center.y += ToWorld( screenRect.GetHeight() / 2 - topExposed / 2 );
else else
aCenter.y -= ToWorld( screenRect.GetHeight() / 2 - bottomExposed / 2 ); center.y -= ToWorld( screenRect.GetHeight() / 2 - bottomExposed / 2 );
} }
else else
{ {
if( leftExposed > rightExposed ) if( leftExposed > rightExposed )
aCenter.x += ToWorld( screenRect.GetWidth() / 2 - leftExposed / 2 ); center.x += ToWorld( screenRect.GetWidth() / 2 - leftExposed / 2 );
else else
aCenter.x -= ToWorld( screenRect.GetWidth() / 2 - rightExposed / 2 ); center.x -= ToWorld( screenRect.GetWidth() / 2 - rightExposed / 2 );
} }
SetCenter( aCenter ); SetCenter( center );
} }

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 (C) 2013-2017 CERN * Copyright (C) 2013-2017 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.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>
* *
@ -372,7 +373,7 @@ void VIEW_OVERLAY::SetIsFill( bool aIsFillEnabled )
} }
void VIEW_OVERLAY::SetGlyphSize( const VECTOR2D aSize ) void VIEW_OVERLAY::SetGlyphSize( const VECTOR2D& aSize )
{ {
m_commands.push_back( new COMMAND_GLYPH_SIZE( aSize ) ); m_commands.push_back( new COMMAND_GLYPH_SIZE( aSize ) );
} }

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-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2021 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
@ -71,7 +71,7 @@ class POINT_COORD
public: public:
POINT_COORD() { m_Anchor = RB_CORNER; } POINT_COORD() { m_Anchor = RB_CORNER; }
POINT_COORD( DPOINT aPos, enum CORNER_ANCHOR aAnchor = RB_CORNER ) POINT_COORD( const DPOINT& aPos, enum CORNER_ANCHOR aAnchor = RB_CORNER )
{ {
m_Pos = aPos; m_Pos = aPos;
m_Anchor = aAnchor; m_Anchor = aAnchor;
@ -103,7 +103,6 @@ public:
DS_BITMAP DS_BITMAP
}; };
public:
DS_DATA_ITEM( DS_ITEM_TYPE aType ); DS_DATA_ITEM( DS_ITEM_TYPE aType );
virtual ~DS_DATA_ITEM(); virtual ~DS_DATA_ITEM();
@ -147,28 +146,28 @@ public:
* *
* @param aPosition the new position of item, in mm. * @param aPosition the new position of item, in mm.
*/ */
void MoveTo( DPOINT aPosition ); void MoveTo( const DPOINT& aPosition );
/** /**
* Move item to a new position. * Move item to a new position.
* *
* @param aPosition the new position of the starting point in graphic units. * @param aPosition the new position of the starting point in graphic units.
*/ */
void MoveToUi( wxPoint aPosition ); void MoveToUi( const wxPoint& aPosition );
/** /**
* Move the starting point of the item to a new position. * Move the starting point of the item to a new position.
* *
* @param aPosition the new position of the starting point, in mm. * @param aPosition the new position of the starting point, in mm.
*/ */
void MoveStartPointTo( DPOINT aPosition ); void MoveStartPointTo( const DPOINT& aPosition );
/** /**
* Move the starting point of the item to a new position. * Move the starting point of the item to a new position.
* *
* @param aPosition is the new position of item in graphic units. * @param aPosition is the new position of item in graphic units.
*/ */
void MoveStartPointToUi( wxPoint aPosition ); void MoveStartPointToUi( const wxPoint& aPosition );
/** /**
@ -178,7 +177,7 @@ public:
* *
* @param aPosition is the new position of the ending point, in mm. * @param aPosition is the new position of the ending point, in mm.
*/ */
void MoveEndPointTo( DPOINT aPosition ); void MoveEndPointTo( const DPOINT& aPosition );
/** /**
* Move the ending point of the item to a new position. * Move the ending point of the item to a new position.
@ -187,7 +186,7 @@ public:
* *
* @param aPosition is the new position of the ending point in graphic units * @param aPosition is the new position of the ending point in graphic units
*/ */
void MoveEndPointToUi( wxPoint aPosition ); void MoveEndPointToUi( const wxPoint& aPosition );
/** /**
* @return true if the item is inside the rectangle defined by the 4 corners, false otherwise. * @return true if the item is inside the rectangle defined by the 4 corners, false otherwise.
@ -196,13 +195,6 @@ public:
const wxString GetClassName() const; const wxString GetClassName() const;
protected:
DS_ITEM_TYPE m_type;
PAGE_OPTION m_pageOption;
std::vector<DS_DRAW_ITEM_BASE*> m_drawItems;
public:
wxString m_Name; // a name used in drawing sheet editor to identify items wxString m_Name; // a name used in drawing sheet editor to identify items
wxString m_Info; // a comment, only useful in drawing sheet editor wxString m_Info; // a comment, only useful in drawing sheet editor
POINT_COORD m_Pos; POINT_COORD m_Pos;
@ -211,6 +203,12 @@ public:
int m_RepeatCount; // repeat count for duplicate items int m_RepeatCount; // repeat count for duplicate items
DPOINT m_IncrementVector; // for duplicate items: move vector for position increment DPOINT m_IncrementVector; // for duplicate items: move vector for position increment
int m_IncrementLabel; int m_IncrementLabel;
protected:
DS_ITEM_TYPE m_type;
PAGE_OPTION m_pageOption;
std::vector<DS_DRAW_ITEM_BASE*> m_drawItems;
}; };
@ -234,7 +232,7 @@ public:
} }
/** /**
* Closes the current contour, by storing the index of the last corner of the current * Close the current contour, by storing the index of the last corner of the current
* polygon in m_polyIndexEnd. * polygon in m_polyIndexEnd.
*/ */
void CloseContour() void CloseContour()
@ -326,7 +324,6 @@ public:
*/ */
void SetConstrainedTextSize(); void SetConstrainedTextSize();
/** /**
* Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\' * Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\'
* inside m_FullText * inside m_FullText

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-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2021 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
@ -101,12 +101,12 @@ public:
* *
* @param aOutputString is a wxString to store the S expr string * @param aOutputString is a wxString to store the S expr string
*/ */
void SaveInString( wxString& aOutputString ); void SaveInString( const wxString& aOutputString );
/** /**
* Fill the given string with an S-expr serialization of the WS_DATA_ITEMs. * Fill the given string with an S-expr serialization of the WS_DATA_ITEMs.
*/ */
void SaveInString( std::vector<DS_DATA_ITEM*> aItemsList, wxString& aOutputString ); void SaveInString( std::vector<DS_DATA_ITEM*>& aItemsList, const wxString& aOutputString );
void Append( DS_DATA_ITEM* aItem ); void Append( DS_DATA_ITEM* aItem );
void Remove( DS_DATA_ITEM* aItem ); void Remove( DS_DATA_ITEM* aItem );
@ -212,8 +212,6 @@ private:
double m_rightMargin; // the right page margin in mm double m_rightMargin; // the right page margin in mm
double m_topMargin; // the top page margin in mm double m_topMargin; // the top page margin in mm
double m_bottomMargin; // the bottom page margin in mm double m_bottomMargin; // the bottom page margin in mm
}; };
#endif // DS_DATA_MODEL_H #endif // DS_DATA_MODEL_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) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2021 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
@ -65,7 +65,7 @@ public:
void ViewGetLayers( int aLayers[], int& aCount ) const override; void ViewGetLayers( int aLayers[], int& aCount ) const override;
virtual void SetEnd( wxPoint aPos ) { /* not all types will need this */ } virtual void SetEnd( const wxPoint& aPos ) { /* not all types will need this */ }
virtual int GetPenWidth() const virtual int GetPenWidth() const
{ {
@ -131,9 +131,9 @@ public:
virtual wxString GetClass() const override { return wxT( "DS_DRAW_ITEM_LINE" ); } virtual wxString GetClass() const override { return wxT( "DS_DRAW_ITEM_LINE" ); }
const wxPoint& GetStart() const { return m_start; } const wxPoint& GetStart() const { return m_start; }
void SetStart( wxPoint aPos ) { m_start = aPos; } void SetStart( const wxPoint& aPos ) { m_start = aPos; }
const wxPoint& GetEnd() const { return m_end; } const wxPoint& GetEnd() const { return m_end; }
void SetEnd( wxPoint aPos ) override { m_end = aPos; } void SetEnd( const wxPoint& aPos ) override { m_end = aPos; }
wxPoint GetPosition() const override { return GetStart(); } wxPoint GetPosition() const override { return GetStart(); }
void SetPosition( const wxPoint& aPos ) override { SetStart( aPos ); } void SetPosition( const wxPoint& aPos ) override { SetStart( aPos ); }
@ -217,9 +217,9 @@ public:
virtual wxString GetClass() const override { return wxT( "DS_DRAW_ITEM_RECT" ); } virtual wxString GetClass() const override { return wxT( "DS_DRAW_ITEM_RECT" ); }
const wxPoint& GetStart() const { return m_start; } const wxPoint& GetStart() const { return m_start; }
void SetStart( wxPoint aPos ) { m_start = aPos; } void SetStart( const wxPoint& aPos ) { m_start = aPos; }
const wxPoint& GetEnd() const { return m_end; } const wxPoint& GetEnd() const { return m_end; }
void SetEnd( wxPoint aPos ) override { m_end = aPos; } void SetEnd( const wxPoint& aPos ) override { m_end = aPos; }
wxPoint GetPosition() const override { return GetStart(); } wxPoint GetPosition() const override { return GetStart(); }
void SetPosition( const wxPoint& aPos ) override { SetStart( aPos ); } void SetPosition( const wxPoint& aPos ) override { SetStart( aPos ); }
@ -261,10 +261,10 @@ public:
virtual wxString GetClass() const override { return wxT( "DS_DRAW_ITEM_PAGE" ); } virtual wxString GetClass() const override { return wxT( "DS_DRAW_ITEM_PAGE" ); }
void SetPageSize( wxSize aSize ) { m_pageSize = aSize; } void SetPageSize( const wxSize& aSize ) { m_pageSize = aSize; }
wxSize GetPageSize() const { return m_pageSize; } wxSize GetPageSize() const { return m_pageSize; }
const wxPoint& GetMarkerPos() const { return m_markerPos; } const wxPoint& GetMarkerPos() const { return m_markerPos; }
void SetMarkerPos( wxPoint aPos ) { m_markerPos = aPos; } void SetMarkerPos( const wxPoint& aPos ) { m_markerPos = aPos; }
double GetMarkerSize() const { return m_markerSize; } double GetMarkerSize() const { return m_markerSize; }
wxPoint GetPosition() const override { return wxPoint( 0, 0 ); } wxPoint GetPosition() const override { return wxPoint( 0, 0 ); }
@ -297,8 +297,8 @@ private:
class DS_DRAW_ITEM_TEXT : public DS_DRAW_ITEM_BASE, public EDA_TEXT class DS_DRAW_ITEM_TEXT : public DS_DRAW_ITEM_BASE, public EDA_TEXT
{ {
public: public:
DS_DRAW_ITEM_TEXT( DS_DATA_ITEM* aPeer, int aIndex, wxString& aText, wxPoint aPos, DS_DRAW_ITEM_TEXT( DS_DATA_ITEM* aPeer, int aIndex, const wxString& aText, const wxPoint& aPos,
wxSize aSize, int aPenWidth, bool aItalic = false, const wxSize& aSize, int aPenWidth, bool aItalic = false,
bool aBold = false ) : bool aBold = false ) :
DS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_TEXT_T), DS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_TEXT_T),
EDA_TEXT( aText ) EDA_TEXT( aText )

View File

@ -123,12 +123,6 @@ enum class RATSNEST_MODE
*/ */
struct LAYER_PRESET struct LAYER_PRESET
{ {
wxString name; ///< A name for this layer set
LSET layers; ///< Board layers that are visible
GAL_SET renderLayers; ///< Render layers (e.g. object types) that are visible
PCB_LAYER_ID activeLayer; ///< Optional layer to set active when this preset is loaded
bool readOnly; ///< True if this is a read-only (built-in) preset
LAYER_PRESET( const wxString& aName = wxEmptyString ) : LAYER_PRESET( const wxString& aName = wxEmptyString ) :
name( aName ), name( aName ),
activeLayer( UNSELECTED_LAYER ) activeLayer( UNSELECTED_LAYER )
@ -161,6 +155,12 @@ struct LAYER_PRESET
{ {
return aOther.layers == layers && aOther.renderLayers == renderLayers; return aOther.layers == layers && aOther.renderLayers == renderLayers;
} }
wxString name; ///< A name for this layer set
LSET layers; ///< Board layers that are visible
GAL_SET renderLayers; ///< Render layers (e.g. object types) that are visible
PCB_LAYER_ID activeLayer; ///< Optional layer to set active when this preset is loaded
bool readOnly; ///< True if this is a read-only (built-in) preset
}; };

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 (C) 2020 CERN * Copyright (C) 2020 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Jon Evans <jon@craftyjon.com> * @author Jon Evans <jon@craftyjon.com>
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
@ -46,7 +47,7 @@ public:
* A map of fully-qualified net names to colors used in the board context. * A map of fully-qualified net names to colors used in the board context.
* Since these color overrides are for the board, buses are not included here. * Since these color overrides are for the board, buses are not included here.
* Only nets that the user has assigned custom colors to will be in this list. * Only nets that the user has assigned custom colors to will be in this list.
* Nets that no longer exist will be deleted during a netlist read in PcbNew. * Nets that no longer exist will be deleted during a netlist read in Pcbnew.
*/ */
std::map<wxString, KIGFX::COLOR4D> m_PcbNetColors; std::map<wxString, KIGFX::COLOR4D> m_PcbNetColors;
@ -54,8 +55,9 @@ public:
const wxString& GetNetclassName( const wxString& aNetName ) const; const wxString& GetNetclassName( const wxString& aNetName ) const;
/** /**
* Parses a bus vector (e.g. A[7..0]) into name, begin, and end. * Parse a bus vector (e.g. A[7..0]) into name, begin, and end.
* Ensures that begin and end are positive and that end > begin. *
* Ensure that begin and end are positive and that end > begin.
* *
* @param aBus is a bus vector label string * @param aBus is a bus vector label string
* @param aName out is the bus name, e.g. "A" * @param aName out is the bus name, e.g. "A"
@ -66,18 +68,18 @@ public:
std::vector<wxString>* aMemberList ); std::vector<wxString>* aMemberList );
/** /**
* Parses a bus group label into the name and a list of components. * Parse a bus group label into the name and a list of components.
* *
* @param aGroup is the input label, e.g. "USB{DP DM}" * @param aGroup is the input label, e.g. "USB{DP DM}"
* @param name is the output group name, e.g. "USB" * @param name is the output group name, e.g. "USB"
* @param aMemberList is a list of member strings, e.g. "DP", "DM" * @param aMemberList is a list of member strings, e.g. "DP", "DM"
* @return true if aGroup was successfully parsed * @return true if aGroup was successfully parsed
*/ */
static bool ParseBusGroup( wxString aGroup, wxString* name, static bool ParseBusGroup( const wxString& aGroup, wxString* name,
std::vector<wxString>* aMemberList ); std::vector<wxString>* aMemberList );
/** /**
* Explodes the list of netclass assignments to include atomic members of composite labels * Explode the list of netclass assignments to include atomic members of composite labels
* (buses). * (buses).
* *
* @param aRebuildFromScratch indicates the assignments should be rebuilt from the netclass * @param aRebuildFromScratch indicates the assignments should be rebuilt from the netclass

View File

@ -101,22 +101,10 @@ protected:
wxString getLegacyFileExt() const override; wxString getLegacyFileExt() const override;
private:
/// An list of schematic sheets in this project
std::vector<FILE_INFO_PAIR> m_sheets;
/// A list of board files in this project
std::vector<FILE_INFO_PAIR> m_boards;
/// A link to the owning PROJECT
PROJECT* m_project;
/** /**
* Below are project-level settings that have not been moved to a dedicated file * Below are project-level settings that have not been moved to a dedicated file
*/ */
public: public:
/** /**
* Shared params, used by more than one application * Shared params, used by more than one application
*/ */
@ -179,6 +167,16 @@ public:
/// List of stored layer presets /// List of stored layer presets
std::vector<LAYER_PRESET> m_LayerPresets; std::vector<LAYER_PRESET> m_LayerPresets;
private:
/// An list of schematic sheets in this project
std::vector<FILE_INFO_PAIR> m_sheets;
/// A list of board files in this project
std::vector<FILE_INFO_PAIR> m_boards;
/// A link to the owning PROJECT
PROJECT* m_project;
}; };
// Specializations to allow directly reading/writing FILE_INFO_PAIRs from JSON // Specializations to allow directly reading/writing FILE_INFO_PAIRs from JSON

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 (C) 2020 CERN * Copyright (C) 2020 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* @author Jon Evans <jon@craftyjon.com> * @author Jon Evans <jon@craftyjon.com>
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
@ -65,8 +66,13 @@ public:
m_project = aProject; m_project = aProject;
} }
protected: void SaveFileState( const wxString& aFileName, const WINDOW_SETTINGS* aWindowCfg, bool aOpen );
const PROJECT_FILE_STATE* GetFileState( const wxString& aFileName );
void ClearFileState();
protected:
wxString getFileExt() const override wxString getFileExt() const override
{ {
return ProjectLocalSettingsFileExtension; return ProjectLocalSettingsFileExtension;
@ -77,11 +83,6 @@ protected:
return wxT( "NO_SUCH_FILE_EXTENSION" ); return wxT( "NO_SUCH_FILE_EXTENSION" );
} }
private:
/// A link to the owning project
PROJECT* m_project;
public: public:
/** /**
@ -136,11 +137,9 @@ public:
/// State of the selection filter widget /// State of the selection filter widget
SELECTION_FILTER_OPTIONS m_SelectionFilter; SELECTION_FILTER_OPTIONS m_SelectionFilter;
void SaveFileState( const wxString& aFileName, const WINDOW_SETTINGS* aWindowCfg, bool aOpen ); private:
/// A link to the owning project
const PROJECT_FILE_STATE* GetFileState( const wxString& aFileName ); PROJECT* m_project;
void ClearFileState();
}; };
#endif #endif

View File

@ -323,7 +323,7 @@ public:
* @param aCenter: the new center point, in world space coordinates. * @param aCenter: the new center point, in world space coordinates.
* @param occultingScreenRect: the occulting rect, in screen space coordinates. * @param occultingScreenRect: the occulting rect, in screen space coordinates.
*/ */
void SetCenter( VECTOR2D aCenter, const BOX2D& occultingScreenRect ); void SetCenter( const VECTOR2D& aCenter, const BOX2D& occultingScreenRect );
/** /**
* Return the center point of this VIEW (in world space coordinates). * Return the center point of this VIEW (in world space coordinates).

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 (C) 2013-2017 CERN * Copyright (C) 2013-2017 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.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>
* *
@ -89,15 +90,14 @@ public:
void Polyline( const SHAPE_LINE_CHAIN& aPolyLine ); void Polyline( const SHAPE_LINE_CHAIN& aPolyLine );
void Polygon( const VECTOR2D aPointList[], int aListSize ); void Polygon( const VECTOR2D aPointList[], int aListSize );
void BitmapText( const wxString& aText, const VECTOR2D& aPosition, void BitmapText( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle );
double aRotationAngle );
// Draw settings // Draw settings
void SetIsFill( bool aIsFillEnabled ); void SetIsFill( bool aIsFillEnabled );
void SetIsStroke( bool aIsStrokeEnabled ); void SetIsStroke( bool aIsStrokeEnabled );
void SetFillColor( const COLOR4D& aColor ); void SetFillColor( const COLOR4D& aColor );
void SetStrokeColor( const COLOR4D& aColor ); void SetStrokeColor( const COLOR4D& aColor );
void SetGlyphSize( const VECTOR2D aSize ); void SetGlyphSize( const VECTOR2D& aSize );
void SetLineWidth( double aLineWidth ); void SetLineWidth( double aLineWidth );
const COLOR4D& GetStrokeColor() const { return m_strokeColor; } const COLOR4D& GetStrokeColor() const { return m_strokeColor; }

View File

@ -114,7 +114,7 @@ public:
return m_noline; return m_noline;
} }
inline void SetCluster( std::shared_ptr<CN_CLUSTER> aCluster ) inline void SetCluster( std::shared_ptr<CN_CLUSTER>& aCluster )
{ {
m_cluster = aCluster; m_cluster = aCluster;
} }
@ -126,7 +126,7 @@ public:
/** /**
* The anchor point is dangling if the parent is a track and this anchor point is not * The anchor point is dangling if the parent is a track and this anchor point is not
* connected to another item ( track, vas pad or zone) or if the parent is a via and * connected to another item ( track, vias pad or zone) or if the parent is a via and
* this anchor point is connected to only one track and not to another item. * this anchor point is connected to only one track and not to another item.
* *
* @return true if this anchor is dangling. * @return true if this anchor is dangling.
@ -323,7 +323,7 @@ public:
return ContainsPoint( anchor->Pos(), 0 ); return ContainsPoint( anchor->Pos(), 0 );
} }
bool ContainsPoint( const VECTOR2I p, int aAccuracy = 0 ) const bool ContainsPoint( const VECTOR2I& p, int aAccuracy = 0 ) const
{ {
ZONE* zone = static_cast<ZONE*>( Parent() ); ZONE* zone = static_cast<ZONE*>( Parent() );
int clearance = aAccuracy; int clearance = aAccuracy;