Gfx import: fix many issues, and add many enhancements.

* Do not compile dxf old files.
* import gfx, gal mode: make absolute placement working.
* Import gfx in legacy canvas: use it and make interactive placement working
* Take imported line width in account. Ensure DXF line thickness is OK.
* handling empty files in legacy mode.
This commit is contained in:
jean-pierre charras 2018-11-05 17:04:05 +01:00
parent 430c61822d
commit cc0aa8b928
25 changed files with 3430 additions and 2683 deletions

View File

@ -181,14 +181,6 @@ if( KICAD_SCRIPTING AND KICAD_SCRIPTING_ACTION_MENU )
) )
endif() endif()
if( 1)
set( PCBNEW_IMPORT_DXF
import_dxf/dialog_dxf_import.cpp
import_dxf/dialog_dxf_import_base.cpp
import_dxf/dxf2brd_items.cpp
)
endif()
set( PCBNEW_IMPORT_GFX set( PCBNEW_IMPORT_GFX
import_gfx/dialog_import_gfx_base.cpp import_gfx/dialog_import_gfx_base.cpp
import_gfx/dialog_import_gfx.cpp import_gfx/dialog_import_gfx.cpp
@ -222,7 +214,6 @@ set( PCBNEW_MICROWAVE_SRCS
set( PCBNEW_CLASS_SRCS set( PCBNEW_CLASS_SRCS
${PCBNEW_DIALOGS} ${PCBNEW_DIALOGS}
${PCBNEW_EXPORTERS} ${PCBNEW_EXPORTERS}
${PCBNEW_IMPORT_DXF}
${PCBNEW_IMPORT_GFX} ${PCBNEW_IMPORT_GFX}
autorouter/rect_placement/rect_placement.cpp autorouter/rect_placement/rect_placement.cpp

View File

@ -1243,7 +1243,7 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_GEN_IMPORT_GRAPHICS_FILE: case ID_GEN_IMPORT_GRAPHICS_FILE:
InvokeDXFDialogBoardImport( this ); InvokeDialogImportGfxBoard( this );
m_canvas->Refresh(); m_canvas->Refresh();
break; break;

View File

@ -799,7 +799,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_GEN_IMPORT_GRAPHICS_FILE: case ID_GEN_IMPORT_GRAPHICS_FILE:
if( GetBoard()->m_Modules ) if( GetBoard()->m_Modules )
{ {
InvokeDXFDialogModuleImport( this, GetBoard()->m_Modules ); InvokeDialogImportGfxModule( this, GetBoard()->m_Modules );
m_canvas->Refresh(); m_canvas->Refresh();
} }
break; break;

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,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, jp.charras at wanadoo.fr * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-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
@ -27,71 +27,76 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include "dialog_import_gfx.h"
#include <kiface_i.h> #include <kiface_i.h>
#include <convert_to_biu.h> #include <convert_to_biu.h>
#include <confirm.h> #include <pcb_layer_box_selector.h>
#include <wildcards_and_files_ext.h>
#include <pcb_base_frame.h>
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
#include <class_edge_mod.h> #include <class_edge_mod.h>
#include <class_text_mod.h> #include <class_text_mod.h>
#include <class_pcb_text.h> #include <class_pcb_text.h>
#include <pcb_layer_box_selector.h> #include "dialog_import_gfx.h"
#include <import_gfx/graphics_importer_pcbnew.h>
// Keys to store setup in config // Keys to store setup in config
#define IMPORT_GFX_LAYER_OPTION_KEY "GfxImportBrdLayer" #define IMPORT_GFX_LAYER_OPTION_KEY "GfxImportBrdLayer"
#define IMPORT_GFX_COORD_ORIGIN_KEY "GfxImportCoordOrigin" #define IMPORT_GFX_PLACEMENT_INTERACTIVE_KEY "GfxImportPlacementInteractive"
#define IMPORT_GFX_LAST_FILE_KEY "GfxImportLastFile" #define IMPORT_GFX_LAST_FILE_KEY "GfxImportLastFile"
#define IMPORT_GFX_GRID_UNITS_KEY "GfxImportGridUnits" #define IMPORT_GFX_POSITION_UNITS_KEY "GfxImportPositionUnits"
#define IMPORT_GFX_GRID_OFFSET_X_KEY "GfxImportGridOffsetX" #define IMPORT_GFX_POSITION_X_KEY "GfxImportPositionX"
#define IMPORT_GFX_GRID_OFFSET_Y_KEY "GfxImportGridOffsetY" #define IMPORT_GFX_POSITION_Y_KEY "GfxImportPositionY"
#define IMPORT_GFX_LINEWIDTH_UNITS_KEY "GfxImportLineWidthUnits"
#define IMPORT_GFX_LINEWIDTH_KEY "GfxImportLineWidth"
// Static members of DIALOG_IMPORT_GFX, to remember the user's choices during the session // Static members of DIALOG_IMPORT_GFX, to remember
// the user's choices during the session
wxString DIALOG_IMPORT_GFX::m_filename; wxString DIALOG_IMPORT_GFX::m_filename;
int DIALOG_IMPORT_GFX::m_offsetSelection = 0; bool DIALOG_IMPORT_GFX::m_placementInteractive = true;
LAYER_NUM DIALOG_IMPORT_GFX::m_layer = Dwgs_User; LAYER_NUM DIALOG_IMPORT_GFX::m_layer = Dwgs_User;
double DIALOG_IMPORT_GFX::m_scaleImport = 1.0; // Do not change the imported items siaz
DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX( PCB_BASE_FRAME* aParent, bool aUseModuleItems ) DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX( PCB_BASE_FRAME* aParent, bool aImportAsFootprintGraphic )
: DIALOG_IMPORT_GFX_BASE( aParent ) : DIALOG_IMPORT_GFX_BASE( aParent )
{ {
m_parent = aParent; m_parent = aParent;
if( aUseModuleItems ) if( aImportAsFootprintGraphic )
m_importer.reset( new GRAPHICS_IMPORTER_MODULE( m_parent->GetBoard()->m_Modules ) ); m_importer.reset( new GRAPHICS_IMPORTER_MODULE( m_parent->GetBoard()->m_Modules ) );
else else
m_importer.reset( new GRAPHICS_IMPORTER_BOARD( m_parent->GetBoard() ) ); m_importer.reset( new GRAPHICS_IMPORTER_BOARD( m_parent->GetBoard() ) );
m_config = Kiface().KifaceSettings(); m_config = Kiface().KifaceSettings();
m_gridUnits = 0; m_originImportUnits = 0;
m_gridOffsetX = 0.0; m_importOrigin.x = 0.0; // always in mm
m_gridOffsetY = 0.0; m_importOrigin.y = 0.0; // always in mm
m_default_lineWidth = 0.2; // always in mm
m_lineWidthImportUnits = 0;
if( m_config ) if( m_config )
{ {
m_layer = m_config->Read( IMPORT_GFX_LAYER_OPTION_KEY, (long)Dwgs_User ); m_layer = m_config->Read( IMPORT_GFX_LAYER_OPTION_KEY, (long)Dwgs_User );
m_offsetSelection = m_config->Read( IMPORT_GFX_COORD_ORIGIN_KEY, (long)0 ); m_placementInteractive = m_config->Read( IMPORT_GFX_PLACEMENT_INTERACTIVE_KEY, true );
m_filename = m_config->Read( IMPORT_GFX_LAST_FILE_KEY, wxEmptyString ); m_filename = m_config->Read( IMPORT_GFX_LAST_FILE_KEY, wxEmptyString );
m_config->Read( IMPORT_GFX_GRID_UNITS_KEY, &m_gridUnits, 0 ); m_config->Read( IMPORT_GFX_LINEWIDTH_KEY, &m_default_lineWidth, 0.2 );
m_config->Read( IMPORT_GFX_GRID_OFFSET_X_KEY, &m_gridOffsetX, 0.0 ); m_config->Read( IMPORT_GFX_POSITION_UNITS_KEY, &m_originImportUnits, 0 );
m_config->Read( IMPORT_GFX_GRID_OFFSET_Y_KEY, &m_gridOffsetY, 0.0 ); m_config->Read( IMPORT_GFX_POSITION_X_KEY, &m_importOrigin.x, 0.0 );
m_config->Read( IMPORT_GFX_POSITION_Y_KEY, &m_importOrigin.y, 0.0 );
} }
m_PCBGridUnits->SetSelection( m_gridUnits ); m_choiceUnitLineWidth->SetSelection( m_lineWidthImportUnits );
wxString tmpStr; showPCBdefaultLineWidth();
tmpStr << m_gridOffsetX;
m_PCBXCoord->SetValue( tmpStr ); m_DxfPcbPositionUnits->SetSelection( m_originImportUnits );
tmpStr = ""; showPcbImportOffsets();
tmpStr << m_gridOffsetY;
m_PCBYCoord->SetValue( tmpStr );
m_textCtrlFileName->SetValue( m_filename ); m_textCtrlFileName->SetValue( m_filename );
m_rbOffsetOption->SetSelection( m_offsetSelection ); m_rbInteractivePlacement->SetValue( m_placementInteractive );
m_rbAbsolutePlacement->SetValue( not m_placementInteractive );
m_textCtrlImportScale->SetValue( wxString::Format( "%f", m_scaleImport ) );
// Configure the layers list selector // Configure the layers list selector
m_SelLayerBox->SetLayersHotkeys( false ); // Do not display hotkeys m_SelLayerBox->SetLayersHotkeys( false ); // Do not display hotkeys
@ -114,23 +119,108 @@ DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX( PCB_BASE_FRAME* aParent, bool aUseModuleIt
DIALOG_IMPORT_GFX::~DIALOG_IMPORT_GFX() DIALOG_IMPORT_GFX::~DIALOG_IMPORT_GFX()
{ {
m_offsetSelection = m_rbOffsetOption->GetSelection(); updatePcbImportOffsets_mm();
m_layer = m_SelLayerBox->GetLayerSelection(); m_layer = m_SelLayerBox->GetLayerSelection();
if( m_config ) if( m_config )
{ {
m_config->Write( IMPORT_GFX_LAYER_OPTION_KEY, (long)m_layer ); m_config->Write( IMPORT_GFX_LAYER_OPTION_KEY, (long)m_layer );
m_config->Write( IMPORT_GFX_COORD_ORIGIN_KEY, m_offsetSelection ); m_config->Write( IMPORT_GFX_PLACEMENT_INTERACTIVE_KEY, m_placementInteractive );
m_config->Write( IMPORT_GFX_LAST_FILE_KEY, m_filename ); m_config->Write( IMPORT_GFX_LAST_FILE_KEY, m_filename );
m_config->Write( IMPORT_GFX_GRID_UNITS_KEY, GetPCBGridUnits() ); m_config->Write( IMPORT_GFX_POSITION_UNITS_KEY, m_originImportUnits );
m_config->Write( IMPORT_GFX_GRID_OFFSET_X_KEY, m_PCBXCoord->GetValue() ); m_config->Write( IMPORT_GFX_POSITION_X_KEY, m_importOrigin.x );
m_config->Write( IMPORT_GFX_GRID_OFFSET_Y_KEY, m_PCBYCoord->GetValue() ); m_config->Write( IMPORT_GFX_POSITION_Y_KEY, m_importOrigin.y );
m_lineWidthImportUnits = getPCBdefaultLineWidthMM();
m_config->Write( IMPORT_GFX_LINEWIDTH_KEY, m_default_lineWidth );
m_config->Write( IMPORT_GFX_LINEWIDTH_UNITS_KEY, m_lineWidthImportUnits );
} }
} }
void DIALOG_IMPORT_GFX::OnBrowseFiles( wxCommandEvent& event ) void DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX::onUnitPositionSelection( wxCommandEvent& event )
{
// Collect last entered values:
updatePcbImportOffsets_mm();
m_originImportUnits = m_DxfPcbPositionUnits->GetSelection();;
showPcbImportOffsets();
}
double DIALOG_IMPORT_GFX::getPCBdefaultLineWidthMM()
{
double value = DoubleValueFromString( UNSCALED_UNITS, m_textCtrlLineWidth->GetValue() );
switch( m_lineWidthImportUnits )
{
default:
case 0: // display units = mm
break;
case 1: // display units = mil
value *= 25.4 / 1000;
break;
case 2: // display units = inch
value *= 25.4;
break;
}
return value; // value is in mm
}
void DIALOG_IMPORT_GFX::onUnitWidthSelection( wxCommandEvent& event )
{
m_default_lineWidth = getPCBdefaultLineWidthMM();
// Switch to new units
m_lineWidthImportUnits = m_choiceUnitLineWidth->GetSelection();
showPCBdefaultLineWidth();
}
void DIALOG_IMPORT_GFX::showPcbImportOffsets()
{
// Display m_importOrigin value according to the unit selection:
VECTOR2D offset = m_importOrigin;
if( m_originImportUnits ) // Units are inches
offset = m_importOrigin / 25.4;
m_DxfPcbXCoord->SetValue( wxString::Format( "%f", offset.x ) );
m_DxfPcbYCoord->SetValue( wxString::Format( "%f", offset.y ) );
}
void DIALOG_IMPORT_GFX::showPCBdefaultLineWidth()
{
double value;
switch( m_lineWidthImportUnits )
{
default:
case 0: // display units = mm
value = m_default_lineWidth;
break;
case 1: // display units = mil
value = m_default_lineWidth / 25.4 * 1000;
break;
case 2: // display units = inch
value = m_default_lineWidth / 25.4;
break;
}
m_textCtrlLineWidth->SetValue( wxString::Format( "%f", value ) );
}
void DIALOG_IMPORT_GFX::onBrowseFiles( wxCommandEvent& event )
{ {
wxString path; wxString path;
wxString filename; wxString filename;
@ -173,155 +263,226 @@ void DIALOG_IMPORT_GFX::OnBrowseFiles( wxCommandEvent& event )
} }
void DIALOG_IMPORT_GFX::OnOKClick( wxCommandEvent& event ) void DIALOG_IMPORT_GFX::onOKClick( wxCommandEvent& event )
{ {
m_filename = m_textCtrlFileName->GetValue(); m_filename = m_textCtrlFileName->GetValue();
if( m_filename.IsEmpty() ) if( m_filename.IsEmpty() )
return;
double offsetX = 0;
double offsetY = 0;
m_offsetSelection = m_rbOffsetOption->GetSelection();
switch( m_offsetSelection )
{ {
case 0: wxMessageBox( _( "Error: No DXF filename!" ) );
offsetX = m_parent->GetPageSizeIU().x * MM_PER_IU / 2; return;
offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU / 2;
break;
case 1:
break;
case 2:
offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU / 2;
break;
case 3:
offsetY = m_parent->GetPageSizeIU().y * MM_PER_IU;
break;
case 4:
GetPCBGridOffsets( offsetX, offsetY );
if( GetPCBGridUnits() )
{
offsetX *= 25.4;
offsetY *= 25.4;
}
break;
} }
// Set coordinates offset for import (offset is given in mm) updatePcbImportOffsets_mm(); // Update m_importOriginX and m_importOriginY;
//m_importer.SetOffset( offsetX, offsetY );
m_layer = m_SelLayerBox->GetLayerSelection(); m_layer = m_SelLayerBox->GetLayerSelection();
if( m_layer < 0 )
{
wxMessageBox( _( "Please, select a valid layer " ) );
return;
}
m_default_lineWidth = getPCBdefaultLineWidthMM();
m_importer->SetLayer( PCB_LAYER_ID( m_layer ) ); m_importer->SetLayer( PCB_LAYER_ID( m_layer ) );
auto plugin = GRAPHICS_IMPORT_MGR::GetPluginByExt( wxFileName( m_filename ).GetExt() ); auto plugin = GRAPHICS_IMPORT_MGR::GetPluginByExt( wxFileName( m_filename ).GetExt() );
if( plugin ) if( plugin )
{ {
m_importer->SetScale( 1.0 /*1e6*/ ); // mm -> IU @todo: add a setting in the dialog and apply it here // Set coordinates offset for import (offset is given in mm)
m_importer->SetLineWidth( 0.1 * 1e6 ); // @todo add a setting in the dialog and apply it here m_importer->SetImportOffsetMM( m_importOrigin );
m_scaleImport = DoubleValueFromString( UNSCALED_UNITS, m_textCtrlImportScale->GetValue() );
m_importer->SetLineWidthMM( m_default_lineWidth );
m_importer->SetPlugin( std::move( plugin ) ); m_importer->SetPlugin( std::move( plugin ) );
if( m_importer->Load( m_filename ) ) LOCALE_IO dummy; // Ensure floats can be read.
m_importer->Import( 1.0, 1.0 ); // @todo
EndModal( wxID_OK ); if( m_importer->Load( m_filename ) )
m_importer->Import( m_scaleImport );
// Get warning messages:
const std::string& warnings = m_importer->GetMessages();
if( !warnings.empty() )
wxMessageBox( warnings.c_str(), _( "Not Handled Items" ) );
event.Skip();
} }
else else
{ {
DisplayError( this, _( "There is no plugin to handle this file type" ) ); wxMessageBox( _( "There is no plugin to handle this file type" ) );
} }
} }
void DIALOG_IMPORT_GFX::onChangeHeight( wxUpdateUIEvent &event)
{
// @todo: implement scaling of Y
#if 0
double heightInput = DoubleValueFromString(UNSCALED_UNITS,m_tcHeight->GetValue());
if(m_cbKeepAspectRatio->GetValue()) // Used only in legacy canvas by the board editor.
{
}
#endif
}
#if 0
// Must be reworked (perhaps removed) because this is not used in GAL canvases
// only in legacy canvas.
bool InvokeDialogImportGfxBoard( PCB_BASE_FRAME* aCaller ) bool InvokeDialogImportGfxBoard( PCB_BASE_FRAME* aCaller )
{ {
DIALOG_IMPORT_GFX dlg( aCaller ); DIALOG_IMPORT_GFX dlg( aCaller );
bool success = ( dlg.ShowModal() == wxID_OK );
if( success ) if( dlg.ShowModal() != wxID_OK )
return false;
auto& list = dlg.GetImportedItems();
// Ensure the list is not empty:
if( list.empty() )
{ {
PICKED_ITEMS_LIST picklist; wxMessageBox( _( "No graphic items found in file to import") );
BOARD* board = aCaller->GetBoard(); return false;
auto& items = dlg.GetImportedItems();
for( auto it = items.begin(); it != items.end(); ++it )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->release() );
board->Add( item );
ITEM_PICKER itemWrapper( item, UR_NEW );
picklist.PushItem( itemWrapper );
}
aCaller->SaveCopyInUndoList( picklist, UR_NEW, wxPoint( 0, 0 ) );
aCaller->OnModify();
} }
return success; PICKED_ITEMS_LIST picklist; // the pick list for undo command
ITEM_PICKER item_picker( nullptr, UR_NEW );
BOARD* board = aCaller->GetBoard();
// Now prepare a block move command to place the new items, if interactive placement,
// and prepare the undo command.
EDA_RECT bbox; // the new items bounding box, for block move if interactive placement.
bool bboxInit = true; // true until the bounding box is initialized
BLOCK_SELECTOR& blockmove = aCaller->GetScreen()->m_BlockLocate;
if( dlg.IsPlacementInteractive() )
aCaller->HandleBlockBegin( NULL, BLOCK_PRESELECT_MOVE, wxPoint( 0, 0) );
PICKED_ITEMS_LIST& blockitemsList = blockmove.GetItems();
for( auto it = list.begin(); it != list.end(); ++it )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->release() );
if( dlg.IsPlacementInteractive() )
item->SetFlags( IS_MOVED );
board->Add( item );
item_picker.SetItem( item );
picklist.PushItem( item_picker );
if( dlg.IsPlacementInteractive() )
{
blockitemsList.PushItem( item_picker );
if( bboxInit )
bbox = item->GetBoundingBox();
else
bbox.Merge( item->GetBoundingBox() );
bboxInit = false;
}
}
aCaller->SaveCopyInUndoList( picklist, UR_NEW, wxPoint( 0, 0 ) );
aCaller->OnModify();
if( dlg.IsPlacementInteractive() )
{
// Finish block move command:
wxPoint cpos = aCaller->GetNearestGridPosition( bbox.Centre() );
blockmove.SetOrigin( bbox.GetOrigin() );
blockmove.SetSize( bbox.GetSize() );
blockmove.SetLastCursorPosition( cpos );
aCaller->HandleBlockEnd( NULL );
}
return true;
} }
// Used only in legacy canvas by the footprint editor.
bool InvokeDialogImportGfxModule( PCB_BASE_FRAME* aCaller, MODULE* aModule ) bool InvokeDialogImportGfxModule( PCB_BASE_FRAME* aCaller, MODULE* aModule )
{ {
wxASSERT( aModule ); if( !aModule )
return false;
DIALOG_IMPORT_GFX dlg( aCaller, true ); DIALOG_IMPORT_GFX dlg( aCaller, true );
bool success = ( dlg.ShowModal() == wxID_OK );
if( success ) if( dlg.ShowModal() != wxID_OK )
return false;
auto& list = dlg.GetImportedItems();
// Ensure the list is not empty:
if( list.empty() )
{ {
aCaller->SaveCopyInUndoList( aModule, UR_CHANGED ); wxMessageBox( _( "No graphic items found in file to import") );
aCaller->OnModify(); return false;
auto& list = dlg.GetImportedItems();
for( auto it = list.begin(); it != list.end(); ++it )
{
aModule->Add( static_cast<BOARD_ITEM*>( it->release() ) );
}
} }
return success; aCaller->SaveCopyInUndoList( aModule, UR_CHANGED );
}
#endif
void DIALOG_IMPORT_GFX::OriginOptionOnUpdateUI( wxUpdateUIEvent& event ) PICKED_ITEMS_LIST picklist; // the pick list for undo command
{ ITEM_PICKER item_picker( nullptr, UR_NEW );
bool enable = m_rbOffsetOption->GetSelection() == 4;
m_PCBGridUnits->Enable( enable ); // Now prepare a block move command to place the new items, if interactive placement,
m_PCBXCoord->Enable( enable ); // and prepare the undo command.
m_PCBYCoord->Enable( enable ); EDA_RECT bbox; // the new items bounding box, for block move if interactive placement.
bool bboxInit = true; // true until the bounding box is initialized
BLOCK_SELECTOR& blockmove = aCaller->GetScreen()->m_BlockLocate;
if( dlg.IsPlacementInteractive() )
aCaller->HandleBlockBegin( nullptr, BLOCK_PRESELECT_MOVE, wxPoint( 0, 0) );
PICKED_ITEMS_LIST& blockitemsList = blockmove.GetItems();
for( auto it = list.begin(); it != list.end(); ++it )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->release() );
aModule->Add( item );
if( dlg.IsPlacementInteractive() )
{
item->SetFlags( IS_MOVED );
item_picker.SetItem( item );
blockitemsList.PushItem( item_picker );
if( bboxInit )
bbox = item->GetBoundingBox();
else
bbox.Merge( item->GetBoundingBox() );
bboxInit = false;
}
}
aCaller->OnModify();
if( dlg.IsPlacementInteractive() )
{
// Finish block move command:
wxPoint cpos = aCaller->GetNearestGridPosition( bbox.Centre() );
blockmove.SetOrigin( bbox.GetOrigin() );
blockmove.SetSize( bbox.GetSize() );
blockmove.SetLastCursorPosition( cpos );
aCaller->HandleBlockEnd( NULL );
}
return true;
} }
int DIALOG_IMPORT_GFX::GetPCBGridUnits( void ) void DIALOG_IMPORT_GFX::originOptionOnUpdateUI( wxUpdateUIEvent& event )
{ {
return m_PCBGridUnits->GetSelection(); m_rbInteractivePlacement->SetValue( m_placementInteractive );
m_rbAbsolutePlacement->SetValue( not m_placementInteractive );
m_DxfPcbPositionUnits->Enable( not m_placementInteractive );
m_DxfPcbXCoord->Enable( not m_placementInteractive );
m_DxfPcbYCoord->Enable( not m_placementInteractive );
} }
void DIALOG_IMPORT_GFX::GetPCBGridOffsets( double &aXOffset, double &aYOffset ) void DIALOG_IMPORT_GFX::updatePcbImportOffsets_mm()
{ {
aXOffset = DoubleValueFromString( UNSCALED_UNITS, m_PCBXCoord->GetValue() ); m_importOrigin.x = DoubleValueFromString( UNSCALED_UNITS, m_DxfPcbXCoord->GetValue() );
aYOffset = DoubleValueFromString( UNSCALED_UNITS, m_PCBYCoord->GetValue() ); m_importOrigin.y = DoubleValueFromString( UNSCALED_UNITS, m_DxfPcbYCoord->GetValue() );
if( m_originImportUnits ) // Units are inches
{
m_importOrigin = m_importOrigin * 25.4;
}
return; return;
} }

View File

@ -22,47 +22,68 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <pcb_edit_frame.h>
#include "dialog_import_gfx_base.h" #include "dialog_import_gfx_base.h"
#include <import_gfx/graphics_importer_pcbnew.h> #include <import_gfx/graphics_importer_pcbnew.h>
class PCB_BASE_FRAME;
class DIALOG_IMPORT_GFX : public DIALOG_IMPORT_GFX_BASE class DIALOG_IMPORT_GFX : public DIALOG_IMPORT_GFX_BASE
{ {
public: public:
DIALOG_IMPORT_GFX( PCB_BASE_FRAME* aParent, bool aUseModuleItems = false ); DIALOG_IMPORT_GFX( PCB_BASE_FRAME* aParent, bool aUseModuleItems = false );
~DIALOG_IMPORT_GFX(); ~DIALOG_IMPORT_GFX();
/** /**
* Function GetImportedItems() * Function GetImportedItems()
* * @return a list of items imported from a vector graphics file.
* Returns a list of items imported from a vector graphics file.
*/ */
std::list<std::unique_ptr<EDA_ITEM>>& GetImportedItems() std::list<std::unique_ptr<EDA_ITEM>>& GetImportedItems()
{ {
return m_importer->GetItems(); return m_importer->GetItems();
} }
/** @return true if the placement is interactive, i.e. all imported
* items must be moved by the mouse cursor to the final position
* false means the imported items are placed to the final position after import.
*/
bool IsPlacementInteractive()
{
return m_placementInteractive;
}
private: private:
PCB_BASE_FRAME* m_parent; PCB_BASE_FRAME* m_parent;
wxConfigBase* m_config; // Current config wxConfigBase* m_config; // Current config
std::unique_ptr<GRAPHICS_IMPORTER_PCBNEW> m_importer; std::unique_ptr<GRAPHICS_IMPORTER_PCBNEW> m_importer;
int m_gridUnits; int m_originImportUnits;
double m_gridOffsetX; VECTOR2D m_importOrigin; // This is the offset to add to imported coordinates
double m_gridOffsetY; // Always in mm
double m_newHeight;
double m_newWidth;
static wxString m_filename; static wxString m_filename;
static int m_offsetSelection; static bool m_placementInteractive;
static LAYER_NUM m_layer; static LAYER_NUM m_layer;
double m_default_lineWidth; // always in mm: line width when a line width is not specified
int m_lineWidthImportUnits;
static double m_scaleImport; // a scale factor to change the size of imported items
// m_scaleImport =1.0 means keep original size
// Virtual event handlers // Virtual event handlers
void OnCancelClick( wxCommandEvent& event ) override { event.Skip(); } void onOKClick( wxCommandEvent& event ) override;
void OnOKClick( wxCommandEvent& event ) override; void onUnitPositionSelection( wxCommandEvent& event ) override;
void OnBrowseFiles( wxCommandEvent& event ) override; void onUnitWidthSelection( wxCommandEvent& event ) override;
void OriginOptionOnUpdateUI( wxUpdateUIEvent& event ) override; void onBrowseFiles( wxCommandEvent& event ) override;
void onChangeHeight( wxUpdateUIEvent& event ) override; void originOptionOnUpdateUI( wxUpdateUIEvent& event ) override;
int GetPCBGridUnits( void ); void onInteractivePlacement( wxCommandEvent& event ) override
void GetPCBGridOffsets( double &aXOffset, double &aYOffset ); {
m_placementInteractive = true;
}
void onAbsolutePlacement( wxCommandEvent& event ) override
{
m_placementInteractive = false;
}
void updatePcbImportOffsets_mm();
double getPCBdefaultLineWidthMM();
void showPCBdefaultLineWidth();
void showPcbImportOffsets();
}; };

View File

@ -21,9 +21,9 @@ DIALOG_IMPORT_GFX_BASE::DIALOG_IMPORT_GFX_BASE( wxWindow* parent, wxWindowID id,
wxBoxSizer* bSizerFile; wxBoxSizer* bSizerFile;
bSizerFile = new wxBoxSizer( wxHORIZONTAL ); bSizerFile = new wxBoxSizer( wxHORIZONTAL );
m_staticText37 = new wxStaticText( this, wxID_ANY, _("File:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextFile = new wxStaticText( this, wxID_ANY, _("File:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText37->Wrap( -1 ); m_staticTextFile->Wrap( -1 );
bSizerFile->Add( m_staticText37, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); bSizerFile->Add( m_staticTextFile, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_textCtrlFileName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); m_textCtrlFileName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_textCtrlFileName->SetMinSize( wxSize( 300,-1 ) ); m_textCtrlFileName->SetMinSize( wxSize( 300,-1 ) );
@ -36,122 +36,163 @@ DIALOG_IMPORT_GFX_BASE::DIALOG_IMPORT_GFX_BASE( wxWindow* parent, wxWindowID id,
bSizerMain->Add( bSizerFile, 0, wxALL|wxEXPAND, 5 ); bSizerMain->Add( bSizerFile, 0, wxALL|wxEXPAND, 5 );
wxBoxSizer* bSizer10; m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizer10 = new wxBoxSizer( wxVERTICAL ); bSizerMain->Add( m_staticline2, 0, wxEXPAND | wxALL, 5 );
wxBoxSizer* bSizer5; wxBoxSizer* bSizerPlacement;
bSizer5 = new wxBoxSizer( wxHORIZONTAL ); bSizerPlacement = new wxBoxSizer( wxVERTICAL );
m_staticText3 = new wxStaticText( this, wxID_ANY, _("Units:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextPlacement = new wxStaticText( this, wxID_ANY, _("Placement:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText3->Wrap( -1 ); m_staticTextPlacement->Wrap( -1 );
bSizer5->Add( m_staticText3, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); m_staticTextPlacement->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) );
wxString m_PCBGridUnitsChoices[] = { _("mm"), _("inch") }; bSizerPlacement->Add( m_staticTextPlacement, 0, wxALL, 5 );
int m_PCBGridUnitsNChoices = sizeof( m_PCBGridUnitsChoices ) / sizeof( wxString );
m_PCBGridUnits = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_PCBGridUnitsNChoices, m_PCBGridUnitsChoices, 0 );
m_PCBGridUnits->SetSelection( 0 );
m_PCBGridUnits->SetToolTip( _("Select PCB grid units") );
bSizer5->Add( m_PCBGridUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxBoxSizer* bSizerOptions;
bSizerOptions = new wxBoxSizer( wxVERTICAL );
m_rbInteractivePlacement = new wxRadioButton( this, wxID_ANY, _("Interactive placement"), wxDefaultPosition, wxDefaultSize, wxRB_SINGLE );
m_rbInteractivePlacement->SetValue( true );
bSizerOptions->Add( m_rbInteractivePlacement, 0, wxALL, 5 );
bSizer10->Add( bSizer5, 0, wxALL|wxEXPAND, 5 ); wxBoxSizer* bSizerUserPos;
bSizerUserPos = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* bSizer3; m_rbAbsolutePlacement = new wxRadioButton( this, wxID_ANY, _("At"), wxDefaultPosition, wxDefaultSize, wxRB_SINGLE );
bSizer3 = new wxBoxSizer( wxHORIZONTAL ); bSizerUserPos->Add( m_rbAbsolutePlacement, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
wxString m_rbOffsetOptionChoices[] = { _("Center of page"), _("Upper left corner of page"), _("Center left side of page"), _("Lower left corner of page"), _("User defined position") }; wxBoxSizer* bSizerPosSettings;
int m_rbOffsetOptionNChoices = sizeof( m_rbOffsetOptionChoices ) / sizeof( wxString ); bSizerPosSettings = new wxBoxSizer( wxHORIZONTAL );
m_rbOffsetOption = new wxRadioBox( this, wxID_ORIGIN_SELECT, _("Place origin (0,0) point:"), wxDefaultPosition, wxDefaultSize, m_rbOffsetOptionNChoices, m_rbOffsetOptionChoices, 1, wxRA_SPECIFY_COLS );
m_rbOffsetOption->SetSelection( 0 );
bSizer3->Add( m_rbOffsetOption, 0, wxALL|wxEXPAND, 5 );
wxBoxSizer* bSizer4; m_staticTextXpos = new wxStaticText( this, wxID_ANY, _("X:"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer4 = new wxBoxSizer( wxVERTICAL ); m_staticTextXpos->Wrap( -1 );
bSizerPosSettings->Add( m_staticTextXpos, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxLEFT, 5 );
wxBoxSizer* bSizer6; m_DxfPcbXCoord = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bSizer6 = new wxBoxSizer( wxHORIZONTAL );
m_staticText4 = new wxStaticText( this, wxID_ANY, _("X Position:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText4->Wrap( -1 );
bSizer6->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_PCBXCoord = new wxTextCtrl( this, wxID_ANY, _("0.0"), wxDefaultPosition, wxDefaultSize, 0 );
#ifdef __WXGTK__ #ifdef __WXGTK__
if ( !m_PCBXCoord->HasFlag( wxTE_MULTILINE ) ) if ( !m_DxfPcbXCoord->HasFlag( wxTE_MULTILINE ) )
{ {
m_PCBXCoord->SetMaxLength( 10 ); m_DxfPcbXCoord->SetMaxLength( 10 );
} }
#else #else
m_PCBXCoord->SetMaxLength( 10 ); m_DxfPcbXCoord->SetMaxLength( 10 );
#endif #endif
m_PCBXCoord->SetToolTip( _("DXF origin on PCB Grid, X Coordinate") ); m_DxfPcbXCoord->SetToolTip( _("DXF origin on PCB Grid, X Coordinate") );
bSizer6->Add( m_PCBXCoord, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); bSizerPosSettings->Add( m_DxfPcbXCoord, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_staticTextYpos = new wxStaticText( this, wxID_ANY, _("Y:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextYpos->Wrap( -1 );
bSizerPosSettings->Add( m_staticTextYpos, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 );
m_DxfPcbYCoord = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
#ifdef __WXGTK__
if ( !m_DxfPcbYCoord->HasFlag( wxTE_MULTILINE ) )
{
m_DxfPcbYCoord->SetMaxLength( 10 );
}
#else
m_DxfPcbYCoord->SetMaxLength( 10 );
#endif
m_DxfPcbYCoord->SetToolTip( _("DXF origin on PCB Grid, Y Coordinate") );
bSizerPosSettings->Add( m_DxfPcbYCoord, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_staticTextUnits = new wxStaticText( this, wxID_ANY, _("Units:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextUnits->Wrap( -1 );
bSizerPosSettings->Add( m_staticTextUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
wxString m_DxfPcbPositionUnitsChoices[] = { _("mm"), _("inch") };
int m_DxfPcbPositionUnitsNChoices = sizeof( m_DxfPcbPositionUnitsChoices ) / sizeof( wxString );
m_DxfPcbPositionUnits = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_DxfPcbPositionUnitsNChoices, m_DxfPcbPositionUnitsChoices, 0 );
m_DxfPcbPositionUnits->SetSelection( 0 );
m_DxfPcbPositionUnits->SetToolTip( _("Select PCB grid units") );
bSizerPosSettings->Add( m_DxfPcbPositionUnits, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 );
bSizer4->Add( bSizer6, 1, wxEXPAND, 5 ); bSizerUserPos->Add( bSizerPosSettings, 1, wxEXPAND|wxTOP|wxBOTTOM, 5 );
bSizerOptions->Add( bSizerUserPos, 0, wxEXPAND, 5 );
bSizerPlacement->Add( bSizerOptions, 1, wxEXPAND|wxLEFT, 20 );
bSizerMain->Add( bSizerPlacement, 1, wxEXPAND, 5 );
m_staticline3 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerMain->Add( m_staticline3, 0, wxEXPAND | wxALL, 5 );
wxBoxSizer* bSizerLayer;
bSizerLayer = new wxBoxSizer( wxVERTICAL );
m_staticTextPrms = new wxStaticText( this, wxID_ANY, _("Import parameters:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextPrms->Wrap( -1 );
m_staticTextPrms->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) );
bSizerLayer->Add( m_staticTextPrms, 0, wxALL, 5 );
wxBoxSizer* bSizer7; wxBoxSizer* bSizer7;
bSizer7 = new wxBoxSizer( wxHORIZONTAL ); bSizer7 = new wxBoxSizer( wxHORIZONTAL );
m_staticText5 = new wxStaticText( this, wxID_ANY, _("Y Position:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText5->Wrap( -1 );
bSizer7->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_PCBYCoord = new wxTextCtrl( this, wxID_ANY, _("0.0"), wxDefaultPosition, wxDefaultSize, 0 ); bSizer7->Add( 0, 0, 0, wxRIGHT|wxLEFT, 10 );
#ifdef __WXGTK__
if ( !m_PCBYCoord->HasFlag( wxTE_MULTILINE ) )
{
m_PCBYCoord->SetMaxLength( 10 );
}
#else
m_PCBYCoord->SetMaxLength( 10 );
#endif
m_PCBYCoord->SetToolTip( _("DXF origin on PCB Grid, Y Coordinate") );
bSizer7->Add( m_PCBYCoord, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxFlexGridSizer* fgSizerImportSettings;
fgSizerImportSettings = new wxFlexGridSizer( 0, 3, 0, 0 );
fgSizerImportSettings->AddGrowableCol( 1 );
fgSizerImportSettings->SetFlexibleDirection( wxBOTH );
fgSizerImportSettings->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_staticTextLineWidth = new wxStaticText( this, wxID_ANY, _("Line width (DXF import):"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextLineWidth->Wrap( -1 );
fgSizerImportSettings->Add( m_staticTextLineWidth, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
bSizer4->Add( bSizer7, 1, wxEXPAND, 5 ); m_textCtrlLineWidth = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerImportSettings->Add( m_textCtrlLineWidth, 0, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 );
wxBoxSizer* bSizer11; wxString m_choiceUnitLineWidthChoices[] = { _("mm"), _("mils"), _("inches") };
bSizer11 = new wxBoxSizer( wxHORIZONTAL ); int m_choiceUnitLineWidthNChoices = sizeof( m_choiceUnitLineWidthChoices ) / sizeof( wxString );
m_choiceUnitLineWidth = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceUnitLineWidthNChoices, m_choiceUnitLineWidthChoices, 0 );
m_choiceUnitLineWidth->SetSelection( 0 );
fgSizerImportSettings->Add( m_choiceUnitLineWidth, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_staticTextScale = new wxStaticText( this, wxID_ANY, _("Scale:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextBrdlayer = new wxStaticText( this, wxID_ANY, _("Graphic layer:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextScale->Wrap( -1 );
bSizer11->Add( m_staticTextScale, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
m_tcScale = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
bSizer11->Add( m_tcScale, 0, wxALIGN_CENTER_VERTICAL, 5 );
bSizer4->Add( bSizer11, 0, wxALL|wxEXPAND, 5 );
bSizer3->Add( bSizer4, 1, wxALIGN_CENTER_VERTICAL, 5 );
bSizer10->Add( bSizer3, 0, wxALL|wxEXPAND, 5 );
bSizerMain->Add( bSizer10, 1, wxALL|wxEXPAND, 5 );
wxBoxSizer* bSizer8;
bSizer8 = new wxBoxSizer( wxHORIZONTAL );
m_staticTextBrdlayer = new wxStaticText( this, wxID_ANY, _("Layer:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextBrdlayer->Wrap( -1 ); m_staticTextBrdlayer->Wrap( -1 );
bSizer8->Add( m_staticTextBrdlayer, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP, 5 ); fgSizerImportSettings->Add( m_staticTextBrdlayer, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxTOP, 5 );
m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 ); m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
bSizer8->Add( m_SelLayerBox, 1, wxALL|wxEXPAND, 5 ); fgSizerImportSettings->Add( m_SelLayerBox, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxEXPAND, 5 );
bSizerMain->Add( bSizer8, 0, wxALL|wxEXPAND, 5 ); fgSizerImportSettings->Add( 0, 0, 0, 0, 5 );
m_staticline8 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); m_staticTextscale = new wxStaticText( this, wxID_ANY, _("Import scale:"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerMain->Add( m_staticline8, 0, wxALL|wxEXPAND, 5 ); m_staticTextscale->Wrap( -1 );
fgSizerImportSettings->Add( m_staticTextscale, 0, wxALL, 5 );
m_textCtrlImportScale = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgSizerImportSettings->Add( m_textCtrlImportScale, 0, wxALL|wxEXPAND, 5 );
fgSizerImportSettings->Add( 0, 0, 0, 0, 5 );
bSizer7->Add( fgSizerImportSettings, 1, wxEXPAND, 5 );
bSizerLayer->Add( bSizer7, 1, wxEXPAND, 5 );
bSizerMain->Add( bSizerLayer, 0, wxALL|wxEXPAND, 5 );
bSizerMain->Add( 0, 0, 1, wxEXPAND, 5 );
m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
bSizerMain->Add( m_staticline, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 );
m_sdbSizer = new wxStdDialogButtonSizer(); m_sdbSizer = new wxStdDialogButtonSizer();
m_sdbSizerOK = new wxButton( this, wxID_OK ); m_sdbSizerOK = new wxButton( this, wxID_OK );
@ -160,30 +201,35 @@ DIALOG_IMPORT_GFX_BASE::DIALOG_IMPORT_GFX_BASE( wxWindow* parent, wxWindowID id,
m_sdbSizer->AddButton( m_sdbSizerCancel ); m_sdbSizer->AddButton( m_sdbSizerCancel );
m_sdbSizer->Realize(); m_sdbSizer->Realize();
bSizerMain->Add( m_sdbSizer, 0, wxALIGN_RIGHT|wxBOTTOM|wxLEFT|wxRIGHT, 5 ); bSizerMain->Add( m_sdbSizer, 0, wxEXPAND|wxALL, 5 );
this->SetSizer( bSizerMain ); this->SetSizer( bSizerMain );
this->Layout(); this->Layout();
bSizerMain->Fit( this );
this->Centre( wxBOTH ); this->Centre( wxBOTH );
// Connect Events // Connect Events
m_buttonBrowse->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::OnBrowseFiles ), NULL, this ); m_buttonBrowse->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onBrowseFiles ), NULL, this );
m_rbOffsetOption->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_IMPORT_GFX_BASE::OriginOptionOnUpdateUI ), NULL, this ); m_rbInteractivePlacement->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onInteractivePlacement ), NULL, this );
m_tcScale->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_IMPORT_GFX_BASE::onChangeHeight ), NULL, this ); m_rbInteractivePlacement->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_IMPORT_GFX_BASE::originOptionOnUpdateUI ), NULL, this );
m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::OnCancelClick ), NULL, this ); m_rbAbsolutePlacement->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onAbsolutePlacement ), NULL, this );
m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::OnOKClick ), NULL, this ); m_rbAbsolutePlacement->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_IMPORT_GFX_BASE::originOptionOnUpdateUI ), NULL, this );
m_DxfPcbPositionUnits->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onUnitPositionSelection ), NULL, this );
m_choiceUnitLineWidth->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onUnitWidthSelection ), NULL, this );
m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onOKClick ), NULL, this );
} }
DIALOG_IMPORT_GFX_BASE::~DIALOG_IMPORT_GFX_BASE() DIALOG_IMPORT_GFX_BASE::~DIALOG_IMPORT_GFX_BASE()
{ {
// Disconnect Events // Disconnect Events
m_buttonBrowse->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::OnBrowseFiles ), NULL, this ); m_buttonBrowse->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onBrowseFiles ), NULL, this );
m_rbOffsetOption->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_IMPORT_GFX_BASE::OriginOptionOnUpdateUI ), NULL, this ); m_rbInteractivePlacement->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onInteractivePlacement ), NULL, this );
m_tcScale->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_IMPORT_GFX_BASE::onChangeHeight ), NULL, this ); m_rbInteractivePlacement->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_IMPORT_GFX_BASE::originOptionOnUpdateUI ), NULL, this );
m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::OnCancelClick ), NULL, this ); m_rbAbsolutePlacement->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onAbsolutePlacement ), NULL, this );
m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::OnOKClick ), NULL, this ); m_rbAbsolutePlacement->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_IMPORT_GFX_BASE::originOptionOnUpdateUI ), NULL, this );
m_DxfPcbPositionUnits->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onUnitPositionSelection ), NULL, this );
m_choiceUnitLineWidth->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onUnitWidthSelection ), NULL, this );
m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_IMPORT_GFX_BASE::onOKClick ), NULL, this );
} }

