public crossLube(myRectangle obl, double width, double depth)
        {
            double cornerX = Math.Cos(Math.PI-Math.PI/2-Math.Atan2(obl.B,obl.A))*width;
            double cornerY = Math.Sin(Math.PI-Math.PI/2-Math.Atan2(obl.B,obl.A))*width;

            p1 = new double[] {obl.P1x+cornerX,			obl.P1y };
            p2 = null;
            p3 = new double[] {obl.P2x-cornerX,			obl.P1y};
            p4 = new double[] {obl.P2x,					obl.P1y+cornerY};
            p5 = null;
            p6 = new double[] {obl.P2x,					obl.P2y-cornerY};
            p7 = new double[] {obl.P2x-cornerX,			obl.P2y};
            p8 = null;
            p9 = new double[] {obl.P1x+cornerX,			obl.P2y  };
            p10 = new double[] {obl.P1x,				obl.P2y-cornerY };
            p11 = null;
            p12 = new double[] {obl.P1x,				obl.P1y+cornerY};

            p2 = new double[] {intersection(p1,p6,p3,p10)[0],intersection(p1,p6,p3,p10)[1]};
            p5 = new double[] {intersection(p4,p9,p1,p6)[0],intersection(p4,p9,p1,p6)[1]};
            p8 = new double[] {intersection(p12,p7,p4,p9)[0],intersection(p12,p7,p4,p9)[1]};
            p11 = new double[] {intersection(p12,p7,p3,p10)[0],intersection(p12,p7,p3,p10)[1]};

            this.width = width;
            this.depth = depth;
        }
        public ZigZagLube(myRectangle obl, double width, double depth)
        {
            this.width = width;
            this.depth = depth;

            if (obl.A<=obl.B) {

                double uhel = Math.Atan2(obl.B/3,obl.A);
                double cornerX = Math.Cos(Math.PI-Math.PI/2-uhel)*width;
                double cornerY = Math.Sin(Math.PI-Math.PI/2-uhel)*width;

                p1 = new double[] {obl.P1x+cornerX,					obl.P1y };
                p2 = new double[] {obl.P2x,							obl.P1y+obl.B/3};
                p3 = new double[] {obl.P1x+width/(Math.Sin(uhel)),	obl.P2y-obl.B/3};
                p4 = new double[] {obl.P2x,							obl.P2y-cornerY};
                p5 = new double[] {obl.P2x-cornerX,					obl.P2y};
                p6 = new double[] {obl.P1x,							obl.P2y-obl.B/3};
                p7 = new double[] {obl.P2x-width/(Math.Sin(uhel)),	obl.P1y+obl.B/3};
                p8 = new double[] {obl.P1x,							obl.P1y+cornerY};
            } else {

                double uhel = Math.Atan2(obl.A/3,obl.B);
                double cornerX = Math.Sin(Math.PI-Math.PI/2-uhel)*width;
                double cornerY = Math.Cos(Math.PI-Math.PI/2-uhel)*width;

                p1 = new double[] {obl.P1x,					obl.P1y+cornerY };
                p2 = new double[] {obl.P1x+obl.A/3,			obl.P2y};
                p3 = new double[] {obl.P2x-obl.A/3,			obl.P1y+width/(Math.Sin(uhel))};
                p4 = new double[] {obl.P2x-cornerX,			obl.P2y};
                p5 = new double[] {obl.P2x,					obl.P2y-cornerY};
                p6 = new double[] {obl.P2x-obl.A/3,			obl.P1y};
                p7 = new double[] {obl.P1x+obl.A/3,			obl.P2y-width/(Math.Sin(uhel))};
                p8 = new double[] {obl.P1x+cornerX,			obl.P1y};
            }
        }
