Skip to content
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

Aligning with changes in BHoMAdapter Refactoring Level 04 #497

Merged
merged 4 commits into from
Jan 24, 2020
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
34 changes: 29 additions & 5 deletions Adapter_Revit_UI/AdapterActions/Push.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2019, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand All @@ -26,6 +26,8 @@
using System.Reflection;

using BH.oM.Base;
using BH.oM.Adapter;
using BH.oM.Adapters.Revit;

namespace BH.UI.Revit.Adapter
{
Expand All @@ -36,11 +38,33 @@ public partial class RevitUIAdapter
/**** Protected Methods ****/
/***************************************************/

public override List<IObject> Push(IEnumerable<IObject> objects, string tag = "", Dictionary<string, object> config = null)
public override List<object> Push(IEnumerable<object> objects, string tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null)
{
bool success = true;

List<IObject> objectsToPush = Config.CloneBeforePush ? objects.Select(x => x is BHoMObject ? ((BHoMObject)x).GetShallowClone() : x).ToList() : objects.ToList(); //ToList() necessary for the return collection to function properly for cloned objects
// ----------------------------------------//
// SET-UP //
// ----------------------------------------//

// If unset, set the pushType to AdapterSettings' value (base AdapterSettings default is FullCRUD).
if (pushType == PushType.AdapterDefault)
pushType = m_AdapterSettings.DefaultPushType;

//Initialize Revit config
RevitConfig revitConfig = actionConfig as RevitConfig;

// Process the objects (verify they are valid; DeepClone them, wrap them, etc).
IEnumerable<IBHoMObject> objectsToPush = ProcessObjectsForPush(objects, revitConfig); // Note: default Push only supports IBHoMObjects.

if (objectsToPush.Count() == 0)
{
BH.Engine.Reflection.Compute.RecordError("Input objects were invalid.");
return new List<object>();
}

// ----------------------------------------//
// ACTUAL PUSH //
// ----------------------------------------//

Type iBHoMObjectType = typeof(IBHoMObject);
MethodInfo miToList = typeof(Enumerable).GetMethod("Cast");
Expand All @@ -52,10 +76,10 @@ public override List<IObject> Push(IEnumerable<IObject> objects, string tag = ""
var list = miListObject.Invoke(typeGroup, new object[] { typeGroup });

if (iBHoMObjectType.IsAssignableFrom(typeGroup.Key))
success &= Create(list as dynamic);
success &= ICreate(list as dynamic);
}

return success ? objectsToPush : new List<IObject>();
return success ? objectsToPush.Cast<object>().ToList() : new List<object>();
}

/***************************************************/
Expand Down
21 changes: 17 additions & 4 deletions Adapter_Revit_UI/Adapter_Revit_UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
<AssemblyName>Adapter_Revit_UI_2020</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Reference Include="Adapter_Engine, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\BHoM_Adapter\Build\Adapter_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Adapter_oM, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\BHoM_Adapter\Build\Adapter_oM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Analytical_oM, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\BHoM\Build\Analytical_oM.dll</HintPath>
Expand All @@ -115,7 +125,8 @@
<HintPath>..\..\BHoM\Build\BHoM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BHoM_Adapter">
<Reference Include="BHoM_Adapter, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\BHoM_Adapter\Build\BHoM_Adapter.dll</HintPath>
<Private>False</Private>
</Reference>
Expand Down Expand Up @@ -146,6 +157,11 @@
<HintPath>..\..\BHoM_Engine\Build\Reflection_Engine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Reflection_oM, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\BHoM\Build\Reflection_oM.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RevitAPI" Condition="'$(Configuration)'=='Debug2018' Or '$(Configuration)'=='Release2018'">
<HintPath>..\libs\2018\RevitAPI.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -198,11 +214,8 @@
<ItemGroup>
<Compile Include="CRUD\Create.cs" />
<Compile Include="CRUD\Delete.cs" />
<Compile Include="AdapterActions\Execute.cs" />
<Compile Include="AdapterActions\Push.cs" />
<Compile Include="CRUD\Read.cs" />
<Compile Include="Types\Comparer.cs" />
<Compile Include="Types\DependencyTypes.cs" />
<Compile Include="CRUD\Update.cs" />
<Compile Include="Messages\Errors.cs" />
<Compile Include="Messages\Warnings.cs" />
Expand Down
8 changes: 5 additions & 3 deletions Adapter_Revit_UI/CRUD/Create.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2019, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -34,6 +34,7 @@
using BH.oM.Adapters.Revit.Settings;
using BH.oM.Adapters.Revit.Interface;
using BH.oM.Adapters.Revit.Properties;
using BH.oM.Adapter;

namespace BH.UI.Revit.Adapter
{
Expand All @@ -43,7 +44,7 @@ public partial class RevitUIAdapter : BH.Adapter.Revit.InternalRevitAdapter
/**** Protected Methods ****/
/***************************************************/

protected override bool Create<T>(IEnumerable<T> objects)
protected override bool ICreate<T>(IEnumerable<T> objects, ActionConfig actionConfig = null)
{
if (Document == null)
{
Expand Down Expand Up @@ -288,7 +289,7 @@ private static void SetIdentifiers(IBHoMObject bHoMObject, Element element)
return;

SetCustomData(bHoMObject, BH.Engine.Adapters.Revit.Convert.ElementId, element.Id.IntegerValue);
SetCustomData(bHoMObject, BH.Engine.Adapters.Revit.Convert.AdapterId, element.UniqueId);
SetCustomData(bHoMObject, BH.Engine.Adapters.Revit.Convert.AdapterIdName, element.UniqueId);

if (element is Family)
{
Expand Down Expand Up @@ -351,6 +352,7 @@ private static void SetCustomData(IBHoMObject bHoMObject, string customDataName,
bHoMObject.CustomData[customDataName] = value;
}


/***************************************************/
/**** Private Classes ****/
/***************************************************/
Expand Down
2 changes: 1 addition & 1 deletion Adapter_Revit_UI/CRUD/Delete.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2019, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down
7 changes: 4 additions & 3 deletions Adapter_Revit_UI/CRUD/Read.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2019, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -35,6 +35,7 @@
using BH.UI.Revit.Engine;
using BH.oM.Data.Requests;
using BH.oM.Adapters.Revit.Properties;
using BH.oM.Adapter;

namespace BH.UI.Revit.Adapter
{
Expand All @@ -44,7 +45,7 @@ public partial class RevitUIAdapter
/**** Protected Methods ****/
/***************************************************/

protected override IEnumerable<IBHoMObject> Read(Type type, IList ids)
protected override IEnumerable<IBHoMObject> IRead(Type type, IList ids, ActionConfig actionConfig = null)
{
if (Document == null)
{
Expand Down Expand Up @@ -116,7 +117,7 @@ protected override IEnumerable<IBHoMObject> Read(Type type, IList ids)

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

protected override IEnumerable<IBHoMObject> Read(FilterRequest filterRequest)
protected override IEnumerable<IBHoMObject> Read(FilterRequest filterRequest, ActionConfig actionConfig = null)
{
Document document = Document;

Expand Down
2 changes: 1 addition & 1 deletion Adapter_Revit_UI/CRUD/Update.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2018, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down
30 changes: 27 additions & 3 deletions Adapter_Revit_UI/RevitUIAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2019, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand All @@ -24,6 +24,11 @@
using Autodesk.Revit.UI;

using BH.Adapter.Revit;
using BH.oM.Adapters.Revit.Elements;
using BH.oM.Structure.Elements;
using BH.oM.Structure.SectionProperties;
using System;
using System.Collections.Generic;

namespace BH.UI.Revit.Adapter
{
Expand All @@ -47,11 +52,30 @@ public partial class RevitUIAdapter : InternalRevitAdapter
public RevitUIAdapter(UIControlledApplication uIControlledApplication, Document document)
: base()
{
AdapterId = BH.Engine.Adapters.Revit.Convert.AdapterId;
Config.UseAdapterId = false;
AdapterIdName = BH.Engine.Adapters.Revit.Convert.AdapterIdName;
m_AdapterSettings.UseAdapterId = false;

m_Document = document;
m_UIControlledApplication = uIControlledApplication;


AdapterComparers = new Dictionary<Type, object>
{
//{typeof(ISectionProperty), new BHoMObjectNameOrToStringComparer() },
//{typeof(IProfile), new BHoMObjectNameOrToStringComparer() },
//{typeof(ISurfaceProperty), new BHoMObjectNameOrToStringComparer() },
//{typeof(Material), new BHoMObjectNameComparer() },
//{typeof(Level), new BHoMObjectNameComparer() },
};

DependencyTypes = new Dictionary<Type, List<Type>>
{
{typeof(oM.Adapters.Revit.Elements.Viewport), new List<Type> { typeof(oM.Adapters.Revit.Elements.Sheet), typeof(oM.Adapters.Revit.Elements.ViewPlan) } },
{typeof(oM.Adapters.Revit.Elements.Sheet), new List<Type> { typeof(oM.Adapters.Revit.Elements.ViewPlan)} }
//{typeof(ISectionProperty), new List<Type> { typeof(Material), typeof(IProfile) } },
//{typeof(PanelPlanar), new List<Type> { typeof(ISurfaceProperty), typeof(Level) } },
//{typeof(ISurfaceProperty), new List<Type> { typeof(Material) } }
};
}


Expand Down
75 changes: 0 additions & 75 deletions Adapter_Revit_UI/Types/DependencyTypes.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Engine_Revit_UI/Modify/SetIdentifiers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2019, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand Down Expand Up @@ -40,7 +40,7 @@ public static IBHoMObject SetIdentifiers(this IBHoMObject bHoMObject, Element el
IBHoMObject obj = bHoMObject.GetShallowClone() as IBHoMObject;

obj = obj.SetCustomData(BH.Engine.Adapters.Revit.Convert.ElementId, element.Id.IntegerValue);
obj = obj.SetCustomData(BH.Engine.Adapters.Revit.Convert.AdapterId, element.UniqueId);
obj = obj.SetCustomData(BH.Engine.Adapters.Revit.Convert.AdapterIdName, element.UniqueId);

int worksetID = WorksetId.InvalidWorksetId.IntegerValue;
if (element.Document != null && element.Document.IsWorkshared)
Expand Down
14 changes: 10 additions & 4 deletions Revit_Adapter/AdapterActions/Execute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2018, the respective contributors. All rights reserved.
* Copyright (c) 2015 - 2020, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
Expand All @@ -20,6 +20,9 @@
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Adapter;
using BH.oM.Adapters.Revit;
using BH.oM.Reflection;
using System.Collections.Generic;

namespace BH.Adapter.Revit
Expand All @@ -30,15 +33,18 @@ public partial class RevitAdapter
/**** Public Methods ****/
/***************************************************/

public override bool Execute(string command, Dictionary<string, object> parameters = null, Dictionary<string, object> config = null)
public override Output<List<object>, bool> Execute(IExecuteCommand command, ActionConfig actionConfig = null)
{
//Initialize Revit config
RevitConfig revitConfig = actionConfig as RevitConfig;

if (InternalAdapter != null)
{
InternalAdapter.RevitSettings = RevitSettings;
return InternalAdapter.Execute(command, parameters, config);
return InternalAdapter.Execute(command, revitConfig);
}

return false;
return null;
}

/***************************************************/
Expand Down
Loading