Example #1
0
        /// <summary>
        /// Display a collection of loops in
        /// a bitmap generated on the fly.
        /// </summary>
        public static Bitmap DisplayLoops(
            ICollection <JtLoops> loops)
        {
            JtBoundingBox2dInt bbFrom = new JtBoundingBox2dInt();

            foreach (JtLoops a in loops)
            {
                bbFrom.ExpandToContain(a.BoundingBox);
            }
            //bbFrom.AdjustBy();

            // Adjust target rectangle height to the
            // displayee loop height.

            int width  = _form_width;
            int height = (int)(width * bbFrom.AspectRatio + 0.5);

            // the bounding box fills the rectangle
            // perfectly and completely, inverted and
            // non-uniformly distorted.

            // Reduce target rectangle slightly so line
            // segments along the outer edge are visible.
            //width -= 6;
            //height -= 6;

            // Specify transformation target rectangle
            // including a margin.

            int bottom = height - (_margin + _margin);

            Point[] parallelogramPoints = new Point[] {
                new Point(_margin, bottom),         // upper left
                new Point(width - _margin, bottom), // upper right
                new Point(_margin, _margin)         // lower left
            };

            // Transform from native loop coordinate system
            // to target display coordinates.

            Matrix transform = new Matrix(
                bbFrom.Rectangle, parallelogramPoints);

            //int edge_width = 4;

            Bitmap bmp = new Bitmap(width, height);

            Graphics graphics = Graphics.FromImage(bmp);

            graphics.Clear(System.Drawing.Color.White);

            foreach (JtLoops a in loops)
            {
                DrawLoopsOnGraphics(graphics,
                                    a.GetGraphicsPathLines(), transform);
            }
            return(bmp);
        }
Example #2
0
 /// <summary>
 /// Expand bounding box to contain
 /// the given other bounding box.
 /// </summary>
 public void ExpandToContain(JtBoundingBox2dInt b)
 {
     ExpandToContain(b.Min);
     ExpandToContain(b.Max);
 }
Example #3
0
        /// <summary>
        /// Display room and the furniture contained in it
        /// in a bitmap generated on the fly.
        /// </summary>
        /// <param name="roomLoops">Room boundary loops</param>
        /// <param name="geometryLoops">Family symbol geometry</param>
        /// <param name="familyInstances">Family instances</param>
        public static Bitmap DisplayRoom(
            JtLoops roomLoops,
            Dictionary <string, JtLoop> geometryLoops,
            List <JtPlacement2dInt> familyInstances)
        {
            JtBoundingBox2dInt bbFrom = roomLoops.BoundingBox;

            // Adjust target rectangle height to the
            // displayee loop height.

            int width  = _form_width;
            int height = (int)(width * bbFrom.AspectRatio + 0.5);

            //SizeF fsize = new SizeF( width, height );

            //SizeF scaling = new SizeF( 1, 1 );
            //PointF translation = new PointF( 0, 0 );

            //GetTransform( fsize, bbFrom,
            //  ref scaling, ref translation, true );

            //Matrix transform1 = new Matrix(
            //  new Rectangle(0,0,width,height),
            //  bbFrom.GetParallelogramPoints());
            //transform1.Invert();

            // the bounding box fills the rectangle
            // perfectly and completely, inverted and
            // non-uniformly distorted:

            //Point2dInt pmin = bbFrom.Min;
            //Rectangle rect = new Rectangle(
            //  pmin.X, pmin.Y, bbFrom.Width, bbFrom.Height );
            //Point[] parallelogramPoints = new Point [] {
            //  new Point( 0, 0 ), // upper left
            //  new Point( width, 0 ), // upper right
            //  new Point( 0, height ) // lower left
            //};

            // the bounding box fills the rectangle
            // perfectly and completely, inverted and
            // non-uniformly distorted:

            // Specify transformation target rectangle
            // including a margin.

            int bottom = height - (_margin + _margin);

            Point[] parallelogramPoints = new Point[] {
                new Point(_margin, bottom),         // upper left
                new Point(width - _margin, bottom), // upper right
                new Point(_margin, _margin)         // lower left
            };

            // Transform from native loop coordinate system
            // to target display coordinates.

            Matrix transform = new Matrix(
                bbFrom.Rectangle, parallelogramPoints);

            Bitmap   bmp      = new Bitmap(width, height);
            Graphics graphics = Graphics.FromImage(bmp);

            graphics.Clear(System.Drawing.Color.White);

            DrawLoopsOnGraphics(graphics,
                                roomLoops.GetGraphicsPathLines(), transform);

            if (null != familyInstances)
            {
                List <Point[]> loops = new List <Point[]>(1);
                loops.Add(new Point[] { });

                foreach (JtPlacement2dInt i in familyInstances)
                {
                    Point2dInt v         = i.Translation;
                    Matrix     placement = new Matrix();
                    placement.Rotate(i.Rotation);
                    placement.Translate(v.X, v.Y, MatrixOrder.Append);
                    placement.Multiply(transform, MatrixOrder.Append);
                    loops[0] = geometryLoops[i.SymbolId]
                               .GetGraphicsPathLines();

                    DrawLoopsOnGraphics(graphics, loops, placement);
                }
            }
            return(bmp);
        }