]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMGUI/GEOM_Displayer.cxx
Salome HOME
Implementation of the "21046: EDF 1610 GUI: To be able to change the width of the...
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.cxx
index ca2b6c92fd692ee49c4110058d09be298d2be490..8d7bb760361c25c80ab02f5b41a011dcb7b61cab 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "GeometryGUI.h"
 
+#include <GEOM_Constants.h>
 #include <GEOM_TypeFilter.h>
 #include <GEOM_EdgeFilter.h>
 #include <GEOM_FaceFilter.h>
@@ -41,6 +42,8 @@
 #include <GEOM_AISTrihedron.hxx>
 #include <GEOM_VTKTrihedron.hxx>
 
+#include <Material_Model.h>
+
 #include <SUIT_Desktop.h>
 #include <SUIT_ViewWindow.h>
 #include <SUIT_Session.h>
@@ -78,6 +81,7 @@
 #include <BRep_Tool.hxx>
 #include <Geom_Plane.hxx>
 #include <Geom_Axis2Placement.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
 #include <gp_Pln.hxx>
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
@@ -309,7 +313,11 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
   myShadingColor = SalomeApp_Tools::color( col );
 
   myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
+
   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);
+
   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));
@@ -692,10 +700,15 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
         Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
         anAspect->SetNumber( anUIsoNumber );
         anAspect->SetColor( aColor );
+       if(HasIsosWidth())
+         anAspect->SetWidth( GetIsosWidth() );
         AISShape->Attributes()->SetUIsoAspect( anAspect );
 
+
         anAspect = AISShape->Attributes()->VIsoAspect();
         anAspect->SetNumber( aVIsoNumber );
+       if(HasIsosWidth())
+         anAspect->SetWidth( GetIsosWidth() );
         anAspect->SetColor( aColor );
         AISShape->Attributes()->SetVIsoAspect( anAspect );
 
@@ -793,6 +806,7 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
             anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
             anAspect->SetColor( aColor );
             AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
+           AISShape->storeBoundaryColors();
 
             // Set free boundaries aspect
             col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
@@ -810,6 +824,11 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
             anAspect->SetColor( aColor );
             AISShape->Attributes()->SetWireAspect( anAspect );
 
+           // Set color for edges in shading
+           col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
+           aColor = SalomeApp_Tools::color( col );
+           AISShape->SetEdgesInShadingColor( aColor );
+           
             // bug [SALOME platform 0019868]
             // Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
             //AISShape->SetOwnDeviationAngle( 10*PI/180 );
@@ -818,6 +837,8 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
             double aDC = 0;
             if(useStudy) {
               aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
+             SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
+             SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
             }
             else {
               aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
@@ -933,7 +954,75 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
               }
             }
           }
+
+          // get material properties, set material
+          Material_Model* aModelF = 0;
+          Material_Model* aModelB = 0;
+          if ( useStudy ) {
+            // Get front material property from study and construct front material model
+            QString aMaterialF = aPropMap.value(FRONT_MATERIAL_PROP).toString();
+            QStringList aProps =  aMaterialF.split(DIGIT_SEPARATOR);
+            aModelF = Material_Model::getMaterialModel( aProps );
+
+            // Get back material property from study and construct back material model
+            QString aMaterialB = aPropMap.value(BACK_MATERIAL_PROP).toString();
+            if ( !aMaterialB.isEmpty() ) {
+              QStringList aPropsB =  aMaterialB.split(DIGIT_SEPARATOR);
+              aModelB = Material_Model::getMaterialModel( aPropsB );
+            }
+            else
+              aModelB = aModelF;
+
+          } else {
+            // Get front material property from study and construct front material model
+            aModelF = new Material_Model();
+            aModelF->fromResources( aResMgr, "Geometry", true );
+
+            // Get back material property from study and construct back material model
+            aModelB = new Material_Model();
+            aModelB->fromResources( aResMgr, "Geometry", false );         
+          }
+
+          // Set front material property
+          QString aMaterialPropF = aModelF->getMaterialProperty();
+          aStudy->setObjectProperty( aMgrId, anIO->getEntry(), FRONT_MATERIAL_PROP, aMaterialPropF );
+
+          // Set back material property
+          QString aMaterialPropB = aModelB->getMaterialProperty();
+          aStudy->setObjectProperty( aMgrId, anIO->getEntry(), BACK_MATERIAL_PROP, aMaterialPropB );
+
+          // Get front material properties from the model
+          Graphic3d_MaterialAspect aMatF = aModelF->getMaterialOCCAspect();
+
+          // Get back material properties from the model
+          Graphic3d_MaterialAspect aMatB = aModelB->getMaterialOCCAspect();
+
+          // Set front material for the selected shape
+          AISShape->SetCurrentFacingModel(Aspect_TOFM_FRONT_SIDE);
+          AISShape->SetMaterial(aMatF); 
+
+          // Set back material for the selected shape
+          AISShape->SetCurrentFacingModel(Aspect_TOFM_BACK_SIDE);
+          AISShape->SetMaterial(aMatB);
+
+          // Return to the default facing mode
+          AISShape->SetCurrentFacingModel(Aspect_TOFM_BOTH_SIDE);
+
+          // Release memory
+          if ( aModelF )
+            delete aModelF;
+          if ( aModelB )
+            delete aModelB;
+
+         if(HasWidth())
+           aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
+
+         if(HasIsosWidth())
+           aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
+
+
         }
+
         // AISShape->SetName(???); ??? necessary to set name ???
         occPrs->AddObject( AISShape );
 
@@ -993,6 +1082,11 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
 
   vtkActorCollection* theActors = 0;
 
+  QString anEntry;
+  if(!myIO.IsNull()) {
+    anEntry = myIO->getEntry();
+  }
+
   if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
     //myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
     GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
@@ -1021,10 +1115,8 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
   else {
     PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
 
-    QString anEntry;
     if(!myIO.IsNull()) {
       aMgrId = getViewManagerId(myViewFrame);
-      anEntry = myIO->getEntry();
     }
     useStudy = !anEntry.isEmpty() && aMgrId != -1;
 
@@ -1059,11 +1151,6 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
     aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
   }
 
-  if ( HasWidth() )
-  {
-    aProp->SetLineWidth( GetWidth() );
-  }
-
   while ( anActor != NULL )
   {
     SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
@@ -1083,6 +1170,14 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
           aGeomGActor->SetShadingProperty( aProp );
           aGeomGActor->SetWireframeProperty( aProp );
         }
+
+       // Set color for edges in shading
+       SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+       if(aResMgr) {
+         QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
+         aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
+       }
+
         int aIsos[2]= { 1, 1 };
         if(useStudy) {
           QString anIsos = aPropMap.value(ISOS_PROP).toString();
@@ -1090,10 +1185,71 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
           aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
           aGeomGActor->SetNbIsos(aIsos);
           aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
+         SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
+         SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
           aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
-          aGeomGActor->setDisplayMode(aPropMap.value(DISPLAY_MODE_PROP).toInt());
+         int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
+         // Specially processing of 'Shading with edges' mode from preferences,
+         // because there is the following enum in VTK viewer:
+         // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
+         // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
+         // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
+         if ( aDispModeId == 2 )
+           // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
+           // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
+           aDispModeId++;
+          aGeomGActor->setDisplayMode(aDispModeId);
           aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
 
+         // Get front material property of the object stored in the study
+         QString aMaterialF = aPropMap.value(FRONT_MATERIAL_PROP).toString();
+         QStringList aPropsF =  aMaterialF.split(DIGIT_SEPARATOR);
+         // Create front material model
+         Material_Model* aModelF = Material_Model::getMaterialModel( aPropsF );          
+         // Set front material properties for the object
+         QString aMaterialPropF = aModelF->getMaterialProperty();
+         aStudy->setObjectProperty( aMgrId, anEntry, FRONT_MATERIAL_PROP, aMaterialPropF );      
+         // Get material properties from the front model
+         vtkProperty* aMatPropF = aModelF->getMaterialVTKProperty();
+         
+         // Get back material property of the object stored in the study
+         QString aMaterialB = aPropMap.value(BACK_MATERIAL_PROP).toString();
+         if ( !aMaterialB.isEmpty() ) {
+           QStringList aPropsB =  aMaterialB.split(DIGIT_SEPARATOR);       
+           // Create back material model
+           Material_Model* aModelB = Material_Model::getMaterialModel( aPropsB );
+           // Set back material properties for the object
+           QString aMaterialPropB = aModelB->getMaterialProperty();
+           aStudy->setObjectProperty( aMgrId, anEntry, BACK_MATERIAL_PROP, aMaterialPropB );
+           // Get material properties from the back model
+           vtkProperty* aMatPropB = aModelB->getMaterialVTKProperty();
+
+           // Set front and back materials for the selected shape
+           std::vector<vtkProperty*> aProps;
+           aProps.push_back(aMatPropF);
+           aProps.push_back(aMatPropB);
+           aGeomGActor->SetMaterial(aProps);
+
+           // Release memory
+           delete aModelB;
+
+           if(HasWidth())
+             aStudy->setObjectProperty( aMgrId, anEntry, EDGE_WIDTH_PROP, GetWidth() );
+
+           if(HasIsosWidth())
+             aStudy->setObjectProperty( aMgrId, anEntry, ISOS_WIDTH_PROP, GetIsosWidth() );
+         
+         }
+         else {
+           // Set the same front and back materials for the selected shape
+           std::vector<vtkProperty*> aProps;
+           aProps.push_back(aMatPropF);
+           aGeomGActor->SetMaterial(aProps);
+         }
+
+         // Release memory
+         delete aModelF;
+
           vtkFloatingPointType aColor[3] = {1.,0.,0.};
           if(aPropMap.contains(COLOR_PROP)) {
             QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
@@ -1126,8 +1282,49 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
           }
           aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
         }
