Exemplo n.º 1
0
        public static Brep GetTrimmedBrep(pps.Surface surface, SurfaceConverter surfConv, CurveConverter curveConv)
        {
            var rhSurf = surfConv.FromPipe <Surface, pps.Surface>(surface);
            var brep   = Brep.CreateFromSurface(rhSurf);

            //if (!brep.IsValid) { brep.Repair(Rhino.RhinoMath.ZeroTolerance); }
            if (typeof(pps.NurbsSurface).IsAssignableFrom(surface.GetType()) &&
                ((pps.NurbsSurface)surface).TrimCurves.Count > 0)
            {
                List <ppc.Curve> trims = ((pps.NurbsSurface)surface).TrimCurves;
                List <ppc.Curve> loops = brep.Faces.First().Loops.Select((l) =>
                                                                         curveConv.ToPipe <Curve, ppc.Curve>(l.To3dCurve())).ToList();

                if (!PipeDataUtil.EqualIgnoreOrder(loops, trims))
                {
                    var rhTrims     = trims.Select((c) => curveConv.FromPipe <Curve, ppc.Curve>(c)).ToList();
                    var faceToSplit = brep.Faces.First();
                    var brep2       = faceToSplit.Split(rhTrims, Rhino.RhinoMath.ZeroTolerance);
                    //if (brep2 != null && !brep2.IsValid) { brep2.Repair(Rhino.RhinoMath.ZeroTolerance); }
                    if (brep2 != null && brep2.IsValid)
                    {
                        brep = GetEnclosedFacesAsBrep(brep2, rhTrims) ?? brep2;
                    }
                }
            }

            return(brep);
        }
Exemplo n.º 2
0
        public void TransformToPlane(Plane newPlane)
        {
            double eps = 1e-7;

            if (!PipeDataUtil.Equals(Vec.Dot(newPlane.Z, Plane.Z), 1, eps))
            {
                throw new InvalidOperationException("Cannot transform arc to a new plane");
            }
            if (Vec.Difference(newPlane.Origin, Plane.Origin).Length > eps)
            {
                throw new InvalidOperationException("The origins of the planes do not match");
            }

            double angle = Vec.AngleBetween(Plane.X, newPlane.X);

            if (angle < eps)
            {
                return;
            }
            if (Vec.Dot(Vec.Cross(Plane.X, newPlane.X), Plane.Z) < 0)
            {
                angle *= -1;
            }

            Plane = new Plane(Plane.Origin, Plane.X.RotateAbout(Plane.Z, angle),
                              Plane.Y.RotateAbout(Plane.Z, angle));
            StartAngle -= angle;
            EndAngle   -= angle;
        }
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
#if DEBUG
            /*
             * setting the document as a globally accessible member, so that the converters can accsess and add
             * intermediate geometry to the document for examination
             */
            RhinoV6PipeConverter.DebugUtil.Document = doc;
#endif
            string pipeIdentifier;
            using (GetString getter = new GetString())
            {
                getter.SetCommandPrompt("Enter the name/url for the pipe");
                if (_prevPipeName != null)
                {
                    getter.SetDefaultString(_prevPipeName);
                }
                if (getter.Get() != GetResult.String)
                {
                    RhinoApp.WriteLine("Invalid Input");
                    return(getter.CommandResult());
                }
                pipeIdentifier = getter.StringResult();
                _prevPipeName  = pipeIdentifier;
            }

            if (PipeDataUtil.IsValidUrl(pipeIdentifier))
            {
                _pipe = new MyWebPipe(pipeIdentifier);
            }
            else
            {
                _pipe = new LocalNamedPipe(pipeIdentifier);
            }

            _pipe.SetEmitter(this);
            try
            {
                _pipe.Update();
            }
            catch (Exception e)
            {
                Rhino.UI.Dialogs.ShowMessage(e.Message, "Error");
            }

            if (_objectsReceived.Count > 0)
            {
                DeletePulledObjects(pipeIdentifier, ref doc);
            }
            List <Guid> received = new List <Guid>();
            foreach (var geom in _objectsReceived)
            {
                Guid id = doc.Objects.Add(geom);
                received.Add(id);
            }
            doc.Views.Redraw();

            SavePulledObjects(pipeIdentifier, received, ref doc);
            return(Result.Success);
        }
