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

📄 eerdm.pas

📁 功能强大的ER图建模工具的源代码。 可以代替ERWin了
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit EERDM;

//----------------------------------------------------------------------------------------------------------------------
//
// This file is part of fabFORCE DBDesigner4.
// Copyright (C) 2002, 2003 Michael G. Zinner, www.fabFORCE.net
//
// DBDesigner4 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 2 of the License, or
// (at your option) any later version.
//
// DBDesigner4 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with DBDesigner4; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//----------------------------------------------------------------------------------------------------------------------
//
// Unit EERDM.pas
// --------------
// Version 2.1, 03.05.2003, Mike
// Description
//   Contains help functions for the EERModel
//
// Changes:
//   Version 2.1, 03.05.2003, Mike
//     added function CenterModel
//   Version 2.0, 18.04.2003, Mike
//     Changed all Records to TObjects.
//   Version 1.3, 08.04.2003, Mike
//     added DefaultTableType and ActivateRefDefForNewRelation
//   Version 1.2, 04.04.2003, Mike
//     added PositionGrid and TableNameInRefs params as initial defaults
//     for EERModel
//   Version 1.1, 31.03.2003, Mike
//     added AssignNewIDsToEERObjects
//   Version 1.0, 13.03.2003, Mike
//     initial version, Mike
//
//----------------------------------------------------------------------------------------------------------------------

interface

uses
  SysUtils, Classes, QTypes, QForms, Qt, QControls,
  IniFiles, QDialogs, QExtCtrls, QMenus, Types, EERModel;

type
  TDMEER = class(TDataModule)
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);

    procedure SetWorkTool(WorkTool: integer);
    procedure UpdateStatusBar;

    procedure RefreshPalettes;
    procedure RefreshNavPalette;
    procedure RefreshNavImg;
    procedure RefreshInfoPalette;

    procedure SetWorkToolCurser(WorkTool: integer);
    procedure SetCurrentWorkTool(WorkTool: integer);

    //Get the Texts from a ini File
    procedure LoadWorkToolLabelTextsFromIniFile;

    procedure LoadCursors;

    procedure LoadSettingsFromIniFile;
    procedure SaveSettingsToIniFile;

    procedure RefreshSavedImg;

    function GetNextNonameNumber: String;

    //Assigns new ids to a model and optionally shifts it 30px to right/bottom
    function AssignNewIDsToEERObjects(themodel: string; shiftObjectPositions: Boolean = false): string;
    //Centers the model on the canvas
    procedure CenterModel(theModel: TEERModel);
  private
    { Private declarations }
    NonameCounter: integer;
  public
    { Public declarations }

    WorkToolLabelTexts: TStringList;
    CurrentWorkTool, SelectedWorkTool: integer;

    DisplayMode: integer;
    DisplayPhysicalSchema,
    DisplayPaperGrid,
    DisplayTableIndices: Boolean;
    Notation: integer;
    DisplayRelationNames: Boolean;
    ShowForeignKeys: Boolean;

    WorkMode: integer;

    DisablePaint,
    DisableTextOutput: Boolean;

    LimitUndoActions: Boolean;
    UndoActionLimit: integer;

    CompareTable: Pointer;

    InitWorkMode: integer;

    DefaultRegionColors: string;

    TblHeaderBGImgs: string;

    //ActiveSQLColumnDragPositions: integer;
    IsDragging: Boolean;

    UsePositionGrid: Boolean;
    PositionGrid: TPoint;

    TableNameInRefs: Boolean;
    DefaultTableType: integer;
    ActivateRefDefForNewRelations: Boolean;

    FKPrefix, FKPostfix: string;

    CreateFKRefDefIndex: Boolean;

    EncloseNames,
    RenameReservedWords: Boolean;

    DoNotUseRelNameInRefDef: Boolean;

    UseNewXMLParser: Boolean;

    TableSplitterPos: integer;

    SyncDatatypesOfForeignKeys: Boolean;
    OutputLinuxStyleLineBreaks: Boolean;

    AddQuotesToDefVals: Boolean;
  end;

  const
    crMoveCursor=2;
    crNewTableCursor=10;
    crRel1nCursor=11;
    crRel1nSubCursor=12;
    crRel11Cursor=13;
    crRelnmCursor=14;
    crRel11SubCursor=15;
    crRel11NonIdCursor=16;
    crNewRegionCursor=20;
    crNewNoteCursor=21;
    crNewImageCursor=22;
    crHandCursor=30;
    crZoomInCursor=31;
    crZoomOutCursor=32;
    crSizeCursor=40;
    crDeleteCursor=41;
    crSQLSelectCursor=50;
    crSQLFromCursor=51;
    crSQLOnCursor=52;
    crSQLWhereCursor=53;
    crSQLGroupCursor=54;
    crSQLHavingCursor=55;
    crSQLOrderCursor=56;
    crSQLSetCursor=57;
    crPlacementCursor=58;


    wtPointer=1;
    wtMove=2;
    wtTable=3;
    wtRel1n=4;
    wtRel1nSub=5;
    wtRel11=6;
    wtRegion=7;
    wtNote=8;
    wtHand=9;
    wtZoomIn=10;
    wtZoomOut=11;
    wtRelnm=12;
    wtDelete=13;
    wtSize=14;
    wtRel11Sub=15;
    wtImage=16;
    wtRel11NonId=17;

    wtSQLSelect=50;
    wtSQLFrom=51;
    wtSQLOn=52;
    wtSQLWhere=53;
    wtSQLGroup=54;
    wtSQLHaving=55;
    wtSQLOrder=56;
    wtSQLSet=57;

    wtPlacementFromFile=58;
    wtPlacementFromDB=59;
    wtPlacementFromLibrary=60;


    dmEntityLevel=1;
    dmPrimaryKeyLevel=2;
    dmAttributeLevel=3;

    noStandard=1;
    noErwin=2;
    noStandard2=3;
    noCrowsFoot=4;

    wmDesign=1;
    wmQuery=2;

