//This method forked from: //https://github.com/jeremytammik/DirectObjLoader
        /// <summary>
        /// Create a new DirectShape element from given
        /// list of faces and return the number of faces
        /// processed.
        /// Return -1 if a face vertex index exceeds the
        /// total number of available vertices, 
        /// representing a fatal error.
        /// </summary>
        static int NewDirectShape(
            Autodesk.DesignScript.Geometry.Point[] vertices,
            IndexGroup[] faces,
            Document doc,
            ElementId graphicsStyleId,
            ElementId materialId,
            string appGuid,
            string shapeName)
        {
            int nFaces = 0;
            int nFacesFailed = 0;

            TessellatedShapeBuilder builder
              = new TessellatedShapeBuilder();

            //builder.LogString = shapeName;

            var corners = new List<Autodesk.DesignScript.Geometry.Point>();

            builder.OpenConnectedFaceSet(false);

            foreach (IndexGroup f in faces)
            {
               // builder.LogInteger = nFaces;

                corners.Clear();
                var indicies = new List<uint>() { f.A, f.B, f.C, f.D };
                for (int i = 0; i < f.Count; i++)
                {
                    var currentindex = Convert.ToInt32(indicies[i]);
                    //Debug.Assert(vertices.Length > currentindex,
                     // "how can the face vertex index be larger "
                     // + "than the total number of vertices?");

                 //   if (currentindex >= vertices.Length)
                  //  {
                  //      return -1;
                  //  }
                    corners.Add(vertices[currentindex]);
                }

                //convert all the points to Revit XYZ vectors
                var xyzs = corners.Select(x => x.ToXyz()).ToList();

                try
                {

                    builder.AddFace(new TessellatedFace(xyzs,
                      materialId));

                    ++nFaces;
                }
                catch (Autodesk.Revit.Exceptions.ArgumentException ex)
                {
                    // Remember something went wrong here.

                    ++nFacesFailed;

                    Debug.Print(
                      "Revit API argument exception {0}\r\n"
                      + "Failed to add face with {1} corners: {2}",
                      ex.Message, corners.Count,
                      string.Join(", ",
                        corners));
                }
            }
            builder.CloseConnectedFaceSet();

            // Refer to StlImport sample for more clever
            // handling of target and fallback and the
            // possible combinations.

            TessellatedShapeBuilderResult r
              = builder.Build(
                TessellatedShapeBuilderTarget.Mesh,
                TessellatedShapeBuilderFallback.Salvage,
                graphicsStyleId);

            var ds = Autodesk.Revit.DB.DirectShape.CreateElement(
              doc, _categoryId, appGuid, shapeName);

            ds.SetShape(r.GetGeometricalObjects());
            ds.Name = shapeName;

            //Debug.Print(
              //"Shape '{0}': added {1} faces, faces{2} failed.",
              //shapeName, nFaces,
              //nFacesFailed);

            return nFaces;
        }
