Skip to content

Commit 16b97ae

Browse files
author
miguelh
committed
New feature: DSS Visualization Tool support. Includes new plot commands, TCP/IP communication and JSON format for message exchange.
git-svn-id: svn://svn.code.sf.net/p/electricdss/code/trunk@2093 d8739450-1e93-4ef4-a0af-c327d92816ff
1 parent d5de316 commit 16b97ae

File tree

7 files changed

+1485
-10
lines changed

7 files changed

+1485
-10
lines changed

Source/Common/DSSGlobals.pas

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
interface
2222

2323
Uses Classes, DSSClassDefs, DSSObject, DSSClass, ParserDel, Hashlist, PointerList,
24-
UComplex, Arraydef, CktElement, Circuit, IniRegSave, {$IFNDEF FPC}Graphics,{$ENDIF}
24+
UComplex, Arraydef, CktElement, Circuit, IniRegSave, {$IFNDEF FPC}Graphics,{$ENDIF} System.IOUtils, inifiles,
2525

2626
{Some units which have global vars defined here}
2727
Spectrum,
@@ -109,7 +109,12 @@ interface
109109
DLLDebugFile :TextFile;
110110
ProgramName :String;
111111
DSS_Registry :TIniRegSave; // Registry (See Executive)
112-
112+
113+
// Global variables for the DSS visualization tool
114+
DSS_Viz_installed :Boolean=False; // DSS visualization tool (flag of existance)
115+
DSS_Viz_path: String;
116+
DSS_Viz_enable: Boolean=False;
117+
113118
IsDLL,
114119
NoFormsAllowed :Boolean;
115120

@@ -772,6 +777,39 @@ function IsDirectoryWritable(const Dir: String): Boolean;
772777
ReallocMem(p, newsize);
773778
End;
774779

780+
// Advance visualization tool check
781+
function GetIni(s,k: string; d: string; f: string=''): string; overload;
782+
var
783+
ini: TMemIniFile;
784+
begin
785+
Result := d;
786+
if f = '' then
787+
begin
788+
ini := TMemIniFile.Create(lowercase(ChangeFileExt(ParamStr(0),'.ini')));
789+
end
790+
else
791+
begin
792+
if not FileExists(f) then Exit;
793+
ini := TMemIniFile.Create(f);
794+
end;
795+
if ini.ReadString(s,k,'') = '' then
796+
begin
797+
ini.WriteString(s,k,d);
798+
ini.UpdateFile;
799+
end;
800+
Result := ini.ReadString(s,k,d);
801+
FreeAndNil(ini);
802+
end;
803+
804+
function CheckDSSVisualizationTool: Boolean;
805+
begin
806+
DSS_Viz_path:=GetIni('Application','path','', TPath.GetHomePath+'\OpenDSS Visualization Tool\settings.ini');
807+
Result:=true;
808+
if DSS_Viz_path='' then
809+
Result:=false;
810+
end;
811+
// End of visualization tool check
812+
775813
initialization
776814

777815
{Various Constants and Switches}
@@ -881,6 +919,8 @@ initialization
881919

882920
//WriteDLLDebugFile('DSSGlobals');
883921

922+
DSS_Viz_installed:= CheckDSSVisualizationTool; // DSS visualization tool (flag of existance)
923+
884924
Finalization
885925

