All my series of “Learning to Develop KiCad” posts are listed in FAQ
Index:
- Use cases in regexp filter used during DDR4 routing
- Add a Dialog
- Add Netlist in the Dialog
- Add two levels data items
- Code reading / analysis of length calculation in Length Tuning Tool
Here is translation from my Chinese article.
I didn’t find a proper platform to share my articles in English. I tried Medium, but I found it may not be better than KiCad forum.
I’m reading current length tuning implementation inside KiCad, and want to try to improve it. But first, I need to show a dialog, something similar to Net Inspector, but functionality like Plugin KiCad Length Matching. The dev doc for KiCad has only samples about PCB TOOLS, too little information to start dev for KiCad. So I wrote articles while I am doing experiments on dev for KiCad, to leave some more information about it.
First, I need to add a dialog like this:
As you know, the KiCad is based on wxWidgets, and all its dialog is designed with wxFormBuilder, which saves design file as .fbp format, and generate _base.h/.cpp files / classes.
After started wxFormBuilder, it created an empty project by default. Change its name and other properties like this:
and change properties for the project like this
Add a “Dialog” in Forms tab
Change properties of the Dialog
And we make the dialog as how Net Inspector does: who is derived from DIALOG_SHIM
Add more controls:
And change their default properties (especially their names)
Save the project under KiCad Source Code/pcbnew/dialogs/ and click the left corner GEAR button to generate C++ code
Now, there are three files here
Next, we need to define our customized subclass DIALOG_LENGTH_TUNING like this:
DIALOG_LENGTH_TUNING.h
/*
* License is omitted
*/
#pragma once
#include <board.h>
#include <optional>
#include <dialog_length_tuning_base.h>
class PCB_EDIT_FRAME;
class NETINFO_ITEM;
class BOARD;
class BOARD_ITEM;
class CN_ITEM;
class EDA_PATTERN_MATCH;
class PCB_TRACK;
/**
* Event sent to parent when dialog is mode-less.
*/
wxDECLARE_EVENT( EDA_EVT_CLOSE_LENGTH_TUNING_DIALOG, wxCommandEvent );
class DIALOG_LENGTH_TUNING : public DIALOG_LENGTH_TUNING_BASE, public BOARD_LISTENER
{
public:
DIALOG_LENGTH_TUNING( PCB_EDIT_FRAME* aParent );
~DIALOG_LENGTH_TUNING();
};
DIALOG_LENGTH_TUNING.cpp
/*
* License is omitted
*/
#include <dialog_length_tuning.h>
#include <pcb_edit_frame.h>
wxDEFINE_EVENT( EDA_EVT_CLOSE_LENGTH_TUNING_DIALOG, wxCommandEvent );
DIALOG_LENGTH_TUNING::DIALOG_LENGTH_TUNING( PCB_EDIT_FRAME* aParent ) :
DIALOG_LENGTH_TUNING_BASE( aParent )
{
}
DIALOG_LENGTH_TUNING::~DIALOG_LENGTH_TUNING()
{
}
Modify current KiCad Source Code, to open our new dialog in UI:
pcbnew/CMakeLists.txt
pcbnew/pcb_edit_frame.h
pcbnew/pcb_edit_frame.cpp
pcbnew/tools/pcb_actions.h
pcbnew/tools/pcb_actions.cpp
pcbnew/menubar_pcb_editor.cpp
pcbnew/tools/board_inspection_tool.h
pcbnew/tools/board_inspection_tool.cpp
if all goes well, and you build kicad now, and run it, there will be a new item named Length Tuning, inside Inspect menu, and click it then shows:
All the code is here
Hope this could be helpful for you.