]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
0021830: [CEA 652] TUI createAndDisplayGO (part 3)
authorvsr <vsr@opencascade.com>
Fri, 1 Feb 2013 09:37:57 +0000 (09:37 +0000)
committervsr <vsr@opencascade.com>
Fri, 1 Feb 2013 09:37:57 +0000 (09:37 +0000)
src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
src/OBJECT/GEOM_Actor.cxx
src/OBJECT/GEOM_Actor.h

index a7d0252cc8b5a94225d5c2495493e537bf12cdd1..268c101c1d9fba3d114a179d63c69f6add9ff774 100644 (file)
@@ -1457,88 +1457,38 @@ void GEOMToolsGUI::OnClsBringToFront() {
   
 void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
 {
-  QString theName;
-  if ( theParam.canConvert<QString>() ) theName = theParam.toString();
-  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
-  if ( !app )
-    return;
-  SalomeApp_Module* mod = dynamic_cast<SalomeApp_Module*>(app->activeModule());
-  if(!mod)
-    return;
-  GEOM_Displayer* disp  = dynamic_cast<GEOM_Displayer*>(mod->displayer());
-  if(!disp)
-    return;
-  LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+  if ( !theParam.canConvert<QString>() ) return;
+  
+  QString theName = theParam.toString();
+
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+  if ( !app ) return;
+  
   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-  if ( !aSelMgr || !study )
-    return;
+  if ( !study ) return;
+  
+  LightApp_SelectionMgr* selMgr = app->selectionMgr();
+
   SALOME_ListIO selected;
-  aSelMgr->selectedObjects( selected );
-  if ( selected.IsEmpty() )
-    return;
-    SUIT_ViewWindow* window = app->desktop()->activeWindow();
-    int mgrId = window ? window->getViewManager()->getGlobalId() : -1;
+  selMgr->selectedObjects( selected );
+
+  if ( selected.IsEmpty() ) return;
+  
+  GEOM_Displayer displayer( study );
+
+  SALOME_View* window = displayer.GetActiveView();
+  if ( !window ) return;
+  
+  int mgrId = dynamic_cast<SUIT_ViewModel*>( window )->getViewManager()->getGlobalId();
 
-  // convert needed material properties to the string representation
   Material_Model aModel;
   aModel.fromResources( theName );
   QString prop = aModel.toProperties();
-  if ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() ) {
-    // for VTK viewer
-    SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
-    if ( !vtkVW )
-      return;
-
-    SVTK_View* aView = vtkVW->getView();
-
-    // get VTK material properties from the current model
-    GEOM_VTKPropertyMaterial* vtkPropF = aModel.getMaterialVTKProperty();
-    GEOM_VTKPropertyMaterial* vtkPropB = aModel.getMaterialVTKProperty( false );
-
-    SUIT_OverrideCursor wc();
-
-    for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
-      // set material property to the presentation
-      aView->SetMaterial( It.Value(), vtkPropF, vtkPropB );
-      // store chosen material in the property map
-      study->setObjectProperty( mgrId, It.Value()->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
-      // set correct color for the non-physical material
-    }
-    aView->Repaint();
-    GeometryGUI::Modified();
-  }
-  else if ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {    
-    // for OCC viewer
-    OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
-    if ( !vm )
-      return;
-
-    Handle(AIS_InteractiveContext) ic = vm->getAISContext();
-
-    // get OCC material aspect from the current model
-    Graphic3d_MaterialAspect front_occAspect = aModel.getMaterialOCCAspect( true );
-    Graphic3d_MaterialAspect back_occAspect = aModel.getMaterialOCCAspect( false );
 
-    SUIT_OverrideCursor wc();
-
-    for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
-      Handle(GEOM_AISShape) aisShape = GEOMBase::ConvertIOinGEOMAISShape( It.Value(), true );
-      if ( !aisShape.IsNull() ) {
-        // Set front material for the selected shape
-             aisShape->SetCurrentFacingModel(Aspect_TOFM_FRONT_SIDE);
-             aisShape->SetMaterial(front_occAspect);
-             // Set back material for the selected shape
-             aisShape->SetCurrentFacingModel(Aspect_TOFM_BACK_SIDE);
-             aisShape->SetMaterial(back_occAspect);
-             // Return to the default facing mode
-             aisShape->SetCurrentFacingModel(Aspect_TOFM_BOTH_SIDE);
-        // store chosen material in the property map
-             study->setObjectProperty( mgrId, It.Value()->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
-             //if ( aisShape->DisplayMode() != AIS_Shaded)
-             ic->Redisplay( aisShape, Standard_False );
-      }
-    }
-    ic->UpdateCurrentViewer();
+  for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
+    Handle(SALOME_InteractiveObject) io = It.Value();
+    study->setObjectProperty( mgrId, io->getEntry(), GEOM::propertyName( GEOM::Material ), prop );
+    if ( window->isVisible( io ) ) displayer.Redisplay( io, false );
   }
+  displayer.UpdateViewer();
 }
