-// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
// GEOM GEOMGUI : GUI for Geometry component
// File : GEOM_Displayer.cxx
#include "GeometryGUI.h"
+#include <GEOM_Constants.h>
#include <GEOM_TypeFilter.h>
#include <GEOM_EdgeFilter.h>
#include <GEOM_FaceFilter.h>
#include <GEOM_Actor.h>
#include <GEOM_AISShape.hxx>
+#include <GEOM_TopWireframeShape.hxx>
#include <GEOM_AISVector.hxx>
#include <GEOM_AISTrihedron.hxx>
#include <GEOM_VTKTrihedron.hxx>
+#include <GEOM_VTKPropertyMaterial.hxx>
+
+#include <Material_Model.h>
#include <SUIT_Desktop.h>
#include <SUIT_ViewWindow.h>
#include <Prs3d_PointAspect.hxx>
#include <StdSelect_TypeOfEdge.hxx>
#include <StdSelect_TypeOfFace.hxx>
+#include <StdSelect_DisplayMode.hxx>
#include <TopoDS_Face.hxx>
#include <BRep_Tool.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Axis2Placement.hxx>
+#include <Graphic3d_AspectFillArea3d.hxx>
#include <gp_Pln.hxx>
#include <TColStd_MapOfInteger.hxx>
#include <TColStd_MapIteratorOfMapOfInteger.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <TopoDS.hxx>
+#include <Prs3d_ShadingAspect.hxx>
+
#include <BRepMesh_IncrementalMesh.hxx>
// VTK Includes
myShadingColor = SalomeApp_Tools::color( col );
myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
+
int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
+ myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
+ myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
+
myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
myColor = -1;
// This color is used for shape displaying. If it is equal -1 then
// default color is used.
+ myTexture = "";
myWidth = -1;
myType = -1;
PropMap aPropMap;
PropMap aDefPropMap;
- if(useStudy){
- aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
- aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
- MergePropertyMaps(aPropMap, aDefPropMap);
- }
-
//Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" );
Handle(GEOM_AISShape) AISShape;
if (myType == GEOM_VECTOR)
// Temporary staff: vertex must be infinite for correct visualization
AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
- // Setup shape properties here ..., e.g. display mode, color, transparency, etc
- if(useStudy) {
- AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
- AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
-
- //Color property
+ if(useStudy){
+ aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
+ aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type());
+ Quantity_Color quant_col;
if(aPropMap.contains(COLOR_PROP)) {
- Quantity_Color quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
+ quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
AISShape->SetShadingColor( quant_col );
} else
useObjColor = true;
+ MergePropertyMaps(aPropMap, aDefPropMap);
+ if(!useObjColor && aPropMap.contains(COLOR_PROP)) {
+ quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value<QColor>());
+ AISShape->SetShadingColor( quant_col );
+ }
+
+ // Setup shape properties here ..., e.g. display mode, color, transparency, etc
+ Standard_Boolean isTopLevel = Standard_False;
+ if(aPropMap.contains(TOP_LEVEL_PROP)) {
+ isTopLevel = aPropMap.value(TOP_LEVEL_PROP).value<Standard_Boolean>();
+ }
+ AISShape->SetDisplayMode( aPropMap.value(DISPLAY_MODE_PROP).toInt() );
+ AISShape->setTopLevel(isTopLevel);
+
+ AISShape->SetDisplayVectors(aPropMap.value(VECTOR_MODE_PROP).toInt());
}else {
AISShape->SetDisplayMode( myDisplayMode );
AISShape->SetShadingColor( myShadingColor );
QStringList uv = anIsos.split(DIGIT_SEPARATOR);
anUIsoNumber = uv[0].toInt();
aVIsoNumber = uv[1].toInt();
- //AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
+ AISShape->SetTransparency(aPropMap.value(TRANSPARENCY_PROP).toDouble());
} else {
anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1);
aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1);
Handle(Prs3d_IsoAspect) anAspect = AISShape->Attributes()->UIsoAspect();
anAspect->SetNumber( anUIsoNumber );
anAspect->SetColor( aColor );
- AISShape->Attributes()->SetUIsoAspect( anAspect );
+ if(HasIsosWidth())
+ anAspect->SetWidth( GetIsosWidth() );
+ AISShape->Attributes()->SetUIsoAspect( anAspect );
anAspect = AISShape->Attributes()->VIsoAspect();
anAspect->SetNumber( aVIsoNumber );
+ if(HasIsosWidth())
+ anAspect->SetWidth( GetIsosWidth() );
anAspect->SetColor( aColor );
AISShape->Attributes()->SetVIsoAspect( anAspect );
useObjMarker = true;
}
}
- }
+ }
else
{
if ( onlyVertex )
anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
anAspect->SetColor( aColor );
AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
+ AISShape->storeBoundaryColors();
// Set free boundaries aspect
col = aResMgr->colorValue( "Geometry", "free_bound_color", QColor( 0, 255, 0 ) );
anAspect->SetColor( aColor );
AISShape->Attributes()->SetWireAspect( anAspect );
+ // Set color for edges in shading
+ col = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
+ aColor = SalomeApp_Tools::color( col );
+ AISShape->SetEdgesInShadingColor( aColor );
+
// bug [SALOME platform 0019868]
// Set deviation angle. Default one is 12 degrees (Prs3d_Drawer.cxx:18)
//AISShape->SetOwnDeviationAngle( 10*PI/180 );
double aDC = 0;
if(useStudy) {
aDC = aPropMap.value(DEFLECTION_COEFF_PROP).toDouble();
+ SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
+ SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
}
else {
aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001);
AISShape->SetOwnDeviationCoefficient(aDC);
}
}
-
+
+ if ( HasTexture() )
+ {
+ AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str()));
+ AISShape->SetTextureMapOn();
+ AISShape->DisableTextureModulate();
+ AISShape->SetDisplayMode(3);
+ }
+
if ( HasWidth() )
AISShape->SetWidth( GetWidth() );
anAspect->SetTypeOfMarker( myTypeOfMarker );
AISShape->Attributes()->SetPointAspect( anAspect );
}
- } else if(!hasColor) {
+ aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, SalomeApp_Tools::color( aQuanColor ) );
+ } else if( !hasColor ) {
//In case if color wasn't defined in the property map of the object
//and GEOM_Object color also wasn't defined get default color from Resource Mgr.
QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
}
}
}
+
+ // get material properties, set material
+ Material_Model material;
+ if ( useStudy ) {
+ // Get material property from study and construct material model
+ material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
+ } else {
+ // Get material property from study and construct material model
+ QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
+ material.fromResources( mname );
+ }
+
+ aStudy->setObjectProperty( aMgrId, anIO->getEntry(), MATERIAL_PROP, material.toProperties() );
+
+ // Set material for the selected shape
+ AISShape->SetMaterial( material.getMaterialOCCAspect() );
+ if(HasWidth())
+ aStudy->setObjectProperty( aMgrId, anIO->getEntry(), EDGE_WIDTH_PROP, GetWidth() );
+ if(HasIsosWidth())
+ aStudy->setObjectProperty( aMgrId, anIO->getEntry(), ISOS_WIDTH_PROP, GetIsosWidth() );
}
+
// AISShape->SetName(???); ??? necessary to set name ???
occPrs->AddObject( AISShape );
-
+
// In accordance with ToActivate() value object will be activated/deactivated
// when it will be displayed
occPrs->SetToActivate( ToActivate() );
+
+ if( AISShape->isTopLevel() && AISShape->topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor) {
+ //21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
+ // Display wireframe presentation additionally
+ Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
+ aWirePrs->SetWidth(AISShape->Width());
+ if ( !myIO.IsNull() ) {
+ aWirePrs->setIO( myIO );
+ aWirePrs->SetOwner( myIO );
+ }
+ occPrs->AddObject(aWirePrs);
+ }
}
}
// if presentation is found -> set again shape for it
return;
bool useStudy = false;
+ bool useObjCol = false;
PropMap aPropMap;
vtkActorCollection* theActors = 0;
+ QString anEntry;
+ if(!myIO.IsNull()) {
+ anEntry = myIO->getEntry();
+ }
+
if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) {
//myToActivate = false; // ouv: commented to make the trihedron pickable (see IPAL18657)
GEOM_VTKTrihedron* aTrh = GEOM_VTKTrihedron::New();
else {
PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type());
- QString anEntry;
if(!myIO.IsNull()) {
aMgrId = getViewManagerId(myViewFrame);
- anEntry = myIO->getEntry();
}
useStudy = !anEntry.isEmpty() && aMgrId != -1;
if(useStudy) {
aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry);
+ if(!aPropMap.contains(COLOR_PROP))
+ useObjCol = true;
MergePropertyMaps(aPropMap, aDefPropMap);
}
}
aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
}
- if ( HasWidth() )
- {
- aProp->SetLineWidth( GetWidth() );
- }
-
while ( anActor != NULL )
{
SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor );
GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor );
if ( aGeomGActor != 0 )
- {
- if ( aProp ) {
- aGeomGActor->SetShadingProperty( aProp );
- aGeomGActor->SetWireframeProperty( aProp );
- }
- int aIsos[2]= { 1, 1 };
- if(useStudy) {
- QString anIsos = aPropMap.value(ISOS_PROP).toString();
- QStringList uv = anIsos.split(DIGIT_SEPARATOR);
- aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
- aGeomGActor->SetNbIsos(aIsos);
- aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
- aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
- aGeomGActor->setDisplayMode(aPropMap.value(DISPLAY_MODE_PROP).toInt());
- aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
-
- vtkFloatingPointType aColor[3] = {1.,0.,0.};
- if(aPropMap.contains(COLOR_PROP)) {
- QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
- aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
- } else { //Get Color from geom object
- Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
- if ( !anIO.IsNull() ) {
- _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->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 );
- bool hasColor = false;
- SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
- if(hasColor) {
- aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
- } else {
- SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
- 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 );
- }
+ {
+ if ( aProp ) {
+ aGeomGActor->SetShadingProperty( aProp );
+ aGeomGActor->SetWireframeProperty( aProp );
+ }
+
+ // Set color for edges in shading
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ if(aResMgr) {
+ QColor c = aResMgr->colorValue( "Geometry", "edges_in_shading_color", QColor( 255, 255, 0 ) );
+ aGeomGActor->SetEdgesInShadingColor( c.red()/255., c.green()/255., c.blue()/255. );
+ }
+
+ int aIsos[2]= { 1, 1 };
+ if(useStudy) {
+ QString anIsos = aPropMap.value(ISOS_PROP).toString();
+ QStringList uv = anIsos.split(DIGIT_SEPARATOR);
+ aIsos[0] = uv[0].toInt(); aIsos[1] = uv[1].toInt();
+ aGeomGActor->SetNbIsos(aIsos);
+ aGeomGActor->SetOpacity(1.0 - aPropMap.value(TRANSPARENCY_PROP).toDouble());
+ SetWidth(aPropMap.value(EDGE_WIDTH_PROP).toInt());
+ SetIsosWidth(aPropMap.value(ISOS_WIDTH_PROP).toInt());
+ aGeomGActor->SetVectorMode(aPropMap.value(VECTOR_MODE_PROP).toInt());
+ int aDispModeId = aPropMap.value(DISPLAY_MODE_PROP).toInt();
+ // Specially processing of 'Shading with edges' mode from preferences,
+ // because there is the following enum in VTK viewer:
+ // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
+ // (see VTKViewer::Representation enum) and the following enum in GEOM_Actor:
+ // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
+ if ( aDispModeId == 2 )
+ // this is 'Shading with edges' mode => do the correct mapping to EDisplayMode
+ // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
+ aDispModeId++;
+ aGeomGActor->setDisplayMode(aDispModeId);
+ aGeomGActor->SetDeflection(aPropMap.value(DEFLECTION_COEFF_PROP).toDouble());
+
+ // Create material model
+ Material_Model material;
+ material.fromProperties( aPropMap.value(MATERIAL_PROP).toString() );
+ // Set material properties for the object
+ aStudy->setObjectProperty( aMgrId, anEntry, MATERIAL_PROP, material.toProperties() );
+ // Set the same front and back materials for the selected shape
+ std::vector<vtkProperty*> aProps;
+ aProps.push_back( material.getMaterialVTKProperty() );
+ aGeomGActor->SetMaterial(aProps);
+
+ vtkFloatingPointType aColor[3] = {1.,0.,0.};
+ if ( useObjCol ) { //Get Color from geom object
+ Handle( SALOME_InteractiveObject ) anIO = aGeomGActor->getIO();
+ if ( !anIO.IsNull() ) {
+ _PTR(SObject) SO ( aStudy->studyDS()->FindObjectID( anIO->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 );
+ bool hasColor = false;
+ SALOMEDS::Color aSColor = getColor(aGeomObject,hasColor);
+ if(hasColor) {
+ aColor[0] = aSColor.R; aColor[1] = aSColor.G; aColor[2] = aSColor.B;
+ } else {
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+ 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, QColor( aColor[0] *255, aColor[1] * 255, aColor[2]* 255) );
}
}
}
+ } else {
+ QColor c = aPropMap.value(COLOR_PROP).value<QColor>();
+ aColor[0] = c.red()/255.; aColor[1] = c.green()/255.; aColor[2] = c.blue()/255.;
+ }
+
+ if ( !material.isPhysical() )
aGeomGActor->SetColor(aColor[0],aColor[1],aColor[2]);
+ }
+ 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 )
GActor->PickableOn();
else
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
myWidth = -1;
}
+
+int GEOM_Displayer::GetIsosWidth() const
+{
+ return myIsosWidth;
+}
+
+void GEOM_Displayer::SetIsosWidth(const int width)
+{
+ myIsosWidth = width;
+}
+
+bool GEOM_Displayer::HasIsosWidth() const
+{
+ return myIsosWidth != -1;
+}
+
+
//=================================================================
/*!
* GEOM_Displayer::SetToActivate
aDefaultMap.insert( DEFLECTION_COEFF_PROP , aDC);
+ //8. Material
+ Material_Model material;
+ QString mname = aResMgr->stringValue( "Geometry", "material", "Plastic" );
+ material.fromResources( mname );
+ aDefaultMap.insert( MATERIAL_PROP, material.toProperties() );
+
+ //9. Width of the edges
+ aDefaultMap.insert( EDGE_WIDTH_PROP , aResMgr->integerValue("Geometry", "edge_width", 1));
+
+
+ //10. Width of iso-lines
+ aDefaultMap.insert( ISOS_WIDTH_PROP , aResMgr->integerValue("Geometry", "isolines_width", 1));
+
+ if(viewer_type == SOCC_Viewer::Type()) {
+
+ aDefaultMap.insert(TOP_LEVEL_PROP, Standard_False);
+ }
+
return aDefaultMap;
}
theOrigin.insert(DEFLECTION_COEFF_PROP, theDefault.value(DEFLECTION_COEFF_PROP));
nbInserted++;
}
+ if(!theOrigin.contains(MATERIAL_PROP)) {
+ theOrigin.insert(MATERIAL_PROP, theDefault.value(MATERIAL_PROP));
+ nbInserted++;
+ }
+
+ if(!theOrigin.contains(EDGE_WIDTH_PROP)) {
+ theOrigin.insert(EDGE_WIDTH_PROP, theDefault.value(EDGE_WIDTH_PROP));
+ nbInserted++;
+ }
+
+ if(!theOrigin.contains(ISOS_WIDTH_PROP)) {
+ theOrigin.insert(ISOS_WIDTH_PROP, theDefault.value(ISOS_WIDTH_PROP));
+ nbInserted++;
+ }
+
+ if(!theOrigin.contains(COLOR_PROP)) {
+ theOrigin.insert(COLOR_PROP, theDefault.value(COLOR_PROP));
+ nbInserted++;
+ }
+
return (nbInserted > 0);
}