Esempio n. 1
0
 private void BuildAnimations(ModelDocument dest)
 {
     foreach (var seq in sequences)
     {
         var a = new ModelAnimation() { Name=seq.label };
         if (seq.blends != null)
         {
             int blend = 0;
             //IList<ModelAnimationFrameBone>[] = b
             var f = new ModelAnimationFrame() { Time=0};
             a.Frames.Add(f);
             for (int bone = 0; bone < bones.Count; ++bone)
             {
                 mstudioanim_t animBlend = seq.blends[blend, bone];
                 f.Bones.Add(new ModelAnimationFrameBone() {Bone=modelBones[bone],Position=modelBones[bone].Position,Rotation=modelBones[bone].Rotaton });
             }
             f = new ModelAnimationFrame() { Time = 1 };
             a.Frames.Add(f);
             for (int bone = 0; bone < bones.Count; ++bone)
             {
                 mstudioanim_t animBlend = seq.blends[blend, bone];
                 f.Bones.Add(new ModelAnimationFrameBone() { Bone = modelBones[bone], Position = modelBones[bone].Position, Rotation = modelBones[bone].Rotaton });
             }
         }
         dest.Animations.Add(a);
     }
 }
Esempio n. 2
0
        public static ModelDocument GenerateTestModel(int floors = 10)
        {
            Core.Print("Generating test model of " + floors * 12 + " elements...");

            ModelDocument doc = new ModelDocument();

            double floorHeight = 4;

            for (int i = 0; i < floors; i++)
            {
                double z = floorHeight * (i + 1);
                for (int j = 0; j < 10; j += 2)
                {
                    doc.Model.Create.LinearElement(new Line(0, j, z, 10, j, z));
                }
                doc.Model.Create.LinearElement(new Line(0, 0, z, 0, 10, z));
                doc.Model.Create.LinearElement(new Line(10, 0, z, 10, 10, z));
            }

            doc.Model.GenerateNodes(new NodeGenerationParameters());

            Core.Print("Done.");

            return(doc);
        }
Esempio n. 3
0
        /// <summary>
        ///  标签有更改时更新界面
        /// </summary>
        /// <param name="file"></param>
        /// <param name="op"></param>

        /*  void _TagCache_CacheUpdated(CacheUpdatedArgs e)
         * {
         *    // 删除结点
         *    TreeNode root = tvClassView.Nodes[e.ProjectIndex];
         *    ClassViewIndex index = root.Tag as ClassViewIndex;
         *    if (index.FileName2TreeNode_Index.ContainsKey(e.File))
         *    {
         *        List<TreeNode> nodeList = index.FileName2TreeNode_Index[e.File];
         *        nodeList.Reverse();
         *        foreach (TreeNode node in nodeList)
         *        {
         *            ITag tag = node.Tag as ITag;
         *            index.TagFullName2TreeNode_Index.Remove(tag.FullName);
         *        }
         *        index.FileName2TreeNode_Index.Remove(e.File);
         *        foreach (TreeNode node in nodeList)
         *        {
         *            if (node.Nodes.Count == 0)  // 没有子结点的情况下才删除。像命名空间往往有很多子结点
         *                node.Remove();  // throw new exception?
         *        }
         *    }
         *    // 如果是Update操作,添加结点
         *    if (e.Operator == Operator.Update)
         *    {
         *        _InsertTags(root, TagCache.GetTags(e.File));
         *    }
         * }*/
        /// <summary>
        /// Update tree for current active document
        /// </summary>
        /// <param name="root"></param>
        /// <param name="tags"></param>
        void _InsertTags(TreeNode root, List <ITag> tags)
        {
            IView _View = ControllerDocument.Instance.GetActiveView();

            if (_View == null || _View.GetViewData() == null)
            {
                return;
            }

            string  _Scope = _View.GetViewData().File;
            Project proj   = ProjectManager.GetProjectByItsFile(_Scope);

            if (proj == null)
            {
                return;
            }
            ModelDocument _Model = proj.Model;

            _Scope = _Model.GetRelativePath(_Scope);
            TreeNode parent = new TreeNode(_Scope);

            _InsertTagsSub(parent, _Scope, _Model);
            tvClassView.Nodes.Clear();
            tvClassView.Nodes.Add(parent);
            tvClassView.ExpandAll();
        }
