2015-12-10 21:34:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-03-02 22:53:49 +00:00
|
|
|
* Copyright (C) 2015-2017 Cirilo Bernardo <cirilo.bernardo@gmail.com>
|
2015-12-10 21:34:52 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
// Note: the board's bottom side is at Z = 0
|
|
|
|
|
2015-12-10 21:34:52 +00:00
|
|
|
#include <iostream>
|
2016-02-23 02:42:51 +00:00
|
|
|
#include <sstream>
|
2015-12-10 21:34:52 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2017-03-02 22:53:49 +00:00
|
|
|
#include <wx/filename.h>
|
2016-02-23 02:42:51 +00:00
|
|
|
#include <wx/log.h>
|
2015-12-13 21:45:22 +00:00
|
|
|
#include <wx/string.h>
|
2017-03-02 22:53:49 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
#include "plugins/3d/3d_plugin.h"
|
2015-12-10 21:34:52 +00:00
|
|
|
#include "plugins/3dapi/ifsg_all.h"
|
|
|
|
#include "idf_parser.h"
|
|
|
|
#include "vrml_layer.h"
|
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
#define PLUGIN_3D_IDF_MAJOR 1
|
|
|
|
#define PLUGIN_3D_IDF_MINOR 0
|
|
|
|
#define PLUGIN_3D_IDF_PATCH 0
|
2015-12-14 03:51:28 +00:00
|
|
|
#define PLUGIN_3D_IDF_REVNO 0
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
// number of colors in the palette; cycles from 1..NCOLORS;
|
|
|
|
// number 0 is special (the PCB board color)
|
|
|
|
#define NCOLORS 6
|
|
|
|
|
2016-02-23 02:42:51 +00:00
|
|
|
// log mask for wxLogTrace
|
|
|
|
#define MASK_IDF "PLUGIN_IDF"
|
|
|
|
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
// read and instantiate an IDF component outline
|
2015-12-17 03:46:09 +00:00
|
|
|
static SCENEGRAPH* loadIDFOutline( const wxString& aFileName );
|
2015-12-18 08:43:27 +00:00
|
|
|
// read and render an IDF board assembly
|
2015-12-17 03:46:09 +00:00
|
|
|
static SCENEGRAPH* loadIDFBoard( const wxString& aFileName );
|
2015-12-18 08:43:27 +00:00
|
|
|
// model a single extruded outline
|
|
|
|
// idxColor = color index to use
|
|
|
|
// aParent = parent SCENEGRAPH object, if any
|
|
|
|
static SCENEGRAPH* addOutline( IDF3_COMP_OUTLINE* outline, int idxColor, SGNODE* aParent );
|
|
|
|
// model the board extrusion
|
|
|
|
static SCENEGRAPH* makeBoard( IDF3_BOARD& brd, SGNODE* aParent );
|
|
|
|
// model all included components
|
|
|
|
static bool makeComponents( IDF3_BOARD& brd, SGNODE* aParent );
|
|
|
|
// model any .OTHER_OUTLINE items
|
|
|
|
static bool makeOtherOutlines( IDF3_BOARD& brd, SGNODE* aParent );
|
|
|
|
// convert the IDF outline to VRML intermediate data
|
|
|
|
static bool getOutlineModel( VRML_LAYER& model, const std::list< IDF_OUTLINE* >* items );
|
|
|
|
// convert IDF segment data to VRML segment data
|
|
|
|
static bool addSegment( VRML_LAYER& model, IDF_SEGMENT* seg, int icont, int iseg );
|
|
|
|
// convert the VRML intermediate data into SG* data
|
|
|
|
static SCENEGRAPH* vrmlToSG( VRML_LAYER& vpcb, int idxColor, SGNODE* aParent, double top, double bottom );
|
2015-12-17 03:46:09 +00:00
|
|
|
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
class LOCALESWITCH
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LOCALESWITCH()
|
|
|
|
{
|
|
|
|
setlocale( LC_NUMERIC, "C" );
|
|
|
|
}
|
|
|
|
|
|
|
|
~LOCALESWITCH()
|
|
|
|
{
|
|
|
|
setlocale( LC_NUMERIC, "" );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static SGNODE* getColor( IFSG_SHAPE& shape, int colorIdx )
|
2015-12-16 04:11:54 +00:00
|
|
|
{
|
|
|
|
IFSG_APPEARANCE material( shape );
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
static int cidx = 1;
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
if( colorIdx == -1 )
|
|
|
|
idx = cidx;
|
|
|
|
else
|
|
|
|
idx = colorIdx;
|
2015-12-16 04:11:54 +00:00
|
|
|
|
|
|
|
switch( idx )
|
|
|
|
{
|
|
|
|
case 0:
|
2015-12-18 08:43:27 +00:00
|
|
|
// green for PCB
|
|
|
|
material.SetSpecular( 0.13, 0.81, 0.22 );
|
|
|
|
material.SetDiffuse( 0.13, 0.81, 0.22 );
|
2016-02-06 21:41:27 +00:00
|
|
|
// default ambient intensity
|
2015-12-18 08:43:27 +00:00
|
|
|
material.SetShininess( 0.3 );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2015-12-16 04:11:54 +00:00
|
|
|
// magenta
|
|
|
|
material.SetSpecular( 0.8, 0.0, 0.8 );
|
|
|
|
material.SetDiffuse( 0.6, 0.0, 0.6 );
|
2016-02-06 21:41:27 +00:00
|
|
|
// default ambient intensity
|
2015-12-16 04:11:54 +00:00
|
|
|
material.SetShininess( 0.3 );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
case 2:
|
2015-12-16 04:11:54 +00:00
|
|
|
// red
|
|
|
|
material.SetSpecular( 0.69, 0.14, 0.14 );
|
|
|
|
material.SetDiffuse( 0.69, 0.14, 0.14 );
|
2016-02-06 21:41:27 +00:00
|
|
|
// default ambient intensity
|
2015-12-16 04:11:54 +00:00
|
|
|
material.SetShininess( 0.3 );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
case 3:
|
2015-12-16 04:11:54 +00:00
|
|
|
// orange
|
|
|
|
material.SetSpecular( 1.0, 0.44, 0.0 );
|
|
|
|
material.SetDiffuse( 1.0, 0.44, 0.0 );
|
2016-02-06 21:41:27 +00:00
|
|
|
// default ambient intensity
|
2015-12-16 04:11:54 +00:00
|
|
|
material.SetShininess( 0.3 );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
case 4:
|
2015-12-16 04:11:54 +00:00
|
|
|
// yellow
|
|
|
|
material.SetSpecular( 0.93, 0.94, 0.16 );
|
|
|
|
material.SetDiffuse( 0.93, 0.94, 0.16 );
|
2016-02-06 21:41:27 +00:00
|
|
|
// default ambient intensity
|
2015-12-16 04:11:54 +00:00
|
|
|
material.SetShininess( 0.3 );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
// blue
|
|
|
|
material.SetSpecular( 0.1, 0.11, 0.88 );
|
|
|
|
material.SetDiffuse( 0.1, 0.11, 0.88 );
|
2016-02-06 21:41:27 +00:00
|
|
|
// default ambient intensity
|
2015-12-16 04:11:54 +00:00
|
|
|
material.SetShininess( 0.3 );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// violet
|
|
|
|
material.SetSpecular( 0.32, 0.07, 0.64 );
|
|
|
|
material.SetDiffuse( 0.32, 0.07, 0.64 );
|
2016-02-06 21:41:27 +00:00
|
|
|
// default ambient intensity
|
2015-12-16 04:11:54 +00:00
|
|
|
material.SetShininess( 0.3 );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
if( ( colorIdx == -1 ) && ( ++cidx > NCOLORS ) )
|
|
|
|
cidx = 1;
|
|
|
|
|
2015-12-16 04:11:54 +00:00
|
|
|
return material.GetRawPtr();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-12-14 03:51:28 +00:00
|
|
|
const char* GetKicadPluginName( void )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
return "PLUGIN_3D_IDF";
|
2015-12-10 21:34:52 +00:00
|
|
|
}
|
2015-12-13 21:45:22 +00:00
|
|
|
|
|
|
|
|
2015-12-14 22:17:10 +00:00
|
|
|
void GetPluginVersion( unsigned char* Major,
|
2015-12-14 03:51:28 +00:00
|
|
|
unsigned char* Minor, unsigned char* Patch, unsigned char* Revision )
|
2015-12-13 21:45:22 +00:00
|
|
|
{
|
|
|
|
if( Major )
|
|
|
|
*Major = PLUGIN_3D_IDF_MAJOR;
|
|
|
|
|
|
|
|
if( Minor )
|
|
|
|
*Minor = PLUGIN_3D_IDF_MINOR;
|
|
|
|
|
|
|
|
if( Patch )
|
|
|
|
*Patch = PLUGIN_3D_IDF_PATCH;
|
|
|
|
|
2015-12-14 03:51:28 +00:00
|
|
|
if( Revision )
|
|
|
|
*Revision = PLUGIN_3D_IDF_REVNO;
|
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// number of extensions supported
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define NEXTS 2
|
2015-12-17 03:46:09 +00:00
|
|
|
#else
|
|
|
|
#define NEXTS 4
|
2015-12-10 21:34:52 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
// number of filter sets supported
|
2015-12-17 03:46:09 +00:00
|
|
|
#define NFILS 2
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
static char ext0[] = "idf";
|
2015-12-17 03:46:09 +00:00
|
|
|
static char ext1[] = "emn";
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-14 03:51:28 +00:00
|
|
|
#ifdef _WIN32
|
2015-12-17 03:46:09 +00:00
|
|
|
static char fil0[] = "IDF (*.idf)|*.idf";
|
2015-12-17 09:32:24 +00:00
|
|
|
static char fil1[] = "IDF BRD v2/v3 (*.emn)|*.emn";
|
2015-12-14 03:51:28 +00:00
|
|
|
#else
|
2015-12-17 03:46:09 +00:00
|
|
|
static char ext2[] = "IDF";
|
|
|
|
static char ext3[] = "EMN";
|
|
|
|
static char fil0[] = "IDF (*.idf;*.IDF)|*.idf;*.IDF";
|
|
|
|
static char fil1[] = "IDF BRD (*.emn;*.EMN)|*.emn;*.EMN";
|
2015-12-13 21:45:22 +00:00
|
|
|
#endif
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
static struct FILE_DATA
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
char const* extensions[NEXTS];
|
|
|
|
char const* filters[NFILS];
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
FILE_DATA()
|
|
|
|
{
|
|
|
|
extensions[0] = ext0;
|
2015-12-17 03:46:09 +00:00
|
|
|
extensions[1] = ext1;
|
2015-12-13 21:45:22 +00:00
|
|
|
filters[0] = fil0;
|
2015-12-17 03:46:09 +00:00
|
|
|
filters[1] = fil1;
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
#ifndef _WIN32
|
2015-12-17 03:46:09 +00:00
|
|
|
extensions[2] = ext2;
|
|
|
|
extensions[3] = ext3;
|
2015-12-10 21:34:52 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
} file_data;
|
2015-12-10 21:34:52 +00:00
|
|
|
|
|
|
|
|
2015-12-14 03:51:28 +00:00
|
|
|
int GetNExtensions( void )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
return NEXTS;
|
2015-12-10 21:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-14 03:51:28 +00:00
|
|
|
char const* GetModelExtension( int aIndex )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
if( aIndex < 0 || aIndex >= NEXTS )
|
|
|
|
return NULL;
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
return file_data.extensions[aIndex];
|
2015-12-10 21:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-14 03:51:28 +00:00
|
|
|
int GetNFilters( void )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
return NFILS;
|
2015-12-10 21:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-14 03:51:28 +00:00
|
|
|
char const* GetFileFilter( int aIndex )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
if( aIndex < 0 || aIndex >= NFILS )
|
|
|
|
return NULL;
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-13 21:45:22 +00:00
|
|
|
return file_data.filters[aIndex];
|
2015-12-10 21:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-14 03:51:28 +00:00
|
|
|
bool CanRender( void )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
|
|
|
// this plugin supports rendering of IDF component outlines
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-14 03:51:28 +00:00
|
|
|
SCENEGRAPH* Load( char const* aFileName )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
2015-12-13 21:45:22 +00:00
|
|
|
if( NULL == aFileName )
|
|
|
|
return NULL;
|
|
|
|
|
2015-12-17 03:46:09 +00:00
|
|
|
wxFileName fname;
|
|
|
|
fname.Assign( wxString::FromUTF8Unchecked( aFileName ) );
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-17 03:46:09 +00:00
|
|
|
wxString ext = fname.GetExt();
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
SCENEGRAPH* data = NULL;
|
|
|
|
|
2015-12-17 03:46:09 +00:00
|
|
|
if( !ext.Cmp( wxT( "idf" ) ) || !ext.Cmp( wxT( "IDF" ) ) )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
2015-12-18 08:43:27 +00:00
|
|
|
data = loadIDFOutline( fname.GetFullPath() );
|
2015-12-10 21:34:52 +00:00
|
|
|
}
|
|
|
|
|
2015-12-17 03:46:09 +00:00
|
|
|
if( !ext.Cmp( wxT( "emn" ) ) || !ext.Cmp( wxT( "EMN" ) ) )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
2015-12-18 08:43:27 +00:00
|
|
|
data = loadIDFBoard( fname.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// DEBUG: WRITE OUT IDF FILE TO CONFIRM NORMALS
|
2016-01-23 05:58:22 +00:00
|
|
|
#if defined( DEBUG_IDF ) && DEBUG_IDF > 3
|
2015-12-18 08:43:27 +00:00
|
|
|
if( data )
|
|
|
|
{
|
|
|
|
wxFileName fn( aFileName );
|
2016-01-02 03:04:28 +00:00
|
|
|
wxString output = wxT( "_idf-" );
|
2016-01-02 01:21:02 +00:00
|
|
|
output.append( fn.GetName() );
|
2015-12-18 08:43:27 +00:00
|
|
|
output.append( wxT(".wrl") );
|
2016-01-29 00:52:42 +00:00
|
|
|
S3D::WriteVRML( output.ToUTF8(), true, (SGNODE*)(data), true, true );
|
2015-12-10 21:34:52 +00:00
|
|
|
}
|
2015-12-18 08:43:27 +00:00
|
|
|
#endif
|
2015-12-10 21:34:52 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
return data;
|
2015-12-10 21:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 03:46:09 +00:00
|
|
|
static bool getOutlineModel( VRML_LAYER& model, const std::list< IDF_OUTLINE* >* items )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
|
|
|
// empty outlines are not unusual so we fail quietly
|
|
|
|
if( items->size() < 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int nvcont = 0;
|
|
|
|
int iseg = 0;
|
|
|
|
|
|
|
|
std::list< IDF_OUTLINE* >::const_iterator scont = items->begin();
|
|
|
|
std::list< IDF_OUTLINE* >::const_iterator econt = items->end();
|
|
|
|
std::list<IDF_SEGMENT*>::iterator sseg;
|
|
|
|
std::list<IDF_SEGMENT*>::iterator eseg;
|
|
|
|
|
|
|
|
IDF_SEGMENT lseg;
|
|
|
|
|
|
|
|
while( scont != econt )
|
|
|
|
{
|
|
|
|
nvcont = model.NewContour();
|
|
|
|
|
|
|
|
if( nvcont < 0 )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-02-23 02:42:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
2016-09-17 06:14:49 +00:00
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] cannot create an outline";
|
2016-02-23 02:42:51 +00:00
|
|
|
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2015-12-10 21:34:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (*scont)->size() < 1 )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-02-23 02:42:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
2016-09-17 06:14:49 +00:00
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] invalid contour: no vertices";
|
2016-02-23 02:42:51 +00:00
|
|
|
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2015-12-10 21:34:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sseg = (*scont)->begin();
|
|
|
|
eseg = (*scont)->end();
|
|
|
|
|
|
|
|
iseg = 0;
|
|
|
|
while( sseg != eseg )
|
|
|
|
{
|
|
|
|
lseg = **sseg;
|
|
|
|
|
2015-12-17 03:46:09 +00:00
|
|
|
if( !addSegment( model, &lseg, nvcont, iseg ) )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-02-23 02:42:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
2016-09-17 06:14:49 +00:00
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] cannot add segment";
|
2016-02-23 02:42:51 +00:00
|
|
|
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2015-12-10 21:34:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
++iseg;
|
|
|
|
++sseg;
|
|
|
|
}
|
|
|
|
|
|
|
|
++scont;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 03:46:09 +00:00
|
|
|
static bool addSegment( VRML_LAYER& model, IDF_SEGMENT* seg, int icont, int iseg )
|
2015-12-10 21:34:52 +00:00
|
|
|
{
|
|
|
|
// note: in all cases we must add all but the last point in the segment
|
|
|
|
// to avoid redundant points
|
|
|
|
|
|
|
|
if( seg->angle != 0.0 )
|
|
|
|
{
|
|
|
|
if( seg->IsCircle() )
|
|
|
|
{
|
|
|
|
if( iseg != 0 )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-02-23 02:42:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
2016-09-17 06:14:49 +00:00
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] adding a circle to an existing vertex list";
|
2016-02-23 02:42:51 +00:00
|
|
|
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2015-12-10 21:34:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return model.AppendCircle( seg->center.x, seg->center.y, seg->radius, icont );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return model.AppendArc( seg->center.x, seg->center.y, seg->radius,
|
|
|
|
seg->offsetAngle, seg->angle, icont );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !model.AddVertex( icont, seg->startPoint.x, seg->startPoint.y ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-12-17 03:46:09 +00:00
|
|
|
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
static SCENEGRAPH* vrmlToSG( VRML_LAYER& vpcb, int idxColor, SGNODE* aParent, double top, double bottom )
|
2015-12-17 03:46:09 +00:00
|
|
|
{
|
2015-12-18 08:43:27 +00:00
|
|
|
vpcb.Tesselate( NULL );
|
|
|
|
std::vector< double > vertices;
|
|
|
|
std::vector< int > idxPlane;
|
|
|
|
std::vector< int > idxSide;
|
2015-12-17 03:46:09 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
if( top < bottom )
|
2015-12-17 03:46:09 +00:00
|
|
|
{
|
2015-12-18 08:43:27 +00:00
|
|
|
double tmp = top;
|
|
|
|
top = bottom;
|
|
|
|
bottom = tmp;
|
|
|
|
}
|
2015-12-17 03:46:09 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
if( !vpcb.Get3DTriangles( vertices, idxPlane, idxSide, top, bottom ) )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-02-23 02:42:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
2016-09-17 06:14:49 +00:00
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] no vertex data";
|
2016-02-23 02:42:51 +00:00
|
|
|
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2015-12-18 08:43:27 +00:00
|
|
|
#endif
|
2016-02-23 02:42:51 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-12-17 03:46:09 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
if( ( idxPlane.size() % 3 ) || ( idxSide.size() % 3 ) )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-02-23 02:42:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
2016-09-17 06:14:49 +00:00
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] index lists are not a multiple of 3 (not a triangle list)";
|
2016-02-23 02:42:51 +00:00
|
|
|
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2015-12-18 08:43:27 +00:00
|
|
|
#endif
|
2016-02-23 02:42:51 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-12-17 03:46:09 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
std::vector< SGPOINT > 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] ) );
|
|
|
|
|
|
|
|
// create the intermediate scenegraph
|
|
|
|
IFSG_TRANSFORM* tx0 = new IFSG_TRANSFORM( aParent ); // tx0 = Transform for this outline
|
|
|
|
IFSG_SHAPE* shape = new IFSG_SHAPE( *tx0 ); // shape will hold (a) all vertices and (b) a local list of normals
|
|
|
|
IFSG_FACESET* face = new IFSG_FACESET( *shape ); // this face shall represent the top and bottom planes
|
|
|
|
IFSG_COORDS* cp = new IFSG_COORDS( *face ); // coordinates for all faces
|
|
|
|
cp->SetCoordsList( nvert, &vlist[0] );
|
|
|
|
IFSG_COORDINDEX* coordIdx = new IFSG_COORDINDEX( *face ); // coordinate indices for top and bottom planes only
|
|
|
|
coordIdx->SetIndices( idxPlane.size(), &idxPlane[0] );
|
|
|
|
IFSG_NORMALS* norms = new IFSG_NORMALS( *face ); // normals for the top and bottom planes
|
|
|
|
|
|
|
|
// number of TOP (and bottom) vertices
|
|
|
|
j = nvert / 2;
|
|
|
|
|
|
|
|
// set the TOP normals
|
|
|
|
for( size_t i = 0; i < j; ++i )
|
|
|
|
norms->AddNormal( 0.0, 0.0, 1.0 );
|
|
|
|
|
|
|
|
// set the BOTTOM normals
|
|
|
|
for( size_t i = 0; i < j; ++i )
|
|
|
|
norms->AddNormal( 0.0, 0.0, -1.0 );
|
|
|
|
|
|
|
|
// assign a color from the palette
|
|
|
|
SGNODE* modelColor = getColor( *shape, idxColor );
|
|
|
|
|
|
|
|
// create a second shape describing the vertical walls of the IDF extrusion
|
|
|
|
// using per-vertex-per-face-normals
|
|
|
|
shape->NewNode( *tx0 );
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
size_t sidx = 0; // index to the new coord set
|
|
|
|
SGPOINT p1, p2, p3;
|
|
|
|
SGVECTOR vnorm;
|
|
|
|
|
|
|
|
while( sI != eI )
|
|
|
|
{
|
|
|
|
p1 = vlist[*sI];
|
|
|
|
cp->AddCoord( p1 );
|
|
|
|
++sI;
|
|
|
|
|
|
|
|
p2 = vlist[*sI];
|
|
|
|
cp->AddCoord( p2 );
|
|
|
|
++sI;
|
|
|
|
|
|
|
|
p3 = vlist[*sI];
|
|
|
|
cp->AddCoord( p3 );
|
|
|
|
++sI;
|
|
|
|
|
|
|
|
vnorm.SetVector( S3D::CalcTriNorm( p1, p2, p3 ) );
|
|
|
|
norms->AddNormal( vnorm );
|
|
|
|
norms->AddNormal( vnorm );
|
|
|
|
norms->AddNormal( vnorm );
|
|
|
|
|
|
|
|
coordIdx->AddIndex( (int)sidx );
|
|
|
|
++sidx;
|
|
|
|
coordIdx->AddIndex( (int)sidx );
|
|
|
|
++sidx;
|
|
|
|
coordIdx->AddIndex( (int)sidx );
|
|
|
|
++sidx;
|
|
|
|
}
|
2015-12-17 03:46:09 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
SCENEGRAPH* data = (SCENEGRAPH*)tx0->GetRawPtr();
|
2015-12-17 03:46:09 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
// delete the API wrappers
|
|
|
|
delete shape;
|
|
|
|
delete face;
|
|
|
|
delete coordIdx;
|
|
|
|
delete cp;
|
|
|
|
delete tx0;
|
2015-12-17 03:46:09 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
return data;
|
|
|
|
}
|
2015-12-17 03:46:09 +00:00
|
|
|
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
static SCENEGRAPH* addOutline( IDF3_COMP_OUTLINE* outline, int idxColor, SGNODE* aParent )
|
|
|
|
{
|
|
|
|
VRML_LAYER vpcb;
|
2015-12-17 03:46:09 +00:00
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
if( !getOutlineModel( vpcb, outline->GetOutlines() ) )
|
2015-12-17 03:46:09 +00:00
|
|
|
{
|
2015-12-18 08:43:27 +00:00
|
|
|
#ifdef DEBUG
|
2016-02-23 02:42:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
2016-09-17 06:14:49 +00:00
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] no valid outline data";
|
2016-02-23 02:42:51 +00:00
|
|
|
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2015-12-18 08:43:27 +00:00
|
|
|
#endif
|
2016-02-23 02:42:51 +00:00
|
|
|
|
2015-12-17 03:46:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-12-18 08:43:27 +00:00
|
|
|
|
|
|
|
vpcb.EnsureWinding( 0, false );
|
|
|
|
|
|
|
|
double top = outline->GetThickness();
|
|
|
|
double bot = 0.0;
|
|
|
|
|
|
|
|
// note: some IDF entities permit negative heights
|
|
|
|
if( top < bot )
|
|
|
|
{
|
|
|
|
bot = top;
|
|
|
|
top = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCENEGRAPH* data = vrmlToSG( vpcb, idxColor, aParent, top, bot );
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SCENEGRAPH* loadIDFOutline( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
LOCALESWITCH switcher;
|
|
|
|
IDF3_BOARD brd( IDF3::CAD_ELEC );
|
|
|
|
IDF3_COMP_OUTLINE* outline = NULL;
|
|
|
|
|
|
|
|
outline = brd.GetComponentOutline( aFileName );
|
|
|
|
|
|
|
|
if( NULL == outline )
|
2015-12-17 03:46:09 +00:00
|
|
|
{
|
2015-12-18 08:43:27 +00:00
|
|
|
#ifdef DEBUG
|
2016-02-23 02:42:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
2016-09-17 06:14:49 +00:00
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] Failed to read IDF data:\n";
|
|
|
|
ostr << brd.GetError() << "\n\n";
|
|
|
|
ostr << " * [INFO] no outline for file '";
|
|
|
|
ostr << aFileName << "'";
|
2016-02-23 02:42:51 +00:00
|
|
|
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2015-12-18 08:43:27 +00:00
|
|
|
#endif
|
2016-02-23 02:42:51 +00:00
|
|
|
|
2015-12-17 03:46:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-18 08:43:27 +00:00
|
|
|
SCENEGRAPH* data = addOutline( outline, -1, NULL );
|
2015-12-17 03:46:09 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SCENEGRAPH* loadIDFBoard( const wxString& aFileName )
|
|
|
|
{
|
2015-12-18 08:43:27 +00:00
|
|
|
LOCALESWITCH switcher;
|
|
|
|
IDF3_BOARD brd( IDF3::CAD_ELEC );
|
|
|
|
|
|
|
|
// note: if the IDF model is defective no outline substitutes shall be made
|
|
|
|
if( !brd.ReadFile( aFileName, true ) )
|
|
|
|
{
|
2016-01-12 07:03:17 +00:00
|
|
|
#ifdef DEBUG
|
2016-02-23 02:42:51 +00:00
|
|
|
do {
|
|
|
|
std::ostringstream ostr;
|
2016-09-17 06:14:49 +00:00
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [INFO] Failed to read IDF file:\n";
|
|
|
|
ostr << brd.GetError() << "\n\n";
|
|
|
|
ostr << " * [INFO] IDF file '" << aFileName.ToUTF8() << "'";
|
2016-02-23 02:42:51 +00:00
|
|
|
wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() );
|
|
|
|
} while( 0 );
|
2016-01-12 07:03:17 +00:00
|
|
|
#endif
|
2015-12-18 08:43:27 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFSG_TRANSFORM tx0( true );
|
|
|
|
SGNODE* topNode = tx0.GetRawPtr();
|
|
|
|
|
|
|
|
bool noBoard = false;
|
|
|
|
bool noComp = false;
|
|
|
|
bool noOther = false;
|
|
|
|
|
|
|
|
if( NULL == makeBoard( brd, topNode ) )
|
|
|
|
noBoard = true;
|
|
|
|
|
|
|
|
if( !makeComponents( brd, topNode ) )
|
|
|
|
noComp = true;
|
|
|
|
|
|
|
|
if( !makeOtherOutlines( brd, topNode ) )
|
|
|
|
noOther = true;
|
|
|
|
|
|
|
|
if( noBoard && noComp && noOther )
|
|
|
|
{
|
|
|
|
tx0.Destroy();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (SCENEGRAPH*) topNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SCENEGRAPH* makeBoard( IDF3_BOARD& brd, SGNODE* aParent )
|
|
|
|
{
|
|
|
|
if( NULL == aParent )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
VRML_LAYER vpcb;
|
|
|
|
|
|
|
|
// check if no board outline
|
|
|
|
if( brd.GetBoardOutlinesSize() < 1 )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if( !getOutlineModel( vpcb, brd.GetBoardOutline()->GetOutlines() ) )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vpcb.EnsureWinding( 0, false );
|
|
|
|
|
|
|
|
int nvcont = vpcb.GetNContours() - 1;
|
|
|
|
|
|
|
|
while( nvcont > 0 )
|
|
|
|
vpcb.EnsureWinding( nvcont--, true );
|
|
|
|
|
|
|
|
// Add the drill holes
|
|
|
|
const std::list<IDF_DRILL_DATA*>* drills = &brd.GetBoardDrills();
|
|
|
|
|
|
|
|
std::list<IDF_DRILL_DATA*>::const_iterator sd = drills->begin();
|
|
|
|
std::list<IDF_DRILL_DATA*>::const_iterator ed = drills->end();
|
|
|
|
|
|
|
|
while( sd != ed )
|
|
|
|
{
|
|
|
|
vpcb.AddCircle( (*sd)->GetDrillXPos(), (*sd)->GetDrillYPos(),
|
|
|
|
(*sd)->GetDrillDia() / 2.0, true );
|
|
|
|
++sd;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map< std::string, IDF3_COMPONENT* >*const comp = brd.GetComponents();
|
|
|
|
std::map< std::string, IDF3_COMPONENT* >::const_iterator sc = comp->begin();
|
|
|
|
std::map< std::string, IDF3_COMPONENT* >::const_iterator ec = comp->end();
|
|
|
|
|
|
|
|
while( sc != ec )
|
|
|
|
{
|
|
|
|
drills = sc->second->GetDrills();
|
|
|
|
sd = drills->begin();
|
|
|
|
ed = drills->end();
|
|
|
|
|
|
|
|
while( sd != ed )
|
|
|
|
{
|
|
|
|
vpcb.AddCircle( (*sd)->GetDrillXPos(), (*sd)->GetDrillYPos(),
|
|
|
|
(*sd)->GetDrillDia() / 2.0, true );
|
|
|
|
++sd;
|
|
|
|
}
|
|
|
|
|
|
|
|
++sc;
|
|
|
|
}
|
|
|
|
|
|
|
|
double top = brd.GetBoardThickness();
|
|
|
|
|
|
|
|
SCENEGRAPH* data = vrmlToSG( vpcb, 0, aParent, top, 0.0 );
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool makeComponents( IDF3_BOARD& brd, SGNODE* aParent )
|
|
|
|
{
|
|
|
|
if( NULL == aParent )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int ncomponents = 0;
|
|
|
|
|
|
|
|
double brdTop = brd.GetBoardThickness();
|
|
|
|
|
|
|
|
// Add the component outlines
|
|
|
|
const std::map< std::string, IDF3_COMPONENT* >*const comp = brd.GetComponents();
|
|
|
|
std::map< std::string, IDF3_COMPONENT* >::const_iterator sc = comp->begin();
|
|
|
|
std::map< std::string, IDF3_COMPONENT* >::const_iterator ec = comp->end();
|
|
|
|
|
|
|
|
std::list< IDF3_COMP_OUTLINE_DATA* >::const_iterator so;
|
|
|
|
std::list< IDF3_COMP_OUTLINE_DATA* >::const_iterator eo;
|
|
|
|
|
|
|
|
double vX, vY, vA;
|
|
|
|
double tX, tY, tZ, tA;
|
|
|
|
bool bottom;
|
|
|
|
IDF3::IDF_LAYER lyr;
|
|
|
|
|
|
|
|
std::map< std::string, SGNODE* > dataMap; // map data by UID
|
|
|
|
std::map< std::string, SGNODE* >::iterator dataItem;
|
|
|
|
IDF3_COMP_OUTLINE* pout;
|
|
|
|
|
|
|
|
while( sc != ec )
|
|
|
|
{
|
|
|
|
sc->second->GetPosition( vX, vY, vA, lyr );
|
|
|
|
|
|
|
|
if( lyr == IDF3::LYR_BOTTOM )
|
|
|
|
bottom = true;
|
|
|
|
else
|
|
|
|
bottom = false;
|
|
|
|
|
|
|
|
so = sc->second->GetOutlinesData()->begin();
|
|
|
|
eo = sc->second->GetOutlinesData()->end();
|
|
|
|
|
|
|
|
while( so != eo )
|
|
|
|
{
|
2016-02-29 23:08:19 +00:00
|
|
|
if( std::abs( (*so)->GetOutline()->GetThickness() ) < 0.001 )
|
2015-12-18 08:43:27 +00:00
|
|
|
{
|
|
|
|
++so;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*so)->GetOffsets( tX, tY, tZ, tA );
|
|
|
|
tX += vX;
|
|
|
|
tY += vY;
|
|
|
|
tA += vA;
|
|
|
|
|
|
|
|
pout = (IDF3_COMP_OUTLINE*)((*so)->GetOutline());
|
|
|
|
|
|
|
|
if( NULL == pout )
|
|
|
|
{
|
|
|
|
++so;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dataItem = dataMap.find( pout->GetUID() );
|
|
|
|
SCENEGRAPH* sg = NULL;
|
|
|
|
|
|
|
|
if( dataItem == dataMap.end() )
|
|
|
|
{
|
|
|
|
sg = addOutline( pout, -1, NULL );
|
|
|
|
|
|
|
|
if( NULL == sg )
|
|
|
|
{
|
|
|
|
++so;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++ncomponents;
|
|
|
|
dataMap.insert( std::pair< std::string, SGNODE* >
|
|
|
|
( pout->GetUID(), (SGNODE*)sg ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sg = (SCENEGRAPH*) dataItem->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFSG_TRANSFORM tx0( aParent );
|
|
|
|
IFSG_TRANSFORM txN( false );
|
|
|
|
txN.Attach( (SGNODE*)sg );
|
|
|
|
|
|
|
|
if( NULL == txN.GetParent() )
|
|
|
|
tx0.AddChildNode( txN );
|
|
|
|
else
|
|
|
|
tx0.AddRefNode( txN );
|
|
|
|
|
|
|
|
if( bottom )
|
|
|
|
{
|
|
|
|
tx0.SetTranslation( SGPOINT( tX, tY, -tZ ) );
|
|
|
|
// for an item on the back of the board we have a compounded rotation,
|
|
|
|
// first a flip on the Y axis as per the IDF spec and then a rotation
|
|
|
|
// of -tA degrees on the Z axis. The resultant rotation axis is an
|
|
|
|
// XY vector equivalent to (0,1) rotated by -(tA/2) degrees
|
|
|
|
//
|
|
|
|
double ang = -tA * M_PI / 360.0;
|
|
|
|
double sinA = sin( ang );
|
|
|
|
double cosA = cos( ang );
|
|
|
|
tx0.SetRotation( SGVECTOR( -sinA, cosA , 0 ), M_PI );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tx0.SetTranslation( SGPOINT( tX, tY, tZ + brdTop ) );
|
|
|
|
tx0.SetRotation( SGVECTOR( 0, 0, 1 ), tA * M_PI / 180.0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
++so;
|
|
|
|
}
|
|
|
|
|
|
|
|
++sc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( 0 == ncomponents )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool makeOtherOutlines( IDF3_BOARD& brd, SGNODE* aParent )
|
|
|
|
{
|
|
|
|
if( NULL == aParent )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
VRML_LAYER vpcb;
|
|
|
|
int ncomponents = 0;
|
|
|
|
|
|
|
|
double brdTop = brd.GetBoardThickness();
|
|
|
|
double top, bot;
|
|
|
|
|
|
|
|
// Add the component outlines
|
|
|
|
const std::map< std::string, OTHER_OUTLINE* >*const comp = brd.GetOtherOutlines();
|
|
|
|
std::map< std::string, OTHER_OUTLINE* >::const_iterator sc = comp->begin();
|
|
|
|
std::map< std::string, OTHER_OUTLINE* >::const_iterator ec = comp->end();
|
|
|
|
|
|
|
|
int nvcont;
|
|
|
|
|
|
|
|
OTHER_OUTLINE* pout;
|
|
|
|
|
|
|
|
while( sc != ec )
|
|
|
|
{
|
|
|
|
pout = sc->second;
|
|
|
|
|
2016-02-29 23:08:19 +00:00
|
|
|
if( std::abs( pout->GetThickness() ) < 0.001 )
|
2015-12-18 08:43:27 +00:00
|
|
|
{
|
|
|
|
++sc;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !getOutlineModel( vpcb, pout->GetOutlines() ) )
|
|
|
|
{
|
|
|
|
vpcb.Clear();
|
|
|
|
++sc;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
vpcb.EnsureWinding( 0, false );
|
|
|
|
|
|
|
|
nvcont = vpcb.GetNContours() - 1;
|
|
|
|
|
|
|
|
while( nvcont > 0 )
|
|
|
|
vpcb.EnsureWinding( nvcont--, true );
|
|
|
|
|
|
|
|
if( pout->GetSide() == IDF3::LYR_BOTTOM )
|
|
|
|
{
|
|
|
|
top = 0.0;
|
|
|
|
bot = -pout->GetThickness();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bot = brdTop;
|
|
|
|
top = bot + pout->GetThickness();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( NULL == vrmlToSG( vpcb, -1, aParent, top, bot ) )
|
|
|
|
{
|
|
|
|
vpcb.Clear();
|
|
|
|
++sc;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++ncomponents;
|
|
|
|
|
|
|
|
vpcb.Clear();
|
|
|
|
++sc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( 0 == ncomponents )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2015-12-17 03:46:09 +00:00
|
|
|
}
|