Code cleaning.

This commit is contained in:
Wayne Stambaugh 2023-02-08 08:26:54 -05:00
parent ae2da76615
commit 3b722de637
4 changed files with 103 additions and 72 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 jp.charras at wanadoo.fr
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2019, 2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -39,6 +39,7 @@
#include "tools/pl_actions.h"
#include "tools/pl_selection_tool.h"
/* XPM
* This bitmap is used to show item types
*/
@ -156,6 +157,7 @@ static const char* img_xpm[] =
" xx "
};
// A helper class to draw these bitmaps into a wxGrid cell:
class BitmapGridCellRenderer : public wxGridCellStringRenderer
{
@ -171,6 +173,7 @@ public:
int aRow, int aCol, bool aIsSelected) override;
};
// Column ids for m_gridListItems
enum COL_INDEX
{
@ -221,10 +224,13 @@ void DIALOG_INSPECTOR::ReCreateDesignList()
// The first item is the layout: Display info about the page: fmt, size...
int row = 0;
GetGridList()->SetCellValue( row, COL_TYPENAME, _( "Layout" ) );
GetGridList()->SetCellValue( row, COL_COMMENT, page_info.GetType() ); // Display page format name
// Display page format name.
GetGridList()->SetCellValue( row, COL_COMMENT, page_info.GetType() );
GetGridList()->SetCellValue( row, COL_REPEAT_NUMBER, "-" );
wxSize page_sizeIU = m_editorFrame->GetPageSizeIU();
GetGridList()->SetCellValue( row, COL_TEXTSTRING, wxString::Format( _( "Size: %.1fx%.1fmm" ),
GetGridList()->SetCellValue( row, COL_TEXTSTRING,
wxString::Format( _( "Size: %.1fx%.1fmm" ),
drawSheetIUScale.IUTomm( page_sizeIU.x ),
drawSheetIUScale.IUTomm( page_sizeIU.y ) ) );
GetGridList()->SetCellRenderer (row, COL_BITMAP, new BitmapGridCellRenderer( root_xpm ) );
@ -233,31 +239,32 @@ void DIALOG_INSPECTOR::ReCreateDesignList()
// Now adding all current items
row++;
for( DS_DATA_ITEM* item : drawingSheet.GetItems() )
{
const char** img = nullptr;
switch( item->GetType() )
{
case DS_DATA_ITEM::DS_SEGMENT:
img = line_xpm;
break;
case DS_DATA_ITEM::DS_SEGMENT:
img = line_xpm;
break;
case DS_DATA_ITEM::DS_RECT:
img = rect_xpm;
break;
case DS_DATA_ITEM::DS_RECT:
img = rect_xpm;
break;
case DS_DATA_ITEM::DS_TEXT:
img = text_xpm;
break;
case DS_DATA_ITEM::DS_TEXT:
img = text_xpm;
break;
case DS_DATA_ITEM::DS_POLYPOLYGON:
img = poly_xpm;
break;
case DS_DATA_ITEM::DS_POLYPOLYGON:
img = poly_xpm;
break;
case DS_DATA_ITEM::DS_BITMAP:
img = img_xpm;
break;
case DS_DATA_ITEM::DS_BITMAP:
img = img_xpm;
break;
}
GetGridList()->AppendRows( 1 );
@ -298,14 +305,15 @@ void DIALOG_INSPECTOR::ReCreateDesignList()
GetGridList()->AutoSizeColumn( col, false );
}
else
{
GetGridList()->AutoSizeColumn( col );
}
GetGridList()->AutoSizeColLabelSize( col );
}
}
// Select the row corresponding to the DS_DATA_ITEM aItem
void DIALOG_INSPECTOR::SelectRow( DS_DATA_ITEM* aItem )
{
// m_itemsList[0] is not a true DS_DATA_ITEM
@ -320,7 +328,7 @@ void DIALOG_INSPECTOR::SelectRow( DS_DATA_ITEM* aItem )
}
}
//return the drawing sheet item managed by the cell
DS_DATA_ITEM* DIALOG_INSPECTOR::GetDrawingSheetDataItem( int aRow ) const
{
return ( aRow >= 0 && aRow < (int)m_itemsList.size() ) ? m_itemsList[aRow]: nullptr;
@ -349,11 +357,11 @@ void DIALOG_INSPECTOR::onCellClicked( wxGridEvent& event )
void BitmapGridCellRenderer::Draw( wxGrid& aGrid, wxGridCellAttr& aAttr,
wxDC& aDc, const wxRect& aRect,
int aRow, int aCol, bool aIsSelected)
int aRow, int aCol, bool aIsSelected )
{
wxGridCellStringRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected);
wxGridCellStringRenderer::Draw( aGrid, aAttr, aDc, aRect, aRow, aCol, aIsSelected );
wxBitmap bm( m_BitmapXPM );
aDc.DrawBitmap( bm,aRect.GetX()+5, aRect.GetY()+2, true);
aDc.DrawBitmap( bm,aRect.GetX()+5, aRect.GetY()+2, true );
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 jp.charras at wanadoo.fr
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2019, 2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -34,19 +34,8 @@ class PL_EDITOR_FRAME;
/**
* DESIGN_INSPECTOR is the left window showing the list of items
*/
class DIALOG_INSPECTOR : public DIALOG_INSPECTOR_BASE
{
friend class PL_EDITOR_FRAME;
private:
wxGrid* GetGridList() const { return m_gridListItems; }
void onCellClicked( wxGridEvent& event ) override;
// The list of DS_DATA_ITEM found in drawing sheet
std::vector<DS_DATA_ITEM*> m_itemsList;
PL_EDITOR_FRAME* m_editorFrame;
public:
DIALOG_INSPECTOR( PL_EDITOR_FRAME* aParent );
~DIALOG_INSPECTOR();
@ -60,6 +49,17 @@ public:
// Select the tree item corresponding to the DS_DATA_ITEM aItem
void SelectRow( DS_DATA_ITEM* aItem );
private:
friend class PL_EDITOR_FRAME;
wxGrid* GetGridList() const { return m_gridListItems; }
void onCellClicked( wxGridEvent& event ) override;
// The list of DS_DATA_ITEM found in drawing sheet
std::vector<DS_DATA_ITEM*> m_itemsList;
PL_EDITOR_FRAME* m_editorFrame;
};
#endif /* _DESIGN_INSPECTOR_H */