Esempio n. 4
0
        void _InsertTagsSub(TreeNode parent, String _Scope, ModelDocument _Model)
        {
            List <Obj> .Enumerator _Objs = _Model.GetObjects(_Scope).GetEnumerator();
            parent.BeginEdit();
            while (_Objs.MoveNext())
            {
                TreeNode node = new TreeNode();
                node.Text       = _Objs.Current.ClassID() + " " + _Objs.Current.Name();
                node.Tag        = _Objs.Current;
                node.ImageIndex = node.SelectedImageIndex =
                    (_Scope == _Objs.Current.Scope())?Resource.ClassViewIcon_Cpp_Variable:Resource.ClassViewIcon_ASM_Type;
                node.ToolTipText = _Objs.Current.Description();
                parent.Nodes.Add(node);
                //Recursiv für jedes Object prüfen ob Subdeclaration vorhanden (Sequenz & lvclass)
                //Todo falls versehentlich recursion in den seq ist hängen wir hier fest

                /* if (_Scope != _Objs.Current.ClassID())
                 *   _InsertTagsSub(node, (_Objs.Current.ClassID()), _Model);*/
            }
            List <ObjDecl> .Enumerator _ObjsDecl = _Model.GetFunctions(_Scope).GetEnumerator();
            while (_ObjsDecl.MoveNext())
            {
                TreeNode node = new TreeNode();
                node.Text       = _ObjsDecl.Current.Function();
                node.Tag        = _ObjsDecl.Current;
                node.ImageIndex = node.SelectedImageIndex =
                    (_Scope == _ObjsDecl.Current.ClassID()) ? Resource.ClassViewIcon_Cpp_Function : Resource.ClassViewIcon_ASM_Macro;
                node.ToolTipText = _ObjsDecl.Current.Description();
                parent.Nodes.Add(node);
            }
            parent.EndEdit(false);
        }
Esempio n. 5
0
        /// <summary>
        /// Open a new, blank, design document and set it as the active design
        /// </summary>
        /// <returns></returns>
        public ModelDocument NewDocument(bool silent = false)
        {
            ModelDocument result = PopulateDefaultData(new ModelDocument());

            ActiveDocument = result;

            //TEMP:
            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Import a document and merge it into the current active model.
        /// </summary>
        public void ImportDocument()
        {
            ModelDocument doc = OpenDocument(true);

            if (doc != null)
            {
                ActiveDocument.MergeIn(doc);
            }
        }
Esempio n. 7
0
        private void Open_Click(object sender, RoutedEventArgs e)
        {
            // Open a document
            ModelDocument document = Core.Instance.OpenDocument(false);

            if (document != null)
            {
                Core.Instance.ActiveDocument = document;
            }
        }
Esempio n. 8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Host.EnsureInitialisation();
            ModelDocument document = Core.Instance.OpenDocument(false);

            if (document != null)
            {
                Core.Instance.ActiveDocument = document;
            }
            return(Result.Success);
        }
Esempio n. 9
0
        public override bool Execute(ExecutionInfo exInfo = null)
        {
            var parser = new GWAParser();
            GSAIDMappingTable idMap = new GSAIDMappingTable();
            Model             model = parser.ReadGWAFile(FilePath, ref idMap, null, Core.Instance.SectionLibrary);

            Document = new ModelDocument(FilePath, model);
            Document.IDMappings[FilePath] = idMap;

            return(true);
        }
Esempio n. 10
0
 public Parser2(ModelDocument Model, String Project) : base()
 {
     m_Project = Project;
     m_Model   = Model;
     m_Context = new Context();
     m_Evaluators.AddLast(new CmdDecl());
     m_Evaluators.AddLast(new CmdFunctionDecl());
     m_Evaluators.AddLast(new CmdUsing());
     m_Evaluators.AddLast(new CmdInclude());
     m_Evaluators.AddLast(new CmdComment());
     m_Evaluators.AddLast(new CmdInvalid());
 }
Esempio n. 11
0
        /// <summary>
        /// Populate a ModelDocument with default data.
        /// Returns the same ModelDocument that was input.
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public ModelDocument PopulateDefaultData(ModelDocument result)
        {
            result.Model.Materials.Add(Material.Steel);
            result.Model.Materials.Add(Material.Concrete);
            result.Model.Materials.Add(Material.Aluminium);
            result.Model.Materials.Add(Material.Glass);
            result.Model.Materials.Add(Material.Wood);
            result.Model.LoadCases.Add(new LoadCase("Dead", LoadCaseType.Dead));
            result.Model.LoadCases.Add(new LoadCase("Superimposed Dead", LoadCaseType.Dead));
            result.Model.LoadCases.Add(new LoadCase("Live", LoadCaseType.Live));

            return(result);
        }
