Salome HOME
0022670: [CEA 1095] Deflection coefficient has no influence on a shape displayed...
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
index f917a2f0ec46c46bacfaa408209499ca4494553d..f9c14313c67474e0f07b1009da6a93b081752e6f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -25,7 +25,7 @@
 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
 
 #include "GEOM_Displayer.h"
-
+#include "GEOMGUI_DimensionProperty.h"
 #include "GeometryGUI.h"
 
 #include <GEOM_Constants.h>
 
 #include <GEOM_Actor.h>
 #include <GEOM_AISShape.hxx>
+#include <GEOM_AISDimension.hxx>
 #include <GEOM_TopWireframeShape.hxx>
 #include <GEOM_AISVector.hxx>
 #include <GEOM_AISTrihedron.hxx>
 #include <GEOM_VTKTrihedron.hxx>
 #include <GEOM_VTKPropertyMaterial.hxx>
 
+#include <GEOMUtils.hxx>
+
 #include <Material_Model.h>
 
 #include <SUIT_Desktop.h>
@@ -62,7 +65,6 @@
 #include <SalomeApp_TypeFilter.h>
 #include <SalomeApp_Tools.h>
 
-#include <SALOME_ListIteratorOfListIO.hxx>
 #include <SALOME_ListIO.hxx>
 #include <SALOME_Prs.h>
 
 
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewPort3d.h>
+#include <OCCViewer_Utilities.h>
 
 // OCCT Includes
 #include <AIS_Drawer.hxx>
+#include <AIS_Dimension.hxx>
+#include <AIS_LengthDimension.hxx>
+#include <AIS_DiameterDimension.hxx>
+#include <AIS_AngleDimension.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <Aspect_PolygonOffsetMode.hxx>
 #include <Aspect_ColorScale.hxx>
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <TopTools_ListOfShape.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 #include <TopoDS.hxx>
+#include <NCollection_DataMap.hxx>
+#include <NCollection_Map.hxx>
 
 #include <Prs3d_ShadingAspect.hxx>
 
 
 #include <GEOMImpl_Types.hxx>
 
-#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
 #include <TColStd_HArray1OfByte.hxx>
-#else
-#include <Graphic3d_HArray1OfBytes.hxx>
-#endif
 
 // If the next macro is defined, autocolor feature works for all sub-shapes;
 // if it is undefined, autocolor feature works for groups only
 
 // Hard-coded value of shape deflection coefficient for VTK viewer
 const double VTK_MIN_DEFLECTION = 0.001;
