Salome HOME
untabify
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
index f8aaa621b82a81d5ae10cc3cb3e84145ff562a34..5833f54bfafe7780f9aa1266695f8546d84e85fe 100644 (file)
@@ -79,6 +79,7 @@
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TopoDS_Iterator.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
 
 // VTK Includes
 #include <vtkActorCollection.h>
@@ -88,6 +89,7 @@
 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
 
 #include <GEOMImpl_Types.hxx>
+#include <Graphic3d_HArray1OfBytes.hxx>
 
 using namespace std;
 
@@ -256,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
@@ -588,54 +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 );
-
-                // bug [SALOME platform 0019868]
-                // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
-                AISShape->SetOwnDeviationAngle( 10*PI/180 );
-             }
+           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() );
@@ -657,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 )
@@ -680,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();
@@ -723,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 );
+                     }
                    }
                  }
                }
@@ -786,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() )
@@ -813,9 +849,7 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
   }
   else
   {
-    bool isVector;
-    if (myType == GEOM_VECTOR) isVector = true;
-    theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, isVector );
+    theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, myType == GEOM_VECTOR );
   }
 
   theActors->InitTraversal();
@@ -991,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