Exemple #1
0
        public void AddElement(string smodel, string simg, int simgid, int id, ModelUIElement3D mod)
        {
            if (simg == "")
            {
                simg = win.soureseDefaultB;
            }
            if (id == 0)
            {
                id = win.iddefaultB;
            }
            if (smodel == "")
            {
                return;
            }
            ModelImporter importer  = new ModelImporter();
            Material      material1 = new DiffuseMaterial(win.defcolor);

            importer.DefaultMaterial = material1;
            double maxx = 0;

            ModelUIElement3D[] masel = new ModelUIElement3D[4];
            masel[0] = win.selectedobject;
            masel[1] = win.twoselectedobject;
            masel[2] = win.threeselectedobject;
            masel[3] = win.fourselectedobject;
            int countmasel = 0;

            for (int i = 0; i < 4; i++)
            {
                if (masel[i] != null)
                {
                    countmasel++;
                }
            }
            for (int j = 0; j < countmasel; j++)
            {
                Model3DGroup model = importer.Load(smodel);
                int          idd   = win.rand.Next(0, 100000);
                for (int i = 0; i < model.Children.Count; i++)
                {
                    GeometryModel3D   gmodel = model.Children[i] as GeometryModel3D;
                    MeshGeometry3D    mmodel = (MeshGeometry3D)gmodel.Geometry;
                    Point3DCollection p3dc   = mmodel.Positions;
                }
                double xx = 9999;
                double yy = 9999;
                double zz = 9999;
                for (int i = 0; i < model.Children.Count; i++)
                {
                    GeometryModel3D   gmodel = model.Children[i] as GeometryModel3D;
                    MeshGeometry3D    mmodel = (MeshGeometry3D)gmodel.Geometry;
                    Point3DCollection p3dc   = mmodel.Positions;
                    if (gmodel.Bounds.SizeX > maxx)
                    {
                        maxx = gmodel.Bounds.SizeX;
                    }
                    if (gmodel.Bounds.SizeY > maxx)
                    {
                        maxx = gmodel.Bounds.SizeY;
                    }
                    if (gmodel.Bounds.SizeZ > maxx)
                    {
                        maxx = gmodel.Bounds.SizeZ;
                    }
                    if (gmodel.Bounds.X < xx)
                    {
                        xx = gmodel.Bounds.X;
                    }
                    if (gmodel.Bounds.Y < yy)
                    {
                        yy = gmodel.Bounds.Y;
                    }
                    if (gmodel.Bounds.Z < zz)
                    {
                        zz = gmodel.Bounds.Z;
                    }
                }
                for (int i = 0; i < model.Children.Count; i++)
                {
                    GeometryModel3D gmodel = new GeometryModel3D();
                    gmodel = model.Children[i] as GeometryModel3D;
                    MeshGeometry3D mmodel = (MeshGeometry3D)gmodel.Geometry;
                    gmodel.Material = new DiffuseMaterial(win.defcolor);
                    Point3DCollection p3dc = mmodel.Positions;
                    for (int ii = 0; ii < p3dc.Count; ii++)
                    {
                        Point3D tp = p3dc[ii];
                        tp.X     = tp.X / maxx;
                        tp.Y     = tp.Y / maxx;
                        tp.Z     = tp.Z / maxx;
                        p3dc[ii] = tp;
                    }
                    for (int ii = 0; ii < p3dc.Count; ii++)
                    {
                        Point3D tp = p3dc[ii];
                        tp.X     = tp.X - xx / maxx;
                        tp.Y     = tp.Y - yy / maxx;
                        tp.Z     = tp.Z - zz / maxx;
                        p3dc[ii] = tp;
                    }
                    ModelUIElement3D modelUI = new ModelUIElement3D();
                    modelUI.Model = gmodel;
                    _3DObject      tempmodel1 = win.CreatedElements[mod.GetHashCode()] as _3DObject;
                    ElementCabinet tempmodel  = new ElementCabinet(modelUI, 1, 1, 1, 0, 0, 0);
                    tempmodel.idtexture   = simgid;
                    tempmodel.groupel     = tempmodel1.groupel;
                    tempmodel.ingroupel   = "Element-" + idd;
                    tempmodel.iningroupel = "El";
                    tempmodel.hashtable   = win.CreatedElements;
                    win.CreatedElements.Add(modelUI.GetHashCode(), tempmodel);
                    win.container.Children.Add(modelUI);
                    modelUI.MouseUp    += win.ClickOnModel;
                    tempmodel.LenZ      = 2;
                    tempmodel.idelement = id;
                    ElementCabinet tmp = win.CreatedElements[masel[j].GetHashCode()] as ElementCabinet;
                    tempmodel.select = tmp;
                    tempmodel.changeObjectLen(0.1, 0.1, 0.1);
                    tempmodel.changeObjectPos(tmp.getPosX() + tmp.getLenX() / 2, tmp.getPosY() + tmp.getLenY() / 2, tmp.getPosZ() + tmp.getLenZ() / 2);
                    tempmodel.otsx = tmp.getLenX() / 2;
                    tempmodel.otsy = tmp.getLenY() / 2;
                    tempmodel.otsz = tmp.getLenZ() / 2;
                    tempmodel.thismodel.Material = new DiffuseMaterial(new SolidColorBrush(win.defcolor.Color));
                }
            }
        }
