From 4025603a1f383b5a8688f3547e014669930d9c2c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 6 Jul 2021 21:22:06 +0100 Subject: [PATCH] Formatting. --- utils/kicad2step/kicad2step.cpp | 20 ++++--- utils/kicad2step/pcb/oce_utils.cpp | 95 ++++++++++++++++-------------- utils/kicad2step/pcb/oce_utils.h | 12 ++-- 3 files changed, 72 insertions(+), 55 deletions(-) diff --git a/utils/kicad2step/kicad2step.cpp b/utils/kicad2step/kicad2step.cpp index ef63e524d3..1bd44f14f4 100644 --- a/utils/kicad2step/kicad2step.cpp +++ b/utils/kicad2step/kicad2step.cpp @@ -2,7 +2,7 @@ * This program source code file is part of kicad2mcad * * Copyright (C) 2016 Cirilo Bernardo - * Copyright (C) 2016-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,8 +42,12 @@ class KICAD2STEP_FRAME; class KICAD2MCAD_APP : public wxApp { public: - KICAD2MCAD_APP() : wxApp(), m_frame( nullptr ), m_Panel( nullptr ) + KICAD2MCAD_APP() : + wxApp(), + m_frame( nullptr ), + m_Panel( nullptr ) {} + virtual bool OnInit() override; virtual int OnRun() override; virtual void OnInitCmdLine(wxCmdLineParser& parser) override; @@ -167,14 +171,14 @@ void KICAD2MCAD_APP::OnInitCmdLine( wxCmdLineParser& parser ) } -PANEL_KICAD2STEP::PANEL_KICAD2STEP( wxWindow* parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, long style ): - wxPanel( parent, id, pos, size, style ) +PANEL_KICAD2STEP::PANEL_KICAD2STEP( wxWindow* parent, wxWindowID id, const wxPoint& pos, + const wxSize& size, long style ) : + wxPanel( parent, id, pos, size, style ) { wxBoxSizer* bSizer = new wxBoxSizer( wxVERTICAL ); - m_tcMessages = new wxTextCtrl( this, wxID_ANY, wxEmptyString, - wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY ); + m_tcMessages = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, + wxTE_MULTILINE|wxTE_READONLY ); bSizer->Add( m_tcMessages, 1, wxALL|wxEXPAND, 5 ); SetSizer( bSizer ); @@ -451,8 +455,10 @@ int PANEL_KICAD2STEP::RunConverter() if( !errs.IsEmpty() ) // Any troubles? { if( !success ) + { msg = "Unable to create STEP file.\n" "Check that the board has a valid outline and models."; + } else { msg = "STEP file has been created, but there are warnings."; diff --git a/utils/kicad2step/pcb/oce_utils.cpp b/utils/kicad2step/pcb/oce_utils.cpp index 60e4fa81c3..7b3d6780de 100644 --- a/utils/kicad2step/pcb/oce_utils.cpp +++ b/utils/kicad2step/pcb/oce_utils.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Cirilo Bernardo + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -602,24 +603,24 @@ bool PCBMODEL::AddPadHole( const KICADPAD* aPad ) // add a component at the given position and orientation bool PCBMODEL::AddComponent( const std::string& aFileName, const std::string& aRefDes, - bool aBottom, DOUBLET aPosition, double aRotation, - TRIPLET aOffset, TRIPLET aOrientation, TRIPLET aScale, - bool aSubstituteModels ) + bool aBottom, DOUBLET aPosition, double aRotation, + TRIPLET aOffset, TRIPLET aOrientation, TRIPLET aScale, + bool aSubstituteModels ) { if( aFileName.empty() ) { - ReportMessage( wxString::Format( "no model defined for component %s\n", aRefDes ) ); + ReportMessage( wxString::Format( "No model defined for component %s.\n", aRefDes ) ); return false; } - ReportMessage( wxString::Format( "add component %s\n", aRefDes ) ); + ReportMessage( wxString::Format( "Add component %s.\n", aRefDes ) ); // first retrieve a label TDF_Label lmodel; if( !getModelLabel( aFileName, aScale, lmodel, aSubstituteModels ) ) { - ReportMessage( wxString::Format( "no model for filename %s\n", aFileName ) ); + ReportMessage( wxString::Format( "No model for filename '%s'.\n", aFileName ) ); return false; } @@ -628,7 +629,7 @@ bool PCBMODEL::AddComponent( const std::string& aFileName, const std::string& aR if( !getModelLocation( aBottom, aPosition, aRotation, aOffset, aOrientation, toploc ) ) { - ReportMessage( wxString::Format( "no location data for filename %s\n", aFileName ) ); + ReportMessage( wxString::Format( "No location data for filename '%s'.\n", aFileName ) ); return false; } @@ -637,7 +638,8 @@ bool PCBMODEL::AddComponent( const std::string& aFileName, const std::string& aR if( llabel.IsNull() ) { - ReportMessage( wxString::Format( "could not add component with filename %s\n", aFileName ) ); + ReportMessage( wxString::Format( "Could not add component with filename '%s'.\n", + aFileName ) ); return false; } @@ -684,7 +686,7 @@ bool PCBMODEL::CreatePCB() if( m_curves.empty() || m_mincurve == m_curves.end() ) { m_hasPCB = true; - ReportMessage( "no valid board outline\n" ); + ReportMessage( "No valid board outline.\n" ); return false; } @@ -695,7 +697,7 @@ bool PCBMODEL::CreatePCB() oln.AddSegment( *m_mincurve ); m_curves.erase( m_mincurve ); - ReportMessage( wxString::Format( "Build board outline (%d items)\n", + ReportMessage( wxString::Format( "Build board outline (%d items).\n", (int)m_curves.size() ) ); while( !m_curves.empty() ) @@ -706,7 +708,7 @@ bool PCBMODEL::CreatePCB() { if( !oln.MakeShape( board, m_thickness ) ) { - ReportMessage( "could not create board extrusion\n" ); + ReportMessage( "Could not create board extrusion.\n" ); return false; } } @@ -720,7 +722,7 @@ bool PCBMODEL::CreatePCB() } else { - ReportMessage( "could not create board cutout\n" ); + ReportMessage( "Could not create board cutout.\n" ); } } @@ -753,7 +755,7 @@ bool PCBMODEL::CreatePCB() if( !added && !oln.m_curves.empty() ) { wxString msg; - msg.Printf( "could not close outline (dropping outline data with %d segments)\n", + msg.Printf( "Could not close outline (dropping outline data with %d segments).\n", static_cast( oln.m_curves.size() ) ); for( const auto& c : oln.m_curves ) @@ -776,7 +778,7 @@ bool PCBMODEL::CreatePCB() { if( !oln.MakeShape( board, m_thickness ) ) { - ReportMessage( "could not create board extrusion\n" ); + ReportMessage( "Could not create board extrusion.\n" ); return false; } } @@ -790,20 +792,22 @@ bool PCBMODEL::CreatePCB() } else { - ReportMessage( "could not create board cutout\n" ); + ReportMessage( "Could not create board cutout.\n" ); } } } else { - ReportMessage( "* could not create closed board outlines *\n" ); + ReportMessage( "Could not create closed board outlines.\n" ); return false; } // subtract cutouts (if any) if( m_cutouts.size() ) - ReportMessage( wxString::Format( "Build board cutouts and holes (%d holes)\n", - (int)m_cutouts.size() ) ); + { + ReportMessage( wxString::Format( "Build board cutouts and holes (%d holes).\n", + (int)m_cutouts.size() ) ); + } #if 0 // First version for holes removing: very slow when having many (> 300) holes // Substract holes (cutouts) can be time consuming, so display activity @@ -847,7 +851,7 @@ bool PCBMODEL::CreatePCB() #endif // push the board to the data structure - ReportMessage( "\nGenerate board full shape\n" ); + ReportMessage( "\nGenerate board full shape.\n" ); m_pcb_label = m_assy->AddComponent( m_assy_label, board ); if( m_pcb_label.IsNull() ) @@ -881,8 +885,8 @@ bool PCBMODEL::WriteIGES( const wxString& aFileName ) { if( m_pcb_label.IsNull() ) { - ReportMessage( wxString::Format( - "No valid PCB assembly; cannot create output file %s\n", aFileName ) ); + ReportMessage( wxString::Format( "No valid PCB assembly; cannot create output file '%s'.\n", + aFileName ) ); return false; } @@ -911,7 +915,8 @@ bool PCBMODEL::WriteSTEP( const wxString& aFileName ) { if( m_pcb_label.IsNull() ) { - ReportMessage( wxString::Format( "No valid PCB assembly; cannot create output file %s\n", aFileName ) ); + ReportMessage( wxString::Format( "No valid PCB assembly; cannot create output file '%s'.\n", + aFileName ) ); return false; } wxFileName fn( aFileName ); @@ -925,10 +930,8 @@ bool PCBMODEL::WriteSTEP( const wxString& aFileName ) // but in the meantime, defaulting to the basename of the output // target is still better than "open cascade step translter v..." // UTF8 should be ok from ISO 10303-21:2016, but... older stuff? use boring ascii - if( !Interface_Static::SetCVal("write.step.product.name", fn.GetName().ToAscii()) ) { - wxString s("Failed to set step product name, but will attempt to continue"); - ReportMessage(s); - } + if( !Interface_Static::SetCVal( "write.step.product.name", fn.GetName().ToAscii() ) ) + ReportMessage( "Failed to set step product name, but will attempt to continue." ); if( Standard_False == writer.Transfer( m_doc, STEPControl_AsIs ) ) return false; @@ -961,8 +964,9 @@ bool PCBMODEL::WriteSTEP( const wxString& aFileName ) { if( !wxRenameFile( tmpfname, fn.GetFullName(), true ) ) { - ReportMessage( wxString::Format( "Cannot rename temporary file '%s' to '%s'\n", - tmpfname, fn.GetFullName() ) ); + ReportMessage( wxString::Format( "Cannot rename temporary file '%s' to '%s'.\n", + tmpfname, + fn.GetFullName() ) ); success = false; } } @@ -973,7 +977,8 @@ bool PCBMODEL::WriteSTEP( const wxString& aFileName ) } -bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_Label& aLabel, bool aSubstituteModels ) +bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_Label& aLabel, + bool aSubstituteModels ) { std::string model_key = aFileName + "_" + std::to_string( aScale.x ) + "_" + std::to_string( aScale.y ) + "_" + std::to_string( aScale.z ); @@ -998,7 +1003,7 @@ bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_ case FMT_IGES: if( !readIGES( doc, aFileName.c_str() ) ) { - ReportMessage( wxString::Format( "readIGES() failed on filename %s\n", + ReportMessage( wxString::Format( "readIGES() failed on filename '%s'.\n", aFileName ) ); return false; } @@ -1007,7 +1012,7 @@ bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_ case FMT_STEP: if( !readSTEP( doc, aFileName.c_str() ) ) { - ReportMessage( wxString::Format( "readSTEP() failed on filename %s\n", + ReportMessage( wxString::Format( "readSTEP() failed on filename '%s'.\n", aFileName ) ); return false; } @@ -1025,7 +1030,7 @@ bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_ if( size == wxInvalidOffset ) { - ReportMessage( wxString::Format( "readSTEP() failed on filename %s\n", + ReportMessage( wxString::Format( "readSTEP() failed on filename '%s'.\n", aFileName ) ); return false; } @@ -1131,11 +1136,12 @@ bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_ std::string altFileName = altFile.GetFullPath().ToStdString(); // When substituting a STEP/IGS file for VRML, do not apply the VRML scaling - // to the new STEP model. This process of auto-substitution is janky as all heck - // so let's not mix up un-displayed scale factors with potentially mis-matched - // files. And hope that the user doesn't have multiples files named "model.wrl" and - // "model.stp" referring to different parts. - // TODO: Fix model handling in v7. Default models should only be STP. Have option to override this in DISPLAY + // to the new STEP model. This process of auto-substitution is janky as all + // heck so let's not mix up un-displayed scale factors with potentially + // mis-matched files. And hope that the user doesn't have multiples files + // named "model.wrl" and "model.stp" referring to different parts. + // TODO: Fix model handling in v7. Default models should only be STP. + // Have option to override this in DISPLAY. if( getModelLabel( altFileName, TRIPLET( 1.0, 1.0, 1.0 ), aLabel, false ) ) { return true; @@ -1156,7 +1162,8 @@ bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_ if( aLabel.IsNull() ) { - ReportMessage( wxString::Format( "could not transfer model data from file %s\n", aFileName ) ); + ReportMessage( wxString::Format( "Could not transfer model data from file '%s'.\n", + aFileName ) ); return false; } @@ -1173,8 +1180,8 @@ bool PCBMODEL::getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_ } -bool PCBMODEL::getModelLocation( bool aBottom, DOUBLET aPosition, double aRotation, - TRIPLET aOffset, TRIPLET aOrientation, TopLoc_Location& aLocation ) +bool PCBMODEL::getModelLocation( bool aBottom, DOUBLET aPosition, double aRotation, TRIPLET aOffset, + TRIPLET aOrientation, TopLoc_Location& aLocation ) { // Order of operations: // a. aOrientation is applied -Z*-Y*-X @@ -1307,7 +1314,7 @@ bool PCBMODEL::readSTEP( Handle(TDocStd_Document)& doc, const char* fname ) TDF_Label PCBMODEL::transferModel( Handle( TDocStd_Document )& source, - Handle( TDocStd_Document )& dest, TRIPLET aScale ) + Handle( TDocStd_Document )& dest, TRIPLET aScale ) { // transfer data from Source into a top level component of Dest @@ -1618,8 +1625,10 @@ bool OUTLINE::addEdge( BRepBuilderAPI_MakeWire* aWire, KICADCURVE& aCurve, DOUBL break; case CURVE_CIRCLE: - edge = BRepBuilderAPI_MakeEdge( gp_Circ( gp_Ax2( gp_Pnt( aCurve.m_start.x, aCurve.m_start.y, 0.0 ), - gp_Dir( 0.0, 0.0, 1.0 ) ), aCurve.m_radius ) ); + edge = BRepBuilderAPI_MakeEdge( gp_Circ( gp_Ax2( gp_Pnt( aCurve.m_start.x, + aCurve.m_start.y, 0.0 ), + gp_Dir( 0.0, 0.0, 1.0 ) ), + aCurve.m_radius ) ); break; case CURVE_BEZIER: diff --git a/utils/kicad2step/pcb/oce_utils.h b/utils/kicad2step/pcb/oce_utils.h index 38da2a2efd..5d4bb7444e 100644 --- a/utils/kicad2step/pcb/oce_utils.h +++ b/utils/kicad2step/pcb/oce_utils.h @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Cirilo Bernardo + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -94,12 +95,13 @@ class PCBMODEL double m_thickness; // PCB thickness, mm double m_minx; // minimum X value in curves (leftmost curve feature) double m_minDistance2; // minimum squared distance between items (mm) - std::list< KICADCURVE >::iterator m_mincurve; // iterator to the leftmost curve + std::list::iterator m_mincurve; // iterator to the leftmost curve - std::list< KICADCURVE > m_curves; - std::vector< TopoDS_Shape > m_cutouts; + std::list m_curves; + std::vector m_cutouts; - bool getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_Label& aLabel, bool aSubstituteModels ); + bool getModelLabel( const std::string& aFileName, TRIPLET aScale, TDF_Label& aLabel, + bool aSubstituteModels ); bool getModelLocation( bool aBottom, DOUBLET aPosition, double aRotation, TRIPLET aOffset, TRIPLET aOrientation, TopLoc_Location& aLocation ); @@ -108,7 +110,7 @@ class PCBMODEL bool readSTEP( Handle( TDocStd_Document )& m_doc, const char* fname ); TDF_Label transferModel( Handle( TDocStd_Document )& source, - Handle( TDocStd_Document )& dest, TRIPLET aScale ); + Handle( TDocStd_Document )& dest, TRIPLET aScale ); public: PCBMODEL();