Beispiel #1
0
        /// <summary>
        /// Adds a new, colored 3D text object to the display list.
        /// </summary>
        /// <param name="text">Text to add.</param>
        /// <param name="plane">Plane for text orientation.</param>
        /// <param name="size">Height (in units) of font.</param>
        /// <param name="color">Color of text.</param>
        public void AddText(string text, Plane plane, double size, Color color)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified");
            }
            if (text == null)
            {
                return;
            }
            if (text.Length == 0)
            {
                return;
            }
            if (!plane.IsValid)
            {
                return;
            }
            if (size <= 0.9)
            {
                return;
            }

            CDU_Text cdu = new CDU_Text();

            cdu.m_color       = Color.FromArgb(255, color);
            cdu.m_text        = new Text3d(text, plane, size);
            cdu.m_text.Bold   = false;
            cdu.m_text.Italic = false;

            m_text.Add(cdu);
            m_clip.Union(cdu.m_text.BoundingBox);
        }
Beispiel #2
0
            /// <summary>
            /// Returns an array of all group names.
            /// </summary>
            /// <param name="ignoreDeletedGroups">Ignore any groups that were deleted.</param>
            /// <returns>An array if group names if succesful, null if there are no groups.</returns>
            /// <since>5.0</since>
            public string[] GroupNames(bool ignoreDeletedGroups)
            {
                int count = Count;

                if (count < 1)
                {
                    return(null);
                }
                Rhino.Collections.RhinoList <string> names = new Rhino.Collections.RhinoList <string>(count);
                for (int i = 0; i < count; i++)
                {
                    if (ignoreDeletedGroups && IsDeleted(i))
                    {
                        continue;
                    }
                    string name = GroupName(i);
                    if (!string.IsNullOrEmpty(name))
                    {
                        names.Add(name);
                    }
                }
                if (names.Count < 1)
                {
                    return(null);
                }
                return(names.ToArray());
            }
        public DocObjects.ObjRef[] Objects()
        {
            int count = ObjectCount;

            if (count < 1)
            {
                return(null);
            }
            Rhino.Collections.RhinoList <DocObjects.ObjRef> objrefs = new Rhino.Collections.RhinoList <Rhino.DocObjects.ObjRef>(count);
            for (int i = 0; i < count; i++)
            {
                DocObjects.ObjRef objref = Object(i);
                objrefs.Add(objref);
            }
            return(objrefs.ToArray());
        }
Beispiel #4
0
 /// <summary>
 /// Adds a list of objects to an existing group.
 /// </summary>
 /// <param name="groupIndex">The group index value.</param>
 /// <param name="objectIds">An array, a list or any enumerable set of IDs to objects.</param>
 /// <returns>true if at least an operation was successful.</returns>
 /// <since>5.0</since>
 public bool AddToGroup(int groupIndex, System.Collections.Generic.IEnumerable <Guid> objectIds)
 {
     if (null == objectIds)
     {
         return(false);
     }
     Rhino.Collections.RhinoList <Guid> ids = new Rhino.Collections.RhinoList <Guid>();
     foreach (Guid id in objectIds)
     {
         ids.Add(id);
     }
     if (ids.Count < 1)
     {
         return(false);
     }
     return(UnsafeNativeMethods.CRhinoGroupTable_AddToGroup(m_doc.RuntimeSerialNumber, groupIndex, ids.Count, ids.m_items));
 }
Beispiel #5
0
 /// <summary>
 /// Adds a new group to the group table with a set of objects.
 /// </summary>
 /// <param name="groupName">Name of new group.</param>
 /// <param name="objectIds">An array, a list or any enumerable set of object IDs.</param>
 /// <returns>
 /// &gt;=0 index of new group.
 /// <para>-1 group not added because a group with that name already exists.</para>
 /// </returns>
 /// <remarks>
 /// In some cases, calling Add() can cause the group indices to become invalid.
 /// </remarks>
 /// <since>5.0</since>
 public int Add(string groupName, System.Collections.Generic.IEnumerable <Guid> objectIds)
 {
     if (null == objectIds)
     {
         return(Add(groupName));
     }
     Rhino.Collections.RhinoList <Guid> ids = new Rhino.Collections.RhinoList <Guid>();
     foreach (Guid id in objectIds)
     {
         ids.Add(id);
     }
     if (ids.Count < 1)
     {
         return(Add(groupName));
     }
     return(UnsafeNativeMethods.CRhinoGroupTable_Add(m_doc.RuntimeSerialNumber, groupName, ids.Count, ids.m_items));
 }