Exemple #2
0
        /// <summary>
        /// Visualize forces and moments in the model for a specific case
        /// </summary>
        /// <param name="StructuralModel">Structural model to visualize results on</param>
        /// <param name="AnalysisResults">Use Analysis.Run and Analysis.GetResults to select a specific case to decompose</param>
        /// <param name="ForceType">Use Force Type dropdown</param>
        /// <param name="Scale">Scale of the visualization</param>
        /// <param name="Visualize">Set Boolean to True to draw the meshes</param>
        /// <returns>Forces and moments  in the form of meshes for each station in each structural member in the model</returns>
        ///
        public static List <List <Mesh> > VisualizeResults(StructuralModel StructuralModel, Analysis AnalysisResults, string ForceType, bool Visualize, double Scale = 1.0)
        {
            List <List <double> > myForces = DecomposeResults(StructuralModel, AnalysisResults, ForceType);
            double max = 0.0;

            for (int i = 0; i < myForces.Count; i++)
            {
                for (int j = 0; j < myForces[i].Count; j++)
                {
                    if (myForces[i][j] >= max)
                    {
                        max = myForces[i][j];
                    }
                }
            }
            // Define a coefficient to visualize the forces
            Frame  fs          = (Frame)StructuralModel.StructuralElements[0];
            double lenght      = 0.5 * fs.BaseCrv.Length;
            double coefficient = 0.0;

            if (max != 0)
            {
                coefficient = lenght / max;
            }

            List <List <Mesh> > VizMeshes    = new List <List <Mesh> >();
            List <Line>         frameNormals = new List <Line>();

            if (Visualize)
            {
                int j = 0;
                for (int i = 0; i < StructuralModel.StructuralElements.Count; i++)
                //for (int i = 0; i < AnalysisResults.FrameResults.Count; i++)
                {
                    //List of meshes per structural element in the model
                    List <Mesh> frameResultsMesh = new List <Mesh>();

                    // Linq inqury
                    FrameResults frmresult = null;
                    try
                    {
                        frmresult = (from frm in AnalysisResults.FrameResults
                                     where frm.ID == StructuralModel.StructuralElements[i].Label
                                     select frm).First();
                    }
                    catch { }

                    if (frmresult == null || StructuralModel.StructuralElements[i].Type != Structure.Type.Frame)
                    {
                        //Add an empty list to match the tree that contains Joints
                        VizMeshes.Add(frameResultsMesh);
                        continue;
                    }


                    // Get the frame's curve specified by the frameID
                    // Frame f = (Frame)StructuralModel.StructuralElements[i];
                    Frame f = (Frame)(from frame in StructuralModel.StructuralElements
                                      where frame.Label == frmresult.ID
                                      select frame).First();

                    Curve c = f.BaseCrv;

                    //LOCAL COORDINATE SYSTEM
                    Vector xAxis = c.TangentAtParameter(0.0);
                    Vector yAxis = c.NormalAtParameter(0.0);
                    //This ensures the right axis for the Z direction
                    CoordinateSystem localCS = CoordinateSystem.ByOriginVectors(c.StartPoint, xAxis, yAxis);

                    //LINES TO VISUALIZE THE NORMALS OF THE FRAME CURVES
                    //Point middlePt = c.PointAtParameter(0.5);
                    //Line ln = Line.ByStartPointDirectionLength(middlePt, localCS.ZAxis, 30.0);
                    //frameNormals.Add(ln);

                    //List to hold the points to make a mesh face
                    List <Point> MeshPoints = new List <Point>();

                    // t value of the previous station
                    double t1 = 0.0;
                    // t value of the current station
                    double t2 = 0.0;
                    // Local Z value of the previous station
                    double v1 = 0.0;
                    // Local Z value of the current station
                    double v2 = 0;
                    // Integer to count the number of times there are stations with value=0 (no force)
                    int zeroCount = 0;

                    // Loop through each station (t value) in the analysis results dictionary
                    foreach (double t in frmresult.Results[AnalysisResults.LCaseOrLPatternRun].Keys)
                    {
                        double newt = t;
                        if (t < 0)
                        {
                            newt = -t;
                        }
                        Mesh m = null;

                        Point tPoint = c.PointAtParameter(newt); // Point on the curve at the specified t2
                        Point vPoint = null;                     // Point that is translated from the cPoint according to the value v2

                        // Double to hold the local Z value of the station multiplied by the scale factor
                        double translateCoord = 0.0;

                        if (ForceType == "Axial") // Get Axial P
                        {
                            v2             = AnalysisResults.FrameResults[j].Results[AnalysisResults.LCaseOrLPatternRun][newt].P;
                            translateCoord = v2 * coefficient * (-Scale);
                        }

                        else if (ForceType == "Shear22") // Get Shear V2
                        {
                            v2             = AnalysisResults.FrameResults[j].Results[AnalysisResults.LCaseOrLPatternRun][newt].V2;
                            translateCoord = v2 * coefficient * (-Scale);
                        }
                        else if (ForceType == "Shear33") // Get Shear V3
                        {
                            v2             = AnalysisResults.FrameResults[j].Results[AnalysisResults.LCaseOrLPatternRun][newt].V3;
                            translateCoord = v2 * coefficient * coefficient * Scale;
                        }

                        else if (ForceType == "Torsion") // Get Torsion T
                        {
                            v2             = AnalysisResults.FrameResults[j].Results[AnalysisResults.LCaseOrLPatternRun][newt].T;
                            translateCoord = v2 * coefficient * (-Scale);
                        }

                        else if (ForceType == "Moment22") // Get Moment M2
                        {
                            v2             = AnalysisResults.FrameResults[j].Results[AnalysisResults.LCaseOrLPatternRun][newt].M2;
                            translateCoord = v2 * coefficient * (-Scale);
                        }

                        else if (ForceType == "Moment33") // Get Moment M3
                        {
                            v2             = AnalysisResults.FrameResults[j].Results[AnalysisResults.LCaseOrLPatternRun][newt].M3;
                            translateCoord = v2 * coefficient * Scale;
                        }

                        v2 = Math.Round(v2, 4, MidpointRounding.AwayFromZero);

                        // if there is no value for the force (it is zero), add one to the count
                        if (translateCoord == 0.0)
                        {
                            zeroCount++;
                        }

                        if (ForceType == "Moment22" || ForceType == "Shear33")
                        {
                            vPoint = (Point)tPoint.Translate(localCS.YAxis, translateCoord); // Translate in the Y direction to match the visualization of SAP
                        }
                        else
                        {
                            vPoint = (Point)tPoint.Translate(localCS.ZAxis, translateCoord); // All the other types must be translate in the Z direction}
                        }

                        //Point that results from the intersection of the line between two value Points and the frame curve
                        Point pzero = null;

                        IndexGroup ig3 = IndexGroup.ByIndices(0, 1, 2);
                        IndexGroup ig4 = IndexGroup.ByIndices(0, 1, 2, 3);

                        //if no points have been added yet, add the point on the curve and then the point representing the value
                        if (MeshPoints.Count == 0)
                        {
                            MeshPoints.Add(tPoint); //index 0

                            // if the first value is not 0

                            if (v2 != 0.0)
                            {
                                MeshPoints.Add(vPoint); //index 1
                            }
                        }

                        // if a previous point(s) has been added
                        else
                        {
                            // List to hold the indices for the mesh face
                            List <IndexGroup> indices = new List <IndexGroup>();

                            //Parameter at which the value of the forces = 0. It is the X coordinate of the pzero
                            double tzero;

                            // Current t parameter of the point being visualized relative to the length of the frame curve
                            t2 = newt * c.Length;

                            // If there is a change in the force sign, calculate the intersection point
                            // Then, add two trianglular mesh faces
                            if ((v1 > 0 && v2 < 0) || (v1 < 0 && v2 > 0))
                            {
                                // The function of the line is: y= (t2-t1)tzero/(d2-d1)+d1  This has to be equal to 0
                                double ml = (v2 - v1) / (t2 - t1);
                                tzero = (0 - v1) / ml;

                                // Add the X coordinate of the last mesh point
                                tzero += t1;

                                pzero = Point.ByCartesianCoordinates(localCS, tzero, 0.0, 0.0);


                                //Add the third point for the first triangular mesh face
                                MeshPoints.Add(pzero); //index 2
                                indices.Add(ig3);

                                // ||| Color coding here

                                m = Mesh.ByPointsFaceIndices(MeshPoints, indices);

                                frameResultsMesh.Add(m);

                                MeshPoints.Clear();

                                //Add the third point for the second triangular mesh face
                                MeshPoints.Add(pzero);  //new face index 0
                                // Add the current station's points
                                MeshPoints.Add(tPoint); //new face index 1
                                MeshPoints.Add(vPoint); //new face index 2

                                // ||| Color coding here

                                m = Mesh.ByPointsFaceIndices(MeshPoints, indices);
                                frameResultsMesh.Add(m);
                            }

                            // Create a quad mesh face or a triangular mesh if the first value was 0
                            else
                            {
                                MeshPoints.Add(vPoint); //index 2 (note: vPoint before cPoint)
                                MeshPoints.Add(tPoint); //index 3


                                if (MeshPoints.Count == 4)
                                {
                                    indices.Add(ig4);
                                }
                                else
                                {
                                    indices.Add(ig3);
                                }

                                // ||| Color coding here

                                m = Mesh.ByPointsFaceIndices(MeshPoints, indices);
                                frameResultsMesh.Add(m);
                            }

                            //Clear the temporary list
                            MeshPoints.Clear();

                            // Add the current station's points
                            MeshPoints.Add(tPoint); //new face index 0
                            MeshPoints.Add(vPoint); //new face index 1
                        }

                        // Update the values for the next station
                        t1 = newt * c.Length;
                        v1 = v2;
                    }

                    // If all the values were zero, show empty list in output for that specific member
                    if (zeroCount == AnalysisResults.FrameResults[j].Results[AnalysisResults.LCaseOrLPatternRun].Keys.Count)
                    {
                        frameResultsMesh.Clear();
                    }

                    VizMeshes.Add(frameResultsMesh);
                    j++;
                }
            }
            return(VizMeshes);
        }
