Diana
0.8.3
|
00001 /* ----------------------------------------------------------------------------- 00002 * Diana process modelling, simulation and analysis software 00003 * Copyright (c) 2005, Michael Krasnyk, Alexey Milokhov 00004 * All rights reserved. 00005 * 00006 * This file is a part of Diana process modelling, simulation and analysis software 00007 * 00008 * Diana is free software; you can redistribute it and/or modify it 00009 * under the terms of the GNU General Public License as published 00010 * by the Free Software Foundation (see accompanying file LICENSE) 00011 * ----------------------------------------------------------------------------- 00012 * $Id: DianaReporting.hpp 8909 2009-10-29 13:01:45Z miha $ 00013 * ----------------------------------------------------------------------------- 00014 * Description: 00015 */ 00016 00017 #ifndef DIANA_REPORTING_H 00018 #define DIANA_REPORTING_H 00019 00020 #include <CapeOpen.hpp> 00021 #include <Diana/IDianaReporting.hpp> 00022 00023 #include <map> 00024 #include <stdio.h> 00025 00026 namespace Diana { 00027 00028 00029 typedef std::vector<Common::Types::CapeArrayDouble> ReportDataEntryValues; 00030 00031 class ReportDataEntry { 00032 public: 00033 ReportDataEntry(Common::Parameter::ICapeParameter *referencedParameter); 00034 ReportDataEntry(Common::Parameter::ICapeParameter *referencedParameter, const ReportDataEntry& templ); 00035 void StoreValue(); 00036 void StartNewChunk(); 00037 ReportDataEntryValues* GetValues(); 00038 const Common::Types::CapeArrayDouble& operator[](const Common::Types::CapeLong index); 00039 Common::Types::CapeLong size() const; 00040 Common::Types::CapeString name() const; 00041 Common::Parameter::CapeParamType type() const; 00042 void clear(); 00043 private: 00044 ReportDataEntryValues values; 00045 Common::Parameter::ICapeParameter *parameter; 00046 }; 00047 00048 00049 // defines internal communication between reporting interface and solver 00050 class MemoryReportingInterface : virtual public IDianaReporting { 00051 protected: 00053 std::map<Common::Parameter::ICapeParameter*, Common::Types::CapeLong> pmap; 00054 std::vector<ReportDataEntry> values; 00055 00056 Diana::IDianaNumericSolver* solver; 00057 Common::Types::CapeString name; 00058 Common::Types::CapeString description; 00059 00060 Diana::DianaCollection collParameters; 00061 public: 00062 MemoryReportingInterface(); 00063 ~MemoryReportingInterface(); 00064 00066 const Common::Types::CapeString& GetComponentName() const 00067 throw (Common::Error::ECapeUnknown); 00068 00071 void SetComponentName(const Common::Types::CapeString& _name) 00072 throw (Common::Error::ECapeUnknown, Common::Error::ECapeInvalidArgument); 00073 00075 const Common::Types::CapeString& GetComponentDescription() const 00076 throw (Common::Error::ECapeUnknown); 00077 00080 void SetComponentDescription(const Common::Types::CapeString& _description) 00081 throw (Common::Error::ECapeUnknown, Common::Error::ECapeInvalidArgument); 00082 00083 void Add(Common::Parameter::ICapeParameter *_parameter) 00084 throw (Common::Error::ECapeUnknown); 00085 00086 Common::Types::CapeLong getIndexByItem(Common::Parameter::ICapeParameter *_parameter) 00087 throw (Common::Error::ECapeUnknown); 00088 00089 void Remove(Common::Parameter::ICapeParameter *_parameter) 00090 throw (Common::Error::ECapeUnknown); 00091 00092 void Remove(Common::Types::CapeLong index) 00093 throw (Common::Error::ECapeUnknown); 00094 00095 void ClearData() 00096 throw (Common::Error::ECapeUnknown); 00097 00098 void StartNewChunk() 00099 throw (Common::Error::ECapeUnknown); 00100 00101 void WriteData(const Common::Types::CapeString& filename, const Common::Types::CapeString& format="") 00102 throw (Common::Error::ECapeUnknown); 00103 00104 void WriteDataMatlab(const Common::Types::CapeString& filename) 00105 throw (Common::Error::ECapeUnknown); 00106 00107 void WriteDataPlain(const Common::Types::CapeString& filename) 00108 throw (Common::Error::ECapeUnknown); 00109 00110 void WriteDataCSV(const Common::Types::CapeString& filename) 00111 throw (Common::Error::ECapeUnknown); 00112 00122 Common::Collection::ICapeCollection* GetParameters() 00123 throw (Common::Error::ECapeUnknown, Common::Error::ECapeFailedInitialisation, 00124 Common::Error::ECapeNoImpl); 00125 00139 void SetSimulationContext(Common::Identification::ICapeIdentification* simContextManager) 00140 throw (Common::Error::ECapeUnknown, Common::Error::ECapeInvalidArgument, 00141 Common::Error::ECapeFailedInitialisation, Common::Error::ECapeNoImpl); 00142 00155 void Initialize() 00156 throw (Common::Error::ECapeUnknown, Common::Error::ECapeFailedInitialisation, 00157 Common::Error::ECapeOutOfResources, Common::Error::ECapeLicenceError, 00158 Common::Error::ECapeBadInvOrder); 00159 00168 void Terminate() 00169 throw (Common::Error::ECapeUnknown, Common::Error::ECapeOutOfResources, 00170 Common::Error::ECapeBadInvOrder); 00171 00172 protected: 00173 ReportDataEntry* getItem(Common::Types::CapeLong index) 00174 throw (Common::Error::ECapeUnknown); 00175 00176 ReportDataEntry* getItem(Common::Parameter::ICapeParameter *_parameter) 00177 throw (Common::Error::ECapeUnknown); 00178 00179 void shutdownReportingInterface(); 00180 00181 void setSolver(Diana::IDianaNumericSolver *_solver) 00182 throw (Common::Error::ECapeUnknown); 00183 00184 void addDimension() 00185 throw (Common::Error::ECapeUnknown); 00186 00187 protected: 00188 virtual void solverStart(); 00189 virtual void solverStep(); 00190 virtual void solverStop(); 00191 virtual void updateValues(); 00192 virtual void solverError(); 00193 00194 public: 00195 void onSolverEvent(SolverEvents event, IDianaNumericSolver* _solver) 00196 throw (Common::Error::ECapeUnknown, Common::Error::ECapeInvalidArgument, Common::Error::ECapeFailedInitialisation); 00197 }; 00198 00199 00200 00201 class Plot2D { 00202 public: 00203 Plot2D(Common::Parameter::ICapeParameter *_x, 00204 Common::Parameter::ICapeParameter *_y, 00205 Common::Types::CapeString _name); 00206 Common::Parameter::ICapeParameter* GetX(); 00207 Common::Parameter::ICapeParameter* GetY(); 00208 Common::Types::CapeString GetName(); 00209 private: 00210 Common::Parameter::ICapeParameter *x; 00211 Common::Parameter::ICapeParameter *y; 00212 Common::Types::CapeString name; 00213 }; 00214 00215 class GraphicalReportingInterface : public MemoryReportingInterface, virtual public IDianaGraphicReporting2 { 00216 public: 00217 virtual void Add2DPlot(Common::Parameter::ICapeParameter *_x, 00218 Common::Parameter::ICapeParameter *_y, 00219 Common::Types::CapeString name = Common::Types::CapeStringUNDEFINED); 00220 virtual void Add2DPlot(Plot2D plot); 00221 virtual void AddSurface(Common::Parameter::ICapeParameter *_x, 00222 Common::Parameter::ICapeParameter *_y, 00223 Common::Parameter::ICapeParameter *_z, 00224 Common::Types::CapeString name = Common::Types::CapeStringUNDEFINED); 00225 virtual void ClearAll2DPlots(); 00226 virtual void Show2DPlots() = 0; 00227 00228 virtual void SetMaxPoints(Common::Types::CapeLong _maxPoints); 00229 virtual void SetUpdateInterval(Common::Types::CapeDouble _period); 00230 virtual void Update() = 0; 00231 protected: 00232 std::vector<Plot2D> plots; 00233 Common::Types::CapeLong maxPoints; 00234 Common::Types::CapeDouble period; 00235 }; 00236 00237 class GNUPlotReportingInterface : virtual public GraphicalReportingInterface { 00238 public: 00239 GNUPlotReportingInterface(); 00240 virtual ~GNUPlotReportingInterface(); 00241 virtual void Show2DPlots(); 00242 virtual void Update(); 00243 private: 00244 FILE* plotPipe; 00245 void StartPlot(); 00246 void StopPlot(); 00247 void SendCommand(Common::Types::CapeString cmd); 00248 protected: 00249 void solverStop(); 00250 00251 }; 00252 00253 } 00254 00255 #endif // DIANA_REPORTING_H