Delphi SDK のハウツー FAQ

 

Altium Designer の SDK コーディングに関する、よくある質問をご覧ください。

SDK API の詳細については、Altium Designer SDK Reference を参照してください。

System

Altium Designer SDK のシステム要件は何ですか?

Altium SDK を使用して Altium Designer 向けのソフトウェア拡張機能を開発するには、Embarcadero Delphi XE2 以降、SDK、そして Altium Designer 13 以降が必要です。Altium Designer のソフトウェア拡張機能のビルドには、比較的新しい Delphi の各エディションを利用できます。Embarcadero Delphi Starter edition(低コストな選択肢)、Professional edition、Enterprise、Architect、Ultimate edition はいずれも Altium SDK で問題なく動作します。

Altium Designer SDK 自体は、3 つの主要な API で構成されています。DXP(Electronic Data Platform API ユニット群)、PCB Editor API、そして Schematic API です。なお、各 API には Delphi / Object Pascal のソースコードユニット一式が用意されています。さらに、Altium SDK の C++ 版および C# 版も利用可能です。

Permissions

Windows 7 上で標準の Altium SDK をインストールした場合、Embarcadero Delphi アプリケーションは SDK の \Examples フォルダーや、Altium Designer の \System フォルダーへ直接書き込めないことがあります。原因は、システム既定のフォルダー/ユーザー権限です。

Windows のフォルダーおよびユーザー権限を適切に変更することもできますが、最も簡単な回避策は、生成された DLL を手動でコピーし、拡張機能プロジェクトの設定ファイル(INS ファイルや RCS ファイルなど)と一緒に Altium Designer の System フォルダーへ配置することです。詳細は、Setting up your Server Project セクション(Getting started: Building a Delphi extension ドキュメント内)を参照してください。

DXP Platform

SDK を使って Schematic ドキュメントを別のファイル形式で保存できますか?

はい、可能です。利用可能なドキュメント形式は、回路図ドキュメントについて Ascii、Orcad、Template、Binary、standard schematic binary、AutoCad DXF、AutoCad DWG です。なお、Template、Binary、および空文字列 ""  の 3 つは、同じ Altium Designer の Schematic Design 形式を表します。

コードスニペット:

doc := Client.GetDocumentByPath(ProjectDoc.DM_FullPath);
doc.SetModified(TRUE);
doc.DoFileSave(documentKind);

ドキュメントを別の形式で保存するには、documentKind パラメーターに次のいずれかのフォーマット文字列を設定する必要があります。

'ASCII'          – ASCII format
'ORCAD'          – ORCAD format
'TEMPLATE'
'BINARY'         – standard binary format
'AUTOCAD DXF'    – DXF format
'AUTOCAD DWG'    – DWG format

プロジェクトがコンパイル済みかどうか、またそのコンパイル結果が最新かどうかを判定できますか?

多くの処理では、プロジェクトがコンパイルされている必要があります。プロジェクトがコンパイル済みで、その後変更されていないかが分からなければ、データにアクセスする前に毎回プロジェクトを無条件にコンパイルするしかありません。この不要なコンパイルを避ける方法があります。

DM_NeedsCompile オブジェクトインターフェース(IProject ユニット)の EDPInterfaces メソッドを使用すると、プロジェクトにコンパイルが必要かどうかを判定できます。

IProject インターフェースにおけるこの関数の宣言は次のとおりです: Function IProject.DM_NeedsCompile : LongBool;

サーバーモジュールは PluginFactory 関数内でのみ作成できますか(SDK サンプルのように)?

Is there is any other way? When does Altium Designer call the PluginFactory function? During launch or during a plugin command call from the Altium plugin panel?

サーバーモジュールは任意の場所で作成できます。たとえば、DLL モジュールのロード時(Initialization 句内)でも可能です。

Altium Designer アプリケーションは、Dynamic Linked Library ファイル(DLL)をロードした直後に PluginFactory 関数を呼び出します。この場合、サーバーモジュールの作成には Main ユニット内の PluginFactory 関数が最適な場所です。

通常、Altium Designer は、そのサーバーモジュールに関連するコマンドを起動する必要が生じたときに、指定されたサーバーモジュールをロードします(PluginFactory 関数を呼び出します)。ただし、拡張サーバーのインストールファイル内の Server End ブロックで "SystemExtension = True" 句を設定することもできます。この場合、Altium Designer は起動時に自動的にそのサーバーモジュールをロードします。

Server
    EditorName        = ...
        ...
    SystemExtension   = True
End

古いバージョンのプロジェクトを Altium Designer 13.1 に更新できますか?

互換性に関する問題は、DXP Service Pack 2 など Altium Designer 以前のサーバープロジェクトのメインユニットに集中しています。stdcall、NewDocumentInstance、AddCommand メソッドなどの一部キーワードはすべて置き換える必要があります。

サーバープロジェクトのメインユニットでは、次の項目を見直す必要があります。

  • AddCommand procedure を RegisterCommand procedure に置き換える
  • コメント: TServerModule クラスの集約クラスとしての CommandLauncher に対して、AddCommand メソッドを RegisterCommand に置き換えてください。AddCommand メソッドは Altium Designer には存在しません。代わりに、宣言したコマンド(process)を Altium Designer のサーバーテーブルに格納するには RegisterCommand メソッドを使用してください。
  • StdcallSafeCall;
  • に置き換える コメント: safecall キーワードは COM の世界で使用され、EXE から DLL のような境界をまたぐ関数インポートの障害に対して、より安全に保護されます。
  • PCharWideString メソッドに置き換える。
  • コメント: TServerModuleNewDocumentInstance メソッドは、パラメーターシグネチャがわずかに変更されています。PChars を WideStrings に置き換えてください。