886926
// Dosimplemsg('Enter DSSGlobals Unit Finalization.');
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
unit ConnectOptions;
2+
{
3+
----------------------------------------------------------
4+
Copyright (c) 2008-2017, Electric Power Research Institute, Inc.
5+
All rights reserved.
6+
----------------------------------------------------------
7+
}
8+
9+
interface
10+
11+
Uses Command;
12+
13+
CONST
14+
NumConnectOptions = 2;
15+
16+
FUNCTION DoConnectCmd:Integer;
17+
FUNCTION DoDisConnectCmd:Integer;
18+
19+
Var
20+
ConnectOption,
21+
ConnectHelp :Array[1..NumConnectOptions] of String;
22+
ConnectCommands:TCommandList;
23+
24+
implementation
25+
26+
Uses TCP_IP, DSSGlobals, SysUtils, ParserDel, Utilities;
27+
28+
29+
PROCEDURE DefineOptions;
30+
Begin
31+
ConnectOption[ 1] := 'address';
32+
ConnectOption[ 2] := 'port';
33+
34+
ConnectHelp[ 1] := 'Address is a string containing the IP address of a particular system with which OpenDSS should form a connection';
35+
ConnectHelp[ 2] := 'Port is the ID of the desired server connection:'+ CRLF +
36+
'47625 = DSS Visualization Tool';
37+
End;
38+
39+
FUNCTION DoConnectCmd:Integer;
40+
//Var
41+
// ParamName, Param:String;
42+
// ParamPointer, i:Integer;
43+
Begin
44+
Result := 0;
45+
// If NoFormsAllowed Then Begin Result :=1; Exit; End;
46+
If Not Assigned(DSSConnectObj) Then DSSConnectObj := TDSSConnect.Create;
47+
DSSConnectObj.SetDefaults;
48+
With DSSConnectObj Do Begin
49+
Connect;
50+
End;
51+
End;
52+
53+
FUNCTION DoDisConnectCmd:Integer;
54+
//Var
55+
// ParamName, Param:String;
56+
// ParamPointer, i:Integer;
57+
Begin
58+
Result := 0;
59+
// If NoFormsAllowed Then Begin Result :=1; Exit; End;
60+
If Assigned(DSSConnectObj) Then
61+
begin
62+
With DSSConnectObj Do Begin
63+
Disconnect;
64+
End;
65+
end;
66+
End;
67+
68+
69+
Procedure DisposeStrings;
70+
Var i:Integer;
71+
72+
Begin
73+
For i := 1 to NumConnectOptions Do Begin
74+
ConnectOption[i] := '';
75+
ConnectHelp[i] := '';
76+
End;
77+
78+
End;
79+
80+
81+
Initialization
82+
DefineOptions;
83+
ConnectCommands := TCommandList.Create(ConnectOption);
84+
ConnectCommands.Abbrev := True;
85+
86+
Finalization
87+
DoDisConnectCmd;
88+
DisposeStrings;
89+
ConnectCommands.Free;
90+
end.

Source/Executive/ExecCommands.pas

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface
1111
Uses Command;
1212

1313
CONST
14-
NumExecCommands = 104;
14+
NumExecCommands = 106;
1515

1616
Var
1717

@@ -28,7 +28,7 @@ interface
2828
implementation
2929

3030
Uses DSSGlobals, ExecHelper, Executive, ExecOptions, ShowOptions,
31-
ExportOptions, ParserDel, LoadShape,
31+
ExportOptions, ConnectOptions, ParserDel, LoadShape,
3232
{$IFDEF FPC} CmdForms,{$ELSE} PlotOptions, DSSForms,{$ENDIF}
3333
sysutils, Utilities, SolutionAlgs;
3434

@@ -142,6 +142,8 @@ implementation
142142
ExecCommand[102] := 'Cleanup';
143143
ExecCommand[103] := 'FinishTimeStep';
144144
ExecCommand[104] := 'NodeList';
145+
ExecCommand[105] := 'Connect';
146+
ExecCommand[106] := 'Disconnect';
145147

146148

147149

@@ -460,6 +462,8 @@ implementation
460462
'If the optional circuit element name is supplied, the program makes it the active element. Usage:' +CRLF+CRLF+
461463
'NodeList' + CRLF +
462464
'NodeList Line.Myline';
465+
CommandHelp[105] := 'Request to create a TCP/IP socket to communicate data with external modules. This function requires the host address and TCP port to connect.';
466+
CommandHelp[106] := 'Request to terminate a TCP/IP socket. This function requires the host address and TCP port to disconnect.';
463467

464468
End;
465469

@@ -686,6 +690,8 @@ implementation
686690
102: EndofTimeStepCleanup;
687691
103: FinishTimeStep;
688692
104: CmdResult := DoNodeListCmd;
693+
105: CmdResult := DoConnectCmd; //'TCP/IP connect';
694+
106: CmdResult := DoDisConnectCmd; //'TCP/IP disconnect';
689695
ELSE
690696
// Ignore excess parameters
691697
End;

Source/Executive/ExecOptions.pas

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface
1111
Uses Command;
1212

1313
CONST
14-
NumExecOptions = 110;
14+
NumExecOptions = 111;
1515

1616
VAR
1717
ExecOption,
@@ -143,6 +143,7 @@ implementation
143143
ExecOption[108] := 'StepTime';
144144
ExecOption[109] := 'SampleEnergyMeters';
145145
ExecOption[110] := 'MinIterations'; // default is 2
146+
ExecOption[111] := 'DSSVisualizationTool';
146147

147148

148149

@@ -396,6 +397,8 @@ implementation
396397
'Normally Time and Duty modes do not automatically sample EnergyMeters whereas Daily, Yearly, M1, M2, M3, LD1 and LD2 modes do. ' +
397398
'Use this Option to turn sampling on or off';
398399
OptionHelp[110] := 'Minimum number of iterations required for a solution. Default is 2.';
400+
OptionHelp[111] := 'Activates/Deactivates the extended version of the plot command for figures with the DSS Visualization Tool.';
401+
399402
End;
400403
//----------------------------------------------------------------------------
401404
FUNCTION DoSetCmd_NoCircuit:Boolean; // Set Commands that do not require a circuit
@@ -427,6 +430,9 @@ implementation
427430
67: DSSExecutive.RecorderOn := InterpretYesNo(Param);
428431
73: DefaultBaseFreq := Parser.DblValue;
429432
102: UpdateRegistry := InterpretYesNo(Param);
433+
111: begin
434+
DSS_Viz_enable := InterpretYesNo(Param);
435+
end;
430436
ELSE
431437
Begin
432438
DoSimpleMsg('You must create a new circuit object first: "new circuit.mycktname" to execute this Set command.', 301);
@@ -619,6 +625,8 @@ implementation
619625
107: ActiveCircuit.Solution.Total_Time := Parser.DblValue;
620626
109: ActiveCircuit.Solution.SampleTheMeters := InterpretYesNo(Param);
621627
110: ActiveCircuit.solution.MinIterations := Parser.IntValue;
628+
111: DSS_Viz_enable := InterpretYesNo(Param);
629+
622630
ELSE
623631
// Ignore excess parameters
624632
End;
@@ -795,6 +803,8 @@ implementation
795803
108: AppendGlobalResult(Format('%-g' ,[ActiveCircuit.Solution.Time_Step]));
796804
109: If ActiveCircuit.Solution.SampleTheMeters Then AppendGlobalResult('Yes') else AppendGlobalResult('No');
797805
110: AppendGlobalResult(IntToStr(ActiveCircuit.solution.MinIterations));
806+
111: if DSS_Viz_enable then AppendGlobalResult('Yes') else AppendGlobalResult('No');
807+
798808
ELSE
799809
// Ignore excess parameters
800810
End;

Source/Executive/PlotOptions.pas

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,14 @@ implementation
204204
ValueIndex := 2;
205205
End;
206206
'C': PlotType := ptCircuitplot;
207+
'E': PlotType := ptEvolutionPlot;
207208
'G': PlotType := ptGeneralDataPlot;
208209
'L': PlotType := ptLoadshape;
209-
'M': PlotType := ptMonitorplot;
210+
'M': IF CompareTextShortest('mon', Param)=0 Then PlotType := ptMonitorplot
211+
ELSE PlotType := ptMatrixplot;
210212
'P': IF CompareTextShortest('pro', Param)=0 Then PlotType := ptProfile
211213
ELSE PlotType := ptPriceShape;
214+
'S': PlotType := ptScatterPlot;
212215
'T': PlotType := ptTshape;
213216
'D': Begin
214217
PlotType := ptDaisyplot;
@@ -293,9 +296,26 @@ implementation
293296
If Not ActiveCircuit.Issolved Then DSSPlotObj.Quantity := pqNone;
294297

