예제 #1
0
        /// <summary>
        ///   Receives click events. Called at mouse down and at mouse up.
        /// </summary>
        /// <param name = "mouseData"></param>
        protected override void OnMouseClick3DAction(Mouse3DPosition mouseData)
        {
            if (Document == null)
            {
                return;
            }
            var entities =
                Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get
                <List <SceneSelectedEntity> >();

            // At mouse down pick the selected edge
            if (!mouseData.MouseDown)
            {
                return;
            }
            // Store the mouse coordinate used to calculate the extrusion height
            Log.Info("Direction - shown");
            InitSession();

            var selectedNodes = entities;

            if (selectedNodes.Count != 1)
            {
                return;
            }

            _currentSelectedEntity = selectedNodes[0];

            // If click on the same shape reverse the face direction
            var reverseFace = false;

            if ((_previousSelectedEntity != null) && (_previousSelectedEntity.Node == _currentSelectedEntity.Node))
            {
                reverseFace = true;
            }
            _previousSelectedEntity = _currentSelectedEntity;

            // If no selected node
            if ((_currentSelectedEntity == null) || (_currentSelectedEntity.ShapeType != TopAbsShapeEnum.TopAbs_FACE))
            {
                return;
            }

            ExitFaceSelectionMode();

            var topoFace =
                GeomUtils.ExtractShapeType(_currentSelectedEntity.Node.Get <TopoDsShapeInterpreter>().Shape,
                                           _currentSelectedEntity.ShapeType,
                                           _currentSelectedEntity.ShapeCount);
            var face = TopoDS.Face(topoFace);

            if (reverseFace)
            {
                ReverseFaceDirection(face);
            }
            ShowFaceDirection(face);

            // Prepare for a new direction
            Reset();
        }
예제 #2
0
        //--------------------------------------------------------------------------------------------------

        public static List <TopoDS_Face> Faces(this TopoDS_Shape shape, bool distinct = true)
        {
            Debug.Assert(shape != null);

            var faces = new List <TopoDS_Face>();

            var exp = new TopExp_Explorer(shape, TopAbs_ShapeEnum.TopAbs_FACE, TopAbs_ShapeEnum.TopAbs_SHAPE);

            while (exp.More())
            {
                var face = TopoDS.Face(exp.Current());
                exp.Next();

                if (distinct)
                {
                    var otherIndex = faces.FindIndex(e => e.IsSame(face));
                    if (otherIndex >= 0)
                    {
                        if (faces[otherIndex].Orientation() == TopAbs_Orientation.TopAbs_REVERSED &&
                            face.Orientation() == TopAbs_Orientation.TopAbs_FORWARD)
                        {
                            // Replace with forward face, this is prefered
                            faces[otherIndex] = face;
                        }

                        // Edge already present or replaced, skip adding
                        continue;
                    }
                }
                faces.Add(face);
            }
            return(faces);
        }
예제 #3
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            bool finished     = false;
            var  selectAction = toolAction as SelectSubshapeAction;

            Debug.Assert(selectAction != null);

            if (selectAction.SelectedSubshapeType == SubshapeTypes.Face)
            {
                var face        = TopoDS.Face(selectAction.SelectedSubshape);
                var brepAdaptor = new BRepAdaptor_Surface(face, true);
                if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane)
                {
                    StatusText = "Selected face is not a plane type surface.";
                }
                else
                {
                    selectAction.Stop();
                    Stop();
                    finished = true;

                    FaceAlgo.GetCenteredPlaneFromFace(face, out _Plane);
                    CreateSketch();
                }
            }

            if (!finished)
            {
                selectAction.Reset();
            }

            WorkspaceController.Invalidate();
        }
예제 #4
0
        public static void DisplayTemporaryDimension(Document animationDocument, Node extrusion, 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 pnt           = new Point3D();
            var computedPoint = GeomUtils.CalculateEdgeMidPoint(edge);

            if (computedPoint != null)
            {
                pnt = (Point3D)computedPoint;
            }

            var dimension = new NodeBuilder(animationDocument, FunctionNames.Dimension);

            dimension[0].Reference          = subShape.Node;
            dimension[1].TransformedPoint3D = pnt;
            dimension.EnableSelection       = enableSelection;
            dimension.ExecuteFunction();

            subShape.Visibility = ObjectVisibility.Hidden;
        }