示例#3
0
        public crossLube(myRectangle obl, double width, double depth)
        {
            double cornerX = Math.Cos(Math.PI - Math.PI / 2 - Math.Atan2(obl.B, obl.A)) * width;
            double cornerY = Math.Sin(Math.PI - Math.PI / 2 - Math.Atan2(obl.B, obl.A)) * width;

            p1  = new double[] { obl.P1x + cornerX, obl.P1y };
            p2  = null;
            p3  = new double[] { obl.P2x - cornerX, obl.P1y };
            p4  = new double[] { obl.P2x, obl.P1y + cornerY };
            p5  = null;
            p6  = new double[] { obl.P2x, obl.P2y - cornerY };
            p7  = new double[] { obl.P2x - cornerX, obl.P2y };
            p8  = null;
            p9  = new double[] { obl.P1x + cornerX, obl.P2y };
            p10 = new double[] { obl.P1x, obl.P2y - cornerY };
            p11 = null;
            p12 = new double[] { obl.P1x, obl.P1y + cornerY };

            p2  = new double[] { intersection(p1, p6, p3, p10)[0], intersection(p1, p6, p3, p10)[1] };
            p5  = new double[] { intersection(p4, p9, p1, p6)[0], intersection(p4, p9, p1, p6)[1] };
            p8  = new double[] { intersection(p12, p7, p4, p9)[0], intersection(p12, p7, p4, p9)[1] };
            p11 = new double[] { intersection(p12, p7, p3, p10)[0], intersection(p12, p7, p3, p10)[1] };

            this.width = width;
            this.depth = depth;
        }
        /// <param name="direction">accepting params: {R, L, B, T}</param>
        /// <returns>If leaked = True</returns>
        public static bool inflationLoop(inflateDirection direction, myRectangle obl, List <double[]> linesListDouble, double inflate, double initilaArea, double maxInflateArea)
        {
            if (direction == inflateDirection.R)
            {
                while (!obl.inflateRightWillCross(linesListDouble, inflate))
                {
                    obl.inflateRigth(inflate);
                    if (obl.obsah > maxInflateArea)
                    {
                        return(true);
                    }
                }
            }
            if (direction == inflateDirection.L)
            {
                while (!obl.inflateLeftWillCross(linesListDouble, inflate))
                {
                    obl.inflateLeft(inflate);
                    if (obl.obsah > maxInflateArea)
                    {
                        return(true);
                    }
                }
            }
            if (direction == inflateDirection.B)
            {
                while (!obl.inflateBottomWillCross(linesListDouble, inflate))
                {
                    obl.inflateBottom(inflate);
                    if (obl.obsah > maxInflateArea)
                    {
                        return(true);
                    }
                }
            }
            if (direction == inflateDirection.T)
            {
                while (!obl.inflateTopWillCross(linesListDouble, inflate))
                {
                    obl.inflateTop(inflate);
                    if (obl.obsah > maxInflateArea)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public static myRectangle optimalMaxAndABRatio(List <myRectangle> inputList)
        {
            inputList = inputList.OrderBy(o => o.obsah).ToList();
            inputList.Reverse();

            myRectangle winner = inputList[0];

            foreach (myRectangle obl in inputList)
            {
                if (obl != winner && obl.obsah >= winner.obsah * 0.75 && Math.Max(obl.A, obl.B) * 0.5 > Math.Max(winner.A, winner.B) && obl.ABRatio > 0.1)
                {
                    winner = obl;
                }
            }

            return(winner);
        }
        /// <param name="direction">accepting params: {R, L, B, T}</param>
        /// <returns>If leaked = True</returns>
        public static bool inflationLoop(inflateDirection direction, myRectangle obl, List<double[]> linesListDouble, double inflate, double initilaArea,double maxInflateArea)
        {
            if (direction==inflateDirection.R) {
                while (!obl.inflateRightWillCross(linesListDouble,inflate)) {
                    obl.inflateRigth(inflate);
                    if (obl.obsah>maxInflateArea) {
                        return true;
                    }
                }
            }
            if (direction==inflateDirection.L) {
                while (!obl.inflateLeftWillCross(linesListDouble,inflate)) {
                    obl.inflateLeft(inflate);
                    if (obl.obsah>maxInflateArea) {
                        return true;
                    }
                }
            }
            if (direction==inflateDirection.B) {
                while (!obl.inflateBottomWillCross(linesListDouble,inflate)) {
                    obl.inflateBottom(inflate);
                    if (obl.obsah>maxInflateArea) {
                        return true;
                    }
                }
            }
            if (direction==inflateDirection.T) {
                while (!obl.inflateTopWillCross(linesListDouble,inflate)) {
                    obl.inflateTop(inflate);
                    if (obl.obsah>maxInflateArea) {
                        return true;
                    }
                }
            }

            return false;
        }
示例#7
0
        public ZigZagLube(myRectangle obl, double width, double depth)
        {
            this.width = width;
            this.depth = depth;

            if (obl.A <= obl.B)
            {
                double uhel    = Math.Atan2(obl.B / 3, obl.A);
                double cornerX = Math.Cos(Math.PI - Math.PI / 2 - uhel) * width;
                double cornerY = Math.Sin(Math.PI - Math.PI / 2 - uhel) * width;

                p1 = new double[] { obl.P1x + cornerX, obl.P1y };
                p2 = new double[] { obl.P2x, obl.P1y + obl.B / 3 };
                p3 = new double[] { obl.P1x + width / (Math.Sin(uhel)), obl.P2y - obl.B / 3 };
                p4 = new double[] { obl.P2x, obl.P2y - cornerY };
                p5 = new double[] { obl.P2x - cornerX, obl.P2y };
                p6 = new double[] { obl.P1x, obl.P2y - obl.B / 3 };
                p7 = new double[] { obl.P2x - width / (Math.Sin(uhel)), obl.P1y + obl.B / 3 };
                p8 = new double[] { obl.P1x, obl.P1y + cornerY };
            }
            else
            {
                double uhel    = Math.Atan2(obl.A / 3, obl.B);
                double cornerX = Math.Sin(Math.PI - Math.PI / 2 - uhel) * width;
                double cornerY = Math.Cos(Math.PI - Math.PI / 2 - uhel) * width;

                p1 = new double[] { obl.P1x, obl.P1y + cornerY };
                p2 = new double[] { obl.P1x + obl.A / 3, obl.P2y };
                p3 = new double[] { obl.P2x - obl.A / 3, obl.P1y + width / (Math.Sin(uhel)) };
                p4 = new double[] { obl.P2x - cornerX, obl.P2y };
                p5 = new double[] { obl.P2x, obl.P2y - cornerY };
                p6 = new double[] { obl.P2x - obl.A / 3, obl.P1y };
                p7 = new double[] { obl.P1x + obl.A / 3, obl.P2y - width / (Math.Sin(uhel)) };
                p8 = new double[] { obl.P1x + cornerX, obl.P1y };
            }
        }
        static void action(PlanarfaceWithReference cpl)
        {
            //all try
              	try {

              	pointsListDouble.Clear();
            linesListDouble.Clear();

              	oPartDocument.Selection.Clear();
              	oPartDocument.Selection.Add(cpl.OPlanarFace);
               	MECMOD.Body oBody = (MECMOD.Body)oPartDocument.Selection.FindObject("CATIAShape").Parent;
            MECMOD.Part oPart = (MECMOD.Part)oBody.Parent;

            MECMOD.Sketch oSketch = oBody.Sketches.Add(cpl.OReference);
            MECMOD.Factory2D oFactory2D = oSketch.OpenEdition();

            oFactory2D.CreateProjection(cpl.OReference);
            oSketch.CloseEdition();

            oPart.Update();
            oPartDocument.Selection.Clear();

            List<object[]> pointsListObjects = new List<object[]>();
            List<MECMOD.Point2D> mecmodPointsForRemoveList = new List<MECMOD.Point2D>();
            List<object[]> linesListObjects = new List<object[]>();
            List<INFITF.AnyObject> mecmodlineForRemoveList = new List<INFITF.AnyObject>();

               string sketchOriginName = oSketch.get_Name();
               oSketch.set_Name(oSketch.get_Name()+ "_Isolate_me_please.");

            oPart.Update();
            oPartDocument.Selection.Add(oSketch);

            if (isolateKeyAuto) {
                SupportClass.isolateKeyAuto();
            }

            bool isolate = false;
            int timeout = 60;
            const int sleep = 1000;
            while (!isolate) {
                catiaInstance.set_StatusBar("Isolate the sketch "+oSketch.get_Name() +" "+(timeout*1000)/sleep + "s timeout");
                Thread.Sleep(sleep);
                if (timeout<=0) {
                    catiaInstance.set_StatusBar("Macro timeout");
                    oPartDocument.Selection.Clear();
                    oPartDocument.Selection.Add(oSketch);
                    oPartDocument.Selection.Delete();
                    return;
                }
                timeout--;
                try {
                    foreach (MECMOD.GeometricElement geo in oSketch.GeometricElements) {
                        if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypePoint2D) {
                            MECMOD.Point2D oPoint = (MECMOD.Point2D)geo;
                            isolate = true;
                            object[] oPointArray = new object[2];
                            oPoint.GetCoordinates(oPointArray);
                            pointsListObjects.Add(oPointArray);
                            mecmodPointsForRemoveList.Add(oPoint);
                        }
                        if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeLine2D) {
                            MECMOD.Line2D oLine = (MECMOD.Line2D)geo;
                            isolate = true;
                            object[] oPointArray = new object[4];
                            oLine.GetEndPoints(oPointArray);
                            linesListObjects.Add(oPointArray);
                            mecmodlineForRemoveList.Add(oLine);
                        }
                        //NOT fully solved! Just gets endpoints and connets them by a line.
                        if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeCircle2D) {
                            MECMOD.Circle2D oCircle = (MECMOD.Circle2D)geo;
                            isolate = true;
                            object[] oPointArray = new object[4];
                            oCircle.GetEndPoints(oPointArray);
                            linesListObjects.Add(oPointArray);
                            mecmodlineForRemoveList.Add(oCircle);
                        }
                        //NOT fully solved! Just gets endpoints and connets them by a line.
                        if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeEllipse2D) {
                            MECMOD.Ellipse2D oElipse = (MECMOD.Ellipse2D)geo;
                            isolate = true;
                            object[] oPointArray = new object[4];
                            oElipse.GetEndPoints(oPointArray);
                            linesListObjects.Add(oPointArray);
                            mecmodlineForRemoveList.Add(oElipse);
                        }
                        //NOT fully solved! Just gets endpoints and connets them by a line.
                        if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeHyperbola2D) {
                            MECMOD.Hyperbola2D oHyp = (MECMOD.Hyperbola2D)geo;
                            isolate = true;
                            object[] oPointArray = new object[4];
                            oHyp.GetEndPoints(oPointArray);
                            linesListObjects.Add(oPointArray);
                            mecmodlineForRemoveList.Add(oHyp);
                        }
                        //NOT fully solved! Just gets endpoints and connets them by a line.
                        if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeParabola2D) {
                            MECMOD.Parabola2D oParab = (MECMOD.Parabola2D)geo;
                            isolate = true;
                            object[] oPointArray = new object[4];
                            oParab.GetEndPoints(oPointArray);
                            linesListObjects.Add(oPointArray);
                            mecmodlineForRemoveList.Add(oParab);
                        }
                        //NOT fully solved! Just gets endpoints and connets them by a line.
                        if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeSpline2D) {
                            MECMOD.Spline2D oSpline = (MECMOD.Spline2D)geo;
                            isolate = true;
                            object[] oPointArray = new object[4];
                            oSpline.GetEndPoints(oPointArray);
                            linesListObjects.Add(oPointArray);
                            mecmodlineForRemoveList.Add(oSpline);
                        }
                        //?????????????????????????????
                        if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeUnknown) {
                            MECMOD.Curve2D o = (MECMOD.Curve2D)geo;
                            isolate = true;
                            object[] oPointArray = new object[4];
                            o.GetEndPoints(oPointArray);
                            linesListObjects.Add(oPointArray);
                            mecmodlineForRemoveList.Add(o);
                        }

                    }
                } catch {    }
            }

            oSketch.set_Name(sketchOriginName);
            oPart.Update();

            oFactory2D = oSketch.OpenEdition();
            oPartDocument.Selection.Clear();
            foreach (MECMOD.Point2D p in mecmodPointsForRemoveList) {
                oPartDocument.Selection.Add(p);
            }
               foreach (INFITF.AnyObject l in mecmodlineForRemoveList) {
                oPartDocument.Selection.Add(l);
            }
            oPartDocument.Selection.Delete();
            oSketch.CloseEdition();

            oPart.Update();

            foreach (object[] point in pointsListObjects) {
                pointsListDouble.Add(new double[] {Double.Parse(point[0].ToString()),Double.Parse(point[1].ToString())});
            }

            foreach (object[] line in linesListObjects) {
                linesListDouble.Add(new double[] {Double.Parse(line[0].ToString()),Double.Parse(line[1].ToString()),Double.Parse(line[2].ToString()),Double.Parse(line[3].ToString())});
            }

            double minX = pointsListDouble.Min(setting => setting[0]);
            double maxX = pointsListDouble.Max(setting => setting[0]);
            double minY = pointsListDouble.Min(setting => setting[1]);
            double maxY = pointsListDouble.Max(setting => setting[1]);
            const double delitel = 20;

            double rastrX = (Math.Abs(maxX-minX))/delitel;
            if (rastrX<0.1) {
                rastrX = 0.1;
            }

            double rastrY = (Math.Abs(maxY-minY))/delitel;
            if (rastrY<0.1) {
                rastrY = 0.1;
            }

            List<myRectangle> allRectanglesInThisLimit = new List<myRectangle>();

            double rastrXvalue = minX;
            double rastrYvalue = minY;
            while (rastrYvalue<maxY) {
                while (rastrXvalue<maxX) {
                    myRectangle rastrInsideLim = new myRectangle(rastrXvalue,rastrYvalue,rastrXvalue+rastrX,rastrYvalue+rastrY);
                    allRectanglesInThisLimit.Add(rastrInsideLim);
                    rastrXvalue += rastrX;
                }
                rastrXvalue = minX;
                rastrYvalue += rastrY;
            }

            List<myRectangle> allRectanglesInThisLimitNoZero = new List<myRectangle>();
            foreach (myRectangle obl in allRectanglesInThisLimit) {
                if (obl.obsah!=0) {
                    obl.resizeAllEdges(-Math.Min(rastrX,rastrY)*0.1);
                    allRectanglesInThisLimitNoZero.Add(obl);
                }
            }

            List<myRectangle> allRectanglesInThisLimitNoCross = new List<myRectangle>();
            foreach (myRectangle obl2 in allRectanglesInThisLimitNoZero) {
                if (!obl2.anyLineFromListCrossRectangle(linesListDouble)) {
                    allRectanglesInThisLimitNoCross.Add(obl2);
                }
            }

            if (debugRastr) {
                DebugCreateAll.createAll(allRectanglesInThisLimitNoCross,oSketch,catiaInstance);
            }

            double inflateX = rastrX/10;
            double inflateY = rastrY/10;
            double maxInflateAreaEdge = Math.Max(Math.Abs(maxX-minX)+rastrX,Math.Abs(maxY-minY)+rastrY);
            double maxInflateArea = maxInflateAreaEdge*maxInflateAreaEdge;
            List<myRectangle> maxRectanglesListIflatedNoLeak = new List<myRectangle>();
            int count = 1;
            foreach (myRectangle obl in allRectanglesInThisLimitNoCross) {
                obl.resizeAllEdges(-Math.Min(rastrX,rastrY)*0.1);
                bool leaked = false;
                if (count==1 ) {
                    double initilaArea = obl.obsah;
                    leaked = SupportClass.inflationLoop(SupportClass.inflateDirection.B,obl,linesListDouble,inflateY,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.R,obl,linesListDouble,inflateX,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.T,obl,linesListDouble,inflateY,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.L,obl,linesListDouble,inflateX,initilaArea,maxInflateArea);
                }
                if (count==2 ) {
                    double initilaArea = obl.obsah;
                    leaked = SupportClass.inflationLoop(SupportClass.inflateDirection.T,obl,linesListDouble,inflateY,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.L,obl,linesListDouble,inflateX,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.B,obl,linesListDouble,inflateY,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.R,obl,linesListDouble,inflateX,initilaArea,maxInflateArea);
                }
                if (count==3 ) {
                    double initilaArea = obl.obsah;
                    leaked =  SupportClass.inflationLoop(SupportClass.inflateDirection.R,obl,linesListDouble,inflateX,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.T,obl,linesListDouble,inflateY,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.L,obl,linesListDouble,inflateX,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.B,obl,linesListDouble,inflateY,initilaArea,maxInflateArea);
                }
                if (count==4 ) {
                    double initilaArea = obl.obsah;
                    leaked =  SupportClass.inflationLoop(SupportClass.inflateDirection.L,obl,linesListDouble,inflateX,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.B,obl,linesListDouble,inflateY,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.R,obl,linesListDouble,inflateX,initilaArea,maxInflateArea)
                    || SupportClass.inflationLoop(SupportClass.inflateDirection.T,obl,linesListDouble,inflateY,initilaArea,maxInflateArea);
                }
                if (!leaked) {
                    if (type==grooveType.Cross&&Math.Min(obl.A,obl.B)>width*2) {
                        maxRectanglesListIflatedNoLeak.Add(obl);
                    }
                    if (type==grooveType.ZigZag&&Math.Min(obl.A,obl.B)>width*3) {
                        maxRectanglesListIflatedNoLeak.Add(obl);
                    }
                 }

                count++;
                if (count>4) {
                    count = 1;
                }
            }

            if (debugInflated) {
                DebugCreateAll.createAll(maxRectanglesListIflatedNoLeak,oSketch,catiaInstance);
            }

            List<myRectangle> maxRectangleListIflatedNoLeakEdgesResized = new List<myRectangle>();
            foreach (myRectangle obl in maxRectanglesListIflatedNoLeak) {
                obl.resizeAllEdges(-edges);
                if (obl.obsah>0) {
                    maxRectangleListIflatedNoLeakEdgesResized.Add(obl);
                }
            }

            double finalP1x = 0;
            double finalP1y = 0;
            double finalP2x = 0;
            double finalP2y = 0;

            myRectangle win = null;
            if (maxRectangleListIflatedNoLeakEdgesResized.Count>0) {

                win = SupportClass.optimalMaxAndABRatio(maxRectangleListIflatedNoLeakEdgesResized);

                finalP1x = Math.Round( win.P1x,1);
                finalP1y =  Math.Round(win.P1y,1);
                finalP2x =  Math.Round(win.P2x,1);
                finalP2y =  Math.Round(win.P2y,1);

                myRectangle finalRectangle = new myRectangle(finalP1x,finalP1y,finalP2x,finalP2y);
                crossLube finalcrossLube = new crossLube(finalRectangle,width,depth);
                ZigZagLube finalZigZagLube = new ZigZagLube(finalRectangle,width,depth);

                oPart.Update();
                oFactory2D = oSketch.OpenEdition();

                if (type==grooveType.ZigZag) {
                    finalZigZagLube.toSketch(oFactory2D);
                } else {
                    finalcrossLube.toSketch(oFactory2D);
                }

                oSketch.CloseEdition();
                oPart.Update();

                if (debugInflated||debugRastr) {
                    return;
                }

                oPart.InWorkObject = oSketch;

                PARTITF.ShapeFactory oShapeFactory = (PARTITF.ShapeFactory)oPart.ShapeFactory;
                PARTITF.Pocket oNewPadPlus = oShapeFactory.AddNewPocket ( oSketch, finalcrossLube.Depth);

                oPart.Update();
            } else {
                MainForm.myForm.Activate();
                MessageBox.Show(@"Groove for the face will not be created!
            Area si too small.");
            }

            //all catch
              	}catch{}
        }
