public CyPhy.EDAModel BuildCyPhyEDAModel(avm.schematic.eda.EDAModel edaModel, CyPhy.Component comp) { var rf = CyPhyClasses.RootFolder.GetRootFolder(CurrentProj); var builder = new AVM2CyPhyML.CyPhyMLComponentBuilder(rf); CyPhy.EDAModel cyPhyEDAModel = builder.process(edaModel, comp); #region layout // find the largest current Y value so our new elements are added below the existing design elements greatest_current_y = 0; foreach (var child in GetCurrentDesignElement().AllChildren) { foreach (MgaPart item in (child.Impl as MgaFCO).Parts) { int read_x, read_y; string read_str; item.GetGmeAttrs(out read_str, out read_x, out read_y); greatest_current_y = (read_y > greatest_current_y) ? read_y : greatest_current_y; } } // layout CAD model to the "south" of existing elements foreach (MgaPart item in (cyPhyEDAModel.Impl as MgaFCO).Parts) { item.SetGmeAttrs(null, MODEL_START_X, greatest_current_y + MODEL_START_Y); } #endregion ExtendDevicePorts(cyPhyEDAModel); return(cyPhyEDAModel); }
private AbstractClasses.Component ParseCyPhyComponent(CyPhy.Component component) { string classification = component.Attributes.Classifications.ToString(); if (String.Compare(classification, "ara_template") == 0 || String.Compare(classification, "template.ara_module_template") == 0) { // Stock module present for component replacement. AbstractClasses.AraTemplateComponent template = new AbstractClasses.AraTemplateComponent() { name = component.Attributes.InstanceGUID, classification = classification }; ParseAraTemplateComponent(component, template); return(template); } AbstractClasses.Component rtn = new AbstractClasses.Component() { // MOT-656 Switch to using component GUID as map key. Each component guaranteed to have a GUID, no need to check. name = component.Attributes.InstanceGUID, classification = classification }; // Check for only one EDAModel IEnumerable <CyPhy.EDAModel> edas = component.Children.EDAModelCollection; if (edas.Count() > 1) { logger.WriteError("Multiple EDAModels found for component {0}. Component should " + "only have one EDAModel.", component.Name); return(null); } IEnumerable <CyPhy.CAD2EDATransform> xforms = component.Children.CAD2EDATransformCollection; if (xforms.Count() == 0) { if (edas.Count() == 0) { logger.WriteInfo("Skipping component {0}, no EDAModel or CAD2EDATransform objects found.", component.Name); } else { logger.WriteWarning("EDAModel found for component {0} with no CAD2EDATransform, will generate " + "placeholder in visualizer based on EDAModel dimensions.", component.Name); CyPhy.EDAModel edaModel = edas.First(); } } else { // At this point you know all transforms point to the same EDAModel. The language also only // allows for one transform connection per CAD model, so you know there are no duplicate // transforms. foreach (var xform in xforms) { CyPhy.CADModel cadModel = xform.SrcEnds.CADModel; AddCadModelToComponent(xform, cadModel, component, rtn); } } return(rtn); }
/// <summary> /// Given a CyPhy EDAModel, create copies of its ports at the /// Component level, and connect them to the EDAModel's ports. /// Do the same for the EDAModel's parameters. /// </summary> /// <param name="model"></param> public void ExtendDevicePorts(CyPhy.EDAModel model) { var component = CyPhyClasses.Component.Cast(model.ParentContainer.Impl); int num_pins_in_schematic_model = model.Children.SchematicModelPortCollection.Count(); int num_rows_in_schematic_model = num_pins_in_schematic_model / 2; int pad_to_get_under_schematic_model = 100 + num_rows_in_schematic_model * 15; int num_parsed_pins = 0; // Use a dictionary to track duplicate pin names, MOT-514 Dictionary <string, List <CyPhy.SchematicModelPort> > pinDict = new Dictionary <string, List <CyPhy.SchematicModelPort> >(); foreach (var pin in model.Children.SchematicModelPortCollection) { var newPin = CyPhyClasses.SchematicModelPort.Create(component); newPin.Name = pin.Name; newPin.Attributes.Definition = pin.Attributes.Definition; newPin.Attributes.DefinitionNotes = pin.Attributes.DefinitionNotes; newPin.Attributes.EDAGate = pin.Attributes.EDAGate; newPin.Attributes.InstanceNotes = pin.Attributes.InstanceNotes; newPin.Attributes.EDASymbolLocationX = pin.Attributes.EDASymbolLocationX; newPin.Attributes.EDASymbolLocationY = pin.Attributes.EDASymbolLocationY; newPin.Attributes.EDASymbolRotation = pin.Attributes.EDASymbolRotation; CyPhyClasses.PortComposition.Connect(pin, newPin, null, null, component); // Add the pin to the dictionary's list, MOT-514 if (!pinDict.ContainsKey(newPin.Name)) { List <CyPhy.SchematicModelPort> tmpList = new List <CyPhy.SchematicModelPort>(); pinDict.Add(newPin.Name, tmpList); } pinDict[newPin.Name].Add(newPin); foreach (MgaPart item in (newPin.Impl as MgaFCO).Parts) { int original_x = 0; int original_y = 0; foreach (MgaPart item2 in (pin.Impl as MgaFCO).Parts) { String icon; item2.GetGmeAttrs(out icon, out original_x, out original_y); break; } int new_x = original_x; int new_y = greatest_current_y + MODEL_START_Y + pad_to_get_under_schematic_model + original_y; item.SetGmeAttrs(null, new_x, new_y); } num_parsed_pins++; } // Try to disambiguate any duplicate pin names, MOT-514. foreach (KeyValuePair <string, List <CyPhy.SchematicModelPort> > entry in pinDict) { if (entry.Value.Count > 1) { foreach (CyPhy.SchematicModelPort pin in entry.Value) { pin.Name += ("_" + pin.Attributes.EDAGate); } } } int num_parsed_params = 0; foreach (var param in model.Children.EDAModelParameterCollection) { var newProp = CyPhyClasses.Property.Create(component); newProp.Name = param.Name; newProp.Attributes.Value = param.Attributes.Value; CyPhyClasses.EDAModelParameterMap.Connect(newProp, param, null, null, component); // - Perform some layout "niceification" on the resulting objects. foreach (MgaPart item in (newProp.Impl as MgaFCO).Parts) { item.SetGmeAttrs(null, PARAMETER_START_X, greatest_current_y + PARAMETER_START_Y + (num_parsed_params * PARAMETER_ADJUST_Y)); } num_parsed_params++; } }