/// <summary> /// Toggles multiple items in the selection</summary> /// <param name="selectionContext">Selection context</param> /// <param name="items">Items to toggle</param> public static void ToggleRange(this ISelectionContext selectionContext, IEnumerable items) { if (selectionContext == null) { throw new ArgumentNullException("selectionContext"); } if (items == null) { throw new ArgumentNullException("items"); } var toggled = new HashSet <object>(); foreach (object item in items) { toggled.Add(item); } var newSelection = new List <object>(); // keep already selected items that aren't to be toggled foreach (object item in selectionContext.Selection) { if (!toggled.Contains(item)) { newSelection.Add(item); } } // add toggled items that aren't in selection foreach (object item in items) { if (!selectionContext.SelectionContains(item)) { newSelection.Add(item); } } selectionContext.Selection = newSelection; }
protected override IList <object> Pick(MouseEventArgs e) { bool multiSelect = DragOverThreshold; List <object> paths = new List <object>(); Picking.HitRecord[] hits; if (multiSelect) {// frustum pick RectangleF rect = MakeRect(FirstMousePoint, CurrentMousePoint); var frustum = XLEBridgeUtils.Utils.MakeFrustumMatrix(Utils.AsCameraDesc(Camera), rect, ClientSize); hits = Picking.FrustumPick( GameEngine.GetEngineDevice(), Adapter.SceneManager, Adapter.TechniqueContext, frustum, Utils.AsCameraDesc(Camera), ClientSize, Picking.Flags.Objects | Picking.Flags.Helpers); } else {// ray pick Ray3F rayW = GetWorldRay(CurrentMousePoint); hits = Picking.RayPick( GameEngine.GetEngineDevice(), Adapter.SceneManager, Adapter.TechniqueContext, rayW, Utils.AsCameraDesc(Camera), ClientSize, Picking.Flags.Terrain | Picking.Flags.Objects | Picking.Flags.Helpers); } if (hits == null) { return(new List <object>()); } // create unique list of hits HashSet <ulong> instanceSet = new HashSet <ulong>(); var uniqueHits = new List <Picking.HitRecord>(); // build 'path' objects for each hit record. foreach (var hit in hits) { bool added = instanceSet.Add(hit.instanceId); if (added) { uniqueHits.Add(hit); } } var firstHit = new Picking.HitRecord(); // build 'path' objects for each hit record. foreach (var hit in uniqueHits) { var nativeIdMapping = Globals.MEFContainer.GetExportedValue <INativeIdMapping>(); var nobj = nativeIdMapping.GetAdapter(hit.documentId, hit.instanceId).As <DomNodeAdapter>(); if (nobj == null) { continue; } DomNode dom = nobj.DomNode; object hitPath = Util.AdaptDomPath(dom); object obj = DesignView.PickFilter.Filter(hitPath, e); if (obj != null) { if (paths.Count == 0) { firstHit = hit; } var newPath = obj as AdaptablePath <object> ?? Util.AdaptDomPath((DomNode)obj); paths.Add(newPath); } } if (multiSelect == false && paths.Count > 0) { var path = paths[0]; ISelectionContext selection = DesignView.Context.As <ISelectionContext>(); ILinear linear = path.As <ILinear>(); if (linear != null && Control.ModifierKeys == System.Windows.Forms.Keys.Shift && selection.SelectionContains(path)) { ITransactionContext trans = DesignView.Context.As <ITransactionContext>(); trans.DoTransaction( delegate { linear.InsertPoint(firstHit.index, firstHit.hitPt.X, firstHit.hitPt.Y, firstHit.hitPt.Z); }, "insert control point".Localize() ); } } return(paths); }
protected override IList <object> Pick(MouseEventArgs e) { bool multiSelect = DragOverThreshold; List <object> paths = new List <object>(); HitRecord[] hits; if (multiSelect) {// frustum pick RectangleF rect = MakeRect(FirstMousePoint, CurrentMousePoint); hits = GameEngine.FrustumPick(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix, rect); } else {// ray pick Ray3F rayW = GetWorldRay(CurrentMousePoint); hits = GameEngine.RayPick(Camera.ViewMatrix, Camera.ProjectionMatrix, rayW, false); } // create unique list of hits HashSet <ulong> instanceSet = new HashSet <ulong>(); List <HitRecord> uniqueHits = new List <HitRecord>(); // build 'path' objects for each hit record. foreach (HitRecord hit in hits) { bool added = instanceSet.Add(hit.instanceId); if (added) { uniqueHits.Add(hit); } } HitRecord firstHit = new HitRecord(); // build 'path' objects for each hit record. foreach (HitRecord hit in uniqueHits) { NativeObjectAdapter nobj = GameEngine.GetAdapterFromId(hit.instanceId); DomNode dom = nobj.DomNode; object hitPath = Util.AdaptDomPath(dom); object obj = DesignView.PickFilter.Filter(hitPath, e); if (obj != null) { if (paths.Count == 0) { firstHit = hit; } var newPath = obj as AdaptablePath <object> ?? Util.AdaptDomPath((DomNode)obj); paths.Add(newPath); } } if (multiSelect == false && paths.Count > 0) { var path = paths[0]; ISelectionContext selection = DesignView.Context.As <ISelectionContext>(); ILinear linear = path.As <ILinear>(); if (linear != null && Control.ModifierKeys == System.Windows.Forms.Keys.Shift && selection.SelectionContains(path)) { ITransactionContext trans = DesignView.Context.As <ITransactionContext>(); trans.DoTransaction( delegate { linear.InsertPoint(firstHit.index, firstHit.hitPt.X, firstHit.hitPt.Y, firstHit.hitPt.Z); }, "insert control point".Localize() ); } } return(paths); }
private void DrawGroupsAndTracks(TimelinePath path, ITimeline timeline, bool expandedTimeline, ISelectionContext selection, Context c, TimelineLayout layout, RectangleF clipBounds) { RectangleF canvasBounds = clipBounds; //clipBounds minus the left-side header canvasBounds.X = HeaderWidth; canvasBounds.Width -= HeaderWidth; RectangleF bounds; foreach (IGroup group in timeline.Groups) { TimelinePath groupPath = path + group; if (!layout.TryGetBounds(groupPath, out bounds)) continue; if (bounds.IntersectsWith(clipBounds)) { DrawMode drawMode = DrawMode.Normal; if (selection.SelectionContains(groupPath)) drawMode |= DrawMode.Selected; if (expandedTimeline) Draw(group, bounds, drawMode, c); IList<ITrack> tracks = group.Tracks; bool collapsed = !expandedTimeline || (!group.Expanded && tracks.Count > 1); foreach (ITrack track in tracks) { TimelinePath trackPath = path + track; bounds = layout.GetBounds(trackPath); if (bounds.IntersectsWith(clipBounds)) { drawMode = DrawMode.Normal; if (selection.SelectionContains(trackPath)) drawMode |= DrawMode.Selected; if (collapsed) drawMode = DrawMode.Collapsed; Draw(track, bounds, drawMode, c); foreach (IInterval interval in track.Intervals) { TimelinePath intervalPath = path + interval; bounds = layout.GetBounds(intervalPath); if (bounds.IntersectsWith(canvasBounds)) { drawMode = DrawMode.Normal; if (selection.SelectionContains(intervalPath)) drawMode |= DrawMode.Selected; if (collapsed) drawMode = DrawMode.Collapsed; Draw(interval, bounds, drawMode, c); } } foreach (IKey key in track.Keys) { TimelinePath keyPath = path + key; bounds = layout.GetBounds(keyPath); if (bounds.IntersectsWith(canvasBounds)) { drawMode = DrawMode.Normal; if (selection.SelectionContains(keyPath)) drawMode |= DrawMode.Selected; if (collapsed) drawMode = DrawMode.Collapsed; Draw(key, bounds, drawMode, c); } } } } } } }
private void DrawMarkers(TimelinePath path, ITimeline timeline, ISelectionContext selection, Context c, TimelineLayout layout, RectangleF clipBounds) { RectangleF bounds; foreach (IMarker marker in timeline.Markers) { TimelinePath markerPath = path + marker; if (!layout.TryGetBounds(markerPath, out bounds)) continue; if (bounds.IntersectsWith(clipBounds)) { DrawMode drawMode = DrawMode.Normal; if (selection.SelectionContains(markerPath)) drawMode |= DrawMode.Selected; Draw(marker, bounds, drawMode, c); } } }
private void DrawSubTimeline( TimelinePath path, ITimeline timeline, bool subTimeline, bool expandedTimeline, ISelectionContext selection, TimelinePath activeGroup, TimelinePath activeTrack, TimelineLayout layout, Context c) { //if (c.TestRecursion(timeline)) // return; if (!subTimeline) m_offsetX = c.Transform.OffsetX; RectangleF clipBounds = m_graphics.ClipBounds; DrawGroupsAndTracks(path, timeline, expandedTimeline, selection, c, layout, clipBounds); // draw markers over keys, intervals, tracks, and group if (subTimeline) { // Give the Markers in the main timeline precedence; draw on top of everything. clipBounds.X = HeaderWidth; clipBounds.Width -= HeaderWidth; DrawMarkers(path, timeline, selection, c, layout, clipBounds); } // Draw the group and track handles only if the owning timeline is expanded. if (expandedTimeline) { if (m_printing) c.Graphics.TranslateTransform(m_marginBounds.Left, 0); RectangleF bounds; foreach (IGroup group in timeline.Groups) { IList<ITrack> tracks = group.Tracks; TimelinePath groupPath = path + group; bounds = layout.GetBounds(groupPath); bounds = GetGroupHandleRect(bounds, !group.Expanded); RectangleF groupLabelBounds = new RectangleF(bounds.X, bounds.Y, HeaderWidth, bounds.Height); // Draw group's move handle. DrawMoveHandle(bounds, selection.SelectionContains(groupPath), groupPath == activeGroup); // Draw expander? if (tracks.Count > 1) { RectangleF expanderRect = GetExpanderRect(bounds); m_graphics.DrawExpander( expanderRect.X, expanderRect.Y, expanderRect.Width, m_expanderBrush, group.Expanded); groupLabelBounds.X += TrackIndent; groupLabelBounds.Width -= TrackIndent; } // Draw tracks' move handles? if (group.Expanded || tracks.Count == 1) { foreach (ITrack track in tracks) { TimelinePath trackPath = path + track; bounds = layout.GetBounds(trackPath); bounds = GetTrackHandleRect(bounds); DrawMoveHandle(bounds, selection.SelectionContains(trackPath), trackPath == activeTrack); if (bounds.Width > 0f) m_graphics.DrawText(track.Name, m_trackTextFormat, bounds, m_nameBrush); } } // Draw group name. if (groupLabelBounds.Width > 0) m_graphics.DrawText(group.Name, c.TextFormat, groupLabelBounds, m_nameBrush); } if (m_printing) c.Graphics.TranslateTransform(-m_marginBounds.Left, 0); } return; }
private void DrawSubTimeline( TimelinePath path, ISelectionContext selection, TimelinePath activeGroup, TimelinePath activeTrack, TimelineLayout layout, Context c) { // Include the reference's offset into the Transform and InverseTransform properties. Matrix localToWorld = D2dTimelineControl.CalculateLocalToWorld(path); c.PushTransform(localToWorld, MatrixOrder.Prepend); // draw the row that has this timeline reference's name ITimelineReference reference = (ITimelineReference)path.Last; RectangleF clipBounds = m_graphics.ClipBounds; RectangleF bounds = layout.GetBounds(path); IHierarchicalTimeline timeline = reference.Target; if (bounds.IntersectsWith(clipBounds)) { DrawMode drawMode = DrawMode.Normal; if (selection.SelectionContains(path)) drawMode |= DrawMode.Selected; DrawTimelineReference(reference, bounds, drawMode, c); } // draw the timeline document as if it were the main document if (timeline != null) DrawSubTimeline(path, timeline, true, reference.Options.Expanded, selection, activeGroup, activeTrack, layout, c); c.PopTransform(); }
protected override IEnumerable <object> Pick(MouseEventArgs e) { bool multiSelect = DragOverThreshold; Picking.HitRecord[] hits; if (multiSelect) { RectangleF rect = MakeRect(FirstMousePoint, CurrentMousePoint); var frustum = XLEBridgeUtils.Utils.MakeFrustumMatrix(Utils.AsCameraDesc(Camera), rect, ClientSize); hits = Picking.FrustumPick( GameEngine.GetEngineDevice(), Adapter.SceneManager, Adapter.TechniqueContext, frustum, Utils.AsCameraDesc(Camera), ClientSize, Picking.Flags.Objects | Picking.Flags.Helpers); } else { Ray3F rayW = GetWorldRay(CurrentMousePoint); hits = Picking.RayPick( GameEngine.GetEngineDevice(), Adapter.SceneManager, Adapter.TechniqueContext, rayW, Utils.AsCameraDesc(Camera), ClientSize, Picking.Flags.Terrain | Picking.Flags.Objects | Picking.Flags.Helpers); } if (hits == null) { return(new List <object>()); } // create unique list of hits var uniqueHits = new List <DomNode>(); var nativeIdMapping = Globals.MEFContainer.GetExportedValue <INativeIdMapping>(); HashSet <ulong> instanceSet = new HashSet <ulong>(); foreach (var hit in hits) { if (instanceSet.Add(hit.instanceId)) { var nobj = nativeIdMapping.GetAdapter(hit.documentId, hit.instanceId).As <DomNodeAdapter>(); if (nobj != null && nobj.DomNode != null) { uniqueHits.Add(nobj.DomNode); } } } // build 'path' objects for each hit record. var paths = new List <AdaptablePath <object> >(); foreach (var node in uniqueHits) { var hitPath = Util.AdaptDomPath(node); var obj = DesignView.PickFilter.Filter(hitPath, e); if (obj != null) { var path = obj as AdaptablePath <object> ?? Util.AdaptDomPath((DomNode)obj); // Prevent the same object from being added multiple times... if (paths.Where(x => x.Last == path.Last).FirstOrDefault() == null) { paths.Add(path); } } } #if false if (multiSelect == false && paths.Count > 0 && firstHit != null) { var path = paths[0]; ISelectionContext selection = DesignView.Context.As <ISelectionContext>(); ILinear linear = path.As <ILinear>(); if (linear != null && Control.ModifierKeys == System.Windows.Forms.Keys.Shift && selection.SelectionContains(path)) { ITransactionContext trans = DesignView.Context.As <ITransactionContext>(); trans.DoTransaction( delegate { linear.InsertPoint(firstHit.index, firstHit.hitPt.X, firstHit.hitPt.Y, firstHit.hitPt.Z); }, "insert control point".Localize() ); } } #endif return(paths); }