Exemple #3
0
        public static List <List <Object> > DisplayLoads(StructuralModel StructuralModel, string LPattern = "Show All", double Size = 1.0, bool ShowValues = true, double TextSize = 1.0)
        {
            //List to hold all the load visualization objects
            List <List <Object> > LoadViz = new List <List <Object> >();

            // Length of the arrow
            Double length = 1.0;

            foreach (Element e in StructuralModel.StructuralElements)
            {
                if (e.GetType().ToString().Contains("Frame"))
                {
                    //get the length of the first frame found in the collection and use to set up a scale for the load display
                    length = ((Frame)e).BaseCrv.Length;
                    break;
                }
            }

            double max = -10000000.0;
            double min = 10000000.0;

            // Loop through all the elements in the structural model
            // get the max and minimum values of distributed loads on the frame
            foreach (Element e in StructuralModel.StructuralElements)
            {
                // If the object is a frame
                if (e.GetType().ToString().Contains("Frame"))
                {
                    Frame f = e as Frame;
                    if (f.Loads != null && f.Loads.Count > 0)
                    {
                        foreach (Load load in f.Loads)
                        {
                            if (load.LoadType == "DistributedLoad")
                            {
                                if (load.Val > max)
                                {
                                    max = load.Val;
                                }
                                if (load.Val < min)
                                {
                                    min = load.Val;
                                }
                                if (load.Val2 > max)
                                {
                                    max = load.Val2;
                                }
                                if (load.Val2 < min)
                                {
                                    min = load.Val2;
                                }
                            }
                        }
                    }
                }
            }

            double refval = Math.Abs(max);

            if (Math.Abs(max) < Math.Abs(min))
            {
                refval = Math.Abs(min);
            }

            // Loop through all the elements in the structural model
            foreach (Element e in StructuralModel.StructuralElements)
            {
                //List to hold the load visualization objects per structural member
                List <Object> LoadObjects = new List <Object>();

                // 1. If the object is a frame
                if (e.GetType().ToString().Contains("Frame"))
                {
                    Frame f = e as Frame;
                    if (f.Loads != null && f.Loads.Count > 0)
                    {
                        //Loop through all the loads on the frame
                        foreach (Load load in f.Loads)
                        {
                            // If the Load type is  a moment, throw warning
                            if (load.FMType == 2)
                            {
                                throw new Exception("Moment visualization is not supported");
                            }

                            Point labelLocation = null;
                            if (LPattern == "Show All")
                            {
                                //show all
                            }
                            else
                            {
                                if (load.lPattern.name != LPattern)
                                {
                                    continue; // show only the loads whose load pattern is the specified in the node
                                }
                            }

                            Curve  c  = f.BaseCrv;
                            double sz = Size;

                            // List to hold parameter values where arrows will be drawn
                            List <double> dd            = new List <double>();
                            bool          isDistributed = false;
                            if (load.LoadType == "DistributedLoad")
                            {
                                isDistributed = true;
                                //number of arrows to represent a Distributed Load
                                int    n    = Convert.ToInt32((load.Dist - load.Dist2) / 0.1);
                                double step = (load.Dist - load.Dist2) / n;

                                for (double i = load.Dist; i < load.Dist2; i += step)
                                {
                                    dd.Add(i);
                                }
                                dd.Add(load.Dist2);
                            }
                            else // if its a point load
                            {
                                dd.Add(load.Dist);
                            }
                            //First top point for distributed load visualization
                            Point A = null;
                            //Last top point for distributed load visualization
                            Point B = null;

                            //Vector used to translate the arrow location point
                            Vector v = null;

                            Vector xAxis          = c.TangentAtParameter(0.0);
                            Vector yAxis          = c.NormalAtParameter(0.0);
                            Vector triangleNormal = null;

                            //List to hold the index group of the mesh
                            List <IndexGroup> igs = new List <IndexGroup>();
                            igs.Add(IndexGroup.ByIndices(0, 1, 2));

                            double arrowLenght  = length / 6;
                            double triangleBase = arrowLenght / 5;

                            //Loop through all the parameter values along the curve.
                            // If it is a point load it will only have one value
                            for (int i = 0; i < dd.Count; i++)
                            {
                                //List to hold the points to create a triangular mesh per arrow
                                List <Point> pps = new List <Point>();

                                //Create the point where the arrow should be located
                                Point p1 = c.PointAtParameter(dd[i]);
                                Point p2 = null;
                                Point p3 = null;
                                Point p4 = null;

                                arrowLenght = -length / 6;
                                double b = load.Val;
                                if (load.Dist != 0)
                                {
                                    b = load.Val - (load.Val2 - load.Val) / (load.Dist2 - load.Dist) * dd[0];
                                }
                                double valueAtd = ((load.Val2 - load.Val) / (load.Dist2 - load.Dist)) * dd[i] + b;
                                if (isDistributed)
                                {
                                    arrowLenght *= valueAtd / refval;
                                }


                                //Calculate the vector needed to create the line of the arrow
                                // if it's the local X Direction
                                if (load.Dir == 1)
                                {
                                    v = xAxis;
                                }
                                // if it's the local Y Direction
                                else if (load.Dir == 2)
                                {
                                    v = yAxis;
                                }
                                // if it's the local Z Direction
                                else if (load.Dir == 3)
                                {
                                    v = xAxis.Cross(yAxis);
                                }
                                // if it's the global X Direction
                                else if (load.Dir == 4)
                                {
                                    v = Vector.ByCoordinates(arrowLenght * sz, 0.0, 0.0);
                                }
                                // if it's the global Y Direction
                                else if (load.Dir == 5)
                                {
                                    v = Vector.ByCoordinates(0.0, arrowLenght * sz, 0.0);
                                }
                                // if it's the global Z Direction
                                else if (load.Dir == 6)
                                {
                                    v = Vector.ByCoordinates(0.0, 0.0, arrowLenght * sz);
                                }
                                // if the direction is 7, 8, 9, 10 or 11
                                else
                                {
                                    throw new Exception("The direction of some of the loads is not supported");
                                }


                                if (Math.Round(v.Length, 3) != 0.0)
                                {
                                    // Create the line of the arrow
                                    p2 = (Point)p1.Translate(v);
                                    Line ln = Line.ByStartPointEndPoint(p1, p2);

                                    // Create a temporary point to hold the position of the base of the triangle of the arrow
                                    arrowLenght = length / 6;
                                    Point ptOnArrow = ln.PointAtDistance(arrowLenght / 5);
                                    triangleNormal = ln.Normal;


                                    // Translate the point on the arrow to the sides to create the base of the triangle
                                    p3 = (Point)ptOnArrow.Translate(triangleNormal, triangleBase);
                                    p4 = (Point)ptOnArrow.Translate(triangleNormal, -triangleBase);

                                    // Add the points to the list
                                    pps.Add(p1); pps.Add(p3); pps.Add(p4);

                                    //Create the triangular mesh of the arrow
                                    Mesh m = Mesh.ByPointsFaceIndices(pps, igs);

                                    //Add the arrow objects to the list
                                    LoadObjects.Add(ln);
                                    LoadObjects.Add(m);
                                }

                                // Calculate the location of the labels
                                if (isDistributed)
                                {
                                    //if it is the start value
                                    if (i == 0)
                                    {
                                        if (p2 == null)
                                        {
                                            A = p1;
                                        }
                                        else
                                        {
                                            A = p2;
                                        }
                                        if (load.Val != load.Val2)
                                        {
                                            if (Math.Round(v.Length, 3) != 0.0)
                                            {
                                                if (ShowValues)
                                                {
                                                    labelLocation = (Point)A.Translate(v.Normalized().Scale(arrowLenght / 4));
                                                    labelLocation.Translate(triangleNormal, 2 * triangleBase);

                                                    string value = Math.Round(load.Val, 2).ToString(); // value of the load rounded to two decimals
                                                    createLabel(LoadObjects, labelLocation, value, TextSize);
                                                }
                                            }
                                        }
                                    }

                                    //if it is the end value
                                    else if (i == dd.Count - 1)
                                    {
                                        if (p2 == null)
                                        {
                                            B = p1;
                                        }
                                        else
                                        {
                                            B = p2;
                                        }
                                        //If it is a distributed load, create a top line
                                        Line topLine = Line.ByStartPointEndPoint(A, B);
                                        LoadObjects.Add(topLine);

                                        if (load.Val != load.Val2)
                                        {
                                            if (Math.Round(v.Length, 3) != 0.0)
                                            {
                                                if (ShowValues)
                                                {
                                                    labelLocation = (Point)B.Translate(v.Normalized().Scale(arrowLenght / 4));
                                                    labelLocation.Translate(triangleNormal, -2 * triangleBase);

                                                    string value = Math.Round(load.Val2, 2).ToString(); // value of the load rounded to two decimals
                                                    createLabel(LoadObjects, labelLocation, value, TextSize);
                                                }
                                            }
                                        }
                                    }
                                    else if (i == Convert.ToInt32(dd.Count / 2) && load.Val == load.Val2) // if it is the middle point of a uniform distributed load
                                    {
                                        labelLocation = (Point)p2.Translate(v.Normalized().Scale(arrowLenght / 4));
                                        if (ShowValues)
                                        {
                                            string value = Math.Round(load.Val, 2).ToString(); // value of the load rounded to two decimals
                                            createLabel(LoadObjects, labelLocation, value, TextSize);
                                        }
                                    }
                                }

                                //if it is a pointLoad
                                else
                                {
                                    // If the user wants to see the values of the forces
                                    if (ShowValues)
                                    {
                                        labelLocation = (Point)p2.Translate(v.Normalized().Scale(arrowLenght / 4));
                                        string value = Math.Round(load.Val, 2).ToString(); // value of the load rounded to two decimals
                                        createLabel(LoadObjects, labelLocation, value, TextSize);
                                    }
                                }
                            }
                        }
                    }
                }

                //TO DO:
                // 2. Add condition for cable

                // 3. Add contiditon for shell

                LoadViz.Add(LoadObjects);
            }

            // Return Load Visualization
            return(LoadViz);
        }
Exemple #4
0
 /// <summary>
 /// Create a mesh from a collection of Points and a collection of IndexGroups referencing the Point collection
 ///
 /// </summary>
 /// <search>mesh,meshes
 ///             </search>
 public static Mesh ByPointsFaceIndices(IEnumerable <Point> vertexPositions, IEnumerable <IndexGroup> indices)
 {
     return(Mesh.Wrap(HostFactory.Factory.MeshByPointsFaceIndices(Point.Unwrap(vertexPositions), IndexGroup.Unwrap(indices)), true));
 }
Exemple #5
0
        private MWNumericArray GetIndexTimeSeries(IndexType type, int yieldspan)
        {
            IndexSelector ids    = new IndexSelector();
            IndexGroup    idgSWI = null;;

            switch (type)
            {
            case IndexType.SWIndustry:
                idgSWI = ids.GetSWIndustryIndex();
                break;

            case IndexType.ZXIndustry:
                idgSWI = ids.GetZXIndustryIndex();
                break;

            case IndexType.JCIndustry:
                idgSWI = ids.GetJCIndustryIndex();
                break;

            case IndexType.ZZSize:
                idgSWI = ids.GetZZSizeIndex();
                break;

            case IndexType.JCSize:
                idgSWI = ids.GetJCSizeIndex();
                break;

            case IndexType.SWProfit:
                idgSWI = ids.GetSWProfitIndex();
                break;

            case IndexType.JCStyle:
                idgSWI = ids.GetJCStyleIndex();
                break;

            default:
                throw new Exception("未知的指数类型");
            }

            idgSWI.SetDatePeriod(this.StartDate, this.EndDate);
            idgSWI.LoadData(DataInfoType.SecurityInfo);
            idgSWI.LoadData(DataInfoType.TradingPrice);

            int rows = idgSWI.SecurityHoldings[0].TradingPrice.AdjustedTimeSeries.Count;
            int cols = idgSWI.SecurityHoldings.Count;

            double[,] aryi = new double[rows, cols];
            for (int irow = 0; irow < rows; irow++)
            {
                for (int icol = 0; icol < cols; icol++)
                {
                    //从降序排列转换为升序排列
                    Nullable <double> d = null;
                    switch (yieldspan)
                    {
                    case 1:
                        d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay1;
                        break;

                    case 2:
                        d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay2;
                        break;

                    case 3:
                        d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay3;
                        break;

                    case 4:
                        d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay4;
                        break;

                    case 5:
                        d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay5;
                        break;

                    default:
                        d = idgSWI.SecurityHoldings[icol].TradingPrice.AdjustedTimeSeries[irow].UpAndDown.KLineDay1;
                        break;
                    }

                    if (d == null)
                    {
                        aryi[rows - irow - 1, icol] = 0;
                    }
                    else
                    {
                        aryi[rows - irow - 1, icol] = d.Value;
                    }
                }
            }

            MWNumericArray x = aryi;

            return(x);
        }
Exemple #6
0
        internal DynamoPipeConverter()
        {
            //conversion of strings
            AddConverter(new PipeConverter <string, PipeString>(
                             (str) => { return(new PipeString(str)); },
                             (pStr) => { return(pStr.Value); }
                             ));
            //conversion of integers
            AddConverter(new PipeConverter <int, PipeInteger>(
                             (i) => { return(new PipeInteger(i)); },
                             (pi) => { return(pi.Value); }
                             ));
            //conversion of doubles
            AddConverter(new PipeConverter <double, PipeNumber>(
                             (val) => { return(new PipeNumber(val)); },
                             (pval) => { return(pval.Value); }
                             ));
            //conversion of geometry
            var geomConv = new GeometryConverter();

            AddConverter(geomConv);

            //mesh converter
            AddConverter(new PipeConverter <Mesh, ppg.Mesh>(
                             (dm) => {
                return(new ppg.Mesh(dm.VertexPositions.Select((v) => geomConv.ptConv.ToPipe <Point, ppg.Vec>(v)).ToList(),
                                    dm.FaceIndices.Select((f) => {
                    if (f.Count == 3)
                    {
                        return new ulong[] { f.A, f.B, f.C };
                    }
                    else if (f.Count == 4)
                    {
                        return new ulong[] { f.A, f.B, f.C, f.D };
                    }
                    else
                    {
                        throw new ArgumentException("A Mesh face can only have either 3 or 4 vertices!");
                    }
                }).ToList()));
            },
                             (ppm) => {
                return(Mesh.ByPointsFaceIndices(ppm.Vertices.Select((v) => geomConv.ptConv.FromPipe <Point, ppg.Vec>(v)),
                                                ppm.Faces.Select((f) => ppg.Mesh.FaceIsTriangle(f) ? IndexGroup.ByIndices((uint)f[0], (uint)f[1], (uint)f[2]) :
                                                                 IndexGroup.ByIndices((uint)f[0], (uint)f[1], (uint)f[2], (uint)f[3]))));
            }
                             ));
        }
Exemple #7
0
        private static Autodesk.DesignScript.Geometry.Mesh SolidToMesh(Autodesk.Revit.DB.Solid solid)
        {
            Autodesk.DesignScript.Geometry.Mesh mesh = null;

            List <Autodesk.DesignScript.Geometry.Mesh> unjoinedMeshes = new List <Autodesk.DesignScript.Geometry.Mesh>();

            foreach (Autodesk.Revit.DB.Face f in solid.Faces)
            {
                Autodesk.Revit.DB.Mesh rMesh = f.Triangulate();
                Autodesk.DesignScript.Geometry.Mesh dMesh = RevitToProtoMesh.ToProtoType(rMesh, true);
                unjoinedMeshes.Add(dMesh);
            }

            // Join meshes
            if (unjoinedMeshes.Count == 0)
            {
                mesh = unjoinedMeshes[0];
            }
            else
            {
                // Join all of the meshes?
                List <Autodesk.DesignScript.Geometry.Point> vertices = new List <Autodesk.DesignScript.Geometry.Point>();
                List <IndexGroup> indexGroups = new List <IndexGroup>();

                foreach (Autodesk.DesignScript.Geometry.Mesh m in unjoinedMeshes)
                {
                    if (m == null)
                    {
                        continue;
                    }
                    int baseCount = vertices.Count;
                    foreach (Autodesk.DesignScript.Geometry.Point pt in m.VertexPositions)
                    {
                        vertices.Add(pt);
                    }
                    foreach (IndexGroup ig in m.FaceIndices)
                    {
                        if (ig.Count == 3)
                        {
                            IndexGroup iGroup = IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount));
                            indexGroups.Add(iGroup);
                        }
                        else
                        {
                            IndexGroup iGroup = IndexGroup.ByIndices((uint)(ig.A + baseCount), (uint)(ig.B + baseCount), (uint)(ig.C + baseCount), (uint)(ig.D + baseCount));
                            indexGroups.Add(iGroup);
                        }
                    }
                }
                try
                {
                    Autodesk.DesignScript.Geometry.Mesh joinedMesh = Autodesk.DesignScript.Geometry.Mesh.ByPointsFaceIndices(vertices, indexGroups);
                    if (joinedMesh != null)
                    {
                        mesh = joinedMesh;
                        simpleMeshes.Add(joinedMesh);
                    }
                }
                catch
                {
                    // For now just add them all as is
                }
            }
            return(mesh);
        }
