/// <summary> /// distiles actual drawing structure from earlier set initial draw structure /// </summary> /// <param name="in_initialRotationAngleRad"></param> public void prepareActualGraphicalDXFStructure(double in_initialRotationAngleRad) { if (primalDrawingStructure != null) { this.SuspendLayout(); actualDrawingStructure = new CompleteDxfDrawingStruct(primalDrawingStructure, in_initialRotationAngleRad); //expand the size of drawing control // A TOURNAMENT FOR SELECTION OF INITIAL SCALE FACTOR STARTS NOW! // RULES: get two scale factors (horizontal and vertical) and use that one which is smaller double internalScaleFactorHorizontalChallenger = (this.Size.Width) / (Math.Abs(actualDrawingStructure.XLowerLeft - actualDrawingStructure.XUpperRight) + 2); double internalScaleFactorVerticalChallenger = (this.Size.Height) / (Math.Abs(actualDrawingStructure.YLowerLeft - actualDrawingStructure.YUpperRight) + 2); if (internalScaleFactorHorizontalChallenger < internalScaleFactorVerticalChallenger) { internalScaleFactor = internalScaleFactorHorizontalChallenger; } else { internalScaleFactor = internalScaleFactorVerticalChallenger; } this.realPaintingCanvas.Height = (int)(internalScaleFactor * Math.Abs(actualDrawingStructure.YLowerLeft - actualDrawingStructure.YUpperRight)) + 3; this.realPaintingCanvas.Width = (int)(internalScaleFactor * Math.Abs(actualDrawingStructure.XLowerLeft - actualDrawingStructure.XUpperRight)) + 3; this.realPaintingCanvas.Left = this.Width / 2 - realPaintingCanvas.Width / 2 + 1; this.realPaintingCanvas.Top = this.Height / 2 - realPaintingCanvas.Height / 2 + 1; internalScaleFactorChangedInternally?.Invoke(internalScaleFactor); this.ResumeLayout(true); } else { throw new NullReferenceException("primalDrawingStructure was null. Either DXF file was not read or setupLogicalAndGraphicalDXFstructures was not called"); } }
/// <summary> /// Setup only INITIAL logical and graphical datastructures. /// </summary> /// <param name="in_savedStructureOfDxf">Logical structure of DXF as read from file</param> public void setupLogicalAndGraphicalDXFstructures(LOGICAL.completeDxfStruct in_savedStructureOfDxf) { savedStructureOfDxf = in_savedStructureOfDxf; //generate primal drawing structure MyDxfBoundingBox obtainedBox2 = savedStructureOfDxf.GetBoundingBox(); if (obtainedBox2.XLowerLeft != 0) { offsetOfDxfHorizontal = 0 - obtainedBox2.XLowerLeft; } if (obtainedBox2.YLowerLeft != 0) { offsetOfDxfVertical = 0 - obtainedBox2.YLowerLeft; } primalDrawingStructure = new CompleteDxfDrawingStruct(null); int currentSizeOfDxfStruct = savedStructureOfDxf.getSize(); for (int i = 0; i < currentSizeOfDxfStruct; i++) { DXFdrawingEntry someEntry = savedStructureOfDxf.getItemByIndex(i); MyDxfBoundingBox obtainedBox = someEntry.GetBoundingBox(); //offsets to centralize the drawing in the box Pen usedPen = null; if ((collectionOfLayerDefinitions != null) && (collectionOfLayerDefinitions.ContainsKey(someEntry.layerIdentifier))) { usedPen = collectionOfLayerDefinitions[someEntry.layerIdentifier].Item2; } else { usedPen = new Pen(Color.Black); } if (someEntry is MyDxfLine) { MyDxfLine castLine = someEntry as MyDxfLine; DXFentryForDisplay theLineForDisplay = new MyDxfLineForDisplay(castLine.XStart + offsetOfDxfHorizontal, castLine.YStart + offsetOfDxfVertical, castLine.XEnd + offsetOfDxfHorizontal, castLine.YEnd + offsetOfDxfVertical, usedPen); primalDrawingStructure.addSingleEntry(theLineForDisplay, obtainedBox.XLowerLeft + offsetOfDxfHorizontal, obtainedBox.YLowerLeft + offsetOfDxfVertical, obtainedBox.XUpperRight + offsetOfDxfHorizontal, obtainedBox.YUpperRight + offsetOfDxfVertical); } else if (someEntry is MyDxfArc) { MyDxfArc castArc = someEntry as MyDxfArc; DXFentryForDisplay theArcForDisplay = new MyDxfArcForDisplay(castArc.XCenter + offsetOfDxfHorizontal, castArc.YCenter + offsetOfDxfVertical, castArc.Radius, castArc.StartAngleDegree, castArc.EndAngleDegree, usedPen); primalDrawingStructure.addSingleEntry(theArcForDisplay, obtainedBox.XLowerLeft + offsetOfDxfHorizontal, obtainedBox.YLowerLeft + offsetOfDxfVertical, obtainedBox.XUpperRight + offsetOfDxfHorizontal, obtainedBox.YUpperRight + offsetOfDxfVertical); } } //performing flip on draw structure is done by means of graphical container }