0012121: Optimization of existing selection classes
[occt.git] / src / OpenGl / OpenGl_togl_parray.cxx
1 /*
2 File OpenGl_togl_parray.c
3 Created 16/06/2000 : ATS : G005
4 */
5
6 #include <OpenGl_tgl_all.hxx>
7 #include <InterfaceGraphic_Graphic3d.hxx>
8 #include <OpenGl_tgl.hxx>
9 #include <OpenGl_tgl_funcs.hxx>
10 #include <OpenGl_tgl_subrs.hxx>
11 #include <OpenGl_tgl_utilgr.hxx>
12
13 void EXPORT call_togl_parray
14 (
15  CALL_DEF_GROUP *agroup,
16  CALL_DEF_PARRAY *parray
17  )
18 {
19   if (! agroup->IsOpen) call_togl_opengroup (agroup);
20   call_subr_parray (parray);
21   if (! agroup->IsOpen) call_togl_closegroup (agroup);
22   return;
23 }
24
25 //=======================================================================
26 //function : call_togl_parray_remove
27 //purpose  : Remove the driver's element corresponding to the primitives
28 //           array <thePArray> and clean its visualization data. The driver
29 //           clears all its references to array and stops displaying it.
30 //           <theGroup> is the group that has added <thePArray> to driver.
31 //=======================================================================
32
33 void EXPORT call_togl_parray_remove (CALL_DEF_GROUP*  theGroup,
34                                      CALL_DEF_PARRAY* thePArray)
35 {
36   CALL_DEF_PARRAY* anElData;
37   Tint aBegId, aEndId, aCurId; 
38   TSM_ELEM anElem;
39
40   // set edit mode and open struct
41   call_func_set_edit_mode (CALL_PHIGS_EDIT_REPLACE);
42   call_func_open_struct (theGroup->Struct->Id);
43
44   // get begin label
45   call_func_set_elem_ptr (0);
46   if (call_func_set_elem_ptr_label (theGroup->LabelBegin) == TFailure)
47     return;
48   call_func_inq_elem_ptr (&aBegId);
49
50   // get end label
51   if (call_func_set_elem_ptr_label (theGroup->LabelEnd) == TFailure)
52     return;
53   call_func_inq_elem_ptr (&aEndId);
54
55   // iterate between labels and search for the array
56   if (aBegId != aEndId)
57   {
58     // move one element back
59     if (call_func_offset_elem_ptr (-1)   == TFailure ||
60         call_func_inq_elem_ptr (&aCurId) == TFailure)
61       return;
62
63     // iterate from end label to begin label
64     while (aCurId > aBegId)
65     {
66       call_func_inq_elem (&anElem);
67
68       // compare element with the array
69       if (anElem.el == TelParray && anElem.data.pdata == (void* )thePArray)
70       {
71         anElData = (CALL_DEF_PARRAY* )anElem.data.pdata;
72
73         // validate for correct pointer
74         if (anElData->num_bounds  == thePArray->num_bounds  && 
75             anElData->num_edges   == thePArray->num_edges   &&
76             anElData->num_vertexs == thePArray->num_vertexs &&
77             anElData->type        == thePArray->type)
78         {
79           call_func_del_elem();
80           break;
81         }
82       }
83       else
84       {
85         call_func_offset_elem_ptr (-1);
86         call_func_inq_elem_ptr (&aCurId);
87       }
88     }
89   }
90
91   call_func_close_struct();
92 }