protected BaseSpecFloor(FloorDesigner designer) : base(1.4f, float.MaxValue) { Contract.Requires(designer != null); _designer = designer; }
public override void Subdivide(Prism bounds, ISubdivisionGeometry geometry, INamedDataCollection hierarchicalParameters) { if (_designer == null) { _designer = hierarchicalParameters.GetValue(FloorDesignerName, false); } base.Subdivide(bounds, geometry, hierarchicalParameters); }
/// <summary> /// Construct a spec floor which will find it's spec from the hierarchicalParameters /// </summary> /// <param name="findInMetadata">Indicates if the system should find it's spec in the metadata (must be set to true)</param> protected BaseSpecFloor(bool findInMetadata = false) { //This is weird; why am I taking a parameter and requiring that you set it to a known value? //I don't really need any parameters here, so I could leave this empty. However, if I did that //then this would be the *default* but I want this to be an obscure option no one uses! If you //use this by accident you will get an exception (telling you exactly what's wrong) if (!findInMetadata) { throw new ArgumentException("If this is false then no spec will be found, must be true", "findInMetadata"); } _designer = null; }
public void TestMethod1() { var rnd = new Random(3); var random = (Func <double>)rnd.NextDouble; var metadata = new NamedBoxCollection(); var designer = FloorDesigner.Deserialize(new StringReader(@" # root node !Floorplan # tags for this floorplan Tags: Type: Residential Style: None # Aliases block is just a list of items, not used by the system. Handy place to define objects which will be used later in the markup Aliases: # A single room, with a set of constraints - &office !Room Id: Office Walkthrough: false Tags: 1: { Office } # Constraints: [] # - { Strength: 1, Req: !ExteriorWindow { } } # - { Strength: 0.5, Req: !ExteriorDoor { Deny: true } } # - { Strength: 0.5, Req: !Area { Min: 11 } } # A group of rooms - &office_group !Group Id: Offices Children: - *office - *office GrowthParameters: SeedSpacing: !NormalValue { Min: 2.5, Mean: 5, Max: 6.5, Vary: true } SeedChance: 0.75 IntersectionContinuationChance: 0.3 ParallelCheck: Length: 1 Width: 3.5 Angle: 15 MergeParameters: AngularDeviation: Weight: 0.4 Threshold: 0.5 Convexity: Weight: 0.3 Threshold: 0.5 Area: Weight: 0.3 Threshold: 45 Cutoff: 5 CorridorParameters: Width: 1 Spaces: - !Repeat Count: !NormalValue { Min: 1, Max: 100 } Space: *office_group ")); Func <IEnumerable <KeyValuePair <string, string> >, Type[], ScriptReference> finder = (tags, types) => { var tagsClean = from tag in tags let k = string.IsNullOrEmpty(tag.Key) let v = string.IsNullOrEmpty(tag.Value) where !k || !v select(!k && !v) ? (tag.Key + ":" + tag.Value) : (k ? tag.Value : tag.Key); return(ScriptReferenceFactory.Create(typeof(TestScript), Guid.NewGuid(), string.Join(",", tagsClean))); }; ////Corner shape //var shape = new[] { // new Vector2(9, 5), new Vector2(9, -6), new Vector2(0, -6), new Vector2(0, 0), new Vector2(-4, 0), new Vector2(-4, 5) //}; //var sections = new[] { // new Subsection[] { new Subsection(0, 1, Subsection.Types.Window) }, // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[] { new Subsection(0, 1, Subsection.Types.Window) }, // new Subsection[0] //}; //Diagonal bend shape var shape = new[] { new Vector2(10, 10), new Vector2(20, 0), new Vector2(23, 0), new Vector2(33, 10), new Vector2(43, 0), new Vector2(28, -15), new Vector2(15, -15), new Vector2(0, 0) }; var sections = new[] { new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0] }; var verticals = new Vector2[][] { }; ////Actual office floorplan //var shape = new[] { // new Vector2(-25, 17), // new Vector2(0, 17), // new Vector2(3, 15), // new Vector2(33, 15), // new Vector2(38, 0), // new Vector2(-25, -25) //}; //var sections = new[] { // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[0] //}; //var verticals = new[] { // new[] { // new Vector2(0, 0), // new Vector2(7, 0), // new Vector2(7, -7), // new Vector2(0, -7), // } //}; ////rectangle //var shape = new[] { // new Vector2(9, 0), // new Vector2(9, -6), // new Vector2(0, -6), // new Vector2(0, 0) //}; //var sections = new[] { // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[0], //}; var plan = new GeometricFloorplan(shape); designer.Design(random, metadata, finder, plan, sections, 0.175f, verticals, new List <ConstrainedVerticalSelection>()); Console.WriteLine(SvgRoomVisualiser.FloorplanToSvg(plan, 55, basic: false)); }