예제 #5
0
        //--------------------------------------------------------------------------------------------------

        public static List <TopoDS_Edge> Edges(this TopoDS_Shape shape, bool distinct = true)
        {
            var edges = new List <TopoDS_Edge>();

            var exp = new TopExp_Explorer(shape, TopAbs_ShapeEnum.TopAbs_EDGE, TopAbs_ShapeEnum.TopAbs_SHAPE);

            while (exp.More())
            {
                var edge = TopoDS.Edge(exp.Current());
                exp.Next();

                if (distinct)
                {
                    var otherEdgeIndex = edges.FindIndex(e => e.IsSame(edge));
                    if (otherEdgeIndex >= 0)
                    {
                        if (edges[otherEdgeIndex].Orientation() == TopAbs_Orientation.TopAbs_REVERSED &&
                            edge.Orientation() == TopAbs_Orientation.TopAbs_FORWARD)
                        {
                            // Replace with forward edge, this is prefered
                            edges[otherEdgeIndex] = edge;
                        }

                        // Edge already present or replaced, skip adding
                        continue;
                    }
                }

                edges.Add(edge);
            }
            return(edges);
        }
예제 #6
0
        private static void AddFaceFilletVertex(TopoDSShape face, int filletChamferType, double radius,
                                                SceneSelectedEntity firstEntity, SceneSelectedEntity secondEntity,
                                                BRepFilletAPIMakeFillet2d fillet)
        {
            var firstWire          = GeomUtils.ExtractShapeType(face, firstEntity.ShapeType, firstEntity.ShapeCount);
            var secondWire         = GeomUtils.ExtractShapeType(face, secondEntity.ShapeType, secondEntity.ShapeCount);
            var listOfCommonVertex = GeomUtils.CommonVertexes(firstWire, secondWire);

            if (listOfCommonVertex.Count >= 1)
            {
                // If operation type is fillet
                if (filletChamferType == (int)FilletChamferTypes.SimpleFillet2D)
                {
                    foreach (var vertex in listOfCommonVertex)
                    {
                        fillet.AddFillet(vertex, radius);
                    }
                }
                else
                {
                    // If operation type is chamfer
                    fillet.AddChamfer(TopoDS.Edge(firstWire), listOfCommonVertex[0], radius,
                                      GeomUtils.DegreesToRadians(45));
                }
            }
            else
            {
                return;
            }

            return;
        }
        private void DetectFaceUnderMouse(DataPackage data)
        {
            if (InteractiveWorkSuspended)
            {
                return;
            }
            var mousePosition = data.Get <Mouse3DPosition>();

            Inputs[InputNames.SelectionContainerPipe].Send(NotificationNames.BuildSelections, mousePosition);
            var selectedEntities =
                Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get
                <List <SceneSelectedEntity> >();

            if (selectedEntities.Count <= 0)
            {
                Face = null;
                return;
            }

            var shape = selectedEntities[0].TargetShape();

            if (shape == null)
            {
                Face = null;
                return;
            }
            if (shape.ShapeType == TopAbsShapeEnum.TopAbs_FACE)
            {
                Face = TopoDS.Face(shape);
            }
            var container =
                Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetContainer).Get
                <SelectionContainer>();
            //    BuildDragAxis(container.Document, shape, 1);
        }
        public static TriangleMesh Process(TopoDSShape shapeFused)
        {
            var result  = new TriangleMesh();
            var builder = new BRepBuilder();
            var comp    = new TopoDSCompound();

            builder.MakeCompound(comp);
            BRepMesh.Mesh(shapeFused, 1);
            var ex = new TopExpExplorer(shapeFused,
                                        TopAbsShapeEnum.TopAbs_FACE,
                                        TopAbsShapeEnum.TopAbs_SHAPE);

            while (ex.More)
            {
                var shapeResult = new TriangleMesh();
                var face        = TopoDS.Face(ex.Current);
                var location    = new TopLocLocation();
                var facing      = BRepTool.Triangulation(face, location);
                var tab         = new TColgpArray1OfPnt(1, facing.NbNodes);
                //  facing.Nodes(tab);
                var tri = new PolyArray1OfTriangle(1, facing.NbTriangles);
                //  facing.Triangles(tri);
                var triCount   = facing.NbTriangles;
                var listPoints = new List <Point3D>();
                for (var i = 1; i <= triCount; i++)
                {
                    var trian = tri.Value(i);
                    int index1 = 0, index2 = 0, index3 = 0;
                    trian.Get(ref index1, ref index2, ref index3);

                    var firstPoint  = new Point3D(tab.Value(index1));
                    var secondPoint = new Point3D(tab.Value(index2));
                    var thirdPoint  = new Point3D(tab.Value(index3));
                    listPoints.Add(firstPoint);
                    listPoints.Add(secondPoint);
                    listPoints.Add(thirdPoint);
                }
                shapeResult.Points.Clear();
                foreach (var point in listPoints)
                {
                    shapeResult.Points.Add(point);
                }
                shapeResult.Points = GeomUtils.SortAndCompactListPoints(shapeResult.Points);
                var triangleIndex = 0;
                var triangleArray = new int[3];
                foreach (var point in listPoints)
                {
                    triangleArray[triangleIndex] = shapeResult.ComputePointId(point);
                    triangleIndex = (triangleIndex + 1) % 3;
                    if (triangleIndex == 0)
                    {
                        shapeResult.AddTriangle(triangleArray);
                    }
                }
                ex.Next();
                result = result.Combine(shapeResult);
            }
            return(result);
        }
