Koh,<div><br></div><div> can you repost putting some markers at the beginning of the lines that actually make the relevant calls to VisualWorks? That would make it much easier to understand. e.g.</div><div> ...</div>
<div>[1]<span class="Apple-style-span" style="border-collapse: collapse; "> aCADSMClass.StartDynamic();</span></div><div> ...</div><div><span class="Apple-style-span" style="border-collapse: collapse;">and then explain each marker, e.g.</span></div>
<div><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></div><div><span class="Apple-style-span" style="border-collapse: collapse;">[1] call StartDynamic. This is implemented by the Foo class ...</span></div>
<div><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></div><div>TIA<br><br><div class="gmail_quote">On Mon, Feb 16, 2009 at 1:28 PM, askoh <span dir="ltr"><<a href="mailto:askoh@askoh.com">askoh@askoh.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
The code below is how C# would call a VisualWorks Smalltalk COM server for<br>
motion simulation. I would like C# to call a Squeak motion simulator in a<br>
similar fashion. But any workable method would be good too.<br>
<br>
I look forward to all suggestions. Squeak can benefit from having the<br>
ability to make plugins.<br>
<div class="Ih2E3d"><br>
All the best,<br>
Aik-Siong Koh<br>
<br>
</div>using System;<br>
using System.Collections.Generic;<br>
using System.ComponentModel;<br>
using System.Data;<br>
using System.Drawing;<br>
using System.Text;<br>
using System.Windows.Forms;<br>
using CADSM;<br>
<br>
public partial class Form1 : Form<br>
{<br>
//Have Added reference to CADSM, under COM tab.<br>
//CADSM is actually a tlb, which is registered in the Registry<br>
//C# program now connects to VisualWorks Smalltalk COM server.<br>
CADSMClass aCADSMClass = new CADSMClass();<br>
<br>
public Form1()<br>
{<br>
InitializeComponent();<br>
<br>
}<br>
<br>
private void button1_Click(object sender, EventArgs e)<br>
{<br>
// Button Click will Trigger the Interaction between CADSM and<br>
C# Code<br>
//Initiate an Assy and assign name and gravity<br>
CSMAssembly aAssembly = (CSMAssembly)aCADSMClass.AddAssembly();<br>
aAssembly.Name = "Assembly1";<br>
double[] aAGravity = {0.0, -9.81, 0.0};<br>
aAssembly.Gravity = aAGravity;<br>
<br>
//Add GlobalOriginMarker to Assy and set marker co-ordinates<br>
//This is Global Origin Marker<br>
CSMMarker aGlobalOriginMarker =<br>
(CSMMarker)aAssembly.AddMarker();<br>
aGlobalOriginMarker.Name = "GlobalOriginMarker";<br>
double[] aGlobalOriginMarkerrFfF = { 0.0, 0.0, 0.0 };<br>
aGlobalOriginMarker.rFfF = aGlobalOriginMarkerrFfF;<br>
double[] aGlobalOriginMarkerEulerxyzFf = { 0.0, 0.0, 0.0 };<br>
aGlobalOriginMarker.EulerxyzFf = aGlobalOriginMarkerEulerxyzFf;<br>
<br>
<br>
//Initiate a Part and assign name, co-ordinates and Eulers<br>
Parameters<br>
CSMPart aPendulumBlock = (CSMPart)aAssembly.AddPart();<br>
aPendulumBlock.Name = "PendulumBlock";<br>
double[] aPendulumBlockrFfF = { 0.0, 0.0, 0.0 };<br>
aPendulumBlock.rFfF = aPendulumBlockrFfF;<br>
double[] aPendulumBlockEulerxyzFf = { 0.0, 0.0, 0.0 };<br>
aPendulumBlock.EulerxyzFf = aPendulumBlockEulerxyzFf;<br>
double[] aPendulumBlockvOfO = { 0.0, 0.0, 0.0 };<br>
aPendulumBlock.vOfO = aPendulumBlockvOfO;<br>
double[] aPendulumBlockOmeOfO = { 0.0, 0.0, 0.0 };<br>
aPendulumBlock.OmeOfO = aPendulumBlockOmeOfO;<br>
<br>
//Add MassMarker to PendulumBlock<br>
CSMMassMarker aPendulumBlockMassMarker =<br>
(CSMMassMarker)aPendulumBlock.AddMassMarker();<br>
aPendulumBlockMassMarker.Name = "MassMarker";<br>
double[] aPendulumBlockMassMarkerrFfF = { 0.5, 0.1, 0.0 };<br>
aPendulumBlockMassMarker.rFfF = aPendulumBlockMassMarkerrFfF;<br>
double[] aPendulumBlockMassMarkerEulerxyzFf = { 0.0, 0.0, 0.0 };<br>
aPendulumBlockMassMarker.EulerxyzFf =<br>
aPendulumBlockMassMarkerEulerxyzFf;<br>
aPendulumBlockMassMarker.Mass = 10.0;<br>
double[] aPendulumBlockMassMarkerPrincipalInertias = { 0.1, 0.2,<br>
0.3 };<br>
aPendulumBlockMassMarker.PrincipalInertias =<br>
aPendulumBlockMassMarkerPrincipalInertias;<br>
<br>
//Add JointMarker to PendulumBlock<br>
CSMMarker aPendulumBlockJointMarker =<br>
(CSMMarker)aPendulumBlock.AddMarker();<br>
aPendulumBlockJointMarker.Name = "JointMarker";<br>
double[] aPendulumBlockJointMarkerrFfF = { 0.1, 0.1, 0.0 };<br>
aPendulumBlockJointMarker.rFfF = aPendulumBlockJointMarkerrFfF;<br>
double[] aPendulumBlockJointMarkerEulerxyzFf = { 0.0, 0.0, 0.0<br>
};<br>
aPendulumBlockJointMarker.EulerxyzFf =<br>
aPendulumBlockJointMarkerEulerxyzFf;<br>
<br>
<br>
//Connect the part marker to the ground marker with a joint.<br>
CSMCylindricalJoint aCylindricalJoint =<br>
(CSMCylindricalJoint)aAssembly.AddCylindricalJoint();<br>
aCylindricalJoint.MarkerI = aGlobalOriginMarker.FullName();<br>
aCylindricalJoint.MarkerJ =<br>
aPendulumBlockJointMarker.FullName();<br>
<br>
//Add a Prescribed Rotational Motion to Joint<br>
CSMRotationalMotion aMotion1 =<br>
(CSMRotationalMotion)aCylindricalJoint.AddRotation();<br>
aMotion1.Rotation = "2.0*pi*time";<br>
<br>
//Setup Simulation parameters<br>
CSMSimulation aSimulation =<br>
(CSMSimulation)aAssembly.SimulationParameters();<br>
aSimulation.Tstart = 0.0;<br>
aSimulation.Tend = 1.0;<br>
aSimulation.Hout = 0.1;<br>
aSimulation.Hmin = 1.0e-9;<br>
aSimulation.Hmax = 1.0;<br>
aSimulation.ErrorTolerance = 1.0e-6;<br>
<br>
aCADSMClass.StartDynamic();<br>
<br>
//Now, CADSM will start its Dynamic Computations. We need to<br>
check the frame and loop through<br>
// the parts and get their Position details, frame by frame<br>
//Since we have only one part in this example (PendulumBlock),<br>
we just have to get<br>
// Positional Values, frame by frame.<br>
//Get Number of Frames from CADSM, this is the first data, we<br>
get from CADSM to C#<br>
int aNoOfFrames = aCADSMClass.NumberOfFrames();<br>
<br>
//Create an Array to store output data in C#.<br>
Array _AllFramesTransformArray = Array.CreateInstance(typeof(Array),<br>
aNoOfFrames);<br>
<br>
//Itereate through frames<br>
short iFrame = 1;<br>
while (iFrame <= aNoOfFrames)<br>
{<br>
if (aCADSMClass.CheckFrame(iFrame))<br>
{<br>
Array temp_frameArray = new double[28];<br>
CSMPart current_part = aPendulumBlock ;<br>
<br>
//This code gets<br>
Position-Velocity-Acceleration data from CADSM<br>
//This needs to be done to every<br>
part and every frame..<br>
temp_frameArray = (Array)current_part.Pos4by4VelAccData(iFrame);<br>
<br>
//Set the Array Value to corresponding index<br>
AllFramesTransformArray.SetValue(temp_frameArray,<br>
iFrame-1);<br>
iFrame++;<br>
}<br>
}<br>
//Makes a cadsm .asm file for Debug purpose, This will<br>
have all the markers and Motion/Forces etc..<br>
aAssembly.DebugASM();<br>
System.Windows.Forms.MessageBox.Show("DebugASM run");<br>
}<br>
}<br>
<font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/Will-Newspeak-be-callable-by-external-programs--tp21896396p22046302.html" target="_blank">http://www.nabble.com/Will-Newspeak-be-callable-by-external-programs--tp21896396p22046302.html</a><br>
</font><div><div></div><div class="Wj3C7c">Sent from the Squeak - Dev mailing list archive at Nabble.com.<br>
<br>
<br>
</div></div></blockquote></div><br></div>