Exemple #1
0
 public MainAbutmentSection(DynamicGeometry.Drawing drawing)
     : this()
 {
     Drawing = drawing;
     CreateMainSection();
     Drawing.Figures.Add(this);
 }
Exemple #2
0
 public PasteAction(Drawing drawing, string copiedFigures)
     : base(drawing)
 {
     List<IFigure> list = new List<IFigure>();
     new DrawingDeserializer().ReadFigureList(list, XElement.Parse(copiedFigures), Drawing);
     Figures = list.ToArray();
 }
Exemple #3
0
        public CompileResult CompileExpression(
            Drawing drawing,
            string expressionText,
            Predicate<IFigure> isFigureAllowed)
        {
            CompileResult result = new CompileResult();
            if (expressionText.IsEmpty())
            {
                return result;
            }

            ParseTree ast = Parse(expressionText, result);
            if (!result.Errors.IsEmpty())
            {
                return result;
            }

            ExpressionTreeBuilder builder = new ExpressionTreeBuilder();
            builder.SetContext(drawing, isFigureAllowed);
            var expressionTree = builder.CreateExpression(ast.Root, result);
            if (expressionTree == null || !result.Errors.IsEmpty())
            {
                return result;
            }
            Func<double> function = ExpressionTreeEvaluatorProvider.InterpretExpression(expressionTree);
            result.Expression = function;
            return result;
        }
Exemple #4
0
        public CompileResult CompileFunction(Drawing drawing, string functionText)
        {
            CompileResult result = new CompileResult();
            if (string.IsNullOrEmpty(functionText))
            {
                return result;
            }

            ParseTree ast = Parse(functionText, result);
            if (!result.Errors.IsEmpty())
            {
                return result;
            }

            ExpressionTreeBuilder builder = new ExpressionTreeBuilder();
            builder.SetContext(drawing, f => true);
            var expressionTree = builder.CreateFunction(ast.Root, result);
            if (expressionTree == null || !result.Errors.IsEmpty())
            {
                return result;
            }

            Func<double, double> function = ExpressionTreeEvaluatorProvider.InterpretFunction(expressionTree);
            result.Function = function;
            return result;
        }
Exemple #5
0
 public static Bar CreateBar(DynamicGeometry.Drawing drawing, IList <IFigure> dependencies)
 {
     return(new Bar()
     {
         Drawing = drawing, Dependencies = dependencies
     });
 }
 public BoxCulvertSection(DynamicGeometry.Drawing drawing)
     : this()
 {
     Drawing = drawing;
     DrawSection();
     Drawing.Figures.Add(this);
 }
 public BoxCulvertSection(DynamicGeometry.Drawing drawing, Point insertpoint)
     : this()
 {
     Drawing     = drawing;
     InsertPoint = insertpoint;
     DrawSection();
     Drawing.Figures.Add(this);
 }
Exemple #8
0
        public CoordinateSystem(Drawing drawing)
        {
            Check.NotNull(drawing);

            Drawing = drawing;
            Drawing.SizeChanged += Drawing_SizeChanged;
            Origin = PhysicalSize.Scale(0.5).SnapToIntegers().Minus(0.5);
        }
Exemple #9
0
 public MoveAction(
     Drawing drawing,
     IEnumerable<IMovable> points,
     Point offset,
     IEnumerable<IFigure> toRecalculate)
     : base(drawing)
 {
     Points = points;
     Offset = offset;
     ToRecalculate = toRecalculate;
 }