const
  QEventType_EditTable = QEventType(Integer(QEventType_ClxUser) + 1);
  QEventType_EditRel = QEventType(Integer(QEventType_ClxUser) + 2);
  QEventType_EditRegion = QEventType(Integer(QEventType_ClxUser) + 3);
  QEventType_EditNote = QEventType(Integer(QEventType_ClxUser) + 4);
  QEventType_EditImage = QEventType(Integer(QEventType_ClxUser) + 5);
  QEventType_SetWorkTool = QEventType(Integer(QEventType_ClxUser) + 10);
  QEventType_RefreshPalettes = QEventType(Integer(QEventType_ClxUser) + 11);
  QEventType_RefreshNavPalette = QEventType(Integer(QEventType_ClxUser) + 12);
  QEventType_ClearNavImg = QEventType(Integer(QEventType_ClxUser) + 13);
  QEventType_RefreshInfoPalette = QEventType(Integer(QEventType_ClxUser) + 14);
  QEventType_UpdateStatusBar = QEventType(Integer(QEventType_ClxUser) + 15);
  QEventType_SetStatusCaption = QEventType(Integer(QEventType_ClxUser) + 16);
  QEventType_SetSaveImgs = QEventType(Integer(QEventType_ClxUser) + 17);
  QEventType_RefreshDataTypesPalette = QEventType(Integer(QEventType_ClxUser) + 18);
  QEventType_RefreshModelPalette = QEventType(Integer(QEventType_ClxUser) + 19);
  QEventType_EnableMainFormRefreshTmr = QEventType(Integer(QEventType_ClxUser) + 20);
  QEventType_RemoveChildFormsMenuItem = QEventType(Integer(QEventType_ClxUser) + 21);
  QEventType_AddToRecentFileList = QEventType(Integer(QEventType_ClxUser) + 22);
  QEventType_StartEERObjectDrag = QEventType(Integer(QEventType_ClxUser) + 23);
  QEventType_EndEERObjectDrag = QEventType(Integer(QEventType_ClxUser) + 24);
  QEventType_SelectSQLColumnFromTable = QEventType(Integer(QEventType_ClxUser) + 25);
  QEventType_RestoreStayOnTopForms = QEventType(Integer(QEventType_ClxUser) + 26);
  QEventType_RefreshGridBtn = QEventType(Integer(QEventType_ClxUser) + 27);
  QEventType_ModelNameChanged = QEventType(Integer(QEventType_ClxUser) + 28);
  QEventType_PlaceModelFromFile = QEventType(Integer(QEventType_ClxUser) + 29);
  QEventType_PlaceModelFromDB = QEventType(Integer(QEventType_ClxUser) + 30);
  QEventType_PlaceModelFromLibrary = QEventType(Integer(QEventType_ClxUser) + 31);
  QEventType_DeleteObject = QEventType(Integer(QEventType_ClxUser) + 32);
  QEventType_RedrawTableList = QEventType(Integer(QEventType_ClxUser) + 33);
var
  DMEER: TDMEER;

implementation

uses MainDM;

{$R *.xfm}

procedure TDMEER.DataModuleCreate(Sender: TObject);
begin
  //Create StringLists
  WorkToolLabelTexts:=TStringList.Create;


  //Load Cursors from Bitmaps
  LoadCursors;


  //Initialise Variables
  DisablePaint:=False;
  DisableTextOutput:=False;


  DisplayMode:=3;
  DisplayPhysicalSchema:=True;
  DisplayTableIndices:=False;
  DisplayPaperGrid:=False;
  Notation:=noStandard;
  DisplayRelationNames:=False;
  ShowForeignKeys:=True;

  TblHeaderBGImgs:='XP1';

  NonameCounter:=0;

  InitWorkMode:=wmDesign;
  WorkMode:=wmDesign;

  LoadSettingsFromIniFile;

  LoadWorkToolLabelTextsFromIniFile;

  //ActiveSQLColumnDragPositions:=0;
  IsDragging:=False;

  UseNewXMLParser:=True;
end;

procedure TDMEER.DataModuleDestroy(Sender: TObject);
begin
  SaveSettingsToIniFile;
  
  WorkToolLabelTexts.Free;
end;

procedure TDMEER.SetWorkTool(WorkTool: integer);
begin
  SelectedWorkTool:=WorkTool;
  SetCurrentWorkTool(SelectedWorkTool);

  //Post SetWorkTool Event
  sendCLXEvent(Application.MainForm.Handle, QCustomEvent_create(QEventType_SetWorkTool, @SelectedWorkTool));

  if(Application.MainForm.Visible)then
    Application.MainForm.SetFocus;

  //Clear current WorkTool selection
  {for i:=ComponentCount-1 downto 0 do
    if(Copy(Components[I].Name, 1, 2)='wt')and
      (Components[I].Classname='TSpeedButton')then
      TSpeedButton(Components[I]).Down:=False;}
end;

procedure TDMEER.UpdateStatusBar;
begin
  if(Assigned(Application.MainForm))then
    sendCLXEvent(Application.MainForm.Handle, QCustomEvent_create(QEventType_UpdateStatusBar, @SelectedWorkTool));
end;

procedure TDMEER.RefreshPalettes;
begin
  if(Assigned(Application.MainForm))then
    QApplication_postEvent(Application.MainForm.Handle, QCustomEvent_create(QEventType_RefreshPalettes, nil));
end;

procedure TDMEER.RefreshNavPalette;
begin
  if(Assigned(Application.MainForm))then
    QApplication_postEvent(Application.MainForm.Handle, QCustomEvent_create(QEventType_RefreshNavPalette, nil));
end;

procedure TDMEER.RefreshNavImg;
begin
  if(Assigned(Application.MainForm))then
    QApplication_postEvent(Application.MainForm.Handle, QCustomEvent_create(QEventType_RefreshNavPalette, nil));
end;

procedure TDMEER.RefreshInfoPalette;
begin
  if(Assigned(Application.MainForm))then
    QApplication_postEvent(Application.MainForm.Handle, QCustomEvent_create(QEventType_RefreshInfoPalette, nil));
end;

procedure TDMEER.SetWorkToolCurser(WorkTool: integer);
begin
  case CurrentWorkTool of
      wtPointer:
        Screen.Cursor:=crDefault;
      wtMove:
        Screen.Cursor:=crMoveCursor;
      wtDelete:
        Screen.Cursor:=crDeleteCursor;
      wtSize:
        Screen.Cursor:=crSizeCursor;

      wtRegion:
        Screen.Cursor:=crNewRegionCursor;
      wtTable:
        Screen.Cursor:=crNewTableCursor;
      wtRel1n:
        Screen.Cursor:=crRel1nCursor;
      wtRel1nSub:
        Screen.Cursor:=crRel1nSubCursor;
      wtRel11:
        Screen.Cursor:=crRel11Cursor;
      wtRelnm:
        Screen.Cursor:=crRelnmCursor;
      wtRel11Sub:
        Screen.Cursor:=crRel11SubCursor;
      wtRel11NonId:
        Screen.Cursor:=crRel11NonIdCursor;

      wtNote:
        Screen.Cursor:=crNewNoteCursor;
      wtImage:
        Screen.Cursor:=crNewImageCursor;

      wtHand:
        Screen.Cursor:=crHandCursor;
      wtZoomIn:
        Screen.Cursor:=crZoomInCursor;
      wtZoomOut:
        Screen.Cursor:=crZoomOutCursor;

      wtSQLSelect:
        Screen.Cursor:=crSQLSelectCursor;
      wtSQLFrom:
        Screen.Cursor:=crSQLFromCursor;
      wtSQLOn:
        Screen.Cursor:=crSQLOnCursor;
      wtSQLWhere:
        Screen.Cursor:=crSQLWhereCursor;
      wtSQLGroup:
        Screen.Cursor:=crSQLGroupCursor;
      wtSQLHaving:
        Screen.Cursor:=crSQLHavingCursor;
      wtSQLOrder:
        Screen.Cursor:=crSQLOrderCursor;
      wtSQLSet:
        Screen.Cursor:=crSQLSetCursor;
      wtPlacementFromFile:
        Screen.Cursor:=crPlacementCursor;
      wtPlacementFromDB:
        Screen.Cursor:=crPlacementCursor;
      wtPlacementFromLibrary:
        Screen.Cursor:=crPlacementCursor;
  end;
end;

procedure TDMEER.SetCurrentWorkTool(WorkTool: integer);
var theEvent: QCustomEventH;
begin
  CurrentWorkTool:=WorkTool;
  SetWorkToolCurser(CurrentWorkTool);

  //Display the WorkTool Info
  if(CurrentWorkTool<=WorkToolLabelTexts.Count)then
    theEvent := QCustomEvent_create(QEventType_SetStatusCaption, PChar(WorkToolLabelTexts[CurrentWorkTool-1]))
  else
    theEvent := QCustomEvent_create(QEventType_SetStatusCaption, PChar(''));

  if(Application.MainForm<>nil)then
    sendCLXEvent(Application.MainForm.Handle, theEvent);

end;

⌨️ 快捷键说明

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