Ejemplo n.º 1
0
        // Merge all components into one (the first) assembly
        // Meta-Link is using this for unconnected assemblies
        public void MergeAssemblies()
        {
            if (assemblies.Count <= 1)
            {
                return;
            }
            int         i     = 0;
            CADAssembly first = null;

            foreach (var assembly in assemblies.Values)
            {
                if (i == 0)
                {
                    first = assembly;
                    i++;
                    continue;
                }
                else
                {
                    first.ChildComponents = first.ChildComponents.Union(assembly.ChildComponents).ToDictionary(k => k.Key, v => v.Value);
                    first.ChildEdges.AddRange(assembly.ChildEdges);
                }
            }
            assemblies.Clear();
            assemblies.Add(first.Id, first);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Meta-Link feature: If there's no components in an assembly still need to add one empty root component
        /// </summary>
        /// <param name="?"></param>
        public void AddRootComponent(CyPhy.ComponentAssembly assembly)
        {
            CADAssembly a = new CADAssembly();

            a.Id   = a.ConfigID = assembly.Guid.ToString();
            a.Name = a.DisplayName = assembly.Name;
            assemblies.Add(UtilityHelpers.CleanString2(assembly.Name), a);
        }
Ejemplo n.º 3
0
        public void ToDAG(DataRep.CADAssembly assembly,
                          List <string> RefCoordComponents)
        {
            string        start_component_id = "-1";
            List <string> openComponents     = new List <string>();
            List <string> closedComponents   = new List <string>();


            // [1] Create openEdges
            List <DataRep.CADEdge> openEdges = new List <DataRep.CADEdge>();

            openEdges.AddRange(assembly.ChildEdges);

            // [2] Find starting component and create openComponents set

            /*
             * // META-2885
             * start_component_id = FindStartingComponent(assembly.ChildComponents.Keys.ToList(),
             *                                         RefCoordComponents,
             *                                         openEdges,
             *                                         openComponents);
             */
            start_component_id = FindStartingComponent(assembly.ChildComponents.OrderBy(x => x.Value.Name).ToDictionary(x => x.Key, x => x.Value).Keys.ToList(),
                                                       RefCoordComponents,
                                                       openEdges,
                                                       openComponents);
            assembly.RootComponentID = start_component_id;
            closedComponents.Add(start_component_id);
            // cassemblyParent_in->SetRootComponentID(start_component_id);
            int degree = 6, openSize = openComponents.Count();

            while (openComponents.Any())
            {
                ConstrainComponents(closedComponents, openEdges, degree, openComponents);
                //ConstrainComponents(closedComponents, assembly.ChildEdges, degree, openComponents);
                int tmp_open_size = openComponents.Count();

                if (tmp_open_size == openSize)                  // was not able to find components with edges of dof 6
                {
                    degree--;
                }
                else
                {
                    degree = 6;
                }

                openSize = tmp_open_size;
            }

            if (openEdges.Any())
            {
                debugMessages.Add("+++++ Left Over Edges +++++\n");
                foreach (var edge in openEdges)
                {
                    debugMessages.Add("		Source: "+ edge.Src.Id + "Dst: " + edge.Dst.Id + "\n");
                }
            }
        }
        public DataRep.CADContainer WalkAssembly(Dictionary<string, DataRep.CADComponent> regularComponents,
                                 List<DataRep.CADEdge> regularEdges,
                                 Dictionary<string, DataRep.CADComponent> size2fitComponents,
                                 List<DataRep.CADEdge> size2fitEdges,
                                 List<DataRep.CADComponent> orphans,
                                 List<string> RefCoordIDs)
        {
            //Dictionary<string, DataRep.CADAssembly> tmpassemblies = new Dictionary<string, DataRep.CADAssembly>();
    
            DataRep.CADContainer assembliesContainer = new DataRep.CADContainer("jklmn");

            List<DataRep.CADEdge> openEdges = new List<DataRep.CADEdge>();
            openEdges = regularEdges;
            List<string> openComponents = regularComponents.Keys.ToList();
            Queue<string> openQ = new Queue<string>();

            assembliesContainer.orphans.AddRange(orphans);

            if (openComponents.Count() == 1 && !openEdges.Any())
            {
                string ID = assemblyID + "|" + newAssemblyIDSeed.ToString();
                DataRep.CADAssembly anassembly = new DataRep.CADAssembly(ID, assemblyName);               //DataRep.CADAssembly anassembly = new DataRep.CADAssembly(assemblyID, assemblyName);
                anassembly.ChildComponents.Add(regularComponents.First().Key, regularComponents.First().Value);
                anassembly.ChildComponents = regularComponents;
                anassembly.ChildEdges = regularEdges;
                ToDAG(anassembly, RefCoordIDs);     // EXPERIMENT!!!
                assembliesContainer.assemblies.Add(assemblyID, anassembly);
            }
            else
            {
                int z = 1;
                while (openEdges.Any())
                {
                    List<DataRep.CADEdge> closedEdges = new List<DataRep.CADEdge>();
                    List<string> closedComponents = new List<string>();

                    DataRep.CADEdge lastEdge = openEdges.Last();
                    string srcid = lastEdge.Src.Id;
                    FindComponentID(srcid,
                                    openComponents,
                                    openQ);
                    
                    WalkIncidentEdges(openQ, 
                                      openComponents, 
                                      closedComponents, 
                                      openEdges, 
                                      closedEdges);
                    
                    // create a new island CAssembly;
                    string ID = assemblyID + "|" + newAssemblyIDSeed.ToString();
                    DataRep.CADAssembly anassembly = new DataRep.CADAssembly(ID, assemblyName + "_" + newAssemblyIDSeed.ToString());
                    foreach (var key in closedComponents)
                    {
                        if (regularComponents.ContainsKey(key))
                        {
                            anassembly.ChildComponents.Add(key, regularComponents[key]);
                            component2assemblyTable[key]= ID;
                        }
                    }

                    anassembly.ChildEdges.AddRange(closedEdges);
                    ToDAG(anassembly, RefCoordIDs);
                    assembliesContainer.assemblies.Add(ID, anassembly);

                    newAssemblyIDSeed++;
                    z++;
                }

                if (openComponents.Any())
                {
                    foreach (string id in openComponents)
                    {
                        DataRep.CADComponent component;
                        if (regularComponents.TryGetValue(id, out component))
                            assembliesContainer.orphans.Add(component);
                    }
                }
                
                // size2fit
                // iterate through Size2Fit (are they orphans or belong to a CAssembly?)
		        // for each size2fit, find its size2fit edges
		        // find which assembly contains the edge's source
		        // if they are in the same 
		        foreach (var item in size2fitComponents)
		        {
			        List<DataRep.CADEdge> s2fclosedEdges = new List<DataRep.CADEdge>();				// <source, CEdge*>
			        string assemblyParent_ID = FindSize2FitEdges(item.Key, size2fitEdges, s2fclosedEdges);

			        // orphan if no edges or parentID is -1
			        if (!s2fclosedEdges.Any() || assemblyParent_ID == "-1")
			        {
                        assembliesContainer.orphans.Add(item.Value);
			        }
			        else
			        {
				        // add size2fit + size2fit edges to island assembly
                        if (assembliesContainer.assemblies.ContainsKey(assemblyParent_ID))
                        {
                            assembliesContainer.assemblies[assemblyParent_ID].ChildSize2FitComponents[item.Key] = item.Value;
                            assembliesContainer.assemblies[assemblyParent_ID].ChildSize2FitEdges.AddRange(s2fclosedEdges);
				        }
			        }
		        }

                // Testing
                //assembliesContainer.ToString();

                // Convert to DAG                
                //ToDAG(assembliesContainer.assemblies, RefCoordIDs);

                Print();

            } // else


            
            return assembliesContainer;
        }
Ejemplo n.º 5
0
        public DataRep.CADContainer WalkAssembly(Dictionary <string, DataRep.CADComponent> regularComponents,
                                                 List <DataRep.CADEdge> regularEdges,
                                                 Dictionary <string, DataRep.CADComponent> size2fitComponents,
                                                 List <DataRep.CADEdge> size2fitEdges,
                                                 List <DataRep.CADComponent> orphans,
                                                 List <string> RefCoordIDs)
        {
            //Dictionary<string, DataRep.CADAssembly> tmpassemblies = new Dictionary<string, DataRep.CADAssembly>();

            DataRep.CADContainer assembliesContainer = new DataRep.CADContainer("jklmn");

            List <DataRep.CADEdge> openEdges = new List <DataRep.CADEdge>();

            openEdges = regularEdges;
            List <string>  openComponents = regularComponents.Keys.ToList();
            Queue <string> openQ          = new Queue <string>();

            assembliesContainer.orphans.AddRange(orphans);

            if (openComponents.Count() == 1 && !openEdges.Any())
            {
                string ID = assemblyID + "|" + newAssemblyIDSeed.ToString();
                DataRep.CADAssembly anassembly = new DataRep.CADAssembly(ID, assemblyName + "_" + (newAssemblyIDSeed++).ToString());               //DataRep.CADAssembly anassembly = new DataRep.CADAssembly(assemblyID, assemblyName);
                anassembly.ChildComponents.Add(regularComponents.First().Key, regularComponents.First().Value);
                anassembly.ChildComponents = regularComponents;
                anassembly.ChildEdges      = regularEdges;
                ToDAG(anassembly, RefCoordIDs);     // EXPERIMENT!!!
                assembliesContainer.assemblies.Add(assemblyID, anassembly);
            }
            else
            {
                int z = 1;
                while (openEdges.Any())
                {
                    List <DataRep.CADEdge> closedEdges      = new List <DataRep.CADEdge>();
                    List <string>          closedComponents = new List <string>();

                    DataRep.CADEdge lastEdge = openEdges.Last();
                    string          srcid    = lastEdge.Src.Id;
                    FindComponentID(srcid,
                                    openComponents,
                                    openQ);

                    WalkIncidentEdges(openQ,
                                      openComponents,
                                      closedComponents,
                                      openEdges,
                                      closedEdges);

                    // create a new island CAssembly;
                    string ID = assemblyID + "|" + newAssemblyIDSeed.ToString();
                    DataRep.CADAssembly anassembly = new DataRep.CADAssembly(ID, assemblyName + "_" + newAssemblyIDSeed.ToString());
                    foreach (var key in closedComponents)
                    {
                        if (regularComponents.ContainsKey(key))
                        {
                            anassembly.ChildComponents.Add(key, regularComponents[key]);
                            component2assemblyTable[key] = ID;
                        }
                    }

                    anassembly.ChildEdges.AddRange(closedEdges);
                    ToDAG(anassembly, RefCoordIDs);
                    assembliesContainer.assemblies.Add(ID, anassembly);

                    newAssemblyIDSeed++;
                    z++;
                }

                if (openComponents.Any())
                {
                    foreach (string id in openComponents)
                    {
                        DataRep.CADComponent component;
                        if (regularComponents.TryGetValue(id, out component))
                        {
                            assembliesContainer.orphans.Add(component);
                        }
                    }
                }

                // size2fit
                // iterate through Size2Fit (are they orphans or belong to a CAssembly?)
                // for each size2fit, find its size2fit edges
                // find which assembly contains the edge's source
                // if they are in the same
                foreach (var item in size2fitComponents)
                {
                    List <DataRep.CADEdge> s2fclosedEdges = new List <DataRep.CADEdge>();                                       // <source, CEdge*>
                    string assemblyParent_ID = FindSize2FitEdges(item.Key, size2fitEdges, s2fclosedEdges);

                    // orphan if no edges or parentID is -1
                    if (!s2fclosedEdges.Any() || assemblyParent_ID == "-1")
                    {
                        assembliesContainer.orphans.Add(item.Value);
                    }
                    else
                    {
                        // add size2fit + size2fit edges to island assembly
                        if (assembliesContainer.assemblies.ContainsKey(assemblyParent_ID))
                        {
                            assembliesContainer.assemblies[assemblyParent_ID].ChildSize2FitComponents[item.Key] = item.Value;
                            assembliesContainer.assemblies[assemblyParent_ID].ChildSize2FitEdges.AddRange(s2fclosedEdges);
                        }
                    }
                }

                // Testing
                //assembliesContainer.ToString();

                // Convert to DAG
                //ToDAG(assembliesContainer.assemblies, RefCoordIDs);

                Print();
            } // else



            return(assembliesContainer);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Meta-Link feature: If there's no components in an assembly still need to add one empty root component
 /// </summary>
 /// <param name="?"></param>
 public void AddRootComponent(CyPhy.ComponentAssembly assembly)
 {
     CADAssembly a = new CADAssembly();
     a.Id = a.ConfigID = assembly.Guid.ToString();
     a.Name = a.DisplayName = assembly.Name;
     assemblies.Add(UtilityHelpers.CleanString2(assembly.Name), a);
 }