appselectionset.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. #include "appselectionset.h"
  2. #include "appmodel.h"
  3. #include "appview.h"
  4. #include "vlist.h"
  5. #include "body.hxx"
  6. #include "face.hxx"
  7. #include "edge.hxx"
  8. AppSelectionSet::AppSelectionSet(HBaseView* view) : HSelectionSet(view)
  9. {
  10. m_SelectLevel = BODY_TYPE; // set default level to body BODY_TYPE
  11. SetAllowEntitySelection(true);
  12. }
  13. AppSelectionSet::~AppSelectionSet()
  14. {
  15. if( m_pSolidSelection )
  16. {
  17. delete_vlist(m_pSolidSelection);
  18. m_pSolidSelection = 0;
  19. }
  20. }
  21. // create a new list object
  22. void AppSelectionSet::Init()
  23. {
  24. m_pSolidSelection = new_vlist(malloc, free);
  25. HSelectionSet::Init();
  26. }
  27. int AppSelectionSet::GetSolidListSize()
  28. {
  29. return vlist_count( m_pSolidSelection );
  30. }
  31. long long AppSelectionSet::GetAtSolidEntity(int index)
  32. {
  33. return (long long) vlist_nth_item( m_pSolidSelection, index );
  34. }
  35. void AppSelectionSet::Reset()
  36. {
  37. if( m_pSolidSelection )
  38. {
  39. delete_vlist(m_pSolidSelection);
  40. m_pSolidSelection = new_vlist(malloc, free);
  41. }
  42. HSelectionSet::Reset();
  43. }
  44. // deselect all items as in DeSelect
  45. void AppSelectionSet::DeSelectAll()
  46. {
  47. if( m_pSolidSelection )
  48. {
  49. delete_vlist(m_pSolidSelection);
  50. m_pSolidSelection = new_vlist(malloc, free);
  51. }
  52. HSelectionSet::DeSelectAll();
  53. m_pView->EmitDeSelectAllMessage();
  54. }
  55. void AppSelectionSet::Select( HC_KEY key, int num_include_keys, HC_KEY * include_keys, bool emit_message)
  56. {
  57. HC_KEY* sel_keys = 0;
  58. int count = 0;
  59. ENTITY* entity = 0;
  60. if (((AppModel *) HSelectionSet::m_pView->GetModel())->IsSolidModel() != true)
  61. {
  62. char type[64];
  63. HC_KEY segkey;
  64. HC_Show_Key_Type(key, type);
  65. if (!streq(type, "segment"))
  66. segkey = HC_KShow_Owner_By_Key(key);
  67. else
  68. segkey = key;
  69. HSelectionSet::Select( segkey, num_include_keys, include_keys, emit_message);
  70. }
  71. else
  72. {
  73. entity = HA_Compute_Entity_Pointer(key, m_SelectLevel);//FACE_TYPE? BODY_TYPE?
  74. if (entity)
  75. {
  76. bool bFind = false;
  77. for (int i = 0; i < vlist_count(m_pSolidSelection); i++)
  78. {
  79. if ((void*)entity == vlist_nth_item(m_pSolidSelection, i))
  80. {
  81. bFind = true;
  82. }
  83. }
  84. if (!bFind)
  85. {
  86. vlist_add_last(m_pSolidSelection, (void*)entity);
  87. if (m_SelectLevel == BODY_TYPE) // && body segments is true
  88. {
  89. sel_keys = new HC_KEY[1];
  90. count = HA_Compute_Geometry_Keys(entity, 1, sel_keys, "bodies");
  91. }
  92. else if (m_SelectLevel == FACE_TYPE)
  93. {
  94. count = HA_Compute_Geometry_Key_Count(entity, "faces");
  95. if (count > 0)
  96. {
  97. sel_keys = new HC_KEY[count];
  98. HA_Compute_Geometry_Keys(entity, count, sel_keys, "faces");
  99. }
  100. }
  101. else if (m_SelectLevel == EDGE_TYPE)
  102. {
  103. count = HA_Compute_Geometry_Key_Count(entity, "edges");
  104. if (count > 0)
  105. {
  106. sel_keys = new HC_KEY[count];
  107. HA_Compute_Geometry_Keys(entity, count, sel_keys, "edges");
  108. }
  109. }
  110. }
  111. }
  112. for (int c = 0; c < count; c++)
  113. HSelectionSet::Select(sel_keys[c], num_include_keys, include_keys, emit_message); // call base class fcn for each key
  114. if( sel_keys )
  115. delete [] sel_keys;
  116. }
  117. }
  118. void AppSelectionSet::Select(ENTITY* entity, bool emit_message)
  119. {
  120. HC_KEY* sel_keys = 0;
  121. int count = 0;
  122. int eclass;
  123. eclass = entity->identity();
  124. if (entity)
  125. {
  126. bool bFind = false;
  127. for (int i = 0; i < vlist_count(m_pSolidSelection); i++)
  128. {
  129. if ((void*)entity == vlist_nth_item(m_pSolidSelection, i))
  130. {
  131. bFind = true;
  132. }
  133. }
  134. if (!bFind)
  135. {
  136. vlist_add_last(m_pSolidSelection, (void*)entity);
  137. if (m_SelectLevel == BODY_TYPE) // && body segments is true
  138. {
  139. sel_keys = new HC_KEY[1];
  140. count = HA_Compute_Geometry_Keys(entity, 1, sel_keys, "bodies");
  141. }
  142. else if (m_SelectLevel == FACE_TYPE)
  143. {
  144. count = HA_Compute_Geometry_Key_Count(entity, "faces");
  145. if (count > 0)
  146. {
  147. sel_keys = new HC_KEY[count];
  148. HA_Compute_Geometry_Keys(entity, count, sel_keys, "faces");
  149. }
  150. }
  151. else if (m_SelectLevel == EDGE_TYPE)
  152. {
  153. count = HA_Compute_Geometry_Key_Count(entity, "edges");
  154. if (count > 0)
  155. {
  156. sel_keys = new HC_KEY[count];
  157. HA_Compute_Geometry_Keys(entity, count, sel_keys, "edges");
  158. }
  159. }
  160. }
  161. }
  162. for (int c = 0; c < count; c++)
  163. HSelectionSet::Select(sel_keys[c], "", INVALID_KEY, INVALID_KEY, emit_message); // call base class fcn for each key
  164. if( sel_keys )
  165. delete [] sel_keys;
  166. }
  167. void AppSelectionSet::DeSelect( HC_KEY key, bool emit_message )
  168. {
  169. HC_KEY* sel_keys = 0;
  170. int count = 0;
  171. if (((AppModel *) m_pView->GetModel())->IsSolidModel() != true)
  172. {
  173. char type[1024];
  174. HC_KEY segkey;
  175. HC_Show_Key_Type(key, type);
  176. if (!streq(type, "segment"))
  177. segkey = HC_KShow_Owner_By_Key(key);
  178. else
  179. segkey = key;
  180. HSelectionSet::DeSelect(segkey, emit_message);
  181. }
  182. else
  183. {
  184. ENTITY* entity = 0;
  185. entity = HA_Compute_Entity_Pointer(key, m_SelectLevel);
  186. if (entity)
  187. {
  188. vlist_remove(m_pSolidSelection, (void*)entity);
  189. if (m_SelectLevel == BODY_TYPE) // && body segments is true
  190. {
  191. sel_keys = new HC_KEY[1];
  192. count = HA_Compute_Geometry_Keys(entity, 1, sel_keys, "bodies");
  193. }
  194. else if (m_SelectLevel == FACE_TYPE)
  195. {
  196. count = HA_Compute_Geometry_Key_Count(entity, "faces");
  197. if( count > 0 )
  198. {
  199. sel_keys = new HC_KEY[count];
  200. HA_Compute_Geometry_Keys(entity, count, sel_keys, "faces");
  201. }
  202. }
  203. else if (m_SelectLevel == EDGE_TYPE)
  204. {
  205. count = HA_Compute_Geometry_Key_Count(entity, "edges");
  206. if( count > 0 )
  207. {
  208. sel_keys = new HC_KEY[count];
  209. HA_Compute_Geometry_Keys(entity, count, sel_keys, "edges");
  210. }
  211. }
  212. }
  213. if (count > 0)
  214. {
  215. for( int c = 0; c < count; c++)
  216. HSelectionSet::DeSelect(sel_keys[c], emit_message); // call base class fcn for each key
  217. }
  218. else
  219. HSelectionSet::DeSelect(key, emit_message);
  220. }
  221. if( sel_keys )
  222. delete[] sel_keys;
  223. }
  224. void AppSelectionSet::DeSelectEntity(ENTITY* entity, bool emit_message )
  225. {
  226. HC_KEY* sel_keys = 0;
  227. int count = 0;
  228. if (entity)
  229. {
  230. vlist_remove(m_pSolidSelection, (void*) entity);
  231. if (m_SelectLevel == BODY_TYPE) // && body segments is true
  232. {
  233. sel_keys = new HC_KEY[1];
  234. count = HA_Compute_Geometry_Keys(entity, 1, sel_keys, "bodies");
  235. }
  236. else if (m_SelectLevel == FACE_TYPE)
  237. {
  238. count = HA_Compute_Geometry_Key_Count(entity, "faces");
  239. if( count > 0 )
  240. {
  241. sel_keys = new HC_KEY[count];
  242. HA_Compute_Geometry_Keys(entity, count, sel_keys, "faces");
  243. }
  244. }
  245. else if (m_SelectLevel == EDGE_TYPE)
  246. {
  247. count = HA_Compute_Geometry_Key_Count(entity, "edges");
  248. if( count > 0 )
  249. {
  250. sel_keys = new HC_KEY[count];
  251. HA_Compute_Geometry_Keys(entity, count, sel_keys, "edges");
  252. }
  253. }
  254. }
  255. if (count > 0)
  256. {
  257. for( int c = 0; c < count; c++)
  258. HSelectionSet::DeSelect(sel_keys[c], emit_message); // call base class fcn for each key
  259. }
  260. if( sel_keys )
  261. delete[] sel_keys;
  262. }
  263. bool AppSelectionSet::IsSelected(HC_KEY key)
  264. {
  265. if (((AppModel *) m_pView->GetModel())->IsSolidModel() != true)
  266. {
  267. char type[1024];
  268. HC_Show_Key_Type(key, type);
  269. if (!streq(type, "segment"))
  270. key = HC_KShow_Owner_By_Key(key);
  271. }
  272. else
  273. {
  274. int count;
  275. if (m_SelectLevel == BODY_TYPE) // && body segments is true
  276. {
  277. ENTITY* entity = 0;
  278. entity = HA_Compute_Entity_Pointer(key, m_SelectLevel);
  279. if (entity)
  280. count = HA_Compute_Geometry_Keys(entity, 1, &key, "bodies");
  281. assert(count == 1);
  282. }
  283. }
  284. // call base class function with the computed key
  285. return HSelectionSet::IsSelected(key);
  286. }
  287. // If it is a call to select something from HNet message,
  288. // by pass our selection functionality and just call the
  289. // vanilla Select. JUST SELECT THIS KEY!
  290. // This is to work around the case where the master client
  291. // is in some selection mode (face) and slave is in some (body)
  292. void AppSelectionSet::SelectFromMessage(HC_KEY key, int num_include_keys, HC_KEY * include_keys, bool emit_message)
  293. {
  294. HSelectionSet::Select( key, num_include_keys, include_keys, emit_message);
  295. }
  296. // See the Description for SelectFromMessage
  297. void AppSelectionSet::DeSelectFromMessage(HC_KEY key, bool emit_message)
  298. {
  299. HSelectionSet::DeSelect(key, emit_message);
  300. }