Salome HOME
untabify
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
index fdceadb4d2fdb2898b2be6de0e382ca027d34f1d..5833f54bfafe7780f9aa1266695f8546d84e85fe 100644 (file)
@@ -1,6 +1,6 @@
-//  GEOM GEOMGUI : GUI for Geometry component
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 //  This library is free software; you can redistribute it and/or
 //  License along with this library; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// GEOM GEOMGUI : GUI for Geometry component
+// File   : GEOM_Displayer.cxx
+// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
 //
-//
-//  File   : GEOM_Displayer.cxx
-//  Author : Vadim SANDLER
-//  Module : GEOM
-//  $Header$
-
 #include "GEOM_Displayer.h"
 
 #include "GeometryGUI.h"
 
-#include "GEOM_TypeFilter.h"
-#include "GEOM_EdgeFilter.h"
-#include "GEOM_FaceFilter.h"
-#include "GEOM_PreviewFilter.h"
-#include "GEOM_LogicalFilter.h"
-#include "GEOM_OCCFilter.h"
-
-#include "GEOM_Actor.h"
-#include "GEOM_AssemblyBuilder.h"
-#include "GEOM_AISShape.hxx"
-#include "GEOM_AISVector.hxx"
-#include "GEOM_AISTrihedron.hxx"
-#include "GEOM_VTKTrihedron.hxx"
+#include <GEOM_TypeFilter.h>
+#include <GEOM_EdgeFilter.h>
+#include <GEOM_FaceFilter.h>
+#include <GEOM_CompoundFilter.h>
+#include <GEOM_PreviewFilter.h>
+#include <GEOM_LogicalFilter.h>
+#include <GEOM_OCCFilter.h>
+
+#include <GEOM_Actor.h>
+#include <GEOM_AssemblyBuilder.h>
+#include <GEOM_AISShape.hxx>
+#include <GEOM_AISVector.hxx>
+#include <GEOM_AISTrihedron.hxx>
+#include <GEOM_VTKTrihedron.hxx>
 
 #include <SUIT_Desktop.h>
 #include <SUIT_ViewWindow.h>
 #include <SUIT_Session.h>
-#include <SUIT_Tools.h>
 #include <SUIT_ViewManager.h>
+#include <SUIT_ResourceMgr.h>
 
 #include <SalomeApp_Study.h>
 #include <SalomeApp_Application.h>
@@ -57,6 +55,8 @@
 #include <SalomeApp_Tools.h>
 
 #include <SALOME_ListIteratorOfListIO.hxx>
+#include <SALOME_ListIO.hxx>
+#include <SALOME_Prs.h>
 
 #include <SOCC_Prs.h>
 #include <SOCC_ViewModel.h>
 #include <SVTK_Prs.h>
 #include <SVTK_ViewModel.h>
 
-#include <SALOMEDSClient.hxx>
-#include <SALOMEDSClient_SObject.hxx>
-
 // OCCT Includes
 #include <AIS_Drawer.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_PointAspect.hxx>
-#include <Graphic3d_AspectMarker3d.hxx>
 #include <StdSelect_TypeOfEdge.hxx>
 #include <StdSelect_TypeOfFace.hxx>
 #include <TopoDS_Face.hxx>
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TopoDS_Iterator.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
 
 // VTK Includes
 #include <vtkActorCollection.h>
 #include <vtkProperty.h>
 
-// STL Includes
-#include <cstring>
-
 // CORBA Headers
 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
 
-#include "GEOMImpl_Types.hxx"
+#include <GEOMImpl_Types.hxx>
+#include <Graphic3d_HArray1OfBytes.hxx>
 
 using namespace std;
 
@@ -167,6 +162,30 @@ SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
   return aFilter;
 }
 
+//================================================================
+// Function : getComplexFilter
+// Purpose  : Get compound filter corresponding to the type of 
+//            object from GEOMImpl_Types.h
+//================================================================
+SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
+{
+  GEOM_CompoundFilter* aFilter;
+  
+  if(aSubShapes != NULL ) {
+    aFilter = new GEOM_CompoundFilter(getStudy());
+    QList<int> aTopAbsTypes;
+    QList<int>::const_iterator it;
+    for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
+      int topAbsMode = getTopAbsMode(*it);
+      if(topAbsMode != -1 )
+        aTopAbsTypes.append(topAbsMode);
+    }
+    aFilter->addSubTypes(aTopAbsTypes);
+  }
+  
+  return aFilter;
+}
+
 //================================================================
 // Function : getEntry
 // Purpose  :
@@ -239,13 +258,10 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
   myShadingColor = SalomeApp_Tools::color( col );
 
   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
-  myTypeOfMarker = (Aspect_TypeOfMarker)resMgr->integerValue("Geometry", "type_of_marker", Aspect_TOM_PLUS);
-  myScaleOfMarker = resMgr->doubleValue("Geometry", "marker_scale", 1.);
-  if(myScaleOfMarker < 1.0)
-    myScaleOfMarker = 1.0;
-  if(myScaleOfMarker > 7.)
-    myScaleOfMarker = 7.;
-
+  int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
+  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));
 
   myColor = -1;
   // This color is used for shape displaying. If it is equal -1 then
