Пример #1
0
        public void CreateWalls
            (Document doc, HouseObject house,
            List <WallType> autoTypes, Level baseLevel)
        {
            foreach (A_Floor floor in house.Floors)
            {
                ///Create the walls.
                foreach (A_Wall wa in floor.Walls)
                {
                    WallType currentWt = null;
                    XYZ      p1        = new XYZ(wa.P1.X, wa.P1.Y, 0);
                    XYZ      p2        = new XYZ(wa.P2.X, wa.P2.Y, 0);
                    Curve    c         = Line.CreateBound(p1, p2);

                    ///Find the right wall type.
                    ///If the type doesnt exist,create a new one.
                    try
                    {
                        currentWt = autoTypes
                                    .First(at => at.Width - wa.Thickness < 0.0001);
                    }
                    catch
                    {
                        ///Duplicate a new walltype;
                        float wallWidthMm = Helper.Feet2Mm(wa.Thickness);
                        currentWt = AutoWallTypes[0].Duplicate
                                        ("AutoWall-" + wallWidthMm) as WallType;
                        ///Set the width of the new type;
                        CompoundStructure cStru = CompoundStructure
                                                  .CreateSingleLayerCompoundStructure
                                                      (MaterialFunctionAssignment.Structure,
                                                      wa.Thickness, currentWt.GetCompoundStructure().GetMaterialId(0));
                        currentWt.SetCompoundStructure(cStru);
                        ///Add it to collection.
                        AutoWallTypes.Add(currentWt);
                    }

                    ///Create the individual wall
                    wa.Wall = Wall.Create(doc, c, currentWt.Id, baseLevel.Id,
                                          floor.Height, 0, false, true);

                    ActiveForm.UpdateProgress(wallWorkLoad);
                }

                ///Create the floor.
                CurveArray floorCrv = new CurveArray();
                foreach (A_Room outer in floor.Outers)
                {
                    foreach (A_Contour con in outer.Meta.Contours)
                    {
                        floorCrv.Append(Line.CreateBound
                                            (new XYZ(con.P1.X, con.P1.Y, baseLevel.Elevation),
                                            new XYZ(con.P2.X, con.P2.Y, baseLevel.Elevation)));
                    }
                    doc.Create.NewFloor(floorCrv, false);
                }
            }
        }
