X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMGUI%2FGEOM_Displayer.cxx;h=bd364b92cdc2a3b35c94865f44f1334136307382;hb=12d2cd28a6a9975ca7521f27ca1891f0f82d2323;hp=7d79a2cd5e3f6168cfeb9485463f71003207670a;hpb=6f000dfe28cad33bcf7053913e1a2f24b3fa3e33;p=modules%2Fgeom.git diff --git a/src/GEOMGUI/GEOM_Displayer.cxx b/src/GEOMGUI/GEOM_Displayer.cxx old mode 100644 new mode 100755 index 7d79a2cd5..bd364b92c --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 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 @@ -25,7 +25,6 @@ // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) #include "GEOM_Displayer.h" -#include "GEOMGUI_DimensionProperty.h" #include "GeometryGUI.h" #include @@ -38,14 +37,18 @@ #include #include -#include #include +#include #include #include #include #include #include +#include +#include +#include + #include #include @@ -56,17 +59,17 @@ #include #include -#include - #include #include #include #include #include #include +#include "utilities.h" #include #include +#include "utilities.h" #include #include @@ -79,14 +82,12 @@ #include // OCCT Includes -#include #include #include #include #include #include #include -#include #include #include #include @@ -98,7 +99,6 @@ #include #include #include -#include #include #include #include @@ -108,6 +108,7 @@ #include #include #include +#include #include @@ -133,6 +134,9 @@ // Hard-coded value of shape deflection coefficient for VTK viewer const double VTK_MIN_DEFLECTION = 0.001; +// If the next macro is defined, the deflection coefficient for VTK presentation +// is limited by VTK_MIN_DEFLECTION +//#define LIMIT_DEFLECTION_FOR_VTK // Pixmap caching support namespace @@ -163,7 +167,7 @@ namespace if ( aPixmap.IsNull() ) { QPixmap px(":images/default_texture.png"); if ( !px.isNull() ) - aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() ); + aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() ); } return aPixmap; } @@ -234,8 +238,11 @@ namespace if ( aAISShape.IsNull() ) continue; -#ifdef USE_TEXTURED_SHAPE - const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap(); + const Handle(Graphic3d_TextureMap)& aTexture = aAISShape->Attributes()->ShadingAspect()->Aspect()->TextureMap(); + if ( aTexture.IsNull() ) + continue; + + const Handle(Image_PixMap)& aPixmap = aTexture->GetImage(); if ( aPixmap.IsNull() ) continue; @@ -250,10 +257,22 @@ namespace aPixmapUsersMap.UnBind( aPixmap ); aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) ); } -#endif } } -} + + uint randomize( uint size ) + { + static bool initialized = false; + if ( !initialized ) { + qsrand( QDateTime::currentDateTime().toTime_t() ); + initialized = true; + } + uint v = qrand(); + v = uint( (double)( v ) / RAND_MAX * size ); + v = qMax( uint(0), qMin ( v, size-1 ) ); + return v; + } +} // namespace //================================================================ // Function : getActiveStudy @@ -443,6 +462,7 @@ static std::string getName( GEOM::GEOM_BaseObject_ptr object ) */ //================================================================= GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st ) + : myUpdateColorScale( true ), myIsRedisplayed( false ) { if( st ) myApp = dynamic_cast( st->application() ); @@ -460,34 +480,33 @@ GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st ) myHasDisplayMode = false; 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); - myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.; - myHasTransparency = false; - 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)); + // Next properties provide a way to customize displaying of presentations; + // for instance, this is useful for preview myColor = -1; - // This color is used for shape displaying. If it is equal -1 then - // default color is used. myTexture = ""; - + myNbIsos = -1; myWidth = -1; + myTransparency = -1; myType = -1; + myIsosColor = -1; + myIsosWidth = -1; + + // This parameter is used for activisation/deactivisation (selection) of objects to be displayed myToActivate = true; - // This parameter is used for activisation/deactivisation of objects to be displayed - // 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); - } + // Activate parallel vizualisation by default. + // It can be switched OFF via the environment variable: + // export PARALLEL_VISU=0 + Standard_Boolean parallel_visu = Standard_True; + char* parallel_visu_env = getenv("PARALLEL_VISU"); + if (parallel_visu_env && atoi(parallel_visu_env) == 0) + parallel_visu = Standard_False; + BRepMesh_IncrementalMesh::SetParallelDefault(parallel_visu); myViewFrame = 0; @@ -614,6 +633,8 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO, const bool updateViewer, const bool checkActiveViewer ) { + bool aRedisplayed = myIsRedisplayed; + myIsRedisplayed = true; // Remove the object permanently ( == true) SUIT_Session* ses = SUIT_Session::session(); SUIT_Application* app = ses->activeApplication(); @@ -643,6 +664,7 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO, } } } + myIsRedisplayed = aRedisplayed; } //================================================================= @@ -662,8 +684,23 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO, return; } + bool aRedisplayed = myIsRedisplayed; + myIsRedisplayed = true; Erase( theIO, true, false, theViewFrame ); Display( theIO, theUpdateViewer, theViewFrame ); + myIsRedisplayed = aRedisplayed; + // hide annotations for erased presentation + SUIT_Session* session = SUIT_Session::session(); + SalomeApp_Application* anApp = dynamic_cast( session->activeApplication() ); + GeometryGUI* aModule = dynamic_cast( anApp->activeModule() ); + if ( aModule ) { + if ( !theViewFrame->isVisible( theIO ) ) { + aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast( theViewFrame )); + } + else { + aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(theIO->getEntry()), dynamic_cast( theViewFrame )); + } + } } //================================================================= @@ -692,7 +729,7 @@ void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool QString entry = p->GetEntry(); if ( !entry.isEmpty() ) { if ( vId != -1 ) - aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on ); + aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on ); setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState ); } } @@ -816,18 +853,21 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap // - color for edges in shading+edges mode AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value() ) ); + // - color of labels (textual fields and shape name) + AISShape->SetLabelColor( qColorFromResources( "label_color", QColor( 255, 255, 255 ) ) ); + // set display mode - AISShape->SetDisplayMode( HasDisplayMode() ? - // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function - GetDisplayMode() : - // display mode from properties - propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() ); - - // - face boundaries color - if( AISShape->DisplayMode() == GEOM_AISShape::ShadingWithEdges ) - AISShape->Attributes()->SetFaceBoundaryDraw( Standard_True ); + int displayMode = HasDisplayMode() ? + // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function + GetDisplayMode() : + // display mode from properties + propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt(); + AISShape->SetDisplayMode( displayMode ); + + // - face boundaries color and line width anAspect = AISShape->Attributes()->FaceBoundaryAspect(); anAspect->SetColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value() ) ); + anAspect->SetWidth( HasWidth() ? GetWidth() : propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() ); AISShape->Attributes()->SetFaceBoundaryAspect( anAspect ); // set display vectors flag @@ -837,6 +877,10 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap bool isVerticesMode = propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool(); AISShape->SetDisplayVertices( isVerticesMode ); + // set display name flag + bool isNameMode = propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool(); + AISShape->SetDisplayName( isNameMode ); + // set transparency if( HasTransparency() ) { AISShape->SetTransparency( GetTransparency() ); @@ -851,12 +895,34 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt(); Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect(); Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect(); - uIsoAspect->SetColor( isosColor ); - uIsoAspect->SetWidth( isosWidth ); - uIsoAspect->SetNumber( uIsos ); - vIsoAspect->SetColor( isosColor ); - vIsoAspect->SetWidth( isosWidth ); - vIsoAspect->SetNumber( vIsos ); + + if ( HasIsosColor() ) { + uIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() ); + vIsoAspect->SetColor( (Quantity_NameOfColor)GetIsosColor() ); + } + else { + uIsoAspect->SetColor( isosColor ); + vIsoAspect->SetColor( isosColor ); + } + + if ( HasIsosWidth() ) { + uIsoAspect->SetWidth( GetIsosWidth() ); + vIsoAspect->SetWidth( GetIsosWidth() ); + } + else { + uIsoAspect->SetWidth( isosWidth ); + vIsoAspect->SetWidth( isosWidth ); + } + + if ( HasNbIsos() ) { + uIsoAspect->SetNumber( GetNbIsos() ); + vIsoAspect->SetNumber( GetNbIsos() ); + } + else { + uIsoAspect->SetNumber( uIsos ); + vIsoAspect->SetNumber( vIsos ); + } + AISShape->Attributes()->SetUIsoAspect( uIsoAspect ); AISShape->Attributes()->SetVIsoAspect( vIsoAspect ); @@ -886,7 +952,6 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString(); } -#ifdef USE_TEXTURED_SHAPE Handle(Image_PixMap) aPixmap; if ( !aImagePath.isEmpty() ) aPixmap = cacheTextureFor( aImagePath, AISShape ); @@ -895,14 +960,12 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap // apply image to shape if ( !aPixmap.IsNull() ) { - AISShape->SetTexturePixMap( aPixmap ); - AISShape->SetTextureMapOn(); - AISShape->DisableTextureModulate(); - } - else { - AISShape->SetTextureMapOff(); + AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap( new Graphic3d_Texture2Dmanual( aPixmap ) ); } -#endif + if ( displayMode == GEOM_AISShape::TexturedShape ) + AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn(); + else + AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff(); // set line width AISShape->SetWidth( HasWidth() ? @@ -940,9 +1003,9 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap if ( !aTexture.IsNull() ) { Handle(Prs3d_PointAspect) aTextureAspect = new Prs3d_PointAspect( HasColor() ? - // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function - (Quantity_NameOfColor)GetColor() : - // color from properties + // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function + (Quantity_NameOfColor)GetColor() : + // color from properties SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value() ), aWidth, aHeight, aTexture ); @@ -1008,7 +1071,11 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create ) // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR); ///////////////////////////////////////////////////////////////////////// if ( !actor->getTopo().IsSame( myShape ) ) +#ifdef LIMIT_DEFLECTION_FOR_VTK actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR ); +#else + actor->SetShape( myShape, qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ), myType == GEOM_VECTOR ); +#endif // set material Material_Model material; @@ -1022,16 +1089,25 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create ) // - set number of iso-lines int nbIsos[2]= { 1, 1 }; - QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() ); - nbIsos[0] = isos[0].toInt(); - nbIsos[1] = isos[1].toInt(); + if ( HasNbIsos() ) { + nbIsos[0] = GetNbIsos(); + nbIsos[1] = GetNbIsos(); + } + else { + QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() ); + nbIsos[0] = isos[0].toInt(); + nbIsos[1] = isos[1].toInt(); + } actor->SetNbIsos( nbIsos ); // - set iso-lines width - actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() ); + actor->SetIsosWidth( HasIsosWidth() ? GetIsosWidth() : propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() ); // - set iso-lines color - c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value(); + if ( HasIsosColor() ) + c = SalomeApp_Tools::color( Quantity_Color((Quantity_NameOfColor)GetIsosColor()) ); + else + c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value(); actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() ); // set colors @@ -1070,6 +1146,10 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create ) c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value(); actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() ); + // - color of labels (shape name) + c = colorFromResources( "label_color", QColor( 255, 255, 255 ) ); + actor->SetLabelColor( c.redF(), c.greenF(), c.blueF() ); + // set opacity if( HasTransparency() ) { actor->SetOpacity( 1.0 - GetTransparency() ); @@ -1090,6 +1170,9 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create ) // set display vertices flag actor->SetVerticesMode( propMap.value( GEOM::propertyName( GEOM::Vertices ) ).toBool() ); + // set display name flag + actor->SetNameMode( propMap.value( GEOM::propertyName( GEOM::ShowName ) ).toBool() ); + // set display mode int displayMode = HasDisplayMode() ? // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function @@ -1170,11 +1253,12 @@ void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& t QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) ); int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 ); - double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 ); + QFont aFont = aResMgr->fontValue ( "Geometry", "dimensions_font", QFont("Y14.5M-2009", 14) ); double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 ); bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false ); QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" ); QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" ); + bool aUseText3d = aResMgr->booleanValue( "Geometry", "dimensions_use_text3d", false ); // restore dimension presentation from saved attribute or property data AIS_ListOfInteractive aRestoredDimensions; @@ -1240,10 +1324,12 @@ void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& t aStyle->SetCommonColor( aColor ); aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown ); - aStyle->MakeText3d( Standard_True ); + aStyle->MakeText3d( aUseText3d ); aStyle->MakeTextShaded( Standard_True ); - aStyle->SetExtensionSize( aFontHeight * 0.5 ); - aStyle->TextAspect()->SetHeight( aFontHeight ); + int fsize = aFont.pixelSize() != -1 ? aFont.pixelSize() : aFont.pointSize(); + aStyle->SetExtensionSize( fsize * 0.5 ); + aStyle->TextAspect()->SetFont( aFont.family().toLatin1().data() ); + aStyle->TextAspect()->SetHeight( fsize ); aStyle->ArrowAspect()->SetLength( anArrowLength ); aStyle->LineAspect()->SetWidth( aLineWidth ); aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() ); @@ -1704,6 +1790,7 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry, if ( !GeomObject->_is_nil() ) { + theIO->setName( GeomObject->GetName() ); // finally set shape setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) ); } @@ -1784,7 +1871,7 @@ void GEOM_Displayer::internalReset() * of their sub-shapes (with opened local context for OCC viewer) */ //================================================================= -void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode ) +void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const std::list modes ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); @@ -1801,11 +1888,25 @@ void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& the if (!theIO.IsNull() && !vf->isVisible(theIO)) Display(theIO); SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() ); - vf->LocalSelection( prs, theMode ); + vf->LocalSelection( prs, modes ); delete prs; // delete presentation because displayer is its owner } } +//================================================================= +/*! + * GEOM_Displayer::LocalSelection + * Activate selection of CAD shapes with activisation of selection + * of their sub-shapes (with opened local context for OCC viewer) + */ +//================================================================= +void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode ) +{ + std::list modes; + modes.push_back( theMode ); + LocalSelection( theIO, modes ); +} + //================================================================= /*! * GEOM_Displayer::globalSelection @@ -1919,11 +2020,25 @@ void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes, * of their sub-shapes (with opened local context for OCC viewer) */ //================================================================= -void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode ) +void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const std::list modes ) { SALOME_ListIteratorOfListIO Iter( theIOList ); for ( ; Iter.More(); Iter.Next() ) - LocalSelection( Iter.Value(), theMode ); + LocalSelection( Iter.Value(), modes ); +} + +//================================================================= +/*! + * GEOM_Displayer::LocalSelection + * Activate selection of CAD shapes with activisation of selection + * of their sub-shapes (with opened local context for OCC viewer) + */ +//================================================================= +void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode ) +{ + std::list modes; + modes.push_back( theMode ); + LocalSelection( theIOList, modes ); } //================================================================= @@ -1942,14 +2057,26 @@ void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* ) if ( !ic.IsNull() ) { if ( ic->HasOpenedContext() ) - ic->CloseAllContexts(); + ic->CloseAllContexts(Standard_True); } } } void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p ) { - UpdateColorScale(false,false); + UpdateColorScale(); + + // visualize annotations for displayed presentation + SUIT_Session* session = SUIT_Session::session(); + SalomeApp_Application* anApp = dynamic_cast( session->activeApplication() ); + GeometryGUI* aModule = dynamic_cast( anApp->activeModule() ); + if ( aModule ) { + if ( !myIsRedisplayed ) { + aModule->GetAnnotationMgr()->DisplayVisibleAnnotations(QString(p->GetEntry()), dynamic_cast( v )); + } else { + aModule->GetAnnotationMgr()->UpdateVisibleAnnotations(QString(p->GetEntry()), dynamic_cast( v )); + } + } } void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p ) @@ -1961,7 +2088,16 @@ void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p ) void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p ) { LightApp_Displayer::AfterErase( v, p ); - UpdateColorScale(false,false); + UpdateColorScale(); + + if ( !myIsRedisplayed ) { + // hide annotations for erased presentation + SUIT_Session* session = SUIT_Session::session(); + SalomeApp_Application* anApp = dynamic_cast( session->activeApplication() ); + GeometryGUI* aModule = dynamic_cast( anApp->activeModule() ); + if ( aModule ) + aModule->GetAnnotationMgr()->EraseVisibleAnnotations(QString(p->GetEntry()), dynamic_cast( v )); + } } //================================================================= @@ -2009,15 +2145,9 @@ void GEOM_Displayer::UnsetColor() //================================================================= double GEOM_Displayer::SetTransparency( const double transparency ) { - double aPrevTransparency = myTransparency; - if ( transparency < 0 ) { - UnsetTransparency(); - } - else { - myTransparency = transparency; - myHasTransparency = true; - } - return aPrevTransparency; + double prevTransparency = myTransparency; + myTransparency = transparency; + return prevTransparency; } //================================================================= @@ -2039,7 +2169,7 @@ double GEOM_Displayer::GetTransparency() const //================================================================= bool GEOM_Displayer::HasTransparency() const { - return myHasTransparency; + return myTransparency >= 0; } //================================================================= @@ -2050,27 +2180,17 @@ bool GEOM_Displayer::HasTransparency() const //================================================================= double GEOM_Displayer::UnsetTransparency() { - double aPrevTransparency = myTransparency; - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - myTransparency = resMgr->integerValue("Geometry", "transparency", 0) / 100.; - myHasTransparency = false; - return aPrevTransparency; + return SetTransparency( -1 ); } - //================================================================= /*! * 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; - } + myTexture = texureFileName; } bool GEOM_Displayer::HasTexture() const @@ -2109,7 +2229,6 @@ void GEOM_Displayer::UnsetWidth() myWidth = -1; } - int GEOM_Displayer::GetIsosWidth() const { return myIsosWidth; @@ -2125,6 +2244,49 @@ bool GEOM_Displayer::HasIsosWidth() const return myIsosWidth != -1; } +int GEOM_Displayer::SetNbIsos( const int nbIsos ) +{ + int prevNbIsos = myNbIsos; + myNbIsos = nbIsos; + return prevNbIsos; +} + +int GEOM_Displayer::UnsetNbIsos() +{ + return SetNbIsos( -1 ); +} + +int GEOM_Displayer::GetNbIsos() const +{ + return myNbIsos; +} + +bool GEOM_Displayer::HasNbIsos() const +{ + return myNbIsos >= 0; +} + +int GEOM_Displayer::SetIsosColor( const int color ) +{ + int prevColor = myIsosColor; + myIsosColor = color; + return prevColor; +} + +int GEOM_Displayer::GetIsosColor() const +{ + return myIsosColor; +} + +bool GEOM_Displayer::HasIsosColor() const +{ + return myIsosColor != -1; +} + +int GEOM_Displayer::UnsetIsosColor() +{ + return SetIsosColor( -1 ); +} //================================================================= /*! @@ -2261,7 +2423,7 @@ SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor() } } - static int currentColor = 0; + static int currentColor = randomize( colors.size() ); SALOMEDS::Color color; color.R = (double)colors[currentColor].red() / 255.0; @@ -2433,7 +2595,7 @@ PropMap GEOM_Displayer::getDefaultPropertyMap() // - transparency (opacity = 1-transparency) propMap.insert( GEOM::propertyName( GEOM::Transparency ), - resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. ); + resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. ); // - display mode (take default value from preferences) propMap.insert( GEOM::propertyName( GEOM::DisplayMode ), @@ -2445,6 +2607,9 @@ PropMap GEOM_Displayer::getDefaultPropertyMap() // - show vertices flag (false by default) propMap.insert( GEOM::propertyName( GEOM::Vertices ), false ); + // - show name flag (false by default) + propMap.insert( GEOM::propertyName( GEOM::ShowName ), false ); + // - shading color (take default value from preferences) propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) ); @@ -2789,7 +2954,7 @@ QList GEOM_Displayer::groupFieldData( const QList& theFieldS { QColor aQColor; Quantity_Color aColor; - if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) ) + if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) ) aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() ); aResultList << aQColor; } @@ -2797,187 +2962,91 @@ QList GEOM_Displayer::groupFieldData( const QList& theFieldS return aResultList; } -// Note: the method is copied from Aspect_ColorScale class -Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue, - const Standard_Integer aMin, - const Standard_Integer aMax ) +void GEOM_Displayer::UpdateColorScale() { - Standard_Integer minLimit( 0 ), maxLimit( 230 ); - - Standard_Integer aHue = maxLimit; - if ( aMin != aMax ) - aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) ); - - aHue = Min( Max( minLimit, aHue ), maxLimit ); - - return aHue; -} - -// Note: the method is copied from Aspect_ColorScale class -Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue, - const Standard_Real aMin, - const Standard_Real aMax, - const Standard_Integer ColorsCount, - Quantity_Color& aColor ) -{ - if( aValueaMax || aMaxaMax ) - IntervNumber = ColorsCount-1; - else if( Abs( aMax-aMin ) > Precision::Approximation() ) - IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor' - - Standard_Integer Interv = Standard_Integer( IntervNumber ); - - aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS ); - - return Standard_True; - } -} - -void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer ) -{ - SalomeApp_Study* aStudy = dynamic_cast( myApp->activeStudy() ); - if( !aStudy ) - return; - - SOCC_Viewer* aViewModel = dynamic_cast( GetActiveView() ); - if( !aViewModel ) - return; - - Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d(); - if( aViewer.IsNull() ) + if ( !myUpdateColorScale ) return; - aViewer->InitActiveViews(); - if( !aViewer->MoreActiveViews() ) - return; - - Handle(V3d_View) aView = aViewer->ActiveView(); - if( aView.IsNull() ) - return; + SUIT_Session* session = SUIT_Session::session(); + SUIT_Application* app = session->activeApplication(); + if ( !app ) return; - Standard_Boolean anIsDisplayColorScale = Standard_False; - TCollection_AsciiString aColorScaleTitle; - Standard_Real aColorScaleMin = 0, aColorScaleMax = 0; - Standard_Boolean anIsBoolean = Standard_False; + Handle(SALOME_InteractiveObject) io = myApp->selectionMgr()->soleSelectedObject(); - SALOME_ListIO aSelectedObjects; - myApp->selectionMgr()->selectedObjects( aSelectedObjects ); - if( aSelectedObjects.Extent() == 1 ) + QList windows = app->desktop()->windows(); + foreach( SUIT_ViewWindow* window, windows ) { - Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First(); - if( !anIO.IsNull() ) + OCCViewer_ViewWindow* occWindow = dynamic_cast( window ); + if ( !occWindow ) continue; + if ( !occWindow->getViewManager() ) continue; + if ( !window->getViewManager() ) continue; + if ( !window->getViewManager()->getViewModel() ) continue; + SOCC_Viewer* view = dynamic_cast( window->getViewManager()->getViewModel() ); + if ( !view ) continue; + Handle(V3d_Viewer) viewer = view->getViewer3d(); + if ( !io.IsNull() && view->isVisible( io ) ) { - SOCC_Prs* aPrs = dynamic_cast( aViewModel->CreatePrs( anIO->getEntry() ) ); - if( aPrs ) + bool visible = false; + SOCC_Prs* prs = dynamic_cast( view->CreatePrs( io->getEntry() ) ); + if ( prs ) { - AIS_ListOfInteractive aList; - aPrs->GetObjects( aList ); - AIS_ListIteratorOfListOfInteractive anIter( aList ); - for( ; anIter.More(); anIter.Next() ) + AIS_ListOfInteractive presentations; + prs->GetObjects( presentations ); + AIS_ListIteratorOfListOfInteractive iter( presentations ); + for ( ; iter.More(); iter.Next() ) { - Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() ); - if( !aShape.IsNull() ) + Handle(GEOM_AISShape) shape = Handle(GEOM_AISShape)::DownCast( iter.Value() ); + if ( shape.IsNull() ) continue; + GEOM::field_data_type fieldDataType; + int fieldDimension; + QList fieldStepData; + TCollection_AsciiString fieldStepName; + Standard_Real fieldStepRangeMin, fieldStepRangeMax; + shape->getFieldStepInfo( fieldDataType, fieldDimension, fieldStepData, + fieldStepName, fieldStepRangeMin, fieldStepRangeMax ); + visible = !fieldStepData.isEmpty() && fieldDataType != GEOM::FDT_String; + if ( visible ) { - GEOM::field_data_type aFieldDataType; - int aFieldDimension; - QList aFieldStepData; - TCollection_AsciiString aFieldStepName; - double aFieldStepRangeMin, aFieldStepRangeMax; - aShape->getFieldStepInfo( aFieldDataType, - aFieldDimension, - aFieldStepData, - aFieldStepName, - aFieldStepRangeMin, - aFieldStepRangeMax ); - if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String ) - { - anIsDisplayColorScale = Standard_True; - aColorScaleTitle = aFieldStepName; - aColorScaleMin = aFieldStepRangeMin; - aColorScaleMax = aFieldStepRangeMax; - anIsBoolean = aFieldDataType == GEOM::FDT_Bool; - } - } + SUIT_Session* session = SUIT_Session::session(); + SUIT_ResourceMgr* resMgr = session->resourceMgr(); + + Standard_Real xPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 ); + Standard_Real yPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 ); + Standard_Real width = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 ); + Standard_Real height = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 ); + Standard_Integer textHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 ); + Standard_Integer nbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 ); + + Standard_Integer viewWidth = 0, viewHeight = 0; + occWindow->getView(0)->getViewPort()->getView()->Window()->Size( viewWidth, viewHeight ); + + Handle(AIS_ColorScale) colorScale = view->getColorScale(); + + colorScale->SetPosition( viewWidth * xPos, viewHeight * yPos ); + colorScale->SetBreadth( viewWidth * width ); + colorScale->SetHeight( viewHeight * height ); + colorScale->SetRange( fieldStepRangeMin, fieldStepRangeMax ); + colorScale->SetNumberOfIntervals( fieldDataType == GEOM::FDT_Bool ? 2 : nbIntervals ); + colorScale->SetTextHeight( textHeight ); + colorScale->SetTitle( fieldStepName ); + } // if ( visible ) } } - } - } - - if( anIsDisplayColorScale ) - { - Handle(Aspect_ColorScale) aColorScale = aView->ColorScale(); - if( !aColorScale.IsNull() ) + view->setColorScaleShown( visible ); + } // if ( view->isVisible( io ) ) + else { - SUIT_Session* session = SUIT_Session::session(); - SUIT_ResourceMgr* resMgr = session->resourceMgr(); - - Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 ); - Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 ); - Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 ); - Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 ); - Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 ); - Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 ); - - aColorScale->SetXPosition( anXPos ); - aColorScale->SetYPosition( anYPos ); - aColorScale->SetWidth( aWidth ); - aColorScale->SetHeight( aHeight ); - - aColorScale->SetTextHeight( aTextHeight ); - aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals ); - - aColorScale->SetTitle( aColorScaleTitle ); - aColorScale->SetRange( aColorScaleMin, aColorScaleMax ); + view->setColorScaleShown( false ); } - if( !aView->ColorScaleIsDisplayed() ) - aView->ColorScaleDisplay(); - } - else - { - if( aView->ColorScaleIsDisplayed() ) - aView->ColorScaleErase(); - } + } // foreach( SUIT_ViewWindow* window, windows ) +} - if( theIsRedisplayFieldSteps ) - { - _PTR(Study) aStudyDS = aStudy->studyDS(); - QList vmList; - myApp->viewManagers( vmList ); - for( QList::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ ) - { - if( SUIT_ViewManager* aViewManager = *vmIt ) - { - const ObjMap& anObjects = aStudy->getObjectProperties( aViewManager->getGlobalId() ); - for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ ) - { - _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) ); - if( aSObj ) - { - CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj ); - if( !CORBA::is_nil( anObject ) ) - { - GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject ); - if( !aFieldStep->_is_nil() ) - { - CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry(); - Handle(SALOME_InteractiveObject) aStepIO = - new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" ); - Redisplay( aStepIO, false, false ); - } - } - } - } - } - } - } - if(updateViewer) - UpdateViewer(); +bool GEOM_Displayer::SetUpdateColorScale( bool toUpdate ) // IPAL54049 +{ + bool previous = myUpdateColorScale; + myUpdateColorScale = toUpdate; + if ( myUpdateColorScale && !previous ) + UpdateColorScale(); + return previous; } +