Skip to content

Commit

Permalink
Fixed #12 - NullReferenceException in MacroFeatureRebuildResult.FromBody
Browse files Browse the repository at this point in the history
Implemented #13  - Provide a reason for the macro feature handler destroy
Implemented #14 - Need to have support for more types in macro feature parameters (DateTime, decimal)
Updated the header for all files
Removed obsolete members
Added the readme to nuget
  • Loading branch information
codestackdev committed Aug 5, 2019
1 parent 4133c09 commit 54c5232
Show file tree
Hide file tree
Showing 51 changed files with 299 additions and 259 deletions.
4 changes: 2 additions & 2 deletions AddInExample/LifecycleMacroFeature.cs
Expand Up @@ -29,9 +29,9 @@ public void Init(ISldWorks app, IModelDoc2 model, IFeature feat)
m_App.SendMsgToUser($"{m_Model.GetTitle()}\\{m_Feat.Name} loaded");
}

public void Unload()
public void Unload(MacroFeatureUnloadReason_e reason)
{
m_App.SendMsgToUser($"{m_Model.GetTitle()}\\{m_Feat.Name} unloaded");
m_App.SendMsgToUser($"{m_Model.GetTitle()}\\{m_Feat.Name} unloaded: {reason}");
}

public void Rebuild()
Expand Down
4 changes: 4 additions & 0 deletions AddInExample/ParamsMacroFeature.cs
Expand Up @@ -42,6 +42,8 @@ public class ParamsMacroFeatureParams
{
public string Param2 { get; set; }
public int EditDefinitionsCount { get; set; }
public DateTime DateTime { get; set; }
public decimal Decimal { get; set; }
}

[ComVisible(true)]
Expand All @@ -57,6 +59,8 @@ protected override bool OnEditDefinition(ISldWorks app, IModelDoc2 model, IFeatu

var featParams = GetParameters(feature, featData, model);

featParams.DateTime = DateTime.Now;
featParams.Decimal = (featParams.Decimal + 1M) * 1.002M;
app.SendMsgToUser($"{nameof(featParams.Param2)} = {featParams.Param2}; {nameof(featParams.EditDefinitionsCount)} = {featParams.EditDefinitionsCount}");
featParams.EditDefinitionsCount = featParams.EditDefinitionsCount + 1;

Expand Down
21 changes: 3 additions & 18 deletions Base/Attributes/FeatureIconAttribute.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand All @@ -12,21 +12,6 @@

namespace CodeStack.SwEx.MacroFeature.Attributes
{
[Obsolete("Deprecated. Use FeatureIconAttribute or Common.Attributes.IconAttribute instead")]
public class IconAttribute : FeatureIconAttribute
{
public IconAttribute(Type resType, string resName, string iconFolderName = "")
: base(resType, resName, iconFolderName)
{
}

public IconAttribute(Type resType, string smallResName, string mediumResName,
string largeResName, string iconFolderName = "")
: base(resType, smallResName, mediumResName, largeResName, iconFolderName)
{
}
}

/// <summary>
/// Specifies the icon for macro feature to be displayed in the Feature Manager Tree
/// </summary>
Expand Down Expand Up @@ -56,7 +41,7 @@ public FeatureIconAttribute(Type resType, string resName, string iconFolderName
IconFolderName = iconFolderName;
}

///<inheritdoc cref="IconAttribute(Type, string, string)"/>
///<inheritdoc cref="FeatureIconAttribute(Type, string, string)"/>
/// <param name="smallResName">Name of the resource representing the small size icon</param>
/// <param name="mediumResName">Name of the resource representing the medium size icon</param>
/// <param name="largeResName">Name of the resource representing the large size icon</param>
Expand Down
4 changes: 2 additions & 2 deletions Base/Attributes/OptionsAttribute.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand Down
17 changes: 3 additions & 14 deletions Base/Attributes/ParameterDimensionAttribute.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand Down Expand Up @@ -32,10 +32,7 @@ public class ParameterDimensionAttribute : Attribute
swDimensionType_e.swLinearDimension,
swDimensionType_e.swRadialDimension
};

[Obsolete("This property is deprecated")]
internal int DimensionIndex { get; private set; } = -1;


internal swDimensionType_e DimensionType { get; private set; }

/// <summary>
Expand All @@ -51,13 +48,5 @@ public ParameterDimensionAttribute(swDimensionType_e dimType)

DimensionType = dimType;
}

[Obsolete("This constructor is deprecated")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public ParameterDimensionAttribute(swDimensionType_e dimType, int dimIndex)
: this(dimType)
{
DimensionIndex = dimIndex;
}
}
}
20 changes: 2 additions & 18 deletions Base/Attributes/ParameterEditBodyAttribute.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand All @@ -22,21 +22,5 @@ namespace CodeStack.SwEx.MacroFeature.Attributes
[AttributeUsage(AttributeTargets.Property)]
public class ParameterEditBodyAttribute : Attribute
{
[Obsolete("This property is deprecated")]
internal int BodyIndex { get; private set; } = -1;

/// <summary>
/// Marks this property as a container for edit bodies
/// </summary>
public ParameterEditBodyAttribute()
{
}

[Obsolete("This constructor is deprecated")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public ParameterEditBodyAttribute(int bodyIndex)
{
BodyIndex = bodyIndex;
}
}
}
23 changes: 2 additions & 21 deletions Base/Attributes/ParameterSelectionAttribute.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand All @@ -23,24 +23,5 @@ namespace CodeStack.SwEx.MacroFeature.Attributes
[AttributeUsage(AttributeTargets.Property)]
public class ParameterSelectionAttribute : System.Attribute
{
/// <summary>
/// Index of the selection in the selection array
/// </summary>
[Obsolete("This property is deprecated")]
internal int SelectionIndex { get; private set; } = -1;

/// <summary>
/// Marks this property as a selection
/// </summary>
public ParameterSelectionAttribute()
{
}

[Obsolete("This constructor is deprecated")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public ParameterSelectionAttribute(int selIndex)
{
SelectionIndex = selIndex;
}
}
}
4 changes: 2 additions & 2 deletions Base/Attributes/ParametersVersionAttribute.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand Down
1 change: 0 additions & 1 deletion Base/Base.csproj
Expand Up @@ -76,7 +76,6 @@
<Compile Include="Base\IParametersVersionConverter.cs" />
<Compile Include="Base\MacroFeatureOutdateState.cs" />
<Compile Include="Base\MacroFeatureRebuildBodyResult.cs" />
<Compile Include="Base\MacroFeatureRebuildPatternResult.cs" />
<Compile Include="Base\MacroFeatureRebuildResult.cs" />
<Compile Include="Base\MacroFeatureRebuldStatusResult.cs" />
<Compile Include="Core\MacroFeatureExOfTParams.cs" />
Expand Down
7 changes: 5 additions & 2 deletions Base/Base.nuspec
Expand Up @@ -2,11 +2,11 @@
<package >
<metadata>
<id>CodeStack.SwEx.MacroFeature</id>
<version>0.4.4</version>
<version>0.5.0</version>
<title>Framework for developing custom macro features in SOLIDWORKS</title>
<authors>CodeStack</authors>
<owners>CodeStack</owners>
<licenseUrl>https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE</licenseUrl>
<licenseUrl>https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE</licenseUrl>
<projectUrl>https://www.codestack.net/labs/solidworks/swex/macro-feature</projectUrl>
<iconUrl>https://www.codestack.net/labs/solidworks/swex/macro-feature/logo.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
Expand All @@ -15,4 +15,7 @@
<copyright>Copyright © CodeStack 2019</copyright>
<tags>MacroFeature SOLIDWORKS</tags>
</metadata>
<files>
<file src="readme.txt" target="" />
</files>
</package>
26 changes: 22 additions & 4 deletions Base/Base/IMacroFeatureHandler.cs
@@ -1,14 +1,31 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

