Esempio n. 1
0
 public LineShape(PointD2D startPosition, PointD2D endPosition, Altaxo.Main.Properties.IReadOnlyPropertyBag context)
     :
     this(startPosition, context)
 {
     _location.SizeX = RADouble.NewAbs(endPosition.X - startPosition.X);
     _location.SizeY = RADouble.NewAbs(endPosition.Y - startPosition.Y);
 }
        public override bool Apply(bool disposeController)
        {
            _doc.XPartitioning.Clear();
            _doc.YPartitioning.Clear();

            foreach (var val in _columnCollection)
            {
                if (object.ReferenceEquals(val.Unit, _percentLayerXSizeUnit))
                {
                    _doc.XPartitioning.Add(RADouble.NewRel(val.Value / 100));
                }
                else
                {
                    _doc.XPartitioning.Add(RADouble.NewAbs(val.AsValueIn(AUL.Point.Instance)));
                }
            }

            foreach (var val in _rowCollection)
            {
                if (object.ReferenceEquals(val.Unit, _percentLayerYSizeUnit))
                {
                    _doc.YPartitioning.Add(RADouble.NewRel(val.Value / 100));
                }
                else
                {
                    _doc.YPartitioning.Add(RADouble.NewAbs(val.AsValueIn(AUL.Point.Instance)));
                }
            }

            return(ApplyEnd(true, disposeController));
        }
Esempio n. 3
0
        protected virtual void InternalSetAbsoluteSizeSilent(PointD2D value)
        {
            RADouble sizeX, sizeY;

            if (_sizeX.IsAbsolute)
            {
                sizeX = RADouble.NewAbs(value.X);
            }
            else if (_parentSize.X != 0 && !double.IsNaN(_parentSize.X))
            {
                sizeX = RADouble.NewRel(value.X / _parentSize.X);
            }
            else
            {
                throw new InvalidOperationException("_parentSize.X is undefined or zero");
            }

            if (_sizeY.IsAbsolute)
            {
                sizeY = RADouble.NewAbs(value.Y);
            }
            else if (_parentSize.Y != 0 && !double.IsNaN(_parentSize.Y))
            {
                sizeY = RADouble.NewRel(value.Y / _parentSize.Y);
            }
            else
            {
                throw new InvalidOperationException("_parentSize.Y is undefined or zero");
            }

            InternalSetSizeSilent(sizeX, sizeY);
        }
Esempio n. 4
0
 public LineShape(PointD3D startPosition, PointD3D endPosition, double lineWidth, NamedColor lineColor)
     :
     this(startPosition, null)
 {
     _location.SizeX = RADouble.NewAbs(endPosition.X - startPosition.X);
     _location.SizeY = RADouble.NewAbs(endPosition.Y - startPosition.Y);
     _location.SizeZ = RADouble.NewAbs(endPosition.Z - startPosition.Z);
     _linePen        = _linePen.WithUniformThickness(lineWidth).WithColor(lineColor);
 }
