OpenVSP API Documentation  3.38.0
CustomGeom.h
1 //
2 // This file is released under the terms of the NASA Open Source Agreement (NOSA)
3 // version 1.3 as detailed in the LICENSE file which accompanies this software.
4 //
5 
6 // CustomGeom.h:
7 // J.R Gloudemans
8 //
10 
11 /*
12 Three ways to create custom components:
13 1. Read from file with script attached
14 2. Create from GUI with script (preparsed) stored in local dir
15 3. Create from API with location of script
16 
17 Script:
18 
19 Init()
20 - Name & type & script_name
21 - Create/init parms
22 - Describe GUI
23 - Set num cuv_vec
24 
25 UpdateSurf()
26 - load crv_vecs based on parms
27 - Skin surfs over cuv_vecs
28 
29 CustomGeomMgr - store parsed scripts
30 
31 */
32 
33 
34 
35 #if !defined(VSPCUSTOMGEOM__INCLUDED_)
36 #define VSPCUSTOMGEOM__INCLUDED_
37 
38 #include "Defines.h"
39 #include "Geom.h"
40 #include "XSec.h"
41 #include "XSecSurf.h"
42 
43 #include <map>
44 using std::map;
45 
46 
47 //====Custom Geom Manager ====//
49 {
50 public:
51  static CustomGeomMgrSingleton& getInstance()
52  {
53  static CustomGeomMgrSingleton instance;
54  return instance;
55  }
56  static void Init() {}
57 
58  //==== Init Geom ====//
59  void InitGeom( const string& id, const string& module_name, const string& display_name );
60  void SetCurrCustomGeom( const string& id ) { m_CurrGeom = id; }
61  string GetCurrCustomGeom() { return m_CurrGeom; }
62 
63  void ReadCustomScripts( Vehicle* veh );
64  vector< GeomType > GetCustomTypes() { return m_CustomTypeVec; }
65 
66  //==== Adds A Parm To The Current Custom Geom - Return Index of The Added Parm ====//
67  string AddParm( int type, const string & name, const string & group );
68  string GetCustomParm( int index );
69 
70  //==== Add A Gui Device Constructor to Current Custom Geom - Gui Will Be Created By Custom Screen (if connected) ===//
71  int AddGui( int type, const string & label = string(), const string & parm_name = string(), const string & group_name = string(), double range = 10 );
72  vector< GuiDef > GetGuiDefVec( const string & geom_id );
73 
74  //==== Add Gui->Parm Pairing To Update Vec ====//
75  void AddUpdateGui( int gui_id, const string & parm_id );
76  vector< GuiUpdate > GetGuiUpdateVec();
77  bool CheckClearTriggerEvent( int gui_id );
78 
79  //==== Add XSec Surface To Current Geom - Return ID =====//
80  string AddXSecSurf();
81  void RemoveXSecSurf( const string& id );
82  void ClearXSecSurfs();
83  void SkinXSecSurf( bool closed_flag );
84  void TransformSurf( int index, Matrix4d & mat );
85  void CloneSurf( int index, Matrix4d & mat );
86 
87  //==== Surface Attribute (Wing, Fuse...) =====//
88  void SetVspSurfType( int type, int surf_id = -1 );
89 
90  //==== Surface Cfd type (NORM, NEGATIVE, TRANSPARENT) ====//
91  void SetVspSurfCfdType ( int type, int surf_id = -1);
92 
93  //==== Set Up Default Sources =====//
94  void SetupCustomDefaultSource( int type, int surf_index, double l1, double r1, double u1, double w1,
95  double l2 = 0, double r2 = 0, double u2 = 0, double w2 = 0 );
96  void ClearAllCustomDefaultSources();
97 
98  void SetCustomCenter( double x, double y, double z );
99 
100  //==== Custom XSecs Functions ====//
101  void SetCustomXSecLoc( const string & xsec_id, const vec3d & loc );
102  vec3d GetCustomXSecLoc( const string & xsec_id );
103  void SetCustomXSecRot( const string & xsec_id, const vec3d & rot );
104  vec3d GetCustomXSecRot( const string & xsec_id );
105 
106  //==== Append Cut Copy Paste Insert ====//
107  string AppendCustomXSec( const string & xsec_surf_id, int type );
108  void CutCustomXSec( const string & xsec_surf_id, int index );
109  void CopyCustomXSec( const string & xsec_surf_id, int index );
110  void PasteCustomXSec( const string & xsec_surf_id, int index );
111  string InsertCustomXSec( const string & xsec_surf_id, int type, int index );
112 
113  //==== Get All Custom Script Module Name ====//
114  vector< string > GetCustomScriptModuleNames();
115 
116  //==== Save Custom Script Content To File ====//
117  static int SaveScriptContentToFile( const string & module_name, const string & file_name );
118 
119 
120 private:
121 
123  CustomGeomMgrSingleton( CustomGeomMgrSingleton const& copy ); // Not Implemented
124  CustomGeomMgrSingleton& operator=( CustomGeomMgrSingleton const& copy ); // Not Implemented
125 
126  string m_CurrGeom;
127  vector< GeomType > m_CustomTypeVec;
128  map< string, string > m_ModuleGeomIDMap;
129 
130 };
131 
132 #define CustomGeomMgr CustomGeomMgrSingleton::getInstance()
133 
134 //==================================================================================================//
135 //==================================================================================================//
136 //==================================================================================================//
137 //==================================================================================================//
138 
139 //==== Custom Geom XSec =====//
140 class CustomXSec : public SkinXSec
141 {
142 public:
143 
144  CustomXSec( XSecCurve *xsc );
145 
146  virtual void Update();
147  virtual void CopyBasePos( XSec* xs );
148 
149  virtual void SetLoc( const vec3d & loc );
150  virtual vec3d GetLoc() { return m_Loc; }
151  virtual void SetRot( const vec3d & rot );
152  virtual vec3d GetRot() { return m_Rot; }
153 
154  virtual double GetScale();
155 
156 protected:
157 
158  vec3d m_Loc;
159  vec3d m_Rot;
160 
161 };
162 
163 
164 //==================================================================================================//
165 //==================================================================================================//
166 //==================================================================================================//
167 //==================================================================================================//
168 
169 //==== Custom Geom ====//
170 class CustomGeom : public Geom
171 {
172 public:
173  CustomGeom( Vehicle* vehicle_ptr );
174  virtual ~CustomGeom();
175 
176  void Clear();
177  void InitGeom( );
178  void SetScriptModuleName( const string& name ) { m_ScriptModuleName = name; }
179  string GetScriptModuleName() { return m_ScriptModuleName; }
180  void SetDisplayName( const string& name ) { m_DisplayName = name; }
181  string GetDisplayName() { return m_DisplayName; }
182 
183  //==== Add a Parm Return ID ====//
184  string AddParm( int type, const string & name, const string & group );
185  string FindParmID( int index );
186 
187  //==== Add Gui ====//
188  int AddGui( const GuiDef & gd );
189  vector< GuiDef > GetGuiDefVec() { return m_GuiDefVec; }
190  void AddGuiTriggerEvent( int gui_index );
191  bool CheckClearTriggerEvent( int gui_index );
192 
193  void AddUpdateGui( const GuiUpdate & gu );
194  vector< GuiUpdate > GetGuiUpdateVec();
195 
196  //==== Add XSec Surface Return ID =====//
197  string AddXSecSurf();
198  void RemoveXSecSurf( const string& id );
199  void ClearXSecSurfs();
200 
201  virtual int GetNumXSecSurfs() const { return ( int )m_XSecSurfVec.size(); }
202  virtual XSecSurf* GetXSecSurf( int index );
203 
204  //==== Skin XSecs ====//
205  virtual void SkinXSecSurf( bool closed_flag );
206  virtual void CloneSurf( int index, Matrix4d & mat );
207  virtual void TransformSurf( int index, Matrix4d & mat );
208 
209  //==== Encode/Decode XML ====//
210  virtual xmlNodePtr EncodeXml( xmlNodePtr & node );
211  virtual xmlNodePtr DecodeXml( xmlNodePtr & node );
212 
213  //==== Set VSP Surf Type ====//
214  virtual void SetVspSurfType( int type, int surf_id = -1 );
215  virtual void SetVspSurfCfdType( int type, int surf_id = -1);
216 
217  //==== CFD Sources =====//
218  virtual void AddDefaultSources( double base_len = 1.0);
219  virtual void SetUpDefaultSource( SourceData & sd ) { m_DefaultSourceVec.push_back( sd ); }
220  virtual void ClearAllDefaultSources() { m_DefaultSourceVec.clear(); }
221 
222  virtual void ComputeCenter();
223  virtual void Scale();
224 
225  //==== Offset XSecs For Conformal =====//
226  virtual void OffsetXSecs( double off );
227 
228 protected:
229 
230  bool m_InitGeomFlag;
231  string m_ScriptModuleName;
232  string m_DisplayName;
233 
234  vector< Parm* > m_ParmVec; // Storage For Pointers
235  vector< GuiDef > m_GuiDefVec; // Gui Definition
236  vector< GuiUpdate > m_UpdateGuiVec; // Match Gui with Parms
237  vector< XSecSurf* > m_XSecSurfVec;
238  vector< int > m_TriggerVec;
239  vector< SourceData > m_DefaultSourceVec;
240 
241  int m_VspSurfType;
242  map< int, int > m_VspSurfTypeMap;
243  int m_VspSurfCfdType;
244  map< int, int > m_VspSurfCfdTypeMap;
245 
246 
247  virtual void UpdateSurf();
248  // Updates the cfd surface types
249  // Needed for transparent custom geoms
250  virtual void UpdateFlags();
251 
252  bool m_ConformalFlag;
253  double m_ConformalOffset;
254  virtual void ApplyConformalOffset( double off );
255 };
256 
257 
258 #endif // !defined(VSPCUSTOMGEOM__INCLUDED_)
Definition: Vec3d.h:235