コード例 #1
0
        public override void ProcessEntity(PicEntity entity)
        {
            PicDrawable drawable = entity as PicDrawable;

            // non drawable not taken into account
            if (null == drawable)
            {
                return;
            }
            if (drawable is PicBlockRef)
            {
                PicBlockRef blockRef = entity as PicBlockRef;
                _box.Extend(blockRef.Box);
            }
            else if ((drawable is PicBlock))
            {
                if (_takePicBlocsIntoAccount)
                {
                    PicBlock block = entity as PicBlock;
                    _box.Extend(block.Box);
                }
            }
            else
            {
                PicTypedDrawable typedDrawable = drawable as PicTypedDrawable;
                if (null != typedDrawable && typedDrawable.LineType != PicGraphics.LT.LT_CONSTRUCTION)
                {
                    _box.Extend(drawable.Box);
                }
            }
        }
コード例 #2
0
        private static Vector2D OppositePoint(PicTypedDrawable entity, Vector2D pt)
        {
            PicSegment seg = entity as PicSegment;

            if (null != seg)
            {
                if ((seg.Pt0 - pt).GetLength() < (seg.Pt1 - pt).GetLength())
                {
                    return(seg.Pt1);
                }
                else
                {
                    return(seg.Pt0);
                }
            }
            PicArc arc = entity as PicArc;

            if (null != arc)
            {
                if ((arc.Source - pt).GetLength() < (arc.Target - pt).GetLength())
                {
                    return(arc.Target);
                }
                else
                {
                    return(arc.Source);
                }
            }
            return(Vector2D.Zero);
        }
コード例 #3
0
        private static bool EntityPoints(PicTypedDrawable entity, Vector2D pt, ref Vector2D pt0, ref Vector2D pt1)
        {
            PicSegment seg = entity as PicSegment;

            if (null != seg)
            {
                if ((pt - seg.Pt0).GetLength() < (pt - seg.Pt1).GetLength())
                {
                    pt0 = seg.Pt0; pt1 = seg.Pt1;
                }
                else
                {
                    pt0 = seg.Pt1; pt1 = seg.Pt0;
                }
            }
            PicArc arc = entity as PicArc;

            if (null != arc)
            {
                if ((pt - arc.Source).GetLength() < (pt - arc.Target).GetLength())
                {
                    pt0 = arc.Source; pt1 = arc.Target;
                }
                else
                {
                    pt1 = arc.Target; pt0 = arc.Source;
                }
            }
            return((pt0 - pt).GetLength() < _epsilon);
        }
コード例 #4
0
 private bool HasFoldLineType(PicTypedDrawable drawable)
 {
     return((drawable.LineType == PicGraphics.LT.LT_CREASING) ||
            (drawable.LineType == PicGraphics.LT.LT_HALFCUT) ||
            (drawable.LineType == PicGraphics.LT.LT_PERFO) ||
            (drawable.LineType == PicGraphics.LT.LT_PERFOCREASING));
 }
コード例 #5
0
        public void ExportEntity(ExpBlock block, PicEntity entity)
        {
            PicTypedDrawable drawable = entity as PicTypedDrawable;
            ExpLayer         layer    = null;
            ExpPen           pen      = null;

            if (null != drawable)
            {
                pen   = _exporter.GetPenByAttribute(LineTypeToExpPen(drawable.LineType));
                layer = _exporter.GetLayerByName(string.Format("Layer {0}", drawable.Layer));
            }
            PicSegment seg = entity as PicSegment;

            if (null != seg)
            {
                _exporter.AddSegment(block, layer, pen, seg.Pt0.X, seg.Pt0.Y, seg.Pt1.X, seg.Pt1.Y);
            }
            PicArc arc = entity as PicArc;

            if (null != arc)
            {
                // using dxf conversions
                double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg;
                if (ang < 0.0)
                {
                    angd += ang; ango = -ang;
                }
                else
                {
                    ango = ang;
                }
                _exporter.AddArc(block, layer, pen, arc.Center.X, arc.Center.Y, arc.Radius, angd, angd + ango);
            }
        }
