2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-04-25 14:38:41 +00:00
|
|
|
* Copyright (C) 2015-2020 Mario Luzeiro <mrluzeiro@ua.pt>
|
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-01-03 22:23:00 +00:00
|
|
|
* @file object_3d.h
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#ifndef _OBJECT_3D_H_
|
|
|
|
#define _OBJECT_3D_H_
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "bbox_3d.h"
|
|
|
|
#include "../material.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
class BOARD_ITEM;
|
|
|
|
class HITINFOR;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
enum class OBJECT_3D_TYPE
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2019-12-30 13:01:06 +00:00
|
|
|
CYLINDER,
|
|
|
|
DUMMYBLOCK,
|
|
|
|
LAYERITEM,
|
|
|
|
XYPLANE,
|
|
|
|
ROUNDSEG,
|
|
|
|
TRIANGLE,
|
|
|
|
MAX
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
class OBJECT_3D
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-01-02 21:05:29 +00:00
|
|
|
explicit OBJECT_3D( OBJECT_3D_TYPE aObjType );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2023-05-20 12:00:00 +00:00
|
|
|
void SetBoardItem( BOARD_ITEM* aBoardItem ) { m_boardItem = aBoardItem; }
|
2021-01-02 21:05:29 +00:00
|
|
|
BOARD_ITEM* GetBoardItem() const { return m_boardItem; }
|
2020-09-04 00:00:56 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void SetMaterial( const MATERIAL* aMaterial )
|
2020-05-22 13:28:04 +00:00
|
|
|
{
|
|
|
|
m_material = aMaterial;
|
|
|
|
m_modelTransparency = aMaterial->GetTransparency(); // Default transparency is from material
|
|
|
|
}
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
const MATERIAL* GetMaterial() const { return m_material; }
|
2020-04-25 14:38:41 +00:00
|
|
|
float GetModelTransparency() const { return m_modelTransparency; }
|
2020-12-11 13:51:42 +00:00
|
|
|
void SetModelTransparency( float aModelTransparency )
|
|
|
|
{
|
|
|
|
m_modelTransparency = aModelTransparency;
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual SFVEC3F GetDiffuseColor( const HITINFO& aHitInfo ) const = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual ~OBJECT_3D() {}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* @return true if this object intersects \a aBBox.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual bool Intersects( const BBOX_3D& aBBox ) const = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* @return true if the \a aRay intersects the object.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual bool Intersect( const RAY& aRay, HITINFO& aHitInfo ) const = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* @param aMaxDistance is the maximum distance of the test.
|
|
|
|
* @return true if \a aRay intersects the object.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual bool IntersectP( const RAY& aRay, float aMaxDistance ) const = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const BBOX_3D& GetBBox() const { return m_bbox; }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const SFVEC3F& GetCentroid() const { return m_centroid; }
|
2020-12-11 13:51:42 +00:00
|
|
|
|
|
|
|
protected:
|
2021-01-02 21:05:29 +00:00
|
|
|
BBOX_3D m_bbox;
|
2020-12-11 13:51:42 +00:00
|
|
|
SFVEC3F m_centroid;
|
2021-01-02 21:05:29 +00:00
|
|
|
OBJECT_3D_TYPE m_obj_type;
|
|
|
|
const MATERIAL* m_material;
|
2020-12-11 13:51:42 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
BOARD_ITEM* m_boardItem;
|
2020-12-11 13:51:42 +00:00
|
|
|
|
|
|
|
// m_modelTransparency combines the material and model opacity
|
|
|
|
// 0.0 full opaque, 1.0 full transparent.
|
|
|
|
float m_modelTransparency;
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Implements a class for object statistics
|
|
|
|
/// using Singleton pattern
|
2021-01-02 21:05:29 +00:00
|
|
|
class OBJECT_3D_STATS
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-12-30 13:01:06 +00:00
|
|
|
void ResetStats()
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT_3D_TYPE::MAX ) );
|
2019-12-30 13:01:06 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
unsigned int GetCountOf( OBJECT_3D_TYPE aObjType ) const
|
2019-12-30 13:01:06 +00:00
|
|
|
{
|
|
|
|
return m_counter[static_cast<int>( aObjType )];
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void AddOne( OBJECT_3D_TYPE aObjType )
|
2019-12-30 13:01:06 +00:00
|
|
|
{
|
|
|
|
m_counter[static_cast<int>( aObjType )]++;
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-05-03 20:07:16 +00:00
|
|
|
// void PrintStats();
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
static OBJECT_3D_STATS& Instance()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
if( !s_instance )
|
2021-01-02 21:05:29 +00:00
|
|
|
s_instance = new OBJECT_3D_STATS;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
return *s_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-01-02 21:05:29 +00:00
|
|
|
OBJECT_3D_STATS(){ ResetStats(); }
|
|
|
|
OBJECT_3D_STATS( const OBJECT_3D_STATS& old );
|
|
|
|
const OBJECT_3D_STATS& operator=( const OBJECT_3D_STATS& old );
|
|
|
|
~OBJECT_3D_STATS() {}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
unsigned int m_counter[static_cast<int>( OBJECT_3D_TYPE::MAX )];
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
static OBJECT_3D_STATS* s_instance;
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#endif // _OBJECT_3D_H_
|