/// <summary>
        /// Creates a PrinterViewModel with one X Axis ViewModel, one Y Axis ViewModel, one Z Axis ViewModel, and one PrintheadViewModel.
        /// </summary>
        /// <param name="PrinterModel"></param>
        public PrinterViewModel(PrinterModel PrinterModel, SerialCommunicationCommandSetsModel SerialCommunicationCommandSetsModel)
        {
            _printerModel = PrinterModel;
            _serialCommunicationCommandSetsModel = SerialCommunicationCommandSetsModel;
            _gPIOPinListsViewModel = new GPIOPinListsViewModel();

            _microcontrollerViewModel = new MicrocontrollerViewModel(_printerModel.MicroControllerModel, _gPIOPinListsViewModel);

            //Populates the Axis ViewModel lists with their Axis Model counterparts.
            foreach (AxisModel axisModel in _printerModel.AxisModelList)
            {
                AxisViewModel newAxisViewModel = new AxisViewModel(axisModel, _gPIOPinListsViewModel);

                _axisViewModelList.Add(newAxisViewModel);
                if (newAxisViewModel.Name.Contains('Z'))
                {
                    _zAxisViewModelList.Add(newAxisViewModel);
                }
            }

            //Populates the Printhead ViewModel lists with their Printhead Model counterparts.
            foreach (PrintheadModel printheadModel in _printerModel.PrintheadModelList)
            {
                _printheadViewModelList.Add(new PrintheadViewModel(printheadModel, _gPIOPinListsViewModel));
            }

            //Populates the empty PrintheadViewModel list with an empty Printhead.
            _emptyPrintheadViewModelList.Add(new PrintheadViewModel(new PrintheadModel(""), _gPIOPinListsViewModel));

            //Subscribe to events.
            SerialCommunicationCommandSetsModel.RealTimeStatusDataModel.RecordLimitExecuted += new RecordLimitExecutedEventHandler(UpdateMinMaxPositions);
            SerialCommunicationCommandSetsModel.CommandSetMinMaxPositionChanged             += new CommandSetMinMaxPositionChangedEventHandler(UpdateMinMaxPositions);
        }
        /// <summary>
        /// Adds an Axis to the Printer.
        /// </summary>
        private void AddZAxis()
        {
            _printerModel.AddZAxis();
            AxisViewModel newZAxis = new AxisViewModel(_printerModel.AxisModelList[_printerModel.AxisModelList.Count - 1], _gPIOPinListsViewModel);

            _axisViewModelList.Add(newZAxis);
            _zAxisViewModelList.Add(newZAxis);
            OnPropertyChanged("AxisViewModelList");
            OnPropertyChanged("ZAxisViewModelList");
            OnPropertyChanged("ZAxesCreatedCount");
        }
        /// <summary>
        /// Adds an Axis with a Name to the Printer.
        /// </summary>
        /// <param name="axisName"></param>
        /// <returns></returns>
        /// <remarks>
        /// This method was created for XML Serializers.
        /// </remarks>
        public AxisViewModel AddZAxis(string axisName)
        {
            _printerModel.AddZAxis(axisName);
            AxisViewModel newZAxis = new AxisViewModel(_printerModel.AxisModelList[_printerModel.AxisModelList.Count - 1], _gPIOPinListsViewModel);

            _axisViewModelList.Add(newZAxis);
            _zAxisViewModelList.Add(newZAxis);
            OnPropertyChanged("AxisViewModelList");
            OnPropertyChanged("ZAxisViewModelList");
            OnPropertyChanged("ZAxesCreatedCount");
            return(_axisViewModelList[_axisViewModelList.Count - 1]);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(new SolidColorBrush(Color.FromArgb(0x40, 0xBE, 0xE6, 0xFD)));
            }

            AxisViewModel axis      = (AxisViewModel)value;
            AxisType      checkType = (AxisType)parameter;

            return(axis.Type == checkType ? new SolidColorBrush(Color.FromArgb(0xC0, 0xC4, 0xE5, 0x00)) : new SolidColorBrush(Color.FromArgb(0x40, 0xBE, 0xE6, 0xFD)));
        }
