Пример #1
0
        internal ScaffoldItem(ReadableIdentifier name, IEnumerable <Point2Dstep> points)
            : base(name)
        {
            _definition = points.ToArray();

            constructionInitialization();
        }
Пример #2
0
        /// <inheritdoc/>
        internal override ShapeItem Load(string path, ReadableIdentifier identifier)
        {
            var lines       = File.ReadAllLines(path);
            var points      = new List <Point2Dmm>();
            var pointsScale = 100.0;

            foreach (var line in lines)
            {
                if (line.Trim() == "")
                {
                    continue;
                }

                var pointParts = line.Trim().Split('\t');
                var x          = double.Parse(pointParts[0]) * pointsScale;
                var y          = double.Parse(pointParts[1]) * pointsScale;

                var point = new Point2Dmm(-x, -y);
                points.Add(point);
            }

            var shape = new ShapeItem2D(identifier, points);

            shape.MetricWidth = pointsScale;
            return(shape);
        }
Пример #3
0
        public IEnumerable <Point2Dmm[]> Load(string path, out ReadableIdentifier identifier)
        {
            var extension = Path.GetExtension(path).ToLowerInvariant();
            var name      = Path.GetFileNameWithoutExtension(path);

            identifier = new ReadableIdentifier(name);

            if (_panel != null)
            {
                identifier = _panel.UnusedVersion(identifier);
            }

            if (!_loaders.ContainsKey(extension))
            {
                ShowError("No available loader found.");
                return(null);
            }

            try
            {
                return(_loaders[extension].LoadPoints(path));
            }
            catch (Exception ex)
            {
                ShowError("Loading failed with an error: " + ex.Message);
                return(null);
            }
        }
Пример #4
0
        internal MillingShapeItemGCode(string gcode, ReadableIdentifier identifier) :
            base(identifier)
        {
            var parser = new GeometryCNC.GCode.Parser(gcode);

            _toolPath = parser.GetToolPath();
        }
Пример #5
0
        /// <inheritdoc/>
        internal override ShapeItem Load(string path, ReadableIdentifier identifier)
        {
            var lines  = File.ReadAllLines(path);
            var points = new List <Point2Dmm>();

            foreach (var line in lines)
            {
                var pointParts = sanitizeDatLine(line).Split(' ');
                if (pointParts.Length != 2)
                {
                    //invalid line
                    continue;
                }

                double x, y;
                if (!double.TryParse(pointParts[0], out x) || !double.TryParse(pointParts[1], out y))
                {
                    continue;
                }

                var point = new Point2Dmm(-x, -y);
                points.Add(point);
            }
            points.Add(points.First());
            var shape = new ShapeItem2D(identifier, points);

            shape.MetricWidth = 50;
            return(shape);
        }
Пример #6
0
 internal MillingWorkspaceItem(SerializationInfo info, StreamingContext context)
 {
     _positionX     = info.GetInt32("_positionX");
     _positionY     = info.GetInt32("_positionY");
     _rotationAngle = info.GetDouble("_rotationAngle");
     Name           = (ReadableIdentifier)info.GetValue("Name", typeof(ReadableIdentifier));
     constructionInitialization();
 }
Пример #7
0
        /// <inheritdoc/>
        internal override ShapeItem Load(string path, ReadableIdentifier identifier)
        {
            var points = LoadPoints(path);
            var shape  = new ShapeItem2D(identifier, points.FirstOrDefault());

            shape.MetricWidth = pointsScale;
            return(shape);
        }
Пример #8
0
        internal override ShapeItem Clone(ReadableIdentifier cloneName)
        {
            var shapeItem = new ShapeItem2D(cloneName, ShapeDefinition.ToUV());

            shapeItem.MetricWidth   = MetricWidth;
            shapeItem.RotationAngle = RotationAngle;
            shapeItem.MetricHeight  = MetricHeight;
            return(shapeItem);
        }
Пример #9
0
        internal MillingShapeItemRelief Clone(ReadableIdentifier cloneName)
        {
            var shapeItem = new MillingShapeItemRelief(cloneName, _reliefDefinition);

            shapeItem.MetricWidth   = MetricWidth;
            shapeItem.RotationAngle = RotationAngle;
            shapeItem.MetricHeight  = MetricHeight;
            shapeItem.MillingDepth  = MillingDepth;
            return(shapeItem);
        }
Пример #10
0
        internal ShapeItem(ReadableIdentifier name, IEnumerable <Point4Dmm> shapeDefinition)
            : base(name)
        {
            if (shapeDefinition == null)
            {
                throw new ArgumentNullException("shapeDefinition");
            }

            _shapeDefinition = shapeDefinition.ToArray();
            _useClockwiseCut = true;

            constructionInitialization();
        }
