From: gdd Date: Wed, 26 Oct 2011 15:40:48 +0000 (+0000) Subject: rnc: added a method to put textures on shapes X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=859f480fc1881215084f11338f0efd59eefca197;p=modules%2Fgeom.git rnc: added a method to put textures on shapes --- diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index e56073134..e49dc8e2d 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -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 ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index 72525fd2f..59498a5e6 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -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 diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index 008d71b86..cc95e6831 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -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; diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.h b/src/GEOMToolsGUI/GEOMToolsGUI.h index bb20a9687..12cead468 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI.h @@ -66,6 +66,7 @@ private: void OnAutoColor(); void OnDisableAutoColor(); void OnColor(); + void OnTexture(); void OnTransparency(); void OnNbIsos( ActionType actionType = SHOWDLG ); void OnDeflection(); diff --git a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx index f9d1c20b0..cb3497dd1 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI_1.cxx @@ -33,6 +33,7 @@ #include "GEOMToolsGUI_PublishDlg.h" #include +#include #include #include @@ -86,6 +87,7 @@ // QT Includes #include #include +#include #include #include @@ -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( 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 ( 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() );