Ejemplo n.º 1
0
        /// <summary>
        /// 布局线路 
        /// </summary>
        /// <param name="pshape"></param>
        void layeroutmx(BaseShape pshape)
        {
            ShapeCollection childshapes = pshape.GetChildShapes();

            if (pshape is MX1Shape)
            {
                MX1Shape mx1 = pshape as MX1Shape;
                mx1.Width           = Math.Max(mx1.Width, 40 * childshapes.Count);
                mx1.ConnectorNumber = childshapes.Count;
            }
            foreach (Connector cr in pshape.Connectors)
            {
                if (cr.ConnectorLocation == ConnectorLocation.South)
                {
                    foreach (Connection cn in cr.Connections)
                    {
                        Connector crto = cn.From;
                        if (cn.From == cr)
                        {
                            crto = cn.To;
                        }
                        if (!movedshapes.Contains(crto.BelongsTo))
                        {
                            movedshapes.Add(crto.BelongsTo);
                            PointF pf1  = crto.BelongsTo.ConnectionPoint(crto);
                            PointF pf2  = cr.BelongsTo.ConnectionPoint(cr);
                            float  offx = pf2.X - pf1.X;
                            float  offy = 50;
                            crto.BelongsTo.X += offx;
                            crto.BelongsTo.Y += offy;
                        }
                    }
                }
            }
            float xlright = 0;  //线路右边范围
            int   xlnum   = -1; //有设备的线路

            foreach (BaseShape sp1 in childshapes)
            {
                if (!layershapes.Contains(sp1))
                {
                    layershapes.Add(sp1);
                    {
                        if (sp1.GetChildShapes().Count > 1)
                        {
                            if (xlright > sp1.X)
                            {
                                sp1.X = xlright + 30;
                            }
                            if (sp1.DeviceType != "01")
                            {
                                sp1.Y -= xlnum * 3; xlnum++;
                            }
                            layeroutsb(sp1, ref xlright);
                        }
                    }
                }
            }
            curWidth = Math.Max(xlright, pshape.X + pshape.Width);
        }