Пример #11
0
        internal MillingShapeItemRelief(ReadableIdentifier name, double[,] reliefDefinition)
            : base(name)
        {
            if (reliefDefinition == null)
            {
                throw new ArgumentNullException("reliefDefinition");
            }

            _reliefDefinition = (double[, ])reliefDefinition.Clone();
            _millingDepth     = 1.0;

            constructionInitialization();
        }
Пример #12
0
        /// <inheritdoc/>
        internal override ShapeItem Load(string path, ReadableIdentifier identifier)
        {
            var formatter = new BinaryFormatter();

            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var definition = (ShapeDefinition4D)formatter.Deserialize(stream);
                var shape      = new ShapeItem4D(identifier, definition.Points);
                shape.MetricThickness = definition.Thickness;
                shape.SetOriginalSize();
                return(shape);
            }
        }
Пример #13
0
        /// <inheritdoc/>
        internal override ShapeItem Load(string path, ReadableIdentifier identifier)
        {
            var lines      = File.ReadAllLines(path);
            var dimensions = new List <double>();

            foreach (var line in lines)
            {
                var parts = line.Split(' ');
                if (parts.Length == 0)
                {
                    continue;
                }

                var dimension = double.Parse(parts[0]);
                dimensions.Add(dimension);
            }

            var sliceThickness = dimensions[0];
            var sliceLength    = dimensions[1];
            var sliceCount     = (int)Math.Round(dimensions[2]);

            //TODO even counts are now not supported
            sliceCount = ((sliceCount + 1) / 2) * 2;

            var slicePoints = new List <Point2Dmm>();

            for (var i = 0; i < sliceCount; ++i)
            {
                var totalHeight = i * sliceThickness;
                if (i % 2 == 0)
                {
                    slicePoints.Add(new Point2Dmm(0, totalHeight));
                    slicePoints.Add(new Point2Dmm(sliceLength, totalHeight));
                }
                else
                {
                    slicePoints.Add(new Point2Dmm(sliceLength, totalHeight));
                    slicePoints.Add(new Point2Dmm(0, totalHeight));
                }
            }

            //this we can do only for odd slice counts
            slicePoints.Add(new Point2Dmm(0, 0));
            slicePoints.Reverse();

            var item = new ShapeItem2D(identifier, slicePoints);

            item.SetOriginalSize();
            return(item);
        }
Пример #14
0
        internal MillingShapeItem2D(ReadableIdentifier name, IEnumerable <Point2Dmm[]> shapeDefinition)
            : base(name)
        {
            if (shapeDefinition == null)
            {
                throw new ArgumentNullException("shapeDefinition");
            }

            _shapeDefinition = preparePoints(shapeDefinition);
            _useClockwiseCut = true;
            _millingDepth    = 1.0;

            constructionInitialization();
        }
Пример #15
0
        /// <inheritdoc/>
        internal override ShapeItem Load(string path, ReadableIdentifier identifier)
        {
            Message("Image processing, please wait.");
            var interpolator = new ImageInterpolator(path);
            var points       = interpolator.InterpolatePoints();

            points = ShapeFactory.Centered(points);
            HideMessage();

            var shape = new ShapeItem2D(identifier, points);

            shape.MetricWidth = 50;
            return(shape);
        }
Пример #16
0
        public double[,] LoadRelief(string path, out ReadableIdentifier identifier)
        {
            var imageLoader = new ImageLoader();
            var map         = imageLoader.LoadRelief(path);

            var extension = Path.GetExtension(path).ToLowerInvariant();
            var name      = Path.GetFileNameWithoutExtension(path);

            identifier = new ReadableIdentifier(name);

            if (_panel != null)
            {
                identifier = _panel.UnusedVersion(identifier);
            }

            return(map);
        }
Пример #17
0
        /// <inheritdoc/>
        internal override ShapeItem Clone(ReadableIdentifier cloneName)
        {
            var shapeItem = new ShapeItem4D(cloneName, ShapeDefinition);

            shapeItem.MetricWidth             = MetricWidth;
            shapeItem.RotationAngle           = RotationAngle;
            shapeItem.MetricHeight            = MetricHeight;
            shapeItem.MetricThickness         = MetricThickness;
            shapeItem.UseClockwiseCut         = UseClockwiseCut;
            shapeItem.UseExplicitKerf         = UseExplicitKerf;
            shapeItem.KerfUV                  = KerfUV;
            shapeItem.KerfXY                  = KerfXY;
            shapeItem.IsUvXySwitched          = IsUvXySwitched;
            shapeItem.SpeedAlgorithm          = SpeedAlgorithm;
            shapeItem.FinishCutMetricMarginC2 = FinishCutMetricMarginC2;

            return(shapeItem);
        }
