Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

User-driven applications

, 10 Apr 2010
User-driven applications are the programs in which full control is given to the users. Designers of such programs are responsible only for developing an instrument for solving some task, but they do not enforce users to work with this instrument according with a predefined scenario.
TheoryOfUserDrivenApplications.zip
TheoryOfUserDrivenApplications
TheoryOfUserDrivenApplications
bin
Debug
TheoryOfUserDrivenApplications.vshost.exe
Release
MoveGraphLibrary.dll
TheoryOfUserDrivenApplications.bin
TheoryOfUserDrivenApplications.exe
TheoryOfUserDrivenApplications.vshost.exe
Properties
Settings.settings
Resources
ArrowDown.bmp
ArrowUp.bmp
DELETE.BMP
Hangar.bmp
Lock.bmp
palette_.bmp
RuralHouse.bmp
RuralLeftPlus.bmp
RuralRightPlus.bmp
SimpleHouse.bmp
User_driven_applications.doc
User_driven_applications.pdf
using System;
using System .Collections .Generic;
using System .IO;
using System .Windows .Forms;

using MoveGraphLibrary;

namespace UserDrivenApplications
{
    public class Data_ABArray
    {
        string name;
        bool bShowToUser;
        double A_min, A_max, B_min, B_max;
        bool bUseRange_A, bUseRange_B;
        List<Data_ABPair> pairs = new List<Data_ABPair> ();
        string comment = "";
        MSPlot plot;