index 5865ba5d28ccc5759e5858a7ddac1c1a58f14aa4..1552ee79425aa5ad416aeeda223ad481ae0a05c2 100644 (file)
@@ -150,19 +150,22 @@ GEOM_Actor::GEOM_Actor():
   myIsolatedEdgeActor->SetInput(myIsolatedEdgeSource->GetOutput(),false); 
   aProperty = myIsolatedEdgeActor->GetProperty(); 
   aProperty->SetRepresentation(VTK_WIREFRAME); 
-  aProperty->SetColor(1, 0, 0);
+  myIsolatedEdgeColor[0] = 1; myIsolatedEdgeColor[1] = 0; myIsolatedEdgeColor[2] = 0;
+  aProperty->SetColor(myIsolatedEdgeColor[0], myIsolatedEdgeColor[1], myIsolatedEdgeColor[2]);
  
   myAppendFilter->AddInput(myOneFaceEdgeSource->GetOutput());
   myOneFaceEdgeActor->SetInput(myOneFaceEdgeSource->GetOutput(),false); 
   aProperty = myOneFaceEdgeActor->GetProperty(); 
   aProperty->SetRepresentation(VTK_WIREFRAME); 
-  aProperty->SetColor(0, 1, 0);
+  myOneFaceEdgeColor[0] = 0; myOneFaceEdgeColor[1] = 1; myOneFaceEdgeColor[2] = 0;
+  aProperty->SetColor(myOneFaceEdgeColor[0], myOneFaceEdgeColor[1], myOneFaceEdgeColor[2]);
  
   myAppendFilter->AddInput(mySharedEdgeSource->GetOutput()); 
   mySharedEdgeActor->SetInput(mySharedEdgeSource->GetOutput(),false); 
   aProperty = mySharedEdgeActor->GetProperty(); 
   aProperty->SetRepresentation(VTK_WIREFRAME); 
-  aProperty->SetColor(1, 1, 0);
+  mySharedEdgeColor[0] = 1; mySharedEdgeColor[1] = 1; mySharedEdgeColor[2] = 0;
+  aProperty->SetColor(mySharedEdgeColor[0], mySharedEdgeColor[1], mySharedEdgeColor[2]);
  
   myAppendFilter->AddInput(myWireframeFaceSource->GetOutput()); 
   myWireframeFaceActor->SetInput(myWireframeFaceSource->GetOutput(),false); 
@@ -183,8 +186,6 @@ GEOM_Actor::GEOM_Actor():
 
   myShadingFaceActor->SetProperty(myShadingFaceProp.GetPointer());
 
-  StoreBoundaryColors();
-
   myNbIsos[0] = -1;
   myNbIsos[1] = -1;
 
@@ -296,40 +297,42 @@ setDisplayMode(int theMode)
   MESSAGE ( "GEOM_Actor::setDisplayMode = "<<theMode );
 #endif
   
-  if ( theMode == (int)eWireframe ) {
-    RestoreIsoNumbers();
-    // Restore wireframe edges colors
-    RestoreBoundaryColors();
-  }
-  else if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
+  if ( theMode == (int)eShading || theMode == (int)eShadingWithEdges ) {
     // Temporary store number of iso lines in order to recover its later 
-    // when display mode is achnged to 'Wirefame' or 'Shading'.
-    // Iso lines are not displayed in 'Shading with edges' mode.
+    // when display mode is changed to 'Wirefame'
+    // Iso lines are not displayed in 'Shading' and 'Shading with edges' modes.
     StoreIsoNumbers();
 
     // Reset number of iso lines to 0
     ResetIsoNumbers();
+  }
 
-    if ( theMode == (int)eShadingWithEdges ) {
-      // Store wireframe edges colors
-      StoreBoundaryColors();
-
-      // Coloring edges
-      myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
-                                                  myEdgesInShadingColor[1],
-                                                  myEdgesInShadingColor[2]);
-      myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
-                                                 myEdgesInShadingColor[1],
-                                                 myEdgesInShadingColor[2]);
-      mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
+  if ( theMode == (int)eShadingWithEdges ) {
+    // Coloring edges
+    myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
                                                 myEdgesInShadingColor[1],
                                                 myEdgesInShadingColor[2]);
-      //SetModified();
-    } else {
-      myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
-                                                  myEdgesInWireframeColor[1],
-                                                  myEdgesInWireframeColor[2]);
-    }
+    myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
+                                               myEdgesInShadingColor[1],
+                                               myEdgesInShadingColor[2]);
+    mySharedEdgeActor->GetProperty()->SetColor(myEdgesInShadingColor[0],
+                                              myEdgesInShadingColor[1],
+                                              myEdgesInShadingColor[2]);
+  }
+  else {
+    // Restore number of iso-lines
+    RestoreIsoNumbers();
+
+    // Coloring edges
+    myIsolatedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
+                                                myIsolatedEdgeColor[1],
+                                                myIsolatedEdgeColor[2]);
+    mySharedEdgeActor->GetProperty()->SetColor(myIsolatedEdgeColor[0],
+                                              myIsolatedEdgeColor[1],
+                                              myIsolatedEdgeColor[2]);
+    myOneFaceEdgeActor->GetProperty()->SetColor(myOneFaceEdgeColor[0],
+                                              myOneFaceEdgeColor[1],
+                                              myOneFaceEdgeColor[2]);
   }
 
   VTKViewer_Actor::setDisplayMode(theMode);
@@ -502,6 +505,26 @@ vtkProperty* GEOM_Actor::GetWireframeProperty()
   return myWireframeFaceActor->GetProperty();
 }
 
+vtkProperty* GEOM_Actor::GetIsolatedEdgeProperty()
+{
+  return myIsolatedEdgeActor->GetProperty();
+}
+
+vtkProperty* GEOM_Actor::GetVertexProperty()
+{
+  return myVertexActor->GetProperty();
+}
+
+vtkProperty* GEOM_Actor::GetSharedEdgeProperty()
+{
+  return mySharedEdgeActor->GetProperty();
+}
+
+vtkProperty* GEOM_Actor::GetFaceEdgeProperty()
+{
+  return myOneFaceEdgeActor->GetProperty();
+}
+
 void GEOM_Actor::SetShadingProperty(vtkProperty* Prop)
 {
 #ifdef MYDEBUG
@@ -691,22 +714,22 @@ vtkFloatingPointType GEOM_Actor::GetOpacity()
 
 void GEOM_Actor::SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b)
 {
-  // enk:tested OK
-  myShadingFaceProp->SetColor(r,g,b);                          // shading color (Shading)
-  myShadingBackFaceProp->SetColor(r,g,b);                      // back face shading color (Shading)
-  myVertexActor->GetProperty()->SetColor(r,g,b);               // vertex actor (Shading/Wireframe)
-  if ( myDisplayMode != (int)eShadingWithEdges ) {
-    myIsolatedEdgeActor->GetProperty()->SetColor(r,g,b);         // standalone edge color (Wireframe)
-    myOneFaceEdgeActor->GetProperty()->SetColor(r,g,b);          // standalone face edge color (Wireframe)
-    mySharedEdgeActor->GetProperty()->SetColor(r,g,b);           // share edge color (Wireframe)
-  }
-
-  StoreBoundaryColors();
+  // set the same color to all sub-actors:
+  // - points
+  // - standalone edges
+  // - shared edges
+  // - free edges
+  // - shading color (front and back faces)
+  SetPointColor(r, g, b);
+  SetIsolatedEdgeColor(r, g, b);
+  SetSharedEdgeColor(r, g, b);
+  SetFreeEdgeColor(r, g, b);
+  myShadingFaceProp->SetColor(r,g,b);     // shading color
+  myShadingBackFaceProp->SetColor(r,g,b); // back face shading color
 }
 
 void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b)
 {
-  // enk:tested OK
   vtkFloatingPointType aRGB[3];
   myShadingFaceProp->GetColor(aRGB);
   r = aRGB[0];
@@ -714,6 +737,60 @@ void GEOM_Actor::GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFlo
   b = aRGB[2];
 }
 
