Пример #1
0
        /// <summary>
        /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.PositionOf (GeoPoint)"/>
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public override GeoPoint2D PositionOf(GeoPoint p)
        {
            if (basisCurve.GetPlanarState() == PlanarState.Planar)
            {
                Plane cp = basisCurve.GetPlane();
                // ICurve2D c2d = basisCurve.GetProjectedCurve(cp); wird nicht benötigt
                if (Precision.IsPerpendicular(cp.Normal, direction, false))
                {
                }
                else
                {
                    GeoPoint pp = cp.Intersect(p, direction); // direction darf natürlich nicht in der Ebene der Kurve liegen
                    double   u  = basisCurve.PositionOf(pp);
                    double   v  = Geometry.LinePar(basisCurve.PointAt(u), direction, p);
#if DEBUG
                    //GeoPoint2D dbg1 = base.PositionOf(p);
                    //GeoPoint2D dbg2 = new GeoPoint2D(curveStartParameter + u * (curveEndParameter - curveStartParameter), v);
                    //if ((dbg1 | dbg2) > 1e-6)
                    //{
                    //    throw new ApplicationException("error in SurfaceOfLinearExtrusion.PositionOf");
                    //}
#endif
                    return(new GeoPoint2D(curveStartParameter + u * (curveEndParameter - curveStartParameter), v));
                }
            }
            Plane    pl        = new Plane(basisCurve.StartPoint, direction);
            ICurve2D projected = basisCurve.GetProjectedCurve(pl);
            double   uu        = projected.PositionOf(pl.Project(p)); // assuming the projected curve and the basisCurve have the same parameter space (which is true for NURBS)
            GeoPoint start     = basisCurve.PointAt(uu);
            double   vv        = Geometry.LinePar(start, direction, p);
            return(new GeoPoint2D(uu, vv));
            // GeoPoint2D res = base.PositionOf(p);
            // return res;
        }
Пример #2
0
        /// <summary>
        /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.GetPlaneIntersection (PlaneSurface, double, double, double, double, double)"/>
        /// </summary>
        /// <param name="pl"></param>
        /// <param name="umin"></param>
        /// <param name="umax"></param>
        /// <param name="vmin"></param>
        /// <param name="vmax"></param>
        /// <param name="precision"></param>
        /// <returns></returns>
        public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision)
        {
            if (Precision.IsPerpendicular(pl.Plane.Normal, direction, false))
            {   // Ebene, die parallel zur Auszugsrichtung liegt. Es entstehen Linien
                List <IDualSurfaceCurve> res = new List <IDualSurfaceCurve>();
                double[] cpar = basisCurve.GetPlaneIntersection(pl.Plane);
                for (int i = 0; i < cpar.Length; i++)
                {
                    // von 0..1 auf startParameter..endParameter umrechnen
                    double pos = curveStartParameter + cpar[i] * (curveEndParameter - curveStartParameter);
                    if (pos >= umin && pos <= umax)
                    {
                        ICurve           c3d = FixedU(pos, vmin, vmax);
                        Line2D           l2d = new Line2D(new GeoPoint2D(pos, vmin), new GeoPoint2D(pos, vmax));
                        DualSurfaceCurve dsc = new DualSurfaceCurve(c3d, this, l2d, pl, c3d.GetProjectedCurve(pl.Plane));
                        res.Add(dsc);
                    }
                }
                return(res.ToArray());
                //return new IDualSurfaceCurve[] { };
                //return base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision); // stürzt ab mit 50050020_012_1_FMZ.stp
            }
            else if (Precision.SameDirection(direction, pl.Plane.Normal, false))
            {
                if (basisCurve.GetPlanarState() == PlanarState.Planar && Precision.SameDirection(direction, basisCurve.GetPlane().Normal, false))
                {
                    Plane cp = basisCurve.GetPlane();
                    if (!Precision.SameNotOppositeDirection(cp.Normal, direction))
                    {
                        cp = new Plane(cp.Location, cp.DirectionY, cp.DirectionX);
                    }
                    double           v   = cp.Distance(pl.Plane.Location) / direction.Length;
                    Line2D           l2d = new Line2D(new GeoPoint2D(curveStartParameter, v), new GeoPoint2D(curveEndParameter, v));
                    DualSurfaceCurve dsc = new DualSurfaceCurve(basisCurve.CloneModified(ModOp.Translate(v * direction)), this, l2d, pl, basisCurve.GetProjectedCurve(pl.Plane));
                    return(new IDualSurfaceCurve[] { dsc });
                }
            }
            // keine Lösung gefunden
            double[] upos = basisCurve.GetSavePositions();
            InterpolatedDualSurfaceCurve.SurfacePoint[] sp = new InterpolatedDualSurfaceCurve.SurfacePoint[upos.Length];
            for (int i = 0; i < upos.Length; ++i)
            {
                GeoPoint     p0  = basisCurve.PointAt(upos[i]);
                double       pos = curveStartParameter + upos[i] * (curveEndParameter - curveStartParameter);
                GeoPoint2D[] ips = pl.GetLineIntersection(p0, direction);
                if (ips.Length == 1)
                {
                    GeoPoint p3d = pl.PointAt(ips[0]);
                    double   v   = Geometry.LinePar(p0, direction, p3d);
                    sp[i] = new InterpolatedDualSurfaceCurve.SurfacePoint(p3d, new GeoPoint2D(pos, v), ips[0]);
                }
            }
            InterpolatedDualSurfaceCurve idsc = new InterpolatedDualSurfaceCurve(this, pl, sp, true);

            return(new IDualSurfaceCurve[] { idsc.ToDualSurfaceCurve() });
            //return base.GetPlaneIntersection(pl, umin, umax, vmin, vmax, precision);
        }
