BIM Link Example Configure PluginFactory - idea-statica/ideastatica-public GitHub Wiki
Configure the Rstab Plugin Factory
The PluginFactory
class inherits from the IBIMPluginFactory
. This interface is stored in the IdeaStatiCa.Plugin package.
- The license lock is specific to Rstab, although other programs may have a similar concept. This basically allows us to manage the state of the model at a higher level or to ensure the model is available for use.
The Create()
tells us a lot about the different provides and classes we will need to set up in the following steps. As a programmer of a plugin, we should also be able to define here the backbone of the requirements we will need to enable testing of the plugin. For example, we may neglect the load's provider or results provider in the first instance to concentrate on the import of geometry.
using Dlubal.RSTAB8;
using IdeaRstabPlugin.BimApi;
using IdeaRstabPlugin.Factories;
using IdeaRstabPlugin.Geometry;
using IdeaRstabPlugin.Providers;
using IdeaStatiCa.Plugin;
using System.IO;
namespace IdeaRstabPlugin
{
public class PluginFactory : IBIMPluginFactory
{
public string FeaAppName => "RSTAB";
public string IdeaStaticaAppPath
{
get
{
string ideaInstallDir = string.Empty;
#if PUBLIC
// get installation directory from windosw registry
ideaInstallDir = IdeaStatiCa.Plugin.Utilities.IdeaStatiCaSetupTools.GetIdeaStatiCaInstallDir(Constants.IdeaStatiCaVersion);
#else
// the plugin is located in installation directory of IdeaStatiCa
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
ideaInstallDir = Path.GetDirectoryName(assembly.Location);
#endif
return Path.Combine(ideaInstallDir, Constants.CheckbotAppName);
}
}
public string WorkingDirectory { get; }
private readonly IModel _model;
private readonly IPluginLogger _logger;
public PluginFactory(IModel model, IPluginLogger pluginLogger)
{
_model = model;
_logger = pluginLogger;
WorkingDirectory = Path.Combine(Path.GetDirectoryName(_model.GetPath()), "IdeaStatiCa-" + _model.GetName());
if (!Directory.Exists(WorkingDirectory))
{
Directory.CreateDirectory(WorkingDirectory);
}
}
public IApplicationBIM Create()
{
using (new LicenceLock(_model))
{
ImportSession importSession = new ImportSession(_model);
ModelDataProvider modelDataProvider = new ModelDataProvider(_model);
LinesAndNodes linesAndNodes = new LinesAndNodes(modelDataProvider);
LoadsProvider loadsProvider = new LoadsProvider(_model);
ResultsProvider resultsProvider = new ResultsProvider(loadsProvider, _model.GetCalculation());
ObjectFactory objectFactory = new ObjectFactory(_model, modelDataProvider, linesAndNodes, loadsProvider,
resultsProvider, importSession);
RstabGeometry geometry = new RstabGeometry(linesAndNodes, objectFactory);
RstabGeometryProvider geometryProvider = new RstabGeometryProvider(geometry);
ObjectRestorer objectRestorer = new ObjectRestorer(objectFactory, linesAndNodes);
RstabModel rstabModel = new RstabModel(_model, linesAndNodes, objectFactory, loadsProvider, importSession);
RstabApplication application = new RstabApplication(_logger, rstabModel, objectRestorer, geometryProvider,
resultsProvider, importSession, WorkingDirectory);
application.AddDataCache(modelDataProvider);
application.AddDataCache(loadsProvider);
application.AddDataCache(objectFactory);
application.AddDataCache(resultsProvider);
return application;
}
}
}
}
Code of the license lock file:
using Dlubal.RSTAB8;
using System;
namespace IdeaRstabPlugin
{
internal class LicenceLock : IDisposable
{
private readonly IApplication _application;
public LicenceLock(IModel model)
{
_application = model.GetApplication();
_application.LockLicense();
}
public void Dispose()
{
_application.UnlockLicense();
}
}
}