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
49
50 // Now all widgets have the size fixed, call FinishDialogSettings
52}
53
54
56{
57 wxFileName fn = m_filePicker->GetPath();
58
59 if( fn.Exists() )
60 {
61 if( wxMessageBox( _( "Are you sure you want to overwrite the existing file?" ), _( "Warning" ),
62 wxYES_NO | wxCENTER | wxICON_QUESTION, this )
63 == wxNO )
64 {
65 return false;
66 }
67 }
68
69 return true;
70}
71
72
74{
75 BOARD* board = m_frame->GetBoard();
76
77 // Build default output file name
78 wxString path = m_frame->GetLastPath( LAST_PATH_VRML );
79
80 if( path.IsEmpty() )
81 {
82 wxFileName brdFile = board->GetFileName();
83 brdFile.SetExt( wxT( "wrl" ) );
84 path = brdFile.GetFullPath();
85 }
86
88 dlg.FilePicker()->SetPath( path );
89
90 if( dlg.ShowModal() != wxID_OK )
91 return 0;
92
93 double aXRef;
94 double aYRef;
95
96 if( dlg.GetSetUserDefinedOrigin() )
97 {
98 aXRef = dlg.GetXRefMM();
99 aYRef = dlg.GetYRefMM();
100 }
101 else
102 {
103 // Origin = board center:
104 BOX2I bbox = board->ComputeBoundingBox( true );
105 aXRef = pcbIUScale.IUTomm( bbox.GetCenter().x );
106 aYRef = pcbIUScale.IUTomm( bbox.GetCenter().y );
107 }
108
109 path = dlg.FilePicker()->GetPath();
110 m_frame->SetLastPath( LAST_PATH_VRML, path );
111 wxFileName modelPath = path;
112
113 wxBusyCursor dummy;
114
115 modelPath.AppendDir( dlg.GetSubdir3Dshapes() );
116
117 if( dlg.GetCopyFilesOption() && !modelPath.DirExists() )
118 {
119 if( !modelPath.Mkdir() )
120 {
121 DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create folder '%s'." ),
122 modelPath.GetPath() ) );
123 return 0;
124 }
125 }
126
127 if( !m_frame->ExportVRML_File( path,
128 dlg.GetScale(),
130 !dlg.GetNoDNPOption(),
131 dlg.GetCopyFilesOption(),
133 modelPath.GetPath(),
134 aXRef, aYRef ) )
135 {
136 DisplayErrorMessage( m_frame, wxString::Format( _( "Failed to create file '%s'." ), path ) );
137 }
138
139 return 0;
140}
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:317
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:194
This file is part of the common library.
#define _(s)
@ LAST_PATH_VRML
std::vector< FAB_LAYER_COLOR > dummy