Exemple #10
0
 public MeshBase(DynamicGeometry.Drawing drawing, MeshContainer meshContainer, Bar bar)
 {
     Drawing               = drawing;
     MeshContainer         = meshContainer;
     InsertPoint           = meshContainer.Focus;
     Bar                   = bar;
     Cover                 = bar.Cover;
     Width                 = MeshContainer.Width;
     VerticalBarsSpacing   = Bar.Step;
     HorizontalBarsSpacing = Bar.Step;
 }
        /// <summary>
        /// Construct the parser that converts from the UI representation to the tutor back-end representation.
        /// </summary>
        /// <param name="figure">The figure to parse.</param>
        public DirectComponentsFromUI(Drawing d, List<IFigure> figs)
        {
            ifigs = figs;
            drawing = d;

            uiToEngineMap = new Dictionary<IFigure, GroundedClause>();
            definedPoints = new List<Point>();
            definedSegments = new List<GeometryTutorLib.ConcreteAST.Segment>();
            circles = new List<GeometryTutorLib.ConcreteAST.Circle>();

            polygons = GeometryTutorLib.ConcreteAST.Polygon.ConstructPolygonContainer();
        }
Exemple #12
0
        public static void Recalculate(Drawing drawing, IEnumerable<IFigure> toRecalculate)
        {
            if (toRecalculate != null)
            {
                foreach (var figure in toRecalculate)
                {
                    figure.RecalculateAndUpdateVisual();
                }

                if (drawing != null)
                {
                    drawing.RaiseFigureCoordinatesChanged(
                        new Drawing.FigureCoordinatesChangedEventArgs(
                            toRecalculate));
                }
            }
        }
Exemple #13
0
 public MacroResultSelector(Drawing drawing, IList<IFigure> inputs)
 {
     Inputs = inputs;
     Drawing = drawing;
 }
Exemple #14
0
 public RootFigureList(Drawing drawing)
     : base(drawing)
 {
     FigureDictionary = new Dictionary <FrameworkElement, IFigure>();
 }
Exemple #15
0
 public RemoveFigureAction(Drawing drawing, IFigure figure)
     : base(drawing)
 {
     Figure = figure;
 }
Exemple #16
0
 public RemoveFiguresAction(Drawing drawing, IEnumerable<IFigure> figures)
     : base(drawing)
 {
     Figures = figures.ToArray();
 }
Exemple #17
0
 public override void OnAddingToDrawing(Drawing drawing)
 {
     base.OnAddingToDrawing(drawing);
     // The undo system can attach this label to a point but not set the point's label property.
     // This ensures that the label property is set to this pointLabel.
     var point = GetPoint();
     if (point.Label == null)
     {
         point.Label = this;
     }
 }
 /// <summary>
 /// Create a new Drawing Parser.
 /// </summary>
 /// <param name="drawing">The drawing to parse.</param>
 /// <param name="parseController">The parseController, used to add disambiguation dialogs.</param>
 public DrawingParserMain(Drawing drawing)
     : base()
 {
     this.drawing = drawing;
 }
Exemple #19
0
 public ReplaceFigureAction(Drawing drawing, IFigure figure, IFigure replacement)
     : base(drawing)
 {
     Figure = figure;
     Replacement = replacement;
 }
Exemple #20
0
 public static void GenerateNewNameIfNecessary(this IFigure figure, Drawing drawing, List<string> blacklist)
 {
     while (figure.Name == null || drawing
         .Figures
         //.GetAllFiguresRecursive() // Do not look recursively.
         .Where(f => f.Name == figure.Name)
         .Where(f => f != figure)
         .Any())
     {
         figure.Name = figure.GenerateFigureName(blacklist);
     }
 }
Exemple #21
0
 public virtual void OnRemovingFromDrawing(Drawing drawing)
 {
 }
Exemple #22
0
 public static CompileResult CompileExpression(this Drawing drawing, string expression)
 {
     return(MEFHost.Instance.CompilerService.CompileExpression(drawing, expression, f => true));
 }
Exemple #23
0
 public virtual void OnAddingToDrawing(Drawing drawing)
 {
     this.GenerateNewNameIfNecessary(drawing, null);
 }