示例#9
0
        static void action(PlanarfaceWithReference cpl)
        {
            //all try
            try {
                pointsListDouble.Clear();
                linesListDouble.Clear();

                oPartDocument.Selection.Clear();
                oPartDocument.Selection.Add(cpl.OPlanarFace);
                MECMOD.Body oBody = (MECMOD.Body)oPartDocument.Selection.FindObject("CATIAShape").Parent;
                MECMOD.Part oPart = (MECMOD.Part)oBody.Parent;

                MECMOD.Sketch    oSketch    = oBody.Sketches.Add(cpl.OReference);
                MECMOD.Factory2D oFactory2D = oSketch.OpenEdition();

                oFactory2D.CreateProjection(cpl.OReference);
                oSketch.CloseEdition();

                oPart.Update();
                oPartDocument.Selection.Clear();

                List <object[]>         pointsListObjects         = new List <object[]>();
                List <MECMOD.Point2D>   mecmodPointsForRemoveList = new List <MECMOD.Point2D>();
                List <object[]>         linesListObjects          = new List <object[]>();
                List <INFITF.AnyObject> mecmodlineForRemoveList   = new List <INFITF.AnyObject>();

                string sketchOriginName = oSketch.get_Name();
                oSketch.set_Name(oSketch.get_Name() + "_Isolate_me_please.");

                oPart.Update();
                oPartDocument.Selection.Add(oSketch);

                if (isolateKeyAuto)
                {
                    SupportClass.isolateKeyAuto();
                }

                bool      isolate = false;
                int       timeout = 60;
                const int sleep   = 1000;
                while (!isolate)
                {
                    catiaInstance.set_StatusBar("Isolate the sketch " + oSketch.get_Name() + " " + (timeout * 1000) / sleep + "s timeout");
                    Thread.Sleep(sleep);
                    if (timeout <= 0)
                    {
                        catiaInstance.set_StatusBar("Macro timeout");
                        oPartDocument.Selection.Clear();
                        oPartDocument.Selection.Add(oSketch);
                        oPartDocument.Selection.Delete();
                        return;
                    }
                    timeout--;
                    try {
                        foreach (MECMOD.GeometricElement geo in oSketch.GeometricElements)
                        {
                            if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypePoint2D)
                            {
                                MECMOD.Point2D oPoint = (MECMOD.Point2D)geo;
                                isolate = true;
                                object[] oPointArray = new object[2];
                                oPoint.GetCoordinates(oPointArray);
                                pointsListObjects.Add(oPointArray);
                                mecmodPointsForRemoveList.Add(oPoint);
                            }
                            if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeLine2D)
                            {
                                MECMOD.Line2D oLine = (MECMOD.Line2D)geo;
                                isolate = true;
                                object[] oPointArray = new object[4];
                                oLine.GetEndPoints(oPointArray);
                                linesListObjects.Add(oPointArray);
                                mecmodlineForRemoveList.Add(oLine);
                            }
                            //NOT fully solved! Just gets endpoints and connets them by a line.
                            if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeCircle2D)
                            {
                                MECMOD.Circle2D oCircle = (MECMOD.Circle2D)geo;
                                isolate = true;
                                object[] oPointArray = new object[4];
                                oCircle.GetEndPoints(oPointArray);
                                linesListObjects.Add(oPointArray);
                                mecmodlineForRemoveList.Add(oCircle);
                            }
                            //NOT fully solved! Just gets endpoints and connets them by a line.
                            if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeEllipse2D)
                            {
                                MECMOD.Ellipse2D oElipse = (MECMOD.Ellipse2D)geo;
                                isolate = true;
                                object[] oPointArray = new object[4];
                                oElipse.GetEndPoints(oPointArray);
                                linesListObjects.Add(oPointArray);
                                mecmodlineForRemoveList.Add(oElipse);
                            }
                            //NOT fully solved! Just gets endpoints and connets them by a line.
                            if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeHyperbola2D)
                            {
                                MECMOD.Hyperbola2D oHyp = (MECMOD.Hyperbola2D)geo;
                                isolate = true;
                                object[] oPointArray = new object[4];
                                oHyp.GetEndPoints(oPointArray);
                                linesListObjects.Add(oPointArray);
                                mecmodlineForRemoveList.Add(oHyp);
                            }
                            //NOT fully solved! Just gets endpoints and connets them by a line.
                            if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeParabola2D)
                            {
                                MECMOD.Parabola2D oParab = (MECMOD.Parabola2D)geo;
                                isolate = true;
                                object[] oPointArray = new object[4];
                                oParab.GetEndPoints(oPointArray);
                                linesListObjects.Add(oPointArray);
                                mecmodlineForRemoveList.Add(oParab);
                            }
                            //NOT fully solved! Just gets endpoints and connets them by a line.
                            if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeSpline2D)
                            {
                                MECMOD.Spline2D oSpline = (MECMOD.Spline2D)geo;
                                isolate = true;
                                object[] oPointArray = new object[4];
                                oSpline.GetEndPoints(oPointArray);
                                linesListObjects.Add(oPointArray);
                                mecmodlineForRemoveList.Add(oSpline);
                            }
                            //?????????????????????????????
                            if (geo.GeometricType == MECMOD.CatGeometricType.catGeoTypeUnknown)
                            {
                                MECMOD.Curve2D o = (MECMOD.Curve2D)geo;
                                isolate = true;
                                object[] oPointArray = new object[4];
                                o.GetEndPoints(oPointArray);
                                linesListObjects.Add(oPointArray);
                                mecmodlineForRemoveList.Add(o);
                            }
                        }
                    } catch {    }
                }

                oSketch.set_Name(sketchOriginName);
                oPart.Update();

                oFactory2D = oSketch.OpenEdition();
                oPartDocument.Selection.Clear();
                foreach (MECMOD.Point2D p in mecmodPointsForRemoveList)
                {
                    oPartDocument.Selection.Add(p);
                }
                foreach (INFITF.AnyObject l in mecmodlineForRemoveList)
                {
                    oPartDocument.Selection.Add(l);
                }
                oPartDocument.Selection.Delete();
                oSketch.CloseEdition();

                oPart.Update();

                foreach (object[] point in pointsListObjects)
                {
                    pointsListDouble.Add(new double[] { Double.Parse(point[0].ToString()), Double.Parse(point[1].ToString()) });
                }

                foreach (object[] line in linesListObjects)
                {
                    linesListDouble.Add(new double[] { Double.Parse(line[0].ToString()), Double.Parse(line[1].ToString()), Double.Parse(line[2].ToString()), Double.Parse(line[3].ToString()) });
                }

                double       minX    = pointsListDouble.Min(setting => setting[0]);
                double       maxX    = pointsListDouble.Max(setting => setting[0]);
                double       minY    = pointsListDouble.Min(setting => setting[1]);
                double       maxY    = pointsListDouble.Max(setting => setting[1]);
                const double delitel = 20;

                double rastrX = (Math.Abs(maxX - minX)) / delitel;
                if (rastrX < 0.1)
                {
                    rastrX = 0.1;
                }

                double rastrY = (Math.Abs(maxY - minY)) / delitel;
                if (rastrY < 0.1)
                {
                    rastrY = 0.1;
                }

                List <myRectangle> allRectanglesInThisLimit = new List <myRectangle>();

                double rastrXvalue = minX;
                double rastrYvalue = minY;
                while (rastrYvalue < maxY)
                {
                    while (rastrXvalue < maxX)
                    {
                        myRectangle rastrInsideLim = new myRectangle(rastrXvalue, rastrYvalue, rastrXvalue + rastrX, rastrYvalue + rastrY);
                        allRectanglesInThisLimit.Add(rastrInsideLim);
                        rastrXvalue += rastrX;
                    }
                    rastrXvalue  = minX;
                    rastrYvalue += rastrY;
                }

                List <myRectangle> allRectanglesInThisLimitNoZero = new List <myRectangle>();
                foreach (myRectangle obl in allRectanglesInThisLimit)
                {
                    if (obl.obsah != 0)
                    {
                        obl.resizeAllEdges(-Math.Min(rastrX, rastrY) * 0.1);
                        allRectanglesInThisLimitNoZero.Add(obl);
                    }
                }

                List <myRectangle> allRectanglesInThisLimitNoCross = new List <myRectangle>();
                foreach (myRectangle obl2 in allRectanglesInThisLimitNoZero)
                {
                    if (!obl2.anyLineFromListCrossRectangle(linesListDouble))
                    {
                        allRectanglesInThisLimitNoCross.Add(obl2);
                    }
                }

                if (debugRastr)
                {
                    DebugCreateAll.createAll(allRectanglesInThisLimitNoCross, oSketch, catiaInstance);
                }



                double             inflateX                       = rastrX / 10;
                double             inflateY                       = rastrY / 10;
                double             maxInflateAreaEdge             = Math.Max(Math.Abs(maxX - minX) + rastrX, Math.Abs(maxY - minY) + rastrY);
                double             maxInflateArea                 = maxInflateAreaEdge * maxInflateAreaEdge;
                List <myRectangle> maxRectanglesListIflatedNoLeak = new List <myRectangle>();
                int count = 1;
                foreach (myRectangle obl in allRectanglesInThisLimitNoCross)
                {
                    obl.resizeAllEdges(-Math.Min(rastrX, rastrY) * 0.1);
                    bool leaked = false;
                    if (count == 1)
                    {
                        double initilaArea = obl.obsah;
                        leaked = SupportClass.inflationLoop(SupportClass.inflateDirection.B, obl, linesListDouble, inflateY, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.R, obl, linesListDouble, inflateX, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.T, obl, linesListDouble, inflateY, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.L, obl, linesListDouble, inflateX, initilaArea, maxInflateArea);
                    }
                    if (count == 2)
                    {
                        double initilaArea = obl.obsah;
                        leaked = SupportClass.inflationLoop(SupportClass.inflateDirection.T, obl, linesListDouble, inflateY, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.L, obl, linesListDouble, inflateX, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.B, obl, linesListDouble, inflateY, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.R, obl, linesListDouble, inflateX, initilaArea, maxInflateArea);
                    }
                    if (count == 3)
                    {
                        double initilaArea = obl.obsah;
                        leaked = SupportClass.inflationLoop(SupportClass.inflateDirection.R, obl, linesListDouble, inflateX, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.T, obl, linesListDouble, inflateY, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.L, obl, linesListDouble, inflateX, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.B, obl, linesListDouble, inflateY, initilaArea, maxInflateArea);
                    }
                    if (count == 4)
                    {
                        double initilaArea = obl.obsah;
                        leaked = SupportClass.inflationLoop(SupportClass.inflateDirection.L, obl, linesListDouble, inflateX, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.B, obl, linesListDouble, inflateY, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.R, obl, linesListDouble, inflateX, initilaArea, maxInflateArea) ||
                                 SupportClass.inflationLoop(SupportClass.inflateDirection.T, obl, linesListDouble, inflateY, initilaArea, maxInflateArea);
                    }
                    if (!leaked)
                    {
                        if (type == grooveType.Cross && Math.Min(obl.A, obl.B) > width * 2)
                        {
                            maxRectanglesListIflatedNoLeak.Add(obl);
                        }
                        if (type == grooveType.ZigZag && Math.Min(obl.A, obl.B) > width * 3)
                        {
                            maxRectanglesListIflatedNoLeak.Add(obl);
                        }
                    }

                    count++;
                    if (count > 4)
                    {
                        count = 1;
                    }
                }

                if (debugInflated)
                {
                    DebugCreateAll.createAll(maxRectanglesListIflatedNoLeak, oSketch, catiaInstance);
                }

                List <myRectangle> maxRectangleListIflatedNoLeakEdgesResized = new List <myRectangle>();
                foreach (myRectangle obl in maxRectanglesListIflatedNoLeak)
                {
                    obl.resizeAllEdges(-edges);
                    if (obl.obsah > 0)
                    {
                        maxRectangleListIflatedNoLeakEdgesResized.Add(obl);
                    }
                }

                double finalP1x = 0;
                double finalP1y = 0;
                double finalP2x = 0;
                double finalP2y = 0;

                myRectangle win = null;
                if (maxRectangleListIflatedNoLeakEdgesResized.Count > 0)
                {
                    win = SupportClass.optimalMaxAndABRatio(maxRectangleListIflatedNoLeakEdgesResized);

                    finalP1x = Math.Round(win.P1x, 1);
                    finalP1y = Math.Round(win.P1y, 1);
                    finalP2x = Math.Round(win.P2x, 1);
                    finalP2y = Math.Round(win.P2y, 1);

                    myRectangle finalRectangle  = new myRectangle(finalP1x, finalP1y, finalP2x, finalP2y);
                    crossLube   finalcrossLube  = new crossLube(finalRectangle, width, depth);
                    ZigZagLube  finalZigZagLube = new ZigZagLube(finalRectangle, width, depth);

                    oPart.Update();
                    oFactory2D = oSketch.OpenEdition();

                    if (type == grooveType.ZigZag)
                    {
                        finalZigZagLube.toSketch(oFactory2D);
                    }
                    else
                    {
                        finalcrossLube.toSketch(oFactory2D);
                    }

                    oSketch.CloseEdition();
                    oPart.Update();

                    if (debugInflated || debugRastr)
                    {
                        return;
                    }

                    oPart.InWorkObject = oSketch;

                    PARTITF.ShapeFactory oShapeFactory = (PARTITF.ShapeFactory)oPart.ShapeFactory;
                    PARTITF.Pocket       oNewPadPlus   = oShapeFactory.AddNewPocket(oSketch, finalcrossLube.Depth);

                    oPart.Update();
                }
                else
                {
                    MainForm.myForm.Activate();
                    MessageBox.Show(@"Groove for the face will not be created!
Area si too small.");
                }

                //all catch
            }catch {}
        }