KiCad PCB EDA Suite
Loading...
Searching...
No Matches
nl_footprint_properties_plugin_impl.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 3Dconnexion
5 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
23
24// KiCAD includes
25#include <tool/action_manager.h>
26#include <tool/tool_manager.h>
27#include <tool/tools_holder.h>
28
29#include <wx/mstream.h>
30
31#define BOUNDING_BOX_SCALE_FACTOR 1.3f
32
41 wxT( "KI_TRACE_NL_FOOTPRINT_PROPERTIES_PLUGIN" );
42
43
45 NL_3D_VIEWER_PLUGIN_IMPL(aCanvas, "KiCAD Footprint Properties")
46{}
47
48
49long NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::GetModelExtents( navlib::box_t& extents ) const
50{
53
54 SFVEC3F diff = ( BOUNDING_BOX_SCALE_FACTOR - 1.f ) / 2.f * ( max - min );
55
56 min -= diff;
57 max += diff;
58
59 extents = { min.x, min.y, min.z, max.x, max.y, max.z };
60
61 return 0;
62}
63
64
66{
67 std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList();
68
69 if( actions.size() == 0 )
70 {
71 return;
72 }
73
74 using TDx::SpaceMouse::CCommand;
75 using TDx::SpaceMouse::CCommandSet;
76
77 // The root action set node
78 CCommandSet commandSet( "EDA_3D_CANVAS", "3D Viewer" );
79
80 // Activate the command set
81 NAV_3D::PutActiveCommands( commandSet.GetId() );
82
83 // temporary store for the categories
84 CATEGORY_STORE categoryStore;
85
86 std::vector<TDx::CImage> vImages;
87
88 // add the action set to the category_store
89 categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type( ".", &commandSet ) );
90
91 std::list<TOOL_ACTION*>::const_iterator it;
92
93 for( it = actions.begin(); it != actions.end(); ++it )
94 {
95 const TOOL_ACTION* action = *it;
96 std::string label = action->GetMenuLabel().ToStdString();
97
98 if( label.empty() )
99 {
100 continue;
101 }
102
103 std::string name = action->GetName();
104
105 // Do no export commands for the pcbnew app.
106 if( name.rfind( "pcbnew.", 0 ) == 0 )
107 {
108 continue;
109 }
110
111 // Exclude commands which can't be used in the footprint properties.
112 if( name.rfind( "3DViewer.Control.pivotCenter", 0 ) == 0
113 || name.rfind( "3DViewer.Control.material", 0 ) == 0
114 || name.rfind( "3DViewer.Control.attribute", 0 ) == 0
115 || name.rfind( "3DViewer.Control.show", 0 ) == 0 )
116 {
117 continue;
118 }
119
120 std::string strCategory = action->GetToolName();
121 CATEGORY_STORE::iterator iter = categoryStore.find( strCategory );
122
123 if( iter == categoryStore.end() )
124 {
125 iter = add_category( std::move( strCategory ), categoryStore );
126 }
127
128 std::string description = action->GetDescription().ToStdString();
129
130 // Arbitrary 8-bit data stream
131 wxMemoryOutputStream imageStream;
132
133 if( action->GetIcon() != BITMAPS::INVALID_BITMAP )
134 {
135 wxImage image = KiBitmap( action->GetIcon() ).ConvertToImage();
136 image.SaveFile( imageStream, wxBitmapType::wxBITMAP_TYPE_PNG );
137 image.Destroy();
138
139 if( imageStream.GetSize() )
140 {
141 wxStreamBuffer* streamBuffer = imageStream.GetOutputStreamBuffer();
142 TDx::CImage tdxImage = TDx::CImage::FromData( "", 0, name.c_str() );
143 tdxImage.AssignImage( std::string( reinterpret_cast<const char*>(
144 streamBuffer->GetBufferStart() ),
145 streamBuffer->GetBufferSize() ),
146 0 );
147
148 wxLogTrace( m_logTrace, wxT( "Adding image for : %s" ), name );
149 vImages.push_back( std::move( tdxImage ) );
150 }
151 }
152
153 wxLogTrace( m_logTrace, wxT( "Inserting command: %s, description: %s, in category: %s" ),
154 name, description, iter->first );
155
156 iter->second->push_back(
157 CCommand( std::move( name ), std::move( label ), std::move( description ) ) );
158 }
159
160 NAV_3D::AddCommandSet( commandSet );
161 NAV_3D::AddImages( vImages );
162}
const char * name
Definition: DXF_plotter.cpp:57
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
const BBOX_3D & GetBBox() const noexcept
Get the board outling bounding box.
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:49
const BOARD_ADAPTER & GetBoardAdapter() const
Get information used to display 3D board.
The class that implements the accessors and mutators required for 3D navigation in an EDA_3D_CANVAS u...
EDA_3D_CANVAS * GetCanvas() const
Get the m_canvas pointer.
void exportCommandsAndImages() override
Export the invocable actions and images to the 3Dconnexion UI.
long GetModelExtents(navlib::box_t &extents) const override
Get Footprint 3D Model extents.
NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL(EDA_3D_CANVAS *aCanvas)
Initializes a new instance of the NL_FOOTPRINT_PROPERTIES_PLUGIN.
Represent a single user action.
Definition: tool_action.h:269
wxString GetMenuLabel() const
Return the translated label for the action.
BITMAPS GetIcon() const
Return an icon associated with the action.
Definition: tool_action.h:422
std::string GetToolName() const
Return name of the tool associated with the action.
const std::string & GetName() const
Return name of the action.
Definition: tool_action.h:302
wxString GetDescription() const
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
CATEGORY_STORE::iterator add_category(std::string aCategoryPath, CATEGORY_STORE &aCategoryStore)
Add a category to the store.
std::map< std::string, TDx::CCommandTreeNode * > CATEGORY_STORE
#define BOUNDING_BOX_SCALE_FACTOR
declaration of the nl_footprint_properties_plugin_impl class
const SFVEC3F & Min() const
Return the minimum vertex pointer.
Definition: bbox_3d.h:192
const SFVEC3F & Max() const
Return the maximum vertex pointer.
Definition: bbox_3d.h:199
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44