diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp index ed79df20cc..a2930dfb8c 100644 --- a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp +++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp @@ -133,7 +133,9 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, bool hasFileSelector ) : if( hasFileSelector ) { hboxDirChoice = new wxBoxSizer( wxHORIZONTAL ); - dirChoices = new wxChoice( this, ID_SET_DIR ); + dirChoices = new wxChoice( this, ID_SET_DIR, wxDefaultPosition, + wxSize( 320, 20 ) ); + dirChoices->SetMinSize( wxSize( 320, 12 ) ); #ifdef _WIN32 // Note: On Win32 the native selector box will truncate text diff --git a/3d-viewer/3d_cache/sg/CMakeLists.txt b/3d-viewer/3d_cache/sg/CMakeLists.txt index 9ecf034c56..45be0fb426 100644 --- a/3d-viewer/3d_cache/sg/CMakeLists.txt +++ b/3d-viewer/3d_cache/sg/CMakeLists.txt @@ -1,6 +1,5 @@ include_directories( ${CMAKE_SOURCE_DIR}/include -# ${CMAKE_SOURCE_DIR}/include/gal/opengl ${CMAKE_SOURCE_DIR}/3d-viewer ) diff --git a/plugins/3d/CMakeLists.txt b/plugins/3d/CMakeLists.txt index b2274e9ce6..918c1b6188 100644 --- a/plugins/3d/CMakeLists.txt +++ b/plugins/3d/CMakeLists.txt @@ -1,31 +1,3 @@ -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} -) - -add_library( s3d_plugin_dummy MODULE - s3d_plugin_dummy.cpp - ) - -target_link_libraries( s3d_plugin_dummy ${wxWidgets_LIBRARIES} ) - -add_library( s3d_plugin_tetra MODULE - s3d_plugin_tetra.cpp - ) - -target_link_libraries( s3d_plugin_tetra s3d_sg ${wxWidgets_LIBRARIES} ) - -if( APPLE ) - install( TARGETS - s3d_plugin_dummy - s3d_plugin_tetra - DESTINATION /Applications/kicad.app/SharedSupport/plugins/3d - COMPONENT binary - ) -else() - install( TARGETS - s3d_plugin_dummy - s3d_plugin_tetra - DESTINATION lib/kicad/plugins/3d - COMPONENT binary - ) -endif() +add_subdirectory( dummy ) +add_subdirectory( tetra ) +add_subdirectory( idf ) diff --git a/plugins/3d/dummy/CMakeLists.txt b/plugins/3d/dummy/CMakeLists.txt new file mode 100644 index 0000000000..6974d1bee2 --- /dev/null +++ b/plugins/3d/dummy/CMakeLists.txt @@ -0,0 +1,23 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_library( s3d_plugin_dummy MODULE + s3d_plugin_dummy.cpp + ) + +target_link_libraries( s3d_plugin_dummy ${wxWidgets_LIBRARIES} ) + +if( APPLE ) + install( TARGETS + s3d_plugin_dummy + DESTINATION /Applications/kicad.app/SharedSupport/plugins/3d + COMPONENT binary + ) +else() + install( TARGETS + s3d_plugin_dummy + DESTINATION lib/kicad/plugins/3d + COMPONENT binary + ) +endif() diff --git a/plugins/3d/s3d_plugin_dummy.cpp b/plugins/3d/dummy/s3d_plugin_dummy.cpp similarity index 100% rename from plugins/3d/s3d_plugin_dummy.cpp rename to plugins/3d/dummy/s3d_plugin_dummy.cpp diff --git a/plugins/3d/s3d_plugin_dummy.h b/plugins/3d/dummy/s3d_plugin_dummy.h similarity index 100% rename from plugins/3d/s3d_plugin_dummy.h rename to plugins/3d/dummy/s3d_plugin_dummy.h diff --git a/plugins/3d/idf/CMakeLists.txt b/plugins/3d/idf/CMakeLists.txt new file mode 100644 index 0000000000..70087dee62 --- /dev/null +++ b/plugins/3d/idf/CMakeLists.txt @@ -0,0 +1,28 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/utils/idftools +) + +add_library( s3d_plugin_idf MODULE + s3d_plugin_idf.cpp + ${CMAKE_SOURCE_DIR}/utils/idftools/vrml_layer.cpp + ) + +set_target_properties( s3d_plugin_idf PROPERTIES + LINK_FLAGS -L${CMAKE_BINARY_DIR}/utils/idftools ) + +target_link_libraries( s3d_plugin_idf s3d_sg idf3 ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} ) + +if( APPLE ) + install( TARGETS + s3d_plugin_idf + DESTINATION /Applications/kicad.app/SharedSupport/plugins/3d + COMPONENT binary + ) +else() + install( TARGETS + s3d_plugin_idf + DESTINATION lib/kicad/plugins/3d + COMPONENT binary + ) +endif() diff --git a/plugins/3d/idf/s3d_plugin_idf.cpp b/plugins/3d/idf/s3d_plugin_idf.cpp new file mode 100644 index 0000000000..3e62209b3d --- /dev/null +++ b/plugins/3d/idf/s3d_plugin_idf.cpp @@ -0,0 +1,272 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2015 Cirilo Bernardo + * + * 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 + */ + +#include +#include +#include +#include +#include "s3d_plugin_idf.h" +#include "plugins/3dapi/ifsg_all.h" +#include "idf_parser.h" +#include "vrml_layer.h" + + +static S3D_PLUGIN_IDF idf_plugin; + +#ifndef _WIN32 +extern "C" __attribute__((__visibility__("default"))) S3D_PLUGIN* Get3DPlugin( void ) +{ + return &idf_plugin; +} +#else +extern "C" __declspec( dllexport ) S3D_PLUGIN* Get3DPlugin( void ) + { + return &idf_plugin; + } +#endif + + +static bool PopulateVRML( VRML_LAYER& model, const std::list< IDF_OUTLINE* >* items ); +static bool AddSegment( VRML_LAYER& model, IDF_SEGMENT* seg, int icont, int iseg ); + + +S3D_PLUGIN_IDF::S3D_PLUGIN_IDF() +{ + m_extensions.push_back( wxString::FromUTF8Unchecked( "idf" ) ); + +#ifdef _WIN32 + // assume a case-insensitive file system + m_filters.push_back( wxT( "IDF 2.0/3.0 (*.idf)|*.idf" ) ); +#else + // assume the filesystem is case sensitive + m_extensions.push_back( wxString::FromUTF8Unchecked( "IDF" ) ); + + m_filters.push_back( wxT( "IDF 2.0/3.0 (*.idf;*.IDF)|*.idf;*.IDF" ) ); +#endif + + + return; +} + + +S3D_PLUGIN_IDF::~S3D_PLUGIN_IDF() +{ + return; +} + + +int S3D_PLUGIN_IDF::GetNExtensions( void ) const +{ + return (int) m_extensions.size(); +} + + +const wxString S3D_PLUGIN_IDF::GetModelExtension( int aIndex ) const +{ + if( aIndex < 0 || aIndex >= (int) m_extensions.size() ) + return wxString( "" ); + + return m_extensions[aIndex]; +} + + +int S3D_PLUGIN_IDF::GetNFilters( void ) const +{ + return (int)m_filters.size(); +} + + +const wxString S3D_PLUGIN_IDF::GetFileFilter( int aIndex ) const +{ + if( aIndex < 0 || aIndex >= m_filters.size() ) + return wxEmptyString; + + return m_filters[aIndex]; +} + + +bool S3D_PLUGIN_IDF::CanRender( void ) const +{ + // this plugin supports rendering of IDF component outlines + return true; +} + + +SCENEGRAPH* S3D_PLUGIN_IDF::Load( const wxString& aFileName ) +{ + // load and render the file + #warning TO BE IMPLEMENTED + IDF3_BOARD brd( IDF3::CAD_ELEC ); + IDF3_COMP_OUTLINE* outline = brd.GetComponentOutline( aFileName ); + + if( NULL == outline ) + return NULL; + + // render the component outline + const std::map< std::string, IDF3_COMPONENT* >*const comp = brd.GetComponents(); + size_t asize = comp->size(); + + if( 1 != asize ) + { + #ifdef DEBUG + std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + std::cerr << " * [INFO] unexpected number of components: " << asize << "\n"; + #endif + return NULL; + } + + const std::list< IDF3_COMP_OUTLINE_DATA* >* + ip = comp[0].begin()->second->GetOutlinesData(); + + asize = ip->size(); + + if( 1 != asize ) + { + #ifdef DEBUG + std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + std::cerr << " * [INFO] unexpected number of outlines: " << asize << "\n"; + #endif + return NULL; + } + + IDF3_COMP_OUTLINE_DATA* dp = *( ip->begin() ); + IDF3_COMP_OUTLINE* pout = (IDF3_COMP_OUTLINE*)( dp->GetOutline() ); + VRML_LAYER vpcb; + + if( !PopulateVRML( vpcb, pout->GetOutlines() ) ) + { + #ifdef DEBUG + std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + std::cerr << " * [INFO] no valid outline data\n"; + #endif + return NULL; + } + + // XXX - TO BE IMPLEMENTED + + return NULL; +} + + +static bool PopulateVRML( VRML_LAYER& model, const std::list< IDF_OUTLINE* >* items ) +{ + // 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::iterator sseg; + std::list::iterator eseg; + + IDF_SEGMENT lseg; + + while( scont != econt ) + { + nvcont = model.NewContour(); + + if( nvcont < 0 ) + { + #ifdef DEBUG + std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + std::cerr << " * [INFO] cannot create an outline\n"; + #endif + + return false; + } + + if( (*scont)->size() < 1 ) + { + #ifdef DEBUG + std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + std::cerr << " * [INFO] invalid contour: no vertices\n"; + #endif + + return false; + } + + sseg = (*scont)->begin(); + eseg = (*scont)->end(); + + iseg = 0; + while( sseg != eseg ) + { + lseg = **sseg; + + if( !AddSegment( model, &lseg, nvcont, iseg ) ) + { + #ifdef DEBUG + std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + std::cerr << " * [BUG] cannot add segment\n"; + #endif + + return false; + } + + ++iseg; + ++sseg; + } + + ++scont; + } + + return true; +} + + +static bool AddSegment( VRML_LAYER& model, IDF_SEGMENT* seg, int icont, int iseg ) +{ + // 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 + std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; + std::cerr << " * [INFO] adding a circle to an existing vertex list\n"; + #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; +} diff --git a/plugins/3d/idf/s3d_plugin_idf.h b/plugins/3d/idf/s3d_plugin_idf.h new file mode 100644 index 0000000000..8f52412d6a --- /dev/null +++ b/plugins/3d/idf/s3d_plugin_idf.h @@ -0,0 +1,57 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2015 Cirilo Bernardo + * + * 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 + */ + +/** + * @file 3d_plugin_idf.h + * is a 3D plugin to support the rendering of IDF component outlines + */ + + +#ifndef PLUGIN_3D_IDF_H +#define PLUGIN_3D_IDF_H + +#include +#include + +class SCENEGRAPH; + +class S3D_PLUGIN_IDF : public S3D_PLUGIN +{ +private: + std::vector< wxString > m_extensions; // supported extensions + std::vector< wxString > m_filters; // file filters + +public: + S3D_PLUGIN_IDF(); + virtual ~S3D_PLUGIN_IDF(); + + virtual int GetNExtensions( void ) const; + virtual const wxString GetModelExtension( int aIndex ) const; + virtual int GetNFilters( void ) const; + virtual const wxString GetFileFilter( int aIndex ) const; + + bool CanRender( void ) const; + SCENEGRAPH* Load( const wxString& aFileName ); +}; + +#endif // PLUGIN_3D_IDF_H diff --git a/plugins/3d/tetra/CMakeLists.txt b/plugins/3d/tetra/CMakeLists.txt new file mode 100644 index 0000000000..e121b63b1d --- /dev/null +++ b/plugins/3d/tetra/CMakeLists.txt @@ -0,0 +1,23 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_library( s3d_plugin_tetra MODULE + s3d_plugin_tetra.cpp + ) + +target_link_libraries( s3d_plugin_tetra s3d_sg ${wxWidgets_LIBRARIES} ) + +if( APPLE ) + install( TARGETS + s3d_plugin_tetra + DESTINATION /Applications/kicad.app/SharedSupport/plugins/3d + COMPONENT binary + ) +else() + install( TARGETS + s3d_plugin_tetra + DESTINATION lib/kicad/plugins/3d + COMPONENT binary + ) +endif() diff --git a/plugins/3d/s3d_plugin_tetra.cpp b/plugins/3d/tetra/s3d_plugin_tetra.cpp similarity index 98% rename from plugins/3d/s3d_plugin_tetra.cpp rename to plugins/3d/tetra/s3d_plugin_tetra.cpp index d4b6890a23..de21917c7d 100644 --- a/plugins/3d/s3d_plugin_tetra.cpp +++ b/plugins/3d/tetra/s3d_plugin_tetra.cpp @@ -21,14 +21,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/* - * NOTES: - * - * 1. Notice that the plugin class is instantiated as a static; this - * ensures that it is created an destroyed. - */ - -#include #include #include #include diff --git a/plugins/3d/s3d_plugin_tetra.h b/plugins/3d/tetra/s3d_plugin_tetra.h similarity index 100% rename from plugins/3d/s3d_plugin_tetra.h rename to plugins/3d/tetra/s3d_plugin_tetra.h