Ejemplo n.º 2
0
        public void SelectUIShape(UIShapeBase shape)
        {
            if (m_bCopying == true)
            {
                return;
            }

            if (m_selectedShapeList.Contains(shape) == false)
            {
                m_selectedShapeList.Add(shape);                        // 선택에 넣음
            }
            if (shape == m_baseDialog || shape.Parent == m_baseDialog) // 작업 다이얼로그는 그대로
            {
                m_UIShapeList.Clear();

                foreach (ShapeBase child in m_baseDialog.ChildCollection)
                {
                    if (child is UIShapeBase)
                    {
                        m_UIShapeList.Add(child as UIShapeBase);
                    }
                }

                m_UIShapeList.Add(m_baseDialog); // 다이얼로그는 제일 마지막에 추가 ( 나중에 검색할때 가장 나중에 검색되도록 )

                return;
            }

            // 작업 다이얼로그가 변경됨
            if (shape is UIShapeDialog)
            {
                m_baseDialog = shape as UIShapeDialog;
            }
            else if (shape.Parent is UIShapeDialog)
            {
                m_baseDialog = shape.Parent as UIShapeDialog;
            }
            else
            {
                return;
            }

            m_UIShapeList.Clear();
            foreach (ShapeBase child in m_baseDialog.ChildCollection)
            {
                if (child is UIShapeBase)
                {
                    m_UIShapeList.Add(child as UIShapeBase);
                }
            }

            m_UIShapeList.Add(m_baseDialog); // 다이얼로그는 제일 마지막에 추가 ( 나중에 검색할때 가장 나중에 검색되도록 )
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Overridden save function
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public override bool Save(string filename)
        {
            PrefabDesc      prefab = new PrefabDesc(filename);
            ShapeCollection all    = new ShapeCollection();

            // the following shapes go into the prefab: lightgrid boxes, lights
            foreach (ShapeBase shape in this.FilteredSupplier)
            {
                all.Add(shape);
            }

            foreach (ShapeBase shape in this.FilteredLights)
            {
                if (!all.Contains(shape))
                {
                    all.Add(shape);
                }
            }

            if (!prefab.CreateFromInstances(all, Vector3F.Zero, false, false))
            {
                return(false);
            }
            return(prefab.SaveToFile(null));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Overridden save function
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public override bool Save(string filename)
        {
            PrefabDesc prefab = new PrefabDesc(filename);
              ShapeCollection all = new ShapeCollection();

              // the following shapes go into the prefab: lightgrid boxes, lights
              foreach (ShapeBase shape in this.FilteredSupplier)
            all.Add(shape);

              foreach (ShapeBase shape in this.FilteredLights)
            if (!all.Contains(shape))
              all.Add(shape);

              if (!prefab.CreateFromInstances(all, Vector3F.Zero, false, false))
            return false;
              return prefab.SaveToFile(null);
        }
Ejemplo n.º 5
0
        void CommonInit(ShapeCollection shapes, Shape3D.DropToFloorMode mode, Vector3F axis, bool includeShapes)
        {
            for (int i = 0; i < shapes.Count; i++)
            {
                Shape3D shape = shapes[i] as Shape3D;
                if (shape == null || !shape.Traceable || !shape.Modifiable)
                {
                    continue;
                }


                ShapeCollection colliderShapes = null;
                if (includeShapes)
                {
                    colliderShapes = EditorManager.Scene.AllShapesOfType(typeof(Shape3D), true);
                    if (colliderShapes.Contains(shape))
                    {
                        colliderShapes.Remove(shape);
                    }
                }

                // use a replacement action? (e.g. billboards rather want to drop every single instance)
                IAction custom = shape.GetCustomDropToFloorAction(mode, axis, colliderShapes);
                if (custom != null)
                {
                    this.Add(custom);
                    continue;
                }

                float fHeight = EditorApp.ActiveView.EngineManager.GetDropToFloorHeight(shape, mode, axis, colliderShapes);
                if (fHeight == 0.0f)
                {
                    continue;
                }
                this.Add(new MoveShapeAction(shape, shape.Position, shape.Position + axis * fHeight));
            }
        }
Ejemplo n.º 6
0
        private void SortSelectedShapes(MoveShapesDirection moveDirection)
        {
            ShapeCollection selected = shapeTreeView.SelectedShapes;

              // return if any of the indices is already on the maximum.
              foreach (ShapeBase shape in selected)
              {
            if (moveDirection == MoveShapesDirection.Up)
            {
              if (shape.Parent.ChildCollection.FindIndex(i => i == shape) <= 0)
            return;
            }
            else
              if (shape.Parent.ChildCollection.FindIndex(i => i == shape) >= shape.Parent.ChildCollection.Count - 1)
            return;
              }

              // get all parents to share modified collections between their children.
              ShapeCollection parents = new ShapeCollection();
              foreach (ShapeBase shape in selected)
            if (!parents.Contains(shape.Parent))
              parents.Add(shape.Parent);

              EditorManager.Actions.StartGroup("Sort Shapes");
              foreach (ShapeBase parent in parents)
              {
            // create copy of the original collection before sorting
            ShapeCollection copyOfChildren = new ShapeCollection();
            copyOfChildren.AddRange(parent.ChildCollection);

            if (moveDirection == MoveShapesDirection.Up)
            {
              for (int i = 0; i < selected.Count; i++)
              {
            ShapeBase child = selected[i];
            if (child.Parent == parent)
            {
              int index = copyOfChildren.FindIndex(c => c == child);
              copyOfChildren.Remove(child);
              copyOfChildren.Insert(index - 1, child);
              EditorManager.Actions.Add(new SortShapeChildrenAction(parent, copyOfChildren));
            }
              }
            }
            else
              for (int i = selected.Count - 1; i > -1; i--)
              {
            ShapeBase child = selected[i];
            if (child.Parent == parent)
            {
              int index = copyOfChildren.FindIndex(c => c == child);
              copyOfChildren.Remove(child);
              copyOfChildren.Insert(index + 1, child);
              EditorManager.Actions.Add(new SortShapeChildrenAction(parent, copyOfChildren));
            }
              }
              }
              EditorManager.Actions.EndGroup();

              // recover selection
              ArrayList newSelection = new ArrayList();
              foreach (ShapeTreeNode node in shapeTreeView.Nodes)
              {
            if (selected.Contains(node.shape)) // root
              newSelection.Add(node);
            foreach (ShapeTreeNode subNode in shapeTreeView.GetChildNodes(node))
            {
              if (selected.Contains(subNode.shape)) // all children
            newSelection.Add(subNode);
            }
              }
              shapeTreeView.SelectedNodes = newSelection;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Exports the part of the diagram that encloses all given shapes (plus margin on each side) to an image of the given format.
        /// Pass null/Nothing for Parameter shapes in order to expor the whole diagram area.
        /// </summary>
        /// <param name="imageFormat">Specifies the format of the graphics file.</param>
        /// <param name="shapes">The shapes that should be drawn. If null/Nothing, the whole diagram area will be exported.</param>
        /// <param name="margin">Specifies the thickness of the margin around the exported diagram area.</param>
        /// <param name="withBackground">Specifies whether the diagram's background should be exported to the graphics file.</param>
        /// <param name="backgroundColor">Specifies a color for the exported image's background. 
        /// If the diagram is exported with background, the diagram's background will be drawn over the specified background color.</param>
        /// <param name="dpi">Specifies the resolution for the export file. Only applies to pixel based image file formats.</param>
        public Image CreateImage(ImageFileFormat imageFormat, IEnumerable<Shape> shapes, int margin, bool withBackground, Color backgroundColor, int dpi)
        {
            Image result = null;

            // Get/Create info graphics
            bool disposeInfoGfx;
            Graphics infoGraphics;
            if (DisplayService != null) {
                infoGraphics = DisplayService.InfoGraphics;
                disposeInfoGfx = false;
            } else {
                infoGraphics = Graphics.FromHwnd(IntPtr.Zero);
                disposeInfoGfx = true;
            }

            try {
                // If dpi value is not valid, get current dpi from display service
                if (dpi <= 0)
                    dpi = (int)Math.Round((infoGraphics.DpiX + infoGraphics.DpiY) / 2f);

                // Get bounding rectangle around the given shapes
                Rectangle imageBounds = Rectangle.Empty;
                if (shapes == null) {
                    imageBounds.X = imageBounds.Y = 0;
                    imageBounds.Width = Width;
                    imageBounds.Height = Height;
                } else {
                    int left, top, right, bottom;
                    left = top = int.MaxValue;
                    right = bottom = int.MinValue;
                    // Calculate the bounding rectangle of the given shapes
                    Rectangle boundingRect = Rectangle.Empty;
                    foreach (Shape shape in shapes) {
                        boundingRect = shape.GetBoundingRectangle(true);
                        if (boundingRect.Left < left) left = boundingRect.Left;
                        if (boundingRect.Top < top) top = boundingRect.Top;
                        if (boundingRect.Right > right) right = boundingRect.Right;
                        if (boundingRect.Bottom > bottom) bottom = boundingRect.Bottom;
                    }
                    if (Geometry.IsValid(left, top, right, bottom))
                        imageBounds = Rectangle.FromLTRB(left, top, right, bottom);
                }
                imageBounds.Inflate(margin, margin);
                imageBounds.Width += 1;
                imageBounds.Height += 1;

                bool originalQualitySetting = this.HighQualityRendering;
                HighQualityRendering = true;
                UpdateBrushes();

                float scaleX = 1, scaleY = 1;
                switch (imageFormat) {
                    case ImageFileFormat.Svg:
                        throw new NotImplementedException();

                    case ImageFileFormat.Emf:
                    case ImageFileFormat.EmfPlus:
                        // Create MetaFile and graphics context
                        IntPtr hdc = infoGraphics.GetHdc();
                        try {
                            Rectangle bounds = Rectangle.Empty;
                            bounds.Size = imageBounds.Size;
                            result = new Metafile(hdc, bounds, MetafileFrameUnit.Pixel,
                                                (imageFormat == ImageFileFormat.Emf) ? EmfType.EmfOnly : EmfType.EmfPlusDual,
                                                Name);
                        } finally {
                            infoGraphics.ReleaseHdc(hdc);
                        }
                        break;

                    case ImageFileFormat.Bmp:
                    case ImageFileFormat.Gif:
                    case ImageFileFormat.Jpeg:
                    case ImageFileFormat.Png:
                    case ImageFileFormat.Tiff:
                        int imgWidth = imageBounds.Width;
                        int imgHeight = imageBounds.Height;
                        if (dpi > 0 && dpi != infoGraphics.DpiX || dpi != infoGraphics.DpiY) {
                            scaleX = dpi / infoGraphics.DpiX;
                            scaleY = dpi / infoGraphics.DpiY;
                            imgWidth = (int)Math.Round(scaleX * imageBounds.Width);
                            imgHeight = (int)Math.Round(scaleY * imageBounds.Height);
                        }
                        result = new Bitmap(Math.Max(1, imgWidth), Math.Max(1, imgHeight));
                        ((Bitmap)result).SetResolution(dpi, dpi);
                        break;

                    default:
                        throw new NShapeUnsupportedValueException(typeof(ImageFileFormat), imageFormat);
                }

                // Draw diagram
                using (Graphics gfx = Graphics.FromImage(result)) {
                    GdiHelpers.ApplyGraphicsSettings(gfx, RenderingQuality.MaximumQuality);

                    // Fill background with background color
                    if (backgroundColor.A < 255) {
                        if (imageFormat == ImageFileFormat.Bmp || imageFormat == ImageFileFormat.Jpeg) {
                            // For image formats that do not support transparency, fill background with the RGB part of
                            // the given backgropund color
                            gfx.Clear(Color.FromArgb(255, backgroundColor));
                        } else if (backgroundColor.A > 0) {
                            // Skip filling background for meta files if transparency is 100%:
                            // Filling Background with Color.Transparent causes graphical glitches with many applications
                            gfx.Clear(backgroundColor);
                        }
                    } else {
                        // Graphics.Clear() does not work as expected for classic EMF (fills only the top left pixel
                        // instead of the whole graphics context).
                        if (imageFormat == ImageFileFormat.Emf) {
                            using (SolidBrush brush = new SolidBrush(backgroundColor))
                                gfx.FillRectangle(brush, gfx.ClipBounds);
                        } else gfx.Clear(backgroundColor);
                    }

                    // Transform graphics (if necessary)
                    gfx.TranslateTransform(-imageBounds.X, -imageBounds.Y, MatrixOrder.Prepend);
                    if (scaleX != 1 || scaleY != 1) gfx.ScaleTransform(scaleX, scaleY, MatrixOrder.Append);

                    // Draw diagram background
                    if (withBackground) DrawBackground(gfx, imageBounds);
                    // Draw diagram shapes
                    if (shapes == null) {
                        foreach (Shape shape in diagramShapes.BottomUp) shape.Draw(gfx);
                    } else {
                        // Add shapes to ShapeCollection (in order to maintain zOrder while drawing)
                        int cnt = (shapes is ICollection) ? ((ICollection)shapes).Count : -1;
                        ShapeCollection shapeCollection = new ShapeCollection(cnt);
                        foreach (Shape s in shapes) {
                            // Sort out duplicate references to shapes (as they can occur in the result of Diagram.FindShapes())
                            if (shapeCollection.Contains(s)) continue;
                            shapeCollection.Add(s, s.ZOrder);
                        }
                        // Draw shapes
                        foreach (Shape shape in shapeCollection.BottomUp)
                            shape.Draw(gfx);
                        shapeCollection.Clear();
                    }
                    // Reset transformation
                    gfx.ResetTransform();
                }
                // Restore original graphics settings
                HighQualityRendering = originalQualitySetting;
                UpdateBrushes();

                return result;
            } finally {
                if (disposeInfoGfx)
                    GdiHelpers.DisposeObject(ref infoGraphics);
            }
        }