コード例 #1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // TODO: complete command.
            MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;

            if (p.if_painted_object_set_ == false)
            {
                RhinoApp.WriteLine("No mesh");
                return(Result.Failure);
            }
            Mesh my_mesh = p.painted_object_;

            DijkstraGraph my_graph = p.graph;
            GetObject     gcurve   = new GetObject();

            gcurve.SetCommandPrompt("Get nurbscurve");
            gcurve.GeometryFilter  = Rhino.DocObjects.ObjectType.Curve;
            gcurve.SubObjectSelect = false;
            gcurve.Get();
            if (gcurve.CommandResult() != Result.Success)
            {
                return(gcurve.CommandResult());
            }
            ObjRef      curve_objref              = gcurve.Object(0);
            RhinoObject curve_obj                 = curve_objref.Object();
            Curve       selected_curve            = curve_objref.Curve();
            NurbsCurve  nurbs_curve               = selected_curve.ToNurbsCurve();
            Guid        path_id                   = selected_curve.UserDictionary.GetGuid("PathID");
            IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve);

            foreach (RhinoObject path in path_objref)
            {
                doc.Objects.Delete(path, true);
            }
            List <NurbsCurve> new_path_list = new List <NurbsCurve>();

            new_path_list = my_graph.DijkstraPath_DeletePath(path_id);

            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor      = Color.Yellow;
            my_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
            my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
            my_attributes.PlotWeight       = 2.0;

            //doc.Objects.Delete(my_objref1, true);

            for (int i = 0; i < new_path_list.Count; i++)
            {
                Guid PathID = new_path_list[i].UserDictionary.GetGuid("PathID");
                my_attributes.ObjectId = PathID;
                doc.Objects.Add(new_path_list[i], my_attributes);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
コード例 #2
0
        /// <summary>
        /// Rhino calls the virtual ReplayHistory functions to to remake an objects when inputs have changed.
        /// </summary>
        protected override bool ReplayHistory(ReplayHistoryData replay)
        {
            ObjRef rail_objref  = null;
            ObjRef shape_objref = null;
            double tolerance    = RhinoMath.UnsetValue;

            if (!ReadHistory(replay, ref rail_objref, ref shape_objref, ref tolerance))
            {
                return(false);
            }

            Rhino.Geometry.Curve rail_curve = rail_objref.Curve();
            if (null == rail_curve)
            {
                return(false);
            }

            Rhino.Geometry.Curve shape_curve = shape_objref.Curve();
            if (null == shape_curve)
            {
                return(false);
            }

            if (!Rhino.RhinoMath.IsValidDouble(tolerance))
            {
                tolerance = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
            }

            Brep[] brep = Brep.CreateFromSweep(rail_curve, shape_curve, false, tolerance);
            if (null == brep || 0 == brep.Length)
            {
                return(false);
            }

            for (int i = 0; i < brep.Length; i++)
            {
                if (null != replay.Results[i])
                {
                    replay.Results[i].UpdateToBrep(brep[i], null);
                }
                else
                {
                    break;
                }
            }

            return(true);
        }
コード例 #3
0
        //Method checks whether there are any unclosed curves in the panels.
        private void checkClosedContours()
        {
            RhinoObject[] perimeterObjects = null;
            List <String> sortingList      = new List <String>();
            int           objectFound      = 5;
            int           indexCount       = 0;

            labelObjects     = doc.Objects.FindByLayer("LABELS");          //get the label objects
            labelObjects     = removeFalseLabels(labelObjects);
            perimeterObjects = doc.Objects.FindByLayer("PANEL PERIMETER"); //get the perimeter objects
            objectFound      = (perimeterObjects.Length) - 1;
            indexCount       = (perimeterObjects.Length) - 1;
            foreach (RhinoObject obj in labelObjects)
            {
                sortingList.Add(((AnnotationObjectBase)obj).DisplayText);
            }

            foreach (RhinoObject panel in labelObjects)
            {
                RhinoObject rh = perimeterObjects[objectFound];

                ObjRef objRef = new ObjRef(rh);
                Curve  curve  = objRef.Curve();
                if (curve.IsClosed == false)
                {
                    RhinoApp.WriteLine(objRef.ToString() + "curve is open");
                    curveOpen = true;
                    unClosedPanels.Add(sortingList[indexCount]); //adds the panel label name to the list
                }
                if (objectFound > 0 && indexCount > 0)
                {
                    objectFound--;
                    indexCount--;
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Rhino calls the virtual ReplayHistory functions to to remake an objects when inputs have changed.
        /// </summary>
        protected override bool ReplayHistory(Rhino.DocObjects.ReplayHistoryData replay)
        {
            Rhino.DocObjects.ObjRef objref2 = null;
            List <Curve>            curves2 = new List <Curve>();

            Brep[]        pipe2;
            PipeCapMode[] pCapM = { PipeCapMode.None, PipeCapMode.Flat, PipeCapMode.Round };

            double radius1 = 0.0;
            double radius2 = 0.0;

            double[] radiParam = { 0.0, 0.5, 1.0 };
            double[] radi      = { radius1, radius2, radius1 };

            if (!ReadHistory(replay, ref ids, ref radius1, ref radius2, ref capIndex))
            {
                return(false);
            }

            foreach (Guid i in ids)
            {
                objref2 = new ObjRef(i);
                Rhino.Geometry.Curve curve = objref2.Curve();
                curves2.Add(curve);
            }

            foreach (Curve x in curves2)
            {
                pipe2 = Brep.CreatePipe(x, radiParam, radi, true, pCapM[capIndex], true, 0.01, 0.01);
                replay.Results[0].UpdateToBrep(pipe2[0], null);
            }



            return(true);
        }
コード例 #5
0
        /**
         * Method contains the logic to draw fixing holes evening on the panel based on the user's criteria
         * */
        public static List <Guid> drawFixingFoles(PerforationPanel panel, FoldedPerforationPanel foldPanel, Boolean Folded, double panelBottom, double panelLeft, int folds, double panelY0, double panelY1, DimensionStyle dimStyle, List <Guid> guidList, double panelX0, double panelX1, double panelRight, double panelTop)
        {
            RhinoDoc doc = RhinoDoc.ActiveDoc;

            Rhino.Geometry.Point3d pt;
            Point3d offset;
            Plane   plane = Rhino.Geometry.Plane.WorldXY;
            Point3d origin;
            double  pointOne = 0;

            //Execute the method only if atleast one of the side contain fixing holes
            if (panel.TopFixingHoles.Equals("1") || panel.BottomFixingHoles.Equals("1") || panel.LeftFixingHoles.Equals("1") || panel.RightFixingHoles.Equals("1"))
            {
                int tempLayerIndex = 0;
                tempLayerIndex = createSubLayers.createSubLayer("FIXING HOLES DIMENSIONS",
                                                                System.Drawing.Color.DarkGreen, doc.Layers[doc.Layers.Find("LAYERS FOR APPROVAL DRAWINGS", true)]);

                Rhino.DocObjects.RhinoObject[] go = null;
                int layerIndex = createSubLayers.createSubLayer("FIXING HOLES",
                                                                System.Drawing.Color.Black, doc.Layers[doc.Layers.Find("LAYERS FOR NESTING", true)]);
                doc.Layers.SetCurrentLayerIndex(layerIndex, true);



                go = doc.Objects.FindByLayer("Fixing");

                double holeSize               = panel.HoleDiameter;
                double totalTopFixingHoles    = panel.TopFixingHoleQuantity;
                double totalBottomFixingHoles = panel.BottomFixingHoleQuantity;
                double totalLeftFixingHoles   = panel.LeftFixingHoleQuantity;
                double totalRightFixingHoles  = panel.RightFixingHoleQuantity;



                int objecTCount = go.Length;

                foreach (RhinoObject ob in go)
                {
                    ObjRef objRef = new ObjRef(ob);
                    Curve  curve  = objRef.Curve();

                    // If curve is null, means objRef is not a curve
                    if (curve == null)
                    {
                        continue;
                    }

                    // If curve is not Closed Curve
                    if (curve.IsClosed == false)
                    {
                        RhinoApp.WriteLine(objRef.ToString() + " curve is open");
                        continue;
                    }

                    if (curve.IsPlanar() == false)
                    {
                        RhinoApp.WriteLine(objRef.ToString() + " curve is not planar");
                        continue;
                    }


                    // Find the boundary
                    BoundingBox boundingBox = curve.GetBoundingBox(Plane.WorldXY);
                    Point3d     min         = boundingBox.Min;
                    Point3d     max         = boundingBox.Max;

                    List <Point3d> pointsList = new List <Point3d>();
                    double         runningX   = 0;
                    double         runningY   = 0;
                    runningY = max.Y - panel.TopHoleSetbackTop; //calculate the starting point for the first from the right (with setback)

                    if (Folded)
                    {
                        runningX = panelX0 + foldPanel.LeftFirstFoldSetbackTop + foldPanel.KFactor + panel.TopHoleSetbackLeft;
                    }
                    else
                    {
                        runningX = min.X + panel.TopHoleSetbackLeft; //calculate the starting point for the first hole from the left(with set back)
                    }

                    int     points = 1;
                    Point3d point;



                    //Draw the top holes
                    if (panel.TopFixingHoles.Equals("1"))
                    {
                        if (Folded)
                        {
                            if (folds == 4)
                            {
                                if (foldPanel != null)
                                {
                                    point = new Point3d(panelX1 - panel.TopHoleSetbackRight - foldPanel.TopFirstFoldSetbackRight, runningY, 0); //adds the top right fixing hole
                                }
                                else
                                {
                                    point = new Point3d(panelX1 - foldPanel.RightFirstFoldSetbackBottom - foldPanel.KFactor - panel.TopHoleSetbackRight, runningY, 0); //adds the top right fixing hole
                                }
                                pointsList.Add(point);

                                point = new Point3d(runningX, runningY, 0); //adds the top left fixing hole
                                pointsList.Add(point);

                                while (points <= (panel.TopFixingHoleQuantity - 2))
                                {
                                    runningX = runningX + panel.TopFixingHoleDistance; //multiply by 2 to increase width (for equaliity)
                                    point    = new Point3d(runningX, runningY, 0);     //adds the top left fixing hole
                                    pointsList.Add(point);
                                    points++;
                                }
                            }
                        }
                        else
                        {
                            point = new Point3d(max.X - panel.TopHoleSetbackRight, runningY, 0); //adds the top right fixing hole
                            pointsList.Add(point);

                            point = new Point3d(runningX, runningY, 0); //adds the top left fixing hole
                            pointsList.Add(point);

                            while (points <= (panel.TopFixingHoleQuantity - 2))
                            {
                                runningX = runningX + panel.TopFixingHoleDistance; //multiply by 2 to increase width (for equaliity)
                                point    = new Point3d(runningX, runningY, 0);     //adds the top left fixing hole
                                pointsList.Add(point);
                                points++;
                            }
                        }
                    }


                    //Draw the top horizontal fixing holes dimension (between the fixing holes)
                    doc.Layers.SetCurrentLayerIndex(tempLayerIndex, true);
                    if (foldPanel.TopFixingHoles == "1")
                    {
                        runningY = max.Y - panel.TopHoleSetbackTop; //calculate the starting point for the first from the right (with setback)

                        if (Folded)
                        {
                            runningX = panelX0 + foldPanel.LeftFirstFoldSetbackTop + foldPanel.KFactor + panel.TopHoleSetbackLeft;
                        }
                        else
                        {
                            runningX = min.X + panel.TopHoleSetbackLeft; //calculate the starting point for the first hole from the left(with set back)
                        }

                        points = 0;
                        while (points <= (panel.TopFixingHoleQuantity) - 2)
                        {
                            origin = new Point3d(runningX + panel.TopFixingHoleDistance, runningY + 15, 0); //right
                            offset = new Point3d(runningX, runningY + 15, 0);                               //left
                            pt     = new Point3d((offset.X - origin.X) / 2, (runningY + 15) + (dimStyle.TextHeight * 4), 0);

                            plane        = Plane.WorldXY;
                            plane.Origin = origin;

                            guidList = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension

                            runningX = runningX + panel.TopFixingHoleDistance;                  //multiply by 2 to increase width (for equaliity)
                            points++;
                        }

                        //Draw the setback dimension of top fixing hole (left)
                        runningY = max.Y - panel.TopHoleSetbackTop; //calculate the starting point for the first from the right (with setback)

                        if (Folded)
                        {
                            runningX = panelX0 + foldPanel.LeftFirstFoldSetbackTop + foldPanel.KFactor + panel.TopHoleSetbackLeft;
                        }
                        else
                        {
                            runningX = min.X + panel.TopHoleSetbackLeft; //calculate the starting point for the first hole from the left(with set back)
                        }
                        origin = new Point3d(runningX, runningY + 15, 0);
                        offset = new Point3d(runningX - panel.TopHoleSetbackLeft, runningY + 15, 0);
                        pt     = new Point3d((offset.X - origin.X) / 2, (runningY + 15) + (dimStyle.TextHeight * 2), 0);

                        plane    = Plane.WorldXY;
                        guidList = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension

                        runningY = max.Y - panel.TopHoleSetbackTop;                         //calculate the starting point for the first from the right (with setback)

                        //Draw the setback dimension of top fixing hole (right)
                        if (Folded)
                        {
                            runningX = panelX1 - foldPanel.LeftFirstFoldSetbackTop - foldPanel.KFactor - panel.TopHoleSetbackLeft;
                        }
                        else
                        {
                            runningX = max.X - panel.TopHoleSetbackLeft; //calculate the starting point for the first hole from the left(with set back)
                        }
                        origin = new Point3d(runningX, runningY + 15, 0);
                        offset = new Point3d(runningX + panel.TopHoleSetbackLeft, runningY + 15, 0);
                        pt     = new Point3d((offset.X - origin.X) / 2, (runningY + 15) + (dimStyle.TextHeight * 2), 0);

                        plane    = Plane.WorldXY;
                        guidList = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension

                        //Draw the dimension between the top folded line and the center of the fixing hole
                        origin = new Point3d(min.X - 30, runningY, 0);                  //upper horizontal line of dimension
                        offset = new Point3d(min.X - 30, max.Y, 0);                     //bottom horizontal line of the dimension
                        pt     = new Point3d(min.X - 30, (offset.Y - origin.Y) / 2, 0); //addjust the text position

                        plane        = Plane.WorldXY;
                        plane.XAxis  = new Vector3d(0, -1, 0);
                        plane.YAxis  = new Vector3d(-1, 0, 0);
                        plane.ZAxis  = new Vector3d(0, 0, -1);
                        plane.Origin = origin;

                        guidList = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension
                    }

                    //Draw the bottom holes
                    doc.Layers.SetCurrentLayerIndex(layerIndex, true);
                    if (panel.BottomFixingHoles.Equals("1"))
                    {
                        runningY = min.Y + panel.BottomHoleSetbackBottom; //calculate the starting point for the first from the right (with setback)

                        if (Folded)
                        {
                            runningX = panelX0 + foldPanel.LeftFirstFoldSetbackBottom + foldPanel.KFactor + panel.BottomHoleSetbackLeft;
                        }
                        else
                        {
                            runningX = min.X + panel.BottomHoleSetbackLeft; //calculate the starting point for the first hole from the left(with set back)
                        }

                        if (Folded)
                        {
                            point = new Point3d(runningX, runningY, 0); //adds the bottom  Left fixing hole
                            pointsList.Add(point);


                            if (foldPanel != null)
                            {
                                point = new Point3d(panelX1 - panel.BottomHoleSetbackRight - foldPanel.BottomFirstFoldSetbackRight, runningY, 0); //adds the bottom right fixing hole
                            }
                            else
                            {
                                point = new Point3d(panelX1 - foldPanel.LeftFirstFoldSetbackBottom - foldPanel.KFactor - panel.BottomHoleSetbackRight, runningY, 0); //adds the bottom right fixing hole
                            }
                            pointsList.Add(point);
                            points = 1;
                            while (points <= panel.BottomFixingHoleQuantity - 2)
                            {
                                runningX = runningX + panel.BottomFixingHoleDistance;
                                point    = new Point3d(runningX, runningY, 0); //adds the bottom fixing hole
                                pointsList.Add(point);
                                points++;
                            }
                        }
                        else
                        {
                            point = new Point3d(runningX, runningY, 0); //adds the bottom  Left fixing hole
                            pointsList.Add(point);

                            point = new Point3d(max.X - panel.BottomHoleSetbackRight, runningY, 0); //adds the bottom right fixing hole
                            pointsList.Add(point);

                            points = 1;
                            while (points <= panel.BottomFixingHoleQuantity - 2)
                            {
                                runningX = runningX + panel.BottomFixingHoleDistance;
                                point    = new Point3d(runningX, runningY, 0); //adds the bottom fixing hole
                                pointsList.Add(point);
                                points++;
                            }
                        }
                    }

                    //Draw the Bottom horizontal fixing holes dimension (between the fixing holes)
                    doc.Layers.SetCurrentLayerIndex(tempLayerIndex, true);
                    if (panel.BottomFixingHoles == "1")
                    {
                        runningY = min.Y + panel.BottomHoleSetbackBottom; //calculate the starting point for the first from the right (with setback)

                        if (Folded)
                        {
                            runningX = panelX0 + foldPanel.LeftFirstFoldSetbackBottom + foldPanel.KFactor + panel.BottomHoleSetbackLeft;
                        }
                        else
                        {
                            runningX = min.X + panel.BottomHoleSetbackLeft; //calculate the starting point for the first hole from the left(with set back)
                        }
                        points = 0;
                        while (points <= (panel.BottomFixingHoleQuantity) - 2)
                        {
                            origin = new Point3d(runningX + panel.BottomFixingHoleDistance, runningY + panel.BottomHoleSetbackBottom, 0); //right
                            offset = new Point3d(runningX, runningY + panel.BottomHoleSetbackBottom, 0);                                  //left
                            pt     = new Point3d((offset.X - origin.X) / 2, (runningY + panel.BottomHoleSetbackBottom) - (dimStyle.TextHeight * 4), 0);

                            plane        = Plane.WorldXY;
                            plane.Origin = origin;

                            guidList = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension

                            runningX = runningX + panel.BottomFixingHoleDistance;               //multiply by 2 to increase width (for equaliity)
                            points++;
                        }
                    }
                    //Draw the Left holes
                    doc.Layers.SetCurrentLayerIndex(layerIndex, true);
                    if (panel.LeftFixingHoles.Equals("1"))
                    {
                        runningX = min.X + panel.LeftHoleSetbackLeft;
                        if (Folded) //if the panel is folded x value should be within the fold
                        {
                            runningY = panelY1 - foldPanel.LeftFirstFoldSetbackTop - foldPanel.KFactor - panel.LeftHoleSetbackTop;
                        }
                        else //if the panel is flat panel the x value should be between the folded panel finished and the borders
                        {
                            runningY = max.Y - panel.LeftHoleSetbackTop;
                        }

                        if (!panel.TopFixingHoles.Equals("1") || folds == 4) //check if there is top fixing holes
                        {
                            point = new Point3d(runningX, runningY, 0);      //adds the Left top fixing hole
                            pointsList.Add(point);
                        }

                        if (!panel.BottomFixingHoles.Equals("1") || folds == 4) //check if there is bottom fixing holes
                        {
                            if (foldPanel != null)
                            {
                                point = new Point3d(runningX, panelY0 + panel.LeftHoleSetbackBottom + foldPanel.LeftFirstFoldSetbackBottom, 0); //adds the  left bottom fixing hole
                            }
                            else
                            {
                                point = new Point3d(runningX, panelY0 + panel.LeftHoleSetbackBottom, 0); //adds the  left bottom fixing hole
                            }

                            pointsList.Add(point);
                        }
                        points = 1;
                        if (Folded)
                        {
                            while (points <= panel.LeftFixingHoleQuantity - 2)
                            {
                                runningY = runningY - panel.LeftFixingHoleDistance;
                                point    = new Point3d(runningX, runningY, 0); //draw the left fixing holes
                                pointsList.Add(point);
                                points++;
                            }
                        }
                        else
                        {
                            while (points <= panel.LeftFixingHoleQuantity - 2)
                            {
                                runningY = runningY - panel.LeftFixingHoleDistance;
                                point    = new Point3d(runningX, runningY, 0); //draw the left fixing holes
                                pointsList.Add(point);
                                points++;
                            }
                        }
                    }


                    //Draw the left vertical fixing holes dimension (between the left fixing holes)
                    doc.Layers.SetCurrentLayerIndex(tempLayerIndex, true);
                    if (panel.LeftFixingHoles == "1")
                    {
                        runningX = min.X + panel.LeftHoleSetbackLeft;
                        if (Folded) //if the panel is folded x value should be within the fold
                        {
                            runningY = panelY1 - foldPanel.LeftFirstFoldSetbackTop - foldPanel.KFactor - panel.LeftHoleSetbackTop;
                        }
                        else //if the panel is flat panel the x value should be between the folded panel finished and the borders
                        {
                            runningY = max.Y - panel.LeftHoleSetbackTop;
                        }
                        points = 0;
                        while (points < (panel.LeftFixingHoleQuantity) - 1)
                        {
                            if (Folded)
                            {
                                origin = new Point3d(min.X - foldPanel.LeftFirstFoldWidth, runningY - panel.LeftFixingHoleDistance, 0); //right
                                offset = new Point3d(min.X - foldPanel.LeftFirstFoldWidth, runningY, 0);                                //left
                                pt     = new Point3d(min.X - foldPanel.LeftFirstFoldWidth, runningY + (dimStyle.TextHeight * 4), 0);
                            }
                            else
                            {
                                origin = new Point3d(min.X + 20, runningY - panel.LeftFixingHoleDistance, 0); //right
                                offset = new Point3d(min.X + 20, runningY, 0);                                //left
                                pt     = new Point3d(min.X - 20, runningY + (dimStyle.TextHeight * 4), 0);
                            }

                            plane        = Plane.WorldXY;
                            plane.XAxis  = new Vector3d(0, -1, 0);
                            plane.YAxis  = new Vector3d(-1, 0, 0);
                            plane.ZAxis  = new Vector3d(0, 0, -1);
                            plane.Origin = origin;

                            guidList = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension
                            runningY = runningY - panel.LeftFixingHoleDistance;                 //multiply by 2 to increase width (for equaliity)

                            pointOne = runningY;

                            points++;
                        }
                    }


                    //Draw the Right holes
                    doc.Layers.SetCurrentLayerIndex(layerIndex, true);
                    if (panel.RightFixingHoles.Equals("1"))
                    {
                        runningX = max.X - panel.RightHoleSetbackRight;
                        if (Folded) //if the panel is folded x value should be within the fold
                        {
                            runningY = panelY1 - foldPanel.RightFirstFoldSetbackTop - foldPanel.KFactor - panel.RightHoleSetbackTop;
                        }
                        else //if the panel is flat panel the x value should be between the folded panel finished and the borders
                        {
                            runningY = max.Y - panel.RightHoleSetbackTop;
                        }

                        if (!panel.TopFixingHoles.Equals("1") || folds == 4)
                        {
                            point = new Point3d(runningX, runningY, 0); //adds the Right top fixing hole
                            pointsList.Add(point);
                        }
                        if (!panel.BottomFixingHoles.Equals("1") || folds == 4)
                        {
                            if (foldPanel != null)
                            {
                                point = new Point3d(runningX, panelY0 + panel.RightHoleSetbackBottom + foldPanel.RightFirstFoldSetbackBottom, 0); //adds the  RIght bottom fixing hole
                            }
                            else
                            {
                                point = new Point3d(runningX, panelY0 + panel.RightHoleSetbackBottom, 0); //adds the  RIght bottom fixing hole
                            }
                            pointsList.Add(point);
                        }
                        points = 1;
                        while (points <= panel.RightFixingHoleQuantity - 2)
                        {
                            runningY = runningY - panel.RightFixingHoleDistance;
                            point    = new Point3d(runningX, runningY, 0); //draw the right fixing holes
                            pointsList.Add(point);
                            points++;
                        }
                    }


                    //Draw the right vertical fixing holes dimension (between the right fixing holes)
                    doc.Layers.SetCurrentLayerIndex(tempLayerIndex, true);
                    if (panel.RightFixingHoles == "1")
                    {
                        runningX = max.X - panel.RightHoleSetbackRight;

                        if (Folded) //if the panel is folded x value should be within the fold
                        {
                            runningY = panelY1 - foldPanel.RightFirstFoldSetbackTop - foldPanel.KFactor - panel.RightHoleSetbackTop;
                        }
                        else //if the panel is flat panel the x value should be between the folded panel finished and the borders
                        {
                            runningY = max.Y - panel.RightHoleSetbackTop;
                        }
                        points = 0;
                        while (points < (panel.LeftFixingHoleQuantity) - 1)
                        {
                            //multiply by 2 to increase width (for equaliity)
                            origin = new Point3d(max.X + 50, runningY - panel.RightFixingHoleDistance, 0); //right
                            offset = new Point3d(max.X + 50, runningY, 0);                                 //left
                            pt     = new Point3d(max.X + 50, runningY + (dimStyle.TextHeight * 4), 0);

                            plane        = Plane.WorldXY;
                            plane.XAxis  = new Vector3d(0, -1, 0);
                            plane.YAxis  = new Vector3d(-1, 0, 0);
                            plane.ZAxis  = new Vector3d(0, 0, -1);
                            plane.Origin = origin;

                            guidList = drawDimension(plane, pt, offset, origin, guidList, doc); //draw the dimension
                            runningY = runningY - panel.RightFixingHoleDistance;

                            points++;
                        }
                    }
                    //Drawing fixings holes on the dimensions
                    doc.Layers.SetCurrentLayerIndex(layerIndex, true);
                    //Draw the top hole
                    if (panel.TopFixingHoles.Equals("1") && Folded)
                    {
                        runningX = panelX0 + foldPanel.LeftFirstFoldSetbackTop + foldPanel.KFactor + panel.TopHoleSetbackLeft;
                        runningY = (panelBottom + foldPanel.TopFirstFoldWidth) - panel.TopHoleSetbackTop; //calculate the starting point for the first from the right (with setback)

                        points = 1;
                        if (foldPanel != null)
                        {
                            if (foldPanel.TopFirstFoldDirection == 1)
                            {
                                runningY = (panelTop - foldPanel.TopFirstFoldWidth) + panel.TopHoleSetbackTop; //calculate the starting point for the first from the right (with setback)
                            }
                        }
                        else
                        {
                            point = new Point3d(panelX1 - foldPanel.LeftFirstFoldSetbackTop - foldPanel.KFactor - panel.TopHoleSetbackRight, (panelBottom + foldPanel.TopFirstFoldWidth) - panel.TopHoleSetbackTop, 0); //adds the top right fixing hole in the dimensions blue (use panel bottom)
                            pointsList.Add(point);
                        }
                        point = new Point3d(panelX1 - panel.TopHoleSetbackRight - foldPanel.TopFirstFoldSetbackRight, runningY, 0); //adds the top right fixing hole in the dimensions blue (use panel bottom)
                        pointsList.Add(point);
                        point = new Point3d(runningX, runningY, 0);                                                                 //adds the top left fixing hole
                        pointsList.Add(point);

                        while (points <= (panel.TopFixingHoleQuantity - 2))
                        {
                            runningX = runningX + panel.TopFixingHoleDistance; //multiply by 2 to increase width (for equaliity)
                            point    = new Point3d(runningX, runningY, 0);     //adds the top left fixing hole
                            pointsList.Add(point);
                            points++;
                        }
                    }

                    //Draw the Left holes
                    if (panel.LeftFixingHoles.Equals("1") && Folded && folds == 4) //draw the fixing holes on the left dimension only on folded panels because flat panels do not have the left dimension
                    {
                        runningY = panelY1 - foldPanel.LeftFirstFoldSetbackTop - foldPanel.KFactor - panel.LeftHoleSetbackTop;
                        runningX = panelRight - foldPanel.LeftFirstFoldWidth + panel.LeftHoleSetbackLeft;



                        if (foldPanel != null)
                        {
                            if (foldPanel.TopFirstFoldDirection == 1)
                            {
                                runningX = (panelLeft + foldPanel.LeftFirstFoldWidth) - panel.LeftHoleSetbackLeft;
                            }
                        }
                        else
                        {
                            point = new Point3d(runningX, panelY0 + panel.LeftHoleSetbackBottom, 0); //adds the  left bottom fixing hole
                            pointsList.Add(point);
                        }
                        point = new Point3d(runningX, runningY, 0);                                                                     //adds the Left top fixing hole
                        pointsList.Add(point);
                        point = new Point3d(runningX, panelY0 + panel.LeftHoleSetbackBottom + foldPanel.LeftFirstFoldSetbackBottom, 0); //adds the  left bottom fixing hole
                        pointsList.Add(point);

                        points = 1;
                        while (points <= panel.LeftFixingHoleQuantity - 2)
                        {
                            runningY = runningY - panel.LeftFixingHoleDistance;
                            point    = new Point3d(runningX, runningY, 0); //draw the left fixing holes
                            pointsList.Add(point);
                            points++;
                        }
                    }

                    // Process the curve


                    // Draw all the holes
                    Round round = new Round();
                    round.X = holeSize;


                    foreach (Point3d p in pointsList)
                    {
                        round.drawTool(p);
                    }
                }
            }
            return(guidList);
        }
コード例 #6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetObject go = new GetObject();

            go.SetCommandPrompt("Select curve to split");
            go.GeometryFilter          = ObjectType.Curve;
            go.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
            go.SubObjectSelect         = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            ObjRef      object_ref = go.Object(0);
            RhinoObject rh_object  = object_ref.Object();
            Curve       curve      = object_ref.Curve();

            if (null == rh_object || null == curve)
            {
                return(Result.Failure);
            }

            GetPoint gp = new GetPoint();

            gp.SetCommandPrompt("Point on curve to split at");
            gp.Constrain(curve, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Point3d point = gp.Point();
            double  t     = Rhino.RhinoMath.UnsetValue;

            if (!curve.ClosestPoint(point, out t))
            {
                return(Result.Failure);
            }

            List <double> curve_t = new List <double>(3);

            curve_t.Add(curve.Domain.Min);
            curve_t.Add(curve.Domain.Max);
            curve_t.Add(t);
            curve_t.Sort();

            List <double> culled_t = curve_t.Distinct().ToList();

            if (culled_t.Count < 3)
            {
                return(Result.Nothing);
            }

            ObjectAttributes attributes = rh_object.Attributes.Duplicate();

            attributes.ObjectId = Guid.Empty;

            for (int i = 0; i < culled_t.Count - 1; i++)
            {
                Interval domain = new Interval(culled_t[i], culled_t[i + 1]);
                if (curve.Domain.IncludesInterval(domain))
                {
                    Curve trim = curve.Trim(domain);
                    if (null != trim)
                    {
                        doc.Objects.Add(trim, attributes);
                    }
                }
            }

            doc.Objects.Delete(object_ref, false);
            doc.Views.Redraw();

            return(Result.Success);
        }
コード例 #7
0
        /// <summary>
        /// read meta data from one doc object
        /// </summary>
        /// <param name="oref">object reference</param>
        /// <param name="propkeys">query keys</param>
        /// <returns>array of properties</returns>
        private string[] GetProp(ObjRef oref, string[] propkeys)
        {
            string[]    line = new string[propkeys.Length];
            RhinoObject obj  = oref.Object();

            for (int i = 0; i < propkeys.Length; i++)
            {
                string k = propkeys[i];
                if (popup.cun != "" && popup.cun != null)
                {
                    docunit = popup.cun;
                }
                else
                {
                    docunit = parent.GetUnitSystemName(true, false, true, true);
                }
                switch (k)
                {
                case "GUID":
                    line.SetValue(oref.ObjectId.ToString(), i);
                    break;

                case "Type":
                    line.SetValue(obj.ObjectType.ToString(), i);
                    break;

                case "Name":
                    line.SetValue(obj.Name, i);
                    break;

                case "Layer":
                    var li    = obj.Attributes.LayerIndex;
                    var layer = parent.Layers.FindIndex(li);
                    line.SetValue(layer.Name, i);
                    break;

                case "Color":
                    var c = obj.Attributes.DrawColor(parent);
                    if (popup.cf == 0)
                    {
                        line.SetValue(c.ToString(), i);
                    }
                    else if (popup.cf == 1)
                    {
                        line.SetValue(string.Format("{0}-{1}-{2}", c.R, c.G, c.B), i);
                    }
                    else
                    {
                        line.SetValue(string.Format("{0} {1} {2}", c.R, c.G, c.B), i);
                    }
                    break;

                case "LineType":
                    var lti = parent.Linetypes.LinetypeIndexForObject(obj);
                    var lt  = parent.Linetypes[lti].Name;
                    line.SetValue(lt, i);
                    break;

                case "PrintColor":
                    Color pc;
                    var   pcs = obj.Attributes.PlotColorSource;
                    if (pcs == ObjectPlotColorSource.PlotColorFromLayer)
                    {
                        li    = obj.Attributes.LayerIndex;
                        layer = parent.Layers.FindIndex(li);
                        pc    = layer.PlotColor;
                    }
                    else
                    {
                        pc = obj.Attributes.PlotColor;
                    }
                    if (popup.cf == 0)
                    {
                        line.SetValue(pc.ToString(), i);
                    }
                    else if (popup.cf == 1)
                    {
                        line.SetValue(string.Format("{0}-{1}-{2}", pc.R, pc.G, pc.B), i);
                    }
                    else
                    {
                        line.SetValue(string.Format("{0} {1} {2}", pc.R, pc.G, pc.B), i);
                    }
                    break;

                case "PrintWidth":
                    double pw;
                    var    pws = obj.Attributes.PlotWeightSource;
                    if (pws == ObjectPlotWeightSource.PlotWeightFromLayer)
                    {
                        li    = obj.Attributes.LayerIndex;
                        layer = parent.Layers.FindIndex(li);
                        pw    = layer.PlotWeight;
                    }
                    else
                    {
                        pw = obj.Attributes.PlotWeight;
                    }
                    if (options[0])
                    {
                        line.SetValue(pw.ToString() + "pt", i);                 // with unit
                    }
                    else
                    {
                        line.SetValue(pw.ToString(), i);
                    }
                    break;

                case "Material":
                    var mti = obj.Attributes.MaterialIndex;
                    var mt  = parent.Materials.FindIndex(mti);
                    if (mt == null)
                    {
                        line.SetValue(null, i);
                    }
                    else
                    {
                        line.SetValue(mt.Name, i);
                    }
                    break;

                case "Length":
                    string len = null;
                    if (obj.ObjectType == ObjectType.Curve)
                    {
                        var len_num = Math.Round(oref.Curve().GetLength(), popup.dp); //decimal
                        len_num *= popup.su;                                          //custom scale
                        if (popup.ts == ",")
                        {
                            len = len_num.ToString("#,##0.00");
                        }
                        else if (popup.ts == ".")
                        {
                            len = len_num.ToString("#.##0.00");
                        }
                        else if (popup.ts == " ")
                        {
                            len = len_num.ToString("# ##0.00");
                        }
                        else
                        {
                            len = len_num.ToString();
                        }
                    }
                    if (options[0] && len != null)
                    {
                        len += docunit;                              // with unit
                    }
                    line.SetValue(len, i);
                    break;

                case "Area":
                    AreaMassProperties amp = null;
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        amp = AreaMassProperties.Compute(oref.Brep());
                    }
                    else if (obj.ObjectType == ObjectType.Curve)
                    {
                        if (oref.Curve().IsClosed)
                        {
                            amp = AreaMassProperties.Compute(oref.Curve());
                        }
                        else
                        {
                            amp = null;
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            amp = AreaMassProperties.Compute(Brep.TryConvertBrep(obj.Geometry));
                        }
                        else
                        {
                            amp = null;
                        }
                    }

                    if (amp != null)
                    {
                        double area_num = Math.Round(amp.Area, popup.dp);
                        area_num *= popup.su;
                        string area;
                        if (popup.ts == ",")
                        {
                            area = area_num.ToString("#,##0.00");
                        }
                        else if (popup.ts == ".")
                        {
                            area = area_num.ToString("#.##0.00");
                        }
                        else if (popup.ts == " ")
                        {
                            area = area_num.ToString("# ##0.00");
                        }
                        else
                        {
                            area = area_num.ToString();
                        }

                        if (options[0])
                        {
                            if (popup.cun != "" && popup.cun != null)
                            {
                                line.SetValue(area + popup.cun + "sq", i);
                            }
                            else
                            {
                                line.SetValue(area + docunit + "sq", i);
                            }
                        }
                        else
                        {
                            line.SetValue(area, i);
                        }
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "Volume":
                    string vol = null;
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        if (oref.Brep().IsSolid)
                        {
                            double vol_num = oref.Brep().GetVolume(rtol, tol);
                            vol_num  = Math.Round(vol_num, popup.dp);
                            vol_num *= popup.su;
                            if (popup.ts == ",")
                            {
                                vol = vol_num.ToString("#,##0.00");
                            }
                            else if (popup.ts == ".")
                            {
                                vol = vol_num.ToString("#.##0.00");
                            }
                            else if (popup.ts == " ")
                            {
                                vol = vol_num.ToString("# ##0.00");
                            }
                            else
                            {
                                vol = vol_num.ToString();
                            }
                        }
                        else
                        {
                            vol = "open brep";
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        Brep b = Brep.TryConvertBrep(obj.Geometry);
                        if (b == null)
                        {
                            vol = "invalid extrusion";
                        }
                        else
                        {
                            if (b.IsSolid)
                            {
                                double vol_num = b.GetVolume(rtol, tol);
                                vol_num  = Math.Round(vol_num, popup.dp);
                                vol_num *= popup.su;
                                if (popup.ts == ",")
                                {
                                    vol = vol_num.ToString("#,##0.00");
                                }
                                else if (popup.ts == ".")
                                {
                                    vol = vol_num.ToString("#.##0.00");
                                }
                                else if (popup.ts == " ")
                                {
                                    vol = vol_num.ToString("# ##0.00");
                                }
                                else
                                {
                                    vol = vol_num.ToString();
                                }
                            }
                            else
                            {
                                vol = "open brep";
                            }
                        }
                    }

                    if (!options[0] || vol == null)
                    {
                        line.SetValue(vol, i);
                    }
                    else if (vol != "open brep" && vol != "invalid extrusion")
                    {
                        if (popup.cun != "" && popup.cun != null)
                        {
                            line.SetValue(vol + popup.cun + "cu", i);
                        }
                        else
                        {
                            line.SetValue(vol + docunit + "cu", i);
                        }
                    }
                    break;

                case "NumPts":
                    if (obj.ObjectType == ObjectType.Curve)
                    {
                        line.SetValue(oref.Curve().ToNurbsCurve().Points.Count.ToString(), i);
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "NumEdges":
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        line.SetValue(oref.Brep().Edges.Count.ToString(), i);
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            line.SetValue(Brep.TryConvertBrep(obj.Geometry).Edges.Count.ToString(), i);
                        }
                        else
                        {
                            line.SetValue("invalid extrusion", i);
                        }
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "NumFaces":
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        line.SetValue(oref.Brep().Faces.Count.ToString(), i);
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            line.SetValue(Brep.TryConvertBrep(obj.Geometry).Faces.Count.ToString(), i);
                        }
                        else
                        {
                            line.SetValue("invalid extrusion", i);
                        }
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "Degree":
                    if (obj.ObjectType == ObjectType.Curve)
                    {
                        line.SetValue(oref.Curve().Degree.ToString(), i);
                    }
                    else
                    {
                        line.SetValue(null, i);
                    }
                    break;

                case "CenterX":
                    var num = obj.Geometry.GetBoundingBox(false).Center.X;
                    num  = Math.Round(num, popup.dp);
                    num *= popup.su;
                    line.SetValue(num.ToString(), i);
                    break;

                case "CenterY":
                    num  = obj.Geometry.GetBoundingBox(false).Center.Y;
                    num  = Math.Round(num, popup.dp);
                    num *= popup.su;
                    line.SetValue(num.ToString(), i);
                    break;

                case "CenterZ":
                    num  = obj.Geometry.GetBoundingBox(false).Center.Z;
                    num  = Math.Round(num, popup.dp);
                    num *= popup.su;
                    line.SetValue(num.ToString(), i);
                    break;

                case "IsPlanar":
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        Brep brep = oref.Brep();
                        if (brep.IsSurface)
                        {
                            if (brep.Faces[0].IsPlanar())
                            {
                                line.SetValue("yes", i);
                            }
                            else
                            {
                                line.SetValue("no", i);
                            }
                        }
                        else
                        {
                            line.SetValue("polysrf", i);
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Curve)
                    {
                        if (oref.Curve().IsPlanar())
                        {
                            line.SetValue("yes", i);
                        }
                        else
                        {
                            line.SetValue("no", i);
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            Brep brep = Brep.TryConvertBrep(obj.Geometry);
                            if (brep.IsSurface)
                            {
                                if (brep.Faces[0].IsPlanar())
                                {
                                    line.SetValue("yes", i);
                                }
                                else
                                {
                                    line.SetValue("no", i);
                                }
                            }
                            else
                            {
                                line.SetValue("polysrf", i);
                            }
                        }
                        else
                        {
                            line.SetValue("invalid extrusion", i);
                        }
                    }
                    else
                    {
                        line.SetValue("irrelevant", i);
                    }
                    break;

                case "IsClosed":
                    if (obj.ObjectType == ObjectType.Brep)
                    {
                        Brep brep = oref.Brep();
                        if (brep.IsSolid)
                        {
                            line.SetValue("yes", i);
                        }
                        else
                        {
                            line.SetValue("no", i);
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Curve)
                    {
                        if (oref.Curve().IsClosed)
                        {
                            line.SetValue("yes", i);
                        }
                        else
                        {
                            line.SetValue("no", i);
                        }
                    }
                    else if (obj.ObjectType == ObjectType.Extrusion)
                    {
                        if (obj.Geometry.HasBrepForm)
                        {
                            Brep brep = Brep.TryConvertBrep(obj.Geometry);
                            if (brep.IsSolid)
                            {
                                line.SetValue("yes", i);
                            }
                            else
                            {
                                line.SetValue("no", i);
                            }
                        }
                        else
                        {
                            line.SetValue("invalid extrusion", i);
                        }
                    }
                    else
                    {
                        line.SetValue("irrelevant", i);
                    }
                    break;

                case "Comments":
                    var    usertxts = obj.Attributes.GetUserStrings();
                    string txt      = null;
                    if (usertxts.Count == 1)
                    {
                        txt = usertxts[0];
                    }
                    else
                    {
                        txt = string.Join(";", usertxts.AllKeys);
                    }
                    line.SetValue("keys_" + txt, i);
                    break;

                default:
                    break;
                }
            }
            return(line);
        }
コード例 #8
0
ファイル: StripFooting.cs プロジェクト: strdesigner/OSforGH
        /// <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)
        {
            int Digit(int num)//数字の桁数を求める関数
            {
                // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。
                return((num == 0) ? 1 : ((int)Math.Log10(num) + 1));
            }

            XColor RGB(double h, double s, double l)//convert HSL to RGB
            {
                var max = 0.0; var min = 0.0; var R = 0.0; var g = 0.0; var b = 0.0;

                if (l < 0.5)
                {
                    max = l + l * s;
                    min = l - l * s;
                }
                else
                {
                    max = l + (1 - l) * s;
                    min = l - (1 - l) * s;
                }
                var HUE_MAX = 360.0; var RGB_MAX = 255;
                var hp = HUE_MAX / 6.0; h *= HUE_MAX; var q = h / hp;

                if (q <= 1)
                {
                    R = max;
                    g = (h / hp) * (max - min) + min;
                    b = min;
                }
                else if (q <= 2)
                {
                    R = ((hp * 2 - h) / hp) * (max - min) + min;
                    g = max;
                    b = min;
                }
                else if (q <= 3)
                {
                    R = min;
                    g = max;
                    b = ((h - hp * 2) / hp) * (max - min) + min;
                }
                else if (q <= 4)
                {
                    R = min;
                    g = ((hp * 4 - h) / hp) * (max - min) + min;
                    b = max;
                }
                else if (q <= 5)
                {
                    R = ((h - hp * 4) / hp) * (max - min) + min;
                    g = min;
                    b = max;
                }
                else
                {
                    R = max;
                    g = min;
                    b = ((HUE_MAX - h) / hp) * (max - min) + min;
                }
                R *= RGB_MAX; g *= RGB_MAX; b *= RGB_MAX;
                return(XColor.FromArgb((int)R, (int)g, (int)b));
            }

            Vector3d rotation(Vector3d a, Vector3d b, double theta)
            {
                double rad = theta * Math.PI / 180;
                double s = Math.Sin(rad); double c = Math.Cos(rad);

                b /= Math.Sqrt(Vector3d.Multiply(b, b));
                double   b1 = b[0]; double b2 = b[1]; double b3 = b[2];
                Vector3d m1 = new Vector3d(c + Math.Pow(b1, 2) * (1 - c), b1 * b2 * (1 - c) - b3 * s, b1 * b3 * (1 - c) + b2 * s);
                Vector3d m2 = new Vector3d(b2 * b1 * (1 - c) + b3 * s, c + Math.Pow(b2, 2) * (1 - c), b2 * b3 * (1 - c) - b1 * s);
                Vector3d m3 = new Vector3d(b3 * b1 * (1 - c) - b2 * s, b3 * b2 * (1 - c) + b1 * s, c + Math.Pow(b3, 2) * (1 - c));

                return(new Vector3d(Vector3d.Multiply(m1, a), Vector3d.Multiply(m2, a), Vector3d.Multiply(m3, a)));
            }

            var doc = RhinoDoc.ActiveDoc;

            DA.GetDataTree("R", out GH_Structure <GH_Number> _r); var           r = _r.Branches;
            DA.GetDataTree("reac_f", out GH_Structure <GH_Number> _reac_f); var reac_f = _reac_f.Branches; var m = reac_f.Count;
            List <string> layer = new List <string>(); var nameB = "布基礎"; var namet = "t"; var namerho = "ρ"; var nameD = "D"; var namepitch = "@"; var nameft = "ft"; var namew = "w"; var nameac = "as";

            DA.GetDataList("layer", layer); DA.GetData("name B", ref nameB); DA.GetData("name t", ref namet); DA.GetData("name rho", ref namerho); DA.GetData("name bar", ref nameD); DA.GetData("name pitch", ref namepitch); DA.GetData("name ft", ref nameft); DA.GetData("name w", ref namew); DA.GetData("name as", ref nameac);
            DA.GetData("FS", ref fontsize);
            var pdfname = "StripBase"; DA.GetData("outputname", ref pdfname);

            var pressure = new List <double>(); var baseshape = new List <Curve>(); var baseline = new List <List <Point3d> >();
            var B = new List <double>(); var T = new List <double>(); var L = new List <double>(); var Rz = new List <double>(); var Sz = new List <double>(); var A = new List <double>();
            var bar = new List <string>(); var M = new List <double>(); var Ma = new List <double>(); var LL = new List <double>(); var Ft = new List <double>(); var J = new List <double>(); var At = new List <double>(); var Ac = new List <double>();

            for (int i = 0; i < layer.Count; i++)
            {
                var line = doc.Objects.FindByLayer(layer[i]);
                for (int j = 0; j < line.Length; j++)
                {
                    var le = line[j];
                    var re = new ObjRef(le);
                    var l = re.Curve(); baseshape.Add(l);
                    var r1 = l.PointAtStart; var r2 = l.PointAtEnd; var l2 = r2 - r1;
                    baseline.Add(new List <Point3d> {
                        r1, r2
                    });
                    var N = 0.0;
                    for (int k = 0; k < m; k++)
                    {
                        int e  = (int)reac_f[k][0].Value;
                        var pt = new Point3d(r[e][0].Value, r[e][1].Value, r[e][2].Value);
                        var l1 = pt - r1;
                        if (l2.Length - l1.Length >= -1e-8 && (l1 / l1.Length - l2 / l2.Length).Length < 1e-8)
                        {
                            N += reac_f[k][3].Value;
                        }
                    }
                    var b   = float.Parse(le.Attributes.GetUserString(nameB));
                    var t   = float.Parse(le.Attributes.GetUserString(namet));
                    var rho = float.Parse(le.Attributes.GetUserString(namerho));
                    L.Add(l2.Length); A.Add(b * L[j]);
                    B.Add(b); T.Add(t); Rz.Add(N); Sz.Add(t * A[j] * rho);
                    var prs = (N + Sz[j]) / A[j];
                    pressure.Add(prs);
                    if (BaseWidth == 1)
                    {
                        _pt.Add(new Point3d((r1[0] + r2[0]) / 2.0, (r1[1] + r2[1]) / 2.0, (r1[2] + r2[2]) / 2.0));
                        _text.Add(b.ToString("F6").Substring(0, digit) + unit_of_length);
                        _c2.Add(Color.Blue);
                    }
                    if (BaseNo == 1)
                    {
                        _pt.Add(new Point3d((r1[0] + r2[0]) / 2.0, (r1[1] + r2[1]) / 2.0, (r1[2] + r2[2]) / 2.0));
                        _text.Add(j.ToString());
                        _c2.Add(Color.Black);
                    }
                    if (BaseThick == 1)
                    {
                        _pt.Add(new Point3d((r1[0] + r2[0]) / 2.0, (r1[1] + r2[1]) / 2.0, (r1[2] + r2[2]) / 2.0));
                        _text.Add(t.ToString("F6").Substring(0, digit) + unit_of_length);
                        _c2.Add(Color.Purple);
                    }
                    if (Pressure == 1)
                    {
                        _pt.Add(new Point3d((r1[0] + r2[0]) / 2.0, (r1[1] + r2[1]) / 2.0, (r1[2] + r2[2]) / 2.0));
                        _text.Add(prs.ToString("F6").Substring(0, digit) + unit_of_force + "/" + unit_of_length + "2");
                        _c2.Add(Color.Red);
                    }
                    if (BaseShape == 1)
                    {
                        Random rand1 = new Random((i + 1) * (j + 1) * 1000); Random rand2 = new Random((i + 1) * (j + 1) * 2000); Random rand3 = new Random((i + 1) * (j + 1) * 3000);
                        _c.Add(Color.FromArgb(rand1.Next(0, 256), rand2.Next(0, 256), rand3.Next(0, 256)));
                        var l1 = rotation(l2, new Vector3d(0, 0, 1), 90); l1 = l1 / l1.Length;
                        var p1 = r1 + l1 * b / 2.0; var p2 = r2 + l1 * b / 2.0; var p3 = r2 - l1 * b / 2.0; var p4 = r1 - l1 * b / 2.0;
                        var brep = Brep.CreatePlanarBreps(new Polyline(new List <Point3d> {
                            p1, p2, p3, p4, p1
                        }).ToNurbsCurve(), 0.001)[0];
                        _s.Add(brep);
                    }
                    var text = le.Attributes.GetUserString(nameD);
                    var D    = 10.0;//[mm]
                    if (text != null)
                    {
                        D = float.Parse(text);
                    }
                    text = le.Attributes.GetUserString(namepitch);
                    var pitch = 200.0;//[mm]
                    if (text != null)
                    {
                        pitch = float.Parse(text);
                    }
                    var ft = 195.0;//[mm2]
                    text = le.Attributes.GetUserString(nameft);
                    if (text != null)
                    {
                        ft = float.Parse(text);
                    }
                    text = le.Attributes.GetUserString(namew);
                    var w = 0.2;//[mm]
                    if (text != null)
                    {
                        w = float.Parse(text);
                    }
                    text = le.Attributes.GetUserString(nameac);
                    var ac = 30.0;//[kN/m2]
                    if (text != null)
                    {
                        ac = float.Parse(text);
                    }
                    Ac.Add(ac);
                    var at = Math.PI * Math.Pow(D, 2) / 4.0 * 1000.0 / pitch; //[mm2]
                    var dj = (t * 1000 - 60) * 7 / 8;                         //[mm]
                    J.Add(dj); At.Add(at);
                    var span = b / 2.0 - w; LL.Add(span);
                    M.Add(prs * Math.Pow(span, 2) / 2.0); //[kNm]
                    Ma.Add(at * ft * dj / 1e+6);          //[kNm]
                    bar.Add("D" + ((int)D).ToString() + "@" + ((int)pitch).ToString()); Ft.Add(ft);
                }
            }
            DA.SetDataList("base", baseshape);
            DA.SetDataList("N/A", pressure);
            DA.GetDataTree("element_node_relationship", out GH_Structure <GH_Number> _ij);
            var ij = _ij.Branches; GH_Structure <GH_Number> e_load = new GH_Structure <GH_Number>(); int kk = 0;

            if (_ij.Branches[0][0].Value != -9999)
            {
                for (int k = 0; k < pressure.Count; k++)
                {
                    var ri = baseline[k][0]; var rj = baseline[k][1];//布基礎の両端の座標
                    var xi = ri[0]; var yi = ri[1]; var zi = ri[2]; var xj = rj[0]; var yj = rj[1]; var zj = rj[2];
                    var xmin = Math.Min(xi, xj) - 0.1; var xmax = Math.Max(xi, xj) + 0.1; var ymin = Math.Min(yi, yj) - 0.1; var ymax = Math.Max(yi, yj) + 0.1; var zmin = Math.Min(zi, zj) - 0.1; var zmax = Math.Max(zi, zj) + 0.1;
                    var v1 = rj - ri;
                    for (int e = 0; e < ij.Count; e++)
                    {
                        int ni = (int)ij[e][0].Value; int nj = (int)ij[e][1].Value;
                        var x1 = r[ni][0].Value; var y1 = r[ni][1].Value; var z1 = r[ni][2].Value; var x2 = r[nj][0].Value; var y2 = r[nj][1].Value; var z2 = r[nj][2].Value;
                        var r1 = new Point3d(x1, y1, z1); var r2 = new Point3d(x2, y2, z2);
                        var v2 = r2 - r1;
                        if (Math.Abs(Math.Abs(Vector3d.VectorAngle(v1, v2))) < 1e-2 || Math.Abs(Math.Abs(Vector3d.VectorAngle(v1, v2))) + 1e-2 > Math.PI)
                        {
                            if (xmin < x1 && x1 < xmax && xmin < x2 && x2 < xmax && ymin < y1 && y1 < ymax && ymin < y2 && y2 < ymax && zmin < z1 && z1 < zmax && zmin < z2 && z2 < zmax)
                            {
                                List <GH_Number> flist = new List <GH_Number>();
                                flist.Add(new GH_Number(e)); flist.Add(new GH_Number(0)); flist.Add(new GH_Number(0)); flist.Add(new GH_Number(pressure[k]));
                                e_load.AppendRange(flist, new GH_Path(kk));
                                kk += 1;
                            }
                        }
                    }
                }
                DA.SetDataTree(2, e_load);
            }
            //pdf作成
            if (on_off == 1)
            {
                // フォントリゾルバーのグローバル登録
                if (PdfCreate.JapaneseFontResolver.fontset == 0)
                {
                    PdfSharp.Fonts.GlobalFontSettings.FontResolver = fontresolver; PdfCreate.JapaneseFontResolver.fontset = 1;
                }
                // PDFドキュメントを作成。
                PdfDocument document = new PdfDocument();
                document.Info.Title  = pdfname;
                document.Info.Author = "Shinnosuke Fujita, Assoc. Prof., The Univ. of Kitakyushu";
                // フォントを作成。
                XFont font     = new XFont("Gen Shin Gothic", 9, XFontStyle.Regular);
                XFont fontbold = new XFont("Gen Shin Gothic", 9, XFontStyle.Bold);
                var   pen      = XPens.Black;
                var   labels   = new List <string>
                {
                    "基礎番号", "幅B[m]", "厚みt[m]", "長さL[m]", "底面積A[m2]", "反力合計[kN]", "基礎自重[kN]", "接地圧N/A[kN/m2]", "許容地耐力[kN/m2]", "地耐力検定比", "基礎出幅[m]", "M[kNm]", "配筋", "断面積at[mm2]", "ft[N/mm2]", "応力中心間距離j[mm]", "Ma[kNm]", "曲げ検定比M/Ma"
                };
                var label_width = 105; var offset_x = 25; var offset_y = 25; var pitchy = 13; var text_width = 20; PdfPage page = new PdfPage(); page.Size = PageSize.A4;
                for (int e = 0; e < pressure.Count; e++)
                {
                    var e_text = e.ToString();
                    var B_text = B[e].ToString("F").Substring(0, Digit((int)(B[e])) + 3);
                    var t_text = T[e].ToString("F").Substring(0, Digit((int)(T[e])) + 3);
                    var L_text = L[e].ToString("F").Substring(0, Digit((int)(L[e])) + 3);
                    var A_text = A[e].ToString("F").Substring(0, Digit((int)(A[e])) + 3);
                    var Rz_text = Rz[e].ToString("F").Substring(0, Digit((int)(Rz[e])) + 3);
                    var Sz_text = Sz[e].ToString("F").Substring(0, Digit((int)(Sz[e])) + 3);
                    var P_text = pressure[e].ToString("F").Substring(0, Digit((int)(pressure[e])) + 3);
                    var ac_text = Ac[e].ToString("F").Substring(0, Digit((int)(Ac[e])) + 3);
                    var l_text = LL[e].ToString("F").Substring(0, Digit((int)(LL[e])) + 3);
                    var M_text = M[e].ToString("F").Substring(0, Digit((int)(M[e])) + 3);
                    var Ma_text = Ma[e].ToString("F").Substring(0, Digit((int)(Ma[e])) + 3);
                    var at_text = At[e].ToString("F").Substring(0, Digit((int)(At[e])) + 3);
                    var ft_text = Ft[e].ToString("F").Substring(0, Digit((int)(Ft[e])) + 3);
                    var j_text = J[e].ToString("F").Substring(0, Digit((int)(J[e])) + 3);
                    var bar_text = bar[e];
                    var kentei2 = pressure[e] / Ac[e];
                    var k2_text = kentei2.ToString("F").Substring(0, 4); var k2_color = new XSolidBrush(RGB((1 - Math.Min(kentei2, 1.0)) * 1.9 / 3.0, 1, 0.5));
                    var kentei = M[e] / Ma[e];
                    var k_text = kentei.ToString("F").Substring(0, 4); var k_color = new XSolidBrush(RGB((1 - Math.Min(kentei, 1.0)) * 1.9 / 3.0, 1, 0.5));
                    var values = new List <string>();
                    values.Add(e_text); values.Add(B_text); values.Add(t_text); values.Add(L_text); values.Add(A_text); values.Add(Rz_text); values.Add(Sz_text); values.Add(P_text); values.Add(ac_text); values.Add(k2_text); values.Add(l_text); values.Add(M_text); values.Add(bar_text); values.Add(at_text); values.Add(ft_text); values.Add(j_text); values.Add(Ma_text);
                    values.Add(k_text);

                    var slide = 0.0;
                    if (6 <= e % 18 && e % 18 < 12)
                    {
                        slide = pitchy * 20;
                    }
                    if (12 <= e % 18 && e % 18 < 18)
                    {
                        slide = pitchy * 40;
                    }

                    if (e % 6 == 0)
                    {
                        // 空白ページを作成。
                        if (e % 18 == 0)
                        {
                            page = document.AddPage(); gfx = XGraphics.FromPdfPage(page);
                        }
                        // 描画するためにXGraphicsオブジェクトを取得。
                        for (int i = 0; i < labels.Count; i++)                                                                                                     //ラベル列**************************************************************************
                        {
                            gfx.DrawLine(pen, offset_x, offset_y + pitchy * i + slide, offset_x + label_width, offset_y + pitchy * i + slide);                     //横線
                            gfx.DrawLine(pen, offset_x + label_width, offset_y + pitchy * i + slide, offset_x + label_width, offset_y + pitchy * (i + 1) + slide); //縦線
                            gfx.DrawString(labels[i], font, XBrushes.Black, new XRect(offset_x, offset_y + pitchy * i + slide, label_width, offset_y + pitchy * (i + 1) + slide), XStringFormats.TopCenter);
                            if (i == labels.Count - 1)
                            {
                                i += 1;
                                gfx.DrawLine(pen, offset_x, offset_y + pitchy * i + slide, offset_x + label_width, offset_y + pitchy * i + slide);//横線
                            }
                        }//***********************************************************************************************************************
                    }
                    for (int i = 0; i < values.Count; i++)
                    {
                        var j = e % 6;
                        gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, offset_x + label_width + text_width * 3 * (j + 1), offset_y + pitchy * i + slide); //横線
                        gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * (i + 1) + slide); //縦線
                        if (i == values.Count - 1)
                        {
                            gfx.DrawString(values[i], font, k_color, new XRect(offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, text_width * 3, offset_y + pitchy * (i + 1) + slide), XStringFormats.TopCenter);
                            i += 1;
                            gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, offset_x + label_width + text_width * 3 * (j + 1), offset_y + pitchy * i + slide);//横線
                        }
                        else
                        {
                            var color = XBrushes.Black;
                            if (i == 9)
                            {
                                color = k2_color;
                            }
                            gfx.DrawString(values[i], font, color, new XRect(offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i + slide, text_width * 3, offset_y + pitchy * (i + 1) + slide), XStringFormats.TopCenter);
                        }
                    }
                }
                var dir = Path.GetDirectoryName(Rhino.RhinoDoc.ActiveDoc.Path);
                // ドキュメントを保存。
                var filename = dir + "/" + pdfname + ".pdf";
                document.Save(filename);
                // ビューアを起動。
                Process.Start(filename);
            }
        }
コード例 #9
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const ObjectType geometryFilter = ObjectType.Curve;

            GetObject get_rail = new GetObject();

            get_rail.SetCommandPrompt("Select rail curve");
            get_rail.GeometryFilter = geometryFilter;
            //get_rail.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
            get_rail.SubObjectSelect = false;
            get_rail.Get();
            if (get_rail.CommandResult() != Result.Success)
            {
                return(get_rail.CommandResult());
            }

            ObjRef rail_objref = get_rail.Object(0);
            Curve  rail_curve  = rail_objref.Curve();

            if (null == rail_curve)
            {
                return(Result.Failure);
            }

            GetObject get_shape = new GetObject();

            get_shape.SetCommandPrompt("Select cross section curve");
            get_shape.GeometryFilter = geometryFilter;
            //get_shape.GeometryAttributeFilter = GeometryAttributeFilter.OpenCurve;
            get_shape.SubObjectSelect = false;
            get_shape.EnablePreSelect(false, false);
            get_shape.DeselectAllBeforePostSelect = false;
            get_shape.Get();
            if (get_shape.CommandResult() != Result.Success)
            {
                return(get_shape.CommandResult());
            }

            ObjRef shape_objref = get_shape.Object(0);
            Curve  shape_curve  = shape_objref.Curve();

            if (null == shape_curve)
            {
                return(Result.Failure);
            }

            double tolerance = doc.ModelAbsoluteTolerance;

            Brep[] brep = Brep.CreateFromSweep(rail_curve, shape_curve, false, tolerance);
            if (null == brep || 0 == brep.Length)
            {
                return(Result.Failure);
            }

            // Create a history record
            HistoryRecord history = new HistoryRecord(this, HISTORY_VERSION);

            WriteHistory(history, rail_objref, shape_objref, tolerance);

            for (int i = 0; i < brep.Length; i++)
            {
                doc.Objects.AddBrep(brep[i], null, history, false);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
コード例 #10
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Open file dialog
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.InitialDirectory = doc.Path;
            openFileDialog.Filter           = "3dm files (*.3dm)|*.3dm| dxf files (*.dxf)|*.dxf|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect      = true;
            openFileDialog.Title            = "CAD files to merge";

            DialogResult dr = openFileDialog.ShowDialog();
            uint         firstSN, lastSN;
            string       sScript;
            BoundingBox  bbox;
            string       panelDetails = "";

            double             importMinX, importMinY;
            double             importMaxX, importMaxY;
            double             globalMinX, globalMinY;
            double             globalMaxX, globalMaxY;
            double             gap          = 500;
            Boolean            executedOnce = false;
            double             commonminY   = 0;
            double             commonminX   = 0;
            double             commonmaxY   = 0;
            List <RhinoObject> imported     = new List <RhinoObject>(); //holds the imported rhino obects (all objects)
            List <RhinoObject> oldObjs      = new List <RhinoObject>(); //holds the old objects in the document
            List <RhinoObject> newObjs      = new List <RhinoObject>(); //holds the new objects in the document
            Boolean            newObjFound  = false;

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                //Select direction and angle
                double            rotationAngle = 0;
                bool              anticlockwise = true;
                MessageBoxButtons buttons       = MessageBoxButtons.YesNo;

                DialogResult result = MessageBox.Show("Do you want to rotate each dxf imported by 90°?", "DXF rotation", buttons);
                if (result == DialogResult.Yes)
                {
                    rotationAngle = 90;
                    result        = MessageBox.Show("Select the rotation direction: 'Yes' for 'Anti-clockwise' and 'No' for 'Clockwise'.", "Rotation Direction", buttons);
                    if (result == DialogResult.No)
                    {
                        rotationAngle = -90;
                        anticlockwise = false;
                    }
                }



                // Read the files
                foreach (String file in openFileDialog.FileNames)
                {
                    importMinX = Double.MaxValue;
                    importMinY = Double.MaxValue;
                    importMaxX = Double.MinValue;
                    importMaxY = Double.MinValue;
                    globalMinX = Double.MaxValue;
                    globalMinY = Double.MaxValue;
                    globalMaxX = Double.MinValue;
                    globalMaxY = Double.MinValue;

                    // Import each file
                    try
                    {
                        sScript = String.Format("! _-Import \"{0}\" _Enter", file);

                        firstSN = RhinoObject.NextRuntimeSerialNumber;
                        RhinoApp.RunScript(sScript, false);
                        lastSN = RhinoObject.NextRuntimeSerialNumber; //Investigate later
                        List <Guid> ids = new List <Guid>();
                        imported = new List <RhinoObject>();
                        newObjs  = new List <RhinoObject>();
                        foreach (RhinoObject obj in doc.Objects)
                        {
                            if (obj.RuntimeSerialNumber >= firstSN && obj.RuntimeSerialNumber < lastSN)
                            {
                                imported.Add(obj);
                                ids.Add(obj.Id);

                                bbox = obj.Geometry.GetBoundingBox(Plane.WorldXY);

                                if (importMaxX < bbox.Max.X)
                                {
                                    importMaxX = bbox.Max.X;
                                }

                                if (importMaxY < bbox.Max.Y)
                                {
                                    importMaxY = bbox.Max.Y;
                                }

                                if (importMinX > bbox.Min.X)
                                {
                                    importMinX = bbox.Min.X;
                                }

                                if (importMinY > bbox.Min.Y)
                                {
                                    importMinY = bbox.Min.Y;
                                }
                            }
                            else
                            {
                                //Global
                                bbox = obj.Geometry.GetBoundingBox(Plane.WorldXY);

                                if (globalMaxX < bbox.Max.X)
                                {
                                    globalMaxX = bbox.Max.X;
                                }

                                if (globalMaxY < bbox.Max.Y)
                                {
                                    globalMaxY = bbox.Max.Y;
                                }

                                if (globalMinX > bbox.Min.X)
                                {
                                    globalMinX = bbox.Min.X;
                                }

                                if (globalMinY > bbox.Min.Y)
                                {
                                    globalMinY = bbox.Min.Y;
                                }
                            }
                        }

                        if (!executedOnce) //execute this only once
                        {
                            commonminY = importMinY;
                            commonminX = importMinX;
                            commonmaxY = importMaxY;
                        }

                        var startPoint = new Point3d(importMinX, importMinY, 0);

                        if (globalMaxX == Double.MinValue)
                        {
                            globalMaxX = 0;
                        }
                        if (globalMaxY == Double.MinValue)
                        {
                            globalMaxY = 0;
                        }
                        if (globalMinX == Double.MaxValue)
                        {
                            globalMinX = 0;
                        }
                        if (globalMinY == Double.MaxValue)
                        {
                            globalMinY = 0;
                        }


                        var endPoint = new Point3d(globalMaxX + gap, commonminY, 0);

                        List <string> names = new List <string>();
                        //find which type of perimeter
                        for (int i = 0; i < 100; i++)
                        {
                            if (doc.Layers.FindIndex(i) != null)
                            {
                                names.Add(doc.Layers.FindIndex(i).Name);
                            }
                            else
                            {
                                break;
                            }
                        }

                        /*
                         * String perimeterName = "Default";
                         * //Get the correct perimeter name
                         * if (doc.Layers.Find("LAYERS_FOR_NESTING$PANEL_P", true) >= 0)
                         * {
                         *  perimeterName = "LAYERS_FOR_NESTING$PANEL_P";
                         * }
                         *
                         * if (doc.Layers.Find("Panel_Perimeter", true) >= 0)
                         * {
                         *  perimeterName = "Panel_Perimeter";
                         * }  */

                        int layer_index = doc.Layers.Find("PANEL PERIMETER", true);
                        if (layer_index < 0)
                        {
                            // Add a new layer to the document
                            layer_index = doc.Layers.Add("PANEL PERIMETER", System.Drawing.Color.Black);
                        }


                        foreach (string perimeterName in names)
                        {
                            foreach (RhinoObject obj in doc.Objects.FindByLayer(perimeterName))
                            {
                                ObjRef objR = new ObjRef(obj);
                                if (objR.Curve() == null)
                                {
                                    continue;
                                }
                                //loop through the old objects array to find if the object is found in the array
                                foreach (RhinoObject rhinObj in oldObjs)
                                {
                                    if (rhinObj.Id.Equals(obj.Id)) //if the ids are equals it means the object belongs to a panel which has already been rotated
                                    {
                                        newObjFound = true;        //set to true
                                        break;                     //exit from this second loop
                                    }
                                }
                                if (!newObjFound)     //go in only if the newObjectfound is false
                                {
                                    newObjs.Add(obj); //add the new object to the array
                                }
                                newObjFound = false;  //set the variable back to false
                            }
                        }



                        // Move all the objects
                        var xform = Transform.Translation(endPoint - startPoint);
                        foreach (var objRef in imported)
                        {
                            doc.Objects.Transform(objRef, xform, true);
                        }

                        executedOnce = true;

                        Rhino.Geometry.Point3d pt    = new Rhino.Geometry.Point3d(globalMaxX + gap, (commonminY + commonmaxY) / 2, 0);
                        Rhino.Geometry.Plane   plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
                        plane.Origin = pt;
                        String dimension = findLeastDimension(newObjs, plane, "PANEL PERIMETER", rotationAngle); //call the method and pass the parameters to find the min X and min Y for the panel


                        // Add the file as the label

                        //The codes below are to create red labels for each panel

                        double height = (importMaxY - importMinY) * 0.1;
                        //double height = 3;
                        string label      = Path.GetFileNameWithoutExtension(file);
                        int    layerIndex = doc.Layers.CurrentLayerIndex;

                        RhinoUtilities.SetActiveLayer("LABELS", System.Drawing.Color.Red);

                        const string font = "Arial";
                        plane        = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
                        plane.Origin = pt;
                        Guid labelGuid = doc.Objects.AddText(label, plane, height, font, false, false);

                        ids.Add(labelGuid);
                        imported.Add(doc.Objects.Find(labelGuid));

                        doc.Layers.SetCurrentLayerIndex(layerIndex, true);

                        //panelDetails = panelDetails + label + "\t" + (importMaxX - importMinX) + "\t" + (importMaxY - importMinY) + "\n";
                        panelDetails = panelDetails + label + "#" + dimension + "\n"; //set the dimension with the panel name                                                                                                                                                                                                                                                                             vv



                        //int index = doc.Groups.Add(ids);

                        oldObjs.AddRange(newObjs);
                    }
                    catch (Exception ex)
                    {
                        // Could not load the image - probably related to Windows file system permissions.
                        MessageBox.Show(ex.Message);
                    }
                }


                double labelHeight = 100;
                Rhino.Geometry.Point3d panelDetailsPt    = new Rhino.Geometry.Point3d(0, 0 + labelHeight, 0);
                const string           labelFont         = "Arial";
                Rhino.Geometry.Plane   panelDetailsPlane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
                panelDetailsPlane.Origin = panelDetailsPt;
                doc.Objects.AddText(panelDetails, panelDetailsPlane, labelHeight, labelFont, false, false);

                doc.Layers.Delete(doc.Layers.Find("temp", false), true);

                exportToExcel(panelDetails); //call to export panel dimensions to excel
            }

            Messages.excelOperationComplete();

            // Export the whole lot
            //string command = string.Format("-_Export \"" + Path.GetDirectoryName(doc.Path) + @"\" + labelName + "\"  Scheme \"R12 Lines & Arcs\" Enter");
            // Export the selected curves
            //RhinoApp.RunScript(command, true);
            doc.Views.Redraw();
            return(Result.Success);
        }
コード例 #11
0
        public String findLeastDimension(List <RhinoObject> newObjs, Plane plane, String perimeterName, double rotationAngle)
        {
            RhinoDoc doc        = RhinoDoc.ActiveDoc;
            double   minX       = 0;
            double   minY       = 0;
            double   minArea    = double.MaxValue;
            Layer    layerIndex = doc.Layers.FindName("Default");

            RhinoUtilities.SetActiveLayer("temp", System.Drawing.Color.Black);
            //Copy Objects of current layer to temp layer
            foreach (var selected_object in newObjs)
            {
                selected_object.Attributes.LayerIndex = doc.Layers.Find("temp", false);
                selected_object.CommitChanges();
            }
            //select objects in the temporart layer and join
            RhinoApp.RunScript("SelNone", true);
            RhinoApp.RunScript("SelLayerNumber " + doc.Layers.Find("temp", true), false);
            //MetrixUtilities.joinCurves(doc.Layers.Find("temp", false));


            //plane.Rotate(i, plane.XAxis); //rotateshape with the value of i
            RhinoObject[] objs      = doc.Objects.FindByLayer("temp");
            List <Curve>  curveList = new List <Curve>();

            Curve[]     curveArray = null;
            RhinoObject obj        = objs[0];

            foreach (RhinoObject objt in objs)
            {
                curveList.Add(new ObjRef(objt).Curve());
            }
            curveArray = Curve.JoinCurves(curveList);



            obj.Attributes.ToString();
            ObjRef objR        = new ObjRef(obj);
            Curve  curve       = objR.Curve();
            double curvelength = -1;
            Curve  baseline    = null;
            double angle       = 0;

            foreach (Curve cv in curveList)
            {
                if (cv.GetLength() > curvelength)
                {
                    curvelength = cv.GetLength();
                    baseline    = cv;
                    angle       = Math.Atan(baseline.TangentAtStart.Y / baseline.TangentAtStart.X);
                }
            }

            if (curveArray != null)
            {
                double maxArea = Double.MinValue;
                foreach (Curve tempCurve in curveArray)
                {
                    BoundingBox tempBBox = tempCurve.GetBoundingBox(true);
                    if (tempBBox.Area > maxArea)
                    {
                        curve = tempCurve;
                    }
                }
            }
            BoundingBox    boundingBox    = curve.GetBoundingBox(Plane.WorldXY);
            List <Point3d> points         = new List <Point3d>();
            PolylineCurve  polyline_curve = curve as PolylineCurve;
            double         diagnal        = 0;
            bool           rectangle      = false;
            Point3d        centerC        = boundingBox.Center;

            minArea = boundingBox.Area;
            minX    = boundingBox.Max.X - boundingBox.Min.X;
            minY    = boundingBox.Max.Y - boundingBox.Min.Y;

            /*
             * if (polyline_curve != null && polyline_curve.PointCount == 5)
             * {
             *  for (int j = 0; j < polyline_curve.PointCount; j++)
             *  {
             *      points.Add(polyline_curve.Point(j));
             *  }
             *
             *  if(Math.Round(points[0].DistanceTo(points[1])) == Math.Round(points[2].DistanceTo(points[3])))
             *  {
             *      minX = points[0].DistanceTo(points[1]);
             *      minY = points[1].DistanceTo(points[2]);
             *      rectangle = true;
             *  }
             *  else
             *  {
             *      rectangle = false;
             *  }
             * }*/

            if (rectangle == false)
            {
                curve.Rotate(-angle, Plane.WorldXY.ZAxis, baseline.PointAtStart);
                boundingBox = curve.GetBoundingBox(Plane.WorldXY);
                if (boundingBox.Area < minArea)
                {
                    Point3d min = boundingBox.Min;
                    Point3d max = boundingBox.Max;
                    minX = max.X - min.X;
                    minY = max.Y - min.Y;
                }
            }


            RhinoApp.RunScript("-_Rotate " + centerC + " " + rotationAngle, false);


            //RhinoApp.RunScript("-_Rotate " + boundingBox.Center +" " + 5, false);



            //Set back the previous default layer
            RhinoUtilities.SetActiveLayer(perimeterName, System.Drawing.Color.Black);
            //Copy all object of temp layer back to the previous layer
            foreach (var selected_object in doc.Objects.FindByLayer("temp"))
            {
                selected_object.Attributes.LayerIndex = doc.Layers.FindByFullPath(perimeterName, false);
                selected_object.CommitChanges();
            }

            doc.Layers.SetCurrentLayerIndex(doc.Layers.FindByFullPath(layerIndex.Name, false), true);
            //needs to fix the tab issue
            return(String.Format("{0}#{1}", Math.Max(minX, minY), Math.Min(minX, minY))); //return the minX and minY for the panel
        }