Exemplo n.º 1
0
        BCOM.Element CreatePileCrossSectionElement(IPileProperty pileprop)
        {
            //double uorpermaster = app.ActiveModelReference.UORsPerMasterUnit;
            BCOM.Matrix3d m         = app.Matrix3dIdentity();
            BCOM.Point3d  centroidp = pileprop.PileTopPoint.Point3dToBCOMPoint3d(1e4 / uorpermaster);
            centroidp.Z = 0; // xy平面
            double pilediameter = pileprop.PileDiameter * 1e4 / uorpermaster;
            int    colorindex   = 3;

            if ((pileprop is SquarePileGeometry) || (pileprop is SquarePileGeometry))
            {
                BCOM.Point3d[] squarvertexs =
                {
                    app.Point3dFromXY(pilediameter / 2,  pilediameter / 2),
                    app.Point3dFromXY(-pilediameter / 2, pilediameter / 2),
                    app.Point3dFromXY(-pilediameter / 2, -pilediameter / 2),
                    app.Point3dFromXY(pilediameter / 2, -pilediameter / 2)
                };
                BCOM.ShapeElement shape = app.CreateShapeElement1(null, ref squarvertexs, BCOM.MsdFillMode.NotFilled);
                shape.Move(ref centroidp);
                shape.Color = colorindex;
                return(shape);
            }
            else
            {
                var c = app.CreateEllipseElement2(null, ref centroidp, pilediameter / 2, pilediameter / 2, ref m, BCOM.MsdFillMode.NotFilled);
                c.Color = colorindex;
                return(c);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Open a 3D View
        /// </summary>
        /// <param name="v"></param>
        private void doOpen3DView(VisualizationInfo v)
        {
            try
            {
                if (MSApp.ActiveModelReference.Type != MsdModelType.Normal)
                {
                    MessageBox.Show("This operation is not allowed in paper space.\nPlease go to model space and retry.",
                                    "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                Point3d cameraPos, viewDirection, upVector;
                double  zoomValue;

                // IS ORTHOGONAL
                if (v.OrthogonalCamera != null)
                {
                    if (v.OrthogonalCamera.CameraViewPoint == null || v.OrthogonalCamera.CameraUpVector == null || v.OrthogonalCamera.CameraDirection == null)
                    {
                        return;
                    }

                    cameraPos     = MSApp.Point3dFromXYZ(v.OrthogonalCamera.CameraViewPoint.X, v.OrthogonalCamera.CameraViewPoint.Y, v.OrthogonalCamera.CameraViewPoint.Z);
                    viewDirection = MSApp.Point3dNormalize(MSApp.Point3dFromXYZ(v.OrthogonalCamera.CameraDirection.X, v.OrthogonalCamera.CameraDirection.Y, v.OrthogonalCamera.CameraDirection.Z));
                    upVector      = MSApp.Point3dNormalize(MSApp.Point3dFromXYZ(v.OrthogonalCamera.CameraUpVector.X, v.OrthogonalCamera.CameraUpVector.Y, v.OrthogonalCamera.CameraUpVector.Z));
                    zoomValue     = v.OrthogonalCamera.ViewToWorldScale;
                }
                else if (v.PerspectiveCamera != null)
                {
                    if (v.PerspectiveCamera.CameraViewPoint == null || v.PerspectiveCamera.CameraUpVector == null || v.PerspectiveCamera.CameraDirection == null)
                    {
                        return;
                    }

                    cameraPos     = MSApp.Point3dFromXYZ(v.PerspectiveCamera.CameraViewPoint.X, v.PerspectiveCamera.CameraViewPoint.Y, v.PerspectiveCamera.CameraViewPoint.Z);
                    viewDirection = MSApp.Point3dNormalize(MSApp.Point3dFromXYZ(v.PerspectiveCamera.CameraDirection.X, v.PerspectiveCamera.CameraDirection.Y, v.PerspectiveCamera.CameraDirection.Z));
                    upVector      = MSApp.Point3dNormalize(MSApp.Point3dFromXYZ(v.PerspectiveCamera.CameraUpVector.X, v.PerspectiveCamera.CameraUpVector.Y, v.PerspectiveCamera.CameraUpVector.Z));
                    zoomValue     = v.PerspectiveCamera.FieldOfView;
                }
                else
                {
                    MessageBox.Show("No camera information was found within this viewpoint.",
                                    "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                // get current view
                int    activeViewNum = getActiveViewNumber();
                View   currentView   = MSApp.ActiveDesignFile.Views[activeViewNum];
                double unitFactor    = GetGunits();

                // set camera properties
                Point3d scaledCameraPos    = MSApp.Point3dScale(cameraPos, unitFactor);
                Point3d scaledCameraTarget = MSApp.Point3dAdd(scaledCameraPos, MSApp.Point3dScale(viewDirection, unitFactor));
                currentView.set_CameraPosition(scaledCameraPos);
                currentView.set_CameraTarget(scaledCameraTarget);
                currentView.set_Center(scaledCameraTarget);
                currentView.set_CameraUpVector(upVector);
                MSApp.CadInputQueue.SendKeyin("MDL KEYIN BENTLEY.VIEWATTRIBUTESDIALOG,VAD VIEWATTRIBUTESDIALOG SETATTRIBUTE 0 Camera False");
                if (v.PerspectiveCamera != null)
                {
                    currentView.CameraAngle = zoomValue * unitFactor;
                }
                else if (v.OrthogonalCamera != null)
                {
                    Point3d currentExtent = currentView.get_Extents();
                    double  zoomLevel     = zoomValue * unitFactor * customZoomLevel / currentExtent.Y;
                    currentView.Zoom(zoomLevel);
                }

                // disable and clear previous clip volume
                ulong previousClipVolumeId = 0;
                try
                {
                    int status = mdlView_getClipBoundaryElement(ref previousClipVolumeId, activeViewNum - 1).ToInt32();
                    if (status == 0)
                    {
                        Element previousClipVolume = MSApp.ActiveModelReference.GetElementByID((long)previousClipVolumeId);
                        MSApp.ActiveModelReference.RemoveElement(previousClipVolume);
                    }
                }
                catch (Exception ex)
                {
                    // do nothing just for catching the exception when clip volume not found
                }
                currentView.ClipVolume = false;

                // handle model view clipping
                if (v.ClippingPlanes != null)
                {
                    List <Plane3d> clippingPlanes = new List <Plane3d>();
                    foreach (var clippingPlane in v.ClippingPlanes)
                    {
                        clippingPlanes.Add(new Plane3d()
                        {
                            Origin = MSApp.Point3dFromXYZ(clippingPlane.Location.X, clippingPlane.Location.Y, clippingPlane.Location.Z),
                            Normal = MSApp.Point3dFromXYZ(clippingPlane.Direction.X, clippingPlane.Direction.Y, clippingPlane.Direction.Z)
                        });
                    }
                    List <Point3d> intersectionPoints = getIntersectionPointsOfClippingPlanes(clippingPlanes);
                    if (intersectionPoints != null)
                    {
                        double maxZ         = intersectionPoints.Max(p => p.Z);
                        double minZ         = intersectionPoints.Min(p => p.Z);
                        double midZ         = (maxZ + minZ) / 2;
                        double halfOfHeight = (maxZ - minZ) / 2;
                        // find XY projection points
                        List <Vector2d> planeVertices = new List <Vector2d>();
                        foreach (Point3d p in intersectionPoints)
                        {
                            bool uniqueProjectionPoint = true;
                            foreach (Vector2d vertex in planeVertices)
                            {
                                if (MSApp.Point2dDistance(new Point2d()
                                {
                                    X = vertex.X, Y = vertex.Y
                                }, new Point2d()
                                {
                                    X = p.X, Y = p.Y
                                }) < distancePrecision)                                                                                                          // arbitrary precision for now
                                {
                                    uniqueProjectionPoint = false;
                                    break;
                                }
                            }

                            if (uniqueProjectionPoint)
                            {
                                planeVertices.Add(new Vector2d(p.X, p.Y));
                            }
                        }
                        // determine convex hull points
                        var convexNullPoints = ConvexHullHelper.MonotoneChainConvexHull(planeVertices.ToArray()).Select(p => new Point3d()
                        {
                            X = p.X, Y = p.Y, Z = midZ
                        });
                        ShapeElement planeShape = MSApp.CreateShapeElement1(null, convexNullPoints.ToArray(), MsdFillMode.UseActive);
                        MSApp.ActiveModelReference.AddElement(planeShape);

                        // produce solid
                        Point3d firstVertex = planeShape.get_Vertex(1);
#if connect
                        MSApp.CadInputQueue.SendKeyin("CONSTRUCT SURFACE PROJECTIONSOLID ");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.nonParametric", 1, "SOLIDMODELING");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidSkewed", 0, "SOLIDMODELING");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidIsDist", 1, "SOLIDMODELING");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrudeSolidDistance", (MSApp.ActiveModelReference.UORsPerMasterUnit * halfOfHeight), "SOLIDMODELING");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidBothWays", 1, "SOLIDMODELING");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrudeSolidYScale", 1, "SOLIDMODELING");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrudeSolidXScale", 1, "SOLIDMODELING");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidActiveAttib", 0, "SOLIDMODELING");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidKeepOriginal", 0, "SOLIDMODELING");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrudeSolidSpinAng", 0, "SOLIDMODELING");
                        MSApp.CadInputQueue.SendKeyin("CONSTRUCT SURFACE PROJECTIONSOLID ");
#elif select
                        MSApp.CadInputQueue.SendCommand("CONSTRUCT SURFACE PROJECTIONSOLID");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidSkewed", 0, "3DTOOLS");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidIsDist", 1, "3DTOOLS");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrudeSolidDistance", (MSApp.ActiveModelReference.UORsPerMasterUnit * halfOfHeight), "3DTOOLS");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidBothWays", 1, "3DTOOLS");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrudeSolidYScale", 1, "3DTOOLS");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrudeSolidXScale", 1, "3DTOOLS");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidActiveAttib", 0, "3DTOOLS");
                        MSApp.SetCExpressionValue("tcb->ms3DToolSettings.extrude.solidKeepOriginal", 0, "3DTOOLS");
                        MSApp.CadInputQueue.SendDataPoint(firstVertex, activeViewNum);
                        MSApp.CadInputQueue.SendDataPoint(firstVertex, activeViewNum);
#endif
                        MSApp.CadInputQueue.SendDataPoint(firstVertex, activeViewNum);
                        MSApp.CadInputQueue.SendDataPoint(firstVertex, activeViewNum);

                        // clip volume
                        MSApp.CadInputQueue.SendCommand("VIEW CLIP SINGLE");
                        MSApp.SetCExpressionValue("tcb->msToolSettings.clipViewTools.hideClipElement", 1, "CLIPVIEW");
                        MSApp.CadInputQueue.SendDataPoint(firstVertex, activeViewNum);
                        MSApp.CadInputQueue.SendDataPoint(firstVertex, activeViewNum);
                    }
                }

                // handle BCF components
                MSApp.ActiveModelReference.UnselectAllElements();
                selectElements(v.Components);

                // redraw current view
                currentView.Redraw();
                MSApp.CommandState.StartDefaultCommand();
            }
            catch (System.Exception ex1)
            {
                MessageBox.Show("exception: " + ex1, "Error!");
            }
        }