Ejemplo n.º 5
0
        public ManualControlViewModel(Global global)
        {
            _global = global ?? throw new ArgumentNullException();

            AxisX = new AxisViewModel(this, global)
            {
                AxisIndex = 0
            };
            AxisY = new AxisViewModel(this, global)
            {
                AxisIndex = 1
            };
            AxisZ = new AxisViewModel(this, global)
            {
                AxisIndex = 2,
                HomeIsMax = true
            };
            AxisA = new AxisViewModel(this, global)
            {
                AxisIndex = 3
            };
            AxisB = new AxisViewModel(this, global)
            {
                AxisIndex = 4
            };
            AxisC = new AxisViewModel(this, global)
            {
                AxisIndex = 5
            };

            Move = new MoveViewModel(this, global);

            CommandHistory = new CommandHistoryViewModel(this, global);

            SD = new SDViewModel(this, global);

            DirectCommand = new DirectCommandViewModel(this, global);

            Shift = new ShiftViewModel(this, global);

            Tool = new ToolViewModel(this, global);

            Rotate = new RotateViewModel(this, global);

            Custom = new CustomViewModel(this, global);

            WorkOffset = new WorkOffsetViewModel(this, global);

            _global.Com.LocalCom.CommandQueueEmpty  += OnCommandQueueEmpty;
            _global.Com.RemoteCom.CommandQueueEmpty += OnCommandQueueEmpty;
        }
        /// <summary>
        /// Writes AxisViewModel properties into a XmlWriter.
        /// </summary>
        /// <param name="xmlWriter"></param>
        /// <param name="axisViewModel"></param>
        public void SerializeAxis(XmlWriter xmlWriter, AxisViewModel axisViewModel)
        {
            //Outmost element should be "Axis".
            xmlWriter.WriteStartElement("Axis");

            //Outmost element should contain properties required for identification and instantiation.
            //Name.
            xmlWriter.WriteAttributeString("Name", axisViewModel.Name);

            //Axis ID.
            xmlWriter.WriteElementString("AxisID", axisViewModel.AxisID.ToString());

            //Motor Step Pin.
            if (axisViewModel.AttachedMotorStepGPIOPinViewModel != null)
            {
                xmlWriter.WriteElementString("MotorStepPin", axisViewModel.AttachedMotorStepGPIOPinViewModel.PinID.ToString());
            }

            //Motor Direction Pin.
            if (axisViewModel.AttachedMotorDirectionGPIOPinViewModel != null)
            {
                xmlWriter.WriteElementString("MotorDirectionPin", axisViewModel.AttachedMotorDirectionGPIOPinViewModel.PinID.ToString());
            }

            //Step Pulse Time.
            xmlWriter.WriteElementString("StepPulseTime", axisViewModel.StepPulseTime.ToString());

            //Limit Switch Pin.
            if (axisViewModel.AttachedLimitSwitchGPIOPinViewModel != null)
            {
                xmlWriter.WriteElementString("LimitSwitchPin", axisViewModel.AttachedLimitSwitchGPIOPinViewModel.PinID.ToString());
            }

            //Max Speed.
            xmlWriter.WriteElementString("MaxSpeed", axisViewModel.MaxSpeed.ToString());

            //Max Acceleration.
            xmlWriter.WriteElementString("MaxAcceleration", axisViewModel.MaxAcceleration.ToString());

            //mm per Step.
            xmlWriter.WriteElementString("MmPerStep", axisViewModel.MmPerStep.ToString());

            //Max Position.
            xmlWriter.WriteElementString("MaxPosition", axisViewModel.MaxPosition.ToString());

            //Min Position.
            xmlWriter.WriteElementString("MinPosition", axisViewModel.MinPosition.ToString());

            //End "Axis" outmost element.
            xmlWriter.WriteEndElement();
        }