+/*!
+  \brief Set color of points
+  Points actor is shown in Wireframe mode only, see SetVisibility()
+*/
+void GEOM_Actor::SetPointColor(vtkFloatingPointType r,  vtkFloatingPointType g,  vtkFloatingPointType b)
+{
+  myVertexActor->GetProperty()->SetColor(r, g, b);
+}
+
+/*!
+  \brief Set color of standalone edges, wires, vectors
+  This actor is shown in all display mode, see SetVisibility()
+  TODO: check - this color seems to be used not only for standalone edges
+*/
+void GEOM_Actor::SetIsolatedEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g,  vtkFloatingPointType b)
+{
+  myIsolatedEdgeColor[0] = r; myIsolatedEdgeColor[1] = g; myIsolatedEdgeColor[2] = b;
+  if ( myDisplayMode != (int)eShadingWithEdges )
+    myIsolatedEdgeActor->GetProperty()->SetColor(r, g, b);
+}
+
+/*!
+  \brief Set color of shared edges
+  This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
+  TODO: check - this seems to be not working currently
+*/
+void GEOM_Actor::SetSharedEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b)
+{
+  mySharedEdgeColor[0] = r; mySharedEdgeColor[1] = g; mySharedEdgeColor[2] = b;
+  if ( myDisplayMode != (int)eShadingWithEdges )
+    mySharedEdgeActor->GetProperty()->SetColor(r, g, b);
+}
+
+/*!
+  \brief Set color of edges for standalone faces
+  This actor is shown only in wireframe and shading+edges display modes, see SetVisibility()
+  TODO: this color should be used not only for faces
+*/
+void GEOM_Actor::SetFreeEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b)
+{
+  myOneFaceEdgeColor[0] = r; myOneFaceEdgeColor[1] = g; myOneFaceEdgeColor[2] = b;
+  if ( myDisplayMode != (int)eShadingWithEdges )
+    myOneFaceEdgeActor->GetProperty()->SetColor(r, g, b);
+}
+
+/*!
+  \brief Set color of iso-lines
+  This actor is shown only in wireframe display mode, see SetVisibility()
+*/
+void GEOM_Actor::SetIsosColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b)
+{
+  myWireframeFaceActor->GetProperty()->SetColor(r, g, b);
+}
+
 void GEOM_Actor::SetMaterial(std::vector<vtkProperty*> theProps)
 {
   // we set material properties as back and front material
@@ -1040,22 +1117,3 @@ void GEOM_Actor::ResetIsoNumbers()
   int aNb[2] = {0, 0};
   myWireframeFaceSource->SetNbIso(aNb);
 }
-
-void GEOM_Actor::StoreBoundaryColors()
-{
-  myShadingFaceProp->GetColor(myEdgesInWireframeColor);
-
-}
-void GEOM_Actor::RestoreBoundaryColors()
-{
-  myIsolatedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
-                                              myEdgesInWireframeColor[1],
-                                              myEdgesInWireframeColor[2]);
-  myOneFaceEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
-                                             myEdgesInWireframeColor[1],
-                                             myEdgesInWireframeColor[2]);
-  mySharedEdgeActor->GetProperty()->SetColor(myEdgesInWireframeColor[0],
-                                            myEdgesInWireframeColor[1],
-                                            myEdgesInWireframeColor[2]);
-}
index f3acde3030d583da1316d6bb81c4238f8a2cbd63..d773b6cf6b090fd89d622a7af34c49ce05a0d67a 100644 (file)
@@ -87,6 +87,10 @@ public:
 
   vtkProperty* GetWireframeProperty();
   vtkProperty* GetShadingProperty();
+  vtkProperty* GetIsolatedEdgeProperty();
+  vtkProperty* GetVertexProperty();
+  vtkProperty* GetSharedEdgeProperty();
+  vtkProperty* GetFaceEdgeProperty();
 
   void setDeflection(double adef);
   virtual void setDisplayMode(int thenewmode);
@@ -120,9 +124,22 @@ public:
   void SetOpacity(vtkFloatingPointType opa);
   vtkFloatingPointType GetOpacity();
 
-  // Color
-  void SetColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
-  void GetColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b);
+  // Color (same to all sub-actors/display modes)
+  void SetColor(vtkFloatingPointType r,  vtkFloatingPointType g,  vtkFloatingPointType b);
+  void GetColor(vtkFloatingPointType& r, vtkFloatingPointType& g, vtkFloatingPointType& b);
+  // Color of points
+  void SetPointColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
+  // Color of standalone edges, wires, vectors
+  void SetIsolatedEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
+  // Color of shared edges
+  void SetSharedEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
+  // Color of free edges
+  void SetFreeEdgeColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
+  // Color of edges in shading+edges display mode
+  void SetEdgesInShadingColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
+  // Color of iso-lines
+  void SetIsosColor(vtkFloatingPointType r, vtkFloatingPointType g, vtkFloatingPointType b);
+
 
   // Material
   void SetMaterial(std::vector<vtkProperty*> theProps);
@@ -185,9 +202,6 @@ public:
   bool
   GetVectorMode();
   
-  //! Edges in shading color management
-  void SetEdgesInShadingColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
-
   void
   StoreIsoNumbers();
 
@@ -202,9 +216,6 @@ protected:
 
   void GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result);
 
-  void StoreBoundaryColors();
-  void RestoreBoundaryColors();
-
   GEOM_Actor();
   ~GEOM_Actor();
 
@@ -254,6 +265,9 @@ private:
 
   vtkFloatingPointType myEdgesInWireframeColor[3];
   vtkFloatingPointType myEdgesInShadingColor[3];
+  vtkFloatingPointType myIsolatedEdgeColor[3];
+  vtkFloatingPointType mySharedEdgeColor[3];
+  vtkFloatingPointType myOneFaceEdgeColor[3];
 };
 
 #endif //GEOM_ACTOR_H