public void Load(SUComponentDefinitionRef p_suComponentRef) { SUDrawingElementRef drawingRef = SKPCExport.SUComponentDefinitionToDrawingElement(p_suComponentRef); SUEntityRef entityRef = SKPCExport.SUDrawingElementToEntity(drawingRef); m_identity = SkpEntityCache.GetIdentity(entityRef); m_defaultMaterialIdentity = SkpEntityCache.GetMaterialDefault(drawingRef); SUEntitiesRef entities = default(SUEntitiesRef); SKPCExport.SUComponentDefinitionGetEntities(p_suComponentRef, ref entities); m_instances = SkpInstance.GetEntityInstances(entities, Model); m_groups = SkpGroup.GetEntityGroups(entities, Model); m_faces = SkpFace.GetEntityFaces(entities, Model); m_clusters = SkpFaceCluster.Load(m_faces.Values, m_model); }
/// <summary> /// 异步加载组件 /// </summary> /// <param name="model"></param> /// <param name="p_model"></param> /// <returns></returns> public static Task <Dictionary <string, SkpComponent> > GetComponentsAsync(SUModelRef model, SkpModel p_model) { TaskCompletionSource <Dictionary <string, SkpComponent> > tcs = new TaskCompletionSource <Dictionary <string, SkpComponent> >(); Task.Run(() => { long componentsCount = 0; SKPCExport.SUModelGetNumComponentDefinitions(model, ref componentsCount); if (componentsCount > 0) { SUComponentDefinitionRef[] componentRefs = new SUComponentDefinitionRef[componentsCount]; SKPCExport.SUModelGetComponentDefinitions(model, componentsCount, componentRefs, ref componentsCount); TaskExcutor.Run <SkpComponent, SUComponentDefinitionRef>(componentRefs, c => { SkpComponent component = new SkpComponent(p_model); component.Load(c); return(component); }).ContinueWith(t => { if (t.IsFaulted) { tcs.TrySetException(t.Exception); } else { Dictionary <string, SkpComponent> components = t.Result.ToDictionary(p => p.Identity, p => p); tcs.TrySetResult(components); } }); } else { tcs.TrySetResult(new Dictionary <string, SkpComponent>()); } }); return(tcs.Task); }
public static Dictionary <string, SkpComponent> GetComponents(SUModelRef model, SkpModel p_model) { Dictionary <string, SkpComponent> components = new Dictionary <string, SkpComponent>(200); long componentsCount = 0; SKPCExport.SUModelGetNumComponentDefinitions(model, ref componentsCount); if (componentsCount > 0) { SUComponentDefinitionRef[] componentRefs = new SUComponentDefinitionRef[componentsCount]; SKPCExport.SUModelGetComponentDefinitions(model, componentsCount, componentRefs, ref componentsCount); for (long i = 0; i < componentsCount; i++) { SkpComponent component = new SkpComponent(p_model); component.Load(componentRefs[i]); components.Add(component.Identity, component); } } return(components); }
/// <summary> /// 获取组件identity /// </summary> /// <param name="p_suComponentRef"></param> /// <returns></returns> public static string GetIdentity(SUComponentDefinitionRef p_suComponentRef) { return(SkpEntityCache.GetIdentity(SKPCExport.SUComponentDefinitionToEntity(p_suComponentRef))); }