拡張機能から他の process を実行するにはどうすればよいですか?

EDPUtil ユニット内の MessageRouter_SendCommandToModule 関数を使うと、拡張サーバーから別のサーバーの process を実行できます。この関数のパラメーターは Process、Parameters、EditorWindow です。

ターゲットウィンドウハンドルは、その process を実行する対象ドキュメントオブジェクトのウィンドウハンドルを指定します。サーバーでサポートされるドキュメントが存在しない場合、このパラメーターは Nil に設定する必要があります。この関数は、対象サーバーがまだ起動していない場合、自動的に起動します。

process は Parameters パラメーターを使って結果を返すことができます。たとえば、"Client:RunCommonDialog" process はダイアログを実行し、その結果をこのパラメーター経由で返します。

Schematic の Zoom Process を呼び出す例:

Procedure ZoomToDoc;
Var
    Parameters : WideString;
Begin
  SetState_Parameter(Parameters, 'Action', 'Document');
  MessageRouter_SendCommandToModule('SCH:Zoom', Parameters, MessageRouter_GetState_CurrentEditorWindow);
End;

文字列 'Action=Document' は Parameters parameter に代入され、その後 process 文字列 SCH:Zoom に渡されて、現在の schematic ドキュメントに対してズームコマンドが実行されます。

PCB の例:

CommandLauncher.LaunchCommand('PCB:Zoom', 'Action=Redraw', Client.CurrentView); 

拡張機能プロジェクトに新しい Delphi フォームを追加するにはどうすればよいですか?

既定では、Delphi はアプリケーションのプロジェクトソースユニットに次のコードを含めることで、アプリケーションのメインフォームを自動的にメモリ上に作成します: Application.Create(TForm1,Form1);

これらのプロジェクトは EXE(実行可能)ファイルとしてコンパイルされます。しかし、サーバープロジェクトは DLL ファイルとしてコンパイルされるため、メインフォームは実行時に自動作成されません。フォームは動的に作成する必要があります。ダイアログフォームをサーバープロジェクトに組み込む手順は次のとおりです:

  1. Delphi で File » New » VCL フォームをクリックすると、サーバーライブラリモジュール(プロジェクトファイル内)にフォームが生成され、ライブラリソースの Uses 句に Form 句が追加されます。
  2. 新しいフォームに対応するユニットがアクティブになっていることを確認してください。この新しいユニットの Uses ディレクティブに、必要な Altium Designer API(例: EDPClasses)を追加します。
  3. 次のステップは、実行時にダイアログを作成することです(process が呼び出されたときにダイアログを表示します)。サーバープロジェクトの commands.pas ユニットで定義される process 群が開始点となり、各 process の内部から、このサーバープロジェクトを構成する別ユニット内の関数が呼び出されることがあります。フォームを有効化するには、次のコードスニペットを実装する必要があります。

commands.pas ユニットにおけるダイアログ作成の例

Procedure Command_ProcessA(View : IServerDocumentView; Parameters : WideString);
Begin
    MyDialog := TMyDialog.Create(Application);
    MyDialog.ShowModal;
    MyDialog.Free;
End;

ダイアログのオーナーハンドルを Altium Designer に属させるために Altium Designer のアプリケーションハンドルを取得するには、サーバープロジェクトのメインユニットにある ServerFactory 関数内で、Client.ApplicationHandleApplication.Handle に設定する必要があります。これによりダイアログは Altium Designer のアイコンを継承し、タスクバー上にも同じアイコンが 1 つだけ表示されます。

PlugInFactory 関数の例:

Function PlugInFactory (AClient : IClient) : IServerModule;
Begin
    Result := TCustomizedServerModule.Create(AClient, 'CustomServer');
    Application.Handle := Client.ApplicationHandle;
End;

特定のパスを使ってドキュメントを開くにはどうすればよいですか?

IClient インターフェースの OpenDocument メソッドおよび ShowDocument メソッド、または EDPInterfaces ユニット由来の IWorkspace インターフェースにある DM_GetDocumentFromPath メソッドを使用します。

コードスニペット:

_Client := Client;
If _Client = Nil Then Exit;
Kind := Client.GetDocumentKindFromDocumentPath(FileName);
ServerDocument := Client.OpenDocument(Kind,FileName);
If ServerDocument <> Nil Then
 Client.ShowDocument(ServerDocument)

コードスニペット:

WorkSpace := GetWorkspace; //IWorkSpace interface
If WorkSpace = Nil then Exit;
//FullPath is a string containing the full path to the document.
Document := WorkSpace.DM_GetDocumentFromPath(FullPath); //IDocument interface
Kind := Client.GetDocumentKindFromDocumentPath(FileName);
ServerDocument := Client.OpenDocument(Kind,FileName);
If ServerDocument <> Nil Then
 Client.ShowDocument(ServerDocument)

Altium Designer でプログラムからドキュメントを閉じるにはどうすればよいですか?

IClient インターフェースの CloseDocument メソッドを使用します。IServerDocument 型の document パラメーターを渡す必要があります。

コードスニペット:

