Exemplo n.º 1
0
        public void FloatTimeEditorChanged(object source, EventArgs e)
        {
            ApplianceState state = (ApplianceState)_objects[SINGLE_STATE];

            double correctFactor = 1000;

            if (state.Type.ValueSpace is FixedPtSpace)
            {
                correctFactor = Math.Pow(10, ((FixedPtSpace)state.Type.ValueSpace).GetPointPosition());
            }

            int[] time = ((TimeEditor)_timeControl).GetTime();

            int inttime = time[(int)TimeUnits.Hours];

            inttime = (inttime * 60) + time[(int)TimeUnits.Minutes];
            inttime = (inttime * 60) + time[(int)TimeUnits.Seconds];

            double dbltime = (double)inttime + ((double)time[(int)TimeUnits.Fraction]) / correctFactor;

            if (state != null)
            {
                state.RequestChange(inttime);
            }
        }
Exemplo n.º 2
0
        // TimeEditor Variants

        public void SetEditorFromMultiple()
        {
            ApplianceState state = (ApplianceState)_objects[HOURS_LABEL];

            if (state != null && state.Defined)
            {
                ((TimeEditor)_timeControl).SetTimeUnit(TimeUnits.Hours, (int)state.Value);
            }

            state = (ApplianceState)_objects[MINUTES_LABEL];
            if (state != null && state.Defined)
            {
                ((TimeEditor)_timeControl).SetTimeUnit(TimeUnits.Minutes, (int)state.Value);
            }

            state = (ApplianceState)_objects[SECONDS_LABEL];
            if (state != null && state.Defined)
            {
                ((TimeEditor)_timeControl).SetTimeUnit(TimeUnits.Seconds, (int)state.Value);
            }

            state = (ApplianceState)_objects[FRACTION_LABEL];
            if (state != null && state.Defined)
            {
                ((TimeEditor)_timeControl).SetTimeUnit(TimeUnits.Fraction, (int)state.Value);
            }
        }
Exemplo n.º 3
0
        /*
         * Control Change Callbacks
         */

        public void MultipleTimeEditorChanged(object source, EventArgs e)
        {
            int[] time = ((TimeEditor)_timeControl).GetTime();

            ApplianceState state = (ApplianceState)_objects[HOURS_LABEL];

            if (state != null &&
                (!state.Defined || time[(int)TimeUnits.Hours] != (int)state.Value))
            {
                state.RequestChange(time[(int)TimeUnits.Hours]);
            }

            state = (ApplianceState)_objects[MINUTES_LABEL];
            if (state != null &&
                (!state.Defined || time[(int)TimeUnits.Minutes] != (int)state.Value))
            {
                state.RequestChange(time[(int)TimeUnits.Minutes]);
            }

            state = (ApplianceState)_objects[SECONDS_LABEL];
            if (state != null &&
                (!state.Defined || time[(int)TimeUnits.Seconds] != (int)state.Value))
            {
                state.RequestChange(time[(int)TimeUnits.Seconds]);
            }

            state = (ApplianceState)_objects[FRACTION_LABEL];
            if (state != null &&
                (!state.Defined || time[(int)TimeUnits.Fraction] != (int)state.Value))
            {
                state.RequestChange(time[(int)TimeUnits.Fraction]);
            }
        }
Exemplo n.º 4
0
        public void SetSliderFromFloat()
        {
            ApplianceState state = (ApplianceState)_objects[SINGLE_STATE];

            PUC.Types.FloatingPtSpace space = (PUC.Types.FloatingPtSpace)state.Type.ValueSpace;

            if (state.Defined)
            {
                string val = state.Value.ToString();

                if (_sentValues[val] != null &&
                    ((int)_sentValues[val]) > 0)
                {
                    int cnt = (int)_sentValues[val];
                    _sentValues[val] = --cnt;
                    return;
                }

                ((TimeSlider)_timeControl).Time    = (double)state.Value;
                ((TimeSlider)_timeControl).Maximum = space.GetMaximum().GetDoubleValue();
            }
            else
            {
                ((TimeSlider)_timeControl).Time    = 0;
                ((TimeSlider)_timeControl).Maximum = 0;
            }
        }