Esempio n. 12
0
        public static TimeSpan SerializeToFormat()
        {
            var           sw  = new Stopwatch();
            ModelDocument doc = Core.GenerateTestModel(100);

            /*sw.Start();
             * var formatter = new UniqueFormatter();
             * formatter.Serialize(null, doc);
             * sw.Stop();
             * string format = formatter.GenerateFormatDescription();
             * Core.Print(format);
             *
             * var formatter2 = new UniqueFormatter();
             * formatter2.Serialize(null, null);
             * formatter2.ReadFormat(new StringReader(format).ReadLine());*/

            var filePathB = "C:/TEMP/SerializationControl.bin";

            sw.Start();
            doc.SaveAs(filePathB, DocumentSaveFileType.Binary);
            sw.Stop();
            Core.Print("Binary: " + sw.Elapsed);

            var filePath = "C:/TEMP/SerializationTest.ass";

            sw.Reset();
            sw.Start();
            doc.SaveAs(filePath, DocumentSaveFileType.Text);
            sw.Stop();
            Core.Print("ASS: " + sw.Elapsed);

            Core.Print("Reading:");

            sw.Reset();
            sw.Start();
            ModelDocument mDocB = Document.Load <ModelDocument>(filePathB, DocumentSaveFileType.Binary);

            sw.Stop();
            Core.Print("Binary: " + sw.Elapsed);

            sw.Reset();
            sw.Start();
            ModelDocument mDoc = Document.Load <ModelDocument>(filePath, DocumentSaveFileType.Text);

            sw.Stop();
            Core.Print("ASS: " + sw.Elapsed);

            var everything = mDoc.Model.Everything;

            return(sw.Elapsed);
        }
Esempio n. 13
0
        /// <summary>
        /// Save a model document to a file selected via a file dialog
        /// </summary>
        /// <param name="document">The document to be saved</param>
        /// <returns></returns>
        public bool SaveDocument(ModelDocument document)
        {
            string filters  = Actions.GetExportFilters();
            string filePath = UI.ShowSaveFileDialog("Enter filepath to write to", filters, null, Actions.ExportFilterIndex(".s3b") + 1);

            if (!string.IsNullOrEmpty(filePath))
            {
                return(SaveDocument(filePath, document));
            }
            else
            {
                return(false);
            }
        }
Esempio n. 14
0
        protected override void ReadDocument(RhinoDoc doc, BinaryArchiveReader archive, FileReadOptions options)
        {
            int major, minor;

            archive.Read3dmChunkVersion(out major, out minor);
            byte[] data = archive.ReadByteArray();
            if (!archive.ReadErrorOccured && data != null)
            {
                Host.EnsureInitialisation(true);
                ModelDocument mDoc = Document.FromBinary <ModelDocument>(data);
                Core.Instance.ActiveDocument = mDoc;
            }
            base.ReadDocument(doc, archive, options);
        }
Esempio n. 15
0
        public override bool Execute(ExecutionInfo exInfo = null)
        {
            var robot = new RobotController();

            robot.Message += HandleMessage;
            RobotIDMappingTable idMap = new RobotIDMappingTable();
            Model model = robot.LoadModelFromRobot(FilePath, ref idMap);

            Document = new ModelDocument(FilePath, model);
            robot.Close();
            robot.Release();
            Document.IDMappings[FilePath] = idMap;
            return(true);
        }
Esempio n. 16
0
        public void ReadModel(BinaryReader source, ModelDocument dest)
        {
            startOfTheFile = source.BaseStream.Position;
            //ReadHeader(source);
            //ReadTextures(source);
            //ReadBones(source);
            //ReadBodyParts(source);
            //ReadAnimations(source);

            //foreach (var bp in bodyParts)
            //    dest.Meshes.Add(BuildMesh(bp));
            //BuildAnimations(dest);
            //BuildBones(dest);
        }
Esempio n. 17
0
        /// <summary>
        /// Save a model document to a file
        /// </summary>
        /// <param name="filePath">The filepath to save to</param>
        /// <param name="document">The document to be saved</param>
        /// <returns>True if export command ran successfully</returns>
        public bool SaveDocument(FilePath filePath, ModelDocument document)
        {
            string        extension = Path.GetExtension(filePath);
            IExportAction exporter  = Actions.GetExporterFor(extension);

            if (exporter != null)
            {
                exporter.FilePath = filePath;
                exporter.Document = document;
                Actions.ExecuteAction(exporter, null, true, false);
                return(true);
            }
            PrintLine("Error: No exporter loaded for extension '." + extension + "'.  File could not be written.");
            return(false);
        }
