public DataLedArrayNode(DataLedArrayNode newData)
 {
     LedNumber = newData.LedNumber;
     StateNumber = newData.StateNumber;
     ledData = new ArrayList();
     for (int stateIndex = 0; stateIndex < StateNumber; stateIndex++)
     {
         ArrayList curState = new ArrayList((ArrayList)newData.ledData[stateIndex]);
         ledData.Add(curState);
     }
 }
Example #2
0
        public static DataLedArrayNode ReadBinaryFile(string filePath)
        {
            if (File.Exists(filePath))
            {

                using (BinaryReader reader = new BinaryReader(File.Open(filePath, FileMode.Open)))
                {
                    int temp;
                    int ledNumber;
                    int stateNumber;
                    //Read global info
                    temp = reader.ReadByte();
                    if (temp != 0xFF)
                    {
            #if __DEBUG
                        MessageBox.Show("Read_binary_file: File format is invalid");
            #endif
                        return null;
                    }
                    ledNumber = reader.ReadByte();
                    stateNumber = reader.ReadByte();
                    temp = reader.ReadByte();
                    if (temp != 0xFF)
                    {
            #if __DEBUG
                        MessageBox.Show("Read_binary_file: File format is invalid");
            #endif
                        return null;
                    }
                    DataLedArrayNode dataRead= new DataLedArrayNode();
                    dataRead.LedNumber = ledNumber;
                    //dataRead.StateNumber = stateNumber;
                    //Read states
                    for (int stateIndex = 0; stateIndex < stateNumber; stateIndex++)
                    {
                        //Read state type
                        ArrayList curState= new ArrayList();
                        Constants.StateType stateType = (Constants.StateType)reader.ReadByte();
                        switch (stateType)
                        {
                            case Constants.StateType.Data:
                                curState.Add(stateType);//Add stateType
                                temp = reader.ReadByte();//Add common value
                                curState.Add(temp);
                                for (int ledIndex = 0; ledIndex < ledNumber; ledIndex++)
                                {
                                    temp = reader.ReadByte();
                                    if (temp > Constants.MAX_BRIGHT)
                                    {
                                        MessageBox.Show("Read_binary_file: File format is invalid");
                                        return null;
                                    }
                                    curState.Add(temp);
                                }
                                break;
                            case Constants.StateType.StartFor:
                                                                curState.Add(stateType);//Add stateType
                                temp = reader.ReadByte();//Add common value
                                curState.Add(temp);
                                break;
                            case Constants.StateType.Endfor:
                                 curState.Add(stateType);//Add stateType
                                break;
                            default:
            #if __DEBUG
                                MessageBox.Show("Read_binary_file: File format is invalid");
            #endif
                                return null;
                        }
                        temp = reader.ReadByte();
                        if (temp != 0xFF)
                        {
            #if __DEBUG
                            MessageBox.Show("Read_binary_file: File format is invalid");
            #endif
                            return null;
                        }
                        dataRead.InsertState(stateIndex,stateType);
                        dataRead.SetState(stateIndex,curState);
                    }
                    return dataRead;
                }
            }
            else
            {
            #if __DEBUG
                MessageBox.Show("Read_text_file: File path is invalid");
            #endif
                return null;
            }
        }
Example #3
0
 public DataLedArrayNode ReadTextFile(string filePath)
 {
     if (File.Exists(filePath))
     {
         DataLedArrayNode temp_data = new DataLedArrayNode();
         return temp_data;
     }
     else
     {
         MessageBox.Show("Read_text_file: File path is invalid");
         return null;
     }
 }
Example #4
0
 public static Boolean SaveBinFile(DataLedArrayNode writeData, string targetPath)
 {
     try
     {
         using (BinaryWriter writer = new BinaryWriter(File.Open(targetPath, FileMode.Create)))
         {
             writer.Write((byte)(0xFF));
             writer.Write((byte)writeData.LedNumber);
             writer.Write((byte)writeData.StateNumber);
             writer.Write((byte)(0xFF));
             for (int stateIndex = 0; stateIndex < writeData.StateNumber; stateIndex++)
             {
                 ArrayList curState = (ArrayList)writeData.GetState(stateIndex);
                 Constants.StateType stateType = (Constants.StateType)curState[0];
                 writer.Write((byte)(stateType));
                 int temp;
                 switch (stateType)
                 {
                     case Constants.StateType.Data:
                         temp = (int)curState[1];// Get common value
                         writer.Write((byte)(temp));
                         for (int ledIndex = 0; ledIndex < writeData.LedNumber; ledIndex++)
                         {
                             temp = (int)curState[ledIndex + 2];
                             writer.Write((byte)(temp));
                         }
                         break;
                     case Constants.StateType.StartFor:
                         temp = (int)curState[1];
                         writer.Write((byte)(temp));
                         break;
                     case Constants.StateType.Endfor:
                         break;
                 }
                 writer.Write((Byte)0xFF);
             }
         }
         return true;
     }
     catch(Exception e)
     {
         MessageBox.Show(e.Message);
         return false;
     }
 }
Example #5
0
        public Model()
        {
            ledData = new DataLedArrayNode(1, 8);
            //CurIndex = new LedNodeIndex(0, 0);

            undoList = new ArrayList();
            DataLedArrayNode temp = new DataLedArrayNode(ledData);
            undoList.Insert(0, temp);
            redoList = new ArrayList();
        }
Example #6
0
 private void AddUndoStep()
 {
     /*
      * This function is used to add current date led into undoList and clear redoList
      * It's called when led data changed by user
      */
     if (undoList.Count >= Constants.MAX_STEP)
     {
         //Remove the last node of undoList
         undoList.RemoveAt(Constants.MAX_STEP-1);
     }
     //Add current date led at the first undoList
     DataLedArrayNode temp = new DataLedArrayNode(ledData);
     undoList.Insert(0,temp);
     //Clear redoList
     redoList.Clear();
 }