Beispiel #6
0
        /// <summary>
        /// Adds a new, colored arc to the display list.
        /// </summary>
        /// <param name="arc">Arc to add.</param>
        /// <param name="color">Color of arc.</param>
        /// <param name="thickness">Thickness of arc.</param>
        public void AddArc(Arc arc, Color color, int thickness)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified");
            }
            if (!arc.IsValid)
            {
                return;
            }

            CDU_Arc cdu = new CDU_Arc();

            cdu.m_arc       = arc;
            cdu.m_color     = Color.FromArgb(255, color);
            cdu.m_thickness = thickness;

            m_arcs.Add(cdu);
            m_clip.Union(arc.BoundingBox());
        }
Beispiel #7
0
        /// <summary>
        /// Adds a new, colored line to the display list.
        /// </summary>
        /// <param name="line">Line to add.</param>
        /// <param name="color">Color of line.</param>
        /// <param name="thickness">Thickness of line.</param>
        public void AddLine(Line line, Color color, int thickness)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified");
            }
            if (!line.IsValid)
            {
                return;
            }

            CDU_Line cdu = new CDU_Line();

            cdu.m_line      = line;
            cdu.m_color     = Color.FromArgb(255, color);
            cdu.m_thickness = thickness;

            m_lines.Add(cdu);
            m_clip.Union(line.BoundingBox);
        }
Beispiel #8
0
        /// <summary>
        /// Adds a new stylized point to the display list.
        /// </summary>
        /// <param name="point">Point to add.</param>
        /// <param name="color">Color of point.</param>
        /// <param name="style">Display style of point.</param>
        /// <param name="radius">Radius of point widget.</param>
        public void AddPoint(Point3d point, Color color, PointStyle style, int radius)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified");
            }
            if (!point.IsValid)
            {
                return;
            }

            CDU_Point cdu = new CDU_Point();

            cdu.m_point  = point;
            cdu.m_color  = Color.FromArgb(255, color);
            cdu.m_style  = style;
            cdu.m_radius = radius;

            m_points.Add(cdu);
            m_clip.Union(point);
        }
Beispiel #9
0
        /// <summary>
        /// Adds a polygon to the drawing list. Polygons are not like Hatches, when you supply a concave
        /// polygon, the shading probably won't work.
        /// </summary>
        /// <param name="polygon">Points that define the corners of the polygon.</param>
        /// <param name="fillColor">Fill color of polygon.</param>
        /// <param name="edgeColor">Edge color of polygon.</param>
        /// <param name="drawFill">If true, the polygon contents will be drawn.</param>
        /// <param name="drawEdge">If true, the polygon edge will be drawn.</param>
        public void AddPolygon(IEnumerable <Point3d> polygon, Color fillColor, Color edgeColor, bool drawFill, bool drawEdge)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified");
            }
            if (polygon == null)
            {
                return;
            }
            Polyline pgon = new Polyline(polygon);

            CDU_Polygon cdu = new CDU_Polygon();

            cdu.m_polygon    = pgon;
            cdu.m_color_fill = fillColor;
            cdu.m_color_edge = edgeColor;
            cdu.m_draw_fill  = drawFill;
            cdu.m_draw_edge  = drawEdge;

            m_polygons.Add(cdu);
            m_clip.Union(pgon.BoundingBox);
        }
Beispiel #10
0
        /// <summary>
        /// Adds a new, colored curve to the display list.
        /// The curve will be duplicated so changes to the
        /// original will not affect the display.
        /// </summary>
        /// <param name="curve">Curve to add.</param>
        /// <param name="color">Color of curve.</param>
        /// <param name="thickness">Thickness of curve.</param>
        public void AddCurve(Curve curve, Color color, int thickness)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified");
            }
            if (curve == null)
            {
                return;
            }
            if (!curve.IsValid)
            {
                return;
            }

            CDU_Curve cdu = new CDU_Curve();

            cdu.m_curve     = curve.DuplicateCurve();
            cdu.m_color     = Color.FromArgb(255, color);
            cdu.m_thickness = thickness;

            m_curves.Add(cdu);
            m_clip.Union(cdu.m_curve.GetBoundingBox(false));
        }
