Example #1
0
        private void GetLayer(double[] del, ref int Layer, ref int direction, ref int clockwise)
        {
            Box sceneBox = GetSceneBox();

            if (null != sceneBox && null != mSelectedFace)
            {
                GraphicsNode node = mSelectedFace.Parent.Parent;

                Box      nodeBox = node.RangeBox;
                double[] midPt   = { (nodeBox.MaxPoint.X + nodeBox.MinPoint.X) / 2.0,
                                     (nodeBox.MaxPoint.Y + nodeBox.MinPoint.Y) / 2.0,
                                     (nodeBox.MaxPoint.Z + nodeBox.MinPoint.Z) / 2.0 };

                double[] delta = { nodeBox.MaxPoint.X - nodeBox.MinPoint.X
                                   , nodeBox.MaxPoint.Y - nodeBox.MinPoint.Y
                                   , nodeBox.MaxPoint.Z - nodeBox.MinPoint.Z };

                int i = (int)((midPt[0] - sceneBox.MinPoint.X) / delta[0]);
                int j = (int)((midPt[1] - sceneBox.MinPoint.Y) / delta[1]);
                int k = (int)((midPt[2] - sceneBox.MinPoint.Z) / delta[2]);

                Plane plane = mSelectedFace.Face.Geometry as Plane;
                if (null == plane)
                {
                    return;
                }

                UnitVector normal = plane.Normal;
                if (mSelectedFace.Face.IsParamReversed == true)
                {
                    normal.X = -normal.X;
                    normal.Y = -normal.Y;
                    normal.Z = -normal.Z;
                }
                normal.TransformBy(node.Transformation);
                if (Math.Abs(Math.Abs(normal.X) - 1.0) < 0.0001)
                {
                    if (Math.Abs(del[1]) > Math.Abs(del[2]))
                    {
                        Layer     = k;
                        direction = 2;
                        //clockwise = (del[1] > 0 ? 1 : -1) * (int)normal.X;
                        clockwise = (del[1] * normal.X > 0 ? 1 : -1);
                    }
                    else
                    {
                        Layer     = j;
                        direction = 1;
                        //clockwise = (del[2] > 0 ? -1 : 1) * (int)normal.X;
                        clockwise = (del[2] * normal.X > 0 ? -1 : 1);
                    }
                }
                else if (Math.Abs(Math.Abs(normal.Y) - 1.0) < 0.0001)
                {
                    if (Math.Abs(del[2]) > Math.Abs(del[0]))
                    {
                        Layer     = i;
                        direction = 0;
                        //clockwise = (del[2] > 0 ? 1 : -1) * (int)normal.Y;
                        clockwise = (del[2] * normal.Y > 0 ? 1 : -1);
                    }
                    else
                    {
                        Layer     = k;
                        direction = 2;
                        //clockwise = (del[0] > 0 ? -1 : 1) * (int)normal.Y;
                        clockwise = (del[0] * normal.Y > 0 ? -1 : 1);
                    }
                }
                else if (Math.Abs(Math.Abs(normal.Z) - 1.0) < 0.0001)
                {
                    if (Math.Abs(del[0]) > Math.Abs(del[1]))
                    {
                        Layer     = j;
                        direction = 1;
                        //clockwise = (del[0] > 0 ? 1 : -1) * (int)normal.Z;
                        clockwise = (del[0] * normal.Z > 0 ? 1 : -1);
                    }
                    else
                    {
                        Layer     = i;
                        direction = 0;
                        //clockwise = (del[1] > 0 ? -1 : 1) * (int)normal.Z;
                        clockwise = (del[1] * normal.Z > 0 ? -1 : 1);
                    }
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private static RectangularPatternFeature[] CopyRectangularPatternFeature(PartComponentDefinition partCompDef,
                                                                                 RectangularPatternFeature AsmFeature,
                                                                                 Matrix invTransfo,
                                                                                 int elementIdx,
                                                                                 ComponentOccurrence occurrence,
                                                                                 out ReportData[] reports)
        {
            List <RectangularPatternFeature> newFeatures = new List <RectangularPatternFeature>();

            ObjectCollection ParentFeatures = FeatureUtilities.CopyParentFeatures(partCompDef,
                                                                                  AsmFeature.Parent.Document as Document,
                                                                                  AsmFeature.ParentFeatures,
                                                                                  invTransfo,
                                                                                  occurrence,
                                                                                  out reports);

            if (ParentFeatures.Count == 0)
            {
                return(null);
            }

            Sketch3D sketch3D = partCompDef.Sketches3D.Add();

            List <RectangularPatternFeatureData> FeaturesDataList = new List <RectangularPatternFeatureData>();

            //Only along X Axis
            if (AsmFeature.XDirectionEntity != null && AsmFeature.YDirectionEntity == null)
            {
                UnitVector xDirection = FeatureUtilities.GetDirection(AsmFeature.XDirectionEntity);
                xDirection.TransformBy(invTransfo);

                Point         xDirStartPoint   = null;
                WorkAxis      xDirAxis         = null;
                SketchPoint3D xDirStartPoint3D = null;

                try
                {
                    xDirStartPoint = FeatureUtilities.GetPoint(AsmFeature.XDirectionStartPoint);
                    xDirStartPoint.TransformBy(invTransfo);

                    xDirAxis = partCompDef.WorkAxes.AddFixed(xDirStartPoint, xDirection, FeatureUtilities.ConstructionWorkAxis);

                    xDirStartPoint3D = sketch3D.SketchPoints3D.Add(xDirStartPoint, false);
                }
                catch
                {
                    xDirAxis = partCompDef.WorkAxes.AddFixed(partCompDef.WorkPoints[1].Point, xDirection, FeatureUtilities.ConstructionWorkAxis);
                }

                double count1 = (double)(AsmFeature.XCount.Value) - elementIdx + 1;

                //Check it's not the last pattern element
                if (count1 != 0 && elementIdx != (double)(AsmFeature.XCount.Value))
                {
                    RectangularPatternFeatureData featureData = newRectangularPatternFeatureData();

                    featureData.xCount = count1;

                    featureData.xSpacing = AsmFeature.XSpacing.Value;

                    featureData.naturalXDirection = AsmFeature.NaturalXDirection;

                    featureData.xDirectionSpacingType = AsmFeature.XDirectionSpacingType;

                    featureData.xDirAxis = xDirAxis;

                    featureData.xDirStartPoint3D = xDirStartPoint3D;

                    FeaturesDataList.Add(featureData);
                }

                double count2 = elementIdx;

                //Check it's not the first pattern element
                if (count2 != 0 && elementIdx != 1)
                {
                    RectangularPatternFeatureData featureData = newRectangularPatternFeatureData();

                    featureData.xCount = count2;

                    featureData.xSpacing = AsmFeature.XSpacing.Value;

                    featureData.naturalXDirection = !AsmFeature.NaturalXDirection;

                    featureData.xDirectionSpacingType = AsmFeature.XDirectionSpacingType;

                    featureData.xDirAxis = xDirAxis;

                    featureData.xDirStartPoint3D = xDirStartPoint3D;

                    FeaturesDataList.Add(featureData);
                }
            }

            //Only along Y Axis
            if (AsmFeature.YDirectionEntity != null && AsmFeature.XDirectionEntity == null)
            {
            }

            //Only along both Axes
            if (AsmFeature.XDirectionEntity != null && AsmFeature.YDirectionEntity != null)
            {
            }

            foreach (RectangularPatternFeatureData featureData in FeaturesDataList)
            {
                RectangularPatternFeature newFeature = partCompDef.Features.RectangularPatternFeatures.Add(ParentFeatures,

                                                                                                           featureData.xDirAxis,
                                                                                                           featureData.naturalXDirection,
                                                                                                           featureData.xCount,
                                                                                                           featureData.xSpacing,
                                                                                                           featureData.xDirectionSpacingType,
                                                                                                           featureData.xDirStartPoint3D,

                                                                                                           featureData.yDirAxis,
                                                                                                           featureData.naturalYDirection,
                                                                                                           featureData.yCount,
                                                                                                           featureData.ySpacing,
                                                                                                           featureData.yDirectionSpacingType,
                                                                                                           featureData.yDirStartPoint3D,

                                                                                                           AsmFeature.ComputeType,
                                                                                                           AsmFeature.OrientationMethod);

                foreach (FeaturePatternElement element in newFeature.PatternElements)
                {
                    if (newFeature.HealthStatus == HealthStatusEnum.kUpToDateHealth)
                    {
                        break;
                    }

                    if (element.Faces.Count == 0 && element.Index != 1)
                    {
                        element.Suppressed = true;
                    }
                }

                if (newFeature != null)
                {
                    newFeatures.Add(newFeature);
                }
            }

            return(newFeatures.ToArray());
        }