//using FeMM.Common.Helpers;
//using FeMM.Grasshopper.DataTypes.FeMM;
//using FeMM.Grasshopper.Helpers;
//using Grasshopper.Kernel;
//using System;
//using System.Collections.Generic;
//using System.IO;

//namespace FeMM.Grasshopper.Components.Export
//{
//    public class StrausExportComponent : GH_Component
//    {
//        protected string _status;
//        protected bool _run;

//        /// <summary>
//        /// Initializes a new instance of the StrausExportComponent class.
//        /// </summary>
//        public StrausExportComponent()
//          : base("Straus7 Export", "ST7", "Export to Straus7", CategoryNameConstants.CATEGORY_FEMM, CategoryNameConstants.SUBCATEGORY_EXPORT)
//        {
//            _status = "";
//            _run = false;
//        }

//        public override void CreateAttributes()
//        {
//            var attr = new ComponentAttributes.ComponentOneButtonAttributes(this, "Save");
//            attr.ButtonPressed += () =>
//            {
//                _run = true;
//                ExpireSolution(true);
//            };
//            m_attributes = attr;
//        }


//        /// <summary>
//        /// Registers all the input parameters for this component.
//        /// </summary>
//        protected override void RegisterInputParams(GH_InputParamManager pManager)
//        {
//            pManager.AddGenericParameter("Model", "M", "The FEM model", GH_ParamAccess.item);
//            pManager.AddTextParameter("Output Path", "O", "The full path of the file model to create", GH_ParamAccess.item);
//            pManager.AddTextParameter("API Server IP", "IP", "The IP of the machine where runs the API server", GH_ParamAccess.item, "localhost");
//        }

//        /// <summary>
//        /// Registers all the output parameters for this component.
//        /// </summary>
//        protected override void RegisterOutputParams(GH_OutputParamManager pManager)
//        {
//            pManager.AddGenericParameter("Status", "S", "The status of the export", GH_ParamAccess.item);
//        }

//        /// <summary>
//        /// This is the method that actually does the work.
//        /// </summary>
//        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
//        protected override void SolveInstance(IGH_DataAccess DA)
//        {
//            Message = "";
//            GH_Model model = null;
//            string outputPath = "";
//            string ip = "";
//            if (!DA.GetData("Model", ref model))
//                return;
//            if (!DA.GetData("Output Path", ref outputPath))
//                return;
//            if (!DA.GetData("API Server IP", ref ip))
//                return;

//            if (Path.GetExtension(outputPath).ToLower() != ".st7")
//            {
//                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid extension in file name");
//                return;
//            }

//            if (_run)
//            {
//                if (StrausHelper.ConnectService(ip, out St7ApiWrapper.ISt7ApiService ro))
//                {
//                    if (StrausHelper.CreateModel(ro, model.Value, outputPath, Rhino.Settings.Tolerance,
//                        out int modelId, out List<string> warnings, out List<string> errors))
//                    {
//                        ro.SaveFile(modelId);
//                        ro.CloseFile(modelId);

//                        Message = "Done";
//                    }
//                    else
//                    {
//                        Message = "Error";
//                    }

//                    foreach (string warning in warnings)
//                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, warning);

//                    foreach (string error in errors)
//                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, error);
//                }
//                else
//                {
//                    Message = "Connection Error";
//                }

//                StrausHelper.DisconnectService();

//                _run = false;
//            }


//            DA.SetData(0, Message);
//        }

//        /// <summary>
//        /// Provides an Icon for the component.
//        /// </summary>
//        protected override System.Drawing.Bitmap Icon => Properties.Resources.StrausExportIcon;

//        /// <summary>
//        /// Gets the unique ID for this component. Do not change this ID after release.
//        /// </summary>
//        public override Guid ComponentGuid => new Guid("7e572885-86c1-402d-a0ea-879dac1066d5");
//    }
//}
303 files24 directories