]> SALOME platform Git repositories - modules/geom.git/blobdiff - src/GEOMToolsGUI/GEOMToolsGUI_1.cxx
Salome HOME
Merge from V6_main 11/02/2013
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI_1.cxx
index 526a9b1e4e5e09c2bc6e379583db94a94fd9f4b7..268c101c1d9fba3d114a179d63c69f6add9ff774 100644 (file)
@@ -34,7 +34,9 @@
 #include "GEOMToolsGUI_PublishDlg.h"
 #include "GEOMToolsGUI_MaterialPropertiesDlg.h"
 #include "GEOMToolsGUI_LineWidthDlg.h"
-#include "Material_Model.h"
+#include <Material_Model.h>
+
+#include <GEOM_VTKPropertyMaterial.hxx>
 
 #include <GeometryGUI.h>
 #include <GeometryGUI_Operations.h>
 // VTK includes
 #include <vtkRenderer.h>
 
+class QtxDialog;
 // 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
@@ -298,8 +301,8 @@ void GEOMToolsGUI::SetColor( const QString& entry, const QColor& color, bool upd
   SUIT_ViewWindow* window = app->desktop()->activeWindow();
   if ( !window ) return;
   
-  bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
-  bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
+  bool isOCC = window->getViewManager()->getType() == OCCViewer_Viewer::Type();
+  bool isVTK = window->getViewManager()->getType() == SVTK_Viewer::Type();
 
   // get view id
   int mgrId = window->getViewManager()->getGlobalId();
@@ -354,7 +357,7 @@ void GEOMToolsGUI::OnColor()
   bool isVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
 
   // get view id
-  int mgrId = window->getViewManager()->getGlobalId();
+  int mgrId = window ? window->getViewManager()->getGlobalId() : -1;
 
   if ( isVTK ) {
     SVTK_ViewWindow* vtkVW = dynamic_cast<SVTK_ViewWindow*>( window );
@@ -363,7 +366,7 @@ void GEOMToolsGUI::OnColor()
     // get initial color (use first object from selection)
     SVTK_View* aView = vtkVW->getView();
     QColor color = aView->GetColor( selected.First()  );
-    QVariant v = appStudy->getObjectProperty( mgrId, selected.First()->getEntry(), COLOR_PROP, color );
+    QVariant v = appStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
 
     // show Choose Color dialog box
     color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
@@ -387,7 +390,7 @@ void GEOMToolsGUI::OnColor()
     QColor color = QColor((int)( aColor.Red()   * 255.0 ),
                          (int)( aColor.Green() * 255.0 ),
                          (int)( aColor.Blue()  * 255.0 ));
-    QVariant v = appStudy->getObjectProperty( mgrId, selected.First()->getEntry(), COLOR_PROP, color );
+    QVariant v = appStudy->getObjectProperty( mgrId, selected.First()->getEntry(), GEOM::propertyName( GEOM::Color ), color );
 
     // show Choose Color dialog box
     color = QColorDialog::getColor( v.value<QColor>(), app->desktop() );
@@ -419,14 +422,14 @@ void GEOMToolsGUI::setVtkColor( SalomeApp_Study* study,                     // s
 {
   // get material property
   QString matProp;
-  matProp = study->getObjectProperty( mgrId, IO->getEntry(), MATERIAL_PROP, matProp ).toString();
+  matProp = study->getObjectProperty( mgrId, IO->getEntry(), GEOM::propertyName( GEOM::Material ), matProp ).toString();
   Material_Model material;
   material.fromProperties( matProp );
 
   // change color only for shapes with not physical type of material
   if ( !material.isPhysical() ) {
     view->SetColor( IO, color );
-    study->setObjectProperty( mgrId, IO->getEntry(), COLOR_PROP, color );
+    study->setObjectProperty( mgrId, IO->getEntry(), GEOM::propertyName( GEOM::Color ), color );
   }
 
   // store color to GEOM_Object
@@ -459,7 +462,7 @@ void GEOMToolsGUI::setOccColor( SalomeApp_Study* study,                     // s
 
   // get material property
   QString matProp;
-  matProp = study->getObjectProperty( mgrId, IO->getEntry(), MATERIAL_PROP, matProp ).toString();
+  matProp = study->getObjectProperty( mgrId, IO->getEntry(), GEOM::propertyName( GEOM::Material ), matProp ).toString();
   Material_Model material;
   material.fromProperties( matProp );
 
@@ -504,7 +507,7 @@ void GEOMToolsGUI::setOccColor( SalomeApp_Study* study,                     // s
 
     io->Redisplay( Standard_True );
 
-    study->setObjectProperty( mgrId, IO->getEntry(), COLOR_PROP, color );
+    study->setObjectProperty( mgrId, IO->getEntry(), GEOM::propertyName( GEOM::Color ), color );
   }    
 
   // store color to GEOM_Object
@@ -661,6 +664,7 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType )
 
     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
+    int aMgrId = window->getViewManager()->getGlobalId();
 
     ic->InitCurrent();
     if ( ic->MoreCurrent() ) {
@@ -702,12 +706,11 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType )
       }
 
       for(; ic->MoreCurrent(); ic->NextCurrent()) {
-        int aMgrId = window->getViewManager()->getGlobalId();
         CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
 
         Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
 
-       QVariant v = aStudy->getObjectProperty( aMgrId, CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP , QVariant() );
+       QVariant v = aStudy->getObjectProperty( aMgrId, CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::LineWidth ) , QVariant() );
 
        int width = v.isValid() ? v.toInt() : 1;
 
@@ -719,8 +722,8 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType )
         ic->SetLocalAttributes(CurObject, CurDrawer);
         ic->Redisplay(CurObject);
 
-        QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
-        aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_PROP, anIsos);
+        QString anIsos = QString("%1%2%3").arg(newNbUIso).arg(GEOM::subSectionSeparator()).arg(newNbVIso);
+        aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos);
       }
     }
     GeometryGUI::Modified();
