#define  OPENGL_TELEM_VIEW_H
 
 #include <OpenGl_telem.hxx>
+#include <OpenGl_tgl.hxx>
+#include <NCollection_List.hxx>
 
 typedef  struct
 {
   Tfloat    zmax;
 } Tlimit3;
 
+
+
 typedef  enum
 {
   TelParallel, TelPerspective
   Tint        border_indicator;
   TEL_COLOUR  border_colour;
   Tint        active_status;
+  NCollection_List<CALL_DEF_PLANE> clipping_planes;
   struct
   {
     Tfloat  vrp[3];
 
     // redraw to new Rendering Context
     call_func_redraw_all_structs_begin (aview->WsId);
 
+    call_togl_setplane( aview ); /* update clipping planes */
+
     if (background == 0)
     {
       glClearColor(1.0, 1.0, 1.0, 1.0);
 
 #include <OpenGl_tgl_funcs.hxx>
 #include <OpenGl_tgl_subrvis.hxx>
 #include <OpenGl_FrameBuffer.hxx>
-#include <OpenGl_ResourceCleaner.hxx>
 #include <InterfaceGraphic_Graphic3d.hxx>
 #include <InterfaceGraphic_Visual3d.hxx>
 
       aFrameBuffer->BindBuffer();
       swap = 0; // no need to swap buffers
     }
-    OpenGl_ResourceCleaner::GetInstance()->Cleanup();
+
     call_func_redraw_all_structs_begin (aview->WsId);
+    call_togl_setplane( aview ); /* apl - OCC22108: update clipping planes */
     if (anunderlayer->ptrLayer)
     {
       call_togl_redraw_layer2d (aview, anunderlayer);
       glScissor ((GLint )x,
                  (GLint )((int )aview->DefWindow.dy - (y + height)),
                  (GLsizei )width, (GLsizei )height);
-      OpenGl_ResourceCleaner::GetInstance()->Cleanup();
       call_func_redraw_all_structs_begin (aview->WsId);
+      call_togl_setplane( aview ); /* apl - OCC22108: update clipping planes */
       if (anunderlayer->ptrLayer)
       {
         call_togl_redraw_layer2d (aview, anunderlayer);
 
 
 #include <OpenGl_tgl_all.hxx>
 #include <OpenGl_tgl.hxx>
+#include <OpenGl_tgl_funcs.hxx>
+#include <OpenGl_telem_view.hxx>
+#include <OpenGl_tsm_ws.hxx>
 #include <GL/gl.h>
 
+
+struct TEL_VIEW_DATA
+{
+  TEL_VIEW_REP    vrep;
+#ifdef CAL_100498
+  Tmatrix3        inverse_matrix;/* accelerates UVN2XYZ conversion */
+#endif
+  IMPLEMENT_MEMORY_OPERATORS
+};
+typedef TEL_VIEW_DATA *tel_view_data;   /* Internal data stored for every view rep */
+
+
 void EXPORT
 /* unimplemented */
 call_togl_setplane
  )
 {
 #ifdef GER61454
+
+  CMN_KEY_DATA    key;
+  tel_view_data   vptr;
+  TEL_VIEW_REP   *call_viewrep;
   CALL_DEF_PLANE *plane;
-  int j,planeid ;
-
-  if( aview->Context.NbActivePlane > 0 ) {
-    for( j=0 ; j<aview->Context.NbActivePlane ; j++ ) {
-      plane = &aview->Context.ActivePlane[j];
-      if( plane->PlaneId > 0 ) {
-        planeid = GL_CLIP_PLANE2 + j;
-        if( plane->Active ) {
-          GLdouble equation[4];
-          equation[0] = plane->CoefA;      
-          equation[1] = plane->CoefB;      
-          equation[2] = plane->CoefC;      
-          equation[3] = plane->CoefD;
-          /*
-          Activates new clip planes
-          */ 
-          glClipPlane( planeid , equation );     
-          if( !glIsEnabled( planeid ) ) glEnable( planeid );     
-        } else {
-          if( glIsEnabled( planeid ) ) glDisable( planeid );     
-        }
-      }
-    }
-  }
-  /*
-  Disable the remainder Clip planes
-  */
-  for( j=aview->Context.NbActivePlane ; j<call_facilities_list.MaxPlanes ; j++ ) {
-    planeid = GL_CLIP_PLANE2 + j;
-    if( glIsEnabled( planeid ) ) glDisable( planeid );
-  }
+  int j;
+  
+  // return view representation 
+  
+  if( aview->ViewId == 0 )
+    return;                 // no modifications on default view
+
+  if( TsmGetWSAttri( aview->WsId, WSViews, &key ) != TSuccess )
+    return;
+
+  vptr = (tel_view_data)key.pdata;
+  if( !vptr )
+    return;
+
+  call_viewrep = &vptr->vrep;
+  
+  // clear clipping planes information
+  call_viewrep->clipping_planes.Clear();
+  // update information 
+  if( aview->Context.NbActivePlane > 0 )
+    for( j=0 ; j<aview->Context.NbActivePlane ; j++ )
+      call_viewrep->clipping_planes.Append( aview->Context.ActivePlane[j] );
+ 
 #endif
-  return;
+return;
 }
 
     TsmGetWSAttri (aview->WsId, WSWindow, &data);
     if (TxglWinset (call_thedisplay, (Window) data.ldata) == TSuccess) {
       call_func_redraw_all_structs_begin (aview->WsId);
+      
+      call_togl_setplane( aview ); /* update clipping planes */
+
       if (anunderlayer->ptrLayer)
         call_togl_redraw_layer2d (aview, anunderlayer);
       call_func_redraw_all_structs_proc (aview->WsId);
 
 10-07-96 : FMN ; Suppression #define sur calcul matrice
 
 ************************************************************************/
-#define GER61454        //GG 14-09-99 Activates the model clipping planes
 
 /*----------------------------------------------------------------------*/
 /*
       waitwait = 1;
       call_togl_viewmapping( aview, waitwait );
       call_togl_cliplimit( aview, waitwait );
-#ifdef GER61454
-      call_togl_setplane( aview );
-#endif
       TelSetViewRepresentation( aview->WsId, aview->ViewId, &call_viewrep );
     }
   }
 
 #include <OpenGl_tsm_ws.hxx>
 #include <OpenGl_txgl.hxx>
 #include <OpenGl_Memory.hxx>
+#include <Standard_TypeDef.hxx>
 
 /*----------------------------------------------------------------------*/
 /*
 * Variables statiques
 */
 
-static void set_clipplanes( tel_view_rep );
+static void set_clipplanes( tel_view_rep );      /* front & back clip planes */
+static void set_userclipplanes( tel_view_rep );  /* user-defined clipping planes */
+
 #ifdef CAL_100498
 static  void  TelEvalInverseMatrix( Tfloat*, Tfloat*, Tfloat*, /*vrp,vpn,vup*/
                                     Tfloat, Tmatrix3 );        /*vpd,inverse*/
       vrep->extra.map.viewport.zmin = ( float )0.0;
     vrep->extra.map.viewport.xmax = vrep->extra.map.viewport.ymax =
       vrep->extra.map.viewport.zmax = ( float )1.0;
+    vrep->clipping_planes.Clear();
     return TSuccess;
   }
 
   vptr = (tel_view_data)key.pdata ; /* Obtain defined view data*/
   if( !vptr ) return TFailure; /* no view defined yet */ 
 
+ 
 #ifdef TRACE_MATRIX
   printf("OpenGl_view.c::TelSetViewIndex::glMatrixMode(GL_MODELVIEW) \n"); 
 #endif
     glDisable(GL_NORMALIZE);
   glMatrixMode(GL_MODELVIEW);
   set_clipplanes( &(vptr->vrep) );
+  
 
   glLoadMatrixf((GLfloat *) vptr->vrep.orientation_matrix );
+  set_userclipplanes( &(vptr->vrep) ); /* set clipping planes defined by user */
 
 #ifdef ENVTEX
   /*
   pr_matrix( vptr->vrep.mapping_matrix );
 #endif
 
-
   return vptr->vrep.active_status == TOn ? TSuccess : TFailure;
 }
 
   if( !vptr ) return TFailure; /* no view defined yet */ 
 
   set_clipplanes( &(vptr->vrep) );
+  set_userclipplanes( &(vptr->vrep) );
 
 #ifdef TRACE_MATRIX
   printf("OpenGl_view.c::TelSetViewProjection::glMatrixMode(GL_PROJECTION) \n"); 
 #endif
   glMatrixMode(GL_PROJECTION);
   glLoadMatrixf((GLfloat *) vptr->vrep.mapping_matrix );
-
-
+ 
   return vptr->vrep.active_status == TOn ? TSuccess : TFailure;
 }
 
   glLoadMatrixf( (GLfloat *) mat );
 }
 
+static void
+set_userclipplanes( tel_view_rep vrep )
+{
+  int j,planeid;
+  CALL_DEF_PLANE* plane;
+
+#ifdef TRACE_MATRIX
+  printf("OpenGl_view.c::set_userclipplanes::glMatrixMode(GL_MODELVIEW) \n"); 
+#endif
+
+  
+  NCollection_List<CALL_DEF_PLANE>::Iterator planeIter(vrep->clipping_planes);
+  
+  // go through all of planes in the list & preview them
+  for( j=0 ; planeIter.More(); planeIter.Next(), j++ ) 
+  {
+    plane = const_cast<CALL_DEF_PLANE*>(&planeIter.Value());
+    
+    if( plane->PlaneId > 0 ) 
+    {
+      planeid = GL_CLIP_PLANE2 + j;
+
+      if( plane->Active ) 
+      {
+         // Activates new clip planes
+         GLdouble equation[4];
+         equation[0] = plane->CoefA;
+         equation[1] = plane->CoefB;
+         equation[2] = plane->CoefC;
+         equation[3] = plane->CoefD;
+         
+          glClipPlane( planeid , equation );     
+          if( !glIsEnabled( planeid ) ) glEnable( planeid );     
+      } 
+      else 
+      {
+       if( glIsEnabled( planeid ) ) glDisable( planeid );     
+      }
+    }
+  }   //for( ; planeIter.More(); planeIter.Next() ) 
+
+  // Disable the remainder Clip planes
+
+  for( j=vrep->clipping_planes.Size(); j < call_facilities_list.MaxPlanes; j++ )
+  {
+    planeid = GL_CLIP_PLANE2 + j; 
+
+    if( glIsEnabled( planeid ) ) 
+      glDisable( planeid );
+   }
+
+  
+}
+
 /*----------------------------------------------------------------------*/
 
 TStatus