[squeak-dev] Will Newspeak be callable by external programs?

Eliot Miranda eliot.miranda at gmail.com
Mon Feb 16 22:31:18 UTC 2009


Koh,
    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.
               ...
[1]           aCADSMClass.StartDynamic();
               ...
and then explain each marker, e.g.

[1] call StartDynamic.  This is implemented by the Foo class ...

TIA

On Mon, Feb 16, 2009 at 1:28 PM, askoh <askoh at askoh.com> wrote:

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


More information about the Squeak-dev mailing list