Param.cs :  » Game » RealmForge » ColladaNET » Import » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Game » RealmForge 
RealmForge » ColladaNET » Import » Param.cs
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
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.