예제 #9
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();
        }
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            bool finished     = false;
            var  selectAction = toolAction as SelectSubshapeAction;

            Debug.Assert(selectAction != null);

            if (selectAction.SelectedSubshapeType == SubshapeTypes.Face)
            {
                var face        = TopoDS.Face(selectAction.SelectedSubshape);
                var brepAdaptor = new BRepAdaptor_Surface(face, true);
                if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane)
                {
                    StatusText = "Selected face is not a plane type surface.";
                }
                else
                {
                    double centerU   = brepAdaptor.FirstUParameter() + (brepAdaptor.LastUParameter() - brepAdaptor.FirstUParameter()) / 2;
                    double centerV   = brepAdaptor.FirstVParameter() + (brepAdaptor.LastVParameter() - brepAdaptor.FirstVParameter()) / 2;
                    var    centerPnt = brepAdaptor.Value(centerU, centerV);

                    WorkspaceController.Workspace.WorkingPlane = new Pln(centerPnt, brepAdaptor.Plane().Axis.Direction);
                    finished = true;
                }
            }
            else if (selectAction.SelectedSubshapeType == SubshapeTypes.Edge)
            {
                var    edge = TopoDS.Edge(selectAction.SelectedSubshape);
                double firstParam = 0, lastParam = 0;
                var    curve = BRep_Tool.Curve(edge, ref firstParam, ref lastParam);
                if (curve != null)
                {
                    var midpoint = curve.Value(firstParam + (lastParam - firstParam) / 2);

                    WorkspaceController.Workspace.WorkingPlane = new Pln(midpoint, WorkspaceController.Workspace.WorkingPlane.Axis.Direction);
                    finished = true;
                }
            }
            else if (selectAction.SelectedSubshapeType == SubshapeTypes.Vertex)
            {
                var vertex = TopoDS.Vertex(selectAction.SelectedSubshape);
                WorkspaceController.Workspace.WorkingPlane = new Pln(BRep_Tool.Pnt(vertex), WorkspaceController.Workspace.WorkingPlane.Axis.Direction);
                finished = true;
            }

            if (finished)
            {
                selectAction.Stop();
                Stop();
            }
            else
            {
                selectAction.Reset();
            }

            WorkspaceController.Invalidate();
        }
예제 #11
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            bool finished     = false;
            var  selectAction = toolAction as SelectSubshapeAction;

            Debug.Assert(selectAction != null);

            if (selectAction.SelectedSubshapeType == SubshapeTypes.Face)
            {
                var face        = TopoDS.Face(selectAction.SelectedSubshape);
                var brepAdaptor = new BRepAdaptor_Surface(face, true);
                if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane)
                {
                    StatusText = "Selected face is not a plane type surface.";
                }
                else
                {
                    selectAction.Stop();
                    Stop();
                    finished = true;

                    var faceRef = _TargetShape.GetSubshapeReference(_TargetShape.GetTransformedBRep(), face);
                    if (faceRef == null)
                    {
                        Messages.Error("A subshape reference could not be produced for this face.");
                        return;
                    }

                    if (_Mode == ToolMode.CreateNew)
                    {
                        // Create new
                        var flangeSheet = FlangeSheet.Create(_TargetBody, faceRef);
                        if (flangeSheet != null)
                        {
                            InteractiveContext.Current.UndoHandler.Commit();
                            InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_TargetBody);
                        }
                    }
                    else if (_Mode == ToolMode.ReselectFace)
                    {
                        // Reselected face
                        _FlangeToChange.Face = faceRef;
                        _FlangeToChange.Invalidate();
                        InteractiveContext.Current.UndoHandler.Commit();
                    }
                }
            }

            if (!finished)
            {
                selectAction.Reset();
            }

            WorkspaceController.Invalidate();
        }
