HNetMessageRegistrar.h
1 // Copyright (c) Tech Soft 3D, Inc.
2 //
3 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
4 // and considered a trade secret as defined under civil and criminal statutes.
5 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
6 // unauthorized use or misappropriation of its trade secrets. Use of this information
7 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
8 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
9 
10 #ifndef _HNetMessageRegistrar_H
11 #define _HNetMessageRegistrar_H
12 
13 #ifndef _HNET_MESSAGE_REGISTRAR
14 #define _HNET_MESSAGE_REGISTRAR
15 
16 #ifdef H_PACK_8
17 #pragma pack(push)
18 #pragma pack(8)
19 #endif
20 
21 #include "HBaseView.h"
22 #include "HOpObjectAnnotate.h"
23 #include "HOpCreateNurbs3D.h"
24 #include "HMarkupManager.h"
25 #include "vhash.h"
26 #include <stdio.h>
27 
28 
32 class MVOMessageHandler: public HNetMessageHandler {
33 
34 public:
39  m_pHBaseView = hbaseview;
40  };
47  const char * message_type,
48  const char * data,
49  unsigned int data_length) {;};
50 
51 protected:
54 };
55 
60 public:
71  const char * message_type,
72  const char * data,
73  unsigned int data_length) {
74  m_pHBaseView->SetCameraFromMessage(data, data_length);
75  };
76 };
77 
82 public:
93  const char * message_type,
94  const char * data,
95  unsigned int data_length) {
96  m_pHBaseView->SetRenderModeFromMessage(data, data_length);
97  };
98 };
99 
100 
105 public:
116  const char * message_type,
117  const char * data,
118  unsigned int data_length) {
119 
120  m_pHBaseView->InsertHSFDataFromMessage(data, data_length);
121  };
122 };
123 
128 public:
133 
140  const char * message_type,
141  const char * data,
142  unsigned int data_length) {
143 
144  m_pHBaseView->FlushFromMessage(data, data_length);
145  };
146 };
147 
148 
152 class HDevNullMessageHandler: public HNetMessageHandler {
153 public:
160  const char * message_type,
161  const char * data,
162  unsigned int data_length) {
163 
164  };
165 };
166 
172 public:
186  const char * message_type,
187  const char * data,
188  unsigned int data_length) {
189 
190  if (strcmp(message_type,"H_DESELECT_ALL") == 0)
192  else if (strcmp(message_type,"H_DELETE_SELECTION_LIST") == 0)
194  else
195  m_pHBaseView->SelectFromMessage(data, data_length);
196  };
197 };
198 
199 
204 public:
209 
216  const char * message_type,
217  const char * data,
218  unsigned int data_length) {
219 
220  m_pHBaseView->DeleteByKeyFromMessage(data, data_length);
221  };
222 };
223 
224 
229 public:
240  const char * message_type,
241  const char * data,
242  unsigned int data_length) {
243 
244  m_pHBaseView->SetWindowColorFromMessage(data, data_length);
245  };
246 };
247 
252 public:
263  const char * message_type,
264  const char * data,
265  unsigned int data_length) {
266 
267  m_pHBaseView->SetModellingMatrixFromMessage(data, data_length);
268  };
269 };
270 
276 public:
290  const char * message_type,
291  const char * data,
292  unsigned int data_length) {
293 
294  if (strcmp(message_type,"H_INSERT_MARKUP_LAYER_HSF_DATA") == 0)
296  else if (strcmp(message_type,"H_SET_MARKUP_LAYER") == 0)
298  else if (strcmp(message_type,"H_DISABLE_CURRENT_MARKUP_LAYER") == 0)
300  };
301 };
302 
307 public:
312 
319  const char * message_type,
320  const char * data,
321  unsigned int data_length) {
322 
324  };
325 };
326 
332 public:
346  const char * message_type,
347  const char * data,
348  unsigned int data_length) {
349 
350  if (strcmp(message_type,"H_INSERT_NURBS") == 0)
352  else if(strcmp(message_type,"H_FINISH_NURBS_EDITING") == 0)
354  else if(strcmp(message_type,"H_MODIFY_CONTROL_POINT") == 0)
356  };
357 };
358 
363 public:
374  const char * message_type,
375  const char * data,
376  unsigned int data_length) {
377  m_pHBaseView->SetHandednessFromMessage(data, data_length);
378  };
379 };
380 
385 public:
396  const char * message_type,
397  const char * data,
398  unsigned int data_length) {
399  m_pHBaseView->SetFontSizeFromMessage(data, data_length);
400  };
401 };
402 
403 
405 
410 
411 public:
412 
420  HBaseView * new_hbaseview,
421  HNetClient * new_hnetclient=0) {
422 
423  hbaseview=new_hbaseview;
424  hnetclient=new_hnetclient;
425 
426  if(!hnetclient)
427  message_handler_hash = new_vhash(1, malloc, free);
428  else
429  message_handler_hash = 0;
430 
431  default_message_handler=0;
432 
433  };
434 
440 
441  UnSetHandlers();
442 
443  if(message_handler_hash) {
444  delete_vhash(message_handler_hash);
445  message_handler_hash=0;
446  }
447  }
448 
458  virtual void SetHandlers(){
459 
461  SetMessageHandler( new HSetRenderModeMessageHandler(hbaseview), "H_SET_RENDERMODE");
462  SetMessageHandler( new HInsertHSFDataMessageHandler(hbaseview), "H_INSERT_HSF_DATA");
463  SetMessageHandler( new HFlushBaseViewMessageHandler(hbaseview), "H_FLUSH_BASE_VIEW");
464  SetMessageHandler( new HDevNullMessageHandler(), "H_DEV_NULL_DATA");
465  SetMessageHandler( new HSelectMessageHandler(hbaseview), "H_SELECT_ENTITY");
466  SetMessageHandler( new HSelectMessageHandler(hbaseview), "H_DESELECT_ALL");
467  SetMessageHandler( new HDeleteByKeyMessageHandler(hbaseview), "H_DELETE_BY_KEY");
468  SetMessageHandler( new HSelectMessageHandler(hbaseview), "H_DELETE_SELECTION_LIST");
469  SetMessageHandler( new HSetModellingMatrixMessageHandler(hbaseview), "H_SET_MODELLING_MATRIX");
470  SetMessageHandler( new HAnnotateObjectMessageHandler(hbaseview), "H_ANNOTATE_OBJECT");
471  SetMessageHandler( new HNurbsMessageHandler(hbaseview), "H_INSERT_NURBS");
472  SetMessageHandler( new HNurbsMessageHandler(hbaseview), "H_MODIFY_CONTROL_POINT");
473  SetMessageHandler( new HNurbsMessageHandler(hbaseview), "H_FINISH_NURBS_EDITING");
474  SetMessageHandler( new HSetWindowColorMessageHandler(hbaseview), "H_SET_WINDOW_COLOR");
475  SetMessageHandler( new HMarkupMessageHandler(hbaseview), "H_DISABLE_MARKUP_LAYER");
476  SetMessageHandler( new HMarkupMessageHandler(hbaseview), "H_SET_MARKUP_LAYER");
477  SetMessageHandler( new HMarkupMessageHandler(hbaseview), "H_INSERT_MARKUP_LAYER_HSF_DATA");
478  SetMessageHandler( new HSetHandednessMessageHandler(hbaseview), "H_SET_HANDEDNESS");
479  SetMessageHandler( new HSetFontSizeMessageHandler(hbaseview), "H_SET_FONT_SIZE");
480 
481  };
482 
488  virtual void UnSetHandlers(){
489 
490  if(hnetclient){
491 
492  hnetclient->EnumerateMessageHandlers(
493  net_unset_message_handler_helper, hnetclient);
494 
495  }else
496  if(message_handler_hash){
497  vhash_string_key_map_function(
498  message_handler_hash,
499  non_net_unset_message_handler_helper,
500  (void*)this);
501  }
502 
503  };
504 
529  virtual HNetMessageHandler * SetMessageHandler(
530  HNetMessageHandler * handler,
531  const char * message_type)
532  {
533  HNetMessageHandler * old_handler=0;
534  if(hnetclient)
535  old_handler = hnetclient->SetMessageHandler(handler,message_type);
536  else
537  if(message_type){
538  old_handler = (HNetMessageHandler *)vhash_remove_string_key(message_handler_hash, message_type);
539  if(handler)
540  vhash_insert_string_key(message_handler_hash, message_type, (void*) handler);
541  }else{
542  if(default_message_handler) old_handler = default_message_handler;
543  default_message_handler = handler;
544  }
545  return old_handler;
546  }
547 
557  bool ReadSnapFile(const char * file_name) {
558 
559  FILE * file = fopen(file_name,"rb");
560 
561  if(file==NULL) return false;
562  if(hnetclient) return false;
563 
564  unsigned long line_number = 0;
565  unsigned long line_buffer_size = 1024;
566  char * line_buffer;
567  unsigned long n;
568  unsigned long expected_n;
569  int a_char;
570  int read_again = 1;
571 
572  line_buffer = (char*) malloc(line_buffer_size);
573  fseek(file,0,SEEK_SET);
574 
575 READ_A_LINE:
576  n=0;
577  expected_n=0;
578  line_number++;
579 
580  while(1) {
581  /*resize buffer as needed*/
582  if(n == line_buffer_size) {
583  char * new_line_buffer;
584  new_line_buffer = (char*) malloc(line_buffer_size*2);
585  memcpy(new_line_buffer, line_buffer, line_buffer_size);
586  free(line_buffer);
587  line_buffer = new_line_buffer;
588  line_buffer_size = line_buffer_size*2;
589  }
590  a_char = fgetc(file);
591  if(a_char == EOF) {
592  read_again=0;
593  break;
594  }
595  if(expected_n) {
596  line_buffer[n] = (char) a_char;
597  n++;
598  if(n==expected_n) {
599  /*have a whole line*/
600  ProcessMessage(line_buffer, n);
601  break;
602  }
603  }else{
604  if(a_char == 0x0D || a_char == 0x0A) {
605  if(n == 0) continue;
606  /*this is a error in the file*/
607  read_again=0;
608  break;
609  }
610  if (a_char == ' ') {
611  line_buffer[n] = '\0';
612  sscanf(line_buffer, "%ld", &expected_n);
613  n=0;
614  }else{
615  line_buffer[n] = (char) a_char;
616  n++;
617  }
618  }
619  }
620  if(read_again)
621  goto READ_A_LINE;
622  free(line_buffer);
623  return true;
624  };
625 
626 
627 protected:
628 
636  virtual void ProcessMessage(
637  const char * message,
638  unsigned long message_length) {
639 
640  if(hnetclient) return;
641 
642  char * message_type = (char*) malloc(message_length);
643  unsigned long n = 0;
644 
645  while(n < message_length && message[n] != ' ') {
646  message_type[n] = message[n];
647  n++;
648  }
649  message_type[n] = '\0';
650  n++;
651  HNetMessageHandler * message_handler =
652  (HNetMessageHandler *) vhash_lookup_string_key(message_handler_hash, message_type);
653 
654  if(!message_handler)
655  message_handler = default_message_handler;
656  if(message_handler)
657  message_handler->ProcessMessage(message_type, &message[n], message_length-n);
658  free(message_type);
659  }
660 
664  HNetClient * hnetclient;
665 
666 private:
667  struct vhash_s * message_handler_hash;
668  HNetMessageHandler * default_message_handler;
669 
670  static void net_unset_message_handler_helper(
671  void * handler,
672  const char * message,
673  void * user_data){
674 
675  ((HNetClient*)user_data)->SetMessageHandler(0,message);
676  delete (HNetMessageHandler*)handler;
677  };
678 
679  static void non_net_unset_message_handler_helper(
680  void * handler,
681  const char * message,
682  void * user_data){
683 
684  HNetMessageRegistrar * self = (HNetMessageRegistrar *) user_data;
685  self->SetMessageHandler(0,message);
686  delete (HNetMessageHandler*)handler;
687  };
688 
689 };
690 
691 
692 #ifdef H_PACK_8
693 #pragma pack(pop)
694 #endif
695 
696 #endif
697 #endif
698 
699 
700 
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:239
HInsertHSFDataMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:109
HBaseView * m_pHBaseView
A pointer to an HBaseView object.
Definition: HNetMessageRegistrar.h:49
virtual void SetHandlers()
Definition: HNetMessageRegistrar.h:458
Definition: HNetMessageRegistrar.h:152
HAnnotateObjectMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:311
virtual void FlushFromMessage(const char *in_data, unsigned int data_length)
HSetHandednessMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:367
Definition: HNetMessageRegistrar.h:228
HNetClient * hnetclient
This is the HNetClient for this registrar.
Definition: HNetMessageRegistrar.h:664
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:92
HSetRenderModeMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:86
static void FinishNurbsEditingFromMessage(const char *in_data, unsigned int data_length, HBaseView *pView)
The HNetMessageRegistrar class maps messages from HNetClients or .snap files to MVO calls...
Definition: HNetMessageRegistrar.h:409
HMarkupManager * GetMarkupManager()
HSetWindowColorMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:233
virtual void SetFontSizeFromMessage(const char *in_data, unsigned int data_length)
virtual void DisableCurrentMarkupLayerFromMessage(const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:81
HSetCameraMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:64
Definition: HNetMessageRegistrar.h:362
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:139
HSelectMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:176
Definition: HNetMessageRegistrar.h:203
Definition: HNetMessageRegistrar.h:331
bool ReadSnapFile(const char *file_name)
Definition: HNetMessageRegistrar.h:557
HSetFontSizeMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:389
HNetMessageRegistrar(HBaseView *new_hbaseview, HNetClient *new_hnetclient=0)
Definition: HNetMessageRegistrar.h:419
HBaseView * hbaseview
This is the HBaseView for this registrar.
Definition: HNetMessageRegistrar.h:662
Definition: HNetMessageRegistrar.h:59
HFlushBaseViewMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:132
virtual HNetMessageHandler * SetMessageHandler(HNetMessageHandler *handler, const char *message_type)
Definition: HNetMessageRegistrar.h:529
Definition: HNetMessageRegistrar.h:104
virtual void DeleteSelectionList(bool emit_message=false)
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:185
HDeleteByKeyMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:208
Definition: HNetMessageRegistrar.h:171
virtual void SetRenderModeFromMessage(const char *in_data, unsigned int data_length)
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:215
The HBaseView class defines and manages a view of model information.
Definition: HBaseView.h:332
MVOMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:38
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:289
virtual void SetWindowColorFromMessage(const char *in_data, unsigned int data_length)
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:345
Definition: HNetMessageRegistrar.h:384
virtual void DeSelectAllFromMessage()
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:115
HSetModellingMatrixMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:256
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:373
Definition: HNetMessageRegistrar.h:32
virtual void DeleteByKeyFromMessage(const char *in_data, unsigned int data_length)
virtual ~HNetMessageRegistrar()
Definition: HNetMessageRegistrar.h:439
Definition: HNetMessageRegistrar.h:251
static void AnnotateObjectFromMessage(HBaseView *pView, const char *in_data, unsigned int data_length)
static void InsertNurbsFromMessage(const char *in_data, unsigned int data_length, HBaseView *m_pView)
Definition: HNetMessageRegistrar.h:306
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:395
Definition: HNetMessageRegistrar.h:127
virtual void SetModellingMatrixFromMessage(const char *in_data, unsigned int data_length)
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:318
virtual void SetMarkupLayerFromMessage(const char *data, unsigned int data_length)
virtual void UnSetHandlers()
Definition: HNetMessageRegistrar.h:488
Definition: HNetMessageRegistrar.h:275
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:262
virtual void InsertHSFDataFromMessage(const char *in_data, unsigned int data_length)
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:159
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:46
virtual void SelectFromMessage(const char *in_data, unsigned int data_length)
HNurbsMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:336
HMarkupMessageHandler(HBaseView *hbaseview)
Definition: HNetMessageRegistrar.h:280
virtual void ProcessMessage(const char *message, unsigned long message_length)
Definition: HNetMessageRegistrar.h:636
static void ModifyControlPointFromMessage(const char *in_data, unsigned int data_length, HBaseView *pView)
virtual void InsertMarkupSegmentFromMessage(const char *in_data, unsigned int data_length)
virtual void SetHandednessFromMessage(const char *in_data, unsigned int data_length)
void ProcessMessage(const char *message_type, const char *data, unsigned int data_length)
Definition: HNetMessageRegistrar.h:70
virtual void SetCameraFromMessage(const char *data, unsigned int data_length)