//-------------------------------------------------------------------------------------------------- double _FindEdgeParam(TopoDS_Edge edge, SelectSubshapeAction selectAction) { // Calculate parameter on the edge double umin = 0, umax = 0; var curve = BRep_Tool.Curve(edge, ref umin, ref umax); var viewAxis = selectAction.LastMouseEventData.PickAxis; var extrema = new GeomAPI_ExtremaCurveCurve(curve, new Geom_Line(viewAxis)); if (extrema.NbExtrema() > 0) { double param1 = 0, param2 = 0; extrema.LowerDistanceParameters(ref param1, ref param2); return(param1); } else { return(Taper.CalculateBaseParameter(edge, 0.5)); } }
//-------------------------------------------------------------------------------------------------- void _OnEdgeOrVertexSelected(SelectSubshapeAction selectAction) { if (selectAction.SelectedSubshapeType == SubshapeTypes.Edge || selectAction.SelectedSubshapeType == SubshapeTypes.Vertex) { selectAction.Stop(); Stop(); var faceRef = _TargetShape.GetSubshapeReference(_TargetBrep, _TargetFace); if (faceRef == null) { Messages.Error("A subshape reference could not be produced for this face."); Stop(); return; } var baseSubshapeRef = _TargetShape.GetSubshapeReference(_TargetBrep, selectAction.SelectedSubshape); if (baseSubshapeRef == null) { Messages.Error("A subshape reference could not be produced for the selected edge or vertex."); return; } // Calculate parameter on the edge, if any double?edgeParam = null; if (selectAction.SelectedSubshapeType == SubshapeTypes.Edge) { edgeParam = _FindEdgeParam(selectAction.SelectedSubshape.ToEdge(), selectAction); } // Create or update if (_Mode == ToolMode.CreateNew) { // Create new var taper = Taper.Create(_TargetBody, faceRef, baseSubshapeRef, 10.0); if (taper != null) { if (edgeParam.HasValue) { taper.BaseParameter = edgeParam.Value; } InteractiveContext.Current.UndoHandler.Commit(); InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_TargetBody); } } else if (_Mode == ToolMode.Reselect) { // Reselected face and base subshape _TaperToChange.Face = faceRef; _TaperToChange.BaseEdgeOrVertex = baseSubshapeRef; if (edgeParam.HasValue) { _TaperToChange.BaseParameter = edgeParam.Value; } else { _TaperToChange.CalculateBaseParameter(0.5); } _TaperToChange.Invalidate(); InteractiveContext.Current.UndoHandler.Commit(); } } }