private void VisitModelItem(Model model, ModelItem mi, NavModelNode node) { node.DisplayName = ((mi.DisplayName.Length == 0) ? mi.ClassDisplayName : mi.DisplayName); this.ReadProperties(mi, node); //如果该项目有几何图形 bool hasGeometry = mi.HasGeometry; if (hasGeometry) { //转换为COM选择集 Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath inwOaPath = ComApiBridge.ToInwOaPath(mi); //创建回调对象 NavGeometryCallback navGeometryCallback = new NavGeometryCallback(); navGeometryCallback.UnitScaleToMM = (float)UnitConversion.ScaleFactor(model.Units, Units.Millimeters); foreach (InwOaFragment3 inwOaFragment in inwOaPath.Fragments()) { Autodesk.Navisworks.Api.Interop.ComApi.InwOpState10 state = ComApiBridge.State; Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath3 inwOaPath2 = (Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath3)inwOaFragment.path; Autodesk.Navisworks.Api.Interop.ComApi.InwLTransform3f localToWorldMatrix = inwOaFragment.GetLocalToWorldMatrix(); Array array3 = (Array)(object)localToWorldMatrix.Matrix; InwOaPath path = inwOaFragment.path; ModelItem obj2 = ComApiBridge.ToModelItem(path); bool flag = !mi.Equals(obj2); if (!flag) { ComApi.InwLTransform3f3 localToWorld = (ComApi.InwLTransform3f3)(object) inwOaFragment.GetLocalToWorldMatrix(); //Array array_v1 = (Array)(object)localToWorld.Matrix; InwLTransform3f3 fragmentTransform = (InwLTransform3f3)inwOaFragment.GetLocalToWorldMatrix(); // navGeometryCallback.localToWorldMatrix = inwOaFragment.GetLocalToWorldMatrix(); navGeometryCallback.FragmentTransform = fragmentTransform; inwOaFragment.GenerateSimplePrimitives(nwEVertexProperty.eNORMAL, navGeometryCallback); } } Color originalColor = mi.Geometry.OriginalColor; NavColor color = new NavColor((float)originalColor.R, (float)originalColor.G, (float)originalColor.B, 1f - (float)mi.Geometry.ActiveTransparency); navGeometryCallback.Geometry.Color = color; this.Geometries.Add(navGeometryCallback.Geometry); this.currentTriangleCount_ += navGeometryCallback.Geometry.Triangles.Count / 3; node.GeometryId = string.Concat(navGeometryCallback.Geometry.Id); bool flag2 = this.currentTriangleCount_ >= this.maxTriangleCount_; if (flag2) { this.WriteModel(); } } foreach (ModelItem modelItem in mi.Children) { bool isHidden = modelItem.IsHidden; if (!isHidden) { NavModelNode navModelNode = new NavModelNode(); node.Children.Add(navModelNode); this.VisitModelItem(model, modelItem, navModelNode); } } }
// Determine if targetParent is only reachable from item via expectedParent // Return true if the only routes from item to targetParent include expectedParent; false otherwise // Do not search past source Properties with a ViewIgnore attribute but continue looking for targetParent private static bool UniqueRoute(ModelItem item, ModelItem targetParent, ModelItem expectedParent) { bool retval = true; if (null == item) { retval = false; } else { HashSet <ModelItem> visited = new HashSet <ModelItem>(); Queue <ModelItem> todo = new Queue <ModelItem>(); todo.Enqueue(item); while (0 < todo.Count) { ModelItem parent = todo.Dequeue(); if (null != parent && !visited.Contains(parent)) { visited.Add(parent); if (parent.Equals(targetParent)) { // Failure: Route was not unique, have reached target without passing expectedParent retval = false; break; } else if (!parent.Equals(expectedParent)) { UniqueModelItemHelper.EnqueueParents(parent, todo); } } } } return(retval); }
//Returns true if child is a member of the tree rooted at the parent; bool IsParentOf(ModelItem parent, ModelItem child) { Fx.Assert(parent != null, "Invalid argument"); bool isParentOf = false; while (child != null) { if (parent.Equals(child)) { isParentOf = true; break; } child = child.Parent; } return(isParentOf); }
// Return HashSet containing ModelItems found only through given property: Cannot reach property.Parent without // hitting property from these immediate descendents of property.Value // Set may contain some internal duplication -- all nodes, not just the root, of a linked tree will be included // // Caveat 1: Due to problems removing Parents (e.g. Case content sometimes holds references to FlowSwitch after // Case removed), this method is not entirely reliable -- customers may occasionally need to reopen Designer // Caveat 2: Due to lazy loading of Properties (and therefore the back-pointing Parents collection), may // temporarily include non-unique ModelItems in returned set -- cleared as tree or designer views expand // // (Throughout, cannot use ModelItem.GetParentEnumerator because that does not check all Sources and Parents) internal static HashSet <ModelItem> FindUniqueChildren(ModelProperty property) { HashSet <ModelItem> retval = new HashSet <ModelItem>(); if (null != property && null != property.Parent && null != property.Value) { ModelItem target = property.Parent; ModelItem expected = property.Value; HashSet <ModelItem> visited = new HashSet <ModelItem>(); // Check all immediate children of property.Value ModelItemCollection collection = expected as ModelItemCollection; if (null == collection) { ModelItemDictionary dictionary = expected as ModelItemDictionary; if (null == dictionary) { // ModelItem // Can't use UniqueRoute because we're starting at expected // Can't use EnqueueParents because we need to special-case given property // Instead confirm property.Value is not referenced anywhere else ModelItemImpl expectedImpl = expected as ModelItemImpl; if (null != expectedImpl) { bool justThisSource = true; // expectedImpl.InternalParents does not include ModelItems that are just Sources if (0 == expectedImpl.InternalParents.Count) { // expectedImpl.InternalSources would be similar but adds a wrapper we don't need here foreach (ModelProperty source in expected.Sources) { if (null != source.Parent && !visited.Contains(source.Parent)) { visited.Add(source.Parent); if (!property.Equals(source) && !expected.Equals(source) && null == ExtensibilityAccessor.GetAttribute <HidePropertyInOutlineViewAttribute>(source)) { // Found a non-ignored property from somewhere else referencing expected justThisSource = false; break; } } } } else { // Found a Parent that's not a Source.Parent: property.Value is in some collection justThisSource = false; } if (justThisSource) { retval.Add(expected); } } } else { // ModelItemDictionary foreach (KeyValuePair <ModelItem, ModelItem> child in dictionary) { if (null != child.Key && !visited.Contains(child.Key)) { visited.Add(child.Key); if (UniqueModelItemHelper.UniqueRoute(child.Key, target, expected)) { retval.Add(child.Key); } } if (null != child.Value && !visited.Contains(child.Value)) { visited.Add(child.Value); if (UniqueModelItemHelper.UniqueRoute(child.Value, target, expected)) { retval.Add(child.Value); } } } } } else { // ModelItemCollection foreach (ModelItem child in collection) { if (null != child && !visited.Contains(child)) { visited.Add(child); if (UniqueModelItemHelper.UniqueRoute(child, target, expected)) { retval.Add(child); } } } } } return(retval); }
internal Connector GetLinkOnCanvas(ModelItem srcFlowElementModelItem, ModelItem destflowElementModelItem, string propertyName) { Connector linkOnCanvas = null; ModelItem shapeModelItem = null; List <Connector> outGoingConnectors = null; if (!srcFlowElementModelItem.Equals(this.ModelItem)) { shapeModelItem = this.GetCorrespondingElementOnCanvas(srcFlowElementModelItem); outGoingConnectors = GetOutGoingConnectors(this.modelElement[shapeModelItem]); } else // Must be startNode { outGoingConnectors = GetOutGoingConnectors(this.StartSymbol); } foreach (Connector connector in outGoingConnectors) { ModelItem connectorDestModelItem = ((VirtualizedContainerService.VirtualizingContainer)FreeFormPanel.GetDestinationConnectionPoint(connector).ParentDesigner).ModelItem; ModelItem connectorDestFlowElementMI = this.GetFlowElementMI(connectorDestModelItem); //Following condition checks if the destination for current connector is equal to the destination passed in. if (destflowElementModelItem != null && destflowElementModelItem.Equals(connectorDestFlowElementMI)) { if (GenericFlowSwitchHelper.IsGenericFlowSwitch(srcFlowElementModelItem.ItemType)) { ModelItem linkModelItem = FlowchartDesigner.GetLinkModelItem(connector); if (linkModelItem.Properties["IsDefaultCase"].Value.GetCurrentValue().Equals(true) && propertyName.Equals("Default")) { linkOnCanvas = connector; break; } else { ModelItem connectorCaseMI = linkModelItem.Properties["Case"].Value; if (linkModelItem.Properties["IsDefaultCase"].Value.GetCurrentValue().Equals(false)) { string caseName = connectorCaseMI == null ? null : GenericFlowSwitchHelper.GetString(connectorCaseMI.GetCurrentValue(), connectorCaseMI.ItemType); if (connectorCaseMI != null && caseName.Equals(propertyName.Substring(GenericFlowSwitchHelper.FlowSwitchCasesKeyIdentifier.Length))) { linkOnCanvas = connector; break; } else if (connectorCaseMI == null) { if (GenericFlowSwitchHelper.FlowSwitchNullCaseKeyIdentifier.Equals(propertyName.Substring(GenericFlowSwitchHelper.FlowSwitchCasesKeyIdentifier.Length))) { linkOnCanvas = connector; break; } } } } } else if (typeof(FlowDecision).IsAssignableFrom(srcFlowElementModelItem.ItemType)) { ConnectionPoint trueConnPoint = FlowchartDesigner.GetTrueConnectionPoint(this.modelElement[shapeModelItem]); ConnectionPoint falseConnPoint = FlowchartDesigner.GetFalseConnectionPoint(this.modelElement[shapeModelItem]); ConnectionPoint connectorSrcConnPoint = FreeFormPanel.GetSourceConnectionPoint(connector); if ((propertyName.Equals("True") && connectorSrcConnPoint.Equals(trueConnPoint)) || (propertyName.Equals("False") && connectorSrcConnPoint.Equals(falseConnPoint))) { linkOnCanvas = connector; break; } } else //FlowStep case. { linkOnCanvas = connector; break; } } } return(linkOnCanvas); }