⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udiagramcreator.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 5 页
字号:



{Extracts the first part up to the first "." of a string.
~param What in: the string to extract the first part from;
            out: the remnant of the string
~result the first part up to the first ".", or all of it }
function ExtractFirstPart(var What: String): String;
var      i               :Integer;   //index of the point
begin
 i := Pos('.', What);                //get the index of the point
 if i = 0 then                       //no point in the string?
  begin
   Result := What;                     //return the whole string
   What := '';                         //no remnant
  end
 else
  begin
   Result := Copy(What, 1, i - 1);     //return the part before it
   Delete(What, 1, i);                 //everythingbehind it remains
  end;
end;

{Extracts the name at the beginning of a string.
~param Part in: the string to extract the first name from;
            out: the remnant of the string without the name
~result the first name }
function ExtractName(var Part: String): String;
var      i          :Integer;       //counter through the string
begin
 Result := Part;
 i := 1;                            //run through the name
 while (i < Length(Result)) and (Result[i] in IdentifierChars) do
  Inc(i);
 if i < Length(Result) then         //there is something after the name?
  begin
   Delete(Part, 1, i - 1);                  //remove the name
   Delete(Result, i, High(Length(Result))); //just return the name
  end
 else
  Part := '';                               //nothing remains
end;


{Adds an object to the list if it is not already in it.
~param List the list to add to
~param What the object to add to the list }
procedure Add(List: TList; What: TObject);
begin
 Assert(Assigned(What));
 if List.IndexOf(What) = -1 then     //the object is not already in the list?
  List.Add(What);                      //add it to the list
end;



{Gets a set of kinds of record-like types from a string.
~param Filter    the text describing kinds of record-like types
~param FilterSet the set of kinds of record-like types
~result whether the set could be validly extracted from the string }
function GetRecordLikeTypeSet(const Filter: String;
                              var FilterSet: TRecordKinds): Boolean;
var      Desc        :TOptionDescription; //a description of an option
         Value       :TOptionValue;       //value of the option
begin
 ClearDescription(Desc);                  //clear structure
 Desc.DataType := otSet;                  //set it to a set of kinds of
 Desc.SetNames := OptionItemsFilterClassesByKind; //record-like types

 Result := StringToValue(Filter, Value, Desc);    //try to read set
 if Result then                           //valid set?
  OptionToSet(Value.SetData, FilterSet, SizeOf(FilterSet)) //return it
 else
  FilterSet := [];                                         //return empty set
end;














                                                                       




    //list for the option "ExportImageType" of the generator
    //~[link TDiagramCreator]
var OptionItemsExportImageType: TStringList = nil;



   { * * *  ***  * * *  ***   TDiagramCreator   ***  * * *  ***  * * *  }




     //all possible options for the generator of diagrams,
     //~[link TDiagramCreator]
     //~see DiagramOptionNames sorted after those names
type TDiagramOption = (
       doAssociations,   //show associations of classes?
       doClass,          //use a digrams of classes instead of files
       doFile,           //use a digrams of files instead of classes
       doFont,           //name of the font to use
       //show the usage of units in the implementation part of other units
       doImplementation,
       doLayout,         //what layout to use for the diagram
       doMargin,         //margin of the diagram
       doMemberKinds,    //what kinds of members to show in classes
       doParameter,      //show parameter of methods
       doResult,         //show type of result of methods
       doScopes,         //show only members with that scope
       doShowFile,       //show the file of classes in the head
       //show record-like types in implementation part of units
       doShowPrivate,
       doSize,           //size(s) of font to use
       doTypes);         //show only record-like types of that kind in files


      //names of the options to use (alphabetically sorted)
const DiagramOptionNames: array[TDiagramOption] of String =
     ('associations', 'class',    'file',        'font',      'implementation',
      'layout',       'margin',   'members',     'parameter', 'result',
      'scopes',       'showfile', 'showprivate', 'size',      'types');







    //the descriptions of messages that can be added in the class
    //~[link TDiagramCreator]
var DiagramCreatorMessageDescriptions: TMessageDescriptions = nil;







{Creates the generator object and initializes the options. }
constructor TDiagramCreator.Create;
begin
 inherited Create;                       //create object

 //register messages of this class
 FDiagramCreatorMessagesID := RegisterMessages(
                                            DiagramCreatorMessageDescriptions);

 FDiagram := TDiagram.Create;            //create object for diagram
 FDiagram.ApplyOptions;                  //initialize with its default options

 FCharacterEncoding := 'UTF-8';          //set default character encoding
end;

{Creates the generator object and initializes the options. }
destructor TDiagramCreator.Destroy;
begin
 FDiagram.Free;                          //free the object of the diagram

 //unregister messages of this class
 UnRegisterMessages(FDiagramCreatorMessagesID);

 inherited Destroy;                      //free the object
end;




{Returns a description of the documentation of the generator.
~result a description of the documentation of the generator }
class function TDiagramCreator.GetDescription: TGeneratorDescription;  
begin
 Result.Name := 'Class or File Diagram';
 Result.Identification := 'Diagram';
 Result.Description := 'Generates diagrams of the classes or files of the parsed data.';
end;






{Returns the number of available options in this class.
~result the number of available options }
class function TDiagramCreator.GetOptionCount: Cardinal;
begin
 Result := inherited GetOptionCount + 9;
end;

