예제 #1
0
        public static DomNode CreateStarter()
        {
            var result  = new DomNode(FolderST.Type);
            var adapter = result.As <PlacementsFolder>();

            if (adapter != null)
            {
                // initialize to the default settings
                var cfg = adapter.GetCfg();
                cfg.UnnamedPlacementDocuments = true;
                adapter.Reconfigure(cfg);

                // add a simple placement with a default object

                var defResource = Globals.ResourceService.Load(
                    new Uri(Utils.CurrentDirectoryAsUri(), "Game/Model/materialsphere.dae"));
                if (defResource != null)
                {
                    var plcmnt = XLEPlacementObject.Create(defResource);
                    if (plcmnt != null)
                    {
                        plcmnt.DomNode.InitializeExtensions();
                        adapter.AddChild(plcmnt);
                    }
                }
                return(result);
            }
            return(null);
        }
예제 #2
0
        public void DoCommand(object commandTag)
        {
            if (!(commandTag is Command))
            {
                return;
            }

            switch ((Command)commandTag)
            {
            case Command.SearchForPlacements:
            {
                var target = _resLister.ContextMenuTarget;
                if (target == null)
                {
                    break;
                }

                IQueryPredicate predicate = null;

                // note --  we could use the IResourceService to do the type resolution here by
                //          calling IResourceService.Load... However, if the load operation is
                //          expensive, we might not always want to do it.
                var ext = System.IO.Path.GetExtension(target.LocalPath);
                if (IsModelExtension(ext))
                {
                    predicate = XLEPlacementObject.CreateSearchPredicate(target);
                }
                else if (IsModelBookmarkExtension(ext))
                {
                    // todo -- we could load the bookmark via the resource service, as so --
                    // var res = IResourceService.Load(target);
                    // if (res == null) break;
                    var bookmark = XLEPlacementObject.LoadBookmark(target);
                    if (bookmark == null)
                    {
                        break;
                    }
                    predicate = XLEPlacementObject.CreateSearchPredicate(bookmark, target);
                }

                if (predicate != null)
                {
                    var queryContext = _contextRegistry.GetActiveContext <IQueryableContext>();
                    if (queryContext != null)
                    {
                        // note -- in our query context, the results will be displaced to the user automatically
                        // we could "show" the search results ui here, however.
                        queryContext.Query(predicate);

                        if (_searchService != null)
                        {
                            _searchService.Show();
                        }
                    }
                }
            }
            break;
            }
        }
예제 #3
0
 IAdaptable IResourceConverter.Convert(IResource resource)
 {
     if (resource == null)
     {
         return(null);
     }
     return(XLEPlacementObject.Create(resource));
 }
예제 #4
0
파일: Converter.cs 프로젝트: coreafive/XLE
        IAdaptable IResourceConverter.Convert(IResource resource)
        {
            if (resource == null)
            {
                return(null);
            }

            if (resource.Type == "ModelBookmark")
            {
                // {
                //     var stream2 = new System.IO.FileStream(
                //         "E:\\XLE\\temp.xml",
                //         System.IO.FileMode.CreateNew, System.IO.FileAccess.Write);
                //     var serializer2 = new XmlSerializer(typeof(Bookmark));
                //     Bookmark b = new Bookmark();
                //     b.Model = "ModelName"; b.Material = "MaterialName"; b.Supplements = "Supp";
                //     serializer2.Serialize(stream2, b);
                // }

                // If this is a bookmark, we need to load the xml and
                // extract the key properties from there.
                var stream = new System.IO.FileStream(
                    resource.Uri.LocalPath,
                    System.IO.FileMode.Open, System.IO.FileAccess.Read);
                var serializer   = new XmlSerializer(typeof(Bookmark));
                var obj          = serializer.Deserialize(stream) as Bookmark;
                var newPlacement = XLEPlacementObject.Create();

                // we need to convert the strings into uris relative to the
                // original filename.
                var resService = Globals.MEFContainer.GetExportedValue <IXLEAssetService>();
                var basePath   = resource.Uri.LocalPath;
                //  all this path processing is a little non-ideal. It would be better
                //  to drag these strings into C++ so we can use the reliable path
                //  manipulation routines there.
                var lastSep = System.Math.Max(basePath.LastIndexOf('/'), basePath.LastIndexOf('\\'));
                if (lastSep != -1)
                {
                    basePath = basePath.Substring(0, lastSep + 1);
                }
                newPlacement.Model       = resService.StripExtension(resService.AsAssetName(new System.Uri(basePath + obj.Model)));
                newPlacement.Material    = resService.StripExtension(resService.AsAssetName(new System.Uri(basePath + obj.Material)));
                newPlacement.Supplements = obj.Supplements ?? "";

                return(newPlacement);
            }
            else
            if (XLEPlacementObject.CanReferenceStatic(resource))
            {
                var newPlacement = XLEPlacementObject.Create();
                newPlacement.Target = resource;
                return(newPlacement);
            }

            return(null);
        }