public void Paint(IGraphicsContext3D g, Altaxo.Graph.IPaintContext paintContext, bool bForPreview) { //_isStructureInSync = false; _isMeasureInSync = false; // Change: interpret text every time in order to update plot items and \ID if (!_isStructureInSync) { // this.Interpret(g); InterpretText(); _isStructureInSync = true; _isMeasureInSync = false; } using (var fontCache = new FontCache()) { if (!_isMeasureInSync) { // this.MeasureStructure(g, obj); MeasureGlyphs(g, fontCache, paintContext); MeasureBackground(g, _rootNode.SizeX, _rootNode.SizeY, _rootNode.SizeZ); _isMeasureInSync = true; } _cachedSymbolPositions.Clear(); var gs = g.SaveGraphicsState(); var bounds = Bounds; var transformmatrix = Matrix4x3.NewScalingShearingRotationDegreesTranslation( ScaleX, ScaleY, ScaleZ, ShearX, ShearY, ShearZ, RotationX, RotationY, RotationZ, _location.AbsolutePivotPositionX, _location.AbsolutePivotPositionY, _location.AbsolutePivotPositionZ); transformmatrix.TranslatePrepend(bounds.X, bounds.Y, bounds.Z); if (!bForPreview) { TransformGraphics(g); g.TranslateTransform(bounds.X, bounds.Y, bounds.Z); } // first of all paint the background PaintBackground(g); var dc = new DrawContext { FontCache = fontCache, bForPreview = bForPreview, LinkedObject = Altaxo.Main.AbsoluteDocumentPath.GetRootNodeImplementing <HostLayer>(this), transformMatrix = transformmatrix, _cachedSymbolPositions = _cachedSymbolPositions }; DrawGlyphs(g, dc, _cachedTextOffset.X, _cachedTextOffset.Y, _cachedTextOffset.Z); g.RestoreGraphicsState(gs); } }
/// <summary> /// Transforms the graphics context is such a way, that the object can be drawn in local coordinates. /// </summary> /// <param name="g">Graphics context (should be saved beforehand).</param> protected virtual void TransformGraphics(IGraphicsContext3D g) { if (RotationX != 0 || RotationY != 0 || RotationZ != 0 || ScaleX != 1 || ScaleY != 1 || ScaleZ != 1 || ShearX != 0 || ShearY != 0 || ShearZ != 0) { g.PrependTransform(Matrix4x3.NewScalingShearingRotationDegreesTranslation( _location.ScaleX, _location.ScaleY, _location.ScaleY , _location.ShearX, _location.ShearY, _location.ShearZ, _location.RotationX, _location.RotationY, _location.RotationZ, _location.AbsolutePivotPosition.X, _location.AbsolutePivotPositionY, _location.AbsolutePivotPositionZ)); } else { var p = _location.AbsolutePivotPosition; g.TranslateTransform(p.X, p.Y, p.Z); } }
public RectangleD3D PaintSymbol(IGraphicsContext3D g, RectangleD3D bounds) { if (IsVisible) { var gs = g.SaveGraphicsState(); g.TranslateTransform((VectorD3D)bounds.Center); var halfwidth = bounds.SizeX / 2; var symsize = _symbolSize; if (_useSymbolGap) { // plot a line with the length of symbolsize from PaintLine(g, new PointD3D(-halfwidth, 0, 0), new PointD3D(-symsize, 0, 0)); PaintLine(g, new PointD3D(symsize, 0, 0), new PointD3D(halfwidth, 0, 0)); } else // no gap { PaintLine(g, new PointD3D(-halfwidth, 0, 0), new PointD3D(halfwidth, 0, 0)); } g.RestoreGraphicsState(gs); } return(bounds); }
public void Paint(IGraphicsContext3D g, Altaxo.Graph.IPaintContext paintContext, bool bForPreview) { //_isStructureInSync = false; _isMeasureInSync = false; // Change: interpret text every time in order to update plot items and \ID if (!this._isStructureInSync) { // this.Interpret(g); this.InterpretText(); _isStructureInSync = true; _isMeasureInSync = false; } using (FontCache fontCache = new FontCache()) { if (!this._isMeasureInSync) { // this.MeasureStructure(g, obj); this.MeasureGlyphs(g, fontCache, paintContext); MeasureBackground(g, _rootNode.SizeX, _rootNode.SizeY, _rootNode.SizeZ); _isMeasureInSync = true; } _cachedSymbolPositions.Clear(); var gs = g.SaveGraphicsState(); var bounds = Bounds; var transformmatrix = Matrix4x3.NewScalingShearingRotationDegreesTranslation( ScaleX, ScaleY, ScaleZ, ShearX, ShearY, ShearZ, RotationX, RotationY, RotationZ, _location.AbsolutePivotPositionX, _location.AbsolutePivotPositionY, _location.AbsolutePivotPositionZ); transformmatrix.TranslatePrepend(bounds.X, bounds.Y, bounds.Z); if (!bForPreview) { TransformGraphics(g); g.TranslateTransform(bounds.X, bounds.Y, bounds.Z); } // first of all paint the background PaintBackground(g); DrawContext dc = new DrawContext(); dc.FontCache = fontCache; dc.bForPreview = bForPreview; dc.LinkedObject = Altaxo.Main.AbsoluteDocumentPath.GetRootNodeImplementing<HostLayer>(this); dc.transformMatrix = transformmatrix; dc._cachedSymbolPositions = _cachedSymbolPositions; DrawGlyphs(g, dc, _cachedTextOffset.X, _cachedTextOffset.Y, _cachedTextOffset.Z); g.RestoreGraphicsState(gs); } }
public void Paint(IGraphicsContext3D g, IPlotArea layer, Processed3DPlotData pdata, Processed3DPlotData prevItemData, Processed3DPlotData nextItemData) { if (this._labelColumnProxy.Document == null) return; if (null != _attachedPlane) _attachedPlane = layer.UpdateCSPlaneID(_attachedPlane); PlotRangeList rangeList = pdata.RangeList; var ptArray = pdata.PlotPointsInAbsoluteLayerCoordinates; Altaxo.Data.IReadableColumn labelColumn = this._labelColumnProxy.Document; bool isUsingVariableColorForLabelText = null != _cachedColorForIndexFunction && IsColorReceiver; bool isUsingVariableColorForLabelBackground = null != _cachedColorForIndexFunction && (null != _backgroundStyle && _backgroundStyle.SupportsUserDefinedMaterial && (_backgroundColorLinkage == ColorLinkage.Dependent || _backgroundColorLinkage == ColorLinkage.PreserveAlpha)); bool isUsingVariableColor = isUsingVariableColorForLabelText || isUsingVariableColorForLabelBackground; IMaterial clonedTextBrush = _material; IMaterial clonedBackBrush = null; if (isUsingVariableColorForLabelBackground) clonedBackBrush = _backgroundStyle.Material; // save the graphics stat since we have to translate the origin var gs = g.SaveGraphicsState(); double xpos = 0, ypos = 0, zpos = 0; double xpre, ypre, zpre; double xdiff, ydiff, zdiff; bool isFormatStringContainingBraces = _labelFormatString?.IndexOf('{') >= 0; var culture = System.Threading.Thread.CurrentThread.CurrentCulture; bool mustUseLogicalCoordinates = null != this._attachedPlane || 0 != _cachedLogicalShiftX || 0 != _cachedLogicalShiftY || 0 != _cachedLogicalShiftZ; for (int r = 0; r < rangeList.Count; r++) { int lower = rangeList[r].LowerBound; int upper = rangeList[r].UpperBound; int offset = rangeList[r].OffsetToOriginal; for (int j = lower; j < upper; j += _skipFrequency) { string label; if (string.IsNullOrEmpty(_labelFormatString)) { label = labelColumn[j + offset].ToString(); } else if (!isFormatStringContainingBraces) { label = labelColumn[j + offset].ToString(_labelFormatString, culture); } else { // the label format string can contain {0} for the label column item, {1} for the row index, {2} .. {4} for the x, y and z component of the data point label = string.Format(_labelFormatString, labelColumn[j + offset], j + offset, pdata.GetPhysical(0, j + offset), pdata.GetPhysical(1, j + offset), pdata.GetPhysical(2, j + offset)); } if (string.IsNullOrEmpty(label)) continue; double localSymbolSize = _symbolSize; if (null != _cachedSymbolSizeForIndexFunction) { localSymbolSize = _cachedSymbolSizeForIndexFunction(j + offset); } double localFontSize = _fontSizeOffset + _fontSizeFactor * localSymbolSize; if (!(localFontSize > 0)) continue; _font = _font.WithSize(localFontSize); // Start of preparation of brushes, if a variable color is used if (isUsingVariableColor) { var c = _cachedColorForIndexFunction(j + offset); if (isUsingVariableColorForLabelText) { clonedTextBrush = clonedTextBrush.WithColor(new NamedColor(AxoColor.FromArgb(c.A, c.R, c.G, c.B), "e")); } if (isUsingVariableColorForLabelBackground) { if (_backgroundColorLinkage == ColorLinkage.PreserveAlpha) clonedBackBrush = clonedBackBrush.WithColor(new NamedColor(AxoColor.FromArgb(clonedBackBrush.Color.Color.A, c.R, c.G, c.B), "e")); else clonedBackBrush = clonedBackBrush.WithColor(new NamedColor(AxoColor.FromArgb(c.A, c.R, c.G, c.B), "e")); } } // end of preparation of brushes for variable colors if (mustUseLogicalCoordinates) // we must use logical coordinates because either there is a shift of logical coordinates, or an attached plane { Logical3D r3d = layer.GetLogical3D(pdata, j + offset); r3d.RX += _cachedLogicalShiftX; r3d.RY += _cachedLogicalShiftY; r3d.RZ += _cachedLogicalShiftZ; if (null != this._attachedPlane) { var pp = layer.CoordinateSystem.GetPointOnPlane(this._attachedPlane, r3d); xpre = pp.X; ypre = pp.Y; zpre = pp.Z; } else { PointD3D pt; layer.CoordinateSystem.LogicalToLayerCoordinates(r3d, out pt); xpre = pt.X; ypre = pt.Y; zpre = pt.Z; } } else // no shifting, thus we can use layer coordinates { xpre = ptArray[j].X; ypre = ptArray[j].Y; zpre = ptArray[j].Z; } xdiff = xpre - xpos; ydiff = ypre - ypos; zdiff = zpre - zpos; xpos = xpre; ypos = ypre; zpos = zpre; g.TranslateTransform(xdiff, ydiff, zdiff); g.RotateTransform(_rotationX, _rotationY, _rotationZ); this.Paint(g, label, localSymbolSize, clonedTextBrush, clonedBackBrush); g.RotateTransform(-_rotationX, -_rotationY, -_rotationZ); } // end for } g.RestoreGraphicsState(gs); // Restore the graphics state }
public RectangleD3D PaintSymbol(IGraphicsContext3D g, RectangleD3D bounds) { if (IsVisible) { var gs = g.SaveGraphicsState(); g.TranslateTransform((VectorD3D)bounds.Center); var halfwidth = bounds.SizeX / 2; var symsize = _symbolSize; if (_useSymbolGap) { // plot a line with the length of symbolsize from PaintLine(g, new PointD3D(-halfwidth, 0, 0), new PointD3D(-symsize, 0, 0)); PaintLine(g, new PointD3D(symsize, 0, 0), new PointD3D(halfwidth, 0, 0)); } else // no gap { PaintLine(g, new PointD3D(-halfwidth, 0, 0), new PointD3D(halfwidth, 0, 0)); } g.RestoreGraphicsState(gs); } return bounds; }