KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_export_vrml.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) 2009-2013 Lorenzo Mercantonio
5 * Copyright (C) 2013 Jean-Pierre Charras jp.charras at wanadoo.fr
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
29#include <wx/dir.h>
30
31#include <base_units.h>
32#include <board.h>
33#include <confirm.h>
34#include <kiface_base.h>
35#include <pcb_edit_frame.h>
36#include <pcbnew_settings.h>
38#include <project/project_file.h> // LAST_PATH_TYPE
39#include <wx/msgdlg.h>
40
41#include <dialog_export_vrml.h>
42
43
45 DIALOG_EXPORT_VRML_BASE( aEditFrame ),
46 m_editFrame( aEditFrame ),
47 m_unitsOpt( 1 ),
48 m_noUnspecified( false ),
49 m_noDNP( false ),
50 m_copy3DFilesOpt( false ),
51 m_useRelativePathsOpt( false ),
52 m_RefUnits( 0 ),
53 m_XRef( 0.0 ),
54 m_YRef( 0.0 ),
55 m_originMode( 0 )
56{
57 m_filePicker->SetFocus();
58
60 {
61 m_unitsOpt = cfg->m_ExportVrml.units;
62 m_noUnspecified = cfg->m_ExportVrml.no_unspecified;
63 m_noDNP = cfg->m_ExportVrml.no_dnp;
64 m_copy3DFilesOpt = cfg->m_ExportVrml.copy_3d_models;
65 m_useRelativePathsOpt = cfg->m_ExportVrml.use_relative_paths;
66 m_RefUnits = cfg->m_ExportVrml.ref_units;
67 m_XRef = cfg->m_ExportVrml.ref_x;
68 m_YRef = cfg->m_ExportVrml.ref_y;
69 m_originMode = cfg->m_ExportVrml.origin_mode;
70 }
71
72 m_rbCoordOrigin->SetSelection( m_originMode );
73 m_rbSelectUnits->SetSelection( m_unitsOpt );
75 m_cbRemoveDNP->SetValue( m_noDNP );
78 m_VRML_RefUnitChoice->SetSelection( m_RefUnits );
79 wxString tmpStr;
80 tmpStr << m_XRef;
81 m_VRML_Xref->SetValue( tmpStr );
82 tmpStr = wxT( "" );
83 tmpStr << m_YRef;
84 m_VRML_Yref->SetValue( tmpStr );
85
87
88 // Now all widgets have the size fixed, call FinishDialogSettings
90}
91
92
94{
99
101 {
102 cfg->m_ExportVrml.units = m_unitsOpt;
103 cfg->m_ExportVrml.no_unspecified = m_noUnspecified;
104 cfg->m_ExportVrml.no_dnp = m_noDNP;
105 cfg->m_ExportVrml.copy_3d_models = m_copy3DFilesOpt;
106 cfg->m_ExportVrml.use_relative_paths = m_useRelativePathsOpt;
107 cfg->m_ExportVrml.ref_units = m_VRML_RefUnitChoice->GetSelection();
108 cfg->m_ExportVrml.origin_mode = m_rbCoordOrigin->GetSelection();
109
110 double val = 0.0;
111 m_VRML_Xref->GetValue().ToDouble( &val );
112 cfg->m_ExportVrml.ref_x = val;
113
114 m_VRML_Yref->GetValue().ToDouble( &val );
115 cfg->m_ExportVrml.ref_y = val;
116 }
117}
118
119
121{
122 wxFileName fn = m_filePicker->GetPath();
123
124 if( fn.Exists() )
125 {
126 if( wxMessageBox( _( "Are you sure you want to overwrite the existing file?" ),
127 _( "Warning" ), wxYES_NO | wxCENTER | wxICON_QUESTION, this ) == wxNO )
128 return false;
129 }
130
131 return true;
132}
133
134
136{
138}
139
140
142{
144}
145
146
148{
149 // These variables are static to keep info during the session.
150 static wxString subDirFor3Dshapes;
151
153
154 // Build default output file name
155 wxString path = m_frame->GetLastPath( LAST_PATH_VRML );
156
157 if( path.IsEmpty() )
158 {
159 wxFileName brdFile = board->GetFileName();
160 brdFile.SetExt( wxT( "wrl" ) );
161 path = brdFile.GetFullPath();
162 }
163
164 if( subDirFor3Dshapes.IsEmpty() )
165 subDirFor3Dshapes = wxT( "shapes3D" );
166
167 // The general VRML scale factor
168 // Assuming the VRML default unit is the mm
169 // this is the mm to VRML scaling factor for mm, 0.1 inch, and inch
170 double scaleList[4] = { 1.0, 0.001, 10.0/25.4, 1.0/25.4 };
171
173 dlg.FilePicker()->SetPath( path );
174 dlg.SetSubdir( subDirFor3Dshapes );
175
176 if( dlg.ShowModal() != wxID_OK )
177 return 0;
178
179 double aXRef = dlg.GetXRef();
180 double aYRef = dlg.GetYRef();
181
182 if( dlg.GetRefUnitsChoice() == 1 )
183 {
184 // selected reference unit is in inches
185 aXRef *= 25.4;
186 aYRef *= 25.4;
187 }
188
189 if( dlg.GetOriginChoice() == 1 )
190 {
191 // Origin = board center:
192 BOX2I bbox = board->ComputeBoundingBox( true );
193 aXRef = pcbIUScale.IUTomm( bbox.GetCenter().x );
194 aYRef = pcbIUScale.IUTomm( bbox.GetCenter().y );
195 }
196
197 double scale = scaleList[dlg.GetUnits()]; // final scale export
198 bool includeUnspecified = !dlg.GetNoUnspecifiedOption();
199 bool includeDNP = !dlg.GetNoDNPOption();
200 bool export3DFiles = dlg.GetCopyFilesOption();
201 bool useRelativePaths = dlg.GetUseRelativePathsOption();
202
203 path = dlg.FilePicker()->GetPath();
205 wxFileName modelPath = path;
206
207 wxBusyCursor dummy;
208
209 subDirFor3Dshapes = dlg.GetSubdir3Dshapes();
210 modelPath.AppendDir( subDirFor3Dshapes );
211
212 if( export3DFiles && !modelPath.DirExists() )
213 {
214 if( !modelPath.Mkdir() )
215 {
216 DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create folder '%s'." ),
217 modelPath.GetPath() ) );
218 return 0;
219 }
220 }
221
222 if( !m_frame->ExportVRML_File( path, scale, includeUnspecified, includeDNP, export3DFiles,
223 useRelativePaths, modelPath.GetPath(), aXRef, aYRef ) )
224 {
225 DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create file '%s'." ),
226 path ) );
227 }
228
229 return 0;
230}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
int ExportVRML(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:297
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1763
const wxString & GetFileName() const
Definition: board.h:334
constexpr const Vec GetCenter() const
Definition: box2.h:230
Class DIALOG_EXPORT_VRML_BASE.
wxFilePickerCtrl * FilePicker()
DIALOG_EXPORT_VRML(PCB_EDIT_FRAME *aEditFrame)
PCB_EDIT_FRAME * m_editFrame
wxString GetSubdir3Dshapes()
bool TransferDataFromWindow() override
void SetSubdir(const wxString &aDir)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
PCBNEW_SETTINGS * GetPcbNewSettings() const
BOARD * GetBoard() const
The main frame for Pcbnew.
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
bool ExportVRML_File(const wxString &aFullFileName, double aMMtoWRMLunit, bool aIncludeUnspecified, bool aIncludeDNP, bool aExport3DFiles, bool aUseRelativePaths, const wxString &a3D_Subdir, double aXRef, double aYRef)
Create the file(s) exporting current BOARD to a VRML file.
BOARD * board() const
Generic, UI-independent tool event.
Definition: tool_event.h:168
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:194
This file is part of the common library.
#define _(s)
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue to a double.
Definition: eda_units.cpp:559
@ LAST_PATH_VRML
Definition: project_file.h:55
const int scale
std::vector< FAB_LAYER_COLOR > dummy
constexpr double IUTomm(int iu) const
Definition: base_units.h:90