]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMGUI/GEOM_Displayer.cxx
Salome HOME
CCAR: GEOM_Client modification to optimize the method find
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
index 83a3c083b07a22022c3161fa0cc9e0c859daec6a..eb0cf2658045d72f652a3c4509ab34d0dac3afc4 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  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
@@ -19,6 +19,7 @@
 //
 //  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)
@@ -80,6 +81,9 @@
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <Graphic3d_AspectMarker3d.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopTools_ListOfShape.hxx>
+#include <TopTools_ListIteratorOfListOfShape.hxx>
 
 // VTK Includes
 #include <vtkActorCollection.h>
@@ -91,7 +95,6 @@
 #include <GEOMImpl_Types.hxx>
 #include <Graphic3d_HArray1OfBytes.hxx>
 
-using namespace std;
 
 //================================================================
 // Function : getActiveStudy
@@ -126,6 +129,36 @@ static inline int getTopAbsMode( const int implType )
   }
 }
 
+static bool isCompoundOfVertices( const TopoDS_Shape& theShape )
+{
+  bool ret = false;
+  if ( !theShape.IsNull() ) {
+    int iType, nbTypes [TopAbs_SHAPE];
+    for (iType = 0; iType < TopAbs_SHAPE; ++iType)
+      nbTypes[iType] = 0;
+    nbTypes[theShape.ShapeType()]++;
+
+    TopTools_MapOfShape aMapOfShape;
+    aMapOfShape.Add(theShape);
+    TopTools_ListOfShape aListOfShape;
+    aListOfShape.Append(theShape);
+
+    TopTools_ListIteratorOfListOfShape itL (aListOfShape);
+    for (; itL.More(); itL.Next()) {
+      TopoDS_Iterator it (itL.Value());
+      for (; it.More(); it.Next()) {
+        TopoDS_Shape s = it.Value();
+        if (aMapOfShape.Add(s)) {
+          aListOfShape.Append(s);
+          nbTypes[s.ShapeType()]++;
+        }
+      }
+    }
+    ret = nbTypes[TopAbs_VERTEX] > 0 && nbTypes[TopAbs_COMPOUND] == 1;
+  }
+  return ret;
+}
+
 //================================================================
 // Function : getFilter
 // Purpose  : Get filter corresponding to the type of object
@@ -190,7 +223,7 @@ SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubSh
 // Function : getEntry
 // Purpose  :
 //================================================================
-static string getEntry( GEOM::GEOM_Object_ptr object )
+static std::string getEntry( GEOM::GEOM_Object_ptr object )
 {
   SUIT_Session* session = SUIT_Session::session();
   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
@@ -200,7 +233,7 @@ static string getEntry( GEOM::GEOM_Object_ptr object )
     if ( strcmp(IOR.in(), "") != 0 )
     {
       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
-      _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) );
+      _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
       if ( SO )
         return SO->GetID();
     }
@@ -212,7 +245,7 @@ static string getEntry( GEOM::GEOM_Object_ptr object )
 // Function : getName
 // Purpose  :
 //================================================================
-static string getName( GEOM::GEOM_Object_ptr object )
+static std::string getName( GEOM::GEOM_Object_ptr object )
 {
   SUIT_Session* session = SUIT_Session::session();
   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
@@ -222,7 +255,7 @@ static string getName( GEOM::GEOM_Object_ptr object )
     if ( strcmp(IOR.in(), "") != 0 )
     {
       SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
-      _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) );
+      _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
 
       _PTR(GenericAttribute) anAttr;
 
@@ -327,7 +360,7 @@ void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateVie
   if ( theObj->_is_nil() )
     return;
 
-  string entry = getEntry( theObj );
+  std::string entry = getEntry( theObj );
   if ( entry != "" ) {
     Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
             updateViewer);
