Salome HOME
updated copyright message
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 56e82b8..0896c4e
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -44,6 +44,7 @@
 #include <GEOM_AISTrihedron.hxx>
 #include <GEOM_VTKTrihedron.hxx>
 #include <GEOM_VTKPropertyMaterial.hxx>
+#include <GEOM_PainterPolyDataMapper.h>
 
 #include <GEOMGUI_DimensionProperty.h>
 #include <GEOMGUI_AnnotationAttrs.h>
 #include <SVTK_Prs.h>
 #include <SVTK_ViewModel.h>
 
+#include <SPV3D_Prs.h>
+#include <SPV3D_ViewModel.h>
+
 #include <OCCViewer_ViewWindow.h>
 #include <OCCViewer_ViewPort3d.h>
 #include <OCCViewer_Utilities.h>
 
+#include <BRepBndLib.hxx>
+#include <pqActiveObjects.h>
+#include <pqApplicationCore.h>
+#include <pqObjectBuilder.h>
+#include <vtkSMPropertyHelper.h>
+#include <vtkSMProxy.h>
+#include <vtkSMParaViewPipelineControllerWithRendering.h>
+#include <vtkNamedColors.h>
+#include <vtkPoints.h>
+#include <vtkCamera.h>
+#include <vtkCellArray.h>
+#include <vtkFloatArray.h>
+#include <vtkPointData.h>
+#include <vtkPolyData.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+
 // OCCT Includes
 #include <AIS_Dimension.hxx>
 #include <AIS_LengthDimension.hxx>
 #include <Prs3d_PointAspect.hxx>
 #include <StdSelect_TypeOfEdge.hxx>
 #include <StdSelect_TypeOfFace.hxx>
-#include <StdSelect_DisplayMode.hxx>
+//#include <StdSelect_DisplayMode.hxx>
 #include <TopoDS_Face.hxx>
 #include <BRep_Tool.hxx>
 #include <Geom_Plane.hxx>
 #include <vtkActorCollection.h>
 #include <vtkProperty.h>
 
+#include <Basics_OCCTVersion.hxx>
 // CORBA Headers
 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
 
 
 #include <TColStd_HArray1OfByte.hxx>
 
+#include "vtkSMSourceProxy.h"
+#include "pqServerManagerModel.h"
+#include "vtkPVTrivialProducer.h"
+#include "vtkSMViewProxy.h"
+
+#if OCC_VERSION_LARGE >= 0x070400ff
+#include <Image_SupportedFormats.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
 #define GENERAL_AUTOCOLOR
@@ -241,8 +273,12 @@ namespace
       const Handle(Graphic3d_TextureMap)& aTexture = aAISShape->Attributes()->ShadingAspect()->Aspect()->TextureMap();
       if ( aTexture.IsNull() )
         continue;
-
+#if OCC_VERSION_LARGE >= 0x070400ff
+      Handle(Image_SupportedFormats) aFormats = new Image_SupportedFormats();
+      const Handle(Image_PixMap)& aPixmap = aTexture->GetImage(aFormats);
+#else
       const Handle(Image_PixMap)& aPixmap = aTexture->GetImage();
+#endif
       if ( aPixmap.IsNull() )
         continue;
 
