OpenVSP API Documentation 3.52.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) ===//
148
149 int AddGui( int type, const string & label = string(), const string & parm_name = string(), const string & group_name = string(), double range = 10 );
150 vector< GuiDef > GetGuiDefVec( const string & geom_id );
151
152 //==== Add Gui->Parm Pairing To Update Vec ====//
171
172 void AddUpdateGui( int gui_id, const string & parm_id );
173 vector< GuiUpdate > GetGuiUpdateVec();
194
195 bool CheckClearTriggerEvent( int gui_id );
196
197 //==== Add XSec Surface To Current Geom - Return ID =====//
214
215 string AddXSecSurf();
231
232 void RemoveXSecSurf( const string& id );
245
261
262 void SkinXSecSurf( bool closed_flag );
283
284 void TransformSurf( int index, Matrix4d & mat );
306
307 void CloneSurf( int index, Matrix4d & mat );
308
309 //==== Surface Attribute (Wing, Fuse...) =====//
325
326 void SetVspSurfType( int type, int surf_id = -1 );
327
328 //==== Surface Cfd type (NORM, NEGATIVE, TRANSPARENT) ====//
344
345 void SetVspSurfCfdType ( int type, int surf_id = -1);
346
347 //==== Set Up Default Sources =====//
371
372 void SetupCustomDefaultSource( int type, int surf_index, double l1, double r1, double u1, double w1,
373 double l2 = 0, double r2 = 0, double u2 = 0, double w2 = 0 );
386
388
403
404 void SetCustomCenter( double x, double y, double z );
405
406 //==== Custom XSecs Functions ====//
425
426 void SetCustomXSecLoc( const string & xsec_id, const vec3d & loc );
441
442 vec3d GetCustomXSecLoc( const string & xsec_id );
457
458 void SetCustomXSecRot( const string & xsec_id, const vec3d & rot );
473
474 vec3d GetCustomXSecRot( const string & xsec_id );
475
476 //==== Append Cut Copy Paste Insert ====//
494
495 string AppendCustomXSec( const string & xsec_surf_id, int type );
511
512 void CutCustomXSec( const string & xsec_surf_id, int index );
527
528 void CopyCustomXSec( const string & xsec_surf_id, int index );
545
546 void PasteCustomXSec( const string & xsec_surf_id, int index );
563
564 string InsertCustomXSec( const string & xsec_surf_id, int type, int index );
565
566 //==== Get All Custom Script Module Name ====//
567 vector< string > GetCustomScriptModuleNames();
568
569 //==== Save Custom Script Content To File ====//
570 static int SaveScriptContentToFile( const string & module_name, const string & file_name );
571
572
573private:
574
575 CustomGeomMgrSingleton();
576 CustomGeomMgrSingleton( CustomGeomMgrSingleton const& copy ) = delete; // Not Implemented
577 CustomGeomMgrSingleton& operator=( CustomGeomMgrSingleton const& copy ) = delete; // Not Implemented
578
579 string m_CurrGeom;
580 vector< GeomType > m_CustomTypeVec;
581 unordered_map< string, string > m_ModuleGeomIDMap;
582
583};
584
585#define CustomGeomMgr CustomGeomMgrSingleton::getInstance()
586
587//==================================================================================================//
588//==================================================================================================//
589//==================================================================================================//
590//==================================================================================================//
591
592//==== Custom Geom XSec =====//
601class CustomXSec : public SkinXSec
602{
603public:
604
605 CustomXSec( XSecCurve *xsc );
606
607 virtual void Update();
608 virtual void CopyBasePos( XSec* xs );
609
610 virtual void SetLoc( const vec3d & loc );
611 virtual vec3d GetLoc() { return m_Loc; }
612 virtual void SetRot( const vec3d & rot );
613 virtual vec3d GetRot() { return m_Rot; }
614
615 virtual double GetScale();
616
617protected:
618
619 vec3d m_Loc;
620 vec3d m_Rot;
621
622};
623
624
625//==================================================================================================//
626//==================================================================================================//
627//==================================================================================================//
628//==================================================================================================//
629
630//==== Custom Geom ====//
639class CustomGeom : public Geom
640{
641public:
642 CustomGeom( Vehicle* vehicle_ptr );
643 virtual ~CustomGeom();
644
645 void Clear();
646 void InitGeom( );
647 void SetScriptModuleName( const string& name ) { m_ScriptModuleName = name; }
648 string GetScriptModuleName() { return m_ScriptModuleName; }
649 void SetDisplayName( const string& name ) { m_DisplayName = name; }
650 string GetDisplayName() { return m_DisplayName; }
651
652 //==== Add a Parm Return ID ====//
653 string AddParm( int type, const string & name, const string & group );
654 string FindParmID( int index );
655
656 //==== Add Gui ====//
657 int AddGui( const GuiDef & gd );
658 vector< GuiDef > GetGuiDefVec() { return m_GuiDefVec; }
659 void AddGuiTriggerEvent( int gui_index );
660 bool CheckClearTriggerEvent( int gui_index );
661
662 void AddUpdateGui( const GuiUpdate & gu );
663 vector< GuiUpdate > GetGuiUpdateVec();
664
665 //==== Add XSec Surface Return ID =====//
666 string AddXSecSurf();
667 void RemoveXSecSurf( const string& id );
668 void ClearXSecSurfs();
669
670 virtual int GetNumXSecSurfs() const { return ( int )m_XSecSurfVec.size(); }
671 virtual XSecSurf* GetXSecSurf( int index );
672
673 //==== Skin XSecs ====//
674 virtual void SkinXSecSurf( bool closed_flag );
675 virtual void CloneSurf( int index, Matrix4d & mat );
676 virtual void TransformSurf( int index, Matrix4d & mat );
677
678 //==== Encode/Decode XML ====//
679 virtual xmlNodePtr EncodeXml( xmlNodePtr & node );
680 virtual xmlNodePtr DecodeXml( xmlNodePtr & node );
681
682 //==== Set VSP Surf Type ====//
683 virtual void SetVspSurfType( int type, int surf_id = -1 );
684 virtual void SetVspSurfCfdType( int type, int surf_id = -1);
685
686 //==== CFD Sources =====//
687 virtual void AddDefaultSources( double base_len = 1.0);
688 virtual void SetUpDefaultSource( SourceData & sd ) { m_DefaultSourceVec.push_back( sd ); }
689 virtual void ClearAllDefaultSources() { m_DefaultSourceVec.clear(); }
690
691 virtual void ComputeCenter();
692 virtual void ApplyScale( double currentScale );
693
694 //==== Offset XSecs For Conformal =====//
695 virtual void OffsetXSecs( double off );
696
697protected:
698
699 bool m_InitGeomFlag;
700 string m_ScriptModuleName;
701 string m_DisplayName;
702
703 vector< Parm* > m_CustomGeomParmVec; // Storage For Pointers
704 vector< GuiDef > m_GuiDefVec; // Gui Definition
705 vector< GuiUpdate > m_UpdateGuiVec; // Match Gui with Parms
706 vector< XSecSurf* > m_XSecSurfVec;
707 vector< int > m_TriggerVec;
708 vector< SourceData > m_DefaultSourceVec;
709
710 int m_VspSurfType;
711 unordered_map< int, int > m_VspSurfTypeMap;
712 int m_VspSurfCfdType;
713 unordered_map< int, int > m_VspSurfCfdTypeMap;
714
715
716 virtual void UpdateSurf();
717 // Updates the cfd surface types
718 // Needed for transparent custom geoms
719 virtual void UpdateFlags();
720
721 bool m_ConformalFlag;
722 double m_ConformalOffset;
723 virtual void ApplyConformalOffset( double off );
724};
725
726
727#endif // !defined(VSPCUSTOMGEOM__INCLUDED_)
void AddUpdateGui(int gui_id, const string &parm_id)
void TransformSurf(int index, Matrix4d &mat)
void RemoveXSecSurf(const string &id)
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)
int AddGui(int type, const string &label=string(), const string &parm_name=string(), const string &group_name=string(), double range=10)
string GetCustomParm(int index)
void SkinXSecSurf(bool closed_flag)
Definition Vec3d.h:238