-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathProjectTypes.pas
More file actions
3915 lines (3818 loc) · 146 KB
/
ProjectTypes.pas
File metadata and controls
3915 lines (3818 loc) · 146 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// main classes, implementing document and project types
// - this unit is part of SynProject, under GPL 3.0 license; version 1.7
unit ProjectTypes;
(*
This file is part of SynProject.
Synopse SynProject. Copyright (C) 2008-2023 Arnaud Bouchez
Synopse Informatique - https://synopse.info
SynProject is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.
SynProject is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
along with SynProject. If not, see <http://www.gnu.org/licenses/>.
*)
interface
{$ifndef DONTUSEPARSER} // for ProjectVersion, e.g.
{$define USEPARSER}
// attempt to get information from source code directly
{$define WITH_GRAPHVIZ}
// if defined, the WinGraphviz COM server will be used to generated diagrams
// (must be defined in ProjectParser, ProjectEditor and ProjectTypes)
{$endif}
uses
Windows, SysUtils, Classes, Contnrs,
ProjectRTF,
ProjectCommons,
ProjectSections,
ProjectVersioning;
const
/// all on-the-fly generated diagrams (from WinGraphviz) are stored in
// this subfolder
GraphDirName = 'GG\';
type
TRiskOneDef = record
Name: string;
Description: string;
Level: array[1..3] of string;
end;
TRiskDef = array[0..2] of TRiskOneDef;
resourcestring
sAbstract = 'Abstract';
sAbstractN = '%s Abstract';
sSpecification = 'Specification';
sRiskDef = 'Severity,identify the severity of incorrect implementation,'+
'Cosmetic or no effect to intended operation,'+
'Potentially effects one or multiple features for intended operation,'+
'Potentially affects a result or safety,'+
'Probability,identify the probability of incorrect or incomplete implementation,'+
'Documentation and familiar with the code,'+
'Documentation but not familiar/familiar but no documentation,'+
'No documentation and not familiar with the code area,'+
'Occurrence,identify the reproducibility of the defect before correction,'+
'One time: relatively few or remote likelihood of failure (<5% failure rate),'+
'Intermittent or recurring: occasional failures (5-25% failure rate),'+
'Reproducible: failure inevitable or repeated (>25% failure rate)';
sRiskShort = 'Sev.,Pro.,Occ.,Management approval,Approved';
sDocumentPurposeSentence =
'The {\i %s} document purpose is to %s for the {\i %s} project.\par '+
'The current revision of this document is %s.\par';
sProjectDocumentation = 'PROJECT DOCUMENTATION';
sTestProcedure = 'TEST PROCEDURE';
sDocumentName = 'Document Name';
sDocumentRevision = 'Document Revision';
sDocumentPurpose = 'Document Purpose';
sDisplayName = 'Display Name';
sPreparedBy = 'Prepared by';
sReviewedBy ='Reviewed by';
sApprovedBy = 'Approved by';
sCompany = 'Company Name';
sProjectName = 'Project Name';
sProtocolName = 'Protocol Name';
sProtocolDescription = 'Protocol Description';
sProtocolRevision = 'Protocol Revision';
sProtocolDate = 'Protocol Date';
sDateTested = 'Date Tested';
sTestedBy = 'Tested by';
sTestDate = 'Test Date';
sPassFail = 'Pass / Fail';
sYesNo = 'Yes / No';
sTestFeatures = 'Test features';
sActions = 'Actions';
sProcedureRequires = 'This procedure requires:';
sExpectedResults = 'Expected results';
sSpecialRequirements = 'Special Requirements';
sDescriptionRtfN = '{\i %s description}';
sProcedureCriteria = 'Procedure Pass/Fail criteria';
sProcedureCriteriaText = 'The procedure will pass if all actions are completed correctly '+
'and no major problem is found';
sSummarySheet = 'Summary sheet';
sExpected = 'expected';
sProcedureSteps = 'Procedure steps';
sValidation = 'Validation';
sObservation = 'Observation';
sRequirement = 'Requirement';
sReference = 'Reference';
sTitle = 'Title';
sSignature = 'Signature';
sDate = 'Date';
sRiskAssessment = 'Risk Assessment';
sRiskAssessmentScale = 'Risk Assessment Scale';
sHighMedLow = 'High,Med,Low';
sDocumentRevisionTable = 'Document Revision Table';
sRev = 'Rev.';
sRevisionSharp = 'Revision #';
sWrittenBy = 'Written by';
sRef = 'Ref.';
sAuthor = 'Author';
sVersion = 'Version';
sDescription = 'Description';
sDescriptionN = '%s Description';
sRequest = 'Request';
sPage = 'Page';
sBelow = 'below';
sPageN = '(page %s)';
sPageNN = 'Page %s of %s';
sItemSharp = 'Item #';
sGlobalArchitecture = 'Global Architecture';
sSourceCodeImplementation = 'source';
sUsedUnitsN = '%s used Units';
sUsedUnitsTextN = 'The %s makes use of the following units.\par';
sImplicationsN = '%s implications';
sOverviewN = '%s overview';
sDocumentNameN = '%s document name';
sAssociatedItem = 'Associated Item';
sAssociatedItems = 'Associated Items';
sUnitTestingProtocol = 'Unit Testing Protocol';
sNotImplemented = 'Not implemented';
sRiskEvaluatedFromSub = 'Risk evaluated from sub-items';
sRiskNotEvaluatedNoModif = 'Since there''s no code modification, no Risk has to be evaluated.';
sRiskEvaluationTeam = 'Risk evaluation team';
sDesignInputSplitDefault = 'This Design Input shall be traced to the following %s items';
sQuickReferenceTableNN = 'The following table is a quick-reference guide to '+
'all the software @%s@ items and their corresponding @%s@ items.\par';
sQuickReferenceTableN = 'The following table is a quick-reference guide to '+
'all the @%s@ items.\par';
sQuickReferenceTableN2 = 'The following table is a quick-reference guide to '+
'all the %s referenced in this @%s@.\par';
sImplementation = 'Implementation';
sTestExtractFromNN = 'Test case below is extracted from the "{\i%s "} document, which purpose is to %s';
sSameAsN = 'Same as @%s@';
sItemModifiedUnits = 'This specification is implemented by the following units';
sItemQuotedUnits = ' The {\i Software Design Document} also quoted the following units';
sUnitName = 'Unit Name';
sSeeInParticular = 'See in particular ';
sAnd = 'and';
sDocNameParenthNN = '{\i %s} (%s) document';
sCONFIDENTIAL = 'CONFIDENTIAL';
sSourceReferenceTable = 'Source Reference Table';
sSourceFileNames = 'Source code File Names';
sReferenceTableN = '%s Reference Table';
sOthers = 'Others';
sName = 'Name';
sRelatedDocuments = 'Related Documents';
sPictures = 'Pictures';
sIndex = 'Keywords';
sTableOfContents = 'Table of Contents';
sFoundIn = 'Found in';
const
VALID_PROGRAM_EXT: array[0..13] of string =
('.PAS','.MOD','.C','.CPP','.H','.CS','.NSI', '.DEF', '.CXX', '.INC',
'.XML','.HTML','.HTM', '.DFM');
VALID_PROGRAM_CHAR: array[-1..high(VALID_PROGRAM_EXT)] of string =
('$', '!', 'µ', '&', '&', '&', '#', '$', 'µ', '&', '$', '$$', '$$', '$$', '!$');
FRONTPAGE_OPTIONS: array[0..12] of string =
('ProjectDetails','Warning','PeopleDetails','RevisionDetails','AddPurpose',
'RiskTable','NoHeader','TestDetails','NoConfidential','NoHeaderBorder',
'HeaderWithLogo','FullTitleInTableOfContent','NoProjectDetailsLogo');
var
RISKDEFS: TRiskDef;
procedure InitLang;
// init RISKDEFS[] with proper sRiskDef resourcestring value
type
TSectionDynArray = array of TSection;
PRisk = ^TRisk;
TRisk = object
// 1,1,3,Claude Mench+Arnaud Bouchez,Service SW is safe
Risk: array[0..2] of integer; // (1,1,3)
EvaluatedBy: string; // 'Claude Mench+Arnaud Bouchez'
Comment: string; // 'Service SW is safe'
procedure FromString(const aString: string);
function ToString: string;
procedure SetWorse(aRisk: PRisk);
function EvaluatedByDisplay: string; // 'Claude Mench, Arnaud Bouchez'
end;
PDocument = ^TDocument;
TDocument = object // DI, SRS, SDD, SAD, Test... (has Revision=..)
Params,
Order: TSection;
Owner: TSection; // from Owner=...
// ex: DI->DI, SRS->DI, SDD->SRS, SAD->SRS, Test->SRS
List: array of TSection; // from Order=...
// ex: DI->DI-4.1,DI-4.2... SRS->SRS-DI-4.1,SRS-MENU01...
TestDoc: PDocument; // [Test].BodyIsTest=Yes -> [Tests] DocByDescription=Test
function GetParentIndex(Index: integer): integer;
function GetPropertyFromParent(Index: integer; const aName: string;
const aDefault: string = ''): string;
function GetSectionIndex(aSection: TSection): integer; overload;
function GetSectionIndex(const aSectionName: string): integer; overload;
function GetSectionNameValueIndex(const aSectionNameValue: string): integer;
function GetSection(const aSectionName: string): TSection;
end;
TProject = class
// Document vars:
public
People,
Project,
Pictures,
DILayout: TSection;
Document: array of TDocument; // DI, SRS, SDD, SAD, Test... (has Owner=..)
DI: PDocument; // points to TDocument for 'DI'
Parse: array of TSection; // [SAD]:Source=EIA,IFA2 -> [SAD-EIA],[SAD-IFA2]
ParseSAD: PDocument; // [SAD]
ParseSDD: PDocument; // [SDD] section to be parsed for modified files as @!EIA\bidule.pas@
ParseTest: PDocument; // [Test] section as DocByDescription=Test was called
FileName, // 'D:\Dev\Synopse\Documents\Product New Version\Product New Version.pro'
FileNameDir, // 'D:\Dev\Synopse\Documents\Product New Version\'
DestinationDir: string; // 'D:\Documents\Product New Version\'
OldWord2k: boolean; // OldWord2k := isTrue(Project['OldWordOpen'])
// functions to search in Document[]:
function DocumentIndex(aSection: TSection): integer; overload;
function DocumentIndex(const aSectionName: string): integer; overload;
function DocumentFind(aSection: TSection): PDocument; overload;
function DocumentFind(const aSectionName: string): PDocument; overload;
procedure DocumentAddSection(Doc: PDocument; aSection: TSection);
private
FData: TSectionsStorage;
// used for document generation { TODO : sub class it? }:
public
Doc: PDocument; // current Document generated
WRClass: TProjectWriterClass;
WR: TProjectWriter;
CreatedDocuments: string; // comma separated list of .doc/.rtf filenames
PageTableHeader: string;
DestroyOpensCreatedDocuments: boolean; // if true -> Destroy will launch docs
private
Header: record
visible: boolean;
withborder: boolean;
withlogo: boolean;
confidential: boolean;
ProjectName,
DocumentTitle,
HeaderName,
HeaderFunction,
Rev,
RevDate: string;
LastFooterTitle: string;
ColWidth: array[0..3] of integer;
end;
Layout: TProjectLayout;
ForcedOnlySection: TSection; // for CreateRTFDetails() -> ignore all other
TitleBookmark: TStringList;
fGraphValues: TSection;
SideBar: TProjectWriter;
ApiFolder: string;
{$ifdef USEPARSER}
SAD: array of TObject; // TProjectBrowser for [SAD-Parse].SourceFile= details
{$endif}
SADUnitNames: TStringList;
// cross-references:
ReferencePictures, // Picture Caption=Bookmark0,Bookmark1...
ReferenceIndex, // KeyWord 1=bookmark0,bookmark1...
ReferenceProgram: TSection; // something.pas=Bookmark0,Bookmark1...
ReferenceImplements: TSection; // IEC 5.7 blabla=Bookmark0,Bookmark1...
ReferencePicturesIndex,
ReferenceProgramIndex,
ReferenceImplementsIndex,
ReferenceIndexIndex: integer;
ReferenceDocuments: TList; // mapped to TSection
ReferenceTablesPos, // used to write DocumentIndex=... tables after parsing
ReferenceDocumentsPos: integer;
ReferenceTablesTitleLevel: TTitleLevel;
procedure TestGetDescr(Test, DIDetails: TSection; TestDoc: PDocument; out docname, title: string);
procedure HeaderOnly;
procedure HeaderAndFooter;
procedure Footer(WR: TProjectWriter; const FooterTitle: string);
procedure AddReferenceDocument(aSec: TSection);
function PictureCaption(var FileName: string; Coords: PString=nil;
aGraphValues: TSection=nil): string;
function GetSourceOutputFileName(const ButtonFileName: string;
mustExists: boolean): string; // 'IFA\Main.pas' -> 'IFA2\Main.pas'
procedure SetData(aData: TSectionsStorage);
public
constructor Create(aClass: TProjectWriterClass; const aFileName: string = ''); reintroduce;
destructor Destroy; override;
procedure SaveToFile(const aFileName: string);
procedure CreateRTF(ProjectDetails, Warning, PeopleDetails, RevisionDetails,
AddPurpose, RiskTable, TestDetails, NoProjectDetailsLogo: boolean;
Landscape: boolean; RevSection: TSection = nil;
aDocumentTitle: string = ''; aRev: string = ''; aHeaderName: string = '';
aPurpose: string = '');
procedure CloseRtf(aFormat: TSaveFormat=fDoc);
procedure ForceLandscape;
procedure ForceFooter(const FooterTitle: string; forcePortrait: boolean = false);
procedure InitPageSize;
procedure CreateRTFBody(aSection: TSection; aTitleOffset: integer = 0;
withNumbers: boolean = true; FirstTitleBookMark: boolean = false; isTest: boolean = false);
procedure CreateRTFTable(const TableKind: string);
procedure CreateRTFDetails(Level: integer; AutoFooter: boolean);
procedure CreateDefaultDocument(const SectionName: string;
SubSection: TSection = nil; TestSummarySheet: boolean = false;
SaveFormat: TSaveFormat=fDoc);
procedure CreateSectionDocument(const SectionName: string);
procedure CreateTestDocument(const SectionName: string);
procedure CreateSummarySheets(Tests: TSection); // manually add all Test Summary Sheets
procedure CreateRiskAssessmentTable;
function ExpandDocumentNames(text: string): string; // '@DI@' -> ...
procedure HtmlWriteWithLinks(Sender: THTML; P: PAnsiChar; PLen: Integer;
PIsCode: boolean; W: PStringWriter);
// 'DI-4.2.1' -> 'Design Input 4.2.1 (SCR#23)':
function GetDIDisplayName(aDI: TSection): string;
function GetPeopleFunction(const PeopleName: string; const Default: string = ''): string;
function GetPeopleFunctionDescription(const PeopleName: string; const Default: string = ''): string;
procedure WriteRiskDescription;
{$ifdef USEPARSER}
procedure UpdateSADFileFromSource(RecreateAll: boolean);
procedure CreateExternalSAE;
{$endif}
{$ifdef WITH_GRAPHVIZ}
procedure UpdateSADGraphViz(const Ext: string; OnlyGraphs: boolean);
{$endif}
procedure NeedGraphValues;
function PercFromTitle(var GraphTitle: string; const UniqueImageName: string): integer;
function PictureFullLine(const Line: string; out Caption,Bookmark: string;
aGraphValues: TSection=nil; doNotReference: Boolean=false): string;
procedure PictureAdd(const Line: string; aGraphValues: TSection=nil;
aWR: TProjectWriter=nil);
function PictureInlined(const ButtonPicture: string; Percent: integer;
WriteBinary: boolean): AnsiString;
class function GetProgramSection(const Button: string): string; // 'EIA\one.pas' -> 'SAD-EIA'
class function GetProgramName(const Button: string): string; // 'EIA\one.pas' -> 'one.pas'
property Data: TSectionsStorage read FData write SetData;
property GraphValues: TSection read fGraphValues;
end;
implementation
uses
ShellApi,
{$ifdef WITH_GRAPHVIZ}
Variants,
{$endif}
{$ifdef USEPARSER}
ProjectParser,
PasDoc_Items,
PasDoc_Types,
SynZipFiles,
{$endif}
ProjectDiff; // for TMemoryMap
{ TProject }
constructor TProject.Create(aClass: TProjectWriterClass; const aFileName: string);
begin
WRClass := aClass;
InitPageSize; // A4 default paper size
if not FileExists(aFileName) then
exit;
// Init Data + various TSection
Data := TSectionsStorage.Create(aFileName); // SetData() will init all TSection
SADUnitNames := TStringList.Create;
SADUnitNames.Sorted := true;
end;
procedure TProject.SetData(aData: TSectionsStorage);
// Init various TSection from Data
procedure Adjust(var Doc: TDocument; const Prop: string);
var i: integer;
Default: string;
begin
Default := Doc.Params['Default'+Prop];
if Default='' then exit;
for i := 0 to length(Doc.List)-1 do
if Doc.List[i][Prop]='' then
Doc.List[i][Prop] := Default;
end;
var i, j, k, n, nsub: integer;
OwnerName, OrderName, s,
DocName, procname, Ext, SubName, procCSV: string;
Sec, Sub, LastOwner, SadSDD: TSection;
D: PDocument;
P: PChar;
MinLevel: integer;
modif: boolean;
begin
if Data<>nil then
exit; // must be called only once
// 1. init cache to common Sections
FData := aData;
ReferencePictures := Data.GetOrCreateSection('ReferencePictures',true);
ReferencePictures.Clear;
ReferenceProgram := Data.GetOrCreateSection('ReferenceProgram',true);
ReferenceProgram.Clear;
ReferenceImplements := Data.GetOrCreateSection('ReferenceImplements',true);
ReferenceImplements.Clear;
ReferenceDocuments := TList.Create;
ReferenceIndex := Data.GetOrCreateSection('ReferenceIndex',true);
ReferenceIndex.Clear;
TitleBookmark := TStringList.Create;
People := Data.GetOrCreateSection('People', true);
Project := Data.GetOrCreateSection('Project', true);
Pictures := Data.GetOrCreateSection('Pictures', true);
Header.ProjectName := Project['Name'];
OldWord2k := isTrue(Project['OldWordOpen']);
// 2. get documents -> Document[]
SetLength(Document,Data.Sections.Count); // max possible length
n := 0;
for i := 0 to Data.Sections.Count-1 do begin
Sec := Data.Sections[i];
if Sec.SectionName<>Sec.SectionNameValue then // name must be 'DI','SRS'..
continue; // not a true document
OwnerName := Sec['Owner'];
Sec.Owner := Data[OwnerName];
if Sec.Owner=nil then // document must have a valid Owner= param
continue; // not a true document
D := @Document[n];
D.Params := Sec;
D.Owner := Sec.Owner;
OrderName := Sec['Order'];
D.Order := Data[OrderName];
SetLength(D.List,Data.Sections.Count); // max possible length
nsub := 0;
LastOwner := nil;
if OrderName='' then begin // no Order= specified => unique Document
D.List[0] := Sec;
nsub := 1;
end else
if OrderName=Sec.SectionName then
// self order (may have sub items)
for j := 0 to Data.Sections.Count-1 do begin
Sub := Data.Sections[j]; // extract the list directly from [Sec-*]
if (Sub.SectionNameKind=Sec.SectionName) and (Sub<>Sec) then begin
if D.Owner<>D.Params then begin // if not DI -> set Owner
Sub.Owner := Data[Sub.SectionNameValue]; // SRS-DI-4.1 -> DI-4.1
if Sub.Owner=nil then begin // SRS-MENU01->DI-4.1
Sub.Owner := Data[Sub['Parent']];
if Sub.Owner=nil then // no Parent
if LastOwner=nil then // lastParent=nil -> [SRS-Service Software] -> not in List[]
continue else
Sub.Owner := LastOwner else // no Parent= -> use last DI
LastOwner := Sub.Owner; // Parent=DI-4.2 -> force this DI
end else
LastOwner := Sub.Owner; // SRS-DI-4.8->DI-4.8
end; // leave Sub.Owner=nil
D.List[nsub] := Sub;
inc(nsub);
end;
end else
// not self ordered -> search by Order List[] values
for j := 0 to n-1 do
with Document[j] do
if Params.SectionName=OrderName then // SRS for SDD, DI for SRS (if no subitem)
for k := 0 to length(List)-1 do begin // get every [Sec-Order*]
Sub := Data.Section[Sec.SectionName+'-'+List[k].SectionNameValueWithDI];
if Sub=nil then continue;
Sub.Owner := List[k]; // SDD-MENU-01.Owner = SRS-MENU-01
D.List[nsub] := Sub;
inc(nsub);
end;
Setlength(D.List,nsub); // adjust List[] count
inc(n); // good document -> store it
end;
SetLength(Document,n); // adjust documents count
// 3. adjust DI params
DI := DocumentFind(Project.ReadString('MainSection','DI'));
if DI<>nil then begin
// raise Exception.Create('At least a [DI] section is necessary');
DILayout := Data.GetOrCreateSection(DI.Params.SectionName+'Layout', true);
MinLevel := maxInt;
for i := 0 to high(DI.List) do
with DI.List[i] do begin
for j := 1 to length(SectionNameValue) do
if SectionNameValue[j]='.' then
inc(Level);
if Level<MinLevel then
MinLevel := Level;
if Value['InputLevel']='' then
Value['InputLevel'] := 'Must Have';
if Value['Request']='' then // get Request from parent
Value['Request'] := DI.GetPropertyFromParent(i,'Request');
end;
if MinLevel<>1 then // case some DI number with no '.' inside
for i := 0 to high(DI.List) do
inc(DI.List[i].Level,1-MinLevel); // -> force level start with 1
// 4. adjust default parameters
for i := 0 to high(Document) do
Adjust(Document[i],'PreparedBy');
// 5. special SAD-like documents:
for i := 0 to high(Document) do
with Document[i] do
if Params['Source']<>'' then begin
// [SAD]:Source=EIA,IFA2,Firmware -> [SAD-EIA],[SAD-IFA2],[SAD-Firmware]
// [SAD-EIA] will get files from @EIA\name.pas@
n := length(Parse);
SetLength(Parse,n+Data.Sections.Count); // max possible length
P := pointer(Params['Source']);
if ParseSAD=nil then // first Source=.. document is the project main SAD
ParseSAD := @Document[i];
repeat
s := GetNextItem(P); // 'EIA'
if s<>'' then begin
Parse[n] := Data[Params.SectionName+'-'+s];
if Parse[n]<>nil then
inc(n);
end;
until P=nil;
SetLength(Parse,n);
if n>0 then begin
D := DocumentFind(Params['SourceSDD']);
if D<>nil then begin
ParseSDD := D; // [SDD] section to be parsed for modified files as @!EIA\bidule.pas@
for j := 0 to high(ParseSDD.List) do begin // read body
Data.ReadOpen(ParseSDD.List[j].SectionName,false);
SubName := Params.SectionName+'-'+ParseSDD.List[j].SectionNameValue;
while not Data.ReadEof do begin
s := Data.ReadLine;
if s='' then continue;
repeat
// find @something.pas@
k := pos('@',s);
if k=0 then
break; // no valid @..
if s[k+1]='@' then
break; // ignore line with @@
if (k>1) and (NormToUpper[s[k-1]] in ['A'..'Z','0'..'9']) then begin
delete(s,1,k); // bidule@mlds -> email adress -> ignore
continue;
end;
delete(s,1,k);
k := pos('@',s);
if k=0 then
break; // no valid ..@
DocName := copy(s,1,k-1);
delete(s,1,k);
Ext := ExtractFileExt(DocName);
if GetStringIndex(VALID_PROGRAM_EXT, Ext)<0 then
continue;
if Data.Section[DocName]<>nil then
continue; // this is @SDD-DI-6.3.2.6.C@ -> ignore
// valid @something.pas@ -> add to [SAD-*] Section
modif := DocName[1]='!';
procname := '';
if modif then begin
delete(DocName,1,1);
k := pos('!',DocName);
if k>0 then begin // '@!procname!EIA\unit.pas@
procname := copy(DocName,1,k-1); // get procname
delete(DocName,1,k); // trim procname
end;
end;
// real filename ('IFA\Main.pas'->'IFA2\Main.pas')
DocName := GetSourceOutputFileName(DocName,true); // mustExists=true
if DocName='' then
continue; // file must exists to be indexed
// update [SAD] and [SAD-DI-4.5]: UnitsUsed=.. + UnitsModified=..
Params.AddCSVValue('UnitsUsed',DocName,true);
Data.AddCSVValue(SubName,'UnitsUsed',DocName,true);
if ParseSAD.GetSectionIndex(SubName)<0 then // add [SAD-DI-4.5] to ParseSAD if necessary
DocumentAddSection(ParseSAD,Data[SubName]);
if modif then begin
Params.AddCSVValue('UnitsModified',DocName,true);
Data.AddCSVValue(SubName,'UnitsModified',DocName,true);
if procname<>'' then begin // [SAD-DI-4.5].unit.pas=TClass.Funct,globalproc
DocName := ExtractFileName(DocName);
P := pointer(procName);
repeat
// allow adding multi procs at once: @!WriteLCD,Warning!Firmware\Main\Hardware.pas@
procCSV := GetNextItemTrimed(P);
Data.AddCSVValue(SubName,DocName,procCSV,true);
// unit.pasexact=.. TClass.Funct only (not TClass)
Data.AddCSVValue(SubName,DocName+'exact',procCSV,true);
k := pos('.',procCSV);
if k>0 then // highlight also 'TClass' in 'TClass.Funct'
Data.AddCSVValue(SubName,DocName,copy(procCSV,1,k-1),true);
until P=nil;
end;
end;
until false;
end; // while not Data.ReadEof
end;
end;
end;
end;
// 5. special Test-like documents:
for i := 0 to high(Document) do
with Document[i] do // Document[i] = [Tests]
if Params['DocByDescription']<>'' then begin
// [Test].BodyIsTest=Yes -> Test.TestDoc=[Tests] where DocByDescription=Test
D := DocumentFind(Params['DocByDescription']); // D = [Test]
if (D<>nil) and isTrue(D.Params['BodyIsTest']) then begin
D.TestDoc := @Document[i]; // .TestDoc=[Tests] where DocByDescription=Test
if ParseTest=nil then
ParseTest := D; // [Test], as DocByDescription=Test was called
end;
end;
end; // if DI<>nil
// 6. Project DestinationDir init as default directory
FileName := Data.FileName; // 'D:\Dev\Synopse\Documents\Product New Version\Product New Version.pro'
FileNameDir := ExtractFilePath(FileName); // 'D:\Dev\Synopse\Documents\Product New Version\'
DestinationDir := Project['DestinationDir'];
if DestinationDir='' then
DestinationDir := GetCurrentDir else begin
if DestinationDir='.' then
DestinationDir := FileNameDir else
if DestinationDir='.exe' then
DestinationDir := ExtractFilePath(paramstr(0)) else
if DestinationDir='.docs' then
DestinationDir := GetMyDocuments else
if DestinationDir='.data' then
DestinationDir := GetAppDataPath;
if not DirectoryExists(DestinationDir) then begin
CreateDir(DestinationDir);
if not DirectoryExists(DestinationDir) then
DestinationDir := GetMyDocuments;
end;
end;
DestinationDir := IncludeTrailingPathDelimiter(IncludeTrailingPathDelimiter(
DestinationDir)+Project['Name']);
if not DirectoryExists(DestinationDir) then // 'D:\Documents\Product New Version\'
if not CreateDir(DestinationDir) then
DestinationDir := IncludeTrailingPathDelimiter(GetMyDocuments);
end;
destructor TProject.Destroy;
procedure OpenDocuments;
var P: PChar;
doc: string;
begin
P := pointer(CreatedDocuments);
if P=nil then exit;
if DestroyOpensCreatedDocuments then
repeat
doc := GetNextItem(P);
if doc='' then break;
if FileExists(doc) and (DebugHook=0) then
ShellExecute(0,nil,pChar(doc),nil,nil,SW_SHOWMAXIMIZED);
until false;
end;
begin
Data.Free;
ReferenceDocuments.Free;
TitleBookmark.Free;
OpenDocuments;
SADUnitNames.Free;
inherited;
end;
procedure TProject.SaveToFile(const aFileName: string);
var W: TStringWriter;
begin
Data.SaveText(W);
W.SaveToFile(aFileName);
end;
function GetCommit(const fn: TFileName): AnsiString;
begin
result := Trim(StringFromFile(fn));
if (result <> '') and (result[1] = '''') then
result := copy(result, 2, length(result) - 2);
end;
procedure TProject.CreateRTF(ProjectDetails, Warning, PeopleDetails,
RevisionDetails, AddPurpose, RiskTable, TestDetails, NoProjectDetailsLogo: boolean;
Landscape: boolean; RevSection: TSection = nil;
aDocumentTitle: string = ''; aRev: string = ''; aHeaderName: string = '';
aPurpose: string = '');
procedure Details(Title,Name: string);
var P: PChar;
begin
P := pointer(Doc.Params[Name]);
if P=nil then exit; // PreparedBy='' -> no table to add
WR.RtfPar;
WR.RtfColsPercent([30,30,20,20],true,true,false,'\trkeep');
WR.RtfRow(['\b '+Title+':',sTitle+':',sSignature+':',sDate+'\b0 ']);
repeat
Name := GetNextItem(P);
if Name='' then break;
WR.RtfRow([Name,GetPeopleFunction(Name),'','']);
until false;
WR.RtfColsEnd;
end;
var Name, Value, Logo, PreparedBy, Purpose, ColW, ProjMan, Rev: string;
RevTableCount: integer;
RevTable: array[0..3] of string;
ValueKind: integer;
P: PAnsiChar;
procedure AddRevisionEntry;
// RevTable[] must have been set appropriatly
begin
inc(RevTableCount);
if RevTableCount<>1 then begin
if RevisionDetails then begin
RevisionDetails := false;
if not TestDetails then
WR.RtfPage;
WR.RtfPar.RtfBig(sDocumentRevisionTable);
WR.RtfColsPercent([10,28,24,38],true,true);
WR.RtfRow(['\b '+sRev,sDate,sAuthor,sDescription+' \b0']);
WR.RtfRow([' '+Header.Rev,Header.RevDate,PreparedBy,
RevSection['RevisionDescription']]);
end;
RevTable[0] := ' '+RevTable[0];
WR.RtfRow(RevTable);
end;
RevTable[0] := ''; // mark written
end;
begin
// 1. RTF header
// 1.1 Init
ReferenceTablesPos := 0; // used to write DocumentIndex=... tables after parsing
ReferenceDocumentsPos := 0;
WR := WRClass.Create(Layout,11,1252,
Project.ReadInteger('DefLang',1033),Landscape,true,isTrue(Doc.Params['TitleFlat']));
WR.PicturePath := FileNameDir; // 'D:\Dev\Synopse\Documents\Product New Version\'
WR.DestPath := DestinationDir;
SideBar := WR.Clone;
if WR.HandlePages then
PageTableHeader := '\qc '+sPage+'\b0' else
if WRClass=THTML then begin
SideBar.AddRtfContent(SIDEBAR_HEADER).RtfText;
P := pointer(Project['HtmlSideBar']);
repeat
Name := GetNextItem(P,'/');
Purpose := GetNextItem(P,':');
Value := GetNextItem(P,',');
if (Name='') or (Value='') then
break;
Name := '{\b '+Name+'}';
if IdemPChar(Pointer(Value),'HTTP') and
((Value[5]=':') or ((Value[5]='s')and(Value[6]=':'))) then
SideBar.AddRtfContent(SideBar.RtfHyperlinkString(Value,Name)) else
SideBar.RtfLinkTo(Value,Name);
SideBar.AddRtfContent(#1'<br><small>'#1+Purpose+#1'</small>'#1).RtfPar;
until P=nil;
(WR as THTML).OnBufferWrite := HtmlWriteWithLinks;
end;
// 1.2 Header and Footer
if aDocumentTitle='' then
Header.DocumentTitle := Doc.Params['Name'] else
Header.DocumentTitle := aDocumentTitle;
ProjMan := Project['Manager'];
if aHeaderName='' then begin
Header.HeaderName := Project['Writer'];
if Header.HeaderName='' then begin
Header.HeaderName := ProjMan;
Header.HeaderFunction := GetPeopleFunction(ProjMan,'Project Manager');
end else
Header.HeaderFunction := sWrittenBy;
ColW := Project['HeaderColWidth'];
P := pointer(ColW);
if (P=nil) or not TryStrToInt(GetNextItem(P),Header.ColWidth[0]) or
not TryStrToInt(GetNextItem(P),Header.ColWidth[1]) or
not TryStrToInt(GetNextItem(P),Header.ColWidth[2]) or
not TryStrToInt(GetNextItem(P),Header.ColWidth[3]) then begin
Header.ColWidth[0] := 22;
Header.ColWidth[1] := 48;
Header.ColWidth[2] := 15;
Header.ColWidth[3] := 15;
end;
end else begin
Header.HeaderName := aHeaderName;
Header.HeaderFunction := sWrittenBy;
Header.ColWidth[0] := 22;
Header.ColWidth[1] := 38; // smaller width for DocumentTitle
Header.ColWidth[2] := 15;
Header.ColWidth[3] := 25; // bigger width for HeaderName
end;
if RevSection=nil then
RevSection := Doc.Params;
ApiFolder := 'api';
if aRev='' then
begin
Rev := RevSection['Revision'];
if (PosEx('.inc', Rev) <> 0) and
(RevSection['DefaultPath'] <> '') then
Rev := GetCommit(IncludeTrailingPathDelimiter(RevSection['DefaultPath']) + Rev);
if Rev = '' then
Header.Rev := RevSection['Revision'] else
Header.Rev := Rev;
end
else
Header.Rev := aRev;
Header.RevDate := RevSection.RevisionDate;
HeaderAndFooter;
// 1.3 Document Properties
PreparedBy := ValAt(Doc.Params['PreparedBy'],0);
if aPurpose='' then
Purpose := Doc.Params['Purpose'] else
Purpose := aPurpose;
WR.SetInfo(Header.DocumentTitle+' '+Header.Rev,PreparedBy,
Header.ProjectName+': '+Purpose,
Project.ReadString('Manager',Header.HeaderName),Project['Company']);
// 1.4 End rtf header
WR.InitClose;
// 2. First page
if ProjectDetails then begin
Logo := Project['Logo'];
if (Logo<>'') and (Pictures[Logo]<>'') and not NoProjectDetailsLogo then begin
Logo := Logo+' '+ValAt(Pictures[Logo],0);
WR.RtfImage(Logo,'',true,'\ql').AddRtfContent('\line'#13#10);
end;
WR.AddRtfContent('{\b\cf9 '+sProjectDocumentation);
if not Header.Visible then // no header -> write Company name in ProjectDetails
WR.AddRtfContent(' - '+Project['Company']);
WR.AddRtfContent('\par}');
WR.RtfColsPercent([30,70],true,true);
WR.RtfRow([sProjectName+':','{\b '+Header.ProjectName+'}']);
WR.RtfRow([sDocumentName+':','{\b '+Header.DocumentTitle+'}']);
WR.RtfRow([sDocumentRevision+':','{\b '+Header.Rev+'}']);
WR.RtfRow([sDate+':','{\b '+Header.RevDate+'}']);
if ProjMan='' then
WR.RtfRow([Header.HeaderFunction+':','{\b '+Header.HeaderName+'}'],true) else
WR.RtfRow([GetPeopleFunction(ProjMan,'Project Manager')+':','{\b '+ProjMan+'}'],true);
WR.RtfPar;
end;
if TestDetails then begin
WR.AddRtfContent('{\b\cf9 '+sTestProcedure+'\par}');
WR.RtfColsPercent([30,70],true,true);
WR.RtfRow([sProjectName+':','{\b '+Header.ProjectName+'}']);
WR.RtfRow([sProtocolName+':','{\b '+Header.DocumentTitle+'}']);
WR.RtfRow([sProtocolDescription+':','{\b '+TrimLastPeriod(Purpose)+'}']);
WR.RtfRow([sProtocolRevision+':','{\b '+Header.Rev+'}']);
WR.RtfRow([sProtocolDate+':','{\b '+Header.RevDate+'}']);
WR.RtfRow([sPreparedBy+':','{\b '+PreparedBy+'}'],true);
WR.RtfPar;
WR.RtfColsPercent([30,70],true,true);
WR.RtfRow([sTestedBy+':','']);
WR.RtfRow([sTestDate+':',''],true);
end;
if Warning then
CreateRTFBody(Project); // get WARNING message from [Project] body
if PeopleDetails then begin
Details(sPreparedBy,'PreparedBy');
Details(sReviewedBy,'ReviewedBy');
Details(sApprovedBy,'ApprovedBy');
end;
if RevisionDetails then begin
RevTableCount := 0;
Data.ReadOpen(RevSection.SectionName,true);
while Data.ReadNextNameValue(Name,Value) do begin
ValueKind := GetStringIndex(
['Revision','RevisionDate','PreparedBy','RevisionDescription'],Name);
if ValueKind<0 then continue;
if (ValueKind=0) and (RevTable[0]<>'') then // Revision=... ?
AddRevisionEntry; // mark previous revision if any
RevTable[ValueKind] := Value;
end;
if RevTable[0]<>'' then
AddRevisionEntry; // will only make the table revision if more than one revision
WR.RtfColsEnd;
end else // force RtfPage if something written
RevisionDetails := ProjectDetails or Warning or PeopleDetails or RevisionDetails;
if AddPurpose then begin
if Purpose<>'' then begin
if RevisionDetails then begin
RevisionDetails := false; // new page now if not already done
if not TestDetails then
WR.RtfPage;
end;
WR.RtfPar.RtfBig(sDocumentPurpose).
AddRtfContent(sDocumentPurposeSentence,[Header.DocumentTitle,
TrimLastPeriod(Purpose,true),Header.ProjectName,Header.Rev]).
AddRtfContent(#13#10);
end;
WR.RtfText; // close any pending {
ReferenceDocumentsPos := WR.len;
if RiskTable then
WriteRiskDescription;
end;
if RevisionDetails and not TestDetails and AddPurpose then
WR.RtfPage; // change page if not already done
// 3. set FileName
if aDocumentTitle='' then begin
aDocumentTitle := Doc.Params.DocName;
WR.FileName := RevSection['FileName'];
if WR.FileName = '' then
WR.FileName := Project.ReadString('DocName',Header.ProjectName)+' '+
aDocumentTitle+' '+Header.Rev;
end else
WR.FileName := Header.DocumentTitle;
WR.FileName := WR.FileName+'.rtf';
if DestinationDir<>'' then // <>'' -> 'D:\Documents\Product New Version\'
WR.FileName := DestinationDir+WR.FileName;
end;
procedure TProject.WriteRiskDescription;
var i: integer;
HighMedLow: string;
P: PChar;
begin
WR.RtfPar.RtfBig(sRiskAssessmentScale);
HighMedLow := sHighMedLow;
for i := 0 to 2 do
with RiskDefs[i] do begin
WR.AddRtfContent('{\b\cf9 '+Name+'}: '+Description+'\par');
WR.RtfColsPercent([15,85],true,true,false,'\trkeep');
P := pointer(HighMedLow);
WR.RtfRow(['\qc 3 - '+GetNextItem(P),'\qj '+Level[3]]);
WR.RtfRow(['\qc 2 - '+GetNextItem(P),'\qj '+Level[2]]);
WR.RtfRow(['\qc 1 - '+GetNextItem(P),'\qj '+Level[1]],true);
end;
end;
procedure TProject.CreateRTFBody(aSection: TSection;
aTitleOffset: integer = 0; withNumbers: boolean = true; FirstTitleBookMark: boolean = false;
isTest: boolean = false);
(* special lines begin with
: for titles (no Name=Value pairs after a :title)
- for a list item
! for pascal source
!! for modified pascal source line
& for c c++ source
&! for modified c c++ source line
# for c# source
#! for modified c# source line
$ for text file (fixed-width font)
$! for modified text file line (fixed-width font)
%filename.jpg [640x480 85%] for images jpg/bmp/png/emf - see [Pictures]
|=-%30%40%30 then |Col 1|Col 2|Col 3 then |% for columns
(=:no indent -:no border)
=[SectionName] to inline the [SectionName] content at this place
text can be formated as rtf (with \b \i { } e.g.) - each new text paragraph
will be ended with \par
{} can be used for a \par alone (void lines are just ignored)
you can link to another item with @SectionName@ (@DI-4.1@ e.g) or @DocName@ (@SRS@)
in the [SDD-*] sections, specify @Module\filename.pas@ for each file name,
@!Module\filename.pas@ for filename modified or
@!procedurename,classname,class.methodname!Module\filename.pas@ in order to
specify the procedure name.
The corresponding units (and procedures) will be highlited in the [SAD] document.
some special lines commands can be entered:
\page to force a new page
\landscape to change the page orientation to landscape
\portrait to change the page orientation to portrait
\footer blabla to change the footer text
\Layout to add a list with all DILayout titles
\LayoutPage idem + associated pages in the document
\Refers to add a list with all Refers= titles
\RefersPage idem + associated pages in the document
\risk to add the Risk Assessment Scale table
\Source (for [SAD] section) to add the list of the Source=.. modules
\SourcePage idem + associated pages in the document
\graph UniqueImageName [Title] then following lines either .dot normal text,
either "\From Text\To Text[\Label between both]"
\include filename.ext ext will be used to append !&#$ left
=[SectionName] to include this section content at the current place
\Implements ISO 5.1 [blabla][\DocumentName] will be processed by \TableImplements=ISO
\TableSoftwareChanges or \TableTraceabilityMatrix for SCRS
\TableNewFeatures or \TableBugFixes or \TableTests[=October 16, 2008] for Release Notes
\TableDI=6.3.1.2,6.3.1.3 for a table with all the supplied Design Inputs
\TableDocuments[=DI,SRS,SDD,SAD] for a table with the supplied document details
in the [Test-*] sections, special auto-defined columns can be used with
|Actions[|Expected Results]
manual tables can be used as usual (with |%..)
*)
var s, line, caption, UniqueImageName, BookMarkName, IEC, BookMarks: string;
i, j, BookMark: integer;
withPage: boolean;
ColType: (noCol, testCol, manualCol);
TestNumber: integer;
Sec: TSection;
RefDoc: PDocument;
PC: PChar;
procedure WRtestCol;
var P: PChar;
n, i: integer;
Colss: TStringDynArray;
begin
SetLength(Colss,20);
Colss[0] := '\qc '+IntToStr(TestNumber);
inc(TestNumber);