コード例 #6
0
        public override void ProcessEntity(PicEntity entity)
        {
            PicTypedDrawable drawable = (PicTypedDrawable)entity;

            if (null != drawable)
            {
                drawable.Transform(_transform);
            }
        }
        public override void ProcessEntity(PicEntity entity)
        {
            PicTypedDrawable drawable = entity as PicTypedDrawable;

            if (null != drawable)
            {
                _entities.Add(drawable);
            }
        }
コード例 #8
0
ファイル: PicFilter.cs プロジェクト: treeDiM/PackLib4ES
        public override bool Accept(PicEntity entity)
        {
            PicTypedDrawable typedDrawable = entity as PicTypedDrawable;

            if (null == typedDrawable)
            {
                return(false);
            }
            return(typedDrawable.Group == _grp);
        }
コード例 #9
0
ファイル: PicFilter.cs プロジェクト: treeDiM/PackLib4ES
        public override bool Accept(PicEntity entity)
        {
            PicTypedDrawable typedDrawable = entity as PicTypedDrawable;

            if (null == typedDrawable)
            {
                return(true);
            }
            return(typedDrawable.Length > _epsilon);
        }
コード例 #10
0
        public override void  ProcessEntity(PicEntity entity)
        {
            PicTypedDrawable typedDrawable = entity as PicTypedDrawable;

            if (null != typedDrawable &&
                typedDrawable.Group == _grp &&
                typedDrawable.LineType != PicGraphics.LT.LT_CONSTRUCTION &&
                typedDrawable.Code == PicEntity.eCode.PE_SEGMENT)
            {
                _entities.Add(typedDrawable);
            }
        }
コード例 #11
0
        public static PicBlock CreateNewBlock(uint id, IEntityContainer container, Transform2D transf)
        {
            PicBlock block = new PicBlock(id);

            // copies each entity from container (either block or factory) in block
            foreach (PicEntity entity in container)
            {
                PicTypedDrawable entityNew = entity.Clone(block) as PicTypedDrawable;
                entityNew.Transform(transf);
                block._entities.Add(entityNew);
            }
            return(block);
        }
コード例 #12
0
ファイル: PicFactory.cs プロジェクト: treeDiM/PackLib4ES
 public void AddEntities(IEntityContainer container, Transform2D transform)
 {
     foreach (PicEntity entityIn in container)
     {
         if (null == entityIn)
         {
             continue;
         }
         PicTypedDrawable entityOut = (entityIn.Clone(this)) as PicTypedDrawable;
         entityOut.Transform(transform);
         _entities.Add(entityOut);
     }
 }
コード例 #13
0
ファイル: PicFilter.cs プロジェクト: treeDiM/PackLib4ES
        // override PicFilter
        public override bool Accept(PicEntity entity)
        {
            PicTypedDrawable drawable = entity as PicTypedDrawable;

            if (null == drawable)
            {
                return(false);
            }
            else
            {
                return(drawable.LineType == _lt);
            }
        }
コード例 #14
0
ファイル: PicFactory.cs プロジェクト: treeDiM/PackLib4ES
 /// <summary>
 /// Adds any entity in the list of entities and updates groups, layers...
 /// </summary>
 /// <param name="entity">Entity being added</param>
 protected void AddEntity(PicEntity entity)
 {
     _entities.Add(entity);
     if (null != EntityAdded)
     {
         EntityAdded(entity);
     }
     if (entity is PicTypedDrawable)
     {
         PicTypedDrawable drawable = entity as PicTypedDrawable;
         TryAddGroup(drawable.Group);
         TryAddLayer(drawable.Layer);
     }
 }
コード例 #15
0
ファイル: PicFilter.cs プロジェクト: treeDiM/PackLib4ES
        public override bool Accept(PicEntity entity)
        {
            if (null == _layers)
            {
                return(true);
            }
            PicTypedDrawable typedDrawable = entity as PicTypedDrawable;

            if (null == typedDrawable)
            {
                return(false);
            }
            return(_layers.Contains(typedDrawable.Layer));
        }