Exemplo n.º 4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string pipeIdentifier;

            using (GetString getter = new GetString())
            {
                getter.SetCommandPrompt("Enter the name/url for the pipe");
                if (_prevPipeName != null)
                {
                    getter.SetDefaultString(_prevPipeName);
                }
                if (getter.Get() != GetResult.String)
                {
                    RhinoApp.WriteLine("Invalid Input");
                    return(getter.CommandResult());
                }
                pipeIdentifier = getter.StringResult();
                _prevPipeName  = pipeIdentifier;
            }

            if (PipeDataUtil.IsValidUrl(pipeIdentifier))
            {
                _pipe = new MyWebPipe(pipeIdentifier);
            }
            else
            {
                _pipe = new LocalNamedPipe(pipeIdentifier);
            }

            _pipe.SetEmitter(this);
            try
            {
                _pipe.Update();
            }
            catch (Exception e)
            {
                Rhino.UI.Dialogs.ShowMessageBox(e.Message, "Error");
            }

            if (_objectsReceived.Count > 0)
            {
                DeletePulledObjects(pipeIdentifier, ref doc);
            }
            List <Guid> received = new List <Guid>();

            foreach (var geom in _objectsReceived)
            {
                Guid id = doc.Objects.Add(geom);
                received.Add(id);
            }
            doc.Views.Redraw();

            SavePulledObjects(pipeIdentifier, received, ref doc);
            return(Result.Success);
        }
Exemplo n.º 5
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                string        pipeId = PipeForRevit.PipeIdentifier;
                UIApplication uiApp  = commandData.Application;
                _document = uiApp.ActiveUIDocument.Document;
                PipeForRevit.ActiveDocument = uiApp.ActiveUIDocument.Document;
                Selection sel = uiApp.ActiveUIDocument.Selection;

                Pipe   pipe     = null;
                Action callBack = () => {
                    if (pipe != null)
                    {
                        pipe.ClosePipe();
                    }
                    RevitPipeUtil.ShowMessage("Success", "Pushed data to the pipe.");
                };
                if (PipeDataUtil.IsValidUrl(pipeId))
                {
                    pipe = new MyWebPipe(pipeId, callBack);
                }
                else
                {
                    pipe = new LocalNamedPipe(pipeId, callBack);
                }
                pipe.SetEmitter(this);
                pipe.Update();

                if (GeometryTypeMatch())
                {
                    bool deleteExisting;
                    bool updateGeom = UserDecidedToUpdateGeometry(out deleteExisting);
                    if (updateGeom)
                    {
                        UpdateGeometry(_receivedObjects);
                    }
                    else
                    {
                        _previousIds = AddObjectsToDocument(_receivedObjects, deleteExisting);
                    }
                }
                else
                {
                    _previousIds = AddObjectsToDocument(_receivedObjects, false);
                }

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                RevitPipeUtil.ShowMessage("Error", "The following error occured. Aborting operation.", e.Message);
                return(Result.Failed);
            }
        }
Exemplo n.º 6
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                string        pipeId = PipeForRevit.PipeIdentifier;
                UIApplication uiApp  = commandData.Application;
                Document      doc    = uiApp.ActiveUIDocument.Document;
                PipeForRevit.ActiveDocument = uiApp.ActiveUIDocument.Document;
                Selection sel = uiApp.ActiveUIDocument.Selection;

                //List<Reference> pickedCurves = sel.PickObjects(ObjectType.Edge, "Select the curves to send through the pipe or click finish to select" +
                //    "elements").ToList();
                List <Reference> picked = sel.PickObjects(ObjectType.Element, "Select the elements to send through the pipe").ToList();
                _selectedObjects = new List <GeometryObject>();
                Options opt = new Options();
                foreach (var objRef in picked)
                {
                    GeometryElement geom = doc.GetElement(objRef).get_Geometry(opt);
                    _selectedObjects.AddRange(geom.Where((g) => g is Solid || g is Mesh));
                }
                //foreach (var objRef in pickedCurves)
                //{
                //    Edge edge = (Edge)doc.GetElement(objRef).GetGeometryObjectFromReference(objRef);
                //    _selectedObjects.Add(edge);
                //}

                Pipe   pipe     = null;
                Action callBack = () => {
                    if (pipe != null)
                    {
                        pipe.ClosePipe();
                    }
                    RevitPipeUtil.ShowMessage("Success", "Pushed data to the pipe.");
                };
                if (PipeDataUtil.IsValidUrl(pipeId))
                {
                    pipe = new MyWebPipe(pipeId, callBack);
                }
                else
                {
                    pipe = new LocalNamedPipe(pipeId, callBack);
                }
                pipe.SetCollector(this);
                pipe.Update();

                return(Result.Succeeded);
            }
            catch (Exception e)
            {
                RevitPipeUtil.ShowMessage("Error", "The following error occured. Aborting operation.", e.Message);
                return(Result.Failed);
            }
        }
