コード例 #1
0
 private void PerpFoot()
 {
     if (dimCurve != null) //falls in CurveInput (s.u.) ein Objekt getroffen war
     {
         Plane      pl;
         double     mindist   = double.MaxValue;
         GeoPoint2D footPoint = new GeoPoint2D(0.0, 0.0);
         if (Curves.GetCommonPlane(dim.DimLineRef, dimCurve, out pl))
         {
             ICurve2D c2D = dimCurve.GetProjectedCurve(pl);
             if (c2D is Path2D)
             {
                 (c2D as Path2D).Flatten();
             }
             GeoPoint2D[] perpPoints = c2D.PerpendicularFoot(pl.Project(dim.DimLineRef));
             if (perpPoints.Length > 0)
             {   // eine gültige Kurve ist gefunden
                 for (int j = 0; j < perpPoints.Length; ++j)
                 {
                     double dist = Geometry.Dist(perpPoints[j], pl.Project(dim.DimLineRef));
                     if (dist < mindist)
                     {
                         mindist   = dist;
                         footPoint = perpPoints[j];
                     }
                 }
             }
         }
         if (mindist < double.MaxValue)
         {   // also: Fußpunkt gefunden
             dim.SetPoint(0, pl.ToGlobal(footPoint));
         }
     }
 }
コード例 #2
0
        private bool Recalc()
        {
            Plane      pl;
            GeoPoint2D lotPoint = new GeoPoint2D(0.0, 0.0);

            if (Curves.GetCommonPlane(distPoint, distCurve, out pl))
            {
                ICurve2D curve_2D = distCurve.GetProjectedCurve(pl); // die 2D-Kurve
                if (curve_2D is Path2D)
                {
                    (curve_2D as Path2D).Flatten();
                }
                GeoPoint2D   distPoint2D = pl.Project(distPoint);
                GeoPoint2D[] perpP       = curve_2D.PerpendicularFoot(distPoint2D); // Lotpunkt(e) Kurve
                double       distCP      = double.MaxValue;
                for (int j = 0; j < perpP.Length; ++j)                              // Schleife über alle Lotpunkte Kurve
                {
                    double distLoc = Geometry.Dist(perpP[j], distPoint2D);
                    if (distLoc < distCP)
                    {
                        distCP   = distLoc;
                        lotPoint = perpP[j]; // Lotpunkt schonmal merken
                    }
                }
                if (distCP < double.MaxValue)
                {
                    feedBackLine.SetTwoPoints(distPoint, pl.ToGlobal(lotPoint));
                    if (!feedBackAdd)
                    {
                        base.FeedBack.Add(feedBackLine);
                        feedBackAdd = true;
                    }
                    actualLength = Geometry.Dist(distPoint, pl.ToGlobal(lotPoint));
                    secondPoint  = pl.ToGlobal(lotPoint);
                    using (Frame.Project.Undo.ContextFrame(this))
                    {
                        if (lengthProperty != null)
                        {
                            lengthProperty.SetLength(actualLength);
                        }
                    }
                    return(true);
                }
            }
            if (feedBackAdd)
            {
                base.FeedBack.Remove(feedBackLine);
                feedBackAdd = false;
            }

            using (Frame.Project.Undo.ContextFrame(this))
            {
                if (lengthProperty != null)
                {
                    lengthProperty.SetLength(cancelLength);
                }
            }
            actualLength = 0;
            return(false);
        }
コード例 #3
0
 private double OnCalculateDist(GeoPoint MousePosition)
 {
     if (theBaseCurve != null)
     {
         Plane pln;
         if (theBaseCurve.GetPlanarState() == PlanarState.Planar)
         {
             pln = theBaseCurve.GetPlane();
         }
         else
         {
             pln = base.ActiveDrawingPlane;
         }
         ICurve2D     c2d  = theBaseCurve.GetProjectedCurve(pln);
         GeoPoint2D   p2d  = pln.Project(MousePosition);
         GeoPoint2D[] fp   = c2d.PerpendicularFoot(p2d);
         int          ind  = -1;
         double       mind = double.MaxValue;
         GeoVector2D  dir  = GeoVector2D.XAxis; // muss halt initialisiert sein
         for (int i = 0; i < fp.Length; ++i)
         {
             double d = Geometry.Dist(p2d, fp[i]);
             if (d < mind)
             {
                 mind = d;
                 ind  = i;
                 double pos = c2d.PositionOf(fp[i]);
                 dir = c2d.DirectionAt(pos);
             }
         }
         if (ind >= 0)
         {
             if (Geometry.OnLeftSide(p2d, fp[ind], dir))
             {
                 return(-mind);
             }
             else
             {
                 return(mind);
             }
         }
     }
     return(0.0);
 }