+       else {
+         SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+         if ( aResMgr ) {
+           // Create front material model
+           Material_Model aModelF;
+           // Get front material name from resources
+           aModelF.fromResources( aResMgr, "Geometry", true );
+           // Set front material properties for the object
+           QString aMaterialPropF = aModelF.getMaterialProperty();
+           aStudy->setObjectProperty( aMgrId, anEntry, FRONT_MATERIAL_PROP, aMaterialPropF );      
+           // Get material properties from the front model
+           vtkProperty* aMatPropF = aModelF.getMaterialVTKProperty();
+
+           // Create back material model
+           Material_Model aModelB;
+           // Get back material name from resources
+           aModelB.fromResources( aResMgr, "Geometry", false );
+           // Set back material properties for the object
+           QString aMaterialPropB = aModelB.getMaterialProperty();
+           aStudy->setObjectProperty( aMgrId, anEntry, BACK_MATERIAL_PROP, aMaterialPropB );
+           // Get material properties from the back model
+           vtkProperty* aMatPropB = aModelB.getMaterialVTKProperty();
+
+           // Set material for the selected shape
+           std::vector<vtkProperty*> aProps;
+           aProps.push_back(aMatPropF);
+           aProps.push_back(aMatPropB);
+           aGeomGActor->SetMaterial(aProps);
+         }
+       }
       }
 
+    if ( HasWidth() )
+      {
+       aGeomGActor->SetWidth( GetWidth() );
+      }
+    
+    
+    if ( HasIsosWidth() )
+      {
+       aGeomGActor->SetIsosWidth( GetIsosWidth() );
+      }
+    
     if ( myToActivate )
       GActor->PickableOn();
     else
@@ -1596,6 +1793,23 @@ void GEOM_Displayer::UnsetWidth()
   myWidth = -1;
 }
 
+
+int GEOM_Displayer::GetIsosWidth() const
+{
+  return myIsosWidth;
+}
+
+void GEOM_Displayer::SetIsosWidth(const int width) 
+{
+  myIsosWidth = width;
+}
+
+bool GEOM_Displayer::HasIsosWidth() const
+{
+  return myIsosWidth != -1;
+}
+
+
 //=================================================================
 /*!
  *  GEOM_Displayer::SetToActivate
@@ -1791,6 +2005,27 @@ PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) {
 
   aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
 
+  //8. Material
+  //   Front material
+  Material_Model aModelF;
+  aModelF.fromResources( aResMgr, "Geometry", true );
+  QString aMaterialF = aModelF.getMaterialProperty();
+  aDefaultMap.insert( FRONT_MATERIAL_PROP , aMaterialF );  
+
+  //9.  Back material
+  Material_Model aModelB;
+  aModelB.fromResources( aResMgr, "Geometry", false );
+  QString aMaterialB = aModelB.getMaterialProperty();
+  aDefaultMap.insert( BACK_MATERIAL_PROP , aMaterialB );
+
+  //10. Width of the edges
+  aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
+
+
+  //11. Width of iso-lines
+  aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
+
+
   return aDefaultMap;
 }
 
@@ -1820,6 +2055,25 @@ bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault)
     theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
     nbInserted++;
   }
+  if(!theOrigin.contains(FRONT_MATERIAL_PROP)) {
+    theOrigin.insert(FRONT_MATERIAL_PROP, theDefault.value(FRONT_MATERIAL_PROP));
+    nbInserted++;
+  }
+  if(!theOrigin.contains(BACK_MATERIAL_PROP)) {
+    theOrigin.insert(BACK_MATERIAL_PROP, theDefault.value(BACK_MATERIAL_PROP));
+    nbInserted++;
+  }
+
+  if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
+    theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
+    nbInserted++;
+  }
+
+  if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
+    theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
+    nbInserted++;
+  }
+
   return (nbInserted > 0);
 }