1 //#************************************************************** 2 //# filename: WinCompDriverInterface.h 3 //# 4 //# author: Yury Vetyukov, Johannes Gerstmayr 5 //# 6 //# generated: 2003 7 //# description: 8 //# remarks: 9 //# 10 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian 11 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the 12 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved. 13 //# 14 //# This file is part of HotInt. 15 //# HotInt is free software: you can redistribute it and/or modify it under the terms of 16 //# the HOTINT license. See folder 'licenses' for more details. 17 //# 18 //# bug reports are welcome!!! 19 //# WWW: www.hotint.org 20 //# email: bug_reports@hotint.org or support@hotint.org 21 //#*************************************************************************************** 22 23 /* 24 This is an interface class between an OS-independent working (computational) module 25 of an application and an OS-dependent driving module of an application. 26 27 Architecture: 28 The working module of the program contains a class, derived from WCDInterface. 29 A function creating dynamically an object of this kind (working object) 30 WCDInterface * CreateWCDObject(); 31 must be available to the driving module. A pointer to the created working object 32 is returned. In Windows the working module can be compiled into a standalone 33 DLL, which exports the function CreateWCDObject(). 34 35 The driving module is linked (statically or dynamically) to the working module. 36 After the application is initialized, the function CreateWCDObject() is called 37 and the main object of the working module is created. 38 39 The interface WCDInterface allows direct calls, when something is needed from 40 the working module. The working module performes OS-dependent actions via 41 the feed-back interfaces, provided by the driving module. 42 43 The multithreading of the application is handled in the driving module. 44 Initially only the user interface thread exists. As the computation starts, 45 the working thread is initiated. 46 47 --------------- ---------------- 48 | working | | ------------ | 49 | object |-------->| |feed-back | | 50 | | | |interfaces| | 51 | ----------- | calls | ------------ | 52 | |interface| |<--------| driving | 53 | ----------- | | module | 54 --------------- ---------------- 55 */ 56 57 //#include "tarray.h" 58 //#include "mystring.h" 59 //#include "elementdata.h" 60 //#include "FieldVariableDescriptor.h" 61 #include "mbs_interface.h" 62 #include "ElementsAndModelsLibraryInterface.h" 63 #include "hotint_version_info.h" 64 65 66 #ifndef __WCD_INTERFACE_H_INCLUDED__ 67 #define __WCD_INTERFACE_H_INCLUDED__ 68 69 70 #define WORKING_OBJECT_CREATION_FUNCTION_NAME "CreateWCDObject" 71 #ifdef COMPILE_AND 72 #define WORKING_DLL_NAME "WorkingModuleHOTINT.dll" 73 #else 74 #define WORKING_DLL_NAME "WorkingModule.dll" 75 #endif 76 //#define HOTINT_PUBLIC_DOMAIN 77 78 79 80 81 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 82 // This version of the interface is designed for the 3D scenes 83 84 #include "renderContext.h" 85 86 struct WCDInterface 87 { ~WCDInterfaceWCDInterface88 virtual ~WCDInterface() 89 { 90 } 91 92 // FEED-BACK INTERFACES 93 // these interfaces are provided by the driving module in order to perform 94 // the OS-dependent actions. The working module operates with pointers to these objects, 95 // which are implemented in the driving module. 96 97 // bringing INFORMATION to the user 98 struct UserInterface 99 { ~UserInterfaceWCDInterface::UserInterface100 virtual ~UserInterface() {} 101 // message box; does not return until the user responds 102 virtual void InstantMessageText(const char * ) = 0; 103 // set text on something like status bar 104 virtual void StatusText(const char * ) = 0; 105 // log-file or text running on the screen like in the console window; '\n' means end-of-line 106 virtual void AddText(const char * ) = 0; 107 // if the text-running window has been switch off, this command will switch it on 108 virtual void AssureTextIsVisible() = 0; 109 110 // create directory (only, if it does not exist). 111 // returns 0 in case of error (wrong path), 1 in case it already existed, and 2 if created 112 virtual int CreateMissingDirectory(const char * ) = 0; 113 114 //call a function in WCDriver: 115 virtual int CallWCDriverFunction(int action, int option = 0, int value = 0, ElementDataContainer* edc = NULL) = 0; 116 117 //go to sleep for x milliseconds 118 virtual void SleepX(int xMilliseconds) = 0; 119 120 //is used in MBS::PreComputationOperations 121 virtual int GetModelModified() const = 0; 122 }; 123 124 // these methods are available as the COMPUTATION procedure starts 125 struct ComputationFeedBack 126 { 127 // informs the driving module that the scene must be repainted 128 virtual void ResultsUpdated(int flag=0) = 0; 129 // informs the driving module that the computation is paused 130 virtual void PausedComputation() = 0; 131 // informs the driving module that the computation is finished 132 virtual void FinishedComputation() = 0; 133 // AH: informs the driving module that new data is sent to plottool 134 }; 135 136 // DIRECT calls from the driving module to the working object 137 // these methods must be implemented in the working module 138 139 // the driving module will give the working module a pointer to the 140 // UserInterface interface immediately after the working object is created; 141 // and the text output can be done starting from this point 142 virtual void SetUserInterface(UserInterface* ) = 0; 143 virtual UserInterface* GetUserInterface() const = 0; 144 145 // the maximal absolute value of a coordinate in the scene 146 // the function is called once when the graphic system is initialized 147 virtual float GetSceneMaxAbsCoordinate() = 0; 148 // if the scene is in fact plane, it might be useful 149 // to prevent the user from rotating it 150 virtual int AllowRotation() = 0; 151 // tells the working module to execute all the painting instructions 152 // for the currently provided RenderContext 153 virtual void RenderScene(RenderContext * pRC) = 0; 154 155 // Sets the Pointer to the Dialog in the 156 virtual void RenderControlWindow(ControlWindowContext* pCWC) = 0; //!AD: 2012-12-13 157 158 // prints data to the UserInterface context on the user request 159 virtual void PrintData(const char * pDataSpecification) = 0; 160 161 // start the computation from the current position 162 // this function is run in a separate (working) thread 163 // and should return only when the computation is stopped 164 // the ComputationFeedBack interface should be used to inform the driving module 165 // about the progress in the computation; the UserInterface can be also used 166 virtual void Go(ComputationFeedBack * pCFB) = 0; 167 virtual void SetPCFB(ComputationFeedBack * p_cfb) = 0; 168 169 170 //call initialize function after config file loaded: 171 virtual void InitializeAfterConfigLoaded() = 0; 172 173 // check if the computation is still in progress 174 virtual int IsComputationInProgress() = 0; 175 176 // tells to stop the computation when possible 177 virtual void StopWhenPossible() = 0; 178 179 // reset computation, new computation is started with new initial conditions at starttime 180 virtual void ResetComputation() = 0; 181 182 // returns if calculation is paused 183 virtual int IsPaused() = 0; 184 185 // tells to pause the computation 186 virtual void Pause() = 0; 187 188 // tells to resume the computation 189 virtual void Resume() = 0; 190 191 // print timing statistics 192 virtual void PrintTimingList() = 0; 193 194 //old options: 195 virtual void SetIOption(int index, int data) = 0; 196 virtual const int& GetIOption(int index) const = 0; 197 virtual int& GetIOption(int index) = 0; 198 virtual void SetDOption(int index, double data) = 0; 199 virtual const double& GetDOption(int index) const = 0; 200 virtual double& GetDOption(int index) = 0; 201 virtual void SetTOption(int index, const char* data) = 0; 202 virtual const char* GetTOption(int index) const = 0; 203 204 //new options: 205 //get values in MBS_EDC: 206 virtual void MBS_EDC_TreeGetDouble(double& data, const char* name) const = 0; 207 virtual void MBS_EDC_TreeGetInt(int& data, const char* name) const = 0; 208 virtual const char* MBS_EDC_TreeGetString(const char* name) const = 0; 209 //set values in MBS_EDC: 210 virtual void MBS_EDC_TreeSetDouble(double data, const char* name) = 0; 211 virtual void MBS_EDC_TreeSetInt(int data, const char* name) = 0; 212 virtual void MBS_EDC_TreeSetString(const char* data, const char* name) = 0; 213 214 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 215 //exchange data: elements, MBS-System 216 virtual int GetNElements() const = 0; 217 virtual void GetElementData(int i, int type, int value, ElementDataContainer& edc) = 0; 218 virtual int SetElementData(int i, int type, int value, ElementDataContainer& edc) = 0; 219 220 //$AD 2013-07-08: Manipulate Content of arrays in IOElements from 2D Draw Window 221 virtual void InsertIOElemConNode(int elemnr, int list_idx, int input_nr, Vector2D pos) = 0; 222 virtual void DeleteIOElemConNode(int elemnr, int list_idx) = 0; 223 //$AD 2013-07-10: Change Position of a single element (MBS element, conNode, ...) 224 virtual void MoveConNode2D(int elemnr, int list_idx, double delta_x, double delta_y) = 0; 225 virtual void MoveElement(int elemnr, double delta_x, double delta_y, double delta_z = 0.) = 0; 226 //$ YV 2012-11-29: commented out, these functions go into the general MBS interface 227 //virtual const class CMBSParser& MBSParser() const = 0; 228 //virtual class CMBSParser& MBSParser() = 0; 229 230 virtual int CallCompFunction(int action, int option = 0, int value = 0, ElementDataContainer* edc = NULL) = 0; 231 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 232 // access functions for Sensor / PlotTool (Plottool has no classes MBS, Sensor, etc included) 233 virtual TArray<double>* GetSensorValuesArrayPtr(int i) = 0; // get the i-th sensors (as registered in mbs) own stored values from internal array 234 virtual TArray<double>* GetSensorTimesArrayPtr(int i) = 0; // get the i-th sensors (as registered in mbs) own stored times from internal array GetSensorNameWCDInterface235 virtual mystr GetSensorName(int i) {return 0;}; // get the i-th sensors (as registered in mbs) name GetSensorNumberWCDInterface236 virtual int GetSensorNumber(mystr& name) {return 0;}; // get the number of the (first) sensor that matches the sensorname 237 238 // user interface part of the software needs access to the object factory 239 virtual MBSObjectFactoryInterface * GetObjectFactory() = 0; 240 241 // handling of variable types for post-processing (contour plotting) 242 virtual const TArray<FieldVariableDescriptor> & GetAvailableFieldVariables() = 0; 243 virtual int GetIndexOfActualPostProcessingFieldVariable() = 0; 244 virtual void SetIndexOfActualPostProcessingFieldVariable(int index) = 0; 245 246 // these two structures are responsible for the streamed data storage/loading 247 struct DataSaver 248 { 249 virtual void SetTime(double time) = 0; 250 virtual DataSaver & operator << (int) = 0; 251 virtual DataSaver & operator << (double) = 0; 252 // this function accepts a pointer to a C-style zero terminated string 253 virtual DataSaver & operator << (const char *) = 0; 254 }; 255 256 struct DataLoader 257 { 258 virtual double GetTime() = 0; // should be called before other 259 // data reading operations 260 virtual DataLoader & operator >> (int &) = 0; 261 virtual DataLoader & operator >> (double &) = 0; 262 // here the working module obtains a new pointer to 263 // the the string is C-style zero terminated string char * p, 264 // so that delete[] p should be executed afterwards 265 virtual DataLoader & operator >> (char * & p) = 0; 266 }; 267 268 // these functions are due to the data storage 269 // after each call of ComputationFeedBack::ResultsUpdated() 270 // the function StoreResultsIsOn() is called to check if the results should be stored 271 virtual int StoreResultsIsOn() = 0; 272 // here the working object should remove all saved states 273 virtual int RemoveResults() = 0; 274 // here the working object should save its actual state 275 virtual void StoreResults(DataSaver & storage, double& m_TimePoint) = 0; 276 // here the working object should replace its actual state with the one from the DataLoader 277 // the function is called from the driving module with the user request 278 virtual void LoadResults(DataLoader & loader, int m_TimePointNumber) = 0; 279 // this function returns the actual drawing time 280 virtual double GetActualDrawTime() const = 0; 281 // this function returns the number of stored solution data files 282 virtual int ReadSolDataInfo() = 0; 283 // here the current version of Hotint is returned 284 // this is particularly needed for validation of config files or data sets GetHotintVersionWCDInterface285 virtual const HotintVersionInfo& GetHotintVersion() const {return hotint_version;}; 286 SetModelData_InitializedWCDInterface287 virtual void SetModelData_Initialized(int flag) {}; 288 289 }; 290 291 #endif // __WCD_INTERFACE_H_INCLUDED__