コード例 #1
0
        private void lPartsLvw_SelectedIndexChanged(object sender, EventArgs e)
        {
            lChangingFromControl = true;

            if ((lDesignObject != null) && (lPartsLvw.SelectedItems.Count == 1))
            {
                lCurrDesignElement = (DesignElementRect)lDesignObject.GetDesignElementByName(lPartsLvw.SelectedItems[0].Text);
            }
            else
            {
                lCurrDesignElement = null;
            }

            if (lCurrDesignElement != null)
            {
                lSetPartEntryControlsState(true);

                lPartNameTbx.Text   = lCurrDesignElement.Name;
                lPartWidthTbx.Text  = lCurrDesignElement.DimensionX.ToString();
                lPartHeightTbx.Text = lCurrDesignElement.DimensionZ.ToString();
                lPartDepthTbx.Text  = lCurrDesignElement.DimensionY.ToString();
                if (lCurrDesignElement.AttachmentPoint != null)
                {
                    lPrimaryAttachmentRbtn.Checked = true;
                    lPlaceByMidpointRbtn.Checked   = false;
                    lSetPositionByRelationControlsState(false);
                    lSetAttachmentPointByAttachmentName(lCurrDesignElement.AttachmentPoint.AttachmentName);
                    lSetAttachmentControlsByCurrentDesignElement();
                }
                else
                {
                    lPlaceByMidpointRbtn.Checked   = true;
                    lPrimaryAttachmentRbtn.Checked = false;
                    lSetPositionByRelationControlsState(true);

                    lPartMidXTbx.Text = lCurrDesignElement.Midpoint.X.ToString();
                    lPartMidYTbx.Text = lCurrDesignElement.Midpoint.Y.ToString();
                    lPartMidZTbx.Text = lCurrDesignElement.Midpoint.Z.ToString();
                }
                lSecondaryAttachmentsLvw.Items.Clear();
                // GWH UNFINISHED CODE--WILL HANDLE WHEN SECONDARY ATTACHMENTS HAVE BEEN ADDED TO DESIGN ELEMENT
            }
            else
            {
                lPartNameTbx.Text              = "";
                lPartWidthTbx.Text             = "";
                lPartHeightTbx.Text            = "";
                lPartDepthTbx.Text             = "";
                lPlaceByMidpointRbtn.Checked   = false;
                lPartMidXTbx.Text              = "";
                lPartMidYTbx.Text              = "";
                lPartMidZTbx.Text              = "";
                lPrimaryAttachmentRbtn.Checked = false;
                lPrimaryAttachmentCbx.Text     = "";
                lSecondaryAttachmentsLvw.Items.Clear();
                lSetPartEntryControlsState(false);
            }

            lChangingFromControl = false;
        }
コード例 #2
0
        public override DesignElement Duplicate()
        {
            DesignElementRect newde = new DesignElementRect();
            int ndx = 0;

            newde.Name = Name;
            newde.lMidpoint.SetPoint(lMidpoint);
            newde.lDimensionX = lDimensionX;
            newde.lDimensionY = lDimensionY;
            newde.lDimensionZ = lDimensionZ;

            for (ndx = 0; ndx < Points.Length; ndx++)
            {
                newde.Points[ndx].SetPoint(Points[ndx]);
                newde.TempFigurePoints[ndx].SetPoint(TempFigurePoints[ndx]);
                newde.ProjectedPoints[ndx].SetPoint(ProjectedPoints[ndx]);
            }
            newde.lSetPlanes();
            newde.lSetProjectedPlanes();

            if (lAttachmentPoint != null)
            {
                newde.lAttachmentPoint = new DesignAttachmentParameters();
                newde.lAttachmentPoint.SetFromAttachmentPoint(lAttachmentPoint);
            }

            return(newde);
        }
コード例 #3
0
        private void lDesignLoad()
        {
            bool uiupdate = lChangingFromControl;

            lChangingFromControl  = true;
            lTSDesignFileCbx.Text = "";
            lChangingFromControl  = uiupdate;

            if ((lDesignFilePath.Length > 0) && File.Exists(lDesignFilePath))
            {
                lDesignObject = DesignObject.LoadDesignObject(lDesignFilePath);

                if (lDesignObject != null)
                {
                    lDesignCtrl.SetDesignObject(lDesignObject);
                    lDesignCtrl.ShowAxes = lAppPrefs.ShowAxes;
                    lDesignCtrl.ResetPosition();

                    lTSThetaLbl.Text   = lDesignCtrl.Theta.ToString("0.000");
                    lTSPhiLbl.Text     = lDesignCtrl.Phi.ToString("0.000");
                    lTSScalingCbx.Text = lDesignCtrl.Scaling.ToString("0.000");

                    lPartsLvw.BeginUpdate();
                    lPartsLvw.Items.Clear();

                    lPrimaryAttachmentCbx.BeginUpdate();
                    lPrimaryAttachmentCbx.Items.Clear();

                    // fill in parts list view
                    if (lDesignObject.Elements.Count > 0)
                    {
                        foreach (DesignElement tmpelem in lDesignObject.Elements)
                        {
                            DesignElementRect tmpelemr = (DesignElementRect)tmpelem;
                            lAddDesignElement(tmpelemr);
                        }
                    }

                    lPrimaryAttachmentCbx.EndUpdate();

                    lPartsLvw.EndUpdate();

                    StringHandler.AddStringToStartOfList(lAppPrefs.LastFiles, lDesignFilePath, 10);
                    lPopulateLastFilesListFromPrefs();

                    lChangingFromControl  = true;
                    lTSDesignFileCbx.Text = Path.GetFileName(lDesignFilePath);
                    lChangingFromControl  = uiupdate;
                }
            }
        }
コード例 #4
0
        private ListViewItem lAddDesignElement(DesignElementRect delem)
        {
            ListViewItem tmplv = new ListViewItem(delem.Name);

            tmplv.SubItems.Add(delem.DimensionX.ToString());
            tmplv.SubItems.Add(delem.DimensionY.ToString());
            tmplv.SubItems.Add(delem.DimensionZ.ToString());
            tmplv.SubItems.Add(lGetAttachmentLVStringText(delem));

            lPartsLvw.Items.Add(tmplv);

            lPrimaryAttachmentCbx.Items.Add(delem.Name);

            return(tmplv);
        }
コード例 #5
0
        private void lDeletePartBtn_Click(object sender, EventArgs e)
        {
            if ((lDesignObject != null) && (lCurrDesignElement != null))
            {
                ListViewItem tmplv = lGetLVItemForCurrentDesignElement();
                lDesignObject.Elements.Remove(lCurrDesignElement);

                lPartsLvw.BeginUpdate();
                lPartsLvw.Items.Remove(tmplv);
                lPartsLvw.EndUpdate();

                // force redraw, add item to listview and set listview selected index to the new item
                lDesignCtrl.ForceRedraw();
                lCurrDesignElement = null;
            }
        }
コード例 #6
0
        protected override void lRecalcPoints()
        {
            if ((lDimensionX != 0.0F) && (lDimensionY != 0.0F) && (lDimensionZ != 0.0F))
            {
                double x;
                double y;
                double z;
                double halfx = lDimensionX / 2.0F;
                double halfy = lDimensionY / 2.0F;
                double halfz = lDimensionZ / 2.0F;

                if (lAttachmentPoint != null)
                {
                    DesignElementRect attrect = (DesignElementRect)lAttachmentPoint.Attachment;
                    double            ownx    = lAttachmentPoint.GetOwnPointX(lDimensionX);
                    double            owny    = lAttachmentPoint.GetOwnPointY(lDimensionY);
                    double            ownz    = lAttachmentPoint.GetOwnPointZ(lDimensionZ);
                    double            attx    = lAttachmentPoint.GetAttachmentPointX();
                    double            atty    = lAttachmentPoint.GetAttachmentPointY();
                    double            attz    = lAttachmentPoint.GetAttachmentPointZ();
                    double            midx    = attx - ownx;
                    double            midy    = atty - owny;
                    double            midz    = attz - ownz;

                    lMidpoint.SetPoint(midx, midy, midz);
                }

                x = lMidpoint.X;
                y = lMidpoint.Y;
                z = lMidpoint.Z;

                Points[0].SetPoint(x + halfx, y + halfy, z + halfz);
                Points[1].SetPoint(x - halfx, y + halfy, z + halfz);
                Points[2].SetPoint(x - halfx, y - halfy, z + halfz);
                Points[3].SetPoint(x + halfx, y - halfy, z + halfz);
                Points[4].SetPoint(x + halfx, y + halfy, z - halfz);
                Points[5].SetPoint(x - halfx, y + halfy, z - halfz);
                Points[6].SetPoint(x - halfx, y - halfy, z - halfz);
                Points[7].SetPoint(x + halfx, y - halfy, z - halfz);

                lSetPlanes();
            }
        }
コード例 #7
0
        private void lDuplicatePartBtn_Click(object sender, EventArgs e)
        {
            if ((lDesignObject != null) && (lCurrDesignElement != null))
            {
                // add generic new part to design object
                DesignElementRect newrect = (DesignElementRect)lCurrDesignElement.Duplicate();
                newrect.Name = "New Rect";                  // GWH UNFINISHED CODE--FORCE UNIQUE NAME
                lDesignObject.Elements.Add(newrect);

                lPartsLvw.BeginUpdate();
                lPartsLvwClearSelection();
                ListViewItem newlv = lAddDesignElement(newrect);
                newlv.Selected = true;
                lPartsLvw.EndUpdate();

                // force redraw, add item to listview and set listview selected index to the new item
                newrect.UpdatePoints();
                lDesignCtrl.ForceRedraw();
                lCurrDesignElement = newrect;
            }
        }
コード例 #8
0
        public static DesignObject LoadDesignObject(string filename)
        {
            DesignObject dobj = null;

            string[] filetext = FileHandler.LoadFile(filename);

            if ((filetext != null) && (filetext.Length > 0))
            {
                char[]        eqdelim     = new char[] { '=' };
                char[]        commadelim  = new char[] { ',' };
                char[]        quotedelim  = new char[] { '"' };
                bool          error       = false;
                DesignElement currelement = null;
                int           posndx      = 0;

                dobj = new DesignObject();

                foreach (string fileline in filetext)
                {
                    string linetrim = fileline.Trim();

                    if ((linetrim.Length > 0) && (linetrim[0] != ';'))
                    {
                        string[] linetokens = linetrim.Split(eqdelim);

                        if (linetokens.Length == 2)
                        {
                            string varname = linetokens[0].ToLower();

                            if (currelement != null)
                            {
                                if (varname.Equals("name"))
                                {
                                    currelement.Name = linetokens[1];
                                }
                                else if (varname.Equals("objectend"))
                                {
                                    currelement = null;
                                }
                                else if (currelement.ElementType == DesignElement.ElementTypes.Rect)
                                {
                                    DesignElementRect rectelem = (DesignElementRect)currelement;

                                    if (varname.Equals("dimensions"))
                                    {
                                        string[] dimstrs = linetokens[1].Split(commadelim);

                                        if (dimstrs.Length == 3)
                                        {
                                            try
                                            {
                                                rectelem.DimensionX = Convert.ToDouble(dimstrs[0]);
                                                rectelem.DimensionY = Convert.ToDouble(dimstrs[1]);
                                                rectelem.DimensionZ = Convert.ToDouble(dimstrs[2]);
                                                rectelem.UpdatePoints();
                                            }
                                            catch (System.FormatException /*fex*/)
                                            {
                                                error = true;
                                            }
                                        }
                                        else
                                        {
                                            error = true;
                                        }
                                    }
                                    else if (varname.Equals("attach"))
                                    {
                                        string[] namestrs = linetokens[1].Split(quotedelim);

                                        if (namestrs.Length == 3)
                                        {
                                            string[] ownstrs  = namestrs[0].Split(commadelim, StringSplitOptions.RemoveEmptyEntries);
                                            string[] attrstrs = namestrs[2].Split(commadelim, StringSplitOptions.RemoveEmptyEntries);

                                            if ((ownstrs.Length == 3) && (attrstrs.Length == 3))
                                            {
                                                DesignAttachmentParameters dattach = new DesignAttachmentParameters(namestrs[1]);

                                                if (!dattach.SetAttachmentParametersFromStrings(attrstrs))
                                                {
                                                    error = true;
                                                }
                                                else if (!dattach.SetOwnParametersFromStrings(ownstrs))
                                                {
                                                    error = true;
                                                }

                                                rectelem.AttachmentPoint = dattach;
                                            }
                                            else
                                            {
                                                error = true;
                                            }
                                        }
                                        else
                                        {
                                            error = true;
                                        }
                                    }
                                    else if (varname.Equals("midpoint"))
                                    {
                                        string[] midstrs = linetokens[1].Split(commadelim);

                                        if (midstrs.Length == 3)
                                        {
                                            try
                                            {
                                                double midx = Convert.ToDouble(midstrs[0]);
                                                double midy = Convert.ToDouble(midstrs[1]);
                                                double midz = Convert.ToDouble(midstrs[2]);

                                                rectelem.Midpoint.SetPoint(midx, midy, midz);
                                                rectelem.UpdatePoints();
                                            }
                                            catch (System.FormatException /*fex*/)
                                            {
                                                error = true;
                                            }
                                        }
                                        else
                                        {
                                            error = true;
                                        }
                                    }
                                    else if (varname.Equals("position"))
                                    {
                                        string[] posstrs = linetokens[1].Split(commadelim);

                                        if ((posstrs.Length == 3) && (posndx < rectelem.Points.Length))
                                        {
                                            try
                                            {
                                                double midx = Convert.ToDouble(posstrs[0]);
                                                double midy = Convert.ToDouble(posstrs[1]);
                                                double midz = Convert.ToDouble(posstrs[2]);

                                                rectelem.Points[posndx].SetPoint(midx, midy, midz);
                                                posndx++;
                                            }
                                            catch (System.FormatException /*fex*/)
                                            {
                                                error = true;
                                            }
                                        }
                                        else
                                        {
                                            error = true;
                                        }
                                    }
                                    else
                                    {
                                        error = true;
                                    }
                                }
                                else
                                {
                                    error = true;
                                }
                            }
                            else if (varname.Equals("objectname"))
                            {
                                dobj.Name = linetokens[1];
                            }
                            else if (varname.Equals("measure"))
                            {
                                Units unitval;

                                if (Enum.TryParse(linetokens[1], true, out unitval) && Enum.IsDefined(typeof(Units), unitval))
                                {
                                    dobj.UnitType = unitval;
                                }
                                else
                                {
                                    error = true;
                                }
                            }
                            else if (varname.Equals("objectstart"))
                            {
                                if (currelement == null)
                                {
                                    DesignElement.ElementTypes etype;

                                    if (Enum.TryParse(linetokens[1], true, out etype) && Enum.IsDefined(typeof(DesignElement.ElementTypes), etype))
                                    {
                                        switch (etype)
                                        {
                                        case DesignElement.ElementTypes.Rect:
                                            currelement = new DesignElementRect();
                                            break;

                                        default:
                                            error = true;
                                            break;
                                        }

                                        if (currelement != null)
                                        {
                                            dobj.Elements.Add(currelement);
                                            posndx = 0;
                                        }
                                    }
                                    else
                                    {
                                        error = true;
                                    }
                                }
                                else
                                {
                                    error = true;
                                }
                            }
                        }
                        else
                        {
                            error = true;
                        }
                    }

                    if (error)
                    {
                        break;
                    }
                }

                if (error)
                {
                    dobj = null;
                }
                else
                {
                    // fill in any relative attachment point classes
                    if (dobj.Elements.Count > 0)
                    {
                        List <DesignElement> attelems = new List <DesignElement>();

                        // make a list of all elements that have a primary attachment
                        foreach (DesignElement tmpdelem in dobj.Elements)
                        {
                            lUpdateAttachmentPoints(dobj, tmpdelem);
                        }
                    }
                }
            }

            return(dobj);
        }