@@ -387,7 +423,7 @@ SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
 //================================================================
 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
 {
-  GEOM_CompoundFilter* aFilter;
+  GEOM_CompoundFilter* aFilter = 0;
 
   if(aSubShapes != NULL ) {
     aFilter = new GEOM_CompoundFilter(getStudy());
@@ -776,7 +812,7 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   else if ( !myName.empty() ) {
     // workaround to allow selection of temporary objects
     static int tempId = 0;
-    anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
+    anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toUtf8().data(), "GEOM", myName.c_str() );
     AISShape->setIO( anIO );
     AISShape->SetOwner( anIO );
   }
@@ -830,16 +866,20 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap
   AISShape->Attributes()->SetLineAspect( anAspect );
   
   // - unfree boundaries color
-  anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
-  anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
+  Handle(Prs3d_LineAspect) aUnFreeBoundaryAspect =
+    new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
+  *aUnFreeBoundaryAspect->Aspect() = *AISShape->Attributes()->UnFreeBoundaryAspect()->Aspect();
+  aUnFreeBoundaryAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
-  AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
+  AISShape->Attributes()->SetUnFreeBoundaryAspect( aUnFreeBoundaryAspect );
   
   // - free boundaries color
-  anAspect = AISShape->Attributes()->FreeBoundaryAspect();
-  anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
+  Handle(Prs3d_LineAspect) aFreeBoundaryAspect =
+    new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0);
+  *aFreeBoundaryAspect->Aspect() = *AISShape->Attributes()->FreeBoundaryAspect()->Aspect();
+  aFreeBoundaryAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() : 
                       SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
-  AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
+  AISShape->Attributes()->SetFreeBoundaryAspect( aFreeBoundaryAspect );
   
   // - standalone edges color
   anAspect = AISShape->Attributes()->WireAspect();
@@ -1047,7 +1087,7 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
   else if ( !myName.empty() ) {
     // workaround to allow selection of temporary objects
     static int tempId = 0;
-    anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
+    anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toUtf8().data(), "GEOM", myName.c_str() );
     actor->setIO( anIO );
   }
 
@@ -1343,12 +1383,21 @@ void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& t
       if ( aUnitsAngle == "deg" )
       {
         aPrs->SetSpecialSymbol(0xB0);
+#if OCC_VERSION_LARGE >= 0x070400ff
+        aPrs->SetDisplaySpecialSymbol( isUnitsShown ? PrsDim_DisplaySpecialSymbol_After :
+                                                      PrsDim_DisplaySpecialSymbol_No );
+#else
         aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
+#endif
         aStyle->MakeUnitsDisplayed(Standard_False);
       }
       else
       {
+#if OCC_VERSION_LARGE >= 0x070400ff
+        aPrs->SetDisplaySpecialSymbol(PrsDim_DisplaySpecialSymbol_No);
+#else
         aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
+#endif
         aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
       }
     }
@@ -1430,7 +1479,7 @@ void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
 //=================================================================
 /*!
  *  GEOM_Displayer::Update
- *  Update OCC presentaion
+ *  Update OCC presentation
  *  [ Reimplemented from SALOME_Displayer ]
  */
 //=================================================================
@@ -1565,7 +1614,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
 //=================================================================
 /*!
  *  GEOM_Displayer::Update
- *  Update VTK presentaion
+ *  Update VTK presentation
  *  [ Reimplemented from SALOME_Displayer ]
  */
 //=================================================================
@@ -1666,6 +1715,44 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
   }
 }
 
