OpenVSP API Documentation 3.56.0
Loading...
Searching...
No Matches
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/*
12Three ways to create custom components:
131. Read from file with script attached
142. Create from GUI with script (preparsed) stored in local dir
153. Create from API with location of script
16
17Script:
18
19Init()
20- Name & type & script_name
21- Create/init parms
22- Describe GUI
23- Set num cuv_vec
24
25UpdateSurf()
26- load crv_vecs based on parms
27- Skin surfs over cuv_vecs
28
29CustomGeomMgr - store parsed scripts
30
31*/
32
33
34
35#if !defined(VSPCUSTOMGEOM__INCLUDED_)
36#define VSPCUSTOMGEOM__INCLUDED_
37
38
39#include "Geom.h"
40#include "XSec.h"
41#include "XSecSurf.h"
42
43#include <unordered_map>
44using std::unordered_map;
45
46
47//====Custom Geom Manager ====//
57class CustomGeomMgrSingleton
58{
59public:
60 static CustomGeomMgrSingleton& getInstance()
61 {
62 static CustomGeomMgrSingleton instance;
63 return instance;
64 }
65 static void Init() {}
66
67 //==== Init Geom ====//
68 void InitGeom( const string& id, const string& module_name, const string& display_name );
69 void SetCurrCustomGeom( const string& id ) { m_CurrGeom = id; }
83
84 string GetCurrCustomGeom() { return m_CurrGeom; }
85
86 void ReadCustomScripts( Vehicle* veh );
87 vector< GeomType > GetCustomTypes() { return m_CustomTypeVec; }
88
89 //==== Adds A Parm To The Current Custom Geom - Return Index of The Added Parm ====//
109
110 string AddParm( int type, const string & name, const string & group );
125
126 string GetCustomParm( int index );
127
128 //==== Add A Gui Device Constructor to Current Custom Geom - Gui Will Be Created By Custom Screen (if connected) ===//
171
172 int AddGui( int type, const string & arg1 = string(), const string & arg2 = string(),
173 const string & arg3 = string(), double arg4 = 10, const string & arg5 = string() );
174 vector< GuiDef > GetGuiDefVec( const string & geom_id );
175
176 //==== Add Gui->Parm Pairing To Update Vec ====//
195
196 void AddUpdateGui( int gui_id, const string & parm_id );
197
218
219 void AddUpdateGui( int gui_id, const string & parm_id, const string & parm_id2, int input );
220 vector< GuiUpdate > GetGuiUpdateVec();
241
242 bool CheckClearTriggerEvent( int gui_id );
243
244 //==== Add XSec Surface To Current Geom - Return ID =====//
261
262 string AddXSecSurf();
278
279 void RemoveXSecSurf( const string& id );
292
308
309 void SkinXSecSurf( bool closed_flag );
330
331 void TransformSurf( int index, Matrix4d & mat );
353
354 void CloneSurf( int index, Matrix4d & mat );
355
356 //==== Surface Attribute (Wing, Fuse...) =====//
372
373 void SetVspSurfType( int type, int surf_id = -1 );
374
375 //==== Surface Cfd type (NORM, NEGATIVE, TRANSPARENT) ====//
391
392 void SetVspSurfCfdType ( int type, int surf_id = -1);
393
394 //==== Set Up Default Sources =====//
418
419 void SetupCustomDefaultSource( int type, int surf_index, double l1, double r1, double u1, double w1,
420 double l2 = 0, double r2 = 0, double u2 = 0, double w2 = 0 );
433
435
450
451 void SetCustomCenter( double x, double y, double z );
452
453 //==== Custom XSecs Functions ====//
472
473 void SetCustomXSecLoc( const string & xsec_id, const vec3d & loc );
488
489 vec3d GetCustomXSecLoc( const string & xsec_id );
504
505 void SetCustomXSecRot( const string & xsec_id, const vec3d & rot );
520
521 vec3d GetCustomXSecRot( const string & xsec_id );
522
523 //==== Append Cut Copy Paste Insert ====//
541
542 string AppendCustomXSec( const string & xsec_surf_id, int type );
558
559 void CutCustomXSec( const string & xsec_surf_id, int index );
574
575 void CopyCustomXSec( const string & xsec_surf_id, int index );
592
593 void PasteCustomXSec( const string & xsec_surf_id, int index );
610
611 string InsertCustomXSec( const string & xsec_surf_id, int type, int index );
612
613 //==== Get All Custom Script Module Name ====//
614 vector< string > GetCustomScriptModuleNames();
615
616 //==== Save Custom Script Content To File ====//
617 static int SaveScriptContentToFile( const string & module_name, const string & file_name );
618
619
620private:
621
622 CustomGeomMgrSingleton();
623 CustomGeomMgrSingleton( CustomGeomMgrSingleton const& copy ) = delete; // Not Implemented
624 CustomGeomMgrSingleton& operator=( CustomGeomMgrSingleton const& copy ) = delete; // Not Implemented
625
626 string m_CurrGeom;
627 vector< GeomType > m_CustomTypeVec;
628 unordered_map< string, string > m_ModuleGeomIDMap;
629
630};
631
632#define CustomGeomMgr CustomGeomMgrSingleton::getInstance()
633
634//==================================================================================================//
635//==================================================================================================//
636//==================================================================================================//
637//==================================================================================================//
638
639//==== Custom Geom XSec =====//
648class CustomXSec : public SkinXSec
649{
650public:
651
652 CustomXSec( XSecCurve *xsc );
653
654 virtual void Update();
655 virtual void CopyBasePos( XSec* xs );
656
657 virtual void SetLoc( const vec3d & loc );
658 virtual vec3d GetLoc() { return m_Loc; }
659 virtual void SetRot( const vec3d & rot );
660 virtual vec3d GetRot() { return m_Rot; }
661
662 virtual double GetScale();
663
664protected:
665
666 vec3d m_Loc;
667 vec3d m_Rot;
668
669};
670
671
672//==================================================================================================//
673//==================================================================================================//
674//==================================================================================================//
675//==================================================================================================//
676
677//==== Custom Geom ====//
686class CustomGeom : public Geom
687{
688public:
689 CustomGeom( Vehicle* vehicle_ptr );
690 virtual ~CustomGeom();
691
692 void Clear();
693 void InitGeom( );
694 void SetScriptModuleName( const string& name ) { m_ScriptModuleName = name; }
695 string GetScriptModuleName() { return m_ScriptModuleName; }
696 void SetDisplayName( const string& name ) { m_DisplayName = name; }
697 string GetDisplayName() { return m_DisplayName; }
698
699 //==== Add a Parm Return ID ====//
700 string AddParm( int type, const string & name, const string & group );
701 string FindParmID( int index );
702
703 //==== Add Gui ====//
704 int AddGui( const GuiDef & gd );
705 vector< GuiDef > GetGuiDefVec() { return m_GuiDefVec; }
706 void AddGuiTriggerEvent( int gui_index );
707 bool CheckClearTriggerEvent( int gui_index );
708
709 void AddUpdateGui( const GuiUpdate & gu );
710 vector< GuiUpdate > GetGuiUpdateVec();
711
712 //==== Add XSec Surface Return ID =====//
713 string AddXSecSurf();
714 void RemoveXSecSurf( const string& id );
715 void ClearXSecSurfs();
716
717 virtual int GetNumXSecSurfs() const { return ( int )m_XSecSurfVec.size(); }
718 virtual XSecSurf* GetXSecSurf( int index );
719
720 //==== Skin XSecs ====//
721 virtual void SkinXSecSurf( bool closed_flag );
722 virtual void CloneSurf( int index, Matrix4d & mat );
723 virtual void TransformSurf( int index, Matrix4d & mat );
724
725 //==== Encode/Decode XML ====//
726 virtual xmlNodePtr EncodeXml( xmlNodePtr & node );
727 virtual xmlNodePtr DecodeXml( xmlNodePtr & node );
728
729 //==== Set VSP Surf Type ====//
730 virtual void SetVspSurfType( int type, int surf_id = -1 );
731 virtual void SetVspSurfCfdType( int type, int surf_id = -1);
732
733 //==== CFD Sources =====//
734 virtual void AddDefaultSources( double base_len = 1.0);
735 virtual void SetUpDefaultSource( SourceData & sd ) { m_DefaultSourceVec.push_back( sd ); }
736 virtual void ClearAllDefaultSources() { m_DefaultSourceVec.clear(); }
737
738 virtual void ComputeCenter();
739 virtual void ApplyScale( double currentScale );
740
741 //==== Offset XSecs For Conformal =====//
742 virtual void OffsetXSecs( double off );
743
744protected:
745
746 bool m_InitGeomFlag;
747 string m_ScriptModuleName;
748 string m_DisplayName;
749
750 vector< Parm* > m_CustomGeomParmVec; // Storage For Pointers
751 vector< GuiDef > m_GuiDefVec; // Gui Definition
752 vector< GuiUpdate > m_UpdateGuiVec; // Match Gui with Parms
753 vector< XSecSurf* > m_XSecSurfVec;
754 vector< int > m_TriggerVec;
755 vector< SourceData > m_DefaultSourceVec;
756
757 int m_VspSurfType;
758 unordered_map< int, int > m_VspSurfTypeMap;
759 int m_VspSurfCfdType;
760 unordered_map< int, int > m_VspSurfCfdTypeMap;
761
762
763 virtual void UpdateSurf();
764 // Updates the cfd surface types
765 // Needed for transparent custom geoms
766 virtual void UpdateFlags();
767
768 bool m_ConformalFlag;
769 double m_ConformalOffset;
770 virtual void ApplyConformalOffset( double off );
771};
772
773
774#endif // !defined(VSPCUSTOMGEOM__INCLUDED_)
void AddUpdateGui(int gui_id, const string &parm_id)
void TransformSurf(int index, Matrix4d &mat)
void RemoveXSecSurf(const string &id)
int AddGui(int type, const string &arg1=string(), const string &arg2=string(), const string &arg3=string(), double arg4=10, const string &arg5=string())
string AppendCustomXSec(const string &xsec_surf_id, int type)
void SetupCustomDefaultSource(int type, int surf_index, double l1, double r1, double u1, double w1, double l2=0, double r2=0, double u2=0, double w2=0)
string InsertCustomXSec(const string &xsec_surf_id, int type, int index)
void SetVspSurfCfdType(int type, int surf_id=-1)
void CopyCustomXSec(const string &xsec_surf_id, int index)
void SetCustomXSecRot(const string &xsec_id, const vec3d &rot)
vec3d GetCustomXSecLoc(const string &xsec_id)
void SetVspSurfType(int type, int surf_id=-1)
void SetCustomCenter(double x, double y, double z)
vec3d GetCustomXSecRot(const string &xsec_id)
void CutCustomXSec(const string &xsec_surf_id, int index)
void SetCustomXSecLoc(const string &xsec_id, const vec3d &loc)
void ClearAllCustomDefaultSources()
void CloneSurf(int index, Matrix4d &mat)
void PasteCustomXSec(const string &xsec_surf_id, int index)
string AddParm(int type, const string &name, const string &group)
bool CheckClearTriggerEvent(int gui_id)
string GetCustomParm(int index)
void SkinXSecSurf(bool closed_flag)
void AddUpdateGui(int gui_id, const string &parm_id, const string &parm_id2, int input)
Definition Vec3d.h:238