예제 #12
0
        public void BuildFaceDraftExecutionTest()
        {
            var box       = _testBoxBuilder.Shape;
            var draft     = new BRepOffsetAPIDraftAngle(box);
            var basePlane = new gpPln(new gpPnt(0, 0, 0), new gpDir(0, 0, 1));

            Assert.IsTrue(AngleDraftFunction.BuildFaceDraft(draft,
                                                            TopoDS.Face(_boxRightFace.TargetShape()),
                                                            new gpDir(0, 0, 1), 10, basePlane),
                          "BuildFaceDraft failed");
        }
예제 #13
0
        public static TopoDSFace ComposeWires(List <SceneSelectedEntity> cutShapes, bool skipFaceValidityCheck)
        {
            if (cutShapes.Count > 0)
            {
                alreadyDone.Add(cutShapes[0].Node);
                var mkWire = new BRepBuilderAPIMakeWire();
                foreach (var cutShape in cutShapes)
                {
                    var node  = cutShape.Node;
                    var shape = node.Get <TopoDsShapeInterpreter>().Shape;
                    if (shape == null)
                    {
                        break;
                    }
                    if (shape.ShapeType != TopAbsShapeEnum.TopAbs_WIRE)
                    {
                        continue;
                    }
                    var wire = TopoDS.Wire(shape);
                    mkWire.Add(wire);
                }

                if (mkWire.IsDone)
                {
                    // If the wire generation succeeded generate a Face from it
                    var wireProfile = mkWire.Wire;
                    if (!wireProfile.IsNull)
                    {
                        var faceProfile = new BRepBuilderAPIMakeFace(wireProfile, true).Face;
                        if (!faceProfile.IsNull)
                        {
                            // The face is generated not checking if it is a valid face
                            if (skipFaceValidityCheck)
                            {
                                return(faceProfile);
                            }

                            // Check if it is a valid shape
                            var analyzer = new BRepCheckAnalyzer(faceProfile, true);
                            if (analyzer.IsValid())
                            {
                                return(faceProfile);
                            }
                        }
                    }
                }
            }

            return(null);
        }
예제 #14
0
        private void BuildOffset(NodeBuilder builder)
        {
            if (Dependency.Steps[1].Data is Mouse3DPosition)
            {
                var mouse     = Dependency.Steps[1].Data as Mouse3DPosition;
                var face      = TopoDS.Face(Dependency.Steps[0].Get <SceneSelectedEntity>().TargetShape());
                var direction = GetOffsetDirection(face, mouse.Point.GpPnt);
                Dependency.Steps[1].Data = mouse.Point.GpPnt.Distance(_previousMouseClick.Point.GpPnt) * direction;
            }

            builder[0].Reference = (Dependency.Steps[0].Get <SceneSelectedEntity>()).Node;
            builder[1].Real      = Dependency.Steps[1].Get <double>();
            builder.ExecuteFunction();
        }
예제 #15
0
        public static gpPln ExtractPlaneFromFaceShape(TopoDSShape targetFace)
        {
            var face = TopoDS.Face(targetFace);
            var surf = BRepTool.Surface(face);
            var pl   = new GeomPlane(new gpAx3());

            pl = surf.Convert <GeomPlane>();
            //surf.DownCast(ref pl);
            var faceElementAdaptor = new BRepAdaptorSurface(face, true);

            //TO DO: Investigate why this is not working
            Ensure.AreEqual(faceElementAdaptor.GetType, GeomAbsSurfaceType.GeomAbs_Plane);
            return(pl.Pln);
        }
예제 #16
0
        //--------------------------------------------------------------------------------------------------

        void _OnFaceSelected(SelectSubshapeAction selectAction)
        {
            if (selectAction.SelectedSubshapeType == SubshapeTypes.Face)
            {
                var face        = TopoDS.Face(selectAction.SelectedSubshape);
                var brepAdaptor = new BRepAdaptor_Surface(face, true);
                if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane &&
                    brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Cylinder &&
                    brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Cone)
                {
                    StatusText = "Selected face is not a plane, cylinder or cone type surface.";
                    selectAction.Reset();
                    return;
                }

                selectAction.Stop();

                _TargetFace      = face;
                _Phase           = Phase.BaseEdgeOrVertex;
                _SubshapesOfFace = new List <TopoDS_Shape>();
                var edges = face.Edges().Where(
                    edge =>
                {
                    var analysis = new ShapeAnalysis_Edge();
                    return(!analysis.IsSeam(edge, face));
                }).ToList();
                _SubshapesOfFace.AddRange(edges);

                var vertices = face.Vertices().Where(
                    vertex =>
                {
                    var vertexEdges = edges.Where(edge => edge.Vertices().ContainsSame(vertex));
                    return(vertexEdges.Count() > 1);
                });
                _SubshapesOfFace.AddRange(vertices);

                var newAction = new SelectSubshapeAction(this, _SubshapesOfFace);
                if (!WorkspaceController.StartToolAction(newAction))
                {
                    Stop();
                    return;
                }
                newAction.Previewed += _OnActionPreview;
                newAction.Finished  += _OnActionFinished;

                StatusText = "Select base edge or vertex to define direction of taper.";
                WorkspaceController.HudManager?.SetCursor(Cursors.SelectEdge);
            }
        }
