Exemple #1
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();
        }
Exemple #2
0
        //--------------------------------------------------------------------------------------------------


        #endregion

        #region Visualization

        void _UpdateAisShape()
        {
            try
            {
                if (_AisShape != null)
                {
                    // Remove AIS Shape
                    WorkspaceController.Workspace.AisContext.Remove(_AisShape, false);
                    WorkspaceController.Workspace.AisContext.Erase(_AisShape, false);
                    _AisShape = null;
                }

                var ocShape = SelectedNode?.BrepShape;
                var trsf    = SelectedShape?.GetTransformation();
                if (ocShape != null && trsf != null)
                {
                    // Init AIS Shape
                    _AisShape = new AIS_Shape(ocShape);
                    _AisShape.SetLocalTransformation(trsf.Value);
                    _AisShape.SetZLayer(-2); // Graphic3d_ZLayerId_Top
                    _AisShape.SetColor(Quantity_NameOfColor.Quantity_NOC_BLUE1.ToColor());
                    _AisShape.Attributes().LineAspect().SetColor(Quantity_NameOfColor.Quantity_NOC_BLUE1.ToColor());
                    _AisShape.SetWidth(3);
                    _AisShape.Attributes().PointAspect().SetScale(3);

                    WorkspaceController.Workspace.AisContext.Display(_AisShape, false);
                    WorkspaceController.Workspace.AisContext.Deactivate(_AisShape);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            WorkspaceController.Invalidate();
        }
Exemple #3
0
        //--------------------------------------------------------------------------------------------------

        public override bool Start()
        {
            _TargetBrep = _TargetShape.GetTransformedBRep();

            if (_Mode == ToolMode.Reselect)
            {
                var visualShape = WorkspaceController.VisualObjects.Get(_TargetBody) as VisualShape;
                if (visualShape != null)
                {
                    visualShape.OverrideBrep = _TargetBrep;
                    WorkspaceController.Invalidate();
                }
            }

            _Phase = Phase.Face;
            var toolAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _TargetBody,
                                                      new OrSelectionFilter(new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane),
                                                                            new FaceSelectionFilter(FaceSelectionFilter.FaceType.Cone),
                                                                            new FaceSelectionFilter(FaceSelectionFilter.FaceType.Cylinder)));

            if (!WorkspaceController.StartToolAction(toolAction))
            {
                return(false);
            }
            toolAction.Previewed += _OnActionPreview;
            toolAction.Finished  += _OnActionFinished;

            StatusText = "Select face to taper.";
            WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace);
            return(true);
        }
Exemple #4
0
        //--------------------------------------------------------------------------------------------------

        public void EnableClipPlane(bool enable)
        {
            if (enable)
            {
                if (_ClipPlane != null)
                {
                    return;
                }

                var sketchPlane   = Sketch.Plane;
                var reversedPlane = new Pln(new Ax3(sketchPlane.Location, sketchPlane.Axis.Direction.Reversed()));
                reversedPlane.Translate(reversedPlane.Axis.Direction.Reversed().ToVec().Scaled(0.0001));
                _ClipPlane = new ClipPlane(reversedPlane);
                _ClipPlane.AddViewport(WorkspaceController.ActiveViewport);
                WorkspaceController.Invalidate();
                RaisePropertyChanged(nameof(ClipPlaneEnabled));
            }
            else
            {
                if (_ClipPlane == null)
                {
                    return;
                }

                _ClipPlane.Remove();
                _ClipPlane = null;
                WorkspaceController.Invalidate();
                RaisePropertyChanged(nameof(ClipPlaneEnabled));
            }
        }
Exemple #5
0
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region Selection

        void _OnSelectionChanged(ToolAction toolAction)
        {
            if (CurrentTool != null)
            {
                return;
            }

            if (_MoveAction != null)
            {
                _MoveAction.Stop();
                _MoveAction = null;
            }

            _UpdateSelections();

            if (SelectedSegments.Any() || SelectedPoints.Any())
            {
                _MoveAction = new MoveSketchPointAction(this);
                if (!WorkspaceController.StartToolAction(_MoveAction, false))
                {
                    return;
                }
                _MoveAction.Previewed += _OnMoveActionPreview;
                _MoveAction.Finished  += _OnMoveActionFinished;

                var segPoints = SelectedSegments.SelectMany(seg => seg.Points);
                _MoveAction.SetSketchElements(Sketch, SelectedPoints.Union(segPoints).ToList());
            }

            WorkspaceController.Invalidate();
        }