Exemplo n.º 5
0
        public string GetStringFromInt()
        {
            ApplianceState state = (ApplianceState)_objects[SINGLE_STATE];

            if (state == null || !state.Defined)
            {
                return(null);
            }

            int time = (int)state.Value;

            string sep = ":";
            string ret = "";

            int secs = time % 60;

            time /= 60;

            int mins = time % 60;

            time /= 60;

            int hours = time;

            if (hours > 0)
            {
                ret += hours.ToString() + sep;
            }

            if (mins > 0)
            {
                if (mins == 0)
                {
                    ret += "00" + sep;
                }
                else if (mins < 10)
                {
                    ret += "0" + mins.ToString() + sep;
                }
                else
                {
                    ret += mins.ToString() + sep;
                }
            }

            if (secs == 0)
            {
                ret += "00";
            }
            else if (secs < 10)
            {
                ret += "0" + secs.ToString();
            }
            else
            {
                ret += secs.ToString();
            }

            return(ret);
        }
Exemplo n.º 6
0
 protected void StateValueChanged(ApplianceState state)
 {
     if (ConstraintUpdate != null)
     {
         ConstraintUpdate(this, new EventArgs());
     }
 }
Exemplo n.º 7
0
        protected ArrayList getDepsOfStateHelper(ApplianceState state,
                                                 Dependency d)
        {
            if (d == null)
            {
                return(new ArrayList());
            }

            if (!(d is Formula))
            {
                ArrayList results = new ArrayList();

                if (d is StateDependency && ((StateDependency)d).State == state)
                {
                    results.Add(d);
                }

                return(results);
            }
            else
            {
                Formula   df      = (Formula)d;
                ArrayList results = new ArrayList();

                if (df is OR)
                {
                    IEnumerator e = df.GetDependencies();

                    while (e.MoveNext())
                    {
                        ArrayList childResult = getDepsOfStateHelper(state, (Dependency)e.Current);

                        if (childResult.Count > 0)
                        {
                            results.AddRange(childResult);
                        }
                        else
                        {
                            results.Clear();
                            return(results);
                        }
                    }
                }
                else if (df is AND)
                {
                    IEnumerator e = df.GetDependencies();

                    while (e.MoveNext())
                    {
                        results.AddRange(getDepsOfStateHelper(state, (Dependency)e.Current));
                    }
                }
                else if (df is ApplyOver)
                {
                    // TODO: do anything here?
                }

                return(results);
            }
        }
Exemplo n.º 8
0
        protected ArrayList collectDependency(GroupNode g,
                                              ApplianceState state)
        {
            if (g.IsObject())
            {
                ApplianceObject obj = ((ObjectGroupNode)g).Object;

                if (obj == state)
                {
                    return(new ArrayList());
                }

                return(getDependenciesOfState(state, obj));
            }
            else
            {
                ArrayList results = new ArrayList();

                IEnumerator e = ((BranchGroupNode)g).Children.GetEnumerator();
                while (e.MoveNext())
                {
                    results.AddRange(collectDependency((GroupNode)e.Current, state));
                }

                return(results);
            }
        }
Exemplo n.º 9
0
        protected void refreshStateData(ApplianceState state, Hashtable data, int start, int length, bool firstItem)
        {
            // first get the state name - the list name (+1 is for separator character)
            string noListName = state.FullName.Substring(_listGroup.FullPath.Length + 1);

            string[] names = noListName.Split(VariableTable.NAME_SEPARATORS);

            ArrayList list = (ArrayList)data[names[0]];

            for (int i = 0; i < length; i++)
            {
                object current = list[start + i];
                for (int j = 1; j < names.Length; j++)
                {
                    current = ((Hashtable)current)[names[j]];
                }

                ListViewItem lvi = _listView.Items[start + i];
                if (firstItem)
                {
                    lvi.Text = current.ToString();
                }
                else
                {
                    ListViewItem.ListViewSubItem lvsi = new System.Windows.Forms.ListViewItem.ListViewSubItem();
                    lvsi.Text = current.ToString();
                    lvi.SubItems.Add(lvsi);
                }
            }
        }