Exemple #24
0
 public virtual string ConstructionHintText(Drawing.ConstructionStepCompleteEventArgs args)
 {
     string expectedFigure = "";
     if (args.FigureTypeNeeded.HasInterface<IPoint>())
     {
         expectedFigure = "point";
     }
     else if (args.FigureTypeNeeded == typeof(Vector))
     {
         expectedFigure = "vector or enter values";
     }
     else if (args.FigureTypeNeeded == typeof(IAngleProvider))
     {
         expectedFigure = "figure with an angle such as an arc or enter value";
     }
     else if (args.FigureTypeNeeded == typeof(ILengthProvider))
     {
         expectedFigure = "figure with length such as a segment or enter value";
     }
     else if (args.FigureTypeNeeded.HasInterface<ILine>())
     {
         expectedFigure = "line, ray or a segment";
     }
     else if (args.FigureTypeNeeded.HasInterface<ICircle>())
     {
         expectedFigure = "circle";
     }
     else if (args.FigureTypeNeeded.HasInterface<IEllipse>())
     {
         expectedFigure = "circle or ellipse";
     }
     else if (args.FigureTypeNeeded.HasInterface<ILinearFigure>())
     {
         expectedFigure = "line or a circle";
     }
     else
     {
         expectedFigure = args.FigureTypeNeeded.Name;
     }
     string hint = string.Format("Select a {0}.", expectedFigure);
     return hint;
 }
Exemple #25
0
        private string GenerateUniqueName(Drawing drawing, string originalName)
        {
            while (drawing.Figures[originalName] != null)
            {
                originalName += "1";
            }

            return originalName;
        }
Exemple #26
0
 public RemoveFiguresAction(Drawing drawing, IEnumerable <IFigure> figures)
     : base(drawing)
 {
     Figures = figures.ToArray();
 }
Exemple #27
0
 public GeometryAction(Drawing drawing)
 {
     Drawing = drawing;
 }
Exemple #28
0
        public static List<IFigure> CreateReflectedFigure(Drawing drawing, IFigure source, IFigure mirror)
        {
            Check.NotNull(source, "source");
            Check.NotNull(mirror, "mirror");

            List<IFigure> result = new List<IFigure>();
            if (source is IPoint)
            {
                var reflectedPoint = Factory.CreateReflectedPoint(drawing, new [] { source, mirror });
                if (reflectedPoint == null)
                {
                    throw "reflectedPoint is null. source = {0}, mirror = {1}"
                        .Format(source, mirror)
                        .AsException();
                }
                reflectedPoint.Visible = source.Visible;
                reflectedPoint.Name = source.Name + "'";
                result.Add(reflectedPoint);
            }
            else if ((source is ILine || source is IEllipse || source is IPolygonalChain) && !(mirror is ICircle))
            {
                var dependencies = new List<IFigure>();
                foreach (var dependency in source.Dependencies)
                {
                    var reflectedDependency = CreateReflectedFigure(drawing, dependency, mirror);
                    if (reflectedDependency == null)
                    {
                        throw "reflectedDependency is null. dependency = {0}, mirror = {1}"
                            .Format(dependency, mirror)
                            .AsException();
                    }
                    if (reflectedDependency.IsEmpty())
                    {
                        throw "reflectedDependency is empty. dependency = {0}, mirror = {1}"
                            .Format(dependency, mirror)
                            .AsException();
                    }
                    result.AddRange(reflectedDependency);
                    var last = reflectedDependency.Last();
                    if (last == null)
                    {
                        throw "last = null".AsException();
                    }
                    dependencies.Add(last);
                }
                var reflected = source.Clone();
                if (reflected == null)
                {
                    throw "reflected = null".AsException();
                }
                reflected.UnregisterFromDependencies();
                reflected.Dependencies.SetItems(dependencies);
                result.Add(reflected);

                // Flip the wind of arcs.
                var arc = reflected as IArc;
                if (arc != null && mirror is ILine)
                {
                    arc.Clockwise = !arc.Clockwise;
                }

            }
            return result;
        }
