Salome HOME
0022670: [CEA 1095] Deflection coefficient has no influence on a shape displayed...
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
index b8551a6910b7958369fed45ae17e26ccc605bb22..f9c14313c67474e0f07b1009da6a93b081752e6f 100644 (file)
@@ -65,7 +65,6 @@
 #include <SalomeApp_TypeFilter.h>
 #include <SalomeApp_Tools.h>
 
-#include <SALOME_ListIteratorOfListIO.hxx>
 #include <SALOME_ListIO.hxx>
 #include <SALOME_Prs.h>
 
 
 // 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
@@ -164,7 +166,7 @@ namespace
     if ( aPixmap.IsNull() ) {
       QPixmap px(":images/default_texture.png");
       if ( !px.isNull() )
-       aPixmap = imageToPixmap( px.toImage() );
+       aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
     }
     return aPixmap;
   }
@@ -198,7 +200,7 @@ namespace
     if ( anImage.isNull() )
       return NULL;
 
-    aPixmap = imageToPixmap( anImage );
+    aPixmap = OCCViewer_Utilities::imageToPixmap( anImage );
 
     aPixmapCacheMap.insert( thePath, aPixmap );
 
@@ -235,6 +237,7 @@ namespace
       if ( aAISShape.IsNull() )
         continue;
 
+#ifdef USE_TEXTURED_SHAPE
       const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
       if ( aPixmap.IsNull() )
         continue;
@@ -250,9 +253,23 @@ namespace
         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
@@ -459,25 +476,24 @@ 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);
   
-  myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
-  myHasTransparency = false;
-
   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
 
   // Activate parallel vizualisation only for testing purpose
   // and if the corresponding env variable is set to 1
@@ -524,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
     }
   }
@@ -580,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);
     }
   }
 }
@@ -693,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:
@@ -841,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 );
 
@@ -876,6 +923,7 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
     aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
   }
 
+#ifdef USE_TEXTURED_SHAPE
   Handle(Image_PixMap) aPixmap;
   if ( !aImagePath.isEmpty() )
     aPixmap = cacheTextureFor( aImagePath, AISShape );
@@ -891,6 +939,7 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   else {
     AISShape->SetTextureMapOff();
   }
+#endif
 
   // set line width
   AISShape->SetWidth( HasWidth() ?
@@ -949,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 ???
@@ -996,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;
@@ -1010,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
@@ -1103,7 +1165,7 @@ 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 );
   }
 }
 
@@ -1997,15 +2059,9 @@ void GEOM_Displayer::UnsetColor()
 //=================================================================
 double GEOM_Displayer::SetTransparency( const double transparency )
 {
-  double aPrevTransparency = myTransparency;
-  if ( transparency < 0 ) {
-    UnsetTransparency();
-  }
-  else {
-    myTransparency = transparency;
-    myHasTransparency = true;
-  }
-  return aPrevTransparency;
+  double prevTransparency = myTransparency;
+  myTransparency = transparency;
+  return prevTransparency;
 }
 
 //=================================================================
@@ -2027,7 +2083,7 @@ double GEOM_Displayer::GetTransparency() const
 //=================================================================
 bool GEOM_Displayer::HasTransparency() const
 {
-  return myHasTransparency;
+  return myTransparency >= 0;
 }
 
 //=================================================================
@@ -2038,27 +2094,17 @@ bool GEOM_Displayer::HasTransparency() const
 //=================================================================
 double GEOM_Displayer::UnsetTransparency()
 {
-  double aPrevTransparency = myTransparency;
-  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
-  myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.;
-  myHasTransparency = false;
-  return aPrevTransparency;
+  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
@@ -2097,7 +2143,6 @@ void GEOM_Displayer::UnsetWidth()
   myWidth = -1;
 }
 
-
 int GEOM_Displayer::GetIsosWidth() const
 {
   return myIsosWidth;
@@ -2113,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 );
+}
 
 //=================================================================
 /*!
@@ -2249,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;
@@ -2333,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 ) ) )
@@ -2943,7 +3031,7 @@ void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, cons
     {
       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() ) );