Ejemplo n.º 1
0
        /// <summary>
        /// Sets the transformation needed to draw the model on the canvas when
        /// the diagram needs to fit the screen.
        /// </summary>
        /// <param name="screenBounds">the bounding box of the draw area</param>
        /// <param name="modelBounds">the bounding box of the model</param>
        /// <param name="bondLength">the average bond length of the model</param>
        /// <param name="reset">if true, model center will be set to the modelBounds center and the scale will be re-calculated</param>
        protected virtual void SetupTransformToFit(Rect screenBounds, Rect modelBounds, double bondLength, bool reset)
        {
            if (screenBounds == null)
            {
                return;
            }

            SetDrawCenter(screenBounds.X + screenBounds.Width / 2, screenBounds.Y + screenBounds.Height / 2);

            var scale = this.CalculateScaleForBondLength(bondLength);

            var drawWidth  = screenBounds.Width;
            var drawHeight = screenBounds.Height;

            var diagramWidth  = modelBounds.Width * scale;
            var diagramHeight = modelBounds.Height * scale;

            SetZoomToFit(drawWidth, drawHeight, diagramWidth, diagramHeight);

            // this controls whether editing a molecule causes it to re-center
            // with each change or not
            if (reset || rendererModel.GetFitToScreen())
            {
                SetModelCenter(modelBounds.X + modelBounds.Width / 2, modelBounds.Y + modelBounds.Height / 2);
            }

            // set the scale in the renderer model for the generators
            rendererModel.SetScale(scale);

            Setup();
        }