Exemple #29
0
        public static List<IFigure> CreateRotatedFigure(Drawing drawing, IFigure source, IFigure center, IFigure angleProvider, double angle)
        {
            Check.NotNull(source, "source");
            Check.NotNull(center, "center");

            var list = new List<IFigure>() { source, center };

            var safeAngleProvider = angleProvider as IAngleProvider;
            if (safeAngleProvider != null)
            {
                angle = safeAngleProvider.Angle;
                list.Add(angleProvider);
            }

            List<IFigure> result = new List<IFigure>();
            if (source is IPoint)
            {
                var rotatedPoint = Factory.CreateRotatedPoint(drawing, list, angle);
                if (rotatedPoint == null)
                {
                    throw "rotatedPoint is null. source = {0}, center = {1}, angleArc = {2}, angle = {3}"
                        .Format(source, center, angleProvider, angle)
                        .AsException();
                }
                rotatedPoint.Visible = source.Visible;
                result.Add(rotatedPoint);
            }
            else if (source is ILine || source is IEllipse || source is IPolygonalChain)
            {
                var dependencies = new List<IFigure>();
                foreach (var dependency in source.Dependencies)
                {
                    var rotatedDependency = CreateRotatedFigure(drawing, dependency, center, angleProvider, angle);
                    if (rotatedDependency == null)
                    {
                        throw "rotatedDependency is null. dependency = {0}, center = {1}, angleArc = {2}, angle = {3}"
                            .Format(dependency, center, angleProvider, angle)
                            .AsException();
                    }
                    if (rotatedDependency.IsEmpty())
                    {
                        throw "rotatedDependency is empty. dependency = {0}, center = {1}, angleArc = {2} angle = {3}"
                            .Format(dependency, center, angleProvider, angle)
                            .AsException();
                    }
                    result.AddRange(rotatedDependency);
                    var last = rotatedDependency.Last();
                    if (last == null)
                    {
                        throw "last = null".AsException();
                    }
                    dependencies.Add(last);
                }
                var rotated = source.Clone();
                if (rotated == null)
                {
                    throw "rotated = null".AsException();
                }
                rotated.UnregisterFromDependencies();
                rotated.Dependencies = dependencies;
                result.Add(rotated);
            }
            return result;
        }
Exemple #30
0
 public virtual void OnAddingToDrawing(Drawing drawing)
 {
     //this.GenerateNewNameIfNecessary(drawing, null);
     this.Name = this.GetType().Name + drawing.Figures.Count.ToString();
 }
Exemple #31
0
 public RootFigureList(Drawing drawing)
     : base(drawing)
 {
     FigureDictionary = new Dictionary<FrameworkElement, IFigure>();
 }
Exemple #32
0
 public void SetContext(Drawing drawing, Predicate<IFigure> isFigureAllowed)
 {
     Binder.Drawing = drawing;
     Binder.FigureAllowed = isFigureAllowed;
 }
Exemple #33
0
        public static List<IFigure> CreateDilatedFigure(Drawing drawing, IFigure source, IFigure center, IFigure lengthProvider1, IFigure lengthProvider2, double factor)
        {
            Check.NotNull(source, "source");
            Check.NotNull(center, "center");

            var list = new List<IFigure>() { source, center };

            var lp1 = lengthProvider1 as ILengthProvider;
            var lp2 = lengthProvider2 as ILengthProvider;
            if (lp1 != null)
            {
                if (lp2 != null)
                {
                    factor = lp1.Length / lp2.Length;
                    list.Add(lp1, lp2);
                }
                else
                {
                    factor = lp1.Length;
                    list.Add(lp1);
                }
            }

            List<IFigure> result = new List<IFigure>();
            if (source is IPoint)
            {
                var dilatedPoint = Factory.CreateDilatedPoint(drawing, list, factor);
                if (dilatedPoint == null)
                {
                    throw "dilatedPoint is null. source = {0}, center = {1}, segment1 = {2}, segment2 = {3}, factor = {4}"
                        .Format(source, center, lengthProvider1, lengthProvider2, factor)
                        .AsException();
                }
                dilatedPoint.Visible = source.Visible;
                result.Add(dilatedPoint);
            }
            else if (source is ILine || source is IEllipse || source is IPolygonalChain)
            {
                var dependencies = new List<IFigure>();
                foreach (var dependency in source.Dependencies)
                {
                    var dilatedDependency = CreateDilatedFigure(drawing, dependency, center, lengthProvider1, lengthProvider2, factor);
                    if (dilatedDependency == null)
                    {
                        throw "dilatedDependency is null. dependency = {0}, center = {1}, segment1 = {2}, segment2 = {3} factor = {2}"
                            .Format(dependency, center, lengthProvider1, lengthProvider2, factor)
                            .AsException();
                    }
                    if (dilatedDependency.IsEmpty())
                    {
                        throw "dilatedDependency is empty. dependency = {0}, center = {1}, segment1 = {2}, segment2 = {3} factor = {2}"
                            .Format(dependency, center, lengthProvider1, lengthProvider2, factor)
                            .AsException();
                    }
                    result.AddRange(dilatedDependency);
                    var last = dilatedDependency.Last();
                    if (last == null)
                    {
                        throw "last = null".AsException();
                    }
                    dependencies.Add(last);
                }
                var dilated = source.Clone();
                if (dilated == null)
                {
                    throw "dilated = null".AsException();
                }
                dilated.UnregisterFromDependencies();
                dilated.Dependencies.SetItems(dependencies);
                result.Add(dilated);
            }
            return result;
        }
