/// <summary>
 /// Encapsulates a layer attached to a loading thread
 /// </summary>
 /// <param name="devIf"></param>
 /// <param name="position"></param>
 /// <param name="dimensions"></param>
 /// <param name="id"></param>
 /// <param name="dependants"></param>
 /// <param name="dependancies"></param>
 public LoadingLayer(DeviceInterface devIf, Point position, Size dimensions, string id, IResource[] dependants,
                     ISharableResource[] dependancies)
     : base(devIf, position, dimensions, id, dependants, dependancies)
 {
     AddItem(LayoutManager.AlignItem(progressBar = new GUIProgressBar(new Point(0, 0), new Size(200, 20), Color.Blue),
                                     LayoutRules.Positioning.Center, LayoutRules.Positioning.Center));
     progressBar.Progress = 0;
 }
        public override void Init(DeviceInterface devIf, SceneManager sManager)
        {
            gDevice = devIf.Device;

            // create font
            font = new Font(gDevice, fontSize, 0, fontWeight, 1, false,
                            CharacterSet.Ansi, Precision.Default, FontQuality.ClearType,
                            PitchAndFamily.DefaultPitch, fontFace);
            MeasureText();
        }
        /// <summary>
        /// Initializes a new instance of the DigitalElevationMap class.
        /// </summary>
        /// <param name="mapSize">Size of the map</param>
        /// <param name="rDb"></param>
        /// <param name="devIf"></param>
        /// <param name="reader"></param>
        public DigitalElevationMap(Size mapSize, RasterDatabase.RasterDatabase rDb,
                                   DeviceInterface devIf, GDALReader reader)
            : base(new Vector3(-5f, -0.5f, -5f), new Vector3(5f, 1f, 5f))
        {
            this.mapSize = mapSize;
            maxDimension = mapSize.Width > mapSize.Height ? mapSize.Width : mapSize.Height;
            this.rDb = rDb;

            this.devIf = devIf;
            this.reader = reader;

            axisHelper = new Axis3DHelper(new Vector3(2.5f, 0.5f, 2.5f));
            rotAxisHelper = new RotationAxis3DHelper(new Vector3());
        }
 public SimpleGUILayer(DeviceInterface devIf, Point position, Size dimensions,
                       string id, IResource[] dependants, ISharableResource[] dependancies)
     : base(id, dependants, dependancies)
 {
     this.devIf = devIf;
     device = devIf.Device;
     this.position = position;
     this.dimensions = dimensions;
     enabled = true;
     visible = true;
     itemsList = new List<GUILayerItem>();
     itemsLayout = new QuadTree<GUILayerItem>(dimensions.Width, dimensions.Height);
     checkedOutResources = new List<ISharableResource>();
     layoutManager = new LayoutManager();
 }
        public override void Init(DeviceInterface devIf, SceneManager sManager)
        {
 	        base.Init(devIf, sManager);

            // do a lookup to get y position
            float height = heightLookup.ValueLookup(0.25f, 0.25f) / maxDataValue;
            
            // load text
            text = new ScreenSpaceText(Math.Round((decimal)height * 10, 1) + "m", Color.Yellow, "Tahoma", FontWeight.Bold,
                                       11, new Vector3(0, 2.2f, 0), this);
            text.Init(devIf, sManager);
            sManager.AddEntity(text);
            AddDependant(text);

            Move(new Vector3(1.25f, height, 1.25f));
        }
        public override IResource LoadContent(string filePath, string rzPath, string subPath, string contentType,
                                              XmlNodeList rzNode, out IResource[] loadedDependants,
                                              out IResource[] loadedDependancies, DeviceInterface devIf)
        {
            ILog log = devIf.CDI.GeneralLog;
            log.AddItem(new LogItem(string.Format("Starting loading script rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            BooScript script = BooScript.LoadBooScript(rzPath, filePath);

            log.AddItem(new LogItem(string.Format("Loaded script rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            loadedDependancies = null;
            loadedDependants = null;

            return script;
        }
        public override void Init(DeviceInterface devIf, SceneManager sManager)
        {
 	        base.Init(devIf, sManager);

            BuildGeometry();
            
            axisHelper.Init(devIf, sManager);
            rotAxisHelper.Init(devIf, sManager);

            List<ISharableResource> shared = new List<ISharableResource>();
            overlayTexRz = (TextureResource)devIf.GetSharedResource("file://media/ui/vis/overlay-1s.png", ref shared);

            ShaderHLSL shader;
            if (gProfile.SupportsShaderOverlay)
            {
                shader = new ShaderHLSL(gDevice, devIf.LocalSettings["Base.Path"] + @"shaders\cpu_dem.fx");
                shader.Effect.Technique = shader.Effect.GetTechnique("LitTextured");
                defaultShader = new ShaderInterface(shader);
            }
            /*shader = new ShaderHLSL(gDevice, devIf.LocalSettings["Base.Path"] + @"shaders\cpu_dem_hClr.fx");
            shader.Effect.Technique = shader.Effect.GetTechnique("CPU_DEM_HeightClr");
            hClrShader = new ShaderInterface(shader);*/

            shader = new ShaderHLSL(gDevice, devIf.LocalSettings["Base.Path"] + @"shaders\gpu_dem.fx");
            shader.Effect.Technique = shader.Effect.GetTechnique("Basic");
            sm3Shader = new ShaderInterface(shader);
            
            /*Shape shape = ShapeContentLoader.LoadShape(gDevice, NuGenDEMVis.Properties.Resource1.VerticalPointer_Shape);
            pointerEntity = new VerticalPointerEntity(shape, rDb.Layers[0], maxDataValue);
            pointerEntity.Init(devIf, sManager);
            sManager.AddEntity(pointerEntity);*/

            /*axisHelper.Init(devIf, sManager);
            sManager.AddEntity(axisHelper);

            SetChildren(new IWorldEntity[] { axisHelper, pointerEntity });*/

            //geom.RebuildDiffuseTextures(new HeightMapDEMSampler());
        }
Beispiel #8
0
 public override void Init(DeviceInterface devIf, SceneManager sManager)
 {
     gDevice = devIf.Device;
 }
Beispiel #9
0
 public abstract IResource LoadContent(string filePath, string rzPath, string subPath,
                                       string contentType, XmlNodeList rzNode,
                                       out IResource[] loadedDependants,
                                       out IResource[] loadedDependancies,
                                       DeviceInterface devIf);
Beispiel #10
0
        public IResource LoadResource(Uri uri, DeviceInterface devIf, out IResource[] loadedDependants,
                                      out IResource[] loadedRependancies, out string realRzId)
        {
            // break down uri into any sub-file paths etc.
            string endPath = uri.Segments[uri.Segments.Length - 1];
            string filename;
            int start;
            string subPath = null;
            if ((start = endPath.IndexOf(':')) != -1)
            {
                subPath = endPath.Substring(start);
                filename = endPath.Substring(0, start);
            }
            else
                filename = endPath;

            //string rzPath = uri.LocalPath.Substring(2, uri.LocalPath.Length - endPath.Length + filename.Length - 2);
            string filepath;
            if (subPath == null)
                filepath = (string)HashTableSettings.Instance["Base.Path"] + uri.LocalPath.Substring(2);
            else
                filepath = (string)HashTableSettings.Instance["Base.Path"] + uri.LocalPath.Substring(2, uri.LocalPath.Length - 2 - subPath.Length);
            string metafile = filepath + ".xml";

            // find & read xml meta-data
            string contentType;
            XmlNodeList properties = null;
            if (!File.Exists(metafile) || !ReadMetaXml(metafile, out contentType, out properties))
            {
                // read / guess content-type
                string ext = Path.GetExtension(filename);
                if (!fileExtContentTypes.TryGetValue(ext, out contentType))
                    throw new Exception("Unable to determine content-type for extension: " + ext);
            }

            // load content-type
            RzContentTypeLoader loader;
            if (!contentLoaders.TryGetValue(contentType, out loader))
                throw new Exception("Unable to determine content-type loader for type: " + contentType);

            string rzPath = subPath != null ? uri.OriginalString.Substring(0, uri.OriginalString.Length - subPath.Length) : uri.OriginalString;
            IResource rz = loader.LoadContent(filepath, rzPath, subPath, contentType, properties,
                                              out loadedDependants, out loadedRependancies, devIf);
            if (subPath != null)
                realRzId = rzPath;
            else
                realRzId = uri.OriginalString;
            return rz;
        }
        public override void Init(DeviceInterface devIf, SceneManager sManager)
        {
            base.Init(devIf, sManager);

            BuildRings();
        }
        public override IResource LoadContent(string filePath, string rzPath, string subPath,
                                              string contentType, XmlNodeList rzNode,
                                              out IResource[] loadedDependants,
                                              out IResource[] loadedDependancies, DeviceInterface devIf)
        {
            ILog log = devIf.CDI.GeneralLog;
            log.AddItem(new LogItem(string.Format("Starting loading layer rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            XmlDocument xml = new XmlDocument();
            xml.Load(filePath);

            List<ISharableResource> sharedRzs = new List<ISharableResource>();

            // look for layer info
            XmlNode layerNode = xml.SelectSingleNode("/layer");
            Point position = ParsePoint(layerNode.Attributes["position"].InnerText);
            Size dimensions = ParseSize(layerNode.Attributes["size"].InnerText);
            string booClass = null, booFile = null;
            if (layerNode.Attributes["classFile"] != null)
                booFile = layerNode.Attributes["classFile"].InnerText;
            if (layerNode.Attributes["className"] != null)
                booClass = layerNode.Attributes["className"].InnerText;

            // parse boo script file
            BooScript script = null;
            StringBuilder scriptText;
            if (booFile != null && booClass != null)
            {
                string scriptRzPath = rzPath.Substring(0, rzPath.Length - Path.GetFileName(rzPath).Length) +  booFile;
                log.AddItem(new LogItem(string.Format("Found Layer Script ({0})", scriptRzPath), LogItem.ItemLevel.DebugInfo));
                script = (BooScript)devIf.GetSharedResource(scriptRzPath, ref sharedRzs);
                scriptText = new StringBuilder();
                scriptText.Append(script.Script);
            }
            else
            {
                log.AddItem(new LogItem("Generating Layer Script", LogItem.ItemLevel.DebugInfo));
                // build boo script for layer
                BooScriptBuilder.CreateClass(new string[] { "import Genetibase.VisUI.Scripting from \"NuGenVisUI\"" },
                                             "AutoGenLayer", "ScriptLayer", out scriptText);

                script = new BooScript(scriptText.ToString(), null);
                booClass = "AutoGenLayer";
            }
            
            // load resources
            Dictionary<string, IResource> refRzs = new Dictionary<string, IResource>();
            XmlElement resourcesNode = (XmlElement)layerNode.SelectSingleNode("resources");
            foreach (XmlNode node in resourcesNode.ChildNodes)
            {
                if (node.NodeType != XmlNodeType.Comment)
                {
                    string rzName = node.Attributes["name"].InnerText;
                    string rzUrl = node.Attributes["url"].InnerText;
                    IResource rz = devIf.GetSharedResource(rzUrl, ref sharedRzs);
                    refRzs[rzName] = rz;
                }
            }

            SimpleGUILayer layer = new SimpleGUILayer(devIf, position, dimensions, rzPath, null, sharedRzs.ToArray());

            // pre-load script for layer
            XmlNode itemsNode = layerNode.SelectSingleNode("items");
            /*foreach (XmlNode node in itemsNode.ChildNodes)
            {
                // parse common events
                if (node.Attributes["onclick"] != null)
                {
                    string booCode = node.Attributes["onclick"].InnerText;
                    // insert into script
                    BooScriptBuilder.InsertFunction("", node.Name + "_onclick", "obj as object, args as MouseEventArgs", booCode, ref scriptText);
                }
            }*/

            // compile new script
            log.AddItem(new LogItem(string.Format("Compiling Layer Script (Length: {0})", scriptText.Length), LogItem.ItemLevel.DebugInfo));
            script = new BooScript(scriptText.ToString(), null);
            if (script.Compile())
                log.AddItem(new LogItem("Compiled Layer Script", LogItem.ItemLevel.Success));
            else
                log.AddItem(new LogItem("Failed to Compile Layer Script", LogItem.ItemLevel.Failure));

            // create class instance
            Type layerClass = script.GeneratedAssembly.GetType(booClass);
            ScriptLayer sLayer = (ScriptLayer)script.GeneratedAssembly.CreateInstance(booClass);
            
            // load items
            Font font = new Font("Tahoma", 10);
            foreach (XmlNode node in itemsNode.ChildNodes)
            {
                // TODO: Parse layout instructions
                // TODO: Log building?
                // Parse common attributes
                GUIItemType_Config itemConf;
                Point pos = Point.Empty;
                Size size = Size.Empty;
                LayoutRules.Positioning xLayout = LayoutRules.Positioning.Near;
                LayoutRules.Positioning yLayout = LayoutRules.Positioning.Near;
                MouseEventHandler onclickHandler = null;

                // parse and map common events
                if (node.Attributes["onclick"] != null)
                {
                    string methodName = node.Name + "_onclick";
                    BooScriptEventsBridge evBridge = new BooScriptEventsBridge(sLayer, layerClass.GetMethod(methodName));
                    onclickHandler = evBridge.MouseHandler;
                }

                if (guiItemsConfig.TryGetValue(node.Name, out itemConf))
                {
                    if (itemConf.usePos && node.Attributes["position"] != null)
                        pos = ParsePoint(node.Attributes["position"].InnerText);
                    if (itemConf.useSize && node.Attributes["size"] != null)
                        size = ParseSize(node.Attributes["size"].InnerText);
                    if (itemConf.useLayout && node.Attributes["layout"] != null)
                        ParseLayout(node.Attributes["layout"].InnerText, out xLayout, out yLayout);
                }
                GUILayerItem item = null;
                if (node.Name == "label")
                {
                    string text = node.Attributes["text"].InnerText;
                    
                    item = new GUILabel(text, font, Color.Red, pos, Size.Empty);
                }
                else if (node.Name == "icon")
                {
                    string imgRz = node.Attributes["img"].InnerText;
                    TextureResource.Icon icon = (TextureResource.Icon)refRzs[imgRz];
                    bool highlight = (node.Attributes["highlight"].InnerText == bool.TrueString);
                    bool enabled = (node.Attributes["enabled"].InnerText == bool.TrueString);

                    item = new GUIIcon(pos, size, icon, highlight, enabled);
                }

                if (item != null)
                {
                    item = LayoutManager.AlignItem(item, xLayout, yLayout);
                    if (onclickHandler != null)
                        layer.AddItem(item, null, null, onclickHandler);
                    else
                        layer.AddItem(item);
                }
            }

            log.AddItem(new LogItem(string.Format("Loaded layer rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            loadedDependancies = null;
            loadedDependants = null;
            
            return layer;
        }
 public abstract void DeInit(DeviceInterface devIf, SceneManager sManager);
Beispiel #14
0
        public override void Init(DeviceInterface devIf, SceneManager sManager)
        {
            base.Init(devIf, sManager);

            ray = new CustomVertex.PositionColored[2];
            ray[0] = new CustomVertex.PositionColored(start, Color.Red.ToArgb());
            ray[1] = new CustomVertex.PositionColored(end, Color.Red.ToArgb());
        }
Beispiel #15
0
        public override void Init(DeviceInterface devIf, SceneManager sManager)
        {
 	        base.Init(devIf, sManager);

            vBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 6, gDevice, Usage.None,
                                       CustomVertex.PositionColored.Format, Pool.Managed);
            CustomVertex.PositionColored[] verts = (CustomVertex.PositionColored[])vBuffer.Lock(0, LockFlags.None);

            verts[0].Color = verts[1].Color = Color.Red.ToArgb();
            verts[1].Position = new Vector3(1, 0, 0);

            verts[2].Color = verts[3].Color = Color.Green.ToArgb();
            verts[3].Position = new Vector3(0, 1, 0);

            verts[4].Color = verts[5].Color = Color.Blue.ToArgb();
            verts[5].Position = new Vector3(0, 0, 1);

            vBuffer.Unlock();

            // build selection lines
            selectionVBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 6, gDevice, Usage.None,
                                                    CustomVertex.PositionColored.Format, Pool.Managed);
            verts = (CustomVertex.PositionColored[])selectionVBuffer.Lock(0, LockFlags.None);

            verts[0].Color = verts[1].Color = Color.Yellow.ToArgb();
            verts[1].Position = new Vector3(1, 0, 0);

            verts[2].Color = verts[3].Color = Color.Yellow.ToArgb();
            verts[3].Position = new Vector3(0, 1, 0);

            verts[4].Color = verts[5].Color = Color.Yellow.ToArgb();
            verts[5].Position = new Vector3(0, 0, 1);

            selectionVBuffer.Unlock();

            labels = new ScreenSpaceText[3];
            labels[0] = new ScreenSpaceText("x", Color.Red, "Verdana", FontWeight.Normal, 10,
                                            new Vector3(1.1f, 0, 0), this);
            labels[0].Init(devIf, sManager);
            sManager.AddEntity(labels[0]);
            labels[1] = new ScreenSpaceText("y", Color.Green, "Verdana", FontWeight.Normal, 10,
                                            new Vector3(0, 1.1f, 0), this);
            labels[1].Init(devIf, sManager);
            sManager.AddEntity(labels[1]);
            labels[2] = new ScreenSpaceText("z", Color.Blue, "Verdana", FontWeight.Normal, 10,
                                            new Vector3(0, 0, 1.1f), this);
            labels[2].Init(devIf, sManager);
            sManager.AddEntity(labels[2]);
        }
        protected virtual void InitializeEnvironment(CommonDeviceInterface cdi, HashTableSettings localSettings)
        {
            // Get device settings
            if (outCaps == null)
                outCaps = GraphicsDeviceCaps.GetDefaultAdapterCaps(outProfile.RecommendedVariations[0]);
            // find first recommended settings with full match
            bool fullMatch = false;
            outSettings = GraphicsDeviceSettings.CreateFromRequirements(outProfile.RecommendedVariation,
                                                                        outCaps, outProfile.MinReqs,
                                                                        out fullMatch);

            // Set up the presentation parameters
            presentParams.Windowed = outProfile.RecommendedVariations[0].Windowed;
            presentParams.SwapEffect = SwapEffect.Discard;
            presentParams.AutoDepthStencilFormat = outSettings.DepthFormat;
            presentParams.EnableAutoDepthStencil = (outSettings.DepthFormat != DepthFormat.Unknown);
            presentParams.MultiSample = outSettings.MultiSample;

            CreateDevice();

            devIf = new DeviceInterface(gDevice, cdi, localSettings);

            gPipeline = new GraphicsPipeline(gDevice);
        }