private static bool CreateFeatureFromPoint(CyPhy.Port port, List <KeyValuePair <string, string> > featureList) { PointMetricTraversal traverser = new PointMetricTraversal(port); if (traverser.portsFound.Count() == 1) { CyPhy.Port foundPort = traverser.portsFound.First(); string datumName = ""; if (foundPort.Kind == "Surface") { datumName = (foundPort as CyPhy.Surface).Attributes.DatumName; } else if (foundPort.Kind == "Point") { datumName = (foundPort as CyPhy.Point).Attributes.DatumName; } else if (foundPort.Kind == "Axis") { datumName = (foundPort as CyPhy.Axis).Attributes.DatumName; } KeyValuePair <string, string> pair = new KeyValuePair <string, string>(datumName, CyPhyClasses.Component.Cast(foundPort.ParentContainer.ParentContainer.Impl).Attributes.InstanceGUID); featureList.Add(pair); return(true); } else { return(false); } }
private string GetFeatureName(CyPhy.Port port) { string datumName = ""; PointMetricTraversal traverser = new PointMetricTraversal(port); if (traverser.portsFound.Count() == 1) { CyPhy.Port foundPort = traverser.portsFound.First(); if (foundPort.Kind == "Surface") { datumName = (foundPort as CyPhy.Surface).Attributes.DatumName; } else if (foundPort.Kind == "Point") { datumName = (foundPort as CyPhy.Point).Attributes.DatumName; } else if (foundPort.Kind == "Axis") { datumName = (foundPort as CyPhy.Axis).Attributes.DatumName; } } return(datumName); }
private static IEnumerable <CyPhy.Port> GetReachablePorts(CyPhy.Port port, ConnectionTypes conType, IList <PortTypes> portTypes, IEnumerable <Connection> connections = null) { if (!_reachablePortsCache.ContainsKey(port) || !_reachablePortsCache[port].ContainsKey(conType)) { var result = new List <CyPhy.Port>(); var processedConnection = new List <Connection>(); foreach (var connection in GetAllDstConnection(port) .Where(x => connections == null || connections.Any(y => y.ID == x.ID)) .Where(x => (conType == ConnectionTypes.All) || x.Kind == conType.ToString())) { if (processedConnection.Any(x => x.Guid == connection.Guid)) { continue; } processedConnection.Add(connection); if (!portTypes.Contains(PortTypes.All) && !portTypes.Any(x => connection.GenericDstEnd.Kind == x.ToString())) { continue; } //if (portTypes.All(x => x != PortTypes.All) || portTypes.All(x => connection.GenericDstEnd.Kind != x.ToString())) continue; if (!result.Contains(connection.GenericDstEnd)) { result.Add(CyPhyClasses.Port.Cast(connection.GenericDstEnd.Impl)); } } foreach (var connection in GetAllSrcConnection(port) .Where(x => connections == null || connections.Any(y => y.ID == x.ID)) .Where(x => (conType == ConnectionTypes.All) || x.Kind == conType.ToString())) { if (processedConnection.Any(x => x.Guid == connection.Guid)) { continue; } processedConnection.Add(connection); //if (portTypes.All(x => x != PortTypes.All) || portTypes.All(x => connection.GenericSrcEnd.Kind != x.ToString())) continue; if (!portTypes.Contains(PortTypes.All) && !portTypes.Any(x => connection.GenericSrcEnd.Kind == x.ToString())) { continue; } if (!result.Contains(connection.GenericSrcEnd)) { result.Add(CyPhyClasses.Port.Cast(connection.GenericSrcEnd.Impl)); } } if (!_reachablePortsCache.ContainsKey(port)) { _reachablePortsCache[port] = new Dictionary <ConnectionTypes, List <CyPhy.Port> >(); } _reachablePortsCache[port][conType] = result; } return(_reachablePortsCache[port][conType]); }
private static void GroupStructuralPorts(CyPhy.Port port, ICollection <CyPhy.Port> results, ConnectionTypes connectionType, IEnumerable <Connection> connections = null) { foreach (var nextPort in GetReachableStructuralPorts(port, connectionType, connections)) { if (results.Any(x => x.ID == nextPort.ID)) { continue; } results.Add(nextPort); GroupStructuralPorts(nextPort, results, connectionType, connections); } }
private static String GetOrSetID(CyPhy.Port p) { String id = p.Attributes.ID; if (id == "" && p.IsLib == false) { // set it only if it is not an attached Library object id = p.Impl.GetGuidDisp(); p.Attributes.ID = id; } return(id); }
public PointMetricTraversal(CyPhy.Port port) { portsFound = new List <CyPhy.Port>(); visitedItems = new List <string>(); if (port.Kind == "OrdinalPoint") { portKind = "Point"; } else { portKind = port.Kind; } VisitPort(port); }
private void Traverse(Port srcPort_obj, Tonka.DesignElement parent, Tonka.Port port, Dictionary <string, object> visited) { Logger.WriteDebug("Traverse Port: port {0}", port.Path); if (visited.ContainsKey(port.ID)) { Logger.WriteWarning("Traverse Port Revisit: {0}", port.Path); return; } visited.Add(port.ID, port); // continue traversal var remotes = port.DstConnections.PortCompositionCollection.Select(p => p.DstEnd).Union( port.SrcConnections.PortCompositionCollection.Select(p => p.SrcEnd)); foreach (var remote in remotes) { if (visited.ContainsKey(remote.ID)) { continue; // already visited continue } if (remote.ParentContainer is Tonka.DesignElement) // remote is contained in a Component or ComponentAssembly { srcPort_obj.connectedPorts[remote.Impl.AbsPath] = remote; Traverse(srcPort_obj, remote.ParentContainer as Tonka.DesignElement, remote as Tonka.Port, visited); } else if (remote.ParentContainer is Tonka.Connector) // remote is contained in a Connector { srcPort_obj.connectedPorts[remote.Impl.AbsPath] = remote; Traverse(remote.Name, srcPort_obj, remote.ParentContainer.ParentContainer as Tonka.DesignElement, remote.ParentContainer as Tonka.Connector, visited); } else if (portHasCorrectParentType(remote) && // remote is contained in a SchematicModel CyPhyBuildVisitor.Ports.ContainsKey(remote.ID)) { ConnectPorts(srcPort_obj, CyPhyBuildVisitor.Ports[remote.ID]); } } }
private static IEnumerable <Connection> GetAllDstConnection(CyPhy.Port port) { if (!_dstConnectionCache.ContainsKey(port)) { var result = new List <ISIS.GME.Common.Interfaces.Connection>(); var obj = port.Impl as GME.MGA.MgaFCO; foreach (GME.MGA.MgaConnPoint connpoint in obj.PartOfConns) { var conn = connpoint.Owner as GME.MGA.MgaSimpleConnection; if (conn.Src == obj) { result.Add( ISIS.GME.Common.Utils.CreateObject <ISIS.GME.Common.Classes.Connection>( conn as GME.MGA.MgaObject)); } } _dstConnectionCache[port] = result; } return(_dstConnectionCache[port]); }
private void VisitPort(CyPhy.Port port) { if (!visitedItems.Contains(port.ID)) { visitedItems.Add(port.ID); foreach (CyPhy.PortComposition conn in port.SrcConnections.PortCompositionCollection) { CyPhy.Port feature = conn.SrcEnds.Port; if (feature != null) { if (feature.ParentContainer.Kind == "CADModel" && feature.Kind == portKind) { portsFound.Add(feature); } else { VisitPort(feature); } } } foreach (CyPhy.PortComposition conn in port.DstConnections.PortCompositionCollection) { CyPhy.Port feature = conn.DstEnds.Port; if (feature != null) { if (feature.ParentContainer.Kind == "CADModel" && feature.Kind == portKind) { portsFound.Add(feature); } else { VisitPort(feature); } } } if (port.Kind == "Surface") { foreach (CyPhy.SurfaceReverseMap conn in (port as CyPhy.Surface).SrcConnections.SurfaceReverseMapCollection) { CyPhy.Surface surface = conn.SrcEnds.Surface; if (surface != null) { if (surface.ParentContainer.Kind == "CADModel") { portsFound.Add(surface); } } else { VisitPort(surface); } } foreach (CyPhy.SurfaceReverseMap conn in (port as CyPhy.Surface).DstConnections.SurfaceReverseMapCollection) { CyPhy.Surface surface = conn.DstEnds.Surface; if (surface != null) { if (surface.ParentContainer.Kind == "CADModel") { portsFound.Add(surface); } } else { VisitPort(surface); } } } } }
private static IEnumerable <CyPhy.Port> GetReachableStructuralPorts(CyPhy.Port port, ConnectionTypes conType, IEnumerable <Connection> connections = null) { return(GetReachablePorts(port, conType, new List <PortTypes> { PortTypes.StructuralInterface, PortTypes.StructuralInterfaceForwarder }, connections)); }
private static IEnumerable <CyPhy.Port> GetReachablePorts(CyPhy.Port port, ConnectionTypes conType, IEnumerable <Connection> connections = null) { return(GetReachablePorts(port, conType, new List <PortTypes> { PortTypes.All }, connections)); }