コード例 #4
0
        protected override bool FindTangentialPoint(MouseEventArgs e, IView vw, out GeoPoint found)
        {
            double mindist = double.MaxValue;

            found = GeoPoint.Origin;
            if (CurrentInput == rad && circCenter.Fixed)
            {
                GeoObjectList l = base.GetObjectsUnderCursor(e.Location);
                l.DecomposeBlocks(true);
                l.DecomposeBlockRefs();
                GeoPoint inpoint = base.WorldPoint(e.Location);
                Plane    pln     = vw.Projection.DrawingPlane;
                for (int i = 0; i < l.Count; i++)
                {
                    if (l[i] is ICurve)
                    {
                        ICurve curve = l[i] as ICurve;
                        if (curve.IsInPlane(pln))
                        {
                            ICurve2D     c2d  = curve.GetProjectedCurve(pln);
                            GeoPoint2D   c12d = pln.Project(circle.Center);
                            GeoPoint2D[] pp   = c2d.PerpendicularFoot(c12d);
                            for (int j = 0; j < pp.Length; j++)
                            {
                                GeoPoint p = pln.ToGlobal(pp[j]);
                                double   d = base.WorldPoint(e.Location) | p;
                                if (d < mindist)
                                {
                                    mindist = d;
                                    found   = p;
                                }
                            }
                        }
                    }
                }
            }
            return(mindist != double.MaxValue);
        }
コード例 #5
0
        protected override bool FindTangentialPoint(MouseEventArgs e, IView vw, out GeoPoint found)
        {
            double mindist = double.MaxValue;

            found = GeoPoint.Origin;
            if (CurrentInput == secondPointInput && startPointInput.Fixed)
            {
                GeoObjectList l = base.GetObjectsUnderCursor(e.Location);
                l.DecomposeAll();
                GeoPoint inpoint = base.WorldPoint(e.Location);
                Plane    pln     = vw.Projection.DrawingPlane;
                for (int i = 0; i < l.Count; i++)
                {
                    if (l[i] is ICurve)
                    {
                        ICurve curve = l[i] as ICurve;
                        if (curve.IsInPlane(pln))
                        {
                            ICurve2D     c2d  = curve.GetProjectedCurve(pln);
                            GeoPoint2D   c12d = pln.Project(line.RectangleLocation);
                            GeoPoint2D[] pp   = c2d.PerpendicularFoot(c12d);
                            for (int j = 0; j < pp.Length; j++)
                            {
                                GeoPoint p = pln.ToGlobal(pp[j]);
                                double   d = base.WorldPoint(e.Location) | p;
                                if (d < mindist)
                                {
                                    mindist = d;
                                    found   = p;
                                }
                            }
                        }
                    }
                }
            }
            if (CurrentInput == height && startPointInput.Fixed && secondPointInput.Fixed)
            {
                GeoObjectList l = base.GetObjectsUnderCursor(e.Location);
                l.DecomposeBlocks(true);
                l.DecomposeBlockRefs();
                for (int i = 0; i < l.Count; i++)
                {
                    if (l[i] is ICurve)
                    {
                        double[] tanpos = (l[i] as ICurve).TangentPosition(line.StartDirection);
                        if (tanpos != null)
                        {
                            for (int j = 0; j < tanpos.Length; j++)
                            {
                                GeoPoint p = (l[i] as ICurve).PointAt(tanpos[j]);
                                double   d = base.WorldPoint(e.Location) | p;
                                if (d < mindist)
                                {
                                    mindist = d;
                                    found   = p;
                                }
                            }
                        }
                    }
                }
            }
            return(mindist != double.MaxValue);
        }
