/// <summary>
        /// 生成一个新的MotorTrack
        /// </summary>
        /// <param name="backgroundColor"></param>
        /// <param name="motorIndex"></param>
        /// <param name="motorName"></param>
        /// <param name="defaultStart"></param>
        /// <returns></returns>
        public MotorTrackBase GetNewMotorTrack(Color backgroundColor, int motorIndex, string motorName, float defaultStart)
        {
            MotorTrackBase obj = null;

            //判断需要哪个模块显示
            if (motorIndex == 12)
            {
                obj = new LightTrack(motorIndex);
            }
            else if (motorIndex == 10 || motorIndex == 11 || motorIndex == 13)
            {
                //行进电机
                obj = new TravelTrack(motorIndex);
            }
            else
            {
                //旋转电机
                short min = -50;
                short max = 50;

                //尝试查找配置的临界值
                if (RevolveAngleLimitDict.ContainsKey(motorIndex))
                {
                    min = RevolveAngleLimitDict[motorIndex].Min;
                    max = RevolveAngleLimitDict[motorIndex].Max;
                }

                obj = new RevolveTrack(motorIndex, min, max);
            }

            //设置属性
            obj.BackgroundColor = backgroundColor;
            obj.DisplayText     = motorName;
            obj.MotorName       = motorName;
            obj.Start           = defaultStart;
            obj.End             = obj.Start + 160;

            return(obj);
        }
예제 #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            tbCode.Text = Guid.NewGuid().ToString();

            if (Object != null)
            {
                tbCode.Text = Object.Code;
                tbName.Text = Object.Name;
                aceConditionControl.SetConditionString(Object.Condition);

                List <Robot_Steps> stepList = DBInstance.DbHelper.table("Robot_Steps").where ("ActionId=?", new object[] { Object.Id }).select("*").getList <Robot_Steps>(new Robot_Steps());
                if (stepList != null)
                {
                    float defaultStart = 40;
                    List <MotorTrackBase> motorList = new List <MotorTrackBase>();
                    foreach (Robot_Steps step in stepList)
                    {
                        Control[] labels = adcActionControl.FindDesignLabel((int)step.MotorIndex);
                        if (labels != null && labels.Length >= 1)
                        {
                            Color          backgroundColor = labels[0].BackColor;
                            MotorTrackBase mt = adcActionControl.GetNewMotorTrack(backgroundColor, (int)step.MotorIndex, labels[0].Text.Replace(step.MotorIndex + ",", string.Empty), defaultStart);
                            defaultStart = mt.End + 10;

                            //Sleep
                            mt.BeforeSleep = (int)step.BeforeSleep;
                            mt.AfterSleep  = (int)step.AfterSleep;

                            if (step.MotorType == 0)
                            {
                                //旋转电机
                                RevolveTrack rt = (RevolveTrack)mt;
                                rt.Angle = (short)step.Value;
                            }
                            else if (step.MotorType == 1)
                            {
                                //航行电机
                                TravelTrack tt = (TravelTrack)mt;
                                switch (step.Value)
                                {
                                case 0:
                                    tt.TravelActionType = TravelActionTypes.C_停止;
                                    break;

                                case 1:
                                    tt.TravelActionType = TravelActionTypes.C_前进;
                                    break;

                                case 2:
                                    tt.TravelActionType = TravelActionTypes.C_后退;
                                    break;
                                }
                            }
                            else
                            {
                                //呼吸灯
                                LightTrack lt = (LightTrack)mt;
                                switch (step.Value)
                                {
                                case 0:
                                    lt.LightStateType = LightStateType.C_灭;
                                    break;

                                case 1:
                                    lt.LightStateType = LightStateType.C_红灯;
                                    break;

                                case 2:
                                    lt.LightStateType = LightStateType.C_绿灯;
                                    break;

                                case 3:
                                    lt.LightStateType = LightStateType.C_蓝灯;
                                    break;
                                }
                            }

                            motorList.Add(mt);
                        }
                    }

                    //显示动作
                    adcActionControl.FillTracks(motorList.ToArray());
                }
            }
        }