Пример #18
0
        public MillingItem Load(string path)
        {
            var extension = Path.GetExtension(path);

            if (extension == ".gcode" || extension == ".nc")
            {
                var name       = Path.GetFileNameWithoutExtension(path);
                var identifier = new ReadableIdentifier(name);

                if (_provider != null)
                {
                    identifier = _provider.UnusedVersion(identifier);
                }

                return(new MillingShapeItemGCode(File.ReadAllText(path), identifier));
            }


            var useHeightmap = false;

            if (useHeightmap)
            {
                var reliefShape = _factory.LoadRelief(path, out var name);
                if (reliefShape != null)
                {
                    var reliefShapeItem = new MillingShapeItemRelief(name, reliefShape);
                    reliefShapeItem.MetricHeight = 100;
                    return(reliefShapeItem);
                }
            }
            else
            {
                var flatShape = _factory.Load(path, out var name);
                if (flatShape != null)
                {
                    var shapeItem = new MillingShapeItem2D(name, flatShape);
                    shapeItem.MetricHeight = 100;
                    return(shapeItem);
                }
            }

            return(null);
        }
Пример #19
0
        internal override ShapeItem Load(string path, ReadableIdentifier identifier)
        {
            var lines = File.ReadAllLines(path);

            var segmentSpeeds = new List <Speed>();
            var coordinates   = new List <Point2Dmm>();

            coordinates.Add(new Point2Dmm(0, 0));

            foreach (var line in lines)
            {
                if (line.Trim() == "")
                {
                    //empty line
                    continue;
                }

                var coords = line.Split(' ');
                if (coords.Length != 3)
                {
                    throw new FormatException("Invalid format on line: " + line);
                }

                var coord1 = double.Parse(coords[0]);
                var coord2 = double.Parse(coords[1]);
                var speed  = double.Parse(coords[2]);

                var lastP = coordinates.Last();
                coordinates.Add(new Point2Dmm(coord1 + lastP.C1, coord2 + lastP.C2));
                var deltaT = Configuration.MilimetersPerStep * Configuration.TimerFrequency / speed;
                segmentSpeeds.Add(Speed.FromDeltaT((int)Math.Round(deltaT)));
            }


            var item = new NativeControlItem(identifier, coordinates, segmentSpeeds);

            item.SetOriginalSize();
            return(item);
        }
Пример #20
0
        internal ReadableIdentifier UnusedVersion(ReadableIdentifier name)
        {
            var names = new HashSet <ReadableIdentifier>();

            foreach (var child in Children)
            {
                var item = child as MillingWorkspaceItem;
                if (item == null)
                {
                    continue;
                }

                names.Add(item.Name);
            }

            var currentVersion = name;

            while (names.Contains(currentVersion))
            {
                currentVersion = currentVersion.NextVersion();
            }
            return(currentVersion);
        }
Пример #21
0
 internal NativeControlItem(ReadableIdentifier name, IEnumerable <Point2Dmm> shapeDefinition, IEnumerable <Speed> segmentSpeeds)
     : base(name, shapeDefinition.DuplicateTo4Dmm())
 {
     SegmentSpeeds = segmentSpeeds;
 }
Пример #22
0
 public LevelMillingItem(ReadableIdentifier name) : base(name, new[] { new[] { new Point2Dmm(0, 0), new Point2Dmm(1, 0), new Point2Dmm(1, 1), new Point2Dmm(0, 1) } })
 {
     MillingDepth = 0; // default to z level milling
 }
Пример #23
0
 internal MillingWorkspaceItem(ReadableIdentifier name)
 {
     Name = name;
     constructionInitialization();
 }
Пример #24
0
 internal ReadableIdentifier UnusedVersion(ReadableIdentifier identifier)
 {
     return Workspace.UnusedVersion(identifier);
 }
Пример #25
0
 internal abstract ShapeItem Load(string path, ReadableIdentifier identifier);
Пример #26
0
 public ReadableIdentifier UnusedVersion(ReadableIdentifier identifier)
 {
     return(Workspace.UnusedVersion(identifier));
 }
Пример #27
0
 internal PermanentMillingWorkspaceItem(ReadableIdentifier name) : base(name)
 {
 }
Пример #28
0
 /// <inheritdoc/>
 internal override ShapeItem Clone(ReadableIdentifier cloneName)
 {
     return(new NativeControlItem(cloneName, ShapeDefinition.ToUV(), SegmentSpeeds));
 }
Пример #29
0
 internal MillingItem(ReadableIdentifier name)
     : base(name)
 {
 }
Пример #30
0
 internal PointProviderItem(ReadableIdentifier name)
     : base(name)
 {
 }