Example #1
0
 /*-------------------------------------------------------------*/
 private void OnReelListChanged(StackControl sender, Reel sendersOldReel)
 {
     if (updateAllListsEvent != null)
     {
         updateAllListsEvent(sender, sendersOldReel);
     }
 }
Example #2
0
        /// <summary>
        /// Add a new reel to the control.
        /// <para>Returns true when the reel is added, else false</para>
        /// </summary>
        /// <param name="newReel">Reel to be added</param>
        /// <param name="lockedState">State of the stackControl after adding the reel</param>
        /// <returns>True when the reel is added, else false</returns>
        public bool AddReel(Reel newReel, bool lockedState)
        {
            //find first index of stacks who can have the selected component
            int index = Array.FindIndex(stackControls, curStack => (curStack.Reel == null) && (curStack.StackType == newReel.Footprint.StackType));

            return(this.AddReel(newReel, lockedState, index));
        }
        /// <summary>
        /// Convert the list of components in to a list of reels
        /// </summary>
        /// <param name="componentList">Components to distribute over the reels</param>
        /// <returns>List of reels with the components</returns>
        private static List <Reel> ComponentsToReels(List <PnpComponent> componentList, int speed)
        {
            List <Reel> tempReelList = new List <Reel>();
            List <Reel> result       = new List <Reel>();

            while (componentList.Count != 0)
            {
                PnpComponent        curComponent       = componentList[0];
                List <PnpComponent> matchingComponents = componentList.FindAll(comp_ => (comp_.Comment == curComponent.Comment) && (comp_.ManufacturerPartNumber == curComponent.ManufacturerPartNumber));
                //Find all components of the same type (footprint and comment/value are the same)
                componentList.RemoveAll(comp => matchingComponents.Contains(comp));
                Reel newReel = new Reel(matchingComponents, speed); //make a reel from the components
                tempReelList.Add(newReel);
            }
            while (tempReelList.Count != 0)
            {
                string manufacturerPartNumber = tempReelList[0].Components[0].ManufacturerPartNumber;
                //Find all matching footprints
                List <Reel> similarReels = tempReelList.FindAll(reel => reel.Components[0].ManufacturerPartNumber == manufacturerPartNumber); //make a list of all reels who share the footprint
                tempReelList.RemoveAll(reel => similarReels.Contains(reel));
                Footprint reelFootprint = DatabaseOperations.GetFootprint(manufacturerPartNumber);
                if (reelFootprint != null)
                {
                    foreach (Reel reel in similarReels)
                    {
                        reel.Footprint = reelFootprint;
                    }
                }
                result.AddRange(similarReels);
            }
            return(result);
        }
