2008-05-30

Stereogram in AX

Following job demonstrates random dot stereogram technique in AX.

static void RDStechniqueJob(Args _args)
{
        #define.image("C:\\Images\\pattern.bmp")

        #define.imageSizeX(300) // width*2
        #define.imageSizeY(300) // height

        #define.depth(5)

        Form            form;
        FormRun         formRun;
        FormDesign      formDesign;

        Args            args;
        FormBuildDesign formBuildDesign;

        FormBuildWindowControl formBuildWindowControl;
        FormWindowControl pane;

        Image image     = new Image();
        Image pattern   = new Image();
        int     _x, _y;


        void Draw()
        {
            Random  rnd = new Random();
            int     color;
            ;

            for(_x=0; _x<#imageSizeX/2; _x++)
            {
                for(_y=0; _y<#imageSizeY; _y++)
                {
                    color = rnd.nextInt()*0xFF;
                    image.setPixel(_x, _y, color);
                    image.setPixel(_x+#imageSizeX/2, _y, color);
                }
            }
        }

        void CreateStereogram()
        {
            int     color;
            int     d;
            ;

            pattern.loadImage(#image);

            for(_x=0; _x<#imageSizeX/2; _x++)
            {
                for(_y=0; _y<#imageSizeY; _y++)
                {
                    if(!(pattern.getPixel(_x, _y) mod 2))
                    {
                        color = image.getPixel(_x, _y);
                        image.setPixel(_x+#imageSizeX/2-#depth, _y, color);
                    }
                }
            }
        }
        ;

        form = new Form();
        formBuildDesign = form.addDesign('design');
        formBuildDesign.hideToolbar(true);

        formBuildDesign.columns(1);
        formBuildDesign.topMode(1); // Auto
        formBuildDesign.leftMode(1); // Auto
        formBuildDesign.widthMode(1); // Auto
        formBuildDesign.heightMode(1); // Auto
        formBuildDesign.width(1.1*#imageSizeX);

        formBuildWindowControl = formBuildDesign.addControl(FormControlType::IMAGE, 'pane');
        formBuildWindowControl.height(#imageSizeY);
        formBuildWindowControl.width(#imageSizeX);
        formBuildWindowControl.backgroundColor(0);

        args = new Args();
        args.object(form);
        formRun = classFactory.formRunClass(args);
        formRun.init();
        formRun.resetSize();
        formDesign = formRun.design();
        formRun.resetSize();
        formrun.formOnTop();
        formRun.run();


        formRun.design().caption('Random-dot stereogram');
        pane = formRun.control(formBuildWindowControl.id());

        image.saveType(ImageSaveType::BMP_UNCOMP);
        image.createImage(#imageSizeX, #imageSizeY, 24);

        Draw();

        CreateStereogram();
        pane.image(image);

        formRun.wait();
}

Notes:
in this job
- pattern.bmp should be monochrome.
- imageSizeX should be twice more than width of bitmap file.
- depth -- z-axis (depth).

Copyright © 2008 Ruslan Goncharov

2008-05-23

From Microsoft Dynamics AX Programming newsgroup tricks

TreeNode Alternative for FormControls

I want to create a Control on a Form just like I would with a TreeNode in AX 3.0. But the TreeNode.AOTAdd doesn't work for FOrmControls. Is there an Alternative how I can create a Control? These Fields should notbe temporary like in the Tutorial_Form_AddControl. They should be in the AOT after being created.

    TreeNode                formlist;
    Form                    formNode;

    FormBuildDesign         formDesign;

    ;

    formlist = infolog.findNode('Forms');
    formNode = formlist.AOTfindChild('Form1');

    formDesign = formNode.design();
    formDesign.addControl(FormControlType::String, 'StringEdit');
    formNode.save();
 

Saved form settings

When we import new objects, the user defined form settings are lost. It's possible to prevent that from happening?

static void JobSettingsStoringAndRestoring(Args _args)
{
    syslastvalue    sysLastValue;
    container       dataContainer;
    BinData         binData;

    container       blobContainer;
    ContainerClass  containerClass;
    str             settingsFileName = "c:\\settings.txt";
    ;

//  Store settings -->
    dataContainer = xSysLastValue::getValue(
        curExt(), curUserId(), UtilElementType::Usersetup, 'AddressCheck', 'myDesign');

    containerClass = new ContainerClass(dataContainer);
    blobContainer = containerClass.toBlob();

    binData = new BinData();
    binData.setData(blobContainer);

    binData.saveFile(settingsFileName);
//  Store settings <--

//  Restore settings -->
/*    binData = new BinData();
    binData.loadFile(settingsFileName);

    dataContainer = containerClass::blob2Container(binData.getData());
    xSysLastValue::putValue(dataContainer,
        curExt(), curUserId(), UtilElementType::Usersetup, 'AddressCheck', 'myDesign');*/
//  Restore settings <--
}
Copyright © 2008 Ruslan Goncharov