106 changed files with 9599 additions and 692 deletions
-
23api/CMakeLists.txt
-
91api/enums/enum_exporter.cpp
-
116api/proto/board/board.proto
-
151api/proto/board/board_commands.proto
-
449api/proto/board/board_types.proto
-
5api/proto/common/commands/base_commands.proto
-
160api/proto/common/commands/editor_commands.proto
-
34api/proto/common/commands/project_commands.proto
-
4api/proto/common/envelope.proto
-
191api/proto/common/types/base_types.proto
-
119api/proto/common/types/enums.proto
-
35api/proto/common/types/project_settings.proto
-
24api/proto/schematic/schematic_commands.proto
-
75api/proto/schematic/schematic_types.proto
-
16common/CMakeLists.txt
-
436common/api/api_enums.cpp
-
21common/api/api_handler.cpp
-
32common/api/api_handler_common.cpp
-
353common/api/api_handler_editor.cpp
-
3common/api/api_plugin.cpp
-
46common/api/api_plugin_manager.cpp
-
26common/api/api_server.cpp
-
80common/api/api_utils.cpp
-
4common/dialogs/panel_plugin_settings.cpp
-
44common/eda_draw_frame.cpp
-
9common/eda_shape.cpp
-
5common/pgm_base.cpp
-
9common/tool/actions.cpp
-
9eeschema/CMakeLists.txt
-
305eeschema/api/api_handler_sch.cpp
-
74eeschema/api/api_handler_sch.h
-
107eeschema/api/api_sch_utils.cpp
-
31eeschema/api/api_sch_utils.h
-
2eeschema/lib_shape.h
-
5eeschema/menubar.cpp
-
1eeschema/sch_commit.h
-
21eeschema/sch_edit_frame.cpp
-
10eeschema/sch_edit_frame.h
-
3eeschema/sch_field.h
-
67eeschema/sch_label.cpp
-
12eeschema/sch_label.h
-
46eeschema/sch_line.cpp
-
3eeschema/sch_line.h
-
3eeschema/sch_shape.h
-
2eeschema/sch_table.h
-
21eeschema/toolbars_sch_editor.cpp
-
14eeschema/tools/sch_editor_control.cpp
-
1eeschema/tools/sch_editor_control.h
-
4eeschema/tools/symbol_editor_move_tool.cpp
-
29include/api/api_enums.h
-
30include/api/api_handler.h
-
17include/api/api_handler_common.h
-
115include/api/api_handler_editor.h
-
2include/api/api_plugin.h
-
3include/api/api_plugin_manager.h
-
8include/api/api_server.h
-
48include/api/api_utils.h
-
60include/api/serializable.h
-
7include/eda_base_frame.h
-
13include/eda_draw_frame.h
-
7include/eda_item.h
-
1include/eda_shape.h
-
2include/font/text_attributes.h
-
1include/template_fieldnames.h
-
3include/tool/actions.h
-
8include/tool/tool_manager.h
-
655pcbnew/api/api_handler_pcb.cpp
-
71pcbnew/api/api_handler_pcb.h
-
105pcbnew/api/api_pcb_enums.cpp
-
100pcbnew/api/api_pcb_utils.cpp
-
45pcbnew/api/api_pcb_utils.h
-
29pcbnew/board.cpp
-
41pcbnew/board_stackup_manager/board_stackup.cpp
-
7pcbnew/board_stackup_manager/board_stackup.h
-
2pcbnew/cross-probing.cpp
-
249pcbnew/footprint.cpp
-
3pcbnew/footprint.h
-
4pcbnew/footprint_edit_frame.cpp
-
4pcbnew/footprint_wizard_frame.cpp
-
2pcbnew/menubar_pcb_editor.cpp
-
158pcbnew/pad.cpp
-
3pcbnew/pad.h
-
43pcbnew/pcb_edit_frame.cpp
-
10pcbnew/pcb_edit_frame.h
-
45pcbnew/pcb_field.cpp
-
5pcbnew/pcb_field.h
-
3pcbnew/pcb_painter.cpp
-
271pcbnew/pcb_shape.cpp
-
3pcbnew/pcb_shape.h
-
108pcbnew/pcb_text.cpp
-
3pcbnew/pcb_text.h
-
67pcbnew/pcb_track.cpp
-
9pcbnew/python/scripting/pcb_scripting_tool.cpp
-
35pcbnew/toolbars_pcb_editor.cpp
-
6pcbnew/tools/pcb_actions.cpp
-
1pcbnew/tools/pcb_actions.h
-
3878qa/data/pcbnew/api_kitchen_sink.kicad_pcb
-
272qa/data/pcbnew/api_kitchen_sink.kicad_pro
-
1qa/tests/CMakeLists.txt
-
48qa/tests/api/CMakeLists.txt
@ -1,91 +0,0 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* 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 <filesystem>
|
|||
#include <iostream>
|
|||
#include <string>
|
|||
|
|||
#include <argparse/argparse.hpp>
|
|||
#include <fmt.h>
|
|||
#include <nlohmann/json.hpp>
|
|||
|
|||
#define MAGIC_ENUM_RANGE_MAX 1024
|
|||
#include <magic_enum.hpp>
|
|||
|
|||
#include <layer_ids.h>
|
|||
#include <eda_shape.h>
|
|||
#include <core/typeinfo.h>
|
|||
|
|||
|
|||
template<typename T> |
|||
nlohmann::json FormatEnum() |
|||
{ |
|||
nlohmann::json js; |
|||
|
|||
js["type"] = magic_enum::enum_type_name<T>(); |
|||
js["values"] = nlohmann::json::array(); |
|||
|
|||
for( const std::pair<T, std::string_view>& entry : magic_enum::enum_entries<T>() ) |
|||
{ |
|||
js["values"].emplace_back( nlohmann::json( { |
|||
{ "key", entry.second }, |
|||
{ "value", static_cast<int>( entry.first ) } |
|||
} ) ); |
|||
} |
|||
|
|||
return js; |
|||
} |
|||
|
|||
|
|||
int main( int argc, char* argv[] ) |
|||
{ |
|||
argparse::ArgumentParser args( "enum_exporter" ); |
|||
|
|||
args.add_argument( "output_dir" ).default_value( std::string() ); |
|||
|
|||
try |
|||
{ |
|||
args.parse_args( argc, argv ); |
|||
} |
|||
catch( const std::runtime_error& err ) |
|||
{ |
|||
std::cerr << err.what() << std::endl; |
|||
std::cerr << args; |
|||
std::exit( 1 ); |
|||
} |
|||
|
|||
std::filesystem::path path( args.get<std::string>( "output_dir" ) ); |
|||
std::ofstream outfile; |
|||
|
|||
if( !path.empty() ) |
|||
{ |
|||
path = std::filesystem::absolute( path ); |
|||
outfile.open( path ); |
|||
} |
|||
|
|||
std::ostream& out = outfile.is_open() ? outfile : std::cout; |
|||
|
|||
nlohmann::json js = nlohmann::json::array(); |
|||
|
|||
js += FormatEnum<PCB_LAYER_ID>(); |
|||
js += FormatEnum<SHAPE_T>(); |
|||
js += FormatEnum<KICAD_T>(); |
|||
|
|||
out << js.dump( 4 ) << std::endl; |
|||
} |
@ -0,0 +1,116 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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/>. |
|||
*/ |
|||
|
|||
syntax = "proto3"; |
|||
|
|||
package kiapi.board; |
|||
|
|||
import "common/types/base_types.proto"; |
|||
import "board/board_types.proto"; |
|||
|
|||
message BoardFinish |
|||
{ |
|||
string type_name = 1; |
|||
} |
|||
|
|||
message BoardImpedanceControl |
|||
{ |
|||
bool is_controlled = 1; |
|||
} |
|||
|
|||
message BoardEdgeConnector |
|||
{ |
|||
} |
|||
|
|||
message Castellation |
|||
{ |
|||
bool has_castellated_pads = 1; |
|||
} |
|||
|
|||
message EdgePlating |
|||
{ |
|||
bool has_edge_plating = 1; |
|||
} |
|||
|
|||
message BoardEdgeSettings |
|||
{ |
|||
BoardEdgeConnector connector = 1; |
|||
Castellation castellation = 2; |
|||
EdgePlating plating = 3; |
|||
} |
|||
|
|||
message BoardStackupCopperLayer |
|||
{ |
|||
|
|||
} |
|||
|
|||
message BoardStackupLayer |
|||
{ |
|||
kiapi.common.types.Distance thickness = 1; |
|||
kiapi.board.types.BoardLayer layer = 2; |
|||
bool enabled = 3; |
|||
oneof item { |
|||
BoardStackupCopperLayer copper = 4; |
|||
} |
|||
} |
|||
|
|||
message BoardStackup |
|||
{ |
|||
BoardFinish finish = 1; |
|||
BoardImpedanceControl impedance = 2; |
|||
// NOTE: m_HasThicknessConstrains appears to be unused |
|||
BoardEdgeSettings edge = 3; |
|||
repeated BoardStackupLayer layers = 4; |
|||
} |
|||
|
|||
// LAYER_CLASS_* in BOARD_DESIGN_SETTINGS -- needs to become an enum class |
|||
enum BoardLayerClass |
|||
{ |
|||
BLC_UNKNOWN = 0; |
|||
BLC_SILKSCREEN = 1; |
|||
BLC_COPPER = 2; |
|||
BLC_EDGES = 3; |
|||
BLC_COURTYARD = 4; |
|||
BLC_FABRICATION = 5; |
|||
BLC_OTHER = 6; |
|||
} |
|||
|
|||
message BoardLayerGraphicsDefaults |
|||
{ |
|||
BoardLayerClass layer = 1; |
|||
kiapi.common.types.TextAttributes text = 2; |
|||
kiapi.common.types.Distance line_thickness = 3; |
|||
} |
|||
|
|||
message GraphicsDefaults |
|||
{ |
|||
repeated BoardLayerGraphicsDefaults layers = 1; |
|||
} |
|||
|
|||
// Anything that isn't stackup or design rules |
|||
message BoardSettings |
|||
{ |
|||
GraphicsDefaults graphics_defaults = 1; |
|||
// Dimension default settings |
|||
} |
|||
|
|||
message BoardDesignRules |
|||
{ |
|||
} |
@ -0,0 +1,151 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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/>. |
|||
*/ |
|||
|
|||
syntax = "proto3"; |
|||
|
|||
package kiapi.board.commands; |
|||
|
|||
import "common/types/base_types.proto"; |
|||
import "common/types/enums.proto"; |
|||
import "board/board.proto"; |
|||
import "board/board_types.proto"; |
|||
|
|||
/* |
|||
* Board stackup and properties |
|||
*/ |
|||
|
|||
message GetBoardStackup |
|||
{ |
|||
kiapi.common.types.DocumentSpecifier board = 1; |
|||
} |
|||
|
|||
message BoardStackupResponse |
|||
{ |
|||
kiapi.board.BoardStackup stackup = 1; |
|||
} |
|||
|
|||
message UpdateBoardStackup |
|||
{ |
|||
kiapi.common.types.DocumentSpecifier board = 1; |
|||
kiapi.board.BoardStackup stackup = 2; |
|||
} |
|||
|
|||
message GetGraphicsDefaults |
|||
{ |
|||
kiapi.common.types.DocumentSpecifier board = 1; |
|||
} |
|||
|
|||
message GraphicsDefaultsResponse |
|||
{ |
|||
kiapi.board.GraphicsDefaults defaults = 1; |
|||
} |
|||
|
|||
/* |
|||
* Net management |
|||
*/ |
|||
|
|||
message GetNets |
|||
{ |
|||
kiapi.common.types.DocumentSpecifier board = 1; |
|||
|
|||
// If provided, will only return nets that belong to the given netclass. |
|||
// If more than one netclass_filter is given, nets belonging to any of the given classes will |
|||
// be returned. |
|||
repeated string netclass_filter = 2; |
|||
} |
|||
|
|||
message NetsResponse |
|||
{ |
|||
repeated kiapi.board.types.Net nets = 1; |
|||
} |
|||
|
|||
// Retrieve all the copper items belonging to a certain net or set of nets |
|||
// returns kiapi.common.commands.GetItemsResponse |
|||
message GetItemsByNet |
|||
{ |
|||
// Specifies which document to query, which fields to return, etc. |
|||
kiapi.common.types.ItemHeader header = 1; |
|||
|
|||
// List of one or more types of items to retreive |
|||
repeated kiapi.common.types.KiCadObjectType types = 2; |
|||
|
|||
// A list of net codes to filter items by |
|||
repeated kiapi.board.types.NetCode net_codes = 3; |
|||
} |
|||
|
|||
// Retrieve all the copper items belonging to a certain net class or set of net classes |
|||
// returns kiapi.common.commands.GetItemsResponse |
|||
message GetItemsByNetClass |
|||
{ |
|||
// Specifies which document to query, which fields to return, etc. |
|||
kiapi.common.types.ItemHeader header = 1; |
|||
|
|||
// List of one or more types of items to retreive |
|||
repeated kiapi.common.types.KiCadObjectType types = 2; |
|||
|
|||
// A list of net class names to filter items by |
|||
repeated string net_classes = 3; |
|||
} |
|||
|
|||
/* |
|||
* Blocking operations |
|||
*/ |
|||
|
|||
// Refills some or all zones on the board. |
|||
// This is a blocking operation; it will return Empty immediately, but KiCad will return |
|||
// ApiStatusCode.AS_BUSY to all future API requests until the zone fill has completed. |
|||
message RefillZones |
|||
{ |
|||
kiapi.common.types.DocumentSpecifier board = 1; |
|||
|
|||
// A list of zones to refill. If empty, all zones are refilled. |
|||
repeated kiapi.common.types.KIID zones = 2; |
|||
} |
|||
|
|||
/* |
|||
* Utilities |
|||
*/ |
|||
|
|||
// returns kiapi.common.commands.BoundingBoxResponse |
|||
message GetTextExtents |
|||
{ |
|||
// A temporary text item to calculate the bounding box for |
|||
kiapi.board.types.Text text = 1; |
|||
} |
|||
|
|||
//// Interactive commands //// |
|||
// These commands begin an interactive operation in the editor. |
|||
// They return a response immediately, but the editor will become busy |
|||
// and will not reply to further API commands until the user has finished |
|||
// the operation. |
|||
// These commands will return an error if received in a non-interactive context. |
|||
|
|||
// Selects and begins an interactive move of the given item(s). |
|||
// NOTE: Takes ownership of the active commit, if one exists: |
|||
// the move tool will push the commit when the user confirms the move, |
|||
// or roll back the commit if the user cancels the move. Keep this in |
|||
// mind if using this command in combination with commands that create |
|||
// or modify items using an explicit commit. |
|||
message InteractiveMoveItems |
|||
{ |
|||
kiapi.common.types.DocumentSpecifier board = 1; |
|||
|
|||
repeated kiapi.common.types.KIID items = 2; |
|||
} |
@ -0,0 +1,34 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 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/>. |
|||
*/ |
|||
|
|||
syntax = "proto3"; |
|||
|
|||
package kiapi.common.commands; |
|||
|
|||
import "common/types/project_settings.proto"; |
|||
|
|||
|
|||
message GetNetClasses |
|||
{ |
|||
} |
|||
|
|||
message NetClassesResponse |
|||
{ |
|||
repeated kiapi.common.project.NetClass net_classes = 1; |
|||
} |
@ -0,0 +1,119 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 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/>. |
|||
*/ |
|||
|
|||
/* |
|||
* enums.proto |
|||
* Includes protobuf versions of common KiCad enums |
|||
*/ |
|||
|
|||
syntax = "proto3"; |
|||
|
|||
package kiapi.common.types; |
|||
|
|||
// The set of object types (from KICAD_T) that are exposed to the API. |
|||
enum KiCadObjectType |
|||
{ |
|||
KOT_UNKNOWN = 0; |
|||
|
|||
KOT_PCB_FOOTPRINT = 1; |
|||
KOT_PCB_PAD = 2; |
|||
KOT_PCB_SHAPE = 3; |
|||
KOT_PCB_REFERENCE_IMAGE = 4; |
|||
KOT_PCB_FIELD = 5; |
|||
KOT_PCB_GENERATOR = 6; |
|||
KOT_PCB_TEXT = 7; |
|||
KOT_PCB_TEXTBOX = 8; |
|||
KOT_PCB_TABLE = 9; |
|||
KOT_PCB_TABLECELL = 10; |
|||
KOT_PCB_TRACE = 11; |
|||
KOT_PCB_VIA = 12; |
|||
KOT_PCB_ARC = 13; |
|||
KOT_PCB_MARKER = 14; |
|||
KOT_PCB_DIMENSION = 15; |
|||
KOT_PCB_ZONE = 16; |
|||
KOT_PCB_GROUP = 17; |
|||
|
|||
KOT_SCH_MARKER = 18; |
|||
KOT_SCH_JUNCTION = 19; |
|||
KOT_SCH_NO_CONNECT = 20; |
|||
KOT_SCH_BUS_WIRE_ENTRY = 21; |
|||
KOT_SCH_BUS_BUS_ENTRY = 22; |
|||
KOT_SCH_LINE = 23; |
|||
KOT_SCH_SHAPE = 24; |
|||
KOT_SCH_BITMAP = 25; |
|||
KOT_SCH_TEXTBOX = 26; |
|||
KOT_SCH_TEXT = 27; |
|||
KOT_SCH_TABLE = 28; |
|||
KOT_SCH_TABLECELL = 29; |
|||
KOT_SCH_LABEL = 30; |
|||
KOT_SCH_GLOBAL_LABEL = 31; |
|||
KOT_SCH_HIER_LABEL = 32; |
|||
KOT_SCH_DIRECTIVE_LABEL = 33; |
|||
KOT_SCH_FIELD = 34; |
|||
KOT_SCH_SYMBOL = 35; |
|||
KOT_SCH_SHEET_PIN = 36; |
|||
KOT_SCH_SHEET = 37; |
|||
KOT_SCH_PIN = 38; |
|||
|
|||
KOT_LIB_SYMBOL = 39; |
|||
KOT_LIB_SHAPE = 40; |
|||
KOT_LIB_TEXT = 41; |
|||
KOT_LIB_TEXTBOX = 42; |
|||
KOT_LIB_PIN = 43; |
|||
KOT_LIB_FIELD = 44; |
|||
|
|||
KOT_WSG_LINE = 45; |
|||
KOT_WSG_RECT = 46; |
|||
KOT_WSG_POLY = 47; |
|||
KOT_WSG_TEXT = 48; |
|||
KOT_WSG_BITMAP = 49; |
|||
KOT_WSG_PAGE = 50; |
|||
} |
|||
|
|||
// Mapped to GR_TEXT_H_ALIGN_T |
|||
enum HorizontalAlignment |
|||
{ |
|||
HA_UNKNOWN = 0; |
|||
HA_LEFT = 1; |
|||
HA_CENTER = 2; |
|||
HA_RIGHT = 3; |
|||
HA_INDETERMINATE = 4; |
|||
} |
|||
|
|||
// Mapped to GR_TEXT_V_ALIGN_T |
|||
enum VerticalAlignment |
|||
{ |
|||
VA_UNKNOWN = 0; |
|||
VA_TOP = 1; |
|||
VA_CENTER = 2; |
|||
VA_BOTTOM = 3; |
|||
VA_INDETERMINATE = 4; |
|||
} |
|||
|
|||
// Mapped to LINE_STYLE |
|||
enum StrokeLineStyle |
|||
{ |
|||
SLS_UNKNOWN = 0; |
|||
SLS_DEFAULT = 1; |
|||
SLS_SOLID = 2; |
|||
SLS_DASH = 3; |
|||
SLS_DOT = 4; |
|||
SLS_DASHDOT = 5; |
|||
SLS_DASHDOTDOT = 6; |
|||
} |
@ -0,0 +1,35 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 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/>. |
|||
*/ |
|||
|
|||
/* |
|||
* project_settings.proto |
|||
* Messages that describes project settings shared between schematics and boards |
|||
*/ |
|||
|
|||
syntax = "proto3"; |
|||
|
|||
package kiapi.common.project; |
|||
|
|||
|
|||
message NetClass |
|||
{ |
|||
// The name of the netclass (the literal string "Default" for the default netclass) |
|||
string name = 1; |
|||
|
|||
} |
@ -0,0 +1,24 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 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/>. |
|||
*/ |
|||
|
|||
syntax = "proto3"; |
|||
|
|||
package kiapi.schematic.types; |
|||
|
|||
|
@ -0,0 +1,75 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 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/>. |
|||
*/ |
|||
|
|||
syntax = "proto3"; |
|||
|
|||
package kiapi.schematic.types; |
|||
|
|||
import "common/types/base_types.proto"; |
|||
|
|||
enum SchematicLayer |
|||
{ |
|||
SL_UNKNOWN = 0; |
|||
} |
|||
|
|||
/// Represents a schematic line segment, which may be a wire, bus, or graphical line |
|||
message Line |
|||
{ |
|||
kiapi.common.types.KIID id = 1; |
|||
kiapi.common.types.Vector2 start = 2; |
|||
kiapi.common.types.Vector2 end = 3; |
|||
|
|||
/** |
|||
* One of: LAYER_BUS, LAYER_WIRE, LAYER_NOTES |
|||
*/ |
|||
SchematicLayer layer = 4; |
|||
} |
|||
|
|||
message Text |
|||
{ |
|||
kiapi.common.types.Text text = 1; |
|||
} |
|||
|
|||
message LocalLabel |
|||
{ |
|||
kiapi.common.types.KIID id = 1; |
|||
kiapi.common.types.Vector2 position = 2; |
|||
Text text = 3; |
|||
} |
|||
|
|||
message GlobalLabel |
|||
{ |
|||
kiapi.common.types.KIID id = 1; |
|||
kiapi.common.types.Vector2 position = 2; |
|||
Text text = 3; |
|||
} |
|||
|
|||
message HierarchicalLabel |
|||
{ |
|||
kiapi.common.types.KIID id = 1; |
|||
kiapi.common.types.Vector2 position = 2; |
|||
Text text = 3; |
|||
} |
|||
|
|||
message DirectiveLabel |
|||
{ |
|||
kiapi.common.types.KIID id = 1; |
|||
kiapi.common.types.Vector2 position = 2; |
|||
Text text = 3; |
|||
} |
@ -0,0 +1,436 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 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 <api/api_enums.h>
|
|||
#include <import_export.h>
|
|||
#include <api/common/types/enums.pb.h>
|
|||
#include <api/board/board_types.pb.h>
|
|||
#include <api/schematic/schematic_types.pb.h>
|
|||
|
|||
#include <core/typeinfo.h>
|
|||
#include <font/text_attributes.h>
|
|||
#include <layer_ids.h>
|
|||
#include <stroke_params.h>
|
|||
|
|||
using namespace kiapi; |
|||
using namespace kiapi::common; |
|||
|
|||
template<> |
|||
KICAD_T FromProtoEnum( types::KiCadObjectType aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case types::KiCadObjectType::KOT_PCB_FOOTPRINT: return PCB_FOOTPRINT_T; |
|||
case types::KiCadObjectType::KOT_PCB_PAD: return PCB_PAD_T; |
|||
case types::KiCadObjectType::KOT_PCB_SHAPE: return PCB_SHAPE_T; |
|||
case types::KiCadObjectType::KOT_PCB_REFERENCE_IMAGE: return PCB_REFERENCE_IMAGE_T; |
|||
case types::KiCadObjectType::KOT_PCB_FIELD: return PCB_FIELD_T; |
|||
case types::KiCadObjectType::KOT_PCB_GENERATOR: return PCB_GENERATOR_T; |
|||
case types::KiCadObjectType::KOT_PCB_TEXT: return PCB_TEXT_T; |
|||
case types::KiCadObjectType::KOT_PCB_TEXTBOX: return PCB_TEXTBOX_T; |
|||
case types::KiCadObjectType::KOT_PCB_TABLE: return PCB_TABLE_T; |
|||
case types::KiCadObjectType::KOT_PCB_TABLECELL: return PCB_TABLECELL_T; |
|||
case types::KiCadObjectType::KOT_PCB_TRACE: return PCB_TRACE_T; |
|||
case types::KiCadObjectType::KOT_PCB_VIA: return PCB_VIA_T; |
|||
case types::KiCadObjectType::KOT_PCB_ARC: return PCB_ARC_T; |
|||
case types::KiCadObjectType::KOT_PCB_MARKER: return PCB_MARKER_T; |
|||
case types::KiCadObjectType::KOT_PCB_DIMENSION: return PCB_DIMENSION_T; |
|||
case types::KiCadObjectType::KOT_PCB_ZONE: return PCB_ZONE_T; |
|||
case types::KiCadObjectType::KOT_PCB_GROUP: return PCB_GROUP_T; |
|||
case types::KiCadObjectType::KOT_SCH_MARKER: return SCH_MARKER_T; |
|||
case types::KiCadObjectType::KOT_SCH_JUNCTION: return SCH_JUNCTION_T; |
|||
case types::KiCadObjectType::KOT_SCH_NO_CONNECT: return SCH_NO_CONNECT_T; |
|||
case types::KiCadObjectType::KOT_SCH_BUS_WIRE_ENTRY: return SCH_BUS_WIRE_ENTRY_T; |
|||
case types::KiCadObjectType::KOT_SCH_BUS_BUS_ENTRY: return SCH_BUS_BUS_ENTRY_T; |
|||
case types::KiCadObjectType::KOT_SCH_LINE: return SCH_LINE_T; |
|||
case types::KiCadObjectType::KOT_SCH_SHAPE: return SCH_SHAPE_T; |
|||
case types::KiCadObjectType::KOT_SCH_BITMAP: return SCH_BITMAP_T; |
|||
case types::KiCadObjectType::KOT_SCH_TEXTBOX: return SCH_TEXTBOX_T; |
|||
case types::KiCadObjectType::KOT_SCH_TEXT: return SCH_TEXT_T; |
|||
case types::KiCadObjectType::KOT_SCH_TABLE: return SCH_TABLE_T; |
|||
case types::KiCadObjectType::KOT_SCH_TABLECELL: return SCH_TABLECELL_T; |
|||
case types::KiCadObjectType::KOT_SCH_LABEL: return SCH_LABEL_T; |
|||
case types::KiCadObjectType::KOT_SCH_GLOBAL_LABEL: return SCH_GLOBAL_LABEL_T; |
|||
case types::KiCadObjectType::KOT_SCH_HIER_LABEL: return SCH_HIER_LABEL_T; |
|||
case types::KiCadObjectType::KOT_SCH_DIRECTIVE_LABEL: return SCH_DIRECTIVE_LABEL_T; |
|||
case types::KiCadObjectType::KOT_SCH_FIELD: return SCH_FIELD_T; |
|||
case types::KiCadObjectType::KOT_SCH_SYMBOL: return SCH_SYMBOL_T; |
|||
case types::KiCadObjectType::KOT_SCH_SHEET_PIN: return SCH_SHEET_PIN_T; |
|||
case types::KiCadObjectType::KOT_SCH_SHEET: return SCH_SHEET_T; |
|||
case types::KiCadObjectType::KOT_SCH_PIN: return SCH_PIN_T; |
|||
case types::KiCadObjectType::KOT_LIB_SYMBOL: return LIB_SYMBOL_T; |
|||
case types::KiCadObjectType::KOT_LIB_SHAPE: return LIB_SHAPE_T; |
|||
case types::KiCadObjectType::KOT_LIB_TEXT: return LIB_TEXT_T; |
|||
case types::KiCadObjectType::KOT_LIB_TEXTBOX: return LIB_TEXTBOX_T; |
|||
case types::KiCadObjectType::KOT_LIB_PIN: return LIB_PIN_T; |
|||
case types::KiCadObjectType::KOT_LIB_FIELD: return LIB_FIELD_T; |
|||
case types::KiCadObjectType::KOT_WSG_LINE: return WSG_LINE_T; |
|||
case types::KiCadObjectType::KOT_WSG_RECT: return WSG_RECT_T; |
|||
case types::KiCadObjectType::KOT_WSG_POLY: return WSG_POLY_T; |
|||
case types::KiCadObjectType::KOT_WSG_TEXT: return WSG_TEXT_T; |
|||
case types::KiCadObjectType::KOT_WSG_BITMAP: return WSG_BITMAP_T; |
|||
case types::KiCadObjectType::KOT_WSG_PAGE: return WSG_PAGE_T; |
|||
|
|||
case types::KiCadObjectType::KOT_UNKNOWN: return TYPE_NOT_INIT; |
|||
default: |
|||
wxCHECK_MSG( false, TYPE_NOT_INIT, |
|||
"Unhandled case in FromProtoEnum<types::KiCadObjectType>" ); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
types::KiCadObjectType ToProtoEnum( KICAD_T aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case PCB_FOOTPRINT_T: return types::KiCadObjectType::KOT_PCB_FOOTPRINT; |
|||
case PCB_PAD_T: return types::KiCadObjectType::KOT_PCB_PAD; |
|||
case PCB_SHAPE_T: return types::KiCadObjectType::KOT_PCB_SHAPE; |
|||
case PCB_REFERENCE_IMAGE_T: return types::KiCadObjectType::KOT_PCB_REFERENCE_IMAGE; |
|||
case PCB_FIELD_T: return types::KiCadObjectType::KOT_PCB_FIELD; |
|||
case PCB_GENERATOR_T: return types::KiCadObjectType::KOT_PCB_GENERATOR; |
|||
case PCB_TEXT_T: return types::KiCadObjectType::KOT_PCB_TEXT; |
|||
case PCB_TEXTBOX_T: return types::KiCadObjectType::KOT_PCB_TEXTBOX; |
|||
case PCB_TABLE_T: return types::KiCadObjectType::KOT_PCB_TABLE; |
|||
case PCB_TABLECELL_T: return types::KiCadObjectType::KOT_PCB_TABLECELL; |
|||
case PCB_TRACE_T: return types::KiCadObjectType::KOT_PCB_TRACE; |
|||
case PCB_VIA_T: return types::KiCadObjectType::KOT_PCB_VIA; |
|||
case PCB_ARC_T: return types::KiCadObjectType::KOT_PCB_ARC; |
|||
case PCB_MARKER_T: return types::KiCadObjectType::KOT_PCB_MARKER; |
|||
case PCB_DIMENSION_T: return types::KiCadObjectType::KOT_PCB_DIMENSION; |
|||
case PCB_ZONE_T: return types::KiCadObjectType::KOT_PCB_ZONE; |
|||
case PCB_GROUP_T: return types::KiCadObjectType::KOT_PCB_GROUP; |
|||
case SCH_MARKER_T: return types::KiCadObjectType::KOT_SCH_MARKER; |
|||
case SCH_JUNCTION_T: return types::KiCadObjectType::KOT_SCH_JUNCTION; |
|||
case SCH_NO_CONNECT_T: return types::KiCadObjectType::KOT_SCH_NO_CONNECT; |
|||
case SCH_BUS_WIRE_ENTRY_T: return types::KiCadObjectType::KOT_SCH_BUS_WIRE_ENTRY; |
|||
case SCH_BUS_BUS_ENTRY_T: return types::KiCadObjectType::KOT_SCH_BUS_BUS_ENTRY; |
|||
case SCH_LINE_T: return types::KiCadObjectType::KOT_SCH_LINE; |
|||
case SCH_SHAPE_T: return types::KiCadObjectType::KOT_SCH_SHAPE; |
|||
case SCH_BITMAP_T: return types::KiCadObjectType::KOT_SCH_BITMAP; |
|||
case SCH_TEXTBOX_T: return types::KiCadObjectType::KOT_SCH_TEXTBOX; |
|||
case SCH_TEXT_T: return types::KiCadObjectType::KOT_SCH_TEXT; |
|||
case SCH_TABLE_T: return types::KiCadObjectType::KOT_SCH_TABLE; |
|||
case SCH_TABLECELL_T: return types::KiCadObjectType::KOT_SCH_TABLECELL; |
|||
case SCH_LABEL_T: return types::KiCadObjectType::KOT_SCH_LABEL; |
|||
case SCH_GLOBAL_LABEL_T: return types::KiCadObjectType::KOT_SCH_GLOBAL_LABEL; |
|||
case SCH_HIER_LABEL_T: return types::KiCadObjectType::KOT_SCH_HIER_LABEL; |
|||
case SCH_DIRECTIVE_LABEL_T: return types::KiCadObjectType::KOT_SCH_DIRECTIVE_LABEL; |
|||
case SCH_FIELD_T: return types::KiCadObjectType::KOT_SCH_FIELD; |
|||
case SCH_SYMBOL_T: return types::KiCadObjectType::KOT_SCH_SYMBOL; |
|||
case SCH_SHEET_PIN_T: return types::KiCadObjectType::KOT_SCH_SHEET_PIN; |
|||
case SCH_SHEET_T: return types::KiCadObjectType::KOT_SCH_SHEET; |
|||
case SCH_PIN_T: return types::KiCadObjectType::KOT_SCH_PIN; |
|||
case LIB_SYMBOL_T: return types::KiCadObjectType::KOT_LIB_SYMBOL; |
|||
case LIB_SHAPE_T: return types::KiCadObjectType::KOT_LIB_SHAPE; |
|||
case LIB_TEXT_T: return types::KiCadObjectType::KOT_LIB_TEXT; |
|||
case LIB_TEXTBOX_T: return types::KiCadObjectType::KOT_LIB_TEXTBOX; |
|||
case LIB_PIN_T: return types::KiCadObjectType::KOT_LIB_PIN; |
|||
case LIB_FIELD_T: return types::KiCadObjectType::KOT_LIB_FIELD; |
|||
case WSG_LINE_T: return types::KiCadObjectType::KOT_WSG_LINE; |
|||
case WSG_RECT_T: return types::KiCadObjectType::KOT_WSG_RECT; |
|||
case WSG_POLY_T: return types::KiCadObjectType::KOT_WSG_POLY; |
|||
case WSG_TEXT_T: return types::KiCadObjectType::KOT_WSG_TEXT; |
|||
case WSG_BITMAP_T: return types::KiCadObjectType::KOT_WSG_BITMAP; |
|||
case WSG_PAGE_T: return types::KiCadObjectType::KOT_WSG_PAGE; |
|||
default: |
|||
wxCHECK_MSG( false, types::KiCadObjectType::KOT_UNKNOWN, |
|||
"Unhandled case in ToProtoEnum<KICAD_T>"); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
PCB_LAYER_ID FromProtoEnum( board::types::BoardLayer aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case board::types::BoardLayer::BL_UNDEFINED: return UNDEFINED_LAYER; |
|||
case board::types::BoardLayer::BL_UNSELECTED: return UNSELECTED_LAYER; |
|||
case board::types::BoardLayer::BL_F_Cu: return F_Cu; |
|||
case board::types::BoardLayer::BL_In1_Cu: return In1_Cu; |
|||
case board::types::BoardLayer::BL_In2_Cu: return In2_Cu; |
|||
case board::types::BoardLayer::BL_In3_Cu: return In3_Cu; |
|||
case board::types::BoardLayer::BL_In4_Cu: return In4_Cu; |
|||
case board::types::BoardLayer::BL_In5_Cu: return In5_Cu; |
|||
case board::types::BoardLayer::BL_In6_Cu: return In6_Cu; |
|||
case board::types::BoardLayer::BL_In7_Cu: return In7_Cu; |
|||
case board::types::BoardLayer::BL_In8_Cu: return In8_Cu; |
|||
case board::types::BoardLayer::BL_In9_Cu: return In9_Cu; |
|||
case board::types::BoardLayer::BL_In10_Cu: return In10_Cu; |
|||
case board::types::BoardLayer::BL_In11_Cu: return In11_Cu; |
|||
case board::types::BoardLayer::BL_In12_Cu: return In12_Cu; |
|||
case board::types::BoardLayer::BL_In13_Cu: return In13_Cu; |
|||
case board::types::BoardLayer::BL_In14_Cu: return In14_Cu; |
|||
case board::types::BoardLayer::BL_In15_Cu: return In15_Cu; |
|||
case board::types::BoardLayer::BL_In16_Cu: return In16_Cu; |
|||
case board::types::BoardLayer::BL_In17_Cu: return In17_Cu; |
|||
case board::types::BoardLayer::BL_In18_Cu: return In18_Cu; |
|||
case board::types::BoardLayer::BL_In19_Cu: return In19_Cu; |
|||
case board::types::BoardLayer::BL_In20_Cu: return In20_Cu; |
|||
case board::types::BoardLayer::BL_In21_Cu: return In21_Cu; |
|||
case board::types::BoardLayer::BL_In22_Cu: return In22_Cu; |
|||
case board::types::BoardLayer::BL_In23_Cu: return In23_Cu; |
|||
case board::types::BoardLayer::BL_In24_Cu: return In24_Cu; |
|||
case board::types::BoardLayer::BL_In25_Cu: return In25_Cu; |
|||
case board::types::BoardLayer::BL_In26_Cu: return In26_Cu; |
|||
case board::types::BoardLayer::BL_In27_Cu: return In27_Cu; |
|||
case board::types::BoardLayer::BL_In28_Cu: return In28_Cu; |
|||
case board::types::BoardLayer::BL_In29_Cu: return In29_Cu; |
|||
case board::types::BoardLayer::BL_In30_Cu: return In30_Cu; |
|||
case board::types::BoardLayer::BL_B_Cu: return B_Cu; |
|||
case board::types::BoardLayer::BL_B_Adhes: return B_Adhes; |
|||
case board::types::BoardLayer::BL_F_Adhes: return F_Adhes; |
|||
case board::types::BoardLayer::BL_B_Paste: return B_Paste; |
|||
case board::types::BoardLayer::BL_F_Paste: return F_Paste; |
|||
case board::types::BoardLayer::BL_B_SilkS: return B_SilkS; |
|||
case board::types::BoardLayer::BL_F_SilkS: return F_SilkS; |
|||
case board::types::BoardLayer::BL_B_Mask: return B_Mask; |
|||
case board::types::BoardLayer::BL_F_Mask: return F_Mask; |
|||
case board::types::BoardLayer::BL_Dwgs_User: return Dwgs_User; |
|||
case board::types::BoardLayer::BL_Cmts_User: return Cmts_User; |
|||
case board::types::BoardLayer::BL_Eco1_User: return Eco1_User; |
|||
case board::types::BoardLayer::BL_Eco2_User: return Eco2_User; |
|||
case board::types::BoardLayer::BL_Edge_Cuts: return Edge_Cuts; |
|||
case board::types::BoardLayer::BL_Margin: return Margin; |
|||
case board::types::BoardLayer::BL_B_CrtYd: return B_CrtYd; |
|||
case board::types::BoardLayer::BL_F_CrtYd: return F_CrtYd; |
|||
case board::types::BoardLayer::BL_B_Fab: return B_Fab; |
|||
case board::types::BoardLayer::BL_F_Fab: return F_Fab; |
|||
case board::types::BoardLayer::BL_User_1: return User_1; |
|||
case board::types::BoardLayer::BL_User_2: return User_2; |
|||
case board::types::BoardLayer::BL_User_3: return User_3; |
|||
case board::types::BoardLayer::BL_User_4: return User_4; |
|||
case board::types::BoardLayer::BL_User_5: return User_5; |
|||
case board::types::BoardLayer::BL_User_6: return User_6; |
|||
case board::types::BoardLayer::BL_User_7: return User_7; |
|||
case board::types::BoardLayer::BL_User_8: return User_8; |
|||
case board::types::BoardLayer::BL_User_9: return User_9; |
|||
|
|||
case board::types::BoardLayer::BL_UNKNOWN: return UNDEFINED_LAYER; |
|||
default: |
|||
wxCHECK_MSG( false, UNDEFINED_LAYER, |
|||
"Unhandled case in FromProtoEnum<board::types::BoardLayer>" ); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
board::types::BoardLayer ToProtoEnum( PCB_LAYER_ID aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case UNDEFINED_LAYER: return board::types::BoardLayer::BL_UNDEFINED; |
|||
case UNSELECTED_LAYER: return board::types::BoardLayer::BL_UNSELECTED; |
|||
case F_Cu: return board::types::BoardLayer::BL_F_Cu; |
|||
case In1_Cu: return board::types::BoardLayer::BL_In1_Cu; |
|||
case In2_Cu: return board::types::BoardLayer::BL_In2_Cu; |
|||
case In3_Cu: return board::types::BoardLayer::BL_In3_Cu; |
|||
case In4_Cu: return board::types::BoardLayer::BL_In4_Cu; |
|||
case In5_Cu: return board::types::BoardLayer::BL_In5_Cu; |
|||
case In6_Cu: return board::types::BoardLayer::BL_In6_Cu; |
|||
case In7_Cu: return board::types::BoardLayer::BL_In7_Cu; |
|||
case In8_Cu: return board::types::BoardLayer::BL_In8_Cu; |
|||
case In9_Cu: return board::types::BoardLayer::BL_In9_Cu; |
|||
case In10_Cu: return board::types::BoardLayer::BL_In10_Cu; |
|||
case In11_Cu: return board::types::BoardLayer::BL_In11_Cu; |
|||
case In12_Cu: return board::types::BoardLayer::BL_In12_Cu; |
|||
case In13_Cu: return board::types::BoardLayer::BL_In13_Cu; |
|||
case In14_Cu: return board::types::BoardLayer::BL_In14_Cu; |
|||
case In15_Cu: return board::types::BoardLayer::BL_In15_Cu; |
|||
case In16_Cu: return board::types::BoardLayer::BL_In16_Cu; |
|||
case In17_Cu: return board::types::BoardLayer::BL_In17_Cu; |
|||
case In18_Cu: return board::types::BoardLayer::BL_In18_Cu; |
|||
case In19_Cu: return board::types::BoardLayer::BL_In19_Cu; |
|||
case In20_Cu: return board::types::BoardLayer::BL_In20_Cu; |
|||
case In21_Cu: return board::types::BoardLayer::BL_In21_Cu; |
|||
case In22_Cu: return board::types::BoardLayer::BL_In22_Cu; |
|||
case In23_Cu: return board::types::BoardLayer::BL_In23_Cu; |
|||
case In24_Cu: return board::types::BoardLayer::BL_In24_Cu; |
|||
case In25_Cu: return board::types::BoardLayer::BL_In25_Cu; |
|||
case In26_Cu: return board::types::BoardLayer::BL_In26_Cu; |
|||
case In27_Cu: return board::types::BoardLayer::BL_In27_Cu; |
|||
case In28_Cu: return board::types::BoardLayer::BL_In28_Cu; |
|||
case In29_Cu: return board::types::BoardLayer::BL_In29_Cu; |
|||
case In30_Cu: return board::types::BoardLayer::BL_In30_Cu; |
|||
case B_Cu: return board::types::BoardLayer::BL_B_Cu; |
|||
case B_Adhes: return board::types::BoardLayer::BL_B_Adhes; |
|||
case F_Adhes: return board::types::BoardLayer::BL_F_Adhes; |
|||
case B_Paste: return board::types::BoardLayer::BL_B_Paste; |
|||
case F_Paste: return board::types::BoardLayer::BL_F_Paste; |
|||
case B_SilkS: return board::types::BoardLayer::BL_B_SilkS; |
|||
case F_SilkS: return board::types::BoardLayer::BL_F_SilkS; |
|||
case B_Mask: return board::types::BoardLayer::BL_B_Mask; |
|||
case F_Mask: return board::types::BoardLayer::BL_F_Mask; |
|||
case Dwgs_User: return board::types::BoardLayer::BL_Dwgs_User; |
|||
case Cmts_User: return board::types::BoardLayer::BL_Cmts_User; |
|||
case Eco1_User: return board::types::BoardLayer::BL_Eco1_User; |
|||
case Eco2_User: return board::types::BoardLayer::BL_Eco2_User; |
|||
case Edge_Cuts: return board::types::BoardLayer::BL_Edge_Cuts; |
|||
case Margin: return board::types::BoardLayer::BL_Margin; |
|||
case B_CrtYd: return board::types::BoardLayer::BL_B_CrtYd; |
|||
case F_CrtYd: return board::types::BoardLayer::BL_F_CrtYd; |
|||
case B_Fab: return board::types::BoardLayer::BL_B_Fab; |
|||
case F_Fab: return board::types::BoardLayer::BL_F_Fab; |
|||
case User_1: return board::types::BoardLayer::BL_User_1; |
|||
case User_2: return board::types::BoardLayer::BL_User_2; |
|||
case User_3: return board::types::BoardLayer::BL_User_3; |
|||
case User_4: return board::types::BoardLayer::BL_User_4; |
|||
case User_5: return board::types::BoardLayer::BL_User_5; |
|||
case User_6: return board::types::BoardLayer::BL_User_6; |
|||
case User_7: return board::types::BoardLayer::BL_User_7; |
|||
case User_8: return board::types::BoardLayer::BL_User_8; |
|||
case User_9: return board::types::BoardLayer::BL_User_9; |
|||
default: |
|||
wxCHECK_MSG( false, board::types::BoardLayer::BL_UNKNOWN, |
|||
"Unhandled case in ToProtoEnum<PCB_LAYER_ID>"); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
SCH_LAYER_ID FromProtoEnum( schematic::types::SchematicLayer aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
|
|||
default: |
|||
wxCHECK_MSG( false, SCH_LAYER_ID_START, |
|||
"Unhandled case in FromProtoEnum<schematic::types::SchematicLayer>" ); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
schematic::types::SchematicLayer ToProtoEnum( SCH_LAYER_ID aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
|
|||
default: |
|||
wxCHECK_MSG( false, schematic::types::SchematicLayer::SL_UNKNOWN, |
|||
"Unhandled case in ToProtoEnum<SCH_LAYER_ID>"); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
GR_TEXT_H_ALIGN_T FromProtoEnum( types::HorizontalAlignment aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case types::HorizontalAlignment::HA_LEFT: return GR_TEXT_H_ALIGN_LEFT; |
|||
case types::HorizontalAlignment::HA_CENTER: return GR_TEXT_H_ALIGN_CENTER; |
|||
case types::HorizontalAlignment::HA_RIGHT: return GR_TEXT_H_ALIGN_RIGHT; |
|||
case types::HorizontalAlignment::HA_INDETERMINATE: return GR_TEXT_H_ALIGN_INDETERMINATE; |
|||
|
|||
case types::HorizontalAlignment::HA_UNKNOWN: return GR_TEXT_H_ALIGN_CENTER; |
|||
default: |
|||
wxCHECK_MSG( false, GR_TEXT_H_ALIGN_CENTER, |
|||
"Unhandled case in FromProtoEnum<types::HorizontalAlignment>" ); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
types::HorizontalAlignment ToProtoEnum( GR_TEXT_H_ALIGN_T aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case GR_TEXT_H_ALIGN_LEFT: return types::HorizontalAlignment::HA_LEFT; |
|||
case GR_TEXT_H_ALIGN_CENTER: return types::HorizontalAlignment::HA_CENTER; |
|||
case GR_TEXT_H_ALIGN_RIGHT: return types::HorizontalAlignment::HA_RIGHT; |
|||
case GR_TEXT_H_ALIGN_INDETERMINATE: return types::HorizontalAlignment::HA_INDETERMINATE; |
|||
default: |
|||
wxCHECK_MSG( false, types::HorizontalAlignment::HA_UNKNOWN, |
|||
"Unhandled case in ToProtoEnum<GR_TEXT_H_ALIGN_T>"); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
GR_TEXT_V_ALIGN_T FromProtoEnum( types::VerticalAlignment aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case types::VerticalAlignment::VA_TOP: return GR_TEXT_V_ALIGN_TOP; |
|||
case types::VerticalAlignment::VA_CENTER: return GR_TEXT_V_ALIGN_CENTER; |
|||
case types::VerticalAlignment::VA_BOTTOM: return GR_TEXT_V_ALIGN_BOTTOM; |
|||
case types::VerticalAlignment::VA_INDETERMINATE: return GR_TEXT_V_ALIGN_INDETERMINATE; |
|||
|
|||
case types::VerticalAlignment::VA_UNKNOWN: return GR_TEXT_V_ALIGN_CENTER; |
|||
default: |
|||
wxCHECK_MSG( false, GR_TEXT_V_ALIGN_CENTER, |
|||
"Unhandled case in FromProtoEnum<types::VerticalAlignment>" ); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
types::VerticalAlignment ToProtoEnum( GR_TEXT_V_ALIGN_T aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case GR_TEXT_V_ALIGN_TOP: return types::VerticalAlignment::VA_TOP; |
|||
case GR_TEXT_V_ALIGN_CENTER: return types::VerticalAlignment::VA_CENTER; |
|||
case GR_TEXT_V_ALIGN_BOTTOM: return types::VerticalAlignment::VA_BOTTOM; |
|||
case GR_TEXT_V_ALIGN_INDETERMINATE: return types::VerticalAlignment::VA_INDETERMINATE; |
|||
default: |
|||
wxCHECK_MSG( false, types::VerticalAlignment::VA_UNKNOWN, |
|||
"Unhandled case in ToProtoEnum<GR_TEXT_V_ALIGN_T>"); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
LINE_STYLE FromProtoEnum( types::StrokeLineStyle aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case types::StrokeLineStyle::SLS_DEFAULT: return LINE_STYLE::DEFAULT; |
|||
case types::StrokeLineStyle::SLS_SOLID: return LINE_STYLE::SOLID; |
|||
case types::StrokeLineStyle::SLS_DASH: return LINE_STYLE::DASH; |
|||
case types::StrokeLineStyle::SLS_DOT: return LINE_STYLE::DOT; |
|||
case types::StrokeLineStyle::SLS_DASHDOT: return LINE_STYLE::DASHDOT; |
|||
case types::StrokeLineStyle::SLS_DASHDOTDOT: return LINE_STYLE::DASHDOTDOT; |
|||
case types::StrokeLineStyle::SLS_UNKNOWN: |
|||
default: |
|||
wxCHECK_MSG( false, LINE_STYLE::DEFAULT, |
|||
"Unhandled case in FromProtoEnum<types::StrokeLineStyle>" ); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
types::StrokeLineStyle ToProtoEnum( LINE_STYLE aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case LINE_STYLE::DEFAULT: return types::StrokeLineStyle::SLS_DEFAULT; |
|||
case LINE_STYLE::SOLID: return types::StrokeLineStyle::SLS_SOLID; |
|||
case LINE_STYLE::DASH: return types::StrokeLineStyle::SLS_DASH; |
|||
case LINE_STYLE::DOT: return types::StrokeLineStyle::SLS_DOT; |
|||
case LINE_STYLE::DASHDOT: return types::StrokeLineStyle::SLS_DASHDOT; |
|||
case LINE_STYLE::DASHDOTDOT: return types::StrokeLineStyle::SLS_DASHDOTDOT; |
|||
default: |
|||
wxCHECK_MSG( false, types::StrokeLineStyle::SLS_UNKNOWN, |
|||
"Unhandled case in ToProtoEnum<LINE_STYLE>"); |
|||
} |
|||
} |
@ -0,0 +1,353 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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 <api/api_handler_editor.h>
|
|||
#include <api/api_utils.h>
|
|||
#include <eda_base_frame.h>
|
|||
#include <eda_item.h>
|
|||
#include <wx/wx.h>
|
|||
|
|||
using namespace kiapi::common::commands; |
|||
|
|||
|
|||
API_HANDLER_EDITOR::API_HANDLER_EDITOR( EDA_BASE_FRAME* aFrame ) : |
|||
API_HANDLER(), |
|||
m_frame( aFrame ) |
|||
{ |
|||
registerHandler<BeginCommit, BeginCommitResponse>( &API_HANDLER_EDITOR::handleBeginCommit ); |
|||
registerHandler<EndCommit, EndCommitResponse>( &API_HANDLER_EDITOR::handleEndCommit ); |
|||
registerHandler<CreateItems, CreateItemsResponse>( &API_HANDLER_EDITOR::handleCreateItems ); |
|||
registerHandler<UpdateItems, UpdateItemsResponse>( &API_HANDLER_EDITOR::handleUpdateItems ); |
|||
registerHandler<DeleteItems, DeleteItemsResponse>( &API_HANDLER_EDITOR::handleDeleteItems ); |
|||
registerHandler<HitTest, HitTestResponse>( &API_HANDLER_EDITOR::handleHitTest ); |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<BeginCommitResponse> API_HANDLER_EDITOR::handleBeginCommit( BeginCommit& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ) |
|||
{ |
|||
if( std::optional<ApiResponseStatus> busy = checkForBusy() ) |
|||
return tl::unexpected( *busy ); |
|||
|
|||
if( m_commits.count( aCtx.ClientName ) ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( "the client {} already has a commit in progress", |
|||
aCtx.ClientName ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
wxASSERT( !m_activeClients.count( aCtx.ClientName ) ); |
|||
|
|||
BeginCommitResponse response; |
|||
|
|||
KIID id; |
|||
m_commits[aCtx.ClientName] = std::make_pair( id, createCommit() ); |
|||
response.mutable_id()->set_value( id.AsStdString() ); |
|||
|
|||
m_activeClients.insert( aCtx.ClientName ); |
|||
|
|||
return response; |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<EndCommitResponse> API_HANDLER_EDITOR::handleEndCommit( EndCommit& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ) |
|||
{ |
|||
if( std::optional<ApiResponseStatus> busy = checkForBusy() ) |
|||
return tl::unexpected( *busy ); |
|||
|
|||
if( !m_commits.count( aCtx.ClientName ) ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( "the client {} does not has a commit in progress", |
|||
aCtx.ClientName ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
wxASSERT( m_activeClients.count( aCtx.ClientName ) ); |
|||
|
|||
const std::pair<KIID, std::unique_ptr<COMMIT>>& pair = m_commits.at( aCtx.ClientName ); |
|||
const KIID& id = pair.first; |
|||
const std::unique_ptr<COMMIT>& commit = pair.second; |
|||
|
|||
EndCommitResponse response; |
|||
|
|||
// Do not check IDs with drop; it is a safety net in case the id was lost on the client side
|
|||
switch( aMsg.action() ) |
|||
{ |
|||
case kiapi::common::commands::CMA_DROP: |
|||
{ |
|||
commit->Revert(); |
|||
m_commits.erase( aCtx.ClientName ); |
|||
m_activeClients.erase( aCtx.ClientName ); |
|||
break; |
|||
} |
|||
|
|||
case kiapi::common::commands::CMA_COMMIT: |
|||
{ |
|||
if( aMsg.id().value().compare( id.AsStdString() ) != 0 ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( "the id {} does not match the commit in progress", |
|||
aMsg.id().value() ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
pushCurrentCommit( aCtx, wxString( aMsg.message().c_str(), wxConvUTF8 ) ); |
|||
break; |
|||
} |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
|
|||
return response; |
|||
} |
|||
|
|||
|
|||
COMMIT* API_HANDLER_EDITOR::getCurrentCommit( const HANDLER_CONTEXT& aCtx ) |
|||
{ |
|||
if( !m_commits.count( aCtx.ClientName ) ) |
|||
{ |
|||
KIID id; |
|||
m_commits[aCtx.ClientName] = std::make_pair( id, createCommit() ); |
|||
} |
|||
|
|||
return m_commits.at( aCtx.ClientName ).second.get(); |
|||
} |
|||
|
|||
|
|||
void API_HANDLER_EDITOR::pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage ) |
|||
{ |
|||
auto it = m_commits.find( aCtx.ClientName ); |
|||
|
|||
if( it == m_commits.end() ) |
|||
return; |
|||
|
|||
it->second.second->Push( aMessage.IsEmpty() ? m_defaultCommitMessage : aMessage ); |
|||
m_commits.erase( it ); |
|||
m_activeClients.erase( aCtx.ClientName ); |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<bool> API_HANDLER_EDITOR::validateDocument( |
|||
const kiapi::common::types::DocumentSpecifier& aDocument ) |
|||
{ |
|||
if( !validateDocumentInternal( aDocument ) ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( "the requested document {} is not open", |
|||
aDocument.board_filename() ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<std::optional<KIID>> API_HANDLER_EDITOR::validateItemHeaderDocument( |
|||
const kiapi::common::types::ItemHeader& aHeader ) |
|||
{ |
|||
if( !aHeader.has_document() || aHeader.document().type() != thisDocumentType() ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_UNHANDLED ); |
|||
// No error message, this is a flag that the server should try a different handler
|
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
HANDLER_RESULT<bool> documentValidation = validateDocument( aHeader.document() ); |
|||
|
|||
if( !documentValidation ) |
|||
return tl::unexpected( documentValidation.error() ); |
|||
|
|||
if( !validateDocumentInternal( aHeader.document() ) ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( "the requested document {} is not open", |
|||
aHeader.document().board_filename() ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
if( aHeader.has_container() ) |
|||
{ |
|||
return KIID( aHeader.container().value() ); |
|||
} |
|||
|
|||
// Valid header, but no container provided
|
|||
return std::nullopt; |
|||
} |
|||
|
|||
|
|||
std::optional<ApiResponseStatus> API_HANDLER_EDITOR::checkForBusy() |
|||
{ |
|||
if( !m_frame->CanAcceptApiCommands() ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BUSY ); |
|||
e.set_error_message( "KiCad is busy and cannot respond to API requests right now" ); |
|||
return e; |
|||
} |
|||
|
|||
return std::nullopt; |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<CreateItemsResponse> API_HANDLER_EDITOR::handleCreateItems( CreateItems& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ) |
|||
{ |
|||
if( std::optional<ApiResponseStatus> busy = checkForBusy() ) |
|||
return tl::unexpected( *busy ); |
|||
|
|||
CreateItemsResponse response; |
|||
|
|||
HANDLER_RESULT<ItemRequestStatus> result = handleCreateUpdateItemsInternal( true, aCtx, |
|||
aMsg.header(), aMsg.items(), |
|||
[&]( const ItemStatus& aStatus, const google::protobuf::Any& aItem ) |
|||
{ |
|||
ItemCreationResult itemResult; |
|||
itemResult.mutable_status()->CopyFrom( aStatus ); |
|||
itemResult.mutable_item()->CopyFrom( aItem ); |
|||
response.mutable_created_items()->Add( std::move( itemResult ) ); |
|||
} ); |
|||
|
|||
if( !result.has_value() ) |
|||
return tl::unexpected( result.error() ); |
|||
|
|||
response.set_status( *result ); |
|||
return response; |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<UpdateItemsResponse> API_HANDLER_EDITOR::handleUpdateItems( UpdateItems& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ) |
|||
{ |
|||
if( std::optional<ApiResponseStatus> busy = checkForBusy() ) |
|||
return tl::unexpected( *busy ); |
|||
|
|||
UpdateItemsResponse response; |
|||
|
|||
HANDLER_RESULT<ItemRequestStatus> result = handleCreateUpdateItemsInternal( false, aCtx, |
|||
aMsg.header(), aMsg.items(), |
|||
[&]( const ItemStatus& aStatus, const google::protobuf::Any& aItem ) |
|||
{ |
|||
ItemUpdateResult itemResult; |
|||
itemResult.mutable_status()->CopyFrom( aStatus ); |
|||
itemResult.mutable_item()->CopyFrom( aItem ); |
|||
response.mutable_updated_items()->Add( std::move( itemResult ) ); |
|||
} ); |
|||
|
|||
if( !result.has_value() ) |
|||
return tl::unexpected( result.error() ); |
|||
|
|||
response.set_status( *result ); |
|||
return response; |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<DeleteItemsResponse> API_HANDLER_EDITOR::handleDeleteItems( DeleteItems& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ) |
|||
{ |
|||
if( std::optional<ApiResponseStatus> busy = checkForBusy() ) |
|||
return tl::unexpected( *busy ); |
|||
|
|||
if( !validateItemHeaderDocument( aMsg.header() ) ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
|
|||
e.set_status( ApiStatusCode::AS_UNHANDLED ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
std::map<KIID, ItemDeletionStatus> itemsToDelete; |
|||
|
|||
for( const kiapi::common::types::KIID& kiidBuf : aMsg.item_ids() ) |
|||
{ |
|||
if( !kiidBuf.value().empty() ) |
|||
{ |
|||
KIID kiid( kiidBuf.value() ); |
|||
itemsToDelete[kiid] = ItemDeletionStatus::IDS_NONEXISTENT; |
|||
} |
|||
} |
|||
|
|||
if( itemsToDelete.empty() ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( "no valid items to delete were given" ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
deleteItemsInternal( itemsToDelete, aCtx ); |
|||
|
|||
DeleteItemsResponse response; |
|||
|
|||
for( const auto& [id, status] : itemsToDelete ) |
|||
{ |
|||
ItemDeletionResult result; |
|||
result.mutable_id()->set_value( id.AsStdString() ); |
|||
result.set_status( status ); |
|||
} |
|||
|
|||
response.set_status( kiapi::common::types::ItemRequestStatus::IRS_OK ); |
|||
return response; |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<HitTestResponse> API_HANDLER_EDITOR::handleHitTest( HitTest& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ) |
|||
{ |
|||
if( std::optional<ApiResponseStatus> busy = checkForBusy() ) |
|||
return tl::unexpected( *busy ); |
|||
|
|||
if( !validateItemHeaderDocument( aMsg.header() ) ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
|
|||
e.set_status( ApiStatusCode::AS_UNHANDLED ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
HitTestResponse response; |
|||
|
|||
std::optional<EDA_ITEM*> item = getItemFromDocument( aMsg.header().document(), |
|||
KIID( aMsg.id().value() ) ); |
|||
|
|||
if( !item ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( "the requested item ID is not present in the given document" ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
if( ( *item )->HitTest( kiapi::common::UnpackVector2( aMsg.position() ), aMsg.tolerance() ) ) |
|||
response.set_result( HitTestResult::HTR_HIT ); |
|||
else |
|||
response.set_result( HitTestResult::HTR_NO_HIT ); |
|||
|
|||
return response; |
|||
} |
@ -0,0 +1,80 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* 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 <magic_enum.hpp>
|
|||
#include <api/api_utils.h>
|
|||
|
|||
namespace kiapi::common |
|||
{ |
|||
|
|||
std::optional<KICAD_T> TypeNameFromAny( const google::protobuf::Any& aMessage ) |
|||
{ |
|||
static const std::map<std::string, KICAD_T> s_types = { |
|||
{ "type.googleapis.com/kiapi.board.types.Track", PCB_TRACE_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.Arc", PCB_ARC_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.Via", PCB_VIA_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.Text", PCB_TEXT_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.TextBox", PCB_TEXTBOX_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.GraphicShape", PCB_SHAPE_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.Pad", PCB_PAD_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.Zone", PCB_ZONE_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.Dimension", PCB_DIMENSION_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.ReferenceImage", PCB_REFERENCE_IMAGE_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.Group", PCB_GROUP_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.Field", PCB_FIELD_T }, |
|||
{ "type.googleapis.com/kiapi.board.types.FootprintInstance", PCB_FOOTPRINT_T }, |
|||
}; |
|||
|
|||
auto it = s_types.find( aMessage.type_url() ); |
|||
|
|||
if( it != s_types.end() ) |
|||
return it->second; |
|||
|
|||
return std::nullopt; |
|||
} |
|||
|
|||
|
|||
LIB_ID LibIdFromProto( const types::LibraryIdentifier& aId ) |
|||
{ |
|||
return LIB_ID( aId.library_nickname(), aId.entry_name() ); |
|||
} |
|||
|
|||
|
|||
types::LibraryIdentifier LibIdToProto( const LIB_ID& aId ) |
|||
{ |
|||
types::LibraryIdentifier msg; |
|||
msg.set_library_nickname( aId.GetLibNickname() ); |
|||
msg.set_entry_name( aId.GetLibItemName() ); |
|||
return msg; |
|||
} |
|||
|
|||
|
|||
void PackVector2( kiapi::common::types::Vector2& aOutput, const VECTOR2I aInput ) |
|||
{ |
|||
aOutput.set_x_nm( aInput.x ); |
|||
aOutput.set_y_nm( aInput.y ); |
|||
} |
|||
|
|||
VECTOR2I UnpackVector2( const types::Vector2& aInput ) |
|||
{ |
|||
return VECTOR2I( aInput.x_nm(), aInput.y_nm() ); |
|||
} |
|||
|
|||
} // namespace kiapi::common
|
@ -0,0 +1,305 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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 <api/api_handler_sch.h>
|
|||
#include <api/api_sch_utils.h>
|
|||
#include <api/api_utils.h>
|
|||
#include <magic_enum.hpp>
|
|||
#include <sch_commit.h>
|
|||
#include <sch_edit_frame.h>
|
|||
#include <wx/filename.h>
|
|||
|
|||
#include <api/common/types/base_types.pb.h>
|
|||
|
|||
using namespace kiapi::common::commands; |
|||
using kiapi::common::types::CommandStatus; |
|||
using kiapi::common::types::DocumentType; |
|||
using kiapi::common::types::ItemRequestStatus; |
|||
|
|||
|
|||
API_HANDLER_SCH::API_HANDLER_SCH( SCH_EDIT_FRAME* aFrame ) : |
|||
API_HANDLER_EDITOR(), |
|||
m_frame( aFrame ) |
|||
{ |
|||
registerHandler<GetOpenDocuments, GetOpenDocumentsResponse>( |
|||
&API_HANDLER_SCH::handleGetOpenDocuments ); |
|||
} |
|||
|
|||
|
|||
std::unique_ptr<COMMIT> API_HANDLER_SCH::createCommit() |
|||
{ |
|||
return std::make_unique<SCH_COMMIT>( m_frame ); |
|||
} |
|||
|
|||
|
|||
bool API_HANDLER_SCH::validateDocumentInternal( const DocumentSpecifier& aDocument ) const |
|||
{ |
|||
if( aDocument.type() != DocumentType::DOCTYPE_SCHEMATIC ) |
|||
return false; |
|||
|
|||
// TODO(JE) need serdes for SCH_SHEET_PATH <> SheetPath
|
|||
return true; |
|||
//wxString currentPath = m_frame->GetCurrentSheet().PathAsString();
|
|||
//return 0 == aDocument.sheet_path().compare( currentPath.ToStdString() );
|
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<GetOpenDocumentsResponse> API_HANDLER_SCH::handleGetOpenDocuments( |
|||
GetOpenDocuments& aMsg, const HANDLER_CONTEXT& ) |
|||
{ |
|||
if( aMsg.type() != DocumentType::DOCTYPE_SCHEMATIC ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
|
|||
e.set_status( ApiStatusCode::AS_UNHANDLED ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
GetOpenDocumentsResponse response; |
|||
common::types::DocumentSpecifier doc; |
|||
|
|||
wxFileName fn( m_frame->GetCurrentFileName() ); |
|||
|
|||
doc.set_type( DocumentType::DOCTYPE_SCHEMATIC ); |
|||
doc.set_board_filename( fn.GetFullName() ); |
|||
|
|||
response.mutable_documents()->Add( std::move( doc ) ); |
|||
return response; |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<std::unique_ptr<EDA_ITEM>> API_HANDLER_SCH::createItemForType( KICAD_T aType, |
|||
EDA_ITEM* aContainer ) |
|||
{ |
|||
if( !aContainer ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( "Tried to create an item in a null container" ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
if( aType == SCH_PIN_T && !dynamic_cast<SCH_SYMBOL*>( aContainer ) ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( "Tried to create a pin in {}, which is not a symbol", |
|||
aContainer->GetFriendlyName().ToStdString() ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
else if( aType == SCH_SYMBOL_T && !dynamic_cast<SCHEMATIC*>( aContainer ) ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( "Tried to create a symbol in {}, which is not a schematic", |
|||
aContainer->GetFriendlyName().ToStdString() ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
std::unique_ptr<EDA_ITEM> created = CreateItemForType( aType, aContainer ); |
|||
|
|||
if( !created ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( "Tried to create an item of type {}, which is unhandled", |
|||
magic_enum::enum_name( aType ) ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
return created; |
|||
} |
|||
|
|||
|
|||
HANDLER_RESULT<ItemRequestStatus> API_HANDLER_SCH::handleCreateUpdateItemsInternal( bool aCreate, |
|||
const HANDLER_CONTEXT& aCtx, |
|||
const types::ItemHeader &aHeader, |
|||
const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems, |
|||
std::function<void( ItemStatus, google::protobuf::Any )> aItemHandler ) |
|||
{ |
|||
ApiResponseStatus e; |
|||
|
|||
auto containerResult = validateItemHeaderDocument( aHeader ); |
|||
|
|||
if( !containerResult && containerResult.error().status() == ApiStatusCode::AS_UNHANDLED ) |
|||
{ |
|||
// No message needed for AS_UNHANDLED; this is an internal flag for the API server
|
|||
e.set_status( ApiStatusCode::AS_UNHANDLED ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
else if( !containerResult ) |
|||
{ |
|||
e.CopyFrom( containerResult.error() ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
SCH_SCREEN* screen = m_frame->GetScreen(); |
|||
EE_RTREE& screenItems = screen->Items(); |
|||
|
|||
std::map<KIID, EDA_ITEM*> itemUuidMap; |
|||
|
|||
std::for_each( screenItems.begin(), screenItems.end(), |
|||
[&]( EDA_ITEM* aItem ) |
|||
{ |
|||
itemUuidMap[aItem->m_Uuid] = aItem; |
|||
} ); |
|||
|
|||
EDA_ITEM* container = nullptr; |
|||
|
|||
if( containerResult->has_value() ) |
|||
{ |
|||
const KIID& containerId = **containerResult; |
|||
|
|||
if( itemUuidMap.count( containerId ) ) |
|||
{ |
|||
container = itemUuidMap.at( containerId ); |
|||
|
|||
if( !container ) |
|||
{ |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( |
|||
"The requested container {} is not a valid schematic item container", |
|||
containerId.AsStdString() ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( |
|||
"The requested container {} does not exist in this document", |
|||
containerId.AsStdString() ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
} |
|||
|
|||
COMMIT* commit = getCurrentCommit( aCtx ); |
|||
|
|||
for( const google::protobuf::Any& anyItem : aItems ) |
|||
{ |
|||
ItemStatus status; |
|||
std::optional<KICAD_T> type = TypeNameFromAny( anyItem ); |
|||
|
|||
if( !type ) |
|||
{ |
|||
status.set_code( ItemStatusCode::ISC_INVALID_TYPE ); |
|||
status.set_error_message( fmt::format( "Could not decode a valid type from {}", |
|||
anyItem.type_url() ) ); |
|||
aItemHandler( status, anyItem ); |
|||
continue; |
|||
} |
|||
|
|||
HANDLER_RESULT<std::unique_ptr<EDA_ITEM>> creationResult = |
|||
createItemForType( *type, container ); |
|||
|
|||
if( !creationResult ) |
|||
{ |
|||
status.set_code( ItemStatusCode::ISC_INVALID_TYPE ); |
|||
status.set_error_message( creationResult.error().error_message() ); |
|||
aItemHandler( status, anyItem ); |
|||
continue; |
|||
} |
|||
|
|||
std::unique_ptr<EDA_ITEM> item( std::move( *creationResult ) ); |
|||
|
|||
if( !item->Deserialize( anyItem ) ) |
|||
{ |
|||
e.set_status( ApiStatusCode::AS_BAD_REQUEST ); |
|||
e.set_error_message( fmt::format( "could not unpack {} from request", |
|||
item->GetClass().ToStdString() ) ); |
|||
return tl::unexpected( e ); |
|||
} |
|||
|
|||
if( aCreate && itemUuidMap.count( item->m_Uuid ) ) |
|||
{ |
|||
status.set_code( ItemStatusCode::ISC_EXISTING ); |
|||
status.set_error_message( fmt::format( "an item with UUID {} already exists", |
|||
item->m_Uuid.AsStdString() ) ); |
|||
aItemHandler( status, anyItem ); |
|||
continue; |
|||
} |
|||
else if( !aCreate && !itemUuidMap.count( item->m_Uuid ) ) |
|||
{ |
|||
status.set_code( ItemStatusCode::ISC_NONEXISTENT ); |
|||
status.set_error_message( fmt::format( "an item with UUID {} does not exist", |
|||
item->m_Uuid.AsStdString() ) ); |
|||
aItemHandler( status, anyItem ); |
|||
continue; |
|||
} |
|||
|
|||
status.set_code( ItemStatusCode::ISC_OK ); |
|||
google::protobuf::Any newItem; |
|||
|
|||
if( aCreate ) |
|||
{ |
|||
item->Serialize( newItem ); |
|||
commit->Add( item.release() ); |
|||
|
|||
if( !m_activeClients.count( aCtx.ClientName ) ) |
|||
pushCurrentCommit( aCtx, _( "Added items via API" ) ); |
|||
} |
|||
else |
|||
{ |
|||
EDA_ITEM* edaItem = itemUuidMap[item->m_Uuid]; |
|||
|
|||
if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( edaItem ) ) |
|||
{ |
|||
schItem->SwapData( static_cast<SCH_ITEM*>( item.get() ) ); |
|||
schItem->Serialize( newItem ); |
|||
commit->Modify( schItem ); |
|||
} |
|||
else if( LIB_ITEM* libItem = dynamic_cast<LIB_ITEM*>( edaItem ) ) |
|||
{ |
|||
// TODO: there is not currently a way to do this, haha
|
|||
} |
|||
else |
|||
{ |
|||
wxASSERT( false ); |
|||
} |
|||
|
|||
if( !m_activeClients.count( aCtx.ClientName ) ) |
|||
pushCurrentCommit( aCtx, _( "Created items via API" ) ); |
|||
} |
|||
|
|||
aItemHandler( status, newItem ); |
|||
} |
|||
|
|||
|
|||
return ItemRequestStatus::IRS_OK; |
|||
} |
|||
|
|||
|
|||
void API_HANDLER_SCH::deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete, |
|||
const HANDLER_CONTEXT& aCtx ) |
|||
{ |
|||
// TODO
|
|||
} |
|||
|
|||
|
|||
std::optional<EDA_ITEM*> API_HANDLER_SCH::getItemFromDocument( const DocumentSpecifier& aDocument, |
|||
const KIID& aId ) |
|||
{ |
|||
if( !validateDocument( aDocument ) ) |
|||
return std::nullopt; |
|||
|
|||
// TODO
|
|||
|
|||
return std::nullopt; |
|||
} |
@ -0,0 +1,74 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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 KICAD_API_HANDLER_SCH_H |
|||
#define KICAD_API_HANDLER_SCH_H |
|||
|
|||
#include <api/api_handler_editor.h> |
|||
#include <api/common/commands/editor_commands.pb.h> |
|||
#include <kiid.h> |
|||
|
|||
using namespace kiapi; |
|||
using namespace kiapi::common; |
|||
|
|||
class SCH_EDIT_FRAME; |
|||
class SCH_ITEM; |
|||
|
|||
|
|||
class API_HANDLER_SCH : public API_HANDLER_EDITOR |
|||
{ |
|||
public: |
|||
API_HANDLER_SCH( SCH_EDIT_FRAME* aFrame ); |
|||
|
|||
protected: |
|||
std::unique_ptr<COMMIT> createCommit() override; |
|||
|
|||
kiapi::common::types::DocumentType thisDocumentType() const override |
|||
{ |
|||
return kiapi::common::types::DOCTYPE_SCHEMATIC; |
|||
} |
|||
|
|||
bool validateDocumentInternal( const DocumentSpecifier& aDocument ) const override; |
|||
|
|||
HANDLER_RESULT<std::unique_ptr<EDA_ITEM>> createItemForType( KICAD_T aType, |
|||
EDA_ITEM* aContainer ); |
|||
|
|||
HANDLER_RESULT<types::ItemRequestStatus> handleCreateUpdateItemsInternal( bool aCreate, |
|||
const HANDLER_CONTEXT& aCtx, |
|||
const types::ItemHeader &aHeader, |
|||
const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems, |
|||
std::function<void(commands::ItemStatus, google::protobuf::Any)> aItemHandler ) |
|||
override; |
|||
|
|||
void deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete, |
|||
const HANDLER_CONTEXT& aCtx ) override; |
|||
|
|||
std::optional<EDA_ITEM*> getItemFromDocument( const DocumentSpecifier& aDocument, |
|||
const KIID& aId ) override; |
|||
|
|||
private: |
|||
HANDLER_RESULT<commands::GetOpenDocumentsResponse> handleGetOpenDocuments( |
|||
commands::GetOpenDocuments& aMsg, const HANDLER_CONTEXT& aCtx ); |
|||
|
|||
SCH_EDIT_FRAME* m_frame; |
|||
}; |
|||
|
|||
|
|||
#endif //KICAD_API_HANDLER_SCH_H |
@ -0,0 +1,107 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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 <lib_field.h>
|
|||
#include <lib_pin.h>
|
|||
#include <lib_shape.h>
|
|||
#include <lib_symbol.h>
|
|||
#include <lib_text.h>
|
|||
#include <lib_textbox.h>
|
|||
|
|||
#include <sch_bitmap.h>
|
|||
#include <sch_bus_entry.h>
|
|||
#include <sch_field.h>
|
|||
#include <sch_junction.h>
|
|||
#include <sch_label.h>
|
|||
#include <sch_line.h>
|
|||
#include <sch_no_connect.h>
|
|||
#include <sch_pin.h>
|
|||
#include <sch_shape.h>
|
|||
#include <sch_sheet.h>
|
|||
#include <sch_sheet_pin.h>
|
|||
#include <sch_table.h>
|
|||
#include <sch_tablecell.h>
|
|||
#include <sch_text.h>
|
|||
#include <sch_textbox.h>
|
|||
|
|||
#include "api_sch_utils.h"
|
|||
|
|||
|
|||
std::unique_ptr<EDA_ITEM> CreateItemForType( KICAD_T aType, EDA_ITEM* aContainer ) |
|||
{ |
|||
SCH_ITEM* parentSchItem = dynamic_cast<SCH_ITEM*>( aContainer ); |
|||
LIB_SYMBOL* parentLibSymbol = nullptr; |
|||
|
|||
if( aContainer && aContainer->Type() == LIB_SYMBOL_T ) |
|||
parentLibSymbol = static_cast<LIB_SYMBOL*>( aContainer ); |
|||
|
|||
switch( aType ) |
|||
{ |
|||
case SCH_JUNCTION_T: return std::make_unique<SCH_JUNCTION>(); |
|||
case SCH_NO_CONNECT_T: return std::make_unique<SCH_NO_CONNECT>(); |
|||
case SCH_BUS_WIRE_ENTRY_T: return std::make_unique<SCH_BUS_WIRE_ENTRY>(); |
|||
case SCH_BUS_BUS_ENTRY_T: return std::make_unique<SCH_BUS_BUS_ENTRY>(); |
|||
case SCH_LINE_T: return std::make_unique<SCH_LINE>(); |
|||
case SCH_SHAPE_T: return std::make_unique<SCH_SHAPE>(); |
|||
case SCH_BITMAP_T: return std::make_unique<SCH_BITMAP>(); |
|||
case SCH_TEXTBOX_T: return std::make_unique<SCH_TEXTBOX>(); |
|||
case SCH_TEXT_T: return std::make_unique<SCH_TEXT>(); |
|||
case SCH_TABLE_T: return std::make_unique<SCH_TABLE>(); |
|||
case SCH_TABLECELL_T: return std::make_unique<SCH_TABLECELL>(); |
|||
case SCH_LABEL_T: return std::make_unique<SCH_LABEL>(); |
|||
case SCH_GLOBAL_LABEL_T: return std::make_unique<SCH_GLOBALLABEL>(); |
|||
case SCH_HIER_LABEL_T: return std::make_unique<SCH_HIERLABEL>(); |
|||
case SCH_DIRECTIVE_LABEL_T: return std::make_unique<SCH_DIRECTIVE_LABEL>(); |
|||
case SCH_FIELD_T: return std::make_unique<SCH_FIELD>( parentSchItem ); |
|||
|
|||
case SCH_SYMBOL_T: |
|||
{ |
|||
// TODO: constructing currently requires more than just a "container" LIB_SYMBOL
|
|||
return nullptr; |
|||
} |
|||
|
|||
case SCH_SHEET_PIN_T: |
|||
{ |
|||
if( aContainer && aContainer->Type() == SCH_SHEET_T ) |
|||
return std::make_unique<SCH_SHEET_PIN>( static_cast<SCH_SHEET*>( aContainer ) ); |
|||
|
|||
return nullptr; |
|||
} |
|||
|
|||
case SCH_SHEET_T: return std::make_unique<SCH_SHEET>(); |
|||
|
|||
case SCH_PIN_T: |
|||
{ |
|||
// TODO: constructing currently requires LIB_PIN and SCH_SYMBOL ptr,
|
|||
// or SCH_SYMBOL and number+alt. Need to determine ideal default ctor.
|
|||
return nullptr; |
|||
} |
|||
|
|||
case LIB_SYMBOL_T: return nullptr; // TODO: ctor currently requires non-null name
|
|||
case LIB_SHAPE_T: return std::make_unique<LIB_SHAPE>( parentLibSymbol ); |
|||
case LIB_TEXT_T: return std::make_unique<LIB_TEXT>( parentLibSymbol ); |
|||
case LIB_TEXTBOX_T: return std::make_unique<LIB_TEXTBOX>( parentLibSymbol ); |
|||
case LIB_PIN_T: return std::make_unique<LIB_PIN>( parentLibSymbol ); |
|||
case LIB_FIELD_T: return std::make_unique<LIB_FIELD>( parentLibSymbol ); |
|||
|
|||
default: |
|||
return nullptr; |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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 KICAD_API_SCH_UTILS_H |
|||
#define KICAD_API_SCH_UTILS_H |
|||
|
|||
#include <memory> |
|||
#include <core/typeinfo.h> |
|||
|
|||
class EDA_ITEM; |
|||
|
|||
std::unique_ptr<EDA_ITEM> CreateItemForType( KICAD_T aType, EDA_ITEM* aContainer ); |
|||
|
|||
#endif //KICAD_API_SCH_UTILS_H |
@ -0,0 +1,29 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 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 KICAD_API_ENUMS_H |
|||
#define KICAD_API_ENUMS_H |
|||
|
|||
template<typename KiCadEnum, typename ProtoEnum> |
|||
KiCadEnum FromProtoEnum( ProtoEnum aEnumValue ); |
|||
|
|||
template<typename KiCadEnum, typename ProtoEnum> |
|||
ProtoEnum ToProtoEnum( KiCadEnum aEnumValue ); |
|||
|
|||
#endif //KICAD_API_ENUMS_H |
@ -0,0 +1,115 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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 KICAD_API_HANDLER_EDITOR_H |
|||
#define KICAD_API_HANDLER_EDITOR_H |
|||
|
|||
#include <api/api_handler.h> |
|||
#include <api/common/commands/editor_commands.pb.h> |
|||
#include <commit.h> |
|||
#include <kiid.h> |
|||
|
|||
using namespace kiapi::common; |
|||
using kiapi::common::types::DocumentSpecifier; |
|||
using kiapi::common::types::ItemRequestStatus; |
|||
using kiapi::common::commands::ItemDeletionStatus; |
|||
|
|||
class EDA_BASE_FRAME; |
|||
|
|||
/** |
|||
* Base class for API handlers related to editor frames |
|||
*/ |
|||
class API_HANDLER_EDITOR : public API_HANDLER |
|||
{ |
|||
public: |
|||
API_HANDLER_EDITOR( EDA_BASE_FRAME* aFrame = nullptr ); |
|||
|
|||
protected: |
|||
/// If the header is valid, returns the item container |
|||
HANDLER_RESULT<std::optional<KIID>> validateItemHeaderDocument( |
|||
const kiapi::common::types::ItemHeader& aHeader ); |
|||
|
|||
HANDLER_RESULT<bool> validateDocument( const DocumentSpecifier& aDocument ); |
|||
|
|||
/** |
|||
* Checks if the editor can accept commands |
|||
* @return an error status if busy, std::nullopt if not busy |
|||
*/ |
|||
virtual std::optional<ApiResponseStatus> checkForBusy(); |
|||
|
|||
HANDLER_RESULT<commands::BeginCommitResponse> handleBeginCommit( commands::BeginCommit& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ); |
|||
|
|||
HANDLER_RESULT<commands::EndCommitResponse> handleEndCommit( commands::EndCommit& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ); |
|||
|
|||
COMMIT* getCurrentCommit( const HANDLER_CONTEXT& aCtx ); |
|||
|
|||
virtual void pushCurrentCommit( const HANDLER_CONTEXT& aCtx, const wxString& aMessage ); |
|||
|
|||
HANDLER_RESULT<commands::CreateItemsResponse> handleCreateItems( commands::CreateItems& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ); |
|||
|
|||
HANDLER_RESULT<commands::UpdateItemsResponse> handleUpdateItems( commands::UpdateItems& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ); |
|||
|
|||
HANDLER_RESULT<commands::DeleteItemsResponse> handleDeleteItems( commands::DeleteItems& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ); |
|||
|
|||
HANDLER_RESULT<commands::HitTestResponse> handleHitTest( commands::HitTest& aMsg, |
|||
const HANDLER_CONTEXT& aCtx ); |
|||
|
|||
/** |
|||
* Override this to create an appropriate COMMIT subclass for the frame in question |
|||
* @return a new COMMIT, bound to the editor frame |
|||
*/ |
|||
virtual std::unique_ptr<COMMIT> createCommit() = 0; |
|||
|
|||
/** |
|||
* Override this to specify which document type this editor handles |
|||
*/ |
|||
virtual kiapi::common::types::DocumentType thisDocumentType() const = 0; |
|||
|
|||
/** |
|||
* @return true if the given document is valid for this editor and is currently open |
|||
*/ |
|||
virtual bool validateDocumentInternal( const DocumentSpecifier& aDocument ) const = 0; |
|||
|
|||
virtual HANDLER_RESULT<ItemRequestStatus> handleCreateUpdateItemsInternal( bool aCreate, |
|||
const HANDLER_CONTEXT& aCtx, |
|||
const types::ItemHeader &aHeader, |
|||
const google::protobuf::RepeatedPtrField<google::protobuf::Any>& aItems, |
|||
std::function<void( commands::ItemStatus, google::protobuf::Any )> aItemHandler ) = 0; |
|||
|
|||
virtual void deleteItemsInternal( std::map<KIID, ItemDeletionStatus>& aItemsToDelete, |
|||
const HANDLER_CONTEXT& aCtx ) = 0; |
|||
|
|||
virtual std::optional<EDA_ITEM*> getItemFromDocument( const DocumentSpecifier& aDocument, |
|||
const KIID& aId ) = 0; |
|||
|
|||
protected: |
|||
std::map<std::string, std::pair<KIID, std::unique_ptr<COMMIT>>> m_commits; |
|||
|
|||
std::set<std::string> m_activeClients; |
|||
|
|||
EDA_BASE_FRAME* m_frame; |
|||
}; |
|||
|
|||
#endif //KICAD_API_HANDLER_EDITOR_H |
@ -0,0 +1,48 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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 KICAD_API_UTILS_H |
|||
#define KICAD_API_UTILS_H |
|||
|
|||
#include <optional> |
|||
|
|||
#include <core/typeinfo.h> |
|||
#include <lib_id.h> |
|||
#include <api/common/types/base_types.pb.h> |
|||
#include <google/protobuf/any.pb.h> |
|||
#include <layer_ids.h> |
|||
#include <math/vector2d.h> |
|||
|
|||
namespace kiapi::common |
|||
{ |
|||
|
|||
std::optional<KICAD_T> TypeNameFromAny( const google::protobuf::Any& aMessage ); |
|||
|
|||
LIB_ID LibIdFromProto( const types::LibraryIdentifier& aId ); |
|||
|
|||
types::LibraryIdentifier LibIdToProto( const LIB_ID& aId ); |
|||
|
|||
void PackVector2( kiapi::common::types::Vector2& aOutput, const VECTOR2I aInput ); |
|||
|
|||
VECTOR2I UnpackVector2( const types::Vector2& aInput ); |
|||
|
|||
} // namespace kiapi::common |
|||
|
|||
#endif //KICAD_API_UTILS_H |
@ -0,0 +1,60 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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 KICAD_SERIALIZABLE_H |
|||
#define KICAD_SERIALIZABLE_H |
|||
|
|||
#include <wx/debug.h> |
|||
|
|||
namespace google { |
|||
namespace protobuf { |
|||
class Any; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Interface for objects that can be serialized to Protobuf messages |
|||
*/ |
|||
class SERIALIZABLE |
|||
{ |
|||
public: |
|||
/** |
|||
* Serializes this object to the given Any message. |
|||
* The Any message's concrete type will be specific to the object in question. |
|||
* @param aContainer will be filled with a message describing this object |
|||
*/ |
|||
virtual void Serialize( google::protobuf::Any &aContainer ) const |
|||
{ |
|||
wxASSERT_MSG( false, wxS( "Serialize called on an object that doesn't implement it!" ) ); |
|||
} |
|||
|
|||
/** |
|||
* Deserializes the given protobuf message into this object. |
|||
* @param aContainer is an Any which should have a concrete type matching this object |
|||
* @return true if unpacking and deserialization succeeded |
|||
*/ |
|||
virtual bool Deserialize( const google::protobuf::Any &aContainer ) |
|||
{ |
|||
wxASSERT_MSG( false, wxS( "Deserialize called on an object that doesn't implement it!" ) ); |
|||
return false; |
|||
} |
|||
}; |
|||
|
|||
#endif //KICAD_SERIALIZABLE_H |
@ -0,0 +1,105 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2024 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2024 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 <import_export.h>
|
|||
#include <api/api_enums.h>
|
|||
#include <api/board/board_types.pb.h>
|
|||
#include <wx/wx.h>
|
|||
|
|||
#include <pad_shapes.h>
|
|||
#include <zones.h>
|
|||
|
|||
using namespace kiapi::board; |
|||
|
|||
template<> |
|||
types::PadStackShape ToProtoEnum( PAD_SHAPE aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case PAD_SHAPE::CIRCLE: return types::PadStackShape::PSS_CIRCLE; |
|||
case PAD_SHAPE::RECTANGLE: return types::PadStackShape::PSS_RECTANGLE; |
|||
case PAD_SHAPE::OVAL: return types::PadStackShape::PSS_OVAL; |
|||
case PAD_SHAPE::TRAPEZOID: return types::PadStackShape::PSS_TRAPEZOID; |
|||
case PAD_SHAPE::ROUNDRECT: return types::PadStackShape::PSS_ROUNDRECT; |
|||
case PAD_SHAPE::CHAMFERED_RECT: return types::PadStackShape::PSS_CHAMFEREDRECT; |
|||
case PAD_SHAPE::CUSTOM: return types::PadStackShape::PSS_CUSTOM; |
|||
|
|||
default: |
|||
wxCHECK_MSG( false, types::PadStackShape::PSS_UNKNOWN, |
|||
"Unhandled case in ToProtoEnum<PAD_SHAPE>"); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
PAD_SHAPE FromProtoEnum( types::PadStackShape aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case types::PadStackShape::PSS_CIRCLE: return PAD_SHAPE::CIRCLE; |
|||
case types::PadStackShape::PSS_RECTANGLE: return PAD_SHAPE::RECTANGLE; |
|||
case types::PadStackShape::PSS_OVAL: return PAD_SHAPE::OVAL; |
|||
case types::PadStackShape::PSS_TRAPEZOID: return PAD_SHAPE::TRAPEZOID; |
|||
case types::PadStackShape::PSS_ROUNDRECT: return PAD_SHAPE::ROUNDRECT; |
|||
case types::PadStackShape::PSS_CHAMFEREDRECT: return PAD_SHAPE::CHAMFERED_RECT; |
|||
case types::PadStackShape::PSS_CUSTOM: return PAD_SHAPE::CUSTOM; |
|||
|
|||
default: |
|||
wxCHECK_MSG( false, PAD_SHAPE::CIRCLE, |
|||
"Unhandled case in FromProtoEnum<types::PadStackShape>" ); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
types::ZoneConnectionStyle ToProtoEnum( ZONE_CONNECTION aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case ZONE_CONNECTION::INHERITED: return types::ZoneConnectionStyle::ZCS_INHERITED; |
|||
case ZONE_CONNECTION::NONE: return types::ZoneConnectionStyle::ZCS_NONE; |
|||
case ZONE_CONNECTION::THERMAL: return types::ZoneConnectionStyle::ZCS_THERMAL; |
|||
case ZONE_CONNECTION::FULL: return types::ZoneConnectionStyle::ZCS_FULL; |
|||
case ZONE_CONNECTION::THT_THERMAL: return types::ZoneConnectionStyle::ZCS_PTH_THERMAL; |
|||
|
|||
default: |
|||
wxCHECK_MSG( false, types::ZoneConnectionStyle::ZCS_UNKNOWN, |
|||
"Unhandled case in ToProtoEnum<ZONE_CONNECTION>"); |
|||
} |
|||
} |
|||
|
|||
|
|||
template<> |
|||
ZONE_CONNECTION FromProtoEnum( types::ZoneConnectionStyle aValue ) |
|||
{ |
|||
switch( aValue ) |
|||
{ |
|||
case types::ZoneConnectionStyle::ZCS_UNKNOWN: return ZONE_CONNECTION::INHERITED; |
|||
case types::ZoneConnectionStyle::ZCS_INHERITED: return ZONE_CONNECTION::INHERITED; |
|||
case types::ZoneConnectionStyle::ZCS_NONE: return ZONE_CONNECTION::NONE; |
|||
case types::ZoneConnectionStyle::ZCS_THERMAL: return ZONE_CONNECTION::THERMAL; |
|||
case types::ZoneConnectionStyle::ZCS_FULL: return ZONE_CONNECTION::FULL; |
|||
case types::ZoneConnectionStyle::ZCS_PTH_THERMAL: return ZONE_CONNECTION::THT_THERMAL; |
|||
|
|||
default: |
|||
wxCHECK_MSG( false, ZONE_CONNECTION::INHERITED, |
|||
"Unhandled case in FromProtoEnum<types::ZoneConnectionStyle>" ); |
|||
} |
|||
} |
@ -0,0 +1,100 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* 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 <api/api_pcb_utils.h>
|
|||
#include <api/api_enums.h>
|
|||
#include <board.h>
|
|||
#include <board_item_container.h>
|
|||
#include <footprint.h>
|
|||
#include <pad.h>
|
|||
#include <pcb_group.h>
|
|||
#include <pcb_reference_image.h>
|
|||
#include <pcb_shape.h>
|
|||
#include <pcb_track.h>
|
|||
#include <pcb_text.h>
|
|||
#include <pcb_textbox.h>
|
|||
#include <zone.h>
|
|||
|
|||
|
|||
std::unique_ptr<BOARD_ITEM> CreateItemForType( KICAD_T aType, BOARD_ITEM_CONTAINER* aContainer ) |
|||
{ |
|||
switch( aType ) |
|||
{ |
|||
case PCB_TRACE_T: return std::make_unique<PCB_TRACK>( aContainer ); |
|||
case PCB_ARC_T: return std::make_unique<PCB_ARC>( aContainer ); |
|||
case PCB_VIA_T: return std::make_unique<PCB_VIA>( aContainer ); |
|||
case PCB_TEXT_T: return std::make_unique<PCB_TEXT>( aContainer ); |
|||
case PCB_TEXTBOX_T: return std::make_unique<PCB_TEXTBOX>( aContainer ); |
|||
case PCB_SHAPE_T: return std::make_unique<PCB_SHAPE>( aContainer ); |
|||
case PCB_ZONE_T: return std::make_unique<ZONE>( aContainer ); |
|||
case PCB_GROUP_T: return std::make_unique<PCB_GROUP>( aContainer ); |
|||
case PCB_REFERENCE_IMAGE_T: return std::make_unique<PCB_REFERENCE_IMAGE>( aContainer ); |
|||
|
|||
case PCB_PAD_T: |
|||
{ |
|||
FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aContainer ); |
|||
|
|||
if( !footprint ) |
|||
return nullptr; |
|||
|
|||
return std::make_unique<PAD>( footprint ); |
|||
} |
|||
|
|||
case PCB_FOOTPRINT_T: |
|||
{ |
|||
BOARD* board = dynamic_cast<BOARD*>( aContainer ); |
|||
|
|||
if( !board ) |
|||
return nullptr; |
|||
|
|||
return std::make_unique<FOOTPRINT>( board ); |
|||
} |
|||
|
|||
default: |
|||
return nullptr; |
|||
} |
|||
} |
|||
|
|||
namespace kiapi::board |
|||
{ |
|||
|
|||
void PackLayerSet( google::protobuf::RepeatedField<int>& aOutput, const LSET& aLayerSet ) |
|||
{ |
|||
for( const PCB_LAYER_ID& layer : aLayerSet.Seq() ) |
|||
aOutput.Add( ToProtoEnum<PCB_LAYER_ID, types::BoardLayer>( layer ) ); |
|||
} |
|||
|
|||
|
|||
LSET UnpackLayerSet( const google::protobuf::RepeatedField<int>& aProtoLayerSet ) |
|||
{ |
|||
LSET set; |
|||
|
|||
for( int layer : aProtoLayerSet ) |
|||
{ |
|||
wxCHECK2( layer >= F_Cu && layer < PCB_LAYER_ID_COUNT, continue ); |
|||
PCB_LAYER_ID boardLayer = |
|||
FromProtoEnum<PCB_LAYER_ID>( static_cast<types::BoardLayer>( layer ) ); |
|||
set.set( boardLayer ); |
|||
} |
|||
|
|||
return set; |
|||
} |
|||
|
|||
} // namespace kiapi::board
|
@ -0,0 +1,45 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2023 Jon Evans <jon@craftyjon.com> |
|||
* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify it |
|||
* under the terms of the GNU General Public License as published by the |
|||
* 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 KICAD_API_PCB_UTLIS_H |
|||
#define KICAD_API_PCB_UTLIS_H |
|||
|
|||
#include <memory> |
|||
#include <core/typeinfo.h> |
|||
#include <import_export.h> |
|||
#include <layer_ids.h> |
|||
#include <api/common/types/base_types.pb.h> |
|||
#include <api/board/board_types.pb.h> |
|||
|
|||
class BOARD_ITEM; |
|||
class BOARD_ITEM_CONTAINER; |
|||
|
|||
std::unique_ptr<BOARD_ITEM> CreateItemForType( KICAD_T aType, BOARD_ITEM_CONTAINER* aContainer ); |
|||
|
|||
namespace kiapi::board |
|||
{ |
|||
|
|||
void PackLayerSet( google::protobuf::RepeatedField<int>& aOutput, const LSET& aLayerSet ); |
|||
|
|||
LSET UnpackLayerSet( const google::protobuf::RepeatedField<int>& aInput ); |
|||
|
|||
} // namespace kiapi::board |
|||
|
|||
#endif //KICAD_API_PCB_UTLIS_H |
3878
qa/data/pcbnew/api_kitchen_sink.kicad_pcb
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,272 @@ |
|||
{ |
|||
"board": { |
|||
"3dviewports": [], |
|||
"design_settings": { |
|||
"defaults": { |
|||
"apply_defaults_to_fp_fields": false, |
|||
"apply_defaults_to_fp_shapes": false, |
|||
"apply_defaults_to_fp_text": false, |
|||
"board_outline_line_width": 0.05, |
|||
"copper_line_width": 0.2, |
|||
"copper_text_italic": false, |
|||
"copper_text_size_h": 1.5, |
|||
"copper_text_size_v": 1.5, |
|||
"copper_text_thickness": 0.3, |
|||
"copper_text_upright": false, |
|||
"courtyard_line_width": 0.05, |
|||
"dimension_precision": 4, |
|||
"dimension_units": 3, |
|||
"dimensions": { |
|||
"arrow_length": 1270000, |
|||
"extension_offset": 500000, |
|||
"keep_text_aligned": true, |
|||
"suppress_zeroes": false, |
|||
"text_position": 0, |
|||
"units_format": 1 |
|||
}, |
|||
"fab_line_width": 0.1, |
|||
"fab_text_italic": false, |
|||
"fab_text_size_h": 1.0, |
|||
"fab_text_size_v": 1.0, |
|||
"fab_text_thickness": 0.15, |
|||
"fab_text_upright": false, |
|||
"other_line_width": 0.1, |
|||
"other_text_italic": false, |
|||
"other_text_size_h": 1.0, |
|||
"other_text_size_v": 1.0, |
|||
"other_text_thickness": 0.15, |
|||
"other_text_upright": false, |
|||
"pads": { |
|||
"drill": 1.143, |
|||
"height": 2.032, |
|||
"width": 2.032 |
|||
}, |
|||
"silk_line_width": 0.1, |
|||
"silk_text_italic": false, |
|||
"silk_text_size_h": 1.0, |
|||
"silk_text_size_v": 1.0, |
|||
"silk_text_thickness": 0.1, |
|||
"silk_text_upright": false, |
|||
"zones": { |
|||
"min_clearance": 0.5 |
|||
} |
|||
}, |
|||
"diff_pair_dimensions": [], |
|||
"drc_exclusions": [], |
|||
"meta": { |
|||
"version": 2 |
|||
}, |
|||
"rule_severities": { |
|||
"annular_width": "error", |
|||
"clearance": "error", |
|||
"connection_width": "warning", |
|||
"copper_edge_clearance": "error", |
|||
"copper_sliver": "warning", |
|||
"courtyards_overlap": "error", |
|||
"diff_pair_gap_out_of_range": "error", |
|||
"diff_pair_uncoupled_length_too_long": "error", |
|||
"drill_out_of_range": "error", |
|||
"duplicate_footprints": "warning", |
|||
"extra_footprint": "warning", |
|||
"footprint": "error", |
|||
"footprint_symbol_mismatch": "warning", |
|||
"footprint_type_mismatch": "ignore", |
|||
"hole_clearance": "error", |
|||
"hole_near_hole": "error", |
|||
"invalid_outline": "error", |
|||
"isolated_copper": "warning", |
|||
"item_on_disabled_layer": "error", |
|||
"items_not_allowed": "error", |
|||
"length_out_of_range": "error", |
|||
"lib_footprint_issues": "warning", |
|||
"lib_footprint_mismatch": "warning", |
|||
"malformed_courtyard": "error", |
|||
"microvia_drill_out_of_range": "error", |
|||
"missing_courtyard": "ignore", |
|||
"missing_footprint": "warning", |
|||
"net_conflict": "warning", |
|||
"npth_inside_courtyard": "ignore", |
|||
"padstack": "warning", |
|||
"pth_inside_courtyard": "ignore", |
|||
"shorting_items": "error", |
|||
"silk_edge_clearance": "warning", |
|||
"silk_over_copper": "warning", |
|||
"silk_overlap": "warning", |
|||
"skew_out_of_range": "error", |
|||
"solder_mask_bridge": "error", |
|||
"starved_thermal": "error", |
|||
"text_height": "warning", |
|||
"text_thickness": "warning", |
|||
"through_hole_pad_without_hole": "error", |
|||
"too_many_vias": "error", |
|||
"track_dangling": "warning", |
|||
"track_width": "error", |
|||
"tracks_crossing": "error", |
|||
"unconnected_items": "error", |
|||
"unresolved_variable": "error", |
|||
"via_dangling": "warning", |
|||
"zones_intersect": "error" |
|||
}, |
|||
"rules": { |
|||
"max_error": 0.005, |
|||
"min_clearance": 0.0, |
|||
"min_connection": 0.0, |
|||
"min_copper_edge_clearance": 0.5, |
|||
"min_hole_clearance": 0.25, |
|||
"min_hole_to_hole": 0.25, |
|||
"min_microvia_diameter": 0.2, |
|||
"min_microvia_drill": 0.1, |
|||
"min_resolved_spokes": 2, |
|||
"min_silk_clearance": 0.0, |
|||
"min_text_height": 0.8, |
|||
"min_text_thickness": 0.08, |
|||
"min_through_hole_diameter": 0.3, |
|||
"min_track_width": 0.0, |
|||
"min_via_annular_width": 0.1, |
|||
"min_via_diameter": 0.5, |
|||
"solder_mask_to_copper_clearance": 0.0, |
|||
"use_height_for_length_calcs": true |
|||
}, |
|||
"teardrop_options": [ |
|||
{ |
|||
"td_onpadsmd": true, |
|||
"td_onroundshapesonly": false, |
|||
"td_ontrackend": false, |
|||
"td_onviapad": true |
|||
} |
|||
], |
|||
"teardrop_parameters": [ |
|||
{ |
|||
"td_allow_use_two_tracks": true, |
|||
"td_curve_segcount": 0, |
|||
"td_height_ratio": 1.0, |
|||
"td_length_ratio": 0.5, |
|||
"td_maxheight": 2.0, |
|||
"td_maxlen": 1.0, |
|||
"td_on_pad_in_zone": false, |
|||
"td_target_name": "td_round_shape", |
|||
"td_width_to_size_filter_ratio": 0.9 |
|||
}, |
|||
{ |
|||
"td_allow_use_two_tracks": true, |
|||
"td_curve_segcount": 0, |
|||
"td_height_ratio": 1.0, |
|||
"td_length_ratio": 0.5, |
|||
"td_maxheight": 2.0, |
|||
"td_maxlen": 1.0, |
|||
"td_on_pad_in_zone": false, |
|||
"td_target_name": "td_rect_shape", |
|||
"td_width_to_size_filter_ratio": 0.9 |
|||
}, |
|||
{ |
|||
"td_allow_use_two_tracks": true, |
|||
"td_curve_segcount": 0, |
|||
"td_height_ratio": 1.0, |
|||
"td_length_ratio": 0.5, |
|||
"td_maxheight": 2.0, |
|||
"td_maxlen": 1.0, |
|||
"td_on_pad_in_zone": false, |
|||
"td_target_name": "td_track_end", |
|||
"td_width_to_size_filter_ratio": 0.9 |
|||
} |
|||
], |
|||
"track_widths": [], |
|||
"tuning_pattern_settings": { |
|||
"diff_pair_defaults": { |
|||
"corner_radius_percentage": 80, |
|||
"corner_style": 1, |
|||
"max_amplitude": 1.0, |
|||
"min_amplitude": 0.2, |
|||
"single_sided": false, |
|||
"spacing": 1.0 |
|||
}, |
|||
"diff_pair_skew_defaults": { |
|||
"corner_radius_percentage": 80, |
|||
"corner_style": 1, |
|||
"max_amplitude": 1.0, |
|||
"min_amplitude": 0.2, |
|||
"single_sided": false, |
|||
"spacing": 0.6 |
|||
}, |
|||
"single_track_defaults": { |
|||
"corner_radius_percentage": 80, |
|||
"corner_style": 1, |
|||
"max_amplitude": 1.0, |
|||
"min_amplitude": 0.2, |
|||
"single_sided": false, |
|||
"spacing": 0.6 |
|||
} |
|||
}, |
|||
"via_dimensions": [], |
|||
"zones_allow_external_fillets": false |
|||
}, |
|||
"ipc2581": { |
|||
"dist": "", |
|||
"distpn": "", |
|||
"internal_id": "", |
|||
"mfg": "", |
|||
"mpn": "" |
|||
}, |
|||
"layer_presets": [], |
|||
"viewports": [] |
|||
}, |
|||
"boards": [], |
|||
"cvpcb": { |
|||
"equivalence_files": [] |
|||
}, |
|||
"libraries": { |
|||
"pinned_footprint_libs": [], |
|||
"pinned_symbol_libs": [] |
|||
}, |
|||
"meta": { |
|||
"filename": "api_kitchen_sink.kicad_pro", |
|||
"version": 1 |
|||
}, |
|||
"net_settings": { |
|||
"classes": [ |
|||
{ |
|||
"bus_width": 12, |
|||
"clearance": 0.2, |
|||
"diff_pair_gap": 0.25, |
|||
"diff_pair_via_gap": 0.25, |
|||
"diff_pair_width": 0.2, |
|||
"line_style": 0, |
|||
"microvia_diameter": 0.3, |
|||
"microvia_drill": 0.1, |
|||
"name": "Default", |
|||
"pcb_color": "rgba(0, 0, 0, 0.000)", |
|||
"schematic_color": "rgba(0, 0, 0, 0.000)", |
|||
"track_width": 0.2, |
|||
"via_diameter": 0.6, |
|||
"via_drill": 0.3, |
|||
"wire_width": 6 |
|||
} |
|||
], |
|||
"meta": { |
|||
"version": 3 |
|||
}, |
|||
"net_colors": null, |
|||
"netclass_assignments": null, |
|||
"netclass_patterns": [] |
|||
}, |
|||
"pcbnew": { |
|||
"last_paths": { |
|||
"gencad": "", |
|||
"idf": "", |
|||
"netlist": "", |
|||
"plot": "", |
|||
"pos_files": "", |
|||
"specctra_dsn": "", |
|||
"step": "", |
|||
"svg": "", |
|||
"vrml": "" |
|||
}, |
|||
"page_layout_descr_file": "" |
|||
}, |
|||
"schematic": { |
|||
"legacy_lib_dir": "", |
|||
"legacy_lib_list": [] |
|||
}, |
|||
"sheets": [], |
|||
"text_variables": {} |
|||
} |
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue