Ejemplo n.º 1
0
        protected Vector3d getWidthHeigthDepthVect(Rhino.DocObjects.ObjRef boxObjRef)
        {
            Brep        boxBrep = boxObjRef.Brep();
            BoundingBox bbox    = boxBrep.GetBoundingBox(true);
            Point3d     bboxMin = bbox.Min;
            Point3d     bboxMax = bbox.Max;
            double      xDist   = bboxMax.X - bboxMin.X;
            double      yDist   = bboxMax.Y - bboxMin.Y;
            double      zDist   = bboxMax.Z - bboxMin.Z;

            return(new Vector3d(xDist, yDist, zDist));
        }
Ejemplo n.º 2
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 gbrep1 = new GetObject();

            gbrep1.SetCommandPrompt("get the brep");
            gbrep1.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep1.SubObjectSelect = false;
            gbrep1.Get();
            if (gbrep1.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep1.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref1 = gbrep1.Object(0);
            Rhino.DocObjects.RhinoObject my_obj1    = my_objref1.Object();
            if (my_obj1 == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep1 = my_objref1.Brep();

            if (brep1 == null)
            {
                return(Result.Failure);
            }
            my_obj1.Select(false);

            for (int i = 0; i < p.my_objects_list.Count; i++)
            {
                Guid brep1_id     = My_object_functions.GetComponentID(brep1);
                Guid my_object_id = My_object_functions.GetComponentID(p.my_objects_list[i]);
                if (brep1_id == my_object_id)
                {
                    p.my_objects_list.RemoveAt(i);
                }
            }

            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>();
            int pin_number = My_object_functions.GetPinQuantity(brep1);

            for (int i = 0; i < pin_number; i++)
            {
                Guid pin_id = My_object_functions.GetPinGuid(brep1, i);
                new_path_list = p.graph.DijkstraPath_DeletePin(pin_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 path_id = new_path_list[i].UserDictionary.GetGuid("PathID");
                my_attributes.ObjectId = path_id;
                doc.Objects.Add(new_path_list[i], my_attributes);
            }

            doc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo n.º 3
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_;

            Stopwatch watch = new Stopwatch();

            GetObject gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref = gbrep.Object(0);
            Rhino.DocObjects.RhinoObject my_obj    = my_objref.Object();
            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);

            GetObjectPosition gp = new GetObjectPosition(brep, my_mesh);

            gp.SetCommandPrompt("Get the object position on mesh: ");
            gp.Constrain(my_mesh, false);
            gp.Get();
            if (gp.CommandResult() != Result.Success)
            {
                return(gp.CommandResult());
            }

            Brep     moved_brep     = brep.DuplicateBrep();
            Point3d  Origin         = brep.UserDictionary.GetPoint3d("CurrentPosition");
            Vector3d OriginVector   = brep.UserDictionary.GetVector3d("CurrentDirection");
            Point3d  new_position   = gp.Point();
            Vector3d normal_on_mesh = my_mesh.NormalAt(my_mesh.ClosestMeshPoint(new_position, 0));

            if (OriginVector.IsParallelTo(normal_on_mesh) == 0)
            {
                double   RotationAngle = Vector3d.VectorAngle(OriginVector, normal_on_mesh);
                Vector3d RoationAxis   = Vector3d.CrossProduct(OriginVector, normal_on_mesh);
                moved_brep.Rotate(RotationAngle, RoationAxis, Origin);
            }

            moved_brep.Translate(new_position - Origin);
            moved_brep.UserDictionary.Set("CurrentPosition", new_position);
            moved_brep.UserDictionary.Set("CurrentDirection", normal_on_mesh);

            ObjectAttributes my_attributes = new ObjectAttributes();

            my_attributes.ObjectColor = Color.FromName(moved_brep.UserDictionary.GetString("Color"));
            my_attributes.ColorSource = ObjectColorSource.ColorFromObject;

            watch.Start();
            //delete all old paths
            IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve);

            foreach (RhinoObject path in path_objref)
            {
                doc.Objects.Delete(path, true);
            }
            watch.Stop();
            RhinoApp.WriteLine("time 1: {0}", watch.Elapsed);

            ObjectAttributes path_attributes = new ObjectAttributes();

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


            Guid      pin_1_id          = moved_brep.UserDictionary.GetGuid("PinID");
            MeshPoint current_meshpoint = my_mesh.ClosestMeshPoint(new_position, 0.0);

            watch.Restart();
            List <NurbsCurve> new_path_list = p.graph.DijkstraPath_Change(pin_1_id, current_meshpoint);

            watch.Stop();
            RhinoApp.WriteLine("time 2: {0}", watch.Elapsed);
            watch.Restart();
            for (int i = 0; i < new_path_list.Count; i++)
            {
                doc.Objects.Add(new_path_list[i], path_attributes);
            }

            doc.Objects.Delete(my_objref, true);
            brep.Dispose();
            doc.Objects.AddBrep(moved_brep, my_attributes);
            doc.Views.Redraw();
            watch.Stop();
            RhinoApp.WriteLine("time 3: {0}", watch.Elapsed);

            return(Result.Success);
        }
