Fix for the "0021580: GEOM EDF: SetColor does not work" issue.

This commit is contained in:
ana 2012-05-18 13:53:13 +00:00
parent d5971b8b43
commit 17ec6b3223
3 changed files with 110 additions and 111 deletions

View File

@ -1041,6 +1041,7 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
return; return;
bool useStudy = false; bool useStudy = false;
bool useObjCol = false;
PropMap aPropMap; PropMap aPropMap;
vtkActorCollection* theActors = 0; vtkActorCollection* theActors = 0;
@ -1092,6 +1093,8 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
if(useStudy) { if(useStudy) {
aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry); aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
if(!aPropMap.contains(COLOR_PROP))
useObjCol = true;
MergePropertyMaps(aPropMap, aDefPropMap); MergePropertyMaps(aPropMap, aDefPropMap);
} }
} }
@ -1128,111 +1131,111 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor ); GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
if ( aGeomGActor != 0 ) if ( aGeomGActor != 0 )
{ {
if ( aProp ) { if ( aProp ) {
aGeomGActor->SetShadingProperty( aProp ); aGeomGActor->SetShadingProperty( aProp );
aGeomGActor->SetWireframeProperty( aProp ); aGeomGActor->SetWireframeProperty( aProp );
} }
// Set color for edges in shading // Set color for edges in shading
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
if(aResMgr) { if(aResMgr) {
QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) ); QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. ); aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
} }
int aIsos[2]= { 1, 1 }; int aIsos[2]= { 1, 1 };
if(useStudy) { if(useStudy) {
QString anIsos = aPropMap.value(ISOS_PROP).toString(); QString anIsos = aPropMap.value(ISOS_PROP).toString();
QStringList uv = anIsos.split(DIGIT_SEPARATOR); QStringList uv = anIsos.split(DIGIT_SEPARATOR);
aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt(); aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
aGeomGActor->SetNbIsos(aIsos); aGeomGActor->SetNbIsos(aIsos);
aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble()); aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt()); SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt()); SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt()); aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt(); int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
// Specially processing of 'Shading with edges' mode from preferences, // Specially processing of 'Shading with edges' mode from preferences,
// because there is the following enum in VTK viewer: // because there is the following enum in VTK viewer:
// Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
// (see VTKViewer::Representation enum) and the following enum in GEOM_Actor: // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
// eWireframe - 0, eShading - 1, eShadingWithEdges - 3 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
if ( aDispModeId == 2 ) if ( aDispModeId == 2 )
// this is 'Shading with edges' mode => do the correct mapping to EDisplayMode // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
// enum in GEOM_Actor (and further to VTKViewer::Representation enum) // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
aDispModeId++; aDispModeId++;
aGeomGActor->setDisplayMode(aDispModeId); aGeomGActor->setDisplayMode(aDispModeId);
aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble()); aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
// Create material model // Create material model
Material_Model material; Material_Model material;
material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() ); material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
// Set material properties for the object // Set material properties for the object
aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() ); aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
// Set the same front and back materials for the selected shape // Set the same front and back materials for the selected shape
std::vector<vtkProperty*> aProps; std::vector<vtkProperty*> aProps;
aProps.push_back( material.getMaterialVTKProperty() ); aProps.push_back( material.getMaterialVTKProperty() );
aGeomGActor->SetMaterial(aProps); aGeomGActor->SetMaterial(aProps);
vtkFloatingPointType aColor[3] = {1.,0.,0.}; vtkFloatingPointType aColor[3] = {1.,0.,0.};
if(aPropMap.contains(COLOR_PROP)) { if ( useObjCol ) { //Get Color from geom object
QColor c = aPropMap.value(COLOR_PROP).value<QColor>(); Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.; if ( !anIO.IsNull() ) {
} else { //Get Color from geom object _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) );
Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO(); if ( SO ) {
if ( !anIO.IsNull() ) { // get CORBA reference to data object
_PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->getEntry() ) ); CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
if ( SO ) { if ( !CORBA::is_nil( object ) ) {
// get CORBA reference to data object // downcast to GEOM object
CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO); GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
if ( !CORBA::is_nil( object ) ) { bool hasColor = false;
// downcast to GEOM object SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object ); if(hasColor) {
bool hasColor = false; aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor); } else {
if(hasColor) { SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B; if(aResMgr) {
} else { QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
if(aResMgr) {
QColor c = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, c );
}
} }
} }
aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, QColor( aColor[0] *255, aColor[1] * 255, aColor[2]* 255) );
} }
} }
} }
if ( !material.isPhysical() ) } else {
aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]); QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
} }
else {
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
if ( aResMgr ) {
// Create material model
Material_Model material;
// Get material name from resources
QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
material.fromResources( mname );
// Set material properties for the object
aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
// Set material for the selected shape
std::vector<vtkProperty*> aProps;
aProps.push_back( material.getMaterialVTKProperty() );
aGeomGActor->SetMaterial(aProps);
}
}
}
if ( aGeomGActor ) if ( !material.isPhysical() )
{ aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
if ( HasWidth() )
aGeomGActor->SetWidth( GetWidth() );
if ( HasIsosWidth() )
aGeomGActor->SetIsosWidth( GetIsosWidth() );
} }
else {
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
if ( aResMgr ) {
// Create material model
Material_Model material;
// Get material name from resources
QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
material.fromResources( mname );
// Set material properties for the object
aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
// Set material for the selected shape
std::vector<vtkProperty*> aProps;
aProps.push_back( material.getMaterialVTKProperty() );
aGeomGActor->SetMaterial(aProps);
}
}
}
if ( aGeomGActor )
{
if ( HasWidth() )
aGeomGActor->SetWidth( GetWidth() );
if ( HasIsosWidth() )
aGeomGActor->SetIsosWidth( GetIsosWidth() );
}
if ( myToActivate ) if ( myToActivate )
GActor->PickableOn(); GActor->PickableOn();

