#region Copyright
///////////////////////////////////////////////////////////
//
// Copyright (C) 2006 OpenMI Association
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// or look at URL www.gnu.org/licenses/lgpl.html
//
// Contact info:
// URL: www.openmi.org
// Email: sourcecode@openmi.org
// Discussion forum available at www.sourceforge.net
//
// Coordinator: Roger Moore, CEH Wallingford, Wallingford, Oxon, UK
//
///////////////////////////////////////////////////////////
//
// Original author: Stefan Westen, Wallingford Software
///////////////////////////////////////////////////////////
#endregion
using System;
using System.Collections;
using System.Threading;
using System.Windows.Forms;
using Oatc.OpenMI.Sdk.Backbone;
using Oatc.OpenMI.Sdk.DevelopmentSupport;
using OpenMI.Standard;
using TimeSpan=Oatc.OpenMI.Sdk.Backbone.TimeSpan;
namespace Oatc.OpenMI.Tools.DataMonitor
{
///
/// The DataMonitor class
///
public class DataMonitor:LinkableComponent, IListener
{
///
/// Prepare
///
public override void Prepare()
{
}
///
/// ComponentDescription
///
public override string ComponentDescription
{
get
{
return "Data Monitor";
}
}
///
/// ComponentID
///
public override string ComponentID
{
get
{
return "Data Monitor";
}
}
///
/// ModelID
///
public override string ModelID
{
get
{
return "Data Monitor";
}
}
///
/// ModelDescription
///
public override string ModelDescription
{
get
{
return "Data Monitor";
}
}
///
/// Initialize
///
/// properties
public override void Initialize(IArgument[] properties)
{
}
///
/// EarliestInputTime
///
/// ITimeStamp
public override ITimeStamp EarliestInputTime
{
get
{
return new TimeStamp(0.0);
}
}
///
/// TimeHorizon
///
/// ITimeSpan
public override ITimeSpan TimeHorizon
{
get
{
return new TimeSpan(new TimeStamp(0.0),new TimeStamp(1e6));
}
}
///
/// GetPublishedEventType
///
/// providedEventTypeIndex
/// EventType
public override EventType GetPublishedEventType(int providedEventTypeIndex)
{
return new EventType ();
}
///
/// GetPublishedEventTypeCount
///
/// int
public override int GetPublishedEventTypeCount()
{
return 0;
}
///
/// GetValues
///
/// time
/// LinkID
/// IValueSet
public override IValueSet GetValues(ITime time, string LinkID)
{
return null;
}
///
/// Validate
///
/// string
public override string Validate()
{
return "";
}
///
/// Finish
///
public override void Finish()
{
}
private DataMonitorForm _form;
private ManualResetEvent _formCreatedEvent;
private ArrayList _acceptedEventTypes = new ArrayList();
///
/// DataMonitor
///
public DataMonitor()
{
_acceptedEventTypes.Add(EventType.DataChanged);
// create thread with message-loop to handle the form
_formCreatedEvent = new ManualResetEvent( false );
Thread formThread = new Thread( new ThreadStart(RunFormMessageLoop) );
formThread.Start();
// wait until form window handle is surely created
_formCreatedEvent.WaitOne();
_formCreatedEvent.Close();
_formCreatedEvent = null;
}
private void RunFormMessageLoop()
{
_form = new DataMonitorForm( _formCreatedEvent );
Application.Run( _form );
}
///
/// AddLink
///
/// link
public override void AddLink (ILink link)
{
//subscribe to events
ILinkableComponent LC = link.SourceComponent;
for (int i=0;i
/// OnEvent
///
/// Event
public void OnEvent (IEvent Event)
{
ILink[] links = GetAcceptingLinks();
foreach (ILink link in links)
{
if (link.SourceComponent==Event.Sender)
{
IValueSet values = Event.Sender.GetValues(Event.SimulationTime,link.ID);
if (values is IScalarSet)
{
IScalarSet scalarSet = (IScalarSet)values;
string[] subitems = new string[4+scalarSet.Count];
subitems[0] = CalendarConverter.ModifiedJulian2Gregorian(Event.SimulationTime.ModifiedJulianDay).ToString();
subitems[1] = Event.Sender.ModelID;
subitems[2] = link.SourceQuantity.ID;
subitems[3] = link.SourceElementSet.ID;
for (int i=0;i
/// GetAcceptedEventType
///
/// acceptedEventTypeIndex
/// EventType
public EventType GetAcceptedEventType(int acceptedEventTypeIndex)
{
return (EventType) _acceptedEventTypes[acceptedEventTypeIndex];
}
///
/// GetAcceptedEventTypeCount
///
/// int
public int GetAcceptedEventTypeCount()
{
return _acceptedEventTypes.Count;
}
///
/// GetInputExchangeItem
///
/// inputExchangeItemIndex
/// IInputExchangeItem
public override IInputExchangeItem GetInputExchangeItem(int inputExchangeItemIndex)
{
Quantity quantity = new Quantity(new Unit("Unit",1.0,0.0,"Unit"),"Quantity","Quantity");
ElementSet elementSet = new ElementSet("1","1",ElementType.IDBased,
new SpatialReference());
InputExchangeItem exchangeItem = new InputExchangeItem();
exchangeItem.ElementSet = elementSet;
exchangeItem.Quantity = quantity;
return exchangeItem;
}
///
/// InputExchangeItemCount
///
/// int
public override int InputExchangeItemCount
{
get
{
return 1;
}
}
public override void Dispose()
{
base.Dispose ();
try
{
_form.Invoke( new MethodInvoker(_form.Dispose) );
}
catch
{
}
}
}
}