0032121: Draw Harness, ViewerTest - implement -reset option for vlight command
authorkgv <kgv@opencascade.com>
Fri, 9 Jul 2021 20:22:29 +0000 (23:22 +0300)
committerkgv <kgv@opencascade.com>
Mon, 12 Jul 2021 17:50:25 +0000 (20:50 +0300)
vlight command has been revised to provide more friendly syntax.
Command now accepts light index or name as first argument.
Added arguments -enable/-disable for managing enabled state.
Added argument -reset to reset light parameters to default values.

V3d_Viewer::SetDefaultLights() now sets names "headlight" and "ambient" to created lights.
Graphic3d_TypeOfLightSource enumeration values have been renamed to avoid shortcuts.
Draw::Atof(), applied corrections to avoid explicit new/delete calls.

44 files changed:
samples/tcl/Penrose.tcl
samples/tcl/cpu.tcl
samples/tcl/pathtrace_ball.tcl
samples/tcl/pathtrace_cube.tcl
samples/tcl/pathtrace_materials.tcl
samples/tcl/raytrace.tcl
samples/webgl/WasmOcctView.cpp
src/AIS/AIS_LightSource.cxx
src/Draw/Draw_VariableCommands.cxx
src/Graphic3d/Graphic3d_CLight.cxx
src/Graphic3d/Graphic3d_CLight.hxx
src/Graphic3d/Graphic3d_LightSet.cxx
src/Graphic3d/Graphic3d_LightSet.hxx
src/Graphic3d/Graphic3d_ShaderManager.cxx
src/Graphic3d/Graphic3d_TypeOfLightSource.hxx
src/OpenGl/OpenGl_ShaderManager.cxx
src/OpenGl/OpenGl_ShadowMap.cxx
src/OpenGl/OpenGl_View.cxx
src/OpenGl/OpenGl_View_Raytrace.cxx
src/V3d/V3d_AmbientLight.cxx
src/V3d/V3d_DirectionalLight.cxx
src/V3d/V3d_PositionalLight.cxx
src/V3d/V3d_SpotLight.cxx
src/V3d/V3d_Viewer.cxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/opengl/data/general/double_precision
tests/opengl/data/general/light_off
tests/opengl/data/raytrace/bug25201
tests/opengl/data/raytrace/refraction
tests/opengl/data/shaderprog/phong_fuse
tests/opengl/data/shaderprog/phong_fuse2
tests/opengl/data/shading/flat_fuse1
tests/opengl/data/shading/gouraud_dir2
tests/opengl/data/shading/gouraud_pos1
tests/opengl/data/shading/gouraud_spot1
tests/opengl/data/shading/phong_dir2
tests/opengl/data/shading/phong_pos2
tests/opengl/data/shading/phong_pos3
tests/opengl/data/shading/phong_pos4
tests/opengl/data/shading/phong_spot1
tests/opengl/data/textures/bug24725
tests/v3d/light_source/display_all
tests/v3d/light_source/headlight
tests/v3d/light_source/manipulator

index 77a77b6..c9782f8 100644 (file)
@@ -62,9 +62,9 @@ vrenderparams -rayTrace -fsaa on -reflections off -shadows off
 vcamera -persp -fovy 25
 vviewparams -eye 14 -14 6.8 -up 0 0 1 -at 4 -4 0 -scale 70
 vsetdispmode 1
-vlight def
-vlight add directional direction 1 -2 -10 head 1 color white
-vlight add directional direction 0 -10 0 head 1 color white
+vlight -defaults
+vlight dirlight1 -type DIRECTIONAL -direction 1 -2 -10 -head 1 -color WHITE
+vlight dirlight2 -type DIRECTIONAL -direction 0 -10 0  -head 1 -color WHITE
 
 # display boxes
 vdisplay b1 b2 b3 b4 b5 b6 b7 b8 b9 b10
index a8bebfa..c023799 100644 (file)
@@ -243,17 +243,15 @@ ttranslate crpk_47 18.0 27.6 0
 
 eval compound $lrpk brpk
 
