Example #1
0
        /// <summary>
        ///    Reads an zTXt Chunk from file. The current position must be set
        ///    to the start of the Chunk Data. Such a Chunk contains compressed
        ///    keywords.
        /// </summary>
        /// <param name="data_length">
        ///    A <see cref="System.Int32"/> with the length of the Chunk Data.
        /// </param>
        /// <remarks>
        ///    The Chunk may also contain compressed Exif data which is written
        ///    by other tools. But, since the PNG specification does not support
        ///    Exif data, we ignore it here.
        /// </remarks>
        private void ReadzTXtChunk(int data_length)
        {
            long position = Tell;

            // zTXt Chunk
            //
            // N Bytes     Keyword
            // 1 Byte      Null Separator
            // 1 Byte      Compression Method
            // N Bytes     Txt
            //
            // Followed by 4 Bytes CRC data

            ByteVector data = ReadChunkData(data_length);

            CheckCRC(zTXt_CHUNK_TYPE, data, ReadCRC());

            int    terminator_index;
            string keyword = ReadKeyword(data, 0, out terminator_index);

            if (terminator_index + 1 >= data_length)
            {
                throw new CorruptFileException("Compression Method byte expected");
            }

            byte compression_method = data [terminator_index + 1];

            ByteVector plain_data = Decompress(compression_method, data.Mid(terminator_index + 2));

            // ignore unknown compression methods
            if (plain_data == null)
            {
                return;
            }

            string     value      = plain_data.ToString();
            RawProfile rawProfile = null;

            if (keyword.StartsWith("Raw profile type"))
            {
                rawProfile = ProcessRawProfile(value);
                value      = rawProfile.ToString();
            }

            // handle XMP, which has a fixed header
            if (keyword == "xmp" || rawProfile != null && string.Compare(rawProfile.Name, "xmp", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                ImageTag.AddTag(new XmpTag(string.Join("", rawProfile.Data.ToArray()), this));
            }
            else
            {
                PngTag png_tag = GetTag(TagTypes.Png, true) as PngTag;

                if (png_tag.GetKeyword(keyword) == null)
                {
                    png_tag.SetKeyword(keyword, value);
                }
            }
            AddMetadataBlock(position - 8, data_length + 8 + 4);
        }
Example #2
0
        private static RawProfile ProcessRawProfile(string value)
        {
            // ImageMagick formats 'raw profiles' as
            // '\n<name>\n<length>(%8lu)\n<hex payload>\n'.
            var parts = value.Split(new[] { '\n' });

            if (parts.Length < 4)
            {
                return(null);
            }
            var profile = new RawProfile();

            profile.Name       = parts [1];
            profile.LengthText = parts [2];

            for (int i = 3; i < parts.Length; i++)
            {
                var buffer  = new Byte[parts [i].Length];
                int iBuffer = 0;
                for (int j = 0; j < parts [i].Length - 1; j += 2)
                {
                    var subString = parts [i].Substring(j, 2);
                    buffer [iBuffer++] = Convert.ToByte(subString, 16);
                }
                // raw profile data often has many trailing nulls in most lines, which must be removed
                // for XML processing as XMP data. Are there other raw profiles that need them?
                profile.Data.Add(Encoding.UTF8.GetString(buffer).Trim(new char[] { '\0' }));
            }
            return(profile);
        }
        private static RawProfile CreateDefaultData()
        {
            var profile = new RawProfile(false);

            var ini = new RawInitPoint2D(profile);

            ini.X.SetValue(true, 0);
            ini.Y.SetValue(true, 0);

            var line1 = new RawLine2D(profile);

            line1.DeltaY.SetValue(true, 10);

            var line2 = new RawLine2D(profile);

            line2.DeltaX.SetValue(true, -10);

            var line3 = new RawLine2D(profile);

            line3.Y.SetValue(true, 0);

            var line4 = new RawLine2D(profile);

            line4.X.SetValue(true, 0);


            profile.Add(ini);
            profile.Add(line1);
            profile.Add(line2);
            profile.Add(line3);
            profile.Add(line4);

            return(profile);
        }
        public ProfileEditorViewModel(RawProfile profile, EditStageTreeViewItem workViewModel, AxisSystem axisSystem)
            : base("Input Profile", workViewModel)
        {
            _rawProfile = profile;

            CurrentAxisSystem = axisSystem;

            DictionaryKey = CreateKeyboardShortcuts(CurrentAxisSystem);

            MoveListViewModels = new ObservableCollection <RawItemViewModel>();

            var moveList = profile.GetMoveList();

            foreach (var rawEntity2D in moveList)
            {
                //MoveListViewModels.Add(RawItemViewModel.GetViewModel(rawEntity2D, axisSystem));
                MoveListViewModels.Add(GetViewModel(rawEntity2D));
            }

            SelectedMoveViewModel = MoveListViewModels.LastOrDefault();

            UpdatePreview();

            UpdateMoveListOrientation();
        }
        public Profile2D GetClosedProfile()
        {
            var p = new RawProfile(false);

            var centerPoint = SquareShapeHelper.GetCenterPoint(StartPoint, PuntoStartX, PuntoStartY, Larghezza, Altezza);


            var ini = new RawInitPoint2D(p);

            ini.X.SetValue(true, centerPoint.X + Larghezza / 2);
            ini.Y.SetValue(true, centerPoint.Y + Altezza / 2);
            p.Add(ini);

            var p1 = new RawLine2D(p);

            p1.X.SetValue(true, centerPoint.X + Larghezza / 2);
            p1.Y.SetValue(true, centerPoint.Y - Altezza / 2);
            p.Add(p1);

            var p2 = new RawLine2D(p);

            p2.X.SetValue(true, centerPoint.X - Larghezza / 2);
            p2.Y.SetValue(true, centerPoint.Y - Altezza / 2);
            p.Add(p2);

            var p3 = new RawLine2D(p);

            p3.X.SetValue(true, centerPoint.X - Larghezza / 2);
            p3.Y.SetValue(true, centerPoint.Y + Altezza / 2);
            p.Add(p3);

            var p4 = new RawLine2D(p);

            p4.X.SetValue(true, centerPoint.X + Larghezza / 2);
            p4.Y.SetValue(true, centerPoint.Y + Altezza / 2);
            p.Add(p4);

            if (Chamfer > 0 && ChamferAbilited)
            {
                p1.Chamfer.SetValue(true, Chamfer);
                p2.Chamfer.SetValue(true, Chamfer);
                p3.Chamfer.SetValue(true, Chamfer);
                p4.Chamfer.SetValue(true, Chamfer);
            }
            else if (Chamfer > 0 && !ChamferAbilited)
            {
                p1.EndRadius.SetValue(true, Chamfer);
                p2.EndRadius.SetValue(true, Chamfer);
                p3.EndRadius.SetValue(true, Chamfer);
                p4.EndRadius.SetValue(true, Chamfer);
            }

            var rslt = p.GetProfileResult(true);

            rslt.SetPlotStyle();

            return(rslt);
        }
Example #6
0
        private void AddDummyProfile(TipoTornitura tipoTornitura)
        {
            switch (tipoTornitura)
            {
            case TipoTornitura.Esterna:
            {
                var profile = new RawProfile(true);

                var ini = new RawInitPoint2D(profile);
                ini.X.SetValue(true, 0);
                ini.Y.SetValue(true, 25);

                var line1 = new RawLine2D(profile);
                line1.DeltaX.SetValue(true, -10);

                var line2 = new RawLine2D(profile);
                line2.DeltaY.SetValue(true, 10);
                line2.DeltaX.SetValue(true, -10);

                var line3 = new RawLine2D(profile);
                line3.DeltaY.SetValue(true, 10);

                profile.Add(ini);
                profile.Add(line1);
                profile.Add(line2);
                profile.Add(line3);

                Profile = profile;
            } break;

            case TipoTornitura.Interna:
            {
                var profile = new RawProfile(true);

                var ini = new RawInitPoint2D(profile);
                ini.X.SetValue(true, 0);
                ini.Y.SetValue(true, 70);

                var line1 = new RawLine2D(profile);
                line1.DeltaX.SetValue(true, -10);

                var line2 = new RawLine2D(profile);
                line2.DeltaY.SetValue(true, -10);
                line2.DeltaX.SetValue(true, -10);

                var line3 = new RawLine2D(profile);
                line3.DeltaY.SetValue(true, -10);

                profile.Add(ini);
                profile.Add(line1);
                profile.Add(line2);
                profile.Add(line3);

                Profile = profile;
            } break;
            }
        }
Example #7
0
        static DummyProfileEditorViewModel()
        {
            MoveListViewModels = new List <RawEntity2D>();

            var profileSolver = new RawProfile(false);

            var ini = new RawInitPoint2D(profileSolver);

            ini.X.SetValue(true, 0);
            ini.Y.SetValue(true, 0);

            var line1 = new RawLine2D(profileSolver);

            line1.DeltaY.SetValue(true, 10);

            var line2 = new RawLine2D(profileSolver);

            line2.DeltaX.SetValue(true, -10);

            MoveListViewModels.Add(ini);
            MoveListViewModels.Add(line1);
            MoveListViewModels.Add(line2);

            SelectedMove = MoveListViewModels.LastOrDefault();

            // se cambio SelectedMove aggiorno currentMove
            CurrentMovement = new RawLineViewModel(line2, ProfileEditorViewModel.AxisSystem.Xy);


            //foreach (var rawEntity2D in MoveListViewModels)
            //    profileSolver.Add(rawEntity2D);

            //var profileSolved = profileSolver.GetProfileResult();

            //var listEntity = new List<IEntity2D>();

            //foreach (var entity2D in profileSolved.Source)
            //    listEntity.Add(entity2D);

            //Preview = new ObservableCollection<IEntity2D>(listEntity);
        }
Example #8
0
        public Tornitura(TipoTornitura tipoTornitura)
            : base()
        {
            _tipoTornitura = tipoTornitura;

            Profile = new RawProfile(true);

            /*
             * per evitare danni inserisco punto iniziale qui,
             * anche se e meglio che venga creato dentro ctorù             */

            var ini = new RawInitPoint2D(Profile);

            Profile.Add(ini);
            ini.X.SetValue(true, 0);


            // AddDummyProfile(_tipoTornitura);

            Sgrossatura = new Operazione(this, LavorazioniEnumOperazioni.TornituraSgrossatura);

            Finitura = new Operazione(this, LavorazioniEnumOperazioni.TornituraFinitura);
        }
Example #9
0
		private static RawProfile ProcessRawProfile (string value)
		{
			// ImageMagick formats 'raw profiles' as
			// '\n<name>\n<length>(%8lu)\n<hex payload>\n'.
			var parts = value.Split (new[] { '\n' });
			if (parts.Length < 4)
				return null;
			var profile = new RawProfile ();
			profile.Name = parts [1];
			profile.LengthText = parts [2];

			for (int i = 3; i < parts.Length; i++) {
				var buffer = new Byte[parts [i].Length];
				int iBuffer = 0;
				for (int j = 0; j < parts [i].Length - 1; j += 2) {
					var subString = parts [i].Substring (j, 2);
					buffer [iBuffer++] = Convert.ToByte (subString, 16);
				}
                // raw profile data often has many trailing nulls in most lines, which must be removed
                // for XML processing as XMP data. Are there other raw profiles that need them?
				profile.Data.Add (Encoding.UTF8.GetString (buffer).Trim (new char[] {'\0'}));
			}
			return profile;
		}
Example #10
0
        public Profile2D GetClosedProfile()
        {
            var raggio = Circoscritto ? Radius : GeometryHelper.GetRaggioCircoscritto(Radius, SideNumber);

            var pntList = GeometryHelper.CalculatePoygonInscribed(SideNumber, new Point2D(CentroX, CentroY), raggio);

            var p = new RawProfile(false);


            var iniPoint2D = new Point2D();

            for (int i = 0; i < pntList.Count; i++)
            {
                var point = pntList[i];

                // Initial point
                if (i == 0)
                {
                    iniPoint2D = point;

                    var ini = new RawInitPoint2D(p);
                    ini.X.SetValue(true, iniPoint2D.X + CentroX);
                    ini.Y.SetValue(true, iniPoint2D.Y + CentroY);
                    p.Add(ini);
                    continue;
                }

                var p1 = new RawLine2D(p);
                p1.X.SetValue(true, point.X + CentroX);
                p1.Y.SetValue(true, point.Y + CentroY);
                p.Add(p1);

                if (Chamfer > 0 && ChamferAbilited)
                {
                    p1.Chamfer.SetValue(true, Chamfer);
                }
                else if (Chamfer > 0 && !ChamferAbilited)
                {
                    p1.EndRadius.SetValue(true, Chamfer);
                }
            }

            var end = new RawLine2D(p);

            end.X.SetValue(true, iniPoint2D.X + CentroX);
            end.Y.SetValue(true, iniPoint2D.Y + CentroY);
            p.Add(end);

            if (Chamfer > 0 && ChamferAbilited)
            {
                end.Chamfer.SetValue(true, Chamfer);
            }
            else if (Chamfer > 0 && !ChamferAbilited)
            {
                end.EndRadius.SetValue(true, Chamfer);
            }

            var rslt = p.GetProfileResult(true);

            rslt.SetPlotStyle();

            return(rslt);
        }
Example #11
0
        /// <summary>
        /// Crea profilo per gola a V Esterna
        /// Comprensivo di smussi.
        /// </summary>
        /// <returns></returns>
        protected override Profile2D CalculateProfile()
        {
            var rawProfile = new RawProfile(false);
            var ini        = new RawInitPoint2D(rawProfile);

            ini.X.SetValue(true, CenterZ + LunghezzaEst / 2 + ExternChamferValue);
            ini.Y.SetValue(true, DiametroExt);
            rawProfile.Add(ini);

            var p1 = new RawLine2D(rawProfile);

            p1.X.SetValue(true, CenterZ + LunghezzaEst / 2);
            rawProfile.Add(p1);

            if (ExternChamferValue > 0 && ChamferExternAbilited)
            {
                p1.Chamfer.SetValue(true, ExternChamferValue);
            }
            else if (ExternChamferValue > 0 && !ChamferExternAbilited)
            {
                p1.EndRadius.SetValue(true, ExternChamferValue);
            }

            var p2 = new RawLine2D(rawProfile);

            p2.X.SetValue(true, CenterZ + LunghezzaInt / 2);
            p2.Y.SetValue(true, DiametroMin);
            rawProfile.Add(p2);

            if (InternChamferValue > 0 && ChamferInternAbilited)
            {
                p2.Chamfer.SetValue(true, ExternChamferValue);
            }
            else if (InternChamferValue > 0 && !ChamferInternAbilited)
            {
                p2.EndRadius.SetValue(true, ExternChamferValue);
            }

            // P4
            var p4 = new RawLine2D(rawProfile);

            p4.X.SetValue(true, CenterZ - LunghezzaInt / 2);
            rawProfile.Add(p2);

            if (InternChamferValue > 0 && ChamferInternAbilited)
            {
                p4.Chamfer.SetValue(true, ExternChamferValue);
            }
            else if (InternChamferValue > 0 && !ChamferInternAbilited)
            {
                p4.EndRadius.SetValue(true, ExternChamferValue);
            }

            // P5
            var p5 = new RawLine2D(rawProfile);

            p5.X.SetValue(true, CenterZ - LunghezzaEst / 2);
            rawProfile.Add(p5);

            if (ExternChamferValue > 0 && ChamferExternAbilited)
            {
                p5.Chamfer.SetValue(true, ExternChamferValue);
            }
            else if (ExternChamferValue > 0 && !ChamferExternAbilited)
            {
                p5.EndRadius.SetValue(true, ExternChamferValue);
            }

            // P6 - Last Point
            var p6 = new RawLine2D(rawProfile);

            p6.X.SetValue(true, CenterZ - LunghezzaEst / 2 - ExternChamferValue);
            rawProfile.Add(p6);

            var rslt = rawProfile.GetProfileResult(true);

            rslt.SetPlotStyle();

            return(rslt);
        }
 public FreeProfilePattern()
 {
     _rawProfile = CreateDefaultData();
 }
        /*
         * Magari aggiungere inclinazione
         */

        public Profile2D GetClosedProfile()
        {
            /*
             * Come coordinate 0 prendo centro raggio.
             *
             * Allora primo sono sulla faccia esterna del pezzo
             *
             * poi scendo ( faccio smusso raccordo se esiste )
             *
             * vado a fare raccordo
             *
             * esco sulla faccia del pezzo
             *
             * poi aggirando tutto il profilo chiudo
             *
             * in modo da creare profilo esterno da trimmare.
             */
            var rawProfile = new RawProfile(false);

            if (Radius <= 0 || LunghezzaCentroLato <= 0)
            {
                return(new Profile2D());
            }

            /* Punto iniziale*/
            var initPoint2D = new RawInitPoint2D(rawProfile);

            initPoint2D.X.SetValue(true, CentroX + LunghezzaCentroLato);
            initPoint2D.Y.SetValue(true, CentroY + Radius + ChamferValue * 1.2 + 1);
            initPoint2D.PlotStyle = EnumPlotStyle.Element;


            /*Punto 1*/
            var line1 = new RawLine2D(rawProfile);

            line1.Y.SetValue(true, CentroY + Radius);
            line1.PlotStyle = EnumPlotStyle.Element;
            if (ChamferValue > 0)
            {
                line1.Chamfer.SetValue(true, ChamferValue);
            }

            /*Inizio Arco*/
            var line2 = new RawLine2D(rawProfile);

            line2.PlotStyle = EnumPlotStyle.Element;
            line2.X.SetValue(true, CentroX);

            /*Arco*/
            var arc = new RawArc2D(rawProfile);

            arc.PlotStyle = EnumPlotStyle.Element;

            arc.Radius.SetValue(true, Radius);
            arc.IsClockwise = false;
            arc.Y.SetValue(true, CentroY - Radius);
            arc.CenterX.SetValue(true, CentroX);
            arc.CenterY.SetValue(true, CentroY);

            /*Faccia pezzo*/
            var line3 = new RawLine2D(rawProfile);

            line3.PlotStyle = EnumPlotStyle.Element;
            line3.X.SetValue(true, CentroX + LunghezzaCentroLato);
            if (ChamferValue > 0)
            {
                line3.Chamfer.SetValue(true, ChamferValue);
            }

            /*Scendo pezzo*/
            var line4 = new RawLine2D(rawProfile);

            line4.PlotStyle = EnumPlotStyle.Element;
            line4.Y.SetValue(true, CentroY - Radius - ChamferValue * 1.2 - 1);

            /* Aggiro in 3 linee*/
            var line5 = new RawLine2D(rawProfile);

            line5.PlotStyle = EnumPlotStyle.Invisible;
            line5.X.SetValue(true, CentroX - Radius * 2);

            var line6 = new RawLine2D(rawProfile);

            line6.PlotStyle = EnumPlotStyle.Invisible;
            line6.Y.SetValue(true, initPoint2D.Y.Value);

            var line7 = new RawLine2D(rawProfile);

            line7.PlotStyle = EnumPlotStyle.Invisible;
            line7.X.SetValue(true, initPoint2D.X.Value);

            rawProfile.Add(initPoint2D);
            rawProfile.Add(line1);
            rawProfile.Add(line2);
            rawProfile.Add(arc);
            rawProfile.Add(line3);
            rawProfile.Add(line4);
            rawProfile.Add(line5);
            rawProfile.Add(line6);
            rawProfile.Add(line7);

            var profile = rawProfile.GetProfileResult(true);

            return(profile);
        }