From 1aff34740068e1e220b394cd161fc2745af33e9e Mon Sep 17 00:00:00 2001 From: gdd Date: Thu, 22 Sep 2011 16:17:52 +0000 Subject: [PATCH] rnc : first try to properly manage textures - SALOME_AISShape inherits now from AIS_TexturedShape instead of AIS_Shape - a bug remains that prevents the proper display of the textures --- .../EntityGUI_FeatureDetectorDlg.cxx | 77 +++++++++++++++---- src/GEOMBase/GEOMBase_Helper.cxx | 6 +- src/GEOMGUI/GEOM_Displayer.cxx | 39 ++++++++++ src/GEOMGUI/GEOM_Displayer.h | 6 ++ 4 files changed, 110 insertions(+), 18 deletions(-) diff --git a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx index 80c89e610..c068d3870 100644 --- a/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx +++ b/src/EntityGUI/EntityGUI_FeatureDetectorDlg.cxx @@ -65,10 +65,13 @@ #include +#include +#include + // Constructors enum{ - CORNERS, CONTOURS, + CORNERS }; enum { @@ -117,8 +120,8 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom /***************************************************************/ mainFrame()->GroupConstructors->setTitle(tr("GEOM_FEATURES")); - mainFrame()->RadioButton1->setText(tr("GEOM_CORNERS")); - mainFrame()->RadioButton2->setText(tr("GEOM_CONTOURS")); + mainFrame()->RadioButton1->setText(tr("GEOM_CONTOURS")); + mainFrame()->RadioButton2->setText(tr("GEOM_CORNERS")); // mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); // mainFrame()->RadioButton2->close(); // mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); @@ -140,7 +143,7 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom myPushButton->setIcon(image0); myPushButton->setCheckable(true); - mySnapshotLabel = new QLabel(tr("GEOM_DETECT_ZONE"), mySelectionGroup); + mySnapshotLabel = new QLabel(mySelectionGroup); mySelectGrpLayout->addWidget(mySnapshotLabel, 0); mySelectGrpLayout->addWidget(myPushButton, 0); mySelectGrpLayout->addStretch(1); @@ -268,7 +271,7 @@ void EntityGUI_FeatureDetectorDlg::Init() myY2->setEnabled(false); myZ2->setEnabled(false); - initName(tr("GEOM_CORNERS")); + initName(tr("GEOM_CONTOURS")); resize(100,100); myViewGroup->RadioButton1->setChecked(true); @@ -285,6 +288,8 @@ void EntityGUI_FeatureDetectorDlg::Init() myGeomGUI->SetWorkingPlane( aGlobalCS ); myGeomGUI->ActiveWorkingPlane(); + ConstructorsClicked(myConstructorId); + // SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow(); // OCCViewer_Viewer* anOCCViewer = ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); // OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); @@ -516,10 +521,12 @@ void EntityGUI_FeatureDetectorDlg::setEndPnt(const QPoint& theEndPnt) //================================================================================= GEOM::GEOM_IOperations_ptr EntityGUI_FeatureDetectorDlg::createOperation() { -// if (myConstructorId == CORNERS) - return myGeomGUI->GetGeomGen()->GetIShapesOperations( getStudyId() ); -// else -// return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() ); + GEOM::GEOM_IOperations_ptr anOp; + if (myConstructorId == CORNERS || myConstructorId == CONTOURS) + anOp=myGeomGUI->GetGeomGen()->GetIShapesOperations( getStudyId() ); + else + anOp=myGeomGUI->GetGeomGen()->GetIBlocksOperations( getStudyId() ); + return anOp; } //================================================================================= @@ -665,8 +672,9 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) GEOM::ListOfGO_var geomContourPnts = new GEOM::ListOfGO(); geomContourPnts->length( contour.size() ); - std::cout<<"repere1"< > existing_points; + std::pair< std::set< std::vector >::iterator,bool > pnt_it; for ( it=contour.begin() ; it < contour.end(); it++ ) { // gp_Pnt aContourPnt = EntityGUI::ConvertClickToPoint(viewLeft + it->x*imgZoomRatio, viewTop + it->y*imgZoomRatio, vp->getView()); @@ -675,18 +683,24 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) // double z = aContourPnt.Z(); // When using the new way with textures on shapes we just have to do the following +// double pnt_array[] = {it->x,it->y}; +// std::vector pnt (pnt_array, pnt_array + sizeof(pnt_array) / sizeof(double) ); +// +// pnt_it=existing_points.insert(pnt); +// if (pnt_it.second == true) +// { +// MESSAGE("point absent du contour insere") double x = it->x; double y = height - it->y; double z = 0; - aGeomContourPnt = aBasicOperations->MakePointXYZ( x,y,z ); geomContourPnts[j] = aGeomContourPnt; j++; +// } } - std::cout<<"repere2"<MakePolyline(geomContourPnts.in(), false); +// GEOM::GEOM_Object_var aContourCompound = aShapesOperations->MakeCompound(geomContourPnts); // GEOM::GEOM_Object_var aWire = aCurveOperations->MakeSplineInterpolation(geomContourPnts.in(), false, true); - std::cout<<"repere3"<_is_nil() ) { geomContours->length(contourCount + 1); @@ -694,15 +708,48 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects ) contourCount++; // objects.push_back( aWire._retn() ); } +// if ( !aContourCompound->_is_nil() ) +// { +// geomContours->length(contourCount + 1); +// geomContours[contourCount] = aContourCompound; +// contourCount++; +// // objects.push_back( aWire._retn() ); +// } } - std::cout<<"repere4, contourCount = "<MakeCompound(geomContours); - std::cout<<"repere5"<_is_nil() ) { objects.push_back( aContoursCompound._retn() ); } + res=true; + } + else if (myConstructorId == 2) + { +// gp_Pnt p1(0,0,0); +// gp_Pnt p2(0,height,0); +// gp_Pnt p3(width,height,0); +// gp_Pnt p4(width,0,0); + + GEOM::GEOM_Object_var P1 = aBasicOperations->MakePointXYZ( 0,0,0 ); + GEOM::GEOM_Object_var P2 = aBasicOperations->MakePointXYZ( 0,height,0 ); + GEOM::GEOM_Object_var P3 = aBasicOperations->MakePointXYZ( width,height,0 ); + GEOM::GEOM_Object_var P4 = aBasicOperations->MakePointXYZ( width,0,0 ); + + GEOM::GEOM_IBlocksOperations_var aBlocksOperations = myGeomGUI->GetGeomGen()->GetIBlocksOperations( getStudyId() ); + GEOM::GEOM_Object_var aFace = aBlocksOperations->MakeQuad4Vertices(P1,P2,P3,P4); + getDisplayer()->SetTexture(theImgFileName.toStdString()); +// getDisplayer()->SetDisplayMode(3); + vp->getView()->SetSurfaceDetail(V3d_TEX_ALL); +// OCCViewer_Viewer* anOCCViewer =((OCCViewer_ViewWindow*)theViewWindow)->getViewManager())->getOCCViewer(); +// Handle(AIS_InteractiveContext) aContext = anOCCViewer->getAISContext(); + + MESSAGE("EntityGUI_FeatureDetectorDlg::execute() theImgFileName = "<_is_nil() ) + { + objects.push_back( aFace._retn() ); + } + res=true; } // else diff --git a/src/GEOMBase/GEOMBase_Helper.cxx b/src/GEOMBase/GEOMBase_Helper.cxx index 313854e0d..71355da4d 100755 --- a/src/GEOMBase/GEOMBase_Helper.cxx +++ b/src/GEOMBase/GEOMBase_Helper.cxx @@ -142,8 +142,10 @@ void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateVi { // Unset color of shape ( this color may be set during preview displaying ) // Default color will be used - getDisplayer()->UnsetColor(); +// getDisplayer()->UnsetColor(); getDisplayer()->UnsetWidth(); + + MESSAGE("GEOMBase_Helper::display myTexture = "<GetTexture()) // Enable activisation of selection getDisplayer()->SetToActivate( true ); @@ -832,9 +834,7 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction ) bool result = false; try { - MESSAGE("publish ="<activeApplication()->putInfo( "" ); ObjectList objects; diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 21cc4e27a..716d2961d 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -87,6 +87,8 @@ #include #include +#include + // VTK Includes #include #include @@ -312,6 +314,7 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st ) myColor = -1; // This color is used for shape displaying. If it is equal -1 then // default color is used. + myTexture = ""; myWidth = -1; myType = -1; @@ -722,6 +725,17 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) } } } + if ( HasTexture() ) + { + MESSAGE("GEOM_Displayer::Update HasTexture() == true") + AISShape->SetTextureMapOn(); + AISShape->DisableTextureModulate(); + AISShape->SetMaterial(Graphic3d_NOM_SATIN); + AISShape->SetDisplayMode( 3 ); + AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str())); +// Attributes()->ShadingAspect() + MESSAGE("AISShape->TextureFile() = "<TextureFile()) + } else { if ( onlyVertex ) @@ -1518,6 +1532,31 @@ void GEOM_Displayer::UnsetColor() myShadingColor = SalomeApp_Tools::color( col ); } +//================================================================= +/*! + * GEOM_Displayer::SetTexture + * Set color for shape displaying. If it is equal -1 then default color is used. + * Available values are from Quantity_NameOfColor enumeration + */ +//================================================================= +void GEOM_Displayer::SetTexture( const std::string& texureFileName ) +{ + if(texureFileName!="") + { + myTexture = texureFileName; + } +} + +bool GEOM_Displayer::HasTexture() const +{ + return myTexture != ""; +} + +std::string GEOM_Displayer::GetTexture() const +{ + return myTexture; +} + //================================================================= /*! * GEOM_Displayer::SetWidth diff --git a/src/GEOMGUI/GEOM_Displayer.h b/src/GEOMGUI/GEOM_Displayer.h index 70f5342a1..30337eaac 100644 --- a/src/GEOMGUI/GEOM_Displayer.h +++ b/src/GEOMGUI/GEOM_Displayer.h @@ -123,6 +123,11 @@ public: void UnsetColor(); int GetColor () const; bool HasColor () const; + + /* Set texture for shape displaying. */ + void SetTexture ( const std::string& ); + bool HasTexture () const; + std::string GetTexture () const; /* Set width for shape displaying. If it is equal -1 then default width is used. */ void SetWidth ( const double ); @@ -202,6 +207,7 @@ protected: Handle(SALOME_InteractiveObject) myIO; TopoDS_Shape myShape; std::string myName; + std::string myTexture; int myType; SALOME_View* myViewFrame; -- 2.39.2