@@ -379,9 +395,10 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
   if ( app )
   {
     SUIT_Desktop* desk = app->desktop();
-    QPtrList<SUIT_ViewWindow> wnds = desk->windows();
+    QList<SUIT_ViewWindow*> wnds = desk->windows();
     SUIT_ViewWindow* wnd;
-    for ( wnd = wnds.first(); wnd; wnd = wnds.next() )
+    QListIterator<SUIT_ViewWindow*> it( wnds );
+    while ( it.hasNext() && (wnd = it.next()) )
     {
       SUIT_ViewManager* vman = wnd->getViewManager();
       if ( vman )
@@ -570,50 +587,54 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
           }
         }
        else
+       {
+         if ( myShape.ShapeType() == TopAbs_VERTEX )
          {
-           if ( myShape.ShapeType() == TopAbs_VERTEX )
-             {
-               col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
-               aColor = SalomeApp_Tools::color( col );
-
-               Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
-               anAspect->SetColor( aColor );
-                anAspect->SetScale( myScaleOfMarker );
-                anAspect->SetTypeOfMarker( myTypeOfMarker );
-                AISShape->Attributes()->SetPointAspect( anAspect );
-             }
-           else
-             {
-               // Set line aspect
-               col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
-               aColor = SalomeApp_Tools::color( col );
-
-               Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
-               anAspect->SetColor( aColor );
-               AISShape->Attributes()->SetLineAspect( anAspect );
-
-               // Set unfree boundaries aspect
-               anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
-               anAspect->SetColor( aColor );
-               AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
-
-               // Set free boundaries aspect
-               col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
-               aColor = SalomeApp_Tools::color( col );
-
-               anAspect = AISShape->Attributes()->FreeBoundaryAspect();
-               anAspect->SetColor( aColor );
-               AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
-
-               // Set wire aspect
-               col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
-               aColor = SalomeApp_Tools::color( col );
-
-               anAspect = AISShape->Attributes()->WireAspect();
-               anAspect->SetColor( aColor );
-               AISShape->Attributes()->SetWireAspect( anAspect );
-             }
+           col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
+           aColor = SalomeApp_Tools::color( col );
+           
+           Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
+           anAspect->SetColor( aColor );
+           anAspect->SetScale( myScaleOfMarker );
+           anAspect->SetTypeOfMarker( myTypeOfMarker );
+           AISShape->Attributes()->SetPointAspect( anAspect );
          }
+         else
+         {
+           // Set line aspect
+           col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) );
+           aColor = SalomeApp_Tools::color( col );
+           
+           Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
+           anAspect->SetColor( aColor );
+           AISShape->Attributes()->SetLineAspect( anAspect );
+           
+           // Set unfree boundaries aspect
+           anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
+           anAspect->SetColor( aColor );
+           AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
+           
+           // Set free boundaries aspect
+           col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
+           aColor = SalomeApp_Tools::color( col );
+           
+           anAspect = AISShape->Attributes()->FreeBoundaryAspect();
+           anAspect->SetColor( aColor );
+           AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
+           
+           // Set wire aspect
+           col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) );
+           aColor = SalomeApp_Tools::color( col );
+           
+           anAspect = AISShape->Attributes()->WireAspect();
+           anAspect->SetColor( aColor );
+           AISShape->Attributes()->SetWireAspect( anAspect );
+           
+           // bug [SALOME platform 0019868]
+           // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
+           AISShape->SetOwnDeviationAngle( 10*PI/180 );
+         }
+       }
 
         if ( HasWidth() )
           AISShape->SetWidth( GetWidth() );
@@ -635,7 +656,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
           AISShape->SetOwner( anObj );
         }
 
-       // Get color from GEOM_Object
+       // Get color and other properties from GEOM_Object
        SUIT_Session* session = SUIT_Session::session();
        SUIT_Application* app = session->activeApplication();
        if ( app )
