gerbview: Move more items to actions and tools
* Create a new inspection tool to hold the measure tool and the other inspection items * Move some control functions from the frame to a tool and rearrange the code to be cleaner.
This commit is contained in:
parent
a697690ebb
commit
565bb268bb
|
@ -21,6 +21,7 @@ set( DIALOGS_SRCS
|
||||||
dialogs/panel_gerbview_display_options_base.cpp
|
dialogs/panel_gerbview_display_options_base.cpp
|
||||||
dialogs/panel_gerbview_settings.cpp
|
dialogs/panel_gerbview_settings.cpp
|
||||||
dialogs/panel_gerbview_settings_base.cpp
|
dialogs/panel_gerbview_settings_base.cpp
|
||||||
|
dialogs/dialog_layers_select_to_pcb.cpp
|
||||||
dialogs/dialog_layers_select_to_pcb_base.cpp
|
dialogs/dialog_layers_select_to_pcb_base.cpp
|
||||||
dialogs/dialog_print_gerbview.cpp
|
dialogs/dialog_print_gerbview.cpp
|
||||||
dialogs/dialog_select_one_pcb_layer.cpp
|
dialogs/dialog_select_one_pcb_layer.cpp
|
||||||
|
@ -53,13 +54,13 @@ set( GERBVIEW_SRCS
|
||||||
rs274_read_XY_and_IJ_coordinates.cpp
|
rs274_read_XY_and_IJ_coordinates.cpp
|
||||||
rs274d.cpp
|
rs274d.cpp
|
||||||
rs274x.cpp
|
rs274x.cpp
|
||||||
select_layers_to_pcb.cpp
|
|
||||||
toolbars_gerber.cpp
|
toolbars_gerber.cpp
|
||||||
|
|
||||||
gerbview_draw_panel_gal.cpp
|
gerbview_draw_panel_gal.cpp
|
||||||
gerbview_painter.cpp
|
gerbview_painter.cpp
|
||||||
|
|
||||||
tools/gerbview_actions.cpp
|
tools/gerbview_actions.cpp
|
||||||
|
tools/gerbview_inspection_tool.cpp
|
||||||
tools/gerbview_selection.cpp
|
tools/gerbview_selection.cpp
|
||||||
tools/gerbview_selection_tool.cpp
|
tools/gerbview_selection_tool.cpp
|
||||||
tools/gerbview_control.cpp
|
tools/gerbview_control.cpp
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#include <kiface_i.h>
|
#include <kiface_i.h>
|
||||||
#include <layers_id_colors_and_visibility.h>
|
#include <layers_id_colors_and_visibility.h>
|
||||||
|
|
||||||
#include <select_layers_to_pcb.h>
|
#include <dialogs/dialog_layers_select_to_pcb.h>
|
||||||
|
|
||||||
// Imported function
|
// Imported function
|
||||||
extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );
|
extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );
|
||||||
|
@ -822,4 +822,4 @@ int LAYERS_MAP_DIALOG::findNumX2GerbersLoaded( std::vector<int>& aGerber2KicadMa
|
||||||
}
|
}
|
||||||
|
|
||||||
return numKicadMatches;
|
return numKicadMatches;
|
||||||
}
|
}
|
|
@ -26,11 +26,13 @@
|
||||||
* @file select_layers_to_pcb.h
|
* @file select_layers_to_pcb.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _SELECT_LAYERS_TO_PCB_H_
|
#ifndef DIALOG_LAYERS_SELECT_TO_PCB_H_
|
||||||
#define _SELECT_LAYERS_TO_PCB_H_
|
#define DIALOG_LAYERS_SELECT_TO_PCB_H_
|
||||||
|
|
||||||
#include <dialogs/dialog_layers_select_to_pcb_base.h>
|
#include <dialogs/dialog_layers_select_to_pcb_base.h>
|
||||||
|
|
||||||
|
class GERBVIEW_FRAME;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This dialog shows the gerber files loaded, and allows user to choose
|
* This dialog shows the gerber files loaded, and allows user to choose
|
||||||
* equivalence between gerber layers and pcb layers
|
* equivalence between gerber layers and pcb layers
|
||||||
|
@ -127,4 +129,4 @@ private:
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _SELECT_LAYERS_TO_PCB_H_
|
#endif // DIALOG_LAYERS_SELECT_TO_PCB_H_
|
|
@ -28,7 +28,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gerbview_frame.h>
|
#include <gerbview_frame.h>
|
||||||
#include <select_layers_to_pcb.h>
|
#include <dialogs/dialog_layers_select_to_pcb.h>
|
||||||
|
|
||||||
#define NB_PCB_LAYERS PCB_LAYER_ID_COUNT
|
#define NB_PCB_LAYERS PCB_LAYER_ID_COUNT
|
||||||
#define FIRST_COPPER_LAYER 0
|
#define FIRST_COPPER_LAYER 0
|
||||||
|
|
|
@ -52,7 +52,6 @@ BEGIN_EVENT_TABLE( GERBVIEW_FRAME, EDA_DRAW_FRAME )
|
||||||
|
|
||||||
// Menu Files:
|
// Menu Files:
|
||||||
EVT_MENU( ID_NEW_BOARD, GERBVIEW_FRAME::Files_io )
|
EVT_MENU( ID_NEW_BOARD, GERBVIEW_FRAME::Files_io )
|
||||||
EVT_MENU( ID_GERBVIEW_EXPORT_TO_PCBNEW, GERBVIEW_FRAME::ExportDataInPcbnewFormat )
|
|
||||||
|
|
||||||
EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, GERBVIEW_FRAME::OnGbrFileHistory )
|
EVT_MENU_RANGE( ID_FILE1, ID_FILEMAX, GERBVIEW_FRAME::OnGbrFileHistory )
|
||||||
EVT_MENU( ID_FILE_LIST_CLEAR, GERBVIEW_FRAME::OnClearGbrFileHistory )
|
EVT_MENU( ID_FILE_LIST_CLEAR, GERBVIEW_FRAME::OnClearGbrFileHistory )
|
||||||
|
@ -71,13 +70,6 @@ BEGIN_EVENT_TABLE( GERBVIEW_FRAME, EDA_DRAW_FRAME )
|
||||||
|
|
||||||
EVT_MENU( wxID_EXIT, GERBVIEW_FRAME::OnQuit )
|
EVT_MENU( wxID_EXIT, GERBVIEW_FRAME::OnQuit )
|
||||||
|
|
||||||
// menu Postprocess
|
|
||||||
EVT_MENU( ID_GERBVIEW_SHOW_LIST_DCODES, GERBVIEW_FRAME::Process_Special_Functions )
|
|
||||||
EVT_MENU( ID_GERBVIEW_SHOW_SOURCE, GERBVIEW_FRAME::OnShowGerberSourceFile )
|
|
||||||
|
|
||||||
// menu Miscellaneous
|
|
||||||
EVT_MENU( ID_GERBVIEW_ERASE_CURR_LAYER, GERBVIEW_FRAME::Process_Special_Functions )
|
|
||||||
|
|
||||||
EVT_COMBOBOX( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnSelectActiveLayer )
|
EVT_COMBOBOX( ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnSelectActiveLayer )
|
||||||
|
|
||||||
EVT_SELECT_DCODE( ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE, GERBVIEW_FRAME::OnSelectActiveDCode )
|
EVT_SELECT_DCODE( ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE, GERBVIEW_FRAME::OnSelectActiveDCode )
|
||||||
|
@ -106,30 +98,6 @@ BEGIN_EVENT_TABLE( GERBVIEW_FRAME, EDA_DRAW_FRAME )
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
/* Handles the selection of tools, menu, and popup menu commands.
|
|
||||||
*/
|
|
||||||
void GERBVIEW_FRAME::Process_Special_Functions( wxCommandEvent& event )
|
|
||||||
{
|
|
||||||
switch( event.GetId() )
|
|
||||||
{
|
|
||||||
case ID_GERBVIEW_ERASE_CURR_LAYER:
|
|
||||||
Erase_Current_DrawLayer( true );
|
|
||||||
ClearMsgPanel();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ID_GERBVIEW_SHOW_LIST_DCODES:
|
|
||||||
Liste_D_Codes();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
wxFAIL_MSG( wxT( "GERBVIEW_FRAME::Process_Special_Functions error" ) );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetCanvas()->Refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GERBVIEW_FRAME::OnSelectHighlightChoice( wxCommandEvent& event )
|
void GERBVIEW_FRAME::OnSelectHighlightChoice( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( GetCanvas()->GetView()->GetPainter() )->GetSettings();
|
auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( GetCanvas()->GetView()->GetPainter() )->GetSettings();
|
||||||
|
@ -181,44 +149,6 @@ void GERBVIEW_FRAME::OnSelectActiveLayer( wxCommandEvent& event )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GERBVIEW_FRAME::OnShowGerberSourceFile( wxCommandEvent& event )
|
|
||||||
{
|
|
||||||
int layer = GetActiveLayer();
|
|
||||||
GERBER_FILE_IMAGE* gerber_layer = GetGbrImage( layer );
|
|
||||||
|
|
||||||
if( gerber_layer )
|
|
||||||
{
|
|
||||||
wxString editorname = Pgm().GetEditorName();
|
|
||||||
|
|
||||||
if( !editorname.IsEmpty() )
|
|
||||||
{
|
|
||||||
wxFileName fn( gerber_layer->m_FileName );
|
|
||||||
|
|
||||||
// Call the editor only if the Gerber/drill source file is available.
|
|
||||||
// This is not always the case, because it can be a temporary file
|
|
||||||
// if it comes from a zip archive.
|
|
||||||
if( !fn.FileExists() )
|
|
||||||
{
|
|
||||||
wxString msg;
|
|
||||||
msg.Printf( _( "Source file \"%s\" is not available" ),
|
|
||||||
GetChars( fn.GetFullPath() ) );
|
|
||||||
wxMessageBox( msg );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ExecuteFile( this, editorname, QuoteFullPath( fn ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
wxMessageBox( _( "No editor defined. Please select one" ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxString msg;
|
|
||||||
msg.Printf( _( "No file loaded on the active layer %d" ), layer + 1 );
|
|
||||||
wxMessageBox( msg );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GERBVIEW_FRAME::OnSelectDisplayMode( wxCommandEvent& event )
|
void GERBVIEW_FRAME::OnSelectDisplayMode( wxCommandEvent& event )
|
||||||
{
|
{
|
||||||
switch( event.GetId() )
|
switch( event.GetId() )
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
|
* Copyright (C) 2007-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
|
||||||
* Copyright (C) 1992-2017 KiCad Developers, see change_log.txt for contributors.
|
* Copyright (C) 1992-2020 KiCad Developers, see change_log.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -22,20 +22,16 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @file export_to_pcbnew.cpp
|
|
||||||
* @brief Export the layers to Pcbnew.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <export_to_pcbnew.h>
|
||||||
|
|
||||||
#include <confirm.h>
|
#include <confirm.h>
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
#include <trigo.h>
|
#include <trigo.h>
|
||||||
#include <gerbview_frame.h>
|
#include <gerbview_frame.h>
|
||||||
#include <gerber_file_image.h>
|
#include <gerber_file_image.h>
|
||||||
#include <gerber_file_image_list.h>
|
#include <gerber_file_image_list.h>
|
||||||
#include <select_layers_to_pcb.h>
|
|
||||||
#include <build_version.h>
|
#include <build_version.h>
|
||||||
#include <wildcards_and_files_ext.h>
|
#include <wildcards_and_files_ext.h>
|
||||||
#include "excellon_image.h"
|
#include "excellon_image.h"
|
||||||
|
@ -44,138 +40,6 @@
|
||||||
extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );
|
extern const wxString GetPCBDefaultLayerName( LAYER_NUM aLayerNumber );
|
||||||
|
|
||||||
|
|
||||||
struct EXPORT_VIA
|
|
||||||
{
|
|
||||||
EXPORT_VIA( const wxPoint& aPos, int aSize, int aDrill ) :
|
|
||||||
m_Pos( aPos ),
|
|
||||||
m_Size( aSize ),
|
|
||||||
m_Drill( aDrill )
|
|
||||||
{ }
|
|
||||||
|
|
||||||
wxPoint m_Pos;
|
|
||||||
int m_Size;
|
|
||||||
int m_Drill;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* A helper class to export a Gerber set of files to Pcbnew
|
|
||||||
*/
|
|
||||||
class GBR_TO_PCB_EXPORTER
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
GERBVIEW_FRAME* m_gerbview_frame; // the main gerber frame
|
|
||||||
wxString m_pcb_file_name; // BOARD file to write to
|
|
||||||
FILE* m_fp; // the board file
|
|
||||||
int m_pcbCopperLayersCount;
|
|
||||||
std::vector<EXPORT_VIA> m_vias;
|
|
||||||
public:
|
|
||||||
GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName );
|
|
||||||
~GBR_TO_PCB_EXPORTER();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function ExportPcb
|
|
||||||
* saves a board from a set of Gerber images.
|
|
||||||
*/
|
|
||||||
bool ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLayers );
|
|
||||||
|
|
||||||
private:
|
|
||||||
/**
|
|
||||||
* collect holes from a drill layer.
|
|
||||||
* We'll use these later when writing pads & vias.
|
|
||||||
* @param aGbrItem
|
|
||||||
*/
|
|
||||||
void collect_hole( GERBER_DRAW_ITEM* aGbrItem );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* write a via to the board file.
|
|
||||||
* Some of these will represent actual vias while others are used to represent
|
|
||||||
* holes in pads. (We can't generate actual pads because the Gerbers don't contain
|
|
||||||
* info on how to group them into modules.)
|
|
||||||
* @param aVia
|
|
||||||
*/
|
|
||||||
void export_via( const EXPORT_VIA& aVia );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* write a non copper line or arc to the board file.
|
|
||||||
* @param aGbrItem = the Gerber item (line, arc) to export
|
|
||||||
* @param aLayer = the technical layer to use
|
|
||||||
*/
|
|
||||||
void export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* write a non-copper polygon to the board file.
|
|
||||||
* @param aLayer = the technical layer to use
|
|
||||||
*/
|
|
||||||
void writePcbPolygon( const SHAPE_POLY_SET& aPolys, LAYER_NUM aLayer,
|
|
||||||
const wxPoint& aOffset = { 0, 0 } );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* write a zone item to the board file.
|
|
||||||
* Currently: only experimental, for tests
|
|
||||||
* @param aGbrItem = the Gerber item (line, arc) to export
|
|
||||||
* @param aLayer = the technical layer to use
|
|
||||||
*/
|
|
||||||
void writePcbZoneItem( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* write a track (or via) to the board file.
|
|
||||||
* @param aGbrItem = the Gerber item (line, arc, flashed) to export
|
|
||||||
* @param aLayer = the copper layer to use
|
|
||||||
*/
|
|
||||||
void export_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function export_flashed_copper_item
|
|
||||||
* write a synthetic pad to the board file.
|
|
||||||
* We can't create real pads because the Gerbers don't store grouping/footprint info.
|
|
||||||
* So we synthesize a pad with a via for the hole (if present) and a copper polygon for
|
|
||||||
* the pad.
|
|
||||||
* @param aGbrItem = the flashed Gerber item to export
|
|
||||||
*/
|
|
||||||
void export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function export_segline_copper_item
|
|
||||||
* write a track (not via) to the board file.
|
|
||||||
* @param aGbrItem = the Gerber item (line only) to export
|
|
||||||
* @param aLayer = the copper layer to use
|
|
||||||
*/
|
|
||||||
void export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function export_segarc_copper_item
|
|
||||||
* write a set of tracks (arcs are approximated by track segments)
|
|
||||||
* to the board file.
|
|
||||||
* @param aGbrItem = the Gerber item (arc only) to export
|
|
||||||
* @param aLayer = the copper layer to use
|
|
||||||
*/
|
|
||||||
void export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* function writeCopperLineItem
|
|
||||||
* basic write function to write a a TRACK item
|
|
||||||
* to the board file, from a non flashed item
|
|
||||||
*/
|
|
||||||
void writeCopperLineItem( wxPoint& aStart, wxPoint& aEnd,
|
|
||||||
int aWidth, LAYER_NUM aLayer );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* function writePcbHeader
|
|
||||||
* Write a very basic header to the board file
|
|
||||||
*/
|
|
||||||
void writePcbHeader( LAYER_NUM* aLayerLookUpTable );
|
|
||||||
|
|
||||||
/** In Pcbnew files units are mm for coordinates.
|
|
||||||
* So MapToPcbUnits converts internal gerbview to mm any pcbnew value
|
|
||||||
* @param aValue is a coordinate value to convert in mm
|
|
||||||
*/
|
|
||||||
double MapToPcbUnits( int aValue )
|
|
||||||
{
|
|
||||||
return aValue / IU_PER_MM;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName )
|
GBR_TO_PCB_EXPORTER::GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName )
|
||||||
{
|
{
|
||||||
m_gerbview_frame = aFrame;
|
m_gerbview_frame = aFrame;
|
||||||
|
@ -190,62 +54,6 @@ GBR_TO_PCB_EXPORTER::~GBR_TO_PCB_EXPORTER()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Export data in Pcbnew format
|
|
||||||
* remember Pcbnew uses a Y reversed axis, so we must negate all Y coordinates
|
|
||||||
*/
|
|
||||||
void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event )
|
|
||||||
{
|
|
||||||
int layercount = 0;
|
|
||||||
|
|
||||||
GERBER_FILE_IMAGE_LIST* images = GetGerberLayout()->GetImagesList();
|
|
||||||
|
|
||||||
// Count the Gerber layers which are actually currently used
|
|
||||||
for( LAYER_NUM ii = 0; ii < (LAYER_NUM)images->ImagesMaxCount(); ++ii )
|
|
||||||
{
|
|
||||||
if( images->GetGbrImage( ii ) )
|
|
||||||
layercount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( layercount == 0 )
|
|
||||||
{
|
|
||||||
DisplayInfoMessage( this, _( "None of the Gerber layers contain any data" ) );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString fileDialogName( wxT( "noname." ) + KiCadPcbFileExtension );
|
|
||||||
wxString path = m_mruPath;
|
|
||||||
|
|
||||||
wxFileDialog filedlg( this, _( "Board File Name" ),
|
|
||||||
path, fileDialogName, PcbFileWildcard(),
|
|
||||||
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
||||||
|
|
||||||
if( filedlg.ShowModal() == wxID_CANCEL )
|
|
||||||
return;
|
|
||||||
|
|
||||||
wxFileName fileName = filedlg.GetPath();
|
|
||||||
|
|
||||||
/* Install a dialog frame to choose the mapping
|
|
||||||
* between gerber layers and Pcbnew layers
|
|
||||||
*/
|
|
||||||
LAYERS_MAP_DIALOG* layerdlg = new LAYERS_MAP_DIALOG( this );
|
|
||||||
int ok = layerdlg->ShowModal();
|
|
||||||
layerdlg->Destroy();
|
|
||||||
|
|
||||||
if( ok != wxID_OK )
|
|
||||||
return;
|
|
||||||
|
|
||||||
// If no extension was entered, then force the extension to be a KiCad PCB file
|
|
||||||
if( !fileName.HasExt() )
|
|
||||||
fileName.SetExt( KiCadPcbFileExtension );
|
|
||||||
|
|
||||||
m_mruPath = fileName.GetPath();
|
|
||||||
|
|
||||||
GBR_TO_PCB_EXPORTER gbr_exporter( this, fileName.GetFullPath() );
|
|
||||||
|
|
||||||
gbr_exporter.ExportPcb( layerdlg->GetLayersLookUpTable(), layerdlg->GetCopperLayersCount() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLayers )
|
bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLayers )
|
||||||
{
|
{
|
||||||
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
LOCALE_IO toggle; // toggles on, then off, the C locale.
|
||||||
|
|
|
@ -0,0 +1,164 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007-2014 Jean-Pierre Charras jp.charras at wanadoo.fr
|
||||||
|
* Copyright (C) 1992-2020 KiCad Developers, see change_log.txt for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, you may find one here:
|
||||||
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||||
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||||
|
* or you may write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <convert_to_biu.h>
|
||||||
|
#include <geometry/shape_poly_set.h>
|
||||||
|
#include <layers_id_colors_and_visibility.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct EXPORT_VIA
|
||||||
|
{
|
||||||
|
EXPORT_VIA( const wxPoint& aPos, int aSize, int aDrill ) :
|
||||||
|
m_Pos( aPos ),
|
||||||
|
m_Size( aSize ),
|
||||||
|
m_Drill( aDrill )
|
||||||
|
{ }
|
||||||
|
|
||||||
|
wxPoint m_Pos;
|
||||||
|
int m_Size;
|
||||||
|
int m_Drill;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class GERBER_DRAW_ITEM;
|
||||||
|
class GERBVIEW_FRAME;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper class to export a Gerber set of files to Pcbnew
|
||||||
|
*/
|
||||||
|
class GBR_TO_PCB_EXPORTER
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
GERBVIEW_FRAME* m_gerbview_frame; // the main gerber frame
|
||||||
|
wxString m_pcb_file_name; // BOARD file to write to
|
||||||
|
FILE* m_fp; // the board file
|
||||||
|
int m_pcbCopperLayersCount;
|
||||||
|
std::vector<EXPORT_VIA> m_vias;
|
||||||
|
public:
|
||||||
|
GBR_TO_PCB_EXPORTER( GERBVIEW_FRAME* aFrame, const wxString& aFileName );
|
||||||
|
~GBR_TO_PCB_EXPORTER();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function ExportPcb
|
||||||
|
* saves a board from a set of Gerber images.
|
||||||
|
*/
|
||||||
|
bool ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLayers );
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* collect holes from a drill layer.
|
||||||
|
* We'll use these later when writing pads & vias.
|
||||||
|
* @param aGbrItem
|
||||||
|
*/
|
||||||
|
void collect_hole( GERBER_DRAW_ITEM* aGbrItem );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write a via to the board file.
|
||||||
|
* Some of these will represent actual vias while others are used to represent
|
||||||
|
* holes in pads. (We can't generate actual pads because the Gerbers don't contain
|
||||||
|
* info on how to group them into modules.)
|
||||||
|
* @param aVia
|
||||||
|
*/
|
||||||
|
void export_via( const EXPORT_VIA& aVia );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write a non copper line or arc to the board file.
|
||||||
|
* @param aGbrItem = the Gerber item (line, arc) to export
|
||||||
|
* @param aLayer = the technical layer to use
|
||||||
|
*/
|
||||||
|
void export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write a non-copper polygon to the board file.
|
||||||
|
* @param aLayer = the technical layer to use
|
||||||
|
*/
|
||||||
|
void writePcbPolygon( const SHAPE_POLY_SET& aPolys, LAYER_NUM aLayer,
|
||||||
|
const wxPoint& aOffset = { 0, 0 } );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write a zone item to the board file.
|
||||||
|
* Currently: only experimental, for tests
|
||||||
|
* @param aGbrItem = the Gerber item (line, arc) to export
|
||||||
|
* @param aLayer = the technical layer to use
|
||||||
|
*/
|
||||||
|
void writePcbZoneItem( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write a track (or via) to the board file.
|
||||||
|
* @param aGbrItem = the Gerber item (line, arc, flashed) to export
|
||||||
|
* @param aLayer = the copper layer to use
|
||||||
|
*/
|
||||||
|
void export_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function export_flashed_copper_item
|
||||||
|
* write a synthetic pad to the board file.
|
||||||
|
* We can't create real pads because the Gerbers don't store grouping/footprint info.
|
||||||
|
* So we synthesize a pad with a via for the hole (if present) and a copper polygon for
|
||||||
|
* the pad.
|
||||||
|
* @param aGbrItem = the flashed Gerber item to export
|
||||||
|
*/
|
||||||
|
void export_flashed_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function export_segline_copper_item
|
||||||
|
* write a track (not via) to the board file.
|
||||||
|
* @param aGbrItem = the Gerber item (line only) to export
|
||||||
|
* @param aLayer = the copper layer to use
|
||||||
|
*/
|
||||||
|
void export_segline_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function export_segarc_copper_item
|
||||||
|
* write a set of tracks (arcs are approximated by track segments)
|
||||||
|
* to the board file.
|
||||||
|
* @param aGbrItem = the Gerber item (arc only) to export
|
||||||
|
* @param aLayer = the copper layer to use
|
||||||
|
*/
|
||||||
|
void export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, LAYER_NUM aLayer );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function writeCopperLineItem
|
||||||
|
* basic write function to write a a TRACK item
|
||||||
|
* to the board file, from a non flashed item
|
||||||
|
*/
|
||||||
|
void writeCopperLineItem( wxPoint& aStart, wxPoint& aEnd,
|
||||||
|
int aWidth, LAYER_NUM aLayer );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function writePcbHeader
|
||||||
|
* Write a very basic header to the board file
|
||||||
|
*/
|
||||||
|
void writePcbHeader( LAYER_NUM* aLayerLookUpTable );
|
||||||
|
|
||||||
|
/** In Pcbnew files units are mm for coordinates.
|
||||||
|
* So MapToPcbUnits converts internal gerbview to mm any pcbnew value
|
||||||
|
* @param aValue is a coordinate value to convert in mm
|
||||||
|
*/
|
||||||
|
double MapToPcbUnits( int aValue )
|
||||||
|
{
|
||||||
|
return aValue / IU_PER_MM;
|
||||||
|
}
|
||||||
|
};
|
|
@ -46,6 +46,7 @@
|
||||||
#include <tool/editor_conditions.h>
|
#include <tool/editor_conditions.h>
|
||||||
#include <tool/zoom_tool.h>
|
#include <tool/zoom_tool.h>
|
||||||
#include <tools/gerbview_actions.h>
|
#include <tools/gerbview_actions.h>
|
||||||
|
#include <tools/gerbview_inspection_tool.h>
|
||||||
#include <tools/gerbview_selection.h>
|
#include <tools/gerbview_selection.h>
|
||||||
#include <tools/gerbview_selection_tool.h>
|
#include <tools/gerbview_selection_tool.h>
|
||||||
#include <tools/gerbview_control.h>
|
#include <tools/gerbview_control.h>
|
||||||
|
@ -537,91 +538,6 @@ void GERBVIEW_FRAME::syncLayerBox( bool aRebuildLayerBox )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GERBVIEW_FRAME::Liste_D_Codes()
|
|
||||||
{
|
|
||||||
int ii, jj;
|
|
||||||
wxString Line;
|
|
||||||
wxArrayString list;
|
|
||||||
int curr_layer = GetActiveLayer();
|
|
||||||
|
|
||||||
double scale = 1.0;
|
|
||||||
wxString units;
|
|
||||||
|
|
||||||
switch( GetUserUnits() )
|
|
||||||
{
|
|
||||||
case EDA_UNITS::MILLIMETRES:
|
|
||||||
scale = IU_PER_MM;
|
|
||||||
units = "mm";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EDA_UNITS::INCHES:
|
|
||||||
scale = IU_PER_MILS * 1000;
|
|
||||||
units = "in";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EDA_UNITS::MILS:
|
|
||||||
scale = IU_PER_MILS;
|
|
||||||
units = "mil";
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
wxASSERT_MSG( false, "Invalid units" );
|
|
||||||
}
|
|
||||||
|
|
||||||
for( int layer = 0; layer < (int)ImagesMaxCount(); ++layer )
|
|
||||||
{
|
|
||||||
GERBER_FILE_IMAGE* gerber = GetGbrImage( layer );
|
|
||||||
|
|
||||||
if( gerber == NULL )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( gerber->GetDcodesCount() == 0 )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( layer == curr_layer )
|
|
||||||
Line.Printf( wxT( "*** Active layer (%2.2d) ***" ), layer + 1 );
|
|
||||||
else
|
|
||||||
Line.Printf( wxT( "*** layer %2.2d ***" ), layer + 1 );
|
|
||||||
|
|
||||||
list.Add( Line );
|
|
||||||
|
|
||||||
for( ii = 0, jj = 1; ii < TOOLS_MAX_COUNT; ii++ )
|
|
||||||
{
|
|
||||||
D_CODE* pt_D_code = gerber->GetDCODE( ii + FIRST_DCODE );
|
|
||||||
|
|
||||||
if( pt_D_code == NULL )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if( !pt_D_code->m_InUse && !pt_D_code->m_Defined )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Line.Printf( wxT( "tool %2.2d: D%2.2d V %.4f %s H %.4f %s %s attribute '%s'" ),
|
|
||||||
jj,
|
|
||||||
pt_D_code->m_Num_Dcode,
|
|
||||||
pt_D_code->m_Size.y / scale, units,
|
|
||||||
pt_D_code->m_Size.x / scale, units,
|
|
||||||
D_CODE::ShowApertureType( pt_D_code->m_Shape ),
|
|
||||||
pt_D_code->m_AperFunction.IsEmpty()? wxT( "none" ) : GetChars( pt_D_code->m_AperFunction )
|
|
||||||
);
|
|
||||||
|
|
||||||
if( !pt_D_code->m_Defined )
|
|
||||||
Line += wxT( " (not defined)" );
|
|
||||||
|
|
||||||
if( pt_D_code->m_InUse )
|
|
||||||
Line += wxT( " (in use)" );
|
|
||||||
|
|
||||||
list.Add( Line );
|
|
||||||
jj++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wxSingleChoiceDialog dlg( this, wxEmptyString, _( "D Codes" ), list, (void**) NULL,
|
|
||||||
wxCHOICEDLG_STYLE & ~wxCANCEL );
|
|
||||||
|
|
||||||
dlg.ShowModal();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void GERBVIEW_FRAME::SortLayersByX2Attributes()
|
void GERBVIEW_FRAME::SortLayersByX2Attributes()
|
||||||
{
|
{
|
||||||
auto remapping = GetImagesList()->SortImagesByZOrder();
|
auto remapping = GetImagesList()->SortImagesByZOrder();
|
||||||
|
@ -1145,6 +1061,7 @@ void GERBVIEW_FRAME::setupTools()
|
||||||
m_toolManager->RegisterTool( new COMMON_TOOLS );
|
m_toolManager->RegisterTool( new COMMON_TOOLS );
|
||||||
m_toolManager->RegisterTool( new GERBVIEW_SELECTION_TOOL );
|
m_toolManager->RegisterTool( new GERBVIEW_SELECTION_TOOL );
|
||||||
m_toolManager->RegisterTool( new GERBVIEW_CONTROL );
|
m_toolManager->RegisterTool( new GERBVIEW_CONTROL );
|
||||||
|
m_toolManager->RegisterTool( new GERBVIEW_INSPECTION_TOOL );
|
||||||
m_toolManager->RegisterTool( new ZOOM_TOOL );
|
m_toolManager->RegisterTool( new ZOOM_TOOL );
|
||||||
m_toolManager->InitTools();
|
m_toolManager->InitTools();
|
||||||
|
|
||||||
|
|
|
@ -387,8 +387,6 @@ public:
|
||||||
|
|
||||||
void ShowChangedLanguage() override;
|
void ShowChangedLanguage() override;
|
||||||
|
|
||||||
void Process_Special_Functions( wxCommandEvent& event );
|
|
||||||
|
|
||||||
/// Handles the changing of the highlighted component/net/attribute
|
/// Handles the changing of the highlighted component/net/attribute
|
||||||
void OnSelectHighlightChoice( wxCommandEvent& event );
|
void OnSelectHighlightChoice( wxCommandEvent& event );
|
||||||
|
|
||||||
|
@ -407,13 +405,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void OnSelectActiveLayer( wxCommandEvent& event );
|
void OnSelectActiveLayer( wxCommandEvent& event );
|
||||||
|
|
||||||
/**
|
|
||||||
* Function OnShowGerberSourceFile
|
|
||||||
* Call the preferred editor to show (and edit) the gerber source file
|
|
||||||
* loaded in the active layer
|
|
||||||
*/
|
|
||||||
void OnShowGerberSourceFile( wxCommandEvent& event );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function OnSelectDisplayMode
|
* Function OnSelectDisplayMode
|
||||||
* called on a display mode selection
|
* called on a display mode selection
|
||||||
|
@ -511,12 +502,6 @@ public:
|
||||||
*/
|
*/
|
||||||
bool LoadGerberJobFile( const wxString& aFileName );
|
bool LoadGerberJobFile( const wxString& aFileName );
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Size Items (Lines, Flashes) from DCodes List
|
|
||||||
*/
|
|
||||||
void Liste_D_Codes();
|
|
||||||
|
|
||||||
// PCB handling
|
// PCB handling
|
||||||
bool Clear_DrawLayers( bool query );
|
bool Clear_DrawLayers( bool query );
|
||||||
void Erase_Current_DrawLayer( bool query );
|
void Erase_Current_DrawLayer( bool query );
|
||||||
|
@ -529,9 +514,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void UpdateDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions );
|
void UpdateDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions );
|
||||||
|
|
||||||
// Conversion function
|
|
||||||
void ExportDataInPcbnewFormat( wxCommandEvent& event );
|
|
||||||
|
|
||||||
/* SaveCopyInUndoList() virtual
|
/* SaveCopyInUndoList() virtual
|
||||||
* currently: do nothing in GerbView.
|
* currently: do nothing in GerbView.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -38,19 +38,15 @@ enum gerbview_ids
|
||||||
{
|
{
|
||||||
ID_MAIN_MENUBAR = ID_END_LIST,
|
ID_MAIN_MENUBAR = ID_END_LIST,
|
||||||
|
|
||||||
ID_GERBVIEW_SHOW_LIST_DCODES,
|
|
||||||
ID_GERBVIEW_ERASE_ALL,
|
ID_GERBVIEW_ERASE_ALL,
|
||||||
ID_GERBVIEW_RELOAD_ALL,
|
ID_GERBVIEW_RELOAD_ALL,
|
||||||
ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
|
ID_TOOLBARH_GERBER_SELECT_ACTIVE_DCODE,
|
||||||
ID_GERBVIEW_SHOW_SOURCE,
|
|
||||||
ID_GERBVIEW_EXPORT_TO_PCBNEW,
|
|
||||||
|
|
||||||
ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE,
|
ID_GBR_AUX_TOOLBAR_PCB_CMP_CHOICE,
|
||||||
ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE,
|
ID_GBR_AUX_TOOLBAR_PCB_NET_CHOICE,
|
||||||
ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE,
|
ID_GBR_AUX_TOOLBAR_PCB_APERATTRIBUTES_CHOICE,
|
||||||
|
|
||||||
ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER,
|
ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER,
|
||||||
ID_GERBVIEW_ERASE_CURR_LAYER,
|
|
||||||
ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
|
ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR,
|
||||||
ID_TB_OPTIONS_SHOW_GBR_MODE_0,
|
ID_TB_OPTIONS_SHOW_GBR_MODE_0,
|
||||||
ID_TB_OPTIONS_SHOW_GBR_MODE_1,
|
ID_TB_OPTIONS_SHOW_GBR_MODE_1,
|
||||||
|
|
|
@ -146,10 +146,7 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
|
||||||
reload2_xpm );
|
reload2_xpm );
|
||||||
|
|
||||||
fileMenu->AppendSeparator();
|
fileMenu->AppendSeparator();
|
||||||
fileMenu->Add( _( "Export to Pcbnew..." ),
|
fileMenu->Add( GERBVIEW_ACTIONS::exportToPcbnew );
|
||||||
_( "Export data in Pcbnew format" ),
|
|
||||||
ID_GERBVIEW_EXPORT_TO_PCBNEW,
|
|
||||||
export_xpm );
|
|
||||||
|
|
||||||
fileMenu->AppendSeparator();
|
fileMenu->AppendSeparator();
|
||||||
fileMenu->Add( ACTIONS::print );
|
fileMenu->Add( ACTIONS::print );
|
||||||
|
@ -210,23 +207,14 @@ void GERBVIEW_FRAME::ReCreateMenuBar()
|
||||||
//
|
//
|
||||||
ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
|
ACTION_MENU* toolsMenu = new ACTION_MENU( false, selTool );
|
||||||
|
|
||||||
toolsMenu->Add( _( "&List DCodes..." ),
|
toolsMenu->Add( GERBVIEW_ACTIONS::showDCodes );
|
||||||
_( "List D-codes defined in Gerber files" ),
|
toolsMenu->Add( GERBVIEW_ACTIONS::showSource );
|
||||||
ID_GERBVIEW_SHOW_LIST_DCODES,
|
|
||||||
show_dcodenumber_xpm );
|
|
||||||
|
|
||||||
toolsMenu->Add( _( "&Show Source..." ),
|
|
||||||
_( "Show source file for the current layer" ),
|
|
||||||
ID_GERBVIEW_SHOW_SOURCE,
|
|
||||||
tools_xpm );
|
|
||||||
|
|
||||||
toolsMenu->Add( ACTIONS::measureTool );
|
toolsMenu->Add( ACTIONS::measureTool );
|
||||||
|
|
||||||
toolsMenu->AppendSeparator();
|
toolsMenu->AppendSeparator();
|
||||||
toolsMenu->Add( _( "Clear Current Layer..." ),
|
toolsMenu->Add( GERBVIEW_ACTIONS::eraseLayer );
|
||||||
_( "Clear the selected graphic layer" ),
|
|
||||||
ID_GERBVIEW_ERASE_CURR_LAYER,
|
|
||||||
delete_sheet_xpm );
|
|
||||||
|
|
||||||
//-- Preferences menu -----------------------------------------------
|
//-- Preferences menu -----------------------------------------------
|
||||||
//
|
//
|
||||||
|
|
|
@ -58,6 +58,29 @@ TOOL_ACTION GERBVIEW_ACTIONS::openZipFile( "gerbview.Control.openZipFile",
|
||||||
_( "Open a zipped archive (Gerber and Drill) file" ),
|
_( "Open a zipped archive (Gerber and Drill) file" ),
|
||||||
zip_xpm );
|
zip_xpm );
|
||||||
|
|
||||||
|
TOOL_ACTION GERBVIEW_ACTIONS::showDCodes( "gerbview.Inspection.showDCodes",
|
||||||
|
AS_GLOBAL, 0, "",
|
||||||
|
_( "List DCodes..." ),
|
||||||
|
_( "List D-codes defined in Gerber files" ),
|
||||||
|
show_dcodenumber_xpm );
|
||||||
|
|
||||||
|
TOOL_ACTION GERBVIEW_ACTIONS::showSource( "gerbview.Inspection.showSource",
|
||||||
|
AS_GLOBAL, 0, "",
|
||||||
|
_( "Show Source..." ),
|
||||||
|
_( "Show source file for the current layer" ),
|
||||||
|
tools_xpm );
|
||||||
|
|
||||||
|
TOOL_ACTION GERBVIEW_ACTIONS::exportToPcbnew( "gerbview.Control.exportToPcbnew",
|
||||||
|
AS_GLOBAL, 0, "",
|
||||||
|
_( "Export to Pcbnew..." ),
|
||||||
|
_( "Export data in Pcbnew format" ),
|
||||||
|
export_xpm );
|
||||||
|
|
||||||
|
TOOL_ACTION GERBVIEW_ACTIONS::eraseLayer( "gerbview.Control.eraseLayer",
|
||||||
|
AS_GLOBAL, 0, "",
|
||||||
|
_( "Clear Current Layer..." ), _( "Clear the selected graphic layer" ),
|
||||||
|
delete_sheet_xpm );
|
||||||
|
|
||||||
TOOL_ACTION GERBVIEW_ACTIONS::layerChanged( "gerbview.Control.layerChanged",
|
TOOL_ACTION GERBVIEW_ACTIONS::layerChanged( "gerbview.Control.layerChanged",
|
||||||
AS_GLOBAL, 0, "", "", "",
|
AS_GLOBAL, 0, "", "", "",
|
||||||
nullptr, AF_NOTIFY );
|
nullptr, AF_NOTIFY );
|
||||||
|
|
|
@ -55,6 +55,10 @@ public:
|
||||||
|
|
||||||
/// Activation of the edit tool
|
/// Activation of the edit tool
|
||||||
static TOOL_ACTION properties;
|
static TOOL_ACTION properties;
|
||||||
|
static TOOL_ACTION showDCodes;
|
||||||
|
static TOOL_ACTION showSource;
|
||||||
|
|
||||||
|
static TOOL_ACTION exportToPcbnew;
|
||||||
|
|
||||||
// Display modes
|
// Display modes
|
||||||
static TOOL_ACTION linesDisplayOutlines;
|
static TOOL_ACTION linesDisplayOutlines;
|
||||||
|
@ -68,6 +72,7 @@ public:
|
||||||
// Layer control
|
// Layer control
|
||||||
static TOOL_ACTION layerPrev;
|
static TOOL_ACTION layerPrev;
|
||||||
static TOOL_ACTION layerNext;
|
static TOOL_ACTION layerNext;
|
||||||
|
static TOOL_ACTION eraseLayer;
|
||||||
|
|
||||||
static TOOL_ACTION layerChanged; // notification
|
static TOOL_ACTION layerChanged; // notification
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,17 @@
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <view/view.h>
|
#include <confirm.h>
|
||||||
|
#include <dialogs/dialog_layers_select_to_pcb.h>
|
||||||
|
#include <export_to_pcbnew.h>
|
||||||
|
#include <gerber_file_image_list.h>
|
||||||
#include <gerbview_painter.h>
|
#include <gerbview_painter.h>
|
||||||
#include <gerbview_frame.h>
|
#include <gerbview_frame.h>
|
||||||
#include <tool/tool_manager.h>
|
|
||||||
#include <menus_helpers.h>
|
#include <menus_helpers.h>
|
||||||
|
#include <tool/tool_manager.h>
|
||||||
|
#include <view/view.h>
|
||||||
|
#include <wildcards_and_files_ext.h>
|
||||||
|
|
||||||
#include "gerbview_actions.h"
|
#include "gerbview_actions.h"
|
||||||
#include "gerbview_control.h"
|
#include "gerbview_control.h"
|
||||||
#include "gerbview_selection_tool.h"
|
#include "gerbview_selection_tool.h"
|
||||||
|
@ -75,6 +81,61 @@ int GERBVIEW_CONTROL::OpenZipFile( const TOOL_EVENT& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GERBVIEW_CONTROL::ExportToPcbnew( const TOOL_EVENT& aEvent )
|
||||||
|
{
|
||||||
|
int layercount = 0;
|
||||||
|
|
||||||
|
GERBER_FILE_IMAGE_LIST* images = m_frame->GetGerberLayout()->GetImagesList();
|
||||||
|
|
||||||
|
// Count the Gerber layers which are actually currently used
|
||||||
|
for( LAYER_NUM ii = 0; ii < (LAYER_NUM)images->ImagesMaxCount(); ++ii )
|
||||||
|
{
|
||||||
|
if( images->GetGbrImage( ii ) )
|
||||||
|
layercount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( layercount == 0 )
|
||||||
|
{
|
||||||
|
DisplayInfoMessage( m_frame, _( "None of the Gerber layers contain any data" ) );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxString fileDialogName( wxT( "noname." ) + KiCadPcbFileExtension );
|
||||||
|
wxString path = m_frame->GetMruPath();
|
||||||
|
|
||||||
|
wxFileDialog filedlg( m_frame, _( "Board File Name" ),
|
||||||
|
path, fileDialogName, PcbFileWildcard(),
|
||||||
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
||||||
|
|
||||||
|
if( filedlg.ShowModal() == wxID_CANCEL )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
wxFileName fileName = filedlg.GetPath();
|
||||||
|
|
||||||
|
/* Install a dialog frame to choose the mapping
|
||||||
|
* between gerber layers and Pcbnew layers
|
||||||
|
*/
|
||||||
|
LAYERS_MAP_DIALOG* layerdlg = new LAYERS_MAP_DIALOG( m_frame );
|
||||||
|
int ok = layerdlg->ShowModal();
|
||||||
|
layerdlg->Destroy();
|
||||||
|
|
||||||
|
if( ok != wxID_OK )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
// If no extension was entered, then force the extension to be a KiCad PCB file
|
||||||
|
if( !fileName.HasExt() )
|
||||||
|
fileName.SetExt( KiCadPcbFileExtension );
|
||||||
|
|
||||||
|
m_frame->SetMruPath( fileName.GetPath() );
|
||||||
|
|
||||||
|
GBR_TO_PCB_EXPORTER gbr_exporter( m_frame, fileName.GetFullPath() );
|
||||||
|
|
||||||
|
gbr_exporter.ExportPcb( layerdlg->GetLayersLookUpTable(), layerdlg->GetCopperLayersCount() );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int GERBVIEW_CONTROL::HighlightControl( const TOOL_EVENT& aEvent )
|
int GERBVIEW_CONTROL::HighlightControl( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( getView()->GetPainter() )->GetSettings();
|
auto settings = static_cast<KIGFX::GERBVIEW_PAINTER*>( getView()->GetPainter() )->GetSettings();
|
||||||
|
@ -205,6 +266,15 @@ int GERBVIEW_CONTROL::LayerPrev( const TOOL_EVENT& aEvent )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GERBVIEW_CONTROL::EraseLayer( const TOOL_EVENT& aEvent )
|
||||||
|
{
|
||||||
|
m_frame->Erase_Current_DrawLayer( true );
|
||||||
|
m_frame->ClearMsgPanel();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int GERBVIEW_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
|
int GERBVIEW_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
GERBVIEW_SELECTION_TOOL* selTool = m_toolMgr->GetTool<GERBVIEW_SELECTION_TOOL>();
|
GERBVIEW_SELECTION_TOOL* selTool = m_toolMgr->GetTool<GERBVIEW_SELECTION_TOOL>();
|
||||||
|
@ -233,6 +303,7 @@ void GERBVIEW_CONTROL::setTransitions()
|
||||||
Go( &GERBVIEW_CONTROL::OpenDrillFile, GERBVIEW_ACTIONS::openDrillFile.MakeEvent() );
|
Go( &GERBVIEW_CONTROL::OpenDrillFile, GERBVIEW_ACTIONS::openDrillFile.MakeEvent() );
|
||||||
Go( &GERBVIEW_CONTROL::OpenJobFile, GERBVIEW_ACTIONS::openJobFile.MakeEvent() );
|
Go( &GERBVIEW_CONTROL::OpenJobFile, GERBVIEW_ACTIONS::openJobFile.MakeEvent() );
|
||||||
Go( &GERBVIEW_CONTROL::OpenZipFile, GERBVIEW_ACTIONS::openZipFile.MakeEvent() );
|
Go( &GERBVIEW_CONTROL::OpenZipFile, GERBVIEW_ACTIONS::openZipFile.MakeEvent() );
|
||||||
|
Go( &GERBVIEW_CONTROL::ExportToPcbnew, GERBVIEW_ACTIONS::exportToPcbnew.MakeEvent() );
|
||||||
Go( &GERBVIEW_CONTROL::Print, ACTIONS::print.MakeEvent() );
|
Go( &GERBVIEW_CONTROL::Print, ACTIONS::print.MakeEvent() );
|
||||||
|
|
||||||
Go( &GERBVIEW_CONTROL::HighlightControl, GERBVIEW_ACTIONS::highlightClear.MakeEvent() );
|
Go( &GERBVIEW_CONTROL::HighlightControl, GERBVIEW_ACTIONS::highlightClear.MakeEvent() );
|
||||||
|
@ -242,6 +313,7 @@ void GERBVIEW_CONTROL::setTransitions()
|
||||||
|
|
||||||
Go( &GERBVIEW_CONTROL::LayerNext, GERBVIEW_ACTIONS::layerNext.MakeEvent() );
|
Go( &GERBVIEW_CONTROL::LayerNext, GERBVIEW_ACTIONS::layerNext.MakeEvent() );
|
||||||
Go( &GERBVIEW_CONTROL::LayerPrev, GERBVIEW_ACTIONS::layerPrev.MakeEvent() );
|
Go( &GERBVIEW_CONTROL::LayerPrev, GERBVIEW_ACTIONS::layerPrev.MakeEvent() );
|
||||||
|
Go( &GERBVIEW_CONTROL::EraseLayer, GERBVIEW_ACTIONS::eraseLayer.MakeEvent() );
|
||||||
|
|
||||||
Go( &GERBVIEW_CONTROL::DisplayControl, GERBVIEW_ACTIONS::linesDisplayOutlines.MakeEvent() );
|
Go( &GERBVIEW_CONTROL::DisplayControl, GERBVIEW_ACTIONS::linesDisplayOutlines.MakeEvent() );
|
||||||
Go( &GERBVIEW_CONTROL::DisplayControl, GERBVIEW_ACTIONS::flashedDisplayOutlines.MakeEvent() );
|
Go( &GERBVIEW_CONTROL::DisplayControl, GERBVIEW_ACTIONS::flashedDisplayOutlines.MakeEvent() );
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
// Layer control
|
// Layer control
|
||||||
int LayerNext( const TOOL_EVENT& aEvent );
|
int LayerNext( const TOOL_EVENT& aEvent );
|
||||||
int LayerPrev( const TOOL_EVENT& aEvent );
|
int LayerPrev( const TOOL_EVENT& aEvent );
|
||||||
|
int EraseLayer( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
// Files
|
// Files
|
||||||
int OpenGerber( const TOOL_EVENT& aEvent );
|
int OpenGerber( const TOOL_EVENT& aEvent );
|
||||||
|
@ -57,6 +58,7 @@ public:
|
||||||
int HighlightControl( const TOOL_EVENT& aEvent );
|
int HighlightControl( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
// Miscellaneous
|
// Miscellaneous
|
||||||
|
int ExportToPcbnew( const TOOL_EVENT& aEvent );
|
||||||
int UpdateMessagePanel( const TOOL_EVENT& aEvent );
|
int UpdateMessagePanel( const TOOL_EVENT& aEvent );
|
||||||
int Print( const TOOL_EVENT& aEvent );
|
int Print( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,331 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Jon Evans <jon@craftyjon.com>
|
||||||
|
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <base_struct.h>
|
||||||
|
#include <bitmaps.h>
|
||||||
|
#include <class_draw_panel_gal.h>
|
||||||
|
#include <dialogs/dialog_layers_select_to_pcb.h>
|
||||||
|
#include <gestfich.h>
|
||||||
|
#include <gerber_file_image.h>
|
||||||
|
#include <gerbview_id.h>
|
||||||
|
#include "gerbview_inspection_tool.h"
|
||||||
|
#include "gerbview_actions.h"
|
||||||
|
#include <painter.h>
|
||||||
|
#include <preview_items/ruler_item.h>
|
||||||
|
#include <preview_items/selection_area.h>
|
||||||
|
#include <tool/tool_event.h>
|
||||||
|
#include <tool/tool_manager.h>
|
||||||
|
#include <view/view.h>
|
||||||
|
#include <view/view_controls.h>
|
||||||
|
#include <view/view_group.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GERBVIEW_INSPECTION_TOOL::GERBVIEW_INSPECTION_TOOL() :
|
||||||
|
TOOL_INTERACTIVE( "gerbview.Inspection" ),
|
||||||
|
m_frame( nullptr )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GERBVIEW_INSPECTION_TOOL::~GERBVIEW_INSPECTION_TOOL()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GERBVIEW_INSPECTION_TOOL::Init()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GERBVIEW_INSPECTION_TOOL::Reset( RESET_REASON aReason )
|
||||||
|
{
|
||||||
|
m_frame = getEditFrame<GERBVIEW_FRAME>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GERBVIEW_INSPECTION_TOOL::ShowDCodes( const TOOL_EVENT& aEvent )
|
||||||
|
{
|
||||||
|
int ii, jj;
|
||||||
|
wxString Line;
|
||||||
|
wxArrayString list;
|
||||||
|
int curr_layer = m_frame->GetActiveLayer();
|
||||||
|
|
||||||
|
double scale = 1.0;
|
||||||
|
wxString units;
|
||||||
|
|
||||||
|
switch( m_frame->GetUserUnits() )
|
||||||
|
{
|
||||||
|
case EDA_UNITS::MILLIMETRES:
|
||||||
|
scale = IU_PER_MM;
|
||||||
|
units = "mm";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EDA_UNITS::INCHES:
|
||||||
|
scale = IU_PER_MILS * 1000;
|
||||||
|
units = "in";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EDA_UNITS::MILS:
|
||||||
|
scale = IU_PER_MILS;
|
||||||
|
units = "mil";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
wxASSERT_MSG( false, "Invalid units" );
|
||||||
|
}
|
||||||
|
|
||||||
|
for( unsigned int layer = 0; layer < m_frame->ImagesMaxCount(); ++layer )
|
||||||
|
{
|
||||||
|
GERBER_FILE_IMAGE* gerber = m_frame->GetGbrImage( layer );
|
||||||
|
|
||||||
|
if( !gerber )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( gerber->GetDcodesCount() == 0 )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( curr_layer == static_cast<int>( layer ) )
|
||||||
|
Line.Printf( wxT( "*** Active layer (%2.2d) ***" ), layer + 1 );
|
||||||
|
else
|
||||||
|
Line.Printf( wxT( "*** layer %2.2d ***" ), layer + 1 );
|
||||||
|
|
||||||
|
list.Add( Line );
|
||||||
|
|
||||||
|
for( ii = 0, jj = 1; ii < TOOLS_MAX_COUNT; ii++ )
|
||||||
|
{
|
||||||
|
D_CODE* pt_D_code = gerber->GetDCODE( ii + FIRST_DCODE );
|
||||||
|
|
||||||
|
if( pt_D_code == NULL )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if( !pt_D_code->m_InUse && !pt_D_code->m_Defined )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Line.Printf( wxT( "tool %2.2d: D%2.2d V %.4f %s H %.4f %s %s attribute '%s'" ),
|
||||||
|
jj,
|
||||||
|
pt_D_code->m_Num_Dcode,
|
||||||
|
pt_D_code->m_Size.y / scale, units,
|
||||||
|
pt_D_code->m_Size.x / scale, units,
|
||||||
|
D_CODE::ShowApertureType( pt_D_code->m_Shape ),
|
||||||
|
pt_D_code->m_AperFunction.IsEmpty()? wxT( "none" ) : GetChars( pt_D_code->m_AperFunction )
|
||||||
|
);
|
||||||
|
|
||||||
|
if( !pt_D_code->m_Defined )
|
||||||
|
Line += wxT( " (not defined)" );
|
||||||
|
|
||||||
|
if( pt_D_code->m_InUse )
|
||||||
|
Line += wxT( " (in use)" );
|
||||||
|
|
||||||
|
list.Add( Line );
|
||||||
|
jj++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSingleChoiceDialog dlg( m_frame, wxEmptyString, _( "D Codes" ), list, (void**) NULL,
|
||||||
|
wxCHOICEDLG_STYLE & ~wxCANCEL );
|
||||||
|
|
||||||
|
dlg.ShowModal();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GERBVIEW_INSPECTION_TOOL::ShowSource( const TOOL_EVENT& aEvent )
|
||||||
|
{
|
||||||
|
int layer = m_frame->GetActiveLayer();
|
||||||
|
GERBER_FILE_IMAGE* gerber_layer = m_frame->GetGbrImage( layer );
|
||||||
|
|
||||||
|
if( gerber_layer )
|
||||||
|
{
|
||||||
|
wxString editorname = Pgm().GetEditorName();
|
||||||
|
|
||||||
|
if( !editorname.IsEmpty() )
|
||||||
|
{
|
||||||
|
wxFileName fn( gerber_layer->m_FileName );
|
||||||
|
|
||||||
|
// Call the editor only if the Gerber/drill source file is available.
|
||||||
|
// This is not always the case, because it can be a temporary file
|
||||||
|
// if it comes from a zip archive.
|
||||||
|
if( !fn.FileExists() )
|
||||||
|
{
|
||||||
|
wxString msg;
|
||||||
|
msg.Printf( _( "Source file \"%s\" is not available" ),
|
||||||
|
GetChars( fn.GetFullPath() ) );
|
||||||
|
wxMessageBox( msg );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ExecuteFile( m_frame, editorname, QuoteFullPath( fn ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
wxMessageBox( _( "No editor defined. Please select one" ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxString msg;
|
||||||
|
msg.Printf( _( "No file loaded on the active layer %d" ), layer + 1 );
|
||||||
|
wxMessageBox( msg );
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int GERBVIEW_INSPECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
|
||||||
|
{
|
||||||
|
auto& view = *getView();
|
||||||
|
auto& controls = *getViewControls();
|
||||||
|
auto previous_settings = controls.GetSettings();
|
||||||
|
|
||||||
|
std::string tool = aEvent.GetCommandStr().get();
|
||||||
|
m_frame->PushTool( tool );
|
||||||
|
Activate();
|
||||||
|
|
||||||
|
KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
|
||||||
|
|
||||||
|
EDA_UNITS units = m_frame->GetUserUnits();
|
||||||
|
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
|
||||||
|
|
||||||
|
view.Add( &ruler );
|
||||||
|
view.SetVisible( &ruler, false );
|
||||||
|
|
||||||
|
bool originSet = false;
|
||||||
|
|
||||||
|
controls.ShowCursor( true );
|
||||||
|
|
||||||
|
auto setCursor =
|
||||||
|
[&]()
|
||||||
|
{
|
||||||
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MEASURE );
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set initial cursor
|
||||||
|
setCursor();
|
||||||
|
|
||||||
|
while( TOOL_EVENT* evt = Wait() )
|
||||||
|
{
|
||||||
|
setCursor();
|
||||||
|
const VECTOR2I cursorPos = controls.GetCursorPosition();
|
||||||
|
|
||||||
|
auto clearRuler =
|
||||||
|
[&] ()
|
||||||
|
{
|
||||||
|
view.SetVisible( &ruler, false );
|
||||||
|
controls.SetAutoPan( false );
|
||||||
|
controls.CaptureCursor( false );
|
||||||
|
originSet = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if( evt->IsCancelInteractive() )
|
||||||
|
{
|
||||||
|
if( originSet )
|
||||||
|
{
|
||||||
|
clearRuler();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_frame->PopTool( tool );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if( evt->IsActivate() )
|
||||||
|
{
|
||||||
|
if( originSet )
|
||||||
|
clearRuler();
|
||||||
|
|
||||||
|
if( evt->IsMoveTool() )
|
||||||
|
{
|
||||||
|
// leave ourselves on the stack so we come back after the move
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_frame->PopTool( tool );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// click or drag starts
|
||||||
|
else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
|
||||||
|
{
|
||||||
|
twoPtMgr.SetOrigin( cursorPos );
|
||||||
|
twoPtMgr.SetEnd( cursorPos );
|
||||||
|
|
||||||
|
controls.CaptureCursor( true );
|
||||||
|
controls.SetAutoPan( true );
|
||||||
|
|
||||||
|
originSet = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// second click or mouse up after drag ends
|
||||||
|
else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
|
||||||
|
{
|
||||||
|
originSet = false;
|
||||||
|
|
||||||
|
controls.SetAutoPan( false );
|
||||||
|
controls.CaptureCursor( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// move or drag when origin set updates rules
|
||||||
|
else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
|
||||||
|
{
|
||||||
|
twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) );
|
||||||
|
twoPtMgr.SetEnd( cursorPos );
|
||||||
|
|
||||||
|
view.SetVisible( &ruler, true );
|
||||||
|
view.Update( &ruler, KIGFX::GEOMETRY );
|
||||||
|
}
|
||||||
|
|
||||||
|
else if( evt->IsAction( &ACTIONS::toggleUnits )
|
||||||
|
|| evt->IsAction( &ACTIONS::updateUnits ) )
|
||||||
|
{
|
||||||
|
if( m_frame->GetUserUnits() != units )
|
||||||
|
{
|
||||||
|
units = m_frame->GetUserUnits();
|
||||||
|
ruler.SwitchUnits( units );
|
||||||
|
view.Update( &ruler, KIGFX::GEOMETRY );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if( evt->IsClick( BUT_RIGHT ) )
|
||||||
|
{
|
||||||
|
m_menu.ShowContextMenu( m_frame->GetCurrentSelection() );
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
evt->SetPassEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
view.SetVisible( &ruler, false );
|
||||||
|
view.Remove( &ruler );
|
||||||
|
controls.ApplySettings( previous_settings );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GERBVIEW_INSPECTION_TOOL::setTransitions()
|
||||||
|
{
|
||||||
|
Go( &GERBVIEW_INSPECTION_TOOL::ShowSource, GERBVIEW_ACTIONS::showSource.MakeEvent() );
|
||||||
|
Go( &GERBVIEW_INSPECTION_TOOL::ShowDCodes, GERBVIEW_ACTIONS::showDCodes.MakeEvent() );
|
||||||
|
Go( &GERBVIEW_INSPECTION_TOOL::MeasureTool, ACTIONS::measureTool.MakeEvent() );
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GERBVIEW_INSPECTION_TOOL_H
|
||||||
|
#define GERBVIEW_INSPECTION_TOOL_H
|
||||||
|
|
||||||
|
#include <tool/tool_event.h>
|
||||||
|
#include <tool/tool_interactive.h>
|
||||||
|
#include <gerbview_frame.h>
|
||||||
|
|
||||||
|
class GERBVIEW_INSPECTION_TOOL : public TOOL_INTERACTIVE
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GERBVIEW_INSPECTION_TOOL();
|
||||||
|
~GERBVIEW_INSPECTION_TOOL();
|
||||||
|
|
||||||
|
/// @copydoc TOOL_BASE::Init()
|
||||||
|
bool Init() override;
|
||||||
|
|
||||||
|
/// @copydoc TOOL_BASE::Reset()
|
||||||
|
void Reset( RESET_REASON aReason ) override;
|
||||||
|
|
||||||
|
///> Launches a tool to measure between points
|
||||||
|
int MeasureTool( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
///> Show a list of the DCodes
|
||||||
|
int ShowDCodes( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
///> Show the source for the gerber file
|
||||||
|
int ShowSource( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
///> Sets up handlers for various events.
|
||||||
|
void setTransitions() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GERBVIEW_FRAME* m_frame; // Pointer to the parent frame.
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -312,7 +312,6 @@ void GERBVIEW_SELECTION_TOOL::setTransitions()
|
||||||
Go( &GERBVIEW_SELECTION_TOOL::ClearSelection, GERBVIEW_ACTIONS::selectionClear.MakeEvent() );
|
Go( &GERBVIEW_SELECTION_TOOL::ClearSelection, GERBVIEW_ACTIONS::selectionClear.MakeEvent() );
|
||||||
Go( &GERBVIEW_SELECTION_TOOL::SelectItem, GERBVIEW_ACTIONS::selectItem.MakeEvent() );
|
Go( &GERBVIEW_SELECTION_TOOL::SelectItem, GERBVIEW_ACTIONS::selectItem.MakeEvent() );
|
||||||
Go( &GERBVIEW_SELECTION_TOOL::UnselectItem, GERBVIEW_ACTIONS::unselectItem.MakeEvent() );
|
Go( &GERBVIEW_SELECTION_TOOL::UnselectItem, GERBVIEW_ACTIONS::unselectItem.MakeEvent() );
|
||||||
Go( &GERBVIEW_SELECTION_TOOL::MeasureTool, ACTIONS::measureTool.MakeEvent() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -556,138 +555,3 @@ void GERBVIEW_SELECTION_TOOL::unselectVisually( EDA_ITEM* aItem )
|
||||||
|
|
||||||
getView()->Update( &m_selection );
|
getView()->Update( &m_selection );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
|
|
||||||
{
|
|
||||||
auto& view = *getView();
|
|
||||||
auto& controls = *getViewControls();
|
|
||||||
auto previous_settings = controls.GetSettings();
|
|
||||||
|
|
||||||
std::string tool = aEvent.GetCommandStr().get();
|
|
||||||
m_frame->PushTool( tool );
|
|
||||||
Activate();
|
|
||||||
|
|
||||||
KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
|
|
||||||
|
|
||||||
EDA_UNITS units = m_frame->GetUserUnits();
|
|
||||||
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
|
|
||||||
|
|
||||||
view.Add( &ruler );
|
|
||||||
view.SetVisible( &ruler, false );
|
|
||||||
|
|
||||||
bool originSet = false;
|
|
||||||
|
|
||||||
controls.ShowCursor( true );
|
|
||||||
|
|
||||||
auto setCursor =
|
|
||||||
[&]()
|
|
||||||
{
|
|
||||||
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MEASURE );
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set initial cursor
|
|
||||||
setCursor();
|
|
||||||
|
|
||||||
while( TOOL_EVENT* evt = Wait() )
|
|
||||||
{
|
|
||||||
setCursor();
|
|
||||||
const VECTOR2I cursorPos = controls.GetCursorPosition();
|
|
||||||
|
|
||||||
auto clearRuler =
|
|
||||||
[&] ()
|
|
||||||
{
|
|
||||||
view.SetVisible( &ruler, false );
|
|
||||||
controls.SetAutoPan( false );
|
|
||||||
controls.CaptureCursor( false );
|
|
||||||
originSet = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
if( evt->IsCancelInteractive() )
|
|
||||||
{
|
|
||||||
if( originSet )
|
|
||||||
{
|
|
||||||
clearRuler();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_frame->PopTool( tool );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if( evt->IsActivate() )
|
|
||||||
{
|
|
||||||
if( originSet )
|
|
||||||
clearRuler();
|
|
||||||
|
|
||||||
if( evt->IsMoveTool() )
|
|
||||||
{
|
|
||||||
// leave ourselves on the stack so we come back after the move
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_frame->PopTool( tool );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// click or drag starts
|
|
||||||
else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
|
|
||||||
{
|
|
||||||
twoPtMgr.SetOrigin( cursorPos );
|
|
||||||
twoPtMgr.SetEnd( cursorPos );
|
|
||||||
|
|
||||||
controls.CaptureCursor( true );
|
|
||||||
controls.SetAutoPan( true );
|
|
||||||
|
|
||||||
originSet = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// second click or mouse up after drag ends
|
|
||||||
else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
|
|
||||||
{
|
|
||||||
originSet = false;
|
|
||||||
|
|
||||||
controls.SetAutoPan( false );
|
|
||||||
controls.CaptureCursor( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
// move or drag when origin set updates rules
|
|
||||||
else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
|
|
||||||
{
|
|
||||||
twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) );
|
|
||||||
twoPtMgr.SetEnd( cursorPos );
|
|
||||||
|
|
||||||
view.SetVisible( &ruler, true );
|
|
||||||
view.Update( &ruler, KIGFX::GEOMETRY );
|
|
||||||
}
|
|
||||||
|
|
||||||
else if( evt->IsAction( &ACTIONS::toggleUnits )
|
|
||||||
|| evt->IsAction( &ACTIONS::updateUnits ) )
|
|
||||||
{
|
|
||||||
if( m_frame->GetUserUnits() != units )
|
|
||||||
{
|
|
||||||
units = m_frame->GetUserUnits();
|
|
||||||
ruler.SwitchUnits( units );
|
|
||||||
view.Update( &ruler, KIGFX::GEOMETRY );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if( evt->IsClick( BUT_RIGHT ) )
|
|
||||||
{
|
|
||||||
m_menu.ShowContextMenu( m_selection );
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
evt->SetPassEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
view.SetVisible( &ruler, false );
|
|
||||||
view.Remove( &ruler );
|
|
||||||
controls.ApplySettings( previous_settings );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -81,9 +81,6 @@ public:
|
||||||
int UnselectItem( const TOOL_EVENT& aEvent );
|
int UnselectItem( const TOOL_EVENT& aEvent );
|
||||||
int UnselectItems( const TOOL_EVENT& aEvent );
|
int UnselectItems( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
///> Launches a tool to measure between points
|
|
||||||
int MeasureTool( const TOOL_EVENT& aEvent );
|
|
||||||
|
|
||||||
///> Sets up handlers for various events.
|
///> Sets up handlers for various events.
|
||||||
void setTransitions() override;
|
void setTransitions() override;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue