/// <summary> /// Builds the marker polyline. /// </summary> private void ComputeMarker() { _markerVertexes.SetValue(1, new OCGraphic2d_Vertex(-_halfWidth, -_halfHeight)); _markerVertexes.SetValue(2, new OCGraphic2d_Vertex(-_halfWidth, _halfHeight)); _markerVertexes.SetValue(3, new OCGraphic2d_Vertex(_halfWidth, _halfHeight)); _markerVertexes.SetValue(4, new OCGraphic2d_Vertex(_halfWidth, -_halfHeight)); _markerVertexes.SetValue(5, new OCGraphic2d_Vertex(-_halfWidth, -_halfHeight)); _marker = new OCGraphic2d_PolylineMarker(this, _xPos, _yPos, _markerVertexes); }
/// <summary> /// The endpoints of the line can be set to other coordinates. /// </summary> public void SetEndpoints(Double xPos, Double yPos, Double xEndPos, Double yEndPos) { OCAIS2D_InteractiveContext context = GetContext(); // Create the 2 markers for the end of the segment _startMarker = new PolylineMarker2D(context, xPos, yPos, GeometryConstants.MarkerWidth, GeometryConstants.MarkerWidth); _endMarker = new PolylineMarker2D(context, xEndPos, yEndPos, GeometryConstants.MarkerWidth, GeometryConstants.MarkerWidth); // Store the line attributes _array1OfVertex.SetValue(1, new OCGraphic2d_Vertex(xPos, yPos)); _array1OfVertex.SetValue(2, new OCGraphic2d_Vertex(xEndPos, yEndPos)); BuildPolyline(); }
/// <summary> /// Used to access the rectangle vertexes. The array passed as parameter is filled with the vertexes. /// </summary> /// <param name="vertexArray"></param> public void GetVertexes(OCGraphic2d_Array1OfVertex vertexArray) { if (_array1OfVertex.Length() == vertexArray.Length()) { //TODO: the loop condition is not <= !? for (int i = 1; i < _array1OfVertex.Length(); i++) { vertexArray.SetValue(i, new OCGraphic2d_Vertex(_array1OfVertex.Value(i).X(), _array1OfVertex.Value(i).Y())); } } }
/// <summary> /// Used to retrieve the vertexes of the line. /// </summary> /// <param name="vertexArray"></param> public void GetVertexes(OCGraphic2d_Array1OfVertex vertexArray) { int arrLen = _array1OfVertex.Length(); int vertexLen = vertexArray.Length(); if (arrLen == vertexLen) { for (int i = 1; i <= arrLen; i++) { vertexArray.SetValue(i, new OCGraphic2d_Vertex(_array1OfVertex.Value(i).X(), _array1OfVertex.Value(i).Y())); } } }
/// <summary> /// Calculates the rectangle vertexes. It also builds the vertex markers. /// </summary> private void BuildPolyline() { if (_polyline != null) { this.RemovePrimitive(_polyline); } Double BottomLeftX = _leftBottomX; Double BottomLeftY = _leftBottomY; Double BottomRightX = _leftBottomX + (Math.Cos(_angle) * (_rightBottomX - _leftBottomX)); Double BottomRightY = _leftBottomY + (Math.Sin(_angle) * (_rightBottomX - _leftBottomX)); Double TopRightX = _leftBottomX + (Math.Cos(_angle) * (_rightBottomX - _leftBottomX)) + (-Math.Sin(_angle) * (_leftTopY - _leftBottomY)); Double TopRightY = _leftBottomY + (Math.Sin(_angle) * (_rightBottomX - _leftBottomX)) + (Math.Cos(_angle) * (_leftTopY - _leftBottomY)); Double TopLeftX = _leftBottomX + (-Math.Sin(_angle) * (_leftTopY - _leftBottomY)); Double TopLeftY = _leftBottomY + (Math.Cos(_angle) * (_leftTopY - _leftBottomY)); _array1OfVertex.SetValue(1, new OCGraphic2d_Vertex(BottomLeftX, BottomLeftY)); _array1OfVertex.SetValue(2, new OCGraphic2d_Vertex(TopLeftX, TopLeftY)); _array1OfVertex.SetValue(3, new OCGraphic2d_Vertex(TopRightX, TopRightY)); _array1OfVertex.SetValue(4, new OCGraphic2d_Vertex(BottomRightX, BottomRightY)); _array1OfVertex.SetValue(5, new OCGraphic2d_Vertex(BottomLeftX, BottomLeftY)); // Add the polyline in the representation, for all modes _polyline = new OCGraphic2d_Polyline(this, _array1OfVertex); _polyline.SetColorIndex(1); _polyline.SetWidthIndex(1); _polyline.SetTypeIndex(1); // Position the markers _leftBottomMarker.SetPosition(BottomLeftX, BottomLeftY); _leftTopMarker.SetPosition(TopLeftX, TopLeftY); _rightTopMarker.SetPosition(TopRightX, TopRightY); _rightBottomMarker.SetPosition(BottomRightX, BottomLeftY); }