Beispiel #1
0
        // update the tree.
        private void UpdateTree()
        {
            polyTreeView.Nodes.Clear();

            // append the root node.
            TreeNode rootNode = polyTreeView.Nodes.Add("Boundary Polygon");

            rootNode.ImageIndex         = 0;
            rootNode.SelectedImageIndex = 0;
            rootNode.Tag = m_polyMat.GetMatPolygon().GetID();

            // append the inner polygons.
            Poly2DListEx uselessHoleList = m_polyMat.GetUselessHoleList();

            for (int i = 0; i < uselessHoleList.Size(); i++)
            {
                Polygon2DEx poly = uselessHoleList.GetPolygonByIndex(i);

                String strNodeName = "Inner Polygon ";
                strNodeName += (i + 1);
                TreeNode polyNode = rootNode.Nodes.Add(strNodeName);
                polyNode.ImageIndex         = 0;
                polyNode.SelectedImageIndex = 0;
                polyNode.Tag = poly.GetID();
            }

            // expand the tree.
            polyTreeView.ExpandAll();
        }
Beispiel #2
0
        private void MaterialForm_Load(object sender, EventArgs e)
        {
            nameTextBox.Text  = m_mat.GetName();
            countTextBox.Text = m_mat.GetCount().ToString();

            if (m_mat.GetMatType() == MAT_TYPE_EX.MAT_EX_RECT)
            {
                RectMatEx rectMat = (RectMatEx)(m_mat);
                Rect2DEx  rect    = rectMat.GetBoundaryRect();
                widthTextBox.Enabled  = true;
                widthTextBox.Text     = rect.GetWidth().ToString("0.000");
                heightTextBox.Enabled = true;
                heightTextBox.Text    = rect.GetHeight().ToString("0.000");
            }
            else if (m_mat.GetMatType() == MAT_TYPE_EX.MAT_EX_POLY)
            {
                PolyMatEx   polyMat = (PolyMatEx)(m_mat);
                Polygon2DEx poly    = polyMat.GetMatPolygon();
                Rect2DEx    rect    = poly.GetBoundaryRect();
                widthTextBox.Enabled  = false;
                widthTextBox.Text     = rect.GetWidth().ToString("0.000");
                heightTextBox.Enabled = false;
                heightTextBox.Text    = rect.GetHeight().ToString("0.000");
            }
        }
Beispiel #3
0
        // draw the material.
        static public void DrawMat(MatEx mat, GlViewPortEx viewPort)
        {
            viewPort.SetDrawColor(Color.White);
            viewPort.SetLineWidth(1);

            if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_RECT)
            {
                RectMatEx   rectMat = (RectMatEx)mat;
                Rect2DEx    rect2D  = rectMat.GetBoundaryRect();
                Polygon2DEx poly    = new Polygon2DEx();
                poly.AddPoint(new Point2DEx(rect2D.GetXMin(), rect2D.GetYMin()));
                poly.AddPoint(new Point2DEx(rect2D.GetXMax(), rect2D.GetYMin()));
                poly.AddPoint(new Point2DEx(rect2D.GetXMax(), rect2D.GetYMax()));
                poly.AddPoint(new Point2DEx(rect2D.GetXMin(), rect2D.GetYMax()));
                viewPort.DrawPolygon(poly);
            }
            else if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_POLY)
            {
                PolyMatEx   polyMat = (PolyMatEx)mat;
                Polygon2DEx poly    = polyMat.GetMatPolygon();
                viewPort.DrawPolygon(poly);

                // draw the useless holes.
                Poly2DListEx uselessHoles = polyMat.GetUselessHoleList();
                for (int i = 0; i < uselessHoles.Size(); i++)
                {
                    viewPort.DrawPolygon(uselessHoles.GetPolygonByIndex(i));
                }
            }
        }
Beispiel #4
0
        // add material to list control.
        private void AddMat(MatEx mat)
        {
            // the boundary rect of the material.
            Rect2DEx boundaryRect = null;

            if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_RECT)
            {
                RectMatEx rectMat = (RectMatEx)mat;
                boundaryRect = rectMat.GetBoundaryRect();
            }
            else if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_POLY)
            {
                PolyMatEx   polyMat = (PolyMatEx)mat;
                Polygon2DEx polygon = polyMat.GetMatPolygon();
                boundaryRect = polygon.GetBoundaryRect();
            }

            /************************************************************************/
            // add a row to list control.

            // insert a row.
            int          iCount = matListView.Items.Count + 1;
            ListViewItem item   = matListView.Items.Add(iCount.ToString());

            // name column.
            item.SubItems.Add(mat.GetName());

            // material type column.
            if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_RECT)
            {
                item.SubItems.Add("矩形材料");
            }
            else if (mat.GetMatType() == MAT_TYPE_EX.MAT_EX_POLY)
            {
                item.SubItems.Add("不规则材料");
            }

            // the material height.
            item.SubItems.Add(boundaryRect.GetHeight().ToString("0.000"));

            // the material width.
            item.SubItems.Add(boundaryRect.GetWidth().ToString("0.000"));

            // the material count.
            item.SubItems.Add(mat.GetCount().ToString());

            // hold the ID.
            item.Tag = mat.GetID();
            /************************************************************************/

            // select the last row.
            matListView.SelectedItems.Clear();
            matListView.Items[matListView.Items.Count - 1].Selected = true;
            matListView.Items[matListView.Items.Count - 1].Focused  = true;
            matListView.Items[matListView.Items.Count - 1].EnsureVisible();
        }
