Adding rounded rect and custom pad shapes to VRML export
Fixes: lp:1753552 * https://bugs.launchpad.net/kicad/+bug/1753552
This commit is contained in:
parent
944a0b195e
commit
c69db6cf8f
|
@ -49,6 +49,8 @@
|
|||
#include "pcb_edit_frame.h"
|
||||
#include "../../kicad/kicad.h"
|
||||
|
||||
#include <convert_basic_shapes_to_polygon.h>
|
||||
|
||||
#include <zone_filler.h>
|
||||
|
||||
// minimum width (mm) of a VRML line
|
||||
|
@ -1148,6 +1150,55 @@ static void export_vrml_padshape( MODEL_VRML& aModel, VRML_LAYER* aTinLayer, D_P
|
|||
|
||||
break;
|
||||
|
||||
case PAD_SHAPE_ROUNDRECT:
|
||||
{
|
||||
SHAPE_POLY_SET polySet;
|
||||
int segmentToCircleCount = 32;
|
||||
const int corner_radius = aPad->GetRoundRectCornerRadius( aPad->GetSize() );
|
||||
TransformRoundRectToPolygon( polySet, wxPoint( 0, 0 ), aPad->GetSize(),
|
||||
0.0, corner_radius, segmentToCircleCount );
|
||||
std::vector< wxRealPoint > cornerList;
|
||||
// TransformRoundRectToPolygon creates only one convex polygon
|
||||
SHAPE_LINE_CHAIN poly( polySet.Outline( 0 ) );
|
||||
|
||||
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
||||
cornerList.push_back( wxRealPoint( poly.Point( ii ).x * BOARD_SCALE,
|
||||
-poly.Point( ii ).y * BOARD_SCALE ) );
|
||||
|
||||
// Close polygon
|
||||
cornerList.push_back( cornerList[0] );
|
||||
if( !aTinLayer->AddPolygon( cornerList, pad_x, -pad_y, aPad->GetOrientation() ) )
|
||||
throw( std::runtime_error( aTinLayer->GetError() ) );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PAD_SHAPE_CUSTOM:
|
||||
{
|
||||
SHAPE_POLY_SET polySet;
|
||||
int segmentToCircleCount = 32;
|
||||
std::vector< wxRealPoint > cornerList;
|
||||
aPad->MergePrimitivesAsPolygon( &polySet, segmentToCircleCount );
|
||||
|
||||
for( int cnt = 0; cnt < polySet.OutlineCount(); ++cnt )
|
||||
{
|
||||
SHAPE_LINE_CHAIN& poly = polySet.Outline( cnt );
|
||||
cornerList.clear();
|
||||
|
||||
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
||||
cornerList.push_back( wxRealPoint( poly.Point( ii ).x * BOARD_SCALE,
|
||||
-poly.Point( ii ).y * BOARD_SCALE ) );
|
||||
|
||||
// Close polygon
|
||||
cornerList.push_back( cornerList[0] );
|
||||
|
||||
if( !aTinLayer->AddPolygon( cornerList, pad_x, -pad_y, aPad->GetOrientation() ) )
|
||||
throw( std::runtime_error( aTinLayer->GetError() ) );
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PAD_SHAPE_RECT:
|
||||
// Just to be sure :D
|
||||
pad_dx = 0;
|
||||
|
|
|
@ -22,7 +22,12 @@ add_library( s3d_plugin_idf MODULE
|
|||
${CMAKE_SOURCE_DIR}/utils/idftools/vrml_layer.cpp
|
||||
)
|
||||
|
||||
target_link_libraries( s3d_plugin_idf kicad_3dsg idf3 ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )
|
||||
target_link_libraries( s3d_plugin_idf
|
||||
kicad_3dsg
|
||||
idf3
|
||||
common
|
||||
${OPENGL_LIBRARIES}
|
||||
${wxWidgets_LIBRARIES} )
|
||||
|
||||
if( APPLE )
|
||||
# puts library into the main kicad.app bundle in build tree
|
||||
|
|
|
@ -31,7 +31,7 @@ add_executable( idf2vrml idf2vrml.cpp )
|
|||
|
||||
target_link_libraries( dxf2idf lib_dxf idf3 ${wxWidgets_LIBRARIES} )
|
||||
|
||||
target_link_libraries( idf2vrml idf3 ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )
|
||||
target_link_libraries( idf2vrml idf3 common ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )
|
||||
|
||||
if( APPLE )
|
||||
# puts binaries into the *.app bundle while linking
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include <vrml_layer.h>
|
||||
#include <trigo.h>
|
||||
|
||||
#ifndef CALLBACK
|
||||
#define CALLBACK
|
||||
|
@ -579,6 +580,31 @@ bool VRML_LAYER::AddSlot( double aCenterX, double aCenterY,
|
|||
}
|
||||
|
||||
|
||||
bool VRML_LAYER::AddPolygon( const std::vector< wxRealPoint >& aPolySet, double aCenterX,
|
||||
double aCenterY, double aAngle )
|
||||
{
|
||||
int pad = NewContour( false );
|
||||
|
||||
if( pad < 0 )
|
||||
{
|
||||
error = "AddPolygon(): failed to add a contour";
|
||||
return false;
|
||||
}
|
||||
|
||||
for( auto corner : aPolySet )
|
||||
{
|
||||
// The sense of polygon rotations is reversed
|
||||
RotatePoint( &corner.x, &corner.y, -aAngle );
|
||||
AddVertex( pad, aCenterX + corner.x, aCenterY + corner.y );
|
||||
}
|
||||
|
||||
if( !EnsureWinding( pad, false ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// adds an arc to the given center, start point, pen width, and angle (degrees).
|
||||
bool VRML_LAYER::AppendArc( double aCenterX, double aCenterY, double aRadius,
|
||||
double aStartAngle, double aAngle, int aContourID )
|
||||
|
|
|
@ -312,6 +312,18 @@ public:
|
|||
double aArcWidth, double aAngle,
|
||||
bool aHoleFlag = false, bool aPlatedHole = false );
|
||||
|
||||
/**
|
||||
* Function AddPolygon
|
||||
* creates an arbitrary polygon and adds it to the list of contours
|
||||
*
|
||||
* @param aPolySet is the set of polygon points
|
||||
* @param aCenterX is the X coordinate of the polygon's center
|
||||
* @param aCenterY is the Y coordinate of the polygon's center
|
||||
* @param aAngle is the rotation angle (degrees) of the pad
|
||||
*/
|
||||
bool AddPolygon( const std::vector< wxRealPoint >& aPolySet,
|
||||
double aCenterX, double aCenterY, double aAngle );
|
||||
|
||||
/**
|
||||
* Function Tesselate
|
||||
* creates a list of outline vertices as well as the
|
||||
|
|
Loading…
Reference in New Issue