Example #7
0
 public Boolean ReadFile(string fileType, string filePath)
 {
     ledData=DataFile.ReadBinaryFile(filePath);
     AddUndoStep();
     return true;
 }
Example #8
0
 public Boolean NewFile()
 {
     ledData = new DataLedArrayNode(1, 8);
     AddUndoStep();
     return true;
 }
Example #9
0
 public Boolean GetUndoStep()
 {
     /*
      * This function is called when run command undo
      * It will move the first node of undoList to redoList and update data led with the new first node of undoList
      */
     if (undoList.Count > 1)
     {
         //Get the first node of undoList
         DataLedArrayNode temp = (DataLedArrayNode)undoList[0];
         //Move first node of undoList to redoList
         redoList.Insert(0,temp);
         //Remove the first node of undoList
         undoList.RemoveAt(0);
         //Update data led
         ledData = new DataLedArrayNode((DataLedArrayNode)undoList[0]);
         return true;
     }
     return false;
 }
        private void ShowLedData(DataLedArrayNode dataStructure)
        {
            //TODO:
            showList.Clear();
            pnLedNode.Controls.Clear();
            //ArrayList led_state= (ArrayList)dataStructure.Led[0];
            stateNumber = dataStructure.StateNumber;
            ledNumber = dataStructure.LedNumber;
            for (int stateIndex = 0; stateIndex < dataStructure.StateNumber; stateIndex++)
            {
                ArrayList CurState = (ArrayList)dataStructure.GetState(stateIndex);
                Constants.StateType StateType = dataStructure.GetStateType(stateIndex);
                switch (StateType)
                {
                    case Constants.StateType.Data:
                        for (int ledIndex = 0; ledIndex < dataStructure.LedNumber; ledIndex++)
                        {
                            LedNodeView StateNode = new LedNodeView();
                            StateNode.color = Color.Blue;
                            StateNode.Location = new System.Drawing.Point(10 + 30 * ledIndex, 5 + 30 * stateIndex);
                            StateNode.Size = new System.Drawing.Size(25, 25);
                            StateNode.Name = "LedNodeView" + (char)(ledIndex + 1) + (char)(stateIndex + 1);//LedNodeView + LedIndex + StateIndex
                            StateNode.Value = (int)CurState[ledIndex + 2];
                            StateNode.Type = Constants.StateType.Data;
                            StateNode.LedIndex = ledIndex;
                            StateNode.StateIndex = stateIndex;

                            StateNode.MouseClick += new MouseEventHandler(LedNodeView_Click);
                            StateNode.MouseWheel += new MouseEventHandler(LedNodeView_Mouse_Wheel);
                            StateNode.MouseDoubleClick += new MouseEventHandler(LedNodeView_Mouse_Double_Click);
                            StateNode.MouseMove += new MouseEventHandler(LedNodeView_MouseMove);
                            StateNode.MouseDown += new MouseEventHandler(pnLedNode_MouseDown);
                            StateNode.MouseUp += new MouseEventHandler(pnLedNode_MouseUp);
                            pnLedNode.Controls.Add(StateNode);
                            showList.Add(StateNode);
                            //if (curNode == null) curNode = StateNode;
                        }
                        break;
                    case Constants.StateType.StartFor:
                        LedNodeView StartForNode = new LedNodeView();
                        StartForNode.color = Color.Red;
                        StartForNode.Location = new System.Drawing.Point(10, 5 + 30 * stateIndex);
                        StartForNode.Size = new System.Drawing.Size((int)(30 * dataStructure.LedNumber) - 5, 25);
                        StartForNode.Name = "LedNodeView" + (char)1 + (char)(stateIndex + 1);//LedNodeView + StateIndex
                        StartForNode.Value = dataStructure.GetCommonValue(stateIndex);
                        StartForNode.Type = Constants.StateType.StartFor;
                        StartForNode.LedIndex = 0;
                        StartForNode.StateIndex = stateIndex;

                        StartForNode.MouseClick += new MouseEventHandler(LedNodeView_Click);
                        StartForNode.MouseWheel += new MouseEventHandler(LedNodeView_Mouse_Wheel);
                        pnLedNode.Controls.Add(StartForNode);
                        showList.Add(StartForNode);
                        break;
                    case Constants.StateType.Endfor:
                        LedNodeView EndForNode = new LedNodeView();
                        EndForNode.color = Color.Yellow;
                        EndForNode.Location = new System.Drawing.Point(10, 5 + 30 * stateIndex);
                        EndForNode.Size = new System.Drawing.Size((int)(30 * dataStructure.LedNumber) - 5, 25);
                        EndForNode.Name = "LedNodeView" + (char)1 + (char)(stateIndex + 1);//LedNodeView + StateIndex
                        EndForNode.Value = (int)Constants.MAX_BRIGHT;
                        EndForNode.Type = Constants.StateType.Endfor;
                        EndForNode.LedIndex = 0;
                        EndForNode.StateIndex = stateIndex;
                        EndForNode.Text = "}";
                        //EndForNode.TextAlign = StringAlignment.Far;

                        EndForNode.MouseClick += new MouseEventHandler(LedNodeView_Click);
                        EndForNode.MouseWheel += new MouseEventHandler(LedNodeView_Mouse_Wheel);
                        pnLedNode.Controls.Add(EndForNode);
                        showList.Add(EndForNode);
                        break;
                }
            }
            if (curIndex != defaultIndex)
            {
                SelectNode(curIndex.stateIndex, curIndex.ledIndex);
            }
        }