예제 #17
0
        /// <summary>
        ///   Returns 1 if the point is outside te face and -1 is inside or on the face.
        /// </summary>
        /// <param name = "point"></param>
        /// <returns></returns>
        private int GetDirection(gpPnt point)
        {
            var direction = 1;

            if (_selectedNodes[0].ShapeType == TopAbsShapeEnum.TopAbs_FACE)
            {
                var face       = TopoDS.Face(_selectedNodes[0].Node.Get <TopoDsShapeInterpreter>().Shape);
                var classifier = new IntToolsContext();
                if (classifier.IsValidPointForFace(point, face, Precision.Confusion))
                {
                    direction = -1;
                }
            }
            return(direction);
        }
 private static TopoDSShape MakePipe(TopoDSShape path, TopoDSShape profile)
 {
     try
     {
         var baseEx = new TopExpExplorer();
         baseEx.Init(path, TopAbsShapeEnum.TopAbs_WIRE, TopAbsShapeEnum.TopAbs_SHAPE);
         var spline = TopoDS.Wire(baseEx.Current);
         return(new BRepOffsetAPIMakePipe(spline, profile).Shape);
     }
     catch (Exception ex)
     {
         Log.Error("Error on making pipe: " + ex.Message);
         return(null);
     }
 }
예제 #19
0
        public override bool Execute()
        {
            var draftedShape = Dependency[0].ReferedShape;
            var draftedFace  = TopoDS.Face(Dependency[0].ReferenceData.TargetShape());

            var draftReferenceShape = Dependency[1].ReferenceData.TargetShape();

            Ensure.IsTrue(draftReferenceShape.ShapeType == TopAbsShapeEnum.TopAbs_FACE);
            var draftReferenceFace = TopoDS.Face(draftReferenceShape);
            var draftDirection     = GeomUtils.ExtractDirection(draftReferenceFace).Reversed;

            var angle = Dependency[3].Real;

            if (Math.Abs(angle) < Precision.Angular)
            {
                return(false);
            }

            var neutralPlaneNormal = Dependency[2].Axis3D.GpAxis;
            var neutralPlane       = new gpPln(neutralPlaneNormal.Location, neutralPlaneNormal.Direction);

            var draft = new BRepOffsetAPIDraftAngle(draftedShape);

            var draftSuceeded = BuildFaceDraft(draft, draftedFace, draftDirection, angle, neutralPlane);

            if (!draftSuceeded)
            {
                return(false);
            }

            draft.Build();
            if (!draft.IsDone)
            {
                return(false);
            }
            if (draft.Status != DraftErrorStatus.Draft_NoError)
            {
                return(false);
            }
            var refNode = Dependency[0].Reference;

            NodeUtils.Hide(refNode);

            Shape = draft.Shape;

            return(true);
        }