-# show result in plain 3d viewer
+# show result in 3d viewer
+vinit View1
+vclear
+vsetdispmode 1
+vrenderparams -msaa 8
+vlight -clear
+vlight amblight -type AMBIENT
+vlight dirlight -type DIRECTIONAL -direction 1 -1 -2 -head 1
 if [info exists i7_show_3dview] {
-  vinit Driver1/Viewer1/View1
-  vclear 
-  vsetdispmode 1
-  vrenderparams -msaa 8
-
-  vlight clear
-  vlight add amb
-  vlight add directional direction 1 -1 -2 head 1
-
   vdisplay case
   vsetcolor case GRAY70
 
@@ -318,12 +316,8 @@ XSetColor D rpk1 GRAY70
 XSetColor D rpk2 80664D
 XSetColor D rpk3 GRAY70
 
-XShow D
-vlight clear
-vlight add amb
-vlight add directional direction 1 -1 -2 head 1
-vsetdispmode 1
-vrenderparams -msaa 8
+# display in 3D Viewer
+XDisplay -dispMode 1 D -explore
 vfit
 
 # save to STEP if variable i7_save_xde is defined (specifies file name)
index 9e9f79e..25952d6 100644 (file)
@@ -59,10 +59,10 @@ for {set i 0} {$i < 12} {incr i} {
 }
 
 # Configure light sources
-vlight -change 0 -head 0
+vlight -change 0 -headLight 0
 vlight -change 0 -direction -0.25 -1 -1
-vlight -change 0 -sm   0.3
-vlight -change 0 -int 10.0
+vlight -change 0 -smoothAngle 17
+vlight -change 0 -intensity 10.0
 
 # Load environment map
 vtextureenv on 1
index 0aca0ae..9521a60 100644 (file)
@@ -15,7 +15,7 @@ vglinfo
 
 # setup light sources
 vlight -clear
-vlight -add positional -head 0 -pos 0.5 0.5 0.85 -sm 0.06 -int 30.0
+vlight -add POSITIONAL -headLight 0 -pos 0.5 0.5 0.85 -smoothRadius 0.06 -intensity 30.0 -name pntlight
 
 vvbo 0
 vsetdispmode 1
index b4d3868..895dede 100644 (file)
@@ -211,8 +211,8 @@ vviewparams -size 170.508
 
 # Restore light source parameters
 vlight -clear
-vlight -add ambient
-vlight -add directional -direction -0.303949 -0.434084 -0.848048 -smoothness 0.3 -intensity 12
+vlight -add AMBIENT -name amblight
+vlight -add DIRECTIONAL -direction -0.303949 -0.434084 -0.848048 -smoothAngle 17 -intensity 12 -name dirlight
 
 # Load environment map
 vtextureenv on 1
index 74527dd..cf1f972 100644 (file)
@@ -31,7 +31,7 @@ vsetcolor glass brown
 vsettransparency glass 0.6
 
 # add light source for shadows
-vlight new spot pos -100 -100 300
+vlight spot -type SPOT -pos -100 -100 300
 
 # set white background and fit view
 vbackground -color WHITE
index 1054046..cf2b86e 100644 (file)
@@ -313,7 +313,7 @@ bool WasmOcctView::initViewer()
   for (V3d_ListOfLight::Iterator aLightIter (aViewer->ActiveLights()); aLightIter.More(); aLightIter.Next())
   {
     const Handle(V3d_Light)& aLight = aLightIter.Value();
-    if (aLight->Type() == Graphic3d_TOLS_DIRECTIONAL)
+    if (aLight->Type() == Graphic3d_TypeOfLightSource_Directional)
     {
       aLight->SetCastShadows (true);
     }
index 49c718a..cd5f978 100644 (file)
@@ -75,10 +75,10 @@ AIS_LightSource::AIS_LightSource (const Handle(Graphic3d_CLight)& theLight)
   myOpposMarkerType (Aspect_TOM_O_POINT),
   mySize (50),
   myNbArrows (5),
-  myNbSplitsQuadric (theLight->Type() == Graphic3d_TOLS_AMBIENT ? 10 : 30),
+  myNbSplitsQuadric (theLight->Type() == Graphic3d_TypeOfLightSource_Ambient ? 10 : 30),
   myNbSplitsArrow (20),
-  myIsZoomable (theLight->Type() == Graphic3d_TOLS_POSITIONAL
-             || theLight->Type() == Graphic3d_TOLS_SPOT),
+  myIsZoomable (theLight->Type() == Graphic3d_TypeOfLightSource_Positional
+             || theLight->Type() == Graphic3d_TypeOfLightSource_Spot),
   myToDisplayName (true),
   myToDisplayRange (true),
   myToSwitchOnClick (true)
@@ -101,7 +101,7 @@ AIS_LightSource::AIS_LightSource (const Handle(Graphic3d_CLight)& theLight)
   myDrawer->ArrowAspect()->Aspect()->SetMarkerType (Aspect_TOM_EMPTY);
   myDrawer->ArrowAspect()->Aspect()->SetMarkerScale (2.0f);
   myArrowLineAspectShadow = new Graphic3d_AspectLine3d (Quantity_NOC_BLACK, Aspect_TOL_SOLID,
-                                                        theLight->Type() != Graphic3d_TOLS_AMBIENT ? 3.0f : 1.0f);
+                                                        theLight->Type() != Graphic3d_TypeOfLightSource_Ambient ? 3.0f : 1.0f);
 
   myDrawer->SetupOwnShadingAspect();
   myDrawer->ShadingAspect()->SetColor (aColor);
@@ -155,7 +155,7 @@ void AIS_LightSource::updateLightAspects()
   myDrawer->ArrowAspect()  ->SetColor (aColor);
   myDrawer->ArrowAspect()->Aspect()->ChangeFrontMaterial().SetColor (aColor);
 
-  if (myLightSource->Type() == Graphic3d_TOLS_DIRECTIONAL)
+  if (myLightSource->Type() == Graphic3d_TypeOfLightSource_Directional)
   {
     const Standard_Real anAngleTol = 2.0 * M_PI / 180.0;
     Aspect_TypeOfMarker aDirMark = Aspect_TOM_EMPTY;
@@ -179,7 +179,7 @@ void AIS_LightSource::updateLightTransformPersistence()
   Handle(Graphic3d_TransformPers) aTrsfPers = myTransformPersistence;
   switch (myLightSource->Type())
   {
-    case Graphic3d_TOLS_AMBIENT:
+    case Graphic3d_TypeOfLightSource_Ambient:
     {
       if (!myIsZoomable)
       {
@@ -194,7 +194,7 @@ void AIS_LightSource::updateLightTransformPersistence()
       }
       break;
     }
-    case Graphic3d_TOLS_DIRECTIONAL:
+    case Graphic3d_TypeOfLightSource_Directional:
     {
       Graphic3d_TransModeFlags aMode = myLightSource->IsHeadlight() ? Graphic3d_TMF_2d : Graphic3d_TMF_TriedronPers;
       if (myIsZoomable)
@@ -221,8 +221,8 @@ void AIS_LightSource::updateLightTransformPersistence()
       }
       break;
     }
-    case Graphic3d_TOLS_POSITIONAL:
-    case Graphic3d_TOLS_SPOT:
+    case Graphic3d_TypeOfLightSource_Positional:
+    case Graphic3d_TypeOfLightSource_Spot:
     {
       Graphic3d_TransModeFlags aMode = myLightSource->IsHeadlight()
                                      ? Graphic3d_TMF_CameraPers
@@ -265,7 +265,7 @@ void AIS_LightSource::updateLightLocalTransformation()
   myLocalTransformation.Nullify();
   switch (myLightSource->Type())
   {
-    case Graphic3d_TOLS_AMBIENT:
+    case Graphic3d_TypeOfLightSource_Ambient:
     {
       if (myIsZoomable)
       {
@@ -275,7 +275,7 @@ void AIS_LightSource::updateLightLocalTransformation()
       }
       break;
     }
-    case Graphic3d_TOLS_DIRECTIONAL:
+    case Graphic3d_TypeOfLightSource_Directional:
     {
       const gp_Pnt aLightPos = (myIsZoomable && !myLightSource->IsHeadlight())
                              ? myLightSource->DisplayPosition()
@@ -286,7 +286,7 @@ void AIS_LightSource::updateLightLocalTransformation()
       myLocalTransformation = new TopLoc_Datum3D (aTrsf);
       break;
     }
-    case Graphic3d_TOLS_POSITIONAL:
+    case Graphic3d_TypeOfLightSource_Positional:
     {
       if (myIsZoomable)
       {
@@ -296,7 +296,7 @@ void AIS_LightSource::updateLightLocalTransformation()
       }
       break;
     }
-    case Graphic3d_TOLS_SPOT:
+    case Graphic3d_TypeOfLightSource_Spot:
     {
       gp_Trsf aTrsf;
       const gp_Ax2 anAx2 (myIsZoomable ? myLightSource->Position() : gp::Origin(), -myLightSource->Direction());
@@ -317,11 +317,11 @@ void AIS_LightSource::setLocalTransformation (const Handle(TopLoc_Datum3D)& theT
   const gp_Trsf aTrsf = theTrsf->Transformation();
   switch (myLightSource->Type())
   {
-    case Graphic3d_TOLS_AMBIENT:
+    case Graphic3d_TypeOfLightSource_Ambient:
     {
       break;
     }
-    case Graphic3d_TOLS_DIRECTIONAL:
+    case Graphic3d_TypeOfLightSource_Directional:
     {
       gp_Dir aNewDir = (-gp::DZ()).Transformed (aTrsf);
       myLightSource->SetDirection (aNewDir);
@@ -332,13 +332,13 @@ void AIS_LightSource::setLocalTransformation (const Handle(TopLoc_Datum3D)& theT
       }
       break;
     }
-    case Graphic3d_TOLS_POSITIONAL:
+    case Graphic3d_TypeOfLightSource_Positional:
     {
       gp_Pnt aNewPos = gp::Origin().Transformed (aTrsf);
       myLightSource->SetPosition (aNewPos);
       break;
     }
-    case Graphic3d_TOLS_SPOT:
+    case Graphic3d_TypeOfLightSource_Spot:
     {
       gp_Pnt aNewPos = gp::Origin().Transformed (aTrsf);
       myLightSource->SetPosition (aNewPos);
@@ -379,10 +379,10 @@ void AIS_LightSource::Compute (const Handle(PrsMgr_PresentationManager)& ,
 
   switch (myLightSource->Type())
   {
-    case Graphic3d_TOLS_AMBIENT:     computeAmbient    (thePrs, theMode); break;
-    case Graphic3d_TOLS_DIRECTIONAL: computeDirectional(thePrs, theMode); break;
-    case Graphic3d_TOLS_POSITIONAL:  computePositional (thePrs, theMode); break;
-    case Graphic3d_TOLS_SPOT:        computeSpot       (thePrs, theMode); break;
+    case Graphic3d_TypeOfLightSource_Ambient:     computeAmbient    (thePrs, theMode); break;
+    case Graphic3d_TypeOfLightSource_Directional: computeDirectional(thePrs, theMode); break;
+    case Graphic3d_TypeOfLightSource_Positional:  computePositional (thePrs, theMode); break;
+    case Graphic3d_TypeOfLightSource_Spot:        computeSpot       (thePrs, theMode); break;
   }
 
   if (myToDisplayName)
index e00dcd5..2dd7d81 100644 (file)
@@ -25,6 +25,7 @@
 #include <Draw_ProgressIndicator.hxx>
 #include <Draw_SequenceOfDrawable3D.hxx>
 #include <Message.hxx>
+#include <NCollection_Array1.hxx>
 #include <NCollection_Map.hxx>
 #include <Standard_SStream.hxx>
 #include <Standard_Stream.hxx>
@@ -873,128 +874,154 @@ static Standard_Boolean Alphabetic(char c)
 
 static Standard_Real Parse(char*&);
 
-static Standard_Real ParseValue(char*& name)
+static Standard_Real ParseValue (char*& theName)
 {
-  while (*name == ' ' || *name == '\t') name++;
+  while (*theName == ' ' || *theName == '\t') { ++theName; }
   Standard_Real x = 0;
-  switch (*name) {
-
-  case '\0' :
-    break;
-
-  case '(' :
-    name++;
-    x = Parse(name);
-    if (*name != ')') 
-      std::cout << "Mismatched parenthesis" << std::endl;
-    name++;
-    break;
-
-  case '+' :
-    name++;
-    x = ParseValue(name);
-    break;
-
-  case '-' :
-    name++;
-    x = - ParseValue(name);
-    break;
+  switch (*theName)
+  {
+    case '\0':
+    {
+      break;
+    }
+    case '(':
+    {
+      ++theName;
+      x = Parse (theName);
+      if (*theName != ')')
+      {
+        std::cout << "Mismatched parenthesis" << std::endl;
+      }
+      ++theName;
+      break;
+    }
+    case '+':
+    {
+      ++theName;
+      x = ParseValue (theName);
+      break;
+    }
+    case '-':
+    {
+      ++theName;
+      x = - ParseValue (theName);
+      break;
+    }
+    default:
+    {
+      // process a string
+      char* p = theName;
+      while (Numeric (*p)) { ++p; }
+      // process scientific notation
+      if ((*p == 'e') || (*p == 'E'))
+      {
+        if (Numeric (*(p+1)) || *(p+1) == '+' || *(p+1) == '-')
+        {
+          p+= 2;
+        }
+      }
+      while (Numeric (*p) || Alphabetic (*p)) { p++; }
+      char c = *p;
+      *p = '\0';
 
-    default :
+      if (Numeric (*theName))   // numeric literal
       {
-       // process a string
-       
-       char* p = name;
-       while (Numeric(*p)) p++;
-       // process scientific notation
-       if ((*p == 'e') || (*p == 'E')) {
-         if (Numeric(*(p+1)) || *(p+1) == '+' || *(p+1) == '-')
-           p+= 2;
-       }
-       while (Numeric(*p) || Alphabetic(*p)) p++;
-       char c = *p;
-       *p = '\0';
-       
-       if (Numeric(*name))   // numeric literal
-         x = Atof(name);
-       else if (!Draw::Get((Standard_CString) name,x)) {  // variable
-         
-         // search for a function ...
-         *p = c;
-         // count arguments
-         Standard_Integer argc = 1;
-         char* q = p;
-         while ((*q == ' ') || (*q == '\t')) q++;
-         if (*q == '(') {
-           Standard_Integer pc = 1;
-           argc = 2;
-           q++;
-           while ((pc > 0) && *q) {
-             if (*q == '(') pc++;
-             if (*q == ')') pc--;
-             if ((pc == 1) && (*q == ',')) argc++;
-             q++;
-           }
-           if (pc > 0) {
-             std::cout << "Unclosed parenthesis"<< std::endl;
-             x = 0;
-           }
-           else {
-             // build function call 
-             // replace , and first and last () by space
-             if (argc > 1) {
-               Standard_Integer i = 2;
-               while (*p != '(') p++;
-               *p = ' ';
-               p++;
-               pc = 1;
-               while (pc > 0) {
-                 if (*p == '(') pc++;
-                 if (*p == ')') pc--;
-                 if ((pc == 1) && (*p == ',')) {
-                   *p = ' ';
-                   p++;
-                   i++;
-                 }
-                 else
-                   p++;
-               }
-               *(p-1) = '\0';
-               c = *p;
-
-    Draw_Interpretor& aCommands = Draw::GetInterpretor();
-
-               // call the function, save the current result
-               char* sv = 0;
-               if (*aCommands.Result()) {
-                 sv = new char [strlen(aCommands.Result())];
-                 strcpy(sv,aCommands.Result());
-                 aCommands.Reset();
-               }
-               if (aCommands.Eval(name) != 0) {
-                 std::cout << "Call of function " << name << " failed" << std::endl;
-                 x = 0;
-               }
-               else
-                 x = Atof(aCommands.Result());
-               aCommands.Reset();
-               if (sv) {
-                 aCommands << sv;
-                 delete [] sv;
-               }
-             }
-           }
-         }
-         else
-           Draw_ParseFailed = Standard_True;
-       }
-       *p = c;
-       name = p;
+        x = Atof (theName);
       }
+      else if (!Draw::Get ((Standard_CString )theName, x)) // variable
+      {
+        // search for a function ...
+        *p = c;
+        // count arguments
+        Standard_Integer argc = 1;
+        char* q = p;
+        while ((*q == ' ') || (*q == '\t')) { ++q; }
+        if (*q == '(')
+        {
+          Standard_Integer pc = 1;
+          argc = 2;
+          q++;
+          while ((pc > 0) && *q)
+          {
+            if (*q == '(') { ++pc; }
+            if (*q == ')') { --pc; }
+            if ((pc == 1) && (*q == ',')) { ++argc; }
+            ++q;
+          }
+          if (pc > 0)
+          {
+            std::cout << "Unclosed parenthesis"<< std::endl;
+            x = 0;
+          }
+          else
+          {
+            // build function call
+            // replace , and first and last () by space
+            if (argc > 1)
+            {
+              Standard_Integer i = 2;
+              while (*p != '(') { ++p; }
+              *p = ' ';
+              ++p;
+              pc = 1;
+              while (pc > 0)
+              {
+                if (*p == '(') { ++pc; }
+                if (*p == ')') { --pc; }
+                if ((pc == 1) && (*p == ','))
+                {
+                  *p = ' ';
+                  ++p;
+                  ++i;
+                }
+                else
+                {
+                  ++p;
+                }
+              }
+              *(p-1) = '\0';
+              c = *p;
+
+              Draw_Interpretor& aCommands = Draw::GetInterpretor();
+
+              // call the function, save the current result
+              TCollection_AsciiString sv (aCommands.Result());
+              if (*aCommands.Result())
+              {
+                aCommands.Reset();
+              }
+              if (aCommands.Eval (theName) != 0)
+              {
+                std::cout << "Call of function " << theName << " failed" << std::endl;
+                x = 0;
+              }
+              else
+              {
+                x = Atof (aCommands.Result());
+              }
+              aCommands.Reset();
+              if (!sv.IsEmpty())
+              {
+                aCommands << sv;
+              }
+            }
+          }
+        }
+        else
+        {
+          Draw_ParseFailed = Standard_True;
+        }
+      }
+      *p = c;
+      theName = p;
+    }
     break;
-    
   }
-  while (*name == ' ' || *name == '\t') name++;
+
+  while (*theName == ' ' || *theName == '\t')
+  {
+    ++theName;
+  }
   return x;
 }
 
@@ -1055,17 +1082,16 @@ static Standard_Real Parse(char*& name)
 // function : Atof
 // purpose  :
 //=======================================================================
-Standard_Real Draw::Atof(const Standard_CString name)
+Standard_Real Draw::Atof(const Standard_CString theName)
 {
   // copy the string
-  char* n = new char[1+strlen(name)];
-  char* b = n;
-  strcpy(n,name);
+  NCollection_Array1<char> aBuff (0, (Standard_Integer )strlen (theName));
+  char* n = &aBuff.ChangeFirst();
+  strcpy (n, theName);
   Draw_ParseFailed = Standard_False;
   Standard_Real x = Parse(n);
   while ((*n == ' ') || (*n == '\t')) n++;
   if (*n) Draw_ParseFailed = Standard_True;
-  delete [] b;
   return x;
 }
 
index 228c6a6..4aa8a4b 100644 (file)
@@ -33,10 +33,10 @@ void Graphic3d_CLight::makeId()
   TCollection_AsciiString aTypeSuffix;
   switch (myType)
   {
-    case Graphic3d_TOLS_AMBIENT:     aTypeSuffix = "amb"; break;
-    case Graphic3d_TOLS_DIRECTIONAL: aTypeSuffix = "dir"; break;
-    case Graphic3d_TOLS_POSITIONAL:  aTypeSuffix = "pos"; break;
-    case Graphic3d_TOLS_SPOT:        aTypeSuffix = "spot"; break;
+    case Graphic3d_TypeOfLightSource_Ambient:     aTypeSuffix = "amb"; break;
+    case Graphic3d_TypeOfLightSource_Directional: aTypeSuffix = "dir"; break;
+    case Graphic3d_TypeOfLightSource_Positional:  aTypeSuffix = "pos"; break;
+    case Graphic3d_TypeOfLightSource_Spot:        aTypeSuffix = "spot"; break;
   }
 
   myId = TCollection_AsciiString ("Graphic3d_CLight_") + aTypeSuffix
@@ -62,23 +62,23 @@ Graphic3d_CLight::Graphic3d_CLight (Graphic3d_TypeOfLightSource theType)
 {
   switch (theType)
   {
-    case Graphic3d_TOLS_AMBIENT:
+    case Graphic3d_TypeOfLightSource_Ambient:
     {
       break;
     }
-    case Graphic3d_TOLS_DIRECTIONAL:
+    case Graphic3d_TypeOfLightSource_Directional:
     {
       mySmoothness = 0.2f;
       myIntensity  = 20.0f;
       break;
     }
-    case Graphic3d_TOLS_POSITIONAL:
+    case Graphic3d_TypeOfLightSource_Positional:
     {
       changeConstAttenuation()  = 1.0f;
       changeLinearAttenuation() = 0.0f;
       break;
     }
-    case Graphic3d_TOLS_SPOT:
+    case Graphic3d_TypeOfLightSource_Spot:
     {
       changeConstAttenuation()  = 1.0f;
       changeLinearAttenuation() = 0.0f;
@@ -90,6 +90,39 @@ Graphic3d_CLight::Graphic3d_CLight (Graphic3d_TypeOfLightSource theType)
   makeId();
 }
 
+// =======================================================================
+// function : CopyFrom
+// purpose  :
+// =======================================================================
+void Graphic3d_CLight::CopyFrom (const Handle(Graphic3d_CLight)& theLight)
+{
+  myName      = theLight->myName;
+  myIsEnabled = theLight->myIsEnabled;
+  myIntensity = theLight->myIntensity;
+  myColor     = theLight->myColor;
+  if (myType != Graphic3d_TypeOfLightSource_Ambient)
+  {
+    myPosition    = theLight->myPosition;
+    myIsHeadlight = theLight->myIsHeadlight;
+  }
+  if ((myType == Graphic3d_TypeOfLightSource_Spot
+    || myType == Graphic3d_TypeOfLightSource_Directional)
+   && (theLight->myType == Graphic3d_TypeOfLightSource_Spot
+    || theLight->myType == Graphic3d_TypeOfLightSource_Directional))
+  {
+    myDirection = theLight->myDirection;
+  }
+  if (myType == Graphic3d_TypeOfLightSource_Directional)
+  {
+    myToCastShadows = theLight->myToCastShadows;
+  }
+  if (myType == theLight->myType)
+  {
+    myParams     = theLight->myParams;
+    mySmoothness = theLight->mySmoothness;
+  }
+}
+
 // =======================================================================
 // function : SetColor
 // purpose  :
@@ -116,7 +149,7 @@ void Graphic3d_CLight::SetEnabled (Standard_Boolean theIsOn)
 // =======================================================================
 void Graphic3d_CLight::SetCastShadows (Standard_Boolean theToCast)
 {
-  if (myType != Graphic3d_TOLS_DIRECTIONAL)
+  if (myType != Graphic3d_TypeOfLightSource_Directional)
   {
     throw Standard_NotImplemented ("Graphic3d_CLight::SetCastShadows() is not implemented for this light type");
   }
@@ -130,7 +163,7 @@ void Graphic3d_CLight::SetCastShadows (Standard_Boolean theToCast)
 // =======================================================================
 void Graphic3d_CLight::SetHeadlight (Standard_Boolean theValue)
 {
-  if (myType == Graphic3d_TOLS_AMBIENT)
+  if (myType == Graphic3d_TypeOfLightSource_Ambient)
   {
     throw Standard_ProgramError ("Graphic3d_CLight::SetHeadlight() is not applicable to ambient light");
   }
@@ -144,8 +177,8 @@ void Graphic3d_CLight::SetHeadlight (Standard_Boolean theValue)
 // =======================================================================
 void Graphic3d_CLight::SetDirection (const gp_Dir& theDir)
 {
-  Standard_ProgramError_Raise_if (myType != Graphic3d_TOLS_SPOT
-                               && myType != Graphic3d_TOLS_DIRECTIONAL,
+  Standard_ProgramError_Raise_if (myType != Graphic3d_TypeOfLightSource_Spot
+                               && myType != Graphic3d_TypeOfLightSource_Directional,
                                   "Graphic3d_CLight::SetDirection(), incorrect light type");
   updateRevisionIf (Abs (myDirection.x() - static_cast<Standard_ShortReal> (theDir.X())) > ShortRealEpsilon()
                  || Abs (myDirection.y() - static_cast<Standard_ShortReal> (theDir.Y())) > ShortRealEpsilon()
@@ -162,8 +195,8 @@ void Graphic3d_CLight::SetDirection (const gp_Dir& theDir)
 // =======================================================================
 void Graphic3d_CLight::SetPosition (const gp_Pnt& thePosition)
 {
-  Standard_ProgramError_Raise_if (myType != Graphic3d_TOLS_SPOT
-                               && myType != Graphic3d_TOLS_POSITIONAL,
+  Standard_ProgramError_Raise_if (myType != Graphic3d_TypeOfLightSource_Spot
+                               && myType != Graphic3d_TypeOfLightSource_Positional,
                                   "Graphic3d_CLight::SetPosition(), incorrect light type");
   updateRevisionIf (!myPosition.IsEqual (thePosition, gp::Resolution()));
   myPosition = thePosition;
@@ -175,7 +208,7 @@ void Graphic3d_CLight::SetPosition (const gp_Pnt& thePosition)
 // =======================================================================
 void Graphic3d_CLight::SetDisplayPosition (const gp_Pnt& thePosition)
 {
-  Standard_ProgramError_Raise_if (myType == Graphic3d_TOLS_AMBIENT,
+  Standard_ProgramError_Raise_if (myType == Graphic3d_TypeOfLightSource_Ambient,
                                   "Graphic3d_CLight::SetDisplayPosition(), incorrect light type");
   updateRevisionIf (!myPosition.IsEqual (thePosition, gp::Resolution()));
   myPosition = thePosition;
@@ -198,7 +231,7 @@ void Graphic3d_CLight::SetIntensity (Standard_ShortReal theValue)
 // =======================================================================
 void Graphic3d_CLight::SetAngle (Standard_ShortReal theAngle)
 {
-  Standard_ProgramError_Raise_if (myType != Graphic3d_TOLS_SPOT,
+  Standard_ProgramError_Raise_if (myType != Graphic3d_TypeOfLightSource_Spot,
                                   "Graphic3d_CLight::SetAngle(), incorrect light type");
   Standard_OutOfRange_Raise_if (theAngle <= 0.0 || theAngle >= M_PI,
                                 "Graphic3d_CLight::SetAngle(), bad angle");
@@ -213,8 +246,8 @@ void Graphic3d_CLight::SetAngle (Standard_ShortReal theAngle)
 void Graphic3d_CLight::SetAttenuation (Standard_ShortReal theConstAttenuation,
                                        Standard_ShortReal theLinearAttenuation)
 {
-  Standard_ProgramError_Raise_if (myType != Graphic3d_TOLS_POSITIONAL
-                               && myType != Graphic3d_TOLS_SPOT,
+  Standard_ProgramError_Raise_if (myType != Graphic3d_TypeOfLightSource_Positional
+                               && myType != Graphic3d_TypeOfLightSource_Spot,
                                   "Graphic3d_CLight::SetAttenuation(), incorrect light type");
   Standard_OutOfRange_Raise_if (theConstAttenuation  < 0.0f
                              || theLinearAttenuation < 0.0f
@@ -231,7 +264,7 @@ void Graphic3d_CLight::SetAttenuation (Standard_ShortReal theConstAttenuation,
 // =======================================================================
 void Graphic3d_CLight::SetConcentration (Standard_ShortReal theConcentration)
 {
-  Standard_ProgramError_Raise_if (myType != Graphic3d_TOLS_SPOT, "Graphic3d_CLight::SetConcentration(), incorrect light type");
+  Standard_ProgramError_Raise_if (myType != Graphic3d_TypeOfLightSource_Spot, "Graphic3d_CLight::SetConcentration(), incorrect light type");
   Standard_OutOfRange_Raise_if (theConcentration < 0.0f || theConcentration > 1.0f,
                                 "Graphic3d_CLight::SetConcentration(), bad coefficient");
   updateRevisionIf (Abs (changeConcentration() - theConcentration) > ShortRealEpsilon());
@@ -244,8 +277,8 @@ void Graphic3d_CLight::SetConcentration (Standard_ShortReal theConcentration)
 // =======================================================================
 void Graphic3d_CLight::SetSmoothRadius (Standard_ShortReal theValue)
 {
-  Standard_ProgramError_Raise_if (myType != Graphic3d_TOLS_POSITIONAL
-                               && myType != Graphic3d_TOLS_SPOT,
+  Standard_ProgramError_Raise_if (myType != Graphic3d_TypeOfLightSource_Positional
+                               && myType != Graphic3d_TypeOfLightSource_Spot,
                                   "Graphic3d_CLight::SetSmoothRadius(), incorrect light type");
   Standard_OutOfRange_Raise_if (theValue < 0.0f, "Graphic3d_CLight::SetSmoothRadius(), Bad value for smoothing radius");
   updateRevisionIf (Abs (mySmoothness - theValue) > ShortRealEpsilon());
@@ -258,7 +291,7 @@ void Graphic3d_CLight::SetSmoothRadius (Standard_ShortReal theValue)
 // =======================================================================
 void Graphic3d_CLight::SetSmoothAngle (Standard_ShortReal theValue)
 {
-  Standard_ProgramError_Raise_if (myType != Graphic3d_TOLS_DIRECTIONAL,
+  Standard_ProgramError_Raise_if (myType != Graphic3d_TypeOfLightSource_Directional,
                                   "Graphic3d_CLight::SetSmoothAngle(), incorrect light type");
   Standard_OutOfRange_Raise_if (theValue < 0.0f || theValue > Standard_ShortReal(M_PI / 2.0),
                                 "Graphic3d_CLight::SetSmoothAngle(), Bad value for smoothing angle");
@@ -272,7 +305,8 @@ void Graphic3d_CLight::SetSmoothAngle (Standard_ShortReal theValue)
 // =======================================================================
 void Graphic3d_CLight::SetRange (Standard_ShortReal theValue)
 {
-  Standard_ProgramError_Raise_if (myType != Graphic3d_TOLS_POSITIONAL && myType != Graphic3d_TOLS_SPOT,
+  Standard_ProgramError_Raise_if (myType != Graphic3d_TypeOfLightSource_Positional
+                               && myType != Graphic3d_TypeOfLightSource_Spot,
                                   "Graphic3d_CLight::SetRange(), incorrect light type");
   Standard_OutOfRange_Raise_if (theValue < 0.0, "Graphic3d_CLight::SetRange(), Bad value for falloff range");
   updateRevisionIf (Abs (Range() - theValue) > ShortRealEpsilon());
@@ -291,29 +325,29 @@ void Graphic3d_CLight::DumpJson (Standard_OStream& theOStream, Standard_Integer
   OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myId)
   OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myName)
   
-  if (myType == Graphic3d_TOLS_SPOT || myType == Graphic3d_TOLS_POSITIONAL)
+  if (myType == Graphic3d_TypeOfLightSource_Spot || myType == Graphic3d_TypeOfLightSource_Positional)
   {
     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myPosition)
   }
   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myColor)
   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIntensity)
 
-  if (myType == Graphic3d_TOLS_SPOT || myType == Graphic3d_TOLS_DIRECTIONAL)
+  if (myType == Graphic3d_TypeOfLightSource_Spot || myType == Graphic3d_TypeOfLightSource_Directional)
   {
     gp_Dir aDirection = Direction();
     OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &aDirection)
   }
-  if (myType == Graphic3d_TOLS_POSITIONAL || myType == Graphic3d_TOLS_SPOT)
+  if (myType == Graphic3d_TypeOfLightSource_Positional || myType == Graphic3d_TypeOfLightSource_Spot)
   {
     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, ConstAttenuation())
     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, LinearAttenuation())
   }
-  if (myType == Graphic3d_TOLS_SPOT)
+  if (myType == Graphic3d_TypeOfLightSource_Spot)
   {
     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, Angle())
     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, Concentration())
   }
-  if (myType == Graphic3d_TOLS_POSITIONAL || myType == Graphic3d_TOLS_SPOT)
+  if (myType == Graphic3d_TypeOfLightSource_Positional || myType == Graphic3d_TypeOfLightSource_Spot)
   {
     OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, Range())
   }
index cb44777..95fd89e 100644 (file)
@@ -33,6 +33,9 @@ public:
   //! Empty constructor, which should be followed by light source properties configuration.
   Standard_EXPORT Graphic3d_CLight (Graphic3d_TypeOfLightSource theType);
 
+  //! Copy parameters from another light source excluding source type.
+  Standard_EXPORT void CopyFrom (const Handle(Graphic3d_CLight)& theLight);
+
   //! Returns the Type of the Light, cannot be changed after object construction.
   Graphic3d_TypeOfLightSource Type() const { return myType; }
 
index 61dcca9..103f31c 100644 (file)
@@ -22,10 +22,10 @@ namespace
   //! Suffixes identifying light source type.
   static const char THE_LIGHT_KEY_LETTERS[Graphic3d_TypeOfLightSource_NB] =
   {
-    'a', // Graphic3d_TOLS_AMBIENT
-    'd', // Graphic3d_TOLS_DIRECTIONAL
-    'p', // Graphic3d_TOLS_POSITIONAL
-    's'  // Graphic3d_TOLS_SPOT
+    'a', // Graphic3d_TypeOfLightSource_Ambient
+    'd', // Graphic3d_TypeOfLightSource_Directional
+    'p', // Graphic3d_TypeOfLightSource_Positional
+    's'  // Graphic3d_TypeOfLightSource_Spot
   };
 }
 
@@ -126,7 +126,7 @@ Standard_Size Graphic3d_LightSet::UpdateRevision()
     }
 
     myLightTypesEnabled[aLight->Type()] += 1;
-    if (aLight->Type() == Graphic3d_TOLS_AMBIENT)
+    if (aLight->Type() == Graphic3d_TypeOfLightSource_Ambient)
     {
       myAmbient += aLight->PackedColor() * aLight->Intensity();
     }
@@ -145,12 +145,12 @@ Standard_Size Graphic3d_LightSet::UpdateRevision()
   }
   aKeyLong[aLightLast] = '\0';
   myAmbient.a() = 1.0f;
-  myNbEnabled = myLightTypesEnabled[Graphic3d_TOLS_DIRECTIONAL]
-              + myLightTypesEnabled[Graphic3d_TOLS_POSITIONAL]
-              + myLightTypesEnabled[Graphic3d_TOLS_SPOT];
+  myNbEnabled = myLightTypesEnabled[Graphic3d_TypeOfLightSource_Directional]
+              + myLightTypesEnabled[Graphic3d_TypeOfLightSource_Positional]
+              + myLightTypesEnabled[Graphic3d_TypeOfLightSource_Spot];
   myKeyEnabledLong  = aKeyLong;
-  myKeyEnabledShort = TCollection_AsciiString (myLightTypesEnabled[Graphic3d_TOLS_DIRECTIONAL] > 0 ? THE_LIGHT_KEY_LETTERS[Graphic3d_TOLS_DIRECTIONAL] : '\0')
-                    + TCollection_AsciiString (myLightTypesEnabled[Graphic3d_TOLS_POSITIONAL]  > 0 ? THE_LIGHT_KEY_LETTERS[Graphic3d_TOLS_POSITIONAL]  : '\0')
-                    + TCollection_AsciiString (myLightTypesEnabled[Graphic3d_TOLS_SPOT]        > 0 ? THE_LIGHT_KEY_LETTERS[Graphic3d_TOLS_SPOT]        : '\0');
+  myKeyEnabledShort = TCollection_AsciiString (myLightTypesEnabled[Graphic3d_TypeOfLightSource_Directional] > 0 ? THE_LIGHT_KEY_LETTERS[Graphic3d_TypeOfLightSource_Directional] : '\0')
+                    + TCollection_AsciiString (myLightTypesEnabled[Graphic3d_TypeOfLightSource_Positional]  > 0 ? THE_LIGHT_KEY_LETTERS[Graphic3d_TypeOfLightSource_Positional]  : '\0')
+                    + TCollection_AsciiString (myLightTypesEnabled[Graphic3d_TypeOfLightSource_Spot]        > 0 ? THE_LIGHT_KEY_LETTERS[Graphic3d_TypeOfLightSource_Spot]        : '\0');
   return myRevision;
 }
index 32be557..e853ee0 100644 (file)
@@ -88,7 +88,7 @@ public:
       for (; myIter.More(); myIter.Next())
       {
         if ((myFilter & IterationFilter_ExcludeAmbient) != 0
-         && myIter.Key()->Type() == Graphic3d_TOLS_AMBIENT)
+         && myIter.Key()->Type() == Graphic3d_TypeOfLightSource_Ambient)
         {
           continue;
         }
index 42796fe..b9ee57e 100644 (file)
@@ -1168,7 +1168,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
         for (Graphic3d_LightSet::Iterator aLightIter (theLights, Graphic3d_LightSet::IterationFilter_ExcludeDisabledAndAmbient);
              aLightIter.More(); aLightIter.Next())
         {
-          if (aLightIter.Value()->Type() == Graphic3d_TOLS_DIRECTIONAL
+          if (aLightIter.Value()->Type() == Graphic3d_TypeOfLightSource_Directional
            && aLightIter.Value()->ToCastShadows())
           {
             aLightsLoop = aLightsLoop + EOL"    occDirectionalLight (" + anIndex + ", theNormal, theView, theIsFront,"
@@ -1182,11 +1182,11 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
       {
         switch (aLightIter.Value()->Type())
         {
-          case Graphic3d_TOLS_AMBIENT:
+          case Graphic3d_TypeOfLightSource_Ambient:
           {
             break; // skip ambient
           }
-          case Graphic3d_TOLS_DIRECTIONAL:
+          case Graphic3d_TypeOfLightSource_Directional:
           {
             if (theNbShadowMaps > 0
              && aLightIter.Value()->ToCastShadows())
@@ -1197,13 +1197,13 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
             ++anIndex;
             break;
           }
-          case Graphic3d_TOLS_POSITIONAL:
+          case Graphic3d_TypeOfLightSource_Positional:
           {
             aLightsLoop = aLightsLoop + EOL"    occPointLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront);";
             ++anIndex;
             break;
           }
-          case Graphic3d_TOLS_SPOT:
+          case Graphic3d_TypeOfLightSource_Spot:
           {
             aLightsLoop = aLightsLoop + EOL"    occSpotLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront);";
             ++anIndex;
@@ -1220,7 +1220,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
         EOL"    for (int anIndex = 0; anIndex < occLightSourcesCount; ++anIndex)"
         EOL"    {"
         EOL"      int aType = occLight_Type (anIndex);";
-      if (theLights->NbEnabledLightsOfType (Graphic3d_TOLS_DIRECTIONAL) > 0)
+      if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Directional) > 0)
       {
         isFirstInLoop = false;
         aLightsLoop +=
@@ -1229,7 +1229,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
           EOL"        occDirectionalLight (anIndex, theNormal, theView, theIsFront, 1.0);"
           EOL"      }";
       }
-      if (theLights->NbEnabledLightsOfType (Graphic3d_TOLS_POSITIONAL) > 0)
+      if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Positional) > 0)
       {
         if (!isFirstInLoop)
         {
@@ -1242,7 +1242,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
           EOL"        occPointLight (anIndex, theNormal, theView, aPoint, theIsFront);"
           EOL"      }";
       }
-      if (theLights->NbEnabledLightsOfType (Graphic3d_TOLS_SPOT) > 0)
+      if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Spot) > 0)
       {
         if (!isFirstInLoop)
         {
@@ -1267,7 +1267,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
       aLightsFunc += Shaders_PBRIllumination_glsl;
     }
 
-    if (theLights->NbEnabledLightsOfType (Graphic3d_TOLS_DIRECTIONAL) == 1
+    if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Directional) == 1
      && theNbLights == 1
      && !theIsPBR
      && theNbShadowMaps == 0)
@@ -1276,7 +1276,7 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
       aLightsLoop = EOL"    directionalLightFirst(theNormal, theView, theIsFront, 1.0);";
       aLightsFunc += THE_FUNC_directionalLightFirst;
     }
-    else if (theLights->NbEnabledLightsOfType (Graphic3d_TOLS_DIRECTIONAL) > 0)
+    else if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Directional) > 0)
     {
       if (theNbShadowMaps > 0)
       {
@@ -1284,11 +1284,11 @@ TCollection_AsciiString Graphic3d_ShaderManager::stdComputeLighting (Standard_In
       }
       aLightsFunc += theIsPBR ? Shaders_PBRDirectionalLight_glsl : Shaders_PhongDirectionalLight_glsl;
     }
-    if (theLights->NbEnabledLightsOfType (Graphic3d_TOLS_POSITIONAL) > 0)
+    if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Positional) > 0)
     {
       aLightsFunc += theIsPBR ? Shaders_PBRPointLight_glsl : Shaders_PhongPointLight_glsl;
     }
-    if (theLights->NbEnabledLightsOfType (Graphic3d_TOLS_SPOT) > 0)
+    if (theLights->NbEnabledLightsOfType (Graphic3d_TypeOfLightSource_Spot) > 0)
     {
       aLightsFunc += theIsPBR ? Shaders_PBRSpotLight_glsl : Shaders_PhongSpotLight_glsl;
     }
index 4f4e43b..93961a0 100644 (file)
 //! Definition of all the type of light source.
 enum Graphic3d_TypeOfLightSource
 {
-  Graphic3d_TOLS_AMBIENT,     //!< ambient light
-  Graphic3d_TOLS_DIRECTIONAL, //!< directional light
-  Graphic3d_TOLS_POSITIONAL,  //!< positional light
-  Graphic3d_TOLS_SPOT,        //!< spot light
+  Graphic3d_TypeOfLightSource_Ambient,     //!< ambient light
+  Graphic3d_TypeOfLightSource_Directional, //!< directional light
+  Graphic3d_TypeOfLightSource_Positional,  //!< positional light
+  Graphic3d_TypeOfLightSource_Spot,        //!< spot light
+
   // obsolete aliases
-  V3d_AMBIENT     = Graphic3d_TOLS_AMBIENT,
-  V3d_DIRECTIONAL = Graphic3d_TOLS_DIRECTIONAL,
-  V3d_POSITIONAL  = Graphic3d_TOLS_POSITIONAL,
-  V3d_SPOT        = Graphic3d_TOLS_SPOT
+  Graphic3d_TOLS_AMBIENT     = Graphic3d_TypeOfLightSource_Ambient,
+  Graphic3d_TOLS_DIRECTIONAL = Graphic3d_TypeOfLightSource_Directional,
+  Graphic3d_TOLS_POSITIONAL  = Graphic3d_TypeOfLightSource_Positional,
+  Graphic3d_TOLS_SPOT        = Graphic3d_TypeOfLightSource_Spot,
+  //
+  V3d_AMBIENT     = Graphic3d_TypeOfLightSource_Ambient,
+  V3d_DIRECTIONAL = Graphic3d_TypeOfLightSource_Directional,
+  V3d_POSITIONAL  = Graphic3d_TypeOfLightSource_Positional,
+  V3d_SPOT        = Graphic3d_TypeOfLightSource_Spot
 };
 
 enum
 {
   //! Auxiliary value defining the overall number of values in enumeration Graphic3d_TypeOfLightSource
-  Graphic3d_TypeOfLightSource_NB = Graphic3d_TOLS_SPOT + 1
+  Graphic3d_TypeOfLightSource_NB = Graphic3d_TypeOfLightSource_Spot + 1
 };
 
 #endif // _Graphic3d_TypeOfLightSource_HeaderFile
index a1cc8c7..43315dc 100644 (file)
@@ -54,8 +54,11 @@ namespace
     const Graphic3d_Vec4& aLightColor = theLight.PackedColor();
     switch (theLight.Type())
     {
-      case Graphic3d_TOLS_AMBIENT    : break; // handled by separate if-clause at beginning of method
-      case Graphic3d_TOLS_DIRECTIONAL:
+      case Graphic3d_TypeOfLightSource_Ambient:
+      {
+        break; // handled by separate if-clause at beginning of method
+      }
+      case Graphic3d_TypeOfLightSource_Directional:
       {
         // if the last parameter of GL_POSITION, is zero, the corresponding light source is a Directional one
         const OpenGl_Vec4 anInfDir = -theLight.PackedDirectionRange();
@@ -70,7 +73,7 @@ namespace
         theCtx->core11ffp->glLightf  (theLightGlId, GL_SPOT_CUTOFF,           THE_DEFAULT_SPOT_CUTOFF);
         break;
       }
-      case Graphic3d_TOLS_POSITIONAL:
+      case Graphic3d_TypeOfLightSource_Positional:
       {
         // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE
         const OpenGl_Vec4 aPosition (static_cast<float>(theLight.Position().X()), static_cast<float>(theLight.Position().Y()), static_cast<float>(theLight.Position().Z()), 1.0f);
@@ -86,7 +89,7 @@ namespace
         theCtx->core11ffp->glLightf  (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0f);
         break;
       }
-      case Graphic3d_TOLS_SPOT:
+      case Graphic3d_TypeOfLightSource_Spot:
       {
         const OpenGl_Vec4 aPosition (static_cast<float>(theLight.Position().X()), static_cast<float>(theLight.Position().Y()), static_cast<float>(theLight.Position().Z()), 1.0f);
         theCtx->core11ffp->glLightfv (theLightGlId, GL_AMBIENT,               THE_DEFAULT_AMBIENT);
@@ -464,7 +467,7 @@ void OpenGl_ShaderManager::pushLightSourceState (const Handle(OpenGl_ShaderProgr
     if (!aLight.IsEnabled()) // has no affect with Graphic3d_LightSet::IterationFilter_ExcludeDisabled - here just for consistency
     {
       // if it is desired to keep disabled light in the same order - we can replace it with a black light so that it will have no influence on result
-      aLightType = -1; // Graphic3d_TOLS_AMBIENT can be used instead
+      aLightType = -1; // Graphic3d_TypeOfLightSource_Ambient can be used instead
       aLightParams.Color = OpenGl_Vec4 (0.0f, 0.0f, 0.0f, 0.0f);
       ++aLightsNb;
       continue;
@@ -478,11 +481,11 @@ void OpenGl_ShaderManager::pushLightSourceState (const Handle(OpenGl_ShaderProgr
     aLightParams.Parameters = aLight.PackedParams();
     switch (aLight.Type())
     {
-      case Graphic3d_TOLS_AMBIENT:
+      case Graphic3d_TypeOfLightSource_Ambient:
       {
         break;
       }
-      case Graphic3d_TOLS_DIRECTIONAL:
+      case Graphic3d_TypeOfLightSource_Directional:
       {
         if (aLight.IsHeadlight())
         {
@@ -496,7 +499,7 @@ void OpenGl_ShaderManager::pushLightSourceState (const Handle(OpenGl_ShaderProgr
         }
         break;
       }
-      case Graphic3d_TOLS_SPOT:
+      case Graphic3d_TypeOfLightSource_Spot:
       {
         if (aLight.IsHeadlight())
         {
@@ -510,7 +513,7 @@ void OpenGl_ShaderManager::pushLightSourceState (const Handle(OpenGl_ShaderProgr
         }
       }
       Standard_FALLTHROUGH
-      case Graphic3d_TOLS_POSITIONAL:
+      case Graphic3d_TypeOfLightSource_Positional:
       {
         if (aLight.IsHeadlight())
         {
index 749e9c8..bec004a 100644 (file)
@@ -93,11 +93,11 @@ bool OpenGl_ShadowMap::UpdateCamera (const Graphic3d_CView& theView,
 
   switch (myShadowLight->Type())
   {
-    case Graphic3d_TOLS_AMBIENT:
+    case Graphic3d_TypeOfLightSource_Ambient:
     {
       return false; // not applicable
     }
-    case Graphic3d_TOLS_DIRECTIONAL:
+    case Graphic3d_TypeOfLightSource_Directional:
     {
       if (theOrigin != NULL)
       {
@@ -134,12 +134,12 @@ bool OpenGl_ShadowMap::UpdateCamera (const Graphic3d_CView& theView,
       myLightMatrix = myShadowCamera->ProjectionMatrixF() * myShadowCamera->OrientationMatrixF();
       return true;
     }
-    case Graphic3d_TOLS_POSITIONAL:
+    case Graphic3d_TypeOfLightSource_Positional:
     {
       // render into cubemap shadowmap texture
       return false; // not implemented
     }
-    case Graphic3d_TOLS_SPOT:
+    case Graphic3d_TypeOfLightSource_Spot:
     {
       //myShadowCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
       //myShadowCamera->SetEye (theCastShadowLight->Position());
index 498e460..4e32938 100644 (file)
@@ -154,7 +154,7 @@ OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr,
 
   myWorkspace = new OpenGl_Workspace (this, NULL);
 
-  Handle(Graphic3d_CLight) aLight = new Graphic3d_CLight (Graphic3d_TOLS_AMBIENT);
+  Handle(Graphic3d_CLight) aLight = new Graphic3d_CLight (Graphic3d_TypeOfLightSource_Ambient);
   aLight->SetColor (Quantity_NOC_WHITE);
   myLights = new Graphic3d_LightSet();
   myNoShadingLight = new Graphic3d_LightSet();
index 4dcb082..eb6b9f2 100644 (file)
@@ -2440,7 +2440,7 @@ Standard_Boolean OpenGl_View::updateRaytraceLightSources (const OpenGl_Mat4& the
          aLightIter.More(); aLightIter.Next())
     {
       const Graphic3d_CLight& aLight = *aLightIter.Value();
-      if (aLight.Type() != Graphic3d_TOLS_DIRECTIONAL)
+      if (aLight.Type() != Graphic3d_TypeOfLightSource_Directional)
       {
         aLightSources.push_back (aLightIter.Value());
       }
@@ -2449,7 +2449,7 @@ Standard_Boolean OpenGl_View::updateRaytraceLightSources (const OpenGl_Mat4& the
     for (Graphic3d_LightSet::Iterator aLightIter (myLights, Graphic3d_LightSet::IterationFilter_ExcludeDisabledAndAmbient);
          aLightIter.More(); aLightIter.Next())
     {
-      if (aLightIter.Value()->Type() == Graphic3d_TOLS_DIRECTIONAL)
+      if (aLightIter.Value()->Type() == Graphic3d_TypeOfLightSource_Directional)
       {
         aLightSources.push_back (aLightIter.Value());
       }
@@ -2484,7 +2484,7 @@ Standard_Boolean OpenGl_View::updateRaytraceLightSources (const OpenGl_Mat4& the
                          -aLight.PackedDirectionRange().z(),
                          0.0f);
 
-    if (aLight.Type() != Graphic3d_TOLS_DIRECTIONAL)
+    if (aLight.Type() != Graphic3d_TypeOfLightSource_Directional)
     {
       aPosition = BVH_Vec4f (static_cast<float>(aLight.Position().X()),
                              static_cast<float>(aLight.Position().Y()),
index a64ee21..cce5bfc 100644 (file)
@@ -24,7 +24,7 @@ IMPLEMENT_STANDARD_RTTIEXT(V3d_AmbientLight, Graphic3d_CLight)
 // purpose  :
 // =======================================================================
 V3d_AmbientLight::V3d_AmbientLight (const Quantity_Color& theColor)
-: Graphic3d_CLight (Graphic3d_TOLS_AMBIENT)
+: Graphic3d_CLight (Graphic3d_TypeOfLightSource_Ambient)
 {
   SetColor (theColor);
 }
index ab4aa39..511252a 100644 (file)
@@ -24,7 +24,7 @@ IMPLEMENT_STANDARD_RTTIEXT(V3d_DirectionalLight,V3d_PositionLight)
 V3d_DirectionalLight::V3d_DirectionalLight (const V3d_TypeOfOrientation theDirection,
                                             const Quantity_Color& theColor,
                                             const Standard_Boolean theIsHeadlight)
-: V3d_PositionLight (Graphic3d_TOLS_DIRECTIONAL)
+: V3d_PositionLight (Graphic3d_TypeOfLightSource_Directional)
 {
   SetColor (theColor);
   SetHeadlight (theIsHeadlight);
@@ -38,7 +38,7 @@ V3d_DirectionalLight::V3d_DirectionalLight (const V3d_TypeOfOrientation theDirec
 V3d_DirectionalLight::V3d_DirectionalLight (const gp_Dir& theDirection,
                                             const Quantity_Color& theColor,
                                             const Standard_Boolean theIsHeadlight)
-: V3d_PositionLight (Graphic3d_TOLS_DIRECTIONAL)
+: V3d_PositionLight (Graphic3d_TypeOfLightSource_Directional)
 {
   SetColor (theColor);
   SetHeadlight (theIsHeadlight);
index 7613a82..3b5a29e 100644 (file)
@@ -21,7 +21,7 @@ IMPLEMENT_STANDARD_RTTIEXT(V3d_PositionalLight,V3d_PositionLight)
 // =======================================================================
 V3d_PositionalLight::V3d_PositionalLight (const gp_Pnt& thePos,
                                           const Quantity_Color& theColor)
-: V3d_PositionLight (Graphic3d_TOLS_POSITIONAL)
+: V3d_PositionLight (Graphic3d_TypeOfLightSource_Positional)
 {
   SetColor (theColor);
   SetPosition (thePos);
index faae6f9..e865c9a 100644 (file)
@@ -24,7 +24,7 @@ IMPLEMENT_STANDARD_RTTIEXT(V3d_SpotLight,V3d_PositionLight)
 V3d_SpotLight::V3d_SpotLight (const gp_Pnt& thePos,
                               const V3d_TypeOfOrientation theDirection,
                               const Quantity_Color& theColor)
-: V3d_PositionLight (Graphic3d_TOLS_SPOT)
+: V3d_PositionLight (Graphic3d_TypeOfLightSource_Spot)
 {
   SetColor (theColor);
   SetPosition (thePos);
@@ -38,7 +38,7 @@ V3d_SpotLight::V3d_SpotLight (const gp_Pnt& thePos,
 V3d_SpotLight::V3d_SpotLight (const gp_Pnt& thePos,
                               const gp_Dir& theDirection,
                               const Quantity_Color& theColor)
-: V3d_PositionLight (Graphic3d_TOLS_SPOT)
+: V3d_PositionLight (Graphic3d_TypeOfLightSource_Spot)
 {
   SetColor (theColor);
   SetPosition (thePos);
index 439ed24..ad6467f 100644 (file)
@@ -439,8 +439,11 @@ void V3d_Viewer::SetDefaultLights()
     DelLight (aLight);
   }
 
-  Handle(V3d_DirectionalLight) aDirLight  = new V3d_DirectionalLight (V3d_Zneg, Quantity_NOC_WHITE, Standard_True);
-  Handle(V3d_AmbientLight)     anAmbLight = new V3d_AmbientLight (Quantity_NOC_WHITE);
+  Handle(V3d_DirectionalLight) aDirLight = new V3d_DirectionalLight (V3d_Zneg, Quantity_NOC_WHITE);
+  aDirLight->SetName ("headlight");
+  aDirLight->SetHeadlight (true);
+  Handle(V3d_AmbientLight) anAmbLight = new V3d_AmbientLight (Quantity_NOC_WHITE);
+  anAmbLight->SetName ("amblight");
   AddLight (aDirLight);
   AddLight (anAmbLight);
   SetLightOn (aDirLight);
index ea30197..43c6067 100644 (file)
@@ -10212,80 +10212,71 @@ static int VDefaults (Draw_Interpretor& theDi,
   return 0;
 }
 
-//! Auxiliary method
-inline void addLight (const Handle(V3d_Light)& theLightNew,
-                      const Graphic3d_ZLayerId theLayer,
-                      const Standard_Boolean   theIsGlobal)
+//! Parse light source type from string.
+static bool parseLightSourceType (const TCollection_AsciiString& theTypeName,
+                                  Graphic3d_TypeOfLightSource& theType)
 {
-  if (theLightNew.IsNull())
+  TCollection_AsciiString aType (theTypeName);
+  aType.LowerCase();
+  if (aType == "amb"
+   || aType == "ambient"
+   || aType == "amblight")
   {
-    return;
+    theType = Graphic3d_TypeOfLightSource_Ambient;
   }
-
-  Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
-  if (theLayer == Graphic3d_ZLayerId_UNKNOWN)
+  else if (aType == "directional"
+        || aType == "dirlight")
   {
-    aViewer->AddLight (theLightNew);
-    if (theIsGlobal)
-    {
-      aViewer->SetLightOn (theLightNew);
-    }
-    else
-    {
-      ViewerTest::CurrentView()->SetLightOn (theLightNew);
-    }
+    theType = Graphic3d_TypeOfLightSource_Directional;
   }
-  else
+  else if (aType == "spot"
+        || aType == "spotlight")
   {
-    Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (theLayer);
-    if (aSettings.Lights().IsNull())
-    {
-      aSettings.SetLights (new Graphic3d_LightSet());
-    }
-    aSettings.Lights()->Add (theLightNew);
-    aViewer->SetZLayerSettings (theLayer, aSettings);
+    theType = Graphic3d_TypeOfLightSource_Spot;
   }
-}
-
-//! Auxiliary method
-inline Standard_Integer getLightId (const TCollection_AsciiString& theArgNext)
-{
-  TCollection_AsciiString anArgNextCase (theArgNext);
-  anArgNextCase.UpperCase();
-  if (anArgNextCase.Length() > 5
-   && anArgNextCase.SubString (1, 5).IsEqual ("LIGHT"))
+  else if (aType == "poslight"
+        || aType == "positional"
+        || aType == "point"
+        || aType == "pnt")
   {
-    return theArgNext.SubString (6, theArgNext.Length()).IntegerValue();
+    theType = Graphic3d_TypeOfLightSource_Positional;
   }
   else
   {
-    return theArgNext.IntegerValue();
+    return false;
   }
+  return true;
 }
 
-static Handle(AIS_LightSource) findLightPrs (const Handle(V3d_Light)& theLight,
-                                             const bool theToShowErrors = true)
+//! Find existing light by name or index.
+static Handle(V3d_Light) findLightSource (const TCollection_AsciiString& theName)
 {
-  if (theLight.IsNull())
+  Handle(V3d_Light) aLight;
+  Standard_Integer aLightIndex = -1;
+  Draw::ParseInteger (theName.ToCString(), aLightIndex);
+  Standard_Integer aLightIt = 0;
+  Handle(V3d_View) aView = ViewerTest::CurrentView();
+  for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
   {
-    if (theToShowErrors)
+    if (aLightIndex != -1)
     {
-      Message::SendFail() << "Syntax error: no active light source to find presentation";
+      if (aLightIt == aLightIndex)
+      {
+        return aLightIter.Value();
+      }
     }
-    return Handle(AIS_LightSource)();
-  }
-
-  Handle(AIS_InteractiveObject) anObject;
-  GetMapOfAIS().Find2 (theLight->Name(), anObject);
-  Handle(AIS_LightSource) aLightSource = Handle(AIS_LightSource)::DownCast (anObject);
-  if (aLightSource.IsNull())
-  {
-    if (theToShowErrors)
+    else if (aLightIter.Value()->GetId() == theName
+          || aLightIter.Value()->Name()  == theName)
     {
-      Message::SendFail() << "Syntax error: could not find '" << theLight->Name() << "' AIS object";
+      if (!aLight.IsNull())
+      {
+        Message::SendWarning() << "Warning: ambiguous light name '" << theName << "'";
+        break;
+      }
+      aLight = aLightIter.Value();
     }
   }
-  return aLightSource;
+  return aLight;
 }
 
 //===============================================================================================
@@ -10298,6 +10289,7 @@ static int VLight (Draw_Interpretor& theDi,
 {
   Handle(V3d_View)   aView   = ViewerTest::CurrentView();
   Handle(V3d_Viewer) aViewer = ViewerTest::GetViewerFromContext();
+  const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext();
   if (aView.IsNull()
    || aViewer.IsNull())
   {
@@ -10305,8 +10297,6 @@ static int VLight (Draw_Interpretor& theDi,
     return 1;
   }
 
-  Standard_Real anXYZ[3]   = {};
-  Standard_Real anAtten[2] = {};
   if (theArgsNb < 2)
   {
     // print lights info
@@ -10317,55 +10307,50 @@ static int VLight (Draw_Interpretor& theDi,
       const Quantity_Color aColor = aLight->Color();
       theDi << "Light #" << aLightId
             << (!aLight->Name().IsEmpty() ? (TCollection_AsciiString(" ") + aLight->Name()) : "")
-            << " [" << aLight->GetId() << "]" << "\n";
+            << " [" << aLight->GetId() << "] "
+            << (aLight->IsEnabled() ? "ON" : "OFF") << "\n";
       switch (aLight->Type())
       {
         case V3d_AMBIENT:
         {
-          theDi << "  Type:       Ambient\n";
-          theDi << "  Intensity:  " << aLight->Intensity() << "\n";
+          theDi << "  Type:       Ambient\n"
+                << "  Intensity:  " << aLight->Intensity() << "\n";
           break;
         }
         case V3d_DIRECTIONAL:
         {
-          theDi << "  Type:       Directional\n";
-          theDi << "  Intensity:  " << aLight->Intensity() << "\n";
-          theDi << "  Headlight:  " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
-          theDi << "  CastShadows:" << (aLight->ToCastShadows() ? "TRUE" : "FALSE") << "\n";
-          theDi << "  Smoothness: " << aLight->Smoothness() << "\n";
-          aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
-          theDi << "  Direction:  " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
+          theDi << "  Type:       Directional\n"
+                << "  Intensity:  " << aLight->Intensity() << "\n"
+                << "  Headlight:  " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"
+                << "  CastShadows:" << (aLight->ToCastShadows() ? "TRUE" : "FALSE") << "\n"
+                << "  Smoothness: " << aLight->Smoothness() << "\n"
+                << "  Direction:  " << aLight->PackedDirection().x() << " " << aLight->PackedDirection().y() << " " << aLight->PackedDirection().z() << "\n";
           break;
         }
         case V3d_POSITIONAL:
         {
-          theDi << "  Type:       Positional\n";
-          theDi << "  Intensity:  " << aLight->Intensity() << "\n";
-          theDi << "  Headlight:  " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
-          theDi << "  CastShadows:" << (aLight->ToCastShadows() ? "TRUE" : "FALSE") << "\n";
-          theDi << "  Smoothness: " << aLight->Smoothness() << "\n";
-          aLight->Position  (anXYZ[0], anXYZ[1], anXYZ[2]);
-          theDi << "  Position:   " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
-          aLight->Attenuation (anAtten[0], anAtten[1]);
-          theDi << "  Atten.:     " << anAtten[0] << " " << anAtten[1] << "\n";
-          theDi << "  Range:      " << aLight->Range() << "\n";
+          theDi << "  Type:       Positional\n"
+                << "  Intensity:  " << aLight->Intensity() << "\n"
+                << "  Headlight:  " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"
+                << "  CastShadows:" << (aLight->ToCastShadows() ? "TRUE" : "FALSE") << "\n"
+                << "  Smoothness: " << aLight->Smoothness() << "\n"
+                << "  Position:   " << aLight->Position().X() << " " << aLight->Position().Y() << " " << aLight->Position().Z() << "\n"
+                << "  Atten.:     " << aLight->ConstAttenuation() << " " << aLight->LinearAttenuation() << "\n"
+                << "  Range:      " << aLight->Range() << "\n";
           break;
         }
         case V3d_SPOT:
         {
-          theDi << "  Type:       Spot\n";
-          theDi << "  Intensity:  " << aLight->Intensity() << "\n";
-          theDi << "  Headlight:  " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n";
-          theDi << "  CastShadows:" << (aLight->ToCastShadows() ? "TRUE" : "FALSE") << "\n";
-          aLight->Position  (anXYZ[0], anXYZ[1], anXYZ[2]);
-          theDi << "  Position:   " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
-          aLight->Direction (anXYZ[0], anXYZ[1], anXYZ[2]);
-          theDi << "  Direction:  " << anXYZ[0] << ", " << anXYZ[1] << ", " << anXYZ[2] << "\n";
-          aLight->Attenuation (anAtten[0], anAtten[1]);
-          theDi << "  Atten.:     " << anAtten[0] << " " << anAtten[1] << "\n";
-          theDi << "  Angle:      " << (aLight->Angle() * 180.0 / M_PI) << "\n";
-          theDi << "  Exponent:   " << aLight->Concentration() << "\n";
-          theDi << "  Range:      " << aLight->Range() << "\n";
+          theDi << "  Type:       Spot\n"
+                << "  Intensity:  " << aLight->Intensity() << "\n"
+                << "  Headlight:  " << (aLight->Headlight() ? "TRUE" : "FALSE") << "\n"
+                << "  CastShadows:" << (aLight->ToCastShadows() ? "TRUE" : "FALSE") << "\n"
+                << "  Position:   " << aLight->Position().X() << " " << aLight->Position().Y() << " " << aLight->Position().Z() << "\n"
+                << "  Direction:  " << aLight->PackedDirection().x() << " " << aLight->PackedDirection().y() << " " << aLight->PackedDirection().z() << "\n"
+                << "  Atten.:     " << aLight->ConstAttenuation() << " " << aLight->LinearAttenuation() << "\n"
+                << "  Angle:      " << (aLight->Angle() * 180.0 / M_PI) << "\n"
+                << "  Exponent:   " << aLight->Concentration() << "\n"
+                << "  Range:      " << aLight->Range() << "\n";
           break;
         }
         default:
@@ -10374,110 +10359,115 @@ static int VLight (Draw_Interpretor& theDi,
           break;
         }
       }
-      theDi << "  Color:      " << aColor.Red() << ", " << aColor.Green() << ", " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
+      theDi << "  Color:      " << aColor.Red() << " " << aColor.Green() << " " << aColor.Blue() << " [" << Quantity_Color::StringName (aColor.Name()) << "]\n";
     }
   }
 
-  Handle(V3d_Light) aLightNew, aLightOld;
+  Handle(V3d_Light) aLightOld, aLightNew;
   Graphic3d_ZLayerId aLayer = Graphic3d_ZLayerId_UNKNOWN;
-  Standard_Boolean  isGlobal = Standard_True;
-  Standard_Boolean  toCreate = Standard_False;
-  ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView);
+  bool isGlobal = true;
+  ViewerTest_AutoUpdater anUpdateTool (aCtx, aView);
+  Handle(AIS_LightSource) aLightPrs;
   for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt)
   {
-    Handle(V3d_Light) aLightCurr = aLightNew.IsNull() ? aLightOld : aLightNew;
-
-    TCollection_AsciiString aName, aValue;
     const TCollection_AsciiString anArg (theArgVec[anArgIt]);
     TCollection_AsciiString anArgCase (anArg);
-    anArgCase.UpperCase();
+    anArgCase.LowerCase();
     if (anUpdateTool.parseRedrawMode (anArg))
     {
       continue;
     }
-
-    if (anArgCase.IsEqual ("NEW")
-     || anArgCase.IsEqual ("ADD")
-     || anArgCase.IsEqual ("CREATE")
-     || anArgCase.IsEqual ("-NEW")
-     || anArgCase.IsEqual ("-ADD")
-     || anArgCase.IsEqual ("-CREATE"))
-    {
-      toCreate = Standard_True;
-    }
-    else if (anArgCase.IsEqual ("-LAYER")
-          || anArgCase.IsEqual ("-ZLAYER"))
+    else if (anArgCase == "-new"
+          || anArgCase == "-add"
+          || anArgCase == "-create"
+          || anArgCase == "-type"
+          || (anArgCase == "-reset"
+          && !aLightNew.IsNull())
+          || (anArgCase == "-defaults"
+          && !aLightNew.IsNull())
+          || anArgCase == "add"
+          || anArgCase == "new"
+          || anArgCase == "create")
     {
-      if (++anArgIt >= theArgsNb)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-
-      TCollection_AsciiString aValStr (theArgVec[anArgIt]);
-      aValStr.LowerCase();
-      if (aValStr == "default"
-       || aValStr == "def")
-      {
-        aLayer = Graphic3d_ZLayerId_Default;
-      }
-      else if (aValStr == "top")
+      Graphic3d_TypeOfLightSource aType = Graphic3d_TypeOfLightSource_Ambient;
+      if (anArgCase == "-reset")
       {
-        aLayer = Graphic3d_ZLayerId_Top;
+        aType = aLightNew->Type();
       }
-      else if (aValStr == "topmost")
+      else if (anArgIt + 1 >= theArgsNb
+           || !parseLightSourceType (theArgVec[++anArgIt], aType))
       {
-        aLayer = Graphic3d_ZLayerId_Topmost;
+        theDi << "Syntax error at '" << theArgVec[anArgIt] << "'\n";
+        return 1;
       }
-      else if (aValStr == "toposd"
-            || aValStr == "osd")
+
+      TCollection_AsciiString aName;
+      if (!aLightNew.IsNull())
       {
-        aLayer = Graphic3d_ZLayerId_TopOSD;
+        aName = aLightNew->Name();
       }
-      else if (aValStr == "botosd"
-            || aValStr == "bottom")
+      switch (aType)
       {
-        aLayer = Graphic3d_ZLayerId_BotOSD;
+        case Graphic3d_TypeOfLightSource_Ambient:
+        {
+          aLightNew = new V3d_AmbientLight();
+          break;
+        }
+        case Graphic3d_TypeOfLightSource_Directional:
+        {
+          aLightNew = new V3d_DirectionalLight();
+          break;
+        }
+        case Graphic3d_TypeOfLightSource_Spot:
+        {
+          aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
+          break;
+        }
+        case Graphic3d_TypeOfLightSource_Positional:
+        {
+          aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
+          break;
+        }
       }
-      else if (aValStr.IsIntegerValue())
+
+      if (anArgCase == "-type"
+      && !aLightOld.IsNull())
       {
-        aLayer = Draw::Atoi (theArgVec[anArgIt]);
+        aLightNew->CopyFrom (aLightOld);
       }
-      else
+      aLightNew->SetName (aName);
+    }
+    else if ((anArgCase == "-layer"
+           || anArgCase == "-zlayer")
+          && anArgIt + 1 < theArgsNb)
+    {
+      if (!ViewerTest::ParseZLayer (theArgVec[++anArgIt], aLayer)
+      ||  aLayer == Graphic3d_ZLayerId_UNKNOWN)
       {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
+        Message::SendFail() << "Error: wrong syntax at '" << theArgVec[anArgIt] << "'";
         return 1;
       }
     }
-    else if (anArgCase.IsEqual ("GLOB")
-          || anArgCase.IsEqual ("GLOBAL")
-          || anArgCase.IsEqual ("-GLOB")
-          || anArgCase.IsEqual ("-GLOBAL"))
+    else if (anArgCase == "-glob"
+          || anArgCase == "-global"
+          || anArgCase == "-loc"
+          || anArgCase == "-local")
     {
-      isGlobal = Standard_True;
+      isGlobal = anArgCase.StartsWith ("-glob");
     }
-    else if (anArgCase.IsEqual ("LOC")
-          || anArgCase.IsEqual ("LOCAL")
-          || anArgCase.IsEqual ("-LOC")
-          || anArgCase.IsEqual ("-LOCAL"))
+    else if (anArgCase == "-def"
+          || anArgCase == "-defaults"
+          || anArgCase == "-reset")
     {
-      isGlobal = Standard_False;
-    }
-    else if (anArgCase.IsEqual ("DEF")
-          || anArgCase.IsEqual ("DEFAULTS")
-          || anArgCase.IsEqual ("-DEF")
-          || anArgCase.IsEqual ("-DEFAULTS"))
-    {
-      toCreate = Standard_False;
       aViewer->SetDefaultLights();
+      aLightOld.Nullify();
+      aLightNew.Nullify();
+      aLightPrs.Nullify();
     }
-    else if (anArgCase.IsEqual ("CLR")
-          || anArgCase.IsEqual ("CLEAR")
-          || anArgCase.IsEqual ("-CLR")
-          || anArgCase.IsEqual ("-CLEAR"))
+    else if (anArgCase == "-clr"
+          || anArgCase == "-clear"
+          || anArgCase == "clear")
     {
-      toCreate = Standard_False;
-
       TColStd_SequenceOfInteger aLayers;
       aViewer->GetAllZLayers (aLayers);
       for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
@@ -10497,551 +10487,472 @@ static int VLight (Draw_Interpretor& theDi,
 
       if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
       {
-        ViewerTest_DoubleMapOfInteractiveAndName aMap = GetMapOfAIS();
+        ViewerTest_DoubleMapOfInteractiveAndName& aMap = GetMapOfAIS();
         for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More();)
         {
           Handle(V3d_Light) aLight = aLightIter.Value();
-          if (Handle(AIS_LightSource) aLightSourceDel = findLightPrs (aLight, false))
+          Handle(AIS_InteractiveObject) aPrsObject;
+          GetMapOfAIS().Find2 (aLight->Name(), aPrsObject);
+          if (Handle(AIS_LightSource) aLightSourceDel = Handle(AIS_LightSource)::DownCast (aPrsObject))
           {
-            ViewerTest::GetAISContext()->Remove (aLightSourceDel, false);
-            GetMapOfAIS().UnBind2 (aLight->Name());
+            aCtx->Remove (aLightSourceDel, false);
+            aMap.UnBind1 (aLightSourceDel);
           }
           aViewer->DelLight (aLight);
           aLightIter = aView->ActiveLightIterator();
         }
       }
-    }
-    else if (anArgCase.IsEqual ("AMB")
-          || anArgCase.IsEqual ("AMBIENT")
-          || anArgCase.IsEqual ("AMBLIGHT"))
-    {
-      if (!toCreate)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-
-      addLight (aLightNew, aLayer, isGlobal);
-      toCreate  = Standard_False;
-      aLightNew = new V3d_AmbientLight();
-    }
-    else if (anArgCase.IsEqual ("DIRECTIONAL")
-          || anArgCase.IsEqual ("DIRLIGHT"))
-    {
-      if (!toCreate)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-
-      addLight (aLightNew, aLayer, isGlobal);
-      toCreate  = Standard_False;
-      aLightNew = new V3d_DirectionalLight();
-    }
-    else if (anArgCase.IsEqual ("SPOT")
-          || anArgCase.IsEqual ("SPOTLIGHT"))
-    {
-      if (!toCreate)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-
-      addLight (aLightNew, aLayer, isGlobal);
-      toCreate  = Standard_False;
-      aLightNew = new V3d_SpotLight (gp_Pnt (0.0, 0.0, 0.0));
-    }
-    else if (anArgCase.IsEqual ("POSLIGHT")
-          || anArgCase.IsEqual ("POSITIONAL"))
-    {
-      if (!toCreate)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-
-      addLight (aLightNew, aLayer, isGlobal);
-      toCreate  = Standard_False;
-      aLightNew = new V3d_PositionalLight (gp_Pnt (0.0, 0.0, 0.0));
-    }
-    else if (anArgCase.IsEqual ("CHANGE")
-          || anArgCase.IsEqual ("-CHANGE"))
-    {
-      if (++anArgIt >= theArgsNb)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
 
-      addLight (aLightNew, aLayer, isGlobal);
+      aLightOld.Nullify();
       aLightNew.Nullify();
-      const Standard_Integer aLightId = getLightId (theArgVec[anArgIt]);
-      Standard_Integer aLightIt = 0;
-      for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
-      {
-        if (aLightIt == aLightId)
-        {
-          aLightOld = aLightIter.Value();
-          break;
-        }
-      }
-
-      if (aLightOld.IsNull())
-      {
-        Message::SendFail() << "Error: Light " << theArgVec[anArgIt] << " is undefined";
-        return 1;
-      }
+      aLightPrs.Nullify();
     }
-    else if (anArgCase == "-DISPLAY"
-          || anArgCase == "-DISP"
-          || anArgCase == "-PRESENTATION"
-          || anArgCase == "-PRS")
+    else if (!aLightNew.IsNull()
+          && (anArgCase == "-display"
+           || anArgCase == "-disp"
+           || anArgCase == "-presentation"
+           || anArgCase == "-prs"))
     {
-      if (aLightCurr.IsNull())
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-
-      TCollection_AsciiString aLightName = aLightCurr->Name();
-      if (++anArgIt > theArgsNb
-       && aLightName.IsEmpty())
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-      if (anArgIt < theArgsNb)
+      TCollection_AsciiString aLightName = aLightNew->Name();
+      if (anArgIt + 1 < theArgsNb
+       && theArgVec[anArgIt + 1][0] != '-')
       {
-        if (theArgVec[anArgIt][0] != '-')
-        {
-          aLightName = theArgVec[anArgIt];
-          aLightCurr->SetName (aLightName);
-        }
-        else
+        // old syntax
+        aLightName = theArgVec[++anArgIt];
+        if (aLightNew->Name() != aLightName)
         {
-          --anArgIt;
+          if (Handle(V3d_Light) anOtherLight = findLightSource (aLightName))
+          {
+            theDi << "Syntax error: light with name '" << aLightName << "' is already defined";
+            return 1;
+          }
+          aLightNew->SetName (aLightName);
         }
       }
       if (aLightName.IsEmpty())
       {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-      ViewerTest::Display (aLightName, new AIS_LightSource (aLightCurr), false);
-    }
-    else if (anArgCase == "DEL"
-          || anArgCase == "DELETE"
-          || anArgCase == "-DEL"
-          || anArgCase == "-DELETE"
-          || anArgCase == "-REMOVE")
-    {
-      Handle(V3d_Light) aLightDel;
-      if (++anArgIt >= theArgsNb)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
+        Message::SendFail() << "Error: nameless light source cannot be displayed";
         return 1;
       }
-
-      const TCollection_AsciiString anArgNext (theArgVec[anArgIt]);
-      const Standard_Integer aLightDelId = getLightId (theArgVec[anArgIt]);
-      Standard_Integer aLightIt = 0;
-      for (V3d_ListOfLightIterator aLightIter (aView->ActiveLightIterator()); aLightIter.More(); aLightIter.Next(), ++aLightIt)
-      {
-        aLightDel = aLightIter.Value();
-        if (aLightIt == aLightDelId)
-        {
-          break;
-        }
-      }
-      if (aLightDel.IsNull())
-      {
-        continue;
-      }
-
-      TColStd_SequenceOfInteger aLayers;
-      aViewer->GetAllZLayers (aLayers);
-      for (TColStd_SequenceOfInteger::Iterator aLayeriter (aLayers); aLayeriter.More(); aLayeriter.Next())
+      if (aLightPrs.IsNull())
       {
-        if (aLayeriter.Value() == aLayer
-         || aLayer == Graphic3d_ZLayerId_UNKNOWN)
-        {
-          Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayeriter.Value());
-          if (!aSettings.Lights().IsNull())
-          {
-            aSettings.Lights()->Remove (aLightDel);
-            if (aSettings.Lights()->IsEmpty())
-            {
-              aSettings.SetLights (Handle(Graphic3d_LightSet)());
-            }
-          }
-          aViewer->SetZLayerSettings (aLayeriter.Value(), aSettings);
-          if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
-          {
-            break;
-          }
-        }
+        aLightPrs = new AIS_LightSource (aLightNew);
       }
-
-      if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
+      theDi << aLightName << " ";
+    }
+    else if (!aLightNew.IsNull()
+          && (anArgCase == "-disable"
+           || anArgCase == "-disabled"
+           || anArgCase == "-enable"
+           || anArgCase == "-enabled"))
+    {
+      bool toEnable = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
+      if (anArgCase == "-disable"
+       || anArgCase == "-disabled")
       {
-        if (Handle(AIS_LightSource) aLightSourceDel = findLightPrs (aLightDel, false))
-        {
-          ViewerTest::GetAISContext()->Remove (aLightSourceDel, false);
-          GetMapOfAIS().UnBind2 (aLightDel->Name());
-        }
-        aViewer->DelLight (aLightDel);
+        toEnable = !toEnable;
       }
+      aLightNew->SetEnabled (toEnable);
     }
-    else if (anArgCase.IsEqual ("COLOR")
-          || anArgCase.IsEqual ("COLOUR")
-          || anArgCase.IsEqual ("-COLOR")
-          || anArgCase.IsEqual ("-COLOUR"))
+    else if (!aLightNew.IsNull()
+          && (anArgCase == "-color"
+           || anArgCase == "-colour"
+           || anArgCase == "color"))
     {
       Quantity_Color aColor;
       Standard_Integer aNbParsed = Draw::ParseColor (theArgsNb - anArgIt - 1,
                                                      theArgVec + anArgIt + 1,
                                                      aColor);
       anArgIt += aNbParsed;
-      if (aNbParsed == 0
-       || aLightCurr.IsNull())
+      if (aNbParsed == 0)
       {
         Message::SendFail() << "Syntax error at argument '" << anArg << "'";
         return 1;
       }
-      aLightCurr->SetColor (aColor);
+      aLightNew->SetColor (aColor);
     }
-    else if (anArgCase == "POS"
-          || anArgCase == "POSITION"
-          || anArgCase == "-POS"
-          || anArgCase == "-POSITION"
-          || anArgCase == "-PRSPOSITION"
-          || anArgCase == "-PRSPOS")
+    else if (!aLightNew.IsNull()
+          && (anArgCase == "-pos"
+           || anArgCase == "-position"
+           || anArgCase == "-prsposition"
+           || anArgCase == "-prspos"
+           || anArgCase == "pos"
+           || anArgCase == "position")
+          && (anArgIt + 3) < theArgsNb)
     {
       gp_XYZ aPosXYZ;
-      if ((anArgIt + 3) >= theArgsNb
-       || !parseXYZ (theArgVec + anArgIt + 1, aPosXYZ)
-       || aLightCurr.IsNull())
+      if (!parseXYZ (theArgVec + anArgIt + 1, aPosXYZ))
       {
         Message::SendFail() << "Syntax error at argument '" << anArg << "'";
         return 1;
       }
 
       anArgIt += 3;
-      if (anArgCase == "-PRSPOSITION"
-       || anArgCase == "-PRSPOS")
+      if (anArgCase == "-prsposition"
+       || anArgCase == "-prspos")
       {
-        aLightCurr->SetDisplayPosition (aPosXYZ);
+        aLightNew->SetDisplayPosition (aPosXYZ);
       }
       else
       {
-        if (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
-         && aLightCurr->Type() != Graphic3d_TOLS_SPOT)
+        if (aLightNew->Type() != Graphic3d_TypeOfLightSource_Positional
+         && aLightNew->Type() != Graphic3d_TypeOfLightSource_Spot)
         {
           Message::SendFail() << "Syntax error at argument '" << anArg << "'";
           return 1;
         }
 
-        aLightCurr->SetPosition (aPosXYZ);
+        aLightNew->SetPosition (aPosXYZ);
       }
     }
-    else if (anArgCase.IsEqual ("DIR")
-          || anArgCase.IsEqual ("DIRECTION")
-          || anArgCase.IsEqual ("-DIR")
-          || anArgCase.IsEqual ("-DIRECTION"))
+    else if (!aLightNew.IsNull()
+          && (aLightNew->Type() == Graphic3d_TypeOfLightSource_Directional
+           || aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot)
+          && (anArgCase == "-dir"
+           || anArgCase == "-direction")
+          && (anArgIt + 3) < theArgsNb)
     {
       gp_XYZ aDirXYZ;
-      if ((anArgIt + 3) >= theArgsNb
-       || !parseXYZ (theArgVec + anArgIt + 1, aDirXYZ)
-       || aLightCurr.IsNull()
-       || (aLightCurr->Type() != Graphic3d_TOLS_DIRECTIONAL
-        && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
+      if (!parseXYZ (theArgVec + anArgIt + 1, aDirXYZ))
       {
         Message::SendFail() << "Syntax error at argument '" << anArg << "'";
         return 1;
       }
 
       anArgIt += 3;
-      aLightCurr->SetDirection (gp_Dir (aDirXYZ));
+      aLightNew->SetDirection (gp_Dir (aDirXYZ));
     }
-    else if (anArgCase.IsEqual ("SM")
-          || anArgCase.IsEqual ("SMOOTHNESS")
-          || anArgCase.IsEqual ("-SM")
-          || anArgCase.IsEqual ("-SMOOTHNESS"))
+    else if (!aLightNew.IsNull()
+          && (anArgCase == "-smoothangle"
+           || anArgCase == "-smoothradius"
+           || anArgCase == "-sm"
+           || anArgCase == "-smoothness")
+          && anArgIt + 1 < theArgsNb)
     {
-      if (++anArgIt >= theArgsNb
-       || aLightCurr.IsNull())
+      Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
+      if (aLightNew->Type() == Graphic3d_TypeOfLightSource_Directional)
       {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
+        aSmoothness = Standard_ShortReal(aSmoothness * M_PI / 180.0);
       }
-
-      Standard_ShortReal aSmoothness = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
       if (Abs (aSmoothness) <= ShortRealEpsilon())
       {
-        aLightCurr->SetIntensity (1.f);
+        aLightNew->SetIntensity (1.f);
       }
-      else if (Abs (aLightCurr->Smoothness()) <= ShortRealEpsilon())
+      else if (Abs (aLightNew->Smoothness()) <= ShortRealEpsilon())
       {
-        aLightCurr->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
+        aLightNew->SetIntensity ((aSmoothness * aSmoothness) / 3.f);
       }
       else
       {
-        Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightCurr->Smoothness());
-        aLightCurr->SetIntensity (aLightCurr->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
+        Standard_ShortReal aSmoothnessRatio = static_cast<Standard_ShortReal> (aSmoothness / aLightNew->Smoothness());
+        aLightNew->SetIntensity (aLightNew->Intensity() / (aSmoothnessRatio * aSmoothnessRatio));
       }
 
-      if (aLightCurr->Type() == Graphic3d_TOLS_POSITIONAL)
+      if (aLightNew->Type() == Graphic3d_TypeOfLightSource_Positional)
       {
-        aLightCurr->SetSmoothRadius (aSmoothness);
+        aLightNew->SetSmoothRadius (aSmoothness);
       }
-      else if (aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
+      else if (aLightNew->Type() == Graphic3d_TypeOfLightSource_Directional)
       {
-        aLightCurr->SetSmoothAngle (aSmoothness);
+        aLightNew->SetSmoothAngle (aSmoothness);
       }
     }
-    else if (anArgCase.IsEqual ("INT")
-          || anArgCase.IsEqual ("INTENSITY")
-          || anArgCase.IsEqual ("-INT")
-          || anArgCase.IsEqual ("-INTENSITY"))
+    else if (!aLightNew.IsNull()
+          && (anArgCase == "-int"
+           || anArgCase == "-intensity")
+          && anArgIt + 1 < theArgsNb)
     {
-      if (++anArgIt >= theArgsNb
-       || aLightCurr.IsNull())
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-
-      Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
-      aLightCurr->SetIntensity (aIntensity);
+      Standard_ShortReal aIntensity = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
+      aLightNew->SetIntensity (aIntensity);
     }
-    else if (anArgCase.IsEqual ("ANG")
-          || anArgCase.IsEqual ("ANGLE")
-          || anArgCase.IsEqual ("-ANG")
-          || anArgCase.IsEqual ("-ANGLE"))
+    else if (!aLightNew.IsNull()
+          &&  aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot
+          && (anArgCase == "-spotangle"
+           || anArgCase == "-ang"
+           || anArgCase == "-angle")
+          && anArgIt + 1 < theArgsNb)
     {
-      if (++anArgIt >= theArgsNb
-       || aLightCurr.IsNull()
-       || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-      Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[anArgIt]);
+      Standard_ShortReal anAngle = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
       anAngle = (Standard_ShortReal (anAngle / 180.0 * M_PI));
-      aLightCurr->SetAngle (anAngle);
-    }
-    else if (anArgCase.IsEqual ("CONSTATTEN")
-          || anArgCase.IsEqual ("CONSTATTENUATION")
-          || anArgCase.IsEqual ("-CONSTATTEN")
-          || anArgCase.IsEqual ("-CONSTATTENUATION"))
+      aLightNew->SetAngle (anAngle);
+    }
+    else if (!aLightNew.IsNull()
+          && (aLightNew->Type() == Graphic3d_TypeOfLightSource_Positional
+           || aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot)
+          && (anArgCase == "-constatten"
+           || anArgCase == "-constattenuation")
+          && anArgIt + 1 < theArgsNb)
+    {
+      const Standard_ShortReal aConstAtten = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
+      aLightNew->SetAttenuation (aConstAtten, aLightNew->LinearAttenuation());
+    }
+    else if (!aLightNew.IsNull()
+          && (aLightNew->Type() == Graphic3d_TypeOfLightSource_Positional
+           || aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot)
+          && (anArgCase == "-linatten"
+           || anArgCase == "-linearatten"
+           || anArgCase == "-linearattenuation")
+          && anArgIt + 1 < theArgsNb)
+    {
+      const Standard_ShortReal aLinAtten = (Standard_ShortReal )Atof (theArgVec[++anArgIt]);
+      aLightNew->SetAttenuation (aLightNew->ConstAttenuation(), aLinAtten);
+    }
+    else if (!aLightNew.IsNull()
+          && aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot
+          && (anArgCase == "-spotexp"
+           || anArgCase == "-spotexponent"
+           || anArgCase == "-exp"
+           || anArgCase == "-exponent")
+          && anArgIt + 1 < theArgsNb)
+    {
+      aLightNew->SetConcentration ((Standard_ShortReal )Atof (theArgVec[++anArgIt]));
+    }
+    else if (!aLightNew.IsNull()
+           && aLightNew->Type() != Graphic3d_TypeOfLightSource_Ambient
+           && aLightNew->Type() != Graphic3d_TypeOfLightSource_Directional
+           && anArgCase == "-range"
+           && anArgIt + 1 < theArgsNb)
+    {
+      Standard_ShortReal aRange ((Standard_ShortReal)Atof (theArgVec[++anArgIt]));
+      aLightNew->SetRange (aRange);
+    }
+    else if (!aLightNew.IsNull()
+          && aLightNew->Type() != Graphic3d_TypeOfLightSource_Ambient
+          && (anArgCase == "-head"
+           || anArgCase == "-headlight"))
     {
-      if (++anArgIt >= theArgsNb
-       || aLightCurr.IsNull()
-       || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
-        && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
+      Standard_Boolean isHeadLight = Standard_True;
+      if (anArgIt + 1 < theArgsNb
+       && Draw::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
       {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
+        ++anArgIt;
       }
-
-      aLightCurr->Attenuation (anAtten[0], anAtten[1]);
-      anAtten[0] = Atof (theArgVec[anArgIt]);
-      aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
+      aLightNew->SetHeadlight (isHeadLight);
     }
-    else if (anArgCase.IsEqual ("LINATTEN")
-          || anArgCase.IsEqual ("LINEARATTEN")
-          || anArgCase.IsEqual ("LINEARATTENUATION")
-          || anArgCase.IsEqual ("-LINATTEN")
-          || anArgCase.IsEqual ("-LINEARATTEN")
-          || anArgCase.IsEqual ("-LINEARATTENUATION"))
+    else if (!aLightNew.IsNull()
+           && anArgCase == "-name"
+           && anArgIt + 1 < theArgsNb)
     {
-      if (++anArgIt >= theArgsNb
-       || aLightCurr.IsNull()
-       || (aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL
-        && aLightCurr->Type() != Graphic3d_TOLS_SPOT))
+      const TCollection_AsciiString aName = theArgVec[++anArgIt];
+      if (aLightNew->Name() == aName)
       {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
+        continue;
       }
 
-      aLightCurr->Attenuation (anAtten[0], anAtten[1]);
-      anAtten[1] = Atof (theArgVec[anArgIt]);
-      aLightCurr->SetAttenuation ((Standard_ShortReal )anAtten[0], (Standard_ShortReal )anAtten[1]);
-    }
-    else if (anArgCase.IsEqual ("EXP")
-          || anArgCase.IsEqual ("EXPONENT")
-          || anArgCase.IsEqual ("SPOTEXP")
-          || anArgCase.IsEqual ("SPOTEXPONENT")
-          || anArgCase.IsEqual ("-EXP")
-          || anArgCase.IsEqual ("-EXPONENT")
-          || anArgCase.IsEqual ("-SPOTEXP")
-          || anArgCase.IsEqual ("-SPOTEXPONENT"))
-    {
-      if (++anArgIt >= theArgsNb
-       || aLightCurr.IsNull()
-       || aLightCurr->Type() != Graphic3d_TOLS_SPOT)
+      if (Handle(V3d_Light) anOtherLight = findLightSource (aName))
       {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
+        theDi << "Syntax error: light with name '" << aName << "' is already defined";
         return 1;
       }
-
-      aLightCurr->SetConcentration ((Standard_ShortReal )Atof (theArgVec[anArgIt]));
+      aLightNew->SetName (aName);
     }
-    else if (anArgCase.IsEqual("RANGE")
-          || anArgCase.IsEqual("-RANGE"))
+    else if (!aLightPrs.IsNull()
+          && (anArgCase == "-showzoomable"
+           || anArgCase == "-prszoomable"
+           || anArgCase == "-zoomable"))
     {
-      if (++anArgIt >= theArgsNb
-       || aLightCurr.IsNull()
-       || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT
-       || aLightCurr->Type() == Graphic3d_TOLS_DIRECTIONAL)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-      Standard_ShortReal aRange ((Standard_ShortReal)Atof (theArgVec[anArgIt]));
-      aLightCurr->SetRange (aRange);
+      const bool isZoomable = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
+      aLightPrs->SetZoomable (isZoomable);
+    }
+    else if (!aLightPrs.IsNull()
+          && (anArgCase == "-showname"
+           || anArgCase == "-prsname"))
+    {
+      const bool toDisplay = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
+      aLightPrs->SetDisplayName (toDisplay);
     }
-    else if (anArgCase.IsEqual ("HEAD")
-          || anArgCase.IsEqual ("HEADLIGHT")
-          || anArgCase.IsEqual ("-HEAD")
-          || anArgCase.IsEqual ("-HEADLIGHT"))
+    else if (!aLightPrs.IsNull()
+          && (aLightNew->Type() == Graphic3d_TypeOfLightSource_Spot
+           || aLightNew->Type() == Graphic3d_TypeOfLightSource_Positional)
+          && (anArgCase == "-showrange"
+           || anArgCase == "-prsrange"))
     {
-      if (aLightCurr.IsNull()
-       || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
+      const bool toDisplay = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
+      aLightPrs->SetDisplayRange (toDisplay);
+    }
+    else if (!aLightPrs.IsNull()
+          && (anArgCase == "-showsize"
+           || anArgCase == "-prssize")
+          && anArgIt + 1 < theArgsNb)
+    {
+      Standard_Real aSize = 0.0;
+      if (!Draw::ParseReal (theArgVec[++anArgIt], aSize)
+       || aSize <= 0.0
+       || aLightPrs.IsNull())
       {
         Message::SendFail() << "Syntax error at argument '" << anArg << "'";
         return 1;
       }
 
-      Standard_Boolean isHeadLight = Standard_True;
+      aLightPrs->SetSize (aSize);
+    }
+    else if (!aLightNew.IsNull()
+          && aLightNew->Type() != Graphic3d_TypeOfLightSource_Ambient
+          && (anArgCase == "-castshadow"
+           || anArgCase == "-castshadows"
+           || anArgCase == "-shadows"))
+    {
+      bool toCastShadows = true;
       if (anArgIt + 1 < theArgsNb
-       && Draw::ParseOnOff (theArgVec[anArgIt + 1], isHeadLight))
+       && Draw::ParseOnOff (theArgVec[anArgIt + 1], toCastShadows))
       {
         ++anArgIt;
       }
-      aLightCurr->SetHeadlight (isHeadLight);
+      aLightNew->SetCastShadows (toCastShadows);
     }
-    else if (anArgCase.IsEqual ("NAME")
-          || anArgCase.IsEqual ("-NAME"))
+    else if (anArgCase == "-del"
+          || anArgCase == "-delete"
+          || anArgCase == "-remove"
+          || anArgCase == "del"
+          || anArgCase == "delete"
+          || anArgCase == "remove")
     {
-      if ((anArgIt + 1) >= theArgsNb
-        || aLightCurr.IsNull())
+      if (aLightOld.IsNull())
       {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
+        if (!aLightNew.IsNull())
+        {
+          aLightNew.Nullify();
+          continue;
+        }
+
+        if (++anArgIt >= theArgsNb)
+        {
+          Message::SendFail() << "Syntax error at argument '" << anArg << "'";
+          return 1;
+        }
+
+        const TCollection_AsciiString anOldName (theArgVec[anArgIt]);
+        aLightOld = findLightSource (anOldName);
+        if (aLightOld.IsNull())
+        {
+          Message::SendWarning() << "Warning: light '" << anOldName << "' not found";
+          continue;
+        }
       }
-      aName = theArgVec[++anArgIt];
-      aLightCurr->SetName (aName);
+
+      aLightNew.Nullify();
+      aLightPrs.Nullify();
     }
-    else if (anArgCase == "-SHOWZOOMABLE"
-          || anArgCase == "-PRSZOOMABLE"
-          || anArgCase == "-ZOOMABLE")
+    else if (anArgCase == "-change"
+          || anArgCase == "change")
     {
-      if (aLightCurr.IsNull())
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-
-      if (Handle(AIS_LightSource) aLightSource = findLightPrs (aLightCurr))
-      {
-        const bool isZoomable = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
-        aLightSource->SetZoomable (isZoomable);
-      }
-      else
-      {
-        return 1;
-      }
+      // just skip old syntax
     }
-    else if (anArgCase == "-SHOWNAME"
-          || anArgCase == "-PRSNAME")
+    else if (aLightNew.IsNull()
+         && !anArgCase.StartsWith ("-"))
     {
-      if (aLightCurr.IsNull())
+      if (!aLightNew.IsNull())
       {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
+        continue;
       }
 
-      if (Handle(AIS_LightSource) aLightSource = findLightPrs (aLightCurr))
+      const TCollection_AsciiString anOldName (theArgVec[anArgIt]);
+      aLightOld = findLightSource (anOldName);
+      if (!aLightOld.IsNull())
       {
-        const bool toDisplay = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
-        aLightSource->SetDisplayName (toDisplay);
+        aLightNew = aLightOld;
+
+        Handle(AIS_InteractiveObject) aPrsObject;
+        GetMapOfAIS().Find2 (aLightOld->Name(), aPrsObject);
+        aLightPrs = Handle(AIS_LightSource)::DownCast (aPrsObject);
       }
       else
       {
-        return 1;
+        Standard_Integer aLightIndex = -1;
+        Draw::ParseInteger (anOldName.ToCString(), aLightIndex);
+        if (aLightIndex != -1)
+        {
+          Message::SendFail() << "Syntax error: light source with index '" << aLightIndex << "' is not found";
+          return 1;
+        }
+
+        aLightNew = new V3d_AmbientLight();
+        aLightNew->SetName (anOldName);
       }
     }
-    else if (anArgCase == "-SHOWRANGE"
-          || anArgCase == "-PRSRANGE")
+    else
     {
-      if (aLightCurr.IsNull()
-      || (aLightCurr->Type() != Graphic3d_TOLS_SPOT
-       && aLightCurr->Type() != Graphic3d_TOLS_POSITIONAL))
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
+      Message::SendFail() << "Warning: unknown argument '" << anArg << "'";
+      return 1;
+    }
+  }
 
-      if (Handle(AIS_LightSource) aLightSource = findLightPrs (aLightCurr))
-      {
-        const bool toDisplay = Draw::ParseOnOffIterator (theArgsNb, theArgVec, anArgIt);
-        aLightSource->SetDisplayRange (toDisplay);
-      }
-      else
+  // delete old light source
+  if (!aLightOld.IsNull()
+    && aLightOld != aLightNew)
+  {
+    TColStd_SequenceOfInteger aLayers;
+    aViewer->GetAllZLayers (aLayers);
+    for (TColStd_SequenceOfInteger::Iterator aLayerIter (aLayers); aLayerIter.More(); aLayerIter.Next())
+    {
+      if (aLayerIter.Value() == aLayer
+       || aLayer == Graphic3d_ZLayerId_UNKNOWN)
       {
-        return 1;
+        Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayerIter.Value());
+        if (!aSettings.Lights().IsNull())
+        {
+          aSettings.Lights()->Remove (aLightOld);
+          if (aSettings.Lights()->IsEmpty())
+          {
+            aSettings.SetLights (Handle(Graphic3d_LightSet)());
+          }
+        }
+        aViewer->SetZLayerSettings (aLayerIter.Value(), aSettings);
+        if (aLayer != Graphic3d_ZLayerId_UNKNOWN)
+        {
+          break;
+        }
       }
     }
-    else if (anArgCase == "-SHOWSIZE"
-          || anArgCase == "-PRSSIZE")
+
+    if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
     {
-      Standard_Real aSize = 0.0;
-      if ((anArgIt + 1) >= theArgsNb
-      || !Draw::ParseReal (theArgVec[anArgIt + 1], aSize)
-      ||  aSize <= 0.0)
+      Handle(AIS_InteractiveObject) aPrsObject;
+      GetMapOfAIS().Find2 (aLightOld->Name(), aPrsObject);
+      if (Handle(AIS_LightSource) aLightSourceDel = Handle(AIS_LightSource)::DownCast (aPrsObject))
       {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
+        aCtx->Remove (aLightSourceDel, false);
+        GetMapOfAIS().UnBind1 (aLightSourceDel);
       }
+      aViewer->DelLight (aLightOld);
+    }
+    aLightOld.Nullify();
+  }
 
-      ++anArgIt;
-      if (Handle(AIS_LightSource) aLightSource = findLightPrs (aLightCurr))
+  // add new light source
+  if (!aLightNew.IsNull())
+  {
+    if (aLayer == Graphic3d_ZLayerId_UNKNOWN)
+    {
+      aViewer->AddLight (aLightNew);
+      if (isGlobal)
       {
-        aLightSource->SetSize (aSize);
+        aViewer->SetLightOn (aLightNew);
       }
       else
       {
-        return 1;
+        aView->SetLightOn (aLightNew);
       }
     }
-    else if (anArgCase.IsEqual ("-CASTSHADOW")
-          || anArgCase.IsEqual ("-CASTSHADOWS")
-          || anArgCase.IsEqual ("-SHADOWS"))
+    else
     {
-      if (aLightCurr.IsNull()
-       || aLightCurr->Type() == Graphic3d_TOLS_AMBIENT)
-      {
-        Message::SendFail() << "Syntax error at argument '" << anArg << "'";
-        return 1;
-      }
-
-      bool toCastShadows = true;
-      if (anArgIt + 1 < theArgsNb
-       && Draw::ParseOnOff (theArgVec[anArgIt + 1], toCastShadows))
+      Graphic3d_ZLayerSettings aSettings = aViewer->ZLayerSettings (aLayer);
+      if (aSettings.Lights().IsNull())
       {
-        ++anArgIt;
+        aSettings.SetLights (new Graphic3d_LightSet());
       }
-      aLightCurr->SetCastShadows (toCastShadows);
+      aSettings.Lights()->Add (aLightNew);
+      aViewer->SetZLayerSettings (aLayer, aSettings);
     }
-    else
+
+    if (!aLightPrs.IsNull())
     {
-      Message::SendFail() << "Warning: unknown argument '" << anArg << "'";
+      aLightPrs->SetLight (aLightNew);
+      ViewerTest::Display (aLightNew->Name(), aLightPrs, false);
     }
   }
 
-  addLight (aLightNew, aLayer, isGlobal);
-
+  // manage presentations
   struct LightPrsSort
   {
     bool operator() (const Handle(AIS_LightSource)& theLeft,
@@ -11052,16 +10963,16 @@ static int VLight (Draw_Interpretor& theDi,
   };
 
   AIS_ListOfInteractive aPrsList;
-  ViewerTest::GetAISContext()->DisplayedObjects (AIS_KindOfInteractive_LightSource, -1, aPrsList);
+  aCtx->DisplayedObjects (AIS_KindOfInteractive_LightSource, -1, aPrsList);
   if (!aPrsList.IsEmpty())
   {
     // update light source presentations
     std::vector<Handle(AIS_LightSource)> aLightPrsVec;
     for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More(); aPrsIter.Next())
     {
-      if (Handle(AIS_LightSource) aLightPrs = Handle(AIS_LightSource)::DownCast (aPrsIter.Value()))
+      if (Handle(AIS_LightSource) aLightPrs2 = Handle(AIS_LightSource)::DownCast (aPrsIter.Value()))
       {
-        aLightPrsVec.push_back (aLightPrs);
+        aLightPrsVec.push_back (aLightPrs2);
       }
     }
 
@@ -11071,16 +10982,16 @@ static int VLight (Draw_Interpretor& theDi,
     Standard_Integer aTopStack = 0;
     for (std::vector<Handle(AIS_LightSource)>::iterator aPrsIter = aLightPrsVec.begin(); aPrsIter != aLightPrsVec.end(); ++aPrsIter)
     {
-      Handle(AIS_LightSource) aLightPrs = *aPrsIter;
-      if (!aLightPrs->TransformPersistence().IsNull()
-        && aLightPrs->TransformPersistence()->IsTrihedronOr2d())
+      Handle(AIS_LightSource) aLightPrs2 = *aPrsIter;
+      if (!aLightPrs2->TransformPersistence().IsNull()
+        && aLightPrs2->TransformPersistence()->IsTrihedronOr2d())
       {
-        const Standard_Integer aPrsSize = (Standard_Integer )aLightPrs->Size();
-        aLightPrs->TransformPersistence()->SetOffset2d (Graphic3d_Vec2i (aTopStack + aPrsSize, aPrsSize));
+        const Standard_Integer aPrsSize = (Standard_Integer )aLightPrs2->Size();
+        aLightPrs2->TransformPersistence()->SetOffset2d (Graphic3d_Vec2i (aTopStack + aPrsSize, aPrsSize));
         aTopStack += aPrsSize + aPrsSize / 2;
       }
-      ViewerTest::GetAISContext()->Redisplay (aLightPrs, false);
-      ViewerTest::GetAISContext()->SetTransformPersistence (aLightPrs, aLightPrs->TransformPersistence());
+      aCtx->Redisplay (aLightPrs2, false);
+      aCtx->SetTransformPersistence (aLightPrs2, aLightPrs2->TransformPersistence());
     }
   }
   return 0;
@@ -14967,36 +14878,63 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
        "\n\t\t:           [-autoTriang {off/on | 0/1}]"
     , __FILE__, VDefaults, group);
   theCommands.Add("vlight",
-    "tool to manage light sources, without arguments shows list of lights."
-    "\n    Main commands: "
-    "\n      '-clear' to clear lights"
-    "\n      '-{def}aults' to load default lights"
-    "\n      '-add' <type> to add any light source"
-    "\n          where <type> is one of {amb}ient|directional|{spot}light|positional"
-    "\n      'change' <lightId> to edit light source with specified lightId"
-    "\n\n      In addition to 'add' and 'change' commands you can use light parameters:"
-    "\n        -layer Id"
-    "\n        -{pos}ition X Y Z"
-    "\n        -{dir}ection X Y Z (for directional light or for spotlight)"
-    "\n        -color colorName"
-    "\n        -{head}light 0|1"
-    "\n        -castShadows 0|1"
-    "\n        -{sm}oothness value"
-    "\n        -{int}ensity value"
-    "\n        -{constAtten}uation value"
-    "\n        -{linearAtten}uation value"
-    "\n        -angle angleDeg"
-    "\n        -{spotexp}onent value"
-    "\n        -range value"
-    "\n        -local|-global"
-    "\n        -name value"
-    "\n        -display nameOfLight (display light source with specified nameOfLight or its name)"
-    "\n        -showName  {1|0} show/hide the name of light source; 1 by default"
-    "\n        -showRange {1|0} show/hide the range of spot/positional light source; 1 by default"
-    "\n        -prsZoomable {1|0} make light presentation zoomable/non-zoomable"
-    "\n        -prsSize {Value} set light presentation size"
-    "\n\n      example: vlight -add positional -head 1 -pos 0 1 1 -color red"
-    "\n        example: vlight -change 0 -direction 0 -1 0 -linearAttenuation 0.2",
+              "vlight [lightName] [-noupdate]"
+      "\n\t\t:   [-clear|-defaults] [-layer Id] [-local|-global] [-disable|-enable]"
+      "\n\t\t:   [-type {ambient|directional|spotlight|positional}] [-name value]"
+      "\n\t\t:   [-position X Y Z] [-direction X Y Z] [-color colorName] [-intensity value]"
+      "\n\t\t:   [-headlight 0|1] [-castShadows 0|1]"
+      "\n\t\t:   [-range value] [-constAttenuation value] [-linearAttenuation value]"
+      "\n\t\t:   [-spotExponent value] [-spotAngle angleDeg]"
+      "\n\t\t:   [-smoothAngle value] [-smoothRadius value]"
+      "\n\t\t:   [-display] [-showName 1|0] [-showRange 1|0] [-prsZoomable 1|0] [-prsSize Value]"
+      "\n\t\t: Command manages light sources. Without arguments shows list of lights."
+      "\n\t\t: Arguments affecting the list of defined/active lights:"
+      "\n\t\t:   -clear       remove all light sources"
+      "\n\t\t:   -defaults    defines two standard light sources"
+      "\n\t\t:   -reset       resets light source parameters to default values"
+      "\n\t\t:   -type        sets type of light source"
+      "\n\t\t:   -name        sets new name to light source"
+      "\n\t\t:   -global      assigns light source to all views (default state)"
+      "\n\t\t:   -local       assigns light source to active view"
+      "\n\t\t:   -zlayer      assigns light source to specified Z-Layer"
+      "\n\t\t: Ambient light parameters:"
+      "\n\t\t:   -color       sets (normalized) light color"
+      "\n\t\t:   -intensity   sets intensity of light source, 1.0 by default;"
+      "\n\t\t:                affects also environment cubemap intensity"
+      "\n\t\t: Point light parameters:"
+      "\n\t\t:   -color       sets (normalized) light color"
+      "\n\t\t:   -intensity   sets PBR intensity"
+      "\n\t\t:   -range       sets clamping distance"
+      "\n\t\t:   -constAtten  (obsolete) sets constant attenuation factor"
+      "\n\t\t:   -linearAtten (obsolete) sets linear   attenuation factor"
+      "\n\t\t:   -smoothRadius sets PBR smoothing radius"
+      "\n\t\t: Directional light parameters:"
+      "\n\t\t:   -color       sets (normalized) light color"
+      "\n\t\t:   -intensity   sets PBR intensity"
+      "\n\t\t:   -direction   sets direction"
+      "\n\t\t:   -headlight   sets headlight flag"
+      "\n\t\t:   -castShadows enables/disables shadow casting"
+      "\n\t\t:   -smoothAngle sets PBR smoothing angle (in degrees) within 0..90 range"
+      "\n\t\t: Spot light parameters:"
+      "\n\t\t:   -color       sets (normalized) light color"
+      "\n\t\t:   -intensity   sets PBR intensity"
+      "\n\t\t:   -range       sets clamping distance"
+      "\n\t\t:   -position    sets position"
+      "\n\t\t:   -direction   sets direction"
+      "\n\t\t:   -spotAngle   sets spotlight angle"
+      "\n\t\t:   -spotExp     sets spotlight exponenta"
+      "\n\t\t:   -headlight   sets headlight flag"
+      "\n\t\t:   -constAtten  (obsolete) sets constant attenuation factor"
+      "\n\t\t:   -linearAtten (obsolete) sets linear   attenuation factor"
+      "\n\t\t: Light presentation parameters:"
+      "\n\t\t:   -display     adds light source presentation"
+      "\n\t\t:   -showName    shows/hides the name of light source; 1 by default"
+      "\n\t\t:   -showRange   shows/hides the range of spot/positional light source; 1 by default"
+      "\n\t\t:   -prsZoomable makes light presentation zoomable/non-zoomable"
+      "\n\t\t:   -prsSize     sets light presentation size"
+      "\n\t\t: Examples:"
+      "\n\t\t:   vlight redlight -type POSITIONAL -headlight 1 -pos 0 1 1 -color RED"
+      "\n\t\t:   vlight redlight -delete",
     __FILE__, VLight, group);
   theCommands.Add("vpbrenv",
     "vpbrenv -clear|-generate"
index cce3f0b..0103571 100644 (file)
@@ -43,7 +43,7 @@ vdisplay -top -dispMode 1 -trsfPers zoom -trsfPersPos 1000 0 0 zp
 vclipplane pln -equation -1 0 0 1000 -set
 
 # check positional lights
-vlight add positional pos 1000 0 0.001 color RED1 headlight 0
+vlight pntlight -type POSITIONAL -pos 1000 0 0.001 -color RED1 -headlight 0
 
 vremove f1000
 vmoveto 220 220
index ccb4fe7..7c2134b 100644 (file)
@@ -1,5 +1,5 @@
 puts "========"
-puts "Test to verify the lights are turned off after 'vlight clear' (and scene is black)"
+puts "Test to verify the lights are turned off after 'vlight -clear' (and scene is black)"
 puts "========"
 
 pload MODELING VISUALIZATION
@@ -15,7 +15,7 @@ vsetdispmode 1
 vdisplay b
 vfit
 
-vlight clear
+vlight -clear
 
 set color [vreadpixel 100 100 rgb]
 set black "0 0 0"
index 37c014a..9896f29 100644 (file)
@@ -22,7 +22,7 @@ vdisplay s1 s2
 vsetmaterial s1 Gold
 vsetmaterial s2 Silver
 vsetlocation s1 0.0 0.1 0.0
-vlight -change 0 -dir 0.667 -0.667 -0.333
+vlight -change 0 -dir 0.667 -0.667 -0.333 -smoothAngle 6 -intensity 100
 vturnview 3.0 -1.2 -0.1
 vfit
 
@@ -33,8 +33,6 @@ vrenderparams -rayDepth 12
 
 set aModeNum 0
 
-vlight change 0 sm 0.1
-vlight change 0 int 100
 vbsdf s1 roughness 6400
 
 vfps 200
@@ -52,4 +50,4 @@ vsetmaterial s2 plaster
 
 vfps 200
 vdump $imagedir/${casename}_${aModeNum}.png
-incr aModeNum
\ No newline at end of file
+incr aModeNum
index 952c132..58bf6a6 100644 (file)
@@ -72,6 +72,6 @@ vfront
 vturnview 0 -0.3 0
 vfit
 vlight -change 0 -dir -0.577 -0.577 -0.577
-vlight add directional
+vlight dirlight -type directional
 vrenderparams -raytrace -raydepth 5 -shadows off -reflections -fsaa
 vdump ${imagedir}/${casename}.png
index 01267ab..306d8bf 100644 (file)
@@ -10,7 +10,6 @@ tclean f
 
 # draw box
 vclear
-vclose ALL
 vinit View1
 vdefaults -absDefl 0.5
 vsetdispmode 1
index 98cf4f8..c3d8260 100644 (file)
@@ -10,7 +10,6 @@ tclean f
 
 # draw box
 vclear
-vclose ALL
 vinit View1
 vdefaults -absDefl 0.5
 vsetdispmode 1
@@ -21,14 +20,10 @@ vrotate -0.5 0.0 0.0
 vfit
 
 # setup lights
-vlight delete 0
-vlight delete 0
-vlight delete 0
-vlight delete 0
-vlight delete 0
-vlight add ambient                color WHITE
-vlight add directional dir  1 0 0 color GREEN headlight 1
-vlight add directional dir -1 0 0 color RED1  headlight 1
+vlight -clear
+vlight amblight  -type AMBIENT                 -color WHITE
+vlight dirlight1 -type DIRECTIONAL -dir  1 0 0 -color GREEN -headlight 1
+vlight dirlight2 -type DIRECTIONAL -dir -1 0 0 -color RED1  -headlight 1
 
 # take snapshot with fixed pipeline
 vdump $::imagedir/${::casename}_OFF.png
index 19dd37f..7256b58 100644 (file)
@@ -13,10 +13,10 @@ vdefaults -absDefl 0.5
 vdisplay -dispMode 1 f
 
 # setup lights
-vlight clear
-vlight add ambient                color WHITE
-vlight add directional dir  1 0 0 color GREEN headlight 1
-vlight add directional dir -1 0 0 color RED1  headlight 1
+vlight -clear
+vlight amblight  -type AMBIENT                 -color WHITE
+vlight dirlight1 -type DIRECTIONAL -dir  1 0 0 -color GREEN -headlight 1
+vlight dirlight2 -type DIRECTIONAL -dir -1 0 0 -color RED1  -headlight 1
 
 vrenderparams -shadingModel flat
 vdump $::imagedir/${::casename}.png
index 43b99ec..6cd3bd2 100644 (file)
@@ -9,14 +9,10 @@ vclose ALL
 vinit View1
 vcaps -ffp 0
 vrenderparams -shadingModel vert
-vlight delete 0
-vlight delete 0
-vlight delete 0
-vlight delete 0
-vlight delete 0
-vlight add ambient                color WHITE
-vlight add directional dir  1 0 0 color GREEN headlight 1
-vlight add directional dir -1 0 0 color RED1  headlight 1
+vlight -clear
+vlight amblight  -type AMBIENT                 -color WHITE
+vlight dirlight1 -type DIRECTIONAL -dir  1 0 0 -color GREEN -headlight 1
+vlight dirlight2 -type DIRECTIONAL -dir -1 0 0 -color RED1  -headlight 1
 
 # display shape
 restore [locate_data_file occ/fuse.brep] f
index be6d844..71f3c60 100644 (file)
@@ -28,8 +28,8 @@ vfit
 # setup light
 vcaps -ffp 0
 vrenderparams -shadingModel vert
-vlight clear
-vlight add positional pos $anX 0 0.001 color RED1 headLight 0
+vlight -clear
+vlight pntlight -type POSITIONAL -pos $anX 0 0.001 -color RED1 -headLight 0
 
 set aColor1 [vreadpixel 205 180 rgb name]
 set aColor2 [vreadpixel 205 210 rgb name]
index a4cffc6..2940272 100644 (file)
@@ -28,8 +28,8 @@ vfit
 # setup light
 vcaps -ffp 0
 vrenderparams -shadingModel vert
-vlight clear
-vlight add spotLight pos $anX 0 0.001 dir 0 0 -1 angle 60 constAtten 0.1 exponent 0.1 color RED1 headLight 0
+vlight -clear
+vlight spot -type SPOTLIGHT -pos $anX 0 0.001 -dir 0 0 -1 -spotAngle 60 -constAtten 0.1 -exponent 0.1 -color RED1 -headLight 0
 
 set aColor1 [vreadpixel 205 180 rgb name]
 set aColor2 [vreadpixel 205 220 rgb name]
index 3a3b024..b5195a9 100644 (file)
@@ -11,14 +11,10 @@ vclose ALL
 vinit View1
 vcaps -ffp 0
 vrenderparams -shadingModel phong
-vlight delete 0
-vlight delete 0
-vlight delete 0
-vlight delete 0
-vlight delete 0
-vlight add ambient                color WHITE
-vlight add directional dir  1 0 0 color GREEN headlight 1
-vlight add directional dir -1 0 0 color RED1  headlight 1
+vlight -clear
+vlight amblight  -type AMBIENT                 -color WHITE
+vlight dirlight1 -type DIRECTIONAL -dir  1 0 0 -color GREEN -headlight 1
+vlight dirlight2 -type DIRECTIONAL -dir -1 0 0 -color RED1  -headlight 1
 
 # display shape
 restore [locate_data_file occ/fuse.brep] f
index 963b79d..ede6aae 100644 (file)
@@ -32,12 +32,12 @@ set THE_LIGHTS {
   { -4 -1  0 MAGENTA }
   {  4 -1  0 MAGENTA3 }
 }
-vlight clear
+vlight -clear
 for { set aLightIter 1 } { $aLightIter <= 10 } { incr aLightIter } {
   set aLight [lindex $THE_LIGHTS [expr $aLightIter - 1]]
   set aColor [lindex $aLight 3]
   set aPos [list [lindex $aLight 0] [lindex $aLight 1] [lindex $aLight 2]]
-  vlight add positional pos {*}$aPos color $aColor headLight 0
+  vlight pntlight${aLightIter} -type POSITIONAL -pos {*}$aPos -color $aColor -headLight 0
   vpoint v${aLightIter} {*}$aPos
   vdrawtext t${aLightIter} "light${aLightIter} $aColor" -pos {*}$aPos -color $aColor
   vdump $::imagedir/${::casename}_${aLightIter}.png
index 80c9f9f..acaa01d 100644 (file)
@@ -11,7 +11,7 @@ vinit View1 -width 1024 -height 768
 vaxo
 vcaps -ffp 0
 vrenderparams -shadingModel phong
-vlight clear
+vlight -clear
 
 set THE_LIGHTS {
   { -1 -1 -1 RED1 }
index 54592c0..cec01f2 100644 (file)
@@ -17,7 +17,7 @@ vfit
 
 # define lights
 set THE_COLORS { RED1 YELLOW BLUE CYAN PURPLE WHITE HOTPINK GREEN MAGENTA MAGENTA3 }
-vlight clear
+vlight -clear
 set aNbColors 10
 set aLightIndex 0
 set aConstAtten 0.1
index 643082d..7d14d0d 100644 (file)
@@ -28,8 +28,8 @@ vfit
 # setup light
 vcaps -ffp 0
 vrenderparams -shadingModel phong
-vlight clear
-vlight add spotLight pos $anX 0 0.001 dir 0 0 -1 angle 60 constAtten 0.1 exponent 0.1 color RED1 headLight 0
+vlight -clear
+vlight spot -type SPOTLIGHT -pos $anX 0 0.001 -dir 0 0 -1 -spotAngle 60 -constAtten 0.1 -exponent 0.1 -color RED1 -headLight 0
 
 set aColor1 [vreadpixel 205 180 rgb name]
 set aColor2 [vreadpixel 205 220 rgb name]
index 41a021e..f8872bd 100644 (file)
@@ -13,8 +13,8 @@ box b 1 2 3
 vdisplay b
 vsetdispmode 1
 vtexture b 0
-vlight clear
-vlight add ambient color white
+vlight -clear
+vlight amblight -type AMBIENT -color WHITE
 vfit
 
 vtexture b -modulate off
index 85573c3..402eb5d 100644 (file)
@@ -14,10 +14,10 @@ vaspects b -material Brass
 vfit
 
 puts "=== Add light sources and display their presentations ==="
-vlight -add ambient -color WHITE -name AMBIENT -display
-vlight -add directional -dir 0 1 0 -name DIR -color GREEN -display
-vlight -add spotlight  -pos 50 25 25 -dir -1 0 0 -intensity 1000000000 -name SPOT -color RED -display
-vlight -add positional -pos 25 25 50 -intensity 10000000000 -range 20 -name POSITIONAL -color BLUE -display
+vlight AMBIENT    -type AMBIENT -color WHITE -display
+vlight DIR        -type DIRECTIONAL -dir 0 1 0 -color GREEN -display
+vlight SPOT       -type SPOTLIGHT  -pos 50 25 25 -dir -1 0 0 -intensity 1000000000 -color RED -display
+vlight POSITIONAL -type POSITIONAL -pos 25 25 50 -intensity 10000000000 -range 20 -color BLUE -display
 
 vdump $imagedir/${casename}_def.png
 
index 2b4361c..a15308b 100644 (file)
@@ -8,21 +8,21 @@ vinit View1
 vlight -clear
 vbackground -color GRAY
 vrenderparams -shadingModel PHONG
-vlight -add ambient -COLOR WHITE -intensity 0.1
+vlight amblight -type AMBIENT -color WHITE -intensity 0.1
 box b 10 10 10 30 30 30
 vdisplay b -dispMode 1
 vaspects b -material Brass
 vfit
 
 puts "=== Check headlight option with spotlight ==="
-vlight -add spotlight -dir 0 0 -1 -head 1 -intensity 1000000000 -color GREEN -display aSpotlight
+vlight aSpotlight -type SPOTLIGHT -dir 0 0 -1 -head 1 -intensity 1000000000 -color GREEN -display
 set aColor1 [vreadpixel 200 200 rgb name]
 if { "$aColor1" != "GREEN" } { puts "Error: expected color near the light is GREEN" }
 vdump $imagedir/${casename}_spot.png
 
 puts "=== Check headlight option with positional light ==="
-vlight -remove 1
-vlight -add positional -head 1 -color RED -display aPosLight
+vlight aSpotlight -remove
+vlight aPosLight -type POSITIONAL -head 1 -color RED -display
 set aColor2 [vreadpixel 200 200 rgb name]
 if { "$aColor2" != "RED" } { puts "Error: expected color near the light is RED" }
 vdump $imagedir/${casename}_pos.png
index eb93216..52cc026 100644 (file)
@@ -8,12 +8,12 @@ vinit View1
 vlight -clear
 vbackground -color GRAY
 vrenderparams -shadingModel PHONG
-vlight -add ambient -COLOR WHITE -intensity 0.1
+vlight amblight -type AMBIENT -color WHITE -intensity 0.1
 box b 0 0 0 30 30 30
 vdisplay b -dispMode 1
 vsetmaterial b Brass
 vfit
-vlight -add spotlight -pos 15 -10 15 -dir 0 1 0 -name aSpotLight -color RED -display
+vlight aSpotLight -type SPOTLIGHT -pos 15 -10 15 -dir 0 1 0 -color RED -display
 
 puts "=== Attach manipulator ==="
 vmanipulator m -attach aSpotLight -adjustPosition location