]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
rnc: added a method to put textures on shapes
authorgdd <gdd>
Wed, 26 Oct 2011 15:40:48 +0000 (15:40 +0000)
committergdd <gdd>
Wed, 26 Oct 2011 15:40:48 +0000 (15:40 +0000)
src/GEOMGUI/GeometryGUI.cxx
src/GEOMGUI/GeometryGUI_Operations.h
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOMToolsGUI/GEOMToolsGUI.h
src/GEOMToolsGUI/GEOMToolsGUI_1.cxx

index e5607313423495e0ddc425704f54e434cc201706..e49dc8e2d2eef94fef4a5906940ec8bf98e63052 100644 (file)
@@ -403,6 +403,7 @@ void GeometryGUI::OnGUIEvent( int id )
   case GEOMOp::OpCheckGeom:        // MENU TOOLS - CHECK GEOMETRY
   case GEOMOp::OpDeflection:       // POPUP MENU - DEFLECTION COEFFICIENT
   case GEOMOp::OpColor:            // POPUP MENU - COLOR
+  case GEOMOp::OpSetTexture:       // POPUP MENU - SETTEXTURE
   case GEOMOp::OpTransparency:     // POPUP MENU - TRANSPARENCY
   case GEOMOp::OpIncrTransparency: // SHORTCUT   - INCREASE TRANSPARENCY
   case GEOMOp::OpDecrTransparency: // SHORTCUT   - DECREASE TRANSPARENCY
@@ -803,6 +804,7 @@ void GeometryGUI::initialize( CAM_Application* app )
   createGeomAction( GEOMOp::OpVectors,          "POP_VECTORS", "", 0, true );
   createGeomAction( GEOMOp::OpDeflection,       "POP_DEFLECTION" );
   createGeomAction( GEOMOp::OpColor,            "POP_COLOR" );
+  createGeomAction( GEOMOp::OpSetTexture,       "POP_SETTEXTURE" );
   createGeomAction( GEOMOp::OpTransparency,     "POP_TRANSPARENCY" );
   createGeomAction( GEOMOp::OpIsos,             "POP_ISOS" );
   createGeomAction( GEOMOp::OpAutoColor,        "POP_AUTO_COLOR" );
@@ -1122,10 +1124,14 @@ void GeometryGUI::initialize( CAM_Application* app )
   // ---- create popup menus --------------------------
 
   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
+  QString clientOCC = "(client='OCCViewer')";
   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
+  QString clientOCC_AndSomeVisible = clientOCC + " and selcount>0 and isVisible";
 
+  QString clientOCCorOB = "(client='ObjectBrowser' or client='OCCViewer')";
   QString clientOCCorVTKorOB = "(client='ObjectBrowser' or client='OCCViewer' or client='VTKViewer')";
   QString clientOCCorVTKorOB_AndSomeVisible = clientOCCorVTKorOB + " and selcount>0 and isVisible";
+  QString clientOCCorOB_AndSomeVisible = clientOCCorOB + " and selcount>0 and isVisible";
 
   QString autoColorPrefix =
     "(client='ObjectBrowser' or client='OCCViewer') and type='Shape' and selcount=1 and isOCC=true";
@@ -1152,8 +1158,8 @@ void GeometryGUI::initialize( CAM_Application* app )
   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
   mgr->setRule( action( GEOMOp::OpShading ), clientOCCorVTK + " and displaymode='Shading'", QtxPopupMgr::ToggleRule );
   mgr->insert( action(  GEOMOp::OpTexture ), dispmodeId, -1 ); // wireframe
-  mgr->setRule( action( GEOMOp::OpTexture ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
-  mgr->setRule( action( GEOMOp::OpTexture), clientOCCorVTK + " and displaymode='Texture'", QtxPopupMgr::ToggleRule );
+  mgr->setRule( action( GEOMOp::OpTexture ), clientOCC_AndSomeVisible, QtxPopupMgr::VisibleRule );
+  mgr->setRule( action( GEOMOp::OpTexture), clientOCC + " and displaymode='Texture'", QtxPopupMgr::ToggleRule );
   mgr->insert( separator(), dispmodeId, -1 );
   mgr->insert( action(  GEOMOp::OpVectors ), dispmodeId, -1 ); // vectors
   mgr->setRule( action( GEOMOp::OpVectors ), clientOCCorVTK_AndSomeVisible, QtxPopupMgr::VisibleRule );
@@ -1170,6 +1176,8 @@ void GeometryGUI::initialize( CAM_Application* app )
   mgr->insert( action(  GEOMOp::OpPointMarker ), -1, -1 ); // point marker
   //mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and $typeid in {%1}" ).arg(GEOM_POINT ), QtxPopupMgr::VisibleRule );
   mgr->setRule( action( GEOMOp::OpPointMarker ), QString( "selcount>0 and ( $typeid in {%1} or compoundOfVertices=true ) " ).arg(GEOM::VERTEX).arg(GEOM::COMPOUND), QtxPopupMgr::VisibleRule );
+  mgr->insert( action(  GEOMOp::OpSetTexture ), -1, -1 ); // texture
+  mgr->setRule( action( GEOMOp::OpSetTexture ), clientOCCorOB_AndSomeVisible + " and ($component={'GEOM'})", QtxPopupMgr::VisibleRule );
   mgr->insert( separator(), -1, -1 );     // -----------
   mgr->insert( action(  GEOMOp::OpAutoColor ), -1, -1 ); // auto color
   mgr->setRule( action( GEOMOp::OpAutoColor ), autoColorPrefix + " and isAutoColor=false", QtxPopupMgr::VisibleRule );
index 72525fd2fac6b745d20e298d4b9629b0246c6c6f..59498a5e6baea722d5806f9d52c2eae66ccb1de8 100644 (file)
@@ -48,6 +48,7 @@ namespace GEOMOp {
     OpAutoColor         = 1208,   // POPUP MENU - AUTO COLOR
     OpNoAutoColor       = 1209,   // POPUP MENU - DISABLE AUTO COLOR
     OpPointMarker       = 1210,   // POPUP MENU - POINT MARKER
+    OpSetTexture        = 1211,   // POPUP MENU - SETTEXTURE
     OpShowChildren      = 1250,   // POPUP MENU - SHOW CHILDREN
     OpHideChildren      = 1251,   // POPUP MENU - HIDE CHILDREN
     OpUnpublishObject   = 1253,   // POPUP MENU - UNPUBLISH
index 008d71b8621f9bf61c0b68109f8b9d2c3242c682..cc95e6831cb7f9a2411e2993da468138be3fc490 100644 (file)
@@ -328,6 +328,9 @@ bool GEOMToolsGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
   case GEOMOp::OpColor:          // POPUP - COLOR
     OnColor();
     break;
+  case GEOMOp::OpSetTexture:        // POPUP - TEXTURE
+    OnTexture();
+    break;
   case GEOMOp::OpTransparency:   // POPUP - TRANSPARENCY
     OnTransparency();
     break;
index bb20a9687b3aa8159408e8ba4788ebb7a3025f3a..12cead468218d1bcb3afef44e75f8ca93b7368a7 100644 (file)
@@ -66,6 +66,7 @@ private:
   void         OnAutoColor();
   void         OnDisableAutoColor();
   void         OnColor();
+  void         OnTexture();
   void         OnTransparency();
   void         OnNbIsos( ActionType actionType = SHOWDLG );
   void         OnDeflection();
index f9d1c20b072f1eef8c4d1a6bc1cdd935a633cf16..cb3497dd1e4463c86160512a181d7aedcadda6cf 100644 (file)
@@ -33,6 +33,7 @@
 #include "GEOMToolsGUI_PublishDlg.h"
 
 #include <GeometryGUI.h>
+#include <GeometryGUI_Operations.h>
 #include <GEOM_Displayer.h>
 
 #include <GEOMBase.h>
@@ -86,6 +87,7 @@
 // QT Includes
 #include <QColorDialog>
 #include <QInputDialog>
+#include <QFileDialog>
 #include <QList>
 
 #include <QGridLayout>
@@ -370,6 +372,49 @@ void GEOMToolsGUI::OnColor()
   app->updateActions(); //SRN: To update a Save button in the toolbar
 }
 
+void GEOMToolsGUI::OnTexture()
+{
+  SALOME_ListIO selected;
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+  if ( app && appStudy ) {
+    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
+    if ( aSelMgr ) {
+      aSelMgr->selectedObjects( selected );
+      if ( !selected.IsEmpty() ) {
+        SUIT_ViewWindow* window = app->desktop()->activeWindow();
+        bool isOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
+        int mgrId = window->getViewManager()->getGlobalId();
+        if ( isOCC ) {
+          QString aTexture = QFileDialog::getOpenFileName(window,tr( "SELECT_IMAGE"),QString("/home"), tr("OCC_IMAGE_FILES"));
+          if( !aTexture.isEmpty() )
+          {
+            SUIT_OverrideCursor();
+            OCCViewer_Viewer* vm = dynamic_cast<OCCViewer_Viewer*> ( window->getViewManager()->getViewModel() );
+            Handle (AIS_InteractiveContext) ic = vm->getAISContext();
+            Handle(AIS_InteractiveObject) io ;
+            for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
+              io = GEOMBase::GetAIS( It.Value(), true );
+              if ( !io.IsNull() ) {   
+                if ( io->IsKind( STANDARD_TYPE(GEOM_AISShape) ) )
+                  Handle(GEOM_AISShape)::DownCast( io )->SetTextureFileName(TCollection_AsciiString(aTexture.toStdString().c_str())); 
+                
+              io->Redisplay( Standard_True );
+              }
+            } // for
+            ic->UpdateCurrentViewer();
+            GeometryGUI::Modified();
+            GeometryGUI* myGeomGUI = getGeometryGUI();
+            myGeomGUI->OnGUIEvent(GEOMOp::OpTexture);
+          } // if ( !selFile.isEmpty() )
+        } // if ( isOCC )
+      } // if ( selection not empty )
+    }
+  }
+
+  app->updateActions(); //SRN: To update a Save button in the toolbar
+}
+
 void GEOMToolsGUI::OnTransparency()
 {
   GEOMToolsGUI_TransparencyDlg dlg( SUIT_Session::session()->activeApplication()->desktop() );