OpenVSP API Documentation 3.57.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#include "XSecSurfGeom.h"
43
44#include <unordered_map>
45using std::unordered_map;
46
47
48//====Custom Geom Manager ====//
58class CustomGeomMgrSingleton
59{
60public:
61 static CustomGeomMgrSingleton& getInstance()
62 {
63 static CustomGeomMgrSingleton instance;
64 return instance;
65 }
66 static void Init() {}
67
68 //==== Init Geom ====//
69 void InitGeom( const string& id, const string& module_name, const string& display_name );
70 void SetCurrCustomGeom( const string& id ) { m_CurrGeom = id; }
84
85 string GetCurrCustomGeom() { return m_CurrGeom; }
86
87 // The custom component whose script is running now, or empty when none is.
88 void SetRunningCustomGeom( const string& id ) { m_RunningGeom = id; }
89 string GetRunningCustomGeom() { return m_RunningGeom; }
90
91 void ReadCustomScripts( Vehicle* veh );
92 vector< GeomType > GetCustomTypes() { return m_CustomTypeVec; }
93
94 //==== Adds A Parm To The Current Custom Geom - Return Index of The Added Parm ====//
114
115 string AddParm( int type, const string & name, const string & group );
130
131 string GetCustomParm( int index );
132
133 //==== Add A Gui Device Constructor to Current Custom Geom - Gui Will Be Created By Custom Screen (if connected) ===//
177
178 int AddGui( int type, const string & arg1 = string(), const string & arg2 = string(),
179 const string & arg3 = string(), double arg4 = 10, const string & arg5 = string() );
180 vector< GuiDef > GetGuiDefVec( const string & geom_id );
181
182 //==== Add Gui->Parm Pairing To Update Vec ====//
201
202 void AddUpdateGui( int gui_id, const string & parm_id );
203
224
225 void AddUpdateGui( int gui_id, const string & parm_id, const string & parm_id2, int input );
226 vector< GuiUpdate > GetGuiUpdateVec();
247
248 bool CheckClearTriggerEvent( int gui_id );
249
250 //==== Add XSec Surface To Current Geom - Return ID =====//
267
268 string AddXSecSurf();
284
285 void RemoveXSecSurf( const string& id );
298
314
315 void SkinXSecSurf( bool closed_flag );
336
337 void TransformSurf( int index, Matrix4d & mat );
359
360 void CloneSurf( int index, Matrix4d & mat );
361
362 //==== Surface Attribute (Wing, Fuse...) =====//
378
379 void SetVspSurfType( int type, int surf_id = -1 );
380
381 //==== Surface Cfd type (NORM, NEGATIVE, TRANSPARENT) ====//
397
398 void SetVspSurfCfdType ( int type, int surf_id = -1);
399
400 //==== Set Up Default Sources =====//
424
425 void SetupCustomDefaultSource( int type, int surf_index, double l1, double r1, double u1, double w1,
426 double l2 = 0, double r2 = 0, double u2 = 0, double w2 = 0 );
439
441
456
457 void SetCustomCenter( double x, double y, double z );
458
459 //==== Custom XSecs Functions ====//
478
479 void SetCustomXSecLoc( const string & xsec_id, const vec3d & loc );
494
495 vec3d GetCustomXSecLoc( const string & xsec_id );
510
511 void SetCustomXSecRot( const string & xsec_id, const vec3d & rot );
526
527 vec3d GetCustomXSecRot( const string & xsec_id );
528
529 //==== Append Cut Copy Paste Insert ====//
547
548 string AppendCustomXSec( const string & xsec_surf_id, int type );
564
565 void CutCustomXSec( const string & xsec_surf_id, int index );
580
581 void CopyCustomXSec( const string & xsec_surf_id, int index );
598
599 void PasteCustomXSec( const string & xsec_surf_id, int index );
616
617 string InsertCustomXSec( const string & xsec_surf_id, int type, int index );
618
619 //==== Get All Custom Script Module Name ====//
620 vector< string > GetCustomScriptModuleNames();
621
622 //==== Save Custom Script Content To File ====//
623 static int SaveScriptContentToFile( const string & module_name, const string & file_name );
624
625
626private:
627
628 CustomGeomMgrSingleton();
629 CustomGeomMgrSingleton( CustomGeomMgrSingleton const& copy ) = delete; // Not Implemented
630 CustomGeomMgrSingleton& operator=( CustomGeomMgrSingleton const& copy ) = delete; // Not Implemented
631
632 string m_CurrGeom;
633 string m_RunningGeom;
634 vector< GeomType > m_CustomTypeVec;
635 unordered_map< string, string > m_ModuleGeomIDMap;
636
637};
638
639#define CustomGeomMgr CustomGeomMgrSingleton::getInstance()
640
641//==================================================================================================//
642//==================================================================================================//
643//==================================================================================================//
644//==================================================================================================//
645
646//==== Custom Geom XSec =====//
655class CustomXSec : public BareXSec
656{
657public:
658
659 CustomXSec( XSecCurve *xsc );
660
661 virtual void SetRot( const vec3d & rot );
662 virtual vec3d GetRot() { return m_Rot; }
663
664 virtual void CopyBasePos( XSec* xs );
665
666protected:
667
668 virtual void GetPlacement( Matrix4d & placement );
669
670 vec3d m_Rot;
671};
672
673
674//==================================================================================================//
675//==================================================================================================//
676//==================================================================================================//
677//==================================================================================================//
678
679//==== Custom Geom ====//
688class CustomGeom : public XSecSurfGeom
689{
690public:
691 CustomGeom( Vehicle* vehicle_ptr );
692 virtual ~CustomGeom();
693
694 void Clear();
695 void InitGeom( );
696 void SetScriptModuleName( const string& name ) { m_ScriptModuleName = name; }
697 string GetScriptModuleName() { return m_ScriptModuleName; }
698
699 // Run a function of this component's script, as the running custom component.
700 int RunScript( const char* function_name, bool arg_flag = false, double arg = 0.0 );
701 void SetDisplayName( const string& name ) { m_DisplayName = name; }
702 string GetDisplayName() { return m_DisplayName; }
703
704 //==== Add a Parm Return ID ====//
705 string AddParm( int type, const string & name, const string & group );
706 string FindParmID( int index );
707
708 //==== Add Gui ====//
709 int AddGui( const GuiDef & gd );
710 vector< GuiDef > GetGuiDefVec() { return m_GuiDefVec; }
711 void AddGuiTriggerEvent( int gui_index );
712 bool CheckClearTriggerEvent( int gui_index );
713
714 void AddUpdateGui( const GuiUpdate & gu );
715 vector< GuiUpdate > GetGuiUpdateVec();
716
717 //==== Encode/Decode XML ====//
718 virtual xmlNodePtr EncodeXml( xmlNodePtr & node );
719 virtual xmlNodePtr DecodeXml( xmlNodePtr & node );
720
721 virtual void ComputeCenter();
722 virtual void ApplyScale( double currentScale );
723
724 //==== The Script's Surfaces ====//
725 string AddXSecSurf();
726 void RemoveXSecSurf( const string& id );
727 virtual void ClearXSecSurfs();
728
729 // The skinned and flagged types of one surface, or of every surface where surf_id is -1.
730 void SetVspSurfType( int type, int surf_id );
731 virtual int GetVspSurfType( int surf_id ) const;
732 void SetVspSurfCfdType( int type, int surf_id );
733
734 //==== CFD Sources =====//
735 virtual void AddDefaultSources( double base_len = 1.0 );
736 void SetUpDefaultSource( SourceData & sd ) { m_DefaultSourceVec.push_back( sd ); }
737 void ClearAllDefaultSources() { m_DefaultSourceVec.clear(); }
738
739 // Translate the surfaces so the first one's nose tip lies on the Geom's origin in each chosen coordinate.
740 BoolParm m_NoseOriginXFlag;
741 BoolParm m_NoseOriginYFlag;
742 BoolParm m_NoseOriginZFlag;
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< int > m_TriggerVec;
754
755 virtual void UpdateSurf();
756 virtual void UpdateEndCaps();
757
758 // A subsurface this component's own script adds is internal to it: not listed with it.
759 virtual SubSurface* AddSubSurf( int type, int surfindex );
760
761 // The types a surface was given of its own, over those every surface was given. Needed for transparent
762 // custom geoms.
763 virtual void UpdateFlags();
764
765 unordered_map< int, int > m_VspSurfTypeMap;
766 unordered_map< int, int > m_VspSurfCfdTypeMap;
767 vector< SourceData > m_DefaultSourceVec;
768};
769
770
771#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