295298
With DSSPlotObj Do Begin
296-
297-
Execute; // makes a new plot based on these options
298-
299+
if DSS_Viz_enable then
300+
begin
301+
if (DSS_Viz_installed and ((
302+
PlotType = ptMonitorplot) or (
303+
PlotType = ptLoadshape) or (
304+
PlotType = ptProfile) or (
305+
PlotType = ptScatterPlot) or (
306+
PlotType = ptEvolutionPlot) or (
307+
PlotType = ptMatrixplot))) then
308+
DSSVizPlot; // DSS Visualization tool
309+
end
310+
else
311+
begin
312+
if (PlotType = ptScatterPlot) or (
313+
PlotType = ptEvolutionPlot) or (
314+
PlotType = ptMatrixplot) then
315+
DoSimpleMsg('The DSS Visualization tool is disabled (Check the DSSVisualizationTool option).',0)
316+
else
317+
Execute; // makes a new plot based on these options
318+
end;
299319
End;
300320

301321
End;

Source/Plot/DSSPlot.pas

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ interface
3333
Type
3434
TPlotType = (ptAutoAddLogPlot, ptCircuitplot, ptGeneralDataPlot,
3535
ptGeneralCircuitPlot, ptmonitorplot, ptdaisyplot, ptMeterZones,
36-
ptLoadShape, ptTShape, ptPriceShape, ptProfile);
36+
ptLoadShape, ptTShape, ptPriceShape, ptProfile, ptScatterPlot,
37+
ptEvolutionPlot, ptMatrixplot);
3738
TPlotQuantity = (pqVoltage, pqCurrent, pqPower, pqLosses, pqCapacity,
3839
pqNone);
3940

@@ -122,6 +123,7 @@ TDSSPlot = class(TObject)
122123

123124
Procedure Execute;
124125
Procedure SetDefaults;
126+
procedure DSSVizPlot;
125127

126128
Procedure DoLoadShapePlot(Const LoadShapeName: String);
127129
Procedure DoTempShapePlot(Const TempShapeName: String);
@@ -170,6 +172,7 @@ TGenPlotItemList = class(TList)
170172
implementation
171173

172174
Uses DSSGraph,
175+
TCP_IP,
173176
Comobj,
174177
DSSClassDefs,
175178
DssGlobals,
@@ -1089,6 +1092,31 @@ procedure TDSSPlot.Execute;
10891092

10901093
end;
10911094

1095+
procedure TDSSPlot.DSSVizPlot;
1096+
begin
1097+
If Not Assigned(DSSConnectObj) Then // First connection
1098+
begin
1099+
DSSConnectObj := TDSSConnect.Create; // Creates the connection
1100+
end;
1101+
1102+
DSSConnectObj.Connect; // Connects to the server
1103+
1104+
Case PlotType of // Classifies the plot message
1105+
ptmonitorplot:
1106+
DSSConnectObj.MonitorPlotMsg(ObjectName);
1107+
ptLoadshape:
1108+
DSSConnectObj.LoadshapePlotMsg(ObjectName);
1109+
ptProfile:
1110+
DSSConnectObj.ProfilePlotMsg(ObjectName);
1111+
ptScatterPlot:
1112+
DSSConnectObj.ScatterPlotMsg;
1113+
ptEvolutionPlot:
1114+
DSSConnectObj.EvolutionPlotMsg;
1115+
ptMatrixplot:
1116+
DSSConnectObj.MatrixPlotMsg;
1117+
End;
1118+
end;
1119+
10921120
function TDSSPlot.InterpolateGradientColor(Color1, Color2: TColor;
10931121
Ratio: Double): TColor;
10941122
const

0 commit comments

Comments
 (0)