_Client := Client;
If _Client = Nil Then Exit;
//ADocument is of IServerDocument type.
_Client.CloseDocument(ADocument);

アクティブな Document を取得するにはどうすればよいですか?

Altium Designer でロード済みプロジェクトのアクティブドキュメントを取得するには、EDPInterfaces unit の IWorkSpace インターフェースにある DM_FocusedDocument メソッドを使用する必要があります。

コードスニペット:

WorkSpace := GetWorkspace; //IWorkSpace interface
If WorkSpace = Nil then Exit;
Document := WorkSpace.DM_FocusedDocument; //IDocument interface

自分のドキュメントをフォーカスされた、またはアクティブなドキュメントにするにはどうすればよいですか?

EDPInterfaces ユニットの IServerDocumentView インターフェースにある SetFocus メソッド、または IServerDocument インターフェースの Focus メソッドを使用します。

なお、IServerDocument 型の document は複数の document view を持つことがあり、その場合、IServerDocument には IServerDocumentViews のインデックス付きリストである View プロパティがあります。SetFocus メソッドを適用する前に、目的の document view を取得するための反復処理が必要です。

コードスニペット:

WorkSpace := GetWorkspace; //IWorkSpace interface
If WorkSpace = Nil then Exit;
Document := WorkSpace.DM_FocusedDocument; //Grab the focused IDocument object
Document.Focus; // focus this document.

アクティブな Document のタイプ(document kind)を確認するにはどうすればよいですか?

EDPClasses Unit にある Client オブジェクトを使用し、currentView メソッドを呼び出してアクティブドキュメントの document type(kind)を取得します。

コードスニペット 1 – Client インターフェースを使用:

_Client := Client;
If _Client = Nil Then Exit;
//Check if a schematic document exists or not.
CurrentView := _Client.CurrentView; // IServerDocumentView
OwnerDocument := CurrentView.OwnerDocument; // IServerDocument
If OwnerDocument.Kind = 'SCH' Then ShowMessage('A Schematic document');

または

コードスニペット 2 – Workspace インターフェースを使用:

WorkSpace := GetWorkspace; //IWorkSpace interface
If WorkSpace = Nil then Exit;
Doc := WorkSpace.DM_FocusedDocument;
If Doc.DM_DocumentKind = 'SCH' Then ShowMessage('A Schematic document');

アクティブな Project を取得するにはどうすればよいですか?

まず workspace オブジェクトが必要で、その後 DM_FocusedProject メソッドを呼び出してアクティブプロジェクトを取得します。GetWorkspace 関数は EDPUtil unit にあります。IWorkspace インターフェースは EDPInterfaces ユニットにあります。

コードスニペット:

WorkSpace := GetWorkspace; //workspace is a IWorkSpace interface
If WorkSpace = Nil then Exit;
FocusedProject := WorkSpace.DM_FocusedProject; //FocusedProject = IProject interface

アクティブな Project 内の documents を反復処理するにはどうすればよいですか?

アクティブ / フォーカスされたプロジェクトを取得するには、EDPInterfaces Unit の IWorkspace インターフェースにある DM_FocusedProject メソッドが必要です。

コードスニペット:

WorkSpace := GetWorkspace; //IWorkSpace interface
If WorkSpace = Nil then Exit;
Project := WorkSpace.DM_FocusedProject; //IProject interface
For K := 0 To Project.DM_PhysicalDocumentCount – 1 Do
Begin
    Document := Project.DM_PhysicalDocuments(K);
    S := Document.DM_FullPath; //s is the full filename of the document.
End;

プロジェクトの論理ドキュメントを反復処理するにはどうすればよいですか?

プロジェクトの論理ドキュメントを検索するには、EDPInterfaces ユニットの IProject インターフェースにある DM_LogicalDocuments メソッドを使用する必要があります。

コードスニペット:

WorkSpace := GetWorkspace; //IWorkSpace interface
If WorkSpace = Nil then Exit;
Project := WorkSpace.DM_FocusedProject; //IProject interface
For K := 0 To Project.DM_LogicalDocumentCount – 1 Do
Begin
    LogicalDocument := Project.DM_LogicalDocuments(K); //IDocument
End;

プロジェクトにドキュメントを追加/削除するにはどうすればよいですか?

Workspace manager 関数:

  • DM_AddSourceDocument
  • DM_RemoveSourceDocument

Altium Designer でプロジェクトをコンパイルするにはどうすればよいですか?

プロジェクトをコンパイルするには、IProject インターフェースの DM_Compile メソッドを使用します。

コードスニペット:

WorkSpace := GetWorkspace;    If WorkSpace = Nil then Exit;
Project := WorkSpace.DM_FocusedProject;
  If Project = Nil Then Exit;
  If Project.DM_NeedsCompile Then
    Project.DM_Compile;

Output Jobs

OutputJob ドキュメントで出力を設定し、実行するにはどうすればよいですか?

プロジェクトから OutputJob ドキュメントを取得するには、すべての論理ドキュメントを反復処理し、DocumentKind が "OUTPUTJOB" に等しいドキュメントを見つける必要があります。

SDK から OutputJob を実行するには、次の手順に従ってください:

  1. プロジェクト内の OutputJob ファイルを見つけます(論理ドキュメントを反復処理)。
  2. このファイルを開いてアクティブにします。
  3. 使用したい「出力コンテナ」に応じてコマンドを実行します。
