private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Internet.send(new ExecutiveToServer()
                {
                    requestType = RequestType.GetEquipmentWithFamilies, searchString = textBox1.Text
                });
                response = Internet.receive();
                if (response.success)
                {
                    for (int i = 0; i < response.equipments.Count; i++)
                    {
                        TableLayoutPanel panel = new TableLayoutPanel();
                        panel.RowCount    = 2;
                        panel.ColumnCount = 3;
                        panel.RowStyles.Clear();
                        for (int j = 0; j < 2; j++)
                        {
                            panel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
                        }
                        panel.ColumnStyles.Clear();
                        panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150));
                        panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
                        panel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150));

                        PictureBox box = new PictureBox()
                        {
                            Width = 150, Height = 150
                        };
                        box.Image = Image.FromStream(new MemoryStream(Convert.FromBase64String(response.equipments[i].preview)));
                        panel.Controls.Add(box, 0, 0);
                        panel.SetRowSpan(box, 2);

                        Label name = new Label()
                        {
                            Text = response.equipments[i].name, Dock = DockStyle.Fill
                        };
                        panel.Controls.Add(name, 1, 0);

                        Label desc = new Label()
                        {
                            Text = response.equipments[i].description, Dock = DockStyle.Fill
                        };
                        panel.Controls.Add(desc, 1, 1);

                        Button add = new Button()
                        {
                            Text = "Добавить"
                        };
                        int buff = i;
                        add.MouseClick += (a, b) =>
                        {
                            equipment    = response.equipments[i];
                            DialogResult = DialogResult.OK;
                            Close();
                        };
                        panel.Controls.Add(add, 2, 0);

                        panel1.Controls.Add(panel);
                        panel.Location = new Point(0, 151 * i);
                        Refresh();
                    }
                }
            }
        }
Example #2
0
        private void добавитьСхемуToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Searcher searcher = new Searcher();

            if (searcher.ShowDialog() == DialogResult.OK)
            {
                Equipment result            = searcher.result;
                List <Equipment.Point> fake = new List <Equipment.Point>();
                radiusesFixer(ref result, ref fake);
                if (result.isBox)
                {
                    mainList.RemoveAll(x => x.id == result.id);
                    mainList.Add(result);



                    List <Point> real = new List <Point>();
                    for (int i = 0; i < 4; i++)
                    {
                        if (fake[i] == null)
                        {
                            real.Add(new Point(100, 100)); continue;
                        }
                        float x = (float)Math.Sqrt(10000 / (fake[i].X * fake[i].Y));
                        real.Add(new Point()
                        {
                            X = (int)(fake[i].X * x), Y = (int)(fake[i].Y * x)
                        });
                    }


                    int    id        = RevitProvider.createInstance(result.bytedFile, result.name);
                    bool   hasFamily = id != -1;
                    Random r         = new Random();
                    if (!hasFamily)
                    {
                        id = -1 * r.Next(0, int.MaxValue);
                        while (mainWorkList.Exists(x => x.localID == id))
                        {
                            id = -1 * r.Next(0, int.MaxValue);
                        }
                    }
                    mainWorkList.Add(new boxes()
                    {
                        hasFamily = hasFamily, localID = id, globalId = result.id, locations = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0) }, scales = real.ToArray()
                    });
                    List <drawer> sortedList = new List <drawer>();
                    sortedList.AddRange(mainWorkList.FindAll(x => x is boxes));
                    sortedList.AddRange(mainWorkList.FindAll(x => !(x is boxes)));
                    mainWorkList = sortedList;
                }
                else if (result.isInBox)
                {
                    mainList.RemoveAll(x => x.id == result.id);
                    mainList.Add(result);


                    //calculate proportions for 10 000


                    List <Point> real = new List <Point>();
                    for (int i = 0; i < 4; i++)
                    {
                        if (fake[i] == null)
                        {
                            real.Add(new Point(100, 100));
                            continue;
                        }
                        float x = (float)Math.Sqrt(10000 / (fake[i].X * fake[i].Y));
                        real.Add(new Point()
                        {
                            X = (int)(fake[i].X * x), Y = (int)(fake[i].Y * x)
                        });
                    }


                    int    id        = RevitProvider.createInstance(result.bytedFile, result.name);
                    bool   hasFamily = id != -1;
                    Random r         = new Random();
                    if (!hasFamily)
                    {
                        id = -1 * r.Next(0, int.MaxValue);
                        while (mainWorkList.Exists(x => x.localID == id))
                        {
                            id = -1 * r.Next(0, int.MaxValue);
                        }
                    }

                    mainWorkList.Add(new inboxes()
                    {
                        hasFamily     = hasFamily,
                        numberOfUnits = Convert.ToInt32(result.properties["Занимаемых юнитов (шт)"]),
                        localID       = id,
                        globalId      = result.id,
                        locations     = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0) },
                        scales        = real.ToArray()
                    });
                }
                else if (result.isWire)
                {
                    int current = -1;
                    foreach (var i in wires)
                    {
                        if (i.localID > current)
                        {
                            current = i.localID;
                        }
                    }
                    current++;
                    if (!mainList.Exists(x => x.id == result.id))
                    {
                        mainList.Add(result);
                    }


                    if (result.compatibilities.Count == 1)
                    {
                        wires.Add(new Wire()
                        {
                            localID = current, globalId = result.id, MyOwnFirst = result.compatibilities[0], MyOwnSecond = result.compatibilities[0]
                        });
                    }
                    else
                    {
                        wires.Add(new Wire()
                        {
                            localID = current, globalId = result.id, MyOwnFirst = result.compatibilities[0], MyOwnSecond = result.compatibilities[1]
                        });
                    }
                    tabControl1.SelectedIndex = 1;
                    //      MessageBox.Show("выберите начальное оборудование");
                    ConnectionController.targetWire = wires[wires.Count - 1];
                    ConnectionController.Mode       = modeConnection.buildConnection;
                }
                else
                {
                    mainList.RemoveAll(x => x.id == result.id);
                    mainList.Add(result);
                    //calculate proportions for 10 000

                    List <Point> real = new List <Point>();
                    for (int i = 0; i < 4; i++)
                    {
                        if (fake[i] == null)
                        {
                            real.Add(new Point(100, 100)); continue;
                        }
                        float x = (float)Math.Sqrt(10000 / (fake[i].X * fake[i].Y));
                        real.Add(new Point()
                        {
                            X = (int)(fake[i].X * x), Y = (int)(fake[i].Y * x)
                        });
                    }

                    int    id        = RevitProvider.createInstance(result.bytedFile, result.name);
                    bool   hasFamily = id != -1;
                    Random r         = new Random();
                    if (!hasFamily)
                    {
                        id = -1 * r.Next(0, int.MaxValue);
                        while (mainWorkList.Exists(x => x.localID == id))
                        {
                            id = -1 * r.Next(0, int.MaxValue);
                        }
                    }

                    mainWorkList.Add(new free()
                    {
                        hasFamily = hasFamily,
                        localID   = id,
                        globalId  = result.id,
                        locations = new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0), new Point(0, 0) },
                        scales    = real.ToArray()
                    });
                }
                foreach (var i in mainWorkList)
                {
                    i.drawBox(gr[sheetIndex]);
                }
                pictureBox3.Image = bitmaps[0];
                pictureBox2.Image = bitmaps[1];
                pictureBox1.Image = bitmaps[2];
                strct.Image       = bitmaps[3];
                Refresh();
            }
        }
