//-------------------------------------------------------------------------------------------------- public override bool Start() { if (_TargetShape != _TargetBody?.Shape) { _OverriddenVisualShape = WorkspaceController.VisualShapes.GetVisualShape(_TargetBody); if (_OverriddenVisualShape != null) { _OverriddenVisualShape.OverrideBrep = _TargetShape.GetTransformedBRep(); WorkspaceController.Invalidate(); } } var toolAction = new SelectSubshapeAction(this, SubshapeTypeHelper.GetTypes(_SubshapeType), _TargetBody, _SelectionFilter); if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Finished += _OnActionFinished; StatusText = _StatusText; switch (_SubshapeType) { case SubshapeType.Vertex: WorkspaceController.HudManager?.SetCursor(Cursors.SelectVertex); break; case SubshapeType.Edge: WorkspaceController.HudManager?.SetCursor(Cursors.SelectEdge); break; case SubshapeType.Wire: WorkspaceController.HudManager?.SetCursor(Cursors.SelectWire); break; case SubshapeType.Face: WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace); break; } return(true); }
//-------------------------------------------------------------------------------------------------- protected void AddNamedSubshape(string name, TopoDS_Shape shape, int index) { var newItem = new NamedSubshape() { Type = SubshapeTypeHelper.GetType(shape), Name = name, Index = index, Shape = shape }; // Update shape if type/name/index already exists var sameIndex = _NamedSubshapes.FindIndex(ns => ns.Name == newItem.Name && ns.Index == newItem.Index && ns.Type == newItem.Type); if (sameIndex >= 0) { _NamedSubshapes[sameIndex] = newItem; } else { _NamedSubshapes.Add(newItem); } }
//-------------------------------------------------------------------------------------------------- public virtual SubshapeReference GetSubshapeReference(TopoDS_Shape ocSubshape) { EnsureHistory(); var type = SubshapeTypeHelper.GetType(ocSubshape); // Is this a named subshape? var namedSubshapeIndex = _NamedSubshapes.FindIndex(ns => ns.Shape.IsSame(ocSubshape)); if (namedSubshapeIndex >= 0) { return(new SubshapeReference(type, Guid, _NamedSubshapes[namedSubshapeIndex].Name, _NamedSubshapes[namedSubshapeIndex].Index)); } // Search in shape var ocShape = GetBRep(); if (ocShape == null) { return(null); } switch (type) { case SubshapeType.Edge: return(__FindReferenceInList(ocShape.Edges())); case SubshapeType.Face: return(__FindReferenceInList(ocShape.Faces())); case SubshapeType.Vertex: return(__FindReferenceInList(ocShape.Vertices())); default: throw new NotImplementedException(); } //---- SubshapeReference __FindReferenceInList(IList shapes) { TopoDS_Shape shape = null; var sameShapes = shapes.Cast <TopoDS_Shape>().Where(e => e.IsSame(ocSubshape)).ToArray(); if (sameShapes.Length == 1) { shape = sameShapes[0]; } else if (sameShapes.Length > 1) { // Found more than one candidate. // This can be the case when two subshapes are generated by using the same underlaying TShape // The only way to diffentiate is to check the (localSpace!) location, this can be done // using the hash code var referenceHash = ocSubshape.HashCode(int.MaxValue); shape = sameShapes.FirstOrDefault(e => e.HashCode(int.MaxValue) == referenceHash); } if (shape != null) { return(new SubshapeReference(type, Guid, shapes.IndexOf(shape))); } return(null); } }