Exemple #6
0
    //--------------------------------------------------------------------------------------------------

    void _OnActionFinished(ToolAction toolAction)
    {
        var ta = toolAction as SelectEntityAction <Body>;

        if (ta == null)
        {
            return;
        }

        ta.Stop();

        ModifierBase boolOpShape = null;

        if (ta.SelectedEntity != null)
        {
            boolOpShape = Execute(_SourceBody, new IShapeOperand[] { new BodyShapeOperand(ta.SelectedEntity) });
        }

        Stop();

        if (boolOpShape != null)
        {
            InteractiveContext.Current.UndoHandler.Commit();
            InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_SourceBody);
        }

        WorkspaceController.Invalidate();
    }
        //--------------------------------------------------------------------------------------------------

        public override bool Start()
        {
            _TargetBrep = _TargetShape.GetTransformedBRep();
            if (_TargetBrep == null)
            {
                return(false);
            }

            if (_Mode == ToolMode.ReselectFace)
            {
                var visualShape = WorkspaceController.VisualShapes.GetVisualShape(_TargetBody);
                if (visualShape != null)
                {
                    visualShape.OverrideBrep = _TargetBrep;
                    WorkspaceController.Invalidate();
                }
            }

            var toolAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _TargetBody, new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane));

            if (!WorkspaceController.StartToolAction(toolAction))
            {
                return(false);
            }
            toolAction.Finished += _OnActionFinished;

            StatusText = "Select face to imprint.";
            WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace);
            return(true);
        }
Exemple #8
0
    //--------------------------------------------------------------------------------------------------

    public override bool Start()
    {
        _SourceBody = WorkspaceController.Selection.SelectedEntities.First() as Body;

        if (WorkspaceController.Selection.SelectedEntities.Count > 1)
        {
            var shapeOperands = WorkspaceController.Selection.SelectedEntities
                                .Skip(1)
                                .OfType <Body>()
                                .Select(body => (IShapeOperand) new BodyShapeOperand(body))
                                .ToArray();
            Execute(_SourceBody, shapeOperands);
            Stop();
            WorkspaceController.Invalidate();
            return(false);
        }
        else
        {
            var toolAction = new SelectEntityAction <Body>(this);
            toolAction.SetFilter(body => body.Shape?.ShapeType == ShapeType.Solid);
            if (!WorkspaceController.StartToolAction(toolAction))
            {
                return(false);
            }
            toolAction.Previewed += _OnActionPreview;
            toolAction.Finished  += _OnActionFinished;
            toolAction.Exclude(_SourceBody);

            UpdateStatusText(null);
            WorkspaceController.HudManager?.SetCursor(Cursors.SelectShape);
            return(true);
        }
    }
        //--------------------------------------------------------------------------------------------------

        public override bool Start()
        {
            if (!_Flags.HasFlag(Flags.ForceManualSelect) &&
                UnfoldSheet.CanFindStartFace(_TargetBody.GetBRep()))
            {
                // Auto mode for start face can be used
                var unfoldSheet = UnfoldSheet.Create(_TargetBody);
                if (unfoldSheet != null)
                {
                    ((Tool)this).Stop();
                    InteractiveContext.Current.UndoHandler.Commit();
                    InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_TargetBody);
                    WorkspaceController.Invalidate();
                    return(false);
                }
            }

            var toolAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _TargetBody, new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane));

            if (!WorkspaceController.StartToolAction(toolAction))
            {
                return(false);
            }
            toolAction.Finished += _OnActionFinished;

            StatusText = "Select start face for unfolding.";
            WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace);
            return(true);
        }
Exemple #10
0
        //--------------------------------------------------------------------------------------------------

        public override bool Start()
        {
            _ModifierShape.PropertyChanged += _ModifierShape_PropertyChanged;

            if (_ModifierShape.Operands.Count == 0)
            {
                return(false);
            }

            _Action = new ToggleSubshapesAction(this);
            if (!WorkspaceController.StartToolAction(_Action))
            {
                return(false);
            }
            _Action.Finished += _OnActionFinished;

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

            StatusText = "Select edges to apply modifier on.";
            WorkspaceController.HudManager?.SetCursor(Cursors.SelectEdge);

            WorkspaceController.Invalidate();

            return(true);
        }
Exemple #11
0
        //--------------------------------------------------------------------------------------------------

        public void RotateView(double degree)
        {
            double twist = Maths.NormalizeAngleDegree(WorkspaceController.ActiveViewport.Twist + degree);

            WorkspaceController.ActiveViewport.Twist = twist;
            Elements.OnViewRotated(_TempPoints, Sketch.Segments);
            WorkspaceController.Invalidate();
        }
Exemple #12
0
        //--------------------------------------------------------------------------------------------------

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

            Debug.Assert(selectAction != null);

            SubshapeReference subshapeRef = null;

            switch (_TargetShape.ShapeType)
            {
            case ShapeType.Sketch:
                if (selectAction.SelectedSubshapeType == SubshapeTypes.Edge)
                {
                    subshapeRef = _TargetShape.GetSubshapeReference(_TargetShape.GetTransformedBRep(), TopoDS.Edge(selectAction.SelectedSubshape));
                }
                break;

            case ShapeType.Solid:
                if (selectAction.SelectedSubshapeType == SubshapeTypes.Face)
                {
                    subshapeRef = _TargetShape.GetSubshapeReference(_TargetShape.GetTransformedBRep(), TopoDS.Face(selectAction.SelectedSubshape));
                }
                break;

            default:
                return;
            }

            if (subshapeRef != null)
            {
                selectAction.Stop();
                Stop();

                if (_Mode == ToolMode.CreateNew)
                {
                    var mirror = Mirror.Create(_TargetBody, subshapeRef);
                    if (mirror != null)
                    {
                        InteractiveContext.Current.UndoHandler.Commit();
                        //InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_TargetBody);
                    }
                }
                else if (_Mode == ToolMode.Reselect)
                {
                    // Reselected face or edge
                    _ModifierToChange.ReferenceShape = subshapeRef;
                    _ModifierToChange.Invalidate();
                    InteractiveContext.Current.UndoHandler.Commit();
                }
            }
            else
            {
                selectAction.Reset();
            }

            WorkspaceController.Invalidate();
        }
Exemple #13
0
        //--------------------------------------------------------------------------------------------------

        void _InteractiveEntity_VisualChanged(InteractiveEntity entity)
        {
            if (!_InvalidatedInteractiveEntities.Contains(entity))
            {
                _InvalidatedInteractiveEntities.Add(entity);
            }

            _WorkspaceController.Invalidate();
        }
Exemple #14
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();
        }
Exemple #15
0
        //--------------------------------------------------------------------------------------------------

        public override void Stop()
        {
            var visualShape = WorkspaceController.VisualObjects.Get(_TargetBody) as VisualShape;

            if (visualShape != null)
            {
                visualShape.OverrideBrep = null;
                WorkspaceController.Invalidate();
            }
            base.Stop();
        }
