1 //#***************************************************************************************
2 //# filename:     MBSModelsLibrary.cpp
3 //#
4 //# author:				Johannes Gerstmayr, Yuri Vetyukov
5 //#
6 //# generated:
7 //# description:
8 //#
9 //# comments:
10 //#
11 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian
12 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the
13 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved.
14 //#
15 //# This file is part of HotInt.
16 //# HotInt is free software: you can redistribute it and/or modify it under the terms of
17 //# the HOTINT license. See folder 'licenses' for more details.
18 //#
19 //# bug reports are welcome!!!
20 //# WWW:		www.hotint.org
21 //# email:	bug_reports@hotint.org or support@hotint.org
22 //#***************************************************************************************
23 
24 #include "MBSModelsLibrary.h"
25 
26 // these pointers to global variables need to be set from the kernel
27 UserOutputInterface * global_uo;
28 extern TArray<double> * ptrTMtspent;
29 extern TArray<double> * ptrTMtstart;
30 
31 #ifdef gencnt
32 int *genvec;
33 int *genmat;
34 #endif
35 
SetGlobalVariablesPointers(UserOutputInterface * global_uo_kernel,TArray<double> * ptrTMtspent_kernel,TArray<double> * ptrTMtstart_kernel)36 void MBSModelsLibrary::SetGlobalVariablesPointers(
37 		UserOutputInterface * global_uo_kernel,
38 		TArray<double> * ptrTMtspent_kernel,
39 		TArray<double> * ptrTMtstart_kernel
40 		)
41 {
42 	global_uo = global_uo_kernel;
43 	ptrTMtspent = ptrTMtspent_kernel;
44 	ptrTMtstart = ptrTMtstart_kernel;
45 }
46 #ifdef gencnt
SetGlobalVariablesPointers(UserOutputInterface * global_uo_kernel,TArray<double> * ptrTMtspent_kernel,TArray<double> * ptrTMtstart_kernel,int * global_genvec,int * global_genmat)47 void MBSModelsLibrary::SetGlobalVariablesPointers(
48 		UserOutputInterface * global_uo_kernel,
49 		TArray<double> * ptrTMtspent_kernel,
50 		TArray<double> * ptrTMtstart_kernel,
51 		int *global_genvec,
52 		int *global_genmat
53 		)
54 {
55 	global_uo = global_uo_kernel;
56 	ptrTMtspent = ptrTMtspent_kernel;
57 	ptrTMtstart = ptrTMtstart_kernel;
58 	genvec = global_genvec;
59 	genmat = global_genmat;
60 }
61 #endif
62 
MBSModelsLibrary(void)63 MBSModelsLibrary::MBSModelsLibrary(void)
64 {
65 }
66 
~MBSModelsLibrary(void)67 MBSModelsLibrary::~MBSModelsLibrary(void)
68 {
69 	for(int i = 1; i <= GetModelsCount(); i++)
70 		delete GetModelInterface(i);
71 }
72 
AddModel(MBSModelInterface * model)73 void MBSModelsLibrary::AddModel(MBSModelInterface * model)
74 {
75 	modelsLibrary.models.Add(model);
76 }
77 
78 // there is a global models library object, which needs to be created before the particular model objects
79 #pragma warning(disable:4074)
80 #pragma init_seg(compiler)
81 MBSModelsLibrary modelsLibrary;
82 
83 // first we implement the old functionality with function pointers
84 struct ModelDataWrapperOldFnPointers : MBSModelsLibraryInterface::MBSModelInterface
85 {
86 	mystr modelName;
87 	mystr modelDescription;
88 	int(*function_ptr)(MBS* mbs);
89 	int(*function_ptr_init_modeldata)(MBS* mbs);
90 
GetMBSModelNameModelDataWrapperOldFnPointers91 	virtual mystr & GetMBSModelName() { return modelName; }
GetMBSModelDescriptionModelDataWrapperOldFnPointers92 	virtual mystr & GetMBSModelDescription() { return modelDescription; }
CreateMBSModelModelDataWrapperOldFnPointers93 	virtual int CreateMBSModel(MBS * mbs) { return function_ptr(mbs); }
HasMBSModelInitDataModelDataWrapperOldFnPointers94 	virtual bool HasMBSModelInitData() { return function_ptr_init_modeldata != NULL; }
InitializeMBSModelDataModelDataWrapperOldFnPointers95 	virtual int InitializeMBSModelData(MBS * mbs) { return function_ptr_init_modeldata(mbs); }
96 };
97 
ModelFunctionAutoRegistration(int (* function_ptr)(MBS * mbs),const char * functionName,const char * description,int option,int (* function_ptr_init_modeldata)(MBS * mbs))98 void ModelFunctionAutoRegistration(int(*function_ptr)(MBS* mbs), const char* functionName, const char* description, int option,
99 																	 int(*function_ptr_init_modeldata)(MBS* mbs))
100 {
101 	ModelDataWrapperOldFnPointers * model = new ModelDataWrapperOldFnPointers;
102 	model->function_ptr = function_ptr;
103 	model->function_ptr_init_modeldata = function_ptr_init_modeldata;
104 	model->modelName = functionName;
105 	model->modelDescription = description;
106 
107 	modelsLibrary.AddModel(model);
108 }