2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <cmath>
|
2016-02-23 06:46:22 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <wx/log.h>
|
|
|
|
|
2015-12-09 07:30:48 +00:00
|
|
|
#include "plugins/3dapi/sg_base.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
SGCOLOR::SGCOLOR()
|
|
|
|
{
|
|
|
|
red = 0.0;
|
|
|
|
green = 0.0;
|
|
|
|
blue = 0.0;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGCOLOR::SGCOLOR( float aRVal, float aGVal, float aBVal )
|
|
|
|
{
|
|
|
|
if( !checkRange( aRVal, aGVal, aBVal ) )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-02-23 06:46:22 +00:00
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] invalid value passed to constructor";
|
|
|
|
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
|
2015-12-08 07:31:57 +00:00
|
|
|
#endif
|
|
|
|
red = 0.0;
|
|
|
|
green = 0.0;
|
|
|
|
blue = 0.0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
red = aRVal;
|
|
|
|
green = aGVal;
|
|
|
|
blue = aBVal;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGCOLOR::GetColor( float& aRedVal, float& aGreenVal, float& aBlueVal ) const noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
aRedVal = red;
|
|
|
|
aGreenVal = green;
|
|
|
|
aBlueVal = blue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGCOLOR::GetColor( SGCOLOR& aColor ) const noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
aColor.red = red;
|
|
|
|
aColor.green = green;
|
|
|
|
aColor.blue = blue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGCOLOR::GetColor( SGCOLOR* aColor ) const noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
if( NULL == aColor )
|
|
|
|
{
|
2016-01-12 06:09:04 +00:00
|
|
|
#ifdef DEBUG
|
2016-02-23 06:46:22 +00:00
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] NULL pointer passed for aColor";
|
|
|
|
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
|
2016-01-12 06:09:04 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aColor->red = red;
|
|
|
|
aColor->green = green;
|
|
|
|
aColor->blue = blue;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SGCOLOR::SetColor( float aRedVal, float aGreenVal, float aBlueVal )
|
|
|
|
{
|
|
|
|
if( !checkRange( aRedVal, aGreenVal, aBlueVal ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
red = aRedVal;
|
|
|
|
green = aGreenVal;
|
|
|
|
blue = aBlueVal;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
bool SGCOLOR::SetColor( const SGCOLOR& aColor ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
red = aColor.red;
|
|
|
|
green = aColor.green;
|
|
|
|
blue = aColor.blue;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
bool SGCOLOR::SetColor( const SGCOLOR* aColor ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
if( NULL == aColor )
|
|
|
|
{
|
2016-01-12 06:09:04 +00:00
|
|
|
#ifdef DEBUG
|
2016-02-23 06:46:22 +00:00
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] NULL pointer passed for aColor";
|
|
|
|
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
|
2016-01-12 06:09:04 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
red = aColor->red;
|
|
|
|
green = aColor->green;
|
|
|
|
blue = aColor->blue;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
bool SGCOLOR::checkRange( float aRedVal, float aGreenVal, float aBlueVal ) const noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
if( aRedVal < 0.0 || aRedVal > 1.0 )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-02-23 06:46:22 +00:00
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] invalid RED value: " << aRedVal;
|
|
|
|
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
|
2015-12-08 07:31:57 +00:00
|
|
|
#endif
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aGreenVal < 0.0 || aGreenVal > 1.0 )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
if( ok )
|
|
|
|
{
|
2016-02-23 06:46:22 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, "%s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__ );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
2016-02-23 06:46:22 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, " * [BUG] invalid GREEN value: %f\n", aGreenVal );
|
2015-12-08 07:31:57 +00:00
|
|
|
#endif
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aBlueVal < 0.0 || aBlueVal > 1.0 )
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
if( ok )
|
|
|
|
{
|
2016-02-23 06:46:22 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, "%s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__ );
|
2015-12-08 07:31:57 +00:00
|
|
|
}
|
2016-02-23 06:46:22 +00:00
|
|
|
wxLogTrace( MASK_3D_SG, " * [BUG] invalid BLUE value: %f\n", aBlueVal );
|
2015-12-08 07:31:57 +00:00
|
|
|
#endif
|
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SGPOINT::SGPOINT()
|
|
|
|
{
|
|
|
|
x = 0.0;
|
|
|
|
y = 0.0;
|
|
|
|
z = 0.0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
SGPOINT::SGPOINT( double aXVal, double aYVal, double aZVal ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
x = aXVal;
|
|
|
|
y = aYVal;
|
|
|
|
z = aZVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGPOINT::GetPoint( double& aXVal, double& aYVal, double& aZVal ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
x = aXVal;
|
|
|
|
y = aYVal;
|
|
|
|
z = aZVal;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGPOINT::GetPoint( SGPOINT& aPoint ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
x = aPoint.x;
|
|
|
|
y = aPoint.y;
|
|
|
|
z = aPoint.z;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGPOINT::GetPoint( SGPOINT* aPoint ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
if( NULL == aPoint )
|
|
|
|
{
|
2016-01-12 06:09:04 +00:00
|
|
|
#ifdef DEBUG
|
2016-02-23 06:46:22 +00:00
|
|
|
std::ostringstream ostr;
|
|
|
|
ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
|
|
|
|
ostr << " * [BUG] NULL pointer passed for aPoint";
|
|
|
|
wxLogTrace( MASK_3D_SG, "%s\n", ostr.str().c_str() );
|
2016-01-12 06:09:04 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = aPoint->x;
|
|
|
|
y = aPoint->y;
|
|
|
|
z = aPoint->z;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGPOINT::SetPoint( double aXVal, double aYVal, double aZVal ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
x = aXVal;
|
|
|
|
y = aYVal;
|
|
|
|
z = aZVal;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGPOINT::SetPoint( const SGPOINT& aPoint ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
x = aPoint.x;
|
|
|
|
y = aPoint.y;
|
|
|
|
z = aPoint.z;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SGVECTOR::SGVECTOR()
|
|
|
|
{
|
|
|
|
vx = 0.0;
|
|
|
|
vy = 0.0;
|
|
|
|
vz = 1.0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SGVECTOR::SGVECTOR( double aXVal, double aYVal, double aZVal )
|
|
|
|
{
|
|
|
|
vx = aXVal;
|
|
|
|
vy = aYVal;
|
|
|
|
vz = aZVal;
|
|
|
|
normalize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGVECTOR::GetVector( double& aXVal, double& aYVal, double& aZVal ) const noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
aXVal = vx;
|
|
|
|
aYVal = vy;
|
|
|
|
aZVal = vz;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SGVECTOR::SetVector( double aXVal, double aYVal, double aZVal )
|
|
|
|
{
|
|
|
|
vx = aXVal;
|
|
|
|
vy = aYVal;
|
|
|
|
vz = aZVal;
|
|
|
|
normalize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SGVECTOR::SetVector( const SGVECTOR& aVector )
|
|
|
|
{
|
|
|
|
aVector.GetVector( vx, vy, vz );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
void SGVECTOR::normalize( void ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
double dx = vx * vx;
|
|
|
|
double dy = vy * vy;
|
|
|
|
double dz = vz * vz;
|
2015-12-16 03:25:46 +00:00
|
|
|
double dv2 = sqrt( dx + dy + dz );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2015-12-16 03:25:46 +00:00
|
|
|
if( (dx + dy + dz) < 1e-8 )
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
// use the default; the numbers are too small
|
|
|
|
// to be believable
|
|
|
|
vx = 0.0;
|
|
|
|
vy = 0.0;
|
|
|
|
vz = 1.0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-16 03:25:46 +00:00
|
|
|
vx /= dv2;
|
|
|
|
vy /= dv2;
|
|
|
|
vz /= dv2;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:11:21 +00:00
|
|
|
SGVECTOR& SGVECTOR::operator=( const SGVECTOR& source ) noexcept
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
vx = source.vx;
|
|
|
|
vy = source.vy;
|
|
|
|
vz = source.vz;
|
|
|
|
return *this;
|
|
|
|
}
|