private Mouse3DPosition CalculateCorrectCoordinate(Mouse3DPosition mousePosition) { var correctedMousePosition = new Mouse3DPosition(mousePosition); var initialSelection = _selectionContainer.CurrentSelectionMode; /* if ((_selectionContainer.CurrentSelectionMode != OCTopAbs_ShapeEnum.TopAbs_SOLID) * && (_selectionContainer.CurrentSelectionMode != OCTopAbs_ShapeEnum.TopAbs_COMPOUND))*/ if (_selectionContainer.CurrentSelectionMode == TopAbsShapeEnum.TopAbs_EDGE) { return(correctedMousePosition); } _selectionContainer.SwitchSelectionMode(TopAbsShapeEnum.TopAbs_FACE); _context.MoveTo(mousePosition.Initial2Dx, mousePosition.Initial2Dy, ViewItems.View); _selectionContainer.BuildSelections(mousePosition); if (_selectionContainer.Entities.Count == 1) { // we have a selected face _selectionContainer.selectedFace = _selectionContainer.Entities[0]; } CorrectCoordinateOnSelectedFace(mousePosition, correctedMousePosition); _selectionContainer.SwitchSelectionMode(initialSelection); return(correctedMousePosition); }
private void MouseClickHandler(Mouse3DPosition mouseData) { if (mouseData.MouseDown) { return; } if (mouseData.ShiftDown || mouseData.ControlDown) { Inputs[InputNames.EditingToolsInput].Send(NotificationNames.HideEditor); return; } var entities = Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get <List <SceneSelectedEntity> >(); if (entities.Count == 0) { ActionsGraph.SwitchAction(ModifierNames.None); } if (entities.Count == 1) { ActionsGraph.SwitchAction(ModifierNames.EditingAction); } }
private void PreviewExtrude(bool preview, Mouse3DPosition mouseData) { if (extrudeBuilder.FunctionName == string.Empty) { extrudeBuilder = new NodeBuilder(Document, FunctionNames.Extrude); extrudeBuilder[2].Real = 0.0; extrudeBuilder.ExecuteFunction(); extrudeBuilder.Visibility = ObjectVisibility.Hidden; } else { extrudeType = extrudeBuilder[1].Integer; } InitSession(); if (_sketchNode.Children[2].Get <MeshTopoShapeInterpreter>() != null && _shapePlane != null) { var dimensionIsDisplayed = preview; extrudeBuilder = new NodeBuilder(Document, FunctionNames.Extrude); extrudeBuilder[0].Reference = _sketchNode; extrudeBuilder[1].Integer = extrudeType; extrudeBuilder[2].Real = Math.Abs(extrudeHeight) > Precision.Confusion ? extrudeHeight : GeomUtils.CalculateDistance(mouseData.Point.GpPnt, _shapePlane); extrudeBuilder.ExecuteFunction(); var nb = new NodeBuilder(extrudeBuilder.Node); if (dimensionIsDisplayed) { DisplayTemporaryDimension(Document, _sketchNode, extrudeBuilder.Node, mouseData, false); } Inputs[InputNames.UiElementsItem].Send(NotificationNames.RefreshPropertyTab, extrudeBuilder.Node); } }
protected override void OnMouseDownAction(Mouse3DPosition mouseData) { base.OnMouseDownAction(mouseData); var nodeList = GetSelectedNodeList(mouseData); _view.UpdateSelection(nodeList); }
private void MouseUpHandler(Mouse3DPosition mouseData) { if (_shapeHandler == null) { return; } if (!_shapeHandler.IsDragging) { return; } // var interpreter = _shapeHandler.Node.Get<TransformationInterpreter>(); // var transform = interpreter.CurrTransform.Multiplied(new OCgp_Trsf()); _shapeHandler.MouseDrag(mouseData); //_builder.Transformation = transform; //_builder.ExecuteFunction(); _shapeHandler.EndDragging(mouseData); _editingDocument.Revert(); //var autoGroupNode = AutoGroupLogic.TryAutoGroup(Document, _shapeHandler.Node); //if (autoGroupNode != null) //{ // RebuildTreeView(); //} Inputs[InputNames.UiElementsItem].Send(NotificationNames.SelectNode, _shapeHandler.Node); Document.Commit("Finished dragging"); UpdateView(); ActionsGraph.SwitchAction(ModifierNames.None); }
private void MouseClickHandler(Mouse3DPosition mousePosition) { if (!Enabled) { return; } if (mousePosition.MouseDown == false) { return; } var correctedMousePosition = CalculateCorrectCoordinate(mousePosition); _context.MoveTo(correctedMousePosition.Initial2Dx, correctedMousePosition.Initial2Dy, ViewItems.View); if (mousePosition.MouseDown) { if (mousePosition.ShiftDown) { _context.ShiftSelect(true); } else { _context.Select(true); } } // Perform click selection using the corrected coordinate _selectionContainer.BuildSelections(correctedMousePosition); }
private void ProposeSelectedReferenceShape(TopoDSShape face, Mouse3DPosition mouseData) { SceneSelectedEntity selectedNode = null; if (face != null) { selectedNode = GeomUtils.IdentifyNode(Document.Root, face); if (selectedNode == null) { return; } } else { var node = NodeBuilderUtils.IdentifySelectedObjectLabel(Document.Root); if (node != null) { selectedNode = new SceneSelectedEntity(node); } } if (selectedNode == null) { return; } if (_axisBuilder.Node != null && selectedNode.Node.Index == _axisBuilder.Node.Index) { SetWorkingPlane(); _dragging = true; _startDragPos = mouseData.Point; return; } // The scene selected entity is hold as reference Propose(selectedNode); }
protected override void OnMouseMove3DAction(Mouse3DPosition mouseData) { if (!radiusChecked && builder.Node.Children.Count > 0) { circleRadius = builder[1].Real; if (Points.Count == 2) { radiusChecked = true; } } SetCoordinate(mouseData.Point); if (Points.Count < 2) { WriteTextOnPos(mouseData.Initial2Dx, mouseData.Initial2Dy, mouseData.Point.ToString() + "\nRadius: "); return; } PreviewCircle(); if (Points.Count < 2) { return; } WriteTextOnPos(mouseData.Initial2Dx, mouseData.Initial2Dy, mouseData.Point.ToString() + "\nRadius: " + Points[1].Distance(Points[0]).ToString()); UpdateView(); RebuildTreeView(); }
/// <summary> /// Receives click events. Called at mouse down and at mouse up. /// </summary> /// <param name = "mouseData"></param> protected override void OnMouseClick3DAction(Mouse3DPosition mouseData) { if (mouseData.MouseDown) { return; } Points[Points.Count - 1] = mouseData.Point; Points.Add(mouseData.Point); if (_form == null) { _form = new GearProperties(5, _extrudeSize); _form.OnValueChange += OnPreviewValueChange; _form.OnDialogClosed += OnPreferencesClosed; _form.Show(); } if (Points.Count <= 3) { return; } BuildFinalShape(); _form.Close(); _form = null; BackToNeutralModifier(); }
protected override void OnMouseMove3DAction(Mouse3DPosition mouseData) { var index = GetSplineIndex(mouseData); ShowHint(index != -1 ? "Click To Combine" : string.Empty); base.OnMouseMove3DAction(mouseData); }
/// <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(); }
protected override void OnMouseDownAction(Mouse3DPosition mouseData) { var shapeIndex = GetSplineIndex(mouseData); var sketch = Document.Root.Get <DocumentContextInterpreter>().ActiveSketch; var sketchBuilder = new SketchCreator(Document); var nodeBuilder = new NodeBuilder(sketchBuilder.CurrentSketch); nodeBuilder[0].TransformedAxis3D = sketchBuilder.NormalOnSketch.Value.GpAxis; if (shapeIndex == -1) { return; } var root = Document.Root; var builder = new NodeBuilder(root[shapeIndex]); var pointCount = builder[0].Integer; var subIndex = -1; for (var i = 1; i < pointCount - 1; ++i) { var pointInSpline = builder[i].TransformedPoint3D; if (ArePointsOutOfZoomRange(pointInSpline, mouseData.Point)) { subIndex = i - 1; } } Ensure.IsNotTrue(subIndex == -1); InitSession(); SplitSplineLogic(builder, subIndex); CommitFinal("Split Spline"); UpdateView(); ActionsGraph.SwitchAction(ModifierNames.SplitSpline); }
private void MouseDownHandler(Mouse3DPosition mouseData) { if (_currentHandler == null) { return; } _currentHandler.previousMousePosition = mouseData.Point.GpPnt; _currentHandler.startX = mouseData.Initial2Dx; _currentHandler.startY = mouseData.Initial2Dy; var selectedNodes = NodeBuilderUtils.IdentifyShapesUnderMouse(_editingDocument.Root, mouseData.Initial2Dx, mouseData.Initial2Dy, ViewInfo.View); if (selectedNodes.Count <= 0 && (_currentHandler.SelectedEntity == null || _currentHandler.SelectedEntity.Node == null)) { return; } if (selectedNodes.Count > 0) { _currentHandler.StartDragging(selectedNodes[0]); } else { _currentHandler.StartDragging(_currentHandler.SelectedEntity); } var pusherInput = ActionsGraph[InputNames.CommandLinePrePusher]; pusherInput.Send(NotificationNames.Reset); pusherInput.Send(NotificationNames.PushValue, _currentHandler); pusherInput.Send(NotificationNames.PushValue, _editingDocument); _editingDocument.Transact(); ViewInfo.SwitchAction(ModifierNames.HandleDragging); }
protected override void OnMouseUpAction(Mouse3DPosition mouseData) { base.OnMouseUpAction(mouseData); _dragging = false; if (_extrudeStages == ExtrudeStages.SelectSketch) { var entities = Inputs[InputNames.SelectionContainerPipe].GetData(NotificationNames.GetEntities).Get <List <SceneSelectedEntity> >(); if (entities.Count <= 0) { return; } _sketchNode = AutoGroupLogic.FindSketchNode(entities[0].Node); Ensure.IsNotNull(_sketchNode); PreviewExtrudes(true); _extrudeStages = ExtrudeStages.SelectAutoFace; Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Resume); } else if (_extrudeStages == ExtrudeStages.SelectAutoFace) { ProposeSelectedReferenceShape(_underMouseFace, mouseData); PreviewExtrudes(true); _extrudeStages = ExtrudeStages.ExtrudeAnimation; } else if (_extrudeStages == ExtrudeStages.ExtrudeAnimation) { } }
private void CorrectCoordinateOnSelectedFace(Mouse3DPosition mousePosition, Mouse3DPosition correctedMousePosition) { if (_selectionContainer[TopAbsShapeEnum.TopAbs_FACE].Count <= 0) { return; } var face = _selectionContainer[TopAbsShapeEnum.TopAbs_FACE][0].TargetShape(); var plane = GeomUtils.ExtractPlane(face); if (plane == null) { return; } Inputs[InputNames.Mouse3DEventsPipe].Send(NotificationNames.SetPlane, plane); double x = 0; double y = 0; double z = 0; var isOnPlane = GeomUtils.ConvertToPlane(ViewItems.View, plane, mousePosition.Initial2Dx, mousePosition.Initial2Dy, ref x, ref y, ref z); if (isOnPlane) { correctedMousePosition.Point = new Point3D(x, y, z); } }
/// <summary> /// Receives mouse move events. The mouse move can be made having a button pressed or not /// </summary> /// <param name = "mouseData"></param> protected override void OnMouseMove3DAction(Mouse3DPosition mouseData) { if (Points.Count < 1) { return; } // Draw a temporary line that follows the mouse until the second point is picked try { var normalPoint = (Point3D)GeomUtils.ProjectPointOnLine(Points[0], _direction, mouseData.Point); if (Points[0].IsEqual(normalPoint)) { return; } InitSession(); _temporary = CreateTemporaryBuilder(FunctionNames.LineTwoPoints); _temporary[0].TransformedPoint3D = Points[0]; _temporary[1].TransformedPoint3D = normalPoint; _temporary.ExecuteFunction(); UpdateView(); } catch (Exception) { Log.Info("Line Normal - line generation error"); } }
/// <summary> /// Receives click events. Called at mouse down and at mouse up. /// </summary> /// <param name = "mouseData"></param> protected override void OnMouseDownAction(Mouse3DPosition mouseData) { var pos = HandleEditingPoints(mouseData); if (pos != -1) { if (mouseData.ShiftDown && pos % 3 == 0 && pos != Points.Count - 1) { switch (pos) { case 0: Points.RemoveAt(0); SplineControlPoints.RemoveRange(0, 3); break; default: Points.RemoveAt(pos / 3); SplineControlPoints.RemoveRange(pos - 1, 3); break; } PreviewSpinePath(); } EditedPointIndex = pos; ShowHint("Move mouse to set the coordinate"); return; } if (Points.Count <= 2) { UpdateBasePoint(Points.Count - 1); } SetLastPointAsMouse(mouseData); PreviewSpinePath(); Points.Add(new Point3D()); }
/// <summary> /// Receives mouse move events. The mouse move can be made having a button pressed or not /// </summary> /// <param name = "mouseData"></param> protected override void OnMouseMove3DAction(Mouse3DPosition mouseData) { //TODO: we have bogus logic that is possible to have enabled command line //We need to fix it if (_metaAction == null) { return; } if (mouseData.ControlDown && !_facePickerSuspended) { Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Suspend); _facePickerSuspended = true; } if (!mouseData.ControlDown && _facePickerSuspended) { Inputs[InputNames.FacePickerPlane].Send(NotificationNames.Resume); _facePickerSuspended = false; } try { InitAnimateSession(); ProposeMouseDependency(mouseData, true); // UpdateView(); } catch (Exception ex) { Log.Info("CommandLineAction - mouse move error" + ex.Message); } }
protected override void OnMouseDownAction(Mouse3DPosition mouseData) { if (Points.Count == 0) { Points.Add(mouseData.Point); _firstCoordinateSet = true; Points.Add(new Point3D()); return; } if (Points.Count == 2) { InitSession(); var sketchCreator = new SketchCreator(Document); var normalOnPlane = sketchCreator.NormalOnSketch.Value.GpAxis; var builder = NodeBuilderUtils.BuildLineInDocument(Document, false, normalOnPlane, Points[0], Points[1]); NodeBuilderUtils.BuildDimensionForLine(Document, builder, Points[0], Points[1]); UpdateView(); Points.Clear(); AddNodeToTree(builder.Node); RebuildTreeView(); Document.Commit("Added Dimension"); } }
/// <summary> /// Receives mouse move events. The mouse move can be made having a button pressed or not /// </summary> /// <param name = "mouseData"></param> protected override void OnMouseMove3DAction(Mouse3DPosition mouseData) { // Display the temporary dimension InitSession(); DrawDimension(mouseData.Point); UpdateView(); }
/// <summary> /// Receives click events. Called at mouse down and at mouse up. /// </summary> /// <param name = "mouseData"></param> protected override void OnMouseClick3DAction(Mouse3DPosition mouseData) { //TODO: we have bogus logic that is possible to have enabled command line //We need to fix it if (_metaAction == null) { return; } if (!mouseData.MouseDown) { return; } try { if (Dependency.StepName == InterpreterNames.Reference) { if (Dependency.Steps[Dependency.StepIndex].Data == null) { ProposeSelectedReferenceShape(null); } } PushValue(mouseData); } catch (Exception ex) { NaroMessage.Show(@"Exception on mouse click: " + ex.Message); } }
/// <summary> /// Receives click events. Called at mouse down and at mouse up. /// </summary> /// <param name = "mouseData"></param> protected override void OnMouseClick3DAction(Mouse3DPosition mouseData) { // At mouse down pick the selected edge if (!mouseData.MouseDown) { return; } InitSession(); var builder = DrawDimension(mouseData.Point); if (!builder.ExecuteFunction()) { Document.Revert(); BackToNeutralModifier(); return; } AddNodeToTree(builder.Node); // Finish the transaction CommitFinal("Apply helper line"); // Prepare for a new dimension Reset(); }
protected static List <SceneSelectedEntity> DetectFacesAtCoordinate(SceneSelectedEntity selectedEntity, Mouse3DPosition mousePosition) { var detectedFaces = new List <SceneSelectedEntity>(); var faces = GeomUtils.ExtractFaces(selectedEntity.TargetShape()); var faceNumber = 1; foreach (var face in faces) { var plane = GeomUtils.ExtractPlane(face); if ((plane != null) && (plane.Distance(mousePosition.Point.GpPnt) <= Precision.Confusion)) { var detectedFace = new SceneSelectedEntity(selectedEntity.Node) { ShapeType = TopAbsShapeEnum.TopAbs_FACE, ShapeCount = faceNumber }; detectedFaces.Add(detectedFace); } faceNumber++; } return(detectedFaces); }
public override void UpdatePointPosition(int index, Mouse3DPosition vertex) { var nodeBuilder = new NodeBuilder(Node); if (nodeBuilder.FunctionName == FunctionNames.Trim) { return; } var gravityCenter = GeomUtils.ExtractGravityCenter(nodeBuilder.Shape); var newPoint = GetPointForIndex(vertex.Point, gravityCenter, index); var mouseTranslation = GeomUtils.BuildTranslation((gravityCenter), newPoint); var translateValue = newPoint.SubstractCoordinate(gravityCenter); var document = Dependency[0].Node.Root.Get <DocumentContextInterpreter>().Document; if (!NodeUtils.NodeIsOnSketch(nodeBuilder)) { NodeUtils.Translate3DNode(nodeBuilder, document, translateValue);//, gravityCenter); } else { var sketchNode = AutoGroupLogic.FindSketchNode(Node); NodeUtils.TranslateSketchNode(nodeBuilder, translateValue, sketchNode);// mouseTranslation); var constraintMapper = new ConstraintDocumentHelper(document, sketchNode); constraintMapper.SetMousePosition(Dependency[0].Reference.Index); var error = constraintMapper.ImpactAndSolve(Dependency[0].Node.Get <ReferenceInterpreter>().Node); } }
private void InitializeDragging(Mouse3DPosition vertex, TransformationInterpreter trsfInterpreter) { _initialDraggingPosition = new Point3D(vertex.Point.GpPnt); var nodeBuilder = new NodeBuilder(Node); var gravityCenter = GeomUtils.ExtractGravityCenter(nodeBuilder.Shape); trsfInterpreter.Pivot = gravityCenter.GpPnt; }
private void MouseEventHandler(Mouse3DPosition mouseData) { if (_prevMouse != mouseData.MouseDown) { MouseClickHandler(mouseData); } _prevMouse = mouseData.MouseDown; }
protected override void OnMouseClick3DAction(Mouse3DPosition mouseData) { if (mouseData.MouseDown) { return; } DialogSetSelectedNode(); }
protected override void OnMouseMove3DAction(Mouse3DPosition mouseData) { WriteTextOnPos(mouseData.Initial2Dx, mouseData.Initial2Dy, mouseData.Point.ToString()); SetLastPointAsMouse(mouseData); PreviewSpinePath(); // UpdateView(); }
protected void DetectFacesUnderMouseClick(IEnumerable <SceneSelectedEntity> selectedEntities, Mouse3DPosition mousePosition) { ClearSelectionList(TopAbsShapeEnum.TopAbs_FACE); var facesList = DetectFacesAtCoordinate(selectedEntities, mousePosition); Selection[TopAbsShapeEnum.TopAbs_FACE].AddRange(facesList); }
public override void UpdatePointPosition(int index, Mouse3DPosition vertex) { var trsfInterpreter = Node.Set <TransformationInterpreter>(); if (_initialDraggingPosition == null) { InitializeDragging(vertex, trsfInterpreter); } //Log.DebugFormat("@pivot {0} {1} {2}", trsfInterpreter.Pivot.X(), trsfInterpreter.Pivot.Y(), trsfInterpreter.Pivot.Z()); var rotate = new gpPnt(0, 0, 0); var startDraggingVector = new gpVec(trsfInterpreter.Pivot, _initialDraggingPosition.Value.GpPnt); if (startDraggingVector.Magnitude <= gp.Resolution) { return; } var currentDraggingVector = new gpVec(trsfInterpreter.Pivot, vertex.Point.GpPnt); if (currentDraggingVector.Magnitude <= gp.Resolution) { return; } var currentGizmo = GetPointLocation(index); var rotationAxis = currentGizmo.Direction; if (rotationAxis.IsParallel(gp.OX.Direction, Precision.Angular)) { var rotationAngle = startDraggingVector.AngleWithRef(currentDraggingVector, new gpVec(gp.OX.Direction)) - _previousAngle; _previousAngle = startDraggingVector.AngleWithRef(currentDraggingVector, new gpVec(gp.OX.Direction)); rotate.X = GeomUtils.RadiansToDegrees(rotationAngle); } else if (rotationAxis.IsParallel(gp.OY.Direction, Precision.Angular)) { var rotationAngle = startDraggingVector.AngleWithRef(currentDraggingVector, new gpVec(gp.OY.Direction)) - _previousAngle; _previousAngle = startDraggingVector.AngleWithRef(currentDraggingVector, new gpVec(gp.OY.Direction)); rotate.Y = GeomUtils.RadiansToDegrees(rotationAngle); } else if (rotationAxis.IsParallel(gp.OZ.Direction, Precision.Angular)) { var rotationAngle = startDraggingVector.AngleWithRef(currentDraggingVector, new gpVec(gp.OZ.Direction)) - _previousAngle; _previousAngle = startDraggingVector.AngleWithRef(currentDraggingVector, new gpVec(gp.OZ.Direction)); rotate.Z = GeomUtils.RadiansToDegrees(rotationAngle); } //Log.DebugFormat("@rotation angle {0}", GeomUtils.RadiansToDegrees(rotationAngle)); trsfInterpreter.Rotate = rotate; }