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
This commit is contained in:
gdd 2011-09-22 16:17:52 +00:00
parent 80fcb4b456
commit 1aff347400
4 changed files with 110 additions and 18 deletions

View File

@ -65,10 +65,13 @@
#include <Precision.hxx> #include <Precision.hxx>
#include <set>
#include <utility>
// Constructors // Constructors
enum{ enum{
CORNERS,
CONTOURS, CONTOURS,
CORNERS
}; };
enum { enum {
@ -117,8 +120,8 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
/***************************************************************/ /***************************************************************/
mainFrame()->GroupConstructors->setTitle(tr("GEOM_FEATURES")); mainFrame()->GroupConstructors->setTitle(tr("GEOM_FEATURES"));
mainFrame()->RadioButton1->setText(tr("GEOM_CORNERS")); mainFrame()->RadioButton1->setText(tr("GEOM_CONTOURS"));
mainFrame()->RadioButton2->setText(tr("GEOM_CONTOURS")); mainFrame()->RadioButton2->setText(tr("GEOM_CORNERS"));
// mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); // mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
// mainFrame()->RadioButton2->close(); // mainFrame()->RadioButton2->close();
// mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); // mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
@ -140,7 +143,7 @@ EntityGUI_FeatureDetectorDlg::EntityGUI_FeatureDetectorDlg( GeometryGUI* theGeom
myPushButton->setIcon(image0); myPushButton->setIcon(image0);
myPushButton->setCheckable(true); myPushButton->setCheckable(true);
mySnapshotLabel = new QLabel(tr("GEOM_DETECT_ZONE"), mySelectionGroup); mySnapshotLabel = new QLabel(mySelectionGroup);
mySelectGrpLayout->addWidget(mySnapshotLabel, 0); mySelectGrpLayout->addWidget(mySnapshotLabel, 0);
mySelectGrpLayout->addWidget(myPushButton, 0); mySelectGrpLayout->addWidget(myPushButton, 0);
mySelectGrpLayout->addStretch(1); mySelectGrpLayout->addStretch(1);
@ -268,7 +271,7 @@ void EntityGUI_FeatureDetectorDlg::Init()
myY2->setEnabled(false); myY2->setEnabled(false);
myZ2->setEnabled(false); myZ2->setEnabled(false);
initName(tr("GEOM_CORNERS")); initName(tr("GEOM_CONTOURS"));
resize(100,100); resize(100,100);
myViewGroup->RadioButton1->setChecked(true); myViewGroup->RadioButton1->setChecked(true);
@ -285,6 +288,8 @@ void EntityGUI_FeatureDetectorDlg::Init()
myGeomGUI->SetWorkingPlane( aGlobalCS ); myGeomGUI->SetWorkingPlane( aGlobalCS );
myGeomGUI->ActiveWorkingPlane(); myGeomGUI->ActiveWorkingPlane();
ConstructorsClicked(myConstructorId);
// SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow(); // SUIT_ViewWindow* theViewWindow = getDesktop()->activeWindow();
// OCCViewer_Viewer* anOCCViewer = ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); // OCCViewer_Viewer* anOCCViewer = ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
// OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); // 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() GEOM::GEOM_IOperations_ptr EntityGUI_FeatureDetectorDlg::createOperation()
{ {
// if (myConstructorId == CORNERS) GEOM::GEOM_IOperations_ptr anOp;
return myGeomGUI->GetGeomGen()->GetIShapesOperations( getStudyId() ); if (myConstructorId == CORNERS || myConstructorId == CONTOURS)
// else anOp=myGeomGUI->GetGeomGen()->GetIShapesOperations( getStudyId() );
// return myGeomGUI->GetGeomGen()->GetICurvesOperations( 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(); GEOM::ListOfGO_var geomContourPnts = new GEOM::ListOfGO();
geomContourPnts->length( contour.size() ); geomContourPnts->length( contour.size() );
std::cout<<"repere1"<<std::endl;
int j = 0; int j = 0;
std::set< std::vector<int> > existing_points;
std::pair< std::set< std::vector<int> >::iterator,bool > pnt_it;
for ( it=contour.begin() ; it < contour.end(); it++ ) for ( it=contour.begin() ; it < contour.end(); it++ )
{ {
// gp_Pnt aContourPnt = EntityGUI::ConvertClickToPoint(viewLeft + it->x*imgZoomRatio, viewTop + it->y*imgZoomRatio, vp->getView()); // 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(); // double z = aContourPnt.Z();
// When using the new way with textures on shapes we just have to do the following // 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<int> 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 x = it->x;
double y = height - it->y; double y = height - it->y;
double z = 0; double z = 0;
aGeomContourPnt = aBasicOperations->MakePointXYZ( x,y,z ); aGeomContourPnt = aBasicOperations->MakePointXYZ( x,y,z );
geomContourPnts[j] = aGeomContourPnt; geomContourPnts[j] = aGeomContourPnt;
j++; j++;
// }
} }
std::cout<<"repere2"<<std::endl;
GEOM::GEOM_Object_var aWire = aCurveOperations->MakePolyline(geomContourPnts.in(), false); GEOM::GEOM_Object_var aWire = aCurveOperations->MakePolyline(geomContourPnts.in(), false);
// GEOM::GEOM_Object_var aContourCompound = aShapesOperations->MakeCompound(geomContourPnts);
// GEOM::GEOM_Object_var aWire = aCurveOperations->MakeSplineInterpolation(geomContourPnts.in(), false, true); // GEOM::GEOM_Object_var aWire = aCurveOperations->MakeSplineInterpolation(geomContourPnts.in(), false, true);
std::cout<<"repere3"<<std::endl;
if ( !aWire->_is_nil() ) if ( !aWire->_is_nil() )
{ {
geomContours->length(contourCount + 1); geomContours->length(contourCount + 1);
@ -694,15 +708,48 @@ bool EntityGUI_FeatureDetectorDlg::execute( ObjectList& objects )
contourCount++; contourCount++;
// objects.push_back( aWire._retn() ); // 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 = "<<contourCount<<std::endl;
GEOM::GEOM_Object_var aContoursCompound = aShapesOperations->MakeCompound(geomContours); GEOM::GEOM_Object_var aContoursCompound = aShapesOperations->MakeCompound(geomContours);
std::cout<<"repere5"<<std::endl;
if ( !aContoursCompound->_is_nil() ) if ( !aContoursCompound->_is_nil() )
{ {
objects.push_back( aContoursCompound._retn() ); 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 = "<<theImgFileName.toStdString());
if ( !aFace->_is_nil() )
{
objects.push_back( aFace._retn() );
}
res=true; res=true;
} }
// else // else

View File

@ -142,9 +142,11 @@ void GEOMBase_Helper::display( GEOM::GEOM_Object_ptr object, const bool updateVi
{ {
// Unset color of shape ( this color may be set during preview displaying ) // Unset color of shape ( this color may be set during preview displaying )
// Default color will be used // Default color will be used
getDisplayer()->UnsetColor(); // getDisplayer()->UnsetColor();
getDisplayer()->UnsetWidth(); getDisplayer()->UnsetWidth();
MESSAGE("GEOMBase_Helper::display myTexture = "<<getDisplayer()->GetTexture())
// Enable activisation of selection // Enable activisation of selection
getDisplayer()->SetToActivate( true ); getDisplayer()->SetToActivate( true );
@ -832,9 +834,7 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
bool result = false; bool result = false;
try { try {
MESSAGE("publish ="<<publish<<"useTransaction ="<<useTransaction)
if ( ( !publish && !useTransaction ) || openCommand() ) { if ( ( !publish && !useTransaction ) || openCommand() ) {
MESSAGE("Entered the if")
SUIT_OverrideCursor wc; SUIT_OverrideCursor wc;
SUIT_Session::session()->activeApplication()->putInfo( "" ); SUIT_Session::session()->activeApplication()->putInfo( "" );
ObjectList objects; ObjectList objects;

View File

@ -87,6 +87,8 @@
#include <TopTools_ListIteratorOfListOfShape.hxx> #include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopoDS.hxx> #include <TopoDS.hxx>
#include <Prs3d_ShadingAspect.hxx>
// VTK Includes // VTK Includes
#include <vtkActorCollection.h> #include <vtkActorCollection.h>
#include <vtkProperty.h> #include <vtkProperty.h>
@ -312,6 +314,7 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
myColor = -1; myColor = -1;
// This color is used for shape displaying. If it is equal -1 then // This color is used for shape displaying. If it is equal -1 then
// default color is used. // default color is used.
myTexture = "";
myWidth = -1; myWidth = -1;
myType = -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() = "<<AISShape->TextureFile())
}
else else
{ {
if ( onlyVertex ) if ( onlyVertex )
@ -1518,6 +1532,31 @@ void GEOM_Displayer::UnsetColor()
myShadingColor = SalomeApp_Tools::color( col ); 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 * GEOM_Displayer::SetWidth

View File

@ -124,6 +124,11 @@ public:
int GetColor () const; int GetColor () const;
bool HasColor () 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. */ /* Set width for shape displaying. If it is equal -1 then default width is used. */
void SetWidth ( const double ); void SetWidth ( const double );
void UnsetWidth(); void UnsetWidth();
@ -202,6 +207,7 @@ protected:
Handle(SALOME_InteractiveObject) myIO; Handle(SALOME_InteractiveObject) myIO;
TopoDS_Shape myShape; TopoDS_Shape myShape;
std::string myName; std::string myName;
std::string myTexture;
int myType; int myType;
SALOME_View* myViewFrame; SALOME_View* myViewFrame;