コード例 #16
0
        public void ExportEntity(ExpBlock block, PicEntity entity)
        {
            PicTypedDrawable drawable = entity as PicTypedDrawable;
            ExpLayer         layer    = null;
            ExpPen           pen      = null;

            if (null != drawable)
            {
                pen   = _exporter.GetPenByAttribute(LineTypeToExpPen(drawable.LineType));
                layer = _exporter.GetLayerByName(string.Format("Layer {0}", drawable.Layer));
            }
            PicSegment seg = entity as PicSegment;

            if (null != seg)
            {
                _exporter.AddSegment(block, layer, pen, seg.Pt0.X, seg.Pt0.Y, seg.Pt1.X, seg.Pt1.Y);
            }
            PicArc arc = entity as PicArc;

            if (null != arc)
            {
                // using dxf conversions
                double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg;
                if (ang < 0.0)
                {
                    angd += ang; ango = -ang;
                }
                else
                {
                    ango = ang;
                }
                _exporter.AddArc(block, layer, pen, arc.Center.X, arc.Center.Y, arc.Radius, angd, angd + ango);
            }
            PicCotationDistance cotation = drawable as PicCotationDistance;

            if (null != cotation)
            {
                List <Segment> segments = new List <Segment>();
                Vector2D       textPt   = Vector2D.Zero;
                double         textSize = 0.0;
                cotation.DrawSeg(ref segments, ref textPt, ref textSize);
                foreach (Segment cotSeg in segments)
                {
                    _exporter.AddSegment(block, layer, pen, cotSeg.P0.X, cotSeg.P0.Y, cotSeg.P1.X, cotSeg.P1.Y);
                }
                _exporter.AddText(block, layer, pen, textPt.X, textPt.Y, cotation.Text);
            }
        }
コード例 #17
0
        private static double DistanceEntityPt(PicTypedDrawable entity, Vector2D pt)
        {
            PicSegment seg = entity as PicSegment;

            if (null != seg)
            {
                return(Math.Min((seg.Pt0 - pt).GetLength(), (seg.Pt1 - pt).GetLength()));
            }
            PicArc arc = entity as PicArc;

            if (null != arc)
            {
                return(Math.Min((arc.Source - pt).GetLength(), (arc.Target - pt).GetLength()));
            }
            return(0.0);
        }
コード例 #18
0
 protected override bool Evaluate()
 {
     _box.Reset();
     foreach (PicEntity entity in _entities)
     {
         PicDrawable drawable = entity as PicDrawable;
         if (null != drawable)
         {
             PicTypedDrawable typeDrawable = drawable as PicTypedDrawable;
             if (null == typeDrawable || typeDrawable.LineType != PicGraphics.LT.LT_CONSTRUCTION)
             {
                 _box.Extend(drawable.ComputeBox(Transform2D.Identity));
             }
         }
     }
     return(true);
 }
コード例 #19
0
        public override Box2D ComputeBox(Transform2D transform)
        {
            Box2D box = Box2D.Initial;

            foreach (PicEntity entity in _block)
            {
                PicDrawable drawable = entity as PicDrawable;
                if (null != drawable)
                {
                    PicTypedDrawable typeDrawable = drawable as PicTypedDrawable;
                    if (null == typeDrawable || typeDrawable.LineType != PicGraphics.LT.LT_CONSTRUCTION)
                    {
                        box.Extend(drawable.ComputeBox(transform * BlockTransformation));
                    }
                }
            }
            return(box);
        }
