Beispiel #1
0
        /// <summary>
        /// Overgrown monster function that does everything. We need some refactoring here.
        /// </summary>
        public void ConnectSelection()
        {
            if (Properties.Settings.Default.IdiotLight)
            {
                if (PartSetup && mrb.IsDirty)
                {
                    if (System.Windows.Forms.MessageBox.Show(@"Save property changes?", @"Properties changed", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Write();
                    }
                }
                if (DrawSetup && drb.IsDirty)
                {
                    if (System.Windows.Forms.MessageBox.Show(@"Save property changes?", @"Properties changed", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Write();
                    }
                }
            }

            // Since I create objects and just toss them out liberally, I want to force garbage collection.
            // I think this leaves fewer GDI objects around. (This seems to be a good thing)
            System.GC.Collect(2, GCCollectionMode.Forced);
            prop.CutlistID = 0;
            if (Document != null)
            {
                // ignore clicks on the same object
                if (Document != md_last)
                {
                    // Blow out the propertyset so we can get new ones.
                    prop.Clear();

                    Enabled = true;
                    AddHash();

                    // what sort of doc is open?
                    swDocumentTypes_e docT     = swDocumentTypes_e.swDocNONE;
                    swDocumentTypes_e overDocT = swDocumentTypes_e.swDocNONE;
                    GetTypes(ref docT, ref overDocT);
                    switch (overDocT)
                    {
                    case swDocumentTypes_e.swDocASSEMBLY:
                        DisconnectAssemblyEvents();
                        SetupAssy((ModelDoc2)_swApp.ActiveDoc);
                        // a switch in a switch!
                        switch (docT)
                        {
                        case swDocumentTypes_e.swDocASSEMBLY:
                            regen_ok = true;
                            if (!PartSetup)
                            {
                                SetupPart();
                            }
                            if (!PartEventsAssigned)
                            {
                                ConnectPartEvents(prop.modeldoc);
                                PartSetup = true;
                            }
                            mrb.Update(ref prop);
                            break;

                        case swDocumentTypes_e.swDocDRAWING:
                            break;

                        case swDocumentTypes_e.swDocNONE:
                            break;

                        case swDocumentTypes_e.swDocPART:
                            regen_ok = true;
                            if (!PartSetup)
                            {
                                // ClearControls(this); // <-- redundant
                                // setup
                                SetupPart(prop.modeldoc);
                                // link
                                mrb.Update(ref prop);
                            }
                            else
                            {
                                DisconnectPartEvents();
                                ConnectPartEvents(prop.modeldoc);
                                PartSetup = true; // OK, this isn't how I meant to use this.
                                // or just link
                                mrb.Update(ref prop);
                            }
                            break;

                        case swDocumentTypes_e.swDocSDM:
                            break;

                        default:
                            break;
                        }
                        break;

                    case swDocumentTypes_e.swDocDRAWING:
                        regen_ok = false;
                        ClearControls(this);
                        SetupDrawing();
                        break;

                    case swDocumentTypes_e.swDocNONE:
                        SetupOther();
                        break;

                    case swDocumentTypes_e.swDocPART:
                        regen_ok = true;
                        if (!PartSetup)
                        {
                            // ClearControls(this); // <-- redundant
                            // setup
                            SetupPart(prop.modeldoc);
                            // link
                            mrb.Update(ref prop);
                        }
                        else
                        {
                            DisconnectPartEvents();
                            ConnectPartEvents(prop.modeldoc);
                            PartSetup = true; // OK, this isn't how I meant to use this.
                            // or just link
                            mrb.Update(ref prop);
                        }

                        break;

                    case swDocumentTypes_e.swDocSDM:
                        break;

                    default:
                        SetupOther();
                        break;
                    }
                }
                md_last = Document;
            }
            else
            {
                Enabled = false;
            }
#if EXPERIMENTAL
            if (Document != null)
            {
                Feature f        = (Feature)Document.FirstFeature();
                string  typeName = f.GetTypeName2();
                do
                {
                    f.GetNextSubFeature();
                    typeName = f.GetTypeName2();
                } while (typeName.ToUpper().Contains("FILE"));
                if (typeName != string.Empty)
                {
                    int res0 = SwApp.AddMenuPopupItem4(
                        (int)SolidWorks.Interop.swconst.swDocumentTypes_e.swDocASSEMBLY,
                        cookie,
                        typeName,
                        "Uaaaaaaaaaaaaaaaaa.........",
                        "donothing(1)",
                        "enablemethod(1)",
                        "pow",
                        "bip;bop"
                        );
                    int res1 = SwApp.AddMenuPopupItem4(
                        (int)SolidWorks.Interop.swconst.swDocumentTypes_e.swDocASSEMBLY,
                        cookie,
                        typeName,
                        "Ummmmmmmmmmmmmmm.........",
                        "donothing(2)",
                        "enablemethod(0)",
                        "pow",
                        "bip;bop"
                        );
                    int res2 = SwApp.AddMenuPopupItem(
                        (int)SolidWorks.Interop.swconst.swDocumentTypes_e.swDocASSEMBLY,
                        (int)SolidWorks.Interop.swconst.swSelectType_e.swSelBODYFEATURES,
                        typeName,
                        "donothing(2)",
                        "bip;bop"
                        );
                    (SwApp.Frame() as Frame).SetStatusBarText(
                        string.Format("Runtime Command IDs: {0}, {1}, {2} | Feature: {3}", res0, res1, res2, typeName)
                        );
                }
            }
#endif
        }