1- // SPDX-FileCopyrightText: 2009-2020 TRUMPF Laser GmbH, authors: C-Labs
1+ // SPDX-FileCopyrightText: 2009-2023 TRUMPF Laser GmbH, authors: C-Labs
22//
33// SPDX-License-Identifier: MPL-2.0
44
55using nsCDEngine . BaseClasses ;
66using nsCDEngine . Communication ;
7+ using nsCDEngine . Engines ;
78using nsCDEngine . Engines . NMIService ;
89using nsCDEngine . Engines . ThingService ;
910using nsCDEngine . ViewModels ;
1011using System ;
1112
1213namespace NMIService
1314{
14- public class TheNMIEditor : ICDEThing
15+ public class TheNMIEditor : TheThingBase
1516 {
16- #region ICDEThing Methods
17- public void SetBaseThing ( TheThing pThing )
18- {
19- MyBaseThing = pThing ;
20- }
21- public TheThing GetBaseThing ( )
22- {
23- return MyBaseThing ;
24- }
25- public virtual cdeP GetProperty ( string pName , bool DoCreate )
26- {
27- if ( MyBaseThing != null )
28- return MyBaseThing . GetProperty ( pName , DoCreate ) ;
29- return null ;
30- }
31- public virtual cdeP SetProperty ( string pName , object pValue )
32- {
33- if ( MyBaseThing != null )
34- return MyBaseThing . SetProperty ( pName , pValue ) ;
35- return null ;
36- }
37-
38- public void RegisterEvent ( string pName , Action < ICDEThing , object > pCallBack )
39- {
40- if ( MyBaseThing != null )
41- MyBaseThing . RegisterEvent ( pName , pCallBack ) ;
42- }
43- public void UnregisterEvent ( string pName , Action < ICDEThing , object > pCallBack )
44- {
45- if ( MyBaseThing != null )
46- MyBaseThing . UnregisterEvent ( pName , pCallBack ) ;
47- }
48- public void FireEvent ( string pEventName , ICDEThing sender , object pPara , bool FireAsync )
49- {
50- if ( MyBaseThing != null )
51- MyBaseThing . FireEvent ( pEventName , sender , pPara , FireAsync ) ;
52- }
53- public bool HasRegisteredEvents ( string pEventName )
54- {
55- if ( MyBaseThing != null )
56- return MyBaseThing . HasRegisteredEvents ( pEventName ) ;
57- return false ;
58- }
59-
60- public virtual void HandleMessage ( ICDEThing sender , object pMsg )
61- { }
62-
63- protected TheThing MyBaseThing ;
64-
65- protected bool mIsUXInitCalled ;
66- protected bool mIsUXInitialized ;
67- protected bool mIsInitCalled ;
68- protected bool mIsInitialized ;
69- public bool IsUXInit ( )
70- { return mIsUXInitialized ; }
71- public bool IsInit ( )
72- { return mIsInitialized ; }
73-
74- /// <summary>
75- /// The possible types of WeMo devices that can be detected
76- /// </summary>
77- #endregion
78-
79- public bool Init ( )
17+ public override bool Init ( )
8018 {
8119 if ( mIsInitCalled ) return false ;
8220 mIsInitCalled = true ;
@@ -97,25 +35,12 @@ public virtual bool DoInit()
9735 return true ;
9836 }
9937
100- public bool Delete ( )
101- {
102- mIsInitialized = false ;
103- // TODO Properly implement delete
104- return DoDelete ( ) ;
105- }
106-
107- public virtual bool DoDelete ( )
108- {
109- return true ;
110- }
111-
112-
11338 public virtual void sinkThrottleChanged ( cdeP pNewValue )
11439 {
11540 MyBaseThing . SetPublishThrottle ( TheCommonUtils . CInt ( pNewValue ) ) ;
11641 }
11742
118- public bool CreateUX ( )
43+ public override bool CreateUX ( )
11944 {
12045 if ( mIsUXInitCalled ) return false ;
12146 mIsUXInitCalled = true ;
@@ -176,29 +101,57 @@ public virtual bool DoCreateUX()
176101 {
177102 MyEditorForm = new TheFormInfo ( MyBaseThing ) { DefaultView = eDefaultView . Form , PropertyBag = new ThePropertyBag { "MaxTileWidth=6" , "HideCaption=true" , "AllowDrag=true" } } ;
178103 MyEditorForm . ModelID = "NMIEditor" ;
179-
104+ TheCDEngines . MyNMIService ? . SetProperty ( "NMIEditorFormID" , MyEditorForm . cdeMID ) ;
180105 TheDashboardInfo tDash = TheNMIEngine . GetDashboardById ( TheNMIHtml5RT . eNMIDashboard ) ;
181106 MyEditorDashIcon = TheNMIEngine . AddFormToThingUX ( tDash , MyBaseThing , MyEditorForm , "CMyForm" , "NMI Control Editor" , 1 , 0x89 , 0x80 , "NMI" , null , new ThePropertyBag ( ) { "RenderTarget=cdeInSideBarRight" , "NeverHide=true" } ) ; //"mAllowDrag=true", "nVisibility=false",
107+ return true ; //retired for now. Moved into NMI Control Code
182108
183- MySampleControl = TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . SingleEnded , 3 , 2 , MyBaseThing . cdeA , "CurrentValue" , "Value" , null ) ;
109+ TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileGroup , 9 , 0 , 0 , null , null , new nmiCtrlTileGroup { TileWidth = 7 , TileHeight = 1 , TileFactorY = 2 } ) ;
110+ TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileButton , 10 , 2 , 0 , "Main" , null , new nmiCtrlTileButton { ParentFld = 9 , OnClick = "GRP:NMIP:Main" , TileWidth = 1 , TileHeight = 1 , TileFactorY = 2 , NoTE = true , ClassName = "cdeTransitButton" } ) ;
111+ //TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileButton, 20, 2, 0, "Screen", null, new nmiCtrlTileButton { ParentFld = 9, OnClick = "GRP:NMIP:Screen", TileWidth = 1, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton" });
112+ TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileButton , 30 , 2 , 0 , "All" , null , new nmiCtrlTileButton { ParentFld = 9 , OnClick = "GRP:NMIP:All" , TileWidth = 1 , TileHeight = 1 , TileFactorY = 2 , NoTE = true , ClassName = "cdeTransitButton" } ) ;
113+ //TheNMIEngine.AddSmartControl(MyBaseThing, MyEditorForm, eFieldType.TileButton, 40, 2, 0, "Source", null, new nmiCtrlTileButton { ParentFld = 9, OnClick = "GRP:NMIP:Source", TileWidth = 1, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton" });
184114
115+ TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileGroup , 1000 , 2 , 0x80 , null , null , new nmiCtrlTileGroup ( ) { Group = "NMIP:Main" } ) ;
185116
186- TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileGroup , 9 , 0 , 0 , null , null , new nmiCtrlTileGroup { TileWidth = 7 , TileHeight = 1 , TileFactorY = 2 } ) ;
187- TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileButton , 10 , 2 , 0 , "Basic" , null , new nmiCtrlTileButton { ParentFld = 9 , OnClick = "GRP:NMIP:Basic" , TileWidth = 1 , TileHeight = 1 , TileFactorY = 2 , NoTE = true , ClassName = "cdeTransitButton" } ) ;
188- TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileButton , 20 , 2 , 0 , "Screen" , null , new nmiCtrlTileButton { ParentFld = 9 , OnClick = "GRP:NMIP:Screen" , TileWidth = 1 , TileHeight = 1 , TileFactorY = 2 , NoTE = true , ClassName = "cdeTransitButton" } ) ;
189- TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileButton , 30 , 2 , 0 , "All" , null , new nmiCtrlTileButton { ParentFld = 9 , OnClick = "GRP:NMIP:All" , TileWidth = 1 , TileHeight = 1 , TileFactorY = 2 , NoTE = true , ClassName = "cdeTransitButton" } ) ;
190- TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileButton , 40 , 2 , 0 , "Source" , null , new nmiCtrlTileButton { ParentFld = 9 , OnClick = "GRP:NMIP:Source" , TileWidth = 1 , TileHeight = 1 , TileFactorY = 2 , NoTE = true , ClassName = "cdeTransitButton" } ) ;
191- //TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 50, 2, 0, "Compounds", null, new nmiCtrlTileButton { OnClick = "GRP:Cate:5", TileWidth = 2, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton" });
192- //TheNMIEngine.AddSmartControl(MyBaseThing, MyStatusForm, eFieldType.TileButton, 60, 2, 0, "Gauges", null, new nmiCtrlTileButton { OnClick = "GRP:Cate:6", TileWidth = 2, TileHeight = 1, TileFactorY = 2, NoTE = true, ClassName = "cdeTransitButton" });
193- TheFieldInfo mSendbutton = TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileButton , 70 , 2 , 0x80 , "Reload" , false , "" , null , new nmiCtrlTileButton ( ) { ParentFld = 9 , TileWidth = 2 , NoTE = true , TileFactorY = 2 , ClassName = "cdeGoodActionButton" } ) ;
194- mSendbutton . RegisterUXEvent ( MyBaseThing , eUXEvents . OnClick , "" , ( pThing , pPara ) =>
117+ //ALL Properties
118+ TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileGroup , 2000 , 2 , 0x80 , null , null , new nmiCtrlTileGroup ( ) { TileWidth = 6 , Group = "NMIP:All" , Visibility = false } ) ;
119+
120+ TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . Table , 2010 , 0xA2 , 0x80 , "All Properties" , "mypropertybag;1" , new ThePropertyBag ( ) { "NoTE=true" , "TileHeight=5" , "TileWidth=6" , "ParentFld=2000" } ) ;
121+ TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . SingleEnded , 2020 , 0x0A , 0 , "New Property Name" , "ScratchName" , new nmiCtrlSingleEnded ( ) { ParentFld = 2000 } ) ;
122+ TheFieldInfo tBut = TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileButton , 2040 , 0x0A , 0 , "Add Property" , false , null , null , new nmiCtrlTileButton ( ) { ParentFld = 2000 , NoTE = true , ClassName = "cdeGoodActionButton" } ) ;
123+ tBut . RegisterUXEvent ( MyBaseThing , eUXEvents . OnClick , "AddProp" , ( pThing , pObj ) =>
195124 {
196- TheProcessMessage pMsg = pPara as TheProcessMessage ;
125+ TheProcessMessage pMsg = pObj as TheProcessMessage ;
197126 if ( pMsg ? . Message == null ) return ;
198- UpdateUx ( pThing . GetBaseThing ( ) ) ;
199- MyEditorForm . Reload ( pMsg , tDash . cdeMID , true ) ;
127+ TheThing tOrg = pThing . GetBaseThing ( ) ;
128+
129+ string tNewPropName = TheThing . GetSafePropertyString ( tOrg , "ScratchName" ) ;
130+ if ( string . IsNullOrEmpty ( tNewPropName ) )
131+ TheCommCore . PublishToOriginator ( pMsg . Message , new TSM ( eEngineName . NMIService , "NMI_TOAST" , "Please specify a new property name" ) ) ;
132+ else
133+ {
134+ if ( tOrg . GetProperty ( tNewPropName ) != null )
135+ {
136+ TheCommCore . PublishToOriginator ( pMsg . Message , new TSM ( eEngineName . NMIService , "NMI_TOAST" , "Property already exists" ) ) ;
137+ }
138+ else
139+ {
140+ tOrg . DeclareNMIProperty ( tNewPropName , ePropertyTypes . TString ) ;
141+ TheCommCore . PublishToOriginator ( pMsg . Message , new TSM ( eEngineName . NMIService , "NMI_TOAST" , "Property Added" ) ) ;
142+ MyEditorForm . Reload ( pMsg , false ) ;
143+ }
144+ tOrg . SetProperty ( "ScratchName" , "" ) ;
145+ }
200146 } ) ;
201147
148+ return true ; //retired for now. Moved into NMI Control Code
149+
150+ MySampleControl = TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . SingleEnded , 3 , 2 , MyBaseThing . cdeA , "CurrentValue" , "Value" , null ) ;
151+
152+
153+
154+
202155 TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileGroup , 1000 , 2 , 0x80 , null , null , new nmiCtrlTileGroup ( ) { Group = "NMIP:Basic" } ) ;
203156 TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . ComboBox , 1010 , 2 , 0x80 , "Control Type" , "ControlType" , new ThePropertyBag ( ) { "Options=%RegisteredControlTypes%" , "ParentFld=1000" } ) ;
204157 GetProperty ( "ControlType" , true ) . RegisterEvent ( eThingEvents . PropertyChanged , ( p ) =>
@@ -255,38 +208,7 @@ public virtual bool DoCreateUX()
255208 "<span class='fa-stack'><i class='fa fa-stack-1x'></i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'></i></span>," +
256209 "<span class='fa-stack'><i class='fa fa-stack-1x'></i><i class='fa fa-stack-2x text-danger' style='opacity:0.5'></i></span>" , "ParentFld=3000" } ) . FldWidth = 1 ;
257210
258- //ALL Properties
259- TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileGroup , 2000 , 2 , 0x80 , null , null , new nmiCtrlTileGroup ( ) { TileWidth = 6 , Group = "NMIP:All" , Visibility = false } ) ;
260211
261- TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . Table , 2010 , 0xA2 , 0x80 , "All Properties" , "mypropertybag;1" , new ThePropertyBag ( ) { "NoTE=true" , "TileHeight=4" , "TileLeft=9" , "TileTop=3" , "TileWidth=6" , "FldWidth=6" , "ParentFld=2000" } ) ;
262- TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . SingleEnded , 2020 , 0x0A , 0 , "New Property Name" , "ScratchName" , new nmiCtrlSingleEnded ( ) { ParentFld = 2000 } ) ;
263- TheFieldInfo tBut = TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileButton , 2040 , 0x0A , 0 , "Add Property" , false , null , null , new nmiCtrlTileButton ( ) { ParentFld = 2000 , NoTE = true , ClassName = "cdeGoodActionButton" } ) ;
264- tBut . RegisterUXEvent ( MyBaseThing , eUXEvents . OnClick , "AddProp" , ( pThing , pObj ) =>
265- {
266- TheProcessMessage pMsg = pObj as TheProcessMessage ;
267- if ( pMsg ? . Message == null ) return ;
268- string [ ] parts = pMsg . Message . PLS . Split ( ':' ) ;
269- TheThing tOrg = pThing . GetBaseThing ( ) ; // TheThingRegistry.GetThingByMID(MyBaseEngine.GetEngineName(), TheCommonUtils.CGuid(parts[2]));
270- //if (tOrg == null) return;
271-
272- string tNewPropName = TheThing . GetSafePropertyString ( tOrg , "ScratchName" ) ;
273- if ( string . IsNullOrEmpty ( tNewPropName ) )
274- TheCommCore . PublishToOriginator ( pMsg . Message , new TSM ( eEngineName . NMIService , "NMI_TOAST" , "Please specify a new property name" ) ) ;
275- else
276- {
277- if ( tOrg . GetProperty ( tNewPropName ) != null )
278- {
279- TheCommCore . PublishToOriginator ( pMsg . Message , new TSM ( eEngineName . NMIService , "NMI_TOAST" , "Property already exists" ) ) ;
280- }
281- else
282- {
283- tOrg . DeclareNMIProperty ( tNewPropName , ePropertyTypes . TString ) ;
284- TheCommCore . PublishToOriginator ( pMsg . Message , new TSM ( eEngineName . NMIService , "NMI_TOAST" , "Property Added" ) ) ;
285- MyEditorForm . Reload ( pMsg , false ) ;
286- }
287- tOrg . SetProperty ( "ScratchName" , "" ) ;
288- }
289- } ) ;
290212
291213 //THING Connector
292214 TheNMIEngine . AddSmartControl ( MyBaseThing , MyEditorForm , eFieldType . TileGroup , 5000 , 2 , 0x80 , null , null , new nmiCtrlTileGroup ( ) { TileWidth = 6 , Group = "NMIP:Source" , Visibility = false } ) ;
0 commit comments