/// <summary> /// given a pid, add/removes the component from LinkComponents and its pid from LinkComponentPIDs, as necessary /// </summary> /// <param name="newPID">pid of component to add to this model configuration</param> public void insertModelComp(String newPID) { //check that component not already in the list for (int i = 0; i < LinkComponents.Count; i++) { if (newPID == LinkComponents[i].ComponentPID) return; } //make new component String newPath = path + "/component" + nextComponentNumber; String newconfigname = modelDoc.ConfigurationManager.ActiveConfiguration.Name; int Errors; byte[] pid; pid = Convert.FromBase64String(newPID); Component2 newcomponent = (Component2)modelDoc.Extension.GetObjectByPersistReference3(pid, out Errors); modelComponent newComponent = new modelComponent(newPath, newconfigname, Type, newcomponent, newPID); nextComponentNumber++; }
/// <summary> /// adds the given component to the list of link components if it not in the list already /// and adds the PID to LinkComponentPIDs /// </summary> /// <param name="component">component to add to this model configuration</param> public void insertModelComp(Component2 component) { if (component == null) return; //check that component not already in the list for (int i = 0; i < LinkComponents.Count; i++) { if (component == LinkComponents[i].Component) return; } //make new component String newPath = path + "/component" + nextComponentNumber; String newconfigname = modelDoc.ConfigurationManager.ActiveConfiguration.Name; byte[] pid = modelDoc.Extension.GetPersistReference3(component); String newpid = Convert.ToBase64String(pid); modelComponent newComponent = new modelComponent(newPath,newconfigname,Type,component,newpid); nextComponentNumber++; //insert in order: Collision, Visual, Physical //assume that LinkComponents already ordered as so for (int i = 0; i < LinkComponents.Count; i++) { if (newComponent.ConfigType < LinkComponents[i].ConfigType) { LinkComponents.Insert(i, newComponent); LinkComponentPIDs.AddItem(newpid); break; } } if (!LinkComponents.Contains(newComponent)) // insert newComponent at end { LinkComponents.Add(newComponent); LinkComponentPIDs.AddItem(newpid); } }
/// <summary> /// Loads existing modelconfiguration from the swdata, /// or creats new one if not already existing /// </summary> /// <param name="path"></param> /// <param name="type"></param> public ModelConfiguration(String path, int type, Link owner) { //setup fields this.modelDoc = RobotInfo.ModelDoc; this.swData = RobotInfo.SwData; this.path = path; this.Type = type; this.Owner = owner; LinkComponents = new List<modelComponent>(); //If the link components data exists, load the components data LinkComponentPIDs = new StringStorageArray(swData, path + "/components"); nextComponentNumber = 0; modelComponent newComp; if (LinkComponentPIDs.Count != 0) { foreach (String s in LinkComponentPIDs) { newComp = new modelComponent(path + "/component" + nextComponentNumber); LinkComponents.Add(newComp); nextComponentNumber++; } } }