Beispiel #11
0
        /// <summary>
        /// Adds a new, colored vector to the display list.
        /// </summary>
        /// <param name="anchor">Anchor point of vector.</param>
        /// <param name="span">Direction and magnitude of vector.</param>
        /// <param name="color">Color of vector.</param>
        /// <param name="drawAnchor">Include a point at the vector anchor.</param>
        public void AddVector(Point3d anchor, Vector3d span, Color color, bool drawAnchor)
        {
            if (m_disposed)
            {
                throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified");
            }
            if (!anchor.IsValid)
            {
                return;
            }
            if (!span.IsValid)
            {
                return;
            }

            CDU_Vector cdu = new CDU_Vector();

            cdu.m_span   = new Line(anchor, span);
            cdu.m_color  = Color.FromArgb(255, color);
            cdu.m_anchor = drawAnchor;

            m_vectors.Add(cdu);
            m_clip.Union(cdu.m_span.BoundingBox);
        }
 public DocObjects.ObjRef[] Objects()
 {
   int count = ObjectCount;
   if (count < 1)
     return null;
   Rhino.Collections.RhinoList<DocObjects.ObjRef> objrefs = new Rhino.Collections.RhinoList<Rhino.DocObjects.ObjRef>(count);
   for(int i=0; i<count; i++)
   {
     DocObjects.ObjRef objref = Object(i);
     objrefs.Add(objref);
   }
   return objrefs.ToArray();
 }
Beispiel #13
0
 public string[] GroupNames( bool ignoreDeletedGroups )
 {
   int count = Count;
   if (count < 1)
     return null;
   Rhino.Collections.RhinoList<string> names = new Rhino.Collections.RhinoList<string>(count);
   for (int i = 0; i < count; i++)
   {
     if (ignoreDeletedGroups && IsDeleted(i))
       continue;
     string name = GroupName(i);
     if (!string.IsNullOrEmpty(name))
       names.Add(name);
   }
   if (names.Count < 1)
     return null;
   return names.ToArray();
 }
Beispiel #14
0
 /// <summary>
 /// Adds a list of objects to an existing group.
 /// </summary>
 /// <param name="groupIndex">The group index value.</param>
 /// <param name="objectIds">An array, a list or any enumerable set of IDs to objects.</param>
 /// <returns>true if at least an operation was successful.</returns>
 public bool AddToGroup(int groupIndex, System.Collections.Generic.IEnumerable<Guid> objectIds)
 {
   if (null == objectIds)
     return false;
   Rhino.Collections.RhinoList<Guid> ids = new Rhino.Collections.RhinoList<Guid>();
   foreach (Guid id in objectIds)
   {
     ids.Add(id);
   }
   if (ids.Count < 1)
     return false;
   return UnsafeNativeMethods.CRhinoGroupTable_AddToGroup(m_doc.m_docId, groupIndex, ids.Count, ids.m_items);
 }