コード例 #20
0
        public override void ProcessEntity(PicEntity entity)
        {
            if (entity.Code != PicEntity.eCode.PE_BLOCKREF)
            {
                PicTypedDrawable drawable = entity as PicTypedDrawable;
                if (null == drawable)
                {
                    return;
                }
                double totalLength = drawable.Length;
                if (_dictionnaryLength.ContainsKey(drawable.LineType))
                {
                    totalLength += _dictionnaryLength[drawable.LineType];
                }
                _dictionnaryLength[drawable.LineType] = totalLength;
            }
            else
            {
                PicBlockRef blockRef = entity as PicBlockRef;
                PicBlock    block    = blockRef.Block;

                foreach (PicEntity blockEntity in block)
                {
                    PicTypedDrawable innerDrawable = blockEntity as PicTypedDrawable;
                    if (null == innerDrawable)
                    {
                        continue;
                    }

                    double totalLength = innerDrawable.Length;
                    if (_dictionnaryLength.ContainsKey(innerDrawable.LineType))
                    {
                        totalLength += _dictionnaryLength[innerDrawable.LineType];
                    }
                    _dictionnaryLength[innerDrawable.LineType] = totalLength;
                }
            }
        }
コード例 #21
0
        public void CreateEntities(PicFactory factory)
        {
            if (null == _entities)
            {
                return;
            }
            // show entities
            for (int i = 0; i < Math.Min(_entities.Count, trackBarEntities.Value); ++i)
            {
                PicTypedDrawable entity = _entities[i];
                PicSegment       seg    = entity as PicSegment;
                if (null != seg)
                {
                    factory.AddSegment(seg.LineType, seg.Group, seg.Layer, seg.Pt0, seg.Pt1);
                }

                PicArc arc = entity as PicArc;
                if (null != arc)
                {
                    factory.AddArc(arc.LineType, arc.Group, arc.Layer, arc.Center, arc.Radius, arc.AngleBeg, arc.AngleEnd);
                }
            }
        }
コード例 #22
0
        public override void ProcessEntity(PicEntity entity)
        {
            PicTypedDrawable drawable = entity as PicTypedDrawable;

            if (entity is PicSegment || entity is PicArc)
            {
                ExpBlock defblock = _exporter.GetBlockOrCreate("default");
                ExportEntity(defblock, entity);
            }
            PicBlock block = entity as PicBlock;

            if (null != block)
            {
                // create block
                ExpBlock expBlock = _exporter.CreateBlock(string.Format("Block_{0}", block.Id));
                // create _x=0.0 _y=0.0
                ExpBlockRef expBlockRef = _exporter.CreateBlockRef(expBlock);
                // create entities
                foreach (PicEntity blockEntity in block.Entities)
                {
                    ExportEntity(expBlock, blockEntity);
                }
            }
            PicBlockRef blockRef = entity as PicBlockRef;

            if (null != blockRef)
            {
                // retrieve previously created block
                ExpBlock    expBlock    = _exporter.GetBlock(string.Format("Block_{0}", blockRef.Block.Id));
                ExpBlockRef expBlockRef = _exporter.CreateBlockRef(expBlock);
                expBlockRef._x      = blockRef.Position.X;
                expBlockRef._y      = blockRef.Position.Y;
                expBlockRef._dir    = blockRef.Angle;
                expBlockRef._scaleX = 1.0;
                expBlockRef._scaleY = 1.0;
            }
        }