Exemplo n.º 7
0
 internal ArcConverter(PointConverter ptConv, VectorConverter vecConv) :
     base(
         (dgarc) => {
     ppg.Plane pl = new ppg.Plane(ptConv.ToPipe <dg.Point, ppg.Vec>(dgarc.CenterPoint));
     return(new ppc.Arc(pl, dgarc.Radius, dgarc.StartAngle, dgarc.StartAngle + dgarc.SweepAngle));
 },
         (pparc) => {
     pparc.TransformToPlane(new ppg.Plane(pparc.Plane.Origin, pparc.Plane.Z));
     return(dg.Arc.ByCenterPointRadiusAngle(ptConv.FromPipe <dg.Point, ppg.Vec>(pparc.Plane.Origin), pparc.Radius,
                                            PipeDataUtil.RadiansToDegrees(pparc.StartAngle), PipeDataUtil.RadiansToDegrees(pparc.EndAngle),
                                            vecConv.FromPipe <dg.Vector, ppg.Vec>(pparc.Plane.Z)));
 }
         )
 { }
Exemplo n.º 8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string pipeIdentifier;

            using (GetString getter = new GetString())
            {
                getter.SetCommandPrompt("Enter the name/url for the pipe");
                if (_prevPipeName != null)
                {
                    getter.SetDefaultString(_prevPipeName);
                }
                if (getter.Get() != GetResult.String)
                {
                    RhinoApp.WriteLine("Invalid Input");
                    return(getter.CommandResult());
                }
                pipeIdentifier = getter.StringResult();
                _prevPipeName  = pipeIdentifier;
            }

            if (_pipe != null)
            {
                _pipe.ClosePipe();
                _pipe = null;
            }

            if (PipeDataUtil.IsValidUrl(pipeIdentifier))
            {
                _pipe = new MyWebPipe(pipeIdentifier);
            }
            else
            {
                _pipe = new LocalNamedPipe(pipeIdentifier);
            }

            _pipe.SetCollector(this);

            _objectsToSend = new List <RhinoObject>();
            using (GetObject getter = new GetObject())
            {
                getter.EnablePreSelect(true, false);
                getter.SetCommandPrompt("Select all the objects to be pushed through the pipe");
                getter.GroupSelect = true;
                getter.GetMultiple(1, 0);
                if (getter.CommandResult() != Result.Success)
                {
                    return(getter.CommandResult());
                }

                for (int i = 0; i < getter.ObjectCount; i++)
                {
                    _objectsToSend.Add(getter.Object(i).Object());
                }
            }

            try
            {
                _pipe.Update();
            }
            catch (Exception e)
            {
                Rhino.UI.Dialogs.ShowMessageBox(e.Message, "Error");
            }

            doc.Views.Redraw();
            return(Result.Success);
        }
Exemplo n.º 9
0
 public bool Equals(Mesh otherMesh)
 {
     return PipeDataUtil.EqualIgnoreOrder(_vertices, otherMesh.Vertices) &&
         PipeDataUtil.Equal(_faces, otherMesh.Faces, (f1, f2) => PipeDataUtil.EqualIgnoreOrder(f1, f2));
 }