Esempio n. 1
0
        private void DisplayRoomData()
        {
            try
            {
                progressForm.LabelText = "Preparing Components to be Displayed..";
                progressForm.CurValue  = 1;
                progressForm.Refresh();

                foreach (int roomId in roomDictionary.Keys)
                {
                    progressForm.PerformStep();
                    RoomProperties rp = roomDictionary[roomId];

                    int             index = dataGridViewRoom.Rows.Add();
                    DataGridViewRow row   = dataGridViewRoom.Rows[index];
                    row.Tag            = rp;
                    row.Cells[0].Value = false;
                    row.Cells[1].Value = rp.Number;
                    row.Cells[2].Value = rp.Name;
                    row.Cells[3].Value = rp.Department;
                    row.Cells[4].Value = rp.Level;
                    row.Cells[5].Value = rp.Phase;
                    row.Cells[6].Value = rp.DesignOption;

                    if (placedRooms.Contains(rp.ID))
                    {
                        //row.Cells[0].ReadOnly = true;
                        row.Cells[0].Value             = false;
                        row.DefaultCellStyle.ForeColor = System.Drawing.Color.Gray;
                        foreach (DataGridViewCell cell in row.Cells)
                        {
                            cell.ToolTipText = rp.ID + ": Mass family is already placed in the project.";
                        }
                    }
                    if (roomDiscrepancy.Contains(rp.ID))
                    {
                        row.Cells[0].Value             = true;
                        row.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
                        foreach (DataGridViewCell cell in row.Cells)
                        {
                            cell.ToolTipText = rp.ID + ": Room boundary lines have been changed.";
                        }
                    }
                }

                if (defDictionary.Count > 0)
                {
                    string parameters = "";
                    foreach (string defName in defDictionary.Keys)
                    {
                        parameters += "[" + defName + "]   ";
                    }
                    richTextBoxParameters.Text = parameters;
                }

                progressForm.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to display room data.\n" + ex.Message, "Form_CreateMass:DisplayRoomData", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                progressForm.Close();
            }
        }