コード例 #23
0
        /// <summary>
        /// ProcessEntity : write entity corresponding dxf description in line buffer
        /// </summary>
        /// <param name="entity">Entity</param>
        public override void ProcessEntity(PicEntity entity)
        {
            PicTypedDrawable drawable = (PicTypedDrawable)entity;

            if (null != drawable)
            {
                switch (drawable.Code)
                {
                case PicEntity.ECode.PE_POINT:
                    break;

                case PicEntity.ECode.PE_SEGMENT:
                {
                    PicSegment seg = (PicSegment)entity;
                    dxf.WriteLine(
                        dw
                        , new DL_LineData(
                            seg.Pt0.X                   // start point
                            , seg.Pt0.Y
                            , 0.0
                            , seg.Pt1.X         // end point
                            , seg.Pt1.Y
                            , 0.0
                            , InternalLineTypeToDxfColor(seg.LineType)
                            , "0"
                            )
                        , new DL_Attributes("0", InternalLineTypeToDxfColor(seg.LineType), -1, InternalLineTypeToDxfLineType(seg.LineType))
                        );
                }
                break;

                case PicEntity.ECode.PE_ARC:
                {
                    PicArc arc = (PicArc)entity;
                    double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg;
                    if (ang < 0.0)
                    {
                        angd += ang;
                        ango  = -ang;
                    }
                    else
                    {
                        ango = ang;
                    }

                    dxf.WriteArc(dw,
                                 new DL_ArcData(
                                     arc.Center.X, arc.Center.Y, 0.0,
                                     arc.Radius,
                                     angd, angd + ango,
                                     InternalLineTypeToDxfColor(arc.LineType),
                                     "0"
                                     ),
                                 new DL_Attributes("0", InternalLineTypeToDxfColor(arc.LineType), -1, InternalLineTypeToDxfLineType(arc.LineType))
                                 );
                }
                break;

                case PicEntity.ECode.PE_COTATIONDISTANCE:
                case PicEntity.ECode.PE_COTATIONHORIZONTAL:
                case PicEntity.ECode.PE_COTATIONVERTICAL:
                {
                    PicCotationDistance cotation = entity as PicCotationDistance;
                    List <Segment>      segments = new List <Segment>();
                    Vector2D            textPt   = Vector2D.Zero;
                    double textSize = 0.0;
                    cotation.DrawSeg(ref segments, ref textPt, ref textSize);
                    // draw segments
                    foreach (Segment seg in segments)
                    {
                        dxf.WriteLine(dw,
                                      new DL_LineData(
                                          seg.P0.X, seg.P0.Y, 0.0,
                                          seg.P1.X, seg.P1.Y, 0.0,
                                          InternalLineTypeToDxfColor(cotation.LineType),
                                          "0"
                                          ),
                                      new DL_Attributes("0", InternalLineTypeToDxfColor(cotation.LineType), -1, InternalLineTypeToDxfLineType(cotation.LineType))
                                      );
                    }
                    // draw text
                    dxf.WriteText(dw,
                                  new DL_TextData(
                                      textPt.X, textPt.Y, 0.0,
                                      textPt.X, textPt.Y, 0.0,
                                      textSize, 1.0, 0,
                                      1, 2, cotation.Text, "STANDARD", 0.0),
                                  new DL_Attributes("0", InternalLineTypeToDxfColor(cotation.LineType), -1, InternalLineTypeToDxfLineType(cotation.LineType)));
                }
                break;

                case PicEntity.ECode.PE_ELLIPSE:
                    break;

                case PicEntity.ECode.PE_NURBS:
                    break;

                default:
                    throw new Exception("Can not export this kind of entity!");
                }
            }
        }
コード例 #24
0
        /// <summary>
        /// ProcessEntity : write entity corresponding dxf description in line buffer
        /// </summary>
        /// <param name="entity">Entity</param>
        public override void ProcessEntity(PicEntity entity)
        {
            PicTypedDrawable drawable = (PicTypedDrawable)entity;

            if (null != drawable)
            {
                switch (drawable.Code)
                {
                case PicEntity.eCode.PE_POINT:
                    break;

                case PicEntity.eCode.PE_SEGMENT:
                {
                    PicSegment seg = (PicSegment)entity;
                    dxf.writeLine(
                        dw
                        , new DL_LineData(
                            seg.Pt0.X                   // start point
                            , seg.Pt0.Y
                            , 0.0
                            , seg.Pt1.X         // end point
                            , seg.Pt1.Y
                            , 0.0
                            , 256
                            , LineTypeToDxfLayer(seg.LineType)
                            )
                        , new DL_Attributes(LineTypeToDxfLayer(seg.LineType), 256, -1, "BYLAYER")
                        );
                }
                break;

                case PicEntity.eCode.PE_ARC:
                {
                    PicArc arc = (PicArc)entity;
                    double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg;
                    if (ang < 0.0)
                    {
                        angd += ang;
                        ango  = -ang;
                    }
                    else
                    {
                        ango = ang;
                    }

                    dxf.writeArc(dw,
                                 new DL_ArcData(
                                     arc.Center.X, arc.Center.Y, 0.0,
                                     arc.Radius,
                                     angd, angd + ango,
                                     256,
                                     LineTypeToDxfLayer(arc.LineType)
                                     ),
                                 new DL_Attributes(LineTypeToDxfLayer(arc.LineType), 256, -1, "BYLAYER")
                                 );
                }
                break;

                case PicEntity.eCode.PE_ELLIPSE:
                    break;

                case PicEntity.eCode.PE_NURBS:
                    break;

                default:
                    throw new Exception("Can not export this kind of entity!");
                }
            }
        }
コード例 #25
0
        private void AddEntityLength(PicTypedDrawable drawable, Transform2D transf)
        {
            if (drawable.LineType != PicGraphics.LT.LT_CUT)
            {
                return;
            }
            const double epsilon = 1.0e-03;
            PicSegment   seg     = drawable as PicSegment;

            if (null != seg)
            {
                Segment s1Init = new Segment(transf.transform(seg.Pt0), transf.transform(seg.Pt1));

                // build a list for current segment
                List <Segment> segmentCurrent = new List <Segment>();
                segmentCurrent.Add(s1Init);

                foreach (Segment s0 in _segments)
                {
                    // are segment colinear ?
                    if (!SegmentMethods.AreSegmentsColinear(s0, s1Init, epsilon))
                    {
                        continue;
                    }
                    // get non-overlapping segments ?
                    for (int i1 = 0; i1 < segmentCurrent.Count; ++i1)
                    {
                        Segment s1 = segmentCurrent[i1];
                        // is s1.P0 on s0
                        double coordP0 = Vector2D.DotProduct(s1.P0 - s0.P0, s0.P1 - s0.P0) / (s0.P1 - s0.P0).GetLengthSquared();
                        // is s1.P1 on s0
                        double coordP1 = Vector2D.DotProduct(s1.P1 - s0.P0, s0.P1 - s0.P0) / (s0.P1 - s0.P0).GetLengthSquared();
                        // need to swap s1.P0 and s1.P1 ?
                        bool swapped = false;
                        if (coordP0 > coordP1)
                        {
                            swapped = true;
                            double temp = coordP0;
                            coordP0 = coordP1;
                            coordP1 = temp;
                        }
                        // compute non-overlapping segments
                        if ((coordP0 <= 0.0 && coordP1 <= 0.0) || (coordP0 >= 1.0 && coordP1 >= 1.0))
                        {
                            /* no overlapp */
                        }
                        else if ((coordP0 >= 0.0 && coordP0 <= 1.0) && (coordP1 >= 1))
                        {
                            //-------S0P0---------S1P0---------S0P1--------S1P1--------
                            segmentCurrent.RemoveAt(i1);
                            segmentCurrent.Add(new Segment(s0.P1, swapped ? s1.P0 : s1.P1));
                        }
                        else if ((coordP0 <= 0.0) && (coordP1 >= 0 && coordP1 <= 1))
                        {
                            //-------S1P0---------S0P0---------S1P1--------S0P1--------
                            segmentCurrent.RemoveAt(i1);
                            segmentCurrent.Add(new Segment(swapped ? s1.P1 : s1.P0, s0.P0));
                        }
                        else if ((coordP0 <= 0.0) && (coordP1 >= 1.0))
                        {
                            //-------S1P0--------S0P0----------S0P1--------S1P1---------
                            segmentCurrent.RemoveAt(i1);
                            segmentCurrent.Add(new Segment(swapped ? s1.P1 : s1.P0, s0.P0));
                            segmentCurrent.Add(new Segment(s0.P1, swapped ? s1.P0 : s1.P1));
                        }
                        else if ((coordP0 >= 0.0) && (coordP1 <= 1.0))
                        {
                            //-------S0P0--------S1P0----------S1P1--------S0P1---------
                            segmentCurrent.RemoveAt(i1);
                        }
                    }
                }

                foreach (Segment s in segmentCurrent)
                {
                    // length of remaining segment
                    double segLength = (s.P1 - s.P0).GetLength();
                    // add length
                    _length += segLength;
                    // add to
                    if (segLength > epsilon)
                    {
                        _segments.Add(s);
                    }
                }
            }
            else
            {
                _length += drawable.Length;
            }
        }