Skip to content

Commit

Permalink
Address 2020 compatibility issues, relocate export menu item, and oth…
Browse files Browse the repository at this point in the history
…er items (#106)

* Address 2020 compatibility issues

* More warning resolutions

* Cleaning up warnings and analysis recommendations

* Switch to FxCop, fix some errors surpress others

* Add icons and relocate export button
  • Loading branch information
brawner authored Oct 16, 2020
1 parent 2c515a4 commit dff1e0d
Show file tree
Hide file tree
Showing 68 changed files with 690 additions and 1,159 deletions.
2 changes: 1 addition & 1 deletion INSTALL/Install.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "SolidWorks To URDF"
#define MyAppVersion "2018 v1.4"
#define MyAppVersion "2018 v1.6"
#define MyAppPublisher "Stephen Brawner"
#define MyAppURL "http://wiki.ros.org/sw_urdf_exporter"

Expand Down
Binary file removed SW2URDF/AddInIcon.PNG
Binary file not shown.
15 changes: 15 additions & 0 deletions SW2URDF/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "To be fixed, there are just too many right now", Scope = "module")]
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "To be fixed, there are too many right now", Scope = "module")]
[assembly: SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible", Justification = "See CA1051 above", Scope = "module")]
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "To be fixed, too many to address right now", Scope = "module")]
[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "To be fixed, this tool is not localized", Scope = "module")]
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "To be fixed, this tool is not localized", Scope = "module")]
[assembly: SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "To be fixed, this tool is not localized", Scope = "module")]
[assembly: SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "To be fixed, but too many for now", Scope = "module")]
4 changes: 0 additions & 4 deletions SW2URDF/ROS/ROSFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ THE SOFTWARE.

namespace SW2URDF.ROS
{
internal class ROSFiles
{
}

public abstract class LaunchElement
{
public abstract void WriteFile(XmlWriter writer);
Expand Down
33 changes: 11 additions & 22 deletions SW2URDF/SW/EventHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public bool ConnectModelViews()
{
if (!openModelViews.Contains(mView))
{
DocView dView = new DocView(userAddin, mView, this);
DocView dView = new DocView(mView, this);
dView.AttachEventHandlers();
openModelViews.Add(mView, dView);
}
Expand Down Expand Up @@ -98,21 +98,17 @@ public bool DisconnectModelViews()

public bool DetachModelViewEventHandler(ModelView mView)
{
DocView dView;
if (openModelViews.Contains(mView))
{
dView = (DocView)openModelViews[mView];
openModelViews.Remove(mView);
mView = null;
dView = null;
}
return true;
}
}

public class PartEventHandler : DocumentEventHandler
{
private PartDoc doc;
private readonly PartDoc doc;

public PartEventHandler(ModelDoc2 modDoc, SwAddin addin)
: base(modDoc, addin)
Expand Down Expand Up @@ -148,7 +144,7 @@ public int OnDestroy()
return 0;
}

public int OnNewSelection()
public static int OnNewSelection()
{
return 0;
}
Expand Down Expand Up @@ -200,7 +196,7 @@ public int OnDestroy()
return 0;
}

public int OnNewSelection()
public static int OnNewSelection()
{
return 0;
}
Expand All @@ -221,7 +217,6 @@ protected int ComponentStateChange(object componentModel, short newCompState)
}
break;
}

case swComponentSuppressionState_e.swComponentResolved:
{
if ((modDoc != null) && !swAddin.OpenDocs.Contains(modDoc))
Expand All @@ -230,16 +225,14 @@ protected int ComponentStateChange(object componentModel, short newCompState)
}
break;
}

case swComponentSuppressionState_e.swComponentSuppressed:
break;

case swComponentSuppressionState_e.swComponentLightweight:
break;

case swComponentSuppressionState_e.swComponentFullyLightweight:
break;

case swComponentSuppressionState_e.swComponentInternalIdMismatch:
break;
default:
break;
}
Expand Down Expand Up @@ -281,7 +274,7 @@ private int ComponentVisualPropertiesChangeNotify(object swObject)

public class DrawingEventHandler : DocumentEventHandler
{
private DrawingDoc doc;
private readonly DrawingDoc doc;

public DrawingEventHandler(ModelDoc2 modDoc, SwAddin addin)
: base(modDoc, addin)
Expand Down Expand Up @@ -317,24 +310,20 @@ public int OnDestroy()
return 0;
}

public int OnNewSelection()
public static int OnNewSelection()
{
return 0;
}
}

public class DocView
{
private readonly ISldWorks iSwApp;
private readonly SwAddin userAddin;
private readonly ModelView mView;
private readonly DocumentEventHandler parent;

public DocView(SwAddin addin, IModelView mv, DocumentEventHandler doc)
public DocView(IModelView mv, DocumentEventHandler doc)
{
userAddin = addin;
mView = (ModelView)mv;
iSwApp = userAddin.SwApp;
parent = doc;
}

Expand All @@ -354,7 +343,7 @@ public bool DetachEventHandlers()
}

//EventHandlers
public int OnDestroy(int destroyType)
public static int OnDestroy(int destroyType)
{
switch (destroyType)
{
Expand All @@ -369,7 +358,7 @@ public int OnDestroy(int destroyType)
}
}

public int OnRepaint(int repaintType)
public static int OnRepaint(int repaintType)
{
return 0;
}
Expand Down
74 changes: 48 additions & 26 deletions SW2URDF/SW/SwAddin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class SwAddin : ISwAddin

#region Local Variables

private int addinID = 0;
private int add_in_id_ = 0;