Beispiel #15
0
 /// <summary>
 /// Adds a new group to the group table with a set of objects.
 /// </summary>
 /// <param name="groupName">Name of new group.</param>
 /// <param name="objectIds">An array, a list or any enumerable set of object IDs.</param>
 /// <returns>
 /// &gt;=0 index of new group. 
 /// <para>-1 group not added because a group with that name already exists.</para>
 /// </returns>
 /// <remarks>
 /// In some cases, calling Add() can cause the group indices to become invalid.
 /// </remarks>
 public int Add(string groupName, System.Collections.Generic.IEnumerable<Guid> objectIds)
 {
   if( null==objectIds )
     return Add(groupName);
   Rhino.Collections.RhinoList<Guid> ids = new Rhino.Collections.RhinoList<Guid>();
   foreach( Guid id in objectIds)
   {
     ids.Add(id);
   }
   if( ids.Count<1 )
     return Add(groupName);
   return UnsafeNativeMethods.CRhinoGroupTable_Add(m_doc.m_docId, groupName, ids.Count, ids.m_items);
 }
        // This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Some variables
            string output = "";                        // The file output
            string status = "Starting component...\n"; // The debug output

            // Several arrays where the data is stored
            List <Material>     materials     = new List <Material>();
            List <CrossSection> crossSections = new List <CrossSection>();
            List <Node>         nodes         = new List <Node>();
            List <Beam>         beams         = new List <Beam>();
            List <Load>         loads         = new List <Load>();


            // We need to reset some variables because the objects are not freed until Grasshopper is unloaded
            Parser.id_count = 1;

            bool   iSofistik      = false;
            string sofistikPath   = "";
            bool   iTeddy         = false;
            bool   AccessDatabase = false;

            DA.GetData(1, ref beamSplit);
            DA.GetData(3, ref iSofistik);
            DA.GetData(4, ref iTeddy);
            DA.GetData(5, ref AccessDatabase);
            if (!Directory.Exists(@"C:/Program Files/SOFiSTiK/2018/SOFiSTiK 2018"))
            {
                DA.GetData(6, ref sofistikPath);
            }

            if (AccessDatabase)
            {
                AccessSofistik.AccessSofData.Main();
            }

            try {
                // Load the data from Karamba

                // Retrieve and clone the input model
                GH_Model in_gh_model = null;
                if (!DA.GetData <GH_Model>(0, ref in_gh_model))
                {
                    return;
                }
                Model model = in_gh_model.Value;
                model = (Karamba.Models.Model)model.Clone();  // If the model is not cloned a modification to this variable will imply modification of the input model, thus modifying behavior in other components.
                if (model == null)
                {
                    status += "ERROR: The input model is null.";
                    output  = "Nothing to convert";
                }
                else
                {
                    string path = null;
                    if (!DA.GetData <string>(2, ref path))
                    {
                        path = "";
                    }
                    if (path == "")
                    {
                        status  += "No file path specified. Will not save data to a .dat file.\n";
                        filePath = path;
                    }


                    // Retrieve and store the data
                    // Materials
                    for (int i = 0; i < model.materials.Count; i++)
                    {
                        materials.Add(new Material(model.materials[i], i + 1));
                    }

                    status += materials.Count + " materials loaded...\n";

                    // Cross sections
                    for (int i = 0; i < model.crosecs.Count; i++)
                    {
                        crossSections.Add(new CrossSection(model.crosecs[i], i + 1));
                    }

                    //Add beam ID's to crossections/materials/loads
                    foreach (Karamba.Elements.ModelBeam beam in model.elems)
                    {
                        foreach (CrossSection crosec in crossSections)
                        {
                            if (beam.crosec.name == crosec.name)
                            {
                                crosec.ids.Add(beam.ind.ToString());
                            }
                        }

                        foreach (Material material in materials)
                        {
                            if (beam.crosec.material.name == material.name)
                            {
                                material.ids.Add(beam.ind.ToString());
                            }
                        }
                    }


                    // Nodes
                    foreach (Karamba.Nodes.Node node in model.nodes)
                    {
                        nodes.Add(new Node(node));
                    }
                    status += nodes.Count + " nodes loaded...\n";

                    // Supports
                    foreach (Karamba.Supports.Support support in model.supports)
                    {
                        nodes[support.node_ind].addConstraint(support);
                    }
                    status += "Support constraints added to " + model.supports.Count + " nodes.\n";

                    // Beams
                    foreach (Karamba.Elements.ModelElement beam in model.elems)
                    {
                        Beam curBeam = new Beam(beam);
                        // Adding the start and end nodes
                        curBeam.start = nodes[curBeam.ids[0]];
                        curBeam.end   = nodes[curBeam.ids[1]];
                        beams.Add(curBeam);
                    }

                    status += beams.Count + " beams loaded...\n";

                    // Loads
                    foreach (KeyValuePair <int, Karamba.Loads.GravityLoad> load in model.gravities)
                    {
                        loads.Add(new Load(load));
                    }
                    status += model.gravities.Count + " gravity loads added.\n";
                    foreach (Karamba.Loads.PointLoad load in model.ploads)
                    {
                        Load current = new Load(load);
                        current.node = nodes[load.node_ind];
                        loads.Add(current);
                    }
                    status += model.ploads.Count + " point loads added.\n";

                    foreach (Karamba.Loads.ElementLoad load in model.eloads)
                    {
                        // Create a load variable base on the load type
                        Load current = new Load();
                        Karamba.Loads.UniformlyDistLoad line = load as Karamba.Loads.UniformlyDistLoad;
                        //Karamba.Loads.PreTensionLoad pret = load as Karamba.Loads.PreTensionLoad;
                        Karamba.Loads.TemperatureLoad temp = load as Karamba.Loads.TemperatureLoad;


                        //else if (pret != null) {
                        //    current = new Load(pret);
                        //}

                        //If there is not target element, apply the load to the whole structure


                        if (load.beamIds[0] == "")
                        {
                            current.beam_id = "";
                            loads.Add(current);
                        }
                        else
                        {
                            // We search the element
                            foreach (string beamid in load.beamIds)
                            {
                                if (line != null)
                                {
                                    current = new Load(line);
                                }
                                // Very important to check Temperature BEFORE Pretension becaus Temperature derivates from Pretension
                                else if (temp != null)
                                {
                                    current = new Load(temp);
                                }
                                current.beam.user_id = beamid;
                                current.beam_id      = (beamid);
                                loads.Add(current);
                            }
                        }
                    }

                    // ID matching
                    // Karamba and Sofistik use different ID systems
                    // Karamba's materials and cross sections are pointing to an element ID
                    // Sofistik's elements need a cross section ID which needs a material ID

                    foreach (Material material in materials)
                    {
                        // If the IDs list is empty, it means that we want to apply the material to the whole structure (whichi is the default behavior: the default material is set by the constructors of all elements)
                        bool test = false;
                        foreach (string id in material.ids)
                        {
                            if (id != "")
                            {
                                test = true;
                            }
                        }
                        if (test)
                        {
                            foreach (CrossSection crosec in crossSections)
                            {
                                if (material.ids.Contains((crosec.id).ToString()))
                                {
                                    crosec.material = material;
                                }
                            }
                        }
                    }
                    status += "Matching with material IDs...\n";

                    foreach (CrossSection crosec in crossSections)
                    {
                        // If the IDs list is empty, it means that we want to apply the cross section to the whole structure (which is the default behavior: the default cross section is set by the constructors of all elements)
                        bool test = false;
                        foreach (string id in crosec.ids)
                        {
                            if (id != "")
                            {
                                test = true;
                            }
                        }
                        if (test)
                        {
                            foreach (Beam beam in beams)
                            {
                                if (crosec.ids.Contains((beam.id - 1).ToString()))
                                {
                                    beam.sec = crosec;
                                }
                            }
                        }
                    }
                    status += "Matching with cross section IDs...\n";

                    // Write the data into a .dat file format
                    Parser parser = new Parser(materials, crossSections, nodes, beams, loads);
                    output = parser.file;

                    if (path != "")
                    {
                        status += "Saving file to " + path + "\n";

                        System.IO.File.WriteAllText(@path, output);
                        status += "File saved!\n";
                    }



                    if (iSofistik == true && Directory.Exists(@"C:/Program Files/SOFiSTiK/2018/SOFiSTiK 2018") && path != "")
                    {
                        string targetPath = Path.GetFullPath(path);
                        System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.FileName  = "cmd.exe";
                        startInfo.Arguments = "/k cd C:/Program Files/SOFiSTiK/2018/SOFiSTiK 2018/ & sps -B " + targetPath;
                        process.StartInfo   = startInfo;
                        process.Start();
                    }
                    else if (Directory.Exists(@"C:/Program Files/SOFiSTiK/2018/SOFiSTiK 2018") == false)
                    {
                        string targetPath = Path.GetFullPath(path);
                        string sofPath    = Path.GetFullPath(sofistikPath);
                        System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.FileName  = "cmd.exe";
                        startInfo.Arguments = "/k cd " + sofPath + " & sps -B " + targetPath;
                        process.StartInfo   = startInfo;
                        process.Start();
                    }

                    if (iTeddy)
                    {
                        string targetPath = Path.GetFullPath(path);
                        System.Diagnostics.Process          process   = new System.Diagnostics.Process();
                        System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                        startInfo.FileName  = "cmd.exe";
                        startInfo.Arguments = "/c" + targetPath;
                        process.StartInfo   = startInfo;
                        process.Start();
                    }
                }
            }
            catch (Exception e) {
                status += "\nERROR!\n" + e.ToString() + "\n" + e.Data;
            }

            Rhino.Collections.RhinoList <string> oBeamForces = new Rhino.Collections.RhinoList <string>();

            foreach (string force in AccessSofistik.AccessSofData.SofBeamForces)
            {
                oBeamForces.Add(force.ToString());
            }

            // Return data
            DA.SetData(0, output);
            DA.SetData(1, status);
            DA.SetDataList(2, AccessSofistik.AccessSofData.SofBeamForces);
        }