Exemplo n.º 1
0
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies();

            string id = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

            if (objectProxies == null)
            {
                objectProxies = new Dictionary<string, SimulationObjectProxy>();
            }
            SimulationObjectProxy prox = bbClient.GetObjectProxy(id);
            if (prox != null)
            {
                if (!objectProxies.ContainsKey(id))
                {
                    objectProxies.Add(id, prox);
                }
                else
                {
                    objectProxies[id] = prox;
                }
            }

            if (((StringValue)e["ObjectType"]).value == "LandRegion")
            {
                StateDB.LandRegion l = new StateDB.LandRegion(((StringValue)e["ID"]).value, null);
                Polygon2D poly = new Polygon2D();
                foreach (PolygonValue.PolygonPoint pp in ((PolygonValue)((AttributeCollectionValue)e["Attributes"]).attributes["Polygon"]).points)
                {
                    poly.AddVertex(new Vec2D(pp.X, pp.Y));
                }
                l.poly = poly;
                StateDB.landRegions[l.id] = l;
            }
            else if (((StringValue)e["ObjectType"]).value == "ActiveRegion")
            {
                StateDB.ActiveRegion b = new StateDB.ActiveRegion(((StringValue)e["ID"]).value, null);
                double start = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["StartHeight"]).value;
                double end = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["EndHeight"]).value;
                Polygon3D poly2 = new Polygon3D(start, end);
                foreach (PolygonValue.PolygonPoint pp in ((PolygonValue)((AttributeCollectionValue)e["Attributes"]).attributes["Polygon"]).points)
                {
                    poly2.AddVertex(new Vec2D(pp.X, pp.Y));
                }
                b.poly = poly2;
                if (((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["BlocksMovement"]).value)
                {
                    b.blockingRegion = true;
                }
                else
                {
                    b.blockingRegion = false;
                }
                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("SpeedMultiplier"))
                {
                    b.speedMultiplier = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["SpeedMultiplier"]).value;
                }
                else
                {
                    b.speedMultiplier = 1;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("IsVisible"))
                {
                    b.isVisible = ((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["IsVisible"]).value;
                }
                else
                {
                    b.isVisible = false;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("DisplayColor"))
                {
                    b.displayColor = ((IntegerValue)((AttributeCollectionValue)e["Attributes"]).attributes["DisplayColor"]).value;
                }
                else
                {
                    b.displayColor = -10185235;
                }


                //b.displayColor = -10185235;
                //b.isVisible = true;
                StateDB.activeRegions[b.id] = b;
            }
        }
Exemplo n.º 2
0
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies();

            string id = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

            if (objectProxies == null)
            {
                objectProxies = new Dictionary<string, SimulationObjectProxy>();
            }
            SimulationObjectProxy prox = bbClient.GetObjectProxy(id);
            if (prox != null)
            {
                if (!objectProxies.ContainsKey(id))
                {
                    objectProxies.Add(id, prox);
                }
                else
                {
                    objectProxies[id] = prox;
                }
            }

            if (((StringValue)e["ObjectType"]).value == "LandRegion")
            {
                StateDB.LandRegion l = new StateDB.LandRegion(((StringValue)e["ID"]).value, null);
                Polygon2D poly = new Polygon2D();
                foreach (PolygonValue.PolygonPoint pp in ((PolygonValue)((AttributeCollectionValue)e["Attributes"]).attributes["Polygon"]).points)
                {
                    poly.AddVertex(new Vec2D(pp.X, pp.Y));
                }
                l.poly = poly;
                StateDB.landRegions[l.id] = l;
            }
            else if (((StringValue)e["ObjectType"]).value == "ActiveRegion")
            {
                StateDB.ActiveRegion b = new StateDB.ActiveRegion(((StringValue)e["ID"]).value, null);
                double start = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["StartHeight"]).value;
                double end = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["EndHeight"]).value;
                Polygon3D poly2 = new Polygon3D(start, end);
                foreach (PolygonValue.PolygonPoint pp in ((PolygonValue)((AttributeCollectionValue)e["Attributes"]).attributes["Polygon"]).points)
                {
                    poly2.AddVertex(new Vec2D(pp.X, pp.Y));
                }
                b.poly = poly2;
                b.currentAbsolutePolygon = poly2;
                if (((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["BlocksMovement"]).value)
                {
                    b.blockingRegion = true;
                }
                else
                {
                    b.blockingRegion = false;
                }
                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("SpeedMultiplier"))
                {
                    b.speedMultiplier = ((DoubleValue)((AttributeCollectionValue)e["Attributes"]).attributes["SpeedMultiplier"]).value;
                }
                else
                {
                    b.speedMultiplier = 1;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("IsVisible"))
                {
                    b.isVisible = ((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["IsVisible"]).value;
                }
                else
                {
                    b.isVisible = false;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("DisplayColor"))
                {
                    b.displayColor = ((IntegerValue)((AttributeCollectionValue)e["Attributes"]).attributes["DisplayColor"]).value;
                }
                else
                {
                    b.displayColor = -10185235;
                }

                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("IsDynamicRegion"))
                {
                    b.isDynamicRegion = ((BooleanValue)((AttributeCollectionValue)e["Attributes"]).attributes["IsDynamicRegion"]).value;
                } else {
                    b.isDynamicRegion = false;
                }
                if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("ReferencePoint") && !b.isDynamicRegion) //if isDynamic, will use its LinkedObject as Ref.
                {
                    b.referencePoint = new Vec2D(((LocationValue)((AttributeCollectionValue)e["Attributes"]).attributes["ReferencePoint"]));
                    b.currentAbsolutePolygon = GetAbsolutePolygon(b.referencePoint, poly2.Footprint);
                } else {
                    b.referencePoint = new Vec2D(0,0);
                }


                //Make separate lists for dynamic and active regions in StateDB
                if (b.isDynamicRegion) {
                    StateDB.dynamicRegions[b.id] = b;
                } else {
                    StateDB.activeRegions[b.id] = b;
                }

            }
        }