+// If the next macro is defined, the deflection coefficient for VTK presentation
+// is limited by VTK_MIN_DEFLECTION
+//#define LIMIT_DEFLECTION_FOR_VTK
+
+// Pixmap caching support
+namespace
+{
+  typedef NCollection_Map<Handle(GEOM_AISShape)>                    SetOfAISShapes;
+  typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
+  typedef QMap<QString, Handle(Image_PixMap)>                       PixmapCacheMap;
+
+  static inline PixmapUsageMap& getPixmapUsageMap()
+  {
+    static PixmapUsageMap aMap;
+    return aMap;
+  }
+
+  static inline PixmapCacheMap& getPixmapCacheMap()
+  {
+    static PixmapCacheMap aMap;
+    return aMap;
+  }
+
+  //===========================================================================
+  // Function : getDefaultTexture
+  // Purpose  : Get default texture
+  //===========================================================================
+  static inline Handle(Image_PixMap) getDefaultTexture()
+  {
+    static Handle(Image_PixMap) aPixmap;
+    if ( aPixmap.IsNull() ) {
+      QPixmap px(":images/default_texture.png");
+      if ( !px.isNull() )
+       aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
+    }
+    return aPixmap;
+  }
+
+  //===========================================================================
+  // Function : cacheTextureFor
+  // Purpose  : Load and cache image for the specified presentation.
+  //===========================================================================
+  static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
+                                                      const Handle(GEOM_AISShape)& theShape )
+  {
+    if ( thePath.isEmpty() )
+      return NULL;
+
+    PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
+    PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
+
+    Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
+    if ( !aPixmap.IsNull() ) {
+      // point that the texture is used by the presentation
+      if ( !aPixmapUsersMap.IsBound( aPixmap ) )
+        aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
+
+      aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
+
+      return aPixmap;
+    }
+
+    // convert texture to compatible image format
+    QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
+    if ( anImage.isNull() )
+      return NULL;
+
+    aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
+
+    aPixmapCacheMap.insert( thePath, aPixmap );
+
+    if ( !aPixmapUsersMap.IsBound( aPixmap ) )
+      aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
+
+    aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
+
+    return aPixmap;
+  }
+
+  //===========================================================================
+  // Function : releaseTextures
+  // Purpose  : Releases cached textures found for the specified presentation.
+  //===========================================================================
+  static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
+  {
+    const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
+
+    AIS_ListOfInteractive aListOfIO;
+
+    anOccPrs->GetObjects( aListOfIO );
+
+    AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
+
+    PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
+    PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
+
+    for ( ; aIterateIO.More(); aIterateIO.Next() )
+    {
+      Handle(GEOM_AISShape) aAISShape =
+        Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
+
+      if ( aAISShape.IsNull() )
+        continue;
+
+#ifdef USE_TEXTURED_SHAPE
+      const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
+      if ( aPixmap.IsNull() )
+        continue;
+
+      if ( !aPixmapUsersMap.IsBound( aPixmap ) )
+        continue;
+
+      SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
+
+      aUsersShapes.Remove( aAISShape );
+
+      if ( aUsersShapes.IsEmpty() ) {
+        aPixmapUsersMap.UnBind( aPixmap );
+        aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
+      }
+#endif
+    }
+  }
+
+  uint randomize( uint size )
+  {
+    static bool initialized = false;
+    if ( !initialized ) {
+      qsrand( QDateTime::currentDateTime().toTime_t() );
+      initialized = true;
+    }
+    uint v = qrand();
+    v = uint( (double)( v ) / RAND_MAX * size );
+    v = qMax( uint(0), qMin ( v, size-1 ) );
+    return v;
+  }
+} // namespace
 
 //================================================================
 // Function : getActiveStudy
@@ -333,25 +476,25 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
   myHasDisplayMode = false;
 
   int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
-  myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
-  myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
-
+  
   myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
   myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
   myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
 
+  // Next properties provide a way to customize displaying of presentations;
+  // for instance, this is useful for preview
   myColor = -1;
-  // This color is used for shape displaying. If it is equal -1 then
-  // default color is used.
   myTexture = "";
-
+  myNbIsos = -1;
   myWidth = -1;
+  myTransparency = -1;
   myType = -1;
+  myIsosColor = -1;
+  myIsosWidth = -1;
 
+  // This parameter is used for activisation/deactivisation (selection) of objects to be displayed
   myToActivate = true;
-  // This parameter is used for activisation/deactivisation of objects to be displayed
 
-  #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
   // Activate parallel vizualisation only for testing purpose
   // and if the corresponding env variable is set to 1
   char* parallel_visu = getenv("PARALLEL_VISU");
@@ -360,7 +503,6 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
     MESSAGE("Parallel visualisation on");
     BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
   }
-  #endif
 
   myViewFrame = 0;
 
@@ -398,18 +540,12 @@ void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
     if ( prs )
     {
       vf->BeforeDisplay( this, prs );
-      vf->Display( prs );
+      vf->Display( this, prs );
       vf->AfterDisplay( this, prs );
 
       if ( updateViewer )
         vf->Repaint();
 
-      int aMgrId = getViewManagerId(vf);
-      SalomeApp_Study* aStudy = getStudy();
-      aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
-
-      setVisibilityState(theIO->getEntry(), Qtx::ShownState);
-
       delete prs;  // delete presentation because displayer is its owner
     }
   }
@@ -454,17 +590,11 @@ void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
     SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
     if ( prs ) {
       vf->BeforeErase( this, prs );
-      vf->Erase( prs, forced );
+      vf->Erase( this, prs, forced );
       vf->AfterErase( this, prs );
       if ( updateViewer )
         vf->Repaint();
       delete prs;  // delete presentation because displayer is its owner
-
-      int aMgrId = getViewManagerId(vf);
-      SalomeApp_Study* aStudy = getStudy();
-      aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
-
-      setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
     }
   }
 }
@@ -477,13 +607,14 @@ void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
 //=================================================================
 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
                             const bool forced,
-                            const bool updateViewer )
+                            const bool updateViewer,
+                            SALOME_View* theViewFrame)
 {
   std::string entry = getEntry( theObj );
   if ( entry != "" )
   {
     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
-          forced, updateViewer);
+          forced, updateViewer, theViewFrame);
   }
 }
 
@@ -520,8 +651,7 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
           {
             if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
             {
-              Erase( theIO, true, false, view );
-              Display( theIO, updateViewer, view );
+              Redisplay( theIO, updateViewer, view );
             }
           }
         }
@@ -530,6 +660,27 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
   }
 }
 
+//=================================================================
+/*!
+ *  GEOM_Displayer::Redisplay
+ *  Redisplay (erase and then display again) interactive object
+ *  in the specified view
+ */
+//=================================================================
+void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
+                                const bool theUpdateViewer,
+                                SALOME_View* theViewFrame )
+{
+  SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
+  if ( !vf )
+  {
+    return;
+  }
+
+  Erase( theIO, true, false, theViewFrame );
+  Display( theIO, theUpdateViewer, theViewFrame );
+}
+
 //=================================================================
 /*!
  *  GEOM_Displayer::Display
@@ -546,6 +697,27 @@ void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateV
     UpdateViewer();
 }
 
+void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on )
+{
+  SalomeApp_Study* aStudy = getStudy();
+  int vId = -1;
+  if ( v ) vId = getViewManagerId( v );
+
+  if ( p ) {
+    QString entry = p->GetEntry();
+    if ( !entry.isEmpty() ) {
+      if ( vId != -1 )
+       aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on );
+      setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState );
+    }
+  }
+  else {
+    if ( vId != -1 ) {
+      aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on );
+    }
+  }
+}
+
 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
 {
   // VSR: this method can be improved in future:
@@ -658,9 +830,6 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   
   // - color for edges in shading+edges mode
   AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
-  
-  // ???
-  AISShape->storeBoundaryColors();
 
   // set display mode
   AISShape->SetDisplayMode( HasDisplayMode() ? 
@@ -669,12 +838,26 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
                             // display mode from properties
                             propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
 
+  // - face boundaries color
+  if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges )
+    AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True );
+  anAspect = AISShape->Attributes()->FaceBoundaryAspect();
+  anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
+  AISShape->Attributes()->SetFaceBoundaryAspect( anAspect );
+
   // set display vectors flag
   AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
 
+  // set display vertices flag
+  bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool();
+  AISShape->SetDisplayVertices( isVerticesMode );
+
   // set transparency
-  // VSR: ??? next line is commented: transparency property is set in the AfterDisplay() function
-  //AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
+  if( HasTransparency() ) {
+    AISShape->SetTransparency( GetTransparency() );
+  } else {
+    AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
+  }
 
   // set iso properties
   int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
@@ -683,12 +866,34 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
   Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
   Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
-  uIsoAspect->SetColor( isosColor );
-  uIsoAspect->SetWidth( isosWidth );
-  uIsoAspect->SetNumber( uIsos );
-  vIsoAspect->SetColor( isosColor );
-  vIsoAspect->SetWidth( isosWidth );
-  vIsoAspect->SetNumber( vIsos );
+
+  if ( HasIsosColor() ) {
+    uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
+    vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() );
+  }
+  else {
+    uIsoAspect->SetColor( isosColor );
+    vIsoAspect->SetColor( isosColor );
+  }
+
+  if ( HasIsosWidth() ) {
+    uIsoAspect->SetWidth( GetIsosWidth() );
+    vIsoAspect->SetWidth( GetIsosWidth() );
+  }
+  else {
+    uIsoAspect->SetWidth( isosWidth );
+    vIsoAspect->SetWidth( isosWidth );
+  }
+  
+  if ( HasNbIsos() ) {
+    uIsoAspect->SetNumber( GetNbIsos() );
+    vIsoAspect->SetNumber( GetNbIsos() );
+  }
+  else {
+    uIsoAspect->SetNumber( uIsos );
+    vIsoAspect->SetNumber( vIsos );
+  }
+
   AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
   AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
 
@@ -697,13 +902,44 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
 
   // set texture
+  QString aImagePath;
   if ( HasTexture() ) {
     // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function 
-    AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) );
+    aImagePath = GetTexture().c_str();
+    if ( ! entry.isEmpty() ) {
+      // check that study is active
+      SalomeApp_Study* study = getActiveStudy();
+      if ( study ) {
+        // Store the texture in object properties for next displays
+        study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
+        study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
+        
+        // Update propeties map
+        propMap = getObjectProperties( study, entry, myViewFrame );
+      }
+    }
+  }
+  else {
+    aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
+  }
+
+#ifdef USE_TEXTURED_SHAPE
+  Handle(Image_PixMap) aPixmap;
+  if ( !aImagePath.isEmpty() )
+    aPixmap = cacheTextureFor( aImagePath, AISShape );
+  else
+    aPixmap = getDefaultTexture();
+
+  // apply image to shape
+  if ( !aPixmap.IsNull() ) {
+    AISShape->SetTexturePixMap( aPixmap );
     AISShape->SetTextureMapOn();
     AISShape->DisableTextureModulate();
-    AISShape->SetDisplayMode( 3 );
   }
+  else {
+    AISShape->SetTextureMapOff();
+  }
+#endif
 
   // set line width
   AISShape->SetWidth( HasWidth() ?
@@ -716,7 +952,7 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
 
   // set point marker (for vertex / compound of vertices only)
-  if ( onlyVertex ) {
+  if ( onlyVertex || isVerticesMode ) {
     QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
     if ( aList.size() == 2 ) {
       // standard marker string contains "TypeOfMarker:ScaleOfMarker"
@@ -736,14 +972,9 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
       // custom marker string contains "IdOfTexture"
       int textureId = aList[0].toInt();
       Standard_Integer aWidth, aHeight;
-#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
       Handle(TColStd_HArray1OfByte) aTexture =
-#else
-        Handle(Graphic3d_HArray1OfBytes) aTexture =
-#endif
         GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
       if ( !aTexture.IsNull() ) {
-#if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
         Handle(Prs3d_PointAspect) aTextureAspect =
           new Prs3d_PointAspect( HasColor() ? 
                                 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
@@ -752,18 +983,6 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
                                  SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
                                  aWidth, aHeight,
                                  aTexture );
-#else
-       int TextureId = 0;
-        Handle(Prs3d_PointAspect) aTextureAspect =
-          new Prs3d_PointAspect( HasColor() ? 
-                                // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
-                                (Quantity_NameOfColor)GetColor() : 
-                                // color from properties 
-                                 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ), 
-                                ++TextureId,
-                                 aWidth, aHeight,
-                                 aTexture );
-#endif
         AISShape->Attributes()->SetPointAspect( aTextureAspect );
       }
     }
@@ -779,7 +998,7 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
 
   if ( create && !isTemporary && aMgrId != -1 ) {
     // set properties to the study
-    study->setObjectPropMap( aMgrId, entry, propMap );
+    study->setObjectProperties( aMgrId, entry, propMap );
   }
 
   // AISShape->SetName(???); ??? necessary to set name ???
@@ -826,7 +1045,11 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
   // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
   /////////////////////////////////////////////////////////////////////////
   if ( !actor->getTopo().IsSame( myShape ) )
+#ifdef LIMIT_DEFLECTION_FOR_VTK
     actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
+#else
+    actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR );
+#endif
 
   // set material
   Material_Model material;
@@ -840,16 +1063,25 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
 
   // - set number of iso-lines
   int nbIsos[2]= { 1, 1 };
-  QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
-  nbIsos[0] = isos[0].toInt();
-  nbIsos[1] = isos[1].toInt();
+  if ( HasNbIsos() ) {
+    nbIsos[0] = GetNbIsos();
+    nbIsos[1] = GetNbIsos();
+  }
+  else {
+    QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
+    nbIsos[0] = isos[0].toInt();
+    nbIsos[1] = isos[1].toInt();
+  }
   actor->SetNbIsos( nbIsos );
 
   // - set iso-lines width
-  actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
+  actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
 
   // - set iso-lines color
-  c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
+  if ( HasIsosColor() )
+    c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) );
+  else
+    c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
   actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
 
   // set colors
@@ -868,7 +1100,7 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
     }
 
     // - standalone edge color
-    c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
+    c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
     actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
 
     c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
@@ -889,7 +1121,11 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
   actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
 
   // set opacity
-  actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
+  if( HasTransparency() ) {
+    actor->SetOpacity( 1.0 - GetTransparency() );
+  } else {
+    actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
+  }
 
   // set line width
   actor->SetWidth( HasWidth() ?
@@ -901,6 +1137,9 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
   // set display vectors flag
   actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
 
+  // set display vertices flag
+  actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() );
+
   // set display mode
   int displayMode = HasDisplayMode() ? 
     // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function 
@@ -926,7 +1165,174 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
 
   if ( create && !isTemporary && aMgrId != -1 ) {
     // set properties to the study
-    study->setObjectPropMap( aMgrId, entry, propMap );
+    study->setObjectProperties( aMgrId, entry, propMap );
+  }
+}
+
+//=================================================================
+/*!
+ *  GEOM_Displayer::updateDimensions
+ *  Creates or renews dimension presentation for the IO.
+ */
+//=================================================================
+void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
+                                       SALOME_OCCPrs* thePrs,
+                                       const gp_Ax3& theShapeLCS )
+{
+  SalomeApp_Study* aStudy = getStudy();
+  if ( !aStudy )
+  {
+    return;
+  }
+
+  if ( theIO.IsNull() )
+  {
+    return;
+  }
+
+  SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
+
+  AIS_ListOfInteractive aListOfIO;
+
+  anOccPrs->GetObjects( aListOfIO );
+
+  AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
+
+  // remove outdated presentations of dimensions
+  for ( ; aIterateIO.More(); aIterateIO.Next() )
+  {
+    const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
+    if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
+    {
+      continue;
+    }
+
+    aListOfIO.Remove( aIterateIO );
+
+    if ( !aIterateIO.More() )
+    {
+      break;
+    }
+  }
+
+  // prepare dimension styling
+  SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+
+  QColor  aQColor       = aResMgr->colorValue  ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
+  int     aLineWidth    = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
+  double  aFontHeight   = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
+  double  anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
+  bool    isUnitsShown  = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
+  QString aUnitsLength  = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
+  QString aUnitsAngle   = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
+
+  // restore dimension presentation from saved attribute or property data
+  AIS_ListOfInteractive aRestoredDimensions;
+
+  QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
+                                                  theIO->getEntry(),
+                                                  GEOM::propertyName( GEOM::Dimensions ),
+                                                  QVariant() );
+
+  GEOMGUI_DimensionProperty aRecords;
+
+  if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
+  {
+    aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
+  }
+  else
+  {
+    aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
+  }
+  
+  // create up-to-date dimension presentations
+  for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
+  {
+    if ( !aRecords.IsVisible( aPrsIt ) )
+    {
+      continue;
+    }
+
+    // init dimension by type
+    Handle(AIS_Dimension) aPrs;
+    switch( aRecords.GetType( aPrsIt ) )
+    {
+      case GEOMGUI_DimensionProperty::DimensionType_Length :
+      {
+        Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
+        aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
+        aPrs = aLength;
+        break;
+      }
+
+      case GEOMGUI_DimensionProperty::DimensionType_Diameter :
+      {
+        Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
+        aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
+        aPrs = aDiam;
+        break;
+      }
+
+      case GEOMGUI_DimensionProperty::DimensionType_Angle :
+      {
+        Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
+        aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
+        aPrs = anAng;
+        break;
+      }
+    }
+
+    aPrs->SetOwner( theIO );
+
+    Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
+
+    Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
+
+    aStyle->SetCommonColor( aColor );
+    aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
+    aStyle->MakeText3d( Standard_True );
+    aStyle->MakeTextShaded( Standard_True );
+    aStyle->SetExtensionSize( aFontHeight * 0.5 );
+    aStyle->TextAspect()->SetHeight( aFontHeight );
+    aStyle->ArrowAspect()->SetLength( anArrowLength );
+    aStyle->LineAspect()->SetWidth( aLineWidth );
+    aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
+    aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
+    aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
+    aPrs->SetDimensionAspect( aStyle );
+    aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
+    aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
+    aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
+
+    if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
+    {
+      // show degree symbol for dimension instead of label "deg"
+      if ( aUnitsAngle == "deg" )
+      {
+        aPrs->SetSpecialSymbol(0xB0);
+        aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
+        aStyle->MakeUnitsDisplayed(Standard_False);
+      }
+      else
+      {
+        aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
+        aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
+      }
+    }
+    else
+    {
+      aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
+    }
+
+    aListOfIO.Append( aPrs );
+  }
+
+  // update presentation
+  anOccPrs->Clear();
+
+  for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
+  {
+    anOccPrs->AddObject( aIterateIO.Value() );
   }
 }
 
