using System;
using System.Xml;
using System.Drawing;
using CDAColladaNET.Import.Attributes;
// Copyright (c) 2005 Accelerated Pictures, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace ColladaNET.Import{
public class Param : NamedNode
{
#region Constants
private System.Drawing.Color kInvalidColor = System.Drawing.Color.Fuchsia;
private static readonly string kType = "@type";
private static readonly string kFlowType = "@flow";
private static readonly string kSemantic = "@semantic";
#endregion
#region Enums
public enum EParamType { BOOL, STRING, INT, FLOAT, FLOAT3 };
public enum EFlowType { IN , OUT , INOUT };
#endregion
#region Accessors
#region Semantic
private bool mbSemantic = false;
private string mSemantic;
public string Semantic
{
get
{
if ( mbSemantic == false )
{
mSemantic = XmlSource.SelectSingleNode( kSemantic , Collada.NS ).Value ;
mbSemantic = true;
}
return mSemantic;
}
}
#endregion
#region ParamType
private bool mbParamType = false;
private EParamType mParamType;
public EParamType ParamType
{
get
{
if ( mbParamType == false )
{
mParamType = ((EParamType)(Enum.Parse( typeof(EParamType) , XmlSource.SelectSingleNode( kType , Collada.NS ).Value , true )));
mbParamType = true;
}
return mParamType;
}
}
#endregion
#region FlowType
private bool mbFlowType = false;
private EFlowType mFlowType;
public EFlowType FlowType
{
get
{
if ( mbFlowType == false )
{
mFlowType = ((EFlowType)(Enum.Parse( typeof(EFlowType) , XmlSource.SelectSingleNode( kFlowType , Collada.NS ).Value , true )));
mbFlowType = true;
}
return mFlowType;
}
}
#endregion
#region TextValues
private bool mbTextValues = false;
private string [] mTextValues;
public string [] TextValues
{
get
{
if ( mbTextValues == false )
{
string innerText = XmlSource.InnerText;
string [] tokens = innerText.Split( kWhitespace );
int nonNullTokenCount = 0;
for ( int scanIndex = 0 ; scanIndex < tokens.Length ; scanIndex++ )
{
if ( tokens[scanIndex].Length > 0 )
{
nonNullTokenCount++;
}
}
mTextValues = new string[nonNullTokenCount];
int valueIndex = 0;
for( int tokenIndex = 0 ; (tokenIndex < tokens.Length)&&(valueIndex < mTextValues.Length) ; tokenIndex++ )
{
string token = tokens[tokenIndex];
if ( token.Length > 0 )
{
mTextValues[valueIndex++] = token;
}
}
mbTextValues = true;
}
return mTextValues;
}
}
#endregion
#region Floats
private bool mbFloats = false;
private float [] mFloats;
public float [] Floats
{
get
{
if ( mbFloats == false )
{
mFloats = new float[TextValues.Length];
for( int valueIndex = 0 ; valueIndex < mFloats.Length ; valueIndex++ )
{
mFloats[valueIndex] = float.Parse( mTextValues[valueIndex] );
}
mbFloats = true;
}
return mFloats;
}
}
#endregion
#region Ints
private bool mbInts = false;
private int [] mInts;
public int [] Ints
{
get
{
if ( mbInts == false )
{
mInts = new int[TextValues.Length];
for( int valueIndex = 0 ; valueIndex < mInts.Length ; valueIndex++ )
{
mInts[valueIndex] = int.Parse( mTextValues[valueIndex] );
}
mbInts = true;
}
return mInts;
}
}
#endregion
#region Bools
private bool mbBools = false;
private bool [] mBools;
public bool [] Bools
{
get
{
if ( mbBools == false )
{
mBools = new bool[TextValues.Length];
for( int valueIndex = 0 ; valueIndex < mBools.Length ; valueIndex++ )
{
mBools[valueIndex] = bool.Parse( mTextValues[valueIndex] );
}
mbBools = true;
}
return mBools;
}
}
#endregion
#region ColorValue
private bool mbColorValue = false;
private System.Drawing.Color mColorValue;
public System.Drawing.Color ColorValue
{
get
{
if ( mbColorValue == false )
{
switch( TextValues.Length )
{
case 1:
switch( ParamType )
{
case EParamType.STRING:
mColorValue = Color.FromName( TextValues[0] );
break;
default:
mColorValue = kInvalidColor;
break;
}
break;
case 3:
switch( ParamType )
{
case EParamType.FLOAT:
goto case EParamType.FLOAT3;
case EParamType.FLOAT3:
mColorValue = Color.FromArgb( ((int)(255*Floats[0])) , ((int)(255*Floats[1])) , ((int)(255*Floats[2])) );
break;
case EParamType.INT:
mColorValue = Color.FromArgb( Ints[0] , Ints[1] , Ints[2] );
break;
default:
mColorValue = kInvalidColor;
break;
}
break;
case 4:
switch( ParamType )
{
case EParamType.FLOAT:
goto case EParamType.FLOAT3;
case EParamType.FLOAT3:
mColorValue = Color.FromArgb( ((int)(255*Floats[3])) , ((int)(255*Floats[0])) , ((int)(255*Floats[1])) , ((int)(255*Floats[2])) );
break;
case EParamType.INT:
mColorValue = Color.FromArgb( Ints[3] , Ints[0] , Ints[1] , Ints[2] );
break;
default:
mColorValue = kInvalidColor;
break;
}
break;
default:
mColorValue = kInvalidColor;
break;
}
mbColorValue = true;
}
return mColorValue;
}
}
#endregion
#endregion
#region Constructors
public Param( XmlNode source ) : base( source )
{
}
#endregion
}
}
|