コード例 #1
0
        private void RefreshImage()
        {
            //считать параметры из таблицы
            List <ScetchParameter> parameters = new List <ScetchParameter>();

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                ScetchParameter param = new ScetchParameter();
                param.Name  = row.Cells[0].Value.ToString();
                param.value = row.Cells[1].Value.ToString();

                string posXstring = row.Cells[2].Value.ToString();
                param.PositionX = float.Parse(posXstring);

                string posYstring = row.Cells[3].Value.ToString();
                param.PositionY = float.Parse(posYstring);

                string rotateString = row.Cells[4].Value.ToString();
                param.Rotation = float.Parse(rotateString);

                param.NeedsWrap = (bool)row.Cells[5].Value;

                parameters.Add(param);
            }


            //взять картинку
            //нанести на неё размеры
            //временно сохранить картинку
            string newTempImage = ScetchImage.GenerateTemporary(templateImagePath, parameters);

            //вывести в форму
            pictureBox1.Load(newTempImage);

            if (curTempImage != "")
            {
                System.IO.File.Delete(curTempImage);
            }

            curTempImage = newTempImage;
        }
コード例 #2
0
        private ScetchTemplate CreateTemplate(string nameFolder, bool AsSubtype)
        {
            string         name = nameFolder.Split('\\').Last();
            ScetchTemplate st   = new ScetchTemplate();

            st.formName = name;

            if (AsSubtype)
            {
                st.IsSubtype = true;
                string subtypeNumberString = name.Split('_').Last();
                int    subtypeNumber       = int.Parse(subtypeNumberString);
                st.SubtypeNumber = subtypeNumber;
            }

            string familiesNamesFile = Path.Combine(nameFolder, "families.txt");
            string fileCheck         = CheckFileExists(familiesNamesFile);

            if (fileCheck != "")
            {
                Autodesk.Revit.UI.TaskDialog.Show("Ошибка", fileCheck);
                return(null);
            }

            string[] familiesNames = FileSupport.ReadFileWithAnyDecoding(familiesNamesFile);
            st.familyNames = familiesNames.ToList();

            string imageFile = Path.Combine(nameFolder, "scetch.png");

            fileCheck = CheckFileExists(imageFile);
            if (fileCheck != "")
            {
                Autodesk.Revit.UI.TaskDialog.Show("Ошибка", fileCheck);
                return(null);
            }
            st.templateImagePath = imageFile;

            string paramsFile = Path.Combine(nameFolder, "parameters.txt");

            fileCheck = CheckFileExists(paramsFile);
            if (fileCheck != "")
            {
                Autodesk.Revit.UI.TaskDialog.Show("Ошибка", fileCheck);
                return(null);
            }
            string[] paramsArray = FileSupport.ReadFileWithAnyDecoding(paramsFile);
            st.parameters = new List <ScetchParameter>();
            for (int i = 0; i < paramsArray.Length; i++)
            {
                string p = paramsArray[i];
                if (p.StartsWith("#"))
                {
                    continue;
                }
                ScetchParameter sp        = new ScetchParameter();
                string[]        paramInfo = p.Split(',');
                if (paramInfo.Length < 4)
                {
                    continue;
                }
                sp.Name = paramInfo[0];
                bool checkParseX = float.TryParse(paramInfo[1], out sp.PositionX);
                bool checkParseY = float.TryParse(paramInfo[2], out sp.PositionY);
                bool checkParseR = float.TryParse(paramInfo[3], out sp.Rotation);
                if (!checkParseX || !checkParseY || !checkParseR)
                {
                    throw new ArgumentException("Incorrect syntax in file " + paramsFile.Replace("\\", " \\") + ", line " + i);
                }

                sp.NeedsWrap = false;
                if (paramInfo.Length > 4)
                {
                    if (paramInfo[4] == "1")
                    {
                        sp.NeedsWrap = true;
                    }
                }

                st.parameters.Add(sp);
            }

            Debug.WriteLine("ScetchTemplate is created");
            return(st);
        }