Esempio n. 1
0
        public static void DisplayTemporaryDimension(Document animationDocument, Node baseNode, Node extrusion, Mouse3DPosition mouseData, bool enableSelection)
        {
            var subShape = new NodeBuilder(animationDocument, FunctionNames.SubShape);

            subShape[0].Reference = extrusion;
            subShape[1].Integer   = 1;
            subShape[2].Integer   = (int)TopAbsShapeEnum.TopAbs_EDGE;
            subShape.ExecuteFunction();

            if (subShape.Shape == null)
            {
                return;
            }

            var edge            = TopoDS.Edge(subShape.Shape);
            var baseNodeBuilder = new NodeBuilder(baseNode);
            var gravityCenter   = GeomUtils.ExtractGravityCenter(baseNodeBuilder.Shape);

            var firstPoint           = new Point3D();
            var firstPointCalculated = GeomUtils.CalculateEdgeFirstPoint(edge);

            if (firstPointCalculated != null)
            {
                firstPoint = (Point3D)firstPointCalculated;
            }

            var secondPoint           = new Point3D();
            var secondPointCalculated = GeomUtils.CalculateEdgeLastPoint(edge);

            if (secondPointCalculated != null)
            {
                secondPoint = (Point3D)secondPointCalculated;
            }

            var middlePoint = GeomUtils.ComputeMidPoint(firstPoint, secondPoint);

            // Translate the dimenion text at some distance from the extrude
            var vector = new gpVec(firstPoint.GpPnt, gravityCenter.GpPnt);

            vector.Reverse();
            vector.Normalize();
            vector.Multiply(2);
            middlePoint = GeomUtils.BuildTranslation(middlePoint, vector);

            subShape.Visibility = ObjectVisibility.Hidden;

            // Build a distance dimension just for animation purposes
            var animationBuilder = new NodeBuilder(animationDocument, FunctionNames.PointsDimension);

            animationBuilder[0].TransformedPoint3D = firstPoint;
            animationBuilder[1].TransformedPoint3D = secondPoint;
            animationBuilder[2].TransformedPoint3D = middlePoint;
            animationBuilder[3].Integer            = (int)DsgPrsArrowSide.DsgPrs_AS_FIRSTPT_LASTAR;
            animationBuilder[4].Real         = 1;
            animationBuilder.EnableSelection = false;
            animationBuilder.Color           = Color.Black;
            animationBuilder.ExecuteFunction();
        }