Пример #3
0
        public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision)
        {
            if (Precision.IsPerpendicular(pl.Normal, zAxis, false))
            {
                // two lines along the cylinder axis
                Plane               lower = new Plane(location, zAxis);
                GeoPoint2D          sp2d  = lower.Project(pl.Location);
                GeoVector2D         dir2d = lower.Project(pl.Normal).ToLeft();
                GeoPoint2D[]        ips   = Geometry.IntersectLC(sp2d, dir2d, GeoPoint2D.Origin, xAxis.Length);
                IDualSurfaceCurve[] res   = new IDualSurfaceCurve[ips.Length];
                for (int i = 0; i < ips.Length; i++)
                {
                    GeoPoint p   = lower.ToGlobal(ips[i]);
                    Line     l3d = Line.TwoPoints(p, p + zAxis);
                    res[i] = new DualSurfaceCurve(l3d, this, new Line2D(this.PositionOf(l3d.StartPoint), this.PositionOf(l3d.EndPoint)), pl, new Line2D(pl.PositionOf(l3d.StartPoint), pl.PositionOf(l3d.EndPoint)));
                }
                return(res);
            }
            else
            {
                // an ellipse
                GeoPoint2D[] cnts = pl.GetLineIntersection(location, zAxis);
                if (cnts.Length == 1)
                {   // there must be exactly one intersection
                    GeoPoint  cnt       = pl.PointAt(cnts[0]);
                    GeoVector minorAxis = pl.Normal ^ zAxis;
                    minorAxis.Length = xAxis.Length;
                    GeoVector majorAxis = minorAxis ^ pl.Normal;
                    Polynom   impl      = GetImplicitPolynomial();
                    Polynom   toSolve   = impl.Substitute(new Polynom(majorAxis.x, "u", cnt.x, ""), new Polynom(majorAxis.y, "u", cnt.y, ""), new Polynom(majorAxis.z, "u", cnt.z, ""));
                    double[]  roots     = toSolve.Roots();
                    // there must be two roots
                    majorAxis = roots[0] * majorAxis;

                    Ellipse elli = Ellipse.Construct();
                    elli.SetEllipseCenterAxis(cnt, majorAxis, minorAxis);

                    GeoPoint2D[] fpnts = new GeoPoint2D[5];
                    for (int i = 0; i < 5; i++)
                    {
                        fpnts[i] = PositionOf(elli.PointAt(i / 6.0));
                    }
                    Ellipse2D e2d = Ellipse2D.FromFivePoints(fpnts); // there should be a better way to calculate the 2d ellipse, but the following is wrong:
                    // Ellipse2D e2d = new Ellipse2D(GeoPoint2D.Origin, PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector());
                    // and principal axis doesn't yield the correct result either
                    // Geometry.PrincipalAxis(PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector(), out GeoVector2D maj, out GeoVector2D min);
                    return(new IDualSurfaceCurve[] { new DualSurfaceCurve(elli, this, e2d, pl, pl.GetProjectedCurve(elli, 0.0)) });
                }
            }
            return(new IDualSurfaceCurve[0]);
        }
