Exemplo n.º 1
0
 protected virtual void SwitchUnit(EvaluationUnit unit, bool recompute = true, bool recordEvent = true)
 {
     if (unit != null && (activeUnit == null || activeUnit != unit))
     {
         if (recordEvent)
         {
             this.RecordUndoEvent("Switch Unit", new GH_SwitchAction(this, unit.Name));
         }
         if (activeUnit != null)
         {
             staticData.UnregisterUnit(activeUnit);
             activeUnit.Active = false;
             activeUnit        = null;
         }
         staticData.RegisterUnit(unit);
         activeUnit        = unit;
         activeUnit.Active = true;
         GH_Document val = this.OnPingDocument();
         if (val != null)
         {
             val.Modified();
             val.DestroyAttributeCache();
             val.DestroyObjectTable();
         }
         if (this.Attributes != null)
         {
             ((GH_SwitcherComponentAttributes)this.Attributes).OnSwitchUnit();
         }
         if (unit.DisplayName != null)
         {
             this.SetIconOverride(unit.Icon);
         }
         if (this.Attributes != null)
         {
             this.Attributes.ExpireLayout();
         }
         if (recompute)
         {
             this.ExpireSolution(true);
         }
     }
 }
Exemplo n.º 2
0
        private void ComposeMenu()
        {
            GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)base.Owner;

            composedCollection = new GH_MenuCollection();
            EvaluationUnit activeUnit = gH_SwitcherComponent.ActiveUnit;

            if (activeUnit != null && activeUnit.Context.Collection != null)
            {
                composedCollection.Merge(gH_SwitcherComponent.ActiveUnit.Context.Collection);
            }
            if (collection != null)
            {
                composedCollection.Merge(collection);
            }
            if (unitMenuCollection != null)
            {
                composedCollection.Merge(unitMenuCollection);
            }
        }
Exemplo n.º 3
0
        public void ClearUnit(bool recompute = true, bool recordEvent = true)
        {
            if (!UnitlessExistence)
            {
                return;
            }
            if (activeUnit != null)
            {
                if (recordEvent)
                {
                    this.RecordUndoEvent("Switch Unit", new GH_SwitchAction(this, null));
                }
                staticData.UnregisterUnit(activeUnit);
                activeUnit.Active = false;
                activeUnit        = null;
            }
            GH_Document val = this.OnPingDocument();

            if (val != null)
            {
                val.Modified();
                val.DestroyAttributeCache();
                val.DestroyObjectTable();
            }
            if (this.Attributes != null)
            {
                ((GH_SwitcherComponentAttributes)this.Attributes).OnSwitchUnit();
            }
            this.Name        = staticData.CachedName;
            this.NickName    = staticData.CachedNickname;
            this.Description = staticData.CachedDescription;
            this.SetIconOverride(staticData.CachedIcon);
            if (this.Attributes != null)
            {
                this.Attributes.ExpireLayout();
            }
            if (recompute)
            {
                this.ExpireSolution(true);
            }
        }
Exemplo n.º 4
0
        public void OnSwitchUnit()
        {
            EvaluationUnit activeUnit = ((GH_SwitcherComponent)base.Owner).ActiveUnit;

            ComposeMenu();
            if (activeUnit != null)
            {
                if (_UnitDrop != null)
                {
                    int num = _UnitDrop.FindIndex(activeUnit.Name);
                    if (num != -1)
                    {
                        _UnitDrop.Value = num;
                    }
                }
            }
            else if (((GH_SwitcherComponent)base.Owner).UnitlessExistence && _UnitDrop != null)
            {
                _UnitDrop.Value = 0;
            }
        }
Exemplo n.º 5
0
 private void _UnitDrop__valueChanged(object sender, EventArgs e)
 {
     try
     {
         MenuDropDown       menuDropDown = (MenuDropDown)sender;
         MenuDropDown.Entry entry        = menuDropDown.Items[menuDropDown.Value];
         if (entry.data != null)
         {
             EvaluationUnit evaluationUnit = (EvaluationUnit)entry.data;
             ((GH_SwitcherComponent)base.Owner).SwitchUnit(evaluationUnit.Name);
         }
         else
         {
             ((GH_SwitcherComponent)base.Owner).ClearUnit();
         }
     }
     catch (Exception ex)
     {
         RhinoApp.WriteLine("Error selection:" + ex.StackTrace);
     }
 }