@@ -745,6 +748,8 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType )
     if ( !vtkVW )
       return;
 
+    int aMgrId = window->getViewManager()->getGlobalId();
+
     SALOME_View* view = GEOM_Displayer::GetActiveView();
 
     vtkActorCollection* aCollection = vtkActorCollection::New();
@@ -814,9 +819,8 @@ void GEOMToolsGUI::OnNbIsos( ActionType actionType )
         anActor->SetNbIsos(aIsos);
        anActor->StoreIsoNumbers();
 
-        QString anIsos("%1%2%3");anIsos = anIsos.arg(newNbUIso);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(newNbVIso);
-        int aMgrId = window->getViewManager()->getGlobalId();
-        aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_PROP, anIsos);
+        QString anIsos = QString("%1%2%3").arg(newNbUIso).arg(GEOM::subSectionSeparator()).arg(newNbVIso);
+        aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), GEOM::propertyName( GEOM::NbIsos ), anIsos);
       }
       anAct = aCollection->GetNextActor();
     }
@@ -833,7 +837,7 @@ void GEOMToolsGUI::OnDeflection()
 
   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
-  int mgrId = window->getViewManager()->getGlobalId();
+  int mgrId = window ? window->getViewManager()->getGlobalId() : -1;
 
   if (isOCC) { // if is OCCViewer
     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
@@ -863,7 +867,7 @@ void GEOMToolsGUI::OnDeflection()
               CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
               ic->SetDeviationCoefficient(CurObject, aNewDC, Standard_True);
               ic->Redisplay(CurObject);
-              appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aNewDC);
+              appStudy->setObjectProperty(mgrId,CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::Deflection ), aNewDC);
             }
           }
         }
@@ -932,7 +936,7 @@ void GEOMToolsGUI::OnDeflection()
         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
           // There are no casting to needed actor.
           anActor->SetDeflection(aDC);
-          appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), DEFLECTION_COEFF_PROP, aDC);
+          appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), GEOM::propertyName( GEOM::Deflection ), aDC);
         }
         anAct = aCollection->GetNextActor();
       }
@@ -1006,7 +1010,14 @@ void GEOMToolsGUI::OnPointMarker()
 
 void GEOMToolsGUI::OnMaterialProperties()
 {
-  GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );
+ GEOMToolsGUI_MaterialPropertiesDlg* dlg = new GEOMToolsGUI_MaterialPropertiesDlg( SUIT_Session::session()->activeApplication()->desktop(), true, false, QtxDialog::OK | QtxDialog::Close | QtxDialog::Apply | QtxDialog::Help );
+ dlg->show();
+}
+
+void GEOMToolsGUI::OnMaterialsLibrary()
+{
+       GEOMToolsGUI_MaterialPropertiesDlg dlg( SUIT_Session::session()->activeApplication()->desktop(), false, true, QtxDialog::Standard );
+       dlg.setWindowTitle( tr( "MATERIAL_LIBRARY_TLT" ) );
   dlg.exec();
 }
 
@@ -1093,7 +1104,7 @@ void GEOMToolsGUI::OnEdgeWidth()
 
   bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
-  int mgrId = window->getViewManager()->getGlobalId();
+  int mgrId = window ? window->getViewManager()->getGlobalId() : -1;
 
   if (isOCC) { // if is OCCViewer
     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>(window->getViewManager()->getViewModel());
@@ -1126,7 +1137,7 @@ void GEOMToolsGUI::OnEdgeWidth()
                                        ic->Redisplay(cur);
                                  }
                                }
-                       appStudy->setObjectProperty(mgrId, CurObject->getIO()->getEntry(), EDGE_WIDTH_PROP, aNewWidth);
+                       appStudy->setObjectProperty(mgrId, CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aNewWidth);
                  }
                }
          }
@@ -1195,7 +1206,7 @@ void GEOMToolsGUI::OnEdgeWidth()
         if (GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
           // There are no casting to needed actor.
           anActor->SetWidth(aWidth);
-          appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), EDGE_WIDTH_PROP, aWidth);
+          appStudy->setObjectProperty(mgrId, anActor->getIO()->getEntry(), GEOM::propertyName( GEOM::LineWidth ), aWidth);
         }
         anAct = aCollection->GetNextActor();
       }
@@ -1218,6 +1229,7 @@ void GEOMToolsGUI::OnIsosWidth() {
 
     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
+    int aMgrId = window->getViewManager()->getGlobalId();
 
     ic->InitCurrent();
     if ( ic->MoreCurrent() ) {
@@ -1246,7 +1258,6 @@ void GEOMToolsGUI::OnIsosWidth() {
        return;
       
       for(; ic->MoreCurrent(); ic->NextCurrent()) {
-       int aMgrId = window->getViewManager()->getGlobalId();
        CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
        
        Handle(AIS_Drawer) CurDrawer = CurObject->Attributes();
@@ -1256,7 +1267,7 @@ void GEOMToolsGUI::OnIsosWidth() {
        
        ic->Redisplay(CurObject);
        
-       aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
+       aStudy->setObjectProperty(aMgrId ,CurObject->getIO()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth);
       }
       GeometryGUI::Modified();
     }
@@ -1281,6 +1292,8 @@ void GEOMToolsGUI::OnIsosWidth() {
     if ( !vtkVW )
       return;
 
+    int aMgrId = window->getViewManager()->getGlobalId();
+
     SALOME_View* view = GEOM_Displayer::GetActiveView();
 
     vtkActorCollection* aCollection = vtkActorCollection::New();
@@ -1325,8 +1338,7 @@ void GEOMToolsGUI::OnIsosWidth() {
       if(GEOM_Actor* anActor = GEOM_Actor::SafeDownCast(anAct)) {
         // There are no casting to needed actor.
        anActor->SetIsosWidth(aWidth);
-       int aMgrId = window->getViewManager()->getGlobalId();
-        aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), ISOS_WIDTH_PROP, aWidth);
+        aStudy->setObjectProperty(aMgrId ,anActor->getIO()->getEntry(), GEOM::propertyName( GEOM::IsosWidth ), aWidth);
       }
       anAct = aCollection->GetNextActor();
     }
@@ -1377,15 +1389,15 @@ void GEOMToolsGUI::OnBringToFront() {
   if ( isOCC ) {
     GEOMBase* gb = new GEOMBase();
     Handle(GEOM_AISShape) aisShape;
+    int aMgrId = window->getViewManager()->getGlobalId();
    
     Handle(AIS_InteractiveContext) ic = vm->getAISContext();
     SALOME_ListIO anIOlst;
     for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
       aisShape = gb->ConvertIOinGEOMAISShape( It.Value(), true );
       if ( !aisShape.IsNull() ) {
+       appStudy->setObjectProperty( aMgrId, aisShape->getIO()->getEntry(), GEOM::propertyName( GEOM::TopLevel ), checked );
        aisShape->setTopLevel(checked);
-       int aMgrId = window->getViewManager()->getGlobalId();
-       appStudy->setObjectProperty( aMgrId, aisShape->getIO()->getEntry(), TOP_LEVEL_PROP, checked );
        anIOlst.Append(aisShape->getIO());
       }
     } // for...
@@ -1422,6 +1434,7 @@ void GEOMToolsGUI::OnClsBringToFront() {
     
     OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*>( window->getViewManager()->getViewModel() );
     Handle (AIS_InteractiveContext) ic = vm->getAISContext();
+    int aMgrId = window->getViewManager()->getGlobalId();
     
     SALOME_ListIO anIOlst;
     AIS_ListOfInteractive aList;
@@ -1433,10 +1446,8 @@ void GEOMToolsGUI::OnClsBringToFront() {
       if(CurObject.IsNull())
        continue;
       
+      appStudy->setObjectProperty( aMgrId, QString(CurObject->getIO()->getEntry()), GEOM::propertyName( GEOM::TopLevel ), Standard_False );
       CurObject->setTopLevel(Standard_False);
-      
-      int aMgrId = window->getViewManager()->getGlobalId();
-      appStudy->setObjectProperty( aMgrId, QString(CurObject->getIO()->getEntry()), TOP_LEVEL_PROP, Standard_False );
       anIOlst.Append(CurObject->getIO());
     }
     disp->Redisplay(anIOlst);
@@ -1444,3 +1455,40 @@ void GEOMToolsGUI::OnClsBringToFront() {
   }
 }
   
+void GEOMToolsGUI::OnSetMaterial( const QVariant& theParam )
+{
+  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 ( !study ) return;
+  
+  LightApp_SelectionMgr* selMgr = app->selectionMgr();
+
+  SALOME_ListIO selected;
+  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();
+
+  Material_Model aModel;
+  aModel.fromResources( theName );
+  QString prop = aModel.toProperties();
+
+  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();
+}