X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMGUI%2FGEOM_Displayer.cxx;h=7edbae5b250419101084af6f93bee54c5481c7d6;hb=bed71e55e89040080f5b0ca691d9654b59a26a0d;hp=6e3be0c5a1990a36b666578114084d9efee5274a;hpb=207dcdd566eef37c71ea838b613eac2de139f129;p=modules%2Fgeom.git diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx index 6e3be0c5a..7edbae5b2 100644 --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -1,32 +1,34 @@ -// Copyright (C) 2007-2008 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 +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // GEOM GEOMGUI : GUI for Geometry component // File : GEOM_Displayer.cxx // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -// + #include "GEOM_Displayer.h" #include "GeometryGUI.h" +#include #include #include #include @@ -36,11 +38,14 @@ #include #include -#include #include +#include #include #include #include +#include + +#include #include #include @@ -48,9 +53,12 @@ #include #include +#include + #include #include #include +#include #include #include @@ -71,15 +79,25 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include #include #include +#include +#include +#include +#include + +#include + +#include // VTK Includes #include @@ -89,9 +107,19 @@ #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) #include + +#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1 +#include +#else #include +#endif -using namespace std; +// If the next macro is defined, autocolor feature works for all sub-shapes; +// if it is undefined, autocolor feature works for groups only +//#define GENERAL_AUTOCOLOR +// Below macro, when uncommented, switches on simplified (more performant) algorithm +// of auto-color picking up +//#define SIMPLE_AUTOCOLOR //================================================================ // Function : getActiveStudy @@ -106,6 +134,14 @@ static inline SalomeApp_Study* getActiveStudy() return 0; } +static inline int getViewManagerId( SALOME_View* theViewFrame) { + SUIT_ViewModel* aModel = dynamic_cast(theViewFrame); + SUIT_ViewManager* aViewMgr = 0; + if (aModel != 0) + aViewMgr = aModel->getViewManager(); + return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId()); +} + //================================================================ // Function : getTopAbsMode // Purpose : Get TopAbs_ShapeEnum value corresponding to the @@ -126,6 +162,35 @@ static inline int getTopAbsMode( const int implType ) } } +int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin ) +{ + if ( shape.IsNull() ) + return TopAbs_SHAPE; + + int ret = shape.ShapeType(); + + if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) { + TopoDS_Iterator it(shape, Standard_True, Standard_False); + for (; it.More(); it.Next()) { + TopoDS_Shape sub_shape = it.Value(); + if ( sub_shape.IsNull() ) continue; + int stype = getMinMaxShapeType( sub_shape, ismin ); + if ( stype == TopAbs_SHAPE ) continue; + if ( ismin && stype > ret ) + ret = stype; + else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) ) + ret = stype; + } + } + + return ret; +} + +bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape ) +{ + return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX; +} + //================================================================ // Function : getFilter // Purpose : Get filter corresponding to the type of object @@ -164,13 +229,13 @@ SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode ) //================================================================ // Function : getComplexFilter -// Purpose : Get compound filter corresponding to the type of +// Purpose : Get compound filter corresponding to the type of // object from GEOMImpl_Types.h //================================================================ SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList* aSubShapes) { GEOM_CompoundFilter* aFilter; - + if(aSubShapes != NULL ) { aFilter = new GEOM_CompoundFilter(getStudy()); QList aTopAbsTypes; @@ -182,7 +247,7 @@ SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList* aSubSh } aFilter->addSubTypes(aTopAbsTypes); } - + return aFilter; } @@ -190,7 +255,7 @@ SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList* aSubSh // Function : getEntry // Purpose : //================================================================ -static string getEntry( GEOM::GEOM_Object_ptr object ) +static std::string getEntry( GEOM::GEOM_Object_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); @@ -200,7 +265,7 @@ static string getEntry( GEOM::GEOM_Object_ptr object ) if ( strcmp(IOR.in(), "") != 0 ) { SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); - _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( string(IOR) ) ); + _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) ); if ( SO ) return SO->GetID(); } @@ -212,7 +277,7 @@ static string getEntry( GEOM::GEOM_Object_ptr object ) // Function : getName // Purpose : //================================================================ -static string getName( GEOM::GEOM_Object_ptr object ) +static std::string getName( GEOM::GEOM_Object_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); @@ -222,7 +287,7 @@ static string getName( GEOM::GEOM_Object_ptr object ) if ( strcmp(IOR.in(), "") != 0 ) { SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy(); - _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( string(IOR) ) ); + _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) ); _PTR(GenericAttribute) anAttr; @@ -258,7 +323,11 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st ) 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)); @@ -266,12 +335,24 @@ 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; myToActivate = true; // This parameter is used for activisation/deactivisation of objects to be displayed + + #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2 + // Activate parallel vizualisation only for testing purpose + // and if the corresponding env variable is set to 1 + char* parallel_visu = getenv("PARALLEL_VISU"); + if (parallel_visu && atoi(parallel_visu)) + { + MESSAGE("Parallel visualisation on"); + BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True); + } + #endif myViewFrame = 0; } @@ -303,13 +384,19 @@ void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO, if ( prs ) { - vf->BeforeDisplay( this ); + vf->BeforeDisplay( this, prs ); vf->Display( prs ); - vf->AfterDisplay( this ); + vf->AfterDisplay( this, prs ); if ( updateViewer ) vf->Repaint(); + int aMgrId = getViewManagerId(vf); + SalomeApp_Study* aStudy = getStudy(); + aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 1 ); + + setVisibilityState(theIO->getEntry(), Qtx::ShownState); + delete prs; // delete presentation because displayer is its owner } } @@ -327,7 +414,7 @@ void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateVie if ( theObj->_is_nil() ) return; - string entry = getEntry( theObj ); + std::string entry = getEntry( theObj ); if ( entry != "" ) { Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()), updateViewer); @@ -353,10 +440,18 @@ void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO, if ( vf ) { SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() ); if ( prs ) { + vf->BeforeErase( this, prs ); vf->Erase( prs, forced ); + vf->AfterErase( this, prs ); if ( updateViewer ) vf->Repaint(); delete prs; // delete presentation because displayer is its owner + + int aMgrId = getViewManagerId(vf); + SalomeApp_Study* aStudy = getStudy(); + aStudy->setObjectProperty(aMgrId, theIO->getEntry(), VISIBILITY_PROP, 0 ); + + setVisibilityState(theIO->getEntry(), Qtx::HiddenState); } } } @@ -371,7 +466,7 @@ void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj, const bool forced, const bool updateViewer ) { - string entry = getEntry( theObj ); + std::string entry = getEntry( theObj ); if ( entry != "" ) { Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()), @@ -537,8 +632,26 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) // if presentation is empty we try to create new one if ( occPrs->IsNull() ) { - if ( !myShape.IsNull() ) - { + SalomeApp_Study* aStudy = getStudy(); + if(!aStudy) + return; + if ( !myShape.IsNull() ) { + + bool onlyVertex = (myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape )); + + QString anEntry; + int aMgrId = -1; + if(!myIO.IsNull()) { + aMgrId = getViewManagerId(myViewFrame); + anEntry = myIO->getEntry(); + } + bool useStudy = !anEntry.isEmpty() && aMgrId != -1; + bool useObjColor = false; + bool useObjMarker = false; + + PropMap aPropMap; + PropMap aDefPropMap; + //Handle(GEOM_AISShape) AISShape = new GEOM_AISShape( myShape, "" ); Handle(GEOM_AISShape) AISShape; if (myType == GEOM_VECTOR) @@ -550,96 +663,214 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) AISShape = new GEOM_AISShape (myShape, ""); } // Temporary staff: vertex must be infinite for correct visualization - AISShape->SetInfiniteState( myShape.Infinite() || myShape.ShapeType() == TopAbs_VERTEX ); + AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines) + + if(useStudy){ + aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry); + aDefPropMap = getDefaultPropertyMap(SOCC_Viewer::Type()); + Quantity_Color quant_col; + if(aPropMap.contains(COLOR_PROP)) { + quant_col = SalomeApp_Tools::color( aPropMap.value(COLOR_PROP).value()); + 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()); + AISShape->SetShadingColor( quant_col ); + } - // Setup shape properties here ..., e.g. display mode, color, transparency, etc - AISShape->SetDisplayMode( myDisplayMode ); - AISShape->SetShadingColor( myShadingColor ); + // 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(); + } + 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 ); + } // Set color and number for iso lines SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); QColor col = aResMgr->colorValue( "Geometry", "isos_color", QColor(int(0.5*255), int(0.5*255), int(0.5*255)) ); Quantity_Color aColor = SalomeApp_Tools::color( col ); - int anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1); - int aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1); + + //get the ISOS number, set transparency if need + int anUIsoNumber, aVIsoNumber; + if(useStudy) { + QString anIsos = aPropMap.value(ISOS_PROP).toString(); + QStringList uv = anIsos.split(DIGIT_SEPARATOR); + anUIsoNumber = uv[0].toInt(); + aVIsoNumber = uv[1].toInt(); + 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 ); if ( HasColor() ) { AISShape->SetColor( (Quantity_NameOfColor)GetColor() ); - if ( myShape.ShapeType() == TopAbs_VERTEX ) + if ( onlyVertex ) { - Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); - anAspect->SetColor( (Quantity_NameOfColor)GetColor() ); - anAspect->SetScale( myScaleOfMarker ); - anAspect->SetTypeOfMarker( myTypeOfMarker ); - AISShape->Attributes()->SetPointAspect( anAspect ); + if(aPropMap.contains(MARKER_TYPE_PROP)) { + QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR); + if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker" + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + int aTypeOfMarker = aList[0].toInt(); + double aScaleOfMarker = aList[1].toDouble(); + anAspect->SetScale( aScaleOfMarker ); + anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1)); + anAspect->SetColor((Quantity_NameOfColor)GetColor()); + AISShape->Attributes()->SetPointAspect(anAspect); + } else { //Custom marker string contains "IdOfTexsture" + int textureId = aList[0].toInt(); + Standard_Integer aWidth, aHeight; +#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1 + Handle(TColStd_HArray1OfByte) aTexture = +#else + Handle(Graphic3d_HArray1OfBytes) aTexture = +#endif + GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight); + if (!aTexture.IsNull()) { + static int TextureId = 0; + Handle(Prs3d_PointAspect) aTextureAspect = + new Prs3d_PointAspect ((Quantity_NameOfColor)GetColor(), + ++TextureId, + aWidth, aHeight, + aTexture); + AISShape->Attributes()->SetPointAspect(aTextureAspect); + } else { + useObjMarker = true; + } + } + } else { + useObjMarker = true; + } } - } + } else { - if ( myShape.ShapeType() == TopAbs_VERTEX ) + if ( onlyVertex ) { col = aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ); aColor = SalomeApp_Tools::color( col ); - - Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); - anAspect->SetColor( aColor ); - anAspect->SetScale( myScaleOfMarker ); - anAspect->SetTypeOfMarker( myTypeOfMarker ); - AISShape->Attributes()->SetPointAspect( anAspect ); + + if(aPropMap.contains(MARKER_TYPE_PROP)) { + QStringList aList = aPropMap.value(MARKER_TYPE_PROP).toString().split(DIGIT_SEPARATOR); + if(aList.size() == 2) { //Standard marker string contains "TypeOfMarker:ScaleOfMarker" + int aTypeOfMarker = aList[0].toInt(); + double aScaleOfMarker = aList[1].toDouble(); + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetScale( aScaleOfMarker ); + anAspect->SetTypeOfMarker((Aspect_TypeOfMarker) (aTypeOfMarker-1) ); + anAspect->SetColor( aColor ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } else { //Custom marker string contains "IdOfTexsture" + int textureId = aList[0].toInt(); + Standard_Integer aWidth, aHeight; +#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1 + Handle(TColStd_HArray1OfByte) aTexture = +#else + Handle(Graphic3d_HArray1OfBytes) aTexture = +#endif + GeometryGUI::getTexture(aStudy, textureId, aWidth, aHeight); + if (!aTexture.IsNull()) { + static int TextureId = 0; + Handle(Prs3d_PointAspect) aTextureAspect = + new Prs3d_PointAspect (aColor, ++TextureId, aWidth, aHeight, aTexture); + AISShape->Attributes()->SetPointAspect( aTextureAspect ); + } else { + useObjMarker = true; + } + } + } else { + useObjMarker = true; + } } - else - { + else { // Set line aspect col = aResMgr->colorValue( "Geometry", "wireframe_color", QColor( 255, 255, 0 ) ); aColor = SalomeApp_Tools::color( col ); - + Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect(); anAspect->SetColor( aColor ); AISShape->Attributes()->SetLineAspect( anAspect ); - + // Set unfree boundaries aspect 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 ) ); aColor = SalomeApp_Tools::color( col ); - + anAspect = AISShape->Attributes()->FreeBoundaryAspect(); anAspect->SetColor( aColor ); AISShape->Attributes()->SetFreeBoundaryAspect( anAspect ); - + // Set wire aspect col = aResMgr->colorValue( "Geometry", "line_color", QColor( 255, 0, 0 ) ); aColor = SalomeApp_Tools::color( col ); - + anAspect = AISShape->Attributes()->WireAspect(); 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 ); // IMP 0020626 - double aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001); + 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); + } + + aDC = std::max( aDC, DEFLECTION_MIN ); // to avoid to small values of the coefficient AISShape->SetOwnDeviationCoefficient(aDC); } } - + + if ( HasTexture() ) + { + AISShape->SetTextureFileName(TCollection_AsciiString(myTexture.c_str())); + AISShape->SetTextureMapOn(); + AISShape->DisableTextureModulate(); + AISShape->SetDisplayMode(3); + } + if ( HasWidth() ) AISShape->SetWidth( GetWidth() ); @@ -660,123 +891,124 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) AISShape->SetOwner( anObj ); } - // Get color and other properties from GEOM_Object - SUIT_Session* session = SUIT_Session::session(); - SUIT_Application* app = session->activeApplication(); - if ( app ) - { - SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); - if ( study ) - { - Handle( SALOME_InteractiveObject ) anIO = AISShape->getIO(); - if ( !anIO.IsNull() ) - { - _PTR(SObject) SO ( study->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 ); - if ( !aGeomObject->_is_nil() ) - { - SALOMEDS::Color aSColor = aGeomObject->GetColor(); - bool hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0; - if( !hasColor && aGeomObject->GetType() == GEOM_GROUP ) // auto color for group - { - GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen(); - GEOM::GEOM_IGroupOperations_var anOperations = aGeomGen->GetIGroupOperations( study->id() ); - GEOM::GEOM_Object_var aMainObject = anOperations->GetMainShape( aGeomObject ); - if ( !aMainObject->_is_nil() && aMainObject->GetAutoColor() ) - { - QList aReservedColors; - - SalomeApp_Application* app = dynamic_cast( app ); - CORBA::String_var IOR = app->orb()->object_to_string( aMainObject ); - if ( strcmp(IOR.in(), "") != 0 ) - { - _PTR(Study) aStudy = study->studyDS(); - _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( string(IOR) ) ); - _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); - for( ; it->More(); it->Next() ) - { - _PTR(SObject) aChildSObject( it->Value() ); - GEOM::GEOM_Object_var aChildObject = - GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject)); - if( CORBA::is_nil( aChildObject ) ) - continue; - - if( aChildObject->GetType() != GEOM_GROUP ) - continue; - - SALOMEDS::Color aReservedColor = aChildObject->GetColor(); - aReservedColors.append( aReservedColor ); - } - } - - aSColor = getUniqueColor( aReservedColors ); - hasColor = true; - } - } - - if( hasColor ) - { - Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); - AISShape->SetColor( aQuanColor ); - AISShape->SetShadingColor( aQuanColor ); - if ( myShape.ShapeType() == TopAbs_VERTEX ) { - Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); - anAspect->SetColor( aQuanColor ); - anAspect->SetScale( myScaleOfMarker ); - anAspect->SetTypeOfMarker( myTypeOfMarker ); - AISShape->Attributes()->SetPointAspect( anAspect ); - } - } - // ... marker type - GEOM::marker_type aType = aGeomObject->GetMarkerType(); - GEOM::marker_size aSize = aGeomObject->GetMarkerSize(); - if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) { - Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 ); - double aMSize = ((int)aSize+1)*0.5; - Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); - anAspect->SetScale( aMSize ); - anAspect->SetTypeOfMarker( aMType ); - Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); - if ( hasColor ) - aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); - anAspect->SetColor( aQuanColor ); - AISShape->Attributes()->SetPointAspect( anAspect ); - } - else if ( aType == GEOM::MT_USER ) { - int aTextureId = aGeomObject->GetMarkerTexture(); - Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); - if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); - Standard_Integer aWidth, aHeight; - Handle(Graphic3d_HArray1OfBytes) aTexture = GeometryGUI::getTexture( getStudy(), aTextureId, aWidth, aHeight ); - if ( !aTexture.IsNull() ) { - static int TextureId = 0; - Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect(aQuanColor, - ++TextureId, - aWidth, aHeight, - aTexture ); - AISShape->Attributes()->SetPointAspect( aTextureAspect ); - } - } + Handle( SALOME_InteractiveObject ) anIO = AISShape->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 && useObjColor) { + Quantity_Color aQuanColor( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + AISShape->SetColor( aQuanColor ); + AISShape->SetShadingColor( aQuanColor ); + if ( onlyVertex ) { + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetColor( aQuanColor ); + anAspect->SetScale( myScaleOfMarker ); + anAspect->SetTypeOfMarker( myTypeOfMarker ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } + 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 ) ); + Quantity_Color aQuanColor = SalomeApp_Tools::color( col ); + AISShape->SetShadingColor( aQuanColor ); + aStudy->setObjectProperty( aMgrId, anIO->getEntry(), COLOR_PROP, col ); + } + + // ... marker type + if(useObjMarker) { + GEOM::marker_type aType = aGeomObject->GetMarkerType(); + GEOM::marker_size aSize = aGeomObject->GetMarkerSize(); + if ( aType > GEOM::MT_NONE && aType < GEOM::MT_USER && aSize > GEOM::MS_NONE && aSize <= GEOM::MS_70 ) { + Aspect_TypeOfMarker aMType = (Aspect_TypeOfMarker)( (int)aType-1 ); + double aMSize = ((int)aSize+1)*0.5; + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetScale( aMSize ); + anAspect->SetTypeOfMarker( aMType ); + Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); + if ( hasColor ) + aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + anAspect->SetColor( aQuanColor ); + AISShape->Attributes()->SetPointAspect( anAspect ); + } + else if ( aType == GEOM::MT_USER ) { + int aTextureId = aGeomObject->GetMarkerTexture(); + Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); + if ( hasColor ) aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + Standard_Integer aWidth, aHeight; +#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1 + Handle(TColStd_HArray1OfByte) aTexture = +#else + Handle(Graphic3d_HArray1OfBytes) aTexture = +#endif + GeometryGUI::getTexture(getStudy(), aTextureId, aWidth, aHeight); + if (!aTexture.IsNull()) { + static int TextureId = 0; + Handle(Prs3d_PointAspect) aTextureAspect = + new Prs3d_PointAspect(aQuanColor, ++TextureId, aWidth, aHeight, aTexture ); + AISShape->Attributes()->SetPointAspect( aTextureAspect ); } + } else { //Use marker from the preferences + Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect(); + anAspect->SetScale( myScaleOfMarker ); + anAspect->SetTypeOfMarker( myTypeOfMarker ); + Quantity_Color aQuanColor = SalomeApp_Tools::color( aResMgr->colorValue( "Geometry", "point_color", QColor( 255, 255, 0 ) ) ); + if ( hasColor ) + aQuanColor = Quantity_Color( aSColor.R, aSColor.G, aSColor.B, Quantity_TOC_RGB ); + anAspect->SetColor( aQuanColor ); + AISShape->Attributes()->SetPointAspect( anAspect ); } } } } + + // 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 @@ -818,19 +1050,29 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) //================================================================= void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) { + SalomeApp_Study* aStudy = getStudy(); + int aMgrId = -1; SVTK_Prs* vtkPrs = dynamic_cast( prs ); - if ( !vtkPrs || myShape.IsNull() ) + + if ( !vtkPrs || myShape.IsNull() || !aStudy) return; + bool useStudy = false; + bool useObjCol = false; + PropMap aPropMap; + vtkActorCollection* theActors = 0; - if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE ) - { + 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(); - if ( HasColor() ) - { + if ( HasColor() ) { Quantity_Color aColor( (Quantity_NameOfColor)GetColor() ); aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() ); } @@ -843,17 +1085,35 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) gp_Ax2 anAx2 = aPlane->Pln().Position().Ax2(); aTrh->SetPlacement( new Geom_Axis2Placement( anAx2 ) ); -// if ( SVTK_Viewer* vf = dynamic_cast( GetActiveView() ) ) -// aTrh->SetSize( 0.5 * vf->GetTrihedronSize() ); + // if ( SVTK_Viewer* vf = dynamic_cast( GetActiveView() ) ) + // aTrh->SetSize( 0.5 * vf->GetTrihedronSize() ); vtkPrs->AddObject( aTrh ); theActors = vtkActorCollection::New(); theActors->AddItem( aTrh ); } - else - { - theActors = GEOM_AssemblyBuilder::BuildActors( myShape, 0, 0, Standard_True, myType == GEOM_VECTOR ); + else { + PropMap aDefPropMap = getDefaultPropertyMap(SVTK_Viewer::Type()); + + if(!myIO.IsNull()) { + aMgrId = getViewManagerId(myViewFrame); + } + useStudy = !anEntry.isEmpty() && aMgrId != -1; + + + theActors = vtkActorCollection::New(); + GEOM_Actor* aGeomActor = GEOM_Actor::New(); + aGeomActor->SetShape(myShape,aDefPropMap.value(DEFLECTION_COEFF_PROP).toDouble(),myType == GEOM_VECTOR); + theActors->AddItem(aGeomActor); + aGeomActor->Delete(); + + if(useStudy) { + aPropMap = aStudy->getObjectPropMap(aMgrId,anEntry); + if(!aPropMap.contains(COLOR_PROP)) + useObjCol = true; + MergePropertyMaps(aPropMap, aDefPropMap); + } } theActors->InitTraversal(); @@ -874,11 +1134,6 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) aProp->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() ); } - if ( HasWidth() ) - { - aProp->SetLineWidth( GetWidth() ); - } - while ( anActor != NULL ) { SALOME_Actor* GActor = SALOME_Actor::SafeDownCast( anActor ); @@ -889,15 +1144,116 @@ void GEOM_Displayer::Update( SALOME_VTKPrs* prs ) { GActor->SetProperty( aProp ); GActor->SetPreviewProperty( aProp ); + } - GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor ); - if ( aGeomGActor != 0 ) - { + GEOM_Actor* aGeomGActor = GEOM_Actor::SafeDownCast( anActor ); + if ( aGeomGActor != 0 ) + { + 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 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(); + 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 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 @@ -934,7 +1290,7 @@ SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj ) return 0; internalReset(); - setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), theObj ) ); + setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) ); myType = theObj->GetType(); // Update presentation @@ -1015,7 +1371,7 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry, if ( !GeomObject->_is_nil() ) { // finally set shape - setShape( GEOM_Client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) ); + setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) ); myType = GeomObject->GetType(); } } @@ -1175,10 +1531,10 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, if ( theModes.Extent() == 1 ) { int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key(); - + if ( aMode == GEOM_COMPOUNDFILTER ) aFilter = getComplexFilter( theSubShapes ); - else + else aFilter = getFilter( aMode ); } else if ( theModes.Extent() > 1 ) @@ -1192,7 +1548,7 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, int aMode = anIter.Key(); if ( aMode == GEOM_COMPOUNDFILTER ) aFilter = getComplexFilter( theSubShapes ); - else + else aFilter = getFilter( aMode ); if ( aFilter ) @@ -1236,7 +1592,7 @@ void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int t * [ Reimplemented from SALOME_Displayer ] */ //================================================================= -void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& ) +void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* ) { SOCC_Viewer* vf = dynamic_cast( v ); if ( vf ) @@ -1250,11 +1606,34 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCViewType& ) } } -void GEOM_Displayer::AfterDisplay( SALOME_View*, const SALOME_OCCViewType& ) +void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p ) { + SalomeApp_Study* aStudy = getStudy(); + if (!aStudy) return; + SOCC_Viewer* vf = dynamic_cast( v ); + if ( vf && !p->IsNull() ) { + int aMgrId = getViewManagerId( vf ); + Handle(AIS_InteractiveContext) ic = vf->getAISContext(); + const SOCC_Prs* prs = dynamic_cast( p ); + if ( !ic.IsNull() && prs ) { + AIS_ListOfInteractive objects; + prs->GetObjects( objects ); + AIS_ListIteratorOfListOfInteractive it( objects ); + for ( ; it.More(); it.Next() ) { + Handle(GEOM_AISShape) sh = Handle(GEOM_AISShape)::DownCast( it.Value() ); + if ( sh.IsNull() ) continue; + Handle(SALOME_InteractiveObject) IO = sh->getIO(); + if ( IO.IsNull() ) continue; + PropMap aPropMap = aStudy->getObjectPropMap( aMgrId, IO->getEntry() ); + if ( aPropMap.contains( TRANSPARENCY_PROP ) ) { + double transparency = aPropMap.value(TRANSPARENCY_PROP).toDouble(); + ic->SetTransparency( sh, transparency, true ); + } + } + } + } } - //================================================================= /*! * GEOM_Displayer::SetColor @@ -1286,12 +1665,37 @@ bool GEOM_Displayer::HasColor() const void GEOM_Displayer::UnsetColor() { myColor = -1; - + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) ); 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 @@ -1318,6 +1722,23 @@ void GEOM_Displayer::UnsetWidth() 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 @@ -1378,9 +1799,9 @@ void GEOM_Displayer::setShape( const TopoDS_Shape& theShape ) myShape = theShape; } -bool GEOM_Displayer::canBeDisplayed( const QString& /*entry*/, const QString& viewer_type ) const +bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const { - return viewer_type==SOCC_Viewer::Type() || viewer_type==SVTK_Viewer::Type(); + return viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type(); } int GEOM_Displayer::SetDisplayMode( const int theMode ) @@ -1409,6 +1830,40 @@ int GEOM_Displayer::UnsetDisplayMode() return aPrevMode; } +SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor() +{ + static QList colors; + + if ( colors.isEmpty() ) { + const int rfactor = 4; // red color component split factor, must be > 0 + const int gfactor = 4; // green color component split factor, must be > 0 + const int bfactor = 3; // blue color component split factor, must be > 0 + // - + // total number of pre-defined colors is defined as + // nbcolors = rfactor * gfactor * bfactor + // NB: all three factors should not have same values + // otherwise all colors will be greyish + + for ( int g = 0; g < gfactor; g++ ) { + for ( int r = 0; r < rfactor; r++ ) { + for ( int b = 0; b < bfactor; b++ ) + colors.append( QColor( qRgb( r * 255 / (rfactor-1), g * 255 / (gfactor-1), b * 255 / (bfactor-1) ) ) ); + } + } + } + + static int currentColor = 0; + + SALOMEDS::Color color; + color.R = (double)colors[currentColor].red() / 255.0; + color.G = (double)colors[currentColor].green() / 255.0; + color.B = (double)colors[currentColor].blue() / 255.0; + + currentColor = (currentColor+1) % colors.count(); + + return color; +} + SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList& theReservedColors ) { int aHue = -1; @@ -1425,12 +1880,12 @@ SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList& th if( aTolerance < 1 ) break; } - //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl; + //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl; aHue = (int)( 360.0 * rand() / RAND_MAX ); - //cout << "Hue = " << aHue << endl; + //std::cout << "Hue = " << aHue << std::endl; - //cout << "Auto colors : "; + //std::cout << "Auto colors : "; bool ok = true; QList::const_iterator it = theReservedColors.constBegin(); QList::const_iterator itEnd = theReservedColors.constEnd(); @@ -1441,21 +1896,21 @@ SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList& th int h, s, v; aQColor.getHsv( &h, &s, &v ); - //cout << h << " "; + //std::cout << h << " "; if( abs( h - aHue ) < aTolerance ) { ok = false; - //cout << "break (diff = " << abs( h - aHue ) << ")"; + //std::cout << "break (diff = " << abs( h - aHue ) << ")"; break; } } - //cout << endl; + //std::cout << std::endl; if( ok ) break; } - //cout << "Hue of the returned color = " << aHue << endl; + //std::cout << "Hue of the returned color = " << aHue << std::endl; QColor aColor; aColor.setHsv( aHue, 255, 255 ); @@ -1466,3 +1921,228 @@ SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList& th return aSColor; } + + + +PropMap GEOM_Displayer::getDefaultPropertyMap(const QString& viewer_type) { + PropMap aDefaultMap; + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + //1. Visibility + aDefaultMap.insert(VISIBILITY_PROP , 1); + + //2. Nb Isos + int anUIsoNumber; + int aVIsoNumber; + if(viewer_type == SOCC_Viewer::Type()) { + anUIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_u", 1); + aVIsoNumber = aResMgr->integerValue("OCCViewer", "iso_number_v", 1); + } else if( viewer_type==SVTK_Viewer::Type()) { + anUIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1); + aVIsoNumber = aResMgr->integerValue("VTKViewer", "iso_number_u", 1); + } + QString anIsos("%1%2%3"); + anIsos = anIsos.arg(anUIsoNumber);anIsos = anIsos.arg(DIGIT_SEPARATOR);anIsos = anIsos.arg(aVIsoNumber); + aDefaultMap.insert(ISOS_PROP , anIsos); + + //3. Transparency + aDefaultMap.insert( TRANSPARENCY_PROP , 0.0 ); + + //4. Display Mode + aDefaultMap.insert( DISPLAY_MODE_PROP , aResMgr->integerValue("Geometry", "display_mode", 0)); + + //5. Vector Mode + aDefaultMap.insert( VECTOR_MODE_PROP , 0); + + //6. Color + QColor col = aResMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) ); + aDefaultMap.insert( COLOR_PROP , col); + + //7. Deflection Coeff + double aDC; + + if(viewer_type == SOCC_Viewer::Type()) { + aDC = aResMgr->doubleValue("Geometry", "deflection_coeff", 0.001); + } else if( viewer_type==SVTK_Viewer::Type()) { + aDC = 0.001; + } + + 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; +} + +bool GEOM_Displayer::MergePropertyMaps(PropMap& theOrigin, PropMap& theDefault) { + int nbInserted = 0; + if(!theOrigin.contains(VISIBILITY_PROP)) { + theOrigin.insert(VISIBILITY_PROP, 0); + nbInserted++; + } + if(!theOrigin.contains(TRANSPARENCY_PROP)) { + theOrigin.insert(TRANSPARENCY_PROP, theDefault.value(TRANSPARENCY_PROP)); + nbInserted++; + } + if(!theOrigin.contains(DISPLAY_MODE_PROP)) { + theOrigin.insert(DISPLAY_MODE_PROP, theDefault.value(DISPLAY_MODE_PROP)); + nbInserted++; + } + if(!theOrigin.contains(ISOS_PROP)) { + theOrigin.insert(ISOS_PROP, theDefault.value(ISOS_PROP)); + nbInserted++; + } + if(!theOrigin.contains(VECTOR_MODE_PROP)) { + theOrigin.insert(VECTOR_MODE_PROP, theDefault.value(VECTOR_MODE_PROP)); + nbInserted++; + } + if(!theOrigin.contains(DEFLECTION_COEFF_PROP)) { + 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); +} + + +SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) { + SALOMEDS::Color aSColor; + hasColor = false; + + SUIT_Session* session = SUIT_Session::session(); + SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); + + if ( app && !theGeomObject->_is_nil()) { + SalomeApp_Study* study = dynamic_cast( app->activeStudy() ); + + if ( study ) { + _PTR(Study) aStudy = study->studyDS(); + aSColor = theGeomObject->GetColor(); + hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0; + if ( !hasColor ) { +#ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes + bool general_autocolor = true; +#else // auto-color for groups only + bool general_autocolor = false; +#endif // GENERAL_AUTOCOLOR + if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) { + GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape(); + if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) { +#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors + aSColor = getPredefinedUniqueColor(); + hasColor = true; +#else // old algorithm for auto-colors + QList aReservedColors; + CORBA::String_var IOR = app->orb()->object_to_string( aMainObject ); + _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) ); + if ( aMainSObject ) { + _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) ); + for ( ; it->More(); it->Next() ) { + _PTR(SObject) aChildSObject( it->Value() ); + GEOM::GEOM_Object_var aChildObject = + GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject)); + if ( CORBA::is_nil( aChildObject ) ) + continue; + + SALOMEDS::Color aReservedColor = aChildObject->GetColor(); + if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 ) + aReservedColors.append( aReservedColor ); + } + } + aSColor = getUniqueColor( aReservedColors ); + hasColor = true; +#endif // SIMPLE_AUTOCOLOR + } + } + } + } + } + return aSColor; +} + + +void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO, + const bool eraseOnlyChildren) { + SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() ); + if ( !app ) + return; + + SalomeApp_Study* appStudy = dynamic_cast( app->activeStudy() ); + if ( !appStudy ) + return; + + LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry()); + + if( !parent) + return; + + // Erase from all views + QList views; + SALOME_View* view; + ViewManagerList vmans = app->viewManagers(); + SUIT_ViewManager* vman; + foreach ( vman, vmans ) { + SUIT_ViewModel* vmod = vman->getViewModel(); + view = dynamic_cast ( vmod ); + if ( view ) + views.append( view ); + } + + if( views.count() == 0 ) + return; + + //Erase childrens w/o update views + DataObjectList listObj = parent->children( true ); + SUIT_DataObject* obj; + foreach( obj, listObj ) { + LightApp_DataObject* l_obj = dynamic_cast(obj); + if(l_obj) + foreach ( view, views ) { + Handle(SALOME_InteractiveObject) anIO = + new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", ""); + Erase(anIO, false, false, view); + } + } + + //Erase parent with view update or repaint views + foreach ( view, views ) { + if(!eraseOnlyChildren) + Erase(theIO, false, true, view); + else + view->Repaint(); + } +}