+//=================================================================
+/*!
+ *  GEOM_Displayer::Update
+ *  Update PV3D presentation
+ *  [ Reimplemented from SALOME_Displayer ]
+ */
+//=================================================================
+void GEOM_Displayer::Update( SALOME_PV3DPrs* prs )
+{
+  SPV3D_Prs* pv3dPrs = dynamic_cast<SPV3D_Prs*>( prs );
+
+  SalomeApp_Study* study = getStudy();
+
+  if ( !pv3dPrs || myShape.IsNull() || !study )
+    return;
+
+  if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
+  {
+    // 
+    // specific processing for local coordinate system presentation
+    // 
+    // NYI - Update(PV3DPrs) for the local coordinate system
+  }
+  else
+  {
+    // 
+    // processing for usual geometry presentation
+    // 
+    {
+      pv3dPrs->SetName( myNameInObjBrowser );
+      GEOM_Actor *actor = GEOM_Actor::New();
+      updateActorProperties( actor, true );
+      pv3dPrs->FillUsingActor( actor );
+    }
+  }
+}
+
+
 //=================================================================
 /*!
  *  GEOM_Displayer::BuildPrs
@@ -1742,7 +1829,7 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
     if ( prs )
     {
       Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
-      theIO->setEntry( entry.toLatin1().constData() );
+      theIO->setEntry( entry.toUtf8().constData() );
       if ( !theIO.IsNull() )
       {
         // set interactive object
@@ -1751,7 +1838,7 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
         if ( getStudy() )
         {
           _PTR(SObject) SO ( getStudy()->studyDS()->FindObjectID( theIO->getEntry() ) );
-          if ( SO )
+          if ( SO ) //GeometryGUI::IsInGeomComponent( SO ))
           {
             // get CORBA reference to data object
             CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
@@ -1761,6 +1848,7 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
               GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
               if ( !GeomBaseObject->_is_nil() )
               {
+                myNameInObjBrowser = getName( GeomBaseObject );
                 myType = GeomBaseObject->GetType();
 
                 // downcast to GEOM object
@@ -1821,7 +1909,7 @@ SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape
     if (prs)
     {
       Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
-      theIO->setEntry(entry.toLatin1().constData());
+      theIO->setEntry(entry.toUtf8().constData());
       if (!theIO.IsNull())
       {
         // set interactive object
@@ -1961,27 +2049,26 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
   if ( theModes.Contains( GEOM_ALLOBJECTS ) )
     return;
 
-  SUIT_SelectionFilter* aFilter;
-  if ( theModes.Extent() == 1 )
-    {
-      int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
-
-      if ( aMode == GEOM_COMPOUNDFILTER )
-        aFilter = getComplexFilter( theSubShapes );
-      else
-        aFilter = getFilter( aMode );
-    }
-  else if ( theModes.Extent() > 1 )
+  SUIT_SelectionFilter* aFilter = NULL;
+  if ( theModes.Extent() > 0 )
     {
       TColStd_MapOfInteger aTopAbsModes;
       TColStd_MapIteratorOfMapOfInteger anIter( theModes );
       QList<SUIT_SelectionFilter*> aListOfFilters;
       for ( ; anIter.More(); anIter.Next() )
         {
-          SUIT_SelectionFilter* aFilter;
+          SUIT_SelectionFilter* aFilter = 0;
           int aMode = anIter.Key();
           if ( aMode == GEOM_COMPOUNDFILTER )
             aFilter = getComplexFilter( theSubShapes );
+          if ( aMode == GEOM_COMPOUND ) {
+            // always add COMPSOLID filter together with COMPOUND filter
+            aFilter = new GEOM_TypeFilter( getStudy(), TopAbs_COMPSOLID, true );
+            aListOfFilters.append( aFilter );
+
+            // add the COMPOUND filter itself
+            aFilter = getFilter( aMode );
+          }
           else
             aFilter = getFilter( aMode );
 
@@ -1989,7 +2076,8 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
             aListOfFilters.append( aFilter );
         }
 
-      aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
+      if (aListOfFilters.size() > 1)
+        aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
     }
   else
     return;
@@ -2048,8 +2136,8 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
     Handle(AIS_InteractiveContext) ic = vf->getAISContext();
     if ( !ic.IsNull() )
     {
-      if ( ic->HasOpenedContext() )
-      ic->CloseAllContexts(Standard_True);
+      ic->Deactivate();
+      ic->Activate( 0 );
     }
   }
 }
@@ -2357,12 +2445,17 @@ void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataT
 
 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
 {
-  _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
-  GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
-  GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
-  GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
-  return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
-         (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
+  _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toUtf8() );
+  //if ( ! GeometryGUI::IsInGeomComponent( anObj )) return false;
+  CORBA::Object_var anOrbObj = GeometryGUI::ClientSObjectToObject(anObj);
+  bool isCorbaObj = (!CORBA::is_nil(anOrbObj));
+  GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anOrbObj); // enable displaying of GEOM objects
+  GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(anOrbObj); // enable displaying of GEOM field steps
+  GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(anOrbObj); // enable displaying of whole GEOM component
+  bool isGeomObj = (!CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ));
+  bool ret = ( isGeomObj ) &&
+         (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type() || viewer_type == SPV3D_ViewModel::Type());
+  return ret;
 }
 
 int GEOM_Displayer::SetDisplayMode( const int theMode )
@@ -2519,7 +2612,7 @@ PropMap GEOM_Displayer::getObjectProperties( const QString& entry,
       if ( !entry.isEmpty() ) {
         // get CORBA reference to geom object
         _PTR(SObject) SO( getStudy()->studyDS()->FindObjectID( entry.toStdString() ) );
-        if ( SO ) {
+        if ( SO ) { //GeometryGUI::IsInGeomComponent( SO )) {
           CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
           if ( !CORBA::is_nil( object ) ) {
             GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
@@ -2674,38 +2767,40 @@ SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bo
       aSColor = theGeomObject->GetColor();
       hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
       if ( !hasColor ) {
+        if (!theGeomObject->IsMainShape()) {
 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
-        bool general_autocolor = true;
+          bool general_autocolor = true;
 #else                    // auto-color for groups only
-        bool general_autocolor = false;
+          bool general_autocolor = false;
 #endif                   // GENERAL_AUTOCOLOR
-        if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
-          GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
-          if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
+          if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
+            GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
+            if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
 #ifdef SIMPLE_AUTOCOLOR  // simplified algorithm for auto-colors
-            aSColor = getPredefinedUniqueColor();
-            hasColor = true;
+              aSColor = getPredefinedUniqueColor();
+              hasColor = true;
 #else                    // old algorithm  for auto-colors
-            QList<SALOMEDS::Color> aReservedColors;
-            CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
-            _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
-            if ( aMainSObject ) {
-              _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
-              for ( ; it->More(); it->Next() ) {
-                _PTR(SObject) aChildSObject( it->Value() );
-                GEOM::GEOM_Object_var aChildObject =
-                  GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
-                if ( CORBA::is_nil( aChildObject ) )
-                  continue;
-
-                SALOMEDS::Color aReservedColor = aChildObject->GetColor();
-                if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
-                  aReservedColors.append( aReservedColor );
+              QList<SALOMEDS::Color> aReservedColors;
+              CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
+              _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
+              if ( aMainSObject ) {
+                _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
+                for ( ; it->More(); it->Next() ) {
+                  _PTR(SObject) aChildSObject( it->Value() );
+                  GEOM::GEOM_Object_var aChildObject =
+                    GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
+                  if ( CORBA::is_nil( aChildObject ) )
+                    continue;
+
+                  SALOMEDS::Color aReservedColor = aChildObject->GetColor();
+                  if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
+                    aReservedColors.append( aReservedColor );
+                }
               }
-            }
-            aSColor = getUniqueColor( aReservedColors );
-            hasColor = true;
+              aSColor = getUniqueColor( aReservedColors );
+              hasColor = true;
 #endif                   // SIMPLE_AUTOCOLOR
+            }
           }
         }
       }
@@ -2746,7 +2841,7 @@ void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& t
     if(l_obj)
       foreach ( view, views ) {
       Handle(SALOME_InteractiveObject) anIO =
-        new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
+        new SALOME_InteractiveObject(qUtf8Printable(l_obj->entry()), "GEOM", "");
       Erase(anIO, false, false, view);
     }
   }
@@ -2892,7 +2987,10 @@ QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldS
             aValue = double( aVariant.toLongLong() );
           else if( aVariant.type() == QVariant::Double )
             aValue = aVariant.toDouble();
-          aNorm += aValue * aValue;
+          if ( theFieldNbComponents > 1 )
+            aNorm += aValue * aValue;
+          else
+            aNorm += aValue;
         }
       }
     }
@@ -2903,7 +3001,7 @@ QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldS
     {
       if( anIsBoolean )
         aNorm /= theFieldNbComponents;
-      else
+      else if ( theFieldNbComponents > 1 )
         aNorm = pow( aNorm, 0.5 );
 
       if( aGroupedList.isEmpty() )