2016-03-15 17:26:56 +05:00
// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2005-08-18 12:15:31 +06:00
//
2012-08-09 13:58:02 +06:00
// 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
2014-02-18 12:44:41 +06:00
// version 2.1 of the License, or (at your option) any later version.
2005-08-18 12:15:31 +06:00
//
2012-08-09 13:58:02 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2005-08-18 12:15:31 +06:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06:00
2009-02-13 17:16:39 +05:00
// GEOM GEOMGUI : GUI for Geometry component
// File : GEOM_Displayer.cxx
// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
2012-08-09 13:58:02 +06:00
2004-12-01 15:39:14 +05:00
# include "GEOM_Displayer.h"
2014-01-15 15:27:18 +06:00
# include "GEOMGUI_DimensionProperty.h"
2005-08-18 12:15:31 +06:00
# include "GeometryGUI.h"
2005-06-02 13:17:09 +06:00
2012-08-09 13:58:02 +06:00
# include <GEOM_Constants.h>
2009-02-13 17:16:39 +05:00
# include <GEOM_TypeFilter.h>
# include <GEOM_EdgeFilter.h>
# include <GEOM_FaceFilter.h>
# include <GEOM_CompoundFilter.h>
# include <GEOM_PreviewFilter.h>
# include <GEOM_LogicalFilter.h>
# include <GEOM_OCCFilter.h>
# include <GEOM_Actor.h>
2014-01-15 15:27:18 +06:00
# include <GEOM_AISDimension.hxx>
2012-08-09 13:58:02 +06:00
# include <GEOM_TopWireframeShape.hxx>
2009-02-13 17:16:39 +05:00
# include <GEOM_AISVector.hxx>
# include <GEOM_AISTrihedron.hxx>
# include <GEOM_VTKTrihedron.hxx>
2012-08-09 13:58:02 +06:00
# include <GEOM_VTKPropertyMaterial.hxx>
2014-01-15 15:27:18 +06:00
# include <GEOMUtils.hxx>
2012-08-09 13:58:02 +06:00
# include <Material_Model.h>
2004-12-01 15:39:14 +05:00
2005-06-02 13:17:09 +06:00
# include <SUIT_Desktop.h>
# include <SUIT_ViewWindow.h>
# include <SUIT_Session.h>
# include <SUIT_ViewManager.h>
2009-02-13 17:16:39 +05:00
# include <SUIT_ResourceMgr.h>
2005-06-02 13:17:09 +06:00
2012-08-09 13:58:02 +06:00
# include <Basics_OCCTVersion.hxx>
2005-06-02 13:17:09 +06:00
# include <SalomeApp_Study.h>
# include <SalomeApp_Application.h>
2005-11-03 13:30:14 +05:00
# include <LightApp_SelectionMgr.h>
2012-08-09 13:58:02 +06:00
# include <LightApp_DataObject.h>
2005-06-02 13:17:09 +06:00
# include <SalomeApp_TypeFilter.h>
2005-06-22 12:29:29 +06:00
# include <SalomeApp_Tools.h>
2015-02-09 21:50:36 +05:00
# include "utilities.h"
2005-06-02 13:17:09 +06:00
2009-02-13 17:16:39 +05:00
# include <SALOME_ListIO.hxx>
# include <SALOME_Prs.h>
2014-11-19 20:45:44 +05:00
# include "utilities.h"
2005-06-02 13:17:09 +06:00
# include <SOCC_Prs.h>
2005-08-18 12:15:31 +06:00
# include <SOCC_ViewModel.h>
2005-06-02 13:17:09 +06:00
# include <SVTK_Prs.h>
# include <SVTK_ViewModel.h>
2013-10-18 20:00:58 +06:00
# include <OCCViewer_ViewWindow.h>
# include <OCCViewer_ViewPort3d.h>
2014-09-11 15:02:10 +06:00
# include <OCCViewer_Utilities.h>
2013-10-18 20:00:58 +06:00
2005-08-18 12:15:31 +06:00
// OCCT Includes
2014-01-15 15:27:18 +06:00
# include <AIS_Dimension.hxx>
# include <AIS_LengthDimension.hxx>
# include <AIS_DiameterDimension.hxx>
# include <AIS_AngleDimension.hxx>
2005-08-18 12:15:31 +06:00
# include <AIS_ListIteratorOfListOfInteractive.hxx>
2014-01-15 15:27:18 +06:00
# include <Aspect_PolygonOffsetMode.hxx>
2016-02-24 18:45:13 +05:00
# if OCC_VERSION_MAJOR < 7
# include <Aspect_ColorScale.hxx>
# endif
2008-03-07 12:45:34 +05:00
# include <Prs3d_IsoAspect.hxx>
2004-12-01 15:39:14 +05:00
# include <Prs3d_PointAspect.hxx>
2005-08-18 12:15:31 +06:00
# include <StdSelect_TypeOfEdge.hxx>
# include <StdSelect_TypeOfFace.hxx>
2012-08-09 13:58:02 +06:00
# include <StdSelect_DisplayMode.hxx>
2004-12-01 15:39:14 +05:00
# include <TopoDS_Face.hxx>
# include <BRep_Tool.hxx>
2005-08-18 12:15:31 +06:00
# include <Geom_Plane.hxx>
2004-12-01 15:39:14 +05:00
# include <Geom_Axis2Placement.hxx>
2012-08-09 13:58:02 +06:00
# include <Graphic3d_AspectFillArea3d.hxx>
2005-08-18 12:15:31 +06:00
# include <gp_Pln.hxx>
# include <TColStd_MapIteratorOfMapOfInteger.hxx>
2008-03-07 12:45:34 +05:00
# include <TopoDS_Iterator.hxx>
2012-08-09 13:58:02 +06:00
# include <Graphic3d_AspectMarker3d.hxx>
# include <TopTools_MapOfShape.hxx>
# include <TopTools_ListOfShape.hxx>
# include <TopTools_ListIteratorOfListOfShape.hxx>
# include <TopoDS.hxx>
2014-03-14 15:05:51 +06:00
# include <NCollection_DataMap.hxx>
# include <NCollection_Map.hxx>
2012-08-09 13:58:02 +06:00
# include <Prs3d_ShadingAspect.hxx>
# include <BRepMesh_IncrementalMesh.hxx>
2005-08-18 12:15:31 +06:00
// VTK Includes
2004-12-01 15:39:14 +05:00
# include <vtkActorCollection.h>
2006-02-07 20:58:35 +05:00
# include <vtkProperty.h>
2004-12-01 15:39:14 +05:00
2005-08-18 12:15:31 +06:00
// CORBA Headers
# include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
2009-02-13 17:16:39 +05:00
# include <GEOMImpl_Types.hxx>
2005-08-18 12:15:31 +06:00
2012-08-09 13:58:02 +06:00
# include <TColStd_HArray1OfByte.hxx>
2004-12-01 15:39:14 +05:00
2012-10-08 17:16:36 +06:00
// If the next macro is defined, autocolor feature works for all sub-shapes;
// if it is undefined, autocolor feature works for groups only
2012-12-13 14:40:36 +06:00
# define GENERAL_AUTOCOLOR
2012-10-08 17:16:36 +06:00
// Below macro, when uncommented, switches on simplified (more performant) algorithm
// of auto-color picking up
2012-12-13 14:40:36 +06:00
# define SIMPLE_AUTOCOLOR
2012-10-08 17:16:36 +06:00
2013-02-12 17:35:16 +06:00
// Hard-coded value of shape deflection coefficient for VTK viewer
const double VTK_MIN_DEFLECTION = 0.001 ;
2014-11-07 20:37:50 +05:00
// If the next macro is defined, the deflection coefficient for VTK presentation
// is limited by VTK_MIN_DEFLECTION
//#define LIMIT_DEFLECTION_FOR_VTK
2013-02-12 17:35:16 +06:00
2014-03-14 15:05:51 +06:00
// Pixmap caching support
namespace
{
typedef NCollection_Map < Handle ( GEOM_AISShape ) > SetOfAISShapes ;
typedef NCollection_DataMap < Handle ( Image_PixMap ) , SetOfAISShapes > PixmapUsageMap ;
typedef QMap < QString , Handle ( Image_PixMap ) > PixmapCacheMap ;
static inline PixmapUsageMap & getPixmapUsageMap ( )
{
static PixmapUsageMap aMap ;
return aMap ;
}
static inline PixmapCacheMap & getPixmapCacheMap ( )
{
static PixmapCacheMap aMap ;
return aMap ;
}
2014-04-17 18:25:34 +06:00
//===========================================================================
// 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 ( ) )
2014-10-06 17:30:58 +06:00
aPixmap = OCCViewer_Utilities : : imageToPixmap ( px . toImage ( ) ) ;
2014-04-17 18:25:34 +06:00
}
return aPixmap ;
}
2014-03-14 15:05:51 +06:00
//===========================================================================
// 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 ;
2014-10-06 17:30:58 +06:00
aPixmap = OCCViewer_Utilities : : imageToPixmap ( anImage ) ;
2014-03-14 15:05:51 +06:00
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 < const SOCC_Prs * > ( 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 ;
2014-10-21 19:45:02 +06:00
# ifdef USE_TEXTURED_SHAPE
2014-03-14 15:05:51 +06:00
const Handle ( Image_PixMap ) & aPixmap = aAISShape - > TexturePixMap ( ) ;
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 ) ) ;
}
2014-10-21 19:45:02 +06:00
# endif
2014-03-14 15:05:51 +06:00
}
}
2014-10-31 19:03:46 +05:00
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
2014-03-14 15:05:51 +06:00
2004-12-01 15:39:14 +05:00
//================================================================
// Function : getActiveStudy
// Purpose : Get active study, returns 0 if no open study frame
//================================================================
2005-06-02 13:17:09 +06:00
static inline SalomeApp_Study * getActiveStudy ( )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SUIT_Session * session = SUIT_Session : : session ( ) ;
SalomeApp_Application * app = dynamic_cast < SalomeApp_Application * > ( session - > activeApplication ( ) ) ;
if ( app )
return ( SalomeApp_Study * ) app - > activeStudy ( ) ;
2004-12-01 15:39:14 +05:00
return 0 ;
}
2012-08-09 13:58:02 +06:00
static inline int getViewManagerId ( SALOME_View * theViewFrame ) {
SUIT_ViewModel * aModel = dynamic_cast < SUIT_ViewModel * > ( theViewFrame ) ;
SUIT_ViewManager * aViewMgr = 0 ;
if ( aModel ! = 0 )
aViewMgr = aModel - > getViewManager ( ) ;
return ( ( aViewMgr = = 0 ) ? - 1 : aViewMgr - > getGlobalId ( ) ) ;
}
2004-12-01 15:39:14 +05:00
//================================================================
// Function : getTopAbsMode
// Purpose : Get TopAbs_ShapeEnum value corresponding to the
// one from GEOMImpl_Types.h
//================================================================
static inline int getTopAbsMode ( const int implType )
{
switch ( implType )
{
case GEOM_COMPOUND : return TopAbs_COMPOUND ;
case GEOM_SOLID : return TopAbs_SOLID ;
case GEOM_SHELL : return TopAbs_SHELL ;
case GEOM_FACE : return TopAbs_FACE ;
case GEOM_WIRE : return TopAbs_WIRE ;
case GEOM_EDGE : return TopAbs_EDGE ;
case GEOM_POINT : return TopAbs_VERTEX ;
default : return - 1 ;
}
}
2012-08-09 13:58:02 +06:00
int GEOM_Displayer : : getMinMaxShapeType ( const TopoDS_Shape & shape , bool ismin )
{
if ( shape . IsNull ( ) )
return TopAbs_SHAPE ;
int ret = shape . ShapeType ( ) ;
if ( shape . ShapeType ( ) = = TopAbs_COMPOUND | | shape . ShapeType ( ) = = TopAbs_COMPSOLID ) {
TopoDS_Iterator it ( shape , Standard_True , Standard_False ) ;
for ( ; it . More ( ) ; it . Next ( ) ) {
TopoDS_Shape sub_shape = it . Value ( ) ;
if ( sub_shape . IsNull ( ) ) continue ;
int stype = getMinMaxShapeType ( sub_shape , ismin ) ;
if ( stype = = TopAbs_SHAPE ) continue ;
if ( ismin & & stype > ret )
ret = stype ;
else if ( ! ismin & & ( ret < TopAbs_SOLID | | stype < ret ) )
ret = stype ;
}
}
return ret ;
}
bool GEOM_Displayer : : isCompoundOfVertices ( const TopoDS_Shape & theShape )
{
return theShape . ShapeType ( ) = = TopAbs_COMPOUND & & getMinMaxShapeType ( theShape , false ) = = TopAbs_VERTEX ;
}
2004-12-01 15:39:14 +05:00
//================================================================
2005-06-02 13:17:09 +06:00
// Function : getFilter
2004-12-01 15:39:14 +05:00
// Purpose : Get filter corresponding to the type of object
// from GEOMImpl_Types.h
//================================================================
2005-06-02 13:17:09 +06:00
SUIT_SelectionFilter * GEOM_Displayer : : getFilter ( const int theMode )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SUIT_SelectionFilter * aFilter ;
2005-08-18 12:15:31 +06:00
2004-12-01 15:39:14 +05:00
int aTopAbsMode = getTopAbsMode ( theMode ) ;
if ( aTopAbsMode ! = - 1 )
2005-06-15 12:17:13 +06:00
aFilter = new GEOM_TypeFilter ( getStudy ( ) , aTopAbsMode , true ) ; //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
2004-12-01 15:39:14 +05:00
else
switch ( theMode )
2005-06-02 13:17:09 +06:00
{
case GEOM_LINE : aFilter = new GEOM_EdgeFilter ( getStudy ( ) , StdSelect_Line ) ; break ;
case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter ( getStudy ( ) , StdSelect_Circle ) ; break ;
2005-08-18 12:15:31 +06:00
2005-06-02 13:17:09 +06:00
case GEOM_PLANE : aFilter = new GEOM_FaceFilter ( getStudy ( ) , StdSelect_Plane ) ; break ;
case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter ( getStudy ( ) , StdSelect_Cylinder ) ; break ;
case GEOM_SPHERE : aFilter = new GEOM_FaceFilter ( getStudy ( ) , StdSelect_Sphere ) ; break ;
case GEOM_TORUS : aFilter = new GEOM_FaceFilter ( getStudy ( ) , StdSelect_Torus ) ; break ;
case GEOM_REVOLUTION : aFilter = new GEOM_FaceFilter ( getStudy ( ) , StdSelect_Revol ) ; break ;
case GEOM_CONE : aFilter = new GEOM_FaceFilter ( getStudy ( ) , StdSelect_Cone ) ; break ;
2005-08-18 12:15:31 +06:00
2005-06-02 13:17:09 +06:00
case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter ( getStudy ( ) ) ; break ;
2005-08-18 12:15:31 +06:00
2005-06-02 13:17:09 +06:00
case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter ( getStudy ( ) , true ) ; break ;
case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter ( getStudy ( ) , " GEOM " ) ; break ;
2005-08-18 12:15:31 +06:00
2005-06-02 13:17:09 +06:00
default : aFilter = new GEOM_TypeFilter ( getStudy ( ) , theMode ) ; break ;
}
2005-08-18 12:15:31 +06:00
2004-12-01 15:39:14 +05:00
return aFilter ;
}
2009-02-13 17:16:39 +05:00
//================================================================
// Function : getComplexFilter
2012-08-09 13:58:02 +06:00
// Purpose : Get compound filter corresponding to the type of
2009-02-13 17:16:39 +05:00
// object from GEOMImpl_Types.h
//================================================================
SUIT_SelectionFilter * GEOM_Displayer : : getComplexFilter ( const QList < int > * aSubShapes )
{
GEOM_CompoundFilter * aFilter ;
2012-08-09 13:58:02 +06:00
2009-02-13 17:16:39 +05:00
if ( aSubShapes ! = NULL ) {
aFilter = new GEOM_CompoundFilter ( getStudy ( ) ) ;
QList < int > aTopAbsTypes ;
QList < int > : : const_iterator it ;
for ( it = aSubShapes - > constBegin ( ) ; it ! = aSubShapes - > constEnd ( ) ; + + it ) {
int topAbsMode = getTopAbsMode ( * it ) ;
if ( topAbsMode ! = - 1 )
aTopAbsTypes . append ( topAbsMode ) ;
}
aFilter - > addSubTypes ( aTopAbsTypes ) ;
}
2012-08-09 13:58:02 +06:00
2009-02-13 17:16:39 +05:00
return aFilter ;
}
2004-12-01 15:39:14 +05:00
//================================================================
// Function : getEntry
// Purpose :
//================================================================
2013-10-18 20:00:58 +06:00
static std : : string getEntry ( GEOM : : GEOM_BaseObject_ptr object )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SUIT_Session * session = SUIT_Session : : session ( ) ;
SalomeApp_Application * app = dynamic_cast < SalomeApp_Application * > ( session - > activeApplication ( ) ) ;
2005-08-18 12:15:31 +06:00
if ( app )
2005-06-02 13:17:09 +06:00
{
2008-03-07 12:45:34 +05:00
CORBA : : String_var IOR = app - > orb ( ) - > object_to_string ( object ) ;
if ( strcmp ( IOR . in ( ) , " " ) ! = 0 )
2005-06-02 13:17:09 +06:00
{
SalomeApp_Study * study = ( SalomeApp_Study * ) app - > activeStudy ( ) ;
2012-08-09 13:58:02 +06:00
_PTR ( SObject ) SO ( study - > studyDS ( ) - > FindObjectIOR ( std : : string ( IOR ) ) ) ;
2005-06-02 13:17:09 +06:00
if ( SO )
2012-08-09 13:58:02 +06:00
return SO - > GetID ( ) ;
2004-12-01 15:39:14 +05:00
}
}
return " " ;
}
//================================================================
// Function : getName
// Purpose :
//================================================================
2013-10-18 20:00:58 +06:00
static std : : string getName ( GEOM : : GEOM_BaseObject_ptr object )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SUIT_Session * session = SUIT_Session : : session ( ) ;
SalomeApp_Application * app = dynamic_cast < SalomeApp_Application * > ( session - > activeApplication ( ) ) ;
2005-08-18 12:15:31 +06:00
if ( app )
2004-12-01 15:39:14 +05:00
{
2008-03-07 12:45:34 +05:00
CORBA : : String_var IOR = app - > orb ( ) - > object_to_string ( object ) ;
if ( strcmp ( IOR . in ( ) , " " ) ! = 0 )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SalomeApp_Study * study = ( SalomeApp_Study * ) app - > activeStudy ( ) ;
2012-08-09 13:58:02 +06:00
_PTR ( SObject ) aSObj ( study - > studyDS ( ) - > FindObjectIOR ( std : : string ( IOR ) ) ) ;
2004-12-01 15:39:14 +05:00
2005-06-02 13:17:09 +06:00
_PTR ( GenericAttribute ) anAttr ;
if ( aSObj & & aSObj - > FindAttribute ( anAttr , " AttributeName " ) )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
_PTR ( AttributeName ) aNameAttr ( anAttr ) ;
2005-09-13 17:09:57 +06:00
return aNameAttr - > Value ( ) ;
2004-12-01 15:39:14 +05:00
}
}
}
return " " ;
}
//=================================================================
/*!
* GEOM_Displayer : : GEOM_Displayer
* Constructor
*/
//=================================================================
2005-11-14 18:53:44 +05:00
GEOM_Displayer : : GEOM_Displayer ( SalomeApp_Study * st )
2004-12-01 15:39:14 +05:00
{
2005-11-14 18:53:44 +05:00
if ( st )
myApp = dynamic_cast < SalomeApp_Application * > ( st - > application ( ) ) ;
else
myApp = 0 ;
2005-08-18 12:15:31 +06:00
2004-12-01 15:39:14 +05:00
/* Shading Color */
2005-06-02 13:17:09 +06:00
SUIT_Session * session = SUIT_Session : : session ( ) ;
SUIT_ResourceMgr * resMgr = session - > resourceMgr ( ) ;
2005-06-22 12:29:29 +06:00
QColor col = resMgr - > colorValue ( " Geometry " , " shading_color " , QColor ( 255 , 0 , 0 ) ) ;
myShadingColor = SalomeApp_Tools : : color ( col ) ;
2004-12-01 15:39:14 +05:00
2005-07-06 18:42:51 +06:00
myDisplayMode = resMgr - > integerValue ( " Geometry " , " display_mode " , 0 ) ;
2013-02-12 17:35:16 +06:00
myHasDisplayMode = false ;
2008-03-07 12:45:34 +05:00
2012-08-09 13:58:02 +06:00
int aType = resMgr - > integerValue ( " Geometry " , " type_of_marker " , ( int ) Aspect_TOM_PLUS ) ;
2014-07-02 13:17:40 +06:00
2012-08-09 13:58:02 +06:00
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 ) ) ;
2005-07-06 18:42:51 +06:00
2014-11-07 20:36:38 +05:00
// Next properties provide a way to customize displaying of presentations;
// for instance, this is useful for preview
2004-12-01 15:39:14 +05:00
myColor = - 1 ;
2012-08-09 13:58:02 +06:00
myTexture = " " ;
2014-11-07 20:36:38 +05:00
myNbIsos = - 1 ;
2004-12-01 15:39:14 +05:00
myWidth = - 1 ;
2014-11-07 20:36:38 +05:00
myTransparency = - 1 ;
2004-12-01 15:39:14 +05:00
myType = - 1 ;
2014-11-07 20:36:38 +05:00
myIsosColor = - 1 ;
myIsosWidth = - 1 ;
// This parameter is used for activisation/deactivisation (selection) of objects to be displayed
2004-12-01 15:39:14 +05:00
myToActivate = true ;
2013-02-12 17:35:16 +06:00
// Activate parallel vizualisation only for testing purpose
// and if the corresponding env variable is set to 1
2012-08-09 13:58:02 +06:00
char * parallel_visu = getenv ( " PARALLEL_VISU " ) ;
if ( parallel_visu & & atoi ( parallel_visu ) )
{
MESSAGE ( " Parallel visualisation on " ) ;
BRepMesh_IncrementalMesh : : SetParallelDefault ( Standard_True ) ;
}
2004-12-01 15:39:14 +05:00
myViewFrame = 0 ;
2013-10-18 20:00:58 +06:00
2016-02-24 18:45:13 +05:00
# if OCC_VERSION_MAJOR >= 7
myColorScale = new AIS_ColorScale ;
myColorScale - > SetZLayer ( Graphic3d_ZLayerId_TopOSD ) ;
myColorScale - > SetTransformPersistence ( Graphic3d_TMF_2d , gp_Pnt ( - 1 , - 1 , 0 ) ) ;
# endif
2013-10-18 20:00:58 +06:00
myFieldDataType = GEOM : : FDT_Double ;
myFieldDimension = 0 ;
myFieldStepRangeMin = 0 ;
myFieldStepRangeMax = 0 ;
2004-12-01 15:39:14 +05:00
}
//=================================================================
/*!
* GEOM_Displayer : : ~ GEOM_Displayer
* Destructor
*/
//=================================================================
GEOM_Displayer : : ~ GEOM_Displayer ( )
{
}
//=================================================================
/*!
* GEOM_Displayer : : Display
* Display interactive object in the current viewer
*/
//=================================================================
2005-08-18 12:15:31 +06:00
void GEOM_Displayer : : Display ( const Handle ( SALOME_InteractiveObject ) & theIO ,
2012-08-09 13:58:02 +06:00
const bool updateViewer ,
SALOME_View * theViewFrame )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SALOME_View * vf = theViewFrame ? theViewFrame : GetActiveView ( ) ;
2004-12-01 15:39:14 +05:00
if ( vf )
{
2005-09-27 12:32:15 +06:00
SALOME_Prs * prs = buildPresentation ( theIO - > getEntry ( ) , vf ) ;
2005-08-18 12:15:31 +06:00
2004-12-01 15:39:14 +05:00
if ( prs )
{
2012-08-09 13:58:02 +06:00
vf - > BeforeDisplay ( this , prs ) ;
2014-10-23 18:33:30 +06:00
vf - > Display ( this , prs ) ;
2012-08-09 13:58:02 +06:00
vf - > AfterDisplay ( this , prs ) ;
2005-06-02 13:17:09 +06:00
2004-12-01 15:39:14 +05:00
if ( updateViewer )
vf - > Repaint ( ) ;
2005-08-18 12:15:31 +06:00
2004-12-01 15:39:14 +05:00
delete prs ; // delete presentation because displayer is its owner
}
}
}
//=================================================================
/*!
* GEOM_Displayer : : Display
* This overloaded Display ( ) method can be useful for operations
* not using dialog boxes .
*/
//=================================================================
2013-10-18 20:00:58 +06:00
void GEOM_Displayer : : Display ( GEOM : : GEOM_BaseObject_ptr theObj , const bool updateViewer )
2004-12-01 15:39:14 +05:00
{
if ( theObj - > _is_nil ( ) )
return ;
2012-08-09 13:58:02 +06:00
std : : string entry = getEntry ( theObj ) ;
2004-12-01 15:39:14 +05:00
if ( entry ! = " " ) {
2005-09-13 17:09:57 +06:00
Display ( new SALOME_InteractiveObject ( entry . c_str ( ) , " GEOM " , getName ( theObj ) . c_str ( ) ) ,
updateViewer ) ;
2004-12-01 15:39:14 +05:00
}
}
//=================================================================
/*!
* GEOM_Displayer : : Erase
* Erase interactive object in the current viewer
*/
//=================================================================
void GEOM_Displayer : : Erase ( const Handle ( SALOME_InteractiveObject ) & theIO ,
const bool forced ,
const bool updateViewer ,
2012-08-09 13:58:02 +06:00
SALOME_View * theViewFrame )
2004-12-01 15:39:14 +05:00
{
if ( theIO . IsNull ( ) )
return ;
2005-06-02 13:17:09 +06:00
SALOME_View * vf = theViewFrame ? theViewFrame : GetActiveView ( ) ;
2005-08-18 12:15:31 +06:00
2004-12-01 15:39:14 +05:00
if ( vf ) {
SALOME_Prs * prs = vf - > CreatePrs ( theIO - > getEntry ( ) ) ;
if ( prs ) {
2012-08-09 13:58:02 +06:00
vf - > BeforeErase ( this , prs ) ;
2014-10-23 18:33:30 +06:00
vf - > Erase ( this , prs , forced ) ;
2012-08-09 13:58:02 +06:00
vf - > AfterErase ( this , prs ) ;
2004-12-01 15:39:14 +05:00
if ( updateViewer )
2012-08-09 13:58:02 +06:00
vf - > Repaint ( ) ;
2004-12-01 15:39:14 +05:00
delete prs ; // delete presentation because displayer is its owner
}
}
}
//=================================================================
/*!
* GEOM_Displayer : : Erase
* Erase geometry object in the current viewer
*/
//=================================================================
2013-10-18 20:00:58 +06:00
void GEOM_Displayer : : Erase ( GEOM : : GEOM_BaseObject_ptr theObj ,
2004-12-01 15:39:14 +05:00
const bool forced ,
2014-01-17 13:12:34 +06:00
const bool updateViewer ,
SALOME_View * theViewFrame )
2004-12-01 15:39:14 +05:00
{
2012-08-09 13:58:02 +06:00
std : : string entry = getEntry ( theObj ) ;
2004-12-01 15:39:14 +05:00
if ( entry ! = " " )
{
2005-09-13 17:09:57 +06:00
Erase ( new SALOME_InteractiveObject ( entry . c_str ( ) , " GEOM " , getName ( theObj ) . c_str ( ) ) ,
2014-01-17 13:12:34 +06:00
forced , updateViewer , theViewFrame ) ;
2004-12-01 15:39:14 +05:00
}
}
//=================================================================
/*!
* GEOM_Displayer : : Redisplay
* Redisplay ( erase and then display again ) interactive object
* in the current viewer
*/
//=================================================================
void GEOM_Displayer : : Redisplay ( const Handle ( SALOME_InteractiveObject ) & theIO ,
2013-10-18 20:00:58 +06:00
const bool updateViewer ,
const bool checkActiveViewer )
2004-12-01 15:39:14 +05:00
{
// Remove the object permanently (<forced> == true)
2005-06-02 13:17:09 +06:00
SUIT_Session * ses = SUIT_Session : : session ( ) ;
SUIT_Application * app = ses - > activeApplication ( ) ;
if ( app )
{
SUIT_Desktop * desk = app - > desktop ( ) ;
2009-02-13 17:16:39 +05:00
QList < SUIT_ViewWindow * > wnds = desk - > windows ( ) ;
2005-06-02 13:17:09 +06:00
SUIT_ViewWindow * wnd ;
2009-02-13 17:16:39 +05:00
QListIterator < SUIT_ViewWindow * > it ( wnds ) ;
while ( it . hasNext ( ) & & ( wnd = it . next ( ) ) )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SUIT_ViewManager * vman = wnd - > getViewManager ( ) ;
if ( vman )
{
2012-08-09 13:58:02 +06:00
SUIT_ViewModel * vmodel = vman - > getViewModel ( ) ;
if ( vmodel )
{
SALOME_View * view = dynamic_cast < SALOME_View * > ( vmodel ) ;
if ( view )
{
2013-10-18 20:00:58 +06:00
if ( view - > isVisible ( theIO ) | | ( checkActiveViewer & & view = = GetActiveView ( ) ) )
2012-08-09 13:58:02 +06:00
{
2014-01-15 15:27:18 +06:00
Redisplay ( theIO , updateViewer , view ) ;
2012-08-09 13:58:02 +06:00
}
}
}
2005-06-02 13:17:09 +06:00
}
2004-12-01 15:39:14 +05:00
}
2005-06-02 13:17:09 +06:00
}
2004-12-01 15:39:14 +05:00
}
2014-01-15 15:27:18 +06:00
//=================================================================
/*!
* 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 ;
}
Erase ( theIO , true , false , theViewFrame ) ;
Display ( theIO , theUpdateViewer , theViewFrame ) ;
}
2004-12-01 15:39:14 +05:00
//=================================================================
/*!
* GEOM_Displayer : : Display
* Calls Display ( ) method for each object in the given list
*/
//=================================================================
void GEOM_Displayer : : Display ( const SALOME_ListIO & theIOList , const bool updateViewer )
{
SALOME_ListIteratorOfListIO Iter ( theIOList ) ;
for ( ; Iter . More ( ) ; Iter . Next ( ) ) {
Display ( Iter . Value ( ) , false ) ;
}
if ( updateViewer )
UpdateViewer ( ) ;
}
2014-10-23 18:33:30 +06:00
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 ) ;
}
}
}
2013-02-12 17:35:16 +06:00
Quantity_Color GEOM_Displayer : : qColorFromResources ( const QString & property , const QColor & defColor )
{
// VSR: this method can be improved in future:
// to improve performance, the default values from resource manager should be cached in the displayer
return SalomeApp_Tools : : color ( SUIT_Session : : session ( ) - > resourceMgr ( ) - > colorValue ( " Geometry " , property , defColor ) ) ;
}
QColor GEOM_Displayer : : colorFromResources ( const QString & property , const QColor & defColor )
{
// VSR: this method can be improved in future:
// to improve performance, the default values from resource manager should be cached in the displayer
return SUIT_Session : : session ( ) - > resourceMgr ( ) - > colorValue ( " Geometry " , property , defColor ) ;
}
void GEOM_Displayer : : updateShapeProperties ( const Handle ( GEOM_AISShape ) & AISShape , bool create )
{
// check that shape is not null
if ( AISShape . IsNull ( ) ) return ;
// check that study is active
SalomeApp_Study * study = getStudy ( ) ;
if ( ! study ) return ;
if ( myShape . ShapeType ( ) ! = TopAbs_VERTEX & & // fix pb with not displayed points
! TopoDS_Iterator ( myShape ) . More ( ) )
return ; // NPAL15983 (Bug when displaying empty groups)
// set interactive object
Handle ( SALOME_InteractiveObject ) anIO ;
if ( ! myIO . IsNull ( ) ) {
AISShape - > setIO ( myIO ) ;
AISShape - > SetOwner ( myIO ) ;
anIO = myIO ;
}
else if ( ! myName . empty ( ) ) {
// workaround to allow selection of temporary objects
static int tempId = 0 ;
anIO = new SALOME_InteractiveObject ( QString ( " TEMP_%1 " ) . arg ( tempId + + ) . toLatin1 ( ) . data ( ) , " GEOM " , myName . c_str ( ) ) ;
AISShape - > setIO ( anIO ) ;
AISShape - > SetOwner ( anIO ) ;
}
// flag: only vertex or compound of vertices is processed (specific handling)
bool onlyVertex = myShape . ShapeType ( ) = = TopAbs_VERTEX | | isCompoundOfVertices ( myShape ) ;
// presentation study entry (empty for temporary objects like preview)
QString entry = ! anIO . IsNull ( ) ? QString ( anIO - > getEntry ( ) ) : QString ( ) ;
// flag: temporary object
bool isTemporary = entry . isEmpty ( ) | | entry . startsWith ( " TEMP_ " ) ;
// currently active view window's ID (-1 if no active view)
int aMgrId = ! anIO . IsNull ( ) ? getViewManagerId ( myViewFrame ) : - 1 ;
// get presentation properties
PropMap propMap = getObjectProperties ( study , entry , myViewFrame ) ;
// Temporary staff: vertex must be infinite for correct visualization
AISShape - > SetInfiniteState ( myShape . Infinite ( ) ) ; // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
// set material
Material_Model material ;
// if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
if ( ! HasColor ( ) )
material . fromProperties ( propMap . value ( GEOM : : propertyName ( GEOM : : Material ) ) . toString ( ) ) ;
// - set front material properties
AISShape - > SetCurrentFacingModel ( Aspect_TOFM_FRONT_SIDE ) ;
AISShape - > SetMaterial ( material . getMaterialOCCAspect ( true ) ) ;
// - set back material properties
AISShape - > SetCurrentFacingModel ( Aspect_TOFM_BACK_SIDE ) ;
AISShape - > SetMaterial ( material . getMaterialOCCAspect ( false ) ) ;
// - switch to default (both sides) facing mode
AISShape - > SetCurrentFacingModel ( Aspect_TOFM_BOTH_SIDE ) ;
// set colors
// - shading color
if ( HasColor ( ) ) {
// predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
// we set it to the shape not taking into account material properties
AISShape - > SetShadingColor ( ( Quantity_NameOfColor ) GetColor ( ) ) ;
}
else if ( ! material . isPhysical ( ) ) {
// shading color from properties is used only for non-physical materials
AISShape - > SetShadingColor ( SalomeApp_Tools : : color ( propMap . value ( GEOM : : propertyName ( GEOM : : ShadingColor ) ) . value < QColor > ( ) ) ) ;
}
// - wireframe color
Handle ( Prs3d_LineAspect ) anAspect = AISShape - > Attributes ( ) - > LineAspect ( ) ;
anAspect - > SetColor ( HasColor ( ) ? ( Quantity_NameOfColor ) GetColor ( ) :
2013-06-17 18:15:50 +06:00
SalomeApp_Tools : : color ( propMap . value ( GEOM : : propertyName ( GEOM : : WireframeColor ) ) . value < QColor > ( ) ) ) ;
2013-02-12 17:35:16 +06:00
AISShape - > Attributes ( ) - > SetLineAspect ( anAspect ) ;
// - unfree boundaries color
anAspect = AISShape - > Attributes ( ) - > UnFreeBoundaryAspect ( ) ;
anAspect - > SetColor ( HasColor ( ) ? ( Quantity_NameOfColor ) GetColor ( ) :
2013-06-17 18:15:50 +06:00
SalomeApp_Tools : : color ( propMap . value ( GEOM : : propertyName ( GEOM : : WireframeColor ) ) . value < QColor > ( ) ) ) ;
2013-02-12 17:35:16 +06:00
AISShape - > Attributes ( ) - > SetUnFreeBoundaryAspect ( anAspect ) ;
// - free boundaries color
anAspect = AISShape - > Attributes ( ) - > FreeBoundaryAspect ( ) ;
anAspect - > SetColor ( HasColor ( ) ? ( Quantity_NameOfColor ) GetColor ( ) :
2013-06-17 18:15:50 +06:00
SalomeApp_Tools : : color ( propMap . value ( GEOM : : propertyName ( GEOM : : FreeBndColor ) ) . value < QColor > ( ) ) ) ;
2013-02-12 17:35:16 +06:00
AISShape - > Attributes ( ) - > SetFreeBoundaryAspect ( anAspect ) ;
// - standalone edges color
anAspect = AISShape - > Attributes ( ) - > WireAspect ( ) ;
anAspect - > SetColor ( HasColor ( ) ? ( Quantity_NameOfColor ) GetColor ( ) :
2013-06-17 18:15:50 +06:00
SalomeApp_Tools : : color ( propMap . value ( GEOM : : propertyName ( GEOM : : LineColor ) ) . value < QColor > ( ) ) ) ;
2013-02-12 17:35:16 +06:00
AISShape - > Attributes ( ) - > SetWireAspect ( anAspect ) ;
// - color for edges in shading+edges mode
AISShape - > SetEdgesInShadingColor ( SalomeApp_Tools : : color ( propMap . value ( GEOM : : propertyName ( GEOM : : OutlineColor ) ) . value < QColor > ( ) ) ) ;
2015-03-23 17:33:25 +05:00
// - color of labels (textual fields and shape name)
AISShape - > SetLabelColor ( qColorFromResources ( " label_color " , QColor ( 255 , 255 , 255 ) ) ) ;
2013-02-12 17:35:16 +06:00
// set display mode
AISShape - > SetDisplayMode ( HasDisplayMode ( ) ?
2013-06-17 18:15:50 +06:00
// predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
GetDisplayMode ( ) :
// display mode from properties
propMap . value ( GEOM : : propertyName ( GEOM : : DisplayMode ) ) . toInt ( ) ) ;
2013-02-12 17:35:16 +06:00
2015-03-13 17:55:24 +05:00
// - face boundaries color and line width
2014-07-17 16:56:46 +06:00
anAspect = AISShape - > Attributes ( ) - > FaceBoundaryAspect ( ) ;
anAspect - > SetColor ( SalomeApp_Tools : : color ( propMap . value ( GEOM : : propertyName ( GEOM : : OutlineColor ) ) . value < QColor > ( ) ) ) ;
2015-04-02 13:59:48 +05:00
anAspect - > SetWidth ( HasWidth ( ) ? GetWidth ( ) : propMap . value ( GEOM : : propertyName ( GEOM : : LineWidth ) ) . toInt ( ) ) ;
2014-07-17 16:56:46 +06:00
AISShape - > Attributes ( ) - > SetFaceBoundaryAspect ( anAspect ) ;
2013-02-12 17:35:16 +06:00
// set display vectors flag
AISShape - > SetDisplayVectors ( propMap . value ( GEOM : : propertyName ( GEOM : : EdgesDirection ) ) . toBool ( ) ) ;
2014-08-27 13:03:29 +06:00
// set display vertices flag
2014-09-15 20:32:37 +06:00
bool isVerticesMode = propMap . value ( GEOM : : propertyName ( GEOM : : Vertices ) ) . toBool ( ) ;
AISShape - > SetDisplayVertices ( isVerticesMode ) ;
2014-08-27 13:03:29 +06:00
2015-03-11 15:18:51 +05:00
// set display name flag
bool isNameMode = propMap . value ( GEOM : : propertyName ( GEOM : : ShowName ) ) . toBool ( ) ;
AISShape - > SetDisplayName ( isNameMode ) ;
2013-02-12 17:35:16 +06:00
// set transparency
2014-01-29 20:00:16 +06:00
if ( HasTransparency ( ) ) {
AISShape - > SetTransparency ( GetTransparency ( ) ) ;
} else {
AISShape - > SetTransparency ( propMap . value ( GEOM : : propertyName ( GEOM : : Transparency ) ) . toDouble ( ) ) ;
}
2013-02-12 17:35:16 +06:00
// set iso properties
int uIsos = propMap . value ( GEOM : : propertyName ( GEOM : : NbIsos ) ) . toString ( ) . split ( GEOM : : subSectionSeparator ( ) ) [ 0 ] . toInt ( ) ;
int vIsos = propMap . value ( GEOM : : propertyName ( GEOM : : NbIsos ) ) . toString ( ) . split ( GEOM : : subSectionSeparator ( ) ) [ 1 ] . toInt ( ) ;
Quantity_Color isosColor = SalomeApp_Tools : : color ( propMap . value ( GEOM : : propertyName ( GEOM : : IsosColor ) ) . value < QColor > ( ) ) ;
int isosWidth = propMap . value ( GEOM : : propertyName ( GEOM : : IsosWidth ) ) . toInt ( ) ;
Handle ( Prs3d_IsoAspect ) uIsoAspect = AISShape - > Attributes ( ) - > UIsoAspect ( ) ;
Handle ( Prs3d_IsoAspect ) vIsoAspect = AISShape - > Attributes ( ) - > VIsoAspect ( ) ;
2014-11-07 20:36:38 +05:00
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 ) ;
}
2013-02-12 17:35:16 +06:00
AISShape - > Attributes ( ) - > SetUIsoAspect ( uIsoAspect ) ;
AISShape - > Attributes ( ) - > SetVIsoAspect ( vIsoAspect ) ;
// set deflection coefficient
// ... to avoid to small values of the coefficient, its lower value is limited
AISShape - > SetOwnDeviationCoefficient ( qMax ( propMap . value ( GEOM : : propertyName ( GEOM : : Deflection ) ) . toDouble ( ) , GEOM : : minDeflection ( ) ) ) ;
// set texture
2014-03-14 15:05:51 +06:00
QString aImagePath ;
2013-02-12 17:35:16 +06:00
if ( HasTexture ( ) ) {
// predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
2014-03-14 15:05:51 +06:00
aImagePath = GetTexture ( ) . c_str ( ) ;
2013-12-18 20:23:59 +06:00
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 ) ;
2014-04-17 18:25:34 +06:00
// Update propeties map
2013-12-18 20:23:59 +06:00
propMap = getObjectProperties ( study , entry , myViewFrame ) ;
}
}
}
else {
2014-03-14 15:05:51 +06:00
aImagePath = propMap . value ( GEOM : : propertyName ( GEOM : : Texture ) ) . toString ( ) ;
2013-12-18 20:23:59 +06:00
}
2014-03-14 15:05:51 +06:00
2014-10-21 19:45:02 +06:00
# ifdef USE_TEXTURED_SHAPE
2014-04-17 18:25:34 +06:00
Handle ( Image_PixMap ) aPixmap ;
if ( ! aImagePath . isEmpty ( ) )
aPixmap = cacheTextureFor ( aImagePath , AISShape ) ;
else
aPixmap = getDefaultTexture ( ) ;
2014-03-14 15:05:51 +06:00
2014-04-17 18:25:34 +06:00
// apply image to shape
if ( ! aPixmap . IsNull ( ) ) {
AISShape - > SetTexturePixMap ( aPixmap ) ;
AISShape - > SetTextureMapOn ( ) ;
AISShape - > DisableTextureModulate ( ) ;
}
else {
AISShape - > SetTextureMapOff ( ) ;
}
2014-10-21 19:45:02 +06:00
# endif
2013-02-12 17:35:16 +06:00
// set line width
AISShape - > SetWidth ( HasWidth ( ) ?
2013-06-17 18:15:50 +06:00
// predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
GetWidth ( ) :
// libe width from properties
propMap . value ( GEOM : : propertyName ( GEOM : : LineWidth ) ) . toInt ( ) ) ;
2013-02-12 17:35:16 +06:00
// set top-level flag
AISShape - > setTopLevel ( propMap . value ( GEOM : : propertyName ( GEOM : : TopLevel ) ) . toBool ( ) ) ;
// set point marker (for vertex / compound of vertices only)
2014-09-15 20:32:37 +06:00
if ( onlyVertex | | isVerticesMode ) {
2013-02-12 17:35:16 +06:00
QStringList aList = propMap . value ( GEOM : : propertyName ( GEOM : : PointMarker ) ) . toString ( ) . split ( GEOM : : subSectionSeparator ( ) ) ;
if ( aList . size ( ) = = 2 ) {
// standard marker string contains "TypeOfMarker:ScaleOfMarker"
int aTypeOfMarker = aList [ 0 ] . toInt ( ) ;
double aScaleOfMarker = ( aList [ 1 ] . toInt ( ) + 1 ) * 0.5 ;
Handle ( Prs3d_PointAspect ) anAspect = AISShape - > Attributes ( ) - > PointAspect ( ) ;
anAspect - > SetScale ( aScaleOfMarker ) ;
anAspect - > SetTypeOfMarker ( ( Aspect_TypeOfMarker ) ( aTypeOfMarker - 1 ) ) ;
anAspect - > SetColor ( HasColor ( ) ?
2013-06-17 18:15:50 +06:00
// 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 < QColor > ( ) ) ) ;
2013-02-12 17:35:16 +06:00
AISShape - > Attributes ( ) - > SetPointAspect ( anAspect ) ;
}
else if ( aList . size ( ) = = 1 ) {
// custom marker string contains "IdOfTexture"
int textureId = aList [ 0 ] . toInt ( ) ;
Standard_Integer aWidth , aHeight ;
Handle ( TColStd_HArray1OfByte ) aTexture =
2013-06-17 18:15:50 +06:00
GeometryGUI : : getTexture ( study , textureId , aWidth , aHeight ) ;
2013-02-12 17:35:16 +06:00
if ( ! aTexture . IsNull ( ) ) {
2013-06-17 18:15:50 +06:00
Handle ( Prs3d_PointAspect ) aTextureAspect =
new Prs3d_PointAspect ( HasColor ( ) ?
2013-09-16 19:59:50 +06:00
// predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
( Quantity_NameOfColor ) GetColor ( ) :
// color from properties
2013-06-17 18:15:50 +06:00
SalomeApp_Tools : : color ( propMap . value ( GEOM : : propertyName ( GEOM : : PointColor ) ) . value < QColor > ( ) ) ,
aWidth , aHeight ,
aTexture ) ;
AISShape - > Attributes ( ) - > SetPointAspect ( aTextureAspect ) ;
2013-02-12 17:35:16 +06:00
}
}
}
2013-10-18 20:00:58 +06:00
// set field step data
AISShape - > setFieldStepInfo ( myFieldDataType ,
myFieldDimension ,
myFieldStepData ,
myFieldStepName ,
myFieldStepRangeMin ,
myFieldStepRangeMax ) ;
2013-02-12 17:35:16 +06:00
if ( create & & ! isTemporary & & aMgrId ! = - 1 ) {
// set properties to the study
2014-10-23 18:33:30 +06:00
study - > setObjectProperties ( aMgrId , entry , propMap ) ;
2013-02-12 17:35:16 +06:00
}
// AISShape->SetName(???); ??? necessary to set name ???
}
void GEOM_Displayer : : updateActorProperties ( GEOM_Actor * actor , bool create )
{
// check that actor is not null
if ( ! actor ) return ;
// check that study is active
SalomeApp_Study * study = getStudy ( ) ;
if ( ! study ) return ;
// set interactive object
Handle ( SALOME_InteractiveObject ) anIO ;
if ( ! myIO . IsNull ( ) ) {
actor - > setIO ( myIO ) ;
anIO = myIO ;
}
else if ( ! myName . empty ( ) ) {
// workaround to allow selection of temporary objects
static int tempId = 0 ;
anIO = new SALOME_InteractiveObject ( QString ( " TEMP_VTK_%1 " ) . arg ( tempId + + ) . toLatin1 ( ) . data ( ) , " GEOM " , myName . c_str ( ) ) ;
actor - > setIO ( anIO ) ;
}
// presentation study entry (empty for temporary objects like preview)
QString entry = ! anIO . IsNull ( ) ? QString ( anIO - > getEntry ( ) ) : QString ( ) ;
// flag: temporary object
bool isTemporary = entry . isEmpty ( ) | | entry . startsWith ( " TEMP_ " ) ;
// currently active view window's ID (-1 if no active view)
int aMgrId = ! anIO . IsNull ( ) ? getViewManagerId ( myViewFrame ) : - 1 ;
// get presentation properties
PropMap propMap = getObjectProperties ( study , entry , myViewFrame ) ;
QColor c ;
/////////////////////////////////////////////////////////////////////////
// VSR: for VTK viewer currently deflection coefficient is hardcoded
// due to performance problem
// actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
/////////////////////////////////////////////////////////////////////////
if ( ! actor - > getTopo ( ) . IsSame ( myShape ) )
2014-11-07 20:37:50 +05:00
# ifdef LIMIT_DEFLECTION_FOR_VTK
2013-02-12 17:35:16 +06:00
actor - > SetShape ( myShape , VTK_MIN_DEFLECTION , myType = = GEOM_VECTOR ) ;
2014-11-07 20:37:50 +05:00
# else
actor - > SetShape ( myShape , qMax ( propMap . value ( GEOM : : propertyName ( GEOM : : Deflection ) ) . toDouble ( ) , GEOM : : minDeflection ( ) ) , myType = = GEOM_VECTOR ) ;
# endif
2013-02-12 17:35:16 +06:00
// set material
Material_Model material ;
material . fromProperties ( propMap . value ( GEOM : : propertyName ( GEOM : : Material ) ) . toString ( ) ) ;
std : : vector < vtkProperty * > mprops ;
mprops . push_back ( material . getMaterialVTKProperty ( true ) ) ;
mprops . push_back ( material . getMaterialVTKProperty ( false ) ) ;
actor - > SetMaterial ( mprops ) ;
// set iso-lines properties
// - set number of iso-lines
int nbIsos [ 2 ] = { 1 , 1 } ;
2014-11-07 20:36:38 +05:00
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 ( ) ;
}
2013-02-12 17:35:16 +06:00
actor - > SetNbIsos ( nbIsos ) ;
// - set iso-lines width
2014-11-07 20:36:38 +05:00
actor - > SetIsosWidth ( HasIsosWidth ( ) ? GetIsosWidth ( ) : propMap . value ( GEOM : : propertyName ( GEOM : : IsosWidth ) ) . toInt ( ) ) ;
2013-02-12 17:35:16 +06:00
// - set iso-lines color
2014-11-07 20:36:38 +05:00
if ( HasIsosColor ( ) )
c = SalomeApp_Tools : : color ( Quantity_Color ( ( Quantity_NameOfColor ) GetIsosColor ( ) ) ) ;
else
c = propMap . value ( GEOM : : propertyName ( GEOM : : IsosColor ) ) . value < QColor > ( ) ;
2013-02-12 17:35:16 +06:00
actor - > SetIsosColor ( c . redF ( ) , c . greenF ( ) , c . blueF ( ) ) ;
// set colors
if ( HasColor ( ) ) {
// - same color for all sub-actors
Quantity_Color aColor ( ( Quantity_NameOfColor ) GetColor ( ) ) ;
actor - > SetColor ( aColor . Red ( ) , aColor . Green ( ) , aColor . Blue ( ) ) ;
}
else {
// shading color (for non-physical materials)
if ( ! material . isPhysical ( ) ) {
c = propMap . value ( GEOM : : propertyName ( GEOM : : ShadingColor ) ) . value < QColor > ( ) ;
actor - > GetFrontMaterial ( ) - > SetColor ( c . redF ( ) , c . greenF ( ) , c . blueF ( ) ) ;
actor - > GetBackMaterial ( ) - > SetColor ( c . redF ( ) , c . greenF ( ) , c . blueF ( ) ) ;
}
// - standalone edge color
2014-04-17 14:59:38 +06:00
c = propMap . value ( GEOM : : propertyName ( GEOM : : LineColor ) ) . value < QColor > ( ) ;
2013-02-12 17:35:16 +06:00
actor - > SetIsolatedEdgeColor ( c . redF ( ) , c . greenF ( ) , c . blueF ( ) ) ;
c = propMap . value ( GEOM : : propertyName ( GEOM : : WireframeColor ) ) . value < QColor > ( ) ;
// - shared edges color ???
actor - > SetSharedEdgeColor ( c . redF ( ) , c . greenF ( ) , c . blueF ( ) ) ;
c = propMap . value ( GEOM : : propertyName ( GEOM : : FreeBndColor ) ) . value < QColor > ( ) ;
// - free edges color ???
actor - > SetFreeEdgeColor ( c . redF ( ) , c . greenF ( ) , c . blueF ( ) ) ;
// - point color
c = propMap . value ( GEOM : : propertyName ( GEOM : : PointColor ) ) . value < QColor > ( ) ;
actor - > SetPointColor ( c . redF ( ) , c . greenF ( ) , c . blueF ( ) ) ;
}
// - color for edges in shading+edges mode
c = propMap . value ( GEOM : : propertyName ( GEOM : : OutlineColor ) ) . value < QColor > ( ) ;
actor - > SetEdgesInShadingColor ( c . redF ( ) , c . greenF ( ) , c . blueF ( ) ) ;
2015-03-23 17:33:25 +05:00
// - color of labels (shape name)
c = colorFromResources ( " label_color " , QColor ( 255 , 255 , 255 ) ) ;
actor - > SetLabelColor ( c . redF ( ) , c . greenF ( ) , c . blueF ( ) ) ;
2013-02-12 17:35:16 +06:00
// set opacity
2014-01-29 20:00:16 +06:00
if ( HasTransparency ( ) ) {
actor - > SetOpacity ( 1.0 - GetTransparency ( ) ) ;
} else {
actor - > SetOpacity ( 1.0 - propMap . value ( GEOM : : propertyName ( GEOM : : Transparency ) ) . toDouble ( ) ) ;
}
2013-02-12 17:35:16 +06:00
// set line width
actor - > SetWidth ( HasWidth ( ) ?
2013-06-17 18:15:50 +06:00
// predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
GetWidth ( ) :
// libe width from properties
propMap . value ( GEOM : : propertyName ( GEOM : : LineWidth ) ) . toInt ( ) ) ;
2013-02-12 17:35:16 +06:00
// set display vectors flag
actor - > SetVectorMode ( propMap . value ( GEOM : : propertyName ( GEOM : : EdgesDirection ) ) . toBool ( ) ) ;
2014-08-27 13:03:29 +06:00
// set display vertices flag
actor - > SetVerticesMode ( propMap . value ( GEOM : : propertyName ( GEOM : : Vertices ) ) . toBool ( ) ) ;
2015-03-11 15:18:51 +05:00
// set display name flag
actor - > SetNameMode ( propMap . value ( GEOM : : propertyName ( GEOM : : ShowName ) ) . toBool ( ) ) ;
2013-02-12 17:35:16 +06:00
// set display mode
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 ( ) ;
// specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
// Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
// GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
// eWireframe - 0, eShading - 1, eShadingWithEdges - 3
if ( displayMode = = 2 )
// this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
// enum in GEOM_Actor (and further to VTKViewer::Representation enum)
displayMode + + ;
actor - > setDisplayMode ( displayMode ) ;
if ( myToActivate )
actor - > PickableOn ( ) ;
else
actor - > PickableOff ( ) ;
if ( create & & ! isTemporary & & aMgrId ! = - 1 ) {
// set properties to the study
2014-10-23 18:33:30 +06:00
study - > setObjectProperties ( aMgrId , entry , propMap ) ;
2013-02-12 17:35:16 +06:00
}
}
2014-01-15 15:27:18 +06:00
//=================================================================
/*!
* 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 < SOCC_Prs * > ( 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 ) ;
2014-01-21 22:42:20 +06:00
if ( ! aIterateIO . More ( ) )
{
break ;
}
2014-01-15 15:27:18 +06:00
}
// 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 ) ;
2015-05-19 13:15:20 +05:00
QFont aFont = aResMgr - > fontValue ( " Geometry " , " dimensions_font " , QFont ( " Y14.5M-2009 " , 14 ) ) ;
2014-01-15 15:27:18 +06:00
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 " ) ;
2015-05-19 13:15:20 +05:00
bool aUseText3d = aResMgr - > booleanValue ( " Geometry " , " dimensions_use_text3d " , false ) ;
2014-01-15 15:27:18 +06:00
// 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 < GEOMGUI_DimensionProperty > ( ) )
{
aRecords = aProperty . value < GEOMGUI_DimensionProperty > ( ) ;
}
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 ) ;
2015-05-19 13:15:20 +05:00
aStyle - > MakeText3d ( aUseText3d ) ;
2014-01-15 15:27:18 +06:00
aStyle - > MakeTextShaded ( Standard_True ) ;
2015-05-19 13:15:20 +05:00
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 ) ;
2014-01-15 15:27:18 +06:00
aStyle - > ArrowAspect ( ) - > SetLength ( anArrowLength ) ;
aStyle - > LineAspect ( ) - > SetWidth ( aLineWidth ) ;
aStyle - > SetTextHorizontalPosition ( aPrs - > DimensionAspect ( ) - > TextHorizontalPosition ( ) ) ;
aStyle - > SetTextVerticalPosition ( aPrs - > DimensionAspect ( ) - > TextVerticalPosition ( ) ) ;
2014-01-21 20:56:21 +06:00
aStyle - > SetArrowOrientation ( aPrs - > DimensionAspect ( ) - > ArrowOrientation ( ) ) ;
2014-01-15 15:27:18 +06:00
aPrs - > SetDimensionAspect ( aStyle ) ;
aPrs - > SetPolygonOffsets ( Aspect_POM_Fill , - 1.0 , - 1.0 ) ;
2014-01-21 18:51:45 +06:00
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 ) ;
}
2014-01-15 15:27:18 +06:00
aListOfIO . Append ( aPrs ) ;
}
// update presentation
anOccPrs - > Clear ( ) ;
for ( aIterateIO . Initialize ( aListOfIO ) ; aIterateIO . More ( ) ; aIterateIO . Next ( ) )
{
anOccPrs - > AddObject ( aIterateIO . Value ( ) ) ;
}
}
2004-12-01 15:39:14 +05:00
//=================================================================
/*!
* GEOM_Displayer : : Erase
* Calls Erase ( ) method for each object in the given list
*/
//=================================================================
void GEOM_Displayer : : Erase ( const SALOME_ListIO & theIOList ,
const bool forced ,
const bool updateViewer )
{
SALOME_ListIteratorOfListIO Iter ( theIOList ) ;
for ( ; Iter . More ( ) ; Iter . Next ( ) )
Erase ( Iter . Value ( ) , forced , false ) ;
if ( updateViewer )
UpdateViewer ( ) ;
}
//=================================================================
/*!
* GEOM_Displayer : : Redisplay
* Calls Redisplay ( ) method for each object in the given list
*/
//=================================================================
2013-10-18 20:00:58 +06:00
void GEOM_Displayer : : Redisplay ( const SALOME_ListIO & theIOList ,
const bool updateViewer ,
const bool checkActiveViewer )
2004-12-01 15:39:14 +05:00
{
SALOME_ListIteratorOfListIO Iter ( theIOList ) ;
2005-06-02 13:17:09 +06:00
for ( ; Iter . More ( ) ; Iter . Next ( ) )
2013-10-18 20:00:58 +06:00
Redisplay ( Iter . Value ( ) , false , checkActiveViewer ) ;
2005-06-02 13:17:09 +06:00
2004-12-01 15:39:14 +05:00
if ( updateViewer )
UpdateViewer ( ) ;
}
2014-01-15 15:27:18 +06:00
//=================================================================
/*!
* 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 ( ) ;
}
}
2004-12-01 15:39:14 +05:00
//=================================================================
/*!
* GEOM_Displayer : : Update
* Update OCC presentaion
* [ Reimplemented from SALOME_Displayer ]
*/
//=================================================================
void GEOM_Displayer : : Update ( SALOME_OCCPrs * prs )
{
2005-06-02 13:17:09 +06:00
SOCC_Prs * occPrs = dynamic_cast < SOCC_Prs * > ( prs ) ;
2013-02-12 17:35:16 +06:00
SalomeApp_Study * study = getStudy ( ) ;
if ( ! occPrs | | myShape . IsNull ( ) | | ! study )
2004-12-01 15:39:14 +05:00
return ;
2013-02-12 17:35:16 +06:00
if ( myType = = GEOM_MARKER & & myShape . ShapeType ( ) = = TopAbs_FACE )
2004-12-01 15:39:14 +05:00
{
2013-02-12 17:35:16 +06:00
//
// specific processing for local coordinate system presentation
//
2004-12-01 15:39:14 +05:00
TopoDS_Face aFace = TopoDS : : Face ( myShape ) ;
Handle ( Geom_Plane ) aPlane = Handle ( Geom_Plane ) : : DownCast ( BRep_Tool : : Surface ( aFace ) ) ;
if ( ! aPlane . IsNull ( ) )
{
gp_Ax3 aPos = aPlane - > Pln ( ) . Position ( ) ;
Handle ( Geom_Axis2Placement ) aPlc = new Geom_Axis2Placement ( aPos . Ax2 ( ) ) ;
Handle ( GEOM_AISTrihedron ) aTrh ;
if ( occPrs - > IsNull ( ) )
{
2013-06-17 18:15:50 +06:00
// new presentation is being created
2004-12-01 15:39:14 +05:00
aTrh = new GEOM_AISTrihedron ( aPlc ) ;
occPrs - > AddObject ( aTrh ) ;
}
else
{
2013-06-17 18:15:50 +06:00
// presentation is being updated
2004-12-01 15:39:14 +05:00
AIS_ListOfInteractive aList ;
occPrs - > GetObjects ( aList ) ;
AIS_ListIteratorOfListOfInteractive anIter ( aList ) ;
2013-02-12 17:35:16 +06:00
for ( ; anIter . More ( ) & & aTrh . IsNull ( ) ; anIter . Next ( ) ) {
2004-12-01 15:39:14 +05:00
aTrh = Handle ( GEOM_AISTrihedron ) : : DownCast ( anIter . Value ( ) ) ;
2013-06-17 18:15:50 +06:00
}
2013-02-12 17:35:16 +06:00
}
2013-06-17 18:15:50 +06:00
2013-02-12 17:35:16 +06:00
if ( ! aTrh . IsNull ( ) ) {
2013-06-17 18:15:50 +06:00
// predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
2013-02-12 17:35:16 +06:00
if ( HasColor ( ) )
aTrh - > SetColor ( ( Quantity_NameOfColor ) GetColor ( ) ) ;
2013-06-17 18:15:50 +06:00
// predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
2013-02-12 17:35:16 +06:00
if ( HasWidth ( ) )
aTrh - > SetWidth ( GetWidth ( ) ) ;
2013-06-17 18:15:50 +06:00
2013-02-12 17:35:16 +06:00
if ( ! myIO . IsNull ( ) )
{
aTrh - > setIO ( myIO ) ;
aTrh - > SetOwner ( myIO ) ;
2004-12-01 15:39:14 +05:00
}
2013-06-17 18:15:50 +06:00
aTrh - > SetComponent ( aPlc ) ;
aTrh - > SetToUpdate ( ) ;
2004-12-01 15:39:14 +05:00
}
occPrs - > SetToActivate ( ToActivate ( ) ) ;
}
}
else
{
2013-02-12 17:35:16 +06:00
//
// processing for usual geometry presentation
//
2004-12-01 15:39:14 +05:00
// if presentation is empty we try to create new one
if ( occPrs - > IsNull ( ) )
{
2013-02-12 17:35:16 +06:00
// create presentation (specific for vectors)
Handle ( GEOM_AISShape ) AISShape = ( myType = = GEOM_VECTOR ) ? new GEOM_AISVector ( myShape , " " )
2013-06-17 18:15:50 +06:00
: new GEOM_AISShape ( myShape , " " ) ;
2013-11-18 19:39:39 +06:00
if ( myType = = GEOM_FIELD_STEP )
AISShape - > SetHilightMode ( GEOM_AISShape : : CustomHighlight ) ;
2013-02-12 17:35:16 +06:00
// update shape properties
updateShapeProperties ( AISShape , true ) ;
2008-03-07 12:45:34 +05:00
2013-02-12 17:35:16 +06:00
// add shape to the presentation
occPrs - > AddObject ( AISShape ) ;
2008-03-07 12:45:34 +05:00
2013-02-12 17:35:16 +06:00
// In accordance with ToActivate() value object will be activated/deactivated
// when it will be displayed
occPrs - > SetToActivate ( ToActivate ( ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
if ( AISShape - > isTopLevel ( ) & & GEOM_AISShape : : topLevelDisplayMode ( ) = = GEOM_AISShape : : TopShowAdditionalWActor ) {
2013-06-17 18:15:50 +06:00
// 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
// create additional wireframe shape
Handle ( GEOM_TopWireframeShape ) aWirePrs = new GEOM_TopWireframeShape ( myShape ) ;
aWirePrs - > SetWidth ( AISShape - > Width ( ) ) ;
if ( ! myIO . IsNull ( ) ) {
aWirePrs - > setIO ( myIO ) ;
aWirePrs - > SetOwner ( myIO ) ;
}
// add shape to the presentation
occPrs - > AddObject ( aWirePrs ) ;
2004-12-01 15:39:14 +05:00
}
}
// if presentation is found -> set again shape for it
else
{
2013-02-12 17:35:16 +06:00
AIS_ListOfInteractive IOList ;
occPrs - > GetObjects ( IOList ) ;
AIS_ListIteratorOfListOfInteractive Iter ( IOList ) ;
for ( ; Iter . More ( ) ; Iter . Next ( ) )
2004-12-01 15:39:14 +05:00
{
2013-06-17 18:15:50 +06:00
Handle ( GEOM_AISShape ) AISShape = Handle ( GEOM_AISShape ) : : DownCast ( Iter . Value ( ) ) ;
if ( AISShape . IsNull ( ) )
continue ;
2013-02-12 17:35:16 +06:00
2013-06-17 18:15:50 +06:00
// re-set shape (it might be changed)
if ( AISShape - > Shape ( ) ! = myShape )
AISShape - > Set ( myShape ) ;
2013-02-12 17:35:16 +06:00
2013-06-17 18:15:50 +06:00
// update shape properties
updateShapeProperties ( AISShape , false ) ;
2013-02-12 17:35:16 +06:00
2013-06-17 18:15:50 +06:00
// force updating
AISShape - > UpdateSelection ( ) ;
AISShape - > SetToUpdate ( ) ;
2004-12-01 15:39:14 +05:00
}
}
2014-01-15 15:27:18 +06:00
2014-01-21 22:42:20 +06:00
updateDimensions ( myIO , occPrs , gp_Ax3 ( ) . Transformed ( myShape . Location ( ) . Transformation ( ) ) ) ;
2004-12-01 15:39:14 +05:00
}
}
//=================================================================
/*!
* GEOM_Displayer : : Update
* Update VTK presentaion
* [ Reimplemented from SALOME_Displayer ]
*/
//=================================================================
void GEOM_Displayer : : Update ( SALOME_VTKPrs * prs )
{
2005-06-02 13:17:09 +06:00
SVTK_Prs * vtkPrs = dynamic_cast < SVTK_Prs * > ( prs ) ;
2013-02-12 17:35:16 +06:00
SalomeApp_Study * study = getStudy ( ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
if ( ! vtkPrs | | myShape . IsNull ( ) | | ! study )
2004-12-01 15:39:14 +05:00
return ;
2013-02-12 17:35:16 +06:00
if ( myType = = GEOM_MARKER & & myShape . ShapeType ( ) = = TopAbs_FACE )
{
//
// specific processing for local coordinate system presentation
//
2005-08-18 12:15:31 +06:00
2013-02-12 17:35:16 +06:00
TopoDS_Face aFace = TopoDS : : Face ( myShape ) ;
Handle ( Geom_Plane ) aPlane = Handle ( Geom_Plane ) : : DownCast ( BRep_Tool : : Surface ( aFace ) ) ;
if ( ! aPlane . IsNull ( ) ) {
gp_Ax3 aPos = aPlane - > Pln ( ) . Position ( ) ;
Handle ( Geom_Axis2Placement ) aPlc = new Geom_Axis2Placement ( aPos . Ax2 ( ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
GEOM_VTKTrihedron * aTrh = 0 ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
if ( vtkPrs - > IsNull ( ) ) {
2013-06-17 18:15:50 +06:00
// new presentation is being created
aTrh = GEOM_VTKTrihedron : : New ( ) ;
vtkPrs - > AddObject ( aTrh ) ;
2013-02-12 17:35:16 +06:00
}
else {
2013-06-17 18:15:50 +06:00
// presentation is being updated
vtkActorCollection * actors = vtkPrs - > GetObjects ( ) ;
if ( actors ) {
actors - > InitTraversal ( ) ;
vtkActor * a = actors - > GetNextActor ( ) ;
while ( a & & ! aTrh ) {
aTrh = GEOM_VTKTrihedron : : SafeDownCast ( a ) ;
a = actors - > GetNextActor ( ) ;
}
}
2013-02-12 17:35:16 +06:00
}
if ( aTrh ) {
2013-06-17 18:15:50 +06:00
// predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
if ( HasColor ( ) ) {
Quantity_Color aColor ( ( Quantity_NameOfColor ) GetColor ( ) ) ;
aTrh - > SetColor ( aColor . Red ( ) , aColor . Green ( ) , aColor . Blue ( ) ) ;
}
2013-02-12 17:35:16 +06:00
# ifdef VTK_TRIHEDRON_WIDTH
2013-06-17 18:15:50 +06:00
//
// VSR: currently isn't supported
//
// predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
2013-02-12 17:35:16 +06:00
if ( HasWidth ( ) )
aTrh - > SetWidth ( GetWidth ( ) ) ;
# endif
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
if ( ! myIO . IsNull ( ) )
2013-06-17 18:15:50 +06:00
aTrh - > setIO ( myIO ) ;
2012-08-09 13:58:02 +06:00
2013-06-17 18:15:50 +06:00
aTrh - > SetPlacement ( aPlc ) ;
2013-02-12 17:35:16 +06:00
}
2012-08-09 13:58:02 +06:00
}
2008-03-07 12:45:34 +05:00
}
2013-02-12 17:35:16 +06:00
else
2004-12-01 15:39:14 +05:00
{
2013-02-12 17:35:16 +06:00
//
// processing for usual geometry presentation
//
2004-12-01 15:39:14 +05:00
2013-02-12 17:35:16 +06:00
// if presentation is empty we try to create new one
if ( vtkPrs - > IsNull ( ) )
2004-12-01 15:39:14 +05:00
{
2013-02-12 17:35:16 +06:00
// create an actor
GEOM_Actor * actor = GEOM_Actor : : New ( ) ;
// update actor properties
updateActorProperties ( actor , true ) ;
// add actor to the presentation
vtkPrs - > AddObject ( actor ) ;
2012-08-09 13:58:02 +06:00
}
2013-02-12 17:35:16 +06:00
else {
// presentation is being updated
vtkActorCollection * actors = vtkPrs - > GetObjects ( ) ;
if ( actors ) {
2013-06-17 18:15:50 +06:00
actors - > InitTraversal ( ) ;
vtkActor * a = actors - > GetNextActor ( ) ;
while ( a ) {
GEOM_Actor * actor = GEOM_Actor : : SafeDownCast ( a ) ;
if ( actor ) {
// update actor properties
updateActorProperties ( actor , false ) ;
a = actors - > GetNextActor ( ) ;
}
}
2012-08-09 13:58:02 +06:00
}
2004-12-01 15:39:14 +05:00
}
}
}
//=================================================================
/*!
* GEOM_Displayer : : BuildPrs
* Build presentation accordint to the current viewer type
*/
//=================================================================
SALOME_Prs * GEOM_Displayer : : BuildPrs ( GEOM : : GEOM_Object_ptr theObj )
{
if ( theObj - > _is_nil ( ) )
return 0 ;
myViewFrame = GetActiveView ( ) ;
if ( myViewFrame = = 0 )
return 0 ;
2005-08-18 12:15:31 +06:00
2004-12-01 15:39:14 +05:00
SALOME_Prs * aPrs = myViewFrame - > CreatePrs ( ) ;
if ( aPrs = = 0 )
return 0 ;
2005-08-18 12:15:31 +06:00
internalReset ( ) ;
2012-08-09 13:58:02 +06:00
setShape ( GEOM_Client : : get_client ( ) . GetShape ( GeometryGUI : : GetGeomGen ( ) , theObj ) ) ;
2004-12-01 15:39:14 +05:00
myType = theObj - > GetType ( ) ;
// Update presentation
2005-08-18 12:15:31 +06:00
UpdatePrs ( aPrs ) ;
2004-12-01 15:39:14 +05:00
return aPrs ;
}
//=================================================================
/*!
* GEOM_Displayer : : BuildPrs
* Build presentation accordint to the current viewer type
*/
//=================================================================
SALOME_Prs * GEOM_Displayer : : BuildPrs ( const TopoDS_Shape & theShape )
{
myViewFrame = GetActiveView ( ) ;
if ( theShape . IsNull ( ) | | myViewFrame = = 0 )
return 0 ;
SALOME_Prs * aPrs = myViewFrame - > CreatePrs ( ) ;
if ( aPrs = = 0 )
return 0 ;
internalReset ( ) ;
setShape ( theShape ) ;
myType = - 1 ;
UpdatePrs ( aPrs ) ;
return aPrs ;
}
//=================================================================
/*!
* GEOM_Displayer : : buildPresentation
* Builds / finds object ' s presentation for the current viewer
* Calls corresponding Update ( ) method by means of double dispatch
2005-08-18 12:15:31 +06:00
* [ internal ]
2004-12-01 15:39:14 +05:00
*/
//=================================================================
2005-09-27 12:32:15 +06:00
SALOME_Prs * GEOM_Displayer : : buildPresentation ( const QString & entry ,
2012-08-09 13:58:02 +06:00
SALOME_View * theViewFrame )
2004-12-01 15:39:14 +05:00
{
SALOME_Prs * prs = 0 ;
internalReset ( ) ;
2005-06-02 13:17:09 +06:00
myViewFrame = theViewFrame ? theViewFrame : GetActiveView ( ) ;
2005-08-18 12:15:31 +06:00
if ( myViewFrame )
2005-06-02 13:17:09 +06:00
{
2005-11-03 13:30:14 +05:00
prs = LightApp_Displayer : : buildPresentation ( entry , theViewFrame ) ;
2005-08-18 12:15:31 +06:00
if ( prs )
2005-06-02 13:17:09 +06:00
{
2005-09-27 12:32:15 +06:00
Handle ( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject ( ) ;
2009-02-13 17:16:39 +05:00
theIO - > setEntry ( entry . toLatin1 ( ) . constData ( ) ) ;
2005-08-18 12:15:31 +06:00
if ( ! theIO . IsNull ( ) )
2005-06-02 13:17:09 +06:00
{
2012-08-09 13:58:02 +06:00
// set interactive object
setIO ( theIO ) ;
// Find SOBject (because shape should be published previously)
SUIT_Session * session = SUIT_Session : : session ( ) ;
SUIT_Application * app = session - > activeApplication ( ) ;
if ( app )
{
SalomeApp_Study * study = dynamic_cast < SalomeApp_Study * > ( app - > activeStudy ( ) ) ;
if ( study )
{
_PTR ( SObject ) SO ( study - > studyDS ( ) - > FindObjectID ( theIO - > getEntry ( ) ) ) ;
if ( SO )
{
// get CORBA reference to data object
CORBA : : Object_var object = GeometryGUI : : ClientSObjectToObject ( SO ) ;
if ( ! CORBA : : is_nil ( object ) )
{
2013-10-18 20:00:58 +06:00
// downcast to GEOM base object
GEOM : : GEOM_BaseObject_var GeomBaseObject = GEOM : : GEOM_BaseObject : : _narrow ( object ) ;
if ( ! GeomBaseObject - > _is_nil ( ) )
2012-08-09 13:58:02 +06:00
{
2013-10-18 20:00:58 +06:00
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 ( ) )
{
2015-03-11 15:18:51 +05:00
theIO - > setName ( GeomObject - > GetName ( ) ) ;
2013-10-18 20:00:58 +06:00
// finally set shape
setShape ( GEOM_Client : : get_client ( ) . GetShape ( GeometryGUI : : GetGeomGen ( ) , GeomObject ) ) ;
}
2012-08-09 13:58:02 +06:00
}
}
}
}
}
2004-12-01 15:39:14 +05:00
}
UpdatePrs ( prs ) ; // Update presentation by using of the double dispatch
}
}
return prs ;
}
2012-08-09 13:58:02 +06:00
//=================================================================
/*!
* GEOM_Displayer : : buildSubshapePresentation
* Builds / finds object ' s presentation for the current viewer
* Calls corresponding Update ( ) method by means of double dispatch
* For not published objects ( for Mantis issue 0020435 )
*/
//=================================================================
SALOME_Prs * GEOM_Displayer : : buildSubshapePresentation ( const TopoDS_Shape & aShape ,
const QString & entry ,
SALOME_View * theViewFrame )
{
SALOME_Prs * prs = 0 ;
internalReset ( ) ;
myViewFrame = theViewFrame ? theViewFrame : GetActiveView ( ) ;
if ( myViewFrame )
{
prs = LightApp_Displayer : : buildPresentation ( entry , theViewFrame ) ;
if ( prs )
{
Handle ( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject ( ) ;
theIO - > setEntry ( entry . toLatin1 ( ) . constData ( ) ) ;
if ( ! theIO . IsNull ( ) )
{
// set interactive object
setIO ( theIO ) ;
// finally set shape
setShape ( aShape ) ;
myType = GEOM_SUBSHAPE ;
}
UpdatePrs ( prs ) ; // Update presentation by using of the double dispatch
}
}
return prs ;
}
2004-12-01 15:39:14 +05:00
//=================================================================
/*!
* GEOM_Displayer : : internalReset
* Resets internal data
* [ internal ]
*/
//=================================================================
void GEOM_Displayer : : internalReset ( )
{
myIO . Nullify ( ) ;
myShape . Nullify ( ) ;
2013-10-18 20:00:58 +06:00
myFieldDataType = GEOM : : FDT_Double ;
myFieldDimension = 0 ;
myFieldStepData . clear ( ) ;
myFieldStepName . Clear ( ) ;
myFieldStepRangeMin = 0 ;
myFieldStepRangeMax = 0 ;
2004-12-01 15:39:14 +05:00
}
//=================================================================
/*!
* GEOM_Displayer : : LocalSelection
* Activate selection of CAD shapes with activisation of selection
* of their sub - shapes ( with opened local context for OCC viewer )
*/
//=================================================================
2014-11-19 17:40:00 +05:00
void GEOM_Displayer : : LocalSelection ( const Handle ( SALOME_InteractiveObject ) & theIO , const std : : list < int > modes )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SUIT_Session * session = SUIT_Session : : session ( ) ;
SalomeApp_Application * app = dynamic_cast < SalomeApp_Application * > ( session - > activeApplication ( ) ) ;
if ( ! app )
return ;
2004-12-01 15:39:14 +05:00
2005-11-03 13:30:14 +05:00
LightApp_SelectionMgr * sm = app - > selectionMgr ( ) ;
2005-08-18 12:15:31 +06:00
2005-06-02 13:17:09 +06:00
// remove all filters from selection
sm - > clearFilters ( ) ;
2004-12-01 15:39:14 +05:00
2005-06-02 13:17:09 +06:00
SALOME_View * vf = GetActiveView ( ) ;
2006-02-07 20:58:35 +05:00
if ( vf ) {
if ( ! theIO . IsNull ( ) & & ! vf - > isVisible ( theIO ) )
Display ( theIO ) ;
SALOME_Prs * prs = vf - > CreatePrs ( theIO . IsNull ( ) ? 0 : theIO - > getEntry ( ) ) ;
2014-11-19 17:40:00 +05:00
vf - > LocalSelection ( prs , modes ) ;
2006-02-07 20:58:35 +05:00
delete prs ; // delete presentation because displayer is its owner
}
2004-12-01 15:39:14 +05:00
}
2014-11-19 17:40:00 +05:00
//=================================================================
/*!
* 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 < int > modes ;
modes . push_back ( theMode ) ;
LocalSelection ( theIO , modes ) ;
}
2004-12-01 15:39:14 +05:00
//=================================================================
/*!
* GEOM_Displayer : : globalSelection
* Activate selection of CAD shapes without activisation of selection
* of their sub - shapes ( without opened local context for OCC viewer )
*/
//=================================================================
void GEOM_Displayer : : GlobalSelection ( const int theMode , const bool update )
{
TColStd_MapOfInteger aModes ;
aModes . Add ( theMode ) ;
GlobalSelection ( aModes , update ) ;
}
//=================================================================
/*!
* GEOM_Displayer : : globalSelection
* Activate selection of CAD shapes without activisation of selection
* of their sub - shapes ( without opened local context for OCC viewer )
*/
//=================================================================
void GEOM_Displayer : : GlobalSelection ( const TColStd_MapOfInteger & theModes ,
2012-08-09 13:58:02 +06:00
const bool update , const QList < int > * theSubShapes )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SUIT_Session * session = SUIT_Session : : session ( ) ;
SalomeApp_Application * app = dynamic_cast < SalomeApp_Application * > ( session - > activeApplication ( ) ) ;
if ( ! app )
return ;
2005-08-18 12:15:31 +06:00
2005-06-02 13:17:09 +06:00
SALOME_View * vf = GetActiveView ( ) ;
2004-12-01 15:39:14 +05:00
if ( vf = = 0 )
return ;
2005-08-18 12:15:31 +06:00
2004-12-01 15:39:14 +05:00
// Close local context
vf - > GlobalSelection ( update ) ;
// Set selection filters in accordance with current mode
2005-11-03 13:30:14 +05:00
LightApp_SelectionMgr * sm = app - > selectionMgr ( ) ;
2005-06-02 13:17:09 +06:00
if ( ! sm )
return ;
2004-12-01 15:39:14 +05:00
// Remove from selection temporary objects if necessary
if ( ! theModes . Contains ( GEOM_PREVIEW ) )
2005-06-02 13:17:09 +06:00
clearTemporary ( sm ) ;
2004-12-01 15:39:14 +05:00
2005-06-02 13:17:09 +06:00
//@ aSel->ClearIndex();
2005-08-18 12:15:31 +06:00
2005-06-02 13:17:09 +06:00
sm - > clearFilters ( ) ;
2005-08-18 12:15:31 +06:00
2005-06-02 13:17:09 +06:00
// Remove filters from AIS_InteractiveContext
Handle ( AIS_InteractiveContext ) ic ;
SOCC_Viewer * viewer = dynamic_cast < SOCC_Viewer * > ( vf ) ;
if ( viewer )
{
ic = viewer - > getAISContext ( ) ;
if ( ! ic . IsNull ( ) )
2012-08-09 13:58:02 +06:00
ic - > RemoveFilters ( ) ;
2005-06-02 13:17:09 +06:00
}
2005-08-18 12:15:31 +06:00
2004-12-01 15:39:14 +05:00
if ( theModes . Contains ( GEOM_ALLOBJECTS ) )
return ;
2005-06-02 13:17:09 +06:00
SUIT_SelectionFilter * aFilter ;
2004-12-01 15:39:14 +05:00
if ( theModes . Extent ( ) = = 1 )
2005-06-02 13:17:09 +06:00
{
int aMode = TColStd_MapIteratorOfMapOfInteger ( theModes ) . Key ( ) ;
2012-08-09 13:58:02 +06:00
2009-02-13 17:16:39 +05:00
if ( aMode = = GEOM_COMPOUNDFILTER )
aFilter = getComplexFilter ( theSubShapes ) ;
2012-08-09 13:58:02 +06:00
else
2009-02-13 17:16:39 +05:00
aFilter = getFilter ( aMode ) ;
2005-06-02 13:17:09 +06:00
}
2004-12-01 15:39:14 +05:00
else if ( theModes . Extent ( ) > 1 )
{
2005-06-02 13:17:09 +06:00
TColStd_MapOfInteger aTopAbsModes ;
TColStd_MapIteratorOfMapOfInteger anIter ( theModes ) ;
2009-02-13 17:16:39 +05:00
QList < SUIT_SelectionFilter * > aListOfFilters ;
2005-06-02 13:17:09 +06:00
for ( ; anIter . More ( ) ; anIter . Next ( ) )
2012-08-09 13:58:02 +06:00
{
2009-02-13 17:16:39 +05:00
SUIT_SelectionFilter * aFilter ;
int aMode = anIter . Key ( ) ;
if ( aMode = = GEOM_COMPOUNDFILTER )
aFilter = getComplexFilter ( theSubShapes ) ;
2012-08-09 13:58:02 +06:00
else
2009-02-13 17:16:39 +05:00
aFilter = getFilter ( aMode ) ;
2012-08-09 13:58:02 +06:00
if ( aFilter )
aListOfFilters . append ( aFilter ) ;
}
2005-08-18 12:15:31 +06:00
2005-06-02 13:17:09 +06:00
aFilter = new GEOM_LogicalFilter ( aListOfFilters , GEOM_LogicalFilter : : LO_OR ) ;
2004-12-01 15:39:14 +05:00
}
else
return ;
2005-06-02 13:17:09 +06:00
if ( aFilter )
{
sm - > installFilter ( aFilter ) ;
if ( ! ic . IsNull ( ) )
2012-08-09 13:58:02 +06:00
{
Handle ( GEOM_OCCFilter ) anOCCFilter = new GEOM_OCCFilter ( sm ) ;
ic - > AddFilter ( anOCCFilter ) ;
}
2005-06-02 13:17:09 +06:00
}
2004-12-01 15:39:14 +05:00
}
//=================================================================
/*!
* GEOM_Displayer : : LocalSelection
* Activate selection of CAD shapes with activisation of selection
* of their sub - shapes ( with opened local context for OCC viewer )
*/
//=================================================================
2014-11-19 17:40:00 +05:00
void GEOM_Displayer : : LocalSelection ( const SALOME_ListIO & theIOList , const std : : list < int > modes )
2004-12-01 15:39:14 +05:00
{
SALOME_ListIteratorOfListIO Iter ( theIOList ) ;
2005-08-18 12:15:31 +06:00
for ( ; Iter . More ( ) ; Iter . Next ( ) )
2014-11-19 17:40:00 +05:00
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 < int > modes ;
modes . push_back ( theMode ) ;
LocalSelection ( theIOList , modes ) ;
2004-12-01 15:39:14 +05:00
}
//=================================================================
/*!
* GEOM_Displayer : : BeforeDisplay
* Called before displaying of pars . Close local context
* [ Reimplemented from SALOME_Displayer ]
*/
//=================================================================
2012-08-09 13:58:02 +06:00
void GEOM_Displayer : : BeforeDisplay ( SALOME_View * v , const SALOME_OCCPrs * )
2004-12-01 15:39:14 +05:00
{
2005-06-02 13:17:09 +06:00
SOCC_Viewer * vf = dynamic_cast < SOCC_Viewer * > ( v ) ;
2004-12-01 15:39:14 +05:00
if ( vf )
{
2005-06-02 13:17:09 +06:00
Handle ( AIS_InteractiveContext ) ic = vf - > getAISContext ( ) ;
2004-12-01 15:39:14 +05:00
if ( ! ic . IsNull ( ) )
{
if ( ic - > HasOpenedContext ( ) )
ic - > CloseAllContexts ( ) ;
}
}
}
2012-08-09 13:58:02 +06:00
void GEOM_Displayer : : AfterDisplay ( SALOME_View * v , const SALOME_OCCPrs * p )
2004-12-01 15:39:14 +05:00
{
2013-11-15 16:17:50 +06:00
UpdateColorScale ( false , false ) ;
2013-10-18 20:00:58 +06:00
}
2014-03-14 15:05:51 +06:00
void GEOM_Displayer : : BeforeErase ( SALOME_View * v , const SALOME_OCCPrs * p )
{
LightApp_Displayer : : BeforeErase ( v , p ) ;
releaseTextures ( p ) ;
}
2013-10-18 20:00:58 +06:00
void GEOM_Displayer : : AfterErase ( SALOME_View * v , const SALOME_OCCPrs * p )
{
LightApp_Displayer : : AfterErase ( v , p ) ;
2013-11-15 16:17:50 +06:00
UpdateColorScale ( false , false ) ;
2004-12-01 15:39:14 +05:00
}
//=================================================================
/*!
* GEOM_Displayer : : SetColor
* 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 : : SetColor ( const int color )
{
2008-03-07 12:45:34 +05:00
if ( color = = - 1 )
UnsetColor ( ) ;
else
{
myColor = color ;
myShadingColor = Quantity_Color ( ( Quantity_NameOfColor ) color ) ;
}
2004-12-01 15:39:14 +05:00
}
int GEOM_Displayer : : GetColor ( ) const
{
return myColor ;
}
bool GEOM_Displayer : : HasColor ( ) const
{
return myColor ! = - 1 ;
}
void GEOM_Displayer : : UnsetColor ( )
{
myColor = - 1 ;
2012-08-09 13:58:02 +06:00
2008-03-07 12:45:34 +05:00
SUIT_ResourceMgr * resMgr = SUIT_Session : : session ( ) - > resourceMgr ( ) ;
QColor col = resMgr - > colorValue ( " Geometry " , " shading_color " , QColor ( 255 , 0 , 0 ) ) ;
myShadingColor = SalomeApp_Tools : : color ( col ) ;
2004-12-01 15:39:14 +05:00
}
2014-01-29 20:00:16 +06:00
//=================================================================
/*!
* GEOM_Displayer : : SetTransparency
* Set transparency for shape displaying .
*/
//=================================================================
2014-07-02 13:17:40 +06:00
double GEOM_Displayer : : SetTransparency ( const double transparency )
2014-01-29 20:00:16 +06:00
{
2014-11-07 20:36:38 +05:00
double prevTransparency = myTransparency ;
myTransparency = transparency ;
return prevTransparency ;
2014-01-29 20:00:16 +06:00
}
2014-07-02 13:17:40 +06:00
//=================================================================
/*!
* GEOM_Displayer : : GetTransparency
* Get transparency for shape displaying .
*/
//=================================================================
2014-01-29 20:00:16 +06:00
double GEOM_Displayer : : GetTransparency ( ) const
{
return myTransparency ;
}
2014-07-02 13:17:40 +06:00
//=================================================================
/*!
* GEOM_Displayer : : HasTransparency
* Check if transparency for shape displaying is set .
*/
//=================================================================
2014-01-29 20:00:16 +06:00
bool GEOM_Displayer : : HasTransparency ( ) const
{
2014-11-07 20:36:38 +05:00
return myTransparency > = 0 ;
2014-01-29 20:00:16 +06:00
}
2014-07-02 13:17:40 +06:00
//=================================================================
/*!
* GEOM_Displayer : : UnsetTransparency
* Unset transparency for shape displaying .
*/
//=================================================================
double GEOM_Displayer : : UnsetTransparency ( )
2014-01-29 20:00:16 +06:00
{
2014-11-07 20:36:38 +05:00
return SetTransparency ( - 1 ) ;
2014-01-29 20:00:16 +06:00
}
2012-08-09 13:58:02 +06:00
//=================================================================
/*!
* GEOM_Displayer : : SetTexture
*/
//=================================================================
void GEOM_Displayer : : SetTexture ( const std : : string & texureFileName )
{
2014-11-07 20:36:38 +05:00
myTexture = texureFileName ;
2012-08-09 13:58:02 +06:00
}
bool GEOM_Displayer : : HasTexture ( ) const
{
return myTexture ! = " " ;
}
std : : string GEOM_Displayer : : GetTexture ( ) const
{
return myTexture ;
}
2004-12-01 15:39:14 +05:00
//=================================================================
/*!
* GEOM_Displayer : : SetWidth
* Set width of shape displaying . If it is equal - 1 then default width is used .
*/
//=================================================================
void GEOM_Displayer : : SetWidth ( const double width )
{
myWidth = width ;
}
double GEOM_Displayer : : GetWidth ( ) const
{
return myWidth ;
}
bool GEOM_Displayer : : HasWidth ( ) const
{
return myWidth ! = - 1 ;
}
void GEOM_Displayer : : UnsetWidth ( )
{
myWidth = - 1 ;
}
2012-08-09 13:58:02 +06:00
int GEOM_Displayer : : GetIsosWidth ( ) const
{
return myIsosWidth ;
}
2013-02-12 17:35:16 +06:00
void GEOM_Displayer : : SetIsosWidth ( const int width )
2012-08-09 13:58:02 +06:00
{
myIsosWidth = width ;
}
bool GEOM_Displayer : : HasIsosWidth ( ) const
{
return myIsosWidth ! = - 1 ;
}
2014-11-07 20:36:38 +05:00
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 ) ;
}
2012-08-09 13:58:02 +06:00
2004-12-01 15:39:14 +05:00
//=================================================================
/*!
* GEOM_Displayer : : SetToActivate
* This method is used for activisation / deactivisation of objects to be displayed
*/
//=================================================================
void GEOM_Displayer : : SetToActivate ( const bool toActivate )
{
myToActivate = toActivate ;
}
bool GEOM_Displayer : : ToActivate ( ) const
{
return myToActivate ;
}
//=================================================================
/*!
* GEOM_Displayer : : clearTemporary
2005-08-18 12:15:31 +06:00
* Removes from selection temporary objects
2004-12-01 15:39:14 +05:00
*/
//=================================================================
2005-11-03 13:30:14 +05:00
void GEOM_Displayer : : clearTemporary ( LightApp_SelectionMgr * theSelMgr )
2004-12-01 15:39:14 +05:00
{
2005-06-03 16:41:52 +06:00
SALOME_ListIO selected , toSelect ;
theSelMgr - > selectedObjects ( selected ) ;
2005-08-18 12:15:31 +06:00
2005-06-03 16:41:52 +06:00
for ( SALOME_ListIteratorOfListIO it ( selected ) ; it . More ( ) ; it . Next ( ) ) {
Handle ( SALOME_InteractiveObject ) io = it . Value ( ) ;
2005-08-18 12:15:31 +06:00
if ( ! io . IsNull ( ) & & io - > hasEntry ( ) & & strncmp ( io - > getEntry ( ) , " TEMP_ " , 5 ) ! = 0 )
2005-06-03 16:41:52 +06:00
toSelect . Append ( it . Value ( ) ) ;
}
2005-08-18 12:15:31 +06:00
2005-06-03 16:41:52 +06:00
theSelMgr - > setSelectedObjects ( toSelect , true ) ;
2004-12-01 15:39:14 +05:00
}
2005-11-14 18:53:44 +05:00
void GEOM_Displayer : : SetName ( const char * theName )
{
myName = theName ;
}
void GEOM_Displayer : : UnsetName ( )
{
myName = " " ;
}
SalomeApp_Study * GEOM_Displayer : : getStudy ( ) const
{
return dynamic_cast < SalomeApp_Study * > ( myApp - > activeStudy ( ) ) ;
}
void GEOM_Displayer : : setIO ( const Handle ( SALOME_InteractiveObject ) & theIO )
{
myIO = theIO ;
}
void GEOM_Displayer : : setShape ( const TopoDS_Shape & theShape )
{
myShape = theShape ;
}
2005-12-01 15:05:15 +05:00
2013-10-18 20:00:58 +06:00
void GEOM_Displayer : : setFieldStepInfo ( const GEOM : : field_data_type theFieldDataType ,
const int theFieldDimension ,
const QList < QVariant > & theFieldStepData ,
const TCollection_AsciiString & theFieldStepName ,
const double theFieldStepRangeMin ,
const double theFieldStepRangeMax )
{
myFieldDataType = theFieldDataType ;
myFieldDimension = theFieldDimension ;
myFieldStepData = theFieldStepData ;
myFieldStepName = theFieldStepName ;
myFieldStepRangeMin = theFieldStepRangeMin ;
myFieldStepRangeMax = theFieldStepRangeMax ;
}
2012-08-09 13:58:02 +06:00
bool GEOM_Displayer : : canBeDisplayed ( const QString & entry , const QString & viewer_type ) const
2005-12-01 15:05:15 +05:00
{
2013-06-28 14:18:20 +06:00
_PTR ( SObject ) anObj = getStudy ( ) - > studyDS ( ) - > FindObjectID ( ( const char * ) entry . toLatin1 ( ) ) ;
2013-07-09 17:17:47 +06:00
GEOM : : GEOM_Object_var aGeomObj = GEOM : : GEOM_Object : : _narrow ( GeometryGUI : : ClientSObjectToObject ( anObj ) ) ; // enable displaying of GEOM objects
2013-10-18 20:00:58 +06:00
GEOM : : GEOM_FieldStep_var aFieldStepObj = GEOM : : GEOM_FieldStep : : _narrow ( GeometryGUI : : ClientSObjectToObject ( anObj ) ) ; // enable displaying of GEOM field steps
2013-07-09 17:17:47 +06:00
GEOM : : GEOM_Gen_var aCompObj = GEOM : : GEOM_Gen : : _narrow ( GeometryGUI : : ClientSObjectToObject ( anObj ) ) ; // enable displaying of whole GEOM component
2013-10-18 20:00:58 +06:00
return ( ! CORBA : : is_nil ( aGeomObj ) | | ! CORBA : : is_nil ( aFieldStepObj ) | | ! CORBA : : is_nil ( aCompObj ) ) & &
( viewer_type = = SOCC_Viewer : : Type ( ) | | viewer_type = = SVTK_Viewer : : Type ( ) ) ;
2005-12-01 15:05:15 +05:00
}
2008-03-07 12:45:34 +05:00
int GEOM_Displayer : : SetDisplayMode ( const int theMode )
{
int aPrevMode = myDisplayMode ;
2013-02-12 17:35:16 +06:00
if ( theMode ! = - 1 ) {
2008-03-07 12:45:34 +05:00
myDisplayMode = theMode ;
2013-02-12 17:35:16 +06:00
myHasDisplayMode = true ;
}
else {
UnsetDisplayMode ( ) ;
2008-03-07 12:45:34 +05:00
}
return aPrevMode ;
}
int GEOM_Displayer : : GetDisplayMode ( ) const
{
return myDisplayMode ;
}
int GEOM_Displayer : : UnsetDisplayMode ( )
{
int aPrevMode = myDisplayMode ;
SUIT_ResourceMgr * resMgr = SUIT_Session : : session ( ) - > resourceMgr ( ) ;
myDisplayMode = resMgr - > integerValue ( " Geometry " , " display_mode " , 0 ) ;
2013-02-12 17:35:16 +06:00
myHasDisplayMode = false ;
2008-03-07 12:45:34 +05:00
return aPrevMode ;
}
2013-02-12 17:35:16 +06:00
bool GEOM_Displayer : : HasDisplayMode ( ) const
{
return myHasDisplayMode ;
}
2012-10-08 17:16:36 +06:00
SALOMEDS : : Color GEOM_Displayer : : getPredefinedUniqueColor ( )
{
static QList < QColor > colors ;
if ( colors . isEmpty ( ) ) {
2012-12-13 14:40:36 +06:00
for ( int s = 0 ; s < 2 ; s + + )
{
for ( int v = 100 ; v > = 40 ; v = v - 20 )
{
for ( int h = 0 ; h < 359 ; h = h + 60 )
{
colors . append ( QColor : : fromHsv ( h , 255 - s * 127 , v * 255 / 100 ) ) ;
}
2012-10-08 17:16:36 +06:00
}
}
}
2014-10-31 19:03:46 +05:00
static int currentColor = randomize ( colors . size ( ) ) ;
2012-10-08 17:16:36 +06:00
SALOMEDS : : Color color ;
color . R = ( double ) colors [ currentColor ] . red ( ) / 255.0 ;
color . G = ( double ) colors [ currentColor ] . green ( ) / 255.0 ;
color . B = ( double ) colors [ currentColor ] . blue ( ) / 255.0 ;
currentColor = ( currentColor + 1 ) % colors . count ( ) ;
return color ;
}
2009-02-13 17:16:39 +05:00
SALOMEDS : : Color GEOM_Displayer : : getUniqueColor ( const QList < SALOMEDS : : Color > & theReservedColors )
2008-03-07 12:45:34 +05:00
{
int aHue = - 1 ;
int aTolerance = 64 ;
int anIterations = 0 ;
int aPeriod = 5 ;
while ( 1 )
{
anIterations + + ;
if ( anIterations % aPeriod = = 0 )
{
aTolerance / = 2 ;
if ( aTolerance < 1 )
2012-08-09 13:58:02 +06:00
break ;
2008-03-07 12:45:34 +05:00
}
2012-08-09 13:58:02 +06:00
//std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2008-03-07 12:45:34 +05:00
aHue = ( int ) ( 360.0 * rand ( ) / RAND_MAX ) ;
2012-08-09 13:58:02 +06:00
//std::cout << "Hue = " << aHue << std::endl;
2008-03-07 12:45:34 +05:00
2012-08-09 13:58:02 +06:00
//std::cout << "Auto colors : ";
2008-03-07 12:45:34 +05:00
bool ok = true ;
2009-02-13 17:16:39 +05:00
QList < SALOMEDS : : Color > : : const_iterator it = theReservedColors . constBegin ( ) ;
QList < SALOMEDS : : Color > : : const_iterator itEnd = theReservedColors . constEnd ( ) ;
2008-03-07 12:45:34 +05:00
for ( ; it ! = itEnd ; + + it )
{
SALOMEDS : : Color anAutoColor = * it ;
QColor aQColor ( ( int ) ( anAutoColor . R * 255.0 ) , ( int ) ( anAutoColor . G * 255.0 ) , ( int ) ( anAutoColor . B * 255.0 ) ) ;
int h , s , v ;
aQColor . getHsv ( & h , & s , & v ) ;
2012-08-09 13:58:02 +06:00
//std::cout << h << " ";
2008-03-07 12:45:34 +05:00
if ( abs ( h - aHue ) < aTolerance )
{
2012-08-09 13:58:02 +06:00
ok = false ;
//std::cout << "break (diff = " << abs( h - aHue ) << ")";
break ;
2008-03-07 12:45:34 +05:00
}
}
2012-08-09 13:58:02 +06:00
//std::cout << std::endl;
2008-03-07 12:45:34 +05:00
if ( ok )
break ;
}
2012-08-09 13:58:02 +06:00
//std::cout << "Hue of the returned color = " << aHue << std::endl;
2008-03-07 12:45:34 +05:00
QColor aColor ;
aColor . setHsv ( aHue , 255 , 255 ) ;
SALOMEDS : : Color aSColor ;
aSColor . R = ( double ) aColor . red ( ) / 255.0 ;
aSColor . G = ( double ) aColor . green ( ) / 255.0 ;
aSColor . B = ( double ) aColor . blue ( ) / 255.0 ;
return aSColor ;
}
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
PropMap GEOM_Displayer : : getObjectProperties ( SalomeApp_Study * study ,
2013-06-17 18:15:50 +06:00
const QString & entry ,
SALOME_View * view )
2013-02-12 17:35:16 +06:00
{
// get default properties for the explicitly specified default view type
PropMap propMap = GEOM_Displayer : : getDefaultPropertyMap ( ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
if ( study & & view ) {
SUIT_ViewModel * viewModel = dynamic_cast < SUIT_ViewModel * > ( view ) ;
SUIT_ViewManager * viewMgr = ( viewModel ! = 0 ) ? viewModel - > getViewManager ( ) : 0 ;
int viewId = ( viewMgr ! = 0 ) ? viewMgr - > getGlobalId ( ) : - 1 ;
if ( viewModel & & viewId ! = - 1 ) {
// get properties from the study
2014-10-23 18:33:30 +06:00
PropMap storedMap = study - > getObjectProperties ( viewId , entry ) ;
2013-02-12 17:35:16 +06:00
// overwrite default properties from stored ones (that are specified)
for ( int prop = GEOM : : Visibility ; prop < = GEOM : : LastProperty ; prop + + ) {
2013-06-17 18:15:50 +06:00
if ( storedMap . contains ( GEOM : : propertyName ( ( GEOM : : Property ) prop ) ) )
propMap . insert ( GEOM : : propertyName ( ( GEOM : : Property ) prop ) ,
storedMap . value ( GEOM : : propertyName ( ( GEOM : : Property ) prop ) ) ) ;
2013-02-12 17:35:16 +06:00
}
// ... specific processing for color
// ... current implementation is to use same stored color for all aspects
// ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
if ( storedMap . contains ( GEOM : : propertyName ( GEOM : : Color ) ) ) {
2013-06-17 18:15:50 +06:00
propMap . insert ( GEOM : : propertyName ( GEOM : : ShadingColor ) , storedMap . value ( GEOM : : propertyName ( GEOM : : Color ) ) ) ;
propMap . insert ( GEOM : : propertyName ( GEOM : : WireframeColor ) , storedMap . value ( GEOM : : propertyName ( GEOM : : Color ) ) ) ;
propMap . insert ( GEOM : : propertyName ( GEOM : : LineColor ) , storedMap . value ( GEOM : : propertyName ( GEOM : : Color ) ) ) ;
propMap . insert ( GEOM : : propertyName ( GEOM : : FreeBndColor ) , storedMap . value ( GEOM : : propertyName ( GEOM : : Color ) ) ) ;
propMap . insert ( GEOM : : propertyName ( GEOM : : PointColor ) , storedMap . value ( GEOM : : propertyName ( GEOM : : Color ) ) ) ;
2013-02-12 17:35:16 +06:00
}
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
if ( ! entry . isEmpty ( ) ) {
2013-06-17 18:15:50 +06:00
// get CORBA reference to geom object
_PTR ( SObject ) SO ( study - > studyDS ( ) - > FindObjectID ( entry . toStdString ( ) ) ) ;
if ( SO ) {
CORBA : : Object_var object = GeometryGUI : : ClientSObjectToObject ( SO ) ;
if ( ! CORBA : : is_nil ( object ) ) {
GEOM : : GEOM_Object_var geomObject = GEOM : : GEOM_Object : : _narrow ( object ) ;
2013-10-18 20:00:58 +06:00
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 ) ;
2013-06-17 18:15:50 +06:00
}
2013-10-18 20:00:58 +06:00
// 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 ) ) ;
}
2013-06-17 18:15:50 +06:00
}
}
}
}
2013-02-12 17:35:16 +06:00
}
}
2012-08-09 13:58:02 +06:00
}
2013-02-12 17:35:16 +06:00
return propMap ;
}
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
PropMap GEOM_Displayer : : getDefaultPropertyMap ( )
{
PropMap propMap ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// get resource manager
SUIT_ResourceMgr * resMgr = SUIT_Session : : session ( ) - > resourceMgr ( ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// fill in the properties map with default values
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - visibility (false by default)
propMap . insert ( GEOM : : propertyName ( GEOM : : Visibility ) , false ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - nb isos (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : NbIsos ) ,
2013-06-17 18:15:50 +06:00
QString ( " %1%2%3 " ) .
arg ( resMgr - > integerValue ( " Geometry " , " iso_number_u " , 1 ) ) .
arg ( GEOM : : subSectionSeparator ( ) ) .
arg ( resMgr - > integerValue ( " Geometry " , " iso_number_v " , 1 ) ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - transparency (opacity = 1-transparency)
2014-07-02 13:17:40 +06:00
propMap . insert ( GEOM : : propertyName ( GEOM : : Transparency ) ,
resMgr - > integerValue ( " Geometry " , " transparency " , 0 ) / 100. ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - display mode (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : DisplayMode ) ,
2013-06-17 18:15:50 +06:00
resMgr - > integerValue ( " Geometry " , " display_mode " , 0 ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - show edges direction flag (false by default)
propMap . insert ( GEOM : : propertyName ( GEOM : : EdgesDirection ) , false ) ;
2012-08-09 13:58:02 +06:00
2014-08-27 13:03:29 +06:00
// - show vertices flag (false by default)
propMap . insert ( GEOM : : propertyName ( GEOM : : Vertices ) , false ) ;
2015-03-11 15:18:51 +05:00
// - show name flag (false by default)
propMap . insert ( GEOM : : propertyName ( GEOM : : ShowName ) , false ) ;
2013-02-12 17:35:16 +06:00
// - shading color (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : ShadingColor ) ,
2013-06-17 18:15:50 +06:00
colorFromResources ( " shading_color " , QColor ( 255 , 255 , 0 ) ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - wireframe color (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : WireframeColor ) ,
2013-06-17 18:15:50 +06:00
colorFromResources ( " wireframe_color " , QColor ( 255 , 255 , 0 ) ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - standalone edges color (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : LineColor ) ,
2013-06-17 18:15:50 +06:00
colorFromResources ( " line_color " , QColor ( 255 , 0 , 0 ) ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - free boundaries color (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : FreeBndColor ) ,
2013-06-17 18:15:50 +06:00
colorFromResources ( " free_bound_color " , QColor ( 0 , 255 , 0 ) ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - points color (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : PointColor ) ,
2013-06-17 18:15:50 +06:00
colorFromResources ( " point_color " , QColor ( 255 , 255 , 0 ) ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - isos color (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : IsosColor ) ,
2013-06-17 18:15:50 +06:00
colorFromResources ( " isos_color " , QColor ( 200 , 200 , 200 ) ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - outlines color (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : OutlineColor ) ,
2013-06-17 18:15:50 +06:00
colorFromResources ( " edges_in_shading_color " , QColor ( 180 , 180 , 180 ) ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - deflection coefficient (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : Deflection ) ,
2013-06-17 18:15:50 +06:00
resMgr - > doubleValue ( " Geometry " , " deflection_coeff " , 0.001 ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - material (take default value from preferences)
Material_Model material ;
material . fromResources ( resMgr - > stringValue ( " Geometry " , " material " , " Plastic " ) ) ;
propMap . insert ( GEOM : : propertyName ( GEOM : : Material ) , material . toProperties ( ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - edge width (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : LineWidth ) ,
2013-06-17 18:15:50 +06:00
resMgr - > integerValue ( " Geometry " , " edge_width " , 1 ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - isos width (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : IsosWidth ) ,
2013-06-17 18:15:50 +06:00
resMgr - > integerValue ( " Geometry " , " isolines_width " , 1 ) ) ;
2012-08-09 13:58:02 +06:00
2013-02-12 17:35:16 +06:00
// - point marker (take default value from preferences)
propMap . insert ( GEOM : : propertyName ( GEOM : : PointMarker ) ,
2013-06-17 18:15:50 +06:00
QString ( " %1%2%3 " ) .
arg ( resMgr - > integerValue ( " Geometry " , " type_of_marker " , 1 ) + 1 ) .
arg ( GEOM : : subSectionSeparator ( ) ) .
arg ( resMgr - > integerValue ( " Geometry " , " marker_scale " , 1 ) ) ) ;
2013-02-12 17:35:16 +06:00
// - top-level flag (false by default)
propMap . insert ( GEOM : : propertyName ( GEOM : : TopLevel ) , false ) ;
return propMap ;
}
2012-08-09 13:58:02 +06:00
SALOMEDS : : Color GEOM_Displayer : : getColor ( GEOM : : GEOM_Object_var theGeomObject , bool & hasColor ) {
SALOMEDS : : Color aSColor ;
hasColor = false ;
SUIT_Session * session = SUIT_Session : : session ( ) ;
2012-10-08 17:16:36 +06:00
SalomeApp_Application * app = dynamic_cast < SalomeApp_Application * > ( session - > activeApplication ( ) ) ;
2012-08-09 13:58:02 +06:00
if ( app & & ! theGeomObject - > _is_nil ( ) ) {
SalomeApp_Study * study = dynamic_cast < SalomeApp_Study * > ( app - > activeStudy ( ) ) ;
if ( study ) {
2012-10-08 17:16:36 +06:00
_PTR ( Study ) aStudy = study - > studyDS ( ) ;
2012-08-09 13:58:02 +06:00
aSColor = theGeomObject - > GetColor ( ) ;
hasColor = aSColor . R > = 0 & & aSColor . G > = 0 & & aSColor . B > = 0 ;
2012-10-08 17:16:36 +06:00
if ( ! hasColor ) {
# ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2013-06-17 18:15:50 +06:00
bool general_autocolor = true ;
2012-10-08 17:16:36 +06:00
# else // auto-color for groups only
2013-06-17 18:15:50 +06:00
bool general_autocolor = false ;
2012-10-08 17:16:36 +06:00
# endif // GENERAL_AUTOCOLOR
2013-06-17 18:15:50 +06:00
if ( general_autocolor | | theGeomObject - > GetType ( ) = = GEOM_GROUP ) {
GEOM : : GEOM_Object_var aMainObject = theGeomObject - > GetMainShape ( ) ;
if ( ! CORBA : : is_nil ( aMainObject ) & & aMainObject - > GetAutoColor ( ) ) {
2012-10-08 17:16:36 +06:00
# ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2013-06-17 18:15:50 +06:00
aSColor = getPredefinedUniqueColor ( ) ;
hasColor = true ;
2012-10-08 17:16:36 +06:00
# else // old algorithm for auto-colors
2013-06-17 18:15:50 +06:00
QList < SALOMEDS : : Color > aReservedColors ;
CORBA : : String_var IOR = app - > orb ( ) - > object_to_string ( aMainObject ) ;
_PTR ( SObject ) aMainSObject ( aStudy - > FindObjectIOR ( IOR . in ( ) ) ) ;
if ( aMainSObject ) {
_PTR ( ChildIterator ) it ( aStudy - > NewChildIterator ( aMainSObject ) ) ;
for ( ; it - > More ( ) ; it - > Next ( ) ) {
_PTR ( SObject ) aChildSObject ( it - > Value ( ) ) ;
GEOM : : GEOM_Object_var aChildObject =
GEOM : : GEOM_Object : : _narrow ( GeometryGUI : : ClientSObjectToObject ( aChildSObject ) ) ;
if ( CORBA : : is_nil ( aChildObject ) )
continue ;
SALOMEDS : : Color aReservedColor = aChildObject - > GetColor ( ) ;
if ( aReservedColor . R > = 0 & & aReservedColor . G > = 0 & & aReservedColor . B > = 0 )
aReservedColors . append ( aReservedColor ) ;
}
}
aSColor = getUniqueColor ( aReservedColors ) ;
hasColor = true ;
2012-10-08 17:16:36 +06:00
# endif // SIMPLE_AUTOCOLOR
2013-06-17 18:15:50 +06:00
}
}
2012-08-09 13:58:02 +06:00
}
}
}
return aSColor ;
}
void GEOM_Displayer : : EraseWithChildren ( const Handle ( SALOME_InteractiveObject ) & theIO ,
const bool eraseOnlyChildren ) {
SalomeApp_Application * app = dynamic_cast < SalomeApp_Application * > ( SUIT_Session : : session ( ) - > activeApplication ( ) ) ;
if ( ! app )
return ;
SalomeApp_Study * appStudy = dynamic_cast < SalomeApp_Study * > ( app - > activeStudy ( ) ) ;
if ( ! appStudy )
return ;
LightApp_DataObject * parent = appStudy - > findObjectByEntry ( theIO - > getEntry ( ) ) ;
if ( ! parent )
return ;
// Erase from all views
QList < SALOME_View * > views ;
SALOME_View * view ;
ViewManagerList vmans = app - > viewManagers ( ) ;
SUIT_ViewManager * vman ;
foreach ( vman , vmans ) {
SUIT_ViewModel * vmod = vman - > getViewModel ( ) ;
view = dynamic_cast < SALOME_View * > ( vmod ) ;
if ( view )
views . append ( view ) ;
}
if ( views . count ( ) = = 0 )
return ;
//Erase childrens w/o update views
DataObjectList listObj = parent - > children ( true ) ;
SUIT_DataObject * obj ;
foreach ( obj , listObj ) {
LightApp_DataObject * l_obj = dynamic_cast < LightApp_DataObject * > ( obj ) ;
if ( l_obj )
foreach ( view , views ) {
Handle ( SALOME_InteractiveObject ) anIO =
new SALOME_InteractiveObject ( qPrintable ( l_obj - > entry ( ) ) , " GEOM " , " " ) ;
Erase ( anIO , false , false , view ) ;
}
}
//Erase parent with view update or repaint views
foreach ( view , views ) {
if ( ! eraseOnlyChildren )
Erase ( theIO , false , true , view ) ;
else
view - > Repaint ( ) ;
}
}
2013-10-18 20:00:58 +06:00
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 < QVariant > 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 + + )
2013-10-24 11:25:04 +06:00
aFieldStepData < < ( qlonglong ) aValues [ i ] ;
2013-10-18 20:00:58 +06:00
}
}
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 + + )
2013-10-24 10:57:31 +06:00
aFieldStepData < < ( double ) aValues [ i ] ;
2013-10-18 20:00:58 +06:00
}
}
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 < QVariant > GEOM_Displayer : : groupFieldData ( const QList < QVariant > & theFieldStepData ,
const int theFieldNbComponents ,
const bool theIsString ,
double & theFieldStepRangeMin ,
double & theFieldStepRangeMax )
{
QList < QVariant > aResultList ;
theFieldStepRangeMin = 0 ;
theFieldStepRangeMax = 0 ;
if ( theFieldStepData . isEmpty ( ) | | theFieldNbComponents < 1 )
return aResultList ;
int aNbSubShapes = theFieldStepData . count ( ) / theFieldNbComponents ;
QList < QVariant > 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
{
2014-02-12 19:28:23 +06:00
if ( aVariant . type ( ) = = QVariant : : LongLong )
aValue = double ( aVariant . toLongLong ( ) ) ;
2013-10-18 20:00:58 +06:00
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 < QVariant > anIter ( aGroupedList ) ;
while ( anIter . hasNext ( ) )
{
const QVariant & aVariant = anIter . next ( ) ;
if ( theIsString )
aResultList < < aVariant ;
else
{
QColor aQColor ;
Quantity_Color aColor ;
if ( FindColor ( aVariant . toDouble ( ) , theFieldStepRangeMin , theFieldStepRangeMax , anIsBoolean ? 2 : aNbIntervals , aColor ) )
aQColor = QColor : : fromRgbF ( aColor . Red ( ) , aColor . Green ( ) , aColor . Blue ( ) ) ;
aResultList < < aQColor ;
}
}
return aResultList ;
}
2016-02-24 18:45:13 +05:00
// Note: the method is copied from AIS_ColorScale class
2013-10-18 20:00:58 +06:00
Standard_Integer GEOM_Displayer : : HueFromValue ( const Standard_Integer aValue ,
const Standard_Integer aMin ,
const Standard_Integer aMax )
{
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 ;
}
2016-02-24 18:45:13 +05:00
// Note: the method is copied from AIS_ColorScale class
2013-10-18 20:00:58 +06:00
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 ( aValue < aMin | | aValue > aMax | | aMax < aMin )
return Standard_False ;
else
{
Standard_Real IntervNumber = 0 ;
if ( aValue < aMin )
IntervNumber = 0 ;
else if ( aValue > aMax )
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 ;
}
}
2013-11-15 16:17:50 +06:00
void GEOM_Displayer : : UpdateColorScale ( const bool theIsRedisplayFieldSteps , const bool updateViewer )
2013-10-18 20:00:58 +06:00
{
SalomeApp_Study * aStudy = dynamic_cast < SalomeApp_Study * > ( myApp - > activeStudy ( ) ) ;
if ( ! aStudy )
return ;
SOCC_Viewer * aViewModel = dynamic_cast < SOCC_Viewer * > ( GetActiveView ( ) ) ;
if ( ! aViewModel )
return ;
2016-02-24 18:45:13 +05:00
# if OCC_VERSION_MAJOR < 7
2013-10-18 20:00:58 +06:00
Handle ( V3d_Viewer ) aViewer = aViewModel - > getViewer3d ( ) ;
if ( aViewer . IsNull ( ) )
return ;
aViewer - > InitActiveViews ( ) ;
if ( ! aViewer - > MoreActiveViews ( ) )
return ;
Handle ( V3d_View ) aView = aViewer - > ActiveView ( ) ;
if ( aView . IsNull ( ) )
return ;
2016-02-24 18:45:13 +05:00
# endif
2013-10-18 20:00:58 +06:00
Standard_Boolean anIsDisplayColorScale = Standard_False ;
TCollection_AsciiString aColorScaleTitle ;
Standard_Real aColorScaleMin = 0 , aColorScaleMax = 0 ;
Standard_Boolean anIsBoolean = Standard_False ;
SALOME_ListIO aSelectedObjects ;
myApp - > selectionMgr ( ) - > selectedObjects ( aSelectedObjects ) ;
if ( aSelectedObjects . Extent ( ) = = 1 )
{
Handle ( SALOME_InteractiveObject ) anIO = aSelectedObjects . First ( ) ;
if ( ! anIO . IsNull ( ) )
{
SOCC_Prs * aPrs = dynamic_cast < SOCC_Prs * > ( aViewModel - > CreatePrs ( anIO - > getEntry ( ) ) ) ;
if ( aPrs )
{
AIS_ListOfInteractive aList ;
aPrs - > GetObjects ( aList ) ;
AIS_ListIteratorOfListOfInteractive anIter ( aList ) ;
for ( ; anIter . More ( ) ; anIter . Next ( ) )
{
Handle ( GEOM_AISShape ) aShape = Handle ( GEOM_AISShape ) : : DownCast ( anIter . Value ( ) ) ;
if ( ! aShape . IsNull ( ) )
{
GEOM : : field_data_type aFieldDataType ;
int aFieldDimension ;
QList < QVariant > 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 ;
}
}
}
}
}
}
if ( anIsDisplayColorScale )
{
2016-02-24 18:45:13 +05:00
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 ) ;
# if OCC_VERSION_MAJOR < 7
Handle ( Aspect_ColorScale ) myColorScale = aView - > ColorScale ( ) ;
if ( ! myColorScale . IsNull ( ) )
2013-10-18 20:00:58 +06:00
{
2016-02-24 18:45:13 +05:00
# endif
myColorScale - > SetXPosition ( anXPos ) ;
myColorScale - > SetYPosition ( anYPos ) ;
myColorScale - > SetWidth ( aWidth ) ;
myColorScale - > SetHeight ( aHeight ) ;
myColorScale - > SetTextHeight ( aTextHeight ) ;
myColorScale - > SetNumberOfIntervals ( anIsBoolean ? 2 : aNbIntervals ) ;
myColorScale - > SetTitle ( aColorScaleTitle ) ;
myColorScale - > SetRange ( aColorScaleMin , aColorScaleMax ) ;
# if OCC_VERSION_MAJOR < 7
2013-10-18 20:00:58 +06:00
}
if ( ! aView - > ColorScaleIsDisplayed ( ) )
aView - > ColorScaleDisplay ( ) ;
}
else
if ( aView - > ColorScaleIsDisplayed ( ) )
aView - > ColorScaleErase ( ) ;
2016-02-24 18:45:13 +05:00
# else
if ( ! aViewModel - > getAISContext ( ) - > IsDisplayed ( myColorScale ) )
aViewModel - > getAISContext ( ) - > Display ( myColorScale ) ;
2013-10-18 20:00:58 +06:00
}
2016-02-24 18:45:13 +05:00
else
if ( aViewModel - > getAISContext ( ) - > IsDisplayed ( myColorScale ) )
aViewModel - > getAISContext ( ) - > Erase ( myColorScale ) ;
# endif
2013-10-18 20:00:58 +06:00
if ( theIsRedisplayFieldSteps )
{
_PTR ( Study ) aStudyDS = aStudy - > studyDS ( ) ;
QList < SUIT_ViewManager * > vmList ;
myApp - > viewManagers ( vmList ) ;
for ( QList < SUIT_ViewManager * > : : Iterator vmIt = vmList . begin ( ) ; vmIt ! = vmList . end ( ) ; vmIt + + )
{
if ( SUIT_ViewManager * aViewManager = * vmIt )
{
2014-10-23 18:33:30 +06:00
const ObjMap & anObjects = aStudy - > getObjectProperties ( aViewManager - > getGlobalId ( ) ) ;
2013-10-18 20:00:58 +06:00
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 ) ;
}
}
}
}
}
}
}
2013-11-15 16:17:50 +06:00
if ( updateViewer )
UpdateViewer ( ) ;
2013-10-18 20:00:58 +06:00
}