Procedure Command_PrintOutputJobPDF(View : IServerDocumentView; Parameters : WideString);
Var
    WorkSpace  : IWorkspace;
    Project    : IProject;
    FileName   : String;
    Process    : String;
    ProjectDoc : IDocument;
    ServerDoc  : IServerDocument;
    i          : Integer;
Begin
    WorkSpace := GetWorkspace;
    If WorkSpace = Nil then
        Exit;
    Project := WorkSpace.DM_FocusedProject;
    If Project = Nil Then
        Exit;
    If Project.DM_NeedsCompile Then
        Project.DM_Compile;
    For I := 0 To Project.DM_LogicalDocumentCount – 1 Do
    Begin
        ProjectDoc := Project.DM_LogicalDocuments(i);
        If ProjectDoc <> Nil Then
        Begin
            If ProjectDoc.DM_DocumentKind = 'OUTPUTJOB' Then
            Begin
                FileName := ProjectDoc.DM_FullPath;
                ServerDoc  := Client.OpenDocument('OUTPUTJOB',FileName);
                If ServerDoc <> Nil Then
                Begin
                    Client.ShowDocument(ServerDoc);
                    //Process    := 'WorkspaceManager:Print';        
                    //Parameters := 'Action=PrintDocument|ObjectKind=OutputBatch';
                    Process    := 'WorkspaceManager:Print';
                    Parameters := 'Action=PublishToPDF|DisableDialog=True|ObjectKind=OutputBatch';
                    //Process    := 'WorkspaceManager:Print';
                    //Parameters := 'Action=PublishMultimedia|DisableDialog=True|ObjectKind=OutputBatch';
                    //Process    := 'WorkspaceManager:GenerateReport';
                    //Parameters := 'Action=Run|ObjectKind=OutputBatch';
                    RunCommand(Process, Parameters);
                End;
                Exit;
            End;
        End;
    End;
End;

PCB

PCB プリミティブを変更する標準的な方法は何ですか?

What should I use instead of PCBServer.SendMessageToRobots?

コード:

procedure UpdateTrackFromObject(aObj: TOutlineObject; aTrack: IPCB_Track);
begin
  PCBServer.PreProcess;
  //PCBServer.SendMessageToRobots(aTrack.I_ObjectAddress, c_BroadCast, PCBM_BeginModify, c_NoEventData);
  try
        aT.X1 := round(aObj.X1);
        aT.Y1 := round(aObj.Y1);
        aT.X2 := round(aObj.X2);
        aT.Y2 := round(aObj.Y2);
  finally
        //PCBServer.SendMessageToRobots(aTrack.I_ObjectAddress, c_BroadCast, PCBM_EndModify, c_NoEventData);
        PCBServer.PostProcess;
  end;
end;

これを行うには、次のコードを使用してください:

Procedure UpdateTrackFromObject(aObj: TOutlineObject; aTrack: IPCB_Track);
Var
    Board           : IPCB_Board;
    _PCBServer  : IPCB_ServerInterface;
begin
    _PCBServer := PCBServer;
    If _PCBServer = Nil Then
        Exit;
    Board := _PCBServer.GetCurrentPCBBoard;    
    If Board = Nil Then
        Exit;
    _PCBServer.PreProcess;
    Board.DispatchMessage(aTrack, c_Broadcast, PCBM_BeginModify, c_NoEventData);
    try
        aT.X1 := round(aObj.X1);
        aT.Y1 := round(aObj.Y1);
        aT.X2 := round(aObj.X2);
        aT.Y2 := round(aObj.Y2);
    finally
        Board.DispatchMessage(aTrack, c_Broadcast, PCBM_EndModify, c_NoEventData);
        _PCBServer.PostProcess;
    end;
end;

アクティブな PCB ボードを取得するにはどうすればよいですか?

PCB ボードのハンドルを取得するには、PCBServer 関数を呼び出し、その後 PCBServer オブジェクトの GetCurrentPCBBoard メソッドを呼び出す必要があります。

Var
    Server   : IPCB_ServerInterface;
    PcbBoard : IPCB_Board;
Begin
    Server     := PCBServer;
    PcbBoard   := Server.GetCurrentPCBBoard;
...
End;

PCB オブジェクトを反復処理するにはどうすればよいですか?

PCB ドキュメント上の PCB オブジェクトを反復処理するには、まず PCB ドキュメントを取得し、次に初期条件(レイヤー、オブジェクトタイプ、反復方法など)を指定してイテレータを設定し、それ以上見つかるオブジェクトがなくなるまで反復処理を実行する必要があります。

特定の PCB オブジェクトを反復処理するにはどうすればよいですか?

特定の PCB オブジェクトを反復処理するには、オブジェクトイテレータの Object Set フィルターに PCB タイプを設定する必要があります。

コードスニペット:

Var
    ObjectHandle   : IPCB_Primitive;
    IteratorHandle : IPCB_BoardIterator;
    Server         : IPCB_ServerInterface;
Begin
    Server     := PCBServer;
    PcbBoard   := Server.GetCurrentPCBBoard;
    IteratorHandle := PcbBoard.BoardIterator_Create;
    IteratorHandle.AddFilter_ObjectSet([eNetObject]);
    IteratorHandle.AddFilter_LayerSet(AllLayers);
    IteratorHandle.AddFilter_Method(eProcessAll);
    ObjectHandle := IteratorHandle.FirstPCBObject;
    While ObjectHandle <> Nil Do
    Begin
        ObjectHandle.Index := 0;
        ObjectHandle := IteratorHandle.NextPCBObject;
    End;
    PcbBoard.BoardIterator_Destroy(IteratorHandle);
