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 The 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
23
24// KiCAD includes
25#include <bitmaps.h>
26#include <tool/action_manager.h>
27#include <tool/tool_manager.h>
28#include <tool/tools_holder.h>
31
32#include <wx/mstream.h>
33
34
35#define BOUNDING_BOX_SCALE_FACTOR 1.3f
36
45 wxT( "KI_TRACE_NL_FOOTPRINT_PROPERTIES_PLUGIN" );
46
47
51
52
53long NL_FOOTPRINT_PROPERTIES_PLUGIN_IMPL::GetModelExtents( navlib::box_t& extents ) const
54{
57
58 SFVEC3F diff = ( BOUNDING_BOX_SCALE_FACTOR - 1.f ) / 2.f * ( max - min );
59
60 min -= diff;
61 max += diff;
62
63 extents = { min.x, min.y, min.z, max.x, max.y, max.z };
64
65 return 0;
66}
67
68
70{
71 std::list<TOOL_ACTION*> actions = ACTION_MANAGER::GetActionList();
72
73 if( actions.size() == 0 )
74 {
75 return;
76 }
77
78 using TDx::SpaceMouse::CCommand;
79 using TDx::SpaceMouse::CCommandSet;
80
81 // The root action set node
82 CCommandSet commandSet( "EDA_3D_CANVAS", "3D Viewer" );
83
84 // Activate the command set
85 NAV_3D::PutActiveCommands( commandSet.GetId() );
86
87 // temporary store for the categories
88 CATEGORY_STORE categoryStore;
89
90 std::vector<TDx::CImage> vImages;
91
92 // add the action set to the category_store
93 categoryStore.insert( categoryStore.end(), CATEGORY_STORE::value_type( ".", &commandSet ) );
94
95 std::list<TOOL_ACTION*>::const_iterator it;
96
97 for( it = actions.begin(); it != actions.end(); ++it )
98 {
99 const TOOL_ACTION* action = *it;
100 std::string label = action->GetMenuLabel().ToStdString();
101
102 if( label.empty() )
103 {
104 continue;
105 }
106
107 std::string name = action->GetName();
108
109 // Do no export commands for the pcbnew app.
110 if( name.rfind( "pcbnew.", 0 ) == 0 )
111 {
112 continue;
113 }
114
115 // Exclude commands which can't be used in the footprint properties.
116 if( name.rfind( "3DViewer.Control.pivotCenter", 0 ) == 0
117 || name.rfind( "3DViewer.Control.material", 0 ) == 0
118 || name.rfind( "3DViewer.Control.attribute", 0 ) == 0
119 || name.rfind( "3DViewer.Control.show", 0 ) == 0 )
120 {
121 continue;
122 }
123
124 std::string strCategory = action->GetToolName();
125 CATEGORY_STORE::iterator iter = categoryStore.find( strCategory );
126
127 if( iter == categoryStore.end() )
128 {
129 iter = add_category( std::move( strCategory ), categoryStore );
130 }
131
132 std::string description = action->GetDescription().ToStdString();
133
134 // Arbitrary 8-bit data stream
135 wxMemoryOutputStream imageStream;
136
137 if( action->GetIcon() != BITMAPS::INVALID_BITMAP )
138 {
139 wxImage image = KiBitmap( action->GetIcon() ).ConvertToImage();
140 image.SaveFile( imageStream, wxBitmapType::wxBITMAP_TYPE_PNG );
141 image.Destroy();
142
143 if( imageStream.GetSize() )
144 {
145 wxStreamBuffer* streamBuffer = imageStream.GetOutputStreamBuffer();
146 TDx::CImage tdxImage = TDx::CImage::FromData( "", 0, name.c_str() );
147 tdxImage.AssignImage( std::string( reinterpret_cast<const char*>( streamBuffer->GetBufferStart() ),
148 streamBuffer->GetBufferSize() ),
149 0 );
150
151 wxLogTrace( m_logTrace, wxT( "Adding image for : %s" ), name );
152 vImages.push_back( std::move( tdxImage ) );
153 }
154 }
155
156 wxLogTrace( m_logTrace, wxT( "Inserting command: %s, description: %s, in category: %s" ),
157 name, description, iter->first );
158
159 iter->second->push_back(
160 CCommand( std::move( name ), std::move( label ), std::move( description ) ) );
161 }
162
163 NAV_3D::AddCommandSet( commandSet );
164 NAV_3D::AddImages( vImages );
165}
const char * name
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:100
@ INVALID_BITMAP
static std::list< TOOL_ACTION * > & GetActionList()
Return list of TOOL_ACTIONs.
const BBOX_3D & GetBBox() const noexcept
Get the board outline bounding box.
Implement a canvas based on a wxGLCanvas.
const BOARD_ADAPTER & GetBoardAdapter() const
Get information used to display 3D board.
EDA_3D_CANVAS * GetCanvas() const
Get the m_canvas pointer.
NL_3D_VIEWER_PLUGIN_IMPL(EDA_3D_CANVAS *aCanvas, const std::string &aProfileHint)
Initializes a new instance of the NL_3DVIEWER_PLUGIN.
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)
Initialize a new instance of the NL_FOOTPRINT_PROPERTIES_PLUGIN.
Represent a single user action.
wxString GetMenuLabel() const
Return the translated label for the action.
BITMAPS GetIcon() const
Return an icon associated with the action.
std::string GetToolName() const
Return name of the tool associated with the action.
const std::string & GetName() const
Return name of the action.
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
declaration of the nl_footprint_properties_plugin_impl class
const SFVEC3F & Min() const
Return the minimum vertex pointer.
Definition bbox_3d.h:188
const SFVEC3F & Max() const
Return the maximum vertex pointer.
Definition bbox_3d.h:195
glm::vec3 SFVEC3F
Definition xv3d_types.h:40