Пример #4
0
        private void OnDrawingPlaneDone(ConstructAction ca, bool success)
        {
            if (!success)
            {
                return;
            }
            frame.ShowPropertyDisplay("View");
            if (propertyTreeView != null)
            {
                propertyTreeView.SelectEntry(this);
            }
            Plane          pln = Plane.XYPlane;
            ConstructPlane cp  = ca as ConstructPlane;

            if (ca is ConstructPlane)
            {
                pln = (ca as ConstructPlane).ConstructedPlane;
            }
            else if (ca is ConstructTangentialPlane)
            {
                pln = (ca as ConstructTangentialPlane).ConstructedPlane;
            }
            else
            {
                return;
            }
            try
            {
                if (!Precision.IsPerpendicular(projection.Direction, pln.Normal, false))
                {
                    projection.DrawingPlane = pln;
                }
                else
                {
                    Frame.UIService.ShowMessageBox(StringTable.GetString("Error.DrawingPlane.Impossible"), StringTable.GetString("Errormessage.Title.InvalidInput"), MessageBoxButtons.OK);
                }
            }
            catch (ConstructPlane.ConstructPlaneException)
            {   // hat aus irgend einem Grund nicht geklappt
                Frame.UIService.ShowMessageBox(StringTable.GetString("Error.DrawingPlane.Impossible"), StringTable.GetString("Errormessage.Title.InvalidInput"), MessageBoxButtons.OK);
            }
            planeOrigin.Refresh();
            planeDirectionX.Refresh();
            planeDirectionY.Refresh();
            frame.ActiveView.InvalidateAll();
            frame.SetControlCenterFocus("View", null, false, false);
        }
Пример #5
0
        private GeoVectorHotSpot dirWidthHotSpot, dirHeightHotSpot; // Hotspot für Richtung

        public ShowPropertyPicture(Picture picture, IFrame Frame) : base(Frame)
        {
            this.picture        = picture;
            attributeProperties = picture.GetAttributeProperties(Frame);
            base.resourceId     = "Picture.Object";

            location = new GeoPointProperty("Picture.Location", Frame, true);
            location.GetGeoPointEvent     += new CADability.UserInterface.GeoPointProperty.GetGeoPointDelegate(OnGetRefPoint);
            location.SetGeoPointEvent     += new CADability.UserInterface.GeoPointProperty.SetGeoPointDelegate(OnSetRefPoint);
            location.ModifyWithMouseEvent += new ModifyWithMouseDelegate(OnModifyLocationWithMouse);
            width = new LengthProperty("Picture.Width", Frame, true);
            width.GetLengthEvent += new LengthProperty.GetLengthDelegate(OnGetWidth);
            width.SetLengthEvent += new LengthProperty.SetLengthDelegate(OnSetWidth);
            height = new LengthProperty("Picture.Height", Frame, true);
            height.GetLengthEvent += new LengthProperty.GetLengthDelegate(OnGetHeight);
            height.SetLengthEvent += new LengthProperty.SetLengthDelegate(OnSetHeight);
            dirWidth = new GeoVectorProperty("Picture.DirWidth", Frame, true);
            dirWidth.GetGeoVectorEvent    += new GeoVectorProperty.GetGeoVectorDelegate(OnGetDirWidth);
            dirWidth.SetGeoVectorEvent    += new GeoVectorProperty.SetGeoVectorDelegate(OnSetDirWidth);
            dirWidth.ModifyWithMouseEvent += new ModifyWithMouseDelegate(OnModifyDirWidthWithMouse);
            dirHeight = new GeoVectorProperty("Picture.DirHeight", Frame, true);
            dirHeight.GetGeoVectorEvent    += new GeoVectorProperty.GetGeoVectorDelegate(OnGetDirHeight);
            dirHeight.SetGeoVectorEvent    += new GeoVectorProperty.SetGeoVectorDelegate(OnSetDirHeight);
            dirHeight.ModifyWithMouseEvent += new ModifyWithMouseDelegate(OnModifyDirHeightWithMouse);
            path = new StringProperty(picture.Path, "Picture.Path");
            path.GetStringEvent += new StringProperty.GetStringDelegate(OnGetPath);
            path.SetStringEvent += new StringProperty.SetStringDelegate(OnSetPath);
            path.SetContextMenu("MenuId.Picture.Path", this);
            keepAspectRatio = new BooleanProperty("Picture.KeepAspectRatio", "YesNo.Values");
            double p = picture.DirectionWidth.Length / picture.Bitmap.Width * picture.Bitmap.Height / picture.DirectionHeight.Length;

            keepAspectRatio.BooleanValue         = Math.Abs(1.0 - p) < 1e-6;
            keepAspectRatio.BooleanChangedEvent += new BooleanChangedDelegate(OnKeepAspectRatioChanged);
            rectangular = new BooleanProperty("Picture.Rectangular", "YesNo.Values");
            rectangular.BooleanValue         = Precision.IsPerpendicular(picture.DirectionWidth, picture.DirectionHeight, false);
            rectangular.BooleanChangedEvent += new BooleanChangedDelegate(OnRectangularChanged);
            dirWidthHotSpot           = new GeoVectorHotSpot(dirWidth);
            dirWidthHotSpot.Position  = picture.Location + picture.DirectionWidth;
            dirHeightHotSpot          = new GeoVectorHotSpot(dirHeight);
            dirHeightHotSpot.Position = picture.Location + picture.DirectionHeight;
        }
