public DialogWindowWallAuto(RebarInfoWall riw)
        {
            InitializeComponent();

            rebarInfo = riw;

            radioButtonFreeLengthAuto.Checked   = riw.autoVerticalFreeLength;
            numericUpDownHorizOffset.Value      = (decimal)(304.8 * riw.bottomOffset);
            checkBoxAddHorizStep.Checked        = riw.horizontalAddInterval;
            checkBoxAdditionalStepSpace.Checked = riw.horizontalAdditionalStepSpace;

            textBoxRazdelVert.Text  = riw.verticalSectionText;
            textBoxRazdelHoris.Text = riw.horizontalSectionText;
        }
Beispiel #2
0
        public DialogWindowWall(RebarInfoWall reinfInfo, List <string> rebarTypes1, List <string> rebarTypes2)
        {
            InitializeComponent();

            wri = reinfInfo;

            checkBoxGenerateHorizontal.Checked = reinfInfo.generateHorizontal;
            txtBoxHorizArmSection.Text         = reinfInfo.horizontalSectionText;
            checkBoxGenerateVertical.Checked   = reinfInfo.generateVertical;
            txtBoxVertArmSection.Text          = reinfInfo.verticalSectionText;

            txtBackOffset.Text     = (reinfInfo.backOffset * 304.8).ToString();
            txtBottomOffset.Text   = (reinfInfo.bottomOffset * 304.8).ToString();
            txtTopOffset.Text      = (reinfInfo.topOffset * 304.8).ToString();
            txtVerticalOffset.Text = (reinfInfo.verticalOffset * 304.8).ToString();

            txtHorizontalInterval.Text = (reinfInfo.horizontalRebarInterval * 304.8).ToString();
            txtVerticalInterval.Text   = (reinfInfo.verticalRebarInterval * 304.8).ToString();

            txtRebarCover.Text = (reinfInfo.rebarCover * 304.8).ToString();

            txtVerticalFreeLength.Text            = (reinfInfo.verticalFreeLength * 304.8).ToString();
            checkBoxAutoVerticalFreeLengh.Checked = wri.autoVerticalFreeLength;
            txtHorizontalFreeLength.Text          = (reinfInfo.horizontalFreeLength * 304.8).ToString();

            cmbHorizonalType.DataSource   = rebarTypes1;
            cmbVerticalType.DataSource    = rebarTypes2;
            cmbHorizonalType.SelectedItem = reinfInfo.horizontalRebarTypeName;
            cmbVerticalType.SelectedItem  = reinfInfo.verticalRebarTypeName;

            checkBoxHorizAddInterval.Checked = reinfInfo.horizontalAddInterval;

            checkBoxUnificateLength.Checked = reinfInfo.useUnification;
            foreach (double len in reinfInfo.lengthsUnification)
            {
                string letText = (len * 304.8).ToString("F0");
                textBoxLengths.Text += letText + ";";
            }

            this.Text = "Армирование стен. Версия " + System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();
        }
        public static List <string> GenerateRebar(Document doc, Wall wall, RebarInfoWall wri, RebarCoverType zeroCover, ElementId areaTypeId)
        {
            Debug.WriteLine("Start reinforcement for wall: " + wall.Id.IntegerValue.ToString());
            List <string> messages = new List <string>();

            double      lengthRound      = 5 / 304.8;
            ProjectInfo pi               = doc.ProjectInformation;
            Parameter   roundLengthParam = pi.LookupParameter("Арм.ОкруглениеДлины");

            if (roundLengthParam != null && roundLengthParam.HasValue)
            {
                lengthRound = roundLengthParam.AsDouble();
            }

            wall.get_Parameter(BuiltInParameter.CLEAR_COVER_OTHER).Set(zeroCover.Id);
            Debug.WriteLine("Set zero rebar cover for other faces");

            Solid       sol       = SupportGeometry.GetSolidFromElement(wall);
            List <Face> vertFaces = SupportGeometry.GetVerticalFaces(sol);
            Face        mainFace  = SupportGeometry.GetLargeFace(vertFaces);
            PlanarFace  pface     = mainFace as PlanarFace;

            Debug.WriteLine("Vertical planar face was found");

            List <Curve> wallOutlineDraft = SupportGeometry.GetFaceOuterBoundary(pface);

            Debug.WriteLine("Outline draft curves found: " + wallOutlineDraft.Count.ToString());

            //удаляю совпадающие линии
            List <Curve> wallOutline = SupportGeometry.CleanLoop(wallOutlineDraft);

            Debug.WriteLine("Outline clean curves found: " + wallOutline.Count.ToString());


            //определяю отступы для защитных слоев
            RebarCoverType coverFront = doc.GetElement(wall.get_Parameter(BuiltInParameter.CLEAR_COVER_EXTERIOR).AsElementId()) as RebarCoverType;
            RebarCoverType coverBack  = doc.GetElement(wall.get_Parameter(BuiltInParameter.CLEAR_COVER_INTERIOR).AsElementId()) as RebarCoverType;

            if (coverFront == null)
            {
                coverFront = coverBack;
            }
            if (coverBack == null)
            {
                coverBack = coverFront;
            }

            double userDefineCover = wri.rebarCover;


            MyRebarType verticalRebarType = new MyRebarType(doc, wri.verticalRebarTypeName);

            if (verticalRebarType.isValid == false)
            {
                messages.Add("Не удалось получить тип стержня " + wri.verticalRebarTypeName);
                Debug.WriteLine("Unable to get vertical rebartype: " + wri.verticalRebarTypeName);
            }
            MyRebarType horizontalRebarType = new MyRebarType(doc, wri.horizontalRebarTypeName);

            if (horizontalRebarType.isValid == false)
            {
                messages.Add("Не удалось получить тип стержня " + wri.horizontalRebarTypeName);
                Debug.WriteLine("Unable to get horizontal rebartype: " + wri.horizontalRebarTypeName);
            }

#if R2017 || R2018 || R2019 || R2020 || R2021
            double vertDiam  = verticalRebarType.bartype.BarDiameter;
            double horizDiam = horizontalRebarType.bartype.BarDiameter;
#else
            double vertDiam  = verticalRebarType.bartype.BarNominalDiameter;
            double horizDiam = horizontalRebarType.bartype.BarNominalDiameter;
#endif

            double offsetVerticalExterior   = userDefineCover - coverFront.CoverDistance - 0.5 * vertDiam;
            double offsetVerticalInterior   = userDefineCover - coverBack.CoverDistance - 0.5 * vertDiam;
            double offsetHorizontalExterior = offsetVerticalExterior - horizDiam;
            double offsetHorizontalInterior = offsetVerticalInterior - horizDiam;


            if (wri.generateVertical)
            {
                Debug.WriteLine("Start creating vertical rebar");
                Parameter paramFloorThickinessParam = wall.LookupParameter("Рзм.ТолщинаПерекрытия");

                if (wri.autoVerticalFreeLength)
                {
                    Debug.WriteLine("Try to auto-calculate vertical free length");
                    if (paramFloorThickinessParam != null && paramFloorThickinessParam.HasValue)
                    {
                        double floorThickness = paramFloorThickinessParam.AsDouble();
                        double freeLength     = ConcreteUtils.getRebarFreeLength(verticalRebarType.bartype, wall, lengthRound);
                        wri.verticalFreeLength = floorThickness + freeLength;
                        Debug.WriteLine("Vertical free length = " + wri.verticalFreeLength);
                    }
                    else
                    {
                        Debug.WriteLine("Unable to auto-calculate vertical free length");
                        throw new Exception("Не задан параметр Рзм.ТолщинаПерекрытия в элементе " + wall.Id.IntegerValue.ToString());
                    }
                }


                List <Curve> curvesVertical = SupportGeometry.MoveLine(wallOutline, wri.verticalFreeLength, SupportGeometry.LineSide.Top);
                Debug.WriteLine("Curves for vertical loop: " + curvesVertical.Count.ToString());

                if (wri.useUnification)
                {
                    Debug.WriteLine("Try to unificate vertical length");
                    double verticalZoneHeight = SupportGeometry.GetZoneHeigth(curvesVertical);
                    double unificateLength    = wri.getNearestLength(verticalZoneHeight);
                    double moveToUnificate    = unificateLength - verticalZoneHeight;
                    if (moveToUnificate > 0.005)
                    {
                        List <Curve> curvesVerticalUnificate = SupportGeometry.MoveLine(curvesVertical, moveToUnificate, SupportGeometry.LineSide.Top);
                        curvesVertical = curvesVerticalUnificate;
                    }
                }


                /*LocationCurve wallLocCurve = wall.Location as LocationCurve;
                 * Line wallCurve = wallLocCurve.Curve as Line;
                 * if (wallCurve == null) throw new Exception("Curved wall!");*/

                double sideOffset = wri.backOffset - 0.5 * vertDiam;

                curvesVertical = SupportGeometry.MoveLine(curvesVertical, sideOffset, SupportGeometry.LineSide.Left);
                curvesVertical = SupportGeometry.MoveLine(curvesVertical, sideOffset, SupportGeometry.LineSide.Right);

                CurveUtils.SortCurvesContiguous(doc.Application.Create, curvesVertical, true);
                Debug.WriteLine("Contiguous curves sort");

                if (wri.verticalOffset < 0.0001)
                {
                    Debug.WriteLine("Generate vertical rebar area without offset");
                    AreaReinforcement arVertical = Generate(doc, wall, curvesVertical, false, true, true, offsetVerticalInterior, offsetVerticalExterior, wri.verticalRebarInterval, areaTypeId, verticalRebarType.bartype, wri.verticalSectionText);
                }
                else
                {
                    Debug.WriteLine("Generate vertical rebar area with offset");
                    AreaReinforcement arVertical1 = Generate(doc, wall, curvesVertical, false, true, false, offsetVerticalInterior, offsetVerticalExterior, wri.verticalRebarInterval, areaTypeId, verticalRebarType.bartype, wri.verticalSectionText);

                    List <Curve> curves2 = SupportGeometry.MoveLine(curvesVertical, wri.verticalOffset, SupportGeometry.LineSide.Top);
                    curves2 = SupportGeometry.MoveLine(curves2, wri.verticalOffset, SupportGeometry.LineSide.Bottom);
                    AreaReinforcement arVertical2 = Generate(doc, wall, curves2, false, false, true, offsetVerticalInterior, offsetVerticalExterior, wri.verticalRebarInterval, areaTypeId, verticalRebarType.bartype, wri.verticalSectionText);
                }
            }

            if (wri.generateHorizontal)
            {
                Debug.WriteLine("Start creating horizontal rebar");
                //определяю контур
                double       horizontalTopOffset    = 0.5 * horizDiam - wri.topOffset;
                double       horizintalBottomOffset = wri.bottomOffset - 0.5 * horizDiam;
                List <Curve> curvesHorizontal       = SupportGeometry.MoveLine(wallOutline, horizontalTopOffset, SupportGeometry.LineSide.Top);
                curvesHorizontal = SupportGeometry.MoveLine(curvesHorizontal, horizintalBottomOffset, SupportGeometry.LineSide.Bottom);

                double sideOffset = wri.horizontalFreeLength * -1;
                curvesHorizontal = SupportGeometry.MoveLine(curvesHorizontal, sideOffset, SupportGeometry.LineSide.Left);
                curvesHorizontal = SupportGeometry.MoveLine(curvesHorizontal, sideOffset, SupportGeometry.LineSide.Right);

                List <AreaRebarInfo> curvesBase = new List <AreaRebarInfo>();


                if (wri.horizontalAddInterval)
                {
                    Debug.WriteLine("Create with additional offset");

                    double horizRebarInterval = wri.horizontalRebarInterval;

                    if (wri.horizontalAdditionalStepSpace)
                    {
                        horizRebarInterval = horizRebarInterval / 2;
                    }

                    double heigth              = SupportGeometry.GetZoneHeigth(curvesHorizontal);
                    double heigthByAxis        = heigth - horizDiam;
                    double countCheckAsDouble1 = heigthByAxis / horizRebarInterval;
                    double countCheckAsDouble2 = Math.Round(countCheckAsDouble1, 2);
                    double countCheckAsDouble3 = Math.Truncate(countCheckAsDouble2);
                    int    countCheck          = (int)countCheckAsDouble3;
                    double addIntervalByAxis   = heigthByAxis - countCheck * horizRebarInterval;
                    if (addIntervalByAxis < horizDiam) //доборный шаг не требуется
                    {
                        Debug.WriteLine("Additional offset not needed");
                        curvesBase.Add(new AreaRebarInfo(curvesHorizontal, horizRebarInterval));
                    }
                    else
                    {
                        Debug.WriteLine("Additional offset = " + (addIntervalByAxis * 304.8).ToString("F3"));
                        int count = countCheck - 1;

                        if (addIntervalByAxis < 50 / 304.8) //доборный шаг менее 50мм - увеличиваю отступ сверху
                        {
                            count--;
                        }

                        double       heigthClean = count * horizRebarInterval;
                        double       offsetMain  = heigth - heigthClean - horizDiam;
                        List <Curve> profileMain = SupportGeometry.MoveLine(curvesHorizontal, -offsetMain, SupportGeometry.LineSide.Top);

                        if (wri.horizontalAdditionalStepSpace)
                        {
                            if (wri.horizontalAddStepHeightBottom > 0)
                            {
                                List <List <Curve> > profilesAddBottom = SupportGeometry.CopyTopOrBottomLines(curvesHorizontal, wri.horizontalAddStepHeightBottom, false);
                                foreach (var prof in profilesAddBottom)
                                {
                                    curvesBase.Add(new AreaRebarInfo(prof, horizRebarInterval));
                                }

                                profileMain = SupportGeometry.MoveLine(profileMain, wri.horizontalAddStepHeightBottom, SupportGeometry.LineSide.Bottom);
                            }
                            else if (wri.horizontalAddStepHeightTop > 0)
                            {
                                List <List <Curve> > profilesAddTop = SupportGeometry.CopyTopOrBottomLines(curvesHorizontal, wri.horizontalAddStepHeightTop, true);
                                foreach (var prof in profilesAddTop)
                                {
                                    curvesBase.Add(new AreaRebarInfo(prof, horizRebarInterval));
                                }

                                profileMain = SupportGeometry.MoveLine(profileMain, -wri.horizontalAddStepHeightTop, SupportGeometry.LineSide.Top);
                            }
                            curvesBase.Add(new AreaRebarInfo(profileMain, horizRebarInterval * 2));
                        }
                        else
                        {
                            curvesBase.Add(new AreaRebarInfo(profileMain, horizRebarInterval));
                        }

                        double heigthAdd = heigth - heigthClean - horizRebarInterval;

                        List <List <Curve> > profilesAdd = SupportGeometry.CopyTopOrBottomLines(curvesHorizontal, heigthAdd, true);
                        foreach (var prof in profilesAdd)
                        {
                            curvesBase.Add(new AreaRebarInfo(prof, horizRebarInterval));
                        }
                    }
                }
                else
                {
                    Debug.WriteLine("Create only one zone for horizontal rebars");
                    curvesBase.Add(new AreaRebarInfo(curvesHorizontal, wri.horizontalRebarInterval));
                }


                Debug.WriteLine("Loops for horizontal rebar: " + curvesBase.Count.ToString());

                foreach (var profileInfo in curvesBase)
                {
                    double            interval = profileInfo.interval;
                    List <Curve>      curves   = profileInfo.curves;
                    AreaReinforcement ar       = Generate(doc, wall, curves, true, true, true, offsetHorizontalInterior, offsetHorizontalExterior, interval, areaTypeId, horizontalRebarType.bartype, wri.horizontalSectionText);
                }
            }
            return(messages);
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("WallAreaRebar"));
            Debug.WriteLine("Wall reinforcement start");

            App.ActivateConfigFolder();

            Document doc = commandData.Application.ActiveUIDocument.Document;

            Selection   sel   = commandData.Application.ActiveUIDocument.Selection;
            List <Wall> walls = new List <Wall>();


            foreach (ElementId id in sel.GetElementIds())
            {
                Element elem = doc.GetElement(id);

                if (elem is Wall)
                {
                    walls.Add(elem as Wall);
                }
            }
            if (walls.Count == 0)
            {
                message = "Предварительно выберите стены для армирования";
                return(Result.Failed);
            }

            Debug.WriteLine("Selected walls count: " + walls.Count.ToString());
            foreach (Wall w in walls)
            {
                Parameter isStructural = w.get_Parameter(BuiltInParameter.WALL_STRUCTURAL_SIGNIFICANT);
                if (isStructural == null)
                {
                    continue;
                }
                if (isStructural.AsInteger() != 1)
                {
                    elements.Insert(w);
                }
            }
            if (elements.Size > 0)
            {
                message = "Найдены не несущие стены, армирование не может быть выполнено";
                Debug.WriteLine("Non-structural walls were found");
                return(Result.Failed);
            }

            ElementId      areaTypeId         = SupportDocumentGetter.GetDefaultArea(doc).Id;
            RebarCoverType zeroCover          = SupportDocumentGetter.GetRebarCoverType(doc, 0);
            List <string>  rebarTypes         = SupportDocumentGetter.GetRebarTypes(doc);
            List <string>  rebarTypes2        = rebarTypes.ToList();
            bool           wallsHaveRebarInfo = SupportDocumentGetter.CheckWallsHaveRebarInfo(walls);


            RebarInfoWall riw      = new RebarInfoWall(); //RebarInfoWall.GetDefault(doc);
            string        wallPath = System.IO.Path.Combine(App.localFolder, "wall.xml");

            Debug.WriteLine("Try to deserialize xml: " + wallPath);
            XmlSerializer serializer = new XmlSerializer(typeof(RebarInfoWall));

            if (System.IO.File.Exists(wallPath))
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(wallPath))
                {
                    try
                    {
                        riw = (RebarInfoWall)serializer.Deserialize(reader);
                    }
                    catch
                    {
                        Debug.WriteLine("Deserialize fault!");
                    }
                }
            }

            if (wallsHaveRebarInfo)
            {
                //TaskDialog.Show("Внимание!", "Армирование будет выполнено по данным, указанным в стенах, без вывода диалогового окна.");
                Debug.WriteLine("DialogWindow for auto-reinforcement");
                DialogWindowWallAuto dialogWallAuto = new DialogWindowWallAuto(riw);
                dialogWallAuto.ShowDialog();
                if (dialogWallAuto.DialogResult != System.Windows.Forms.DialogResult.OK)
                {
                    return(Result.Cancelled);
                }
                riw = dialogWallAuto.rebarInfo;
                Debug.WriteLine("RebarInfo created");
            }
            else
            {
                Debug.WriteLine("Dialog window for manual-reinforcement");
                DialogWindowWall form = new DialogWindowWall(riw, rebarTypes, rebarTypes2);
                form.ShowDialog();
                if (form.DialogResult != System.Windows.Forms.DialogResult.OK)
                {
                    return(Result.Cancelled);
                }
            }

            Debug.Write("Delete xml file and rewrite: " + wallPath);
            if (File.Exists(wallPath))
            {
                File.Delete(wallPath);
            }
            using (FileStream writer = new FileStream(wallPath, FileMode.OpenOrCreate))
            {
                serializer.Serialize(writer, riw);
            }
            Debug.WriteLine("... Success!");


            using (Transaction t = new Transaction(doc))
            {
                t.Start("Армирование стен");
                Debug.WriteLine("Start transaction");

                foreach (Wall wall in walls)
                {
                    if (wallsHaveRebarInfo)
                    {
                        Debug.WriteLine("Start auto-reinforcement");
                        RebarInfoWall newRiw = new RebarInfoWall(doc, wall);
                        newRiw.topOffset    = riw.topOffset;
                        newRiw.bottomOffset = riw.bottomOffset;

                        newRiw.horizontalAddInterval         = riw.horizontalAddInterval;
                        newRiw.horizontalAdditionalStepSpace = riw.horizontalAdditionalStepSpace;
                        newRiw.verticalSectionText           = riw.verticalSectionText;
                        newRiw.horizontalSectionText         = riw.horizontalSectionText;
                        newRiw.verticalOffset = riw.verticalOffset;

                        newRiw.useUnification         = riw.useUnification;
                        newRiw.lengthsUnification     = riw.lengthsUnification;
                        newRiw.autoVerticalFreeLength = riw.autoVerticalFreeLength;

                        RebarWorkerWall.GenerateRebar(doc, wall, newRiw, zeroCover, areaTypeId);
                    }
                    else
                    {
                        Debug.WriteLine("Start manual reinforcement");
                        RebarWorkerWall.GenerateRebar(doc, wall, riw, zeroCover, areaTypeId);
                    }
                }
                t.Commit();
                Debug.WriteLine("Finish transaction");
            }
            return(Result.Succeeded);
        }