View File

@ -1,12 +1,8 @@
/**
* @file dialogs_for_printing.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Jean-Pierre Charras, jp.charras at wanadoo.fr
*
@ -28,6 +24,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file dialogs_for_printing.cpp
*/
#include <base_units.h>
#include <gr_basic.h>
#include <drawing_sheet/ds_data_item.h>
@ -47,9 +47,6 @@
*/
class PLEDITOR_PRINTOUT : public wxPrintout
{
private:
PL_EDITOR_FRAME* m_parent;
public:
PLEDITOR_PRINTOUT( PL_EDITOR_FRAME* aParent, const wxString& aTitle ) :
wxPrintout( aTitle )
@ -62,6 +59,9 @@ public:
bool HasPage( int aPageNum ) override { return ( aPageNum <= 2 ); }
void GetPageInfo( int* minPage, int* maxPage, int* selPageFrom, int* selPageTo ) override;
void PrintPage( int aPageNum );
private:
PL_EDITOR_FRAME* m_parent;
};
@ -70,8 +70,6 @@ public:
*/
class PLEDITOR_PREVIEW_FRAME : public wxPreviewFrame
{
PL_EDITOR_FRAME* m_parent;
public:
PLEDITOR_PREVIEW_FRAME( wxPrintPreview* aPreview, PL_EDITOR_FRAME* aParent,
const wxString& aTitle, const wxPoint& aPos = wxDefaultPosition,
@ -118,6 +116,8 @@ public:
}
private:
PL_EDITOR_FRAME* m_parent;
static wxPoint s_pos;
static wxSize s_size;
@ -168,7 +168,6 @@ void PLEDITOR_PRINTOUT::PrintPage( int aPageNum )
old_org = screen->m_DrawOrg;
// Change scale factor and offset to print the whole page.
pageSizeIU = m_parent->GetPageSettings().GetSizeIU( drawSheetIUScale.IU_PER_MILS );
FitThisSizeToPaper( pageSizeIU );
fitRect = GetLogicalPaperRect();

View File

@ -42,9 +42,13 @@
#include <dialogs/html_message_box.h>
#define DLG_MIN_TEXTSIZE 0.01 // min drawing sheet text default size in mm from PROPERTIES_FRAME
// Note also 0.0 is allowed for a given text to use the default size
#define DLG_MAX_TEXTSIZE 100.0 // max drawing sheet text size in mm from PROPERTIES_FRAME
/**
* Minimum drawing sheet text default size in millmeters from #PROPERTIES_FRAME.
*
* @note 0.0 is allowed for a given text to use the default size.
*/
#define DLG_MIN_TEXTSIZE 0.01
#define DLG_MAX_TEXTSIZE 100.0 ///< Maximum drawing sheet text size in mm from PROPERTIES_FRAME.
PROPERTIES_FRAME::PROPERTIES_FRAME( PL_EDITOR_FRAME* aParent ) :
@ -60,10 +64,14 @@ PROPERTIES_FRAME::PROPERTIES_FRAME( PL_EDITOR_FRAME* aParent ) :
m_textEndY( aParent, m_staticTextEndY, m_textCtrlEndY, m_TextEndYUnits ),
m_textStepX( aParent, m_staticTextStepX, m_textCtrlStepX, m_TextStepXUnits ),
m_textStepY( aParent, m_staticTextStepY, m_textCtrlStepY, m_TextStepYUnits ),
m_defaultTextSizeX( aParent, m_staticTextDefTsX, m_textCtrlDefaultTextSizeX, m_defaultTextSizeXUnits ),
m_defaultTextSizeY( aParent, m_staticTextDefTsY, m_textCtrlDefaultTextSizeY, m_defaultTextSizeYUnits ),
m_defaultLineWidth( aParent, m_defaultLineWidthLabel, m_defaultLineWidthCtrl, m_defaultLineWidthUnits ),
m_defaultTextThickness( aParent, m_defaultTextThicknessLabel, m_defaultTextThicknessCtrl, m_defaultTextThicknessUnits ),
m_defaultTextSizeX( aParent, m_staticTextDefTsX, m_textCtrlDefaultTextSizeX,
m_defaultTextSizeXUnits ),
m_defaultTextSizeY( aParent, m_staticTextDefTsY, m_textCtrlDefaultTextSizeY,
m_defaultTextSizeYUnits ),
m_defaultLineWidth( aParent, m_defaultLineWidthLabel, m_defaultLineWidthCtrl,
m_defaultLineWidthUnits ),
m_defaultTextThickness( aParent, m_defaultTextThicknessLabel, m_defaultTextThicknessCtrl,
m_defaultTextThicknessUnits ),
m_textLeftMargin( aParent, m_leftMarginLabel, m_leftMarginCtrl, m_leftMarginUnits ),
m_textRightMargin( aParent, m_rightMarginLabel, m_rightMarginCtrl, m_rightMarginUnits ),
m_textTopMargin( aParent, m_topMarginLabel, m_topMarginCtrl, m_topMarginUnits ),
@ -184,25 +192,26 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToGeneral()
if( is_valid )
model.m_DefaultLineWidth = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, units,
m_defaultLineWidth.GetValue() );
m_defaultLineWidth.GetValue() );
is_valid = m_defaultTextSizeX.Validate( DLG_MIN_TEXTSIZE, DLG_MAX_TEXTSIZE,
EDA_UNITS::MILLIMETRES );
EDA_UNITS::MILLIMETRES );
if( is_valid )
model.m_DefaultTextSize.x = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, units,
m_defaultTextSizeX.GetValue() );
m_defaultTextSizeX.GetValue() );
is_valid = m_defaultTextSizeY.Validate( DLG_MIN_TEXTSIZE, DLG_MAX_TEXTSIZE, EDA_UNITS::MILLIMETRES );
is_valid = m_defaultTextSizeY.Validate( DLG_MIN_TEXTSIZE, DLG_MAX_TEXTSIZE,
EDA_UNITS::MILLIMETRES );
if( is_valid )
model.m_DefaultTextSize.y = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, units,
m_defaultTextSizeY.GetValue() );
m_defaultTextSizeY.GetValue() );
is_valid = m_defaultTextThickness.Validate( 0.0, 5.0, EDA_UNITS::MILLIMETRES );
if( is_valid )
model.m_DefaultTextThickness = EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, units,
m_defaultTextThickness.GetValue() );
m_defaultTextThickness.GetValue() );
// Get page margins values
model.SetRightMargin( EDA_UNIT_UTILS::UI::ToUserUnit( drawSheetIUScale, units,
@ -242,8 +251,10 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( DS_DATA_ITEM* aItem )
}
// Position/ start point
m_textPosX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, aItem->m_Pos.m_Pos.x ) );
m_textPosY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, aItem->m_Pos.m_Pos.y ) );
m_textPosX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
aItem->m_Pos.m_Pos.x ) );
m_textPosY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
aItem->m_Pos.m_Pos.y ) );
switch( aItem->m_Pos.m_Anchor )
{
@ -254,8 +265,10 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( DS_DATA_ITEM* aItem )
}
// End point
m_textEndX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, aItem->m_End.m_Pos.x ) );
m_textEndY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, aItem->m_End.m_Pos.y ) );
m_textEndX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
aItem->m_End.m_Pos.x ) );
m_textEndY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
aItem->m_End.m_Pos.y ) );
switch( aItem->m_End.m_Anchor )
{
@ -265,7 +278,8 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( DS_DATA_ITEM* aItem )
case LT_CORNER: m_comboBoxCornerEnd->SetSelection( 1 ); break;
}
m_lineWidth.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, aItem->m_LineWidth ) );
m_lineWidth.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
aItem->m_LineWidth ) );
// Now, set prms more specific to DS_DATA_ITEM types
// For a given type, disable widgets which are not relevant,
@ -288,8 +302,10 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( DS_DATA_ITEM* aItem )
m_textCtrlRotation->SetValue( msg );
// Constraints:
m_constraintX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, item->m_BoundingBoxSize.x ) );
m_constraintY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, item->m_BoundingBoxSize.y ) );
m_constraintX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
item->m_BoundingBoxSize.x ) );
m_constraintY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
item->m_BoundingBoxSize.y ) );
// Font Options
m_fontCtrl->SetFontSelection( item->m_Font );
@ -320,8 +336,10 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( DS_DATA_ITEM* aItem )
}
// Text size
m_textSizeX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, item->m_TextSize.x ) );
m_textSizeY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, item->m_TextSize.y ) );
m_textSizeX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
item->m_TextSize.x ) );
m_textSizeY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
item->m_TextSize.y ) );
}
if( aItem->GetType() == DS_DATA_ITEM::DS_POLYPOLYGON )
@ -374,11 +392,14 @@ void PROPERTIES_FRAME::CopyPrmsFromItemToPanel( DS_DATA_ITEM* aItem )
msg.Printf( wxT( "%d" ), aItem->m_RepeatCount );
m_textCtrlRepeatCount->SetValue( msg );
m_textStepX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, aItem->m_IncrementVector.x ) );
m_textStepY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units, aItem->m_IncrementVector.y ) );
m_textStepX.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
aItem->m_IncrementVector.x ) );
m_textStepY.SetDoubleValue( EDA_UNIT_UTILS::UI::FromUserUnit( drawSheetIUScale, units,
aItem->m_IncrementVector.y ) );
// The number of widgets was modified, so recalculate sizers
m_swItemProperties->Layout();
#ifdef __WXGTK__
// This call is mandatory on wxGTK to initialize the right virtual size and therefore
// scrollbars, but for some reason, create issues on Windows (incorrect display
@ -519,6 +540,7 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( DS_DATA_ITEM* aItem )
long itmp;
msg = m_textCtrlRepeatCount->GetValue();
msg.ToLong( &itmp );
// Ensure m_RepeatCount is > 0. Otherwise it create issues because a repeat
// count < 1 make no sense
if( itmp < 1l )
@ -567,7 +589,8 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( DS_DATA_ITEM* aItem )
item->m_Font = m_fontCtrl->GetFontSelection( item->m_Bold, item->m_Italic );
msg = m_textCtrlRotation->GetValue();
item->m_Orient = EDA_UNIT_UTILS::UI::DoubleValueFromString( drawSheetIUScale, EDA_UNITS::UNSCALED, msg );
item->m_Orient = EDA_UNIT_UTILS::UI::DoubleValueFromString( drawSheetIUScale,
EDA_UNITS::UNSCALED, msg );
// Import text size
is_valid = m_textSizeX.Validate( 0.0, DLG_MAX_TEXTSIZE, EDA_UNITS::MILLIMETRES );
@ -594,7 +617,8 @@ bool PROPERTIES_FRAME::CopyPrmsFromPanelToItem( DS_DATA_ITEM* aItem )
msg = m_textCtrlRotation->GetValue();
item->m_Orient = EDA_ANGLE(
EDA_UNIT_UTILS::UI::DoubleValueFromString( drawSheetIUScale,EDA_UNITS::UNSCALED, msg ), DEGREES_T );
EDA_UNIT_UTILS::UI::DoubleValueFromString( drawSheetIUScale,EDA_UNITS::UNSCALED,
msg ), DEGREES_T );
}
if( aItem->GetType() == DS_DATA_ITEM::DS_BITMAP )