//-------------------------------------------------------------------------------------------------- public override void OnPointsChanged(Dictionary <int, Pnt2d> points, Dictionary <int, SketchSegment> segments, Dictionary <int, int> markerCounts = default) { var ctx = SketchEditorTool.WorkspaceController.Workspace.AisContext; var edge = Segment.MakeEdge(points); if (edge == null) { Remove(); return; } if (AisObject != null) { var aisShape = AisObject as AIS_Shape; aisShape.Set(edge.Located(new TopLoc_Location(Transform))); if (_IsActive) { ctx.Redisplay(aisShape, false); } else { ctx.RecomputePrsOnly(aisShape, false); } } else { var aisShape = new AIS_Shape(edge.Located(new TopLoc_Location(Transform))); aisShape.SetZLayer(-3); // TOP aisShape.SetWidth(2.0); if (_HighlightDrawer == null) { _HighlightDrawer = new Prs3d_Drawer(); _HighlightDrawer.SetColor(Colors.Highlight); _HighlightDrawer.SetDisplayMode(0); _HighlightDrawer.SetZLayer(-3); // TOP } aisShape.SetDynamicHilightAttributes(_HighlightDrawer); var paramSet = InteractiveContext.Current.Parameters.Get <SketchEditorParameterSet>(); aisShape.SetAngleAndDeviation(paramSet.DeviationAngle.ToRad()); aisShape.SetColor(Colors.SketchEditorSegments); ctx.Display(aisShape, false); ctx.SetSelectionSensitivity(aisShape, 0, (int)(paramSet.SegmentSelectionSensitivity * 1.0)); if (_IsActive) { ctx.Activate(aisShape, 0, false); } else { ctx.Deactivate(aisShape); } AisObject = aisShape; UpdateVisual(); } UpdateHints(points); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { if (_SourceEntity != null) { _SelectionContext = WorkspaceController.Selection.OpenContext(); _SelectionContext.Include(_SourceEntity); } else if (_Shapes != null) { _SelectionContext = WorkspaceController.Selection.OpenContext(); _AisShapes = new List <AIS_Shape>(_Shapes.Count); foreach (var shape in _Shapes) { var aisShape = new AIS_Shape(shape); aisShape.SetColor(Colors.FilteredSubshapes); aisShape.Attributes().SetPointAspect(Marker.CreateBitmapPointAspect(Marker.BallImage, Colors.FilteredSubshapes)); aisShape.Attributes().WireAspect().SetWidth(2); aisShape.SetZLayer(-2); WorkspaceController.Workspace.AisContext.Display(aisShape, false); WorkspaceController.Workspace.AisContext.Activate(aisShape, 0, false); WorkspaceController.Workspace.AisContext.SetSelectionSensitivity(aisShape, 0, 10); _AisShapes.Add(aisShape); } } else { _SelectionContext = WorkspaceController.Selection.OpenContext(SelectionContext.Options.IncludeAll); } _SelectionContext.SetSubshapeSelection(_SubshapeTypes); _SelectionContext.SetSelectionFilter(_SelectionFilter); return(true); }
//-------------------------------------------------------------------------------------------------- #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(); }
//-------------------------------------------------------------------------------------------------- bool _EnsureAisObject() { if (_AisShape != null) { return(true); } if ((_ShapeSource == null) || (AisContext == null)) { return(false); } var brep = OverrideBrep ?? _ShapeSource.GetTransformedBRep(); if (brep == null) { return(false); } _AisShape = new AIS_Shape(brep); _UpdatePresentation(); _UpdateInteractivityStatus(); if (WorkspaceController.Selection.SelectedEntities.Contains(_ShapeSource) && !IsHidden) { AisContext.AddOrRemoveSelected(_AisShape, false); } return(true); }
//-------------------------------------------------------------------------------------------------- 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 _ClearPreviews() { if (_AisPreviewSolid != null) { WorkspaceController.Workspace.AisContext.Remove(_AisPreviewSolid, false); _AisPreviewSolid = null; } if (_AisPreviewEdges != null) { WorkspaceController.Workspace.AisContext.Remove(_AisPreviewEdges, false); _AisPreviewEdges = null; } }
//-------------------------------------------------------------------------------------------------- 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(); }
//-------------------------------------------------------------------------------------------------- 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(); }
//-------------------------------------------------------------------------------------------------- public override void Remove() { if (_AisShape == null) { return; } if (AisContext.IsHilighted(_AisShape)) { AisContext.Unhilight(_AisShape, false); } AisContext.Remove(_AisShape, false); AisContext.Erase(_AisShape, false); _AisShape = null; _UpdateMarker(); }
//-------------------------------------------------------------------------------------------------- void _PreviewRadius(ToolAction toolAction) { if (!(toolAction is AxisValueAction axisValueAction)) { return; } _ClearPreviews(); if (_PreviewShape == null) { // Create solid _PreviewShape = new Sphere() { Radius = 0.1 }; } var radius = axisValueAction.Distance.Round(); if (radius > 0) { var trsf = new Trsf(_Point.ToVec()); _PreviewShape.Radius = radius; _AisPreviewEdges = new AIS_Shape(_PreviewShape.GetTransformedBRep()); _AisPreviewEdges.SetDisplayMode(0); _AisPreviewEdges.SetLocalTransformation(trsf); WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges); _AisPreviewSolid = new AIS_Shape(_PreviewShape.GetTransformedBRep()); _AisPreviewSolid.SetDisplayMode(1); _AisPreviewSolid.SetLocalTransformation(trsf); WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid); StatusText = $"Select Radius: {radius:0.00}"; if (_ValueHudElement != null) { _ValueHudElement.Value = radius; } } }
//-------------------------------------------------------------------------------------------------- void _RemoveReconstructed() { // Remove reconstructed if (_IsReconstructedActive) { var visObject = WorkspaceController.VisualObjects.Get(_Body, true) as VisualShape; if (visObject == null) { return; } visObject.OverrideBrep = null; } _IsReconstructedActive = false; // Remove preview if (_AisPreviewShape != null) { WorkspaceController.Workspace.AisContext.Erase(_AisPreviewShape, false); _AisPreviewShape = null; } WorkspaceController.Invalidate(); }
//-------------------------------------------------------------------------------------------------- void _PreviewHeight(ToolAction toolAction) { if (!(toolAction is AxisValueAction axisValueAction)) { return; } _Position = _PivotPoint.Round(); _Rotation = WorkspaceController.Workspace.GetWorkingPlaneRotation(); _ClearPreviews(); if (_PreviewShape == null) { // Create solid _PreviewShape = new Cylinder() { Radius = _Radius.Round(), Height = 0.1 }; } var height = axisValueAction.Value.Round(); if (Math.Abs(height) < 0.001) { height = 0.001; } if (height > 0) { _Position = _PivotPoint.Round(); _PreviewShape.Height = height; } else { _Position = _PivotPoint.Translated(_Plane.Axis.Direction.ToVec().Multiplied(height)).Round(); _PreviewShape.Height = -height; } 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; } }
//-------------------------------------------------------------------------------------------------- void _PreviewRadius(ToolAction toolAction) { if (!(toolAction is PointAction pointAction)) { return; } _ClearPreviews(); _PointPlane2 = pointAction.PointOnPlane; if (_PointPlane1.IsEqual(_PointPlane2, Double.Epsilon)) { return; } _Radius = new Vec2d(_PointPlane1, _PointPlane2).Magnitude(); if (_Radius <= Double.Epsilon) { return; } var makeCircle = new gce_MakeCirc(_PivotPoint, _Plane.Axis.Direction, _Radius); if (!makeCircle.IsDone()) { return; } var makeEdge = new BRepBuilderAPI_MakeEdge(makeCircle.Value()); if (!makeEdge.IsDone()) { return; } var makeWire = new BRepBuilderAPI_MakeWire(makeEdge.Edge()); if (!makeWire.IsDone()) { return; } var makeFace = new BRepBuilderAPI_MakeFace(makeWire.Wire(), true); if (!makeFace.IsDone()) { return; } _AisPreviewEdges = new AIS_Shape(makeFace.Face()); _AisPreviewEdges.SetDisplayMode(0); WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges); _AisPreviewSolid = new AIS_Shape(makeFace.Face()); _AisPreviewSolid.SetDisplayMode(1); WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false); WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid); StatusText = $"Select radius: {_Radius:0.00}"; if (_ValueHudElement != null) { _ValueHudElement.Value = _Radius; } if (_Coord2DHudElement != null) { _Coord2DHudElement.CoordinateX = pointAction.PointOnPlane.X; _Coord2DHudElement.CoordinateY = pointAction.PointOnPlane.Y; } }