diff --git a/common/hotkeys_basic.cpp b/common/hotkeys_basic.cpp index 46a9ac331e..875d7bea04 100644 --- a/common/hotkeys_basic.cpp +++ b/common/hotkeys_basic.cpp @@ -161,15 +161,6 @@ static struct hotkey_name_descr hotkeyNameList[] = #define MODIFIER_SHIFT wxT( "Shift+" ) -/** - * Return the key name from the key code. - * - * Only some wxWidgets key values are handled for function key ( see hotkeyNameList[] ) - * - * @param aKeycode key code (ASCII value, or wxWidgets value for function keys). - * @param aIsFound a pointer to a bool to return true if found, or false. an be nullptr default). - * @return the key name in a wxString. - */ wxString KeyNameFromKeyCode( int aKeycode, bool* aIsFound ) { wxString keyname, modifier, fullkeyname; @@ -229,12 +220,6 @@ wxString KeyNameFromKeyCode( int aKeycode, bool* aIsFound ) } -/** - * @param aText the base text on which to append the hotkey. - * @param aHotKey the hotkey keycode. - * @param aStyle IS_HOTKEY to add (shortcuts in menus, same as hotkeys). - * IS_COMMENT to add <(keyname)> mainly in tool tips. - */ wxString AddHotkeyName( const wxString& aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle ) { wxString msg = aText; @@ -273,9 +258,6 @@ wxString AddHotkeyName( const wxString& aText, int aHotKey, HOTKEY_ACTION_TYPE a } -/** - * Return the key code from its user-friendly key name (ie: "Ctrl+M"). - */ int KeyCodeFromKeyName( const wxString& keyname ) { int ii, keycode = KEY_NON_FOUND; @@ -339,9 +321,6 @@ int KeyCodeFromKeyName( const wxString& keyname ) } -/* - * Displays the hotkeys registered with the given tool manager. - */ void DisplayHotkeyList( EDA_BASE_FRAME* aParent ) { DIALOG_LIST_HOTKEYS dlg( aParent ); @@ -399,11 +378,13 @@ void ReadHotKeyConfigIntoActions( const wxString& aFileName, std::vectorGetName() ) != hotkeys.end() ) { std::pair keys = hotkeys[action->GetName()]; action->SetHotKey( keys.first, keys.second ); } + } } @@ -420,7 +401,8 @@ int WriteHotKeyConfig( const std::vector& aActions ) // Overlay the current app's hotkey definitions onto the map for( const TOOL_ACTION* action : aActions ) - hotkeys[ action->GetName() ] = std::pair( action->GetHotKey(), action->GetHotKeyAlt() ); + hotkeys[ action->GetName() ] = std::pair( action->GetHotKey(), + action->GetHotKeyAlt() ); // Write entire hotkey set wxFFileOutputStream outStream( fn.GetFullPath() ); diff --git a/common/http_lib/http_lib_connection.cpp b/common/http_lib/http_lib_connection.cpp index 924bec56e2..6cfe81d992 100644 --- a/common/http_lib/http_lib_connection.cpp +++ b/common/http_lib/http_lib_connection.cpp @@ -420,17 +420,7 @@ bool HTTP_LIB_CONNECTION::boolFromString( const std::any& aVal, bool aDefaultVal return aDefaultValue; } -/* -* HTTP response status codes indicate whether a specific HTTP request has been successfully completed. -* Responses are grouped in five classes: -* Informational responses (100 ? 199) -* Successful responses (200 ? 299) -* Redirection messages (300 ? 399) -* Client error responses (400 ? 499) -* Server error responses (500 ? 599) -* -* see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status -*/ + wxString HTTP_LIB_CONNECTION::httpErrorCodeDescription( uint16_t aHttpCode ) { auto codeDescription = @@ -450,7 +440,7 @@ wxString HTTP_LIB_CONNECTION::httpErrorCodeDescription( uint16_t aHttpCode ) case 205: return wxS( "Reset Content" ); case 206: return wxS( "Partial Content" ); case 207: return wxS( "Multi-Status" ); - case 208: return wxS( "Already Reporte" ); + case 208: return wxS( "Already Reported" ); case 226: return wxS( "IM Used" ); case 300: return wxS( "Multiple Choices" ); @@ -482,7 +472,7 @@ wxString HTTP_LIB_CONNECTION::httpErrorCodeDescription( uint16_t aHttpCode ) case 417: return wxS( "Expectation Failed" ); case 418: return wxS( "I'm a teapot" ); case 421: return wxS( "Misdirected Request" ); - case 422: return wxS( "Unprocessable Conten" ); + case 422: return wxS( "Unprocessable Content" ); case 423: return wxS( "Locked" ); case 424: return wxS( "Failed Dependency" ); case 425: return wxS( "Too Early (Experimental)" ); @@ -499,8 +489,8 @@ wxString HTTP_LIB_CONNECTION::httpErrorCodeDescription( uint16_t aHttpCode ) case 504: return wxS( "Gateway Timeout" ); case 505: return wxS( "HTTP Version Not Supported" ); case 506: return wxS( "Variant Also Negotiates" ); - case 507: return wxS( "Insufficient Storag" ); - case 508: return wxS( "Loop Detecte" ); + case 507: return wxS( "Insufficient Storage" ); + case 508: return wxS( "Loop Detected" ); case 510: return wxS( "Not Extended" ); case 511: return wxS( "Network Authentication Required" ); default: return wxS( "Unknown" ); diff --git a/common/import_gfx/dxf_import_plugin.cpp b/common/import_gfx/dxf_import_plugin.cpp index 6c4c3b2c62..aaf2de0f85 100644 --- a/common/import_gfx/dxf_import_plugin.cpp +++ b/common/import_gfx/dxf_import_plugin.cpp @@ -76,7 +76,7 @@ * 6. Blocks are virtual groups, blocks must be placed by a INSERT entity * 7. Blocks may be repeated multiple times * 8. There is no sane way to make text look perfect like the original CAD. - * DXF simply does mpt secifying text/font enough to make it portable. + * DXF simply does mpt specifying text/font enough to make it portable. * We however make do try to get it somewhat close/visually appealing. * 9. We silently drop the z coordinate on 3d polylines */ @@ -464,7 +464,8 @@ void DXF_IMPORT_PLUGIN::addVertex( const DL_VertexData& aData ) if( std::abs( m_curr_entity.m_BulgeVertex ) < MIN_BULGE ) insertLine( m_curr_entity.m_LastCoordinate, seg_end, lineWidth ); else - insertArc( m_curr_entity.m_LastCoordinate, seg_end, m_curr_entity.m_BulgeVertex, lineWidth ); + insertArc( m_curr_entity.m_LastCoordinate, seg_end, m_curr_entity.m_BulgeVertex, + lineWidth ); m_curr_entity.m_LastCoordinate = seg_end; m_curr_entity.m_BulgeVertex = vertex->bulge; @@ -691,9 +692,10 @@ void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData ) { MATRIX3x3D arbAxis = getArbitraryAxis( getExtrusion() ); VECTOR3D refPointCoords = ocsToWcs( arbAxis, VECTOR3D( aData.ipx, aData.ipy, aData.ipz ) ); - VECTOR3D secPointCoords = ocsToWcs( arbAxis, VECTOR3D( std::isnan( aData.apx ) ? 0 : aData.apx, - std::isnan( aData.apy ) ? 0 : aData.apy, - std::isnan( aData.apz ) ? 0 : aData.apz ) ); + VECTOR3D secPointCoords = + ocsToWcs( arbAxis, VECTOR3D( std::isnan( aData.apx ) ? 0 : aData.apx, + std::isnan( aData.apy ) ? 0 : aData.apy, + std::isnan( aData.apz ) ? 0 : aData.apz ) ); VECTOR2D refPoint( mapX( refPointCoords.x ), mapY( refPointCoords.y ) ); VECTOR2D secPoint( mapX( secPointCoords.x ), mapY( secPointCoords.y ) ); @@ -713,6 +715,7 @@ void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData ) DXF_IMPORT_STYLE* style = getImportStyle( aData.style.c_str() ); double textHeight = mapDim( aData.height ); + // The 0.9 factor gives a better height/width base ratio with our font double charWidth = textHeight * 0.9; @@ -720,12 +723,12 @@ void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData ) charWidth *= style->m_widthFactor; double textWidth = charWidth * text.length(); // Rough approximation - double textThickness = textHeight/8.0; // Use a reasonable line thickness for this text + double textThickness = textHeight / 8.0; // Use a reasonable line thickness for this text - VECTOR2D bottomLeft(0.0, 0.0); - VECTOR2D bottomRight(0.0, 0.0); - VECTOR2D topLeft(0.0, 0.0); - VECTOR2D topRight(0.0, 0.0); + VECTOR2D bottomLeft( 0.0, 0.0 ); + VECTOR2D bottomRight( 0.0, 0.0 ); + VECTOR2D topLeft( 0.0, 0.0 ); + VECTOR2D topRight( 0.0, 0.0 ); GR_TEXT_H_ALIGN_T hJustify = GR_TEXT_H_ALIGN_LEFT; GR_TEXT_V_ALIGN_T vJustify = GR_TEXT_V_ALIGN_BOTTOM; @@ -804,6 +807,7 @@ void DXF_IMPORT_PLUGIN::addText( const DL_TextData& aData ) // dxf_lib imports text angle in radians (although there are no comment about that. // So, for the moment, convert this angle to degrees double angle_degree = aData.angle * 180 / M_PI; + // We also need the angle in radians. so convert angle_degree to radians // regardless the aData.angle unit double angleInRads = angle_degree * M_PI / 180.0; @@ -957,6 +961,7 @@ void DXF_IMPORT_PLUGIN::addMText( const DL_MTextData& aData ) // dxf_lib imports text angle in radians (although there are no comment about that. // So, for the moment, convert this angle to degrees double angle_degree = aData.angle * 180/M_PI; + // We also need the angle in radians. so convert angle_degree to radians // regardless the aData.angle unit double angleInRads = angle_degree * M_PI / 180.0; @@ -1032,7 +1037,6 @@ double DXF_IMPORT_PLUGIN::getCurrentUnitScale() } - void DXF_IMPORT_PLUGIN::setVariableInt( const std::string& key, int value, int code ) { // Called for every int variable in the DXF file (e.g. "$INSUNITS"). @@ -1334,6 +1338,7 @@ wxString DXF_IMPORT_PLUGIN::toNativeString( const wxString& aData ) // degree: regexp.Compile( wxT( "%%[dD]" ) ); regexp.Replace( &res, wxChar( 0x00B0 ) ); + // plus/minus regexp.Compile( wxT( "%%[pP]" ) ); regexp.Replace( &res, wxChar( 0x00B1 ) ); @@ -1410,10 +1415,13 @@ void DXF_IMPORT_PLUGIN::insertArc( const VECTOR2D& aSegStart, const VECTOR2D& aS // reflect the Y values to put everything in a RHCS VECTOR2D sp( aSegStart.x, -aSegStart.y ); VECTOR2D ep( aSegEnd.x, -aSegEnd.y ); + // angle from end->start double offAng = atan2( ep.y - sp.y, ep.x - sp.x ); + // length of subtended segment = 1/2 distance between the 2 points - double d = 0.5 * sqrt( (sp.x - ep.x) * (sp.x - ep.x) + (sp.y - ep.y) * (sp.y - ep.y) ); + double d = 0.5 * sqrt( ( sp.x - ep.x ) * ( sp.x - ep.x ) + ( sp.y - ep.y ) * ( sp.y - ep.y ) ); + // midpoint of the subtended segment double xm = ( sp.x + ep.x ) * 0.5; double ym = ( sp.y + ep.y ) * 0.5; @@ -1477,11 +1485,11 @@ void DXF_IMPORT_PLUGIN::insertArc( const VECTOR2D& aSegStart, const VECTOR2D& aS void DXF_IMPORT_PLUGIN::insertSpline( double aWidth ) { #if 0 // Debug only - wxLogMessage("spl deg %d kn %d ctr %d fit %d", - m_curr_entity.m_SplineDegree, - m_curr_entity.m_SplineKnotsList.size(), - m_curr_entity.m_SplineControlPointList.size(), - m_curr_entity.m_SplineFitPointList.size() ); + wxLogMessage( "spl deg %d kn %d ctr %d fit %d", + m_curr_entity.m_SplineDegree, + m_curr_entity.m_SplineKnotsList.size(), + m_curr_entity.m_SplineControlPointList.size(), + m_curr_entity.m_SplineFitPointList.size() ); #endif unsigned imax = m_curr_entity.m_SplineControlPointList.size(); diff --git a/common/import_gfx/dxf_import_plugin.h b/common/import_gfx/dxf_import_plugin.h index c2d55682ba..ab84ee9c86 100644 --- a/common/import_gfx/dxf_import_plugin.h +++ b/common/import_gfx/dxf_import_plugin.h @@ -335,13 +335,13 @@ private: MATRIX3x3D getArbitraryAxis( DL_Extrusion* aData ); /** - * Converts a given world coordinate point to object coordinate using the given arbitrary + * Convert a given world coordinate point to object coordinate using the given arbitrary * axis vectors. */ VECTOR3D wcsToOcs( const MATRIX3x3D& arbitraryAxis, VECTOR3D point ); /** - * Converts a given object coordinate point to world coordinate using the given arbitrary + * Convert a given object coordinate point to world coordinate using the given arbitrary * axis vectors. */ VECTOR3D ocsToWcs( const MATRIX3x3D& arbitraryAxis, VECTOR3D point ); @@ -436,7 +436,7 @@ private: /** * Called for every spline. - * */ + */ virtual void addSpline( const DL_SplineData& aData ) override; /** @@ -459,6 +459,7 @@ private: { ReportMsg( _( "DXF construction lines not currently supported." ) ); } + virtual void addRay( const DL_RayData& ) override { ReportMsg( _( "DXF construction lines not currently supported." ) ); @@ -473,30 +474,37 @@ private: { ReportMsg( _( "DXF dimensions not currently supported." ) ); } + virtual void addDimLinear( const DL_DimensionData&, const DL_DimLinearData& ) override { ReportMsg( _( "DXF dimensions not currently supported." ) ); } + virtual void addDimRadial( const DL_DimensionData&, const DL_DimRadialData& ) override { ReportMsg( _( "DXF dimensions not currently supported." ) ); } + virtual void addDimDiametric( const DL_DimensionData&, const DL_DimDiametricData& ) override { ReportMsg( _( "DXF dimensions not currently supported." ) ); } + virtual void addDimAngular( const DL_DimensionData&, const DL_DimAngular2LData& ) override { ReportMsg( _( "DXF dimensions not currently supported." ) ); } + virtual void addDimAngular3P( const DL_DimensionData&, const DL_DimAngular3PData& ) override { ReportMsg( _( "DXF dimensions not currently supported." ) ); } + virtual void addDimOrdinate( const DL_DimensionData&, const DL_DimOrdinateData& ) override { ReportMsg( _( "DXF dimensions not currently supported." ) ); } + virtual void addLeader( const DL_LeaderData& ) override { ReportMsg( _( "DXF dimensions not currently supported." ) ); @@ -507,6 +515,7 @@ private: { ReportMsg( _( "DXF hatches not currently supported." ) ); } + virtual void addHatchLoop( const DL_HatchLoopData& ) override { } virtual void addHatchEdge( const DL_HatchEdgeData& ) override { } diff --git a/common/import_gfx/graphics_import_mgr.h b/common/import_gfx/graphics_import_mgr.h index c9c50ea5d9..9194dd1657 100644 --- a/common/import_gfx/graphics_import_mgr.h +++ b/common/import_gfx/graphics_import_mgr.h @@ -39,23 +39,23 @@ class wxString; class GRAPHICS_IMPORT_MGR { public: - ///< List of handled file types. + /// List of handled file types. enum GFX_FILE_T { DXF, SVG }; - ///< Vector containing all GFX_FILE_T values that can be imported. + /// Vector containing all GFX_FILE_T values that can be imported. std::vector GetImportableFileTypes() const { return { DXF, SVG }; } - ///< Returns a plugin that handles a specific file extension. + /// Return a plugin that handles a specific file extension. std::unique_ptr GetPluginByExt( const wxString& aExtension ) const; - ///< Returns a plugin instance for a specific file type. + /// Return a plugin instance for a specific file type. std::unique_ptr GetPlugin( GFX_FILE_T aType ) const; }; diff --git a/common/import_gfx/graphics_import_plugin.h b/common/import_gfx/graphics_import_plugin.h index afa67b8d41..ae93d0f1d5 100644 --- a/common/import_gfx/graphics_import_plugin.h +++ b/common/import_gfx/graphics_import_plugin.h @@ -134,7 +134,7 @@ public: virtual void ReportMsg( const wxString& aMessage ) = 0; protected: - ///< Importer used to create objects representing the imported shapes. + /// Importer used to create objects representing the imported shapes. GRAPHICS_IMPORTER* m_importer; }; diff --git a/common/import_gfx/graphics_importer.h b/common/import_gfx/graphics_importer.h index 76588fef71..bf8f0b5cd7 100644 --- a/common/import_gfx/graphics_importer.h +++ b/common/import_gfx/graphics_importer.h @@ -233,7 +233,7 @@ public: m_items.clear(); } - ///< Default line thickness (in mm) + /// Default line thickness (in mm). static constexpr unsigned int DEFAULT_LINE_WIDTH_DFX = 1; virtual void NewShape( POLY_FILL_RULE aFillRule = PF_NONZERO ); @@ -313,45 +313,46 @@ public: const IMPORTED_STROKE& aStroke ) = 0; protected: - ///< Add an item to the imported shapes list. + /// Add an item to the imported shapes list. void addItem( std::unique_ptr aItem ); - /* + /** * Configure a shape as a spline or a line segment if it's degenerate. * * @return false if the shape is near-zero length and should be ignored. */ bool setupSplineOrLine( EDA_SHAPE& aShape, int aAccuracy ); - ///< factor to convert millimeters to Internal Units + /// Factor to convert millimeters to Internal Units. double m_millimeterToIu; - ///< Offset (in mm) for imported coordinates + /// Offset (in mm) for imported coordinates. VECTOR2D m_offsetCoordmm; std::vector m_shapeFillRules; private: - ///< List of imported items + /// List of imported items. std::list> m_items; - ///< Plugin used to load a file + /// Plugin used to load a file. std::unique_ptr m_plugin; - ///< Total image width + /// Total image width. double m_originalWidth; - ///< Total image Height; + /// Total image Height. double m_originalHeight; /** * Scale factor applied to the imported graphics. + * * 1.0 does not change the size of imported items * scale < 1.0 reduce the size of imported items */ VECTOR2D m_scale; - ///< Default line thickness for the imported graphics + /// Default line thickness for the imported graphics. double m_lineWidth; }; diff --git a/common/import_gfx/graphics_importer_buffer.cpp b/common/import_gfx/graphics_importer_buffer.cpp index c447948b16..437ef2d795 100644 --- a/common/import_gfx/graphics_importer_buffer.cpp +++ b/common/import_gfx/graphics_importer_buffer.cpp @@ -114,18 +114,22 @@ void GRAPHICS_IMPORTER_BUFFER::ImportTo( GRAPHICS_IMPORTER& aImporter ) boundingBox.GetSize().y * aImporter.GetScale().y ); // Check that the scaled graphics fit in the KiCad numeric limits - if( boundingBox.GetSize().x * aImporter.GetMillimeterToIuFactor() > std::numeric_limits::max() || - boundingBox.GetSize().y * aImporter.GetMillimeterToIuFactor() > std::numeric_limits::max() ) + if( boundingBox.GetSize().x * aImporter.GetMillimeterToIuFactor() + > std::numeric_limits::max() + || boundingBox.GetSize().y * aImporter.GetMillimeterToIuFactor() + > std::numeric_limits::max() ) { - double scale_factor = std::numeric_limits::max() / ( aImporter.GetMillimeterToIuFactor() + 100 ); + double scale_factor = std::numeric_limits::max() / + ( aImporter.GetMillimeterToIuFactor() + 100 ); double max_scale = std::max( scale_factor / boundingBox.GetSize().x, scale_factor / boundingBox.GetSize().y ); - aImporter.ReportMsg( wxString::Format( _( "Imported graphic is too large. Maximum scale is %f" ), - max_scale ) ); + aImporter.ReportMsg( wxString::Format( _( "Imported graphic is too large. Maximum scale " + "is %f" ), + max_scale ) ); return; } - // They haven't set the import offset, so we set it to the bounding box origin to keep the graphics - // in the KiCad drawing area + // They haven't set the import offset, so we set it to the bounding box origin to keep + // the graphics in the KiCad drawing area. else if( aImporter.GetImportOffsetMM() == VECTOR2D( 0, 0 ) ) { if( boundingBox.GetRight() > std::numeric_limits::max() @@ -156,7 +160,8 @@ void GRAPHICS_IMPORTER_BUFFER::ImportTo( GRAPHICS_IMPORTER& aImporter ) if( max_offset_x >= std::numeric_limits::max() ) { - newOffset.x -= ( max_offset_x - std::numeric_limits::max() + 100.0 ) / total_scale_x; + newOffset.x -= ( max_offset_x - std::numeric_limits::max() + 100.0 ) / + total_scale_x; needsAdjustment = true; } else if( min_offset_x <= std::numeric_limits::min() ) @@ -178,7 +183,8 @@ void GRAPHICS_IMPORTER_BUFFER::ImportTo( GRAPHICS_IMPORTER& aImporter ) if( needsAdjustment ) { - aImporter.ReportMsg( wxString::Format( _( "Import offset adjusted to (%f, %f) to fit within numeric limits" ), + aImporter.ReportMsg( wxString::Format( _( "Import offset adjusted to (%f, %f) to fit " + "within numeric limits" ), newOffset.x, newOffset.y ) ); aImporter.SetImportOffsetMM( newOffset ); } @@ -188,7 +194,8 @@ void GRAPHICS_IMPORTER_BUFFER::ImportTo( GRAPHICS_IMPORTER& aImporter ) shape->ImportTo( aImporter ); } -// converts a single SVG-style polygon (multiple outlines, hole detection based on orientation, custom fill rule) to a format that can be digested by KiCad (single outline, fractured) +// converts a single SVG-style polygon (multiple outlines, hole detection based on orientation, +// custom fill rule) to a format that can be digested by KiCad (single outline, fractured). static void convertPolygon( std::list>& aShapes, std::vector& aPaths, GRAPHICS_IMPORTER::POLY_FILL_RULE aFillRule, @@ -200,8 +207,8 @@ static void convertPolygon( std::list>& aShapes, double maxX = std::numeric_limits::min(); double maxY = maxX; - // as Clipper/SHAPE_POLY_SET uses ints we first need to upscale to a reasonably large size (in integer coordinates) - // to avoid losing accuracy + // as Clipper/SHAPE_POLY_SET uses ints we first need to upscale to a reasonably large size + // (in integer coordinates) to avoid losing accuracy. const double convert_scale = 1000000000.0; for( IMPORTED_POLYGON* path : aPaths ) @@ -254,13 +261,15 @@ static void convertPolygon( std::list>& aShapes, } SHAPE_POLY_SET result; - result.BuildPolysetFromOrientedPaths( upscaledPaths, aFillRule == GRAPHICS_IMPORTER::PF_EVEN_ODD ); + result.BuildPolysetFromOrientedPaths( upscaledPaths, + aFillRule == GRAPHICS_IMPORTER::PF_EVEN_ODD ); result.Fracture(); for( int outl = 0; outl < result.OutlineCount(); outl++ ) { const SHAPE_LINE_CHAIN& ro = result.COutline( outl ); std::vector pts; + for( int i = 0; i < ro.PointCount(); i++ ) { double xp = (double) ro.CPoint( i ).x * ( origW / upscaledW ) + minX; diff --git a/common/import_gfx/graphics_importer_buffer.h b/common/import_gfx/graphics_importer_buffer.h index ed920d5e0b..c3ffca381c 100644 --- a/common/import_gfx/graphics_importer_buffer.h +++ b/common/import_gfx/graphics_importer_buffer.h @@ -385,7 +385,7 @@ public: void PostprocessNestedPolygons(); protected: - ///< List of imported shapes + /// List of imported shapes. std::list> m_shapes; }; diff --git a/common/import_gfx/svg_import_plugin.cpp b/common/import_gfx/svg_import_plugin.cpp index 97abb25107..eacd8d40ef 100644 --- a/common/import_gfx/svg_import_plugin.cpp +++ b/common/import_gfx/svg_import_plugin.cpp @@ -191,16 +191,17 @@ bool SVG_IMPORT_PLUGIN::Import() { if( filled && !path->closed ) { - // KiCad doesn't support a single object representing a filled shape that is *not* closed - // so create a filled, closed shape for the fill, and an unfilled, open shape for the outline + // KiCad doesn't support a single object representing a filled shape that is + // *not* closed so create a filled, closed shape for the fill, and an unfilled, + // open shape for the outline static IMPORTED_STROKE noStroke( -1, LINE_STYLE::SOLID, COLOR4D::UNSPECIFIED ); DrawPath( path->pts, path->npts, true, noStroke, true, fillColor ); DrawPath( path->pts, path->npts, false, stroke, false, COLOR4D::UNSPECIFIED ); } else { - // Either the shape has fill and no stroke, so we implicitly close it (for no difference), - // or it's really closed + // Either the shape has fill and no stroke, so we implicitly close it (for no + // difference), or it's really closed. // We could choose to import a not-filled, closed outline as splines to keep the // original editability and control points, but currently we don't. const bool closed = path->closed || filled; @@ -310,6 +311,7 @@ void SVG_IMPORT_PLUGIN::DrawPath( const float* aPoints, int aNumPoints, bool aCl { // Closed paths are always polygons, which mean they need to be interpolated std::vector collectedPathPoints; + if( aNumPoints > 0 ) GatherInterpolatedCubicBezierPath( aPoints, aNumPoints, collectedPathPoints ); @@ -489,4 +491,4 @@ void SVG_IMPORT_PLUGIN::ReportMsg( const wxString& aMessage ) // Add message to keep trace of not handled svg entities m_messages += aMessage; m_messages += '\n'; -} \ No newline at end of file +} diff --git a/common/increment.cpp b/common/increment.cpp index 2db71215a4..4245f9c509 100644 --- a/common/increment.cpp +++ b/common/increment.cpp @@ -65,12 +65,13 @@ KICOMMON_API bool IncrementString( wxString& name, int aIncrement ) number += aIncrement; // Don't let result go below zero - if( number > -1 ) { name.Remove( ii + 1 ); + //write out a format string with correct number of leading zeroes outputFormat.Printf( wxS( "%%0%dld" ), dCount ); + //write out the number using the format string outputNumber.Printf( outputFormat, number ); name << outputNumber << suffix; @@ -96,13 +97,16 @@ std::optional STRING_INCREMENTER::Increment( const wxString& aStr, int while( goodParts < ( aRightIndex + 1 ) && !remaining.IsEmpty() ) { static const std::regex integerRegex( R"(\d+$)" ); + // ABC or abc but not Abc static const std::regex sameCaseAlphabetRegex( R"(([a-z]+|[A-Z]+)$)" ); + // Skippables - for now anything that isn't a letter or number static const std::regex skipRegex( R"([^a-zA-Z0-9]+$)" ); std::string remainingStr = remaining.ToStdString(); std::smatch match; + if( std::regex_search( remainingStr, match, integerRegex ) ) { parts.push_back( { match.str(), STRING_PART_TYPE::INTEGER } ); @@ -139,10 +143,12 @@ std::optional STRING_INCREMENTER::Increment( const wxString& aStr, int // Reassemble the string - the left-over part, then parts in reverse wxString result = remaining; + for( auto it = parts.rbegin(); it != parts.rend(); ++it ) { result << it->first; } + return result; } @@ -150,11 +156,13 @@ std::optional STRING_INCREMENTER::Increment( const wxString& aStr, int static bool containsIOSQXZ( const wxString& aStr ) { static const wxString iosqxz = "IOSQXZ"; + for( const wxUniChar& c : aStr ) { if( iosqxz.Contains( c ) ) return true; } + return false; } @@ -185,6 +193,7 @@ bool STRING_INCREMENTER::incrementPart( wxString& aPart, STRING_PART_TYPE aType, { aPart = wxString( "0", oldLen - aPart.Len() ) + aPart; } + return true; } diff --git a/common/io/altium/altium_ascii_parser.cpp b/common/io/altium/altium_ascii_parser.cpp index eedf680fd1..622f14e987 100644 --- a/common/io/altium/altium_ascii_parser.cpp +++ b/common/io/altium/altium_ascii_parser.cpp @@ -94,8 +94,10 @@ std::map ALTIUM_ASCII_PARSER::ReadProperties() // convert the strings to wxStrings, since we use them everywhere // value can have non-ASCII characters, so we convert them from LATIN1/ISO8859-1 wxString key( keyS.c_str(), wxConvISO8859_1 ); + // Altium stores keys either in Upper, or in CamelCase. Lets unify it. wxString canonicalKey = key.Trim( false ).Trim( true ).MakeUpper(); + // If the key starts with '%UTF8%' we have to parse the value using UTF8 wxString value; diff --git a/common/io/altium/altium_binary_parser.cpp b/common/io/altium/altium_binary_parser.cpp index 41bfbcb0ee..fb40e982d7 100644 --- a/common/io/altium/altium_binary_parser.cpp +++ b/common/io/altium/altium_binary_parser.cpp @@ -191,7 +191,8 @@ ALTIUM_COMPOUND_FILE::GetLibSymbols( const CFB::COMPOUND_FILE_ENTRY* aStart ) co std::map folders; - m_reader->EnumFiles( root, 1, [&]( const CFB::COMPOUND_FILE_ENTRY* tentry, const CFB::utf16string&, int ) -> int + m_reader->EnumFiles( root, 1, [&]( const CFB::COMPOUND_FILE_ENTRY* tentry, + const CFB::utf16string&, int ) -> int { wxString dirName = UTF16ToWstring( tentry->name, tentry->nameLen ); @@ -199,7 +200,8 @@ ALTIUM_COMPOUND_FILE::GetLibSymbols( const CFB::COMPOUND_FILE_ENTRY* aStart ) co return 0; m_reader->EnumFiles( tentry, 1, - [&]( const CFB::COMPOUND_FILE_ENTRY* entry, const CFB::utf16string&, int ) -> int + [&]( const CFB::COMPOUND_FILE_ENTRY* entry, + const CFB::utf16string&, int ) -> int { std::wstring fileName = UTF16ToWstring( entry->name, entry->nameLen ); @@ -361,8 +363,8 @@ std::map ALTIUM_BINARY_PARSER::ReadProperties( if( !hasNullByte && !isBinary ) { - wxLogTrace( "ALTIUM", wxT( "Missing null byte at end of property list. Imported data might be " - "malformed or missing." ) ); + wxLogTrace( "ALTIUM", wxT( "Missing null byte at end of property list. Imported data " + "might be malformed or missing." ) ); } // we use std::string because std::string can handle NULL-bytes @@ -411,8 +413,10 @@ std::map ALTIUM_BINARY_PARSER::ReadProperties( // convert the strings to wxStrings, since we use them everywhere // value can have non-ASCII characters, so we convert them from LATIN1/ISO8859-1 wxString key( keyS.c_str(), wxConvISO8859_1 ); + // Altium stores keys either in Upper, or in CamelCase. Lets unify it. wxString canonicalKey = key.Trim( false ).Trim( true ).MakeUpper(); + // If the key starts with '%UTF8%' we have to parse the value using UTF8 wxString value; @@ -440,4 +444,4 @@ std::map ALTIUM_BINARY_PARSER::ReadProperties( } return kv; -} \ No newline at end of file +} diff --git a/common/io/altium/altium_binary_parser.h b/common/io/altium/altium_binary_parser.h index 858df72809..0318039ff0 100644 --- a/common/io/altium/altium_binary_parser.h +++ b/common/io/altium/altium_binary_parser.h @@ -96,7 +96,8 @@ public: const CFB::COMPOUND_FILE_ENTRY* FindStream( const std::vector& aStreamPath ) const; - const CFB::COMPOUND_FILE_ENTRY* FindStream( const CFB::COMPOUND_FILE_ENTRY* aStart, const std::vector& aStreamPath ) const; + const CFB::COMPOUND_FILE_ENTRY* FindStream( const CFB::COMPOUND_FILE_ENTRY* aStart, + const std::vector& aStreamPath ) const; const CFB::COMPOUND_FILE_ENTRY* FindStreamSingleLevel( const CFB::COMPOUND_FILE_ENTRY* aEntry, const std::string aName, @@ -116,7 +117,8 @@ private: class ALTIUM_BINARY_PARSER { public: - ALTIUM_BINARY_PARSER( const ALTIUM_COMPOUND_FILE& aFile, const CFB::COMPOUND_FILE_ENTRY* aEntry ); + ALTIUM_BINARY_PARSER( const ALTIUM_COMPOUND_FILE& aFile, + const CFB::COMPOUND_FILE_ENTRY* aEntry ); ALTIUM_BINARY_PARSER( std::unique_ptr& aContent, size_t aSize ); ~ALTIUM_BINARY_PARSER() = default; @@ -124,6 +126,7 @@ public: Type Read() { const size_t remainingBytes = GetRemainingBytes(); + if( remainingBytes >= sizeof( Type ) ) { Type val = *(Type*) ( m_pos ); @@ -188,7 +191,9 @@ public: remaining -= 8; if( length <= 2 ) + { length = 0; // for empty strings, not even the null bytes are present + } else { if( length > remaining ) @@ -405,6 +410,7 @@ public: int id = -1; uint8_t byte = ReadByte(); + if( byte != 0xD0 ) throw std::runtime_error( "ALTIUM_COMPRESSED_READER: invalid compressed string" ); diff --git a/common/io/altium/altium_parser_utils.cpp b/common/io/altium/altium_parser_utils.cpp index c223ff08c0..96ccbbdfee 100644 --- a/common/io/altium/altium_parser_utils.cpp +++ b/common/io/altium/altium_parser_utils.cpp @@ -129,7 +129,8 @@ wxString AltiumSchSpecialStringsToKiCadVariables( const wxString& } else { - wxString specialString = aString.substr( start, delimiter - start ).Trim().Trim( false ); + wxString specialString = + aString.substr( start, delimiter - start ).Trim().Trim( false ); if( specialString.StartsWith( "\"" ) && specialString.EndsWith( "\"" ) ) specialString = specialString.Mid( 1, specialString.Length() - 2 ); @@ -155,6 +156,7 @@ wxString AltiumSchSpecialStringsToKiCadVariables( const wxString& return result; } + // https://www.altium.com/documentation/altium-designer/text-objects-pcb wxString AltiumPcbSpecialStringsToKiCadStrings( const wxString& aString, const std::map& aOverrides ) @@ -182,6 +184,7 @@ wxString AltiumPcbSpecialStringsToKiCadStrings( const wxString& return aString; } + wxString AltiumPinNamesToKiCad( wxString& aString ) { if( aString.IsEmpty() ) @@ -195,6 +198,7 @@ wxString AltiumPinNamesToKiCad( wxString& aString ) return AltiumPropertyToKiCadString( aString ); } + VECTOR2I AltiumGetEllipticalPos( double aMajor, double aMinor, double aAngleRadians ) { if( aMajor == 0 || aMinor == 0 ) @@ -207,8 +211,9 @@ VECTOR2I AltiumGetEllipticalPos( double aMajor, double aMinor, double aAngleRadi double radius = numerator / denominator; - VECTOR2I retval( KiROUND( radius * cos( aAngleRadians ) ), KiROUND( radius * sin( aAngleRadians ) ) ); + VECTOR2I retval( KiROUND( radius * cos( aAngleRadians ) ), + KiROUND( radius * sin( aAngleRadians ) ) ); return retval; -} \ No newline at end of file +} diff --git a/common/io/altium/altium_props_utils.cpp b/common/io/altium/altium_props_utils.cpp index 4eed026a3a..351e2f6111 100644 --- a/common/io/altium/altium_props_utils.cpp +++ b/common/io/altium/altium_props_utils.cpp @@ -54,8 +54,8 @@ int ALTIUM_PROPS_UTILS::ReadInt( const std::map& aProps, con } -double ALTIUM_PROPS_UTILS::ReadDouble( const std::map& aProps, const wxString& aKey, - double aDefault ) +double ALTIUM_PROPS_UTILS::ReadDouble( const std::map& aProps, + const wxString& aKey, double aDefault ) { const std::map::const_iterator& value = aProps.find( aKey ); @@ -73,7 +73,7 @@ double ALTIUM_PROPS_UTILS::ReadDouble( const std::map& aProp bool ALTIUM_PROPS_UTILS::ReadBool( const std::map& aProps, const wxString& aKey, - bool aDefault ) + bool aDefault ) { const std::map::const_iterator& value = aProps.find( aKey ); @@ -85,7 +85,7 @@ bool ALTIUM_PROPS_UTILS::ReadBool( const std::map& aProps, c int32_t ALTIUM_PROPS_UTILS::ReadKicadUnit( const std::map& aProps, - const wxString& aKey, const wxString& aDefault ) + const wxString& aKey, const wxString& aDefault ) { const wxString& value = ReadString( aProps, aKey, aDefault ); @@ -112,7 +112,7 @@ int32_t ALTIUM_PROPS_UTILS::ReadKicadUnit( const std::map& a wxString ALTIUM_PROPS_UTILS::ReadString( const std::map& aProps, - const wxString& aKey, const wxString& aDefault ) + const wxString& aKey, const wxString& aDefault ) { const auto& utf8Value = aProps.find( wxString( "%UTF8%" ) + aKey ); @@ -129,7 +129,7 @@ wxString ALTIUM_PROPS_UTILS::ReadString( const std::map& aPr wxString ALTIUM_PROPS_UTILS::ReadUnicodeString( const std::map& aProps, - const wxString& aKey, const wxString& aDefault ) + const wxString& aKey, const wxString& aDefault ) { const auto& unicodeFlag = aProps.find( wxS( "UNICODE" ) ); @@ -150,4 +150,4 @@ wxString ALTIUM_PROPS_UTILS::ReadUnicodeString( const std::map %s", Name ) ); + wxString::Format( "LINECODE -> %s", Name ) ); } } @@ -396,8 +396,8 @@ void CADSTAR_ARCHIVE_PARSER::EVALUE::Parse( XNODE* aNode, PARSER_CONTEXT* aConte || ( !GetXmlAttributeIDString( aNode, 1 ).ToLong( &Exponent ) ) ) { THROW_PARSING_IO_ERROR( wxT( "Base and Exponent" ), - wxString::Format( - "%s->%s", aNode->GetParent()->GetName(), aNode->GetParent()->GetName() ) ); + wxString::Format( "%s->%s", aNode->GetParent()->GetName(), + aNode->GetParent()->GetName() ) ); } } @@ -495,7 +495,8 @@ void CADSTAR_ARCHIVE_PARSER::VERTEX::AppendToChain( SHAPE_LINE_CHAIN* aChainToAp wxCHECK_MSG( aChainToAppendTo->PointCount() > 0, /*void*/, "Can't append an arc to vertex to an empty chain" ); - aChainToAppendTo->Append( BuildArc( aChainToAppendTo->GetPoint( -1 ), aCadstarToKicadPointCallback), + aChainToAppendTo->Append( BuildArc( aChainToAppendTo->GetPoint( -1 ), + aCadstarToKicadPointCallback ), aAccuracy ); } @@ -625,7 +626,8 @@ SHAPE_POLY_SET CADSTAR_ARCHIVE_PARSER::SHAPE::ConvertToPolySet( { SHAPE_POLY_SET polyset; - wxCHECK( Type != SHAPE_TYPE::OPENSHAPE, polyset ); // We shouldn't convert openshapes to polyset! + // We shouldn't convert openshapes to polyset! + wxCHECK( Type != SHAPE_TYPE::OPENSHAPE, polyset ); polyset.AddOutline( OutlineAsChain( aCadstarToKicadPointCallback, aAccuracy ) ); @@ -885,7 +887,7 @@ wxString CADSTAR_ARCHIVE_PARSER::ParseTextFields( const wxString& aTextString, while( remainingStr.size() > 0 ) { - //Find the start token + // Find the start token size_t startpos = remainingStr.Find( wxT( "<@" ) ); if( static_cast( startpos ) == wxNOT_FOUND ) @@ -2449,7 +2451,8 @@ void CADSTAR_ARCHIVE_PARSER::InsertAttributeAtEnd( XNODE* aNode, wxString aValue XNODE* CADSTAR_ARCHIVE_PARSER::LoadArchiveFile( const wxString& aFileName, - const wxString& aFileTypeIdentifier, PROGRESS_REPORTER* aProgressReporter ) + const wxString& aFileTypeIdentifier, + PROGRESS_REPORTER* aProgressReporter ) { KEYWORD emptyKeywords[1] = {}; XNODE* rootNode = nullptr; @@ -2488,6 +2491,8 @@ XNODE* CADSTAR_ARCHIVE_PARSER::LoadArchiveFile( const wxString& aFileName, if( !aProgressReporter->KeepRefreshing() ) { delete rootNode; + + // @spellingerror THROW_IO_ERROR( _( "File import cancelled by user." ) ); } @@ -2745,7 +2750,8 @@ long CADSTAR_ARCHIVE_PARSER::GetNumberOfChildNodes( XNODE* aNode ) } -long CADSTAR_ARCHIVE_PARSER::GetNumberOfStepsForReporting( XNODE* aRootNode, std::vector aSubNodeChildrenToCount ) +long CADSTAR_ARCHIVE_PARSER::GetNumberOfStepsForReporting( + XNODE* aRootNode, std::vector aSubNodeChildrenToCount ) { XNODE* level1Node = aRootNode->GetChildren(); long retval = 0; diff --git a/common/io/cadstar/cadstar_archive_parser.h b/common/io/cadstar/cadstar_archive_parser.h index 9a9f8ddd5a..ddbe7c6b9a 100644 --- a/common/io/cadstar/cadstar_archive_parser.h +++ b/common/io/cadstar/cadstar_archive_parser.h @@ -87,7 +87,7 @@ class SHAPE_POLY_SET; class SHAPE_ARC; /** - * @brief Helper functions and common structures for CADSTAR PCB and Schematic archive files. + * Helper functions and common structures for CADSTAR PCB and Schematic archive files. */ class CADSTAR_ARCHIVE_PARSER { @@ -206,11 +206,12 @@ public: }; /** - * @brief Replaces CADSTAR fields for the equivalent in KiCad and stores the field values - * in aParserContext - * @param aTextString Text string to parse - * @param aParserContext PARSER_CONTEXT in which to store the values of the found fields - * @return + * Replaces CADSTAR fields for the equivalent in KiCad and stores the field values + * in \a aParserContext. + * + * @param aTextString Text string to parse. + * @param aParserContext #PARSER_CONTEXT in which to store the values of the found fields. + * @return the parsed field. */ static wxString ParseTextFields( const wxString& aTextString, PARSER_CONTEXT* aParserContext ); @@ -335,10 +336,10 @@ public: wxString Name = wxT( "CADSTAR" ); long Modifier1 = FONT_NORMAL; ///< It seems this is related to weight. 400=Normal, 700=Bold. long Modifier2 = 0; ///< It seems this is always 0 regardless of settings - bool KerningPairs = - false; ///< From CADSTAR Help: "Kerning Pairs is for causing the system to - ///< automatically reduce the spacing between certain pairs of - ///< characters in order to improve the appearance of the text" + bool KerningPairs = false; ///< From CADSTAR Help: "Kerning Pairs is for causing the + ///< system to automatically reduce the spacing between + ///< certain pairs of characters in order to improve the + ///< appearance of the text". bool Italic = false; void Parse( XNODE* aNode, PARSER_CONTEXT* aContext ) override; @@ -388,7 +389,7 @@ public: /** - * @brief Represents a floating value in E notation + * Represent a floating value in E notation. */ struct EVALUE : PARSER { @@ -400,7 +401,7 @@ public: }; /** - * @brief Represents a point in x,y coordinates + * Represent a point in x,y coordinates. */ struct POINT : VECTOR2I, PARSER { @@ -436,12 +437,13 @@ public: }; /** - * @brief Represents a vertex in a shape. E.g. A circle is made by two semicircles with the same + * Represents a vertex in a shape. E.g. A circle is made by two semicircles with the same * center point. */ struct VERTEX : PARSER { - VERTEX( VERTEX_TYPE aType = VERTEX_TYPE::POINT, POINT aEnd = POINT(), POINT aCenter = POINT() ) : + VERTEX( VERTEX_TYPE aType = VERTEX_TYPE::POINT, POINT aEnd = POINT(), + POINT aCenter = POINT() ) : Type( aType ), End( aEnd ), Center( aCenter ) {} @@ -462,7 +464,7 @@ public: }; /** - * @brief Represents a cutout in a closed shape (e.g. OUTLINE) + * Represent a cutout in a closed shape (e.g. OUTLINE). */ struct CUTOUT : PARSER { @@ -593,21 +595,20 @@ public: /** - * @brief From CADSTAR Help: "Text Alignment enables you to define the position of an alignment - * origin for all text items in CADSTAR. The alignment origin is a point on or within the text - * boundary and defines how the text is displayed. + * From CADSTAR Help: "Text Alignment enables you to define the position of an alignment + * origin for all text items in CADSTAR. * - * For example, with an alignment of bottom-right the origin will be positioned at the bottom - * right of the text boundary. This makes it easier to right-align several text items - * regardless of the length of text displayed. + * The alignment origin is a point on or within the text boundary and defines how the text + * is displayed. For example, with an alignment of bottom-right the origin will be positioned + * at the bottom right of the text boundary. This makes it easier to right-align several text + * items regardless of the length of text displayed. Text Alignment applies to all CADSTAR + * text. [...] * - * Text Alignment applies to all CADSTAR text. [...] - * - * Note: Unaligned text operates in the way CADSTAR text always has. In most cases this behaves + * @note Unaligned text operates in the way CADSTAR text always has. In most cases this behaves * as Bottom Left alignment, but there are a few exceptions, e.g. pin names. Also unaligned * multiline text has an origin Bottom Left of the first line." * - * See also JUSTIFICATION + * @see JUSTIFICATION */ enum class ALIGNMENT { @@ -627,13 +628,12 @@ public: static ALIGNMENT ParseAlignment( XNODE* aNode ); /** - * @brief From CADSTAR Help: "Multi Line Text can also be justified as Left, Centre or Right. - * This does not affect the text alignment. Note: Justification of single line text has no - * effect." + * From CADSTAR Help: "Multi Line Text can also be justified as Left, Centre or Right. * - * This only affects multiline text + * This does not affect the text alignment. Note: Justification of single line text has no + * effect." This only affects multiline text * - * See also ALIGNMENT + * @see ALIGNMENT */ enum class JUSTIFICATION { @@ -646,12 +646,12 @@ public: static JUSTIFICATION ParseJustification( XNODE* aNode ); /** - * @brief Sets the readability direction of text. From CADSTAR Help: "Horizontal text will - * always be displayed from left to right (i.e. never upside down). Vertical text can be set as - * readable from either the left or right edge of the design." + * Sets the readability direction of text. From CADSTAR Help: "Horizontal text will + * always be displayed from left to right (i.e. never upside down). * - * I.e. Vertical text can either be rotated 90 degrees clockwise or 90 degrees anticlockwise from - * horizontal. This does not impact vertical text + * Vertical text can be set as readable from either the left or right edge of the design." + * I.e. Vertical text can either be rotated 90 degrees clockwise or 90 degrees counterclockwise + * from horizontal. This does not impact vertical text. */ enum class READABILITY { @@ -725,7 +725,7 @@ public: /** - * @brief NOTE from CADSTAR help: To convert a Part Definition Attribute into a hyperlink, prefix + * NOTE from CADSTAR help: To convert a Part Definition Attribute into a hyperlink, prefix * the attribute name with "Link " */ struct ATTRNAME : PARSER @@ -783,7 +783,7 @@ public: /** - * @brief Corresponds to CADSTAR "origin". This is used for setting a location of an attribute + * Corresponds to CADSTAR "origin". This is used for setting a location of an attribute * e.g. Designator (called Component Name in CADSTAR), Part Name (name of component in the * library), etc. The atom identifier is "TEXTLOC" */ @@ -792,7 +792,7 @@ public: TEXT_LOCATION() { // The default alignment for TEXT_LOCATION (when "NO_ALIGNMENT" is selected) is - // Bottom left, matching CADSTAR's default behaviour + // Bottom left, matching CADSTAR's default behavior Alignment = ALIGNMENT::BOTTOMLEFT; } ATTRIBUTE_ID AttributeID; @@ -834,14 +834,12 @@ public: }; /** - * @brief Corresponds to "Display when" Item property. From CADSTAR - * Help: "This parameter enables you to make the visibility of - * a component outline/area (or an area of component copper, or - * a string of component text) dependent on the current mirror - * status of the component. + * Corresponds to "Display when" Item property. * - * For example, you may require a string of component text to - * be displayed only when the component is mirrored." + * From CADSTAR Help: "This parameter enables you to make the visibility of a component + * outline/area (or an area of component copper, or a string of component text) dependent + * on the current mirror status of the component. For example, you may require a string + * of component text to be displayed only when the component is mirrored." */ enum class SWAP_RULE { @@ -867,7 +865,7 @@ public: /** - * @brief References an element from a design reuse block + * References an element from a design reuse block. */ struct REUSEBLOCKREF : PARSER { @@ -994,9 +992,9 @@ public: wxString Identifier = wxEmptyString; ///< This should match a pad identifier ///< in the component footprint - ///< subnode="PINIDENTIFIER". It is assumed - ///< that this could be empty in earlier - ///< versions of CADSTAR + ///< subnode="PINIDENTIFIER". It is + ///< assumed that this could be empty in + ///< earlier versions of CADSTAR wxString Name = wxEmptyString; ///< Can be empty. If empty the pin name ///< displayed will be Identifier ///< (subnode="PINNAME") @@ -1028,7 +1026,6 @@ public: ///< the pin (It is unclear what the units ///< are, but only accepted values are ///< integers) subnode ="PINLOAD" - /// CADSTAR_PIN_POSITION Position = CADSTAR_PIN_POSITION::TOP_RIGHT; ///< The pin names will use these positions ///< when the symbol is added to a design @@ -1157,7 +1154,7 @@ public: NETELEMENT_ID ID; ///< First character is "J" LAYER_ID LayerID; POINT Location; - GROUP_ID GroupID = wxEmptyString; ///< If not empty, this JUCTION is part of a + GROUP_ID GroupID = wxEmptyString; ///< If not empty, this JUNCTION is part of a ///< group REUSEBLOCKREF ReuseBlockRef; bool Fixed = false; @@ -1289,7 +1286,8 @@ public: static void InsertAttributeAtEnd( XNODE* aNode, wxString aValue ); /** - * @brief Reads a CADSTAR Archive file (S-parameter format) + * Reads a CADSTAR Archive file (S-parameter format). + * * @param aFileName * @param aFileTypeIdentifier Identifier of the first node in the file to check against. E.g. "CADSTARPCB" @@ -1303,25 +1301,22 @@ public: PROGRESS_REPORTER* aProgressReporter = nullptr ); /** - * @brief * @param aAttribute * @return */ static bool IsValidAttribute( wxXmlAttribute* aAttribute ); /** - * @brief * @param aNode * @param aID * @param aIsRequired Prevents exception throwing if false. * @return returns the value (wxString) of attribute "attrX" in aNode where 'X' is aID * @throws IO_ERROR if attribute does not exist */ - static wxString GetXmlAttributeIDString( - XNODE* aNode, unsigned int aID, bool aIsRequired = true ); + static wxString GetXmlAttributeIDString( XNODE* aNode, unsigned int aID, + bool aIsRequired = true ); /** - * @brief * @param aNode * @param aID * @param aIsRequired Prevents exception throwing if false. @@ -1331,21 +1326,18 @@ public: static long GetXmlAttributeIDLong( XNODE* aNode, unsigned int aID, bool aIsRequired = true ); /** - * @brief * @param aNode * @throw IO_ERROR if a child node was found */ static void CheckNoChildNodes( XNODE* aNode ); /** - * @brief * @param aNode * @throw IO_ERROR if a node adjacent to aNode was found */ static void CheckNoNextNodes( XNODE* aNode ); /** - * @brief * @param aNode with a child node containing an EVALUE * @param aValueToParse * @throw IO_ERROR if unable to parse or node is not an EVALUE @@ -1353,8 +1345,8 @@ public: static void ParseChildEValue( XNODE* aNode, PARSER_CONTEXT* aContext, EVALUE& aValueToParse ); /** - * @brief if no children are present, it just returns an empty - * vector (without throwing an exception) + * If no children are present, it just returns an empty vector (without throwing an exception). + * * @param aNode containing a series of POINT objects * @param aTestAllChildNodes * @param aExpectedNumPoints if UNDEFINED_VALUE (i.e. -1), this is check is disabled @@ -1362,14 +1354,16 @@ public: * @throw IO_ERROR if one of the following: * - Unable to parse a POINT object * - aTestAllChildNodes is true and one of the child nodes is not a valid POINT object - * - aExpectedNumPoints is non-negative and the number of POINT objects found is different + * - aExpectedNumPoints is non-negative and the number of POINT objects found is + * different */ static std::vector ParseAllChildPoints( XNODE* aNode, PARSER_CONTEXT* aContext, - bool aTestAllChildNodes = false, int aExpectedNumPoints = UNDEFINED_VALUE ); + bool aTestAllChildNodes = false, + int aExpectedNumPoints = UNDEFINED_VALUE ); /** - * @brief if no children are present, it just returns an empty - * vector (without throwing an exception) + * If no children are present, it just returns an empty vector (without throwing an exception). + * * @param aNode containing a series of VERTEX objects * @param aTestAllChildNodes * @param aExpectedNumPoints if -1, this is check is disabled @@ -1378,12 +1372,12 @@ public: * - Unable to parse a VERTEX object * - aTestAllChildNodes is true and one of the child nodes is not a valid VERTEX object */ - static std::vector ParseAllChildVertices( - XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false ); + static std::vector ParseAllChildVertices( XNODE* aNode, PARSER_CONTEXT* aContext, + bool aTestAllChildNodes = false ); /** - * @brief if no children are present, it just returns an empty - * vector (without throwing an exception) + * If no children are present, it just returns an empty vector (without throwing an exception). + * * @param aNode containing a series of CUTOUT objects * @param aTestAllChildNodes * @param aExpectedNumPoints if -1, this is check is disabled @@ -1392,8 +1386,8 @@ public: * - Unable to parse a CUTOUT object * - aTestAllChildNodes is true and one of the child nodes is not a valid CUTOUT object */ - static std::vector ParseAllChildCutouts( - XNODE* aNode, PARSER_CONTEXT* aContext, bool aTestAllChildNodes = false ); + static std::vector ParseAllChildCutouts( XNODE* aNode, PARSER_CONTEXT* aContext, + bool aTestAllChildNodes = false ); static long GetNumberOfChildNodes( XNODE* aNode ); @@ -1412,16 +1406,19 @@ public: } /** - * @brief Convert a string with CADSTAR overbar characters to equivalent in KiCad + * Convert a string with CADSTAR overbar characters to equivalent in KiCad. + * * @param aCadstarString Input string * @return KiCad string with overbar characters - */ + */ static wxString HandleTextOverbar( wxString aCadstarString ); /** - * Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR. Assumes that the - * provided text element has been initialised with a position and orientation. - * @param aKiCadTextItem a Kicad item to correct + * Correct the position of a text element that had NO_ALIGNMENT in CADSTAR. + * + * Assumes that the provided text element has been initialised with a position and orientation. + * + * @param aKiCadTextItem a KiCad item to correct */ static void FixTextPositionNoAlignment( EDA_TEXT* aKiCadTextItem ); @@ -1429,7 +1426,7 @@ public: protected: - void checkPoint(); ///< Updates m_progressReporter or throws if user cancelled + void checkPoint(); ///< Updates m_progressReporter or throws if user canceled PARSER_CONTEXT m_context; PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr diff --git a/common/io/cadstar/cadstar_parts_lib_grammar.h b/common/io/cadstar/cadstar_parts_lib_grammar.h index df6bd3cb35..8f822615ad 100644 --- a/common/io/cadstar/cadstar_parts_lib_grammar.h +++ b/common/io/cadstar/cadstar_parts_lib_grammar.h @@ -48,13 +48,15 @@ struct WHITESPACE_OR_CONTINUATION : sor {}; * String segment( no line continuation ), with exclusion rules */ template -struct STR_SEGMENT_EXCLUDING : plus>, any>{}; +struct STR_SEGMENT_EXCLUDING : plus>, any>{}; /** * String with optional line continuation and exclusion rules */ template -struct STRING_EXCLUDING : plus, opt> {}; +struct STRING_EXCLUDING : plus, + opt> {}; /** @@ -122,7 +124,7 @@ struct FORMAT : seq CURRENT_FORMAT_NUMBER, opt > - {}; +{}; // Newer Parts files have possibility of specifying a tree-like structure to show hierarchy @@ -150,7 +152,7 @@ struct HIERARCHY_NODE_ENTRY : star>, // 'part1' 'part2' opt > - {}; +{}; // ************** // * PART ENTRY * @@ -166,7 +168,7 @@ struct PART_NAME_FILTER : sor, spaced_ch<':'>, spaced_ch<';'>>{}; struct PART_NUMBER_FILTER : one<')'>{}; struct PART_VERSION_FILTER : spaced_ch<';'>{}; - // part header elements: +// part header elements: struct PART_NAME : STRING_EXCLUDING {}; struct PART_NUMBER : STRING_IN_BRACKETS {}; struct PART_VERSION : STRING_EXCLUDING {}; @@ -189,11 +191,11 @@ struct PART_HEADER : // -------------------- //[_()] - // string filters: +// string filters: struct PCB_COMPONENT_FILTER : spaced_ch<'('>{}; struct PCB_ALTERNATE_FILTER : one<')'>{}; - // pcb component elements +// pcb component elements struct PCB_COMPONENT : STRING_EXCLUDING {}; struct PCB_ALTERNATE : STRING_IN_BRACKETS {}; @@ -370,7 +372,7 @@ struct EXTERNAL_SWAP_GROUP : // Part Definition // ----------- -//[*DFN_] +// [*DFN_] struct DEFINITION_NAME : STRING_EXCLUDING<> {}; struct DFN_LINE : seq @@ -383,7 +385,7 @@ struct DFN_LINE : > {}; -//[*NGS] +// [*NGS] struct NGS_LINE : seq < @@ -393,7 +395,7 @@ struct NGS_LINE : > {}; -//[*NPV] +// [*NPV] struct NPV_LINE : seq < @@ -403,7 +405,7 @@ struct NPV_LINE : > {}; -//[*STM_] +// [*STM_] struct STEM : STRING_EXCLUDING<> {}; struct STM_LINE : seq @@ -416,7 +418,7 @@ struct STM_LINE : > {}; -//[*MXP ] +// [*MXP ] struct MAX_PIN_COUNT : plus {}; struct MXP_LINE : seq @@ -429,7 +431,7 @@ struct MXP_LINE : > {}; -//[*SPI_[()]_[]_] +// [*SPI_[()]_[]_] struct SPICE_PART_NAME : STRING_IN_BRACKETS {}; struct SPICE_MODEL : sor> {}; struct SPI_LINE : @@ -446,7 +448,7 @@ struct SPI_LINE : {}; -//[*PAC_()_] +// [*PAC_()_] struct ACCEPTANCE_PART_NAME : STRING_IN_BRACKETS {}; struct ACCEPTANCE_TEXT : STRING_EXCLUDING<> {}; struct PAC_LINE : @@ -464,7 +466,7 @@ struct PAC_LINE : // User defined part attributes // ----------- -//[*_] +// [*_] struct USER_PART_ATTRIBUTE_NAME : sor> {}; struct USER_PART_ATTRIBUTE_VALUE : STRING_EXCLUDING<> {}; struct USER_PART_ATTRIBUTE : @@ -499,28 +501,28 @@ struct GENERIC_ATTRIBUTE : > {}; -//[$[!]()] +// [$[!]()] struct SCM_ATTRIBUTE : GENERIC_ATTRIBUTE<'$'>{}; -//[%[!]()] +// [%[!]()] struct PCB_ATTRIBUTE : GENERIC_ATTRIBUTE<'%'>{}; -//[~[!]()] +// [~[!]()] struct PART_ATTRIBUTE : GENERIC_ATTRIBUTE<'~'>{}; -//[@[!]()] +// [@[!]()] struct SCH_PCB_ATTRIBUTE : GENERIC_ATTRIBUTE<'@'>{}; -//[][_()] +// [][_()] struct SCH_NAME : sor>> {}; struct SCH_ALTERNATE : STRING_IN_BRACKETS {}; struct SCH_SYMBOL_LINE : seq, opt>{}; -//[[.] [!] [:]] +// [[.] [!] [:]] struct PIN_IDENTIFIER : plus{}; struct PIN_POSITION : range<'0', '3'>{}; struct PIN_TYPE : star{}; @@ -553,41 +555,42 @@ struct HIDDEN_PIN_ENTRY : seq, PIN_LIST, opt[ (1234): 1 ;] - PART_PCB_COMPONENT, // [(Alternate)] + PART_HEADER, // .[ (1234): 1 ;] + PART_PCB_COMPONENT, // [(Alternate)] // In any order: star] - PIN_NAMES_LIST, //[*PNM [ ] ...] - PIN_LABELS_LIST, //[*PLB