Exemplo n.º 10
0
        public void ValueChanged(ApplianceState state)
        {
            if (!state.Defined)
            {
                return;
            }

            object objval = state.Value;

            string val;

            if (objval != null)
            {
                val = state.Value.ToString();
            }
            else
            {
                val = "";
            }

            if (_sentValues[val] != null &&
                ((int)_sentValues[val]) > 0)
            {
                int cnt = (int)_sentValues[val];
                _sentValues[val] = --cnt;
            }
            else
            {
                refreshDisplay();
            }
        }
Exemplo n.º 11
0
        /*
         * Member Methods
         */
        public override PUC.CIO.ConcreteInteractionObject ChooseWidget(
            ApplianceObject ao)
        {
            ApplianceState state = (ApplianceState)ao;
            Decision       d     = null;

            switch (state.Type.ValueSpace.Space)
            {
            case PUC.Types.ValueSpace.BOOLEAN_SPACE:
                if (state.Type.ValueLabels != null &&
                    state.Type.ValueLabels.Count == 2)
                {
                    d = (Decision)_choices[TRUE];
                }
                else
                {
                    d = (Decision)_choices[FALSE];
                }
                break;

            default:
                d = (Decision)_choices[FALSE];
                break;
            }

            if (d != null)
            {
                return(d.ChooseWidget(ao));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 12
0
 protected void ChangeNotify(ApplianceState state)
 {
     if (ConstraintUpdate != null)
     {
         ConstraintUpdate(this, new EventArgs());
     }
 }
Exemplo n.º 13
0
        private void UndefineDlg_Load(object sender, System.EventArgs e)
        {
            int currentY = 8;

            _boxes = new ArrayList();

            Appliance   a  = _frame.GetAppliance();
            IEnumerator en = a.VariableTable.GetObjectEnumerator();

            while (en.MoveNext())
            {
                if (((ApplianceObject)en.Current).State)
                {
                    ApplianceState state = (ApplianceState)en.Current;
                    CheckBox       chbx  = new CheckBox();
                    chbx.Location = new System.Drawing.Point(8, currentY);
                    chbx.Size     = new System.Drawing.Size(208, 24);
                    chbx.Checked  = false;
                    chbx.Text     = state.FullName;

                    _boxes.Add(chbx);
                    boxPanel.Controls.Add(chbx);

                    currentY += 32;
                }
            }
        }
Exemplo n.º 14
0
 protected void valueChanged(ApplianceState o)
 {
     if (Changed != null)
     {
         Changed(this, new EventArgs());
     }
 }
Exemplo n.º 15
0
        /*
         * Member Methods
         */

        protected void refreshDisplay()
        {
            ApplianceState state = (ApplianceState)GetApplObj();
            string         lbl;

            try
            {
                lbl = GetApplObj().Labels.GetLabelByPixelLength(GetControl().Font, GetControl().Size.Width - MINIMUM_LEFT_PAD - MINIMUM_RIGHT_PAD);
            }
            catch (Exception)
            {
#if DEBUGSVR
                if (GetApplObj().Labels == null)
                {
                    lbl = GetApplObj().Name;
                }
                else
#endif
                lbl = GetApplObj().Labels.GetShortestLabel();
            }

            GetControl().Text = lbl;

            if (state.Defined)
            {
                ((CheckBox)GetControl()).Checked = (bool)state.Value;
            }
            else
            {
                ((CheckBox)GetControl()).Checked = false;
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Register any constraints in this type with the appropriate
 /// state variable.
 /// </summary>
 /// <param name="state"></param>
 public override void RegisterConstraints(ApplianceState state)
 {
     if (_list.Maximum != null && _list.Maximum is IConstraint)
     {
         new TypeConstraintListener(state, (IConstraint)_list.Maximum);
     }
 }
Exemplo n.º 17
0
        private void saveItem_Click(object sender, System.EventArgs evtargs)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Globals.GetFrame(_appliance).AddLogLine("Saving state in " + dlg.FileName + "...");

                try
                {
                    DataStore saveFile = new DataStore(dlg.FileName);

                    IEnumerator e = _appliance.VariableTable.GetObjectEnumerator();
                    while (e.MoveNext())
                    {
                        if (((ApplianceObject)e.Current).State)
                        {
                            ApplianceState state = (ApplianceState)e.Current;
                            if (state.Defined)
                            {
                                saveFile.Set(state.FullName, state.Value.ToString());
                            }
                        }
                    }

                    saveFile.Close();
                }
                catch (Exception)
                {
                    Globals.GetFrame(_appliance).AddLogLine("File not found.");
                }
            }
        }
Exemplo n.º 18
0
 public NumberConstraint(ApplianceState valueState)
     : base(valueState)
 {
     if (!(State.Type.ValueSpace is NumberSpace))
     {
         setInvalid();
     }
 }
Exemplo n.º 19
0
 public StringConstraint(ApplianceState valueState)
     : base(valueState)
 {
     if (_valid && !(State.Type.ValueSpace is StringSpace))
     {
         setInvalid();
     }
 }
Exemplo n.º 20
0
        public OverlappingOrgDecision(Decision baseDecision, ApplianceState state)
            : base(baseDecision)
        {
            _state   = state;
            _uiValid = false;

            _state.ValueChangedEvent += new ApplianceState.ValueChangedHandler(this.ValueChanged);
        }
Exemplo n.º 21
0
        /*
         * Constructor
         */

        public StateListViewItemCIO(ApplianceState state)
        {
            _state = state;

            _state.EnableChangedEvent += new PUC.ApplianceObject.EnableChangedHandler(this.enableChanged);
            _state.LabelChangedEvent  += new PUC.ApplianceObject.LabelChangedHandler(this.labelChanged);
            _state.ValueChangedEvent  += new PUC.ApplianceState.ValueChangedHandler(this.valueChanged);
        }
Exemplo n.º 22
0
        /*
         * Constructor
         */

        public ControlOrganizer(ApplianceState state)
        {
            _state = state;

            _uiValid = false;

            _state.ValueChangedEvent += new ApplianceState.ValueChangedHandler(this.ValueChanged);
        }
Exemplo n.º 23
0
        /*
         * Constructor
         */

        public ValueConstraint(ApplianceState state)
        {
            _state     = new ValueDataWindow(state);
            _stateName = state.Name;

            State.ValueChangedEvent += new PUC.ApplianceState.ValueChangedHandler(this.StateValueChanged);

            _valid = true;
        }
Exemplo n.º 24
0
        /*
         * Event Handler
         */

        public void ValueChanged(ApplianceState state)
        {
            IEnumerator e = _depObjs.GetEnumerator();

            while (e.MoveNext())
            {
                ApplianceObject obj = (ApplianceObject)e.Current;
                obj.EvalDependencies();
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Creates an EnableConstraint object with a dependency formula.
        /// Also automatically creates a listener for the constrained state.
        /// </summary>
        /// <param name="constrainedState">a reference to the state that will be constrained</param>
        /// <param name="formula">a dependency formula specifying the constraints</param>
        public EnableConstraint(ApplianceState constrainedState,
                                Dependency formula)
        {
            _valid   = false;
            _states  = new ArrayList();
            _formula = formula;

            // create listener
            new TypeConstraintListener(constrainedState, this);
        }
Exemplo n.º 26
0
        public string GetStringFromString()
        {
            ApplianceState state = (ApplianceState)_objects[SINGLE_STATE];

            if (state == null || !state.Defined)
            {
                return(null);
            }

            return((string)state.Value);
        }
Exemplo n.º 27
0
 private void _state_ValueChangedEvent(ApplianceState s)
 {
     if (s.Type.ValueSpace.CompareValues(s.Value, _value) == 0)
     {
         _button.PushDown();
     }
     else
     {
         _button.PushUp();
     }
 }
Exemplo n.º 28
0
        /*
         * Member Variables
         */

        /*
         * Constructor
         */

        public LabelLinkedCIO(ApplianceObject ao)
            : base(ao, new Label())
        {
            ApplianceState state = (ApplianceState)ao;

            state.EnableChangedEvent += new ApplianceObject.EnableChangedHandler(this.EnableChanged);
            state.LabelChangedEvent  += new ApplianceObject.LabelChangedHandler(this.LabelChanged);
            state.TypeChangedEvent   += new ApplianceState.TypeChangedHandler(this.TypeChanged);
            state.ValueChangedEvent  += new ApplianceState.ValueChangedHandler(this.ValueChanged);

            refreshDisplay();
        }
Exemplo n.º 29
0
        /*
         * Constructor
         */
        public TabbedLinkedCIO(ApplianceObject ao)
            : base(ao, new System.Windows.Forms.Panel())
        {
            ApplianceState state = (ApplianceState)GetApplObj();
            Panel          panel = (Panel)GetControl();

            _tabControl = new TabControl();
            panel.Controls.Add(_tabControl);

            _tabControl.Location = new System.Drawing.Point(0, 0);
            _tabControl.Size     = panel.ClientSize;

            panel.Resize += new EventHandler(this.Resized);

            _panelCIOs = new ArrayList();

            object          stateval = state.Value;
            EnumeratedSpace espc     = (EnumeratedSpace)state.Type.ValueSpace;
            Hashtable       labels   = state.Type.ValueLabels;

            int labelWidth = _tabControl.ClientSize.Width / espc.GetItemCount();

            for (int i = 1; i <= espc.GetItemCount(); i++)
            {
                object          labelSpace = i;
                LabelDictionary ldict      = (LabelDictionary)labels[labelSpace];

                TabbedPanelCIO pageCIO = new TabbedPanelCIO(ldict);

                TabPage page = pageCIO.TabPage;
                page.Enabled = ldict.Enabled;

                _tabControl.Controls.Add(page);
                _panelCIOs.Add(pageCIO);

                pageCIO.ChooseLabel(labelWidth - 2 * MINIMUM_TAB_PAD);

                if (state.Defined && i == (int)stateval)
                {
                    _tabControl.SelectedIndex = i - 1;
                }
            }

            state.LabelChangedEvent  += new ApplianceObject.LabelChangedHandler(this.LabelChanged);
            state.EnableChangedEvent += new ApplianceObject.EnableChangedHandler(this.EnableChanged);
            state.TypeChangedEvent   += new ApplianceState.TypeChangedHandler(this.TypeChanged);
            state.ValueChangedEvent  += new ApplianceState.ValueChangedHandler(this.ValueChanged);

            _tabControl.SelectedIndexChanged += new EventHandler(this.SelectedIndexChanged);

            refreshDisplay();
        }
Exemplo n.º 30
0
        /*
         * Constructors
         */

        public ImageSmartCIO(GroupNode specSnippet)
            : base(new Panel(), specSnippet)
        {
            if (specSnippet.IsObject())
            {
                _imageState = (ApplianceState)_objects[SINGLE_STATE];
            }
            else
            {
                _imageState = (ApplianceState)_objects[IMAGE_STATE_NAME];

                // look for labels in state if none were found in group
                if (_labels == null)
                {
                    _labels = _imageState.Labels;
                }
            }

            if (_imageState.Type.ValueSpace is BinarySpace)
            {
                doNotRenderObject(_imageState);
            }

            Panel p = (Panel)GetControl();

            _imageDrawer = new ImageDrawer();
            p.Controls.Add(_imageDrawer);

            if (_labels != null)
            {
                _imageLabel          = new Label();
                _imageLabel.Text     = _labels.GetShortestLabel();
                _imageLabel.Location = new Point(0, 0);
                _imageLabel.Width    = p.Width;
                _imageLabel.Height   = (int)Globals.MeasureString(_imageLabel.Text, _imageLabel.Font).Height;
                p.Controls.Add(_imageLabel);

                _imageDrawer.Location = new Point(0, _imageLabel.Height + IMAGE_SPACER);
                _imageDrawer.Size     = new Size(p.Width, p.Height - _imageLabel.Height);
            }
            else
            {
                _imageDrawer.Location = new Point(0, 0);
                _imageDrawer.Size     = p.Size;
            }

            p.Resize += new EventHandler(p_Resize);

            _imageState.VariableTable.BinaryDataChanged += new PUC.VariableTable.BinaryEventHandler(VariableTable_BinaryDataChanged);
            _imageState.ValueChangedEvent += new PUC.ApplianceState.ValueChangedHandler(imageState_ValueChangedEvent);
        }
Exemplo n.º 31
0
 /**
  * @param initialState
  */
 public Toaster(ApplianceState initialState)
     : base(initialState)
 {
 }
Exemplo n.º 32
0
 public AbstractAppliance(ApplianceState initialState)
 {
     //this.applianceStateBehavior = initialState //.getStateBehavior();
 }
Exemplo n.º 33
0
 /**
  * @return
  */
 private Appliance createAppliance(ApplianceState state)
 {
     return new Toaster(state);
 }