        // -------------------------------------------------
        public Data_ABArray (string strName, bool bShow,
                             bool bUseArange, double minA, double maxA,
                             bool bUseBrange, double minB, double maxB,
                             Data_ABPair [] ab_values, string cmnt, MSPlot plotSrc)
        {
            name = strName;
            bShowToUser = bShow;
            bUseRange_A = bUseArange;
            if (bUseRange_A)
            {
                A_min = Math .Min (minA, maxA);
                A_max = Math .Max (minA, maxA);
            }
            bUseRange_B = bUseBrange;
            if (bUseRange_B)
            {
                B_min = Math .Min (minB, maxB);
                B_max = Math .Max (minB, maxB);
            }
            for (int i = 0; i < ab_values .Length; i++)
            {
                pairs .Add (ab_values [i]);
            }
            if (!string .IsNullOrEmpty (cmnt))
            {
                comment = cmnt;
            }
            plot = plotSrc;
        }
        // -------------------------------------------------
        public Data_ABArray (string strName, bool bShow,
                             bool bUseArange, double minA, double maxA,
                             bool bUseBrange, double minB, double maxB,
                             List<Data_ABPair> ab_values, string cmnt, MSPlot plotSrc)
        {
            name = strName;
            bShowToUser = bShow;
            bUseRange_A = bUseArange;
            if (bUseRange_A)
            {
                A_min = Math .Min (minA, maxA);
                A_max = Math .Max (minA, maxA);
            }
            bUseRange_B = bUseBrange;
            if (bUseRange_B)
            {
                B_min = Math .Min (minB, maxB);
                B_max = Math .Max (minB, maxB);
            }
            pairs = ab_values;
            if (!string .IsNullOrEmpty (cmnt))
            {
                comment = cmnt;
            }
            plot = plotSrc;
        }
        // -------------------------------------------------
        public Data_ABArray (string strName, bool bShow, MSPlot plotSrc)
        {
            name = strName;
            bShowToUser = bShow;
            bUseRange_A = false;
            bUseRange_B = false;
            plot = plotSrc;
        }
        // -------------------------------------------------        Name
        public string Name
        {
            get { return (name); }
            set
            {
                if (!string .IsNullOrEmpty (value))
                {
                    name = value;
                }
            }
        }
        // -------------------------------------------------        ShowToUser
        public bool ShowToUser
        {
            get { return (bShowToUser); }
            set { bShowToUser = value; }
        }
        // -------------------------------------------------        HasData
        public bool HasData
        {
            get { return (pairs .Count > 0); }
        }
        // -------------------------------------------------        UseRange_A
        public bool UseRange_A
        {
            get { return (bUseRange_A); }
        }
        // -------------------------------------------------        A_minimum
        public double A_minimum
        {
            get { return (A_min); }
        }
        // -------------------------------------------------        A_maximum
        public double A_maximum
        {
            get { return (A_max); }
        }
        // -------------------------------------------------        SetRange_A
        public void SetRange_A (double minA, double maxA)
        {
            bUseRange_A = true;
            minA = A_min;
            maxA = A_max;
        }
        // -------------------------------------------------        UseRange_B
        public bool UseRange_B
        {
            get { return (bUseRange_B); }
        }
        // -------------------------------------------------        B_minimum
        public double B_minimum
        {
            get { return (B_min); }
        }
        // -------------------------------------------------        B_maximum
        public double B_maximum
        {
            get { return (B_max); }
        }
        // -------------------------------------------------        SetRange_B
        public void SetRange_B (double minB, double maxB)
        {
            bUseRange_B = true;
            minB = B_min;
            maxB = B_max;
        }
        // -------------------------------------------------        Pairs
        // there is no checking by the ranges !!!
        //
        public List<Data_ABPair> Pairs
        {
            get { return (pairs); }
            set { pairs = value; }
        }
        // -------------------------------------------------        Comment
        public string Comment
        {
            get { return (comment); }
            set
            {
                if (value != null)
                {
                    comment = value;
                }
            }
        }
        // -------------------------------------------------        MSPlot
        public MSPlot MSPlot
        {
            get { return (plot); }
            set { plot = value; }
        }
        // -------------------------------------------------        IntoFile
        public void IntoFile (BinaryWriter bw)
        {
            try
            {
                if (HasData)
                {
                    bw .Write (name);                   // 0
                    bw .Write (bShowToUser);            // 1
                    bw .Write (bUseRange_A);    // 2
                    bw .Write (bUseRange_B);    // 3
                    bw .Write (A_min);          // 4
                    bw .Write (A_max);          // 5
                    bw .Write (B_min);          // 6
                    bw .Write (B_max);          // 7
                    bw .Write (pairs .Count);           // 8
                    for (int i = 0; i < pairs .Count; i++)
                    {
                        bw .Write (pairs [i] .A_value);
                        bw .Write (pairs [i] .B_value);
                    }
                    bw .Write (comment);        // 9
                    bw .Write (plot != null);    // 10
                    if (plot != null)
                    {
                        plot .IntoFile (bw);
                    }
                }
            }
            catch
            {
            }
            finally
            {
            }
        }
        // -------------------------------------------------        FromFile
        public static void FromFile (Form form, BinaryReader br, out Data_ABArray data)
        {
            try
            {
                Data_ABArray arNew;
                string str = br .ReadString ();     // 0
                bool bShow = br .ReadBoolean ();    // 1
                bool bA = br .ReadBoolean ();       // 2
                bool bB = br .ReadBoolean ();       // 3
                double minA = br .ReadDouble ();    // 4
                double maxA = br .ReadDouble ();    // 5
                double minB = br .ReadDouble ();    // 6
                double maxB = br .ReadDouble ();    // 7
                int nPairs = br .ReadInt32 ();      // 8
                Data_ABPair [] ab_values = new Data_ABPair [nPairs];
                for (int i = 0; i < nPairs; i++)
                {
                    ab_values [i] = new Data_ABPair (br .ReadDouble (), br .ReadDouble ());
                }
                string cmnt = br .ReadString ();
                arNew = new Data_ABArray (str, bShow, bA, minA, maxA, bB, minB, maxB, ab_values, cmnt, null);
                bool bPlotToRead = br .ReadBoolean ();  // 10
                if (bPlotToRead)
                {
                    MSPlot plotRead = MSPlot .FromFile (form, br);
                    if (plotRead != null && arNew != null)
                    {
                        arNew .MSPlot = plotRead;
                    }
                }
                data = arNew;
            }
            catch
            {
                data = null;
                string strText = "Can't read Data_ABArray";
                MessageBox .Show (strText, "Problem on Reading", MessageBoxButtons .OK, MessageBoxIcon .Exclamation);
            }
            finally
            {

            }
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

SergeyAndreyev

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 10 Apr 2010
Article Copyright 2010 by SergeyAndreyev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid