/// /// This file is part of ILNumerics Community Edition. /// /// ILNumerics Community Edition - high performance computing for applications. /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net /// /// ILNumerics Community Edition is free software: you can redistribute it and/or modify /// it under the terms of the GNU General Public License version 3 as published by /// the Free Software Foundation. /// /// ILNumerics Community Edition 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 ILNumerics Community Edition. See the file License.txt in the root /// of your distribution package. If not, see . /// /// In addition this software uses the following components and/or licenses: /// /// ================================================================================= /// The Open Toolkit Library License /// /// Copyright (c) 2006 - 2009 the Open Toolkit library. /// /// Permission is hereby granted, free of charge, to any person obtaining a copy /// of this software and associated documentation files (the "Software"), to deal /// in the Software without restriction, including without limitation the rights to /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of /// the Software, and to permit persons to whom the Software is furnished to do /// so, subject to the following conditions: /// /// The above copyright notice and this permission notice shall be included in all /// copies or substantial portions of the Software. /// /// ================================================================================= /// using System; using System.Collections.Generic; using System.Collections; using System.Text; using ILNumerics.Drawing.Collections; using ILNumerics.Drawing.Shapes; using ILNumerics.Drawing; namespace ILNumerics.Drawing.Graphs { /// /// abstract base class for all scene graph nodes /// public abstract class ILSceneGraphNode : //ICollection, IEnumerable ,IEnumerable { #region attributes protected ILSceneGraphNode m_parent; protected ILPoint3Df m_center; protected ILPoint3Df m_positionMin; protected ILPoint3Df m_positionMax; protected bool m_invalidated; protected bool m_visible; protected ILPanel m_panel; // needed for camera position protected bool m_eventingSuspended; #endregion #region constructors internal ILSceneGraphNode(ILPanel panel) { m_panel = panel; m_invalidated = true; m_visible = true; } #endregion #region eventing /// /// fires when the size of the cube tigthly enclosing the shape has changed /// public event EventHandler SizeChanged; protected virtual void OnSizeChanged() { if (SizeChanged != null && !m_eventingSuspended) SizeChanged(this, new EventArgs()); } /// /// fires when the (size)cache of the node was invalidated /// public event EventHandler Invalidated; protected virtual void OnInvalidated() { if (Invalidated != null && !m_eventingSuspended) Invalidated(this, new EventArgs()); } protected virtual void OnNodeAdded(ILSceneGraphNode node) { if (m_parent != null && !m_eventingSuspended) { m_parent.OnNodeAdded(node); } } protected virtual void OnNodeRemoved(ILSceneGraphNode node) { if (m_parent != null && !m_eventingSuspended) { m_parent.OnNodeRemoved(node); } } /// /// stop firing events from this node /// public void EventingSuspend() { m_eventingSuspended = true; } /// /// resume firing events from this node /// public void EventingResume() { m_eventingSuspended = false; } #endregion #region properties /// /// Get/set visiblility for the scene graph branch /// public bool Visible { get { return m_visible; } set { m_visible = value; } } /// /// reference to the scene graph node this node is a child of /// public ILSceneGraphNode Parent { get { return m_parent; } set { m_parent = value; } } /// /// the minimum coordinate of a cube tightly enclosing the node (and all childs) /// /// public virtual ILPoint3Df PositionMin { get { if (m_positionMin.IsEmtpy()) { ComputeNodeLimits(); } return m_positionMin; } } /// /// the maximum coordinate of a cube tightly enclosing the node (and all childs) /// /// public virtual ILPoint3Df PositionMax { get { if (m_positionMax.IsEmtpy()) { ComputeNodeLimits(); } return m_positionMax; } } /// /// current geometric center according of scene graph branch /// public virtual ILPoint3Df Center { get { if (m_center.IsEmtpy()) { ComputeNodeLimits(); } return m_center; } } #endregion #region public interface /// /// invalidate geometry cache for this and all nodes up to root /// public virtual void Invalidate() { m_center = ILPoint3Df.Empty; m_positionMin = ILPoint3Df.Empty; m_positionMax = ILPoint3Df.Empty; m_invalidated = true; if (Parent != null) { Parent.Invalidate(); } else { OnInvalidated(); } } /// /// recompute the size spanned by this node, may fires Changed() event /// internal abstract void Configure(); /// /// draw all children contained in this node /// /// extended rendering properties internal abstract void Draw(ILRenderProperties props); #endregion #region private helper /// /// compute limits of the cube tightly enclosing the branch below this node /// /// protected abstract void ComputeNodeLimits(); //protected void invalidateChilds(ILSceneGraphNode parent) { // parent.m_center = ILPoint3Df.Empty; // parent.m_positionMin = ILPoint3Df.Empty; // parent.m_positionMax = ILPoint3Df.Empty; // foreach (ILSceneGraphNode child in parent.m_childs) { // child.invalidateChilds(child); // } //} #endregion #region IEnumerable Member /// /// Create & returns a typed enumerator /// /// enumerator of all scene graph nodes below this node public IEnumerator GetEnumerator() { List ret = new List(); CollectAllChildren(ret); return ret.GetEnumerator(); } #endregion #region IEnumerable Member /// /// Create and return untyped enumerator /// /// IEnumerator of all scene graph nodes below this node System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { List children = new List(); CollectAllChildren(children); foreach (ILSceneGraphNode node in children) { yield return node; } } internal virtual void CollectAllChildren(List nodes) { nodes.Add(this); } #endregion } }