1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOM_Displayer.cxx
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
27 #include "GEOM_Displayer.h"
28 #include "GEOMGUI_DimensionProperty.h"
29 #include "GeometryGUI.h"
31 #include <GEOM_Constants.h>
32 #include <GEOM_TypeFilter.h>
33 #include <GEOM_EdgeFilter.h>
34 #include <GEOM_FaceFilter.h>
35 #include <GEOM_CompoundFilter.h>
36 #include <GEOM_PreviewFilter.h>
37 #include <GEOM_LogicalFilter.h>
38 #include <GEOM_OCCFilter.h>
40 #include <GEOM_Actor.h>
41 #include <GEOM_AISShape.hxx>
42 #include <GEOM_AISDimension.hxx>
43 #include <GEOM_TopWireframeShape.hxx>
44 #include <GEOM_AISVector.hxx>
45 #include <GEOM_AISTrihedron.hxx>
46 #include <GEOM_VTKTrihedron.hxx>
47 #include <GEOM_VTKPropertyMaterial.hxx>
49 #include <GEOMUtils.hxx>
51 #include <Material_Model.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_ViewWindow.h>
55 #include <SUIT_Session.h>
56 #include <SUIT_ViewManager.h>
57 #include <SUIT_ResourceMgr.h>
59 #include <Basics_OCCTVersion.hxx>
61 #include <SalomeApp_Study.h>
62 #include <SalomeApp_Application.h>
63 #include <LightApp_SelectionMgr.h>
64 #include <LightApp_DataObject.h>
65 #include <SalomeApp_TypeFilter.h>
66 #include <SalomeApp_Tools.h>
68 #include <SALOME_ListIteratorOfListIO.hxx>
69 #include <SALOME_ListIO.hxx>
70 #include <SALOME_Prs.h>
73 #include <SOCC_ViewModel.h>
76 #include <SVTK_ViewModel.h>
78 #include <OCCViewer_ViewWindow.h>
79 #include <OCCViewer_ViewPort3d.h>
82 #include <AIS_Drawer.hxx>
83 #include <AIS_Dimension.hxx>
84 #include <AIS_LengthDimension.hxx>
85 #include <AIS_DiameterDimension.hxx>
86 #include <AIS_AngleDimension.hxx>
87 #include <AIS_ListIteratorOfListOfInteractive.hxx>
88 #include <Aspect_PolygonOffsetMode.hxx>
89 #include <Aspect_ColorScale.hxx>
90 #include <Prs3d_IsoAspect.hxx>
91 #include <Prs3d_PointAspect.hxx>
92 #include <StdSelect_TypeOfEdge.hxx>
93 #include <StdSelect_TypeOfFace.hxx>
94 #include <StdSelect_DisplayMode.hxx>
95 #include <TopoDS_Face.hxx>
96 #include <BRep_Tool.hxx>
97 #include <Geom_Plane.hxx>
98 #include <Geom_Axis2Placement.hxx>
99 #include <Graphic3d_AspectFillArea3d.hxx>
100 #include <gp_Pln.hxx>
101 #include <TColStd_MapOfInteger.hxx>
102 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
103 #include <TopoDS_Iterator.hxx>
104 #include <Graphic3d_AspectMarker3d.hxx>
105 #include <TopTools_MapOfShape.hxx>
106 #include <TopTools_ListOfShape.hxx>
107 #include <TopTools_ListIteratorOfListOfShape.hxx>
108 #include <TopoDS.hxx>
109 #include <NCollection_DataMap.hxx>
110 #include <NCollection_Map.hxx>
112 #include <Prs3d_ShadingAspect.hxx>
114 #include <BRepMesh_IncrementalMesh.hxx>
117 #include <vtkActorCollection.h>
118 #include <vtkProperty.h>
121 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
123 #include <GEOMImpl_Types.hxx>
125 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
126 #include <TColStd_HArray1OfByte.hxx>
128 #include <Graphic3d_HArray1OfBytes.hxx>
131 // If the next macro is defined, autocolor feature works for all sub-shapes;
132 // if it is undefined, autocolor feature works for groups only
133 #define GENERAL_AUTOCOLOR
134 // Below macro, when uncommented, switches on simplified (more performant) algorithm
135 // of auto-color picking up
136 #define SIMPLE_AUTOCOLOR
138 // Hard-coded value of shape deflection coefficient for VTK viewer
139 const double VTK_MIN_DEFLECTION = 0.001;
141 #if OCC_VERSION_LARGE > 0x06070000
142 // Pixmap caching support
145 typedef NCollection_Map<Handle(GEOM_AISShape)> SetOfAISShapes;
146 typedef NCollection_DataMap<Handle(Image_PixMap), SetOfAISShapes> PixmapUsageMap;
147 typedef QMap<QString, Handle(Image_PixMap)> PixmapCacheMap;
149 static inline PixmapUsageMap& getPixmapUsageMap()
151 static PixmapUsageMap aMap;
155 static inline PixmapCacheMap& getPixmapCacheMap()
157 static PixmapCacheMap aMap;
161 //===========================================================================
162 // Function : imageToPixmap
163 // Purpose : Concert QImage to OCCT pixmap
164 //===========================================================================
165 static inline Handle(Image_PixMap) imageToPixmap( const QImage& anImage )
167 Handle(Image_PixMap) aPixmap = new Image_PixMap();
168 if ( !anImage.isNull() ) {
169 aPixmap->InitTrash( Image_PixMap::ImgBGRA, anImage.width(), anImage.height() );
170 aPixmap->SetTopDown( Standard_True );
172 const uchar* aImageBytes = anImage.bits();
174 for ( int aLine = anImage.height() - 1; aLine >= 0; --aLine ) {
175 #if OCC_VERSION_LARGE > 0x06070100
176 // convert pixels from ARGB to renderer-compatible RGBA
177 for ( int aByte = 0; aByte < anImage.width(); ++aByte ) {
178 Image_ColorBGRA& aPixmapBytes = aPixmap->ChangeValue<Image_ColorBGRA>(aLine, aByte);
180 aPixmapBytes.b() = (Standard_Byte) *aImageBytes++;
181 aPixmapBytes.g() = (Standard_Byte) *aImageBytes++;
182 aPixmapBytes.r() = (Standard_Byte) *aImageBytes++;
183 aPixmapBytes.a() = (Standard_Byte) *aImageBytes++;
186 Image_ColorBGRA* aPixmapBytes = aPixmap->EditData<Image_ColorBGRA>().ChangeRow(aLine);
188 // convert pixels from ARGB to renderer-compatible RGBA
189 for ( int aByte = 0; aByte < anImage.width(); ++aByte ) {
190 aPixmapBytes->b() = (Standard_Byte) *aImageBytes++;
191 aPixmapBytes->g() = (Standard_Byte) *aImageBytes++;
192 aPixmapBytes->r() = (Standard_Byte) *aImageBytes++;
193 aPixmapBytes->a() = (Standard_Byte) *aImageBytes++;
202 //===========================================================================
203 // Function : getDefaultTexture
204 // Purpose : Get default texture
205 //===========================================================================
206 static inline Handle(Image_PixMap) getDefaultTexture()
208 static Handle(Image_PixMap) aPixmap;
209 if ( aPixmap.IsNull() ) {
210 QPixmap px(":images/default_texture.png");
212 aPixmap = imageToPixmap( px.toImage() );
217 //===========================================================================
218 // Function : cacheTextureFor
219 // Purpose : Load and cache image for the specified presentation.
220 //===========================================================================
221 static inline Handle(Image_PixMap) cacheTextureFor( const QString& thePath,
222 const Handle(GEOM_AISShape)& theShape )
224 if ( thePath.isEmpty() )
227 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
228 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
230 Handle(Image_PixMap) aPixmap = aPixmapCacheMap.value( thePath, NULL );
231 if ( !aPixmap.IsNull() ) {
232 // point that the texture is used by the presentation
233 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
234 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
236 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
241 // convert texture to compatible image format
242 QImage anImage = QImage( thePath ).convertToFormat( QImage::Format_ARGB32 );
243 if ( anImage.isNull() )
246 aPixmap = imageToPixmap( anImage );
248 aPixmapCacheMap.insert( thePath, aPixmap );
250 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
251 aPixmapUsersMap.Bind( aPixmap, SetOfAISShapes() );
253 aPixmapUsersMap.ChangeFind( aPixmap ).Add( theShape );
258 //===========================================================================
259 // Function : releaseTextures
260 // Purpose : Releases cached textures found for the specified presentation.
261 //===========================================================================
262 static inline void releaseTextures( const SALOME_OCCPrs* thePrs )
264 const SOCC_Prs* anOccPrs = dynamic_cast<const SOCC_Prs*>( thePrs );
266 AIS_ListOfInteractive aListOfIO;
268 anOccPrs->GetObjects( aListOfIO );
270 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
272 PixmapUsageMap& aPixmapUsersMap = getPixmapUsageMap();
273 PixmapCacheMap& aPixmapCacheMap = getPixmapCacheMap();
275 for ( ; aIterateIO.More(); aIterateIO.Next() )
277 Handle(GEOM_AISShape) aAISShape =
278 Handle(GEOM_AISShape)::DownCast( aIterateIO.Value() );
280 if ( aAISShape.IsNull() )
283 const Handle(Image_PixMap)& aPixmap = aAISShape->TexturePixMap();
284 if ( aPixmap.IsNull() )
287 if ( !aPixmapUsersMap.IsBound( aPixmap ) )
290 SetOfAISShapes& aUsersShapes = aPixmapUsersMap.ChangeFind( aPixmap );
292 aUsersShapes.Remove( aAISShape );
294 if ( aUsersShapes.IsEmpty() ) {
295 aPixmapUsersMap.UnBind( aPixmap );
296 aPixmapCacheMap.remove( aPixmapCacheMap.key( aPixmap ) );
303 //================================================================
304 // Function : getActiveStudy
305 // Purpose : Get active study, returns 0 if no open study frame
306 //================================================================
307 static inline SalomeApp_Study* getActiveStudy()
309 SUIT_Session* session = SUIT_Session::session();
310 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
312 return ( SalomeApp_Study* )app->activeStudy();
316 static inline int getViewManagerId( SALOME_View* theViewFrame) {
317 SUIT_ViewModel* aModel = dynamic_cast<SUIT_ViewModel*>(theViewFrame);
318 SUIT_ViewManager* aViewMgr = 0;
320 aViewMgr = aModel->getViewManager();
321 return ((aViewMgr == 0) ? -1 :aViewMgr->getGlobalId());
324 //================================================================
325 // Function : getTopAbsMode
326 // Purpose : Get TopAbs_ShapeEnum value corresponding to the
327 // one from GEOMImpl_Types.h
328 //================================================================
329 static inline int getTopAbsMode( const int implType )
333 case GEOM_COMPOUND : return TopAbs_COMPOUND;
334 case GEOM_SOLID : return TopAbs_SOLID;
335 case GEOM_SHELL : return TopAbs_SHELL;
336 case GEOM_FACE : return TopAbs_FACE;
337 case GEOM_WIRE : return TopAbs_WIRE;
338 case GEOM_EDGE : return TopAbs_EDGE;
339 case GEOM_POINT : return TopAbs_VERTEX;
344 int GEOM_Displayer::getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin )
346 if ( shape.IsNull() )
349 int ret = shape.ShapeType();
351 if ( shape.ShapeType() == TopAbs_COMPOUND || shape.ShapeType() == TopAbs_COMPSOLID ) {
352 TopoDS_Iterator it(shape, Standard_True, Standard_False);
353 for (; it.More(); it.Next()) {
354 TopoDS_Shape sub_shape = it.Value();
355 if ( sub_shape.IsNull() ) continue;
356 int stype = getMinMaxShapeType( sub_shape, ismin );
357 if ( stype == TopAbs_SHAPE ) continue;
358 if ( ismin && stype > ret )
360 else if ( !ismin && ( ret < TopAbs_SOLID || stype < ret ) )
368 bool GEOM_Displayer::isCompoundOfVertices( const TopoDS_Shape& theShape )
370 return theShape.ShapeType() == TopAbs_COMPOUND && getMinMaxShapeType( theShape, false ) == TopAbs_VERTEX;
373 //================================================================
374 // Function : getFilter
375 // Purpose : Get filter corresponding to the type of object
376 // from GEOMImpl_Types.h
377 //================================================================
378 SUIT_SelectionFilter* GEOM_Displayer::getFilter( const int theMode )
380 SUIT_SelectionFilter* aFilter;
382 int aTopAbsMode = getTopAbsMode( theMode );
383 if ( aTopAbsMode != -1 )
384 aFilter = new GEOM_TypeFilter( getStudy(), aTopAbsMode, true ); //@ aFilter = new GEOM_TypeFilter( ( TopAbs_ShapeEnum )aTopAbsMode );
388 case GEOM_LINE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Line ); break;
389 case GEOM_CIRCLE : aFilter = new GEOM_EdgeFilter( getStudy(), StdSelect_Circle ); break;
391 case GEOM_PLANE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Plane ); break;
392 case GEOM_CYLINDER : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cylinder ); break;
393 case GEOM_SPHERE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Sphere ); break;
394 case GEOM_TORUS : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Torus ); break;
395 case GEOM_REVOLUTION: aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Revol ); break;
396 case GEOM_CONE : aFilter = new GEOM_FaceFilter( getStudy(), StdSelect_Cone ); break;
398 case GEOM_PREVIEW : aFilter = new GEOM_PreviewFilter( getStudy() ); break;
400 case GEOM_ALLSHAPES : aFilter = new GEOM_SelectionFilter(getStudy(), true ); break;
401 case GEOM_ALLGEOM : aFilter = new SalomeApp_TypeFilter( getStudy(), "GEOM" ); break;
403 default : aFilter = new GEOM_TypeFilter( getStudy(), theMode ); break;
409 //================================================================
410 // Function : getComplexFilter
411 // Purpose : Get compound filter corresponding to the type of
412 // object from GEOMImpl_Types.h
413 //================================================================
414 SUIT_SelectionFilter* GEOM_Displayer::getComplexFilter( const QList<int>* aSubShapes)
416 GEOM_CompoundFilter* aFilter;
418 if(aSubShapes != NULL ) {
419 aFilter = new GEOM_CompoundFilter(getStudy());
420 QList<int> aTopAbsTypes;
421 QList<int>::const_iterator it;
422 for(it = aSubShapes->constBegin(); it != aSubShapes->constEnd(); ++it ) {
423 int topAbsMode = getTopAbsMode(*it);
424 if(topAbsMode != -1 )
425 aTopAbsTypes.append(topAbsMode);
427 aFilter->addSubTypes(aTopAbsTypes);
433 //================================================================
434 // Function : getEntry
436 //================================================================
437 static std::string getEntry( GEOM::GEOM_BaseObject_ptr object )
439 SUIT_Session* session = SUIT_Session::session();
440 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
443 CORBA::String_var IOR = app->orb()->object_to_string( object );
444 if ( strcmp(IOR.in(), "") != 0 )
446 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
447 _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
455 //================================================================
456 // Function : getName
458 //================================================================
459 static std::string getName( GEOM::GEOM_BaseObject_ptr object )
461 SUIT_Session* session = SUIT_Session::session();
462 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
465 CORBA::String_var IOR = app->orb()->object_to_string( object );
466 if ( strcmp(IOR.in(), "") != 0 )
468 SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
469 _PTR(SObject) aSObj ( study->studyDS()->FindObjectIOR( std::string(IOR) ) );
471 _PTR(GenericAttribute) anAttr;
473 if ( aSObj && aSObj->FindAttribute( anAttr, "AttributeName") )
475 _PTR(AttributeName) aNameAttr( anAttr );
476 return aNameAttr->Value();
484 //=================================================================
486 * GEOM_Displayer::GEOM_Displayer
489 //=================================================================
490 GEOM_Displayer::GEOM_Displayer( SalomeApp_Study* st )
493 myApp = dynamic_cast<SalomeApp_Application*>( st->application() );
498 SUIT_Session* session = SUIT_Session::session();
499 SUIT_ResourceMgr* resMgr = session->resourceMgr();
501 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
502 myShadingColor = SalomeApp_Tools::color( col );
504 myDisplayMode = resMgr->integerValue("Geometry", "display_mode", 0);
505 myHasDisplayMode = false;
507 int aType = resMgr->integerValue("Geometry", "type_of_marker", (int)Aspect_TOM_PLUS);
508 myWidth = resMgr->integerValue("Geometry", "edge_width", -1);
509 myIsosWidth = resMgr->integerValue("Geometry", "isolines_width", -1);
511 myTypeOfMarker = (Aspect_TypeOfMarker)(std::min((int)Aspect_TOM_RING3, std::max((int)Aspect_TOM_POINT, aType)));
512 myScaleOfMarker = (resMgr->integerValue("Geometry", "marker_scale", 1)-(int)GEOM::MS_10)*0.5 + 1.0;
513 myScaleOfMarker = std::min(7.0, std::max(1., myScaleOfMarker));
516 // This color is used for shape displaying. If it is equal -1 then
517 // default color is used.
522 myTransparency = -1.0;
524 // This parameter is used for activisation/deactivisation of objects to be displayed
526 #if OCC_VERSION_LARGE > 0x06050100 // Functionnality available only in OCCT 6.5.2
527 // Activate parallel vizualisation only for testing purpose
528 // and if the corresponding env variable is set to 1
529 char* parallel_visu = getenv("PARALLEL_VISU");
530 if (parallel_visu && atoi(parallel_visu))
532 MESSAGE("Parallel visualisation on");
533 BRepMesh_IncrementalMesh::SetParallelDefault(Standard_True);
539 myFieldDataType = GEOM::FDT_Double;
540 myFieldDimension = 0;
541 myFieldStepRangeMin = 0;
542 myFieldStepRangeMax = 0;
545 //=================================================================
547 * GEOM_Displayer::~GEOM_Displayer
550 //=================================================================
551 GEOM_Displayer::~GEOM_Displayer()
555 //=================================================================
557 * GEOM_Displayer::Display
558 * Display interactive object in the current viewer
560 //=================================================================
561 void GEOM_Displayer::Display( const Handle(SALOME_InteractiveObject)& theIO,
562 const bool updateViewer,
563 SALOME_View* theViewFrame )
565 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
568 SALOME_Prs* prs = buildPresentation( theIO->getEntry(), vf );
572 vf->BeforeDisplay( this, prs );
574 vf->AfterDisplay( this, prs );
579 int aMgrId = getViewManagerId(vf);
580 SalomeApp_Study* aStudy = getStudy();
581 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 1 );
583 setVisibilityState(theIO->getEntry(), Qtx::ShownState);
585 delete prs; // delete presentation because displayer is its owner
590 //=================================================================
592 * GEOM_Displayer::Display
593 * This overloaded Display() method can be useful for operations
594 * not using dialog boxes.
596 //=================================================================
597 void GEOM_Displayer::Display( GEOM::GEOM_BaseObject_ptr theObj, const bool updateViewer )
599 if ( theObj->_is_nil() )
602 std::string entry = getEntry( theObj );
604 Display(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
609 //=================================================================
611 * GEOM_Displayer::Erase
612 * Erase interactive object in the current viewer
614 //=================================================================
615 void GEOM_Displayer::Erase( const Handle(SALOME_InteractiveObject)& theIO,
617 const bool updateViewer,
618 SALOME_View* theViewFrame )
620 if ( theIO.IsNull() )
623 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
626 SALOME_Prs* prs = vf->CreatePrs( theIO->getEntry() );
628 vf->BeforeErase( this, prs );
629 vf->Erase( prs, forced );
630 vf->AfterErase( this, prs );
633 delete prs; // delete presentation because displayer is its owner
635 int aMgrId = getViewManagerId(vf);
636 SalomeApp_Study* aStudy = getStudy();
637 aStudy->setObjectProperty(aMgrId, theIO->getEntry(), GEOM::propertyName( GEOM::Visibility ), 0 );
639 setVisibilityState(theIO->getEntry(), Qtx::HiddenState);
644 //=================================================================
646 * GEOM_Displayer::Erase
647 * Erase geometry object in the current viewer
649 //=================================================================
650 void GEOM_Displayer::Erase( GEOM::GEOM_BaseObject_ptr theObj,
652 const bool updateViewer,
653 SALOME_View* theViewFrame)
655 std::string entry = getEntry( theObj );
658 Erase(new SALOME_InteractiveObject(entry.c_str(), "GEOM", getName(theObj).c_str()),
659 forced, updateViewer, theViewFrame);
663 //=================================================================
665 * GEOM_Displayer::Redisplay
666 * Redisplay (erase and then display again) interactive object
667 * in the current viewer
669 //=================================================================
670 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
671 const bool updateViewer,
672 const bool checkActiveViewer )
674 // Remove the object permanently (<forced> == true)
675 SUIT_Session* ses = SUIT_Session::session();
676 SUIT_Application* app = ses->activeApplication();
679 SUIT_Desktop* desk = app->desktop();
680 QList<SUIT_ViewWindow*> wnds = desk->windows();
681 SUIT_ViewWindow* wnd;
682 QListIterator<SUIT_ViewWindow*> it( wnds );
683 while ( it.hasNext() && (wnd = it.next()) )
685 SUIT_ViewManager* vman = wnd->getViewManager();
688 SUIT_ViewModel* vmodel = vman->getViewModel();
691 SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel);
694 if ( view->isVisible( theIO ) || ( checkActiveViewer && view == GetActiveView() ) )
696 Redisplay( theIO, updateViewer, view );
705 //=================================================================
707 * GEOM_Displayer::Redisplay
708 * Redisplay (erase and then display again) interactive object
709 * in the specified view
711 //=================================================================
712 void GEOM_Displayer::Redisplay( const Handle(SALOME_InteractiveObject)& theIO,
713 const bool theUpdateViewer,
714 SALOME_View* theViewFrame )
716 SALOME_View* vf = theViewFrame ? theViewFrame : GetActiveView();
722 Erase( theIO, true, false, theViewFrame );
723 Display( theIO, theUpdateViewer, theViewFrame );
726 //=================================================================
728 * GEOM_Displayer::Display
729 * Calls Display() method for each object in the given list
731 //=================================================================
732 void GEOM_Displayer::Display( const SALOME_ListIO& theIOList, const bool updateViewer )
734 SALOME_ListIteratorOfListIO Iter( theIOList );
735 for ( ; Iter.More(); Iter.Next() ) {
736 Display( Iter.Value(), false );
742 Quantity_Color GEOM_Displayer::qColorFromResources( const QString& property, const QColor& defColor )
744 // VSR: this method can be improved in future:
745 // to improve performance, the default values from resource manager should be cached in the displayer
746 return SalomeApp_Tools::color( SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor ) );
749 QColor GEOM_Displayer::colorFromResources( const QString& property, const QColor& defColor )
751 // VSR: this method can be improved in future:
752 // to improve performance, the default values from resource manager should be cached in the displayer
753 return SUIT_Session::session()->resourceMgr()->colorValue( "Geometry", property, defColor );
756 void GEOM_Displayer::updateShapeProperties( const Handle(GEOM_AISShape)& AISShape, bool create )
758 // check that shape is not null
759 if ( AISShape.IsNull() ) return;
761 // check that study is active
762 SalomeApp_Study* study = getStudy();
763 if ( !study ) return;
765 if ( myShape.ShapeType() != TopAbs_VERTEX && // fix pb with not displayed points
766 !TopoDS_Iterator(myShape).More() )
767 return; // NPAL15983 (Bug when displaying empty groups)
769 // set interactive object
771 Handle( SALOME_InteractiveObject ) anIO;
773 if ( !myIO.IsNull() ) {
774 AISShape->setIO( myIO );
775 AISShape->SetOwner( myIO );
778 else if ( !myName.empty() ) {
779 // workaround to allow selection of temporary objects
780 static int tempId = 0;
781 anIO = new SALOME_InteractiveObject( QString( "TEMP_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
782 AISShape->setIO( anIO );
783 AISShape->SetOwner( anIO );
786 // flag: only vertex or compound of vertices is processed (specific handling)
787 bool onlyVertex = myShape.ShapeType() == TopAbs_VERTEX || isCompoundOfVertices( myShape );
788 // presentation study entry (empty for temporary objects like preview)
789 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
790 // flag: temporary object
791 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
792 // currently active view window's ID (-1 if no active view)
793 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
795 // get presentation properties
796 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
798 // Temporary staff: vertex must be infinite for correct visualization
799 AISShape->SetInfiniteState( myShape.Infinite() ); // || myShape.ShapeType() == TopAbs_VERTEX // VSR: 05/04/2010: Fix 20668 (Fit All for points & lines)
802 Material_Model material;
803 // if predefined color isn't set in displayer(via GEOM_Displayer::SetColor() function)
805 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
806 // - set front material properties
807 AISShape->SetCurrentFacingModel( Aspect_TOFM_FRONT_SIDE );
808 AISShape->SetMaterial( material.getMaterialOCCAspect( true ) );
809 // - set back material properties
810 AISShape->SetCurrentFacingModel( Aspect_TOFM_BACK_SIDE );
811 AISShape->SetMaterial( material.getMaterialOCCAspect( false ) );
812 // - switch to default (both sides) facing mode
813 AISShape->SetCurrentFacingModel( Aspect_TOFM_BOTH_SIDE );
819 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function;
820 // we set it to the shape not taking into account material properties
821 AISShape->SetShadingColor( (Quantity_NameOfColor)GetColor() );
823 else if ( !material.isPhysical() ) {
824 // shading color from properties is used only for non-physical materials
825 AISShape->SetShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>() ) );
829 Handle(Prs3d_LineAspect) anAspect = AISShape->Attributes()->LineAspect();
830 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
831 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
832 AISShape->Attributes()->SetLineAspect( anAspect );
834 // - unfree boundaries color
835 anAspect = AISShape->Attributes()->UnFreeBoundaryAspect();
836 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
837 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>() ) );
838 AISShape->Attributes()->SetUnFreeBoundaryAspect( anAspect );
840 // - free boundaries color
841 anAspect = AISShape->Attributes()->FreeBoundaryAspect();
842 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
843 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>() ) );
844 AISShape->Attributes()->SetFreeBoundaryAspect( anAspect );
846 // - standalone edges color
847 anAspect = AISShape->Attributes()->WireAspect();
848 anAspect->SetColor( HasColor() ? (Quantity_NameOfColor)GetColor() :
849 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>() ) );
850 AISShape->Attributes()->SetWireAspect( anAspect );
852 // - color for edges in shading+edges mode
853 AISShape->SetEdgesInShadingColor( SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>() ) );
856 AISShape->storeBoundaryColors();
859 AISShape->SetDisplayMode( HasDisplayMode() ?
860 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
862 // display mode from properties
863 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt() );
865 // set display vectors flag
866 AISShape->SetDisplayVectors( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
869 if( HasTransparency() ) {
870 AISShape->SetTransparency( GetTransparency() );
872 AISShape->SetTransparency( propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
875 // set iso properties
876 int uIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[0].toInt();
877 int vIsos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() )[1].toInt();
878 Quantity_Color isosColor = SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>() );
879 int isosWidth = propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt();
880 Handle(Prs3d_IsoAspect) uIsoAspect = AISShape->Attributes()->UIsoAspect();
881 Handle(Prs3d_IsoAspect) vIsoAspect = AISShape->Attributes()->VIsoAspect();
882 uIsoAspect->SetColor( isosColor );
883 uIsoAspect->SetWidth( isosWidth );
884 uIsoAspect->SetNumber( uIsos );
885 vIsoAspect->SetColor( isosColor );
886 vIsoAspect->SetWidth( isosWidth );
887 vIsoAspect->SetNumber( vIsos );
888 AISShape->Attributes()->SetUIsoAspect( uIsoAspect );
889 AISShape->Attributes()->SetVIsoAspect( vIsoAspect );
891 // set deflection coefficient
892 // ... to avoid to small values of the coefficient, its lower value is limited
893 AISShape->SetOwnDeviationCoefficient( qMax( propMap.value( GEOM::propertyName( GEOM::Deflection ) ).toDouble(), GEOM::minDeflection() ) );
897 if ( HasTexture() ) {
898 // predefined display texture, manually set to displayer via GEOM_Displayer::SetTexture() function
899 aImagePath = GetTexture().c_str();
900 if ( ! entry.isEmpty() ) {
901 // check that study is active
902 SalomeApp_Study* study = getActiveStudy();
904 // Store the texture in object properties for next displays
905 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::Texture ), QString( GetTexture().c_str() ) );
906 study->setObjectProperty( aMgrId, entry, GEOM::propertyName( GEOM::DisplayMode ), 3 );
908 // Update propeties map
909 propMap = getObjectProperties( study, entry, myViewFrame );
914 aImagePath = propMap.value( GEOM::propertyName( GEOM::Texture ) ).toString();
917 #if OCC_VERSION_LARGE > 0x06070000
918 Handle(Image_PixMap) aPixmap;
919 if ( !aImagePath.isEmpty() )
920 aPixmap = cacheTextureFor( aImagePath, AISShape );
922 aPixmap = getDefaultTexture();
924 // apply image to shape
925 if ( !aPixmap.IsNull() ) {
926 AISShape->SetTexturePixMap( aPixmap );
927 AISShape->SetTextureMapOn();
928 AISShape->DisableTextureModulate();
931 AISShape->SetTextureMapOff();
934 if ( !aImagePath.isEmpty() ) {
935 AISShape->SetTextureFileName( TCollection_AsciiString( aImagePath.toUtf8().constData() ) );
936 AISShape->SetTextureMapOn();
937 AISShape->DisableTextureModulate();
942 AISShape->SetWidth( HasWidth() ?
943 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
945 // libe width from properties
946 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
948 // set top-level flag
949 AISShape->setTopLevel( propMap.value( GEOM::propertyName( GEOM::TopLevel ) ).toBool() );
951 // set point marker (for vertex / compound of vertices only)
953 QStringList aList = propMap.value( GEOM::propertyName( GEOM::PointMarker ) ).toString().split( GEOM::subSectionSeparator() );
954 if ( aList.size() == 2 ) {
955 // standard marker string contains "TypeOfMarker:ScaleOfMarker"
956 int aTypeOfMarker = aList[0].toInt();
957 double aScaleOfMarker = (aList[1].toInt() + 1) * 0.5;
958 Handle(Prs3d_PointAspect) anAspect = AISShape->Attributes()->PointAspect();
959 anAspect->SetScale( aScaleOfMarker );
960 anAspect->SetTypeOfMarker( (Aspect_TypeOfMarker)( aTypeOfMarker-1 ) );
961 anAspect->SetColor( HasColor() ?
962 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
963 (Quantity_NameOfColor)GetColor() :
964 // color from properties
965 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ) );
966 AISShape->Attributes()->SetPointAspect( anAspect );
968 else if ( aList.size() == 1 ) {
969 // custom marker string contains "IdOfTexture"
970 int textureId = aList[0].toInt();
971 Standard_Integer aWidth, aHeight;
972 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
973 Handle(TColStd_HArray1OfByte) aTexture =
975 Handle(Graphic3d_HArray1OfBytes) aTexture =
977 GeometryGUI::getTexture( study, textureId, aWidth, aHeight );
978 if ( !aTexture.IsNull() ) {
979 #if OCC_VERSION_LARGE > 0x06060000 // Porting to OCCT higher 6.6.0 version
980 Handle(Prs3d_PointAspect) aTextureAspect =
981 new Prs3d_PointAspect( HasColor() ?
982 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
983 (Quantity_NameOfColor)GetColor() :
984 // color from properties
985 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
990 Handle(Prs3d_PointAspect) aTextureAspect =
991 new Prs3d_PointAspect( HasColor() ?
992 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
993 (Quantity_NameOfColor)GetColor() :
994 // color from properties
995 SalomeApp_Tools::color( propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>() ),
1000 AISShape->Attributes()->SetPointAspect( aTextureAspect );
1005 // set field step data
1006 AISShape->setFieldStepInfo( myFieldDataType,
1010 myFieldStepRangeMin,
1011 myFieldStepRangeMax );
1013 if ( create && !isTemporary && aMgrId != -1 ) {
1014 // set properties to the study
1015 study->setObjectPropMap( aMgrId, entry, propMap );
1018 // AISShape->SetName(???); ??? necessary to set name ???
1021 void GEOM_Displayer::updateActorProperties( GEOM_Actor* actor, bool create )
1023 // check that actor is not null
1024 if ( !actor ) return;
1026 // check that study is active
1027 SalomeApp_Study* study = getStudy();
1028 if ( !study ) return;
1030 // set interactive object
1032 Handle( SALOME_InteractiveObject ) anIO;
1034 if ( !myIO.IsNull() ) {
1035 actor->setIO( myIO );
1038 else if ( !myName.empty() ) {
1039 // workaround to allow selection of temporary objects
1040 static int tempId = 0;
1041 anIO = new SALOME_InteractiveObject( QString( "TEMP_VTK_%1" ).arg( tempId++ ).toLatin1().data(), "GEOM", myName.c_str() );
1042 actor->setIO( anIO );
1045 // presentation study entry (empty for temporary objects like preview)
1046 QString entry = !anIO.IsNull() ? QString( anIO->getEntry() ) : QString();
1047 // flag: temporary object
1048 bool isTemporary = entry.isEmpty() || entry.startsWith( "TEMP_" );
1049 // currently active view window's ID (-1 if no active view)
1050 int aMgrId = !anIO.IsNull() ? getViewManagerId( myViewFrame ) : -1;
1052 // get presentation properties
1053 PropMap propMap = getObjectProperties( study, entry, myViewFrame );
1056 /////////////////////////////////////////////////////////////////////////
1057 // VSR: for VTK viewer currently deflection coefficient is hardcoded
1058 // due to performance problem
1059 // actor->SetShape(myShape,aDefPropMap.value(GEOM::propertyName( GEOM::Deflection )).toDouble(),myType == GEOM_VECTOR);
1060 /////////////////////////////////////////////////////////////////////////
1061 if ( !actor->getTopo().IsSame( myShape ) )
1062 actor->SetShape( myShape, VTK_MIN_DEFLECTION, myType == GEOM_VECTOR );
1065 Material_Model material;
1066 material.fromProperties( propMap.value( GEOM::propertyName( GEOM::Material ) ).toString() );
1067 std::vector<vtkProperty*> mprops;
1068 mprops.push_back( material.getMaterialVTKProperty( true ) );
1069 mprops.push_back( material.getMaterialVTKProperty( false) );
1070 actor->SetMaterial( mprops );
1072 // set iso-lines properties
1074 // - set number of iso-lines
1075 int nbIsos[2]= { 1, 1 };
1076 QStringList isos = propMap.value( GEOM::propertyName( GEOM::NbIsos ) ).toString().split( GEOM::subSectionSeparator() );
1077 nbIsos[0] = isos[0].toInt();
1078 nbIsos[1] = isos[1].toInt();
1079 actor->SetNbIsos( nbIsos );
1081 // - set iso-lines width
1082 actor->SetIsosWidth( propMap.value( GEOM::propertyName( GEOM::IsosWidth ) ).toInt() );
1084 // - set iso-lines color
1085 c = propMap.value( GEOM::propertyName( GEOM::IsosColor ) ).value<QColor>();
1086 actor->SetIsosColor( c.redF(), c.greenF(), c.blueF() );
1091 // - same color for all sub-actors
1092 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1093 actor->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1096 // shading color (for non-physical materials)
1097 if ( !material.isPhysical() ) {
1098 c = propMap.value( GEOM::propertyName( GEOM::ShadingColor ) ).value<QColor>();
1099 actor->GetFrontMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1100 actor->GetBackMaterial()->SetColor( c.redF(), c.greenF(), c.blueF() );
1103 // - standalone edge color
1104 c = propMap.value( GEOM::propertyName( GEOM::LineColor ) ).value<QColor>();
1105 actor->SetIsolatedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1107 c = propMap.value( GEOM::propertyName( GEOM::WireframeColor ) ).value<QColor>();
1108 // - shared edges color ???
1109 actor->SetSharedEdgeColor( c.redF(), c.greenF(), c.blueF() );
1111 c = propMap.value( GEOM::propertyName( GEOM::FreeBndColor ) ).value<QColor>();
1112 // - free edges color ???
1113 actor->SetFreeEdgeColor( c.redF(), c.greenF(), c.blueF() );
1116 c = propMap.value( GEOM::propertyName( GEOM::PointColor ) ).value<QColor>();
1117 actor->SetPointColor( c.redF(), c.greenF(), c.blueF() );
1120 // - color for edges in shading+edges mode
1121 c = propMap.value( GEOM::propertyName( GEOM::OutlineColor ) ).value<QColor>();
1122 actor->SetEdgesInShadingColor( c.redF(), c.greenF(), c.blueF() );
1125 if( HasTransparency() ) {
1126 actor->SetOpacity( 1.0 - GetTransparency() );
1128 actor->SetOpacity( 1.0 - propMap.value( GEOM::propertyName( GEOM::Transparency ) ).toDouble() );
1132 actor->SetWidth( HasWidth() ?
1133 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1135 // libe width from properties
1136 propMap.value( GEOM::propertyName( GEOM::LineWidth ) ).toInt() );
1138 // set display vectors flag
1139 actor->SetVectorMode( propMap.value( GEOM::propertyName( GEOM::EdgesDirection ) ).toBool() );
1142 int displayMode = HasDisplayMode() ?
1143 // predefined display mode, manually set to displayer via GEOM_Displayer::SetDisplayMode() function
1145 // display mode from properties
1146 propMap.value( GEOM::propertyName( GEOM::DisplayMode ) ).toInt();
1148 // specific processing of 'shading with edges' mode, as VTK provides only the following standard display modes:
1149 // Points - 0, Wireframe - 1, Surface - 2, Insideframe - 3, SurfaceWithEdges - 4
1150 // GEOM actor allows alternative display modes (see VTKViewer::Representation enum) and enum in GEOM_Actor:
1151 // eWireframe - 0, eShading - 1, eShadingWithEdges - 3
1153 if ( displayMode == 2 )
1154 // this is 'Shading with edges' mode => we have to do the correct mapping to EDisplayMode
1155 // enum in GEOM_Actor (and further to VTKViewer::Representation enum)
1157 actor->setDisplayMode( displayMode );
1160 actor->PickableOn();
1162 actor->PickableOff();
1164 if ( create && !isTemporary && aMgrId != -1 ) {
1165 // set properties to the study
1166 study->setObjectPropMap( aMgrId, entry, propMap );
1170 //=================================================================
1172 * GEOM_Displayer::updateDimensions
1173 * Creates or renews dimension presentation for the IO.
1175 //=================================================================
1176 void GEOM_Displayer::updateDimensions( const Handle(SALOME_InteractiveObject)& theIO,
1177 SALOME_OCCPrs* thePrs,
1178 const gp_Ax3& theShapeLCS )
1180 SalomeApp_Study* aStudy = getStudy();
1186 if ( theIO.IsNull() )
1191 SOCC_Prs* anOccPrs = dynamic_cast<SOCC_Prs*>( thePrs );
1193 AIS_ListOfInteractive aListOfIO;
1195 anOccPrs->GetObjects( aListOfIO );
1197 AIS_ListIteratorOfListOfInteractive aIterateIO( aListOfIO );
1199 // remove outdated presentations of dimensions
1200 for ( ; aIterateIO.More(); aIterateIO.Next() )
1202 const Handle(AIS_InteractiveObject)& anIO = aIterateIO.Value();
1203 if ( !anIO->IsKind( STANDARD_TYPE( AIS_Dimension ) ) )
1208 aListOfIO.Remove( aIterateIO );
1210 if ( !aIterateIO.More() )
1216 // prepare dimension styling
1217 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
1219 QColor aQColor = aResMgr->colorValue ( "Geometry", "dimensions_color", QColor( 0, 255, 0 ) );
1220 int aLineWidth = aResMgr->integerValue( "Geometry", "dimensions_line_width", 1 );
1221 double aFontHeight = aResMgr->doubleValue ( "Geometry", "dimensions_font_height", 10 );
1222 double anArrowLength = aResMgr->doubleValue ( "Geometry", "dimensions_arrow_length", 5 );
1223 bool isUnitsShown = aResMgr->booleanValue( "Geometry", "dimensions_show_units", false );
1224 QString aUnitsLength = aResMgr->stringValue ( "Geometry", "dimensions_length_units", "m" );
1225 QString aUnitsAngle = aResMgr->stringValue ( "Geometry", "dimensions_angle_units", "deg" );
1227 // restore dimension presentation from saved attribute or property data
1228 AIS_ListOfInteractive aRestoredDimensions;
1230 QVariant aProperty = aStudy->getObjectProperty( GEOM::sharedPropertiesId(),
1232 GEOM::propertyName( GEOM::Dimensions ),
1235 GEOMGUI_DimensionProperty aRecords;
1237 if ( aProperty.isValid() && aProperty.canConvert<GEOMGUI_DimensionProperty>() )
1239 aRecords = aProperty.value<GEOMGUI_DimensionProperty>();
1243 aRecords.LoadFromAttribute( getStudy(), theIO->getEntry() );
1246 // create up-to-date dimension presentations
1247 for ( int aPrsIt = 0; aPrsIt < aRecords.GetNumber(); ++aPrsIt )
1249 if ( !aRecords.IsVisible( aPrsIt ) )
1254 // init dimension by type
1255 Handle(AIS_Dimension) aPrs;
1256 switch( aRecords.GetType( aPrsIt ) )
1258 case GEOMGUI_DimensionProperty::DimensionType_Length :
1260 Handle(GEOM_AISLength) aLength = new GEOM_AISLength( aPrsIt );
1261 aRecords.GetRecord( aPrsIt )->AsLength()->Update( aLength, theShapeLCS );
1266 case GEOMGUI_DimensionProperty::DimensionType_Diameter :
1268 Handle(GEOM_AISDiameter) aDiam = new GEOM_AISDiameter( aPrsIt );
1269 aRecords.GetRecord( aPrsIt )->AsDiameter()->Update( aDiam, theShapeLCS );
1274 case GEOMGUI_DimensionProperty::DimensionType_Angle :
1276 Handle(GEOM_AISAngle) anAng = new GEOM_AISAngle( aPrsIt );
1277 aRecords.GetRecord( aPrsIt )->AsAngle()->Update( anAng, theShapeLCS );
1283 aPrs->SetOwner( theIO );
1285 Quantity_Color aColor( aQColor.redF(), aQColor.greenF(), aQColor.blueF(), Quantity_TOC_RGB );
1287 Handle(Prs3d_DimensionAspect) aStyle = new Prs3d_DimensionAspect();
1289 aStyle->SetCommonColor( aColor );
1290 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1291 aStyle->MakeText3d( Standard_True );
1292 aStyle->MakeTextShaded( Standard_True );
1293 aStyle->SetExtensionSize( aFontHeight * 0.5 );
1294 aStyle->TextAspect()->SetHeight( aFontHeight );
1295 aStyle->ArrowAspect()->SetLength( anArrowLength );
1296 aStyle->LineAspect()->SetWidth( aLineWidth );
1297 aStyle->SetTextHorizontalPosition( aPrs->DimensionAspect()->TextHorizontalPosition() );
1298 aStyle->SetTextVerticalPosition( aPrs->DimensionAspect()->TextVerticalPosition() );
1299 aStyle->SetArrowOrientation( aPrs->DimensionAspect()->ArrowOrientation() );
1300 aPrs->SetDimensionAspect( aStyle );
1301 aPrs->SetPolygonOffsets( Aspect_POM_Fill, -1.0, -1.0 );
1302 aPrs->Attributes()->SetDimLengthDisplayUnits( aUnitsLength.toLatin1().data() );
1303 aPrs->Attributes()->SetDimAngleDisplayUnits( aUnitsAngle.toLatin1().data() );
1305 if ( aPrs->IsKind( STANDARD_TYPE(AIS_AngleDimension) ) )
1307 // show degree symbol for dimension instead of label "deg"
1308 if ( aUnitsAngle == "deg" )
1310 aPrs->SetSpecialSymbol(0xB0);
1311 aPrs->SetDisplaySpecialSymbol( isUnitsShown ? AIS_DSS_After : AIS_DSS_No );
1312 aStyle->MakeUnitsDisplayed(Standard_False);
1316 aPrs->SetDisplaySpecialSymbol(AIS_DSS_No);
1317 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1322 aStyle->MakeUnitsDisplayed( (Standard_Boolean) isUnitsShown );
1325 aListOfIO.Append( aPrs );
1328 // update presentation
1331 for ( aIterateIO.Initialize( aListOfIO ); aIterateIO.More(); aIterateIO.Next() )
1333 anOccPrs->AddObject( aIterateIO.Value() );
1337 //=================================================================
1339 * GEOM_Displayer::Erase
1340 * Calls Erase() method for each object in the given list
1342 //=================================================================
1343 void GEOM_Displayer::Erase( const SALOME_ListIO& theIOList,
1345 const bool updateViewer )
1347 SALOME_ListIteratorOfListIO Iter( theIOList );
1348 for ( ; Iter.More(); Iter.Next() )
1349 Erase( Iter.Value(), forced, false );
1355 //=================================================================
1357 * GEOM_Displayer::Redisplay
1358 * Calls Redisplay() method for each object in the given list
1360 //=================================================================
1361 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1362 const bool updateViewer,
1363 const bool checkActiveViewer )
1365 SALOME_ListIteratorOfListIO Iter( theIOList );
1366 for ( ; Iter.More(); Iter.Next() )
1367 Redisplay( Iter.Value(), false, checkActiveViewer );
1373 //=================================================================
1375 * GEOM_Displayer::Redisplay
1376 * Calls Redisplay() method for each object in the given list
1378 //=================================================================
1379 void GEOM_Displayer::Redisplay( const SALOME_ListIO& theIOList,
1380 const bool theUpdateViewer,
1381 SALOME_View* theViewFrame )
1383 SALOME_ListIteratorOfListIO anIter( theIOList );
1384 for ( ; anIter.More(); anIter.Next() )
1386 Redisplay( anIter.Value(), false, theViewFrame );
1389 if ( theUpdateViewer )
1395 //=================================================================
1397 * GEOM_Displayer::Update
1398 * Update OCC presentaion
1399 * [ Reimplemented from SALOME_Displayer ]
1401 //=================================================================
1402 void GEOM_Displayer::Update( SALOME_OCCPrs* prs )
1404 SOCC_Prs* occPrs = dynamic_cast<SOCC_Prs*>( prs );
1405 SalomeApp_Study* study = getStudy();
1407 if ( !occPrs || myShape.IsNull() || !study )
1410 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1413 // specific processing for local coordinate system presentation
1416 TopoDS_Face aFace = TopoDS::Face( myShape );
1417 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1418 if ( !aPlane.IsNull() )
1420 gp_Ax3 aPos = aPlane->Pln().Position();
1421 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1423 Handle(GEOM_AISTrihedron) aTrh;
1425 if ( occPrs->IsNull() )
1427 // new presentation is being created
1428 aTrh = new GEOM_AISTrihedron( aPlc );
1429 occPrs->AddObject( aTrh );
1433 // presentation is being updated
1434 AIS_ListOfInteractive aList;
1435 occPrs->GetObjects( aList );
1436 AIS_ListIteratorOfListOfInteractive anIter( aList );
1437 for ( ; anIter.More() && aTrh.IsNull(); anIter.Next() ) {
1438 aTrh = Handle(GEOM_AISTrihedron)::DownCast( anIter.Value() );
1442 if ( !aTrh.IsNull() ) {
1443 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1445 aTrh->SetColor( (Quantity_NameOfColor)GetColor() );
1446 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1448 aTrh->SetWidth( GetWidth() );
1450 if ( !myIO.IsNull() )
1452 aTrh->setIO( myIO );
1453 aTrh->SetOwner( myIO );
1455 aTrh->SetComponent( aPlc );
1456 aTrh->SetToUpdate();
1458 occPrs->SetToActivate( ToActivate() );
1464 // processing for usual geometry presentation
1467 // if presentation is empty we try to create new one
1468 if ( occPrs->IsNull() )
1470 // create presentation (specific for vectors)
1471 Handle(GEOM_AISShape) AISShape = ( myType == GEOM_VECTOR ) ? new GEOM_AISVector( myShape, "" )
1472 : new GEOM_AISShape ( myShape, "" );
1474 if( myType == GEOM_FIELD_STEP )
1475 AISShape->SetHilightMode( GEOM_AISShape::CustomHighlight );
1476 // update shape properties
1477 updateShapeProperties( AISShape, true );
1479 // add shape to the presentation
1480 occPrs->AddObject( AISShape );
1482 // In accordance with ToActivate() value object will be activated/deactivated
1483 // when it will be displayed
1484 occPrs->SetToActivate( ToActivate() );
1486 if ( AISShape->isTopLevel() && GEOM_AISShape::topLevelDisplayMode() == GEOM_AISShape::TopShowAdditionalWActor ) {
1487 // 21671: EDF 1829 GEOM : Bring to front selected objects (continuation):
1489 // create additional wireframe shape
1490 Handle(GEOM_TopWireframeShape) aWirePrs = new GEOM_TopWireframeShape(myShape);
1491 aWirePrs->SetWidth(AISShape->Width());
1492 if ( !myIO.IsNull() ) {
1493 aWirePrs->setIO( myIO );
1494 aWirePrs->SetOwner( myIO );
1497 // add shape to the presentation
1498 occPrs->AddObject( aWirePrs );
1501 // if presentation is found -> set again shape for it
1504 AIS_ListOfInteractive IOList;
1505 occPrs->GetObjects( IOList );
1506 AIS_ListIteratorOfListOfInteractive Iter( IOList );
1507 for ( ; Iter.More(); Iter.Next() )
1509 Handle(GEOM_AISShape) AISShape = Handle(GEOM_AISShape)::DownCast( Iter.Value() );
1510 if ( AISShape.IsNull() )
1513 // re-set shape (it might be changed)
1514 if ( AISShape->Shape() != myShape )
1515 AISShape->Set( myShape );
1517 // update shape properties
1518 updateShapeProperties( AISShape, false );
1521 AISShape->UpdateSelection();
1522 AISShape->SetToUpdate();
1526 updateDimensions( myIO, occPrs, gp_Ax3().Transformed( myShape.Location().Transformation() ) );
1530 //=================================================================
1532 * GEOM_Displayer::Update
1533 * Update VTK presentaion
1534 * [ Reimplemented from SALOME_Displayer ]
1536 //=================================================================
1537 void GEOM_Displayer::Update( SALOME_VTKPrs* prs )
1539 SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1540 SalomeApp_Study* study = getStudy();
1542 if ( !vtkPrs || myShape.IsNull() || !study )
1545 if ( myType == GEOM_MARKER && myShape.ShapeType() == TopAbs_FACE )
1548 // specific processing for local coordinate system presentation
1551 TopoDS_Face aFace = TopoDS::Face( myShape );
1552 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
1553 if ( !aPlane.IsNull() ) {
1554 gp_Ax3 aPos = aPlane->Pln().Position();
1555 Handle(Geom_Axis2Placement) aPlc = new Geom_Axis2Placement( aPos.Ax2() );
1557 GEOM_VTKTrihedron* aTrh = 0;
1559 if ( vtkPrs->IsNull() ) {
1560 // new presentation is being created
1561 aTrh = GEOM_VTKTrihedron::New();
1562 vtkPrs->AddObject( aTrh );
1565 // presentation is being updated
1566 vtkActorCollection* actors = vtkPrs->GetObjects();
1568 actors->InitTraversal();
1569 vtkActor* a = actors->GetNextActor();
1570 while ( a && !aTrh ) {
1571 aTrh = GEOM_VTKTrihedron::SafeDownCast( a );
1572 a = actors->GetNextActor();
1578 // predefined color, manually set to displayer via GEOM_Displayer::SetColor() function
1580 Quantity_Color aColor( (Quantity_NameOfColor)GetColor() );
1581 aTrh->SetColor( aColor.Red(), aColor.Green(), aColor.Blue() );
1583 #ifdef VTK_TRIHEDRON_WIDTH
1585 // VSR: currently isn't supported
1587 // predefined line width, manually set to displayer via GEOM_Displayer::SetLineWidth() function
1589 aTrh->SetWidth( GetWidth() );
1592 if ( !myIO.IsNull() )
1593 aTrh->setIO( myIO );
1595 aTrh->SetPlacement( aPlc );
1602 // processing for usual geometry presentation
1605 // if presentation is empty we try to create new one
1606 if ( vtkPrs->IsNull() )
1609 GEOM_Actor* actor = GEOM_Actor::New();
1610 // update actor properties
1611 updateActorProperties( actor, true );
1612 // add actor to the presentation
1613 vtkPrs->AddObject( actor );
1616 // presentation is being updated
1617 vtkActorCollection* actors = vtkPrs->GetObjects();
1619 actors->InitTraversal();
1620 vtkActor* a = actors->GetNextActor();
1622 GEOM_Actor* actor = GEOM_Actor::SafeDownCast( a );
1624 // update actor properties
1625 updateActorProperties( actor, false );
1626 a = actors->GetNextActor();
1634 //=================================================================
1636 * GEOM_Displayer::BuildPrs
1637 * Build presentation accordint to the current viewer type
1639 //=================================================================
1640 SALOME_Prs* GEOM_Displayer::BuildPrs( GEOM::GEOM_Object_ptr theObj )
1642 if ( theObj->_is_nil() )
1645 myViewFrame = GetActiveView();
1646 if ( myViewFrame == 0 )
1649 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1654 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), theObj ) );
1655 myType = theObj->GetType();
1657 // Update presentation
1663 //=================================================================
1665 * GEOM_Displayer::BuildPrs
1666 * Build presentation accordint to the current viewer type
1668 //=================================================================
1669 SALOME_Prs* GEOM_Displayer::BuildPrs( const TopoDS_Shape& theShape )
1671 myViewFrame = GetActiveView();
1672 if ( theShape.IsNull() || myViewFrame == 0 )
1675 SALOME_Prs* aPrs = myViewFrame->CreatePrs();
1680 setShape( theShape );
1688 //=================================================================
1690 * GEOM_Displayer::buildPresentation
1691 * Builds/finds object's presentation for the current viewer
1692 * Calls corresponding Update() method by means of double dispatch
1695 //=================================================================
1696 SALOME_Prs* GEOM_Displayer::buildPresentation( const QString& entry,
1697 SALOME_View* theViewFrame )
1699 SALOME_Prs* prs = 0;
1702 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1706 prs = LightApp_Displayer::buildPresentation( entry, theViewFrame );
1709 Handle( SALOME_InteractiveObject ) theIO = new SALOME_InteractiveObject();
1710 theIO->setEntry( entry.toLatin1().constData() );
1711 if ( !theIO.IsNull() )
1713 // set interactive object
1715 // Find SOBject (because shape should be published previously)
1716 SUIT_Session* session = SUIT_Session::session();
1717 SUIT_Application* app = session->activeApplication();
1720 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
1723 _PTR(SObject) SO ( study->studyDS()->FindObjectID( theIO->getEntry() ) );
1726 // get CORBA reference to data object
1727 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject(SO);
1728 if ( !CORBA::is_nil( object ) )
1730 // downcast to GEOM base object
1731 GEOM::GEOM_BaseObject_var GeomBaseObject = GEOM::GEOM_BaseObject::_narrow( object );
1732 if ( !GeomBaseObject->_is_nil() )
1734 myType = GeomBaseObject->GetType();
1736 // downcast to GEOM object
1737 GEOM::GEOM_Object_var GeomObject = GEOM::GEOM_Object::_narrow( GeomBaseObject );
1738 if ( myType == GEOM_FIELD_STEP )
1740 // get the GEOM object from the field's shape
1741 GEOM::GEOM_FieldStep_var GeomFieldStep = GEOM::GEOM_FieldStep::_narrow( GeomBaseObject );
1742 if ( !GeomFieldStep->_is_nil() )
1744 GEOM::GEOM_Field_var GeomField = GeomFieldStep->GetField();
1745 if ( !GeomField->_is_nil() )
1746 GeomObject = GeomField->GetShape();
1749 // read the field step information
1750 readFieldStepInfo( GeomFieldStep );
1753 if ( !GeomObject->_is_nil() )
1755 // finally set shape
1756 setShape( GEOM_Client::get_client().GetShape( GeometryGUI::GetGeomGen(), GeomObject ) );
1764 UpdatePrs( prs ); // Update presentation by using of the double dispatch
1770 //=================================================================
1772 * GEOM_Displayer::buildSubshapePresentation
1773 * Builds/finds object's presentation for the current viewer
1774 * Calls corresponding Update() method by means of double dispatch
1775 * For not published objects (for Mantis issue 0020435)
1777 //=================================================================
1778 SALOME_Prs* GEOM_Displayer::buildSubshapePresentation(const TopoDS_Shape& aShape,
1779 const QString& entry,
1780 SALOME_View* theViewFrame)
1782 SALOME_Prs* prs = 0;
1785 myViewFrame = theViewFrame ? theViewFrame : GetActiveView();
1789 prs = LightApp_Displayer::buildPresentation(entry, theViewFrame);
1792 Handle(SALOME_InteractiveObject) theIO = new SALOME_InteractiveObject();
1793 theIO->setEntry(entry.toLatin1().constData());
1794 if (!theIO.IsNull())
1796 // set interactive object
1798 // finally set shape
1800 myType = GEOM_SUBSHAPE;
1802 UpdatePrs(prs); // Update presentation by using of the double dispatch
1808 //=================================================================
1810 * GEOM_Displayer::internalReset
1811 * Resets internal data
1814 //=================================================================
1815 void GEOM_Displayer::internalReset()
1820 myFieldDataType = GEOM::FDT_Double;
1821 myFieldDimension = 0;
1822 myFieldStepData.clear();
1823 myFieldStepName.Clear();
1824 myFieldStepRangeMin = 0;
1825 myFieldStepRangeMax = 0;
1828 //=================================================================
1830 * GEOM_Displayer::LocalSelection
1831 * Activate selection of CAD shapes with activisation of selection
1832 * of their sub-shapes (with opened local context for OCC viewer)
1834 //=================================================================
1835 void GEOM_Displayer::LocalSelection( const Handle(SALOME_InteractiveObject)& theIO, const int theMode )
1837 SUIT_Session* session = SUIT_Session::session();
1838 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1842 LightApp_SelectionMgr* sm = app->selectionMgr();
1844 // remove all filters from selection
1847 SALOME_View* vf = GetActiveView();
1849 if (!theIO.IsNull() && !vf->isVisible(theIO))
1851 SALOME_Prs* prs = vf->CreatePrs( theIO.IsNull() ? 0 : theIO->getEntry() );
1852 vf->LocalSelection( prs, theMode );
1853 delete prs; // delete presentation because displayer is its owner
1857 //=================================================================
1859 * GEOM_Displayer::globalSelection
1860 * Activate selection of CAD shapes without activisation of selection
1861 * of their sub-shapes (without opened local context for OCC viewer)
1863 //=================================================================
1864 void GEOM_Displayer::GlobalSelection( const int theMode, const bool update )
1866 TColStd_MapOfInteger aModes;
1867 aModes.Add( theMode );
1868 GlobalSelection( aModes, update );
1871 //=================================================================
1873 * GEOM_Displayer::globalSelection
1874 * Activate selection of CAD shapes without activisation of selection
1875 * of their sub-shapes (without opened local context for OCC viewer)
1877 //=================================================================
1878 void GEOM_Displayer::GlobalSelection( const TColStd_MapOfInteger& theModes,
1879 const bool update, const QList<int>* theSubShapes )
1881 SUIT_Session* session = SUIT_Session::session();
1882 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
1886 SALOME_View* vf = GetActiveView();
1890 // Close local context
1891 vf->GlobalSelection( update );
1893 // Set selection filters in accordance with current mode
1894 LightApp_SelectionMgr* sm = app->selectionMgr();
1898 // Remove from selection temporary objects if necessary
1899 if ( !theModes.Contains( GEOM_PREVIEW ) )
1900 clearTemporary( sm );
1902 //@ aSel->ClearIndex();
1906 // Remove filters from AIS_InteractiveContext
1907 Handle(AIS_InteractiveContext) ic;
1908 SOCC_Viewer* viewer = dynamic_cast<SOCC_Viewer*>( vf );
1911 ic = viewer->getAISContext();
1913 ic->RemoveFilters();
1916 if ( theModes.Contains( GEOM_ALLOBJECTS ) )
1919 SUIT_SelectionFilter* aFilter;
1920 if ( theModes.Extent() == 1 )
1922 int aMode = TColStd_MapIteratorOfMapOfInteger( theModes ).Key();
1924 if ( aMode == GEOM_COMPOUNDFILTER )
1925 aFilter = getComplexFilter( theSubShapes );
1927 aFilter = getFilter( aMode );
1929 else if ( theModes.Extent() > 1 )
1931 TColStd_MapOfInteger aTopAbsModes;
1932 TColStd_MapIteratorOfMapOfInteger anIter( theModes );
1933 QList<SUIT_SelectionFilter*> aListOfFilters;
1934 for ( ; anIter.More(); anIter.Next() )
1936 SUIT_SelectionFilter* aFilter;
1937 int aMode = anIter.Key();
1938 if ( aMode == GEOM_COMPOUNDFILTER )
1939 aFilter = getComplexFilter( theSubShapes );
1941 aFilter = getFilter( aMode );
1944 aListOfFilters.append( aFilter );
1947 aFilter = new GEOM_LogicalFilter( aListOfFilters, GEOM_LogicalFilter::LO_OR );
1954 sm->installFilter( aFilter );
1957 Handle(GEOM_OCCFilter) anOCCFilter = new GEOM_OCCFilter( sm );
1958 ic->AddFilter( anOCCFilter );
1963 //=================================================================
1965 * GEOM_Displayer::LocalSelection
1966 * Activate selection of CAD shapes with activisation of selection
1967 * of their sub-shapes (with opened local context for OCC viewer)
1969 //=================================================================
1970 void GEOM_Displayer::LocalSelection( const SALOME_ListIO& theIOList, const int theMode )
1972 SALOME_ListIteratorOfListIO Iter( theIOList );
1973 for ( ; Iter.More(); Iter.Next() )
1974 LocalSelection( Iter.Value(), theMode );
1977 //=================================================================
1979 * GEOM_Displayer::BeforeDisplay
1980 * Called before displaying of pars. Close local context
1981 * [ Reimplemented from SALOME_Displayer ]
1983 //=================================================================
1984 void GEOM_Displayer::BeforeDisplay( SALOME_View* v, const SALOME_OCCPrs* )
1986 SOCC_Viewer* vf = dynamic_cast<SOCC_Viewer*>( v );
1989 Handle(AIS_InteractiveContext) ic = vf->getAISContext();
1992 if ( ic->HasOpenedContext() )
1993 ic->CloseAllContexts();
1998 void GEOM_Displayer::AfterDisplay( SALOME_View* v, const SALOME_OCCPrs* p )
2000 UpdateColorScale(false,false);
2003 #if OCC_VERSION_LARGE > 0x06070000
2004 void GEOM_Displayer::BeforeErase( SALOME_View* v, const SALOME_OCCPrs* p )
2006 LightApp_Displayer::BeforeErase( v, p );
2007 releaseTextures( p );
2011 void GEOM_Displayer::AfterErase( SALOME_View* v, const SALOME_OCCPrs* p )
2013 LightApp_Displayer::AfterErase( v, p );
2014 UpdateColorScale(false,false);
2017 //=================================================================
2019 * GEOM_Displayer::SetColor
2020 * Set color for shape displaying. If it is equal -1 then default color is used.
2021 * Available values are from Quantity_NameOfColor enumeration
2023 //=================================================================
2024 void GEOM_Displayer::SetColor( const int color )
2031 myShadingColor = Quantity_Color( (Quantity_NameOfColor)color );
2035 int GEOM_Displayer::GetColor() const
2040 bool GEOM_Displayer::HasColor() const
2042 return myColor != -1;
2045 void GEOM_Displayer::UnsetColor()
2049 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2050 QColor col = resMgr->colorValue( "Geometry", "shading_color", QColor( 255, 0, 0 ) );
2051 myShadingColor = SalomeApp_Tools::color( col );
2054 //=================================================================
2056 * GEOM_Displayer::SetTransparency
2057 * Set transparency for shape displaying.
2059 //=================================================================
2060 void GEOM_Displayer::SetTransparency( const double transparency )
2062 myTransparency = transparency;
2065 double GEOM_Displayer::GetTransparency() const
2067 return myTransparency;
2070 bool GEOM_Displayer::HasTransparency() const
2072 return myTransparency != -1.0;
2075 void GEOM_Displayer::UnsetTransparency()
2077 myTransparency = -1.0;
2081 //=================================================================
2083 * GEOM_Displayer::SetTexture
2084 * Set color for shape displaying. If it is equal -1 then default color is used.
2085 * Available values are from Quantity_NameOfColor enumeration
2087 //=================================================================
2088 void GEOM_Displayer::SetTexture( const std::string& texureFileName )
2090 if(texureFileName!="")
2092 myTexture = texureFileName;
2096 bool GEOM_Displayer::HasTexture() const
2098 return myTexture != "";
2101 std::string GEOM_Displayer::GetTexture() const
2106 //=================================================================
2108 * GEOM_Displayer::SetWidth
2109 * Set width of shape displaying. If it is equal -1 then default width is used.
2111 //=================================================================
2112 void GEOM_Displayer::SetWidth( const double width )
2117 double GEOM_Displayer::GetWidth() const
2122 bool GEOM_Displayer::HasWidth() const
2124 return myWidth != -1;
2127 void GEOM_Displayer::UnsetWidth()
2133 int GEOM_Displayer::GetIsosWidth() const
2138 void GEOM_Displayer::SetIsosWidth(const int width)
2140 myIsosWidth = width;
2143 bool GEOM_Displayer::HasIsosWidth() const
2145 return myIsosWidth != -1;
2149 //=================================================================
2151 * GEOM_Displayer::SetToActivate
2152 * This method is used for activisation/deactivisation of objects to be displayed
2154 //=================================================================
2155 void GEOM_Displayer::SetToActivate( const bool toActivate )
2157 myToActivate = toActivate;
2159 bool GEOM_Displayer::ToActivate() const
2161 return myToActivate;
2164 //=================================================================
2166 * GEOM_Displayer::clearTemporary
2167 * Removes from selection temporary objects
2169 //=================================================================
2170 void GEOM_Displayer::clearTemporary( LightApp_SelectionMgr* theSelMgr )
2172 SALOME_ListIO selected, toSelect;
2173 theSelMgr->selectedObjects( selected );
2175 for ( SALOME_ListIteratorOfListIO it( selected ) ; it.More(); it.Next() ) {
2176 Handle(SALOME_InteractiveObject) io = it.Value();
2177 if ( !io.IsNull() && io->hasEntry() && strncmp( io->getEntry(), "TEMP_", 5 ) != 0 )
2178 toSelect.Append( it.Value() );
2181 theSelMgr->setSelectedObjects( toSelect, true );
2184 void GEOM_Displayer::SetName( const char* theName )
2189 void GEOM_Displayer::UnsetName()
2194 SalomeApp_Study* GEOM_Displayer::getStudy() const
2196 return dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2199 void GEOM_Displayer::setIO( const Handle(SALOME_InteractiveObject)& theIO )
2204 void GEOM_Displayer::setShape( const TopoDS_Shape& theShape )
2209 void GEOM_Displayer::setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
2210 const int theFieldDimension,
2211 const QList<QVariant>& theFieldStepData,
2212 const TCollection_AsciiString& theFieldStepName,
2213 const double theFieldStepRangeMin,
2214 const double theFieldStepRangeMax )
2216 myFieldDataType = theFieldDataType;
2217 myFieldDimension = theFieldDimension;
2218 myFieldStepData = theFieldStepData;
2219 myFieldStepName = theFieldStepName;
2220 myFieldStepRangeMin = theFieldStepRangeMin;
2221 myFieldStepRangeMax = theFieldStepRangeMax;
2224 bool GEOM_Displayer::canBeDisplayed( const QString& entry, const QString& viewer_type ) const
2226 _PTR(SObject) anObj = getStudy()->studyDS()->FindObjectID( (const char*)entry.toLatin1() );
2227 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM objects
2228 GEOM::GEOM_FieldStep_var aFieldStepObj = GEOM::GEOM_FieldStep::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of GEOM field steps
2229 GEOM::GEOM_Gen_var aCompObj = GEOM::GEOM_Gen::_narrow(GeometryGUI::ClientSObjectToObject(anObj)); // enable displaying of whole GEOM component
2230 return ( !CORBA::is_nil( aGeomObj ) || !CORBA::is_nil( aFieldStepObj ) || !CORBA::is_nil( aCompObj ) ) &&
2231 (viewer_type == SOCC_Viewer::Type() || viewer_type == SVTK_Viewer::Type());
2234 int GEOM_Displayer::SetDisplayMode( const int theMode )
2236 int aPrevMode = myDisplayMode;
2237 if ( theMode != -1 ) {
2238 myDisplayMode = theMode;
2239 myHasDisplayMode = true;
2247 int GEOM_Displayer::GetDisplayMode() const
2249 return myDisplayMode;
2252 int GEOM_Displayer::UnsetDisplayMode()
2254 int aPrevMode = myDisplayMode;
2255 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2256 myDisplayMode = resMgr->integerValue( "Geometry", "display_mode", 0 );
2257 myHasDisplayMode = false;
2261 bool GEOM_Displayer::HasDisplayMode() const
2263 return myHasDisplayMode;
2266 SALOMEDS::Color GEOM_Displayer::getPredefinedUniqueColor()
2268 static QList<QColor> colors;
2270 if ( colors.isEmpty() ) {
2272 for (int s = 0; s < 2 ; s++)
2274 for (int v = 100; v >= 40; v = v - 20)
2276 for (int h = 0; h < 359 ; h = h + 60)
2278 colors.append(QColor::fromHsv(h, 255 - s * 127, v * 255 / 100));
2284 static int currentColor = 0;
2286 SALOMEDS::Color color;
2287 color.R = (double)colors[currentColor].red() / 255.0;
2288 color.G = (double)colors[currentColor].green() / 255.0;
2289 color.B = (double)colors[currentColor].blue() / 255.0;
2291 currentColor = (currentColor+1) % colors.count();
2296 SALOMEDS::Color GEOM_Displayer::getUniqueColor( const QList<SALOMEDS::Color>& theReservedColors )
2299 int aTolerance = 64;
2300 int anIterations = 0;
2306 if( anIterations % aPeriod == 0 )
2309 if( aTolerance < 1 )
2312 //std::cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< std::endl;
2314 aHue = (int)( 360.0 * rand() / RAND_MAX );
2315 //std::cout << "Hue = " << aHue << std::endl;
2317 //std::cout << "Auto colors : ";
2319 QList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
2320 QList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
2321 for( ; it != itEnd; ++it )
2323 SALOMEDS::Color anAutoColor = *it;
2324 QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
2327 aQColor.getHsv( &h, &s, &v );
2328 //std::cout << h << " ";
2329 if( abs( h - aHue ) < aTolerance )
2332 //std::cout << "break (diff = " << abs( h - aHue ) << ")";
2336 //std::cout << std::endl;
2342 //std::cout << "Hue of the returned color = " << aHue << std::endl;
2344 aColor.setHsv( aHue, 255, 255 );
2346 SALOMEDS::Color aSColor;
2347 aSColor.R = (double)aColor.red() / 255.0;
2348 aSColor.G = (double)aColor.green() / 255.0;
2349 aSColor.B = (double)aColor.blue() / 255.0;
2354 PropMap GEOM_Displayer::getObjectProperties( SalomeApp_Study* study,
2355 const QString& entry,
2358 // get default properties for the explicitly specified default view type
2359 PropMap propMap = GEOM_Displayer::getDefaultPropertyMap();
2361 if ( study && view ) {
2362 SUIT_ViewModel* viewModel = dynamic_cast<SUIT_ViewModel*>( view );
2363 SUIT_ViewManager* viewMgr = ( viewModel != 0 ) ? viewModel->getViewManager() : 0;
2364 int viewId = ( viewMgr != 0 ) ? viewMgr->getGlobalId() : -1;
2366 if ( viewModel && viewId != -1 ) {
2367 // get properties from the study
2368 PropMap storedMap = study->getObjectPropMap( viewId, entry );
2369 // overwrite default properties from stored ones (that are specified)
2370 for ( int prop = GEOM::Visibility; prop <= GEOM::LastProperty; prop++ ) {
2371 if ( storedMap.contains( GEOM::propertyName( (GEOM::Property)prop ) ) )
2372 propMap.insert( GEOM::propertyName( (GEOM::Property)prop ),
2373 storedMap.value( GEOM::propertyName( (GEOM::Property)prop ) ) );
2375 // ... specific processing for color
2376 // ... current implementation is to use same stored color for all aspects
2377 // ... (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2378 if ( storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2379 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2380 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2381 propMap.insert( GEOM::propertyName( GEOM::LineColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2382 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2383 propMap.insert( GEOM::propertyName( GEOM::PointColor ), storedMap.value( GEOM::propertyName( GEOM::Color ) ) );
2386 if ( !entry.isEmpty() ) {
2387 // get CORBA reference to geom object
2388 _PTR(SObject) SO( study->studyDS()->FindObjectID( entry.toStdString() ) );
2390 CORBA::Object_var object = GeometryGUI::ClientSObjectToObject( SO );
2391 if ( !CORBA::is_nil( object ) ) {
2392 GEOM::GEOM_Object_var geomObject = GEOM::GEOM_Object::_narrow( object );
2393 if ( !CORBA::is_nil( geomObject ) ) { // to check
2394 // check that geom object has color properly set
2395 bool hasColor = false;
2396 SALOMEDS::Color aSColor = getColor( geomObject, hasColor );
2397 // set color from geometry object (only once, if it is not yet set in GUI)
2398 // current implementation is to use same color for all aspects
2399 // (TODO) possible future improvements about free boundaries, standalone edges etc colors can be here
2400 if ( hasColor && !storedMap.contains( GEOM::propertyName( GEOM::Color ) ) ) {
2401 QColor objColor = QColor::fromRgbF( aSColor.R, aSColor.G, aSColor.B );
2402 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ), objColor );
2403 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ), objColor );
2404 propMap.insert( GEOM::propertyName( GEOM::LineColor ), objColor );
2405 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ), objColor );
2406 propMap.insert( GEOM::propertyName( GEOM::PointColor ), objColor );
2408 // check that object has point marker properly set
2409 GEOM::marker_type mType = geomObject->GetMarkerType();
2410 GEOM::marker_size mSize = geomObject->GetMarkerSize();
2411 int mTextureId = geomObject->GetMarkerTexture();
2412 bool hasMarker = ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER && mSize > GEOM::MS_NONE && mSize <= GEOM::MS_70 ) ||
2413 ( mType == GEOM::MT_USER && mTextureId > 0 );
2414 // set point marker from geometry object (only once, if it is not yet set in GUI)
2415 if ( hasMarker && !storedMap.contains( GEOM::propertyName( GEOM::PointMarker ) ) ) {
2416 if ( mType > GEOM::MT_NONE && mType < GEOM::MT_USER ) {
2418 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2419 QString( "%1%2%3" ).arg( (int)mType ).arg( GEOM::subSectionSeparator() ).arg( (int)mSize ) );
2421 else if ( mType == GEOM::MT_USER ) {
2423 propMap.insert( GEOM::propertyName( GEOM::PointMarker ), QString::number( mTextureId ) );
2435 PropMap GEOM_Displayer::getDefaultPropertyMap()
2439 // get resource manager
2440 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2442 // fill in the properties map with default values
2444 // - visibility (false by default)
2445 propMap.insert( GEOM::propertyName( GEOM::Visibility ), false );
2447 // - nb isos (take default value from preferences)
2448 propMap.insert( GEOM::propertyName( GEOM::NbIsos ),
2449 QString( "%1%2%3" ).
2450 arg( resMgr->integerValue( "Geometry", "iso_number_u", 1 ) ).
2451 arg( GEOM::subSectionSeparator() ).
2452 arg( resMgr->integerValue( "Geometry", "iso_number_v", 1 ) ) );
2454 // - transparency (opacity = 1-transparency)
2455 propMap.insert( GEOM::propertyName( GEOM::Transparency ), 0.0 );
2457 // - display mode (take default value from preferences)
2458 propMap.insert( GEOM::propertyName( GEOM::DisplayMode ),
2459 resMgr->integerValue( "Geometry", "display_mode", 0 ) );
2461 // - show edges direction flag (false by default)
2462 propMap.insert( GEOM::propertyName( GEOM::EdgesDirection ), false );
2464 // - shading color (take default value from preferences)
2465 propMap.insert( GEOM::propertyName( GEOM::ShadingColor ),
2466 colorFromResources( "shading_color", QColor( 255, 255, 0 ) ) );
2468 // - wireframe color (take default value from preferences)
2469 propMap.insert( GEOM::propertyName( GEOM::WireframeColor ),
2470 colorFromResources( "wireframe_color", QColor( 255, 255, 0 ) ) );
2472 // - standalone edges color (take default value from preferences)
2473 propMap.insert( GEOM::propertyName( GEOM::LineColor ),
2474 colorFromResources( "line_color", QColor( 255, 0, 0 ) ) );
2476 // - free boundaries color (take default value from preferences)
2477 propMap.insert( GEOM::propertyName( GEOM::FreeBndColor ),
2478 colorFromResources( "free_bound_color", QColor( 0, 255, 0 ) ) );
2480 // - points color (take default value from preferences)
2481 propMap.insert( GEOM::propertyName( GEOM::PointColor ),
2482 colorFromResources( "point_color", QColor( 255, 255, 0 ) ) );
2484 // - isos color (take default value from preferences)
2485 propMap.insert( GEOM::propertyName( GEOM::IsosColor ),
2486 colorFromResources( "isos_color", QColor( 200, 200, 200 ) ) );
2488 // - outlines color (take default value from preferences)
2489 propMap.insert( GEOM::propertyName( GEOM::OutlineColor ),
2490 colorFromResources( "edges_in_shading_color", QColor( 180, 180, 180 ) ) );
2492 // - deflection coefficient (take default value from preferences)
2493 propMap.insert( GEOM::propertyName( GEOM::Deflection ),
2494 resMgr->doubleValue( "Geometry", "deflection_coeff", 0.001 ) );
2496 // - material (take default value from preferences)
2497 Material_Model material;
2498 material.fromResources( resMgr->stringValue( "Geometry", "material", "Plastic" ) );
2499 propMap.insert( GEOM::propertyName( GEOM::Material ), material.toProperties() );
2501 // - edge width (take default value from preferences)
2502 propMap.insert( GEOM::propertyName( GEOM::LineWidth ),
2503 resMgr->integerValue( "Geometry", "edge_width", 1 ) );
2505 // - isos width (take default value from preferences)
2506 propMap.insert( GEOM::propertyName( GEOM::IsosWidth ),
2507 resMgr->integerValue( "Geometry", "isolines_width", 1 ) );
2509 // - point marker (take default value from preferences)
2510 propMap.insert( GEOM::propertyName( GEOM::PointMarker ),
2511 QString( "%1%2%3" ).
2512 arg( resMgr->integerValue( "Geometry", "type_of_marker", 1 ) + 1 ).
2513 arg( GEOM::subSectionSeparator() ).
2514 arg( resMgr->integerValue( "Geometry", "marker_scale", 1 ) ) );
2516 // - top-level flag (false by default)
2517 propMap.insert( GEOM::propertyName( GEOM::TopLevel ), false );
2522 SALOMEDS::Color GEOM_Displayer::getColor(GEOM::GEOM_Object_var theGeomObject, bool& hasColor) {
2523 SALOMEDS::Color aSColor;
2526 SUIT_Session* session = SUIT_Session::session();
2527 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
2529 if ( app && !theGeomObject->_is_nil()) {
2530 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2533 _PTR(Study) aStudy = study->studyDS();
2534 aSColor = theGeomObject->GetColor();
2535 hasColor = aSColor.R >= 0 && aSColor.G >= 0 && aSColor.B >= 0;
2537 #ifdef GENERAL_AUTOCOLOR // auto-color for all sub-shapes
2538 bool general_autocolor = true;
2539 #else // auto-color for groups only
2540 bool general_autocolor = false;
2541 #endif // GENERAL_AUTOCOLOR
2542 if ( general_autocolor || theGeomObject->GetType() == GEOM_GROUP ) {
2543 GEOM::GEOM_Object_var aMainObject = theGeomObject->GetMainShape();
2544 if ( !CORBA::is_nil( aMainObject ) && aMainObject->GetAutoColor() ) {
2545 #ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
2546 aSColor = getPredefinedUniqueColor();
2548 #else // old algorithm for auto-colors
2549 QList<SALOMEDS::Color> aReservedColors;
2550 CORBA::String_var IOR = app->orb()->object_to_string( aMainObject );
2551 _PTR(SObject) aMainSObject( aStudy->FindObjectIOR( IOR.in() ) );
2552 if ( aMainSObject ) {
2553 _PTR(ChildIterator) it( aStudy->NewChildIterator( aMainSObject ) );
2554 for ( ; it->More(); it->Next() ) {
2555 _PTR(SObject) aChildSObject( it->Value() );
2556 GEOM::GEOM_Object_var aChildObject =
2557 GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(aChildSObject));
2558 if ( CORBA::is_nil( aChildObject ) )
2561 SALOMEDS::Color aReservedColor = aChildObject->GetColor();
2562 if ( aReservedColor.R >= 0 && aReservedColor.G >= 0 && aReservedColor.B >= 0 )
2563 aReservedColors.append( aReservedColor );
2566 aSColor = getUniqueColor( aReservedColors );
2568 #endif // SIMPLE_AUTOCOLOR
2578 void GEOM_Displayer::EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
2579 const bool eraseOnlyChildren) {
2580 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
2584 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
2588 LightApp_DataObject* parent = appStudy->findObjectByEntry(theIO->getEntry());
2593 // Erase from all views
2594 QList<SALOME_View*> views;
2596 ViewManagerList vmans = app->viewManagers();
2597 SUIT_ViewManager* vman;
2598 foreach ( vman, vmans ) {
2599 SUIT_ViewModel* vmod = vman->getViewModel();
2600 view = dynamic_cast<SALOME_View*> ( vmod );
2602 views.append( view );
2605 if( views.count() == 0 )
2608 //Erase childrens w/o update views
2609 DataObjectList listObj = parent->children( true );
2610 SUIT_DataObject* obj;
2611 foreach( obj, listObj ) {
2612 LightApp_DataObject* l_obj = dynamic_cast<LightApp_DataObject*>(obj);
2614 foreach ( view, views ) {
2615 Handle(SALOME_InteractiveObject) anIO =
2616 new SALOME_InteractiveObject(qPrintable(l_obj->entry()), "GEOM", "");
2617 Erase(anIO, false, false, view);
2621 //Erase parent with view update or repaint views
2622 foreach ( view, views ) {
2623 if(!eraseOnlyChildren)
2624 Erase(theIO, false, true, view);
2630 void GEOM_Displayer::readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep )
2632 if( theGeomFieldStep->_is_nil() )
2635 GEOM::GEOM_Field_var aGeomField = theGeomFieldStep->GetField();
2636 if( aGeomField->_is_nil() )
2639 GEOM::GEOM_Object_var aGeomFieldShape = aGeomField->GetShape();
2640 if( aGeomFieldShape->_is_nil() )
2643 TCollection_AsciiString aFieldStepName( theGeomFieldStep->GetName() );
2644 TCollection_AsciiString aFieldName( aGeomField->GetName() );
2645 TCollection_AsciiString aShapeName( aGeomFieldShape->GetName() );
2647 aFieldStepName = aShapeName + "\n" + aFieldName + "\n" + aFieldStepName;
2649 GEOM::field_data_type aFieldDataType = aGeomField->GetDataType();
2651 int aFieldDimension = aGeomField->GetDimension();
2653 GEOM::string_array_var aFieldComponents = aGeomField->GetComponents();
2654 int aFieldNbComponents = aFieldComponents->length();
2656 QList<QVariant> aFieldStepData;
2657 if( aFieldDataType == GEOM::FDT_Bool )
2659 GEOM::GEOM_BoolFieldStep_var aGeomBoolFieldStep = GEOM::GEOM_BoolFieldStep::_narrow( theGeomFieldStep );
2660 if ( !aGeomBoolFieldStep->_is_nil() )
2662 GEOM::short_array_var aValues = aGeomBoolFieldStep->GetValues();
2663 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2664 aFieldStepData << (bool)aValues[i];
2667 else if( aFieldDataType == GEOM::FDT_Int )
2669 GEOM::GEOM_IntFieldStep_var aGeomIntFieldStep = GEOM::GEOM_IntFieldStep::_narrow( theGeomFieldStep );
2670 if ( !aGeomIntFieldStep->_is_nil() )
2672 GEOM::ListOfLong_var aValues = aGeomIntFieldStep->GetValues();
2673 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2674 aFieldStepData << (qlonglong)aValues[i];
2677 else if( aFieldDataType == GEOM::FDT_Double )
2679 GEOM::GEOM_DoubleFieldStep_var aGeomDoubleFieldStep = GEOM::GEOM_DoubleFieldStep::_narrow( theGeomFieldStep );
2680 if ( !aGeomDoubleFieldStep->_is_nil() )
2682 GEOM::ListOfDouble_var aValues = aGeomDoubleFieldStep->GetValues();
2683 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2684 aFieldStepData << (double)aValues[i];
2687 else if( aFieldDataType == GEOM::FDT_String )
2689 GEOM::GEOM_StringFieldStep_var aGeomStringFieldStep = GEOM::GEOM_StringFieldStep::_narrow( theGeomFieldStep );
2690 if ( !aGeomStringFieldStep->_is_nil() )
2692 GEOM::string_array_var aValues = aGeomStringFieldStep->GetValues();
2693 for( size_t i = 0, n = aValues->length(); i < n; i++ )
2694 aFieldStepData << QString( aValues[i] );
2698 double aFieldStepRangeMin = 0, aFieldStepRangeMax = 0;
2699 aFieldStepData = groupFieldData( aFieldStepData,
2701 aFieldDataType == GEOM::FDT_String,
2703 aFieldStepRangeMax );
2705 setFieldStepInfo( aFieldDataType,
2710 aFieldStepRangeMax );
2713 QList<QVariant> GEOM_Displayer::groupFieldData( const QList<QVariant>& theFieldStepData,
2714 const int theFieldNbComponents,
2715 const bool theIsString,
2716 double& theFieldStepRangeMin,
2717 double& theFieldStepRangeMax )
2719 QList<QVariant> aResultList;
2720 theFieldStepRangeMin = 0;
2721 theFieldStepRangeMax = 0;
2723 if( theFieldStepData.isEmpty() || theFieldNbComponents < 1 )
2726 int aNbSubShapes = theFieldStepData.count() / theFieldNbComponents;
2728 QList<QVariant> aGroupedList;
2730 bool anIsBoolean = false;
2731 for( int aSubShape = 0; aSubShape < aNbSubShapes; aSubShape++ )
2734 QStringList aStringList;
2736 int aBaseIndex = aSubShape * theFieldNbComponents;
2737 for( int aComponent = 0; aComponent < theFieldNbComponents; aComponent++ )
2739 int anIndex = aComponent + aBaseIndex;
2741 const QVariant& aVariant = theFieldStepData[ anIndex ];
2744 if( aVariant.type() == QVariant::String )
2745 aStringList << aVariant.toString();
2750 if( aVariant.type() == QVariant::Bool )
2752 aValue = aVariant.toBool() ? 1.0 : 0.0;
2758 if( aVariant.type() == QVariant::LongLong )
2759 aValue = double( aVariant.toLongLong() );
2760 else if( aVariant.type() == QVariant::Double )
2761 aValue = aVariant.toDouble();
2762 aNorm += aValue * aValue;
2768 aGroupedList << aStringList.join( "\n" );
2772 aNorm /= theFieldNbComponents;
2774 aNorm = pow( aNorm, 0.5 );
2776 if( aGroupedList.isEmpty() )
2777 theFieldStepRangeMin = theFieldStepRangeMax = aNorm;
2780 theFieldStepRangeMin = Min( theFieldStepRangeMin, aNorm );
2781 theFieldStepRangeMax = Max( theFieldStepRangeMax, aNorm );
2784 aGroupedList << aNorm;
2790 theFieldStepRangeMin = 0.0;
2791 theFieldStepRangeMax = 1.0;
2794 SUIT_Session* session = SUIT_Session::session();
2795 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2796 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2798 QListIterator<QVariant> anIter( aGroupedList );
2799 while( anIter.hasNext() )
2801 const QVariant& aVariant = anIter.next();
2803 aResultList << aVariant;
2807 Quantity_Color aColor;
2808 if( FindColor( aVariant.toDouble(), theFieldStepRangeMin, theFieldStepRangeMax, anIsBoolean ? 2 : aNbIntervals, aColor ) )
2809 aQColor = QColor::fromRgbF( aColor.Red(), aColor.Green(), aColor.Blue() );
2810 aResultList << aQColor;
2816 // Note: the method is copied from Aspect_ColorScale class
2817 Standard_Integer GEOM_Displayer::HueFromValue( const Standard_Integer aValue,
2818 const Standard_Integer aMin,
2819 const Standard_Integer aMax )
2821 Standard_Integer minLimit( 0 ), maxLimit( 230 );
2823 Standard_Integer aHue = maxLimit;
2825 aHue = (Standard_Integer)( maxLimit - ( maxLimit - minLimit ) * ( aValue - aMin ) / ( aMax - aMin ) );
2827 aHue = Min( Max( minLimit, aHue ), maxLimit );
2832 // Note: the method is copied from Aspect_ColorScale class
2833 Standard_Boolean GEOM_Displayer::FindColor( const Standard_Real aValue,
2834 const Standard_Real aMin,
2835 const Standard_Real aMax,
2836 const Standard_Integer ColorsCount,
2837 Quantity_Color& aColor )
2839 if( aValue<aMin || aValue>aMax || aMax<aMin )
2840 return Standard_False;
2844 Standard_Real IntervNumber = 0;
2847 else if( aValue>aMax )
2848 IntervNumber = ColorsCount-1;
2849 else if( Abs( aMax-aMin ) > Precision::Approximation() )
2850 IntervNumber = Floor( Standard_Real( ColorsCount ) * ( aValue - aMin ) / ( aMax - aMin ) ); // 'Ceiling' replaced with 'Floor'
2852 Standard_Integer Interv = Standard_Integer( IntervNumber );
2854 aColor = Quantity_Color( HueFromValue( Interv, 0, ColorsCount - 1 ), 1.0, 1.0, Quantity_TOC_HLS );
2856 return Standard_True;
2860 void GEOM_Displayer::UpdateColorScale( const bool theIsRedisplayFieldSteps, const bool updateViewer )
2862 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( myApp->activeStudy() );
2866 SOCC_Viewer* aViewModel = dynamic_cast<SOCC_Viewer*>( GetActiveView() );
2870 Handle(V3d_Viewer) aViewer = aViewModel->getViewer3d();
2871 if( aViewer.IsNull() )
2874 aViewer->InitActiveViews();
2875 if( !aViewer->MoreActiveViews() )
2878 Handle(V3d_View) aView = aViewer->ActiveView();
2879 if( aView.IsNull() )
2882 Standard_Boolean anIsDisplayColorScale = Standard_False;
2883 TCollection_AsciiString aColorScaleTitle;
2884 Standard_Real aColorScaleMin = 0, aColorScaleMax = 0;
2885 Standard_Boolean anIsBoolean = Standard_False;
2887 SALOME_ListIO aSelectedObjects;
2888 myApp->selectionMgr()->selectedObjects( aSelectedObjects );
2889 if( aSelectedObjects.Extent() == 1 )
2891 Handle(SALOME_InteractiveObject) anIO = aSelectedObjects.First();
2892 if( !anIO.IsNull() )
2894 SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( aViewModel->CreatePrs( anIO->getEntry() ) );
2897 AIS_ListOfInteractive aList;
2898 aPrs->GetObjects( aList );
2899 AIS_ListIteratorOfListOfInteractive anIter( aList );
2900 for( ; anIter.More(); anIter.Next() )
2902 Handle(GEOM_AISShape) aShape = Handle(GEOM_AISShape)::DownCast( anIter.Value() );
2903 if( !aShape.IsNull() )
2905 GEOM::field_data_type aFieldDataType;
2906 int aFieldDimension;
2907 QList<QVariant> aFieldStepData;
2908 TCollection_AsciiString aFieldStepName;
2909 double aFieldStepRangeMin, aFieldStepRangeMax;
2910 aShape->getFieldStepInfo( aFieldDataType,
2915 aFieldStepRangeMax );
2916 if( !aFieldStepData.isEmpty() && aFieldDataType != GEOM::FDT_String )
2918 anIsDisplayColorScale = Standard_True;
2919 aColorScaleTitle = aFieldStepName;
2920 aColorScaleMin = aFieldStepRangeMin;
2921 aColorScaleMax = aFieldStepRangeMax;
2922 anIsBoolean = aFieldDataType == GEOM::FDT_Bool;
2930 if( anIsDisplayColorScale )
2932 Handle(Aspect_ColorScale) aColorScale = aView->ColorScale();
2933 if( !aColorScale.IsNull() )
2935 SUIT_Session* session = SUIT_Session::session();
2936 SUIT_ResourceMgr* resMgr = session->resourceMgr();
2938 Standard_Real anXPos = resMgr->doubleValue( "Geometry", "scalar_bar_x_position", 0.05 );
2939 Standard_Real anYPos = resMgr->doubleValue( "Geometry", "scalar_bar_y_position", 0.1 );
2940 Standard_Real aWidth = resMgr->doubleValue( "Geometry", "scalar_bar_width", 0.2 );
2941 Standard_Real aHeight = resMgr->doubleValue( "Geometry", "scalar_bar_height", 0.5 );
2942 Standard_Integer aTextHeight = resMgr->integerValue( "Geometry", "scalar_bar_text_height", 14 );
2943 Standard_Integer aNbIntervals = resMgr->integerValue( "Geometry", "scalar_bar_nb_intervals", 20 );
2945 aColorScale->SetXPosition( anXPos );
2946 aColorScale->SetYPosition( anYPos );
2947 aColorScale->SetWidth( aWidth );
2948 aColorScale->SetHeight( aHeight );
2950 aColorScale->SetTextHeight( aTextHeight );
2951 aColorScale->SetNumberOfIntervals( anIsBoolean ? 2 : aNbIntervals );
2953 aColorScale->SetTitle( aColorScaleTitle );
2954 aColorScale->SetRange( aColorScaleMin, aColorScaleMax );
2956 if( !aView->ColorScaleIsDisplayed() )
2957 aView->ColorScaleDisplay();
2961 if( aView->ColorScaleIsDisplayed() )
2962 aView->ColorScaleErase();
2965 if( theIsRedisplayFieldSteps )
2967 _PTR(Study) aStudyDS = aStudy->studyDS();
2968 QList<SUIT_ViewManager*> vmList;
2969 myApp->viewManagers( vmList );
2970 for( QList<SUIT_ViewManager*>::Iterator vmIt = vmList.begin(); vmIt != vmList.end(); vmIt++ )
2972 if( SUIT_ViewManager* aViewManager = *vmIt )
2974 const ObjMap anObjects = aStudy->getObjectMap( aViewManager->getGlobalId() );
2975 for( ObjMap::ConstIterator objIt = anObjects.begin(); objIt != anObjects.end(); objIt++ )
2977 _PTR(SObject) aSObj( aStudyDS->FindObjectID( objIt.key().toLatin1().constData() ) );
2980 CORBA::Object_var anObject = GeometryGUI::ClientSObjectToObject( aSObj );
2981 if( !CORBA::is_nil( anObject ) )
2983 GEOM::GEOM_FieldStep_var aFieldStep = GEOM::GEOM_FieldStep::_narrow( anObject );
2984 if( !aFieldStep->_is_nil() )
2986 CORBA::String_var aStepEntry = aFieldStep->GetStudyEntry();
2987 Handle(SALOME_InteractiveObject) aStepIO =
2988 new SALOME_InteractiveObject( aStepEntry.in(), "GEOM", "TEMP_IO" );
2989 Redisplay( aStepIO, false, false );