Create __init__ method for CST_MicrowaveStudio class
The API will be based on a class CST_MicrowaveStudio, which will contain as one of its instance attributes a handle to a COM object controlling the desired CST project. This class will have several methods for performing certain actions on the project. Each of this actions will be carried out on CST thanks to the use of VBA commands through the COM object.
As an initial step, lets define an \__init_\_ method that launches CST and either opens a project given by the user or (if no project is specified) creates a new empty project.
## Useful resources
<details>
<summary>Example in Matlab</summary>
```Matlab
function obj = CST_MicrowaveStudio(folder,filename)
%CST_MicrowaveStudio with no input parameters will construct an
% instance of CST_MicrowaveStudio related to the currently open
% project in CST.
%
% CST_MicrowaveStudio(folder,filename) will either create a new
% CST mws project, or will open an existing project (if it
% exists).
%
% Examples:
% To create a new microwave studio project
% CST = CST_MicrowaveStudio(cd,'New_MWS_Simulation.cst');
%
% CST = CST_MicrowaveStudio; %Return the currently active MWS
% project
if nargin == 0
%Get the current MWS session
obj.CST = actxserver('CSTStudio.application');
obj.mws = obj.CST.Active3D;
if isempty(obj.mws)
error('CSTMicrowaveStudio:NoFileOpen',...
'I tried to return the active microwave studio session, but it appears that no proects are currently open');
end
[obj.folder,obj.filename] = fileparts(obj.mws.invoke('GetProjectPath','Project'));
obj.installMacros; %Check for and install new macros if new download has happened
fprintf('CST_MicrowaveStudio Successfully opened. Active microwave studio project is:\n%s\\%s.cst\n',obj.folder,obj.filename)
return
end
obj.folder = folder;
%Ensure file has .cst extension.
[~,filename,ext] = fileparts(filename);
if ~isempty(ext)
if ~strcmpi('.cst',ext)
error('CST_MicrowaveStudio:wrongFileExtension','File extension must be .CST')
end
end
obj.filename = filename;
ff = fullfile(obj.folder,[obj.filename,ext]);
if exist(ff,'file') == 2
%If file exists, open
[obj.CST,obj.mws] = CST_MicrowaveStudio.openFile(obj.folder,[obj.filename,ext]);
fprintf('Microwave studio project was successfully opened\n')
else %Create a new MWS session
%Create a directory in 'folder' called
%CST_MicrowaveStudio_Files which is added to .gitignore
fprintf('Creating new microwave studio session\n');
dirstring = fullfile(obj.folder,'CST_MicrowaveStudio_Files');
obj.folder = dirstring;
obj.CST = actxserver('CSTStudio.application');
obj.mws = obj.CST.invoke('NewMWS');
% For Future Version - allow user to store some values as
% object properties, such as the frequency, which update in the
% MWS model whenever they are updated in Matlab
% obj.listeners = addlistener(obj,{'F1','F2'},'PreSet',@obj.setFreqListenerResp);
%Set up some default simulation parameters:
obj.defineUnits;
obj.setFreq(1,10);
%Boundaries:
VBA = sprintf(['With Boundary\n',...
'.Xmin "expanded open"\n',...
'.Xmax "expanded open"\n',...
'.Ymin "expanded open"\n',...
'.Ymax "expanded open"\n',...
'.Zmin "expanded open"\n',...
'.Zmax "expanded open"\n',...
'End With',...
]);
obj.mws.invoke('addToHistory','define boundaries',VBA);
VBA = sprintf(['With Material\n',...
'.Type "Normal\n',...
'.Colour "0.6", "0.6", "0.6"\n',...
'.Epsilon "1"\n',...
'.Mu "1"\n',...
'.ChangeBackgroundMaterial\n',...
'End With',...
]);
obj.mws.invoke('addToHistory','Set Background Material',VBA);
%Turn off the the working plane (which isnt needed for programatic control of CST)
plot = obj.mws.invoke('plot');
plot.invoke('DrawWorkplane','false');
end
obj.installMacros; %Check for and install new macros if new download has happened
end
```
</details>
The Matlab implementation uses the function fileparts() to separate the path, filename and extension of a file. Similar functionality can be obtained in Python thanks to the module [os.path](https://docs.python.org/3/library/os.path.html): [Additional examples](https://note.nkmk.me/en/python-os-basename-dirname-split-splitext/).
issue