Browse Source

Simplify 3D object cache class structure

Remove the CACHE_WRAPPER whose sole purpose was to allow the
cache to be stored in the project, and instead just have the cache
inherit the proper class.
pull/16/head
Ian McInerney 6 years ago
parent
commit
56f6b529c8
  1. 52
      3d-viewer/3d_cache/3d_cache.cpp
  2. 24
      3d-viewer/3d_cache/3d_cache.h
  3. 76
      3d-viewer/3d_cache/3d_cache_wrapper.cpp
  4. 39
      3d-viewer/3d_cache/3d_cache_wrapper.h
  5. 1
      3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp
  6. 1
      3d-viewer/CMakeLists.txt
  7. 2
      include/core/typeinfo.h
  8. 1
      pcbnew/exporters/export_vrml.cpp

52
3d-viewer/3d_cache/3d_cache.cpp

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -24,11 +24,11 @@
#define GLM_FORCE_RADIANS
#include <fstream>
#include <iostream>
#include <iterator>
#include <sstream>
#include <fstream>
#include <utility>
#include <iterator>
#include <wx/datetime.h>
#include <wx/filename.h>
@ -46,18 +46,22 @@
#include <glm/glm.hpp>
#include <glm/ext.hpp>
#include "common.h"
#include "3d_cache.h"
#include "3d_info.h"
#include "sg/scenegraph.h"
#include "filename_resolver.h"
#include "3d_plugin_manager.h"
#include "sg/scenegraph.h"
#include "plugins/3dapi/ifsg_api.h"
#include <common.h>
#include <filename_resolver.h>
#include <pgm_base.h>
#include <project.h>
#define MASK_3D_CACHE "3D_CACHE"
static wxCriticalSection lock3D_cache;
static wxCriticalSection lock3D_cacheManager;
static bool isSHA1Same( const unsigned char* shaA, const unsigned char* shaB )
@ -772,3 +776,39 @@ wxString S3D_CACHE::GetModelHash( const wxString& aModelFileName )
return wxEmptyString;
}
S3D_CACHE* PROJECT::Get3DCacheManager( bool aUpdateProjDir )
{
wxCriticalSectionLocker lock( lock3D_cacheManager );
// Get the existing cache from the project
S3D_CACHE* cache = dynamic_cast<S3D_CACHE*>( GetElem( ELEM_3DCACHE ) );
if( !cache )
{
// Create a cache if there is not one already
cache = new S3D_CACHE();
wxFileName cfgpath;
cfgpath.AssignDir( GetKicadConfigPath() );
cfgpath.AppendDir( wxT( "3d" ) );
cache->SetProgramBase( &Pgm() );
cache->Set3DConfigDir( cfgpath.GetFullPath() );
SetElem( ELEM_3DCACHE, cache );
aUpdateProjDir = true;
}
if( aUpdateProjDir )
cache->SetProjectDir( GetProjectPath() );
return cache;
}
FILENAME_RESOLVER* PROJECT::Get3DFilenameResolver()
{
return Get3DCacheManager()->GetResolver();
}

24
3d-viewer/3d_cache/3d_cache.h

