Koh,<div><br></div><div>&nbsp;&nbsp; &nbsp;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. &nbsp;e.g.</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...</div>
<div>[1]<span class="Apple-style-span" style="border-collapse: collapse; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aCADSMClass.StartDynamic();</span></div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ...</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. &nbsp;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">&lt;<a href="mailto:askoh@askoh.com">askoh@askoh.com</a>&gt;</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>
 &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Have Added &nbsp;reference to CADSM, under COM tab.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//CADSM is actually a tlb, which is registered in the Registry<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//C# program now connects to VisualWorks Smalltalk COM server.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CADSMClass aCADSMClass = new CADSMClass();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public Form1()<br>
 &nbsp; &nbsp; &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;InitializeComponent();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;private void button1_Click(object sender, EventArgs e)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Button Click will Trigger the Interaction between CADSM and<br>
C# Code<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Initiate an Assy and assign name and gravity<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CSMAssembly aAssembly = (CSMAssembly)aCADSMClass.AddAssembly();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aAssembly.Name = &quot;Assembly1&quot;;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aAGravity = {0.0, -9.81, 0.0};<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aAssembly.Gravity = aAGravity;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Add GlobalOriginMarker to Assy and set marker co-ordinates<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//This is Global Origin Marker<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CSMMarker aGlobalOriginMarker =<br>
(CSMMarker)aAssembly.AddMarker();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aGlobalOriginMarker.Name = &quot;GlobalOriginMarker&quot;;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aGlobalOriginMarkerrFfF = { 0.0, 0.0, 0.0 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aGlobalOriginMarker.rFfF = aGlobalOriginMarkerrFfF;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aGlobalOriginMarkerEulerxyzFf = { 0.0, 0.0, 0.0 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aGlobalOriginMarker.EulerxyzFf = aGlobalOriginMarkerEulerxyzFf;<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Initiate a Part and assign name, co-ordinates and Eulers<br>
Parameters<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CSMPart aPendulumBlock = (CSMPart)aAssembly.AddPart();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlock.Name = &quot;PendulumBlock&quot;;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aPendulumBlockrFfF = { 0.0, 0.0, 0.0 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlock.rFfF = aPendulumBlockrFfF;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aPendulumBlockEulerxyzFf = { 0.0, 0.0, 0.0 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlock.EulerxyzFf = aPendulumBlockEulerxyzFf;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aPendulumBlockvOfO = { 0.0, 0.0, 0.0 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlock.vOfO = aPendulumBlockvOfO;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aPendulumBlockOmeOfO = { 0.0, 0.0, 0.0 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlock.OmeOfO = aPendulumBlockOmeOfO;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Add MassMarker to PendulumBlock<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CSMMassMarker aPendulumBlockMassMarker =<br>
(CSMMassMarker)aPendulumBlock.AddMassMarker();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlockMassMarker.Name = &quot;MassMarker&quot;;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aPendulumBlockMassMarkerrFfF = { 0.5, 0.1, 0.0 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlockMassMarker.rFfF = aPendulumBlockMassMarkerrFfF;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aPendulumBlockMassMarkerEulerxyzFf = { 0.0, 0.0, 0.0 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlockMassMarker.EulerxyzFf =<br>
aPendulumBlockMassMarkerEulerxyzFf;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlockMassMarker.Mass = 10.0;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aPendulumBlockMassMarkerPrincipalInertias = { 0.1, 0.2,<br>
0.3 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlockMassMarker.PrincipalInertias =<br>
aPendulumBlockMassMarkerPrincipalInertias;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Add JointMarker to PendulumBlock<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CSMMarker aPendulumBlockJointMarker =<br>
(CSMMarker)aPendulumBlock.AddMarker();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlockJointMarker.Name = &quot;JointMarker&quot;;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aPendulumBlockJointMarkerrFfF = { 0.1, 0.1, 0.0 };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlockJointMarker.rFfF = aPendulumBlockJointMarkerrFfF;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double[] aPendulumBlockJointMarkerEulerxyzFf = { 0.0, 0.0, 0.0<br>
};<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aPendulumBlockJointMarker.EulerxyzFf =<br>
aPendulumBlockJointMarkerEulerxyzFf;<br>
<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Connect the part marker to the ground marker with a joint.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CSMCylindricalJoint aCylindricalJoint =<br>
(CSMCylindricalJoint)aAssembly.AddCylindricalJoint();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aCylindricalJoint.MarkerI = aGlobalOriginMarker.FullName();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aCylindricalJoint.MarkerJ =<br>
aPendulumBlockJointMarker.FullName();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Add a Prescribed Rotational Motion to Joint<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CSMRotationalMotion aMotion1 =<br>
(CSMRotationalMotion)aCylindricalJoint.AddRotation();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aMotion1.Rotation = &quot;2.0*pi*time&quot;;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Setup Simulation parameters<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CSMSimulation aSimulation =<br>
(CSMSimulation)aAssembly.SimulationParameters();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aSimulation.Tstart = 0.0;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aSimulation.Tend = 1.0;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aSimulation.Hout = 0.1;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aSimulation.Hmin = 1.0e-9;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aSimulation.Hmax = 1.0;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aSimulation.ErrorTolerance = 1.0e-6;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aCADSMClass.StartDynamic();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Now, CADSM will start its Dynamic Computations. We need to<br>
check the frame and loop through<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// the parts and get their Position details, frame by frame<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Since we have only one part in this example (PendulumBlock),<br>
we just have to get<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Positional Values, frame by frame.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Get Number of Frames from CADSM, this is the first data, we<br>
get from CADSM to C#<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int aNoOfFrames = aCADSMClass.NumberOfFrames();<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Create an Array to store output data in C#.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Array _AllFramesTransformArray = Array.CreateInstance(typeof(Array),<br>
aNoOfFrames);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Itereate through frames<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;short iFrame = 1;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (iFrame &lt;= aNoOfFrames)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (aCADSMClass.CheckFrame(iFrame))<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Array temp_frameArray = new double[28];<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CSMPart current_part = aPendulumBlock ;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//This code gets<br>
Position-Velocity-Acceleration data from CADSM<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//This needs to be done to every<br>
part and every frame..<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;temp_frameArray = (Array)current_part.Pos4by4VelAccData(iFrame);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Set the Array Value to corresponding index<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AllFramesTransformArray.SetValue(temp_frameArray,<br>
iFrame-1);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iFrame++;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Makes a cadsm .asm file for Debug purpose, This will<br>
have all the markers and Motion/Forces etc..<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aAssembly.DebugASM();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.Windows.Forms.MessageBox.Show(&quot;DebugASM run&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
 &nbsp; &nbsp;}<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>