1- using CodeStack . Community . GeometryPlusPlus . Features . BodiesFillet ;
1+ using CodeStack . Community . GeometryPlusPlus . Core ;
2+ using CodeStack . Community . GeometryPlusPlus . Features . BodiesFillet ;
23using CodeStack . Community . GeometryPlusPlus . Features . ExtrudeSurfaceCap ;
34using CodeStack . Community . GeometryPlusPlus . Features . SolidToSurface ;
4- using CodeStack . Community . GeometryPlusPlus . Features . TrimSurfacesByRegion ;
55using CodeStack . Community . GeometryPlusPlus . Properties ;
66using CodeStack . SwEx . AddIn ;
77using CodeStack . SwEx . AddIn . Attributes ;
88using CodeStack . SwEx . AddIn . Enums ;
9+ using CodeStack . SwEx . Common . Attributes ;
910using System ;
1011using System . Collections . Generic ;
1112using System . ComponentModel ;
@@ -27,124 +28,22 @@ namespace CodeStack.Community.GeometryPlusPlus
2728#if DEBUG
2829 [ AutoRegister ( "Geometry++" , "Additional geometry functionality for SOLIDWORKS" ) ]
2930#endif
31+ [ LoggerOptions ( true , LOGGER_NAME ) ]
3032 public class AddIn : SwAddInEx
3133 {
32- //TODO: redundancy - make commands to load from the available macro features
34+ internal const string LOGGER_NAME = "Geometry++" ;
3335
34- [ Title ( "Geometry++" ) ]
35- [ Icon ( typeof ( Resources ) , nameof ( Resources . geometry_plus_plus ) ) ]
36- private enum Commands_e
37- {
38- [ Icon ( typeof ( Resources ) , nameof ( Resources . solid_to_surface ) ) ]
39- [ Title ( "Convert Solid To Surface" ) ]
40- [ CommandItemInfo ( true , true , swWorkspaceTypes_e . Part , true ) ]
41- SolidToSurface ,
42-
43- [ Icon ( typeof ( Resources ) , nameof ( Resources . trim_surface_region ) ) ]
44- [ Title ( "Trim Surface By Region" ) ]
45- [ CommandItemInfo ( true , true , swWorkspaceTypes_e . Part , true ) ]
46- TrimSurfaceByRegion ,
47-
48- [ Icon ( typeof ( Resources ) , nameof ( Resources . extrude_surface_caps ) ) ]
49- [ Title ( "Extrude Surface Cap" ) ]
50- [ CommandItemInfo ( true , true , swWorkspaceTypes_e . Part , true ) ]
51- ExtrudeSurfaceCap ,
52-
53- [ Icon ( typeof ( Resources ) , nameof ( Resources . fillet ) ) ]
54- [ Title ( "Bodies Fillet" ) ]
55- [ CommandItemInfo ( true , true , swWorkspaceTypes_e . Part , true ) ]
56- BodiesFillet ,
57-
58- [ Title ( "About..." ) ]
59- [ Description ( "About Geometry++" ) ]
60- [ CommandItemInfo ( true , false , swWorkspaceTypes_e . All ) ]
61- [ Icon ( typeof ( Resources ) , nameof ( Resources . about_icon ) ) ]
62- About
63- }
64-
65- private ServicesManager m_Kit ;
36+ private ServicesContainer m_Services ;
6637
6738 public override bool OnConnect ( )
68- {
69- m_Kit = new ServicesManager ( this . GetType ( ) . Assembly , new IntPtr ( App . IFrameObject ( ) . GetHWnd ( ) ) ,
70- typeof ( UpdatesService ) ,
71- typeof ( SystemEventLogService ) ,
72- typeof ( AboutApplicationService ) ) ;
73-
74- m_Kit . HandleError += OnHandleError ;
75-
76- var syncContext = SynchronizationContext . Current ;
77-
78- if ( syncContext == null )
79- {
80- syncContext = new System . Windows . Forms . WindowsFormsSynchronizationContext ( ) ;
81- }
82-
83- Task . Run ( ( ) =>
84- {
85- SynchronizationContext . SetSynchronizationContext (
86- syncContext ) ;
87- m_Kit . StartServicesAsync ( ) . Wait ( ) ;
88- } ) ;
89-
90- this . AddCommandGroup < Commands_e > ( OnButtonClicked ) ;
91-
92- return true ;
93- }
94-
95- private bool OnHandleError ( Exception ex )
96- {
97- try
98- {
99- m_Kit . GetService < ILogService > ( ) . LogException ( ex ) ;
100- }
101- catch
102- {
103- }
104-
105- return true ;
106- }
107-
108- private void OnButtonClicked ( Commands_e btn )
10939 {
110- switch ( btn )
111- {
112- //TODO: use dependency injection with singleton
113-
114- case Commands_e . SolidToSurface :
115- {
116- new SolidToSurfaceMacroFeature ( ) . Insert ( App , App . IActiveDoc2 ) ;
117- break ;
118- }
40+ m_Services = new ServicesContainer ( App ) ;
11941
120- case Commands_e . TrimSurfaceByRegion :
121- {
122- new TrimSurfacesByRegionMacroFeature ( ) . Insert ( App , App . IActiveDoc2 ) ;
123- break ;
124- }
42+ var cmdBar = m_Services . GetService < GeometryFeaturesCommandGroupSpec > ( ) ;
12543
126- case Commands_e . ExtrudeSurfaceCap :
127- {
128- App . SendMsgToUser ( "Not implemented" ) ;
129- new ExtrudeSurfaceCapMacroFeature ( ) . Insert ( App , App . IActiveDoc2 ) ;
130- break ;
131- }
44+ this . AddCommandGroup ( cmdBar ) ;
13245
133- case Commands_e . BodiesFillet :
134- {
135- App . SendMsgToUser ( "Not implemented" ) ;
136- new BodiesFilletMacroFeature ( ) . Insert ( App , App . IActiveDoc2 ) ;
137- break ;
138- }
139-
140- case Commands_e . About :
141- m_Kit . GetService < IAboutApplicationService > ( ) . ShowAboutForm ( ) ;
142- break ;
143-
144- default :
145- App . SendMsgToUser ( "Not implemented" ) ;
146- break ;
147- }
46+ return true ;
14847 }
14948 }
15049}
0 commit comments