public bool DragArc(uint eId, OpenTK.Vector2d vec) { if (!IsElementId(CadElementType.Edge, eId)) { return(false); } if (GetEdgeCurveType(eId) != CurveType.CurveArc) { return(true); } bool oldIsLeftSide; double oldDist; { Edge2D e = GetEdge(eId); e.GetCurveArc(out oldIsLeftSide, out oldDist); } Edge2D edge = GetEdge(eId); System.Diagnostics.Debug.Assert(edge.CurveType == CurveType.CurveArc); { OpenTK.Vector2d sPt = edge.GetVertex(true); OpenTK.Vector2d ePt = edge.GetVertex(false); double edgeLen = Math.Sqrt(CadUtils.SquareLength(sPt, ePt)); if (Math.Abs(CadUtils.TriHeight(vec, sPt, ePt)) > edgeLen * 0.02) { OpenTK.Vector2d cPt; bool ret = CadUtils.CenterCircumcircle(sPt, ePt, vec, out cPt); System.Diagnostics.Debug.Assert(ret); double dist = CadUtils.TriHeight(cPt, sPt, ePt); double distRatio = dist / edgeLen; edge.SetCurveArc(CadUtils.TriArea(sPt, ePt, vec) > 0, distRatio); } else { return(true); } } HashSet <uint> setLId = new HashSet <uint>(); for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(true)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(false)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } foreach (uint lId in setLId) { if (!this.BRep.IsElementId(CadElementType.Loop, lId)) { continue; } if (CheckLoop(lId) != 0) { // fail edge.SetCurveArc(oldIsLeftSide, oldDist); return(true); } } return(true); }
public bool MoveEdge(uint eId, OpenTK.Vector2d vecDelta) { System.Diagnostics.Debug.Assert(IsElementId(CadElementType.Edge, eId)); uint sVId = GetEdgeVertexId(eId, true); uint eVId = GetEdgeVertexId(eId, false); OpenTK.Vector2d preSVec; { // 点を動かす→駄目だったら元に戻す Vertex2D vertex = VertexArray.GetObject(sVId); preSVec = vertex.Point; { double oldX = vertex.Point.X; double oldY = vertex.Point.Y; vertex.Point = new OpenTK.Vector2d(oldX + vecDelta.X, oldY + vecDelta.Y); } } OpenTK.Vector2d preEVec; { // 点を動かす→駄目だったら元に戻す Vertex2D ver = VertexArray.GetObject(eVId); preEVec = ver.Point; { double oldX = ver.Point.X; double oldY = ver.Point.Y; ver.Point = new OpenTK.Vector2d(oldX + vecDelta.X, oldY + vecDelta.Y); } } try { // Check Interfarance HashSet <uint> lIds = new HashSet <uint>(); for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(sVId); !vItr.IsEnd(); vItr++) { uint lId = vItr.GetLoopId(); if (IsElementId(CadElementType.Loop, lId)) { if (!lIds.Contains(lId)) { lIds.Add(lId); } else { continue; } if (CheckLoop(lId) != 0) { throw new InvalidOperationException(); } } } for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(eVId); !vItr.IsEnd(); vItr++) { uint lId = vItr.GetLoopId(); if (IsElementId(CadElementType.Loop, lId)) { if (!lIds.Contains(lId)) { lIds.Add(lId); } else { continue; } if (CheckLoop(lId) != 0) { throw new InvalidOperationException(); } } } } catch (Exception exception) { //////////////////////////////// //if the operation fails { // 動かした点を元に戻す Vertex2D vertex = VertexArray.GetObject(sVId); vertex.Point = preSVec; } { // 動かした点を元に戻す Vertex2D vertex = VertexArray.GetObject(eVId); vertex.Point = preEVec; } return(false); } return(true); }
public bool MoveVertex(uint vId, OpenTK.Vector2d vec) { if (!VertexArray.IsObjectId(vId)) { return(false); } OpenTK.Vector2d preVec; { // store point to move point back in case it fails Vertex2D vertex = VertexArray.GetObject(vId); preVec = vertex.Point; } OpenTK.Vector2d dist = vec; { // move point Vertex2D vertex = VertexArray.GetObject(vId); vertex.Point = dist; } try { VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(vId); if (vItr.GetEdgeCount() == 0) { // move point inside loop uint lId = vItr.GetLoopId(); if (IsElementId(CadElementType.Loop, lId)) { // ignore vtx(id_v) in the signd distance computation double distance = SignedDistancePointLoop(lId, vec, vId); if (distance < this.MinClearance) { throw new InvalidOperationException(); } } } else { // move point adjacent to loop HashSet <uint> lIds = new HashSet <uint>(); for (; !vItr.IsEnd(); vItr++) { uint lId = vItr.GetLoopId(); if (IsElementId(CadElementType.Loop, lId)) { if (!lIds.Contains(lId)) { lIds.Add(lId); } else { continue; } if (CheckLoop(lId) != 0) { throw new InvalidOperationException(); } } } } } catch (Exception exception) { //////////////////////////////// // fail { // reset the moved point Vertex2D vertex = VertexArray.GetObject(vId); vertex.Point = preVec; } return(false); } return(true); }
public bool MoveEdgeCtrl(uint eId, uint iCtrl, OpenTK.Vector2d deltaVec) { if (!IsElementId(CadElementType.Edge, eId)) { return(false); } IList <double> oldRelCos = null; { Edge2D e = GetEdge(eId); oldRelCos = e.GetCurveRelPoint(); } Edge2D edge = GetEdge(eId); if (iCtrl >= edge.GetCurvePoint().Count) { return(true); } { OpenTK.Vector2d sPt = edge.GetVertex(true); OpenTK.Vector2d ePt = edge.GetVertex(false); double sqLen = CadUtils.SquareLength(ePt - sPt); var eh = (ePt - sPt) * (1 / sqLen); OpenTK.Vector2d ev = new OpenTK.Vector2d(-eh.Y, eh.X); var p0 = edge.GetCurvePoint()[(int)iCtrl] + deltaVec; IList <double> aRelCo = edge.GetCurveRelPoint(); aRelCo[(int)(iCtrl * 2 + 0)] = OpenTK.Vector2d.Dot(p0 - sPt, eh); aRelCo[(int)(iCtrl * 2 + 1)] = OpenTK.Vector2d.Dot(p0 - sPt, ev); edge.SetCurveRelPoint(aRelCo); } HashSet <uint> setLId = new HashSet <uint>(); for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(true)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } for (VertexEdgeItr vItr = this.BRep.GetVertexEdgeItr(edge.GetVertexId(false)); !vItr.IsEnd(); vItr++) { uint tmpLId = vItr.GetLoopId(); if (!setLId.Contains(tmpLId)) { setLId.Add(tmpLId); } } foreach (uint lId in setLId) { if (!this.BRep.IsElementId(CadElementType.Loop, lId)) { continue; } if (CheckLoop(lId) != 0) { // fail edge.SetCurveRelPoint(oldRelCos); return(true); } } return(true); }