269 lines
7.7 KiB
C#
269 lines
7.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using PluginCommon;
|
|
using System.Globalization;
|
|
using System.Security.Permissions;
|
|
using System.Threading;
|
|
|
|
namespace SceneParametersEditor
|
|
{
|
|
public partial class SceneParametersEditor : Form
|
|
{
|
|
private const int ITF_INVALID_OBJREF = 0;
|
|
|
|
private pluginWrapper m_plugin = null;
|
|
private readonly engineWrapper m_engine = null;
|
|
private string m_xmlText = null;
|
|
private bool m_connected = false;
|
|
private bool m_updateConnectionStatus = false;
|
|
private bool m_updateGrid = false;
|
|
|
|
// Messages
|
|
private const string strMsgProperties = "Properties";
|
|
private const string strMsgClear = "Clear";
|
|
private const string strMsgGetSessionInfo = "getSessionInfo";
|
|
private const string strPluginName = "SceneParametersEditor_Plugin";
|
|
private const string strPluginId = "PluginId";
|
|
private Thread threadTask = null;
|
|
private bool m_exitRequest = false;
|
|
readonly EngineSettings engineSettings = null;
|
|
|
|
public SceneParametersEditor(string[] args)
|
|
{
|
|
CommandLineArgs cmdArgs = new CommandLineArgs(args);
|
|
engineSettings = new EngineSettings(cmdArgs);
|
|
|
|
InitializeComponent();
|
|
|
|
if (engineSettings.isClientRectValid())
|
|
{
|
|
engineSettings.applyToForm(this);
|
|
}
|
|
|
|
engineSettings.applyCurrentDirectory();
|
|
|
|
|
|
m_engine = new engineWrapper("");
|
|
|
|
CultureInfo tmp_ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
|
|
tmp_ci.NumberFormat.NumberDecimalSeparator = ".";
|
|
System.Threading.Thread.CurrentThread.CurrentCulture = tmp_ci;
|
|
|
|
timerUpdate.Start();
|
|
|
|
xmlPropertyGrid.propertiesChanged += new TechnoControls.XMLPropertyGrid.PropertiesChangedHandler(GridPropertyChanged);
|
|
|
|
threadTask = new Thread(new ThreadStart(this.ThreadTask));
|
|
threadTask.IsBackground = true;
|
|
threadTask.Start();
|
|
}
|
|
|
|
private void updateConnectedStatus()
|
|
{
|
|
bool connected = m_connected;
|
|
|
|
if (connected)
|
|
{
|
|
blobWrapper blob = new blobWrapper();
|
|
connected = blob.sendToHost();
|
|
}
|
|
|
|
if (!connected)
|
|
{
|
|
if (m_connected)
|
|
{
|
|
m_engine.disconnect();
|
|
m_plugin = null;
|
|
|
|
}
|
|
|
|
connected = m_engine.connectToHost("127.0.0.1", 1001);
|
|
|
|
if (connected)
|
|
{
|
|
m_plugin = new pluginWrapper();
|
|
m_engine.addPlugin(strPluginName, m_plugin);
|
|
sendConnected();
|
|
sendGetSessionInfo();
|
|
}
|
|
}
|
|
|
|
if ( connected != m_connected )
|
|
{
|
|
lock(this)
|
|
{
|
|
m_connected = connected;
|
|
m_updateConnectionStatus = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void GridPropertyChanged(object sender, TechnoControls.XMLPropertyGrid.PropertiesChangedEventArgs args)
|
|
{
|
|
lock (this)
|
|
{
|
|
if (m_connected)
|
|
{
|
|
sendProperties(args.xmlText);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void timerUpdate_Tick(object sender, EventArgs e)
|
|
{
|
|
if ( m_updateConnectionStatus )
|
|
{
|
|
lock(this)
|
|
{
|
|
m_updateConnectionStatus = false;
|
|
|
|
if (m_connected)
|
|
{
|
|
Text = "Scene Parameters Editor [Connected]";
|
|
}
|
|
else
|
|
{
|
|
Text = "Scene Parameters Editor [Disconnected]";
|
|
xmlPropertyGrid.Clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if ( m_updateGrid )
|
|
{
|
|
lock (this)
|
|
{
|
|
m_updateGrid = false;
|
|
|
|
if (m_xmlText != null )
|
|
{
|
|
xmlPropertyGrid.ParseXML(m_xmlText);
|
|
m_xmlText = null;
|
|
}
|
|
else
|
|
{
|
|
xmlPropertyGrid.Clear();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ThreadTask()
|
|
{
|
|
CultureInfo tmp_ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
|
|
tmp_ci.NumberFormat.NumberDecimalSeparator = ".";
|
|
System.Threading.Thread.CurrentThread.CurrentCulture = tmp_ci;
|
|
|
|
while (!m_exitRequest)
|
|
{
|
|
updateConnectedStatus();
|
|
|
|
if ( m_connected )
|
|
{
|
|
m_engine.update();
|
|
blobWrapper blob = new blobWrapper();
|
|
while (m_plugin.dispatch(blob))
|
|
{
|
|
string szMessage = "";
|
|
|
|
blob.extract(ref szMessage);
|
|
|
|
if (szMessage == strMsgProperties)
|
|
{
|
|
receiveMsgProperties(blob);
|
|
}
|
|
else if (szMessage == strMsgClear)
|
|
{
|
|
receiveMsgClear();
|
|
}
|
|
else if ( szMessage == strMsgGetSessionInfo )
|
|
{
|
|
receiveMsgDataRoot(blob);
|
|
}
|
|
}
|
|
}
|
|
|
|
Thread.Sleep(100);
|
|
}
|
|
}
|
|
|
|
private void receiveMsgProperties(blobWrapper blob)
|
|
{
|
|
string szBaseObjectData = "";
|
|
|
|
blob.extractString8(ref szBaseObjectData);
|
|
|
|
lock (this)
|
|
{
|
|
m_xmlText = szBaseObjectData;
|
|
m_updateGrid = true;
|
|
}
|
|
}
|
|
|
|
private void receiveMsgClear()
|
|
{
|
|
lock (this)
|
|
{
|
|
m_xmlText = null;
|
|
m_updateGrid = true;
|
|
}
|
|
}
|
|
|
|
private void receiveMsgDataRoot(blobWrapper blob)
|
|
{
|
|
string szDataRoot = "";
|
|
blob.extractDataRoot(ref szDataRoot);
|
|
xmlPropertyGrid.setDataRoot(szDataRoot);
|
|
}
|
|
|
|
private void sendConnected()
|
|
{
|
|
blobWrapper blob = new blobWrapper();
|
|
blob.push(strPluginId);
|
|
blob.push(strPluginName);
|
|
blob.sendToHost();
|
|
}
|
|
|
|
private void sendGetSessionInfo()
|
|
{
|
|
blobWrapper blob = new blobWrapper();
|
|
blob.push(strPluginName);
|
|
blob.push(strMsgGetSessionInfo);
|
|
blob.sendToHost();
|
|
}
|
|
|
|
private void sendProperties( string data )
|
|
{
|
|
blobWrapper blob = new blobWrapper();
|
|
blob.push(strPluginName);
|
|
blob.push(strMsgProperties);
|
|
blob.push(data);
|
|
blob.sendToHost();
|
|
}
|
|
|
|
private void SceneParametersEditor_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
//leave the thread
|
|
if (threadTask!=null)
|
|
{
|
|
m_exitRequest = true;
|
|
threadTask.Join();
|
|
threadTask = null;
|
|
}
|
|
|
|
if (m_engine.isConnected())
|
|
{
|
|
m_engine.disconnect();
|
|
}
|
|
|
|
m_engine.destroy();
|
|
}
|
|
}
|
|
}
|