コード例 #6
0
        private bool showLine()
        {
            ArrayList usableCurves = new ArrayList(); // lokales Array, das die gültigen Kurven sammelt
            double    mindist      = double.MaxValue;

            for (int i = 0; i < perpCurves.Length; ++i)
            {
                Plane pl;
                if (Curves.GetCommonPlane(startPoint, perpCurves[i], out pl))
                {
                    ICurve2D l2D = perpCurves[i].GetProjectedCurve(pl);
                    if (l2D is Path2D)
                    {
                        (l2D as Path2D).Flatten();
                    }
                    GeoPoint2D[] perpPoints = l2D.PerpendicularFoot(pl.Project(startPoint));
                    if (perpPoints.Length > 0)
                    {   // eine gültige Kurve ist gefunden
                        usableCurves.Add(perpCurves[i]);
                        for (int j = 0; j < perpPoints.Length; ++j)
                        {
                            //							double dist = Geometry.Dist(perpPoints[j],pl.Project(startPoint));
                            double dist = Geometry.Dist(perpPoints[j], pl.Project(objectPoint));
                            if (dist < mindist)
                            {
                                mindist  = dist;
                                selected = usableCurves.Count - 1; // merken, welche Kurve die aktuell benutzte ist
                                endPoint = perpPoints[j];
                            }
                        }
                    }
                    else
                    {   // beim Kreis oder Bogen vom Mittelpunkt aus gilt jeder Punkt
                        if (l2D is Circle2D)
                        {
                            if (Precision.IsEqual((l2D as Circle2D).Center, pl.Project(startPoint)))
                            {
                                GeoPoint2D pp   = l2D.PointAt(l2D.PositionOf(pl.Project(objectPoint)));
                                double     dist = Geometry.Dist(pp, pl.Project(objectPoint));
                                if (dist < mindist)
                                {
                                    mindist  = dist;
                                    selected = usableCurves.Count - 1; // merken, welche Kurve die aktuell benutzte ist
                                    endPoint = pp;
                                }
                            }
                        }
                    }
                }
                if (mindist < double.MaxValue)
                {
                    line.SetTwoPoints(startPoint, pl.ToGlobal(endPoint));
                    perpCurves            = (ICurve[])usableCurves.ToArray(typeof(ICurve)); // perpCurves wird mit den gültigen überschrieben und unten zur Anzeige zurückgegeben an den Sender
                    base.ShowActiveObject = true;
                    return(true);
                }
            }
            line.SetTwoPoints(startPoint, objectPoint);
            base.ShowActiveObject = true;
            return(false);
        }