@@ -371,7 +404,7 @@ void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj,
                             const bool forced,
                             const bool updateViewer )
 {
-  string entry = getEntry( theObj );
+  std::string entry = getEntry( theObj );
   if ( entry != "" )
   {
     Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
@@ -550,7 +583,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
           AISShape = new GEOM_AISShape (myShape, "");
         }
         // Temporary staff: vertex must be infinite for correct visualization
-        AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX );
+        AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
 
         // Setup shape properties here ..., e.g. display mode, color, transparency, etc
         AISShape->SetDisplayMode( myDisplayMode );
@@ -577,18 +610,18 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
         if ( HasColor() )
         {
           AISShape->SetColor( (Quantity_NameOfColor)GetColor() );
-          if ( myShape.ShapeType() == TopAbs_VERTEX )
+          Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
+          anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
+          if ( myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ) )
           {
-            Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
-            anAspect->SetColor( (Quantity_NameOfColor)GetColor() );
             anAspect->SetScale( myScaleOfMarker );
             anAspect->SetTypeOfMarker( myTypeOfMarker );
-            AISShape->Attributes()->SetPointAspect( anAspect );
           }
+          AISShape->Attributes()->SetPointAspect( anAspect );
         }
         else
         {
-          if ( myShape.ShapeType() == TopAbs_VERTEX )
+          if ( myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ) )
           {
             col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) );
             aColor = SalomeApp_Tools::color( col );
@@ -632,7 +665,12 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
             
             // bug [SALOME platform 0019868]
             // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
-            AISShape->SetOwnDeviationAngle( 10*PI/180 );
+            //AISShape->SetOwnDeviationAngle( 10*PI/180 );
+
+            // IMP 0020626
+            double aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
+            aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient
+            AISShape->SetOwnDeviationCoefficient(aDC);
           }
         }
 
@@ -694,7 +732,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
                         if ( strcmp(IOR.in(), "") != 0 )
                         {
                           _PTR(Study) aStudy = study->studyDS();
-                          _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( string(IOR) ) );
+                          _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( std::string(IOR) ) );
                           _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
                           for( ; it->More(); it->Next() )
                           {
@@ -722,7 +760,7 @@ 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 ) {
+                      if ( myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape ) ) {
                         Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
                         anAspect->SetColor( aQuanColor );
                         anAspect->SetScale( myScaleOfMarker );
@@ -930,7 +968,7 @@ SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
     return 0;
 
   internalReset();
-  setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
+  setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
   myType = theObj->GetType();
 
   // Update presentation
@@ -1011,7 +1049,7 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
                 if ( !GeomObject->_is_nil() )
                 {
                   // finally set shape
-                  setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
+                  setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
                   myType = GeomObject->GetType();
                 }
               }
@@ -1421,12 +1459,12 @@ SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& th
       if( aTolerance < 1 )
         break;
     }
-    //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
+    //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
 
     aHue = (int)( 360.0 * rand() / RAND_MAX );
-    //cout << "Hue = " << aHue << endl;
+    //std::cout << "Hue = " << aHue << std::endl;
 
-    //cout << "Auto colors : ";
+    //std::cout << "Auto colors : ";
     bool ok = true;
     QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
     QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
@@ -1437,21 +1475,21 @@ SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& th
 
       int h, s, v;
       aQColor.getHsv( &h, &s, &v );
-      //cout << h << " ";
+      //std::cout << h << " ";
       if( abs( h - aHue ) < aTolerance )
       {
         ok = false;
-        //cout << "break (diff = " << abs( h - aHue ) << ")";
+        //std::cout << "break (diff = " << abs( h - aHue ) << ")";
         break;
       }
     }
-    //cout << endl;
+    //std::cout << std::endl;
 
     if( ok )
       break;
   }
 
-  //cout << "Hue of the returned color = " << aHue << endl;
+  //std::cout << "Hue of the returned color = " << aHue << std::endl;
   QColor aColor;
   aColor.setHsv( aHue, 255, 255 );