Esempio n. 5
0
 public LineShape(PointD2D startPosition, PointD2D endPosition, double lineWidth, NamedColor lineColor)
     :
     this(startPosition, null)
 {
     _location.SizeX = RADouble.NewAbs(endPosition.X - startPosition.X);
     _location.SizeY = RADouble.NewAbs(endPosition.Y - startPosition.Y);
     Pen.Width       = (float)lineWidth;
     Pen.Color       = lineColor;
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a empty GraphDocument with no layers and a standard size of A4 landscape.
 /// </summary>
 public GraphDocument()
 {
     RootLayer = new HostLayer()
     {
         ParentObject = this
     };
     RootLayer.Location = new ItemLocationDirect {
         SizeX = RADouble.NewAbs(DefaultRootLayerSizeX), SizeY = RADouble.NewAbs(DefaultRootLayerSizeY)
     };
 }
Esempio n. 7
0
 public void ChangeRelativeSizeValuesToAbsoluteSizeValues()
 {
     if (_sizeX.IsRelative)
     {
         _sizeX = RADouble.NewAbs(AbsoluteSizeX);
     }
     if (_sizeY.IsRelative)
     {
         _sizeY = RADouble.NewAbs(AbsoluteSizeY);
     }
 }
Esempio n. 8
0
 public void ChangeRelativePositionValuesToAbsolutePositionValues()
 {
     if (_positionX.IsRelative)
     {
         _positionX = RADouble.NewAbs(AbsolutePositionX);
     }
     if (_positionY.IsRelative)
     {
         _positionY = RADouble.NewAbs(AbsolutePositionY);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// If the <see cref="IsAutoSized"/> property is <c>true</c> for this instance, the graphical object has to use this function to indicate its size.
        /// </summary>
        /// <param name="autoSize">Size of the graphical object.</param>
        /// <param name="isChangeEventEnabled">If true, the Change event will be fired if the size has changed.</param>
        /// <exception cref="System.InvalidOperationException">Using SetAutoSize is not supported because IsAutoSized is false</exception>
        public void SetSizeInAutoSizeMode(PointD2D autoSize, bool isChangeEventEnabled)
        {
            if (_sizeX.IsRelative || _sizeY.IsRelative || _sizeX.Value != autoSize.X || _sizeY.Value != autoSize.Y)
            {
                _sizeX = RADouble.NewAbs(autoSize.X);
                _sizeY = RADouble.NewAbs(autoSize.Y);

                if (isChangeEventEnabled)
                {
                    EhSelfChanged();
                }
            }
        }
Esempio n. 10
0
        public GraphDocument(GraphDocument from)
        {
            using (var suppressToken = SuspendGetToken())
            {
                _creationTime = _lastChangeTime = DateTime.UtcNow;
                RootLayer     = new HostLayer(null, new ItemLocationDirect {
                    SizeX = RADouble.NewAbs(814), SizeY = RADouble.NewAbs(567)
                });

                CopyFrom(from, GraphCopyOptions.All);

                suppressToken.ResumeSilently();
            }
        }
Esempio n. 11
0
 protected virtual void InternalSetAbsoluteSizeYSilent(double value)
 {
     if (_sizeY.IsAbsolute)
     {
         InternalSetSizeYSilent(RADouble.NewAbs(value));
     }
     else if (_parentSize.Y != 0 && !double.IsNaN(_parentSize.Y))
     {
         InternalSetSizeYSilent(RADouble.NewRel(value / _parentSize.Y));
     }
     else
     {
         throw new InvalidOperationException("_parentSize.Y is undefined or zero");
     }
 }
Esempio n. 12
0
        private void EhNumericPivotYChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var quant = _guiPivotY.SelectedQuantity;

            if (object.ReferenceEquals(quant.Unit, _percentLayerYSizeUnit))
            {
                _pivotY = RADouble.NewRel(quant.Value / 100);
            }
            else
            {
                _pivotY = RADouble.NewAbs(quant.AsValueIn(AUL.Point.Instance));
            }

            SetVisibilityOfSwitchButton();
        }
 /// <summary>
 /// Internal set absolute size y silent. This function is allowed to set <see cref="ItemLocationDirect._sizeY"/> directly. This is the reason why it is declared as private.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <exception cref="System.InvalidOperationException">_parentSize.Y is undefined or zero</exception>
 private void InternalSetAbsoluteSizeYSilentHere(double value)
 {
     if (_sizeY.IsAbsolute)
     {
         _sizeY = RADouble.NewAbs(value);
     }
     else if (_parentSize.Y != 0 && !double.IsNaN(_parentSize.Y))
     {
         _sizeY = RADouble.NewRel(value / _parentSize.Y);
     }
     else
     {
         throw new InvalidOperationException("_parentSize.Y is undefined or zero");
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Creates a empty GraphDocument with no layers and a standard size of A4 landscape.
 /// </summary>
 public GraphDocument()
 {
     _camera   = new Camera.OrthographicCamera();
     _lighting = new LightSettings();
     RootLayer = new HostLayer()
     {
         ParentObject = this
     };
     RootLayer.Location = new ItemLocationDirect
     {
         SizeX = RADouble.NewAbs(DefaultRootLayerSizeX),
         SizeY = RADouble.NewAbs(DefaultRootLayerSizeY),
         SizeZ = RADouble.NewAbs(DefaultRootLayerSizeZ)
     };
 }
Esempio n. 15
0
        private void InternalSetAbsolutePositionXSilent(double value)
        {
            var mySizeX = _sizeX.GetValueRelativeTo(_parentSize.X);

            if (_positionX.IsAbsolute)
            {
                _positionX = RADouble.NewAbs(value - _parentAnchorX.GetValueRelativeTo(_parentSize.X) + _localAnchorX.GetValueRelativeTo(mySizeX));
            }
            else if (0 != _parentSize.X && _parentSize.X.IsFinite())
            {
                _positionX = RADouble.NewRel((value - _parentAnchorX.GetValueRelativeTo(_parentSize.X) + _localAnchorX.GetValueRelativeTo(mySizeX)) / _parentSize.X);
            }
            else
            {
                throw new InvalidOperationException("_parentSize.X is undefined or zero");
            }
        }
Esempio n. 16
0
        private void InternalSetAbsolutePivotPositionYSilent(double value)
        {
            var mySizeY = _sizeY.GetValueRelativeTo(_parentSize.Y);

            if (_positionY.IsAbsolute)
            {
                _positionY = RADouble.NewAbs(value - _parentAnchorY.GetValueRelativeTo(_parentSize.Y));
            }
            else if (0 != _parentSize.Y && _parentSize.Y.IsFinite())
            {
                _positionY = RADouble.NewRel((value - _parentAnchorY.GetValueRelativeTo(_parentSize.Y)) / _parentSize.Y);
            }
            else
            {
                throw new InvalidOperationException("_parentSize.Y is undefined or zero");
            }
        }
Esempio n. 17
0
            public virtual void Deserialize(GraphDocument s, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                //  info.GetBaseValueEmbedded(s,typeof(GraphDocument).BaseType,parent);
                s._name = info.GetString("Name");
                var pageBounds      = (RectangleF)info.GetValue("PageBounds", s);
                var printableBounds = (RectangleF)info.GetValue("PrintableBounds", s);

#pragma warning disable CS0618 // Type or member is obsolete
                var layers = (XYPlotLayer.XYPlotLayerCollection)info.GetValue("LayerList", s);
#pragma warning restore CS0618 // Type or member is obsolete
                if (layers.GraphSize.IsEmpty)
                {
                    s._rootLayer.Location = new ItemLocationDirect {
                        SizeX = RADouble.NewAbs(printableBounds.Size.Width), SizeY = RADouble.NewAbs(printableBounds.Size.Height)
                    }
                }
                ;
                else
                {
                    s._rootLayer.Location = new ItemLocationDirect {
                        SizeX = RADouble.NewAbs(layers.GraphSize.Width), SizeY = RADouble.NewAbs(layers.GraphSize.Height)
                    }
                };

                foreach (var l in layers)
                {
                    s._rootLayer.Layers.Add(l);
                }

                // new in version 1 - Add graph properties
                int numberproperties = info.OpenArray(); // "GraphProperties"
                var pb = numberproperties == 0 ? null : s.PropertyBagNotNull;
                for (int i = 0; i < numberproperties; i++)
                {
                    info.OpenElement(); // "e"
                    string propkey = info.GetString("Key");
                    object propval = info.GetValue("Value", s.PropertyBagNotNull);
                    info.CloseElement(); // "e"
                    pb.SetValue(propkey, propval);
                }
                info.CloseArray(numberproperties);
            }
        }
Esempio n. 18
0
        public static CurlyBraceShape FromLTRB(double left, double top, double right, double bottom, Altaxo.Main.Properties.IReadOnlyPropertyBag context)
        {
            if (left > right)
            {
                Exchange(ref left, ref right);
            }
            if (top > bottom)
            {
                Exchange(ref top, ref bottom);
            }

            var result = new CurlyBraceShape(context);

            result._location.SizeX     = RADouble.NewAbs(right - left);
            result._location.SizeY     = RADouble.NewAbs(bottom - top);
            result._location.PositionX = RADouble.NewAbs(left);
            result._location.PositionY = RADouble.NewAbs(top);
            return(result);
        }
        private void EhSizeYChanged()
        {
            var actn = SizeYChanged;

            if (null != actn)
            {
                RADouble result;
                var      ySize = _view.YSize;

                if (object.ReferenceEquals(ySize.Unit, _percentLayerYSizeUnit))
                {
                    result = RADouble.NewRel(ySize.Value / 100);
                }
                else
                {
                    result = RADouble.NewAbs(ySize.AsValueIn(AUL.Point.Instance));
                }
                actn(result);
            }
        }
Esempio n. 20
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                GraphDocument s = null != o ? (GraphDocument)o : new GraphDocument();

                //  info.GetBaseValueEmbedded(s,typeof(GraphDocument).BaseType,parent);
                s._name = info.GetString("Name");
                var pageBounds      = (RectangleF)info.GetValue("PageBounds", s);
                var printableBounds = (RectangleF)info.GetValue("PrintableBounds", s);

#pragma warning disable CS0618 // Type or member is obsolete
                var layers = (XYPlotLayer.XYPlotLayerCollection)info.GetValue("LayerList", s);
#pragma warning restore CS0618 // Type or member is obsolete
                s._rootLayer.Location = new ItemLocationDirect {
                    SizeX = RADouble.NewAbs(printableBounds.Size.Width), SizeY = RADouble.NewAbs(printableBounds.Size.Height)
                };
                foreach (var l in layers)
                {
                    s._rootLayer.Layers.Add(l);
                }
                return(s);
            }
Esempio n. 21
0
        protected void PaintOneRange(Graphics g, IPlotArea layer, IPlotRange range, Processed2DPlotData pdata)
        {
            const double logicalClampMinimum = -10;
            const double logicalClampMaximum = 11;

            // Plot error bars for the dependent variable (y)
            var columnX = ColumnX;
            var columnY = ColumnY;

            if (columnX == null || columnY == null)
            {
                return; // nothing to do if both error columns are null
            }
            if (!typeof(double).IsAssignableFrom(columnX.ItemType) || !typeof(double).IsAssignableFrom(columnY.ItemType))
            {
                return; // TODO make this an runtime paint error to be reported
            }
            var strokePen = _strokePen.Clone();

            using (var isoLine = new GraphicsPath())
            {
                int lower = range.LowerBound;
                int upper = range.UpperBound;

                for (int j = lower; j < upper; j += _skipFrequency)
                {
                    int    originalRowIndex = range.GetOriginalRowIndexFromPlotPointIndex(j);
                    double symbolSize       = null == _cachedSymbolSizeForIndexFunction ? _symbolSize : _cachedSymbolSizeForIndexFunction(originalRowIndex);

                    strokePen.Width = (_lineWidth1Offset + _lineWidth1Factor * symbolSize);

                    if (null != _cachedColorForIndexFunction)
                    {
                        strokePen.Color = GdiColorHelper.ToNamedColor(_cachedColorForIndexFunction(originalRowIndex), "VariableColor");
                    }

                    if (!(strokePen.EndCap is LineCaps.FlatCap))
                    {
                        strokePen.EndCap = strokePen.EndCap.WithMinimumAbsoluteAndRelativeSize(symbolSize * _endCapSizeFactor + _endCapSizeOffset, 1 + 1E-6);
                    }

                    // Calculate target
                    AltaxoVariant targetX, targetY;
                    switch (_meaningOfValues)
                    {
                    case ValueInterpretation.AbsoluteDifference:
                    {
                        targetX = pdata.GetXPhysical(originalRowIndex) + columnX[originalRowIndex];
                        targetY = pdata.GetYPhysical(originalRowIndex) + columnY[originalRowIndex];
                    }
                    break;

                    case ValueInterpretation.AbsoluteValue:
                    {
                        targetX = columnX[originalRowIndex];
                        targetY = columnY[originalRowIndex];
                    }
                    break;

                    default:
                        throw new NotImplementedException(nameof(_meaningOfValues));
                    }

                    var logicalTarget = layer.GetLogical3D(targetX, targetY);
                    var logicalOrigin = layer.GetLogical3D(pdata, originalRowIndex);

                    if (!_independentOnShiftingGroupStyles && (0 != _cachedLogicalShiftX || 0 != _cachedLogicalShiftY))
                    {
                        logicalOrigin.RX += _cachedLogicalShiftX;
                        logicalOrigin.RY += _cachedLogicalShiftY;
                        logicalTarget.RX += _cachedLogicalShiftX;
                        logicalTarget.RY += _cachedLogicalShiftY;
                    }

                    if (!Calc.RMath.IsInIntervalCC(logicalOrigin.RX, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }
                    if (!Calc.RMath.IsInIntervalCC(logicalOrigin.RY, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }
                    if (!Calc.RMath.IsInIntervalCC(logicalOrigin.RZ, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }

                    if (!Calc.RMath.IsInIntervalCC(logicalTarget.RX, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }
                    if (!Calc.RMath.IsInIntervalCC(logicalTarget.RY, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }
                    if (!Calc.RMath.IsInIntervalCC(logicalTarget.RZ, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }

                    isoLine.Reset();

                    layer.CoordinateSystem.GetIsoline(isoLine, logicalOrigin, logicalTarget);
                    if (null == isoLine)
                    {
                        continue;
                    }

                    PointF[] isoLinePathPoints = null;

                    if (_useManualVectorLength)
                    {
                        isoLine.Flatten();
                        isoLinePathPoints = isoLine.PathPoints;

                        double length        = _vectorLengthOffset + _vectorLengthFactor * symbolSize;
                        double isoLineLength = isoLinePathPoints.TotalLineLength();
                        isoLinePathPoints = isoLinePathPoints.ShortenedBy(RADouble.NewAbs(0), RADouble.NewAbs(isoLineLength - length));
                        if (null == isoLine)
                        {
                            continue;
                        }
                    }

                    if (_useSymbolGap)
                    {
                        if (null == isoLinePathPoints)
                        {
                            isoLine.Flatten();
                            isoLinePathPoints = isoLine.PathPoints;
                        }

                        double gap = _symbolGapOffset + _symbolGapFactor * symbolSize;
                        if (gap != 0)
                        {
                            isoLinePathPoints = isoLinePathPoints.ShortenedBy(RADouble.NewAbs(gap / 2), RADouble.NewAbs(0));
                            if (null == isoLine)
                            {
                                continue;
                            }
                        }
                    }

                    if (null != isoLinePathPoints)
                    {
                        g.DrawLines(_strokePen, isoLinePathPoints);
                    }
                    else
                    {
                        g.DrawPath(strokePen, isoLine);
                    }
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Template to make a line draw.
        /// </summary>
        /// <param name="g">Graphics context.</param>
        /// <param name="pdata">The plot data. Don't use the Range property of the pdata, since it is overriden by the next argument.</param>
        /// <param name="range">The plot range to use.</param>
        /// <param name="layer">Graphics layer.</param>
        /// <param name="pen">The pen to draw the line.</param>
        /// <param name="symbolGap">The size of the symbol gap. Argument is the original index of the data. The return value is the absolute symbol gap at this index. This function is null if no symbol gap is required.</param>
        /// <param name="skipFrequency">Skip frequency. Normally 1, thus all gaps are taken into account. If 2, only every 2nd gap is taken into account, and so on.</param>
        /// <param name="connectCircular">If true, the end of the line is connected with the start of the line.</param>
        public override void Paint(
            IGraphicsContext3D g,
            Processed3DPlotData pdata,
            PlotRange range,
            IPlotArea layer,
            PenX3D pen,
            Func <int, double> symbolGap,
            int skipFrequency,
            bool connectCircular)
        {
            var linePoints = pdata.PlotPointsInAbsoluteLayerCoordinates;
            var linepts    = new PointD3D[range.Length + (connectCircular ? 1 : 0)];

            Array.Copy(linePoints, range.LowerBound, linepts, 0, range.Length); // Extract
            if (connectCircular)
            {
                linepts[linepts.Length - 1] = linepts[0];
            }
            int lastIdx   = range.Length - 1 + (connectCircular ? 1 : 0);
            var layerSize = layer.Size;

            if (symbolGap != null)
            {
                if (skipFrequency <= 1) // skip all scatter symbol gaps -> thus skipOffset can be ignored
                {
                    for (int i = 0; i < lastIdx; i++)
                    {
                        int    originalIndex = range.OffsetToOriginal + i;
                        var    diff          = linepts[i + 1] - linepts[i];
                        double gapAtStart    = symbolGap(originalIndex);
                        double gapAtEnd      = i != (range.Length - 1) ? symbolGap(originalIndex + 1) : symbolGap(range.OffsetToOriginal);
                        var    relAtStart    = 0.5 * gapAtStart / diff.Length; // 0.5 because symbolGap is the full gap between two lines, thus between the symbol center and the beginning of the line it is only 1/2
                        var    relAtEnd      = 0.5 * gapAtEnd / diff.Length;   // 0.5 because symbolGap is the full gap between two lines, thus between the symbol center and the beginning of the line it is only 1/2
                        if ((relAtStart + relAtEnd) < 1)                       // a line only appears if sum of the gaps  is smaller than 1
                        {
                            var start = linepts[i] + relAtStart * diff;
                            var stop  = linepts[i + 1] - relAtEnd * diff;

                            g.DrawLine(pen, start, stop);
                        }
                    } // end for
                }     // skipFrequency was 1
                else  // skipFrequency is > 1
                {
                    for (int i = 0; i < lastIdx; i += skipFrequency)
                    {
                        int originalRowIndex = range.OriginalFirstPoint + i;

                        double gapAtStart = symbolGap(originalRowIndex);
                        double gapAtEnd   = i != range.Length ? symbolGap(originalRowIndex + skipFrequency) : symbolGap(range.OffsetToOriginal);

                        IPolylineD3D polyline = SharpPolylineD3D.FromPointsWithPossibleDublettes(linepts.Skip(i).Take(1 + skipFrequency));
                        polyline = polyline.ShortenedBy(RADouble.NewAbs(gapAtStart / 2), RADouble.NewAbs(gapAtEnd / 2));

                        if (null != polyline)
                        {
                            g.DrawLine(pen, polyline);
                        }
                    } // end for.
                }
            }
            else // no line symbol gap required, so we can use DrawLines to draw the lines
            {
                if (linepts.Length > 1) // we don't want to have a drawing exception if number of points is only one
                {
                    g.DrawLine(pen, SharpPolylineD3D.FromPointsWithPossibleDublettes(linepts));
                }
            }
        }
Esempio n. 23
0
        public void Paint(IGraphicsContext3D g, IPlotArea layer, Processed3DPlotData pdata, Processed3DPlotData prevItemData, Processed3DPlotData nextItemData)
        {
            PlotRangeList rangeList = pdata.RangeList;
            var           ptArray   = pdata.PlotPointsInAbsoluteLayerCoordinates;

            // adjust the skip frequency if it was not set appropriate
            if (_skipFreq <= 0)
            {
                _skipFreq = 1;
            }

            var dropTargets = new List <CSPlaneID>(_dropTargets.Select(id => layer.UpdateCSPlaneID(id)));

            if (_additionalDropTargetIsEnabled)
            {
                CSPlaneID userPlane;
                if (_additionalDropTargetUsePhysicalBaseValue)
                {
                    userPlane = new CSPlaneID(_additionalDropTargetPerpendicularAxis, layer.Scales[_additionalDropTargetPerpendicularAxis].PhysicalVariantToNormal(_additionalDropTargetBaseValue));
                }
                else
                {
                    userPlane = new CSPlaneID(_additionalDropTargetPerpendicularAxis, _additionalDropTargetBaseValue);
                }
                dropTargets.Add(userPlane);
            }

            // paint the scatter style

            PointD3D pos = PointD3D.Empty;

            if (null == _cachedSymbolSizeForIndexFunction && null == _cachedColorForIndexFunction) // using a constant symbol size and constant color
            {
                var pen = _pen;
                // update pen widths
                double w1 = _lineWidth1Offset + _lineWidth1Factor * _cachedSymbolSize;
                double w2 = _lineWidth2Offset + _lineWidth2Factor * _cachedSymbolSize;
                pen = pen.WithThickness1(w1).WithThickness2(w2);

                var gapStart = 0.5 * (_gapAtStartOffset + _gapAtStartFactor * _cachedSymbolSize);
                var gapEnd   = 0.5 * (_gapAtEndOffset + _gapAtEndFactor * _cachedSymbolSize);

                for (int r = 0; r < rangeList.Count; r++)
                {
                    var range = rangeList[r];
                    int lower = range.LowerBound;
                    int upper = range.UpperBound;

                    for (int j = lower; j < upper; j += _skipFreq)
                    {
                        Logical3D r3d = layer.GetLogical3D(pdata, j + range.OffsetToOriginal);
                        foreach (CSPlaneID id in dropTargets)
                        {
                            layer.CoordinateSystem.GetIsolineFromPointToPlane(r3d, id, out var isoLine);
                            if (gapStart != 0 || gapEnd != 0)
                            {
                                isoLine = isoLine.ShortenedBy(RADouble.NewAbs(gapStart), RADouble.NewAbs(gapEnd));
                            }

                            if (null != isoLine)
                            {
                                g.DrawLine(pen, isoLine);
                            }
                        }
                    }
                } // for each range
            }
            else  // using a variable symbol size or variable symbol color
            {
                for (int r = 0; r < rangeList.Count; r++)
                {
                    var range  = rangeList[r];
                    int lower  = range.LowerBound;
                    int upper  = range.UpperBound;
                    int offset = range.OffsetToOriginal;
                    for (int j = lower; j < upper; j += _skipFreq)
                    {
                        var pen = _pen;
                        if (null == _cachedColorForIndexFunction)
                        {
                            _cachedSymbolSize = _cachedSymbolSizeForIndexFunction(j + offset);
                            double w1 = _lineWidth1Offset + _lineWidth1Factor * _cachedSymbolSize;
                            double w2 = _lineWidth2Offset + _lineWidth2Factor * _cachedSymbolSize;
                            pen = _pen.WithThickness1(w1).WithThickness2(w2);
                        }
                        else
                        {
                            _cachedSymbolSize = null == _cachedSymbolSizeForIndexFunction ? _cachedSymbolSize : _cachedSymbolSizeForIndexFunction(j + offset);
                            double w1 = _lineWidth1Offset + _lineWidth1Factor * _cachedSymbolSize;
                            double w2 = _lineWidth2Offset + _lineWidth2Factor * _cachedSymbolSize;

                            var customSymbolColor = _cachedColorForIndexFunction(j + offset);
                            pen = _pen.WithThickness1(w1).WithThickness2(w2).WithColor(NamedColor.FromArgb(customSymbolColor.A, customSymbolColor.R, customSymbolColor.G, customSymbolColor.B));
                        }

                        var gapStart = 0.5 * (_gapAtStartOffset + _gapAtStartFactor * _cachedSymbolSize);
                        var gapEnd   = 0.5 * (_gapAtEndOffset + _gapAtEndFactor * _cachedSymbolSize);

                        Logical3D r3d = layer.GetLogical3D(pdata, j + rangeList[r].OffsetToOriginal);
                        foreach (CSPlaneID id in _dropTargets)
                        {
                            layer.CoordinateSystem.GetIsolineFromPointToPlane(r3d, id, out var isoLine);

                            if (gapStart != 0 || gapEnd != 0)
                            {
                                isoLine = isoLine.ShortenedBy(RADouble.NewAbs(gapStart), RADouble.NewAbs(gapEnd));
                            }
                            if (null != isoLine)
                            {
                                g.DrawLine(pen, isoLine);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 24
0
        private void PaintOneRange(Graphics g, IPlotArea layer, IPlotRange range, Processed2DPlotData pdata)
        {
            // adjust the skip frequency if it was not set appropriate
            if (_skipFrequency <= 0)
            {
                _skipFrequency = 1;
            }

            var dropTargets = new List <CSPlaneID>(_dropTargets.Select(id => layer.UpdateCSPlaneID(id)));

            if (_additionalDropTargetIsEnabled)
            {
                CSPlaneID userPlane;
                if (_additionalDropTargetUsePhysicalBaseValue)
                {
                    userPlane = new CSPlaneID(_additionalDropTargetPerpendicularAxis, layer.Scales[_additionalDropTargetPerpendicularAxis].PhysicalVariantToNormal(_additionalDropTargetBaseValue));
                }
                else
                {
                    userPlane = new CSPlaneID(_additionalDropTargetPerpendicularAxis, _additionalDropTargetBaseValue);
                }
                dropTargets.Add(userPlane);
            }

            // paint the scatter style

            PointD3D pos   = PointD3D.Empty;
            var      gpath = new GraphicsPath();

            if (null == _cachedSymbolSizeForIndexFunction && null == _cachedColorForIndexFunction) // using a constant symbol size and constant color
            {
                // update pen widths
                var    pen = _pen.Clone();
                double w1  = _lineWidth1Offset + _lineWidth1Factor * _cachedSymbolSize;
                pen.Width = w1;

                var gapStart = 0.5 * (_gapAtStartOffset + _gapAtStartFactor * _cachedSymbolSize);
                var gapEnd   = 0.5 * (_gapAtEndOffset + _gapAtEndFactor * _cachedSymbolSize);

                int lower = range.LowerBound;
                int upper = range.UpperBound;

                for (int j = lower; j < upper; j += _skipFrequency)
                {
                    var originalRowIndex = range.GetOriginalRowIndexFromPlotPointIndex(j);

                    Logical3D r3d = layer.GetLogical3D(pdata, originalRowIndex);
                    r3d.RX += _cachedLogicalShiftX;
                    r3d.RY += _cachedLogicalShiftY;

                    foreach (CSPlaneID id in dropTargets)
                    {
                        gpath.Reset();
                        layer.CoordinateSystem.GetIsolineFromPointToPlane(gpath, r3d, id);
                        PointF[] shortenedPathPoints = null;
                        if (gapStart != 0 || gapEnd != 0)
                        {
                            gpath.Flatten();
                            var pathPoints = gpath.PathPoints;
                            shortenedPathPoints = GdiExtensionMethods.ShortenedBy(pathPoints, RADouble.NewAbs(gapStart), RADouble.NewAbs(gapEnd));
                            if (null != shortenedPathPoints)
                            {
                                g.DrawLines(pen, shortenedPathPoints);
                            }
                        }
                        else
                        {
                            g.DrawPath(pen, gpath);
                        }
                    }
                }
            }
            else // using a variable symbol size or variable symbol color
            {
                int lower = range.LowerBound;
                int upper = range.UpperBound;
                for (int j = lower; j < upper; j += _skipFrequency)
                {
                    var originalRowIndex = range.GetOriginalRowIndexFromPlotPointIndex(j);
                    var pen = _pen.Clone();
                    if (null == _cachedColorForIndexFunction)
                    {
                        _cachedSymbolSize = _cachedSymbolSizeForIndexFunction(originalRowIndex);
                        double w1 = _lineWidth1Offset + _lineWidth1Factor * _cachedSymbolSize;
                        pen.Width = w1;
                    }
                    else
                    {
                        _cachedSymbolSize = null == _cachedSymbolSizeForIndexFunction ? _cachedSymbolSize : _cachedSymbolSizeForIndexFunction(originalRowIndex);
                        double w1 = _lineWidth1Offset + _lineWidth1Factor * _cachedSymbolSize;

                        var customSymbolColor = _cachedColorForIndexFunction(originalRowIndex);
                        pen.Width = w1;
                        pen.Color = NamedColor.FromArgb(customSymbolColor.A, customSymbolColor.R, customSymbolColor.G, customSymbolColor.B);
                    }

                    var gapStart = 0.5 * (_gapAtStartOffset + _gapAtStartFactor * _cachedSymbolSize);
                    var gapEnd   = 0.5 * (_gapAtEndOffset + _gapAtEndFactor * _cachedSymbolSize);

                    Logical3D r3d = layer.GetLogical3D(pdata, originalRowIndex);
                    r3d.RX += _cachedLogicalShiftX;
                    r3d.RY += _cachedLogicalShiftY;

                    foreach (CSPlaneID id in _dropTargets)
                    {
                        gpath.Reset();
                        layer.CoordinateSystem.GetIsolineFromPointToPlane(gpath, r3d, id);
                        PointF[] shortenedPathPoints = null;
                        if (gapStart != 0 || gapEnd != 0)
                        {
                            gpath.Flatten();
                            var pathPoints = gpath.PathPoints;
                            shortenedPathPoints = GdiExtensionMethods.ShortenedBy(pathPoints, RADouble.NewAbs(gapStart), RADouble.NewAbs(gapEnd));
                            if (null != shortenedPathPoints)
                            {
                                g.DrawLines(pen, shortenedPathPoints);
                            }
                        }
                        else
                        {
                            g.DrawPath(pen, gpath);
                        }
                    }
                }
            }
        }
Esempio n. 25
0
        public override bool Apply(bool disposeController)
        {
            try
            {
                _doc.RotationX = _view.RotationX;
                _doc.RotationY = _view.RotationY;
                _doc.RotationZ = _view.RotationZ;
                _doc.ShearX    = _view.ShearX;
                _doc.ShearY    = _view.ShearY;
                _doc.ShearZ    = _view.ShearZ;
                _doc.ScaleX    = _view.ScaleX;
                _doc.ScaleY    = _view.ScaleY;
                _doc.ScaleZ    = _view.ScaleZ;

                if (!_doc.IsAutoSized)
                {
                    var xSize = _view.XSize;
                    var ySize = _view.YSize;
                    var zSize = _view.ZSize;

                    if (object.ReferenceEquals(xSize.Unit, _percentLayerXSizeUnit))
                    {
                        _doc.SizeX = RADouble.NewRel(xSize.Value / 100);
                    }
                    else
                    {
                        _doc.SizeX = RADouble.NewAbs(xSize.AsValueIn(AUL.Point.Instance));
                    }

                    if (object.ReferenceEquals(ySize.Unit, _percentLayerYSizeUnit))
                    {
                        _doc.SizeY = RADouble.NewRel(ySize.Value / 100);
                    }
                    else
                    {
                        _doc.SizeY = RADouble.NewAbs(ySize.AsValueIn(AUL.Point.Instance));
                    }

                    if (object.ReferenceEquals(zSize.Unit, _percentLayerZSizeUnit))
                    {
                        _doc.SizeZ = RADouble.NewRel(zSize.Value / 100);
                    }
                    else
                    {
                        _doc.SizeZ = RADouble.NewAbs(zSize.AsValueIn(AUL.Point.Instance));
                    }
                }

                var xPos = _view.XPosition;
                var yPos = _view.YPosition;
                var zPos = _view.ZPosition;

                if (object.ReferenceEquals(xPos.Unit, _percentLayerXSizeUnit))
                {
                    _doc.PositionX = RADouble.NewRel(xPos.Value / 100);
                }
                else
                {
                    _doc.PositionX = RADouble.NewAbs(xPos.AsValueIn(AUL.Point.Instance));
                }

                if (object.ReferenceEquals(yPos.Unit, _percentLayerYSizeUnit))
                {
                    _doc.PositionY = RADouble.NewRel(yPos.Value / 100);
                }
                else
                {
                    _doc.PositionY = RADouble.NewAbs(yPos.AsValueIn(AUL.Point.Instance));
                }

                if (object.ReferenceEquals(zPos.Unit, _percentLayerZSizeUnit))
                {
                    _doc.PositionZ = RADouble.NewRel(zPos.Value / 100);
                }
                else
                {
                    _doc.PositionZ = RADouble.NewAbs(zPos.AsValueIn(AUL.Point.Instance));
                }

                _doc.LocalAnchorX = _view.PivotX;
                _doc.LocalAnchorY = _view.PivotY;
                _doc.LocalAnchorZ = _view.PivotZ;

                _doc.ParentAnchorX = _view.ReferenceX;
                _doc.ParentAnchorY = _view.ReferenceY;
                _doc.ParentAnchorZ = _view.ReferenceZ;
            }
            catch (Exception ex)
            {
                Current.Gui.ErrorMessageBox(ex.Message, "Error applying ItemLocationDirect");
                return(false); // indicate that something failed
            }

            return(ApplyEnd(true, disposeController));
        }
Esempio n. 26
0
        public void Paint(IGraphicsContext3D g, IPlotArea layer, Processed3DPlotData pdata, Processed3DPlotData prevItemData, Processed3DPlotData nextItemData)
        {
            const double logicalClampMinimum = -10;
            const double logicalClampMaximum = 11;

            // Plot error bars for the dependent variable (y)
            PlotRangeList rangeList = pdata.RangeList;
            var           ptArray   = pdata.PlotPointsInAbsoluteLayerCoordinates;
            var           columnX   = ColumnX;
            var           columnY   = ColumnY;
            var           columnZ   = ColumnZ;

            if (columnX == null || columnY == null || columnZ == null)
            {
                return; // nothing to do if both error columns are null
            }
            if (!typeof(double).IsAssignableFrom(columnX.ItemType) || !typeof(double).IsAssignableFrom(columnY.ItemType) || !typeof(double).IsAssignableFrom(columnZ.ItemType))
            {
                return; // TODO make this an runtime paint error to be reported
            }
            var strokePen = _strokePen;

            foreach (PlotRange r in rangeList)
            {
                int lower  = r.LowerBound;
                int upper  = r.UpperBound;
                int offset = r.OffsetToOriginal;

                for (int j = lower; j < upper; j += _skipFrequency)
                {
                    int    originalRow = j + offset;
                    double symbolSize  = null == _cachedSymbolSizeForIndexFunction ? _symbolSize : _cachedSymbolSizeForIndexFunction(originalRow);

                    strokePen = strokePen.WithThickness1(_lineWidth1Offset + _lineWidth1Factor * symbolSize);
                    strokePen = strokePen.WithThickness2(_lineWidth2Offset + _lineWidth2Factor * symbolSize);

                    if (null != _cachedColorForIndexFunction)
                    {
                        strokePen = strokePen.WithColor(GdiColorHelper.ToNamedColor(_cachedColorForIndexFunction(originalRow), "VariableColor"));
                    }
                    if (null != strokePen.LineEndCap)
                    {
                        strokePen = strokePen.WithLineEndCap(strokePen.LineEndCap.WithMinimumAbsoluteAndRelativeSize(symbolSize * _endCapSizeFactor + _endCapSizeOffset, 1 + 1E-6));
                    }

                    // Calculate target
                    AltaxoVariant targetX, targetY, targetZ;
                    switch (_meaningOfValues)
                    {
                    case ValueInterpretation.AbsoluteDifference:
                    {
                        targetX = pdata.GetXPhysical(originalRow) + columnX[originalRow];
                        targetY = pdata.GetYPhysical(originalRow) + columnY[originalRow];
                        targetZ = pdata.GetZPhysical(originalRow) + columnZ[originalRow];
                    }
                    break;

                    case ValueInterpretation.AbsoluteValue:
                    {
                        targetX = columnX[originalRow];
                        targetY = columnY[originalRow];
                        targetZ = columnZ[originalRow];
                    }
                    break;

                    default:
                        throw new NotImplementedException(nameof(_meaningOfValues));
                    }

                    var logicalTarget = layer.GetLogical3D(targetX, targetY, targetZ);
                    var logicalOrigin = layer.GetLogical3D(pdata, originalRow);

                    if (!_independentOnShiftingGroupStyles && (0 != _cachedLogicalShiftX || 0 != _cachedLogicalShiftY || 0 != _cachedLogicalShiftZ))
                    {
                        logicalOrigin.RX += _cachedLogicalShiftX;
                        logicalOrigin.RY += _cachedLogicalShiftY;
                        logicalOrigin.RZ += _cachedLogicalShiftZ;
                        logicalTarget.RX += _cachedLogicalShiftX;
                        logicalTarget.RY += _cachedLogicalShiftY;
                        logicalTarget.RZ += _cachedLogicalShiftZ;
                    }

                    if (!Calc.RMath.IsInIntervalCC(logicalOrigin.RX, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }
                    if (!Calc.RMath.IsInIntervalCC(logicalOrigin.RY, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }
                    if (!Calc.RMath.IsInIntervalCC(logicalOrigin.RZ, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }

                    if (!Calc.RMath.IsInIntervalCC(logicalTarget.RX, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }
                    if (!Calc.RMath.IsInIntervalCC(logicalTarget.RY, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }
                    if (!Calc.RMath.IsInIntervalCC(logicalTarget.RZ, logicalClampMinimum, logicalClampMaximum))
                    {
                        continue;
                    }

                    var isoLine = layer.CoordinateSystem.GetIsoline(logicalOrigin, logicalTarget);
                    if (null == isoLine)
                    {
                        continue;
                    }

                    if (_useManualVectorLength)
                    {
                        double length        = _vectorLengthOffset + _vectorLengthFactor * symbolSize;
                        double isoLineLength = isoLine.TotalLineLength;
                        isoLine = isoLine.ShortenedBy(RADouble.NewAbs(0), RADouble.NewAbs(isoLineLength - length));
                        if (null == isoLine)
                        {
                            continue;
                        }
                    }

                    if (_useSymbolGap)
                    {
                        double gap = _symbolGapOffset + _symbolGapFactor * symbolSize;
                        if (gap != 0)
                        {
                            isoLine = isoLine.ShortenedBy(RADouble.NewAbs(gap / 2), RADouble.NewAbs(0));
                            if (null == isoLine)
                            {
                                continue;
                            }
                        }
                    }

                    g.DrawLine(strokePen, isoLine);
                }
            }
        }
Esempio n. 27
0
            public IItemLocation ConvertToCurrentLocationVersion(PointD2D cachedLayerSize, PointD2D cachedLayerPosition)
            {
                var newLoc = new ItemLocationDirect();

                switch (_layerWidthType)
                {
                case XYPlotLayerSizeType.AbsoluteValue:
                    newLoc.SizeX = RADouble.NewAbs(_layerWidth);
                    break;

                case XYPlotLayerSizeType.RelativeToGraphDocument:
                    newLoc.SizeX = RADouble.NewRel(_layerWidth);
                    break;

                default:
                    newLoc.SizeX = RADouble.NewAbs(cachedLayerSize.X);
                    break;
                }

                switch (_layerHeightType)
                {
                case XYPlotLayerSizeType.AbsoluteValue:
                    newLoc.SizeY = RADouble.NewAbs(_layerHeight);
                    break;

                case XYPlotLayerSizeType.RelativeToGraphDocument:
                    newLoc.SizeY = RADouble.NewRel(_layerHeight);
                    break;

                default:
                    newLoc.SizeY = RADouble.NewAbs(cachedLayerSize.Y);
                    break;
                }

                switch (_layerXPositionType)
                {
                case XYPlotLayerPositionType.AbsoluteValue:
                    newLoc.PositionX = RADouble.NewAbs(_layerXPosition);
                    break;

                case XYPlotLayerPositionType.RelativeToGraphDocument:
                    newLoc.PositionX = RADouble.NewRel(_layerXPosition);
                    break;

                default:
                    newLoc.PositionX = RADouble.NewAbs(cachedLayerPosition.X);
                    break;
                }

                switch (_layerYPositionType)
                {
                case XYPlotLayerPositionType.AbsoluteValue:
                    newLoc.PositionY = RADouble.NewAbs(_layerYPosition);
                    break;

                case XYPlotLayerPositionType.RelativeToGraphDocument:
                    newLoc.PositionY = RADouble.NewRel(_layerYPosition);
                    break;

                default:
                    newLoc.PositionY = RADouble.NewAbs(cachedLayerPosition.Y);
                    break;
                }

                newLoc.Rotation = _layerAngle;
                newLoc.ScaleX   = newLoc.ScaleY = _layerScale;

                return(newLoc);
            }
        public override bool Apply(bool disposeController)
        {
            try
            {
                _doc.Rotation = _view.Rotation;
                _doc.ShearX   = _view.Shear;
                _doc.ScaleX   = _view.ScaleX;
                _doc.ScaleY   = _view.ScaleY;

                if (!_doc.IsAutoSized)
                {
                    var xSize = _view.XSize;
                    var ySize = _view.YSize;

                    if (object.ReferenceEquals(xSize.Unit, _percentLayerXSizeUnit))
                    {
                        _doc.SizeX = RADouble.NewRel(xSize.Value / 100);
                    }
                    else
                    {
                        _doc.SizeX = RADouble.NewAbs(xSize.AsValueIn(AUL.Point.Instance));
                    }

                    if (object.ReferenceEquals(ySize.Unit, _percentLayerYSizeUnit))
                    {
                        _doc.SizeY = RADouble.NewRel(ySize.Value / 100);
                    }
                    else
                    {
                        _doc.SizeY = RADouble.NewAbs(ySize.AsValueIn(AUL.Point.Instance));
                    }
                }

                var xPos = _view.XPosition;
                var yPos = _view.YPosition;

                if (object.ReferenceEquals(xPos.Unit, _percentLayerXSizeUnit))
                {
                    _doc.PositionX = RADouble.NewRel(xPos.Value / 100);
                }
                else
                {
                    _doc.PositionX = RADouble.NewAbs(xPos.AsValueIn(AUL.Point.Instance));
                }

                if (object.ReferenceEquals(yPos.Unit, _percentLayerYSizeUnit))
                {
                    _doc.PositionY = RADouble.NewRel(yPos.Value / 100);
                }
                else
                {
                    _doc.PositionY = RADouble.NewAbs(yPos.AsValueIn(AUL.Point.Instance));
                }

                _doc.LocalAnchorX = _view.PivotX;
                _doc.LocalAnchorY = _view.PivotY;

                _doc.ParentAnchorX = _view.ReferenceX;
                _doc.ParentAnchorY = _view.ReferenceY;
            }
            catch (Exception)
            {
                return(false); // indicate that something failed
            }

            return(ApplyEnd(true, disposeController));
        }