3d_class.cpp 3.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/**
 * @file 3d_class.cpp
 */

/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 1992-2012 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
 * 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
 */

28

29
#include <fctsys.h>
30

31
#include <3d_viewer.h>
32
#include <3d_struct.h>
33

34

35 36 37 38 39 40 41
bool S3D_MASTER::IsOpenGlAllowed()
{
    if( m_loadNonTransparentObjects )    // return true for non transparent objects only
    {
        if( m_lastTransparency == 0.0 )
            return true;
    }
42 43 44

    if( m_loadTransparentObjects )      // return true for transparent objects only
    {
45 46
        if( m_lastTransparency != 0.0 )
            return true;
47
    }
48 49 50 51

    return false;
}

52 53 54 55 56

void S3D_MASTER::Insert( S3D_MATERIAL* aMaterial )
{
    aMaterial->SetNext( m_Materials );
    m_Materials = aMaterial;
57 58
}

59

dickelbeck's avatar
dickelbeck committed
60
void S3D_MASTER::Copy( S3D_MASTER* pattern )
61
{
62
    SetShape3DName( pattern->GetShape3DName() );
63 64 65 66 67
    m_MatScale    = pattern->m_MatScale;
    m_MatRotation = pattern->m_MatRotation;
    m_MatPosition = pattern->m_MatPosition;
    m_3D_Drawings = NULL;
    m_Materials   = NULL;
68 69
}

70

71 72
S3D_MASTER::S3D_MASTER( EDA_ITEM* aParent ) :
    EDA_ITEM( aParent, NOT_USED )
73
{
74
    m_MatScale.x  = m_MatScale.y = m_MatScale.z = 1.0;
75
    m_lastTransparency = 0.0;
76 77
    m_3D_Drawings = NULL;
    m_Materials   = NULL;
78
    m_ShapeType   = FILE3D_NONE;
79 80

    m_use_modelfile_diffuseColor = true;
81 82 83
    m_use_modelfile_emissiveColor = true;
    m_use_modelfile_specularColor = true;
    m_use_modelfile_ambientIntensity = true;
84
    m_use_modelfile_transparency = true;
85
    m_use_modelfile_shininess = true;
86 87 88
}


dickelbeck's avatar
dickelbeck committed
89
S3D_MASTER:: ~S3D_MASTER()
90
{
91
    STRUCT_3D_SHAPE* next;
dickelbeck's avatar
dickelbeck committed
92
    S3D_MATERIAL*   nextmat;
93 94 95 96 97 98 99

    for( ; m_3D_Drawings != NULL; m_3D_Drawings = next )
    {
        next = m_3D_Drawings->Next();
        delete m_3D_Drawings;
    }

100
    for( ; m_Materials != NULL; m_Materials = nextmat )
101 102 103 104
    {
        nextmat = m_Materials->Next();
        delete m_Materials;
    }
105 106 107
}


108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
bool S3D_MASTER::Is3DType( enum FILE3D_TYPE aShapeType )
{
    // type 'none' is not valid and will always return false
    if( aShapeType == FILE3D_NONE )
        return false;

    // no one is interested if we have no file
    if( m_Shape3DName.empty() )
        return false;

    if( aShapeType == m_ShapeType )
        return true;

    return false;
}


void S3D_MASTER::SetShape3DName( const wxString& aShapeName )
{
    m_ShapeType = FILE3D_NONE;
    m_Shape3DName = aShapeName;

    if( m_Shape3DName.empty() )
        return;

    wxFileName fn = m_Shape3DName;
    wxString ext  = fn.GetExt();

    if( ext == wxT( "wrl" ) || ext == wxT( "x3d" ) )
        m_ShapeType = FILE3D_VRML;
    else if( ext == wxT( "idf" ) )
        m_ShapeType = FILE3D_IDF;
    else
        m_ShapeType = FILE3D_UNKNOWN;

    return;
}


147
STRUCT_3D_SHAPE::STRUCT_3D_SHAPE( EDA_ITEM* aParent ) :
148
    EDA_ITEM( aParent, NOT_USED )
149
{
150
    m_3D_Coord = NULL;
151 152
    m_3D_CoordIndex = NULL;
    m_3D_Points     = 0;
153 154 155
}


156
STRUCT_3D_SHAPE:: ~STRUCT_3D_SHAPE()
157
{
158 159
    delete m_3D_Coord;
    delete m_3D_CoordIndex;
160
}