Exemple #2
0
        public void DefineCost()
        {
            CostArr     = new ArrayList[hash.Count];
            materialArr = new ArrayList[hash.Count];
            sizeArr     = new ArrayList[hash.Count];
            nameArr     = new ArrayList[hash.Count];
            for (int i = 0; i < CostArr.Length; i++)
            {
                CostArr[i]     = new ArrayList();
                materialArr[i] = new ArrayList();
                sizeArr[i]     = new ArrayList();
                nameArr[i]     = new ArrayList();
            }
            int ind = 0;

            foreach (var item in hash)
            {
                DictionaryEntry tmp1 = (DictionaryEntry)item;
                ArrayList       tmp2 = tmp1.Value as ArrayList;
                for (int i = 0; i < tmp2.Count; i++)
                {
                    ElementCabinet elcab  = tmp2[i] as ElementCabinet;
                    string[]       tmpstr = elcab.ingroupel.Split('-');
                    if (tmpstr[0] != "Element")
                    {
                        string           request          = "select sizes,price,name from materials where id=" + elcab.idtexture;
                        NpgsqlConnection npgSqlConnection = new NpgsqlConnection(connectionString);
                        npgSqlConnection.Open();
                        NpgsqlCommand    npgSqlCommand = new NpgsqlCommand(request, npgSqlConnection);
                        NpgsqlDataReader reader        = npgSqlCommand.ExecuteReader();
                        int[]            sizes         = null;
                        double           price         = 0;
                        while (reader.Read())
                        {
                            sizes = reader[0] as int[];
                            price = reader.GetDouble(1);
                            materialArr[ind].Add(reader.GetString(2));
                        }
                        long   valueEl    = sizes[0] * sizes[1] * sizes[2];
                        double price1Cube = price / valueEl;

                        if (elcab.ingroupel != "Rack")
                        {
                            CostArr[ind].Add(Math.Abs(Math.Round(elcab.getLenX() * 1000 * elcab.getLenY() * 1000 * elcab.getLenZ() * 1000 * price1Cube, 2)));
                        }
                        else
                        {
                            CostArr[ind].Add(Math.Abs(Math.Round(elcab.getLenX() * 1000 * Math.PI * ((elcab.getLenZ() * 1000 / 2) * (elcab.getLenZ() * 1000 / 2)) * price1Cube, 2)));
                        }
                        sizeArr[ind].Add(Math.Abs(Math.Round(elcab.getLenX(), 3)) * 1000 + " x " + Math.Abs(Math.Round(elcab.getLenY(), 3)) * 1000 + " x " + Math.Abs(Math.Round(elcab.getLenZ(), 3)) * 1000);
                    }
                    else
                    {
                        string           request          = "select price,name from elements where id=" + elcab.idelement;
                        NpgsqlConnection npgSqlConnection = new NpgsqlConnection(connectionString);
                        npgSqlConnection.Open();
                        NpgsqlCommand    npgSqlCommand = new NpgsqlCommand(request, npgSqlConnection);
                        NpgsqlDataReader reader        = npgSqlCommand.ExecuteReader();
                        double           price         = 0;
                        while (reader.Read())
                        {
                            price = reader.GetDouble(0);
                            materialArr[ind].Add(reader.GetString(1));
                        }
                        CostArr[ind].Add(Math.Round(price, 2));
                        sizeArr[ind].Add("-");
                    }
                    ElementCabinet element = tmp2[i] as ElementCabinet;
                    string         name    = "";
                    if (element.ingroupel == "WallL")
                    {
                        name = "Стена корпуса левая.";
                    }
                    if (element.ingroupel == "WallR")
                    {
                        name = "Стена корпуса правая.";
                    }
                    if (element.ingroupel == "WallB")
                    {
                        name = "Стена корпуса задняя.";
                    }
                    if (element.ingroupel == "WallF")
                    {
                        name = "Стена корпуса - цоколь.";
                    }
                    if (element.ingroupel == "Ceiling")
                    {
                        name = "Потолок корпуса.";
                    }
                    if (element.ingroupel == "Floor" || element.ingroupel == "FloorFoot")
                    {
                        name = "Пол корпуса.";
                    }
                    if (element.ingroupel == "Rack")
                    {
                        name = "Вешалка.";
                    }
                    if (element.ingroupel == "ShelfC")
                    {
                        name = "Полочка.";
                    }
                    if (element.ingroupel == "WallC")
                    {
                        name = "Стена.";
                    }
                    if (element.ingroupel == "Door")
                    {
                        name = "Двери.";
                    }
                    if (element.iningroupel == "WR")
                    {
                        name = "Стена ящика правая.";
                    }
                    if (element.iningroupel == "WL")
                    {
                        name = "Стена ящика левая.";
                    }
                    if (element.iningroupel == "WF")
                    {
                        name = "Стена ящика передняя.";
                    }
                    if (element.iningroupel == "WB")
                    {
                        name = "Стена ящика задняя.";
                    }
                    if (element.iningroupel == "WFF")
                    {
                        name = "Стена ящика лицевая.";
                    }
                    if (element.iningroupel == "WD")
                    {
                        name = "Пол ящика.";
                    }
                    if (element.iningroupel == "El")
                    {
                        name = "Елемент мебели.";
                    }
                    if (element.iningroupel == "DoorL")
                    {
                        name = "Левая дверь.";
                    }
                    if (element.iningroupel == "DoorR")
                    {
                        name = " Правая дверь.";
                    }
                    nameArr[ind].Add(name);
                }
                ind++;
            }
            all    = new ArrayList[hash.Count];
            counts = new ArrayList[hash.Count];
            for (int i = 0; i < all.Length; i++)
            {
                all[i]    = new ArrayList();
                counts[i] = new ArrayList();
            }
            for (int i = 0; i < all.Length; i++)
            {
                ArrayList tmp = nameArr[i] as ArrayList;
                for (int j = 0; j < tmp.Count; j++)
                {
                    Row tmprow = new Row {
                        name = nameArr[i][j].ToString(), material = materialArr[i][j].ToString(), size = sizeArr[i][j].ToString(), price = Convert.ToDouble(CostArr[i][j])
                    };
                    if (all[i].IndexOf(tmprow) == -1)
                    {
                        all[i].Add(tmprow); counts[i].Add(1);
                    }
                    else
                    {
                        int id       = all[i].IndexOf(tmprow);
                        int tmpcount = (int)counts[i][id];
                        tmpcount++;
                        counts[i][id] = tmpcount;
                    }
                }
            }
            ArrayList [] alldp    = new ArrayList[all.Length];
            ArrayList[]  countsdp = new ArrayList[all.Length];
            for (int i = 0; i < alldp.Length; i++)
            {
                alldp[i]    = new ArrayList();
                countsdp[i] = new ArrayList();
            }
            for (int i = 0; i < alldp.Length; i++)
            {
                ArrayList tmp1 = all[i] as ArrayList;
                ArrayList tmp2 = counts[i] as ArrayList;
                for (int j = 0; j < tmp1.Count; j++)
                {
                    Row tmprow    = (Row)tmp1[j];
                    int tmpcount  = (int)tmp2[j];
                    Row tmprow1   = (Row)tmp1[j];
                    int tmpcount1 = (int)tmp2[j];
                    if (tmprow.name.IndexOf("корпуса") != -1)
                    {
                        if (tmprow.name == "Стена корпуса задняя.")
                        {
                            string[] ss = tmprow.size.Split('x'); double dd = (2 * int.Parse(ss[0]) + 2 * int.Parse(ss[2])) / 100; tmpcount = (int)dd; tmprow.name = "Гвоздь обивочный"; tmprow.material = "Сталь"; tmprow.size = "1x0,1"; tmprow.price = 0.25;
                        }
                        else
                        {
                            tmprow.name = "Конфирмат"; tmprow.material = "Сталь"; tmprow.size = "5x0,5"; tmprow.price = 0.5; tmpcount = 2;
                        }
                        alldp[i].Add(tmprow); countsdp[i].Add(tmpcount);
                        string[] ss1 = tmprow1.size.Split('x');
                        int[]    arr = new int[] { int.Parse(ss1[0]), int.Parse(ss1[1]), int.Parse(ss1[2]) };
                        Array.Sort(arr);
                        double dd1 = (2 * arr[1] + 2 * arr[2]) / 1000.0; tmpcount = (int)Math.Ceiling(dd1); tmprow.name = "Раскрой"; tmprow.material = "-"; tmprow.size = "-"; tmprow.price = 7;
                        alldp[i].Add(tmprow); countsdp[i].Add(tmpcount);
                    }

                    if (tmprow.name.IndexOf("ящика") != -1)
                    {
                        if (tmprow.name == "Пол ящика.")
                        {
                            string[] ss = tmprow.size.Split('x'); double dd = (2 * int.Parse(ss[0]) + 2 * int.Parse(ss[1])) / 100; tmpcount = (int)dd; tmprow.name = "Гвоздь обивочный"; tmprow.material = "Сталь"; tmprow.size = "1x0,1"; tmprow.price = 0.25;
                        }
                        else
                        {
                            tmprow.name = "Конфирмат"; tmprow.material = "Сталь"; tmprow.size = "5x0,5"; tmprow.price = 0.5; tmpcount = 2;
                        }
                        alldp[i].Add(tmprow); countsdp[i].Add(tmpcount);
                        string[] ss1 = tmprow1.size.Split('x');
                        int[]    arr = new int[] { int.Parse(ss1[0]), int.Parse(ss1[1]), int.Parse(ss1[2]) };
                        Array.Sort(arr);
                        double dd1 = (2 * arr[1] + 2 * arr[2]) / 1000.0; tmpcount = (int)Math.Ceiling(dd1); tmprow.name = "Раскрой"; tmprow.material = "-"; tmprow.size = "-"; tmprow.price = 7;
                        alldp[i].Add(tmprow); countsdp[i].Add(tmpcount);
                    }
                    if (tmprow.name.IndexOf("вер") != -1)
                    {
                        tmprow.name = "Петля накладная"; tmprow.material = "Сталь"; tmprow.size = "-"; tmprow.price = 6.5; tmpcount = 2;
                        alldp[i].Add(tmprow); countsdp[i].Add(tmpcount);
                        string[] ss1 = tmprow1.size.Split('x');
                        int[]    arr = new int[] { int.Parse(ss1[0]), int.Parse(ss1[1]), int.Parse(ss1[2]) };
                        Array.Sort(arr);
                        double dd1 = (2 * arr[1] + 2 * arr[2]) / 1000.0; tmpcount = (int)Math.Ceiling(dd1); tmprow.name = "Раскрой"; tmprow.material = "-"; tmprow.size = "-"; tmprow.price = 7;
                        alldp[i].Add(tmprow); countsdp[i].Add(tmpcount);
                    }
                    if (tmprow.name == "Полочка." || tmprow.name == "Стена.")
                    {
                        tmprow.name = "Конфирмат"; tmprow.material = "Сталь"; tmprow.size = "5x0,5"; tmprow.price = 0.5; tmpcount = 4;
                        alldp[i].Add(tmprow); countsdp[i].Add(tmpcount);
                        string[] ss1 = tmprow1.size.Split('x');
                        int[]    arr = new int[] { int.Parse(ss1[0]), int.Parse(ss1[1]), int.Parse(ss1[2]) };
                        Array.Sort(arr);
                        double dd1 = (2 * arr[1] + 2 * arr[2]) / 1000.0; tmpcount = (int)Math.Ceiling(dd1); tmprow.name = "Раскрой"; tmprow.material = "-"; tmprow.size = "-"; tmprow.price = 7;
                        alldp[i].Add(tmprow); countsdp[i].Add(tmpcount);
                    }
                }
            }

            for (int i = 0; i < alldp.Length; i++)
            {
                ArrayList tmp1 = alldp[i] as ArrayList;
                ArrayList tmp2 = countsdp[i] as ArrayList;
                for (int j = 0; j < tmp1.Count; j++)
                {
                    Row tmprow   = (Row)tmp1[j];
                    int tmpcount = (int)tmp2[j];
                    if (all[i].IndexOf(tmprow) == -1)
                    {
                        all[i].Add(tmprow); counts[i].Add(tmpcount);
                    }
                    else
                    {
                        int id        = all[i].IndexOf(tmprow);
                        int tmpcount1 = (int)counts[i][id];
                        tmpcount1    += tmpcount;
                        counts[i][id] = tmpcount1;
                    }
                }
            }
        }