private void RedrawMolecule(Molecule molecule, Rect?boundingBox = null) { if (chemicalVisuals.ContainsKey(molecule)) { var doomed = chemicalVisuals[molecule]; DeleteVisual(doomed); chemicalVisuals.Remove(molecule); } bool showBrackets = molecule.ShowMoleculeBrackets.HasValue && molecule.ShowMoleculeBrackets.Value || molecule.Count.HasValue && molecule.Count.Value > 0 || molecule.FormalCharge.HasValue && molecule.FormalCharge.Value != 0 || molecule.SpinMultiplicity.HasValue && molecule.SpinMultiplicity.Value > 1; var groupKey = molecule.GetGroupKey(); if (chemicalVisuals.ContainsKey(groupKey)) //it's already in the list { var doomed = chemicalVisuals[groupKey]; DeleteVisual(doomed); chemicalVisuals.Remove(groupKey); } var footprint = GetExtents(molecule); if (molecule.IsGrouped && ShowGroups) { //we may be passing in a null bounding box here chemicalVisuals[groupKey] = new GroupVisual(molecule, footprint); var gv = (GroupVisual)chemicalVisuals[groupKey]; gv.ChemicalVisuals = chemicalVisuals; gv.Render(); AddVisual(gv); } if (boundingBox == null) { boundingBox = Rect.Empty; } if (showBrackets) { boundingBox.Value.Union(footprint); var mv = new MoleculeVisual(molecule, footprint); chemicalVisuals[molecule] = mv; mv.Render(); AddVisual(mv); boundingBox.Value.Union(mv.ContentBounds); } }
public Rect GetDrawnBoundingBox(Molecule molecule) { var bb = GetExtents(molecule); foreach (var m in molecule.Molecules.Values) { if (chemicalVisuals.TryGetValue(m.GetGroupKey(), out DrawingVisual molVisual)) { GroupVisual gv = (GroupVisual)molVisual; bb.Union(gv.ContentBounds); bb.Inflate(Spacing, Spacing); } else { bb.Union(GetDrawnBoundingBox(m)); } } return(bb); }
public GroupHoverAdorner(UIElement adornedElement, GroupVisual targetedVisual) : this(adornedElement) { _targetedVisual = targetedVisual; }
VisualSelection model;// = new VisualSelection(); public MainWindow() { InitializeComponent(); GroupVisual host = new GroupVisual(); // 单一图形 Rectangle rect = new Rectangle(new Rect(20, 20, 40, 40), 0, 0); GeomVisual g1 = new GeomVisual(rect); g1.Fill = Brushes.Blue.CloneCurrentValue(); g1.Angle = 20; g1.Origin = new Point(30, 30); host.AddIntoGroup(g1); Rectangle rrr = new Rectangle(new Rect(50, 50, 40, 40), 0, 0); GeomVisual g2 = new GeomVisual(rrr); //g2.Fill = Brushes.Blue.CloneCurrentValue(); g2.Angle = 0; g2.Origin = new Point(50, 50); host.AddIntoGroup(g2); //Rect r1 = g1.ContentBounds; //Rect r2 = g1.DescendantBounds; //r1.Transform(g1.Transform.Value); // 组合图形 GroupVisual group = new GroupVisual(); GeomVisual ga = new GeomVisual( new Rectangle(new Rect(250, 250, 50, 50), 0, 0)); group.AddIntoGroup(ga); GeomVisual gb = new GeomVisual( new Rectangle(new Rect(200, 300, 20, 80), 0, 0)); group.AddIntoGroup(gb); host.AddIntoGroup(group); group.Angle = 30; canvas.DataContext = host; //r1 = group.ContentBounds; //r2 = group.DescendantBounds; //b = g1; //model = new VisualEditViewModel(); model = canvas.VisualSelection; List <GraphicVisual> list = new List <GraphicVisual>() { g1, g2 }; model.AddIntoSelection(list); model.AddIntoSelection(g1); //model.AddIntoSelection(g2); //model.AddIntoSelection(group); Loaded += MainWindow_Loaded; }