123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- #include "appselectionset.h"
- #include "appmodel.h"
- #include "appview.h"
- #include "vlist.h"
- #include "body.hxx"
- #include "face.hxx"
- #include "edge.hxx"
- AppSelectionSet::AppSelectionSet(HBaseView* view) : HSelectionSet(view)
- {
- m_SelectLevel = BODY_TYPE; // set default level to body BODY_TYPE
- SetAllowEntitySelection(true);
- }
- AppSelectionSet::~AppSelectionSet()
- {
- if( m_pSolidSelection )
- {
- delete_vlist(m_pSolidSelection);
- m_pSolidSelection = 0;
- }
- }
- // create a new list object
- void AppSelectionSet::Init()
- {
- m_pSolidSelection = new_vlist(malloc, free);
- HSelectionSet::Init();
- }
- int AppSelectionSet::GetSolidListSize()
- {
- return vlist_count( m_pSolidSelection );
- }
- long long AppSelectionSet::GetAtSolidEntity(int index)
- {
- return (long long) vlist_nth_item( m_pSolidSelection, index );
- }
- void AppSelectionSet::Reset()
- {
- if( m_pSolidSelection )
- {
- delete_vlist(m_pSolidSelection);
- m_pSolidSelection = new_vlist(malloc, free);
- }
- HSelectionSet::Reset();
- }
- // deselect all items as in DeSelect
- void AppSelectionSet::DeSelectAll()
- {
- if( m_pSolidSelection )
- {
- delete_vlist(m_pSolidSelection);
- m_pSolidSelection = new_vlist(malloc, free);
- }
- HSelectionSet::DeSelectAll();
- m_pView->EmitDeSelectAllMessage();
- }
- void AppSelectionSet::Select( HC_KEY key, int num_include_keys, HC_KEY * include_keys, bool emit_message)
- {
- HC_KEY* sel_keys = 0;
- int count = 0;
- ENTITY* entity = 0;
- if (((AppModel *) HSelectionSet::m_pView->GetModel())->IsSolidModel() != true)
- {
- char type[64];
- HC_KEY segkey;
- HC_Show_Key_Type(key, type);
- if (!streq(type, "segment"))
- segkey = HC_KShow_Owner_By_Key(key);
- else
- segkey = key;
- HSelectionSet::Select( segkey, num_include_keys, include_keys, emit_message);
- }
- else
- {
- entity = HA_Compute_Entity_Pointer(key, m_SelectLevel);//FACE_TYPE? BODY_TYPE?
- if (entity)
- {
- bool bFind = false;
- for (int i = 0; i < vlist_count(m_pSolidSelection); i++)
- {
- if ((void*)entity == vlist_nth_item(m_pSolidSelection, i))
- {
- bFind = true;
- }
- }
- if (!bFind)
- {
- vlist_add_last(m_pSolidSelection, (void*)entity);
- if (m_SelectLevel == BODY_TYPE) // && body segments is true
- {
- sel_keys = new HC_KEY[1];
- count = HA_Compute_Geometry_Keys(entity, 1, sel_keys, "bodies");
- }
- else if (m_SelectLevel == FACE_TYPE)
- {
- count = HA_Compute_Geometry_Key_Count(entity, "faces");
- if (count > 0)
- {
- sel_keys = new HC_KEY[count];
- HA_Compute_Geometry_Keys(entity, count, sel_keys, "faces");
- }
- }
- else if (m_SelectLevel == EDGE_TYPE)
- {
- count = HA_Compute_Geometry_Key_Count(entity, "edges");
- if (count > 0)
- {
- sel_keys = new HC_KEY[count];
- HA_Compute_Geometry_Keys(entity, count, sel_keys, "edges");
- }
- }
- }
- }
- for (int c = 0; c < count; c++)
- HSelectionSet::Select(sel_keys[c], num_include_keys, include_keys, emit_message); // call base class fcn for each key
- if( sel_keys )
- delete [] sel_keys;
- }
- }
- void AppSelectionSet::Select(ENTITY* entity, bool emit_message)
- {
- HC_KEY* sel_keys = 0;
- int count = 0;
- int eclass;
- eclass = entity->identity();
- if (entity)
- {
- bool bFind = false;
- for (int i = 0; i < vlist_count(m_pSolidSelection); i++)
- {
- if ((void*)entity == vlist_nth_item(m_pSolidSelection, i))
- {
- bFind = true;
- }
- }
- if (!bFind)
- {
- vlist_add_last(m_pSolidSelection, (void*)entity);
- if (m_SelectLevel == BODY_TYPE) // && body segments is true
- {
- sel_keys = new HC_KEY[1];
- count = HA_Compute_Geometry_Keys(entity, 1, sel_keys, "bodies");
- }
- else if (m_SelectLevel == FACE_TYPE)
- {
- count = HA_Compute_Geometry_Key_Count(entity, "faces");
- if (count > 0)
- {
- sel_keys = new HC_KEY[count];
- HA_Compute_Geometry_Keys(entity, count, sel_keys, "faces");
- }
- }
- else if (m_SelectLevel == EDGE_TYPE)
- {
- count = HA_Compute_Geometry_Key_Count(entity, "edges");
- if (count > 0)
- {
- sel_keys = new HC_KEY[count];
- HA_Compute_Geometry_Keys(entity, count, sel_keys, "edges");
- }
- }
- }
- }
- for (int c = 0; c < count; c++)
- HSelectionSet::Select(sel_keys[c], "", INVALID_KEY, INVALID_KEY, emit_message); // call base class fcn for each key
- if( sel_keys )
- delete [] sel_keys;
- }
- void AppSelectionSet::DeSelect( HC_KEY key, bool emit_message )
- {
- HC_KEY* sel_keys = 0;
- int count = 0;
- if (((AppModel *) m_pView->GetModel())->IsSolidModel() != true)
- {
- char type[1024];
- HC_KEY segkey;
- HC_Show_Key_Type(key, type);
- if (!streq(type, "segment"))
- segkey = HC_KShow_Owner_By_Key(key);
- else
- segkey = key;
- HSelectionSet::DeSelect(segkey, emit_message);
- }
- else
- {
- ENTITY* entity = 0;
- entity = HA_Compute_Entity_Pointer(key, m_SelectLevel);
- if (entity)
- {
- vlist_remove(m_pSolidSelection, (void*)entity);
- if (m_SelectLevel == BODY_TYPE) // && body segments is true
- {
- sel_keys = new HC_KEY[1];
- count = HA_Compute_Geometry_Keys(entity, 1, sel_keys, "bodies");
- }
- else if (m_SelectLevel == FACE_TYPE)
- {
- count = HA_Compute_Geometry_Key_Count(entity, "faces");
- if( count > 0 )
- {
- sel_keys = new HC_KEY[count];
- HA_Compute_Geometry_Keys(entity, count, sel_keys, "faces");
- }
- }
- else if (m_SelectLevel == EDGE_TYPE)
- {
- count = HA_Compute_Geometry_Key_Count(entity, "edges");
- if( count > 0 )
- {
- sel_keys = new HC_KEY[count];
- HA_Compute_Geometry_Keys(entity, count, sel_keys, "edges");
- }
- }
- }
- if (count > 0)
- {
- for( int c = 0; c < count; c++)
- HSelectionSet::DeSelect(sel_keys[c], emit_message); // call base class fcn for each key
- }
- else
- HSelectionSet::DeSelect(key, emit_message);
- }
- if( sel_keys )
- delete[] sel_keys;
- }
- void AppSelectionSet::DeSelectEntity(ENTITY* entity, bool emit_message )
- {
- HC_KEY* sel_keys = 0;
- int count = 0;
- if (entity)
- {
- vlist_remove(m_pSolidSelection, (void*) entity);
- if (m_SelectLevel == BODY_TYPE) // && body segments is true
- {
- sel_keys = new HC_KEY[1];
- count = HA_Compute_Geometry_Keys(entity, 1, sel_keys, "bodies");
- }
- else if (m_SelectLevel == FACE_TYPE)
- {
- count = HA_Compute_Geometry_Key_Count(entity, "faces");
- if( count > 0 )
- {
- sel_keys = new HC_KEY[count];
- HA_Compute_Geometry_Keys(entity, count, sel_keys, "faces");
- }
- }
- else if (m_SelectLevel == EDGE_TYPE)
- {
- count = HA_Compute_Geometry_Key_Count(entity, "edges");
- if( count > 0 )
- {
- sel_keys = new HC_KEY[count];
- HA_Compute_Geometry_Keys(entity, count, sel_keys, "edges");
- }
- }
- }
- if (count > 0)
- {
- for( int c = 0; c < count; c++)
- HSelectionSet::DeSelect(sel_keys[c], emit_message); // call base class fcn for each key
- }
- if( sel_keys )
- delete[] sel_keys;
- }
- bool AppSelectionSet::IsSelected(HC_KEY key)
- {
- if (((AppModel *) m_pView->GetModel())->IsSolidModel() != true)
- {
- char type[1024];
- HC_Show_Key_Type(key, type);
- if (!streq(type, "segment"))
- key = HC_KShow_Owner_By_Key(key);
- }
- else
- {
- int count;
- if (m_SelectLevel == BODY_TYPE) // && body segments is true
- {
- ENTITY* entity = 0;
- entity = HA_Compute_Entity_Pointer(key, m_SelectLevel);
- if (entity)
- count = HA_Compute_Geometry_Keys(entity, 1, &key, "bodies");
- assert(count == 1);
- }
- }
- // call base class function with the computed key
- return HSelectionSet::IsSelected(key);
- }
- // If it is a call to select something from HNet message,
- // by pass our selection functionality and just call the
- // vanilla Select. JUST SELECT THIS KEY!
- // This is to work around the case where the master client
- // is in some selection mode (face) and slave is in some (body)
- void AppSelectionSet::SelectFromMessage(HC_KEY key, int num_include_keys, HC_KEY * include_keys, bool emit_message)
- {
- HSelectionSet::Select( key, num_include_keys, include_keys, emit_message);
- }
- // See the Description for SelectFromMessage
- void AppSelectionSet::DeSelectFromMessage(HC_KEY key, bool emit_message)
- {
- HSelectionSet::DeSelect(key, emit_message);
- }
|