Exemple #16
0
        //--------------------------------------------------------------------------------------------------

        void _PreviewHeight(ToolAction toolAction)
        {
            if (!(toolAction is AxisValueAction axisValueAction))
            {
                return;
            }

            _ClearPreviews();

            _Position = ElSLib.Value(Math.Min(_PointPlane1.X, _PointPlane2.X), Math.Min(_PointPlane1.Y, _PointPlane2.Y), _Plane).Round();
            _Rotation = WorkspaceController.Workspace.GetWorkingPlaneRotation();
            if (_PreviewShape == null)
            {
                // Create solid
                _PreviewShape = new Box
                {
                    DimensionX = Math.Abs(_PointPlane1.X - _PointPlane2.X).Round(),
                    DimensionY = Math.Abs(_PointPlane1.Y - _PointPlane2.Y).Round(),
                    DimensionZ = 0.1
                };
            }

            var height = axisValueAction.Value.Round();

            _PreviewShape.DimensionZ = (Math.Abs(height) >= 0.001) ? height : 0.001;

            var ocShape = _PreviewShape.GetTransformedBRep();

            if (ocShape != null)
            {
                var trsf = new Trsf(_Rotation, _Position.ToVec());

                _AisPreviewEdges = new AIS_Shape(ocShape);
                _AisPreviewEdges.SetDisplayMode(0);
                _AisPreviewEdges.SetLocalTransformation(trsf);
                WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false);
                WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges);

                _AisPreviewSolid = new AIS_Shape(ocShape);
                _AisPreviewSolid.SetDisplayMode(1);
                _AisPreviewSolid.SetLocalTransformation(trsf);
                WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false);
                WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid);
            }

            StatusText = $"Selected height: {height:0.00}";
            if (_ValueHudElement != null)
            {
                _ValueHudElement.Value = height;
            }

            WorkspaceController.Invalidate();
        }
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            var selectAction = toolAction as SelectEntityAction <Body>;

            Debug.Assert(selectAction != null);
            selectAction.Stop();

            _AddOperand(selectAction.SelectedEntity);
            InteractiveContext.Current.UndoHandler.Commit();
            WorkspaceController.Invalidate();

            _StartToolAction();
        }
Exemple #18
0
        //--------------------------------------------------------------------------------------------------

        public override void Stop()
        {
            if (CurrentTool != null)
            {
                StopTool();
            }

            if (Sketch != null)
            {
                if (Sketch.IsVisible)
                {
                    var visualSketchShape = WorkspaceController.VisualShapes.GetVisualShape(Sketch.Body);
                    if (visualSketchShape != null)
                    {
                        visualSketchShape.IsHidden = false;
                    }
                }

                Sketch.ElementsChanged -= _Sketch_ElementsChanged;
            }

            WorkspaceController.Selection.CloseContext(_SelectionContext);
            _SelectionContext = null;

            Elements.RemoveAll();

            WorkspaceController.Workspace.WorkingContext = null;
            WorkspaceController.LockWorkingPlane         = false;

            var vc = WorkspaceController.ActiveViewControlller;

            if (Sketch != null)
            {
                var editorSettings = SketchEditorSettingsCache.GetOrCreate(Sketch);
                editorSettings.ViewParameters   = vc.Viewport.GetViewParameters();
                editorSettings.ClipPlaneEnabled = ClipPlaneEnabled;
            }

            vc.Viewport.PropertyChanged -= _Viewport_PropertyChanged;
            vc.LockedToPlane             = false;
            if (_SavedViewParameters != null)
            {
                vc.Viewport.RestoreViewParameters(_SavedViewParameters);
            }

            EnableClipPlane(false);

            WorkspaceController.Invalidate();

            base.Stop();
        }