File diff suppressed because it is too large Load Diff

View File

@ -26,16 +26,15 @@ class PCB_LAYER_BOX_SELECTOR;
#include <wx/icon.h> #include <wx/icon.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/choice.h>
#include <wx/radiobox.h>
#include <wx/valtext.h>
#include <wx/bmpcbox.h>
#include <wx/statline.h> #include <wx/statline.h>
#include <wx/radiobut.h>
#include <wx/valtext.h>
#include <wx/choice.h>
#include <wx/bmpcbox.h>
#include <wx/dialog.h> #include <wx/dialog.h>
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#define wxID_ORIGIN_SELECT 1000
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_IMPORT_GFX_BASE /// Class DIALOG_IMPORT_GFX_BASE
@ -45,36 +44,46 @@ class DIALOG_IMPORT_GFX_BASE : public DIALOG_SHIM
private: private:
protected: protected:
wxStaticText* m_staticText37; wxStaticText* m_staticTextFile;
wxTextCtrl* m_textCtrlFileName; wxTextCtrl* m_textCtrlFileName;
wxButton* m_buttonBrowse; wxButton* m_buttonBrowse;
wxStaticText* m_staticText3; wxStaticLine* m_staticline2;
wxChoice* m_PCBGridUnits; wxStaticText* m_staticTextPlacement;
wxRadioBox* m_rbOffsetOption; wxRadioButton* m_rbInteractivePlacement;
wxStaticText* m_staticText4; wxRadioButton* m_rbAbsolutePlacement;
wxTextCtrl* m_PCBXCoord; wxStaticText* m_staticTextXpos;
wxStaticText* m_staticText5; wxTextCtrl* m_DxfPcbXCoord;
wxTextCtrl* m_PCBYCoord; wxStaticText* m_staticTextYpos;
wxStaticText* m_staticTextScale; wxTextCtrl* m_DxfPcbYCoord;
wxTextCtrl* m_tcScale; wxStaticText* m_staticTextUnits;
wxChoice* m_DxfPcbPositionUnits;
wxStaticLine* m_staticline3;
wxStaticText* m_staticTextPrms;
wxStaticText* m_staticTextLineWidth;
wxTextCtrl* m_textCtrlLineWidth;
wxChoice* m_choiceUnitLineWidth;
wxStaticText* m_staticTextBrdlayer; wxStaticText* m_staticTextBrdlayer;
PCB_LAYER_BOX_SELECTOR* m_SelLayerBox; PCB_LAYER_BOX_SELECTOR* m_SelLayerBox;
wxStaticLine* m_staticline8; wxStaticText* m_staticTextscale;
wxTextCtrl* m_textCtrlImportScale;
wxStaticLine* m_staticline;
wxStdDialogButtonSizer* m_sdbSizer; wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK; wxButton* m_sdbSizerOK;
wxButton* m_sdbSizerCancel; wxButton* m_sdbSizerCancel;
// Virtual event handlers, overide them in your derived class // Virtual event handlers, overide them in your derived class
virtual void OnBrowseFiles( wxCommandEvent& event ) { event.Skip(); } virtual void onBrowseFiles( wxCommandEvent& event ) { event.Skip(); }
virtual void OriginOptionOnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } virtual void onInteractivePlacement( wxCommandEvent& event ) { event.Skip(); }
virtual void onChangeHeight( wxUpdateUIEvent& event ) { event.Skip(); } virtual void originOptionOnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); } virtual void onAbsolutePlacement( wxCommandEvent& event ) { event.Skip(); }
virtual void OnOKClick( wxCommandEvent& event ) { event.Skip(); } virtual void onUnitPositionSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void onUnitWidthSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void onOKClick( wxCommandEvent& event ) { event.Skip(); }
public: public:
DIALOG_IMPORT_GFX_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Import vector graphics file"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); DIALOG_IMPORT_GFX_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Import vector graphics file"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 476,373 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_IMPORT_GFX_BASE(); ~DIALOG_IMPORT_GFX_BASE();
}; };

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) 1992-2018 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
@ -42,10 +42,20 @@
#include <class_text_mod.h> #include <class_text_mod.h>
#include "common.h" #include "common.h"
/*
* Important note: all DXF coordinates and sizes are converted to mm.
* they will be converted to internal units later.
*/
// minimum bulge value before resorting to a line segment; // minimum bulge value before resorting to a line segment;
// the value 0.0218 is equivalent to about 5 degrees arc, // the value 0.0218 is equivalent to about 5 degrees arc,
#define MIN_BULGE 0.0218 #define MIN_BULGE 0.0218
//#define SCALE_FACTOR(x) millimeter2iu(x) /* no longer used */
#define SCALE_FACTOR(x) (x)
DXF_IMPORT_PLUGIN::DXF_IMPORT_PLUGIN() : DL_CreationAdapter() DXF_IMPORT_PLUGIN::DXF_IMPORT_PLUGIN() : DL_CreationAdapter()
{ {
m_xOffset = 0.0; // X coord offset for conversion (in mm) m_xOffset = 0.0; // X coord offset for conversion (in mm)
@ -55,10 +65,8 @@ DXF_IMPORT_PLUGIN::DXF_IMPORT_PLUGIN() : DL_CreationAdapter()
m_defaultThickness = 0.2; // default thickness (in mm) m_defaultThickness = 0.2; // default thickness (in mm)
m_brdLayer = Dwgs_User; // The default import layer m_brdLayer = Dwgs_User; // The default import layer
m_importAsfootprintGraphicItems = true; m_importAsfootprintGraphicItems = true;
m_minX = std::numeric_limits<int>::max(); m_minX = m_minY = std::numeric_limits<double>::max();
m_maxX = std::numeric_limits<int>::min(); m_maxX = m_maxY = std::numeric_limits<double>::min();
m_minY = std::numeric_limits<int>::max();
m_maxY = std::numeric_limits<int>::min();
} }
@ -73,7 +81,7 @@ bool DXF_IMPORT_PLUGIN::Load( const wxString& aFileName )
} }
bool DXF_IMPORT_PLUGIN::Import( float aXScale, float aYScale ) bool DXF_IMPORT_PLUGIN::Import()
{ {
wxCHECK( m_importer, false ); wxCHECK( m_importer, false );
m_internalImporter.ImportTo( *m_importer ); m_internalImporter.ImportTo( *m_importer );
@ -82,43 +90,45 @@ bool DXF_IMPORT_PLUGIN::Import( float aXScale, float aYScale )
} }
unsigned int DXF_IMPORT_PLUGIN::GetImageWidth() const { double DXF_IMPORT_PLUGIN::GetImageWidth() const
{
return m_maxX - m_minX; return m_maxX - m_minX;
} }
unsigned int DXF_IMPORT_PLUGIN::GetImageHeight() const { double DXF_IMPORT_PLUGIN::GetImageHeight() const
{
return m_maxY - m_minY; return m_maxY - m_minY;
} }
// coordinate conversions from dxf to internal units // coordinate conversions from dxf to internal units
int DXF_IMPORT_PLUGIN::mapX( double aDxfCoordX ) double DXF_IMPORT_PLUGIN::mapX( double aDxfCoordX )
{ {
return Millimeter2iu( m_xOffset + ( aDxfCoordX * m_DXF2mm ) ); return SCALE_FACTOR( m_xOffset + ( aDxfCoordX * m_DXF2mm ) );
} }
int DXF_IMPORT_PLUGIN::mapY( double aDxfCoordY ) double DXF_IMPORT_PLUGIN::mapY( double aDxfCoordY )
{ {
return Millimeter2iu( m_yOffset - ( aDxfCoordY * m_DXF2mm ) ); return SCALE_FACTOR( m_yOffset - ( aDxfCoordY * m_DXF2mm ) );
} }
int DXF_IMPORT_PLUGIN::mapDim( double aDxfValue ) double DXF_IMPORT_PLUGIN::mapDim( double aDxfValue )
{ {
return Millimeter2iu( aDxfValue * m_DXF2mm ); return SCALE_FACTOR( aDxfValue * m_DXF2mm );
} }
int DXF_IMPORT_PLUGIN::mapWidth( double aDxfWidth ) double DXF_IMPORT_PLUGIN::mapWidth( double aDxfWidth )
{ {
// Always return the default line width // Always return the default line width
#if 0 #if 0
// mapWidth returns the aDxfValue if aDxfWidth > 0 m_defaultThickness // mapWidth returns the aDxfValue if aDxfWidth > 0 m_defaultThickness
if( aDxfWidth > 0.0 ) if( aDxfWidth > 0.0 )
return Millimeter2iu( aDxfWidth * m_DXF2mm ); return SCALE_FACTOR( aDxfWidth * m_DXF2mm );
#endif #endif
return Millimeter2iu( m_defaultThickness ); return SCALE_FACTOR( m_defaultThickness );
} }
bool DXF_IMPORT_PLUGIN::ImportDxfFile( const wxString& aFile ) bool DXF_IMPORT_PLUGIN::ImportDxfFile( const wxString& aFile )
@ -171,8 +181,8 @@ void DXF_IMPORT_PLUGIN::addControlPoint( const DL_ControlPointData& aData )
void DXF_IMPORT_PLUGIN::addFitPoint( const DL_FitPointData& aData ) void DXF_IMPORT_PLUGIN::addFitPoint( const DL_FitPointData& aData )
{ {
// Called for every spline fit point, when reading a spline entity // Called for every spline fit point, when reading a spline entity
// we store only the X,Y coord values in a wxRealPoint // we store only the X,Y coord values in a VECTOR2D
m_curr_entity.m_SplineFitPointList.push_back( wxRealPoint( aData.x, aData.y ) ); m_curr_entity.m_SplineFitPointList.push_back( VECTOR2D( aData.x, aData.y ) );
} }
@ -195,23 +205,14 @@ void DXF_IMPORT_PLUGIN::addLayer( const DL_LayerData& aData )
void DXF_IMPORT_PLUGIN::addLine( const DL_LineData& aData ) void DXF_IMPORT_PLUGIN::addLine( const DL_LineData& aData )
{ {
/* DRAWSEGMENT* segm = ( m_importAsfootprintGraphicItems ) ?
static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
wxPoint start( mapX( aData.x1 ), mapY( aData.y1 ) );
segm->SetStart( start );
wxPoint end( mapX( aData.x2 ), mapY( aData.y2 ) );
segm->SetEnd( end );
segm->SetWidth( mapWidth( attributes.getWidth() ) );
m_newItemsList.push_back( segm );*/
VECTOR2D start( mapX( aData.x1 ), mapY( aData.y1 ) ); VECTOR2D start( mapX( aData.x1 ), mapY( aData.y1 ) );
VECTOR2D end( mapX( aData.x2 ), mapY( aData.y2 ) ); VECTOR2D end( mapX( aData.x2 ), mapY( aData.y2 ) );
m_internalImporter.AddLine( start, end ); double lineWidth = mapWidth( attributes.getWidth() );
m_internalImporter.AddLine( start, end, lineWidth );
updateImageLimits( start ); updateImageLimits( start );
updateImageLimits( end ); updateImageLimits( end );
} }
@ -223,7 +224,6 @@ void DXF_IMPORT_PLUGIN::addPolyline(const DL_PolylineData& aData )
// to import correctly is a 2D Polyline in X and Y, which is what // to import correctly is a 2D Polyline in X and Y, which is what
// we assume of all Polylines. The width used is the width of the Polyline. // we assume of all Polylines. The width used is the width of the Polyline.
// per-vertex line widths, if present, are ignored. // per-vertex line widths, if present, are ignored.
m_curr_entity.Clear(); m_curr_entity.Clear();
m_curr_entity.m_EntityParseStatus = 1; m_curr_entity.m_EntityParseStatus = 1;
m_curr_entity.m_EntityFlag = aData.flags; m_curr_entity.m_EntityFlag = aData.flags;
@ -236,7 +236,7 @@ void DXF_IMPORT_PLUGIN::addVertex( const DL_VertexData& aData )
if( m_curr_entity.m_EntityParseStatus == 0 ) if( m_curr_entity.m_EntityParseStatus == 0 )
return; // Error return; // Error
int lineWidth = mapWidth( attributes.getWidth() ); double lineWidth = mapWidth( attributes.getWidth() );
const DL_VertexData* vertex = &aData; const DL_VertexData* vertex = &aData;
@ -250,8 +250,7 @@ void DXF_IMPORT_PLUGIN::addVertex( const DL_VertexData& aData )
return; return;
} }
VECTOR2D seg_end( m_xOffset + vertex->x * m_DXF2mm,
wxRealPoint seg_end( m_xOffset + vertex->x * m_DXF2mm,
m_yOffset - vertex->y * m_DXF2mm ); m_yOffset - vertex->y * m_DXF2mm );
if( std::abs( m_curr_entity.m_BulgeVertex ) < MIN_BULGE ) if( std::abs( m_curr_entity.m_BulgeVertex ) < MIN_BULGE )
@ -272,7 +271,7 @@ void DXF_IMPORT_PLUGIN::endEntity()
// Polyline flags bit 0 indicates closed (1) or open (0) polyline // Polyline flags bit 0 indicates closed (1) or open (0) polyline
if( m_curr_entity.m_EntityFlag & 1 ) if( m_curr_entity.m_EntityFlag & 1 )
{ {
int lineWidth = mapWidth( attributes.getWidth() ); double lineWidth = mapWidth( attributes.getWidth() );
if( std::abs( m_curr_entity.m_BulgeVertex ) < MIN_BULGE ) if( std::abs( m_curr_entity.m_BulgeVertex ) < MIN_BULGE )
insertLine( m_curr_entity.m_LastCoordinate, m_curr_entity.m_PolylineStart, lineWidth ); insertLine( m_curr_entity.m_LastCoordinate, m_curr_entity.m_PolylineStart, lineWidth );
@ -284,7 +283,7 @@ void DXF_IMPORT_PLUGIN::endEntity()
if( m_curr_entity.m_EntityType == DL_ENTITY_SPLINE ) if( m_curr_entity.m_EntityType == DL_ENTITY_SPLINE )
{ {
int lineWidth = mapWidth( attributes.getWidth() ); double lineWidth = mapWidth( attributes.getWidth() );
insertSpline( lineWidth ); insertSpline( lineWidth );
} }
@ -294,20 +293,9 @@ void DXF_IMPORT_PLUGIN::endEntity()
void DXF_IMPORT_PLUGIN::addCircle( const DL_CircleData& aData ) void DXF_IMPORT_PLUGIN::addCircle( const DL_CircleData& aData )
{ {
/* DRAWSEGMENT* segm = ( m_importAsfootprintGraphicItems ) ?
static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
segm->SetShape( S_CIRCLE );
wxPoint center( mapX( aData.cx ), mapY( aData.cy ) );
segm->SetCenter( center );
wxPoint circle_start( mapX( aData.cx + aData.radius ), mapY( aData.cy ) );
segm->SetArcStart( circle_start );
segm->SetWidth( mapWidth( attributes.getWidth() ) );
m_newItemsList.push_back( segm );
*/
VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) ); VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) );
m_internalImporter.AddCircle( center, mapDim( aData.radius ) ); double lineWidth = mapWidth( attributes.getWidth() );
m_internalImporter.AddCircle( center, mapDim( aData.radius ), lineWidth );
VECTOR2D radiusDelta( mapDim( aData.radius ), mapDim( aData.radius ) ); VECTOR2D radiusDelta( mapDim( aData.radius ), mapDim( aData.radius ) );
@ -321,43 +309,6 @@ void DXF_IMPORT_PLUGIN::addCircle( const DL_CircleData& aData )
*/ */
void DXF_IMPORT_PLUGIN::addArc( const DL_ArcData& aData ) void DXF_IMPORT_PLUGIN::addArc( const DL_ArcData& aData )
{ {
/*
DRAWSEGMENT* segm = ( m_importAsfootprintGraphicItems ) ?
static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT;
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
segm->SetShape( S_ARC );
// Init arc centre:
wxPoint center( mapX( aData.cx ), mapY( aData.cy ) );
segm->SetCenter( center );
// Init arc start point
double arcStartx = aData.radius;
double arcStarty = 0;
// aData.anglex is in degrees. Our internal units are 0.1 degree
// so convert DXF angles to our units
#define DXF2ANGLEUI 10
double startangle = aData.angle1 * DXF2ANGLEUI;
double endangle = aData.angle2 * DXF2ANGLEUI;
RotatePoint( &arcStartx, &arcStarty, -startangle );
wxPoint arcStart( mapX( arcStartx + aData.cx ),
mapY( arcStarty + aData.cy ) );
segm->SetArcStart( arcStart );
// calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
double angle = -( endangle - startangle );
if( angle > 0.0 )
angle -= 3600.0;
segm->SetAngle( angle );
segm->SetWidth( mapWidth( attributes.getWidth() ) );
m_newItemsList.push_back( segm );
*/
// Init arc centre: // Init arc centre:
VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) ); VECTOR2D center( mapX( aData.cx ), mapY( aData.cy ) );
@ -372,7 +323,7 @@ void DXF_IMPORT_PLUGIN::addArc( const DL_ArcData& aData )
double endangle = aData.angle2 * DXF2ANGLEUI; double endangle = aData.angle2 * DXF2ANGLEUI;
RotatePoint( &arcStartx, &arcStarty, -RAD2DECIDEG( startangle ) ); RotatePoint( &arcStartx, &arcStarty, -RAD2DECIDEG( startangle ) );
wxPoint arcStart( mapX( arcStartx + aData.cx ), mapY( arcStarty + aData.cy ) ); VECTOR2D arcStart( mapX( arcStartx + aData.cx ), mapY( arcStarty + aData.cy ) );
// calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew) // calculate arc angle (arcs are CCW, and should be < 0 in Pcbnew)
double angle = -( endangle - startangle ); double angle = -( endangle - startangle );
@ -380,7 +331,8 @@ void DXF_IMPORT_PLUGIN::addArc( const DL_ArcData& aData )
if( angle > 0.0 ) if( angle > 0.0 )
angle -= 3600.0; angle -= 3600.0;
m_internalImporter.AddArc( center, arcStart, angle ); double lineWidth = mapWidth( attributes.getWidth() );
m_internalImporter.AddArc( center, arcStart, angle, lineWidth );
VECTOR2D radiusDelta( mapDim( aData.radius ), mapDim( aData.radius ) ); VECTOR2D radiusDelta( mapDim( aData.radius ), mapDim( aData.radius ) );
@ -391,123 +343,14 @@ void DXF_IMPORT_PLUGIN::addArc( const DL_ArcData& aData )
void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData ) void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData )
{ {
#if 0 VECTOR2D refPoint( mapX( aData.ipx ), mapY( aData.ipy ) );
BOARD_ITEM* brdItem; VECTOR2D secPoint( mapX( aData.apx ), mapY( aData.apy ) );
EDA_TEXT* textItem;
if( m_importAsfootprintGraphicItems )
{
TEXTE_MODULE* modText = new TEXTE_MODULE( NULL );
brdItem = static_cast< BOARD_ITEM* >( modText );
textItem = static_cast< EDA_TEXT* >( modText );
}
else
{
TEXTE_PCB* pcbText = new TEXTE_PCB( NULL );
brdItem = static_cast< BOARD_ITEM* >( pcbText );
textItem = static_cast< EDA_TEXT* >( pcbText );
}
brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) );
wxPoint refPoint( mapX( aData.ipx ), mapY( aData.ipy ) );
wxPoint secPoint( mapX( aData.apx ), mapY( aData.apy ) );
if( aData.vJustification != 0 || aData.hJustification != 0 || aData.hJustification == 4 ) if( aData.vJustification != 0 || aData.hJustification != 0 || aData.hJustification == 4 )
{ {
if( aData.hJustification != 3 && aData.hJustification != 5 ) if( aData.hJustification != 3 && aData.hJustification != 5 )
{ {
wxPoint tmp = secPoint; VECTOR2D tmp = secPoint;
secPoint = refPoint;
refPoint = tmp;
}
}
switch( aData.vJustification )
{
case 0: //DRW_Text::VBaseLine:
textItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
break;
case 1: //DRW_Text::VBottom:
textItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
break;
case 2: //DRW_Text::VMiddle:
textItem->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
break;
case 3: //DRW_Text::VTop:
textItem->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
break;
}
switch( aData.hJustification )
{
case 0: //DRW_Text::HLeft:
textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
break;
case 1: //DRW_Text::HCenter:
textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
break;
case 2: //DRW_Text::HRight:
textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
break;
case 3: //DRW_Text::HAligned:
// no equivalent options in text pcb.
textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
break;
case 4: //DRW_Text::HMiddle:
// no equivalent options in text pcb.
textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
break;
case 5: //DRW_Text::HFit:
// no equivalent options in text pcb.
textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
break;
}
#if 0
wxString sty = wxString::FromUTF8( aData.style.c_str() );
sty = sty.ToLower();
if( aData.textgen == 2 )
{
// Text dir = left to right;
} else if( aData.textgen == 4 )
{
// Text dir = top to bottom;
} else
{
}
#endif
wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
textItem->SetTextPos( refPoint );
textItem->SetTextAngle( aData.angle * 10 );
// The 0.9 factor gives a better height/width ratio with our font
textItem->SetTextWidth( mapDim( aData.height * 0.9 ) );
textItem->SetTextHeight( mapDim( aData.height ) );
textItem->SetThickness( mapWidth( aData.height * DEFAULT_TEXT_WIDTH ) ); // Gives a reasonable text thickness
textItem->SetText( text );
m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) );
#endif
wxPoint refPoint( mapX( aData.ipx ), mapY( aData.ipy ) );
wxPoint secPoint( mapX( aData.apx ), mapY( aData.apy ) );
if( aData.vJustification != 0 || aData.hJustification != 0 || aData.hJustification == 4 )
{
if( aData.hJustification != 3 && aData.hJustification != 5 )
{
wxPoint tmp = secPoint;
secPoint = refPoint; secPoint = refPoint;
refPoint = tmp; refPoint = tmp;
} }
@ -635,116 +478,6 @@ void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData )
void DXF_IMPORT_PLUGIN::addMText( const DL_MTextData& aData ) void DXF_IMPORT_PLUGIN::addMText( const DL_MTextData& aData )
{ {
#if 0
wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
wxString attrib, tmp;
/* Some texts start by '\' and have formating chars (font name, font option...)
* ending with ';'
* Here are some mtext formatting codes:
* Format code Purpose
* \0...\o Turns overline on and off
* \L...\l Turns underline on and off
* \~ Inserts a nonbreaking space
\\ Inserts a backslash
\\\{...\} Inserts an opening and closing brace
\\ \File name; Changes to the specified font file
\\ \Hvalue; Changes to the text height specified in drawing units
\\ \Hvaluex; Changes the text height to a multiple of the current text height
\\ \S...^...; Stacks the subsequent text at the \, #, or ^ symbol
\\ \Tvalue; Adjusts the space between characters, from.75 to 4 times
\\ \Qangle; Changes obliquing angle
\\ \Wvalue; Changes width factor to produce wide text
\\ \A Sets the alignment value; valid values: 0, 1, 2 (bottom, center, top) while( text.StartsWith( wxT("\\") ) )
*/
while( text.StartsWith( wxT( "\\" ) ) )
{
attrib << text.BeforeFirst( ';' );
tmp = text.AfterFirst( ';' );
text = tmp;
}
BOARD_ITEM* brdItem;
EDA_TEXT* textItem;
if( m_importAsfootprintGraphicItems )
{
TEXTE_MODULE* modText = new TEXTE_MODULE( NULL );
brdItem = static_cast< BOARD_ITEM* >( modText );
textItem = static_cast< EDA_TEXT* >( modText );
}
else
{
TEXTE_PCB* pcbText = new TEXTE_PCB( NULL );
brdItem = static_cast< BOARD_ITEM* >( pcbText );
textItem = static_cast< EDA_TEXT* >( pcbText );
}
brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) );
wxPoint textpos( mapX( aData.ipx ), mapY( aData.ipy ) );
textItem->SetTextPos( textpos );
textItem->SetTextAngle( aData.angle * 10 );
// The 0.9 factor gives a better height/width ratio with our font
textItem->SetTextWidth( mapDim( aData.height * 0.9 ) );
textItem->SetTextHeight( mapDim( aData.height ) );
textItem->SetThickness( mapWidth( aData.height * DEFAULT_TEXT_WIDTH ) ); // Gives a reasonable text thickness
textItem->SetText( text );
// Initialize text justifications:
if( aData.attachmentPoint <= 3 )
{
textItem->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
}
else if( aData.attachmentPoint <= 6 )
{
textItem->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
}
else
{
textItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
}
if( aData.attachmentPoint % 3 == 1 )
{
textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
}
else if( aData.attachmentPoint % 3 == 2 )
{
textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
}
else
{
textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
}
#if 0 // These setting have no meaning in Pcbnew
if( data.alignH == 1 )
{
// Text is left to right;
}
else if( data.alignH == 3 )
{
// Text is top to bottom;
}
else
{
// use ByStyle;
}
if( aData.alignV == 1 )
{
// use AtLeast;
}
else
{
// useExact;
}
#endif
m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) );
#endif
wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) ); wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) );
wxString attrib, tmp; wxString attrib, tmp;
@ -753,10 +486,10 @@ void DXF_IMPORT_PLUGIN::addMText( const DL_MTextData& aData )
double charWidth = textHeight * 0.9; double charWidth = textHeight * 0.9;
double textWidth = charWidth * text.length(); // Rough approximation double textWidth = charWidth * text.length(); // Rough approximation
wxRealPoint bottomLeft(0.0, 0.0); VECTOR2D bottomLeft(0.0, 0.0);
wxRealPoint bottomRight(0.0, 0.0); VECTOR2D bottomRight(0.0, 0.0);
wxRealPoint topLeft(0.0, 0.0); VECTOR2D topLeft(0.0, 0.0);
wxRealPoint topRight(0.0, 0.0); VECTOR2D topRight(0.0, 0.0);
/* Some texts start by '\' and have formating chars (font name, font option...) /* Some texts start by '\' and have formating chars (font name, font option...)
* ending with ';' * ending with ';'
@ -783,7 +516,7 @@ void DXF_IMPORT_PLUGIN::addMText( const DL_MTextData& aData )
text = tmp; text = tmp;
} }
wxPoint textpos( mapX( aData.ipx ), mapY( aData.ipy ) ); VECTOR2D textpos( mapX( aData.ipx ), mapY( aData.ipy ) );
// Initialize text justifications: // Initialize text justifications:
EDA_TEXT_HJUSTIFY_T hJustify = GR_TEXT_HJUSTIFY_LEFT; EDA_TEXT_HJUSTIFY_T hJustify = GR_TEXT_HJUSTIFY_LEFT;
@ -1116,39 +849,23 @@ void DXF_IMPORT_PLUGIN::addTextStyle( const DL_StyleData& aData )
} }
void DXF_IMPORT_PLUGIN::insertLine( const wxRealPoint& aSegStart, void DXF_IMPORT_PLUGIN::insertLine( const VECTOR2D& aSegStart,
const wxRealPoint& aSegEnd, int aWidth ) const VECTOR2D& aSegEnd, int aWidth )
{ {
#if 0 VECTOR2D origin( SCALE_FACTOR( aSegStart.x ), SCALE_FACTOR( aSegStart.y ) );
DRAWSEGMENT* segm = ( m_importAsfootprintGraphicItems ) ? VECTOR2D end( SCALE_FACTOR( aSegEnd.x ), SCALE_FACTOR( aSegEnd.y ) );
static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT; m_internalImporter.AddLine( origin, end, aWidth );
wxPoint segment_startpoint( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
wxPoint segment_endpoint( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
segm->SetStart( segment_startpoint );
segm->SetEnd( segment_endpoint );
segm->SetWidth( aWidth );
m_newItemsList.push_back( segm );
#endif
VECTOR2D origin( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
VECTOR2D end( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
m_internalImporter.AddLine( origin, end );
updateImageLimits( origin ); updateImageLimits( origin );
updateImageLimits( end ); updateImageLimits( end );
} }
void DXF_IMPORT_PLUGIN::insertArc( const wxRealPoint& aSegStart, const wxRealPoint& aSegEnd, void DXF_IMPORT_PLUGIN::insertArc( const VECTOR2D& aSegStart, const VECTOR2D& aSegEnd,
double aBulge, int aWidth ) double aBulge, int aWidth )
{ {
/* DRAWSEGMENT* segm = ( m_importAsfootprintGraphicItems ) ? VECTOR2D segment_startpoint( SCALE_FACTOR( aSegStart.x ), SCALE_FACTOR( aSegStart.y ) );
static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : new DRAWSEGMENT; VECTOR2D segment_endpoint( SCALE_FACTOR( aSegEnd.x ), SCALE_FACTOR( aSegEnd.y ) );
*/
VECTOR2D segment_startpoint( Millimeter2iu( aSegStart.x ), Millimeter2iu( aSegStart.y ) );
VECTOR2D segment_endpoint( Millimeter2iu( aSegEnd.x ), Millimeter2iu( aSegEnd.y ) );
// ensure aBulge represents an angle from +/- ( 0 .. approx 359.8 deg ) // ensure aBulge represents an angle from +/- ( 0 .. approx 359.8 deg )
if( aBulge < -2000.0 ) if( aBulge < -2000.0 )
@ -1198,34 +915,23 @@ void DXF_IMPORT_PLUGIN::insertArc( const wxRealPoint& aSegStart, const wxRealPoi
// center point // center point
double cx = h * cos( offAng ) + xm; double cx = h * cos( offAng ) + xm;
double cy = h * sin( offAng ) + ym; double cy = h * sin( offAng ) + ym;
VECTOR2D center( Millimeter2iu( cx ), Millimeter2iu( -cy ) ); VECTOR2D center( SCALE_FACTOR( cx ), SCALE_FACTOR( -cy ) );
VECTOR2D arc_start; VECTOR2D arc_start;
double angle = RAD2DECIDEG( ang ); double angle = RAD2DECIDEG( ang );
//segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
//segm->SetShape( S_ARC );
//segm->SetCenter( wxPoint( Millimeter2iu( cx ), Millimeter2iu( -cy ) ) );
if( ang < 0.0 ) if( ang < 0.0 )
{ {
arc_start = VECTOR2D( Millimeter2iu( ep.x ), Millimeter2iu( -ep.y ) ); arc_start = VECTOR2D( SCALE_FACTOR( ep.x ), SCALE_FACTOR( -ep.y ) );
//segm->SetArcStart( wxPoint( Millimeter2iu( ep.x ), Millimeter2iu( -ep.y ) ) );
//segm->SetAngle( RAD2DECIDEG( ang ) );
} }
else else
{ {
arc_start = VECTOR2D( Millimeter2iu( sp.x ), Millimeter2iu( -sp.y ) ); arc_start = VECTOR2D( SCALE_FACTOR( sp.x ), SCALE_FACTOR( -sp.y ) );
angle = -angle; angle = -angle;
//segm->SetArcStart( wxPoint( Millimeter2iu( sp.x ), Millimeter2iu( -sp.y ) ) );
//segm->SetAngle( RAD2DECIDEG( -ang ) );
} }
//segm->SetWidth( aWidth ); m_internalImporter.AddArc( center, arc_start, angle, aWidth );
//m_newItemsList.push_back( segm );
m_internalImporter.AddArc( center, arc_start, angle ); VECTOR2D radiusDelta( SCALE_FACTOR( radius ), SCALE_FACTOR( radius ) );
wxPoint radiusDelta( Millimeter2iu( radius ), Millimeter2iu( radius ) );
updateImageLimits( center + radiusDelta ); updateImageLimits( center + radiusDelta );
updateImageLimits( center - radiusDelta ); updateImageLimits( center - radiusDelta );
@ -1245,31 +951,27 @@ void DXF_IMPORT_PLUGIN::insertSpline( int aWidth )
m_curr_entity.m_SplineFitPointList.size() ); m_curr_entity.m_SplineFitPointList.size() );
#endif #endif
// Very basic conversion to segments
unsigned imax = m_curr_entity.m_SplineControlPointList.size(); unsigned imax = m_curr_entity.m_SplineControlPointList.size();
if( imax < 2 ) // malformed spline if( imax < 2 ) // malformed spline
return; return;
#if 0 // set to 1 to approximate the spline by segments between 2 control points #if 0 // set to 1 to approximate the spline by segments between 2 control points
wxPoint startpoint( mapX( m_curr_entity.m_SplineControlPointList[0].m_x ), VECTOR2D startpoint( mapX( m_curr_entity.m_SplineControlPointList[0].m_x ),
mapY( m_curr_entity.m_SplineControlPointList[0].m_y ) ); mapY( m_curr_entity.m_SplineControlPointList[0].m_y ) );
for( unsigned int ii = 1; ii < imax; ++ii ) for( unsigned int ii = 1; ii < imax; ++ii )
{ {
wxPoint endpoint( mapX( m_curr_entity.m_SplineControlPointList[ii].m_x ), VECTOR2D endpoint( mapX( m_curr_entity.m_SplineControlPointList[ii].m_x ),
mapY( m_curr_entity.m_SplineControlPointList[ii].m_y ) ); mapY( m_curr_entity.m_SplineControlPointList[ii].m_y ) );
if( startpoint != endpoint ) if( startpoint != endpoint )
{ {
DRAWSEGMENT* segm = ( m_importAsfootprintGraphicItems ) ? m_internalImporter.AddLine( startpoint, endpoint );
static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) :
new DRAWSEGMENT; updateImageLimits( startpoint );
segm->SetLayer( ToLAYER_ID( m_brdLayer ) ); updateImageLimits( endpoint );
segm->SetStart( startpoint );
segm->SetEnd( endpoint );
segm->SetWidth( aWidth );
m_newItemsList.push_back( segm );
startpoint = endpoint; startpoint = endpoint;
} }
} }
@ -1294,20 +996,6 @@ void DXF_IMPORT_PLUGIN::insertSpline( int aWidth )
// So we can have more than one Bezier curve ( there are one curve each four vertices) // So we can have more than one Bezier curve ( there are one curve each four vertices)
for( unsigned ii = 0; ii < coords.size(); ii += 8 ) for( unsigned ii = 0; ii < coords.size(); ii += 8 )
{ {
#if 0
DRAWSEGMENT* segm = ( m_importAsfootprintGraphicItems ) ?
static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) :
new DRAWSEGMENT;
segm->SetLayer( ToLAYER_ID( m_brdLayer ) );
segm->SetShape( S_CURVE );
segm->SetStart( wxPoint( mapX( coords[ii] ), mapY( coords[ii+1] ) ) );
segm->SetBezControl1( wxPoint( mapX( coords[ii+2] ), mapY( coords[ii+3] ) ) );
segm->SetBezControl2( wxPoint( mapX( coords[ii+4] ), mapY( coords[ii+5] ) ) );
segm->SetEnd( wxPoint( mapX( coords[ii+6] ), mapY( coords[ii+7] ) ) );
segm->SetWidth( aWidth );
segm->RebuildBezierToSegmentsPointsList( aWidth );
m_newItemsList.push_back( segm );
#endif
VECTOR2D start( mapX( coords[ii] ), mapY( coords[ii+1] ) ); VECTOR2D start( mapX( coords[ii] ), mapY( coords[ii+1] ) );
VECTOR2D bezierControl1( mapX( coords[ii+2] ), mapY( coords[ii+3] ) ); VECTOR2D bezierControl1( mapX( coords[ii+2] ), mapY( coords[ii+3] ) );
VECTOR2D bezierControl2( mapX( coords[ii+4] ), mapY( coords[ii+5] ) ); VECTOR2D bezierControl2( mapX( coords[ii+4] ), mapY( coords[ii+5] ) );
@ -1319,20 +1007,6 @@ void DXF_IMPORT_PLUGIN::insertSpline( int aWidth )
void DXF_IMPORT_PLUGIN::updateImageLimits( const VECTOR2D& aPoint ) void DXF_IMPORT_PLUGIN::updateImageLimits( const VECTOR2D& aPoint )
{
wxPoint truncatedPoint( (int)aPoint.x, (int)aPoint.y );
updateImageLimits( truncatedPoint );
}
void DXF_IMPORT_PLUGIN::updateImageLimits( const wxRealPoint& aPoint )
{
updateImageLimits( VECTOR2D( aPoint.x, aPoint.y ) );
}
void DXF_IMPORT_PLUGIN::updateImageLimits( const wxPoint& aPoint )
{ {
m_minX = std::min( aPoint.x, m_minX ); m_minX = std::min( aPoint.x, m_minX );
m_maxX = std::max( aPoint.x, m_maxX ); m_maxX = std::max( aPoint.x, m_maxX );

View File

@ -64,8 +64,8 @@ public:
// 2 = entity in progress // 2 = entity in progress
int m_EntityFlag; // a info flag to parse entities int m_EntityFlag; // a info flag to parse entities
wxRealPoint m_LastCoordinate; // the last vertex coordinate read (unit = mm) VECTOR2D m_LastCoordinate; // the last vertex coordinate read (unit = mm)
wxRealPoint m_PolylineStart; // The first point of the polyline entity, when reading a polyline (unit = mm) VECTOR2D m_PolylineStart; // The first point of the polyline entity, when reading a polyline (unit = mm)
double m_BulgeVertex; // the last vertex bulge value read double m_BulgeVertex; // the last vertex bulge value read
// for spline parsing: parameters // for spline parsing: parameters
@ -83,7 +83,7 @@ public:
// control points list coordinates, code 10, 20 & 30 (only X and Y cood and Weight) // control points list coordinates, code 10, 20 & 30 (only X and Y cood and Weight)
std::vector<SPLINE_CTRL_POINT> m_SplineControlPointList; std::vector<SPLINE_CTRL_POINT> m_SplineControlPointList;
// fit points list, code 11, 21 & 31 (only X and Y cood) // fit points list, code 11, 21 & 31 (only X and Y cood)
std::vector<wxRealPoint> m_SplineFitPointList; std::vector<VECTOR2D> m_SplineFitPointList;
DXF2BRD_ENTITY_DATA() { Clear(); }; DXF2BRD_ENTITY_DATA() { Clear(); };
@ -115,7 +115,6 @@ public:
class DXF_IMPORT_PLUGIN : public GRAPHICS_IMPORT_PLUGIN, public DL_CreationAdapter class DXF_IMPORT_PLUGIN : public GRAPHICS_IMPORT_PLUGIN, public DL_CreationAdapter
{ {
private: private:
std::list<BOARD_ITEM*> m_newItemsList; // The list of new items added to the board
double m_xOffset; // X coord offset for conversion (in mm) double m_xOffset; // X coord offset for conversion (in mm)
double m_yOffset; // Y coord offset for conversion (in mm) double m_yOffset; // Y coord offset for conversion (in mm)
double m_defaultThickness; // default line thickness for conversion (in mm) double m_defaultThickness; // default line thickness for conversion (in mm)
@ -129,8 +128,8 @@ private:
// Each message ends by '\n' // Each message ends by '\n'
DXF2BRD_ENTITY_DATA m_curr_entity; // the current entity parameters when parsing a DXF entity DXF2BRD_ENTITY_DATA m_curr_entity; // the current entity parameters when parsing a DXF entity
int m_minX, m_maxX; // handles image size double m_minX, m_maxX; // handles image size in mm
int m_minY, m_maxY; // handles image size double m_minY, m_maxY; // handles image size in mm
GRAPHICS_IMPORTER_BUFFER m_internalImporter; GRAPHICS_IMPORTER_BUFFER m_internalImporter;
@ -150,13 +149,11 @@ public:
} }
bool Load( const wxString& aFileName ) override; bool Load( const wxString& aFileName ) override;
bool Import( float aXScale, float aYScale ) override; bool Import() override;
unsigned int GetImageWidth() const override; double GetImageWidth() const override;
unsigned int GetImageHeight() const override; double GetImageHeight() const override;
void updateImageLimits( const wxPoint& aPoint );
void updateImageLimits( const wxRealPoint& aPoint );
void updateImageLimits( const VECTOR2D& aPoint ); void updateImageLimits( const VECTOR2D& aPoint );
/** /**
@ -209,34 +206,30 @@ public:
*/ */
bool ImportDxfFile( const wxString& aFile ); bool ImportDxfFile( const wxString& aFile );
/**
* @return the list of new BOARD_ITEM
*/
const std::list<BOARD_ITEM*>& GetItemsList() const
{
return m_newItemsList;
}
/** /**
* @return the list of messages in one string. Each message ends by '\n' * @return the list of messages in one string. Each message ends by '\n'
*/ */
std::string& GetMessages() { return m_messages; } const std::string& GetMessages() const override
{
return m_messages;
}
private: private:
// report message to keep trace of not supported dxf entities: // report message to keep trace of not supported dxf entities:
void reportMsg( const char* aMessage ); void reportMsg( const char* aMessage );
// coordinate conversions from dxf to internal units // coordinate conversions from dxf file to mm
int mapX( double aDxfCoordX ); double mapX( double aDxfCoordX );
int mapY( double aDxfCoordY ); double mapY( double aDxfCoordY );
int mapDim( double aDxfValue ); double mapDim( double aDxfValue );
// mapWidth returns ( in internal units) the aDxfValue if aDxfWidth > 0 // mapWidth returns ( in mm) the aDxfValue if aDxfWidth > 0
// or m_defaultThickness // or m_defaultThickness
int mapWidth( double aDxfWidth ); double mapWidth( double aDxfWidth );
// Functions to aid in the creation of a Polyline // Functions to aid in the creation of a Polyline
void insertLine( const wxRealPoint& aSegStart, const wxRealPoint& aSegEnd, int aWidth ); void insertLine( const VECTOR2D& aSegStart, const VECTOR2D& aSegEnd, int aWidth );
void insertArc( const wxRealPoint& aSegStart, const wxRealPoint& aSegEnd, void insertArc( const VECTOR2D& aSegStart, const VECTOR2D& aSegEnd,
double aBulge, int aWidth ); double aBulge, int aWidth );
// Add a dxf spline (stored in m_curr_entity) to the board, after conversion to segments // Add a dxf spline (stored in m_curr_entity) to the board, after conversion to segments
void insertSpline( int aWidth ); void insertSpline( int aWidth );

View File

@ -38,7 +38,8 @@ class GRAPHICS_IMPORT_MGR
{ {
public: public:
///> List of handled file types. ///> List of handled file types.
enum GFX_FILE_T { enum GFX_FILE_T
{
DXF, DXF,
SVG SVG
}; };

View File

@ -91,23 +91,30 @@ public:
/** /**
* @brief Return image height from original imported file. * @brief Return image height from original imported file.
* *
* @return Original Image height in internal units. * @return Original Image height in mm.
*/ */
virtual unsigned int GetImageHeight() const = 0; virtual double GetImageHeight() const = 0;
/** /**
* @brief Return image width from original imported file. * @brief Return image width from original imported file.
* *
* @return Original Image width in internal units. * @return Original Image width in mm.
*/ */
virtual unsigned int GetImageWidth() const = 0; virtual double GetImageWidth() const = 0;
/** /**
* @brief Actually imports the file. * @brief Actually imports the file.
* *
* It is necessary to have loaded the file beforehand. * It is necessary to have loaded the file beforehand.
*/ */
virtual bool Import( float aXScale, float aYScale ) = 0; virtual bool Import() = 0;
/**
* @brief collect warning and error messages after loading/importing.
* @return the list of messages in one string. Each message ends by '\n'
*/
const virtual std::string& GetMessages() const = 0;
protected: protected:

View File

@ -25,9 +25,13 @@
#include "graphics_importer.h" #include "graphics_importer.h"
#include "graphics_import_plugin.h" #include "graphics_import_plugin.h"
GRAPHICS_IMPORTER::GRAPHICS_IMPORTER() : GRAPHICS_IMPORTER::GRAPHICS_IMPORTER()
m_lineWidth( DEFAULT_LINE_WIDTH_DFX ), m_scale( 1.0 )
{ {
m_millimeterToIu = 1.0;
m_lineWidth = DEFAULT_LINE_WIDTH_DFX;
m_scale = 1.0;
m_originalWidth = 0.0;
m_originalHeight = 0.0;
} }
@ -46,7 +50,7 @@ bool GRAPHICS_IMPORTER::Load( const wxString &aFileName )
return m_plugin->Load( aFileName ); return m_plugin->Load( aFileName );
} }
bool GRAPHICS_IMPORTER::Import( float aXScale, float aYScale) bool GRAPHICS_IMPORTER::Import( double aScale )
{ {
if( !m_plugin ) if( !m_plugin )
{ {
@ -54,7 +58,9 @@ bool GRAPHICS_IMPORTER::Import( float aXScale, float aYScale)
return false; return false;
} }
SetScale( aScale );
m_plugin->SetImporter( this ); m_plugin->SetImporter( this );
return m_plugin->Import( aXScale, aYScale ); return m_plugin->Import();
} }

View File

@ -68,16 +68,28 @@ public:
* @brief Imports shapes from loaded file. * @brief Imports shapes from loaded file.
* *
* It is important to have the file loaded before importing. * It is important to have the file loaded before importing.
*
* @param aScale allow import graphic items with a non 1:1 import ratio
* aScale = 1.0 to import graphics with their actual size.
*/ */
bool Import( float aXScale, float aYScale); bool Import( double aScale = 1.0 );
/**
* @brief collect warning and error messages after loading/importing.
* @return the list of messages in one string. Each message ends by '\n'
*/
const std::string& GetMessages() const
{
return m_plugin->GetMessages();
}
/** /**
* @brief Get original image Wigth. * @brief Get original image Wigth.
* *
* @return Width of the loaded image in internal units. * @return Width of the loaded image in mm.
*/ */
unsigned int GetImageWidth() const double GetImageWidthMM() const
{ {
return m_originalWidth; return m_originalWidth;
} }
@ -85,48 +97,77 @@ public:
/** /**
* @brief Get original image Height * @brief Get original image Height
* *
* @return Height of the loaded image in internal units. * @return Height of the loaded image in mm.
*/ */
unsigned int GetImageHeight() const double GetImageHeightMM() const
{ {
return m_originalHeight; return m_originalHeight;
} }
/** /**
* @brief Sets the line width for the imported outlines. * @brief Sets the line width for the imported outlines (in mm).
*/ */
void SetLineWidth( double aWidth ) void SetLineWidthMM( double aWidth )
{ {
m_lineWidth = (unsigned int)( aWidth * m_scale ); m_lineWidth = aWidth;
} }
/** /**
* @brief Returns the line width used for importing the outlines. * @brief Returns the line width used for importing the outlines (in mm).
*/ */
unsigned int GetLineWidth() const double GetLineWidthMM() const
{ {
return m_lineWidth; return m_lineWidth;
} }
/** @return the scale factor affecting the imported shapes.
/**
* @brief Returns the scale factor affecting the imported shapes.
*/ */
double GetScale() const double GetScale() const
{ {
return m_scale; return m_scale;
} }
/** /** @return the offset to add to coordinates when importing graphic items.
* @brief set the scale factor affecting the imported shapes. * The offset is always in mm
* it allows conversion between imported shapes units and internal units */
const VECTOR2D& GetImportOffsetMM() const
{
return m_offsetCoordmm;
}
/** Set the offset to add to coordinates when importing graphic items.
* The offset is always in mm
*/
void SetImportOffsetMM( const VECTOR2D& aOffset )
{
m_offsetCoordmm = aOffset;
}
/** Set the scale factor affecting the imported shapes.
* it allows conversion between imported shapes units and mm
*/ */
void SetScale( double aScale ) void SetScale( double aScale )
{ {
m_scale = aScale; m_scale = aScale;
} }
/** @return the conversion factor from mm to internal unit
*/
double GetMillimeterToIuFactor()
{
return m_millimeterToIu;
}
/**
* @return the overall scale factor to convert the imported shapes dimension to mm.
*/
double ImportScalingFactor() const
{
return m_scale * m_millimeterToIu;
}
/** /**
* @breif Returns the list of objects representing the imported shapes. * @breif Returns the list of objects representing the imported shapes.
*/ */
@ -135,35 +176,38 @@ public:
return m_items; return m_items;
} }
///> Default line thickness (in internal units) ///> Default line thickness (in mm)
static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1; static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1;
// Methods to be implemented by derived graphics importers // Methods to be implemented by derived graphics importers
/** /**
* @brief Creates an object representing a line segment. * @brief Creates an object representing a line segment.
* @param aOrigin is the segment origin point expressed in internal units. * @param aOrigin is the segment origin point expressed in mm.
* @param aEnd is the segment end point expressed in internal units. * @param aEnd is the segment end point expressed in mm.
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
*/ */
virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd ) = 0; virtual void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd, double aWidth ) = 0;
/** /**
* @brief Creates an object representing a circle. * @brief Creates an object representing a circle.
* @param aCenter is the circle center point expressed in internal units. * @param aCenter is the circle center point expressed in mm.
* @param aRadius is the circle radius expressed in internal units. * @param aRadius is the circle radius expressed in mm.
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
*/ */
virtual void AddCircle( const VECTOR2D& aCenter, double aRadius ) = 0; virtual void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth ) = 0;
/** /**
* @brief Creates an object representing an arc. * @brief Creates an object representing an arc.
* @param aCenter is the arc center point expressed in internal units. * @param aCenter is the arc center point expressed in mm.
* @param aStart is the arc arm end point expressed in internal units. * @param aStart is the arc arm end point expressed in mm.
* Its length is the arc radius. * Its length is the arc radius.
* @param aAngle is the arc angle expressed in decidegrees. * @param aAngle is the arc angle expressed in decidegrees.
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
*/ */
virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle ) = 0; virtual void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth ) = 0;
virtual void AddPolygon( const std::vector< VECTOR2D >& aVertices ) = 0; virtual void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) = 0;
//virtual void AddArc( const VECTOR2D& aOrigin, double aStartAngle, double aEndAngle ) = 0; //virtual void AddArc( const VECTOR2D& aOrigin, double aStartAngle, double aEndAngle ) = 0;
// //
@ -171,16 +215,25 @@ public:
* @brief Creates an object representing a text. * @brief Creates an object representing a text.
* @param aOrigin is the text position. * @param aOrigin is the text position.
* @param aText is the displayed text. * @param aText is the displayed text.
* @param aHeight is the text height expressed in internal units. * @param aHeight is the text height expressed in mm.
* @param aWidth is the text width expressed in internal units. * @param aWidth is the text width expressed in mm.
* @param aOrientation is the text orientation angle expressed in decidegrees. * @param aOrientation is the text orientation angle expressed in decidegrees.
* @param aHJustify is the text horizontal justification. * @param aHJustify is the text horizontal justification.
* @param aVJustify is the text vertical justification. * @param aVJustify is the text vertical justification.
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
*/ */
virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText, virtual void AddText( const VECTOR2D& aOrigin, const wxString& aText,
double aHeight, double, double aOrientation, double aHeight, double aWidth, double aOrientation,
EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) = 0; EDA_TEXT_HJUSTIFY_T aHJustify, EDA_TEXT_VJUSTIFY_T aVJustify ) = 0;
/**
* @brief Creates an object representing an arc.
* @param aStart is the curve start point expressed in mm.
* @param aBezierControl1 is the first Bezier control point expressed in mm.
* @param aBezierControl2 is the second Bezier control point expressed in mm.
* @param aEnd is the curve end point expressed in mm.
* @param aWidth is the segment thickness in mm. Use -1 for default line thickness
*/
virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1, virtual void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd, double aWidth ) = 0; const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd, double aWidth ) = 0;
@ -199,17 +252,26 @@ private:
std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin; std::unique_ptr<GRAPHICS_IMPORT_PLUGIN> m_plugin;
///> Total image width ///> Total image width
unsigned int m_originalWidth; double m_originalWidth;
///> Total image Height; ///> Total image Height;
unsigned int m_originalHeight; double m_originalHeight;
///> Default line thickness for the imported graphics ///> Default line thickness for the imported graphics
unsigned int m_lineWidth; double m_lineWidth;
///> Scale factor applied to the imported graphics /** Scale factor applied to the imported graphics.
* 1.0 does not change the size of imported items
* scale < 1.0 reduce the size of imported items
*/
double m_scale; double m_scale;
protected:
///> factor to convert millimeters to Internal Units
double m_millimeterToIu;
///> Offset (in mm) for imported coordinates
VECTOR2D m_offsetCoordmm;
}; };
#endif /* GRAPHICS_IMPORTER_H */ #endif /* GRAPHICS_IMPORTER_H */