Пример #6
0
        public override void OnSetAction()
        {
            if (defaultText == null)
            {
                text                = Text.Construct();
                text.TextString     = StringTable.GetString("Text.Default");
                text.LineDirection  = base.ActiveDrawingPlane.DirectionX;
                text.GlyphDirection = base.ActiveDrawingPlane.DirectionY;
                text.TextSize       = ConstrDefaults.DefaultTextSize;
                text.Font           = "Arial";
            }
            else
            {
                text = defaultText.Clone() as Text;
            }
            if (!Precision.IsPerpendicular(ActiveDrawingPlane.Normal, text.LineDirection, false) || !Precision.IsPerpendicular(ActiveDrawingPlane.Normal, text.GlyphDirection, false))
            {   // die DrawingPlane wurde seit dem letzten Text geändert
                text.LineDirection  = base.ActiveDrawingPlane.DirectionX;
                text.GlyphDirection = base.ActiveDrawingPlane.DirectionY;
            }

            base.ActiveObject = text;

            base.TitleId = "Constr.Text.1Point";

            GeoPointInput startPointInput = new GeoPointInput("Text.StartPoint");

            startPointInput.DefaultGeoPoint   = ConstrDefaults.DefaultStartPoint;
            startPointInput.DefinesBasePoint  = true;
            startPointInput.SetGeoPointEvent += new ConstructAction.GeoPointInput.SetGeoPointDelegate(StartPoint);

            EditInput editInput = new EditInput(text);

            base.SetInput(startPointInput, editInput);
            base.ShowAttributes = true;

            base.OnSetAction();
        }
Пример #7
0
 public override bool IsExtruded(GeoVector direction)
 {
     return(Precision.IsPerpendicular(Normal, direction, false));
 }
Пример #8
0
 /// <summary>
 /// Overrides <see cref="CADability.GeoObject.ISurfaceImpl.IsVanishingProjection (Projection, double, double, double, double)"/>
 /// </summary>
 /// <param name="p"></param>
 /// <param name="umin"></param>
 /// <param name="umax"></param>
 /// <param name="vmin"></param>
 /// <param name="vmax"></param>
 /// <returns></returns>
 public override bool IsVanishingProjection(Projection p, double umin, double umax, double vmin, double vmax)
 {
     return(Precision.IsPerpendicular(p.Direction, fromUnitPlane * GeoVector.ZAxis, false));
 }