Exemple #19
0
        //--------------------------------------------------------------------------------------------------

        void _PreviewBaseRect(ToolAction toolAction)
        {
            if (!(toolAction is PointAction pointAction))
            {
                return;
            }

            _ClearPreviews();

            _PointPlane2 = pointAction.PointOnPlane;

            if (_PointPlane1.IsEqual(_PointPlane2, Double.Epsilon))
            {
                return;
            }

            var face = new BRepBuilderAPI_MakeFace(WorkspaceController.Workspace.WorkingPlane,
                                                   Math.Min(_PointPlane1.X, _PointPlane2.X),
                                                   Math.Max(_PointPlane1.X, _PointPlane2.X),
                                                   Math.Min(_PointPlane1.Y, _PointPlane2.Y),
                                                   Math.Max(_PointPlane1.Y, _PointPlane2.Y)).Face();

            _AisPreviewEdges = new AIS_Shape(face);
            _AisPreviewEdges.SetDisplayMode(0);
            WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false);
            WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges);

            _AisPreviewSolid = new AIS_Shape(face);
            _AisPreviewSolid.SetDisplayMode(1);
            WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false);
            WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid);

            var dim1 = Math.Abs(_PointPlane1.X - _PointPlane2.X);
            var dim2 = Math.Abs(_PointPlane1.Y - _PointPlane2.Y);

            StatusText = $"Select opposite corner point. Size: {dim1:0.00} x {dim2:0.00}";

            if (_Coord2DHudElement != null)
            {
                _Coord2DHudElement.CoordinateX = pointAction.PointOnPlane.X;
                _Coord2DHudElement.CoordinateY = pointAction.PointOnPlane.Y;
            }

            if (_MultiValueHudElement != null)
            {
                _MultiValueHudElement.Value1 = dim1;
                _MultiValueHudElement.Value2 = dim2;
            }

            WorkspaceController.Invalidate();
        }
        //--------------------------------------------------------------------------------------------------

        public override bool Start()
        {
            _TargetBody = WorkspaceController.Selection.SelectedEntities.FirstOrDefault() as Body;
            if (_TargetBody == null)
            {
                return(false);
            }

            if (_TargetBody?.Shape?.ShapeType != ShapeType.Sketch)
            {
                if (_TargetBody.Shape is Loft)
                {
                    _LoftShape = _TargetBody.Shape as Loft;
                }
                else
                {
                    return(false);
                }
            }

            if (WorkspaceController.Selection.SelectedEntities.Count > 1)
            {
                foreach (var entity in WorkspaceController.Selection.SelectedEntities.Skip(1))
                {
                    var body = entity as Body;
                    if (body == null)
                    {
                        continue;
                    }

                    _AddOperand(body);
                }
                InteractiveContext.Current.UndoHandler.Commit();

                Stop();

                WorkspaceController.Selection.SelectEntity(_TargetBody);
                WorkspaceController.Invalidate();
                return(false);
            }

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

            StatusText = "Select section sketches.";
            WorkspaceController.HudManager?.SetCursor(Cursors.SelectShape);
            return(true);
        }
Exemple #21
0
        //--------------------------------------------------------------------------------------------------

        void _ClearPreviews()
        {
            if (_AisPreviewSolid != null)
            {
                WorkspaceController.Workspace.AisContext.Remove(_AisPreviewSolid, false);
                _AisPreviewSolid = null;
            }
            if (_AisPreviewEdges != null)
            {
                WorkspaceController.Workspace.AisContext.Remove(_AisPreviewEdges, false);
                _AisPreviewEdges = null;
            }
            WorkspaceController.Invalidate();
        }
Exemple #22
0
        //--------------------------------------------------------------------------------------------------

        void _UpdateReconstructed()
        {
            // Update reconstructed
            var visObject = WorkspaceController.VisualObjects.Get(_Body, true) as VisualShape;

            if (visObject == null)
            {
                return;
            }

            visObject.OverrideBrep = _Component.ReconstructedBRep?.Located(new TopLoc_Location(_Body.GetTransformation()));;
            _IsReconstructedActive = true;

            // Update preview
            var builder  = new BRep_Builder();
            var compound = new TopoDS_Compound();

            builder.MakeCompound(compound);

            if (_Component.Layers != null)
            {
                foreach (var layer in _Component.Layers)
                {
                    var location = new TopLoc_Location(new Trsf(layer.CutPlane.Position, Ax3.XOY));
                    builder.Add(compound, layer.BRep.Located(location));
                }
            }

            compound.Location(new TopLoc_Location(_Body.GetTransformation()));

            if (_AisPreviewShape == null)
            {
                _AisPreviewShape = new AIS_Shape(compound);
                _AisPreviewShape.SetColor(Colors.FilteredSubshapesHot);
                _AisPreviewShape.SetWidth(2.0);
                _AisPreviewShape.SetZLayer(-2); // Top
                WorkspaceController.Workspace.AisContext.Display(_AisPreviewShape, 0, -1, false, false);
            }
            else
            {
                _AisPreviewShape.SetShape(compound);
                WorkspaceController.Workspace.AisContext.RecomputePrsOnly(_AisPreviewShape, false);
            }

            // Finalize
            _IsReconstructeUpdating = false;

            WorkspaceController.Invalidate();
        }