@ -29,24 +29,29 @@
#ifndef CACHE_3D_H
#define CACHE_3D_H
#include "3d_info.h"
#include <core/typeinfo.h>
#include "kicad_string.h"
#include <list>
#include <map>
#include <wx/string.h>
#include "kicad_string.h"
#include "filename_resolver.h"
#include "3d_info.h"
#include "plugins/3dapi/c3dmodel.h"
#include <project.h>
#include <wx/string.h>
class PGM_BASE;
class S3D_CACHE;
class S3D_CACHE_ENTRY;
class SCENEGRAPH;
class FILENAME_RESOLVER;
class S3D_PLUGIN_MANAGER;
class S3D_CACHE
/**
* S3D_CACHE
*
* Cache for storing the 3D shapes. This cache is able to be stored as a project
* element (since it inherits from PROJECT::_ELEM).
*/
class S3D_CACHE : public PROJECT::_ELEM
{
private:
/// cache entries
@ -110,6 +115,11 @@ public:
S3D_CACHE();
virtual ~S3D_CACHE();
KICAD_T Type() override
{
return S3D_CACHE_T;
}
/**
* Function Set3DConfigDir
* Sets the configuration directory to be used by the

76
3d-viewer/3d_cache/3d_cache_wrapper.cpp

@ -1,76 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <common.h>
#include <pgm_base.h>
#include "3d_cache_wrapper.h"
static wxCriticalSection lock3D_wrapper;
CACHE_WRAPPER::CACHE_WRAPPER()
{
return;
}
CACHE_WRAPPER::~CACHE_WRAPPER()
{
return;
}
FILENAME_RESOLVER* PROJECT::Get3DFilenameResolver()
{
return Get3DCacheManager()->GetResolver();
}
S3D_CACHE* PROJECT::Get3DCacheManager( bool updateProjDir )
{
wxCriticalSectionLocker lock( lock3D_wrapper );
CACHE_WRAPPER* cw = (CACHE_WRAPPER*) GetElem( ELEM_3DCACHE );
S3D_CACHE* cache = dynamic_cast<S3D_CACHE*>( cw );
// check that we get the expected type of object or NULL
wxASSERT( !cw || cache );
if( !cw )
{
cw = new CACHE_WRAPPER;
cache = dynamic_cast<S3D_CACHE*>( cw );
wxFileName cfgpath;
cfgpath.AssignDir( GetKicadConfigPath() );
cfgpath.AppendDir( wxT( "3d" ) );
cache->SetProgramBase( &Pgm() );
cache->Set3DConfigDir( cfgpath.GetFullPath() );
SetElem( ELEM_3DCACHE, cw );
updateProjDir = true;
}
if( updateProjDir )
cache->SetProjectDir( GetProjectPath() );
return cache;
}

39
3d-viewer/3d_cache/3d_cache_wrapper.h

@ -1,39 +0,0 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Cirilo Bernardo <cirilo.bernardo@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef CACHE_WRAPPER_3D_H
#define CACHE_WRAPPER_3D_H
#include <project.h>
#include "3d_cache.h"
class CACHE_WRAPPER : public S3D_CACHE, public PROJECT::_ELEM
{
public:
KICAD_T Type() override { return CACHE_WRAPPER_T; }
CACHE_WRAPPER();
virtual ~CACHE_WRAPPER();
};
#endif // CACHE_WRAPPER_3D_H

1
3d-viewer/3d_cache/dialogs/dlg_select_3dmodel.cpp

@ -32,6 +32,7 @@
#include "3d_cache_dialogs.h"
#include <3d_model_viewer/c3d_model_viewer.h>
#include <common_ogl/cogl_att_list.h>
#include <filename_resolver.h>
#include <pcbnew/class_module.h>
#define ID_FILE_TREE ( wxID_LAST + 1 )

1
3d-viewer/CMakeLists.txt

@ -29,7 +29,6 @@ set( DIR_3D_PLUGINS ${CMAKE_SOURCE_DIR}/plugins/ldr )
set(3D-VIEWER_SRCS
${DIR_3D_PLUGINS}/pluginldr.cpp
${DIR_3D_PLUGINS}/3d/pluginldr3D.cpp
3d_cache/3d_cache_wrapper.cpp
3d_cache/3d_cache.cpp
3d_cache/3d_plugin_manager.cpp
${DIR_DLG}/3d_cache_dialogs.cpp

2
include/core/typeinfo.h

@ -198,7 +198,7 @@ enum KICAD_T
FP_LIB_TABLE_T,
PART_LIBS_T,
SEARCH_STACK_T,
CACHE_WRAPPER_T,
S3D_CACHE_T,
// End value
MAX_STRUCT_TYPE_ID

1
pcbnew/exporters/export_vrml.cpp

@ -40,6 +40,7 @@
#include "class_track.h"
#include "class_zone.h"
#include "convert_to_biu.h"
#include <filename_resolver.h>
#include "gr_text.h"
#include "macros.h"
#include "pgm_base.h"

Loading…
Cancel
Save