Exemplo n.º 6
0
        private void SetupEvaluationUnits()
        {
            if (activeUnit != null)
            {
                throw new ArgumentException("Invalid switcher state. No evaluation unit must be active at this point.");
            }
            EvaluationUnit evaluationUnit = GetUnit(DefaultEvaluationUnit);

            if (evaluationUnit == null && !UnitlessExistence)
            {
                if (EvalUnits.Count == 0)
                {
                    throw new ArgumentException("Switcher has no evaluation units registered and UnitlessExistence is false.");
                }
                evaluationUnit = EvalUnits[0];
            }
            if (this.OnPingDocument() != null)
            {
                RhinoApp.WriteLine("Component belongs to a document at a stage where it should not belong to one.");
            }
            SwitchUnit(evaluationUnit, recompute: false, recordEvent: false);
        }
 public void RegisterUnit(EvaluationUnit unit)
 {
     stcInputs.Clear();
     stcOutputs.Clear();
     dynInputs.Clear();
     dynOutputs.Clear();
     foreach (IGH_Param item in component.Params.Input)
     {
         stcInputs.Add(item);
     }
     foreach (IGH_Param item2 in component.Params.Output)
     {
         stcOutputs.Add(item2);
     }
     foreach (ExtendedPlug input in unit.Inputs)
     {
         component.Params.RegisterInputParam(input.Parameter);
         if (input.IsMenu)
         {
             dynInputs.Add(input.Parameter);
         }
         else
         {
             stcInputs.Add(input.Parameter);
         }
     }
     foreach (ExtendedPlug output in unit.Outputs)
     {
         component.Params.RegisterOutputParam(output.Parameter);
         if (output.IsMenu)
         {
             dynOutputs.Add(output.Parameter);
         }
         else
         {
             stcOutputs.Add(output.Parameter);
         }
     }
 }
 public void UnregisterUnit(EvaluationUnit unit)
 {
     stcInputs.Clear();
     stcOutputs.Clear();
     dynInputs.Clear();
     dynOutputs.Clear();
     foreach (ExtendedPlug input in unit.Inputs)
     {
         UnregisterParameter(input.Parameter, input: true, isolate: true);
     }
     foreach (ExtendedPlug output in unit.Outputs)
     {
         UnregisterParameter(output.Parameter, input: false, isolate: true);
     }
     foreach (IGH_Param item in component.Params.Input)
     {
         stcInputs.Add(item);
     }
     foreach (IGH_Param item2 in component.Params.Output)
     {
         stcOutputs.Add(item2);
     }
 }
Exemplo n.º 9
0
            public static GH_SwitcherConnectivity Create(GH_SwitcherComponent component)
            {
                GH_SwitcherConnectivity gH_SwitcherConnectivity = new GH_SwitcherConnectivity();

                gH_SwitcherConnectivity.componentId = component.InstanceGuid;
                EvaluationUnit activeUnit = component.ActiveUnit;

                if (activeUnit != null)
                {
                    gH_SwitcherConnectivity.noUnit = false;
                    gH_SwitcherConnectivity.unit   = activeUnit.Name;
                }
                else if (component.UnitlessExistence)
                {
                    gH_SwitcherConnectivity.noUnit = true;
                }
                foreach (IGH_Param item in component.Params.Input)
                {
                    GH_SwitcherParamState gH_SwitcherParamState = new GH_SwitcherParamState(0, item.InstanceGuid);
                    gH_SwitcherConnectivity.inputs.Add(gH_SwitcherParamState);
                    foreach (IGH_Param source in item.Sources)
                    {
                        gH_SwitcherParamState.Targets.Add(source.InstanceGuid);
                    }
                }
                foreach (IGH_Param item2 in component.Params.Output)
                {
                    GH_SwitcherParamState gH_SwitcherParamState2 = new GH_SwitcherParamState(GH_ParameterSide.Output, item2.InstanceGuid);
                    gH_SwitcherConnectivity.outputs.Add(gH_SwitcherParamState2);
                    foreach (IGH_Param recipient in item2.Recipients)
                    {
                        gH_SwitcherParamState2.Targets.Add(recipient.InstanceGuid);
                    }
                }
                return(gH_SwitcherConnectivity);
            }
Exemplo n.º 10
0
 protected abstract void SolveInstance(IGH_DataAccess DA, EvaluationUnit unit);
 public EvaluationUnitContext(EvaluationUnit unit)
 {
     this.unit  = unit;
     collection = new GH_MenuCollection();
 }