@@ -966,6 +1372,28 @@ void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
     UpdateViewer();
 }
 
+//=================================================================
+/*!
+ *  GEOM_Displayer::Redisplay
+ *  Calls Redisplay() method for each object in the given list
+ */
+//=================================================================
+void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
+                                const bool theUpdateViewer,
+                                SALOME_View* theViewFrame )
+{
+  SALOME_ListIteratorOfListIO anIter( theIOList );
+  for ( ; anIter.More(); anIter.Next() )
+  {
+    Redisplay( anIter.Value(), false, theViewFrame );
+  }
+
+  if ( theUpdateViewer )
+  {
+    UpdateViewer();
+  }
+}
+
 //=================================================================
 /*!
  *  GEOM_Displayer::Update
@@ -1044,6 +1472,9 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
       // create presentation (specific for vectors)
       Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
                                                                  : new GEOM_AISShape ( myShape, "" );
+
+      if( myType == GEOM_FIELD_STEP )
+        AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
       // update shape properties
       updateShapeProperties( AISShape, true );
 
@@ -1093,6 +1524,8 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
         AISShape->SetToUpdate();
       }
     }
+
+    updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
   }
 }
 
@@ -1566,37 +1999,19 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
 
 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
 {
-  SalomeApp_Study* aStudy = getStudy();
-  if (!aStudy) return;
-  SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
-  if ( vf && !p->IsNull() ) {
-    int aMgrId = getViewManagerId( vf );
-    Handle(AIS_InteractiveContext) ic = vf->getAISContext();
-    const SOCC_Prs* prs = dynamic_cast<const SOCC_Prs*>( p );
-    if ( !ic.IsNull() && prs ) {
-      AIS_ListOfInteractive objects;
-      prs->GetObjects( objects );
-      AIS_ListIteratorOfListOfInteractive it( objects );
-      for ( ; it.More(); it.Next() ) {
-        Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() );
-        if ( sh.IsNull() ) continue;
-        Handle(SALOME_InteractiveObject) IO = sh->getIO();
-        if ( IO.IsNull() ) continue;
-        PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() );
-        if ( aPropMap.contains( GEOM::propertyName( GEOM::Transparency ) ) ) {
-          double transparency = aPropMap.value(GEOM::propertyName( GEOM::Transparency )).toDouble();
-          ic->SetTransparency( sh, transparency, true );
-        }
-      }
-    }
-  }
-  UpdateColorScale();
+  UpdateColorScale(false,false);
+}
+
+void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
+{
+  LightApp_Displayer::BeforeErase( v, p );
+  releaseTextures( p );
 }
 
 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
 {
   LightApp_Displayer::AfterErase( v, p );
-  UpdateColorScale();
+  UpdateColorScale(false,false);
 }
 
 //=================================================================
@@ -1636,19 +2051,60 @@ void GEOM_Displayer::UnsetColor()
   myShadingColor = SalomeApp_Tools::color( col );
 }
 
+//=================================================================
+/*!
+ *  GEOM_Displayer::SetTransparency
+ *  Set transparency for shape displaying.
+ */
+//=================================================================
+double GEOM_Displayer::SetTransparency( const double transparency )
+{
+  double prevTransparency = myTransparency;
+  myTransparency = transparency;
+  return prevTransparency;
+}
+
+//=================================================================
+/*!
+ *  GEOM_Displayer::GetTransparency
+ *  Get transparency for shape displaying.
+ */
+//=================================================================
+double GEOM_Displayer::GetTransparency() const
+{
+  return myTransparency;
+}
+
+//=================================================================
+/*!
+ *  GEOM_Displayer::HasTransparency
+ *  Check if transparency for shape displaying is set.
+ */
+//=================================================================
+bool GEOM_Displayer::HasTransparency() const
+{
+  return myTransparency >= 0;
+}
+
+//=================================================================
+/*!
+ *  GEOM_Displayer::UnsetTransparency
+ *  Unset transparency for shape displaying.
+ */
+//=================================================================
+double GEOM_Displayer::UnsetTransparency()
+{
+  return SetTransparency( -1 );
+}
+
 //=================================================================
 /*!
  *  GEOM_Displayer::SetTexture
- *  Set color for shape displaying. If it is equal -1 then default color is used.
- *  Available values are from Quantity_NameOfColor enumeration
  */
 //=================================================================
 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
 {
-  if(texureFileName!="")
-  {
-    myTexture = texureFileName;
-  }
+  myTexture = texureFileName;
 }
 
 bool GEOM_Displayer::HasTexture() const