예제 #20
0
        public static TopoDSShape ExtractSubShape(
            TopoDSShape originalShape,
            int facePosition,
            TopAbsShapeEnum shapeType)
        {
            if (originalShape == null)
            {
                return(null);
            }
            // Find the face
            var baseEx = new TopExpExplorer();

            baseEx.Init(originalShape, shapeType, TopAbsShapeEnum.TopAbs_SHAPE);

            while (baseEx.More && (facePosition != 1))
            {
                baseEx.Next();
                facePosition--;
            }
            //if (!baseEx.More())
            //    return null;
            TopoDSShape shape = null;

            switch (shapeType)
            {
            case TopAbsShapeEnum.TopAbs_VERTEX:
                shape = TopoDS.Vertex(baseEx.Current);
                break;

            case TopAbsShapeEnum.TopAbs_EDGE:
                shape = TopoDS.Edge(baseEx.Current);
                break;

            case TopAbsShapeEnum.TopAbs_WIRE:
                shape = TopoDS.Wire(baseEx.Current);
                break;

            case TopAbsShapeEnum.TopAbs_FACE:
                shape = TopoDS.Face(baseEx.Current);
                break;

            case TopAbsShapeEnum.TopAbs_SOLID:
            case TopAbsShapeEnum.TopAbs_COMPOUND:
                return(originalShape);
            }
            return(shape);
        }
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            bool finished     = false;
            var  selectAction = toolAction as SelectSubshapeAction;

            Debug.Assert(selectAction != null);

            if (selectAction.SelectedSubshapeType == SubshapeTypes.Face)
            {
                var face = TopoDS.Face(selectAction.SelectedSubshape);
                selectAction.Stop();
                Stop();
                finished = true;
                var faceRef = _TargetShape.GetSubshapeReference(_TargetShape.GetTransformedBRep(), face);
                if (faceRef == null)
                {
                    Messages.Error("A subshape reference could not be produced for this face.");
                    return;
                }

                if (_Mode == ToolMode.CreateNew)
                {
                    // Create new
                    var extrude = Extrude.Create(_TargetBody, faceRef);
                    if (extrude != null)
                    {
                        InteractiveContext.Current.UndoHandler.Commit();
                        InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_TargetBody);
                    }
                }
                else if (_Mode == ToolMode.ReselectFace)
                {
                    // Reselected face
                    _ExtrudeToChange.Face = faceRef;
                    _ExtrudeToChange.Invalidate();
                    InteractiveContext.Current.UndoHandler.Commit();
                }
            }

            if (!finished)
            {
                selectAction.Reset();
            }

            WorkspaceController.Invalidate();
        }
예제 #22
0
        /// <summary>
        ///   Detects the referenced shape type and generates an appropiate
        ///   dimension for it
        /// </summary>
        public static AISInteractiveObject CreateDependency(TopoDSShape referenceShape, gpPnt textLocation, DsgPrsArrowSide arrowType, bool isOffset = false, gpPnt offset = null)
        {
            if (referenceShape == null || referenceShape.ShapeType != TopAbsShapeEnum.TopAbs_EDGE)
            {
                return(null);
            }

            var curve = new BRepAdaptorCurve(TopoDS.Edge(referenceShape));

            if (curve.GetType == GeomAbsCurveType.GeomAbs_Circle)
            {
                return(BuildCircleDimension(referenceShape, textLocation));
            }
            return(curve.GetType == GeomAbsCurveType.GeomAbs_Line
                       ? BuildLineDimension(TopoDS.Edge(referenceShape), textLocation, null, arrowType, isOffset, offset)
                       : null);
        }
        private void GetLength(ref object resultvalue)
        {
            if (Builder[0].ReferenceBuilder.FunctionName == FunctionNames.Circle)
            {
                var radius = Builder[0].ReferenceBuilder.Dependency[1].Real;
                resultvalue = radius * 2;
                return;
            }
            var referenceShape = ShapeUtils.ExtractSubShape(Builder[0].ReferenceData);
            var edge           = TopoDS.Edge(referenceShape);
            var curve          = new BRepAdaptorCurve(edge);
            var firstPoint     = curve.Value(curve.FirstParameter);
            var lastPoint      = curve.Value(curve.LastParameter);
            var length         = firstPoint.Distance(lastPoint);

            resultvalue = length;
        }
예제 #24
0
        //--------------------------------------------------------------------------------------------------

        void _SelectFaceAction_OnFinished(ToolAction toolaction)
        {
            Debug.Assert(toolaction == _SelectFaceAction);

            if (_SelectFaceAction.SelectedSubshapeType == SubshapeTypes.Face)
            {
                var face        = TopoDS.Face(_SelectFaceAction.SelectedSubshape);
                var brepAdaptor = new BRepAdaptor_Surface(face, true);
                if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane)
                {
                    StatusText = "Selected face is not a plane type surface.";
                    _SelectFaceAction.Reset();
                    return;
                }

                var subshapeReference = _Body.Shape.GetSubshapeReference(_ShapeForFaceSelection.GetTransformedBRep(), _SelectFaceAction.SelectedSubshape);

                if (subshapeReference != null)
                {
                    if (_Component == null)
                    {
                        _CreateComponent();
                    }
                    _Component.ReferenceFace = subshapeReference;
                    InteractiveContext.Current.UndoHandler.Commit();
                }
                else
                {
                    Messages.Error("A subshape reference could not be produced for this subshape.");
                }
            }

            ToggleFaceSelection();

            if (_Component != null)
            {
                _InitInteractions();
            }
            else
            {
                Stop();
            }
        }