using SolidWorks.Interop.sldworks;
using System;

namespace CodeStack.SwEx.MacroFeature.Base
{
/// <summary>
/// Reason of macro feature handler unloading. Used in <see cref="IMacroFeatureHandler.Unload(MacroFeatureUnloadReason_e)"/>
/// </summary>
public enum MacroFeatureUnloadReason_e
{
/// <summary>
/// Model containing this macro feature is closed
/// </summary>
ModelClosed,

/// <summary>
/// This macro feature is deleted
/// </summary>
Deleted
}

/// <summary>
/// Handler of each macro feature used in <see cref="MacroFeatureEx{TParams, THandler}"/>
/// </summary>
Expand All @@ -22,10 +39,11 @@ public interface IMacroFeatureHandler
/// <param name="model">Pointer to model</param>
/// <param name="feat">Pointer to feature</param>
void Init(ISldWorks app, IModelDoc2 model, IFeature feat);

/// <summary>
/// Called when macro feature is deleted or model is closed
/// </summary>
void Unload();
/// <param name="reason">Reason of macro feature unload</param>
void Unload(MacroFeatureUnloadReason_e reason);
}
}
4 changes: 2 additions & 2 deletions Base/Base/IParametersVersionConverter.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand Down
4 changes: 2 additions & 2 deletions Base/Base/MacroFeatureOutdateState.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand Down
6 changes: 4 additions & 2 deletions Base/Base/MacroFeatureRebuildBodyResult.cs
@@ -1,13 +1,14 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

using SolidWorks.Interop.sldworks;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

Expand All @@ -18,6 +19,7 @@ namespace CodeStack.SwEx.MacroFeature.Base
/// </summary>
public class MacroFeatureRebuildBodyResult : MacroFeatureRebuildResult
{
[Obsolete, Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal protected MacroFeatureRebuildBodyResult(params IBody2[] bodies) : this(null, false, bodies)
{
}
Expand Down
25 changes: 0 additions & 25 deletions Base/Base/MacroFeatureRebuildPatternResult.cs

This file was deleted.

12 changes: 3 additions & 9 deletions Base/Base/MacroFeatureRebuildResult.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand All @@ -26,6 +26,7 @@ public abstract class MacroFeatureRebuildResult
/// <param name="body">Body to return</param>
/// <returns>Result</returns>
/// <remarks>Use this result if you need to macro feature to generate a single body (solid or surface)</remarks>
[Obsolete ("Obsolete method, use another overload"), Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public static MacroFeatureRebuildResult FromBody(IBody2 body)
{
return new MacroFeatureRebuildBodyResult(body);
Expand All @@ -50,13 +51,6 @@ public static MacroFeatureRebuildResult FromBodies(IBody2[] bodies, IMacroFeatur
return new MacroFeatureRebuildBodyResult(featData, updateEntityIds, bodies);
}

[Obsolete("Deprecated. Use FromBodies method instead")]
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public static MacroFeatureRebuildResult FromPattern(IBody2[] bodiesPattern)
{
return new MacroFeatureRebuildPatternResult(bodiesPattern);
}

/// <summary>
/// Returns the status of the rebuild operation
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Base/Base/MacroFeatureRebuldStatusResult.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand Down
4 changes: 2 additions & 2 deletions Base/Core/MacroFeatureEx.cs
@@ -1,7 +1,7 @@
//**********************
//SwEx.MacroFeature - framework for developing macro features in SOLIDWORKS
//Copyright(C) 2018 www.codestack.net
//License: https://github.com/codestack-net-dev/swex-macrofeature/blob/master/LICENSE
//Copyright(C) 2019 www.codestack.net
//License: https://github.com/codestackdev/swex-macrofeature/blob/master/LICENSE
//Product URL: https://www.codestack.net/labs/solidworks/swex/macro-feature
//**********************

Expand Down

0 comments on commit 54c5232

Please sign in to comment.