Exemple #8
0
        private void AddToolStripButton_Click(object sender, EventArgs e)
        {
            if (_currentNode == null)
            {
                return;
            }
            _hasChanges = true;
            if (_currentNode.Parent == null)
            {
                //добавляем в верхние узлы
                if (_currentNode.Text == Resources.UmtEditorForm_BuildTree_Coil_Status)
                {
                    var x = new CoilStatus()
                    {
                        Function = Resources.UmtEditorForm_New_Element
                    };
                    Indexes.CoilStatuses.Add(x);

                    _currentNode.Nodes.Add(new TreeNode()
                    {
                        Text = Resources.UmtEditorForm_New_Element,
                        Tag  = x
                    });
                }
                else if (_currentNode.Text == Resources.UmtEditorForm_BuildTree_Input_Status)
                {
                    var x = new IndexGroup <InputStatus>()
                    {
                        Name = Resources.UmtEditorForm_New_Element
                    };
                    Indexes.InputStatusGroups.Add(x);

                    _currentNode.Nodes.Add(new TreeNode()
                    {
                        Text = Resources.UmtEditorForm_New_Element,
                        Tag  = x
                    });
                }
                else if (_currentNode.Text == Resources.UmtEditorForm_BuildTree_Input_Register)
                {
                    var x = new IndexGroup <InputRegister>()
                    {
                        Name = Resources.UmtEditorForm_New_Element
                    };
                    Indexes.InputRegisterGroups.Add(x);

                    _currentNode.Nodes.Add(new TreeNode()
                    {
                        Text = Resources.UmtEditorForm_New_Element,
                        Tag  = x
                    });
                }
                else if (_currentNode.Text == Resources.UmtEditorForm_BuildTree_Hold_Register)
                {
                    var x = new IndexGroup <HoldRegister>()
                    {
                        Name = Resources.UmtEditorForm_New_Element
                    };
                    Indexes.HoldRegisterGroups.Add(x);

                    _currentNode.Nodes.Add(new TreeNode()
                    {
                        Text = Resources.UmtEditorForm_New_Element,
                        Tag  = x
                    });
                }
                else if (_currentNode.Text == Resources.UmtEditorForm_BuildTree_Custom_types)
                {
                    var t = new CustomType()
                    {
                        Name = Resources.UmtEditorForm_New_Element
                    };
                    Indexes.CustomTypes.Add(t);

                    _currentNode.Nodes.Add(new TreeNode()
                    {
                        Text = Resources.UmtEditorForm_New_Element,
                        Tag  = t
                    });
                }
            }
            else
            {
                //добавляем в группу
                var group = _currentNode.Tag;
                if (group != null)
                {
                    var type = group.GetType();
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IndexGroup <>))
                    {
                        var newElement = Activator.CreateInstance(type.GetGenericArguments()[0]) as BaseIndex;
                        if (newElement != null)
                        {
                            newElement.Function = Resources.UmtEditorForm_New_Element;
                            (group as IList)?.Add(newElement);
                            _currentNode.Nodes.Add(new TreeNode()
                            {
                                Text = Resources.UmtEditorForm_New_Element,
                                Tag  = newElement
                            });
                        }
                    }
                }
            }

            _currentNode.Expand();
        }
 public int Add(int vertIndex, int normIndex, int texcoordIndex)
 {
     IndexGroup[] newData = new IndexGroup[this.Count + 1];
     int idx = 0;
     if (null != _groups)
     {
         foreach (IndexGroup ig in _groups)
         {
             newData[idx++] = ig;
         }
     }
     newData[idx] = new IndexGroup(vertIndex, normIndex, texcoordIndex);
     _groups = newData;
     return _groups.Length - 1;
 }
Exemple #10
0
 public virtual void GiveThisSelectorARotation(IndexGroup selectedIndexes)
 {
     throw new System.NotImplementedException();
 }
Exemple #11
0
 public IndexGroup(IndexGroup _group)
 {
     Values = new List <int> (_group.Values);
 }