End;

パッドオブジェクトを検索する別の例です。

コードスニペット:

Iterator        := Board.BoardIterator_Create;
Iterator.AddFilter_ObjectSet([ePadObject]);
Iterator.AddFilter_LayerSet_2(cAllLayers);
Iterator.AddFilter_Method(eProcessAll);
// search and count pads
Pad := Iterator.FirstPCBObject;
While (Pad <> Nil) Do
Begin
    PadNumber := PadNumber + 1;
    Pad := Iterator.NextPCBObject;
End;
Board.BoardIterator_Destroy(Iterator);

選択されている PCB オブジェクトを取得するにはどうすればよいですか?

PCB 設計オブジェクトの Selected プロパティを呼び出して、選択状態のブール値を取得または設定できます。すべての PCB オブジェクトのオブジェクトインターフェースは、IPCB_Primitive インターフェースから継承されています。

PCB オブジェクトを更新するにはどうすればよいですか?

PCB オブジェクトの属性を変更した場合、その PCB オブジェクトを更新するために PCB ボードの DispatchMessage メソッドを呼び出す必要があります。これは 2 段階の処理で、オブジェクトを変更する前に DispatchMessage メソッドへ PCBM_BeginModify パラメータを指定して呼び出し、その後 PCBM_EndModify パラメータを指定した別の DispatchMessage 呼び出しを行います。

コードスニペット

Board.DispatchMessage(Component, c_Broadcast, PCBM_BeginModify, c_NoEventData);
    If OriginalHeight <> C Then
    Begin
        Component.Height := C;
        CommandLauncher.LaunchCommand('PCB:Zoom', 'Action=Redraw', 255, Client.CurrentView);
    End;
Board.DispatchMessage(Component, c_Broadcast, PCBM_EndModify, c_NoEventData);

PCB ドキュメントに新しい PCB オブジェクトを追加するにはどうすればよいですか?

PCBServer オブジェクトの PCBObjectFactory メソッドを使用して新しい PCB オブジェクトを作成し、PCB ドキュメントに追加します。トラックオブジェクトを作成するには、それが寸法として使用されるかどうかを指定する必要があります。この PCBObjectFactory メソッドの宣言は次のとおりです。

Function PCBObjectFactory(Const AObjectId : EDPTypes_PCB.TObjectId;
Const ADimensionKind : TDimensionKind;
Const ACreationMode : TObjectCreationMode) : IPCB_Primitive;

パラメータのうち、AObjectID は実際の設計オブジェクト、ADimensionKind は(主にトラックおよびアーク用)、ACreationMode はデフォルトで eCreate_Default です。

アークオブジェクトを作成する例:

コードスニペット:

_PCBServer := PCBServer;
If _PCBServer = Nil Then
   Exit;
PCB_Board := _PCBServer.GetCurrentPCBBoard;
If PCB_Board  = Nil Then
   Exit;
_PCBServer.PreProcess;
// Current segment is an arc; create an Arc object.
IPrimitive := _PCBServer.PCBObjectFactory(eArcObject,eNoDimension,eCreate_Default);
If IPrimitive = Nil Then
   Exit;
Arc := IPCB_Arc(IPrimitive);
Arc.XCenter    := SegmentI.cx;
Arc.YCenter    := SegmentI.cy;
Arc.Layer      := ALayer;
Arc.LineWidth  := AWidth;
Arc.Radius     := SegmentI.Radius;
Arc.StartAngle := SegmentI.Angle1;
Arc.EndAngle   := SegmentI.Angle2;
PCB_Board.AddPCBObject(Arc);
_PCBServer.PostProcess;

Schematic

回路図ドキュメントに新しい Parameter を追加するにはどうすればよいですか?

Is it possible to make this Parameter non-visible to the end user (so having some kind of an internal property), or at least make it read-only (and writable only through SDK or several 'clicks' so that a user does not change or delete it by mistake)?

回路図ドキュメントのパラメータは管理できますが、パラメータを hidden または read-only に設定することはできません。以下は、それらを反復処理して新しいパラメータを追加する方法の例です:

Procedure Command_SCHDocParameters(View : IServerDocumentView; Parameters : WideString);
Var
    _SCHServer   : ISch_ServerInterface;
    RobotManager : ISch_RobotManager;
    WorkSpace    : IWorkspace;
    Project      : IProject;
    FileName     : String;
    ParamName    : String;
    ParamValue   : String;
    ProjectDoc   : IDocument;
    Sch_Doc      : ISch_Document;
    Sch_Sheet    : ISch_Sheet;
    Iterator     : ISch_Iterator;
    SchParameter : ISch_Parameter;
    SchParameter1: ISch_Parameter;
    Container    : ISch_BasicContainer;
    Container1   : ISch_BasicContainer;
    i            : Integer;
Begin
    WorkSpace := GetWorkspace;
    If WorkSpace = Nil then Exit;
    _SCHServer := SCHServer;
    If _SCHServer = Nil Then Exit;
    RobotManager := _SCHServer.RobotManager;
    If RobotManager = Nil Then Exit;
    ProjectDoc := WorkSpace.DM_FocusedDocument;
    If ProjectDoc <> Nil Then
    Begin
        If ProjectDoc.DM_DocumentKind = 'SCH' Then
        Begin
            FileName := ProjectDoc.DM_FullPath;
            Sch_Doc  := _SCHServer.GetSchDocumentByPath(FileName);
            If Sch_Doc <> Nil Then
            Begin
                Sch_Sheet := ISch_Sheet(Sch_Doc);              
                // Iterating for existing parameter objects.
                Iterator  := Sch_Sheet.SchIterator_Create;
                Iterator.SetState_IterationDepth(eIterateFirstLevel);
                Iterator.AddFilter_ObjectSet([eParameter]);
                Container := Iterator.FirstSchObject;
                While Container <> Nil Do
                Begin
                    SchParameter := ISch_Parameter(Container);
                    ParamName    := SchParameter.Name;
                    ParamValue   := SchParameter.GetState_Text;
                    Container   := Iterator.NextSchObject;
                End;
                Sch_Sheet.SchIterator_Destroy(Iterator);
                // Add a new parameter object and put it on the sheet
                RobotManager.SendMessage(c_FromSystem, c_BroadCast, SCHM_SystemInvalid, c_NoEventData);
                Container1 := _SCHServer.SchObjectFactory(eParameter, eCreate_Default);
                SchParameter1 := ISch_Parameter(Container1);
                SchParameter1.Name := 'TestParam';
                SchParameter1.SetState_Text('TestValue');
                Sch_Sheet.AddSchObject(SchParameter1);
                RobotManager.SendMessage(c_FromSystem, c_BroadCast, SCHM_SystemValid, c_NoEventData);
            End;
        End;
    End;
End;

アクティブな回路図シートを取得するにはどうすればよいですか?

回路図シートはプロジェクトの一部なので、シートにアクセスするには Workspace と Schematic Server のハンドルを取得する必要があります。Workspace manager オブジェクトを使用すると、フォーカスされているドキュメントを見つけて、そのドキュメントタイプを確認できます。回路図ドキュメントタイプであることが確認できたら、回路図オブジェクトの追加、削除、更新を進めることができます。

WorkSpace := GetWorkspace;
    If WorkSpace = Nil then
        Exit;
    _SCHServer := SCHServer;
    If _SCHServer = Nil Then
        Exit;
    ProjectDoc := WorkSpace.DM_FocusedDocument;
    If ProjectDoc <> Nil Then
    Begin
        If ProjectDoc.DM_DocumentKind = 'SCH' Then
        Begin
            FileName := ProjectDoc.DM_FullPath;
            Sch_Doc  := _SCHServer.GetSchDocumentByPath(FileName);
            If Sch_Doc <> Nil Then
            Begin
                Sch_Sheet := ISch_Sheet(Sch_Doc); //this is the focused sheet
            End;
        End;
    End;

回路図オブジェクトを反復処理するにはどうすればよいですか?

回路図ドキュメント上の回路図オブジェクトを反復処理するには、まず回路図ドキュメントを取得し、次に初期条件(オブジェクトタイプや反復方法など)を指定してイテレータを設定し、それ以上見つかるオブジェクトがなくなるまで反復処理を実行する必要があります。イテレータでは、回路図ドキュメント上の親オブジェクトのみ、または親とその子オブジェクトの両方を対象に検索できる点に注意してください。

特定の回路図オブジェクトを反復処理するにはどうすればよいですか?

回路図シートオブジェクトから呼び出したイテレータオブジェクトを設定し、反復の深さを設定し、反復を開始する前にオブジェクトタイプを指定します。

コードスニペット

// Iterating for existing parameter objects.
Iterator  := Sch_Sheet.SchIterator_Create;
Iterator.SetState_IterationDepth(eIterateFirstLevel);
Iterator.AddFilter_ObjectSet([eParameter]);
Container := Iterator.FirstSchObject;
While Container <> Nil Do
Begin
    SchParameter := ISch_Parameter(Container);
    ParamName    := SchParameter.Name;
    ParamValue   := SchParameter.GetState_Text;
    Container    := Iterator.NextSchObject;
End;
Sch_Sheet.SchIterator_Destroy(Iterator);

選択されている回路図オブジェクトを取得するにはどうすればよいですか?

回路図設計オブジェクトの Selection プロパティを呼び出して、選択状態のブール値を Get または Set できます。回路図オブジェクトのオブジェクトインターフェースは、ISch_GraphicalObject インターフェースから継承されています。

回路図オブジェクト/ドキュメントに対してパラメータを反復処理/更新/追加するにはどうすればよいですか?

コード:

Procedure Command_SCHDocParameters(View : IServerDocumentView; Parameters : WideString);
Var
    _SCHServer   : ISch_ServerInterface;
    RobotManager : ISch_RobotManager;
    WorkSpace    : IWorkspace;
    Project      : IProject;
    FileName     : String;
    ParamName    : String;
    ParamValue   : String;
    ProjectDoc   : IDocument;
    Sch_Doc      : ISch_Document;
    Sch_Sheet    : ISch_Sheet;
    Iterator     : ISch_Iterator;
    SchParameter : ISch_Parameter;
    SchParameter1: ISch_Parameter;
    Container    : ISch_BasicContainer;
    Container1   : ISch_BasicContainer;
    i            : Integer;