public const int mainCmdGroupID = 5;
public const int mainItemID1 = 0;
Expand Down Expand Up @@ -123,14 +123,14 @@ public static void RegisterFunction(Type t)
{
logger.Error("There was a problem registering this dll: SWattr is null. \n\"" +
nl.Message + "\"", nl);
MessageBox.Show("There was a problem registering this dll: SWattr is null. \n\"" +
nl.Message + "\"\nEmail your maintainer with the log file found at " + Logger.GetFileName());
// MessageBox.Show("There was a problem registering this dll: SWattr is null. \n\"" +
// nl.Message + "\"\nEmail your maintainer with the log file found at " + Logger.GetFileName());
}
catch (Exception e)
{
logger.Error(e.Message);
MessageBox.Show("There was a problem registering the function: \n\"" + e.Message +
"\"\nEmail your maintainer with the log file found at " + Logger.GetFileName());
// MessageBox.Show("There was a problem registering the function: \n\"" + e.Message +
// "\"\nEmail your maintainer with the log file found at " + Logger.GetFileName());
}
}

Expand Down Expand Up @@ -172,11 +172,6 @@ public static void UnregisterFunction(Type t)

public SwAddin()
{
Application.ThreadException +=
new ThreadExceptionEventHandler(ExceptionHandler);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(UnhandledException);
Logger.Setup();
}

Expand All @@ -194,21 +189,25 @@ private void UnhandledException(object sender, UnhandledExceptionEventArgs e)

public bool ConnectToSW(object ThisSW, int cookie)
{
logger.Info("Attempting to connect to SW");
SwApp = (ISldWorks)ThisSW;
addinID = cookie;
add_in_id_ = cookie;

//Setup callbacks
SwApp.SetAddinCallbackInfo(0, this, addinID);
logger.Info("Setting up callbacks");
SwApp.SetAddinCallbackInfo(0, this, add_in_id_);

#region Setup the Command Manager

logger.Info("Setting up command manager");
CmdMgr = SwApp.GetCommandManager(cookie);

logger.Info("Adding command manager");
AddCommandMgr();

#endregion Setup the Command Manager

#region Setup the Event Handlers

logger.Info("Adding event handlers");
SwEventPtr = (SldWorks)SwApp;
OpenDocs = new Hashtable();
AttachEventHandlers();
Expand Down Expand Up @@ -245,14 +244,38 @@ public bool DisconnectFromSW()

public void AddCommandMgr()
{
SwApp.AddMenuItem3((int)swDocumentTypes_e.swDocASSEMBLY, addinID, "Export as URDF@&File",
10, "AssemblyURDFExporter", "", "Export assembly as URDF file", "");
// Do not use AddMenuItem5 here despite the obselete warning, AddMenuItem5 doesn't work
string[] images = {
"C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_20x20.png",
"C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_32x32.png",
"C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_40x40.png",
"C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_64x64.png",
"C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_96x96.png",
"C:\\Program Files\\SOLIDWORKS Corp\\SOLIDWORKS\\URDFExporter\\images\\ros_logo_128x128.png",
};
int ret = SwApp.AddMenuItem5((int)swDocumentTypes_e.swDocASSEMBLY, add_in_id_, "Export as URDF@&Tools",
-1, "AssemblyURDFExporter", "", "Export assembly as URDF file", images);
if (ret < 0)
{
logger.Error("Failure to add menu item 'Export as URDF' to menu 'Tools'");
return;
}
logger.Info("Adding Assembly export to file menu");
SwApp.AddMenuItem3((int)swDocumentTypes_e.swDocPART, addinID, "Export as URDF@&File",
10, "PartURDFExporter", "", "Export part as URDF file", "");
ret = SwApp.AddMenuItem5((int)swDocumentTypes_e.swDocPART, add_in_id_, "Export as URDF@&Tools",
-1, "PartURDFExporter", "", "Export part as URDF file", images);
if (ret < 0)
{
logger.Error("Failure to add menu item 'Export as URDF' to menu 'Tools'");
return;
}

logger.Info("Adding Part export to file menu");
}

public int ToolbarEnableMethod()
{
return 1;
}
public void RemoveCommandMgr()
{
SwApp.RemoveMenu((int)swDocumentTypes_e.swDocASSEMBLY, "Export as URDF@&File", "");
Expand Down Expand Up @@ -343,6 +366,7 @@ public void SetupPartExporter()
PartExportForm exportForm = new PartExportForm((SldWorks)SwApp);
logger.Info("Showing part");
exportForm.Show();
exportForm.Dispose();
}
}

Expand Down Expand Up @@ -453,11 +477,14 @@ public void AttachEventsToAllDocuments()
}
else if (OpenDocs.Contains(modDoc))
{
bool connected = false;
DocumentEventHandler docHandler = (DocumentEventHandler)OpenDocs[modDoc];
if (docHandler != null)
{
connected = docHandler.ConnectModelViews();
bool connected = docHandler.ConnectModelViews();
if (!connected)
{
logger.Warn("Failed to connect to model views");
}
}
}

Expand All @@ -472,10 +499,9 @@ public bool AttachModelDocEventHandler(ModelDoc2 modDoc)
return false;
}

DocumentEventHandler docHandler = null;

if (!OpenDocs.Contains(modDoc))
{
DocumentEventHandler docHandler;
switch (modDoc.GetType())
{
case (int)swDocumentTypes_e.swDocPART:
Expand Down Expand Up @@ -506,11 +532,7 @@ public bool AttachModelDocEventHandler(ModelDoc2 modDoc)

public bool DetachModelEventHandler(ModelDoc2 modDoc)
{
DocumentEventHandler docHandler;
docHandler = (DocumentEventHandler)OpenDocs[modDoc];
OpenDocs.Remove(modDoc);
modDoc = null;
docHandler = null;
return true;
}

Expand Down
Loading

0 comments on commit dff1e0d

Please sign in to comment.