Pcbnew, import graphics: fixes and enhancements:

- fix regression: allow grouping or not imported items
- store more settings in Pcbnew settings: all options are now stored.
- default tolerance to connect items is now 0.01 mm. 1 mm is a too big value,
and can create serious artifacts in imported outlines.
This commit is contained in:
jean-pierre charras 2023-11-15 20:22:43 +01:00
parent 44374c661f
commit a663dd7ec4
8 changed files with 207 additions and 12 deletions

View File

@ -41,9 +41,11 @@
#include <memory>
// Static members of DIALOG_IMPORT_GRAPHICS, to remember the user's choices during the session
bool DIALOG_IMPORT_GRAPHICS::s_useDlgLayerSelection = true;
bool DIALOG_IMPORT_GRAPHICS::s_placementInteractive = true;
bool DIALOG_IMPORT_GRAPHICS::s_shouldGroupItems = true;
bool DIALOG_IMPORT_GRAPHICS::s_fixDiscontinuities = true;
int DIALOG_IMPORT_GRAPHICS::s_toleranceValue = pcbIUScale.mmToIU( 1 );
int DIALOG_IMPORT_GRAPHICS::s_toleranceValue = pcbIUScale.mmToIU( 0.01 );
double DIALOG_IMPORT_GRAPHICS::s_importScale = 1.0; // Do not change the imported items size
@ -74,7 +76,14 @@ DIALOG_IMPORT_GRAPHICS::DIALOG_IMPORT_GRAPHICS( PCB_BASE_FRAME* aParent ) :
PCBNEW_SETTINGS* cfg = m_parent->GetPcbNewSettings();
s_shouldGroupItems = cfg->m_ImportGraphics.group_items;
s_fixDiscontinuities = cfg->m_ImportGraphics.fix_discontinuities;
s_toleranceValue = cfg->m_ImportGraphics.tolerance * pcbIUScale.IU_PER_MM;
s_useDlgLayerSelection = cfg->m_ImportGraphics.use_dlg_layer_selection;
s_placementInteractive = cfg->m_ImportGraphics.interactive_placement;
m_cbGroupItems->SetValue( s_shouldGroupItems );
m_setLayerCheckbox->SetValue( s_useDlgLayerSelection );
m_xOrigin.SetValue( cfg->m_ImportGraphics.origin_x * pcbIUScale.IU_PER_MM );
m_yOrigin.SetValue( cfg->m_ImportGraphics.origin_y * pcbIUScale.IU_PER_MM );
@ -124,6 +133,8 @@ DIALOG_IMPORT_GRAPHICS::~DIALOG_IMPORT_GRAPHICS()
s_placementInteractive = !m_placeAtCheckbox->GetValue();
s_fixDiscontinuities = m_rbFixDiscontinuities->GetValue();
s_toleranceValue = m_tolerance.GetIntValue();
s_shouldGroupItems = m_cbGroupItems->IsChecked();
s_useDlgLayerSelection = m_setLayerCheckbox->IsChecked();
PCBNEW_SETTINGS* cfg = nullptr;
@ -139,16 +150,19 @@ DIALOG_IMPORT_GRAPHICS::~DIALOG_IMPORT_GRAPHICS()
if( cfg )
{
cfg->m_ImportGraphics.layer = m_SelLayerBox->GetLayerSelection();
cfg->m_ImportGraphics.use_dlg_layer_selection = s_useDlgLayerSelection;
cfg->m_ImportGraphics.interactive_placement = s_placementInteractive;
cfg->m_ImportGraphics.last_file = m_textCtrlFileName->GetValue();
cfg->m_ImportGraphics.dxf_line_width = pcbIUScale.IUTomm( m_defaultLineWidth.GetIntValue() );
cfg->m_ImportGraphics.origin_x = pcbIUScale.IUTomm( m_xOrigin.GetIntValue() );
cfg->m_ImportGraphics.origin_y = pcbIUScale.IUTomm( m_yOrigin.GetIntValue() );
cfg->m_ImportGraphics.dxf_units = m_dxfUnitsChoice->GetSelection();
cfg->m_ImportGraphics.group_items = s_shouldGroupItems;
cfg->m_ImportGraphics.fix_discontinuities = s_fixDiscontinuities;
cfg->m_ImportGraphics.tolerance = pcbIUScale.IUTomm( s_toleranceValue );
}
s_importScale = EDA_UNIT_UTILS::UI::DoubleValueFromString( m_importScaleCtrl->GetValue() );
s_toleranceValue = m_tolerance.GetIntValue();
m_textCtrlFileName->Disconnect( wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler( DIALOG_IMPORT_GRAPHICS::onFilename ),

View File

@ -65,6 +65,11 @@ public:
*/
int GetTolerance() { return m_tolerance.GetValue(); }
/**
* @return true if imported items must be placed in a new PCB_GROUP.
*/
bool ShouldGroupItems() { return m_cbGroupItems->IsChecked(); }
bool TransferDataFromWindow() override;
private:
@ -83,6 +88,7 @@ private:
UNIT_BINDER m_defaultLineWidth;
UNIT_BINDER m_tolerance;
static bool s_useDlgLayerSelection;
static bool s_shouldGroupItems;
static bool s_placementInteractive;
static bool s_fixDiscontinuities;

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -125,6 +125,8 @@ DIALOG_IMPORT_GRAPHICS_BASE::DIALOG_IMPORT_GRAPHICS_BASE( wxWindow* parent, wxWi
gbSizer2->Add( m_yUnits, wxGBPosition( 0, 4 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 );
m_setLayerCheckbox = new wxCheckBox( this, wxID_ANY, _("Set layer:"), wxDefaultPosition, wxDefaultSize, 0 );
m_setLayerCheckbox->SetToolTip( _("If checked, use the selected layer in this dialog\nIf unchecked, use the Board Editor active layer") );
gbSizer2->Add( m_setLayerCheckbox, wxGBPosition( 1, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 );
m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
@ -139,6 +141,19 @@ DIALOG_IMPORT_GRAPHICS_BASE::DIALOG_IMPORT_GRAPHICS_BASE( wxWindow* parent, wxWi
m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerMain->Add( m_staticline1, 0, wxEXPAND|wxTOP|wxBOTTOM, 6 );
wxBoxSizer* bSizerGroupOpt;
bSizerGroupOpt = new wxBoxSizer( wxVERTICAL );
m_cbGroupItems = new wxCheckBox( this, wxID_ANY, _("Group imported items"), wxDefaultPosition, wxDefaultSize, 0 );
m_cbGroupItems->SetValue(true);
bSizerGroupOpt->Add( m_cbGroupItems, 0, wxALL, 5 );
m_staticline3 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerGroupOpt->Add( m_staticline3, 0, wxEXPAND | wxALL, 5 );
bSizerMain->Add( bSizerGroupOpt, 0, wxEXPAND|wxLEFT, 5 );
wxBoxSizer* bSizer11;
bSizer11 = new wxBoxSizer( wxHORIZONTAL );
@ -159,7 +174,7 @@ DIALOG_IMPORT_GRAPHICS_BASE::DIALOG_IMPORT_GRAPHICS_BASE( wxWindow* parent, wxWi
bSizer11->Add( m_toleranceUnits, 0, wxALIGN_CENTER_VERTICAL, 5 );
bSizerMain->Add( bSizer11, 0, wxEXPAND|wxALL, 10 );
bSizerMain->Add( bSizer11, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 10 );
bSizerMain->Add( 0, 3, 1, wxEXPAND, 5 );

View File

@ -1195,7 +1195,7 @@
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="tooltip">If checked, use the selected layer in this dialog&#x0A;If unchecked, use the Board Editor active layer</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
@ -1333,9 +1333,142 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>
<property name="name">bSizerGroupOpt</property>
<property name="orient">wxVERTICAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">1</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Group imported items</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_cbGroupItems</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxEXPAND | wxALL</property>
<property name="proportion">0</property>
<object class="wxStaticLine" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticline3</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxLI_HORIZONTAL</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">10</property>
<property name="flag">wxEXPAND|wxALL</property>
<property name="flag">wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT</property>
<property name="proportion">0</property>
<object class="wxBoxSizer" expanded="1">
<property name="minimum_size"></property>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -65,6 +65,8 @@ class DIALOG_IMPORT_GRAPHICS_BASE : public DIALOG_SHIM
wxCheckBox* m_setLayerCheckbox;
PCB_LAYER_BOX_SELECTOR* m_SelLayerBox;
wxStaticLine* m_staticline1;
wxCheckBox* m_cbGroupItems;
wxStaticLine* m_staticline3;
wxCheckBox* m_rbFixDiscontinuities;
wxStaticText* m_toleranceLabel;
wxTextCtrl* m_toleranceCtrl;

View File

@ -425,9 +425,21 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS()
m_params.emplace_back( new PARAM<int>( "import_graphics.layer",
&m_ImportGraphics.layer, Dwgs_User ) );
m_params.emplace_back( new PARAM<bool>( "import_graphics.use_dlg_layer_selection",
&m_ImportGraphics.use_dlg_layer_selection, true ) );
m_params.emplace_back( new PARAM<bool>( "import_graphics.interactive_placement",
&m_ImportGraphics.interactive_placement, true ) );
m_params.emplace_back( new PARAM<bool>( "import_graphics.group_items",
&m_ImportGraphics.group_items, true ) );
m_params.emplace_back( new PARAM<bool>( "import_graphics.fix_discontinuities",
&m_ImportGraphics.fix_discontinuities, false ) );
m_params.emplace_back( new PARAM<double>( "import_graphics.tolerance",
&m_ImportGraphics.tolerance, 0.01, 0.0, 10.0 ) );
m_params.emplace_back( new PARAM<int>( "import_graphics.line_width_units",
&m_ImportGraphics.dxf_line_width_units, 0 ) );

View File

@ -234,7 +234,11 @@ public:
struct DIALOG_IMPORT_GRAPHICS
{
int layer;
bool use_dlg_layer_selection;
bool interactive_placement;
bool group_items;
bool fix_discontinuities;
double tolerance;
wxString last_file;
double dxf_line_width;
int dxf_line_width_units;

View File

@ -1509,11 +1509,15 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
PICKED_ITEMS_LIST groupUndoList;
PCB_LAYER_ID layer = F_Cu;
PCB_GROUP* group = new PCB_GROUP( m_frame->GetModel() );
PCB_GROUP* group = dlg.ShouldGroupItems() ? new PCB_GROUP( m_frame->GetModel() )
: nullptr;
newItems.push_back( group );
selectedItems.push_back( group );
preview.Add( group );
if( group )
{
newItems.push_back( group );
selectedItems.push_back( group );
preview.Add( group );
}
if( dlg.ShouldFixDiscontinuities() )
{
@ -1541,7 +1545,12 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
wxCHECK2( item, continue );
newItems.push_back( item );
group->AddItem( item );
if( group )
group->AddItem( item );
else
selectedItems.push_back( item );
groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) );
preview.Add( item );