Begin
    WorkSpace := GetWorkspace;
    If WorkSpace = Nil then
        Exit;
    _SCHServer := SCHServer;
    If _SCHServer = Nil Then
        Exit;
    RobotManager := _SCHServer.RobotManager;
    If RobotManager = Nil Then
        Exit;
    ProjectDoc := WorkSpace.DM_FocusedDocument;
    If ProjectDoc <> Nil Then
    Begin
        If ProjectDoc.DM_DocumentKind = 'SCH' Then
        Begin
            FileName := ProjectDoc.DM_FullPath;
            Sch_Doc  := _SCHServer.GetSchDocumentByPath(FileName);
            If Sch_Doc <> Nil Then
            Begin
                Sch_Sheet := ISch_Sheet(Sch_Doc);
                
                       // Add a new parameter object and put it on the sheet
                RobotManager.SendMessage(c_FromSystem, c_BroadCast, SCHM_SystemInvalid, c_NoEventData);
                Container1 := _SCHServer.SchObjectFactory(eParameter, eCreate_Default);
                SchParameter1 := ISch_Parameter(Container1);
                SchParameter1.Name := 'TestParam';
                SchParameter1.SetState_Text('TestValue');
                Sch_Sheet.AddSchObject(SchParameter1);
                RobotManager.SendMessage(c_FromSystem, c_BroadCast, SCHM_SystemValid, c_NoEventData);
            End;
        End;
    End;
End;

Altium Designer のグラフィカルユーザーインターフェース

既存のメニューにメニュー項目を作成し、実行するコードを割り当てるにはどうすればよいですか?

新しいメニュー項目をターゲットのメニュー(ターゲットはたとえば PCB Editor や Schematic Editor)に追加し、それらに拡張サーバーのプロセスランチャーを割り当てる必要があります。行うべきことは 3 つあります:

  1. リソースファイル(拡張子 RCS)を Insertion End ブロック付きで更新する必要があります。
  2. プロジェクトのインストールファイル(拡張子 INS)に、ターゲットエディタ名の Updates 句を挿入します(たとえば PCB エディタには AdvPCB という名前があります)。
  3. ターゲットエディタのインストールファイル(PCB または Schematic エディタのインストールファイル)の ResourceDependencies ブロックに、拡張サーバーの名前を挿入します。

これを行うには、新しいメニュー項目をエディタのメニュー内のどこに表示するかを示す Target ID と Resource reference ID の値を把握している必要があります。これらの TargetID および RefID0 識別子は、Altium Designer の system フォルダにあるエディタの RCS ファイル、たとえば PCB エディタの AdvPCB.rcs ファイルを参照して確認できます。

リソースファイル(拡張子 RCS)内の Process Launcher Tree セクションでは、プロセスランチャーを含むメニュー項目が特定のメニューのどこに接続されるかを定義します。

自分のメニュー項目を PCB メニューに追加するにはどうすればよいですか?

  1. プロジェクトのリソースファイル(拡張子 RCS)を Insertion End ブロック付きで更新する必要があります。
  2. インストールファイル(拡張子 INS)の Server End ブロック内に、‘AdvPCB’ という名前で Updates 句を挿入します。
  3. AdvPCB.ins リソースファイルの ResourceDependencies ブロックに、拡張プロジェクトの名前を挿入します。

プラグインのインストールファイルのスニペット:

Server
    EditorName        = 'AddOn'                                                                   
    EditorExePath     = 'AddOn.DLL'                                                               
    EditorDescription = 'Demonstratory AddOn module'                                            
    Version           = 'Version 6.3.0.6689'                                                      
    Date              = '29-Dec-2012'                                                             
    HelpAboutInfo     = 'This software is protected by copyright law and international treaties.'
    Copyright         = 'Copyright © Altium Limited 2012'
    Updates           = 'ADVPCB'                                                                  
End

AdvPCB インストールファイルのスニペット:

Server
    EditorName        = 'PCB'                                                                     
    EditorExePath     = 'ADVPCB.DLL'                                                              
    EditorDescription = 'Altium Designer PCB Editor'                                        
    Version           = 'Version 10.0.0.28321'                                                      
    Date              = '03-May-2013'                                                             
    HelpAboutInfo     = 'This software is protected by copyright law and international treaties.'
    Copyright         = 'Copyright c Altium Limited 2013'                                         
    SupportsDDB       = True                                                                      

    ResourceDependencies
        'AutoPlacer'
        'CompMake'
        'HSEdit'
        'LayerStackupAnalyzer'
        'Macro'
        'MakeLib'
        'PCB3D'
        'PCBMaker'
        'PCBMiter'
        'Placer'
        'SignalIntegrity'
        'HelpAdvisor'
        'OrcadLayoutImporter'
        'SavePCADPCB'
        'AutoPlacer'
        'PinSwapper'
           'YourPlugInName'
    End
End

ボタンを作成し、それを自分の拡張機能のコマンド(プロセスランチャー)に割り当てるにはどうすればよいですか?

このようなボタンには画像が必要で、それらのビットマップは 18x18 ピクセルサイズである必要があります。ボタンファイル(拡張子 BMP)を Altium Designer のインストール先の ..\System\Buttons フォルダにコピーしてください。

これらのファイルは、エディタのメニュー項目の横に表示される画像や、ツールバーのボタンに使用されます。

独自のパネルを作成するにはどうすればよいですか?

サーバー内でグローバルパネルビューを追加および管理するには、パネルマネージャオブジェクトを構築し、その対応するオブジェクトインターフェースを定義する必要があります。このオブジェクトがグローバルパネルを管理します。このパネルマネージャオブジェクトはインターフェースとしても公開されるため、Extension を表す TServerModule オブジェクト内で使用できます。