@@ -1687,7 +2143,6 @@ void GEOM_Displayer::UnsetWidth()
   myWidth = -1;
 }
 
-
 int GEOM_Displayer::GetIsosWidth() const
 {
   return myIsosWidth;
@@ -1703,6 +2158,49 @@ bool GEOM_Displayer::HasIsosWidth() const
   return myIsosWidth != -1;
 }
 
+int GEOM_Displayer::SetNbIsos( const int nbIsos )
+{
+  int prevNbIsos = myNbIsos;
+  myNbIsos = nbIsos;
+  return prevNbIsos;
+}
+
+int GEOM_Displayer::UnsetNbIsos()
+{
+  return SetNbIsos( -1 );
+}
+
+int GEOM_Displayer::GetNbIsos() const
+{
+  return myNbIsos;
+}
+
+bool GEOM_Displayer::HasNbIsos() const
+{
+  return myNbIsos >= 0;
+}
+
+int GEOM_Displayer::SetIsosColor( const int color )
+{
+  int prevColor = myIsosColor;
+  myIsosColor = color;
+  return prevColor;
+}
+
+int GEOM_Displayer::GetIsosColor() const
+{
+  return myIsosColor;
+}
+
+bool GEOM_Displayer::HasIsosColor() const
+{
+  return myIsosColor != -1;
+}
+
+int GEOM_Displayer::UnsetIsosColor()
+{
+  return SetIsosColor( -1 );
+}
 
 //=================================================================
 /*!
@@ -1839,7 +2337,7 @@ SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
     }
   }
 
-  static int currentColor = 0;
+  static int currentColor = randomize( colors.size() );
 
   SALOMEDS::Color color;
   color.R = (double)colors[currentColor].red()   / 255.0;
@@ -1923,7 +2421,7 @@ PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
   
     if ( viewModel && viewId != -1 ) {
       // get properties from the study
-      PropMap storedMap = study->getObjectPropMap( viewId, entry );
+      PropMap storedMap = study->getObjectProperties( viewId, entry );
       // overwrite default properties from stored ones (that are specified)
       for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
         if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
@@ -2010,7 +2508,8 @@ PropMap GEOM_Displayer::getDefaultPropertyMap()
                   arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
 
   // - transparency (opacity = 1-transparency)
-  propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
+  propMap.insert( GEOM::propertyName( GEOM::Transparency ),
+                 resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. );
 
   // - display mode (take default value from preferences)
   propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
@@ -2019,6 +2518,9 @@ PropMap GEOM_Displayer::getDefaultPropertyMap()
   // - show edges direction flag (false by default)
   propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
 
+  // - show vertices flag (false by default)
+  propMap.insert( GEOM::propertyName( GEOM::Vertices ), false );
+
   // - shading color (take default value from preferences)
   propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
                   colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
@@ -2229,7 +2731,7 @@ void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldSte
     {
       GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
       for( size_t i = 0, n = aValues->length(); i < n; i++ )
-        aFieldStepData << (long)aValues[i];
+        aFieldStepData << (qlonglong)aValues[i];
     }
   }
   else if( aFieldDataType == GEOM::FDT_Double )
@@ -2313,8 +2815,8 @@ QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldS
         }
         else
         {
-          if( aVariant.type() == QVariant::Int )
-            aValue = double( aVariant.toInt() );
+          if( aVariant.type() == QVariant::LongLong )
+            aValue = double( aVariant.toLongLong() );
           else if( aVariant.type() == QVariant::Double )
             aValue = aVariant.toDouble();
           aNorm += aValue * aValue;
@@ -2415,7 +2917,7 @@ Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
   } 
 }
 
-void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps )
+void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) 
 {
   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
   if( !aStudy )
@@ -2529,7 +3031,7 @@ void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps )
     {
       if( SUIT_ViewManager* aViewManager = *vmIt )
       {
-        const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
+        const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() );
         for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
         {
           _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
@@ -2552,6 +3054,6 @@ void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps )
       }
     }
   }
-
-  UpdateViewer();
+  if(updateViewer)
+    UpdateViewer();
 }