View File

@ -32,28 +32,28 @@ static std::unique_ptr<T> make_shape( const Args&... aArguments )
return std::unique_ptr<T>( new T( aArguments... ) ); return std::unique_ptr<T>( new T( aArguments... ) );
} }
void GRAPHICS_IMPORTER_BUFFER::AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd ) void GRAPHICS_IMPORTER_BUFFER::AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth )
{ {
m_shapes.push_back( make_shape< IMPORTED_LINE >( aStart, aEnd ) ); m_shapes.push_back( make_shape< IMPORTED_LINE >( aStart, aEnd, aWidth ) );
} }
void GRAPHICS_IMPORTER_BUFFER::AddCircle( const VECTOR2D& aCenter, double aRadius ) void GRAPHICS_IMPORTER_BUFFER::AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth )
{ {
m_shapes.push_back( make_shape< IMPORTED_CIRCLE >( aCenter, aRadius ) ); m_shapes.push_back( make_shape< IMPORTED_CIRCLE >( aCenter, aRadius, aWidth ) );
} }
void GRAPHICS_IMPORTER_BUFFER::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, void GRAPHICS_IMPORTER_BUFFER::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart,
double aAngle ) double aAngle, double aWidth )
{ {
m_shapes.push_back( make_shape< IMPORTED_ARC >( aCenter, aStart, aAngle ) ); m_shapes.push_back( make_shape< IMPORTED_ARC >( aCenter, aStart, aAngle, aWidth ) );
} }
void GRAPHICS_IMPORTER_BUFFER::AddPolygon( const std::vector< VECTOR2D >& aVertices ) void GRAPHICS_IMPORTER_BUFFER::AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth )
{ {
m_shapes.push_back( make_shape< IMPORTED_POLYGON >( aVertices ) ); m_shapes.push_back( make_shape< IMPORTED_POLYGON >( aVertices, aWidth ) );
} }

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) 2017 CERN * Copyright (C) 2017 CERN
* @author Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com> * @author Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
* 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
@ -39,76 +40,80 @@ public:
class IMPORTED_LINE : public IMPORTED_SHAPE class IMPORTED_LINE : public IMPORTED_SHAPE
{ {
public: public:
IMPORTED_LINE( const VECTOR2D& aStart, const VECTOR2D& aEnd ) IMPORTED_LINE( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth )
: m_start( aStart ), m_end( aEnd ) : m_start( aStart ), m_end( aEnd ), m_width( aWidth )
{ {
} }
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
{ {
aImporter.AddLine( m_start, m_end ); aImporter.AddLine( m_start, m_end, m_width );
} }
private: private:
const VECTOR2D m_start; const VECTOR2D m_start;
const VECTOR2D m_end; const VECTOR2D m_end;
double m_width;
}; };
class IMPORTED_CIRCLE : public IMPORTED_SHAPE class IMPORTED_CIRCLE : public IMPORTED_SHAPE
{ {
public: public:
IMPORTED_CIRCLE( const VECTOR2D& aCenter, double aRadius ) IMPORTED_CIRCLE( const VECTOR2D& aCenter, double aRadius, double aWidth )
: m_center( aCenter ), m_radius( aRadius ) : m_center( aCenter ), m_radius( aRadius ), m_width( aWidth )
{ {
} }
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
{ {
aImporter.AddCircle( m_center, m_radius ); aImporter.AddCircle( m_center, m_radius, m_width );
} }
private: private:
const VECTOR2D m_center; const VECTOR2D m_center;
double m_radius; double m_radius;
double m_width;
}; };
class IMPORTED_ARC : public IMPORTED_SHAPE class IMPORTED_ARC : public IMPORTED_SHAPE
{ {
public: public:
IMPORTED_ARC( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle ) IMPORTED_ARC( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth )
: m_center( aCenter ), m_start( aStart ), m_angle( aAngle ) : m_center( aCenter ), m_start( aStart ), m_angle( aAngle ), m_width( aWidth )
{ {
} }
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
{ {
aImporter.AddArc( m_center, m_start, m_angle ); aImporter.AddArc( m_center, m_start, m_angle, m_width );
} }
private: private:
const VECTOR2D m_center; const VECTOR2D m_center;
const VECTOR2D m_start; const VECTOR2D m_start;
double m_angle; double m_angle;
double m_width;
}; };
class IMPORTED_POLYGON : public IMPORTED_SHAPE class IMPORTED_POLYGON : public IMPORTED_SHAPE
{ {
public: public:
IMPORTED_POLYGON( const std::vector< VECTOR2D >& aVertices ) IMPORTED_POLYGON( const std::vector< VECTOR2D >& aVertices, double aWidth )
: m_vertices( aVertices ) : m_vertices( aVertices ), m_width( aWidth )
{ {
} }
void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override void ImportTo( GRAPHICS_IMPORTER& aImporter ) const override
{ {
aImporter.AddPolygon( m_vertices ); aImporter.AddPolygon( m_vertices, m_width );
} }
private: private:
const std::vector< VECTOR2D > m_vertices; const std::vector< VECTOR2D > m_vertices;
double m_width;
}; };
@ -169,13 +174,13 @@ private:
class GRAPHICS_IMPORTER_BUFFER : public GRAPHICS_IMPORTER class GRAPHICS_IMPORTER_BUFFER : public GRAPHICS_IMPORTER
{ {
public: public:
void AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd ) override; void AddLine( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aWidth ) override;
void AddCircle( const VECTOR2D& aCenter, double aRadius ) override; void AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth ) override;
void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle ) override; void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth ) override;
void AddPolygon( const std::vector< VECTOR2D >& aVertices ) override; void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) override;
void AddText( const VECTOR2D& aOrigin, const wxString& aText, void AddText( const VECTOR2D& aOrigin, const wxString& aText,
double aHeight, double aWidth, double aOrientation, double aHeight, double aWidth, double aOrientation,

View File

@ -3,13 +3,14 @@
* *
* Copyright (C) 2016 CERN * Copyright (C) 2016 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* 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
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
@ -30,62 +31,99 @@
#include <class_text_mod.h> #include <class_text_mod.h>
#include <tuple> #include <tuple>
using namespace std; #include "convert_to_biu.h"
static std::vector<wxPoint> convertPoints( const std::vector<VECTOR2D>& aPoints,
double aScaleFactor );
static wxPoint Round( const VECTOR2D& aVec ) GRAPHICS_IMPORTER_PCBNEW::GRAPHICS_IMPORTER_PCBNEW()
{ {
return wxPoint( (int) aVec.x, (int) aVec.y ); m_layer = Dwgs_User;
m_millimeterToIu = Millimeter2iu( 1.0 );
} }
void GRAPHICS_IMPORTER_PCBNEW::AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd ) wxPoint GRAPHICS_IMPORTER_PCBNEW::MapCoordinate( const VECTOR2D& aCoordinate )
{
VECTOR2D coord = ( aCoordinate + GetImportOffsetMM() ) * ImportScalingFactor();
return wxPoint( (int) coord.x, (int) coord.y );
}
int GRAPHICS_IMPORTER_PCBNEW::MapLineWidth( double aLineWidth )
{
if( aLineWidth <= 0.0 )
return int( GetLineWidthMM() * ImportScalingFactor() );
// aLineWidth is in mm:
return int( aLineWidth * ImportScalingFactor() );
}
void GRAPHICS_IMPORTER_PCBNEW::AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd, double aWidth )
{ {
unique_ptr<DRAWSEGMENT> line( createDrawing() ); unique_ptr<DRAWSEGMENT> line( createDrawing() );
line->SetShape( S_SEGMENT ); line->SetShape( S_SEGMENT );
line->SetLayer( GetLayer() ); line->SetLayer( GetLayer() );
line->SetWidth( GetLineWidth() ); line->SetWidth( MapLineWidth( aWidth ) );
line->SetStart( Round ( aOrigin * GetScale() ) ); line->SetStart( MapCoordinate( aOrigin ) );
line->SetEnd( Round ( aEnd * GetScale() ) ); line->SetEnd( MapCoordinate( aEnd ) );
if( line->Type() == PCB_MODULE_EDGE_T )
static_cast<EDGE_MODULE*>( line.get() )->SetLocalCoord();
addItem( std::move( line ) ); addItem( std::move( line ) );
} }
void GRAPHICS_IMPORTER_PCBNEW::AddCircle( const VECTOR2D& aCenter, double aRadius ) void GRAPHICS_IMPORTER_PCBNEW::AddCircle( const VECTOR2D& aCenter, double aRadius, double aWidth )
{ {
unique_ptr<DRAWSEGMENT> circle( createDrawing() ); unique_ptr<DRAWSEGMENT> circle( createDrawing() );
circle->SetShape( S_CIRCLE ); circle->SetShape( S_CIRCLE );
circle->SetLayer( GetLayer() ); circle->SetLayer( GetLayer() );
circle->SetWidth( GetLineWidth() ); circle->SetWidth( MapLineWidth( aWidth ) );
circle->SetCenter( Round ( aCenter * GetScale() ) ); circle->SetCenter( MapCoordinate( aCenter ) );
circle->SetArcStart( Round ( VECTOR2D( aCenter.x + aRadius, aCenter.y ) * GetScale() ) ); circle->SetArcStart( MapCoordinate( VECTOR2D( aCenter.x + aRadius, aCenter.y ) ) );
if( circle->Type() == PCB_MODULE_EDGE_T )
static_cast<EDGE_MODULE*>( circle.get() )->SetLocalCoord();
addItem( std::move( circle ) ); addItem( std::move( circle ) );
} }
void GRAPHICS_IMPORTER_PCBNEW::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle ) void GRAPHICS_IMPORTER_PCBNEW::AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth )
{ {
unique_ptr<DRAWSEGMENT> arc( createDrawing() ); unique_ptr<DRAWSEGMENT> arc( createDrawing() );
arc->SetShape( S_ARC ); arc->SetShape( S_ARC );
arc->SetLayer( GetLayer() ); arc->SetLayer( GetLayer() );
arc->SetWidth( GetLineWidth() ); arc->SetWidth( MapLineWidth( aWidth ) );
arc->SetCenter( Round ( aCenter * GetScale() ) ); arc->SetCenter( MapCoordinate( aCenter) );
arc->SetArcStart( Round ( aStart * GetScale() ) ); arc->SetArcStart( MapCoordinate( aStart ) );
arc->SetAngle( aAngle ); arc->SetAngle( aAngle );
if( arc->Type() == PCB_MODULE_EDGE_T )
static_cast<EDGE_MODULE*>( arc.get() )->SetLocalCoord();
addItem( std::move( arc ) ); addItem( std::move( arc ) );
} }
void GRAPHICS_IMPORTER_PCBNEW::AddPolygon( const std::vector< VECTOR2D >& aVertices ) void GRAPHICS_IMPORTER_PCBNEW::AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth )
{ {
std::vector< wxPoint > convertedVertices = convertPoints( aVertices, GetScale() ); std::vector< wxPoint > convertedPoints;
convertedPoints.reserve( convertedPoints.size() );
for( const VECTOR2D& precisePoint : aVertices )
convertedPoints.emplace_back( MapCoordinate( precisePoint ) );
unique_ptr<DRAWSEGMENT> polygon( createDrawing() ); unique_ptr<DRAWSEGMENT> polygon( createDrawing() );
polygon->SetShape( S_POLYGON ); polygon->SetShape( S_POLYGON );
polygon->SetLayer( GetLayer() ); polygon->SetLayer( GetLayer() );
polygon->SetPolyPoints( convertedVertices ); polygon->SetPolyPoints( convertedPoints );
if( polygon->Type() == PCB_MODULE_EDGE_T )
static_cast<EDGE_MODULE*>( polygon.get() )->SetLocalCoord();
polygon->SetWidth( MapLineWidth( aWidth ) );
addItem( std::move( polygon ) ); addItem( std::move( polygon ) );
} }
@ -98,14 +136,18 @@ void GRAPHICS_IMPORTER_PCBNEW::AddText( const VECTOR2D& aOrigin, const wxString&
EDA_TEXT* textItem; EDA_TEXT* textItem;
tie( boardItem, textItem ) = createText(); tie( boardItem, textItem ) = createText();
boardItem->SetLayer( GetLayer() ); boardItem->SetLayer( GetLayer() );
textItem->SetThickness( GetLineWidth() ); textItem->SetThickness( MapLineWidth( aWidth ) );
textItem->SetTextPos( Round( aOrigin * GetScale() ) ); textItem->SetTextPos( MapCoordinate( aOrigin ) );
textItem->SetTextAngle( aOrientation ); textItem->SetTextAngle( aOrientation );
textItem->SetTextWidth( aWidth * GetScale() ); textItem->SetTextWidth( aWidth * ImportScalingFactor() );
textItem->SetTextHeight( aHeight * GetScale() ); textItem->SetTextHeight( aHeight * ImportScalingFactor() );
textItem->SetVertJustify( aVJustify ); textItem->SetVertJustify( aVJustify );
textItem->SetHorizJustify( aHJustify ); textItem->SetHorizJustify( aHJustify );
textItem->SetText( aText ); textItem->SetText( aText );
if( boardItem->Type() == PCB_MODULE_TEXT_T )
static_cast<TEXTE_MODULE*>( boardItem.get() )->SetLocalCoord();
addItem( std::move( boardItem ) ); addItem( std::move( boardItem ) );
} }
@ -114,15 +156,18 @@ void GRAPHICS_IMPORTER_PCBNEW::AddSpline( const VECTOR2D& aStart, const VECTOR2D
const VECTOR2D& BezierControl2, const VECTOR2D& aEnd, double aWidth ) const VECTOR2D& BezierControl2, const VECTOR2D& aEnd, double aWidth )
{ {
unique_ptr<DRAWSEGMENT> spline( createDrawing() ); unique_ptr<DRAWSEGMENT> spline( createDrawing() );
aWidth = GetLineWidth(); // To do: use dxf line thickness if defined
spline->SetShape( S_CURVE ); spline->SetShape( S_CURVE );
spline->SetLayer( GetLayer() ); spline->SetLayer( GetLayer() );
spline->SetWidth( aWidth ); spline->SetWidth( MapLineWidth( aWidth ) );
spline->SetStart( Round( aStart * GetScale() ) ); spline->SetStart( MapCoordinate( aStart ) );
spline->SetBezControl1( Round( BezierControl1 * GetScale() ) ); spline->SetBezControl1( MapCoordinate( BezierControl1 ) );
spline->SetBezControl2( Round( BezierControl2 * GetScale() ) ); spline->SetBezControl2( MapCoordinate( BezierControl2 ) );
spline->SetEnd( Round( aEnd * GetScale() ) ); spline->SetEnd( MapCoordinate( aEnd ) );
spline->RebuildBezierToSegmentsPointsList( aWidth ); spline->RebuildBezierToSegmentsPointsList( aWidth );
if( spline->Type() == PCB_MODULE_EDGE_T )
static_cast<EDGE_MODULE*>( spline.get() )->SetLocalCoord();
addItem( std::move( spline ) ); addItem( std::move( spline ) );
} }
@ -133,7 +178,7 @@ unique_ptr<DRAWSEGMENT> GRAPHICS_IMPORTER_BOARD::createDrawing()
} }
pair<unique_ptr<BOARD_ITEM>, EDA_TEXT*> GRAPHICS_IMPORTER_BOARD::createText() std::pair<unique_ptr<BOARD_ITEM>, EDA_TEXT*> GRAPHICS_IMPORTER_BOARD::createText()
{ {
TEXTE_PCB* text = new TEXTE_PCB( m_board ); TEXTE_PCB* text = new TEXTE_PCB( m_board );
return make_pair( unique_ptr<BOARD_ITEM>( text ), static_cast<EDA_TEXT*>( text ) ); return make_pair( unique_ptr<BOARD_ITEM>( text ), static_cast<EDA_TEXT*>( text ) );
@ -146,26 +191,8 @@ unique_ptr<DRAWSEGMENT> GRAPHICS_IMPORTER_MODULE::createDrawing()
} }
pair<unique_ptr<BOARD_ITEM>, EDA_TEXT*> GRAPHICS_IMPORTER_MODULE::createText() std::pair<unique_ptr<BOARD_ITEM>, EDA_TEXT*> GRAPHICS_IMPORTER_MODULE::createText()
{ {
TEXTE_MODULE* text = new TEXTE_MODULE( m_module ); TEXTE_MODULE* text = new TEXTE_MODULE( m_module );
return make_pair( unique_ptr<BOARD_ITEM>( text ), static_cast<EDA_TEXT*>( text ) ); return make_pair( unique_ptr<BOARD_ITEM>( text ), static_cast<EDA_TEXT*>( text ) );
} }
static std::vector< wxPoint > convertPoints( const std::vector<VECTOR2D>& aPoints,
double aScaleFactor )
{
std::vector<wxPoint> convertedPoints;
convertedPoints.reserve( aPoints.size() );
for( const VECTOR2D& precisePoint : aPoints )
{
auto scaledX = precisePoint.x * aScaleFactor;
auto scaledY = precisePoint.y * aScaleFactor;
convertedPoints.emplace_back( scaledX, scaledY );
}
return convertedPoints;
}

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) 2016 CERN * Copyright (C) 2016 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* 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
@ -38,10 +39,7 @@ class EDA_TEXT;
class GRAPHICS_IMPORTER_PCBNEW : public GRAPHICS_IMPORTER class GRAPHICS_IMPORTER_PCBNEW : public GRAPHICS_IMPORTER
{ {
public: public:
GRAPHICS_IMPORTER_PCBNEW() GRAPHICS_IMPORTER_PCBNEW();
: m_layer( Dwgs_User )
{
}
/** /**
* @brief Sets the target layer for the imported shapes. * @brief Sets the target layer for the imported shapes.
@ -60,13 +58,13 @@ public:
return m_layer; return m_layer;
} }
void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd ) override; void AddLine( const VECTOR2D& aOrigin, const VECTOR2D& aEnd, double aWidth ) override;
void AddCircle( const VECTOR2D& aOrigin, double aRadius ) override; void AddCircle( const VECTOR2D& aOrigin, double aRadius, double aWidth ) override;
void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle ) override; void AddArc( const VECTOR2D& aCenter, const VECTOR2D& aStart, double aAngle, double aWidth ) override;
void AddPolygon( const std::vector< VECTOR2D >& aVertices ) override; void AddPolygon( const std::vector< VECTOR2D >& aVertices, double aWidth ) override;
void AddText( const VECTOR2D& aOrigin, const wxString& aText, void AddText( const VECTOR2D& aOrigin, const wxString& aText,
double aHeight, double aWidth, double aOrientation, double aHeight, double aWidth, double aOrientation,
@ -75,6 +73,19 @@ public:
void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1, void AddSpline( const VECTOR2D& aStart, const VECTOR2D& aBezierControl1,
const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd , double aWidth ) override; const VECTOR2D& aBezierControl2, const VECTOR2D& aEnd , double aWidth ) override;
/** convert a imported coordinate to a board coordinate, according to
* the internal units, the user scale and offset
* @param aCoordinate is the imported coordinate in mm
*/
wxPoint MapCoordinate( const VECTOR2D& aCoordinate );
/** @return a line thickness in a board Iu value, according to
* the internal units.
* if aLineWidth < 0, the default ine thickness value is returned
* @param aLineWidth is the line thickness in mm to convert
*/
int MapLineWidth( double aLineWidth );
protected: protected:
///> Create an object representing a graphical shape. ///> Create an object representing a graphical shape.
virtual std::unique_ptr<DRAWSEGMENT> createDrawing() = 0; virtual std::unique_ptr<DRAWSEGMENT> createDrawing() = 0;

View File

@ -141,8 +141,8 @@ typedef struct NSVGshape
float opacity; // Opacity of the shape. float opacity; // Opacity of the shape.
float strokeWidth; // Stroke width (scaled). float strokeWidth; // Stroke width (scaled).
float strokeDashOffset; // Stroke dash offset (scaled). float strokeDashOffset; // Stroke dash offset (scaled).
float strokeDashArray[8]; // Stroke dash array (scaled). float strokeDashArray[8]; // Stroke dash array (scaled).
char strokeDashCount; // Number of dash values in dash array. char strokeDashCount; // Number of dash values in dash array.
char strokeLineJoin; // Stroke join type. char strokeLineJoin; // Stroke join type.
char strokeLineCap; // Stroke cap type. char strokeLineCap; // Stroke cap type.
char fillRule; // Fill rule, see NSVGfillRule. char fillRule; // Fill rule, see NSVGfillRule.

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) 2016 CERN * Copyright (C) 2016 CERN
* @author Janito V. Ferreira Filho * @author Janito V. Ferreira Filho
* Copyright (C) 1992-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
@ -49,6 +50,7 @@ static VECTOR2D getPointInLine( const VECTOR2D& aLineStart, const VECTOR2D& aLin
static float distanceFromPointToLine( const VECTOR2D& aPoint, const VECTOR2D& aLineStart, static float distanceFromPointToLine( const VECTOR2D& aPoint, const VECTOR2D& aLineStart,
const VECTOR2D& aLineEnd ); const VECTOR2D& aLineEnd );
bool SVG_IMPORT_PLUGIN::Load( const wxString& aFileName ) bool SVG_IMPORT_PLUGIN::Load( const wxString& aFileName )
{ {
wxCHECK( m_importer, false ); wxCHECK( m_importer, false );
@ -60,31 +62,55 @@ bool SVG_IMPORT_PLUGIN::Load( const wxString& aFileName )
return true; return true;
} }
bool SVG_IMPORT_PLUGIN::Import(float aXScale, float aYScale) bool SVG_IMPORT_PLUGIN::Import()
{ {
for( NSVGshape* shape = m_parsedImage->shapes; shape != NULL; shape = shape->next ) for( NSVGshape* shape = m_parsedImage->shapes; shape != NULL; shape = shape->next )
{ {
m_importer->SetLineWidth( shape->strokeWidth ); double lineWidth = shape->strokeWidth;
for( NSVGpath* path = shape->paths; path != NULL; path = path->next ) for( NSVGpath* path = shape->paths; path != NULL; path = path->next )
DrawPath( path->pts, path->npts, path->closed ); DrawPath( path->pts, path->npts, path->closed, shape->fill.type == NSVG_PAINT_COLOR, lineWidth );
} }
return true; return true;
} }
void SVG_IMPORT_PLUGIN::DrawPath( const float* aPoints, int aNumPoints, bool aClosedPath ) double SVG_IMPORT_PLUGIN::GetImageHeight() const
{
if( !m_parsedImage )
{
wxASSERT_MSG(false, "Image must have been loaded before checking height");
return 0.0;
}
return m_parsedImage->height;
}
double SVG_IMPORT_PLUGIN::GetImageWidth() const
{
if( !m_parsedImage )
{
wxASSERT_MSG(false, "Image must have been loaded before checking width");
return 0.0;
}
return m_parsedImage->width;
}
void SVG_IMPORT_PLUGIN::DrawPath( const float* aPoints, int aNumPoints, bool aClosedPath, bool aFilled, double aLineWidth )
{ {
std::vector< VECTOR2D > collectedPathPoints; std::vector< VECTOR2D > collectedPathPoints;
if( aNumPoints > 0 ) if( aNumPoints > 0 )
DrawCubicBezierPath( aPoints, aNumPoints, collectedPathPoints ); DrawCubicBezierPath( aPoints, aNumPoints, collectedPathPoints );
if( aClosedPath ) if( aFilled && aClosedPath )
DrawPolygon( collectedPathPoints ); DrawPolygon( collectedPathPoints, aLineWidth );
else else
DrawLineSegments( collectedPathPoints ); DrawLineSegments( collectedPathPoints, aLineWidth );
} }
@ -109,28 +135,28 @@ void SVG_IMPORT_PLUGIN::DrawCubicBezierPath( const float* aPoints, int aNumPoint
void SVG_IMPORT_PLUGIN::DrawCubicBezierCurve( const float* aPoints, void SVG_IMPORT_PLUGIN::DrawCubicBezierCurve( const float* aPoints,
std::vector< VECTOR2D >& aGeneratedPoints ) std::vector< VECTOR2D >& aGeneratedPoints )
{ {
auto start = getBezierPoint( aPoints, 0.f ); auto start = getBezierPoint( aPoints, 0.0f );
auto end = getBezierPoint( aPoints, 1.f ); auto end = getBezierPoint( aPoints, 1.0f );
auto segmentationThreshold = calculateBezierSegmentationThreshold( aPoints ); auto segmentationThreshold = calculateBezierSegmentationThreshold( aPoints );
aGeneratedPoints.push_back( start ); aGeneratedPoints.push_back( start );
segmentBezierCurve( start, end, 0.f, 0.5f, aPoints, segmentationThreshold, aGeneratedPoints ); segmentBezierCurve( start, end, 0.0f, 0.5f, aPoints, segmentationThreshold, aGeneratedPoints );
aGeneratedPoints.push_back( end ); aGeneratedPoints.push_back( end );
} }
void SVG_IMPORT_PLUGIN::DrawPolygon( const std::vector< VECTOR2D >& aPoints ) void SVG_IMPORT_PLUGIN::DrawPolygon( const std::vector< VECTOR2D >& aPoints, double aWidth )
{ {
m_importer->AddPolygon( aPoints ); m_importer->AddPolygon( aPoints, aWidth );
} }
void SVG_IMPORT_PLUGIN::DrawLineSegments( const std::vector< VECTOR2D >& aPoints ) void SVG_IMPORT_PLUGIN::DrawLineSegments( const std::vector< VECTOR2D >& aPoints, double aWidth )
{ {
unsigned int numLineStartPoints = aPoints.size() - 1; unsigned int numLineStartPoints = aPoints.size() - 1;
for( unsigned int pointIndex = 0; pointIndex < numLineStartPoints; ++pointIndex ) for( unsigned int pointIndex = 0; pointIndex < numLineStartPoints; ++pointIndex )
m_importer->AddLine( aPoints[ pointIndex ], aPoints[ pointIndex + 1 ] ); m_importer->AddLine( aPoints[ pointIndex ], aPoints[ pointIndex + 1 ], aWidth );
} }
@ -185,10 +211,8 @@ static float calculateBezierSegmentationThreshold( const float* aCurvePoints )
static VECTOR2D calculateBezierBoundingBoxExtremity( const float* aCurvePoints, static VECTOR2D calculateBezierBoundingBoxExtremity( const float* aCurvePoints,
std::function< const float&( const float&, const float& ) > comparator ) std::function< const float&( const float&, const float& ) > comparator )
{ {
float x, y; float x = aCurvePoints[0];
float y = aCurvePoints[1];
x = aCurvePoints[0];
y = aCurvePoints[1];
for( int pointIndex = 1; pointIndex < 3; ++pointIndex ) for( int pointIndex = 1; pointIndex < 3; ++pointIndex )
{ {

View File

@ -3,6 +3,7 @@
* *
* Copyright (C) 2016 CERN * Copyright (C) 2016 CERN
* @author Janito V. Ferreira Filho <janito.vff@gmail.com> * @author Janito V. Ferreira Filho <janito.vff@gmail.com>
* 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
@ -25,11 +26,11 @@
#ifndef SVG_IMPORT_PLUGIN_H #ifndef SVG_IMPORT_PLUGIN_H
#define SVG_IMPORT_PLUGIN_H #define SVG_IMPORT_PLUGIN_H
#include "vector"
#include "nanosvg.h" #include "nanosvg.h"
#include "graphics_import_plugin.h" #include "graphics_import_plugin.h"
//#include "drw_interface.h"
#include "convert_to_biu.h"
#include <math/vector2d.h> #include <math/vector2d.h>
@ -46,34 +47,22 @@ public:
return wxArrayString( 1, { "svg" } ); return wxArrayString( 1, { "svg" } );
} }
bool Import(float aXScale, float aYScale) override; /**
* @return the list of messages in one string. Each message ends by '\n'
*/
const std::string& GetMessages() const override
{
return m_messages;
}
bool Import() override;
bool Load( const wxString& aFileName ) override; bool Load( const wxString& aFileName ) override;
virtual unsigned int GetImageHeight() const override virtual double GetImageHeight() const override;
{ virtual double GetImageWidth() const override;
if( !m_parsedImage )
{
wxASSERT_MSG(false, "Image must have been loaded before checking height");
return false;
}
return Millimeter2iu( m_parsedImage->height );
}
virtual unsigned int GetImageWidth() const override
{
if( !m_parsedImage )
{
wxASSERT_MSG(false, "Image must have been loaded before checking width");
return false;
}
return Millimeter2iu( m_parsedImage->width );
}
private: private:
void DrawPath( const float* aPoints, int aNumPoints, bool aClosedPath ); void DrawPath( const float* aPoints, int aNumPoints, bool aClosedPath, bool aFilled, double aLineWidth );
void DrawCubicBezierPath( const float* aPoints, int aNumPoints, void DrawCubicBezierPath( const float* aPoints, int aNumPoints,
std::vector< VECTOR2D >& aGeneratedPoints ); std::vector< VECTOR2D >& aGeneratedPoints );
@ -81,10 +70,13 @@ private:
void DrawCubicBezierCurve( const float* aPoints, void DrawCubicBezierCurve( const float* aPoints,
std::vector< VECTOR2D >& aGeneratedPoints ); std::vector< VECTOR2D >& aGeneratedPoints );
void DrawPolygon( const std::vector< VECTOR2D >& aPoints ); void DrawPolygon( const std::vector< VECTOR2D >& aPoints, double aWidth );
void DrawLineSegments( const std::vector< VECTOR2D >& aPoints ); void DrawLineSegments( const std::vector< VECTOR2D >& aPoints, double aWidth );
struct NSVGimage* m_parsedImage; struct NSVGimage* m_parsedImage;
std::string m_messages; // messages generated during svg file parsing.
// Each message ends by '\n'
}; };
#endif /* SVG_IMPORT_PLUGIN_H */ #endif /* SVG_IMPORT_PLUGIN_H */

View File

@ -96,23 +96,21 @@ void InvokePluginOptionsEditor( wxWindow* aCaller, const wxString& aNickname,
const wxString& aPluginType, const wxString& aOptions, wxString* aResult ); const wxString& aPluginType, const wxString& aOptions, wxString* aResult );
/** /**
* Function InvokeDXFDialogBoardImport * Shows the modal DIALOG_IMPORT_GFX for importing a DXF file to a board.
* shows the modal DIALOG_DXF_IMPORT for importing a DXF file to a board.
* @param aCaller is the wxTopLevelWindow which is invoking the dialog. * @param aCaller is the wxTopLevelWindow which is invoking the dialog.
* @return true if the import was made. * @return true if the import was made.
*/ */
bool InvokeDXFDialogBoardImport( PCB_BASE_FRAME* aCaller ); bool InvokeDialogImportGfxBoard( PCB_BASE_FRAME* aCaller );
/** /**
* Function InvokeDXFDialogModuleImport * shows the modal DIALOG_IMPORT_GFX for importing a DXF file as footprint outlines.
* shows the modal DIALOG_DXF_IMPORT for importing a DXF file as footprint outlines.
* *
* @param aCaller is the wxTopLevelWindow which is invoking the dialog. * @param aCaller is the wxTopLevelWindow which is invoking the dialog.
* @param aModule is the footprint currently edited. * @param aModule is the footprint currently edited.
* @return true if the import was made. * @return true if the import was made.
*/ */
bool InvokeDXFDialogModuleImport( PCB_BASE_FRAME* aCaller, MODULE* aModule ); bool InvokeDialogImportGfxModule( PCB_BASE_FRAME* aCaller, MODULE* aModule );
/** /**
* Function InvokeExportSVG * Function InvokeExportSVG

View File

@ -831,8 +831,8 @@ void prepareFilesMenu( wxMenu* aParentMenu, bool aIsOutsideProject )
KiBitmap( import_xpm ) ); KiBitmap( import_xpm ) );
AddMenuItem( submenuImport, ID_GEN_IMPORT_GRAPHICS_FILE, AddMenuItem( submenuImport, ID_GEN_IMPORT_GRAPHICS_FILE,
_( "SVG or DXF &Graphics..." ), _( "Import &Graphics..." ),
_( "Import 2D Drawing DXF or SVG file to Pcbnew on Drawings layer" ), _( "Import 2D Drawing file to Pcbnew on Drawings layer" ),
KiBitmap( import_xpm ) ); KiBitmap( import_xpm ) );
AddMenuItem( aParentMenu, submenuImport, AddMenuItem( aParentMenu, submenuImport,

View File

@ -739,33 +739,58 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
if( !m_frame->GetModel() ) if( !m_frame->GetModel() )
return 0; return 0;
//DIALOG_DXF_IMPORT dlg( m_frame );
// Note: PlaceImportedGraphics() will convert PCB_LINE_T and PCB_TEXT_T to module graphic items // Note: PlaceImportedGraphics() will convert PCB_LINE_T and PCB_TEXT_T to module graphic items
// if needed // if needed
DIALOG_IMPORT_GFX dlg( m_frame, false );// m_editModules ); DIALOG_IMPORT_GFX dlg( m_frame, m_editModules );
int dlgResult = dlg.ShowModal(); int dlgResult = dlg.ShowModal();
/*const std::list<BOARD_ITEM*>*/auto& list = dlg.GetImportedItems(); auto& list = dlg.GetImportedItems();
if( dlgResult != wxID_OK || list.empty() ) if( dlgResult != wxID_OK )
return 0; return 0;
// Ensure the list is not empty:
if( list.empty() )
{
wxMessageBox( _( "No graphic items found in file to import") );
return 0;
}
m_frame->SetNoToolSelected();
// Add a VIEW_GROUP that serves as a preview for the new item // Add a VIEW_GROUP that serves as a preview for the new item
SELECTION preview; SELECTION preview;
BOARD_COMMIT commit( m_frame ); BOARD_COMMIT commit( m_frame );
// Build the undo list & add items to the current view // Build the undo list & add items to the current view
//for( auto item : list )
for( auto it = list.begin(), itEnd = list.end(); it != itEnd; ++it ) for( auto it = list.begin(), itEnd = list.end(); it != itEnd; ++it )
{ {
EDA_ITEM* item = it->get(); EDA_ITEM* item = it->get();
wxASSERT( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T ); if( m_editModules )
{
wxASSERT( item->Type() == PCB_MODULE_EDGE_T || item->Type() == PCB_MODULE_TEXT_T );
}
else
{
wxASSERT( item->Type() == PCB_LINE_T || item->Type() == PCB_TEXT_T );
}
if( dlg.IsPlacementInteractive() )
preview.Add( item );
else
commit.Add( item );
preview.Add( item );
it->release(); it->release();
} }
if( !dlg.IsPlacementInteractive() )
{
commit.Push( _( "Place a DXF_SVG drawing" ) );
return 0;
}
BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( preview.Front() ); BOARD_ITEM* firstItem = static_cast<BOARD_ITEM*>( preview.Front() );
m_view->Add( &preview ); m_view->Add( &preview );
@ -836,86 +861,9 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
} }
else if( evt->IsClick( BUT_LEFT ) ) else if( evt->IsClick( BUT_LEFT ) )
{ {
// Place the drawing // Place the imported drawings
BOARD_ITEM_CONTAINER* parent = m_frame->GetModel();
for( auto item : preview ) for( auto item : preview )
{ commit.Add( item );
if( m_editModules )
{
// Modules use different types for the same things,
// so we need to convert imported items to appropriate classes.
BOARD_ITEM* converted = NULL;
switch( item->Type() )
{
case PCB_TEXT_T:
{
TEXTE_PCB* text = static_cast<TEXTE_PCB*>( item );
TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) parent );
// Assignment operator also copies the item PCB_TEXT_T type,
// so it cannot be added to a module which handles PCB_MODULE_TEXT_T
textMod->SetText( text->GetText() );
#if 0
textMod->SetTextSize( text->GetTextSize() );
textMod->SetThickness( text->GetThickness() );
textMod->SetOrientation( text->GetTextAngle() );
textMod->SetTextPos( text->GetTextPos() );
textMod->SetTextSize( text->GetTextSize() );
textMod->SetVisible( text->GetVisible() );
textMod->SetMirrored( text->IsMirrored() );
textMod->SetItalic( text->IsItalic() );
textMod->SetBold( text->IsBold() );
textMod->SetHorizJustify( text->GetHorizJustify() );
textMod->SetVertJustify( text->GetVertJustify() );
textMod->SetMultilineAllowed( text->IsMultilineAllowed() );
#else
textMod->EDA_TEXT::SetEffects( *text );
textMod->SetLocalCoord(); // using changed SetTexPos() via SetEffects()
#endif
converted = textMod;
break;
}
case PCB_LINE_T:
{
DRAWSEGMENT* seg = static_cast<DRAWSEGMENT*>( item );
EDGE_MODULE* modSeg = new EDGE_MODULE( (MODULE*) parent );
// Assignment operator also copies the item PCB_LINE_T type,
// so it cannot be added to a module which handles PCB_MODULE_EDGE_T
modSeg->SetWidth( seg->GetWidth() );
modSeg->SetStart( seg->GetStart() );
modSeg->SetEnd( seg->GetEnd() );
modSeg->SetAngle( seg->GetAngle() );
modSeg->SetShape( seg->GetShape() );
modSeg->SetType( seg->GetType() );
modSeg->SetBezControl1( seg->GetBezControl1() );
modSeg->SetBezControl2( seg->GetBezControl2() );
modSeg->SetBezierPoints( seg->GetBezierPoints() );
modSeg->SetPolyShape( seg->GetPolyShape() );
modSeg->SetLocalCoord();
converted = modSeg;
break;
}
default:
wxASSERT_MSG( false,
wxString::Format( "item type %d not allowed", item->Type() ) );
break;
}
if( converted )
converted->SetLayer( static_cast<BOARD_ITEM*>( item )->GetLayer() );
delete item;
item = converted;
}
if( item )
commit.Add( item );
}
commit.Push( _( "Place a DXF_SVG drawing" ) ); commit.Push( _( "Place a DXF_SVG drawing" ) );
break; break;