Example #3
0
        void radiusesFixer(ref Equipment result, ref List <Equipment.Point> fake)
        {
            if (result.inConnectionScheme != null)
            {
                foreach (var i in result.inConnectionScheme.circles)
                {
                    i.radiusX = i.radius;
                    i.radiusY = i.radius;
                }
            }
            if (result.inStructural != null)
            {
                foreach (var i in result.inStructural.circles)
                {
                    i.radiusX = i.radius;
                    i.radiusY = i.radius;
                }
            }
            if (result.inBox != null)
            {
                foreach (var i in result.inBox.circles)
                {
                    i.radiusX = i.radius;
                    i.radiusY = i.radius;
                }
            }

            if (result.inPlacementScheme != null)
            {
                foreach (var i in result.inPlacementScheme.circles)
                {
                    i.radiusX = i.radius;
                    i.radiusY = i.radius;
                }
            }

            fake = new List <Equipment.Point>();
            if (result.inPlacementScheme != null)
            {
                fake.Add(result.inPlacementScheme.GetProp());
            }
            else
            {
                fake.Add(null);
            }
            if (result.inConnectionScheme != null)
            {
                fake.Add(result.inConnectionScheme.GetProp());
            }
            else
            {
                fake.Add(null);
            }
            if (result.inBox != null)
            {
                fake.Add(result.inBox.GetProp());
            }
            else
            {
                fake.Add(null);
            }
            if (result.inStructural != null)
            {
                fake.Add(result.inStructural.GetProp());
            }
            else
            {
                fake.Add(null);
            }
        }
        public static int copy(Equipment target)
        {
            int id = -1;
            ////
            Transaction tr = null;

            try
            {
                File.Create(target.name + ".rfa").Close();
                File.WriteAllBytes(target.name + ".rfa", target.bytedFile);

                Document doc = commandData.Application.ActiveUIDocument.Document;
                Autodesk.Revit.DB.Family family = null;

                tr = new Transaction(doc);
                tr.Start("My Super trans");
                //попытка найти существующее семейство
                var  search = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).Cast <FamilySymbol>().ToList();
                bool good   = false;
                foreach (FamilySymbol symbq in search)
                {
                    if (symbq.Family.Name == target.name)
                    {
                        if (!symbq.IsActive)
                        {
                            symbq.Activate();
                        }
                        var buffInstance = doc.Create.NewFamilyInstance(new XYZ(0, 0, 0), symbq, structuralType: Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
                        buffInstance.Id.ToString();
                        id   = Convert.ToInt32(buffInstance.Id.ToString());
                        good = true;
                        break;
                    }
                }
                tr.Commit();
            }
            catch (Exception ex)
            {
                id = -1;
                try
                {
                    tr.Commit();
                }
                catch (Exception eeee)
                {
                }
            }
            if (id == -1)
            {
                id = -1;
                ////
                int max = int.MinValue;
                foreach (var i in Schemes_Editor.mainWorkList)
                {
                    if (i.localID > max)
                    {
                        max = i.localID;
                    }
                }
                max++;
                return(max);
            }
            return(id);
        }