コード例 #7
0
        private bool showRound()
        {   // jetzt werden die Rundparameter bestimmt
            Plane pl;

            try
            {
                if (Curves.GetCommonPlane(iCurve1, iCurve2, out pl))
                {
                    bool       rndPos    = false; // Runden möglich
                    GeoPoint2D arcP1     = new GeoPoint2D(0.0, 0.0);
                    GeoPoint2D arcP2     = new GeoPoint2D(0.0, 0.0);
                    GeoPoint2D arcP1Loc  = new GeoPoint2D(0.0, 0.0);
                    GeoPoint2D arcP2Loc  = new GeoPoint2D(0.0, 0.0);
                    GeoPoint2D arcCenter = new GeoPoint2D(0.0, 0.0);
                    ICurve2D   curve1_2D = iCurve1.GetProjectedCurve(pl); // die 2D-Kurven
                    if (curve1_2D is Path2D)
                    {
                        (curve1_2D as Path2D).Flatten();
                    }
                    ICurve2D curve2_2D = iCurve2.GetProjectedCurve(pl);
                    if (curve2_2D is Path2D)
                    {
                        (curve2_2D as Path2D).Flatten();
                    }

                    // ist beim menrfachrunden nicht nötig!!
                    // hier die Schnittpunkte bestimmen und den ObjectPoint auf den nächsten Schnittpunt setzen
                    //				GeoPoint2DWithParameter[] intersectPoints = curve1_2D.Intersect(curve2_2D);
                    //				GeoPoint2D objectPoint2D = new GeoPoint2D(0.0,0.0);
                    //				double distS = double.MaxValue; // Entfernung des Pickpunkts zu den Schnittpunkten
                    //				for (int i=0; i< intersectPoints.Length; ++i) // macht hier wenig Sinn, schadet aber auch nicht
                    //				{ // macht hier wenig Sinn, schadet aber auch nicht, Kompatibilität zum einfachrunden
                    //					double distLoc = Geometry.dist(intersectPoints[i].p,pl.Project(objectPoint));
                    //					if (distLoc < distS)
                    //					{
                    //						distS = distLoc;
                    //						objectPoint2D = intersectPoints[i].p; // Pickpunkt  merken
                    //					}
                    //				}

                    // statt der Berechnung oben: Auswahlpunkt ist der gemeinsame Punkt der beiden Kurven!!
                    GeoPoint2D objectPoint2D = curve1_2D.EndPoint;



                    double locmin1, locmin2; // Parametergrenzen vorbesetzen für den Fall: Realer Schnittpunkt
                    locmin1 = 0.0;           // Parametergrenzen vorbesetzen für den Fall: Realer Schnittpunkt
                    locmin2 = 0.0;           // Parametergrenzen vorbesetzen für den Fall: Realer Schnittpunkt
                    double locmax1, locmax2; // Parametergrenzen vorbesetzen für den Fall: Realer Schnittpunkt
                    locmax1 = 1.0;
                    locmax2 = 1.0;

                    // bei mehfachrunden nicht nötig, da alle aneinanderhängen, also nur reale Schnittpunkte!
                    //				double locPar; // für den Fall: virtueller Schnittpunkt die Parametergrenzen anpassen
                    //				locPar = curve1_2D.PositionOf(objectPoint2D); // position des Schnittpunktes auf der Kurve1
                    //				if ( locPar > 1.0) locmax1 = locPar;
                    //				if ( locPar < 0.0) locmin1 = locPar;
                    //				locPar = curve2_2D.PositionOf(objectPoint2D); // position des Schnittpunktes auf der Kurve2
                    //				if ( locPar > 1.0) locmax2 = locPar;
                    //				if ( locPar < 0.0) locmin2 = locPar;

                    // die Parallelen links und rechts der 2 Kurven
                    ICurve2D P1L1 = curve1_2D.Parallel(roundRad, false, 0.0, 0.0);
                    ICurve2D P1L2 = curve1_2D.Parallel(-roundRad, false, 0.0, 0.0);
                    ICurve2D P2L1 = curve2_2D.Parallel(roundRad, false, 0.0, 0.0);
                    ICurve2D P2L2 = curve2_2D.Parallel(-roundRad, false, 0.0, 0.0);
                    // nun alle mit allen schneiden und Schnittpunkte (=evtl. Mittelpunkte des Bogens) merken
                    ArrayList centers = new ArrayList();
                    centers.AddRange(P1L1.Intersect(P2L1));
                    centers.AddRange(P1L1.Intersect(P2L2));
                    centers.AddRange(P1L2.Intersect(P2L1));
                    centers.AddRange(P1L2.Intersect(P2L2));
                    GeoPoint2DWithParameter[] centerPoints = (GeoPoint2DWithParameter[])centers.ToArray(typeof(GeoPoint2DWithParameter));
                    GeoPoint2D[] perpP;                    // Lotfusspunkte
                    double       loc;                      // location des schnittpunktes der parallelen auf der Kurve
                    double       distCP;                   // Entfernung von der Ecke für Fusspunkte
                    double       distCS = double.MaxValue; // Entfernung von der Ecke für Schnittpunkte
                    bool         ok1, ok2;
                    // der gesuchte Schnittpunkt hat einen realen Lotfusspunkt auf beiden Kurven und den Abstand roundRad von diesen
                    for (int i = 0; i < centerPoints.Length; ++i) // Schleife über alle Schnittpunkte
                    {
                        ok1    = false;
                        ok2    = false;
                        perpP  = curve1_2D.PerpendicularFoot(centerPoints[i].p); // Lotpunkt(e) Kurve 1
                        distCP = double.MaxValue;
                        for (int j = 0; j < perpP.Length; ++j)                   // Schleife über alle Lotpunkte Kurve 1
                        {
                            loc = curve1_2D.PositionOf(perpP[j]);                // der Parameter des j. Lotpunktes auf Kurve1
                            // der Parameter muss innerhalb der Kurve sein und der Abstand = roundRad
                            if ((loc >= locmin1) & (loc <= locmax1) & (Math.Abs(Geometry.Dist(perpP[j], centerPoints[i].p) - roundRad) < Precision.eps))
                            {
                                double distLoc = Geometry.Dist(perpP[j], objectPoint2D);
                                if (distLoc < distCP)
                                {
                                    distCP   = distLoc;
                                    arcP1Loc = perpP[j]; // Lotpunkt schonmal merken
                                }
                                ok1 = true;
                            }
                        }
                        if (ok1)                                                     // also was gefunden oben, jetzt dasselbe mit Kurve 2
                        {
                            perpP  = curve2_2D.PerpendicularFoot(centerPoints[i].p); // Lotpunkt(e) Kurve 2
                            distCP = double.MaxValue;
                            for (int j = 0; j < perpP.Length; ++j)                   // Schleife über alle Lotpunkte Kurve 2
                            {
                                loc = curve2_2D.PositionOf(perpP[j]);                // der Parameter des j. Lotpunktes auf Kurve2
                                // der Parameter muss innerhalb der Kurve sein und der Abstand = roundRad
                                if ((loc >= locmin2) & (loc <= locmax2) & (Math.Abs(Geometry.Dist(perpP[j], centerPoints[i].p) - roundRad) < Precision.eps))
                                {
                                    double distLoc = Geometry.Dist(perpP[j], objectPoint2D);
                                    if (distLoc < distCP)
                                    {
                                        distCP   = distLoc;
                                        arcP2Loc = perpP[j]; // Lotpunkt schonmal merken
                                    }
                                    ok2 = true;
                                }
                            }
                        }
                        if (ok2)
                        {       // falls mehrere Schnittpunkte alle Bedingungen erfüllen: Den nächsten nehmen!
                            double distLoc = Geometry.Dist(centerPoints[i].p, objectPoint2D);
                            if (distLoc < distCS)
                            {
                                distCS = distLoc;
                                // jetzt merken
                                arcCenter = centerPoints[i].p;
                                arcP1     = arcP1Loc;
                                arcP2     = arcP2Loc;
                                rndPos    = true;
                            }
                        }
                    }
                    if (rndPos && !Precision.IsEqual(arcP1, arcP2)) // runden war möglich
                    {                                               // Mittelwert zwischen dem Kurven
                        //					roundRadCalc = (Math.Abs(curve1_2D.Distance(pl.Project(radiusPoint))) + Math.Abs(curve2_2D.Distance(pl.Project(radiusPoint)))) / 2.0;
                        objectPoint = pl.ToGlobal(objectPoint2D);   // merken als Entscheidungskriterium, ist hier immer der Schnittpunkt
                        Ellipse arc  = Ellipse.Construct();
                        Ellipse arc1 = Ellipse.Construct();
                        arc.SetArcPlaneCenterStartEndPoint(base.ActiveDrawingPlane, arcCenter, arcP1, arcP2, pl, false);
                        arc1.SetArcPlaneCenterStartEndPoint(base.ActiveDrawingPlane, arcCenter, arcP1, arcP2, pl, true);
                        if (Math.Abs(arc.SweepParameter) > Math.Abs(arc1.SweepParameter)) // es ist immer der kleinere Bogen!
                        {
                            arc = arc1;
                        }
                        arc.CopyAttributes(iCurve1 as IGeoObject);
                        if (iCurve1.PositionOf(objectPoint) > 0.5)
                        {
                            iCurve1.Trim(0.0, iCurve1.PositionOf(arc.StartPoint));
                        }
                        else
                        {
                            iCurve1.Trim(iCurve1.PositionOf(arc.StartPoint), 1.0);
                        }
                        if (iCurve2.PositionOf(objectPoint) > 0.5)
                        {
                            iCurve2.Trim(0.0, iCurve2.PositionOf(arc.EndPoint));
                        }
                        else
                        {
                            iCurve2.Trim(iCurve2.PositionOf(arc.EndPoint), 1.0);
                        }
                        if (iCurve1.Length > Precision.eps)
                        {
                            blk.Add(iCurve1 as IGeoObject);
                            //                        base.FeedBack.AddSelected(iCurve1 as IGeoObject); // darstellen
                        }
                        blk.Add(arc);
                        //                    base.FeedBack.AddSelected(arc); // darstellen
                        iCurve1 = iCurve2; // getrimmte Curve2 als Grundlage zur nächsten Berechnung
                        return(true);
                    }
                }
            }
            catch (ApplicationException e)
            {
                return(false);
            }
            blk.Add(iCurve1 as IGeoObject); // unveränderte 1. Kurve zufügen, da kein Runden möglich
                                            //            base.FeedBack.AddSelected(iCurve1 as IGeoObject); // darstellen
            iCurve1 = iCurve2;              // unveränderte Curve2 als Grundlage zur nächsten Berechnung
            return(false);
        }