Пример #2
0
        private void ReadCurrentSelection(Stream fileStream)
        {
            CurrentHouse    = new HouseObject();
            RoomSoftDesigns = new List <RoomSoftDesign>();
            using (StreamReader reader = new StreamReader(fileStream))
            {
                JObject jsonObj = (JObject)JToken.ReadFrom(new JsonTextReader(reader));

                try
                {///Try read the json as only house object.
                    CurrentHouse.Version  = jsonObj["version"].ToString();
                    CurrentHouse.Rotation = jsonObj["rotation"].ToObject <float>();
                    CurrentHouse.Floors   = new List <A_Floor>();
                    foreach (JToken j in jsonObj["floors"].Children())
                    {
                        CurrentHouse.Floors.Add(j.ToObject <A_Floor>());
                    }

                    if (CurrentHouse.Floors == null)
                    {
                        throw new Exception();
                    }
                }
                catch
                {
                    try
                    {///Try read the json as house with soft design.
                        CurrentHouse = jsonObj["house"].ToObject <HouseObject>();
                        foreach (JToken j in jsonObj["roomSoftDesigns"].Children())
                        {
                            RoomSoftDesigns.Add(j.ToObject <RoomSoftDesign>());
                        }

                        if (CurrentHouse.Floors == null)
                        {
                            throw new Exception();
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// The method to convert all mm to inch in the house object.
        /// </summary>
        /// <param name="house"></param>
        private void TransferDataUnits(HouseObject house)
        {
            try
            {
                foreach (A_Floor floor in house.Floors)
                {
                    foreach (A_Wall wa in floor.Walls)
                    {
                        wa.P1.X      = Helper.Mm2Feet(wa.P1.X);
                        wa.P1.Y      = Helper.Mm2Feet(wa.P1.Y);
                        wa.P2.X      = Helper.Mm2Feet(wa.P2.X);
                        wa.P2.Y      = Helper.Mm2Feet(wa.P2.Y);
                        wa.Thickness = Helper.Mm2Feet(wa.Thickness);
                        wa.Height    = Helper.Mm2Feet(wa.Height);
                    }
                    foreach (A_Door door in floor.Doors)
                    {
                        door.P1.X       = Helper.Mm2Feet(door.P1.X);
                        door.P1.Y       = Helper.Mm2Feet(door.P1.Y);
                        door.P2.X       = Helper.Mm2Feet(door.P2.X);
                        door.P2.Y       = Helper.Mm2Feet(door.P2.Y);
                        door.Height     = Helper.Mm2Feet(door.Height);
                        door.SillHeight = Helper.Mm2Feet(door.SillHeight);
                    }
                    foreach (A_Window window in floor.Windows)
                    {
                        window.P1.X       = Helper.Mm2Feet(window.P1.X);
                        window.P1.Y       = Helper.Mm2Feet(window.P1.Y);
                        window.P2.X       = Helper.Mm2Feet(window.P2.X);
                        window.P2.Y       = Helper.Mm2Feet(window.P2.Y);
                        window.Height     = Helper.Mm2Feet(window.Height);
                        window.SillHeight = Helper.Mm2Feet(window.SillHeight);
                        window.BayDepth   = Helper.Mm2Feet(window.BayDepth);
                    }
                    foreach (A_Cube cube in floor.Cubes)
                    {
                        cube.X     = Helper.Mm2Feet(cube.X);
                        cube.Y     = Helper.Mm2Feet(cube.Y);
                        cube.XSize = Helper.Mm2Feet(cube.XSize);
                        cube.YSize = Helper.Mm2Feet(cube.YSize);
                        cube.Z     = Helper.Mm2Feet(cube.Z);
                        cube.ZSize = Helper.Mm2Feet(cube.ZSize);
                    }
                    foreach (A_Room room in floor.Rooms)
                    {
                        foreach (A_Contour contour in room.Meta.Contours)
                        {
                            contour.P1.X = Helper.Mm2Feet(contour.P1.X);
                            contour.P1.Y = Helper.Mm2Feet(contour.P1.Y);
                            contour.P2.X = Helper.Mm2Feet(contour.P2.X);
                            contour.P2.Y = Helper.Mm2Feet(contour.P2.Y);
                        }
                        foreach (A_Contour contour in room.Meta.CubeContours)
                        {
                            contour.P1.X = Helper.Mm2Feet(contour.P1.X);
                            contour.P1.Y = Helper.Mm2Feet(contour.P1.Y);
                            contour.P2.X = Helper.Mm2Feet(contour.P2.X);
                            contour.P2.Y = Helper.Mm2Feet(contour.P2.Y);
                        }
                    }
                    foreach (A_Room outer in floor.Outers)
                    {
                        foreach (A_Contour contour in outer.Meta.Contours)
                        {
                            contour.P1.X = Helper.Mm2Feet(contour.P1.X);
                            contour.P1.Y = Helper.Mm2Feet(contour.P1.Y);
                            contour.P2.X = Helper.Mm2Feet(contour.P2.X);
                            contour.P2.Y = Helper.Mm2Feet(contour.P2.Y);
                        }
                        foreach (A_Contour contour in outer.Meta.CubeContours)
                        {
                            contour.P1.X = Helper.Mm2Feet(contour.P1.X);
                            contour.P1.Y = Helper.Mm2Feet(contour.P1.Y);
                            contour.P2.X = Helper.Mm2Feet(contour.P2.X);
                            contour.P2.Y = Helper.Mm2Feet(contour.P2.Y);
                        }
                    }
                    foreach (A_Label label in floor.Labels)
                    {
                        label.Position.X = Helper.Mm2Feet(label.Position.X);
                        label.Position.Y = Helper.Mm2Feet(label.Position.Y);
                    }
                    floor.Height = Helper.Mm2Feet(floor.Height);


                    if (floor.Socket == null)
                    {
                        floor.Socket = new List <A_Socket>();
                    }
                    foreach (A_Socket socket in floor.Socket)
                    {
                        socket.X = Helper.Mm2Feet(socket.X);
                        socket.Y = Helper.Mm2Feet(socket.Y);
                        socket.Z = Helper.Mm2Feet(socket.Z);
                    }
                }
            }
            catch
            {
                throw new Exception("Json数据不完整或数据损坏,请检查数据文件。");
            }
        }
Пример #4
0
        public void CreateOpenings
            (Document doc, HouseObject house,
            Level baseLevel, List <Family> doorFamilies,
            List <Family> windowFamilies)
        {
            foreach (A_Floor f in house.Floors)
            {
                foreach (A_Door d in f.Doors)
                {
                    ///Find the right doorfamily.
                    Family doorFam;
                    switch (d.Kind)
                    {
                    case A_DoorKind.PASS:
                        doorFam = doorFamilies
                                  .First(fa => fa.Name.Contains("PASS"));
                        break;

                    case A_DoorKind.SLIDING:
                        doorFam = doorFamilies
                                  .First(fa => fa.Name.Contains("SLIDING"));
                        break;

                    default:
                        doorFam = doorFamilies
                                  .First(fa => fa.Name.Contains("SINGLE"));
                        break;
                    }

                    ///Create the door.
                    d.Instance = CreateSingleOpening
                                     (doc, f, d, baseLevel, doorFam,
                                     BuiltInCategory.OST_Doors);

                    bool fliped = false;
                    ///Check the direction.
                    doc.Regenerate();
                    if (!d.Instance.FacingOrientation
                        .IsAlmostEqualTo(d.FacingOrientation))
                    {
                        d.Instance.flipFacing();
                        fliped = true;
                    }
                    if (!d.Instance.HandOrientation
                        .IsAlmostEqualTo(d.HandOrientation))
                    {
                        d.Instance.flipHand();
                        fliped = true;
                    }
                    if (!fliped)
                    {
                        d.Instance.flipFacing();
                        d.Instance.flipFacing();
                    }

                    ///Update the progress.
                    ActiveForm.UpdateProgress(doorWorkLoad);
                }

                foreach (A_Window w in f.Windows)
                {
                    ///Find the right window family.
                    string test      = w.Kind.ToString();
                    Family windowFam = windowFamilies
                                       .First(wf => wf.Name.Contains(w.Kind.ToString()));

                    ///Create the window.
                    w.Instance = CreateSingleOpening
                                     (doc, f, w, BaseLevel, windowFam,
                                     BuiltInCategory.OST_Windows);
                    doc.Regenerate();
                    w.Instance.flipFacing();
                    doc.Regenerate();
                    w.Instance.flipFacing();

                    ActiveForm.UpdateProgress(windowWorkLoad);
                }
            }
        }