{Gets a description of an option.
~param Index index of the option to get data of
~param Desc  out: the description of the option (name, type, default value,
                  etc.)
~see GetOptionCount }
class procedure TDiagramCreator.GetOptionDescription(Index: Cardinal;
                                                 var Desc: TOptionDescription);
var             PreOptionCount   :Cardinal;     //number of inherited options
begin
 PreOptionCount := inherited GetOptionCount;    //get number of inherited ones
 if Index < PreOptionCount then                 //asked for inherited option?
  inherited GetOptionDescription(Index, Desc)     //forward to parent class
 else
  begin
   ClearDescription(Desc);               //clear structure
   case Index - PreOptionCount of        //depending on index of option
     0: begin                            //set the values describing the option
         Desc.Name := 'FileName';
         Desc.Description := 'The name of the file to save the image of the diagram to.';
         Desc.DataType := otString;
        end;
     1: begin
         Desc.Name := 'LinkMapFileName';
         Desc.Description := 'The name of the file to save the link map of the diagram to.';
         Desc.DataType := otString;
        end;
     2: begin
         Desc.Name := 'ExportImageType';
         Desc.Category := 'Diagram';
         Desc.Description := 'Used to select the format of the image the diagram is exported as.';
         Desc.DataType := otEnumeration;
         Desc.EnumNames := OptionItemsExportImageType;
        end;
     3: begin
         Desc.Name := 'CharacterEncoding';
         Desc.Category := 'Diagram.SVG';
         Desc.Description := 'The character encoding of the source code files as it should be used for generated SVG images of diagrams.';
         Desc.DataType := otString;
         Desc.DefaultValue.StrData := 'UTF-8';
        end;
     4: begin
         Desc.Name := 'Option';
         Desc.Category := 'Diagram';
         Desc.Description := 'Can be used to set an option for the diagram.';
         Desc.Options := [ooChangesOtherOptions, ooNoRead];
         Desc.DataType := otString;
        end;
     5: begin
         Desc.Name := 'Add';
         Desc.Category := 'Diagram';
         Desc.Description := 'Adds the file(s) or class(es) to the diagram.';
         Desc.Options := [ooChangesOtherOptions, ooNoRead];
         Desc.DataType := otString;
        end;
     6: begin
         Desc.Name := 'Sub';
         Desc.Category := 'Diagram';
         Desc.Description := 'Removes the file(s) or class(es) from the diagram.';
         Desc.Options := [ooChangesOtherOptions, ooNoRead];
         Desc.DataType := otString;
        end;
     7: begin
         Desc.Name := 'Parameter';
         Desc.Category := 'Diagram';
         Desc.Description := 'Sends a parameter, that will be used to set "Option", "Add" or "Sub".';
         Desc.Options := [ooChangesOtherOptions, ooNoRead];
         Desc.DataType := otString;
        end;
     8: begin
         Desc.Name := 'Parameters';
         Desc.Category := 'Diagram';
         Desc.Description := 'Each parameter will be assigned to "Parameter".';
         Desc.DataType := otString;
        end;
   else
    Assert(Index >= GetOptionCount);
    raise EInvalidOption.Create('Invalid index for option supplied!');
   end;
 end;
end;



{Gets the value of an option. Call ~[link GetOptionDescription] to get the type
 and the meaning of the option.
~param Index index of the option to get the value of
~result the value of the option }
function TDiagramCreator.GetOption(Index: Cardinal): TOptionValue;
var      PreOptionCount  :Cardinal;             //number of inherited options
begin
 PreOptionCount := inherited GetOptionCount;    //get number of inherited ones
 if Index < PreOptionCount then                 //asked for inherited option?
  Result := inherited GetOption(Index)            //forward to parent class
 else
  case Index - PreOptionCount of               //depending on index of option
    0:    Result.StrData := FImageFileName;      //get the value
    1:    Result.StrData := FLinkMapFileName;
    2:    Result.EnumData := Ord(FExportImageType);
    3:    Result.StrData := FCharacterEncoding;
    4..7: Result.StrData := '';                  //write-only options!
    8:    Result.StrData := GetAllOptionsString;
  else
   Assert(Index >= GetOptionCount);
   raise EInvalidOption.Create('Invalid index for option supplied!');
  end;
end;

{Sets the value of an option. Call ~[link GetOptionDescription] to get the type
 and the meaning of the option.
~param Index index of the option to set the value
~param Value the new value of the option }
procedure TDiagramCreator.SetOption(Index: Cardinal;
                                    const Value: TOptionValue);
var       PreOptionCount  :Cardinal;          //number of inherited options
begin
 PreOptionCount := inherited GetOptionCount;  //get number of inherited ones
 if Index < PreOptionCount then               //asked for inherited option?
  inherited SetOption(Index, Value)             //forward to parent class
 else
  case Index - PreOptionCount of                //depending on index of option
    0:    FImageFileName := Value.StrData;       //set the option to the value
    1:    FLinkMapFileName := Value.StrData;
    2:    FExportImageType := TDiagramExportFileType(Value.EnumData);
    3:    FCharacterEncoding := Value.StrData;
    4:    if Value.StrData <> '' then
           DiagramOption(Value.StrData);
    5..6: if Value.StrData <> '' then
           DiagramAddSub(Value.StrData, Index - PreOptionCount = 6);
    7:    DiagramParameter(Value.StrData);
    8:    DiagramParameters(Value.StrData);
  else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -