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 */
25
26#include <wx/dir.h>
27
28#include <base_units.h>
29#include <board.h>
30#include <confirm.h>
31#include <kiface_base.h>
32#include <pcb_edit_frame.h>
33#include <pcbnew_settings.h>
35#include <project/project_file.h> // LAST_PATH_TYPE
36#include <wx/msgdlg.h>
37
38#include <dialog_export_vrml.h>
39
40
42 DIALOG_EXPORT_VRML_BASE( aEditFrame ),
43 m_xOrigin( aEditFrame, m_xLabel, m_VRML_Xref, m_xUnits ),
44 m_yOrigin( aEditFrame, m_yLabel, m_VRML_Yref, m_yUnits )
45{
46 m_filePicker->SetFocus();
47
50
52
53 // Now all widgets have the size fixed, call FinishDialogSettings
55}
56
57
59{
60 wxFileName fn = m_filePicker->GetPath();
61
62 if( fn.Exists() )
63 {
64 if( wxMessageBox( _( "Are you sure you want to overwrite the existing file?" ), _( "Warning" ),
65 wxYES_NO | wxCENTER | wxICON_QUESTION, this )
66 == wxNO )
67 {
68 return false;
69 }
70 }
71
72 return true;
73}
74
75
77{
78 BOARD* board = m_frame->GetBoard();
79
80 // Build default output file name
81 wxString path = m_frame->GetLastPath( LAST_PATH_VRML );
82
83 if( path.IsEmpty() )
84 {
85 wxFileName brdFile = board->GetFileName();
86 brdFile.SetExt( wxT( "wrl" ) );
87 path = brdFile.GetFullPath();
88 }
89
91 dlg.FilePicker()->SetPath( path );
92
93 if( dlg.ShowModal() != wxID_OK )
94 return 0;
95
96 double aXRef;
97 double aYRef;
98
99 if( dlg.GetSetUserDefinedOrigin() )
100 {
101 aXRef = dlg.GetXRefMM();
102 aYRef = dlg.GetYRefMM();
103 }
104 else
105 {
106 // Origin = board center:
107 BOX2I bbox = board->ComputeBoundingBox( true );
108 aXRef = pcbIUScale.IUTomm( bbox.GetCenter().x );
109 aYRef = pcbIUScale.IUTomm( bbox.GetCenter().y );
110 }
111
112 path = dlg.FilePicker()->GetPath();
113 m_frame->SetLastPath( LAST_PATH_VRML, path );
114 wxFileName modelPath = path;
115
116 wxBusyCursor dummy;
117
118 modelPath.AppendDir( dlg.GetSubdir3Dshapes() );
119
120 if( dlg.GetCopyFilesOption() && !modelPath.DirExists() )
121 {
122 if( !modelPath.Mkdir() )
123 {
124 DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create folder '%s'." ),
125 modelPath.GetPath() ) );
126 return 0;
127 }
128 }
129
130 if( !m_frame->ExportVRML_File( path,
131 dlg.GetScale(),
133 !dlg.GetNoDNPOption(),
134 dlg.GetCopyFilesOption(),
136 modelPath.GetPath(),
137 aXRef, aYRef ) )
138 {
139 DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create file '%s'." ), path ) );
140 }
141
142 return 0;
143}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
int ExportVRML(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
constexpr const Vec GetCenter() const
Definition box2.h:230
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:171
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:202
This file is part of the common library.
#define _(s)
@ LAST_PATH_VRML
std::vector< FAB_LAYER_COLOR > dummy
std::string path