KiCad PCB EDA Suite
fabmaster_plugin.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) 2020 BeagleBoard Foundation
5  * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.TXT for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU 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, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-3.0.html
20  * or you may search the http://www.gnu.org website for the version 3 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include "fabmaster_plugin.h"
31 #include <board.h>
32 #include <progress_reporter.h>
33 #include <common.h>
34 #include <macros.h>
35 
36 
38 {
39  m_board = nullptr;
40  m_props = nullptr;
41 }
42 
43 
45 {
46 }
47 
48 
49 const wxString FABMASTER_PLUGIN::PluginName() const
50 {
51  return wxT( "Fabmaster" );
52 }
53 
54 
55 const wxString FABMASTER_PLUGIN::GetFileExtension() const
56 {
57  return wxT( "txt" );
58 }
59 
60 
61 BOARD* FABMASTER_PLUGIN::Load( const wxString &aFileName, BOARD *aAppendToMe,
62  const PROPERTIES *aProperties, PROJECT *aProject,
63  PROGRESS_REPORTER* aProgressReporter )
64 {
65  m_props = aProperties;
66 
67  m_board = aAppendToMe ? aAppendToMe : new BOARD();
68 
69  // Give the filename to the board if it's new
70  if( !aAppendToMe )
71  m_board->SetFileName( aFileName );
72 
73  if( aProgressReporter )
74  {
75  aProgressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
76 
77  if( !aProgressReporter->KeepRefreshing() )
78  THROW_IO_ERROR( ( "Open cancelled by user." ) );
79  }
80 
81  if( !m_fabmaster.Read( aFileName.ToStdString() ) )
82  {
83  std::string readerr;
84 
85  readerr = _( "Could not read file " ) + aFileName.ToStdString();
86  THROW_IO_ERROR( readerr );
87  }
88 
90  m_fabmaster.LoadBoard( m_board, aProgressReporter );
91 
92  return m_board;
93 }
bool Read(const std::string &aFile)
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
Container for project specific data.
Definition: project.h:62
A progress reporter interface for use in multi-threaded environments.
const PROPERTIES * m_props
bool LoadBoard(BOARD *aBoard, PROGRESS_REPORTER *aProgressReporter)
A name/value tuple with unique names and optional values.
Definition: properties.h:33
This file contains miscellaneous commonly used macros and functions.
const wxString GetFileExtension() const override
Returns the file extension for the PLUGIN.
#define _(s)
void SetFileName(const wxString &aFileName)
Definition: board.h:227
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const wxString PluginName() const override
Return a brief hard coded name for this PLUGIN.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:191
The common library.
BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr) override
Load information from some input file format that this PLUGIN implementation knows about into either ...
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
Pcbnew PLUGIN for Fabmaster (Allegro) ASCII format.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38