1 //#*************************************************************************************** 2 //# filename: MBSObjectFactory.h 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 #pragma once 25 #include "elementsandmodelslibraryinterface.h" 26 27 class MBSObjectFactory : public MBSObjectFactoryInterface 28 { 29 struct ObjectTypeInfo 30 { 31 mystr name; // name of the object, e.g. Rigid3D 32 int flags; // flags - characteristic properties of the type (e.g. constraint or not, 2D/3D for elements) 33 mystr description; // tex description for the docu 34 mystr example; // example file for the docu 35 36 void operator=(const ObjectTypeInfo & oti) 37 { 38 name = oti.name; 39 description = oti.description; 40 flags = oti.flags; 41 example = oti.example; 42 } ObjectTypeInfoObjectTypeInfo43 ObjectTypeInfo() : flags(0) {} ObjectTypeInfoObjectTypeInfo44 ObjectTypeInfo(const ObjectTypeInfo & oti) 45 { 46 *this = oti; 47 } 48 ObjectTypeInfo(char * name, int flags, char * example, char * description); 49 }; 50 51 // first index (outer array) - class 52 // second index (inner array) - type id 53 TArrayDynamic<TArrayDynamic<ObjectTypeInfo>> objectTypeInfos; 54 55 MBS * mbs; 56 57 // adding objects of particular classes 58 int AddElement(int objectTypeId); 59 int AddSensor(int objectTypeId); 60 int AddLoad(int objectTypeId); 61 int AddMaterial(int objectTypeId); 62 int AddBeamProperties(int objectTypeId); 63 int AddNode(int objectTypeId); 64 int AddGeomElement(int objectTypeId); 65 66 // initialization of object type infos is performed in constructor; 67 // first the automatically generated part is called 68 void AddObjectInfos_Auto(); 69 // this function adds a new object type info entry 70 void AddObjectInfo(MBSObjectFactoryClass objectClass, char * name, int flag, char * example, char * description); 71 GetMBS()72 MBS * GetMBS() { return mbs; } 73 74 public: 75 MBSObjectFactory(void); 76 ~MBSObjectFactory(void); SetMBS(MBS * mbs)77 virtual void SetMBS(MBS * mbs) { this->mbs = mbs; } 78 79 // these functions add objects of a given class and type to mbs 80 // the number in the corresponding array in mbs (numerical identificator) is returned 81 // or -1 if no object could be added 82 virtual int AddObject(MBSObjectFactoryClass objectClass, int objectTypeId); 83 // available range types: maximal value of objectType for a given class GetAvailableTypesCount(MBSObjectFactoryClass objectClass)84 virtual int GetAvailableTypesCount(MBSObjectFactoryClass objectClass) { return objectTypeInfos(objectClass).Length(); } 85 // name of an object type id and object type id for a given name (if exists, otherwise -1) GetTypeName(MBSObjectFactoryClass objectClass,int objectTypeId)86 virtual const mystr & GetTypeName(MBSObjectFactoryClass objectClass, int objectTypeId) { return objectTypeInfos(objectClass)(objectTypeId).name; } 87 virtual int GetObjectTypeId(MBSObjectFactoryClass objectClass, const mystr & typeName); 88 // description for the documentation and for the user interface GetTypeDescription(MBSObjectFactoryClass objectClass,int objectTypeId)89 virtual const mystr & GetTypeDescription(MBSObjectFactoryClass objectClass, int objectTypeId) { return objectTypeInfos(objectClass)(objectTypeId).description; } 90 // flags - characteristic properties of the type (e.g. constraint or not, 2D/3D for elements) GetTypeFlags(MBSObjectFactoryClass objectClass,int objectTypeId)91 virtual int GetTypeFlags(MBSObjectFactoryClass objectClass, int objectTypeId) { return objectTypeInfos(objectClass)(objectTypeId).flags; } 92 // example of the type in skript language GetTypeExample(MBSObjectFactoryClass objectClass,int objectTypeId)93 virtual mystr GetTypeExample(MBSObjectFactoryClass objectClass, int objectTypeId) { return objectTypeInfos(objectClass)(objectTypeId).example; } 94 // if this function returns 1, then all experimental elements are removed from Hotint ExcludeExperimentalObjects()95 virtual int ExcludeExperimentalObjects() { 96 #ifdef __EXCLUDE_EXPERIMENTAL_OBJECTS__ 97 return 1; 98 #else 99 return 0; 100 #endif 101 } 102 103 }; 104 105 // there is a global object factory object 106 extern MBSObjectFactory objectFactory;