Esempio n. 18
0
        public void SerializeModelDocumentAndDeserialize()
        {
            FilePath path = "C:/TEMP/SerializeModelDocumentAndDeserializeTest.test";

            var model = new Model.Model();

            model.Add(new LinearElement(0, 0, 0, 10, 0, 0));
            var doc = new ModelDocument(model);

            doc.SaveAs(path);

            var doc2 = ModelDocument.Load(path);

            Assert.AreEqual(1, doc2.Model.Elements.Count);
        }
Esempio n. 19
0
        public bool ConnectModelViews()
        {
            IModelView mView;

            mView = (IModelView)ModelDocument.GetFirstModelView();

            while (mView != null)
            {
                if (!OpenModelViews.Contains(mView))
                {
                    DocView dView = new DocView(UserAddin, mView, this);
                    dView.AttachEventHandlers();
                    OpenModelViews.Add(mView, dView);
                }
                mView = (IModelView)mView.GetNext();
            }
            return(true);
        }
Esempio n. 20
0
        /// <summary>
        /// Update tree for current active document
        /// </summary>
        /// <param name="root"></param>
        /// <param name="tags"></param>
        void _InsertTags(TreeNode root, List <ITag> tags)
        {
            string  _Scope = NPP.GetCurrentFile();
            Project proj   = ProjectManager.GetProjectByItsFile(_Scope);

            if (proj == null)
            {
                return;
            }
            ModelDocument _Model = proj.Model;

            _Scope = _Model.GetRelativePath(_Scope);
            TreeNode parent = new TreeNode(_Scope);

            _InsertTagsSub(parent, _Scope, _Model);
            tvClassView.Nodes.Clear();
            tvClassView.Nodes.Add(parent);
            tvClassView.ExpandAll();
        }
Esempio n. 21
0
        /// <summary>
        /// Open a design document from a file
        /// </summary>
        /// <param name="filePath">The filepath to open</param>
        /// <param name="background">If true, the opened design will not be added to the set of currently open designs or made active</param>
        /// <returns></returns>
        public ModelDocument OpenDocument(string filePath, bool background = false)
        {
            ModelDocument result = null;

            if (File.Exists(filePath))
            {
                string        extension = Path.GetExtension(filePath);
                IImportAction importer  = Actions.GetImporterFor(extension);
                if (importer != null)
                {
                    importer.FilePath = filePath;
                    Actions.ExecuteAction(importer, null, !background, false);
                    if (importer is IImportDocumentAction)
                    {
                        result = ((IImportDocumentAction)importer).Document;
                    }
                }
            }
            return(result);
        }
Esempio n. 22
0
        public static TimeSpan WriteToETABS()
        {
            var sw = new Stopwatch();

            ModelDocument doc = new ModelDocument();

            doc.Model.Create.LinearElement(new Line(0, 0, 10, 0));
            doc.Model.Create.LinearElement(new Line(0, 10, 10, 0));
            doc.Model.Create.LinearElement(new Line(0, 0, -10, 0));
            doc.Model.GenerateNodes(new NodeGenerationParameters());
            doc.Model.Add(new LinearElementSet(doc.Model.Elements));
            doc.Model.Add(new NodeSet(doc.Model.Nodes));

            var etabs = new ETABSClient();
            var idMap = new ETABSIDMappingTable();

            etabs.WriteModelToEtabs("C:\\Temp\\Test3.edb", doc.Model, ref idMap);
            etabs.Close();
            etabs.Release();

            sw.Stop();

            return(sw.Elapsed);
        }
Esempio n. 23
0
 public void ReadModel(System.IO.BinaryReader source, ModelDocument dest)
 {
     throw new NotImplementedException();
 }
Esempio n. 24
0
 private void BuildBones(ModelDocument dest)
 {
     foreach (var bone in modelBones)
         if (bone.Parent == null)
             dest.Bones.Add(bone);
 }
Esempio n. 25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="projFile"></param>
 /// <param name="root"></param>
 public Project(string projFile, ProjectItem root)
 {
     ProjectFile = projFile;
     Root        = root;
     m_Model     = new ModelDocument(projFile);
 }
        /// <summary>
        /// Convert the specified object to the specified type.
        /// Override this function to convert to data types not natively supported
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="toType"></param>
        /// <returns></returns>
        /// <remarks>Currently supported:
        ///  DesignLink.Types.Line</remarks>
        protected virtual object Convert(object obj, Type toType)
        {
            //if (obj is SectionFamilyGoo && typeof(SectionFamily).IsAssignableFrom(toType)) return ((SectionFamilyGoo)obj).Value;
            //if (toType == typeof(LinearElementGoo)) return new LinearElementGoo(obj as LinearElement);
            //else if (toType == typeof(SectionFamily)) return new SectionFamilyGoo(obj as SectionFamily);

            if (obj is ISalamander_Goo)
            {
                return(((ISalamander_Goo)obj).GetValue(toType));                        //Single items
            }
            else if (obj is IList && typeof(IList).IsAssignableFrom(toType) &&
                     typeof(ISalamander_Goo).IsAssignableFrom(obj.GetType().GetItemType()))
            {
                // Collections:
                IList list     = (IList)obj;
                IList result   = Activator.CreateInstance(toType) as IList;
                Type  itemType = obj.GetType().GetItemType();
                foreach (ISalamander_Goo item in list)
                {
                    result.Add(item.GetValue(itemType));
                }
                return(result);
            }
            else if (toType == typeof(Angle))
            {
                return(new Angle((double)obj));
            }
            else if (toType == typeof(FilePath))
            {
                return(new FilePath(obj.ToString()));
            }
            else if (toType == typeof(ActionTriggerInput))
            {
                return(new ActionTriggerInput());
            }
            else if (toType == typeof(Direction))
            {
                return(Enum.Parse(typeof(Direction), obj?.ToString()));
            }
            else if (toType == typeof(CoordinateSystemReference) && !(obj is CoordinateSystemReference))
            {
                GH_Document doc = OnPingDocument();
                if (doc != null)
                {
                    ModelDocument modelDoc = GrasshopperManager.Instance.BackgroundDocument(doc);
                    return(modelDoc?.Model?.CoordinateSystems.GetByKeyword(obj.ToString()));
                }
            }
            else if (toType.IsEnum)
            {
                return(Enum.Parse(toType, obj?.ToString()));
            }

            return(Conversion.Instance.Convert(obj, toType));

            /*
             * //From RhinoCommon:
             * if (toType.IsAssignableFrom(typeof(Curve)))
             * {
             *  if (obj is RC.Curve) return RCtoFB.Convert((RC.Curve)obj);
             * }
             * //To RhinoCommon:
             * if (toType.IsAssignableFrom(typeof(RC.Point3d)))
             * {
             *  if (obj is Vector) return FBtoRC.Convert((Vector)obj);
             * }
             * return obj;
             */
        }
Esempio n. 27
0
 public override bool Execute(ExecutionInfo exInfo = null)
 {
     Document = ModelDocument.Load(FilePath);
     return(true);
 }
Esempio n. 28
0
        public override void Run()
        {
            Settings settings = Settings.GetInstance();

            try
            {
                settings.GetDefaultSettings();
            }
            catch (LigralException)
            {
                logger.Error(new LigralException("Default settings is not valid, ligral exited with errors."));
                logger.Throw();
                return;
            }
            PluginLoader pluginLoader = new PluginLoader();

            pluginLoader.Load();
            List <Model> models = new List <Model>();

            if (ModelName is string modelName)
            {
                if (ModelManager.ModelTypePool.ContainsKey(modelName))
                {
                    models.Add(ModelManager.Create(modelName));
                }
                else
                {
                    logger.Error(new OptionException(modelName, $"No model named {modelName}"));
                    logger.Throw();
                    return;
                }
            }
            else
            {
                foreach (string modelType in ModelManager.ModelTypePool.Keys)
                {
                    if (modelType.Contains('<'))
                    {
                        continue;
                    }
                    models.Add(ModelManager.Create(modelType));
                }
            }
            if (ToJson is bool toJson && toJson)
            {
                if (OutputFolder is string outputFolder)
                {
                    settings.OutputFolder = outputFolder;
                }
                if (!Directory.Exists(settings.OutputFolder))
                {
                    Directory.CreateDirectory(settings.OutputFolder);
                }
                foreach (Model model in models)
                {
                    ModelDocument modelDocument = model.GetDocStruct();
                    string        modelJson     = JsonSerializer.Serialize <ModelDocument>(
                        modelDocument, new JsonSerializerOptions()
                    {
                        WriteIndented = true
                    }
                        );
                    string modelJsonFileName = Path.Join(settings.OutputFolder, $"{modelDocument.Type}.mdl.json");
                    try
                    {
                        File.WriteAllText(modelJsonFileName, modelJson);
                    }
                    catch (Exception e)
                    {
                        logger.Error(new LigralException($"Cannot write to {modelJsonFileName}: {e.Message}"));
                        logger.Throw();
                        return;
                    }
                }
            }
Esempio n. 29
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="document"></param>
 public DocumentOpenedEventArgs(ModelDocument document)
 {
     Document = document;
 }