このパネルを表す Delphi フォームが必要であり、パネルはパネルマネージャオブジェクト内および TServerModule オブジェクト内の private フィールドとしてカプセル化されます。グローバルパネルビューを構築するには、グローバルパネルビューは TServerPanelView クラスから継承され、グローバルパネルフォームは TServerPanelForm クラスから継承される必要があります。

TServerModule クラスには次の 3 つのフィールドを追加する必要があります:

  • パネルフォーム (TServerPanelForm)
  • パネルビュー (TServerPanelView)
  • パネルマネージャ(スタンドアロンクラスと、公開メソッドを持つそのインターフェース表現)。

TServermodule クラスに追加される 2 つのメソッド:

  • HandleNotification ハンドラ
  • CreateServerViews メソッド

TServerModule クラスに追加するプロパティ:

  • パネルマネージャオブジェクトを表す Panel Manager プロパティ

TServerPanelForm Object

TServerPanelForm コンストラクタでは、通知ハンドラがクライアントモジュールに登録され、self パラメータが渡されます。デストラクタでは通知ハンドラの登録を解除します。HandleNotification メソッドは、パネルが変更中かどうかを処理します。

TServerPanelView Object

通常、TServerPanelView オブジェクトはこのクラスから直接継承されるため、メソッドを追加またはオーバーライドする必要はありません。これらのメソッドは Altium Designer の Client システムによって処理されます。

The Panel manager Object

グローバルパネルを管理するために必要なメソッドをシステムに公開できるよう、Panel manager ユニット内にはマネージャのインターフェース表現が必要です。インターフェース表現はマネージャクラス内で定義され、そこにはパネルフォームフィールドとインターフェースメソッドが含まれます。パネルマネージャが作成されると、パネルフォームはこのマネージャオブジェクトに関連付けられ、パネルのフォームコントロールを更新できるようになります。

TServerModule Object

TServerModule コンストラクターでは、サーバーコマンドを登録する箇所で、グローバルパネルビューとパネルマネージャーを作成します。ここでは登録通知ハンドラーの設定も必要です。CreateServerViews メソッドには、グローバルパネルフォームと、このグローバルパネルフォームを使用して作成されたビューが含まれます。次に、このビューをサーバーモジュール(TServerModule.AddView() メソッド)とクライアント(Client.AddServerView メソッド)の両方に追加します。ServerModule デストラクターでは、パネルマネージャーを nil に設定し、通知ハンドラーの登録を解除します。

Installation file

インストールファイルは、グローバルパネルを反映するために新しい PanelInfo ブロックを追加するよう更新する必要があります。たとえば、

PanelInfo
Name = 'GraphicMessages'
Category = 'Graphic'
Bitmap = ''
Hotkey = 'M'
ButtonVisible = True
CanDockVertical = True
CanDockHorizontal = True
End

SDK フォルダー内の Graphic Viewer のサンプルを参照できます。

自分のパネルを PCB パネルに追加するにはどうすればよいですか?

必要なことは 2 つあります。

  1. 拡張プロジェクトにグローバルパネルを追加する
  2. PCB Editor のインストールファイル(advpcb.ins)に PanelInfo End ブロックを追加する。

例として、PCB Editor のインストールファイル(advpcb.ins)では次のようになります。

PanelInfo
    Name              = 'BoardInSight'
    Category          = '&PCB'                
    Bitmap            = ''                    
    Hotkey            = ''                   
    ButtonVisible     = True                  
    CanDockVertical   = True
    CanDockHorizontal = True
End

自分のファイルタイプ用の独自エディターを作成するにはどうすればよいですか?

独自のドキュメントタイプを編集するための独自エディターを作成するには、2 つの作業が必要です。

1. Server Module and its Documents in the Main.pas file

main.pas ユニットでは、サーバードキュメントクラスとサーバーモジュールクラスを定義および実装します。このユニットではサーバープロセスも定義および実装され、これらのサーバープロセスに対応する interfaces ユニットも定義されてリンクされます。ServerFactory 関数は、関連付けられたグラフィックドキュメントが読み込まれる際に、Altium Designer 内の Client モジュールによって(1 回だけ)呼び出されます。つまり、Graphic Viewer サーバーは一度だけメモリに読み込まれます。

この main.pas ユニットでは、TServerModule クラスと TServerDocument クラスの 2 つのクラスを扱います。

TServerModule クラスは継承されて TGraphicViewerModule クラスへ拡張されます。TServerDocument は継承されて TGraphicDocument クラスへ拡張されます。

TServerDocument クラスは、プロセスの実装、パネルとビューの制御、およびファイルの保存/読み込みメソッドを実装します。プロセスは main.pas ユニットで宣言され、インターフェースは commands.pas ユニットで実装されます。

 SDK インストールの \Examples\GraphicViewer\ フォルダーにある GraphicViewer の Main.pas ファイルを参照してください。

2. You need to specify the EditorWindowKind blocks in your editor’s installation file.

各ドキュメント種別は、この EditorWindowKind ブロックで表されます。また、各 EditorWindowKind ブロック内に LoadFilters および SaveFilters サブブロックを指定する必要があります。

SDK フォルダー内の Graphic Viewer のサンプルを参照できます。

 

AI-LocalizedAI で翻訳
問題が見つかった場合、文字/画像を選択し、Ctrl + Enter キーを押してフィードバックをお送りください。
Content