Exemple #23
0
        //--------------------------------------------------------------------------------------------------

        void _FinishHeight(ToolAction toolAction)
        {
            toolAction?.Stop();

            var body = Body.Create(_PreviewShape);

            body.Position = _Position;
            body.Rotation = _Rotation;
            InteractiveContext.Current.Document.AddChild(body);
            InteractiveContext.Current.UndoHandler.Commit();

            ((Tool)this).Stop();
            InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(body);
            WorkspaceController.Invalidate();
        }
Exemple #24
0
        //--------------------------------------------------------------------------------------------------

        void _RemoveReconstructed()
        {
            if (_IsReconstructedActive)
            {
                var visObject = WorkspaceController.VisualObjects.Get(_Body, true) as VisualShape;
                if (visObject == null)
                {
                    return;
                }

                visObject.OverrideBrep = null;
                WorkspaceController.Invalidate();
            }
            _IsReconstructedActive = false;
        }
Exemple #25
0
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region Movement

        Dictionary <int, Pnt2d> _ApplyMoveDelta(IEnumerable <int> points, Vec2d moveDelta)
        {
            foreach (var pointIndex in points)
            {
                _TempPoints[pointIndex] = Sketch.Points[pointIndex].Translated(moveDelta);
            }

            SketchConstraintSolver.Solve(Sketch, _TempPoints, false);
            Elements.OnPointsChanged(_TempPoints, Sketch.Segments);
            WorkspaceController.Invalidate();

            //Debug.WriteLine("ApplyMoveDelta");

            return(_TempPoints);
        }
Exemple #26
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            switch (_Phase)
            {
            case Phase.Face:
                _OnFaceSelected(toolAction as SelectSubshapeAction);
                break;

            case Phase.BaseEdgeOrVertex:
                _OnEdgeOrVertexSelected(toolAction as SelectSubshapeAction);
                break;
            }

            WorkspaceController.Invalidate();
        }
Exemple #27
0
        //--------------------------------------------------------------------------------------------------

        void _UpdateReconstructed()
        {
            var visObject = WorkspaceController.VisualObjects.Get(_Body, true) as VisualShape;

            if (visObject == null)
            {
                return;
            }

            visObject.OverrideBrep = _Component.ReconstructedBRep?.Located(new TopLoc_Location(_Body.GetTransformation()));;
            WorkspaceController.Invalidate();

            _IsReconstructedActive  = true;
            _IsReconstructeUpdating = false;
        }
Exemple #28
0
        //--------------------------------------------------------------------------------------------------

        public void ToggleFaceSelection()
        {
            if (_SelectFaceAction != null)
            {
                _SelectFaceAction.Cancel(true);
                _SelectFaceAction = null;
                StatusText        = "";
                WorkspaceController.HudManager?.SetCursor(null);
                RaisePropertyChanged(nameof(IsSelectingFace));

                if (_Component == null)
                {
                    // No face, no component
                    Stop();
                }
                else
                {
                    _UpdateReconstructed();
                    WorkspaceController.Invalidate();
                }
            }
            else
            {
                _ShapeForFaceSelection = _Component?.GetShape() ?? _Body.Shape;
                var selectionBRep = _ShapeForFaceSelection.GetTransformedBRep();
                if (selectionBRep == null)
                {
                    return;
                }
                var visObject = WorkspaceController.VisualObjects.Get(_Body, true) as VisualShape;
                if (visObject == null)
                {
                    return;
                }
                visObject.OverrideBrep = selectionBRep;

                _SelectFaceAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _Body, new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane));
                if (!WorkspaceController.StartToolAction(_SelectFaceAction))
                {
                    _SelectFaceAction = null;
                    return;
                }
                _SelectFaceAction.Finished += _SelectFaceAction_OnFinished;
                StatusText = "Select plane base face.";
                WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace);
            }
            RaisePropertyChanged(nameof(IsSelectingFace));
        }
        //--------------------------------------------------------------------------------------------------

        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();
        }
        //--------------------------------------------------------------------------------------------------

        void _ClearHints()
        {
            _HintCircle?.Remove();
            _HintCircle = null;

            if (_HintAngles != null)
            {
                foreach (var hintLine in _HintAngles)
                {
                    hintLine?.Remove();
                }

                _HintAngles = null;
            }


            WorkspaceController.Invalidate();
        }