Ejemplo n.º 7
0
        public ManualControlViewModel()
        {
            AxisX = new AxisViewModel(this)
            {
                AxisIndex = 0
            };
            AxisY = new AxisViewModel(this)
            {
                AxisIndex = 1
            };
            AxisZ = new AxisViewModel(this)
            {
                AxisIndex = 2,
                HomeIsMax = true
            };
            AxisA = new AxisViewModel(this)
            {
                AxisIndex = 3
            };
            AxisB = new AxisViewModel(this)
            {
                AxisIndex = 4
            };
            AxisC = new AxisViewModel(this)
            {
                AxisIndex = 5
            };

            Move = new MoveViewModel(this);

            CommandHistory = new CommandHistoryViewModel(this);

            SD = new SDViewModel(this);

            DirectCommand = new DirectCommandViewModel(this);

            Shift = new ShiftViewModel(this);

            Tool = new ToolViewModel(this);

            Rotate = new RotateViewModel(this);

            Custom = new CustomViewModel(this);

            WorkOffset = new WorkOffsetViewModel(this);

            Global.Instance.Com.LocalCom.CommandQueueEmpty  += OnCommandQueueEmpty;
            Global.Instance.Com.RemoteCom.CommandQueueEmpty += OnCommandQueueEmpty;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Translates task queued message when a Set Axis task is complete.
        /// Sets parameters for the Real Time Status.
        /// </summary>
        /// <param name="taskQueuedMessage"></param>
        public void InterpretSetAxisComplete(string taskQueuedMessage)
        {
            char   axisID   = 'A';                                                                                     //X, Y, or Z. A is just a temporary placeholder.
            string axisName = taskQueuedMessage.Substring(12, taskQueuedMessage.IndexOf(" S") - 12);                   //Name of the Axis. Labelled as unknown if Axis cannot be found.

            double[] parameterValues = ParseDoubleArray(taskQueuedMessage.Substring(taskQueuedMessage.IndexOf(" S"))); //Array of numerical values in incomingMessage.

            axisName = (_printerModel.FindAxis(axisName) != null) ? axisName : "Unknown Axis";
            int maxSpeed     = (int)parameterValues[0];
            int acceleration = (int)parameterValues[1];

            //The old Axis is used to revert the active status of the old Axis.
            AxisViewModel oldAxisViewModel = null;

            switch (taskQueuedMessage.Substring(4, 1)) //Axis Name.
            {
            case "X":
                axisID = 'X';
                break;

            case "Y":
                axisID = 'Y';
                break;

            case "Z":
                axisID           = 'Z';
                oldAxisViewModel = _printerViewModel.FindAxis(_realTimeStatusDataModel.ZRealTimeStatusAxisModel.Name);
                break;

            default:
                //If Axis was not found.
                axisName = "Unknown Axis";
                break;
            }

            //Set Real Time Status parameters based on this incomingMessage.
            if ((axisID != 'A') &&
                (axisName != "Unknown Axis"))
            {
                if (oldAxisViewModel != null)
                {
                    oldAxisViewModel.AxisStatus = AxisStatus.Idle;
                }
                _realTimeStatusDataModel.RecordSetAxis(axisID, axisName, maxSpeed, acceleration);
                _printerViewModel.FindAxis(axisName).AxisStatus = AxisStatus.Active;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Deserialize an Axis.
        /// </summary>
        /// <param name="xmlReader"></param>
        /// <param name="printerViewModel"></param>
        private void LoadAxis(XmlReader xmlReader, PrinterViewModel printerViewModel)
        {
            //Name of the new Axis.
            string axisName = xmlReader.GetAttribute("Name");

            //AxisID of the new Axis can only be 'Z' as only Z Axis can be created and removed.

            //Reference of the new Axis that will be deserialized.
            AxisViewModel newAxis = null;

            //See if there is a matching Axis.
            bool matchingAxis = false;

            foreach (AxisViewModel axisViewModel in printerViewModel.AxisViewModelList)
            {
                if (axisViewModel.Name == axisName)
                {
                    matchingAxis = true;
                    newAxis      = axisViewModel;
                    break;
                }
            }

            //If there is no matching Axis, then create a new Axis.
            if (matchingAxis == false)
            {
                newAxis = printerViewModel.AddZAxis(axisName);
            }

            //Loads the new Axis with properties from XML and remembers the newly deserialized Axis.
            if (newAxis != null)
            {
                _axisXMLDeserializerModel.DeserializeAxis(xmlReader, newAxis);
                _deserializedAxisViewModelsList.Add(newAxis);
            }
        }
        /// <summary>
        /// Reads AxisViewModel properties from XML and sets an AxisViewModel with said properties.
        /// </summary>
        /// <param name="xmlReader"></param>
        /// <param name="axisViewModel"></param>
        public void DeserializeAxis(XmlReader xmlReader, AxisViewModel axisViewModel)
        {
            //Read through each element of the XML string and populate each property of the Axis.
            while (xmlReader.Read())
            {
                //Skip through newlines (this program's XML Writer uses newlines).
                if ((xmlReader.Name != "\n") && (!String.IsNullOrWhiteSpace(xmlReader.Name)))
                {
                    //End method if the end of "Axis" element is reached.
                    if ((xmlReader.Name == "Axis") && (xmlReader.NodeType == XmlNodeType.EndElement))
                    {
                        return;
                    }

                    switch (xmlReader.Name)
                    {
                    case "Name":     //See if there is a mismatch between the Axis argument and the deserialized Axis.
                        if (xmlReader.ReadElementContentAsString() != axisViewModel.Name)
                        {
                            base.ReportErrorMismatchedEqupment(xmlReader);
                        }
                        break;

                    case "AxisID":     //See if there is a mismatch between the Axis argument and the deserialized Axis.
                        if (xmlReader.ReadElementContentAsString() != axisViewModel.AxisID.ToString())
                        {
                            base.ReportErrorMismatchedEqupment(xmlReader);
                        }
                        break;

                    case "MotorStepPin":
                        axisViewModel.AttachedMotorStepGPIOPinViewModel = _printerViewModel.MicrocontrollerViewModel.FindPin(xmlReader.ReadElementContentAsInt());
                        axisViewModel.ExecuteRefreshPinBySettingListCommand("MotorStepPinViewModelList");
                        break;

                    case "MotorDirectionPin":
                        axisViewModel.AttachedMotorDirectionGPIOPinViewModel = _printerViewModel.MicrocontrollerViewModel.FindPin(xmlReader.ReadElementContentAsInt());
                        axisViewModel.ExecuteRefreshPinBySettingListCommand("MotorDirectionPinViewModelList");
                        break;

                    case "StepPulseTime":
                        axisViewModel.StepPulseTime = xmlReader.ReadElementContentAsInt();
                        break;

                    case "LimitSwitchPin":
                        axisViewModel.AttachedLimitSwitchGPIOPinViewModel = _printerViewModel.MicrocontrollerViewModel.FindPin(xmlReader.ReadElementContentAsInt());
                        axisViewModel.ExecuteRefreshPinBySettingListCommand("LimitSwitchPinViewModelList");
                        break;

                    case "MaxSpeed":
                        axisViewModel.MaxSpeed = xmlReader.ReadElementContentAsDouble();
                        break;

                    case "MaxAcceleration":
                        axisViewModel.MaxAcceleration = xmlReader.ReadElementContentAsDouble();
                        break;

                    case "MmPerStep":
                        axisViewModel.MmPerStep = xmlReader.ReadElementContentAsDouble();
                        break;

                    case "MaxPosition":
                        axisViewModel.MaxPosition = xmlReader.ReadElementContentAsDouble();
                        break;

                    case "MinPosition":
                        axisViewModel.MinPosition = xmlReader.ReadElementContentAsDouble();
                        break;

                    default:
                        base.ReportErrorUnrecognizedElement(xmlReader);
                        break;
                    }
                }
            }
        }