Beispiel #5
0
        private void polyTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode treeNode = e.Node;

            // all polygons in material.
            Poly2DListEx poly2DList = new Poly2DListEx();

            poly2DList.AddPoly(m_polyMat.GetMatPolygon());
            poly2DList.AddPolyList(m_polyMat.GetUselessHoleList());

            // the selected polygon.
            long iPolygonID = (long)treeNode.Tag;

            m_selPoly = poly2DList.GetPolygonByID(iPolygonID);

            Invalidate();
        }
Beispiel #6
0
        private void reGenBtn_Click(object sender, EventArgs e)
        {
            // verify input.
            try
            {
                Convert.ToDouble(mergeDisTextBox.Text);
            }
            catch (FormatException exception)
            {
                MessageBox.Show("Incorrect input: " + exception.Message, "NestProfessor DEMO");
                return;
            }

            // re-generate the remnant material from the sheet.
            m_polyMat = NestFacadeEx.BuildRemnantMat(m_sheet, m_dConnectTol, Convert.ToDouble(mergeDisTextBox.Text));

            // update tree nodes.
            UpdateTree();

            /************************************************************************/
            // adjust the drawing area.

            // the boundary rect of all polygons in material.
            Poly2DListEx poly2DList = new Poly2DListEx();

            poly2DList.AddPoly(m_polyMat.GetMatPolygon());
            poly2DList.AddPolyList(m_polyMat.GetUselessHoleList());
            Rect2DEx geomRect = poly2DList.GetRectBox();

            // set the drawing area.
            Int32     iWidth       = matViewWnd.Right - matViewWnd.Left;
            Int32     iHeight      = matViewWnd.Bottom - matViewWnd.Top;
            Point2DEx leftBottomPt = new Point2DEx();
            double    dXDirRange   = m_matViewPort.GetFitAllParam(iWidth, iHeight, geomRect, 1.2, leftBottomPt);

            m_matViewPort.SetDrawingArea(1.1 * dXDirRange, iWidth, iHeight, leftBottomPt);

            m_selPoly = null;
            Invalidate();
            /************************************************************************/
        }
Beispiel #7
0
        private void RemnantMatInfoForm_Paint(object sender, PaintEventArgs e)
        {
            if (m_polyMat != null)
            {
                // all polygons in material.
                Poly2DListEx poly2DList = new Poly2DListEx();
                poly2DList.AddPoly(m_polyMat.GetMatPolygon());
                poly2DList.AddPolyList(m_polyMat.GetUselessHoleList());

                // clear screen and set the background color.
                m_matViewPort.BindRendContext();
                m_matViewPort.ClearScreen();
                m_matViewPort.SetBackgroundColor(Color.Black);

                // draw coordinate.
                m_matViewPort.SetDrawColor(Color.Blue);
                m_matViewPort.SetLineWidth(1);
                m_matViewPort.DrawCoordinate(0, 0, 0, false);

                // draw material polygons.
                m_matViewPort.SetDrawColor(Color.White);
                m_matViewPort.SetLineWidth(1);
                for (int i = 0; i < poly2DList.Size(); i++)
                {
                    Polygon2DEx poly      = poly2DList.GetPolygonByIndex(i);
                    ArrayList   lineItems = poly.GetLineList();
                    for (int j = 0; j < lineItems.Count; j++)
                    {
                        m_matViewPort.DrawLineItem((LineItemEx)lineItems[j]);
                    }
                }

                // draw selected polygon.
                if (m_selPoly != null)
                {
                    // hold the current drawing mode.
                    ROP_MODE_EX iOldRopMode = ROP_MODE_EX.ROP_EX_NORMAL;
                    m_matViewPort.GetROP(ref iOldRopMode);

                    // hold the current drawing width.
                    int iOldLineWid = m_matViewPort.GetLineWidth();

                    // hold the current drawing color.
                    Color oldColor = new Color();
                    m_matViewPort.GetDrawColor(ref oldColor);

                    // get the stipple mode.
                    bool   bOldStipple = false;
                    int    iOldRepeat  = 1;
                    ushort iOldPattern = 0xffff;
                    m_matViewPort.GetLineStipple(ref bOldStipple, ref iOldRepeat, ref iOldPattern);

                    // draw selected part placements.
                    m_matViewPort.SetROP(ROP_MODE_EX.ROP_EX_COPY);
                    m_matViewPort.SetLineWidth(2);
                    m_matViewPort.SetDrawColor(Color.Red);
                    m_matViewPort.SetLineStipple(true, 2, 0xcccc);
                    ArrayList lineItems = m_selPoly.GetLineList();
                    for (int j = 0; j < lineItems.Count; j++)
                    {
                        m_matViewPort.DrawLineItem((LineItemEx)lineItems[j]);
                    }

                    // restore the old drawer config.
                    m_matViewPort.SetROP(iOldRopMode);
                    m_matViewPort.SetLineWidth(iOldLineWid);
                    m_matViewPort.SetDrawColor(oldColor);
                    m_matViewPort.SetLineStipple(bOldStipple, iOldRepeat, iOldPattern);
                }

                // swap buffer to display the geometry.
                m_matViewPort.SwapBuffers();
            }
        }