Exemple #34
0
 public static List<IFigure> CreateTranslatedFigure(Drawing drawing, IFigure source, List<IFigure> dependenciesSubset, double magnitude, double direction)
 {
     Check.NotNull(source, "source");
     List<IFigure> result = new List<IFigure>();
     if (source is IPoint)
     {
         var list = new List<IFigure>() { source };
         list.AddRange(dependenciesSubset);
         var translatedPoint = Factory.CreateTranslatedPoint(drawing, list, magnitude, direction);
         if (translatedPoint == null)
         {
             throw "translatedPoint is null. source = {0}, magnitude = {1}, direction = {2}"
                 .Format(source, magnitude, direction)
                 .AsException();
         }
         translatedPoint.Visible = source.Visible;
         result.Add(translatedPoint);
     }
     else if (source is ILine || source is IEllipse || source is IPolygonalChain)
     {
         var dependencies = new List<IFigure>();
         foreach (var dependency in source.Dependencies)
         {
             var translatedDependency = CreateTranslatedFigure(drawing, dependency, dependenciesSubset, magnitude, direction);
             if (translatedDependency == null)
             {
                 throw "translatedDependency is null. dependency = {0}, center = {1}, direction = {2}"
                     .Format(dependency, magnitude, direction)
                     .AsException();
             }
             if (translatedDependency.IsEmpty())
             {
                 throw "translatedDependency is empty. dependency = {0}, center = {1}, direction = {2}"
                     .Format(dependency, magnitude, direction)
                     .AsException();
             }
             result.AddRange(translatedDependency);
             var last = translatedDependency.Last();
             if (last == null)
             {
                 throw "last = null".AsException();
             }
             dependencies.Add(last);
         }
         var translated = source.Clone();
         if (translated == null)
         {
             throw "translated = null".AsException();
         }
         translated.UnregisterFromDependencies();
         translated.Dependencies = dependencies;
         result.Add(translated);
     }
     return result;
 }
Exemple #35
0
        private void EnsureUniqueNames(Drawing drawing, XElement figuresElement)
        {
            List<XElement> renames = new List<XElement>();

            foreach (var figureElement in figuresElement.Elements())
            {
                string oldName = figureElement.ReadString("Name");
                if (drawing.Figures[oldName] != null)
                {
                    renames.Add(figureElement);
                }
            }

            if (renames.Count == 0)
            {
                return;
            }

            foreach (var element in renames)
            {
                string oldName = element.ReadString("Name");
                string newName = GenerateUniqueName(drawing, oldName);
                element.SetAttributeValue("Name", newName);
                foreach (var figure in figuresElement.Elements())
                {
                    foreach (var dependency in figure.Elements("Dependency"))
                    {
                        if (dependency.ReadString("Name") == oldName)
                        {
                            dependency.SetAttributeValue("Name", newName);
                        }
                    }
                }
            }
        }