예제 #25
0
        private static AISInteractiveObject BuildCircleDimension(TopoDSShape referenceShape, gpPnt textLocation)
        {
            var edge  = TopoDS.Edge(referenceShape);
            var curve = new BRepAdaptorCurve(edge);

            if (curve.GetType != GeomAbsCurveType.GeomAbs_Circle)
            {
                return(null);
            }

            // For a circle use a diameter dimension
            var circle   = curve.Circle;
            var diameter = 2.0 * circle.Radius;
            var text     = new TCollectionExtendedString(String.Format("{0:0.00}", diameter));
            var rd       = new AISDiameterDimension(referenceShape, diameter, text, textLocation,
                                                    DsgPrsArrowSide.DsgPrs_AS_BOTHAR, true, ArrowSize);

            rd.SetColor(QuantityNameOfColor.Quantity_NOC_RED);
            return(rd);
        }
예제 #26
0
        public static bool IsPlanarFace(TopoDSShape shape)
        {
            TopoDSFace face;

            try
            {
                if ((shape.IsNull) || (shape.ShapeType != TopAbsShapeEnum.TopAbs_FACE))
                {
                    return(false);
                }
                face = TopoDS.Face(shape);
            }
            catch
            {
                return(false);
            }
            var aFaceElementAdaptor = new BRepAdaptorSurface(face, true);
            var surfaceType         = aFaceElementAdaptor.GetType;

            return(surfaceType == GeomAbsSurfaceType.GeomAbs_Plane);
        }
        public override bool Execute()
        {
            var edgeNode      = Dependency[0].Reference;
            var edgeIndexNode = Dependency[0].ReferenceData.ShapeCount;

            if (ShapeUtils.ExtractShape(edgeNode) == null)
            {
                return(false);
            }
            var edge =
                TopoDS.Edge(ShapeUtils.ExtractSubShape(edgeNode, edgeIndexNode, TopAbsShapeEnum.TopAbs_EDGE));
            var distance = Dependency[1].Real;

            var referenceShape           = Dependency[2].Reference;
            var referebceShapePointIndex = Dependency[3].Integer;

            if (referenceShape == null)
            {
                return(false);
            }
            var point = NodeBuilderUtils.GetNodePoint(referenceShape[referebceShapePointIndex]);

            if (point != null)
            {
                var projectionPoint = GeomUtils.ProjectPointOnEdge(edge, ((Point3D)point).GpPnt);
                var newPoint        = new Point3D(projectionPoint);
                var currentDistance = projectionPoint.Distance(((Point3D)point).GpPnt);
                if (Math.Abs(currentDistance - distance) > 0.01)
                {
                    var scale = currentDistance / distance;
                    if (Math.Abs(scale - 1) > Precision.Confusion)
                    {
                        newPoint = TreeUtils.ScaleSegment(newPoint, ((Point3D)point), scale);
                    }
                }

                NodeBuilderUtils.SetupNodePoint(referenceShape[referebceShapePointIndex], newPoint);
            }
            return(true);
        }
예제 #28
0
        public override bool Execute()
        {
            // Get the extrusion referenece shape, height and extrusion type
            var offsetShape  = Dependency[0].ReferedShape;
            var offsetLength = Dependency[1].Real;

            // Don't allow 0 offset
            if (Math.Abs(offsetLength) < Precision.Confusion)
            {
                return(false);
            }

            //TopoDSShape resultShape = NodeUtils.GenerateWireOffset(offsetShapes, offsetLength);
            // ! Currently only offset on 2D closed shapes of type Face can be made
            if (offsetShape.ShapeType != TopAbsShapeEnum.TopAbs_FACE)
            {
                return(false);
            }

            var face        = TopoDS.Face(offsetShape);
            var resultShape = GeomUtils.GenerateFaceOffset(face, offsetLength);

            if ((resultShape == null) || (resultShape.IsNull))
            {
                return(false);
            }

            var wire       = TopoDS.Wire(resultShape);
            var offsetFace = new BRepBuilderAPIMakeFace(wire, false).Face;

            if (offsetFace.IsNull)
            {
                return(false);
            }

            // Set the result in the NamedShapeInterpreter and make the shape visible
            Shape = offsetFace;

            return(true);
        }
예제 #29
0
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region Property List

        void _InitProperties()
        {
            if (_Properties != null)
            {
                return;
            }

            _Properties = new List <BRepTopologyTreeProperty>();
            try
            {
                _AddDefaultProperties();

                switch (BrepShape.ShapeType())
                {
                case TopAbs_ShapeEnum.TopAbs_SHELL:
                    _AddShellProperties(BrepShape as TopoDS_Shell ?? TopoDS.Shell(BrepShape));
                    break;

                case TopAbs_ShapeEnum.TopAbs_FACE:
                    _AddFaceProperties(BrepShape as TopoDS_Face ?? TopoDS.Face(BrepShape));
                    break;

                case TopAbs_ShapeEnum.TopAbs_WIRE:
                    _AddWireProperties(BrepShape as TopoDS_Wire ?? TopoDS.Wire(BrepShape));
                    break;

                case TopAbs_ShapeEnum.TopAbs_EDGE:
                    _AddEdgeProperties(BrepShape as TopoDS_Edge ?? TopoDS.Edge(BrepShape));
                    break;

                case TopAbs_ShapeEnum.TopAbs_VERTEX:
                    _AddVertexProperties(BrepShape as TopoDS_Vertex ?? TopoDS.Vertex(BrepShape));
                    break;
                }
            }
            catch (Exception e)
            {
                Messages.Exception($"Error getting properties for B-Rep shape {Name}", e);
            }
        }
예제 #30
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            bool finished     = false;
            var  selectAction = toolAction as SelectSubshapeAction;

            Debug.Assert(selectAction != null);

            if (selectAction.SelectedSubshapeType == SubshapeTypes.Face)
            {
                var face        = TopoDS.Face(selectAction.SelectedSubshape);
                var brepAdaptor = new BRepAdaptor_Surface(face, true);
                if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane)
                {
                    StatusText = "Selected face is not a plane type surface.";
                }

                finished = true;
            }

            if (finished)
            {
                var subshapeReference = _TargetShape.GetSubshapeReference(_TargetShape.GetTransformedBRep(), selectAction.SelectedSubshape);
                selectAction.Stop();
                Stop();

                if (subshapeReference == null)
                {
                    Messages.Error("A subshape reference could not be produced for this subshape.");
                    return;
                }

                _SelectedFunc.Invoke(subshapeReference);
            }
            else
            {
                selectAction.Reset();
            }

            WorkspaceController.Invalidate();
        }
예제 #31
0
        public static List<TessalatedShape> Triangulate(TopoDS.Shape topoShape)
        {
            TopExp.Explorer ex = new TopExp.Explorer(topoShape, TopAbs.ShapeEnum.FACE, TopAbs.ShapeEnum.SHAPE);

            BRepMesh.General.Mesh(topoShape, 0.1);

            List<TessalatedShape> faces = new List<TessalatedShape>();

            // Loop all faces
            while (ex.More())
            {

                TessalatedShape shape = new TessalatedShape();

                TopoDS.Face F = TopoDS.General.Face(ex.Current());
                TopLoc.Location location = new TopLoc.Location();

                Poly.Triangulation triangulation = BRep.Tool.Triangulation(F, location);

                Poly.Array1OfTriangle arrayOfTriangle = triangulation.Triangles();

                TColgp.Array1OfPnt p3d = triangulation.Nodes();

                shape.points = new gp.Pnt[p3d.Length()];
                for (int i = 0; i < shape.points.Length; ++i)
                {
                    shape.points[i] = p3d.Value(i + 1);
                }

                if (location != null)
                {
                    gp.Trsf trsf = location.Transformation();
                    for (int i = 0; i < shape.points.Length; ++i)
                    {
                        trsf.Transforms(out shape.points[i].x, out shape.points[i].y, out shape.points[i].z);
                    }
                }
                TColgp.Array1OfPnt2d p2d = triangulation.UVNodes();
                if (p2d != null)
                {
                    shape.uvpoints = new gp.Pnt2d[p2d.Length()];
                    for (int i = 0; i < shape.uvpoints.Length; ++i)
                    {
                        shape.uvpoints[i] = p2d.Value(i + 1);
                    }
                }
                else
                {
                    shape.uvpoints = null;
                }
                shape.triangles = new int[arrayOfTriangle.Length() * 3];
                int l = arrayOfTriangle.Length();
                for (int i = 0; i < l; ++i)
                {
                    Poly.Triangle t = arrayOfTriangle.Value(i + 1);
                    shape.triangles[3 * i] = t.Value(1) - 1;
                    shape.triangles[3 * i + 1] = t.Value(2) - 1;
                    shape.triangles[3 * i + 2] = t.Value(3) - 1;
                }

                faces.Add(shape);

                ex.Next();
            }

            return faces;
        }
예제 #32
0
 public void Add(TopoDS.Shape shape)
 {
     viewedShapes.Add(shape);
     triangulations.AddRange(Utility.Triangulate(shape));
 }