Beispiel #8
0
        // load boundary polygon from dxf/dwg file.
        static public MatEx LoadMatFromDxfdwg(String strFilePath, NestParamEx nestParam)
        {
            MatEx mat = null;

            /************************************************************************/
            // load all geometry items from the dxf/dwg file.

            // the file name.
            int    iDotIndex   = strFilePath.LastIndexOf('.');
            int    iSlashIndex = strFilePath.LastIndexOf('\\');
            String strFileName = strFilePath.Substring(iSlashIndex + 1, iDotIndex - iSlashIndex - 1);

            // whether the file is dxf file or dwg file.
            bool   bDwg   = true;
            String strExt = strFilePath.Substring(iDotIndex, strFilePath.Length - iDotIndex);

            strExt = strExt.ToLower();
            if (strExt == ".dxf")
            {
                bDwg = false;
            }
            else if (strExt == ".dwg")
            {
                bDwg = true;
            }
            else
            {
                return(mat);
            }

            // extract geometry items from dxf/dwg file.
            ImpDataEx impData;

            if (!bDwg)
            {
                impData = NestFacadeEx.ExtractGeomItems(strFilePath);
            }
            else
            {
                // the temp folder for dxf.
                String strDxfPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                strDxfPath += "\\";
                strDxfPath += new Random().Next(1, 100000).ToString();
                strDxfPath += ".dxf";

                // save dxf file in tmp path.
                NestFacadeEx.Dwg2Dxf(strFilePath, strDxfPath);

                // extract geometry items from dxf file.
                impData = NestFacadeEx.ExtractGeomItems(strDxfPath);

                // delete the temp file.
                File.Delete(strDxfPath);
            }
            /************************************************************************/

            /************************************************************************/
            // get the polygons from the dxf/dwg file.

            // build the polygons of all the geometry items.
            GeomItemListEx geomItemList = impData.GetAllGeomItem();
            Poly2DListEx   polyList     = NestFacadeEx.BuildPolyListFromLineArc(geomItemList, nestParam.GetConTol());

            // if no closed polygon found, return.
            if (polyList.Size() == 0)
            {
                MessageBox.Show("No closed boundary found.", "NestProfessor DEMO");
                return(mat);
            }

            // the outer boundary polygon.
            int         iMaxIndex = polyList.GetMaxAreaPoly();
            Polygon2DEx outerPoly = polyList.GetPolygonByIndex(iMaxIndex);

            // the hole polygons.
            polyList.DelPolygonByIndex(iMaxIndex);
            Poly2DListEx holePolyList = polyList;
            /************************************************************************/

            /************************************************************************/
            // build the material object.

            // whether the boundary polygon is a rectangle.
            bool bRectMat = true;

            if (outerPoly.GetPtCount() != 4)
            {
                bRectMat = false;
            }
            else if (holePolyList.Size() > 0)
            {
                bRectMat = false;
            }
            else
            {
                // line items in the polygon.
                ArrayList  lineItems = outerPoly.GetLineList();
                LineItemEx lineItem1 = (LineItemEx)lineItems[0];
                LineItemEx lineItem2 = (LineItemEx)lineItems[1];
                LineItemEx lineItem3 = (LineItemEx)lineItems[2];
                LineItemEx lineItem4 = (LineItemEx)lineItems[3];

                if (Math.Abs(lineItem1.GetLength() - lineItem3.GetLength()) > 0.0001)
                {
                    bRectMat = false;
                }
                if (Math.Abs(lineItem2.GetLength() - lineItem4.GetLength()) > 0.0001)
                {
                    bRectMat = false;
                }

                Vector2DEx vect1 = lineItem1.GetBaseVector();
                Vector2DEx vect2 = lineItem2.GetBaseVector();
                if (!vect1.OrthogonalTo(vect2))
                {
                    bRectMat = false;
                }
            }

            // build the material object.
            if (bRectMat)
            {
                mat = new RectMatEx(strFileName, outerPoly.GetBoundaryRect(), 1);
            }
            else
            {
                PolyMatEx polyMat = new PolyMatEx(strFileName, outerPoly, 1);
                polyMat.SetUselessHoleList(holePolyList);
                mat = polyMat;
            }
            /************************************************************************/

            return(mat);
        }