View File

@ -297,11 +297,22 @@ void GEOMToolsGUI::OnColor()
QString matProp; QString matProp;
matProp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, matProp).toString(); matProp = appStudy->getObjectProperty(mgrId,It.Value()->getEntry(), MATERIAL_PROP, matProp).toString();
Material_Model material; Material_Model material;
material.fromProperties( matProp ); material.fromProperties( matProp );
if ( !material.isPhysical() ) { if ( !material.isPhysical() ) {
aView->SetColor( It.Value(), c ); aView->SetColor( It.Value(), c );
appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c); appStudy->setObjectProperty(mgrId,It.Value()->getEntry(),COLOR_PROP, c);
} }
// store color to GEOM_Object
_PTR(Study) aStudy = appStudy->studyDS();
_PTR(SObject) aSObject( aStudy->FindObjectID( It.Value()->getEntry() ) );
GEOM::GEOM_Object_var anObject =
GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aSObject));
SALOMEDS::Color aSColor;
aSColor.R = (double)c.red() / 255.0;
aSColor.G = (double)c.green() / 255.0;
aSColor.B = (double)c.blue() / 255.0;
anObject->SetColor( aSColor );
anObject->SetAutoColor( false );
} }
GeometryGUI::Modified(); GeometryGUI::Modified();
} }

View File

@ -269,22 +269,7 @@ GEOMToolsGUI_MaterialPropertiesDlg::GEOMToolsGUI_MaterialPropertiesDlg( QWidget*
QString matProp = propMap.value(MATERIAL_PROP).toString(); QString matProp = propMap.value(MATERIAL_PROP).toString();
if ( !matProp.isEmpty() ) if ( !matProp.isEmpty() )
myCurrentModel.fromProperties( matProp ); myCurrentModel.fromProperties( matProp );
QColor c; QColor c = propMap.value(COLOR_PROP).value<QColor>();
if(propMap.contains(COLOR_PROP))
c = propMap.value(COLOR_PROP).value<QColor>();
else {
_PTR(SObject) SO ( study->studyDS()->FindObjectID( io->getEntry() ) );
if ( SO ) {
// get CORBA reference to data object
CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
if ( !CORBA::is_nil( object ) ) {
// downcast to GEOM object
GEOM::GEOM_Object_var aGeomObject = GEOM::GEOM_Object::_narrow( object );
SALOMEDS::Color aSColor = aGeomObject->GetColor();
c.setRgb( 255.*aSColor.R, 255.*aSColor.G, 255.*aSColor.B );
}
}
}
if ( c.isValid() ) if ( c.isValid() )
myColor->setColor( c ); myColor->setColor( c );
} }