@@ -658,7 +679,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
                  if ( !aGeomObject->_is_nil() )
                  {
                    SALOMEDS::Color aSColor = aGeomObject->GetColor();
-                   bool hasColor = aSColor.R > 0 || aSColor.G > 0 || aSColor.B > 0;
+                   bool hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
                    if( !hasColor && aGeomObject->GetType() == GEOM_GROUP ) // auto color for group
                    {
                      GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
@@ -666,7 +687,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
                      GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( aGeomObject );
                      if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() )
                      {
-                       QValueList<SALOMEDS::Color> aReservedColors;
+                       QList<SALOMEDS::Color> aReservedColors;
 
                        SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( app );
                        CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
@@ -701,6 +722,43 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
                      Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
                      AISShape->SetColor( aQuanColor );
                      AISShape->SetShadingColor( aQuanColor );
+                      if ( myShape.ShapeType() == TopAbs_VERTEX ) {
+                        Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
+                        anAspect->SetColor( aQuanColor );
+                        anAspect->SetScale( myScaleOfMarker );
+                        anAspect->SetTypeOfMarker( myTypeOfMarker );
+                        AISShape->Attributes()->SetPointAspect( anAspect );
+                      }
+                   }
+                   // ... marker type
+                   GEOM::marker_type aType = aGeomObject->GetMarkerType();
+                   GEOM::marker_size aSize = aGeomObject->GetMarkerSize();
+                   if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) {
+                     Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 );
+                     double aMSize = ((int)aSize+1)*0.5;
+                     Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
+                     anAspect->SetScale( aMSize );
+                     anAspect->SetTypeOfMarker( aMType );
+                     Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
+                     if ( hasColor )
+                       aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
+                     anAspect->SetColor( aQuanColor );
+                     AISShape->Attributes()->SetPointAspect( anAspect );
+                   }
+                   else if ( aType == GEOM::MT_USER ) {
+                     int aTextureId = aGeomObject->GetMarkerTexture();
+                     Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) );
+                     if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB );
+                     Standard_Integer aWidth, aHeight;
+                     Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( getStudy(), aTextureId, aWidth, aHeight );
+                     if ( !aTexture.IsNull() ) {
+                       static int TextureId = 0;
+                       Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aQuanColor,
+                                                                                        ++TextureId,
+                                                                                        aWidth, aHeight,
+                                                                                        aTexture );
+                       AISShape->Attributes()->SetPointAspect( aTextureAspect );
+                     }
                    }
                  }
                }
@@ -764,7 +822,7 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
 
   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
   {
-    myToActivate = false;
+    //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
     GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
 
     if ( HasColor() )
@@ -791,8 +849,7 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
   }
   else
   {
-    bool isVector = (myType == GEOM_VECTOR);
-    theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
+    theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, myType == GEOM_VECTOR );
   }
 
   theActors->InitTraversal();
@@ -929,7 +986,7 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
     if ( prs )
     {
       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
-      theIO->setEntry( entry.latin1() );
+      theIO->setEntry( entry.toLatin1().constData() );
       if ( !theIO.IsNull() )
       {
        // set interactive object
@@ -968,6 +1025,44 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
   return prs;
 }
 
+//=================================================================
+/*!
+ *  GEOM_Displayer::buildSubshapePresentation
+ *  Builds/finds object's presentation for the current viewer
+ *  Calls corresponding Update() method by means of double dispatch
+ *  For not published objects (for Mantis issue 0020435)
+ */
+//=================================================================
+SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
+                                                      const QString& entry,
+                                                      SALOME_View* theViewFrame)
+{
+  SALOME_Prs* prs = 0;
+  internalReset();
+
+  myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
+
+  if (myViewFrame)
+  {
+    prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
+    if (prs)
+    {
+      Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
+      theIO->setEntry(entry.toLatin1().constData());
+      if (!theIO.IsNull())
+      {
+       // set interactive object
+       setIO(theIO);
+        // finally set shape
+        setShape(aShape);
+        myType = GEOM_SUBSHAPE;
+      }
+      UpdatePrs(prs);  // Update presentation by using of the double dispatch
+    }
+  }
+  return prs;
+}
+
 //=================================================================
 /*!
  *  GEOM_Displayer::internalReset
@@ -1032,7 +1127,7 @@ void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
  */
 //=================================================================
 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
-                                     const bool update )
+                                     const bool update, const QList<int>* theSubShapes )
 {
   SUIT_Session* session = SUIT_Session::session();
   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
@@ -1076,16 +1171,26 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
   if ( theModes.Extent() == 1 )
     {
       int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
-      aFilter = getFilter( aMode );
+      
+      if ( aMode == GEOM_COMPOUNDFILTER )
+        aFilter = getComplexFilter( theSubShapes );
+      else    
+        aFilter = getFilter( aMode );
     }
   else if ( theModes.Extent() > 1 )
     {
       TColStd_MapOfInteger aTopAbsModes;
       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
-      QPtrList<SUIT_SelectionFilter> aListOfFilters;
+      QList<SUIT_SelectionFilter*> aListOfFilters;
       for ( ; anIter.More(); anIter.Next() )
        {
-         SUIT_SelectionFilter* aFilter = getFilter( anIter.Key() );
+          SUIT_SelectionFilter* aFilter;
+          int aMode = anIter.Key();
+          if ( aMode == GEOM_COMPOUNDFILTER )
+            aFilter = getComplexFilter( theSubShapes );
+          else    
+            aFilter = getFilter( aMode );
+
          if ( aFilter )
            aListOfFilters.append( aFilter );
        }
@@ -1300,7 +1405,7 @@ int GEOM_Displayer::UnsetDisplayMode()
   return aPrevMode;
 }
 
-SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
+SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
 {
   int aHue = -1;
   int aTolerance = 64;
@@ -1323,8 +1428,8 @@ SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QValueList<SALOMEDS::Color
 
     //cout << "Auto colors : ";
     bool ok = true;
-    QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
-    QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
+    QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
+    QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
     for( ; it != itEnd; ++it )
     {
       SALOMEDS::Color anAutoColor = *it;