Example #4
0
        /*-------------------------------------------------------------*/
        private void btnMerge_Click(object sender, EventArgs e)
        {
            //Find all selected reels
            List <Reel> selectedReels = new List <Reel>();

            foreach (ListViewItem selectedItem in lvIncluded.SelectedItems)
            {
                Reel selectedReel = reelsToPlace.Find(curReel => curReel.GetDisplayString() == selectedItem.Text);
                selectedReels.Add(selectedReel);
            }
            //Check if multiple reesl are selected
            if (selectedReels.Count <= 1)
            {
                MessageBox.Show("Please select more the none reel to merge", "warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //Ask wich settings to keep
            MergeForm mergeForm = new MergeForm(selectedReels);

            if (mergeForm.ShowDialog() == DialogResult.OK)
            {
                Reel mergedReel = new Reel(selectedReels, mergeForm.SelectedReel); //new merged reel
                //remove the old reels
                foreach (Reel reelToRemove in selectedReels)
                {
                    reelsToPlace.Remove(reelToRemove);
                }
                reelsToPlace.Add(mergedReel);
                GenerateListViewItems(lvIncluded, reelsToPlace); //only the included list must be updated
                if (stacklisters.Count != 0)
                {
                    AssignReels(false);
                }
            }
        }
Example #5
0
 /// <summary>
 /// Handler for the updateAllListEvent, this event occurs when one of the comboboxes of the stackcontrols is changed,
 /// When that happens the sendersOldReel and the senders new reel change position
 /// </summary>
 /// <param name="sender">Stackcontrol who started the update event</param>
 /// <param name="sendersOldReel">The old reel of the stackControl</param>
 private void UpdateAllListsEvent(StackControl sender, Reel sendersOldReel)
 {
     foreach (StackList stackList_ in stacklisters)
     {
         if (stackList_.UpdateAllLists(sender, sendersOldReel))
         {
             return;                                                    //If the change has happend return, no need to check the ohters
         }
     }
 }
        /*-------------------------------------------------------------*/
        private void cbxAvailable_SelectedIndexChanged(object sender, EventArgs e)
        {
            Reel oldReel = this.reel_;

            this.reel_ = (Reel)cbxReels.SelectedItem;
            if (ReelChanged != null)
            {
                ReelChanged(this, oldReel);
            }
            RefreshList();
        }
Example #7
0
 public bool ReelCanBePlaced(Reel componentReel)
 {
     if ((componentReel.Footprint != null) &&
         (componentReel.Footprint.Height > 0) &&
         (componentReel.Footprint.Height <= height_) &&
         (this.GetNozzleNumber(componentReel.Footprint.Nozzle) != -1))
     {
         return(true);
     }
     return(false);
 }
Example #8
0
        /// <summary>
        /// Edit the settings of the selected reel in the lvIncluded ListView
        /// </summary>
        private void EditReel(object sender, EventArgs e)
        {
            if (lvIncluded.SelectedItems.Count == 0)
            {
                MessageBox.Show("Please select a reel", "no reel selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //Find the reel in reelsToPlace
            ListViewItem selectedItem = lvIncluded.SelectedItems[0];
            Reel         selectedReel = reelsToPlace.Find(curReel => curReel.GetDisplayString() == selectedItem.Text);

#if DEBUG
            //this only happens when the listview isn't updated when the reelsToPlace list is changed (the reel is in the excludedReels list)
            if (selectedReel == null)
            {
                MessageBox.Show("This error is the result of a bug," + Environment.NewLine + "You shouldn't see this" + Environment.NewLine + "have a nice day, for safety reasens the program wil automaticly close", "critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                return;
            }
#endif
            FootprintForm dialog = new FootprintForm();
            dialog.SetFootprint(selectedReel.Footprint);
            if (dialog.ShowDialog() == DialogResult.Yes)
            {
                StackType oldStackType  = selectedReel.Footprint.StackType;
                Footprint footprint     = dialog.GetFootprint();
                bool      couldBePlaced = pnpMachine.ReelCanBePlaced(selectedReel);
                //Changing MPN = creating/changing footprint, changing reels with the original MPN makes it impossible to break the "connection"
                //between reels with the same MPN
                //however, all reels with the same new MPN need to be updated
                selectedReel.Footprint = footprint; //If the manufacturer part number changes, it needs to be updated
                List <Reel> similarReels = reelsToPlace.FindAll(reel => reel.ManufacturerPartNumber == footprint.ManufacturerPartNumber);
                similarReels.AddRange(excludedReels.FindAll(reel => reel.ManufacturerPartNumber == footprint.ManufacturerPartNumber));
                foreach (Reel reel in similarReels)
                {
                    reel.Footprint = footprint;
                }
                //BUG: a splitted reel is not in the list
                //if ((stacklisters.Count != 0) &&
                //    (couldBePlaced != pnpMachine.ReelCanBeplaced(selectedReel) || (footprint.StackType != oldStackType)))
                //{
                //    //IF the stacks are fild AND
                //    //the ReelCanBePlaced state is changed OR the StackType has changed
                //    //then should the stacks be updated
                //    AssignReels(false);
                //}
                if (stacklisters.Count != 0)
                {
                    AssignReels(false);
                }
                GenerateListViewItems(lvIncluded, reelsToPlace);
            }
        }
 /// <summary>
 /// Sets the reel and throw a new <see cref="PickAndPlace.StackControl.ReelChanged"/> event
 /// </summary>
 /// <param name="value">Reel to be set</param>
 public void SetReelWithUpdate(Reel value)
 {
     if (value.ManufacturerPartNumber == this.manufacturerPartNumber_) //TO DO: check -> optional? caller checks also
     {
         SetReel(value, false);
     }
     RefreshList();
     if (ReelChanged != null)
     {
         ReelChanged(this, null);
     }
 }
        /// <summary>
        /// Returns a new reel that only contains the components of one layer
        /// </summary>
        /// <param name="layer">Layer of the components</param>
        /// <returns>One side Reel</returns>
        public Reel GetOneLayer(Layer layer)
        {
            List <PnpComponent> goodSide = components_.FindAll(comp => comp.Location.Layer == layer);

            //if (goodSide.Count != 0) return new Reel(goodSide, this.footprint_.manufacturerPartNumber, this.speed_);
            if (goodSide.Count != 0)
            {
                Reel reel_ = new Reel(goodSide, this.speed_);
                reel_.Footprint = this.footprint_;
                return(reel_);
            }
            return(null);
        }
Example #11
0
 /// <summary>
 /// Changes the reel of one of the <see cref="PickAndPlace.StackControl"/> with the senders old reel
 /// </summary>
 /// <param name="sender">Sender who contains the new rail</param>
 /// <param name="sendersOldReel">Rail to exchange</param>
 /// <returns>True if the <see cref="PickAndPlace.StackControl"/> who contains the senders new reel is in this <see cref="PickAndPlace.StackList"/> else false</returns>
 public bool UpdateAllLists(StackControl sender, Reel sendersOldReel)
 {
     for (int i = 0; i < stackControls.Length; i++)
     {
         StackControl stackControl_ = stackControls[i];
         if ((stackControl_.Reel == sender.Reel) && (stackControl_ != sender))
         {
             stackControl_.ChangeReel(sendersOldReel);
             return(true);
         }
     }
     return(false);
 }
Example #12
0
 /// <summary>
 /// Add a new reel to the control, add the specific location
 /// <para>Returns true when the reel is added, else false</para>
 /// </summary>
 /// <param name="newReel">Reel to be added</param>
 /// <param name="lockedState">State of the stackControl after adding the reel</param>
 /// <param name="index">Index of the new reel</param>
 /// <returns>True when the reel is added, else false</returns>
 public bool AddReel(Reel newReel, bool lockedState, int index)
 {
     if ((index < 0) || (index > stackControls.Length))
     {
         return(false);
     }
     stackControls[index].SetReel(newReel, lockedState);
     if (this.layer_ == ReelLayer.Both)
     {
         this.layer_ = newReel.ReelLayer;
         UpdateTitle();
     }
     return(true);
 }
Example #13
0
 /*-------------------------------------------------------------*/
 private void btnOk_Click(object sender, EventArgs e)
 {
     selectedReel_ = displayedReels.Find(reel => reel.GetDisplayString() == lvReels.SelectedItems[0].Text);
     if (selectedReel_ == null)
     {
         MessageBox.Show("Please select a reel", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (MessageBox.Show("Warning: this change is irreversible" + Environment.NewLine + "Are you sure?", "Please confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
 }
 /// <summary>
 /// Merges the reels and creates a new reel with a given speed and footprint
 /// </summary>
 /// <param name="reels">Reels to merge</param>
 /// <param name="mainReel">Reel with the settings to keep</param>
 public Reel(List <Reel> reels, Reel mainReel)
 {
     speed_      = mainReel.speed_;
     footprint_  = mainReel.footprint_;
     components_ = new List <PnpComponent>();
     foreach (Reel reel in reels)
     {
         foreach (PnpComponent component_ in reel.components_)
         {
             component_.Comment = mainReel.components_[0].Comment;
             component_.ManufacturerPartNumber = mainReel.components_[0].ManufacturerPartNumber;
         }
         components_.AddRange(reel.Components);
     }
     components_.Sort((x, y) => string.Compare(x.Designator, y.Designator));
 }
Example #15
0
        /// <summary>
        /// Add a new reel to the control and activate the update event
        /// <para>Returns true when the reel is added, else false</para>
        /// </summary>
        /// <param name="newReel">Reel to be aded</param>
        /// <returns>True when the reel is added, else false</returns>
        public bool AddReelWithUpdate(Reel newReel)
        {
            //find first index of stacks who can have the selected component
            int index = Array.FindIndex(stackControls, curStack => (curStack.Reel == null) &&
                                        (curStack.ManufacturerPartNumber == newReel.Footprint.ManufacturerPartNumber));

            if (index >= 0)
            {
                stackControls[index].SetReelWithUpdate(newReel);//Difference with the normal AddReel
                if (this.layer_ == ReelLayer.Both)
                {
                    this.layer_ = newReel.ReelLayer;
                    UpdateTitle();
                }
                return(true);
            }
            return(false);
        }
Example #16
0
        /// <summary>
        /// Create stackList controls and fills them with the reels, one layer only
        /// </summary>
        /// <param name="reelsToFill">Reels to fill in the stackControls</param>
        private void FillStackListers(List <Reel> reelsToFill)
        {
            if (reelsToFill.Count == 0)
            {
                return;
            }
            GenerateNewPhase();
            int reelIndex = 0;

            //foreach (Reel goodReel in reelsToFill)
            while (reelIndex < reelsToFill.Count)
            {
                Reel             goodReel             = reelsToFill[reelIndex];
                List <StackList> matchingStackListers = stacklisters.FindAll(stacklister => ((stacklister.Layer == ReelLayer.Both) || (stacklister.Layer == goodReel.ReelLayer)));
                if (matchingStackListers.Count == 0)
                {
                    matchingStackListers.Add(GenerateNewPhase());
                }
                int  index  = 0;
                bool succes = false;
                do
                {
                    succes = matchingStackListers[index].AddReel(goodReel);
                    index++; //go to next (in case it failed)
                    if ((index == matchingStackListers.Count) && (!succes))
                    {
                        StackList newStackControl = GenerateNewPhase();
                        if (!newStackControl.AddReel(goodReel))
                        {
                            //this reel can't be added
                            //newStackControl.updateAllListsEvent -= updateAllListsEvent;
                            //stacklisters.Remove(newStackControl);
                            //newStackControl.Dispose();
                            reelIndex--; //go to previous : otherwise a reel could be skipped
                            reelsToFill.Remove(goodReel);
                        }
                        succes = true;
                    }
                } while (!succes);
                reelIndex++;
            }
        }
        /// <summary>
        /// Sets the reel of the current control
        /// </summary>
        /// <param name="value">Reel to be se</param>
        /// <param name="locked">Control is in the locked state (reel can't be moved to other <see cref="PickAndPlace.StackControl"/>)</param>
        public void SetReel(Reel reel, bool locked)
        {
            if (reel.Footprint.StackType == this.myType)
            {
                this.cbLocked.CheckedChanged -= cbLocked_CheckedChanged;
                this.reel_                    = reel;
                this.nudSpeed.Value           = reel_.Speed;
                this.cbLocked.Checked         = locked;
                this.nudSpeed.Enabled         = !locked;
                this.cbxReels.Enabled         = !locked;
                this.cbLocked.CheckedChanged += cbLocked_CheckedChanged;
#if DEBUG
                if (reel.ReelLayer == ReelLayer.Both)
                {
                    this.BackColor = Color.Chocolate;
                }
                //Visual indicator that something is wrong. Why Chocolate? I like eating Chocolate.
#endif
            }
        }
        /// <summary>
        /// Split the list in 2 lists, one with all the reels for the top layer phase(s), and one with all the reels for the bottom layer phase(s)
        /// </summary>
        /// <param name="allReels">All reels to be placed</param>
        /// <param name="topReels">Reels used in the top layer phase</param>
        /// <param name="bottomReels">Reels used in the bottom layer phase</param>
        public static void SplitReelList(List <Reel> allReels, out List <Reel> topReels, out List <Reel> bottomReels)
        {
            topReels    = new List <Reel>();
            bottomReels = new List <Reel>();
            topReels    = allReels.FindAll(reel => reel.ReelLayer == ReelLayer.Top);
            bottomReels = allReels.FindAll(reel => reel.ReelLayer == ReelLayer.Bottom);
            List <Reel> bothReels = allReels.FindAll(reel => reel.ReelLayer == ReelLayer.Both);

            foreach (Reel reel in bothReels)
            {
                Reel topReelPart = reel.GetOneLayer(Layer.Top);
                if (topReelPart != null)
                {
                    topReels.Add(topReelPart);
                }
                Reel bottomReelPart = reel.GetOneLayer(Layer.Bottom);
                if (bottomReelPart != null)
                {
                    bottomReels.Add(bottomReelPart);
                }
            }
        }
Example #19
0
        /// <summary>
        /// Move a reel from one list to the other
        /// </summary>
        /// <param name="lvOrigin">Listview with the selected reel</param>
        /// <param name="originList">List that currently contains the reel</param>
        /// <param name="destinationList">Target list</param>
        private void MoveReelToOtherListView(ListView lvOrigin, ListView lvDestination, List <Reel> originList, List <Reel> destinationList)
        {
            if (lvOrigin.Items.Count == 0)
            {
                return;
            }
            if (lvOrigin.SelectedItems.Count == 0)
            {
                lvOrigin.Items[0].Selected = true;
            }
            ListViewItem selectedLvItem = lvOrigin.SelectedItems[0];
            int          indexInReel    = originList.FindIndex(curReel => curReel.GetDisplayString() == selectedLvItem.Text);
            Reel         reelToMove     = originList[indexInReel];

            destinationList.Add(reelToMove);
            originList.Remove(reelToMove);

            //move the listview item:
            lvOrigin.Items.Remove(selectedLvItem);
            lvDestination.Items.Add(selectedLvItem);
            selectedLvItem.ImageIndex = Convert.ToInt32(pnpMachine.ReelCanBePlaced(reelToMove));
        }
Example #20
0
 /// <summary>
 /// Add a new reel to the control.
 /// <para>Returns true when the reel is added, else false</para>
 /// </summary>
 /// <param name="newReel">Reel to be added</param>
 /// <returns>True when the reel is added, else false</returns>
 public bool AddReel(Reel newReel)
 {
     return(this.AddReel(newReel, false));
 }
 /// <summary>
 /// Changes the reel of the current control (USE ONLY DURING SWITCHING)
 /// </summary>
 /// <param name="newReel">New reel of the control</param>
 public void ChangeReel(Reel newReel)
 {
     this.reel_ = newReel;
     //this.manufacturerPartNumber_ = newReel.footprint.manufacturerPartNumber; //Optional: mpn is only used for loading configuration
     RefreshList();
 }
        /// <summary>
        /// Load a pick and place project from the project.path
        /// </summary>
        /// <param name="project">Project to load data to</param>
        /// <exception cref="PickAndPlace.FileOperationsException">Thrown when data is missing or when a line could not be decoded</exception>
        public static void LoadProject(PnpProject project)
        {
            List <PnpComponent> includedComponents = new List <PnpComponent>();
            List <PnpComponent> excludedComponents = new List <PnpComponent>();

            //project.stackListers = new List<StackList>();
            using (StreamReader reader = new StreamReader(project.Path))
            {
                while (!reader.EndOfStream)
                {
                    string curLine = reader.ReadLine();
                    //# is a line with comment
                    if (curLine.StartsWith("#") || String.IsNullOrWhiteSpace(curLine))
                    {
                        continue;
                    }
                    string[] splitedLine = curLine.Split(new char[] { ',', '=' }, StringSplitOptions.None);
                    switch (splitedLine[0])
                    {
                    case "ProjectName":
                        project.ProjectName = splitedLine[1];
                        break;

                    case "ProjectFolder":
                        project.ProjectFolder = splitedLine[1];
                        break;

                    case "MachineType":
                        project.Machine = (IMachine)Assembly.GetExecutingAssembly().CreateInstance(splitedLine[1]);
                        project.Machine.DefaultSpeed = Convert.ToInt32(splitedLine[3]);
                        for (int i = 5; i < splitedLine.Length; i++)
                        {
                            Nozzle nozzle = PNPconverterTools.StringToNozzle(splitedLine[i]);
                            project.Machine.SetNozzle(i - 5, nozzle);
                        }
                        break;

                    case "originOffsetX":
                        project.HorizontalOriginOffset = float.Parse(splitedLine[1]);
                        project.VerticalOriginOffset   = float.Parse(splitedLine[3]);
                        break;

                    case "boardsX":
                        project.BoardsX = Convert.ToInt32(splitedLine[1]);
                        project.BoardsY = Convert.ToInt32(splitedLine[3]);
                        break;

                    case "distanceX":
                        project.DistanceX = float.Parse(splitedLine[1]);
                        project.DistanceY = float.Parse(splitedLine[3]);
                        break;

                    case "boardDimX":
                        project.BoardWidth  = float.Parse(splitedLine[1]);
                        project.BoardLength = float.Parse(splitedLine[3]);
                        break;

                    case "Designator":
                        //load new component
                        string designator = splitedLine[1];
                        string manufacturerPartNumber_ = splitedLine[3];
                        float  x        = float.Parse(splitedLine[5]);
                        float  y        = float.Parse(splitedLine[7]);
                        int    rotation = Convert.ToInt32(splitedLine[9]);
                        Layer  layer_;
                        if (splitedLine[11] == Layer.Bottom.ToString())
                        {
                            layer_ = Layer.Bottom;
                        }
                        else
                        {
                            layer_ = Layer.Top;
                        }
                        Location     location_ = new Location(x, y, rotation, layer_);
                        string       comment   = splitedLine[13];
                        bool         included  = Convert.ToBoolean(splitedLine[15]);
                        PnpComponent comp      = new PnpComponent(designator, location_, comment, manufacturerPartNumber_);
                        if (included)
                        {
                            includedComponents.Add(comp);
                        }
                        else
                        {
                            excludedComponents.Add(comp);
                        }
                        break;

                    case "Phase":
                        //last part of the file
                        string   remainingLines        = reader.ReadToEnd();
                        string[] remainingLinesSplited = remainingLines.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
                        //1) make reels from the components:

                        project.IncludedReels = ComponentsToReels(includedComponents, project.Machine.DefaultSpeed);
                        project.ExcludedReels = ComponentsToReels(excludedComponents, project.Machine.DefaultSpeed);

                        List <Reel> completeReelList = new List <Reel>(project.IncludedReels);
                        completeReelList.AddRange(project.ExcludedReels);
                        //the completeReelList contains all reels, however these reels where not splited
                        List <Reel> topReels, bottomReels;
                        Reel.SplitReelList(completeReelList, out topReels, out bottomReels);
                        completeReelList.Clear();
                        completeReelList.AddRange(topReels);
                        completeReelList.AddRange(bottomReels);
                        //topReels and bottomReels contain all reels, also the excluded reels
                        //they will be reused later

                        //2) read each line
                        StackList newStackList = new StackList(project.Machine, Convert.ToInt32(splitedLine[1]));
                        newStackList.Name = "stackList";
                        project.StackListers.Add(newStackList);
                        int index = -1;

                        for (int i = 0; i < remainingLinesSplited.Length; i++)
                        {
                            splitedLine = remainingLinesSplited[i].Split(new char[] { '=', ',' });
                            if (splitedLine[0] != "Phase")
                            {
                                index++;     //Stacks are saved in order (starting at reel 0 -> reel n)
                                string designator_ = splitedLine[1];
                                if (String.IsNullOrWhiteSpace(designator_))
                                {
                                    continue;                                             //empty stack
                                }
                                bool locked = Convert.ToBoolean(splitedLine[5]);
                                //find the reel in the completeReelList
                                Reel matchingReel = completeReelList.Find(reel => reel.GetDesignators().Contains(designator_));
                                matchingReel.Speed = Convert.ToInt32(splitedLine[3]);
                                newStackList.AddReel(matchingReel, locked, index);
                                project.ReelsInStackList.Add(matchingReel);
                            }
                            else
                            {
                                //make a new phase
                                //Phase=X (X=phase number)
                                newStackList      = new StackList(project.Machine, Convert.ToInt32(splitedLine[1]));
                                newStackList.Name = "stackList";
                                project.StackListers.Add(newStackList);
                                index = -1;
                            }
                        }
                        //Reusing topReels and bottomReels
                        Reel.SplitReelList(project.ReelsInStackList, out topReels, out bottomReels);
                        project.TopReels    = topReels;
                        project.BottomReels = bottomReels;

                        break;

                    default:
                        throw new FileOperationsException(String.Format("Unable to read file: {0}{2}Problem with reading folowing line:{2}{1}", project.Path, curLine, Environment.NewLine));
                    }
                }
            }
            if (project.StackListers.Count == 0)
            {
                //no phases saved
                project.IncludedReels = ComponentsToReels(includedComponents, project.Machine.DefaultSpeed);
                project.ExcludedReels = ComponentsToReels(excludedComponents, project.Machine.DefaultSpeed);
            }
            if ((project.HorizontalOriginOffset == -1f) || (project.VerticalOriginOffset == -1f) ||
                (project.BoardsX == -1) || (project.BoardsY == -1) ||
                (project.DistanceX == -1f) || (project.DistanceY == -1f) ||
                (project.BoardWidth == -1f) || (project.BoardLength == -1f) ||
                (project.Machine == null))
            {
                throw new FileOperationsException("Not all data was found in the file");
            }
        }
        /// <summary>
        /// Reads both the pnpFile and the bom file and returns a list of reels based on the two files
        /// </summary>
        /// <param name="pnpFilePath">Path to the Pick and place file</param>
        /// <param name="pnpHeaders">Headers used to read the pnp file</param>
        /// <param name="bomFilePath">Path to the BOM file</param>
        /// <param name="bomHeaders">Headers used to read the BOM</param>
        /// <param name="defaultSpeed">Default speed of the reels</param>
        /// <returns>List of reels that was created based on the data in the files</returns>
        /// <exception cref="PickAndPlace.FileOperationsException">Thrown when some data cannot be processed </exception>
        /// <exception cref="PickAndPlace.HeaderNotFoundException">Thrown when one of the header parameters is not found</exception>
        /// <exception cref="PickAndPlace.PnpConversionException">Thrown when the pnp file uses an unknown length unit</exception>
        public static List <Reel> ReadPickAndPlaceFiles(string pnpFilePath, string[] pnpHeaders, string bomFilePath, string[] bomHeaders, int defaultSpeed)
        {
            List <Reel>         result     = new List <Reel>();
            List <PnpComponent> components = new List <PnpComponent>();

            using (StreamReader reader = new StreamReader(pnpFilePath, Encoding.Default))
            {
                //I had the best result with Encoding.Default and Encoding.UTF7 (ยต character)
                string   line;
                string[] colNames;
                do
                {
                    line     = reader.ReadLine();
                    colNames = SplitLinePNPfile(line);
                } while (colNames.Length < pnpHeaders.Length);

                //find location of corresponding columns
                int colDesignator = IndexOfHeader(colNames, pnpHeaders[0]);
                int colX          = IndexOfHeader(colNames, pnpHeaders[1]);
                int colY          = IndexOfHeader(colNames, pnpHeaders[2]);
                int colLayer      = IndexOfHeader(colNames, pnpHeaders[3]);
                int colRotation   = IndexOfHeader(colNames, pnpHeaders[4]);
                int colComment    = IndexOfHeader(colNames, pnpHeaders[5]);
                //read the document
                while (!reader.EndOfStream)
                {
                    line = reader.ReadLine();
                    string[] parameters = SplitLinePNPfile(line);
                    //first line is empty (contains "", so string.empty doesn't work)
                    if (parameters.Length == colNames.Length)
                    {
                        float X, Y;
                        int   rotation;
                        Layer layer = Layer.Top;
                        X        = ConvertPnpValue(parameters[colX]);
                        Y        = ConvertPnpValue(parameters[colY]);
                        rotation = (int)Convert.ToDouble(parameters[colRotation]);
                        switch (parameters[colLayer])
                        {
                        case "B":
                        case "BottomLayer":
                            layer = Layer.Bottom;
                            break;

                        case "T":
                        case "TopLayer":
                            layer = Layer.Top;
                            break;

                        default:
                            throw new FileOperationsException("Folowing line contains an unknown layer:" + Environment.NewLine + line);
                        }
                        Location     loc  = new Location(X, Y, rotation, layer);
                        PnpComponent comp = new PnpComponent(parameters[colDesignator], loc, parameters[colComment]);
                        components.Add(comp);
                    }
                }
            }
            using (StreamReader xReader = new StreamReader(bomFilePath))
            {
                string   line           = xReader.ReadLine();
                string[] colNames       = line.Split(','); //unlike the pnp file, the header of the BOM has no " "," "
                int      colDesignators = IndexOfHeader(colNames, bomHeaders[0]);
                int      colMPN         = IndexOfHeader(colNames, bomHeaders[1]);
                int      checkCounter   = 0;
                while (!xReader.EndOfStream)
                {
                    line = xReader.ReadLine();
                    string[] parameters = SplitLinePNPfile(line);
                    if (parameters.Length == colNames.Length)
                    {
                        string[]            designators   = parameters[colDesignators].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                        List <PnpComponent> bomComponents = new List <PnpComponent>();
                        foreach (string designator in designators)
                        {
                            PnpComponent comp = components.Find(comp_ => comp_.Designator == designator);
                            if (comp == null)
                            {
                                throw new FileOperationsException("folowing designator was not found in the pick and place file: " + designator);
                            }

                            comp.ManufacturerPartNumber = parameters[colMPN];
                            bomComponents.Add(comp);
                            checkCounter++;
                        }
                        Reel reel = new Reel(bomComponents, defaultSpeed);
                        result.Add(reel);
                    }
                }
                if (checkCounter != components.Count)
                {
                    throw new FileOperationsException("The BOM contains more components then the Pick and Place file");
                }
            }
            return(result);
        }
Example #24
0
        public void ExportToFile(string path, BoardSettings boardSettings, StackList phaseStackList)
        {
            StringBuilder sbStackOffset        = new StringBuilder();
            StringBuilder sbFeederSpacing      = new StringBuilder();
            StringBuilder sbComponentLocations = new StringBuilder();
            int           operationNumber      = 1;
            int           curSpeed             = -1;

            for (int index = 0; index < this.totalAmountOfReels_; index++)
            {
                //values for when there is no reel
                float  offsetX         = 0;
                float  offsetY         = 0;
                string comment         = "";
                float  feedSpacingReel = 0;
                Reel   reelWithIntel   = phaseStackList.GetReel(index);
                if (reelWithIntel != null)
                {
                    Footprint reelsFootprint = reelWithIntel.Footprint; //this makes reading the code easier
                    if (reelWithIntel.Footprint.StackType != StackType.Tray18mm)
                    {
                        offsetX = reelsFootprint.OffsetStackX;
                        offsetY = reelsFootprint.OffsetStackY;
                    }
                    else
                    {
                        offsetX = -9.4f + reelsFootprint.Width / 2 + reelsFootprint.OffsetStackX;
                        offsetY = 8.5f - reelsFootprint.Length / 2 + reelsFootprint.OffsetStackY;
                    }
                    comment         = reelsFootprint.ManufacturerPartNumber;
                    feedSpacingReel = reelsFootprint.FeedRate;

                    int speedValue = reelWithIntel.Speed / 10;
                    //1) check if the speed changes
                    if (speedValue != curSpeed)
                    {
                        curSpeed = speedValue;
                        sbComponentLocations.AppendFormat("0,{0},0,0,0,0,0,0,{1}", speedValue, Environment.NewLine);
                    }
                    //set all components
                    for (int i = 0; i < reelWithIntel.Components.Count; i++)
                    {
                        PnpComponent comp = reelWithIntel.Components[i];
                        float        distance;
                        int          nozzleNumber = this.GetNozzleNumber(reelsFootprint.Nozzle);
                        //This should never give -1 and if it does, the machine wil give an error
                        int compRotation;
                        if (comp.Location.Layer == Layer.Top)
                        {
                            distance     = comp.Location.Y;
                            compRotation = ATmMachine.ConvertAngle(comp.Location.Rotation + reelsFootprint.Rotation);
                        }
                        else
                        {
                            //botom
                            distance     = boardSettings.BoardLength - comp.Location.Y;
                            compRotation = ATmMachine.ConvertAngle(180 - (comp.Location.Rotation + reelsFootprint.Rotation));
                        }
                        //%,Head,Stack,X,Y,R,H,skip,Ref,Comment,
                        sbComponentLocations.AppendFormat("{0},{1},{2},{3:0.###},{4:0.###},{5},{6:0.##},0,{7},{8}{9}",
                                                          new object[] { operationNumber, nozzleNumber, index, comp.Location.X, distance,
                                                                         compRotation, reelsFootprint.Height,
                                                                         comp.Designator, reelsFootprint.ManufacturerPartNumber, Environment.NewLine });
                        operationNumber++;
                    }
                }
                //%,StackOffsetCommand,Stack,X,Y,Comment
                sbStackOffset.AppendFormat("65535,1,{0},{1},{2},{3}{4}",
                                           new object[] { index, offsetX, offsetY, comment, Environment.NewLine });
                sbFeederSpacing.AppendFormat("65535,2,{0},{1},{2}", index, feedSpacingReel, Environment.NewLine);
            }
            using (StreamWriter writer = new StreamWriter(path))
            {
                //1) origin offset
                writer.WriteLine("%,OriginOffsetCommand,X,Y,,");
                writer.WriteLine("65535,0,{0:0.##},{1:0.##},", boardSettings.HorizontalOriginOffset, boardSettings.VerticalOriginOffset);
                writer.WriteLine();

                //2) stack offset
                writer.WriteLine("%,StackOffsetCommand,Stack,X,Y,Comment");
                writer.WriteLine(sbStackOffset.ToString());

                //3) Feeder spacing
                writer.WriteLine("%,FeederSpacingCommand,Stack,FeedSpacing,");
                writer.WriteLine(sbFeederSpacing.ToString());

                //4) Board setup
                writer.WriteLine("%,JointedBoardCommand,X,Y,");
                for (int i = 0; i < boardSettings.BoardsX; i++)
                {
                    for (int j = 0; j < boardSettings.BoardsY; j++)
                    {
                        if ((i != 0) || (j != 0))
                        {
                            //skip the first board
                            float Xcoord = i * (boardSettings.BoardWidth + boardSettings.DistanceX);
                            float Ycoord = j * (boardSettings.BoardLength + boardSettings.DistanceY);
                            writer.WriteLine("65535,3,{0:0.##},{1:0.##},", Xcoord, Ycoord);
                        }
                    }
                }
                writer.WriteLine();
                //5) Component locations
                writer.WriteLine("%,Head,Stack,X,Y,R,H,Skip,Ref,Comment,");
                writer.Write(sbComponentLocations.ToString());
            }
        }
Example #25
0
        /// <summary>
        /// Checks all reels and fill the stacks automatic with the good reels
        /// </summary>
        /// <param name="showWarnings">True if warnings are shown, else false</param>
        private void AssignReels(bool showWarnings)
        {
            //1) Filter the reels
            List <Reel> acceptedReels = new List <Reel>();

            acceptedReels = reelsToPlace.FindAll(curReel => pnpMachine.ReelCanBePlaced(curReel));
            if (showWarnings)
            {
                //Show warnings to the user
                if (acceptedReels.Count == 0)
                {
                    MessageBox.Show("No reels accepted", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                int numberRejected = reelsToPlace.Count - acceptedReels.Count;
                //Not all components are accepted
                if ((numberRejected != 0) &&
                    (MessageBox.Show(numberRejected.ToString() + " rejected" + Environment.NewLine + "Do you want to continue?",
                                     "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No))
                {
                    return;
                }
            }
            //2) clear the old tabPages
            ClearPhases();

            //3) split the list: top and bottom
            List <Reel> topReels, bottomReels;

            Reel.SplitReelList(acceptedReels, out topReels, out bottomReels);
            FillStackListers(topReels);
            FillStackListers(bottomReels);


            int index = 0;

            while (index < stacklisters.Count)
            {
                if (stacklisters[index].Layer == ReelLayer.Top)
                {
                    stacklisters[index].SetTotalList(topReels);
                }
                else if (stacklisters[index].Layer == ReelLayer.Bottom)
                {
                    stacklisters[index].SetTotalList(bottomReels);
                }
                else if (!stacklisters[index].ContainsReels)
                {
                    //Stacklayer == both -> empty stacklist
                    //if, for some reasen (reasen = bug), the layer is both and it contains reels, it should not be removed
                    StackList removedStackList = stacklisters[index]; //need pointer to control for dispose
                    removedStackList.updateAllListsEvent -= UpdateAllListsEvent;
                    stacklisters.RemoveAt(index);
                    removedStackList.Dispose();
                    continue;
                }
                GenerateTabPage(stacklisters[index]);
                index++; //index > 0
            }
            if (index != 0)
            {
                this.pnlExportButtons.Enabled = true;
            }
        }