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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <wx/dir.h>
23
24#include <base_units.h>
25#include <board.h>
26#include <confirm.h>
27#include <kiface_base.h>
28#include <pcb_edit_frame.h>
29#include <pcbnew_settings.h>
31#include <project/project_file.h> // LAST_PATH_TYPE
32#include <wx/msgdlg.h>
33
34#include <dialog_export_vrml.h>
35
36
38 DIALOG_EXPORT_VRML_BASE( aEditFrame ),
39 m_xOrigin( aEditFrame, m_xLabel, m_VRML_Xref, m_xUnits ),
40 m_yOrigin( aEditFrame, m_yLabel, m_VRML_Yref, m_yUnits )
41{
42 m_filePicker->SetFocus();
43
46
48
49 // Now all widgets have the size fixed, call FinishDialogSettings
51}
52
53
55{
56 wxFileName fn = m_filePicker->GetPath();
57
58 if( fn.Exists() )
59 {
60 if( wxMessageBox( _( "Are you sure you want to overwrite the existing file?" ), _( "Warning" ),
61 wxYES_NO | wxCENTER | wxICON_QUESTION, this )
62 == wxNO )
63 {
64 return false;
65 }
66 }
67
68 return true;
69}
70
71
73{
74 BOARD* board = m_frame->GetBoard();
75
76 // Build default output file name
77 wxString path = m_frame->GetLastPath( LAST_PATH_VRML );
78
79 if( path.IsEmpty() )
80 {
81 wxFileName brdFile = board->GetFileName();
82 brdFile.SetExt( wxT( "wrl" ) );
83 path = brdFile.GetFullPath();
84 }
85
87 dlg.FilePicker()->SetPath( path );
88
89 if( dlg.ShowModal() != wxID_OK )
90 return 0;
91
92 double aXRef;
93 double aYRef;
94
95 if( dlg.GetSetUserDefinedOrigin() )
96 {
97 aXRef = dlg.GetXRefMM();
98 aYRef = dlg.GetYRefMM();
99 }
100 else
101 {
102 // Origin = board center:
103 BOX2I bbox = board->ComputeBoundingBox( true, true );
104 aXRef = pcbIUScale.IUTomm( bbox.GetCenter().x );
105 aYRef = pcbIUScale.IUTomm( bbox.GetCenter().y );
106 }
107
108 path = dlg.FilePicker()->GetPath();
109 m_frame->SetLastPath( LAST_PATH_VRML, path );
110 wxFileName modelPath = path;
111
112 wxBusyCursor dummy;
113
114 modelPath.AppendDir( dlg.GetSubdir3Dshapes() );
115
116 if( dlg.GetCopyFilesOption() && !modelPath.DirExists() )
117 {
118 if( !modelPath.Mkdir() )
119 {
120 DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create folder '%s'." ),
121 modelPath.GetPath() ) );
122 return 0;
123 }
124 }
125
126 if( !m_frame->ExportVRML_File( path,
127 dlg.GetScale(),
129 !dlg.GetNoDNPOption(),
130 dlg.GetCopyFilesOption(),
132 modelPath.GetPath(),
133 aXRef, aYRef ) )
134 {
135 DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create file '%s'." ), path ) );
136 }
137
138 return 0;
139}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
int ExportVRML(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
constexpr const Vec GetCenter() const
Definition box2.h:226
DIALOG_EXPORT_VRML_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("VRML Export Options"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxFilePickerCtrl * FilePicker()
DIALOG_EXPORT_VRML(PCB_EDIT_FRAME *aEditFrame)
bool TransferDataFromWindow() override
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
The main frame for Pcbnew.
BOARD * board() const
Generic, UI-independent tool event.
Definition tool_event.h:167
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define _(s)
@ LAST_PATH_VRML
std::vector< FAB_LAYER_COLOR > dummy
std::string path