Ejemplo n.º 4
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 gbrep1 = new GetObject();

            gbrep1.SetCommandPrompt("get the brep");
            gbrep1.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep1.SubObjectSelect = false;
            gbrep1.Get();
            if (gbrep1.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep1.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref1 = gbrep1.Object(0);
            Rhino.DocObjects.RhinoObject my_obj1    = my_objref1.Object();
            if (my_obj1 == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep1 = my_objref1.Brep();

            if (brep1 == null)
            {
                return(Result.Failure);
            }
            my_obj1.Select(false);

            GetObject gbrep2 = new GetObject();

            gbrep2.SetCommandPrompt("get the brep");
            gbrep2.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep2.SubObjectSelect = false;
            gbrep2.Get();
            if (gbrep2.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep2.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref2 = gbrep2.Object(0);
            Rhino.DocObjects.RhinoObject my_obj2    = my_objref2.Object();
            if (my_obj2 == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep2 = my_objref2.Brep();

            if (brep2 == null)
            {
                return(Result.Failure);
            }
            my_obj2.Select(false);

            Point3d pin_1_position = brep1.UserDictionary.GetPoint3d("CurrentPosition");
            Point3d pin_2_position = brep2.UserDictionary.GetPoint3d("CurrentPosition");
            Guid    pin_1_id       = brep1.UserDictionary.GetGuid("PinID");
            Guid    pin_2_id       = brep2.UserDictionary.GetGuid("PinID");

            MeshPoint pin_1_meshpoint = my_mesh.ClosestMeshPoint(pin_1_position, 0);
            MeshPoint pin_2_meshpoint = my_mesh.ClosestMeshPoint(pin_2_position, 0);
            Stopwatch watch           = new Stopwatch();

            watch.Start();
            NurbsCurve d_path = my_graph.DijkstraPath_Add(pin_1_meshpoint, pin_1_id, pin_2_meshpoint, pin_2_id);

            watch.Stop();
            if (d_path == null)
            {
                return(Result.Success);
            }
            RhinoApp.WriteLine("link time: {0}", watch.Elapsed);
            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.AddCurve(d_path, my_attributes);
            doc.Views.Redraw();

            return(Result.Success);
        }
Ejemplo n.º 5
0
        protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            nishanchiPlugin pluginObj = ((nishanchiPlugin)this.PlugIn);

            Boolean selectedObjectIsBrep = false;
            Boolean selectedObjectIsCurve = false;

            if (!pluginObj.trackerConnected)
            {
                RhinoApp.WriteLine("Tracker disconnected");
                return Rhino.Commands.Result.Failure;
            }
            connectKbEvt();

            //Ask the user to select Breps to print.
            //Result rc = Rhino.Input.RhinoGet.GetMultipleObjects("Select the surfaces to print",
            //false, Rhino.DocObjects.ObjectType.Surface, out objrefs);

            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select the entity to print");
            go.GroupSelect = true;

            //Set this to go.GetMultiple(0,0) if you want to allow multiple entities to be selected
            go.GetMultiple(0, 1);

            Result rc = go.CommandResult();

            if (rc != Rhino.Commands.Result.Success)
            {
                disconnectKbEvt();
                return rc;
            }

            List<Rhino.Geometry.Brep> breps = new List<Rhino.Geometry.Brep>();
            List<Rhino.Geometry.Curve> curves = new List<Rhino.Geometry.Curve>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                ObjRef tmpRef = new ObjRef(go.Object(i).ObjectId);
                Rhino.Geometry.Brep brep = tmpRef.Brep();
                if (brep != null)
                {
                    breps.Add(brep);
                    selectedObjectIsBrep = true;
                }

                Rhino.Geometry.Curve curve = tmpRef.Curve();
                if (curve != null)
                {
                    curves.Add(curve);
                    selectedObjectIsCurve = true;
                }

            }
            if (selectedObjectIsBrep)
                RhinoApp.WriteLine("Selected " + breps.Count + " surfaces! Good! No, not, really, I'm just a program, I couldn't care less.");

            if (selectedObjectIsCurve)
                RhinoApp.WriteLine("Selected " + curves.Count + " curves! Good! No, not, really, I'm just a program, I couldn't care less.");

            createEntities(doc);

            fastrak trackerObj = pluginObj.trackerObj;
            int numPoints = 0;
            int numIntersections = 0;
            Boolean retval;

            RhinoApp.WriteLine(string.Format("Starting continuous mode on the tracker."));
            pluginObj.trackerObj.setContinuous();
            RhinoApp.WriteLine(string.Format("Printing mode enabled now."));

            Curve[] intersectionCurves;
            Point3d[] intersectionPoints;

            running = true;
            while (running)
            {
                retval = trackerObj.readFrame();
                if (retval)
                {
                    //q0,q1,q2,q3 Quaternion begin
                    //Compute the rotation matrix
                    rxTxTx = new Point3d(trackerObj.x, trackerObj.y, trackerObj.z);
                    orientationQuat = new Quaternion(trackerObj.q0, trackerObj.q1, trackerObj.q2, trackerObj.q3);
                    orientationQuat.GetRotation(out angle, out axis);
                    rotMat = Transform.Rotation(angle, axis, origin);

                    // Compute the new positions for the nozzlePoints and also compute the new lines
                    for (int i = 0; i < numNozzles; i++)
                    {
                        nozzleStartPointRxTx[i] = rotMat * nozzleStartPointRxRx[i];
                        nozzleStartPointTxTx[i] = nozzleStartPointRxTx[i] + rxTxTx;

                        nozzleEndPointRxTx[i] = rotMat * nozzleEndPointRxRx[i];
                        nozzleEndPointTxTx[i] = nozzleEndPointRxTx[i] + rxTxTx;

                        nozzleLinesTx[i] = new Line(nozzleStartPointTxTx[i], nozzleEndPointTxTx[i]);
                        nozzleCurves[i] = new LineCurve(nozzleLinesTx[i]);
                    }

                    numIntersections = 0;
                    if (selectedObjectIsBrep)
                    {
                        for (int i = 0; i < numNozzles; i++)
                        {
                            foreach (Brep b in breps)
                            {
                                try
                                {
                                    Intersection.CurveBrep(nozzleCurves[i], b, nozzleTolerance, out intersectionCurves, out intersectionPoints);
                                    if (intersectionPoints.Length > 0)
                                    {
                                        intersectionsBits[i] = 1;
                                        numIntersections++;
                                    }
                                    else
                                    {
                                        intersectionsBits[i] = 0;
                                    }
                                }
                                catch (Exception e)
                                {
                                    RhinoApp.WriteLine(e.Message);
                                }
                            }
                        }
                    }

                    if (selectedObjectIsCurve)
                    {
                        for (int i = 0; i < numNozzles; i++)
                        {
                            foreach (Curve c in curves)
                            {
                                try
                                {
                                    var events = Intersection.CurveCurve(nozzleCurves[i], c, nozzleTolerance, nozzleTolerance);
                                    if (events != null)
                                    {
                                        if (events.Count >= 1)
                                        {
                                            intersectionsBits[i] = 1;
                                            numIntersections++;
                                        }
                                        else
                                        {
                                            intersectionsBits[i] = 0;
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    RhinoApp.WriteLine(e.Message);
                                }
                            }
                        }
                    }

                    if (pluginObj.printHeadConnected)
                    {
                        // I print
                        if (((numPoints % 5) == 0)&&(numIntersections > 0))
                        {
                            string p = printCommand();
                            //RhinoApp.WriteLine(p);
                            pluginObj.printHeadObj.printFrame(p);
                            //pluginObj.printHeadObj.printFullLine();
                        }
                    }

                    numPoints++;
                }

                //And, I move the printer like thing on the screen
                if ((numPoints % 10) == 0)
                {
                    for (int i = 0; i < numNozzles; i++)
                    {
                        doc.Objects.Delete(lineGuids[i],false);
                        lineGuids[i] = doc.Objects.AddLine(nozzleLinesTx[i]);
                    }
                    doc.Objects.Delete(ballGuid, false);
                    ball = new Sphere(rxTxTx, ballRadius);
                    ballGuid = doc.Objects.AddSphere(ball);

                    doc.Views.ActiveView.Redraw();
                    RhinoApp.Wait();
                }
            }

            running = false;
            removeEntities(doc);

            RhinoApp.WriteLine(string.Format("Stopping continuous mode on the tracker."));
            pluginObj.trackerObj.stopContinuous();
            disconnectKbEvt();
            RhinoApp.WriteLine(string.Format("I guess you don't wanna print anymore, well who cares! Not me!"));
            return Rhino.Commands.Result.Success;
        }
Ejemplo n.º 6
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 gbrep = new GetObject();

            gbrep.SetCommandPrompt("get the brep");
            gbrep.GeometryFilter  = Rhino.DocObjects.ObjectType.Brep;
            gbrep.SubObjectSelect = false;
            gbrep.Get();
            if (gbrep.CommandResult() != Rhino.Commands.Result.Success)
            {
                return(gbrep.CommandResult());
            }
            Rhino.DocObjects.ObjRef      my_objref = gbrep.Object(0);
            Rhino.DocObjects.RhinoObject my_obj    = my_objref.Object();
            if (my_obj == null)
            {
                return(Rhino.Commands.Result.Failure);
            }
            Brep brep = my_objref.Brep();

            if (brep == null)
            {
                return(Result.Failure);
            }
            my_obj.Select(false);

            int         pin_number_1         = My_object_functions.GetPinQuantity(brep);
            List <Guid> pin_ball_guid_list_1 = new List <Guid>();

            for (int i = 0; i < pin_number_1; i++)
            {
                ObjectAttributes green_ball_attributes = new ObjectAttributes();
                green_ball_attributes.ObjectColor = Color.Green;
                green_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject;

                Point3d pin_position = My_object_functions.GetPinPosition(brep, i);
                Guid    pin_id       = My_object_functions.GetPinGuid(brep, i);
                green_ball_attributes.ObjectId = pin_id;
                green_ball_attributes.UserDictionary.Set("isPin", true);
                Sphere pin_ball = new Sphere(pin_position, 2);
                //Brep pin_ball_brep = pin_ball.ToBrep();
                doc.Objects.AddSphere(pin_ball, green_ball_attributes);
                pin_ball_guid_list_1.Add(pin_id);
            }
            doc.Views.Redraw();

            GetObject g_pinball = new GetObject();

            g_pinball.SetCommandPrompt("choose the pin");
            g_pinball.GeometryFilter = ObjectType.Surface;
            //g_pinball.SetCustomGeometryFilter(PinBallGeometryFilter);
            //g_pinball.DisablePreSelect();
            g_pinball.SubObjectSelect = false;
            g_pinball.Get();
            if (g_pinball.CommandResult() != Result.Success)
            {
                return(g_pinball.CommandResult());
            }
            if (g_pinball.Object(0).Brep() == null)
            {
                return(Result.Failure);
            }

            RhinoObject selected_pin_ball    = g_pinball.Object(0).Object();
            Guid        selected_pin_ball_id = selected_pin_ball.Id;

            for (int i = 0; i < pin_ball_guid_list_1.Count; i++)
            {
                doc.Objects.Delete(pin_ball_guid_list_1[i], true);
            }

            ObjectAttributes greenyellow_ball_attributes = new ObjectAttributes();

            greenyellow_ball_attributes.ObjectColor = Color.GreenYellow;
            greenyellow_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject;
            greenyellow_ball_attributes.ObjectId    = selected_pin_ball_id;
            greenyellow_ball_attributes.UserDictionary.Set("isPin", true);
            int     pin_number            = My_object_functions.FindPinNumber(brep, selected_pin_ball_id);
            Point3d selected_pin_position = My_object_functions.GetPinPosition(brep, pin_number);
            Sphere  pin_ball_new          = new Sphere(selected_pin_position, 2);

            doc.Objects.AddSphere(pin_ball_new, greenyellow_ball_attributes);


            doc.Views.Redraw();

            //MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance;
            if (p.my_objects_list.Count <= 1)
            {
                RhinoApp.WriteLine("not enough objects");
                return(Result.Failure);
            }

            List <Guid> pin_ball_guid_list_2 = new List <Guid>();

            for (int i = 0; i < p.my_objects_list.Count; i++)
            {
                Brep an_object = p.my_objects_list[i];
                if (My_object_functions.GetComponentID(brep) != My_object_functions.GetComponentID(an_object))
                {
                    int pin_quantity = My_object_functions.GetPinQuantity(an_object);
                    for (int j = 0; j < pin_quantity; j++)
                    {
                        ObjectAttributes green_ball_attributes = new ObjectAttributes();
                        green_ball_attributes.ObjectColor = Color.Green;
                        green_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject;
                        Point3d pin_position = My_object_functions.GetPinPosition(an_object, j);
                        Guid    pin_id       = My_object_functions.GetPinGuid(an_object, j);
                        green_ball_attributes.ObjectId = pin_id;
                        green_ball_attributes.UserDictionary.Set("isPin", true);
                        Sphere pin_ball = new Sphere(pin_position, 2);
                        doc.Objects.AddSphere(pin_ball, green_ball_attributes);
                        pin_ball_guid_list_2.Add(pin_id);
                    }
                }
            }
            doc.Views.Redraw();

            GetObject g_pinball_2 = new GetObject();

            g_pinball_2.SetCommandPrompt("choose the pin");
            g_pinball_2.GeometryFilter = ObjectType.Surface;
            //g_pinball.SetCustomGeometryFilter(PinBallGeometryFilter);
            //g_pinball.DisablePreSelect();
            g_pinball_2.SubObjectSelect = false;
            g_pinball_2.Get();
            if (g_pinball_2.CommandResult() != Result.Success)
            {
                return(g_pinball_2.CommandResult());
            }
            if (g_pinball_2.Object(0).Brep() == null)
            {
                return(Result.Failure);
            }

            RhinoObject selected_pin_ball_2    = g_pinball_2.Object(0).Object();
            Guid        selected_pin_ball_id_2 = selected_pin_ball_2.Id;
            Brep        brep_2 = null;

            for (int i = 0; i < p.my_objects_list.Count; i++)
            {
                Brep an_object    = p.my_objects_list[i];
                int  pin_quantity = My_object_functions.GetPinQuantity(an_object);
                bool mark         = false;
                for (int j = 0; j < pin_quantity; j++)
                {
                    if (My_object_functions.GetPinGuid(an_object, j) == selected_pin_ball_id_2)
                    {
                        mark = true;
                        break;
                    }
                }
                if (mark)
                {
                    brep_2 = an_object;
                    break;
                }
            }
            if (brep_2 == null)
            {
                return(Result.Failure);
            }

            int selected_pin_number_2 = My_object_functions.FindPinNumber(brep_2, selected_pin_ball_id_2);

            for (int i = 0; i < pin_ball_guid_list_2.Count; i++)
            {
                doc.Objects.Delete(pin_ball_guid_list_2[i], true);
            }

            Point3d selected_pin_position_2 = My_object_functions.GetPinPosition(brep_2, selected_pin_number_2);

            Sphere pin_ball_new_2 = new Sphere(selected_pin_position_2, 2);

            greenyellow_ball_attributes.ObjectId = selected_pin_ball_id_2;

            doc.Objects.AddSphere(pin_ball_new_2, greenyellow_ball_attributes);

            doc.Views.Redraw();

            MeshPoint  pin_1_meshpoint = my_mesh.ClosestMeshPoint(selected_pin_position, 0);
            MeshPoint  pin_2_meshpoint = my_mesh.ClosestMeshPoint(selected_pin_position_2, 0);
            NurbsCurve d_path          = my_graph.DijkstraPath_Add(pin_1_meshpoint, selected_pin_ball_id, pin_2_meshpoint, selected_pin_ball_id_2);


            if (d_path != null)
            {
                ObjectAttributes path_attributes = new ObjectAttributes();
                path_attributes.ObjectColor      = Color.Yellow;
                path_attributes.ColorSource      = ObjectColorSource.ColorFromObject;
                path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject;
                path_attributes.PlotWeight       = 2.0;
                path_attributes.ObjectId         = d_path.UserDictionary.GetGuid("PathID");
                doc.Objects.AddCurve(d_path, path_attributes);
            }



            doc.Objects.Delete(selected_pin_ball_id, true);
            doc.Objects.Delete(selected_pin_ball_id_2, true);

            doc.Views.Redraw();



            return(Result.Success);
        }
Ejemplo n.º 7
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            const Rhino.DocObjects.ObjectType geometryFilter = Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.PolysrfFilter;

            Rhino.DocObjects.ObjRef objref;
            Result rc = Rhino.Input.RhinoGet.GetOneObject("Select first/main polysurface or surface to bool",
                                                          false, geometryFilter, out objref);

            if (rc != Rhino.Commands.Result.Success)
            {
                return(rc);
            }
            if (objref == null)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Rhino.Geometry.Brep brep = objref.Brep();
            bool resIssolid          = brep.IsSolid;

            if (!resIssolid)
            {
                Dialogs.ShowMessage("Your polysurface or surface is not solid! Result might not be valid!", "Warning!");
            }
            Guid firstBrep = objref.ObjectId;

            doc.Objects.UnselectAll(true);


            //Select rest of polysurfaces or surfaces to bool
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select rest of polysurfaces or surfaces to bool");
            go.GeometryFilter = geometryFilter | Rhino.DocObjects.ObjectType.InstanceReference;
            go.GroupSelect    = true;
            go.GetMultiple(1, 0);

            bool isSolid = true;

            //Add set to breps list
            List <Rhino.Geometry.Brep> breps = new List <Rhino.Geometry.Brep>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                //Explode if instance object and add to breps list
                if (go.Object(i).Object() is InstanceObject)
                {
                    InstanceObject     instObj = go.Object(i).Object() as InstanceObject;
                    RhinoObject[]      explodedObjects;
                    ObjectAttributes[] attributesOfExplodedObjects;
                    Transform[]        transformOfExplodedObjects;

                    instObj.Explode(false, out explodedObjects, out attributesOfExplodedObjects, out transformOfExplodedObjects);
                    Guid addedObjectID = doc.Objects.Add(explodedObjects[0].Geometry, explodedObjects[0].Attributes);

                    ObjRef objrefs            = new Rhino.DocObjects.ObjRef(addedObjectID);
                    Rhino.Geometry.Brep brepd = objrefs.Brep();

                    brepd.Transform(transformOfExplodedObjects[0]);

                    resIssolid = brepd.IsSolid;
                    if (!resIssolid)
                    {
                        isSolid = false;
                    }
                    if (brepd != null && firstBrep != addedObjectID)
                    {
                        breps.Add(brepd);
                    }
                    doc.Objects.Delete(addedObjectID, true);
                }
                else
                {
                    Rhino.DocObjects.ObjRef objrefs = go.Object(i);
                    Rhino.Geometry.Brep     brepd   = objrefs.Brep();
                    resIssolid = brepd.IsSolid;
                    if (!resIssolid)
                    {
                        isSolid = false;
                    }
                    if (brepd != null && firstBrep != objrefs.ObjectId)
                    {
                        breps.Add(brepd);
                    }
                }
            }
            if (!isSolid)
            {
                Dialogs.ShowMessage("At least on polysurface or surface to subtract is not solid! Result might not be valid!", "Warning!");
            }

            doc.Objects.UnselectAll(true);

            //Create layers for failed and successfull booleans if not already existing
            var fail_layer_index = doc.Layers.FindName("FJ Boolean Fails");

            if (fail_layer_index == null)
            {
                string name_fail_layer          = "FJ Boolean Fails";
                Rhino.DocObjects.Layer boolFail = new Rhino.DocObjects.Layer();
                boolFail.Name  = name_fail_layer;
                boolFail.Color = System.Drawing.Color.Red;
                doc.Layers.Add(boolFail);
                fail_layer_index = doc.Layers.FindName(name_fail_layer);
            }

            var done_layer_index = doc.Layers.FindName("FJ Boolean Done");

            if (done_layer_index == null)
            {
                string name_done_layer          = "FJ Boolean Done";
                Rhino.DocObjects.Layer boolDone = new Rhino.DocObjects.Layer();
                boolDone.Name  = name_done_layer;
                boolDone.Color = System.Drawing.Color.BlueViolet;
                doc.Layers.Add(boolDone);
                done_layer_index = doc.Layers.FindName(name_done_layer);
            }

            //Compute boolean union
            double tolerance = doc.ModelAbsoluteTolerance;
            int    a         = 0;

            for (int i = 0; i < breps.Count; i++)
            {
                RhinoApp.WriteLine("computing number: " + i + " of: " + breps.Count + " operations...");

                List <Brep> brepBool = new List <Brep>();
                brepBool.Add(brep);
                brepBool.Add(breps[i]);
                Rhino.Geometry.Brep[] brepBoolNew = Rhino.Geometry.Brep.CreateBooleanUnion(brepBool, tolerance, true);

                if (brepBoolNew == null || brepBoolNew.Length > 1)
                {
                    a++;
                    doc.Objects.Delete(go.Object(i).Object());

                    var    boolresultfail = doc.Objects.AddBrep(breps[i]);
                    ObjRef objFailref     = new ObjRef(boolresultfail);
                    Rhino.DocObjects.RhinoObject objFail = objFailref.Object();
                    objFail.Attributes.LayerIndex = fail_layer_index.Index;
                    objFail.CommitChanges();
                }
                else
                {
                    brep = brepBoolNew[0];
                    doc.Objects.Delete(go.Object(i).Object());

                    var    boolresult = doc.Objects.AddBrep(breps[i]);
                    ObjRef obj20ref   = new ObjRef(boolresult);
                    Rhino.DocObjects.RhinoObject obj2Org = obj20ref.Object();
                    obj2Org.Attributes.LayerIndex = done_layer_index.Index;
                    obj2Org.CommitChanges();
                }

                doc.Views.Redraw();
            }

            RhinoApp.WriteLine(a + " of " + breps.Count + " operations failed!");

            Rhino.DocObjects.RhinoObject obj1Org = objref.Object();
            doc.Objects.Delete(obj1Org);

            doc.Objects.AddBrep(brep);

            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
Ejemplo n.º 8
0
        //Dynamic Object Draw
        void RefObjDraw(object sender, Rhino.Input.Custom.GetPointDrawEventArgs e)
        {
            double factorTemp = (scaleCenter.DistanceTo(e.CurrentPoint)) / (scaleCenter.DistanceTo(scaleRefPoint));

            //Translate 3d
            if (dimensionIndex == 0)
            {
                for (int i = 0; i < dynRef.Count; i++)
                {
                    Rhino.DocObjects.ObjRef objref = dynRef[i] as Rhino.DocObjects.ObjRef;
                    var xform = Transform.Scale(centers[i], factorTemp);

                    Brep brep  = objref.Brep();
                    var  index = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, 0.01, 0, true);
                        //doc.Objects.Replace(objref.ObjectId, brep);

                        e.Display.DrawBrepWires(brep, System.Drawing.Color.Gray);
                    }
                    else
                    {
                        Rhino.DocObjects.RhinoObject rhobj = objref.Object();
                        e.Display.DrawObject(rhobj, xform);
                    }
                }
            }
            //Translate 2d
            else if (dimensionIndex == 1)
            {
                for (int i = 0; i < dynRef.Count; i++)
                {
                    Rhino.DocObjects.ObjRef objref = dynRef[i] as Rhino.DocObjects.ObjRef;
                    plane2D.Origin = centers[i];
                    var  xform = Rhino.Geometry.Transform.Scale(plane2D, factorTemp, factorTemp, 1);
                    Brep brep  = objref.Brep();
                    var  index = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, 0.01, 0, true);
                        //doc.Objects.Replace(objref.ObjectId, brep);

                        e.Display.DrawBrepWires(brep, System.Drawing.Color.Gray);
                    }
                    else
                    {
                        Rhino.DocObjects.RhinoObject rhobj = objref.Object();
                        e.Display.DrawObject(rhobj, xform);
                    }
                }
            }
            //Translate 1d
            else if (dimensionIndex == 2)
            {
                for (int i = 0; i < dynRef.Count; i++)
                {
                    Vector3d vec                   = (scaleRefPoint - scaleCenter);
                    Plane    scalePlane            = new Plane(centers[i], vec);
                    var      xform                 = Transform.Scale(scalePlane, 1, 1, factorTemp);
                    Rhino.DocObjects.ObjRef objref = dynRef[i] as Rhino.DocObjects.ObjRef;
                    Brep brep  = objref.Brep();
                    var  index = objref.GeometryComponentIndex.Index;
                    if (index > 0)
                    {
                        brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, 0.01, 0, true);
                        //doc.Objects.Replace(objref.ObjectId, brep);

                        e.Display.DrawBrepWires(brep, System.Drawing.Color.Gray);
                    }
                    else
                    {
                        Rhino.DocObjects.RhinoObject rhobj = objref.Object();
                        e.Display.DrawObject(rhobj, xform);
                    }
                }
            }
        }