diff --git a/_clang-format b/_clang-format deleted file mode 100644 index 230059149..000000000 --- a/_clang-format +++ /dev/null @@ -1,53 +0,0 @@ -BasedOnStyle: LLVM -AccessModifierOffset: -4 -AlignAfterOpenBracket: DontAlign -AlignConsecutiveDeclarations: true -AlignEscapedNewlinesLeft: true -AlignOperands: true -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: true -AllowShortFunctionsOnASingleLine: false -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: false -BinPackArguments: true -BinPackParameters: true -BreakBeforeBinaryOperators: NonAssignment -BreakBeforeBraces: Allman -BreakBeforeTernaryOperators: false -BreakConstructorInitializersBeforeComma: false -BreakStringLiterals: false -ColumnLimit: 100 -ConstructorInitializerAllOnOneLineOrOnePerLine: true -ConstructorInitializerIndentWidth: 8 -ContinuationIndentWidth: 8 -Cpp11BracedListStyle: false -DerivePointerAlignment: false -DisableFormat: false -ForEachMacros: [ BOOST_FOREACH ] -IndentCaseLabels: false -IndentWidth: 4 -IndentWrappedFunctionNames: false -KeepEmptyLinesAtTheStartOfBlocks: true -Language: Cpp -MaxEmptyLinesToKeep: 2 -NamespaceIndentation: Inner -PointerAlignment: Left -ReflowComments: false -SortIncludes: true -SpaceAfterCStyleCast: true -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: Never -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInCStyleCastParentheses: false -SpacesInParentheses: true -SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 4 -UseTab: Never diff --git a/pcbnew/exporters/export_vrml.cpp b/pcbnew/exporters/export_vrml.cpp index ec8f85aea..81040c664 100644 --- a/pcbnew/exporters/export_vrml.cpp +++ b/pcbnew/exporters/export_vrml.cpp @@ -31,6 +31,7 @@ #include #include +#include "../../kicad/kicad.h" #include "3d_cache/3d_cache.h" #include "3d_cache/3d_info.h" #include "class_board.h" @@ -42,34 +43,36 @@ #include "convert_to_biu.h" #include "draw_graphic_text.h" #include "macros.h" +#include "pcb_edit_frame.h" #include "pgm_base.h" #include "plugins/3dapi/ifsg_all.h" #include "streamwrapper.h" #include "vrml_layer.h" -#include "pcb_edit_frame.h" -#include "../../kicad/kicad.h" #include - #include +#include "../../3d-viewer/3d_viewer/eda_3d_viewer.h" +#include "../../3d-viewer/3d_canvas/cinfo3d_visu.h" + // minimum width (mm) of a VRML line -#define MIN_VRML_LINEWIDTH 0.05 // previously 0.12 +#define MIN_VRML_LINEWIDTH 0.05 // previously 0.12 // offset for art layers, mm (silk, paste, etc) -#define ART_OFFSET 0.025 +#define ART_OFFSET 0.025 // offset for plating -#define PLATE_OFFSET 0.005 +#define PLATE_OFFSET 0.005 static S3D_CACHE* cache; -static bool USE_INLINES; // true to use legacy inline{} behavior -static bool USE_DEFS; // true to reuse component definitions -static bool USE_RELPATH; // true to use relative paths in VRML inline{} -static double WORLD_SCALE = 1.0; // scaling from 0.1 in to desired VRML unit -static double BOARD_SCALE; // scaling from mm to desired VRML world scale -static const int PRECISION = 6; // legacy precision factor (now set to 6) -static wxString SUBDIR_3D; // legacy 3D subdirectory -static wxString PROJ_DIR; // project directory +static bool USE_INLINES; // true to use legacy inline{} behavior +static bool USE_DEFS; // true to reuse component definitions +static bool USE_RELPATH; // true to use relative paths in VRML inline{} +static bool USE_3DVIEWER_COLORS; // true to use 3D Viewer colors instead of default colors +static double WORLD_SCALE = 1.0; // scaling from 0.1 in to desired VRML unit +static double BOARD_SCALE; // scaling from mm to desired VRML world scale +static const int PRECISION = 6; // legacy precision factor (now set to 6) +static wxString SUBDIR_3D; // legacy 3D subdirectory +static wxString PROJ_DIR; // project directory struct VRML_COLOR { @@ -103,14 +106,12 @@ struct VRML_COLOR emit_blu = 0.0; ambient = 0.8; - transp = 0; - shiny = 0.02; + transp = 0; + shiny = 0.02; } - VRML_COLOR( float dr, float dg, float db, - float sr, float sg, float sb, - float er, float eg, float eb, - float am, float tr, float sh ) + VRML_COLOR( float dr, float dg, float db, float sr, float sg, float sb, float er, float eg, + float eb, float am, float tr, float sh ) { diffuse_red = dr; diffuse_grn = dg; @@ -123,8 +124,13 @@ struct VRML_COLOR emit_blu = eb; ambient = am; - transp = tr; - shiny = sh; + transp = tr; + shiny = sh; + } + + VRML_COLOR( float r, float g, float b, float tr = 0 ) + : VRML_COLOR( r, g, b, 0.1 * r, 0.1 * g, 0.1 * b, 0, 0, 0, 0.8, tr, 0.02 ) + { } }; @@ -139,45 +145,45 @@ enum VRML_COLOR_INDEX }; static VRML_COLOR colors[VRML_COLOR_LAST]; -static SGNODE* sgmaterial[VRML_COLOR_LAST] = { NULL }; +static SGNODE* sgmaterial[VRML_COLOR_LAST] = { NULL }; class MODEL_VRML { private: - double m_layer_z[PCB_LAYER_ID_COUNT]; + double m_layer_z[PCB_LAYER_ID_COUNT]; - int m_iMaxSeg; // max. sides to a small circle - double m_arcMinLen, m_arcMaxLen; // min and max lengths of an arc chord + int m_iMaxSeg; // max. sides to a small circle + double m_arcMinLen, m_arcMaxLen; // min and max lengths of an arc chord public: IFSG_TRANSFORM m_OutputPCB; - VRML_LAYER m_holes; - VRML_LAYER m_board; - VRML_LAYER m_top_copper; - VRML_LAYER m_bot_copper; - VRML_LAYER m_top_silk; - VRML_LAYER m_bot_silk; - VRML_LAYER m_top_tin; - VRML_LAYER m_bot_tin; - VRML_LAYER m_plated_holes; - - std::list< SGNODE* > m_components; + VRML_LAYER m_holes; + VRML_LAYER m_board; + VRML_LAYER m_top_copper; + VRML_LAYER m_bot_copper; + VRML_LAYER m_top_silk; + VRML_LAYER m_bot_silk; + VRML_LAYER m_top_tin; + VRML_LAYER m_bot_tin; + VRML_LAYER m_plated_holes; + + std::list m_components; bool m_plainPCB; - double m_minLineWidth; // minimum width of a VRML line segment + double m_minLineWidth; // minimum width of a VRML line segment - double m_tx; // global translation along X - double m_ty; // global translation along Y + double m_tx; // global translation along X + double m_ty; // global translation along Y double m_brd_thickness; // depth of the PCB LAYER_NUM m_text_layer; - int m_text_width; + int m_text_width; MODEL_VRML() : m_OutputPCB( (SGNODE*) NULL ) { - for( unsigned i = 0; i < DIM( m_layer_z ); ++i ) + for( unsigned i = 0; i < DIM( m_layer_z ); ++i ) m_layer_z[i] = 0; m_holes.GetArcParams( m_iMaxSeg, m_arcMinLen, m_arcMaxLen ); @@ -186,17 +192,14 @@ public: m_brd_thickness = 1.6; // pcb green - colors[ VRML_COLOR_PCB ] = VRML_COLOR( .07, .3, .12, .01, .03, .01, - 0, 0, 0, 0.8, 0, 0.02 ); + colors[VRML_COLOR_PCB] = VRML_COLOR( .07, .3, .12, .01, .03, .01, 0, 0, 0, 0.8, 0, 0.02 ); // track green - colors[ VRML_COLOR_TRACK ] = VRML_COLOR( .08, .5, .1, .01, .05, .01, - 0, 0, 0, 0.8, 0, 0.02 ); + colors[VRML_COLOR_TRACK] = VRML_COLOR( .08, .5, .1, .01, .05, .01, 0, 0, 0, 0.8, 0, 0.02 ); // silkscreen white - colors[ VRML_COLOR_SILK ] = VRML_COLOR( .9, .9, .9, .1, .1, .1, - 0, 0, 0, 0.9, 0, 0.02 ); + colors[VRML_COLOR_SILK] = VRML_COLOR( .9, .9, .9, .1, .1, .1, 0, 0, 0, 0.9, 0, 0.02 ); // pad silver - colors[ VRML_COLOR_TIN ] = VRML_COLOR( .749, .756, .761, .749, .756, .761, - 0, 0, 0, 0.8, 0, 0.8 ); + colors[VRML_COLOR_TIN] = + VRML_COLOR( .749, .756, .761, .749, .756, .761, 0, 0, 0, 0.8, 0, 0.8 ); m_plainPCB = false; SetOffset( 0.0, 0.0 ); @@ -257,7 +260,7 @@ public: if( unsigned( aLayer ) >= DIM( m_layer_z ) ) return 0; - return m_layer_z[ aLayer ]; + return m_layer_z[aLayer]; } void SetLayerZ( LAYER_NUM aLayer, double aValue ) @@ -276,7 +279,6 @@ public: return true; } - }; @@ -290,70 +292,43 @@ static bool GetLayer( MODEL_VRML& aModel, LAYER_NUM layer, VRML_LAYER** vlayer ) { switch( layer ) { - case B_Cu: - *vlayer = &aModel.m_bot_copper; - break; + case B_Cu: *vlayer = &aModel.m_bot_copper; break; - case F_Cu: - *vlayer = &aModel.m_top_copper; - break; + case F_Cu: *vlayer = &aModel.m_top_copper; break; - case B_SilkS: - *vlayer = &aModel.m_bot_silk; - break; + case B_SilkS: *vlayer = &aModel.m_bot_silk; break; - case F_SilkS: - *vlayer = &aModel.m_top_silk; - break; + case F_SilkS: *vlayer = &aModel.m_top_silk; break; - default: - return false; + default: return false; } return true; } static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, - VRML_LAYER* layer, double top_z, double bottom_z ); + VRML_LAYER* layer, double top_z, double bottom_z ); static void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, - VRML_LAYER* layer, double aHeight, bool aTopPlane ); + VRML_LAYER* layer, double aHeight, bool aTopPlane ); -static void write_triangle_bag( std::ostream& aOut_file, VRML_COLOR& aColor, - VRML_LAYER* aLayer, bool aPlane, bool aTop, - double aTop_z, double aBottom_z ) +static void write_triangle_bag( std::ostream& aOut_file, VRML_COLOR& aColor, VRML_LAYER* aLayer, + bool aPlane, bool aTop, double aTop_z, double aBottom_z ) { /* A lot of nodes are not required, but blender sometimes chokes * without them */ - static const char* shape_boiler[] = - { - "Transform {\n", - " children [\n", - " Group {\n", - " children [\n", - " Shape {\n", - " appearance Appearance {\n", + static const char* shape_boiler[] = { + "Transform {\n", " children [\n", " Group {\n", " children [\n", + " Shape {\n", " appearance Appearance {\n", " material Material {\n", - 0, // Material marker - " }\n", - " }\n", - " geometry IndexedFaceSet {\n", - " solid TRUE\n", - " coord Coordinate {\n", - " point [\n", - 0, // Coordinates marker - " ]\n", - " }\n", - " coordIndex [\n", - 0, // Index marker - " ]\n", - " }\n", - " }\n", - " ]\n", - " }\n", - " ]\n", - "}\n", - 0 // End marker + 0, // Material marker + " }\n", " }\n", " geometry IndexedFaceSet {\n", + " solid TRUE\n", " coord Coordinate {\n", " point [\n", + 0, // Coordinates marker + " ]\n", " }\n", " coordIndex [\n", + 0, // Index marker + " ]\n", " }\n", " }\n", " ]\n", " }\n", " ]\n", "}\n", + 0 // End marker }; int marker_found = 0, lineno = 0; @@ -368,8 +343,8 @@ static void write_triangle_bag( std::ostream& aOut_file, VRML_COLOR& aColor, switch( marker_found ) { - case 1: // Material marker - aOut_file << " diffuseColor " << std::setprecision(3); + case 1: // Material marker + aOut_file << " diffuseColor " << std::setprecision( 3 ); aOut_file << aColor.diffuse_red << " "; aOut_file << aColor.diffuse_grn << " "; aOut_file << aColor.diffuse_blu << "\n"; @@ -409,8 +384,7 @@ static void write_triangle_bag( std::ostream& aOut_file, VRML_COLOR& aColor, aOut_file << "\n"; break; - default: - break; + default: break; } } @@ -419,18 +393,18 @@ static void write_triangle_bag( std::ostream& aOut_file, VRML_COLOR& aColor, } -static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, - const char* aFileName, OSTREAM* aOutputFile ) +static void write_layers( + MODEL_VRML& aModel, BOARD* aPcb, const char* aFileName, OSTREAM* aOutputFile ) { // VRML_LAYER board; aModel.m_board.Tesselate( &aModel.m_holes ); - double brdz = aModel.m_brd_thickness / 2.0 - - ( Millimeter2iu( ART_OFFSET / 2.0 ) ) * BOARD_SCALE; + double brdz = + aModel.m_brd_thickness / 2.0 - ( Millimeter2iu( ART_OFFSET / 2.0 ) ) * BOARD_SCALE; if( USE_INLINES ) { - write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_PCB ), - &aModel.m_board, false, false, brdz, -brdz ); + write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_PCB ), &aModel.m_board, false, + false, brdz, -brdz ); } else { @@ -450,14 +424,13 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, if( USE_INLINES ) { - write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ), - &aModel.m_top_copper, true, true, - aModel.GetLayerZ( F_Cu ), 0 ); + write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ), &aModel.m_top_copper, + true, true, aModel.GetLayerZ( F_Cu ), 0 ); } else { create_vrml_plane( aModel.m_OutputPCB, VRML_COLOR_TRACK, &aModel.m_top_copper, - aModel.GetLayerZ( F_Cu ), true ); + aModel.GetLayerZ( F_Cu ), true ); } // VRML_LAYER m_top_tin; @@ -465,16 +438,14 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, if( USE_INLINES ) { - write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ), - &aModel.m_top_tin, true, true, - aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, - 0 ); + write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ), &aModel.m_top_tin, + true, true, + aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, 0 ); } else { create_vrml_plane( aModel.m_OutputPCB, VRML_COLOR_TIN, &aModel.m_top_tin, - aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, - true ); + aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, true ); } // VRML_LAYER m_bot_copper; @@ -482,14 +453,13 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, if( USE_INLINES ) { - write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ), - &aModel.m_bot_copper, true, false, - aModel.GetLayerZ( B_Cu ), 0 ); + write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TRACK ), &aModel.m_bot_copper, + true, false, aModel.GetLayerZ( B_Cu ), 0 ); } else { create_vrml_plane( aModel.m_OutputPCB, VRML_COLOR_TRACK, &aModel.m_bot_copper, - aModel.GetLayerZ( B_Cu ), false ); + aModel.GetLayerZ( B_Cu ), false ); } // VRML_LAYER m_bot_tin; @@ -497,17 +467,14 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, if( USE_INLINES ) { - write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ), - &aModel.m_bot_tin, true, false, - aModel.GetLayerZ( B_Cu ) - - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, - 0 ); + write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ), &aModel.m_bot_tin, + true, false, + aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, 0 ); } else { create_vrml_plane( aModel.m_OutputPCB, VRML_COLOR_TIN, &aModel.m_bot_tin, - aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, - false ); + aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, false ); } // VRML_LAYER PTH; @@ -515,16 +482,16 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, if( USE_INLINES ) { - write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ), - &aModel.m_plated_holes, false, false, - aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, - aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE ); + write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_TIN ), &aModel.m_plated_holes, + false, false, + aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, + aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE ); } else { create_vrml_shell( aModel.m_OutputPCB, VRML_COLOR_TIN, &aModel.m_plated_holes, - aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, - aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE ); + aModel.GetLayerZ( F_Cu ) + Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE, + aModel.GetLayerZ( B_Cu ) - Millimeter2iu( ART_OFFSET / 2.0 ) * BOARD_SCALE ); } // VRML_LAYER m_top_silk; @@ -533,12 +500,12 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, if( USE_INLINES ) { write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_top_silk, - true, true, aModel.GetLayerZ( F_SilkS ), 0 ); + true, true, aModel.GetLayerZ( F_SilkS ), 0 ); } else { create_vrml_plane( aModel.m_OutputPCB, VRML_COLOR_SILK, &aModel.m_top_silk, - aModel.GetLayerZ( F_SilkS ), true ); + aModel.GetLayerZ( F_SilkS ), true ); } // VRML_LAYER m_bot_silk; @@ -547,12 +514,12 @@ static void write_layers( MODEL_VRML& aModel, BOARD* aPcb, if( USE_INLINES ) { write_triangle_bag( *aOutputFile, aModel.GetColor( VRML_COLOR_SILK ), &aModel.m_bot_silk, - true, false, aModel.GetLayerZ( B_SilkS ), 0 ); + true, false, aModel.GetLayerZ( B_SilkS ), 0 ); } else { create_vrml_plane( aModel.m_OutputPCB, VRML_COLOR_SILK, &aModel.m_bot_silk, - aModel.GetLayerZ( B_SilkS ), false ); + aModel.GetLayerZ( B_SilkS ), false ); } if( !USE_INLINES ) @@ -569,14 +536,15 @@ static void compute_layer_Zs( MODEL_VRML& aModel, BOARD* pcb ) double half_thickness = aModel.m_brd_thickness / 2; // Compute each layer's Z value, more or less like the 3d view - for( LSEQ seq = LSET::AllCuMask().Seq(); seq; ++seq ) + for( LSEQ seq = LSET::AllCuMask().Seq(); seq; ++seq ) { PCB_LAYER_ID i = *seq; if( i < copper_layers ) - aModel.SetLayerZ( i, half_thickness - aModel.m_brd_thickness * i / (copper_layers - 1) ); + aModel.SetLayerZ( + i, half_thickness - aModel.m_brd_thickness * i / ( copper_layers - 1 ) ); else - aModel.SetLayerZ( i, - half_thickness ); // bottom layer + aModel.SetLayerZ( i, -half_thickness ); // bottom layer } /* To avoid rounding interference, we apply an epsilon to each @@ -598,34 +566,32 @@ static void compute_layer_Zs( MODEL_VRML& aModel, BOARD* pcb ) } -static void export_vrml_line( MODEL_VRML& aModel, LAYER_NUM layer, - double startx, double starty, - double endx, double endy, double width ) +static void export_vrml_line( MODEL_VRML& aModel, LAYER_NUM layer, double startx, double starty, + double endx, double endy, double width ) { VRML_LAYER* vlayer; if( !GetLayer( aModel, layer, &vlayer ) ) return; - if( width < aModel.m_minLineWidth) + if( width < aModel.m_minLineWidth ) width = aModel.m_minLineWidth; starty = -starty; endy = -endy; - double angle = atan2( endy - starty, endx - startx ) * 180.0 / M_PI; - double length = Distance( startx, starty, endx, endy ) + width; - double cx = ( startx + endx ) / 2.0; - double cy = ( starty + endy ) / 2.0; + double angle = atan2( endy - starty, endx - startx ) * 180.0 / M_PI; + double length = Distance( startx, starty, endx, endy ) + width; + double cx = ( startx + endx ) / 2.0; + double cy = ( starty + endy ) / 2.0; if( !vlayer->AddSlot( cx, cy, length, width, angle, false ) ) throw( std::runtime_error( vlayer->GetError() ) ); } -static void export_vrml_circle( MODEL_VRML& aModel, LAYER_NUM layer, - double startx, double starty, - double endx, double endy, double width ) +static void export_vrml_circle( MODEL_VRML& aModel, LAYER_NUM layer, double startx, double starty, + double endx, double endy, double width ) { VRML_LAYER* vlayer; @@ -640,7 +606,7 @@ static void export_vrml_circle( MODEL_VRML& aModel, LAYER_NUM layer, double hole, radius; - radius = Distance( startx, starty, endx, endy ) + ( width / 2); + radius = Distance( startx, starty, endx, endy ) + ( width / 2 ); hole = radius - width; if( !vlayer->AddCircle( startx, starty, radius, false ) ) @@ -654,10 +620,8 @@ static void export_vrml_circle( MODEL_VRML& aModel, LAYER_NUM layer, } -static void export_vrml_arc( MODEL_VRML& aModel, LAYER_NUM layer, - double centerx, double centery, - double arc_startx, double arc_starty, - double width, double arc_angle ) +static void export_vrml_arc( MODEL_VRML& aModel, LAYER_NUM layer, double centerx, double centery, + double arc_startx, double arc_starty, double width, double arc_angle ) { VRML_LAYER* vlayer; @@ -672,26 +636,25 @@ static void export_vrml_arc( MODEL_VRML& aModel, LAYER_NUM layer, if( !vlayer->AddArc( centerx, centery, arc_startx, arc_starty, width, -arc_angle, false ) ) throw( std::runtime_error( vlayer->GetError() ) ); - } -static void export_vrml_polygon( MODEL_VRML& aModel, LAYER_NUM layer, - DRAWSEGMENT *aOutline, double aOrientation, wxPoint aPos ) +static void export_vrml_polygon( MODEL_VRML& aModel, LAYER_NUM layer, DRAWSEGMENT* aOutline, + double aOrientation, wxPoint aPos ) { const int circleSegmentsCount = 32; if( aOutline->IsPolyShapeValid() ) { SHAPE_POLY_SET shape = aOutline->GetPolyShape(); - VRML_LAYER* vlayer; + VRML_LAYER* vlayer; if( !GetLayer( aModel, layer, &vlayer ) ) - return; + return; if( aOutline->GetWidth() ) { - shape.Inflate( aOutline->GetWidth()/2, circleSegmentsCount ); + shape.Inflate( aOutline->GetWidth() / 2, circleSegmentsCount ); shape.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE ); } @@ -704,7 +667,7 @@ static void export_vrml_polygon( MODEL_VRML& aModel, LAYER_NUM layer, for( int j = 0; j < outline.PointCount(); j++ ) { if( !vlayer->AddVertex( seg, outline.CPoint( j ).x * BOARD_SCALE, - -outline.CPoint( j ).y * BOARD_SCALE ) ) + -outline.CPoint( j ).y * BOARD_SCALE ) ) throw( std::runtime_error( vlayer->GetError() ) ); } @@ -716,12 +679,12 @@ static void export_vrml_polygon( MODEL_VRML& aModel, LAYER_NUM layer, static void export_vrml_drawsegment( MODEL_VRML& aModel, DRAWSEGMENT* drawseg ) { LAYER_NUM layer = drawseg->GetLayer(); - double w = drawseg->GetWidth() * BOARD_SCALE; - double x = drawseg->GetStart().x * BOARD_SCALE; - double y = drawseg->GetStart().y * BOARD_SCALE; - double xf = drawseg->GetEnd().x * BOARD_SCALE; - double yf = drawseg->GetEnd().y * BOARD_SCALE; - double r = sqrt( pow( x - xf, 2 ) + pow( y - yf, 2 ) ); + double w = drawseg->GetWidth() * BOARD_SCALE; + double x = drawseg->GetStart().x * BOARD_SCALE; + double y = drawseg->GetStart().y * BOARD_SCALE; + double xf = drawseg->GetEnd().x * BOARD_SCALE; + double yf = drawseg->GetEnd().y * BOARD_SCALE; + double r = sqrt( pow( x - xf, 2 ) + pow( y - yf, 2 ) ); // Items on the edge layer are handled elsewhere; just return if( layer == Edge_Cuts ) @@ -730,28 +693,22 @@ static void export_vrml_drawsegment( MODEL_VRML& aModel, DRAWSEGMENT* drawseg ) switch( drawseg->GetShape() ) { case S_ARC: - export_vrml_arc( aModel, layer, - (double) drawseg->GetCenter().x * BOARD_SCALE, - (double) drawseg->GetCenter().y * BOARD_SCALE, - (double) drawseg->GetArcStart().x * BOARD_SCALE, - (double) drawseg->GetArcStart().y * BOARD_SCALE, - w, drawseg->GetAngle() / 10 ); + export_vrml_arc( aModel, layer, (double) drawseg->GetCenter().x * BOARD_SCALE, + (double) drawseg->GetCenter().y * BOARD_SCALE, + (double) drawseg->GetArcStart().x * BOARD_SCALE, + (double) drawseg->GetArcStart().y * BOARD_SCALE, w, drawseg->GetAngle() / 10 ); break; case S_CIRCLE: // Break circles into two 180 arcs to prevent the vrml hole from obscuring objects // within the hole area of the circle. - export_vrml_arc( aModel, layer, x, y, x, y-r, w, 180.0 ); - export_vrml_arc( aModel, layer, x, y, x, y+r, w, 180.0 ); + export_vrml_arc( aModel, layer, x, y, x, y - r, w, 180.0 ); + export_vrml_arc( aModel, layer, x, y, x, y + r, w, 180.0 ); break; - case S_POLYGON: - export_vrml_polygon( aModel, layer, drawseg, 0.0, wxPoint( 0, 0 ) ); - break; + case S_POLYGON: export_vrml_polygon( aModel, layer, drawseg, 0.0, wxPoint( 0, 0 ) ); break; - default: - export_vrml_line( aModel, layer, x, y, xf, yf, w ); - break; + default: export_vrml_line( aModel, layer, x, y, xf, yf, w ); break; } } @@ -761,26 +718,24 @@ static void export_vrml_drawsegment( MODEL_VRML& aModel, DRAWSEGMENT* drawseg ) static void vrml_text_callback( int x0, int y0, int xf, int yf, void* aData ) { LAYER_NUM m_text_layer = model_vrml->m_text_layer; - int m_text_width = model_vrml->m_text_width; + int m_text_width = model_vrml->m_text_width; - export_vrml_line( *model_vrml, m_text_layer, - x0 * BOARD_SCALE, y0 * BOARD_SCALE, - xf * BOARD_SCALE, yf * BOARD_SCALE, - m_text_width * BOARD_SCALE ); + export_vrml_line( *model_vrml, m_text_layer, x0 * BOARD_SCALE, y0 * BOARD_SCALE, + xf * BOARD_SCALE, yf * BOARD_SCALE, m_text_width * BOARD_SCALE ); } static void export_vrml_pcbtext( MODEL_VRML& aModel, TEXTE_PCB* text ) { - model_vrml->m_text_layer = text->GetLayer(); - model_vrml->m_text_width = text->GetThickness(); + model_vrml->m_text_layer = text->GetLayer(); + model_vrml->m_text_width = text->GetThickness(); wxSize size = text->GetTextSize(); if( text->IsMirrored() ) size.x = -size.x; - COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by DrawGraphicText + COLOR4D color = COLOR4D::BLACK; // not actually used, but needed by DrawGraphicText if( text->IsMultilineAllowed() ) { @@ -793,22 +748,16 @@ static void export_vrml_pcbtext( MODEL_VRML& aModel, TEXTE_PCB* text ) for( unsigned ii = 0; ii < strings_list.Count(); ii++ ) { wxString& txt = strings_list.Item( ii ); - DrawGraphicText( NULL, NULL, positions[ii], color, - txt, text->GetTextAngle(), size, - text->GetHorizJustify(), text->GetVertJustify(), - text->GetThickness(), text->IsItalic(), - true, - vrml_text_callback ); + DrawGraphicText( NULL, NULL, positions[ii], color, txt, text->GetTextAngle(), size, + text->GetHorizJustify(), text->GetVertJustify(), text->GetThickness(), + text->IsItalic(), true, vrml_text_callback ); } } else { - DrawGraphicText( NULL, NULL, text->GetTextPos(), color, - text->GetShownText(), text->GetTextAngle(), size, - text->GetHorizJustify(), text->GetVertJustify(), - text->GetThickness(), text->IsItalic(), - true, - vrml_text_callback ); + DrawGraphicText( NULL, NULL, text->GetTextPos(), color, text->GetShownText(), + text->GetTextAngle(), size, text->GetHorizJustify(), text->GetVertJustify(), + text->GetThickness(), text->IsItalic(), true, vrml_text_callback ); } } @@ -825,16 +774,11 @@ static void export_vrml_drawings( MODEL_VRML& aModel, BOARD* pcb ) switch( drawing->Type() ) { - case PCB_LINE_T: - export_vrml_drawsegment( aModel, (DRAWSEGMENT*) drawing ); - break; + case PCB_LINE_T: export_vrml_drawsegment( aModel, (DRAWSEGMENT*) drawing ); break; - case PCB_TEXT_T: - export_vrml_pcbtext( aModel, (TEXTE_PCB*) drawing ); - break; + case PCB_TEXT_T: export_vrml_pcbtext( aModel, (TEXTE_PCB*) drawing ); break; - default: - break; + default: break; } } } @@ -843,13 +787,13 @@ static void export_vrml_drawings( MODEL_VRML& aModel, BOARD* pcb ) // board edges and cutouts static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb ) { - SHAPE_POLY_SET pcbOutlines; // stores the board main outlines - wxString msg; + SHAPE_POLY_SET pcbOutlines; // stores the board main outlines + wxString msg; if( !aPcb->GetBoardPolygonOutlines( pcbOutlines, &msg ) ) { - msg << "\n\n" << - _( "Unable to calculate the board outlines; fall back to using the board boundary box." ); + msg << "\n\n" + << _( "Unable to calculate the board outlines; fall back to using the board boundary box." ); wxMessageBox( msg ); } @@ -863,9 +807,8 @@ static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb ) for( int j = 0; j < outline.PointCount(); j++ ) { - aModel.m_board.AddVertex( seg, (double)outline.CPoint(j).x * BOARD_SCALE, - -((double)outline.CPoint(j).y * BOARD_SCALE ) ); - + aModel.m_board.AddVertex( seg, (double) outline.CPoint( j ).x * BOARD_SCALE, + -( (double) outline.CPoint( j ).y * BOARD_SCALE ) ); } aModel.m_board.EnsureWinding( seg, false ); @@ -879,8 +822,7 @@ static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb ) if( seg < 0 ) { - msg << "\n\n" << - _( "VRML Export Failed: Could not add holes to contours." ); + msg << "\n\n" << _( "VRML Export Failed: Could not add holes to contours." ); wxMessageBox( msg ); return; @@ -888,9 +830,8 @@ static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb ) for( int j = 0; j < hole.PointCount(); j++ ) { - aModel.m_holes.AddVertex( seg, (double)hole.CPoint(j).x * BOARD_SCALE, - -((double)hole.CPoint(j).y * BOARD_SCALE ) ); - + aModel.m_holes.AddVertex( seg, (double) hole.CPoint( j ).x * BOARD_SCALE, + -( (double) hole.CPoint( j ).y * BOARD_SCALE ) ); } aModel.m_holes.EnsureWinding( seg, true ); @@ -899,13 +840,11 @@ static void export_vrml_board( MODEL_VRML& aModel, BOARD* aPcb ) } -static void export_round_padstack( MODEL_VRML& aModel, BOARD* pcb, - double x, double y, double r, - LAYER_NUM bottom_layer, LAYER_NUM top_layer, - double hole ) +static void export_round_padstack( MODEL_VRML& aModel, BOARD* pcb, double x, double y, double r, + LAYER_NUM bottom_layer, LAYER_NUM top_layer, double hole ) { - LAYER_NUM layer = top_layer; - bool thru = true; + LAYER_NUM layer = top_layer; + bool thru = true; // if not a thru hole do not put a hole in the board if( top_layer != F_Cu || bottom_layer != B_Cu ) @@ -925,7 +864,6 @@ static void export_round_padstack( MODEL_VRML& aModel, BOARD* pcb, if( hole > 0 && !thru ) aModel.m_bot_copper.AddCircle( x, -y, hole, true ); - } else if( layer == F_Cu ) { @@ -933,7 +871,6 @@ static void export_round_padstack( MODEL_VRML& aModel, BOARD* pcb, if( hole > 0 && !thru ) aModel.m_top_copper.AddCircle( x, -y, hole, true ); - } if( layer == bottom_layer ) @@ -946,13 +883,13 @@ static void export_round_padstack( MODEL_VRML& aModel, BOARD* pcb, static void export_vrml_via( MODEL_VRML& aModel, BOARD* aPcb, const VIA* aVia ) { - double x, y, r, hole; - PCB_LAYER_ID top_layer, bottom_layer; + double x, y, r, hole; + PCB_LAYER_ID top_layer, bottom_layer; hole = aVia->GetDrillValue() * BOARD_SCALE / 2.0; - r = aVia->GetWidth() * BOARD_SCALE / 2.0; - x = aVia->GetStart().x * BOARD_SCALE; - y = aVia->GetStart().y * BOARD_SCALE; + r = aVia->GetWidth() * BOARD_SCALE / 2.0; + x = aVia->GetStart().x * BOARD_SCALE; + y = aVia->GetStart().y * BOARD_SCALE; aVia->LayerPair( &top_layer, &bottom_layer ); // do not render a buried via @@ -972,14 +909,10 @@ static void export_vrml_tracks( MODEL_VRML& aModel, BOARD* pcb ) { export_vrml_via( aModel, pcb, (const VIA*) track ); } - else if( ( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu ) - && !aModel.m_plainPCB ) - export_vrml_line( aModel, track->GetLayer(), - track->GetStart().x * BOARD_SCALE, - track->GetStart().y * BOARD_SCALE, - track->GetEnd().x * BOARD_SCALE, - track->GetEnd().y * BOARD_SCALE, - track->GetWidth() * BOARD_SCALE ); + else if( ( track->GetLayer() == B_Cu || track->GetLayer() == F_Cu ) && !aModel.m_plainPCB ) + export_vrml_line( aModel, track->GetLayer(), track->GetStart().x * BOARD_SCALE, + track->GetStart().y * BOARD_SCALE, track->GetEnd().x * BOARD_SCALE, + track->GetEnd().y * BOARD_SCALE, track->GetWidth() * BOARD_SCALE ); } } @@ -1015,10 +948,9 @@ static void export_vrml_zones( MODEL_VRML& aModel, BOARD* aPcb ) for( int j = 0; j < outline.PointCount(); j++ ) { - if( !vl->AddVertex( seg, (double)outline.CPoint( j ).x * BOARD_SCALE, - -((double)outline.CPoint( j ).y * BOARD_SCALE ) ) ) + if( !vl->AddVertex( seg, (double) outline.CPoint( j ).x * BOARD_SCALE, + -( (double) outline.CPoint( j ).y * BOARD_SCALE ) ) ) throw( std::runtime_error( vl->GetError() ) ); - } vl->EnsureWinding( seg, false ); @@ -1034,52 +966,42 @@ static void export_vrml_text_module( TEXTE_MODULE* module ) wxSize size = module->GetTextSize(); if( module->IsMirrored() ) - size.x = -size.x; // Text is mirrored + size.x = -size.x; // Text is mirrored - model_vrml->m_text_layer = module->GetLayer(); - model_vrml->m_text_width = module->GetThickness(); + model_vrml->m_text_layer = module->GetLayer(); + model_vrml->m_text_width = module->GetThickness(); - DrawGraphicText( NULL, NULL, module->GetTextPos(), BLACK, - module->GetShownText(), module->GetDrawRotation(), size, - module->GetHorizJustify(), module->GetVertJustify(), - module->GetThickness(), module->IsItalic(), - true, - vrml_text_callback ); + DrawGraphicText( NULL, NULL, module->GetTextPos(), BLACK, module->GetShownText(), + module->GetDrawRotation(), size, module->GetHorizJustify(), + module->GetVertJustify(), module->GetThickness(), module->IsItalic(), true, + vrml_text_callback ); } } -static void export_vrml_edge_module( MODEL_VRML& aModel, EDGE_MODULE* aOutline, - MODULE* aModule ) +static void export_vrml_edge_module( MODEL_VRML& aModel, EDGE_MODULE* aOutline, MODULE* aModule ) { LAYER_NUM layer = aOutline->GetLayer(); - double x = aOutline->GetStart().x * BOARD_SCALE; - double y = aOutline->GetStart().y * BOARD_SCALE; - double xf = aOutline->GetEnd().x * BOARD_SCALE; - double yf = aOutline->GetEnd().y * BOARD_SCALE; - double w = aOutline->GetWidth() * BOARD_SCALE; + double x = aOutline->GetStart().x * BOARD_SCALE; + double y = aOutline->GetStart().y * BOARD_SCALE; + double xf = aOutline->GetEnd().x * BOARD_SCALE; + double yf = aOutline->GetEnd().y * BOARD_SCALE; + double w = aOutline->GetWidth() * BOARD_SCALE; switch( aOutline->GetShape() ) { - case S_SEGMENT: - export_vrml_line( aModel, layer, x, y, xf, yf, w ); - break; + case S_SEGMENT: export_vrml_line( aModel, layer, x, y, xf, yf, w ); break; - case S_ARC: - export_vrml_arc( aModel, layer, x, y, xf, yf, w, aOutline->GetAngle() / 10 ); - break; + case S_ARC: export_vrml_arc( aModel, layer, x, y, xf, yf, w, aOutline->GetAngle() / 10 ); break; - case S_CIRCLE: - export_vrml_circle( aModel, layer, x, y, xf, yf, w ); - break; + case S_CIRCLE: export_vrml_circle( aModel, layer, x, y, xf, yf, w ); break; case S_POLYGON: - export_vrml_polygon( aModel, layer, aOutline, aModule->GetOrientationRadians(), - aModule->GetPosition() ); + export_vrml_polygon( + aModel, layer, aOutline, aModule->GetOrientationRadians(), aModule->GetPosition() ); break; - default: - break; + default: break; } } @@ -1088,15 +1010,15 @@ static void export_vrml_padshape( MODEL_VRML& aModel, VRML_LAYER* aTinLayer, D_P { // The (maybe offset) pad position wxPoint pad_pos = aPad->ShapePos(); - double pad_x = pad_pos.x * BOARD_SCALE; - double pad_y = pad_pos.y * BOARD_SCALE; + double pad_x = pad_pos.x * BOARD_SCALE; + double pad_y = pad_pos.y * BOARD_SCALE; wxSize pad_delta = aPad->GetDelta(); - double pad_dx = pad_delta.x * BOARD_SCALE / 2.0; - double pad_dy = pad_delta.y * BOARD_SCALE / 2.0; + double pad_dx = pad_delta.x * BOARD_SCALE / 2.0; + double pad_dy = pad_delta.y * BOARD_SCALE / 2.0; - double pad_w = aPad->GetSize().x * BOARD_SCALE / 2.0; - double pad_h = aPad->GetSize().y * BOARD_SCALE / 2.0; + double pad_w = aPad->GetSize().x * BOARD_SCALE / 2.0; + double pad_h = aPad->GetSize().y * BOARD_SCALE / 2.0; switch( aPad->GetShape() ) { @@ -1110,7 +1032,7 @@ static void export_vrml_padshape( MODEL_VRML& aModel, VRML_LAYER* aTinLayer, D_P case PAD_SHAPE_OVAL: if( !aTinLayer->AddSlot( pad_x, -pad_y, pad_w * 2.0, pad_h * 2.0, - aPad->GetOrientation()/10.0, false ) ) + aPad->GetOrientation() / 10.0, false ) ) throw( std::runtime_error( aTinLayer->GetError() ) ); break; @@ -1118,17 +1040,17 @@ static void export_vrml_padshape( MODEL_VRML& aModel, VRML_LAYER* aTinLayer, D_P 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; + 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 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 ) ); + cornerList.push_back( wxRealPoint( + poly.Point( ii ).x * BOARD_SCALE, -poly.Point( ii ).y * BOARD_SCALE ) ); // Close polygon cornerList.push_back( cornerList[0] ); @@ -1140,9 +1062,9 @@ static void export_vrml_padshape( MODEL_VRML& aModel, VRML_LAYER* aTinLayer, D_P case PAD_SHAPE_CUSTOM: { - SHAPE_POLY_SET polySet; - int segmentToCircleCount = 32; - std::vector< wxRealPoint > cornerList; + SHAPE_POLY_SET polySet; + int segmentToCircleCount = 32; + std::vector cornerList; aPad->MergePrimitivesAsPolygon( &polySet, segmentToCircleCount ); for( int cnt = 0; cnt < polySet.OutlineCount(); ++cnt ) @@ -1151,8 +1073,8 @@ static void export_vrml_padshape( MODEL_VRML& aModel, VRML_LAYER* aTinLayer, D_P 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 ) ); + cornerList.push_back( wxRealPoint( + poly.Point( ii ).x * BOARD_SCALE, -poly.Point( ii ).y * BOARD_SCALE ) ); // Close polygon cornerList.push_back( cornerList[0] ); @@ -1166,18 +1088,13 @@ static void export_vrml_padshape( MODEL_VRML& aModel, VRML_LAYER* aTinLayer, D_P case PAD_SHAPE_RECT: // Just to be sure :D - pad_dx = 0; - pad_dy = 0; + pad_dx = 0; + pad_dy = 0; case PAD_SHAPE_TRAPEZOID: { - double coord[8] = - { - -pad_w + pad_dy, -pad_h - pad_dx, - -pad_w - pad_dy, pad_h + pad_dx, - +pad_w - pad_dy, -pad_h + pad_dx, - +pad_w + pad_dy, pad_h - pad_dx - }; + double coord[8] = { -pad_w + pad_dy, -pad_h - pad_dx, -pad_w - pad_dy, pad_h + pad_dx, + +pad_w - pad_dy, -pad_h + pad_dx, +pad_w + pad_dy, pad_h - pad_dx }; for( int i = 0; i < 4; i++ ) { @@ -1211,27 +1128,25 @@ static void export_vrml_padshape( MODEL_VRML& aModel, VRML_LAYER* aTinLayer, D_P break; } - default: - break; + default: break; } } static void export_vrml_pad( MODEL_VRML& aModel, BOARD* aPcb, D_PAD* aPad ) { - double hole_drill_w = (double) aPad->GetDrillSize().x * BOARD_SCALE / 2.0; - double hole_drill_h = (double) aPad->GetDrillSize().y * BOARD_SCALE / 2.0; - double hole_drill = std::min( hole_drill_w, hole_drill_h ); - double hole_x = aPad->GetPosition().x * BOARD_SCALE; - double hole_y = aPad->GetPosition().y * BOARD_SCALE; + double hole_drill_w = (double) aPad->GetDrillSize().x * BOARD_SCALE / 2.0; + double hole_drill_h = (double) aPad->GetDrillSize().y * BOARD_SCALE / 2.0; + double hole_drill = std::min( hole_drill_w, hole_drill_h ); + double hole_x = aPad->GetPosition().x * BOARD_SCALE; + double hole_y = aPad->GetPosition().y * BOARD_SCALE; // Export the hole on the edge layer if( hole_drill > 0 ) { bool pth = false; - if( ( aPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED ) - && !aModel.m_plainPCB ) + if( ( aPad->GetAttribute() != PAD_ATTRIB_HOLE_NOT_PLATED ) && !aModel.m_plainPCB ) pth = true; if( aPad->GetDrillShape() == PAD_DRILL_SHAPE_OBLONG ) @@ -1241,18 +1156,16 @@ static void export_vrml_pad( MODEL_VRML& aModel, BOARD* aPcb, D_PAD* aPad ) if( pth ) { aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0 + PLATE_OFFSET, - hole_drill_h * 2.0 + PLATE_OFFSET, - aPad->GetOrientation()/10.0, true, true ); + hole_drill_h * 2.0 + PLATE_OFFSET, aPad->GetOrientation() / 10.0, true, + true ); - aModel.m_plated_holes.AddSlot( hole_x, -hole_y, - hole_drill_w * 2.0, hole_drill_h * 2.0, - aPad->GetOrientation()/10.0, true, false ); + aModel.m_plated_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0, + hole_drill_h * 2.0, aPad->GetOrientation() / 10.0, true, false ); } else { aModel.m_holes.AddSlot( hole_x, -hole_y, hole_drill_w * 2.0, hole_drill_h * 2.0, - aPad->GetOrientation()/10.0, true, false ); - + aPad->GetOrientation() / 10.0, true, false ); } } else @@ -1268,7 +1181,6 @@ static void export_vrml_pad( MODEL_VRML& aModel, BOARD* aPcb, D_PAD* aPad ) { aModel.m_holes.AddCircle( hole_x, -hole_y, hole_drill, true, false ); } - } } @@ -1292,7 +1204,6 @@ static void export_vrml_pad( MODEL_VRML& aModel, BOARD* aPcb, D_PAD* aPad ) else export_vrml_padshape( aModel, &aModel.m_top_copper, aPad ); } - } @@ -1337,8 +1248,8 @@ static void compose_quat( double q1[4], double q2[4], double qr[4] ) } -static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, - MODULE* aModule, std::ostream* aOutputFile ) +static void export_vrml_module( + MODEL_VRML& aModel, BOARD* aPcb, MODULE* aModule, std::ostream* aOutputFile ) { if( !aModel.m_plainPCB ) { @@ -1354,17 +1265,15 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, { switch( item->Type() ) { - case PCB_MODULE_TEXT_T: - export_vrml_text_module( static_cast( item ) ); - break; + case PCB_MODULE_TEXT_T: + export_vrml_text_module( static_cast( item ) ); + break; - case PCB_MODULE_EDGE_T: - export_vrml_edge_module( aModel, static_cast( item ), - aModule ); - break; + case PCB_MODULE_EDGE_T: + export_vrml_edge_module( aModel, static_cast( item ), aModule ); + break; - default: - break; + default: break; } } } @@ -1438,8 +1347,8 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, SGPOINT trans; trans.x = ( offsetx + aModule->GetPosition().x ) * BOARD_SCALE + aModel.m_tx; - trans.y = -(offsety + aModule->GetPosition().y) * BOARD_SCALE - aModel.m_ty; - trans.z = (offsetz * BOARD_SCALE ) + aModel.GetLayerZ( aModule->GetLayer() ); + trans.y = -( offsety + aModule->GetPosition().y ) * BOARD_SCALE - aModel.m_ty; + trans.z = ( offsetz * BOARD_SCALE ) + aModel.GetLayerZ( aModule->GetLayer() ); if( USE_INLINES ) { @@ -1447,7 +1356,7 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, wxFileName dstFile; dstFile.SetPath( SUBDIR_3D ); dstFile.SetName( srcFile.GetName() ); - dstFile.SetExt( "wrl" ); + dstFile.SetExt( "wrl" ); // copy the file if necessary wxDateTime srcModTime = srcFile.GetModificationTime(); @@ -1460,9 +1369,8 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, if( srcModTime != destModTime ) { - wxLogDebug( "Copying 3D model %s to %s.", - GetChars( srcFile.GetFullPath() ), - GetChars( dstFile.GetFullPath() ) ); + wxLogDebug( "Copying 3D model %s to %s.", GetChars( srcFile.GetFullPath() ), + GetChars( dstFile.GetFullPath() ) ); wxString fileExt = srcFile.GetExt(); fileExt.LowerCase(); @@ -1476,31 +1384,33 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, } else { - if( !S3D::WriteVRML( dstFile.GetFullPath().ToUTF8(), true, mod3d, USE_DEFS, true ) ) + if( !S3D::WriteVRML( + dstFile.GetFullPath().ToUTF8(), true, mod3d, USE_DEFS, true ) ) continue; } } - (*aOutputFile) << "Transform {\n"; + ( *aOutputFile ) << "Transform {\n"; // only write a rotation if it is >= 0.1 deg if( std::abs( rot[3] ) > 0.0001745 ) { - (*aOutputFile) << " rotation " << std::setprecision( 5 ); - (*aOutputFile) << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << "\n"; + ( *aOutputFile ) << " rotation " << std::setprecision( 5 ); + ( *aOutputFile ) << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] + << "\n"; } - (*aOutputFile) << " translation " << std::setprecision( PRECISION ); - (*aOutputFile) << trans.x << " "; - (*aOutputFile) << trans.y << " "; - (*aOutputFile) << trans.z << "\n"; + ( *aOutputFile ) << " translation " << std::setprecision( PRECISION ); + ( *aOutputFile ) << trans.x << " "; + ( *aOutputFile ) << trans.y << " "; + ( *aOutputFile ) << trans.z << "\n"; - (*aOutputFile) << " scale "; - (*aOutputFile) << sM->m_Scale.x << " "; - (*aOutputFile) << sM->m_Scale.y << " "; - (*aOutputFile) << sM->m_Scale.z << "\n"; + ( *aOutputFile ) << " scale "; + ( *aOutputFile ) << sM->m_Scale.x << " "; + ( *aOutputFile ) << sM->m_Scale.y << " "; + ( *aOutputFile ) << sM->m_Scale.z << "\n"; - (*aOutputFile) << " children [\n Inline {\n url \""; + ( *aOutputFile ) << " children [\n Inline {\n url \""; if( USE_RELPATH ) { @@ -1513,8 +1423,8 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, wxString fn = dstFile.GetFullPath(); fn.Replace( "\\", "/" ); - (*aOutputFile) << TO_UTF8( fn ) << "\"\n } ]\n"; - (*aOutputFile) << " }\n"; + ( *aOutputFile ) << TO_UTF8( fn ) << "\"\n } ]\n"; + ( *aOutputFile ) << " }\n"; } else { @@ -1536,7 +1446,6 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, { modelShape->AddRefNode( mod3d ); } - } ++sM; @@ -1545,21 +1454,41 @@ static void export_vrml_module( MODEL_VRML& aModel, BOARD* aPcb, bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMtoWRMLunit, - bool aExport3DFiles, bool aUseRelativePaths, - bool aUsePlainPCB, const wxString& a3D_Subdir, - double aXRef, double aYRef ) + bool aExport3DFiles, bool aUseRelativePaths, bool aUsePlainPCB, const wxString& a3D_Subdir, + double aXRef, double aYRef ) { - BOARD* pcb = GetBoard(); - bool ok = true; + BOARD* pcb = GetBoard(); + bool ok = true; USE_INLINES = aExport3DFiles; USE_DEFS = true; USE_RELPATH = aUseRelativePaths; + USE_3DVIEWER_COLORS = true; cache = Prj().Get3DCacheManager(); PROJ_DIR = Prj().GetProjectPath(); SUBDIR_3D = a3D_Subdir; + MODEL_VRML model3d; + + if( USE_3DVIEWER_COLORS ) + { + EDA_3D_VIEWER* viewer = Get3DViewerFrame(); + + if( viewer != nullptr ) + { + const CINFO3D_VISU& settings = viewer->GetSettings(); + + const auto to_vrml_color = []( SFVEC3D color ) { + return VRML_COLOR( color.r, color.g, color.b ); + }; + + colors[VRML_COLOR_PCB] = to_vrml_color( settings.m_BoardBodyColor ); + colors[VRML_COLOR_TRACK] = to_vrml_color( settings.m_CopperColor ); + colors[VRML_COLOR_SILK] = to_vrml_color( settings.m_SilkScreenColor ); + } + } + model_vrml = &model3d; model3d.SetScale( aMMtoWRMLunit ); @@ -1581,10 +1510,10 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt { // Preliminary computation: the z value for each layer - compute_layer_Zs(model3d, pcb); + compute_layer_Zs( model3d, pcb ); // board edges and cutouts - export_vrml_board(model3d, pcb); + export_vrml_board( model3d, pcb ); // Drawing and text on the board if( !aUsePlainPCB ) @@ -1595,14 +1524,14 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt // Export zone fills if( !aUsePlainPCB ) - export_vrml_zones( model3d, pcb); + export_vrml_zones( model3d, pcb ); if( USE_INLINES ) { // check if the 3D Subdir exists - create if not wxFileName subdir( SUBDIR_3D, "" ); - if( ! subdir.DirExists() ) + if( !subdir.DirExists() ) { if( !wxDir::Make( subdir.GetFullPath() ) ) throw( std::runtime_error( "Could not create 3D model subdirectory" ) ); @@ -1621,7 +1550,7 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString& aFullFileName, double aMMt // Begin with the usual VRML boilerplate wxString fn = aFullFileName; - fn.Replace( "\\" , "/" ); + fn.Replace( "\\", "/" ); output_file << "#VRML V2.0 utf8\n"; output_file << "WorldInfo {\n"; output_file << " title \"" << TO_UTF8( fn ) << " - Generated by Pcbnew\"\n"; @@ -1679,7 +1608,7 @@ static SGNODE* getSGColor( VRML_COLOR_INDEX colorIdx ) return sgmaterial[colorIdx]; IFSG_APPEARANCE vcolor( (SGNODE*) NULL ); - VRML_COLOR* cp = &colors[colorIdx]; + VRML_COLOR* cp = &colors[colorIdx]; vcolor.SetSpecular( cp->spec_red, cp->spec_grn, cp->spec_blu ); vcolor.SetDiffuse( cp->diffuse_red, cp->diffuse_grn, cp->diffuse_blu ); @@ -1696,16 +1625,17 @@ static SGNODE* getSGColor( VRML_COLOR_INDEX colorIdx ) static void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, - VRML_LAYER* layer, double top_z, bool aTopPlane ) + VRML_LAYER* layer, double top_z, bool aTopPlane ) { - std::vector< double > vertices; - std::vector< int > idxPlane; - std::vector< int > idxSide; + std::vector vertices; + std::vector idxPlane; + std::vector idxSide; - if( !(*layer).Get2DTriangles( vertices, idxPlane, top_z, aTopPlane ) ) + if( !( *layer ).Get2DTriangles( vertices, idxPlane, top_z, aTopPlane ) ) { #ifdef DEBUG - do { + do + { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * [INFO] no vertex data"; @@ -1719,7 +1649,8 @@ static void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX color if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) ) { #ifdef DEBUG - do { + do + { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)"; @@ -1727,25 +1658,26 @@ static void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX color } while( 0 ); #endif - throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) ); + throw( std::runtime_error( + "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) ); } - std::vector< SGPOINT > vlist; - size_t nvert = vertices.size() / 3; - size_t j = 0; + std::vector vlist; + size_t nvert = vertices.size() / 3; + size_t j = 0; - for( size_t i = 0; i < nvert; ++i, j+= 3 ) - vlist.push_back( SGPOINT( vertices[j], vertices[j+1], vertices[j+2] ) ); + for( size_t i = 0; i < nvert; ++i, j += 3 ) + vlist.push_back( SGPOINT( vertices[j], vertices[j + 1], vertices[j + 2] ) ); // create the intermediate scenegraph - IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline - IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals - IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes - IFSG_COORDS cp( face ); // coordinates for all faces + IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline + IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals + IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes + IFSG_COORDS cp( face ); // coordinates for all faces cp.SetCoordsList( nvert, &vlist[0] ); - IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only + IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] ); - IFSG_NORMALS norms( face ); // normals for the top and bottom planes + IFSG_NORMALS norms( face ); // normals for the top and bottom planes // set the normals if( aTopPlane ) @@ -1775,11 +1707,11 @@ static void create_vrml_plane( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX color static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX colorID, - VRML_LAYER* layer, double top_z, double bottom_z ) + VRML_LAYER* layer, double top_z, double bottom_z ) { - std::vector< double > vertices; - std::vector< int > idxPlane; - std::vector< int > idxSide; + std::vector vertices; + std::vector idxPlane; + std::vector idxSide; if( top_z < bottom_z ) { @@ -1788,10 +1720,11 @@ static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX color bottom_z = tmp; } - if( !(*layer).Get3DTriangles( vertices, idxPlane, idxSide, top_z, bottom_z ) ) + if( !( *layer ).Get3DTriangles( vertices, idxPlane, idxSide, top_z, bottom_z ) ) { #ifdef DEBUG - do { + do + { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * [INFO] no vertex data"; @@ -1805,7 +1738,8 @@ static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX color if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) ) { #ifdef DEBUG - do { + do + { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)"; @@ -1813,25 +1747,26 @@ static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX color } while( 0 ); #endif - throw( std::runtime_error( "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) ); + throw( std::runtime_error( + "[BUG] index lists are not a multiple of 3 (not a triangle list)" ) ); } - std::vector< SGPOINT > vlist; - size_t nvert = vertices.size() / 3; - size_t j = 0; + std::vector vlist; + size_t nvert = vertices.size() / 3; + size_t j = 0; - for( size_t i = 0; i < nvert; ++i, j+= 3 ) - vlist.push_back( SGPOINT( vertices[j], vertices[j+1], vertices[j+2] ) ); + for( size_t i = 0; i < nvert; ++i, j += 3 ) + vlist.push_back( SGPOINT( vertices[j], vertices[j + 1], vertices[j + 2] ) ); // create the intermediate scenegraph - IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline - IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals - IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes - IFSG_COORDS cp( face ); // coordinates for all faces + IFSG_TRANSFORM tx0( PcbOutput.GetRawPtr() ); // tx0 = Transform for this outline + IFSG_SHAPE shape( tx0 ); // shape will hold (a) all vertices and (b) a local list of normals + IFSG_FACESET face( shape ); // this face shall represent the top and bottom planes + IFSG_COORDS cp( face ); // coordinates for all faces cp.SetCoordsList( nvert, &vlist[0] ); - IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only + IFSG_COORDINDEX coordIdx( face ); // coordinate indices for top and bottom planes only coordIdx.SetIndices( idxPlane.size(), &idxPlane[0] ); - IFSG_NORMALS norms( face ); // normals for the top and bottom planes + IFSG_NORMALS norms( face ); // normals for the top and bottom planes // number of TOP (and bottom) vertices j = nvert / 2; @@ -1858,18 +1793,18 @@ static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX color // create a second shape describing the vertical walls of the extrusion // using per-vertex-per-face-normals shape.NewNode( tx0 ); - shape.AddRefNode( modelColor ); // set the color to be the same as the top/bottom + shape.AddRefNode( modelColor ); // set the color to be the same as the top/bottom face.NewNode( shape ); - cp.NewNode( face ); // new vertex list - norms.NewNode( face ); // new normals list - coordIdx.NewNode( face ); // new index list + cp.NewNode( face ); // new vertex list + norms.NewNode( face ); // new normals list + coordIdx.NewNode( face ); // new index list // populate the new per-face vertex list and its indices and normals - std::vector< int >::iterator sI = idxSide.begin(); - std::vector< int >::iterator eI = idxSide.end(); + std::vector::iterator sI = idxSide.begin(); + std::vector::iterator eI = idxSide.end(); - size_t sidx = 0; // index to the new coord set - SGPOINT p1, p2, p3; + size_t sidx = 0; // index to the new coord set + SGPOINT p1, p2, p3; SGVECTOR vnorm; while( sI != eI ) @@ -1891,11 +1826,11 @@ static void create_vrml_shell( IFSG_TRANSFORM& PcbOutput, VRML_COLOR_INDEX color norms.AddNormal( vnorm ); norms.AddNormal( vnorm ); - coordIdx.AddIndex( (int)sidx ); + coordIdx.AddIndex( (int) sidx ); ++sidx; - coordIdx.AddIndex( (int)sidx ); + coordIdx.AddIndex( (int) sidx ); ++sidx; - coordIdx.AddIndex( (int)sidx ); + coordIdx.AddIndex( (int) sidx ); ++sidx; } }