Skip to content

BHoM_Adapter: Adding Before and After methods for each action #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion BHoM_Adapter/AdapterActions/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract partial class BHoMAdapter
/* These methods represent Actions that the Adapter can complete.
They are publicly available in the UI as individual components, e.g. in Grasshopper, under BHoM/Adapters tab. */

[Description("Performs a set up for the ActionConfig of the Execute Action.")]
[Description("Performs a set up for the ActionConfig of the Execute Action. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool SetupExecuteConfig(ActionConfig actionConfig, out ActionConfig executeConfig)
{
// If null, set the actionConfig to a new ActionConfig.
Expand All @@ -51,6 +51,26 @@ public virtual bool SetupExecuteConfig(ActionConfig actionConfig, out ActionConf
return true;
}

/******************************************************/

[Description("Performs an action prior to any execute actions. For example can be used to open up a file for repeated execute actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool BeforeExecute(IExecuteCommand command, ActionConfig actionConfig = null)
{
m_HasRunPreExecuteAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any execute actions. For example can be used to close a file for repeated execute actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool AfterExecute(IExecuteCommand command, ActionConfig actionConfig = null)
{
m_HasRunPreExecuteAction = false; //Reset for next execute action
return true;
}

/******************************************************/

[Description("To be implemented to send specific commands to the external software, through its API or other means." +
"To be implemented (overridden) in Toolkits.")]
[Output("Output<object, bool>", "Output is a tuple-like class with: " +
Expand Down
20 changes: 20 additions & 0 deletions BHoM_Adapter/AdapterActions/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ public virtual bool Move(IBHoMAdapter to, IRequest request,

return to.Push(objects.Cast<IObject>(), tag, pushType, pushConfig).Count() == count;
}

/******************************************************/

[Description("Performs an action prior to any move actions. For example can be used to open up a file for repeated move actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool BeforeMove(IBHoMAdapter to, IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig pullConfig = null, PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPreMoveAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any move actions. For example can be used to close a file for repeated move actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool AfterMove(IBHoMAdapter to, IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig pullConfig = null, PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPreMoveAction = false; //Reset for next move action
return true;
}

/******************************************************/
}
}

Expand Down
32 changes: 25 additions & 7 deletions BHoM_Adapter/AdapterActions/Pull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract partial class BHoMAdapter
/* These methods represent Actions that the Adapter can complete.
They are publicly available in the UI as individual components, e.g. in Grasshopper, under BHoM/Adapters tab. */

[Description("Performs a set up for the Request input of the Pull Action.")]
[Description("Performs a set up for the Request input of the Pull Action. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool SetupPullRequest(object request, out IRequest actualRequest)
{
// Always assure there is a Request. Allow to input a Type to generate a FilterRequest.
Expand All @@ -60,7 +60,9 @@ public virtual bool SetupPullRequest(object request, out IRequest actualRequest)
return true;
}

[Description("Performs a set up for the ActionConfig of the Pull Action.")]
/******************************************************/

[Description("Performs a set up for the ActionConfig of the Pull Action. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool SetupPullConfig(ActionConfig actionConfig, out ActionConfig pullConfig)
{
// If null, set the actionConfig to a new ActionConfig.
Expand All @@ -69,6 +71,26 @@ public virtual bool SetupPullConfig(ActionConfig actionConfig, out ActionConfig
return true;
}

/******************************************************/

[Description("Performs an action prior to any pull actions. For example can be used to open up a file for repeated pull actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool BeforePull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPrePullAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any pull actions. For example can be used to close a file that was opened for repeated pull actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool AfterPull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPrePullAction = false; //Reset to false for the next pull
return true;
}

/******************************************************/

[Description("Pulls objects from an external software using the basic CRUD/Read method as appropriate.")]
public virtual IEnumerable<object> Pull(IRequest request, PullType pullType = PullType.AdapterDefault, ActionConfig actionConfig = null)
{
Expand All @@ -86,8 +108,4 @@ public virtual IEnumerable<object> Pull(IRequest request, PullType pullType = Pu
return read;
}
}
}




}
24 changes: 22 additions & 2 deletions BHoM_Adapter/AdapterActions/Push.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract partial class BHoMAdapter
/* These methods represent Actions that the Adapter can complete.
They are publicly available in the UI as individual components, e.g. in Grasshopper, under BHoM/Adapters tab. */

[Description("Performs a set up for the ActionConfig of the Push Action.")]
[Description("Performs a set up for the ActionConfig of the Push Action. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool SetupPushConfig(ActionConfig actionConfig, out ActionConfig pushConfig)
{
// If null, set the actionConfig to a new ActionConfig.
Expand All @@ -52,7 +52,7 @@ public virtual bool SetupPushConfig(ActionConfig actionConfig, out ActionConfig
return true;
}

[Description("Performs a set up for the ActionConfig of the Push Action.")]
[Description("Performs a set up for the ActionConfig of the Push Action. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool SetupPushType(PushType inputPushType, out PushType pushType)
{
// If unset, set the pushType to AdapterSettings' value (base AdapterSettings default is FullPush).
Expand Down Expand Up @@ -133,6 +133,26 @@ public virtual List<object> Push(IEnumerable<object> objects, string tag = "", P
this.ClearCache();
return success ? objectsToPush.Cast<object>().ToList() : new List<object>();
}

/******************************************************/

[Description("Performs an action prior to any push actions. For example can be used to open up a file for repeated push actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool BeforePush(IEnumerable<object> objects, string tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPrePushAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any push actions. For example can be used to close a file for repeated push actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool AfterPush(IEnumerable<object> objects, string tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
{
m_HasRunPrePushAction = false; //Reset for next push action
return true;
}

/******************************************************/
}
}

Expand Down
24 changes: 22 additions & 2 deletions BHoM_Adapter/AdapterActions/Remove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public abstract partial class BHoMAdapter
/* These methods represent Actions that the Adapter can complete.
They are publicly available in the UI as individual components, e.g. in Grasshopper, under BHoM/Adapters tab. */

[Description("Performs a set up for the Request input of the Remove Action.")]
[Description("Performs a set up for the Request input of the Remove Action. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool SetupRemoveRequest(object obj, out IRequest removeRequest)
{
return SetupPullRequest(obj, out removeRequest);
}

[Description("Performs a set up for the ActionConfig of the Remove Action.")]
[Description("Performs a set up for the ActionConfig of the Remove Action. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool SetupRemoveConfig(ActionConfig actionConfig, out ActionConfig removeConfig)
{
// If null, set the actionConfig to a new ActionConfig.
Expand All @@ -63,6 +63,26 @@ public virtual int Remove(IRequest request, ActionConfig actionConfig = null)
this.ClearCache();
return Delete(request as dynamic, actionConfig);
}

/******************************************************/

[Description("Performs an action prior to any remove actions. For example can be used to open up a file for repeated remove actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool BeforeRemove(IRequest request, ActionConfig actionConfig = null)
{
m_HasRunPreRemoveAction = true;
return true;
}

/******************************************************/

[Description("Performs an action after any remove actions. For example can be used to close a file for repeated remove actions. This method is intended to be called by the context in which this Adapter is run, which typically is a UI supported by BHoM.")]
public virtual bool AfterRemove(IRequest request, ActionConfig actionConfig = null)
{
m_HasRunPreRemoveAction = false; //Reset for next remove action
return true;
}

/******************************************************/
}
}

Expand Down
6 changes: 6 additions & 0 deletions BHoM_Adapter/BHoMAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public abstract partial class BHoMAdapter : IBHoMAdapter
// e.g. AdapterSettings.WrapNonBHoMObjects = true;
protected AdapterSettings m_AdapterSettings { get; set; } = new AdapterSettings();

protected bool m_HasRunPrePullAction { get; set; } = false; //Flag to determine whether the adapter has run pre-pull actions
protected bool m_HasRunPrePushAction { get; set; } = false; //Flag to determine whether the adapter has run pre-push actions
protected bool m_HasRunPreExecuteAction { get; set; } = false; //Flag to determine whether the adapter has run pre-execute actions
protected bool m_HasRunPreMoveAction { get; set; } = false; //Flag to determine whether the adapter has run pre-move actions
protected bool m_HasRunPreRemoveAction { get; set; } = false; //Flag to determine whether the adapter has run pre-remove actions

/***************************************************/
/**** Public Events ****/
/***************************************************/
Expand Down