Esempio n. 2
0
        private void bttnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                List <int> checkedRows = new List <int>();
                for (int i = 0; i < dataGridViewRoom.Rows.Count; i++)
                {
                    if (Convert.ToBoolean(dataGridViewRoom.Rows[i].Cells[0].Value))
                    {
                        checkedRows.Add(i);
                    }
                }

                if (checkedRows.Count > 0)
                {
                    using (TransactionGroup tg = new TransactionGroup(doc))
                    {
                        tg.Start("Update Masses");
                        try
                        {
                            double height = 0;
                            if (checkBoxHeight.Checked)
                            {
                                if (!ValidateHeight(out height))
                                {
                                    MessageBox.Show("Please enter a valid room height.", "Room Height Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                                else if (height == 0)
                                {
                                    MessageBox.Show("Please enter a valid room height.", "Room Height Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                            }

                            massCreator.DefDictionary = defDictionary;

                            Dictionary <int, RoomProperties> createdRooms = new Dictionary <int, RoomProperties>(); //created rooms at this run
                            Dictionary <int, MassProperties> placedMasses = new Dictionary <int, MassProperties>();

                            statusLabel.Text             = "Updating Masses . . .";
                            toolStripProgressBar.Maximum = checkedRows.Count;
                            toolStripProgressBar.Visible = true;

                            StringBuilder resultMessage = new StringBuilder();

                            foreach (int index in checkedRows)
                            {
                                toolStripProgressBar.PerformStep();
                                DataGridViewRow row = dataGridViewRoom.Rows[index];
                                if (null != row.Tag)
                                {
                                    RoomProperties rp = row.Tag as RoomProperties;
                                    MassProperties mp = new MassProperties();
                                    mp.HostElementId   = rp.ID;
                                    rp.IsDefaultHeight = checkBoxHeight.Checked;
                                    rp.DefaultHeight   = height;

                                    if (placedRooms.Contains(rp.ID))
                                    {
                                        FamilyInstance instance = MassUtils.FindMassById(doc, rp.ID);
                                        if (null != instance)
                                        {
                                            mp.MassFamilyInstance = instance;
                                            double roomHeight = (rp.IsDefaultHeight == true) ? rp.DefaultHeight : rp.UnboundedHeight;
#if RELEASE2015 || RELEASE2016
                                            Parameter parameter = instance.LookupParameter("Height");
#elif RELEASE2013 || RELEASE2014
                                            Parameter parameter = instance.get_Parameter("Height");
#endif

                                            if (null != parameter)
                                            {
                                                using (Transaction trans = new Transaction(doc))
                                                {
                                                    trans.Start("Update Height");
                                                    try
                                                    {
                                                        parameter.Set(roomHeight);
                                                        trans.Commit();
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        string message = ex.Message;
                                                        trans.RollBack();
                                                    }
                                                }
                                            }

                                            if (!placedMasses.ContainsKey(rp.ID))
                                            {
                                                placedMasses.Add(rp.ID, mp);
                                            }

                                            resultMessage.AppendLine(rp.ID + "\t" + rp.Number + "\t" + rp.Name);
                                        }
                                        continue;
                                    }

                                    if (roomDiscrepancy.Contains(rp.ID))
                                    {
                                        FamilyInstance instance = MassUtils.FindMassById(doc, rp.ID);
                                        if (null != instance)
                                        {
                                            using (Transaction trans = new Transaction(doc))
                                            {
                                                trans.Start("Delete Element");
                                                doc.Delete(instance.Id);
                                                trans.Commit();
                                            }
                                        }
                                    }

                                    FamilyInstance familyInstance = massCreator.CreateFamily(rp);
                                    if (null != familyInstance)
                                    {
                                        mp.MassFamilyInstance = familyInstance;
                                        if (!placedMasses.ContainsKey(rp.ID))
                                        {
                                            placedMasses.Add(rp.ID, mp);
                                        }
                                    }

                                    createdRooms.Add(rp.ID, rp);
                                    resultMessage.AppendLine(rp.ID + "\t" + rp.Number + "\t" + rp.Name);
                                }
                            }
                            //to include placed masses from the previous run into the snapshot.png
                            foreach (int roomId in placedRooms)
                            {
                                FamilyInstance instance = MassUtils.FindMassById(doc, roomId);
                                MassProperties mp       = new MassProperties();
                                if (null != instance)
                                {
                                    mp.MassFamilyInstance = instance;
                                    if (!placedMasses.ContainsKey(roomId))
                                    {
                                        placedMasses.Add(roomId, mp);
                                    }
                                }
                            }

                            statusLabel.Text             = "Done";
                            roomDataManager.CreatedRooms = createdRooms;
                            roomDataManager.WriteINI();
                            if (massCreator.FailureMessage.Length > 0)
                            {
                                DialogResult dr = MessageBox.Show("Errors occured while creating extrusion forms.\n" + massCreator.FailureMessage.ToString(), "Warning Messages", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                if (dr == DialogResult.OK)
                                {
                                    using (Transaction trans = new Transaction(doc))
                                    {
                                        trans.Start("Set Shared Parameters");
                                        m_app.Application.SharedParametersFilename = originalDefFile;
                                        trans.Commit();
                                    }

                                    this.Close();
                                }
                            }
                            else
                            {
                                if (resultMessage.Length > 0)
                                {
                                    string         header      = "Room Masses are sucessfully updated. \n[Room ID], [Room Number], [Room Name]\n";
                                    MessageBoxForm messageForm = new MessageBoxForm("Completion Messages", header + resultMessage.ToString(), "", false, false);
                                    if (DialogResult.OK == messageForm.ShowDialog())
                                    {
                                        using (Transaction trans = new Transaction(doc))
                                        {
                                            trans.Start("Set Shared Parameters");
                                            m_app.Application.SharedParametersFilename = originalDefFile;
                                            trans.Commit();
                                        }
                                        this.Close();
                                    }
                                }
                            }
                            tg.Assimilate();
                        }
                        catch (Exception ex)
                        {
                            tg.RollBack();
                            MessageBox.Show("Failed to update masses from rooms.\n" + ex.Message, "Create Masses from Rooms", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please select at leaset one Room item to proceed.", "Empty Selection", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create mass rooms.\n" + ex.Message, "Form_CreateMass:BttnCreate_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }