/// <summary>
            /// Get the block with an insertion with a layer different from the keep layer.
            /// </summary>
            /// <param name="insertLayer">The insert layer.</param>
            /// <returns>The block.</returns>
            private DxfBlock WithDifferentLayer(DxfLayer insertLayer)
            {
                if (blockWithDifferentLayerInsert == null)
                {
                    // CloneContext cc = new CloneContext(visitor.model, ReferenceResolutionType.CloneMissing);
                    CloneContext cc = new CloneContext(visitor.model, visitor.model, ReferenceResolutionType.CloneMissing);

                    blockWithDifferentLayerInsert = (DxfBlock)original.Clone(cc);
                    cc.ResolveReferences();
                    if (blockWithKeepLayerInsert != null)
                    {
                        // need different name for block
                        blockWithDifferentLayerInsert.Name += "-DIFF";
                    }
                    if (!visitor.HandleEntityCollection(blockWithDifferentLayerInsert.Entities,
                                                        insertLayer))
                    {
                        // no layer 0 entitites, so no need to have diffent blocks
                        blockWithKeepLayerInsert = blockWithDifferentLayerInsert;
                    }
                }
                return(blockWithDifferentLayerInsert);
            }
Ejemplo n.º 2
0
        public void ExportDwgToJpg(string destPath)
        {
            string sourcePath = String.Format("{0}{1}.dwg", DefaultDwgFolder, Control.ControlNo);
            Dictionary<string, string> dictDim = new Dictionary<string, string>();

            foreach (ControlDrawingDetail detail in ControlDrawingDetails)
            {
                if (dictDim.ContainsKey(detail.Dim.DimNo) == false)
                {
                    dictDim.Add(detail.Dim.DimNo, detail.DimValue);
                }
            }

            try
            {
                DxfModel readModel = DwgReader.Read(sourcePath);
                DxfModel writeModel = new DxfModel();
                CloneContext ct = new CloneContext(readModel, ReferenceResolutionType.CloneMissing);
                TransformConfig tc = new TransformConfig();
                Matrix4D translation = Transformation4D.Translation(250, 0, 0);

                ct.RenameClashingBlocks = true;

                for (int i = 0; i < readModel.Entities.Count; i++)
                {
                    DxfEntity block = readModel.Entities[i];

                    if (block.GetType() == typeof(DxfMText))
                    {
                        DxfMText di = (DxfMText)block;
                        if (dictDim.ContainsKey(di.SimplifiedText))
                        {
                            di.Text = dictDim[di.SimplifiedText];
                            di.Width = di.BoxWidth * 2;
                        }

                        writeModel.Entities.Add(di);
                    }
                    else if (block.GetType() == typeof(DxfText))
                    {
                        DxfText di = (DxfText)block;
                        if (dictDim.ContainsKey(di.SimplifiedText))
                        {
                            di.Text = dictDim[di.SimplifiedText];
                        }

                        writeModel.Entities.Add(di);
                    }
                    else
                    {
                        writeModel.Entities.Add(block);
                    }
                }

                ct.ResolveReferences();
                CADHelper.ExportToJpg(writeModel, destPath);
            }
            catch (Exception exc)
            {
                Tracing.Tracer.LogError(exc.Message);
                Logger.For(this).Error(exc.Message);
            }
        }
Ejemplo n.º 3
0
        public static void puzzle(List<string> dxfFileNameList,List<string> dxfTopViewList,List<TextValue> valueList,string frameName)
        {
            DxfModel targetModel=new DxfModel();
            testModel = targetModel;
            targetModel.TextStyles.Add(textStyle);
            CloneContext cloneContext = new CloneContext(targetModel, ReferenceResolutionType.CloneMissing);
            for (int i = 0; i < dxfFileNameList.Count;i++ )
            {
                    DxfModel sourceModel = DxfReader.Read(dxfFileNameList[i]);
                    //第一个图形作为初始
                    if (i == 0)
                    {
                        //拼到一个图纸中后,Entity应该参照那个的左下角坐标
                        location = getRelativeStartLocation(sourceModel);
                        //源图纸中Entity的左下角坐标
                        relativeStartLocation = getRelativeStartLocation(sourceModel);
                        //保存第一个算好的左下角坐标
                        firstDimensionLocation = location;
                        foreach (DxfEntity entity in sourceModel.Entities)
                        {
                            DxfEntity clonedEntity = (DxfEntity)entity.Clone(cloneContext);
                            clonedEntity = getCaculateLocationEntity(clonedEntity, location, relativeStartLocation);
                            targetModel.Entities.Add(clonedEntity);
                        }
                        rightLocation = getNextStartLocation(positionList);
                        //记录最后一点坐标
                        lastDimensionLocation = rightLocation;
                        //清空坐标位置链表
                        positionList.RemoveAll(name => { return true;});

                        //花标注
                        DxfDimension.Aligned dxfDimension = new DxfDimension.Aligned(targetModel.DefaultDimensionStyle);
                        dxfDimension.ExtensionLine1StartPoint = new Point3D(location.X, location.Y, location.Z);
                        dxfDimension.ExtensionLine2StartPoint = new Point3D(rightLocation.X, rightLocation.Y, rightLocation.Z);
                        dxfDimension.DimensionStyleOverrides.TextHeight = 56d;
                        dxfDimension.DimensionStyleOverrides.ArrowSize = 56d;
                        dxfDimension.Text = getDimensionText(dxfDimension);
                        // dxfDimension.DimensionLineLocation = new Point3D((location.X+rightLocation.X)/2,location.Y-8,location.Z);
                        targetModel.Entities.Add(dxfDimension);
                    }
                    else
                    {
                        location = rightLocation;
                        relativeStartLocation = getRelativeStartLocation(sourceModel);
                        foreach (DxfEntity entity in sourceModel.Entities)
                        {
                            DxfEntity clonedEntity = (DxfEntity)entity.Clone(cloneContext);
                            clonedEntity = getCaculateLocationEntity(clonedEntity, location, relativeStartLocation);
                            targetModel.Entities.Add(clonedEntity);
                        }
                        rightLocation = getNextStartLocation(positionList);
                        lastDimensionLocation = rightLocation;
                        //计算最后一个元素右上角坐标
                        if (i == dxfFileNameList.Count - 1)
                        {
                            rightTopDimensionLocation = getRightTopLocation(positionList);
                            largestLocation = getLargestXLocation(positionList);
                        }

                        positionList.RemoveAll(name => { return true; });

                        //花标注
                        DxfDimension.Aligned dxfDimension = new DxfDimension.Aligned(targetModel.DefaultDimensionStyle);
                        dxfDimension.ExtensionLine1StartPoint = new Point3D(location.X, location.Y, location.Z);
                        dxfDimension.ExtensionLine2StartPoint = new Point3D(rightLocation.X, rightLocation.Y, rightLocation.Z);
                        dxfDimension.DimensionStyleOverrides.TextHeight = 56d;
                        dxfDimension.DimensionStyleOverrides.ArrowSize = 56d;
                        dxfDimension.Text = getDimensionText(dxfDimension);
                        targetModel.Entities.Add(dxfDimension);
                    }
            }

            DxfDimension.Aligned wholeDxfDimension = new DxfDimension.Aligned(targetModel.DefaultDimensionStyle);
            wholeDxfDimension.ExtensionLine1StartPoint = new Point3D(firstDimensionLocation.X, firstDimensionLocation.Y, firstDimensionLocation.Z);
            wholeDxfDimension.ExtensionLine2StartPoint = new Point3D(lastDimensionLocation.X, lastDimensionLocation.Y, lastDimensionLocation.Z);
            wholeDxfDimension.DimensionStyleOverrides.TextHeight = 56d;
            wholeDxfDimension.DimensionStyleOverrides.ArrowSize = 56d;
            wholeDxfDimension.Text = getDimensionText(wholeDxfDimension);
            wholeDxfDimension.DimensionLineLocation = new Point3D(firstDimensionLocation.X+lastDimensionLocation.X,firstDimensionLocation.Y-1000,firstDimensionLocation.Z);
            targetModel.Entities.Add(wholeDxfDimension);

            DxfDimension.Aligned rightDimension = new DxfDimension.Aligned(targetModel.DefaultDimensionStyle);
            rightDimension.ExtensionLine1StartPoint = new Point3D(lastDimensionLocation.X, lastDimensionLocation.Y, lastDimensionLocation.Z);
            rightDimension.ExtensionLine2StartPoint = new Point3D(rightTopDimensionLocation.X, rightTopDimensionLocation.Y, rightTopDimensionLocation.Z);
            rightDimension.DimensionStyleOverrides.TextHeight = 56d;
            rightDimension.DimensionStyleOverrides.ArrowSize = 56d;
            rightDimension.Text = getDimensionText(rightDimension);
            rightDimension.DimensionLineLocation = new Point3D(largestLocation.X + 200, firstDimensionLocation.Y, firstDimensionLocation.Z);
            targetModel.Entities.Add(rightDimension);

            //绘制俯视图
            for (int i = 0; i < dxfTopViewList.Count;i++ )
            {
                DxfModel topViewSourceModel = new DxfModel();
                topViewSourceModel = DxfReader.Read(dxfTopViewList[i]);
                if (i == 0)
                {
                    topViewLocation = new DLocation(firstDimensionLocation.X, rightTopDimensionLocation.Y + RelativeDistance.yTopViewDistance, firstDimensionLocation.Z);
                    topViewRelativeLocation = getTopViewRelativeStartLocation(topViewSourceModel);
                }
                else
                {
                    topViewLocation = topViewRightLocation;
                        DxfModel filterModel = getFilterBottomNotLineDxfModel(topViewSourceModel);
                        topViewRelativeLocation = getTopViewRelativeStartLocation(filterModel);

                }

                foreach(DxfEntity entity in topViewSourceModel.Entities)
                {
                    DxfEntity clonedEntity = (DxfEntity)entity.Clone(cloneContext);
                    clonedEntity = getCaculateLocationEntity(clonedEntity, topViewLocation, topViewRelativeLocation);
                    targetModel.Entities.Add(clonedEntity);
                }
                topViewRightLocation = getTopViewNextStartLocation(positionList);
                positionList.RemoveAll(name=>{return true;});
            }

            // 复制frame框体
            DxfModel sourceFrameModel = new DxfModel();
            sourceFrameModel = DxfReader.Read(frameName);
            DLocation frameLeftDownLocation = getFrameLeftDownLocation(sourceFrameModel);
            frameLastLineX = getFrameLastVerticalLineX(sourceFrameModel);
            Point2D frameRightPoint2D = getFrameRightPoint(sourceFrameModel);
            //这里求的是宽度比较,因为Frame的最后位置还没确定,不能单纯的考个别点进行位置大小比较
            if ((largestLocation.X-firstDimensionLocation.X+RelativeDistance.xDistance)>= (frameRightPoint2D.X-frameLeftDownLocation.X))
            {
                RelativeDistance.increaseWidth = (largestLocation.X - firstDimensionLocation.X + RelativeDistance.xDistance) - (frameRightPoint2D.X - frameLeftDownLocation.X) + RelativeDistance.xDistance;
            }
            else
            {
                RelativeDistance.increaseWidth = 0;
            }
            foreach (DxfEntity entity in sourceFrameModel.Entities)
            {
                DxfEntity clonedEntity = (DxfEntity)entity.Clone(cloneContext);
                clonedEntity = getFrameEntity(clonedEntity, firstDimensionLocation, frameLeftDownLocation, RelativeDistance.increaseWidth);
                targetModel.Entities.Add(clonedEntity);
            }

            //传递表单数据值
            foreach(TextValue textValue in textValueList){
                foreach(TextValue transFormValue in valueList){
                    if (textValue.text.Equals(transFormValue.text))
                    {
                        DxfText dxfText = new DxfText();
                        dxfText.Text = transFormValue.value;
                        dxfText.Height = textValue.height;
                        dxfText.Thickness = 0.5d;
                        dxfText.AlignmentPoint1 = new Point3D(textValue.valuePosition.X, textValue.valuePosition.Y, textValue.valuePosition.Z);
                        dxfText.AlignmentPoint2 = dxfText.AlignmentPoint1;
                        targetModel.Entities.Add(dxfText);
                    }
                }
            }

            cloneContext.ResolveReferences();

            DxfWriter.Write("cloneTest.dxf", targetModel);
        }