├── README.md ├── CMakeModules ├── CheckFindPackageResult.cmake ├── cmake_uninstall.cmake.in ├── MinGWResourceCompiler.cmake ├── FindGLM.cmake ├── Functions.cmake └── UsewxWidgets.cmake ├── include └── plugins │ └── 3dapi │ ├── sg_version.h │ ├── ifsg_all.h │ ├── sg_types.h │ ├── ifsg_shape.h │ ├── ifsg_coordindex.h │ ├── ifsg_faceset.h │ ├── xv3d_types.h │ ├── ifsg_coords.h │ ├── ifsg_colors.h │ ├── ifsg_normals.h │ ├── ifsg_defs.h │ ├── ifsg_transform.h │ ├── ifsg_index.h │ ├── ifsg_appearance.h │ ├── sg_base.h │ ├── c3dmodel.h │ ├── ifsg_node.h │ └── ifsg_api.h └── scenegraph └── 3d_cache └── sg ├── sg_coordindex.cpp ├── sg_coordindex.h ├── sg_colors.h ├── sg_normals.h ├── sg_coords.h ├── sg_shape.h ├── CMakeLists.txt ├── ifsg_index.cpp ├── sg_appearance.h ├── sg_index.h ├── sg_faceset.h ├── scenegraph.h ├── ifsg_coordindex.cpp ├── ifsg_shape.cpp ├── ifsg_faceset.cpp ├── ifsg_coords.cpp ├── ifsg_colors.cpp ├── ifsg_normals.cpp ├── ifsg_transform.cpp ├── ifsg_node.cpp ├── sg_base.cpp ├── sg_node.h ├── sg_normals.cpp ├── sg_helpers.h ├── sg_colors.cpp ├── sg_index.cpp └── sg_coords.cpp /README.md: -------------------------------------------------------------------------------- 1 | This project is experimental code intended to result in a 2 | KiCad 3D plugin to visualize IGES and STEP solid models 3 | via the OpenCascade framework. 4 | 5 | -------------------------------------------------------------------------------- /CMakeModules/CheckFindPackageResult.cmake: -------------------------------------------------------------------------------- 1 | macro(check_find_package_result _VAR _PKGNAME) 2 | if(${_VAR}) 3 | message(STATUS "Check for installed ${_PKGNAME} -- found") 4 | else(${_VAR}) 5 | message(STATUS "Check for installed ${_PKGNAME} -- not found") 6 | message(FATAL_ERROR "${_PKGNAME} was not found - it is required to build Kicad") 7 | endif(${_VAR}) 8 | endmacro(check_find_package_result) 9 | -------------------------------------------------------------------------------- /CMakeModules/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if( NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" ) 2 | message( FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"" ) 3 | endif() 4 | 5 | file( READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files ) 6 | string( REGEX REPLACE "\n" ";" files "${files}" ) 7 | 8 | foreach( file ${files} ) 9 | message( STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"" ) 10 | if( EXISTS "$ENV{DESTDIR}${file}" ) 11 | exec_program( 12 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 13 | OUTPUT_VARIABLE rm_out 14 | RETURN_VALUE rm_retval 15 | ) 16 | if( NOT "${rm_retval}" STREQUAL "0" ) 17 | message( STATUS "Problem when removing \"$ENV{DESTDIR}${file}\"" ) 18 | endif() 19 | else() 20 | message( STATUS "File \"$ENV{DESTDIR}${file}\" does not exist." ) 21 | endif() 22 | endforeach() 23 | -------------------------------------------------------------------------------- /include/plugins/3dapi/sg_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2016 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_version.h 26 | * defines the library version of the intermediate scenegraph (SG) 27 | * implementation 28 | */ 29 | 30 | #ifndef SG_VERSION_H 31 | #define SG_VERSION_H 32 | 33 | #define KICADSG_VERSION_MAJOR 2 34 | #define KICADSG_VERSION_MINOR 0 35 | #define KICADSG_VERSION_PATCH 0 36 | #define KICADSG_VERSION_REVISION 0 37 | 38 | #endif // SG_VERSION_H 39 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_all.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_all.h 26 | * collects header files for all SG* wrappers and the API 27 | */ 28 | 29 | #include "plugins/3dapi/ifsg_transform.h" 30 | #include "plugins/3dapi/ifsg_appearance.h" 31 | #include "plugins/3dapi/ifsg_colors.h" 32 | #include "plugins/3dapi/ifsg_coords.h" 33 | #include "plugins/3dapi/ifsg_faceset.h" 34 | #include "plugins/3dapi/ifsg_coordindex.h" 35 | #include "plugins/3dapi/ifsg_normals.h" 36 | #include "plugins/3dapi/ifsg_shape.h" 37 | #include "plugins/3dapi/ifsg_api.h" 38 | -------------------------------------------------------------------------------- /include/plugins/3dapi/sg_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_types.h 26 | * defines the types of intermediate scene graph objects 27 | */ 28 | 29 | #ifndef SG_TYPES_H 30 | #define SG_TYPES_H 31 | 32 | namespace S3D 33 | { 34 | enum SGTYPES 35 | { 36 | SGTYPE_TRANSFORM = 0, 37 | SGTYPE_APPEARANCE, 38 | SGTYPE_COLORS, 39 | SGTYPE_COLORINDEX, 40 | SGTYPE_FACESET, 41 | SGTYPE_COORDS, 42 | SGTYPE_COORDINDEX, 43 | SGTYPE_NORMALS, 44 | SGTYPE_SHAPE, 45 | SGTYPE_END 46 | }; 47 | }; 48 | 49 | #endif // SG_TYPES_H 50 | -------------------------------------------------------------------------------- /CMakeModules/MinGWResourceCompiler.cmake: -------------------------------------------------------------------------------- 1 | # resource compilation for mingw (http://www.cmake.org/Bug/view.php?id=4068) 2 | 3 | macro(dbg_msg _MSG) 4 | # message(STATUS "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}") 5 | endmacro(dbg_msg) 6 | 7 | macro(mingw_resource_compiler _NAME) 8 | # Resource compiler name. 9 | if(NOT DEFINED CMAKE_RC_COMPILER) 10 | set(CMAKE_RC_COMPILER windres.exe) 11 | endif(NOT DEFINED CMAKE_RC_COMPILER) 12 | dbg_msg("CMAKE_RC_COMPILER: ${CMAKE_RC_COMPILER}") 13 | 14 | # Input file. 15 | set(_IN "${CMAKE_CURRENT_SOURCE_DIR}/${_NAME}.rc") 16 | dbg_msg("_IN: ${_IN}") 17 | 18 | # Output file. 19 | set(_OUT "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_NAME}.dir/${_NAME}_rc.obj") 20 | dbg_msg("_OUT: ${_OUT}") 21 | 22 | # Include directories. 23 | set(_WINDRES_INCLUDE_DIRS -I${CMAKE_CURRENT_SOURCE_DIR}) 24 | foreach(wx_include_dir ${wxWidgets_INCLUDE_DIRS}) 25 | set(_WINDRES_INCLUDE_DIRS ${_WINDRES_INCLUDE_DIRS} -I${wx_include_dir}) 26 | endforeach(wx_include_dir ${wxWidgets_INCLUDE_DIRS}) 27 | dbg_msg("_WINDRES_INCLUDE_DIRS: ${_WINDRES_INCLUDE_DIRS}") 28 | 29 | # windres arguments. 30 | set(_ARGS ${_WINDRES_INCLUDE_DIRS} -i${_IN} -o${_OUT}) 31 | dbg_msg("_ARGS: ${_ARGS}") 32 | 33 | # Compile resource file. 34 | add_custom_command(OUTPUT ${_OUT} 35 | COMMAND ${CMAKE_RC_COMPILER} 36 | ARGS ${_ARGS} 37 | COMMENT "Compiling ${_NAME}'s resource file" 38 | VERBATIM) 39 | 40 | # Set a NAME_RESOURCES variable 41 | string(TOUPPER ${_NAME} _NAME_UPPER) 42 | set(${_NAME_UPPER}_RESOURCES ${_OUT}) 43 | dbg_msg("${_NAME_UPPER}_RESOURCES: ${${_NAME_UPPER}_RESOURCES}") 44 | endmacro(mingw_resource_compiler) 45 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_shape.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_shape.h 26 | * defines the wrapper for the SGSHAPE class 27 | */ 28 | 29 | 30 | #ifndef IFSG_SHAPE_H 31 | #define IFSG_SHAPE_H 32 | 33 | #include "plugins/3dapi/ifsg_node.h" 34 | 35 | 36 | /** 37 | * Class IFSG_SHAPE 38 | * is the wrapper for the SGSHAPE class 39 | */ 40 | class SGLIB_API IFSG_SHAPE : public IFSG_NODE 41 | { 42 | public: 43 | IFSG_SHAPE( bool create ); 44 | IFSG_SHAPE( SGNODE* aParent ); 45 | IFSG_SHAPE( IFSG_NODE& aParent ); 46 | 47 | bool Attach( SGNODE* aNode ); 48 | bool NewNode( SGNODE* aParent ); 49 | bool NewNode( IFSG_NODE& aParent ); 50 | }; 51 | 52 | #endif // IFSG_SHAPE_H 53 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_coordindex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | #include "3d_cache/sg/sg_coordindex.h" 25 | 26 | 27 | SGCOORDINDEX::SGCOORDINDEX( SGNODE* aParent ) : SGINDEX( aParent ) 28 | { 29 | m_SGtype = S3D::SGTYPE_COORDINDEX; 30 | 31 | if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() ) 32 | { 33 | m_Parent->AddChildNode( this ); 34 | } 35 | 36 | return; 37 | } 38 | 39 | 40 | SGCOORDINDEX::~SGCOORDINDEX() 41 | { 42 | return; 43 | } 44 | 45 | 46 | void SGCOORDINDEX::GatherCoordIndices( std::vector< int >& aIndexList ) 47 | { 48 | if( index.empty() ) 49 | return; 50 | 51 | aIndexList.insert( aIndexList.end(), index.begin(), index.end() ); 52 | 53 | return; 54 | } 55 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_coordindex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_coordindex.h 26 | * defines the CoordIndex node wrapper 27 | */ 28 | 29 | 30 | #ifndef IFSG_COORDINDEX_H 31 | #define IFSG_COORDINDEX_H 32 | 33 | #include "plugins/3dapi/ifsg_index.h" 34 | 35 | 36 | /** 37 | * Class IFSG_COORDINDEX 38 | * is the wrapper for SGCOORDINDEX 39 | */ 40 | class SGLIB_API IFSG_COORDINDEX : public IFSG_INDEX 41 | { 42 | public: 43 | IFSG_COORDINDEX( bool create ); 44 | IFSG_COORDINDEX( SGNODE* aParent ); 45 | IFSG_COORDINDEX( IFSG_NODE& aParent ); 46 | 47 | bool Attach( SGNODE* aNode ); 48 | bool NewNode( SGNODE* aParent ); 49 | bool NewNode( IFSG_NODE& aParent ); 50 | }; 51 | 52 | #endif // IFSG_COORDINDEX_H 53 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_faceset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_faceset.h 26 | * defines the wrapper for the SGFACESET class 27 | */ 28 | 29 | 30 | #ifndef IFSG_FACESET_H 31 | #define IFSG_FACESET_H 32 | 33 | #include "plugins/3dapi/ifsg_node.h" 34 | 35 | 36 | /** 37 | * Class IFSG_FACESET 38 | * is the wrapper for the SGFACESET class 39 | */ 40 | class SGLIB_API IFSG_FACESET : public IFSG_NODE 41 | { 42 | public: 43 | IFSG_FACESET( bool create ); 44 | IFSG_FACESET( SGNODE* aParent ); 45 | IFSG_FACESET( IFSG_NODE& aParent ); 46 | 47 | bool Attach( SGNODE* aNode ); 48 | bool NewNode( SGNODE* aParent ); 49 | bool NewNode( IFSG_NODE& aParent ); 50 | 51 | bool CalcNormals( SGNODE** aPtr ); 52 | }; 53 | 54 | #endif // IFSG_FACESET_H 55 | -------------------------------------------------------------------------------- /include/plugins/3dapi/xv3d_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Mario Luzeiro 5 | * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, you may find one here: 19 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 20 | * or you may search the http://www.gnu.org website for the version 2 license, 21 | * or you may write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 23 | */ 24 | 25 | /** 26 | * @file xv3d_types.h 27 | * @brief 28 | */ 29 | 30 | #ifndef XV3D_TYPES_H 31 | #define XV3D_TYPES_H 32 | 33 | #define GLM_FORCE_RADIANS 34 | 35 | // Disable SIMD detection 36 | #define GLM_FORCE_PURE 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | typedef glm::uvec2 SFVEC2UI; 43 | typedef glm::ivec2 SFVEC2I; 44 | typedef glm::vec2 SFVEC2F; 45 | typedef glm::dvec2 SFVEC2D; 46 | typedef glm::vec3 SFVEC3F; 47 | typedef glm::dvec3 SFVEC3D; 48 | typedef glm::vec4 SFVEC4F; 49 | typedef glm::uvec3 SFVEC3UI; 50 | typedef glm::dvec3 SFVEC3D; 51 | 52 | #define CLASS_ALIGNMENT 16 53 | 54 | #endif // XV3D_TYPES_H 55 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_coords.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_coords.h 26 | * defines the coordinate list wrapper 27 | */ 28 | 29 | 30 | #ifndef IFSG_COORDS_H 31 | #define IFSG_COORDS_H 32 | 33 | #include "plugins/3dapi/ifsg_node.h" 34 | 35 | 36 | /** 37 | * Class IFSG_INDEX 38 | * is the wrapper for SGCOORDS 39 | */ 40 | class SGLIB_API IFSG_COORDS : public IFSG_NODE 41 | { 42 | public: 43 | IFSG_COORDS( bool create ); 44 | IFSG_COORDS( SGNODE* aParent ); 45 | IFSG_COORDS( IFSG_NODE& aParent ); 46 | 47 | bool Attach( SGNODE* aNode ); 48 | bool NewNode( SGNODE* aParent ); 49 | bool NewNode( IFSG_NODE& aParent ); 50 | 51 | bool GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList ); 52 | bool SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList ); 53 | bool AddCoord( double aXValue, double aYValue, double aZValue ); 54 | bool AddCoord( const SGPOINT& aPoint ); 55 | }; 56 | 57 | #endif // IFSG_COORDS_H 58 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_colors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_colors.h 26 | * defines the color list wrapper 27 | */ 28 | 29 | 30 | #ifndef IFSG_COLORS_H 31 | #define IFSG_COLORS_H 32 | 33 | #include 34 | #include "plugins/3dapi/ifsg_node.h" 35 | 36 | 37 | /** 38 | * Class IFSG_INDEX 39 | * is the wrapper for SGCOLORS 40 | */ 41 | class SGLIB_API IFSG_COLORS : public IFSG_NODE 42 | { 43 | public: 44 | IFSG_COLORS( bool create ); 45 | IFSG_COLORS( SGNODE* aParent ); 46 | IFSG_COLORS( IFSG_NODE& aParent ); 47 | 48 | bool Attach( SGNODE* aNode ); 49 | bool NewNode( SGNODE* aParent ); 50 | bool NewNode( IFSG_NODE& aParent ); 51 | 52 | bool GetColorList( size_t& aListSize, SGCOLOR*& aColorList ); 53 | bool SetColorList( size_t aListSize, const SGCOLOR* aColorList ); 54 | bool AddColor( double aRedValue, double aGreenValue, double aBlueValue ); 55 | bool AddColor( const SGCOLOR& aColor ); 56 | }; 57 | 58 | #endif // IFSG_COLORS_H 59 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_normals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_transform.h 26 | * defines the wrapper for the SGNORMALS class 27 | */ 28 | 29 | 30 | #ifndef IFSG_NORMALS_H 31 | #define IFSG_NORMALS_H 32 | 33 | #include "plugins/3dapi/ifsg_node.h" 34 | 35 | 36 | /** 37 | * Class IFSG_NORMALS 38 | * is the wrapper for the SGNORMALS class 39 | */ 40 | class SGLIB_API IFSG_NORMALS : public IFSG_NODE 41 | { 42 | public: 43 | IFSG_NORMALS( bool create ); 44 | IFSG_NORMALS( SGNODE* aParent ); 45 | IFSG_NORMALS( IFSG_NODE& aParent ); 46 | 47 | bool Attach( SGNODE* aNode ); 48 | bool NewNode( SGNODE* aParent ); 49 | bool NewNode( IFSG_NODE& aParent ); 50 | 51 | bool GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList ); 52 | bool SetNormalList( size_t aListSize, const SGVECTOR* aNormalList ); 53 | bool AddNormal( double aXValue, double aYValue, double aZValue ); 54 | bool AddNormal( const SGVECTOR& aNormal ); 55 | }; 56 | 57 | #endif // IFSG_NORMALS_H 58 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_coordindex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_coordindex.h 26 | * defines an coordinate index set for a scenegraph object 27 | */ 28 | 29 | #ifndef SG_COORDINDEX_H 30 | #define SG_COORDINDEX_H 31 | 32 | #include "3d_cache/sg/sg_index.h" 33 | 34 | /** 35 | * Class SGCOORDINDEX 36 | * is a class which maintains a coordinate index list. Users 37 | * must ensure that coordinate indices are specified as 38 | * triplets (triangular faces) since no checking is performed. 39 | * In instances where it is not possible to determine which 40 | * side of the triangle is to be rendered (for example IGES 41 | * entities) then the user must supply each triplet in both 42 | * point orders. 43 | */ 44 | class SGCOORDINDEX : public SGINDEX 45 | { 46 | public: 47 | SGCOORDINDEX( SGNODE* aParent ); 48 | virtual ~SGCOORDINDEX(); 49 | 50 | /** 51 | * Function GatherCoordIndices 52 | * adds all coordinate indices to the given list 53 | * in preparation for a normals calculation 54 | */ 55 | void GatherCoordIndices( std::vector< int >& aIndexList ); 56 | }; 57 | 58 | #endif // SG_COORDINDEX_H 59 | -------------------------------------------------------------------------------- /CMakeModules/FindGLM.cmake: -------------------------------------------------------------------------------- 1 | find_path( GLM_INCLUDE_DIR glm/glm.hpp 2 | PATHS ${GLM_ROOT_DIR} $ENV{GLM_ROOT_DIR} 3 | DOC "GLM library header path." 4 | ) 5 | 6 | if( NOT ${GLM_INCLUDE_DIR} STREQUAL "GLM_INCLUDE_DIR-NOTFOUND" ) 7 | 8 | # attempt to extract the GLM Version information from setup.hpp 9 | find_file( GLM_SETUP setup.hpp 10 | PATHS ${GLM_INCLUDE_DIR} 11 | PATH_SUFFIXES glm/core glm/detail 12 | NO_DEFAULT_PATH ) 13 | 14 | if( NOT ${GLM_SETUP} STREQUAL "GLM_SETUP-NOTFOUND" ) 15 | 16 | # extract the "#define GLM_VERSION*" lines 17 | file( STRINGS ${GLM_SETUP} _version REGEX "^#define.*GLM_VERSION.*" ) 18 | 19 | foreach( SVAR ${_version} ) 20 | string( REGEX MATCH GLM_VERSION_[M,A,J,O,R,I,N,P,T,C,H,E,V,I,S]* _VARNAME ${SVAR} ) 21 | string( REGEX MATCH [0-9]+ _VALUE ${SVAR} ) 22 | 23 | if( NOT ${_VARNAME} STREQUAL "" AND NOT ${_VALUE} STREQUAL "" ) 24 | set( _${_VARNAME} ${_VALUE} ) 25 | endif() 26 | 27 | endforeach() 28 | 29 | #ensure that NOT GLM_VERSION* will evaluate to '0' 30 | if( NOT _GLM_VERSION_MAJOR ) 31 | set( _GLM_VERSION_MAJOR 0 ) 32 | endif() 33 | 34 | if( NOT _GLM_VERSION_MINOR ) 35 | set( _GLM_VERSION_MINOR 0 ) 36 | endif() 37 | 38 | if( NOT _GLM_VERSION_PATCH ) 39 | set( _GLM_VERSION_PATCH 0 ) 40 | endif() 41 | 42 | if( NOT _GLM_VERSION_REVISION ) 43 | set( _GLM_VERSION_REVISION 0 ) 44 | endif() 45 | 46 | set( GLM_VERSION ${_GLM_VERSION_MAJOR}.${_GLM_VERSION_MINOR}.${_GLM_VERSION_PATCH}.${_GLM_VERSION_REVISION} ) 47 | unset( GLM_SETUP CACHE ) 48 | 49 | endif() 50 | endif() 51 | 52 | 53 | include( FindPackageHandleStandardArgs ) 54 | FIND_PACKAGE_HANDLE_STANDARD_ARGS( GLM 55 | REQUIRED_VARS 56 | GLM_INCLUDE_DIR 57 | GLM_VERSION 58 | VERSION_VAR GLM_VERSION ) 59 | 60 | 61 | mark_as_advanced( GLM_INCLUDE_DIR ) 62 | set( GLM_VERSION_MAJOR ${_GLM_VERSION_MAJOR} CACHE INTERNAL "" ) 63 | set( GLM_VERSION_MINOR ${_GLM_VERSION_MINOR} CACHE INTERNAL "" ) 64 | set( GLM_VERSION_PATCH ${_GLM_VERSION_PATCH} CACHE INTERNAL "" ) 65 | set( GLM_VERSION_TWEAK ${_GLM_VERSION_REVISION} CACHE INTERNAL "" ) 66 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2011 SoftPLC Corporation, Dick Hollenbeck 5 | * Copyright (C) 2015 KiCad Developers, see change_log.txt for contributors. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, you may find one here: 19 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 20 | * or you may search the http://www.gnu.org website for the version 2 license, 21 | * or you may write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 23 | */ 24 | 25 | /* 26 | * Note: this is based on kicad's import_export.h file but is 27 | * reproduced here in order to facilitate support of out-of-tree 28 | * builds for 3D plugins. 29 | */ 30 | 31 | #ifndef IFSG_DEFS_H 32 | #define IFSG_DEFS_H 33 | 34 | #if defined(__MINGW32__) || defined( MSVC ) 35 | #define APIEXPORT __declspec(dllexport) 36 | #define APIIMPORT __declspec(dllimport) 37 | #define APILOCAL 38 | 39 | #elif defined(__GNUC__) && __GNUC__ >= 4 40 | // On ELF, we compile with hidden visibility, so unwrap that for specific symbols: 41 | #define APIEXPORT __attribute__ ((visibility("default"))) 42 | #define APIIMPORT __attribute__ ((visibility("default"))) 43 | #define APILOCAL __attribute__ ((visibility("hidden"))) 44 | 45 | #else 46 | #pragma message ( "warning: a supported C++ compiler is required" ) 47 | #define APIEXPORT 48 | #define APIIMPORT 49 | #define APILOCAL 50 | #endif 51 | 52 | #if defined (COMPILE_SGLIB) 53 | #define SGLIB_API APIEXPORT 54 | #define MASK_3D_SG "3D_SG" 55 | #else 56 | #define SGLIB_API APIIMPORT 57 | #endif 58 | 59 | #endif // IFSG_DEFS_H 60 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_transform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_transform.h 26 | * defines the wrapper for the SCENEGRAPH class 27 | */ 28 | 29 | 30 | #ifndef IFSG_TRANSFORM_H 31 | #define IFSG_TRANSFORM_H 32 | 33 | #include "plugins/3dapi/ifsg_node.h" 34 | 35 | 36 | /** 37 | * Class IFSG_TRANSFORM 38 | * is the wrapper for the VRML compatible TRANSFORM block class SCENEGRAPH 39 | */ 40 | class SGLIB_API IFSG_TRANSFORM : public IFSG_NODE 41 | { 42 | public: 43 | IFSG_TRANSFORM( bool create ); 44 | IFSG_TRANSFORM( SGNODE* aParent ); 45 | // note: IFSG_TRANSFORM( IFSG_NODE& aParent ) does not exist 46 | // since a transform may own another transform and that construct 47 | // invites accidental misuse of the copy constructor 48 | 49 | bool Attach( SGNODE* aNode ); 50 | bool NewNode( SGNODE* aParent ); 51 | bool NewNode( IFSG_NODE& aParent ); 52 | 53 | bool SetScaleOrientation( const SGVECTOR& aScaleAxis, double aAngle ); 54 | bool SetRotation( const SGVECTOR& aRotationAxis, double aAngle ); 55 | bool SetScale( const SGPOINT& aScale ); 56 | bool SetScale( double aScale ); 57 | bool SetCenter( const SGPOINT& aCenter ); 58 | bool SetTranslation( const SGPOINT& aTranslation ); 59 | }; 60 | 61 | #endif // IFSG_TRANSFORM_H 62 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_index.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_index.h 26 | * defines the index nodes wrapper 27 | */ 28 | 29 | 30 | #ifndef IFSG_INDEX_H 31 | #define IFSG_INDEX_H 32 | 33 | #include "plugins/3dapi/ifsg_node.h" 34 | 35 | 36 | /** 37 | * Class IFSG_INDEX 38 | * is the wrapper for SGINDEX 39 | */ 40 | class SGLIB_API IFSG_INDEX : public IFSG_NODE 41 | { 42 | public: 43 | IFSG_INDEX(); 44 | 45 | virtual bool Attach( SGNODE* aNode ) = 0; 46 | virtual bool NewNode( SGNODE* aParent ) = 0; 47 | virtual bool NewNode( IFSG_NODE& aParent ) = 0; 48 | 49 | bool GetIndices( size_t& nIndices, int*& aIndexList ); 50 | 51 | /** 52 | * Function SetIndices 53 | * sets the number of indices and creates a copy of the given index data. 54 | * 55 | * @param nIndices [in] the number of indices to be stored 56 | * @param aIndexList [in] the index data 57 | */ 58 | bool SetIndices( size_t nIndices, int* aIndexList ); 59 | 60 | 61 | /** 62 | * Function AddIndex 63 | * adds a single index to the list 64 | * 65 | * @param nIndices [in] the number of indices to be stored 66 | * @param aIndexList [in] the index data 67 | */ 68 | bool AddIndex( int aIndex ); 69 | }; 70 | 71 | #endif // IFSG_INDEX_H 72 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_colors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_colors.h 26 | * defines an RGB color set for a scenegraph object 27 | */ 28 | 29 | #ifndef SG_COLORS_H 30 | #define SG_COLORS_H 31 | 32 | #include 33 | #include "3d_cache/sg/sg_node.h" 34 | 35 | class SGCOLORS : public SGNODE 36 | { 37 | public: 38 | std::vector< SGCOLOR > colors; 39 | 40 | void unlinkChildNode( const SGNODE* aNode ); 41 | void unlinkRefNode( const SGNODE* aNode ); 42 | 43 | public: 44 | SGCOLORS( SGNODE* aParent ); 45 | virtual ~SGCOLORS(); 46 | 47 | virtual bool SetParent( SGNODE* aParent, bool notify = true ); 48 | 49 | SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller); 50 | bool AddRefNode( SGNODE* aNode ); 51 | bool AddChildNode( SGNODE* aNode ); 52 | 53 | bool GetColorList( size_t& aListSize, SGCOLOR*& aColorList ); 54 | void SetColorList( size_t aListSize, const SGCOLOR* aColorList ); 55 | void AddColor( double aRedValue, double aGreenValue, double aBlueValue ); 56 | void AddColor( const SGCOLOR& aColor ); 57 | 58 | void ReNameNodes( void ); 59 | bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ); 60 | 61 | bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ); 62 | bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ); 63 | }; 64 | 65 | #endif // SG_COLORS_H 66 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_normals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_normals.h 26 | * defines a set of vertex normals for a scene graph object 27 | */ 28 | 29 | #ifndef SG_NORMALS_H 30 | #define SG_NORMALS_H 31 | 32 | #include 33 | #include "3d_cache/sg/sg_node.h" 34 | 35 | class SGNORMALS : public SGNODE 36 | { 37 | public: 38 | std::vector< SGVECTOR > norms; 39 | 40 | void unlinkChildNode( const SGNODE* aNode ); 41 | void unlinkRefNode( const SGNODE* aNode ); 42 | 43 | public: 44 | SGNORMALS( SGNODE* aParent ); 45 | virtual ~SGNORMALS(); 46 | 47 | virtual bool SetParent( SGNODE* aParent, bool notify = true ); 48 | 49 | SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller); 50 | bool AddRefNode( SGNODE* aNode ); 51 | bool AddChildNode( SGNODE* aNode ); 52 | 53 | bool GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList ); 54 | void SetNormalList( size_t aListSize, const SGVECTOR* aNormalList ); 55 | void AddNormal( double aXValue, double aYValue, double aZValue ); 56 | void AddNormal( const SGVECTOR& aNormal ); 57 | 58 | void ReNameNodes( void ); 59 | bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ); 60 | 61 | bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ); 62 | bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ); 63 | }; 64 | 65 | #endif // SG_NORMALS_H 66 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_appearance.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_appearance.h 26 | * defines the wrapper of the SGAPPEARANCE class 27 | */ 28 | 29 | #ifndef IFSG_APPEARANCE_H 30 | #define IFSG_APPEARANCE_H 31 | 32 | #include "plugins/3dapi/ifsg_node.h" 33 | 34 | class SGLIB_API IFSG_APPEARANCE : public IFSG_NODE 35 | { 36 | public: 37 | IFSG_APPEARANCE( bool create ); 38 | IFSG_APPEARANCE( SGNODE* aParent ); 39 | IFSG_APPEARANCE( IFSG_NODE& aParent ); 40 | 41 | bool Attach( SGNODE* aNode ); 42 | bool NewNode( SGNODE* aParent ); 43 | bool NewNode( IFSG_NODE& aParent ); 44 | 45 | bool SetEmissive( float aRVal, float aGVal, float aBVal ); 46 | bool SetEmissive( const SGCOLOR* aRGBColor ); 47 | bool SetEmissive( const SGCOLOR& aRGBColor ); 48 | 49 | bool SetDiffuse( float aRVal, float aGVal, float aBVal ); 50 | bool SetDiffuse( const SGCOLOR* aRGBColor ); 51 | bool SetDiffuse( const SGCOLOR& aRGBColor ); 52 | 53 | bool SetSpecular( float aRVal, float aGVal, float aBVal ); 54 | bool SetSpecular( const SGCOLOR* aRGBColor ); 55 | bool SetSpecular( const SGCOLOR& aRGBColor ); 56 | 57 | bool SetAmbient( float aRVal, float aGVal, float aBVal ); 58 | bool SetAmbient( const SGCOLOR* aRGBColor ); 59 | bool SetAmbient( const SGCOLOR& aRGBColor ); 60 | 61 | bool SetShininess( float aShininess ); 62 | bool SetTransparency( float aTransparency ); 63 | }; 64 | 65 | #endif // IFSG_APPEARANCE_H 66 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_coords.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_coords.h 26 | * defines a vertex coordinate set for a scenegraph object 27 | */ 28 | 29 | #ifndef SG_COORDS_H 30 | #define SG_COORDS_H 31 | 32 | #include 33 | #include "3d_cache/sg/sg_node.h" 34 | 35 | class SGFACESET; 36 | 37 | class SGCOORDS : public SGNODE 38 | { 39 | public: 40 | std::vector< SGPOINT > coords; 41 | 42 | void unlinkChildNode( const SGNODE* aNode ); 43 | void unlinkRefNode( const SGNODE* aNode ); 44 | 45 | public: 46 | SGCOORDS( SGNODE* aParent ); 47 | virtual ~SGCOORDS(); 48 | 49 | virtual bool SetParent( SGNODE* aParent, bool notify = true ); 50 | 51 | SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller); 52 | bool AddRefNode( SGNODE* aNode ); 53 | bool AddChildNode( SGNODE* aNode ); 54 | 55 | bool GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList ); 56 | void SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList ); 57 | void AddCoord( double aXValue, double aYValue, double aZValue ); 58 | void AddCoord( const SGPOINT& aPoint ); 59 | 60 | /** 61 | * Function CalcNormals 62 | * calculates normals for this coordinate list and sets the 63 | * normals list in the parent SGFACESET 64 | */ 65 | bool CalcNormals( SGFACESET* callingNode, SGNODE** aPtr = NULL ); 66 | 67 | void ReNameNodes( void ); 68 | bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ); 69 | 70 | bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ); 71 | bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ); 72 | }; 73 | 74 | #endif // SG_COORDS_H 75 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_shape.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_shape.h 26 | * defines a complex 3D shape for a scenegraph object 27 | */ 28 | 29 | 30 | #ifndef SG_SHAPE_H 31 | #define SG_SHAPE_H 32 | 33 | #include 34 | #include "3d_cache/sg/sg_node.h" 35 | 36 | class SGAPPEARANCE; 37 | class SGFACESET; 38 | 39 | class SGSHAPE : public SGNODE 40 | { 41 | private: 42 | void unlinkNode( const SGNODE* aNode, bool isChild ); 43 | bool addNode( SGNODE* aNode, bool isChild ); 44 | 45 | public: 46 | // owned node 47 | SGAPPEARANCE* m_Appearance; 48 | SGFACESET* m_FaceSet; 49 | 50 | // referenced nodes 51 | SGAPPEARANCE* m_RAppearance; 52 | SGFACESET* m_RFaceSet; 53 | 54 | void unlinkChildNode( const SGNODE* aNode ); 55 | void unlinkRefNode( const SGNODE* aNode ); 56 | 57 | public: 58 | SGSHAPE( SGNODE* aParent ); 59 | virtual ~SGSHAPE(); 60 | 61 | virtual bool SetParent( SGNODE* aParent, bool notify = true ); 62 | 63 | SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller); 64 | bool AddRefNode( SGNODE* aNode ); 65 | bool AddChildNode( SGNODE* aNode ); 66 | 67 | void ReNameNodes( void ); 68 | bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ); 69 | 70 | bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ); 71 | bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ); 72 | 73 | bool Prepare( const glm::dmat4* aTransform, 74 | S3D::MATLIST& materials, std::vector< SMESH >& meshes ); 75 | }; 76 | 77 | /* 78 | p.107 79 | Shape { 80 | appearance NULL 81 | geometry NULL 82 | } 83 | */ 84 | 85 | #endif // SG_SHAPE_H 86 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories( 2 | ${CMAKE_SOURCE_DIR}/include 3 | ${CMAKE_SOURCE_DIR}/3d-viewer 4 | ) 5 | 6 | add_library( kicad_3dsg SHARED 7 | sg_base.cpp 8 | sg_node.cpp 9 | sg_helpers.cpp 10 | scenegraph.cpp 11 | sg_appearance.cpp 12 | sg_faceset.cpp 13 | sg_shape.cpp 14 | sg_colors.cpp 15 | sg_coords.cpp 16 | sg_normals.cpp 17 | sg_index.cpp 18 | sg_coordindex.cpp 19 | ifsg_node.cpp 20 | ifsg_transform.cpp 21 | ifsg_appearance.cpp 22 | ifsg_index.cpp 23 | ifsg_coordindex.cpp 24 | ifsg_colors.cpp 25 | ifsg_coords.cpp 26 | ifsg_faceset.cpp 27 | ifsg_normals.cpp 28 | ifsg_shape.cpp 29 | ifsg_api.cpp 30 | ) 31 | 32 | if( APPLE ) 33 | # puts library into the main kicad.app bundle in build tree 34 | set_target_properties( kicad_3dsg PROPERTIES 35 | LIBRARY_OUTPUT_DIRECTORY "${OSX_BUNDLE_BUILD_LIB_DIR}" 36 | INSTALL_NAME_DIR "${OSX_BUNDLE_BUILD_LIB_DIR}" 37 | ) 38 | endif() 39 | 40 | find_file( S3DSG_VERSION_FILE sg_version.h 41 | PATHS ${CMAKE_SOURCE_DIR}/include/plugins/3dapi NO_DEFAULT_PATH ) 42 | 43 | if( NOT ${S3DSG_VERSION_FILE} STREQUAL "S3DSG_VERSION_FILE-NOTFOUND" ) 44 | 45 | # extract the "#define KICADSG_VERSION_*" lines 46 | file( STRINGS ${S3DSG_VERSION_FILE} _version 47 | REGEX "^[' ','\t']*#define[' ','\t']*KICADSG_VERSION_.*" ) 48 | 49 | foreach( SVAR ${_version} ) 50 | string( REGEX MATCH KICADSG_VERSION_[M,A,J,O,R,I,N,P,T,C,H,E,V]* _VARNAME ${SVAR} ) 51 | string( REGEX MATCH [0-9]+ _VALUE ${SVAR} ) 52 | 53 | if( NOT ${_VARNAME} STREQUAL "" ) 54 | message( "INFO: " ${_VARNAME} " = " ${_VALUE} ) 55 | if( NOT ${_VALUE} STREQUAL "" ) 56 | set( ${_VARNAME} ${_VALUE} ) 57 | else() 58 | set( ${_VARNAME} 0 ) 59 | endif() 60 | endif() 61 | 62 | endforeach() 63 | 64 | if( NOT KICADSG_VERSION_MAJOR AND NOT ${KICADSG_VERSION_MAJOR} STREQUAL "0" ) 65 | message( FATAL_ERROR "Cannot determine the S3DSG library version" ) 66 | endif() 67 | 68 | #ensure that NOT SG_VERSION* will evaluate to '0' 69 | if( NOT KICADSG_VERSION_MINOR ) 70 | set( KICADSG_VERSION_MINOR 0 ) 71 | endif() 72 | 73 | if( NOT KICADSG_VERSION_PATCH ) 74 | set( KICADSG_VERSION_PATCH 0 ) 75 | endif() 76 | 77 | set_target_properties( kicad_3dsg 78 | PROPERTIES SOVERSION 79 | ${KICADSG_VERSION_MAJOR}.${KICADSG_VERSION_MINOR}.${KICADSG_VERSION_PATCH} ) 80 | 81 | else() 82 | message( FATAL_ERROR "Cannot determine the S3DSG library version" ) 83 | endif() 84 | 85 | unset( S3DSG_VERSION_FILE CACHE ) 86 | 87 | # Define a flag to expose the appropriate EXPORT macro at build time 88 | target_compile_definitions( kicad_3dsg PRIVATE -DCOMPILE_SGLIB ) 89 | 90 | target_link_libraries( kicad_3dsg ${wxWidgets_LIBRARIES} ) 91 | 92 | if( INSTALL_LIB ) 93 | install( TARGETS 94 | kicad_3dsg 95 | DESTINATION ${KICAD_LIB} 96 | COMPONENT binary 97 | ) 98 | endif() -------------------------------------------------------------------------------- /CMakeModules/Functions.cmake: -------------------------------------------------------------------------------- 1 | # This program source code file is part of KICAD, a free EDA CAD application. 2 | # 3 | # Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck 4 | # Copyright (C) 2010 Kicad Developers, see AUTHORS.txt for contributors. 5 | # 6 | # This program is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU General Public License 8 | # as published by the Free Software Foundation; either version 2 9 | # of the License, or (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, you may find one here: 18 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | # or you may search the http://www.gnu.org website for the version 2 license, 20 | # or you may write to the Free Software Foundation, Inc., 21 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | # 23 | 24 | 25 | # Function make_lexer 26 | # is a standard way to invoke TokenList2DsnLexer.cmake. 27 | # Extra arguments are treated as source files which depend on the generated 28 | # outHeaderFile 29 | 30 | function( make_lexer inputFile outHeaderFile outCppFile enum ) 31 | add_custom_command( 32 | OUTPUT ${outHeaderFile} 33 | ${outCppFile} 34 | COMMAND ${CMAKE_COMMAND} 35 | -Denum=${enum} 36 | -DinputFile=${inputFile} 37 | -DoutHeaderFile=${outHeaderFile} 38 | -DoutCppFile=${outCppFile} 39 | -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake 40 | DEPENDS ${inputFile} 41 | ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake 42 | COMMENT "TokenList2DsnLexer.cmake creating: 43 | ${outHeaderFile} and 44 | ${outCppFile} from 45 | ${inputFile}" 46 | ) 47 | 48 | # extra_args, if any, are treated as source files (typically headers) which 49 | # are known to depend on the generated outHeader. 50 | foreach( extra_arg ${ARGN} ) 51 | set_source_files_properties( ${extra_arg} 52 | PROPERTIES OBJECT_DEPENDS ${outHeaderFile} 53 | ) 54 | endforeach() 55 | 56 | endfunction() 57 | 58 | 59 | # Is a macro instead of function so there's a higher probability that the 60 | # scope of CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA is global 61 | macro( add_conffiles ) 62 | if( ${ARGC} STREQUAL "0" ) 63 | # remove the file when user passes no arguments, which he should do exactly once at top 64 | file( REMOVE ${CMAKE_CURRENT_BINARY_DIR}/conffiles ) 65 | else() 66 | foreach( filename ${ARGV} ) 67 | file( APPEND ${CMAKE_CURRENT_BINARY_DIR}/conffiles "${filename}\n" ) 68 | endforeach() 69 | set( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_CURRENT_BINARY_DIR}/conffiles ) 70 | endif() 71 | endmacro( add_conffiles ) 72 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/ifsg_index.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "plugins/3dapi/ifsg_index.h" 30 | #include "3d_cache/sg/sg_coordindex.h" 31 | 32 | 33 | extern char BadObject[]; 34 | extern char BadOperand[]; 35 | extern char BadParent[]; 36 | extern char WrongParent[]; 37 | 38 | 39 | IFSG_INDEX::IFSG_INDEX() : IFSG_NODE() 40 | { 41 | return; 42 | } 43 | 44 | 45 | bool IFSG_INDEX::GetIndices( size_t& nIndices, int*& aIndexList ) 46 | { 47 | if( NULL == m_node ) 48 | { 49 | #ifdef DEBUG 50 | std::ostringstream ostr; 51 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 52 | ostr << BadObject; 53 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 54 | #endif 55 | 56 | return false; 57 | } 58 | 59 | return ((SGINDEX*)m_node)->GetIndices( nIndices, aIndexList ); 60 | } 61 | 62 | 63 | bool IFSG_INDEX::SetIndices( size_t nIndices, int* aIndexList ) 64 | { 65 | if( NULL == m_node ) 66 | { 67 | #ifdef DEBUG 68 | std::ostringstream ostr; 69 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 70 | ostr << BadObject; 71 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 72 | #endif 73 | 74 | return false; 75 | } 76 | 77 | ((SGINDEX*)m_node)->SetIndices( nIndices, aIndexList ); 78 | 79 | return true; 80 | } 81 | 82 | 83 | bool IFSG_INDEX::AddIndex( int aIndex ) 84 | { 85 | if( NULL == m_node ) 86 | { 87 | #ifdef DEBUG 88 | std::ostringstream ostr; 89 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 90 | ostr << BadObject; 91 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 92 | #endif 93 | 94 | return false; 95 | } 96 | 97 | ((SGINDEX*)m_node)->AddIndex( aIndex ); 98 | 99 | return true; 100 | } 101 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_appearance.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_appearance.h 26 | * defines the generic material appearance of a scenegraph object 27 | */ 28 | 29 | #ifndef SG_APPEARANCE_H 30 | #define SG_APPEARANCE_H 31 | 32 | #include "3d_cache/sg/sg_node.h" 33 | 34 | class SGAPPEARANCE : public SGNODE 35 | { 36 | public: 37 | float shininess; // default 0.2 38 | float transparency; // default 0.0 39 | SGCOLOR ambient; // default 0.05317 0.17879 0.01804 40 | SGCOLOR diffuse; // default 0.8 0.8 0.8 41 | SGCOLOR emissive; // default 0.0 0.0 0.0 42 | SGCOLOR specular; // default 0.0 0.0 0.0 43 | 44 | void unlinkChildNode( const SGNODE* aNode ); 45 | void unlinkRefNode( const SGNODE* aNode ); 46 | 47 | public: 48 | SGAPPEARANCE( SGNODE* aParent ); 49 | virtual ~SGAPPEARANCE(); 50 | 51 | virtual bool SetParent( SGNODE* aParent, bool notify = true ); 52 | 53 | bool SetEmissive( float aRVal, float aGVal, float aBVal ); 54 | bool SetEmissive( const SGCOLOR* aRGBColor ); 55 | bool SetEmissive( const SGCOLOR& aRGBColor ); 56 | 57 | bool SetDiffuse( float aRVal, float aGVal, float aBVal ); 58 | bool SetDiffuse( const SGCOLOR* aRGBColor ); 59 | bool SetDiffuse( const SGCOLOR& aRGBColor ); 60 | 61 | bool SetSpecular( float aRVal, float aGVal, float aBVal ); 62 | bool SetSpecular( const SGCOLOR* aRGBColor ); 63 | bool SetSpecular( const SGCOLOR& aRGBColor ); 64 | 65 | bool SetAmbient( float aRVal, float aGVal, float aBVal ); 66 | bool SetAmbient( const SGCOLOR* aRGBColor ); 67 | bool SetAmbient( const SGCOLOR& aRGBColor ); 68 | 69 | SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller); 70 | bool AddRefNode( SGNODE* aNode ); 71 | bool AddChildNode( SGNODE* aNode ); 72 | 73 | void ReNameNodes( void ); 74 | bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ); 75 | 76 | bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ); 77 | bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ); 78 | }; 79 | 80 | #endif // SG_APPEARANCE_H 81 | -------------------------------------------------------------------------------- /include/plugins/3dapi/sg_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_base.h 26 | * defines the low level classes common to scene graph nodes 27 | */ 28 | 29 | 30 | #ifndef SG_BASE_H 31 | #define SG_BASE_H 32 | 33 | #include "plugins/3dapi/ifsg_defs.h" 34 | 35 | #ifndef SGLIB_API 36 | #if defined (COMPILE_SGLIB) 37 | #define SGLIB_API APIEXPORT 38 | #else 39 | #define SGLIB_API APIIMPORT 40 | #endif 41 | #endif 42 | 43 | class SGLIB_API SGCOLOR 44 | { 45 | protected: 46 | float red; 47 | float green; 48 | float blue; 49 | 50 | public: 51 | SGCOLOR(); 52 | SGCOLOR( float aRVal, float aGVal, float aBVal ); 53 | 54 | void GetColor( float& aRedVal, float& aGreenVal, float& aBlueVal ) const; 55 | void GetColor( SGCOLOR& aColor ) const; 56 | void GetColor( SGCOLOR* aColor ) const; 57 | 58 | bool SetColor( float aRedVal, float aGreenVal, float aBlueVal ); 59 | bool SetColor( const SGCOLOR& aColor ); 60 | bool SetColor( const SGCOLOR* aColor ); 61 | 62 | private: 63 | bool checkRange( float aRedVal, float aGreenVal, float aBlueVal ) const; 64 | }; 65 | 66 | 67 | class SGLIB_API SGPOINT 68 | { 69 | public: 70 | double x; 71 | double y; 72 | double z; 73 | 74 | public: 75 | SGPOINT(); 76 | SGPOINT( double aXVal, double aYVal, double aZVal ); 77 | 78 | void GetPoint( double& aXVal, double& aYVal, double& aZVal ); 79 | void GetPoint( SGPOINT& aPoint ); 80 | void GetPoint( SGPOINT* aPoint ); 81 | 82 | void SetPoint( double aXVal, double aYVal, double aZVal ); 83 | void SetPoint( const SGPOINT& aPoint ); 84 | }; 85 | 86 | 87 | class SGLIB_API SGVECTOR 88 | { 89 | private: 90 | void normalize( void ); 91 | 92 | double vx; 93 | double vy; 94 | double vz; 95 | 96 | public: 97 | SGVECTOR(); 98 | SGVECTOR( double aXVal, double aYVal, double aZVal ); 99 | 100 | void GetVector( double& aXVal, double& aYVal, double& aZVal ) const; 101 | 102 | void SetVector( double aXVal, double aYVal, double aZVal ); 103 | void SetVector( const SGVECTOR& aVector ); 104 | 105 | SGVECTOR& operator=( const SGVECTOR& source ); 106 | }; 107 | 108 | 109 | #endif // SG_BASE_H 110 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_index.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_index.h 26 | * defines a generic Index interface for a scenegraph object 27 | */ 28 | 29 | #ifndef SG_INDEX_H 30 | #define SG_INDEX_H 31 | 32 | #include 33 | #include "3d_cache/sg/sg_node.h" 34 | 35 | class SGINDEX : public SGNODE 36 | { 37 | protected: 38 | bool writeCoordIndex( std::ofstream& aFile ); 39 | bool writeColorIndex( std::ofstream& aFile ); 40 | bool writeIndexList( std::ofstream& aFile ); 41 | 42 | public: 43 | // for internal SG consumption only 44 | std::vector< int > index; 45 | void unlinkChildNode( const SGNODE* aCaller ); 46 | void unlinkRefNode( const SGNODE* aCaller ); 47 | 48 | public: 49 | SGINDEX( SGNODE* aParent ); 50 | virtual ~SGINDEX(); 51 | 52 | virtual bool SetParent( SGNODE* aParent, bool notify = true ); 53 | 54 | SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller); 55 | bool AddRefNode( SGNODE* aNode ); 56 | bool AddChildNode( SGNODE* aNode ); 57 | 58 | /** 59 | * Function GetIndices 60 | * retrieves the number of indices and a pointer to 61 | * the list. Note: the returned pointer may be invalidated 62 | * by future operations on the SGNODE; the caller must make 63 | * immediate use of the data and must not rely on the pointer's 64 | * validity in the future. 65 | * 66 | * @param nIndices [out] will hold the number of indices in the list 67 | * @param aIndexList [out] will store a pointer to the data 68 | * @return true if there was available data (nIndices > 0) otherwise false 69 | */ 70 | bool GetIndices( size_t& nIndices, int*& aIndexList ); 71 | 72 | /** 73 | * Function SetIndices 74 | * sets the number of indices and creates a copy of the given index data. 75 | * 76 | * @param nIndices [in] the number of indices to be stored 77 | * @param aIndexList [in] the index data 78 | */ 79 | void SetIndices( size_t nIndices, int* aIndexList ); 80 | 81 | 82 | /** 83 | * Function AddIndex 84 | * adds a single index to the list 85 | * 86 | * @param nIndices [in] the number of indices to be stored 87 | * @param aIndexList [in] the index data 88 | */ 89 | void AddIndex( int aIndex ); 90 | 91 | void ReNameNodes( void ); 92 | bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ); 93 | 94 | bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ); 95 | bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ); 96 | }; 97 | 98 | #endif // SG_INDEX_H 99 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_faceset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_faceset.h 26 | * defines an indexed face set for a scenegraph 27 | */ 28 | 29 | 30 | #ifndef SG_FACESET_H 31 | #define SG_FACESET_H 32 | 33 | #include 34 | #include "3d_cache/sg/sg_node.h" 35 | 36 | 37 | class SGCOLORS; 38 | class SGCOORDS; 39 | class SGNORMALS; 40 | class SGCOLORINDEX; 41 | class SGCOORDINDEX; 42 | 43 | class SGFACESET : public SGNODE 44 | { 45 | private: 46 | bool valid; 47 | bool validated; 48 | void unlinkNode( const SGNODE* aNode, bool isChild ); 49 | bool addNode( SGNODE* aNode, bool isChild ); 50 | 51 | public: 52 | // owned objects 53 | SGCOLORS* m_Colors; 54 | SGCOORDS* m_Coords; 55 | SGCOORDINDEX* m_CoordIndices; 56 | SGNORMALS* m_Normals; 57 | 58 | // referenced objects 59 | SGCOLORS* m_RColors; 60 | SGCOORDS* m_RCoords; 61 | SGNORMALS* m_RNormals; 62 | 63 | void unlinkChildNode( const SGNODE* aNode ); 64 | void unlinkRefNode( const SGNODE* aNode ); 65 | // validate the data held by this face set 66 | bool validate( void ); 67 | 68 | public: 69 | SGFACESET( SGNODE* aParent ); 70 | virtual ~SGFACESET(); 71 | 72 | virtual bool SetParent( SGNODE* aParent, bool notify = true ); 73 | 74 | SGNODE* FindNode( const char *aNodeName, const SGNODE *aCaller ); 75 | bool AddRefNode( SGNODE* aNode ); 76 | bool AddChildNode( SGNODE* aNode ); 77 | 78 | bool CalcNormals( SGNODE** aPtr ); 79 | 80 | void ReNameNodes( void ); 81 | bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ); 82 | 83 | bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ); 84 | bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ); 85 | 86 | /** 87 | * Function GatherCoordIndices 88 | * adds all internal coordinate indices to the given list 89 | * in preparation for a normals calculation 90 | */ 91 | void GatherCoordIndices( std::vector< int >& aIndexList ); 92 | }; 93 | 94 | /* 95 | p.88 96 | IndexedFaceSet { 97 | color NULL 98 | coord NULL 99 | normal NULL 100 | texCoord NULL 101 | ccw TRUE 102 | colorIndex [] 103 | colorPerVertex TRUE 104 | convex TRUE 105 | coordIndex [] 106 | creaseAngle 0 107 | normalIndex [] 108 | normalPerVertex TRUE 109 | solid TRUE 110 | texCoordIndex [] 111 | } 112 | */ 113 | 114 | #endif // SG_FACESET_H 115 | -------------------------------------------------------------------------------- /CMakeModules/UsewxWidgets.cmake: -------------------------------------------------------------------------------- 1 | # - Convenience include for using wxWidgets library. 2 | # Determines if wxWidgets was FOUND and sets the appropriate libs, incdirs, 3 | # flags, etc. INCLUDE_DIRECTORIES and LINK_DIRECTORIES are called. 4 | # 5 | # USAGE 6 | # # Note that for MinGW users the order of libs is important! 7 | # FIND_PACKAGE(wxWidgets REQUIRED net gl core base) 8 | # INCLUDE(${wxWidgets_USE_FILE}) 9 | # # and for each of your dependant executable/library targets: 10 | # TARGET_LINK_LIBRARIES( ${wxWidgets_LIBRARIES}) 11 | # 12 | # DEPRECATED 13 | # LINK_LIBRARIES is not called in favor of adding dependencies per target. 14 | # 15 | # AUTHOR 16 | # Jan Woetzel 17 | 18 | #============================================================================= 19 | # Copyright 2004-2009 Kitware, Inc. 20 | # Copyright 2006 Jan Woetzel 21 | # 22 | # Distributed under the OSI-approved BSD License (the "License"); 23 | # see accompanying file Copyright.txt for details. 24 | # 25 | # This software is distributed WITHOUT ANY WARRANTY; without even the 26 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 27 | # See the License for more information. 28 | #============================================================================= 29 | # (To distribute this file outside of CMake, substitute the full 30 | # License text for the above reference.) 31 | 32 | # debug message and logging. 33 | # comment these out for distribution 34 | IF (NOT LOGFILE ) 35 | # SET(LOGFILE "${PROJECT_BINARY_DIR}/CMakeOutput.log") 36 | ENDIF (NOT LOGFILE ) 37 | MACRO(MSG _MSG) 38 | # FILE(APPEND ${LOGFILE} "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}\n") 39 | # MESSAGE(STATUS "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${_MSG}") 40 | ENDMACRO(MSG) 41 | 42 | 43 | MSG("wxWidgets_FOUND=${wxWidgets_FOUND}") 44 | IF (wxWidgets_FOUND) 45 | IF (wxWidgets_INCLUDE_DIRS) 46 | IF(wxWidgets_INCLUDE_DIRS_NO_SYSTEM) 47 | INCLUDE_DIRECTORIES(${wxWidgets_INCLUDE_DIRS}) 48 | ELSE(wxWidgets_INCLUDE_DIRS_NO_SYSTEM) 49 | INCLUDE_DIRECTORIES(SYSTEM ${wxWidgets_INCLUDE_DIRS}) 50 | ENDIF(wxWidgets_INCLUDE_DIRS_NO_SYSTEM) 51 | MSG("wxWidgets_INCLUDE_DIRS=${wxWidgets_INCLUDE_DIRS}") 52 | ENDIF(wxWidgets_INCLUDE_DIRS) 53 | 54 | IF (wxWidgets_LIBRARY_DIRS) 55 | LINK_DIRECTORIES(${wxWidgets_LIBRARY_DIRS}) 56 | MSG("wxWidgets_LIBRARY_DIRS=${wxWidgets_LIBRARY_DIRS}") 57 | ENDIF(wxWidgets_LIBRARY_DIRS) 58 | 59 | IF (wxWidgets_DEFINITIONS) 60 | SET_PROPERTY(DIRECTORY APPEND 61 | PROPERTY COMPILE_DEFINITIONS ${wxWidgets_DEFINITIONS}) 62 | MSG("wxWidgets_DEFINITIONS=${wxWidgets_DEFINITIONS}") 63 | ENDIF(wxWidgets_DEFINITIONS) 64 | 65 | IF (wxWidgets_DEFINITIONS_DEBUG) 66 | SET_PROPERTY(DIRECTORY APPEND 67 | PROPERTY COMPILE_DEFINITIONS_DEBUG ${wxWidgets_DEFINITIONS_DEBUG}) 68 | MSG("wxWidgets_DEFINITIONS_DEBUG=${wxWidgets_DEFINITIONS_DEBUG}") 69 | ENDIF(wxWidgets_DEFINITIONS_DEBUG) 70 | 71 | IF (wxWidgets_CXX_FLAGS) 72 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${wxWidgets_CXX_FLAGS}") 73 | MSG("wxWidgets_CXX_FLAGS=${wxWidgets_CXX_FLAGS}") 74 | ENDIF(wxWidgets_CXX_FLAGS) 75 | 76 | # DEPRECATED JW 77 | # just for backward compatibility: add deps to all targets 78 | # library projects better use advanced FIND_PACKAGE(wxWidgets) directly. 79 | #IF(wxWidgets_LIBRARIES) 80 | # LINK_LIBRARIES(${wxWidgets_LIBRARIES}) 81 | # # BUG: str too long: MSG("wxWidgets_LIBRARIES=${wxWidgets_LIBRARIES}") 82 | # IF(LOGFILE) 83 | # FILE(APPEND ${LOGFILE} "${CMAKE_CURRENT_LIST_FILE}(${CMAKE_CURRENT_LIST_LINE}): ${wxWidgets_LIBRARIES}\n") 84 | # ENDIF(LOGFILE) 85 | #ENDIF(wxWidgets_LIBRARIES) 86 | 87 | ELSE (wxWidgets_FOUND) 88 | MESSAGE("wxWidgets requested but not found.") 89 | ENDIF(wxWidgets_FOUND) 90 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/scenegraph.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file scenegraph.h 26 | * defines the basic data set required to represent a 3D model; 27 | * this model must remain compatible with VRML2.0 in order to 28 | * facilitate VRML export of scene graph data created by avaiable 29 | * 3D plugins. 30 | */ 31 | 32 | 33 | #ifndef SCENE_GRAPH_H 34 | #define SCENE_GRAPH_H 35 | 36 | #include 37 | #include "3d_cache/sg/sg_node.h" 38 | 39 | class SGSHAPE; 40 | 41 | class SCENEGRAPH : public SGNODE 42 | { 43 | private: 44 | // The following are items which may be defined for reuse 45 | // in a VRML output file. They do not necessarily correspond 46 | // to the use of DEF within a VRML input file; it is the 47 | // responsibility of the plugin to perform any necessary 48 | // conversions to comply with the restrictions imposed by 49 | // this scene graph structure 50 | std::vector< SCENEGRAPH* > m_Transforms; // local Transform nodes 51 | std::vector< SGSHAPE* > m_Shape; // local Shape nodes 52 | 53 | std::vector< SCENEGRAPH* > m_RTransforms; // referenced Transform nodes 54 | std::vector< SGSHAPE* > m_RShape; // referenced Shape nodes 55 | 56 | void unlinkNode( const SGNODE* aNode, bool isChild ); 57 | bool addNode( SGNODE* aNode, bool isChild ); 58 | 59 | public: 60 | void unlinkChildNode( const SGNODE* aNode ); 61 | void unlinkRefNode( const SGNODE* aNode ); 62 | 63 | public: 64 | // note: order of transformation is Translate, Rotate, Offset 65 | SGPOINT center; 66 | SGPOINT translation; 67 | SGVECTOR rotation_axis; 68 | double rotation_angle; // radians 69 | SGPOINT scale; 70 | SGVECTOR scale_axis; 71 | double scale_angle; // radians 72 | 73 | SCENEGRAPH( SGNODE* aParent ); 74 | virtual ~SCENEGRAPH(); 75 | 76 | virtual bool SetParent( SGNODE* aParent, bool notify = true ); 77 | SGNODE* FindNode(const char *aNodeName, const SGNODE *aCaller); 78 | bool AddRefNode( SGNODE* aNode ); 79 | bool AddChildNode( SGNODE* aNode ); 80 | 81 | void ReNameNodes( void ); 82 | bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ); 83 | 84 | bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ); 85 | bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ); 86 | 87 | bool Prepare( const glm::dmat4* aTransform, 88 | S3D::MATLIST& materials, std::vector< SMESH >& meshes ); 89 | }; 90 | 91 | /* 92 | p.120 93 | Transform { 94 | center 0 0 0 95 | children [] 96 | rotation 0 0 1 0 97 | scale 1 1 1 98 | scaleOrientation 0 0 1 0 99 | translation 0 0 0 100 | bboxCenter 0 0 0 101 | bboxSize -1 -1 -1 102 | } 103 | */ 104 | 105 | #endif // SCENE_GRAPH_H 106 | -------------------------------------------------------------------------------- /include/plugins/3dapi/c3dmodel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Mario Luzeiro 5 | * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU General Public License 9 | * as published by the Free Software Foundation; either version 2 10 | * of the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, you may find one here: 19 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 20 | * or you may search the http://www.gnu.org website for the version 2 license, 21 | * or you may write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 23 | */ 24 | 25 | /** 26 | * @file c3dmodel.h 27 | * @brief define an internal structure to be used by the 3D renders 28 | */ 29 | 30 | 31 | #ifndef C3DMODEL_H 32 | #define C3DMODEL_H 33 | 34 | #include "plugins/3dapi/xv3d_types.h" 35 | 36 | 37 | typedef struct 38 | { 39 | SFVEC3F m_Ambient; // 40 | SFVEC3F m_Diffuse; ///< Default diffuse color if m_Color is NULL 41 | SFVEC3F m_Emissive; // 42 | SFVEC3F m_Specular; // 43 | float m_Shininess; // 44 | float m_Transparency; ///< 1.0 is completely transparent, 0.0 completely opaque 45 | 46 | // !TODO: to be implemented 47 | /*struct textures 48 | { 49 | wxString m_Ambient; // map_Ka 50 | wxString m_Diffuse; // map_Kd 51 | wxString m_Specular; // map_Ks 52 | wxString m_Specular_highlight; // map_Ns 53 | wxString m_Bump; // map_bump, bump 54 | wxString m_Displacement; // disp 55 | wxString m_Alpha; // map_d 56 | };*/ 57 | } SMATERIAL; 58 | 59 | 60 | /// Per-vertex normal/color/texcoors structure. 61 | /// CONDITIONS: 62 | /// m_Positions size == m_Normals size == m_Texcoords size == m_Color size 63 | /// m_Texcoords can be NULL, textures will not be applied in that case 64 | /// m_Color can be NULL, it will use the m_Diffuse color for every triangle 65 | /// any m_FaceIdx must be an index of a the element lists 66 | /// m_MaterialIdx must be an existent material index stored in the parent model 67 | /// SCALES: 68 | /// m_Positions units are in mm, example: 69 | /// 0.1 unit == 0.1 mm 70 | /// 1.0 unit == 1.0 mm 71 | /// 10.0 unit == 10.0 mm 72 | /// 73 | /// To convert this units to pcbunits, use the convertion facto UNITS3D_TO_UNITSPCB 74 | /// 75 | /// m_Normals, m_Color and m_Texcoords are beween 0.0f and 1.0f 76 | typedef struct 77 | { 78 | unsigned int m_VertexSize; ///< Number of vertex in the arrays 79 | SFVEC3F *m_Positions; ///< Vertex position array 80 | SFVEC3F *m_Normals; ///< Vertex normals array 81 | SFVEC2F *m_Texcoords; ///< Vertex texture coordinates array, can be NULL 82 | SFVEC3F *m_Color; ///< Vertex color array, can be NULL 83 | unsigned int m_FaceIdxSize; ///< Number of elements of the m_FaceIdx array 84 | unsigned int *m_FaceIdx; ///< Triangle Face Indexes 85 | unsigned int m_MaterialIdx; ///< Material Index to be used in this mesh (must be < m_MaterialsSize ) 86 | } SMESH; 87 | 88 | 89 | /// Store the a model based on meshes and materials 90 | typedef struct 91 | { 92 | unsigned int m_MeshesSize; ///< Number of meshes in the array 93 | SMESH *m_Meshes; ///< The meshes list of this model 94 | 95 | unsigned int m_MaterialsSize; ///< Number of materials in the material array 96 | SMATERIAL *m_Materials; ///< The materials list of this model 97 | } S3DMODEL; 98 | 99 | #endif // C3DMODEL_H 100 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/ifsg_coordindex.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "plugins/3dapi/ifsg_coordindex.h" 30 | #include "3d_cache/sg/sg_coordindex.h" 31 | 32 | 33 | extern char BadObject[]; 34 | extern char BadOperand[]; 35 | extern char BadParent[]; 36 | extern char WrongParent[]; 37 | 38 | 39 | IFSG_COORDINDEX::IFSG_COORDINDEX( bool create ) 40 | { 41 | m_node = NULL; 42 | 43 | if( !create ) 44 | return; 45 | 46 | m_node = new SGCOORDINDEX( NULL ); 47 | 48 | if( m_node ) 49 | m_node->AssociateWrapper( &m_node ); 50 | 51 | return; 52 | } 53 | 54 | 55 | IFSG_COORDINDEX::IFSG_COORDINDEX( SGNODE* aParent ) 56 | { 57 | m_node = new SGCOORDINDEX( NULL ); 58 | 59 | if( !m_node->SetParent( aParent ) ) 60 | { 61 | delete m_node; 62 | m_node = NULL; 63 | 64 | #ifdef DEBUG 65 | std::ostringstream ostr; 66 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 67 | ostr << WrongParent; 68 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 69 | #endif 70 | 71 | return; 72 | } 73 | 74 | m_node->AssociateWrapper( &m_node ); 75 | 76 | return; 77 | } 78 | 79 | 80 | IFSG_COORDINDEX::IFSG_COORDINDEX( IFSG_NODE& aParent ) 81 | { 82 | SGNODE* pp = aParent.GetRawPtr(); 83 | 84 | if( !pp ) 85 | { 86 | #ifdef DEBUG 87 | std::ostringstream ostr; 88 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 89 | ostr << BadParent; 90 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 91 | #endif 92 | 93 | return; 94 | } 95 | 96 | m_node = new SGCOORDINDEX( NULL ); 97 | 98 | if( !m_node->SetParent( pp ) ) 99 | { 100 | #ifdef DEBUG 101 | std::ostringstream ostr; 102 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 103 | ostr << WrongParent; 104 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 105 | #endif 106 | 107 | delete m_node; 108 | m_node = NULL; 109 | return; 110 | } 111 | 112 | m_node->AssociateWrapper( &m_node ); 113 | 114 | return; 115 | } 116 | 117 | 118 | bool IFSG_COORDINDEX::Attach( SGNODE* aNode ) 119 | { 120 | if( m_node ) 121 | m_node->DisassociateWrapper( &m_node ); 122 | 123 | m_node = NULL; 124 | 125 | if( !aNode ) 126 | return false; 127 | 128 | if( S3D::SGTYPE_COORDINDEX != aNode->GetNodeType() ) 129 | { 130 | return false; 131 | } 132 | 133 | m_node = aNode; 134 | m_node->AssociateWrapper( &m_node ); 135 | 136 | return true; 137 | } 138 | 139 | 140 | bool IFSG_COORDINDEX::NewNode( SGNODE* aParent ) 141 | { 142 | if( m_node ) 143 | m_node->DisassociateWrapper( &m_node ); 144 | 145 | m_node = new SGCOORDINDEX( aParent ); 146 | 147 | if( aParent != m_node->GetParent() ) 148 | { 149 | #ifdef DEBUG 150 | std::ostringstream ostr; 151 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 152 | ostr << " * [BUG] invalid SGNODE parent ("; 153 | ostr << aParent->GetNodeTypeName( aParent->GetNodeType() ); 154 | ostr << ") to SGCOORDINDEX"; 155 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 156 | #endif 157 | 158 | delete m_node; 159 | m_node = NULL; 160 | return false; 161 | } 162 | 163 | m_node->AssociateWrapper( &m_node ); 164 | 165 | return true; 166 | } 167 | 168 | 169 | bool IFSG_COORDINDEX::NewNode( IFSG_NODE& aParent ) 170 | { 171 | SGNODE* np = aParent.GetRawPtr(); 172 | 173 | if( NULL == np ) 174 | { 175 | #ifdef DEBUG 176 | std::ostringstream ostr; 177 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 178 | ostr << BadParent; 179 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 180 | #endif 181 | 182 | return false; 183 | } 184 | 185 | return NewNode( np ); 186 | } 187 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/ifsg_shape.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "plugins/3dapi/ifsg_shape.h" 30 | #include "3d_cache/sg/sg_shape.h" 31 | 32 | 33 | extern char BadObject[]; 34 | extern char BadOperand[]; 35 | extern char BadParent[]; 36 | extern char WrongParent[]; 37 | 38 | 39 | IFSG_SHAPE::IFSG_SHAPE( bool create ) 40 | { 41 | m_node = NULL; 42 | 43 | if( !create ) 44 | return ; 45 | 46 | m_node = new SGSHAPE( NULL ); 47 | 48 | if( m_node ) 49 | m_node->AssociateWrapper( &m_node ); 50 | 51 | return; 52 | } 53 | 54 | 55 | IFSG_SHAPE::IFSG_SHAPE( SGNODE* aParent ) 56 | { 57 | m_node = new SGSHAPE( NULL ); 58 | 59 | if( m_node ) 60 | { 61 | if( !m_node->SetParent( aParent ) ) 62 | { 63 | delete m_node; 64 | m_node = NULL; 65 | 66 | #ifdef DEBUG 67 | std::ostringstream ostr; 68 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 69 | ostr << WrongParent; 70 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 71 | #endif 72 | 73 | return; 74 | } 75 | 76 | m_node->AssociateWrapper( &m_node ); 77 | } 78 | 79 | return; 80 | } 81 | 82 | 83 | IFSG_SHAPE::IFSG_SHAPE( IFSG_NODE& aParent ) 84 | { 85 | SGNODE* pp = aParent.GetRawPtr(); 86 | 87 | #ifdef DEBUG 88 | if( ! pp ) 89 | { 90 | std::ostringstream ostr; 91 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 92 | ostr << BadParent; 93 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 94 | } 95 | #endif 96 | 97 | m_node = new SGSHAPE( NULL ); 98 | 99 | if( m_node ) 100 | { 101 | if( !m_node->SetParent( pp ) ) 102 | { 103 | delete m_node; 104 | m_node = NULL; 105 | 106 | #ifdef DEBUG 107 | std::ostringstream ostr; 108 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 109 | ostr << WrongParent; 110 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 111 | #endif 112 | 113 | return; 114 | } 115 | 116 | m_node->AssociateWrapper( &m_node ); 117 | } 118 | 119 | return; 120 | } 121 | 122 | 123 | bool IFSG_SHAPE::Attach( SGNODE* aNode ) 124 | { 125 | if( m_node ) 126 | m_node->DisassociateWrapper( &m_node ); 127 | 128 | m_node = NULL; 129 | 130 | if( !aNode ) 131 | return false; 132 | 133 | if( S3D::SGTYPE_SHAPE != aNode->GetNodeType() ) 134 | { 135 | return false; 136 | } 137 | 138 | m_node = aNode; 139 | m_node->AssociateWrapper( &m_node ); 140 | 141 | return true; 142 | } 143 | 144 | 145 | bool IFSG_SHAPE::NewNode( SGNODE* aParent ) 146 | { 147 | if( m_node ) 148 | m_node->DisassociateWrapper( &m_node ); 149 | 150 | m_node = new SGSHAPE( aParent ); 151 | 152 | if( aParent != m_node->GetParent() ) 153 | { 154 | #ifdef DEBUG 155 | std::ostringstream ostr; 156 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 157 | ostr << " * [BUG] invalid SGNODE parent ("; 158 | ostr << aParent->GetNodeTypeName( aParent->GetNodeType() ); 159 | ostr << ") to SGSHAPE"; 160 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 161 | #endif 162 | 163 | delete m_node; 164 | m_node = NULL; 165 | return false; 166 | } 167 | 168 | m_node->AssociateWrapper( &m_node ); 169 | 170 | return true; 171 | } 172 | 173 | 174 | bool IFSG_SHAPE::NewNode( IFSG_NODE& aParent ) 175 | { 176 | SGNODE* np = aParent.GetRawPtr(); 177 | 178 | if( NULL == np ) 179 | { 180 | #ifdef DEBUG 181 | std::ostringstream ostr; 182 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 183 | ostr << BadParent; 184 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 185 | #endif 186 | 187 | return false; 188 | } 189 | 190 | return NewNode( np ); 191 | } 192 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/ifsg_faceset.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "plugins/3dapi/ifsg_faceset.h" 30 | #include "3d_cache/sg/sg_faceset.h" 31 | 32 | 33 | extern char BadObject[]; 34 | extern char BadParent[]; 35 | extern char WrongParent[]; 36 | 37 | 38 | IFSG_FACESET::IFSG_FACESET( bool create ) 39 | { 40 | m_node = NULL; 41 | 42 | if( !create ) 43 | return ; 44 | 45 | m_node = new SGFACESET( NULL ); 46 | 47 | if( m_node ) 48 | m_node->AssociateWrapper( &m_node ); 49 | 50 | return; 51 | } 52 | 53 | 54 | IFSG_FACESET::IFSG_FACESET( SGNODE* aParent ) 55 | { 56 | m_node = new SGFACESET( NULL ); 57 | 58 | if( m_node ) 59 | { 60 | if( !m_node->SetParent( aParent ) ) 61 | { 62 | delete m_node; 63 | m_node = NULL; 64 | 65 | #ifdef DEBUG 66 | std::ostringstream ostr; 67 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 68 | ostr << WrongParent; 69 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 70 | #endif 71 | 72 | return; 73 | } 74 | 75 | m_node->AssociateWrapper( &m_node ); 76 | } 77 | 78 | return; 79 | } 80 | 81 | 82 | IFSG_FACESET::IFSG_FACESET( IFSG_NODE& aParent ) 83 | { 84 | SGNODE* pp = aParent.GetRawPtr(); 85 | 86 | #ifdef DEBUG 87 | if( ! pp ) 88 | { 89 | std::ostringstream ostr; 90 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 91 | ostr << BadParent; 92 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 93 | } 94 | #endif 95 | 96 | m_node = new SGFACESET( NULL ); 97 | 98 | if( m_node ) 99 | { 100 | if( !m_node->SetParent( pp ) ) 101 | { 102 | delete m_node; 103 | m_node = NULL; 104 | 105 | #ifdef DEBUG 106 | std::ostringstream ostr; 107 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 108 | ostr << WrongParent; 109 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 110 | #endif 111 | 112 | return; 113 | } 114 | 115 | m_node->AssociateWrapper( &m_node ); 116 | } 117 | 118 | return; 119 | } 120 | 121 | 122 | bool IFSG_FACESET::Attach( SGNODE* aNode ) 123 | { 124 | if( m_node ) 125 | m_node->DisassociateWrapper( &m_node ); 126 | 127 | m_node = NULL; 128 | 129 | if( !aNode ) 130 | return false; 131 | 132 | if( S3D::SGTYPE_FACESET != aNode->GetNodeType() ) 133 | { 134 | return false; 135 | } 136 | 137 | m_node = aNode; 138 | m_node->AssociateWrapper( &m_node ); 139 | 140 | return true; 141 | } 142 | 143 | 144 | bool IFSG_FACESET::NewNode( SGNODE* aParent ) 145 | { 146 | if( m_node ) 147 | m_node->DisassociateWrapper( &m_node ); 148 | 149 | m_node = new SGFACESET( aParent ); 150 | 151 | if( aParent != m_node->GetParent() ) 152 | { 153 | #ifdef DEBUG 154 | std::ostringstream ostr; 155 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 156 | ostr << " * [BUG] invalid SGNODE parent ("; 157 | ostr << aParent->GetNodeTypeName( aParent->GetNodeType() ); 158 | ostr << ") to SGFACESET"; 159 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 160 | #endif 161 | 162 | delete m_node; 163 | m_node = NULL; 164 | return false; 165 | } 166 | 167 | m_node->AssociateWrapper( &m_node ); 168 | 169 | return true; 170 | } 171 | 172 | 173 | bool IFSG_FACESET::NewNode( IFSG_NODE& aParent ) 174 | { 175 | SGNODE* np = aParent.GetRawPtr(); 176 | 177 | if( NULL == np ) 178 | { 179 | #ifdef DEBUG 180 | std::ostringstream ostr; 181 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 182 | ostr << BadParent; 183 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 184 | #endif 185 | 186 | return false; 187 | } 188 | 189 | return NewNode( np ); 190 | } 191 | 192 | 193 | bool IFSG_FACESET::CalcNormals( SGNODE** aPtr ) 194 | { 195 | if( m_node ) 196 | return ((SGFACESET*)m_node)->CalcNormals( aPtr ); 197 | 198 | return false; 199 | } 200 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_node.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_node.h 26 | * defines the wrapper of the base class SG_NODE 27 | */ 28 | 29 | /* 30 | * NOTES: 31 | * 1. The IFSG wrapper classes shall be aimed at creating a VRML-like 32 | * intermediate scenegraph representation. Although objects are 33 | * readily created and added to the structure, no provision shall 34 | * be made to inspect the structures in detail. For example the 35 | * SCENEGRAPH class may contain various SGSHAPE and SCENEGRAPH 36 | * nodes but there shall be no provision to extract those nodes. 37 | * This was done because in principle all the detailed data shall 38 | * only be handled within the SG* classes and only data processed 39 | * via GetRenderData() shall be available via the wrappers. 40 | */ 41 | 42 | #ifndef IFSG_NODE_H 43 | #define IFSG_NODE_H 44 | 45 | #include "plugins/3dapi/sg_base.h" 46 | #include "plugins/3dapi/sg_types.h" 47 | 48 | class SGNODE; 49 | 50 | /** 51 | * Class IFSG_NODE 52 | * represents the base class of all DLL-safe Scene Graph nodes 53 | */ 54 | class SGLIB_API IFSG_NODE 55 | { 56 | private: 57 | // hide the copy constructors and assignment operator to avoid accidental misuse 58 | IFSG_NODE( const IFSG_NODE& aParent ); 59 | IFSG_NODE( IFSG_NODE& aParent ); 60 | IFSG_NODE( volatile const IFSG_NODE& aParent ); 61 | IFSG_NODE( volatile IFSG_NODE& aParent ); 62 | IFSG_NODE& operator= ( const IFSG_NODE& ); 63 | 64 | protected: 65 | SGNODE* m_node; 66 | 67 | public: 68 | IFSG_NODE(); 69 | virtual ~IFSG_NODE(); 70 | 71 | /** 72 | * Function Destroy 73 | * deletes the object held by this wrapper 74 | */ 75 | void Destroy( void ); 76 | 77 | /** 78 | * Function Attach 79 | * associates a given SGNODE* with this wrapper 80 | */ 81 | virtual bool Attach( SGNODE* aNode ) = 0; 82 | 83 | /** 84 | * Function NewNode 85 | * creates a new node to associate with this wrapper 86 | */ 87 | virtual bool NewNode( SGNODE* aParent ) = 0; 88 | virtual bool NewNode( IFSG_NODE& aParent ) = 0; 89 | 90 | /** 91 | * Function GetRawPtr() 92 | * returns the raw internal SGNODE pointer 93 | */ 94 | SGNODE* GetRawPtr( void ); 95 | 96 | /** 97 | * Function GetNodeType 98 | * returns the type of this node instance 99 | */ 100 | S3D::SGTYPES GetNodeType( void ) const; 101 | 102 | /** 103 | * Function GetParent 104 | * returns a pointer to the parent SGNODE of this object 105 | * or NULL if the object has no parent (ie. top level transform). 106 | */ 107 | SGNODE* GetParent( void ) const; 108 | 109 | /** 110 | * Function SetParent 111 | * sets the parent SGNODE of this object. 112 | * 113 | * @param aParent [in] is the desired parent node 114 | * @return true if the operation succeeds; false if 115 | * the given node is not allowed to be a parent to 116 | * the derived object 117 | */ 118 | bool SetParent( SGNODE* aParent ); 119 | 120 | /** 121 | * Function GetName 122 | * returns a pointer to the node name (NULL if no name assigned) 123 | */ 124 | const char* GetName( void ); 125 | 126 | /** 127 | * Function SetName 128 | * sets the node's name; if the pointer passed is NULL 129 | * then the node's name is erased 130 | * 131 | * @return true on success 132 | */ 133 | bool SetName( const char *aName ); 134 | 135 | /** 136 | * Function GetNodeTypeName 137 | * returns the text representation of the node type 138 | * or NULL if the node somehow has an invalid type 139 | */ 140 | const char * GetNodeTypeName( S3D::SGTYPES aNodeType ) const; 141 | 142 | /** 143 | * Function FindNode searches the tree of linked nodes and returns a 144 | * reference to the first node found with the given name. The reference 145 | * is then typically added to another node via AddRefNode(). 146 | * 147 | * @param aNodeName is the name of the node to search for 148 | * @param aCaller is a pointer to the node invoking this function 149 | * @return is a valid node pointer on success, otherwise NULL 150 | */ 151 | SGNODE* FindNode( const char *aNodeName ); 152 | 153 | /** 154 | * Function AddRefNode 155 | * adds a reference to an existing node which is not owned by 156 | * (not a child of) this node. 157 | * 158 | * @return true on success 159 | */ 160 | bool AddRefNode( SGNODE* aNode ); 161 | bool AddRefNode( IFSG_NODE& aNode ); 162 | 163 | /** 164 | * Function AddChildNode 165 | * adds a node as a child owned by this node. 166 | * 167 | * @return true on success 168 | */ 169 | bool AddChildNode( SGNODE* aNode ); 170 | bool AddChildNode( IFSG_NODE& aNode ); 171 | }; 172 | 173 | #endif // IFSG_NODE_H 174 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/ifsg_coords.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "plugins/3dapi/ifsg_coords.h" 29 | #include "3d_cache/sg/sg_coords.h" 30 | 31 | 32 | extern char BadObject[]; 33 | extern char BadParent[]; 34 | extern char WrongParent[]; 35 | 36 | 37 | IFSG_COORDS::IFSG_COORDS( bool create ) 38 | { 39 | m_node = NULL; 40 | 41 | if( !create ) 42 | return ; 43 | 44 | m_node = new SGCOORDS( NULL ); 45 | 46 | if( m_node ) 47 | m_node->AssociateWrapper( &m_node ); 48 | 49 | return; 50 | } 51 | 52 | 53 | IFSG_COORDS::IFSG_COORDS( SGNODE* aParent ) 54 | { 55 | m_node = new SGCOORDS( NULL ); 56 | 57 | if( m_node ) 58 | { 59 | if( !m_node->SetParent( aParent ) ) 60 | { 61 | delete m_node; 62 | m_node = NULL; 63 | 64 | #ifdef DEBUG 65 | std::ostringstream ostr; 66 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 67 | ostr << WrongParent; 68 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 69 | #endif 70 | 71 | return; 72 | } 73 | 74 | m_node->AssociateWrapper( &m_node ); 75 | } 76 | 77 | return; 78 | } 79 | 80 | 81 | IFSG_COORDS::IFSG_COORDS( IFSG_NODE& aParent ) 82 | { 83 | SGNODE* pp = aParent.GetRawPtr(); 84 | 85 | #ifdef DEBUG 86 | if( ! pp ) 87 | { 88 | std::ostringstream ostr; 89 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 90 | ostr << BadParent; 91 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 92 | } 93 | #endif 94 | 95 | m_node = new SGCOORDS( NULL ); 96 | 97 | if( m_node ) 98 | { 99 | if( !m_node->SetParent( pp ) ) 100 | { 101 | delete m_node; 102 | m_node = NULL; 103 | 104 | #ifdef DEBUG 105 | std::ostringstream ostr; 106 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 107 | ostr << WrongParent; 108 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 109 | #endif 110 | 111 | return; 112 | } 113 | 114 | m_node->AssociateWrapper( &m_node ); 115 | } 116 | 117 | return; 118 | } 119 | 120 | 121 | bool IFSG_COORDS::Attach( SGNODE* aNode ) 122 | { 123 | if( m_node ) 124 | m_node->DisassociateWrapper( &m_node ); 125 | 126 | m_node = NULL; 127 | 128 | if( !aNode ) 129 | return false; 130 | 131 | if( S3D::SGTYPE_COORDS != aNode->GetNodeType() ) 132 | { 133 | return false; 134 | } 135 | 136 | m_node = aNode; 137 | m_node->AssociateWrapper( &m_node ); 138 | 139 | return true; 140 | } 141 | 142 | 143 | bool IFSG_COORDS::NewNode( SGNODE* aParent ) 144 | { 145 | if( m_node ) 146 | m_node->DisassociateWrapper( &m_node ); 147 | 148 | m_node = new SGCOORDS( aParent ); 149 | 150 | if( aParent != m_node->GetParent() ) 151 | { 152 | #ifdef DEBUG 153 | std::ostringstream ostr; 154 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 155 | ostr << " * [BUG] invalid SGNODE parent ("; 156 | ostr << aParent->GetNodeTypeName( aParent->GetNodeType() ); 157 | ostr << ") to SGCOORDS"; 158 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 159 | #endif 160 | 161 | delete m_node; 162 | m_node = NULL; 163 | return false; 164 | } 165 | 166 | m_node->AssociateWrapper( &m_node ); 167 | 168 | return true; 169 | } 170 | 171 | 172 | bool IFSG_COORDS::NewNode( IFSG_NODE& aParent ) 173 | { 174 | SGNODE* np = aParent.GetRawPtr(); 175 | 176 | if( NULL == np ) 177 | { 178 | #ifdef DEBUG 179 | std::ostringstream ostr; 180 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 181 | ostr << BadParent; 182 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 183 | #endif 184 | 185 | return false; 186 | } 187 | 188 | return NewNode( np ); 189 | } 190 | 191 | 192 | bool IFSG_COORDS::GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList ) 193 | { 194 | if( NULL == m_node ) 195 | { 196 | #ifdef DEBUG 197 | std::ostringstream ostr; 198 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 199 | ostr << BadObject; 200 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 201 | #endif 202 | 203 | return false; 204 | } 205 | 206 | return ((SGCOORDS*)m_node)->GetCoordsList( aListSize, aCoordsList ); 207 | } 208 | 209 | 210 | bool IFSG_COORDS::SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList ) 211 | { 212 | if( NULL == m_node ) 213 | { 214 | #ifdef DEBUG 215 | std::ostringstream ostr; 216 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 217 | ostr << BadObject; 218 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 219 | #endif 220 | 221 | return false; 222 | } 223 | 224 | ((SGCOORDS*)m_node)->SetCoordsList( aListSize, aCoordsList ); 225 | 226 | return true; 227 | } 228 | 229 | 230 | bool IFSG_COORDS::AddCoord( double aXValue, double aYValue, double aZValue ) 231 | { 232 | if( NULL == m_node ) 233 | { 234 | #ifdef DEBUG 235 | std::ostringstream ostr; 236 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 237 | ostr << BadObject; 238 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 239 | #endif 240 | 241 | return false; 242 | } 243 | 244 | ((SGCOORDS*)m_node)->AddCoord( aXValue, aYValue, aZValue ); 245 | 246 | return true; 247 | } 248 | 249 | 250 | bool IFSG_COORDS::AddCoord( const SGPOINT& aPoint ) 251 | { 252 | if( NULL == m_node ) 253 | { 254 | #ifdef DEBUG 255 | std::ostringstream ostr; 256 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 257 | ostr << BadObject; 258 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 259 | #endif 260 | 261 | return false; 262 | } 263 | 264 | ((SGCOORDS*)m_node)->AddCoord( aPoint ); 265 | 266 | return true; 267 | } 268 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/ifsg_colors.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "plugins/3dapi/ifsg_colors.h" 29 | #include "3d_cache/sg/sg_colors.h" 30 | 31 | 32 | extern char BadObject[]; 33 | extern char BadParent[]; 34 | extern char WrongParent[]; 35 | 36 | 37 | IFSG_COLORS::IFSG_COLORS( bool create ) 38 | { 39 | m_node = NULL; 40 | 41 | if( !create ) 42 | return ; 43 | 44 | m_node = new SGCOLORS( NULL ); 45 | 46 | if( m_node ) 47 | m_node->AssociateWrapper( &m_node ); 48 | 49 | return; 50 | } 51 | 52 | 53 | IFSG_COLORS::IFSG_COLORS( SGNODE* aParent ) 54 | { 55 | m_node = new SGCOLORS( NULL ); 56 | 57 | if( m_node ) 58 | { 59 | if( !m_node->SetParent( aParent ) ) 60 | { 61 | delete m_node; 62 | m_node = NULL; 63 | 64 | #ifdef DEBUG 65 | std::ostringstream ostr; 66 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 67 | ostr << WrongParent; 68 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 69 | #endif 70 | 71 | return; 72 | } 73 | 74 | m_node->AssociateWrapper( &m_node ); 75 | } 76 | 77 | return; 78 | } 79 | 80 | 81 | IFSG_COLORS::IFSG_COLORS( IFSG_NODE& aParent ) 82 | { 83 | SGNODE* pp = aParent.GetRawPtr(); 84 | 85 | #ifdef DEBUG 86 | if( ! pp ) 87 | { 88 | std::ostringstream ostr; 89 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 90 | ostr << BadParent; 91 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 92 | } 93 | #endif 94 | 95 | m_node = new SGCOLORS( NULL ); 96 | 97 | if( m_node ) 98 | { 99 | if( !m_node->SetParent( pp ) ) 100 | { 101 | delete m_node; 102 | m_node = NULL; 103 | 104 | #ifdef DEBUG 105 | std::ostringstream ostr; 106 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 107 | ostr << WrongParent; 108 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 109 | #endif 110 | 111 | return; 112 | } 113 | 114 | m_node->AssociateWrapper( &m_node ); 115 | } 116 | 117 | return; 118 | } 119 | 120 | 121 | bool IFSG_COLORS::Attach( SGNODE* aNode ) 122 | { 123 | if( m_node ) 124 | m_node->DisassociateWrapper( &m_node ); 125 | 126 | m_node = NULL; 127 | 128 | if( !aNode ) 129 | return false; 130 | 131 | if( S3D::SGTYPE_COLORS != aNode->GetNodeType() ) 132 | { 133 | return false; 134 | } 135 | 136 | m_node = aNode; 137 | m_node->AssociateWrapper( &m_node ); 138 | 139 | return true; 140 | } 141 | 142 | 143 | bool IFSG_COLORS::NewNode( SGNODE* aParent ) 144 | { 145 | if( m_node ) 146 | m_node->DisassociateWrapper( &m_node ); 147 | 148 | m_node = new SGCOLORS( aParent ); 149 | 150 | if( aParent != m_node->GetParent() ) 151 | { 152 | #ifdef DEBUG 153 | std::ostringstream ostr; 154 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 155 | ostr << " * [BUG] invalid SGNODE parent ("; 156 | ostr << aParent->GetNodeTypeName( aParent->GetNodeType() ); 157 | ostr << ") to SGCOLORS"; 158 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 159 | #endif 160 | 161 | delete m_node; 162 | m_node = NULL; 163 | return false; 164 | } 165 | 166 | m_node->AssociateWrapper( &m_node ); 167 | 168 | return true; 169 | } 170 | 171 | 172 | bool IFSG_COLORS::NewNode( IFSG_NODE& aParent ) 173 | { 174 | SGNODE* np = aParent.GetRawPtr(); 175 | 176 | if( NULL == np ) 177 | { 178 | #ifdef DEBUG 179 | std::ostringstream ostr; 180 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 181 | ostr << BadParent; 182 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 183 | #endif 184 | 185 | return false; 186 | } 187 | 188 | return NewNode( np ); 189 | } 190 | 191 | 192 | bool IFSG_COLORS::GetColorList( size_t& aListSize, SGCOLOR*& aColorList ) 193 | { 194 | if( NULL == m_node ) 195 | { 196 | #ifdef DEBUG 197 | std::ostringstream ostr; 198 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 199 | ostr << BadObject; 200 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 201 | #endif 202 | 203 | return false; 204 | } 205 | 206 | return ((SGCOLORS*)m_node)->GetColorList( aListSize, aColorList ); 207 | } 208 | 209 | 210 | bool IFSG_COLORS::SetColorList( size_t aListSize, const SGCOLOR* aColorList ) 211 | { 212 | if( NULL == m_node ) 213 | { 214 | #ifdef DEBUG 215 | std::ostringstream ostr; 216 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 217 | ostr << BadObject; 218 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 219 | #endif 220 | 221 | return false; 222 | } 223 | 224 | ((SGCOLORS*)m_node)->SetColorList( aListSize, aColorList ); 225 | 226 | return true; 227 | } 228 | 229 | 230 | bool IFSG_COLORS::AddColor( double aRedValue, double aGreenValue, double aBlueValue ) 231 | { 232 | if( NULL == m_node ) 233 | { 234 | #ifdef DEBUG 235 | std::ostringstream ostr; 236 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 237 | ostr << BadObject; 238 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 239 | #endif 240 | 241 | return false; 242 | } 243 | 244 | ((SGCOLORS*)m_node)->AddColor( aRedValue, aGreenValue, aBlueValue ); 245 | 246 | return true; 247 | } 248 | 249 | 250 | bool IFSG_COLORS::AddColor( const SGCOLOR& aColor ) 251 | { 252 | if( NULL == m_node ) 253 | { 254 | #ifdef DEBUG 255 | std::ostringstream ostr; 256 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 257 | ostr << BadObject; 258 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 259 | #endif 260 | 261 | return false; 262 | } 263 | 264 | ((SGCOLORS*)m_node)->AddColor( aColor ); 265 | 266 | return true; 267 | } 268 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/ifsg_normals.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "plugins/3dapi/ifsg_normals.h" 30 | #include "3d_cache/sg/sg_normals.h" 31 | 32 | 33 | extern char BadObject[]; 34 | extern char BadOperand[]; 35 | extern char BadParent[]; 36 | extern char WrongParent[]; 37 | 38 | 39 | IFSG_NORMALS::IFSG_NORMALS( bool create ) 40 | { 41 | m_node = NULL; 42 | 43 | if( !create ) 44 | return; 45 | 46 | m_node = new SGNORMALS( NULL ); 47 | 48 | if( m_node ) 49 | m_node->AssociateWrapper( &m_node ); 50 | 51 | return; 52 | } 53 | 54 | 55 | IFSG_NORMALS::IFSG_NORMALS( SGNODE* aParent ) 56 | { 57 | m_node = new SGNORMALS( NULL ); 58 | 59 | if( m_node ) 60 | { 61 | if( !m_node->SetParent( aParent ) ) 62 | { 63 | delete m_node; 64 | m_node = NULL; 65 | 66 | #ifdef DEBUG 67 | std::ostringstream ostr; 68 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 69 | ostr << WrongParent; 70 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 71 | #endif 72 | 73 | return; 74 | } 75 | 76 | m_node->AssociateWrapper( &m_node ); 77 | } 78 | 79 | return; 80 | } 81 | 82 | 83 | IFSG_NORMALS::IFSG_NORMALS( IFSG_NODE& aParent ) 84 | { 85 | SGNODE* pp = aParent.GetRawPtr(); 86 | 87 | #ifdef DEBUG 88 | if( ! pp ) 89 | { 90 | std::ostringstream ostr; 91 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 92 | ostr << BadParent; 93 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 94 | } 95 | #endif 96 | 97 | m_node = new SGNORMALS( NULL ); 98 | 99 | if( m_node ) 100 | { 101 | if( !m_node->SetParent( pp ) ) 102 | { 103 | delete m_node; 104 | m_node = NULL; 105 | 106 | #ifdef DEBUG 107 | std::ostringstream ostr; 108 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 109 | ostr << WrongParent; 110 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 111 | #endif 112 | 113 | return; 114 | } 115 | 116 | m_node->AssociateWrapper( &m_node ); 117 | } 118 | 119 | return; 120 | } 121 | 122 | 123 | bool IFSG_NORMALS::Attach( SGNODE* aNode ) 124 | { 125 | if( m_node ) 126 | m_node->DisassociateWrapper( &m_node ); 127 | 128 | m_node = NULL; 129 | 130 | if( !aNode ) 131 | return false; 132 | 133 | if( S3D::SGTYPE_NORMALS != aNode->GetNodeType() ) 134 | { 135 | return false; 136 | } 137 | 138 | m_node = aNode; 139 | m_node->AssociateWrapper( &m_node ); 140 | 141 | return true; 142 | } 143 | 144 | 145 | bool IFSG_NORMALS::NewNode( SGNODE* aParent ) 146 | { 147 | if( m_node ) 148 | m_node->DisassociateWrapper( &m_node ); 149 | 150 | m_node = new SGNORMALS( aParent ); 151 | 152 | if( aParent != m_node->GetParent() ) 153 | { 154 | #ifdef DEBUG 155 | std::ostringstream ostr; 156 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 157 | ostr << " * [BUG] invalid SGNODE parent ("; 158 | ostr << aParent->GetNodeTypeName( aParent->GetNodeType() ); 159 | ostr << ") to SGNORMALS"; 160 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 161 | #endif 162 | 163 | delete m_node; 164 | m_node = NULL; 165 | return false; 166 | } 167 | 168 | m_node->AssociateWrapper( &m_node ); 169 | 170 | return true; 171 | } 172 | 173 | 174 | bool IFSG_NORMALS::NewNode( IFSG_NODE& aParent ) 175 | { 176 | SGNODE* np = aParent.GetRawPtr(); 177 | 178 | if( NULL == np ) 179 | { 180 | #ifdef DEBUG 181 | std::ostringstream ostr; 182 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 183 | ostr << BadParent; 184 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 185 | #endif 186 | 187 | return false; 188 | } 189 | 190 | return NewNode( np ); 191 | } 192 | 193 | 194 | bool IFSG_NORMALS::GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList ) 195 | { 196 | if( NULL == m_node ) 197 | { 198 | #ifdef DEBUG 199 | std::ostringstream ostr; 200 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 201 | ostr << BadObject; 202 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 203 | #endif 204 | 205 | return false; 206 | } 207 | 208 | return ((SGNORMALS*)m_node)->GetNormalList( aListSize, aNormalList ); 209 | } 210 | 211 | 212 | bool IFSG_NORMALS::SetNormalList( size_t aListSize, const SGVECTOR* aNormalList ) 213 | { 214 | if( NULL == m_node ) 215 | { 216 | #ifdef DEBUG 217 | std::ostringstream ostr; 218 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 219 | ostr << BadObject; 220 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 221 | #endif 222 | 223 | return false; 224 | } 225 | 226 | ((SGNORMALS*)m_node)->SetNormalList( aListSize, aNormalList ); 227 | return true; 228 | } 229 | 230 | 231 | bool IFSG_NORMALS::AddNormal( double aXValue, double aYValue, double aZValue ) 232 | { 233 | if( NULL == m_node ) 234 | { 235 | #ifdef DEBUG 236 | std::ostringstream ostr; 237 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 238 | ostr << BadObject; 239 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 240 | #endif 241 | 242 | return false; 243 | } 244 | 245 | ((SGNORMALS*)m_node)->AddNormal( aXValue, aYValue, aZValue ); 246 | return true; 247 | } 248 | 249 | 250 | bool IFSG_NORMALS::AddNormal( const SGVECTOR& aNormal ) 251 | { 252 | if( NULL == m_node ) 253 | { 254 | #ifdef DEBUG 255 | std::ostringstream ostr; 256 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 257 | ostr << BadObject; 258 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 259 | #endif 260 | 261 | return false; 262 | } 263 | 264 | ((SGNORMALS*)m_node)->AddNormal( aNormal ); 265 | return true; 266 | } 267 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/ifsg_transform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "plugins/3dapi/ifsg_transform.h" 30 | #include "3d_cache/sg/scenegraph.h" 31 | 32 | 33 | extern char BadObject[]; 34 | extern char BadOperand[]; 35 | extern char BadParent[]; 36 | extern char WrongParent[]; 37 | 38 | IFSG_TRANSFORM::IFSG_TRANSFORM( bool create ) 39 | { 40 | m_node = NULL; 41 | 42 | if( !create ) 43 | return; 44 | 45 | m_node = new SCENEGRAPH( NULL ); 46 | 47 | if( m_node ) 48 | m_node->AssociateWrapper( &m_node ); 49 | 50 | return; 51 | } 52 | 53 | 54 | IFSG_TRANSFORM::IFSG_TRANSFORM( SGNODE* aParent ) 55 | { 56 | m_node = new SCENEGRAPH( NULL ); 57 | 58 | if( m_node ) 59 | { 60 | if( !m_node->SetParent( aParent ) ) 61 | { 62 | delete m_node; 63 | m_node = NULL; 64 | 65 | #ifdef DEBUG 66 | std::ostringstream ostr; 67 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 68 | ostr << WrongParent; 69 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 70 | #endif 71 | 72 | return; 73 | } 74 | 75 | m_node->AssociateWrapper( &m_node ); 76 | } 77 | 78 | return; 79 | } 80 | 81 | 82 | bool IFSG_TRANSFORM::Attach( SGNODE* aNode ) 83 | { 84 | if( m_node ) 85 | m_node->DisassociateWrapper( &m_node ); 86 | 87 | m_node = NULL; 88 | 89 | if( !aNode ) 90 | return false; 91 | 92 | if( S3D::SGTYPE_TRANSFORM != aNode->GetNodeType() ) 93 | { 94 | return false; 95 | } 96 | 97 | m_node = aNode; 98 | m_node->AssociateWrapper( &m_node ); 99 | 100 | return true; 101 | } 102 | 103 | 104 | bool IFSG_TRANSFORM::NewNode( SGNODE* aParent ) 105 | { 106 | if( m_node ) 107 | m_node->DisassociateWrapper( &m_node ); 108 | 109 | m_node = new SCENEGRAPH( aParent ); 110 | 111 | if( aParent != m_node->GetParent() ) 112 | { 113 | #ifdef DEBUG 114 | std::ostringstream ostr; 115 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 116 | ostr << " * [BUG] invalid SGNODE parent ("; 117 | ostr << aParent->GetNodeTypeName( aParent->GetNodeType() ); 118 | ostr << ") to SCENEGRAPH"; 119 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 120 | #endif 121 | 122 | delete m_node; 123 | m_node = NULL; 124 | return false; 125 | } 126 | 127 | m_node->AssociateWrapper( &m_node ); 128 | 129 | return true; 130 | } 131 | 132 | 133 | bool IFSG_TRANSFORM::NewNode( IFSG_NODE& aParent ) 134 | { 135 | SGNODE* np = aParent.GetRawPtr(); 136 | 137 | if( NULL == np ) 138 | { 139 | #ifdef DEBUG 140 | std::ostringstream ostr; 141 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 142 | ostr << BadParent; 143 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 144 | #endif 145 | 146 | return false; 147 | } 148 | 149 | return NewNode( np ); 150 | } 151 | 152 | 153 | bool IFSG_TRANSFORM::SetRotation( const SGVECTOR& aRotationAxis, double aAngle ) 154 | { 155 | if( NULL == m_node ) 156 | { 157 | #ifdef DEBUG 158 | std::ostringstream ostr; 159 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 160 | ostr << BadObject; 161 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 162 | #endif 163 | 164 | return false; 165 | } 166 | 167 | ((SCENEGRAPH*)m_node)->rotation_axis = aRotationAxis; 168 | ((SCENEGRAPH*)m_node)->rotation_angle = aAngle; 169 | 170 | return true; 171 | } 172 | 173 | 174 | bool IFSG_TRANSFORM::SetScale( const SGPOINT& aScale ) 175 | { 176 | if( NULL == m_node ) 177 | { 178 | #ifdef DEBUG 179 | std::ostringstream ostr; 180 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 181 | ostr << BadObject; 182 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 183 | #endif 184 | 185 | return false; 186 | } 187 | 188 | ((SCENEGRAPH*)m_node)->scale = aScale; 189 | 190 | return true; 191 | } 192 | 193 | 194 | bool IFSG_TRANSFORM::SetScale( double aScale ) 195 | { 196 | if( NULL == m_node ) 197 | { 198 | #ifdef DEBUG 199 | std::ostringstream ostr; 200 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 201 | ostr << BadObject; 202 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 203 | #endif 204 | 205 | return false; 206 | } 207 | 208 | if( aScale < 1e-8 && aScale > -1e-8 ) 209 | { 210 | #ifdef DEBUG 211 | std::ostringstream ostr; 212 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 213 | ostr << " * [BUG] |scale| is < 1e-8 - this seems strange"; 214 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 215 | #endif 216 | 217 | return false; 218 | } 219 | 220 | ((SCENEGRAPH*)m_node)->scale = SGPOINT( aScale, aScale, aScale ); 221 | 222 | return true; 223 | } 224 | 225 | 226 | bool IFSG_TRANSFORM::SetTranslation( const SGPOINT& aTranslation ) 227 | { 228 | if( NULL == m_node ) 229 | { 230 | #ifdef DEBUG 231 | std::ostringstream ostr; 232 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 233 | ostr << BadObject; 234 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 235 | #endif 236 | 237 | return false; 238 | } 239 | 240 | ((SCENEGRAPH*)m_node)->translation = aTranslation; 241 | 242 | return true; 243 | } 244 | 245 | 246 | bool IFSG_TRANSFORM::SetScaleOrientation( const SGVECTOR& aScaleAxis, double aAngle ) 247 | { 248 | if( NULL == m_node ) 249 | { 250 | #ifdef DEBUG 251 | std::ostringstream ostr; 252 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 253 | ostr << BadObject; 254 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 255 | #endif 256 | 257 | return false; 258 | } 259 | 260 | ((SCENEGRAPH*)m_node)->scale_axis = aScaleAxis; 261 | ((SCENEGRAPH*)m_node)->scale_angle = aAngle; 262 | 263 | return true; 264 | } 265 | 266 | 267 | bool IFSG_TRANSFORM::SetCenter( const SGPOINT& aCenter ) 268 | { 269 | if( NULL == m_node ) 270 | { 271 | #ifdef DEBUG 272 | std::ostringstream ostr; 273 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 274 | ostr << BadObject; 275 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 276 | #endif 277 | 278 | return false; 279 | } 280 | 281 | ((SCENEGRAPH*)m_node)->center = aCenter; 282 | 283 | return true; 284 | } 285 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/ifsg_node.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "plugins/3dapi/ifsg_node.h" 30 | #include "3d_cache/sg/sg_node.h" 31 | #include "plugins/3dapi/ifsg_api.h" 32 | 33 | // collection of common error strings used by the wrappers 34 | char BadObject[] = " * [BUG] operating on an invalid wrapper (object may have been deleted)"; 35 | char BadOperand[] = " * [BUG] parameter aNode is an invalid wrapper; its data may have been deleted"; 36 | char BadParent[] = " * [BUG] invalid parent node (data may have been deleted)"; 37 | char WrongParent[] = " * [BUG] parent node type is incompatible"; 38 | 39 | IFSG_NODE::IFSG_NODE() 40 | { 41 | m_node = NULL; 42 | } 43 | 44 | 45 | IFSG_NODE::~IFSG_NODE() 46 | { 47 | if( m_node ) 48 | m_node->DisassociateWrapper( &m_node ); 49 | 50 | return; 51 | } 52 | 53 | 54 | void IFSG_NODE::Destroy( void ) 55 | { 56 | if( m_node ) 57 | m_node->DisassociateWrapper( &m_node ); 58 | 59 | delete m_node; 60 | m_node = NULL; 61 | 62 | return; 63 | } 64 | 65 | 66 | SGNODE* IFSG_NODE::GetRawPtr( void ) 67 | { 68 | return m_node; 69 | } 70 | 71 | 72 | S3D::SGTYPES IFSG_NODE::GetNodeType( void ) const 73 | { 74 | if( NULL == m_node ) 75 | { 76 | #ifdef DEBUG 77 | std::ostringstream ostr; 78 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 79 | ostr << BadObject; 80 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 81 | #endif 82 | 83 | return S3D::SGTYPE_END; 84 | } 85 | 86 | return m_node->GetNodeType(); 87 | } 88 | 89 | 90 | SGNODE* IFSG_NODE::GetParent( void ) const 91 | { 92 | if( NULL == m_node ) 93 | { 94 | #ifdef DEBUG 95 | std::ostringstream ostr; 96 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 97 | ostr << BadObject; 98 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 99 | #endif 100 | 101 | return NULL; 102 | } 103 | 104 | return m_node->GetParent(); 105 | } 106 | 107 | 108 | bool IFSG_NODE::SetParent( SGNODE* aParent ) 109 | { 110 | if( NULL == m_node ) 111 | { 112 | #ifdef DEBUG 113 | std::ostringstream ostr; 114 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 115 | ostr << BadObject; 116 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 117 | #endif 118 | 119 | return false; 120 | } 121 | 122 | return m_node->SetParent( aParent ); 123 | } 124 | 125 | 126 | const char* IFSG_NODE::GetName( void ) 127 | { 128 | if( NULL == m_node ) 129 | { 130 | #ifdef DEBUG 131 | std::ostringstream ostr; 132 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 133 | ostr << BadObject; 134 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 135 | #endif 136 | 137 | return NULL; 138 | } 139 | 140 | return m_node->GetName(); 141 | } 142 | 143 | 144 | bool IFSG_NODE::SetName( const char *aName ) 145 | { 146 | if( NULL == m_node ) 147 | { 148 | #ifdef DEBUG 149 | std::ostringstream ostr; 150 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 151 | ostr << BadObject; 152 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 153 | #endif 154 | 155 | return false; 156 | } 157 | 158 | m_node->SetName( aName ); 159 | return true; 160 | } 161 | 162 | 163 | const char * IFSG_NODE::GetNodeTypeName( S3D::SGTYPES aNodeType ) const 164 | { 165 | if( NULL == m_node ) 166 | { 167 | #ifdef DEBUG 168 | std::ostringstream ostr; 169 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 170 | ostr << BadObject; 171 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 172 | #endif 173 | 174 | return NULL; 175 | } 176 | 177 | return m_node->GetNodeTypeName( aNodeType ); 178 | } 179 | 180 | 181 | SGNODE* IFSG_NODE::FindNode( const char *aNodeName ) 182 | { 183 | if( NULL == m_node ) 184 | { 185 | #ifdef DEBUG 186 | std::ostringstream ostr; 187 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 188 | ostr << BadObject; 189 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 190 | #endif 191 | 192 | return NULL; 193 | } 194 | 195 | return m_node->FindNode( aNodeName, NULL ); 196 | } 197 | 198 | 199 | bool IFSG_NODE::AddRefNode( SGNODE* aNode ) 200 | { 201 | if( NULL == m_node ) 202 | { 203 | #ifdef DEBUG 204 | std::ostringstream ostr; 205 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 206 | ostr << BadObject; 207 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 208 | #endif 209 | 210 | return false; 211 | } 212 | 213 | return m_node->AddRefNode( aNode ); 214 | } 215 | 216 | 217 | bool IFSG_NODE::AddRefNode( IFSG_NODE& aNode ) 218 | { 219 | if( NULL == m_node ) 220 | { 221 | #ifdef DEBUG 222 | std::ostringstream ostr; 223 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 224 | ostr << BadObject; 225 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 226 | #endif 227 | 228 | return false; 229 | } 230 | 231 | SGNODE* np = aNode.GetRawPtr(); 232 | 233 | if( NULL == np ) 234 | { 235 | #ifdef DEBUG 236 | std::ostringstream ostr; 237 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 238 | ostr << BadOperand; 239 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 240 | #endif 241 | 242 | return false; 243 | } 244 | 245 | return m_node->AddRefNode( np ); 246 | } 247 | 248 | 249 | bool IFSG_NODE::AddChildNode( SGNODE* aNode ) 250 | { 251 | if( NULL == m_node ) 252 | { 253 | #ifdef DEBUG 254 | std::ostringstream ostr; 255 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 256 | ostr << BadObject; 257 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 258 | #endif 259 | 260 | return false; 261 | } 262 | 263 | return m_node->AddChildNode( aNode ); 264 | } 265 | 266 | 267 | bool IFSG_NODE::AddChildNode( IFSG_NODE& aNode ) 268 | { 269 | if( NULL == m_node ) 270 | { 271 | #ifdef DEBUG 272 | std::ostringstream ostr; 273 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 274 | ostr << BadObject; 275 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 276 | #endif 277 | 278 | return false; 279 | } 280 | 281 | SGNODE* np = aNode.GetRawPtr(); 282 | 283 | if( NULL == np ) 284 | { 285 | #ifdef DEBUG 286 | std::ostringstream ostr; 287 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 288 | ostr << BadOperand; 289 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 290 | #endif 291 | 292 | return false; 293 | } 294 | 295 | return m_node->AddChildNode( np ); 296 | } 297 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_base.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "plugins/3dapi/sg_base.h" 31 | 32 | 33 | SGCOLOR::SGCOLOR() 34 | { 35 | red = 0.0; 36 | green = 0.0; 37 | blue = 0.0; 38 | 39 | return; 40 | } 41 | 42 | SGCOLOR::SGCOLOR( float aRVal, float aGVal, float aBVal ) 43 | { 44 | if( !checkRange( aRVal, aGVal, aBVal ) ) 45 | { 46 | #ifdef DEBUG 47 | std::ostringstream ostr; 48 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 49 | ostr << " * [BUG] invalid value passed to constructor"; 50 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 51 | #endif 52 | red = 0.0; 53 | green = 0.0; 54 | blue = 0.0; 55 | return; 56 | } 57 | 58 | red = aRVal; 59 | green = aGVal; 60 | blue = aBVal; 61 | return; 62 | } 63 | 64 | 65 | void SGCOLOR::GetColor( float& aRedVal, float& aGreenVal, float& aBlueVal ) const 66 | { 67 | aRedVal = red; 68 | aGreenVal = green; 69 | aBlueVal = blue; 70 | return; 71 | } 72 | 73 | 74 | void SGCOLOR::GetColor( SGCOLOR& aColor ) const 75 | { 76 | aColor.red = red; 77 | aColor.green = green; 78 | aColor.blue = blue; 79 | return; 80 | } 81 | 82 | 83 | void SGCOLOR::GetColor( SGCOLOR* aColor ) const 84 | { 85 | if( NULL == aColor ) 86 | { 87 | #ifdef DEBUG 88 | std::ostringstream ostr; 89 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 90 | ostr << " * [BUG] NULL pointer passed for aColor"; 91 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 92 | #endif 93 | 94 | return; 95 | } 96 | 97 | aColor->red = red; 98 | aColor->green = green; 99 | aColor->blue = blue; 100 | return; 101 | } 102 | 103 | 104 | bool SGCOLOR::SetColor( float aRedVal, float aGreenVal, float aBlueVal ) 105 | { 106 | if( !checkRange( aRedVal, aGreenVal, aBlueVal ) ) 107 | return false; 108 | 109 | red = aRedVal; 110 | green = aGreenVal; 111 | blue = aBlueVal; 112 | 113 | return true; 114 | } 115 | 116 | 117 | bool SGCOLOR::SetColor( const SGCOLOR& aColor ) 118 | { 119 | red = aColor.red; 120 | green = aColor.green; 121 | blue = aColor.blue; 122 | return true; 123 | } 124 | 125 | 126 | bool SGCOLOR::SetColor( const SGCOLOR* aColor ) 127 | { 128 | if( NULL == aColor ) 129 | { 130 | #ifdef DEBUG 131 | std::ostringstream ostr; 132 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 133 | ostr << " * [BUG] NULL pointer passed for aColor"; 134 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 135 | #endif 136 | 137 | return false; 138 | } 139 | 140 | red = aColor->red; 141 | green = aColor->green; 142 | blue = aColor->blue; 143 | return true; 144 | } 145 | 146 | 147 | bool SGCOLOR::checkRange( float aRedVal, float aGreenVal, float aBlueVal ) const 148 | { 149 | bool ok = true; 150 | 151 | if( aRedVal < 0.0 || aRedVal > 1.0 ) 152 | { 153 | #ifdef DEBUG 154 | std::ostringstream ostr; 155 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 156 | ostr << " * [BUG] invalid RED value: " << aRedVal; 157 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 158 | #endif 159 | ok = false; 160 | } 161 | 162 | if( aGreenVal < 0.0 || aGreenVal > 1.0 ) 163 | { 164 | #ifdef DEBUG 165 | if( ok ) 166 | { 167 | wxLogTrace( MASK_3D_SG, "%s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__ ); 168 | } 169 | wxLogTrace( MASK_3D_SG, " * [BUG] invalid GREEN value: %f\n", aGreenVal ); 170 | #endif 171 | ok = false; 172 | } 173 | 174 | if( aBlueVal < 0.0 || aBlueVal > 1.0 ) 175 | { 176 | #ifdef DEBUG 177 | if( ok ) 178 | { 179 | wxLogTrace( MASK_3D_SG, "%s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__ ); 180 | } 181 | wxLogTrace( MASK_3D_SG, " * [BUG] invalid BLUE value: %f\n", aBlueVal ); 182 | #endif 183 | ok = false; 184 | } 185 | 186 | return ok; 187 | } 188 | 189 | 190 | SGPOINT::SGPOINT() 191 | { 192 | x = 0.0; 193 | y = 0.0; 194 | z = 0.0; 195 | return; 196 | } 197 | 198 | 199 | SGPOINT::SGPOINT( double aXVal, double aYVal, double aZVal ) 200 | { 201 | x = aXVal; 202 | y = aYVal; 203 | z = aZVal; 204 | } 205 | 206 | 207 | void SGPOINT::GetPoint( double& aXVal, double& aYVal, double& aZVal ) 208 | { 209 | x = aXVal; 210 | y = aYVal; 211 | z = aZVal; 212 | return; 213 | } 214 | 215 | 216 | void SGPOINT::GetPoint( SGPOINT& aPoint ) 217 | { 218 | x = aPoint.x; 219 | y = aPoint.y; 220 | z = aPoint.z; 221 | return; 222 | } 223 | 224 | 225 | void SGPOINT::GetPoint( SGPOINT* aPoint ) 226 | { 227 | if( NULL == aPoint ) 228 | { 229 | #ifdef DEBUG 230 | std::ostringstream ostr; 231 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 232 | ostr << " * [BUG] NULL pointer passed for aPoint"; 233 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 234 | #endif 235 | 236 | return; 237 | } 238 | 239 | x = aPoint->x; 240 | y = aPoint->y; 241 | z = aPoint->z; 242 | return; 243 | } 244 | 245 | 246 | void SGPOINT::SetPoint( double aXVal, double aYVal, double aZVal ) 247 | { 248 | x = aXVal; 249 | y = aYVal; 250 | z = aZVal; 251 | return; 252 | } 253 | 254 | 255 | void SGPOINT::SetPoint( const SGPOINT& aPoint ) 256 | { 257 | x = aPoint.x; 258 | y = aPoint.y; 259 | z = aPoint.z; 260 | return; 261 | } 262 | 263 | 264 | SGVECTOR::SGVECTOR() 265 | { 266 | vx = 0.0; 267 | vy = 0.0; 268 | vz = 1.0; 269 | return; 270 | } 271 | 272 | 273 | SGVECTOR::SGVECTOR( double aXVal, double aYVal, double aZVal ) 274 | { 275 | vx = aXVal; 276 | vy = aYVal; 277 | vz = aZVal; 278 | normalize(); 279 | return; 280 | } 281 | 282 | 283 | void SGVECTOR::GetVector( double& aXVal, double& aYVal, double& aZVal ) const 284 | { 285 | aXVal = vx; 286 | aYVal = vy; 287 | aZVal = vz; 288 | return; 289 | } 290 | 291 | 292 | void SGVECTOR::SetVector( double aXVal, double aYVal, double aZVal ) 293 | { 294 | vx = aXVal; 295 | vy = aYVal; 296 | vz = aZVal; 297 | normalize(); 298 | return; 299 | } 300 | 301 | 302 | void SGVECTOR::SetVector( const SGVECTOR& aVector ) 303 | { 304 | aVector.GetVector( vx, vy, vz ); 305 | return; 306 | } 307 | 308 | 309 | void SGVECTOR::normalize( void ) 310 | { 311 | double dx = vx * vx; 312 | double dy = vy * vy; 313 | double dz = vz * vz; 314 | double dv2 = sqrt( dx + dy + dz ); 315 | 316 | if( (dx + dy + dz) < 1e-8 ) 317 | { 318 | // use the default; the numbers are too small 319 | // to be believable 320 | vx = 0.0; 321 | vy = 0.0; 322 | vz = 1.0; 323 | return; 324 | } 325 | 326 | vx /= dv2; 327 | vy /= dv2; 328 | vz /= dv2; 329 | 330 | return; 331 | } 332 | 333 | 334 | SGVECTOR& SGVECTOR::operator=( const SGVECTOR& source ) 335 | { 336 | vx = source.vx; 337 | vy = source.vy; 338 | vz = source.vz; 339 | return *this; 340 | } 341 | -------------------------------------------------------------------------------- /include/plugins/3dapi/ifsg_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file ifsg_api.h 26 | * defines the API calls for the manipulation of SG* classes 27 | */ 28 | 29 | #ifndef IFSG_API_H 30 | #define IFSG_API_H 31 | 32 | #include "plugins/3dapi/sg_types.h" 33 | #include "plugins/3dapi/sg_base.h" 34 | #include "plugins/3dapi/c3dmodel.h" 35 | 36 | class SGNODE; 37 | class SCENEGRAPH; 38 | struct S3D_INFO; 39 | struct S3D_POINT; 40 | 41 | namespace S3D 42 | { 43 | /** 44 | * Function GetLibVersion retrieves version information of the 45 | * kicad_3dsg library 46 | */ 47 | SGLIB_API void GetLibVersion( unsigned char* Major, unsigned char* Minor, 48 | unsigned char* Patch, unsigned char* Revision ); 49 | 50 | // functions to extract information from SGNODE pointers 51 | SGLIB_API S3D::SGTYPES GetSGNodeType( SGNODE* aNode ); 52 | SGLIB_API SGNODE* GetSGNodeParent( SGNODE* aNode ); 53 | SGLIB_API bool AddSGNodeRef( SGNODE* aParent, SGNODE* aChild ); 54 | SGLIB_API bool AddSGNodeChild( SGNODE* aParent, SGNODE* aChild ); 55 | SGLIB_API void AssociateSGNodeWrapper( SGNODE* aObject, SGNODE** aRefPtr ); 56 | 57 | /** 58 | * Function CalcTriNorm 59 | * returns the normal vector of a triangle described by vertices p1, p2, p3 60 | */ 61 | SGLIB_API SGVECTOR CalcTriNorm( const SGPOINT& p1, const SGPOINT& p2, const SGPOINT& p3 ); 62 | 63 | /** 64 | * Function WriteCache 65 | * writes the SGNODE tree to a binary cache file 66 | * 67 | * @param aFileName is the name of the file to write 68 | * @param overwrite must be set to true to overwrite an existing file 69 | * @param aNode is any node within the node tree which is to be written 70 | * @return true on success 71 | */ 72 | SGLIB_API bool WriteCache( const char* aFileName, bool overwrite, SGNODE* aNode, 73 | const char* aPluginInfo ); 74 | 75 | /** 76 | * Function ReadCache 77 | * reads a binary cache file and creates an SGNODE tree 78 | * 79 | * @param aFileName is the name of the binary cache file to be read 80 | * @return NULL on failure, on success a pointer to the top level SCENEGRAPH node; 81 | * if desired this node can be associated with an IFSG_TRANSFORM wrapper via 82 | * the IFSG_TRANSFORM::Attach() function. 83 | */ 84 | SGLIB_API SGNODE* ReadCache( const char* aFileName, void* aPluginMgr, 85 | bool (*aTagCheck)( const char*, void* ) ); 86 | 87 | /** 88 | * Function WriteVRML 89 | * writes out the given node and its subnodes to a VRML2 file 90 | * 91 | * @param filename is the name of the output file 92 | * @param overwrite should be set to true to overwrite an existing VRML file 93 | * @param aTopNode is a pointer to a SCENEGRAPH object representing the VRML scene 94 | * @param reuse should be set to true to make use of VRML DEF/USE features 95 | * @return true on success 96 | */ 97 | SGLIB_API bool WriteVRML( const char* filename, bool overwrite, SGNODE* aTopNode, 98 | bool reuse, bool renameNodes ); 99 | 100 | // NOTE: The following functions are used in combination to create a VRML 101 | // assembly which may use various instances of each SG* representation of a module. 102 | // A typical use case would be: 103 | // 1. invoke 'ResetNodeIndex()' to reset the global node name indices 104 | // 2. for each model pointer provided by 'S3DCACHE->Load()', invoke 'RenameNodes()' once; 105 | // this ensures that all nodes have a unique name to present to the final output file. 106 | // Internally, RenameNodes() will only rename the given node and all Child subnodes; 107 | // nodes which are only referenced will not be renamed. Using the pointer supplied 108 | // by 'S3DCACHE->Load()' ensures that all nodes but the returned node (top node) are 109 | // children of at least one node, so all nodes are given unique names. 110 | // 3. if SG* trees are created independently of S3DCACHE->Load() the user must invoke 111 | // RenameNodes() as appropriate to ensure that all nodes have a unique name 112 | // 4. create an assembly structure by creating new IFSG_TRANSFORM nodes as appropriate 113 | // for each instance of a component; the component base model as returned by 114 | // S3DCACHE->Load() may be added to these IFSG_TRANSFORM nodes via 'AddRefNode()'; 115 | // set the offset, rotation, etc of the IFSG_TRANSFORM node to ensure correct 116 | // 5. Ensure that all new IFSG_TRANSFORM nodes are placed as child nodes within a 117 | // top level IFSG_TRANSFORM node in preparation for final node naming and output 118 | // 6. Invoke RenameNodes() on the top level assembly node 119 | // 7. Invoke WriteVRML() as normal, with renameNodes = false, to write the entire assembly 120 | // structure to a single VRML file 121 | // 8. Clean up by deleting any extra IFSG_TRANSFORM wrappers and their underlying SG* 122 | // classes which have been created solely for the assembly output 123 | 124 | /** 125 | * Function ResetNodeIndex 126 | * resets the global SG* class indices 127 | * 128 | * @param aNode may be any valid SGNODE 129 | */ 130 | SGLIB_API void ResetNodeIndex( SGNODE* aNode ); 131 | 132 | /** 133 | * Function RenameNodes 134 | * renames a node and all children nodes based on the current 135 | * values of the global SG* class indices 136 | * 137 | * @param aNode is a top level node 138 | */ 139 | SGLIB_API void RenameNodes( SGNODE* aNode ); 140 | 141 | /** 142 | * Function DestroyNode 143 | * deletes the given SG* class node. This function makes it possible 144 | * to safely delete an SG* node without associating the node with 145 | * its corresponding IFSG* wrapper. 146 | */ 147 | SGLIB_API void DestroyNode( SGNODE* aNode ); 148 | 149 | // NOTE: The following functions facilitate the creation and destruction 150 | // of data structures for rendering 151 | 152 | /** 153 | * Function GetModel 154 | * creates an S3DMODEL representation of aNode (raw data, no transforms) 155 | * 156 | * @param aNode is the node to be transcribed into an S3DMODEL representation 157 | * @return an S3DMODEL representation of aNode on success, otherwise NULL 158 | */ 159 | SGLIB_API S3DMODEL* GetModel( SCENEGRAPH* aNode ); 160 | 161 | /** 162 | * Function Destroy3DModel 163 | * frees memory used by an S3DMODEL structure and sets the pointer to 164 | * the structure to NULL 165 | */ 166 | SGLIB_API void Destroy3DModel( S3DMODEL** aModel ); 167 | 168 | /** 169 | * Function Free3DModel 170 | * frees memory used internally by an S3DMODEL structure 171 | */ 172 | SGLIB_API void Free3DModel( S3DMODEL& aModel ); 173 | 174 | /** 175 | * Function Free3DMesh 176 | * frees memory used internally by an SMESH structure 177 | */ 178 | SGLIB_API void Free3DMesh( SMESH& aMesh ); 179 | 180 | /** 181 | * Function New3DModel 182 | * creates and initializes an S3DMODEL struct 183 | */ 184 | SGLIB_API S3DMODEL* New3DModel( void ); 185 | 186 | /** 187 | * Function Init3DMaterial 188 | * initializes an SMATERIAL struct 189 | */ 190 | SGLIB_API void Init3DMaterial( SMATERIAL& aMat ); 191 | 192 | /** 193 | * Function Init3DMesh 194 | * creates and initializes an SMESH struct 195 | */ 196 | SGLIB_API void Init3DMesh( SMESH& aMesh ); 197 | }; 198 | 199 | #endif // IFSG_API_H 200 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_node.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_node.h 26 | * defines the base class of the intermediate scene graph NODE 27 | */ 28 | 29 | 30 | #ifndef SG_NODE_H 31 | #define SG_NODE_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "plugins/3dapi/c3dmodel.h" 41 | #include "plugins/3dapi/sg_base.h" 42 | #include "plugins/3dapi/sg_types.h" 43 | 44 | class SGNODE; 45 | class SGAPPEARANCE; 46 | 47 | namespace S3D 48 | { 49 | /** 50 | * Function GetNodeTypeName 51 | * returns the name of the given type of node 52 | */ 53 | char const* GetNodeTypeName( S3D::SGTYPES aType ); 54 | 55 | struct MATLIST 56 | { 57 | std::vector< SGAPPEARANCE const* > matorder; // materials in order of addition 58 | std::map< SGAPPEARANCE const*, int > matmap; // mapping from material to index 59 | }; 60 | 61 | bool GetMatIndex( MATLIST& aList, SGNODE* aNode, int& aIndex ); 62 | 63 | void INIT_SMATERIAL( SMATERIAL& aMaterial ); 64 | void INIT_SMESH( SMESH& aMesh ); 65 | void INIT_S3DMODEL( S3DMODEL& aModel ); 66 | 67 | void FREE_SMESH( SMESH& aMesh); 68 | void FREE_S3DMODEL( S3DMODEL& aModel ); 69 | }; 70 | 71 | 72 | /** 73 | * Class SGNODE 74 | * represents the base class of all Scene Graph nodes 75 | */ 76 | class SGNODE 77 | { 78 | private: 79 | SGNODE** m_Association; // handle to the instance held by a wrapper 80 | 81 | protected: 82 | std::list< SGNODE* > m_BackPointers; // nodes which hold a reference to this 83 | SGNODE* m_Parent; // pointer to parent node; may be NULL for top level transform 84 | S3D::SGTYPES m_SGtype; // type of SG node 85 | std::string m_Name; // name to use for referencing the entity by name 86 | bool m_written; // set true when the object has been written after a ReNameNodes() 87 | 88 | public: 89 | /** 90 | * Function unlinkChild 91 | * removes references to an owned child; it is invoked by the child upon destruction 92 | * to ensure that the parent has no invalid references. 93 | * 94 | * @param aNode is the child which is being deleted 95 | */ 96 | virtual void unlinkChildNode( const SGNODE* aNode ) = 0; 97 | 98 | /** 99 | * Function unlinkRef 100 | * removes pointers to a referenced node; it is invoked by the referenced node 101 | * upon destruction to ensure that the referring node has no invalid references. 102 | * 103 | * @param aNode is the node which is being deleted 104 | */ 105 | virtual void unlinkRefNode( const SGNODE* aNode ) = 0; 106 | 107 | /** 108 | * Function addNodeRef 109 | * adds a pointer to a node which references, but does not own, this node. 110 | * Such back-pointers are required to ensure that invalidated references 111 | * are removed when a node is deleted 112 | * 113 | * @param aNode is the node holding a reference to this object 114 | */ 115 | void addNodeRef( SGNODE* aNode ); 116 | 117 | /** 118 | * Function delNodeRef 119 | * removes a pointer to a node which references, but does not own, this node. 120 | * 121 | * @param aNode is the node holding a reference to this object 122 | */ 123 | void delNodeRef( const SGNODE* aNode ); 124 | 125 | /** 126 | * Function IsWritten 127 | * returns true if the object had already been written to a 128 | * cache file or VRML file; for internal use only. 129 | */ 130 | bool isWritten( void ) 131 | { 132 | return m_written; 133 | } 134 | 135 | public: 136 | SGNODE( SGNODE* aParent ); 137 | virtual ~SGNODE(); 138 | 139 | /** 140 | * Function GetNodeType 141 | * returns the type of this node instance 142 | */ 143 | S3D::SGTYPES GetNodeType( void ) const; 144 | 145 | /** 146 | * Function GetParent 147 | * returns a pointer to the parent SGNODE of this object 148 | * or NULL if the object has no parent (ie. top level transform) 149 | */ 150 | SGNODE* GetParent( void ) const; 151 | 152 | /** 153 | * Function SetParent 154 | * sets the parent SGNODE of this object. 155 | * 156 | * @param aParent [in] is the desired parent node 157 | * @return true if the operation succeeds; false if 158 | * the given node is not allowed to be a parent to 159 | * the derived object. 160 | */ 161 | virtual bool SetParent( SGNODE* aParent, bool notify = true ) = 0; 162 | 163 | /** 164 | * Function SwapParent 165 | * swaps the ownership with the given parent. This operation 166 | * may be required when reordering nodes for optimization. 167 | * 168 | * @param aNewParent [in] will become the new parent to the 169 | * object; it must be the same type as the parent of this 170 | * instance. 171 | */ 172 | bool SwapParent( SGNODE* aNewParent ); 173 | 174 | const char* GetName( void ); 175 | void SetName(const char *aName); 176 | 177 | const char * GetNodeTypeName( S3D::SGTYPES aNodeType ) const; 178 | 179 | /** 180 | * Function FindNode searches the tree of linked nodes and returns a 181 | * reference to the first node found with the given name. The reference 182 | * is then typically added to another node via AddRefNode(). 183 | * 184 | * @param aNodeName is the name of the node to search for 185 | * @param aCaller is a pointer to the node invoking this function 186 | * @return is a valid node pointer on success, otherwise NULL 187 | */ 188 | virtual SGNODE* FindNode( const char *aNodeName, const SGNODE *aCaller ) = 0; 189 | 190 | virtual bool AddRefNode( SGNODE* aNode ) = 0; 191 | 192 | virtual bool AddChildNode( SGNODE* aNode ) = 0; 193 | 194 | /** 195 | * Function AssociateWrapper 196 | * associates this object with a handle to itself; this handle 197 | * is typically held by an IFSG* wrapper and the pointer which 198 | * it refers to is set to NULL upon destruction of this object. 199 | * This mechanism provides a scheme by which a wrapper can be 200 | * notified of the destruction of the object which it wraps. 201 | */ 202 | void AssociateWrapper( SGNODE** aWrapperRef ); 203 | 204 | /** 205 | * Function DisassociateWrapper 206 | * removes the association between an IFSG* wrapper 207 | * object and this object. 208 | */ 209 | void DisassociateWrapper( SGNODE** aWrapperRef ); 210 | 211 | /** 212 | * Function ResetNodeIndex 213 | * resets the global SG* node indices in preparation for 214 | * Write() operations 215 | */ 216 | void ResetNodeIndex( void ); 217 | 218 | /** 219 | * Function ReNameNodes 220 | * renames a node and all its child nodes in preparation for 221 | * Write() operations 222 | */ 223 | virtual void ReNameNodes( void ) = 0; 224 | 225 | /** 226 | * Function WriteVRML 227 | * writes this node's data to a VRML file; this includes 228 | * all data of child and referenced nodes. 229 | */ 230 | virtual bool WriteVRML( std::ofstream& aFile, bool aReuseFlag ) = 0; 231 | 232 | /** 233 | * Function WriteCache 234 | * write's this node's data to a binary cache file; the data 235 | * includes all data of children and references to children. 236 | * If this function is invoked by the user, parentNode must be 237 | * set to NULL in order to ensure coherent data. 238 | */ 239 | virtual bool WriteCache( std::ofstream& aFile, SGNODE* parentNode ) = 0; 240 | 241 | /** 242 | * Function ReadCache 243 | * Reads binary format data from a cache file. To read a cache file, 244 | * open the file for reading and invoke this function from a new 245 | * SCENEGRAPH node. 246 | */ 247 | virtual bool ReadCache( std::ifstream& aFile, SGNODE* parentNode ) = 0; 248 | }; 249 | 250 | #endif // SG_NODE_H 251 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_normals.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "3d_cache/sg/sg_normals.h" 29 | #include "3d_cache/sg/sg_helpers.h" 30 | 31 | 32 | SGNORMALS::SGNORMALS( SGNODE* aParent ) : SGNODE( aParent ) 33 | { 34 | m_SGtype = S3D::SGTYPE_NORMALS; 35 | 36 | if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() ) 37 | { 38 | m_Parent = NULL; 39 | 40 | #ifdef DEBUG 41 | std::ostringstream ostr; 42 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 43 | ostr << " * [BUG] inappropriate parent to SGNORMALS (type "; 44 | ostr << aParent->GetNodeType() << ")"; 45 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 46 | #endif 47 | } 48 | else if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() ) 49 | { 50 | m_Parent->AddChildNode( this ); 51 | } 52 | 53 | return; 54 | } 55 | 56 | 57 | SGNORMALS::~SGNORMALS() 58 | { 59 | norms.clear(); 60 | return; 61 | } 62 | 63 | 64 | bool SGNORMALS::SetParent( SGNODE* aParent, bool notify ) 65 | { 66 | if( NULL != m_Parent ) 67 | { 68 | if( aParent == m_Parent ) 69 | return true; 70 | 71 | // handle the change in parents 72 | if( notify ) 73 | m_Parent->unlinkChildNode( this ); 74 | 75 | m_Parent = NULL; 76 | 77 | if( NULL == aParent ) 78 | return true; 79 | } 80 | 81 | // only a SGFACESET may be parent to a SGNORMALS 82 | if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() ) 83 | return false; 84 | 85 | m_Parent = aParent; 86 | 87 | if( m_Parent ) 88 | m_Parent->AddChildNode( this ); 89 | 90 | return true; 91 | } 92 | 93 | 94 | SGNODE* SGNORMALS::FindNode(const char *aNodeName, const SGNODE *aCaller) 95 | { 96 | if( NULL == aNodeName || 0 == aNodeName[0] ) 97 | return NULL; 98 | 99 | if( !m_Name.compare( aNodeName ) ) 100 | return this; 101 | 102 | return NULL; 103 | } 104 | 105 | 106 | void SGNORMALS::unlinkChildNode( const SGNODE* aCaller ) 107 | { 108 | #ifdef DEBUG 109 | std::ostringstream ostr; 110 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 111 | ostr << " * [BUG] unexpected code branch; node should have no children or refs"; 112 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 113 | #endif 114 | 115 | return; 116 | } 117 | 118 | 119 | void SGNORMALS::unlinkRefNode( const SGNODE* aCaller ) 120 | { 121 | #ifdef DEBUG 122 | std::ostringstream ostr; 123 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 124 | ostr << " * [BUG] unexpected code branch; node should have no children or refs"; 125 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 126 | #endif 127 | 128 | return; 129 | } 130 | 131 | 132 | bool SGNORMALS::AddRefNode( SGNODE* aNode ) 133 | { 134 | #ifdef DEBUG 135 | std::ostringstream ostr; 136 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 137 | ostr << " * [BUG] this node does not accept children or refs"; 138 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 139 | #endif 140 | 141 | return false; 142 | } 143 | 144 | 145 | bool SGNORMALS::AddChildNode( SGNODE* aNode ) 146 | { 147 | #ifdef DEBUG 148 | std::ostringstream ostr; 149 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 150 | ostr << " * [BUG] this node does not accept children or refs"; 151 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 152 | #endif 153 | 154 | return false; 155 | } 156 | 157 | 158 | bool SGNORMALS::GetNormalList( size_t& aListSize, SGVECTOR*& aNormalList ) 159 | { 160 | if( norms.empty() ) 161 | { 162 | aListSize = 0; 163 | aNormalList = NULL; 164 | return false; 165 | } 166 | 167 | aListSize = norms.size(); 168 | aNormalList = &norms[0]; 169 | return true; 170 | } 171 | 172 | 173 | void SGNORMALS::SetNormalList( size_t aListSize, const SGVECTOR* aNormalList ) 174 | { 175 | norms.clear(); 176 | 177 | if( 0 == aListSize || NULL == aNormalList ) 178 | return; 179 | 180 | for( int i = 0; i < (int)aListSize; ++i ) 181 | norms.push_back( aNormalList[i] ); 182 | 183 | return; 184 | } 185 | 186 | 187 | void SGNORMALS::AddNormal( double aXValue, double aYValue, double aZValue ) 188 | { 189 | norms.push_back( SGVECTOR( aXValue, aYValue, aZValue ) ); 190 | return; 191 | } 192 | 193 | 194 | void SGNORMALS::AddNormal( const SGVECTOR& aNormal ) 195 | { 196 | norms.push_back( aNormal ); 197 | return; 198 | } 199 | 200 | 201 | void SGNORMALS::ReNameNodes( void ) 202 | { 203 | m_written = false; 204 | 205 | // rename this node 206 | m_Name.clear(); 207 | GetName(); 208 | } 209 | 210 | 211 | bool SGNORMALS::WriteVRML( std::ofstream& aFile, bool aReuseFlag ) 212 | { 213 | if( norms.empty() ) 214 | return false; 215 | 216 | if( aReuseFlag ) 217 | { 218 | if( !m_written ) 219 | { 220 | aFile << " normal DEF " << GetName() << " Normal { vector [\n "; 221 | m_written = true; 222 | } 223 | else 224 | { 225 | aFile << " normal USE " << GetName() << "\n"; 226 | return true; 227 | } 228 | } 229 | else 230 | { 231 | aFile << " normal Normal { vector [\n "; 232 | } 233 | 234 | std::string tmp; 235 | size_t n = norms.size(); 236 | bool nline = false; 237 | 238 | for( size_t i = 0; i < n; ) 239 | { 240 | S3D::FormatVector( tmp, norms[i] ); 241 | aFile << tmp ; 242 | ++i; 243 | 244 | if( i < n ) 245 | { 246 | aFile << ","; 247 | 248 | if( nline ) 249 | { 250 | aFile << "\n "; 251 | nline = false; 252 | } 253 | else 254 | { 255 | nline = true; 256 | } 257 | 258 | } 259 | } 260 | 261 | aFile << "] }\n"; 262 | 263 | return true; 264 | } 265 | 266 | 267 | bool SGNORMALS::WriteCache( std::ofstream& aFile, SGNODE* parentNode ) 268 | { 269 | if( NULL == parentNode ) 270 | { 271 | if( NULL == m_Parent ) 272 | { 273 | #ifdef DEBUG 274 | std::ostringstream ostr; 275 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 276 | ostr << " * [BUG] corrupt data; m_aParent is NULL"; 277 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 278 | #endif 279 | 280 | return false; 281 | } 282 | 283 | SGNODE* np = m_Parent; 284 | 285 | while( NULL != np->GetParent() ) 286 | np = np->GetParent(); 287 | 288 | if( np->WriteCache( aFile, NULL ) ) 289 | { 290 | m_written = true; 291 | return true; 292 | } 293 | 294 | return false; 295 | } 296 | 297 | if( parentNode != m_Parent ) 298 | { 299 | #ifdef DEBUG 300 | std::ostringstream ostr; 301 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 302 | ostr << " * [BUG] corrupt data; parentNode != m_aParent"; 303 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 304 | #endif 305 | 306 | return false; 307 | } 308 | 309 | if( !aFile.good() ) 310 | { 311 | #ifdef DEBUG 312 | std::ostringstream ostr; 313 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 314 | ostr << " * [INFO] bad stream"; 315 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 316 | #endif 317 | 318 | return false; 319 | } 320 | 321 | aFile << "[" << GetName() << "]"; 322 | size_t npts = norms.size(); 323 | aFile.write( (char*)&npts, sizeof(size_t) ); 324 | 325 | for( size_t i = 0; i < npts; ++i ) 326 | S3D::WriteVector( aFile, norms[i] ); 327 | 328 | if( aFile.fail() ) 329 | return false; 330 | 331 | m_written = true; 332 | return true; 333 | } 334 | 335 | 336 | bool SGNORMALS::ReadCache( std::ifstream& aFile, SGNODE* parentNode ) 337 | { 338 | if( !norms.empty() ) 339 | { 340 | #ifdef DEBUG 341 | std::ostringstream ostr; 342 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 343 | ostr << " * [BUG] non-empty node"; 344 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 345 | #endif 346 | 347 | return false; 348 | } 349 | 350 | size_t npts; 351 | aFile.read( (char*)&npts, sizeof(size_t) ); 352 | SGVECTOR tmp; 353 | 354 | if( aFile.fail() ) 355 | return false; 356 | 357 | for( size_t i = 0; i < npts; ++i ) 358 | { 359 | if( !S3D::ReadVector( aFile, tmp ) || aFile.fail() ) 360 | return false; 361 | 362 | norms.push_back( tmp ); 363 | } 364 | 365 | return true; 366 | } 367 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_helpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | /** 25 | * @file sg_helpers.h 26 | * defines a number of macro functions to aid in repetitious code which 27 | * is probably best expressed as a preprocessor macro rather than as 28 | * a template. This header also declares a number of functions which are 29 | * only of use within the sg_* classes. 30 | */ 31 | 32 | #ifndef SG_HELPERS_H 33 | #define SG_HELPERS_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "plugins/3dapi/sg_base.h" 40 | #include "plugins/3dapi/sg_types.h" 41 | #include 42 | 43 | class SGNORMALS; 44 | class SGCOORDS; 45 | class SGCOORDINDEX; 46 | 47 | // Function to drop references within an SGNODE 48 | // The node being destroyed must remove itself from the object reference's 49 | // backpointer list in order to avoid a segfault. 50 | #define DROP_REFS( aType, aList ) do { \ 51 | std::vector< aType* >::iterator sL = aList.begin(); \ 52 | std::vector< aType* >::iterator eL = aList.end(); \ 53 | while( sL != eL ) { \ 54 | ((SGNODE*)*sL)->delNodeRef( this ); \ 55 | ++sL; \ 56 | } \ 57 | aList.clear(); \ 58 | } while( 0 ) 59 | 60 | 61 | // Function to delete owned objects within an SGNODE 62 | // The owned object's parent is set to NULL before 63 | // deletion to avoid a redundant 'unlinkChildNode' call. 64 | #define DEL_OBJS( aType, aList ) do { \ 65 | std::vector< aType* >::iterator sL = aList.begin(); \ 66 | std::vector< aType* >::iterator eL = aList.end(); \ 67 | while( sL != eL ) { \ 68 | ((SGNODE*)*sL)->SetParent( NULL, false ); \ 69 | delete *sL; \ 70 | ++sL; \ 71 | } \ 72 | aList.clear(); \ 73 | } while( 0 ) 74 | 75 | 76 | // Function to unlink a child or reference node when that child or 77 | // reference node is being destroyed. 78 | #define UNLINK_NODE( aNodeID, aType, aNode, aOwnedList, aRefList, isChild ) do { \ 79 | if( aNodeID == aNode->GetNodeType() ) { \ 80 | std::vector< aType* >* oSL; \ 81 | std::vector< aType* >::iterator sL; \ 82 | std::vector< aType* >::iterator eL; \ 83 | if( isChild ) { \ 84 | oSL = &aOwnedList; \ 85 | sL = aOwnedList.begin(); \ 86 | eL = aOwnedList.end(); \ 87 | while( sL != eL ) { \ 88 | if( (SGNODE*)*sL == aNode ) { \ 89 | oSL->erase( sL ); \ 90 | return; \ 91 | } \ 92 | ++sL; \ 93 | } \ 94 | } else { \ 95 | oSL = &aRefList; \ 96 | sL = aRefList.begin(); \ 97 | eL = aRefList.end(); \ 98 | while( sL != eL ) { \ 99 | if( (SGNODE*)*sL == aNode ) { \ 100 | delNodeRef( this ); \ 101 | oSL->erase( sL ); \ 102 | return; \ 103 | } \ 104 | ++sL; \ 105 | } \ 106 | } \ 107 | return; \ 108 | } } while( 0 ) 109 | 110 | 111 | // Function to check a node type, check for an existing reference, 112 | // and add the node type to the reference list if applicable 113 | #define ADD_NODE( aNodeID, aType, aNode, aOwnedList, aRefList, isChild ) do { \ 114 | if( aNodeID == aNode->GetNodeType() ) { \ 115 | std::vector< aType* >::iterator sL; \ 116 | sL = std::find( aOwnedList.begin(), aOwnedList.end(), aNode ); \ 117 | if( sL != aOwnedList.end() ) return true; \ 118 | sL = std::find( aRefList.begin(), aRefList.end(), aNode ); \ 119 | if( sL != aRefList.end() ) return true; \ 120 | if( isChild ) { \ 121 | SGNODE* ppn = (SGNODE*)aNode->GetParent(); \ 122 | if( NULL != ppn ) { \ 123 | if( this != ppn ) { \ 124 | std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; \ 125 | std::cerr << " * [BUG] object '" << aNode->GetName(); \ 126 | std::cerr << "' has multiple parents '" << ppn->GetName() << "', '"; \ 127 | std::cerr << m_Name << "'\n"; \ 128 | return false; \ 129 | } \ 130 | } \ 131 | aOwnedList.push_back( (aType*)aNode ); \ 132 | aNode->SetParent( this, false ); \ 133 | } else { \ 134 | if( NULL == aNode->GetParent() ) { \ 135 | std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; \ 136 | std::cerr << " * [BUG] object '" << aNode->GetName(); \ 137 | std::cerr << "' has no parent\n"; \ 138 | std::cerr << " * [INFO] possible copy assignment or copy constructor bug\n"; \ 139 | return false; \ 140 | } \ 141 | aRefList.push_back( (aType*)aNode ); \ 142 | aNode->addNodeRef( this ); \ 143 | } \ 144 | return true; \ 145 | } } while( 0 ) 146 | 147 | 148 | // Function to find a node object given a (non-unique) node name 149 | #define FIND_NODE( aType, aName, aNodeList, aCallingNode ) do { \ 150 | std::vector< aType* >::iterator sLA = aNodeList.begin(); \ 151 | std::vector< aType* >::iterator eLA = aNodeList.end(); \ 152 | SGNODE* psg = NULL; \ 153 | while( sLA != eLA ) { \ 154 | if( (SGNODE*)*sLA != aCallingNode ) { \ 155 | psg = (SGNODE*) (*sLA)->FindNode( aName, this ); \ 156 | if( NULL != psg) \ 157 | return psg; \ 158 | } \ 159 | ++sLA; \ 160 | } } while ( 0 ) 161 | 162 | namespace S3D 163 | { 164 | bool degenerate( glm::dvec3* pts ); 165 | 166 | // 167 | // Normals calculations from triangles 168 | // 169 | 170 | /* 171 | * Function CalcTriangleNormals 172 | * takes an array of 3D coordinates and its corresponding index set and calculates 173 | * the normals assuming that indices are given in CCW order. Care must be taken in 174 | * using this function to ensure that: 175 | * (a) all coordinates are indexed; unindexed coordinates are assigned normal(0,0,1); 176 | * when dealing with VRML models which may list and reuse one large coordinate set it 177 | * is necessary to gather all index sets and perform this operation only once. 178 | * (b) index sets must represent triangles (multiple of 3 indices) and must not be 179 | * degenerate - that is all indices and coordinates in a triad must be unique. 180 | * 181 | * @param coords is the array of 3D vertices 182 | * @param index is the array of 3x vertex indices (triads) 183 | * @param norms is an empty array which holds the normals corresponding to each vector 184 | * @return true on success; otherwise false. 185 | */ 186 | bool CalcTriangleNormals( std::vector< SGPOINT > coords, std::vector< int >& index, 187 | std::vector< SGVECTOR >& norms ); 188 | 189 | // 190 | // VRML related functions 191 | // 192 | 193 | // formats a floating point number for text output to a VRML file 194 | void FormatFloat( std::string& result, double value ); 195 | 196 | // format orientation data for VRML output 197 | void FormatOrientation( std::string& result, const SGVECTOR& axis, double rotation ); 198 | 199 | // format point data for VRML output 200 | void FormatPoint( std::string& result, const SGPOINT& point ); 201 | 202 | // format vector data for VRML output 203 | void FormatVector( std::string& result, const SGVECTOR& aVector ); 204 | 205 | // format Color data for VRML output 206 | void FormatColor( std::string& result, const SGCOLOR& aColor ); 207 | 208 | // 209 | // Cache related WRITE functions 210 | // 211 | 212 | // write out an XYZ vertex 213 | bool WritePoint( std::ofstream& aFile, const SGPOINT& aPoint ); 214 | 215 | // write out a unit vector 216 | bool WriteVector( std::ofstream& aFile, const SGVECTOR& aVector ); 217 | 218 | // write out an RGB color 219 | bool WriteColor( std::ofstream& aFile, const SGCOLOR& aColor ); 220 | 221 | // 222 | // Cache related READ functions 223 | // 224 | 225 | /** 226 | * Function ReadTag 227 | * reads the text tag of a binary cache file which is the 228 | * NodeTag and unique ID number combined 229 | * 230 | * @param aFile is a binary file open for reading 231 | * @param aName will hold the tag name on successful return 232 | * @return will be the NodeType which the tag represents or 233 | * S3D::SGTYPES::SGTYPE_END on failure 234 | */ 235 | S3D::SGTYPES ReadTag( std::ifstream& aFile, std::string& aName ); 236 | 237 | // read an XYZ vertex 238 | bool ReadPoint( std::ifstream& aFile, SGPOINT& aPoint ); 239 | 240 | // read a unit vector 241 | bool ReadVector( std::ifstream& aFile, SGVECTOR& aVector ); 242 | 243 | // read an RGB color 244 | bool ReadColor( std::ifstream& aFile, SGCOLOR& aColor ); 245 | }; 246 | 247 | #endif // SG_HELPERS_H 248 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_colors.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "3d_cache/sg/sg_colors.h" 29 | #include "3d_cache/sg/sg_helpers.h" 30 | 31 | SGCOLORS::SGCOLORS( SGNODE* aParent ) : SGNODE( aParent ) 32 | { 33 | m_SGtype = S3D::SGTYPE_COLORS; 34 | 35 | if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() ) 36 | { 37 | m_Parent = NULL; 38 | 39 | #ifdef DEBUG 40 | std::ostringstream ostr; 41 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 42 | ostr << " * [BUG] inappropriate parent to SGCOLORS (type "; 43 | ostr << aParent->GetNodeType() << ")"; 44 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 45 | #endif 46 | } 47 | else if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() ) 48 | { 49 | m_Parent->AddChildNode( this ); 50 | } 51 | 52 | return; 53 | } 54 | 55 | 56 | SGCOLORS::~SGCOLORS() 57 | { 58 | colors.clear(); 59 | return; 60 | } 61 | 62 | 63 | bool SGCOLORS::SetParent( SGNODE* aParent, bool notify ) 64 | { 65 | if( NULL != m_Parent ) 66 | { 67 | if( aParent == m_Parent ) 68 | return true; 69 | 70 | // handle the change in parents 71 | if( notify ) 72 | m_Parent->unlinkChildNode( this ); 73 | 74 | m_Parent = NULL; 75 | 76 | if( NULL == aParent ) 77 | return true; 78 | } 79 | 80 | // only a SGFACESET may be parent to a SGCOLORS 81 | if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() ) 82 | return false; 83 | 84 | m_Parent = aParent; 85 | 86 | if( m_Parent ) 87 | m_Parent->AddChildNode( this ); 88 | 89 | return true; 90 | } 91 | 92 | 93 | SGNODE* SGCOLORS::FindNode(const char *aNodeName, const SGNODE *aCaller) 94 | { 95 | if( NULL == aNodeName || 0 == aNodeName[0] ) 96 | return NULL; 97 | 98 | if( !m_Name.compare( aNodeName ) ) 99 | return this; 100 | 101 | return NULL; 102 | } 103 | 104 | 105 | void SGCOLORS::unlinkChildNode( const SGNODE* aCaller ) 106 | { 107 | #ifdef DEBUG 108 | std::ostringstream ostr; 109 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 110 | ostr << " * [BUG] unexpected code branch; node should have no children or refs"; 111 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 112 | #endif 113 | 114 | return; 115 | } 116 | 117 | 118 | void SGCOLORS::unlinkRefNode( const SGNODE* aCaller ) 119 | { 120 | #ifdef DEBUG 121 | std::ostringstream ostr; 122 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 123 | ostr << " * [BUG] unexpected code branch; node should have no children or refs"; 124 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 125 | #endif 126 | 127 | return; 128 | } 129 | 130 | 131 | bool SGCOLORS::AddRefNode( SGNODE* aNode ) 132 | { 133 | #ifdef DEBUG 134 | std::ostringstream ostr; 135 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 136 | ostr << " * [BUG] this node does not accept children or refs"; 137 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 138 | #endif 139 | 140 | return false; 141 | } 142 | 143 | 144 | bool SGCOLORS::AddChildNode( SGNODE* aNode ) 145 | { 146 | #ifdef DEBUG 147 | std::ostringstream ostr; 148 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 149 | ostr << " * [BUG] this node does not accept children or refs"; 150 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 151 | #endif 152 | 153 | return false; 154 | } 155 | 156 | 157 | bool SGCOLORS::GetColorList( size_t& aListSize, SGCOLOR*& aColorList ) 158 | { 159 | if( colors.empty() ) 160 | { 161 | aListSize = 0; 162 | aColorList = NULL; 163 | return false; 164 | } 165 | 166 | aListSize = colors.size(); 167 | aColorList = &colors[0]; 168 | return true; 169 | } 170 | 171 | 172 | void SGCOLORS::SetColorList( size_t aListSize, const SGCOLOR* aColorList ) 173 | { 174 | colors.clear(); 175 | 176 | if( 0 == aListSize || NULL == aColorList ) 177 | return; 178 | 179 | for( size_t i = 0; i < aListSize; ++i ) 180 | colors.push_back( aColorList[i] ); 181 | 182 | return; 183 | } 184 | 185 | 186 | void SGCOLORS::AddColor( double aRedValue, double aGreenValue, double aBlueValue ) 187 | { 188 | colors.push_back( SGCOLOR( aRedValue, aGreenValue, aBlueValue ) ); 189 | return; 190 | } 191 | 192 | 193 | void SGCOLORS::AddColor( const SGCOLOR& aColor ) 194 | { 195 | colors.push_back( aColor ); 196 | return; 197 | } 198 | 199 | 200 | void SGCOLORS::ReNameNodes( void ) 201 | { 202 | m_written = false; 203 | 204 | // rename this node 205 | m_Name.clear(); 206 | GetName(); 207 | } 208 | 209 | 210 | bool SGCOLORS::WriteVRML( std::ofstream& aFile, bool aReuseFlag ) 211 | { 212 | if( colors.empty() ) 213 | return false; 214 | 215 | if( aReuseFlag ) 216 | { 217 | if( !m_written ) 218 | { 219 | aFile << "color DEF " << GetName() << " Color { color [\n "; 220 | m_written = true; 221 | } 222 | else 223 | { 224 | aFile << "color USE " << GetName() << "\n"; 225 | return true; 226 | } 227 | } 228 | else 229 | { 230 | aFile << "color Color { color [\n "; 231 | } 232 | 233 | std::string tmp; 234 | size_t n = colors.size(); 235 | bool nline = false; 236 | 237 | for( size_t i = 0; i < n; ) 238 | { 239 | S3D::FormatColor( tmp, colors[i] ); 240 | float r,g,b; 241 | colors[i].GetColor(r, g, b); 242 | aFile << tmp ; 243 | ++i; 244 | 245 | if( i < n ) 246 | { 247 | aFile << ","; 248 | 249 | if( nline ) 250 | { 251 | aFile << "\n "; 252 | nline = false; 253 | } 254 | else 255 | { 256 | nline = true; 257 | } 258 | 259 | } 260 | } 261 | 262 | aFile << "] }\n"; 263 | 264 | return true; 265 | } 266 | 267 | 268 | bool SGCOLORS::WriteCache( std::ofstream& aFile, SGNODE* parentNode ) 269 | { 270 | if( NULL == parentNode ) 271 | { 272 | if( NULL == m_Parent ) 273 | { 274 | #ifdef DEBUG 275 | std::ostringstream ostr; 276 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 277 | ostr << " * [BUG] corrupt data; m_aParent is NULL"; 278 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 279 | #endif 280 | 281 | return false; 282 | } 283 | 284 | SGNODE* np = m_Parent; 285 | 286 | while( NULL != np->GetParent() ) 287 | np = np->GetParent(); 288 | 289 | if( np->WriteCache( aFile, NULL ) ) 290 | { 291 | m_written = true; 292 | return true; 293 | } 294 | 295 | return false; 296 | } 297 | 298 | if( parentNode != m_Parent ) 299 | { 300 | #ifdef DEBUG 301 | std::ostringstream ostr; 302 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 303 | ostr << " * [BUG] corrupt data; parentNode != m_aParent"; 304 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 305 | #endif 306 | 307 | return false; 308 | } 309 | 310 | if( !aFile.good() ) 311 | { 312 | #ifdef DEBUG 313 | std::ostringstream ostr; 314 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 315 | ostr << " * [INFO] bad stream"; 316 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 317 | #endif 318 | 319 | return false; 320 | } 321 | 322 | aFile << "[" << GetName() << "]"; 323 | size_t ncolors = colors.size(); 324 | aFile.write( (char*)&ncolors, sizeof(size_t) ); 325 | 326 | for( size_t i = 0; i < ncolors; ++i ) 327 | S3D::WriteColor( aFile, colors[i] ); 328 | 329 | if( aFile.fail() ) 330 | return false; 331 | 332 | m_written = true; 333 | return true; 334 | } 335 | 336 | 337 | bool SGCOLORS::ReadCache( std::ifstream& aFile, SGNODE* parentNode ) 338 | { 339 | if( !colors.empty() ) 340 | { 341 | #ifdef DEBUG 342 | std::ostringstream ostr; 343 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 344 | ostr << " * [BUG] non-empty node"; 345 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 346 | #endif 347 | 348 | return false; 349 | } 350 | 351 | size_t ncolors; 352 | aFile.read( (char*)&ncolors, sizeof(size_t) ); 353 | SGCOLOR tmp; 354 | 355 | if( aFile.fail() ) 356 | return false; 357 | 358 | for( size_t i = 0; i < ncolors; ++i ) 359 | { 360 | if( !S3D::ReadColor( aFile, tmp ) || aFile.fail() ) 361 | return false; 362 | 363 | colors.push_back( tmp ); 364 | } 365 | 366 | return true; 367 | } 368 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_index.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "3d_cache/sg/sg_index.h" 30 | 31 | 32 | SGINDEX::SGINDEX( SGNODE* aParent ) : SGNODE( aParent ) 33 | { 34 | if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() ) 35 | { 36 | m_Parent = NULL; 37 | 38 | #ifdef DEBUG 39 | std::ostringstream ostr; 40 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 41 | ostr << " * [BUG] inappropriate parent to SGINDEX (type "; 42 | ostr << aParent->GetNodeType() << ")"; 43 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 44 | #endif 45 | } 46 | 47 | return; 48 | } 49 | 50 | 51 | SGINDEX::~SGINDEX() 52 | { 53 | index.clear(); 54 | return; 55 | } 56 | 57 | 58 | bool SGINDEX::SetParent( SGNODE* aParent, bool notify ) 59 | { 60 | if( NULL != m_Parent ) 61 | { 62 | if( aParent == m_Parent ) 63 | return true; 64 | 65 | // handle the change in parents 66 | if( notify ) 67 | m_Parent->unlinkChildNode( this ); 68 | 69 | m_Parent = NULL; 70 | 71 | if( NULL == aParent ) 72 | return true; 73 | } 74 | 75 | // only a SGFACESET may be parent to a SGINDEX and derived types 76 | if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() ) 77 | return false; 78 | 79 | m_Parent = aParent; 80 | 81 | if( m_Parent ) 82 | m_Parent->AddChildNode( this ); 83 | 84 | return true; 85 | } 86 | 87 | 88 | SGNODE* SGINDEX::FindNode(const char *aNodeName, const SGNODE *aCaller) 89 | { 90 | if( NULL == aNodeName || 0 == aNodeName[0] ) 91 | return NULL; 92 | 93 | if( !m_Name.compare( aNodeName ) ) 94 | return this; 95 | 96 | return NULL; 97 | } 98 | 99 | 100 | void SGINDEX::unlinkChildNode( const SGNODE* aCaller ) 101 | { 102 | #ifdef DEBUG 103 | std::ostringstream ostr; 104 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 105 | ostr << " * [BUG] unexpected code branch; node should have no children or refs"; 106 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 107 | #endif 108 | 109 | return; 110 | } 111 | 112 | 113 | void SGINDEX::unlinkRefNode( const SGNODE* aCaller ) 114 | { 115 | #ifdef DEBUG 116 | std::ostringstream ostr; 117 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 118 | ostr << " * [BUG] unexpected code branch; node should have no children or refs"; 119 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 120 | #endif 121 | 122 | return; 123 | } 124 | 125 | 126 | bool SGINDEX::AddRefNode( SGNODE* aNode ) 127 | { 128 | #ifdef DEBUG 129 | std::ostringstream ostr; 130 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 131 | ostr << " * [BUG] this node does not accept children or refs"; 132 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 133 | #endif 134 | 135 | return false; 136 | } 137 | 138 | 139 | bool SGINDEX::AddChildNode( SGNODE* aNode ) 140 | { 141 | #ifdef DEBUG 142 | std::ostringstream ostr; 143 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 144 | ostr << " * [BUG] this node does not accept children or refs"; 145 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 146 | #endif 147 | 148 | return false; 149 | } 150 | 151 | 152 | bool SGINDEX::GetIndices( size_t& nIndices, int*& aIndexList ) 153 | { 154 | if( index.empty() ) 155 | { 156 | nIndices = 0; 157 | aIndexList = NULL; 158 | return false; 159 | } 160 | 161 | nIndices = index.size(); 162 | aIndexList = & index[0]; 163 | return true; 164 | } 165 | 166 | 167 | void SGINDEX::SetIndices( size_t nIndices, int* aIndexList ) 168 | { 169 | index.clear(); 170 | 171 | if( 0 == nIndices || NULL == aIndexList ) 172 | return; 173 | 174 | for( size_t i = 0; i < nIndices; ++i ) 175 | index.push_back( aIndexList[i] ); 176 | 177 | return; 178 | } 179 | 180 | 181 | void SGINDEX::AddIndex( int aIndex ) 182 | { 183 | index.push_back( aIndex ); 184 | return; 185 | } 186 | 187 | 188 | void SGINDEX::ReNameNodes( void ) 189 | { 190 | m_written = false; 191 | 192 | // rename this node 193 | m_Name.clear(); 194 | GetName(); 195 | } 196 | 197 | 198 | bool SGINDEX::WriteVRML( std::ofstream& aFile, bool aReuseFlag ) 199 | { 200 | if( index.empty() ) 201 | return false; 202 | 203 | if( S3D::SGTYPE_COORDINDEX == m_SGtype ) 204 | return writeCoordIndex( aFile ); 205 | 206 | return writeColorIndex( aFile ); 207 | } 208 | 209 | 210 | bool SGINDEX::writeCoordIndex( std::ofstream& aFile ) 211 | { 212 | size_t n = index.size(); 213 | 214 | if( n % 3 ) 215 | { 216 | #ifdef DEBUG 217 | std::ostringstream ostr; 218 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 219 | ostr << " * [BUG] coord index is not divisible by three (violates triangle constraint)"; 220 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 221 | #endif 222 | 223 | return false; 224 | } 225 | 226 | aFile << " coordIndex [\n "; 227 | 228 | // indices to control formatting 229 | int nv0 = 0; 230 | int nv1 = 0; 231 | 232 | for( size_t i = 0; i < n; ) 233 | { 234 | aFile << index[i]; 235 | ++i; 236 | 237 | if( ++nv0 == 3 ) 238 | { 239 | aFile << ",-1"; 240 | ++nv1; 241 | nv0 = 0; 242 | } 243 | 244 | if( i < n ) 245 | { 246 | aFile << ","; 247 | 248 | if( nv1 == 8 ) 249 | { 250 | nv1 = 0; 251 | aFile << "\n "; 252 | } 253 | } 254 | } 255 | 256 | aFile << "]\n"; 257 | 258 | return true; 259 | } 260 | 261 | 262 | bool SGINDEX::writeColorIndex( std::ofstream& aFile ) 263 | { 264 | aFile << " colorIndex [\n "; 265 | return writeIndexList( aFile ); 266 | } 267 | 268 | 269 | bool SGINDEX::writeIndexList( std::ofstream& aFile ) 270 | { 271 | // index to control formatting 272 | int nv = 0; 273 | size_t n = index.size(); 274 | 275 | for( size_t i = 0; i < n; ) 276 | { 277 | aFile << index[i]; 278 | ++i; 279 | 280 | if( i < n ) 281 | { 282 | aFile << ","; 283 | 284 | if( ++nv == 20 ) 285 | { 286 | aFile << "\n "; 287 | nv = 0; 288 | } 289 | } 290 | } 291 | 292 | aFile << "]\n"; 293 | 294 | return true; 295 | } 296 | 297 | 298 | bool SGINDEX::WriteCache( std::ofstream& aFile, SGNODE* parentNode ) 299 | { 300 | if( NULL == parentNode ) 301 | { 302 | if( NULL == m_Parent ) 303 | { 304 | #ifdef DEBUG 305 | std::ostringstream ostr; 306 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 307 | ostr << " * [BUG] corrupt data; m_aParent is NULL"; 308 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 309 | #endif 310 | 311 | return false; 312 | } 313 | 314 | SGNODE* np = m_Parent; 315 | 316 | while( NULL != np->GetParent() ) 317 | np = np->GetParent(); 318 | 319 | if( np->WriteCache( aFile, NULL ) ) 320 | { 321 | m_written = true; 322 | return true; 323 | } 324 | 325 | return false; 326 | } 327 | 328 | if( parentNode != m_Parent ) 329 | { 330 | #ifdef DEBUG 331 | std::ostringstream ostr; 332 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 333 | ostr << " * [BUG] corrupt data; parentNode != m_aParent"; 334 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 335 | #endif 336 | 337 | return false; 338 | } 339 | 340 | if( !aFile.good() ) 341 | { 342 | #ifdef DEBUG 343 | std::ostringstream ostr; 344 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 345 | ostr << " * [INFO] bad stream"; 346 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 347 | #endif 348 | 349 | return false; 350 | } 351 | 352 | aFile << "[" << GetName() << "]"; 353 | size_t npts = index.size(); 354 | aFile.write( (char*)&npts, sizeof(size_t) ); 355 | 356 | for( size_t i = 0; i < npts; ++i ) 357 | aFile.write( (char*)&index[i], sizeof(int) ); 358 | 359 | if( aFile.fail() ) 360 | return false; 361 | 362 | m_written = true; 363 | return true; 364 | } 365 | 366 | 367 | bool SGINDEX::ReadCache( std::ifstream& aFile, SGNODE* parentNode ) 368 | { 369 | if( !index.empty() ) 370 | { 371 | #ifdef DEBUG 372 | std::ostringstream ostr; 373 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 374 | ostr << " * [BUG] non-empty node"; 375 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 376 | #endif 377 | 378 | return false; 379 | } 380 | 381 | size_t npts; 382 | aFile.read( (char*)&npts, sizeof(size_t) ); 383 | int tmp; 384 | 385 | if( aFile.fail() ) 386 | return false; 387 | 388 | for( size_t i = 0; i < npts; ++i ) 389 | { 390 | aFile.read( (char*)&tmp, sizeof(int) ); 391 | 392 | if( aFile.fail() ) 393 | return false; 394 | 395 | index.push_back( tmp ); 396 | } 397 | 398 | return true; 399 | } 400 | -------------------------------------------------------------------------------- /scenegraph/3d_cache/sg/sg_coords.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * This program source code file is part of KiCad, a free EDA CAD application. 3 | * 4 | * Copyright (C) 2015 Cirilo Bernardo 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 2 9 | * of the License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, you may find one here: 18 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 19 | * or you may search the http://www.gnu.org website for the version 2 license, 20 | * or you may write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "3d_cache/sg/sg_coords.h" 29 | #include "3d_cache/sg/sg_helpers.h" 30 | #include "3d_cache/sg/sg_normals.h" 31 | #include "3d_cache/sg/sg_faceset.h" 32 | 33 | 34 | SGCOORDS::SGCOORDS( SGNODE* aParent ) : SGNODE( aParent ) 35 | { 36 | m_SGtype = S3D::SGTYPE_COORDS; 37 | 38 | if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() ) 39 | { 40 | m_Parent = NULL; 41 | 42 | #ifdef DEBUG 43 | std::ostringstream ostr; 44 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 45 | ostr << " * [BUG] inappropriate parent to SGCOORDS (type "; 46 | ostr << aParent->GetNodeType() << ")"; 47 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 48 | #endif 49 | } 50 | else if( NULL != aParent && S3D::SGTYPE_FACESET == aParent->GetNodeType() ) 51 | { 52 | m_Parent->AddChildNode( this ); 53 | } 54 | 55 | return; 56 | } 57 | 58 | 59 | SGCOORDS::~SGCOORDS() 60 | { 61 | coords.clear(); 62 | return; 63 | } 64 | 65 | 66 | bool SGCOORDS::SetParent( SGNODE* aParent, bool notify ) 67 | { 68 | if( NULL != m_Parent ) 69 | { 70 | if( aParent == m_Parent ) 71 | return true; 72 | 73 | // handle the change in parents 74 | if( notify ) 75 | m_Parent->unlinkChildNode( this ); 76 | 77 | m_Parent = NULL; 78 | 79 | if( NULL == aParent ) 80 | return true; 81 | } 82 | 83 | // only a SGFACESET may be parent to a SGCOORDS 84 | if( NULL != aParent && S3D::SGTYPE_FACESET != aParent->GetNodeType() ) 85 | return false; 86 | 87 | m_Parent = aParent; 88 | 89 | if( m_Parent ) 90 | m_Parent->AddChildNode( this ); 91 | 92 | return true; 93 | } 94 | 95 | 96 | SGNODE* SGCOORDS::FindNode(const char *aNodeName, const SGNODE *aCaller) 97 | { 98 | if( NULL == aNodeName || 0 == aNodeName[0] ) 99 | return NULL; 100 | 101 | if( !m_Name.compare( aNodeName ) ) 102 | return this; 103 | 104 | return NULL; 105 | } 106 | 107 | 108 | void SGCOORDS::unlinkChildNode( const SGNODE* aCaller ) 109 | { 110 | #ifdef DEBUG 111 | std::ostringstream ostr; 112 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 113 | ostr << " * [BUG] unexpected code branch; node should have no children or refs"; 114 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 115 | #endif 116 | 117 | return; 118 | } 119 | 120 | 121 | void SGCOORDS::unlinkRefNode( const SGNODE* aCaller ) 122 | { 123 | #ifdef DEBUG 124 | std::ostringstream ostr; 125 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 126 | ostr << " * [BUG] unexpected code branch; node should have no children or refs"; 127 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 128 | #endif 129 | 130 | return; 131 | } 132 | 133 | 134 | bool SGCOORDS::AddRefNode( SGNODE* aNode ) 135 | { 136 | #ifdef DEBUG 137 | std::ostringstream ostr; 138 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 139 | ostr << " * [BUG] this node does not accept children or refs"; 140 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 141 | #endif 142 | 143 | return false; 144 | } 145 | 146 | 147 | bool SGCOORDS::AddChildNode( SGNODE* aNode ) 148 | { 149 | #ifdef DEBUG 150 | std::ostringstream ostr; 151 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 152 | ostr << " * [BUG] this node does not accept children or refs"; 153 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 154 | #endif 155 | 156 | return false; 157 | } 158 | 159 | 160 | bool SGCOORDS::GetCoordsList( size_t& aListSize, SGPOINT*& aCoordsList ) 161 | { 162 | if( coords.empty() ) 163 | { 164 | aListSize = 0; 165 | aCoordsList = NULL; 166 | return false; 167 | } 168 | 169 | aListSize = coords.size(); 170 | aCoordsList = &coords[0]; 171 | return true; 172 | } 173 | 174 | 175 | void SGCOORDS::SetCoordsList( size_t aListSize, const SGPOINT* aCoordsList ) 176 | { 177 | coords.clear(); 178 | 179 | if( 0 == aListSize || NULL == aCoordsList ) 180 | return; 181 | 182 | for( size_t i = 0; i < aListSize; ++i ) 183 | coords.push_back( aCoordsList[i] ); 184 | 185 | return; 186 | } 187 | 188 | 189 | void SGCOORDS::AddCoord( double aXValue, double aYValue, double aZValue ) 190 | { 191 | coords.push_back( SGPOINT( aXValue, aYValue, aZValue ) ); 192 | return; 193 | } 194 | 195 | 196 | void SGCOORDS::AddCoord( const SGPOINT& aPoint ) 197 | { 198 | coords.push_back( aPoint ); 199 | return; 200 | } 201 | 202 | 203 | void SGCOORDS::ReNameNodes( void ) 204 | { 205 | m_written = false; 206 | 207 | // rename this node 208 | m_Name.clear(); 209 | GetName(); 210 | } 211 | 212 | 213 | bool SGCOORDS::WriteVRML( std::ofstream& aFile, bool aReuseFlag ) 214 | { 215 | if( coords.empty() ) 216 | return false; 217 | 218 | if( aReuseFlag ) 219 | { 220 | if( !m_written ) 221 | { 222 | aFile << " coord DEF " << GetName() << " Coordinate { point [\n "; 223 | m_written = true; 224 | } 225 | else 226 | { 227 | aFile << " coord USE " << GetName() << "\n"; 228 | return true; 229 | } 230 | } 231 | else 232 | { 233 | aFile << " coord Coordinate { point [\n "; 234 | } 235 | 236 | std::string tmp; 237 | size_t n = coords.size(); 238 | bool nline = false; 239 | SGPOINT pt; 240 | 241 | for( size_t i = 0; i < n; ) 242 | { 243 | // ensure VRML output has 1U = 0.1 inch as per legacy kicad expectations 244 | pt = coords[i]; 245 | pt.x /= 2.54; 246 | pt.y /= 2.54; 247 | pt.z /= 2.54; 248 | S3D::FormatPoint( tmp, pt ); 249 | aFile << tmp ; 250 | ++i; 251 | 252 | if( i < n ) 253 | { 254 | aFile << ","; 255 | 256 | if( nline ) 257 | { 258 | aFile << "\n "; 259 | nline = false; 260 | } 261 | else 262 | { 263 | nline = true; 264 | } 265 | 266 | } 267 | } 268 | 269 | aFile << "] }\n"; 270 | 271 | return true; 272 | } 273 | 274 | 275 | bool SGCOORDS::WriteCache( std::ofstream& aFile, SGNODE* parentNode ) 276 | { 277 | if( NULL == parentNode ) 278 | { 279 | if( NULL == m_Parent ) 280 | { 281 | #ifdef DEBUG 282 | std::ostringstream ostr; 283 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 284 | ostr << " * [BUG] corrupt data; m_aParent is NULL"; 285 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 286 | #endif 287 | 288 | return false; 289 | } 290 | 291 | SGNODE* np = m_Parent; 292 | 293 | while( NULL != np->GetParent() ) 294 | np = np->GetParent(); 295 | 296 | if( np->WriteCache( aFile, NULL ) ) 297 | { 298 | m_written = true; 299 | return true; 300 | } 301 | 302 | return false; 303 | } 304 | 305 | if( parentNode != m_Parent ) 306 | { 307 | #ifdef DEBUG 308 | std::ostringstream ostr; 309 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 310 | ostr << " * [BUG] corrupt data; parentNode != m_aParent"; 311 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 312 | #endif 313 | 314 | return false; 315 | } 316 | 317 | if( !aFile.good() ) 318 | { 319 | #ifdef DEBUG 320 | std::ostringstream ostr; 321 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 322 | ostr << " * [INFO] bad stream"; 323 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 324 | #endif 325 | 326 | return false; 327 | } 328 | 329 | aFile << "[" << GetName() << "]"; 330 | size_t npts = coords.size(); 331 | aFile.write( (char*)&npts, sizeof(size_t) ); 332 | 333 | for( size_t i = 0; i < npts; ++i ) 334 | S3D::WritePoint( aFile, coords[i] ); 335 | 336 | if( aFile.fail() ) 337 | return false; 338 | 339 | m_written = true; 340 | return true; 341 | } 342 | 343 | 344 | bool SGCOORDS::ReadCache( std::ifstream& aFile, SGNODE* parentNode ) 345 | { 346 | if( !coords.empty() ) 347 | { 348 | #ifdef DEBUG 349 | std::ostringstream ostr; 350 | ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; 351 | ostr << " * [BUG] non-empty node"; 352 | wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() ); 353 | #endif 354 | 355 | return false; 356 | } 357 | 358 | size_t npts; 359 | aFile.read( (char*)&npts, sizeof(size_t) ); 360 | SGPOINT tmp; 361 | 362 | if( aFile.fail() ) 363 | return false; 364 | 365 | for( size_t i = 0; i < npts; ++i ) 366 | { 367 | if( !S3D::ReadPoint( aFile, tmp ) || aFile.fail() ) 368 | return false; 369 | 370 | coords.push_back( tmp ); 371 | } 372 | 373 | return true; 374 | } 375 | 376 | 377 | bool SGCOORDS::CalcNormals( SGFACESET* callingNode, SGNODE** aPtr ) 378 | { 379 | if( aPtr ) 380 | *aPtr = NULL; 381 | 382 | if( NULL == m_Parent || NULL == callingNode ) 383 | return false; 384 | 385 | // the parent and all references must have indices; collect all 386 | // indices into one std::vector<> 387 | std::vector< int > ilist; 388 | SGNORMALS* np = NULL; 389 | 390 | if( callingNode == m_Parent ) 391 | { 392 | ((SGFACESET*)m_Parent)->GatherCoordIndices( ilist ); 393 | 394 | std::list< SGNODE* >::iterator sB = m_BackPointers.begin(); 395 | std::list< SGNODE* >::iterator eB = m_BackPointers.end(); 396 | 397 | while( sB != eB ) 398 | { 399 | SGFACESET* fp = (SGFACESET*)(*sB); 400 | fp->GatherCoordIndices( ilist ); 401 | ++sB; 402 | } 403 | 404 | np = ((SGFACESET*)m_Parent)->m_Normals; 405 | 406 | if( !np ) 407 | np = new SGNORMALS( m_Parent ); 408 | 409 | } 410 | else 411 | { 412 | callingNode->GatherCoordIndices( ilist ); 413 | np = callingNode->m_Normals; 414 | 415 | if( !np ) 416 | np = new SGNORMALS( callingNode ); 417 | 418 | } 419 | 420 | if( S3D::CalcTriangleNormals( coords, ilist, np->norms ) ) 421 | { 422 | if( aPtr ) 423 | *aPtr = np; 424 | 425 | return true; 426 | } 427 | 428 | delete np; 429 | 430 | return false; 431 | } 432 | --------------------------------------------------------------------------------