Пример #1
0
        /////////////////////////////////////////////////////////////
        // Use: Returns Normal as UnitVector for input Face.
        //
        /////////////////////////////////////////////////////////////
        public static UnitVector GetFaceNormal(Face face)
        {
            SurfaceEvaluator oEvaluator = face.Evaluator;

            double[] point = new double[3]
            {
                face.PointOnFace.X,
                face.PointOnFace.Y,
                face.PointOnFace.Z
            };

            double[] guessParams = new double[2] {
                0.0, 0.0
            };
            double[] maxDev = new double[2] {
                0.0, 0.0
            };
            double[] Params = new double[2] {
                0.0, 0.0
            };

            SolutionNatureEnum[] sol = new SolutionNatureEnum[1]
            {
                SolutionNatureEnum.kUnknownSolutionNature
            };

            oEvaluator.GetParamAtPoint(ref point,
                                       ref guessParams,
                                       ref maxDev,
                                       ref Params,
                                       ref sol);

            double[] normal = new double[3];

            oEvaluator.GetNormal(ref Params, ref normal);

            return(_Tg.CreateUnitVector(
                       normal[0],
                       normal[1],
                       normal[2]));
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // OnMouseMove Event is used to transform  current GraphicsNode moved by the user
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        void MouseEvents_OnMouseMove(
            MouseButtonEnum Button,
            ShiftStateEnum ShiftKeys,
            Inventor.Point ModelPosition,
            Point2d ViewPosition,
            Inventor.View View)
        {
            if (_symbolNode == null)
            {
                // Define symbol inputs: center, normal, radius
                Point center = _Tg.CreatePoint(0, 0, 0);

                UnitVector normal = _Tg.CreateUnitVector(0, 0, 1);

                double radius = _sheet.Width / 30;

                _symbolNode = DrawSymbol(normal, center, radius);
            }

            SetNodePosition(_symbolNode, ModelPosition);

            _clientGraphicsMng.UpdateView();
        }
Пример #3
0
 static public UnitVector CUV(double x, double y, double z)
 {
     return(tg.CreateUnitVector(x, y, z));
 }
Пример #4
0
        public static void addProjectCut(PartDocument oDoc, WorkPlane oWpReference, bool manual = false)
        {
            SheetMetalComponentDefinition oCompDef = (SheetMetalComponentDefinition)oDoc.ComponentDefinition;

            WorkPlane oWpWork = oCompDef.WorkPlanes.AddByPlaneAndOffset(oWpReference, 0);

            oWpWork.Name    = "wpWork";
            oWpWork.Visible = false;

            PlanarSketch oSketch     = oCompDef.Sketches.Add(oWpWork);
            ProjectedCut oProjectCut = oSketch.ProjectedCuts.Add();

            if (!manual)
            {
                int tmpSegmThk = countThicknessSegment(oProjectCut.SketchEntities);

                int    loop   = 0;
                double offset = 1;
                while (tmpSegmThk != 2)
                {
                    // Devo spostare il piano se ci sono cose nel mezzo
                    oWpWork.SetByPlaneAndOffset(oWpReference, offset);

                    tmpSegmThk = countThicknessSegment(oProjectCut.SketchEntities);
                    loop++;

                    offset += offset;

                    if (loop == 20)
                    {
                        throw new Exception("Numero massimo offset piano.");
                    }
                }

                oProjectCut.Delete();

                oProjectCut = oSketch.ProjectedCuts.Add();
            }

            List <ObjectCollection> dataLine = splittoLinea(oProjectCut.SketchEntities);

            ObjectCollection linea = lengthPerimetro();

            TransientGeometry oTransGeom     = iApp.TransientGeometry;
            UnitVector        oNormalVector  = oSketch.PlanarEntityGeometry.Normal;
            UnitVector2d      oLineDir       = linea[1].Geometry.Direction;
            UnitVector        oLineVector    = (UnitVector)oTransGeom.CreateUnitVector(oLineDir.X, oLineDir.Y, 0);
            UnitVector        oOffsetVector  = (UnitVector)oLineVector.CrossProduct(oNormalVector);
            UnitVector        oDesiredVector = (UnitVector)oTransGeom.CreateUnitVector(0, 1, 0);

            bool bNaturalOffsetDir;

            if (oOffsetVector.IsEqualTo(oDesiredVector))
            {
                bNaturalOffsetDir = true;
            }
            else
            {
                bNaturalOffsetDir = false;
            }

            SketchEntitiesEnumerator oSSketchEntitiesEnum = oSketch.OffsetSketchEntitiesUsingDistance(linea, 0.5, bNaturalOffsetDir, false);

            oProjectCut.Delete();

            styleSketch(oSketch.SketchEntities);

            int countThicknessSegment(SketchEntitiesEnumerator oSketchEntities)
            {
                int result = 0;

                foreach (SketchEntity e in oSketchEntities)
                {
                    if (e.Type == ObjectTypeEnum.kSketchLineObject)
                    {
                        SketchLine oSketchLine = (SketchLine)e;

                        double length = Math.Round(oSketchLine.Length * 100) / 100;

                        if (length == Math.Round(oCompDef.Thickness.Value * 100) / 100)
                        {
                            result++;
                        }
                    }
                }

                return(result);
            }

            List <ObjectCollection> splittoLinea(SketchEntitiesEnumerator oSketchEntities)
            {
                List <ObjectCollection> tmp = new List <ObjectCollection>();

                tmp.Add(iApp.TransientObjects.CreateObjectCollection());
                tmp.Add(iApp.TransientObjects.CreateObjectCollection());
                tmp.Add(iApp.TransientObjects.CreateObjectCollection());

                int indice = 0;

                foreach (SketchEntity oSketchEntity in oSketchEntities)
                {
                    if (oSketchEntity.Type != ObjectTypeEnum.kSketchPointObject)
                    {
                        if (oSketchEntity.Type == ObjectTypeEnum.kSketchLineObject)
                        {
                            SketchLine oSketchLine = (SketchLine)oSketchEntity;

                            if (Math.Round(oSketchLine.Length * 100) / 100 == Math.Round(oCompDef.Thickness.Value * 100) / 100)
                            {
                                if (indice == 0)
                                {
                                    indice = 1;
                                }
                                else
                                {
                                    indice = 2;
                                }
                            }
                            else
                            {
                                tmp[indice].Add(oSketchEntity);
                            }
                        }

                        if (oSketchEntity.Type == ObjectTypeEnum.kSketchArcObject)
                        {
                            tmp[indice].Add(oSketchEntity);
                        }
                    }
                }

                foreach (SketchEntity oSketchEntity in tmp[0])
                {
                    tmp[2].Add(oSketchEntity);
                }

                List <ObjectCollection> result = new List <ObjectCollection>();

                result.Add(tmp[1]);
                result.Add(tmp[2]);

                return(result);
            }

            void styleSketch(SketchEntitiesEnumerator oSketchEntities)
            {
                foreach (SketchEntity oSe in oSketchEntities)
                {
                    if (oSe.Type == ObjectTypeEnum.kSketchLineObject)
                    {
                        SketchLine se = (SketchLine)oSe;

                        se.OverrideColor = iApp.TransientObjects.CreateColor(0, 0, 255);
                        se.LineType      = LineTypeEnum.kDashDottedLineType;
                    }
                    else if (oSe.Type == ObjectTypeEnum.kSketchArcObject)
                    {
                        SketchArc sa = (SketchArc)oSe;

                        sa.OverrideColor = iApp.TransientObjects.CreateColor(0, 0, 255);
                        sa.LineType      = LineTypeEnum.kDashDottedLineType;
                    }
                }
            }

            ObjectCollection lengthPerimetro()
            {
                double l0 = 0;
                double l1 = 0;

                foreach (SketchEntity oSE in dataLine[0])
                {
                    if (oSE.Type == ObjectTypeEnum.kSketchLineObject)
                    {
                        SketchLine se = (SketchLine)oSE;

                        l0 = l0 + se.Length;
                    }
                    else if (oSE.Type == ObjectTypeEnum.kSketchArcObject)
                    {
                        SketchArc se = (SketchArc)oSE;

                        l0 = l0 + se.Length;
                    }
                }
                foreach (SketchEntity oSE in dataLine[1])
                {
                    if (oSE.Type == ObjectTypeEnum.kSketchLineObject)
                    {
                        SketchLine se = (SketchLine)oSE;

                        l1 = l1 + se.Length;
                    }
                    else if (oSE.Type == ObjectTypeEnum.kSketchArcObject)
                    {
                        SketchArc se = (SketchArc)oSE;

                        l1 = l1 + se.Length;
                    }
                }

                if (l0 > l1)
                {
                    return(dataLine[0]);
                }
                else
                {
                    return(dataLine[1]);
                }
            }
        }