X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMGUI%2FGEOM_Displayer.cxx;h=bd364b92cdc2a3b35c94865f44f1334136307382;hb=12d2cd28a6a9975ca7521f27ca1891f0f82d2323;hp=fca01937933bf472db9c3b6a095ce0be0103b75d;hpb=b5c2a231e77bff1a13b68dce0874a2f8f4ee9015;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 fca019379..bd364b92c --- a/src/GEOMGUI/GEOM_Displayer.cxx +++ b/src/GEOMGUI/GEOM_Displayer.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 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 @@ -6,7 +6,7 @@ // 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. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -25,7 +25,6 @@ // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) #include "GEOM_Displayer.h" - #include "GeometryGUI.h" #include @@ -38,13 +37,20 @@ #include #include -#include +#include +#include #include #include #include #include #include +#include +#include +#include + +#include + #include #include @@ -53,18 +59,17 @@ #include #include -#include - #include #include #include #include #include #include +#include "utilities.h" -#include #include #include +#include "utilities.h" #include #include @@ -72,9 +77,17 @@ #include #include +#include +#include +#include + // OCCT Includes -#include +#include +#include +#include +#include #include +#include #include #include #include @@ -86,7 +99,6 @@ #include #include #include -#include #include #include #include @@ -94,6 +106,9 @@ #include #include #include +#include +#include +#include #include @@ -108,11 +123,7 @@ #include -#if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1 #include -#else -#include -#endif // If the next macro is defined, autocolor feature works for all sub-shapes; // if it is undefined, autocolor feature works for groups only @@ -123,6 +134,145 @@ // 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 +{ + typedef NCollection_Map SetOfAISShapes; + typedef NCollection_DataMap PixmapUsageMap; + typedef QMap PixmapCacheMap; + + static inline PixmapUsageMap& getPixmapUsageMap() + { + static PixmapUsageMap aMap; + return aMap; + } + + static inline PixmapCacheMap& getPixmapCacheMap() + { + static PixmapCacheMap aMap; + return aMap; + } + + //=========================================================================== + // Function : getDefaultTexture + // Purpose : Get default texture + //=========================================================================== + static inline Handle(Image_PixMap) getDefaultTexture() + { + static Handle(Image_PixMap) aPixmap; + if ( aPixmap.IsNull() ) { + QPixmap px(":images/default_texture.png"); + if ( !px.isNull() ) + aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() ); + } + return aPixmap; + } + + //=========================================================================== + // Function : cacheTextureFor + // Purpose : Load and cache image for the specified presentation. + //=========================================================================== + static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath, + const Handle(GEOM_AISShape)& theShape ) + { + if ( thePath.isEmpty() ) + return NULL; + + PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap(); + PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap(); + + Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL ); + if ( !aPixmap.IsNull() ) { + // point that the texture is used by the presentation + if ( !aPixmapUsersMap.IsBound( aPixmap ) ) + aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() ); + + aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape ); + + return aPixmap; + } + + // convert texture to compatible image format + QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 ); + if ( anImage.isNull() ) + return NULL; + + aPixmap = OCCViewer_Utilities::imageToPixmap( anImage ); + + aPixmapCacheMap.insert( thePath, aPixmap ); + + if ( !aPixmapUsersMap.IsBound( aPixmap ) ) + aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() ); + + aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape ); + + return aPixmap; + } + + //=========================================================================== + // Function : releaseTextures + // Purpose : Releases cached textures found for the specified presentation. + //=========================================================================== + static inline void releaseTextures( const SALOME_OCCPrs* thePrs ) + { + const SOCC_Prs* anOccPrs = dynamic_cast( thePrs ); + + AIS_ListOfInteractive aListOfIO; + + anOccPrs->GetObjects( aListOfIO ); + + AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO ); + + PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap(); + PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap(); + + for ( ; aIterateIO.More(); aIterateIO.Next() ) + { + Handle(GEOM_AISShape) aAISShape = + Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() ); + + if ( aAISShape.IsNull() ) + continue; + + 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; + + if ( !aPixmapUsersMap.IsBound( aPixmap ) ) + continue; + + SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap ); + + aUsersShapes.Remove( aAISShape ); + + if ( aUsersShapes.IsEmpty() ) { + aPixmapUsersMap.UnBind( aPixmap ); + aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) ); + } + } + } + + 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 @@ -258,7 +408,7 @@ SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList* aSubSh // Function : getEntry // Purpose : //================================================================ -static std::string getEntry( GEOM::GEOM_Object_ptr object ) +static std::string getEntry( GEOM::GEOM_BaseObject_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); @@ -280,7 +430,7 @@ static std::string getEntry( GEOM::GEOM_Object_ptr object ) // Function : getName // Purpose : //================================================================ -static std::string getName( GEOM::GEOM_Object_ptr object ) +static std::string getName( GEOM::GEOM_BaseObject_ptr object ) { SUIT_Session* session = SUIT_Session::session(); SalomeApp_Application* app = dynamic_cast( session->activeApplication() ); @@ -312,6 +462,7 @@ static std::string getName( GEOM::GEOM_Object_ptr object ) */ //================================================================= GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st ) + : myUpdateColorScale( true ), myIsRedisplayed( false ) { if( st ) myApp = dynamic_cast( st->application() ); @@ -329,36 +480,40 @@ 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); - + 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 - #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 + // 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; + + myFieldDataType = GEOM::FDT_Double; + myFieldDimension = 0; + myFieldStepRangeMin = 0; + myFieldStepRangeMax = 0; } //================================================================= @@ -389,18 +544,12 @@ void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO, if ( prs ) { vf->BeforeDisplay( this, prs ); - vf->Display( prs ); + vf->Display( this, prs ); vf->AfterDisplay( this, prs ); if ( updateViewer ) vf->Repaint(); - int aMgrId = getViewManagerId(vf); - SalomeApp_Study* aStudy = getStudy(); - aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 ); - - setVisibilityState(theIO->getEntry(), Qtx::ShownState); - delete prs; // delete presentation because displayer is its owner } } @@ -413,7 +562,7 @@ void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO, * not using dialog boxes. */ //================================================================= -void GEOM_Displayer::Display( GEOM::GEOM_Object_ptr theObj, const bool updateViewer ) +void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer ) { if ( theObj->_is_nil() ) return; @@ -445,17 +594,11 @@ void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO, SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() ); if ( prs ) { vf->BeforeErase( this, prs ); - vf->Erase( prs, forced ); + vf->Erase( this, 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(), GEOM::propertyName( GEOM::Visibility ), 0 ); - - setVisibilityState(theIO->getEntry(), Qtx::HiddenState); } } } @@ -466,15 +609,16 @@ void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO, * Erase geometry object in the current viewer */ //================================================================= -void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj, +void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj, const bool forced, - const bool updateViewer ) + const bool updateViewer, + SALOME_View* theViewFrame) { std::string entry = getEntry( theObj ); if ( entry != "" ) { Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()), - forced, updateViewer); + forced, updateViewer, theViewFrame); } } @@ -486,8 +630,11 @@ void GEOM_Displayer::Erase( GEOM::GEOM_Object_ptr theObj, */ //================================================================= void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO, - const bool updateViewer ) + 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(); @@ -508,16 +655,52 @@ void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO, SALOME_View* view = dynamic_cast(vmodel); if ( view ) { - if ( view->isVisible( theIO ) || view == GetActiveView() ) + if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) ) { - Erase( theIO, true, false, view ); - Display( theIO, updateViewer, view ); + Redisplay( theIO, updateViewer, view ); } } } } } } + myIsRedisplayed = aRedisplayed; +} + +//================================================================= +/*! + * GEOM_Displayer::Redisplay + * Redisplay (erase and then display again) interactive object + * in the specified view + */ +//================================================================= +void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO, + const bool theUpdateViewer, + SALOME_View* theViewFrame ) +{ + SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView(); + if ( !vf ) + { + 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 )); + } + } } //================================================================= @@ -536,6 +719,27 @@ void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateV UpdateViewer(); } +void GEOM_Displayer::UpdateVisibility( SALOME_View* v, const SALOME_Prs* p, bool on ) +{ + SalomeApp_Study* aStudy = getStudy(); + int vId = -1; + if ( v ) vId = getViewManagerId( v ); + + if ( p ) { + QString entry = p->GetEntry(); + if ( !entry.isEmpty() ) { + if ( vId != -1 ) + aStudy->setObjectProperty( vId, entry, GEOM::propertyName( GEOM::Visibility ), on ); + setVisibilityState( entry, on ? Qtx::ShownState : Qtx::HiddenState ); + } + } + else { + if ( vId != -1 ) { + aStudy->setObjectProperty( vId, GEOM::propertyName( GEOM::Visibility ), on ); + } + } +} + Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor ) { // VSR: this method can be improved in future: @@ -648,23 +852,41 @@ 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() ) ); - - // ??? - AISShape->storeBoundaryColors(); + + // - 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() ); + 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 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() ); + // set display vertices flag + 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 - // VSR: ??? next line is commented: transparency property is set in the AfterDisplay() function - //AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() ); + if( HasTransparency() ) { + AISShape->SetTransparency( GetTransparency() ); + } else { + AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() ); + } // set iso properties int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt(); @@ -673,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 ); @@ -687,13 +931,41 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) ); // set texture + QString aImagePath; if ( HasTexture() ) { // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function - AISShape->SetTextureFileName( TCollection_AsciiString( GetTexture().c_str() ) ); - AISShape->SetTextureMapOn(); - AISShape->DisableTextureModulate(); - AISShape->SetDisplayMode( 3 ); + aImagePath = GetTexture().c_str(); + if ( ! entry.isEmpty() ) { + // check that study is active + SalomeApp_Study* study = getActiveStudy(); + if ( study ) { + // Store the texture in object properties for next displays + study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) ); + study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 ); + + // Update propeties map + propMap = getObjectProperties( study, entry, myViewFrame ); + } + } + } + else { + aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString(); + } + + Handle(Image_PixMap) aPixmap; + if ( !aImagePath.isEmpty() ) + aPixmap = cacheTextureFor( aImagePath, AISShape ); + else + aPixmap = getDefaultTexture(); + + // apply image to shape + if ( !aPixmap.IsNull() ) { + AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap( new Graphic3d_Texture2Dmanual( aPixmap ) ); } + if ( displayMode == GEOM_AISShape::TexturedShape ) + AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn(); + else + AISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOff(); // set line width AISShape->SetWidth( HasWidth() ? @@ -706,7 +978,7 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() ); // set point marker (for vertex / compound of vertices only) - if ( onlyVertex ) { + if ( onlyVertex || isVerticesMode ) { QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() ); if ( aList.size() == 2 ) { // standard marker string contains "TypeOfMarker:ScaleOfMarker" @@ -726,42 +998,33 @@ void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShap // custom marker string contains "IdOfTexture" 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( study, textureId, aWidth, aHeight ); if ( !aTexture.IsNull() ) { -#if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version 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 ); -#else - int TextureId = 0; - 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 - SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value() ), - ++TextureId, - aWidth, aHeight, - aTexture ); -#endif AISShape->Attributes()->SetPointAspect( aTextureAspect ); } } } + // set field step data + AISShape->setFieldStepInfo( myFieldDataType, + myFieldDimension, + myFieldStepData, + myFieldStepName, + myFieldStepRangeMin, + myFieldStepRangeMax ); + if ( create && !isTemporary && aMgrId != -1 ) { // set properties to the study - study->setObjectPropMap( aMgrId, entry, propMap ); + study->setObjectProperties( aMgrId, entry, propMap ); } // AISShape->SetName(???); ??? necessary to set name ??? @@ -808,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; @@ -822,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 @@ -850,7 +1126,7 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create ) } // - standalone edge color - c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value(); + c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value(); actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() ); c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value(); @@ -870,8 +1146,16 @@ 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 - actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() ); + if( HasTransparency() ) { + actor->SetOpacity( 1.0 - GetTransparency() ); + } else { + actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() ); + } // set line width actor->SetWidth( HasWidth() ? @@ -883,6 +1167,12 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create ) // set display vectors flag actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() ); + // 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 @@ -908,7 +1198,177 @@ void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create ) if ( create && !isTemporary && aMgrId != -1 ) { // set properties to the study - study->setObjectPropMap( aMgrId, entry, propMap ); + study->setObjectProperties( aMgrId, entry, propMap ); + } +} + +//================================================================= +/*! + * GEOM_Displayer::updateDimensions + * Creates or renews dimension presentation for the IO. + */ +//================================================================= +void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO, + SALOME_OCCPrs* thePrs, + const gp_Ax3& theShapeLCS ) +{ + SalomeApp_Study* aStudy = getStudy(); + if ( !aStudy ) + { + return; + } + + if ( theIO.IsNull() ) + { + return; + } + + SOCC_Prs* anOccPrs = dynamic_cast( thePrs ); + + AIS_ListOfInteractive aListOfIO; + + anOccPrs->GetObjects( aListOfIO ); + + AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO ); + + // remove outdated presentations of dimensions + for ( ; aIterateIO.More(); aIterateIO.Next() ) + { + const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value(); + if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) ) + { + continue; + } + + aListOfIO.Remove( aIterateIO ); + + if ( !aIterateIO.More() ) + { + break; + } + } + + // prepare dimension styling + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + + QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) ); + int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 ); + 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; + + QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(), + theIO->getEntry(), + GEOM::propertyName( GEOM::Dimensions ), + QVariant() ); + + GEOMGUI_DimensionProperty aRecords; + + if ( aProperty.isValid() && aProperty.canConvert() ) + { + aRecords = aProperty.value(); + } + else + { + aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() ); + } + + // create up-to-date dimension presentations + for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt ) + { + if ( !aRecords.IsVisible( aPrsIt ) ) + { + continue; + } + + // init dimension by type + Handle(AIS_Dimension) aPrs; + switch( aRecords.GetType( aPrsIt ) ) + { + case GEOMGUI_DimensionProperty::DimensionType_Length : + { + Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt ); + aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS ); + aPrs = aLength; + break; + } + + case GEOMGUI_DimensionProperty::DimensionType_Diameter : + { + Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt ); + aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS ); + aPrs = aDiam; + break; + } + + case GEOMGUI_DimensionProperty::DimensionType_Angle : + { + Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt ); + aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS ); + aPrs = anAng; + break; + } + } + + aPrs->SetOwner( theIO ); + + Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB ); + + Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect(); + + aStyle->SetCommonColor( aColor ); + aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown ); + aStyle->MakeText3d( aUseText3d ); + aStyle->MakeTextShaded( Standard_True ); + 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() ); + aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() ); + aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() ); + aPrs->SetDimensionAspect( aStyle ); + aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 ); + aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() ); + aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() ); + + if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) ) + { + // show degree symbol for dimension instead of label "deg" + if ( aUnitsAngle == "deg" ) + { + aPrs->SetSpecialSymbol(0xB0); + aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No ); + aStyle->MakeUnitsDisplayed(Standard_False); + } + else + { + aPrs->SetDisplaySpecialSymbol(AIS_DSS_No); + aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown ); + } + } + else + { + aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown ); + } + + aListOfIO.Append( aPrs ); + } + + // update presentation + anOccPrs->Clear(); + + for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() ) + { + anOccPrs->AddObject( aIterateIO.Value() ); } } @@ -936,16 +1396,40 @@ void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList, * Calls Redisplay() method for each object in the given list */ //================================================================= -void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, const bool updateViewer ) +void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, + const bool updateViewer, + const bool checkActiveViewer ) { SALOME_ListIteratorOfListIO Iter( theIOList ); for ( ; Iter.More(); Iter.Next() ) - Redisplay( Iter.Value(), false ); + Redisplay( Iter.Value(), false, checkActiveViewer ); if ( updateViewer ) UpdateViewer(); } +//================================================================= +/*! + * GEOM_Displayer::Redisplay + * Calls Redisplay() method for each object in the given list + */ +//================================================================= +void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList, + const bool theUpdateViewer, + SALOME_View* theViewFrame ) +{ + SALOME_ListIteratorOfListIO anIter( theIOList ); + for ( ; anIter.More(); anIter.Next() ) + { + Redisplay( anIter.Value(), false, theViewFrame ); + } + + if ( theUpdateViewer ) + { + UpdateViewer(); + } +} + //================================================================= /*! * GEOM_Displayer::Update @@ -1024,6 +1508,9 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) // create presentation (specific for vectors) Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" ) : new GEOM_AISShape ( myShape, "" ); + + if( myType == GEOM_FIELD_STEP ) + AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight ); // update shape properties updateShapeProperties( AISShape, true ); @@ -1073,6 +1560,8 @@ void GEOM_Displayer::Update( SALOME_OCCPrs* prs ) AISShape->SetToUpdate(); } } + + updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) ); } } @@ -1276,13 +1765,35 @@ SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry, CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO); if ( !CORBA::is_nil( object ) ) { - // downcast to GEOM object - GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( object ); - if ( !GeomObject->_is_nil() ) + // downcast to GEOM base object + GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object ); + if ( !GeomBaseObject->_is_nil() ) { - // finally set shape - setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) ); - myType = GeomObject->GetType(); + myType = GeomBaseObject->GetType(); + + // downcast to GEOM object + GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject ); + if ( myType == GEOM_FIELD_STEP ) + { + // get the GEOM object from the field's shape + GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject ); + if ( !GeomFieldStep->_is_nil() ) + { + GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField(); + if ( !GeomField->_is_nil() ) + GeomObject = GeomField->GetShape(); + } + + // read the field step information + readFieldStepInfo( GeomFieldStep ); + } + + if ( !GeomObject->_is_nil() ) + { + theIO->setName( GeomObject->GetName() ); + // finally set shape + setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) ); + } } } } @@ -1344,6 +1855,13 @@ void GEOM_Displayer::internalReset() { myIO.Nullify(); myShape.Nullify(); + + myFieldDataType = GEOM::FDT_Double; + myFieldDimension = 0; + myFieldStepData.clear(); + myFieldStepName.Clear(); + myFieldStepRangeMin = 0; + myFieldStepRangeMax = 0; } //================================================================= @@ -1353,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() ); @@ -1370,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 @@ -1488,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 ); } //================================================================= @@ -1511,39 +2057,49 @@ 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 ) { - 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( GEOM::propertyName( GEOM::Transparency ) ) ) { - double transparency = aPropMap.value(GEOM::propertyName( GEOM::Transparency )).toDouble(); - ic->SetTransparency( sh, transparency, true ); - } - } + 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 ) +{ + LightApp_Displayer::BeforeErase( v, p ); + releaseTextures( p ); +} + +void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p ) +{ + LightApp_Displayer::AfterErase( v, p ); + 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 )); + } +} + //================================================================= /*! * GEOM_Displayer::SetColor @@ -1581,19 +2137,60 @@ void GEOM_Displayer::UnsetColor() myShadingColor = SalomeApp_Tools::color( col ); } +//================================================================= +/*! + * GEOM_Displayer::SetTransparency + * Set transparency for shape displaying. + */ +//================================================================= +double GEOM_Displayer::SetTransparency( const double transparency ) +{ + double prevTransparency = myTransparency; + myTransparency = transparency; + return prevTransparency; +} + +//================================================================= +/*! + * GEOM_Displayer::GetTransparency + * Get transparency for shape displaying. + */ +//================================================================= +double GEOM_Displayer::GetTransparency() const +{ + return myTransparency; +} + +//================================================================= +/*! + * GEOM_Displayer::HasTransparency + * Check if transparency for shape displaying is set. + */ +//================================================================= +bool GEOM_Displayer::HasTransparency() const +{ + return myTransparency >= 0; +} + +//================================================================= +/*! + * GEOM_Displayer::UnsetTransparency + * Unset transparency for shape displaying. + */ +//================================================================= +double GEOM_Displayer::UnsetTransparency() +{ + 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 @@ -1632,7 +2229,6 @@ void GEOM_Displayer::UnsetWidth() myWidth = -1; } - int GEOM_Displayer::GetIsosWidth() const { return myIsosWidth; @@ -1648,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 ); +} //================================================================= /*! @@ -1709,12 +2348,29 @@ void GEOM_Displayer::setShape( const TopoDS_Shape& theShape ) myShape = theShape; } +void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType, + const int theFieldDimension, + const QList& theFieldStepData, + const TCollection_AsciiString& theFieldStepName, + const double theFieldStepRangeMin, + const double theFieldStepRangeMax ) +{ + myFieldDataType = theFieldDataType; + myFieldDimension = theFieldDimension; + myFieldStepData = theFieldStepData; + myFieldStepName = theFieldStepName; + myFieldStepRangeMin = theFieldStepRangeMin; + myFieldStepRangeMax = theFieldStepRangeMax; +} + bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const { _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() ); GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects + GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component - return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aCompObj ) ) && (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type()); + return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) && + (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type()); } int GEOM_Displayer::SetDisplayMode( const int theMode ) @@ -1767,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; @@ -1851,7 +2507,7 @@ PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study, if ( viewModel && viewId != -1 ) { // get properties from the study - PropMap storedMap = study->getObjectPropMap( viewId, entry ); + PropMap storedMap = study->getObjectProperties( viewId, entry ); // overwrite default properties from stored ones (that are specified) for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) { if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) ) @@ -1876,36 +2532,38 @@ PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study, CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO ); if ( !CORBA::is_nil( object ) ) { GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object ); - // check that geom object has color properly set - bool hasColor = false; - SALOMEDS::Color aSColor = getColor( geomObject, hasColor ); - // set color from geometry object (only once, if it is not yet set in GUI) - // current implementation is to use same color for all aspects - // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here - if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) { - QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B ); - propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor ); - propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor ); - propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor ); - propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor ); - propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor ); - } - // check that object has point marker properly set - GEOM::marker_type mType = geomObject->GetMarkerType(); - GEOM::marker_size mSize = geomObject->GetMarkerSize(); - int mTextureId = geomObject->GetMarkerTexture(); - bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || - ( mType == GEOM::MT_USER && mTextureId > 0 ); - // set point marker from geometry object (only once, if it is not yet set in GUI) - if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) { - if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) { - // standard type - propMap.insert( GEOM::propertyName( GEOM::PointMarker ), - QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) ); + if ( !CORBA::is_nil( geomObject ) ) { // to check + // check that geom object has color properly set + bool hasColor = false; + SALOMEDS::Color aSColor = getColor( geomObject, hasColor ); + // set color from geometry object (only once, if it is not yet set in GUI) + // current implementation is to use same color for all aspects + // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here + if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) { + QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B ); + propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor ); + propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor ); + propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor ); + propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor ); + propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor ); } - else if ( mType == GEOM::MT_USER ) { - // custom texture - propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) ); + // check that object has point marker properly set + GEOM::marker_type mType = geomObject->GetMarkerType(); + GEOM::marker_size mSize = geomObject->GetMarkerSize(); + int mTextureId = geomObject->GetMarkerTexture(); + bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) || + ( mType == GEOM::MT_USER && mTextureId > 0 ); + // set point marker from geometry object (only once, if it is not yet set in GUI) + if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) { + if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) { + // standard type + propMap.insert( GEOM::propertyName( GEOM::PointMarker ), + QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) ); + } + else if ( mType == GEOM::MT_USER ) { + // custom texture + propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) ); + } } } } @@ -1936,7 +2594,8 @@ PropMap GEOM_Displayer::getDefaultPropertyMap() arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) ); // - transparency (opacity = 1-transparency) - propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 ); + propMap.insert( GEOM::propertyName( GEOM::Transparency ), + resMgr->integerValue( "Geometry", "transparency", 0 ) / 100. ); // - display mode (take default value from preferences) propMap.insert( GEOM::propertyName( GEOM::DisplayMode ), @@ -1945,6 +2604,12 @@ PropMap GEOM_Displayer::getDefaultPropertyMap() // - show edges direction flag (false by default) propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false ); + // - 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 ) ) ); @@ -2110,3 +2775,278 @@ void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& t view->Repaint(); } } + +void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep ) +{ + if( theGeomFieldStep->_is_nil() ) + return; + + GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField(); + if( aGeomField->_is_nil() ) + return; + + GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape(); + if( aGeomFieldShape->_is_nil() ) + return; + + TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() ); + TCollection_AsciiString aFieldName( aGeomField->GetName() ); + TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() ); + + aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName; + + GEOM::field_data_type aFieldDataType = aGeomField->GetDataType(); + + int aFieldDimension = aGeomField->GetDimension(); + + GEOM::string_array_var aFieldComponents = aGeomField->GetComponents(); + int aFieldNbComponents = aFieldComponents->length(); + + QList aFieldStepData; + if( aFieldDataType == GEOM::FDT_Bool ) + { + GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep ); + if ( !aGeomBoolFieldStep->_is_nil() ) + { + GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues(); + for( size_t i = 0, n = aValues->length(); i < n; i++ ) + aFieldStepData << (bool)aValues[i]; + } + } + else if( aFieldDataType == GEOM::FDT_Int ) + { + GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep ); + if ( !aGeomIntFieldStep->_is_nil() ) + { + GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues(); + for( size_t i = 0, n = aValues->length(); i < n; i++ ) + aFieldStepData << (qlonglong)aValues[i]; + } + } + else if( aFieldDataType == GEOM::FDT_Double ) + { + GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep ); + if ( !aGeomDoubleFieldStep->_is_nil() ) + { + GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues(); + for( size_t i = 0, n = aValues->length(); i < n; i++ ) + aFieldStepData << (double)aValues[i]; + } + } + else if( aFieldDataType == GEOM::FDT_String ) + { + GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep ); + if ( !aGeomStringFieldStep->_is_nil() ) + { + GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues(); + for( size_t i = 0, n = aValues->length(); i < n; i++ ) + aFieldStepData << QString( aValues[i] ); + } + } + + double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0; + aFieldStepData = groupFieldData( aFieldStepData, + aFieldNbComponents, + aFieldDataType == GEOM::FDT_String, + aFieldStepRangeMin, + aFieldStepRangeMax ); + + setFieldStepInfo( aFieldDataType, + aFieldDimension, + aFieldStepData, + aFieldStepName, + aFieldStepRangeMin, + aFieldStepRangeMax ); +} + +QList GEOM_Displayer::groupFieldData( const QList& theFieldStepData, + const int theFieldNbComponents, + const bool theIsString, + double& theFieldStepRangeMin, + double& theFieldStepRangeMax ) +{ + QList aResultList; + theFieldStepRangeMin = 0; + theFieldStepRangeMax = 0; + + if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 ) + return aResultList; + + int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents; + + QList aGroupedList; + + bool anIsBoolean = false; + for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ ) + { + double aNorm = 0; + QStringList aStringList; + + int aBaseIndex = aSubShape * theFieldNbComponents; + for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ ) + { + int anIndex = aComponent + aBaseIndex; + + const QVariant& aVariant = theFieldStepData[ anIndex ]; + if( theIsString ) + { + if( aVariant.type() == QVariant::String ) + aStringList << aVariant.toString(); + } + else + { + double aValue = 0; + if( aVariant.type() == QVariant::Bool ) + { + aValue = aVariant.toBool() ? 1.0 : 0.0; + aNorm += aValue; + anIsBoolean = true; + } + else + { + if( aVariant.type() == QVariant::LongLong ) + aValue = double( aVariant.toLongLong() ); + else if( aVariant.type() == QVariant::Double ) + aValue = aVariant.toDouble(); + aNorm += aValue * aValue; + } + } + } + + if( theIsString ) + aGroupedList << aStringList.join( "\n" ); + else + { + if( anIsBoolean ) + aNorm /= theFieldNbComponents; + else + aNorm = pow( aNorm, 0.5 ); + + if( aGroupedList.isEmpty() ) + theFieldStepRangeMin = theFieldStepRangeMax = aNorm; + else + { + theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm ); + theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm ); + } + + aGroupedList << aNorm; + } + } + + if( anIsBoolean ) + { + theFieldStepRangeMin = 0.0; + theFieldStepRangeMax = 1.0; + } + + SUIT_Session* session = SUIT_Session::session(); + SUIT_ResourceMgr* resMgr = session->resourceMgr(); + Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 ); + + QListIterator anIter( aGroupedList ); + while( anIter.hasNext() ) + { + const QVariant& aVariant = anIter.next(); + if( theIsString ) + aResultList << aVariant; + else + { + QColor aQColor; + Quantity_Color aColor; + if( AIS_ColorScale::FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) ) + aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() ); + aResultList << aQColor; + } + } + return aResultList; +} + +void GEOM_Displayer::UpdateColorScale() +{ + if ( !myUpdateColorScale ) + return; + + SUIT_Session* session = SUIT_Session::session(); + SUIT_Application* app = session->activeApplication(); + if ( !app ) return; + + Handle(SALOME_InteractiveObject) io = myApp->selectionMgr()->soleSelectedObject(); + + QList windows = app->desktop()->windows(); + foreach( SUIT_ViewWindow* window, windows ) + { + 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 ) ) + { + bool visible = false; + SOCC_Prs* prs = dynamic_cast( view->CreatePrs( io->getEntry() ) ); + if ( prs ) + { + AIS_ListOfInteractive presentations; + prs->GetObjects( presentations ); + AIS_ListIteratorOfListOfInteractive iter( presentations ); + for ( ; iter.More(); iter.Next() ) + { + 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 ) + { + 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 ) + } + } + view->setColorScaleShown( visible ); + } // if ( view->isVisible( io ) ) + else + { + view->setColorScaleShown( false ); + } + } // foreach( SUIT_ViewWindow* window, windows ) +} + +bool GEOM_Displayer::SetUpdateColorScale( bool toUpdate ) // IPAL54049 +{ + bool previous = myUpdateColorScale; + myUpdateColorScale = toUpdate; + if ( myUpdateColorScale && !previous ) + UpdateColorScale(); + return previous; +} +